sycamore.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. /*
  2. * Architecture- / platform-specific boot-time initialization code for
  3. * IBM PowerPC 4xx based boards.
  4. *
  5. * Author: Armin Kuster <akuster@mvista.com>
  6. *
  7. * 2000-2002 (c) MontaVista, Software, Inc. This file is licensed under
  8. * the terms of the GNU General Public License version 2. This program
  9. * is licensed "as is" without any warranty of any kind, whether express
  10. * or implied.
  11. */
  12. #include <linux/init.h>
  13. #include <linux/smp.h>
  14. #include <linux/threads.h>
  15. #include <linux/param.h>
  16. #include <linux/string.h>
  17. #include <linux/pci.h>
  18. #include <linux/rtc.h>
  19. #include <asm/ocp.h>
  20. #include <asm/ppc4xx_pic.h>
  21. #include <asm/system.h>
  22. #include <asm/pci-bridge.h>
  23. #include <asm/machdep.h>
  24. #include <asm/page.h>
  25. #include <asm/time.h>
  26. #include <asm/io.h>
  27. #include <asm/ibm_ocp_pci.h>
  28. #include <asm/todc.h>
  29. #undef DEBUG
  30. #ifdef DEBUG
  31. #define DBG(x...) printk(x)
  32. #else
  33. #define DBG(x...)
  34. #endif
  35. void *kb_cs;
  36. void *kb_data;
  37. void *sycamore_rtc_base;
  38. /*
  39. * Define external IRQ senses and polarities.
  40. */
  41. unsigned char ppc4xx_uic_ext_irq_cfg[] __initdata = {
  42. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* Ext Int 7 */
  43. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* Ext Int 8 */
  44. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* Ext Int 9 */
  45. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* Ext Int 10 */
  46. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* Ext Int 11 */
  47. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* Ext Int 12 */
  48. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* Ext Int 0 */
  49. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* Ext Int 1 */
  50. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* Ext Int 2 */
  51. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* Ext Int 3 */
  52. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* Ext Int 4 */
  53. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* Ext Int 5 */
  54. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* Ext Int 6 */
  55. };
  56. /* Some IRQs unique to Sycamore.
  57. * Used by the generic 405 PCI setup functions in ppc4xx_pci.c
  58. */
  59. int __init
  60. ppc405_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
  61. {
  62. static char pci_irq_table[][4] =
  63. /*
  64. * PCI IDSEL/INTPIN->INTLINE
  65. * A B C D
  66. */
  67. {
  68. {28, 28, 28, 28}, /* IDSEL 1 - PCI slot 1 */
  69. {29, 29, 29, 29}, /* IDSEL 2 - PCI slot 2 */
  70. {30, 30, 30, 30}, /* IDSEL 3 - PCI slot 3 */
  71. {31, 31, 31, 31}, /* IDSEL 4 - PCI slot 4 */
  72. };
  73. const long min_idsel = 1, max_idsel = 4, irqs_per_slot = 4;
  74. return PCI_IRQ_TABLE_LOOKUP;
  75. };
  76. void __init
  77. sycamore_setup_arch(void)
  78. {
  79. void *fpga_brdc;
  80. unsigned char fpga_brdc_data;
  81. void *fpga_enable;
  82. void *fpga_polarity;
  83. void *fpga_status;
  84. void *fpga_trigger;
  85. ppc4xx_setup_arch();
  86. ibm_ocp_set_emac(0, 0);
  87. kb_data = ioremap(SYCAMORE_PS2_BASE, 8);
  88. if (!kb_data) {
  89. printk(KERN_CRIT
  90. "sycamore_setup_arch() kb_data ioremap failed\n");
  91. return;
  92. }
  93. kb_cs = kb_data + 1;
  94. fpga_status = ioremap(PPC40x_FPGA_BASE, 8);
  95. if (!fpga_status) {
  96. printk(KERN_CRIT
  97. "sycamore_setup_arch() fpga_status ioremap failed\n");
  98. return;
  99. }
  100. fpga_enable = fpga_status + 1;
  101. fpga_polarity = fpga_status + 2;
  102. fpga_trigger = fpga_status + 3;
  103. fpga_brdc = fpga_status + 4;
  104. /* split the keyboard and mouse interrupts */
  105. fpga_brdc_data = readb(fpga_brdc);
  106. fpga_brdc_data |= 0x80;
  107. writeb(fpga_brdc_data, fpga_brdc);
  108. writeb(0x3, fpga_enable);
  109. writeb(0x3, fpga_polarity);
  110. writeb(0x3, fpga_trigger);
  111. /* RTC step for the sycamore */
  112. sycamore_rtc_base = (void *) SYCAMORE_RTC_VADDR;
  113. TODC_INIT(TODC_TYPE_DS1743, sycamore_rtc_base, sycamore_rtc_base,
  114. sycamore_rtc_base, 8);
  115. /* Identify the system */
  116. printk(KERN_INFO "IBM Sycamore (IBM405GPr) Platform\n");
  117. printk(KERN_INFO
  118. "Port by MontaVista Software, Inc. (source@mvista.com)\n");
  119. }
  120. void __init
  121. bios_fixup(struct pci_controller *hose, struct pcil0_regs *pcip)
  122. {
  123. #ifdef CONFIG_PCI
  124. unsigned int bar_response, bar;
  125. /*
  126. * Expected PCI mapping:
  127. *
  128. * PLB addr PCI memory addr
  129. * --------------------- ---------------------
  130. * 0000'0000 - 7fff'ffff <--- 0000'0000 - 7fff'ffff
  131. * 8000'0000 - Bfff'ffff ---> 8000'0000 - Bfff'ffff
  132. *
  133. * PLB addr PCI io addr
  134. * --------------------- ---------------------
  135. * e800'0000 - e800'ffff ---> 0000'0000 - 0001'0000
  136. *
  137. * The following code is simplified by assuming that the bootrom
  138. * has been well behaved in following this mapping.
  139. */
  140. #ifdef DEBUG
  141. int i;
  142. printk("ioremap PCLIO_BASE = 0x%x\n", pcip);
  143. printk("PCI bridge regs before fixup \n");
  144. for (i = 0; i <= 3; i++) {
  145. printk(" pmm%dma\t0x%x\n", i, in_le32(&(pcip->pmm[i].ma)));
  146. printk(" pmm%dma\t0x%x\n", i, in_le32(&(pcip->pmm[i].la)));
  147. printk(" pmm%dma\t0x%x\n", i, in_le32(&(pcip->pmm[i].pcila)));
  148. printk(" pmm%dma\t0x%x\n", i, in_le32(&(pcip->pmm[i].pciha)));
  149. }
  150. printk(" ptm1ms\t0x%x\n", in_le32(&(pcip->ptm1ms)));
  151. printk(" ptm1la\t0x%x\n", in_le32(&(pcip->ptm1la)));
  152. printk(" ptm2ms\t0x%x\n", in_le32(&(pcip->ptm2ms)));
  153. printk(" ptm2la\t0x%x\n", in_le32(&(pcip->ptm2la)));
  154. #endif
  155. /* added for IBM boot rom version 1.15 bios bar changes -AK */
  156. /* Disable region first */
  157. out_le32((void *) &(pcip->pmm[0].ma), 0x00000000);
  158. /* PLB starting addr, PCI: 0x80000000 */
  159. out_le32((void *) &(pcip->pmm[0].la), 0x80000000);
  160. /* PCI start addr, 0x80000000 */
  161. out_le32((void *) &(pcip->pmm[0].pcila), PPC405_PCI_MEM_BASE);
  162. /* 512MB range of PLB to PCI */
  163. out_le32((void *) &(pcip->pmm[0].pciha), 0x00000000);
  164. /* Enable no pre-fetch, enable region */
  165. out_le32((void *) &(pcip->pmm[0].ma), ((0xffffffff -
  166. (PPC405_PCI_UPPER_MEM -
  167. PPC405_PCI_MEM_BASE)) | 0x01));
  168. /* Enable inbound region one - 1GB size */
  169. out_le32((void *) &(pcip->ptm1ms), 0xc0000001);
  170. /* Disable outbound region one */
  171. out_le32((void *) &(pcip->pmm[1].ma), 0x00000000);
  172. out_le32((void *) &(pcip->pmm[1].la), 0x00000000);
  173. out_le32((void *) &(pcip->pmm[1].pcila), 0x00000000);
  174. out_le32((void *) &(pcip->pmm[1].pciha), 0x00000000);
  175. out_le32((void *) &(pcip->pmm[1].ma), 0x00000000);
  176. /* Disable inbound region two */
  177. out_le32((void *) &(pcip->ptm2ms), 0x00000000);
  178. /* Disable outbound region two */
  179. out_le32((void *) &(pcip->pmm[2].ma), 0x00000000);
  180. out_le32((void *) &(pcip->pmm[2].la), 0x00000000);
  181. out_le32((void *) &(pcip->pmm[2].pcila), 0x00000000);
  182. out_le32((void *) &(pcip->pmm[2].pciha), 0x00000000);
  183. out_le32((void *) &(pcip->pmm[2].ma), 0x00000000);
  184. /* Zero config bars */
  185. for (bar = PCI_BASE_ADDRESS_1; bar <= PCI_BASE_ADDRESS_2; bar += 4) {
  186. early_write_config_dword(hose, hose->first_busno,
  187. PCI_FUNC(hose->first_busno), bar,
  188. 0x00000000);
  189. early_read_config_dword(hose, hose->first_busno,
  190. PCI_FUNC(hose->first_busno), bar,
  191. &bar_response);
  192. DBG("BUS %d, device %d, Function %d bar 0x%8.8x is 0x%8.8x\n",
  193. hose->first_busno, PCI_SLOT(hose->first_busno),
  194. PCI_FUNC(hose->first_busno), bar, bar_response);
  195. }
  196. /* end work arround */
  197. #ifdef DEBUG
  198. printk("PCI bridge regs after fixup \n");
  199. for (i = 0; i <= 3; i++) {
  200. printk(" pmm%dma\t0x%x\n", i, in_le32(&(pcip->pmm[i].ma)));
  201. printk(" pmm%dma\t0x%x\n", i, in_le32(&(pcip->pmm[i].la)));
  202. printk(" pmm%dma\t0x%x\n", i, in_le32(&(pcip->pmm[i].pcila)));
  203. printk(" pmm%dma\t0x%x\n", i, in_le32(&(pcip->pmm[i].pciha)));
  204. }
  205. printk(" ptm1ms\t0x%x\n", in_le32(&(pcip->ptm1ms)));
  206. printk(" ptm1la\t0x%x\n", in_le32(&(pcip->ptm1la)));
  207. printk(" ptm2ms\t0x%x\n", in_le32(&(pcip->ptm2ms)));
  208. printk(" ptm2la\t0x%x\n", in_le32(&(pcip->ptm2la)));
  209. #endif
  210. #endif
  211. }
  212. void __init
  213. sycamore_map_io(void)
  214. {
  215. ppc4xx_map_io();
  216. io_block_mapping(SYCAMORE_RTC_VADDR,
  217. SYCAMORE_RTC_PADDR, SYCAMORE_RTC_SIZE, _PAGE_IO);
  218. }
  219. void __init
  220. platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
  221. unsigned long r6, unsigned long r7)
  222. {
  223. ppc4xx_init(r3, r4, r5, r6, r7);
  224. ppc_md.setup_arch = sycamore_setup_arch;
  225. ppc_md.setup_io_mappings = sycamore_map_io;
  226. #ifdef CONFIG_GEN_RTC
  227. ppc_md.time_init = todc_time_init;
  228. ppc_md.set_rtc_time = todc_set_rtc_time;
  229. ppc_md.get_rtc_time = todc_get_rtc_time;
  230. ppc_md.nvram_read_val = todc_direct_read_val;
  231. ppc_md.nvram_write_val = todc_direct_write_val;
  232. #endif
  233. }