sycamore.c 8.0 KB

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