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>
10 #include <linux/slab.h>
12 MODULE_DESCRIPTION("Broadcom's specific AMBA driver");
13 MODULE_LICENSE("GPL");
15 static int bcma_bus_match(struct device *dev, struct device_driver *drv);
16 static int bcma_device_probe(struct device *dev);
17 static int bcma_device_remove(struct device *dev);
19 static ssize_t manuf_show(struct device *dev, struct device_attribute *attr, char *buf)
21 struct bcma_device *core = container_of(dev, struct bcma_device, dev);
22 return sprintf(buf, "0x%03X\n", core->id.manuf);
24 static ssize_t id_show(struct device *dev, struct device_attribute *attr, char *buf)
26 struct bcma_device *core = container_of(dev, struct bcma_device, dev);
27 return sprintf(buf, "0x%03X\n", core->id.id);
29 static ssize_t rev_show(struct device *dev, struct device_attribute *attr, char *buf)
31 struct bcma_device *core = container_of(dev, struct bcma_device, dev);
32 return sprintf(buf, "0x%02X\n", core->id.rev);
34 static ssize_t class_show(struct device *dev, struct device_attribute *attr, char *buf)
36 struct bcma_device *core = container_of(dev, struct bcma_device, dev);
37 return sprintf(buf, "0x%X\n", core->id.class);
39 static struct device_attribute bcma_device_attrs[] = {
47 static struct bus_type bcma_bus_type = {
49 .match = bcma_bus_match,
50 .probe = bcma_device_probe,
51 .remove = bcma_device_remove,
52 .dev_attrs = bcma_device_attrs,
55 static struct bcma_device *bcma_find_core(struct bcma_bus *bus, u16 coreid)
57 struct bcma_device *core;
59 list_for_each_entry(core, &bus->cores, list) {
60 if (core->id.id == coreid)
66 static void bcma_release_core_dev(struct device *dev)
68 struct bcma_device *core = container_of(dev, struct bcma_device, dev);
72 static int bcma_register_cores(struct bcma_bus *bus)
74 struct bcma_device *core;
77 list_for_each_entry(core, &bus->cores, list) {
78 /* We support that cores ourself */
79 switch (core->id.id) {
80 case BCMA_CORE_CHIPCOMMON:
86 core->dev.release = bcma_release_core_dev;
87 core->dev.bus = &bcma_bus_type;
88 dev_set_name(&core->dev, "bcma%d:%d", 0/*bus->num*/, dev_id);
90 switch (bus->hosttype) {
91 case BCMA_HOSTTYPE_PCI:
92 core->dev.parent = &bus->host_pci->dev;
93 core->dma_dev = &bus->host_pci->dev;
94 core->irq = bus->host_pci->irq;
96 case BCMA_HOSTTYPE_NONE:
97 case BCMA_HOSTTYPE_SDIO:
101 err = device_register(&core->dev);
103 pr_err("Could not register dev for core 0x%03X\n",
107 core->dev_registered = true;
114 static void bcma_unregister_cores(struct bcma_bus *bus)
116 struct bcma_device *core;
118 list_for_each_entry(core, &bus->cores, list) {
119 if (core->dev_registered)
120 device_unregister(&core->dev);
124 int bcma_bus_register(struct bcma_bus *bus)
127 struct bcma_device *core;
129 /* Scan for devices (cores) */
130 err = bcma_bus_scan(bus);
132 pr_err("Failed to scan: %d\n", err);
137 core = bcma_find_core(bus, BCMA_CORE_CHIPCOMMON);
139 bus->drv_cc.core = core;
140 bcma_core_chipcommon_init(&bus->drv_cc);
144 core = bcma_find_core(bus, BCMA_CORE_PCIE);
146 bus->drv_pci.core = core;
147 bcma_core_pci_init(&bus->drv_pci);
150 /* Try to get SPROM */
151 err = bcma_sprom_get(bus);
152 if (err == -ENOENT) {
153 pr_err("No SPROM available\n");
155 pr_err("Failed to get SPROM: %d\n", err);
159 /* Register found cores */
160 bcma_register_cores(bus);
162 pr_info("Bus registered\n");
167 void bcma_bus_unregister(struct bcma_bus *bus)
169 bcma_unregister_cores(bus);
172 int __init bcma_bus_early_register(struct bcma_bus *bus,
173 struct bcma_device *core_cc,
174 struct bcma_device *core_mips)
177 struct bcma_device *core;
178 struct bcma_device_id match;
182 match.manuf = BCMA_MANUF_BCM;
183 match.id = BCMA_CORE_CHIPCOMMON;
184 match.class = BCMA_CL_SIM;
185 match.rev = BCMA_ANY_REV;
187 /* Scan for chip common core */
188 err = bcma_bus_scan_early(bus, &match, core_cc);
190 pr_err("Failed to scan for common core: %d\n", err);
194 match.manuf = BCMA_MANUF_MIPS;
195 match.id = BCMA_CORE_MIPS_74K;
196 match.class = BCMA_CL_SIM;
197 match.rev = BCMA_ANY_REV;
199 /* Scan for mips core */
200 err = bcma_bus_scan_early(bus, &match, core_mips);
202 pr_err("Failed to scan for mips core: %d\n", err);
207 core = bcma_find_core(bus, BCMA_CORE_CHIPCOMMON);
209 bus->drv_cc.core = core;
210 bcma_core_chipcommon_init(&bus->drv_cc);
213 pr_info("Early bus registered\n");
218 int __bcma_driver_register(struct bcma_driver *drv, struct module *owner)
220 drv->drv.name = drv->name;
221 drv->drv.bus = &bcma_bus_type;
222 drv->drv.owner = owner;
224 return driver_register(&drv->drv);
226 EXPORT_SYMBOL_GPL(__bcma_driver_register);
228 void bcma_driver_unregister(struct bcma_driver *drv)
230 driver_unregister(&drv->drv);
232 EXPORT_SYMBOL_GPL(bcma_driver_unregister);
234 static int bcma_bus_match(struct device *dev, struct device_driver *drv)
236 struct bcma_device *core = container_of(dev, struct bcma_device, dev);
237 struct bcma_driver *adrv = container_of(drv, struct bcma_driver, drv);
238 const struct bcma_device_id *cid = &core->id;
239 const struct bcma_device_id *did;
241 for (did = adrv->id_table; did->manuf || did->id || did->rev; did++) {
242 if ((did->manuf == cid->manuf || did->manuf == BCMA_ANY_MANUF) &&
243 (did->id == cid->id || did->id == BCMA_ANY_ID) &&
244 (did->rev == cid->rev || did->rev == BCMA_ANY_REV) &&
245 (did->class == cid->class || did->class == BCMA_ANY_CLASS))
251 static int bcma_device_probe(struct device *dev)
253 struct bcma_device *core = container_of(dev, struct bcma_device, dev);
254 struct bcma_driver *adrv = container_of(dev->driver, struct bcma_driver,
259 err = adrv->probe(core);
264 static int bcma_device_remove(struct device *dev)
266 struct bcma_device *core = container_of(dev, struct bcma_device, dev);
267 struct bcma_driver *adrv = container_of(dev->driver, struct bcma_driver,
276 static int __init bcma_modinit(void)
280 err = bus_register(&bcma_bus_type);
284 #ifdef CONFIG_BCMA_HOST_PCI
285 err = bcma_host_pci_init();
287 pr_err("PCI host initialization failed\n");
294 fs_initcall(bcma_modinit);
296 static void __exit bcma_modexit(void)
298 #ifdef CONFIG_BCMA_HOST_PCI
299 bcma_host_pci_exit();
301 bus_unregister(&bcma_bus_type);
303 module_exit(bcma_modexit)