led.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. #include <linux/pci.h>
  42. #include "ath5k.h"
  43. #include "base.h"
  44. void ath5k_led_enable(struct ath5k_softc *sc)
  45. {
  46. if (test_bit(ATH_STAT_LEDSOFT, sc->status)) {
  47. ath5k_hw_set_gpio_output(sc->ah, sc->led_pin);
  48. ath5k_led_off(sc);
  49. }
  50. }
  51. void ath5k_led_on(struct ath5k_softc *sc)
  52. {
  53. if (!test_bit(ATH_STAT_LEDSOFT, sc->status))
  54. return;
  55. ath5k_hw_set_gpio(sc->ah, sc->led_pin, sc->led_on);
  56. }
  57. void ath5k_led_off(struct ath5k_softc *sc)
  58. {
  59. if (!test_bit(ATH_STAT_LEDSOFT, sc->status))
  60. return;
  61. ath5k_hw_set_gpio(sc->ah, sc->led_pin, !sc->led_on);
  62. }
  63. static void
  64. ath5k_led_brightness_set(struct led_classdev *led_dev,
  65. enum led_brightness brightness)
  66. {
  67. struct ath5k_led *led = container_of(led_dev, struct ath5k_led,
  68. led_dev);
  69. if (brightness == LED_OFF)
  70. ath5k_led_off(led->sc);
  71. else
  72. ath5k_led_on(led->sc);
  73. }
  74. static int
  75. ath5k_register_led(struct ath5k_softc *sc, struct ath5k_led *led,
  76. const char *name, char *trigger)
  77. {
  78. int err;
  79. led->sc = sc;
  80. strncpy(led->name, name, sizeof(led->name));
  81. led->led_dev.name = led->name;
  82. led->led_dev.default_trigger = trigger;
  83. led->led_dev.brightness_set = ath5k_led_brightness_set;
  84. err = led_classdev_register(&sc->pdev->dev, &led->led_dev);
  85. if (err) {
  86. ATH5K_WARN(sc, "could not register LED %s\n", name);
  87. led->sc = NULL;
  88. }
  89. return err;
  90. }
  91. static void
  92. ath5k_unregister_led(struct ath5k_led *led)
  93. {
  94. if (!led->sc)
  95. return;
  96. led_classdev_unregister(&led->led_dev);
  97. ath5k_led_off(led->sc);
  98. led->sc = NULL;
  99. }
  100. void ath5k_unregister_leds(struct ath5k_softc *sc)
  101. {
  102. ath5k_unregister_led(&sc->rx_led);
  103. ath5k_unregister_led(&sc->tx_led);
  104. }
  105. int ath5k_init_leds(struct ath5k_softc *sc)
  106. {
  107. int ret = 0;
  108. struct ieee80211_hw *hw = sc->hw;
  109. struct pci_dev *pdev = sc->pdev;
  110. char name[ATH5K_LED_MAX_NAME_LEN + 1];
  111. /*
  112. * Auto-enable soft led processing for IBM cards and for
  113. * 5211 minipci cards.
  114. */
  115. if (pdev->device == PCI_DEVICE_ID_ATHEROS_AR5212_IBM ||
  116. pdev->device == PCI_DEVICE_ID_ATHEROS_AR5211) {
  117. __set_bit(ATH_STAT_LEDSOFT, sc->status);
  118. sc->led_pin = 0;
  119. sc->led_on = 0; /* active low */
  120. }
  121. /* Enable softled on PIN1 on HP Compaq nc6xx, nc4000 & nx5000 laptops */
  122. if (pdev->subsystem_vendor == PCI_VENDOR_ID_COMPAQ) {
  123. __set_bit(ATH_STAT_LEDSOFT, sc->status);
  124. sc->led_pin = 1;
  125. sc->led_on = 1; /* active high */
  126. }
  127. /*
  128. * Pin 3 on Foxconn chips used in Acer Aspire One (0x105b:e008) and
  129. * in emachines notebooks with AMBIT subsystem.
  130. */
  131. if (pdev->subsystem_vendor == PCI_VENDOR_ID_FOXCONN ||
  132. pdev->subsystem_vendor == PCI_VENDOR_ID_AMBIT) {
  133. __set_bit(ATH_STAT_LEDSOFT, sc->status);
  134. sc->led_pin = 3;
  135. sc->led_on = 0; /* active low */
  136. }
  137. if (!test_bit(ATH_STAT_LEDSOFT, sc->status))
  138. goto out;
  139. ath5k_led_enable(sc);
  140. snprintf(name, sizeof(name), "ath5k-%s::rx", wiphy_name(hw->wiphy));
  141. ret = ath5k_register_led(sc, &sc->rx_led, name,
  142. ieee80211_get_rx_led_name(hw));
  143. if (ret)
  144. goto out;
  145. snprintf(name, sizeof(name), "ath5k-%s::tx", wiphy_name(hw->wiphy));
  146. ret = ath5k_register_led(sc, &sc->tx_led, name,
  147. ieee80211_get_tx_led_name(hw));
  148. out:
  149. return ret;
  150. }