cpu.c 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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) 2008 Maxime Bizon <mbizon@freebox.fr>
  7. * Copyright (C) 2009 Florian Fainelli <florian@openwrt.org>
  8. */
  9. #include <linux/kernel.h>
  10. #include <linux/module.h>
  11. #include <linux/cpu.h>
  12. #include <bcm63xx_cpu.h>
  13. #include <bcm63xx_regs.h>
  14. #include <bcm63xx_io.h>
  15. #include <bcm63xx_irq.h>
  16. const unsigned long *bcm63xx_regs_base;
  17. EXPORT_SYMBOL(bcm63xx_regs_base);
  18. const int *bcm63xx_irqs;
  19. EXPORT_SYMBOL(bcm63xx_irqs);
  20. static u16 bcm63xx_cpu_id;
  21. static u16 bcm63xx_cpu_rev;
  22. static unsigned int bcm63xx_cpu_freq;
  23. static unsigned int bcm63xx_memory_size;
  24. /*
  25. * 6338 register sets and irqs
  26. */
  27. static const unsigned long bcm96338_regs_base[] = {
  28. [RSET_DSL_LMEM] = BCM_6338_DSL_LMEM_BASE,
  29. [RSET_PERF] = BCM_6338_PERF_BASE,
  30. [RSET_TIMER] = BCM_6338_TIMER_BASE,
  31. [RSET_WDT] = BCM_6338_WDT_BASE,
  32. [RSET_UART0] = BCM_6338_UART0_BASE,
  33. [RSET_GPIO] = BCM_6338_GPIO_BASE,
  34. [RSET_SPI] = BCM_6338_SPI_BASE,
  35. [RSET_OHCI0] = BCM_6338_OHCI0_BASE,
  36. [RSET_OHCI_PRIV] = BCM_6338_OHCI_PRIV_BASE,
  37. [RSET_USBH_PRIV] = BCM_6338_USBH_PRIV_BASE,
  38. [RSET_UDC0] = BCM_6338_UDC0_BASE,
  39. [RSET_MPI] = BCM_6338_MPI_BASE,
  40. [RSET_PCMCIA] = BCM_6338_PCMCIA_BASE,
  41. [RSET_SDRAM] = BCM_6338_SDRAM_BASE,
  42. [RSET_DSL] = BCM_6338_DSL_BASE,
  43. [RSET_ENET0] = BCM_6338_ENET0_BASE,
  44. [RSET_ENET1] = BCM_6338_ENET1_BASE,
  45. [RSET_ENETDMA] = BCM_6338_ENETDMA_BASE,
  46. [RSET_MEMC] = BCM_6338_MEMC_BASE,
  47. [RSET_DDR] = BCM_6338_DDR_BASE,
  48. };
  49. static const int bcm96338_irqs[] = {
  50. [IRQ_TIMER] = BCM_6338_TIMER_IRQ,
  51. [IRQ_UART0] = BCM_6338_UART0_IRQ,
  52. [IRQ_DSL] = BCM_6338_DSL_IRQ,
  53. [IRQ_ENET0] = BCM_6338_ENET0_IRQ,
  54. [IRQ_ENET_PHY] = BCM_6338_ENET_PHY_IRQ,
  55. [IRQ_ENET0_RXDMA] = BCM_6338_ENET0_RXDMA_IRQ,
  56. [IRQ_ENET0_TXDMA] = BCM_6338_ENET0_TXDMA_IRQ,
  57. };
  58. /*
  59. * 6345 register sets and irqs
  60. */
  61. static const unsigned long bcm96345_regs_base[] = {
  62. [RSET_DSL_LMEM] = BCM_6345_DSL_LMEM_BASE,
  63. [RSET_PERF] = BCM_6345_PERF_BASE,
  64. [RSET_TIMER] = BCM_6345_TIMER_BASE,
  65. [RSET_WDT] = BCM_6345_WDT_BASE,
  66. [RSET_UART0] = BCM_6345_UART0_BASE,
  67. [RSET_GPIO] = BCM_6345_GPIO_BASE,
  68. [RSET_SPI] = BCM_6345_SPI_BASE,
  69. [RSET_UDC0] = BCM_6345_UDC0_BASE,
  70. [RSET_OHCI0] = BCM_6345_OHCI0_BASE,
  71. [RSET_OHCI_PRIV] = BCM_6345_OHCI_PRIV_BASE,
  72. [RSET_USBH_PRIV] = BCM_6345_USBH_PRIV_BASE,
  73. [RSET_MPI] = BCM_6345_MPI_BASE,
  74. [RSET_PCMCIA] = BCM_6345_PCMCIA_BASE,
  75. [RSET_DSL] = BCM_6345_DSL_BASE,
  76. [RSET_ENET0] = BCM_6345_ENET0_BASE,
  77. [RSET_ENET1] = BCM_6345_ENET1_BASE,
  78. [RSET_ENETDMA] = BCM_6345_ENETDMA_BASE,
  79. [RSET_EHCI0] = BCM_6345_EHCI0_BASE,
  80. [RSET_SDRAM] = BCM_6345_SDRAM_BASE,
  81. [RSET_MEMC] = BCM_6345_MEMC_BASE,
  82. [RSET_DDR] = BCM_6345_DDR_BASE,
  83. };
  84. static const int bcm96345_irqs[] = {
  85. [IRQ_TIMER] = BCM_6345_TIMER_IRQ,
  86. [IRQ_UART0] = BCM_6345_UART0_IRQ,
  87. [IRQ_DSL] = BCM_6345_DSL_IRQ,
  88. [IRQ_ENET0] = BCM_6345_ENET0_IRQ,
  89. [IRQ_ENET_PHY] = BCM_6345_ENET_PHY_IRQ,
  90. [IRQ_ENET0_RXDMA] = BCM_6345_ENET0_RXDMA_IRQ,
  91. [IRQ_ENET0_TXDMA] = BCM_6345_ENET0_TXDMA_IRQ,
  92. };
  93. /*
  94. * 6348 register sets and irqs
  95. */
  96. static const unsigned long bcm96348_regs_base[] = {
  97. [RSET_DSL_LMEM] = BCM_6348_DSL_LMEM_BASE,
  98. [RSET_PERF] = BCM_6348_PERF_BASE,
  99. [RSET_TIMER] = BCM_6348_TIMER_BASE,
  100. [RSET_WDT] = BCM_6348_WDT_BASE,
  101. [RSET_UART0] = BCM_6348_UART0_BASE,
  102. [RSET_GPIO] = BCM_6348_GPIO_BASE,
  103. [RSET_SPI] = BCM_6348_SPI_BASE,
  104. [RSET_OHCI0] = BCM_6348_OHCI0_BASE,
  105. [RSET_OHCI_PRIV] = BCM_6348_OHCI_PRIV_BASE,
  106. [RSET_USBH_PRIV] = BCM_6348_USBH_PRIV_BASE,
  107. [RSET_MPI] = BCM_6348_MPI_BASE,
  108. [RSET_PCMCIA] = BCM_6348_PCMCIA_BASE,
  109. [RSET_SDRAM] = BCM_6348_SDRAM_BASE,
  110. [RSET_DSL] = BCM_6348_DSL_BASE,
  111. [RSET_ENET0] = BCM_6348_ENET0_BASE,
  112. [RSET_ENET1] = BCM_6348_ENET1_BASE,
  113. [RSET_ENETDMA] = BCM_6348_ENETDMA_BASE,
  114. [RSET_MEMC] = BCM_6348_MEMC_BASE,
  115. [RSET_DDR] = BCM_6348_DDR_BASE,
  116. };
  117. static const int bcm96348_irqs[] = {
  118. [IRQ_TIMER] = BCM_6348_TIMER_IRQ,
  119. [IRQ_UART0] = BCM_6348_UART0_IRQ,
  120. [IRQ_DSL] = BCM_6348_DSL_IRQ,
  121. [IRQ_ENET0] = BCM_6348_ENET0_IRQ,
  122. [IRQ_ENET1] = BCM_6348_ENET1_IRQ,
  123. [IRQ_ENET_PHY] = BCM_6348_ENET_PHY_IRQ,
  124. [IRQ_OHCI0] = BCM_6348_OHCI0_IRQ,
  125. [IRQ_PCMCIA] = BCM_6348_PCMCIA_IRQ,
  126. [IRQ_ENET0_RXDMA] = BCM_6348_ENET0_RXDMA_IRQ,
  127. [IRQ_ENET0_TXDMA] = BCM_6348_ENET0_TXDMA_IRQ,
  128. [IRQ_ENET1_RXDMA] = BCM_6348_ENET1_RXDMA_IRQ,
  129. [IRQ_ENET1_TXDMA] = BCM_6348_ENET1_TXDMA_IRQ,
  130. [IRQ_PCI] = BCM_6348_PCI_IRQ,
  131. };
  132. /*
  133. * 6358 register sets and irqs
  134. */
  135. static const unsigned long bcm96358_regs_base[] = {
  136. [RSET_DSL_LMEM] = BCM_6358_DSL_LMEM_BASE,
  137. [RSET_PERF] = BCM_6358_PERF_BASE,
  138. [RSET_TIMER] = BCM_6358_TIMER_BASE,
  139. [RSET_WDT] = BCM_6358_WDT_BASE,
  140. [RSET_UART0] = BCM_6358_UART0_BASE,
  141. [RSET_GPIO] = BCM_6358_GPIO_BASE,
  142. [RSET_SPI] = BCM_6358_SPI_BASE,
  143. [RSET_OHCI0] = BCM_6358_OHCI0_BASE,
  144. [RSET_EHCI0] = BCM_6358_EHCI0_BASE,
  145. [RSET_OHCI_PRIV] = BCM_6358_OHCI_PRIV_BASE,
  146. [RSET_USBH_PRIV] = BCM_6358_USBH_PRIV_BASE,
  147. [RSET_MPI] = BCM_6358_MPI_BASE,
  148. [RSET_PCMCIA] = BCM_6358_PCMCIA_BASE,
  149. [RSET_SDRAM] = BCM_6358_SDRAM_BASE,
  150. [RSET_DSL] = BCM_6358_DSL_BASE,
  151. [RSET_ENET0] = BCM_6358_ENET0_BASE,
  152. [RSET_ENET1] = BCM_6358_ENET1_BASE,
  153. [RSET_ENETDMA] = BCM_6358_ENETDMA_BASE,
  154. [RSET_MEMC] = BCM_6358_MEMC_BASE,
  155. [RSET_DDR] = BCM_6358_DDR_BASE,
  156. };
  157. static const int bcm96358_irqs[] = {
  158. [IRQ_TIMER] = BCM_6358_TIMER_IRQ,
  159. [IRQ_UART0] = BCM_6358_UART0_IRQ,
  160. [IRQ_DSL] = BCM_6358_DSL_IRQ,
  161. [IRQ_ENET0] = BCM_6358_ENET0_IRQ,
  162. [IRQ_ENET1] = BCM_6358_ENET1_IRQ,
  163. [IRQ_ENET_PHY] = BCM_6358_ENET_PHY_IRQ,
  164. [IRQ_OHCI0] = BCM_6358_OHCI0_IRQ,
  165. [IRQ_EHCI0] = BCM_6358_EHCI0_IRQ,
  166. [IRQ_PCMCIA] = BCM_6358_PCMCIA_IRQ,
  167. [IRQ_ENET0_RXDMA] = BCM_6358_ENET0_RXDMA_IRQ,
  168. [IRQ_ENET0_TXDMA] = BCM_6358_ENET0_TXDMA_IRQ,
  169. [IRQ_ENET1_RXDMA] = BCM_6358_ENET1_RXDMA_IRQ,
  170. [IRQ_ENET1_TXDMA] = BCM_6358_ENET1_TXDMA_IRQ,
  171. [IRQ_PCI] = BCM_6358_PCI_IRQ,
  172. };
  173. u16 __bcm63xx_get_cpu_id(void)
  174. {
  175. return bcm63xx_cpu_id;
  176. }
  177. EXPORT_SYMBOL(__bcm63xx_get_cpu_id);
  178. u16 bcm63xx_get_cpu_rev(void)
  179. {
  180. return bcm63xx_cpu_rev;
  181. }
  182. EXPORT_SYMBOL(bcm63xx_get_cpu_rev);
  183. unsigned int bcm63xx_get_cpu_freq(void)
  184. {
  185. return bcm63xx_cpu_freq;
  186. }
  187. unsigned int bcm63xx_get_memory_size(void)
  188. {
  189. return bcm63xx_memory_size;
  190. }
  191. static unsigned int detect_cpu_clock(void)
  192. {
  193. unsigned int tmp, n1 = 0, n2 = 0, m1 = 0;
  194. /* BCM6338 has a fixed 240 Mhz frequency */
  195. if (BCMCPU_IS_6338())
  196. return 240000000;
  197. /* BCM6345 has a fixed 140Mhz frequency */
  198. if (BCMCPU_IS_6345())
  199. return 140000000;
  200. /*
  201. * frequency depends on PLL configuration:
  202. */
  203. if (BCMCPU_IS_6348()) {
  204. /* 16MHz * (N1 + 1) * (N2 + 2) / (M1_CPU + 1) */
  205. tmp = bcm_perf_readl(PERF_MIPSPLLCTL_REG);
  206. n1 = (tmp & MIPSPLLCTL_N1_MASK) >> MIPSPLLCTL_N1_SHIFT;
  207. n2 = (tmp & MIPSPLLCTL_N2_MASK) >> MIPSPLLCTL_N2_SHIFT;
  208. m1 = (tmp & MIPSPLLCTL_M1CPU_MASK) >> MIPSPLLCTL_M1CPU_SHIFT;
  209. n1 += 1;
  210. n2 += 2;
  211. m1 += 1;
  212. }
  213. if (BCMCPU_IS_6358()) {
  214. /* 16MHz * N1 * N2 / M1_CPU */
  215. tmp = bcm_ddr_readl(DDR_DMIPSPLLCFG_REG);
  216. n1 = (tmp & DMIPSPLLCFG_N1_MASK) >> DMIPSPLLCFG_N1_SHIFT;
  217. n2 = (tmp & DMIPSPLLCFG_N2_MASK) >> DMIPSPLLCFG_N2_SHIFT;
  218. m1 = (tmp & DMIPSPLLCFG_M1_MASK) >> DMIPSPLLCFG_M1_SHIFT;
  219. }
  220. return (16 * 1000000 * n1 * n2) / m1;
  221. }
  222. /*
  223. * attempt to detect the amount of memory installed
  224. */
  225. static unsigned int detect_memory_size(void)
  226. {
  227. unsigned int cols = 0, rows = 0, is_32bits = 0, banks = 0;
  228. u32 val;
  229. if (BCMCPU_IS_6345())
  230. return (8 * 1024 * 1024);
  231. if (BCMCPU_IS_6338() || BCMCPU_IS_6348()) {
  232. val = bcm_sdram_readl(SDRAM_CFG_REG);
  233. rows = (val & SDRAM_CFG_ROW_MASK) >> SDRAM_CFG_ROW_SHIFT;
  234. cols = (val & SDRAM_CFG_COL_MASK) >> SDRAM_CFG_COL_SHIFT;
  235. is_32bits = (val & SDRAM_CFG_32B_MASK) ? 1 : 0;
  236. banks = (val & SDRAM_CFG_BANK_MASK) ? 2 : 1;
  237. }
  238. if (BCMCPU_IS_6358()) {
  239. val = bcm_memc_readl(MEMC_CFG_REG);
  240. rows = (val & MEMC_CFG_ROW_MASK) >> MEMC_CFG_ROW_SHIFT;
  241. cols = (val & MEMC_CFG_COL_MASK) >> MEMC_CFG_COL_SHIFT;
  242. is_32bits = (val & MEMC_CFG_32B_MASK) ? 0 : 1;
  243. banks = 2;
  244. }
  245. /* 0 => 11 address bits ... 2 => 13 address bits */
  246. rows += 11;
  247. /* 0 => 8 address bits ... 2 => 10 address bits */
  248. cols += 8;
  249. return 1 << (cols + rows + (is_32bits + 1) + banks);
  250. }
  251. void __init bcm63xx_cpu_init(void)
  252. {
  253. unsigned int tmp, expected_cpu_id;
  254. struct cpuinfo_mips *c = &current_cpu_data;
  255. /* soc registers location depends on cpu type */
  256. expected_cpu_id = 0;
  257. switch (c->cputype) {
  258. /*
  259. * BCM6338 as the same PrId as BCM3302 see arch/mips/kernel/cpu-probe.c
  260. */
  261. case CPU_BCM3302:
  262. expected_cpu_id = BCM6338_CPU_ID;
  263. bcm63xx_regs_base = bcm96338_regs_base;
  264. bcm63xx_irqs = bcm96338_irqs;
  265. break;
  266. case CPU_BCM6345:
  267. expected_cpu_id = BCM6345_CPU_ID;
  268. bcm63xx_regs_base = bcm96345_regs_base;
  269. bcm63xx_irqs = bcm96345_irqs;
  270. break;
  271. case CPU_BCM6348:
  272. expected_cpu_id = BCM6348_CPU_ID;
  273. bcm63xx_regs_base = bcm96348_regs_base;
  274. bcm63xx_irqs = bcm96348_irqs;
  275. break;
  276. case CPU_BCM6358:
  277. expected_cpu_id = BCM6358_CPU_ID;
  278. bcm63xx_regs_base = bcm96358_regs_base;
  279. bcm63xx_irqs = bcm96358_irqs;
  280. break;
  281. }
  282. /*
  283. * really early to panic, but delaying panic would not help since we
  284. * will never get any working console
  285. */
  286. if (!expected_cpu_id)
  287. panic("unsupported Broadcom CPU");
  288. /*
  289. * bcm63xx_regs_base is set, we can access soc registers
  290. */
  291. /* double check CPU type */
  292. tmp = bcm_perf_readl(PERF_REV_REG);
  293. bcm63xx_cpu_id = (tmp & REV_CHIPID_MASK) >> REV_CHIPID_SHIFT;
  294. bcm63xx_cpu_rev = (tmp & REV_REVID_MASK) >> REV_REVID_SHIFT;
  295. if (bcm63xx_cpu_id != expected_cpu_id)
  296. panic("bcm63xx CPU id mismatch");
  297. bcm63xx_cpu_freq = detect_cpu_clock();
  298. bcm63xx_memory_size = detect_memory_size();
  299. printk(KERN_INFO "Detected Broadcom 0x%04x CPU revision %02x\n",
  300. bcm63xx_cpu_id, bcm63xx_cpu_rev);
  301. printk(KERN_INFO "CPU frequency is %u MHz\n",
  302. bcm63xx_cpu_freq / 1000000);
  303. printk(KERN_INFO "%uMB of RAM installed\n",
  304. bcm63xx_memory_size >> 20);
  305. }