/arch/ppc/platforms/4xx/sycamore.c

https://bitbucket.org/evzijst/gittest · C · 278 lines · 185 code · 40 blank · 53 comment · 5 complexity · d82bb552b3e58f23c9fea9df468dda19 MD5 · raw file

  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. #define SYCAMORE_PS2_BASE 0xF0100000
  83. #define SYCAMORE_FPGA_BASE 0xF0300000
  84. void *fpga_brdc;
  85. unsigned char fpga_brdc_data;
  86. void *fpga_enable;
  87. void *fpga_polarity;
  88. void *fpga_status;
  89. void *fpga_trigger;
  90. ppc4xx_setup_arch();
  91. ibm_ocp_set_emac(0, 1);
  92. kb_data = ioremap(SYCAMORE_PS2_BASE, 8);
  93. if (!kb_data) {
  94. printk(KERN_CRIT
  95. "sycamore_setup_arch() kb_data ioremap failed\n");
  96. return;
  97. }
  98. kb_cs = kb_data + 1;
  99. fpga_status = ioremap(SYCAMORE_FPGA_BASE, 8);
  100. if (!fpga_status) {
  101. printk(KERN_CRIT
  102. "sycamore_setup_arch() fpga_status ioremap failed\n");
  103. return;
  104. }
  105. fpga_enable = fpga_status + 1;
  106. fpga_polarity = fpga_status + 2;
  107. fpga_trigger = fpga_status + 3;
  108. fpga_brdc = fpga_status + 4;
  109. /* split the keyboard and mouse interrupts */
  110. fpga_brdc_data = readb(fpga_brdc);
  111. fpga_brdc_data |= 0x80;
  112. writeb(fpga_brdc_data, fpga_brdc);
  113. writeb(0x3, fpga_enable);
  114. writeb(0x3, fpga_polarity);
  115. writeb(0x3, fpga_trigger);
  116. /* RTC step for the sycamore */
  117. sycamore_rtc_base = (void *) SYCAMORE_RTC_VADDR;
  118. TODC_INIT(TODC_TYPE_DS1743, sycamore_rtc_base, sycamore_rtc_base,
  119. sycamore_rtc_base, 8);
  120. /* Identify the system */
  121. printk(KERN_INFO "IBM Sycamore (IBM405GPr) Platform\n");
  122. printk(KERN_INFO
  123. "Port by MontaVista Software, Inc. (source@mvista.com)\n");
  124. }
  125. void __init
  126. bios_fixup(struct pci_controller *hose, struct pcil0_regs *pcip)
  127. {
  128. #ifdef CONFIG_PCI
  129. unsigned int bar_response, bar;
  130. /*
  131. * Expected PCI mapping:
  132. *
  133. * PLB addr PCI memory addr
  134. * --------------------- ---------------------
  135. * 0000'0000 - 7fff'ffff <--- 0000'0000 - 7fff'ffff
  136. * 8000'0000 - Bfff'ffff ---> 8000'0000 - Bfff'ffff
  137. *
  138. * PLB addr PCI io addr
  139. * --------------------- ---------------------
  140. * e800'0000 - e800'ffff ---> 0000'0000 - 0001'0000
  141. *
  142. * The following code is simplified by assuming that the bootrom
  143. * has been well behaved in following this mapping.
  144. */
  145. #ifdef DEBUG
  146. int i;
  147. printk("ioremap PCLIO_BASE = 0x%x\n", pcip);
  148. printk("PCI bridge regs before fixup \n");
  149. for (i = 0; i <= 3; i++) {
  150. printk(" pmm%dma\t0x%x\n", i, in_le32(&(pcip->pmm[i].ma)));
  151. printk(" pmm%dma\t0x%x\n", i, in_le32(&(pcip->pmm[i].la)));
  152. printk(" pmm%dma\t0x%x\n", i, in_le32(&(pcip->pmm[i].pcila)));
  153. printk(" pmm%dma\t0x%x\n", i, in_le32(&(pcip->pmm[i].pciha)));
  154. }
  155. printk(" ptm1ms\t0x%x\n", in_le32(&(pcip->ptm1ms)));
  156. printk(" ptm1la\t0x%x\n", in_le32(&(pcip->ptm1la)));
  157. printk(" ptm2ms\t0x%x\n", in_le32(&(pcip->ptm2ms)));
  158. printk(" ptm2la\t0x%x\n", in_le32(&(pcip->ptm2la)));
  159. #endif
  160. /* added for IBM boot rom version 1.15 bios bar changes -AK */
  161. /* Disable region first */
  162. out_le32((void *) &(pcip->pmm[0].ma), 0x00000000);
  163. /* PLB starting addr, PCI: 0x80000000 */
  164. out_le32((void *) &(pcip->pmm[0].la), 0x80000000);
  165. /* PCI start addr, 0x80000000 */
  166. out_le32((void *) &(pcip->pmm[0].pcila), PPC405_PCI_MEM_BASE);
  167. /* 512MB range of PLB to PCI */
  168. out_le32((void *) &(pcip->pmm[0].pciha), 0x00000000);
  169. /* Enable no pre-fetch, enable region */
  170. out_le32((void *) &(pcip->pmm[0].ma), ((0xffffffff -
  171. (PPC405_PCI_UPPER_MEM -
  172. PPC405_PCI_MEM_BASE)) | 0x01));
  173. /* Enable inbound region one - 1GB size */
  174. out_le32((void *) &(pcip->ptm1ms), 0xc0000001);
  175. /* Disable outbound region one */
  176. out_le32((void *) &(pcip->pmm[1].ma), 0x00000000);
  177. out_le32((void *) &(pcip->pmm[1].la), 0x00000000);
  178. out_le32((void *) &(pcip->pmm[1].pcila), 0x00000000);
  179. out_le32((void *) &(pcip->pmm[1].pciha), 0x00000000);
  180. out_le32((void *) &(pcip->pmm[1].ma), 0x00000000);
  181. /* Disable inbound region two */
  182. out_le32((void *) &(pcip->ptm2ms), 0x00000000);
  183. /* Disable outbound region two */
  184. out_le32((void *) &(pcip->pmm[2].ma), 0x00000000);
  185. out_le32((void *) &(pcip->pmm[2].la), 0x00000000);
  186. out_le32((void *) &(pcip->pmm[2].pcila), 0x00000000);
  187. out_le32((void *) &(pcip->pmm[2].pciha), 0x00000000);
  188. out_le32((void *) &(pcip->pmm[2].ma), 0x00000000);
  189. /* Zero config bars */
  190. for (bar = PCI_BASE_ADDRESS_1; bar <= PCI_BASE_ADDRESS_2; bar += 4) {
  191. early_write_config_dword(hose, hose->first_busno,
  192. PCI_FUNC(hose->first_busno), bar,
  193. 0x00000000);
  194. early_read_config_dword(hose, hose->first_busno,
  195. PCI_FUNC(hose->first_busno), bar,
  196. &bar_response);
  197. DBG("BUS %d, device %d, Function %d bar 0x%8.8x is 0x%8.8x\n",
  198. hose->first_busno, PCI_SLOT(hose->first_busno),
  199. PCI_FUNC(hose->first_busno), bar, bar_response);
  200. }
  201. /* end work arround */
  202. #ifdef DEBUG
  203. printk("PCI bridge regs after fixup \n");
  204. for (i = 0; i <= 3; i++) {
  205. printk(" pmm%dma\t0x%x\n", i, in_le32(&(pcip->pmm[i].ma)));
  206. printk(" pmm%dma\t0x%x\n", i, in_le32(&(pcip->pmm[i].la)));
  207. printk(" pmm%dma\t0x%x\n", i, in_le32(&(pcip->pmm[i].pcila)));
  208. printk(" pmm%dma\t0x%x\n", i, in_le32(&(pcip->pmm[i].pciha)));
  209. }
  210. printk(" ptm1ms\t0x%x\n", in_le32(&(pcip->ptm1ms)));
  211. printk(" ptm1la\t0x%x\n", in_le32(&(pcip->ptm1la)));
  212. printk(" ptm2ms\t0x%x\n", in_le32(&(pcip->ptm2ms)));
  213. printk(" ptm2la\t0x%x\n", in_le32(&(pcip->ptm2la)));
  214. #endif
  215. #endif
  216. }
  217. void __init
  218. sycamore_map_io(void)
  219. {
  220. ppc4xx_map_io();
  221. io_block_mapping(SYCAMORE_RTC_VADDR,
  222. SYCAMORE_RTC_PADDR, SYCAMORE_RTC_SIZE, _PAGE_IO);
  223. }
  224. void __init
  225. platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
  226. unsigned long r6, unsigned long r7)
  227. {
  228. ppc4xx_init(r3, r4, r5, r6, r7);
  229. ppc_md.setup_arch = sycamore_setup_arch;
  230. ppc_md.setup_io_mappings = sycamore_map_io;
  231. #ifdef CONFIG_GEN_RTC
  232. ppc_md.time_init = todc_time_init;
  233. ppc_md.set_rtc_time = todc_set_rtc_time;
  234. ppc_md.get_rtc_time = todc_get_rtc_time;
  235. ppc_md.nvram_read_val = todc_direct_read_val;
  236. ppc_md.nvram_write_val = todc_direct_write_val;
  237. #endif
  238. }