This source file includes following definitions.
- ath5k_led_enable
- ath5k_led_on
- ath5k_led_off
- ath5k_led_brightness_set
- ath5k_register_led
- ath5k_unregister_led
- ath5k_unregister_leds
- ath5k_init_leds
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 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
43
44 #include <linux/pci.h>
45 #include "ath5k.h"
46
47 #define ATH_SDEVICE(subv, subd) \
48 .vendor = PCI_ANY_ID, .device = PCI_ANY_ID, \
49 .subvendor = (subv), .subdevice = (subd)
50
51 #define ATH_LED(pin, polarity) .driver_data = (((pin) << 8) | (polarity))
52 #define ATH_PIN(data) ((data) >> 8)
53 #define ATH_POLARITY(data) ((data) & 0xff)
54
55
56 static const struct pci_device_id ath5k_led_devices[] = {
57
58 { PCI_VDEVICE(ATHEROS, PCI_DEVICE_ID_ATHEROS_AR5211), ATH_LED(0, 0) },
59
60 { ATH_SDEVICE(PCI_VENDOR_ID_COMPAQ, PCI_ANY_ID), ATH_LED(1, 1) },
61
62 { ATH_SDEVICE(PCI_VENDOR_ID_FOXCONN, 0xe008), ATH_LED(3, 0) },
63
64 { ATH_SDEVICE(PCI_VENDOR_ID_FOXCONN, 0xe00d), ATH_LED(3, 0) },
65
66 { ATH_SDEVICE(PCI_VENDOR_ID_AMBIT, 0x0422), ATH_LED(1, 1) },
67
68 { ATH_SDEVICE(PCI_VENDOR_ID_AMBIT, 0x0428), ATH_LED(3, 0) },
69
70 { ATH_SDEVICE(PCI_VENDOR_ID_QMI, 0x0100), ATH_LED(1, 0) },
71
72 { ATH_SDEVICE(PCI_VENDOR_ID_QMI, 0x0105), ATH_LED(3, 0) },
73
74 { ATH_SDEVICE(PCI_VENDOR_ID_AZWAVE, 0x1026), ATH_LED(3, 0) },
75
76 { ATH_SDEVICE(PCI_VENDOR_ID_IBM, 0x058a), ATH_LED(1, 0) },
77
78 { ATH_SDEVICE(PCI_VENDOR_ID_HP, 0x0137a), ATH_LED(3, 1) },
79
80 { ATH_SDEVICE(PCI_VENDOR_ID_HP, 0x0137b), ATH_LED(3, 0) },
81
82 { ATH_SDEVICE(PCI_VENDOR_ID_ATHEROS, 0x3067), ATH_LED(3, 0) },
83
84 { PCI_VDEVICE(ATHEROS, PCI_DEVICE_ID_ATHEROS_AR5212_IBM), ATH_LED(0, 0) },
85
86 { ATH_SDEVICE(PCI_VENDOR_ID_QMI, 0x0112), ATH_LED(3, 0) },
87 { }
88 };
89
90 void ath5k_led_enable(struct ath5k_hw *ah)
91 {
92 if (test_bit(ATH_STAT_LEDSOFT, ah->status)) {
93 ath5k_hw_set_gpio_output(ah, ah->led_pin);
94 ath5k_led_off(ah);
95 }
96 }
97
98 static void ath5k_led_on(struct ath5k_hw *ah)
99 {
100 if (!test_bit(ATH_STAT_LEDSOFT, ah->status))
101 return;
102 ath5k_hw_set_gpio(ah, ah->led_pin, ah->led_on);
103 }
104
105 void ath5k_led_off(struct ath5k_hw *ah)
106 {
107 if (!test_bit(ATH_STAT_LEDSOFT, ah->status))
108 return;
109 ath5k_hw_set_gpio(ah, ah->led_pin, !ah->led_on);
110 }
111
112 static void
113 ath5k_led_brightness_set(struct led_classdev *led_dev,
114 enum led_brightness brightness)
115 {
116 struct ath5k_led *led = container_of(led_dev, struct ath5k_led,
117 led_dev);
118
119 if (brightness == LED_OFF)
120 ath5k_led_off(led->ah);
121 else
122 ath5k_led_on(led->ah);
123 }
124
125 static int
126 ath5k_register_led(struct ath5k_hw *ah, struct ath5k_led *led,
127 const char *name, const char *trigger)
128 {
129 int err;
130
131 led->ah = ah;
132 strncpy(led->name, name, sizeof(led->name));
133 led->name[sizeof(led->name)-1] = 0;
134 led->led_dev.name = led->name;
135 led->led_dev.default_trigger = trigger;
136 led->led_dev.brightness_set = ath5k_led_brightness_set;
137
138 err = led_classdev_register(ah->dev, &led->led_dev);
139 if (err) {
140 ATH5K_WARN(ah, "could not register LED %s\n", name);
141 led->ah = NULL;
142 }
143 return err;
144 }
145
146 static void
147 ath5k_unregister_led(struct ath5k_led *led)
148 {
149 if (!led->ah)
150 return;
151 led_classdev_unregister(&led->led_dev);
152 ath5k_led_off(led->ah);
153 led->ah = NULL;
154 }
155
156 void ath5k_unregister_leds(struct ath5k_hw *ah)
157 {
158 ath5k_unregister_led(&ah->rx_led);
159 ath5k_unregister_led(&ah->tx_led);
160 }
161
162 int ath5k_init_leds(struct ath5k_hw *ah)
163 {
164 int ret = 0;
165 struct ieee80211_hw *hw = ah->hw;
166 #ifndef CONFIG_ATH5K_AHB
167 struct pci_dev *pdev = ah->pdev;
168 #endif
169 char name[ATH5K_LED_MAX_NAME_LEN + 1];
170 const struct pci_device_id *match;
171
172 if (!ah->pdev)
173 return 0;
174
175 #ifdef CONFIG_ATH5K_AHB
176 match = NULL;
177 #else
178 match = pci_match_id(&ath5k_led_devices[0], pdev);
179 #endif
180 if (match) {
181 __set_bit(ATH_STAT_LEDSOFT, ah->status);
182 ah->led_pin = ATH_PIN(match->driver_data);
183 ah->led_on = ATH_POLARITY(match->driver_data);
184 }
185
186 if (!test_bit(ATH_STAT_LEDSOFT, ah->status))
187 goto out;
188
189 ath5k_led_enable(ah);
190
191 snprintf(name, sizeof(name), "ath5k-%s::rx", wiphy_name(hw->wiphy));
192 ret = ath5k_register_led(ah, &ah->rx_led, name,
193 ieee80211_get_rx_led_name(hw));
194 if (ret)
195 goto out;
196
197 snprintf(name, sizeof(name), "ath5k-%s::tx", wiphy_name(hw->wiphy));
198 ret = ath5k_register_led(ah, &ah->tx_led, name,
199 ieee80211_get_tx_led_name(hw));
200 out:
201 return ret;
202 }
203