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