2 * Broadcom specific AMBA
5 * Licensed under the GNU/GPL. See COPYING for details.
8 #include "bcma_private.h"
9 #include <linux/module.h>
10 #include <linux/bcma/bcma.h>
11 #include <linux/slab.h>
13 MODULE_DESCRIPTION("Broadcom's specific AMBA driver");
14 MODULE_LICENSE("GPL");
16 static int bcma_bus_match(struct device
*dev
, struct device_driver
*drv
);
17 static int bcma_device_probe(struct device
*dev
);
18 static int bcma_device_remove(struct device
*dev
);
19 static int bcma_device_uevent(struct device
*dev
, struct kobj_uevent_env
*env
);
21 static ssize_t
manuf_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
23 struct bcma_device
*core
= container_of(dev
, struct bcma_device
, dev
);
24 return sprintf(buf
, "0x%03X\n", core
->id
.manuf
);
26 static ssize_t
id_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
28 struct bcma_device
*core
= container_of(dev
, struct bcma_device
, dev
);
29 return sprintf(buf
, "0x%03X\n", core
->id
.id
);
31 static ssize_t
rev_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
33 struct bcma_device
*core
= container_of(dev
, struct bcma_device
, dev
);
34 return sprintf(buf
, "0x%02X\n", core
->id
.rev
);
36 static ssize_t
class_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
38 struct bcma_device
*core
= container_of(dev
, struct bcma_device
, dev
);
39 return sprintf(buf
, "0x%X\n", core
->id
.class);
41 static struct device_attribute bcma_device_attrs
[] = {
49 static struct bus_type bcma_bus_type
= {
51 .match
= bcma_bus_match
,
52 .probe
= bcma_device_probe
,
53 .remove
= bcma_device_remove
,
54 .uevent
= bcma_device_uevent
,
55 .dev_attrs
= bcma_device_attrs
,
58 static struct bcma_device
*bcma_find_core(struct bcma_bus
*bus
, u16 coreid
)
60 struct bcma_device
*core
;
62 list_for_each_entry(core
, &bus
->cores
, list
) {
63 if (core
->id
.id
== coreid
)
69 static void bcma_release_core_dev(struct device
*dev
)
71 struct bcma_device
*core
= container_of(dev
, struct bcma_device
, dev
);
73 iounmap(core
->io_addr
);
75 iounmap(core
->io_wrap
);
79 static int bcma_register_cores(struct bcma_bus
*bus
)
81 struct bcma_device
*core
;
84 list_for_each_entry(core
, &bus
->cores
, list
) {
85 /* We support that cores ourself */
86 switch (core
->id
.id
) {
87 case BCMA_CORE_CHIPCOMMON
:
90 case BCMA_CORE_MIPS_74K
:
94 core
->dev
.release
= bcma_release_core_dev
;
95 core
->dev
.bus
= &bcma_bus_type
;
96 dev_set_name(&core
->dev
, "bcma%d:%d", 0/*bus->num*/, dev_id
);
98 switch (bus
->hosttype
) {
99 case BCMA_HOSTTYPE_PCI
:
100 core
->dev
.parent
= &bus
->host_pci
->dev
;
101 core
->dma_dev
= &bus
->host_pci
->dev
;
102 core
->irq
= bus
->host_pci
->irq
;
104 case BCMA_HOSTTYPE_SOC
:
105 core
->dev
.dma_mask
= &core
->dev
.coherent_dma_mask
;
106 core
->dma_dev
= &core
->dev
;
108 case BCMA_HOSTTYPE_SDIO
:
112 err
= device_register(&core
->dev
);
114 pr_err("Could not register dev for core 0x%03X\n",
118 core
->dev_registered
= true;
125 static void bcma_unregister_cores(struct bcma_bus
*bus
)
127 struct bcma_device
*core
;
129 list_for_each_entry(core
, &bus
->cores
, list
) {
130 if (core
->dev_registered
)
131 device_unregister(&core
->dev
);
135 int bcma_bus_register(struct bcma_bus
*bus
)
138 struct bcma_device
*core
;
140 /* Scan for devices (cores) */
141 err
= bcma_bus_scan(bus
);
143 pr_err("Failed to scan: %d\n", err
);
148 core
= bcma_find_core(bus
, BCMA_CORE_CHIPCOMMON
);
150 bus
->drv_cc
.core
= core
;
151 bcma_core_chipcommon_init(&bus
->drv_cc
);
155 core
= bcma_find_core(bus
, BCMA_CORE_MIPS_74K
);
157 bus
->drv_mips
.core
= core
;
158 bcma_core_mips_init(&bus
->drv_mips
);
162 core
= bcma_find_core(bus
, BCMA_CORE_PCIE
);
164 bus
->drv_pci
.core
= core
;
165 bcma_core_pci_init(&bus
->drv_pci
);
168 /* Try to get SPROM */
169 err
= bcma_sprom_get(bus
);
170 if (err
== -ENOENT
) {
171 pr_err("No SPROM available\n");
173 pr_err("Failed to get SPROM: %d\n", err
);
175 /* Register found cores */
176 bcma_register_cores(bus
);
178 pr_info("Bus registered\n");
183 void bcma_bus_unregister(struct bcma_bus
*bus
)
185 bcma_unregister_cores(bus
);
188 int __init
bcma_bus_early_register(struct bcma_bus
*bus
,
189 struct bcma_device
*core_cc
,
190 struct bcma_device
*core_mips
)
193 struct bcma_device
*core
;
194 struct bcma_device_id match
;
198 match
.manuf
= BCMA_MANUF_BCM
;
199 match
.id
= BCMA_CORE_CHIPCOMMON
;
200 match
.class = BCMA_CL_SIM
;
201 match
.rev
= BCMA_ANY_REV
;
203 /* Scan for chip common core */
204 err
= bcma_bus_scan_early(bus
, &match
, core_cc
);
206 pr_err("Failed to scan for common core: %d\n", err
);
210 match
.manuf
= BCMA_MANUF_MIPS
;
211 match
.id
= BCMA_CORE_MIPS_74K
;
212 match
.class = BCMA_CL_SIM
;
213 match
.rev
= BCMA_ANY_REV
;
215 /* Scan for mips core */
216 err
= bcma_bus_scan_early(bus
, &match
, core_mips
);
218 pr_err("Failed to scan for mips core: %d\n", err
);
223 core
= bcma_find_core(bus
, BCMA_CORE_CHIPCOMMON
);
225 bus
->drv_cc
.core
= core
;
226 bcma_core_chipcommon_init(&bus
->drv_cc
);
230 core
= bcma_find_core(bus
, BCMA_CORE_MIPS_74K
);
232 bus
->drv_mips
.core
= core
;
233 bcma_core_mips_init(&bus
->drv_mips
);
236 pr_info("Early bus registered\n");
242 int bcma_bus_suspend(struct bcma_bus
*bus
)
244 struct bcma_device
*core
;
246 list_for_each_entry(core
, &bus
->cores
, list
) {
247 struct device_driver
*drv
= core
->dev
.driver
;
249 struct bcma_driver
*adrv
= container_of(drv
, struct bcma_driver
, drv
);
257 int bcma_bus_resume(struct bcma_bus
*bus
)
259 struct bcma_device
*core
;
262 core
= bcma_find_core(bus
, BCMA_CORE_CHIPCOMMON
);
264 bus
->drv_cc
.setup_done
= false;
265 bcma_core_chipcommon_init(&bus
->drv_cc
);
268 list_for_each_entry(core
, &bus
->cores
, list
) {
269 struct device_driver
*drv
= core
->dev
.driver
;
271 struct bcma_driver
*adrv
= container_of(drv
, struct bcma_driver
, drv
);
281 int __bcma_driver_register(struct bcma_driver
*drv
, struct module
*owner
)
283 drv
->drv
.name
= drv
->name
;
284 drv
->drv
.bus
= &bcma_bus_type
;
285 drv
->drv
.owner
= owner
;
287 return driver_register(&drv
->drv
);
289 EXPORT_SYMBOL_GPL(__bcma_driver_register
);
291 void bcma_driver_unregister(struct bcma_driver
*drv
)
293 driver_unregister(&drv
->drv
);
295 EXPORT_SYMBOL_GPL(bcma_driver_unregister
);
297 static int bcma_bus_match(struct device
*dev
, struct device_driver
*drv
)
299 struct bcma_device
*core
= container_of(dev
, struct bcma_device
, dev
);
300 struct bcma_driver
*adrv
= container_of(drv
, struct bcma_driver
, drv
);
301 const struct bcma_device_id
*cid
= &core
->id
;
302 const struct bcma_device_id
*did
;
304 for (did
= adrv
->id_table
; did
->manuf
|| did
->id
|| did
->rev
; did
++) {
305 if ((did
->manuf
== cid
->manuf
|| did
->manuf
== BCMA_ANY_MANUF
) &&
306 (did
->id
== cid
->id
|| did
->id
== BCMA_ANY_ID
) &&
307 (did
->rev
== cid
->rev
|| did
->rev
== BCMA_ANY_REV
) &&
308 (did
->class == cid
->class || did
->class == BCMA_ANY_CLASS
))
314 static int bcma_device_probe(struct device
*dev
)
316 struct bcma_device
*core
= container_of(dev
, struct bcma_device
, dev
);
317 struct bcma_driver
*adrv
= container_of(dev
->driver
, struct bcma_driver
,
322 err
= adrv
->probe(core
);
327 static int bcma_device_remove(struct device
*dev
)
329 struct bcma_device
*core
= container_of(dev
, struct bcma_device
, dev
);
330 struct bcma_driver
*adrv
= container_of(dev
->driver
, struct bcma_driver
,
339 static int bcma_device_uevent(struct device
*dev
, struct kobj_uevent_env
*env
)
341 struct bcma_device
*core
= container_of(dev
, struct bcma_device
, dev
);
343 return add_uevent_var(env
,
344 "MODALIAS=bcma:m%04Xid%04Xrev%02Xcl%02X",
345 core
->id
.manuf
, core
->id
.id
,
346 core
->id
.rev
, core
->id
.class);
349 static int __init
bcma_modinit(void)
353 err
= bus_register(&bcma_bus_type
);
357 #ifdef CONFIG_BCMA_HOST_PCI
358 err
= bcma_host_pci_init();
360 pr_err("PCI host initialization failed\n");
367 fs_initcall(bcma_modinit
);
369 static void __exit
bcma_modexit(void)
371 #ifdef CONFIG_BCMA_HOST_PCI
372 bcma_host_pci_exit();
374 bus_unregister(&bcma_bus_type
);
376 module_exit(bcma_modexit
)