diff options
author | Luis R. Rodriguez <lrodriguez@atheros.com> | 2009-03-30 22:30:33 -0400 |
---|---|---|
committer | John W. Linville <linville@tuxdriver.com> | 2009-04-22 16:54:38 -0400 |
commit | 203c4805e91786f9a010bc7945a0fde70c9da28e (patch) | |
tree | 00415276b2fe65713f066ffe07b11ad2d8b6bea8 /drivers/net/wireless/ath/ath5k/led.c | |
parent | 1878f77e13b9d720b78c4f818b94bfd4a7f596e5 (diff) |
atheros: put atheros wireless drivers into ath/
Signed-off-by: Luis R. Rodriguez <lrodriguez@atheros.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'drivers/net/wireless/ath/ath5k/led.c')
-rw-r--r-- | drivers/net/wireless/ath/ath5k/led.c | 176 |
1 files changed, 176 insertions, 0 deletions
diff --git a/drivers/net/wireless/ath/ath5k/led.c b/drivers/net/wireless/ath/ath5k/led.c new file mode 100644 index 00000000000..19555fb79c9 --- /dev/null +++ b/drivers/net/wireless/ath/ath5k/led.c | |||
@@ -0,0 +1,176 @@ | |||
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 | |||
46 | #define ATH_SDEVICE(subv,subd) \ | ||
47 | .vendor = PCI_ANY_ID, .device = PCI_ANY_ID, \ | ||
48 | .subvendor = (subv), .subdevice = (subd) | ||
49 | |||
50 | #define ATH_LED(pin,polarity) .driver_data = (((pin) << 8) | (polarity)) | ||
51 | #define ATH_PIN(data) ((data) >> 8) | ||
52 | #define ATH_POLARITY(data) ((data) & 0xff) | ||
53 | |||
54 | /* Devices we match on for LED config info (typically laptops) */ | ||
55 | static const struct pci_device_id ath5k_led_devices[] = { | ||
56 | /* IBM-specific AR5212 */ | ||
57 | { PCI_VDEVICE(ATHEROS, PCI_DEVICE_ID_ATHEROS_AR5212_IBM), ATH_LED(0, 0) }, | ||
58 | /* AR5211 */ | ||
59 | { PCI_VDEVICE(ATHEROS, PCI_DEVICE_ID_ATHEROS_AR5211), ATH_LED(0, 0) }, | ||
60 | /* HP Compaq nc6xx, nc4000, nx6000 */ | ||
61 | { ATH_SDEVICE(PCI_VENDOR_ID_COMPAQ, PCI_ANY_ID), ATH_LED(1, 1) }, | ||
62 | /* Acer Aspire One A150 (maximlevitsky@gmail.com) */ | ||
63 | { ATH_SDEVICE(PCI_VENDOR_ID_FOXCONN, 0xe008), ATH_LED(3, 0) }, | ||
64 | /* Acer Ferrari 5000 (russ.dill@gmail.com) */ | ||
65 | { ATH_SDEVICE(PCI_VENDOR_ID_AMBIT, 0x0422), ATH_LED(1, 1) }, | ||
66 | /* E-machines E510 (tuliom@gmail.com) */ | ||
67 | { ATH_SDEVICE(PCI_VENDOR_ID_AMBIT, 0x0428), ATH_LED(3, 0) }, | ||
68 | /* Acer Extensa 5620z (nekoreeve@gmail.com) */ | ||
69 | { ATH_SDEVICE(PCI_VENDOR_ID_QMI, 0x0105), ATH_LED(3, 0) }, | ||
70 | { } | ||
71 | }; | ||
72 | |||
73 | void ath5k_led_enable(struct ath5k_softc *sc) | ||
74 | { | ||
75 | if (test_bit(ATH_STAT_LEDSOFT, sc->status)) { | ||
76 | ath5k_hw_set_gpio_output(sc->ah, sc->led_pin); | ||
77 | ath5k_led_off(sc); | ||
78 | } | ||
79 | } | ||
80 | |||
81 | void ath5k_led_on(struct ath5k_softc *sc) | ||
82 | { | ||
83 | if (!test_bit(ATH_STAT_LEDSOFT, sc->status)) | ||
84 | return; | ||
85 | ath5k_hw_set_gpio(sc->ah, sc->led_pin, sc->led_on); | ||
86 | } | ||
87 | |||
88 | void ath5k_led_off(struct ath5k_softc *sc) | ||
89 | { | ||
90 | if (!test_bit(ATH_STAT_LEDSOFT, sc->status)) | ||
91 | return; | ||
92 | ath5k_hw_set_gpio(sc->ah, sc->led_pin, !sc->led_on); | ||
93 | } | ||
94 | |||
95 | static void | ||
96 | ath5k_led_brightness_set(struct led_classdev *led_dev, | ||
97 | enum led_brightness brightness) | ||
98 | { | ||
99 | struct ath5k_led *led = container_of(led_dev, struct ath5k_led, | ||
100 | led_dev); | ||
101 | |||
102 | if (brightness == LED_OFF) | ||
103 | ath5k_led_off(led->sc); | ||
104 | else | ||
105 | ath5k_led_on(led->sc); | ||
106 | } | ||
107 | |||
108 | static int | ||
109 | ath5k_register_led(struct ath5k_softc *sc, struct ath5k_led *led, | ||
110 | const char *name, char *trigger) | ||
111 | { | ||
112 | int err; | ||
113 | |||
114 | led->sc = sc; | ||
115 | strncpy(led->name, name, sizeof(led->name)); | ||
116 | led->led_dev.name = led->name; | ||
117 | led->led_dev.default_trigger = trigger; | ||
118 | led->led_dev.brightness_set = ath5k_led_brightness_set; | ||
119 | |||
120 | err = led_classdev_register(&sc->pdev->dev, &led->led_dev); | ||
121 | if (err) { | ||
122 | ATH5K_WARN(sc, "could not register LED %s\n", name); | ||
123 | led->sc = NULL; | ||
124 | } | ||
125 | return err; | ||
126 | } | ||
127 | |||
128 | static void | ||
129 | ath5k_unregister_led(struct ath5k_led *led) | ||
130 | { | ||
131 | if (!led->sc) | ||
132 | return; | ||
133 | led_classdev_unregister(&led->led_dev); | ||
134 | ath5k_led_off(led->sc); | ||
135 | led->sc = NULL; | ||
136 | } | ||
137 | |||
138 | void ath5k_unregister_leds(struct ath5k_softc *sc) | ||
139 | { | ||
140 | ath5k_unregister_led(&sc->rx_led); | ||
141 | ath5k_unregister_led(&sc->tx_led); | ||
142 | } | ||
143 | |||
144 | int ath5k_init_leds(struct ath5k_softc *sc) | ||
145 | { | ||
146 | int ret = 0; | ||
147 | struct ieee80211_hw *hw = sc->hw; | ||
148 | struct pci_dev *pdev = sc->pdev; | ||
149 | char name[ATH5K_LED_MAX_NAME_LEN + 1]; | ||
150 | const struct pci_device_id *match; | ||
151 | |||
152 | match = pci_match_id(&ath5k_led_devices[0], pdev); | ||
153 | if (match) { | ||
154 | __set_bit(ATH_STAT_LEDSOFT, sc->status); | ||
155 | sc->led_pin = ATH_PIN(match->driver_data); | ||
156 | sc->led_on = ATH_POLARITY(match->driver_data); | ||
157 | } | ||
158 | |||
159 | if (!test_bit(ATH_STAT_LEDSOFT, sc->status)) | ||
160 | goto out; | ||
161 | |||
162 | ath5k_led_enable(sc); | ||
163 | |||
164 | snprintf(name, sizeof(name), "ath5k-%s::rx", wiphy_name(hw->wiphy)); | ||
165 | ret = ath5k_register_led(sc, &sc->rx_led, name, | ||
166 | ieee80211_get_rx_led_name(hw)); | ||
167 | if (ret) | ||
168 | goto out; | ||
169 | |||
170 | snprintf(name, sizeof(name), "ath5k-%s::tx", wiphy_name(hw->wiphy)); | ||
171 | ret = ath5k_register_led(sc, &sc->tx_led, name, | ||
172 | ieee80211_get_tx_led_name(hw)); | ||
173 | out: | ||
174 | return ret; | ||
175 | } | ||
176 | |||