blob: 8c17a00f7dad64ccd3756f54566b9dc187749820 [file] [log] [blame]
Bob Copeland0ed45482009-03-08 00:10:20 -05001/*
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
Pavel Roskine4bbf2f2011-07-07 18:14:13 -040046#define ATH_SDEVICE(subv, subd) \
Bob Copelandcdb02dc2009-03-08 00:10:21 -050047 .vendor = PCI_ANY_ID, .device = PCI_ANY_ID, \
48 .subvendor = (subv), .subdevice = (subd)
49
Pavel Roskine4bbf2f2011-07-07 18:14:13 -040050#define ATH_LED(pin, polarity) .driver_data = (((pin) << 8) | (polarity))
Bob Copelandcdb02dc2009-03-08 00:10:21 -050051#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) */
Pavel Roskin25380d82011-07-07 18:13:42 -040055static DEFINE_PCI_DEVICE_TABLE(ath5k_led_devices) = {
Bob Copelandcdb02dc2009-03-08 00:10:21 -050056 /* AR5211 */
57 { PCI_VDEVICE(ATHEROS, PCI_DEVICE_ID_ATHEROS_AR5211), ATH_LED(0, 0) },
58 /* HP Compaq nc6xx, nc4000, nx6000 */
59 { ATH_SDEVICE(PCI_VENDOR_ID_COMPAQ, PCI_ANY_ID), ATH_LED(1, 1) },
60 /* Acer Aspire One A150 (maximlevitsky@gmail.com) */
Bob Copeland22e5b0852009-03-08 00:10:22 -050061 { ATH_SDEVICE(PCI_VENDOR_ID_FOXCONN, 0xe008), ATH_LED(3, 0) },
Keng-Yu Lin77c82582009-11-05 11:21:37 +080062 /* Acer Aspire One AO531h AO751h (keng-yu.lin@canonical.com) */
63 { ATH_SDEVICE(PCI_VENDOR_ID_FOXCONN, 0xe00d), ATH_LED(3, 0) },
Bob Copeland22e5b0852009-03-08 00:10:22 -050064 /* Acer Ferrari 5000 (russ.dill@gmail.com) */
65 { ATH_SDEVICE(PCI_VENDOR_ID_AMBIT, 0x0422), ATH_LED(1, 1) },
Bob Copelandcdb02dc2009-03-08 00:10:21 -050066 /* E-machines E510 (tuliom@gmail.com) */
Bob Copeland22e5b0852009-03-08 00:10:22 -050067 { ATH_SDEVICE(PCI_VENDOR_ID_AMBIT, 0x0428), ATH_LED(3, 0) },
Bob Copeland1e93bd42009-11-08 21:59:02 -050068 /* BenQ Joybook R55v (nowymarluk@wp.pl) */
69 { ATH_SDEVICE(PCI_VENDOR_ID_QMI, 0x0100), ATH_LED(1, 0) },
Tulio Magno Quites Machado Filhoaf83deb2009-03-22 01:41:13 +010070 /* Acer Extensa 5620z (nekoreeve@gmail.com) */
71 { ATH_SDEVICE(PCI_VENDOR_ID_QMI, 0x0105), ATH_LED(3, 0) },
Bob Copeland6a362bb2009-04-05 11:01:20 -040072 /* Fukato Datacask Jupiter 1014a (mrb74@gmx.at) */
73 { ATH_SDEVICE(PCI_VENDOR_ID_AZWAVE, 0x1026), ATH_LED(3, 0) },
Paride Legovini84379cb2009-04-30 15:55:52 -040074 /* IBM ThinkPad AR5BXB6 (legovini@spiro.fisica.unipd.it) */
75 { ATH_SDEVICE(PCI_VENDOR_ID_IBM, 0x058a), ATH_LED(1, 0) },
Bob Copeland6f9797a2009-11-08 21:59:01 -050076 /* HP Compaq CQ60-206US (ddreggors@jumptv.com) */
77 { ATH_SDEVICE(PCI_VENDOR_ID_HP, 0x0137a), ATH_LED(3, 1) },
Marcos Chaparro09c9bae2009-08-24 23:00:31 -040078 /* HP Compaq C700 (nitrousnrg@gmail.com) */
79 { ATH_SDEVICE(PCI_VENDOR_ID_HP, 0x0137b), ATH_LED(3, 1) },
Luca Verdesca47db3a62009-12-22 18:10:01 +010080 /* LiteOn AR5BXB63 (magooz@salug.it) */
81 { ATH_SDEVICE(PCI_VENDOR_ID_ATHEROS, 0x3067), ATH_LED(3, 0) },
Paride Legovini84379cb2009-04-30 15:55:52 -040082 /* IBM-specific AR5212 (all others) */
83 { PCI_VDEVICE(ATHEROS, PCI_DEVICE_ID_ATHEROS_AR5212_IBM), ATH_LED(0, 0) },
Shahar Or6a213af2009-12-07 12:05:54 +020084 /* Dell Vostro A860 (shahar@shahar-or.co.il) */
85 { ATH_SDEVICE(PCI_VENDOR_ID_QMI, 0x0112), ATH_LED(3, 0) },
Bob Copelandcdb02dc2009-03-08 00:10:21 -050086 { }
87};
88
Pavel Roskine0d687b2011-07-14 20:21:55 -040089void ath5k_led_enable(struct ath5k_hw *ah)
Bob Copeland0ed45482009-03-08 00:10:20 -050090{
Pavel Roskine0d687b2011-07-14 20:21:55 -040091 if (test_bit(ATH_STAT_LEDSOFT, ah->status)) {
92 ath5k_hw_set_gpio_output(ah, ah->led_pin);
93 ath5k_led_off(ah);
Bob Copeland0ed45482009-03-08 00:10:20 -050094 }
95}
96
Pavel Roskine0d687b2011-07-14 20:21:55 -040097static void ath5k_led_on(struct ath5k_hw *ah)
Bob Copeland0ed45482009-03-08 00:10:20 -050098{
Pavel Roskine0d687b2011-07-14 20:21:55 -040099 if (!test_bit(ATH_STAT_LEDSOFT, ah->status))
Bob Copeland0ed45482009-03-08 00:10:20 -0500100 return;
Pavel Roskine0d687b2011-07-14 20:21:55 -0400101 ath5k_hw_set_gpio(ah, ah->led_pin, ah->led_on);
Bob Copeland0ed45482009-03-08 00:10:20 -0500102}
103
Pavel Roskine0d687b2011-07-14 20:21:55 -0400104void ath5k_led_off(struct ath5k_hw *ah)
Bob Copeland0ed45482009-03-08 00:10:20 -0500105{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400106 if (!test_bit(ATH_STAT_LEDSOFT, ah->status))
Bob Copeland0ed45482009-03-08 00:10:20 -0500107 return;
Pavel Roskine0d687b2011-07-14 20:21:55 -0400108 ath5k_hw_set_gpio(ah, ah->led_pin, !ah->led_on);
Bob Copeland0ed45482009-03-08 00:10:20 -0500109}
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)
Pavel Roskine0d687b2011-07-14 20:21:55 -0400119 ath5k_led_off(led->ah);
Bob Copeland0ed45482009-03-08 00:10:20 -0500120 else
Pavel Roskine0d687b2011-07-14 20:21:55 -0400121 ath5k_led_on(led->ah);
Bob Copeland0ed45482009-03-08 00:10:20 -0500122}
123
124static int
Pavel Roskine0d687b2011-07-14 20:21:55 -0400125ath5k_register_led(struct ath5k_hw *ah, struct ath5k_led *led,
Bob Copeland0ed45482009-03-08 00:10:20 -0500126 const char *name, char *trigger)
127{
128 int err;
129
Pavel Roskine0d687b2011-07-14 20:21:55 -0400130 led->ah = ah;
Bob Copeland0ed45482009-03-08 00:10:20 -0500131 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
Pavel Roskine0d687b2011-07-14 20:21:55 -0400136 err = led_classdev_register(ah->dev, &led->led_dev);
Bob Copeland0ed45482009-03-08 00:10:20 -0500137 if (err) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400138 ATH5K_WARN(ah, "could not register LED %s\n", name);
139 led->ah = NULL;
Bob Copeland0ed45482009-03-08 00:10:20 -0500140 }
141 return err;
142}
143
144static void
145ath5k_unregister_led(struct ath5k_led *led)
146{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400147 if (!led->ah)
Bob Copeland0ed45482009-03-08 00:10:20 -0500148 return;
149 led_classdev_unregister(&led->led_dev);
Pavel Roskine0d687b2011-07-14 20:21:55 -0400150 ath5k_led_off(led->ah);
151 led->ah = NULL;
Bob Copeland0ed45482009-03-08 00:10:20 -0500152}
153
Pavel Roskine0d687b2011-07-14 20:21:55 -0400154void ath5k_unregister_leds(struct ath5k_hw *ah)
Bob Copeland0ed45482009-03-08 00:10:20 -0500155{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400156 ath5k_unregister_led(&ah->rx_led);
157 ath5k_unregister_led(&ah->tx_led);
Bob Copeland0ed45482009-03-08 00:10:20 -0500158}
159
Pavel Roskine0d687b2011-07-14 20:21:55 -0400160int __devinit ath5k_init_leds(struct ath5k_hw *ah)
Bob Copeland0ed45482009-03-08 00:10:20 -0500161{
162 int ret = 0;
Pavel Roskine0d687b2011-07-14 20:21:55 -0400163 struct ieee80211_hw *hw = ah->hw;
Felix Fietkaua0b907e2010-12-02 10:27:16 +0100164#ifndef CONFIG_ATHEROS_AR231X
Pavel Roskine0d687b2011-07-14 20:21:55 -0400165 struct pci_dev *pdev = ah->pdev;
Felix Fietkaua0b907e2010-12-02 10:27:16 +0100166#endif
Bob Copeland0ed45482009-03-08 00:10:20 -0500167 char name[ATH5K_LED_MAX_NAME_LEN + 1];
Bob Copelandcdb02dc2009-03-08 00:10:21 -0500168 const struct pci_device_id *match;
Bob Copeland0ed45482009-03-08 00:10:20 -0500169
Pavel Roskine0d687b2011-07-14 20:21:55 -0400170 if (!ah->pdev)
Felix Fietkau8efa5d72010-12-02 10:27:06 +0100171 return 0;
172
Felix Fietkaua0b907e2010-12-02 10:27:16 +0100173#ifdef CONFIG_ATHEROS_AR231X
174 match = NULL;
175#else
Bob Copelandcdb02dc2009-03-08 00:10:21 -0500176 match = pci_match_id(&ath5k_led_devices[0], pdev);
Felix Fietkaua0b907e2010-12-02 10:27:16 +0100177#endif
Bob Copelandcdb02dc2009-03-08 00:10:21 -0500178 if (match) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400179 __set_bit(ATH_STAT_LEDSOFT, ah->status);
180 ah->led_pin = ATH_PIN(match->driver_data);
181 ah->led_on = ATH_POLARITY(match->driver_data);
Bob Copeland0ed45482009-03-08 00:10:20 -0500182 }
183
Pavel Roskine0d687b2011-07-14 20:21:55 -0400184 if (!test_bit(ATH_STAT_LEDSOFT, ah->status))
Bob Copeland0ed45482009-03-08 00:10:20 -0500185 goto out;
186
Pavel Roskine0d687b2011-07-14 20:21:55 -0400187 ath5k_led_enable(ah);
Bob Copeland0ed45482009-03-08 00:10:20 -0500188
189 snprintf(name, sizeof(name), "ath5k-%s::rx", wiphy_name(hw->wiphy));
Pavel Roskine0d687b2011-07-14 20:21:55 -0400190 ret = ath5k_register_led(ah, &ah->rx_led, name,
Bob Copeland0ed45482009-03-08 00:10:20 -0500191 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));
Pavel Roskine0d687b2011-07-14 20:21:55 -0400196 ret = ath5k_register_led(ah, &ah->tx_led, name,
Bob Copeland0ed45482009-03-08 00:10:20 -0500197 ieee80211_get_tx_led_name(hw));
198out:
199 return ret;
200}
201