sycamore.c 8.0 KB

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