vr4131-pci.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. /*
  2. * VR4131 PCIU support code for TANBAC Evaluation board TB0229.
  3. *
  4. * (C) Masami Komiya <mkomiya@sonare.it> 2004
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation; either version 2, or (at
  9. * your option) any later version.
  10. */
  11. #include <common.h>
  12. #include <pci.h>
  13. #include <asm/addrspace.h>
  14. #define VR4131_PCIMMAW1REG (volatile unsigned int *)(CKSEG1 + 0x0f000c00)
  15. #define VR4131_PCIMMAW2REG (volatile unsigned int *)(CKSEG1 + 0x0f000c04)
  16. #define VR4131_PCITAW1REG (volatile unsigned int *)(CKSEG1 + 0x0f000c08)
  17. #define VR4131_PCITAW2REG (volatile unsigned int *)(CKSEG1 + 0x0f000c0c)
  18. #define VR4131_PCIMIOAWREG (volatile unsigned int *)(CKSEG1 + 0x0f000c10)
  19. #define VR4131_PCICONFDREG (volatile unsigned int *)(CKSEG1 + 0x0f000c14)
  20. #define VR4131_PCICONFAREG (volatile unsigned int *)(CKSEG1 + 0x0f000c18)
  21. #define VR4131_PCIMAILREG (volatile unsigned int *)(CKSEG1 + 0x0f000c1c)
  22. #define VR4131_BUSERRADREG (volatile unsigned int *)(CKSEG1 + 0x0f000c24)
  23. #define VR4131_INTCNTSTAREG (volatile unsigned int *)(CKSEG1 + 0x0f000c28)
  24. #define VR4131_PCIEXACCREG (volatile unsigned int *)(CKSEG1 + 0x0f000c2c)
  25. #define VR4131_PCIRECONTREG (volatile unsigned int *)(CKSEG1 + 0x0f000c30)
  26. #define VR4131_PCIENREG (volatile unsigned int *)(CKSEG1 + 0x0f000c34)
  27. #define VR4131_PCICLKSELREG (volatile unsigned int *)(CKSEG1 + 0x0f000c38)
  28. #define VR4131_PCITRDYREG (volatile unsigned int *)(CKSEG1 + 0x0f000c3c)
  29. #define VR4131_PCICLKRUNREG (volatile unsigned int *)(CKSEG1 + 0x0f000c60)
  30. #define VR4131_PCIHOSTCONFIG (volatile unsigned int *)(CKSEG1 + 0x0f000d00)
  31. #define VR4131_VENDORIDREG (volatile unsigned int *)(CKSEG1 + 0x0f000d00)
  32. #define VR4131_DEVICEIDREG (volatile unsigned int *)(CKSEG1 + 0x0f000d00)
  33. #define VR4131_COMMANDREG (volatile unsigned int *)(CKSEG1 + 0x0f000d04)
  34. #define VR4131_STATUSREG (volatile unsigned int *)(CKSEG1 + 0x0f000d04)
  35. #define VR4131_REVREG (volatile unsigned int *)(CKSEG1 + 0x0f000d08)
  36. #define VR4131_CLASSREG (volatile unsigned int *)(CKSEG1 + 0x0f000d08)
  37. #define VR4131_CACHELSREG (volatile unsigned int *)(CKSEG1 + 0x0f000d0c)
  38. #define VR4131_LATTIMERRG (volatile unsigned int *)(CKSEG1 + 0x0f000d0c)
  39. #define VR4131_MAILBAREG (volatile unsigned int *)(CKSEG1 + 0x0f000d10)
  40. #define VR4131_PCIMBA1REG (volatile unsigned int *)(CKSEG1 + 0x0f000d14)
  41. #define VR4131_PCIMBA2REG (volatile unsigned int *)(CKSEG1 + 0x0f000d18)
  42. /*#define VR41XX_PCIIRQ_OFFSET (VR41XX_IRQ_MAX + 1) */
  43. /*#define VR41XX_PCIIRQ_MAX (VR41XX_IRQ_MAX + 12) */
  44. /*#define VR4122_PCI_HOST_BASE 0xa0000000 */
  45. volatile unsigned int *pciconfigaddr;
  46. volatile unsigned int *pciconfigdata;
  47. #define PCI_ACCESS_READ 0
  48. #define PCI_ACCESS_WRITE 1
  49. /*
  50. * Access PCI Configuration Register for VR4131
  51. */
  52. static int vr4131_pci_config_access (u8 access_type, u32 dev, u32 reg,
  53. u32 * data)
  54. {
  55. u32 bus;
  56. u32 device;
  57. bus = ((dev & 0xff0000) >> 16);
  58. device = ((dev & 0xf800) >> 11);
  59. if (bus == 0) {
  60. /* Type 0 Configuration */
  61. *VR4131_PCICONFAREG = (u32) (1UL << device | (reg & 0xfc));
  62. } else {
  63. /* Type 1 Configuration */
  64. *VR4131_PCICONFAREG = (u32) (dev | ((reg / 4) << 2) | 1);
  65. }
  66. if (access_type == PCI_ACCESS_WRITE) {
  67. *VR4131_PCICONFDREG = *data;
  68. } else {
  69. *data = *VR4131_PCICONFDREG;
  70. }
  71. return (0);
  72. }
  73. static int vr4131_pci_read_config_byte (u32 hose, u32 dev, u32 reg, u8 * val)
  74. {
  75. u32 data;
  76. if (vr4131_pci_config_access (PCI_ACCESS_READ, dev, reg, &data))
  77. return -1;
  78. *val = (data >> ((reg & 3) << 3)) & 0xff;
  79. return 0;
  80. }
  81. static int vr4131_pci_read_config_word (u32 hose, u32 dev, u32 reg, u16 * val)
  82. {
  83. u32 data;
  84. if (reg & 1)
  85. return -1;
  86. if (vr4131_pci_config_access (PCI_ACCESS_READ, dev, reg, &data))
  87. return -1;
  88. *val = (data >> ((reg & 3) << 3)) & 0xffff;
  89. return 0;
  90. }
  91. static int vr4131_pci_read_config_dword (u32 hose, u32 dev, u32 reg,
  92. u32 * val)
  93. {
  94. u32 data = 0;
  95. if (reg & 3)
  96. return -1;
  97. if (vr4131_pci_config_access (PCI_ACCESS_READ, dev, reg, &data))
  98. return -1;
  99. *val = data;
  100. return (0);
  101. }
  102. static int vr4131_pci_write_config_byte (u32 hose, u32 dev, u32 reg, u8 val)
  103. {
  104. u32 data = 0;
  105. if (vr4131_pci_config_access (PCI_ACCESS_READ, dev, reg, &data))
  106. return -1;
  107. data = (data & ~(0xff << ((reg & 3) << 3))) | (val <<
  108. ((reg & 3) << 3));
  109. if (vr4131_pci_config_access (PCI_ACCESS_WRITE, dev, reg, &data))
  110. return -1;
  111. return 0;
  112. }
  113. static int vr4131_pci_write_config_word (u32 hose, u32 dev, u32 reg, u16 val)
  114. {
  115. u32 data = 0;
  116. if (reg & 1)
  117. return -1;
  118. if (vr4131_pci_config_access (PCI_ACCESS_READ, dev, reg, &data))
  119. return -1;
  120. data = (data & ~(0xffff << ((reg & 3) << 3))) | (val <<
  121. ((reg & 3) << 3));
  122. if (vr4131_pci_config_access (PCI_ACCESS_WRITE, dev, reg, &data))
  123. return -1;
  124. return 0;
  125. }
  126. static int vr4131_pci_write_config_dword (u32 hose, u32 dev, u32 reg, u32 val)
  127. {
  128. u32 data;
  129. if (reg & 3) {
  130. return -1;
  131. }
  132. data = val;
  133. if (vr4131_pci_config_access (PCI_ACCESS_WRITE, dev, reg, &data))
  134. return -1;
  135. return (0);
  136. }
  137. /*
  138. * Initialize VR4131 PCIU
  139. */
  140. vr4131_pciu_init ()
  141. {
  142. /* PCI clock */
  143. *VR4131_PCICLKSELREG = 0x00000002;
  144. /* PCI memory and I/O space */
  145. *VR4131_PCIMMAW1REG = 0x100F9010;
  146. *VR4131_PCIMMAW2REG = 0x140FD014;
  147. *VR4131_PCIMIOAWREG = 0x160FD000;
  148. /* Target memory window */
  149. *VR4131_PCITAW1REG = 0x00081000; /* 64MB */
  150. *VR4131_PCITAW2REG = 0x00000000;
  151. *VR4131_MAILBAREG = 0UL;
  152. *VR4131_PCIMBA1REG = 0UL;
  153. *VR4131_PCITRDYREG = 0x00008004;
  154. *VR4131_PCIENREG = 0x00000004; /* PCI enable */
  155. *VR4131_COMMANDREG = 0x02000007;
  156. }
  157. /*
  158. * Initialize Module
  159. */
  160. void init_vr4131_pci (struct pci_controller *hose)
  161. {
  162. hose->first_busno = 0;
  163. hose->last_busno = 0xff;
  164. vr4131_pciu_init (); /* Initialize VR4131 PCIU */
  165. /* PCI memory space #1 */
  166. pci_set_region (hose->regions + 0,
  167. 0x10000000, 0xb0000000, 0x04000000, PCI_REGION_MEM);
  168. /* PCI memory space #2 */
  169. pci_set_region (hose->regions + 1,
  170. 0x14000000, 0xb4000000, 0x02000000, PCI_REGION_MEM);
  171. /* PCI I/O space */
  172. pci_set_region (hose->regions + 2,
  173. 0x16000000, 0xb6000000, 0x02000000, PCI_REGION_IO);
  174. /* System memory space */
  175. pci_set_region (hose->regions + 3,
  176. 0x00000000,
  177. 0x80000000,
  178. 0x04000000, PCI_REGION_MEM | PCI_REGION_SYS_MEMORY);
  179. hose->region_count = 4;
  180. hose->read_byte = vr4131_pci_read_config_byte;
  181. hose->read_word = vr4131_pci_read_config_word;
  182. hose->read_dword = vr4131_pci_read_config_dword;
  183. hose->write_byte = vr4131_pci_write_config_byte;
  184. hose->write_word = vr4131_pci_write_config_word;
  185. hose->write_dword = vr4131_pci_write_config_dword;
  186. pci_register_hose (hose);
  187. hose->last_busno = pci_hose_scan (hose);
  188. return;
  189. }