2 * arch/mips/ddb5074/pci.c -- NEC DDB Vrc-5074 PCI access routines
4 * Copyright (C) 2000 Geert Uytterhoeven <geert@sonycom.com>
5 * Albert Dorofeev <albert@sonycom.com>
6 * Sony Suprastructure Center Europe (SUPC-E), Brussels
8 * $Id: pci.c,v 1.4 2000/02/18 00:02:17 ralf Exp $
11 #include <linux/init.h>
12 #include <linux/kernel.h>
13 #include <linux/pci.h>
14 #include <linux/types.h>
15 #include <linux/sched.h>
16 #include <linux/ioport.h>
17 #include <asm-mips/nile4.h>
20 static u32
nile4_pre_pci_access0(int slot_num
)
23 u32 virt_addr
= NILE4_PCI_CFG_BASE
;
25 /* Set window 1 address 8000000 - 64 bit - 2 MB (PCI config space) */
26 nile4_set_pdar(NILE4_PCIW1
, PHYSADDR(virt_addr
), 0x00200000, 64, 0, 0);
28 pci_addr
= 0x00040000 << slot_num
;
30 virt_addr
+= 0x00040000 << slot_num
;
31 nile4_set_pmr(NILE4_PCIINIT1
, NILE4_PCICMD_CFG
, pci_addr
);
35 static void nile4_post_pci_access0(void)
37 /* Set window 1 back to address 8000000 - 64 bit - 128 MB (PCI IO space) */
38 nile4_set_pdar(NILE4_PCIW1
, PHYSADDR(NILE4_PCI_MEM_BASE
), 0x08000000, 64,
40 nile4_set_pmr(NILE4_PCIINIT1
, NILE4_PCICMD_MEM
, 0);
44 static int nile4_pci_read_config_dword( struct pci_dev
*dev
,
47 int slot_num
, func_num
;
51 * For starters let's do configuration cycle 0 only (one bus only)
54 return PCIBIOS_FUNC_NOT_SUPPORTED
;
56 slot_num
= PCI_SLOT(dev
->devfn
);
57 func_num
= PCI_FUNC(dev
->devfn
);
60 * This is Nile 4 and it will crash if we access it like other
63 *val
= nile4_in32(NILE4_PCI_BASE
+ where
);
64 return PCIBIOS_SUCCESSFUL
;
66 base
= nile4_pre_pci_access0(slot_num
);
67 *val
= *((volatile u32
*)(base
+ (func_num
<< 8) + (where
& 0xfc)));
68 nile4_post_pci_access0();
69 return PCIBIOS_SUCCESSFUL
;
72 static int nile4_pci_write_config_dword(struct pci_dev
*dev
, int where
,
75 int slot_num
, func_num
;
79 * For starters let's do configuration cycle 0 only (one bus only)
82 return PCIBIOS_FUNC_NOT_SUPPORTED
;
84 slot_num
= PCI_SLOT(dev
->devfn
);
85 func_num
= PCI_FUNC(dev
->devfn
);
88 * This is Nile 4 and it will crash if we access it like other
91 nile4_out32(NILE4_PCI_BASE
+ where
, val
);
92 return PCIBIOS_SUCCESSFUL
;
94 base
= nile4_pre_pci_access0(slot_num
);
95 *((volatile u32
*)(base
+ (func_num
<< 8) + (where
& 0xfc))) = val
;
96 nile4_post_pci_access0();
97 return PCIBIOS_SUCCESSFUL
;
100 static int nile4_pci_read_config_word(struct pci_dev
*dev
, int where
, u16
*val
)
105 status
= nile4_pci_read_config_dword(dev
, where
, &result
);
106 if (status
!= PCIBIOS_SUCCESSFUL
)
110 *val
= result
& 0xffff;
111 return PCIBIOS_SUCCESSFUL
;
114 static int nile4_pci_read_config_byte(struct pci_dev
*dev
, int where
, u8
*val
)
119 status
= nile4_pci_read_config_dword(dev
, where
, &result
);
120 if (status
!= PCIBIOS_SUCCESSFUL
)
126 *val
= result
& 0xff;
127 return PCIBIOS_SUCCESSFUL
;
130 static int nile4_pci_write_config_word(struct pci_dev
*dev
, int where
, u16 val
)
132 int status
, shift
= 0;
135 status
= nile4_pci_read_config_dword(dev
, where
, &result
);
136 if (status
!= PCIBIOS_SUCCESSFUL
)
140 result
&= ~(0xffff << shift
);
141 result
|= val
<< shift
;
142 return nile4_pci_write_config_dword(dev
, where
, result
);
145 static int nile4_pci_write_config_byte( struct pci_dev
*dev
, int where
, u8 val
)
147 int status
, shift
= 0;
150 status
= nile4_pci_read_config_dword(dev
, where
, &result
);
151 if (status
!= PCIBIOS_SUCCESSFUL
)
157 result
&= ~(0xff << shift
);
158 result
|= val
<< shift
;
159 return nile4_pci_write_config_dword(dev
, where
, result
);
162 struct pci_ops nile4_pci_ops
= {
163 nile4_pci_read_config_byte
,
164 nile4_pci_read_config_word
,
165 nile4_pci_read_config_dword
,
166 nile4_pci_write_config_byte
,
167 nile4_pci_write_config_word
,
168 nile4_pci_write_config_dword
172 static void __init
pcibios_claim_resources(struct list_head
*bus_list
)
174 struct list_head
*ln
, *dn
;
179 for (ln
= bus_list
->next
; ln
!= bus_list
; ln
= ln
->next
) {
181 for (dn
= bus
->devices
.next
; dn
!= &bus
->devices
; dn
= dn
->next
) {
183 for (idx
= 0; idx
< PCI_NUM_RESOURCES
; idx
++) {
184 struct resource
*r
= &dev
->resource
[idx
];
188 pr
= pci_find_parent_resource(dev
, r
);
189 if (!pr
|| request_resource(pr
, r
) < 0) {
190 printk(KERN_ERR
"PCI: Address space collision on region %d of device %s\n", idx
, dev
->name
);
191 /* We probably should disable the region, shouldn't we? */
195 pcibios_claim_resources(&bus
->children
);
200 void pcibios_init(void)
202 printk("PCI: Probing PCI hardware\n");
203 ioport_resource
.end
= 0x1ffffff;
204 pci_scan_bus(0, &nile4_pci_ops
, NULL
);
205 pcibios_claim_resources(&pci_root_buses
);
208 void pcibios_fixup_bus(struct pci_bus
*bus
)
210 struct list_head
*dn
;
212 extern struct pci_dev
*pci_pmu
; /* for LEDs D2 and D3 */
213 int slot_num
, func_num
;
217 * FIXME: PMON doesn't autoconfigure the PCI devices
218 * For now we just hardcode them for our configuration
220 printk("PCI: Configuring PCI devices (hardcoded)\n");
221 for (dn
= bus
->devices
.next
; dn
!= &bus
->devices
; dn
= dn
->next
) {
224 slot_num
= PCI_SLOT(dev
->devfn
);
225 func_num
= PCI_FUNC(dev
->devfn
);
226 printk(" Device %2d: ", slot_num
);
229 printk("[onboard] Acer Labs M1533 Aladdin IV\n");
230 dev
->irq
= nile4_to_irq(NILE4_INT_INTE
);
233 printk("[onboard] DEC DC21140\n");
234 dev
->irq
= nile4_to_irq(NILE4_INT_INTA
);
235 dev
->resource
[0].start
= 0x100000;
236 dev
->resource
[0].end
= dev
->resource
[0].start
+0x7f;
237 nile4_pci_write_config_dword(dev
, PCI_BASE_ADDRESS_0
,
238 dev
->resource
[0].start
);
239 dev
->resource
[1].start
= 0x1000000;
240 dev
->resource
[1].end
= dev
->resource
[1].start
+0x7f;
241 nile4_pci_write_config_dword(dev
, PCI_BASE_ADDRESS_0
,
242 dev
->resource
[1].start
);
245 printk("[slot 1] Realtek 8029\n");
246 dev
->irq
= nile4_to_irq(NILE4_INT_INTA
);
247 dev
->resource
[0].start
= 0x800000;
248 dev
->resource
[0].end
= dev
->resource
[0].start
+0x1f;
249 nile4_pci_write_config_dword(dev
, PCI_BASE_ADDRESS_0
,
250 dev
->resource
[0].start
);
253 printk("[slot 2] DEC DC21140 (#2)\n");
254 dev
->irq
= nile4_to_irq(NILE4_INT_INTB
);
255 dev
->resource
[0].start
= 0x1000000;
256 dev
->resource
[0].end
= dev
->resource
[0].start
+0x7f;
257 nile4_pci_write_config_dword(dev
, PCI_BASE_ADDRESS_0
,
258 dev
->resource
[0].start
);
259 dev
->resource
[1].start
= 0x4000000;
260 dev
->resource
[1].end
= dev
->resource
[1].start
+0x7f;
261 nile4_pci_write_config_dword(dev
, PCI_BASE_ADDRESS_0
,
262 dev
->resource
[1].start
);
265 printk("[slot 3] Promise Technology IDE UltraDMA/33");
266 printk(" or 3Com 3c905 :-)\n");
267 dev
->irq
= nile4_to_irq(NILE4_INT_INTC
);
268 dev
->resource
[0].start
= 0x1800000;
269 dev
->resource
[0].end
= dev
->resource
[0].start
+0x7fffff;
270 nile4_pci_write_config_dword(dev
, PCI_BASE_ADDRESS_0
,
271 dev
->resource
[0].start
);
274 printk("[onboard] NEC Vrc-5074 Nile 4 Host Bridge\n");
276 * Fixup so the serial driver can use the UART
278 dev
->irq
= nile4_to_irq(NILE4_INT_UART
);
279 dev
->resource
[0].start
= PHYSADDR(NILE4_BASE
);
280 dev
->resource
[0].end
= dev
->resource
[0].start
+NILE4_SIZE
-1;
281 dev
->resource
[0].flags
= IORESOURCE_MEM
|
282 PCI_BASE_ADDRESS_MEM_TYPE_64
;
286 printk("[onboard] Acer Labs M7101 PMU\n");
288 /* Program the lines for LEDs D2 and D3 to output */
289 nile4_pci_read_config_byte(dev
, 0x7d, &t8
);
291 nile4_pci_write_config_byte(dev
, 0x7d, t8
);
292 /* Turn LEDs D2 and D3 off */
293 nile4_pci_read_config_byte(dev
, 0x7e, &t8
);
295 nile4_pci_write_config_byte(dev
, 0x7e, t8
);
298 printk("[onboard] Acer Labs M5237 USB\n");
299 dev
->irq
= nile4_to_irq(NILE4_INT_INTE
);
300 dev
->resource
[0].start
= 0x1001000;
301 dev
->resource
[0].end
= dev
->resource
[0].start
+0xfff;
302 nile4_pci_write_config_dword(dev
, PCI_BASE_ADDRESS_0
,
303 dev
->resource
[0].start
);
312 char *pcibios_setup (char *str
)
317 void __init
pcibios_update_resource(struct pci_dev
*dev
, struct resource
*root
,
318 struct resource
*res
, int resource
)
320 unsigned long where
, size
;
323 where
= PCI_BASE_ADDRESS_0
+ (resource
* 4);
324 size
= res
->end
- res
->start
;
325 pci_read_config_dword(dev
, where
, ®
);
326 reg
= (reg
& size
) | (((u32
)(res
->start
- root
->start
)) & ~size
);
327 pci_write_config_dword(dev
, where
, reg
);
330 void __init
pcibios_update_irq(struct pci_dev
*dev
, int irq
)
332 pci_write_config_byte(dev
, PCI_INTERRUPT_LINE
, irq
);
335 void __init
pcibios_fixup_pbus_ranges(struct pci_bus
*bus
,
336 struct pbus_set_ranges_data
*ranges
)
338 ranges
->io_start
-= bus
->resource
[0]->start
;
339 ranges
->io_end
-= bus
->resource
[0]->start
;
340 ranges
->mem_start
-= bus
->resource
[1]->start
;
341 ranges
->mem_end
-= bus
->resource
[1]->start
;
344 int __init
pcibios_enable_device(struct pci_dev
*dev
)
346 printk("pcibios_enable_device for %04x:%04x\n", dev
->vendor
, dev
->device
);
347 panic("pcibios_enable_device: not yet implemented\n");
350 void __init
pcibios_align_resource(void *data
, struct resource
*res
,
354 struct pci_fixup pcibios_fixups
[] = {};