led.c 3.8 KB

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