1 /* SPDX-License-Identifier: GPL-2.0 */
2 /******************************************************************************
3 *
4 * Copyright(c) 2007 - 2017 Realtek Corporation.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of version 2 of the GNU General Public License as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
15 *****************************************************************************/
16
17 #include <drv_types.h>
18 #include <rtl8188e_hal.h>
19 #ifdef CONFIG_RTW_SW_LED
20
21 /* ********************************************************************************
22 * LED object.
23 * ******************************************************************************** */
24
25
26 /* ********************************************************************************
27 * Prototype of protected function.
28 * ******************************************************************************** */
29
30
31 /* ********************************************************************************
32 * LED_819xUsb routines.
33 * ******************************************************************************** */
34
35 /*
36 * Description:
37 * Turn on LED according to LedPin specified.
38 * */
39 static void
SwLedOn_8188EU(_adapter * padapter,PLED_USB pLed)40 SwLedOn_8188EU(
41 _adapter *padapter,
42 PLED_USB pLed
43 )
44 {
45 u8 LedCfg;
46 /* HAL_DATA_TYPE *pHalData = GET_HAL_DATA(padapter); */
47
48 if (RTW_CANNOT_RUN(padapter))
49 return;
50
51 LedCfg = rtw_read8(padapter, REG_LEDCFG2);
52 switch (pLed->LedPin) {
53 case LED_PIN_LED0:
54 rtw_write8(padapter, REG_LEDCFG2, (LedCfg & 0xf0) | BIT5 | BIT6); /* SW control led0 on. */
55 break;
56
57 case LED_PIN_LED1:
58 rtw_write8(padapter, REG_LEDCFG2, (LedCfg & 0x0f) | BIT5); /* SW control led1 on. */
59 break;
60
61 default:
62 break;
63 }
64
65 pLed->bLedOn = _TRUE;
66 }
67
68
69 /*
70 * Description:
71 * Turn off LED according to LedPin specified.
72 * */
73 static void
SwLedOff_8188EU(_adapter * padapter,PLED_USB pLed)74 SwLedOff_8188EU(
75 _adapter *padapter,
76 PLED_USB pLed
77 )
78 {
79 u8 LedCfg;
80 HAL_DATA_TYPE *pHalData = GET_HAL_DATA(padapter);
81
82 if (RTW_CANNOT_RUN(padapter))
83 goto exit;
84
85
86 LedCfg = rtw_read8(padapter, REG_LEDCFG2);/* 0x4E */
87
88 switch (pLed->LedPin) {
89 case LED_PIN_LED0:
90 if (pHalData->bLedOpenDrain == _TRUE) { /* Open-drain arrangement for controlling the LED) */
91 LedCfg &= 0x90; /* Set to software control. */
92 rtw_write8(padapter, REG_LEDCFG2, (LedCfg | BIT3));
93 LedCfg = rtw_read8(padapter, REG_MAC_PINMUX_CFG);
94 LedCfg &= 0xFE;
95 rtw_write8(padapter, REG_MAC_PINMUX_CFG, LedCfg);
96 } else
97 rtw_write8(padapter, REG_LEDCFG2, (LedCfg | BIT3 | BIT5 | BIT6));
98 break;
99
100 case LED_PIN_LED1:
101 LedCfg &= 0x0f; /* Set to software control. */
102 rtw_write8(padapter, REG_LEDCFG2, (LedCfg | BIT3));
103 break;
104
105 default:
106 break;
107 }
108 exit:
109 pLed->bLedOn = _FALSE;
110
111 }
112
113 /* ********************************************************************************
114 * Interface to manipulate LED objects.
115 * ******************************************************************************** */
116
117
118 /* ********************************************************************************
119 * Default LED behavior.
120 * ******************************************************************************** */
121
122 /*
123 * Description:
124 * Initialize all LED_871x objects.
125 * */
126 void
rtl8188eu_InitSwLeds(_adapter * padapter)127 rtl8188eu_InitSwLeds(
128 _adapter *padapter
129 )
130 {
131 struct led_priv *pledpriv = adapter_to_led(padapter);
132
133 pledpriv->LedControlHandler = LedControlUSB;
134
135 pledpriv->SwLedOn = SwLedOn_8188EU;
136 pledpriv->SwLedOff = SwLedOff_8188EU;
137
138 InitLed(padapter, &(pledpriv->SwLed0), LED_PIN_LED0);
139
140 InitLed(padapter, &(pledpriv->SwLed1), LED_PIN_LED1);
141 }
142
143
144 /*
145 * Description:
146 * DeInitialize all LED_819xUsb objects.
147 * */
148 void
rtl8188eu_DeInitSwLeds(_adapter * padapter)149 rtl8188eu_DeInitSwLeds(
150 _adapter *padapter
151 )
152 {
153 struct led_priv *ledpriv = adapter_to_led(padapter);
154
155 DeInitLed(&(ledpriv->SwLed0));
156 DeInitLed(&(ledpriv->SwLed1));
157 }
158 #endif
159