mpc85xx_ds.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. /*
  2. * MPC85xx DS Board Setup
  3. *
  4. * Author Xianghua Xiao (x.xiao@freescale.com)
  5. * Roy Zang <tie-fei.zang@freescale.com>
  6. * - Add PCI/PCI Exprees support
  7. * Copyright 2007 Freescale Semiconductor Inc.
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License as published by the
  11. * Free Software Foundation; either version 2 of the License, or (at your
  12. * option) any later version.
  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 <linux/memblock.h>
  23. #include <asm/system.h>
  24. #include <asm/time.h>
  25. #include <asm/machdep.h>
  26. #include <asm/pci-bridge.h>
  27. #include <mm/mmu_decl.h>
  28. #include <asm/prom.h>
  29. #include <asm/udbg.h>
  30. #include <asm/mpic.h>
  31. #include <asm/i8259.h>
  32. #include <asm/swiotlb.h>
  33. #include <sysdev/fsl_soc.h>
  34. #include <sysdev/fsl_pci.h>
  35. #include "smp.h"
  36. #include "mpc85xx.h"
  37. #undef DEBUG
  38. #ifdef DEBUG
  39. #define DBG(fmt, args...) printk(KERN_ERR "%s: " fmt, __func__, ## args)
  40. #else
  41. #define DBG(fmt, args...)
  42. #endif
  43. #ifdef CONFIG_PPC_I8259
  44. static void mpc85xx_8259_cascade(unsigned int irq, struct irq_desc *desc)
  45. {
  46. struct irq_chip *chip = irq_desc_get_chip(desc);
  47. unsigned int cascade_irq = i8259_irq();
  48. if (cascade_irq != NO_IRQ) {
  49. generic_handle_irq(cascade_irq);
  50. }
  51. chip->irq_eoi(&desc->irq_data);
  52. }
  53. #endif /* CONFIG_PPC_I8259 */
  54. void __init mpc85xx_ds_pic_init(void)
  55. {
  56. struct mpic *mpic;
  57. #ifdef CONFIG_PPC_I8259
  58. struct device_node *np;
  59. struct device_node *cascade_node = NULL;
  60. int cascade_irq;
  61. #endif
  62. unsigned long root = of_get_flat_dt_root();
  63. if (of_flat_dt_is_compatible(root, "fsl,MPC8572DS-CAMP")) {
  64. mpic = mpic_alloc(NULL, 0,
  65. MPIC_BIG_ENDIAN | MPIC_BROKEN_FRR_NIRQS |
  66. MPIC_SINGLE_DEST_CPU,
  67. 0, 256, " OpenPIC ");
  68. } else {
  69. mpic = mpic_alloc(NULL, 0,
  70. MPIC_WANTS_RESET |
  71. MPIC_BIG_ENDIAN | MPIC_BROKEN_FRR_NIRQS |
  72. MPIC_SINGLE_DEST_CPU,
  73. 0, 256, " OpenPIC ");
  74. }
  75. BUG_ON(mpic == NULL);
  76. mpic_init(mpic);
  77. #ifdef CONFIG_PPC_I8259
  78. /* Initialize the i8259 controller */
  79. for_each_node_by_type(np, "interrupt-controller")
  80. if (of_device_is_compatible(np, "chrp,iic")) {
  81. cascade_node = np;
  82. break;
  83. }
  84. if (cascade_node == NULL) {
  85. printk(KERN_DEBUG "Could not find i8259 PIC\n");
  86. return;
  87. }
  88. cascade_irq = irq_of_parse_and_map(cascade_node, 0);
  89. if (cascade_irq == NO_IRQ) {
  90. printk(KERN_ERR "Failed to map cascade interrupt\n");
  91. return;
  92. }
  93. DBG("mpc85xxds: cascade mapped to irq %d\n", cascade_irq);
  94. i8259_init(cascade_node, 0);
  95. of_node_put(cascade_node);
  96. irq_set_chained_handler(cascade_irq, mpc85xx_8259_cascade);
  97. #endif /* CONFIG_PPC_I8259 */
  98. }
  99. #ifdef CONFIG_PCI
  100. static int primary_phb_addr;
  101. extern int uli_exclude_device(struct pci_controller *hose,
  102. u_char bus, u_char devfn);
  103. static int mpc85xx_exclude_device(struct pci_controller *hose,
  104. u_char bus, u_char devfn)
  105. {
  106. struct device_node* node;
  107. struct resource rsrc;
  108. node = hose->dn;
  109. of_address_to_resource(node, 0, &rsrc);
  110. if ((rsrc.start & 0xfffff) == primary_phb_addr) {
  111. return uli_exclude_device(hose, bus, devfn);
  112. }
  113. return PCIBIOS_SUCCESSFUL;
  114. }
  115. #endif /* CONFIG_PCI */
  116. /*
  117. * Setup the architecture
  118. */
  119. static void __init mpc85xx_ds_setup_arch(void)
  120. {
  121. #ifdef CONFIG_PCI
  122. struct device_node *np;
  123. struct pci_controller *hose;
  124. #endif
  125. dma_addr_t max = 0xffffffff;
  126. if (ppc_md.progress)
  127. ppc_md.progress("mpc85xx_ds_setup_arch()", 0);
  128. #ifdef CONFIG_PCI
  129. for_each_node_by_type(np, "pci") {
  130. if (of_device_is_compatible(np, "fsl,mpc8540-pci") ||
  131. of_device_is_compatible(np, "fsl,mpc8548-pcie") ||
  132. of_device_is_compatible(np, "fsl,p2020-pcie")) {
  133. struct resource rsrc;
  134. of_address_to_resource(np, 0, &rsrc);
  135. if ((rsrc.start & 0xfffff) == primary_phb_addr)
  136. fsl_add_bridge(np, 1);
  137. else
  138. fsl_add_bridge(np, 0);
  139. hose = pci_find_hose_for_OF_device(np);
  140. max = min(max, hose->dma_window_base_cur +
  141. hose->dma_window_size);
  142. }
  143. }
  144. ppc_md.pci_exclude_device = mpc85xx_exclude_device;
  145. #endif
  146. mpc85xx_smp_init();
  147. #ifdef CONFIG_SWIOTLB
  148. if (memblock_end_of_DRAM() > max) {
  149. ppc_swiotlb_enable = 1;
  150. set_pci_dma_ops(&swiotlb_dma_ops);
  151. ppc_md.pci_dma_dev_setup = pci_dma_dev_setup_swiotlb;
  152. }
  153. #endif
  154. printk("MPC85xx DS board from Freescale Semiconductor\n");
  155. }
  156. /*
  157. * Called very early, device-tree isn't unflattened
  158. */
  159. static int __init mpc8544_ds_probe(void)
  160. {
  161. unsigned long root = of_get_flat_dt_root();
  162. if (of_flat_dt_is_compatible(root, "MPC8544DS")) {
  163. #ifdef CONFIG_PCI
  164. primary_phb_addr = 0xb000;
  165. #endif
  166. return 1;
  167. }
  168. return 0;
  169. }
  170. machine_device_initcall(mpc8544_ds, mpc85xx_common_publish_devices);
  171. machine_device_initcall(mpc8572_ds, mpc85xx_common_publish_devices);
  172. machine_device_initcall(p2020_ds, mpc85xx_common_publish_devices);
  173. machine_arch_initcall(mpc8544_ds, swiotlb_setup_bus_notifier);
  174. machine_arch_initcall(mpc8572_ds, swiotlb_setup_bus_notifier);
  175. machine_arch_initcall(p2020_ds, swiotlb_setup_bus_notifier);
  176. /*
  177. * Called very early, device-tree isn't unflattened
  178. */
  179. static int __init mpc8572_ds_probe(void)
  180. {
  181. unsigned long root = of_get_flat_dt_root();
  182. if (of_flat_dt_is_compatible(root, "fsl,MPC8572DS")) {
  183. #ifdef CONFIG_PCI
  184. primary_phb_addr = 0x8000;
  185. #endif
  186. return 1;
  187. }
  188. return 0;
  189. }
  190. /*
  191. * Called very early, device-tree isn't unflattened
  192. */
  193. static int __init p2020_ds_probe(void)
  194. {
  195. unsigned long root = of_get_flat_dt_root();
  196. if (of_flat_dt_is_compatible(root, "fsl,P2020DS")) {
  197. #ifdef CONFIG_PCI
  198. primary_phb_addr = 0x9000;
  199. #endif
  200. return 1;
  201. }
  202. return 0;
  203. }
  204. define_machine(mpc8544_ds) {
  205. .name = "MPC8544 DS",
  206. .probe = mpc8544_ds_probe,
  207. .setup_arch = mpc85xx_ds_setup_arch,
  208. .init_IRQ = mpc85xx_ds_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(mpc8572_ds) {
  218. .name = "MPC8572 DS",
  219. .probe = mpc8572_ds_probe,
  220. .setup_arch = mpc85xx_ds_setup_arch,
  221. .init_IRQ = mpc85xx_ds_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(p2020_ds) {
  231. .name = "P2020 DS",
  232. .probe = p2020_ds_probe,
  233. .setup_arch = mpc85xx_ds_setup_arch,
  234. .init_IRQ = mpc85xx_ds_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. };