blob: efc8ddf162b83b789e5b9d0d2dad634e9fb12ebd [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>
Alex Kiernan9c215492018-04-01 09:22:38 +00007#include <environment.h>
Marek Vasutba2ade92015-12-01 18:09:52 +01008#include <asm/arch/reset_manager.h>
9#include <asm/io.h>
10#include <asm/gpio.h>
11#include <i2c.h>
12
13DECLARE_GLOBAL_DATA_PTR;
14
15/*
16 * Miscellaneous platform dependent initialisations
17 */
18int board_late_init(void)
19{
20 const unsigned int phy_nrst_gpio = 0;
21 const unsigned int usb_nrst_gpio = 35;
22 int ret;
23
Uri Mashiach4892d392017-01-19 10:51:45 +020024 status_led_set(1, CONFIG_LED_STATUS_ON);
25 status_led_set(2, CONFIG_LED_STATUS_ON);
Marek Vasutba2ade92015-12-01 18:09:52 +010026
27 /* Address of boot parameters for ATAG (if ATAG is used) */
28 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
29
30 ret = gpio_request(phy_nrst_gpio, "phy_nrst_gpio");
31 if (!ret)
32 gpio_direction_output(phy_nrst_gpio, 1);
33 else
34 printf("Cannot remove PHY from reset!\n");
35
36 ret = gpio_request(usb_nrst_gpio, "usb_nrst_gpio");
37 if (!ret)
38 gpio_direction_output(usb_nrst_gpio, 1);
39 else
40 printf("Cannot remove USB from reset!\n");
41
42 mdelay(50);
43
44 return 0;
45}
46
47#ifndef CONFIG_SPL_BUILD
48int misc_init_r(void)
49{
50 uchar data[128];
51 char str[32];
52 u32 serial;
53 int ret;
54
Simon Goldschmidt021aa562019-03-28 22:09:35 +010055 /* EEPROM is at address 0x50 (at bus CONFIG_SYS_EEPROM_BUS_NUM). */
Marek Vasutba2ade92015-12-01 18:09:52 +010056 ret = eeprom_read(0x50, 0, data, sizeof(data));
57 if (ret) {
58 puts("Cannot read I2C EEPROM.\n");
59 return 0;
60 }
61
62 /* Check EEPROM signature. */
63 if (!(data[0] == 0xa5 && data[1] == 0x5a)) {
64 puts("Invalid I2C EEPROM signature.\n");
Simon Glass6a38e412017-08-03 12:22:09 -060065 env_set("unit_serial", "invalid");
66 env_set("unit_ident", "VINing-xxxx-STD");
67 env_set("hostname", "vining-invalid");
Marek Vasutba2ade92015-12-01 18:09:52 +010068 return 0;
69 }
70
71 /* If 'unit_serial' is already set, do nothing. */
Simon Glass64b723f2017-08-03 12:22:12 -060072 if (!env_get("unit_serial")) {
Marek Vasutba2ade92015-12-01 18:09:52 +010073 /* This field is Big Endian ! */
74 serial = (data[0x54] << 24) | (data[0x55] << 16) |
75 (data[0x56] << 8) | (data[0x57] << 0);
76 memset(str, 0, sizeof(str));
77 sprintf(str, "%07i", serial);
Simon Glass6a38e412017-08-03 12:22:09 -060078 env_set("unit_serial", str);
Marek Vasutba2ade92015-12-01 18:09:52 +010079 }
80
Simon Glass64b723f2017-08-03 12:22:12 -060081 if (!env_get("unit_ident")) {
Marek Vasutba2ade92015-12-01 18:09:52 +010082 memset(str, 0, sizeof(str));
83 memcpy(str, &data[0x2e], 18);
Simon Glass6a38e412017-08-03 12:22:09 -060084 env_set("unit_ident", str);
Marek Vasutba2ade92015-12-01 18:09:52 +010085 }
86
87 /* Set ethernet address from EEPROM. */
Simon Glass64b723f2017-08-03 12:22:12 -060088 if (!env_get("ethaddr") && is_valid_ethaddr(&data[0x62]))
Simon Glass8551d552017-08-03 12:22:11 -060089 eth_env_set_enetaddr("ethaddr", &data[0x62]);
Marek Vasutba2ade92015-12-01 18:09:52 +010090
91 return 0;
92}
93#endif