main.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Device probe and register.
  4. *
  5. * Copyright (c) 2017-2020, Silicon Laboratories, Inc.
  6. * Copyright (c) 2010, ST-Ericsson
  7. * Copyright (c) 2008, Johannes Berg <johannes@sipsolutions.net>
  8. * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
  9. * Copyright (c) 2007-2009, Christian Lamparter <chunkeey@web.de>
  10. * Copyright (c) 2006, Michael Wu <flamingice@sourmilk.net>
  11. * Copyright (c) 2004-2006 Jean-Baptiste Note <jbnote@gmail.com>, et al.
  12. */
  13. #include <linux/module.h>
  14. #include <linux/of.h>
  15. #include <linux/of_net.h>
  16. #include <linux/gpio/consumer.h>
  17. #include <linux/mmc/sdio_func.h>
  18. #include <linux/spi/spi.h>
  19. #include <linux/etherdevice.h>
  20. #include <linux/firmware.h>
  21. #include "main.h"
  22. #include "wfx.h"
  23. #include "fwio.h"
  24. #include "hwio.h"
  25. #include "bus.h"
  26. #include "bh.h"
  27. #include "sta.h"
  28. #include "key.h"
  29. #include "scan.h"
  30. #include "debug.h"
  31. #include "data_tx.h"
  32. #include "hif_tx_mib.h"
  33. #include "hif_api_cmd.h"
  34. #define WFX_PDS_TLV_TYPE 0x4450 // "PD" (Platform Data) in ascii little-endian
  35. #define WFX_PDS_MAX_CHUNK_SIZE 1500
  36. MODULE_DESCRIPTION("Silicon Labs 802.11 Wireless LAN driver for WF200");
  37. MODULE_AUTHOR("Jérôme Pouiller <jerome.pouiller@silabs.com>");
  38. MODULE_LICENSE("GPL");
  39. #define RATETAB_ENT(_rate, _rateid, _flags) { \
  40. .bitrate = (_rate), \
  41. .hw_value = (_rateid), \
  42. .flags = (_flags), \
  43. }
  44. static struct ieee80211_rate wfx_rates[] = {
  45. RATETAB_ENT(10, 0, 0),
  46. RATETAB_ENT(20, 1, IEEE80211_RATE_SHORT_PREAMBLE),
  47. RATETAB_ENT(55, 2, IEEE80211_RATE_SHORT_PREAMBLE),
  48. RATETAB_ENT(110, 3, IEEE80211_RATE_SHORT_PREAMBLE),
  49. RATETAB_ENT(60, 6, 0),
  50. RATETAB_ENT(90, 7, 0),
  51. RATETAB_ENT(120, 8, 0),
  52. RATETAB_ENT(180, 9, 0),
  53. RATETAB_ENT(240, 10, 0),
  54. RATETAB_ENT(360, 11, 0),
  55. RATETAB_ENT(480, 12, 0),
  56. RATETAB_ENT(540, 13, 0),
  57. };
  58. #define CHAN2G(_channel, _freq, _flags) { \
  59. .band = NL80211_BAND_2GHZ, \
  60. .center_freq = (_freq), \
  61. .hw_value = (_channel), \
  62. .flags = (_flags), \
  63. .max_antenna_gain = 0, \
  64. .max_power = 30, \
  65. }
  66. static struct ieee80211_channel wfx_2ghz_chantable[] = {
  67. CHAN2G(1, 2412, 0),
  68. CHAN2G(2, 2417, 0),
  69. CHAN2G(3, 2422, 0),
  70. CHAN2G(4, 2427, 0),
  71. CHAN2G(5, 2432, 0),
  72. CHAN2G(6, 2437, 0),
  73. CHAN2G(7, 2442, 0),
  74. CHAN2G(8, 2447, 0),
  75. CHAN2G(9, 2452, 0),
  76. CHAN2G(10, 2457, 0),
  77. CHAN2G(11, 2462, 0),
  78. CHAN2G(12, 2467, 0),
  79. CHAN2G(13, 2472, 0),
  80. CHAN2G(14, 2484, 0),
  81. };
  82. static const struct ieee80211_supported_band wfx_band_2ghz = {
  83. .channels = wfx_2ghz_chantable,
  84. .n_channels = ARRAY_SIZE(wfx_2ghz_chantable),
  85. .bitrates = wfx_rates,
  86. .n_bitrates = ARRAY_SIZE(wfx_rates),
  87. .ht_cap = {
  88. /* Receive caps */
  89. .cap = IEEE80211_HT_CAP_GRN_FLD | IEEE80211_HT_CAP_SGI_20 |
  90. IEEE80211_HT_CAP_MAX_AMSDU | (1 << IEEE80211_HT_CAP_RX_STBC_SHIFT),
  91. .ht_supported = 1,
  92. .ampdu_factor = IEEE80211_HT_MAX_AMPDU_16K,
  93. .ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE,
  94. .mcs = {
  95. .rx_mask = { 0xFF }, /* MCS0 to MCS7 */
  96. .rx_highest = cpu_to_le16(72),
  97. .tx_params = IEEE80211_HT_MCS_TX_DEFINED,
  98. },
  99. },
  100. };
  101. static const struct ieee80211_iface_limit wdev_iface_limits[] = {
  102. { .max = 1, .types = BIT(NL80211_IFTYPE_STATION) },
  103. { .max = 1, .types = BIT(NL80211_IFTYPE_AP) },
  104. };
  105. static const struct ieee80211_iface_combination wfx_iface_combinations[] = {
  106. {
  107. .num_different_channels = 2,
  108. .max_interfaces = 2,
  109. .limits = wdev_iface_limits,
  110. .n_limits = ARRAY_SIZE(wdev_iface_limits),
  111. }
  112. };
  113. static const struct ieee80211_ops wfx_ops = {
  114. .start = wfx_start,
  115. .stop = wfx_stop,
  116. .add_interface = wfx_add_interface,
  117. .remove_interface = wfx_remove_interface,
  118. .config = wfx_config,
  119. .tx = wfx_tx,
  120. .wake_tx_queue = ieee80211_handle_wake_tx_queue,
  121. .join_ibss = wfx_join_ibss,
  122. .leave_ibss = wfx_leave_ibss,
  123. .conf_tx = wfx_conf_tx,
  124. .hw_scan = wfx_hw_scan,
  125. .cancel_hw_scan = wfx_cancel_hw_scan,
  126. .start_ap = wfx_start_ap,
  127. .stop_ap = wfx_stop_ap,
  128. .sta_add = wfx_sta_add,
  129. .sta_remove = wfx_sta_remove,
  130. .set_tim = wfx_set_tim,
  131. .set_key = wfx_set_key,
  132. .set_rts_threshold = wfx_set_rts_threshold,
  133. .set_default_unicast_key = wfx_set_default_unicast_key,
  134. .bss_info_changed = wfx_bss_info_changed,
  135. .configure_filter = wfx_configure_filter,
  136. .ampdu_action = wfx_ampdu_action,
  137. .flush = wfx_flush,
  138. .add_chanctx = wfx_add_chanctx,
  139. .remove_chanctx = wfx_remove_chanctx,
  140. .change_chanctx = wfx_change_chanctx,
  141. .assign_vif_chanctx = wfx_assign_vif_chanctx,
  142. .unassign_vif_chanctx = wfx_unassign_vif_chanctx,
  143. .remain_on_channel = wfx_remain_on_channel,
  144. .cancel_remain_on_channel = wfx_cancel_remain_on_channel,
  145. };
  146. bool wfx_api_older_than(struct wfx_dev *wdev, int major, int minor)
  147. {
  148. if (wdev->hw_caps.api_version_major < major)
  149. return true;
  150. if (wdev->hw_caps.api_version_major > major)
  151. return false;
  152. if (wdev->hw_caps.api_version_minor < minor)
  153. return true;
  154. return false;
  155. }
  156. /* The device needs data about the antenna configuration. This information in provided by PDS
  157. * (Platform Data Set, this is the wording used in WF200 documentation) files. For hardware
  158. * integrators, the full process to create PDS files is described here:
  159. * https://github.com/SiliconLabs/wfx-firmware/blob/master/PDS/README.md
  160. *
  161. * The PDS file is an array of Time-Length-Value structs.
  162. */
  163. int wfx_send_pds(struct wfx_dev *wdev, u8 *buf, size_t len)
  164. {
  165. int ret, chunk_type, chunk_len, chunk_num = 0;
  166. if (*buf == '{') {
  167. dev_err(wdev->dev, "PDS: malformed file (legacy format?)\n");
  168. return -EINVAL;
  169. }
  170. while (len > 0) {
  171. chunk_type = get_unaligned_le16(buf + 0);
  172. chunk_len = get_unaligned_le16(buf + 2);
  173. if (chunk_len < 4 || chunk_len > len) {
  174. dev_err(wdev->dev, "PDS:%d: corrupted file\n", chunk_num);
  175. return -EINVAL;
  176. }
  177. if (chunk_type != WFX_PDS_TLV_TYPE) {
  178. dev_info(wdev->dev, "PDS:%d: skip unknown data\n", chunk_num);
  179. goto next;
  180. }
  181. if (chunk_len > WFX_PDS_MAX_CHUNK_SIZE)
  182. dev_warn(wdev->dev, "PDS:%d: unexpectedly large chunk\n", chunk_num);
  183. if (buf[4] != '{' || buf[chunk_len - 1] != '}')
  184. dev_warn(wdev->dev, "PDS:%d: unexpected content\n", chunk_num);
  185. ret = wfx_hif_configuration(wdev, buf + 4, chunk_len - 4);
  186. if (ret > 0) {
  187. dev_err(wdev->dev, "PDS:%d: invalid data (unsupported options?)\n", chunk_num);
  188. return -EINVAL;
  189. }
  190. if (ret == -ETIMEDOUT) {
  191. dev_err(wdev->dev, "PDS:%d: chip didn't reply (corrupted file?)\n", chunk_num);
  192. return ret;
  193. }
  194. if (ret) {
  195. dev_err(wdev->dev, "PDS:%d: chip returned an unknown error\n", chunk_num);
  196. return -EIO;
  197. }
  198. next:
  199. chunk_num++;
  200. len -= chunk_len;
  201. buf += chunk_len;
  202. }
  203. return 0;
  204. }
  205. static int wfx_send_pdata_pds(struct wfx_dev *wdev)
  206. {
  207. int ret = 0;
  208. const struct firmware *pds;
  209. u8 *tmp_buf;
  210. ret = request_firmware(&pds, wdev->pdata.file_pds, wdev->dev);
  211. if (ret) {
  212. dev_err(wdev->dev, "can't load antenna parameters (PDS file %s). The device may be unstable.\n",
  213. wdev->pdata.file_pds);
  214. return ret;
  215. }
  216. tmp_buf = kmemdup(pds->data, pds->size, GFP_KERNEL);
  217. if (!tmp_buf) {
  218. ret = -ENOMEM;
  219. goto release_fw;
  220. }
  221. ret = wfx_send_pds(wdev, tmp_buf, pds->size);
  222. kfree(tmp_buf);
  223. release_fw:
  224. release_firmware(pds);
  225. return ret;
  226. }
  227. static void wfx_free_common(void *data)
  228. {
  229. struct wfx_dev *wdev = data;
  230. mutex_destroy(&wdev->tx_power_loop_info_lock);
  231. mutex_destroy(&wdev->rx_stats_lock);
  232. mutex_destroy(&wdev->scan_lock);
  233. mutex_destroy(&wdev->conf_mutex);
  234. ieee80211_free_hw(wdev->hw);
  235. }
  236. struct wfx_dev *wfx_init_common(struct device *dev, const struct wfx_platform_data *pdata,
  237. const struct wfx_hwbus_ops *hwbus_ops, void *hwbus_priv)
  238. {
  239. struct ieee80211_hw *hw;
  240. struct wfx_dev *wdev;
  241. hw = ieee80211_alloc_hw(sizeof(struct wfx_dev), &wfx_ops);
  242. if (!hw)
  243. return NULL;
  244. SET_IEEE80211_DEV(hw, dev);
  245. ieee80211_hw_set(hw, TX_AMPDU_SETUP_IN_HW);
  246. ieee80211_hw_set(hw, AMPDU_AGGREGATION);
  247. ieee80211_hw_set(hw, CONNECTION_MONITOR);
  248. ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS);
  249. ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS);
  250. ieee80211_hw_set(hw, SIGNAL_DBM);
  251. ieee80211_hw_set(hw, SUPPORTS_PS);
  252. ieee80211_hw_set(hw, MFP_CAPABLE);
  253. hw->vif_data_size = sizeof(struct wfx_vif);
  254. hw->sta_data_size = sizeof(struct wfx_sta_priv);
  255. hw->queues = 4;
  256. hw->max_rates = 8;
  257. hw->max_rate_tries = 8;
  258. hw->extra_tx_headroom = sizeof(struct wfx_hif_msg) + sizeof(struct wfx_hif_req_tx) +
  259. 4 /* alignment */ + 8 /* TKIP IV */;
  260. hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
  261. BIT(NL80211_IFTYPE_ADHOC) |
  262. BIT(NL80211_IFTYPE_AP);
  263. hw->wiphy->probe_resp_offload = NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
  264. NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
  265. NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P |
  266. NL80211_PROBE_RESP_OFFLOAD_SUPPORT_80211U;
  267. hw->wiphy->features |= NL80211_FEATURE_AP_SCAN;
  268. hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
  269. hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
  270. hw->wiphy->max_remain_on_channel_duration = 5000;
  271. hw->wiphy->max_ap_assoc_sta = HIF_LINK_ID_MAX;
  272. hw->wiphy->max_scan_ssids = 2;
  273. hw->wiphy->max_scan_ie_len = IEEE80211_MAX_DATA_LEN;
  274. hw->wiphy->n_iface_combinations = ARRAY_SIZE(wfx_iface_combinations);
  275. hw->wiphy->iface_combinations = wfx_iface_combinations;
  276. /* FIXME: also copy wfx_rates and wfx_2ghz_chantable */
  277. hw->wiphy->bands[NL80211_BAND_2GHZ] = devm_kmemdup(dev, &wfx_band_2ghz,
  278. sizeof(wfx_band_2ghz), GFP_KERNEL);
  279. if (!hw->wiphy->bands[NL80211_BAND_2GHZ])
  280. goto err;
  281. wdev = hw->priv;
  282. wdev->hw = hw;
  283. wdev->dev = dev;
  284. wdev->hwbus_ops = hwbus_ops;
  285. wdev->hwbus_priv = hwbus_priv;
  286. memcpy(&wdev->pdata, pdata, sizeof(*pdata));
  287. of_property_read_string(dev->of_node, "silabs,antenna-config-file", &wdev->pdata.file_pds);
  288. wdev->pdata.gpio_wakeup = devm_gpiod_get_optional(dev, "wakeup", GPIOD_OUT_LOW);
  289. if (IS_ERR(wdev->pdata.gpio_wakeup))
  290. goto err;
  291. if (wdev->pdata.gpio_wakeup)
  292. gpiod_set_consumer_name(wdev->pdata.gpio_wakeup, "wfx wakeup");
  293. mutex_init(&wdev->conf_mutex);
  294. mutex_init(&wdev->scan_lock);
  295. mutex_init(&wdev->rx_stats_lock);
  296. mutex_init(&wdev->tx_power_loop_info_lock);
  297. init_completion(&wdev->firmware_ready);
  298. INIT_DELAYED_WORK(&wdev->cooling_timeout_work, wfx_cooling_timeout_work);
  299. skb_queue_head_init(&wdev->tx_pending);
  300. init_waitqueue_head(&wdev->tx_dequeue);
  301. wfx_init_hif_cmd(&wdev->hif_cmd);
  302. if (devm_add_action_or_reset(dev, wfx_free_common, wdev))
  303. return NULL;
  304. return wdev;
  305. err:
  306. ieee80211_free_hw(hw);
  307. return NULL;
  308. }
  309. int wfx_probe(struct wfx_dev *wdev)
  310. {
  311. int i;
  312. int err;
  313. struct gpio_desc *gpio_saved;
  314. /* During first part of boot, gpio_wakeup cannot yet been used. So prevent bh() to touch
  315. * it.
  316. */
  317. gpio_saved = wdev->pdata.gpio_wakeup;
  318. wdev->pdata.gpio_wakeup = NULL;
  319. wdev->poll_irq = true;
  320. wdev->bh_wq = alloc_workqueue("wfx_bh_wq", WQ_HIGHPRI, 0);
  321. if (!wdev->bh_wq)
  322. return -ENOMEM;
  323. wfx_bh_register(wdev);
  324. err = wfx_init_device(wdev);
  325. if (err)
  326. goto bh_unregister;
  327. wfx_bh_poll_irq(wdev);
  328. err = wait_for_completion_timeout(&wdev->firmware_ready, 1 * HZ);
  329. if (err == 0) {
  330. dev_err(wdev->dev, "timeout while waiting for startup indication\n");
  331. err = -ETIMEDOUT;
  332. goto bh_unregister;
  333. }
  334. /* FIXME: fill wiphy::hw_version */
  335. dev_info(wdev->dev, "started firmware %d.%d.%d \"%s\" (API: %d.%d, keyset: %02X, caps: 0x%.8X)\n",
  336. wdev->hw_caps.firmware_major, wdev->hw_caps.firmware_minor,
  337. wdev->hw_caps.firmware_build, wdev->hw_caps.firmware_label,
  338. wdev->hw_caps.api_version_major, wdev->hw_caps.api_version_minor,
  339. wdev->keyset, wdev->hw_caps.link_mode);
  340. snprintf(wdev->hw->wiphy->fw_version,
  341. sizeof(wdev->hw->wiphy->fw_version),
  342. "%d.%d.%d",
  343. wdev->hw_caps.firmware_major,
  344. wdev->hw_caps.firmware_minor,
  345. wdev->hw_caps.firmware_build);
  346. if (wfx_api_older_than(wdev, 1, 0)) {
  347. dev_err(wdev->dev, "unsupported firmware API version (expect 1 while firmware returns %d)\n",
  348. wdev->hw_caps.api_version_major);
  349. err = -EOPNOTSUPP;
  350. goto bh_unregister;
  351. }
  352. if (wdev->hw_caps.link_mode == SEC_LINK_ENFORCED) {
  353. dev_err(wdev->dev, "chip require secure_link, but can't negotiate it\n");
  354. goto bh_unregister;
  355. }
  356. if (wdev->hw_caps.region_sel_mode) {
  357. wdev->hw->wiphy->regulatory_flags |= REGULATORY_DISABLE_BEACON_HINTS;
  358. wdev->hw->wiphy->bands[NL80211_BAND_2GHZ]->channels[11].flags |=
  359. IEEE80211_CHAN_NO_IR;
  360. wdev->hw->wiphy->bands[NL80211_BAND_2GHZ]->channels[12].flags |=
  361. IEEE80211_CHAN_NO_IR;
  362. wdev->hw->wiphy->bands[NL80211_BAND_2GHZ]->channels[13].flags |=
  363. IEEE80211_CHAN_DISABLED;
  364. }
  365. dev_dbg(wdev->dev, "sending configuration file %s\n", wdev->pdata.file_pds);
  366. err = wfx_send_pdata_pds(wdev);
  367. if (err < 0 && err != -ENOENT)
  368. goto bh_unregister;
  369. wdev->poll_irq = false;
  370. err = wdev->hwbus_ops->irq_subscribe(wdev->hwbus_priv);
  371. if (err)
  372. goto bh_unregister;
  373. err = wfx_hif_use_multi_tx_conf(wdev, true);
  374. if (err)
  375. dev_err(wdev->dev, "misconfigured IRQ?\n");
  376. wdev->pdata.gpio_wakeup = gpio_saved;
  377. if (wdev->pdata.gpio_wakeup) {
  378. dev_dbg(wdev->dev, "enable 'quiescent' power mode with wakeup GPIO and PDS file %s\n",
  379. wdev->pdata.file_pds);
  380. gpiod_set_value_cansleep(wdev->pdata.gpio_wakeup, 1);
  381. wfx_control_reg_write(wdev, 0);
  382. wfx_hif_set_operational_mode(wdev, HIF_OP_POWER_MODE_QUIESCENT);
  383. } else {
  384. wfx_hif_set_operational_mode(wdev, HIF_OP_POWER_MODE_DOZE);
  385. }
  386. for (i = 0; i < ARRAY_SIZE(wdev->addresses); i++) {
  387. eth_zero_addr(wdev->addresses[i].addr);
  388. err = of_get_mac_address(wdev->dev->of_node, wdev->addresses[i].addr);
  389. if (!err)
  390. wdev->addresses[i].addr[ETH_ALEN - 1] += i;
  391. else
  392. ether_addr_copy(wdev->addresses[i].addr, wdev->hw_caps.mac_addr[i]);
  393. if (!is_valid_ether_addr(wdev->addresses[i].addr)) {
  394. dev_warn(wdev->dev, "using random MAC address\n");
  395. eth_random_addr(wdev->addresses[i].addr);
  396. }
  397. dev_info(wdev->dev, "MAC address %d: %pM\n", i, wdev->addresses[i].addr);
  398. }
  399. wdev->hw->wiphy->n_addresses = ARRAY_SIZE(wdev->addresses);
  400. wdev->hw->wiphy->addresses = wdev->addresses;
  401. if (!wfx_api_older_than(wdev, 3, 8))
  402. wdev->hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
  403. err = ieee80211_register_hw(wdev->hw);
  404. if (err)
  405. goto irq_unsubscribe;
  406. err = wfx_debug_init(wdev);
  407. if (err)
  408. goto ieee80211_unregister;
  409. return 0;
  410. ieee80211_unregister:
  411. ieee80211_unregister_hw(wdev->hw);
  412. irq_unsubscribe:
  413. wdev->hwbus_ops->irq_unsubscribe(wdev->hwbus_priv);
  414. bh_unregister:
  415. wfx_bh_unregister(wdev);
  416. destroy_workqueue(wdev->bh_wq);
  417. return err;
  418. }
  419. void wfx_release(struct wfx_dev *wdev)
  420. {
  421. ieee80211_unregister_hw(wdev->hw);
  422. wfx_hif_shutdown(wdev);
  423. wdev->hwbus_ops->irq_unsubscribe(wdev->hwbus_priv);
  424. wfx_bh_unregister(wdev);
  425. destroy_workqueue(wdev->bh_wq);
  426. }
  427. static int __init wfx_core_init(void)
  428. {
  429. int ret = 0;
  430. if (IS_ENABLED(CONFIG_SPI)) {
  431. ret = spi_register_driver(&wfx_spi_driver);
  432. if (ret)
  433. goto out;
  434. }
  435. if (IS_ENABLED(CONFIG_MMC)) {
  436. ret = sdio_register_driver(&wfx_sdio_driver);
  437. if (ret)
  438. goto unregister_spi;
  439. }
  440. return 0;
  441. unregister_spi:
  442. if (IS_ENABLED(CONFIG_SPI))
  443. spi_unregister_driver(&wfx_spi_driver);
  444. out:
  445. return ret;
  446. }
  447. module_init(wfx_core_init);
  448. static void __exit wfx_core_exit(void)
  449. {
  450. if (IS_ENABLED(CONFIG_MMC))
  451. sdio_unregister_driver(&wfx_sdio_driver);
  452. if (IS_ENABLED(CONFIG_SPI))
  453. spi_unregister_driver(&wfx_spi_driver);
  454. }
  455. module_exit(wfx_core_exit);