blob: 63ce4a20b5d17b20620aac77f8933742cee27a8b [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Marek Vasut569a1912015-12-01 18:09:52 +01002/*
3 * Copyright (C) 2012 Altera Corporation <www.altera.com>
Marek Vasut569a1912015-12-01 18:09:52 +01004 */
5
6#include <common.h>
Simon Glass9fb625c2019-08-01 09:46:51 -06007#include <env.h>
Alex Kiernan9925f1d2018-04-01 09:22:38 +00008#include <environment.h>
Marek Vasut569a1912015-12-01 18:09:52 +01009#include <asm/arch/reset_manager.h>
10#include <asm/io.h>
11#include <asm/gpio.h>
12#include <i2c.h>
13
14DECLARE_GLOBAL_DATA_PTR;
15
16/*
17 * Miscellaneous platform dependent initialisations
18 */
19int board_late_init(void)
20{
21 const unsigned int phy_nrst_gpio = 0;
22 const unsigned int usb_nrst_gpio = 35;
23 int ret;
24
Uri Mashiach2d8d1902017-01-19 10:51:45 +020025 status_led_set(1, CONFIG_LED_STATUS_ON);
26 status_led_set(2, CONFIG_LED_STATUS_ON);
Marek Vasut569a1912015-12-01 18:09:52 +010027
28 /* Address of boot parameters for ATAG (if ATAG is used) */
29 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
30
31 ret = gpio_request(phy_nrst_gpio, "phy_nrst_gpio");
32 if (!ret)
33 gpio_direction_output(phy_nrst_gpio, 1);
34 else
35 printf("Cannot remove PHY from reset!\n");
36
37 ret = gpio_request(usb_nrst_gpio, "usb_nrst_gpio");
38 if (!ret)
39 gpio_direction_output(usb_nrst_gpio, 1);
40 else
41 printf("Cannot remove USB from reset!\n");
42
43 mdelay(50);
44
45 return 0;
46}
47
48#ifndef CONFIG_SPL_BUILD
49int misc_init_r(void)
50{
51 uchar data[128];
52 char str[32];
53 u32 serial;
54 int ret;
55
Simon Goldschmidt0b7eb432019-03-28 22:09:35 +010056 /* EEPROM is at address 0x50 (at bus CONFIG_SYS_EEPROM_BUS_NUM). */
Marek Vasut569a1912015-12-01 18:09:52 +010057 ret = eeprom_read(0x50, 0, data, sizeof(data));
58 if (ret) {
59 puts("Cannot read I2C EEPROM.\n");
60 return 0;
61 }
62
63 /* Check EEPROM signature. */
64 if (!(data[0] == 0xa5 && data[1] == 0x5a)) {
65 puts("Invalid I2C EEPROM signature.\n");
Simon Glass382bee52017-08-03 12:22:09 -060066 env_set("unit_serial", "invalid");
67 env_set("unit_ident", "VINing-xxxx-STD");
68 env_set("hostname", "vining-invalid");
Marek Vasut569a1912015-12-01 18:09:52 +010069 return 0;
70 }
71
72 /* If 'unit_serial' is already set, do nothing. */
Simon Glass00caae62017-08-03 12:22:12 -060073 if (!env_get("unit_serial")) {
Marek Vasut569a1912015-12-01 18:09:52 +010074 /* This field is Big Endian ! */
75 serial = (data[0x54] << 24) | (data[0x55] << 16) |
76 (data[0x56] << 8) | (data[0x57] << 0);
77 memset(str, 0, sizeof(str));
78 sprintf(str, "%07i", serial);
Simon Glass382bee52017-08-03 12:22:09 -060079 env_set("unit_serial", str);
Marek Vasut569a1912015-12-01 18:09:52 +010080 }
81
Simon Glass00caae62017-08-03 12:22:12 -060082 if (!env_get("unit_ident")) {
Marek Vasut569a1912015-12-01 18:09:52 +010083 memset(str, 0, sizeof(str));
84 memcpy(str, &data[0x2e], 18);
Simon Glass382bee52017-08-03 12:22:09 -060085 env_set("unit_ident", str);
Marek Vasut569a1912015-12-01 18:09:52 +010086 }
87
88 /* Set ethernet address from EEPROM. */
Simon Glass00caae62017-08-03 12:22:12 -060089 if (!env_get("ethaddr") && is_valid_ethaddr(&data[0x62]))
Simon Glassfd1e9592017-08-03 12:22:11 -060090 eth_env_set_enetaddr("ethaddr", &data[0x62]);
Marek Vasut569a1912015-12-01 18:09:52 +010091
92 return 0;
93}
94#endif