ep405.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /*
  2. * arch/ppc/platforms/4xx/ep405.c
  3. *
  4. * Embedded Planet 405GP board
  5. * http://www.embeddedplanet.com
  6. *
  7. * Author: Matthew Locke <mlocke@mvista.com>
  8. *
  9. * 2001 (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/pci.h>
  17. #include <asm/system.h>
  18. #include <asm/pci-bridge.h>
  19. #include <asm/machdep.h>
  20. #include <asm/todc.h>
  21. #include <asm/ocp.h>
  22. #include <asm/ibm_ocp_pci.h>
  23. #undef DEBUG
  24. #ifdef DEBUG
  25. #define DBG(x...) printk(x)
  26. #else
  27. #define DBG(x...)
  28. #endif
  29. u8 *ep405_bcsr;
  30. u8 *ep405_nvram;
  31. static struct {
  32. u8 cpld_xirq_select;
  33. int pci_idsel;
  34. int irq;
  35. } ep405_devtable[] = {
  36. #ifdef CONFIG_EP405PC
  37. {0x07, 0x0E, 25}, /* EP405PC: USB */
  38. #endif
  39. };
  40. int __init
  41. ppc405_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
  42. {
  43. int i;
  44. /* AFAICT this is only called a few times during PCI setup, so
  45. performance is not critical */
  46. for (i = 0; i < ARRAY_SIZE(ep405_devtable); i++) {
  47. if (idsel == ep405_devtable[i].pci_idsel)
  48. return ep405_devtable[i].irq;
  49. }
  50. return -1;
  51. };
  52. void __init
  53. ep405_setup_arch(void)
  54. {
  55. ppc4xx_setup_arch();
  56. ibm_ocp_set_emac(0, 0);
  57. if (__res.bi_nvramsize == 512*1024) {
  58. /* FIXME: we should properly handle NVRTCs of different sizes */
  59. TODC_INIT(TODC_TYPE_DS1557, ep405_nvram, ep405_nvram, ep405_nvram, 8);
  60. }
  61. }
  62. void __init
  63. bios_fixup(struct pci_controller *hose, struct pcil0_regs *pcip)
  64. {
  65. unsigned int bar_response, bar;
  66. /*
  67. * Expected PCI mapping:
  68. *
  69. * PLB addr PCI memory addr
  70. * --------------------- ---------------------
  71. * 0000'0000 - 7fff'ffff <--- 0000'0000 - 7fff'ffff
  72. * 8000'0000 - Bfff'ffff ---> 8000'0000 - Bfff'ffff
  73. *
  74. * PLB addr PCI io addr
  75. * --------------------- ---------------------
  76. * e800'0000 - e800'ffff ---> 0000'0000 - 0001'0000
  77. *
  78. */
  79. /* Disable region zero first */
  80. out_le32((void *) &(pcip->pmm[0].ma), 0x00000000);
  81. /* PLB starting addr, PCI: 0x80000000 */
  82. out_le32((void *) &(pcip->pmm[0].la), 0x80000000);
  83. /* PCI start addr, 0x80000000 */
  84. out_le32((void *) &(pcip->pmm[0].pcila), PPC405_PCI_MEM_BASE);
  85. /* 512MB range of PLB to PCI */
  86. out_le32((void *) &(pcip->pmm[0].pciha), 0x00000000);
  87. /* Enable no pre-fetch, enable region */
  88. out_le32((void *) &(pcip->pmm[0].ma), ((0xffffffff -
  89. (PPC405_PCI_UPPER_MEM -
  90. PPC405_PCI_MEM_BASE)) | 0x01));
  91. /* Disable region one */
  92. out_le32((void *) &(pcip->pmm[1].ma), 0x00000000);
  93. out_le32((void *) &(pcip->pmm[1].la), 0x00000000);
  94. out_le32((void *) &(pcip->pmm[1].pcila), 0x00000000);
  95. out_le32((void *) &(pcip->pmm[1].pciha), 0x00000000);
  96. out_le32((void *) &(pcip->pmm[1].ma), 0x00000000);
  97. out_le32((void *) &(pcip->ptm1ms), 0x00000000);
  98. /* Disable region two */
  99. out_le32((void *) &(pcip->pmm[2].ma), 0x00000000);
  100. out_le32((void *) &(pcip->pmm[2].la), 0x00000000);
  101. out_le32((void *) &(pcip->pmm[2].pcila), 0x00000000);
  102. out_le32((void *) &(pcip->pmm[2].pciha), 0x00000000);
  103. out_le32((void *) &(pcip->pmm[2].ma), 0x00000000);
  104. out_le32((void *) &(pcip->ptm2ms), 0x00000000);
  105. /* Configure PTM (PCI->PLB) region 1 */
  106. out_le32((void *) &(pcip->ptm1la), 0x00000000); /* PLB base address */
  107. /* Disable PTM region 2 */
  108. out_le32((void *) &(pcip->ptm2ms), 0x00000000);
  109. /* Zero config bars */
  110. for (bar = PCI_BASE_ADDRESS_1; bar <= PCI_BASE_ADDRESS_2; bar += 4) {
  111. early_write_config_dword(hose, hose->first_busno,
  112. PCI_FUNC(hose->first_busno), bar,
  113. 0x00000000);
  114. early_read_config_dword(hose, hose->first_busno,
  115. PCI_FUNC(hose->first_busno), bar,
  116. &bar_response);
  117. DBG("BUS %d, device %d, Function %d bar 0x%8.8x is 0x%8.8x\n",
  118. hose->first_busno, PCI_SLOT(hose->first_busno),
  119. PCI_FUNC(hose->first_busno), bar, bar_response);
  120. }
  121. /* end work arround */
  122. }
  123. void __init
  124. ep405_map_io(void)
  125. {
  126. bd_t *bip = &__res;
  127. ppc4xx_map_io();
  128. ep405_bcsr = ioremap(EP405_BCSR_PADDR, EP405_BCSR_SIZE);
  129. if (bip->bi_nvramsize > 0) {
  130. ep405_nvram = ioremap(EP405_NVRAM_PADDR, bip->bi_nvramsize);
  131. }
  132. }
  133. void __init
  134. ep405_init_IRQ(void)
  135. {
  136. int i;
  137. ppc4xx_init_IRQ();
  138. /* Workaround for a bug in the firmware it incorrectly sets
  139. the IRQ polarities for XIRQ0 and XIRQ1 */
  140. mtdcr(DCRN_UIC_PR(DCRN_UIC0_BASE), 0xffffff80); /* set the polarity */
  141. mtdcr(DCRN_UIC_SR(DCRN_UIC0_BASE), 0x00000060); /* clear bogus interrupts */
  142. /* Activate the XIRQs from the CPLD */
  143. writeb(0xf0, ep405_bcsr+10);
  144. /* Set up IRQ routing */
  145. for (i = 0; i < ARRAY_SIZE(ep405_devtable); i++) {
  146. if ( (ep405_devtable[i].irq >= 25)
  147. && (ep405_devtable[i].irq) <= 31) {
  148. writeb(ep405_devtable[i].cpld_xirq_select, ep405_bcsr+5);
  149. writeb(ep405_devtable[i].irq - 25, ep405_bcsr+6);
  150. }
  151. }
  152. }
  153. void __init
  154. platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
  155. unsigned long r6, unsigned long r7)
  156. {
  157. ppc4xx_init(r3, r4, r5, r6, r7);
  158. ppc_md.setup_arch = ep405_setup_arch;
  159. ppc_md.setup_io_mappings = ep405_map_io;
  160. ppc_md.init_IRQ = ep405_init_IRQ;
  161. ppc_md.nvram_read_val = todc_direct_read_val;
  162. ppc_md.nvram_write_val = todc_direct_write_val;
  163. if (__res.bi_nvramsize == 512*1024) {
  164. ppc_md.time_init = todc_time_init;
  165. ppc_md.set_rtc_time = todc_set_rtc_time;
  166. ppc_md.get_rtc_time = todc_get_rtc_time;
  167. } else {
  168. printk("EP405: NVRTC size is not 512k (not a DS1557). Not sure what to do with it\n");
  169. }
  170. }