slcr.c 4.1 KB

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