3 Broadcom BCM43xx 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>
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"
30 #include "bcm43xx_main.h"
32 static void bcm43xx_led_changestate(struct bcm43xx_led
*led
)
34 struct bcm43xx_wldev
*dev
= led
->dev
;
35 const int index
= bcm43xx_led_index(led
);
36 const u16 mask
= (1 << index
);
39 assert(index
>= 0 && index
< BCM43xx_NR_LEDS
);
40 assert(led
->blink_interval
);
41 ledctl
= bcm43xx_read16(dev
, BCM43xx_MMIO_GPIO_CONTROL
);
42 ledctl
= (ledctl
& mask
) ? (ledctl
& ~mask
) : (ledctl
| mask
);
43 bcm43xx_write16(dev
, BCM43xx_MMIO_GPIO_CONTROL
, ledctl
);
46 static void bcm43xx_led_blink(unsigned long d
)
48 struct bcm43xx_led
*led
= (struct bcm43xx_led
*)d
;
49 struct bcm43xx_wldev
*dev
= led
->dev
;
52 spin_lock_irqsave(&dev
->wl
->leds_lock
, flags
);
53 if (led
->blink_interval
) {
54 bcm43xx_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 bcm43xx_led_blink_start(struct bcm43xx_led
*led
,
61 unsigned long interval
)
63 if (led
->blink_interval
)
65 led
->blink_interval
= interval
;
66 bcm43xx_led_changestate(led
);
67 led
->blink_timer
.expires
= jiffies
+ interval
;
68 add_timer(&led
->blink_timer
);
71 static void bcm43xx_led_blink_stop(struct bcm43xx_led
*led
, int sync
)
73 struct bcm43xx_wldev
*dev
= led
->dev
;
74 const int index
= bcm43xx_led_index(led
);
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 assert(index
>= 0 && index
< BCM43xx_NR_LEDS
);
87 ledctl
= bcm43xx_read16(dev
, BCM43xx_MMIO_GPIO_CONTROL
);
89 ledctl
|= (1 << index
);
91 ledctl
&= ~(1 << index
);
92 bcm43xx_write16(dev
, BCM43xx_MMIO_GPIO_CONTROL
, ledctl
);
95 static void bcm43xx_led_init_hardcoded(struct bcm43xx_wldev
*dev
,
96 struct bcm43xx_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 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
;
112 if (bus
->board_vendor
== PCI_VENDOR_ID_COMPAQ
)
113 led
->behaviour
= BCM43xx_LED_RADIO_ALL
;
116 led
->behaviour
= BCM43xx_LED_RADIO_B
;
117 if (bus
->board_vendor
== PCI_VENDOR_ID_ASUSTEK
)
118 led
->behaviour
= BCM43xx_LED_ASSOC
;
121 led
->behaviour
= BCM43xx_LED_RADIO_A
;
124 led
->behaviour
= BCM43xx_LED_OFF
;
131 int bcm43xx_leds_init(struct bcm43xx_wldev
*dev
)
133 struct bcm43xx_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
< BCM43xx_NR_LEDS
; i
++) {
143 led
= &(dev
->leds
[i
]);
145 setup_timer(&led
->blink_timer
,
149 if (sprom
[i
] == 0xFF) {
150 bcm43xx_led_init_hardcoded(dev
, led
, i
);
152 led
->behaviour
= sprom
[i
] & BCM43xx_LED_BEHAVIOUR
;
153 led
->activelow
= !!(sprom
[i
] & BCM43xx_LED_ACTIVELOW
);
160 void bcm43xx_leds_exit(struct bcm43xx_wldev
*dev
)
162 struct bcm43xx_led
*led
;
165 for (i
= 0; i
< BCM43xx_NR_LEDS
; i
++) {
166 led
= &(dev
->leds
[i
]);
167 bcm43xx_led_blink_stop(led
, 1);
169 bcm43xx_leds_switch_all(dev
, 0);
172 void bcm43xx_leds_update(struct bcm43xx_wldev
*dev
, int activity
)
174 struct bcm43xx_led
*led
;
175 struct bcm43xx_phy
*phy
= &dev
->phy
;
176 const int transferring
= (jiffies
- dev
->stats
.last_tx
) < BCM43xx_LED_XFER_THRES
;
178 unsigned long interval
= 0;
182 spin_lock_irqsave(&dev
->wl
->leds_lock
, flags
);
183 ledctl
= bcm43xx_read16(dev
, BCM43xx_MMIO_GPIO_CONTROL
);
184 for (i
= 0; i
< BCM43xx_NR_LEDS
; i
++) {
185 led
= &(dev
->leds
[i
]);
188 switch (led
->behaviour
) {
189 case BCM43xx_LED_INACTIVE
:
191 case BCM43xx_LED_OFF
:
196 case BCM43xx_LED_ACTIVITY
:
199 case BCM43xx_LED_RADIO_ALL
:
200 turn_on
= phy
->radio_on
&& bcm43xx_is_hw_radio_enabled(dev
);
202 case BCM43xx_LED_RADIO_A
:
203 turn_on
= (phy
->radio_on
&& bcm43xx_is_hw_radio_enabled(dev
)
204 && phy
->type
== BCM43xx_PHYTYPE_A
);
206 case BCM43xx_LED_RADIO_B
:
207 turn_on
= (phy
->radio_on
&& bcm43xx_is_hw_radio_enabled(dev
) &&
208 (phy
->type
== BCM43xx_PHYTYPE_B
||
209 phy
->type
== BCM43xx_PHYTYPE_G
));
211 case BCM43xx_LED_MODE_BG
:
212 if (phy
->type
== BCM43xx_PHYTYPE_G
&& bcm43xx_is_hw_radio_enabled(dev
) &&
213 1/*FIXME: using G rates.*/)
216 case BCM43xx_LED_TRANSFER
:
218 bcm43xx_led_blink_start(led
, BCM43xx_LEDBLINK_MEDIUM
);
220 bcm43xx_led_blink_stop(led
, 0);
222 case BCM43xx_LED_APTRANSFER
:
223 if (bcm43xx_is_mode(dev
->wl
, IEEE80211_IF_TYPE_AP
)) {
225 interval
= BCM43xx_LEDBLINK_FAST
;
230 if (0/*TODO: not assoc*/)
231 interval
= BCM43xx_LEDBLINK_SLOW
;
232 else if (transferring
)
233 interval
= BCM43xx_LEDBLINK_FAST
;
238 bcm43xx_led_blink_start(led
, interval
);
240 bcm43xx_led_blink_stop(led
, 0);
242 case BCM43xx_LED_WEIRD
:
245 case BCM43xx_LED_ASSOC
:
246 if (1/*dev->softmac->associated*/)
249 #ifdef CONFIG_BCM43XX_DEBUG
250 case BCM43xx_LED_TEST_BLINKSLOW
:
251 bcm43xx_led_blink_start(led
, BCM43xx_LEDBLINK_SLOW
);
253 case BCM43xx_LED_TEST_BLINKMEDIUM
:
254 bcm43xx_led_blink_start(led
, BCM43xx_LEDBLINK_MEDIUM
);
256 case BCM43xx_LED_TEST_BLINKFAST
:
257 bcm43xx_led_blink_start(led
, BCM43xx_LEDBLINK_FAST
);
259 #endif /* CONFIG_BCM43XX_DEBUG */
271 bcm43xx_write16(dev
, BCM43xx_MMIO_GPIO_CONTROL
, ledctl
);
272 spin_unlock_irqrestore(&dev
->wl
->leds_lock
, flags
);
275 void bcm43xx_leds_switch_all(struct bcm43xx_wldev
*dev
, int on
)
277 struct bcm43xx_led
*led
;
283 spin_lock_irqsave(&dev
->wl
->leds_lock
, flags
);
284 ledctl
= bcm43xx_read16(dev
, BCM43xx_MMIO_GPIO_CONTROL
);
285 for (i
= 0; i
< BCM43xx_NR_LEDS
; i
++) {
286 led
= &(dev
->leds
[i
]);
287 if (led
->behaviour
== BCM43xx_LED_INACTIVE
)
290 bit_on
= led
->activelow
? 0 : 1;
292 bit_on
= led
->activelow
? 1 : 0;
298 bcm43xx_write16(dev
, BCM43xx_MMIO_GPIO_CONTROL
, ledctl
);
299 spin_unlock_irqrestore(&dev
->wl
->leds_lock
, flags
);