walnut.c 7.0 KB

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