xes_mpc85xx.c 5.8 KB

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