a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync/*
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * RFKILL support for ath5k
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync *
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * Copyright (c) 2009 Tobias Doerffel <tobias.doerffel@gmail.com>
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * Lightly modified for iPXE, Sep 2008 by Joshua Oreman <oremanj@rwcr.net>
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync *
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * All rights reserved.
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync *
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * Redistribution and use in source and binary forms, with or without
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * modification, are permitted provided that the following conditions
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * are met:
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * 1. Redistributions of source code must retain the above copyright
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * notice, this list of conditions and the following disclaimer,
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * without modification.
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * 2. Redistributions in binary form must reproduce at minimum a disclaimer
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * redistribution must be conditioned upon including a substantially
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * similar Disclaimer requirement for further binary redistribution.
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * 3. Neither the names of the above-listed copyright holders nor the names
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * of any contributors may be used to endorse or promote products derived
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * from this software without specific prior written permission.
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync *
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * NO WARRANTY
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * THE POSSIBILITY OF SUCH DAMAGES.
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncFILE_LICENCE ( MIT );
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync#include "base.h"
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncstatic inline void ath5k_rfkill_disable(struct ath5k_softc *sc)
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync{
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync DBG("ath5k: rfkill disable (gpio:%d polarity:%d)\n",
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync sc->rf_kill.gpio, sc->rf_kill.polarity);
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync ath5k_hw_set_gpio_output(sc->ah, sc->rf_kill.gpio);
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync ath5k_hw_set_gpio(sc->ah, sc->rf_kill.gpio, !sc->rf_kill.polarity);
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync}
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncstatic inline void ath5k_rfkill_enable(struct ath5k_softc *sc)
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync{
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync DBG("ath5k: rfkill enable (gpio:%d polarity:%d)\n",
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync sc->rf_kill.gpio, sc->rf_kill.polarity);
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync ath5k_hw_set_gpio_output(sc->ah, sc->rf_kill.gpio);
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync ath5k_hw_set_gpio(sc->ah, sc->rf_kill.gpio, sc->rf_kill.polarity);
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync}
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncstatic inline void ath5k_rfkill_set_intr(struct ath5k_softc *sc, int enable)
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync{
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync struct ath5k_hw *ah = sc->ah;
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync u32 curval;
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync ath5k_hw_set_gpio_input(ah, sc->rf_kill.gpio);
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync curval = ath5k_hw_get_gpio(ah, sc->rf_kill.gpio);
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync ath5k_hw_set_gpio_intr(ah, sc->rf_kill.gpio, enable ?
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync !!curval : !curval);
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync}
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncstatic int __unused
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncath5k_is_rfkill_set(struct ath5k_softc *sc)
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync{
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /* configuring GPIO for input for some reason disables rfkill */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /*ath5k_hw_set_gpio_input(sc->ah, sc->rf_kill.gpio);*/
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync return (ath5k_hw_get_gpio(sc->ah, sc->rf_kill.gpio) ==
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync sc->rf_kill.polarity);
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync}
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncvoid
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncath5k_rfkill_hw_start(struct ath5k_hw *ah)
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync{
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync struct ath5k_softc *sc = ah->ah_sc;
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /* read rfkill GPIO configuration from EEPROM header */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync sc->rf_kill.gpio = ah->ah_capabilities.cap_eeprom.ee_rfkill_pin;
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync sc->rf_kill.polarity = ah->ah_capabilities.cap_eeprom.ee_rfkill_pol;
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync ath5k_rfkill_disable(sc);
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /* enable interrupt for rfkill switch */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync if (AR5K_EEPROM_HDR_RFKILL(ah->ah_capabilities.cap_eeprom.ee_header))
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync ath5k_rfkill_set_intr(sc, 1);
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync}
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncvoid
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncath5k_rfkill_hw_stop(struct ath5k_hw *ah)
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync{
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync struct ath5k_softc *sc = ah->ah_sc;
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /* disable interrupt for rfkill switch */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync if (AR5K_EEPROM_HDR_RFKILL(ah->ah_capabilities.cap_eeprom.ee_header))
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync ath5k_rfkill_set_intr(sc, 0);
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /* enable RFKILL when stopping HW so Wifi LED is turned off */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync ath5k_rfkill_enable(sc);
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync}