led.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. * 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. *****************************************************************************/
  23. #include "../wifi.h"
  24. #include "../usb.h"
  25. #include "reg.h"
  26. #include "led.h"
  27. static void _rtl92cu_init_led(struct ieee80211_hw *hw,
  28. struct rtl_led *pled, enum rtl_led_pin ledpin)
  29. {
  30. pled->hw = hw;
  31. pled->ledpin = ledpin;
  32. pled->ledon = false;
  33. }
  34. static void _rtl92cu_deInit_led(struct rtl_led *pled)
  35. {
  36. }
  37. void rtl92cu_sw_led_on(struct ieee80211_hw *hw, struct rtl_led *pled)
  38. {
  39. u8 ledcfg;
  40. struct rtl_priv *rtlpriv = rtl_priv(hw);
  41. RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD, "LedAddr:%X ledpin=%d\n",
  42. REG_LEDCFG2, pled->ledpin);
  43. ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG2);
  44. switch (pled->ledpin) {
  45. case LED_PIN_GPIO0:
  46. break;
  47. case LED_PIN_LED0:
  48. rtl_write_byte(rtlpriv,
  49. REG_LEDCFG2, (ledcfg & 0xf0) | BIT(5) | BIT(6));
  50. break;
  51. case LED_PIN_LED1:
  52. rtl_write_byte(rtlpriv, REG_LEDCFG2, (ledcfg & 0x0f) | BIT(5));
  53. break;
  54. default:
  55. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  56. "switch case %#x not processed\n", pled->ledpin);
  57. break;
  58. }
  59. pled->ledon = true;
  60. }
  61. void rtl92cu_sw_led_off(struct ieee80211_hw *hw, struct rtl_led *pled)
  62. {
  63. struct rtl_priv *rtlpriv = rtl_priv(hw);
  64. struct rtl_usb_priv *usbpriv = rtl_usbpriv(hw);
  65. u8 ledcfg;
  66. RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD, "LedAddr:%X ledpin=%d\n",
  67. 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 (usbpriv->ledctl.led_opendrain)
  75. rtl_write_byte(rtlpriv, REG_LEDCFG2,
  76. (ledcfg | BIT(1) | BIT(5) | BIT(6)));
  77. else
  78. rtl_write_byte(rtlpriv, REG_LEDCFG2,
  79. (ledcfg | BIT(3) | BIT(5) | BIT(6)));
  80. break;
  81. case LED_PIN_LED1:
  82. ledcfg &= 0x0f;
  83. rtl_write_byte(rtlpriv, REG_LEDCFG2, (ledcfg | BIT(3)));
  84. break;
  85. default:
  86. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  87. "switch case %#x not processed\n", pled->ledpin);
  88. break;
  89. }
  90. pled->ledon = false;
  91. }
  92. void rtl92cu_init_sw_leds(struct ieee80211_hw *hw)
  93. {
  94. struct rtl_usb_priv *usbpriv = rtl_usbpriv(hw);
  95. _rtl92cu_init_led(hw, &(usbpriv->ledctl.sw_led0), LED_PIN_LED0);
  96. _rtl92cu_init_led(hw, &(usbpriv->ledctl.sw_led1), LED_PIN_LED1);
  97. }
  98. void rtl92cu_deinit_sw_leds(struct ieee80211_hw *hw)
  99. {
  100. struct rtl_usb_priv *usbpriv = rtl_usbpriv(hw);
  101. _rtl92cu_deInit_led(&(usbpriv->ledctl.sw_led0));
  102. _rtl92cu_deInit_led(&(usbpriv->ledctl.sw_led1));
  103. }
  104. static void _rtl92cu_sw_led_control(struct ieee80211_hw *hw,
  105. enum led_ctl_mode ledaction)
  106. {
  107. }
  108. void rtl92cu_led_control(struct ieee80211_hw *hw,
  109. 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_LOUD, "ledaction %d\n", ledaction);
  124. _rtl92cu_sw_led_control(hw, ledaction);
  125. }