sc520_spunk_pci.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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 <ds1722.h>
  27. #include <asm/io.h>
  28. #include <asm/pci.h>
  29. #include <asm/ic/sc520.h>
  30. #include <asm/ic/pci.h>
  31. DECLARE_GLOBAL_DATA_PTR;
  32. static void pci_sc520_spunk_fixup_irq(struct pci_controller *hose, pci_dev_t dev)
  33. {
  34. int version = sc520_mmcr->sysinfo;
  35. /* a configurable lists of irqs to steal
  36. * when we need one (a board with more pci interrupt pins
  37. * would use a larger table */
  38. static int irq_list[] = {
  39. CONFIG_SYS_FIRST_PCI_IRQ,
  40. CONFIG_SYS_SECOND_PCI_IRQ,
  41. CONFIG_SYS_THIRD_PCI_IRQ,
  42. CONFIG_SYS_FORTH_PCI_IRQ
  43. };
  44. static int next_irq_index=0;
  45. uchar tmp_pin;
  46. int pin;
  47. pci_hose_read_config_byte(hose, dev, PCI_INTERRUPT_PIN, &tmp_pin);
  48. pin = tmp_pin;
  49. pin-=1; /* pci config space use 1-based numbering */
  50. if (-1 == pin) {
  51. return; /* device use no irq */
  52. }
  53. /* map device number + pin to a pin on the sc520 */
  54. switch (PCI_DEV(dev)) {
  55. case 6: /* ETH0 */
  56. pin+=SC520_PCI_INTA;
  57. break;
  58. case 7: /* ETH1 */
  59. pin+=SC520_PCI_INTB;
  60. break;
  61. case 8: /* Crypto */
  62. pin+=SC520_PCI_INTC;
  63. break;
  64. case 9: /* PMC slot */
  65. pin+=SC520_PCI_INTD;
  66. break;
  67. case 10: /* PC-Card */
  68. if (version < 10) {
  69. pin+=SC520_PCI_INTD;
  70. } else {
  71. pin+=SC520_PCI_INTC;
  72. }
  73. break;
  74. default:
  75. return;
  76. }
  77. pin&=3; /* wrap around */
  78. if (sc520_pci_ints[pin] == -1) {
  79. /* re-route one interrupt for us */
  80. if (next_irq_index > 3) {
  81. return;
  82. }
  83. if (pci_sc520_set_irq(pin, irq_list[next_irq_index])) {
  84. return;
  85. }
  86. next_irq_index++;
  87. }
  88. if (-1 != sc520_pci_ints[pin]) {
  89. pci_hose_write_config_byte(hose, dev, PCI_INTERRUPT_LINE,
  90. sc520_pci_ints[pin]);
  91. }
  92. #if 0
  93. printf("fixup_irq: device %d pin %c irq %d\n",
  94. PCI_DEV(dev), 'A' + pin, sc520_pci_ints[pin]);
  95. #endif
  96. }
  97. static void pci_sc520_spunk_configure_cardbus(struct pci_controller *hose,
  98. pci_dev_t dev, struct pci_config_table *te)
  99. {
  100. u32 io_base;
  101. u32 temp;
  102. pciauto_config_device(hose, dev);
  103. pci_hose_write_config_word(hose, dev, PCI_COMMAND, 0x07); /* enable device */
  104. pci_hose_write_config_byte(hose, dev, 0x0c, 0x10); /* cacheline size */
  105. pci_hose_write_config_byte(hose, dev, 0x0d, 0x40); /* latency timer */
  106. pci_hose_write_config_byte(hose, dev, 0x1b, 0x40); /* cardbus latency timer */
  107. pci_hose_write_config_word(hose, dev, PCI_BRIDGE_CONTROL, 0x0040); /* reset cardbus */
  108. pci_hose_write_config_word(hose, dev, PCI_BRIDGE_CONTROL, 0x0080); /* route interrupts though ExCA */
  109. pci_hose_write_config_word(hose, dev, 0x44, 0x3e0); /* map legacy I/O port to 0x3e0 */
  110. pci_hose_read_config_dword(hose, dev, 0x80, &temp); /* System control */
  111. pci_hose_write_config_dword(hose, dev, 0x80, temp | 0x60); /* System control: disable clockrun */
  112. /* route MF0 to ~INT and MF3 to IRQ7
  113. * reserve all others */
  114. pci_hose_write_config_dword(hose, dev, 0x8c, 0x00007002);
  115. pci_hose_write_config_byte(hose, dev, 0x91, 0x00); /* card control */
  116. pci_hose_write_config_byte(hose, dev, 0x92, 0x62); /* device control */
  117. if (te->device != 0xac56) {
  118. pci_hose_write_config_byte(hose, dev, 0x93, 0x21); /* async interrupt enable */
  119. pci_hose_write_config_word(hose, dev, 0xa8, 0x0000); /* reset GPIO */
  120. pci_hose_write_config_word(hose, dev, 0xac, 0x0000); /* reset GPIO */
  121. pci_hose_write_config_word(hose, dev, 0xaa, 0x0000); /* reset GPIO */
  122. pci_hose_write_config_word(hose, dev, 0xae, 0x0000); /* reset GPIO */
  123. } else {
  124. pci_hose_write_config_byte(hose, dev, 0x93, 0x20); /* */
  125. }
  126. pci_hose_write_config_word(hose, dev, 0xa4, 0x8000); /* reset power management */
  127. pci_hose_read_config_dword(hose, dev, PCI_BASE_ADDRESS_0, &io_base);
  128. io_base &= ~0xfL;
  129. writeb(0x07, io_base+0x803); /* route CSC irq though ExCA and enable IRQ7 */
  130. writel(0, io_base+0x10); /* CLKRUN default */
  131. writel(0, io_base+0x20); /* CLKRUN default */
  132. }
  133. static struct pci_config_table pci_sc520_spunk_config_table[] = {
  134. { 0x104c, 0xac50, PCI_ANY_ID, 0, 0x0a, 0, pci_sc520_spunk_configure_cardbus, { 0, 0, 0} },
  135. { 0x104c, 0xac56, PCI_ANY_ID, 0, 0x0a, 0, pci_sc520_spunk_configure_cardbus, { 0, 0, 0} },
  136. { 0, 0, 0, 0, 0, 0, NULL, {0,0,0}}
  137. };
  138. static struct pci_controller sc520_spunk_hose = {
  139. fixup_irq: pci_sc520_spunk_fixup_irq,
  140. config_table: pci_sc520_spunk_config_table,
  141. first_busno: 0x00,
  142. last_busno: 0xff,
  143. };
  144. void pci_init_board(void)
  145. {
  146. pci_sc520_init(&sc520_spunk_hose);
  147. }
  148. /*
  149. * This function should map a chunk of size bytes
  150. * of the system address space to the ISA bus
  151. *
  152. * The function will return the memory address
  153. * as seen by the host (which may very will be the
  154. * same as the bus address)
  155. */
  156. u32 isa_map_rom(u32 bus_addr, int size)
  157. {
  158. u32 par;
  159. printf("isa_map_rom asked to map %d bytes at %x\n",
  160. size, bus_addr);
  161. par = size;
  162. if (par < 0x80000) {
  163. par = 0x80000;
  164. }
  165. par >>= 12;
  166. par--;
  167. par&=0x7f;
  168. par <<= 18;
  169. par |= (bus_addr>>12);
  170. par |= 0x50000000;
  171. printf ("setting PAR11 to %x\n", par);
  172. /* Map rom 0x10000 with PAR1 */
  173. sc520_mmcr->par[11] = par;
  174. return bus_addr;
  175. }
  176. /*
  177. * this function removed any mapping created
  178. * with pci_get_rom_window()
  179. */
  180. void isa_unmap_rom(u32 addr)
  181. {
  182. printf("isa_unmap_rom asked to unmap %x", addr);
  183. if ((addr>>12) == (sc520_mmcr->par[11] & 0x3ffff)) {
  184. sc520_mmcr->par[11] = 0;
  185. printf(" done\n");
  186. return;
  187. }
  188. printf(" not ours\n");
  189. }
  190. #define PCI_ROM_TEMP_SPACE 0x10000
  191. /*
  192. * This function should map a chunk of size bytes
  193. * of the system address space to the PCI bus,
  194. * suitable to map PCI ROMS (bus address < 16M)
  195. * the function will return the host memory address
  196. * which should be converted into a bus address
  197. * before used to configure the PCI rom address
  198. * decoder
  199. */
  200. u32 pci_get_rom_window(struct pci_controller *hose, int size)
  201. {
  202. u32 par;
  203. par = size;
  204. if (par < 0x80000) {
  205. par = 0x80000;
  206. }
  207. par >>= 16;
  208. par--;
  209. par&=0x7ff;
  210. par <<= 14;
  211. par |= (PCI_ROM_TEMP_SPACE>>16);
  212. par |= 0x72000000;
  213. printf ("setting PAR1 to %x\n", par);
  214. /* Map rom 0x10000 with PAR1 */
  215. sc520_mmcr->par[1] = par;
  216. return PCI_ROM_TEMP_SPACE;
  217. }
  218. /*
  219. * this function removed any mapping created
  220. * with pci_get_rom_window()
  221. */
  222. void pci_remove_rom_window(struct pci_controller *hose, u32 addr)
  223. {
  224. printf("pci_remove_rom_window: %x", addr);
  225. if (addr == PCI_ROM_TEMP_SPACE) {
  226. sc520_mmcr->par[1] = 0;
  227. printf(" done\n");
  228. return;
  229. }
  230. printf(" not ours\n");
  231. }
  232. /*
  233. * This function is called in order to provide acces to the
  234. * legacy video I/O ports on the PCI bus.
  235. * After this function accesses to I/O ports 0x3b0-0x3bb and
  236. * 0x3c0-0x3df shuld result in transactions on the PCI bus.
  237. *
  238. */
  239. int pci_enable_legacy_video_ports(struct pci_controller *hose)
  240. {
  241. /* Map video memory to 0xa0000*/
  242. sc520_mmcr->par[0] = 0x7200400a;
  243. /* forward all I/O accesses to PCI */
  244. sc520_mmcr->adddecctl = sc520_mmcr->adddecctl | IO_HOLE_DEST_PCI;
  245. /* so we map away all io ports to pci (only way to access pci io
  246. * below 0x400. But then we have to map back the portions that we dont
  247. * use so that the generate cycles on the GPIO bus where the sio and
  248. * ISA slots are connected, this requre the use of several PAR registers
  249. */
  250. /* bring 0x100 - 0x2f7 back to ISA using PAR5 */
  251. sc520_mmcr->par[5] = 0x31f70100;
  252. /* com2 use 2f8-2ff */
  253. /* bring 0x300 - 0x3af back to ISA using PAR7 */
  254. sc520_mmcr->par[7] = 0x30af0300;
  255. /* vga use 3b0-3bb */
  256. /* bring 0x3bc - 0x3bf back to ISA using PAR8 */
  257. sc520_mmcr->par[8] = 0x300303bc;
  258. /* vga use 3c0-3df */
  259. /* bring 0x3e0 - 0x3f7 back to ISA using PAR9 */
  260. sc520_mmcr->par[9] = 0x301703e0;
  261. /* com1 use 3f8-3ff */
  262. return 0;
  263. }