wl1271_main.c 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394
  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,
  150. WL1271_ACX_INTR_ALL & ~(WL1271_INTR_MASK));
  151. wl1271_ps_elp_sleep(wl);
  152. out:
  153. mutex_unlock(&wl->mutex);
  154. }
  155. static irqreturn_t wl1271_irq(int irq, void *cookie)
  156. {
  157. struct wl1271 *wl;
  158. unsigned long flags;
  159. wl1271_debug(DEBUG_IRQ, "IRQ");
  160. wl = cookie;
  161. /* complete the ELP completion */
  162. spin_lock_irqsave(&wl->wl_lock, flags);
  163. if (wl->elp_compl) {
  164. complete(wl->elp_compl);
  165. wl->elp_compl = NULL;
  166. }
  167. schedule_work(&wl->irq_work);
  168. spin_unlock_irqrestore(&wl->wl_lock, flags);
  169. return IRQ_HANDLED;
  170. }
  171. static int wl1271_fetch_firmware(struct wl1271 *wl)
  172. {
  173. const struct firmware *fw;
  174. int ret;
  175. ret = request_firmware(&fw, WL1271_FW_NAME, &wl->spi->dev);
  176. if (ret < 0) {
  177. wl1271_error("could not get firmware: %d", ret);
  178. return ret;
  179. }
  180. if (fw->size % 4) {
  181. wl1271_error("firmware size is not multiple of 32 bits: %zu",
  182. fw->size);
  183. ret = -EILSEQ;
  184. goto out;
  185. }
  186. wl->fw_len = fw->size;
  187. wl->fw = kmalloc(wl->fw_len, GFP_KERNEL);
  188. if (!wl->fw) {
  189. wl1271_error("could not allocate memory for the firmware");
  190. ret = -ENOMEM;
  191. goto out;
  192. }
  193. memcpy(wl->fw, fw->data, wl->fw_len);
  194. ret = 0;
  195. out:
  196. release_firmware(fw);
  197. return ret;
  198. }
  199. static int wl1271_fetch_nvs(struct wl1271 *wl)
  200. {
  201. const struct firmware *fw;
  202. int ret;
  203. ret = request_firmware(&fw, WL1271_NVS_NAME, &wl->spi->dev);
  204. if (ret < 0) {
  205. wl1271_error("could not get nvs file: %d", ret);
  206. return ret;
  207. }
  208. if (fw->size % 4) {
  209. wl1271_error("nvs size is not multiple of 32 bits: %zu",
  210. fw->size);
  211. ret = -EILSEQ;
  212. goto out;
  213. }
  214. wl->nvs_len = fw->size;
  215. wl->nvs = kmalloc(wl->nvs_len, GFP_KERNEL);
  216. if (!wl->nvs) {
  217. wl1271_error("could not allocate memory for the nvs file");
  218. ret = -ENOMEM;
  219. goto out;
  220. }
  221. memcpy(wl->nvs, fw->data, wl->nvs_len);
  222. ret = 0;
  223. out:
  224. release_firmware(fw);
  225. return ret;
  226. }
  227. static void wl1271_fw_wakeup(struct wl1271 *wl)
  228. {
  229. u32 elp_reg;
  230. elp_reg = ELPCTRL_WAKE_UP;
  231. wl1271_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, elp_reg);
  232. }
  233. static int wl1271_setup(struct wl1271 *wl)
  234. {
  235. wl->fw_status = kmalloc(sizeof(*wl->fw_status), GFP_KERNEL);
  236. if (!wl->fw_status)
  237. return -ENOMEM;
  238. wl->tx_res_if = kmalloc(sizeof(*wl->tx_res_if), GFP_KERNEL);
  239. if (!wl->tx_res_if) {
  240. kfree(wl->fw_status);
  241. return -ENOMEM;
  242. }
  243. INIT_WORK(&wl->irq_work, wl1271_irq_work);
  244. INIT_WORK(&wl->tx_work, wl1271_tx_work);
  245. return 0;
  246. }
  247. static int wl1271_chip_wakeup(struct wl1271 *wl)
  248. {
  249. int ret = 0;
  250. wl1271_power_on(wl);
  251. msleep(WL1271_POWER_ON_SLEEP);
  252. wl1271_spi_reset(wl);
  253. wl1271_spi_init(wl);
  254. /* We don't need a real memory partition here, because we only want
  255. * to use the registers at this point. */
  256. wl1271_set_partition(wl,
  257. 0x00000000,
  258. 0x00000000,
  259. REGISTERS_BASE,
  260. REGISTERS_DOWN_SIZE);
  261. /* ELP module wake up */
  262. wl1271_fw_wakeup(wl);
  263. /* whal_FwCtrl_BootSm() */
  264. /* 0. read chip id from CHIP_ID */
  265. wl->chip.id = wl1271_reg_read32(wl, CHIP_ID_B);
  266. /* 1. check if chip id is valid */
  267. switch (wl->chip.id) {
  268. case CHIP_ID_1271_PG10:
  269. wl1271_warning("chip id 0x%x (1271 PG10) support is obsolete",
  270. wl->chip.id);
  271. ret = wl1271_setup(wl);
  272. if (ret < 0)
  273. goto out;
  274. break;
  275. case CHIP_ID_1271_PG20:
  276. wl1271_debug(DEBUG_BOOT, "chip id 0x%x (1271 PG20)",
  277. wl->chip.id);
  278. ret = wl1271_setup(wl);
  279. if (ret < 0)
  280. goto out;
  281. break;
  282. default:
  283. wl1271_error("unsupported chip id: 0x%x", wl->chip.id);
  284. ret = -ENODEV;
  285. goto out;
  286. }
  287. if (wl->fw == NULL) {
  288. ret = wl1271_fetch_firmware(wl);
  289. if (ret < 0)
  290. goto out;
  291. }
  292. /* No NVS from netlink, try to get it from the filesystem */
  293. if (wl->nvs == NULL) {
  294. ret = wl1271_fetch_nvs(wl);
  295. if (ret < 0)
  296. goto out;
  297. }
  298. out:
  299. return ret;
  300. }
  301. static void wl1271_filter_work(struct work_struct *work)
  302. {
  303. struct wl1271 *wl =
  304. container_of(work, struct wl1271, filter_work);
  305. int ret;
  306. mutex_lock(&wl->mutex);
  307. if (wl->state == WL1271_STATE_OFF)
  308. goto out;
  309. ret = wl1271_ps_elp_wakeup(wl, false);
  310. if (ret < 0)
  311. goto out;
  312. /* FIXME: replace the magic numbers with proper definitions */
  313. ret = wl1271_cmd_join(wl, wl->bss_type, 1, 100, 0);
  314. if (ret < 0)
  315. goto out_sleep;
  316. out_sleep:
  317. wl1271_ps_elp_sleep(wl);
  318. out:
  319. mutex_unlock(&wl->mutex);
  320. }
  321. int wl1271_plt_start(struct wl1271 *wl)
  322. {
  323. int ret;
  324. mutex_lock(&wl->mutex);
  325. wl1271_notice("power up");
  326. if (wl->state != WL1271_STATE_OFF) {
  327. wl1271_error("cannot go into PLT state because not "
  328. "in off state: %d", wl->state);
  329. ret = -EBUSY;
  330. goto out;
  331. }
  332. wl->state = WL1271_STATE_PLT;
  333. ret = wl1271_chip_wakeup(wl);
  334. if (ret < 0)
  335. goto out;
  336. ret = wl1271_boot(wl);
  337. if (ret < 0)
  338. goto out;
  339. wl1271_notice("firmware booted in PLT mode (%s)", wl->chip.fw_ver);
  340. ret = wl1271_plt_init(wl);
  341. if (ret < 0)
  342. goto out;
  343. out:
  344. mutex_unlock(&wl->mutex);
  345. return ret;
  346. }
  347. int wl1271_plt_stop(struct wl1271 *wl)
  348. {
  349. int ret = 0;
  350. mutex_lock(&wl->mutex);
  351. wl1271_notice("power down");
  352. if (wl->state != WL1271_STATE_PLT) {
  353. wl1271_error("cannot power down because not in PLT "
  354. "state: %d", wl->state);
  355. ret = -EBUSY;
  356. goto out;
  357. }
  358. wl1271_disable_interrupts(wl);
  359. wl1271_power_off(wl);
  360. wl->state = WL1271_STATE_OFF;
  361. out:
  362. mutex_unlock(&wl->mutex);
  363. return ret;
  364. }
  365. static int wl1271_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
  366. {
  367. struct wl1271 *wl = hw->priv;
  368. skb_queue_tail(&wl->tx_queue, skb);
  369. /*
  370. * The chip specific setup must run before the first TX packet -
  371. * before that, the tx_work will not be initialized!
  372. */
  373. schedule_work(&wl->tx_work);
  374. /*
  375. * The workqueue is slow to process the tx_queue and we need stop
  376. * the queue here, otherwise the queue will get too long.
  377. */
  378. if (skb_queue_len(&wl->tx_queue) >= WL1271_TX_QUEUE_MAX_LENGTH) {
  379. ieee80211_stop_queues(wl->hw);
  380. /*
  381. * FIXME: this is racy, the variable is not properly
  382. * protected. Maybe fix this by removing the stupid
  383. * variable altogether and checking the real queue state?
  384. */
  385. wl->tx_queue_stopped = true;
  386. }
  387. return NETDEV_TX_OK;
  388. }
  389. static int wl1271_op_start(struct ieee80211_hw *hw)
  390. {
  391. struct wl1271 *wl = hw->priv;
  392. int ret = 0;
  393. wl1271_debug(DEBUG_MAC80211, "mac80211 start");
  394. mutex_lock(&wl->mutex);
  395. if (wl->state != WL1271_STATE_OFF) {
  396. wl1271_error("cannot start because not in off state: %d",
  397. wl->state);
  398. ret = -EBUSY;
  399. goto out;
  400. }
  401. ret = wl1271_chip_wakeup(wl);
  402. if (ret < 0)
  403. goto out;
  404. ret = wl1271_boot(wl);
  405. if (ret < 0)
  406. goto out;
  407. ret = wl1271_hw_init(wl);
  408. if (ret < 0)
  409. goto out;
  410. wl->state = WL1271_STATE_ON;
  411. wl1271_info("firmware booted (%s)", wl->chip.fw_ver);
  412. out:
  413. if (ret < 0)
  414. wl1271_power_off(wl);
  415. mutex_unlock(&wl->mutex);
  416. return ret;
  417. }
  418. static void wl1271_op_stop(struct ieee80211_hw *hw)
  419. {
  420. struct wl1271 *wl = hw->priv;
  421. int i;
  422. wl1271_info("down");
  423. wl1271_debug(DEBUG_MAC80211, "mac80211 stop");
  424. mutex_lock(&wl->mutex);
  425. WARN_ON(wl->state != WL1271_STATE_ON);
  426. if (wl->scanning) {
  427. mutex_unlock(&wl->mutex);
  428. ieee80211_scan_completed(wl->hw, true);
  429. mutex_lock(&wl->mutex);
  430. wl->scanning = false;
  431. }
  432. wl->state = WL1271_STATE_OFF;
  433. wl1271_disable_interrupts(wl);
  434. mutex_unlock(&wl->mutex);
  435. cancel_work_sync(&wl->irq_work);
  436. cancel_work_sync(&wl->tx_work);
  437. cancel_work_sync(&wl->filter_work);
  438. mutex_lock(&wl->mutex);
  439. /* let's notify MAC80211 about the remaining pending TX frames */
  440. wl1271_tx_flush(wl);
  441. wl1271_power_off(wl);
  442. memset(wl->bssid, 0, ETH_ALEN);
  443. memset(wl->ssid, 0, IW_ESSID_MAX_SIZE + 1);
  444. wl->ssid_len = 0;
  445. wl->listen_int = 1;
  446. wl->bss_type = MAX_BSS_TYPE;
  447. wl->rx_counter = 0;
  448. wl->elp = false;
  449. wl->psm = 0;
  450. wl->tx_queue_stopped = false;
  451. wl->power_level = WL1271_DEFAULT_POWER_LEVEL;
  452. wl->tx_blocks_available = 0;
  453. wl->tx_results_count = 0;
  454. wl->tx_packets_count = 0;
  455. wl->time_offset = 0;
  456. wl->session_counter = 0;
  457. for (i = 0; i < NUM_TX_QUEUES; i++)
  458. wl->tx_blocks_freed[i] = 0;
  459. wl1271_debugfs_reset(wl);
  460. mutex_unlock(&wl->mutex);
  461. }
  462. static int wl1271_op_add_interface(struct ieee80211_hw *hw,
  463. struct ieee80211_if_init_conf *conf)
  464. {
  465. struct wl1271 *wl = hw->priv;
  466. int ret = 0;
  467. wl1271_debug(DEBUG_MAC80211, "mac80211 add interface type %d mac %pM",
  468. conf->type, 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,u64 multicast)
  610. {
  611. struct wl1271 *wl = hw->priv;
  612. wl1271_debug(DEBUG_MAC80211, "mac80211 configure filter");
  613. *total &= WL1271_SUPPORTED_FILTERS;
  614. changed &= WL1271_SUPPORTED_FILTERS;
  615. if (changed == 0)
  616. return;
  617. /* FIXME: wl->rx_config and wl->rx_filter are not protected */
  618. wl->rx_config = WL1271_DEFAULT_RX_CONFIG;
  619. wl->rx_filter = WL1271_DEFAULT_RX_FILTER;
  620. /*
  621. * FIXME: workqueues need to be properly cancelled on stop(), for
  622. * now let's just disable changing the filter settings. They will
  623. * be updated any on config().
  624. */
  625. /* schedule_work(&wl->filter_work); */
  626. }
  627. static int wl1271_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  628. struct ieee80211_vif *vif,
  629. struct ieee80211_sta *sta,
  630. struct ieee80211_key_conf *key_conf)
  631. {
  632. struct wl1271 *wl = hw->priv;
  633. const u8 *addr;
  634. int ret;
  635. u8 key_type;
  636. static const u8 bcast_addr[ETH_ALEN] =
  637. { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
  638. wl1271_debug(DEBUG_MAC80211, "mac80211 set key");
  639. addr = sta ? sta->addr : bcast_addr;
  640. wl1271_debug(DEBUG_CRYPT, "CMD: 0x%x", cmd);
  641. wl1271_dump(DEBUG_CRYPT, "ADDR: ", addr, ETH_ALEN);
  642. wl1271_debug(DEBUG_CRYPT, "Key: algo:0x%x, id:%d, len:%d flags 0x%x",
  643. key_conf->alg, key_conf->keyidx,
  644. key_conf->keylen, key_conf->flags);
  645. wl1271_dump(DEBUG_CRYPT, "KEY: ", key_conf->key, key_conf->keylen);
  646. if (is_zero_ether_addr(addr)) {
  647. /* We dont support TX only encryption */
  648. ret = -EOPNOTSUPP;
  649. goto out;
  650. }
  651. mutex_lock(&wl->mutex);
  652. ret = wl1271_ps_elp_wakeup(wl, false);
  653. if (ret < 0)
  654. goto out_unlock;
  655. switch (key_conf->alg) {
  656. case ALG_WEP:
  657. key_type = KEY_WEP;
  658. key_conf->hw_key_idx = key_conf->keyidx;
  659. break;
  660. case ALG_TKIP:
  661. key_type = KEY_TKIP;
  662. key_conf->hw_key_idx = key_conf->keyidx;
  663. break;
  664. case ALG_CCMP:
  665. key_type = KEY_AES;
  666. key_conf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  667. break;
  668. default:
  669. wl1271_error("Unknown key algo 0x%x", key_conf->alg);
  670. ret = -EOPNOTSUPP;
  671. goto out_sleep;
  672. }
  673. switch (cmd) {
  674. case SET_KEY:
  675. ret = wl1271_cmd_set_key(wl, KEY_ADD_OR_REPLACE,
  676. key_conf->keyidx, key_type,
  677. key_conf->keylen, key_conf->key,
  678. addr);
  679. if (ret < 0) {
  680. wl1271_error("Could not add or replace key");
  681. goto out_sleep;
  682. }
  683. break;
  684. case DISABLE_KEY:
  685. ret = wl1271_cmd_set_key(wl, KEY_REMOVE,
  686. key_conf->keyidx, key_type,
  687. key_conf->keylen, key_conf->key,
  688. addr);
  689. if (ret < 0) {
  690. wl1271_error("Could not remove key");
  691. goto out_sleep;
  692. }
  693. break;
  694. default:
  695. wl1271_error("Unsupported key cmd 0x%x", cmd);
  696. ret = -EOPNOTSUPP;
  697. goto out_sleep;
  698. break;
  699. }
  700. out_sleep:
  701. wl1271_ps_elp_sleep(wl);
  702. out_unlock:
  703. mutex_unlock(&wl->mutex);
  704. out:
  705. return ret;
  706. }
  707. static int wl1271_op_hw_scan(struct ieee80211_hw *hw,
  708. struct cfg80211_scan_request *req)
  709. {
  710. struct wl1271 *wl = hw->priv;
  711. int ret;
  712. u8 *ssid = NULL;
  713. size_t ssid_len = 0;
  714. wl1271_debug(DEBUG_MAC80211, "mac80211 hw scan");
  715. if (req->n_ssids) {
  716. ssid = req->ssids[0].ssid;
  717. ssid_len = req->ssids[0].ssid_len;
  718. }
  719. mutex_lock(&wl->mutex);
  720. ret = wl1271_ps_elp_wakeup(wl, false);
  721. if (ret < 0)
  722. goto out;
  723. ret = wl1271_cmd_scan(hw->priv, ssid, ssid_len, 1, 0, 13, 3);
  724. wl1271_ps_elp_sleep(wl);
  725. out:
  726. mutex_unlock(&wl->mutex);
  727. return ret;
  728. }
  729. static int wl1271_op_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
  730. {
  731. struct wl1271 *wl = hw->priv;
  732. int ret;
  733. mutex_lock(&wl->mutex);
  734. ret = wl1271_ps_elp_wakeup(wl, false);
  735. if (ret < 0)
  736. goto out;
  737. ret = wl1271_acx_rts_threshold(wl, (u16) value);
  738. if (ret < 0)
  739. wl1271_warning("wl1271_op_set_rts_threshold failed: %d", ret);
  740. wl1271_ps_elp_sleep(wl);
  741. out:
  742. mutex_unlock(&wl->mutex);
  743. return ret;
  744. }
  745. static void wl1271_op_bss_info_changed(struct ieee80211_hw *hw,
  746. struct ieee80211_vif *vif,
  747. struct ieee80211_bss_conf *bss_conf,
  748. u32 changed)
  749. {
  750. enum wl1271_cmd_ps_mode mode;
  751. struct wl1271 *wl = hw->priv;
  752. int ret;
  753. wl1271_debug(DEBUG_MAC80211, "mac80211 bss info changed");
  754. mutex_lock(&wl->mutex);
  755. ret = wl1271_ps_elp_wakeup(wl, false);
  756. if (ret < 0)
  757. goto out;
  758. if (changed & BSS_CHANGED_ASSOC) {
  759. if (bss_conf->assoc) {
  760. wl->aid = bss_conf->aid;
  761. ret = wl1271_cmd_build_ps_poll(wl, wl->aid);
  762. if (ret < 0)
  763. goto out_sleep;
  764. ret = wl1271_acx_aid(wl, wl->aid);
  765. if (ret < 0)
  766. goto out_sleep;
  767. /* If we want to go in PSM but we're not there yet */
  768. if (wl->psm_requested && !wl->psm) {
  769. mode = STATION_POWER_SAVE_MODE;
  770. ret = wl1271_ps_set_mode(wl, mode);
  771. if (ret < 0)
  772. goto out_sleep;
  773. }
  774. }
  775. }
  776. if (changed & BSS_CHANGED_ERP_SLOT) {
  777. if (bss_conf->use_short_slot)
  778. ret = wl1271_acx_slot(wl, SLOT_TIME_SHORT);
  779. else
  780. ret = wl1271_acx_slot(wl, SLOT_TIME_LONG);
  781. if (ret < 0) {
  782. wl1271_warning("Set slot time failed %d", ret);
  783. goto out_sleep;
  784. }
  785. }
  786. if (changed & BSS_CHANGED_ERP_PREAMBLE) {
  787. if (bss_conf->use_short_preamble)
  788. wl1271_acx_set_preamble(wl, ACX_PREAMBLE_SHORT);
  789. else
  790. wl1271_acx_set_preamble(wl, ACX_PREAMBLE_LONG);
  791. }
  792. if (changed & BSS_CHANGED_ERP_CTS_PROT) {
  793. if (bss_conf->use_cts_prot)
  794. ret = wl1271_acx_cts_protect(wl, CTSPROTECT_ENABLE);
  795. else
  796. ret = wl1271_acx_cts_protect(wl, CTSPROTECT_DISABLE);
  797. if (ret < 0) {
  798. wl1271_warning("Set ctsprotect failed %d", ret);
  799. goto out_sleep;
  800. }
  801. }
  802. out_sleep:
  803. wl1271_ps_elp_sleep(wl);
  804. out:
  805. mutex_unlock(&wl->mutex);
  806. }
  807. /* can't be const, mac80211 writes to this */
  808. static struct ieee80211_rate wl1271_rates[] = {
  809. { .bitrate = 10,
  810. .hw_value = 0x1,
  811. .hw_value_short = 0x1, },
  812. { .bitrate = 20,
  813. .hw_value = 0x2,
  814. .hw_value_short = 0x2,
  815. .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  816. { .bitrate = 55,
  817. .hw_value = 0x4,
  818. .hw_value_short = 0x4,
  819. .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  820. { .bitrate = 110,
  821. .hw_value = 0x20,
  822. .hw_value_short = 0x20,
  823. .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  824. { .bitrate = 60,
  825. .hw_value = 0x8,
  826. .hw_value_short = 0x8, },
  827. { .bitrate = 90,
  828. .hw_value = 0x10,
  829. .hw_value_short = 0x10, },
  830. { .bitrate = 120,
  831. .hw_value = 0x40,
  832. .hw_value_short = 0x40, },
  833. { .bitrate = 180,
  834. .hw_value = 0x80,
  835. .hw_value_short = 0x80, },
  836. { .bitrate = 240,
  837. .hw_value = 0x200,
  838. .hw_value_short = 0x200, },
  839. { .bitrate = 360,
  840. .hw_value = 0x400,
  841. .hw_value_short = 0x400, },
  842. { .bitrate = 480,
  843. .hw_value = 0x800,
  844. .hw_value_short = 0x800, },
  845. { .bitrate = 540,
  846. .hw_value = 0x1000,
  847. .hw_value_short = 0x1000, },
  848. };
  849. /* can't be const, mac80211 writes to this */
  850. static struct ieee80211_channel wl1271_channels[] = {
  851. { .hw_value = 1, .center_freq = 2412},
  852. { .hw_value = 2, .center_freq = 2417},
  853. { .hw_value = 3, .center_freq = 2422},
  854. { .hw_value = 4, .center_freq = 2427},
  855. { .hw_value = 5, .center_freq = 2432},
  856. { .hw_value = 6, .center_freq = 2437},
  857. { .hw_value = 7, .center_freq = 2442},
  858. { .hw_value = 8, .center_freq = 2447},
  859. { .hw_value = 9, .center_freq = 2452},
  860. { .hw_value = 10, .center_freq = 2457},
  861. { .hw_value = 11, .center_freq = 2462},
  862. { .hw_value = 12, .center_freq = 2467},
  863. { .hw_value = 13, .center_freq = 2472},
  864. };
  865. /* can't be const, mac80211 writes to this */
  866. static struct ieee80211_supported_band wl1271_band_2ghz = {
  867. .channels = wl1271_channels,
  868. .n_channels = ARRAY_SIZE(wl1271_channels),
  869. .bitrates = wl1271_rates,
  870. .n_bitrates = ARRAY_SIZE(wl1271_rates),
  871. };
  872. static const struct ieee80211_ops wl1271_ops = {
  873. .start = wl1271_op_start,
  874. .stop = wl1271_op_stop,
  875. .add_interface = wl1271_op_add_interface,
  876. .remove_interface = wl1271_op_remove_interface,
  877. .config = wl1271_op_config,
  878. /* .config_interface = wl1271_op_config_interface, */
  879. .configure_filter = wl1271_op_configure_filter,
  880. .tx = wl1271_op_tx,
  881. .set_key = wl1271_op_set_key,
  882. .hw_scan = wl1271_op_hw_scan,
  883. .bss_info_changed = wl1271_op_bss_info_changed,
  884. .set_rts_threshold = wl1271_op_set_rts_threshold,
  885. };
  886. static int wl1271_register_hw(struct wl1271 *wl)
  887. {
  888. int ret;
  889. if (wl->mac80211_registered)
  890. return 0;
  891. SET_IEEE80211_PERM_ADDR(wl->hw, wl->mac_addr);
  892. ret = ieee80211_register_hw(wl->hw);
  893. if (ret < 0) {
  894. wl1271_error("unable to register mac80211 hw: %d", ret);
  895. return ret;
  896. }
  897. wl->mac80211_registered = true;
  898. wl1271_notice("loaded");
  899. return 0;
  900. }
  901. static int wl1271_init_ieee80211(struct wl1271 *wl)
  902. {
  903. /*
  904. * The tx descriptor buffer and the TKIP space.
  905. *
  906. * FIXME: add correct 1271 descriptor size
  907. */
  908. wl->hw->extra_tx_headroom = WL1271_TKIP_IV_SPACE;
  909. /* unit us */
  910. /* FIXME: find a proper value */
  911. wl->hw->channel_change_time = 10000;
  912. wl->hw->flags = IEEE80211_HW_SIGNAL_DBM |
  913. IEEE80211_HW_NOISE_DBM;
  914. wl->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
  915. wl->hw->wiphy->max_scan_ssids = 1;
  916. wl->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &wl1271_band_2ghz;
  917. SET_IEEE80211_DEV(wl->hw, &wl->spi->dev);
  918. return 0;
  919. }
  920. static void wl1271_device_release(struct device *dev)
  921. {
  922. }
  923. static struct platform_device wl1271_device = {
  924. .name = "wl1271",
  925. .id = -1,
  926. /* device model insists to have a release function */
  927. .dev = {
  928. .release = wl1271_device_release,
  929. },
  930. };
  931. #define WL1271_DEFAULT_CHANNEL 0
  932. static int __devinit wl1271_probe(struct spi_device *spi)
  933. {
  934. struct wl12xx_platform_data *pdata;
  935. struct ieee80211_hw *hw;
  936. struct wl1271 *wl;
  937. int ret, i;
  938. static const u8 nokia_oui[3] = {0x00, 0x1f, 0xdf};
  939. pdata = spi->dev.platform_data;
  940. if (!pdata) {
  941. wl1271_error("no platform data");
  942. return -ENODEV;
  943. }
  944. hw = ieee80211_alloc_hw(sizeof(*wl), &wl1271_ops);
  945. if (!hw) {
  946. wl1271_error("could not alloc ieee80211_hw");
  947. return -ENOMEM;
  948. }
  949. wl = hw->priv;
  950. memset(wl, 0, sizeof(*wl));
  951. wl->hw = hw;
  952. dev_set_drvdata(&spi->dev, wl);
  953. wl->spi = spi;
  954. skb_queue_head_init(&wl->tx_queue);
  955. INIT_WORK(&wl->filter_work, wl1271_filter_work);
  956. wl->channel = WL1271_DEFAULT_CHANNEL;
  957. wl->scanning = false;
  958. wl->default_key = 0;
  959. wl->listen_int = 1;
  960. wl->rx_counter = 0;
  961. wl->rx_config = WL1271_DEFAULT_RX_CONFIG;
  962. wl->rx_filter = WL1271_DEFAULT_RX_FILTER;
  963. wl->elp = false;
  964. wl->psm = 0;
  965. wl->psm_requested = false;
  966. wl->tx_queue_stopped = false;
  967. wl->power_level = WL1271_DEFAULT_POWER_LEVEL;
  968. /* We use the default power on sleep time until we know which chip
  969. * we're using */
  970. for (i = 0; i < FW_TX_CMPLT_BLOCK_SIZE; i++)
  971. wl->tx_frames[i] = NULL;
  972. spin_lock_init(&wl->wl_lock);
  973. /*
  974. * In case our MAC address is not correctly set,
  975. * we use a random but Nokia MAC.
  976. */
  977. memcpy(wl->mac_addr, nokia_oui, 3);
  978. get_random_bytes(wl->mac_addr + 3, 3);
  979. wl->state = WL1271_STATE_OFF;
  980. mutex_init(&wl->mutex);
  981. wl->rx_descriptor = kmalloc(sizeof(*wl->rx_descriptor), GFP_KERNEL);
  982. if (!wl->rx_descriptor) {
  983. wl1271_error("could not allocate memory for rx descriptor");
  984. ret = -ENOMEM;
  985. goto out_free;
  986. }
  987. /* This is the only SPI value that we need to set here, the rest
  988. * comes from the board-peripherals file */
  989. spi->bits_per_word = 32;
  990. ret = spi_setup(spi);
  991. if (ret < 0) {
  992. wl1271_error("spi_setup failed");
  993. goto out_free;
  994. }
  995. wl->set_power = pdata->set_power;
  996. if (!wl->set_power) {
  997. wl1271_error("set power function missing in platform data");
  998. ret = -ENODEV;
  999. goto out_free;
  1000. }
  1001. wl->irq = spi->irq;
  1002. if (wl->irq < 0) {
  1003. wl1271_error("irq missing in platform data");
  1004. ret = -ENODEV;
  1005. goto out_free;
  1006. }
  1007. ret = request_irq(wl->irq, wl1271_irq, 0, DRIVER_NAME, wl);
  1008. if (ret < 0) {
  1009. wl1271_error("request_irq() failed: %d", ret);
  1010. goto out_free;
  1011. }
  1012. set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
  1013. disable_irq(wl->irq);
  1014. ret = platform_device_register(&wl1271_device);
  1015. if (ret) {
  1016. wl1271_error("couldn't register platform device");
  1017. goto out_irq;
  1018. }
  1019. dev_set_drvdata(&wl1271_device.dev, wl);
  1020. ret = wl1271_init_ieee80211(wl);
  1021. if (ret)
  1022. goto out_platform;
  1023. ret = wl1271_register_hw(wl);
  1024. if (ret)
  1025. goto out_platform;
  1026. wl1271_debugfs_init(wl);
  1027. wl1271_notice("initialized");
  1028. return 0;
  1029. out_platform:
  1030. platform_device_unregister(&wl1271_device);
  1031. out_irq:
  1032. free_irq(wl->irq, wl);
  1033. out_free:
  1034. kfree(wl->rx_descriptor);
  1035. wl->rx_descriptor = NULL;
  1036. ieee80211_free_hw(hw);
  1037. return ret;
  1038. }
  1039. static int __devexit wl1271_remove(struct spi_device *spi)
  1040. {
  1041. struct wl1271 *wl = dev_get_drvdata(&spi->dev);
  1042. ieee80211_unregister_hw(wl->hw);
  1043. wl1271_debugfs_exit(wl);
  1044. platform_device_unregister(&wl1271_device);
  1045. free_irq(wl->irq, wl);
  1046. kfree(wl->target_mem_map);
  1047. kfree(wl->fw);
  1048. wl->fw = NULL;
  1049. kfree(wl->nvs);
  1050. wl->nvs = NULL;
  1051. kfree(wl->rx_descriptor);
  1052. wl->rx_descriptor = NULL;
  1053. kfree(wl->fw_status);
  1054. kfree(wl->tx_res_if);
  1055. ieee80211_free_hw(wl->hw);
  1056. return 0;
  1057. }
  1058. static struct spi_driver wl1271_spi_driver = {
  1059. .driver = {
  1060. .name = "wl1271",
  1061. .bus = &spi_bus_type,
  1062. .owner = THIS_MODULE,
  1063. },
  1064. .probe = wl1271_probe,
  1065. .remove = __devexit_p(wl1271_remove),
  1066. };
  1067. static int __init wl1271_init(void)
  1068. {
  1069. int ret;
  1070. ret = spi_register_driver(&wl1271_spi_driver);
  1071. if (ret < 0) {
  1072. wl1271_error("failed to register spi driver: %d", ret);
  1073. goto out;
  1074. }
  1075. out:
  1076. return ret;
  1077. }
  1078. static void __exit wl1271_exit(void)
  1079. {
  1080. spi_unregister_driver(&wl1271_spi_driver);
  1081. wl1271_notice("unloaded");
  1082. }
  1083. module_init(wl1271_init);
  1084. module_exit(wl1271_exit);
  1085. MODULE_LICENSE("GPL");
  1086. MODULE_AUTHOR("Luciano Coelho <luciano.coelho@nokia.com>");