OSDN Git Service

Add rtl8821ce driver version 5.5.2
[android-x86/external-kernel-drivers.git] / rtl8821ce / hal / rtl8821c / pci / rtl8821ce_led.c
1 /******************************************************************************
2  *
3  * Copyright(c) 2016 - 2017 Realtek Corporation.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of version 2 of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  *****************************************************************************/
15
16 #include <drv_types.h>          /* PADAPTER */
17 #include <hal_data.h>           /* PHAL_DATA_TYPE */
18 #include <hal_com_led.h>        /* PLED_PCIE */
19
20 #ifdef CONFIG_RTW_SW_LED
21
22 /*
23  *==============================================================================
24  *      Prototype of protected function.
25  *==============================================================================
26  */
27
28 /*
29  *==============================================================================
30  * LED_819xUsb routines.
31  *==============================================================================
32  */
33
34 /*
35  * Description:
36  *      Turn on LED according to LedPin specified.
37  */
38 static void SwLedOn_8821ce(PADAPTER adapter, PLED_PCIE pLed)
39 {
40 #if 0
41         u16 LedReg = REG_LEDCFG0;
42         u8 LedCfg = 0;
43         struct led_priv *ledpriv = adapter_to_led(adapter);
44
45         if (RTW_CANNOT_RUN(adapter))
46                 return;
47
48         switch (pLed->LedPin) {
49         case LED_PIN_LED0:
50                 if (ledpriv->LedStrategy == SW_LED_MODE10)
51                         LedReg = REG_LEDCFG0;
52                 else
53                         LedReg = REG_LEDCFG1;
54                 break;
55
56         case LED_PIN_LED1:
57                 LedReg = REG_LEDCFG2;
58                 break;
59
60         case LED_PIN_GPIO0:
61         default:
62                 break;
63         }
64
65         LedCfg = rtw_read8(adapter, LedReg);
66         LedCfg |= BIT5; /* Set 0x4c[21] */
67
68         /* Clear 0x4c[23:22] and 0x4c[19:16] */
69         LedCfg &= ~(BIT7 | BIT6 | BIT3 | BIT2 | BIT1 | BIT0);
70
71         /* SW control led0 on. */
72         rtw_write8(adapter, LedReg, LedCfg);
73         pLed->bLedOn = _TRUE;
74 #else
75         RTW_INFO("%s(%d)TODO LED\n", __func__, __LINE__);
76 #endif
77 }
78
79
80 /*
81  * Description:
82  *      Turn off LED according to LedPin specified.
83  */
84 static void SwLedOff_8821ce(PADAPTER adapter, PLED_PCIE pLed)
85 {
86 #if 0
87         u16 LedReg = REG_LEDCFG0;
88         PHAL_DATA_TYPE hal = GET_HAL_DATA(adapter);
89         struct led_priv *ledpriv = adapter_to_led(adapter);
90
91         if (RTW_CANNOT_RUN(adapter))
92                 return;
93
94         switch (pLed->LedPin) {
95         case LED_PIN_LED0:
96                 if (ledpriv->LedStrategy == SW_LED_MODE10)
97                         LedReg = REG_LEDCFG0;
98                 else
99                         LedReg = REG_LEDCFG1;
100                 break;
101
102         case LED_PIN_LED1:
103                 LedReg = REG_LEDCFG2;
104                 break;
105
106         case LED_PIN_GPIO0:
107         default:
108                 break;
109         }
110
111         /* Open-drain arrangement for controlling the LED */
112         if (hal->bLedOpenDrain == _TRUE) {
113                 u8 LedCfg = rtw_read8(adapter, LedReg);
114
115                 LedCfg &= 0xd0; /* Set to software control. */
116                 rtw_write8(adapter, LedReg, (LedCfg | BIT3));
117
118                 /* Open-drain arrangement */
119                 LedCfg = rtw_read8(adapter, REG_MAC_PINMUX_CFG);
120                 LedCfg &= 0xFE;/* Set GPIO[8] to input mode */
121                 rtw_write8(adapter, REG_MAC_PINMUX_CFG, LedCfg);
122
123         } else
124                 rtw_write8(adapter, LedReg, 0x28);
125
126         pLed->bLedOn = _FALSE;
127 #else
128         RTW_INFO("%s(%d)TODO LED\n", __func__, __LINE__);
129 #endif
130 }
131
132 /*
133  * Description:
134  *      Initialize all LED_871x objects.
135  */
136 void rtl8821ce_InitSwLeds(PADAPTER adapter)
137 {
138         struct led_priv *pledpriv = adapter_to_led(adapter);
139
140         pledpriv->LedControlHandler = LedControlPCIE;
141
142         pledpriv->SwLedOn = SwLedOn_8821ce;
143         pledpriv->SwLedOff = SwLedOff_8821ce;
144
145         InitLed(adapter, &pledpriv->SwLed0, LED_PIN_LED0);
146         InitLed(adapter, &pledpriv->SwLed1, LED_PIN_LED1);
147 }
148
149
150 /*
151  * Description:
152  *      DeInitialize all LED_819xUsb objects.
153  */
154 void rtl8821ce_DeInitSwLeds(PADAPTER adapter)
155 {
156         struct led_priv *ledpriv = adapter_to_led(adapter);
157
158         DeInitLed(&ledpriv->SwLed0);
159         DeInitLed(&ledpriv->SwLed1);
160 }
161 #endif