diff options
author | Michael Buesch <mb@bu3sch.de> | 2007-09-27 09:31:40 -0400 |
---|---|---|
committer | David S. Miller <davem@sunset.davemloft.net> | 2007-10-10 19:54:11 -0400 |
commit | 21954c367e4088c491122edd263964345bc1d3bf (patch) | |
tree | 149faa19794ff6834c56f3af4501fe921880092e /drivers/net/wireless/b43/leds.c | |
parent | 20405c08412a4d89357870d7220f9fb1c458b286 (diff) |
[B43]: LED triggers support
Drive the LEDs through the generic LED triggers.
Signed-off-by: Michael Buesch <mb@bu3sch.de>
Cc: Larry Finger <larry.finger@lwfinger.net>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/wireless/b43/leds.c')
-rw-r--r-- | drivers/net/wireless/b43/leds.c | 395 |
1 files changed, 164 insertions, 231 deletions
diff --git a/drivers/net/wireless/b43/leds.c b/drivers/net/wireless/b43/leds.c index 0f155b4f34eb..ddab856f1140 100644 --- a/drivers/net/wireless/b43/leds.c +++ b/drivers/net/wireless/b43/leds.c | |||
@@ -1,12 +1,13 @@ | |||
1 | /* | 1 | /* |
2 | 2 | ||
3 | Broadcom B43 wireless driver | 3 | Broadcom B43 wireless driver |
4 | LED control | ||
4 | 5 | ||
5 | Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>, | 6 | Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>, |
6 | Stefano Brivio <st3@riseup.net> | 7 | Copyright (c) 2005 Stefano Brivio <st3@riseup.net> |
7 | Michael Buesch <mb@bu3sch.de> | 8 | Copyright (c) 2005-2007 Michael Buesch <mb@bu3sch.de> |
8 | Danny van Dyk <kugelfang@gentoo.org> | 9 | Copyright (c) 2005 Danny van Dyk <kugelfang@gentoo.org> |
9 | Andreas Jaggi <andreas.jaggi@waterwave.ch> | 10 | Copyright (c) 2005 Andreas Jaggi <andreas.jaggi@waterwave.ch> |
10 | 11 | ||
11 | This program is free software; you can redistribute it and/or modify | 12 | This program is free software; you can redistribute it and/or modify |
12 | it under the terms of the GNU General Public License as published by | 13 | it under the terms of the GNU General Public License as published by |
@@ -27,272 +28,204 @@ | |||
27 | 28 | ||
28 | #include "b43.h" | 29 | #include "b43.h" |
29 | #include "leds.h" | 30 | #include "leds.h" |
30 | #include "main.h" | ||
31 | 31 | ||
32 | static void b43_led_changestate(struct b43_led *led) | ||
33 | { | ||
34 | struct b43_wldev *dev = led->dev; | ||
35 | const int index = led->index; | ||
36 | u16 ledctl; | ||
37 | |||
38 | B43_WARN_ON(!(index >= 0 && index < B43_NR_LEDS)); | ||
39 | B43_WARN_ON(!led->blink_interval); | ||
40 | ledctl = b43_read16(dev, B43_MMIO_GPIO_CONTROL); | ||
41 | ledctl ^= (1 << index); | ||
42 | b43_write16(dev, B43_MMIO_GPIO_CONTROL, ledctl); | ||
43 | } | ||
44 | 32 | ||
45 | static void b43_led_blink(unsigned long d) | 33 | static void b43_led_turn_on(struct b43_wldev *dev, u8 led_index, |
34 | bool activelow) | ||
46 | { | 35 | { |
47 | struct b43_led *led = (struct b43_led *)d; | 36 | struct b43_wl *wl = dev->wl; |
48 | struct b43_wldev *dev = led->dev; | ||
49 | unsigned long flags; | 37 | unsigned long flags; |
38 | u16 ctl; | ||
50 | 39 | ||
51 | spin_lock_irqsave(&dev->wl->leds_lock, flags); | 40 | spin_lock_irqsave(&wl->leds_lock, flags); |
52 | if (led->blink_interval) { | 41 | ctl = b43_read16(dev, B43_MMIO_GPIO_CONTROL); |
53 | b43_led_changestate(led); | 42 | if (activelow) |
54 | mod_timer(&led->blink_timer, jiffies + led->blink_interval); | 43 | ctl &= ~(1 << led_index); |
55 | } | 44 | else |
56 | spin_unlock_irqrestore(&dev->wl->leds_lock, flags); | 45 | ctl |= (1 << led_index); |
46 | b43_write16(dev, B43_MMIO_GPIO_CONTROL, ctl); | ||
47 | spin_unlock_irqrestore(&wl->leds_lock, flags); | ||
57 | } | 48 | } |
58 | 49 | ||
59 | static void b43_led_blink_start(struct b43_led *led, unsigned long interval) | 50 | static void b43_led_turn_off(struct b43_wldev *dev, u8 led_index, |
51 | bool activelow) | ||
60 | { | 52 | { |
61 | if (led->blink_interval) | 53 | struct b43_wl *wl = dev->wl; |
62 | return; | 54 | unsigned long flags; |
63 | led->blink_interval = interval; | 55 | u16 ctl; |
64 | b43_led_changestate(led); | 56 | |
65 | led->blink_timer.expires = jiffies + interval; | 57 | spin_lock_irqsave(&wl->leds_lock, flags); |
66 | add_timer(&led->blink_timer); | 58 | ctl = b43_read16(dev, B43_MMIO_GPIO_CONTROL); |
59 | if (activelow) | ||
60 | ctl |= (1 << led_index); | ||
61 | else | ||
62 | ctl &= ~(1 << led_index); | ||
63 | b43_write16(dev, B43_MMIO_GPIO_CONTROL, ctl); | ||
64 | spin_unlock_irqrestore(&wl->leds_lock, flags); | ||
67 | } | 65 | } |
68 | 66 | ||
69 | static void b43_led_blink_stop(struct b43_led *led, int sync) | 67 | /* Callback from the LED subsystem. */ |
68 | static void b43_led_brightness_set(struct led_classdev *led_dev, | ||
69 | enum led_brightness brightness) | ||
70 | { | 70 | { |
71 | struct b43_led *led = container_of(led_dev, struct b43_led, led_dev); | ||
71 | struct b43_wldev *dev = led->dev; | 72 | struct b43_wldev *dev = led->dev; |
72 | const int index = led->index; | 73 | bool radio_enabled; |
73 | u16 ledctl; | ||
74 | 74 | ||
75 | if (!led->blink_interval) | 75 | /* Checking the radio-enabled status here is slightly racy, |
76 | return; | 76 | * but we want to avoid the locking overhead and we don't care |
77 | if (unlikely(sync)) | 77 | * whether the LED has the wrong state for a second. */ |
78 | del_timer_sync(&led->blink_timer); | 78 | radio_enabled = (dev->phy.radio_on && dev->radio_hw_enable); |
79 | else | ||
80 | del_timer(&led->blink_timer); | ||
81 | led->blink_interval = 0; | ||
82 | 79 | ||
83 | /* Make sure the LED is turned off. */ | 80 | if (brightness == LED_OFF || !radio_enabled) |
84 | B43_WARN_ON(!(index >= 0 && index < B43_NR_LEDS)); | 81 | b43_led_turn_off(dev, led->index, led->activelow); |
85 | ledctl = b43_read16(dev, B43_MMIO_GPIO_CONTROL); | ||
86 | if (led->activelow) | ||
87 | ledctl |= (1 << index); | ||
88 | else | 82 | else |
89 | ledctl &= ~(1 << index); | 83 | b43_led_turn_on(dev, led->index, led->activelow); |
90 | b43_write16(dev, B43_MMIO_GPIO_CONTROL, ledctl); | ||
91 | } | 84 | } |
92 | 85 | ||
93 | static void b43_led_init_hardcoded(struct b43_wldev *dev, | 86 | static int b43_register_led(struct b43_wldev *dev, struct b43_led *led, |
94 | struct b43_led *led, int led_index) | 87 | const char *name, char *default_trigger, |
88 | u8 led_index, bool activelow) | ||
95 | { | 89 | { |
96 | struct ssb_bus *bus = dev->dev->bus; | 90 | int err; |
91 | |||
92 | b43_led_turn_off(dev, led_index, activelow); | ||
93 | if (led->dev) | ||
94 | return -EEXIST; | ||
95 | if (!default_trigger) | ||
96 | return -EINVAL; | ||
97 | led->dev = dev; | ||
98 | led->index = led_index; | ||
99 | led->activelow = activelow; | ||
100 | strncpy(led->name, name, sizeof(led->name)); | ||
101 | |||
102 | led->led_dev.name = led->name; | ||
103 | led->led_dev.default_trigger = default_trigger; | ||
104 | led->led_dev.brightness_set = b43_led_brightness_set; | ||
105 | |||
106 | err = led_classdev_register(dev->dev->dev, &led->led_dev); | ||
107 | if (err) { | ||
108 | b43warn(dev->wl, "LEDs: Failed to register %s\n", name); | ||
109 | led->dev = NULL; | ||
110 | return err; | ||
111 | } | ||
112 | return 0; | ||
113 | } | ||
114 | |||
115 | static void b43_unregister_led(struct b43_led *led) | ||
116 | { | ||
117 | if (!led->dev) | ||
118 | return; | ||
119 | led_classdev_unregister(&led->led_dev); | ||
120 | b43_led_turn_off(led->dev, led->index, led->activelow); | ||
121 | led->dev = NULL; | ||
122 | } | ||
97 | 123 | ||
98 | /* This function is called, if the behaviour (and activelow) | 124 | static void b43_map_led(struct b43_wldev *dev, |
99 | * information for a LED is missing in the SPROM. | 125 | u8 led_index, |
100 | * We hardcode the behaviour values for various devices here. | 126 | enum b43_led_behaviour behaviour, |
101 | * Note that the B43_LED_TEST_XXX behaviour values can | 127 | bool activelow) |
102 | * be used to figure out which led is mapped to which index. | 128 | { |
103 | */ | 129 | struct ieee80211_hw *hw = dev->wl->hw; |
130 | char name[B43_LED_MAX_NAME_LEN + 1]; | ||
104 | 131 | ||
105 | switch (led_index) { | 132 | /* Map the b43 specific LED behaviour value to the |
106 | case 0: | 133 | * generic LED triggers. */ |
107 | led->behaviour = B43_LED_ACTIVITY; | 134 | switch (behaviour) { |
108 | led->activelow = 1; | 135 | case B43_LED_INACTIVE: |
109 | if (bus->boardinfo.vendor == PCI_VENDOR_ID_COMPAQ) | 136 | break; |
110 | led->behaviour = B43_LED_RADIO_ALL; | 137 | case B43_LED_OFF: |
138 | b43_led_turn_off(dev, led_index, activelow); | ||
111 | break; | 139 | break; |
112 | case 1: | 140 | case B43_LED_ON: |
113 | led->behaviour = B43_LED_RADIO_B; | 141 | b43_led_turn_on(dev, led_index, activelow); |
114 | if (bus->boardinfo.vendor == PCI_VENDOR_ID_ASUSTEK) | ||
115 | led->behaviour = B43_LED_ASSOC; | ||
116 | break; | 142 | break; |
117 | case 2: | 143 | case B43_LED_ACTIVITY: |
118 | led->behaviour = B43_LED_RADIO_A; | 144 | case B43_LED_TRANSFER: |
145 | case B43_LED_APTRANSFER: | ||
146 | snprintf(name, sizeof(name), | ||
147 | "b43-%s:tx", wiphy_name(hw->wiphy)); | ||
148 | b43_register_led(dev, &dev->led_tx, name, | ||
149 | ieee80211_get_tx_led_name(hw), | ||
150 | led_index, activelow); | ||
151 | snprintf(name, sizeof(name), | ||
152 | "b43-%s:rx", wiphy_name(hw->wiphy)); | ||
153 | b43_register_led(dev, &dev->led_rx, name, | ||
154 | ieee80211_get_rx_led_name(hw), | ||
155 | led_index, activelow); | ||
119 | break; | 156 | break; |
120 | case 3: | 157 | /*FIXME: We need another trigger for the "radio-on" LEDs below. |
121 | led->behaviour = B43_LED_OFF; | 158 | * Wiggle that somehow into the rfkill subsystem. */ |
159 | case B43_LED_RADIO_ALL: | ||
160 | case B43_LED_RADIO_A: | ||
161 | case B43_LED_RADIO_B: | ||
162 | case B43_LED_MODE_BG: | ||
163 | case B43_LED_WEIRD: | ||
164 | case B43_LED_ASSOC: | ||
165 | snprintf(name, sizeof(name), | ||
166 | "b43-%s:assoc", wiphy_name(hw->wiphy)); | ||
167 | b43_register_led(dev, &dev->led_assoc, name, | ||
168 | ieee80211_get_assoc_led_name(hw), | ||
169 | led_index, activelow); | ||
122 | break; | 170 | break; |
123 | default: | 171 | default: |
124 | B43_WARN_ON(1); | 172 | b43warn(dev->wl, "LEDs: Unknown behaviour 0x%02X\n", |
173 | behaviour); | ||
174 | break; | ||
125 | } | 175 | } |
126 | } | 176 | } |
127 | 177 | ||
128 | int b43_leds_init(struct b43_wldev *dev) | 178 | void b43_leds_init(struct b43_wldev *dev) |
129 | { | 179 | { |
130 | struct b43_led *led; | 180 | struct ssb_bus *bus = dev->dev->bus; |
131 | u8 sprom[4]; | 181 | u8 sprom[4]; |
132 | int i; | 182 | int i; |
183 | enum b43_led_behaviour behaviour; | ||
184 | bool activelow; | ||
133 | 185 | ||
134 | sprom[0] = dev->dev->bus->sprom.r1.gpio0; | 186 | sprom[0] = bus->sprom.r1.gpio0; |
135 | sprom[1] = dev->dev->bus->sprom.r1.gpio1; | 187 | sprom[1] = bus->sprom.r1.gpio1; |
136 | sprom[2] = dev->dev->bus->sprom.r1.gpio2; | 188 | sprom[2] = bus->sprom.r1.gpio2; |
137 | sprom[3] = dev->dev->bus->sprom.r1.gpio3; | 189 | sprom[3] = bus->sprom.r1.gpio3; |
138 | |||
139 | for (i = 0; i < B43_NR_LEDS; i++) { | ||
140 | led = &(dev->leds[i]); | ||
141 | led->index = i; | ||
142 | led->dev = dev; | ||
143 | setup_timer(&led->blink_timer, | ||
144 | b43_led_blink, (unsigned long)led); | ||
145 | 190 | ||
191 | for (i = 0; i < 4; i++) { | ||
146 | if (sprom[i] == 0xFF) { | 192 | if (sprom[i] == 0xFF) { |
147 | b43_led_init_hardcoded(dev, led, i); | 193 | /* There is no LED information in the SPROM |
194 | * for this LED. Hardcode it here. */ | ||
195 | activelow = 0; | ||
196 | switch (i) { | ||
197 | case 0: | ||
198 | behaviour = B43_LED_ACTIVITY; | ||
199 | activelow = 1; | ||
200 | if (bus->boardinfo.vendor == PCI_VENDOR_ID_COMPAQ) | ||
201 | behaviour = B43_LED_RADIO_ALL; | ||
202 | break; | ||
203 | case 1: | ||
204 | behaviour = B43_LED_RADIO_B; | ||
205 | if (bus->boardinfo.vendor == PCI_VENDOR_ID_ASUSTEK) | ||
206 | behaviour = B43_LED_ASSOC; | ||
207 | break; | ||
208 | case 2: | ||
209 | behaviour = B43_LED_RADIO_A; | ||
210 | break; | ||
211 | case 3: | ||
212 | behaviour = B43_LED_OFF; | ||
213 | break; | ||
214 | default: | ||
215 | B43_WARN_ON(1); | ||
216 | return; | ||
217 | } | ||
148 | } else { | 218 | } else { |
149 | led->behaviour = sprom[i] & B43_LED_BEHAVIOUR; | 219 | behaviour = sprom[i] & B43_LED_BEHAVIOUR; |
150 | led->activelow = !!(sprom[i] & B43_LED_ACTIVELOW); | 220 | activelow = !!(sprom[i] & B43_LED_ACTIVELOW); |
151 | } | 221 | } |
222 | b43_map_led(dev, i, behaviour, activelow); | ||
152 | } | 223 | } |
153 | |||
154 | return 0; | ||
155 | } | 224 | } |
156 | 225 | ||
157 | void b43_leds_exit(struct b43_wldev *dev) | 226 | void b43_leds_exit(struct b43_wldev *dev) |
158 | { | 227 | { |
159 | struct b43_led *led; | 228 | b43_unregister_led(&dev->led_tx); |
160 | int i; | 229 | b43_unregister_led(&dev->led_rx); |
161 | 230 | b43_unregister_led(&dev->led_assoc); | |
162 | for (i = 0; i < B43_NR_LEDS; i++) { | ||
163 | led = &(dev->leds[i]); | ||
164 | b43_led_blink_stop(led, 1); | ||
165 | } | ||
166 | b43_leds_switch_all(dev, 0); | ||
167 | } | ||
168 | |||
169 | void b43_leds_update(struct b43_wldev *dev, int activity) | ||
170 | { | ||
171 | struct b43_led *led; | ||
172 | struct b43_phy *phy = &dev->phy; | ||
173 | const int transferring = | ||
174 | (jiffies - dev->stats.last_tx) < B43_LED_XFER_THRES; | ||
175 | int i, turn_on; | ||
176 | unsigned long interval = 0; | ||
177 | u16 ledctl; | ||
178 | unsigned long flags; | ||
179 | bool radio_enabled = (phy->radio_on && dev->radio_hw_enable); | ||
180 | |||
181 | spin_lock_irqsave(&dev->wl->leds_lock, flags); | ||
182 | ledctl = b43_read16(dev, B43_MMIO_GPIO_CONTROL); | ||
183 | for (i = 0; i < B43_NR_LEDS; i++) { | ||
184 | led = &(dev->leds[i]); | ||
185 | |||
186 | turn_on = 0; | ||
187 | switch (led->behaviour) { | ||
188 | case B43_LED_INACTIVE: | ||
189 | continue; | ||
190 | case B43_LED_OFF: | ||
191 | break; | ||
192 | case B43_LED_ON: | ||
193 | turn_on = 1; | ||
194 | break; | ||
195 | case B43_LED_ACTIVITY: | ||
196 | turn_on = activity; | ||
197 | break; | ||
198 | case B43_LED_RADIO_ALL: | ||
199 | turn_on = radio_enabled; | ||
200 | break; | ||
201 | case B43_LED_RADIO_A: | ||
202 | turn_on = (radio_enabled && phy->type == B43_PHYTYPE_A); | ||
203 | break; | ||
204 | case B43_LED_RADIO_B: | ||
205 | turn_on = (radio_enabled && | ||
206 | (phy->type == B43_PHYTYPE_B | ||
207 | || phy->type == B43_PHYTYPE_G)); | ||
208 | break; | ||
209 | case B43_LED_MODE_BG: | ||
210 | if (phy->type == B43_PHYTYPE_G | ||
211 | && radio_enabled) | ||
212 | turn_on = 1; | ||
213 | break; | ||
214 | case B43_LED_TRANSFER: | ||
215 | if (transferring) | ||
216 | b43_led_blink_start(led, B43_LEDBLINK_MEDIUM); | ||
217 | else | ||
218 | b43_led_blink_stop(led, 0); | ||
219 | continue; | ||
220 | case B43_LED_APTRANSFER: | ||
221 | if (b43_is_mode(dev->wl, IEEE80211_IF_TYPE_AP)) { | ||
222 | if (transferring) { | ||
223 | interval = B43_LEDBLINK_FAST; | ||
224 | turn_on = 1; | ||
225 | } | ||
226 | } else { | ||
227 | turn_on = 1; | ||
228 | if (0 /*TODO: not assoc */ ) | ||
229 | interval = B43_LEDBLINK_SLOW; | ||
230 | else if (transferring) | ||
231 | interval = B43_LEDBLINK_FAST; | ||
232 | else | ||
233 | turn_on = 0; | ||
234 | } | ||
235 | if (turn_on) | ||
236 | b43_led_blink_start(led, interval); | ||
237 | else | ||
238 | b43_led_blink_stop(led, 0); | ||
239 | continue; | ||
240 | case B43_LED_WEIRD: | ||
241 | //TODO | ||
242 | break; | ||
243 | case B43_LED_ASSOC: | ||
244 | if (1 /*dev->softmac->associated */ ) | ||
245 | turn_on = 1; | ||
246 | break; | ||
247 | #ifdef CONFIG_B43_DEBUG | ||
248 | case B43_LED_TEST_BLINKSLOW: | ||
249 | b43_led_blink_start(led, B43_LEDBLINK_SLOW); | ||
250 | continue; | ||
251 | case B43_LED_TEST_BLINKMEDIUM: | ||
252 | b43_led_blink_start(led, B43_LEDBLINK_MEDIUM); | ||
253 | continue; | ||
254 | case B43_LED_TEST_BLINKFAST: | ||
255 | b43_led_blink_start(led, B43_LEDBLINK_FAST); | ||
256 | continue; | ||
257 | #endif /* CONFIG_B43_DEBUG */ | ||
258 | default: | ||
259 | B43_WARN_ON(1); | ||
260 | }; | ||
261 | |||
262 | if (led->activelow) | ||
263 | turn_on = !turn_on; | ||
264 | if (turn_on) | ||
265 | ledctl |= (1 << i); | ||
266 | else | ||
267 | ledctl &= ~(1 << i); | ||
268 | } | ||
269 | b43_write16(dev, B43_MMIO_GPIO_CONTROL, ledctl); | ||
270 | spin_unlock_irqrestore(&dev->wl->leds_lock, flags); | ||
271 | } | ||
272 | |||
273 | void b43_leds_switch_all(struct b43_wldev *dev, int on) | ||
274 | { | ||
275 | struct b43_led *led; | ||
276 | u16 ledctl; | ||
277 | int i; | ||
278 | int bit_on; | ||
279 | unsigned long flags; | ||
280 | |||
281 | spin_lock_irqsave(&dev->wl->leds_lock, flags); | ||
282 | ledctl = b43_read16(dev, B43_MMIO_GPIO_CONTROL); | ||
283 | for (i = 0; i < B43_NR_LEDS; i++) { | ||
284 | led = &(dev->leds[i]); | ||
285 | if (led->behaviour == B43_LED_INACTIVE) | ||
286 | continue; | ||
287 | if (on) | ||
288 | bit_on = led->activelow ? 0 : 1; | ||
289 | else | ||
290 | bit_on = led->activelow ? 1 : 0; | ||
291 | if (bit_on) | ||
292 | ledctl |= (1 << i); | ||
293 | else | ||
294 | ledctl &= ~(1 << i); | ||
295 | } | ||
296 | b43_write16(dev, B43_MMIO_GPIO_CONTROL, ledctl); | ||
297 | spin_unlock_irqrestore(&dev->wl->leds_lock, flags); | ||
298 | } | 231 | } |