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 28#include "../wifi.h" 29#include "../usb.h" 30#include "reg.h" 31#include "led.h" 32 33static void _rtl92cu_init_led(struct ieee80211_hw *hw, 34 struct rtl_led *pled, enum rtl_led_pin ledpin) 35{ 36 pled->hw = hw; 37 pled->ledpin = ledpin; 38 pled->ledon = false; 39} 40 41static void _rtl92cu_deInit_led(struct rtl_led *pled) 42{ 43} 44 45void rtl92cu_sw_led_on(struct ieee80211_hw *hw, struct rtl_led *pled) 46{ 47 u8 ledcfg; 48 struct rtl_priv *rtlpriv = rtl_priv(hw); 49 50 RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD, "LedAddr:%X ledpin=%d\n", 51 REG_LEDCFG2, pled->ledpin); 52 ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG2); 53 switch (pled->ledpin) { 54 case LED_PIN_GPIO0: 55 break; 56 case LED_PIN_LED0: 57 rtl_write_byte(rtlpriv, 58 REG_LEDCFG2, (ledcfg & 0xf0) | BIT(5) | BIT(6)); 59 break; 60 case LED_PIN_LED1: 61 rtl_write_byte(rtlpriv, REG_LEDCFG2, (ledcfg & 0x0f) | BIT(5)); 62 break; 63 default: 64 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, 65 "switch case not processed\n"); 66 break; 67 } 68 pled->ledon = true; 69} 70 71void rtl92cu_sw_led_off(struct ieee80211_hw *hw, struct rtl_led *pled) 72{ 73 struct rtl_priv *rtlpriv = rtl_priv(hw); 74 struct rtl_usb_priv *usbpriv = rtl_usbpriv(hw); 75 u8 ledcfg; 76 77 RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD, "LedAddr:%X ledpin=%d\n", 78 REG_LEDCFG2, pled->ledpin); 79 ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG2); 80 switch (pled->ledpin) { 81 case LED_PIN_GPIO0: 82 break; 83 case LED_PIN_LED0: 84 ledcfg &= 0xf0; 85 if (usbpriv->ledctl.led_opendrain) 86 rtl_write_byte(rtlpriv, REG_LEDCFG2, 87 (ledcfg | BIT(1) | BIT(5) | BIT(6))); 88 else 89 rtl_write_byte(rtlpriv, REG_LEDCFG2, 90 (ledcfg | BIT(3) | BIT(5) | BIT(6))); 91 break; 92 case LED_PIN_LED1: 93 ledcfg &= 0x0f; 94 rtl_write_byte(rtlpriv, REG_LEDCFG2, (ledcfg | BIT(3))); 95 break; 96 default: 97 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, 98 "switch case not processed\n"); 99 break; 100 } 101 pled->ledon = false; 102} 103 104void rtl92cu_init_sw_leds(struct ieee80211_hw *hw) 105{ 106 struct rtl_usb_priv *usbpriv = rtl_usbpriv(hw); 107 _rtl92cu_init_led(hw, &(usbpriv->ledctl.sw_led0), LED_PIN_LED0); 108 _rtl92cu_init_led(hw, &(usbpriv->ledctl.sw_led1), LED_PIN_LED1); 109} 110 111void rtl92cu_deinit_sw_leds(struct ieee80211_hw *hw) 112{ 113 struct rtl_usb_priv *usbpriv = rtl_usbpriv(hw); 114 _rtl92cu_deInit_led(&(usbpriv->ledctl.sw_led0)); 115 _rtl92cu_deInit_led(&(usbpriv->ledctl.sw_led1)); 116} 117 118static void _rtl92cu_sw_led_control(struct ieee80211_hw *hw, 119 enum led_ctl_mode ledaction) 120{ 121} 122 123void rtl92cu_led_control(struct ieee80211_hw *hw, 124 enum led_ctl_mode ledaction) 125{ 126 struct rtl_priv *rtlpriv = rtl_priv(hw); 127 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); 128 129 if ((ppsc->rfoff_reason > RF_CHANGE_BY_PS) && 130 (ledaction == LED_CTL_TX || 131 ledaction == LED_CTL_RX || 132 ledaction == LED_CTL_SITE_SURVEY || 133 ledaction == LED_CTL_LINK || 134 ledaction == LED_CTL_NO_LINK || 135 ledaction == LED_CTL_START_TO_LINK || 136 ledaction == LED_CTL_POWER_ON)) { 137 return; 138 } 139 RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD, "ledaction %d\n", ledaction); 140 _rtl92cu_sw_led_control(hw, ledaction); 141} 142