ibm440gx_common.c 7.6 KB

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