blob: 5a88b6c8adef8b0e37ee2670d99a1d46fdd3337d [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Marek Vasutba2ade92015-12-01 18:09:52 +01002/*
3 * Copyright (C) 2012 Altera Corporation <www.altera.com>
Marek Vasutba2ade92015-12-01 18:09:52 +01004 */
5
6#include <common.h>
Simon Glasseba6b8d2019-11-14 12:57:50 -07007#include <eeprom.h>
Simon Glass5e6201b2019-08-01 09:46:51 -06008#include <env.h>
Simon Glassa7b51302019-11-14 12:57:46 -07009#include <init.h>
Simon Glasse7872cb2019-11-14 12:57:11 -070010#include <status_led.h>
Marek Vasutba2ade92015-12-01 18:09:52 +010011#include <asm/arch/reset_manager.h>
12#include <asm/io.h>
13#include <asm/gpio.h>
14#include <i2c.h>
15
16DECLARE_GLOBAL_DATA_PTR;
17
18/*
19 * Miscellaneous platform dependent initialisations
20 */
21int board_late_init(void)
22{
23 const unsigned int phy_nrst_gpio = 0;
24 const unsigned int usb_nrst_gpio = 35;
25 int ret;
26
Uri Mashiach4892d392017-01-19 10:51:45 +020027 status_led_set(1, CONFIG_LED_STATUS_ON);
28 status_led_set(2, CONFIG_LED_STATUS_ON);
Marek Vasutba2ade92015-12-01 18:09:52 +010029
30 /* Address of boot parameters for ATAG (if ATAG is used) */
31 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
32
33 ret = gpio_request(phy_nrst_gpio, "phy_nrst_gpio");
34 if (!ret)
35 gpio_direction_output(phy_nrst_gpio, 1);
36 else
37 printf("Cannot remove PHY from reset!\n");
38
39 ret = gpio_request(usb_nrst_gpio, "usb_nrst_gpio");
40 if (!ret)
41 gpio_direction_output(usb_nrst_gpio, 1);
42 else
43 printf("Cannot remove USB from reset!\n");
44
45 mdelay(50);
46
47 return 0;
48}
49
50#ifndef CONFIG_SPL_BUILD
51int misc_init_r(void)
52{
53 uchar data[128];
54 char str[32];
55 u32 serial;
56 int ret;
57
Simon Goldschmidt021aa562019-03-28 22:09:35 +010058 /* EEPROM is at address 0x50 (at bus CONFIG_SYS_EEPROM_BUS_NUM). */
Marek Vasutba2ade92015-12-01 18:09:52 +010059 ret = eeprom_read(0x50, 0, data, sizeof(data));
60 if (ret) {
61 puts("Cannot read I2C EEPROM.\n");
62 return 0;
63 }
64
65 /* Check EEPROM signature. */
66 if (!(data[0] == 0xa5 && data[1] == 0x5a)) {
67 puts("Invalid I2C EEPROM signature.\n");
Simon Glass6a38e412017-08-03 12:22:09 -060068 env_set("unit_serial", "invalid");
69 env_set("unit_ident", "VINing-xxxx-STD");
70 env_set("hostname", "vining-invalid");
Marek Vasutba2ade92015-12-01 18:09:52 +010071 return 0;
72 }
73
74 /* If 'unit_serial' is already set, do nothing. */
Simon Glass64b723f2017-08-03 12:22:12 -060075 if (!env_get("unit_serial")) {
Marek Vasutba2ade92015-12-01 18:09:52 +010076 /* This field is Big Endian ! */
77 serial = (data[0x54] << 24) | (data[0x55] << 16) |
78 (data[0x56] << 8) | (data[0x57] << 0);
79 memset(str, 0, sizeof(str));
80 sprintf(str, "%07i", serial);
Simon Glass6a38e412017-08-03 12:22:09 -060081 env_set("unit_serial", str);
Marek Vasutba2ade92015-12-01 18:09:52 +010082 }
83
Simon Glass64b723f2017-08-03 12:22:12 -060084 if (!env_get("unit_ident")) {
Marek Vasutba2ade92015-12-01 18:09:52 +010085 memset(str, 0, sizeof(str));
86 memcpy(str, &data[0x2e], 18);
Simon Glass6a38e412017-08-03 12:22:09 -060087 env_set("unit_ident", str);
Marek Vasutba2ade92015-12-01 18:09:52 +010088 }
89
90 /* Set ethernet address from EEPROM. */
Simon Glass64b723f2017-08-03 12:22:12 -060091 if (!env_get("ethaddr") && is_valid_ethaddr(&data[0x62]))
Simon Glass8551d552017-08-03 12:22:11 -060092 eth_env_set_enetaddr("ethaddr", &data[0x62]);
Marek Vasut5e57ad32019-06-27 00:19:35 +020093 if (!env_get("eth1addr") && is_valid_ethaddr(&data[0x6a]))
94 eth_env_set_enetaddr("eth1addr", &data[0x6a]);
Marek Vasutba2ade92015-12-01 18:09:52 +010095
96 return 0;
97}
98#endif