15bd4f692SLarry Finger // SPDX-License-Identifier: GPL-2.0
25bd4f692SLarry Finger /* Copyright(c) 2009-2012 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
rtl92de_sw_led_on(struct ieee80211_hw * hw,enum rtl_led_pin pin)9*084f1f55SDmitry Antipov void rtl92de_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
146bf8bc19SLarry Finger rtl_dbg(rtlpriv, COMP_LED, DBG_LOUD, "LedAddr:%X ledpin=%d\n",
15*084f1f55SDmitry Antipov 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
23f1d2b4d3SLarry Finger if ((rtlpriv->efuse.eeprom_did == 0x8176) ||
24f1d2b4d3SLarry Finger (rtlpriv->efuse.eeprom_did == 0x8193))
25f1d2b4d3SLarry Finger /* BIT7 of REG_LEDCFG2 should be set to
26f1d2b4d3SLarry Finger * make sure we could emit the led2. */
27f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_LEDCFG2, (ledcfg & 0xf0) |
28f1d2b4d3SLarry Finger BIT(7) | BIT(5) | BIT(6));
29f1d2b4d3SLarry Finger else
30f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_LEDCFG2, (ledcfg & 0xf0) |
31f1d2b4d3SLarry Finger BIT(7) | BIT(5));
32f1d2b4d3SLarry Finger break;
33f1d2b4d3SLarry Finger case LED_PIN_LED1:
34f1d2b4d3SLarry Finger ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG1);
35f1d2b4d3SLarry Finger
36f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_LEDCFG2, (ledcfg & 0x0f) | BIT(5));
37f1d2b4d3SLarry Finger break;
38f1d2b4d3SLarry Finger default:
39*084f1f55SDmitry Antipov pr_err("switch case %#x not processed\n", pin);
40f1d2b4d3SLarry Finger break;
41f1d2b4d3SLarry Finger }
42f1d2b4d3SLarry Finger }
43f1d2b4d3SLarry Finger
rtl92de_sw_led_off(struct ieee80211_hw * hw,enum rtl_led_pin pin)44*084f1f55SDmitry Antipov void rtl92de_sw_led_off(struct ieee80211_hw *hw, enum rtl_led_pin pin)
45f1d2b4d3SLarry Finger {
46f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw);
47f1d2b4d3SLarry Finger u8 ledcfg;
48f1d2b4d3SLarry Finger
496bf8bc19SLarry Finger rtl_dbg(rtlpriv, COMP_LED, DBG_LOUD, "LedAddr:%X ledpin=%d\n",
50*084f1f55SDmitry Antipov REG_LEDCFG2, pin);
51f1d2b4d3SLarry Finger
52f1d2b4d3SLarry Finger ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG2);
53f1d2b4d3SLarry Finger
54*084f1f55SDmitry Antipov switch (pin) {
55f1d2b4d3SLarry Finger case LED_PIN_GPIO0:
56f1d2b4d3SLarry Finger break;
57f1d2b4d3SLarry Finger case LED_PIN_LED0:
58f1d2b4d3SLarry Finger ledcfg &= 0xf0;
59d5efe153SLarry Finger if (rtlpriv->ledctl.led_opendrain)
60f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_LEDCFG2,
61f1d2b4d3SLarry Finger (ledcfg | BIT(1) | BIT(5) | BIT(6)));
62f1d2b4d3SLarry Finger else
63f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_LEDCFG2,
64f1d2b4d3SLarry Finger (ledcfg | BIT(3) | BIT(5) | BIT(6)));
65f1d2b4d3SLarry Finger break;
66f1d2b4d3SLarry Finger case LED_PIN_LED1:
67f1d2b4d3SLarry Finger ledcfg &= 0x0f;
68f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_LEDCFG2, (ledcfg | BIT(3)));
69f1d2b4d3SLarry Finger break;
70f1d2b4d3SLarry Finger default:
71*084f1f55SDmitry Antipov pr_err("switch case %#x not processed\n", pin);
72f1d2b4d3SLarry Finger break;
73f1d2b4d3SLarry Finger }
74f1d2b4d3SLarry Finger }
75f1d2b4d3SLarry Finger
_rtl92ce_sw_led_control(struct ieee80211_hw * hw,enum led_ctl_mode ledaction)76f1d2b4d3SLarry Finger static void _rtl92ce_sw_led_control(struct ieee80211_hw *hw,
77f1d2b4d3SLarry Finger enum led_ctl_mode ledaction)
78f1d2b4d3SLarry Finger {
79d5efe153SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw);
80*084f1f55SDmitry Antipov enum rtl_led_pin pin0 = rtlpriv->ledctl.sw_led0;
81d5efe153SLarry Finger
82f1d2b4d3SLarry Finger switch (ledaction) {
83f1d2b4d3SLarry Finger case LED_CTL_POWER_ON:
84f1d2b4d3SLarry Finger case LED_CTL_LINK:
85f1d2b4d3SLarry Finger case LED_CTL_NO_LINK:
86*084f1f55SDmitry Antipov rtl92de_sw_led_on(hw, pin0);
87f1d2b4d3SLarry Finger break;
88f1d2b4d3SLarry Finger case LED_CTL_POWER_OFF:
89*084f1f55SDmitry Antipov rtl92de_sw_led_off(hw, pin0);
90f1d2b4d3SLarry Finger break;
91f1d2b4d3SLarry Finger default:
92f1d2b4d3SLarry Finger break;
93f1d2b4d3SLarry Finger }
94f1d2b4d3SLarry Finger }
95f1d2b4d3SLarry Finger
rtl92de_led_control(struct ieee80211_hw * hw,enum led_ctl_mode ledaction)96f1d2b4d3SLarry Finger void rtl92de_led_control(struct ieee80211_hw *hw, enum led_ctl_mode ledaction)
97f1d2b4d3SLarry Finger {
98f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw);
99f1d2b4d3SLarry Finger struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
100f1d2b4d3SLarry Finger
101f1d2b4d3SLarry Finger if ((ppsc->rfoff_reason > RF_CHANGE_BY_PS) &&
102f1d2b4d3SLarry Finger (ledaction == LED_CTL_TX ||
103f1d2b4d3SLarry Finger ledaction == LED_CTL_RX ||
104f1d2b4d3SLarry Finger ledaction == LED_CTL_SITE_SURVEY ||
105f1d2b4d3SLarry Finger ledaction == LED_CTL_LINK ||
106f1d2b4d3SLarry Finger ledaction == LED_CTL_NO_LINK ||
107f1d2b4d3SLarry Finger ledaction == LED_CTL_START_TO_LINK ||
108f1d2b4d3SLarry Finger ledaction == LED_CTL_POWER_ON)) {
109f1d2b4d3SLarry Finger return;
110f1d2b4d3SLarry Finger }
1116bf8bc19SLarry Finger rtl_dbg(rtlpriv, COMP_LED, DBG_LOUD, "ledaction %d,\n", ledaction);
112f1d2b4d3SLarry Finger
113f1d2b4d3SLarry Finger _rtl92ce_sw_led_control(hw, ledaction);
114f1d2b4d3SLarry Finger }
115