1 --- a/drivers/net/wireless/ath/ath9k/ath9k.h
2 +++ b/drivers/net/wireless/ath/ath9k/ath9k.h
3 @@ -437,26 +437,20 @@ void ath9k_btcoex_timer_pause(struct ath
5 #define ATH_LED_PIN_DEF 1
6 #define ATH_LED_PIN_9287 8
7 -#define ATH_LED_ON_DURATION_IDLE 350 /* in msecs */
8 -#define ATH_LED_OFF_DURATION_IDLE 250 /* in msecs */
18 - struct ath_softc *sc;
19 - struct led_classdev led_cdev;
20 - enum ath_led_type led_type;
25 +#ifdef CONFIG_MAC80211_LEDS
26 void ath_init_leds(struct ath_softc *sc);
27 void ath_deinit_leds(struct ath_softc *sc);
29 +static inline void ath_init_leds(struct ath_softc *sc)
33 +static inline void ath_deinit_leds(struct ath_softc *sc)
39 /* Antenna diversity/combining */
40 #define ATH_ANT_RX_CURRENT_SHIFT 4
41 @@ -606,15 +600,11 @@ struct ath_softc {
42 struct ath_beacon beacon;
43 struct ieee80211_supported_band sbands[IEEE80211_NUM_BANDS];
45 - struct ath_led radio_led;
46 - struct ath_led assoc_led;
47 - struct ath_led tx_led;
48 - struct ath_led rx_led;
49 - struct delayed_work ath_led_blink_work;
50 - int led_on_duration;
51 - int led_off_duration;
54 +#ifdef CONFIG_MAC80211_LEDS
55 + bool led_registered;
57 + struct led_classdev led_cdev;
62 --- a/drivers/net/wireless/ath/ath9k/gpio.c
63 +++ b/drivers/net/wireless/ath/ath9k/gpio.c
66 /********************************/
68 -static void ath_led_blink_work(struct work_struct *work)
70 - struct ath_softc *sc = container_of(work, struct ath_softc,
71 - ath_led_blink_work.work);
73 - if (!(sc->sc_flags & SC_OP_LED_ASSOCIATED))
76 - if ((sc->led_on_duration == ATH_LED_ON_DURATION_IDLE) ||
77 - (sc->led_off_duration == ATH_LED_OFF_DURATION_IDLE))
78 - ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, 0);
80 - ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin,
81 - (sc->sc_flags & SC_OP_LED_ON) ? 1 : 0);
83 - ieee80211_queue_delayed_work(sc->hw,
84 - &sc->ath_led_blink_work,
85 - (sc->sc_flags & SC_OP_LED_ON) ?
86 - msecs_to_jiffies(sc->led_off_duration) :
87 - msecs_to_jiffies(sc->led_on_duration));
89 - sc->led_on_duration = sc->led_on_cnt ?
90 - max((ATH_LED_ON_DURATION_IDLE - sc->led_on_cnt), 25) :
91 - ATH_LED_ON_DURATION_IDLE;
92 - sc->led_off_duration = sc->led_off_cnt ?
93 - max((ATH_LED_OFF_DURATION_IDLE - sc->led_off_cnt), 10) :
94 - ATH_LED_OFF_DURATION_IDLE;
95 - sc->led_on_cnt = sc->led_off_cnt = 0;
96 - if (sc->sc_flags & SC_OP_LED_ON)
97 - sc->sc_flags &= ~SC_OP_LED_ON;
99 - sc->sc_flags |= SC_OP_LED_ON;
101 +#ifdef CONFIG_MAC80211_LEDS
102 +static const struct ieee80211_tpt_blink ath9k_blink[] = {
103 + { .throughput = 0 * 1024, .blink_time = 334 },
104 + { .throughput = 1 * 1024, .blink_time = 260 },
105 + { .throughput = 5 * 1024, .blink_time = 220 },
106 + { .throughput = 10 * 1024, .blink_time = 190 },
107 + { .throughput = 20 * 1024, .blink_time = 170 },
108 + { .throughput = 50 * 1024, .blink_time = 150 },
109 + { .throughput = 70 * 1024, .blink_time = 130 },
110 + { .throughput = 100 * 1024, .blink_time = 110 },
111 + { .throughput = 200 * 1024, .blink_time = 80 },
112 + { .throughput = 300 * 1024, .blink_time = 50 },
115 static void ath_led_brightness(struct led_classdev *led_cdev,
116 enum led_brightness brightness)
118 - struct ath_led *led = container_of(led_cdev, struct ath_led, led_cdev);
119 - struct ath_softc *sc = led->sc;
121 - switch (brightness) {
123 - if (led->led_type == ATH_LED_ASSOC ||
124 - led->led_type == ATH_LED_RADIO) {
125 - ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin,
126 - (led->led_type == ATH_LED_RADIO));
127 - sc->sc_flags &= ~SC_OP_LED_ASSOCIATED;
128 - if (led->led_type == ATH_LED_RADIO)
129 - sc->sc_flags &= ~SC_OP_LED_ON;
135 - if (led->led_type == ATH_LED_ASSOC) {
136 - sc->sc_flags |= SC_OP_LED_ASSOCIATED;
138 - ieee80211_queue_delayed_work(sc->hw,
139 - &sc->ath_led_blink_work, 0);
140 - } else if (led->led_type == ATH_LED_RADIO) {
141 - ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, 0);
142 - sc->sc_flags |= SC_OP_LED_ON;
152 -static int ath_register_led(struct ath_softc *sc, struct ath_led *led,
158 - led->led_cdev.name = led->name;
159 - led->led_cdev.default_trigger = trigger;
160 - led->led_cdev.brightness_set = ath_led_brightness;
162 - ret = led_classdev_register(wiphy_dev(sc->hw->wiphy), &led->led_cdev);
164 - ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_FATAL,
165 - "Failed to register led:%s", led->name);
167 - led->registered = 1;
171 -static void ath_unregister_led(struct ath_led *led)
173 - if (led->registered) {
174 - led_classdev_unregister(&led->led_cdev);
175 - led->registered = 0;
177 + struct ath_softc *sc = container_of(led_cdev, struct ath_softc, led_cdev);
178 + ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, (brightness == LED_OFF));
181 void ath_deinit_leds(struct ath_softc *sc)
183 - if (AR_SREV_9100(sc->sc_ah))
184 + if (!sc->led_registered)
187 - ath_unregister_led(&sc->assoc_led);
188 - sc->sc_flags &= ~SC_OP_LED_ASSOCIATED;
189 - ath_unregister_led(&sc->tx_led);
190 - ath_unregister_led(&sc->rx_led);
191 - ath_unregister_led(&sc->radio_led);
192 - ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, 1);
193 + ath_led_brightness(&sc->led_cdev, LED_OFF);
194 + led_classdev_unregister(&sc->led_cdev);
197 void ath_init_leds(struct ath_softc *sc)
198 @@ -152,48 +71,28 @@ void ath_init_leds(struct ath_softc *sc)
199 /* LED off, active low */
200 ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, 1);
203 - INIT_DELAYED_WORK(&sc->ath_led_blink_work, ath_led_blink_work);
205 + * create the tpt trigger even if led_blink is disabled, so that
206 + * user space can still make use of it
208 + trigger = ieee80211_create_tpt_led_trigger(sc->hw, HZ, ath9k_blink,
209 + ARRAY_SIZE(ath9k_blink));
211 + trigger = ieee80211_get_radio_led_name(sc->hw);
213 + snprintf(sc->led_name, sizeof(sc->led_name),
214 + "ath9k-%s", wiphy_name(sc->hw->wiphy));
215 + sc->led_cdev.name = sc->led_name;
216 + sc->led_cdev.default_trigger = trigger;
217 + sc->led_cdev.brightness_set = ath_led_brightness;
219 + ret = led_classdev_register(wiphy_dev(sc->hw->wiphy), &sc->led_cdev);
223 - trigger = ieee80211_get_radio_led_name(sc->hw);
224 - snprintf(sc->radio_led.name, sizeof(sc->radio_led.name),
225 - "ath9k-%s::radio", wiphy_name(sc->hw->wiphy));
226 - ret = ath_register_led(sc, &sc->radio_led, trigger);
227 - sc->radio_led.led_type = ATH_LED_RADIO;
231 - trigger = ieee80211_get_assoc_led_name(sc->hw);
232 - snprintf(sc->assoc_led.name, sizeof(sc->assoc_led.name),
233 - "ath9k-%s::assoc", wiphy_name(sc->hw->wiphy));
234 - ret = ath_register_led(sc, &sc->assoc_led, trigger);
235 - sc->assoc_led.led_type = ATH_LED_ASSOC;
239 - trigger = ieee80211_get_tx_led_name(sc->hw);
240 - snprintf(sc->tx_led.name, sizeof(sc->tx_led.name),
241 - "ath9k-%s::tx", wiphy_name(sc->hw->wiphy));
242 - ret = ath_register_led(sc, &sc->tx_led, trigger);
243 - sc->tx_led.led_type = ATH_LED_TX;
247 - trigger = ieee80211_get_rx_led_name(sc->hw);
248 - snprintf(sc->rx_led.name, sizeof(sc->rx_led.name),
249 - "ath9k-%s::rx", wiphy_name(sc->hw->wiphy));
250 - ret = ath_register_led(sc, &sc->rx_led, trigger);
251 - sc->rx_led.led_type = ATH_LED_RX;
259 - cancel_delayed_work_sync(&sc->ath_led_blink_work);
260 - ath_deinit_leds(sc);
261 + sc->led_registered = true;
265 /*******************/
267 --- a/drivers/net/wireless/ath/ath9k/main.c
268 +++ b/drivers/net/wireless/ath/ath9k/main.c
269 @@ -1276,9 +1276,6 @@ static void ath9k_stop(struct ieee80211_
271 aphy->state = ATH_WIPHY_INACTIVE;
274 - cancel_delayed_work_sync(&sc->ath_led_blink_work);
276 cancel_delayed_work_sync(&sc->tx_complete_work);
277 cancel_work_sync(&sc->paprd_work);
278 cancel_work_sync(&sc->hw_check_work);