blob: 8283e9b27639f5bd95350fd09652ccfded1888ed [file] [log] [blame]
Larry Finger0c817332010-12-08 11:12:31 -06001/******************************************************************************
2 *
Larry Finger9003a4a2012-01-07 20:46:44 -06003 * Copyright(c) 2009-2012 Realtek Corporation.
Larry Finger0c817332010-12-08 11:12:31 -06004 *
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"
John W. Linville5c405b52010-12-16 15:43:36 -050032#include "reg.h"
33#include "led.h"
Larry Finger0c817332010-12-08 11:12:31 -060034
Chaoming Li228bdfc2011-04-10 18:30:23 -050035static void _rtl92ce_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
Larry Finger0c817332010-12-08 11:12:31 -060043void rtl92ce_sw_led_on(struct ieee80211_hw *hw, struct rtl_led *pled)
44{
45 u8 ledcfg;
46 struct rtl_priv *rtlpriv = rtl_priv(hw);
47
Joe Perchesf30d7502012-01-04 19:40:41 -080048 RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD, "LedAddr:%X ledpin=%d\n",
49 REG_LEDCFG2, pled->ledpin);
Larry Finger0c817332010-12-08 11:12:31 -060050
51 ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG2);
52
53 switch (pled->ledpin) {
54 case LED_PIN_GPIO0:
55 break;
56 case LED_PIN_LED0:
57 rtl_write_byte(rtlpriv,
58 REG_LEDCFG2, (ledcfg & 0xf0) | BIT(5) | BIT(6));
59 break;
60 case LED_PIN_LED1:
61 rtl_write_byte(rtlpriv, REG_LEDCFG2, (ledcfg & 0x0f) | BIT(5));
62 break;
63 default:
64 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
Joe Perchesf30d7502012-01-04 19:40:41 -080065 "switch case not processed\n");
Larry Finger0c817332010-12-08 11:12:31 -060066 break;
67 }
Larry Finger7ea47242011-02-19 16:28:57 -060068 pled->ledon = true;
Larry Finger0c817332010-12-08 11:12:31 -060069}
70
71void rtl92ce_sw_led_off(struct ieee80211_hw *hw, struct rtl_led *pled)
72{
73 struct rtl_priv *rtlpriv = rtl_priv(hw);
74 struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
75 u8 ledcfg;
76
Joe Perchesf30d7502012-01-04 19:40:41 -080077 RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD, "LedAddr:%X ledpin=%d\n",
78 REG_LEDCFG2, pled->ledpin);
Larry Finger0c817332010-12-08 11:12:31 -060079
80 ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG2);
81
82 switch (pled->ledpin) {
83 case LED_PIN_GPIO0:
84 break;
85 case LED_PIN_LED0:
86 ledcfg &= 0xf0;
Mike McCormacke10542c2011-06-20 10:47:51 +090087 if (pcipriv->ledctl.led_opendrain)
Larry Finger0c817332010-12-08 11:12:31 -060088 rtl_write_byte(rtlpriv, REG_LEDCFG2,
89 (ledcfg | BIT(1) | BIT(5) | BIT(6)));
90 else
91 rtl_write_byte(rtlpriv, REG_LEDCFG2,
92 (ledcfg | BIT(3) | BIT(5) | BIT(6)));
93 break;
94 case LED_PIN_LED1:
95 ledcfg &= 0x0f;
96 rtl_write_byte(rtlpriv, REG_LEDCFG2, (ledcfg | BIT(3)));
97 break;
98 default:
99 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
Joe Perchesf30d7502012-01-04 19:40:41 -0800100 "switch case not processed\n");
Larry Finger0c817332010-12-08 11:12:31 -0600101 break;
102 }
Larry Finger7ea47242011-02-19 16:28:57 -0600103 pled->ledon = false;
Larry Finger0c817332010-12-08 11:12:31 -0600104}
105
106void rtl92ce_init_sw_leds(struct ieee80211_hw *hw)
107{
Chaoming Li228bdfc2011-04-10 18:30:23 -0500108 struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
Chaoming Li228bdfc2011-04-10 18:30:23 -0500109 _rtl92ce_init_led(hw, &(pcipriv->ledctl.sw_led0), LED_PIN_LED0);
110 _rtl92ce_init_led(hw, &(pcipriv->ledctl.sw_led1), LED_PIN_LED1);
Larry Finger0c817332010-12-08 11:12:31 -0600111}
112
Chaoming_Li2b8359f2011-04-25 12:53:55 -0500113static void _rtl92ce_sw_led_control(struct ieee80211_hw *hw,
Larry Finger0c817332010-12-08 11:12:31 -0600114 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 rtl92ce_sw_led_on(hw, pLed0);
123 break;
124 case LED_CTL_POWER_OFF:
125 rtl92ce_sw_led_off(hw, pLed0);
126 break;
127 default:
128 break;
129 }
130}
131
132void rtl92ce_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 }
Joe Perchesf30d7502012-01-04 19:40:41 -0800148 RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD, "ledaction %d\n",
149 ledaction);
Larry Finger0c817332010-12-08 11:12:31 -0600150 _rtl92ce_sw_led_control(hw, ledaction);
151}