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 26 #include "../wifi.h" 27 #include "../pci.h" 28 #include "reg.h" 29 #include "led.h" 30 31 static void _rtl8723e_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 39 void rtl8723e_sw_led_on(struct ieee80211_hw *hw, struct rtl_led *pled) 40 { 41 u8 ledcfg; 42 struct rtl_priv *rtlpriv = rtl_priv(hw); 43 44 RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD, 45 "LedAddr:%X ledpin=%d\n", REG_LEDCFG2, pled->ledpin); 46 47 switch (pled->ledpin) { 48 case LED_PIN_GPIO0: 49 break; 50 case LED_PIN_LED0: 51 ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG2); 52 ledcfg &= ~BIT(6); 53 rtl_write_byte(rtlpriv, 54 REG_LEDCFG2, (ledcfg & 0xf0) | BIT(5)); 55 break; 56 case LED_PIN_LED1: 57 ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG1); 58 rtl_write_byte(rtlpriv, REG_LEDCFG1, ledcfg & 0x10); 59 break; 60 default: 61 pr_err("switch case %#x not processed\n", 62 pled->ledpin); 63 break; 64 } 65 pled->ledon = true; 66 } 67 68 void rtl8723e_sw_led_off(struct ieee80211_hw *hw, struct rtl_led *pled) 69 { 70 struct rtl_priv *rtlpriv = rtl_priv(hw); 71 u8 ledcfg; 72 73 RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD, 74 "LedAddr:%X ledpin=%d\n", REG_LEDCFG2, pled->ledpin); 75 76 ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG2); 77 78 switch (pled->ledpin) { 79 case LED_PIN_GPIO0: 80 break; 81 case LED_PIN_LED0: 82 ledcfg &= 0xf0; 83 if (rtlpriv->ledctl.led_opendrain) { 84 ledcfg &= 0x90; /* Set to software control. */ 85 rtl_write_byte(rtlpriv, REG_LEDCFG2, (ledcfg|BIT(3))); 86 ledcfg = rtl_read_byte(rtlpriv, REG_MAC_PINMUX_CFG); 87 ledcfg &= 0xFE; 88 rtl_write_byte(rtlpriv, REG_MAC_PINMUX_CFG, ledcfg); 89 } else { 90 ledcfg &= ~BIT(6); 91 rtl_write_byte(rtlpriv, REG_LEDCFG2, 92 (ledcfg | BIT(3) | BIT(5))); 93 } 94 break; 95 case LED_PIN_LED1: 96 ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG1); 97 ledcfg &= 0x10; /* Set to software control. */ 98 rtl_write_byte(rtlpriv, REG_LEDCFG1, ledcfg|BIT(3)); 99 100 break; 101 default: 102 pr_err("switch case %#x not processed\n", 103 pled->ledpin); 104 break; 105 } 106 pled->ledon = false; 107 } 108 109 void rtl8723e_init_sw_leds(struct ieee80211_hw *hw) 110 { 111 struct rtl_priv *rtlpriv = rtl_priv(hw); 112 113 _rtl8723e_init_led(hw, &rtlpriv->ledctl.sw_led0, LED_PIN_LED0); 114 _rtl8723e_init_led(hw, &rtlpriv->ledctl.sw_led1, LED_PIN_LED1); 115 } 116 117 static void _rtl8723e_sw_led_control(struct ieee80211_hw *hw, 118 enum led_ctl_mode ledaction) 119 { 120 struct rtl_priv *rtlpriv = rtl_priv(hw); 121 struct rtl_led *pled0 = &rtlpriv->ledctl.sw_led0; 122 123 switch (ledaction) { 124 case LED_CTL_POWER_ON: 125 case LED_CTL_LINK: 126 case LED_CTL_NO_LINK: 127 rtl8723e_sw_led_on(hw, pled0); 128 break; 129 case LED_CTL_POWER_OFF: 130 rtl8723e_sw_led_off(hw, pled0); 131 break; 132 default: 133 break; 134 } 135 } 136 137 void rtl8723e_led_control(struct ieee80211_hw *hw, 138 enum led_ctl_mode ledaction) 139 { 140 struct rtl_priv *rtlpriv = rtl_priv(hw); 141 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); 142 143 if ((ppsc->rfoff_reason > RF_CHANGE_BY_PS) && 144 (ledaction == LED_CTL_TX || 145 ledaction == LED_CTL_RX || 146 ledaction == LED_CTL_SITE_SURVEY || 147 ledaction == LED_CTL_LINK || 148 ledaction == LED_CTL_NO_LINK || 149 ledaction == LED_CTL_START_TO_LINK || 150 ledaction == LED_CTL_POWER_ON)) { 151 return; 152 } 153 RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD, "ledaction %d,\n", 154 ledaction); 155 _rtl8723e_sw_led_control(hw, ledaction); 156 } 157