walnut.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /*
  2. * Architecture- / platform-specific boot-time initialization code for
  3. * IBM PowerPC 4xx based boards. Adapted from original
  4. * code by Gary Thomas, Cort Dougan <cort@fsmlabs.com>, and Dan Malek
  5. * <dan@net4x.com>.
  6. *
  7. * Copyright(c) 1999-2000 Grant Erickson <grant@lcse.umn.edu>
  8. *
  9. * 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/init.h>
  15. #include <linux/smp.h>
  16. #include <linux/threads.h>
  17. #include <linux/param.h>
  18. #include <linux/string.h>
  19. #include <linux/pci.h>
  20. #include <linux/rtc.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/ocp.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 *walnut_rtc_base;
  39. /* Some IRQs unique to Walnut.
  40. * Used by the generic 405 PCI setup functions in ppc4xx_pci.c
  41. */
  42. int __init
  43. ppc405_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
  44. {
  45. static char pci_irq_table[][4] =
  46. /*
  47. * PCI IDSEL/INTPIN->INTLINE
  48. * A B C D
  49. */
  50. {
  51. {28, 28, 28, 28}, /* IDSEL 1 - PCI slot 1 */
  52. {29, 29, 29, 29}, /* IDSEL 2 - PCI slot 2 */
  53. {30, 30, 30, 30}, /* IDSEL 3 - PCI slot 3 */
  54. {31, 31, 31, 31}, /* IDSEL 4 - PCI slot 4 */
  55. };
  56. const long min_idsel = 1, max_idsel = 4, irqs_per_slot = 4;
  57. return PCI_IRQ_TABLE_LOOKUP;
  58. };
  59. void __init
  60. walnut_setup_arch(void)
  61. {
  62. void *fpga_brdc;
  63. unsigned char fpga_brdc_data;
  64. void *fpga_enable;
  65. void *fpga_polarity;
  66. void *fpga_status;
  67. void *fpga_trigger;
  68. ppc4xx_setup_arch();
  69. ibm_ocp_set_emac(0, 0);
  70. kb_data = ioremap(WALNUT_PS2_BASE, 8);
  71. if (!kb_data) {
  72. printk(KERN_CRIT
  73. "walnut_setup_arch() kb_data ioremap failed\n");
  74. return;
  75. }
  76. kb_cs = kb_data + 1;
  77. fpga_status = ioremap(PPC40x_FPGA_BASE, 8);
  78. if (!fpga_status) {
  79. printk(KERN_CRIT
  80. "walnut_setup_arch() fpga_status ioremap failed\n");
  81. return;
  82. }
  83. fpga_enable = fpga_status + 1;
  84. fpga_polarity = fpga_status + 2;
  85. fpga_trigger = fpga_status + 3;
  86. fpga_brdc = fpga_status + 4;
  87. /* split the keyboard and mouse interrupts */
  88. fpga_brdc_data = readb(fpga_brdc);
  89. fpga_brdc_data |= 0x80;
  90. writeb(fpga_brdc_data, fpga_brdc);
  91. writeb(0x3, fpga_enable);
  92. writeb(0x3, fpga_polarity);
  93. writeb(0x3, fpga_trigger);
  94. /* RTC step for the walnut */
  95. walnut_rtc_base = (void *) WALNUT_RTC_VADDR;
  96. TODC_INIT(TODC_TYPE_DS1743, walnut_rtc_base, walnut_rtc_base,
  97. walnut_rtc_base, 8);
  98. /* Identify the system */
  99. printk("IBM Walnut port (C) 2000-2002 MontaVista Software, Inc. (source@mvista.com)\n");
  100. }
  101. void __init
  102. bios_fixup(struct pci_controller *hose, struct pcil0_regs *pcip)
  103. {
  104. #ifdef CONFIG_PCI
  105. unsigned int bar_response, bar;
  106. /*
  107. * Expected PCI mapping:
  108. *
  109. * PLB addr PCI memory addr
  110. * --------------------- ---------------------
  111. * 0000'0000 - 7fff'ffff <--- 0000'0000 - 7fff'ffff
  112. * 8000'0000 - Bfff'ffff ---> 8000'0000 - Bfff'ffff
  113. *
  114. * PLB addr PCI io addr
  115. * --------------------- ---------------------
  116. * e800'0000 - e800'ffff ---> 0000'0000 - 0001'0000
  117. *
  118. * The following code is simplified by assuming that the bootrom
  119. * has been well behaved in following this mapping.
  120. */
  121. #ifdef DEBUG
  122. int i;
  123. printk("ioremap PCLIO_BASE = 0x%x\n", pcip);
  124. printk("PCI bridge regs before fixup \n");
  125. for (i = 0; i <= 3; i++) {
  126. printk(" pmm%dma\t0x%x\n", i, in_le32(&(pcip->pmm[i].ma)));
  127. printk(" pmm%dma\t0x%x\n", i, in_le32(&(pcip->pmm[i].la)));
  128. printk(" pmm%dma\t0x%x\n", i, in_le32(&(pcip->pmm[i].pcila)));
  129. printk(" pmm%dma\t0x%x\n", i, in_le32(&(pcip->pmm[i].pciha)));
  130. }
  131. printk(" ptm1ms\t0x%x\n", in_le32(&(pcip->ptm1ms)));
  132. printk(" ptm1la\t0x%x\n", in_le32(&(pcip->ptm1la)));
  133. printk(" ptm2ms\t0x%x\n", in_le32(&(pcip->ptm2ms)));
  134. printk(" ptm2la\t0x%x\n", in_le32(&(pcip->ptm2la)));
  135. #endif
  136. /* added for IBM boot rom version 1.15 bios bar changes -AK */
  137. /* Disable region first */
  138. out_le32((void *) &(pcip->pmm[0].ma), 0x00000000);
  139. /* PLB starting addr, PCI: 0x80000000 */
  140. out_le32((void *) &(pcip->pmm[0].la), 0x80000000);
  141. /* PCI start addr, 0x80000000 */
  142. out_le32((void *) &(pcip->pmm[0].pcila), PPC405_PCI_MEM_BASE);
  143. /* 512MB range of PLB to PCI */
  144. out_le32((void *) &(pcip->pmm[0].pciha), 0x00000000);
  145. /* Enable no pre-fetch, enable region */
  146. out_le32((void *) &(pcip->pmm[0].ma), ((0xffffffff -
  147. (PPC405_PCI_UPPER_MEM -
  148. PPC405_PCI_MEM_BASE)) | 0x01));
  149. /* Disable region one */
  150. out_le32((void *) &(pcip->pmm[1].ma), 0x00000000);
  151. out_le32((void *) &(pcip->pmm[1].la), 0x00000000);
  152. out_le32((void *) &(pcip->pmm[1].pcila), 0x00000000);
  153. out_le32((void *) &(pcip->pmm[1].pciha), 0x00000000);
  154. out_le32((void *) &(pcip->pmm[1].ma), 0x00000000);
  155. out_le32((void *) &(pcip->ptm1ms), 0x00000000);
  156. /* Disable region two */
  157. out_le32((void *) &(pcip->pmm[2].ma), 0x00000000);
  158. out_le32((void *) &(pcip->pmm[2].la), 0x00000000);
  159. out_le32((void *) &(pcip->pmm[2].pcila), 0x00000000);
  160. out_le32((void *) &(pcip->pmm[2].pciha), 0x00000000);
  161. out_le32((void *) &(pcip->pmm[2].ma), 0x00000000);
  162. out_le32((void *) &(pcip->ptm2ms), 0x00000000);
  163. /* Zero config bars */
  164. for (bar = PCI_BASE_ADDRESS_1; bar <= PCI_BASE_ADDRESS_2; bar += 4) {
  165. early_write_config_dword(hose, hose->first_busno,
  166. PCI_FUNC(hose->first_busno), bar,
  167. 0x00000000);
  168. early_read_config_dword(hose, hose->first_busno,
  169. PCI_FUNC(hose->first_busno), bar,
  170. &bar_response);
  171. DBG("BUS %d, device %d, Function %d bar 0x%8.8x is 0x%8.8x\n",
  172. hose->first_busno, PCI_SLOT(hose->first_busno),
  173. PCI_FUNC(hose->first_busno), bar, bar_response);
  174. }
  175. /* end work arround */
  176. #ifdef DEBUG
  177. printk("PCI bridge regs after fixup \n");
  178. for (i = 0; i <= 3; i++) {
  179. printk(" pmm%dma\t0x%x\n", i, in_le32(&(pcip->pmm[i].ma)));
  180. printk(" pmm%dma\t0x%x\n", i, in_le32(&(pcip->pmm[i].la)));
  181. printk(" pmm%dma\t0x%x\n", i, in_le32(&(pcip->pmm[i].pcila)));
  182. printk(" pmm%dma\t0x%x\n", i, in_le32(&(pcip->pmm[i].pciha)));
  183. }
  184. printk(" ptm1ms\t0x%x\n", in_le32(&(pcip->ptm1ms)));
  185. printk(" ptm1la\t0x%x\n", in_le32(&(pcip->ptm1la)));
  186. printk(" ptm2ms\t0x%x\n", in_le32(&(pcip->ptm2ms)));
  187. printk(" ptm2la\t0x%x\n", in_le32(&(pcip->ptm2la)));
  188. #endif
  189. #endif
  190. }
  191. void __init
  192. walnut_map_io(void)
  193. {
  194. ppc4xx_map_io();
  195. io_block_mapping(WALNUT_RTC_VADDR,
  196. WALNUT_RTC_PADDR, WALNUT_RTC_SIZE, _PAGE_IO);
  197. }
  198. void __init
  199. platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
  200. unsigned long r6, unsigned long r7)
  201. {
  202. ppc4xx_init(r3, r4, r5, r6, r7);
  203. ppc_md.setup_arch = walnut_setup_arch;
  204. ppc_md.setup_io_mappings = walnut_map_io;
  205. #ifdef CONFIG_GEN_RTC
  206. ppc_md.time_init = todc_time_init;
  207. ppc_md.set_rtc_time = todc_set_rtc_time;
  208. ppc_md.get_rtc_time = todc_get_rtc_time;
  209. ppc_md.nvram_read_val = todc_direct_read_val;
  210. ppc_md.nvram_write_val = todc_direct_write_val;
  211. #endif
  212. }