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
)
96 pr_err("No attach callback registered\n");
100 if (dev
->bus
->hosttype
!= BCMA_HOSTTYPE_SOC
)
102 pr_err("Unsupported BCMA bus type %d\n", dev
->bus
->hosttype
);
108 * 0x18000000 = BCMA_ADDR_BASE
109 * 0x1000 = BCMA_CORE_SIZE
112 mmio
= (void *) 0x18000000 + dev
->core_index
* 0x1000;
113 wldev
= attach_cb(dev
->id
.manuf
, dev
->id
.id
, (ulong
)mmio
, dev
, dev
->irq
);
117 pr_err("The attach callback failed, BCMA probe aborted\n");
121 bcma_set_drvdata(dev
, wldev
);
125 static void wl_glue_bcma_remove(struct bcma_device
*dev
)
127 void *wldev
= bcma_get_drvdata(dev
);
132 bcma_set_drvdata(dev
, NULL
);
135 static const struct bcma_device_id wl_glue_bcma_tbl
[] = {
136 BCMA_CORE(BCMA_MANUF_BCM
, BCMA_CORE_80211
, BCMA_ANY_REV
, BCMA_ANY_CLASS
),
140 static struct bcma_driver wl_glue_bcma_driver
= {
141 .name
= KBUILD_MODNAME
,
142 .id_table
= wl_glue_bcma_tbl
,
143 .probe
= wl_glue_bcma_probe
,
144 .remove
= wl_glue_bcma_remove
,
146 #endif /* CONFIG_BCMA */
149 void wl_glue_set_attach_callback(wl_glue_attach_cb_t cb
)
153 EXPORT_SYMBOL(wl_glue_set_attach_callback
);
155 void wl_glue_set_remove_callback(wl_glue_remove_cb_t cb
)
159 EXPORT_SYMBOL(wl_glue_set_remove_callback
);
161 int wl_glue_register(void)
165 switch(active_bus_type
)
168 case WL_GLUE_BUS_TYPE_SSB
:
169 err
= ssb_driver_register(&wl_glue_ssb_driver
);
171 #endif /* CONFIG_SSB */
174 case WL_GLUE_BUS_TYPE_BCMA
:
175 err
= bcma_driver_register(&wl_glue_bcma_driver
);
177 #endif /* CONFIG_BCMA */
180 pr_err("Not attaching through glue driver due to unsupported bus\n");
187 pr_info("SSB/BCMA glue driver successfully attached\n");
188 wl_glue_attached
= 1;
193 EXPORT_SYMBOL(wl_glue_register
);
195 int wl_glue_unregister(void)
199 if (!wl_glue_attached
)
202 switch (active_bus_type
)
205 case WL_GLUE_BUS_TYPE_SSB
:
206 ssb_driver_unregister(&wl_glue_ssb_driver
);
209 #endif /* CONFIG_SSB */
212 case WL_GLUE_BUS_TYPE_BCMA
:
213 bcma_driver_unregister(&wl_glue_bcma_driver
);
216 #endif /* CONFIG_BCMA */
219 pr_err("Not removing glue driver due to unsupported bus\n");
226 pr_info("SSB/BCMA glue driver successfully detached\n");
227 wl_glue_attached
= 0;
232 EXPORT_SYMBOL(wl_glue_unregister
);
234 struct device
* wl_glue_get_dmadev(void *dev
)
236 struct device
*dma_dev
;
238 if (!wl_glue_attached
)
244 switch (active_bus_type
)
247 case WL_GLUE_BUS_TYPE_SSB
:
248 dma_dev
= ((struct ssb_device
*)dev
)->dma_dev
;
250 #endif /* CONFIG_SSB */
253 case WL_GLUE_BUS_TYPE_BCMA
:
254 dma_dev
= ((struct bcma_device
*)dev
)->dma_dev
;
256 #endif /* CONFIG_BCMA */
266 EXPORT_SYMBOL(wl_glue_get_dmadev
);
269 static int __init
wl_glue_init(void)
271 #ifdef CONFIG_BCM47XX
273 * BCM47xx currently supports either SSB or BCMA bus,
274 * determine the used one from the info set by the
275 * platform setup code.
277 switch (bcm47xx_active_bus_type
)
280 case BCM47XX_BUS_TYPE_SSB
:
281 active_bus_type
= WL_GLUE_BUS_TYPE_SSB
;
283 #endif /* CONFIG_SSB */
286 case BCM47XX_BUS_TYPE_BCMA
:
287 active_bus_type
= WL_GLUE_BUS_TYPE_BCMA
;
289 #endif /* CONFIG_BCMA */
291 #endif /* CONFIG_BCM47XX */
293 #ifdef CONFIG_BCM63XX
296 * BCM63xx currently only uses SSB, so assume that.
298 active_bus_type
= WL_GLUE_BUS_TYPE_SSB
;
299 #endif /* CONFIG_SSB */
300 #endif /* CONFIG_BCM63XX */
302 /* do not fail here, let wl_glue_register() return -ENOSYS later */
303 if (active_bus_type
== WL_GLUE_BUS_TYPE_UNSPEC
)
304 pr_err("Unable to determine used system bus type\n");
309 static void __exit
wl_glue_exit(void)
311 if (wl_glue_attached
)
313 if (wl_glue_unregister())
314 pr_err("Failed to unregister glue driver\n");
316 wl_glue_attached
= 0;
322 module_init(wl_glue_init
);
323 module_exit(wl_glue_exit
);