led.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2009-2014 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 _rtl92ee_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 rtl92ee_sw_led_on(struct ieee80211_hw *hw, struct rtl_led *pled)
  37. {
  38. u32 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_dword(rtlpriv , REG_GPIO_PIN_CTRL);
  47. ledcfg &= ~BIT(13);
  48. ledcfg |= BIT(21);
  49. ledcfg &= ~BIT(29);
  50. rtl_write_dword(rtlpriv, REG_GPIO_PIN_CTRL, ledcfg);
  51. break;
  52. case LED_PIN_LED1:
  53. break;
  54. default:
  55. RT_TRACE(rtlpriv, COMP_ERR, DBG_LOUD,
  56. "switch case not process\n");
  57. break;
  58. }
  59. pled->ledon = true;
  60. }
  61. void rtl92ee_sw_led_off(struct ieee80211_hw *hw, struct rtl_led *pled)
  62. {
  63. struct rtl_priv *rtlpriv = rtl_priv(hw);
  64. u32 ledcfg;
  65. RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD,
  66. "LedAddr:%X ledpin=%d\n", REG_LEDCFG2, pled->ledpin);
  67. switch (pled->ledpin) {
  68. case LED_PIN_GPIO0:
  69. break;
  70. case LED_PIN_LED0:
  71. ledcfg = rtl_read_dword(rtlpriv , REG_GPIO_PIN_CTRL);
  72. ledcfg |= ~BIT(21);
  73. ledcfg &= ~BIT(29);
  74. rtl_write_dword(rtlpriv, REG_GPIO_PIN_CTRL, ledcfg);
  75. break;
  76. case LED_PIN_LED1:
  77. break;
  78. default:
  79. RT_TRACE(rtlpriv, COMP_ERR, DBG_LOUD,
  80. "switch case not process\n");
  81. break;
  82. }
  83. pled->ledon = false;
  84. }
  85. void rtl92ee_init_sw_leds(struct ieee80211_hw *hw)
  86. {
  87. struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
  88. _rtl92ee_init_led(hw, &pcipriv->ledctl.sw_led0, LED_PIN_LED0);
  89. _rtl92ee_init_led(hw, &pcipriv->ledctl.sw_led1, LED_PIN_LED1);
  90. }
  91. static void _rtl92ee_sw_led_control(struct ieee80211_hw *hw,
  92. enum led_ctl_mode ledaction)
  93. {
  94. struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
  95. struct rtl_led *pLed0 = &pcipriv->ledctl.sw_led0;
  96. switch (ledaction) {
  97. case LED_CTL_POWER_ON:
  98. case LED_CTL_LINK:
  99. case LED_CTL_NO_LINK:
  100. rtl92ee_sw_led_on(hw, pLed0);
  101. break;
  102. case LED_CTL_POWER_OFF:
  103. rtl92ee_sw_led_off(hw, pLed0);
  104. break;
  105. default:
  106. break;
  107. }
  108. }
  109. void rtl92ee_led_control(struct ieee80211_hw *hw, enum led_ctl_mode ledaction)
  110. {
  111. struct rtl_priv *rtlpriv = rtl_priv(hw);
  112. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  113. if ((ppsc->rfoff_reason > RF_CHANGE_BY_PS) &&
  114. (ledaction == LED_CTL_TX ||
  115. ledaction == LED_CTL_RX ||
  116. ledaction == LED_CTL_SITE_SURVEY ||
  117. ledaction == LED_CTL_LINK ||
  118. ledaction == LED_CTL_NO_LINK ||
  119. ledaction == LED_CTL_START_TO_LINK ||
  120. ledaction == LED_CTL_POWER_ON)) {
  121. return;
  122. }
  123. RT_TRACE(rtlpriv, COMP_LED, DBG_TRACE, "ledaction %d,\n", ledaction);
  124. _rtl92ee_sw_led_control(hw, ledaction);
  125. }