Commit | Line | Data |
---|---|---|
8369ae33 RM |
1 | /* |
2 | * Broadcom specific AMBA | |
3 | * Bus subsystem | |
4 | * | |
5 | * Licensed under the GNU/GPL. See COPYING for details. | |
6 | */ | |
7 | ||
8 | #include "bcma_private.h" | |
200351c7 | 9 | #include <linux/module.h> |
d57ef3a6 | 10 | #include <linux/platform_device.h> |
8369ae33 | 11 | #include <linux/bcma/bcma.h> |
eef72699 | 12 | #include <linux/slab.h> |
2101e533 | 13 | #include <linux/of_address.h> |
8369ae33 RM |
14 | |
15 | MODULE_DESCRIPTION("Broadcom's specific AMBA driver"); | |
16 | MODULE_LICENSE("GPL"); | |
17 | ||
8f9ada4f HM |
18 | /* contains the number the next bus should get. */ |
19 | static unsigned int bcma_bus_next_num = 0; | |
20 | ||
21 | /* bcma_buses_mutex locks the bcma_bus_next_num */ | |
22 | static DEFINE_MUTEX(bcma_buses_mutex); | |
23 | ||
8369ae33 RM |
24 | static int bcma_bus_match(struct device *dev, struct device_driver *drv); |
25 | static int bcma_device_probe(struct device *dev); | |
26 | static int bcma_device_remove(struct device *dev); | |
886b66ef | 27 | static int bcma_device_uevent(struct device *dev, struct kobj_uevent_env *env); |
8369ae33 RM |
28 | |
29 | static ssize_t manuf_show(struct device *dev, struct device_attribute *attr, char *buf) | |
30 | { | |
31 | struct bcma_device *core = container_of(dev, struct bcma_device, dev); | |
32 | return sprintf(buf, "0x%03X\n", core->id.manuf); | |
33 | } | |
fdcf4f81 GKH |
34 | static DEVICE_ATTR_RO(manuf); |
35 | ||
8369ae33 RM |
36 | static ssize_t id_show(struct device *dev, struct device_attribute *attr, char *buf) |
37 | { | |
38 | struct bcma_device *core = container_of(dev, struct bcma_device, dev); | |
39 | return sprintf(buf, "0x%03X\n", core->id.id); | |
40 | } | |
fdcf4f81 GKH |
41 | static DEVICE_ATTR_RO(id); |
42 | ||
8369ae33 RM |
43 | static ssize_t rev_show(struct device *dev, struct device_attribute *attr, char *buf) |
44 | { | |
45 | struct bcma_device *core = container_of(dev, struct bcma_device, dev); | |
46 | return sprintf(buf, "0x%02X\n", core->id.rev); | |
47 | } | |
fdcf4f81 GKH |
48 | static DEVICE_ATTR_RO(rev); |
49 | ||
8369ae33 RM |
50 | static ssize_t class_show(struct device *dev, struct device_attribute *attr, char *buf) |
51 | { | |
52 | struct bcma_device *core = container_of(dev, struct bcma_device, dev); | |
53 | return sprintf(buf, "0x%X\n", core->id.class); | |
54 | } | |
fdcf4f81 GKH |
55 | static DEVICE_ATTR_RO(class); |
56 | ||
57 | static struct attribute *bcma_device_attrs[] = { | |
58 | &dev_attr_manuf.attr, | |
59 | &dev_attr_id.attr, | |
60 | &dev_attr_rev.attr, | |
61 | &dev_attr_class.attr, | |
62 | NULL, | |
8369ae33 | 63 | }; |
fdcf4f81 | 64 | ATTRIBUTE_GROUPS(bcma_device); |
8369ae33 RM |
65 | |
66 | static struct bus_type bcma_bus_type = { | |
67 | .name = "bcma", | |
68 | .match = bcma_bus_match, | |
69 | .probe = bcma_device_probe, | |
70 | .remove = bcma_device_remove, | |
886b66ef | 71 | .uevent = bcma_device_uevent, |
fdcf4f81 | 72 | .dev_groups = bcma_device_groups, |
8369ae33 RM |
73 | }; |
74 | ||
6d5cfc9f RM |
75 | static u16 bcma_cc_core_id(struct bcma_bus *bus) |
76 | { | |
77 | if (bus->chipinfo.id == BCMA_CHIP_ID_BCM4706) | |
78 | return BCMA_CORE_4706_CHIPCOMMON; | |
79 | return BCMA_CORE_CHIPCOMMON; | |
80 | } | |
81 | ||
929a03ae HM |
82 | struct bcma_device *bcma_find_core_unit(struct bcma_bus *bus, u16 coreid, |
83 | u8 unit) | |
dfae7143 HM |
84 | { |
85 | struct bcma_device *core; | |
86 | ||
87 | list_for_each_entry(core, &bus->cores, list) { | |
88 | if (core->id.id == coreid && core->core_unit == unit) | |
89 | return core; | |
90 | } | |
91 | return NULL; | |
92 | } | |
b2395b8a | 93 | EXPORT_SYMBOL_GPL(bcma_find_core_unit); |
dfae7143 | 94 | |
88f9b65d RM |
95 | bool bcma_wait_value(struct bcma_device *core, u16 reg, u32 mask, u32 value, |
96 | int timeout) | |
97 | { | |
98 | unsigned long deadline = jiffies + timeout; | |
99 | u32 val; | |
100 | ||
101 | do { | |
102 | val = bcma_read32(core, reg); | |
103 | if ((val & mask) == value) | |
104 | return true; | |
105 | cpu_relax(); | |
106 | udelay(10); | |
107 | } while (!time_after_eq(jiffies, deadline)); | |
108 | ||
109 | bcma_warn(core->bus, "Timeout waiting for register 0x%04X!\n", reg); | |
110 | ||
111 | return false; | |
112 | } | |
113 | ||
8369ae33 RM |
114 | static void bcma_release_core_dev(struct device *dev) |
115 | { | |
116 | struct bcma_device *core = container_of(dev, struct bcma_device, dev); | |
ecd177c2 HM |
117 | if (core->io_addr) |
118 | iounmap(core->io_addr); | |
119 | if (core->io_wrap) | |
120 | iounmap(core->io_wrap); | |
8369ae33 RM |
121 | kfree(core); |
122 | } | |
123 | ||
37a7f876 RM |
124 | static bool bcma_is_core_needed_early(u16 core_id) |
125 | { | |
126 | switch (core_id) { | |
127 | case BCMA_CORE_NS_NAND: | |
128 | case BCMA_CORE_NS_QSPI: | |
129 | return true; | |
130 | } | |
131 | ||
132 | return false; | |
133 | } | |
134 | ||
2101e533 HM |
135 | #ifdef CONFIG_OF |
136 | static struct device_node *bcma_of_find_child_device(struct platform_device *parent, | |
137 | struct bcma_device *core) | |
138 | { | |
139 | struct device_node *node; | |
140 | u64 size; | |
141 | const __be32 *reg; | |
142 | ||
143 | if (!parent || !parent->dev.of_node) | |
144 | return NULL; | |
145 | ||
146 | for_each_child_of_node(parent->dev.of_node, node) { | |
147 | reg = of_get_address(node, 0, &size, NULL); | |
148 | if (!reg) | |
149 | continue; | |
150 | if (of_translate_address(node, reg) == core->addr) | |
151 | return node; | |
152 | } | |
153 | return NULL; | |
154 | } | |
155 | ||
156 | static void bcma_of_fill_device(struct platform_device *parent, | |
157 | struct bcma_device *core) | |
158 | { | |
159 | struct device_node *node; | |
160 | ||
161 | node = bcma_of_find_child_device(parent, core); | |
162 | if (node) | |
163 | core->dev.of_node = node; | |
164 | } | |
165 | #else | |
166 | static void bcma_of_fill_device(struct platform_device *parent, | |
167 | struct bcma_device *core) | |
168 | { | |
169 | } | |
170 | #endif /* CONFIG_OF */ | |
171 | ||
ab54bc84 | 172 | void bcma_prepare_core(struct bcma_bus *bus, struct bcma_device *core) |
6e094bd8 | 173 | { |
6e094bd8 RM |
174 | core->dev.release = bcma_release_core_dev; |
175 | core->dev.bus = &bcma_bus_type; | |
176 | dev_set_name(&core->dev, "bcma%d:%d", bus->num, core->core_index); | |
177 | ||
178 | switch (bus->hosttype) { | |
179 | case BCMA_HOSTTYPE_PCI: | |
180 | core->dev.parent = &bus->host_pci->dev; | |
181 | core->dma_dev = &bus->host_pci->dev; | |
182 | core->irq = bus->host_pci->irq; | |
183 | break; | |
184 | case BCMA_HOSTTYPE_SOC: | |
185 | core->dev.dma_mask = &core->dev.coherent_dma_mask; | |
2101e533 HM |
186 | if (bus->host_pdev) { |
187 | core->dma_dev = &bus->host_pdev->dev; | |
188 | core->dev.parent = &bus->host_pdev->dev; | |
189 | bcma_of_fill_device(bus->host_pdev, core); | |
190 | } else { | |
191 | core->dma_dev = &core->dev; | |
192 | } | |
6e094bd8 RM |
193 | break; |
194 | case BCMA_HOSTTYPE_SDIO: | |
195 | break; | |
196 | } | |
ab54bc84 RM |
197 | } |
198 | ||
199 | static void bcma_register_core(struct bcma_bus *bus, struct bcma_device *core) | |
200 | { | |
201 | int err; | |
6e094bd8 RM |
202 | |
203 | err = device_register(&core->dev); | |
204 | if (err) { | |
205 | bcma_err(bus, "Could not register dev for core 0x%03X\n", | |
206 | core->id.id); | |
207 | put_device(&core->dev); | |
208 | return; | |
209 | } | |
210 | core->dev_registered = true; | |
211 | } | |
212 | ||
213 | static int bcma_register_devices(struct bcma_bus *bus) | |
8369ae33 RM |
214 | { |
215 | struct bcma_device *core; | |
6e094bd8 | 216 | int err; |
8369ae33 RM |
217 | |
218 | list_for_each_entry(core, &bus->cores, list) { | |
219 | /* We support that cores ourself */ | |
220 | switch (core->id.id) { | |
6d5cfc9f | 221 | case BCMA_CORE_4706_CHIPCOMMON: |
8369ae33 | 222 | case BCMA_CORE_CHIPCOMMON: |
1716bcf3 | 223 | case BCMA_CORE_NS_CHIPCOMMON_B: |
8369ae33 RM |
224 | case BCMA_CORE_PCI: |
225 | case BCMA_CORE_PCIE: | |
f473832f | 226 | case BCMA_CORE_PCIE2: |
21e0534a | 227 | case BCMA_CORE_MIPS_74K: |
e1ac4b40 | 228 | case BCMA_CORE_4706_MAC_GBIT_COMMON: |
8369ae33 RM |
229 | continue; |
230 | } | |
231 | ||
37a7f876 RM |
232 | /* Early cores were already registered */ |
233 | if (bcma_is_core_needed_early(core->id.id)) | |
234 | continue; | |
235 | ||
10419d08 RM |
236 | /* Only first GMAC core on BCM4706 is connected and working */ |
237 | if (core->id.id == BCMA_CORE_4706_MAC_GBIT && | |
238 | core->core_unit > 0) | |
239 | continue; | |
240 | ||
6e094bd8 | 241 | bcma_register_core(bus, core); |
8369ae33 RM |
242 | } |
243 | ||
73e4dbe4 RM |
244 | #ifdef CONFIG_BCMA_DRIVER_MIPS |
245 | if (bus->drv_cc.pflash.present) { | |
246 | err = platform_device_register(&bcma_pflash_dev); | |
247 | if (err) | |
248 | bcma_err(bus, "Error registering parallel flash\n"); | |
249 | } | |
250 | #endif | |
251 | ||
d57ef3a6 RM |
252 | #ifdef CONFIG_BCMA_SFLASH |
253 | if (bus->drv_cc.sflash.present) { | |
254 | err = platform_device_register(&bcma_sflash_dev); | |
255 | if (err) | |
256 | bcma_err(bus, "Error registering serial flash\n"); | |
257 | } | |
258 | #endif | |
259 | ||
371a0044 RM |
260 | #ifdef CONFIG_BCMA_NFLASH |
261 | if (bus->drv_cc.nflash.present) { | |
262 | err = platform_device_register(&bcma_nflash_dev); | |
263 | if (err) | |
264 | bcma_err(bus, "Error registering NAND flash\n"); | |
265 | } | |
266 | #endif | |
cf0936b0 HM |
267 | err = bcma_gpio_init(&bus->drv_cc); |
268 | if (err == -ENOTSUPP) | |
269 | bcma_debug(bus, "GPIO driver not activated\n"); | |
270 | else if (err) | |
271 | bcma_err(bus, "Error registering GPIO driver: %i\n", err); | |
371a0044 | 272 | |
a4855f39 HM |
273 | if (bus->hosttype == BCMA_HOSTTYPE_SOC) { |
274 | err = bcma_chipco_watchdog_register(&bus->drv_cc); | |
275 | if (err) | |
276 | bcma_err(bus, "Error registering watchdog driver\n"); | |
277 | } | |
278 | ||
8369ae33 RM |
279 | return 0; |
280 | } | |
281 | ||
282 | static void bcma_unregister_cores(struct bcma_bus *bus) | |
283 | { | |
1fffa905 | 284 | struct bcma_device *core, *tmp; |
8369ae33 | 285 | |
1fffa905 PH |
286 | list_for_each_entry_safe(core, tmp, &bus->cores, list) { |
287 | list_del(&core->list); | |
8369ae33 RM |
288 | if (core->dev_registered) |
289 | device_unregister(&core->dev); | |
290 | } | |
a4855f39 HM |
291 | if (bus->hosttype == BCMA_HOSTTYPE_SOC) |
292 | platform_device_unregister(bus->drv_cc.watchdog); | |
8369ae33 RM |
293 | } |
294 | ||
0f58a01d | 295 | int bcma_bus_register(struct bcma_bus *bus) |
8369ae33 RM |
296 | { |
297 | int err; | |
298 | struct bcma_device *core; | |
299 | ||
8f9ada4f HM |
300 | mutex_lock(&bcma_buses_mutex); |
301 | bus->num = bcma_bus_next_num++; | |
302 | mutex_unlock(&bcma_buses_mutex); | |
303 | ||
8369ae33 RM |
304 | /* Scan for devices (cores) */ |
305 | err = bcma_bus_scan(bus); | |
306 | if (err) { | |
3d9d8af3 | 307 | bcma_err(bus, "Failed to scan: %d\n", err); |
1cabf7db | 308 | return err; |
8369ae33 RM |
309 | } |
310 | ||
30cfb023 HM |
311 | /* Early init CC core */ |
312 | core = bcma_find_core(bus, bcma_cc_core_id(bus)); | |
313 | if (core) { | |
314 | bus->drv_cc.core = core; | |
315 | bcma_core_chipcommon_early_init(&bus->drv_cc); | |
316 | } | |
317 | ||
37a7f876 RM |
318 | /* Cores providing flash access go before SPROM init */ |
319 | list_for_each_entry(core, &bus->cores, list) { | |
320 | if (bcma_is_core_needed_early(core->id.id)) | |
321 | bcma_register_core(bus, core); | |
322 | } | |
323 | ||
30cfb023 HM |
324 | /* Try to get SPROM */ |
325 | err = bcma_sprom_get(bus); | |
326 | if (err == -ENOENT) { | |
327 | bcma_err(bus, "No SPROM available\n"); | |
328 | } else if (err) | |
329 | bcma_err(bus, "Failed to get SPROM: %d\n", err); | |
330 | ||
8369ae33 | 331 | /* Init CC core */ |
6d5cfc9f | 332 | core = bcma_find_core(bus, bcma_cc_core_id(bus)); |
8369ae33 RM |
333 | if (core) { |
334 | bus->drv_cc.core = core; | |
335 | bcma_core_chipcommon_init(&bus->drv_cc); | |
336 | } | |
337 | ||
1716bcf3 HM |
338 | /* Init CC core */ |
339 | core = bcma_find_core(bus, BCMA_CORE_NS_CHIPCOMMON_B); | |
340 | if (core) { | |
341 | bus->drv_cc_b.core = core; | |
342 | bcma_core_chipcommon_b_init(&bus->drv_cc_b); | |
343 | } | |
344 | ||
21e0534a HM |
345 | /* Init MIPS core */ |
346 | core = bcma_find_core(bus, BCMA_CORE_MIPS_74K); | |
347 | if (core) { | |
348 | bus->drv_mips.core = core; | |
349 | bcma_core_mips_init(&bus->drv_mips); | |
350 | } | |
351 | ||
8369ae33 | 352 | /* Init PCIE core */ |
dfae7143 HM |
353 | core = bcma_find_core_unit(bus, BCMA_CORE_PCIE, 0); |
354 | if (core) { | |
355 | bus->drv_pci[0].core = core; | |
356 | bcma_core_pci_init(&bus->drv_pci[0]); | |
357 | } | |
358 | ||
359 | /* Init PCIE core */ | |
360 | core = bcma_find_core_unit(bus, BCMA_CORE_PCIE, 1); | |
8369ae33 | 361 | if (core) { |
dfae7143 HM |
362 | bus->drv_pci[1].core = core; |
363 | bcma_core_pci_init(&bus->drv_pci[1]); | |
8369ae33 RM |
364 | } |
365 | ||
f473832f RM |
366 | /* Init PCIe Gen 2 core */ |
367 | core = bcma_find_core_unit(bus, BCMA_CORE_PCIE2, 0); | |
368 | if (core) { | |
369 | bus->drv_pcie2.core = core; | |
370 | bcma_core_pcie2_init(&bus->drv_pcie2); | |
371 | } | |
372 | ||
e1ac4b40 RM |
373 | /* Init GBIT MAC COMMON core */ |
374 | core = bcma_find_core(bus, BCMA_CORE_4706_MAC_GBIT_COMMON); | |
375 | if (core) { | |
376 | bus->drv_gmac_cmn.core = core; | |
377 | bcma_core_gmac_cmn_init(&bus->drv_gmac_cmn); | |
378 | } | |
379 | ||
8369ae33 | 380 | /* Register found cores */ |
6e094bd8 | 381 | bcma_register_devices(bus); |
8369ae33 | 382 | |
3d9d8af3 | 383 | bcma_info(bus, "Bus registered\n"); |
8369ae33 RM |
384 | |
385 | return 0; | |
386 | } | |
8369ae33 RM |
387 | |
388 | void bcma_bus_unregister(struct bcma_bus *bus) | |
389 | { | |
ee915927 | 390 | struct bcma_device *cores[3]; |
c50ae947 HM |
391 | int err; |
392 | ||
393 | err = bcma_gpio_unregister(&bus->drv_cc); | |
394 | if (err == -EBUSY) | |
395 | bcma_err(bus, "Some GPIOs are still in use.\n"); | |
396 | else if (err) | |
397 | bcma_err(bus, "Can not unregister GPIO driver: %i\n", err); | |
ee915927 | 398 | |
1716bcf3 HM |
399 | bcma_core_chipcommon_b_free(&bus->drv_cc_b); |
400 | ||
ee915927 SSJ |
401 | cores[0] = bcma_find_core(bus, BCMA_CORE_MIPS_74K); |
402 | cores[1] = bcma_find_core(bus, BCMA_CORE_PCIE); | |
403 | cores[2] = bcma_find_core(bus, BCMA_CORE_4706_MAC_GBIT_COMMON); | |
404 | ||
8369ae33 | 405 | bcma_unregister_cores(bus); |
ee915927 SSJ |
406 | |
407 | kfree(cores[2]); | |
408 | kfree(cores[1]); | |
409 | kfree(cores[0]); | |
8369ae33 | 410 | } |
8369ae33 | 411 | |
517f43e5 HM |
412 | int __init bcma_bus_early_register(struct bcma_bus *bus, |
413 | struct bcma_device *core_cc, | |
414 | struct bcma_device *core_mips) | |
415 | { | |
416 | int err; | |
417 | struct bcma_device *core; | |
418 | struct bcma_device_id match; | |
419 | ||
517f43e5 | 420 | match.manuf = BCMA_MANUF_BCM; |
6d5cfc9f | 421 | match.id = bcma_cc_core_id(bus); |
517f43e5 HM |
422 | match.class = BCMA_CL_SIM; |
423 | match.rev = BCMA_ANY_REV; | |
424 | ||
425 | /* Scan for chip common core */ | |
426 | err = bcma_bus_scan_early(bus, &match, core_cc); | |
427 | if (err) { | |
3d9d8af3 | 428 | bcma_err(bus, "Failed to scan for common core: %d\n", err); |
517f43e5 HM |
429 | return -1; |
430 | } | |
431 | ||
432 | match.manuf = BCMA_MANUF_MIPS; | |
433 | match.id = BCMA_CORE_MIPS_74K; | |
434 | match.class = BCMA_CL_SIM; | |
435 | match.rev = BCMA_ANY_REV; | |
436 | ||
437 | /* Scan for mips core */ | |
438 | err = bcma_bus_scan_early(bus, &match, core_mips); | |
439 | if (err) { | |
3d9d8af3 | 440 | bcma_err(bus, "Failed to scan for mips core: %d\n", err); |
517f43e5 HM |
441 | return -1; |
442 | } | |
443 | ||
49655bb8 | 444 | /* Early init CC core */ |
6d5cfc9f | 445 | core = bcma_find_core(bus, bcma_cc_core_id(bus)); |
517f43e5 HM |
446 | if (core) { |
447 | bus->drv_cc.core = core; | |
49655bb8 | 448 | bcma_core_chipcommon_early_init(&bus->drv_cc); |
517f43e5 HM |
449 | } |
450 | ||
49655bb8 | 451 | /* Early init MIPS core */ |
21e0534a HM |
452 | core = bcma_find_core(bus, BCMA_CORE_MIPS_74K); |
453 | if (core) { | |
454 | bus->drv_mips.core = core; | |
49655bb8 | 455 | bcma_core_mips_early_init(&bus->drv_mips); |
21e0534a HM |
456 | } |
457 | ||
3d9d8af3 | 458 | bcma_info(bus, "Early bus registered\n"); |
517f43e5 HM |
459 | |
460 | return 0; | |
461 | } | |
462 | ||
775ab521 | 463 | #ifdef CONFIG_PM |
685a4ef0 LT |
464 | int bcma_bus_suspend(struct bcma_bus *bus) |
465 | { | |
7d5869e7 LT |
466 | struct bcma_device *core; |
467 | ||
468 | list_for_each_entry(core, &bus->cores, list) { | |
469 | struct device_driver *drv = core->dev.driver; | |
470 | if (drv) { | |
471 | struct bcma_driver *adrv = container_of(drv, struct bcma_driver, drv); | |
472 | if (adrv->suspend) | |
473 | adrv->suspend(core); | |
474 | } | |
475 | } | |
685a4ef0 LT |
476 | return 0; |
477 | } | |
478 | ||
775ab521 RM |
479 | int bcma_bus_resume(struct bcma_bus *bus) |
480 | { | |
481 | struct bcma_device *core; | |
482 | ||
483 | /* Init CC core */ | |
6d5cfc9f | 484 | if (bus->drv_cc.core) { |
775ab521 RM |
485 | bus->drv_cc.setup_done = false; |
486 | bcma_core_chipcommon_init(&bus->drv_cc); | |
487 | } | |
488 | ||
7d5869e7 LT |
489 | list_for_each_entry(core, &bus->cores, list) { |
490 | struct device_driver *drv = core->dev.driver; | |
491 | if (drv) { | |
492 | struct bcma_driver *adrv = container_of(drv, struct bcma_driver, drv); | |
493 | if (adrv->resume) | |
494 | adrv->resume(core); | |
495 | } | |
496 | } | |
497 | ||
775ab521 RM |
498 | return 0; |
499 | } | |
500 | #endif | |
501 | ||
8369ae33 RM |
502 | int __bcma_driver_register(struct bcma_driver *drv, struct module *owner) |
503 | { | |
504 | drv->drv.name = drv->name; | |
505 | drv->drv.bus = &bcma_bus_type; | |
506 | drv->drv.owner = owner; | |
507 | ||
508 | return driver_register(&drv->drv); | |
509 | } | |
510 | EXPORT_SYMBOL_GPL(__bcma_driver_register); | |
511 | ||
512 | void bcma_driver_unregister(struct bcma_driver *drv) | |
513 | { | |
514 | driver_unregister(&drv->drv); | |
515 | } | |
516 | EXPORT_SYMBOL_GPL(bcma_driver_unregister); | |
517 | ||
518 | static int bcma_bus_match(struct device *dev, struct device_driver *drv) | |
519 | { | |
520 | struct bcma_device *core = container_of(dev, struct bcma_device, dev); | |
521 | struct bcma_driver *adrv = container_of(drv, struct bcma_driver, drv); | |
522 | const struct bcma_device_id *cid = &core->id; | |
523 | const struct bcma_device_id *did; | |
524 | ||
525 | for (did = adrv->id_table; did->manuf || did->id || did->rev; did++) { | |
526 | if ((did->manuf == cid->manuf || did->manuf == BCMA_ANY_MANUF) && | |
527 | (did->id == cid->id || did->id == BCMA_ANY_ID) && | |
528 | (did->rev == cid->rev || did->rev == BCMA_ANY_REV) && | |
529 | (did->class == cid->class || did->class == BCMA_ANY_CLASS)) | |
530 | return 1; | |
531 | } | |
532 | return 0; | |
533 | } | |
534 | ||
535 | static int bcma_device_probe(struct device *dev) | |
536 | { | |
537 | struct bcma_device *core = container_of(dev, struct bcma_device, dev); | |
538 | struct bcma_driver *adrv = container_of(dev->driver, struct bcma_driver, | |
539 | drv); | |
540 | int err = 0; | |
541 | ||
542 | if (adrv->probe) | |
543 | err = adrv->probe(core); | |
544 | ||
545 | return err; | |
546 | } | |
547 | ||
548 | static int bcma_device_remove(struct device *dev) | |
549 | { | |
550 | struct bcma_device *core = container_of(dev, struct bcma_device, dev); | |
551 | struct bcma_driver *adrv = container_of(dev->driver, struct bcma_driver, | |
552 | drv); | |
553 | ||
554 | if (adrv->remove) | |
555 | adrv->remove(core); | |
556 | ||
557 | return 0; | |
558 | } | |
559 | ||
886b66ef DW |
560 | static int bcma_device_uevent(struct device *dev, struct kobj_uevent_env *env) |
561 | { | |
562 | struct bcma_device *core = container_of(dev, struct bcma_device, dev); | |
563 | ||
564 | return add_uevent_var(env, | |
565 | "MODALIAS=bcma:m%04Xid%04Xrev%02Xcl%02X", | |
566 | core->id.manuf, core->id.id, | |
567 | core->id.rev, core->id.class); | |
568 | } | |
569 | ||
8369ae33 RM |
570 | static int __init bcma_modinit(void) |
571 | { | |
572 | int err; | |
573 | ||
574 | err = bus_register(&bcma_bus_type); | |
575 | if (err) | |
576 | return err; | |
577 | ||
2101e533 HM |
578 | err = bcma_host_soc_register_driver(); |
579 | if (err) { | |
580 | pr_err("SoC host initialization failed\n"); | |
581 | err = 0; | |
582 | } | |
8369ae33 RM |
583 | #ifdef CONFIG_BCMA_HOST_PCI |
584 | err = bcma_host_pci_init(); | |
585 | if (err) { | |
586 | pr_err("PCI host initialization failed\n"); | |
587 | err = 0; | |
588 | } | |
589 | #endif | |
590 | ||
591 | return err; | |
592 | } | |
593 | fs_initcall(bcma_modinit); | |
594 | ||
595 | static void __exit bcma_modexit(void) | |
596 | { | |
597 | #ifdef CONFIG_BCMA_HOST_PCI | |
598 | bcma_host_pci_exit(); | |
599 | #endif | |
2101e533 | 600 | bcma_host_soc_unregister_driver(); |
8369ae33 RM |
601 | bus_unregister(&bcma_bus_type); |
602 | } | |
603 | module_exit(bcma_modexit) |