Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Marek Vasut | ba2ade9 | 2015-12-01 18:09:52 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2012 Altera Corporation <www.altera.com> |
Marek Vasut | ba2ade9 | 2015-12-01 18:09:52 +0100 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Alex Kiernan | 9c21549 | 2018-04-01 09:22:38 +0000 | [diff] [blame] | 7 | #include <environment.h> |
Marek Vasut | ba2ade9 | 2015-12-01 18:09:52 +0100 | [diff] [blame] | 8 | #include <asm/arch/reset_manager.h> |
| 9 | #include <asm/io.h> |
| 10 | #include <asm/gpio.h> |
| 11 | #include <i2c.h> |
| 12 | |
| 13 | DECLARE_GLOBAL_DATA_PTR; |
| 14 | |
| 15 | /* |
| 16 | * Miscellaneous platform dependent initialisations |
| 17 | */ |
| 18 | int 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 Mashiach | 4892d39 | 2017-01-19 10:51:45 +0200 | [diff] [blame] | 24 | status_led_set(1, CONFIG_LED_STATUS_ON); |
| 25 | status_led_set(2, CONFIG_LED_STATUS_ON); |
Marek Vasut | ba2ade9 | 2015-12-01 18:09:52 +0100 | [diff] [blame] | 26 | |
| 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 |
| 48 | int misc_init_r(void) |
| 49 | { |
| 50 | uchar data[128]; |
| 51 | char str[32]; |
| 52 | u32 serial; |
| 53 | int ret; |
| 54 | |
| 55 | /* EEPROM is at bus 0. */ |
| 56 | ret = i2c_set_bus_num(0); |
| 57 | if (ret) { |
| 58 | puts("Cannot select EEPROM I2C bus.\n"); |
| 59 | return 0; |
| 60 | } |
| 61 | |
| 62 | /* EEPROM is at address 0x50. */ |
| 63 | ret = eeprom_read(0x50, 0, data, sizeof(data)); |
| 64 | if (ret) { |
| 65 | puts("Cannot read I2C EEPROM.\n"); |
| 66 | return 0; |
| 67 | } |
| 68 | |
| 69 | /* Check EEPROM signature. */ |
| 70 | if (!(data[0] == 0xa5 && data[1] == 0x5a)) { |
| 71 | puts("Invalid I2C EEPROM signature.\n"); |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 72 | env_set("unit_serial", "invalid"); |
| 73 | env_set("unit_ident", "VINing-xxxx-STD"); |
| 74 | env_set("hostname", "vining-invalid"); |
Marek Vasut | ba2ade9 | 2015-12-01 18:09:52 +0100 | [diff] [blame] | 75 | return 0; |
| 76 | } |
| 77 | |
| 78 | /* If 'unit_serial' is already set, do nothing. */ |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 79 | if (!env_get("unit_serial")) { |
Marek Vasut | ba2ade9 | 2015-12-01 18:09:52 +0100 | [diff] [blame] | 80 | /* This field is Big Endian ! */ |
| 81 | serial = (data[0x54] << 24) | (data[0x55] << 16) | |
| 82 | (data[0x56] << 8) | (data[0x57] << 0); |
| 83 | memset(str, 0, sizeof(str)); |
| 84 | sprintf(str, "%07i", serial); |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 85 | env_set("unit_serial", str); |
Marek Vasut | ba2ade9 | 2015-12-01 18:09:52 +0100 | [diff] [blame] | 86 | } |
| 87 | |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 88 | if (!env_get("unit_ident")) { |
Marek Vasut | ba2ade9 | 2015-12-01 18:09:52 +0100 | [diff] [blame] | 89 | memset(str, 0, sizeof(str)); |
| 90 | memcpy(str, &data[0x2e], 18); |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 91 | env_set("unit_ident", str); |
Marek Vasut | ba2ade9 | 2015-12-01 18:09:52 +0100 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | /* Set ethernet address from EEPROM. */ |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 95 | if (!env_get("ethaddr") && is_valid_ethaddr(&data[0x62])) |
Simon Glass | 8551d55 | 2017-08-03 12:22:11 -0600 | [diff] [blame] | 96 | eth_env_set_enetaddr("ethaddr", &data[0x62]); |
Marek Vasut | ba2ade9 | 2015-12-01 18:09:52 +0100 | [diff] [blame] | 97 | |
| 98 | return 0; |
| 99 | } |
| 100 | #endif |