led.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2009-2010 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. void rtl92ce_sw_led_on(struct ieee80211_hw *hw, struct rtl_led *pled)
  34. {
  35. u8 ledcfg;
  36. struct rtl_priv *rtlpriv = rtl_priv(hw);
  37. RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD,
  38. ("LedAddr:%X ledpin=%d\n", REG_LEDCFG2, pled->ledpin));
  39. ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG2);
  40. switch (pled->ledpin) {
  41. case LED_PIN_GPIO0:
  42. break;
  43. case LED_PIN_LED0:
  44. rtl_write_byte(rtlpriv,
  45. REG_LEDCFG2, (ledcfg & 0xf0) | BIT(5) | BIT(6));
  46. break;
  47. case LED_PIN_LED1:
  48. rtl_write_byte(rtlpriv, REG_LEDCFG2, (ledcfg & 0x0f) | BIT(5));
  49. break;
  50. default:
  51. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  52. ("switch case not process\n"));
  53. break;
  54. }
  55. pled->b_ledon = true;
  56. }
  57. void rtl92ce_sw_led_off(struct ieee80211_hw *hw, struct rtl_led *pled)
  58. {
  59. struct rtl_priv *rtlpriv = rtl_priv(hw);
  60. struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
  61. u8 ledcfg;
  62. RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD,
  63. ("LedAddr:%X ledpin=%d\n", REG_LEDCFG2, pled->ledpin));
  64. ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG2);
  65. switch (pled->ledpin) {
  66. case LED_PIN_GPIO0:
  67. break;
  68. case LED_PIN_LED0:
  69. ledcfg &= 0xf0;
  70. if (pcipriv->ledctl.bled_opendrain == true)
  71. rtl_write_byte(rtlpriv, REG_LEDCFG2,
  72. (ledcfg | BIT(1) | BIT(5) | BIT(6)));
  73. else
  74. rtl_write_byte(rtlpriv, REG_LEDCFG2,
  75. (ledcfg | BIT(3) | BIT(5) | BIT(6)));
  76. break;
  77. case LED_PIN_LED1:
  78. ledcfg &= 0x0f;
  79. rtl_write_byte(rtlpriv, REG_LEDCFG2, (ledcfg | BIT(3)));
  80. break;
  81. default:
  82. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  83. ("switch case not process\n"));
  84. break;
  85. }
  86. pled->b_ledon = false;
  87. }
  88. void rtl92ce_init_sw_leds(struct ieee80211_hw *hw)
  89. {
  90. }
  91. void rtl92ce_deinit_sw_leds(struct ieee80211_hw *hw)
  92. {
  93. }
  94. void _rtl92ce_sw_led_control(struct ieee80211_hw *hw,
  95. enum led_ctl_mode ledaction)
  96. {
  97. struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
  98. struct rtl_led *pLed0 = &(pcipriv->ledctl.sw_led0);
  99. switch (ledaction) {
  100. case LED_CTL_POWER_ON:
  101. case LED_CTL_LINK:
  102. case LED_CTL_NO_LINK:
  103. rtl92ce_sw_led_on(hw, pLed0);
  104. break;
  105. case LED_CTL_POWER_OFF:
  106. rtl92ce_sw_led_off(hw, pLed0);
  107. break;
  108. default:
  109. break;
  110. }
  111. }
  112. void rtl92ce_led_control(struct ieee80211_hw *hw,
  113. enum led_ctl_mode ledaction)
  114. {
  115. struct rtl_priv *rtlpriv = rtl_priv(hw);
  116. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  117. if ((ppsc->rfoff_reason > RF_CHANGE_BY_PS) &&
  118. (ledaction == LED_CTL_TX ||
  119. ledaction == LED_CTL_RX ||
  120. ledaction == LED_CTL_SITE_SURVEY ||
  121. ledaction == LED_CTL_LINK ||
  122. ledaction == LED_CTL_NO_LINK ||
  123. ledaction == LED_CTL_START_TO_LINK ||
  124. ledaction == LED_CTL_POWER_ON)) {
  125. return;
  126. }
  127. RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD, ("ledaction %d,\n",
  128. ledaction));
  129. _rtl92ce_sw_led_control(hw, ledaction);
  130. }