1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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
55static const struct pci_device_id ath5k_led_devices[] = {
56
57 { PCI_VDEVICE(ATHEROS, PCI_DEVICE_ID_ATHEROS_AR5211), ATH_LED(0, 0) },
58
59 { ATH_SDEVICE(PCI_VENDOR_ID_COMPAQ, PCI_ANY_ID), ATH_LED(1, 1) },
60
61 { ATH_SDEVICE(PCI_VENDOR_ID_FOXCONN, 0xe008), ATH_LED(3, 0) },
62
63 { ATH_SDEVICE(PCI_VENDOR_ID_FOXCONN, 0xe00d), ATH_LED(3, 0) },
64
65 { ATH_SDEVICE(PCI_VENDOR_ID_AMBIT, 0x0422), ATH_LED(1, 1) },
66
67 { ATH_SDEVICE(PCI_VENDOR_ID_AMBIT, 0x0428), ATH_LED(3, 0) },
68
69 { ATH_SDEVICE(PCI_VENDOR_ID_QMI, 0x0100), ATH_LED(1, 0) },
70
71 { ATH_SDEVICE(PCI_VENDOR_ID_QMI, 0x0105), ATH_LED(3, 0) },
72
73 { ATH_SDEVICE(PCI_VENDOR_ID_AZWAVE, 0x1026), ATH_LED(3, 0) },
74
75 { ATH_SDEVICE(PCI_VENDOR_ID_IBM, 0x058a), ATH_LED(1, 0) },
76
77 { ATH_SDEVICE(PCI_VENDOR_ID_HP, 0x0137a), ATH_LED(3, 1) },
78
79 { ATH_SDEVICE(PCI_VENDOR_ID_HP, 0x0137b), ATH_LED(3, 1) },
80
81 { ATH_SDEVICE(PCI_VENDOR_ID_ATHEROS, 0x3067), ATH_LED(3, 0) },
82
83 { PCI_VDEVICE(ATHEROS, PCI_DEVICE_ID_ATHEROS_AR5212_IBM), ATH_LED(0, 0) },
84
85 { ATH_SDEVICE(PCI_VENDOR_ID_QMI, 0x0112), ATH_LED(3, 0) },
86 { }
87};
88
89void ath5k_led_enable(struct ath5k_softc *sc)
90{
91 if (test_bit(ATH_STAT_LEDSOFT, sc->status)) {
92 ath5k_hw_set_gpio_output(sc->ah, sc->led_pin);
93 ath5k_led_off(sc);
94 }
95}
96
97static void ath5k_led_on(struct ath5k_softc *sc)
98{
99 if (!test_bit(ATH_STAT_LEDSOFT, sc->status))
100 return;
101 ath5k_hw_set_gpio(sc->ah, sc->led_pin, sc->led_on);
102}
103
104void ath5k_led_off(struct ath5k_softc *sc)
105{
106 if (!test_bit(ATH_STAT_LEDSOFT, sc->status))
107 return;
108 ath5k_hw_set_gpio(sc->ah, sc->led_pin, !sc->led_on);
109}
110
111static void
112ath5k_led_brightness_set(struct led_classdev *led_dev,
113 enum led_brightness brightness)
114{
115 struct ath5k_led *led = container_of(led_dev, struct ath5k_led,
116 led_dev);
117
118 if (brightness == LED_OFF)
119 ath5k_led_off(led->sc);
120 else
121 ath5k_led_on(led->sc);
122}
123
124static int
125ath5k_register_led(struct ath5k_softc *sc, struct ath5k_led *led,
126 const char *name, char *trigger)
127{
128 int err;
129
130 led->sc = sc;
131 strncpy(led->name, name, sizeof(led->name));
132 led->led_dev.name = led->name;
133 led->led_dev.default_trigger = trigger;
134 led->led_dev.brightness_set = ath5k_led_brightness_set;
135
136 err = led_classdev_register(sc->dev, &led->led_dev);
137 if (err) {
138 ATH5K_WARN(sc, "could not register LED %s\n", name);
139 led->sc = NULL;
140 }
141 return err;
142}
143
144static void
145ath5k_unregister_led(struct ath5k_led *led)
146{
147 if (!led->sc)
148 return;
149 led_classdev_unregister(&led->led_dev);
150 ath5k_led_off(led->sc);
151 led->sc = NULL;
152}
153
154void ath5k_unregister_leds(struct ath5k_softc *sc)
155{
156 ath5k_unregister_led(&sc->rx_led);
157 ath5k_unregister_led(&sc->tx_led);
158}
159
160int ath5k_init_leds(struct ath5k_softc *sc)
161{
162 int ret = 0;
163 struct ieee80211_hw *hw = sc->hw;
164#ifndef CONFIG_ATHEROS_AR231X
165 struct pci_dev *pdev = sc->pdev;
166#endif
167 char name[ATH5K_LED_MAX_NAME_LEN + 1];
168 const struct pci_device_id *match;
169
170 if (!sc->pdev)
171 return 0;
172
173#ifdef CONFIG_ATHEROS_AR231X
174 match = NULL;
175#else
176 match = pci_match_id(&ath5k_led_devices[0], pdev);
177#endif
178 if (match) {
179 __set_bit(ATH_STAT_LEDSOFT, sc->status);
180 sc->led_pin = ATH_PIN(match->driver_data);
181 sc->led_on = ATH_POLARITY(match->driver_data);
182 }
183
184 if (!test_bit(ATH_STAT_LEDSOFT, sc->status))
185 goto out;
186
187 ath5k_led_enable(sc);
188
189 snprintf(name, sizeof(name), "ath5k-%s::rx", wiphy_name(hw->wiphy));
190 ret = ath5k_register_led(sc, &sc->rx_led, name,
191 ieee80211_get_rx_led_name(hw));
192 if (ret)
193 goto out;
194
195 snprintf(name, sizeof(name), "ath5k-%s::tx", wiphy_name(hw->wiphy));
196 ret = ath5k_register_led(sc, &sc->tx_led, name,
197 ieee80211_get_tx_led_name(hw));
198out:
199 return ret;
200}
201
202