3 Broadcom B43legacy wireless driver
5 Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>,
6 Stefano Brivio <st3@riseup.net>
7 Michael Buesch <mb@bu3sch.de>
8 Danny van Dyk <kugelfang@gentoo.org>
9 Andreas Jaggi <andreas.jaggi@waterwave.ch>
10 Copyright (c) 2007 Larry Finger <Larry.Finger@lwfinger.net>
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.
30 #include "b43legacy.h"
33 static void b43legacy_led_changestate(struct b43legacy_led
*led
)
35 struct b43legacy_wldev
*dev
= led
->dev
;
36 const int index
= led
->index
;
39 B43legacy_WARN_ON(!(index
>= 0 && index
< B43legacy_NR_LEDS
));
40 B43legacy_WARN_ON(!led
->blink_interval
);
41 ledctl
= b43legacy_read16(dev
, B43legacy_MMIO_GPIO_CONTROL
);
42 ledctl
^= (1 << index
);
43 b43legacy_write16(dev
, B43legacy_MMIO_GPIO_CONTROL
, ledctl
);
46 static void b43legacy_led_blink(unsigned long d
)
48 struct b43legacy_led
*led
= (struct b43legacy_led
*)d
;
49 struct b43legacy_wldev
*dev
= led
->dev
;
52 spin_lock_irqsave(&dev
->wl
->leds_lock
, flags
);
53 if (led
->blink_interval
) {
54 b43legacy_led_changestate(led
);
55 mod_timer(&led
->blink_timer
, jiffies
+ led
->blink_interval
);
57 spin_unlock_irqrestore(&dev
->wl
->leds_lock
, flags
);
60 static void b43legacy_led_blink_start(struct b43legacy_led
*led
,
61 unsigned long interval
)
63 if (led
->blink_interval
)
65 led
->blink_interval
= interval
;
66 b43legacy_led_changestate(led
);
67 led
->blink_timer
.expires
= jiffies
+ interval
;
68 add_timer(&led
->blink_timer
);
71 static void b43legacy_led_blink_stop(struct b43legacy_led
*led
, int sync
)
73 struct b43legacy_wldev
*dev
= led
->dev
;
74 const int index
= led
->index
;
77 if (!led
->blink_interval
)
80 del_timer_sync(&led
->blink_timer
);
82 del_timer(&led
->blink_timer
);
83 led
->blink_interval
= 0;
85 /* Make sure the LED is turned off. */
86 B43legacy_WARN_ON(!(index
>= 0 && index
< B43legacy_NR_LEDS
));
87 ledctl
= b43legacy_read16(dev
, B43legacy_MMIO_GPIO_CONTROL
);
89 ledctl
|= (1 << index
);
91 ledctl
&= ~(1 << index
);
92 b43legacy_write16(dev
, B43legacy_MMIO_GPIO_CONTROL
, ledctl
);
95 static void b43legacy_led_init_hardcoded(struct b43legacy_wldev
*dev
,
96 struct b43legacy_led
*led
,
99 struct ssb_bus
*bus
= dev
->dev
->bus
;
101 /* This function is called, if the behaviour (and activelow)
102 * information for a LED is missing in the SPROM.
103 * We hardcode the behaviour values for various devices here.
104 * Note that the B43legacy_LED_TEST_XXX behaviour values can
105 * be used to figure out which led is mapped to which index.
110 led
->behaviour
= B43legacy_LED_ACTIVITY
;
112 if (bus
->boardinfo
.vendor
== PCI_VENDOR_ID_COMPAQ
)
113 led
->behaviour
= B43legacy_LED_RADIO_ALL
;
116 led
->behaviour
= B43legacy_LED_RADIO_B
;
117 if (bus
->boardinfo
.vendor
== PCI_VENDOR_ID_ASUSTEK
)
118 led
->behaviour
= B43legacy_LED_ASSOC
;
121 led
->behaviour
= B43legacy_LED_RADIO_A
;
124 led
->behaviour
= B43legacy_LED_OFF
;
131 int b43legacy_leds_init(struct b43legacy_wldev
*dev
)
133 struct b43legacy_led
*led
;
137 sprom
[0] = dev
->dev
->bus
->sprom
.r1
.gpio0
;
138 sprom
[1] = dev
->dev
->bus
->sprom
.r1
.gpio1
;
139 sprom
[2] = dev
->dev
->bus
->sprom
.r1
.gpio2
;
140 sprom
[3] = dev
->dev
->bus
->sprom
.r1
.gpio3
;
142 for (i
= 0; i
< B43legacy_NR_LEDS
; i
++) {
143 led
= &(dev
->leds
[i
]);
146 setup_timer(&led
->blink_timer
,
150 if (sprom
[i
] == 0xFF)
151 b43legacy_led_init_hardcoded(dev
, led
, i
);
153 led
->behaviour
= sprom
[i
] & B43legacy_LED_BEHAVIOUR
;
154 led
->activelow
= !!(sprom
[i
] &
155 B43legacy_LED_ACTIVELOW
);
162 void b43legacy_leds_exit(struct b43legacy_wldev
*dev
)
164 struct b43legacy_led
*led
;
167 for (i
= 0; i
< B43legacy_NR_LEDS
; i
++) {
168 led
= &(dev
->leds
[i
]);
169 b43legacy_led_blink_stop(led
, 1);
171 b43legacy_leds_switch_all(dev
, 0);
174 void b43legacy_leds_update(struct b43legacy_wldev
*dev
, int activity
)
176 struct b43legacy_led
*led
;
177 struct b43legacy_phy
*phy
= &dev
->phy
;
178 const int transferring
= (jiffies
- dev
->stats
.last_tx
)
179 < B43legacy_LED_XFER_THRES
;
182 unsigned long interval
= 0;
185 bool radio_enabled
= (phy
->radio_on
&& dev
->radio_hw_enable
);
187 spin_lock_irqsave(&dev
->wl
->leds_lock
, flags
);
188 ledctl
= b43legacy_read16(dev
, B43legacy_MMIO_GPIO_CONTROL
);
189 for (i
= 0; i
< B43legacy_NR_LEDS
; i
++) {
190 led
= &(dev
->leds
[i
]);
193 switch (led
->behaviour
) {
194 case B43legacy_LED_INACTIVE
:
196 case B43legacy_LED_OFF
:
198 case B43legacy_LED_ON
:
201 case B43legacy_LED_ACTIVITY
:
204 case B43legacy_LED_RADIO_ALL
:
205 turn_on
= radio_enabled
;
207 case B43legacy_LED_RADIO_A
:
209 case B43legacy_LED_RADIO_B
:
210 turn_on
= radio_enabled
;
212 case B43legacy_LED_MODE_BG
:
213 if (phy
->type
== B43legacy_PHYTYPE_G
&& radio_enabled
)
216 case B43legacy_LED_TRANSFER
:
218 b43legacy_led_blink_start(led
,
219 B43legacy_LEDBLINK_MEDIUM
);
221 b43legacy_led_blink_stop(led
, 0);
223 case B43legacy_LED_APTRANSFER
:
224 if (b43legacy_is_mode(dev
->wl
,
225 IEEE80211_IF_TYPE_AP
)) {
227 interval
= B43legacy_LEDBLINK_FAST
;
233 interval
= B43legacy_LEDBLINK_FAST
;
238 b43legacy_led_blink_start(led
, interval
);
240 b43legacy_led_blink_stop(led
, 0);
242 case B43legacy_LED_WEIRD
:
244 case B43legacy_LED_ASSOC
:
246 #ifdef CONFIG_B43LEGACY_DEBUG
247 case B43legacy_LED_TEST_BLINKSLOW
:
248 b43legacy_led_blink_start(led
, B43legacy_LEDBLINK_SLOW
);
250 case B43legacy_LED_TEST_BLINKMEDIUM
:
251 b43legacy_led_blink_start(led
,
252 B43legacy_LEDBLINK_MEDIUM
);
254 case B43legacy_LED_TEST_BLINKFAST
:
255 b43legacy_led_blink_start(led
, B43legacy_LEDBLINK_FAST
);
257 #endif /* CONFIG_B43LEGACY_DEBUG */
269 b43legacy_write16(dev
, B43legacy_MMIO_GPIO_CONTROL
, ledctl
);
270 spin_unlock_irqrestore(&dev
->wl
->leds_lock
, flags
);
273 void b43legacy_leds_switch_all(struct b43legacy_wldev
*dev
, int on
)
275 struct b43legacy_led
*led
;
281 spin_lock_irqsave(&dev
->wl
->leds_lock
, flags
);
282 ledctl
= b43legacy_read16(dev
, B43legacy_MMIO_GPIO_CONTROL
);
283 for (i
= 0; i
< B43legacy_NR_LEDS
; i
++) {
284 led
= &(dev
->leds
[i
]);
285 if (led
->behaviour
== B43legacy_LED_INACTIVE
)
288 bit_on
= led
->activelow
? 0 : 1;
290 bit_on
= led
->activelow
? 1 : 0;
296 b43legacy_write16(dev
, B43legacy_MMIO_GPIO_CONTROL
, ledctl
);
297 spin_unlock_irqrestore(&dev
->wl
->leds_lock
, flags
);