slcr.c 4.5 KB

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