blob: d70c22f48fe549fac3a6c129155aa4f422bd3276 [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>
Simon Glass52559322019-11-14 12:57:46 -07008#include <init.h>
Simon Glassc3e44302019-11-14 12:57:11 -07009#include <status_led.h>
Marek Vasut569a1912015-12-01 18:09:52 +010010#include <asm/arch/reset_manager.h>
11#include <asm/io.h>
12#include <asm/gpio.h>
13#include <i2c.h>
14
15DECLARE_GLOBAL_DATA_PTR;
16
17/*
18 * Miscellaneous platform dependent initialisations
19 */
20int board_late_init(void)
21{
22 const unsigned int phy_nrst_gpio = 0;
23 const unsigned int usb_nrst_gpio = 35;
24 int ret;
25
Uri Mashiach2d8d1902017-01-19 10:51:45 +020026 status_led_set(1, CONFIG_LED_STATUS_ON);
27 status_led_set(2, CONFIG_LED_STATUS_ON);
Marek Vasut569a1912015-12-01 18:09:52 +010028
29 /* Address of boot parameters for ATAG (if ATAG is used) */
30 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
31
32 ret = gpio_request(phy_nrst_gpio, "phy_nrst_gpio");
33 if (!ret)
34 gpio_direction_output(phy_nrst_gpio, 1);
35 else
36 printf("Cannot remove PHY from reset!\n");
37
38 ret = gpio_request(usb_nrst_gpio, "usb_nrst_gpio");
39 if (!ret)
40 gpio_direction_output(usb_nrst_gpio, 1);
41 else
42 printf("Cannot remove USB from reset!\n");
43
44 mdelay(50);
45
46 return 0;
47}
48
49#ifndef CONFIG_SPL_BUILD
50int misc_init_r(void)
51{
52 uchar data[128];
53 char str[32];
54 u32 serial;
55 int ret;
56
Simon Goldschmidt0b7eb432019-03-28 22:09:35 +010057 /* EEPROM is at address 0x50 (at bus CONFIG_SYS_EEPROM_BUS_NUM). */
Marek Vasut569a1912015-12-01 18:09:52 +010058 ret = eeprom_read(0x50, 0, data, sizeof(data));
59 if (ret) {
60 puts("Cannot read I2C EEPROM.\n");
61 return 0;
62 }
63
64 /* Check EEPROM signature. */
65 if (!(data[0] == 0xa5 && data[1] == 0x5a)) {
66 puts("Invalid I2C EEPROM signature.\n");
Simon Glass382bee52017-08-03 12:22:09 -060067 env_set("unit_serial", "invalid");
68 env_set("unit_ident", "VINing-xxxx-STD");
69 env_set("hostname", "vining-invalid");
Marek Vasut569a1912015-12-01 18:09:52 +010070 return 0;
71 }
72
73 /* If 'unit_serial' is already set, do nothing. */
Simon Glass00caae62017-08-03 12:22:12 -060074 if (!env_get("unit_serial")) {
Marek Vasut569a1912015-12-01 18:09:52 +010075 /* This field is Big Endian ! */
76 serial = (data[0x54] << 24) | (data[0x55] << 16) |
77 (data[0x56] << 8) | (data[0x57] << 0);
78 memset(str, 0, sizeof(str));
79 sprintf(str, "%07i", serial);
Simon Glass382bee52017-08-03 12:22:09 -060080 env_set("unit_serial", str);
Marek Vasut569a1912015-12-01 18:09:52 +010081 }
82
Simon Glass00caae62017-08-03 12:22:12 -060083 if (!env_get("unit_ident")) {
Marek Vasut569a1912015-12-01 18:09:52 +010084 memset(str, 0, sizeof(str));
85 memcpy(str, &data[0x2e], 18);
Simon Glass382bee52017-08-03 12:22:09 -060086 env_set("unit_ident", str);
Marek Vasut569a1912015-12-01 18:09:52 +010087 }
88
89 /* Set ethernet address from EEPROM. */
Simon Glass00caae62017-08-03 12:22:12 -060090 if (!env_get("ethaddr") && is_valid_ethaddr(&data[0x62]))
Simon Glassfd1e9592017-08-03 12:22:11 -060091 eth_env_set_enetaddr("ethaddr", &data[0x62]);
Marek Vasute6281b82019-06-27 00:19:35 +020092 if (!env_get("eth1addr") && is_valid_ethaddr(&data[0x6a]))
93 eth_env_set_enetaddr("eth1addr", &data[0x6a]);
Marek Vasut569a1912015-12-01 18:09:52 +010094
95 return 0;
96}
97#endif