xes_mpc85xx.c 5.8 KB

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