diff options
author | Christian Lamparter <chunkeey@web.de> | 2009-06-23 11:37:59 -0400 |
---|---|---|
committer | John W. Linville <linville@tuxdriver.com> | 2009-07-10 15:01:58 -0400 |
commit | 0597c0141cf011ccf76419cb4f96f99b0d4b6171 (patch) | |
tree | 478e9241b6b26166923d935e466b68ecb170c892 /drivers/net/wireless/p54 | |
parent | 76074e1670b197385ce93242e3ba3ccc7a6be377 (diff) |
p54: Move LED code
Copy the LED code from p54common.c into a new file led.c
Signed-off-by: Christian Lamparter <chunkeey@web.de>
Signed-off-by: Larry Finger <Larry.Finger@lwfinger.net>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'drivers/net/wireless/p54')
-rw-r--r-- | drivers/net/wireless/p54/led.c | 163 |
1 files changed, 163 insertions, 0 deletions
diff --git a/drivers/net/wireless/p54/led.c b/drivers/net/wireless/p54/led.c new file mode 100644 index 000000000000..c00115b206d4 --- /dev/null +++ b/drivers/net/wireless/p54/led.c | |||
@@ -0,0 +1,163 @@ | |||
1 | /* | ||
2 | * Common code for mac80211 Prism54 drivers | ||
3 | * | ||
4 | * Copyright (c) 2006, Michael Wu <flamingice@sourmilk.net> | ||
5 | * Copyright (c) 2007-2009, Christian Lamparter <chunkeey@web.de> | ||
6 | * Copyright 2008, Johannes Berg <johannes@sipsolutions.net> | ||
7 | * | ||
8 | * Based on: | ||
9 | * - the islsm (softmac prism54) driver, which is: | ||
10 | * Copyright 2004-2006 Jean-Baptiste Note <jbnote@gmail.com>, et al. | ||
11 | * - stlc45xx driver | ||
12 | * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies). | ||
13 | * | ||
14 | * This program is free software; you can redistribute it and/or modify | ||
15 | * it under the terms of the GNU General Public License version 2 as | ||
16 | * published by the Free Software Foundation. | ||
17 | */ | ||
18 | |||
19 | #include <linux/init.h> | ||
20 | #include <linux/firmware.h> | ||
21 | #include <linux/etherdevice.h> | ||
22 | |||
23 | #include <net/mac80211.h> | ||
24 | #ifdef CONFIG_P54_LEDS | ||
25 | #include <linux/leds.h> | ||
26 | #endif /* CONFIG_P54_LEDS */ | ||
27 | |||
28 | #include "p54.h" | ||
29 | #include "lmac.h" | ||
30 | |||
31 | static void p54_update_leds(struct work_struct *work) | ||
32 | { | ||
33 | struct p54_common *priv = container_of(work, struct p54_common, | ||
34 | led_work.work); | ||
35 | int err, i, tmp, blink_delay = 400; | ||
36 | bool rerun = false; | ||
37 | |||
38 | /* Don't toggle the LED, when the device is down. */ | ||
39 | if (priv->mode == NL80211_IFTYPE_UNSPECIFIED) | ||
40 | return ; | ||
41 | |||
42 | for (i = 0; i < ARRAY_SIZE(priv->leds); i++) | ||
43 | if (priv->leds[i].toggled) { | ||
44 | priv->softled_state |= BIT(i); | ||
45 | |||
46 | tmp = 70 + 200 / (priv->leds[i].toggled); | ||
47 | if (tmp < blink_delay) | ||
48 | blink_delay = tmp; | ||
49 | |||
50 | if (priv->leds[i].led_dev.brightness == LED_OFF) | ||
51 | rerun = true; | ||
52 | |||
53 | priv->leds[i].toggled = | ||
54 | !!priv->leds[i].led_dev.brightness; | ||
55 | } else | ||
56 | priv->softled_state &= ~BIT(i); | ||
57 | |||
58 | err = p54_set_leds(priv); | ||
59 | if (err && net_ratelimit()) | ||
60 | printk(KERN_ERR "%s: failed to update LEDs (%d).\n", | ||
61 | wiphy_name(priv->hw->wiphy), err); | ||
62 | |||
63 | if (rerun) | ||
64 | queue_delayed_work(priv->hw->workqueue, &priv->led_work, | ||
65 | msecs_to_jiffies(blink_delay)); | ||
66 | } | ||
67 | |||
68 | static void p54_led_brightness_set(struct led_classdev *led_dev, | ||
69 | enum led_brightness brightness) | ||
70 | { | ||
71 | struct p54_led_dev *led = container_of(led_dev, struct p54_led_dev, | ||
72 | led_dev); | ||
73 | struct ieee80211_hw *dev = led->hw_dev; | ||
74 | struct p54_common *priv = dev->priv; | ||
75 | |||
76 | if (priv->mode == NL80211_IFTYPE_UNSPECIFIED) | ||
77 | return ; | ||
78 | |||
79 | if ((brightness) && (led->registered)) { | ||
80 | led->toggled++; | ||
81 | queue_delayed_work(priv->hw->workqueue, &priv->led_work, | ||
82 | HZ/10); | ||
83 | } | ||
84 | } | ||
85 | |||
86 | static int p54_register_led(struct p54_common *priv, | ||
87 | unsigned int led_index, | ||
88 | char *name, char *trigger) | ||
89 | { | ||
90 | struct p54_led_dev *led = &priv->leds[led_index]; | ||
91 | int err; | ||
92 | |||
93 | if (led->registered) | ||
94 | return -EEXIST; | ||
95 | |||
96 | snprintf(led->name, sizeof(led->name), "p54-%s::%s", | ||
97 | wiphy_name(priv->hw->wiphy), name); | ||
98 | led->hw_dev = priv->hw; | ||
99 | led->index = led_index; | ||
100 | led->led_dev.name = led->name; | ||
101 | led->led_dev.default_trigger = trigger; | ||
102 | led->led_dev.brightness_set = p54_led_brightness_set; | ||
103 | |||
104 | err = led_classdev_register(wiphy_dev(priv->hw->wiphy), &led->led_dev); | ||
105 | if (err) | ||
106 | printk(KERN_ERR "%s: Failed to register %s LED.\n", | ||
107 | wiphy_name(priv->hw->wiphy), name); | ||
108 | else | ||
109 | led->registered = 1; | ||
110 | |||
111 | return err; | ||
112 | } | ||
113 | |||
114 | int p54_init_leds(struct p54_common *priv) | ||
115 | { | ||
116 | int err; | ||
117 | |||
118 | /* | ||
119 | * TODO: | ||
120 | * Figure out if the EEPROM contains some hints about the number | ||
121 | * of available/programmable LEDs of the device. | ||
122 | */ | ||
123 | |||
124 | INIT_DELAYED_WORK(&priv->led_work, p54_update_leds); | ||
125 | |||
126 | err = p54_register_led(priv, 0, "assoc", | ||
127 | ieee80211_get_assoc_led_name(priv->hw)); | ||
128 | if (err) | ||
129 | return err; | ||
130 | |||
131 | err = p54_register_led(priv, 1, "tx", | ||
132 | ieee80211_get_tx_led_name(priv->hw)); | ||
133 | if (err) | ||
134 | return err; | ||
135 | |||
136 | err = p54_register_led(priv, 2, "rx", | ||
137 | ieee80211_get_rx_led_name(priv->hw)); | ||
138 | if (err) | ||
139 | return err; | ||
140 | |||
141 | err = p54_register_led(priv, 3, "radio", | ||
142 | ieee80211_get_radio_led_name(priv->hw)); | ||
143 | if (err) | ||
144 | return err; | ||
145 | |||
146 | err = p54_set_leds(priv); | ||
147 | return err; | ||
148 | } | ||
149 | |||
150 | void p54_unregister_leds(struct p54_common *priv) | ||
151 | { | ||
152 | int i; | ||
153 | |||
154 | for (i = 0; i < ARRAY_SIZE(priv->leds); i++) { | ||
155 | if (priv->leds[i].registered) { | ||
156 | priv->leds[i].registered = false; | ||
157 | priv->leds[i].toggled = 0; | ||
158 | led_classdev_unregister(&priv->leds[i].led_dev); | ||
159 | } | ||
160 | } | ||
161 | |||
162 | cancel_delayed_work_sync(&priv->led_work); | ||
163 | } | ||