led.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2009-2012 Realtek Corporation. All rights reserved.
  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. *****************************************************************************/
  27. #include "../wifi.h"
  28. #include "../usb.h"
  29. #include "reg.h"
  30. #include "led.h"
  31. static void _rtl92cu_init_led(struct ieee80211_hw *hw,
  32. struct rtl_led *pled, enum rtl_led_pin ledpin)
  33. {
  34. pled->hw = hw;
  35. pled->ledpin = ledpin;
  36. pled->ledon = false;
  37. }
  38. static void _rtl92cu_deInit_led(struct rtl_led *pled)
  39. {
  40. }
  41. void rtl92cu_sw_led_on(struct ieee80211_hw *hw, struct rtl_led *pled)
  42. {
  43. u8 ledcfg;
  44. struct rtl_priv *rtlpriv = rtl_priv(hw);
  45. RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD, "LedAddr:%X ledpin=%d\n",
  46. REG_LEDCFG2, pled->ledpin);
  47. ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG2);
  48. switch (pled->ledpin) {
  49. case LED_PIN_GPIO0:
  50. break;
  51. case LED_PIN_LED0:
  52. rtl_write_byte(rtlpriv,
  53. REG_LEDCFG2, (ledcfg & 0xf0) | BIT(5) | BIT(6));
  54. break;
  55. case LED_PIN_LED1:
  56. rtl_write_byte(rtlpriv, REG_LEDCFG2, (ledcfg & 0x0f) | BIT(5));
  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 rtl92cu_sw_led_off(struct ieee80211_hw *hw, struct rtl_led *pled)
  66. {
  67. struct rtl_priv *rtlpriv = rtl_priv(hw);
  68. struct rtl_usb_priv *usbpriv = rtl_usbpriv(hw);
  69. u8 ledcfg;
  70. RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD, "LedAddr:%X ledpin=%d\n",
  71. REG_LEDCFG2, pled->ledpin);
  72. ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG2);
  73. switch (pled->ledpin) {
  74. case LED_PIN_GPIO0:
  75. break;
  76. case LED_PIN_LED0:
  77. ledcfg &= 0xf0;
  78. if (usbpriv->ledctl.led_opendrain)
  79. rtl_write_byte(rtlpriv, REG_LEDCFG2,
  80. (ledcfg | BIT(1) | BIT(5) | BIT(6)));
  81. else
  82. rtl_write_byte(rtlpriv, REG_LEDCFG2,
  83. (ledcfg | BIT(3) | BIT(5) | BIT(6)));
  84. break;
  85. case LED_PIN_LED1:
  86. ledcfg &= 0x0f;
  87. rtl_write_byte(rtlpriv, REG_LEDCFG2, (ledcfg | BIT(3)));
  88. break;
  89. default:
  90. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  91. "switch case not processed\n");
  92. break;
  93. }
  94. pled->ledon = false;
  95. }
  96. void rtl92cu_init_sw_leds(struct ieee80211_hw *hw)
  97. {
  98. struct rtl_usb_priv *usbpriv = rtl_usbpriv(hw);
  99. _rtl92cu_init_led(hw, &(usbpriv->ledctl.sw_led0), LED_PIN_LED0);
  100. _rtl92cu_init_led(hw, &(usbpriv->ledctl.sw_led1), LED_PIN_LED1);
  101. }
  102. void rtl92cu_deinit_sw_leds(struct ieee80211_hw *hw)
  103. {
  104. struct rtl_usb_priv *usbpriv = rtl_usbpriv(hw);
  105. _rtl92cu_deInit_led(&(usbpriv->ledctl.sw_led0));
  106. _rtl92cu_deInit_led(&(usbpriv->ledctl.sw_led1));
  107. }
  108. static void _rtl92cu_sw_led_control(struct ieee80211_hw *hw,
  109. enum led_ctl_mode ledaction)
  110. {
  111. }
  112. void rtl92cu_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", ledaction);
  128. _rtl92cu_sw_led_control(hw, ledaction);
  129. }