soc.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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 "%pOF: Can't get cache-size!\n", np);
  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 "%pOF: Can't get DCR register base !", np);
  89. of_node_put(np);
  90. return -ENODEV;
  91. }
  92. dcrbase_isram = dcrreg[0];
  93. dcrbase_l2c = dcrreg[2];
  94. /* Get and map irq number from device tree */
  95. irq = irq_of_parse_and_map(np, 0);
  96. if (!irq) {
  97. printk(KERN_ERR "irq_of_parse_and_map failed\n");
  98. of_node_put(np);
  99. return -ENODEV;
  100. }
  101. /* Install error handler */
  102. if (request_irq(irq, l2c_error_handler, 0, "L2C", 0) < 0) {
  103. printk(KERN_ERR "Cannot install L2C error handler"
  104. ", cache is not enabled\n");
  105. of_node_put(np);
  106. return -ENODEV;
  107. }
  108. local_irq_save(flags);
  109. asm volatile ("sync" ::: "memory");
  110. /* Disable SRAM */
  111. mtdcr(dcrbase_isram + DCRN_SRAM0_DPC,
  112. mfdcr(dcrbase_isram + DCRN_SRAM0_DPC) & ~SRAM_DPC_ENABLE);
  113. mtdcr(dcrbase_isram + DCRN_SRAM0_SB0CR,
  114. mfdcr(dcrbase_isram + DCRN_SRAM0_SB0CR) & ~SRAM_SBCR_BU_MASK);
  115. mtdcr(dcrbase_isram + DCRN_SRAM0_SB1CR,
  116. mfdcr(dcrbase_isram + DCRN_SRAM0_SB1CR) & ~SRAM_SBCR_BU_MASK);
  117. mtdcr(dcrbase_isram + DCRN_SRAM0_SB2CR,
  118. mfdcr(dcrbase_isram + DCRN_SRAM0_SB2CR) & ~SRAM_SBCR_BU_MASK);
  119. mtdcr(dcrbase_isram + DCRN_SRAM0_SB3CR,
  120. mfdcr(dcrbase_isram + DCRN_SRAM0_SB3CR) & ~SRAM_SBCR_BU_MASK);
  121. /* Enable L2_MODE without ICU/DCU */
  122. r = mfdcr(dcrbase_l2c + DCRN_L2C0_CFG) &
  123. ~(L2C_CFG_ICU | L2C_CFG_DCU | L2C_CFG_SS_MASK);
  124. r |= L2C_CFG_L2M | L2C_CFG_SS_256;
  125. mtdcr(dcrbase_l2c + DCRN_L2C0_CFG, r);
  126. mtdcr(dcrbase_l2c + DCRN_L2C0_ADDR, 0);
  127. /* Hardware Clear Command */
  128. mtdcr(dcrbase_l2c + DCRN_L2C0_CMD, L2C_CMD_HCC);
  129. while (!(mfdcr(dcrbase_l2c + DCRN_L2C0_SR) & L2C_SR_CC))
  130. ;
  131. /* Clear Cache Parity and Tag Errors */
  132. mtdcr(dcrbase_l2c + DCRN_L2C0_CMD, L2C_CMD_CCP | L2C_CMD_CTE);
  133. /* Enable 64G snoop region starting at 0 */
  134. r = mfdcr(dcrbase_l2c + DCRN_L2C0_SNP0) &
  135. ~(L2C_SNP_BA_MASK | L2C_SNP_SSR_MASK);
  136. r |= L2C_SNP_SSR_32G | L2C_SNP_ESR;
  137. mtdcr(dcrbase_l2c + DCRN_L2C0_SNP0, r);
  138. r = mfdcr(dcrbase_l2c + DCRN_L2C0_SNP1) &
  139. ~(L2C_SNP_BA_MASK | L2C_SNP_SSR_MASK);
  140. r |= 0x80000000 | L2C_SNP_SSR_32G | L2C_SNP_ESR;
  141. mtdcr(dcrbase_l2c + DCRN_L2C0_SNP1, r);
  142. asm volatile ("sync" ::: "memory");
  143. /* Enable ICU/DCU ports */
  144. r = mfdcr(dcrbase_l2c + DCRN_L2C0_CFG);
  145. r &= ~(L2C_CFG_DCW_MASK | L2C_CFG_PMUX_MASK | L2C_CFG_PMIM
  146. | L2C_CFG_TPEI | L2C_CFG_CPEI | L2C_CFG_NAM | L2C_CFG_NBRM);
  147. r |= L2C_CFG_ICU | L2C_CFG_DCU | L2C_CFG_TPC | L2C_CFG_CPC | L2C_CFG_FRAN
  148. | L2C_CFG_CPIM | L2C_CFG_TPIM | L2C_CFG_LIM | L2C_CFG_SMCM;
  149. /* Check for 460EX/GT special handling */
  150. if (of_device_is_compatible(np, "ibm,l2-cache-460ex") ||
  151. of_device_is_compatible(np, "ibm,l2-cache-460gt"))
  152. r |= L2C_CFG_RDBW;
  153. mtdcr(dcrbase_l2c + DCRN_L2C0_CFG, r);
  154. asm volatile ("sync; isync" ::: "memory");
  155. local_irq_restore(flags);
  156. printk(KERN_INFO "%dk L2-cache enabled\n", l2_size >> 10);
  157. of_node_put(np);
  158. return 0;
  159. }
  160. arch_initcall(ppc4xx_l2c_probe);
  161. /*
  162. * Apply a system reset. Alternatively a board specific value may be
  163. * provided via the "reset-type" property in the cpu node.
  164. */
  165. void ppc4xx_reset_system(char *cmd)
  166. {
  167. struct device_node *np;
  168. u32 reset_type = DBCR0_RST_SYSTEM;
  169. const u32 *prop;
  170. np = of_find_node_by_type(NULL, "cpu");
  171. if (np) {
  172. prop = of_get_property(np, "reset-type", NULL);
  173. /*
  174. * Check if property exists and if it is in range:
  175. * 1 - PPC4xx core reset
  176. * 2 - PPC4xx chip reset
  177. * 3 - PPC4xx system reset (default)
  178. */
  179. if ((prop) && ((prop[0] >= 1) && (prop[0] <= 3)))
  180. reset_type = prop[0] << 28;
  181. }
  182. mtspr(SPRN_DBCR0, mfspr(SPRN_DBCR0) | reset_type);
  183. while (1)
  184. ; /* Just in case the reset doesn't work */
  185. }