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 rtl92de_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 switch (pled->ledpin) { 48 case LED_PIN_GPIO0: 49 break; 50 case LED_PIN_LED0: 51 ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG2); 52 53 if ((rtlpriv->efuse.eeprom_did == 0x8176) || 54 (rtlpriv->efuse.eeprom_did == 0x8193)) 55 /* BIT7 of REG_LEDCFG2 should be set to 56 * make sure we could emit the led2. */ 57 rtl_write_byte(rtlpriv, REG_LEDCFG2, (ledcfg & 0xf0) | 58 BIT(7) | BIT(5) | BIT(6)); 59 else 60 rtl_write_byte(rtlpriv, REG_LEDCFG2, (ledcfg & 0xf0) | 61 BIT(7) | BIT(5)); 62 break; 63 case LED_PIN_LED1: 64 ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG1); 65 66 rtl_write_byte(rtlpriv, REG_LEDCFG2, (ledcfg & 0x0f) | BIT(5)); 67 break; 68 default: 69 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, 70 "switch case %#x not processed\n", pled->ledpin); 71 break; 72 } 73 pled->ledon = true; 74 } 75 76 void rtl92de_sw_led_off(struct ieee80211_hw *hw, struct rtl_led *pled) 77 { 78 struct rtl_priv *rtlpriv = rtl_priv(hw); 79 struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw); 80 u8 ledcfg; 81 82 RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD, "LedAddr:%X ledpin=%d\n", 83 REG_LEDCFG2, pled->ledpin); 84 85 ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG2); 86 87 switch (pled->ledpin) { 88 case LED_PIN_GPIO0: 89 break; 90 case LED_PIN_LED0: 91 ledcfg &= 0xf0; 92 if (pcipriv->ledctl.led_opendrain) 93 rtl_write_byte(rtlpriv, REG_LEDCFG2, 94 (ledcfg | BIT(1) | BIT(5) | BIT(6))); 95 else 96 rtl_write_byte(rtlpriv, REG_LEDCFG2, 97 (ledcfg | BIT(3) | BIT(5) | BIT(6))); 98 break; 99 case LED_PIN_LED1: 100 ledcfg &= 0x0f; 101 rtl_write_byte(rtlpriv, REG_LEDCFG2, (ledcfg | BIT(3))); 102 break; 103 default: 104 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, 105 "switch case %#x not processed\n", pled->ledpin); 106 break; 107 } 108 pled->ledon = false; 109 } 110 111 void rtl92de_init_sw_leds(struct ieee80211_hw *hw) 112 { 113 struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw); 114 _rtl92ce_init_led(hw, &(pcipriv->ledctl.sw_led0), LED_PIN_LED0); 115 _rtl92ce_init_led(hw, &(pcipriv->ledctl.sw_led1), LED_PIN_LED1); 116 } 117 118 static void _rtl92ce_sw_led_control(struct ieee80211_hw *hw, 119 enum led_ctl_mode ledaction) 120 { 121 struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw); 122 struct rtl_led *pLed0 = &(pcipriv->ledctl.sw_led0); 123 switch (ledaction) { 124 case LED_CTL_POWER_ON: 125 case LED_CTL_LINK: 126 case LED_CTL_NO_LINK: 127 rtl92de_sw_led_on(hw, pLed0); 128 break; 129 case LED_CTL_POWER_OFF: 130 rtl92de_sw_led_off(hw, pLed0); 131 break; 132 default: 133 break; 134 } 135 } 136 137 void rtl92de_led_control(struct ieee80211_hw *hw, enum led_ctl_mode ledaction) 138 { 139 struct rtl_priv *rtlpriv = rtl_priv(hw); 140 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); 141 142 if ((ppsc->rfoff_reason > RF_CHANGE_BY_PS) && 143 (ledaction == LED_CTL_TX || 144 ledaction == LED_CTL_RX || 145 ledaction == LED_CTL_SITE_SURVEY || 146 ledaction == LED_CTL_LINK || 147 ledaction == LED_CTL_NO_LINK || 148 ledaction == LED_CTL_START_TO_LINK || 149 ledaction == LED_CTL_POWER_ON)) { 150 return; 151 } 152 RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD, "ledaction %d,\n", ledaction); 153 154 _rtl92ce_sw_led_control(hw, ledaction); 155 } 156