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 | |
| 42 | #include <linux/pci.h> |
| 43 | #include "ath5k.h" |
| 44 | #include "base.h" |
| 45 | |
| 46 | void 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 | |
| 54 | void 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 | |
| 61 | void 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 | |
| 68 | static void |
| 69 | ath5k_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 | |
| 81 | static int |
| 82 | ath5k_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 | |
| 101 | static void |
| 102 | ath5k_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 | |
| 111 | void 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 | |
| 118 | int 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)); |
| 166 | out: |
| 167 | return ret; |
| 168 | } |
| 169 | |