1e6a3b616STobias Doerffel /*
2e6a3b616STobias Doerffel * RFKILL support for ath5k
3e6a3b616STobias Doerffel *
4e6a3b616STobias Doerffel * Copyright (c) 2009 Tobias Doerffel <tobias.doerffel@gmail.com>
5e6a3b616STobias Doerffel *
6e6a3b616STobias Doerffel * All rights reserved.
7e6a3b616STobias Doerffel *
8e6a3b616STobias Doerffel * Redistribution and use in source and binary forms, with or without
9e6a3b616STobias Doerffel * modification, are permitted provided that the following conditions
10e6a3b616STobias Doerffel * are met:
11e6a3b616STobias Doerffel * 1. Redistributions of source code must retain the above copyright
12e6a3b616STobias Doerffel * notice, this list of conditions and the following disclaimer,
13e6a3b616STobias Doerffel * without modification.
14e6a3b616STobias Doerffel * 2. Redistributions in binary form must reproduce at minimum a disclaimer
15e6a3b616STobias Doerffel * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
16e6a3b616STobias Doerffel * redistribution must be conditioned upon including a substantially
17e6a3b616STobias Doerffel * similar Disclaimer requirement for further binary redistribution.
18e6a3b616STobias Doerffel * 3. Neither the names of the above-listed copyright holders nor the names
19e6a3b616STobias Doerffel * of any contributors may be used to endorse or promote products derived
20e6a3b616STobias Doerffel * from this software without specific prior written permission.
21e6a3b616STobias Doerffel *
22e6a3b616STobias Doerffel * NO WARRANTY
23e6a3b616STobias Doerffel * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24e6a3b616STobias Doerffel * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25e6a3b616STobias Doerffel * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
26e6a3b616STobias Doerffel * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
27e6a3b616STobias Doerffel * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
28e6a3b616STobias Doerffel * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29e6a3b616STobias Doerffel * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30e6a3b616STobias Doerffel * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
31e6a3b616STobias Doerffel * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32e6a3b616STobias Doerffel * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
33e6a3b616STobias Doerffel * THE POSSIBILITY OF SUCH DAMAGES.
34e6a3b616STobias Doerffel */
35e6a3b616STobias Doerffel
36931be260SPavel Roskin #include "ath5k.h"
37e6a3b616STobias Doerffel
38e6a3b616STobias Doerffel
ath5k_rfkill_disable(struct ath5k_hw * ah)39e0d687bdSPavel Roskin static inline void ath5k_rfkill_disable(struct ath5k_hw *ah)
40e6a3b616STobias Doerffel {
41e0d687bdSPavel Roskin ATH5K_DBG(ah, ATH5K_DEBUG_ANY, "rfkill disable (gpio:%d polarity:%d)\n",
42e0d687bdSPavel Roskin ah->rf_kill.gpio, ah->rf_kill.polarity);
43e0d687bdSPavel Roskin ath5k_hw_set_gpio_output(ah, ah->rf_kill.gpio);
44e0d687bdSPavel Roskin ath5k_hw_set_gpio(ah, ah->rf_kill.gpio, !ah->rf_kill.polarity);
45e6a3b616STobias Doerffel }
46e6a3b616STobias Doerffel
47e6a3b616STobias Doerffel
ath5k_rfkill_enable(struct ath5k_hw * ah)48e0d687bdSPavel Roskin static inline void ath5k_rfkill_enable(struct ath5k_hw *ah)
49e6a3b616STobias Doerffel {
50e0d687bdSPavel Roskin ATH5K_DBG(ah, ATH5K_DEBUG_ANY, "rfkill enable (gpio:%d polarity:%d)\n",
51e0d687bdSPavel Roskin ah->rf_kill.gpio, ah->rf_kill.polarity);
52e0d687bdSPavel Roskin ath5k_hw_set_gpio_output(ah, ah->rf_kill.gpio);
53e0d687bdSPavel Roskin ath5k_hw_set_gpio(ah, ah->rf_kill.gpio, ah->rf_kill.polarity);
54e6a3b616STobias Doerffel }
55e6a3b616STobias Doerffel
ath5k_rfkill_set_intr(struct ath5k_hw * ah,bool enable)56e0d687bdSPavel Roskin static inline void ath5k_rfkill_set_intr(struct ath5k_hw *ah, bool enable)
57e6a3b616STobias Doerffel {
58a6ae0716SBob Copeland u32 curval;
59a6ae0716SBob Copeland
60e0d687bdSPavel Roskin ath5k_hw_set_gpio_input(ah, ah->rf_kill.gpio);
61e0d687bdSPavel Roskin curval = ath5k_hw_get_gpio(ah, ah->rf_kill.gpio);
62e0d687bdSPavel Roskin ath5k_hw_set_gpio_intr(ah, ah->rf_kill.gpio, enable ?
63a6ae0716SBob Copeland !!curval : !curval);
64e6a3b616STobias Doerffel }
65e6a3b616STobias Doerffel
66e6a3b616STobias Doerffel static bool
ath5k_is_rfkill_set(struct ath5k_hw * ah)67e0d687bdSPavel Roskin ath5k_is_rfkill_set(struct ath5k_hw *ah)
68e6a3b616STobias Doerffel {
69e6a3b616STobias Doerffel /* configuring GPIO for input for some reason disables rfkill */
70e0d687bdSPavel Roskin /*ath5k_hw_set_gpio_input(ah, ah->rf_kill.gpio);*/
71e0d687bdSPavel Roskin return ath5k_hw_get_gpio(ah, ah->rf_kill.gpio) ==
72e0d687bdSPavel Roskin ah->rf_kill.polarity;
73e6a3b616STobias Doerffel }
74e6a3b616STobias Doerffel
75e6a3b616STobias Doerffel static void
ath5k_tasklet_rfkill_toggle(struct tasklet_struct * t)76*c068a9ecSAllen Pais ath5k_tasklet_rfkill_toggle(struct tasklet_struct *t)
77e6a3b616STobias Doerffel {
78*c068a9ecSAllen Pais struct ath5k_hw *ah = from_tasklet(ah, t, rf_kill.toggleq);
79e6a3b616STobias Doerffel bool blocked;
80e6a3b616STobias Doerffel
81e0d687bdSPavel Roskin blocked = ath5k_is_rfkill_set(ah);
82e0d687bdSPavel Roskin wiphy_rfkill_set_hw_state(ah->hw->wiphy, blocked);
83e6a3b616STobias Doerffel }
84e6a3b616STobias Doerffel
85e6a3b616STobias Doerffel
86e6a3b616STobias Doerffel void
ath5k_rfkill_hw_start(struct ath5k_hw * ah)87e6a3b616STobias Doerffel ath5k_rfkill_hw_start(struct ath5k_hw *ah)
88e6a3b616STobias Doerffel {
89e6a3b616STobias Doerffel /* read rfkill GPIO configuration from EEPROM header */
90e0d687bdSPavel Roskin ah->rf_kill.gpio = ah->ah_capabilities.cap_eeprom.ee_rfkill_pin;
91e0d687bdSPavel Roskin ah->rf_kill.polarity = ah->ah_capabilities.cap_eeprom.ee_rfkill_pol;
92e6a3b616STobias Doerffel
93*c068a9ecSAllen Pais tasklet_setup(&ah->rf_kill.toggleq, ath5k_tasklet_rfkill_toggle);
94e6a3b616STobias Doerffel
95e0d687bdSPavel Roskin ath5k_rfkill_disable(ah);
96e6a3b616STobias Doerffel
97e6a3b616STobias Doerffel /* enable interrupt for rfkill switch */
98a6ae0716SBob Copeland if (AR5K_EEPROM_HDR_RFKILL(ah->ah_capabilities.cap_eeprom.ee_header))
99e0d687bdSPavel Roskin ath5k_rfkill_set_intr(ah, true);
100e6a3b616STobias Doerffel }
101e6a3b616STobias Doerffel
102e6a3b616STobias Doerffel
103e6a3b616STobias Doerffel void
ath5k_rfkill_hw_stop(struct ath5k_hw * ah)104e6a3b616STobias Doerffel ath5k_rfkill_hw_stop(struct ath5k_hw *ah)
105e6a3b616STobias Doerffel {
106e6a3b616STobias Doerffel /* disable interrupt for rfkill switch */
107a6ae0716SBob Copeland if (AR5K_EEPROM_HDR_RFKILL(ah->ah_capabilities.cap_eeprom.ee_header))
108e0d687bdSPavel Roskin ath5k_rfkill_set_intr(ah, false);
109e6a3b616STobias Doerffel
110e0d687bdSPavel Roskin tasklet_kill(&ah->rf_kill.toggleq);
111e6a3b616STobias Doerffel
112e6a3b616STobias Doerffel /* enable RFKILL when stopping HW so Wifi LED is turned off */
113e0d687bdSPavel Roskin ath5k_rfkill_enable(ah);
114e6a3b616STobias Doerffel }
115e6a3b616STobias Doerffel
116