1fbb35286SLarry Finger // SPDX-License-Identifier: GPL-2.0
2fbb35286SLarry Finger /* Copyright(c) 2009-2013 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
rtl88ee_sw_led_on(struct ieee80211_hw * hw,enum rtl_led_pin pin)9*084f1f55SDmitry Antipov void rtl88ee_sw_led_on(struct ieee80211_hw *hw, enum rtl_led_pin pin)
10f1d2b4d3SLarry Finger {
11f1d2b4d3SLarry Finger u8 ledcfg;
12f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw);
13f1d2b4d3SLarry Finger
1457b0b743SLarry 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_byte(rtlpriv, REG_LEDCFG2);
22f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv,
23f1d2b4d3SLarry Finger REG_LEDCFG2, (ledcfg & 0xf0) | BIT(5) | BIT(6));
24f1d2b4d3SLarry Finger break;
25f1d2b4d3SLarry Finger case LED_PIN_LED1:
26f1d2b4d3SLarry Finger ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG1);
27f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_LEDCFG1, ledcfg & 0x10);
28f1d2b4d3SLarry Finger break;
29f1d2b4d3SLarry Finger default:
3057b0b743SLarry Finger rtl_dbg(rtlpriv, COMP_ERR, DBG_LOUD,
31*084f1f55SDmitry Antipov "switch case %#x not processed\n", pin);
32f1d2b4d3SLarry Finger break;
33f1d2b4d3SLarry Finger }
34f1d2b4d3SLarry Finger }
35f1d2b4d3SLarry Finger
rtl88ee_sw_led_off(struct ieee80211_hw * hw,enum rtl_led_pin pin)36*084f1f55SDmitry Antipov void rtl88ee_sw_led_off(struct ieee80211_hw *hw, enum rtl_led_pin pin)
37f1d2b4d3SLarry Finger {
38f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw);
39f1d2b4d3SLarry Finger u8 ledcfg;
40f1d2b4d3SLarry Finger
4157b0b743SLarry Finger rtl_dbg(rtlpriv, COMP_LED, DBG_LOUD,
42*084f1f55SDmitry Antipov "LedAddr:%X ledpin=%d\n", REG_LEDCFG2, pin);
43f1d2b4d3SLarry Finger
44*084f1f55SDmitry Antipov switch (pin) {
45f1d2b4d3SLarry Finger case LED_PIN_GPIO0:
46f1d2b4d3SLarry Finger break;
47f1d2b4d3SLarry Finger case LED_PIN_LED0:
48f1d2b4d3SLarry Finger ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG2);
49f1d2b4d3SLarry Finger ledcfg &= 0xf0;
50d5efe153SLarry Finger if (rtlpriv->ledctl.led_opendrain) {
51f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_LEDCFG2,
52f1d2b4d3SLarry Finger (ledcfg | BIT(3) | BIT(5) | BIT(6)));
53f1d2b4d3SLarry Finger ledcfg = rtl_read_byte(rtlpriv, REG_MAC_PINMUX_CFG);
54f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_MAC_PINMUX_CFG,
55f1d2b4d3SLarry Finger (ledcfg & 0xFE));
56f1d2b4d3SLarry Finger } else
57f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_LEDCFG2,
58f1d2b4d3SLarry Finger (ledcfg | BIT(3) | BIT(5) | BIT(6)));
59f1d2b4d3SLarry Finger break;
60f1d2b4d3SLarry Finger case LED_PIN_LED1:
61f1d2b4d3SLarry Finger ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG1);
62f1d2b4d3SLarry Finger ledcfg &= 0x10;
63f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_LEDCFG1, (ledcfg | BIT(3)));
64f1d2b4d3SLarry Finger break;
65f1d2b4d3SLarry Finger default:
6657b0b743SLarry Finger rtl_dbg(rtlpriv, COMP_ERR, DBG_LOUD,
67*084f1f55SDmitry Antipov "switch case %#x not processed\n", pin);
68f1d2b4d3SLarry Finger break;
69f1d2b4d3SLarry Finger }
70f1d2b4d3SLarry Finger }
71f1d2b4d3SLarry Finger
_rtl88ee_sw_led_control(struct ieee80211_hw * hw,enum led_ctl_mode ledaction)72f1d2b4d3SLarry Finger static void _rtl88ee_sw_led_control(struct ieee80211_hw *hw,
73f1d2b4d3SLarry Finger enum led_ctl_mode ledaction)
74f1d2b4d3SLarry Finger {
75d5efe153SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw);
76*084f1f55SDmitry Antipov enum rtl_led_pin pin0 = rtlpriv->ledctl.sw_led0;
77d5efe153SLarry Finger
78f1d2b4d3SLarry Finger switch (ledaction) {
79f1d2b4d3SLarry Finger case LED_CTL_POWER_ON:
80f1d2b4d3SLarry Finger case LED_CTL_LINK:
81f1d2b4d3SLarry Finger case LED_CTL_NO_LINK:
82*084f1f55SDmitry Antipov rtl88ee_sw_led_on(hw, pin0);
83f1d2b4d3SLarry Finger break;
84f1d2b4d3SLarry Finger case LED_CTL_POWER_OFF:
85*084f1f55SDmitry Antipov rtl88ee_sw_led_off(hw, pin0);
86f1d2b4d3SLarry Finger break;
87f1d2b4d3SLarry Finger default:
88f1d2b4d3SLarry Finger break;
89f1d2b4d3SLarry Finger }
90f1d2b4d3SLarry Finger }
91f1d2b4d3SLarry Finger
rtl88ee_led_control(struct ieee80211_hw * hw,enum led_ctl_mode ledaction)92f1d2b4d3SLarry Finger void rtl88ee_led_control(struct ieee80211_hw *hw,
93f1d2b4d3SLarry Finger enum led_ctl_mode ledaction)
94f1d2b4d3SLarry Finger {
95f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw);
96f1d2b4d3SLarry Finger struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
97f1d2b4d3SLarry Finger
98f1d2b4d3SLarry Finger if ((ppsc->rfoff_reason > RF_CHANGE_BY_PS) &&
99f1d2b4d3SLarry Finger (ledaction == LED_CTL_TX ||
100f1d2b4d3SLarry Finger ledaction == LED_CTL_RX ||
101f1d2b4d3SLarry Finger ledaction == LED_CTL_SITE_SURVEY ||
102f1d2b4d3SLarry Finger ledaction == LED_CTL_LINK ||
103f1d2b4d3SLarry Finger ledaction == LED_CTL_NO_LINK ||
104f1d2b4d3SLarry Finger ledaction == LED_CTL_START_TO_LINK ||
105f1d2b4d3SLarry Finger ledaction == LED_CTL_POWER_ON)) {
106f1d2b4d3SLarry Finger return;
107f1d2b4d3SLarry Finger }
10857b0b743SLarry Finger rtl_dbg(rtlpriv, COMP_LED, DBG_TRACE, "ledaction %d,\n",
109f1d2b4d3SLarry Finger ledaction);
110f1d2b4d3SLarry Finger _rtl88ee_sw_led_control(hw, ledaction);
111f1d2b4d3SLarry Finger }
112