slcr.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /*
  2. * Copyright (c) 2013 Xilinx Inc.
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <asm/io.h>
  8. #include <malloc.h>
  9. #include <asm/arch/hardware.h>
  10. #include <asm/arch/sys_proto.h>
  11. #define SLCR_LOCK_MAGIC 0x767B
  12. #define SLCR_UNLOCK_MAGIC 0xDF0D
  13. #define SLCR_NAND_L2_SEL 0x10
  14. #define SLCR_NAND_L2_SEL_MASK 0x1F
  15. #define SLCR_USB_L1_SEL 0x04
  16. #define SLCR_IDCODE_MASK 0x1F000
  17. #define SLCR_IDCODE_SHIFT 12
  18. /*
  19. * zynq_slcr_mio_get_status - Get the status of MIO peripheral.
  20. *
  21. * @peri_name: Name of the peripheral for checking MIO status
  22. * @get_pins: Pointer to array of get pin for this peripheral
  23. * @num_pins: Number of pins for this peripheral
  24. * @mask: Mask value
  25. * @check_val: Required check value to get the status of periph
  26. */
  27. struct zynq_slcr_mio_get_status {
  28. const char *peri_name;
  29. const int *get_pins;
  30. int num_pins;
  31. u32 mask;
  32. u32 check_val;
  33. };
  34. static const int nand8_pins[] = {
  35. 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13
  36. };
  37. static const int nand16_pins[] = {
  38. 16, 17, 18, 19, 20, 21, 22, 23
  39. };
  40. static const int usb0_pins[] = {
  41. 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39
  42. };
  43. static const int usb1_pins[] = {
  44. 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51
  45. };
  46. static const struct zynq_slcr_mio_get_status mio_periphs[] = {
  47. {
  48. "nand8",
  49. nand8_pins,
  50. ARRAY_SIZE(nand8_pins),
  51. SLCR_NAND_L2_SEL_MASK,
  52. SLCR_NAND_L2_SEL,
  53. },
  54. {
  55. "nand16",
  56. nand16_pins,
  57. ARRAY_SIZE(nand16_pins),
  58. SLCR_NAND_L2_SEL_MASK,
  59. SLCR_NAND_L2_SEL,
  60. },
  61. {
  62. "usb0",
  63. usb0_pins,
  64. ARRAY_SIZE(usb0_pins),
  65. SLCR_USB_L1_SEL,
  66. SLCR_USB_L1_SEL,
  67. },
  68. {
  69. "usb1",
  70. usb1_pins,
  71. ARRAY_SIZE(usb1_pins),
  72. SLCR_USB_L1_SEL,
  73. SLCR_USB_L1_SEL,
  74. },
  75. };
  76. static int slcr_lock = 1; /* 1 means locked, 0 means unlocked */
  77. void zynq_slcr_lock(void)
  78. {
  79. if (!slcr_lock) {
  80. writel(SLCR_LOCK_MAGIC, &slcr_base->slcr_lock);
  81. slcr_lock = 1;
  82. }
  83. }
  84. void zynq_slcr_unlock(void)
  85. {
  86. if (slcr_lock) {
  87. writel(SLCR_UNLOCK_MAGIC, &slcr_base->slcr_unlock);
  88. slcr_lock = 0;
  89. }
  90. }
  91. /* Reset the entire system */
  92. void zynq_slcr_cpu_reset(void)
  93. {
  94. /*
  95. * Unlock the SLCR then reset the system.
  96. * Note that this seems to require raw i/o
  97. * functions or there's a lockup?
  98. */
  99. zynq_slcr_unlock();
  100. /*
  101. * Clear 0x0F000000 bits of reboot status register to workaround
  102. * the FSBL not loading the bitstream after soft-reboot
  103. * This is a temporary solution until we know more.
  104. */
  105. clrbits_le32(&slcr_base->reboot_status, 0xF000000);
  106. writel(1, &slcr_base->pss_rst_ctrl);
  107. }
  108. void zynq_slcr_devcfg_disable(void)
  109. {
  110. u32 reg_val;
  111. zynq_slcr_unlock();
  112. /* Disable AXI interface by asserting FPGA resets */
  113. writel(0xF, &slcr_base->fpga_rst_ctrl);
  114. /* Disable Level shifters before setting PS-PL */
  115. reg_val = readl(&slcr_base->lvl_shftr_en);
  116. reg_val &= ~0xF;
  117. writel(reg_val, &slcr_base->lvl_shftr_en);
  118. /* Set Level Shifters DT618760 */
  119. writel(0xA, &slcr_base->lvl_shftr_en);
  120. zynq_slcr_lock();
  121. }
  122. void zynq_slcr_devcfg_enable(void)
  123. {
  124. zynq_slcr_unlock();
  125. /* Set Level Shifters DT618760 */
  126. writel(0xF, &slcr_base->lvl_shftr_en);
  127. /* Enable AXI interface by de-asserting FPGA resets */
  128. writel(0x0, &slcr_base->fpga_rst_ctrl);
  129. zynq_slcr_lock();
  130. }
  131. u32 zynq_slcr_get_boot_mode(void)
  132. {
  133. /* Get the bootmode register value */
  134. return readl(&slcr_base->boot_mode);
  135. }
  136. u32 zynq_slcr_get_idcode(void)
  137. {
  138. return (readl(&slcr_base->pss_idcode) & SLCR_IDCODE_MASK) >>
  139. SLCR_IDCODE_SHIFT;
  140. }
  141. /*
  142. * zynq_slcr_get_mio_pin_status - Get the MIO pin status of peripheral.
  143. *
  144. * @periph: Name of the peripheral
  145. *
  146. * Returns count to indicate the number of pins configured for the
  147. * given @periph.
  148. */
  149. int zynq_slcr_get_mio_pin_status(const char *periph)
  150. {
  151. const struct zynq_slcr_mio_get_status *mio_ptr;
  152. int val, i, j;
  153. int mio = 0;
  154. for (i = 0; i < ARRAY_SIZE(mio_periphs); i++) {
  155. if (strcmp(periph, mio_periphs[i].peri_name) == 0) {
  156. mio_ptr = &mio_periphs[i];
  157. for (j = 0; j < mio_ptr->num_pins; j++) {
  158. val = readl(&slcr_base->mio_pin
  159. [mio_ptr->get_pins[j]]);
  160. if ((val & mio_ptr->mask) == mio_ptr->check_val)
  161. mio++;
  162. }
  163. break;
  164. }
  165. }
  166. return mio;
  167. }