2 Copyright (C) 2004 - 2009 rt2x00 SourceForge Project
3 <http://rt2x00.serialmonkey.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the
17 Free Software Foundation, Inc.,
18 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 Abstract: rt2x00 led specific routines.
26 #include <linux/kernel.h>
27 #include <linux/module.h>
30 #include "rt2x00lib.h"
32 void rt2x00leds_led_quality(struct rt2x00_dev
*rt2x00dev
, int rssi
)
34 struct rt2x00_led
*led
= &rt2x00dev
->led_qual
;
35 unsigned int brightness
;
37 if ((led
->type
!= LED_TYPE_QUALITY
) || !(led
->flags
& LED_REGISTERED
))
41 * Led handling requires a positive value for the rssi,
42 * to do that correctly we need to add the correction.
44 rssi
+= rt2x00dev
->rssi_offset
;
47 * Get the rssi level, this is used to convert the rssi
48 * to a LED value inside the range LED_OFF - LED_FULL.
64 * Note that we must _not_ send LED_OFF since the driver
65 * is going to calculate the value and might use it in a
68 brightness
= ((LED_FULL
/ 6) * rssi
) + 1;
69 if (brightness
!= led
->led_dev
.brightness
) {
70 led
->led_dev
.brightness_set(&led
->led_dev
, brightness
);
71 led
->led_dev
.brightness
= brightness
;
75 static void rt2x00led_led_simple(struct rt2x00_led
*led
, bool enabled
)
77 unsigned int brightness
= enabled
? LED_FULL
: LED_OFF
;
79 if (!(led
->flags
& LED_REGISTERED
))
82 led
->led_dev
.brightness_set(&led
->led_dev
, brightness
);
83 led
->led_dev
.brightness
= brightness
;
86 void rt2x00led_led_activity(struct rt2x00_dev
*rt2x00dev
, bool enabled
)
88 if (rt2x00dev
->led_qual
.type
== LED_TYPE_ACTIVITY
)
89 rt2x00led_led_simple(&rt2x00dev
->led_qual
, enabled
);
92 void rt2x00leds_led_assoc(struct rt2x00_dev
*rt2x00dev
, bool enabled
)
94 if (rt2x00dev
->led_assoc
.type
== LED_TYPE_ASSOC
)
95 rt2x00led_led_simple(&rt2x00dev
->led_assoc
, enabled
);
98 void rt2x00leds_led_radio(struct rt2x00_dev
*rt2x00dev
, bool enabled
)
100 if (rt2x00dev
->led_radio
.type
== LED_TYPE_RADIO
)
101 rt2x00led_led_simple(&rt2x00dev
->led_radio
, enabled
);
104 static int rt2x00leds_register_led(struct rt2x00_dev
*rt2x00dev
,
105 struct rt2x00_led
*led
,
108 struct device
*device
= wiphy_dev(rt2x00dev
->hw
->wiphy
);
111 led
->led_dev
.name
= name
;
112 led
->led_dev
.brightness
= LED_OFF
;
114 retval
= led_classdev_register(device
, &led
->led_dev
);
116 ERROR(rt2x00dev
, "Failed to register led handler.\n");
120 led
->flags
|= LED_REGISTERED
;
125 void rt2x00leds_register(struct rt2x00_dev
*rt2x00dev
)
130 unsigned long on_period
;
131 unsigned long off_period
;
133 snprintf(dev_name
, sizeof(dev_name
), "%s-%s",
134 rt2x00dev
->ops
->name
, wiphy_name(rt2x00dev
->hw
->wiphy
));
136 if (rt2x00dev
->led_radio
.flags
& LED_INITIALIZED
) {
137 snprintf(name
, sizeof(name
), "%s::radio", dev_name
);
139 retval
= rt2x00leds_register_led(rt2x00dev
,
140 &rt2x00dev
->led_radio
,
146 if (rt2x00dev
->led_assoc
.flags
& LED_INITIALIZED
) {
147 snprintf(name
, sizeof(name
), "%s::assoc", dev_name
);
149 retval
= rt2x00leds_register_led(rt2x00dev
,
150 &rt2x00dev
->led_assoc
,
156 if (rt2x00dev
->led_qual
.flags
& LED_INITIALIZED
) {
157 snprintf(name
, sizeof(name
), "%s::quality", dev_name
);
159 retval
= rt2x00leds_register_led(rt2x00dev
,
160 &rt2x00dev
->led_qual
,
167 * Initialize blink time to default value:
171 if (rt2x00dev
->led_radio
.led_dev
.blink_set
) {
174 rt2x00dev
->led_radio
.led_dev
.blink_set(
175 &rt2x00dev
->led_radio
.led_dev
, &on_period
, &off_period
);
181 rt2x00leds_unregister(rt2x00dev
);
184 static void rt2x00leds_unregister_led(struct rt2x00_led
*led
)
186 led_classdev_unregister(&led
->led_dev
);
189 * This might look weird, but when we are unregistering while
190 * suspended the led is already off, and since we haven't
191 * fully resumed yet, access to the device might not be
194 if (!(led
->led_dev
.flags
& LED_SUSPENDED
))
195 led
->led_dev
.brightness_set(&led
->led_dev
, LED_OFF
);
197 led
->flags
&= ~LED_REGISTERED
;
200 void rt2x00leds_unregister(struct rt2x00_dev
*rt2x00dev
)
202 if (rt2x00dev
->led_qual
.flags
& LED_REGISTERED
)
203 rt2x00leds_unregister_led(&rt2x00dev
->led_qual
);
204 if (rt2x00dev
->led_assoc
.flags
& LED_REGISTERED
)
205 rt2x00leds_unregister_led(&rt2x00dev
->led_assoc
);
206 if (rt2x00dev
->led_radio
.flags
& LED_REGISTERED
)
207 rt2x00leds_unregister_led(&rt2x00dev
->led_radio
);
210 static inline void rt2x00leds_suspend_led(struct rt2x00_led
*led
)
212 led_classdev_suspend(&led
->led_dev
);
214 /* This shouldn't be needed, but just to be safe */
215 led
->led_dev
.brightness_set(&led
->led_dev
, LED_OFF
);
216 led
->led_dev
.brightness
= LED_OFF
;
219 void rt2x00leds_suspend(struct rt2x00_dev
*rt2x00dev
)
221 if (rt2x00dev
->led_qual
.flags
& LED_REGISTERED
)
222 rt2x00leds_suspend_led(&rt2x00dev
->led_qual
);
223 if (rt2x00dev
->led_assoc
.flags
& LED_REGISTERED
)
224 rt2x00leds_suspend_led(&rt2x00dev
->led_assoc
);
225 if (rt2x00dev
->led_radio
.flags
& LED_REGISTERED
)
226 rt2x00leds_suspend_led(&rt2x00dev
->led_radio
);
229 static inline void rt2x00leds_resume_led(struct rt2x00_led
*led
)
231 led_classdev_resume(&led
->led_dev
);
233 /* Device might have enabled the LEDS during resume */
234 led
->led_dev
.brightness_set(&led
->led_dev
, LED_OFF
);
235 led
->led_dev
.brightness
= LED_OFF
;
238 void rt2x00leds_resume(struct rt2x00_dev
*rt2x00dev
)
240 if (rt2x00dev
->led_radio
.flags
& LED_REGISTERED
)
241 rt2x00leds_resume_led(&rt2x00dev
->led_radio
);
242 if (rt2x00dev
->led_assoc
.flags
& LED_REGISTERED
)
243 rt2x00leds_resume_led(&rt2x00dev
->led_assoc
);
244 if (rt2x00dev
->led_qual
.flags
& LED_REGISTERED
)
245 rt2x00leds_resume_led(&rt2x00dev
->led_qual
);