ep405.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. #ifdef CONFIG_PCI
  63. unsigned int bar_response, bar;
  64. /*
  65. * Expected PCI mapping:
  66. *
  67. * PLB addr PCI memory addr
  68. * --------------------- ---------------------
  69. * 0000'0000 - 7fff'ffff <--- 0000'0000 - 7fff'ffff
  70. * 8000'0000 - Bfff'ffff ---> 8000'0000 - Bfff'ffff
  71. *
  72. * PLB addr PCI io addr
  73. * --------------------- ---------------------
  74. * e800'0000 - e800'ffff ---> 0000'0000 - 0001'0000
  75. *
  76. */
  77. /* Disable region zero first */
  78. out_le32((void *) &(pcip->pmm[0].ma), 0x00000000);
  79. /* PLB starting addr, PCI: 0x80000000 */
  80. out_le32((void *) &(pcip->pmm[0].la), 0x80000000);
  81. /* PCI start addr, 0x80000000 */
  82. out_le32((void *) &(pcip->pmm[0].pcila), PPC405_PCI_MEM_BASE);
  83. /* 512MB range of PLB to PCI */
  84. out_le32((void *) &(pcip->pmm[0].pciha), 0x00000000);
  85. /* Enable no pre-fetch, enable region */
  86. out_le32((void *) &(pcip->pmm[0].ma), ((0xffffffff -
  87. (PPC405_PCI_UPPER_MEM -
  88. PPC405_PCI_MEM_BASE)) | 0x01));
  89. /* Disable region one */
  90. out_le32((void *) &(pcip->pmm[1].ma), 0x00000000);
  91. out_le32((void *) &(pcip->pmm[1].la), 0x00000000);
  92. out_le32((void *) &(pcip->pmm[1].pcila), 0x00000000);
  93. out_le32((void *) &(pcip->pmm[1].pciha), 0x00000000);
  94. out_le32((void *) &(pcip->pmm[1].ma), 0x00000000);
  95. out_le32((void *) &(pcip->ptm1ms), 0x00000000);
  96. /* Disable region two */
  97. out_le32((void *) &(pcip->pmm[2].ma), 0x00000000);
  98. out_le32((void *) &(pcip->pmm[2].la), 0x00000000);
  99. out_le32((void *) &(pcip->pmm[2].pcila), 0x00000000);
  100. out_le32((void *) &(pcip->pmm[2].pciha), 0x00000000);
  101. out_le32((void *) &(pcip->pmm[2].ma), 0x00000000);
  102. out_le32((void *) &(pcip->ptm2ms), 0x00000000);
  103. /* Configure PTM (PCI->PLB) region 1 */
  104. out_le32((void *) &(pcip->ptm1la), 0x00000000); /* PLB base address */
  105. /* Disable PTM region 2 */
  106. out_le32((void *) &(pcip->ptm2ms), 0x00000000);
  107. /* Zero config bars */
  108. for (bar = PCI_BASE_ADDRESS_1; bar <= PCI_BASE_ADDRESS_2; bar += 4) {
  109. early_write_config_dword(hose, hose->first_busno,
  110. PCI_FUNC(hose->first_busno), bar,
  111. 0x00000000);
  112. early_read_config_dword(hose, hose->first_busno,
  113. PCI_FUNC(hose->first_busno), bar,
  114. &bar_response);
  115. DBG("BUS %d, device %d, Function %d bar 0x%8.8x is 0x%8.8x\n",
  116. hose->first_busno, PCI_SLOT(hose->first_busno),
  117. PCI_FUNC(hose->first_busno), bar, bar_response);
  118. }
  119. /* end workaround */
  120. #endif
  121. }
  122. void __init
  123. ep405_map_io(void)
  124. {
  125. bd_t *bip = &__res;
  126. ppc4xx_map_io();
  127. ep405_bcsr = ioremap(EP405_BCSR_PADDR, EP405_BCSR_SIZE);
  128. if (bip->bi_nvramsize > 0) {
  129. ep405_nvram = ioremap(EP405_NVRAM_PADDR, bip->bi_nvramsize);
  130. }
  131. }
  132. void __init
  133. ep405_init_IRQ(void)
  134. {
  135. int i;
  136. ppc4xx_init_IRQ();
  137. /* Workaround for a bug in the firmware it incorrectly sets
  138. the IRQ polarities for XIRQ0 and XIRQ1 */
  139. mtdcr(DCRN_UIC_PR(DCRN_UIC0_BASE), 0xffffff80); /* set the polarity */
  140. mtdcr(DCRN_UIC_SR(DCRN_UIC0_BASE), 0x00000060); /* clear bogus interrupts */
  141. /* Activate the XIRQs from the CPLD */
  142. writeb(0xf0, ep405_bcsr+10);
  143. /* Set up IRQ routing */
  144. for (i = 0; i < ARRAY_SIZE(ep405_devtable); i++) {
  145. if ( (ep405_devtable[i].irq >= 25)
  146. && (ep405_devtable[i].irq) <= 31) {
  147. writeb(ep405_devtable[i].cpld_xirq_select, ep405_bcsr+5);
  148. writeb(ep405_devtable[i].irq - 25, ep405_bcsr+6);
  149. }
  150. }
  151. }
  152. void __init
  153. platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
  154. unsigned long r6, unsigned long r7)
  155. {
  156. ppc4xx_init(r3, r4, r5, r6, r7);
  157. ppc_md.setup_arch = ep405_setup_arch;
  158. ppc_md.setup_io_mappings = ep405_map_io;
  159. ppc_md.init_IRQ = ep405_init_IRQ;
  160. ppc_md.nvram_read_val = todc_direct_read_val;
  161. ppc_md.nvram_write_val = todc_direct_write_val;
  162. if (__res.bi_nvramsize == 512*1024) {
  163. ppc_md.time_init = todc_time_init;
  164. ppc_md.set_rtc_time = todc_set_rtc_time;
  165. ppc_md.get_rtc_time = todc_get_rtc_time;
  166. } else {
  167. printk("EP405: NVRTC size is not 512k (not a DS1557). Not sure what to do with it\n");
  168. }
  169. }