blob: 270a319f3aebb903f9d20140f87a3bf57d51f96a [file] [log] [blame]
Tobias Doerffele6a3b612009-06-09 17:33:27 +02001/*
2 * RFKILL support for ath5k
3 *
4 * Copyright (c) 2009 Tobias Doerffel <tobias.doerffel@gmail.com>
5 *
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer,
13 * without modification.
14 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
15 * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
16 * redistribution must be conditioned upon including a substantially
17 * similar Disclaimer requirement for further binary redistribution.
18 * 3. Neither the names of the above-listed copyright holders nor the names
19 * of any contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * NO WARRANTY
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
26 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
27 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
28 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
31 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
33 * THE POSSIBILITY OF SUCH DAMAGES.
34 */
35
Pavel Roskin931be262011-07-26 22:26:59 -040036#include "ath5k.h"
Tobias Doerffele6a3b612009-06-09 17:33:27 +020037
38
Pavel Roskine0d687b2011-07-14 20:21:55 -040039static inline void ath5k_rfkill_disable(struct ath5k_hw *ah)
Tobias Doerffele6a3b612009-06-09 17:33:27 +020040{
Pavel Roskine0d687b2011-07-14 20:21:55 -040041 ATH5K_DBG(ah, ATH5K_DEBUG_ANY, "rfkill disable (gpio:%d polarity:%d)\n",
42 ah->rf_kill.gpio, ah->rf_kill.polarity);
43 ath5k_hw_set_gpio_output(ah, ah->rf_kill.gpio);
44 ath5k_hw_set_gpio(ah, ah->rf_kill.gpio, !ah->rf_kill.polarity);
Tobias Doerffele6a3b612009-06-09 17:33:27 +020045}
46
47
Pavel Roskine0d687b2011-07-14 20:21:55 -040048static inline void ath5k_rfkill_enable(struct ath5k_hw *ah)
Tobias Doerffele6a3b612009-06-09 17:33:27 +020049{
Pavel Roskine0d687b2011-07-14 20:21:55 -040050 ATH5K_DBG(ah, ATH5K_DEBUG_ANY, "rfkill enable (gpio:%d polarity:%d)\n",
51 ah->rf_kill.gpio, ah->rf_kill.polarity);
52 ath5k_hw_set_gpio_output(ah, ah->rf_kill.gpio);
53 ath5k_hw_set_gpio(ah, ah->rf_kill.gpio, ah->rf_kill.polarity);
Tobias Doerffele6a3b612009-06-09 17:33:27 +020054}
55
Pavel Roskine0d687b2011-07-14 20:21:55 -040056static inline void ath5k_rfkill_set_intr(struct ath5k_hw *ah, bool enable)
Tobias Doerffele6a3b612009-06-09 17:33:27 +020057{
Bob Copelanda6ae0712009-06-09 23:43:11 -040058 u32 curval;
59
Pavel Roskine0d687b2011-07-14 20:21:55 -040060 ath5k_hw_set_gpio_input(ah, ah->rf_kill.gpio);
61 curval = ath5k_hw_get_gpio(ah, ah->rf_kill.gpio);
62 ath5k_hw_set_gpio_intr(ah, ah->rf_kill.gpio, enable ?
Bob Copelanda6ae0712009-06-09 23:43:11 -040063 !!curval : !curval);
Tobias Doerffele6a3b612009-06-09 17:33:27 +020064}
65
66static bool
Pavel Roskine0d687b2011-07-14 20:21:55 -040067ath5k_is_rfkill_set(struct ath5k_hw *ah)
Tobias Doerffele6a3b612009-06-09 17:33:27 +020068{
69 /* configuring GPIO for input for some reason disables rfkill */
Pavel Roskine0d687b2011-07-14 20:21:55 -040070 /*ath5k_hw_set_gpio_input(ah, ah->rf_kill.gpio);*/
71 return ath5k_hw_get_gpio(ah, ah->rf_kill.gpio) ==
72 ah->rf_kill.polarity;
Tobias Doerffele6a3b612009-06-09 17:33:27 +020073}
74
75static void
76ath5k_tasklet_rfkill_toggle(unsigned long data)
77{
Pavel Roskine0d687b2011-07-14 20:21:55 -040078 struct ath5k_hw *ah = (void *)data;
Tobias Doerffele6a3b612009-06-09 17:33:27 +020079 bool blocked;
80
Pavel Roskine0d687b2011-07-14 20:21:55 -040081 blocked = ath5k_is_rfkill_set(ah);
82 wiphy_rfkill_set_hw_state(ah->hw->wiphy, blocked);
Tobias Doerffele6a3b612009-06-09 17:33:27 +020083}
84
85
86void
87ath5k_rfkill_hw_start(struct ath5k_hw *ah)
88{
Tobias Doerffele6a3b612009-06-09 17:33:27 +020089 /* read rfkill GPIO configuration from EEPROM header */
Pavel Roskine0d687b2011-07-14 20:21:55 -040090 ah->rf_kill.gpio = ah->ah_capabilities.cap_eeprom.ee_rfkill_pin;
91 ah->rf_kill.polarity = ah->ah_capabilities.cap_eeprom.ee_rfkill_pol;
Tobias Doerffele6a3b612009-06-09 17:33:27 +020092
Pavel Roskine0d687b2011-07-14 20:21:55 -040093 tasklet_init(&ah->rf_kill.toggleq, ath5k_tasklet_rfkill_toggle,
94 (unsigned long)ah);
Tobias Doerffele6a3b612009-06-09 17:33:27 +020095
Pavel Roskine0d687b2011-07-14 20:21:55 -040096 ath5k_rfkill_disable(ah);
Tobias Doerffele6a3b612009-06-09 17:33:27 +020097
98 /* enable interrupt for rfkill switch */
Bob Copelanda6ae0712009-06-09 23:43:11 -040099 if (AR5K_EEPROM_HDR_RFKILL(ah->ah_capabilities.cap_eeprom.ee_header))
Pavel Roskine0d687b2011-07-14 20:21:55 -0400100 ath5k_rfkill_set_intr(ah, true);
Tobias Doerffele6a3b612009-06-09 17:33:27 +0200101}
102
103
104void
105ath5k_rfkill_hw_stop(struct ath5k_hw *ah)
106{
Tobias Doerffele6a3b612009-06-09 17:33:27 +0200107 /* disable interrupt for rfkill switch */
Bob Copelanda6ae0712009-06-09 23:43:11 -0400108 if (AR5K_EEPROM_HDR_RFKILL(ah->ah_capabilities.cap_eeprom.ee_header))
Pavel Roskine0d687b2011-07-14 20:21:55 -0400109 ath5k_rfkill_set_intr(ah, false);
Tobias Doerffele6a3b612009-06-09 17:33:27 +0200110
Pavel Roskine0d687b2011-07-14 20:21:55 -0400111 tasklet_kill(&ah->rf_kill.toggleq);
Tobias Doerffele6a3b612009-06-09 17:33:27 +0200112
113 /* enable RFKILL when stopping HW so Wifi LED is turned off */
Pavel Roskine0d687b2011-07-14 20:21:55 -0400114 ath5k_rfkill_enable(ah);
Tobias Doerffele6a3b612009-06-09 17:33:27 +0200115}
116