socfpga.c 2.1 KB

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