2 * Sonics Silicon Backplane
5 * Copyright (C) 2005-2007 Michael Buesch <mb@bu3sch.de>
6 * Copyright (C) 2005 Martin Langer <martin-langer@gmx.de>
7 * Copyright (C) 2005 Stefano Brivio <st3@riseup.net>
8 * Copyright (C) 2005 Danny van Dyk <kugelfang@gentoo.org>
9 * Copyright (C) 2005 Andreas Jaggi <andreas.jaggi@waterwave.ch>
10 * Copyright (C) 2006 Broadcom Corporation.
12 * Licensed under the GNU/GPL. See COPYING for details.
15 #include <linux/ssb/ssb.h>
16 #include <linux/ssb/ssb_regs.h>
17 #include <linux/pci.h>
20 #include <pcmcia/cistpl.h>
21 #include <pcmcia/ds.h>
23 #include "ssb_private.h"
26 const char *ssb_core_name(u16 coreid
)
29 case SSB_DEV_CHIPCOMMON
:
39 case SSB_DEV_ETHERNET
:
40 return "Fast Ethernet";
43 case SSB_DEV_USB11_HOSTDEV
:
44 return "USB 1.1 Hostdev";
47 case SSB_DEV_ILINE100
:
53 case SSB_DEV_INTERNAL_MEM
:
54 return "Internal Memory";
55 case SSB_DEV_MEMC_SDRAM
:
61 case SSB_DEV_MIPS_3302
:
63 case SSB_DEV_USB11_HOST
:
64 return "USB 1.1 Host";
65 case SSB_DEV_USB11_DEV
:
66 return "USB 1.1 Device";
67 case SSB_DEV_USB20_HOST
:
68 return "USB 2.0 Host";
69 case SSB_DEV_USB20_DEV
:
70 return "USB 2.0 Device";
71 case SSB_DEV_SDIO_HOST
:
73 case SSB_DEV_ROBOSWITCH
:
75 case SSB_DEV_PARA_ATA
:
77 case SSB_DEV_SATA_XORDMA
:
78 return "SATA XOR-DMA";
79 case SSB_DEV_ETHERNET_GBIT
:
80 return "GBit Ethernet";
83 case SSB_DEV_MIMO_PHY
:
85 case SSB_DEV_SRAM_CTRLR
:
86 return "SRAM Controller";
87 case SSB_DEV_MINI_MACPHY
:
89 case SSB_DEV_ARM_1176
:
91 case SSB_DEV_ARM_7TDMI
:
97 static u16
pcidev_to_chipid(struct pci_dev
*pci_dev
)
99 u16 chipid_fallback
= 0;
101 switch (pci_dev
->device
) {
103 chipid_fallback
= 0x4301;
105 case 0x4305 ... 0x4307:
106 chipid_fallback
= 0x4307;
109 chipid_fallback
= 0x4402;
111 case 0x4610 ... 0x4615:
112 chipid_fallback
= 0x4610;
114 case 0x4710 ... 0x4715:
115 chipid_fallback
= 0x4710;
117 case 0x4320 ... 0x4325:
118 chipid_fallback
= 0x4309;
120 case PCI_DEVICE_ID_BCM4401
:
121 case PCI_DEVICE_ID_BCM4401B0
:
122 case PCI_DEVICE_ID_BCM4401B1
:
123 chipid_fallback
= 0x4401;
126 ssb_printk(KERN_ERR PFX
127 "PCI-ID not in fallback list\n");
130 return chipid_fallback
;
133 static u8
chipid_to_nrcores(u16 chipid
)
153 ssb_printk(KERN_ERR PFX
154 "CHIPID not in nrcores fallback list\n");
160 static u32
scan_read32(struct ssb_bus
*bus
, u8 current_coreidx
,
165 switch (bus
->bustype
) {
166 case SSB_BUSTYPE_SSB
:
167 offset
+= current_coreidx
* SSB_CORE_SIZE
;
169 case SSB_BUSTYPE_PCI
:
171 case SSB_BUSTYPE_PCMCIA
:
172 if (offset
>= 0x800) {
173 ssb_pcmcia_switch_segment(bus
, 1);
176 ssb_pcmcia_switch_segment(bus
, 0);
177 lo
= readw(bus
->mmio
+ offset
);
178 hi
= readw(bus
->mmio
+ offset
+ 2);
179 return lo
| (hi
<< 16);
180 case SSB_BUSTYPE_SDIO
:
181 offset
+= current_coreidx
* SSB_CORE_SIZE
;
182 return ssb_sdio_scan_read32(bus
, offset
);
184 return readl(bus
->mmio
+ offset
);
187 static int scan_switchcore(struct ssb_bus
*bus
, u8 coreidx
)
189 switch (bus
->bustype
) {
190 case SSB_BUSTYPE_SSB
:
192 case SSB_BUSTYPE_PCI
:
193 return ssb_pci_switch_coreidx(bus
, coreidx
);
194 case SSB_BUSTYPE_PCMCIA
:
195 return ssb_pcmcia_switch_coreidx(bus
, coreidx
);
196 case SSB_BUSTYPE_SDIO
:
197 return ssb_sdio_scan_switch_coreidx(bus
, coreidx
);
202 void ssb_iounmap(struct ssb_bus
*bus
)
204 switch (bus
->bustype
) {
205 case SSB_BUSTYPE_SSB
:
206 case SSB_BUSTYPE_PCMCIA
:
209 case SSB_BUSTYPE_PCI
:
210 #ifdef CONFIG_SSB_PCIHOST
211 pci_iounmap(bus
->host_pci
, bus
->mmio
);
213 SSB_BUG_ON(1); /* Can't reach this code. */
216 case SSB_BUSTYPE_SDIO
:
220 bus
->mapped_device
= NULL
;
223 static void __iomem
*ssb_ioremap(struct ssb_bus
*bus
,
224 unsigned long baseaddr
)
226 void __iomem
*mmio
= NULL
;
228 switch (bus
->bustype
) {
229 case SSB_BUSTYPE_SSB
:
230 /* Only map the first core for now. */
232 case SSB_BUSTYPE_PCMCIA
:
233 mmio
= ioremap(baseaddr
, SSB_CORE_SIZE
);
235 case SSB_BUSTYPE_PCI
:
236 #ifdef CONFIG_SSB_PCIHOST
237 mmio
= pci_iomap(bus
->host_pci
, 0, ~0UL);
239 SSB_BUG_ON(1); /* Can't reach this code. */
242 case SSB_BUSTYPE_SDIO
:
243 /* Nothing to ioremap in the SDIO case, just fake it */
244 mmio
= (void __iomem
*)baseaddr
;
251 static int we_support_multiple_80211_cores(struct ssb_bus
*bus
)
253 /* More than one 802.11 core is only supported by special chips.
254 * There are chips with two 802.11 cores, but with dangling
255 * pins on the second core. Be careful and reject them here.
258 #ifdef CONFIG_SSB_PCIHOST
259 if (bus
->bustype
== SSB_BUSTYPE_PCI
) {
260 if (bus
->host_pci
->vendor
== PCI_VENDOR_ID_BROADCOM
&&
261 bus
->host_pci
->device
== 0x4324)
264 #endif /* CONFIG_SSB_PCIHOST */
268 int ssb_bus_scan(struct ssb_bus
*bus
,
269 unsigned long baseaddr
)
273 u32 idhi
, cc
, rev
, tmp
;
275 struct ssb_device
*dev
;
276 int nr_80211_cores
= 0;
278 mmio
= ssb_ioremap(bus
, baseaddr
);
283 err
= scan_switchcore(bus
, 0); /* Switch to first core */
287 idhi
= scan_read32(bus
, 0, SSB_IDHIGH
);
288 cc
= (idhi
& SSB_IDHIGH_CC
) >> SSB_IDHIGH_CC_SHIFT
;
289 rev
= (idhi
& SSB_IDHIGH_RCLO
);
290 rev
|= (idhi
& SSB_IDHIGH_RCHI
) >> SSB_IDHIGH_RCHI_SHIFT
;
293 if (cc
== SSB_DEV_CHIPCOMMON
) {
294 tmp
= scan_read32(bus
, 0, SSB_CHIPCO_CHIPID
);
296 bus
->chip_id
= (tmp
& SSB_CHIPCO_IDMASK
);
297 bus
->chip_rev
= (tmp
& SSB_CHIPCO_REVMASK
) >>
299 bus
->chip_package
= (tmp
& SSB_CHIPCO_PACKMASK
) >>
300 SSB_CHIPCO_PACKSHIFT
;
302 bus
->nr_devices
= (tmp
& SSB_CHIPCO_NRCORESMASK
) >>
303 SSB_CHIPCO_NRCORESSHIFT
;
305 tmp
= scan_read32(bus
, 0, SSB_CHIPCO_CAP
);
306 bus
->chipco
.capabilities
= tmp
;
308 if (bus
->bustype
== SSB_BUSTYPE_PCI
) {
309 bus
->chip_id
= pcidev_to_chipid(bus
->host_pci
);
310 pci_read_config_byte(bus
->host_pci
, PCI_REVISION_ID
,
312 bus
->chip_package
= 0;
314 bus
->chip_id
= 0x4710;
316 bus
->chip_package
= 0;
319 if (!bus
->nr_devices
)
320 bus
->nr_devices
= chipid_to_nrcores(bus
->chip_id
);
321 if (bus
->nr_devices
> ARRAY_SIZE(bus
->devices
)) {
322 ssb_printk(KERN_ERR PFX
323 "More than %d ssb cores found (%d)\n",
324 SSB_MAX_NR_CORES
, bus
->nr_devices
);
327 if (bus
->bustype
== SSB_BUSTYPE_SSB
) {
328 /* Now that we know the number of cores,
329 * remap the whole IO space for all cores.
333 mmio
= ioremap(baseaddr
, SSB_CORE_SIZE
* bus
->nr_devices
);
339 /* Fetch basic information about each core/device */
340 for (i
= 0, dev_i
= 0; i
< bus
->nr_devices
; i
++) {
341 err
= scan_switchcore(bus
, i
);
344 dev
= &(bus
->devices
[dev_i
]);
346 idhi
= scan_read32(bus
, i
, SSB_IDHIGH
);
347 dev
->id
.coreid
= (idhi
& SSB_IDHIGH_CC
) >> SSB_IDHIGH_CC_SHIFT
;
348 dev
->id
.revision
= (idhi
& SSB_IDHIGH_RCLO
);
349 dev
->id
.revision
|= (idhi
& SSB_IDHIGH_RCHI
) >> SSB_IDHIGH_RCHI_SHIFT
;
350 dev
->id
.vendor
= (idhi
& SSB_IDHIGH_VC
) >> SSB_IDHIGH_VC_SHIFT
;
355 printk(KERN_DEBUG PFX
357 "(cc 0x%03X, rev 0x%02X, vendor 0x%04X)\n",
358 i
, ssb_core_name(dev
->id
.coreid
),
359 dev
->id
.coreid
, dev
->id
.revision
, dev
->id
.vendor
);
361 switch (dev
->id
.coreid
) {
364 if (nr_80211_cores
> 1) {
365 if (!we_support_multiple_80211_cores(bus
)) {
366 ssb_dprintk(KERN_INFO PFX
"Ignoring additional "
373 #ifdef CONFIG_SSB_DRIVER_EXTIF
374 if (bus
->extif
.dev
) {
375 ssb_printk(KERN_WARNING PFX
376 "WARNING: Multiple EXTIFs found\n");
379 bus
->extif
.dev
= dev
;
380 #endif /* CONFIG_SSB_DRIVER_EXTIF */
382 case SSB_DEV_CHIPCOMMON
:
383 if (bus
->chipco
.dev
) {
384 ssb_printk(KERN_WARNING PFX
385 "WARNING: Multiple ChipCommon found\n");
388 bus
->chipco
.dev
= dev
;
391 case SSB_DEV_MIPS_3302
:
392 #ifdef CONFIG_SSB_DRIVER_MIPS
393 if (bus
->mipscore
.dev
) {
394 ssb_printk(KERN_WARNING PFX
395 "WARNING: Multiple MIPS cores found\n");
398 bus
->mipscore
.dev
= dev
;
399 #endif /* CONFIG_SSB_DRIVER_MIPS */
403 #ifdef CONFIG_SSB_DRIVER_PCICORE
404 if (bus
->bustype
== SSB_BUSTYPE_PCI
) {
405 /* Ignore PCI cores on PCI-E cards.
406 * Ignore PCI-E cores on PCI cards. */
407 if (dev
->id
.coreid
== SSB_DEV_PCI
) {
408 if (pci_is_pcie(bus
->host_pci
))
411 if (!pci_is_pcie(bus
->host_pci
))
415 if (bus
->pcicore
.dev
) {
416 ssb_printk(KERN_WARNING PFX
417 "WARNING: Multiple PCI(E) cores found\n");
420 bus
->pcicore
.dev
= dev
;
421 #endif /* CONFIG_SSB_DRIVER_PCICORE */
423 case SSB_DEV_ETHERNET
:
424 if (bus
->bustype
== SSB_BUSTYPE_PCI
) {
425 if (bus
->host_pci
->vendor
== PCI_VENDOR_ID_BROADCOM
&&
426 (bus
->host_pci
->device
& 0xFF00) == 0x4300) {
427 /* This is a dangling ethernet core on a
428 * wireless device. Ignore it. */
439 bus
->nr_devices
= dev_i
;