led.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2009-2013 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 rtl88ee_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 rtl88ee_sw_led_on(struct ieee80211_hw *hw, struct rtl_led *pled)
  41. {
  42. u8 ledcfg;
  43. struct rtl_priv *rtlpriv = rtl_priv(hw);
  44. RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD,
  45. "LedAddr:%X ledpin =%d\n", REG_LEDCFG2, pled->ledpin);
  46. switch (pled->ledpin) {
  47. case LED_PIN_GPIO0:
  48. break;
  49. case LED_PIN_LED0:
  50. ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG2);
  51. rtl_write_byte(rtlpriv, REG_LEDCFG2,
  52. (ledcfg & 0xf0) | BIT(5) | BIT(6));
  53. break;
  54. case LED_PIN_LED1:
  55. ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG1);
  56. rtl_write_byte(rtlpriv, REG_LEDCFG1, ledcfg & 0x10);
  57. break;
  58. default:
  59. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  60. "switch case not processed\n");
  61. break;
  62. }
  63. pled->ledon = true;
  64. }
  65. void rtl88ee_sw_led_off(struct ieee80211_hw *hw, struct rtl_led *pled)
  66. {
  67. struct rtl_priv *rtlpriv = rtl_priv(hw);
  68. struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
  69. u8 ledcfg;
  70. u8 val;
  71. RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD,
  72. "LedAddr:%X ledpin =%d\n", REG_LEDCFG2, pled->ledpin);
  73. switch (pled->ledpin) {
  74. case LED_PIN_GPIO0:
  75. break;
  76. case LED_PIN_LED0:
  77. ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG2);
  78. ledcfg &= 0xf0;
  79. val = ledcfg | BIT(3) | BIT(5) | BIT(6);
  80. if (pcipriv->ledctl.led_opendrain == true) {
  81. rtl_write_byte(rtlpriv, REG_LEDCFG2, val);
  82. ledcfg = rtl_read_byte(rtlpriv, REG_MAC_PINMUX_CFG);
  83. val = ledcfg & 0xFE;
  84. rtl_write_byte(rtlpriv, REG_MAC_PINMUX_CFG, val);
  85. } else {
  86. rtl_write_byte(rtlpriv, REG_LEDCFG2, val);
  87. }
  88. break;
  89. case LED_PIN_LED1:
  90. ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG1);
  91. ledcfg &= 0x10;
  92. rtl_write_byte(rtlpriv, REG_LEDCFG1, (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. void rtl88ee_init_sw_leds(struct ieee80211_hw *hw)
  102. {
  103. struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
  104. rtl88ee_init_led(hw, &(pcipriv->ledctl.sw_led0), LED_PIN_LED0);
  105. rtl88ee_init_led(hw, &(pcipriv->ledctl.sw_led1), LED_PIN_LED1);
  106. }
  107. static void rtl88ee_sw_led_control(struct ieee80211_hw *hw,
  108. enum led_ctl_mode ledaction)
  109. {
  110. struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
  111. struct rtl_led *pLed0 = &(pcipriv->ledctl.sw_led0);
  112. switch (ledaction) {
  113. case LED_CTL_POWER_ON:
  114. case LED_CTL_LINK:
  115. case LED_CTL_NO_LINK:
  116. rtl88ee_sw_led_on(hw, pLed0);
  117. break;
  118. case LED_CTL_POWER_OFF:
  119. rtl88ee_sw_led_off(hw, pLed0);
  120. break;
  121. default:
  122. break;
  123. }
  124. }
  125. void rtl88ee_led_control(struct ieee80211_hw *hw,
  126. enum led_ctl_mode ledaction)
  127. {
  128. struct rtl_priv *rtlpriv = rtl_priv(hw);
  129. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  130. if ((ppsc->rfoff_reason > RF_CHANGE_BY_PS) &&
  131. (ledaction == LED_CTL_TX ||
  132. ledaction == LED_CTL_RX ||
  133. ledaction == LED_CTL_SITE_SURVEY ||
  134. ledaction == LED_CTL_LINK ||
  135. ledaction == LED_CTL_NO_LINK ||
  136. ledaction == LED_CTL_START_TO_LINK ||
  137. ledaction == LED_CTL_POWER_ON)) {
  138. return;
  139. }
  140. RT_TRACE(rtlpriv, COMP_LED, DBG_TRACE, "ledaction %d,\n",
  141. ledaction);
  142. rtl88ee_sw_led_control(hw, ledaction);
  143. }