Holger Brunck | ddef889 | 2020-02-19 19:55:14 +0100 | [diff] [blame^] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright (C) 2017-2020 ABB |
| 4 | */ |
| 5 | #include <common.h> |
| 6 | #include <i2c.h> |
| 7 | #include <asm/gpio.h> |
| 8 | |
| 9 | #include "../common/common.h" |
| 10 | |
| 11 | /* |
| 12 | * For FU1, the MAC address associated with the mgmt port should |
| 13 | * be the base address (as read from the IVM) + 4, and for FU2 it |
| 14 | * is + 10 |
| 15 | */ |
| 16 | #define MAC_ADDRESS_OFFSET_FU1 4 |
| 17 | #define MAC_ADDRESS_OFFSET_FU2 10 |
| 18 | |
| 19 | /* |
| 20 | * This function reads the state of GPIO40 and returns true (non-zero) |
| 21 | * if it is '1' and false(0) otherwise. |
| 22 | * |
| 23 | * This pin is routed to a pull-up on FU2 and a pull-down on |
| 24 | */ |
| 25 | #define GPIO_FU_DETECTION 40 |
| 26 | |
| 27 | int secu1_is_fu2(void) |
| 28 | { |
| 29 | int value; |
| 30 | int ret = gpio_request(GPIO_FU_DETECTION, "secu"); |
| 31 | |
| 32 | if (ret) { |
| 33 | printf("gpio: failed to request pin for FU detection\n"); |
| 34 | return 1; |
| 35 | } |
| 36 | gpio_direction_input(GPIO_FU_DETECTION); |
| 37 | value = gpio_get_value(GPIO_FU_DETECTION); |
| 38 | |
| 39 | if (value == 1) |
| 40 | printf("FU2 detected\n"); |
| 41 | else |
| 42 | printf("FU1 detected\n"); |
| 43 | |
| 44 | return value; |
| 45 | } |
| 46 | |
| 47 | static uchar ivm_content[CONFIG_SYS_IVM_EEPROM_MAX_LEN]; |
| 48 | |
| 49 | #if defined(CONFIG_HUSH_INIT_VAR) |
| 50 | int hush_init_var(void) |
| 51 | { |
| 52 | ivm_analyze_eeprom(ivm_content, CONFIG_SYS_IVM_EEPROM_MAX_LEN); |
| 53 | return 0; |
| 54 | } |
| 55 | #endif |
| 56 | |
| 57 | int misc_init_r(void) |
| 58 | { |
| 59 | if (secu1_is_fu2()) |
| 60 | ivm_read_eeprom(ivm_content, CONFIG_SYS_IVM_EEPROM_MAX_LEN, |
| 61 | MAC_ADDRESS_OFFSET_FU2); |
| 62 | else |
| 63 | ivm_read_eeprom(ivm_content, CONFIG_SYS_IVM_EEPROM_MAX_LEN, |
| 64 | MAC_ADDRESS_OFFSET_FU1); |
| 65 | |
| 66 | return 0; |
| 67 | } |