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