ep405.c 5.3 KB

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