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 void rtl92cu_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 	ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG2);
17 	switch (pin) {
18 	case LED_PIN_GPIO0:
19 		break;
20 	case LED_PIN_LED0:
21 		rtl_write_byte(rtlpriv,
22 			       REG_LEDCFG2, (ledcfg & 0xf0) | BIT(5) | BIT(6));
23 		break;
24 	case LED_PIN_LED1:
25 		rtl_write_byte(rtlpriv, REG_LEDCFG2, (ledcfg & 0x0f) | BIT(5));
26 		break;
27 	default:
28 		pr_err("switch case %#x not processed\n", pin);
29 		break;
30 	}
31 }
32 
33 void rtl92cu_sw_led_off(struct ieee80211_hw *hw, enum rtl_led_pin pin)
34 {
35 	struct rtl_priv *rtlpriv = rtl_priv(hw);
36 	u8 ledcfg;
37 
38 	rtl_dbg(rtlpriv, COMP_LED, DBG_LOUD, "LedAddr:%X ledpin=%d\n",
39 		REG_LEDCFG2, pin);
40 	ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG2);
41 	switch (pin) {
42 	case LED_PIN_GPIO0:
43 		break;
44 	case LED_PIN_LED0:
45 		ledcfg &= 0xf0;
46 		if (rtlpriv->ledctl.led_opendrain)
47 			rtl_write_byte(rtlpriv, REG_LEDCFG2,
48 				       (ledcfg | BIT(1) | BIT(5) | BIT(6)));
49 		else
50 			rtl_write_byte(rtlpriv, REG_LEDCFG2,
51 				       (ledcfg | BIT(3) | BIT(5) | BIT(6)));
52 		break;
53 	case LED_PIN_LED1:
54 		ledcfg &= 0x0f;
55 		rtl_write_byte(rtlpriv, REG_LEDCFG2, (ledcfg | BIT(3)));
56 		break;
57 	default:
58 		pr_err("switch case %#x not processed\n", pin);
59 		break;
60 	}
61 }
62 
63 void rtl92cu_led_control(struct ieee80211_hw *hw,
64 			 enum led_ctl_mode ledaction)
65 {
66 	struct rtl_priv *rtlpriv = rtl_priv(hw);
67 	struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
68 
69 	if ((ppsc->rfoff_reason > RF_CHANGE_BY_PS) &&
70 	    (ledaction == LED_CTL_TX ||
71 	     ledaction == LED_CTL_RX ||
72 	     ledaction == LED_CTL_SITE_SURVEY ||
73 	     ledaction == LED_CTL_LINK ||
74 	     ledaction == LED_CTL_NO_LINK ||
75 	     ledaction == LED_CTL_START_TO_LINK ||
76 	     ledaction == LED_CTL_POWER_ON)) {
77 		return;
78 	}
79 	rtl_dbg(rtlpriv, COMP_LED, DBG_LOUD, "ledaction %d\n", ledaction);
80 }
81