xes_mpc85xx.c 6.5 KB

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