aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless
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
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')
-rw-r--r--drivers/net/wireless/ath5k/Makefile1
-rw-r--r--drivers/net/wireless/ath5k/ath5k.h6
-rw-r--r--drivers/net/wireless/ath5k/base.c140
-rw-r--r--drivers/net/wireless/ath5k/led.c169
4 files changed, 176 insertions, 140 deletions
diff --git a/drivers/net/wireless/ath5k/Makefile b/drivers/net/wireless/ath5k/Makefile
index 719cfaef7085..84a74c5248e5 100644
--- a/drivers/net/wireless/ath5k/Makefile
+++ b/drivers/net/wireless/ath5k/Makefile
@@ -10,5 +10,6 @@ ath5k-y += phy.o
10ath5k-y += reset.o 10ath5k-y += reset.o
11ath5k-y += attach.o 11ath5k-y += attach.o
12ath5k-y += base.o 12ath5k-y += base.o
13ath5k-y += led.o
13ath5k-$(CONFIG_ATH5K_DEBUG) += debug.o 14ath5k-$(CONFIG_ATH5K_DEBUG) += debug.o
14obj-$(CONFIG_ATH5K) += ath5k.o 15obj-$(CONFIG_ATH5K) += ath5k.o
diff --git a/drivers/net/wireless/ath5k/ath5k.h b/drivers/net/wireless/ath5k/ath5k.h
index b9af2b84c05f..0dc2c7321c8b 100644
--- a/drivers/net/wireless/ath5k/ath5k.h
+++ b/drivers/net/wireless/ath5k/ath5k.h
@@ -1129,6 +1129,12 @@ struct ath5k_hw {
1129extern struct ath5k_hw *ath5k_hw_attach(struct ath5k_softc *sc, u8 mac_version); 1129extern struct ath5k_hw *ath5k_hw_attach(struct ath5k_softc *sc, u8 mac_version);
1130extern void ath5k_hw_detach(struct ath5k_hw *ah); 1130extern void ath5k_hw_detach(struct ath5k_hw *ah);
1131 1131
1132/* LED functions */
1133extern int ath5k_init_leds(struct ath5k_softc *sc);
1134extern void ath5k_led_enable(struct ath5k_softc *sc);
1135extern void ath5k_led_off(struct ath5k_softc *sc);
1136extern void ath5k_unregister_leds(struct ath5k_softc *sc);
1137
1132/* Reset Functions */ 1138/* Reset Functions */
1133extern int ath5k_hw_nic_wakeup(struct ath5k_hw *ah, int flags, bool initial); 1139extern int ath5k_hw_nic_wakeup(struct ath5k_hw *ah, int flags, bool initial);
1134extern int ath5k_hw_reset(struct ath5k_hw *ah, enum nl80211_iftype op_mode, struct ieee80211_channel *channel, bool change_channel); 1140extern int ath5k_hw_reset(struct ath5k_hw *ah, enum nl80211_iftype op_mode, struct ieee80211_channel *channel, bool change_channel);
diff --git a/drivers/net/wireless/ath5k/base.c b/drivers/net/wireless/ath5k/base.c
index f2e5c3936f06..cad3ccf61b00 100644
--- a/drivers/net/wireless/ath5k/base.c
+++ b/drivers/net/wireless/ath5k/base.c
@@ -370,11 +370,6 @@ static irqreturn_t ath5k_intr(int irq, void *dev_id);
370static void ath5k_tasklet_reset(unsigned long data); 370static void ath5k_tasklet_reset(unsigned long data);
371 371
372static void ath5k_calibrate(unsigned long data); 372static void ath5k_calibrate(unsigned long data);
373/* LED functions */
374static int ath5k_init_leds(struct ath5k_softc *sc);
375static void ath5k_led_enable(struct ath5k_softc *sc);
376static void ath5k_led_off(struct ath5k_softc *sc);
377static void ath5k_unregister_leds(struct ath5k_softc *sc);
378 373
379/* 374/*
380 * Module init/exit functions 375 * Module init/exit functions
@@ -2530,141 +2525,6 @@ ath5k_calibrate(unsigned long data)
2530} 2525}
2531 2526
2532 2527
2533
2534/***************\
2535* LED functions *
2536\***************/
2537
2538static void
2539ath5k_led_enable(struct ath5k_softc *sc)
2540{
2541 if (test_bit(ATH_STAT_LEDSOFT, sc->status)) {
2542 ath5k_hw_set_gpio_output(sc->ah, sc->led_pin);
2543 ath5k_led_off(sc);
2544 }
2545}
2546
2547static void
2548ath5k_led_on(struct ath5k_softc *sc)
2549{
2550 if (!test_bit(ATH_STAT_LEDSOFT, sc->status))
2551 return;
2552 ath5k_hw_set_gpio(sc->ah, sc->led_pin, sc->led_on);
2553}
2554
2555static void
2556ath5k_led_off(struct ath5k_softc *sc)
2557{
2558 if (!test_bit(ATH_STAT_LEDSOFT, sc->status))
2559 return;
2560 ath5k_hw_set_gpio(sc->ah, sc->led_pin, !sc->led_on);
2561}
2562
2563static void
2564ath5k_led_brightness_set(struct led_classdev *led_dev,
2565 enum led_brightness brightness)
2566{
2567 struct ath5k_led *led = container_of(led_dev, struct ath5k_led,
2568 led_dev);
2569
2570 if (brightness == LED_OFF)
2571 ath5k_led_off(led->sc);
2572 else
2573 ath5k_led_on(led->sc);
2574}
2575
2576static int
2577ath5k_register_led(struct ath5k_softc *sc, struct ath5k_led *led,
2578 const char *name, char *trigger)
2579{
2580 int err;
2581
2582 led->sc = sc;
2583 strncpy(led->name, name, sizeof(led->name));
2584 led->led_dev.name = led->name;
2585 led->led_dev.default_trigger = trigger;
2586 led->led_dev.brightness_set = ath5k_led_brightness_set;
2587
2588 err = led_classdev_register(&sc->pdev->dev, &led->led_dev);
2589 if (err) {
2590 ATH5K_WARN(sc, "could not register LED %s\n", name);
2591 led->sc = NULL;
2592 }
2593 return err;
2594}
2595
2596static void
2597ath5k_unregister_led(struct ath5k_led *led)
2598{
2599 if (!led->sc)
2600 return;
2601 led_classdev_unregister(&led->led_dev);
2602 ath5k_led_off(led->sc);
2603 led->sc = NULL;
2604}
2605
2606static void
2607ath5k_unregister_leds(struct ath5k_softc *sc)
2608{
2609 ath5k_unregister_led(&sc->rx_led);
2610 ath5k_unregister_led(&sc->tx_led);
2611}
2612
2613
2614static int
2615ath5k_init_leds(struct ath5k_softc *sc)
2616{
2617 int ret = 0;
2618 struct ieee80211_hw *hw = sc->hw;
2619 struct pci_dev *pdev = sc->pdev;
2620 char name[ATH5K_LED_MAX_NAME_LEN + 1];
2621
2622 /*
2623 * Auto-enable soft led processing for IBM cards and for
2624 * 5211 minipci cards.
2625 */
2626 if (pdev->device == PCI_DEVICE_ID_ATHEROS_AR5212_IBM ||
2627 pdev->device == PCI_DEVICE_ID_ATHEROS_AR5211) {
2628 __set_bit(ATH_STAT_LEDSOFT, sc->status);
2629 sc->led_pin = 0;
2630 sc->led_on = 0; /* active low */
2631 }
2632 /* Enable softled on PIN1 on HP Compaq nc6xx, nc4000 & nx5000 laptops */
2633 if (pdev->subsystem_vendor == PCI_VENDOR_ID_COMPAQ) {
2634 __set_bit(ATH_STAT_LEDSOFT, sc->status);
2635 sc->led_pin = 1;
2636 sc->led_on = 1; /* active high */
2637 }
2638 /*
2639 * Pin 3 on Foxconn chips used in Acer Aspire One (0x105b:e008) and
2640 * in emachines notebooks with AMBIT subsystem.
2641 */
2642 if (pdev->subsystem_vendor == PCI_VENDOR_ID_FOXCONN ||
2643 pdev->subsystem_vendor == PCI_VENDOR_ID_AMBIT) {
2644 __set_bit(ATH_STAT_LEDSOFT, sc->status);
2645 sc->led_pin = 3;
2646 sc->led_on = 0; /* active low */
2647 }
2648
2649 if (!test_bit(ATH_STAT_LEDSOFT, sc->status))
2650 goto out;
2651
2652 ath5k_led_enable(sc);
2653
2654 snprintf(name, sizeof(name), "ath5k-%s::rx", wiphy_name(hw->wiphy));
2655 ret = ath5k_register_led(sc, &sc->rx_led, name,
2656 ieee80211_get_rx_led_name(hw));
2657 if (ret)
2658 goto out;
2659
2660 snprintf(name, sizeof(name), "ath5k-%s::tx", wiphy_name(hw->wiphy));
2661 ret = ath5k_register_led(sc, &sc->tx_led, name,
2662 ieee80211_get_tx_led_name(hw));
2663out:
2664 return ret;
2665}
2666
2667
2668/********************\ 2528/********************\
2669* Mac80211 functions * 2529* Mac80211 functions *
2670\********************/ 2530\********************/
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