1647f21b1SLarry Finger // SPDX-License-Identifier: GPL-2.0
2647f21b1SLarry Finger /* Copyright(c) 2009-2014 Realtek Corporation.*/
3f1d2b4d3SLarry Finger
4f1d2b4d3SLarry Finger #include "../wifi.h"
5f1d2b4d3SLarry Finger #include "../pci.h"
6f1d2b4d3SLarry Finger #include "reg.h"
7f1d2b4d3SLarry Finger #include "led.h"
8f1d2b4d3SLarry Finger
rtl92ee_sw_led_on(struct ieee80211_hw * hw,enum rtl_led_pin pin)9*084f1f55SDmitry Antipov void rtl92ee_sw_led_on(struct ieee80211_hw *hw, enum rtl_led_pin pin)
10f1d2b4d3SLarry Finger {
11f1d2b4d3SLarry Finger u32 ledcfg;
12f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw);
13f1d2b4d3SLarry Finger
14e24a2a87SLarry Finger rtl_dbg(rtlpriv, COMP_LED, DBG_LOUD,
15*084f1f55SDmitry Antipov "LedAddr:%X ledpin=%d\n", REG_LEDCFG2, pin);
16f1d2b4d3SLarry Finger
17*084f1f55SDmitry Antipov switch (pin) {
18f1d2b4d3SLarry Finger case LED_PIN_GPIO0:
19f1d2b4d3SLarry Finger break;
20f1d2b4d3SLarry Finger case LED_PIN_LED0:
21f1d2b4d3SLarry Finger ledcfg = rtl_read_dword(rtlpriv , REG_GPIO_PIN_CTRL);
22f1d2b4d3SLarry Finger ledcfg &= ~BIT(13);
23f1d2b4d3SLarry Finger ledcfg |= BIT(21);
24f1d2b4d3SLarry Finger ledcfg &= ~BIT(29);
25f1d2b4d3SLarry Finger
26f1d2b4d3SLarry Finger rtl_write_dword(rtlpriv, REG_GPIO_PIN_CTRL, ledcfg);
27f1d2b4d3SLarry Finger
28f1d2b4d3SLarry Finger break;
29f1d2b4d3SLarry Finger case LED_PIN_LED1:
30f1d2b4d3SLarry Finger
31f1d2b4d3SLarry Finger break;
32f1d2b4d3SLarry Finger default:
33e24a2a87SLarry Finger rtl_dbg(rtlpriv, COMP_ERR, DBG_LOUD,
34*084f1f55SDmitry Antipov "switch case %#x not processed\n", pin);
35f1d2b4d3SLarry Finger break;
36f1d2b4d3SLarry Finger }
37f1d2b4d3SLarry Finger }
38f1d2b4d3SLarry Finger
rtl92ee_sw_led_off(struct ieee80211_hw * hw,enum rtl_led_pin pin)39*084f1f55SDmitry Antipov void rtl92ee_sw_led_off(struct ieee80211_hw *hw, enum rtl_led_pin pin)
40f1d2b4d3SLarry Finger {
41f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw);
42f1d2b4d3SLarry Finger u32 ledcfg;
43f1d2b4d3SLarry Finger
44e24a2a87SLarry Finger rtl_dbg(rtlpriv, COMP_LED, DBG_LOUD,
45*084f1f55SDmitry Antipov "LedAddr:%X ledpin=%d\n", REG_LEDCFG2, pin);
46f1d2b4d3SLarry Finger
47*084f1f55SDmitry Antipov switch (pin) {
48f1d2b4d3SLarry Finger case LED_PIN_GPIO0:
49f1d2b4d3SLarry Finger break;
50f1d2b4d3SLarry Finger case LED_PIN_LED0:
51f1d2b4d3SLarry Finger
52f1d2b4d3SLarry Finger ledcfg = rtl_read_dword(rtlpriv , REG_GPIO_PIN_CTRL);
53f1d2b4d3SLarry Finger ledcfg |= ~BIT(21);
54f1d2b4d3SLarry Finger ledcfg &= ~BIT(29);
55f1d2b4d3SLarry Finger rtl_write_dword(rtlpriv, REG_GPIO_PIN_CTRL, ledcfg);
56f1d2b4d3SLarry Finger
57f1d2b4d3SLarry Finger break;
58f1d2b4d3SLarry Finger case LED_PIN_LED1:
59f1d2b4d3SLarry Finger
60f1d2b4d3SLarry Finger break;
61f1d2b4d3SLarry Finger default:
62e24a2a87SLarry Finger rtl_dbg(rtlpriv, COMP_ERR, DBG_LOUD,
63*084f1f55SDmitry Antipov "switch case %#x not processed\n", pin);
64f1d2b4d3SLarry Finger break;
65f1d2b4d3SLarry Finger }
66f1d2b4d3SLarry Finger }
67f1d2b4d3SLarry Finger
_rtl92ee_sw_led_control(struct ieee80211_hw * hw,enum led_ctl_mode ledaction)68f1d2b4d3SLarry Finger static void _rtl92ee_sw_led_control(struct ieee80211_hw *hw,
69f1d2b4d3SLarry Finger enum led_ctl_mode ledaction)
70f1d2b4d3SLarry Finger {
71d5efe153SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw);
72*084f1f55SDmitry Antipov enum rtl_led_pin pin0 = rtlpriv->ledctl.sw_led0;
73f1d2b4d3SLarry Finger
74f1d2b4d3SLarry Finger switch (ledaction) {
75f1d2b4d3SLarry Finger case LED_CTL_POWER_ON:
76f1d2b4d3SLarry Finger case LED_CTL_LINK:
77f1d2b4d3SLarry Finger case LED_CTL_NO_LINK:
78*084f1f55SDmitry Antipov rtl92ee_sw_led_on(hw, pin0);
79f1d2b4d3SLarry Finger break;
80f1d2b4d3SLarry Finger case LED_CTL_POWER_OFF:
81*084f1f55SDmitry Antipov rtl92ee_sw_led_off(hw, pin0);
82f1d2b4d3SLarry Finger break;
83f1d2b4d3SLarry Finger default:
84f1d2b4d3SLarry Finger break;
85f1d2b4d3SLarry Finger }
86f1d2b4d3SLarry Finger }
87f1d2b4d3SLarry Finger
rtl92ee_led_control(struct ieee80211_hw * hw,enum led_ctl_mode ledaction)88f1d2b4d3SLarry Finger void rtl92ee_led_control(struct ieee80211_hw *hw, enum led_ctl_mode ledaction)
89f1d2b4d3SLarry Finger {
90f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw);
91f1d2b4d3SLarry Finger struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
92f1d2b4d3SLarry Finger
93f1d2b4d3SLarry Finger if ((ppsc->rfoff_reason > RF_CHANGE_BY_PS) &&
94f1d2b4d3SLarry Finger (ledaction == LED_CTL_TX ||
95f1d2b4d3SLarry Finger ledaction == LED_CTL_RX ||
96f1d2b4d3SLarry Finger ledaction == LED_CTL_SITE_SURVEY ||
97f1d2b4d3SLarry Finger ledaction == LED_CTL_LINK ||
98f1d2b4d3SLarry Finger ledaction == LED_CTL_NO_LINK ||
99f1d2b4d3SLarry Finger ledaction == LED_CTL_START_TO_LINK ||
100f1d2b4d3SLarry Finger ledaction == LED_CTL_POWER_ON)) {
101f1d2b4d3SLarry Finger return;
102f1d2b4d3SLarry Finger }
103e24a2a87SLarry Finger rtl_dbg(rtlpriv, COMP_LED, DBG_TRACE, "ledaction %d,\n", ledaction);
104f1d2b4d3SLarry Finger _rtl92ee_sw_led_control(hw, ledaction);
105f1d2b4d3SLarry Finger }
106