xes_mpc85xx.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. /*
  2. * Copyright (C) 2009 Extreme Engineering Solutions, Inc.
  3. *
  4. * X-ES board-specific functionality
  5. *
  6. * Based on mpc85xx_ds code from Freescale Semiconductor, Inc.
  7. *
  8. * Author: Nate Case <ncase@xes-inc.com>
  9. *
  10. * This is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. */
  14. #include <linux/stddef.h>
  15. #include <linux/kernel.h>
  16. #include <linux/pci.h>
  17. #include <linux/kdev_t.h>
  18. #include <linux/delay.h>
  19. #include <linux/seq_file.h>
  20. #include <linux/interrupt.h>
  21. #include <linux/of_platform.h>
  22. #include <asm/system.h>
  23. #include <asm/time.h>
  24. #include <asm/machdep.h>
  25. #include <asm/pci-bridge.h>
  26. #include <mm/mmu_decl.h>
  27. #include <asm/prom.h>
  28. #include <asm/udbg.h>
  29. #include <asm/mpic.h>
  30. #include <sysdev/fsl_soc.h>
  31. #include <sysdev/fsl_pci.h>
  32. #include "smp.h"
  33. #include "mpc85xx.h"
  34. /* A few bit definitions needed for fixups on some boards */
  35. #define MPC85xx_L2CTL_L2E 0x80000000 /* L2 enable */
  36. #define MPC85xx_L2CTL_L2I 0x40000000 /* L2 flash invalidate */
  37. #define MPC85xx_L2CTL_L2SIZ_MASK 0x30000000 /* L2 SRAM size (R/O) */
  38. void __init xes_mpc85xx_pic_init(void)
  39. {
  40. struct mpic *mpic;
  41. struct device_node *np;
  42. np = of_find_node_by_type(NULL, "open-pic");
  43. if (np == NULL) {
  44. printk(KERN_ERR "Could not find open-pic node\n");
  45. return;
  46. }
  47. mpic = mpic_alloc(np, 0,
  48. MPIC_PRIMARY | MPIC_WANTS_RESET |
  49. MPIC_BIG_ENDIAN | MPIC_BROKEN_FRR_NIRQS,
  50. 0, 256, " OpenPIC ");
  51. BUG_ON(mpic == NULL);
  52. of_node_put(np);
  53. mpic_init(mpic);
  54. }
  55. static void xes_mpc85xx_configure_l2(void __iomem *l2_base)
  56. {
  57. volatile uint32_t ctl, tmp;
  58. asm volatile("msync; isync");
  59. tmp = in_be32(l2_base);
  60. /*
  61. * xMon may have enabled part of L2 as SRAM, so we need to set it
  62. * up for all cache mode just to be safe.
  63. */
  64. printk(KERN_INFO "xes_mpc85xx: Enabling L2 as cache\n");
  65. ctl = MPC85xx_L2CTL_L2E | MPC85xx_L2CTL_L2I;
  66. if (of_machine_is_compatible("MPC8540") ||
  67. of_machine_is_compatible("MPC8560"))
  68. /*
  69. * Assume L2 SRAM is used fully for cache, so set
  70. * L2BLKSZ (bits 4:5) to match L2SIZ (bits 2:3).
  71. */
  72. ctl |= (tmp & MPC85xx_L2CTL_L2SIZ_MASK) >> 2;
  73. asm volatile("msync; isync");
  74. out_be32(l2_base, ctl);
  75. asm volatile("msync; isync");
  76. }
  77. static void xes_mpc85xx_fixups(void)
  78. {
  79. struct device_node *np;
  80. int err;
  81. /*
  82. * Legacy xMon firmware on some X-ES boards does not enable L2
  83. * as cache. We must ensure that they get enabled here.
  84. */
  85. for_each_node_by_name(np, "l2-cache-controller") {
  86. struct resource r[2];
  87. void __iomem *l2_base;
  88. /* Only MPC8548, MPC8540, and MPC8560 boards are affected */
  89. if (!of_device_is_compatible(np,
  90. "fsl,mpc8548-l2-cache-controller") &&
  91. !of_device_is_compatible(np,
  92. "fsl,mpc8540-l2-cache-controller") &&
  93. !of_device_is_compatible(np,
  94. "fsl,mpc8560-l2-cache-controller"))
  95. continue;
  96. err = of_address_to_resource(np, 0, &r[0]);
  97. if (err) {
  98. printk(KERN_WARNING "xes_mpc85xx: Could not get "
  99. "resource for device tree node '%s'",
  100. np->full_name);
  101. continue;
  102. }
  103. l2_base = ioremap(r[0].start, resource_size(&r[0]));
  104. xes_mpc85xx_configure_l2(l2_base);
  105. }
  106. }
  107. #ifdef CONFIG_PCI
  108. static int primary_phb_addr;
  109. #endif
  110. /*
  111. * Setup the architecture
  112. */
  113. static void __init xes_mpc85xx_setup_arch(void)
  114. {
  115. #ifdef CONFIG_PCI
  116. struct device_node *np;
  117. #endif
  118. struct device_node *root;
  119. const char *model = "Unknown";
  120. root = of_find_node_by_path("/");
  121. if (root == NULL)
  122. return;
  123. model = of_get_property(root, "model", NULL);
  124. printk(KERN_INFO "X-ES MPC85xx-based single-board computer: %s\n",
  125. model + strlen("xes,"));
  126. xes_mpc85xx_fixups();
  127. #ifdef CONFIG_PCI
  128. for_each_node_by_type(np, "pci") {
  129. if (of_device_is_compatible(np, "fsl,mpc8540-pci") ||
  130. of_device_is_compatible(np, "fsl,mpc8548-pcie")) {
  131. struct resource rsrc;
  132. of_address_to_resource(np, 0, &rsrc);
  133. if ((rsrc.start & 0xfffff) == primary_phb_addr)
  134. fsl_add_bridge(np, 1);
  135. else
  136. fsl_add_bridge(np, 0);
  137. }
  138. }
  139. #endif
  140. mpc85xx_smp_init();
  141. }
  142. machine_device_initcall(xes_mpc8572, mpc85xx_common_publish_devices);
  143. machine_device_initcall(xes_mpc8548, mpc85xx_common_publish_devices);
  144. machine_device_initcall(xes_mpc8540, mpc85xx_common_publish_devices);
  145. /*
  146. * Called very early, device-tree isn't unflattened
  147. */
  148. static int __init xes_mpc8572_probe(void)
  149. {
  150. unsigned long root = of_get_flat_dt_root();
  151. if (of_flat_dt_is_compatible(root, "xes,MPC8572")) {
  152. #ifdef CONFIG_PCI
  153. primary_phb_addr = 0x8000;
  154. #endif
  155. return 1;
  156. } else {
  157. return 0;
  158. }
  159. }
  160. static int __init xes_mpc8548_probe(void)
  161. {
  162. unsigned long root = of_get_flat_dt_root();
  163. if (of_flat_dt_is_compatible(root, "xes,MPC8548")) {
  164. #ifdef CONFIG_PCI
  165. primary_phb_addr = 0xb000;
  166. #endif
  167. return 1;
  168. } else {
  169. return 0;
  170. }
  171. }
  172. static int __init xes_mpc8540_probe(void)
  173. {
  174. unsigned long root = of_get_flat_dt_root();
  175. if (of_flat_dt_is_compatible(root, "xes,MPC8540")) {
  176. #ifdef CONFIG_PCI
  177. primary_phb_addr = 0xb000;
  178. #endif
  179. return 1;
  180. } else {
  181. return 0;
  182. }
  183. }
  184. define_machine(xes_mpc8572) {
  185. .name = "X-ES MPC8572",
  186. .probe = xes_mpc8572_probe,
  187. .setup_arch = xes_mpc85xx_setup_arch,
  188. .init_IRQ = xes_mpc85xx_pic_init,
  189. #ifdef CONFIG_PCI
  190. .pcibios_fixup_bus = fsl_pcibios_fixup_bus,
  191. #endif
  192. .get_irq = mpic_get_irq,
  193. .restart = fsl_rstcr_restart,
  194. .calibrate_decr = generic_calibrate_decr,
  195. .progress = udbg_progress,
  196. };
  197. define_machine(xes_mpc8548) {
  198. .name = "X-ES MPC8548",
  199. .probe = xes_mpc8548_probe,
  200. .setup_arch = xes_mpc85xx_setup_arch,
  201. .init_IRQ = xes_mpc85xx_pic_init,
  202. #ifdef CONFIG_PCI
  203. .pcibios_fixup_bus = fsl_pcibios_fixup_bus,
  204. #endif
  205. .get_irq = mpic_get_irq,
  206. .restart = fsl_rstcr_restart,
  207. .calibrate_decr = generic_calibrate_decr,
  208. .progress = udbg_progress,
  209. };
  210. define_machine(xes_mpc8540) {
  211. .name = "X-ES MPC8540",
  212. .probe = xes_mpc8540_probe,
  213. .setup_arch = xes_mpc85xx_setup_arch,
  214. .init_IRQ = xes_mpc85xx_pic_init,
  215. #ifdef CONFIG_PCI
  216. .pcibios_fixup_bus = fsl_pcibios_fixup_bus,
  217. #endif
  218. .get_irq = mpic_get_irq,
  219. .restart = fsl_rstcr_restart,
  220. .calibrate_decr = generic_calibrate_decr,
  221. .progress = udbg_progress,
  222. };