2 * Broadcom B43 wireless driver
4 * SDIO over Sonics Silicon Backplane bus glue for b43.
6 * Copyright (C) 2009 Albert Herranz
7 * Copyright (C) 2009 Michael Buesch <mb@bu3sch.de>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or (at
12 * your option) any later version.
15 #include <linux/kernel.h>
16 #include <linux/mmc/card.h>
17 #include <linux/mmc/sdio_func.h>
18 #include <linux/mmc/sdio_ids.h>
19 #include <linux/ssb/ssb.h>
25 #define HNBU_CHIPID 0x01 /* vendor & device id */
27 #define B43_SDIO_BLOCK_SIZE 64 /* rx fifo max size in bytes */
30 static const struct b43_sdio_quirk {
34 } b43_sdio_quirks[] = {
35 { 0x14E4, 0x4318, SSB_QUIRK_SDIO_READ_AFTER_WRITE32, },
40 static unsigned int b43_sdio_get_quirks(u16 vendor, u16 device)
42 const struct b43_sdio_quirk *q;
44 for (q = b43_sdio_quirks; q->quirks; q++) {
45 if (vendor == q->vendor && device == q->device)
52 static void b43_sdio_interrupt_dispatcher(struct sdio_func *func)
54 struct b43_sdio *sdio = sdio_get_drvdata(func);
55 struct b43_wldev *dev = sdio->irq_handler_opaque;
57 sdio->irq_handler(dev);
60 int b43_sdio_request_irq(struct b43_wldev *dev,
61 void (*handler)(struct b43_wldev *dev))
63 struct ssb_bus *bus = dev->dev->bus;
64 struct sdio_func *func = bus->host_sdio;
65 struct b43_sdio *sdio = sdio_get_drvdata(func);
68 sdio->irq_handler_opaque = dev;
69 sdio->irq_handler = handler;
70 sdio_claim_host(func);
71 err = sdio_claim_irq(func, b43_sdio_interrupt_dispatcher);
72 sdio_release_host(func);
77 void b43_sdio_free_irq(struct b43_wldev *dev)
79 struct ssb_bus *bus = dev->dev->bus;
80 struct sdio_func *func = bus->host_sdio;
81 struct b43_sdio *sdio = sdio_get_drvdata(func);
83 sdio_claim_host(func);
84 sdio_release_irq(func);
85 sdio_release_host(func);
86 sdio->irq_handler_opaque = NULL;
87 sdio->irq_handler = NULL;
90 static int b43_sdio_probe(struct sdio_func *func,
91 const struct sdio_device_id *id)
93 struct b43_sdio *sdio;
94 struct sdio_func_tuple *tuple;
95 u16 vendor = 0, device = 0;
98 /* Look for the card chip identifier. */
101 switch (tuple->code) {
103 switch (tuple->data[0]) {
105 if (tuple->size != 5)
107 vendor = tuple->data[1] | (tuple->data[2]<<8);
108 device = tuple->data[3] | (tuple->data[4]<<8);
109 dev_info(&func->dev, "Chip ID %04x:%04x\n",
121 if (!vendor || !device) {
126 sdio_claim_host(func);
127 error = sdio_set_block_size(func, B43_SDIO_BLOCK_SIZE);
129 dev_err(&func->dev, "failed to set block size to %u bytes,"
130 " error %d\n", B43_SDIO_BLOCK_SIZE, error);
131 goto err_release_host;
133 error = sdio_enable_func(func);
135 dev_err(&func->dev, "failed to enable func, error %d\n", error);
136 goto err_release_host;
138 sdio_release_host(func);
140 sdio = kzalloc(sizeof(*sdio), GFP_KERNEL);
143 dev_err(&func->dev, "failed to allocate ssb bus\n");
144 goto err_disable_func;
146 error = ssb_bus_sdiobus_register(&sdio->ssb, func,
147 b43_sdio_get_quirks(vendor, device));
149 dev_err(&func->dev, "failed to register ssb sdio bus,"
150 " error %d\n", error);
153 sdio_set_drvdata(func, sdio);
160 sdio_disable_func(func);
162 sdio_release_host(func);
167 static void b43_sdio_remove(struct sdio_func *func)
169 struct b43_sdio *sdio = sdio_get_drvdata(func);
171 ssb_bus_unregister(&sdio->ssb);
172 sdio_disable_func(func);
174 sdio_set_drvdata(func, NULL);
177 static const struct sdio_device_id b43_sdio_ids[] = {
178 { SDIO_DEVICE(0x02d0, 0x044b) }, /* Nintendo Wii WLAN daughter card */
182 static struct sdio_driver b43_sdio_driver = {
184 .id_table = b43_sdio_ids,
185 .probe = b43_sdio_probe,
186 .remove = b43_sdio_remove,
189 int b43_sdio_init(void)
191 return sdio_register_driver(&b43_sdio_driver);
194 void b43_sdio_exit(void)
196 sdio_unregister_driver(&b43_sdio_driver);