2 * Low-Level PCI and SB support for BCM47xx (Linux support code)
4 * Copyright 2006, Broadcom Corporation
7 * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
8 * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
9 * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
10 * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
12 * $Id: pcibios.c,v 1.1.1.9 2006/02/27 03:42:55 honor Exp $
15 #include <linux/config.h>
16 #include <linux/types.h>
17 #include <linux/kernel.h>
18 #include <linux/sched.h>
19 #include <linux/pci.h>
20 #include <linux/init.h>
21 #include <linux/delay.h>
24 #include <asm/paccess.h>
36 /* Global SB handle */
37 extern sb_t
*bcm947xx_sbh
;
38 extern spinlock_t bcm947xx_sbh_lock
;
41 #define sbh bcm947xx_sbh
42 #define sbh_lock bcm947xx_sbh_lock
45 sbpci_read_config_byte(struct pci_dev
*dev
, int where
, u8
*value
)
50 spin_lock_irqsave(&sbh_lock
, flags
);
51 ret
= sbpci_read_config(sbh
, dev
->bus
->number
, PCI_SLOT(dev
->devfn
),
52 PCI_FUNC(dev
->devfn
), where
, value
, sizeof(*value
));
53 spin_unlock_irqrestore(&sbh_lock
, flags
);
54 return ret
? PCIBIOS_DEVICE_NOT_FOUND
: PCIBIOS_SUCCESSFUL
;
58 sbpci_read_config_word(struct pci_dev
*dev
, int where
, u16
*value
)
63 spin_lock_irqsave(&sbh_lock
, flags
);
64 ret
= sbpci_read_config(sbh
, dev
->bus
->number
, PCI_SLOT(dev
->devfn
),
65 PCI_FUNC(dev
->devfn
), where
, value
, sizeof(*value
));
66 spin_unlock_irqrestore(&sbh_lock
, flags
);
67 return ret
? PCIBIOS_DEVICE_NOT_FOUND
: PCIBIOS_SUCCESSFUL
;
71 sbpci_read_config_dword(struct pci_dev
*dev
, int where
, u32
*value
)
76 spin_lock_irqsave(&sbh_lock
, flags
);
77 ret
= sbpci_read_config(sbh
, dev
->bus
->number
, PCI_SLOT(dev
->devfn
),
78 PCI_FUNC(dev
->devfn
), where
, value
, sizeof(*value
));
79 spin_unlock_irqrestore(&sbh_lock
, flags
);
80 return ret
? PCIBIOS_DEVICE_NOT_FOUND
: PCIBIOS_SUCCESSFUL
;
84 sbpci_write_config_byte(struct pci_dev
*dev
, int where
, u8 value
)
89 spin_lock_irqsave(&sbh_lock
, flags
);
90 ret
= sbpci_write_config(sbh
, dev
->bus
->number
, PCI_SLOT(dev
->devfn
),
91 PCI_FUNC(dev
->devfn
), where
, &value
, sizeof(value
));
92 spin_unlock_irqrestore(&sbh_lock
, flags
);
93 return ret
? PCIBIOS_DEVICE_NOT_FOUND
: PCIBIOS_SUCCESSFUL
;
97 sbpci_write_config_word(struct pci_dev
*dev
, int where
, u16 value
)
102 spin_lock_irqsave(&sbh_lock
, flags
);
103 ret
= sbpci_write_config(sbh
, dev
->bus
->number
, PCI_SLOT(dev
->devfn
),
104 PCI_FUNC(dev
->devfn
), where
, &value
, sizeof(value
));
105 spin_unlock_irqrestore(&sbh_lock
, flags
);
106 return ret
? PCIBIOS_DEVICE_NOT_FOUND
: PCIBIOS_SUCCESSFUL
;
110 sbpci_write_config_dword(struct pci_dev
*dev
, int where
, u32 value
)
115 spin_lock_irqsave(&sbh_lock
, flags
);
116 ret
= sbpci_write_config(sbh
, dev
->bus
->number
, PCI_SLOT(dev
->devfn
),
117 PCI_FUNC(dev
->devfn
), where
, &value
, sizeof(value
));
118 spin_unlock_irqrestore(&sbh_lock
, flags
);
119 return ret
? PCIBIOS_DEVICE_NOT_FOUND
: PCIBIOS_SUCCESSFUL
;
122 static struct pci_ops pcibios_ops
= {
123 sbpci_read_config_byte
,
124 sbpci_read_config_word
,
125 sbpci_read_config_dword
,
126 sbpci_write_config_byte
,
127 sbpci_write_config_word
,
128 sbpci_write_config_dword
137 if (!(sbh
= sb_kattach()))
138 panic("sb_kattach failed");
139 spin_lock_init(&sbh_lock
);
141 spin_lock_irqsave(&sbh_lock
, flags
);
143 spin_unlock_irqrestore(&sbh_lock
, flags
);
145 set_io_port_base((unsigned long) ioremap_nocache(SB_PCI_MEM
, 0x04000000));
147 /* Scan the SB bus */
148 pci_scan_bus(0, &pcibios_ops
, NULL
);
153 pcibios_setup(char *str
)
155 if (!strncmp(str
, "ban=", 4)) {
156 sbpci_ban(simple_strtoul(str
+ 4, NULL
, 0));
163 static u32 pci_iobase
= 0x100;
164 static u32 pci_membase
= SB_PCI_DMA
;
165 static u32 pcmcia_membase
= 0x40004000;
168 pcibios_fixup_bus(struct pci_bus
*b
)
170 struct list_head
*ln
;
172 struct resource
*res
;
177 printk("PCI: Fixing up bus %d\n", b
->number
);
180 if (b
->number
== 0) {
181 for (ln
= b
->devices
.next
; ln
!= &b
->devices
; ln
= ln
->next
) {
183 /* Fix up interrupt lines */
184 pci_read_config_byte(d
, PCI_INTERRUPT_LINE
, &irq
);
186 pci_write_config_byte(d
, PCI_INTERRUPT_LINE
, d
->irq
);
190 /* Fix up external PCI */
192 for (ln
= b
->devices
.next
; ln
!= &b
->devices
; ln
= ln
->next
) {
194 /* Fix up resource bases */
195 for (pos
= 0; pos
< 6; pos
++) {
196 res
= &d
->resource
[pos
];
197 base
= (res
->flags
& IORESOURCE_IO
) ? &pci_iobase
: ((b
->number
== 2) ? &pcmcia_membase
: &pci_membase
);
199 size
= res
->end
- res
->start
+ 1;
200 if (*base
& (size
- 1))
201 *base
= (*base
+ size
) & ~(size
- 1);
203 res
->end
= res
->start
+ size
- 1;
205 pci_write_config_dword(d
,
206 PCI_BASE_ADDRESS_0
+ (pos
<< 2), res
->start
);
208 /* Fix up PCI bridge BAR0 only */
209 if (b
->number
== 1 && PCI_SLOT(d
->devfn
) == 0)
212 /* Fix up interrupt lines */
213 if (pci_find_device(VENDOR_BROADCOM
, SB_PCI
, NULL
))
214 d
->irq
= (pci_find_device(VENDOR_BROADCOM
, SB_PCI
, NULL
))->irq
;
215 pci_write_config_byte(d
, PCI_INTERRUPT_LINE
, d
->irq
);
221 pcibios_assign_all_busses(void)
227 pcibios_align_resource(void *data
, struct resource
*res
,
228 unsigned long size
, unsigned long align
)
233 pcibios_enable_resources(struct pci_dev
*dev
)
239 /* External PCI only */
240 if (dev
->bus
->number
== 0)
243 pci_read_config_word(dev
, PCI_COMMAND
, &cmd
);
245 for (idx
= 0; idx
< 6; idx
++) {
246 r
= &dev
->resource
[idx
];
247 if (r
->flags
& IORESOURCE_IO
)
248 cmd
|= PCI_COMMAND_IO
;
249 if (r
->flags
& IORESOURCE_MEM
)
250 cmd
|= PCI_COMMAND_MEMORY
;
252 if (dev
->resource
[PCI_ROM_RESOURCE
].start
)
253 cmd
|= PCI_COMMAND_MEMORY
;
254 if (cmd
!= old_cmd
) {
255 printk("PCI: Enabling device %s (%04x -> %04x)\n", dev
->slot_name
, old_cmd
, cmd
);
256 pci_write_config_word(dev
, PCI_COMMAND
, cmd
);
262 pcibios_enable_device(struct pci_dev
*dev
, int mask
)
268 /* External PCI device enable */
269 if (dev
->bus
->number
!= 0)
270 return pcibios_enable_resources(dev
);
272 /* These cores come out of reset enabled */
273 if (dev
->device
== SB_MIPS
||
274 dev
->device
== SB_MIPS33
||
275 dev
->device
== SB_EXTIF
||
276 dev
->device
== SB_CC
)
279 spin_lock_irqsave(&sbh_lock
, flags
);
280 coreidx
= sb_coreidx(sbh
);
281 regs
= sb_setcoreidx(sbh
, PCI_SLOT(dev
->devfn
));
283 return PCIBIOS_DEVICE_NOT_FOUND
;
286 * The USB core requires a special bit to be set during core
287 * reset to enable host (OHCI) mode. Resetting the SB core in
288 * pcibios_enable_device() is a hack for compatibility with
289 * vanilla usb-ohci so that it does not have to know about
290 * SB. A driver that wants to use the USB core in device mode
291 * should know about SB and should reset the bit back to 0
292 * after calling pcibios_enable_device().
294 if (sb_coreid(sbh
) == SB_USB
) {
295 sb_core_disable(sbh
, sb_coreflags(sbh
, 0, 0));
296 sb_core_reset(sbh
, 1 << 29, 0);
299 * USB 2.0 special considerations:
301 * 1. Since the core supports both OHCI and EHCI functions, it must
302 * only be reset once.
304 * 2. In addition to the standard SB reset sequence, the Host Control
305 * Register must be programmed to bring the USB core and various
306 * phy components out of reset.
308 else if (sb_coreid(sbh
) == SB_USB20H
) {
309 if (!sb_iscoreup(sbh
)) {
310 sb_core_reset(sbh
, 0, 0);
311 writel(0x7FF, (ulong
)regs
+ 0x200);
315 sb_core_reset(sbh
, 0, 0);
317 sb_setcoreidx(sbh
, coreidx
);
318 spin_unlock_irqrestore(&sbh_lock
, flags
);
324 pcibios_update_resource(struct pci_dev
*dev
, struct resource
*root
,
325 struct resource
*res
, int resource
)
327 unsigned long where
, size
;
330 /* External PCI only */
331 if (dev
->bus
->number
== 0)
334 where
= PCI_BASE_ADDRESS_0
+ (resource
* 4);
335 size
= res
->end
- res
->start
;
336 pci_read_config_dword(dev
, where
, ®
);
338 if (dev
->bus
->number
== 1)
339 reg
= (reg
& size
) | (((u32
)(res
->start
- root
->start
)) & ~size
);
343 pci_write_config_dword(dev
, where
, reg
);
347 quirk_sbpci_bridge(struct pci_dev
*dev
)
349 if (dev
->bus
->number
!= 1 || PCI_SLOT(dev
->devfn
) != 0)
352 printk("PCI: Fixing up bridge\n");
354 /* Enable PCI bridge bus mastering and memory space */
356 pcibios_enable_resources(dev
);
358 /* Enable PCI bridge BAR1 prefetch and burst */
359 pci_write_config_dword(dev
, PCI_BAR1_CONTROL
, 3);
362 struct pci_fixup pcibios_fixups
[] = {
363 { PCI_FIXUP_HEADER
, PCI_ANY_ID
, PCI_ANY_ID
, quirk_sbpci_bridge
},
368 * If we set up a device for bus mastering, we need to check the latency
369 * timer as certain crappy BIOSes forget to set it properly.
371 unsigned int pcibios_max_latency
= 255;
373 void pcibios_set_master(struct pci_dev
*dev
)
376 pci_read_config_byte(dev
, PCI_LATENCY_TIMER
, &lat
);
378 lat
= (64 <= pcibios_max_latency
) ? 64 : pcibios_max_latency
;
379 else if (lat
> pcibios_max_latency
)
380 lat
= pcibios_max_latency
;
383 printk(KERN_DEBUG
"PCI: Setting latency timer of device %s to %d\n", dev
->slot_name
, lat
);
384 pci_write_config_byte(dev
, PCI_LATENCY_TIMER
, lat
);