socfpga.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2012 Altera Corporation <www.altera.com>
  4. */
  5. #include <common.h>
  6. #include <eeprom.h>
  7. #include <env.h>
  8. #include <init.h>
  9. #include <net.h>
  10. #include <status_led.h>
  11. #include <asm/arch/reset_manager.h>
  12. #include <asm/io.h>
  13. #include <asm/gpio.h>
  14. #include <i2c.h>
  15. #include <linux/delay.h>
  16. DECLARE_GLOBAL_DATA_PTR;
  17. /*
  18. * Miscellaneous platform dependent initialisations
  19. */
  20. int board_late_init(void)
  21. {
  22. const unsigned int phy_nrst_gpio = 0;
  23. const unsigned int usb_nrst_gpio = 35;
  24. int ret;
  25. status_led_set(1, CONFIG_LED_STATUS_ON);
  26. status_led_set(2, CONFIG_LED_STATUS_ON);
  27. /* Address of boot parameters for ATAG (if ATAG is used) */
  28. gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
  29. ret = gpio_request(phy_nrst_gpio, "phy_nrst_gpio");
  30. if (!ret)
  31. gpio_direction_output(phy_nrst_gpio, 1);
  32. else
  33. printf("Cannot remove PHY from reset!\n");
  34. ret = gpio_request(usb_nrst_gpio, "usb_nrst_gpio");
  35. if (!ret)
  36. gpio_direction_output(usb_nrst_gpio, 1);
  37. else
  38. printf("Cannot remove USB from reset!\n");
  39. mdelay(50);
  40. return 0;
  41. }
  42. #ifndef CONFIG_SPL_BUILD
  43. int misc_init_r(void)
  44. {
  45. uchar data[128];
  46. char str[32];
  47. u32 serial;
  48. int ret;
  49. /* EEPROM is at address 0x50 (at bus CONFIG_SYS_EEPROM_BUS_NUM). */
  50. ret = eeprom_read(0x50, 0, data, sizeof(data));
  51. if (ret) {
  52. puts("Cannot read I2C EEPROM.\n");
  53. return 0;
  54. }
  55. /* Check EEPROM signature. */
  56. if (!(data[0] == 0xa5 && data[1] == 0x5a)) {
  57. puts("Invalid I2C EEPROM signature.\n");
  58. env_set("unit_serial", "invalid");
  59. env_set("unit_ident", "VINing-xxxx-STD");
  60. env_set("hostname", "vining-invalid");
  61. return 0;
  62. }
  63. /* If 'unit_serial' is already set, do nothing. */
  64. if (!env_get("unit_serial")) {
  65. /* This field is Big Endian ! */
  66. serial = (data[0x54] << 24) | (data[0x55] << 16) |
  67. (data[0x56] << 8) | (data[0x57] << 0);
  68. memset(str, 0, sizeof(str));
  69. sprintf(str, "%07i", serial);
  70. env_set("unit_serial", str);
  71. }
  72. if (!env_get("unit_ident")) {
  73. memset(str, 0, sizeof(str));
  74. memcpy(str, &data[0x2e], 18);
  75. env_set("unit_ident", str);
  76. }
  77. /* Set ethernet address from EEPROM. */
  78. if (!env_get("ethaddr") && is_valid_ethaddr(&data[0x62]))
  79. eth_env_set_enetaddr("ethaddr", &data[0x62]);
  80. if (!env_get("eth1addr") && is_valid_ethaddr(&data[0x6a]))
  81. eth_env_set_enetaddr("eth1addr", &data[0x6a]);
  82. return 0;
  83. }
  84. #endif