2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2015-12-01 17:09:52 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012 Altera Corporation <www.altera.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2019-11-14 19:57:50 +00:00
|
|
|
#include <eeprom.h>
|
2019-08-01 15:46:51 +00:00
|
|
|
#include <env.h>
|
2019-11-14 19:57:46 +00:00
|
|
|
#include <init.h>
|
2019-11-14 19:57:11 +00:00
|
|
|
#include <status_led.h>
|
2015-12-01 17:09:52 +00:00
|
|
|
#include <asm/arch/reset_manager.h>
|
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/gpio.h>
|
|
|
|
#include <i2c.h>
|
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Miscellaneous platform dependent initialisations
|
|
|
|
*/
|
|
|
|
int board_late_init(void)
|
|
|
|
{
|
|
|
|
const unsigned int phy_nrst_gpio = 0;
|
|
|
|
const unsigned int usb_nrst_gpio = 35;
|
|
|
|
int ret;
|
|
|
|
|
2017-01-19 08:51:45 +00:00
|
|
|
status_led_set(1, CONFIG_LED_STATUS_ON);
|
|
|
|
status_led_set(2, CONFIG_LED_STATUS_ON);
|
2015-12-01 17:09:52 +00:00
|
|
|
|
|
|
|
/* Address of boot parameters for ATAG (if ATAG is used) */
|
|
|
|
gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
|
|
|
|
|
|
|
|
ret = gpio_request(phy_nrst_gpio, "phy_nrst_gpio");
|
|
|
|
if (!ret)
|
|
|
|
gpio_direction_output(phy_nrst_gpio, 1);
|
|
|
|
else
|
|
|
|
printf("Cannot remove PHY from reset!\n");
|
|
|
|
|
|
|
|
ret = gpio_request(usb_nrst_gpio, "usb_nrst_gpio");
|
|
|
|
if (!ret)
|
|
|
|
gpio_direction_output(usb_nrst_gpio, 1);
|
|
|
|
else
|
|
|
|
printf("Cannot remove USB from reset!\n");
|
|
|
|
|
|
|
|
mdelay(50);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef CONFIG_SPL_BUILD
|
|
|
|
int misc_init_r(void)
|
|
|
|
{
|
|
|
|
uchar data[128];
|
|
|
|
char str[32];
|
|
|
|
u32 serial;
|
|
|
|
int ret;
|
|
|
|
|
2019-03-28 21:09:35 +00:00
|
|
|
/* EEPROM is at address 0x50 (at bus CONFIG_SYS_EEPROM_BUS_NUM). */
|
2015-12-01 17:09:52 +00:00
|
|
|
ret = eeprom_read(0x50, 0, data, sizeof(data));
|
|
|
|
if (ret) {
|
|
|
|
puts("Cannot read I2C EEPROM.\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check EEPROM signature. */
|
|
|
|
if (!(data[0] == 0xa5 && data[1] == 0x5a)) {
|
|
|
|
puts("Invalid I2C EEPROM signature.\n");
|
2017-08-03 18:22:09 +00:00
|
|
|
env_set("unit_serial", "invalid");
|
|
|
|
env_set("unit_ident", "VINing-xxxx-STD");
|
|
|
|
env_set("hostname", "vining-invalid");
|
2015-12-01 17:09:52 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If 'unit_serial' is already set, do nothing. */
|
2017-08-03 18:22:12 +00:00
|
|
|
if (!env_get("unit_serial")) {
|
2015-12-01 17:09:52 +00:00
|
|
|
/* This field is Big Endian ! */
|
|
|
|
serial = (data[0x54] << 24) | (data[0x55] << 16) |
|
|
|
|
(data[0x56] << 8) | (data[0x57] << 0);
|
|
|
|
memset(str, 0, sizeof(str));
|
|
|
|
sprintf(str, "%07i", serial);
|
2017-08-03 18:22:09 +00:00
|
|
|
env_set("unit_serial", str);
|
2015-12-01 17:09:52 +00:00
|
|
|
}
|
|
|
|
|
2017-08-03 18:22:12 +00:00
|
|
|
if (!env_get("unit_ident")) {
|
2015-12-01 17:09:52 +00:00
|
|
|
memset(str, 0, sizeof(str));
|
|
|
|
memcpy(str, &data[0x2e], 18);
|
2017-08-03 18:22:09 +00:00
|
|
|
env_set("unit_ident", str);
|
2015-12-01 17:09:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set ethernet address from EEPROM. */
|
2017-08-03 18:22:12 +00:00
|
|
|
if (!env_get("ethaddr") && is_valid_ethaddr(&data[0x62]))
|
2017-08-03 18:22:11 +00:00
|
|
|
eth_env_set_enetaddr("ethaddr", &data[0x62]);
|
2019-06-26 22:19:35 +00:00
|
|
|
if (!env_get("eth1addr") && is_valid_ethaddr(&data[0x6a]))
|
|
|
|
eth_env_set_enetaddr("eth1addr", &data[0x6a]);
|
2015-12-01 17:09:52 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|