1 /******************************************************************************
2 *
3 * Copyright(c) 2009-2013 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
_rtl88ee_init_led(struct ieee80211_hw * hw,struct rtl_led * pled,enum rtl_led_pin ledpin)31 static void _rtl88ee_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
rtl88ee_sw_led_on(struct ieee80211_hw * hw,struct rtl_led * pled)39 void rtl88ee_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,
45 "LedAddr:%X ledpin=%d\n", 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 rtl_write_byte(rtlpriv,
53 REG_LEDCFG2, (ledcfg & 0xf0) | BIT(5) | BIT(6));
54 break;
55 case LED_PIN_LED1:
56 ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG1);
57 rtl_write_byte(rtlpriv, REG_LEDCFG1, ledcfg & 0x10);
58 break;
59 default:
60 RT_TRACE(rtlpriv, COMP_ERR, DBG_LOUD,
61 "switch case %#x not processed\n", pled->ledpin);
62 break;
63 }
64 pled->ledon = true;
65 }
66
rtl88ee_sw_led_off(struct ieee80211_hw * hw,struct rtl_led * pled)67 void rtl88ee_sw_led_off(struct ieee80211_hw *hw, struct rtl_led *pled)
68 {
69 struct rtl_priv *rtlpriv = rtl_priv(hw);
70 u8 ledcfg;
71
72 RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD,
73 "LedAddr:%X ledpin=%d\n", REG_LEDCFG2, pled->ledpin);
74
75 switch (pled->ledpin) {
76 case LED_PIN_GPIO0:
77 break;
78 case LED_PIN_LED0:
79 ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG2);
80 ledcfg &= 0xf0;
81 if (rtlpriv->ledctl.led_opendrain) {
82 rtl_write_byte(rtlpriv, REG_LEDCFG2,
83 (ledcfg | BIT(3) | BIT(5) | BIT(6)));
84 ledcfg = rtl_read_byte(rtlpriv, REG_MAC_PINMUX_CFG);
85 rtl_write_byte(rtlpriv, REG_MAC_PINMUX_CFG,
86 (ledcfg & 0xFE));
87 } else
88 rtl_write_byte(rtlpriv, REG_LEDCFG2,
89 (ledcfg | BIT(3) | BIT(5) | BIT(6)));
90 break;
91 case LED_PIN_LED1:
92 ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG1);
93 ledcfg &= 0x10;
94 rtl_write_byte(rtlpriv, REG_LEDCFG1, (ledcfg | BIT(3)));
95 break;
96 default:
97 RT_TRACE(rtlpriv, COMP_ERR, DBG_LOUD,
98 "switch case %#x not processed\n", pled->ledpin);
99 break;
100 }
101 pled->ledon = false;
102 }
103
rtl88ee_init_sw_leds(struct ieee80211_hw * hw)104 void rtl88ee_init_sw_leds(struct ieee80211_hw *hw)
105 {
106 struct rtl_priv *rtlpriv = rtl_priv(hw);
107
108 _rtl88ee_init_led(hw, &rtlpriv->ledctl.sw_led0, LED_PIN_LED0);
109 _rtl88ee_init_led(hw, &rtlpriv->ledctl.sw_led1, LED_PIN_LED1);
110 }
111
_rtl88ee_sw_led_control(struct ieee80211_hw * hw,enum led_ctl_mode ledaction)112 static void _rtl88ee_sw_led_control(struct ieee80211_hw *hw,
113 enum led_ctl_mode ledaction)
114 {
115 struct rtl_priv *rtlpriv = rtl_priv(hw);
116 struct rtl_led *pled0 = &rtlpriv->ledctl.sw_led0;
117
118 switch (ledaction) {
119 case LED_CTL_POWER_ON:
120 case LED_CTL_LINK:
121 case LED_CTL_NO_LINK:
122 rtl88ee_sw_led_on(hw, pled0);
123 break;
124 case LED_CTL_POWER_OFF:
125 rtl88ee_sw_led_off(hw, pled0);
126 break;
127 default:
128 break;
129 }
130 }
131
rtl88ee_led_control(struct ieee80211_hw * hw,enum led_ctl_mode ledaction)132 void rtl88ee_led_control(struct ieee80211_hw *hw,
133 enum led_ctl_mode ledaction)
134 {
135 struct rtl_priv *rtlpriv = rtl_priv(hw);
136 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
137
138 if ((ppsc->rfoff_reason > RF_CHANGE_BY_PS) &&
139 (ledaction == LED_CTL_TX ||
140 ledaction == LED_CTL_RX ||
141 ledaction == LED_CTL_SITE_SURVEY ||
142 ledaction == LED_CTL_LINK ||
143 ledaction == LED_CTL_NO_LINK ||
144 ledaction == LED_CTL_START_TO_LINK ||
145 ledaction == LED_CTL_POWER_ON)) {
146 return;
147 }
148 RT_TRACE(rtlpriv, COMP_LED, DBG_TRACE, "ledaction %d,\n",
149 ledaction);
150 _rtl88ee_sw_led_control(hw, ledaction);
151 }
152