sc520_cdp_pci.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. /*
  2. *
  3. * (C) Copyright 2002
  4. * Daniel Engström, Omicron Ceti AB <daniel@omicron.se>.
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. * MA 02111-1307 USA
  23. */
  24. #include <common.h>
  25. #include <pci.h>
  26. #include <asm/io.h>
  27. #include <asm/pci.h>
  28. #include <asm/ic/sc520.h>
  29. #include <asm/ic/pci.h>
  30. DECLARE_GLOBAL_DATA_PTR;
  31. #undef SC520_CDP_DEBUG
  32. #ifdef SC520_CDP_DEBUG
  33. #define PRINTF(fmt,args...) printf (fmt ,##args)
  34. #else
  35. #define PRINTF(fmt,args...)
  36. #endif
  37. static void pci_sc520_cdp_fixup_irq(struct pci_controller *hose, pci_dev_t dev)
  38. {
  39. /* a configurable lists of irqs to steal
  40. * when we need one (a board with more pci interrupt pins
  41. * would use a larger table */
  42. static int irq_list[] = {
  43. CONFIG_SYS_FIRST_PCI_IRQ,
  44. CONFIG_SYS_SECOND_PCI_IRQ,
  45. CONFIG_SYS_THIRD_PCI_IRQ,
  46. CONFIG_SYS_FORTH_PCI_IRQ
  47. };
  48. static int next_irq_index=0;
  49. uchar tmp_pin;
  50. int pin;
  51. pci_hose_read_config_byte(hose, dev, PCI_INTERRUPT_PIN, &tmp_pin);
  52. pin = tmp_pin;
  53. pin-=1; /* pci config space use 1-based numbering */
  54. if (-1 == pin) {
  55. return; /* device use no irq */
  56. }
  57. /* map device number + pin to a pin on the sc520 */
  58. switch (PCI_DEV(dev)) {
  59. case 20:
  60. pin+=SC520_PCI_INTA;
  61. break;
  62. case 19:
  63. pin+=SC520_PCI_INTB;
  64. break;
  65. case 18:
  66. pin+=SC520_PCI_INTC;
  67. break;
  68. case 17:
  69. pin+=SC520_PCI_INTD;
  70. break;
  71. default:
  72. return;
  73. }
  74. pin&=3; /* wrap around */
  75. if (sc520_pci_ints[pin] == -1) {
  76. /* re-route one interrupt for us */
  77. if (next_irq_index > 3) {
  78. return;
  79. }
  80. if (pci_sc520_set_irq(pin, irq_list[next_irq_index])) {
  81. return;
  82. }
  83. next_irq_index++;
  84. }
  85. if (-1 != sc520_pci_ints[pin]) {
  86. pci_hose_write_config_byte(hose, dev, PCI_INTERRUPT_LINE,
  87. sc520_pci_ints[pin]);
  88. }
  89. PRINTF("fixup_irq: device %d pin %c irq %d\n",
  90. PCI_DEV(dev), 'A' + pin, sc520_pci_ints[pin]);
  91. }
  92. static struct pci_controller sc520_cdp_hose = {
  93. fixup_irq: pci_sc520_cdp_fixup_irq,
  94. };
  95. void pci_init_board(void)
  96. {
  97. pci_sc520_init(&sc520_cdp_hose);
  98. }
  99. /*
  100. * This function should map a chunk of size bytes
  101. * of the system address space to the ISA bus
  102. *
  103. * The function will return the memory address
  104. * as seen by the host (which may very will be the
  105. * same as the bus address)
  106. */
  107. u32 isa_map_rom(u32 bus_addr, int size)
  108. {
  109. u32 par;
  110. PRINTF("isa_map_rom asked to map %d bytes at %x\n",
  111. size, bus_addr);
  112. par = size;
  113. if (par < 0x80000) {
  114. par = 0x80000;
  115. }
  116. par >>= 12;
  117. par--;
  118. par&=0x7f;
  119. par <<= 18;
  120. par |= (bus_addr>>12);
  121. par |= 0x50000000;
  122. PRINTF ("setting PAR11 to %x\n", par);
  123. /* Map rom 0x10000 with PAR1 */
  124. sc520_mmcr->par[11] = par;
  125. return bus_addr;
  126. }
  127. /*
  128. * this function removed any mapping created
  129. * with pci_get_rom_window()
  130. */
  131. void isa_unmap_rom(u32 addr)
  132. {
  133. PRINTF("isa_unmap_rom asked to unmap %x", addr);
  134. if ((addr>>12) == (sc520_mmcr->par[11] & 0x3ffff)) {
  135. sc520_mmcr->par[11] = 0;
  136. PRINTF(" done\n");
  137. return;
  138. }
  139. PRINTF(" not ours\n");
  140. }
  141. #define PCI_ROM_TEMP_SPACE 0x10000
  142. /*
  143. * This function should map a chunk of size bytes
  144. * of the system address space to the PCI bus,
  145. * suitable to map PCI ROMS (bus address < 16M)
  146. * the function will return the host memory address
  147. * which should be converted into a bus address
  148. * before used to configure the PCI rom address
  149. * decoder
  150. */
  151. u32 pci_get_rom_window(struct pci_controller *hose, int size)
  152. {
  153. u32 par;
  154. par = size;
  155. if (par < 0x80000) {
  156. par = 0x80000;
  157. }
  158. par >>= 16;
  159. par--;
  160. par&=0x7ff;
  161. par <<= 14;
  162. par |= (PCI_ROM_TEMP_SPACE>>16);
  163. par |= 0x72000000;
  164. PRINTF ("setting PAR1 to %x\n", par);
  165. /* Map rom 0x10000 with PAR1 */
  166. sc520_mmcr->par[1] = par;
  167. return PCI_ROM_TEMP_SPACE;
  168. }
  169. /*
  170. * this function removed any mapping created
  171. * with pci_get_rom_window()
  172. */
  173. void pci_remove_rom_window(struct pci_controller *hose, u32 addr)
  174. {
  175. PRINTF("pci_remove_rom_window: %x", addr);
  176. if (addr == PCI_ROM_TEMP_SPACE) {
  177. sc520_mmcr->par[1] = 0;
  178. PRINTF(" done\n");
  179. return;
  180. }
  181. PRINTF(" not ours\n");
  182. }
  183. /*
  184. * This function is called in order to provide acces to the
  185. * legacy video I/O ports on the PCI bus.
  186. * After this function accesses to I/O ports 0x3b0-0x3bb and
  187. * 0x3c0-0x3df shuld result in transactions on the PCI bus.
  188. *
  189. */
  190. int pci_enable_legacy_video_ports(struct pci_controller *hose)
  191. {
  192. /* Map video memory to 0xa0000*/
  193. sc520_mmcr->par[0] = 0x7200400a;
  194. /* forward all I/O accesses to PCI */
  195. sc520_mmcr->adddecctl = sc520_mmcr->adddecctl | IO_HOLE_DEST_PCI;
  196. /* so we map away all io ports to pci (only way to access pci io
  197. * below 0x400. But then we have to map back the portions that we dont
  198. * use so that the generate cycles on the GPIO bus where the sio and
  199. * ISA slots are connected, this requre the use of several PAR registers
  200. */
  201. /* bring 0x100 - 0x1ef back to ISA using PAR5 */
  202. sc520_mmcr->par[5] = 0x30ef0100;
  203. /* IDE use 1f0-1f7 */
  204. /* bring 0x1f8 - 0x2f7 back to ISA using PAR6 */
  205. sc520_mmcr->par[6] = 0x30ff01f8;
  206. /* com2 use 2f8-2ff */
  207. /* bring 0x300 - 0x3af back to ISA using PAR7 */
  208. sc520_mmcr->par[7] = 0x30af0300;
  209. /* vga use 3b0-3bb */
  210. /* bring 0x3bc - 0x3bf back to ISA using PAR8 */
  211. sc520_mmcr->par[8] = 0x300303bc;
  212. /* vga use 3c0-3df */
  213. /* bring 0x3e0 - 0x3f5 back to ISA using PAR9 */
  214. sc520_mmcr->par[9] = 0x301503e0;
  215. /* ide use 3f6 */
  216. /* bring 0x3f7 back to ISA using PAR10 */
  217. sc520_mmcr->par[10] = 0x300003f7;
  218. /* com1 use 3f8-3ff */
  219. return 0;
  220. }