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> |
Simon Glass | eba6b8d | 2019-11-14 12:57:50 -0700 | [diff] [blame] | 7 | #include <eeprom.h> |
Simon Glass | 5e6201b | 2019-08-01 09:46:51 -0600 | [diff] [blame] | 8 | #include <env.h> |
Simon Glass | a7b5130 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 9 | #include <init.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 10 | #include <net.h> |
Simon Glass | e7872cb | 2019-11-14 12:57:11 -0700 | [diff] [blame] | 11 | #include <status_led.h> |
Marek Vasut | ba2ade9 | 2015-12-01 18:09:52 +0100 | [diff] [blame] | 12 | #include <asm/arch/reset_manager.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 13 | #include <asm/global_data.h> |
Marek Vasut | ba2ade9 | 2015-12-01 18:09:52 +0100 | [diff] [blame] | 14 | #include <asm/io.h> |
| 15 | #include <asm/gpio.h> |
| 16 | #include <i2c.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 17 | #include <linux/delay.h> |
Marek Vasut | ba2ade9 | 2015-12-01 18:09:52 +0100 | [diff] [blame] | 18 | |
| 19 | DECLARE_GLOBAL_DATA_PTR; |
| 20 | |
| 21 | /* |
| 22 | * Miscellaneous platform dependent initialisations |
| 23 | */ |
| 24 | int board_late_init(void) |
| 25 | { |
Marek Vasut | ba2ade9 | 2015-12-01 18:09:52 +0100 | [diff] [blame] | 26 | const unsigned int usb_nrst_gpio = 35; |
| 27 | int ret; |
| 28 | |
Uri Mashiach | 4892d39 | 2017-01-19 10:51:45 +0200 | [diff] [blame] | 29 | status_led_set(1, CONFIG_LED_STATUS_ON); |
| 30 | status_led_set(2, CONFIG_LED_STATUS_ON); |
Marek Vasut | ba2ade9 | 2015-12-01 18:09:52 +0100 | [diff] [blame] | 31 | |
| 32 | /* Address of boot parameters for ATAG (if ATAG is used) */ |
Tom Rini | bb4dd96 | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 33 | gd->bd->bi_boot_params = CFG_SYS_SDRAM_BASE + 0x100; |
Marek Vasut | ba2ade9 | 2015-12-01 18:09:52 +0100 | [diff] [blame] | 34 | |
Marek Vasut | ba2ade9 | 2015-12-01 18:09:52 +0100 | [diff] [blame] | 35 | ret = gpio_request(usb_nrst_gpio, "usb_nrst_gpio"); |
| 36 | if (!ret) |
| 37 | gpio_direction_output(usb_nrst_gpio, 1); |
| 38 | else |
| 39 | printf("Cannot remove USB from reset!\n"); |
| 40 | |
| 41 | mdelay(50); |
| 42 | |
| 43 | return 0; |
| 44 | } |
| 45 | |
| 46 | #ifndef CONFIG_SPL_BUILD |
| 47 | int misc_init_r(void) |
| 48 | { |
| 49 | uchar data[128]; |
| 50 | char str[32]; |
| 51 | u32 serial; |
| 52 | int ret; |
| 53 | |
Simon Goldschmidt | 021aa56 | 2019-03-28 22:09:35 +0100 | [diff] [blame] | 54 | /* EEPROM is at address 0x50 (at bus CONFIG_SYS_EEPROM_BUS_NUM). */ |
Marek Vasut | ba2ade9 | 2015-12-01 18:09:52 +0100 | [diff] [blame] | 55 | ret = eeprom_read(0x50, 0, data, sizeof(data)); |
| 56 | if (ret) { |
| 57 | puts("Cannot read I2C EEPROM.\n"); |
| 58 | return 0; |
| 59 | } |
| 60 | |
| 61 | /* Check EEPROM signature. */ |
| 62 | if (!(data[0] == 0xa5 && data[1] == 0x5a)) { |
| 63 | puts("Invalid I2C EEPROM signature.\n"); |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 64 | env_set("unit_serial", "invalid"); |
| 65 | env_set("unit_ident", "VINing-xxxx-STD"); |
| 66 | env_set("hostname", "vining-invalid"); |
Marek Vasut | ba2ade9 | 2015-12-01 18:09:52 +0100 | [diff] [blame] | 67 | return 0; |
| 68 | } |
| 69 | |
| 70 | /* If 'unit_serial' is already set, do nothing. */ |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 71 | if (!env_get("unit_serial")) { |
Marek Vasut | ba2ade9 | 2015-12-01 18:09:52 +0100 | [diff] [blame] | 72 | /* This field is Big Endian ! */ |
| 73 | serial = (data[0x54] << 24) | (data[0x55] << 16) | |
| 74 | (data[0x56] << 8) | (data[0x57] << 0); |
| 75 | memset(str, 0, sizeof(str)); |
| 76 | sprintf(str, "%07i", serial); |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 77 | env_set("unit_serial", str); |
Marek Vasut | ba2ade9 | 2015-12-01 18:09:52 +0100 | [diff] [blame] | 78 | } |
| 79 | |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 80 | if (!env_get("unit_ident")) { |
Marek Vasut | ba2ade9 | 2015-12-01 18:09:52 +0100 | [diff] [blame] | 81 | memset(str, 0, sizeof(str)); |
| 82 | memcpy(str, &data[0x2e], 18); |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 83 | env_set("unit_ident", str); |
Marek Vasut | ba2ade9 | 2015-12-01 18:09:52 +0100 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | /* Set ethernet address from EEPROM. */ |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 87 | if (!env_get("ethaddr") && is_valid_ethaddr(&data[0x62])) |
Simon Glass | 8551d55 | 2017-08-03 12:22:11 -0600 | [diff] [blame] | 88 | eth_env_set_enetaddr("ethaddr", &data[0x62]); |
Marek Vasut | 5e57ad3 | 2019-06-27 00:19:35 +0200 | [diff] [blame] | 89 | if (!env_get("eth1addr") && is_valid_ethaddr(&data[0x6a])) |
| 90 | eth_env_set_enetaddr("eth1addr", &data[0x6a]); |
Marek Vasut | ba2ade9 | 2015-12-01 18:09:52 +0100 | [diff] [blame] | 91 | |
| 92 | return 0; |
| 93 | } |
| 94 | #endif |