socfpga.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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/global_data.h>
  13. #include <asm/io.h>
  14. #include <asm/gpio.h>
  15. #include <i2c.h>
  16. #include <linux/delay.h>
  17. DECLARE_GLOBAL_DATA_PTR;
  18. /*
  19. * Miscellaneous platform dependent initialisations
  20. */
  21. int board_late_init(void)
  22. {
  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(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 address 0x50 (at bus CONFIG_SYS_EEPROM_BUS_NUM). */
  45. ret = eeprom_read(0x50, 0, data, sizeof(data));
  46. if (ret) {
  47. puts("Cannot read I2C EEPROM.\n");
  48. return 0;
  49. }
  50. /* Check EEPROM signature. */
  51. if (!(data[0] == 0xa5 && data[1] == 0x5a)) {
  52. puts("Invalid I2C EEPROM signature.\n");
  53. env_set("unit_serial", "invalid");
  54. env_set("unit_ident", "VINing-xxxx-STD");
  55. env_set("hostname", "vining-invalid");
  56. return 0;
  57. }
  58. /* If 'unit_serial' is already set, do nothing. */
  59. if (!env_get("unit_serial")) {
  60. /* This field is Big Endian ! */
  61. serial = (data[0x54] << 24) | (data[0x55] << 16) |
  62. (data[0x56] << 8) | (data[0x57] << 0);
  63. memset(str, 0, sizeof(str));
  64. sprintf(str, "%07i", serial);
  65. env_set("unit_serial", str);
  66. }
  67. if (!env_get("unit_ident")) {
  68. memset(str, 0, sizeof(str));
  69. memcpy(str, &data[0x2e], 18);
  70. env_set("unit_ident", str);
  71. }
  72. /* Set ethernet address from EEPROM. */
  73. if (!env_get("ethaddr") && is_valid_ethaddr(&data[0x62]))
  74. eth_env_set_enetaddr("ethaddr", &data[0x62]);
  75. if (!env_get("eth1addr") && is_valid_ethaddr(&data[0x6a]))
  76. eth_env_set_enetaddr("eth1addr", &data[0x6a]);
  77. return 0;
  78. }
  79. #endif