xes_mpc85xx.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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. /* A few bit definitions needed for fixups on some boards */
  33. #define MPC85xx_L2CTL_L2E 0x80000000 /* L2 enable */
  34. #define MPC85xx_L2CTL_L2I 0x40000000 /* L2 flash invalidate */
  35. #define MPC85xx_L2CTL_L2SIZ_MASK 0x30000000 /* L2 SRAM size (R/O) */
  36. void __init xes_mpc85xx_pic_init(void)
  37. {
  38. struct mpic *mpic;
  39. struct resource r;
  40. struct device_node *np;
  41. np = of_find_node_by_type(NULL, "open-pic");
  42. if (np == NULL) {
  43. printk(KERN_ERR "Could not find open-pic node\n");
  44. return;
  45. }
  46. if (of_address_to_resource(np, 0, &r)) {
  47. printk(KERN_ERR "Failed to map mpic register space\n");
  48. of_node_put(np);
  49. return;
  50. }
  51. mpic = mpic_alloc(np, r.start,
  52. MPIC_PRIMARY | MPIC_WANTS_RESET |
  53. MPIC_BIG_ENDIAN | MPIC_BROKEN_FRR_NIRQS,
  54. 0, 256, " OpenPIC ");
  55. BUG_ON(mpic == NULL);
  56. of_node_put(np);
  57. mpic_init(mpic);
  58. }
  59. static void xes_mpc85xx_configure_l2(void __iomem *l2_base)
  60. {
  61. volatile uint32_t ctl, tmp;
  62. asm volatile("msync; isync");
  63. tmp = in_be32(l2_base);
  64. /*
  65. * xMon may have enabled part of L2 as SRAM, so we need to set it
  66. * up for all cache mode just to be safe.
  67. */
  68. printk(KERN_INFO "xes_mpc85xx: Enabling L2 as cache\n");
  69. ctl = MPC85xx_L2CTL_L2E | MPC85xx_L2CTL_L2I;
  70. if (of_machine_is_compatible("MPC8540") ||
  71. of_machine_is_compatible("MPC8560"))
  72. /*
  73. * Assume L2 SRAM is used fully for cache, so set
  74. * L2BLKSZ (bits 4:5) to match L2SIZ (bits 2:3).
  75. */
  76. ctl |= (tmp & MPC85xx_L2CTL_L2SIZ_MASK) >> 2;
  77. asm volatile("msync; isync");
  78. out_be32(l2_base, ctl);
  79. asm volatile("msync; isync");
  80. }
  81. static void xes_mpc85xx_fixups(void)
  82. {
  83. struct device_node *np;
  84. int err;
  85. /*
  86. * Legacy xMon firmware on some X-ES boards does not enable L2
  87. * as cache. We must ensure that they get enabled here.
  88. */
  89. for_each_node_by_name(np, "l2-cache-controller") {
  90. struct resource r[2];
  91. void __iomem *l2_base;
  92. /* Only MPC8548, MPC8540, and MPC8560 boards are affected */
  93. if (!of_device_is_compatible(np,
  94. "fsl,mpc8548-l2-cache-controller") &&
  95. !of_device_is_compatible(np,
  96. "fsl,mpc8540-l2-cache-controller") &&
  97. !of_device_is_compatible(np,
  98. "fsl,mpc8560-l2-cache-controller"))
  99. continue;
  100. err = of_address_to_resource(np, 0, &r[0]);
  101. if (err) {
  102. printk(KERN_WARNING "xes_mpc85xx: Could not get "
  103. "resource for device tree node '%s'",
  104. np->full_name);
  105. continue;
  106. }
  107. l2_base = ioremap(r[0].start, r[0].end - r[0].start + 1);
  108. xes_mpc85xx_configure_l2(l2_base);
  109. }
  110. }
  111. #ifdef CONFIG_PCI
  112. static int primary_phb_addr;
  113. #endif
  114. /*
  115. * Setup the architecture
  116. */
  117. #ifdef CONFIG_SMP
  118. extern void __init mpc85xx_smp_init(void);
  119. #endif
  120. static void __init xes_mpc85xx_setup_arch(void)
  121. {
  122. #ifdef CONFIG_PCI
  123. struct device_node *np;
  124. #endif
  125. struct device_node *root;
  126. const char *model = "Unknown";
  127. root = of_find_node_by_path("/");
  128. if (root == NULL)
  129. return;
  130. model = of_get_property(root, "model", NULL);
  131. printk(KERN_INFO "X-ES MPC85xx-based single-board computer: %s\n",
  132. model + strlen("xes,"));
  133. xes_mpc85xx_fixups();
  134. #ifdef CONFIG_PCI
  135. for_each_node_by_type(np, "pci") {
  136. if (of_device_is_compatible(np, "fsl,mpc8540-pci") ||
  137. of_device_is_compatible(np, "fsl,mpc8548-pcie")) {
  138. struct resource rsrc;
  139. of_address_to_resource(np, 0, &rsrc);
  140. if ((rsrc.start & 0xfffff) == primary_phb_addr)
  141. fsl_add_bridge(np, 1);
  142. else
  143. fsl_add_bridge(np, 0);
  144. }
  145. }
  146. #endif
  147. #ifdef CONFIG_SMP
  148. mpc85xx_smp_init();
  149. #endif
  150. }
  151. static struct of_device_id __initdata xes_mpc85xx_ids[] = {
  152. { .type = "soc", },
  153. { .compatible = "soc", },
  154. { .compatible = "simple-bus", },
  155. { .compatible = "gianfar", },
  156. {},
  157. };
  158. static int __init xes_mpc85xx_publish_devices(void)
  159. {
  160. return of_platform_bus_probe(NULL, xes_mpc85xx_ids, NULL);
  161. }
  162. machine_device_initcall(xes_mpc8572, xes_mpc85xx_publish_devices);
  163. machine_device_initcall(xes_mpc8548, xes_mpc85xx_publish_devices);
  164. machine_device_initcall(xes_mpc8540, xes_mpc85xx_publish_devices);
  165. /*
  166. * Called very early, device-tree isn't unflattened
  167. */
  168. static int __init xes_mpc8572_probe(void)
  169. {
  170. unsigned long root = of_get_flat_dt_root();
  171. if (of_flat_dt_is_compatible(root, "xes,MPC8572")) {
  172. #ifdef CONFIG_PCI
  173. primary_phb_addr = 0x8000;
  174. #endif
  175. return 1;
  176. } else {
  177. return 0;
  178. }
  179. }
  180. static int __init xes_mpc8548_probe(void)
  181. {
  182. unsigned long root = of_get_flat_dt_root();
  183. if (of_flat_dt_is_compatible(root, "xes,MPC8548")) {
  184. #ifdef CONFIG_PCI
  185. primary_phb_addr = 0xb000;
  186. #endif
  187. return 1;
  188. } else {
  189. return 0;
  190. }
  191. }
  192. static int __init xes_mpc8540_probe(void)
  193. {
  194. unsigned long root = of_get_flat_dt_root();
  195. if (of_flat_dt_is_compatible(root, "xes,MPC8540")) {
  196. #ifdef CONFIG_PCI
  197. primary_phb_addr = 0xb000;
  198. #endif
  199. return 1;
  200. } else {
  201. return 0;
  202. }
  203. }
  204. define_machine(xes_mpc8572) {
  205. .name = "X-ES MPC8572",
  206. .probe = xes_mpc8572_probe,
  207. .setup_arch = xes_mpc85xx_setup_arch,
  208. .init_IRQ = xes_mpc85xx_pic_init,
  209. #ifdef CONFIG_PCI
  210. .pcibios_fixup_bus = fsl_pcibios_fixup_bus,
  211. #endif
  212. .get_irq = mpic_get_irq,
  213. .restart = fsl_rstcr_restart,
  214. .calibrate_decr = generic_calibrate_decr,
  215. .progress = udbg_progress,
  216. };
  217. define_machine(xes_mpc8548) {
  218. .name = "X-ES MPC8548",
  219. .probe = xes_mpc8548_probe,
  220. .setup_arch = xes_mpc85xx_setup_arch,
  221. .init_IRQ = xes_mpc85xx_pic_init,
  222. #ifdef CONFIG_PCI
  223. .pcibios_fixup_bus = fsl_pcibios_fixup_bus,
  224. #endif
  225. .get_irq = mpic_get_irq,
  226. .restart = fsl_rstcr_restart,
  227. .calibrate_decr = generic_calibrate_decr,
  228. .progress = udbg_progress,
  229. };
  230. define_machine(xes_mpc8540) {
  231. .name = "X-ES MPC8540",
  232. .probe = xes_mpc8540_probe,
  233. .setup_arch = xes_mpc85xx_setup_arch,
  234. .init_IRQ = xes_mpc85xx_pic_init,
  235. #ifdef CONFIG_PCI
  236. .pcibios_fixup_bus = fsl_pcibios_fixup_bus,
  237. #endif
  238. .get_irq = mpic_get_irq,
  239. .restart = fsl_rstcr_restart,
  240. .calibrate_decr = generic_calibrate_decr,
  241. .progress = udbg_progress,
  242. };