mac80211: add pending patches for throughput based led blinking and replace the broke...
[openwrt/svn-archive/archive.git] / package / mac80211 / patches / 565-ath9k_cleanup_led_blink.patch
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
4
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 */
9 -
10 -enum ath_led_type {
11 - ATH_LED_RADIO,
12 - ATH_LED_ASSOC,
13 - ATH_LED_TX,
14 - ATH_LED_RX
15 -};
16 -
17 -struct ath_led {
18 - struct ath_softc *sc;
19 - struct led_classdev led_cdev;
20 - enum ath_led_type led_type;
21 - char name[32];
22 - bool registered;
23 -};
24
25 +#ifdef CONFIG_MAC80211_LEDS
26 void ath_init_leds(struct ath_softc *sc);
27 void ath_deinit_leds(struct ath_softc *sc);
28 +#else
29 +static inline void ath_init_leds(struct ath_softc *sc)
30 +{
31 +}
32 +
33 +static inline void ath_deinit_leds(struct ath_softc *sc)
34 +{
35 +}
36 +#endif
37 +
38
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];
44
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;
52 - int led_on_cnt;
53 - int led_off_cnt;
54 +#ifdef CONFIG_MAC80211_LEDS
55 + bool led_registered;
56 + char led_name[32];
57 + struct led_classdev led_cdev;
58 +#endif
59
60 int beacon_interval;
61
62 --- a/drivers/net/wireless/ath/ath9k/gpio.c
63 +++ b/drivers/net/wireless/ath/ath9k/gpio.c
64 @@ -20,115 +20,34 @@
65 /* LED functions */
66 /********************************/
67
68 -static void ath_led_blink_work(struct work_struct *work)
69 -{
70 - struct ath_softc *sc = container_of(work, struct ath_softc,
71 - ath_led_blink_work.work);
72 -
73 - if (!(sc->sc_flags & SC_OP_LED_ASSOCIATED))
74 - return;
75 -
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);
79 - else
80 - ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin,
81 - (sc->sc_flags & SC_OP_LED_ON) ? 1 : 0);
82 -
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));
88 -
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;
98 - else
99 - sc->sc_flags |= SC_OP_LED_ON;
100 -}
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 },
113 +};
114
115 static void ath_led_brightness(struct led_classdev *led_cdev,
116 enum led_brightness brightness)
117 {
118 - struct ath_led *led = container_of(led_cdev, struct ath_led, led_cdev);
119 - struct ath_softc *sc = led->sc;
120 -
121 - switch (brightness) {
122 - case LED_OFF:
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;
130 - } else {
131 - sc->led_off_cnt++;
132 - }
133 - break;
134 - case LED_FULL:
135 - if (led->led_type == ATH_LED_ASSOC) {
136 - sc->sc_flags |= SC_OP_LED_ASSOCIATED;
137 - if (led_blink)
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;
143 - } else {
144 - sc->led_on_cnt++;
145 - }
146 - break;
147 - default:
148 - break;
149 - }
150 -}
151 -
152 -static int ath_register_led(struct ath_softc *sc, struct ath_led *led,
153 - char *trigger)
154 -{
155 - int ret;
156 -
157 - led->sc = sc;
158 - led->led_cdev.name = led->name;
159 - led->led_cdev.default_trigger = trigger;
160 - led->led_cdev.brightness_set = ath_led_brightness;
161 -
162 - ret = led_classdev_register(wiphy_dev(sc->hw->wiphy), &led->led_cdev);
163 - if (ret)
164 - ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_FATAL,
165 - "Failed to register led:%s", led->name);
166 - else
167 - led->registered = 1;
168 - return ret;
169 -}
170 -
171 -static void ath_unregister_led(struct ath_led *led)
172 -{
173 - if (led->registered) {
174 - led_classdev_unregister(&led->led_cdev);
175 - led->registered = 0;
176 - }
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));
179 }
180
181 void ath_deinit_leds(struct ath_softc *sc)
182 {
183 - if (AR_SREV_9100(sc->sc_ah))
184 + if (!sc->led_registered)
185 return;
186
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);
195 }
196
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);
201
202 - if (led_blink)
203 - INIT_DELAYED_WORK(&sc->ath_led_blink_work, ath_led_blink_work);
204 + /*
205 + * create the tpt trigger even if led_blink is disabled, so that
206 + * user space can still make use of it
207 + */
208 + trigger = ieee80211_create_tpt_led_trigger(sc->hw, HZ, ath9k_blink,
209 + ARRAY_SIZE(ath9k_blink));
210 + if (!led_blink)
211 + trigger = ieee80211_get_radio_led_name(sc->hw);
212 +
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;
218 +
219 + ret = led_classdev_register(wiphy_dev(sc->hw->wiphy), &sc->led_cdev);
220 + if (ret < 0)
221 + return;
222
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;
228 - if (ret)
229 - goto fail;
230 -
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;
236 - if (ret)
237 - goto fail;
238 -
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;
244 - if (ret)
245 - goto fail;
246 -
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;
252 - if (ret)
253 - goto fail;
254 -
255 - return;
256 -
257 -fail:
258 - if (led_blink)
259 - cancel_delayed_work_sync(&sc->ath_led_blink_work);
260 - ath_deinit_leds(sc);
261 + sc->led_registered = true;
262 }
263 +#endif
264
265 /*******************/
266 /* Rfkill */
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_
270
271 aphy->state = ATH_WIPHY_INACTIVE;
272
273 - if (led_blink)
274 - cancel_delayed_work_sync(&sc->ath_led_blink_work);
275 -
276 cancel_delayed_work_sync(&sc->tx_complete_work);
277 cancel_work_sync(&sc->paprd_work);
278 cancel_work_sync(&sc->hw_check_work);