Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 1 | /* |
| 2 | |
| 3 | Broadcom B43 wireless driver |
Michael Buesch | 21954c3 | 2007-09-27 15:31:40 +0200 | [diff] [blame] | 4 | LED control |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 5 | |
| 6 | Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>, |
Stefano Brivio | 1f21ad2 | 2007-11-06 22:49:20 +0100 | [diff] [blame] | 7 | Copyright (c) 2005 Stefano Brivio <stefano.brivio@polimi.it> |
Michael Buesch | 21954c3 | 2007-09-27 15:31:40 +0200 | [diff] [blame] | 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> |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 11 | |
| 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. |
| 16 | |
| 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. |
| 21 | |
| 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. |
| 26 | |
| 27 | */ |
| 28 | |
| 29 | #include "b43.h" |
| 30 | #include "leds.h" |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 31 | |
Michael Buesch | 21954c3 | 2007-09-27 15:31:40 +0200 | [diff] [blame] | 32 | |
| 33 | static void b43_led_turn_on(struct b43_wldev *dev, u8 led_index, |
| 34 | bool activelow) |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 35 | { |
Michael Buesch | 21954c3 | 2007-09-27 15:31:40 +0200 | [diff] [blame] | 36 | struct b43_wl *wl = dev->wl; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 37 | unsigned long flags; |
Michael Buesch | 21954c3 | 2007-09-27 15:31:40 +0200 | [diff] [blame] | 38 | u16 ctl; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 39 | |
Michael Buesch | 21954c3 | 2007-09-27 15:31:40 +0200 | [diff] [blame] | 40 | spin_lock_irqsave(&wl->leds_lock, flags); |
| 41 | ctl = b43_read16(dev, B43_MMIO_GPIO_CONTROL); |
| 42 | if (activelow) |
| 43 | ctl &= ~(1 << led_index); |
| 44 | else |
| 45 | ctl |= (1 << led_index); |
| 46 | b43_write16(dev, B43_MMIO_GPIO_CONTROL, ctl); |
| 47 | spin_unlock_irqrestore(&wl->leds_lock, flags); |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 48 | } |
| 49 | |
Michael Buesch | 21954c3 | 2007-09-27 15:31:40 +0200 | [diff] [blame] | 50 | static void b43_led_turn_off(struct b43_wldev *dev, u8 led_index, |
| 51 | bool activelow) |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 52 | { |
Michael Buesch | 21954c3 | 2007-09-27 15:31:40 +0200 | [diff] [blame] | 53 | struct b43_wl *wl = dev->wl; |
| 54 | unsigned long flags; |
| 55 | u16 ctl; |
| 56 | |
| 57 | spin_lock_irqsave(&wl->leds_lock, flags); |
| 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); |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 65 | } |
| 66 | |
Michael Buesch | 21954c3 | 2007-09-27 15:31:40 +0200 | [diff] [blame] | 67 | /* Callback from the LED subsystem. */ |
| 68 | static void b43_led_brightness_set(struct led_classdev *led_dev, |
| 69 | enum led_brightness brightness) |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 70 | { |
Michael Buesch | 21954c3 | 2007-09-27 15:31:40 +0200 | [diff] [blame] | 71 | struct b43_led *led = container_of(led_dev, struct b43_led, led_dev); |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 72 | struct b43_wldev *dev = led->dev; |
Michael Buesch | 21954c3 | 2007-09-27 15:31:40 +0200 | [diff] [blame] | 73 | bool radio_enabled; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 74 | |
Michael Buesch | 21954c3 | 2007-09-27 15:31:40 +0200 | [diff] [blame] | 75 | /* Checking the radio-enabled status here is slightly racy, |
| 76 | * but we want to avoid the locking overhead and we don't care |
| 77 | * whether the LED has the wrong state for a second. */ |
| 78 | radio_enabled = (dev->phy.radio_on && dev->radio_hw_enable); |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 79 | |
Michael Buesch | 21954c3 | 2007-09-27 15:31:40 +0200 | [diff] [blame] | 80 | if (brightness == LED_OFF || !radio_enabled) |
| 81 | b43_led_turn_off(dev, led->index, led->activelow); |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 82 | else |
Michael Buesch | 21954c3 | 2007-09-27 15:31:40 +0200 | [diff] [blame] | 83 | b43_led_turn_on(dev, led->index, led->activelow); |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 84 | } |
| 85 | |
Michael Buesch | 21954c3 | 2007-09-27 15:31:40 +0200 | [diff] [blame] | 86 | static int b43_register_led(struct b43_wldev *dev, struct b43_led *led, |
| 87 | const char *name, char *default_trigger, |
| 88 | u8 led_index, bool activelow) |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 89 | { |
Michael Buesch | 21954c3 | 2007-09-27 15:31:40 +0200 | [diff] [blame] | 90 | int err; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 91 | |
Michael Buesch | 21954c3 | 2007-09-27 15:31:40 +0200 | [diff] [blame] | 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)); |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 101 | |
Michael Buesch | 21954c3 | 2007-09-27 15:31:40 +0200 | [diff] [blame] | 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; |
Rafael J. Wysocki | 3506e0c | 2008-02-04 22:30:15 -0800 | [diff] [blame] | 119 | if (led->dev->suspend_in_progress) |
| 120 | led_classdev_unregister_suspended(&led->led_dev); |
| 121 | else |
| 122 | led_classdev_unregister(&led->led_dev); |
Michael Buesch | 21954c3 | 2007-09-27 15:31:40 +0200 | [diff] [blame] | 123 | b43_led_turn_off(led->dev, led->index, led->activelow); |
| 124 | led->dev = NULL; |
| 125 | } |
| 126 | |
| 127 | static void b43_map_led(struct b43_wldev *dev, |
| 128 | u8 led_index, |
| 129 | enum b43_led_behaviour behaviour, |
| 130 | bool activelow) |
| 131 | { |
| 132 | struct ieee80211_hw *hw = dev->wl->hw; |
| 133 | char name[B43_LED_MAX_NAME_LEN + 1]; |
| 134 | |
| 135 | /* Map the b43 specific LED behaviour value to the |
| 136 | * generic LED triggers. */ |
| 137 | switch (behaviour) { |
| 138 | case B43_LED_INACTIVE: |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 139 | break; |
Michael Buesch | 21954c3 | 2007-09-27 15:31:40 +0200 | [diff] [blame] | 140 | case B43_LED_OFF: |
| 141 | b43_led_turn_off(dev, led_index, activelow); |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 142 | break; |
Michael Buesch | 21954c3 | 2007-09-27 15:31:40 +0200 | [diff] [blame] | 143 | case B43_LED_ON: |
| 144 | b43_led_turn_on(dev, led_index, activelow); |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 145 | break; |
Michael Buesch | 21954c3 | 2007-09-27 15:31:40 +0200 | [diff] [blame] | 146 | case B43_LED_ACTIVITY: |
| 147 | case B43_LED_TRANSFER: |
| 148 | case B43_LED_APTRANSFER: |
| 149 | snprintf(name, sizeof(name), |
Richard Purdie | 6c152be | 2007-10-31 15:00:07 +0100 | [diff] [blame^] | 150 | "b43-%s::tx", wiphy_name(hw->wiphy)); |
Michael Buesch | 21954c3 | 2007-09-27 15:31:40 +0200 | [diff] [blame] | 151 | b43_register_led(dev, &dev->led_tx, name, |
| 152 | ieee80211_get_tx_led_name(hw), |
| 153 | led_index, activelow); |
| 154 | snprintf(name, sizeof(name), |
Richard Purdie | 6c152be | 2007-10-31 15:00:07 +0100 | [diff] [blame^] | 155 | "b43-%s::rx", wiphy_name(hw->wiphy)); |
Michael Buesch | 21954c3 | 2007-09-27 15:31:40 +0200 | [diff] [blame] | 156 | b43_register_led(dev, &dev->led_rx, name, |
| 157 | ieee80211_get_rx_led_name(hw), |
| 158 | led_index, activelow); |
| 159 | break; |
Michael Buesch | 21954c3 | 2007-09-27 15:31:40 +0200 | [diff] [blame] | 160 | case B43_LED_RADIO_ALL: |
| 161 | case B43_LED_RADIO_A: |
| 162 | case B43_LED_RADIO_B: |
| 163 | case B43_LED_MODE_BG: |
Michael Buesch | 8e9f752 | 2007-09-27 21:35:34 +0200 | [diff] [blame] | 164 | snprintf(name, sizeof(name), |
Richard Purdie | 6c152be | 2007-10-31 15:00:07 +0100 | [diff] [blame^] | 165 | "b43-%s::radio", wiphy_name(hw->wiphy)); |
Michael Buesch | 8e9f752 | 2007-09-27 21:35:34 +0200 | [diff] [blame] | 166 | b43_register_led(dev, &dev->led_radio, name, |
| 167 | b43_rfkill_led_name(dev), |
| 168 | led_index, activelow); |
Larry Finger | 1a8d1227 | 2007-12-14 13:59:11 +0100 | [diff] [blame] | 169 | /* Sync the RF-kill LED state with the switch state. */ |
| 170 | if (dev->radio_hw_enable) |
| 171 | b43_led_turn_on(dev, led_index, activelow); |
Michael Buesch | 8e9f752 | 2007-09-27 21:35:34 +0200 | [diff] [blame] | 172 | break; |
Michael Buesch | 21954c3 | 2007-09-27 15:31:40 +0200 | [diff] [blame] | 173 | case B43_LED_WEIRD: |
| 174 | case B43_LED_ASSOC: |
| 175 | snprintf(name, sizeof(name), |
Richard Purdie | 6c152be | 2007-10-31 15:00:07 +0100 | [diff] [blame^] | 176 | "b43-%s::assoc", wiphy_name(hw->wiphy)); |
Michael Buesch | 21954c3 | 2007-09-27 15:31:40 +0200 | [diff] [blame] | 177 | b43_register_led(dev, &dev->led_assoc, name, |
| 178 | ieee80211_get_assoc_led_name(hw), |
| 179 | led_index, activelow); |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 180 | break; |
| 181 | default: |
Michael Buesch | 21954c3 | 2007-09-27 15:31:40 +0200 | [diff] [blame] | 182 | b43warn(dev->wl, "LEDs: Unknown behaviour 0x%02X\n", |
| 183 | behaviour); |
| 184 | break; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 185 | } |
| 186 | } |
| 187 | |
Michael Buesch | 21954c3 | 2007-09-27 15:31:40 +0200 | [diff] [blame] | 188 | void b43_leds_init(struct b43_wldev *dev) |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 189 | { |
Michael Buesch | 21954c3 | 2007-09-27 15:31:40 +0200 | [diff] [blame] | 190 | struct ssb_bus *bus = dev->dev->bus; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 191 | u8 sprom[4]; |
| 192 | int i; |
Michael Buesch | 21954c3 | 2007-09-27 15:31:40 +0200 | [diff] [blame] | 193 | enum b43_led_behaviour behaviour; |
| 194 | bool activelow; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 195 | |
Larry Finger | 95de284 | 2007-11-09 16:57:18 -0600 | [diff] [blame] | 196 | sprom[0] = bus->sprom.gpio0; |
| 197 | sprom[1] = bus->sprom.gpio1; |
| 198 | sprom[2] = bus->sprom.gpio2; |
| 199 | sprom[3] = bus->sprom.gpio3; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 200 | |
Michael Buesch | 21954c3 | 2007-09-27 15:31:40 +0200 | [diff] [blame] | 201 | for (i = 0; i < 4; i++) { |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 202 | if (sprom[i] == 0xFF) { |
Michael Buesch | 21954c3 | 2007-09-27 15:31:40 +0200 | [diff] [blame] | 203 | /* There is no LED information in the SPROM |
| 204 | * for this LED. Hardcode it here. */ |
| 205 | activelow = 0; |
| 206 | switch (i) { |
| 207 | case 0: |
| 208 | behaviour = B43_LED_ACTIVITY; |
| 209 | activelow = 1; |
| 210 | if (bus->boardinfo.vendor == PCI_VENDOR_ID_COMPAQ) |
| 211 | behaviour = B43_LED_RADIO_ALL; |
| 212 | break; |
| 213 | case 1: |
| 214 | behaviour = B43_LED_RADIO_B; |
| 215 | if (bus->boardinfo.vendor == PCI_VENDOR_ID_ASUSTEK) |
| 216 | behaviour = B43_LED_ASSOC; |
| 217 | break; |
| 218 | case 2: |
| 219 | behaviour = B43_LED_RADIO_A; |
| 220 | break; |
| 221 | case 3: |
| 222 | behaviour = B43_LED_OFF; |
| 223 | break; |
| 224 | default: |
| 225 | B43_WARN_ON(1); |
| 226 | return; |
| 227 | } |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 228 | } else { |
Michael Buesch | 21954c3 | 2007-09-27 15:31:40 +0200 | [diff] [blame] | 229 | behaviour = sprom[i] & B43_LED_BEHAVIOUR; |
| 230 | activelow = !!(sprom[i] & B43_LED_ACTIVELOW); |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 231 | } |
Michael Buesch | 21954c3 | 2007-09-27 15:31:40 +0200 | [diff] [blame] | 232 | b43_map_led(dev, i, behaviour, activelow); |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 233 | } |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | void b43_leds_exit(struct b43_wldev *dev) |
| 237 | { |
Michael Buesch | 21954c3 | 2007-09-27 15:31:40 +0200 | [diff] [blame] | 238 | b43_unregister_led(&dev->led_tx); |
| 239 | b43_unregister_led(&dev->led_rx); |
| 240 | b43_unregister_led(&dev->led_assoc); |
Larry Finger | 1a8d1227 | 2007-12-14 13:59:11 +0100 | [diff] [blame] | 241 | b43_unregister_led(&dev->led_radio); |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 242 | } |