blob: 4be787e5327906708efb05ab202ca82c1f792032 [file] [log] [blame]
Chaoming Lif53d5a72011-06-10 15:10:10 -05001/******************************************************************************
2 *
Larry Finger6a57b082012-01-07 20:46:46 -06003 * Copyright(c) 2009-2012 Realtek Corporation.
Chaoming Lif53d5a72011-06-10 15:10:10 -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 *
Chaoming Lif53d5a72011-06-10 15:10:10 -050014 * 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
31static void _rtl92ce_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
Larry Fingerab049fb2011-06-28 18:55:50 -050039void rtl92de_sw_led_on(struct ieee80211_hw *hw, struct rtl_led *pled)
Chaoming Lif53d5a72011-06-10 15:10:10 -050040{
41 u8 ledcfg;
42 struct rtl_priv *rtlpriv = rtl_priv(hw);
43
Joe Perchesf30d7502012-01-04 19:40:41 -080044 RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD, "LedAddr:%X ledpin=%d\n",
45 REG_LEDCFG2, pled->ledpin);
Chaoming Lif53d5a72011-06-10 15:10:10 -050046
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
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));
59 else
60 rtl_write_byte(rtlpriv, REG_LEDCFG2, (ledcfg & 0xf0) |
61 BIT(7) | BIT(5));
62 break;
63 case LED_PIN_LED1:
64 ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG1);
65
66 rtl_write_byte(rtlpriv, REG_LEDCFG2, (ledcfg & 0x0f) | BIT(5));
67 break;
68 default:
Larry Fingerb8c79f42016-12-15 12:23:05 -060069 pr_err("switch case %#x not processed\n",
70 pled->ledpin);
Chaoming Lif53d5a72011-06-10 15:10:10 -050071 break;
72 }
73 pled->ledon = true;
74}
75
Larry Fingerab049fb2011-06-28 18:55:50 -050076void rtl92de_sw_led_off(struct ieee80211_hw *hw, struct rtl_led *pled)
Chaoming Lif53d5a72011-06-10 15:10:10 -050077{
78 struct rtl_priv *rtlpriv = rtl_priv(hw);
79 struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
80 u8 ledcfg;
81
Joe Perchesf30d7502012-01-04 19:40:41 -080082 RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD, "LedAddr:%X ledpin=%d\n",
83 REG_LEDCFG2, pled->ledpin);
Chaoming Lif53d5a72011-06-10 15:10:10 -050084
85 ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG2);
86
87 switch (pled->ledpin) {
88 case LED_PIN_GPIO0:
89 break;
90 case LED_PIN_LED0:
91 ledcfg &= 0xf0;
Larry Finger9928c7d2011-06-30 16:47:11 -050092 if (pcipriv->ledctl.led_opendrain)
Chaoming Lif53d5a72011-06-10 15:10:10 -050093 rtl_write_byte(rtlpriv, REG_LEDCFG2,
94 (ledcfg | BIT(1) | BIT(5) | BIT(6)));
95 else
96 rtl_write_byte(rtlpriv, REG_LEDCFG2,
97 (ledcfg | BIT(3) | BIT(5) | BIT(6)));
98 break;
99 case LED_PIN_LED1:
100 ledcfg &= 0x0f;
101 rtl_write_byte(rtlpriv, REG_LEDCFG2, (ledcfg | BIT(3)));
102 break;
103 default:
Larry Fingerb8c79f42016-12-15 12:23:05 -0600104 pr_err("switch case %#x not processed\n",
105 pled->ledpin);
Chaoming Lif53d5a72011-06-10 15:10:10 -0500106 break;
107 }
108 pled->ledon = false;
109}
110
111void rtl92de_init_sw_leds(struct ieee80211_hw *hw)
112{
113 struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
114 _rtl92ce_init_led(hw, &(pcipriv->ledctl.sw_led0), LED_PIN_LED0);
115 _rtl92ce_init_led(hw, &(pcipriv->ledctl.sw_led1), LED_PIN_LED1);
116}
117
118static void _rtl92ce_sw_led_control(struct ieee80211_hw *hw,
119 enum led_ctl_mode ledaction)
120{
121 struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
122 struct rtl_led *pLed0 = &(pcipriv->ledctl.sw_led0);
123 switch (ledaction) {
124 case LED_CTL_POWER_ON:
125 case LED_CTL_LINK:
126 case LED_CTL_NO_LINK:
Larry Fingerab049fb2011-06-28 18:55:50 -0500127 rtl92de_sw_led_on(hw, pLed0);
Chaoming Lif53d5a72011-06-10 15:10:10 -0500128 break;
129 case LED_CTL_POWER_OFF:
Larry Fingerab049fb2011-06-28 18:55:50 -0500130 rtl92de_sw_led_off(hw, pLed0);
Chaoming Lif53d5a72011-06-10 15:10:10 -0500131 break;
132 default:
133 break;
134 }
135}
136
137void rtl92de_led_control(struct ieee80211_hw *hw, enum led_ctl_mode ledaction)
138{
139 struct rtl_priv *rtlpriv = rtl_priv(hw);
140 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
141
142 if ((ppsc->rfoff_reason > RF_CHANGE_BY_PS) &&
143 (ledaction == LED_CTL_TX ||
144 ledaction == LED_CTL_RX ||
145 ledaction == LED_CTL_SITE_SURVEY ||
146 ledaction == LED_CTL_LINK ||
147 ledaction == LED_CTL_NO_LINK ||
148 ledaction == LED_CTL_START_TO_LINK ||
149 ledaction == LED_CTL_POWER_ON)) {
150 return;
151 }
Joe Perchesf30d7502012-01-04 19:40:41 -0800152 RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD, "ledaction %d,\n", ledaction);
Chaoming Lif53d5a72011-06-10 15:10:10 -0500153
154 _rtl92ce_sw_led_control(hw, ledaction);
155}