reset.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 2012 Jonas Gorski <jonas.gorski@gmail.com>
  7. */
  8. #include <linux/module.h>
  9. #include <linux/mutex.h>
  10. #include <linux/err.h>
  11. #include <linux/clk.h>
  12. #include <linux/delay.h>
  13. #include <bcm63xx_cpu.h>
  14. #include <bcm63xx_io.h>
  15. #include <bcm63xx_regs.h>
  16. #include <bcm63xx_reset.h>
  17. #define __GEN_RESET_BITS_TABLE(__cpu) \
  18. [BCM63XX_RESET_SPI] = BCM## __cpu ##_RESET_SPI, \
  19. [BCM63XX_RESET_ENET] = BCM## __cpu ##_RESET_ENET, \
  20. [BCM63XX_RESET_USBH] = BCM## __cpu ##_RESET_USBH, \
  21. [BCM63XX_RESET_USBD] = BCM## __cpu ##_RESET_USBD, \
  22. [BCM63XX_RESET_DSL] = BCM## __cpu ##_RESET_DSL, \
  23. [BCM63XX_RESET_SAR] = BCM## __cpu ##_RESET_SAR, \
  24. [BCM63XX_RESET_EPHY] = BCM## __cpu ##_RESET_EPHY, \
  25. [BCM63XX_RESET_ENETSW] = BCM## __cpu ##_RESET_ENETSW, \
  26. [BCM63XX_RESET_PCM] = BCM## __cpu ##_RESET_PCM, \
  27. [BCM63XX_RESET_MPI] = BCM## __cpu ##_RESET_MPI, \
  28. [BCM63XX_RESET_PCIE] = BCM## __cpu ##_RESET_PCIE, \
  29. [BCM63XX_RESET_PCIE_EXT] = BCM## __cpu ##_RESET_PCIE_EXT,
  30. #define BCM6328_RESET_SPI SOFTRESET_6328_SPI_MASK
  31. #define BCM6328_RESET_ENET 0
  32. #define BCM6328_RESET_USBH SOFTRESET_6328_USBH_MASK
  33. #define BCM6328_RESET_USBD SOFTRESET_6328_USBS_MASK
  34. #define BCM6328_RESET_DSL 0
  35. #define BCM6328_RESET_SAR SOFTRESET_6328_SAR_MASK
  36. #define BCM6328_RESET_EPHY SOFTRESET_6328_EPHY_MASK
  37. #define BCM6328_RESET_ENETSW SOFTRESET_6328_ENETSW_MASK
  38. #define BCM6328_RESET_PCM SOFTRESET_6328_PCM_MASK
  39. #define BCM6328_RESET_MPI 0
  40. #define BCM6328_RESET_PCIE \
  41. (SOFTRESET_6328_PCIE_MASK | \
  42. SOFTRESET_6328_PCIE_CORE_MASK | \
  43. SOFTRESET_6328_PCIE_HARD_MASK)
  44. #define BCM6328_RESET_PCIE_EXT SOFTRESET_6328_PCIE_EXT_MASK
  45. #define BCM6338_RESET_SPI SOFTRESET_6338_SPI_MASK
  46. #define BCM6338_RESET_ENET SOFTRESET_6338_ENET_MASK
  47. #define BCM6338_RESET_USBH SOFTRESET_6338_USBH_MASK
  48. #define BCM6338_RESET_USBD SOFTRESET_6338_USBS_MASK
  49. #define BCM6338_RESET_DSL SOFTRESET_6338_ADSL_MASK
  50. #define BCM6338_RESET_SAR SOFTRESET_6338_SAR_MASK
  51. #define BCM6338_RESET_EPHY 0
  52. #define BCM6338_RESET_ENETSW 0
  53. #define BCM6338_RESET_PCM 0
  54. #define BCM6338_RESET_MPI 0
  55. #define BCM6338_RESET_PCIE 0
  56. #define BCM6338_RESET_PCIE_EXT 0
  57. #define BCM6348_RESET_SPI SOFTRESET_6348_SPI_MASK
  58. #define BCM6348_RESET_ENET SOFTRESET_6348_ENET_MASK
  59. #define BCM6348_RESET_USBH SOFTRESET_6348_USBH_MASK
  60. #define BCM6348_RESET_USBD SOFTRESET_6348_USBS_MASK
  61. #define BCM6348_RESET_DSL SOFTRESET_6348_ADSL_MASK
  62. #define BCM6348_RESET_SAR SOFTRESET_6348_SAR_MASK
  63. #define BCM6348_RESET_EPHY 0
  64. #define BCM6348_RESET_ENETSW 0
  65. #define BCM6348_RESET_PCM 0
  66. #define BCM6348_RESET_MPI 0
  67. #define BCM6348_RESET_PCIE 0
  68. #define BCM6348_RESET_PCIE_EXT 0
  69. #define BCM6358_RESET_SPI SOFTRESET_6358_SPI_MASK
  70. #define BCM6358_RESET_ENET SOFTRESET_6358_ENET_MASK
  71. #define BCM6358_RESET_USBH SOFTRESET_6358_USBH_MASK
  72. #define BCM6358_RESET_USBD 0
  73. #define BCM6358_RESET_DSL SOFTRESET_6358_ADSL_MASK
  74. #define BCM6358_RESET_SAR SOFTRESET_6358_SAR_MASK
  75. #define BCM6358_RESET_EPHY SOFTRESET_6358_EPHY_MASK
  76. #define BCM6358_RESET_ENETSW 0
  77. #define BCM6358_RESET_PCM SOFTRESET_6358_PCM_MASK
  78. #define BCM6358_RESET_MPI SOFTRESET_6358_MPI_MASK
  79. #define BCM6358_RESET_PCIE 0
  80. #define BCM6358_RESET_PCIE_EXT 0
  81. #define BCM6368_RESET_SPI SOFTRESET_6368_SPI_MASK
  82. #define BCM6368_RESET_ENET 0
  83. #define BCM6368_RESET_USBH SOFTRESET_6368_USBH_MASK
  84. #define BCM6368_RESET_USBD SOFTRESET_6368_USBS_MASK
  85. #define BCM6368_RESET_DSL 0
  86. #define BCM6368_RESET_SAR SOFTRESET_6368_SAR_MASK
  87. #define BCM6368_RESET_EPHY SOFTRESET_6368_EPHY_MASK
  88. #define BCM6368_RESET_ENETSW 0
  89. #define BCM6368_RESET_PCM SOFTRESET_6368_PCM_MASK
  90. #define BCM6368_RESET_MPI SOFTRESET_6368_MPI_MASK
  91. #define BCM6368_RESET_PCIE 0
  92. #define BCM6368_RESET_PCIE_EXT 0
  93. #ifdef BCMCPU_RUNTIME_DETECT
  94. /*
  95. * core reset bits
  96. */
  97. static const u32 bcm6328_reset_bits[] = {
  98. __GEN_RESET_BITS_TABLE(6328)
  99. };
  100. static const u32 bcm6338_reset_bits[] = {
  101. __GEN_RESET_BITS_TABLE(6338)
  102. };
  103. static const u32 bcm6348_reset_bits[] = {
  104. __GEN_RESET_BITS_TABLE(6348)
  105. };
  106. static const u32 bcm6358_reset_bits[] = {
  107. __GEN_RESET_BITS_TABLE(6358)
  108. };
  109. static const u32 bcm6368_reset_bits[] = {
  110. __GEN_RESET_BITS_TABLE(6368)
  111. };
  112. const u32 *bcm63xx_reset_bits;
  113. static int reset_reg;
  114. static int __init bcm63xx_reset_bits_init(void)
  115. {
  116. if (BCMCPU_IS_6328()) {
  117. reset_reg = PERF_SOFTRESET_6328_REG;
  118. bcm63xx_reset_bits = bcm6328_reset_bits;
  119. } else if (BCMCPU_IS_6338()) {
  120. reset_reg = PERF_SOFTRESET_REG;
  121. bcm63xx_reset_bits = bcm6338_reset_bits;
  122. } else if (BCMCPU_IS_6348()) {
  123. reset_reg = PERF_SOFTRESET_REG;
  124. bcm63xx_reset_bits = bcm6348_reset_bits;
  125. } else if (BCMCPU_IS_6358()) {
  126. reset_reg = PERF_SOFTRESET_6358_REG;
  127. bcm63xx_reset_bits = bcm6358_reset_bits;
  128. } else if (BCMCPU_IS_6368()) {
  129. reset_reg = PERF_SOFTRESET_6368_REG;
  130. bcm63xx_reset_bits = bcm6368_reset_bits;
  131. }
  132. return 0;
  133. }
  134. #else
  135. #ifdef CONFIG_BCM63XX_CPU_6328
  136. static const u32 bcm63xx_reset_bits[] = {
  137. __GEN_RESET_BITS_TABLE(6328)
  138. };
  139. #define reset_reg PERF_SOFTRESET_6328_REG
  140. #endif
  141. #ifdef CONFIG_BCM63XX_CPU_6338
  142. static const u32 bcm63xx_reset_bits[] = {
  143. __GEN_RESET_BITS_TABLE(6338)
  144. };
  145. #define reset_reg PERF_SOFTRESET_REG
  146. #endif
  147. #ifdef CONFIG_BCM63XX_CPU_6345
  148. static const u32 bcm63xx_reset_bits[] = { };
  149. #define reset_reg 0
  150. #endif
  151. #ifdef CONFIG_BCM63XX_CPU_6348
  152. static const u32 bcm63xx_reset_bits[] = {
  153. __GEN_RESET_BITS_TABLE(6348)
  154. };
  155. #define reset_reg PERF_SOFTRESET_REG
  156. #endif
  157. #ifdef CONFIG_BCM63XX_CPU_6358
  158. static const u32 bcm63xx_reset_bits[] = {
  159. __GEN_RESET_BITS_TABLE(6358)
  160. };
  161. #define reset_reg PERF_SOFTRESET_6358_REG
  162. #endif
  163. #ifdef CONFIG_BCM63XX_CPU_6368
  164. static const u32 bcm63xx_reset_bits[] = {
  165. __GEN_RESET_BITS_TABLE(6368)
  166. };
  167. #define reset_reg PERF_SOFTRESET_6368_REG
  168. #endif
  169. static int __init bcm63xx_reset_bits_init(void) { return 0; }
  170. #endif
  171. static DEFINE_SPINLOCK(reset_mutex);
  172. static void __bcm63xx_core_set_reset(u32 mask, int enable)
  173. {
  174. unsigned long flags;
  175. u32 val;
  176. if (!mask)
  177. return;
  178. spin_lock_irqsave(&reset_mutex, flags);
  179. val = bcm_perf_readl(reset_reg);
  180. if (enable)
  181. val &= ~mask;
  182. else
  183. val |= mask;
  184. bcm_perf_writel(val, reset_reg);
  185. spin_unlock_irqrestore(&reset_mutex, flags);
  186. }
  187. void bcm63xx_core_set_reset(enum bcm63xx_core_reset core, int reset)
  188. {
  189. __bcm63xx_core_set_reset(bcm63xx_reset_bits[core], reset);
  190. }
  191. EXPORT_SYMBOL(bcm63xx_core_set_reset);
  192. postcore_initcall(bcm63xx_reset_bits_init);