led.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2009-2012 Realtek Corporation.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of version 2 of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  17. *
  18. * The full GNU General Public License is included in this distribution in the
  19. * file called LICENSE.
  20. *
  21. * Contact Information:
  22. * wlanfae <wlanfae@realtek.com>
  23. * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
  24. * Hsinchu 300, Taiwan.
  25. *
  26. * Larry Finger <Larry.Finger@lwfinger.net>
  27. *
  28. *****************************************************************************/
  29. #include "../wifi.h"
  30. #include "../pci.h"
  31. #include "reg.h"
  32. #include "led.h"
  33. static void _rtl92se_init_led(struct ieee80211_hw *hw,
  34. struct rtl_led *pled, enum rtl_led_pin ledpin)
  35. {
  36. pled->hw = hw;
  37. pled->ledpin = ledpin;
  38. pled->ledon = false;
  39. }
  40. void rtl92se_init_sw_leds(struct ieee80211_hw *hw)
  41. {
  42. struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
  43. _rtl92se_init_led(hw, &(pcipriv->ledctl.sw_led0), LED_PIN_LED0);
  44. _rtl92se_init_led(hw, &(pcipriv->ledctl.sw_led1), LED_PIN_LED1);
  45. }
  46. void rtl92se_sw_led_on(struct ieee80211_hw *hw, struct rtl_led *pled)
  47. {
  48. u8 ledcfg;
  49. struct rtl_priv *rtlpriv = rtl_priv(hw);
  50. RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD, "LedAddr:%X ledpin=%d\n",
  51. LEDCFG, pled->ledpin);
  52. ledcfg = rtl_read_byte(rtlpriv, LEDCFG);
  53. switch (pled->ledpin) {
  54. case LED_PIN_GPIO0:
  55. break;
  56. case LED_PIN_LED0:
  57. rtl_write_byte(rtlpriv, LEDCFG, ledcfg & 0xf0);
  58. break;
  59. case LED_PIN_LED1:
  60. rtl_write_byte(rtlpriv, LEDCFG, ledcfg & 0x0f);
  61. break;
  62. default:
  63. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  64. "switch case not processed\n");
  65. break;
  66. }
  67. pled->ledon = true;
  68. }
  69. void rtl92se_sw_led_off(struct ieee80211_hw *hw, struct rtl_led *pled)
  70. {
  71. struct rtl_priv *rtlpriv;
  72. struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
  73. u8 ledcfg;
  74. rtlpriv = rtl_priv(hw);
  75. if (!rtlpriv || rtlpriv->max_fw_size)
  76. return;
  77. RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD, "LedAddr:%X ledpin=%d\n",
  78. LEDCFG, pled->ledpin);
  79. ledcfg = rtl_read_byte(rtlpriv, LEDCFG);
  80. switch (pled->ledpin) {
  81. case LED_PIN_GPIO0:
  82. break;
  83. case LED_PIN_LED0:
  84. ledcfg &= 0xf0;
  85. if (pcipriv->ledctl.led_opendrain)
  86. rtl_write_byte(rtlpriv, LEDCFG, (ledcfg | BIT(1)));
  87. else
  88. rtl_write_byte(rtlpriv, LEDCFG, (ledcfg | BIT(3)));
  89. break;
  90. case LED_PIN_LED1:
  91. ledcfg &= 0x0f;
  92. rtl_write_byte(rtlpriv, LEDCFG, (ledcfg | BIT(3)));
  93. break;
  94. default:
  95. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  96. "switch case not processed\n");
  97. break;
  98. }
  99. pled->ledon = false;
  100. }
  101. static void _rtl92se_sw_led_control(struct ieee80211_hw *hw,
  102. enum led_ctl_mode ledaction)
  103. {
  104. struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
  105. struct rtl_led *pLed0 = &(pcipriv->ledctl.sw_led0);
  106. switch (ledaction) {
  107. case LED_CTL_POWER_ON:
  108. case LED_CTL_LINK:
  109. case LED_CTL_NO_LINK:
  110. rtl92se_sw_led_on(hw, pLed0);
  111. break;
  112. case LED_CTL_POWER_OFF:
  113. rtl92se_sw_led_off(hw, pLed0);
  114. break;
  115. default:
  116. break;
  117. }
  118. }
  119. void rtl92se_led_control(struct ieee80211_hw *hw, enum led_ctl_mode ledaction)
  120. {
  121. struct rtl_priv *rtlpriv = rtl_priv(hw);
  122. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  123. if ((ppsc->rfoff_reason > RF_CHANGE_BY_PS) &&
  124. (ledaction == LED_CTL_TX ||
  125. ledaction == LED_CTL_RX ||
  126. ledaction == LED_CTL_SITE_SURVEY ||
  127. ledaction == LED_CTL_LINK ||
  128. ledaction == LED_CTL_NO_LINK ||
  129. ledaction == LED_CTL_START_TO_LINK ||
  130. ledaction == LED_CTL_POWER_ON)) {
  131. return;
  132. }
  133. RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD, "ledaction %d\n", ledaction);
  134. _rtl92se_sw_led_control(hw, ledaction);
  135. }