reset.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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 BCM3368_RESET_SPI SOFTRESET_3368_SPI_MASK
  31. #define BCM3368_RESET_ENET SOFTRESET_3368_ENET_MASK
  32. #define BCM3368_RESET_USBH 0
  33. #define BCM3368_RESET_USBD SOFTRESET_3368_USBS_MASK
  34. #define BCM3368_RESET_DSL 0
  35. #define BCM3368_RESET_SAR 0
  36. #define BCM3368_RESET_EPHY SOFTRESET_3368_EPHY_MASK
  37. #define BCM3368_RESET_ENETSW 0
  38. #define BCM3368_RESET_PCM SOFTRESET_3368_PCM_MASK
  39. #define BCM3368_RESET_MPI SOFTRESET_3368_MPI_MASK
  40. #define BCM3368_RESET_PCIE 0
  41. #define BCM3368_RESET_PCIE_EXT 0
  42. #define BCM6328_RESET_SPI SOFTRESET_6328_SPI_MASK
  43. #define BCM6328_RESET_ENET 0
  44. #define BCM6328_RESET_USBH SOFTRESET_6328_USBH_MASK
  45. #define BCM6328_RESET_USBD SOFTRESET_6328_USBS_MASK
  46. #define BCM6328_RESET_DSL 0
  47. #define BCM6328_RESET_SAR SOFTRESET_6328_SAR_MASK
  48. #define BCM6328_RESET_EPHY SOFTRESET_6328_EPHY_MASK
  49. #define BCM6328_RESET_ENETSW SOFTRESET_6328_ENETSW_MASK
  50. #define BCM6328_RESET_PCM SOFTRESET_6328_PCM_MASK
  51. #define BCM6328_RESET_MPI 0
  52. #define BCM6328_RESET_PCIE \
  53. (SOFTRESET_6328_PCIE_MASK | \
  54. SOFTRESET_6328_PCIE_CORE_MASK | \
  55. SOFTRESET_6328_PCIE_HARD_MASK)
  56. #define BCM6328_RESET_PCIE_EXT SOFTRESET_6328_PCIE_EXT_MASK
  57. #define BCM6338_RESET_SPI SOFTRESET_6338_SPI_MASK
  58. #define BCM6338_RESET_ENET SOFTRESET_6338_ENET_MASK
  59. #define BCM6338_RESET_USBH SOFTRESET_6338_USBH_MASK
  60. #define BCM6338_RESET_USBD SOFTRESET_6338_USBS_MASK
  61. #define BCM6338_RESET_DSL SOFTRESET_6338_ADSL_MASK
  62. #define BCM6338_RESET_SAR SOFTRESET_6338_SAR_MASK
  63. #define BCM6338_RESET_EPHY 0
  64. #define BCM6338_RESET_ENETSW 0
  65. #define BCM6338_RESET_PCM 0
  66. #define BCM6338_RESET_MPI 0
  67. #define BCM6338_RESET_PCIE 0
  68. #define BCM6338_RESET_PCIE_EXT 0
  69. #define BCM6348_RESET_SPI SOFTRESET_6348_SPI_MASK
  70. #define BCM6348_RESET_ENET SOFTRESET_6348_ENET_MASK
  71. #define BCM6348_RESET_USBH SOFTRESET_6348_USBH_MASK
  72. #define BCM6348_RESET_USBD SOFTRESET_6348_USBS_MASK
  73. #define BCM6348_RESET_DSL SOFTRESET_6348_ADSL_MASK
  74. #define BCM6348_RESET_SAR SOFTRESET_6348_SAR_MASK
  75. #define BCM6348_RESET_EPHY 0
  76. #define BCM6348_RESET_ENETSW 0
  77. #define BCM6348_RESET_PCM 0
  78. #define BCM6348_RESET_MPI 0
  79. #define BCM6348_RESET_PCIE 0
  80. #define BCM6348_RESET_PCIE_EXT 0
  81. #define BCM6358_RESET_SPI SOFTRESET_6358_SPI_MASK
  82. #define BCM6358_RESET_ENET SOFTRESET_6358_ENET_MASK
  83. #define BCM6358_RESET_USBH SOFTRESET_6358_USBH_MASK
  84. #define BCM6358_RESET_USBD 0
  85. #define BCM6358_RESET_DSL SOFTRESET_6358_ADSL_MASK
  86. #define BCM6358_RESET_SAR SOFTRESET_6358_SAR_MASK
  87. #define BCM6358_RESET_EPHY SOFTRESET_6358_EPHY_MASK
  88. #define BCM6358_RESET_ENETSW 0
  89. #define BCM6358_RESET_PCM SOFTRESET_6358_PCM_MASK
  90. #define BCM6358_RESET_MPI SOFTRESET_6358_MPI_MASK
  91. #define BCM6358_RESET_PCIE 0
  92. #define BCM6358_RESET_PCIE_EXT 0
  93. #define BCM6362_RESET_SPI SOFTRESET_6362_SPI_MASK
  94. #define BCM6362_RESET_ENET 0
  95. #define BCM6362_RESET_USBH SOFTRESET_6362_USBH_MASK
  96. #define BCM6362_RESET_USBD SOFTRESET_6362_USBS_MASK
  97. #define BCM6362_RESET_DSL 0
  98. #define BCM6362_RESET_SAR SOFTRESET_6362_SAR_MASK
  99. #define BCM6362_RESET_EPHY SOFTRESET_6362_EPHY_MASK
  100. #define BCM6362_RESET_ENETSW SOFTRESET_6362_ENETSW_MASK
  101. #define BCM6362_RESET_PCM SOFTRESET_6362_PCM_MASK
  102. #define BCM6362_RESET_MPI 0
  103. #define BCM6362_RESET_PCIE (SOFTRESET_6362_PCIE_MASK | \
  104. SOFTRESET_6362_PCIE_CORE_MASK)
  105. #define BCM6362_RESET_PCIE_EXT SOFTRESET_6362_PCIE_EXT_MASK
  106. #define BCM6368_RESET_SPI SOFTRESET_6368_SPI_MASK
  107. #define BCM6368_RESET_ENET 0
  108. #define BCM6368_RESET_USBH SOFTRESET_6368_USBH_MASK
  109. #define BCM6368_RESET_USBD SOFTRESET_6368_USBS_MASK
  110. #define BCM6368_RESET_DSL 0
  111. #define BCM6368_RESET_SAR SOFTRESET_6368_SAR_MASK
  112. #define BCM6368_RESET_EPHY SOFTRESET_6368_EPHY_MASK
  113. #define BCM6368_RESET_ENETSW 0
  114. #define BCM6368_RESET_PCM SOFTRESET_6368_PCM_MASK
  115. #define BCM6368_RESET_MPI SOFTRESET_6368_MPI_MASK
  116. #define BCM6368_RESET_PCIE 0
  117. #define BCM6368_RESET_PCIE_EXT 0
  118. #ifdef BCMCPU_RUNTIME_DETECT
  119. /*
  120. * core reset bits
  121. */
  122. static const u32 bcm3368_reset_bits[] = {
  123. __GEN_RESET_BITS_TABLE(3368)
  124. };
  125. static const u32 bcm6328_reset_bits[] = {
  126. __GEN_RESET_BITS_TABLE(6328)
  127. };
  128. static const u32 bcm6338_reset_bits[] = {
  129. __GEN_RESET_BITS_TABLE(6338)
  130. };
  131. static const u32 bcm6348_reset_bits[] = {
  132. __GEN_RESET_BITS_TABLE(6348)
  133. };
  134. static const u32 bcm6358_reset_bits[] = {
  135. __GEN_RESET_BITS_TABLE(6358)
  136. };
  137. static const u32 bcm6362_reset_bits[] = {
  138. __GEN_RESET_BITS_TABLE(6362)
  139. };
  140. static const u32 bcm6368_reset_bits[] = {
  141. __GEN_RESET_BITS_TABLE(6368)
  142. };
  143. const u32 *bcm63xx_reset_bits;
  144. static int reset_reg;
  145. static int __init bcm63xx_reset_bits_init(void)
  146. {
  147. if (BCMCPU_IS_3368()) {
  148. reset_reg = PERF_SOFTRESET_6358_REG;
  149. bcm63xx_reset_bits = bcm3368_reset_bits;
  150. } else if (BCMCPU_IS_6328()) {
  151. reset_reg = PERF_SOFTRESET_6328_REG;
  152. bcm63xx_reset_bits = bcm6328_reset_bits;
  153. } else if (BCMCPU_IS_6338()) {
  154. reset_reg = PERF_SOFTRESET_REG;
  155. bcm63xx_reset_bits = bcm6338_reset_bits;
  156. } else if (BCMCPU_IS_6348()) {
  157. reset_reg = PERF_SOFTRESET_REG;
  158. bcm63xx_reset_bits = bcm6348_reset_bits;
  159. } else if (BCMCPU_IS_6358()) {
  160. reset_reg = PERF_SOFTRESET_6358_REG;
  161. bcm63xx_reset_bits = bcm6358_reset_bits;
  162. } else if (BCMCPU_IS_6362()) {
  163. reset_reg = PERF_SOFTRESET_6362_REG;
  164. bcm63xx_reset_bits = bcm6362_reset_bits;
  165. } else if (BCMCPU_IS_6368()) {
  166. reset_reg = PERF_SOFTRESET_6368_REG;
  167. bcm63xx_reset_bits = bcm6368_reset_bits;
  168. }
  169. return 0;
  170. }
  171. #else
  172. #ifdef CONFIG_BCM63XX_CPU_3368
  173. static const u32 bcm63xx_reset_bits[] = {
  174. __GEN_RESET_BITS_TABLE(3368)
  175. };
  176. #define reset_reg PERF_SOFTRESET_6358_REG
  177. #endif
  178. #ifdef CONFIG_BCM63XX_CPU_6328
  179. static const u32 bcm63xx_reset_bits[] = {
  180. __GEN_RESET_BITS_TABLE(6328)
  181. };
  182. #define reset_reg PERF_SOFTRESET_6328_REG
  183. #endif
  184. #ifdef CONFIG_BCM63XX_CPU_6338
  185. static const u32 bcm63xx_reset_bits[] = {
  186. __GEN_RESET_BITS_TABLE(6338)
  187. };
  188. #define reset_reg PERF_SOFTRESET_REG
  189. #endif
  190. #ifdef CONFIG_BCM63XX_CPU_6345
  191. static const u32 bcm63xx_reset_bits[] = { };
  192. #define reset_reg 0
  193. #endif
  194. #ifdef CONFIG_BCM63XX_CPU_6348
  195. static const u32 bcm63xx_reset_bits[] = {
  196. __GEN_RESET_BITS_TABLE(6348)
  197. };
  198. #define reset_reg PERF_SOFTRESET_REG
  199. #endif
  200. #ifdef CONFIG_BCM63XX_CPU_6358
  201. static const u32 bcm63xx_reset_bits[] = {
  202. __GEN_RESET_BITS_TABLE(6358)
  203. };
  204. #define reset_reg PERF_SOFTRESET_6358_REG
  205. #endif
  206. #ifdef CONFIG_BCM63XX_CPU_6362
  207. static const u32 bcm63xx_reset_bits[] = {
  208. __GEN_RESET_BITS_TABLE(6362)
  209. };
  210. #define reset_reg PERF_SOFTRESET_6362_REG
  211. #endif
  212. #ifdef CONFIG_BCM63XX_CPU_6368
  213. static const u32 bcm63xx_reset_bits[] = {
  214. __GEN_RESET_BITS_TABLE(6368)
  215. };
  216. #define reset_reg PERF_SOFTRESET_6368_REG
  217. #endif
  218. static int __init bcm63xx_reset_bits_init(void) { return 0; }
  219. #endif
  220. static DEFINE_SPINLOCK(reset_mutex);
  221. static void __bcm63xx_core_set_reset(u32 mask, int enable)
  222. {
  223. unsigned long flags;
  224. u32 val;
  225. if (!mask)
  226. return;
  227. spin_lock_irqsave(&reset_mutex, flags);
  228. val = bcm_perf_readl(reset_reg);
  229. if (enable)
  230. val &= ~mask;
  231. else
  232. val |= mask;
  233. bcm_perf_writel(val, reset_reg);
  234. spin_unlock_irqrestore(&reset_mutex, flags);
  235. }
  236. void bcm63xx_core_set_reset(enum bcm63xx_core_reset core, int reset)
  237. {
  238. __bcm63xx_core_set_reset(bcm63xx_reset_bits[core], reset);
  239. }
  240. EXPORT_SYMBOL(bcm63xx_core_set_reset);
  241. postcore_initcall(bcm63xx_reset_bits_init);