socfpga.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. #include "../common/common.h"
  9. /*
  10. * For FU1, the MAC address associated with the mgmt port should
  11. * be the base address (as read from the IVM) + 4, and for FU2 it
  12. * is + 10
  13. */
  14. #define MAC_ADDRESS_OFFSET_FU1 4
  15. #define MAC_ADDRESS_OFFSET_FU2 10
  16. /*
  17. * This function reads the state of GPIO40 and returns true (non-zero)
  18. * if it is '1' and false(0) otherwise.
  19. *
  20. * This pin is routed to a pull-up on FU2 and a pull-down on
  21. */
  22. #define GPIO_FU_DETECTION 40
  23. int secu1_is_fu2(void)
  24. {
  25. int value;
  26. int ret = gpio_request(GPIO_FU_DETECTION, "secu");
  27. if (ret) {
  28. printf("gpio: failed to request pin for FU detection\n");
  29. return 1;
  30. }
  31. gpio_direction_input(GPIO_FU_DETECTION);
  32. value = gpio_get_value(GPIO_FU_DETECTION);
  33. if (value == 1)
  34. printf("FU2 detected\n");
  35. else
  36. printf("FU1 detected\n");
  37. return value;
  38. }
  39. static uchar ivm_content[CONFIG_SYS_IVM_EEPROM_MAX_LEN];
  40. #if defined(CONFIG_HUSH_INIT_VAR)
  41. int hush_init_var(void)
  42. {
  43. ivm_analyze_eeprom(ivm_content, CONFIG_SYS_IVM_EEPROM_MAX_LEN);
  44. return 0;
  45. }
  46. #endif
  47. int misc_init_r(void)
  48. {
  49. if (secu1_is_fu2())
  50. ivm_read_eeprom(ivm_content, CONFIG_SYS_IVM_EEPROM_MAX_LEN,
  51. MAC_ADDRESS_OFFSET_FU2);
  52. else
  53. ivm_read_eeprom(ivm_content, CONFIG_SYS_IVM_EEPROM_MAX_LEN,
  54. MAC_ADDRESS_OFFSET_FU1);
  55. return 0;
  56. }