2 * Copyright (c) 2010-2011 Atheros Communications Inc.
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
21 MODULE_AUTHOR("Atheros Communications");
22 MODULE_LICENSE("Dual BSD/GPL");
23 MODULE_DESCRIPTION("Atheros driver 802.11n HTC based wireless devices");
25 static unsigned int ath9k_debug = ATH_DBG_DEFAULT;
26 module_param_named(debug, ath9k_debug, uint, 0);
27 MODULE_PARM_DESC(debug, "Debugging mask");
29 int htc_modparam_nohwcrypt;
30 module_param_named(nohwcrypt, htc_modparam_nohwcrypt, int, 0444);
31 MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption");
33 static int ath9k_htc_btcoex_enable;
34 module_param_named(btcoex_enable, ath9k_htc_btcoex_enable, int, 0444);
35 MODULE_PARM_DESC(btcoex_enable, "Enable wifi-BT coexistence");
37 static int ath9k_ps_enable;
38 module_param_named(ps_enable, ath9k_ps_enable, int, 0444);
39 MODULE_PARM_DESC(ps_enable, "Enable WLAN PowerSave");
41 #ifdef CONFIG_MAC80211_LEDS
42 static const struct ieee80211_tpt_blink ath9k_htc_tpt_blink[] = {
43 { .throughput = 0 * 1024, .blink_time = 334 },
44 { .throughput = 1 * 1024, .blink_time = 260 },
45 { .throughput = 5 * 1024, .blink_time = 220 },
46 { .throughput = 10 * 1024, .blink_time = 190 },
47 { .throughput = 20 * 1024, .blink_time = 170 },
48 { .throughput = 50 * 1024, .blink_time = 150 },
49 { .throughput = 70 * 1024, .blink_time = 130 },
50 { .throughput = 100 * 1024, .blink_time = 110 },
51 { .throughput = 200 * 1024, .blink_time = 80 },
52 { .throughput = 300 * 1024, .blink_time = 50 },
56 static void ath9k_htc_op_ps_wakeup(struct ath_common *common)
58 ath9k_htc_ps_wakeup((struct ath9k_htc_priv *) common->priv);
61 static void ath9k_htc_op_ps_restore(struct ath_common *common)
63 ath9k_htc_ps_restore((struct ath9k_htc_priv *) common->priv);
66 static struct ath_ps_ops ath9k_htc_ps_ops = {
67 .wakeup = ath9k_htc_op_ps_wakeup,
68 .restore = ath9k_htc_op_ps_restore,
71 static int ath9k_htc_wait_for_target(struct ath9k_htc_priv *priv)
75 if (atomic_read(&priv->htc->tgt_ready) > 0) {
76 atomic_dec(&priv->htc->tgt_ready);
80 /* Firmware can take up to 50ms to get ready, to be safe use 1 second */
81 time_left = wait_for_completion_timeout(&priv->htc->target_wait, HZ);
83 dev_err(priv->dev, "ath9k_htc: Target is unresponsive\n");
87 atomic_dec(&priv->htc->tgt_ready);
92 static void ath9k_deinit_priv(struct ath9k_htc_priv *priv)
94 ath9k_hw_deinit(priv->ah);
99 static void ath9k_deinit_device(struct ath9k_htc_priv *priv)
101 struct ieee80211_hw *hw = priv->hw;
103 wiphy_rfkill_stop_polling(hw->wiphy);
104 ath9k_deinit_leds(priv);
105 ath9k_htc_deinit_debug(priv);
106 ieee80211_unregister_hw(hw);
107 ath9k_rx_cleanup(priv);
108 ath9k_tx_cleanup(priv);
109 ath9k_deinit_priv(priv);
112 static inline int ath9k_htc_connect_svc(struct ath9k_htc_priv *priv,
116 enum htc_endpoint_id,
118 enum htc_endpoint_id *ep_id)
120 struct htc_service_connreq req;
122 memset(&req, 0, sizeof(struct htc_service_connreq));
124 req.service_id = service_id;
125 req.ep_callbacks.priv = priv;
126 req.ep_callbacks.rx = ath9k_htc_rxep;
127 req.ep_callbacks.tx = tx;
129 return htc_connect_service(priv->htc, &req, ep_id);
132 static int ath9k_init_htc_services(struct ath9k_htc_priv *priv, u16 devid,
138 ret = ath9k_wmi_connect(priv->htc, priv->wmi, &priv->wmi_cmd_ep);
143 ret = ath9k_htc_connect_svc(priv, WMI_BEACON_SVC, ath9k_htc_beaconep,
149 ret = ath9k_htc_connect_svc(priv, WMI_CAB_SVC, ath9k_htc_txep,
156 ret = ath9k_htc_connect_svc(priv, WMI_UAPSD_SVC, ath9k_htc_txep,
162 ret = ath9k_htc_connect_svc(priv, WMI_MGMT_SVC, ath9k_htc_txep,
168 ret = ath9k_htc_connect_svc(priv, WMI_DATA_BE_SVC, ath9k_htc_txep,
174 ret = ath9k_htc_connect_svc(priv, WMI_DATA_BK_SVC, ath9k_htc_txep,
180 ret = ath9k_htc_connect_svc(priv, WMI_DATA_VI_SVC, ath9k_htc_txep,
186 ret = ath9k_htc_connect_svc(priv, WMI_DATA_VO_SVC, ath9k_htc_txep,
192 * Setup required credits before initializing HTC.
193 * This is a bit hacky, but, since queuing is done in
194 * the HIF layer, shouldn't matter much.
197 if (IS_AR7010_DEVICE(drv_info))
198 priv->htc->credits = 45;
200 priv->htc->credits = 33;
202 ret = htc_init(priv->htc);
206 dev_info(priv->dev, "ath9k_htc: HTC initialized with %d credits\n",
212 dev_err(priv->dev, "ath9k_htc: Unable to initialize HTC services\n");
216 static void ath9k_reg_notifier(struct wiphy *wiphy,
217 struct regulatory_request *request)
219 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
220 struct ath9k_htc_priv *priv = hw->priv;
222 ath_reg_notifier_apply(wiphy, request,
223 ath9k_hw_regulatory(priv->ah));
226 static unsigned int ath9k_regread(void *hw_priv, u32 reg_offset)
228 struct ath_hw *ah = (struct ath_hw *) hw_priv;
229 struct ath_common *common = ath9k_hw_common(ah);
230 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv;
231 __be32 val, reg = cpu_to_be32(reg_offset);
234 r = ath9k_wmi_cmd(priv->wmi, WMI_REG_READ_CMDID,
235 (u8 *) ®, sizeof(reg),
236 (u8 *) &val, sizeof(val),
239 ath_dbg(common, WMI, "REGISTER READ FAILED: (0x%04x, %d)\n",
244 return be32_to_cpu(val);
247 static void ath9k_multi_regread(void *hw_priv, u32 *addr,
250 struct ath_hw *ah = (struct ath_hw *) hw_priv;
251 struct ath_common *common = ath9k_hw_common(ah);
252 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv;
257 for (i = 0; i < count; i++) {
258 tmpaddr[i] = cpu_to_be32(addr[i]);
261 ret = ath9k_wmi_cmd(priv->wmi, WMI_REG_READ_CMDID,
262 (u8 *)tmpaddr , sizeof(u32) * count,
263 (u8 *)tmpval, sizeof(u32) * count,
267 "Multiple REGISTER READ FAILED (count: %d)\n", count);
270 for (i = 0; i < count; i++) {
271 val[i] = be32_to_cpu(tmpval[i]);
275 static void ath9k_regwrite_multi(struct ath_common *common)
277 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv;
281 r = ath9k_wmi_cmd(priv->wmi, WMI_REG_WRITE_CMDID,
282 (u8 *) &priv->wmi->multi_write,
283 sizeof(struct register_write) * priv->wmi->multi_write_idx,
284 (u8 *) &rsp_status, sizeof(rsp_status),
288 "REGISTER WRITE FAILED, multi len: %d\n",
289 priv->wmi->multi_write_idx);
291 priv->wmi->multi_write_idx = 0;
294 static void ath9k_regwrite_single(void *hw_priv, u32 val, u32 reg_offset)
296 struct ath_hw *ah = (struct ath_hw *) hw_priv;
297 struct ath_common *common = ath9k_hw_common(ah);
298 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv;
299 const __be32 buf[2] = {
300 cpu_to_be32(reg_offset),
305 r = ath9k_wmi_cmd(priv->wmi, WMI_REG_WRITE_CMDID,
306 (u8 *) &buf, sizeof(buf),
307 (u8 *) &val, sizeof(val),
310 ath_dbg(common, WMI, "REGISTER WRITE FAILED:(0x%04x, %d)\n",
315 static void ath9k_regwrite_buffer(void *hw_priv, u32 val, u32 reg_offset)
317 struct ath_hw *ah = (struct ath_hw *) hw_priv;
318 struct ath_common *common = ath9k_hw_common(ah);
319 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv;
321 mutex_lock(&priv->wmi->multi_write_mutex);
323 /* Store the register/value */
324 priv->wmi->multi_write[priv->wmi->multi_write_idx].reg =
325 cpu_to_be32(reg_offset);
326 priv->wmi->multi_write[priv->wmi->multi_write_idx].val =
329 priv->wmi->multi_write_idx++;
331 /* If the buffer is full, send it out. */
332 if (priv->wmi->multi_write_idx == MAX_CMD_NUMBER)
333 ath9k_regwrite_multi(common);
335 mutex_unlock(&priv->wmi->multi_write_mutex);
338 static void ath9k_regwrite(void *hw_priv, u32 val, u32 reg_offset)
340 struct ath_hw *ah = (struct ath_hw *) hw_priv;
341 struct ath_common *common = ath9k_hw_common(ah);
342 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv;
344 if (atomic_read(&priv->wmi->mwrite_cnt))
345 ath9k_regwrite_buffer(hw_priv, val, reg_offset);
347 ath9k_regwrite_single(hw_priv, val, reg_offset);
350 static void ath9k_enable_regwrite_buffer(void *hw_priv)
352 struct ath_hw *ah = (struct ath_hw *) hw_priv;
353 struct ath_common *common = ath9k_hw_common(ah);
354 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv;
356 atomic_inc(&priv->wmi->mwrite_cnt);
359 static void ath9k_regwrite_flush(void *hw_priv)
361 struct ath_hw *ah = (struct ath_hw *) hw_priv;
362 struct ath_common *common = ath9k_hw_common(ah);
363 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv;
365 atomic_dec(&priv->wmi->mwrite_cnt);
367 mutex_lock(&priv->wmi->multi_write_mutex);
369 if (priv->wmi->multi_write_idx)
370 ath9k_regwrite_multi(common);
372 mutex_unlock(&priv->wmi->multi_write_mutex);
375 static u32 ath9k_reg_rmw(void *hw_priv, u32 reg_offset, u32 set, u32 clr)
379 val = ath9k_regread(hw_priv, reg_offset);
382 ath9k_regwrite(hw_priv, val, reg_offset);
386 static void ath_usb_read_cachesize(struct ath_common *common, int *csz)
388 *csz = L1_CACHE_BYTES >> 2;
391 static bool ath_usb_eeprom_read(struct ath_common *common, u32 off, u16 *data)
393 struct ath_hw *ah = (struct ath_hw *) common->ah;
395 (void)REG_READ(ah, AR5416_EEPROM_OFFSET + (off << AR5416_EEPROM_S));
397 if (!ath9k_hw_wait(ah,
398 AR_EEPROM_STATUS_DATA,
399 AR_EEPROM_STATUS_DATA_BUSY |
400 AR_EEPROM_STATUS_DATA_PROT_ACCESS, 0,
404 *data = MS(REG_READ(ah, AR_EEPROM_STATUS_DATA),
405 AR_EEPROM_STATUS_DATA_VAL);
410 static const struct ath_bus_ops ath9k_usb_bus_ops = {
411 .ath_bus_type = ATH_USB,
412 .read_cachesize = ath_usb_read_cachesize,
413 .eeprom_read = ath_usb_eeprom_read,
416 static int ath9k_init_queues(struct ath9k_htc_priv *priv)
418 struct ath_common *common = ath9k_hw_common(priv->ah);
421 for (i = 0; i < ARRAY_SIZE(priv->hwq_map); i++)
422 priv->hwq_map[i] = -1;
424 priv->beacon.beaconq = ath9k_hw_beaconq_setup(priv->ah);
425 if (priv->beacon.beaconq == -1) {
426 ath_err(common, "Unable to setup BEACON xmit queue\n");
430 priv->cabq = ath9k_htc_cabq_setup(priv);
431 if (priv->cabq == -1) {
432 ath_err(common, "Unable to setup CAB xmit queue\n");
436 if (!ath9k_htc_txq_setup(priv, IEEE80211_AC_BE)) {
437 ath_err(common, "Unable to setup xmit queue for BE traffic\n");
441 if (!ath9k_htc_txq_setup(priv, IEEE80211_AC_BK)) {
442 ath_err(common, "Unable to setup xmit queue for BK traffic\n");
445 if (!ath9k_htc_txq_setup(priv, IEEE80211_AC_VI)) {
446 ath_err(common, "Unable to setup xmit queue for VI traffic\n");
449 if (!ath9k_htc_txq_setup(priv, IEEE80211_AC_VO)) {
450 ath_err(common, "Unable to setup xmit queue for VO traffic\n");
460 static void ath9k_init_misc(struct ath9k_htc_priv *priv)
462 struct ath_common *common = ath9k_hw_common(priv->ah);
464 memcpy(common->bssidmask, ath_bcast_mac, ETH_ALEN);
466 common->last_rssi = ATH_RSSI_DUMMY_MARKER;
467 priv->ah->opmode = NL80211_IFTYPE_STATION;
469 priv->spec_priv.ah = priv->ah;
470 priv->spec_priv.spec_config.enabled = 0;
471 priv->spec_priv.spec_config.short_repeat = false;
472 priv->spec_priv.spec_config.count = 8;
473 priv->spec_priv.spec_config.endless = false;
474 priv->spec_priv.spec_config.period = 0x12;
475 priv->spec_priv.spec_config.fft_period = 0x02;
478 static int ath9k_init_priv(struct ath9k_htc_priv *priv,
479 u16 devid, char *product,
482 struct ath_hw *ah = NULL;
483 struct ath_common *common;
484 int i, ret = 0, csz = 0;
486 ah = kzalloc(sizeof(struct ath_hw), GFP_KERNEL);
492 ah->hw_version.devid = devid;
493 ah->hw_version.usbdev = drv_info;
494 ah->ah_flags |= AH_USE_EEPROM;
495 ah->reg_ops.read = ath9k_regread;
496 ah->reg_ops.multi_read = ath9k_multi_regread;
497 ah->reg_ops.write = ath9k_regwrite;
498 ah->reg_ops.enable_write_buffer = ath9k_enable_regwrite_buffer;
499 ah->reg_ops.write_flush = ath9k_regwrite_flush;
500 ah->reg_ops.rmw = ath9k_reg_rmw;
503 common = ath9k_hw_common(ah);
504 common->ops = &ah->reg_ops;
505 common->ps_ops = &ath9k_htc_ps_ops;
506 common->bus_ops = &ath9k_usb_bus_ops;
508 common->hw = priv->hw;
510 common->debug_mask = ath9k_debug;
511 common->btcoex_enabled = ath9k_htc_btcoex_enable == 1;
512 set_bit(ATH_OP_INVALID, &common->op_flags);
514 spin_lock_init(&priv->beacon_lock);
515 spin_lock_init(&priv->tx.tx_lock);
516 mutex_init(&priv->mutex);
517 mutex_init(&priv->htc_pm_lock);
518 tasklet_init(&priv->rx_tasklet, ath9k_rx_tasklet,
519 (unsigned long)priv);
520 tasklet_init(&priv->tx_failed_tasklet, ath9k_tx_failed_tasklet,
521 (unsigned long)priv);
522 INIT_DELAYED_WORK(&priv->ani_work, ath9k_htc_ani_work);
523 INIT_WORK(&priv->ps_work, ath9k_ps_work);
524 INIT_WORK(&priv->fatal_work, ath9k_fatal_work);
525 setup_timer(&priv->tx.cleanup_timer, ath9k_htc_tx_cleanup_timer,
526 (unsigned long)priv);
529 * Cache line size is used to size and align various
530 * structures used to communicate with the hardware.
532 ath_read_cachesize(common, &csz);
533 common->cachelsz = csz << 2; /* convert to bytes */
535 ret = ath9k_hw_init(ah);
538 "Unable to initialize hardware; initialization status: %d\n",
543 ret = ath9k_init_queues(priv);
547 for (i = 0; i < ATH9K_HTC_MAX_BCN_VIF; i++)
548 priv->beacon.bslot[i] = NULL;
549 priv->beacon.slottime = ATH9K_SLOT_TIME_9;
551 ath9k_cmn_init_channels_rates(common);
552 ath9k_cmn_init_crypto(ah);
553 ath9k_init_misc(priv);
554 ath9k_htc_init_btcoex(priv, product);
568 static const struct ieee80211_iface_limit if_limits[] = {
569 { .max = 2, .types = BIT(NL80211_IFTYPE_STATION) |
570 BIT(NL80211_IFTYPE_P2P_CLIENT) },
571 { .max = 2, .types = BIT(NL80211_IFTYPE_AP) |
572 #ifdef CONFIG_MAC80211_MESH
573 BIT(NL80211_IFTYPE_MESH_POINT) |
575 BIT(NL80211_IFTYPE_P2P_GO) },
578 static const struct ieee80211_iface_combination if_comb = {
580 .n_limits = ARRAY_SIZE(if_limits),
582 .num_different_channels = 1,
585 static void ath9k_set_hw_capab(struct ath9k_htc_priv *priv,
586 struct ieee80211_hw *hw)
588 struct ath_hw *ah = priv->ah;
589 struct ath_common *common = ath9k_hw_common(priv->ah);
590 struct base_eep_header *pBase;
592 hw->flags = IEEE80211_HW_SIGNAL_DBM |
593 IEEE80211_HW_AMPDU_AGGREGATION |
594 IEEE80211_HW_SPECTRUM_MGMT |
595 IEEE80211_HW_HAS_RATE_CONTROL |
596 IEEE80211_HW_RX_INCLUDES_FCS |
597 IEEE80211_HW_PS_NULLFUNC_STACK |
598 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
599 IEEE80211_HW_MFP_CAPABLE |
600 IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING;
603 hw->flags |= IEEE80211_HW_SUPPORTS_PS;
605 hw->wiphy->interface_modes =
606 BIT(NL80211_IFTYPE_STATION) |
607 BIT(NL80211_IFTYPE_ADHOC) |
608 BIT(NL80211_IFTYPE_AP) |
609 BIT(NL80211_IFTYPE_P2P_GO) |
610 BIT(NL80211_IFTYPE_P2P_CLIENT) |
611 BIT(NL80211_IFTYPE_MESH_POINT);
613 hw->wiphy->iface_combinations = &if_comb;
614 hw->wiphy->n_iface_combinations = 1;
616 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
618 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN |
619 WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
621 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
624 hw->max_listen_interval = 1;
626 hw->vif_data_size = sizeof(struct ath9k_htc_vif);
627 hw->sta_data_size = sizeof(struct ath9k_htc_sta);
629 /* tx_frame_hdr is larger than tx_mgmt_hdr anyway */
630 hw->extra_tx_headroom = sizeof(struct tx_frame_hdr) +
631 sizeof(struct htc_frame_hdr) + 4;
633 if (priv->ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ)
634 hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
635 &common->sbands[IEEE80211_BAND_2GHZ];
636 if (priv->ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ)
637 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
638 &common->sbands[IEEE80211_BAND_5GHZ];
640 ath9k_cmn_reload_chainmask(ah);
642 pBase = ath9k_htc_get_eeprom_base(priv);
644 hw->wiphy->available_antennas_rx = pBase->rxMask;
645 hw->wiphy->available_antennas_tx = pBase->txMask;
648 SET_IEEE80211_PERM_ADDR(hw, common->macaddr);
651 static int ath9k_init_firmware_version(struct ath9k_htc_priv *priv)
653 struct ieee80211_hw *hw = priv->hw;
654 struct wmi_fw_version cmd_rsp;
657 memset(&cmd_rsp, 0, sizeof(cmd_rsp));
659 WMI_CMD(WMI_GET_FW_VERSION);
663 priv->fw_version_major = be16_to_cpu(cmd_rsp.major);
664 priv->fw_version_minor = be16_to_cpu(cmd_rsp.minor);
666 snprintf(hw->wiphy->fw_version, sizeof(hw->wiphy->fw_version), "%d.%d",
667 priv->fw_version_major,
668 priv->fw_version_minor);
670 dev_info(priv->dev, "ath9k_htc: FW Version: %d.%d\n",
671 priv->fw_version_major,
672 priv->fw_version_minor);
675 * Check if the available FW matches the driver's
678 if (priv->fw_version_major != MAJOR_VERSION_REQ ||
679 priv->fw_version_minor < MINOR_VERSION_REQ) {
680 dev_err(priv->dev, "ath9k_htc: Please upgrade to FW version %d.%d\n",
681 MAJOR_VERSION_REQ, MINOR_VERSION_REQ);
688 static int ath9k_init_device(struct ath9k_htc_priv *priv,
689 u16 devid, char *product, u32 drv_info)
691 struct ieee80211_hw *hw = priv->hw;
692 struct ath_common *common;
695 struct ath_regulatory *reg;
698 /* Bring up device */
699 error = ath9k_init_priv(priv, devid, product, drv_info);
704 common = ath9k_hw_common(ah);
705 ath9k_set_hw_capab(priv, hw);
707 error = ath9k_init_firmware_version(priv);
711 /* Initialize regulatory */
712 error = ath_regd_init(&common->regulatory, priv->hw->wiphy,
717 reg = &common->regulatory;
720 error = ath9k_tx_init(priv);
725 error = ath9k_rx_init(priv);
729 ath9k_hw_disable(priv->ah);
730 #ifdef CONFIG_MAC80211_LEDS
731 /* must be initialized before ieee80211_register_hw */
732 priv->led_cdev.default_trigger = ieee80211_create_tpt_led_trigger(priv->hw,
733 IEEE80211_TPT_LEDTRIG_FL_RADIO, ath9k_htc_tpt_blink,
734 ARRAY_SIZE(ath9k_htc_tpt_blink));
737 /* Register with mac80211 */
738 error = ieee80211_register_hw(hw);
742 /* Handle world regulatory */
743 if (!ath_is_world_regd(reg)) {
744 error = regulatory_hint(hw->wiphy, reg->alpha2);
749 error = ath9k_htc_init_debug(priv->ah);
751 ath_err(common, "Unable to create debugfs files\n");
755 ath_dbg(common, CONFIG,
756 "WMI:%d, BCN:%d, CAB:%d, UAPSD:%d, MGMT:%d, BE:%d, BK:%d, VI:%d, VO:%d\n",
767 ath9k_hw_name(priv->ah, hw_name, sizeof(hw_name));
768 wiphy_info(hw->wiphy, "%s\n", hw_name);
770 ath9k_init_leds(priv);
771 ath9k_start_rfkill_poll(priv);
776 ieee80211_unregister_hw(hw);
778 ath9k_rx_cleanup(priv);
780 ath9k_tx_cleanup(priv);
786 ath9k_deinit_priv(priv);
791 int ath9k_htc_probe_device(struct htc_target *htc_handle, struct device *dev,
792 u16 devid, char *product, u32 drv_info)
794 struct ieee80211_hw *hw;
795 struct ath9k_htc_priv *priv;
798 hw = ieee80211_alloc_hw(sizeof(struct ath9k_htc_priv), &ath9k_htc_ops);
804 priv->htc = htc_handle;
806 htc_handle->drv_priv = priv;
807 SET_IEEE80211_DEV(hw, priv->dev);
809 ret = ath9k_htc_wait_for_target(priv);
813 priv->wmi = ath9k_init_wmi(priv);
819 ret = ath9k_init_htc_services(priv, devid, drv_info);
823 ret = ath9k_init_device(priv, devid, product, drv_info);
830 ath9k_deinit_wmi(priv);
832 ieee80211_free_hw(hw);
836 void ath9k_htc_disconnect_device(struct htc_target *htc_handle, bool hotunplug)
838 if (htc_handle->drv_priv) {
840 /* Check if the device has been yanked out. */
842 htc_handle->drv_priv->ah->ah_flags |= AH_UNPLUGGED;
844 ath9k_deinit_device(htc_handle->drv_priv);
845 ath9k_deinit_wmi(htc_handle->drv_priv);
846 ieee80211_free_hw(htc_handle->drv_priv->hw);
852 void ath9k_htc_suspend(struct htc_target *htc_handle)
854 ath9k_htc_setpower(htc_handle->drv_priv, ATH9K_PM_FULL_SLEEP);
857 int ath9k_htc_resume(struct htc_target *htc_handle)
859 struct ath9k_htc_priv *priv = htc_handle->drv_priv;
862 ret = ath9k_htc_wait_for_target(priv);
866 ret = ath9k_init_htc_services(priv, priv->ah->hw_version.devid,
867 priv->ah->hw_version.usbdev);
868 ath9k_configure_leds(priv);
874 static int __init ath9k_htc_init(void)
876 if (ath9k_hif_usb_init() < 0) {
877 pr_err("No USB devices found, driver not installed\n");
883 module_init(ath9k_htc_init);
885 static void __exit ath9k_htc_exit(void)
887 ath9k_hif_usb_exit();
888 pr_info("Driver unloaded\n");
890 module_exit(ath9k_htc_exit);