OSDN Git Service

564dc0a0f09257d868fa78f6a7aba2e2e2231d72
[android-x86/external-modules-rtl8723au.git] / include / rtw_led.h
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  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17  *
18  *
19  ******************************************************************************/
20 #ifndef __RTW_LED_H_
21 #define __RTW_LED_H_
22
23 #include <drv_conf.h>
24 #include <osdep_service.h>
25 #include <drv_types.h>
26
27 #define MSECS(t)        (HZ * ((t) / 1000) + (HZ * ((t) % 1000)) / 1000)
28
29 #define LED_BLINK_NORMAL_INTERVAL       100
30 #define LED_BLINK_SLOWLY_INTERVAL       200
31 #define LED_BLINK_LONG_INTERVAL 400
32
33 #define LED_BLINK_NO_LINK_INTERVAL_ALPHA                1000
34 #define LED_BLINK_LINK_INTERVAL_ALPHA                   500             //500
35 #define LED_BLINK_SCAN_INTERVAL_ALPHA           180     //150
36 #define LED_BLINK_FASTER_INTERVAL_ALPHA         50
37 #define LED_BLINK_WPS_SUCESS_INTERVAL_ALPHA     5000
38
39 #define LED_BLINK_NORMAL_INTERVAL_NETTRONIX  100
40 #define LED_BLINK_SLOWLY_INTERVAL_NETTRONIX  2000
41
42 #define LED_BLINK_SLOWLY_INTERVAL_PORNET 1000
43 #define LED_BLINK_NORMAL_INTERVAL_PORNET 100
44
45 #define LED_BLINK_FAST_INTERVAL_BITLAND 30
46
47 // 060403, rcnjko: Customized for AzWave.
48 #define LED_CM2_BLINK_ON_INTERVAL                       250
49 #define LED_CM2_BLINK_OFF_INTERVAL              4750
50
51 #define LED_CM8_BLINK_INTERVAL                  500             //for QMI
52 #define LED_CM8_BLINK_OFF_INTERVAL      3750    //for QMI
53
54 // 080124, lanhsin: Customized for RunTop
55 #define LED_RunTop_BLINK_INTERVAL                       300
56
57 // 060421, rcnjko: Customized for Sercomm Printer Server case.
58 #define LED_CM3_BLINK_INTERVAL                          1500
59
60 typedef enum _LED_CTL_MODE{
61         LED_CTL_POWER_ON = 1,
62         LED_CTL_LINK = 2,
63         LED_CTL_NO_LINK = 3,
64         LED_CTL_TX = 4,
65         LED_CTL_RX = 5,
66         LED_CTL_SITE_SURVEY = 6,
67         LED_CTL_POWER_OFF = 7,
68         LED_CTL_START_TO_LINK = 8,
69         LED_CTL_START_WPS = 9,
70         LED_CTL_STOP_WPS = 10,
71         LED_CTL_START_WPS_BOTTON = 11, //added for runtop
72         LED_CTL_STOP_WPS_FAIL = 12, //added for ALPHA
73         LED_CTL_STOP_WPS_FAIL_OVERLAP = 13, //added for BELKIN
74         LED_CTL_CONNECTION_NO_TRANSFER = 14,
75 }LED_CTL_MODE;
76
77 typedef enum _LED_STATE_871x{
78         LED_UNKNOWN = 0,
79         RTW_LED_ON = 1,
80         RTW_LED_OFF = 2,
81         LED_BLINK_NORMAL = 3,
82         LED_BLINK_SLOWLY = 4,
83         LED_BLINK_POWER_ON = 5,
84         LED_BLINK_SCAN = 6, // LED is blinking during scanning period, the # of times to blink is depend on time for scanning.
85         LED_BLINK_NO_LINK = 7, // LED is blinking during no link state.
86         LED_BLINK_StartToBlink = 8,// Customzied for Sercomm Printer Server case
87         LED_BLINK_TXRX = 9,
88         LED_BLINK_WPS = 10,     // LED is blinkg during WPS communication
89         LED_BLINK_WPS_STOP = 11,        //for ALPHA
90         LED_BLINK_WPS_STOP_OVERLAP = 12,        //for BELKIN
91         LED_BLINK_RUNTOP = 13, // Customized for RunTop
92         LED_BLINK_CAMEO = 14,
93         LED_BLINK_XAVI = 15,
94         LED_BLINK_ALWAYS_ON = 16,
95 }LED_STATE_871x;
96
97 typedef enum _LED_PIN_871x{
98         LED_PIN_NULL = 0,
99         LED_PIN_LED0 = 1,
100         LED_PIN_LED1 = 2,
101         LED_PIN_LED2 = 3,
102         LED_PIN_GPIO0 = 4,
103 }LED_PIN_871x;
104
105 typedef struct _LED_871x{
106         _adapter                                *padapter;
107
108         LED_PIN_871x            LedPin; // Identify how to implement this SW led.
109         LED_STATE_871x          CurrLedState; // Current LED state.
110         LED_STATE_871x          BlinkingLedState; // Next state for blinking, either RTW_LED_ON or RTW_LED_OFF are.
111
112         u8                                      bLedOn; // true if LED is ON, false if LED is OFF.
113
114         u8                                      bLedBlinkInProgress; // true if it is blinking, false o.w..
115
116         u8                                      bLedWPSBlinkInProgress;
117
118         u32                                     BlinkTimes; // Number of times to toggle led state for blinking.
119
120         _timer                          BlinkTimer; // Timer object for led blinking.
121
122 #if defined(CONFIG_USB_HCI) || defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
123         u8                                      bSWLedCtrl;
124
125         // ALPHA, added by chiyoko, 20090106
126         u8                                      bLedNoLinkBlinkInProgress;
127         u8                                      bLedLinkBlinkInProgress;
128         u8                                      bLedStartToLinkBlinkInProgress;
129         u8                                      bLedScanBlinkInProgress;
130
131         #if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)|| defined PLATFORM_FREEBSD
132         _workitem                       BlinkWorkItem; // Workitem used by BlinkTimer to manipulate H/W to blink LED.
133         #endif
134 #endif //defined(CONFIG_USB_HCI) || defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
135
136 #if defined(CONFIG_PCI_HCI)
137         u8                                      bLedSlowBlinkInProgress;//added by vivi, for led new mode
138 #endif
139
140 } LED_871x, *PLED_871x;
141
142 #if defined(CONFIG_USB_HCI) || defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
143
144 #define IS_LED_WPS_BLINKING(_LED_871x)  (((PLED_871x)_LED_871x)->CurrLedState==LED_BLINK_WPS \
145                                         || ((PLED_871x)_LED_871x)->CurrLedState==LED_BLINK_WPS_STOP \
146                                         || ((PLED_871x)_LED_871x)->bLedWPSBlinkInProgress)
147
148 #define IS_LED_BLINKING(_LED_871x)      (((PLED_871x)_LED_871x)->bLedWPSBlinkInProgress \
149                                         ||((PLED_871x)_LED_871x)->bLedScanBlinkInProgress)
150
151 //================================================================================
152 // LED customization.
153 //================================================================================
154
155 typedef enum _LED_STRATEGY_871x{
156         SW_LED_MODE0 = 0, // SW control 1 LED via GPIO0. It is default option.
157         SW_LED_MODE1= 1, // 2 LEDs, through LED0 and LED1. For ALPHA.
158         SW_LED_MODE2 = 2, // SW control 1 LED via GPIO0, customized for AzWave 8187 minicard.
159         SW_LED_MODE3 = 3, // SW control 1 LED via GPIO0, customized for Sercomm Printer Server case.
160         SW_LED_MODE4 = 4, //for Edimax / Belkin
161         SW_LED_MODE5 = 5, //for Sercomm / Belkin
162         SW_LED_MODE6 = 6, //for 88CU minicard, porting from ce SW_LED_MODE7
163         HW_LED = 50, // HW control 2 LEDs, LED0 and LED1 (there are 4 different control modes, see MAC.CONFIG1 for details.)
164         LED_ST_NONE = 99,
165 }LED_STRATEGY_871x, *PLED_STRATEGY_871x;
166
167 void
168 LedControl871x(
169         _adapter                                *padapter,
170         LED_CTL_MODE            LedAction
171         );
172 #endif //defined(CONFIG_USB_HCI) || defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
173
174 #if defined(CONFIG_PCI_HCI)
175 //================================================================================
176 // LED customization.
177 //================================================================================
178
179 typedef enum _LED_STRATEGY_871x{
180         SW_LED_MODE0 = 0, // SW control 1 LED via GPIO0. It is default option.
181         SW_LED_MODE1 = 1, // SW control for PCI Express
182         SW_LED_MODE2 = 2, // SW control for Cameo.
183         SW_LED_MODE3 = 3, // SW contorl for RunTop.
184         SW_LED_MODE4 = 4, // SW control for Netcore
185         SW_LED_MODE5 = 5, //added by vivi, for led new mode, DLINK
186         SW_LED_MODE6 = 6, //added by vivi, for led new mode, PRONET
187         SW_LED_MODE7 = 7, //added by chiyokolin, for Lenovo, PCI Express Minicard Spec Rev.1.2 spec
188         SW_LED_MODE8 = 8, //added by chiyokolin, for QMI
189         SW_LED_MODE9 = 9, //added by chiyokolin, for BITLAND, PCI Express Minicard Spec Rev.1.1
190         SW_LED_MODE10 = 10, //added by chiyokolin, for Edimax-ASUS
191         HW_LED = 50, // HW control 2 LEDs, LED0 and LED1 (there are 4 different control modes)
192         LED_ST_NONE = 99,
193 }LED_STRATEGY_871x, *PLED_STRATEGY_871x;
194 #endif //defined(CONFIG_PCI_HCI)
195
196 struct led_priv{
197         /* add for led controll */
198         LED_871x                        SwLed0;
199         LED_871x                        SwLed1;
200         LED_STRATEGY_871x       LedStrategy;
201         u8                                      bRegUseLed;
202         void (*LedControlHandler)(_adapter *padapter, LED_CTL_MODE LedAction);
203         /* add for led controll */
204 };
205
206 #ifdef CONFIG_SW_LED
207 #define rtw_led_control(adapter, LedAction) \
208         do { \
209                 if((adapter)->ledpriv.LedControlHandler) \
210                         (adapter)->ledpriv.LedControlHandler((adapter), (LedAction)); \
211         } while(0)
212 #else //CONFIG_SW_LED
213 #define rtw_led_control(adapter, LedAction)
214 #endif //CONFIG_SW_LED
215
216 void BlinkTimerCallback(void *data);
217 void BlinkWorkItemCallback(struct work_struct *work);
218
219 void ResetLedStatus(PLED_871x pLed);
220
221 void
222 InitLed871x(
223         _adapter                        *padapter,
224         PLED_871x               pLed,
225         LED_PIN_871x    LedPin
226         );
227
228 void
229 DeInitLed871x(
230         PLED_871x                       pLed
231         );
232
233 //hal...
234 extern void BlinkHandler(PLED_871x       pLed);
235
236 #endif //__RTW_LED_H_