2007-09-26 07:46:54 +08:00
|
|
|
/*
|
|
|
|
|
2007-10-13 12:04:51 +08:00
|
|
|
Broadcom B43 wireless driver
|
|
|
|
LED control
|
2007-09-26 07:46:54 +08:00
|
|
|
|
|
|
|
Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>,
|
2007-11-07 05:49:20 +08:00
|
|
|
Copyright (c) 2005 Stefano Brivio <stefano.brivio@polimi.it>
|
2007-10-13 12:04:51 +08:00
|
|
|
Copyright (c) 2005-2007 Michael Buesch <mb@bu3sch.de>
|
|
|
|
Copyright (c) 2005 Danny van Dyk <kugelfang@gentoo.org>
|
|
|
|
Copyright (c) 2005 Andreas Jaggi <andreas.jaggi@waterwave.ch>
|
2007-09-26 07:46:54 +08:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; see the file COPYING. If not, write to
|
|
|
|
the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
|
|
|
|
Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "b43legacy.h"
|
2007-10-13 12:04:51 +08:00
|
|
|
#include "leds.h"
|
2007-09-26 07:46:54 +08:00
|
|
|
|
|
|
|
|
2007-10-13 12:04:51 +08:00
|
|
|
static void b43legacy_led_turn_on(struct b43legacy_wldev *dev, u8 led_index,
|
|
|
|
bool activelow)
|
2007-09-26 07:46:54 +08:00
|
|
|
{
|
2007-10-13 12:04:51 +08:00
|
|
|
struct b43legacy_wl *wl = dev->wl;
|
2007-09-26 07:46:54 +08:00
|
|
|
unsigned long flags;
|
2007-10-13 12:04:51 +08:00
|
|
|
u16 ctl;
|
2007-09-26 07:46:54 +08:00
|
|
|
|
2007-10-13 12:04:51 +08:00
|
|
|
spin_lock_irqsave(&wl->leds_lock, flags);
|
|
|
|
ctl = b43legacy_read16(dev, B43legacy_MMIO_GPIO_CONTROL);
|
|
|
|
if (activelow)
|
|
|
|
ctl &= ~(1 << led_index);
|
|
|
|
else
|
|
|
|
ctl |= (1 << led_index);
|
|
|
|
b43legacy_write16(dev, B43legacy_MMIO_GPIO_CONTROL, ctl);
|
|
|
|
spin_unlock_irqrestore(&wl->leds_lock, flags);
|
2007-09-26 07:46:54 +08:00
|
|
|
}
|
|
|
|
|
2007-10-13 12:04:51 +08:00
|
|
|
static void b43legacy_led_turn_off(struct b43legacy_wldev *dev, u8 led_index,
|
|
|
|
bool activelow)
|
2007-09-26 07:46:54 +08:00
|
|
|
{
|
2007-10-13 12:04:51 +08:00
|
|
|
struct b43legacy_wl *wl = dev->wl;
|
|
|
|
unsigned long flags;
|
|
|
|
u16 ctl;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&wl->leds_lock, flags);
|
|
|
|
ctl = b43legacy_read16(dev, B43legacy_MMIO_GPIO_CONTROL);
|
|
|
|
if (activelow)
|
|
|
|
ctl |= (1 << led_index);
|
|
|
|
else
|
|
|
|
ctl &= ~(1 << led_index);
|
|
|
|
b43legacy_write16(dev, B43legacy_MMIO_GPIO_CONTROL, ctl);
|
|
|
|
spin_unlock_irqrestore(&wl->leds_lock, flags);
|
2007-09-26 07:46:54 +08:00
|
|
|
}
|
|
|
|
|
2007-10-13 12:04:51 +08:00
|
|
|
/* Callback from the LED subsystem. */
|
|
|
|
static void b43legacy_led_brightness_set(struct led_classdev *led_dev,
|
|
|
|
enum led_brightness brightness)
|
2007-09-26 07:46:54 +08:00
|
|
|
{
|
2007-10-13 12:04:51 +08:00
|
|
|
struct b43legacy_led *led = container_of(led_dev, struct b43legacy_led,
|
|
|
|
led_dev);
|
2007-09-26 07:46:54 +08:00
|
|
|
struct b43legacy_wldev *dev = led->dev;
|
2007-10-13 12:04:51 +08:00
|
|
|
bool radio_enabled;
|
2007-09-26 07:46:54 +08:00
|
|
|
|
2007-10-13 12:04:51 +08:00
|
|
|
/* Checking the radio-enabled status here is slightly racy,
|
|
|
|
* but we want to avoid the locking overhead and we don't care
|
|
|
|
* whether the LED has the wrong state for a second. */
|
|
|
|
radio_enabled = (dev->phy.radio_on && dev->radio_hw_enable);
|
2007-09-26 07:46:54 +08:00
|
|
|
|
2007-10-13 12:04:51 +08:00
|
|
|
if (brightness == LED_OFF || !radio_enabled)
|
|
|
|
b43legacy_led_turn_off(dev, led->index, led->activelow);
|
2007-09-26 07:46:54 +08:00
|
|
|
else
|
2007-10-13 12:04:51 +08:00
|
|
|
b43legacy_led_turn_on(dev, led->index, led->activelow);
|
2007-09-26 07:46:54 +08:00
|
|
|
}
|
|
|
|
|
2007-10-13 12:04:51 +08:00
|
|
|
static int b43legacy_register_led(struct b43legacy_wldev *dev,
|
|
|
|
struct b43legacy_led *led,
|
|
|
|
const char *name, char *default_trigger,
|
|
|
|
u8 led_index, bool activelow)
|
2007-09-26 07:46:54 +08:00
|
|
|
{
|
2007-10-13 12:04:51 +08:00
|
|
|
int err;
|
|
|
|
|
|
|
|
b43legacy_led_turn_off(dev, led_index, activelow);
|
|
|
|
if (led->dev)
|
|
|
|
return -EEXIST;
|
|
|
|
if (!default_trigger)
|
|
|
|
return -EINVAL;
|
|
|
|
led->dev = dev;
|
|
|
|
led->index = led_index;
|
|
|
|
led->activelow = activelow;
|
|
|
|
strncpy(led->name, name, sizeof(led->name));
|
|
|
|
|
|
|
|
led->led_dev.name = led->name;
|
|
|
|
led->led_dev.default_trigger = default_trigger;
|
|
|
|
led->led_dev.brightness_set = b43legacy_led_brightness_set;
|
|
|
|
|
|
|
|
err = led_classdev_register(dev->dev->dev, &led->led_dev);
|
|
|
|
if (err) {
|
|
|
|
b43legacywarn(dev->wl, "LEDs: Failed to register %s\n", name);
|
|
|
|
led->dev = NULL;
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2007-09-26 07:46:54 +08:00
|
|
|
|
2007-10-13 12:04:51 +08:00
|
|
|
static void b43legacy_unregister_led(struct b43legacy_led *led)
|
|
|
|
{
|
|
|
|
if (!led->dev)
|
|
|
|
return;
|
|
|
|
led_classdev_unregister(&led->led_dev);
|
|
|
|
b43legacy_led_turn_off(led->dev, led->index, led->activelow);
|
|
|
|
led->dev = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void b43legacy_map_led(struct b43legacy_wldev *dev,
|
|
|
|
u8 led_index,
|
|
|
|
enum b43legacy_led_behaviour behaviour,
|
|
|
|
bool activelow)
|
|
|
|
{
|
|
|
|
struct ieee80211_hw *hw = dev->wl->hw;
|
|
|
|
char name[B43legacy_LED_MAX_NAME_LEN + 1];
|
2007-09-26 07:46:54 +08:00
|
|
|
|
2007-10-13 12:04:51 +08:00
|
|
|
/* Map the b43 specific LED behaviour value to the
|
|
|
|
* generic LED triggers. */
|
|
|
|
switch (behaviour) {
|
|
|
|
case B43legacy_LED_INACTIVE:
|
2007-09-26 07:46:54 +08:00
|
|
|
break;
|
2007-10-13 12:04:51 +08:00
|
|
|
case B43legacy_LED_OFF:
|
|
|
|
b43legacy_led_turn_off(dev, led_index, activelow);
|
2007-09-26 07:46:54 +08:00
|
|
|
break;
|
2007-10-13 12:04:51 +08:00
|
|
|
case B43legacy_LED_ON:
|
|
|
|
b43legacy_led_turn_on(dev, led_index, activelow);
|
2007-09-26 07:46:54 +08:00
|
|
|
break;
|
2007-10-13 12:04:51 +08:00
|
|
|
case B43legacy_LED_ACTIVITY:
|
|
|
|
case B43legacy_LED_TRANSFER:
|
|
|
|
case B43legacy_LED_APTRANSFER:
|
|
|
|
snprintf(name, sizeof(name),
|
2009-01-31 22:52:16 +08:00
|
|
|
"b43legacy-%s::tx", wiphy_name(hw->wiphy));
|
2007-10-13 12:04:51 +08:00
|
|
|
b43legacy_register_led(dev, &dev->led_tx, name,
|
|
|
|
ieee80211_get_tx_led_name(hw),
|
|
|
|
led_index, activelow);
|
|
|
|
snprintf(name, sizeof(name),
|
2009-01-31 22:52:16 +08:00
|
|
|
"b43legacy-%s::rx", wiphy_name(hw->wiphy));
|
2007-10-13 12:04:51 +08:00
|
|
|
b43legacy_register_led(dev, &dev->led_rx, name,
|
|
|
|
ieee80211_get_rx_led_name(hw),
|
|
|
|
led_index, activelow);
|
|
|
|
break;
|
|
|
|
case B43legacy_LED_RADIO_ALL:
|
|
|
|
case B43legacy_LED_RADIO_A:
|
|
|
|
case B43legacy_LED_RADIO_B:
|
|
|
|
case B43legacy_LED_MODE_BG:
|
2007-10-11 11:44:22 +08:00
|
|
|
snprintf(name, sizeof(name),
|
2009-01-31 22:52:16 +08:00
|
|
|
"b43legacy-%s::radio", wiphy_name(hw->wiphy));
|
2007-10-11 11:44:22 +08:00
|
|
|
b43legacy_register_led(dev, &dev->led_radio, name,
|
|
|
|
b43legacy_rfkill_led_name(dev),
|
|
|
|
led_index, activelow);
|
2007-12-17 02:21:06 +08:00
|
|
|
/* Sync the RF-kill LED state with the switch state. */
|
|
|
|
if (dev->radio_hw_enable)
|
|
|
|
b43legacy_led_turn_on(dev, led_index, activelow);
|
2007-10-11 11:44:22 +08:00
|
|
|
break;
|
2007-10-13 12:04:51 +08:00
|
|
|
case B43legacy_LED_WEIRD:
|
|
|
|
case B43legacy_LED_ASSOC:
|
|
|
|
snprintf(name, sizeof(name),
|
2009-01-31 22:52:16 +08:00
|
|
|
"b43legacy-%s::assoc", wiphy_name(hw->wiphy));
|
2007-10-13 12:04:51 +08:00
|
|
|
b43legacy_register_led(dev, &dev->led_assoc, name,
|
|
|
|
ieee80211_get_assoc_led_name(hw),
|
|
|
|
led_index, activelow);
|
2007-09-26 07:46:54 +08:00
|
|
|
break;
|
|
|
|
default:
|
2007-10-13 12:04:51 +08:00
|
|
|
b43legacywarn(dev->wl, "LEDs: Unknown behaviour 0x%02X\n",
|
|
|
|
behaviour);
|
|
|
|
break;
|
2007-09-26 07:46:54 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-13 12:04:51 +08:00
|
|
|
void b43legacy_leds_init(struct b43legacy_wldev *dev)
|
2007-09-26 07:46:54 +08:00
|
|
|
{
|
2007-10-13 12:04:51 +08:00
|
|
|
struct ssb_bus *bus = dev->dev->bus;
|
2007-09-26 07:46:54 +08:00
|
|
|
u8 sprom[4];
|
|
|
|
int i;
|
2007-10-13 12:04:51 +08:00
|
|
|
enum b43legacy_led_behaviour behaviour;
|
|
|
|
bool activelow;
|
|
|
|
|
2007-11-10 06:57:34 +08:00
|
|
|
sprom[0] = bus->sprom.gpio0;
|
|
|
|
sprom[1] = bus->sprom.gpio1;
|
|
|
|
sprom[2] = bus->sprom.gpio2;
|
|
|
|
sprom[3] = bus->sprom.gpio3;
|
2007-10-13 12:04:51 +08:00
|
|
|
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
if (sprom[i] == 0xFF) {
|
|
|
|
/* There is no LED information in the SPROM
|
|
|
|
* for this LED. Hardcode it here. */
|
|
|
|
activelow = 0;
|
|
|
|
switch (i) {
|
|
|
|
case 0:
|
|
|
|
behaviour = B43legacy_LED_ACTIVITY;
|
|
|
|
activelow = 1;
|
|
|
|
if (bus->boardinfo.vendor == PCI_VENDOR_ID_COMPAQ)
|
|
|
|
behaviour = B43legacy_LED_RADIO_ALL;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
behaviour = B43legacy_LED_RADIO_B;
|
|
|
|
if (bus->boardinfo.vendor == PCI_VENDOR_ID_ASUSTEK)
|
|
|
|
behaviour = B43legacy_LED_ASSOC;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
behaviour = B43legacy_LED_RADIO_A;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
behaviour = B43legacy_LED_OFF;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
B43legacy_WARN_ON(1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
behaviour = sprom[i] & B43legacy_LED_BEHAVIOUR;
|
|
|
|
activelow = !!(sprom[i] & B43legacy_LED_ACTIVELOW);
|
2007-09-26 07:46:54 +08:00
|
|
|
}
|
2007-10-13 12:04:51 +08:00
|
|
|
b43legacy_map_led(dev, i, behaviour, activelow);
|
2007-09-26 07:46:54 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void b43legacy_leds_exit(struct b43legacy_wldev *dev)
|
|
|
|
{
|
2007-10-13 12:04:51 +08:00
|
|
|
b43legacy_unregister_led(&dev->led_tx);
|
|
|
|
b43legacy_unregister_led(&dev->led_rx);
|
|
|
|
b43legacy_unregister_led(&dev->led_assoc);
|
2007-12-17 02:21:06 +08:00
|
|
|
b43legacy_unregister_led(&dev->led_radio);
|
2007-09-26 07:46:54 +08:00
|
|
|
}
|