holly.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. /*
  2. * Board setup routines for the IBM 750GX/CL platform w/ TSI10x bridge
  3. *
  4. * Copyright 2007 IBM Corporation
  5. *
  6. * Stephen Winiecki <stevewin@us.ibm.com>
  7. * Josh Boyer <jwboyer@linux.vnet.ibm.com>
  8. *
  9. * Based on code from mpc7448_hpc2.c
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License
  13. * version 2 as published by the Free Software Foundation.
  14. */
  15. #include <linux/stddef.h>
  16. #include <linux/kernel.h>
  17. #include <linux/pci.h>
  18. #include <linux/kdev_t.h>
  19. #include <linux/console.h>
  20. #include <linux/delay.h>
  21. #include <linux/irq.h>
  22. #include <linux/ide.h>
  23. #include <linux/seq_file.h>
  24. #include <linux/root_dev.h>
  25. #include <linux/serial.h>
  26. #include <linux/tty.h>
  27. #include <linux/serial_core.h>
  28. #include <asm/system.h>
  29. #include <asm/time.h>
  30. #include <asm/machdep.h>
  31. #include <asm/prom.h>
  32. #include <asm/udbg.h>
  33. #include <asm/tsi108.h>
  34. #include <asm/pci-bridge.h>
  35. #include <asm/reg.h>
  36. #include <mm/mmu_decl.h>
  37. #include <asm/tsi108_irq.h>
  38. #include <asm/tsi108_pci.h>
  39. #include <asm/mpic.h>
  40. #include <asm/of_platform.h>
  41. #undef DEBUG
  42. #define HOLLY_PCI_CFG_PHYS 0x7c000000
  43. int holly_exclude_device(u_char bus, u_char devfn)
  44. {
  45. if (bus == 0 && PCI_SLOT(devfn) == 0)
  46. return PCIBIOS_DEVICE_NOT_FOUND;
  47. else
  48. return PCIBIOS_SUCCESSFUL;
  49. }
  50. static void holly_remap_bridge(void)
  51. {
  52. u32 lut_val, lut_addr;
  53. int i;
  54. printk(KERN_INFO "Remapping PCI bridge\n");
  55. /* Re-init the PCI bridge and LUT registers to have mappings that don't
  56. * rely on PIBS
  57. */
  58. lut_addr = 0x900;
  59. for (i = 0; i < 31; i++) {
  60. tsi108_write_reg(TSI108_PB_OFFSET + lut_addr, 0x00000201);
  61. lut_addr += 4;
  62. tsi108_write_reg(TSI108_PB_OFFSET + lut_addr, 0x0);
  63. lut_addr += 4;
  64. }
  65. /* Reserve the last LUT entry for PCI I/O space */
  66. tsi108_write_reg(TSI108_PB_OFFSET + lut_addr, 0x00000241);
  67. lut_addr += 4;
  68. tsi108_write_reg(TSI108_PB_OFFSET + lut_addr, 0x0);
  69. /* Map PCI I/O space */
  70. tsi108_write_reg(TSI108_PCI_PFAB_IO_UPPER, 0x0);
  71. tsi108_write_reg(TSI108_PCI_PFAB_IO, 0x1);
  72. /* Map PCI CFG space */
  73. tsi108_write_reg(TSI108_PCI_PFAB_BAR0_UPPER, 0x0);
  74. tsi108_write_reg(TSI108_PCI_PFAB_BAR0, 0x7c000000 | 0x01);
  75. /* We don't need MEM32 and PRM remapping so disable them */
  76. tsi108_write_reg(TSI108_PCI_PFAB_MEM32, 0x0);
  77. tsi108_write_reg(TSI108_PCI_PFAB_PFM3, 0x0);
  78. tsi108_write_reg(TSI108_PCI_PFAB_PFM4, 0x0);
  79. /* Set P2O_BAR0 */
  80. tsi108_write_reg(TSI108_PCI_P2O_BAR0_UPPER, 0x0);
  81. tsi108_write_reg(TSI108_PCI_P2O_BAR0, 0xc0000000);
  82. /* Init the PCI LUTs to do no remapping */
  83. lut_addr = 0x500;
  84. lut_val = 0x00000002;
  85. for (i = 0; i < 32; i++) {
  86. tsi108_write_reg(TSI108_PCI_OFFSET + lut_addr, lut_val);
  87. lut_addr += 4;
  88. tsi108_write_reg(TSI108_PCI_OFFSET + lut_addr, 0x40000000);
  89. lut_addr += 4;
  90. lut_val += 0x02000000;
  91. }
  92. tsi108_write_reg(TSI108_PCI_P2O_PAGE_SIZES, 0x00007900);
  93. /* Set 64-bit PCI bus address for system memory */
  94. tsi108_write_reg(TSI108_PCI_P2O_BAR2_UPPER, 0x0);
  95. tsi108_write_reg(TSI108_PCI_P2O_BAR2, 0x0);
  96. }
  97. static void __init holly_setup_arch(void)
  98. {
  99. struct device_node *cpu;
  100. struct device_node *np;
  101. if (ppc_md.progress)
  102. ppc_md.progress("holly_setup_arch():set_bridge", 0);
  103. cpu = of_find_node_by_type(NULL, "cpu");
  104. if (cpu) {
  105. const unsigned int *fp;
  106. fp = of_get_property(cpu, "clock-frequency", NULL);
  107. if (fp)
  108. loops_per_jiffy = *fp / HZ;
  109. else
  110. loops_per_jiffy = 50000000 / HZ;
  111. of_node_put(cpu);
  112. }
  113. tsi108_csr_vir_base = get_vir_csrbase();
  114. /* setup PCI host bridge */
  115. holly_remap_bridge();
  116. np = of_find_node_by_type(NULL, "pci");
  117. if (np)
  118. tsi108_setup_pci(np, HOLLY_PCI_CFG_PHYS, 1);
  119. ppc_md.pci_exclude_device = holly_exclude_device;
  120. if (ppc_md.progress)
  121. ppc_md.progress("tsi108: resources set", 0x100);
  122. printk(KERN_INFO "PPC750GX/CL Platform\n");
  123. }
  124. /*
  125. * Interrupt setup and service. Interrrupts on the holly come
  126. * from the four external INT pins, PCI interrupts are routed via
  127. * PCI interrupt control registers, it generates internal IRQ23
  128. *
  129. * Interrupt routing on the Holly Board:
  130. * TSI108:PB_INT[0] -> CPU0:INT#
  131. * TSI108:PB_INT[1] -> CPU0:MCP#
  132. * TSI108:PB_INT[2] -> N/C
  133. * TSI108:PB_INT[3] -> N/C
  134. */
  135. static void __init holly_init_IRQ(void)
  136. {
  137. struct mpic *mpic;
  138. phys_addr_t mpic_paddr = 0;
  139. struct device_node *tsi_pic;
  140. #ifdef CONFIG_PCI
  141. unsigned int cascade_pci_irq;
  142. struct device_node *tsi_pci;
  143. struct device_node *cascade_node = NULL;
  144. #endif
  145. tsi_pic = of_find_node_by_type(NULL, "open-pic");
  146. if (tsi_pic) {
  147. unsigned int size;
  148. const void *prop = of_get_property(tsi_pic, "reg", &size);
  149. mpic_paddr = of_translate_address(tsi_pic, prop);
  150. }
  151. if (mpic_paddr == 0) {
  152. printk(KERN_ERR "%s: No tsi108 PIC found !\n", __func__);
  153. return;
  154. }
  155. pr_debug("%s: tsi108 pic phys_addr = 0x%x\n", __func__, (u32) mpic_paddr);
  156. mpic = mpic_alloc(tsi_pic, mpic_paddr,
  157. MPIC_PRIMARY | MPIC_BIG_ENDIAN | MPIC_WANTS_RESET |
  158. MPIC_SPV_EOI | MPIC_NO_PTHROU_DIS | MPIC_REGSET_TSI108,
  159. 24,
  160. NR_IRQS-4, /* num_sources used */
  161. "Tsi108_PIC");
  162. BUG_ON(mpic == NULL);
  163. mpic_assign_isu(mpic, 0, mpic_paddr + 0x100);
  164. mpic_init(mpic);
  165. #ifdef CONFIG_PCI
  166. tsi_pci = of_find_node_by_type(NULL, "pci");
  167. if (tsi_pci == NULL) {
  168. printk(KERN_ERR "%s: No tsi108 pci node found !\n", __func__);
  169. return;
  170. }
  171. cascade_node = of_find_node_by_type(NULL, "pic-router");
  172. if (cascade_node == NULL) {
  173. printk(KERN_ERR "%s: No tsi108 pci cascade node found !\n", __func__);
  174. return;
  175. }
  176. cascade_pci_irq = irq_of_parse_and_map(tsi_pci, 0);
  177. pr_debug("%s: tsi108 cascade_pci_irq = 0x%x\n", __func__, (u32) cascade_pci_irq);
  178. tsi108_pci_int_init(cascade_node);
  179. set_irq_data(cascade_pci_irq, mpic);
  180. set_irq_chained_handler(cascade_pci_irq, tsi108_irq_cascade);
  181. #endif
  182. /* Configure MPIC outputs to CPU0 */
  183. tsi108_write_reg(TSI108_MPIC_OFFSET + 0x30c, 0);
  184. of_node_put(tsi_pic);
  185. }
  186. void holly_show_cpuinfo(struct seq_file *m)
  187. {
  188. seq_printf(m, "vendor\t\t: IBM\n");
  189. seq_printf(m, "machine\t\t: PPC750 GX/CL\n");
  190. }
  191. void holly_restart(char *cmd)
  192. {
  193. __be32 __iomem *ocn_bar1 = NULL;
  194. unsigned long bar;
  195. struct device_node *bridge = NULL;
  196. const void *prop;
  197. int size;
  198. phys_addr_t addr = 0xc0000000;
  199. local_irq_disable();
  200. bridge = of_find_node_by_type(NULL, "tsi-bridge");
  201. if (bridge) {
  202. prop = of_get_property(bridge, "reg", &size);
  203. addr = of_translate_address(bridge, prop);
  204. }
  205. addr += (TSI108_PB_OFFSET + 0x414);
  206. ocn_bar1 = ioremap(addr, 0x4);
  207. /* Turn on the BOOT bit so the addresses are correctly
  208. * routed to the HLP interface */
  209. bar = ioread32be(ocn_bar1);
  210. bar |= 2;
  211. iowrite32be(bar, ocn_bar1);
  212. iosync();
  213. /* Set SRR0 to the reset vector and turn on MSR_IP */
  214. mtspr(SPRN_SRR0, 0xfff00100);
  215. mtspr(SPRN_SRR1, MSR_IP);
  216. /* Do an rfi to jump back to firmware. Somewhat evil,
  217. * but it works
  218. */
  219. __asm__ __volatile__("rfi" : : : "memory");
  220. /* Spin until reset happens. Shouldn't really get here */
  221. for (;;) ;
  222. }
  223. void holly_power_off(void)
  224. {
  225. local_irq_disable();
  226. /* No way to shut power off with software */
  227. for (;;) ;
  228. }
  229. void holly_halt(void)
  230. {
  231. holly_power_off();
  232. }
  233. /*
  234. * Called very early, device-tree isn't unflattened
  235. */
  236. static int __init holly_probe(void)
  237. {
  238. unsigned long root = of_get_flat_dt_root();
  239. if (!of_flat_dt_is_compatible(root, "ibm,holly"))
  240. return 0;
  241. return 1;
  242. }
  243. static int ppc750_machine_check_exception(struct pt_regs *regs)
  244. {
  245. const struct exception_table_entry *entry;
  246. /* Are we prepared to handle this fault */
  247. if ((entry = search_exception_tables(regs->nip)) != NULL) {
  248. tsi108_clear_pci_cfg_error();
  249. regs->msr |= MSR_RI;
  250. regs->nip = entry->fixup;
  251. return 1;
  252. }
  253. return 0;
  254. }
  255. define_machine(holly){
  256. .name = "PPC750 GX/CL TSI",
  257. .probe = holly_probe,
  258. .setup_arch = holly_setup_arch,
  259. .init_IRQ = holly_init_IRQ,
  260. .show_cpuinfo = holly_show_cpuinfo,
  261. .get_irq = mpic_get_irq,
  262. .restart = holly_restart,
  263. .calibrate_decr = generic_calibrate_decr,
  264. .machine_check_exception = ppc750_machine_check_exception,
  265. .progress = udbg_progress,
  266. };