ipv6: reallocate addrconf router for ipv6 address when lo device up
[linux/fpc-iii.git] / drivers / bcma / main.c
blobedb9233b26d20108a5c4ce78b5505f340736be68
1 /*
2 * Broadcom specific AMBA
3 * Bus subsystem
5 * Licensed under the GNU/GPL. See COPYING for details.
6 */
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 /* contains the number the next bus should get. */
17 static unsigned int bcma_bus_next_num = 0;
19 /* bcma_buses_mutex locks the bcma_bus_next_num */
20 static DEFINE_MUTEX(bcma_buses_mutex);
22 static int bcma_bus_match(struct device *dev, struct device_driver *drv);
23 static int bcma_device_probe(struct device *dev);
24 static int bcma_device_remove(struct device *dev);
25 static int bcma_device_uevent(struct device *dev, struct kobj_uevent_env *env);
27 static ssize_t manuf_show(struct device *dev, struct device_attribute *attr, char *buf)
29 struct bcma_device *core = container_of(dev, struct bcma_device, dev);
30 return sprintf(buf, "0x%03X\n", core->id.manuf);
32 static ssize_t id_show(struct device *dev, struct device_attribute *attr, char *buf)
34 struct bcma_device *core = container_of(dev, struct bcma_device, dev);
35 return sprintf(buf, "0x%03X\n", core->id.id);
37 static ssize_t rev_show(struct device *dev, struct device_attribute *attr, char *buf)
39 struct bcma_device *core = container_of(dev, struct bcma_device, dev);
40 return sprintf(buf, "0x%02X\n", core->id.rev);
42 static ssize_t class_show(struct device *dev, struct device_attribute *attr, char *buf)
44 struct bcma_device *core = container_of(dev, struct bcma_device, dev);
45 return sprintf(buf, "0x%X\n", core->id.class);
47 static struct device_attribute bcma_device_attrs[] = {
48 __ATTR_RO(manuf),
49 __ATTR_RO(id),
50 __ATTR_RO(rev),
51 __ATTR_RO(class),
52 __ATTR_NULL,
55 static struct bus_type bcma_bus_type = {
56 .name = "bcma",
57 .match = bcma_bus_match,
58 .probe = bcma_device_probe,
59 .remove = bcma_device_remove,
60 .uevent = bcma_device_uevent,
61 .dev_attrs = bcma_device_attrs,
64 struct bcma_device *bcma_find_core(struct bcma_bus *bus, u16 coreid)
66 struct bcma_device *core;
68 list_for_each_entry(core, &bus->cores, list) {
69 if (core->id.id == coreid)
70 return core;
72 return NULL;
74 EXPORT_SYMBOL_GPL(bcma_find_core);
76 static void bcma_release_core_dev(struct device *dev)
78 struct bcma_device *core = container_of(dev, struct bcma_device, dev);
79 if (core->io_addr)
80 iounmap(core->io_addr);
81 if (core->io_wrap)
82 iounmap(core->io_wrap);
83 kfree(core);
86 static int bcma_register_cores(struct bcma_bus *bus)
88 struct bcma_device *core;
89 int err, dev_id = 0;
91 list_for_each_entry(core, &bus->cores, list) {
92 /* We support that cores ourself */
93 switch (core->id.id) {
94 case BCMA_CORE_CHIPCOMMON:
95 case BCMA_CORE_PCI:
96 case BCMA_CORE_PCIE:
97 case BCMA_CORE_MIPS_74K:
98 continue;
101 core->dev.release = bcma_release_core_dev;
102 core->dev.bus = &bcma_bus_type;
103 dev_set_name(&core->dev, "bcma%d:%d", bus->num, dev_id);
105 switch (bus->hosttype) {
106 case BCMA_HOSTTYPE_PCI:
107 core->dev.parent = &bus->host_pci->dev;
108 core->dma_dev = &bus->host_pci->dev;
109 core->irq = bus->host_pci->irq;
110 break;
111 case BCMA_HOSTTYPE_SOC:
112 core->dev.dma_mask = &core->dev.coherent_dma_mask;
113 core->dma_dev = &core->dev;
114 break;
115 case BCMA_HOSTTYPE_SDIO:
116 break;
119 err = device_register(&core->dev);
120 if (err) {
121 pr_err("Could not register dev for core 0x%03X\n",
122 core->id.id);
123 continue;
125 core->dev_registered = true;
126 dev_id++;
129 return 0;
132 static void bcma_unregister_cores(struct bcma_bus *bus)
134 struct bcma_device *core, *tmp;
136 list_for_each_entry_safe(core, tmp, &bus->cores, list) {
137 list_del(&core->list);
138 if (core->dev_registered)
139 device_unregister(&core->dev);
143 int __devinit bcma_bus_register(struct bcma_bus *bus)
145 int err;
146 struct bcma_device *core;
148 mutex_lock(&bcma_buses_mutex);
149 bus->num = bcma_bus_next_num++;
150 mutex_unlock(&bcma_buses_mutex);
152 /* Scan for devices (cores) */
153 err = bcma_bus_scan(bus);
154 if (err) {
155 pr_err("Failed to scan: %d\n", err);
156 return -1;
159 /* Init CC core */
160 core = bcma_find_core(bus, BCMA_CORE_CHIPCOMMON);
161 if (core) {
162 bus->drv_cc.core = core;
163 bcma_core_chipcommon_init(&bus->drv_cc);
166 /* Init MIPS core */
167 core = bcma_find_core(bus, BCMA_CORE_MIPS_74K);
168 if (core) {
169 bus->drv_mips.core = core;
170 bcma_core_mips_init(&bus->drv_mips);
173 /* Init PCIE core */
174 core = bcma_find_core(bus, BCMA_CORE_PCIE);
175 if (core) {
176 bus->drv_pci.core = core;
177 bcma_core_pci_init(&bus->drv_pci);
180 /* Try to get SPROM */
181 err = bcma_sprom_get(bus);
182 if (err == -ENOENT) {
183 pr_err("No SPROM available\n");
184 } else if (err)
185 pr_err("Failed to get SPROM: %d\n", err);
187 /* Register found cores */
188 bcma_register_cores(bus);
190 pr_info("Bus registered\n");
192 return 0;
195 void bcma_bus_unregister(struct bcma_bus *bus)
197 bcma_unregister_cores(bus);
200 int __init bcma_bus_early_register(struct bcma_bus *bus,
201 struct bcma_device *core_cc,
202 struct bcma_device *core_mips)
204 int err;
205 struct bcma_device *core;
206 struct bcma_device_id match;
208 bcma_init_bus(bus);
210 match.manuf = BCMA_MANUF_BCM;
211 match.id = BCMA_CORE_CHIPCOMMON;
212 match.class = BCMA_CL_SIM;
213 match.rev = BCMA_ANY_REV;
215 /* Scan for chip common core */
216 err = bcma_bus_scan_early(bus, &match, core_cc);
217 if (err) {
218 pr_err("Failed to scan for common core: %d\n", err);
219 return -1;
222 match.manuf = BCMA_MANUF_MIPS;
223 match.id = BCMA_CORE_MIPS_74K;
224 match.class = BCMA_CL_SIM;
225 match.rev = BCMA_ANY_REV;
227 /* Scan for mips core */
228 err = bcma_bus_scan_early(bus, &match, core_mips);
229 if (err) {
230 pr_err("Failed to scan for mips core: %d\n", err);
231 return -1;
234 /* Init CC core */
235 core = bcma_find_core(bus, BCMA_CORE_CHIPCOMMON);
236 if (core) {
237 bus->drv_cc.core = core;
238 bcma_core_chipcommon_init(&bus->drv_cc);
241 /* Init MIPS core */
242 core = bcma_find_core(bus, BCMA_CORE_MIPS_74K);
243 if (core) {
244 bus->drv_mips.core = core;
245 bcma_core_mips_init(&bus->drv_mips);
248 pr_info("Early bus registered\n");
250 return 0;
253 #ifdef CONFIG_PM
254 int bcma_bus_suspend(struct bcma_bus *bus)
256 struct bcma_device *core;
258 list_for_each_entry(core, &bus->cores, list) {
259 struct device_driver *drv = core->dev.driver;
260 if (drv) {
261 struct bcma_driver *adrv = container_of(drv, struct bcma_driver, drv);
262 if (adrv->suspend)
263 adrv->suspend(core);
266 return 0;
269 int bcma_bus_resume(struct bcma_bus *bus)
271 struct bcma_device *core;
273 /* Init CC core */
274 core = bcma_find_core(bus, BCMA_CORE_CHIPCOMMON);
275 if (core) {
276 bus->drv_cc.setup_done = false;
277 bcma_core_chipcommon_init(&bus->drv_cc);
280 list_for_each_entry(core, &bus->cores, list) {
281 struct device_driver *drv = core->dev.driver;
282 if (drv) {
283 struct bcma_driver *adrv = container_of(drv, struct bcma_driver, drv);
284 if (adrv->resume)
285 adrv->resume(core);
289 return 0;
291 #endif
293 int __bcma_driver_register(struct bcma_driver *drv, struct module *owner)
295 drv->drv.name = drv->name;
296 drv->drv.bus = &bcma_bus_type;
297 drv->drv.owner = owner;
299 return driver_register(&drv->drv);
301 EXPORT_SYMBOL_GPL(__bcma_driver_register);
303 void bcma_driver_unregister(struct bcma_driver *drv)
305 driver_unregister(&drv->drv);
307 EXPORT_SYMBOL_GPL(bcma_driver_unregister);
309 static int bcma_bus_match(struct device *dev, struct device_driver *drv)
311 struct bcma_device *core = container_of(dev, struct bcma_device, dev);
312 struct bcma_driver *adrv = container_of(drv, struct bcma_driver, drv);
313 const struct bcma_device_id *cid = &core->id;
314 const struct bcma_device_id *did;
316 for (did = adrv->id_table; did->manuf || did->id || did->rev; did++) {
317 if ((did->manuf == cid->manuf || did->manuf == BCMA_ANY_MANUF) &&
318 (did->id == cid->id || did->id == BCMA_ANY_ID) &&
319 (did->rev == cid->rev || did->rev == BCMA_ANY_REV) &&
320 (did->class == cid->class || did->class == BCMA_ANY_CLASS))
321 return 1;
323 return 0;
326 static int bcma_device_probe(struct device *dev)
328 struct bcma_device *core = container_of(dev, struct bcma_device, dev);
329 struct bcma_driver *adrv = container_of(dev->driver, struct bcma_driver,
330 drv);
331 int err = 0;
333 if (adrv->probe)
334 err = adrv->probe(core);
336 return err;
339 static int bcma_device_remove(struct device *dev)
341 struct bcma_device *core = container_of(dev, struct bcma_device, dev);
342 struct bcma_driver *adrv = container_of(dev->driver, struct bcma_driver,
343 drv);
345 if (adrv->remove)
346 adrv->remove(core);
348 return 0;
351 static int bcma_device_uevent(struct device *dev, struct kobj_uevent_env *env)
353 struct bcma_device *core = container_of(dev, struct bcma_device, dev);
355 return add_uevent_var(env,
356 "MODALIAS=bcma:m%04Xid%04Xrev%02Xcl%02X",
357 core->id.manuf, core->id.id,
358 core->id.rev, core->id.class);
361 static int __init bcma_modinit(void)
363 int err;
365 err = bus_register(&bcma_bus_type);
366 if (err)
367 return err;
369 #ifdef CONFIG_BCMA_HOST_PCI
370 err = bcma_host_pci_init();
371 if (err) {
372 pr_err("PCI host initialization failed\n");
373 err = 0;
375 #endif
377 return err;
379 fs_initcall(bcma_modinit);
381 static void __exit bcma_modexit(void)
383 #ifdef CONFIG_BCMA_HOST_PCI
384 bcma_host_pci_exit();
385 #endif
386 bus_unregister(&bcma_bus_type);
388 module_exit(bcma_modexit)