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