4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18 * Copyright (C) 2005 Texas Instruments Incorporated
19 * Copyright (C) 2008 Google Inc
20 * Copyright (C) 2009 Bob Copeland (me@bobcopeland.com)
22 #include <linux/module.h>
23 #include <linux/crc7.h>
24 #include <linux/mod_devicetable.h>
25 #include <linux/irq.h>
26 #include <linux/mmc/sdio_func.h>
27 #include <linux/mmc/sdio_ids.h>
28 #include <linux/platform_device.h>
31 #include "wl12xx_80211.h"
33 #include "wl1251_ps.h"
34 #include "wl1251_io.h"
35 #include "wl1251_tx.h"
36 #include "wl1251_debugfs.h"
38 #ifndef SDIO_VENDOR_ID_TI
39 #define SDIO_VENDOR_ID_TI 0x104c
42 #ifndef SDIO_DEVICE_ID_TI_WL1251
43 #define SDIO_DEVICE_ID_TI_WL1251 0x9066
46 static struct sdio_func *wl_to_func(struct wl1251 *wl)
51 static void wl1251_sdio_interrupt(struct sdio_func *func)
53 wl1251_irq(0, sdio_get_drvdata(func));
56 static const struct sdio_device_id wl1251_devices[] = {
57 { SDIO_DEVICE(SDIO_VENDOR_ID_TI, SDIO_DEVICE_ID_TI_WL1251) },
60 MODULE_DEVICE_TABLE(sdio, wl1251_devices);
63 void wl1251_sdio_read(struct wl1251 *wl, int addr, void *buf, size_t len)
66 struct sdio_func *func = wl_to_func(wl);
68 sdio_claim_host(func);
69 ret = sdio_memcpy_fromio(func, buf, addr, len);
71 wl1251_error("sdio read failed (%d)", ret);
72 sdio_release_host(func);
75 void wl1251_sdio_write(struct wl1251 *wl, int addr, void *buf, size_t len)
78 struct sdio_func *func = wl_to_func(wl);
80 sdio_claim_host(func);
81 ret = sdio_memcpy_toio(func, addr, buf, len);
83 wl1251_error("sdio write failed (%d)", ret);
84 sdio_release_host(func);
87 void wl1251_sdio_reset(struct wl1251 *wl)
91 void wl1251_sdio_set_power(bool enable)
95 struct wl1251_if_operations wl1251_sdio_ops = {
96 .read = wl1251_sdio_read,
97 .write = wl1251_sdio_write,
98 .reset = wl1251_sdio_reset,
101 int wl1251_sdio_probe(struct sdio_func *func, const struct sdio_device_id *id)
105 struct ieee80211_hw *hw;
107 hw = wl1251_alloc_hw();
113 sdio_claim_host(func);
114 ret = sdio_enable_func(func);
118 sdio_set_block_size(func, 512);
120 SET_IEEE80211_DEV(hw, &func->dev);
122 wl->if_ops = &wl1251_sdio_ops;
123 wl->set_power = wl1251_sdio_set_power;
125 sdio_release_host(func);
126 ret = wl1251_init_ieee80211(wl);
127 sdio_claim_host(func);
131 ret = sdio_claim_irq(func, wl1251_sdio_interrupt);
135 sdio_release_host(func);
136 sdio_set_drvdata(func, wl);
142 sdio_disable_func(func);
144 sdio_release_host(func);
148 static void __devexit wl1251_sdio_remove(struct sdio_func *func)
150 struct wl1251 *wl = sdio_get_drvdata(func);
154 sdio_claim_host(func);
155 sdio_release_irq(func);
156 sdio_disable_func(func);
157 sdio_release_host(func);
160 static struct sdio_driver wl1251_sdio_driver = {
161 .name = "wl1251_sdio",
162 .id_table = wl1251_devices,
163 .probe = wl1251_sdio_probe,
164 .remove = __devexit_p(wl1251_sdio_remove),
167 static int __init wl1251_sdio_init(void)
171 err = sdio_register_driver(&wl1251_sdio_driver);
173 wl1251_error("failed to register sdio driver: %d", err);
177 static void __exit wl1251_sdio_exit(void)
179 sdio_unregister_driver(&wl1251_sdio_driver);
180 wl1251_notice("unloaded");
183 module_init(wl1251_sdio_init);
184 module_exit(wl1251_sdio_exit);
186 MODULE_LICENSE("GPL");
187 MODULE_AUTHOR("Kalle Valo <Kalle.Valo@nokia.com>");
188 MODULE_AUTHOR("Luciano Coelho <luciano.coelho@nokia.com>");