diff options
author | Bob Copeland <me@bobcopeland.com> | 2009-08-07 06:33:26 -0400 |
---|---|---|
committer | John W. Linville <linville@tuxdriver.com> | 2009-08-14 09:13:37 -0400 |
commit | 8e639c0673a9b676bb7c6bd4e50f9003bdda423e (patch) | |
tree | fb4e87e44347baa1e0b46c9b84c219501a14b11c /drivers/net/wireless/wl12xx/wl1251_spi.c | |
parent | 0d77e141331b25adf190ce30d69fe5744a69c5bd (diff) |
wl1251: move module probe methods into spi.c
This change moves all of the spi specific code from main.c into
spi.c. The module initialization code also moves, but common
code for initializing mac80211 etc. stays in main.c, as this will
eventually form a common library module also used by wl1251_sdio.
Signed-off-by: Bob Copeland <me@bobcopeland.com>
Signed-off-by: Kalle Valo <kalle.valo@nokia.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'drivers/net/wireless/wl12xx/wl1251_spi.c')
-rw-r--r-- | drivers/net/wireless/wl12xx/wl1251_spi.c | 125 |
1 files changed, 123 insertions, 2 deletions
diff --git a/drivers/net/wireless/wl12xx/wl1251_spi.c b/drivers/net/wireless/wl12xx/wl1251_spi.c index ceb237b4e579..13e7a726dea2 100644 --- a/drivers/net/wireless/wl12xx/wl1251_spi.c +++ b/drivers/net/wireless/wl12xx/wl1251_spi.c | |||
@@ -21,9 +21,11 @@ | |||
21 | * | 21 | * |
22 | */ | 22 | */ |
23 | 23 | ||
24 | #include <linux/irq.h> | ||
24 | #include <linux/module.h> | 25 | #include <linux/module.h> |
25 | #include <linux/crc7.h> | 26 | #include <linux/crc7.h> |
26 | #include <linux/spi/spi.h> | 27 | #include <linux/spi/spi.h> |
28 | #include <linux/spi/wl12xx.h> | ||
27 | 29 | ||
28 | #include "wl1251.h" | 30 | #include "wl1251.h" |
29 | #include "reg.h" | 31 | #include "reg.h" |
@@ -55,7 +57,7 @@ static void wl1251_spi_reset(struct wl1251 *wl) | |||
55 | wl1251_dump(DEBUG_SPI, "spi reset -> ", cmd, WSPI_INIT_CMD_LEN); | 57 | wl1251_dump(DEBUG_SPI, "spi reset -> ", cmd, WSPI_INIT_CMD_LEN); |
56 | } | 58 | } |
57 | 59 | ||
58 | static void wl1251_spi_init(struct wl1251 *wl) | 60 | static void wl1251_spi_wake(struct wl1251 *wl) |
59 | { | 61 | { |
60 | u8 crc[WSPI_INIT_CMD_CRC_LEN], *cmd; | 62 | u8 crc[WSPI_INIT_CMD_CRC_LEN], *cmd; |
61 | struct spi_transfer t; | 63 | struct spi_transfer t; |
@@ -112,7 +114,7 @@ static void wl1251_spi_init(struct wl1251 *wl) | |||
112 | static void wl1251_spi_reset_wake(struct wl1251 *wl) | 114 | static void wl1251_spi_reset_wake(struct wl1251 *wl) |
113 | { | 115 | { |
114 | wl1251_spi_reset(wl); | 116 | wl1251_spi_reset(wl); |
115 | wl1251_spi_init(wl); | 117 | wl1251_spi_wake(wl); |
116 | } | 118 | } |
117 | 119 | ||
118 | static void wl1251_spi_read(struct wl1251 *wl, int addr, void *buf, | 120 | static void wl1251_spi_read(struct wl1251 *wl, int addr, void *buf, |
@@ -191,3 +193,122 @@ const struct wl1251_if_operations wl1251_spi_ops = { | |||
191 | .write = wl1251_spi_write, | 193 | .write = wl1251_spi_write, |
192 | .reset = wl1251_spi_reset_wake, | 194 | .reset = wl1251_spi_reset_wake, |
193 | }; | 195 | }; |
196 | |||
197 | static int __devinit wl1251_spi_probe(struct spi_device *spi) | ||
198 | { | ||
199 | struct wl12xx_platform_data *pdata; | ||
200 | struct ieee80211_hw *hw; | ||
201 | struct wl1251 *wl; | ||
202 | int ret; | ||
203 | |||
204 | pdata = spi->dev.platform_data; | ||
205 | if (!pdata) { | ||
206 | wl1251_error("no platform data"); | ||
207 | return -ENODEV; | ||
208 | } | ||
209 | |||
210 | hw = wl1251_alloc_hw(); | ||
211 | if (IS_ERR(hw)) | ||
212 | return PTR_ERR(hw); | ||
213 | |||
214 | wl = hw->priv; | ||
215 | |||
216 | SET_IEEE80211_DEV(hw, &spi->dev); | ||
217 | dev_set_drvdata(&spi->dev, wl); | ||
218 | wl->spi = spi; | ||
219 | wl->if_ops = &wl1251_spi_ops; | ||
220 | |||
221 | /* This is the only SPI value that we need to set here, the rest | ||
222 | * comes from the board-peripherals file */ | ||
223 | spi->bits_per_word = 32; | ||
224 | |||
225 | ret = spi_setup(spi); | ||
226 | if (ret < 0) { | ||
227 | wl1251_error("spi_setup failed"); | ||
228 | goto out_free; | ||
229 | } | ||
230 | |||
231 | wl->set_power = pdata->set_power; | ||
232 | if (!wl->set_power) { | ||
233 | wl1251_error("set power function missing in platform data"); | ||
234 | return -ENODEV; | ||
235 | } | ||
236 | |||
237 | wl->irq = spi->irq; | ||
238 | if (wl->irq < 0) { | ||
239 | wl1251_error("irq missing in platform data"); | ||
240 | return -ENODEV; | ||
241 | } | ||
242 | |||
243 | ret = request_irq(wl->irq, wl1251_irq, 0, DRIVER_NAME, wl); | ||
244 | if (ret < 0) { | ||
245 | wl1251_error("request_irq() failed: %d", ret); | ||
246 | goto out_free; | ||
247 | } | ||
248 | |||
249 | set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING); | ||
250 | |||
251 | disable_irq(wl->irq); | ||
252 | |||
253 | ret = wl1251_init_ieee80211(wl); | ||
254 | if (ret) | ||
255 | goto out_irq; | ||
256 | |||
257 | return 0; | ||
258 | |||
259 | out_irq: | ||
260 | free_irq(wl->irq, wl); | ||
261 | |||
262 | out_free: | ||
263 | ieee80211_free_hw(hw); | ||
264 | |||
265 | return ret; | ||
266 | } | ||
267 | |||
268 | static int __devexit wl1251_spi_remove(struct spi_device *spi) | ||
269 | { | ||
270 | struct wl1251 *wl = dev_get_drvdata(&spi->dev); | ||
271 | |||
272 | wl1251_free_hw(wl); | ||
273 | |||
274 | return 0; | ||
275 | } | ||
276 | |||
277 | static struct spi_driver wl1251_spi_driver = { | ||
278 | .driver = { | ||
279 | .name = "wl12xx", | ||
280 | .bus = &spi_bus_type, | ||
281 | .owner = THIS_MODULE, | ||
282 | }, | ||
283 | |||
284 | .probe = wl1251_spi_probe, | ||
285 | .remove = __devexit_p(wl1251_spi_remove), | ||
286 | }; | ||
287 | |||
288 | static int __init wl1251_spi_init(void) | ||
289 | { | ||
290 | int ret; | ||
291 | |||
292 | ret = spi_register_driver(&wl1251_spi_driver); | ||
293 | if (ret < 0) { | ||
294 | wl1251_error("failed to register spi driver: %d", ret); | ||
295 | goto out; | ||
296 | } | ||
297 | |||
298 | out: | ||
299 | return ret; | ||
300 | } | ||
301 | |||
302 | static void __exit wl1251_spi_exit(void) | ||
303 | { | ||
304 | spi_unregister_driver(&wl1251_spi_driver); | ||
305 | |||
306 | wl1251_notice("unloaded"); | ||
307 | } | ||
308 | |||
309 | module_init(wl1251_spi_init); | ||
310 | module_exit(wl1251_spi_exit); | ||
311 | |||
312 | MODULE_LICENSE("GPL"); | ||
313 | MODULE_AUTHOR("Kalle Valo <Kalle.Valo@nokia.com>"); | ||
314 | MODULE_AUTHOR("Luciano Coelho <luciano.coelho@nokia.com>"); | ||