blob: 7e311b7a1c38ec9cf53b2e28ef36ab76434a7873 [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 Glass274e0b02020-05-10 11:39:56 -060010#include <net.h>
Simon Glasse7872cb2019-11-14 12:57:11 -070011#include <status_led.h>
Marek Vasutba2ade92015-12-01 18:09:52 +010012#include <asm/arch/reset_manager.h>
13#include <asm/io.h>
14#include <asm/gpio.h>
15#include <i2c.h>
Simon Glassdbd79542020-05-10 11:40:11 -060016#include <linux/delay.h>
Marek Vasutba2ade92015-12-01 18:09:52 +010017
18DECLARE_GLOBAL_DATA_PTR;
19
20/*
21 * Miscellaneous platform dependent initialisations
22 */
23int board_late_init(void)
24{
25 const unsigned int phy_nrst_gpio = 0;
26 const unsigned int usb_nrst_gpio = 35;
27 int ret;
28
Uri Mashiach4892d392017-01-19 10:51:45 +020029 status_led_set(1, CONFIG_LED_STATUS_ON);
30 status_led_set(2, CONFIG_LED_STATUS_ON);
Marek Vasutba2ade92015-12-01 18:09:52 +010031
32 /* Address of boot parameters for ATAG (if ATAG is used) */
33 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
34
35 ret = gpio_request(phy_nrst_gpio, "phy_nrst_gpio");
36 if (!ret)
37 gpio_direction_output(phy_nrst_gpio, 1);
38 else
39 printf("Cannot remove PHY from reset!\n");
40
41 ret = gpio_request(usb_nrst_gpio, "usb_nrst_gpio");
42 if (!ret)
43 gpio_direction_output(usb_nrst_gpio, 1);
44 else
45 printf("Cannot remove USB from reset!\n");
46
47 mdelay(50);
48
49 return 0;
50}
51
52#ifndef CONFIG_SPL_BUILD
53int misc_init_r(void)
54{
55 uchar data[128];
56 char str[32];
57 u32 serial;
58 int ret;
59
Simon Goldschmidt021aa562019-03-28 22:09:35 +010060 /* EEPROM is at address 0x50 (at bus CONFIG_SYS_EEPROM_BUS_NUM). */
Marek Vasutba2ade92015-12-01 18:09:52 +010061 ret = eeprom_read(0x50, 0, data, sizeof(data));
62 if (ret) {
63 puts("Cannot read I2C EEPROM.\n");
64 return 0;
65 }
66
67 /* Check EEPROM signature. */
68 if (!(data[0] == 0xa5 && data[1] == 0x5a)) {
69 puts("Invalid I2C EEPROM signature.\n");
Simon Glass6a38e412017-08-03 12:22:09 -060070 env_set("unit_serial", "invalid");
71 env_set("unit_ident", "VINing-xxxx-STD");
72 env_set("hostname", "vining-invalid");
Marek Vasutba2ade92015-12-01 18:09:52 +010073 return 0;
74 }
75
76 /* If 'unit_serial' is already set, do nothing. */
Simon Glass64b723f2017-08-03 12:22:12 -060077 if (!env_get("unit_serial")) {
Marek Vasutba2ade92015-12-01 18:09:52 +010078 /* This field is Big Endian ! */
79 serial = (data[0x54] << 24) | (data[0x55] << 16) |
80 (data[0x56] << 8) | (data[0x57] << 0);
81 memset(str, 0, sizeof(str));
82 sprintf(str, "%07i", serial);
Simon Glass6a38e412017-08-03 12:22:09 -060083 env_set("unit_serial", str);
Marek Vasutba2ade92015-12-01 18:09:52 +010084 }
85
Simon Glass64b723f2017-08-03 12:22:12 -060086 if (!env_get("unit_ident")) {
Marek Vasutba2ade92015-12-01 18:09:52 +010087 memset(str, 0, sizeof(str));
88 memcpy(str, &data[0x2e], 18);
Simon Glass6a38e412017-08-03 12:22:09 -060089 env_set("unit_ident", str);
Marek Vasutba2ade92015-12-01 18:09:52 +010090 }
91
92 /* Set ethernet address from EEPROM. */
Simon Glass64b723f2017-08-03 12:22:12 -060093 if (!env_get("ethaddr") && is_valid_ethaddr(&data[0x62]))
Simon Glass8551d552017-08-03 12:22:11 -060094 eth_env_set_enetaddr("ethaddr", &data[0x62]);
Marek Vasut5e57ad32019-06-27 00:19:35 +020095 if (!env_get("eth1addr") && is_valid_ethaddr(&data[0x6a]))
96 eth_env_set_enetaddr("eth1addr", &data[0x6a]);
Marek Vasutba2ade92015-12-01 18:09:52 +010097
98 return 0;
99}
100#endif