spl.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (c) 2019 SiFive, Inc
  4. *
  5. * Authors:
  6. * Pragnesh Patel <pragnesh.patel@sifive.com>
  7. */
  8. #include <init.h>
  9. #include <spl.h>
  10. #include <misc.h>
  11. #include <log.h>
  12. #include <linux/delay.h>
  13. #include <linux/io.h>
  14. #include <asm/gpio.h>
  15. #include <asm/arch/gpio.h>
  16. #include <asm/arch/spl.h>
  17. #define GEM_PHY_RESET SIFIVE_GENERIC_GPIO_NR(0, 12)
  18. #define MODE_SELECT_REG 0x1000
  19. #define MODE_SELECT_QSPI 0x6
  20. #define MODE_SELECT_SD 0xb
  21. #define MODE_SELECT_MASK GENMASK(3, 0)
  22. int spl_board_init_f(void)
  23. {
  24. int ret;
  25. ret = spl_soc_init();
  26. if (ret) {
  27. debug("FU540 SPL init failed: %d\n", ret);
  28. return ret;
  29. }
  30. /*
  31. * GEMGXL init VSC8541 PHY reset sequence;
  32. * leave pull-down active for 2ms
  33. */
  34. udelay(2000);
  35. ret = gpio_request(GEM_PHY_RESET, "gem_phy_reset");
  36. if (ret) {
  37. debug("gem_phy_reset gpio request failed: %d\n", ret);
  38. return ret;
  39. }
  40. /* Set GPIO 12 (PHY NRESET) */
  41. ret = gpio_direction_output(GEM_PHY_RESET, 1);
  42. if (ret) {
  43. debug("gem_phy_reset gpio direction set failed: %d\n", ret);
  44. return ret;
  45. }
  46. udelay(1);
  47. /* Reset PHY again to enter unmanaged mode */
  48. gpio_set_value(GEM_PHY_RESET, 0);
  49. udelay(1);
  50. gpio_set_value(GEM_PHY_RESET, 1);
  51. mdelay(15);
  52. return 0;
  53. }
  54. u32 spl_boot_device(void)
  55. {
  56. u32 mode_select = readl((void *)MODE_SELECT_REG);
  57. u32 boot_device = mode_select & MODE_SELECT_MASK;
  58. switch (boot_device) {
  59. case MODE_SELECT_QSPI:
  60. return BOOT_DEVICE_SPI;
  61. case MODE_SELECT_SD:
  62. return BOOT_DEVICE_MMC1;
  63. default:
  64. debug("Unsupported boot device 0x%x but trying MMC1\n",
  65. boot_device);
  66. return BOOT_DEVICE_MMC1;
  67. }
  68. }
  69. #ifdef CONFIG_SPL_LOAD_FIT
  70. int board_fit_config_name_match(const char *name)
  71. {
  72. /* boot using first FIT config */
  73. return 0;
  74. }
  75. #endif