ep405.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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/config.h>
  13. #include <linux/init.h>
  14. #include <linux/pci.h>
  15. #include <asm/system.h>
  16. #include <asm/pci-bridge.h>
  17. #include <asm/machdep.h>
  18. #include <asm/todc.h>
  19. #include <asm/ocp.h>
  20. #include <asm/ibm_ocp_pci.h>
  21. #undef DEBUG
  22. #ifdef DEBUG
  23. #define DBG(x...) printk(x)
  24. #else
  25. #define DBG(x...)
  26. #endif
  27. u8 *ep405_bcsr;
  28. u8 *ep405_nvram;
  29. static struct {
  30. u8 cpld_xirq_select;
  31. int pci_idsel;
  32. int irq;
  33. } ep405_devtable[] = {
  34. #ifdef CONFIG_EP405PC
  35. {0x07, 0x0E, 25}, /* EP405PC: USB */
  36. #endif
  37. };
  38. int __init
  39. ppc405_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
  40. {
  41. int i;
  42. /* AFAICT this is only called a few times during PCI setup, so
  43. performance is not critical */
  44. for (i = 0; i < ARRAY_SIZE(ep405_devtable); i++) {
  45. if (idsel == ep405_devtable[i].pci_idsel)
  46. return ep405_devtable[i].irq;
  47. }
  48. return -1;
  49. };
  50. void __init
  51. ep405_setup_arch(void)
  52. {
  53. ppc4xx_setup_arch();
  54. ibm_ocp_set_emac(0, 0);
  55. if (__res.bi_nvramsize == 512*1024) {
  56. /* FIXME: we should properly handle NVRTCs of different sizes */
  57. TODC_INIT(TODC_TYPE_DS1557, ep405_nvram, ep405_nvram, ep405_nvram, 8);
  58. }
  59. }
  60. void __init
  61. bios_fixup(struct pci_controller *hose, struct pcil0_regs *pcip)
  62. {
  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 work arround */
  120. }
  121. void __init
  122. ep405_map_io(void)
  123. {
  124. bd_t *bip = &__res;
  125. ppc4xx_map_io();
  126. ep405_bcsr = ioremap(EP405_BCSR_PADDR, EP405_BCSR_SIZE);
  127. if (bip->bi_nvramsize > 0) {
  128. ep405_nvram = ioremap(EP405_NVRAM_PADDR, bip->bi_nvramsize);
  129. }
  130. }
  131. void __init
  132. ep405_init_IRQ(void)
  133. {
  134. int i;
  135. ppc4xx_init_IRQ();
  136. /* Workaround for a bug in the firmware it incorrectly sets
  137. the IRQ polarities for XIRQ0 and XIRQ1 */
  138. mtdcr(DCRN_UIC_PR(DCRN_UIC0_BASE), 0xffffff80); /* set the polarity */
  139. mtdcr(DCRN_UIC_SR(DCRN_UIC0_BASE), 0x00000060); /* clear bogus interrupts */
  140. /* Activate the XIRQs from the CPLD */
  141. writeb(0xf0, ep405_bcsr+10);
  142. /* Set up IRQ routing */
  143. for (i = 0; i < ARRAY_SIZE(ep405_devtable); i++) {
  144. if ( (ep405_devtable[i].irq >= 25)
  145. && (ep405_devtable[i].irq) <= 31) {
  146. writeb(ep405_devtable[i].cpld_xirq_select, ep405_bcsr+5);
  147. writeb(ep405_devtable[i].irq - 25, ep405_bcsr+6);
  148. }
  149. }
  150. }
  151. void __init
  152. platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
  153. unsigned long r6, unsigned long r7)
  154. {
  155. ppc4xx_init(r3, r4, r5, r6, r7);
  156. ppc_md.setup_arch = ep405_setup_arch;
  157. ppc_md.setup_io_mappings = ep405_map_io;
  158. ppc_md.init_IRQ = ep405_init_IRQ;
  159. ppc_md.nvram_read_val = todc_direct_read_val;
  160. ppc_md.nvram_write_val = todc_direct_write_val;
  161. if (__res.bi_nvramsize == 512*1024) {
  162. ppc_md.time_init = todc_time_init;
  163. ppc_md.set_rtc_time = todc_set_rtc_time;
  164. ppc_md.get_rtc_time = todc_get_rtc_time;
  165. } else {
  166. printk("EP405: NVRTC size is not 512k (not a DS1557). Not sure what to do with it\n");
  167. }
  168. }