ibm440gx_common.c 7.2 KB

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