3 Broadcom BCM43xx wireless driver
5 Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>,
6 Stefano Brivio <st3@riseup.net>
7 Michael Buesch <mbuesch@freenet.de>
8 Danny van Dyk <kugelfang@gentoo.org>
9 Andreas Jaggi <andreas.jaggi@waterwave.ch>
11 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 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; see the file COPYING. If not, write to
23 the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
24 Boston, MA 02110-1301, USA.
28 #include "bcm43xx_leds.h"
31 #include <asm/bitops.h>
34 static void bcm43xx_led_changestate(struct bcm43xx_led
*led
)
36 struct bcm43xx_private
*bcm
= led
->bcm
;
37 const int index
= bcm43xx_led_index(led
);
38 const u16 mask
= (1 << index
);
41 assert(index
>= 0 && index
< BCM43xx_NR_LEDS
);
42 assert(led
->blink_interval
);
43 ledctl
= bcm43xx_read16(bcm
, BCM43xx_MMIO_GPIO_CONTROL
);
44 ledctl
= (ledctl
& mask
) ? (ledctl
& ~mask
) : (ledctl
| mask
);
45 bcm43xx_write16(bcm
, BCM43xx_MMIO_GPIO_CONTROL
, ledctl
);
48 static void bcm43xx_led_blink(unsigned long d
)
50 struct bcm43xx_led
*led
= (struct bcm43xx_led
*)d
;
51 struct bcm43xx_private
*bcm
= led
->bcm
;
54 spin_lock_irqsave(&bcm
->leds_lock
, flags
);
55 if (led
->blink_interval
) {
56 bcm43xx_led_changestate(led
);
57 mod_timer(&led
->blink_timer
, jiffies
+ led
->blink_interval
);
59 spin_unlock_irqrestore(&bcm
->leds_lock
, flags
);
62 static void bcm43xx_led_blink_start(struct bcm43xx_led
*led
,
63 unsigned long interval
)
65 if (led
->blink_interval
)
67 led
->blink_interval
= interval
;
68 bcm43xx_led_changestate(led
);
69 led
->blink_timer
.expires
= jiffies
+ interval
;
70 add_timer(&led
->blink_timer
);
73 static void bcm43xx_led_blink_stop(struct bcm43xx_led
*led
, int sync
)
75 struct bcm43xx_private
*bcm
= led
->bcm
;
76 const int index
= bcm43xx_led_index(led
);
79 if (!led
->blink_interval
)
82 del_timer_sync(&led
->blink_timer
);
84 del_timer(&led
->blink_timer
);
85 led
->blink_interval
= 0;
87 /* Make sure the LED is turned off. */
88 assert(index
>= 0 && index
< BCM43xx_NR_LEDS
);
89 ledctl
= bcm43xx_read16(bcm
, BCM43xx_MMIO_GPIO_CONTROL
);
91 ledctl
|= (1 << index
);
93 ledctl
&= ~(1 << index
);
94 bcm43xx_write16(bcm
, BCM43xx_MMIO_GPIO_CONTROL
, ledctl
);
97 static void bcm43xx_led_init_hardcoded(struct bcm43xx_private
*bcm
,
98 struct bcm43xx_led
*led
,
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 BCM43xx_LED_TEST_XXX behaviour values can
105 * be used to figure out which led is mapped to which index.
110 led
->behaviour
= BCM43xx_LED_ACTIVITY
;
111 if (bcm
->board_vendor
== PCI_VENDOR_ID_COMPAQ
)
112 led
->behaviour
= BCM43xx_LED_RADIO_ALL
;
115 led
->behaviour
= BCM43xx_LED_RADIO_B
;
116 if (bcm
->board_vendor
== PCI_VENDOR_ID_ASUSTEK
)
117 led
->behaviour
= BCM43xx_LED_ASSOC
;
120 led
->behaviour
= BCM43xx_LED_RADIO_A
;
123 led
->behaviour
= BCM43xx_LED_OFF
;
130 int bcm43xx_leds_init(struct bcm43xx_private
*bcm
)
132 struct bcm43xx_led
*led
;
136 sprom
[0] = bcm
->sprom
.wl0gpio0
;
137 sprom
[1] = bcm
->sprom
.wl0gpio1
;
138 sprom
[2] = bcm
->sprom
.wl0gpio2
;
139 sprom
[3] = bcm
->sprom
.wl0gpio3
;
141 for (i
= 0; i
< BCM43xx_NR_LEDS
; i
++) {
142 led
= &(bcm
->leds
[i
]);
144 setup_timer(&led
->blink_timer
,
148 if (sprom
[i
] == 0xFF) {
149 bcm43xx_led_init_hardcoded(bcm
, led
, i
);
151 led
->behaviour
= sprom
[i
] & BCM43xx_LED_BEHAVIOUR
;
152 led
->activelow
= !!(sprom
[i
] & BCM43xx_LED_ACTIVELOW
);
159 void bcm43xx_leds_exit(struct bcm43xx_private
*bcm
)
161 struct bcm43xx_led
*led
;
164 for (i
= 0; i
< BCM43xx_NR_LEDS
; i
++) {
165 led
= &(bcm
->leds
[i
]);
166 bcm43xx_led_blink_stop(led
, 1);
168 bcm43xx_leds_switch_all(bcm
, 0);
171 void bcm43xx_leds_update(struct bcm43xx_private
*bcm
, int activity
)
173 struct bcm43xx_led
*led
;
174 struct bcm43xx_radioinfo
*radio
= bcm43xx_current_radio(bcm
);
175 struct bcm43xx_phyinfo
*phy
= bcm43xx_current_phy(bcm
);
176 const int transferring
= (jiffies
- bcm
->stats
.last_tx
) < BCM43xx_LED_XFER_THRES
;
178 unsigned long interval
= 0;
182 spin_lock_irqsave(&bcm
->leds_lock
, flags
);
183 ledctl
= bcm43xx_read16(bcm
, BCM43xx_MMIO_GPIO_CONTROL
);
184 for (i
= 0; i
< BCM43xx_NR_LEDS
; i
++) {
185 led
= &(bcm
->leds
[i
]);
188 switch (led
->behaviour
) {
189 case BCM43xx_LED_INACTIVE
:
191 case BCM43xx_LED_OFF
:
192 case BCM43xx_LED_BCM4303_3
:
197 case BCM43xx_LED_ACTIVITY
:
198 case BCM43xx_LED_BCM4303_0
:
201 case BCM43xx_LED_RADIO_ALL
:
202 turn_on
= radio
->enabled
;
204 case BCM43xx_LED_RADIO_A
:
205 case BCM43xx_LED_BCM4303_2
:
206 turn_on
= (radio
->enabled
&& phy
->type
== BCM43xx_PHYTYPE_A
);
208 case BCM43xx_LED_RADIO_B
:
209 case BCM43xx_LED_BCM4303_1
:
210 turn_on
= (radio
->enabled
&&
211 (phy
->type
== BCM43xx_PHYTYPE_B
||
212 phy
->type
== BCM43xx_PHYTYPE_G
));
214 case BCM43xx_LED_MODE_BG
:
215 if (phy
->type
== BCM43xx_PHYTYPE_G
&&
216 1/*FIXME: using G rates.*/)
219 case BCM43xx_LED_TRANSFER
:
221 bcm43xx_led_blink_start(led
, BCM43xx_LEDBLINK_MEDIUM
);
223 bcm43xx_led_blink_stop(led
, 0);
225 case BCM43xx_LED_APTRANSFER
:
226 if (bcm
->ieee
->iw_mode
== IW_MODE_MASTER
) {
228 interval
= BCM43xx_LEDBLINK_FAST
;
233 if (0/*TODO: not assoc*/)
234 interval
= BCM43xx_LEDBLINK_SLOW
;
235 else if (transferring
)
236 interval
= BCM43xx_LEDBLINK_FAST
;
241 bcm43xx_led_blink_start(led
, interval
);
243 bcm43xx_led_blink_stop(led
, 0);
245 case BCM43xx_LED_WEIRD
:
248 case BCM43xx_LED_ASSOC
:
249 if (bcm
->softmac
->associnfo
.associated
)
252 #ifdef CONFIG_BCM43XX_DEBUG
253 case BCM43xx_LED_TEST_BLINKSLOW
:
254 bcm43xx_led_blink_start(led
, BCM43xx_LEDBLINK_SLOW
);
256 case BCM43xx_LED_TEST_BLINKMEDIUM
:
257 bcm43xx_led_blink_start(led
, BCM43xx_LEDBLINK_MEDIUM
);
259 case BCM43xx_LED_TEST_BLINKFAST
:
260 bcm43xx_led_blink_start(led
, BCM43xx_LEDBLINK_FAST
);
262 #endif /* CONFIG_BCM43XX_DEBUG */
264 dprintkl(KERN_INFO PFX
"Bad value in leds_update,"
265 " led->behaviour: 0x%x\n", led
->behaviour
);
275 bcm43xx_write16(bcm
, BCM43xx_MMIO_GPIO_CONTROL
, ledctl
);
276 spin_unlock_irqrestore(&bcm
->leds_lock
, flags
);
279 void bcm43xx_leds_switch_all(struct bcm43xx_private
*bcm
, int on
)
281 struct bcm43xx_led
*led
;
287 spin_lock_irqsave(&bcm
->leds_lock
, flags
);
288 ledctl
= bcm43xx_read16(bcm
, BCM43xx_MMIO_GPIO_CONTROL
);
289 for (i
= 0; i
< BCM43xx_NR_LEDS
; i
++) {
290 led
= &(bcm
->leds
[i
]);
291 if (led
->behaviour
== BCM43xx_LED_INACTIVE
)
294 bit_on
= led
->activelow
? 0 : 1;
296 bit_on
= led
->activelow
? 1 : 0;
302 bcm43xx_write16(bcm
, BCM43xx_MMIO_GPIO_CONTROL
, ledctl
);
303 spin_unlock_irqrestore(&bcm
->leds_lock
, flags
);