led.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. * The full GNU General Public License is included in this distribution in the
  15. * file called LICENSE.
  16. *
  17. * Contact Information:
  18. * wlanfae <wlanfae@realtek.com>
  19. * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
  20. * Hsinchu 300, Taiwan.
  21. *
  22. * Larry Finger <Larry.Finger@lwfinger.net>
  23. *
  24. *****************************************************************************/
  25. #include "../wifi.h"
  26. #include "../pci.h"
  27. #include "reg.h"
  28. #include "led.h"
  29. static void _rtl8723e_init_led(struct ieee80211_hw *hw,
  30. struct rtl_led *pled, enum rtl_led_pin ledpin)
  31. {
  32. pled->hw = hw;
  33. pled->ledpin = ledpin;
  34. pled->ledon = false;
  35. }
  36. void rtl8723e_sw_led_on(struct ieee80211_hw *hw, struct rtl_led *pled)
  37. {
  38. u8 ledcfg;
  39. struct rtl_priv *rtlpriv = rtl_priv(hw);
  40. RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD,
  41. "LedAddr:%X ledpin=%d\n", REG_LEDCFG2, pled->ledpin);
  42. switch (pled->ledpin) {
  43. case LED_PIN_GPIO0:
  44. break;
  45. case LED_PIN_LED0:
  46. ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG2);
  47. ledcfg &= ~BIT(6);
  48. rtl_write_byte(rtlpriv,
  49. REG_LEDCFG2, (ledcfg & 0xf0) | BIT(5));
  50. break;
  51. case LED_PIN_LED1:
  52. ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG1);
  53. rtl_write_byte(rtlpriv, REG_LEDCFG1, ledcfg & 0x10);
  54. break;
  55. default:
  56. pr_err("switch case %#x not processed\n",
  57. pled->ledpin);
  58. break;
  59. }
  60. pled->ledon = true;
  61. }
  62. void rtl8723e_sw_led_off(struct ieee80211_hw *hw, struct rtl_led *pled)
  63. {
  64. struct rtl_priv *rtlpriv = rtl_priv(hw);
  65. u8 ledcfg;
  66. RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD,
  67. "LedAddr:%X ledpin=%d\n", REG_LEDCFG2, pled->ledpin);
  68. ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG2);
  69. switch (pled->ledpin) {
  70. case LED_PIN_GPIO0:
  71. break;
  72. case LED_PIN_LED0:
  73. ledcfg &= 0xf0;
  74. if (rtlpriv->ledctl.led_opendrain) {
  75. ledcfg &= 0x90; /* Set to software control. */
  76. rtl_write_byte(rtlpriv, REG_LEDCFG2, (ledcfg|BIT(3)));
  77. ledcfg = rtl_read_byte(rtlpriv, REG_MAC_PINMUX_CFG);
  78. ledcfg &= 0xFE;
  79. rtl_write_byte(rtlpriv, REG_MAC_PINMUX_CFG, ledcfg);
  80. } else {
  81. ledcfg &= ~BIT(6);
  82. rtl_write_byte(rtlpriv, REG_LEDCFG2,
  83. (ledcfg | BIT(3) | BIT(5)));
  84. }
  85. break;
  86. case LED_PIN_LED1:
  87. ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG1);
  88. ledcfg &= 0x10; /* Set to software control. */
  89. rtl_write_byte(rtlpriv, REG_LEDCFG1, ledcfg|BIT(3));
  90. break;
  91. default:
  92. pr_err("switch case %#x not processed\n",
  93. pled->ledpin);
  94. break;
  95. }
  96. pled->ledon = false;
  97. }
  98. void rtl8723e_init_sw_leds(struct ieee80211_hw *hw)
  99. {
  100. struct rtl_priv *rtlpriv = rtl_priv(hw);
  101. _rtl8723e_init_led(hw, &rtlpriv->ledctl.sw_led0, LED_PIN_LED0);
  102. _rtl8723e_init_led(hw, &rtlpriv->ledctl.sw_led1, LED_PIN_LED1);
  103. }
  104. static void _rtl8723e_sw_led_control(struct ieee80211_hw *hw,
  105. enum led_ctl_mode ledaction)
  106. {
  107. struct rtl_priv *rtlpriv = rtl_priv(hw);
  108. struct rtl_led *pled0 = &rtlpriv->ledctl.sw_led0;
  109. switch (ledaction) {
  110. case LED_CTL_POWER_ON:
  111. case LED_CTL_LINK:
  112. case LED_CTL_NO_LINK:
  113. rtl8723e_sw_led_on(hw, pled0);
  114. break;
  115. case LED_CTL_POWER_OFF:
  116. rtl8723e_sw_led_off(hw, pled0);
  117. break;
  118. default:
  119. break;
  120. }
  121. }
  122. void rtl8723e_led_control(struct ieee80211_hw *hw,
  123. enum led_ctl_mode ledaction)
  124. {
  125. struct rtl_priv *rtlpriv = rtl_priv(hw);
  126. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  127. if ((ppsc->rfoff_reason > RF_CHANGE_BY_PS) &&
  128. (ledaction == LED_CTL_TX ||
  129. ledaction == LED_CTL_RX ||
  130. ledaction == LED_CTL_SITE_SURVEY ||
  131. ledaction == LED_CTL_LINK ||
  132. ledaction == LED_CTL_NO_LINK ||
  133. ledaction == LED_CTL_START_TO_LINK ||
  134. ledaction == LED_CTL_POWER_ON)) {
  135. return;
  136. }
  137. RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD, "ledaction %d,\n",
  138. ledaction);
  139. _rtl8723e_sw_led_control(hw, ledaction);
  140. }