uniphier_boot_device.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /*
  2. * Copyright (c) 2017-2020, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <assert.h>
  7. #include <stdbool.h>
  8. #include <stddef.h>
  9. #include <lib/mmio.h>
  10. #include <lib/utils_def.h>
  11. #include "uniphier.h"
  12. #define UNIPHIER_PINMON0 0x0
  13. #define UNIPHIER_PINMON2 0x8
  14. static const uintptr_t uniphier_pinmon_base[] = {
  15. [UNIPHIER_SOC_LD11] = 0x5f900100,
  16. [UNIPHIER_SOC_LD20] = 0x5f900100,
  17. [UNIPHIER_SOC_PXS3] = 0x5f900100,
  18. };
  19. static bool uniphier_ld11_is_usb_boot(uint32_t pinmon)
  20. {
  21. return !!(~pinmon & 0x00000080);
  22. }
  23. static bool uniphier_ld20_is_usb_boot(uint32_t pinmon)
  24. {
  25. return !!(~pinmon & 0x00000780);
  26. }
  27. static bool uniphier_pxs3_is_usb_boot(uint32_t pinmon)
  28. {
  29. uintptr_t pinmon_base = uniphier_pinmon_base[UNIPHIER_SOC_PXS3];
  30. uint32_t pinmon2 = mmio_read_32(pinmon_base + UNIPHIER_PINMON2);
  31. return !!(pinmon2 & BIT(31));
  32. }
  33. static const unsigned int uniphier_ld11_boot_device_table[] = {
  34. UNIPHIER_BOOT_DEVICE_NAND,
  35. UNIPHIER_BOOT_DEVICE_NAND,
  36. UNIPHIER_BOOT_DEVICE_NAND,
  37. UNIPHIER_BOOT_DEVICE_NAND,
  38. UNIPHIER_BOOT_DEVICE_NAND,
  39. UNIPHIER_BOOT_DEVICE_NAND,
  40. UNIPHIER_BOOT_DEVICE_NAND,
  41. UNIPHIER_BOOT_DEVICE_NAND,
  42. UNIPHIER_BOOT_DEVICE_NAND,
  43. UNIPHIER_BOOT_DEVICE_NAND,
  44. UNIPHIER_BOOT_DEVICE_NAND,
  45. UNIPHIER_BOOT_DEVICE_NAND,
  46. UNIPHIER_BOOT_DEVICE_NAND,
  47. UNIPHIER_BOOT_DEVICE_NAND,
  48. UNIPHIER_BOOT_DEVICE_NAND,
  49. UNIPHIER_BOOT_DEVICE_NAND,
  50. UNIPHIER_BOOT_DEVICE_NAND,
  51. UNIPHIER_BOOT_DEVICE_NAND,
  52. UNIPHIER_BOOT_DEVICE_NAND,
  53. UNIPHIER_BOOT_DEVICE_NAND,
  54. UNIPHIER_BOOT_DEVICE_NAND,
  55. UNIPHIER_BOOT_DEVICE_NAND,
  56. UNIPHIER_BOOT_DEVICE_NAND,
  57. UNIPHIER_BOOT_DEVICE_NAND,
  58. UNIPHIER_BOOT_DEVICE_EMMC,
  59. UNIPHIER_BOOT_DEVICE_EMMC,
  60. UNIPHIER_BOOT_DEVICE_EMMC,
  61. UNIPHIER_BOOT_DEVICE_EMMC,
  62. UNIPHIER_BOOT_DEVICE_EMMC,
  63. UNIPHIER_BOOT_DEVICE_EMMC,
  64. UNIPHIER_BOOT_DEVICE_EMMC,
  65. UNIPHIER_BOOT_DEVICE_NOR,
  66. };
  67. static unsigned int uniphier_ld11_get_boot_device(uint32_t pinmon)
  68. {
  69. unsigned int boot_sel = (pinmon >> 1) & 0x1f;
  70. assert(boot_sel < ARRAY_SIZE(uniphier_ld11_boot_device_table));
  71. return uniphier_ld11_boot_device_table[boot_sel];
  72. }
  73. static const unsigned int uniphier_pxs3_boot_device_table[] = {
  74. UNIPHIER_BOOT_DEVICE_NAND,
  75. UNIPHIER_BOOT_DEVICE_NAND,
  76. UNIPHIER_BOOT_DEVICE_NAND,
  77. UNIPHIER_BOOT_DEVICE_NAND,
  78. UNIPHIER_BOOT_DEVICE_NAND,
  79. UNIPHIER_BOOT_DEVICE_NAND,
  80. UNIPHIER_BOOT_DEVICE_NAND,
  81. UNIPHIER_BOOT_DEVICE_NAND,
  82. UNIPHIER_BOOT_DEVICE_EMMC,
  83. UNIPHIER_BOOT_DEVICE_EMMC,
  84. UNIPHIER_BOOT_DEVICE_EMMC,
  85. UNIPHIER_BOOT_DEVICE_EMMC,
  86. UNIPHIER_BOOT_DEVICE_EMMC,
  87. UNIPHIER_BOOT_DEVICE_EMMC,
  88. UNIPHIER_BOOT_DEVICE_NAND,
  89. UNIPHIER_BOOT_DEVICE_NAND,
  90. };
  91. static unsigned int uniphier_pxs3_get_boot_device(uint32_t pinmon)
  92. {
  93. unsigned int boot_sel = (pinmon >> 1) & 0xf;
  94. assert(boot_sel < ARRAY_SIZE(uniphier_pxs3_boot_device_table));
  95. return uniphier_pxs3_boot_device_table[boot_sel];
  96. }
  97. struct uniphier_boot_device_info {
  98. bool have_boot_swap;
  99. bool (*is_sd_boot)(uint32_t pinmon);
  100. bool (*is_usb_boot)(uint32_t pinmon);
  101. unsigned int (*get_boot_device)(uint32_t pinmon);
  102. };
  103. static const struct uniphier_boot_device_info uniphier_boot_device_info[] = {
  104. [UNIPHIER_SOC_LD11] = {
  105. .have_boot_swap = true,
  106. .is_usb_boot = uniphier_ld11_is_usb_boot,
  107. .get_boot_device = uniphier_ld11_get_boot_device,
  108. },
  109. [UNIPHIER_SOC_LD20] = {
  110. .have_boot_swap = true,
  111. .is_usb_boot = uniphier_ld20_is_usb_boot,
  112. .get_boot_device = uniphier_ld11_get_boot_device,
  113. },
  114. [UNIPHIER_SOC_PXS3] = {
  115. .have_boot_swap = true,
  116. .is_usb_boot = uniphier_pxs3_is_usb_boot,
  117. .get_boot_device = uniphier_pxs3_get_boot_device,
  118. },
  119. };
  120. unsigned int uniphier_get_boot_device(unsigned int soc)
  121. {
  122. const struct uniphier_boot_device_info *info;
  123. uintptr_t pinmon_base;
  124. uint32_t pinmon;
  125. assert(soc < ARRAY_SIZE(uniphier_boot_device_info));
  126. info = &uniphier_boot_device_info[soc];
  127. assert(soc < ARRAY_SIZE(uniphier_boot_device_info));
  128. pinmon_base = uniphier_pinmon_base[soc];
  129. pinmon = mmio_read_32(pinmon_base + UNIPHIER_PINMON0);
  130. if (info->have_boot_swap && !(pinmon & BIT(29)))
  131. return UNIPHIER_BOOT_DEVICE_NOR;
  132. if (info->is_sd_boot && info->is_sd_boot(pinmon))
  133. return UNIPHIER_BOOT_DEVICE_SD;
  134. if (info->is_usb_boot && info->is_usb_boot(pinmon))
  135. return UNIPHIER_BOOT_DEVICE_USB;
  136. return info->get_boot_device(pinmon);
  137. }
  138. static const bool uniphier_have_onchip_scp[] = {
  139. [UNIPHIER_SOC_LD11] = true,
  140. [UNIPHIER_SOC_LD20] = true,
  141. [UNIPHIER_SOC_PXS3] = false,
  142. };
  143. unsigned int uniphier_get_boot_master(unsigned int soc)
  144. {
  145. assert(soc < ARRAY_SIZE(uniphier_have_onchip_scp));
  146. if (uniphier_have_onchip_scp[soc]) {
  147. uintptr_t pinmon_base;
  148. assert(soc < ARRAY_SIZE(uniphier_boot_device_info));
  149. pinmon_base = uniphier_pinmon_base[soc];
  150. if (mmio_read_32(pinmon_base + UNIPHIER_PINMON0) & BIT(27))
  151. return UNIPHIER_BOOT_MASTER_THIS;
  152. else
  153. return UNIPHIER_BOOT_MASTER_SCP;
  154. } else {
  155. return UNIPHIER_BOOT_MASTER_EXT;
  156. }
  157. }