2 * wl_glue.c: Broadcom WL support module providing a unified SSB/BCMA handling.
3 * Copyright (C) 2011 Jo-Philipp Wich <jow@openwrt.org>
8 #include <linux/kernel.h>
9 #include <linux/module.h>
10 #include <linux/init.h>
17 #include <linux/ssb/ssb.h>
21 #include <linux/bcma/bcma.h>
24 MODULE_AUTHOR("Jo-Philipp Wich (jow@openwrt.org)");
25 MODULE_DESCRIPTION("Broadcom WL SSB/BCMA compatibility layer");
26 MODULE_LICENSE("GPL");
28 static wl_glue_attach_cb_t attach_cb = NULL;
29 static wl_glue_remove_cb_t remove_cb = NULL;
30 static enum wl_glue_bus_type active_bus_type = WL_GLUE_BUS_TYPE_UNSPEC;
31 static int wl_glue_attached = 0;
35 static int wl_glue_ssb_probe(struct ssb_device *dev, const struct ssb_device_id *id)
42 pr_err("No attach callback registered\n");
46 if (dev->bus->bustype != SSB_BUSTYPE_SSB)
48 pr_err("Attaching to SSB behind PCI is not supported. Please remove the b43 ssb bridge\n");
52 mmio = (void *) 0x18000000 + dev->core_index * 0x1000;
53 wldev = attach_cb(id->vendor, id->coreid, (ulong)mmio, dev, dev->irq);
57 pr_err("The attach callback failed, SSB probe aborted\n");
61 ssb_set_drvdata(dev, wldev);
65 static void wl_glue_ssb_remove(struct ssb_device *dev)
67 void *wldev = ssb_get_drvdata(dev);
72 ssb_set_drvdata(dev, NULL);
75 static const struct ssb_device_id wl_glue_ssb_tbl[] = {
76 SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_80211, SSB_ANY_REV),
80 static struct ssb_driver wl_glue_ssb_driver = {
81 .name = KBUILD_MODNAME,
82 .id_table = wl_glue_ssb_tbl,
83 .probe = wl_glue_ssb_probe,
84 .remove = wl_glue_ssb_remove,
86 #endif /* CONFIG_SSB */
89 static int wl_glue_bcma_probe(struct bcma_device *dev)
95 pr_err("No attach callback registered\n");
99 if (dev->bus->hosttype != BCMA_HOSTTYPE_SOC)
101 pr_err("Unsupported BCMA bus type %d\n", dev->bus->hosttype);
107 * 0x18000000 = BCMA_ADDR_BASE
108 * 0x1000 = BCMA_CORE_SIZE
111 wldev = attach_cb(dev->id.manuf, dev->id.id, (ulong)dev->addr, dev, dev->irq);
115 pr_err("The attach callback failed, BCMA probe aborted\n");
119 bcma_set_drvdata(dev, wldev);
123 static void wl_glue_bcma_remove(struct bcma_device *dev)
125 void *wldev = bcma_get_drvdata(dev);
130 bcma_set_drvdata(dev, NULL);
133 static const struct bcma_device_id wl_glue_bcma_tbl[] = {
134 BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_80211, BCMA_ANY_REV, BCMA_ANY_CLASS),
138 static struct bcma_driver wl_glue_bcma_driver = {
139 .name = KBUILD_MODNAME,
140 .id_table = wl_glue_bcma_tbl,
141 .probe = wl_glue_bcma_probe,
142 .remove = wl_glue_bcma_remove,
144 #endif /* CONFIG_BCMA */
147 void wl_glue_set_attach_callback(wl_glue_attach_cb_t cb)
151 EXPORT_SYMBOL(wl_glue_set_attach_callback);
153 void wl_glue_set_remove_callback(wl_glue_remove_cb_t cb)
157 EXPORT_SYMBOL(wl_glue_set_remove_callback);
159 int wl_glue_register(void)
163 switch(active_bus_type)
166 case WL_GLUE_BUS_TYPE_SSB:
167 err = ssb_driver_register(&wl_glue_ssb_driver);
169 #endif /* CONFIG_SSB */
172 case WL_GLUE_BUS_TYPE_BCMA:
173 err = bcma_driver_register(&wl_glue_bcma_driver);
175 #endif /* CONFIG_BCMA */
178 pr_err("Not attaching through glue driver due to unsupported bus\n");
185 pr_info("SSB/BCMA glue driver successfully attached\n");
186 wl_glue_attached = 1;
191 EXPORT_SYMBOL(wl_glue_register);
193 int wl_glue_unregister(void)
197 if (!wl_glue_attached)
200 switch (active_bus_type)
203 case WL_GLUE_BUS_TYPE_SSB:
204 ssb_driver_unregister(&wl_glue_ssb_driver);
207 #endif /* CONFIG_SSB */
210 case WL_GLUE_BUS_TYPE_BCMA:
211 bcma_driver_unregister(&wl_glue_bcma_driver);
214 #endif /* CONFIG_BCMA */
217 pr_err("Not removing glue driver due to unsupported bus\n");
224 pr_info("SSB/BCMA glue driver successfully detached\n");
225 wl_glue_attached = 0;
230 EXPORT_SYMBOL(wl_glue_unregister);
232 struct device * wl_glue_get_dmadev(void *dev)
234 struct device *dma_dev;
236 switch (active_bus_type)
239 case WL_GLUE_BUS_TYPE_SSB:
240 dma_dev = ((struct ssb_device *)dev)->dma_dev;
242 #endif /* CONFIG_SSB */
245 case WL_GLUE_BUS_TYPE_BCMA:
246 dma_dev = ((struct bcma_device *)dev)->dma_dev;
248 #endif /* CONFIG_BCMA */
258 EXPORT_SYMBOL(wl_glue_get_dmadev);
261 static int __init wl_glue_init(void)
263 #ifdef CONFIG_BCM47XX
265 * BCM47xx currently supports either SSB or BCMA bus,
266 * determine the used one from the info set by the
267 * platform setup code.
269 switch (bcm47xx_bus_type)
272 case BCM47XX_BUS_TYPE_SSB:
273 active_bus_type = WL_GLUE_BUS_TYPE_SSB;
275 #endif /* CONFIG_SSB */
278 case BCM47XX_BUS_TYPE_BCMA:
279 active_bus_type = WL_GLUE_BUS_TYPE_BCMA;
281 #endif /* CONFIG_BCMA */
283 #endif /* CONFIG_BCM47XX */
285 #ifdef CONFIG_BCM63XX
288 * BCM63xx currently only uses SSB, so assume that.
290 active_bus_type = WL_GLUE_BUS_TYPE_SSB;
291 #endif /* CONFIG_SSB */
292 #endif /* CONFIG_BCM63XX */
294 /* do not fail here, let wl_glue_register() return -ENOSYS later */
295 if (active_bus_type == WL_GLUE_BUS_TYPE_UNSPEC)
296 pr_err("Unable to determine used system bus type\n");
301 static void __exit wl_glue_exit(void)
303 if (wl_glue_attached)
305 if (wl_glue_unregister())
306 pr_err("Failed to unregister glue driver\n");
308 wl_glue_attached = 0;
314 module_init(wl_glue_init);
315 module_exit(wl_glue_exit);