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