aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/ath/ath9k/gpio.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/wireless/ath/ath9k/gpio.c')
-rw-r--r--drivers/net/wireless/ath/ath9k/gpio.c254
1 files changed, 57 insertions, 197 deletions
diff --git a/drivers/net/wireless/ath/ath9k/gpio.c b/drivers/net/wireless/ath/ath9k/gpio.c
index 3a8ee999da5d..bc713fc28191 100644
--- a/drivers/net/wireless/ath/ath9k/gpio.c
+++ b/drivers/net/wireless/ath/ath9k/gpio.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2008-2009 Atheros Communications Inc. 2 * Copyright (c) 2008-2011 Atheros Communications Inc.
3 * 3 *
4 * Permission to use, copy, modify, and/or distribute this software for any 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 5 * purpose with or without fee is hereby granted, provided that the above
@@ -20,123 +20,37 @@
20/* LED functions */ 20/* LED functions */
21/********************************/ 21/********************************/
22 22
23static void ath_led_blink_work(struct work_struct *work) 23#ifdef CONFIG_MAC80211_LEDS
24{
25 struct ath_softc *sc = container_of(work, struct ath_softc,
26 ath_led_blink_work.work);
27
28 if (!(sc->sc_flags & SC_OP_LED_ASSOCIATED))
29 return;
30
31 if ((sc->led_on_duration == ATH_LED_ON_DURATION_IDLE) ||
32 (sc->led_off_duration == ATH_LED_OFF_DURATION_IDLE))
33 ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, 0);
34 else
35 ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin,
36 (sc->sc_flags & SC_OP_LED_ON) ? 1 : 0);
37
38 ieee80211_queue_delayed_work(sc->hw,
39 &sc->ath_led_blink_work,
40 (sc->sc_flags & SC_OP_LED_ON) ?
41 msecs_to_jiffies(sc->led_off_duration) :
42 msecs_to_jiffies(sc->led_on_duration));
43
44 sc->led_on_duration = sc->led_on_cnt ?
45 max((ATH_LED_ON_DURATION_IDLE - sc->led_on_cnt), 25) :
46 ATH_LED_ON_DURATION_IDLE;
47 sc->led_off_duration = sc->led_off_cnt ?
48 max((ATH_LED_OFF_DURATION_IDLE - sc->led_off_cnt), 10) :
49 ATH_LED_OFF_DURATION_IDLE;
50 sc->led_on_cnt = sc->led_off_cnt = 0;
51 if (sc->sc_flags & SC_OP_LED_ON)
52 sc->sc_flags &= ~SC_OP_LED_ON;
53 else
54 sc->sc_flags |= SC_OP_LED_ON;
55}
56
57static void ath_led_brightness(struct led_classdev *led_cdev, 24static void ath_led_brightness(struct led_classdev *led_cdev,
58 enum led_brightness brightness) 25 enum led_brightness brightness)
59{ 26{
60 struct ath_led *led = container_of(led_cdev, struct ath_led, led_cdev); 27 struct ath_softc *sc = container_of(led_cdev, struct ath_softc, led_cdev);
61 struct ath_softc *sc = led->sc; 28 ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, (brightness == LED_OFF));
62
63 switch (brightness) {
64 case LED_OFF:
65 if (led->led_type == ATH_LED_ASSOC ||
66 led->led_type == ATH_LED_RADIO) {
67 ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin,
68 (led->led_type == ATH_LED_RADIO));
69 sc->sc_flags &= ~SC_OP_LED_ASSOCIATED;
70 if (led->led_type == ATH_LED_RADIO)
71 sc->sc_flags &= ~SC_OP_LED_ON;
72 } else {
73 sc->led_off_cnt++;
74 }
75 break;
76 case LED_FULL:
77 if (led->led_type == ATH_LED_ASSOC) {
78 sc->sc_flags |= SC_OP_LED_ASSOCIATED;
79 if (led_blink)
80 ieee80211_queue_delayed_work(sc->hw,
81 &sc->ath_led_blink_work, 0);
82 } else if (led->led_type == ATH_LED_RADIO) {
83 ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, 0);
84 sc->sc_flags |= SC_OP_LED_ON;
85 } else {
86 sc->led_on_cnt++;
87 }
88 break;
89 default:
90 break;
91 }
92}
93
94static int ath_register_led(struct ath_softc *sc, struct ath_led *led,
95 char *trigger)
96{
97 int ret;
98
99 led->sc = sc;
100 led->led_cdev.name = led->name;
101 led->led_cdev.default_trigger = trigger;
102 led->led_cdev.brightness_set = ath_led_brightness;
103
104 ret = led_classdev_register(wiphy_dev(sc->hw->wiphy), &led->led_cdev);
105 if (ret)
106 ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_FATAL,
107 "Failed to register led:%s", led->name);
108 else
109 led->registered = 1;
110 return ret;
111}
112
113static void ath_unregister_led(struct ath_led *led)
114{
115 if (led->registered) {
116 led_classdev_unregister(&led->led_cdev);
117 led->registered = 0;
118 }
119} 29}
120 30
121void ath_deinit_leds(struct ath_softc *sc) 31void ath_deinit_leds(struct ath_softc *sc)
122{ 32{
123 ath_unregister_led(&sc->assoc_led); 33 if (!sc->led_registered)
124 sc->sc_flags &= ~SC_OP_LED_ASSOCIATED; 34 return;
125 ath_unregister_led(&sc->tx_led); 35
126 ath_unregister_led(&sc->rx_led); 36 ath_led_brightness(&sc->led_cdev, LED_OFF);
127 ath_unregister_led(&sc->radio_led); 37 led_classdev_unregister(&sc->led_cdev);
128 ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, 1);
129} 38}
130 39
131void ath_init_leds(struct ath_softc *sc) 40void ath_init_leds(struct ath_softc *sc)
132{ 41{
133 char *trigger;
134 int ret; 42 int ret;
135 43
136 if (AR_SREV_9287(sc->sc_ah)) 44 if (sc->sc_ah->led_pin < 0) {
137 sc->sc_ah->led_pin = ATH_LED_PIN_9287; 45 if (AR_SREV_9287(sc->sc_ah))
138 else 46 sc->sc_ah->led_pin = ATH_LED_PIN_9287;
139 sc->sc_ah->led_pin = ATH_LED_PIN_DEF; 47 else if (AR_SREV_9485(sc->sc_ah))
48 sc->sc_ah->led_pin = ATH_LED_PIN_9485;
49 else if (AR_SREV_9300(sc->sc_ah))
50 sc->sc_ah->led_pin = ATH_LED_PIN_9300;
51 else
52 sc->sc_ah->led_pin = ATH_LED_PIN_DEF;
53 }
140 54
141 /* Configure gpio 1 for output */ 55 /* Configure gpio 1 for output */
142 ath9k_hw_cfg_output(sc->sc_ah, sc->sc_ah->led_pin, 56 ath9k_hw_cfg_output(sc->sc_ah, sc->sc_ah->led_pin,
@@ -144,48 +58,22 @@ void ath_init_leds(struct ath_softc *sc)
144 /* LED off, active low */ 58 /* LED off, active low */
145 ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, 1); 59 ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, 1);
146 60
147 if (led_blink) 61 if (!led_blink)
148 INIT_DELAYED_WORK(&sc->ath_led_blink_work, ath_led_blink_work); 62 sc->led_cdev.default_trigger =
149 63 ieee80211_get_radio_led_name(sc->hw);
150 trigger = ieee80211_get_radio_led_name(sc->hw); 64
151 snprintf(sc->radio_led.name, sizeof(sc->radio_led.name), 65 snprintf(sc->led_name, sizeof(sc->led_name),
152 "ath9k-%s::radio", wiphy_name(sc->hw->wiphy)); 66 "ath9k-%s", wiphy_name(sc->hw->wiphy));
153 ret = ath_register_led(sc, &sc->radio_led, trigger); 67 sc->led_cdev.name = sc->led_name;
154 sc->radio_led.led_type = ATH_LED_RADIO; 68 sc->led_cdev.brightness_set = ath_led_brightness;
155 if (ret) 69
156 goto fail; 70 ret = led_classdev_register(wiphy_dev(sc->hw->wiphy), &sc->led_cdev);
157 71 if (ret < 0)
158 trigger = ieee80211_get_assoc_led_name(sc->hw); 72 return;
159 snprintf(sc->assoc_led.name, sizeof(sc->assoc_led.name), 73
160 "ath9k-%s::assoc", wiphy_name(sc->hw->wiphy)); 74 sc->led_registered = true;
161 ret = ath_register_led(sc, &sc->assoc_led, trigger);
162 sc->assoc_led.led_type = ATH_LED_ASSOC;
163 if (ret)
164 goto fail;
165
166 trigger = ieee80211_get_tx_led_name(sc->hw);
167 snprintf(sc->tx_led.name, sizeof(sc->tx_led.name),
168 "ath9k-%s::tx", wiphy_name(sc->hw->wiphy));
169 ret = ath_register_led(sc, &sc->tx_led, trigger);
170 sc->tx_led.led_type = ATH_LED_TX;
171 if (ret)
172 goto fail;
173
174 trigger = ieee80211_get_rx_led_name(sc->hw);
175 snprintf(sc->rx_led.name, sizeof(sc->rx_led.name),
176 "ath9k-%s::rx", wiphy_name(sc->hw->wiphy));
177 ret = ath_register_led(sc, &sc->rx_led, trigger);
178 sc->rx_led.led_type = ATH_LED_RX;
179 if (ret)
180 goto fail;
181
182 return;
183
184fail:
185 if (led_blink)
186 cancel_delayed_work_sync(&sc->ath_led_blink_work);
187 ath_deinit_leds(sc);
188} 75}
76#endif
189 77
190/*******************/ 78/*******************/
191/* Rfkill */ 79/* Rfkill */
@@ -201,8 +89,7 @@ static bool ath_is_rfkill_set(struct ath_softc *sc)
201 89
202void ath9k_rfkill_poll_state(struct ieee80211_hw *hw) 90void ath9k_rfkill_poll_state(struct ieee80211_hw *hw)
203{ 91{
204 struct ath_wiphy *aphy = hw->priv; 92 struct ath_softc *sc = hw->priv;
205 struct ath_softc *sc = aphy->sc;
206 bool blocked = !!ath_is_rfkill_set(sc); 93 bool blocked = !!ath_is_rfkill_set(sc);
207 94
208 wiphy_rfkill_set_hw_state(hw->wiphy, blocked); 95 wiphy_rfkill_set_hw_state(hw->wiphy, blocked);
@@ -236,13 +123,13 @@ static void ath_detect_bt_priority(struct ath_softc *sc)
236 sc->sc_flags &= ~(SC_OP_BT_PRIORITY_DETECTED | SC_OP_BT_SCAN); 123 sc->sc_flags &= ~(SC_OP_BT_PRIORITY_DETECTED | SC_OP_BT_SCAN);
237 /* Detect if colocated bt started scanning */ 124 /* Detect if colocated bt started scanning */
238 if (btcoex->bt_priority_cnt >= ATH_BT_CNT_SCAN_THRESHOLD) { 125 if (btcoex->bt_priority_cnt >= ATH_BT_CNT_SCAN_THRESHOLD) {
239 ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_BTCOEX, 126 ath_dbg(ath9k_hw_common(sc->sc_ah), ATH_DBG_BTCOEX,
240 "BT scan detected"); 127 "BT scan detected\n");
241 sc->sc_flags |= (SC_OP_BT_SCAN | 128 sc->sc_flags |= (SC_OP_BT_SCAN |
242 SC_OP_BT_PRIORITY_DETECTED); 129 SC_OP_BT_PRIORITY_DETECTED);
243 } else if (btcoex->bt_priority_cnt >= ATH_BT_CNT_THRESHOLD) { 130 } else if (btcoex->bt_priority_cnt >= ATH_BT_CNT_THRESHOLD) {
244 ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_BTCOEX, 131 ath_dbg(ath9k_hw_common(sc->sc_ah), ATH_DBG_BTCOEX,
245 "BT priority traffic detected"); 132 "BT priority traffic detected\n");
246 sc->sc_flags |= SC_OP_BT_PRIORITY_DETECTED; 133 sc->sc_flags |= SC_OP_BT_PRIORITY_DETECTED;
247 } 134 }
248 135
@@ -251,45 +138,15 @@ static void ath_detect_bt_priority(struct ath_softc *sc)
251 } 138 }
252} 139}
253 140
254/*
255 * Configures appropriate weight based on stomp type.
256 */
257static void ath9k_btcoex_bt_stomp(struct ath_softc *sc,
258 enum ath_stomp_type stomp_type)
259{
260 struct ath_hw *ah = sc->sc_ah;
261
262 switch (stomp_type) {
263 case ATH_BTCOEX_STOMP_ALL:
264 ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT,
265 AR_STOMP_ALL_WLAN_WGHT);
266 break;
267 case ATH_BTCOEX_STOMP_LOW:
268 ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT,
269 AR_STOMP_LOW_WLAN_WGHT);
270 break;
271 case ATH_BTCOEX_STOMP_NONE:
272 ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT,
273 AR_STOMP_NONE_WLAN_WGHT);
274 break;
275 default:
276 ath_print(ath9k_hw_common(ah), ATH_DBG_BTCOEX,
277 "Invalid Stomptype\n");
278 break;
279 }
280
281 ath9k_hw_btcoex_enable(ah);
282}
283
284static void ath9k_gen_timer_start(struct ath_hw *ah, 141static void ath9k_gen_timer_start(struct ath_hw *ah,
285 struct ath_gen_timer *timer, 142 struct ath_gen_timer *timer,
286 u32 timer_next, 143 u32 trig_timeout,
287 u32 timer_period) 144 u32 timer_period)
288{ 145{
289 ath9k_hw_gen_timer_start(ah, timer, timer_next, timer_period); 146 ath9k_hw_gen_timer_start(ah, timer, trig_timeout, timer_period);
290 147
291 if ((ah->imask & ATH9K_INT_GENTIMER) == 0) { 148 if ((ah->imask & ATH9K_INT_GENTIMER) == 0) {
292 ath9k_hw_set_interrupts(ah, 0); 149 ath9k_hw_disable_interrupts(ah);
293 ah->imask |= ATH9K_INT_GENTIMER; 150 ah->imask |= ATH9K_INT_GENTIMER;
294 ath9k_hw_set_interrupts(ah, ah->imask); 151 ath9k_hw_set_interrupts(ah, ah->imask);
295 } 152 }
@@ -303,7 +160,7 @@ static void ath9k_gen_timer_stop(struct ath_hw *ah, struct ath_gen_timer *timer)
303 160
304 /* if no timer is enabled, turn off interrupt mask */ 161 /* if no timer is enabled, turn off interrupt mask */
305 if (timer_table->timer_mask.val == 0) { 162 if (timer_table->timer_mask.val == 0) {
306 ath9k_hw_set_interrupts(ah, 0); 163 ath9k_hw_disable_interrupts(ah);
307 ah->imask &= ~ATH9K_INT_GENTIMER; 164 ah->imask &= ~ATH9K_INT_GENTIMER;
308 ath9k_hw_set_interrupts(ah, ah->imask); 165 ath9k_hw_set_interrupts(ah, ah->imask);
309 } 166 }
@@ -322,13 +179,14 @@ static void ath_btcoex_period_timer(unsigned long data)
322 u32 timer_period; 179 u32 timer_period;
323 bool is_btscan; 180 bool is_btscan;
324 181
182 ath9k_ps_wakeup(sc);
325 ath_detect_bt_priority(sc); 183 ath_detect_bt_priority(sc);
326 184
327 is_btscan = sc->sc_flags & SC_OP_BT_SCAN; 185 is_btscan = sc->sc_flags & SC_OP_BT_SCAN;
328 186
329 spin_lock_bh(&btcoex->btcoex_lock); 187 spin_lock_bh(&btcoex->btcoex_lock);
330 188
331 ath9k_btcoex_bt_stomp(sc, is_btscan ? ATH_BTCOEX_STOMP_ALL : 189 ath9k_hw_btcoex_bt_stomp(ah, is_btscan ? ATH_BTCOEX_STOMP_ALL :
332 btcoex->bt_stomp_type); 190 btcoex->bt_stomp_type);
333 191
334 spin_unlock_bh(&btcoex->btcoex_lock); 192 spin_unlock_bh(&btcoex->btcoex_lock);
@@ -339,13 +197,12 @@ static void ath_btcoex_period_timer(unsigned long data)
339 197
340 timer_period = is_btscan ? btcoex->btscan_no_stomp : 198 timer_period = is_btscan ? btcoex->btscan_no_stomp :
341 btcoex->btcoex_no_stomp; 199 btcoex->btcoex_no_stomp;
342 ath9k_gen_timer_start(ah, 200 ath9k_gen_timer_start(ah, btcoex->no_stomp_timer, timer_period,
343 btcoex->no_stomp_timer, 201 timer_period * 10);
344 (ath9k_hw_gettsf32(ah) +
345 timer_period), timer_period * 10);
346 btcoex->hw_timer_enabled = true; 202 btcoex->hw_timer_enabled = true;
347 } 203 }
348 204
205 ath9k_ps_restore(sc);
349 mod_timer(&btcoex->period_timer, jiffies + 206 mod_timer(&btcoex->period_timer, jiffies +
350 msecs_to_jiffies(ATH_BTCOEX_DEF_BT_PERIOD)); 207 msecs_to_jiffies(ATH_BTCOEX_DEF_BT_PERIOD));
351} 208}
@@ -359,19 +216,22 @@ static void ath_btcoex_no_stomp_timer(void *arg)
359 struct ath_softc *sc = (struct ath_softc *)arg; 216 struct ath_softc *sc = (struct ath_softc *)arg;
360 struct ath_hw *ah = sc->sc_ah; 217 struct ath_hw *ah = sc->sc_ah;
361 struct ath_btcoex *btcoex = &sc->btcoex; 218 struct ath_btcoex *btcoex = &sc->btcoex;
219 struct ath_common *common = ath9k_hw_common(ah);
362 bool is_btscan = sc->sc_flags & SC_OP_BT_SCAN; 220 bool is_btscan = sc->sc_flags & SC_OP_BT_SCAN;
363 221
364 ath_print(ath9k_hw_common(ah), ATH_DBG_BTCOEX, 222 ath_dbg(common, ATH_DBG_BTCOEX,
365 "no stomp timer running\n"); 223 "no stomp timer running\n");
366 224
225 ath9k_ps_wakeup(sc);
367 spin_lock_bh(&btcoex->btcoex_lock); 226 spin_lock_bh(&btcoex->btcoex_lock);
368 227
369 if (btcoex->bt_stomp_type == ATH_BTCOEX_STOMP_LOW || is_btscan) 228 if (btcoex->bt_stomp_type == ATH_BTCOEX_STOMP_LOW || is_btscan)
370 ath9k_btcoex_bt_stomp(sc, ATH_BTCOEX_STOMP_NONE); 229 ath9k_hw_btcoex_bt_stomp(ah, ATH_BTCOEX_STOMP_NONE);
371 else if (btcoex->bt_stomp_type == ATH_BTCOEX_STOMP_ALL) 230 else if (btcoex->bt_stomp_type == ATH_BTCOEX_STOMP_ALL)
372 ath9k_btcoex_bt_stomp(sc, ATH_BTCOEX_STOMP_LOW); 231 ath9k_hw_btcoex_bt_stomp(ah, ATH_BTCOEX_STOMP_LOW);
373 232
374 spin_unlock_bh(&btcoex->btcoex_lock); 233 spin_unlock_bh(&btcoex->btcoex_lock);
234 ath9k_ps_restore(sc);
375} 235}
376 236
377int ath_init_btcoex_timer(struct ath_softc *sc) 237int ath_init_btcoex_timer(struct ath_softc *sc)
@@ -408,8 +268,8 @@ void ath9k_btcoex_timer_resume(struct ath_softc *sc)
408 struct ath_btcoex *btcoex = &sc->btcoex; 268 struct ath_btcoex *btcoex = &sc->btcoex;
409 struct ath_hw *ah = sc->sc_ah; 269 struct ath_hw *ah = sc->sc_ah;
410 270
411 ath_print(ath9k_hw_common(ah), ATH_DBG_BTCOEX, 271 ath_dbg(ath9k_hw_common(ah), ATH_DBG_BTCOEX,
412 "Starting btcoex timers"); 272 "Starting btcoex timers\n");
413 273
414 /* make sure duty cycle timer is also stopped when resuming */ 274 /* make sure duty cycle timer is also stopped when resuming */
415 if (btcoex->hw_timer_enabled) 275 if (btcoex->hw_timer_enabled)