Bob Copeland | 0ed4548 | 2009-03-08 00:10:20 -0500 | [diff] [blame] | 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 | |
Joe Perches | 516304b | 2012-03-18 17:30:52 -0700 | [diff] [blame] | 42 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 43 | |
Bob Copeland | 0ed4548 | 2009-03-08 00:10:20 -0500 | [diff] [blame] | 44 | #include <linux/pci.h> |
| 45 | #include "ath5k.h" |
Bob Copeland | 0ed4548 | 2009-03-08 00:10:20 -0500 | [diff] [blame] | 46 | |
Pavel Roskin | e4bbf2f | 2011-07-07 18:14:13 -0400 | [diff] [blame] | 47 | #define ATH_SDEVICE(subv, subd) \ |
Bob Copeland | cdb02dc | 2009-03-08 00:10:21 -0500 | [diff] [blame] | 48 | .vendor = PCI_ANY_ID, .device = PCI_ANY_ID, \ |
| 49 | .subvendor = (subv), .subdevice = (subd) |
| 50 | |
Pavel Roskin | e4bbf2f | 2011-07-07 18:14:13 -0400 | [diff] [blame] | 51 | #define ATH_LED(pin, polarity) .driver_data = (((pin) << 8) | (polarity)) |
Bob Copeland | cdb02dc | 2009-03-08 00:10:21 -0500 | [diff] [blame] | 52 | #define ATH_PIN(data) ((data) >> 8) |
| 53 | #define ATH_POLARITY(data) ((data) & 0xff) |
| 54 | |
| 55 | /* Devices we match on for LED config info (typically laptops) */ |
Pavel Roskin | 25380d8 | 2011-07-07 18:13:42 -0400 | [diff] [blame] | 56 | static DEFINE_PCI_DEVICE_TABLE(ath5k_led_devices) = { |
Bob Copeland | cdb02dc | 2009-03-08 00:10:21 -0500 | [diff] [blame] | 57 | /* AR5211 */ |
| 58 | { PCI_VDEVICE(ATHEROS, PCI_DEVICE_ID_ATHEROS_AR5211), ATH_LED(0, 0) }, |
| 59 | /* HP Compaq nc6xx, nc4000, nx6000 */ |
| 60 | { ATH_SDEVICE(PCI_VENDOR_ID_COMPAQ, PCI_ANY_ID), ATH_LED(1, 1) }, |
| 61 | /* Acer Aspire One A150 (maximlevitsky@gmail.com) */ |
Bob Copeland | 22e5b085 | 2009-03-08 00:10:22 -0500 | [diff] [blame] | 62 | { ATH_SDEVICE(PCI_VENDOR_ID_FOXCONN, 0xe008), ATH_LED(3, 0) }, |
Keng-Yu Lin | 77c8258 | 2009-11-05 11:21:37 +0800 | [diff] [blame] | 63 | /* Acer Aspire One AO531h AO751h (keng-yu.lin@canonical.com) */ |
| 64 | { ATH_SDEVICE(PCI_VENDOR_ID_FOXCONN, 0xe00d), ATH_LED(3, 0) }, |
Bob Copeland | 22e5b085 | 2009-03-08 00:10:22 -0500 | [diff] [blame] | 65 | /* Acer Ferrari 5000 (russ.dill@gmail.com) */ |
| 66 | { ATH_SDEVICE(PCI_VENDOR_ID_AMBIT, 0x0422), ATH_LED(1, 1) }, |
Bob Copeland | cdb02dc | 2009-03-08 00:10:21 -0500 | [diff] [blame] | 67 | /* E-machines E510 (tuliom@gmail.com) */ |
Bob Copeland | 22e5b085 | 2009-03-08 00:10:22 -0500 | [diff] [blame] | 68 | { ATH_SDEVICE(PCI_VENDOR_ID_AMBIT, 0x0428), ATH_LED(3, 0) }, |
Bob Copeland | 1e93bd4 | 2009-11-08 21:59:02 -0500 | [diff] [blame] | 69 | /* BenQ Joybook R55v (nowymarluk@wp.pl) */ |
| 70 | { ATH_SDEVICE(PCI_VENDOR_ID_QMI, 0x0100), ATH_LED(1, 0) }, |
Tulio Magno Quites Machado Filho | af83deb | 2009-03-22 01:41:13 +0100 | [diff] [blame] | 71 | /* Acer Extensa 5620z (nekoreeve@gmail.com) */ |
| 72 | { ATH_SDEVICE(PCI_VENDOR_ID_QMI, 0x0105), ATH_LED(3, 0) }, |
Bob Copeland | 6a362bb | 2009-04-05 11:01:20 -0400 | [diff] [blame] | 73 | /* Fukato Datacask Jupiter 1014a (mrb74@gmx.at) */ |
| 74 | { ATH_SDEVICE(PCI_VENDOR_ID_AZWAVE, 0x1026), ATH_LED(3, 0) }, |
Paride Legovini | 84379cb | 2009-04-30 15:55:52 -0400 | [diff] [blame] | 75 | /* IBM ThinkPad AR5BXB6 (legovini@spiro.fisica.unipd.it) */ |
| 76 | { ATH_SDEVICE(PCI_VENDOR_ID_IBM, 0x058a), ATH_LED(1, 0) }, |
Bob Copeland | 6f9797a | 2009-11-08 21:59:01 -0500 | [diff] [blame] | 77 | /* HP Compaq CQ60-206US (ddreggors@jumptv.com) */ |
| 78 | { ATH_SDEVICE(PCI_VENDOR_ID_HP, 0x0137a), ATH_LED(3, 1) }, |
Marcos Chaparro | 09c9bae | 2009-08-24 23:00:31 -0400 | [diff] [blame] | 79 | /* HP Compaq C700 (nitrousnrg@gmail.com) */ |
| 80 | { ATH_SDEVICE(PCI_VENDOR_ID_HP, 0x0137b), ATH_LED(3, 1) }, |
Luca Verdesca | 47db3a6 | 2009-12-22 18:10:01 +0100 | [diff] [blame] | 81 | /* LiteOn AR5BXB63 (magooz@salug.it) */ |
| 82 | { ATH_SDEVICE(PCI_VENDOR_ID_ATHEROS, 0x3067), ATH_LED(3, 0) }, |
Paride Legovini | 84379cb | 2009-04-30 15:55:52 -0400 | [diff] [blame] | 83 | /* IBM-specific AR5212 (all others) */ |
| 84 | { PCI_VDEVICE(ATHEROS, PCI_DEVICE_ID_ATHEROS_AR5212_IBM), ATH_LED(0, 0) }, |
Shahar Or | 6a213af | 2009-12-07 12:05:54 +0200 | [diff] [blame] | 85 | /* Dell Vostro A860 (shahar@shahar-or.co.il) */ |
| 86 | { ATH_SDEVICE(PCI_VENDOR_ID_QMI, 0x0112), ATH_LED(3, 0) }, |
Bob Copeland | cdb02dc | 2009-03-08 00:10:21 -0500 | [diff] [blame] | 87 | { } |
| 88 | }; |
| 89 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 90 | void ath5k_led_enable(struct ath5k_hw *ah) |
Bob Copeland | 0ed4548 | 2009-03-08 00:10:20 -0500 | [diff] [blame] | 91 | { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 92 | if (test_bit(ATH_STAT_LEDSOFT, ah->status)) { |
| 93 | ath5k_hw_set_gpio_output(ah, ah->led_pin); |
| 94 | ath5k_led_off(ah); |
Bob Copeland | 0ed4548 | 2009-03-08 00:10:20 -0500 | [diff] [blame] | 95 | } |
| 96 | } |
| 97 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 98 | static void ath5k_led_on(struct ath5k_hw *ah) |
Bob Copeland | 0ed4548 | 2009-03-08 00:10:20 -0500 | [diff] [blame] | 99 | { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 100 | if (!test_bit(ATH_STAT_LEDSOFT, ah->status)) |
Bob Copeland | 0ed4548 | 2009-03-08 00:10:20 -0500 | [diff] [blame] | 101 | return; |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 102 | ath5k_hw_set_gpio(ah, ah->led_pin, ah->led_on); |
Bob Copeland | 0ed4548 | 2009-03-08 00:10:20 -0500 | [diff] [blame] | 103 | } |
| 104 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 105 | void ath5k_led_off(struct ath5k_hw *ah) |
Bob Copeland | 0ed4548 | 2009-03-08 00:10:20 -0500 | [diff] [blame] | 106 | { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 107 | if (!test_bit(ATH_STAT_LEDSOFT, ah->status)) |
Bob Copeland | 0ed4548 | 2009-03-08 00:10:20 -0500 | [diff] [blame] | 108 | return; |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 109 | ath5k_hw_set_gpio(ah, ah->led_pin, !ah->led_on); |
Bob Copeland | 0ed4548 | 2009-03-08 00:10:20 -0500 | [diff] [blame] | 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) |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 120 | ath5k_led_off(led->ah); |
Bob Copeland | 0ed4548 | 2009-03-08 00:10:20 -0500 | [diff] [blame] | 121 | else |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 122 | ath5k_led_on(led->ah); |
Bob Copeland | 0ed4548 | 2009-03-08 00:10:20 -0500 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | static int |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 126 | ath5k_register_led(struct ath5k_hw *ah, struct ath5k_led *led, |
Bob Copeland | 0ed4548 | 2009-03-08 00:10:20 -0500 | [diff] [blame] | 127 | const char *name, char *trigger) |
| 128 | { |
| 129 | int err; |
| 130 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 131 | led->ah = ah; |
Bob Copeland | 0ed4548 | 2009-03-08 00:10:20 -0500 | [diff] [blame] | 132 | strncpy(led->name, name, sizeof(led->name)); |
| 133 | led->led_dev.name = led->name; |
| 134 | led->led_dev.default_trigger = trigger; |
| 135 | led->led_dev.brightness_set = ath5k_led_brightness_set; |
| 136 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 137 | err = led_classdev_register(ah->dev, &led->led_dev); |
Bob Copeland | 0ed4548 | 2009-03-08 00:10:20 -0500 | [diff] [blame] | 138 | if (err) { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 139 | ATH5K_WARN(ah, "could not register LED %s\n", name); |
| 140 | led->ah = NULL; |
Bob Copeland | 0ed4548 | 2009-03-08 00:10:20 -0500 | [diff] [blame] | 141 | } |
| 142 | return err; |
| 143 | } |
| 144 | |
| 145 | static void |
| 146 | ath5k_unregister_led(struct ath5k_led *led) |
| 147 | { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 148 | if (!led->ah) |
Bob Copeland | 0ed4548 | 2009-03-08 00:10:20 -0500 | [diff] [blame] | 149 | return; |
| 150 | led_classdev_unregister(&led->led_dev); |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 151 | ath5k_led_off(led->ah); |
| 152 | led->ah = NULL; |
Bob Copeland | 0ed4548 | 2009-03-08 00:10:20 -0500 | [diff] [blame] | 153 | } |
| 154 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 155 | void ath5k_unregister_leds(struct ath5k_hw *ah) |
Bob Copeland | 0ed4548 | 2009-03-08 00:10:20 -0500 | [diff] [blame] | 156 | { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 157 | ath5k_unregister_led(&ah->rx_led); |
| 158 | ath5k_unregister_led(&ah->tx_led); |
Bob Copeland | 0ed4548 | 2009-03-08 00:10:20 -0500 | [diff] [blame] | 159 | } |
| 160 | |
Bill Pemberton | e829cf9 | 2012-12-03 09:56:28 -0500 | [diff] [blame] | 161 | int ath5k_init_leds(struct ath5k_hw *ah) |
Bob Copeland | 0ed4548 | 2009-03-08 00:10:20 -0500 | [diff] [blame] | 162 | { |
| 163 | int ret = 0; |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 164 | struct ieee80211_hw *hw = ah->hw; |
Felix Fietkau | a0b907e | 2010-12-02 10:27:16 +0100 | [diff] [blame] | 165 | #ifndef CONFIG_ATHEROS_AR231X |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 166 | struct pci_dev *pdev = ah->pdev; |
Felix Fietkau | a0b907e | 2010-12-02 10:27:16 +0100 | [diff] [blame] | 167 | #endif |
Bob Copeland | 0ed4548 | 2009-03-08 00:10:20 -0500 | [diff] [blame] | 168 | char name[ATH5K_LED_MAX_NAME_LEN + 1]; |
Bob Copeland | cdb02dc | 2009-03-08 00:10:21 -0500 | [diff] [blame] | 169 | const struct pci_device_id *match; |
Bob Copeland | 0ed4548 | 2009-03-08 00:10:20 -0500 | [diff] [blame] | 170 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 171 | if (!ah->pdev) |
Felix Fietkau | 8efa5d7 | 2010-12-02 10:27:06 +0100 | [diff] [blame] | 172 | return 0; |
| 173 | |
Felix Fietkau | a0b907e | 2010-12-02 10:27:16 +0100 | [diff] [blame] | 174 | #ifdef CONFIG_ATHEROS_AR231X |
| 175 | match = NULL; |
| 176 | #else |
Bob Copeland | cdb02dc | 2009-03-08 00:10:21 -0500 | [diff] [blame] | 177 | match = pci_match_id(&ath5k_led_devices[0], pdev); |
Felix Fietkau | a0b907e | 2010-12-02 10:27:16 +0100 | [diff] [blame] | 178 | #endif |
Bob Copeland | cdb02dc | 2009-03-08 00:10:21 -0500 | [diff] [blame] | 179 | if (match) { |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 180 | __set_bit(ATH_STAT_LEDSOFT, ah->status); |
| 181 | ah->led_pin = ATH_PIN(match->driver_data); |
| 182 | ah->led_on = ATH_POLARITY(match->driver_data); |
Bob Copeland | 0ed4548 | 2009-03-08 00:10:20 -0500 | [diff] [blame] | 183 | } |
| 184 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 185 | if (!test_bit(ATH_STAT_LEDSOFT, ah->status)) |
Bob Copeland | 0ed4548 | 2009-03-08 00:10:20 -0500 | [diff] [blame] | 186 | goto out; |
| 187 | |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 188 | ath5k_led_enable(ah); |
Bob Copeland | 0ed4548 | 2009-03-08 00:10:20 -0500 | [diff] [blame] | 189 | |
| 190 | snprintf(name, sizeof(name), "ath5k-%s::rx", wiphy_name(hw->wiphy)); |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 191 | ret = ath5k_register_led(ah, &ah->rx_led, name, |
Bob Copeland | 0ed4548 | 2009-03-08 00:10:20 -0500 | [diff] [blame] | 192 | ieee80211_get_rx_led_name(hw)); |
| 193 | if (ret) |
| 194 | goto out; |
| 195 | |
| 196 | snprintf(name, sizeof(name), "ath5k-%s::tx", wiphy_name(hw->wiphy)); |
Pavel Roskin | e0d687b | 2011-07-14 20:21:55 -0400 | [diff] [blame] | 197 | ret = ath5k_register_led(ah, &ah->tx_led, name, |
Bob Copeland | 0ed4548 | 2009-03-08 00:10:20 -0500 | [diff] [blame] | 198 | ieee80211_get_tx_led_name(hw)); |
| 199 | out: |
| 200 | return ret; |
| 201 | } |
| 202 | |