m82xx_pci.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. /*
  2. *
  3. * (C) Copyright 2003
  4. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  5. *
  6. * (C) Copyright 2004 Red Hat, Inc.
  7. *
  8. * 2005 (c) MontaVista Software, Inc.
  9. * Vitaly Bordug <vbordug@ru.mvista.com>
  10. *
  11. * See file CREDITS for list of people who contributed to this
  12. * project.
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License as
  16. * published by the Free Software Foundation; either version 2 of
  17. * the License, or (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  27. * MA 02111-1307 USA
  28. */
  29. #include <linux/kernel.h>
  30. #include <linux/init.h>
  31. #include <linux/pci.h>
  32. #include <linux/slab.h>
  33. #include <linux/delay.h>
  34. #include <linux/irq.h>
  35. #include <linux/interrupt.h>
  36. #include <asm/byteorder.h>
  37. #include <asm/io.h>
  38. #include <asm/irq.h>
  39. #include <asm/uaccess.h>
  40. #include <asm/machdep.h>
  41. #include <asm/pci-bridge.h>
  42. #include <asm/immap_cpm2.h>
  43. #include <asm/mpc8260.h>
  44. #include <asm/cpm2.h>
  45. #include "m82xx_pci.h"
  46. /*
  47. * Interrupt routing
  48. */
  49. static inline int
  50. pq2pci_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
  51. {
  52. static char pci_irq_table[][4] =
  53. /*
  54. * PCI IDSEL/INTPIN->INTLINE
  55. * A B C D
  56. */
  57. {
  58. { PIRQA, PIRQB, PIRQC, PIRQD }, /* IDSEL 22 - PCI slot 0 */
  59. { PIRQD, PIRQA, PIRQB, PIRQC }, /* IDSEL 23 - PCI slot 1 */
  60. { PIRQC, PIRQD, PIRQA, PIRQB }, /* IDSEL 24 - PCI slot 2 */
  61. };
  62. const long min_idsel = 22, max_idsel = 24, irqs_per_slot = 4;
  63. return PCI_IRQ_TABLE_LOOKUP;
  64. }
  65. static void
  66. pq2pci_mask_irq(unsigned int irq)
  67. {
  68. int bit = irq - NR_CPM_INTS;
  69. *(volatile unsigned long *) PCI_INT_MASK_REG |= (1 << (31 - bit));
  70. return;
  71. }
  72. static void
  73. pq2pci_unmask_irq(unsigned int irq)
  74. {
  75. int bit = irq - NR_CPM_INTS;
  76. *(volatile unsigned long *) PCI_INT_MASK_REG &= ~(1 << (31 - bit));
  77. return;
  78. }
  79. static void
  80. pq2pci_mask_and_ack(unsigned int irq)
  81. {
  82. int bit = irq - NR_CPM_INTS;
  83. *(volatile unsigned long *) PCI_INT_MASK_REG |= (1 << (31 - bit));
  84. return;
  85. }
  86. static void
  87. pq2pci_end_irq(unsigned int irq)
  88. {
  89. int bit = irq - NR_CPM_INTS;
  90. *(volatile unsigned long *) PCI_INT_MASK_REG &= ~(1 << (31 - bit));
  91. return;
  92. }
  93. struct hw_interrupt_type pq2pci_ic = {
  94. "PQ2 PCI",
  95. NULL,
  96. NULL,
  97. pq2pci_unmask_irq,
  98. pq2pci_mask_irq,
  99. pq2pci_mask_and_ack,
  100. pq2pci_end_irq,
  101. 0
  102. };
  103. static irqreturn_t
  104. pq2pci_irq_demux(int irq, void *dev_id, struct pt_regs *regs)
  105. {
  106. unsigned long stat, mask, pend;
  107. int bit;
  108. for(;;) {
  109. stat = *(volatile unsigned long *) PCI_INT_STAT_REG;
  110. mask = *(volatile unsigned long *) PCI_INT_MASK_REG;
  111. pend = stat & ~mask & 0xf0000000;
  112. if (!pend)
  113. break;
  114. for (bit = 0; pend != 0; ++bit, pend <<= 1) {
  115. if (pend & 0x80000000)
  116. __do_IRQ(NR_CPM_INTS + bit, regs);
  117. }
  118. }
  119. return IRQ_HANDLED;
  120. }
  121. static struct irqaction pq2pci_irqaction = {
  122. .handler = pq2pci_irq_demux,
  123. .flags = SA_INTERRUPT,
  124. .mask = CPU_MASK_NONE,
  125. .name = "PQ2 PCI cascade",
  126. };
  127. void
  128. pq2pci_init_irq(void)
  129. {
  130. int irq;
  131. volatile cpm2_map_t *immap = cpm2_immr;
  132. #if defined CONFIG_ADS8272
  133. /* configure chip select for PCI interrupt controller */
  134. immap->im_memctl.memc_br3 = PCI_INT_STAT_REG | 0x00001801;
  135. immap->im_memctl.memc_or3 = 0xffff8010;
  136. #elif defined CONFIG_PQ2FADS
  137. immap->im_memctl.memc_br8 = PCI_INT_STAT_REG | 0x00001801;
  138. immap->im_memctl.memc_or8 = 0xffff8010;
  139. #endif
  140. for (irq = NR_CPM_INTS; irq < NR_CPM_INTS + 4; irq++)
  141. irq_desc[irq].handler = &pq2pci_ic;
  142. /* make PCI IRQ level sensitive */
  143. immap->im_intctl.ic_siexr &=
  144. ~(1 << (14 - (PCI_INT_TO_SIU - SIU_INT_IRQ1)));
  145. /* mask all PCI interrupts */
  146. *(volatile unsigned long *) PCI_INT_MASK_REG |= 0xfff00000;
  147. /* install the demultiplexer for the PCI cascade interrupt */
  148. setup_irq(PCI_INT_TO_SIU, &pq2pci_irqaction);
  149. return;
  150. }
  151. static int
  152. pq2pci_exclude_device(u_char bus, u_char devfn)
  153. {
  154. return PCIBIOS_SUCCESSFUL;
  155. }
  156. /* PCI bus configuration registers.
  157. */
  158. static void
  159. pq2ads_setup_pci(struct pci_controller *hose)
  160. {
  161. __u32 val;
  162. volatile cpm2_map_t *immap = cpm2_immr;
  163. bd_t* binfo = (bd_t*) __res;
  164. u32 sccr = immap->im_clkrst.car_sccr;
  165. uint pci_div,freq,time;
  166. /* PCI int lowest prio */
  167. /* Each 4 bits is a device bus request and the MS 4bits
  168. is highest priority */
  169. /* Bus 4bit value
  170. --- ----------
  171. CPM high 0b0000
  172. CPM middle 0b0001
  173. CPM low 0b0010
  174. PCI reguest 0b0011
  175. Reserved 0b0100
  176. Reserved 0b0101
  177. Internal Core 0b0110
  178. External Master 1 0b0111
  179. External Master 2 0b1000
  180. External Master 3 0b1001
  181. The rest are reserved
  182. */
  183. immap->im_siu_conf.siu_82xx.sc_ppc_alrh = 0x61207893;
  184. /* park bus on core */
  185. immap->im_siu_conf.siu_82xx.sc_ppc_acr = PPC_ACR_BUS_PARK_CORE;
  186. /*
  187. * Set up master windows that allow the CPU to access PCI space. These
  188. * windows are set up using the two SIU PCIBR registers.
  189. */
  190. immap->im_memctl.memc_pcimsk0 = M82xx_PCI_PRIM_WND_SIZE;
  191. immap->im_memctl.memc_pcibr0 = M82xx_PCI_PRIM_WND_BASE | PCIBR_ENABLE;
  192. #ifdef M82xx_PCI_SEC_WND_SIZE
  193. immap->im_memctl.memc_pcimsk1 = M82xx_PCI_SEC_WND_SIZE;
  194. immap->im_memctl.memc_pcibr1 = M82xx_PCI_SEC_WND_BASE | PCIBR_ENABLE;
  195. #endif
  196. #if defined CONFIG_ADS8272
  197. immap->im_siu_conf.siu_82xx.sc_siumcr =
  198. (immap->im_siu_conf.siu_82xx.sc_siumcr &
  199. ~(SIUMCR_BBD | SIUMCR_ESE | SIUMCR_PBSE |
  200. SIUMCR_CDIS | SIUMCR_DPPC11 | SIUMCR_L2CPC11 |
  201. SIUMCR_LBPC11 | SIUMCR_APPC11 |
  202. SIUMCR_CS10PC11 | SIUMCR_BCTLC11 | SIUMCR_MMR11)) |
  203. SIUMCR_DPPC11 | SIUMCR_L2CPC01 | SIUMCR_LBPC00 |
  204. SIUMCR_APPC10 | SIUMCR_CS10PC00 |
  205. SIUMCR_BCTLC00 | SIUMCR_MMR11 ;
  206. #elif defined CONFIG_PQ2FADS
  207. /*
  208. * Setting required to enable IRQ1-IRQ7 (SIUMCR [DPPC]),
  209. * and local bus for PCI (SIUMCR [LBPC]).
  210. */
  211. immap->im_siu_conf.siu_82xx.sc_siumcr = (immap->im_siu_conf.siu_82xx.sc_siumcr &
  212. ~(SIUMCR_L2CPC11 | SIUMCR_LBPC11 | SIUMCR_CS10PC11 | SIUMCR_APPC11) |
  213. SIUMCR_BBD | SIUMCR_LBPC01 | SIUMCR_DPPC11 | SIUMCR_APPC10);
  214. #endif
  215. /* Enable PCI */
  216. immap->im_pci.pci_gcr = cpu_to_le32(PCIGCR_PCI_BUS_EN);
  217. pci_div = ( (sccr & SCCR_PCI_MODCK) ? 2 : 1) *
  218. ( ( (sccr & SCCR_PCIDF_MSK) >> SCCR_PCIDF_SHIFT) + 1);
  219. freq = (uint)((2*binfo->bi_cpmfreq)/(pci_div));
  220. time = (int)66666666/freq;
  221. /* due to PCI Local Bus spec, some devices needs to wait such a long
  222. time after RST deassertion. More specifically, 0.508s for 66MHz & twice more for 33 */
  223. printk("%s: The PCI bus is %d Mhz.\nWaiting %s after deasserting RST...\n",__FILE__,freq,
  224. (time==1) ? "0.5 seconds":"1 second" );
  225. {
  226. int i;
  227. for(i=0;i<(500*time);i++)
  228. udelay(1000);
  229. }
  230. /* setup ATU registers */
  231. immap->im_pci.pci_pocmr0 = cpu_to_le32(POCMR_ENABLE | POCMR_PCI_IO |
  232. ((~(M82xx_PCI_IO_SIZE - 1U)) >> POTA_ADDR_SHIFT));
  233. immap->im_pci.pci_potar0 = cpu_to_le32(M82xx_PCI_LOWER_IO >> POTA_ADDR_SHIFT);
  234. immap->im_pci.pci_pobar0 = cpu_to_le32(M82xx_PCI_IO_BASE >> POTA_ADDR_SHIFT);
  235. /* Set-up non-prefetchable window */
  236. immap->im_pci.pci_pocmr1 = cpu_to_le32(POCMR_ENABLE | ((~(M82xx_PCI_MMIO_SIZE-1U)) >> POTA_ADDR_SHIFT));
  237. immap->im_pci.pci_potar1 = cpu_to_le32(M82xx_PCI_LOWER_MMIO >> POTA_ADDR_SHIFT);
  238. immap->im_pci.pci_pobar1 = cpu_to_le32((M82xx_PCI_LOWER_MMIO - M82xx_PCI_MMIO_OFFSET) >> POTA_ADDR_SHIFT);
  239. /* Set-up prefetchable window */
  240. immap->im_pci.pci_pocmr2 = cpu_to_le32(POCMR_ENABLE |POCMR_PREFETCH_EN |
  241. (~(M82xx_PCI_MEM_SIZE-1U) >> POTA_ADDR_SHIFT));
  242. immap->im_pci.pci_potar2 = cpu_to_le32(M82xx_PCI_LOWER_MEM >> POTA_ADDR_SHIFT);
  243. immap->im_pci.pci_pobar2 = cpu_to_le32((M82xx_PCI_LOWER_MEM - M82xx_PCI_MEM_OFFSET) >> POTA_ADDR_SHIFT);
  244. /* Inbound transactions from PCI memory space */
  245. immap->im_pci.pci_picmr0 = cpu_to_le32(PICMR_ENABLE | PICMR_PREFETCH_EN |
  246. ((~(M82xx_PCI_SLAVE_MEM_SIZE-1U)) >> PITA_ADDR_SHIFT));
  247. immap->im_pci.pci_pibar0 = cpu_to_le32(M82xx_PCI_SLAVE_MEM_BUS >> PITA_ADDR_SHIFT);
  248. immap->im_pci.pci_pitar0 = cpu_to_le32(M82xx_PCI_SLAVE_MEM_LOCAL>> PITA_ADDR_SHIFT);
  249. #if defined CONFIG_ADS8272
  250. /* PCI int highest prio */
  251. immap->im_siu_conf.siu_82xx.sc_ppc_alrh = 0x01236745;
  252. #elif defined CONFIG_PQ2FADS
  253. immap->im_siu_conf.siu_82xx.sc_ppc_alrh = 0x03124567;
  254. #endif
  255. /* park bus on PCI */
  256. immap->im_siu_conf.siu_82xx.sc_ppc_acr = PPC_ACR_BUS_PARK_PCI;
  257. /* Enable bus mastering and inbound memory transactions */
  258. early_read_config_dword(hose, hose->first_busno, 0, PCI_COMMAND, &val);
  259. val &= 0xffff0000;
  260. val |= PCI_COMMAND_MEMORY|PCI_COMMAND_MASTER;
  261. early_write_config_dword(hose, hose->first_busno, 0, PCI_COMMAND, val);
  262. }
  263. void __init pq2_find_bridges(void)
  264. {
  265. extern int pci_assign_all_buses;
  266. struct pci_controller * hose;
  267. int host_bridge;
  268. pci_assign_all_buses = 1;
  269. hose = pcibios_alloc_controller();
  270. if (!hose)
  271. return;
  272. ppc_md.pci_swizzle = common_swizzle;
  273. hose->first_busno = 0;
  274. hose->bus_offset = 0;
  275. hose->last_busno = 0xff;
  276. #ifdef CONFIG_ADS8272
  277. hose->set_cfg_type = 1;
  278. #endif
  279. setup_m8260_indirect_pci(hose,
  280. (unsigned long)&cpm2_immr->im_pci.pci_cfg_addr,
  281. (unsigned long)&cpm2_immr->im_pci.pci_cfg_data);
  282. /* Make sure it is a supported bridge */
  283. early_read_config_dword(hose,
  284. 0,
  285. PCI_DEVFN(0,0),
  286. PCI_VENDOR_ID,
  287. &host_bridge);
  288. switch (host_bridge) {
  289. case PCI_DEVICE_ID_MPC8265:
  290. break;
  291. case PCI_DEVICE_ID_MPC8272:
  292. break;
  293. default:
  294. printk("Attempting to use unrecognized host bridge ID"
  295. " 0x%08x.\n", host_bridge);
  296. break;
  297. }
  298. pq2ads_setup_pci(hose);
  299. hose->io_space.start = M82xx_PCI_LOWER_IO;
  300. hose->io_space.end = M82xx_PCI_UPPER_IO;
  301. hose->mem_space.start = M82xx_PCI_LOWER_MEM;
  302. hose->mem_space.end = M82xx_PCI_UPPER_MMIO;
  303. hose->pci_mem_offset = M82xx_PCI_MEM_OFFSET;
  304. isa_io_base =
  305. (unsigned long) ioremap(M82xx_PCI_IO_BASE,
  306. M82xx_PCI_IO_SIZE);
  307. hose->io_base_virt = (void *) isa_io_base;
  308. /* setup resources */
  309. pci_init_resource(&hose->mem_resources[0],
  310. M82xx_PCI_LOWER_MEM,
  311. M82xx_PCI_UPPER_MEM,
  312. IORESOURCE_MEM|IORESOURCE_PREFETCH, "PCI prefetchable memory");
  313. pci_init_resource(&hose->mem_resources[1],
  314. M82xx_PCI_LOWER_MMIO,
  315. M82xx_PCI_UPPER_MMIO,
  316. IORESOURCE_MEM, "PCI memory");
  317. pci_init_resource(&hose->io_resource,
  318. M82xx_PCI_LOWER_IO,
  319. M82xx_PCI_UPPER_IO,
  320. IORESOURCE_IO | 1, "PCI I/O");
  321. ppc_md.pci_exclude_device = pq2pci_exclude_device;
  322. hose->last_busno = pciauto_bus_scan(hose, hose->first_busno);
  323. ppc_md.pci_map_irq = pq2pci_map_irq;
  324. ppc_md.pcibios_fixup = NULL;
  325. ppc_md.pcibios_fixup_bus = NULL;
  326. }