blob: 6d1cf57014521d73c3d66657d8aeb30a2c504b95 [file] [log] [blame]
Rafał Miłecki8369ae32011-05-09 18:56:46 +02001/*
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"
Paul Gortmaker200351c2011-07-01 16:06:37 -04009#include <linux/module.h>
Rafał Miłeckid57ef3a2012-08-10 21:23:53 +020010#include <linux/platform_device.h>
Rafał Miłecki8369ae32011-05-09 18:56:46 +020011#include <linux/bcma/bcma.h>
Geert Uytterhoeveneef72692011-06-26 10:19:44 +020012#include <linux/slab.h>
Hauke Mehrtens2101e532014-09-26 00:09:19 +020013#include <linux/of_address.h>
Rafał Miłecki8369ae32011-05-09 18:56:46 +020014
15MODULE_DESCRIPTION("Broadcom's specific AMBA driver");
16MODULE_LICENSE("GPL");
17
Hauke Mehrtens8f9ada42012-01-31 00:03:36 +010018/* contains the number the next bus should get. */
19static unsigned int bcma_bus_next_num = 0;
20
21/* bcma_buses_mutex locks the bcma_bus_next_num */
22static DEFINE_MUTEX(bcma_buses_mutex);
23
Rafał Miłecki8369ae32011-05-09 18:56:46 +020024static int bcma_bus_match(struct device *dev, struct device_driver *drv);
25static int bcma_device_probe(struct device *dev);
26static int bcma_device_remove(struct device *dev);
David Woodhouse886b66e2011-08-19 22:14:47 +020027static int bcma_device_uevent(struct device *dev, struct kobj_uevent_env *env);
Rafał Miłecki8369ae32011-05-09 18:56:46 +020028
29static 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}
Greg Kroah-Hartmanfdcf4f82013-10-06 23:55:45 -070034static DEVICE_ATTR_RO(manuf);
35
Rafał Miłecki8369ae32011-05-09 18:56:46 +020036static 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}
Greg Kroah-Hartmanfdcf4f82013-10-06 23:55:45 -070041static DEVICE_ATTR_RO(id);
42
Rafał Miłecki8369ae32011-05-09 18:56:46 +020043static 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}
Greg Kroah-Hartmanfdcf4f82013-10-06 23:55:45 -070048static DEVICE_ATTR_RO(rev);
49
Rafał Miłecki8369ae32011-05-09 18:56:46 +020050static 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}
Greg Kroah-Hartmanfdcf4f82013-10-06 23:55:45 -070055static DEVICE_ATTR_RO(class);
56
57static 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,
Rafał Miłecki8369ae32011-05-09 18:56:46 +020063};
Greg Kroah-Hartmanfdcf4f82013-10-06 23:55:45 -070064ATTRIBUTE_GROUPS(bcma_device);
Rafał Miłecki8369ae32011-05-09 18:56:46 +020065
66static struct bus_type bcma_bus_type = {
67 .name = "bcma",
68 .match = bcma_bus_match,
69 .probe = bcma_device_probe,
70 .remove = bcma_device_remove,
David Woodhouse886b66e2011-08-19 22:14:47 +020071 .uevent = bcma_device_uevent,
Greg Kroah-Hartmanfdcf4f82013-10-06 23:55:45 -070072 .dev_groups = bcma_device_groups,
Rafał Miłecki8369ae32011-05-09 18:56:46 +020073};
74
Rafał Miłecki6d5cfc92012-07-10 23:45:49 +020075static 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
Hauke Mehrtens929a03a2013-01-04 00:51:20 +010082struct bcma_device *bcma_find_core_unit(struct bcma_bus *bus, u16 coreid,
83 u8 unit)
Hauke Mehrtensdfae7142012-09-29 20:40:18 +020084{
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}
Hauke Mehrtensb2395b82014-01-05 01:10:43 +010093EXPORT_SYMBOL_GPL(bcma_find_core_unit);
Hauke Mehrtensdfae7142012-09-29 20:40:18 +020094
Rafał Miłecki88f9b652013-06-26 10:02:11 +020095bool 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
Rafał Miłecki8369ae32011-05-09 18:56:46 +0200114static void bcma_release_core_dev(struct device *dev)
115{
116 struct bcma_device *core = container_of(dev, struct bcma_device, dev);
Hauke Mehrtensecd177c2011-07-23 01:20:08 +0200117 if (core->io_addr)
118 iounmap(core->io_addr);
119 if (core->io_wrap)
120 iounmap(core->io_wrap);
Rafał Miłecki8369ae32011-05-09 18:56:46 +0200121 kfree(core);
122}
123
Rafał Miłecki37a7f872014-09-05 00:18:49 +0200124static 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
Hauke Mehrtens2101e532014-09-26 00:09:19 +0200135#ifdef CONFIG_OF
136static 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
156static 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
166static void bcma_of_fill_device(struct platform_device *parent,
167 struct bcma_device *core)
168{
169}
170#endif /* CONFIG_OF */
171
Hauke Mehrtens85eb92e2014-11-01 16:54:55 +0100172unsigned int bcma_core_irq(struct bcma_device *core, int num)
173{
174 struct bcma_bus *bus = core->bus;
175 unsigned int mips_irq;
176
177 switch (bus->hosttype) {
178 case BCMA_HOSTTYPE_PCI:
179 return bus->host_pci->irq;
180 case BCMA_HOSTTYPE_SOC:
181 if (bus->drv_mips.core && num == 0) {
182 mips_irq = bcma_core_mips_irq(core);
183 return mips_irq <= 4 ? mips_irq + 2 : 0;
184 }
185 break;
186 case BCMA_HOSTTYPE_SDIO:
187 return 0;
188 }
189
190 return 0;
191}
192EXPORT_SYMBOL(bcma_core_irq);
193
Rafał Miłeckiab54bc82014-10-03 17:00:24 +0200194void bcma_prepare_core(struct bcma_bus *bus, struct bcma_device *core)
Rafał Miłecki6e094bd2014-09-05 00:18:48 +0200195{
Rafał Miłecki6e094bd2014-09-05 00:18:48 +0200196 core->dev.release = bcma_release_core_dev;
197 core->dev.bus = &bcma_bus_type;
198 dev_set_name(&core->dev, "bcma%d:%d", bus->num, core->core_index);
199
200 switch (bus->hosttype) {
201 case BCMA_HOSTTYPE_PCI:
202 core->dev.parent = &bus->host_pci->dev;
203 core->dma_dev = &bus->host_pci->dev;
204 core->irq = bus->host_pci->irq;
205 break;
206 case BCMA_HOSTTYPE_SOC:
207 core->dev.dma_mask = &core->dev.coherent_dma_mask;
Hauke Mehrtens2101e532014-09-26 00:09:19 +0200208 if (bus->host_pdev) {
209 core->dma_dev = &bus->host_pdev->dev;
210 core->dev.parent = &bus->host_pdev->dev;
211 bcma_of_fill_device(bus->host_pdev, core);
212 } else {
213 core->dma_dev = &core->dev;
214 }
Rafał Miłecki6e094bd2014-09-05 00:18:48 +0200215 break;
216 case BCMA_HOSTTYPE_SDIO:
217 break;
218 }
Rafał Miłeckiab54bc82014-10-03 17:00:24 +0200219}
220
221static void bcma_register_core(struct bcma_bus *bus, struct bcma_device *core)
222{
223 int err;
Rafał Miłecki6e094bd2014-09-05 00:18:48 +0200224
225 err = device_register(&core->dev);
226 if (err) {
227 bcma_err(bus, "Could not register dev for core 0x%03X\n",
228 core->id.id);
229 put_device(&core->dev);
230 return;
231 }
232 core->dev_registered = true;
233}
234
235static int bcma_register_devices(struct bcma_bus *bus)
Rafał Miłecki8369ae32011-05-09 18:56:46 +0200236{
237 struct bcma_device *core;
Rafał Miłecki6e094bd2014-09-05 00:18:48 +0200238 int err;
Rafał Miłecki8369ae32011-05-09 18:56:46 +0200239
240 list_for_each_entry(core, &bus->cores, list) {
241 /* We support that cores ourself */
242 switch (core->id.id) {
Rafał Miłecki6d5cfc92012-07-10 23:45:49 +0200243 case BCMA_CORE_4706_CHIPCOMMON:
Rafał Miłecki8369ae32011-05-09 18:56:46 +0200244 case BCMA_CORE_CHIPCOMMON:
Hauke Mehrtens1716bcf2014-09-08 22:53:36 +0200245 case BCMA_CORE_NS_CHIPCOMMON_B:
Rafał Miłecki8369ae32011-05-09 18:56:46 +0200246 case BCMA_CORE_PCI:
247 case BCMA_CORE_PCIE:
Rafał Miłeckif4738322014-07-05 01:10:41 +0200248 case BCMA_CORE_PCIE2:
Hauke Mehrtens21e05342011-07-23 01:20:09 +0200249 case BCMA_CORE_MIPS_74K:
Rafał Miłeckie1ac4b42012-07-11 09:23:43 +0200250 case BCMA_CORE_4706_MAC_GBIT_COMMON:
Rafał Miłecki8369ae32011-05-09 18:56:46 +0200251 continue;
252 }
253
Rafał Miłecki37a7f872014-09-05 00:18:49 +0200254 /* Early cores were already registered */
255 if (bcma_is_core_needed_early(core->id.id))
256 continue;
257
Rafał Miłecki10419d02013-02-19 19:41:42 +0100258 /* Only first GMAC core on BCM4706 is connected and working */
259 if (core->id.id == BCMA_CORE_4706_MAC_GBIT &&
260 core->core_unit > 0)
261 continue;
262
Rafał Miłecki6e094bd2014-09-05 00:18:48 +0200263 bcma_register_core(bus, core);
Rafał Miłecki8369ae32011-05-09 18:56:46 +0200264 }
265
Rafał Miłecki73e4dbe42013-01-25 11:37:26 +0100266#ifdef CONFIG_BCMA_DRIVER_MIPS
267 if (bus->drv_cc.pflash.present) {
268 err = platform_device_register(&bcma_pflash_dev);
269 if (err)
270 bcma_err(bus, "Error registering parallel flash\n");
271 }
272#endif
273
Rafał Miłeckid57ef3a2012-08-10 21:23:53 +0200274#ifdef CONFIG_BCMA_SFLASH
275 if (bus->drv_cc.sflash.present) {
276 err = platform_device_register(&bcma_sflash_dev);
277 if (err)
278 bcma_err(bus, "Error registering serial flash\n");
279 }
280#endif
281
Rafał Miłecki371a0042012-08-12 13:08:05 +0200282#ifdef CONFIG_BCMA_NFLASH
283 if (bus->drv_cc.nflash.present) {
284 err = platform_device_register(&bcma_nflash_dev);
285 if (err)
286 bcma_err(bus, "Error registering NAND flash\n");
287 }
288#endif
Hauke Mehrtenscf0936b2012-11-20 22:24:30 +0000289 err = bcma_gpio_init(&bus->drv_cc);
290 if (err == -ENOTSUPP)
291 bcma_debug(bus, "GPIO driver not activated\n");
292 else if (err)
293 bcma_err(bus, "Error registering GPIO driver: %i\n", err);
Rafał Miłecki371a0042012-08-12 13:08:05 +0200294
Hauke Mehrtensa4855f392012-12-05 18:46:02 +0100295 if (bus->hosttype == BCMA_HOSTTYPE_SOC) {
296 err = bcma_chipco_watchdog_register(&bus->drv_cc);
297 if (err)
298 bcma_err(bus, "Error registering watchdog driver\n");
299 }
300
Rafał Miłecki8369ae32011-05-09 18:56:46 +0200301 return 0;
302}
303
304static void bcma_unregister_cores(struct bcma_bus *bus)
305{
Piotr Haber1fffa902012-10-11 14:05:15 +0200306 struct bcma_device *core, *tmp;
Rafał Miłecki8369ae32011-05-09 18:56:46 +0200307
Piotr Haber1fffa902012-10-11 14:05:15 +0200308 list_for_each_entry_safe(core, tmp, &bus->cores, list) {
309 list_del(&core->list);
Rafał Miłecki8369ae32011-05-09 18:56:46 +0200310 if (core->dev_registered)
311 device_unregister(&core->dev);
312 }
Hauke Mehrtensa4855f392012-12-05 18:46:02 +0100313 if (bus->hosttype == BCMA_HOSTTYPE_SOC)
314 platform_device_unregister(bus->drv_cc.watchdog);
Rafał Miłecki8369ae32011-05-09 18:56:46 +0200315}
316
Greg Kroah-Hartman0f58a012012-12-21 15:12:59 -0800317int bcma_bus_register(struct bcma_bus *bus)
Rafał Miłecki8369ae32011-05-09 18:56:46 +0200318{
319 int err;
320 struct bcma_device *core;
321
Hauke Mehrtens8f9ada42012-01-31 00:03:36 +0100322 mutex_lock(&bcma_buses_mutex);
323 bus->num = bcma_bus_next_num++;
324 mutex_unlock(&bcma_buses_mutex);
325
Rafał Miłecki8369ae32011-05-09 18:56:46 +0200326 /* Scan for devices (cores) */
327 err = bcma_bus_scan(bus);
328 if (err) {
Rafał Miłecki3d9d8af2012-07-05 22:07:32 +0200329 bcma_err(bus, "Failed to scan: %d\n", err);
Hauke Mehrtens1cabf7d2013-07-15 13:15:07 +0200330 return err;
Rafał Miłecki8369ae32011-05-09 18:56:46 +0200331 }
332
Hauke Mehrtens30cfb022012-09-29 20:29:50 +0200333 /* Early init CC core */
334 core = bcma_find_core(bus, bcma_cc_core_id(bus));
335 if (core) {
336 bus->drv_cc.core = core;
337 bcma_core_chipcommon_early_init(&bus->drv_cc);
338 }
339
Rafał Miłecki37a7f872014-09-05 00:18:49 +0200340 /* Cores providing flash access go before SPROM init */
341 list_for_each_entry(core, &bus->cores, list) {
342 if (bcma_is_core_needed_early(core->id.id))
343 bcma_register_core(bus, core);
344 }
345
Hauke Mehrtens30cfb022012-09-29 20:29:50 +0200346 /* Try to get SPROM */
347 err = bcma_sprom_get(bus);
348 if (err == -ENOENT) {
349 bcma_err(bus, "No SPROM available\n");
350 } else if (err)
351 bcma_err(bus, "Failed to get SPROM: %d\n", err);
352
Rafał Miłecki8369ae32011-05-09 18:56:46 +0200353 /* Init CC core */
Rafał Miłecki6d5cfc92012-07-10 23:45:49 +0200354 core = bcma_find_core(bus, bcma_cc_core_id(bus));
Rafał Miłecki8369ae32011-05-09 18:56:46 +0200355 if (core) {
356 bus->drv_cc.core = core;
357 bcma_core_chipcommon_init(&bus->drv_cc);
358 }
359
Hauke Mehrtens1716bcf2014-09-08 22:53:36 +0200360 /* Init CC core */
361 core = bcma_find_core(bus, BCMA_CORE_NS_CHIPCOMMON_B);
362 if (core) {
363 bus->drv_cc_b.core = core;
364 bcma_core_chipcommon_b_init(&bus->drv_cc_b);
365 }
366
Hauke Mehrtens21e05342011-07-23 01:20:09 +0200367 /* Init MIPS core */
368 core = bcma_find_core(bus, BCMA_CORE_MIPS_74K);
369 if (core) {
370 bus->drv_mips.core = core;
371 bcma_core_mips_init(&bus->drv_mips);
372 }
373
Rafał Miłecki8369ae32011-05-09 18:56:46 +0200374 /* Init PCIE core */
Hauke Mehrtensdfae7142012-09-29 20:40:18 +0200375 core = bcma_find_core_unit(bus, BCMA_CORE_PCIE, 0);
Rafał Miłecki8369ae32011-05-09 18:56:46 +0200376 if (core) {
Hauke Mehrtensdfae7142012-09-29 20:40:18 +0200377 bus->drv_pci[0].core = core;
378 bcma_core_pci_init(&bus->drv_pci[0]);
379 }
380
381 /* Init PCIE core */
382 core = bcma_find_core_unit(bus, BCMA_CORE_PCIE, 1);
383 if (core) {
384 bus->drv_pci[1].core = core;
385 bcma_core_pci_init(&bus->drv_pci[1]);
Rafał Miłecki8369ae32011-05-09 18:56:46 +0200386 }
387
Rafał Miłeckif4738322014-07-05 01:10:41 +0200388 /* Init PCIe Gen 2 core */
389 core = bcma_find_core_unit(bus, BCMA_CORE_PCIE2, 0);
390 if (core) {
391 bus->drv_pcie2.core = core;
392 bcma_core_pcie2_init(&bus->drv_pcie2);
393 }
394
Rafał Miłeckie1ac4b42012-07-11 09:23:43 +0200395 /* Init GBIT MAC COMMON core */
396 core = bcma_find_core(bus, BCMA_CORE_4706_MAC_GBIT_COMMON);
397 if (core) {
398 bus->drv_gmac_cmn.core = core;
399 bcma_core_gmac_cmn_init(&bus->drv_gmac_cmn);
400 }
401
Rafał Miłecki8369ae32011-05-09 18:56:46 +0200402 /* Register found cores */
Rafał Miłecki6e094bd2014-09-05 00:18:48 +0200403 bcma_register_devices(bus);
Rafał Miłecki8369ae32011-05-09 18:56:46 +0200404
Rafał Miłecki3d9d8af2012-07-05 22:07:32 +0200405 bcma_info(bus, "Bus registered\n");
Rafał Miłecki8369ae32011-05-09 18:56:46 +0200406
407 return 0;
408}
Rafał Miłecki8369ae32011-05-09 18:56:46 +0200409
410void bcma_bus_unregister(struct bcma_bus *bus)
411{
Saul St. Johnee915922012-08-16 15:42:30 -0500412 struct bcma_device *cores[3];
Hauke Mehrtensc50ae942013-02-03 23:25:33 +0100413 int err;
414
415 err = bcma_gpio_unregister(&bus->drv_cc);
416 if (err == -EBUSY)
417 bcma_err(bus, "Some GPIOs are still in use.\n");
418 else if (err)
419 bcma_err(bus, "Can not unregister GPIO driver: %i\n", err);
Saul St. Johnee915922012-08-16 15:42:30 -0500420
Hauke Mehrtens1716bcf2014-09-08 22:53:36 +0200421 bcma_core_chipcommon_b_free(&bus->drv_cc_b);
422
Saul St. Johnee915922012-08-16 15:42:30 -0500423 cores[0] = bcma_find_core(bus, BCMA_CORE_MIPS_74K);
424 cores[1] = bcma_find_core(bus, BCMA_CORE_PCIE);
425 cores[2] = bcma_find_core(bus, BCMA_CORE_4706_MAC_GBIT_COMMON);
426
Rafał Miłecki8369ae32011-05-09 18:56:46 +0200427 bcma_unregister_cores(bus);
Saul St. Johnee915922012-08-16 15:42:30 -0500428
429 kfree(cores[2]);
430 kfree(cores[1]);
431 kfree(cores[0]);
Rafał Miłecki8369ae32011-05-09 18:56:46 +0200432}
Rafał Miłecki8369ae32011-05-09 18:56:46 +0200433
Hauke Mehrtens517f43e2011-07-23 01:20:07 +0200434int __init bcma_bus_early_register(struct bcma_bus *bus,
435 struct bcma_device *core_cc,
436 struct bcma_device *core_mips)
437{
438 int err;
439 struct bcma_device *core;
440 struct bcma_device_id match;
441
Hauke Mehrtens517f43e2011-07-23 01:20:07 +0200442 match.manuf = BCMA_MANUF_BCM;
Rafał Miłecki6d5cfc92012-07-10 23:45:49 +0200443 match.id = bcma_cc_core_id(bus);
Hauke Mehrtens517f43e2011-07-23 01:20:07 +0200444 match.class = BCMA_CL_SIM;
445 match.rev = BCMA_ANY_REV;
446
447 /* Scan for chip common core */
448 err = bcma_bus_scan_early(bus, &match, core_cc);
449 if (err) {
Rafał Miłecki3d9d8af2012-07-05 22:07:32 +0200450 bcma_err(bus, "Failed to scan for common core: %d\n", err);
Hauke Mehrtens517f43e2011-07-23 01:20:07 +0200451 return -1;
452 }
453
454 match.manuf = BCMA_MANUF_MIPS;
455 match.id = BCMA_CORE_MIPS_74K;
456 match.class = BCMA_CL_SIM;
457 match.rev = BCMA_ANY_REV;
458
459 /* Scan for mips core */
460 err = bcma_bus_scan_early(bus, &match, core_mips);
461 if (err) {
Rafał Miłecki3d9d8af2012-07-05 22:07:32 +0200462 bcma_err(bus, "Failed to scan for mips core: %d\n", err);
Hauke Mehrtens517f43e2011-07-23 01:20:07 +0200463 return -1;
464 }
465
Hauke Mehrtens49655bb2012-09-29 20:29:49 +0200466 /* Early init CC core */
Rafał Miłecki6d5cfc92012-07-10 23:45:49 +0200467 core = bcma_find_core(bus, bcma_cc_core_id(bus));
Hauke Mehrtens517f43e2011-07-23 01:20:07 +0200468 if (core) {
469 bus->drv_cc.core = core;
Hauke Mehrtens49655bb2012-09-29 20:29:49 +0200470 bcma_core_chipcommon_early_init(&bus->drv_cc);
Hauke Mehrtens517f43e2011-07-23 01:20:07 +0200471 }
472
Hauke Mehrtens49655bb2012-09-29 20:29:49 +0200473 /* Early init MIPS core */
Hauke Mehrtens21e05342011-07-23 01:20:09 +0200474 core = bcma_find_core(bus, BCMA_CORE_MIPS_74K);
475 if (core) {
476 bus->drv_mips.core = core;
Hauke Mehrtens49655bb2012-09-29 20:29:49 +0200477 bcma_core_mips_early_init(&bus->drv_mips);
Hauke Mehrtens21e05342011-07-23 01:20:09 +0200478 }
479
Rafał Miłecki3d9d8af2012-07-05 22:07:32 +0200480 bcma_info(bus, "Early bus registered\n");
Hauke Mehrtens517f43e2011-07-23 01:20:07 +0200481
482 return 0;
483}
484
Rafał Miłecki775ab522011-12-09 22:16:07 +0100485#ifdef CONFIG_PM
Linus Torvalds685a4ef2012-01-13 23:58:40 +0100486int bcma_bus_suspend(struct bcma_bus *bus)
487{
Linus Torvalds7d5869e2012-01-13 23:58:41 +0100488 struct bcma_device *core;
489
490 list_for_each_entry(core, &bus->cores, list) {
491 struct device_driver *drv = core->dev.driver;
492 if (drv) {
493 struct bcma_driver *adrv = container_of(drv, struct bcma_driver, drv);
494 if (adrv->suspend)
495 adrv->suspend(core);
496 }
497 }
Linus Torvalds685a4ef2012-01-13 23:58:40 +0100498 return 0;
499}
500
Rafał Miłecki775ab522011-12-09 22:16:07 +0100501int bcma_bus_resume(struct bcma_bus *bus)
502{
503 struct bcma_device *core;
504
505 /* Init CC core */
Rafał Miłecki6d5cfc92012-07-10 23:45:49 +0200506 if (bus->drv_cc.core) {
Rafał Miłecki775ab522011-12-09 22:16:07 +0100507 bus->drv_cc.setup_done = false;
508 bcma_core_chipcommon_init(&bus->drv_cc);
509 }
510
Linus Torvalds7d5869e2012-01-13 23:58:41 +0100511 list_for_each_entry(core, &bus->cores, list) {
512 struct device_driver *drv = core->dev.driver;
513 if (drv) {
514 struct bcma_driver *adrv = container_of(drv, struct bcma_driver, drv);
515 if (adrv->resume)
516 adrv->resume(core);
517 }
518 }
519
Rafał Miłecki775ab522011-12-09 22:16:07 +0100520 return 0;
521}
522#endif
523
Rafał Miłecki8369ae32011-05-09 18:56:46 +0200524int __bcma_driver_register(struct bcma_driver *drv, struct module *owner)
525{
526 drv->drv.name = drv->name;
527 drv->drv.bus = &bcma_bus_type;
528 drv->drv.owner = owner;
529
530 return driver_register(&drv->drv);
531}
532EXPORT_SYMBOL_GPL(__bcma_driver_register);
533
534void bcma_driver_unregister(struct bcma_driver *drv)
535{
536 driver_unregister(&drv->drv);
537}
538EXPORT_SYMBOL_GPL(bcma_driver_unregister);
539
540static int bcma_bus_match(struct device *dev, struct device_driver *drv)
541{
542 struct bcma_device *core = container_of(dev, struct bcma_device, dev);
543 struct bcma_driver *adrv = container_of(drv, struct bcma_driver, drv);
544 const struct bcma_device_id *cid = &core->id;
545 const struct bcma_device_id *did;
546
547 for (did = adrv->id_table; did->manuf || did->id || did->rev; did++) {
548 if ((did->manuf == cid->manuf || did->manuf == BCMA_ANY_MANUF) &&
549 (did->id == cid->id || did->id == BCMA_ANY_ID) &&
550 (did->rev == cid->rev || did->rev == BCMA_ANY_REV) &&
551 (did->class == cid->class || did->class == BCMA_ANY_CLASS))
552 return 1;
553 }
554 return 0;
555}
556
557static int bcma_device_probe(struct device *dev)
558{
559 struct bcma_device *core = container_of(dev, struct bcma_device, dev);
560 struct bcma_driver *adrv = container_of(dev->driver, struct bcma_driver,
561 drv);
562 int err = 0;
563
564 if (adrv->probe)
565 err = adrv->probe(core);
566
567 return err;
568}
569
570static int bcma_device_remove(struct device *dev)
571{
572 struct bcma_device *core = container_of(dev, struct bcma_device, dev);
573 struct bcma_driver *adrv = container_of(dev->driver, struct bcma_driver,
574 drv);
575
576 if (adrv->remove)
577 adrv->remove(core);
578
579 return 0;
580}
581
David Woodhouse886b66e2011-08-19 22:14:47 +0200582static int bcma_device_uevent(struct device *dev, struct kobj_uevent_env *env)
583{
584 struct bcma_device *core = container_of(dev, struct bcma_device, dev);
585
586 return add_uevent_var(env,
587 "MODALIAS=bcma:m%04Xid%04Xrev%02Xcl%02X",
588 core->id.manuf, core->id.id,
589 core->id.rev, core->id.class);
590}
591
Rafał Miłecki8369ae32011-05-09 18:56:46 +0200592static int __init bcma_modinit(void)
593{
594 int err;
595
596 err = bus_register(&bcma_bus_type);
597 if (err)
598 return err;
599
Hauke Mehrtens2101e532014-09-26 00:09:19 +0200600 err = bcma_host_soc_register_driver();
601 if (err) {
602 pr_err("SoC host initialization failed\n");
603 err = 0;
604 }
Rafał Miłecki8369ae32011-05-09 18:56:46 +0200605#ifdef CONFIG_BCMA_HOST_PCI
606 err = bcma_host_pci_init();
607 if (err) {
608 pr_err("PCI host initialization failed\n");
609 err = 0;
610 }
611#endif
612
613 return err;
614}
615fs_initcall(bcma_modinit);
616
617static void __exit bcma_modexit(void)
618{
619#ifdef CONFIG_BCMA_HOST_PCI
620 bcma_host_pci_exit();
621#endif
Hauke Mehrtens2101e532014-09-26 00:09:19 +0200622 bcma_host_soc_unregister_driver();
Rafał Miłecki8369ae32011-05-09 18:56:46 +0200623 bus_unregister(&bcma_bus_type);
624}
625module_exit(bcma_modexit)