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