wl1271_main.c 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396
  1. /*
  2. * This file is part of wl1271
  3. *
  4. * Copyright (C) 2008-2009 Nokia Corporation
  5. *
  6. * Contact: Luciano Coelho <luciano.coelho@nokia.com>
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * version 2 as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA
  21. *
  22. */
  23. #include <linux/module.h>
  24. #include <linux/platform_device.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/firmware.h>
  27. #include <linux/delay.h>
  28. #include <linux/irq.h>
  29. #include <linux/spi/spi.h>
  30. #include <linux/crc32.h>
  31. #include <linux/etherdevice.h>
  32. #include <linux/spi/wl12xx.h>
  33. #include "wl1271.h"
  34. #include "wl12xx_80211.h"
  35. #include "wl1271_reg.h"
  36. #include "wl1271_spi.h"
  37. #include "wl1271_event.h"
  38. #include "wl1271_tx.h"
  39. #include "wl1271_rx.h"
  40. #include "wl1271_ps.h"
  41. #include "wl1271_init.h"
  42. #include "wl1271_debugfs.h"
  43. #include "wl1271_cmd.h"
  44. #include "wl1271_boot.h"
  45. static int wl1271_plt_init(struct wl1271 *wl)
  46. {
  47. int ret;
  48. ret = wl1271_acx_init_mem_config(wl);
  49. if (ret < 0)
  50. return ret;
  51. ret = wl1271_cmd_data_path(wl, wl->channel, 1);
  52. if (ret < 0)
  53. return ret;
  54. return 0;
  55. }
  56. static void wl1271_disable_interrupts(struct wl1271 *wl)
  57. {
  58. disable_irq(wl->irq);
  59. }
  60. static void wl1271_power_off(struct wl1271 *wl)
  61. {
  62. wl->set_power(false);
  63. }
  64. static void wl1271_power_on(struct wl1271 *wl)
  65. {
  66. wl->set_power(true);
  67. }
  68. static void wl1271_fw_status(struct wl1271 *wl, struct wl1271_fw_status *status)
  69. {
  70. u32 total = 0;
  71. int i;
  72. /*
  73. * FIXME: Reading the FW status directly from the registers seems to
  74. * be the right thing to do, but it doesn't work. And in the
  75. * reference driver, there is a workaround called
  76. * USE_SDIO_24M_WORKAROUND, which reads the status from memory
  77. * instead, so we do the same here.
  78. */
  79. wl1271_spi_mem_read(wl, STATUS_MEM_ADDRESS, status, sizeof(*status));
  80. wl1271_debug(DEBUG_IRQ, "intr: 0x%x (fw_rx_counter = %d, "
  81. "drv_rx_counter = %d, tx_results_counter = %d)",
  82. status->intr,
  83. status->fw_rx_counter,
  84. status->drv_rx_counter,
  85. status->tx_results_counter);
  86. /* update number of available TX blocks */
  87. for (i = 0; i < NUM_TX_QUEUES; i++) {
  88. u32 cnt = status->tx_released_blks[i] - wl->tx_blocks_freed[i];
  89. wl->tx_blocks_freed[i] = status->tx_released_blks[i];
  90. wl->tx_blocks_available += cnt;
  91. total += cnt;
  92. }
  93. /* if more blocks are available now, schedule some tx work */
  94. if (total && !skb_queue_empty(&wl->tx_queue))
  95. schedule_work(&wl->tx_work);
  96. /* update the host-chipset time offset */
  97. wl->time_offset = jiffies_to_usecs(jiffies) - status->fw_localtime;
  98. }
  99. #define WL1271_IRQ_MAX_LOOPS 10
  100. static void wl1271_irq_work(struct work_struct *work)
  101. {
  102. u32 intr, ctr = WL1271_IRQ_MAX_LOOPS;
  103. int ret;
  104. struct wl1271 *wl =
  105. container_of(work, struct wl1271, irq_work);
  106. mutex_lock(&wl->mutex);
  107. wl1271_debug(DEBUG_IRQ, "IRQ work");
  108. if (wl->state == WL1271_STATE_OFF)
  109. goto out;
  110. ret = wl1271_ps_elp_wakeup(wl, true);
  111. if (ret < 0)
  112. goto out;
  113. wl1271_reg_write32(wl, ACX_REG_INTERRUPT_MASK, WL1271_ACX_INTR_ALL);
  114. intr = wl1271_reg_read32(wl, ACX_REG_INTERRUPT_CLEAR);
  115. if (!intr) {
  116. wl1271_debug(DEBUG_IRQ, "Zero interrupt received.");
  117. goto out_sleep;
  118. }
  119. intr &= WL1271_INTR_MASK;
  120. do {
  121. wl1271_fw_status(wl, wl->fw_status);
  122. if (intr & (WL1271_ACX_INTR_EVENT_A |
  123. WL1271_ACX_INTR_EVENT_B)) {
  124. wl1271_debug(DEBUG_IRQ,
  125. "WL1271_ACX_INTR_EVENT (0x%x)", intr);
  126. if (intr & WL1271_ACX_INTR_EVENT_A)
  127. wl1271_event_handle(wl, 0);
  128. else
  129. wl1271_event_handle(wl, 1);
  130. }
  131. if (intr & WL1271_ACX_INTR_INIT_COMPLETE)
  132. wl1271_debug(DEBUG_IRQ,
  133. "WL1271_ACX_INTR_INIT_COMPLETE");
  134. if (intr & WL1271_ACX_INTR_HW_AVAILABLE)
  135. wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_HW_AVAILABLE");
  136. if (intr & WL1271_ACX_INTR_DATA) {
  137. u8 tx_res_cnt = wl->fw_status->tx_results_counter -
  138. wl->tx_results_count;
  139. wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_DATA");
  140. /* check for tx results */
  141. if (tx_res_cnt)
  142. wl1271_tx_complete(wl, tx_res_cnt);
  143. wl1271_rx(wl, wl->fw_status);
  144. }
  145. intr = wl1271_reg_read32(wl, ACX_REG_INTERRUPT_CLEAR);
  146. intr &= WL1271_INTR_MASK;
  147. } while (intr && --ctr);
  148. out_sleep:
  149. wl1271_reg_write32(wl, ACX_REG_INTERRUPT_MASK, ~(WL1271_INTR_MASK));
  150. wl1271_ps_elp_sleep(wl);
  151. out:
  152. mutex_unlock(&wl->mutex);
  153. }
  154. static irqreturn_t wl1271_irq(int irq, void *cookie)
  155. {
  156. struct wl1271 *wl;
  157. unsigned long flags;
  158. wl1271_debug(DEBUG_IRQ, "IRQ");
  159. wl = cookie;
  160. /* complete the ELP completion */
  161. spin_lock_irqsave(&wl->wl_lock, flags);
  162. if (wl->elp_compl) {
  163. complete(wl->elp_compl);
  164. wl->elp_compl = NULL;
  165. }
  166. schedule_work(&wl->irq_work);
  167. spin_unlock_irqrestore(&wl->wl_lock, flags);
  168. return IRQ_HANDLED;
  169. }
  170. static int wl1271_fetch_firmware(struct wl1271 *wl)
  171. {
  172. const struct firmware *fw;
  173. int ret;
  174. ret = request_firmware(&fw, WL1271_FW_NAME, &wl->spi->dev);
  175. if (ret < 0) {
  176. wl1271_error("could not get firmware: %d", ret);
  177. return ret;
  178. }
  179. if (fw->size % 4) {
  180. wl1271_error("firmware size is not multiple of 32 bits: %zu",
  181. fw->size);
  182. ret = -EILSEQ;
  183. goto out;
  184. }
  185. wl->fw_len = fw->size;
  186. wl->fw = kmalloc(wl->fw_len, GFP_KERNEL);
  187. if (!wl->fw) {
  188. wl1271_error("could not allocate memory for the firmware");
  189. ret = -ENOMEM;
  190. goto out;
  191. }
  192. memcpy(wl->fw, fw->data, wl->fw_len);
  193. ret = 0;
  194. out:
  195. release_firmware(fw);
  196. return ret;
  197. }
  198. static int wl1271_fetch_nvs(struct wl1271 *wl)
  199. {
  200. const struct firmware *fw;
  201. int ret;
  202. ret = request_firmware(&fw, WL1271_NVS_NAME, &wl->spi->dev);
  203. if (ret < 0) {
  204. wl1271_error("could not get nvs file: %d", ret);
  205. return ret;
  206. }
  207. if (fw->size % 4) {
  208. wl1271_error("nvs size is not multiple of 32 bits: %zu",
  209. fw->size);
  210. ret = -EILSEQ;
  211. goto out;
  212. }
  213. wl->nvs_len = fw->size;
  214. wl->nvs = kmalloc(wl->nvs_len, GFP_KERNEL);
  215. if (!wl->nvs) {
  216. wl1271_error("could not allocate memory for the nvs file");
  217. ret = -ENOMEM;
  218. goto out;
  219. }
  220. memcpy(wl->nvs, fw->data, wl->nvs_len);
  221. ret = 0;
  222. out:
  223. release_firmware(fw);
  224. return ret;
  225. }
  226. static void wl1271_fw_wakeup(struct wl1271 *wl)
  227. {
  228. u32 elp_reg;
  229. elp_reg = ELPCTRL_WAKE_UP;
  230. wl1271_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, elp_reg);
  231. }
  232. static int wl1271_setup(struct wl1271 *wl)
  233. {
  234. wl->fw_status = kmalloc(sizeof(*wl->fw_status), GFP_KERNEL);
  235. if (!wl->fw_status)
  236. return -ENOMEM;
  237. wl->tx_res_if = kmalloc(sizeof(*wl->tx_res_if), GFP_KERNEL);
  238. if (!wl->tx_res_if) {
  239. kfree(wl->fw_status);
  240. return -ENOMEM;
  241. }
  242. INIT_WORK(&wl->irq_work, wl1271_irq_work);
  243. INIT_WORK(&wl->tx_work, wl1271_tx_work);
  244. return 0;
  245. }
  246. static int wl1271_chip_wakeup(struct wl1271 *wl)
  247. {
  248. int ret = 0;
  249. wl1271_power_on(wl);
  250. msleep(WL1271_POWER_ON_SLEEP);
  251. wl1271_spi_reset(wl);
  252. wl1271_spi_init(wl);
  253. /* We don't need a real memory partition here, because we only want
  254. * to use the registers at this point. */
  255. wl1271_set_partition(wl,
  256. 0x00000000,
  257. 0x00000000,
  258. REGISTERS_BASE,
  259. REGISTERS_DOWN_SIZE);
  260. /* ELP module wake up */
  261. wl1271_fw_wakeup(wl);
  262. /* whal_FwCtrl_BootSm() */
  263. /* 0. read chip id from CHIP_ID */
  264. wl->chip.id = wl1271_reg_read32(wl, CHIP_ID_B);
  265. /* 1. check if chip id is valid */
  266. switch (wl->chip.id) {
  267. case CHIP_ID_1271_PG10:
  268. wl1271_warning("chip id 0x%x (1271 PG10) support is obsolete",
  269. wl->chip.id);
  270. ret = wl1271_setup(wl);
  271. if (ret < 0)
  272. goto out;
  273. break;
  274. case CHIP_ID_1271_PG20:
  275. wl1271_debug(DEBUG_BOOT, "chip id 0x%x (1271 PG20)",
  276. wl->chip.id);
  277. ret = wl1271_setup(wl);
  278. if (ret < 0)
  279. goto out;
  280. break;
  281. default:
  282. wl1271_error("unsupported chip id: 0x%x", wl->chip.id);
  283. ret = -ENODEV;
  284. goto out;
  285. }
  286. if (wl->fw == NULL) {
  287. ret = wl1271_fetch_firmware(wl);
  288. if (ret < 0)
  289. goto out;
  290. }
  291. /* No NVS from netlink, try to get it from the filesystem */
  292. if (wl->nvs == NULL) {
  293. ret = wl1271_fetch_nvs(wl);
  294. if (ret < 0)
  295. goto out;
  296. }
  297. out:
  298. return ret;
  299. }
  300. static void wl1271_filter_work(struct work_struct *work)
  301. {
  302. struct wl1271 *wl =
  303. container_of(work, struct wl1271, filter_work);
  304. int ret;
  305. mutex_lock(&wl->mutex);
  306. if (wl->state == WL1271_STATE_OFF)
  307. goto out;
  308. ret = wl1271_ps_elp_wakeup(wl, false);
  309. if (ret < 0)
  310. goto out;
  311. /* FIXME: replace the magic numbers with proper definitions */
  312. ret = wl1271_cmd_join(wl, wl->bss_type, 1, 100, 0);
  313. if (ret < 0)
  314. goto out_sleep;
  315. out_sleep:
  316. wl1271_ps_elp_sleep(wl);
  317. out:
  318. mutex_unlock(&wl->mutex);
  319. }
  320. int wl1271_plt_start(struct wl1271 *wl)
  321. {
  322. int ret;
  323. mutex_lock(&wl->mutex);
  324. wl1271_notice("power up");
  325. if (wl->state != WL1271_STATE_OFF) {
  326. wl1271_error("cannot go into PLT state because not "
  327. "in off state: %d", wl->state);
  328. ret = -EBUSY;
  329. goto out;
  330. }
  331. wl->state = WL1271_STATE_PLT;
  332. ret = wl1271_chip_wakeup(wl);
  333. if (ret < 0)
  334. goto out;
  335. ret = wl1271_boot(wl);
  336. if (ret < 0)
  337. goto out;
  338. wl1271_notice("firmware booted in PLT mode (%s)", wl->chip.fw_ver);
  339. ret = wl1271_plt_init(wl);
  340. if (ret < 0)
  341. goto out;
  342. out:
  343. mutex_unlock(&wl->mutex);
  344. return ret;
  345. }
  346. int wl1271_plt_stop(struct wl1271 *wl)
  347. {
  348. int ret = 0;
  349. mutex_lock(&wl->mutex);
  350. wl1271_notice("power down");
  351. if (wl->state != WL1271_STATE_PLT) {
  352. wl1271_error("cannot power down because not in PLT "
  353. "state: %d", wl->state);
  354. ret = -EBUSY;
  355. goto out;
  356. }
  357. wl1271_disable_interrupts(wl);
  358. wl1271_power_off(wl);
  359. wl->state = WL1271_STATE_OFF;
  360. out:
  361. mutex_unlock(&wl->mutex);
  362. return ret;
  363. }
  364. static int wl1271_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
  365. {
  366. struct wl1271 *wl = hw->priv;
  367. skb_queue_tail(&wl->tx_queue, skb);
  368. /*
  369. * The chip specific setup must run before the first TX packet -
  370. * before that, the tx_work will not be initialized!
  371. */
  372. schedule_work(&wl->tx_work);
  373. /*
  374. * The workqueue is slow to process the tx_queue and we need stop
  375. * the queue here, otherwise the queue will get too long.
  376. */
  377. if (skb_queue_len(&wl->tx_queue) >= WL1271_TX_QUEUE_MAX_LENGTH) {
  378. ieee80211_stop_queues(wl->hw);
  379. /*
  380. * FIXME: this is racy, the variable is not properly
  381. * protected. Maybe fix this by removing the stupid
  382. * variable altogether and checking the real queue state?
  383. */
  384. wl->tx_queue_stopped = true;
  385. }
  386. return NETDEV_TX_OK;
  387. }
  388. static int wl1271_op_start(struct ieee80211_hw *hw)
  389. {
  390. struct wl1271 *wl = hw->priv;
  391. int ret = 0;
  392. wl1271_debug(DEBUG_MAC80211, "mac80211 start");
  393. mutex_lock(&wl->mutex);
  394. if (wl->state != WL1271_STATE_OFF) {
  395. wl1271_error("cannot start because not in off state: %d",
  396. wl->state);
  397. ret = -EBUSY;
  398. goto out;
  399. }
  400. ret = wl1271_chip_wakeup(wl);
  401. if (ret < 0)
  402. goto out;
  403. ret = wl1271_boot(wl);
  404. if (ret < 0)
  405. goto out;
  406. ret = wl1271_hw_init(wl);
  407. if (ret < 0)
  408. goto out;
  409. wl->state = WL1271_STATE_ON;
  410. wl1271_info("firmware booted (%s)", wl->chip.fw_ver);
  411. out:
  412. if (ret < 0)
  413. wl1271_power_off(wl);
  414. mutex_unlock(&wl->mutex);
  415. return ret;
  416. }
  417. static void wl1271_op_stop(struct ieee80211_hw *hw)
  418. {
  419. struct wl1271 *wl = hw->priv;
  420. int i;
  421. wl1271_info("down");
  422. wl1271_debug(DEBUG_MAC80211, "mac80211 stop");
  423. mutex_lock(&wl->mutex);
  424. WARN_ON(wl->state != WL1271_STATE_ON);
  425. if (wl->scanning) {
  426. mutex_unlock(&wl->mutex);
  427. ieee80211_scan_completed(wl->hw, true);
  428. mutex_lock(&wl->mutex);
  429. wl->scanning = false;
  430. }
  431. wl->state = WL1271_STATE_OFF;
  432. wl1271_disable_interrupts(wl);
  433. mutex_unlock(&wl->mutex);
  434. cancel_work_sync(&wl->irq_work);
  435. cancel_work_sync(&wl->tx_work);
  436. cancel_work_sync(&wl->filter_work);
  437. mutex_lock(&wl->mutex);
  438. /* let's notify MAC80211 about the remaining pending TX frames */
  439. wl1271_tx_flush(wl);
  440. wl1271_power_off(wl);
  441. memset(wl->bssid, 0, ETH_ALEN);
  442. memset(wl->ssid, 0, IW_ESSID_MAX_SIZE + 1);
  443. wl->ssid_len = 0;
  444. wl->listen_int = 1;
  445. wl->bss_type = MAX_BSS_TYPE;
  446. wl->rx_counter = 0;
  447. wl->elp = false;
  448. wl->psm = 0;
  449. wl->tx_queue_stopped = false;
  450. wl->power_level = WL1271_DEFAULT_POWER_LEVEL;
  451. wl->tx_blocks_available = 0;
  452. wl->tx_results_count = 0;
  453. wl->tx_packets_count = 0;
  454. wl->time_offset = 0;
  455. wl->session_counter = 0;
  456. for (i = 0; i < NUM_TX_QUEUES; i++)
  457. wl->tx_blocks_freed[i] = 0;
  458. wl1271_debugfs_reset(wl);
  459. mutex_unlock(&wl->mutex);
  460. }
  461. static int wl1271_op_add_interface(struct ieee80211_hw *hw,
  462. struct ieee80211_if_init_conf *conf)
  463. {
  464. struct wl1271 *wl = hw->priv;
  465. DECLARE_MAC_BUF(mac);
  466. int ret = 0;
  467. wl1271_debug(DEBUG_MAC80211, "mac80211 add interface type %d mac %s",
  468. conf->type, print_mac(mac, conf->mac_addr));
  469. mutex_lock(&wl->mutex);
  470. switch (conf->type) {
  471. case NL80211_IFTYPE_STATION:
  472. wl->bss_type = BSS_TYPE_STA_BSS;
  473. break;
  474. case NL80211_IFTYPE_ADHOC:
  475. wl->bss_type = BSS_TYPE_IBSS;
  476. break;
  477. default:
  478. ret = -EOPNOTSUPP;
  479. goto out;
  480. }
  481. /* FIXME: what if conf->mac_addr changes? */
  482. out:
  483. mutex_unlock(&wl->mutex);
  484. return ret;
  485. }
  486. static void wl1271_op_remove_interface(struct ieee80211_hw *hw,
  487. struct ieee80211_if_init_conf *conf)
  488. {
  489. wl1271_debug(DEBUG_MAC80211, "mac80211 remove interface");
  490. }
  491. #if 0
  492. static int wl1271_op_config_interface(struct ieee80211_hw *hw,
  493. struct ieee80211_vif *vif,
  494. struct ieee80211_if_conf *conf)
  495. {
  496. struct wl1271 *wl = hw->priv;
  497. struct sk_buff *beacon;
  498. DECLARE_MAC_BUF(mac);
  499. int ret;
  500. wl1271_debug(DEBUG_MAC80211, "mac80211 config_interface bssid %s",
  501. print_mac(mac, conf->bssid));
  502. wl1271_dump_ascii(DEBUG_MAC80211, "ssid: ", conf->ssid,
  503. conf->ssid_len);
  504. mutex_lock(&wl->mutex);
  505. ret = wl1271_ps_elp_wakeup(wl, false);
  506. if (ret < 0)
  507. goto out;
  508. memcpy(wl->bssid, conf->bssid, ETH_ALEN);
  509. ret = wl1271_cmd_build_null_data(wl);
  510. if (ret < 0)
  511. goto out_sleep;
  512. wl->ssid_len = conf->ssid_len;
  513. if (wl->ssid_len)
  514. memcpy(wl->ssid, conf->ssid, wl->ssid_len);
  515. if (wl->bss_type != BSS_TYPE_IBSS) {
  516. /* FIXME: replace the magic numbers with proper definitions */
  517. ret = wl1271_cmd_join(wl, wl->bss_type, 5, 100, 1);
  518. if (ret < 0)
  519. goto out_sleep;
  520. }
  521. if (conf->changed & IEEE80211_IFCC_BEACON) {
  522. beacon = ieee80211_beacon_get(hw, vif);
  523. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_BEACON,
  524. beacon->data, beacon->len);
  525. if (ret < 0) {
  526. dev_kfree_skb(beacon);
  527. goto out_sleep;
  528. }
  529. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PROBE_RESPONSE,
  530. beacon->data, beacon->len);
  531. dev_kfree_skb(beacon);
  532. if (ret < 0)
  533. goto out_sleep;
  534. /* FIXME: replace the magic numbers with proper definitions */
  535. ret = wl1271_cmd_join(wl, wl->bss_type, 1, 100, 0);
  536. if (ret < 0)
  537. goto out_sleep;
  538. }
  539. out_sleep:
  540. wl1271_ps_elp_sleep(wl);
  541. out:
  542. mutex_unlock(&wl->mutex);
  543. return ret;
  544. }
  545. #endif
  546. static int wl1271_op_config(struct ieee80211_hw *hw, u32 changed)
  547. {
  548. struct wl1271 *wl = hw->priv;
  549. struct ieee80211_conf *conf = &hw->conf;
  550. int channel, ret = 0;
  551. channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
  552. wl1271_debug(DEBUG_MAC80211, "mac80211 config ch %d psm %s power %d",
  553. channel,
  554. conf->flags & IEEE80211_CONF_PS ? "on" : "off",
  555. conf->power_level);
  556. mutex_lock(&wl->mutex);
  557. ret = wl1271_ps_elp_wakeup(wl, false);
  558. if (ret < 0)
  559. goto out;
  560. if (channel != wl->channel) {
  561. u8 old_channel = wl->channel;
  562. wl->channel = channel;
  563. /* FIXME: use beacon interval provided by mac80211 */
  564. ret = wl1271_cmd_join(wl, wl->bss_type, 1, 100, 0);
  565. if (ret < 0) {
  566. wl->channel = old_channel;
  567. goto out_sleep;
  568. }
  569. }
  570. ret = wl1271_cmd_build_null_data(wl);
  571. if (ret < 0)
  572. goto out_sleep;
  573. if (conf->flags & IEEE80211_CONF_PS && !wl->psm_requested) {
  574. wl1271_info("psm enabled");
  575. wl->psm_requested = true;
  576. /*
  577. * We enter PSM only if we're already associated.
  578. * If we're not, we'll enter it when joining an SSID,
  579. * through the bss_info_changed() hook.
  580. */
  581. ret = wl1271_ps_set_mode(wl, STATION_POWER_SAVE_MODE);
  582. } else if (!(conf->flags & IEEE80211_CONF_PS) &&
  583. wl->psm_requested) {
  584. wl1271_info("psm disabled");
  585. wl->psm_requested = false;
  586. if (wl->psm)
  587. ret = wl1271_ps_set_mode(wl, STATION_ACTIVE_MODE);
  588. }
  589. if (conf->power_level != wl->power_level) {
  590. ret = wl1271_acx_tx_power(wl, conf->power_level);
  591. if (ret < 0)
  592. goto out;
  593. wl->power_level = conf->power_level;
  594. }
  595. out_sleep:
  596. wl1271_ps_elp_sleep(wl);
  597. out:
  598. mutex_unlock(&wl->mutex);
  599. return ret;
  600. }
  601. #define WL1271_SUPPORTED_FILTERS (FIF_PROMISC_IN_BSS | \
  602. FIF_ALLMULTI | \
  603. FIF_FCSFAIL | \
  604. FIF_BCN_PRBRESP_PROMISC | \
  605. FIF_CONTROL | \
  606. FIF_OTHER_BSS)
  607. static void wl1271_op_configure_filter(struct ieee80211_hw *hw,
  608. unsigned int changed,
  609. unsigned int *total,
  610. int mc_count,
  611. struct dev_addr_list *mc_list)
  612. {
  613. struct wl1271 *wl = hw->priv;
  614. wl1271_debug(DEBUG_MAC80211, "mac80211 configure filter");
  615. *total &= WL1271_SUPPORTED_FILTERS;
  616. changed &= WL1271_SUPPORTED_FILTERS;
  617. if (changed == 0)
  618. return;
  619. /* FIXME: wl->rx_config and wl->rx_filter are not protected */
  620. wl->rx_config = WL1271_DEFAULT_RX_CONFIG;
  621. wl->rx_filter = WL1271_DEFAULT_RX_FILTER;
  622. /*
  623. * FIXME: workqueues need to be properly cancelled on stop(), for
  624. * now let's just disable changing the filter settings. They will
  625. * be updated any on config().
  626. */
  627. /* schedule_work(&wl->filter_work); */
  628. }
  629. static int wl1271_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  630. struct ieee80211_vif *vif,
  631. struct ieee80211_sta *sta,
  632. struct ieee80211_key_conf *key_conf)
  633. {
  634. struct wl1271 *wl = hw->priv;
  635. const u8 *addr;
  636. int ret;
  637. u8 key_type;
  638. static const u8 bcast_addr[ETH_ALEN] =
  639. { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
  640. wl1271_debug(DEBUG_MAC80211, "mac80211 set key");
  641. addr = sta ? sta->addr : bcast_addr;
  642. wl1271_debug(DEBUG_CRYPT, "CMD: 0x%x", cmd);
  643. wl1271_dump(DEBUG_CRYPT, "ADDR: ", addr, ETH_ALEN);
  644. wl1271_debug(DEBUG_CRYPT, "Key: algo:0x%x, id:%d, len:%d flags 0x%x",
  645. key_conf->alg, key_conf->keyidx,
  646. key_conf->keylen, key_conf->flags);
  647. wl1271_dump(DEBUG_CRYPT, "KEY: ", key_conf->key, key_conf->keylen);
  648. if (is_zero_ether_addr(addr)) {
  649. /* We dont support TX only encryption */
  650. ret = -EOPNOTSUPP;
  651. goto out;
  652. }
  653. mutex_lock(&wl->mutex);
  654. ret = wl1271_ps_elp_wakeup(wl, false);
  655. if (ret < 0)
  656. goto out_unlock;
  657. switch (key_conf->alg) {
  658. case ALG_WEP:
  659. key_type = KEY_WEP;
  660. key_conf->hw_key_idx = key_conf->keyidx;
  661. break;
  662. case ALG_TKIP:
  663. key_type = KEY_TKIP;
  664. key_conf->hw_key_idx = key_conf->keyidx;
  665. break;
  666. case ALG_CCMP:
  667. key_type = KEY_AES;
  668. key_conf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  669. break;
  670. default:
  671. wl1271_error("Unknown key algo 0x%x", key_conf->alg);
  672. ret = -EOPNOTSUPP;
  673. goto out_sleep;
  674. }
  675. switch (cmd) {
  676. case SET_KEY:
  677. ret = wl1271_cmd_set_key(wl, KEY_ADD_OR_REPLACE,
  678. key_conf->keyidx, key_type,
  679. key_conf->keylen, key_conf->key,
  680. addr);
  681. if (ret < 0) {
  682. wl1271_error("Could not add or replace key");
  683. goto out_sleep;
  684. }
  685. break;
  686. case DISABLE_KEY:
  687. ret = wl1271_cmd_set_key(wl, KEY_REMOVE,
  688. key_conf->keyidx, key_type,
  689. key_conf->keylen, key_conf->key,
  690. addr);
  691. if (ret < 0) {
  692. wl1271_error("Could not remove key");
  693. goto out_sleep;
  694. }
  695. break;
  696. default:
  697. wl1271_error("Unsupported key cmd 0x%x", cmd);
  698. ret = -EOPNOTSUPP;
  699. goto out_sleep;
  700. break;
  701. }
  702. out_sleep:
  703. wl1271_ps_elp_sleep(wl);
  704. out_unlock:
  705. mutex_unlock(&wl->mutex);
  706. out:
  707. return ret;
  708. }
  709. static int wl1271_op_hw_scan(struct ieee80211_hw *hw,
  710. struct cfg80211_scan_request *req)
  711. {
  712. struct wl1271 *wl = hw->priv;
  713. int ret;
  714. u8 *ssid = NULL;
  715. size_t ssid_len = 0;
  716. wl1271_debug(DEBUG_MAC80211, "mac80211 hw scan");
  717. if (req->n_ssids) {
  718. ssid = req->ssids[0].ssid;
  719. ssid_len = req->ssids[0].ssid_len;
  720. }
  721. mutex_lock(&wl->mutex);
  722. ret = wl1271_ps_elp_wakeup(wl, false);
  723. if (ret < 0)
  724. goto out;
  725. ret = wl1271_cmd_scan(hw->priv, ssid, ssid_len, 1, 0, 13, 3);
  726. wl1271_ps_elp_sleep(wl);
  727. out:
  728. mutex_unlock(&wl->mutex);
  729. return ret;
  730. }
  731. static int wl1271_op_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
  732. {
  733. struct wl1271 *wl = hw->priv;
  734. int ret;
  735. mutex_lock(&wl->mutex);
  736. ret = wl1271_ps_elp_wakeup(wl, false);
  737. if (ret < 0)
  738. goto out;
  739. ret = wl1271_acx_rts_threshold(wl, (u16) value);
  740. if (ret < 0)
  741. wl1271_warning("wl1271_op_set_rts_threshold failed: %d", ret);
  742. wl1271_ps_elp_sleep(wl);
  743. out:
  744. mutex_unlock(&wl->mutex);
  745. return ret;
  746. }
  747. static void wl1271_op_bss_info_changed(struct ieee80211_hw *hw,
  748. struct ieee80211_vif *vif,
  749. struct ieee80211_bss_conf *bss_conf,
  750. u32 changed)
  751. {
  752. enum wl1271_cmd_ps_mode mode;
  753. struct wl1271 *wl = hw->priv;
  754. int ret;
  755. wl1271_debug(DEBUG_MAC80211, "mac80211 bss info changed");
  756. mutex_lock(&wl->mutex);
  757. ret = wl1271_ps_elp_wakeup(wl, false);
  758. if (ret < 0)
  759. goto out;
  760. if (changed & BSS_CHANGED_ASSOC) {
  761. if (bss_conf->assoc) {
  762. wl->aid = bss_conf->aid;
  763. ret = wl1271_cmd_build_ps_poll(wl, wl->aid);
  764. if (ret < 0)
  765. goto out_sleep;
  766. ret = wl1271_acx_aid(wl, wl->aid);
  767. if (ret < 0)
  768. goto out_sleep;
  769. /* If we want to go in PSM but we're not there yet */
  770. if (wl->psm_requested && !wl->psm) {
  771. mode = STATION_POWER_SAVE_MODE;
  772. ret = wl1271_ps_set_mode(wl, mode);
  773. if (ret < 0)
  774. goto out_sleep;
  775. }
  776. }
  777. }
  778. if (changed & BSS_CHANGED_ERP_SLOT) {
  779. if (bss_conf->use_short_slot)
  780. ret = wl1271_acx_slot(wl, SLOT_TIME_SHORT);
  781. else
  782. ret = wl1271_acx_slot(wl, SLOT_TIME_LONG);
  783. if (ret < 0) {
  784. wl1271_warning("Set slot time failed %d", ret);
  785. goto out_sleep;
  786. }
  787. }
  788. if (changed & BSS_CHANGED_ERP_PREAMBLE) {
  789. if (bss_conf->use_short_preamble)
  790. wl1271_acx_set_preamble(wl, ACX_PREAMBLE_SHORT);
  791. else
  792. wl1271_acx_set_preamble(wl, ACX_PREAMBLE_LONG);
  793. }
  794. if (changed & BSS_CHANGED_ERP_CTS_PROT) {
  795. if (bss_conf->use_cts_prot)
  796. ret = wl1271_acx_cts_protect(wl, CTSPROTECT_ENABLE);
  797. else
  798. ret = wl1271_acx_cts_protect(wl, CTSPROTECT_DISABLE);
  799. if (ret < 0) {
  800. wl1271_warning("Set ctsprotect failed %d", ret);
  801. goto out_sleep;
  802. }
  803. }
  804. out_sleep:
  805. wl1271_ps_elp_sleep(wl);
  806. out:
  807. mutex_unlock(&wl->mutex);
  808. }
  809. /* can't be const, mac80211 writes to this */
  810. static struct ieee80211_rate wl1271_rates[] = {
  811. { .bitrate = 10,
  812. .hw_value = 0x1,
  813. .hw_value_short = 0x1, },
  814. { .bitrate = 20,
  815. .hw_value = 0x2,
  816. .hw_value_short = 0x2,
  817. .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  818. { .bitrate = 55,
  819. .hw_value = 0x4,
  820. .hw_value_short = 0x4,
  821. .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  822. { .bitrate = 110,
  823. .hw_value = 0x20,
  824. .hw_value_short = 0x20,
  825. .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  826. { .bitrate = 60,
  827. .hw_value = 0x8,
  828. .hw_value_short = 0x8, },
  829. { .bitrate = 90,
  830. .hw_value = 0x10,
  831. .hw_value_short = 0x10, },
  832. { .bitrate = 120,
  833. .hw_value = 0x40,
  834. .hw_value_short = 0x40, },
  835. { .bitrate = 180,
  836. .hw_value = 0x80,
  837. .hw_value_short = 0x80, },
  838. { .bitrate = 240,
  839. .hw_value = 0x200,
  840. .hw_value_short = 0x200, },
  841. { .bitrate = 360,
  842. .hw_value = 0x400,
  843. .hw_value_short = 0x400, },
  844. { .bitrate = 480,
  845. .hw_value = 0x800,
  846. .hw_value_short = 0x800, },
  847. { .bitrate = 540,
  848. .hw_value = 0x1000,
  849. .hw_value_short = 0x1000, },
  850. };
  851. /* can't be const, mac80211 writes to this */
  852. static struct ieee80211_channel wl1271_channels[] = {
  853. { .hw_value = 1, .center_freq = 2412},
  854. { .hw_value = 2, .center_freq = 2417},
  855. { .hw_value = 3, .center_freq = 2422},
  856. { .hw_value = 4, .center_freq = 2427},
  857. { .hw_value = 5, .center_freq = 2432},
  858. { .hw_value = 6, .center_freq = 2437},
  859. { .hw_value = 7, .center_freq = 2442},
  860. { .hw_value = 8, .center_freq = 2447},
  861. { .hw_value = 9, .center_freq = 2452},
  862. { .hw_value = 10, .center_freq = 2457},
  863. { .hw_value = 11, .center_freq = 2462},
  864. { .hw_value = 12, .center_freq = 2467},
  865. { .hw_value = 13, .center_freq = 2472},
  866. };
  867. /* can't be const, mac80211 writes to this */
  868. static struct ieee80211_supported_band wl1271_band_2ghz = {
  869. .channels = wl1271_channels,
  870. .n_channels = ARRAY_SIZE(wl1271_channels),
  871. .bitrates = wl1271_rates,
  872. .n_bitrates = ARRAY_SIZE(wl1271_rates),
  873. };
  874. static const struct ieee80211_ops wl1271_ops = {
  875. .start = wl1271_op_start,
  876. .stop = wl1271_op_stop,
  877. .add_interface = wl1271_op_add_interface,
  878. .remove_interface = wl1271_op_remove_interface,
  879. .config = wl1271_op_config,
  880. /* .config_interface = wl1271_op_config_interface, */
  881. .configure_filter = wl1271_op_configure_filter,
  882. .tx = wl1271_op_tx,
  883. .set_key = wl1271_op_set_key,
  884. .hw_scan = wl1271_op_hw_scan,
  885. .bss_info_changed = wl1271_op_bss_info_changed,
  886. .set_rts_threshold = wl1271_op_set_rts_threshold,
  887. };
  888. static int wl1271_register_hw(struct wl1271 *wl)
  889. {
  890. int ret;
  891. if (wl->mac80211_registered)
  892. return 0;
  893. SET_IEEE80211_PERM_ADDR(wl->hw, wl->mac_addr);
  894. ret = ieee80211_register_hw(wl->hw);
  895. if (ret < 0) {
  896. wl1271_error("unable to register mac80211 hw: %d", ret);
  897. return ret;
  898. }
  899. wl->mac80211_registered = true;
  900. wl1271_notice("loaded");
  901. return 0;
  902. }
  903. static int wl1271_init_ieee80211(struct wl1271 *wl)
  904. {
  905. /*
  906. * The tx descriptor buffer and the TKIP space.
  907. *
  908. * FIXME: add correct 1271 descriptor size
  909. */
  910. wl->hw->extra_tx_headroom = WL1271_TKIP_IV_SPACE;
  911. /* unit us */
  912. /* FIXME: find a proper value */
  913. wl->hw->channel_change_time = 10000;
  914. wl->hw->flags = IEEE80211_HW_SIGNAL_DBM |
  915. IEEE80211_HW_NOISE_DBM;
  916. wl->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
  917. wl->hw->wiphy->max_scan_ssids = 1;
  918. wl->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &wl1271_band_2ghz;
  919. SET_IEEE80211_DEV(wl->hw, &wl->spi->dev);
  920. return 0;
  921. }
  922. static void wl1271_device_release(struct device *dev)
  923. {
  924. }
  925. static struct platform_device wl1271_device = {
  926. .name = "wl1271",
  927. .id = -1,
  928. /* device model insists to have a release function */
  929. .dev = {
  930. .release = wl1271_device_release,
  931. },
  932. };
  933. #define WL1271_DEFAULT_CHANNEL 0
  934. static int __devinit wl1271_probe(struct spi_device *spi)
  935. {
  936. struct wl12xx_platform_data *pdata;
  937. struct ieee80211_hw *hw;
  938. struct wl1271 *wl;
  939. int ret, i;
  940. static const u8 nokia_oui[3] = {0x00, 0x1f, 0xdf};
  941. pdata = spi->dev.platform_data;
  942. if (!pdata) {
  943. wl1271_error("no platform data");
  944. return -ENODEV;
  945. }
  946. hw = ieee80211_alloc_hw(sizeof(*wl), &wl1271_ops);
  947. if (!hw) {
  948. wl1271_error("could not alloc ieee80211_hw");
  949. return -ENOMEM;
  950. }
  951. wl = hw->priv;
  952. memset(wl, 0, sizeof(*wl));
  953. wl->hw = hw;
  954. dev_set_drvdata(&spi->dev, wl);
  955. wl->spi = spi;
  956. skb_queue_head_init(&wl->tx_queue);
  957. INIT_WORK(&wl->filter_work, wl1271_filter_work);
  958. wl->channel = WL1271_DEFAULT_CHANNEL;
  959. wl->scanning = false;
  960. wl->default_key = 0;
  961. wl->listen_int = 1;
  962. wl->rx_counter = 0;
  963. wl->rx_config = WL1271_DEFAULT_RX_CONFIG;
  964. wl->rx_filter = WL1271_DEFAULT_RX_FILTER;
  965. wl->elp = false;
  966. wl->psm = 0;
  967. wl->psm_requested = false;
  968. wl->tx_queue_stopped = false;
  969. wl->power_level = WL1271_DEFAULT_POWER_LEVEL;
  970. /* We use the default power on sleep time until we know which chip
  971. * we're using */
  972. for (i = 0; i < FW_TX_CMPLT_BLOCK_SIZE; i++)
  973. wl->tx_frames[i] = NULL;
  974. spin_lock_init(&wl->wl_lock);
  975. /*
  976. * In case our MAC address is not correctly set,
  977. * we use a random but Nokia MAC.
  978. */
  979. memcpy(wl->mac_addr, nokia_oui, 3);
  980. get_random_bytes(wl->mac_addr + 3, 3);
  981. wl->state = WL1271_STATE_OFF;
  982. mutex_init(&wl->mutex);
  983. wl->rx_descriptor = kmalloc(sizeof(*wl->rx_descriptor), GFP_KERNEL);
  984. if (!wl->rx_descriptor) {
  985. wl1271_error("could not allocate memory for rx descriptor");
  986. ret = -ENOMEM;
  987. goto out_free;
  988. }
  989. /* This is the only SPI value that we need to set here, the rest
  990. * comes from the board-peripherals file */
  991. spi->bits_per_word = 32;
  992. ret = spi_setup(spi);
  993. if (ret < 0) {
  994. wl1271_error("spi_setup failed");
  995. goto out_free;
  996. }
  997. wl->set_power = pdata->set_power;
  998. if (!wl->set_power) {
  999. wl1271_error("set power function missing in platform data");
  1000. ret = -ENODEV;
  1001. goto out_free;
  1002. }
  1003. wl->irq = spi->irq;
  1004. if (wl->irq < 0) {
  1005. wl1271_error("irq missing in platform data");
  1006. ret = -ENODEV;
  1007. goto out_free;
  1008. }
  1009. ret = request_irq(wl->irq, wl1271_irq, 0, DRIVER_NAME, wl);
  1010. if (ret < 0) {
  1011. wl1271_error("request_irq() failed: %d", ret);
  1012. goto out_free;
  1013. }
  1014. set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
  1015. disable_irq(wl->irq);
  1016. ret = platform_device_register(&wl1271_device);
  1017. if (ret) {
  1018. wl1271_error("couldn't register platform device");
  1019. goto out_irq;
  1020. }
  1021. dev_set_drvdata(&wl1271_device.dev, wl);
  1022. ret = wl1271_init_ieee80211(wl);
  1023. if (ret)
  1024. goto out_platform;
  1025. ret = wl1271_register_hw(wl);
  1026. if (ret)
  1027. goto out_platform;
  1028. wl1271_debugfs_init(wl);
  1029. wl1271_notice("initialized");
  1030. return 0;
  1031. out_platform:
  1032. platform_device_unregister(&wl1271_device);
  1033. out_irq:
  1034. free_irq(wl->irq, wl);
  1035. out_free:
  1036. kfree(wl->rx_descriptor);
  1037. wl->rx_descriptor = NULL;
  1038. ieee80211_free_hw(hw);
  1039. return ret;
  1040. }
  1041. static int __devexit wl1271_remove(struct spi_device *spi)
  1042. {
  1043. struct wl1271 *wl = dev_get_drvdata(&spi->dev);
  1044. ieee80211_unregister_hw(wl->hw);
  1045. wl1271_debugfs_exit(wl);
  1046. platform_device_unregister(&wl1271_device);
  1047. free_irq(wl->irq, wl);
  1048. kfree(wl->target_mem_map);
  1049. kfree(wl->fw);
  1050. wl->fw = NULL;
  1051. kfree(wl->nvs);
  1052. wl->nvs = NULL;
  1053. kfree(wl->rx_descriptor);
  1054. wl->rx_descriptor = NULL;
  1055. kfree(wl->fw_status);
  1056. kfree(wl->tx_res_if);
  1057. ieee80211_free_hw(wl->hw);
  1058. return 0;
  1059. }
  1060. static struct spi_driver wl1271_spi_driver = {
  1061. .driver = {
  1062. .name = "wl1271",
  1063. .bus = &spi_bus_type,
  1064. .owner = THIS_MODULE,
  1065. },
  1066. .probe = wl1271_probe,
  1067. .remove = __devexit_p(wl1271_remove),
  1068. };
  1069. static int __init wl1271_init(void)
  1070. {
  1071. int ret;
  1072. ret = spi_register_driver(&wl1271_spi_driver);
  1073. if (ret < 0) {
  1074. wl1271_error("failed to register spi driver: %d", ret);
  1075. goto out;
  1076. }
  1077. out:
  1078. return ret;
  1079. }
  1080. static void __exit wl1271_exit(void)
  1081. {
  1082. spi_unregister_driver(&wl1271_spi_driver);
  1083. wl1271_notice("unloaded");
  1084. }
  1085. module_init(wl1271_init);
  1086. module_exit(wl1271_exit);
  1087. MODULE_LICENSE("GPL");
  1088. MODULE_AUTHOR("Luciano Coelho <luciano.coelho@nokia.com>");