aboutsummaryrefslogtreecommitdiffstats
path: root/arch/sh/drivers/pci/pci-sh7751.c
diff options
context:
space:
mode:
authorPaul Mundt <lethal@linux-sh.org>2006-09-27 03:43:28 -0400
committerPaul Mundt <lethal@linux-sh.org>2006-09-27 03:43:28 -0400
commit959f85f8a3223c116bbe95dd8a9b207790b5d4d3 (patch)
treee7da9ccf292f860bfa0ff9cc8b2682cd1d6bad4d /arch/sh/drivers/pci/pci-sh7751.c
parente108b2ca2349f510ce7d7f910eda89f71d710d84 (diff)
sh: Consolidated SH7751/SH7780 PCI support.
This cleans up quite a lot of the PCI mess that we currently have, and attempts to consolidate the duplication in the SH7780 and SH7751 PCI controllers. Signed-off-by: Paul Mundt <lethal@linux-sh.org>
Diffstat (limited to 'arch/sh/drivers/pci/pci-sh7751.c')
-rw-r--r--arch/sh/drivers/pci/pci-sh7751.c322
1 files changed, 61 insertions, 261 deletions
diff --git a/arch/sh/drivers/pci/pci-sh7751.c b/arch/sh/drivers/pci/pci-sh7751.c
index 65093ec1b55e..dbe837884983 100644
--- a/arch/sh/drivers/pci/pci-sh7751.c
+++ b/arch/sh/drivers/pci/pci-sh7751.c
@@ -15,180 +15,14 @@
15 15
16#undef DEBUG 16#undef DEBUG
17 17
18#include <linux/types.h>
19#include <linux/kernel.h>
20#include <linux/init.h> 18#include <linux/init.h>
21#include <linux/pci.h> 19#include <linux/pci.h>
22#include <linux/sched.h> 20#include <linux/types.h>
23#include <linux/ioport.h>
24#include <linux/errno.h> 21#include <linux/errno.h>
25#include <linux/irq.h>
26#include <linux/delay.h> 22#include <linux/delay.h>
27 23#include "pci-sh4.h"
28#include <asm/machvec.h> 24#include <asm/addrspace.h>
29#include <asm/io.h> 25#include <asm/io.h>
30#include "pci-sh7751.h"
31
32static unsigned int pci_probe = PCI_PROBE_CONF1;
33extern int pci_fixup_pcic(void);
34
35void pcibios_fixup_irqs(void) __attribute__ ((weak));
36
37/*
38 * Direct access to PCI hardware...
39 */
40
41#define CONFIG_CMD(bus, devfn, where) (0x80000000 | (bus->number << 16) | (devfn << 8) | (where & ~3))
42
43/*
44 * Functions for accessing PCI configuration space with type 1 accesses
45 */
46static int sh7751_pci_read(struct pci_bus *bus, unsigned int devfn,
47 int where, int size, u32 *val)
48{
49 unsigned long flags;
50 u32 data;
51
52 /*
53 * PCIPDR may only be accessed as 32 bit words,
54 * so we must do byte alignment by hand
55 */
56 local_irq_save(flags);
57 outl(CONFIG_CMD(bus,devfn,where), PCI_REG(SH7751_PCIPAR));
58 data = inl(PCI_REG(SH7751_PCIPDR));
59 local_irq_restore(flags);
60
61 switch (size) {
62 case 1:
63 *val = (data >> ((where & 3) << 3)) & 0xff;
64 break;
65 case 2:
66 *val = (data >> ((where & 2) << 3)) & 0xffff;
67 break;
68 case 4:
69 *val = data;
70 break;
71 default:
72 return PCIBIOS_FUNC_NOT_SUPPORTED;
73 }
74
75 return PCIBIOS_SUCCESSFUL;
76}
77
78/*
79 * Since SH7751 only does 32bit access we'll have to do a read,
80 * mask,write operation.
81 * We'll allow an odd byte offset, though it should be illegal.
82 */
83static int sh7751_pci_write(struct pci_bus *bus, unsigned int devfn,
84 int where, int size, u32 val)
85{
86 unsigned long flags;
87 int shift;
88 u32 data;
89
90 local_irq_save(flags);
91 outl(CONFIG_CMD(bus,devfn,where), PCI_REG(SH7751_PCIPAR));
92 data = inl(PCI_REG(SH7751_PCIPDR));
93 local_irq_restore(flags);
94
95 switch (size) {
96 case 1:
97 shift = (where & 3) << 3;
98 data &= ~(0xff << shift);
99 data |= ((val & 0xff) << shift);
100 break;
101 case 2:
102 shift = (where & 2) << 3;
103 data &= ~(0xffff << shift);
104 data |= ((val & 0xffff) << shift);
105 break;
106 case 4:
107 data = val;
108 break;
109 default:
110 return PCIBIOS_FUNC_NOT_SUPPORTED;
111 }
112
113 outl(data, PCI_REG(SH7751_PCIPDR));
114
115 return PCIBIOS_SUCCESSFUL;
116}
117
118#undef CONFIG_CMD
119
120struct pci_ops sh7751_pci_ops = {
121 .read = sh7751_pci_read,
122 .write = sh7751_pci_write,
123};
124
125static int __init pci_check_direct(void)
126{
127 unsigned int tmp, id;
128
129 /* check for SH7751/SH7751R hardware */
130 id = inl(SH7751_PCIREG_BASE+SH7751_PCICONF0);
131 if (id != ((SH7751_DEVICE_ID << 16) | SH7751_VENDOR_ID) &&
132 id != ((SH7751R_DEVICE_ID << 16) | SH7751_VENDOR_ID)) {
133 pr_debug("PCI: This is not an SH7751(R) (%x)\n", id);
134 return -ENODEV;
135 }
136
137 /*
138 * Check if configuration works.
139 */
140 if (pci_probe & PCI_PROBE_CONF1) {
141 tmp = inl (PCI_REG(SH7751_PCIPAR));
142 outl (0x80000000, PCI_REG(SH7751_PCIPAR));
143 if (inl (PCI_REG(SH7751_PCIPAR)) == 0x80000000) {
144 outl (tmp, PCI_REG(SH7751_PCIPAR));
145 printk(KERN_INFO "PCI: Using configuration type 1\n");
146 request_region(PCI_REG(SH7751_PCIPAR), 8, "PCI conf1");
147 return 0;
148 }
149 outl (tmp, PCI_REG(SH7751_PCIPAR));
150 }
151
152 pr_debug("PCI: pci_check_direct failed\n");
153 return -EINVAL;
154}
155
156/***************************************************************************************/
157
158/*
159 * Handle bus scanning and fixups ....
160 */
161
162static void __init pci_fixup_ide_bases(struct pci_dev *d)
163{
164 int i;
165
166 /*
167 * PCI IDE controllers use non-standard I/O port decoding, respect it.
168 */
169 if ((d->class >> 8) != PCI_CLASS_STORAGE_IDE)
170 return;
171 pr_debug("PCI: IDE base address fixup for %s\n", pci_name(d));
172 for(i=0; i<4; i++) {
173 struct resource *r = &d->resource[i];
174 if ((r->start & ~0x80) == 0x374) {
175 r->start |= 2;
176 r->end = r->start;
177 }
178 }
179}
180
181DECLARE_PCI_FIXUP_HEADER(PCI_ANY_ID, PCI_ANY_ID, pci_fixup_ide_bases);
182
183/*
184 * Called after each bus is probed, but before its children
185 * are examined.
186 */
187
188void __init pcibios_fixup_bus(struct pci_bus *b)
189{
190 pci_read_bridge_bases(b);
191}
192 26
193/* 27/*
194 * Initialization. Try all known PCI access methods. Note that we support 28 * Initialization. Try all known PCI access methods. Note that we support
@@ -196,25 +30,29 @@ void __init pcibios_fixup_bus(struct pci_bus *b)
196 * to access config space. 30 * to access config space.
197 * 31 *
198 * Note that the platform specific initialization (BSC registers, and memory 32 * Note that the platform specific initialization (BSC registers, and memory
199 * space mapping) will be called via the machine vectors (sh_mv.mv_pci_init()) if it 33 * space mapping) will be called via the platform defined function
200 * exitst and via the platform defined function pcibios_init_platform(). 34 * pcibios_init_platform().
201 * See pci_bigsur.c for implementation;
202 *
203 * The BIOS version of the pci functions is not yet implemented but it is left
204 * in for completeness. Currently an error will be genereated at compile time.
205 */ 35 */
206
207static int __init sh7751_pci_init(void) 36static int __init sh7751_pci_init(void)
208{ 37{
38 unsigned int id;
209 int ret; 39 int ret;
210 40
211 pr_debug("PCI: Starting intialization.\n"); 41 pr_debug("PCI: Starting intialization.\n");
212 if ((ret = pci_check_direct()) != 0) 42
43 /* check for SH7751/SH7751R hardware */
44 id = pci_read_reg(SH7751_PCICONF0);
45 if (id != ((SH7751_DEVICE_ID << 16) | SH7751_VENDOR_ID) &&
46 id != ((SH7751R_DEVICE_ID << 16) | SH7751_VENDOR_ID)) {
47 pr_debug("PCI: This is not an SH7751(R) (%x)\n", id);
48 return -ENODEV;
49 }
50
51 if ((ret = sh4_pci_check_direct()) != 0)
213 return ret; 52 return ret;
214 53
215 return pcibios_init_platform(); 54 return pcibios_init_platform();
216} 55}
217
218subsys_initcall(sh7751_pci_init); 56subsys_initcall(sh7751_pci_init);
219 57
220static int __init __area_sdram_check(unsigned int area) 58static int __init __area_sdram_check(unsigned int area)
@@ -228,7 +66,7 @@ static int __init __area_sdram_check(unsigned int area)
228 area, word); 66 area, word);
229 return 0; 67 return 0;
230 } 68 }
231 outl(word, PCI_REG(SH7751_PCIBCR1)); 69 pci_write_reg(word, SH4_PCIBCR1);
232 70
233 word = (u16)inw(SH7751_BCR2); 71 word = (u16)inw(SH7751_BCR2);
234 /* check BCR2 for 32bit SDRAM interface*/ 72 /* check BCR2 for 32bit SDRAM interface*/
@@ -237,12 +75,12 @@ static int __init __area_sdram_check(unsigned int area)
237 area, word); 75 area, word);
238 return 0; 76 return 0;
239 } 77 }
240 outl(word, PCI_REG(SH7751_PCIBCR2)); 78 pci_write_reg(word, SH4_PCIBCR2);
241 79
242 return 1; 80 return 1;
243} 81}
244 82
245int __init sh7751_pcic_init(struct sh7751_pci_address_map *map) 83int __init sh7751_pcic_init(struct sh4_pci_address_map *map)
246{ 84{
247 u32 reg; 85 u32 reg;
248 u32 word; 86 u32 word;
@@ -251,39 +89,39 @@ int __init sh7751_pcic_init(struct sh7751_pci_address_map *map)
251 reg = inl(SH7751_BCR1); 89 reg = inl(SH7751_BCR1);
252 reg |= 0x80000; 90 reg |= 0x80000;
253 outl(reg, SH7751_BCR1); 91 outl(reg, SH7751_BCR1);
254 92
255 /* Turn the clocks back on (not done in reset)*/ 93 /* Turn the clocks back on (not done in reset)*/
256 outl(0, PCI_REG(SH7751_PCICLKR)); 94 pci_write_reg(0, SH4_PCICLKR);
257 /* Clear Powerdown IRQ's (not done in reset) */ 95 /* Clear Powerdown IRQ's (not done in reset) */
258 word = SH7751_PCIPINT_D3 | SH7751_PCIPINT_D0; 96 word = SH4_PCIPINT_D3 | SH4_PCIPINT_D0;
259 outl(word, PCI_REG(SH7751_PCIPINT)); 97 pci_write_reg(word, SH4_PCIPINT);
260 98
261 /* 99 /*
262 * This code is unused for some boards as it is done in the 100 * This code is unused for some boards as it is done in the
263 * bootloader and doing it here means the MAC addresses loaded 101 * bootloader and doing it here means the MAC addresses loaded
264 * by the bootloader get lost. 102 * by the bootloader get lost.
265 */ 103 */
266 if (!(map->flags & SH7751_PCIC_NO_RESET)) { 104 if (!(map->flags & SH4_PCIC_NO_RESET)) {
267 /* toggle PCI reset pin */ 105 /* toggle PCI reset pin */
268 word = SH7751_PCICR_PREFIX | SH7751_PCICR_PRST; 106 word = SH4_PCICR_PREFIX | SH4_PCICR_PRST;
269 outl(word,PCI_REG(SH7751_PCICR)); 107 pci_write_reg(word, SH4_PCICR);
270 /* Wait for a long time... not 1 sec. but long enough */ 108 /* Wait for a long time... not 1 sec. but long enough */
271 mdelay(100); 109 mdelay(100);
272 word = SH7751_PCICR_PREFIX; 110 word = SH4_PCICR_PREFIX;
273 outl(word,PCI_REG(SH7751_PCICR)); 111 pci_write_reg(word, SH4_PCICR);
274 } 112 }
275 113
276 /* set the command/status bits to: 114 /* set the command/status bits to:
277 * Wait Cycle Control + Parity Enable + Bus Master + 115 * Wait Cycle Control + Parity Enable + Bus Master +
278 * Mem space enable 116 * Mem space enable
279 */ 117 */
280 word = SH7751_PCICONF1_WCC | SH7751_PCICONF1_PER | 118 word = SH7751_PCICONF1_WCC | SH7751_PCICONF1_PER |
281 SH7751_PCICONF1_BUM | SH7751_PCICONF1_MES; 119 SH7751_PCICONF1_BUM | SH7751_PCICONF1_MES;
282 outl(word, PCI_REG(SH7751_PCICONF1)); 120 pci_write_reg(word, SH7751_PCICONF1);
283 121
284 /* define this host as the host bridge */ 122 /* define this host as the host bridge */
285 word = SH7751_PCI_HOST_BRIDGE << 24; 123 word = PCI_BASE_CLASS_BRIDGE << 24;
286 outl(word, PCI_REG(SH7751_PCICONF2)); 124 pci_write_reg(word, SH7751_PCICONF2);
287 125
288 /* Set IO and Mem windows to local address 126 /* Set IO and Mem windows to local address
289 * Make PCI and local address the same for easy 1 to 1 mapping 127 * Make PCI and local address the same for easy 1 to 1 mapping
@@ -291,46 +129,49 @@ int __init sh7751_pcic_init(struct sh7751_pci_address_map *map)
291 * Window1 = map->window1.size @ cached area base = SDRAM 129 * Window1 = map->window1.size @ cached area base = SDRAM
292 */ 130 */
293 word = map->window0.size - 1; 131 word = map->window0.size - 1;
294 outl(word, PCI_REG(SH7751_PCILSR0)); 132 pci_write_reg(word, SH4_PCILSR0);
295 word = map->window1.size - 1; 133 word = map->window1.size - 1;
296 outl(word, PCI_REG(SH7751_PCILSR1)); 134 pci_write_reg(word, SH4_PCILSR1);
297 /* Set the values on window 0 PCI config registers */ 135 /* Set the values on window 0 PCI config registers */
298 word = P2SEGADDR(map->window0.base); 136 word = P2SEGADDR(map->window0.base);
299 outl(word, PCI_REG(SH7751_PCILAR0)); 137 pci_write_reg(word, SH4_PCILAR0);
300 outl(word, PCI_REG(SH7751_PCICONF5)); 138 pci_write_reg(word, SH7751_PCICONF5);
301 /* Set the values on window 1 PCI config registers */ 139 /* Set the values on window 1 PCI config registers */
302 word = PHYSADDR(map->window1.base); 140 word = PHYSADDR(map->window1.base);
303 outl(word, PCI_REG(SH7751_PCILAR1)); 141 pci_write_reg(word, SH4_PCILAR1);
304 outl(word, PCI_REG(SH7751_PCICONF6)); 142 pci_write_reg(word, SH7751_PCICONF6);
305 143
306 /* Set the local 16MB PCI memory space window to 144 /* Set the local 16MB PCI memory space window to
307 * the lowest PCI mapped address 145 * the lowest PCI mapped address
308 */ 146 */
309 word = PCIBIOS_MIN_MEM & SH7751_PCIMBR_MASK; 147 word = PCIBIOS_MIN_MEM & SH4_PCIMBR_MASK;
310 PCIDBG(2,"PCI: Setting upper bits of Memory window to 0x%x\n", word); 148 pr_debug("PCI: Setting upper bits of Memory window to 0x%x\n", word);
311 outl(word , PCI_REG(SH7751_PCIMBR)); 149 pci_write_reg(word , SH4_PCIMBR);
312 150
313 /* Map IO space into PCI IO window 151 /* Map IO space into PCI IO window
314 * The IO window is 64K-PCIBIOS_MIN_IO in size 152 * The IO window is 64K-PCIBIOS_MIN_IO in size
315 * IO addresses will be translated to the 153 * IO addresses will be translated to the
316 * PCI IO window base address 154 * PCI IO window base address
317 */ 155 */
318 PCIDBG(3,"PCI: Mapping IO address 0x%x - 0x%x to base 0x%x\n", PCIBIOS_MIN_IO, 156 pr_debug("PCI: Mapping IO address 0x%x - 0x%x to base 0x%x\n",
319 (64*1024), SH7751_PCI_IO_BASE+PCIBIOS_MIN_IO); 157 PCIBIOS_MIN_IO, (64 << 10),
158 SH4_PCI_IO_BASE + PCIBIOS_MIN_IO);
320 159
321 /* 160 /*
322 * XXX: For now, leave this board-specific. In the event we have other 161 * XXX: For now, leave this board-specific. In the event we have other
323 * boards that need to do similar work, this can be wrapped. 162 * boards that need to do similar work, this can be wrapped.
324 */ 163 */
325#ifdef CONFIG_SH_BIGSUR 164#ifdef CONFIG_SH_BIGSUR
326 bigsur_port_map(PCIBIOS_MIN_IO, (64*1024), SH7751_PCI_IO_BASE+PCIBIOS_MIN_IO,0); 165 bigsur_port_map(PCIBIOS_MIN_IO, (64 << 10),
166 SH4_PCI_IO_BASE + PCIBIOS_MIN_IO, 0);
327#endif 167#endif
328 168
329 /* Make sure the MSB's of IO window are set to access PCI space correctly */ 169 /* Make sure the MSB's of IO window are set to access PCI space
330 word = PCIBIOS_MIN_IO & SH7751_PCIIOBR_MASK; 170 * correctly */
331 PCIDBG(2,"PCI: Setting upper bits of IO window to 0x%x\n", word); 171 word = PCIBIOS_MIN_IO & SH4_PCIIOBR_MASK;
332 outl(word, PCI_REG(SH7751_PCIIOBR)); 172 pr_debug("PCI: Setting upper bits of IO window to 0x%x\n", word);
333 173 pci_write_reg(word, SH4_PCIIOBR);
174
334 /* Set PCI WCRx, BCRx's, copy from BSC locations */ 175 /* Set PCI WCRx, BCRx's, copy from BSC locations */
335 176
336 /* check BCR for SDRAM in specified area */ 177 /* check BCR for SDRAM in specified area */
@@ -349,13 +190,13 @@ int __init sh7751_pcic_init(struct sh7751_pci_address_map *map)
349 190
350 /* configure the wait control registers */ 191 /* configure the wait control registers */
351 word = inl(SH7751_WCR1); 192 word = inl(SH7751_WCR1);
352 outl(word, PCI_REG(SH7751_PCIWCR1)); 193 pci_write_reg(word, SH4_PCIWCR1);
353 word = inl(SH7751_WCR2); 194 word = inl(SH7751_WCR2);
354 outl(word, PCI_REG(SH7751_PCIWCR2)); 195 pci_write_reg(word, SH4_PCIWCR2);
355 word = inl(SH7751_WCR3); 196 word = inl(SH7751_WCR3);
356 outl(word, PCI_REG(SH7751_PCIWCR3)); 197 pci_write_reg(word, SH4_PCIWCR3);
357 word = inl(SH7751_MCR); 198 word = inl(SH7751_MCR);
358 outl(word, PCI_REG(SH7751_PCIMCR)); 199 pci_write_reg(word, SH4_PCIMCR);
359 200
360 /* NOTE: I'm ignoring the PCI error IRQs for now.. 201 /* NOTE: I'm ignoring the PCI error IRQs for now..
361 * TODO: add support for the internal error interrupts and 202 * TODO: add support for the internal error interrupts and
@@ -368,49 +209,8 @@ int __init sh7751_pcic_init(struct sh7751_pci_address_map *map)
368 209
369 /* SH7751 init done, set central function init complete */ 210 /* SH7751 init done, set central function init complete */
370 /* use round robin mode to stop a device starving/overruning */ 211 /* use round robin mode to stop a device starving/overruning */
371 word = SH7751_PCICR_PREFIX | SH7751_PCICR_CFIN | SH7751_PCICR_ARBM; 212 word = SH4_PCICR_PREFIX | SH4_PCICR_CFIN | SH4_PCICR_ARBM;
372 outl(word,PCI_REG(SH7751_PCICR)); 213 pci_write_reg(word, SH4_PCICR);
373 214
374 return 1; 215 return 1;
375} 216}
376
377char * __init pcibios_setup(char *str)
378{
379 if (!strcmp(str, "off")) {
380 pci_probe = 0;
381 return NULL;
382 }
383
384 return str;
385}
386
387/*
388 * IRQ functions
389 */
390static u8 __init sh7751_no_swizzle(struct pci_dev *dev, u8 *pin)
391{
392 /* no swizzling */
393 return PCI_SLOT(dev->devfn);
394}
395
396static int sh7751_pci_lookup_irq(struct pci_dev *dev, u8 slot, u8 pin)
397{
398 int irq = -1;
399
400 /* now lookup the actual IRQ on a platform specific basis (pci-'platform'.c) */
401 irq = pcibios_map_platform_irq(slot,pin);
402 if( irq < 0 ) {
403 pr_debug("PCI: Error mapping IRQ on device %s\n", pci_name(dev));
404 return irq;
405 }
406
407 pr_debug("Setting IRQ for slot %s to %d\n", pci_name(dev), irq);
408
409 return irq;
410}
411
412void __init pcibios_fixup_irqs(void)
413{
414 pci_fixup_irqs(sh7751_no_swizzle, sh7751_pci_lookup_irq);
415}
416