xref: /linux/drivers/net/wireless/realtek/rtlwifi/rtl8192ce/led.c (revision 34dc1baba215b826e454b8d19e4f24adbeb7d00d)
1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2009-2012  Realtek Corporation.*/
3 
4 #include "../wifi.h"
5 #include "../pci.h"
6 #include "reg.h"
7 #include "led.h"
8 
9 void rtl92ce_sw_led_on(struct ieee80211_hw *hw, enum rtl_led_pin pin)
10 {
11 	u8 ledcfg;
12 	struct rtl_priv *rtlpriv = rtl_priv(hw);
13 
14 	rtl_dbg(rtlpriv, COMP_LED, DBG_LOUD, "LedAddr:%X ledpin=%d\n",
15 		REG_LEDCFG2, pin);
16 
17 	ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG2);
18 
19 	switch (pin) {
20 	case LED_PIN_GPIO0:
21 		break;
22 	case LED_PIN_LED0:
23 		rtl_write_byte(rtlpriv,
24 			       REG_LEDCFG2, (ledcfg & 0xf0) | BIT(5) | BIT(6));
25 		break;
26 	case LED_PIN_LED1:
27 		rtl_write_byte(rtlpriv, REG_LEDCFG2, (ledcfg & 0x0f) | BIT(5));
28 		break;
29 	default:
30 		pr_err("switch case %#x not processed\n", pin);
31 		break;
32 	}
33 }
34 
35 void rtl92ce_sw_led_off(struct ieee80211_hw *hw, enum rtl_led_pin pin)
36 {
37 	struct rtl_priv *rtlpriv = rtl_priv(hw);
38 	u8 ledcfg;
39 
40 	rtl_dbg(rtlpriv, COMP_LED, DBG_LOUD, "LedAddr:%X ledpin=%d\n",
41 		REG_LEDCFG2, pin);
42 
43 	ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG2);
44 
45 	switch (pin) {
46 	case LED_PIN_GPIO0:
47 		break;
48 	case LED_PIN_LED0:
49 		ledcfg &= 0xf0;
50 		if (rtlpriv->ledctl.led_opendrain)
51 			rtl_write_byte(rtlpriv, REG_LEDCFG2,
52 				       (ledcfg | BIT(1) | BIT(5) | BIT(6)));
53 		else
54 			rtl_write_byte(rtlpriv, REG_LEDCFG2,
55 				       (ledcfg | BIT(3) | BIT(5) | BIT(6)));
56 		break;
57 	case LED_PIN_LED1:
58 		ledcfg &= 0x0f;
59 		rtl_write_byte(rtlpriv, REG_LEDCFG2, (ledcfg | BIT(3)));
60 		break;
61 	default:
62 		pr_info("switch case %#x not processed\n", pin);
63 		break;
64 	}
65 }
66 
67 static void _rtl92ce_sw_led_control(struct ieee80211_hw *hw,
68 				    enum led_ctl_mode ledaction)
69 {
70 	struct rtl_priv *rtlpriv = rtl_priv(hw);
71 	enum rtl_led_pin pin0 = rtlpriv->ledctl.sw_led0;
72 
73 	switch (ledaction) {
74 	case LED_CTL_POWER_ON:
75 	case LED_CTL_LINK:
76 	case LED_CTL_NO_LINK:
77 		rtl92ce_sw_led_on(hw, pin0);
78 		break;
79 	case LED_CTL_POWER_OFF:
80 		rtl92ce_sw_led_off(hw, pin0);
81 		break;
82 	default:
83 		break;
84 	}
85 }
86 
87 void rtl92ce_led_control(struct ieee80211_hw *hw,
88 			enum led_ctl_mode ledaction)
89 {
90 	struct rtl_priv *rtlpriv = rtl_priv(hw);
91 	struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
92 
93 	if ((ppsc->rfoff_reason > RF_CHANGE_BY_PS) &&
94 	    (ledaction == LED_CTL_TX ||
95 	     ledaction == LED_CTL_RX ||
96 	     ledaction == LED_CTL_SITE_SURVEY ||
97 	     ledaction == LED_CTL_LINK ||
98 	     ledaction == LED_CTL_NO_LINK ||
99 	     ledaction == LED_CTL_START_TO_LINK ||
100 	     ledaction == LED_CTL_POWER_ON)) {
101 		return;
102 	}
103 	rtl_dbg(rtlpriv, COMP_LED, DBG_LOUD, "ledaction %d\n",
104 		ledaction);
105 	_rtl92ce_sw_led_control(hw, ledaction);
106 }
107