GNU Linux-libre 4.14.259-gnu1
[releases.git] / drivers / staging / rtl8188eu / hal / rtl8188eu_led.c
1 /******************************************************************************
2  *
3  * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
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 <osdep_service.h>
17 #include <drv_types.h>
18 #include <rtl8188e_hal.h>
19 #include <rtl8188e_led.h>
20 #include <usb_ops_linux.h>
21
22 /*  LED object. */
23
24 /*  LED_819xUsb routines. */
25 /*      Description: */
26 /*              Turn on LED according to LedPin specified. */
27 void SwLedOn(struct adapter *padapter, struct LED_871x *pLed)
28 {
29         u8      LedCfg;
30
31         if (padapter->bSurpriseRemoved || padapter->bDriverStopped)
32                 return;
33         LedCfg = usb_read8(padapter, REG_LEDCFG2);
34         usb_write8(padapter, REG_LEDCFG2, (LedCfg&0xf0) | BIT(5) | BIT(6)); /*  SW control led0 on. */
35         pLed->bLedOn = true;
36 }
37
38 /*      Description: */
39 /*              Turn off LED according to LedPin specified. */
40 void SwLedOff(struct adapter *padapter, struct LED_871x *pLed)
41 {
42         u8      LedCfg;
43
44         if (padapter->bSurpriseRemoved || padapter->bDriverStopped)
45                 goto exit;
46
47         LedCfg = usb_read8(padapter, REG_LEDCFG2);/* 0x4E */
48
49         /*  Open-drain arrangement for controlling the LED) */
50         LedCfg &= 0x90; /*  Set to software control. */
51         usb_write8(padapter, REG_LEDCFG2, (LedCfg | BIT(3)));
52         LedCfg = usb_read8(padapter, REG_MAC_PINMUX_CFG);
53         LedCfg &= 0xFE;
54         usb_write8(padapter, REG_MAC_PINMUX_CFG, LedCfg);
55 exit:
56         pLed->bLedOn = false;
57 }
58
59 /*  Interface to manipulate LED objects. */
60 /*  Default LED behavior. */
61
62 /*      Description: */
63 /*              Initialize all LED_871x objects. */
64 void rtw_hal_sw_led_init(struct adapter *padapter)
65 {
66         struct led_priv *pledpriv = &(padapter->ledpriv);
67
68         InitLed871x(padapter, &(pledpriv->SwLed0));
69 }
70
71 /*      Description: */
72 /*              DeInitialize all LED_819xUsb objects. */
73 void rtw_hal_sw_led_deinit(struct adapter *padapter)
74 {
75         struct led_priv *ledpriv = &(padapter->ledpriv);
76
77         DeInitLed871x(&(ledpriv->SwLed0));
78 }