1 /******************************************************************************
3 * Copyright(c) 2009-2012 Realtek Corporation.
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.
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
14 * The full GNU General Public License is included in this distribution in the
15 * file called LICENSE.
17 * Contact Information:
18 * wlanfae <wlanfae@realtek.com>
19 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
20 * Hsinchu 300, Taiwan.
22 * Larry Finger <Larry.Finger@lwfinger.net>
24 *****************************************************************************/
31 static void _rtl92ce_init_led(struct ieee80211_hw
*hw
,
32 struct rtl_led
*pled
, enum rtl_led_pin ledpin
)
35 pled
->ledpin
= ledpin
;
39 void rtl92de_sw_led_on(struct ieee80211_hw
*hw
, struct rtl_led
*pled
)
42 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
44 RT_TRACE(rtlpriv
, COMP_LED
, DBG_LOUD
, "LedAddr:%X ledpin=%d\n",
45 REG_LEDCFG2
, pled
->ledpin
);
47 switch (pled
->ledpin
) {
51 ledcfg
= rtl_read_byte(rtlpriv
, REG_LEDCFG2
);
53 if ((rtlpriv
->efuse
.eeprom_did
== 0x8176) ||
54 (rtlpriv
->efuse
.eeprom_did
== 0x8193))
55 /* BIT7 of REG_LEDCFG2 should be set to
56 * make sure we could emit the led2. */
57 rtl_write_byte(rtlpriv
, REG_LEDCFG2
, (ledcfg
& 0xf0) |
58 BIT(7) | BIT(5) | BIT(6));
60 rtl_write_byte(rtlpriv
, REG_LEDCFG2
, (ledcfg
& 0xf0) |
64 ledcfg
= rtl_read_byte(rtlpriv
, REG_LEDCFG1
);
66 rtl_write_byte(rtlpriv
, REG_LEDCFG2
, (ledcfg
& 0x0f) | BIT(5));
69 pr_err("switch case %#x not processed\n",
76 void rtl92de_sw_led_off(struct ieee80211_hw
*hw
, struct rtl_led
*pled
)
78 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
81 RT_TRACE(rtlpriv
, COMP_LED
, DBG_LOUD
, "LedAddr:%X ledpin=%d\n",
82 REG_LEDCFG2
, pled
->ledpin
);
84 ledcfg
= rtl_read_byte(rtlpriv
, REG_LEDCFG2
);
86 switch (pled
->ledpin
) {
91 if (rtlpriv
->ledctl
.led_opendrain
)
92 rtl_write_byte(rtlpriv
, REG_LEDCFG2
,
93 (ledcfg
| BIT(1) | BIT(5) | BIT(6)));
95 rtl_write_byte(rtlpriv
, REG_LEDCFG2
,
96 (ledcfg
| BIT(3) | BIT(5) | BIT(6)));
100 rtl_write_byte(rtlpriv
, REG_LEDCFG2
, (ledcfg
| BIT(3)));
103 pr_err("switch case %#x not processed\n",
110 void rtl92de_init_sw_leds(struct ieee80211_hw
*hw
)
112 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
114 _rtl92ce_init_led(hw
, &rtlpriv
->ledctl
.sw_led0
, LED_PIN_LED0
);
115 _rtl92ce_init_led(hw
, &rtlpriv
->ledctl
.sw_led1
, LED_PIN_LED1
);
118 static void _rtl92ce_sw_led_control(struct ieee80211_hw
*hw
,
119 enum led_ctl_mode ledaction
)
121 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
122 struct rtl_led
*pled0
= &rtlpriv
->ledctl
.sw_led0
;
125 case LED_CTL_POWER_ON
:
127 case LED_CTL_NO_LINK
:
128 rtl92de_sw_led_on(hw
, pled0
);
130 case LED_CTL_POWER_OFF
:
131 rtl92de_sw_led_off(hw
, pled0
);
138 void rtl92de_led_control(struct ieee80211_hw
*hw
, enum led_ctl_mode ledaction
)
140 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
141 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
143 if ((ppsc
->rfoff_reason
> RF_CHANGE_BY_PS
) &&
144 (ledaction
== LED_CTL_TX
||
145 ledaction
== LED_CTL_RX
||
146 ledaction
== LED_CTL_SITE_SURVEY
||
147 ledaction
== LED_CTL_LINK
||
148 ledaction
== LED_CTL_NO_LINK
||
149 ledaction
== LED_CTL_START_TO_LINK
||
150 ledaction
== LED_CTL_POWER_ON
)) {
153 RT_TRACE(rtlpriv
, COMP_LED
, DBG_LOUD
, "ledaction %d,\n", ledaction
);
155 _rtl92ce_sw_led_control(hw
, ledaction
);