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