ppc4xx_soc.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /*
  2. * IBM/AMCC PPC4xx SoC setup code
  3. *
  4. * Copyright 2008 DENX Software Engineering, Stefan Roese <sr@denx.de>
  5. *
  6. * L2 cache routines cloned from arch/ppc/syslib/ibm440gx_common.c which is:
  7. * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net>
  8. * Copyright (c) 2003 - 2006 Zultys Technologies
  9. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License as published by the
  12. * Free Software Foundation; either version 2 of the License, or (at your
  13. * option) any later version.
  14. */
  15. #include <linux/stddef.h>
  16. #include <linux/kernel.h>
  17. #include <linux/init.h>
  18. #include <linux/errno.h>
  19. #include <linux/interrupt.h>
  20. #include <linux/irq.h>
  21. #include <linux/of_irq.h>
  22. #include <linux/of_platform.h>
  23. #include <asm/dcr.h>
  24. #include <asm/dcr-regs.h>
  25. #include <asm/reg.h>
  26. static u32 dcrbase_l2c;
  27. /*
  28. * L2-cache
  29. */
  30. /* Issue L2C diagnostic command */
  31. static inline u32 l2c_diag(u32 addr)
  32. {
  33. mtdcr(dcrbase_l2c + DCRN_L2C0_ADDR, addr);
  34. mtdcr(dcrbase_l2c + DCRN_L2C0_CMD, L2C_CMD_DIAG);
  35. while (!(mfdcr(dcrbase_l2c + DCRN_L2C0_SR) & L2C_SR_CC))
  36. ;
  37. return mfdcr(dcrbase_l2c + DCRN_L2C0_DATA);
  38. }
  39. static irqreturn_t l2c_error_handler(int irq, void *dev)
  40. {
  41. u32 sr = mfdcr(dcrbase_l2c + DCRN_L2C0_SR);
  42. if (sr & L2C_SR_CPE) {
  43. /* Read cache trapped address */
  44. u32 addr = l2c_diag(0x42000000);
  45. printk(KERN_EMERG "L2C: Cache Parity Error, addr[16:26] = 0x%08x\n",
  46. addr);
  47. }
  48. if (sr & L2C_SR_TPE) {
  49. /* Read tag trapped address */
  50. u32 addr = l2c_diag(0x82000000) >> 16;
  51. printk(KERN_EMERG "L2C: Tag Parity Error, addr[16:26] = 0x%08x\n",
  52. addr);
  53. }
  54. /* Clear parity errors */
  55. if (sr & (L2C_SR_CPE | L2C_SR_TPE)){
  56. mtdcr(dcrbase_l2c + DCRN_L2C0_ADDR, 0);
  57. mtdcr(dcrbase_l2c + DCRN_L2C0_CMD, L2C_CMD_CCP | L2C_CMD_CTE);
  58. } else {
  59. printk(KERN_EMERG "L2C: LRU error\n");
  60. }
  61. return IRQ_HANDLED;
  62. }
  63. static int __init ppc4xx_l2c_probe(void)
  64. {
  65. struct device_node *np;
  66. u32 r;
  67. unsigned long flags;
  68. int irq;
  69. const u32 *dcrreg;
  70. u32 dcrbase_isram;
  71. int len;
  72. const u32 *prop;
  73. u32 l2_size;
  74. np = of_find_compatible_node(NULL, NULL, "ibm,l2-cache");
  75. if (!np)
  76. return 0;
  77. /* Get l2 cache size */
  78. prop = of_get_property(np, "cache-size", NULL);
  79. if (prop == NULL) {
  80. printk(KERN_ERR "%s: Can't get cache-size!\n", np->full_name);
  81. of_node_put(np);
  82. return -ENODEV;
  83. }
  84. l2_size = prop[0];
  85. /* Map DCRs */
  86. dcrreg = of_get_property(np, "dcr-reg", &len);
  87. if (!dcrreg || (len != 4 * sizeof(u32))) {
  88. printk(KERN_ERR "%s: Can't get DCR register base !",
  89. np->full_name);
  90. of_node_put(np);
  91. return -ENODEV;
  92. }
  93. dcrbase_isram = dcrreg[0];
  94. dcrbase_l2c = dcrreg[2];
  95. /* Get and map irq number from device tree */
  96. irq = irq_of_parse_and_map(np, 0);
  97. if (!irq) {
  98. printk(KERN_ERR "irq_of_parse_and_map failed\n");
  99. of_node_put(np);
  100. return -ENODEV;
  101. }
  102. /* Install error handler */
  103. if (request_irq(irq, l2c_error_handler, 0, "L2C", 0) < 0) {
  104. printk(KERN_ERR "Cannot install L2C error handler"
  105. ", cache is not enabled\n");
  106. of_node_put(np);
  107. return -ENODEV;
  108. }
  109. local_irq_save(flags);
  110. asm volatile ("sync" ::: "memory");
  111. /* Disable SRAM */
  112. mtdcr(dcrbase_isram + DCRN_SRAM0_DPC,
  113. mfdcr(dcrbase_isram + DCRN_SRAM0_DPC) & ~SRAM_DPC_ENABLE);
  114. mtdcr(dcrbase_isram + DCRN_SRAM0_SB0CR,
  115. mfdcr(dcrbase_isram + DCRN_SRAM0_SB0CR) & ~SRAM_SBCR_BU_MASK);
  116. mtdcr(dcrbase_isram + DCRN_SRAM0_SB1CR,
  117. mfdcr(dcrbase_isram + DCRN_SRAM0_SB1CR) & ~SRAM_SBCR_BU_MASK);
  118. mtdcr(dcrbase_isram + DCRN_SRAM0_SB2CR,
  119. mfdcr(dcrbase_isram + DCRN_SRAM0_SB2CR) & ~SRAM_SBCR_BU_MASK);
  120. mtdcr(dcrbase_isram + DCRN_SRAM0_SB3CR,
  121. mfdcr(dcrbase_isram + DCRN_SRAM0_SB3CR) & ~SRAM_SBCR_BU_MASK);
  122. /* Enable L2_MODE without ICU/DCU */
  123. r = mfdcr(dcrbase_l2c + DCRN_L2C0_CFG) &
  124. ~(L2C_CFG_ICU | L2C_CFG_DCU | L2C_CFG_SS_MASK);
  125. r |= L2C_CFG_L2M | L2C_CFG_SS_256;
  126. mtdcr(dcrbase_l2c + DCRN_L2C0_CFG, r);
  127. mtdcr(dcrbase_l2c + DCRN_L2C0_ADDR, 0);
  128. /* Hardware Clear Command */
  129. mtdcr(dcrbase_l2c + DCRN_L2C0_CMD, L2C_CMD_HCC);
  130. while (!(mfdcr(dcrbase_l2c + DCRN_L2C0_SR) & L2C_SR_CC))
  131. ;
  132. /* Clear Cache Parity and Tag Errors */
  133. mtdcr(dcrbase_l2c + DCRN_L2C0_CMD, L2C_CMD_CCP | L2C_CMD_CTE);
  134. /* Enable 64G snoop region starting at 0 */
  135. r = mfdcr(dcrbase_l2c + DCRN_L2C0_SNP0) &
  136. ~(L2C_SNP_BA_MASK | L2C_SNP_SSR_MASK);
  137. r |= L2C_SNP_SSR_32G | L2C_SNP_ESR;
  138. mtdcr(dcrbase_l2c + DCRN_L2C0_SNP0, r);
  139. r = mfdcr(dcrbase_l2c + DCRN_L2C0_SNP1) &
  140. ~(L2C_SNP_BA_MASK | L2C_SNP_SSR_MASK);
  141. r |= 0x80000000 | L2C_SNP_SSR_32G | L2C_SNP_ESR;
  142. mtdcr(dcrbase_l2c + DCRN_L2C0_SNP1, r);
  143. asm volatile ("sync" ::: "memory");
  144. /* Enable ICU/DCU ports */
  145. r = mfdcr(dcrbase_l2c + DCRN_L2C0_CFG);
  146. r &= ~(L2C_CFG_DCW_MASK | L2C_CFG_PMUX_MASK | L2C_CFG_PMIM
  147. | L2C_CFG_TPEI | L2C_CFG_CPEI | L2C_CFG_NAM | L2C_CFG_NBRM);
  148. r |= L2C_CFG_ICU | L2C_CFG_DCU | L2C_CFG_TPC | L2C_CFG_CPC | L2C_CFG_FRAN
  149. | L2C_CFG_CPIM | L2C_CFG_TPIM | L2C_CFG_LIM | L2C_CFG_SMCM;
  150. /* Check for 460EX/GT special handling */
  151. if (of_device_is_compatible(np, "ibm,l2-cache-460ex") ||
  152. of_device_is_compatible(np, "ibm,l2-cache-460gt"))
  153. r |= L2C_CFG_RDBW;
  154. mtdcr(dcrbase_l2c + DCRN_L2C0_CFG, r);
  155. asm volatile ("sync; isync" ::: "memory");
  156. local_irq_restore(flags);
  157. printk(KERN_INFO "%dk L2-cache enabled\n", l2_size >> 10);
  158. of_node_put(np);
  159. return 0;
  160. }
  161. arch_initcall(ppc4xx_l2c_probe);
  162. /*
  163. * Apply a system reset. Alternatively a board specific value may be
  164. * provided via the "reset-type" property in the cpu node.
  165. */
  166. void ppc4xx_reset_system(char *cmd)
  167. {
  168. struct device_node *np;
  169. u32 reset_type = DBCR0_RST_SYSTEM;
  170. const u32 *prop;
  171. np = of_find_node_by_type(NULL, "cpu");
  172. if (np) {
  173. prop = of_get_property(np, "reset-type", NULL);
  174. /*
  175. * Check if property exists and if it is in range:
  176. * 1 - PPC4xx core reset
  177. * 2 - PPC4xx chip reset
  178. * 3 - PPC4xx system reset (default)
  179. */
  180. if ((prop) && ((prop[0] >= 1) && (prop[0] <= 3)))
  181. reset_type = prop[0] << 28;
  182. }
  183. mtspr(SPRN_DBCR0, mfspr(SPRN_DBCR0) | reset_type);
  184. while (1)
  185. ; /* Just in case the reset doesn't work */
  186. }