walnut.c 7.0 KB

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