blob: 9849cb988186808584ddc89c80e65e1adcc2f2e4 [file] [log] [blame]
Chaoming Li29338002011-05-03 09:48:25 -05001/******************************************************************************
2 *
Larry Fingerca742cd2012-01-07 20:46:47 -06003 * Copyright(c) 2009-2012 Realtek Corporation.
Chaoming Li29338002011-05-03 09:48:25 -05004 *
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
35static void _rtl92se_init_led(struct ieee80211_hw *hw,
36 struct rtl_led *pled, enum rtl_led_pin ledpin)
37{
38 pled->hw = hw;
39 pled->ledpin = ledpin;
40 pled->ledon = false;
41}
42
43void rtl92se_init_sw_leds(struct ieee80211_hw *hw)
44{
45 struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
46 _rtl92se_init_led(hw, &(pcipriv->ledctl.sw_led0), LED_PIN_LED0);
47 _rtl92se_init_led(hw, &(pcipriv->ledctl.sw_led1), LED_PIN_LED1);
48}
49
50void rtl92se_sw_led_on(struct ieee80211_hw *hw, struct rtl_led *pled)
51{
52 u8 ledcfg;
53 struct rtl_priv *rtlpriv = rtl_priv(hw);
54
Joe Perchesf30d7502012-01-04 19:40:41 -080055 RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD, "LedAddr:%X ledpin=%d\n",
56 LEDCFG, pled->ledpin);
Chaoming Li29338002011-05-03 09:48:25 -050057
58 ledcfg = rtl_read_byte(rtlpriv, LEDCFG);
59
60 switch (pled->ledpin) {
61 case LED_PIN_GPIO0:
62 break;
63 case LED_PIN_LED0:
64 rtl_write_byte(rtlpriv, LEDCFG, ledcfg & 0xf0);
65 break;
66 case LED_PIN_LED1:
67 rtl_write_byte(rtlpriv, LEDCFG, ledcfg & 0x0f);
68 break;
69 default:
70 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
Joe Perchesad574882016-09-23 11:27:19 -070071 "switch case %#x not processed\n", pled->ledpin);
Chaoming Li29338002011-05-03 09:48:25 -050072 break;
73 }
74 pled->ledon = true;
75}
76
77void rtl92se_sw_led_off(struct ieee80211_hw *hw, struct rtl_led *pled)
78{
Larry Fingerb0302ab2012-01-30 09:54:49 -060079 struct rtl_priv *rtlpriv;
Chaoming Li29338002011-05-03 09:48:25 -050080 struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
81 u8 ledcfg;
82
Larry Fingerb0302ab2012-01-30 09:54:49 -060083 rtlpriv = rtl_priv(hw);
84 if (!rtlpriv || rtlpriv->max_fw_size)
85 return;
Joe Perchesf30d7502012-01-04 19:40:41 -080086 RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD, "LedAddr:%X ledpin=%d\n",
87 LEDCFG, pled->ledpin);
Chaoming Li29338002011-05-03 09:48:25 -050088
89 ledcfg = rtl_read_byte(rtlpriv, LEDCFG);
90
91 switch (pled->ledpin) {
92 case LED_PIN_GPIO0:
93 break;
94 case LED_PIN_LED0:
95 ledcfg &= 0xf0;
Mike McCormacke10542c2011-06-20 10:47:51 +090096 if (pcipriv->ledctl.led_opendrain)
Chaoming Li29338002011-05-03 09:48:25 -050097 rtl_write_byte(rtlpriv, LEDCFG, (ledcfg | BIT(1)));
98 else
99 rtl_write_byte(rtlpriv, LEDCFG, (ledcfg | BIT(3)));
100 break;
101 case LED_PIN_LED1:
102 ledcfg &= 0x0f;
103 rtl_write_byte(rtlpriv, LEDCFG, (ledcfg | BIT(3)));
104 break;
105 default:
106 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
Joe Perchesad574882016-09-23 11:27:19 -0700107 "switch case %#x not processed\n", pled->ledpin);
Chaoming Li29338002011-05-03 09:48:25 -0500108 break;
109 }
110 pled->ledon = false;
111}
112
113static void _rtl92se_sw_led_control(struct ieee80211_hw *hw,
114 enum led_ctl_mode ledaction)
115{
116 struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
117 struct rtl_led *pLed0 = &(pcipriv->ledctl.sw_led0);
118 switch (ledaction) {
119 case LED_CTL_POWER_ON:
120 case LED_CTL_LINK:
121 case LED_CTL_NO_LINK:
122 rtl92se_sw_led_on(hw, pLed0);
123 break;
124 case LED_CTL_POWER_OFF:
125 rtl92se_sw_led_off(hw, pLed0);
126 break;
127 default:
128 break;
129 }
130}
131
132void rtl92se_led_control(struct ieee80211_hw *hw, enum led_ctl_mode ledaction)
133{
134 struct rtl_priv *rtlpriv = rtl_priv(hw);
135 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
136
137 if ((ppsc->rfoff_reason > RF_CHANGE_BY_PS) &&
138 (ledaction == LED_CTL_TX ||
139 ledaction == LED_CTL_RX ||
140 ledaction == LED_CTL_SITE_SURVEY ||
141 ledaction == LED_CTL_LINK ||
142 ledaction == LED_CTL_NO_LINK ||
143 ledaction == LED_CTL_START_TO_LINK ||
144 ledaction == LED_CTL_POWER_ON)) {
145 return;
146 }
Joe Perchesf30d7502012-01-04 19:40:41 -0800147 RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD, "ledaction %d\n", ledaction);
Chaoming Li29338002011-05-03 09:48:25 -0500148
149 _rtl92se_sw_led_control(hw, ledaction);
150}
151