aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/ath5k/led.c
diff options
context:
space:
mode:
authorBob Copeland <me@bobcopeland.com>2009-03-08 00:10:20 -0500
committerJohn W. Linville <linville@tuxdriver.com>2009-03-16 18:09:37 -0400
commit0ed4548f81b69363a6257dbc23086fc9fe4a23cb (patch)
treea7513ef6461534124bca54ee0e33f2d57438642b /drivers/net/wireless/ath5k/led.c
parent8d6c39efed5987d3c1ade96e93753125a099f512 (diff)
ath5k: extract LED code into a separate file
Move LED code out of base.c for clarity. Changes-licensed-under: 3-Clause-BSD Signed-off-by: Bob Copeland <me@bobcopeland.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'drivers/net/wireless/ath5k/led.c')
-rw-r--r--drivers/net/wireless/ath5k/led.c169
1 files changed, 169 insertions, 0 deletions
diff --git a/drivers/net/wireless/ath5k/led.c b/drivers/net/wireless/ath5k/led.c
new file mode 100644
index 000000000000..7cef2bb408df
--- /dev/null
+++ b/drivers/net/wireless/ath5k/led.c
@@ -0,0 +1,169 @@
1/*
2 * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
3 * Copyright (c) 2004-2005 Atheros Communications, Inc.
4 * Copyright (c) 2007 Jiri Slaby <jirislaby@gmail.com>
5 * Copyright (c) 2009 Bob Copeland <me@bobcopeland.com>
6 *
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer,
14 * without modification.
15 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
16 * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
17 * redistribution must be conditioned upon including a substantially
18 * similar Disclaimer requirement for further binary redistribution.
19 * 3. Neither the names of the above-listed copyright holders nor the names
20 * of any contributors may be used to endorse or promote products derived
21 * from this software without specific prior written permission.
22 *
23 * Alternatively, this software may be distributed under the terms of the
24 * GNU General Public License ("GPL") version 2 as published by the Free
25 * Software Foundation.
26 *
27 * NO WARRANTY
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
31 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
32 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
33 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
36 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
38 * THE POSSIBILITY OF SUCH DAMAGES.
39 *
40 */
41
42#include <linux/pci.h>
43#include "ath5k.h"
44#include "base.h"
45
46void ath5k_led_enable(struct ath5k_softc *sc)
47{
48 if (test_bit(ATH_STAT_LEDSOFT, sc->status)) {
49 ath5k_hw_set_gpio_output(sc->ah, sc->led_pin);
50 ath5k_led_off(sc);
51 }
52}
53
54void ath5k_led_on(struct ath5k_softc *sc)
55{
56 if (!test_bit(ATH_STAT_LEDSOFT, sc->status))
57 return;
58 ath5k_hw_set_gpio(sc->ah, sc->led_pin, sc->led_on);
59}
60
61void ath5k_led_off(struct ath5k_softc *sc)
62{
63 if (!test_bit(ATH_STAT_LEDSOFT, sc->status))
64 return;
65 ath5k_hw_set_gpio(sc->ah, sc->led_pin, !sc->led_on);
66}
67
68static void
69ath5k_led_brightness_set(struct led_classdev *led_dev,
70 enum led_brightness brightness)
71{
72 struct ath5k_led *led = container_of(led_dev, struct ath5k_led,
73 led_dev);
74
75 if (brightness == LED_OFF)
76 ath5k_led_off(led->sc);
77 else
78 ath5k_led_on(led->sc);
79}
80
81static int
82ath5k_register_led(struct ath5k_softc *sc, struct ath5k_led *led,
83 const char *name, char *trigger)
84{
85 int err;
86
87 led->sc = sc;
88 strncpy(led->name, name, sizeof(led->name));
89 led->led_dev.name = led->name;
90 led->led_dev.default_trigger = trigger;
91 led->led_dev.brightness_set = ath5k_led_brightness_set;
92
93 err = led_classdev_register(&sc->pdev->dev, &led->led_dev);
94 if (err) {
95 ATH5K_WARN(sc, "could not register LED %s\n", name);
96 led->sc = NULL;
97 }
98 return err;
99}
100
101static void
102ath5k_unregister_led(struct ath5k_led *led)
103{
104 if (!led->sc)
105 return;
106 led_classdev_unregister(&led->led_dev);
107 ath5k_led_off(led->sc);
108 led->sc = NULL;
109}
110
111void ath5k_unregister_leds(struct ath5k_softc *sc)
112{
113 ath5k_unregister_led(&sc->rx_led);
114 ath5k_unregister_led(&sc->tx_led);
115}
116
117
118int ath5k_init_leds(struct ath5k_softc *sc)
119{
120 int ret = 0;
121 struct ieee80211_hw *hw = sc->hw;
122 struct pci_dev *pdev = sc->pdev;
123 char name[ATH5K_LED_MAX_NAME_LEN + 1];
124
125 /*
126 * Auto-enable soft led processing for IBM cards and for
127 * 5211 minipci cards.
128 */
129 if (pdev->device == PCI_DEVICE_ID_ATHEROS_AR5212_IBM ||
130 pdev->device == PCI_DEVICE_ID_ATHEROS_AR5211) {
131 __set_bit(ATH_STAT_LEDSOFT, sc->status);
132 sc->led_pin = 0;
133 sc->led_on = 0; /* active low */
134 }
135 /* Enable softled on PIN1 on HP Compaq nc6xx, nc4000 & nx5000 laptops */
136 if (pdev->subsystem_vendor == PCI_VENDOR_ID_COMPAQ) {
137 __set_bit(ATH_STAT_LEDSOFT, sc->status);
138 sc->led_pin = 1;
139 sc->led_on = 1; /* active high */
140 }
141 /*
142 * Pin 3 on Foxconn chips used in Acer Aspire One (0x105b:e008) and
143 * in emachines notebooks with AMBIT subsystem.
144 */
145 if (pdev->subsystem_vendor == PCI_VENDOR_ID_FOXCONN ||
146 pdev->subsystem_vendor == PCI_VENDOR_ID_AMBIT) {
147 __set_bit(ATH_STAT_LEDSOFT, sc->status);
148 sc->led_pin = 3;
149 sc->led_on = 0; /* active low */
150 }
151
152 if (!test_bit(ATH_STAT_LEDSOFT, sc->status))
153 goto out;
154
155 ath5k_led_enable(sc);
156
157 snprintf(name, sizeof(name), "ath5k-%s::rx", wiphy_name(hw->wiphy));
158 ret = ath5k_register_led(sc, &sc->rx_led, name,
159 ieee80211_get_rx_led_name(hw));
160 if (ret)
161 goto out;
162
163 snprintf(name, sizeof(name), "ath5k-%s::tx", wiphy_name(hw->wiphy));
164 ret = ath5k_register_led(sc, &sc->tx_led, name,
165 ieee80211_get_tx_led_name(hw));
166out:
167 return ret;
168}
169