3 Broadcom B43 wireless driver
6 Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>,
7 Copyright (c) 2005 Stefano Brivio <stefano.brivio@polimi.it>
8 Copyright (c) 2005-2007 Michael Buesch <mb@bu3sch.de>
9 Copyright (c) 2005 Danny van Dyk <kugelfang@gentoo.org>
10 Copyright (c) 2005 Andreas Jaggi <andreas.jaggi@waterwave.ch>
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program; see the file COPYING. If not, write to
24 the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
25 Boston, MA 02110-1301, USA.
34 static void b43_led_turn_on(struct b43_wldev *dev, u8 led_index,
39 ctl = b43_read16(dev, B43_MMIO_GPIO_CONTROL);
41 ctl &= ~(1 << led_index);
43 ctl |= (1 << led_index);
44 b43_write16(dev, B43_MMIO_GPIO_CONTROL, ctl);
47 static void b43_led_turn_off(struct b43_wldev *dev, u8 led_index,
52 ctl = b43_read16(dev, B43_MMIO_GPIO_CONTROL);
54 ctl |= (1 << led_index);
56 ctl &= ~(1 << led_index);
57 b43_write16(dev, B43_MMIO_GPIO_CONTROL, ctl);
60 static void b43_led_update(struct b43_wldev *dev,
69 radio_enabled = (dev->phy.radio_on && dev->radio_hw_enable);
71 /* The led->state read is racy, but we don't care. In case we raced
72 * with the brightness_set handler, we will be called again soon
73 * to fixup our state. */
75 turn_on = atomic_read(&led->state) != LED_OFF;
78 if (turn_on == led->hw_state)
80 led->hw_state = turn_on;
83 b43_led_turn_on(dev, led->index, led->activelow);
85 b43_led_turn_off(dev, led->index, led->activelow);
88 static void b43_leds_work(struct work_struct *work)
90 struct b43_leds *leds = container_of(work, struct b43_leds, work);
91 struct b43_wl *wl = container_of(leds, struct b43_wl, leds);
92 struct b43_wldev *dev;
94 mutex_lock(&wl->mutex);
95 dev = wl->current_dev;
96 if (unlikely(!dev || b43_status(dev) < B43_STAT_STARTED))
99 b43_led_update(dev, &wl->leds.led_tx);
100 b43_led_update(dev, &wl->leds.led_rx);
101 b43_led_update(dev, &wl->leds.led_radio);
102 b43_led_update(dev, &wl->leds.led_assoc);
105 mutex_unlock(&wl->mutex);
108 /* Callback from the LED subsystem. */
109 static void b43_led_brightness_set(struct led_classdev *led_dev,
110 enum led_brightness brightness)
112 struct b43_led *led = container_of(led_dev, struct b43_led, led_dev);
113 struct b43_wl *wl = led->wl;
115 /* The check for current_dev is only needed while unregistering,
116 * so it is sequencial and does not race. But we must not dereference
117 * current_dev here. */
118 if (likely(wl->current_dev)) {
119 atomic_set(&led->state, brightness);
120 ieee80211_queue_work(wl->hw, &wl->leds.work);
124 static int b43_register_led(struct b43_wldev *dev, struct b43_led *led,
125 const char *name, const char *default_trigger,
126 u8 led_index, bool activelow)
132 if (!default_trigger)
135 led->index = led_index;
136 led->activelow = activelow;
137 strncpy(led->name, name, sizeof(led->name));
138 atomic_set(&led->state, 0);
140 led->led_dev.name = led->name;
141 led->led_dev.default_trigger = default_trigger;
142 led->led_dev.brightness_set = b43_led_brightness_set;
144 err = led_classdev_register(dev->dev->dev, &led->led_dev);
146 b43warn(dev->wl, "LEDs: Failed to register %s\n", name);
154 static void b43_unregister_led(struct b43_led *led)
158 led_classdev_unregister(&led->led_dev);
162 static void b43_map_led(struct b43_wldev *dev,
164 enum b43_led_behaviour behaviour,
167 struct ieee80211_hw *hw = dev->wl->hw;
168 char name[B43_LED_MAX_NAME_LEN + 1];
170 /* Map the b43 specific LED behaviour value to the
171 * generic LED triggers. */
173 case B43_LED_INACTIVE:
177 case B43_LED_ACTIVITY:
178 case B43_LED_TRANSFER:
179 case B43_LED_APTRANSFER:
180 snprintf(name, sizeof(name),
181 "b43-%s::tx", wiphy_name(hw->wiphy));
182 b43_register_led(dev, &dev->wl->leds.led_tx, name,
183 ieee80211_get_tx_led_name(hw),
184 led_index, activelow);
185 snprintf(name, sizeof(name),
186 "b43-%s::rx", wiphy_name(hw->wiphy));
187 b43_register_led(dev, &dev->wl->leds.led_rx, name,
188 ieee80211_get_rx_led_name(hw),
189 led_index, activelow);
191 case B43_LED_RADIO_ALL:
192 case B43_LED_RADIO_A:
193 case B43_LED_RADIO_B:
194 case B43_LED_MODE_BG:
195 snprintf(name, sizeof(name),
196 "b43-%s::radio", wiphy_name(hw->wiphy));
197 b43_register_led(dev, &dev->wl->leds.led_radio, name,
198 ieee80211_get_radio_led_name(hw),
199 led_index, activelow);
203 snprintf(name, sizeof(name),
204 "b43-%s::assoc", wiphy_name(hw->wiphy));
205 b43_register_led(dev, &dev->wl->leds.led_assoc, name,
206 ieee80211_get_assoc_led_name(hw),
207 led_index, activelow);
210 b43warn(dev->wl, "LEDs: Unknown behaviour 0x%02X\n",
216 static void b43_led_get_sprominfo(struct b43_wldev *dev,
217 unsigned int led_index,
218 enum b43_led_behaviour *behaviour,
221 struct ssb_bus *bus = dev->dev->bus;
224 sprom[0] = bus->sprom.gpio0;
225 sprom[1] = bus->sprom.gpio1;
226 sprom[2] = bus->sprom.gpio2;
227 sprom[3] = bus->sprom.gpio3;
229 if (sprom[led_index] == 0xFF) {
230 /* There is no LED information in the SPROM
231 * for this LED. Hardcode it here. */
235 *behaviour = B43_LED_ACTIVITY;
237 if (bus->boardinfo.vendor == PCI_VENDOR_ID_COMPAQ)
238 *behaviour = B43_LED_RADIO_ALL;
241 *behaviour = B43_LED_RADIO_B;
242 if (bus->boardinfo.vendor == PCI_VENDOR_ID_ASUSTEK)
243 *behaviour = B43_LED_ASSOC;
246 *behaviour = B43_LED_RADIO_A;
249 *behaviour = B43_LED_OFF;
256 *behaviour = sprom[led_index] & B43_LED_BEHAVIOUR;
257 *activelow = !!(sprom[led_index] & B43_LED_ACTIVELOW);
261 void b43_leds_init(struct b43_wldev *dev)
265 enum b43_led_behaviour behaviour;
268 /* Sync the RF-kill LED state (if we have one) with radio and switch states. */
269 led = &dev->wl->leds.led_radio;
271 if (dev->phy.radio_on && b43_is_hw_radio_enabled(dev)) {
272 b43_led_turn_on(dev, led->index, led->activelow);
274 atomic_set(&led->state, 1);
276 b43_led_turn_off(dev, led->index, led->activelow);
278 atomic_set(&led->state, 0);
282 /* Initialize TX/RX/ASSOC leds */
283 led = &dev->wl->leds.led_tx;
285 b43_led_turn_off(dev, led->index, led->activelow);
287 atomic_set(&led->state, 0);
289 led = &dev->wl->leds.led_rx;
291 b43_led_turn_off(dev, led->index, led->activelow);
293 atomic_set(&led->state, 0);
295 led = &dev->wl->leds.led_assoc;
297 b43_led_turn_off(dev, led->index, led->activelow);
299 atomic_set(&led->state, 0);
302 /* Initialize other LED states. */
303 for (i = 0; i < B43_MAX_NR_LEDS; i++) {
304 b43_led_get_sprominfo(dev, i, &behaviour, &activelow);
307 b43_led_turn_off(dev, i, activelow);
310 b43_led_turn_on(dev, i, activelow);
313 /* Leave others as-is. */
319 void b43_leds_exit(struct b43_wldev *dev)
321 struct b43_leds *leds = &dev->wl->leds;
323 b43_led_turn_off(dev, leds->led_tx.index, leds->led_tx.activelow);
324 b43_led_turn_off(dev, leds->led_rx.index, leds->led_rx.activelow);
325 b43_led_turn_off(dev, leds->led_assoc.index, leds->led_assoc.activelow);
326 b43_led_turn_off(dev, leds->led_radio.index, leds->led_radio.activelow);
329 void b43_leds_register(struct b43_wldev *dev)
332 enum b43_led_behaviour behaviour;
335 INIT_WORK(&dev->wl->leds.work, b43_leds_work);
337 /* Register the LEDs to the LED subsystem. */
338 for (i = 0; i < B43_MAX_NR_LEDS; i++) {
339 b43_led_get_sprominfo(dev, i, &behaviour, &activelow);
340 b43_map_led(dev, i, behaviour, activelow);
344 void b43_leds_unregister(struct b43_wldev *dev)
346 struct b43_leds *leds = &dev->wl->leds;
348 b43_unregister_led(&leds->led_tx);
349 b43_unregister_led(&leds->led_rx);
350 b43_unregister_led(&leds->led_assoc);
351 b43_unregister_led(&leds->led_radio);