ibm440gx_common.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. /*
  2. * PPC440GX system library
  3. *
  4. * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net>
  5. * Copyright (c) 2003 - 2006 Zultys Technologies
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the
  9. * Free Software Foundation; either version 2 of the License, or (at your
  10. * option) any later version.
  11. *
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/interrupt.h>
  15. #include <asm/ibm44x.h>
  16. #include <asm/mmu.h>
  17. #include <asm/processor.h>
  18. #include <syslib/ibm440gx_common.h>
  19. /*
  20. * Calculate 440GX clocks
  21. */
  22. static inline u32 __fix_zero(u32 v, u32 def){
  23. return v ? v : def;
  24. }
  25. void __init ibm440gx_get_clocks(struct ibm44x_clocks* p, unsigned int sys_clk,
  26. unsigned int ser_clk)
  27. {
  28. u32 pllc = CPR_READ(DCRN_CPR_PLLC);
  29. u32 plld = CPR_READ(DCRN_CPR_PLLD);
  30. u32 uart0 = SDR_READ(DCRN_SDR_UART0);
  31. u32 uart1 = SDR_READ(DCRN_SDR_UART1);
  32. #ifdef CONFIG_440EP
  33. u32 uart2 = SDR_READ(DCRN_SDR_UART2);
  34. u32 uart3 = SDR_READ(DCRN_SDR_UART3);
  35. #endif
  36. /* Dividers */
  37. u32 fbdv = __fix_zero((plld >> 24) & 0x1f, 32);
  38. u32 fwdva = __fix_zero((plld >> 16) & 0xf, 16);
  39. u32 fwdvb = __fix_zero((plld >> 8) & 7, 8);
  40. u32 lfbdv = __fix_zero(plld & 0x3f, 64);
  41. u32 pradv0 = __fix_zero((CPR_READ(DCRN_CPR_PRIMAD) >> 24) & 7, 8);
  42. u32 prbdv0 = __fix_zero((CPR_READ(DCRN_CPR_PRIMBD) >> 24) & 7, 8);
  43. u32 opbdv0 = __fix_zero((CPR_READ(DCRN_CPR_OPBD) >> 24) & 3, 4);
  44. u32 perdv0 = __fix_zero((CPR_READ(DCRN_CPR_PERD) >> 24) & 3, 4);
  45. /* Input clocks for primary dividers */
  46. u32 clk_a, clk_b;
  47. if (pllc & 0x40000000){
  48. u32 m;
  49. /* Feedback path */
  50. switch ((pllc >> 24) & 7){
  51. case 0:
  52. /* PLLOUTx */
  53. m = ((pllc & 0x20000000) ? fwdvb : fwdva) * lfbdv;
  54. break;
  55. case 1:
  56. /* CPU */
  57. m = fwdva * pradv0;
  58. break;
  59. case 5:
  60. /* PERClk */
  61. m = fwdvb * prbdv0 * opbdv0 * perdv0;
  62. break;
  63. default:
  64. printk(KERN_EMERG "invalid PLL feedback source\n");
  65. goto bypass;
  66. }
  67. m *= fbdv;
  68. p->vco = sys_clk * m;
  69. clk_a = p->vco / fwdva;
  70. clk_b = p->vco / fwdvb;
  71. }
  72. else {
  73. bypass:
  74. /* Bypass system PLL */
  75. p->vco = 0;
  76. clk_a = clk_b = sys_clk;
  77. }
  78. p->cpu = clk_a / pradv0;
  79. p->plb = clk_b / prbdv0;
  80. p->opb = p->plb / opbdv0;
  81. p->ebc = p->opb / perdv0;
  82. /* UARTs clock */
  83. if (uart0 & 0x00800000)
  84. p->uart0 = ser_clk;
  85. else
  86. p->uart0 = p->plb / __fix_zero(uart0 & 0xff, 256);
  87. if (uart1 & 0x00800000)
  88. p->uart1 = ser_clk;
  89. else
  90. p->uart1 = p->plb / __fix_zero(uart1 & 0xff, 256);
  91. #ifdef CONFIG_440EP
  92. if (uart2 & 0x00800000)
  93. p->uart2 = ser_clk;
  94. else
  95. p->uart2 = p->plb / __fix_zero(uart2 & 0xff, 256);
  96. if (uart3 & 0x00800000)
  97. p->uart3 = ser_clk;
  98. else
  99. p->uart3 = p->plb / __fix_zero(uart3 & 0xff, 256);
  100. #endif
  101. }
  102. /* Issue L2C diagnostic command */
  103. static inline u32 l2c_diag(u32 addr)
  104. {
  105. mtdcr(DCRN_L2C0_ADDR, addr);
  106. mtdcr(DCRN_L2C0_CMD, L2C_CMD_DIAG);
  107. while (!(mfdcr(DCRN_L2C0_SR) & L2C_SR_CC)) ;
  108. return mfdcr(DCRN_L2C0_DATA);
  109. }
  110. static irqreturn_t l2c_error_handler(int irq, void* dev)
  111. {
  112. u32 sr = mfdcr(DCRN_L2C0_SR);
  113. if (sr & L2C_SR_CPE){
  114. /* Read cache trapped address */
  115. u32 addr = l2c_diag(0x42000000);
  116. printk(KERN_EMERG "L2C: Cache Parity Error, addr[16:26] = 0x%08x\n", addr);
  117. }
  118. if (sr & L2C_SR_TPE){
  119. /* Read tag trapped address */
  120. u32 addr = l2c_diag(0x82000000) >> 16;
  121. printk(KERN_EMERG "L2C: Tag Parity Error, addr[16:26] = 0x%08x\n", addr);
  122. }
  123. /* Clear parity errors */
  124. if (sr & (L2C_SR_CPE | L2C_SR_TPE)){
  125. mtdcr(DCRN_L2C0_ADDR, 0);
  126. mtdcr(DCRN_L2C0_CMD, L2C_CMD_CCP | L2C_CMD_CTE);
  127. } else
  128. printk(KERN_EMERG "L2C: LRU error\n");
  129. return IRQ_HANDLED;
  130. }
  131. /* Enable L2 cache */
  132. void __init ibm440gx_l2c_enable(void){
  133. u32 r;
  134. unsigned long flags;
  135. /* Install error handler */
  136. if (request_irq(87, l2c_error_handler, IRQF_DISABLED, "L2C", 0) < 0){
  137. printk(KERN_ERR "Cannot install L2C error handler, cache is not enabled\n");
  138. return;
  139. }
  140. local_irq_save(flags);
  141. asm volatile ("sync" ::: "memory");
  142. /* Disable SRAM */
  143. mtdcr(DCRN_SRAM0_DPC, mfdcr(DCRN_SRAM0_DPC) & ~SRAM_DPC_ENABLE);
  144. mtdcr(DCRN_SRAM0_SB0CR, mfdcr(DCRN_SRAM0_SB0CR) & ~SRAM_SBCR_BU_MASK);
  145. mtdcr(DCRN_SRAM0_SB1CR, mfdcr(DCRN_SRAM0_SB1CR) & ~SRAM_SBCR_BU_MASK);
  146. mtdcr(DCRN_SRAM0_SB2CR, mfdcr(DCRN_SRAM0_SB2CR) & ~SRAM_SBCR_BU_MASK);
  147. mtdcr(DCRN_SRAM0_SB3CR, mfdcr(DCRN_SRAM0_SB3CR) & ~SRAM_SBCR_BU_MASK);
  148. /* Enable L2_MODE without ICU/DCU */
  149. r = mfdcr(DCRN_L2C0_CFG) & ~(L2C_CFG_ICU | L2C_CFG_DCU | L2C_CFG_SS_MASK);
  150. r |= L2C_CFG_L2M | L2C_CFG_SS_256;
  151. mtdcr(DCRN_L2C0_CFG, r);
  152. mtdcr(DCRN_L2C0_ADDR, 0);
  153. /* Hardware Clear Command */
  154. mtdcr(DCRN_L2C0_CMD, L2C_CMD_HCC);
  155. while (!(mfdcr(DCRN_L2C0_SR) & L2C_SR_CC)) ;
  156. /* Clear Cache Parity and Tag Errors */
  157. mtdcr(DCRN_L2C0_CMD, L2C_CMD_CCP | L2C_CMD_CTE);
  158. /* Enable 64G snoop region starting at 0 */
  159. r = mfdcr(DCRN_L2C0_SNP0) & ~(L2C_SNP_BA_MASK | L2C_SNP_SSR_MASK);
  160. r |= L2C_SNP_SSR_32G | L2C_SNP_ESR;
  161. mtdcr(DCRN_L2C0_SNP0, r);
  162. r = mfdcr(DCRN_L2C0_SNP1) & ~(L2C_SNP_BA_MASK | L2C_SNP_SSR_MASK);
  163. r |= 0x80000000 | L2C_SNP_SSR_32G | L2C_SNP_ESR;
  164. mtdcr(DCRN_L2C0_SNP1, r);
  165. asm volatile ("sync" ::: "memory");
  166. /* Enable ICU/DCU ports */
  167. r = mfdcr(DCRN_L2C0_CFG);
  168. r &= ~(L2C_CFG_DCW_MASK | L2C_CFG_PMUX_MASK | L2C_CFG_PMIM | L2C_CFG_TPEI
  169. | L2C_CFG_CPEI | L2C_CFG_NAM | L2C_CFG_NBRM);
  170. r |= L2C_CFG_ICU | L2C_CFG_DCU | L2C_CFG_TPC | L2C_CFG_CPC | L2C_CFG_FRAN
  171. | L2C_CFG_CPIM | L2C_CFG_TPIM | L2C_CFG_LIM | L2C_CFG_SMCM;
  172. mtdcr(DCRN_L2C0_CFG, r);
  173. asm volatile ("sync; isync" ::: "memory");
  174. local_irq_restore(flags);
  175. }
  176. /* Disable L2 cache */
  177. void __init ibm440gx_l2c_disable(void){
  178. u32 r;
  179. unsigned long flags;
  180. local_irq_save(flags);
  181. asm volatile ("sync" ::: "memory");
  182. /* Disable L2C mode */
  183. r = mfdcr(DCRN_L2C0_CFG) & ~(L2C_CFG_L2M | L2C_CFG_ICU | L2C_CFG_DCU);
  184. mtdcr(DCRN_L2C0_CFG, r);
  185. /* Enable SRAM */
  186. mtdcr(DCRN_SRAM0_DPC, mfdcr(DCRN_SRAM0_DPC) | SRAM_DPC_ENABLE);
  187. mtdcr(DCRN_SRAM0_SB0CR,
  188. SRAM_SBCR_BAS0 | SRAM_SBCR_BS_64KB | SRAM_SBCR_BU_RW);
  189. mtdcr(DCRN_SRAM0_SB1CR,
  190. SRAM_SBCR_BAS1 | SRAM_SBCR_BS_64KB | SRAM_SBCR_BU_RW);
  191. mtdcr(DCRN_SRAM0_SB2CR,
  192. SRAM_SBCR_BAS2 | SRAM_SBCR_BS_64KB | SRAM_SBCR_BU_RW);
  193. mtdcr(DCRN_SRAM0_SB3CR,
  194. SRAM_SBCR_BAS3 | SRAM_SBCR_BS_64KB | SRAM_SBCR_BU_RW);
  195. asm volatile ("sync; isync" ::: "memory");
  196. local_irq_restore(flags);
  197. }
  198. void __init ibm440gx_l2c_setup(struct ibm44x_clocks* p)
  199. {
  200. /* Disable L2C on rev.A, rev.B and 800MHz version of rev.C,
  201. enable it on all other revisions
  202. */
  203. if (strcmp(cur_cpu_spec->cpu_name, "440GX Rev. A") == 0 ||
  204. strcmp(cur_cpu_spec->cpu_name, "440GX Rev. B") == 0
  205. || (strcmp(cur_cpu_spec->cpu_name, "440GX Rev. C")
  206. == 0 && p->cpu > 667000000))
  207. ibm440gx_l2c_disable();
  208. else
  209. ibm440gx_l2c_enable();
  210. }
  211. int __init ibm440gx_get_eth_grp(void)
  212. {
  213. return (SDR_READ(DCRN_SDR_PFC1) & DCRN_SDR_PFC1_EPS) >> DCRN_SDR_PFC1_EPS_SHIFT;
  214. }
  215. void __init ibm440gx_set_eth_grp(int group)
  216. {
  217. SDR_WRITE(DCRN_SDR_PFC1, (SDR_READ(DCRN_SDR_PFC1) & ~DCRN_SDR_PFC1_EPS) | (group << DCRN_SDR_PFC1_EPS_SHIFT));
  218. }
  219. void __init ibm440gx_tah_enable(void)
  220. {
  221. /* Enable TAH0 and TAH1 */
  222. SDR_WRITE(DCRN_SDR_MFR,SDR_READ(DCRN_SDR_MFR) &
  223. ~DCRN_SDR_MFR_TAH0);
  224. SDR_WRITE(DCRN_SDR_MFR,SDR_READ(DCRN_SDR_MFR) &
  225. ~DCRN_SDR_MFR_TAH1);
  226. }
  227. int ibm440gx_show_cpuinfo(struct seq_file *m){
  228. u32 l2c_cfg = mfdcr(DCRN_L2C0_CFG);
  229. const char* s;
  230. if (l2c_cfg & L2C_CFG_L2M){
  231. switch (l2c_cfg & (L2C_CFG_ICU | L2C_CFG_DCU)){
  232. case L2C_CFG_ICU: s = "I-Cache only"; break;
  233. case L2C_CFG_DCU: s = "D-Cache only"; break;
  234. default: s = "I-Cache/D-Cache"; break;
  235. }
  236. }
  237. else
  238. s = "disabled";
  239. seq_printf(m, "L2-Cache\t: %s (0x%08x 0x%08x)\n", s,
  240. l2c_cfg, mfdcr(DCRN_L2C0_SR));
  241. return 0;
  242. }
  243. void __init ibm440gx_platform_init(unsigned long r3, unsigned long r4,
  244. unsigned long r5, unsigned long r6,
  245. unsigned long r7)
  246. {
  247. /* Erratum 440_43 workaround, disable L1 cache parity checking */
  248. if (!strcmp(cur_cpu_spec->cpu_name, "440GX Rev. C") ||
  249. !strcmp(cur_cpu_spec->cpu_name, "440GX Rev. F"))
  250. mtspr(SPRN_CCR1, mfspr(SPRN_CCR1) | CCR1_DPC);
  251. ibm44x_platform_init(r3, r4, r5, r6, r7);
  252. }