xref: /linux/drivers/net/wireless/realtek/rtlwifi/rtl8192se/led.c (revision e5c86679d5e864947a52fb31e45a425dea3e7fa9)
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 _rtl92se_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 rtl92se_init_sw_leds(struct ieee80211_hw *hw)
40 {
41 	struct rtl_priv *rtlpriv = rtl_priv(hw);
42 
43 	_rtl92se_init_led(hw, &rtlpriv->ledctl.sw_led0, LED_PIN_LED0);
44 	_rtl92se_init_led(hw, &rtlpriv->ledctl.sw_led1, LED_PIN_LED1);
45 }
46 
47 void rtl92se_sw_led_on(struct ieee80211_hw *hw, struct rtl_led *pled)
48 {
49 	u8 ledcfg;
50 	struct rtl_priv *rtlpriv = rtl_priv(hw);
51 
52 	RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD, "LedAddr:%X ledpin=%d\n",
53 		 LEDCFG, pled->ledpin);
54 
55 	ledcfg = rtl_read_byte(rtlpriv, LEDCFG);
56 
57 	switch (pled->ledpin) {
58 	case LED_PIN_GPIO0:
59 		break;
60 	case LED_PIN_LED0:
61 		rtl_write_byte(rtlpriv, LEDCFG, ledcfg & 0xf0);
62 		break;
63 	case LED_PIN_LED1:
64 		rtl_write_byte(rtlpriv, LEDCFG, ledcfg & 0x0f);
65 		break;
66 	default:
67 		pr_err("switch case %#x not processed\n",
68 		       pled->ledpin);
69 		break;
70 	}
71 	pled->ledon = true;
72 }
73 
74 void rtl92se_sw_led_off(struct ieee80211_hw *hw, struct rtl_led *pled)
75 {
76 	struct rtl_priv *rtlpriv;
77 	u8 ledcfg;
78 
79 	rtlpriv = rtl_priv(hw);
80 	if (!rtlpriv || rtlpriv->max_fw_size)
81 		return;
82 	RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD, "LedAddr:%X ledpin=%d\n",
83 		 LEDCFG, pled->ledpin);
84 
85 	ledcfg = rtl_read_byte(rtlpriv, LEDCFG);
86 
87 	switch (pled->ledpin) {
88 	case LED_PIN_GPIO0:
89 		break;
90 	case LED_PIN_LED0:
91 		ledcfg &= 0xf0;
92 		if (rtlpriv->ledctl.led_opendrain)
93 			rtl_write_byte(rtlpriv, LEDCFG, (ledcfg | BIT(1)));
94 		else
95 			rtl_write_byte(rtlpriv, LEDCFG, (ledcfg | BIT(3)));
96 		break;
97 	case LED_PIN_LED1:
98 		ledcfg &= 0x0f;
99 		rtl_write_byte(rtlpriv, LEDCFG, (ledcfg | BIT(3)));
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 static void _rtl92se_sw_led_control(struct ieee80211_hw *hw,
110 				    enum led_ctl_mode ledaction)
111 {
112 	struct rtl_priv *rtlpriv = rtl_priv(hw);
113 	struct rtl_led *pled0 = &rtlpriv->ledctl.sw_led0;
114 
115 	switch (ledaction) {
116 	case LED_CTL_POWER_ON:
117 	case LED_CTL_LINK:
118 	case LED_CTL_NO_LINK:
119 		rtl92se_sw_led_on(hw, pled0);
120 		break;
121 	case LED_CTL_POWER_OFF:
122 		rtl92se_sw_led_off(hw, pled0);
123 		break;
124 	default:
125 		break;
126 	}
127 }
128 
129 void rtl92se_led_control(struct ieee80211_hw *hw, 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", ledaction);
145 
146 	_rtl92se_sw_led_control(hw, ledaction);
147 }
148 
149