pci-rc32434.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /*
  2. * BRIEF MODULE DESCRIPTION
  3. * PCI initialization for IDT EB434 board
  4. *
  5. * Copyright 2004 IDT Inc. (rischelp@idt.com)
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the
  9. * Free Software Foundation; either version 2 of the License, or (at your
  10. * option) any later version.
  11. *
  12. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  13. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  14. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  15. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  16. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  17. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  18. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  19. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  20. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  21. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  22. *
  23. * You should have received a copy of the GNU General Public License along
  24. * with this program; if not, write to the Free Software Foundation, Inc.,
  25. * 675 Mass Ave, Cambridge, MA 02139, USA.
  26. */
  27. #include <linux/types.h>
  28. #include <linux/pci.h>
  29. #include <linux/kernel.h>
  30. #include <linux/init.h>
  31. #include <asm/mach-rc32434/rc32434.h>
  32. #include <asm/mach-rc32434/pci.h>
  33. #define PCI_ACCESS_READ 0
  34. #define PCI_ACCESS_WRITE 1
  35. /* define an unsigned array for the PCI registers */
  36. static unsigned int korina_cnfg_regs[25] = {
  37. KORINA_CNFG1, KORINA_CNFG2, KORINA_CNFG3, KORINA_CNFG4,
  38. KORINA_CNFG5, KORINA_CNFG6, KORINA_CNFG7, KORINA_CNFG8,
  39. KORINA_CNFG9, KORINA_CNFG10, KORINA_CNFG11, KORINA_CNFG12,
  40. KORINA_CNFG13, KORINA_CNFG14, KORINA_CNFG15, KORINA_CNFG16,
  41. KORINA_CNFG17, KORINA_CNFG18, KORINA_CNFG19, KORINA_CNFG20,
  42. KORINA_CNFG21, KORINA_CNFG22, KORINA_CNFG23, KORINA_CNFG24
  43. };
  44. static struct resource rc32434_res_pci_mem1;
  45. static struct resource rc32434_res_pci_mem2;
  46. static struct resource rc32434_res_pci_mem1 = {
  47. .name = "PCI MEM1",
  48. .start = 0x50000000,
  49. .end = 0x5FFFFFFF,
  50. .flags = IORESOURCE_MEM,
  51. .sibling = NULL,
  52. .child = &rc32434_res_pci_mem2
  53. };
  54. static struct resource rc32434_res_pci_mem2 = {
  55. .name = "PCI Mem2",
  56. .start = 0x60000000,
  57. .end = 0x6FFFFFFF,
  58. .flags = IORESOURCE_MEM,
  59. .parent = &rc32434_res_pci_mem1,
  60. .sibling = NULL,
  61. .child = NULL
  62. };
  63. static struct resource rc32434_res_pci_io1 = {
  64. .name = "PCI I/O1",
  65. .start = 0x18800000,
  66. .end = 0x188FFFFF,
  67. .flags = IORESOURCE_IO,
  68. };
  69. extern struct pci_ops rc32434_pci_ops;
  70. #define PCI_MEM1_START PCI_ADDR_START
  71. #define PCI_MEM1_END (PCI_ADDR_START + CPUTOPCI_MEM_WIN - 1)
  72. #define PCI_MEM2_START (PCI_ADDR_START + CPUTOPCI_MEM_WIN)
  73. #define PCI_MEM2_END (PCI_ADDR_START + (2 * CPUTOPCI_MEM_WIN) - 1)
  74. #define PCI_IO1_START (PCI_ADDR_START + (2 * CPUTOPCI_MEM_WIN))
  75. #define PCI_IO1_END \
  76. (PCI_ADDR_START + (2 * CPUTOPCI_MEM_WIN) + CPUTOPCI_IO_WIN - 1)
  77. #define PCI_IO2_START \
  78. (PCI_ADDR_START + (2 * CPUTOPCI_MEM_WIN) + CPUTOPCI_IO_WIN)
  79. #define PCI_IO2_END \
  80. (PCI_ADDR_START + (2 * CPUTOPCI_MEM_WIN) + (2 * CPUTOPCI_IO_WIN) - 1)
  81. struct pci_controller rc32434_controller2;
  82. struct pci_controller rc32434_controller = {
  83. .pci_ops = &rc32434_pci_ops,
  84. .mem_resource = &rc32434_res_pci_mem1,
  85. .io_resource = &rc32434_res_pci_io1,
  86. .mem_offset = 0,
  87. .io_offset = 0,
  88. };
  89. #ifdef __MIPSEB__
  90. #define PCI_ENDIAN_FLAG PCILBAC_sb_m
  91. #else
  92. #define PCI_ENDIAN_FLAG 0
  93. #endif
  94. static int __init rc32434_pcibridge_init(void)
  95. {
  96. unsigned int pcicvalue, pcicdata = 0;
  97. unsigned int dummyread, pcicntlval;
  98. int loopCount;
  99. unsigned int pci_config_addr;
  100. pcicvalue = rc32434_pci->pcic;
  101. pcicvalue = (pcicvalue >> PCIM_SHFT) & PCIM_BIT_LEN;
  102. if (!((pcicvalue == PCIM_H_EA) ||
  103. (pcicvalue == PCIM_H_IA_FIX) ||
  104. (pcicvalue == PCIM_H_IA_RR))) {
  105. pr_err("PCI init error!!!\n");
  106. /* Not in Host Mode, return ERROR */
  107. return -1;
  108. }
  109. /* Enables the Idle Grant mode, Arbiter Parking */
  110. pcicdata |= (PCI_CTL_IGM | PCI_CTL_EAP | PCI_CTL_EN);
  111. rc32434_pci->pcic = pcicdata; /* Enable the PCI bus Interface */
  112. /* Zero out the PCI status & PCI Status Mask */
  113. for (;;) {
  114. pcicdata = rc32434_pci->pcis;
  115. if (!(pcicdata & PCI_STAT_RIP))
  116. break;
  117. }
  118. rc32434_pci->pcis = 0;
  119. rc32434_pci->pcism = 0xFFFFFFFF;
  120. /* Zero out the PCI decoupled registers */
  121. rc32434_pci->pcidac = 0; /*
  122. * disable PCI decoupled accesses at
  123. * initialization
  124. */
  125. rc32434_pci->pcidas = 0; /* clear the status */
  126. rc32434_pci->pcidasm = 0x0000007F; /* Mask all the interrupts */
  127. /* Mask PCI Messaging Interrupts */
  128. rc32434_pci_msg->pciiic = 0;
  129. rc32434_pci_msg->pciiim = 0xFFFFFFFF;
  130. rc32434_pci_msg->pciioic = 0;
  131. rc32434_pci_msg->pciioim = 0;
  132. /* Setup PCILB0 as Memory Window */
  133. rc32434_pci->pcilba[0].address = (unsigned int) (PCI_ADDR_START);
  134. /* setup the PCI map address as same as the local address */
  135. rc32434_pci->pcilba[0].mapping = (unsigned int) (PCI_ADDR_START);
  136. /* Setup PCILBA1 as MEM */
  137. rc32434_pci->pcilba[0].control =
  138. (((SIZE_256MB & 0x1f) << PCI_LBAC_SIZE_BIT) | PCI_ENDIAN_FLAG);
  139. dummyread = rc32434_pci->pcilba[0].control; /* flush the CPU write Buffers */
  140. rc32434_pci->pcilba[1].address = 0x60000000;
  141. rc32434_pci->pcilba[1].mapping = 0x60000000;
  142. /* setup PCILBA2 as IO Window */
  143. rc32434_pci->pcilba[1].control =
  144. (((SIZE_256MB & 0x1f) << PCI_LBAC_SIZE_BIT) | PCI_ENDIAN_FLAG);
  145. dummyread = rc32434_pci->pcilba[1].control; /* flush the CPU write Buffers */
  146. rc32434_pci->pcilba[2].address = 0x18C00000;
  147. rc32434_pci->pcilba[2].mapping = 0x18FFFFFF;
  148. /* setup PCILBA2 as IO Window */
  149. rc32434_pci->pcilba[2].control =
  150. (((SIZE_4MB & 0x1f) << PCI_LBAC_SIZE_BIT) | PCI_ENDIAN_FLAG);
  151. dummyread = rc32434_pci->pcilba[2].control; /* flush the CPU write Buffers */
  152. /* Setup PCILBA3 as IO Window */
  153. rc32434_pci->pcilba[3].address = 0x18800000;
  154. rc32434_pci->pcilba[3].mapping = 0x18800000;
  155. rc32434_pci->pcilba[3].control =
  156. ((((SIZE_1MB & 0x1ff) << PCI_LBAC_SIZE_BIT) | PCI_LBAC_MSI) |
  157. PCI_ENDIAN_FLAG);
  158. dummyread = rc32434_pci->pcilba[3].control; /* flush the CPU write Buffers */
  159. pci_config_addr = (unsigned int) (0x80000004);
  160. for (loopCount = 0; loopCount < 24; loopCount++) {
  161. rc32434_pci->pcicfga = pci_config_addr;
  162. dummyread = rc32434_pci->pcicfga;
  163. rc32434_pci->pcicfgd = korina_cnfg_regs[loopCount];
  164. dummyread = rc32434_pci->pcicfgd;
  165. pci_config_addr += 4;
  166. }
  167. rc32434_pci->pcitc =
  168. (unsigned int) ((PCITC_RTIMER_VAL & 0xff) << PCI_TC_RTIMER_BIT) |
  169. ((PCITC_DTIMER_VAL & 0xff) << PCI_TC_DTIMER_BIT);
  170. pcicntlval = rc32434_pci->pcic;
  171. pcicntlval &= ~PCI_CTL_TNR;
  172. rc32434_pci->pcic = pcicntlval;
  173. pcicntlval = rc32434_pci->pcic;
  174. return 0;
  175. }
  176. static int __init rc32434_pci_init(void)
  177. {
  178. void __iomem *io_map_base;
  179. pr_info("PCI: Initializing PCI\n");
  180. ioport_resource.start = rc32434_res_pci_io1.start;
  181. ioport_resource.end = rc32434_res_pci_io1.end;
  182. rc32434_pcibridge_init();
  183. io_map_base = ioremap(rc32434_res_pci_io1.start,
  184. resource_size(&rc32434_res_pci_io1));
  185. if (!io_map_base)
  186. return -ENOMEM;
  187. rc32434_controller.io_map_base =
  188. (unsigned long)io_map_base - rc32434_res_pci_io1.start;
  189. register_pci_controller(&rc32434_controller);
  190. rc32434_sync();
  191. return 0;
  192. }
  193. arch_initcall(rc32434_pci_init);