mpc85xx_ds.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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/lmb.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. #undef DEBUG
  36. #ifdef DEBUG
  37. #define DBG(fmt, args...) printk(KERN_ERR "%s: " fmt, __func__, ## args)
  38. #else
  39. #define DBG(fmt, args...)
  40. #endif
  41. #ifdef CONFIG_PPC_I8259
  42. static void mpc85xx_8259_cascade(unsigned int irq, struct irq_desc *desc)
  43. {
  44. unsigned int cascade_irq = i8259_irq();
  45. if (cascade_irq != NO_IRQ) {
  46. generic_handle_irq(cascade_irq);
  47. }
  48. desc->chip->eoi(irq);
  49. }
  50. #endif /* CONFIG_PPC_I8259 */
  51. void __init mpc85xx_ds_pic_init(void)
  52. {
  53. struct mpic *mpic;
  54. struct resource r;
  55. struct device_node *np;
  56. #ifdef CONFIG_PPC_I8259
  57. struct device_node *cascade_node = NULL;
  58. int cascade_irq;
  59. #endif
  60. unsigned long root = of_get_flat_dt_root();
  61. np = of_find_node_by_type(NULL, "open-pic");
  62. if (np == NULL) {
  63. printk(KERN_ERR "Could not find open-pic node\n");
  64. return;
  65. }
  66. if (of_address_to_resource(np, 0, &r)) {
  67. printk(KERN_ERR "Failed to map mpic register space\n");
  68. of_node_put(np);
  69. return;
  70. }
  71. if (of_flat_dt_is_compatible(root, "fsl,MPC8572DS-CAMP")) {
  72. mpic = mpic_alloc(np, r.start,
  73. MPIC_PRIMARY |
  74. MPIC_BIG_ENDIAN | MPIC_BROKEN_FRR_NIRQS,
  75. 0, 256, " OpenPIC ");
  76. } else {
  77. mpic = mpic_alloc(np, r.start,
  78. MPIC_PRIMARY | MPIC_WANTS_RESET |
  79. MPIC_BIG_ENDIAN | MPIC_BROKEN_FRR_NIRQS |
  80. MPIC_SINGLE_DEST_CPU,
  81. 0, 256, " OpenPIC ");
  82. }
  83. BUG_ON(mpic == NULL);
  84. of_node_put(np);
  85. mpic_init(mpic);
  86. #ifdef CONFIG_PPC_I8259
  87. /* Initialize the i8259 controller */
  88. for_each_node_by_type(np, "interrupt-controller")
  89. if (of_device_is_compatible(np, "chrp,iic")) {
  90. cascade_node = np;
  91. break;
  92. }
  93. if (cascade_node == NULL) {
  94. printk(KERN_DEBUG "Could not find i8259 PIC\n");
  95. return;
  96. }
  97. cascade_irq = irq_of_parse_and_map(cascade_node, 0);
  98. if (cascade_irq == NO_IRQ) {
  99. printk(KERN_ERR "Failed to map cascade interrupt\n");
  100. return;
  101. }
  102. DBG("mpc85xxds: cascade mapped to irq %d\n", cascade_irq);
  103. i8259_init(cascade_node, 0);
  104. of_node_put(cascade_node);
  105. set_irq_chained_handler(cascade_irq, mpc85xx_8259_cascade);
  106. #endif /* CONFIG_PPC_I8259 */
  107. }
  108. #ifdef CONFIG_PCI
  109. static int primary_phb_addr;
  110. extern int uli_exclude_device(struct pci_controller *hose,
  111. u_char bus, u_char devfn);
  112. static int mpc85xx_exclude_device(struct pci_controller *hose,
  113. u_char bus, u_char devfn)
  114. {
  115. struct device_node* node;
  116. struct resource rsrc;
  117. node = hose->dn;
  118. of_address_to_resource(node, 0, &rsrc);
  119. if ((rsrc.start & 0xfffff) == primary_phb_addr) {
  120. return uli_exclude_device(hose, bus, devfn);
  121. }
  122. return PCIBIOS_SUCCESSFUL;
  123. }
  124. #endif /* CONFIG_PCI */
  125. /*
  126. * Setup the architecture
  127. */
  128. #ifdef CONFIG_SMP
  129. extern void __init mpc85xx_smp_init(void);
  130. #endif
  131. static void __init mpc85xx_ds_setup_arch(void)
  132. {
  133. #ifdef CONFIG_PCI
  134. struct device_node *np;
  135. struct pci_controller *hose;
  136. #endif
  137. dma_addr_t max = 0xffffffff;
  138. if (ppc_md.progress)
  139. ppc_md.progress("mpc85xx_ds_setup_arch()", 0);
  140. #ifdef CONFIG_PCI
  141. for_each_node_by_type(np, "pci") {
  142. if (of_device_is_compatible(np, "fsl,mpc8540-pci") ||
  143. of_device_is_compatible(np, "fsl,mpc8548-pcie") ||
  144. of_device_is_compatible(np, "fsl,p2020-pcie")) {
  145. struct resource rsrc;
  146. of_address_to_resource(np, 0, &rsrc);
  147. if ((rsrc.start & 0xfffff) == primary_phb_addr)
  148. fsl_add_bridge(np, 1);
  149. else
  150. fsl_add_bridge(np, 0);
  151. hose = pci_find_hose_for_OF_device(np);
  152. max = min(max, hose->dma_window_base_cur +
  153. hose->dma_window_size);
  154. }
  155. }
  156. ppc_md.pci_exclude_device = mpc85xx_exclude_device;
  157. #endif
  158. #ifdef CONFIG_SMP
  159. mpc85xx_smp_init();
  160. #endif
  161. #ifdef CONFIG_SWIOTLB
  162. if (lmb_end_of_DRAM() > max) {
  163. ppc_swiotlb_enable = 1;
  164. set_pci_dma_ops(&swiotlb_dma_ops);
  165. ppc_md.pci_dma_dev_setup = pci_dma_dev_setup_swiotlb;
  166. }
  167. #endif
  168. printk("MPC85xx DS board from Freescale Semiconductor\n");
  169. }
  170. /*
  171. * Called very early, device-tree isn't unflattened
  172. */
  173. static int __init mpc8544_ds_probe(void)
  174. {
  175. unsigned long root = of_get_flat_dt_root();
  176. if (of_flat_dt_is_compatible(root, "MPC8544DS")) {
  177. #ifdef CONFIG_PCI
  178. primary_phb_addr = 0xb000;
  179. #endif
  180. return 1;
  181. }
  182. return 0;
  183. }
  184. static struct of_device_id __initdata mpc85xxds_ids[] = {
  185. { .type = "soc", },
  186. { .compatible = "soc", },
  187. { .compatible = "simple-bus", },
  188. { .compatible = "gianfar", },
  189. {},
  190. };
  191. static int __init mpc85xxds_publish_devices(void)
  192. {
  193. return of_platform_bus_probe(NULL, mpc85xxds_ids, NULL);
  194. }
  195. machine_device_initcall(mpc8544_ds, mpc85xxds_publish_devices);
  196. machine_device_initcall(mpc8572_ds, mpc85xxds_publish_devices);
  197. machine_device_initcall(p2020_ds, mpc85xxds_publish_devices);
  198. machine_arch_initcall(mpc8544_ds, swiotlb_setup_bus_notifier);
  199. machine_arch_initcall(mpc8572_ds, swiotlb_setup_bus_notifier);
  200. machine_arch_initcall(p2020_ds, swiotlb_setup_bus_notifier);
  201. /*
  202. * Called very early, device-tree isn't unflattened
  203. */
  204. static int __init mpc8572_ds_probe(void)
  205. {
  206. unsigned long root = of_get_flat_dt_root();
  207. if (of_flat_dt_is_compatible(root, "fsl,MPC8572DS")) {
  208. #ifdef CONFIG_PCI
  209. primary_phb_addr = 0x8000;
  210. #endif
  211. return 1;
  212. }
  213. return 0;
  214. }
  215. /*
  216. * Called very early, device-tree isn't unflattened
  217. */
  218. static int __init p2020_ds_probe(void)
  219. {
  220. unsigned long root = of_get_flat_dt_root();
  221. if (of_flat_dt_is_compatible(root, "fsl,P2020DS")) {
  222. #ifdef CONFIG_PCI
  223. primary_phb_addr = 0x9000;
  224. #endif
  225. return 1;
  226. }
  227. return 0;
  228. }
  229. define_machine(mpc8544_ds) {
  230. .name = "MPC8544 DS",
  231. .probe = mpc8544_ds_probe,
  232. .setup_arch = mpc85xx_ds_setup_arch,
  233. .init_IRQ = mpc85xx_ds_pic_init,
  234. #ifdef CONFIG_PCI
  235. .pcibios_fixup_bus = fsl_pcibios_fixup_bus,
  236. #endif
  237. .get_irq = mpic_get_irq,
  238. .restart = fsl_rstcr_restart,
  239. .calibrate_decr = generic_calibrate_decr,
  240. .progress = udbg_progress,
  241. };
  242. define_machine(mpc8572_ds) {
  243. .name = "MPC8572 DS",
  244. .probe = mpc8572_ds_probe,
  245. .setup_arch = mpc85xx_ds_setup_arch,
  246. .init_IRQ = mpc85xx_ds_pic_init,
  247. #ifdef CONFIG_PCI
  248. .pcibios_fixup_bus = fsl_pcibios_fixup_bus,
  249. #endif
  250. .get_irq = mpic_get_irq,
  251. .restart = fsl_rstcr_restart,
  252. .calibrate_decr = generic_calibrate_decr,
  253. .progress = udbg_progress,
  254. };
  255. define_machine(p2020_ds) {
  256. .name = "P2020 DS",
  257. .probe = p2020_ds_probe,
  258. .setup_arch = mpc85xx_ds_setup_arch,
  259. .init_IRQ = mpc85xx_ds_pic_init,
  260. #ifdef CONFIG_PCI
  261. .pcibios_fixup_bus = fsl_pcibios_fixup_bus,
  262. #endif
  263. .get_irq = mpic_get_irq,
  264. .restart = fsl_rstcr_restart,
  265. .calibrate_decr = generic_calibrate_decr,
  266. .progress = udbg_progress,
  267. };