2 Copyright (C) 2004 - 2008 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 if (!rt2x00dev->trigger_qual.registered)
38 * Led handling requires a positive value for the rssi,
39 * to do that correctly we need to add the correction.
41 rssi += rt2x00dev->rssi_offset;
44 * Get the rssi level, this is used to convert the rssi
45 * to a LED value inside the range LED_OFF - LED_FULL.
61 * Note that we must _not_ send LED_OFF since the driver
62 * is going to calculate the value and might use it in a
65 led_trigger_event(&rt2x00dev->trigger_qual.trigger,
66 ((LED_FULL / 6) * rssi) + 1);
69 static int rt2x00leds_register_trigger(struct rt2x00_dev *rt2x00dev,
70 struct rt2x00_trigger *trigger,
75 trigger->trigger.name = name;
76 retval = led_trigger_register(&trigger->trigger);
78 ERROR(rt2x00dev, "Failed to register led trigger.\n");
82 trigger->registered = 1;
87 static int rt2x00leds_register_led(struct rt2x00_dev *rt2x00dev,
88 struct rt2x00_led *led,
90 const char *name, char *trigger)
92 struct device *device = wiphy_dev(rt2x00dev->hw->wiphy);
95 led->led_dev.name = name;
96 led->led_dev.brightness_set = rt2x00dev->ops->lib->led_brightness;
97 led->led_dev.default_trigger = trigger;
99 retval = led_classdev_register(device, &led->led_dev);
101 ERROR(rt2x00dev, "Failed to register led handler.\n");
105 led->rt2x00dev = rt2x00dev;
112 void rt2x00leds_register(struct rt2x00_dev *rt2x00dev)
119 if (!rt2x00dev->ops->lib->led_brightness)
122 snprintf(dev_name, sizeof(dev_name), "%s-%s",
123 rt2x00dev->ops->name, wiphy_name(rt2x00dev->hw->wiphy));
125 if (rt2x00dev->led_flags & LED_SUPPORT_RADIO) {
126 trigger = ieee80211_get_radio_led_name(rt2x00dev->hw);
127 snprintf(name, sizeof(name), "%s:radio", dev_name);
129 retval = rt2x00leds_register_led(rt2x00dev,
130 &rt2x00dev->led_radio,
137 if (rt2x00dev->led_flags & LED_SUPPORT_ASSOC) {
138 trigger = ieee80211_get_assoc_led_name(rt2x00dev->hw);
139 snprintf(name, sizeof(name), "%s:assoc", dev_name);
141 retval = rt2x00leds_register_led(rt2x00dev,
142 &rt2x00dev->led_assoc,
149 if (rt2x00dev->led_flags & LED_SUPPORT_QUALITY) {
150 snprintf(name, sizeof(name), "%s:quality", dev_name);
152 retval = rt2x00leds_register_trigger(rt2x00dev,
153 &rt2x00dev->trigger_qual,
156 retval = rt2x00leds_register_led(rt2x00dev,
157 &rt2x00dev->led_qual,
167 rt2x00leds_unregister(rt2x00dev);
170 static void rt2x00leds_unregister_trigger(struct rt2x00_trigger *trigger)
172 if (!trigger->registered)
175 led_trigger_unregister(&trigger->trigger);
176 trigger->registered = 0;
179 static void rt2x00leds_unregister_led(struct rt2x00_led *led)
181 if (!led->registered)
184 led_classdev_unregister(&led->led_dev);
186 led->led_dev.brightness_set(&led->led_dev, LED_OFF);
190 void rt2x00leds_unregister(struct rt2x00_dev *rt2x00dev)
192 rt2x00leds_unregister_trigger(&rt2x00dev->trigger_qual);
193 rt2x00leds_unregister_led(&rt2x00dev->led_qual);
194 rt2x00leds_unregister_led(&rt2x00dev->led_assoc);
195 rt2x00leds_unregister_led(&rt2x00dev->led_radio);
198 void rt2x00leds_suspend(struct rt2x00_dev *rt2x00dev)
200 if (rt2x00dev->led_qual.registered)
201 led_classdev_suspend(&rt2x00dev->led_qual.led_dev);
202 if (rt2x00dev->led_assoc.registered)
203 led_classdev_suspend(&rt2x00dev->led_assoc.led_dev);
204 if (rt2x00dev->led_radio.registered)
205 led_classdev_suspend(&rt2x00dev->led_radio.led_dev);
208 void rt2x00leds_resume(struct rt2x00_dev *rt2x00dev)
210 if (rt2x00dev->led_radio.registered)
211 led_classdev_resume(&rt2x00dev->led_radio.led_dev);
212 if (rt2x00dev->led_assoc.registered)
213 led_classdev_resume(&rt2x00dev->led_assoc.led_dev);
214 if (rt2x00dev->led_qual.registered)
215 led_classdev_resume(&rt2x00dev->led_qual.led_dev);