2 * Broadcom specific AMBA
5 * Licensed under the GNU/GPL. See COPYING for details.
8 #include "bcma_private.h"
9 #include <linux/bcma/bcma.h>
11 MODULE_DESCRIPTION("Broadcom's specific AMBA driver");
12 MODULE_LICENSE("GPL");
14 static int bcma_bus_match(struct device
*dev
, struct device_driver
*drv
);
15 static int bcma_device_probe(struct device
*dev
);
16 static int bcma_device_remove(struct device
*dev
);
18 static ssize_t
manuf_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
20 struct bcma_device
*core
= container_of(dev
, struct bcma_device
, dev
);
21 return sprintf(buf
, "0x%03X\n", core
->id
.manuf
);
23 static ssize_t
id_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
25 struct bcma_device
*core
= container_of(dev
, struct bcma_device
, dev
);
26 return sprintf(buf
, "0x%03X\n", core
->id
.id
);
28 static ssize_t
rev_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
30 struct bcma_device
*core
= container_of(dev
, struct bcma_device
, dev
);
31 return sprintf(buf
, "0x%02X\n", core
->id
.rev
);
33 static ssize_t
class_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
35 struct bcma_device
*core
= container_of(dev
, struct bcma_device
, dev
);
36 return sprintf(buf
, "0x%X\n", core
->id
.class);
38 static struct device_attribute bcma_device_attrs
[] = {
46 static struct bus_type bcma_bus_type
= {
48 .match
= bcma_bus_match
,
49 .probe
= bcma_device_probe
,
50 .remove
= bcma_device_remove
,
51 .dev_attrs
= bcma_device_attrs
,
54 static struct bcma_device
*bcma_find_core(struct bcma_bus
*bus
, u16 coreid
)
56 struct bcma_device
*core
;
58 list_for_each_entry(core
, &bus
->cores
, list
) {
59 if (core
->id
.id
== coreid
)
65 static void bcma_release_core_dev(struct device
*dev
)
67 struct bcma_device
*core
= container_of(dev
, struct bcma_device
, dev
);
71 static int bcma_register_cores(struct bcma_bus
*bus
)
73 struct bcma_device
*core
;
76 list_for_each_entry(core
, &bus
->cores
, list
) {
77 /* We support that cores ourself */
78 switch (core
->id
.id
) {
79 case BCMA_CORE_CHIPCOMMON
:
85 core
->dev
.release
= bcma_release_core_dev
;
86 core
->dev
.bus
= &bcma_bus_type
;
87 dev_set_name(&core
->dev
, "bcma%d:%d", 0/*bus->num*/, dev_id
);
89 switch (bus
->hosttype
) {
90 case BCMA_HOSTTYPE_PCI
:
91 core
->dev
.parent
= &bus
->host_pci
->dev
;
92 core
->dma_dev
= &bus
->host_pci
->dev
;
93 core
->irq
= bus
->host_pci
->irq
;
95 case BCMA_HOSTTYPE_NONE
:
96 case BCMA_HOSTTYPE_SDIO
:
100 err
= device_register(&core
->dev
);
102 pr_err("Could not register dev for core 0x%03X\n",
106 core
->dev_registered
= true;
113 static void bcma_unregister_cores(struct bcma_bus
*bus
)
115 struct bcma_device
*core
;
117 list_for_each_entry(core
, &bus
->cores
, list
) {
118 if (core
->dev_registered
)
119 device_unregister(&core
->dev
);
123 int bcma_bus_register(struct bcma_bus
*bus
)
126 struct bcma_device
*core
;
128 /* Scan for devices (cores) */
129 err
= bcma_bus_scan(bus
);
131 pr_err("Failed to scan: %d\n", err
);
136 core
= bcma_find_core(bus
, BCMA_CORE_CHIPCOMMON
);
138 bus
->drv_cc
.core
= core
;
139 bcma_core_chipcommon_init(&bus
->drv_cc
);
143 core
= bcma_find_core(bus
, BCMA_CORE_PCIE
);
145 bus
->drv_pci
.core
= core
;
146 bcma_core_pci_init(&bus
->drv_pci
);
149 /* Register found cores */
150 bcma_register_cores(bus
);
152 pr_info("Bus registered\n");
156 EXPORT_SYMBOL_GPL(bcma_bus_register
);
158 void bcma_bus_unregister(struct bcma_bus
*bus
)
160 bcma_unregister_cores(bus
);
162 EXPORT_SYMBOL_GPL(bcma_bus_unregister
);
164 int __bcma_driver_register(struct bcma_driver
*drv
, struct module
*owner
)
166 drv
->drv
.name
= drv
->name
;
167 drv
->drv
.bus
= &bcma_bus_type
;
168 drv
->drv
.owner
= owner
;
170 return driver_register(&drv
->drv
);
172 EXPORT_SYMBOL_GPL(__bcma_driver_register
);
174 void bcma_driver_unregister(struct bcma_driver
*drv
)
176 driver_unregister(&drv
->drv
);
178 EXPORT_SYMBOL_GPL(bcma_driver_unregister
);
180 static int bcma_bus_match(struct device
*dev
, struct device_driver
*drv
)
182 struct bcma_device
*core
= container_of(dev
, struct bcma_device
, dev
);
183 struct bcma_driver
*adrv
= container_of(drv
, struct bcma_driver
, drv
);
184 const struct bcma_device_id
*cid
= &core
->id
;
185 const struct bcma_device_id
*did
;
187 for (did
= adrv
->id_table
; did
->manuf
|| did
->id
|| did
->rev
; did
++) {
188 if ((did
->manuf
== cid
->manuf
|| did
->manuf
== BCMA_ANY_MANUF
) &&
189 (did
->id
== cid
->id
|| did
->id
== BCMA_ANY_ID
) &&
190 (did
->rev
== cid
->rev
|| did
->rev
== BCMA_ANY_REV
) &&
191 (did
->class == cid
->class || did
->class == BCMA_ANY_CLASS
))
197 static int bcma_device_probe(struct device
*dev
)
199 struct bcma_device
*core
= container_of(dev
, struct bcma_device
, dev
);
200 struct bcma_driver
*adrv
= container_of(dev
->driver
, struct bcma_driver
,
205 err
= adrv
->probe(core
);
210 static int bcma_device_remove(struct device
*dev
)
212 struct bcma_device
*core
= container_of(dev
, struct bcma_device
, dev
);
213 struct bcma_driver
*adrv
= container_of(dev
->driver
, struct bcma_driver
,
222 static int __init
bcma_modinit(void)
226 err
= bus_register(&bcma_bus_type
);
230 #ifdef CONFIG_BCMA_HOST_PCI
231 err
= bcma_host_pci_init();
233 pr_err("PCI host initialization failed\n");
240 fs_initcall(bcma_modinit
);
242 static void __exit
bcma_modexit(void)
244 #ifdef CONFIG_BCMA_HOST_PCI
245 bcma_host_pci_exit();
247 bus_unregister(&bcma_bus_type
);
249 module_exit(bcma_modexit
)