• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  * Copyright(c) 2007 - 2012 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 <drv_types.h>
17 #include <rtl8723a_led.h>
18 
19 /*  */
20 /*	Description: */
21 /*		Callback function of LED BlinkTimer, */
22 /*		it just schedules to corresponding BlinkWorkItem/led_blink_hdl23a */
23 /*  */
BlinkTimerCallback(unsigned long data)24 static void BlinkTimerCallback(unsigned long data)
25 {
26 	struct led_8723a *pLed = (struct led_8723a *)data;
27 	struct rtw_adapter *padapter = pLed->padapter;
28 
29 	/* DBG_8723A("%s\n", __func__); */
30 
31 	if ((padapter->bSurpriseRemoved == true) || (padapter->bDriverStopped == true))
32 	{
33 		/* DBG_8723A("%s bSurpriseRemoved:%d, bDriverStopped:%d\n", __func__, padapter->bSurpriseRemoved, padapter->bDriverStopped); */
34 		return;
35 	}
36 	schedule_work(&pLed->BlinkWorkItem);
37 }
38 
39 /*  */
40 /*	Description: */
41 /*		Callback function of LED BlinkWorkItem. */
42 /*		We dispatch acture LED blink action according to LedStrategy. */
43 /*  */
BlinkWorkItemCallback23a(struct work_struct * work)44 void BlinkWorkItemCallback23a(struct work_struct *work)
45 {
46 	struct led_8723a *pLed = container_of(work, struct led_8723a, BlinkWorkItem);
47 	BlinkHandler23a(pLed);
48 }
49 
50 /*  */
51 /*	Description: */
52 /*		Reset status of led_8723a object. */
53 /*  */
ResetLedStatus23a(struct led_8723a * pLed)54 void ResetLedStatus23a(struct led_8723a * pLed) {
55 
56 	pLed->CurrLedState = RTW_LED_OFF; /*  Current LED state. */
57 	pLed->bLedOn = false; /*  true if LED is ON, false if LED is OFF. */
58 
59 	pLed->bLedBlinkInProgress = false; /*  true if it is blinking, false o.w.. */
60 	pLed->bLedWPSBlinkInProgress = false;
61 
62 	pLed->BlinkTimes = 0; /*  Number of times to toggle led state for blinking. */
63 	pLed->BlinkingLedState = LED_UNKNOWN; /*  Next state for blinking, either RTW_LED_ON or RTW_LED_OFF are. */
64 
65 	pLed->bLedNoLinkBlinkInProgress = false;
66 	pLed->bLedLinkBlinkInProgress = false;
67 	pLed->bLedStartToLinkBlinkInProgress = false;
68 	pLed->bLedScanBlinkInProgress = false;
69 }
70 
71  /*  */
72 /*	Description: */
73 /*		Initialize an led_8723a object. */
74 /*  */
75 void
InitLed871x23a(struct rtw_adapter * padapter,struct led_8723a * pLed,enum led_pin_8723a LedPin)76 InitLed871x23a(struct rtw_adapter *padapter, struct led_8723a *pLed, enum led_pin_8723a LedPin)
77 {
78 	pLed->padapter = padapter;
79 	pLed->LedPin = LedPin;
80 
81 	ResetLedStatus23a(pLed);
82 
83 	setup_timer(&pLed->BlinkTimer, BlinkTimerCallback, (unsigned long)pLed);
84 
85 	INIT_WORK(&pLed->BlinkWorkItem, BlinkWorkItemCallback23a);
86 }
87 
88 /*  */
89 /*	Description: */
90 /*		DeInitialize an led_8723a object. */
91 /*  */
92 void
DeInitLed871x23a(struct led_8723a * pLed)93 DeInitLed871x23a(struct led_8723a *pLed)
94 {
95 	cancel_work_sync(&pLed->BlinkWorkItem);
96 	del_timer_sync(&pLed->BlinkTimer);
97 	ResetLedStatus23a(pLed);
98 }
99 
100 /*	Description: */
101 /*		Implementation of LED blinking behavior. */
102 /*		It toggle off LED and schedule corresponding timer if necessary. */
103 
SwLedBlink(struct led_8723a * pLed)104 static void SwLedBlink(struct led_8723a *pLed)
105 {
106 	struct rtw_adapter *padapter = pLed->padapter;
107 	struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
108 	u8 bStopBlinking = false;
109 
110 	/*  Change LED according to BlinkingLedState specified. */
111 	if (pLed->BlinkingLedState == RTW_LED_ON) {
112 		SwLedOn23a(padapter, pLed);
113 		RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("Blinktimes (%d): turn on\n", pLed->BlinkTimes));
114 	} else {
115 		SwLedOff23a(padapter, pLed);
116 		RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("Blinktimes (%d): turn off\n", pLed->BlinkTimes));
117 	}
118 
119 	/*  Determine if we shall change LED state again. */
120 	pLed->BlinkTimes--;
121 	switch (pLed->CurrLedState) {
122 
123 	case LED_BLINK_NORMAL:
124 		if (pLed->BlinkTimes == 0)
125 			bStopBlinking = true;
126 		break;
127 	case LED_BLINK_StartToBlink:
128 		if (check_fwstate(pmlmepriv, _FW_LINKED) &&
129 		    check_fwstate(pmlmepriv, WIFI_STATION_STATE))
130 			bStopBlinking = true;
131 		if (check_fwstate(pmlmepriv, _FW_LINKED) &&
132 		    (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) ||
133 		    check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)))
134 			bStopBlinking = true;
135 		else if (pLed->BlinkTimes == 0)
136 			bStopBlinking = true;
137 		break;
138 	case LED_BLINK_WPS:
139 		if (pLed->BlinkTimes == 0)
140 			bStopBlinking = true;
141 		break;
142 	default:
143 		bStopBlinking = true;
144 		break;
145 	}
146 
147 	if (bStopBlinking) {
148 		if ((check_fwstate(pmlmepriv, _FW_LINKED)) && !pLed->bLedOn)
149 			SwLedOn23a(padapter, pLed);
150 		else if ((check_fwstate(pmlmepriv, _FW_LINKED)) &&  pLed->bLedOn)
151 			SwLedOff23a(padapter, pLed);
152 
153 		pLed->BlinkTimes = 0;
154 		pLed->bLedBlinkInProgress = false;
155 	} else {
156 		/*  Assign LED state to toggle. */
157 		if (pLed->BlinkingLedState == RTW_LED_ON)
158 			pLed->BlinkingLedState = RTW_LED_OFF;
159 		else
160 			pLed->BlinkingLedState = RTW_LED_ON;
161 
162 		/*  Schedule a timer to toggle LED state. */
163 		switch (pLed->CurrLedState) {
164 		case LED_BLINK_NORMAL:
165 			mod_timer(&pLed->BlinkTimer, jiffies +
166 				  msecs_to_jiffies(LED_BLINK_NORMAL_INTERVAL));
167 			break;
168 		case LED_BLINK_SLOWLY:
169 		case LED_BLINK_StartToBlink:
170 			mod_timer(&pLed->BlinkTimer, jiffies +
171 				  msecs_to_jiffies(LED_BLINK_SLOWLY_INTERVAL));
172 			break;
173 		case LED_BLINK_WPS:
174 			mod_timer(&pLed->BlinkTimer, jiffies +
175 				  msecs_to_jiffies(LED_BLINK_LONG_INTERVAL));
176 			break;
177 		default:
178 			mod_timer(&pLed->BlinkTimer, jiffies +
179 				  msecs_to_jiffies(LED_BLINK_SLOWLY_INTERVAL));
180 			break;
181 		}
182 	}
183 }
184 
SwLedBlink1(struct led_8723a * pLed)185 static void SwLedBlink1(struct led_8723a *pLed)
186 {
187 	struct rtw_adapter *padapter = pLed->padapter;
188 	struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
189 	unsigned long delay = 0;
190 	u8 bStopBlinking = false;
191 
192 	/*  Change LED according to BlinkingLedState specified. */
193 	if (pLed->BlinkingLedState == RTW_LED_ON) {
194 		SwLedOn23a(padapter, pLed);
195 		RT_TRACE(_module_rtl8712_led_c_, _drv_info_,
196 			 ("Blinktimes (%d): turn on\n", pLed->BlinkTimes));
197 	} else {
198 		SwLedOff23a(padapter, pLed);
199 		RT_TRACE(_module_rtl8712_led_c_, _drv_info_,
200 			 ("Blinktimes (%d): turn off\n", pLed->BlinkTimes));
201 	}
202 
203 	if (padapter->pwrctrlpriv.rf_pwrstate != rf_on) {
204 		SwLedOff23a(padapter, pLed);
205 		ResetLedStatus23a(pLed);
206 		return;
207 	}
208 	switch (pLed->CurrLedState) {
209 	case LED_BLINK_SLOWLY:
210 		if (pLed->bLedOn)
211 			pLed->BlinkingLedState = RTW_LED_OFF;
212 		else
213 			pLed->BlinkingLedState = RTW_LED_ON;
214 		delay = LED_BLINK_NO_LINK_INTERVAL_ALPHA;
215 		break;
216 	case LED_BLINK_NORMAL:
217 		if (pLed->bLedOn)
218 			pLed->BlinkingLedState = RTW_LED_OFF;
219 		else
220 			pLed->BlinkingLedState = RTW_LED_ON;
221 		delay = LED_BLINK_LINK_INTERVAL_ALPHA;
222 		break;
223 	case LED_BLINK_SCAN:
224 		pLed->BlinkTimes--;
225 		if (pLed->BlinkTimes == 0)
226 			bStopBlinking = true;
227 		if (bStopBlinking) {
228 			if (check_fwstate(pmlmepriv, _FW_LINKED)) {
229 				pLed->bLedLinkBlinkInProgress = true;
230 				pLed->CurrLedState = LED_BLINK_NORMAL;
231 				if (pLed->bLedOn)
232 					pLed->BlinkingLedState = RTW_LED_OFF;
233 				else
234 					pLed->BlinkingLedState = RTW_LED_ON;
235 				delay = LED_BLINK_LINK_INTERVAL_ALPHA;
236 				RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("CurrLedState %d\n", pLed->CurrLedState));
237 			} else {
238 				pLed->bLedNoLinkBlinkInProgress = true;
239 				pLed->CurrLedState = LED_BLINK_SLOWLY;
240 				if (pLed->bLedOn)
241 					pLed->BlinkingLedState = RTW_LED_OFF;
242 				else
243 					pLed->BlinkingLedState = RTW_LED_ON;
244 				delay = LED_BLINK_NO_LINK_INTERVAL_ALPHA;
245 				RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("CurrLedState %d\n", pLed->CurrLedState));
246 			}
247 			pLed->bLedScanBlinkInProgress = false;
248 		} else {
249 			if (pLed->bLedOn)
250 				pLed->BlinkingLedState = RTW_LED_OFF;
251 			else
252 				pLed->BlinkingLedState = RTW_LED_ON;
253 			delay = LED_BLINK_SCAN_INTERVAL_ALPHA;
254 		}
255 		break;
256 	case LED_BLINK_TXRX:
257 		pLed->BlinkTimes--;
258 		if (pLed->BlinkTimes == 0)
259 			bStopBlinking = true;
260 		if (bStopBlinking) {
261 			if (check_fwstate(pmlmepriv, _FW_LINKED)) {
262 				pLed->bLedLinkBlinkInProgress = true;
263 				pLed->CurrLedState = LED_BLINK_NORMAL;
264 				if (pLed->bLedOn)
265 					pLed->BlinkingLedState = RTW_LED_OFF;
266 				else
267 					pLed->BlinkingLedState = RTW_LED_ON;
268 				delay = LED_BLINK_LINK_INTERVAL_ALPHA;
269 				RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("CurrLedState %d\n", pLed->CurrLedState));
270 			} else {
271 				pLed->bLedNoLinkBlinkInProgress = true;
272 				pLed->CurrLedState = LED_BLINK_SLOWLY;
273 				if (pLed->bLedOn)
274 					pLed->BlinkingLedState = RTW_LED_OFF;
275 				else
276 					pLed->BlinkingLedState = RTW_LED_ON;
277 				delay = LED_BLINK_NO_LINK_INTERVAL_ALPHA;
278 				RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("CurrLedState %d\n", pLed->CurrLedState));
279 			}
280 			pLed->BlinkTimes = 0;
281 			pLed->bLedBlinkInProgress = false;
282 		} else {
283 			if (pLed->bLedOn)
284 				pLed->BlinkingLedState = RTW_LED_OFF;
285 			else
286 				pLed->BlinkingLedState = RTW_LED_ON;
287 			delay = LED_BLINK_FASTER_INTERVAL_ALPHA;
288 		}
289 		break;
290 	case LED_BLINK_WPS:
291 		if (pLed->bLedOn)
292 			pLed->BlinkingLedState = RTW_LED_OFF;
293 		else
294 			pLed->BlinkingLedState = RTW_LED_ON;
295 		delay = LED_BLINK_SCAN_INTERVAL_ALPHA;
296 		break;
297 	case LED_BLINK_WPS_STOP:	/* WPS success */
298 		if (pLed->BlinkingLedState == RTW_LED_ON)
299 			bStopBlinking = false;
300 		else
301 			bStopBlinking = true;
302 		if (bStopBlinking) {
303 			pLed->bLedLinkBlinkInProgress = true;
304 			pLed->CurrLedState = LED_BLINK_NORMAL;
305 			if (pLed->bLedOn)
306 				pLed->BlinkingLedState = RTW_LED_OFF;
307 			else
308 				pLed->BlinkingLedState = RTW_LED_ON;
309 			delay = LED_BLINK_LINK_INTERVAL_ALPHA;
310 			RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("CurrLedState %d\n", pLed->CurrLedState));
311 
312 			pLed->bLedWPSBlinkInProgress = false;
313 		} else {
314 			pLed->BlinkingLedState = RTW_LED_OFF;
315 			delay = LED_BLINK_WPS_SUCESS_INTERVAL_ALPHA;
316 		}
317 		break;
318 	default:
319 		break;
320 	}
321 	if (delay)
322 		mod_timer(&pLed->BlinkTimer, jiffies + msecs_to_jiffies(delay));
323 }
324 
SwLedBlink2(struct led_8723a * pLed)325 static void SwLedBlink2(struct led_8723a *pLed)
326 {
327 	struct rtw_adapter *padapter = pLed->padapter;
328 	struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
329 	u8 bStopBlinking = false;
330 
331 	/*  Change LED according to BlinkingLedState specified. */
332 	if (pLed->BlinkingLedState == RTW_LED_ON) {
333 		SwLedOn23a(padapter, pLed);
334 		RT_TRACE(_module_rtl8712_led_c_, _drv_info_,
335 			 ("Blinktimes (%d): turn on\n", pLed->BlinkTimes));
336 	} else {
337 		SwLedOff23a(padapter, pLed);
338 		RT_TRACE(_module_rtl8712_led_c_, _drv_info_,
339 			 ("Blinktimes (%d): turn off\n", pLed->BlinkTimes));
340 	}
341 	switch (pLed->CurrLedState) {
342 	case LED_BLINK_SCAN:
343 		pLed->BlinkTimes--;
344 		if (pLed->BlinkTimes == 0)
345 			bStopBlinking = true;
346 		if (bStopBlinking) {
347 			if (padapter->pwrctrlpriv.rf_pwrstate != rf_on) {
348 				SwLedOff23a(padapter, pLed);
349 			} else if (check_fwstate(pmlmepriv, _FW_LINKED)) {
350 				pLed->CurrLedState = RTW_LED_ON;
351 				pLed->BlinkingLedState = RTW_LED_ON;
352 				SwLedOn23a(padapter, pLed);
353 				RT_TRACE(_module_rtl8712_led_c_, _drv_info_,
354 					 ("stop scan blink CurrLedState %d\n",
355 					 pLed->CurrLedState));
356 			} else {
357 				pLed->CurrLedState = RTW_LED_OFF;
358 				pLed->BlinkingLedState = RTW_LED_OFF;
359 				SwLedOff23a(padapter, pLed);
360 				RT_TRACE(_module_rtl8712_led_c_, _drv_info_,
361 					 ("stop scan blink CurrLedState %d\n",
362 					 pLed->CurrLedState));
363 			}
364 			pLed->bLedScanBlinkInProgress = false;
365 		} else {
366 			if (padapter->pwrctrlpriv.rf_pwrstate != rf_on) {
367 				SwLedOff23a(padapter, pLed);
368 			} else {
369 				if (pLed->bLedOn)
370 					pLed->BlinkingLedState = RTW_LED_OFF;
371 				else
372 					pLed->BlinkingLedState = RTW_LED_ON;
373 				mod_timer(&pLed->BlinkTimer,
374 					  jiffies + msecs_to_jiffies(LED_BLINK_SCAN_INTERVAL_ALPHA));
375 			}
376 		}
377 		break;
378 	case LED_BLINK_TXRX:
379 		pLed->BlinkTimes--;
380 		if (pLed->BlinkTimes == 0)
381 			bStopBlinking = true;
382 		if (bStopBlinking) {
383 			if (padapter->pwrctrlpriv.rf_pwrstate != rf_on) {
384 				SwLedOff23a(padapter, pLed);
385 			} else if (check_fwstate(pmlmepriv, _FW_LINKED)) {
386 				pLed->CurrLedState = RTW_LED_ON;
387 				pLed->BlinkingLedState = RTW_LED_ON;
388 				SwLedOn23a(padapter, pLed);
389 				RT_TRACE(_module_rtl8712_led_c_, _drv_info_,
390 					 ("stop CurrLedState %d\n", pLed->CurrLedState));
391 
392 			} else {
393 				pLed->CurrLedState = RTW_LED_OFF;
394 				pLed->BlinkingLedState = RTW_LED_OFF;
395 				SwLedOff23a(padapter, pLed);
396 				RT_TRACE(_module_rtl8712_led_c_, _drv_info_,
397 					 ("stop CurrLedState %d\n", pLed->CurrLedState));
398 			}
399 			pLed->bLedBlinkInProgress = false;
400 		} else {
401 			if (padapter->pwrctrlpriv.rf_pwrstate != rf_on) {
402 				SwLedOff23a(padapter, pLed);
403 			} else {
404 				if (pLed->bLedOn)
405 					pLed->BlinkingLedState = RTW_LED_OFF;
406 				else
407 					pLed->BlinkingLedState = RTW_LED_ON;
408 				mod_timer(&pLed->BlinkTimer,
409 					  jiffies + msecs_to_jiffies(LED_BLINK_FASTER_INTERVAL_ALPHA));
410 			}
411 		}
412 		break;
413 	default:
414 		break;
415 	}
416 }
417 
SwLedBlink3(struct led_8723a * pLed)418 static void SwLedBlink3(struct led_8723a *pLed)
419 {
420 	struct rtw_adapter *padapter = pLed->padapter;
421 	struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
422 	u8 bStopBlinking = false;
423 
424 	/*  Change LED according to BlinkingLedState specified. */
425 	if (pLed->BlinkingLedState == RTW_LED_ON)
426 	{
427 		SwLedOn23a(padapter, pLed);
428 		RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("Blinktimes (%d): turn on\n", pLed->BlinkTimes));
429 	}
430 	else
431 	{
432 		if (pLed->CurrLedState != LED_BLINK_WPS_STOP)
433 			SwLedOff23a(padapter, pLed);
434 		RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("Blinktimes (%d): turn off\n", pLed->BlinkTimes));
435 	}
436 
437 	switch (pLed->CurrLedState)
438 	{
439 		case LED_BLINK_SCAN:
440 			pLed->BlinkTimes--;
441 			if (pLed->BlinkTimes == 0)
442 			{
443 				bStopBlinking = true;
444 			}
445 
446 			if (bStopBlinking)
447 			{
448 				if (padapter->pwrctrlpriv.rf_pwrstate != rf_on)
449 				{
450 					SwLedOff23a(padapter, pLed);
451 				}
452 				else if (check_fwstate(pmlmepriv, _FW_LINKED)) {
453 					pLed->CurrLedState = RTW_LED_ON;
454 					pLed->BlinkingLedState = RTW_LED_ON;
455 					if (!pLed->bLedOn)
456 						SwLedOn23a(padapter, pLed);
457 
458 					RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("CurrLedState %d\n", pLed->CurrLedState));
459 				} else {
460 					pLed->CurrLedState = RTW_LED_OFF;
461 					pLed->BlinkingLedState = RTW_LED_OFF;
462 					if (pLed->bLedOn)
463 						SwLedOff23a(padapter, pLed);
464 
465 					RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("CurrLedState %d\n", pLed->CurrLedState));
466 				}
467 				pLed->bLedScanBlinkInProgress = false;
468 			}
469 			else
470 			{
471 				if (padapter->pwrctrlpriv.rf_pwrstate != rf_on)
472 				{
473 					SwLedOff23a(padapter, pLed);
474 				}
475 				else
476 				{
477 					if (pLed->bLedOn)
478 						pLed->BlinkingLedState = RTW_LED_OFF;
479 					else
480 						pLed->BlinkingLedState = RTW_LED_ON;
481 					mod_timer(&pLed->BlinkTimer,
482 						  jiffies + msecs_to_jiffies(LED_BLINK_SCAN_INTERVAL_ALPHA));
483 				}
484 			}
485 			break;
486 
487 		case LED_BLINK_TXRX:
488 			pLed->BlinkTimes--;
489 			if (pLed->BlinkTimes == 0)
490 			{
491 				bStopBlinking = true;
492 			}
493 			if (bStopBlinking)
494 			{
495 				if (padapter->pwrctrlpriv.rf_pwrstate != rf_on)
496 				{
497 					SwLedOff23a(padapter, pLed);
498 				} else if (check_fwstate(pmlmepriv,
499 							 _FW_LINKED)) {
500 					pLed->CurrLedState = RTW_LED_ON;
501 					pLed->BlinkingLedState = RTW_LED_ON;
502 
503 					if (!pLed->bLedOn)
504 						SwLedOn23a(padapter, pLed);
505 
506 					RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("CurrLedState %d\n", pLed->CurrLedState));
507 				} else {
508 					pLed->CurrLedState = RTW_LED_OFF;
509 					pLed->BlinkingLedState = RTW_LED_OFF;
510 
511 					if (pLed->bLedOn)
512 						SwLedOff23a(padapter, pLed);
513 
514 					RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("CurrLedState %d\n", pLed->CurrLedState));
515 				}
516 				pLed->bLedBlinkInProgress = false;
517 			}
518 			else
519 			{
520 				if (padapter->pwrctrlpriv.rf_pwrstate != rf_on)
521 				{
522 					SwLedOff23a(padapter, pLed);
523 				}
524 				else
525 				{
526 					if (pLed->bLedOn)
527 						pLed->BlinkingLedState = RTW_LED_OFF;
528 					else
529 						pLed->BlinkingLedState = RTW_LED_ON;
530 					mod_timer(&pLed->BlinkTimer,
531 						  jiffies + msecs_to_jiffies(LED_BLINK_FASTER_INTERVAL_ALPHA));
532 				}
533 			}
534 			break;
535 
536 		case LED_BLINK_WPS:
537 			if (pLed->bLedOn)
538 				pLed->BlinkingLedState = RTW_LED_OFF;
539 			else
540 				pLed->BlinkingLedState = RTW_LED_ON;
541 			mod_timer(&pLed->BlinkTimer, jiffies +
542 				  msecs_to_jiffies(LED_BLINK_SCAN_INTERVAL_ALPHA));
543 			break;
544 
545 		case LED_BLINK_WPS_STOP:	/* WPS success */
546 			if (pLed->BlinkingLedState == RTW_LED_ON)
547 			{
548 				pLed->BlinkingLedState = RTW_LED_OFF;
549 				mod_timer(&pLed->BlinkTimer, jiffies +
550 					  msecs_to_jiffies(LED_BLINK_WPS_SUCESS_INTERVAL_ALPHA));
551 				bStopBlinking = false;
552 			} else {
553 				bStopBlinking = true;
554 			}
555 
556 			if (bStopBlinking)
557 			{
558 				if (padapter->pwrctrlpriv.rf_pwrstate != rf_on)
559 				{
560 					SwLedOff23a(padapter, pLed);
561 				}
562 				else
563 				{
564 					pLed->CurrLedState = RTW_LED_ON;
565 					pLed->BlinkingLedState = RTW_LED_ON;
566 					SwLedOn23a(padapter, pLed);
567 					RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("CurrLedState %d\n", pLed->CurrLedState));
568 				}
569 				pLed->bLedWPSBlinkInProgress = false;
570 			}
571 			break;
572 
573 		default:
574 			break;
575 	}
576 }
577 
SwLedBlink4(struct led_8723a * pLed)578 static void SwLedBlink4(struct led_8723a *pLed)
579 {
580 	struct rtw_adapter *padapter = pLed->padapter;
581 	struct led_priv *ledpriv = &padapter->ledpriv;
582 	struct led_8723a *pLed1 = &ledpriv->SwLed1;
583 	u8 bStopBlinking = false;
584 	unsigned long delay = 0;
585 
586 	/*  Change LED according to BlinkingLedState specified. */
587 	if (pLed->BlinkingLedState == RTW_LED_ON)
588 	{
589 		SwLedOn23a(padapter, pLed);
590 		RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("Blinktimes (%d): turn on\n", pLed->BlinkTimes));
591 	} else {
592 		SwLedOff23a(padapter, pLed);
593 		RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("Blinktimes (%d): turn off\n", pLed->BlinkTimes));
594 	}
595 
596 	if (!pLed1->bLedWPSBlinkInProgress && pLed1->BlinkingLedState == LED_UNKNOWN)
597 	{
598 		pLed1->BlinkingLedState = RTW_LED_OFF;
599 		pLed1->CurrLedState = RTW_LED_OFF;
600 		SwLedOff23a(padapter, pLed1);
601 	}
602 
603 	switch (pLed->CurrLedState)
604 	{
605 		case LED_BLINK_SLOWLY:
606 			if (pLed->bLedOn)
607 				pLed->BlinkingLedState = RTW_LED_OFF;
608 			else
609 				pLed->BlinkingLedState = RTW_LED_ON;
610 			delay = LED_BLINK_NO_LINK_INTERVAL_ALPHA;
611 			break;
612 
613 		case LED_BLINK_StartToBlink:
614 			if (pLed->bLedOn) {
615 				pLed->BlinkingLedState = RTW_LED_OFF;
616 				delay = LED_BLINK_SLOWLY_INTERVAL;
617 			} else {
618 				pLed->BlinkingLedState = RTW_LED_ON;
619 				delay = LED_BLINK_NORMAL_INTERVAL;
620 			}
621 			break;
622 
623 		case LED_BLINK_SCAN:
624 			pLed->BlinkTimes--;
625 			if (pLed->BlinkTimes == 0) {
626 				bStopBlinking = false;
627 			}
628 
629 			if (bStopBlinking) {
630 				if (padapter->pwrctrlpriv.rf_pwrstate != rf_on && padapter->pwrctrlpriv.rfoff_reason > RF_CHANGE_BY_PS) {
631 					SwLedOff23a(padapter, pLed);
632 				} else {
633 					pLed->bLedNoLinkBlinkInProgress = false;
634 					pLed->CurrLedState = LED_BLINK_SLOWLY;
635 					if (pLed->bLedOn)
636 						pLed->BlinkingLedState = RTW_LED_OFF;
637 					else
638 						pLed->BlinkingLedState = RTW_LED_ON;
639 					delay = LED_BLINK_NO_LINK_INTERVAL_ALPHA;
640 				}
641 				pLed->bLedScanBlinkInProgress = false;
642 			} else {
643 				if (padapter->pwrctrlpriv.rf_pwrstate != rf_on && padapter->pwrctrlpriv.rfoff_reason > RF_CHANGE_BY_PS) {
644 					SwLedOff23a(padapter, pLed);
645 				} else {
646 					if (pLed->bLedOn)
647 						pLed->BlinkingLedState = RTW_LED_OFF;
648 					else
649 						pLed->BlinkingLedState = RTW_LED_ON;
650 					delay = LED_BLINK_SCAN_INTERVAL_ALPHA;
651 				}
652 			}
653 			break;
654 
655 		case LED_BLINK_TXRX:
656 			pLed->BlinkTimes--;
657 			if (pLed->BlinkTimes == 0) {
658 				bStopBlinking = true;
659 			}
660 			if (bStopBlinking) {
661 				if (padapter->pwrctrlpriv.rf_pwrstate != rf_on && padapter->pwrctrlpriv.rfoff_reason > RF_CHANGE_BY_PS) {
662 					SwLedOff23a(padapter, pLed);
663 				} else {
664 					pLed->bLedNoLinkBlinkInProgress = true;
665 					pLed->CurrLedState = LED_BLINK_SLOWLY;
666 					if (pLed->bLedOn)
667 						pLed->BlinkingLedState = RTW_LED_OFF;
668 					else
669 						pLed->BlinkingLedState = RTW_LED_ON;
670 					delay = LED_BLINK_NO_LINK_INTERVAL_ALPHA;
671 				}
672 				pLed->bLedBlinkInProgress = false;
673 			} else {
674 				if (padapter->pwrctrlpriv.rf_pwrstate != rf_on && padapter->pwrctrlpriv.rfoff_reason > RF_CHANGE_BY_PS) {
675 					SwLedOff23a(padapter, pLed);
676 				} else {
677 					if (pLed->bLedOn)
678 						pLed->BlinkingLedState = RTW_LED_OFF;
679 					else
680 						pLed->BlinkingLedState = RTW_LED_ON;
681 					delay = LED_BLINK_FASTER_INTERVAL_ALPHA;
682 				}
683 			}
684 			break;
685 
686 		case LED_BLINK_WPS:
687 			if (pLed->bLedOn) {
688 				pLed->BlinkingLedState = RTW_LED_OFF;
689 				delay = LED_BLINK_SLOWLY_INTERVAL;
690 			} else {
691 				pLed->BlinkingLedState = RTW_LED_ON;
692 				delay = LED_BLINK_NORMAL_INTERVAL;
693 			}
694 			break;
695 
696 		case LED_BLINK_WPS_STOP:	/* WPS authentication fail */
697 			if (pLed->bLedOn)
698 				pLed->BlinkingLedState = RTW_LED_OFF;
699 			else
700 				pLed->BlinkingLedState = RTW_LED_ON;
701 
702 			delay = LED_BLINK_NORMAL_INTERVAL;
703 			break;
704 
705 		case LED_BLINK_WPS_STOP_OVERLAP:	/* WPS session overlap */
706 			pLed->BlinkTimes--;
707 			if (pLed->BlinkTimes == 0) {
708 				if (pLed->bLedOn) {
709 					pLed->BlinkTimes = 1;
710 				} else {
711 					bStopBlinking = true;
712 				}
713 			}
714 
715 			if (bStopBlinking) {
716 				pLed->BlinkTimes = 10;
717 				pLed->BlinkingLedState = RTW_LED_ON;
718 				delay = LED_BLINK_LINK_INTERVAL_ALPHA;
719 			} else {
720 				if (pLed->bLedOn)
721 					pLed->BlinkingLedState = RTW_LED_OFF;
722 				else
723 					pLed->BlinkingLedState = RTW_LED_ON;
724 
725 				delay = LED_BLINK_NORMAL_INTERVAL;
726 			}
727 			break;
728 
729 		default:
730 			break;
731 	}
732 	if (delay)
733 		mod_timer(&pLed->BlinkTimer, jiffies + msecs_to_jiffies(delay));
734 
735 	RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("SwLedBlink4 CurrLedState %d\n", pLed->CurrLedState));
736 }
737 
SwLedBlink5(struct led_8723a * pLed)738 static void SwLedBlink5(struct led_8723a *pLed)
739 {
740 	struct rtw_adapter *padapter = pLed->padapter;
741 	u8 bStopBlinking = false;
742 	unsigned long delay = 0;
743 
744 	/*  Change LED according to BlinkingLedState specified. */
745 	if (pLed->BlinkingLedState == RTW_LED_ON) {
746 		SwLedOn23a(padapter, pLed);
747 		RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("Blinktimes (%d): turn on\n", pLed->BlinkTimes));
748 	} else {
749 		SwLedOff23a(padapter, pLed);
750 		RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("Blinktimes (%d): turn off\n", pLed->BlinkTimes));
751 	}
752 
753 	switch (pLed->CurrLedState)
754 	{
755 		case LED_BLINK_SCAN:
756 			pLed->BlinkTimes--;
757 			if (pLed->BlinkTimes == 0) {
758 				bStopBlinking = true;
759 			}
760 
761 			if (bStopBlinking) {
762 				if (padapter->pwrctrlpriv.rf_pwrstate != rf_on && padapter->pwrctrlpriv.rfoff_reason > RF_CHANGE_BY_PS) {
763 					pLed->CurrLedState = RTW_LED_OFF;
764 					pLed->BlinkingLedState = RTW_LED_OFF;
765 					if (pLed->bLedOn)
766 						SwLedOff23a(padapter, pLed);
767 				} else {
768 					pLed->CurrLedState = RTW_LED_ON;
769 					pLed->BlinkingLedState = RTW_LED_ON;
770 					if (!pLed->bLedOn)
771 						delay = LED_BLINK_FASTER_INTERVAL_ALPHA;
772 				}
773 
774 				pLed->bLedScanBlinkInProgress = false;
775 			} else {
776 				if (padapter->pwrctrlpriv.rf_pwrstate != rf_on && padapter->pwrctrlpriv.rfoff_reason > RF_CHANGE_BY_PS) {
777 					SwLedOff23a(padapter, pLed);
778 				} else {
779 					if (pLed->bLedOn)
780 						pLed->BlinkingLedState = RTW_LED_OFF;
781 					else
782 						pLed->BlinkingLedState = RTW_LED_ON;
783 					delay = LED_BLINK_SCAN_INTERVAL_ALPHA;
784 				}
785 			}
786 			break;
787 
788 		case LED_BLINK_TXRX:
789 			pLed->BlinkTimes--;
790 			if (pLed->BlinkTimes == 0) {
791 				bStopBlinking = true;
792 			}
793 
794 			if (bStopBlinking) {
795 				if (padapter->pwrctrlpriv.rf_pwrstate != rf_on && padapter->pwrctrlpriv.rfoff_reason > RF_CHANGE_BY_PS) {
796 					pLed->CurrLedState = RTW_LED_OFF;
797 					pLed->BlinkingLedState = RTW_LED_OFF;
798 					if (pLed->bLedOn)
799 						SwLedOff23a(padapter, pLed);
800 				} else {
801 					pLed->CurrLedState = RTW_LED_ON;
802 					pLed->BlinkingLedState = RTW_LED_ON;
803 					if (!pLed->bLedOn)
804 						delay = LED_BLINK_FASTER_INTERVAL_ALPHA;
805 				}
806 
807 				pLed->bLedBlinkInProgress = false;
808 			} else {
809 				if (padapter->pwrctrlpriv.rf_pwrstate != rf_on && padapter->pwrctrlpriv.rfoff_reason > RF_CHANGE_BY_PS) {
810 					SwLedOff23a(padapter, pLed);
811 				} else {
812 					if (pLed->bLedOn)
813 						pLed->BlinkingLedState = RTW_LED_OFF;
814 					else
815 						pLed->BlinkingLedState = RTW_LED_ON;
816 					delay = LED_BLINK_FASTER_INTERVAL_ALPHA;
817 				}
818 			}
819 			break;
820 
821 		default:
822 			break;
823 	}
824 
825 	if (delay)
826 		mod_timer(&pLed->BlinkTimer, jiffies + msecs_to_jiffies(delay));
827 
828 	RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("SwLedBlink5 CurrLedState %d\n", pLed->CurrLedState));
829 }
830 
SwLedBlink6(struct led_8723a * pLed)831 static void SwLedBlink6(struct led_8723a *pLed)
832 {
833 	struct rtw_adapter *padapter = pLed->padapter;
834 
835 	/*  Change LED according to BlinkingLedState specified. */
836 	if (pLed->BlinkingLedState == RTW_LED_ON) {
837 		SwLedOn23a(padapter, pLed);
838 		RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("Blinktimes (%d): turn on\n", pLed->BlinkTimes));
839 	} else {
840 		SwLedOff23a(padapter, pLed);
841 		RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("Blinktimes (%d): turn off\n", pLed->BlinkTimes));
842 	}
843 	RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("<==== blink6\n"));
844 }
845 
846 /* ALPHA, added by chiyoko, 20090106 */
847 static void
SwLedControlMode1(struct rtw_adapter * padapter,enum led_ctl_mode LedAction)848 SwLedControlMode1(struct rtw_adapter *padapter, enum led_ctl_mode LedAction)
849 {
850 	struct led_priv *ledpriv = &padapter->ledpriv;
851 	struct led_8723a *pLed = &ledpriv->SwLed0;
852 	struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
853 
854 	long delay = -1;
855 
856 	switch (LedAction)
857 	{
858 		case LED_CTL_POWER_ON:
859 		case LED_CTL_START_TO_LINK:
860 		case LED_CTL_NO_LINK:
861 			if (pLed->bLedNoLinkBlinkInProgress == false) {
862 				if (pLed->CurrLedState == LED_BLINK_SCAN ||
863 				    IS_LED_WPS_BLINKING(pLed)) {
864 					return;
865 				}
866 				if (pLed->bLedLinkBlinkInProgress == true) {
867 					del_timer_sync(&pLed->BlinkTimer);
868 					pLed->bLedLinkBlinkInProgress = false;
869 				}
870 				if (pLed->bLedBlinkInProgress == true) {
871 					del_timer_sync(&pLed->BlinkTimer);
872 					pLed->bLedBlinkInProgress = false;
873 				}
874 
875 				pLed->bLedNoLinkBlinkInProgress = true;
876 				pLed->CurrLedState = LED_BLINK_SLOWLY;
877 				if (pLed->bLedOn)
878 					pLed->BlinkingLedState = RTW_LED_OFF;
879 				else
880 					pLed->BlinkingLedState = RTW_LED_ON;
881 				delay = LED_BLINK_NO_LINK_INTERVAL_ALPHA;
882 			}
883 			break;
884 
885 		case LED_CTL_LINK:
886 			if (pLed->bLedLinkBlinkInProgress == false) {
887 				if (pLed->CurrLedState == LED_BLINK_SCAN ||
888 				    IS_LED_WPS_BLINKING(pLed)) {
889 					return;
890 				}
891 				if (pLed->bLedNoLinkBlinkInProgress == true) {
892 					del_timer_sync(&pLed->BlinkTimer);
893 					pLed->bLedNoLinkBlinkInProgress = false;
894 				}
895 				if (pLed->bLedBlinkInProgress == true) {
896 					del_timer_sync(&pLed->BlinkTimer);
897 					pLed->bLedBlinkInProgress = false;
898 				}
899 				pLed->bLedLinkBlinkInProgress = true;
900 				pLed->CurrLedState = LED_BLINK_NORMAL;
901 				if (pLed->bLedOn)
902 					pLed->BlinkingLedState = RTW_LED_OFF;
903 				else
904 					pLed->BlinkingLedState = RTW_LED_ON;
905 				delay = LED_BLINK_LINK_INTERVAL_ALPHA;
906 			}
907 			break;
908 
909 		case LED_CTL_SITE_SURVEY:
910 			 if (pmlmepriv->LinkDetectInfo.bBusyTraffic &&
911 			     check_fwstate(pmlmepriv, _FW_LINKED))
912 				;
913 			 else if (pLed->bLedScanBlinkInProgress == false) {
914 				if (IS_LED_WPS_BLINKING(pLed))
915 					return;
916 
917 				if (pLed->bLedNoLinkBlinkInProgress == true) {
918 					del_timer_sync(&pLed->BlinkTimer);
919 					pLed->bLedNoLinkBlinkInProgress = false;
920 				}
921 				if (pLed->bLedLinkBlinkInProgress == true) {
922 					del_timer_sync(&pLed->BlinkTimer);
923 					pLed->bLedLinkBlinkInProgress = false;
924 				}
925 				if (pLed->bLedBlinkInProgress == true) {
926 					del_timer_sync(&pLed->BlinkTimer);
927 					pLed->bLedBlinkInProgress = false;
928 				}
929 				pLed->bLedScanBlinkInProgress = true;
930 				pLed->CurrLedState = LED_BLINK_SCAN;
931 				pLed->BlinkTimes = 24;
932 				if (pLed->bLedOn)
933 					pLed->BlinkingLedState = RTW_LED_OFF;
934 				else
935 					pLed->BlinkingLedState = RTW_LED_ON;
936 				delay = LED_BLINK_SCAN_INTERVAL_ALPHA;
937 			 }
938 			break;
939 
940 		case LED_CTL_TX:
941 		case LED_CTL_RX:
942 			if (pLed->bLedBlinkInProgress == false) {
943 				if (pLed->CurrLedState == LED_BLINK_SCAN ||
944 				    IS_LED_WPS_BLINKING(pLed)) {
945 					return;
946 				}
947 				if (pLed->bLedNoLinkBlinkInProgress == true) {
948 					del_timer_sync(&pLed->BlinkTimer);
949 					pLed->bLedNoLinkBlinkInProgress = false;
950 				}
951 				if (pLed->bLedLinkBlinkInProgress == true) {
952 					del_timer_sync(&pLed->BlinkTimer);
953 					pLed->bLedLinkBlinkInProgress = false;
954 				}
955 				pLed->bLedBlinkInProgress = true;
956 				pLed->CurrLedState = LED_BLINK_TXRX;
957 				pLed->BlinkTimes = 2;
958 				if (pLed->bLedOn)
959 					pLed->BlinkingLedState = RTW_LED_OFF;
960 				else
961 					pLed->BlinkingLedState = RTW_LED_ON;
962 				delay = LED_BLINK_FASTER_INTERVAL_ALPHA;
963 			}
964 			break;
965 
966 		case LED_CTL_START_WPS: /* wait until xinpin finish */
967 		case LED_CTL_START_WPS_BOTTON:
968 			if (pLed->bLedWPSBlinkInProgress == false) {
969 				if (pLed->bLedNoLinkBlinkInProgress == true) {
970 					del_timer_sync(&pLed->BlinkTimer);
971 					pLed->bLedNoLinkBlinkInProgress = false;
972 				}
973 				if (pLed->bLedLinkBlinkInProgress == true) {
974 					del_timer_sync(&pLed->BlinkTimer);
975 					pLed->bLedLinkBlinkInProgress = false;
976 				}
977 				if (pLed->bLedBlinkInProgress == true) {
978 					del_timer_sync(&pLed->BlinkTimer);
979 					pLed->bLedBlinkInProgress = false;
980 				}
981 				if (pLed->bLedScanBlinkInProgress == true) {
982 					del_timer_sync(&pLed->BlinkTimer);
983 					pLed->bLedScanBlinkInProgress = false;
984 				}
985 				pLed->bLedWPSBlinkInProgress = true;
986 				pLed->CurrLedState = LED_BLINK_WPS;
987 				if (pLed->bLedOn)
988 					pLed->BlinkingLedState = RTW_LED_OFF;
989 				else
990 					pLed->BlinkingLedState = RTW_LED_ON;
991 				delay = LED_BLINK_SCAN_INTERVAL_ALPHA;
992 			 }
993 			break;
994 
995 		case LED_CTL_STOP_WPS:
996 			if (pLed->bLedNoLinkBlinkInProgress == true) {
997 				del_timer_sync(&pLed->BlinkTimer);
998 				pLed->bLedNoLinkBlinkInProgress = false;
999 			}
1000 			if (pLed->bLedLinkBlinkInProgress == true) {
1001 				del_timer_sync(&pLed->BlinkTimer);
1002 				pLed->bLedLinkBlinkInProgress = false;
1003 			}
1004 			if (pLed->bLedBlinkInProgress == true) {
1005 				del_timer_sync(&pLed->BlinkTimer);
1006 				pLed->bLedBlinkInProgress = false;
1007 			}
1008 			if (pLed->bLedScanBlinkInProgress == true) {
1009 				del_timer_sync(&pLed->BlinkTimer);
1010 				pLed->bLedScanBlinkInProgress = false;
1011 			}
1012 			if (pLed->bLedWPSBlinkInProgress) {
1013 				del_timer_sync(&pLed->BlinkTimer);
1014 			} else {
1015 				pLed->bLedWPSBlinkInProgress = true;
1016 			}
1017 
1018 			pLed->CurrLedState = LED_BLINK_WPS_STOP;
1019 			if (pLed->bLedOn) {
1020 				pLed->BlinkingLedState = RTW_LED_OFF;
1021 				delay = LED_BLINK_WPS_SUCESS_INTERVAL_ALPHA;
1022 			} else {
1023 				pLed->BlinkingLedState = RTW_LED_ON;
1024 				delay = 0;
1025 			}
1026 			break;
1027 
1028 		case LED_CTL_STOP_WPS_FAIL:
1029 			if (pLed->bLedWPSBlinkInProgress) {
1030 				del_timer_sync(&pLed->BlinkTimer);
1031 				pLed->bLedWPSBlinkInProgress = false;
1032 			}
1033 
1034 			pLed->bLedNoLinkBlinkInProgress = true;
1035 			pLed->CurrLedState = LED_BLINK_SLOWLY;
1036 			if (pLed->bLedOn)
1037 				pLed->BlinkingLedState = RTW_LED_OFF;
1038 			else
1039 				pLed->BlinkingLedState = RTW_LED_ON;
1040 			delay = LED_BLINK_NO_LINK_INTERVAL_ALPHA;
1041 			break;
1042 
1043 		case LED_CTL_POWER_OFF:
1044 			pLed->CurrLedState = RTW_LED_OFF;
1045 			pLed->BlinkingLedState = RTW_LED_OFF;
1046 			if (pLed->bLedNoLinkBlinkInProgress) {
1047 				del_timer_sync(&pLed->BlinkTimer);
1048 				pLed->bLedNoLinkBlinkInProgress = false;
1049 			}
1050 			if (pLed->bLedLinkBlinkInProgress) {
1051 				del_timer_sync(&pLed->BlinkTimer);
1052 				pLed->bLedLinkBlinkInProgress = false;
1053 			}
1054 			if (pLed->bLedBlinkInProgress) {
1055 				del_timer_sync(&pLed->BlinkTimer);
1056 				pLed->bLedBlinkInProgress = false;
1057 			}
1058 			if (pLed->bLedWPSBlinkInProgress) {
1059 				del_timer_sync(&pLed->BlinkTimer);
1060 				pLed->bLedWPSBlinkInProgress = false;
1061 			}
1062 			if (pLed->bLedScanBlinkInProgress) {
1063 				del_timer_sync(&pLed->BlinkTimer);
1064 				pLed->bLedScanBlinkInProgress = false;
1065 			}
1066 
1067 			SwLedOff23a(padapter, pLed);
1068 			break;
1069 
1070 		default:
1071 			break;
1072 
1073 	}
1074 
1075 	if (delay != -1)
1076 		mod_timer(&pLed->BlinkTimer, jiffies + msecs_to_jiffies(delay));
1077 
1078 	RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("Led %d\n", pLed->CurrLedState));
1079 }
1080 
1081  /* Arcadyan/Sitecom , added by chiyoko, 20090216 */
1082 static void
SwLedControlMode2(struct rtw_adapter * padapter,enum led_ctl_mode LedAction)1083 SwLedControlMode2(struct rtw_adapter *padapter, enum led_ctl_mode LedAction)
1084 {
1085 	struct led_priv *ledpriv = &padapter->ledpriv;
1086 	struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1087 	struct led_8723a *pLed = &ledpriv->SwLed0;
1088 	long delay = -1;
1089 
1090 	switch (LedAction) {
1091 	case LED_CTL_SITE_SURVEY:
1092 		 if (pmlmepriv->LinkDetectInfo.bBusyTraffic)
1093 			;
1094 		 else if (pLed->bLedScanBlinkInProgress == false) {
1095 			if (IS_LED_WPS_BLINKING(pLed))
1096 				return;
1097 
1098 			if (pLed->bLedBlinkInProgress == true) {
1099 				del_timer_sync(&pLed->BlinkTimer);
1100 				pLed->bLedBlinkInProgress = false;
1101 			}
1102 			pLed->bLedScanBlinkInProgress = true;
1103 			pLed->CurrLedState = LED_BLINK_SCAN;
1104 			pLed->BlinkTimes = 24;
1105 			if (pLed->bLedOn)
1106 				pLed->BlinkingLedState = RTW_LED_OFF;
1107 			else
1108 				pLed->BlinkingLedState = RTW_LED_ON;
1109 			delay = LED_BLINK_SCAN_INTERVAL_ALPHA;
1110 		 }
1111 		 break;
1112 	case LED_CTL_TX:
1113 	case LED_CTL_RX:
1114 		if (pLed->bLedBlinkInProgress == false &&
1115 		    check_fwstate(pmlmepriv, _FW_LINKED)) {
1116 			if (pLed->CurrLedState == LED_BLINK_SCAN ||
1117 			    IS_LED_WPS_BLINKING(pLed)) {
1118 				return;
1119 			}
1120 
1121 			pLed->bLedBlinkInProgress = true;
1122 			pLed->CurrLedState = LED_BLINK_TXRX;
1123 			pLed->BlinkTimes = 2;
1124 			if (pLed->bLedOn)
1125 				pLed->BlinkingLedState = RTW_LED_OFF;
1126 			else
1127 				pLed->BlinkingLedState = RTW_LED_ON;
1128 			delay = LED_BLINK_FASTER_INTERVAL_ALPHA;
1129 		}
1130 		break;
1131 	case LED_CTL_LINK:
1132 		pLed->CurrLedState = RTW_LED_ON;
1133 		pLed->BlinkingLedState = RTW_LED_ON;
1134 		if (pLed->bLedBlinkInProgress) {
1135 			del_timer_sync(&pLed->BlinkTimer);
1136 			pLed->bLedBlinkInProgress = false;
1137 		}
1138 		if (pLed->bLedScanBlinkInProgress) {
1139 			del_timer_sync(&pLed->BlinkTimer);
1140 			pLed->bLedScanBlinkInProgress = false;
1141 		}
1142 
1143 		delay = 0;
1144 		break;
1145 	case LED_CTL_START_WPS: /* wait until xinpin finish */
1146 	case LED_CTL_START_WPS_BOTTON:
1147 		if (pLed->bLedWPSBlinkInProgress == false) {
1148 			if (pLed->bLedBlinkInProgress == true) {
1149 				del_timer_sync(&pLed->BlinkTimer);
1150 				pLed->bLedBlinkInProgress = false;
1151 			}
1152 			if (pLed->bLedScanBlinkInProgress == true) {
1153 				del_timer_sync(&pLed->BlinkTimer);
1154 				pLed->bLedScanBlinkInProgress = false;
1155 			}
1156 			pLed->bLedWPSBlinkInProgress = true;
1157 			pLed->CurrLedState = RTW_LED_ON;
1158 			pLed->BlinkingLedState = RTW_LED_ON;
1159 			delay = 0;
1160 		 }
1161 		break;
1162 	case LED_CTL_STOP_WPS:
1163 		pLed->bLedWPSBlinkInProgress = false;
1164 		if (padapter->pwrctrlpriv.rf_pwrstate != rf_on) {
1165 			SwLedOff23a(padapter, pLed);
1166 		} else {
1167 			pLed->CurrLedState = RTW_LED_ON;
1168 			pLed->BlinkingLedState = RTW_LED_ON;
1169 			delay = 0;
1170 			RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("CurrLedState %d\n", pLed->CurrLedState));
1171 		}
1172 		break;
1173 	case LED_CTL_STOP_WPS_FAIL:
1174 		pLed->bLedWPSBlinkInProgress = false;
1175 		if (padapter->pwrctrlpriv.rf_pwrstate != rf_on) {
1176 			SwLedOff23a(padapter, pLed);
1177 		} else {
1178 			pLed->CurrLedState = RTW_LED_OFF;
1179 			pLed->BlinkingLedState = RTW_LED_OFF;
1180 			delay = 0;
1181 			RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("CurrLedState %d\n", pLed->CurrLedState));
1182 		}
1183 		break;
1184 	case LED_CTL_START_TO_LINK:
1185 	case LED_CTL_NO_LINK:
1186 		if (!IS_LED_BLINKING(pLed))
1187 		{
1188 			pLed->CurrLedState = RTW_LED_OFF;
1189 			pLed->BlinkingLedState = RTW_LED_OFF;
1190 			delay = 0;
1191 		}
1192 		break;
1193 	case LED_CTL_POWER_OFF:
1194 		pLed->CurrLedState = RTW_LED_OFF;
1195 		pLed->BlinkingLedState = RTW_LED_OFF;
1196 		if (pLed->bLedBlinkInProgress) {
1197 			del_timer_sync(&pLed->BlinkTimer);
1198 			pLed->bLedBlinkInProgress = false;
1199 		}
1200 		if (pLed->bLedScanBlinkInProgress) {
1201 			del_timer_sync(&pLed->BlinkTimer);
1202 			pLed->bLedScanBlinkInProgress = false;
1203 		}
1204 		if (pLed->bLedWPSBlinkInProgress) {
1205 			del_timer_sync(&pLed->BlinkTimer);
1206 			pLed->bLedWPSBlinkInProgress = false;
1207 		}
1208 
1209 		delay = 0;
1210 		break;
1211 	default:
1212 		break;
1213 
1214 	}
1215 
1216 	if (delay != -1)
1217 		mod_timer(&pLed->BlinkTimer, jiffies + msecs_to_jiffies(delay));
1218 
1219 	RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("CurrLedState %d\n", pLed->CurrLedState));
1220 }
1221 
1222   /* COREGA, added by chiyoko, 20090316 */
1223 static void
SwLedControlMode3(struct rtw_adapter * padapter,enum led_ctl_mode LedAction)1224 SwLedControlMode3(struct rtw_adapter *padapter, enum led_ctl_mode LedAction)
1225 {
1226 	struct led_priv *ledpriv = &padapter->ledpriv;
1227 	struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1228 	struct led_8723a *pLed = &ledpriv->SwLed0;
1229 	long delay = -1;
1230 
1231 	switch (LedAction)
1232 	{
1233 		case LED_CTL_SITE_SURVEY:
1234 			if (pmlmepriv->LinkDetectInfo.bBusyTraffic)
1235 				;
1236 			else if (pLed->bLedScanBlinkInProgress == false) {
1237 				if (IS_LED_WPS_BLINKING(pLed))
1238 					return;
1239 
1240 				if (pLed->bLedBlinkInProgress == true) {
1241 					del_timer_sync(&pLed->BlinkTimer);
1242 					pLed->bLedBlinkInProgress = false;
1243 				}
1244 				pLed->bLedScanBlinkInProgress = true;
1245 				pLed->CurrLedState = LED_BLINK_SCAN;
1246 				pLed->BlinkTimes = 24;
1247 				if (pLed->bLedOn)
1248 					pLed->BlinkingLedState = RTW_LED_OFF;
1249 				else
1250 					pLed->BlinkingLedState = RTW_LED_ON;
1251 				delay = LED_BLINK_SCAN_INTERVAL_ALPHA;
1252 			}
1253 			break;
1254 
1255 		case LED_CTL_TX:
1256 		case LED_CTL_RX:
1257 			if (pLed->bLedBlinkInProgress == false &&
1258 			    check_fwstate(pmlmepriv, _FW_LINKED)) {
1259 				if (pLed->CurrLedState == LED_BLINK_SCAN ||
1260 				    IS_LED_WPS_BLINKING(pLed)) {
1261 					return;
1262 				}
1263 
1264 				pLed->bLedBlinkInProgress = true;
1265 				pLed->CurrLedState = LED_BLINK_TXRX;
1266 				pLed->BlinkTimes = 2;
1267 				if (pLed->bLedOn)
1268 					pLed->BlinkingLedState = RTW_LED_OFF;
1269 				else
1270 					pLed->BlinkingLedState = RTW_LED_ON;
1271 				delay =  LED_BLINK_FASTER_INTERVAL_ALPHA;
1272 			}
1273 			break;
1274 
1275 		case LED_CTL_LINK:
1276 			if (IS_LED_WPS_BLINKING(pLed))
1277 				return;
1278 
1279 			pLed->CurrLedState = RTW_LED_ON;
1280 			pLed->BlinkingLedState = RTW_LED_ON;
1281 			if (pLed->bLedBlinkInProgress) {
1282 				del_timer_sync(&pLed->BlinkTimer);
1283 				pLed->bLedBlinkInProgress = false;
1284 			}
1285 			if (pLed->bLedScanBlinkInProgress) {
1286 				del_timer_sync(&pLed->BlinkTimer);
1287 				pLed->bLedScanBlinkInProgress = false;
1288 			}
1289 
1290 			delay = 0;
1291 			break;
1292 
1293 		case LED_CTL_START_WPS: /* wait until xinpin finish */
1294 		case LED_CTL_START_WPS_BOTTON:
1295 			if (pLed->bLedWPSBlinkInProgress == false) {
1296 				if (pLed->bLedBlinkInProgress == true) {
1297 					del_timer_sync(&pLed->BlinkTimer);
1298 					pLed->bLedBlinkInProgress = false;
1299 				}
1300 				if (pLed->bLedScanBlinkInProgress == true) {
1301 					del_timer_sync(&pLed->BlinkTimer);
1302 					pLed->bLedScanBlinkInProgress = false;
1303 				}
1304 				pLed->bLedWPSBlinkInProgress = true;
1305 				pLed->CurrLedState = LED_BLINK_WPS;
1306 				if (pLed->bLedOn)
1307 					pLed->BlinkingLedState = RTW_LED_OFF;
1308 				else
1309 					pLed->BlinkingLedState = RTW_LED_ON;
1310 				delay = LED_BLINK_SCAN_INTERVAL_ALPHA;
1311 			}
1312 			break;
1313 
1314 		case LED_CTL_STOP_WPS:
1315 			if (pLed->bLedWPSBlinkInProgress) {
1316 				del_timer_sync(&pLed->BlinkTimer);
1317 				pLed->bLedWPSBlinkInProgress = false;
1318 			} else {
1319 				pLed->bLedWPSBlinkInProgress = true;
1320 			}
1321 
1322 			pLed->CurrLedState = LED_BLINK_WPS_STOP;
1323 			if (pLed->bLedOn) {
1324 				pLed->BlinkingLedState = RTW_LED_OFF;
1325 				delay = LED_BLINK_WPS_SUCESS_INTERVAL_ALPHA;
1326 			} else {
1327 				pLed->BlinkingLedState = RTW_LED_ON;
1328 				delay = 0;
1329 			}
1330 
1331 			break;
1332 
1333 		case LED_CTL_STOP_WPS_FAIL:
1334 			if (pLed->bLedWPSBlinkInProgress) {
1335 				del_timer_sync(&pLed->BlinkTimer);
1336 				pLed->bLedWPSBlinkInProgress = false;
1337 			}
1338 
1339 			pLed->CurrLedState = RTW_LED_OFF;
1340 			pLed->BlinkingLedState = RTW_LED_OFF;
1341 			delay = 0;
1342 			break;
1343 
1344 		case LED_CTL_START_TO_LINK:
1345 		case LED_CTL_NO_LINK:
1346 			if (!IS_LED_BLINKING(pLed))
1347 			{
1348 				pLed->CurrLedState = RTW_LED_OFF;
1349 				pLed->BlinkingLedState = RTW_LED_OFF;
1350 				delay = 0;
1351 			}
1352 			break;
1353 
1354 		case LED_CTL_POWER_OFF:
1355 			pLed->CurrLedState = RTW_LED_OFF;
1356 			pLed->BlinkingLedState = RTW_LED_OFF;
1357 			if (pLed->bLedBlinkInProgress) {
1358 				del_timer_sync(&pLed->BlinkTimer);
1359 				pLed->bLedBlinkInProgress = false;
1360 			}
1361 			if (pLed->bLedScanBlinkInProgress) {
1362 				del_timer_sync(&pLed->BlinkTimer);
1363 				pLed->bLedScanBlinkInProgress = false;
1364 			}
1365 			if (pLed->bLedWPSBlinkInProgress) {
1366 				del_timer_sync(&pLed->BlinkTimer);
1367 				pLed->bLedWPSBlinkInProgress = false;
1368 			}
1369 
1370 			delay = 0;
1371 			break;
1372 
1373 		default:
1374 			break;
1375 
1376 	}
1377 
1378 	if (delay != -1)
1379 		mod_timer(&pLed->BlinkTimer, jiffies + msecs_to_jiffies(delay));
1380 
1381 	RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("CurrLedState %d\n", pLed->CurrLedState));
1382 }
1383 
1384  /* Edimax-Belkin, added by chiyoko, 20090413 */
1385 static void
SwLedControlMode4(struct rtw_adapter * padapter,enum led_ctl_mode LedAction)1386 SwLedControlMode4(struct rtw_adapter *padapter, enum led_ctl_mode LedAction)
1387 {
1388 	struct led_priv *ledpriv = &padapter->ledpriv;
1389 	struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1390 	struct led_8723a *pLed = &ledpriv->SwLed0;
1391 	struct led_8723a *pLed1 = &ledpriv->SwLed1;
1392 
1393 	switch (LedAction)
1394 	{
1395 		case LED_CTL_START_TO_LINK:
1396 			if (pLed1->bLedWPSBlinkInProgress) {
1397 				pLed1->bLedWPSBlinkInProgress = false;
1398 				del_timer_sync(&pLed1->BlinkTimer);
1399 
1400 				pLed1->BlinkingLedState = RTW_LED_OFF;
1401 				pLed1->CurrLedState = RTW_LED_OFF;
1402 
1403 				if (pLed1->bLedOn)
1404 					mod_timer(&pLed->BlinkTimer, jiffies);
1405 			}
1406 
1407 			if (pLed->bLedStartToLinkBlinkInProgress == false) {
1408 				if (pLed->CurrLedState == LED_BLINK_SCAN ||
1409 				    IS_LED_WPS_BLINKING(pLed)) {
1410 					return;
1411 				}
1412 				if (pLed->bLedBlinkInProgress == true) {
1413 					del_timer_sync(&pLed->BlinkTimer);
1414 					pLed->bLedBlinkInProgress = false;
1415 				}
1416 				if (pLed->bLedNoLinkBlinkInProgress == true) {
1417 					del_timer_sync(&pLed->BlinkTimer);
1418 					pLed->bLedNoLinkBlinkInProgress = false;
1419 				}
1420 
1421 				pLed->bLedStartToLinkBlinkInProgress = true;
1422 				pLed->CurrLedState = LED_BLINK_StartToBlink;
1423 				if (pLed->bLedOn) {
1424 					pLed->BlinkingLedState = RTW_LED_OFF;
1425 					mod_timer(&pLed->BlinkTimer,
1426 						  jiffies + msecs_to_jiffies(LED_BLINK_SLOWLY_INTERVAL));
1427 				} else {
1428 					pLed->BlinkingLedState = RTW_LED_ON;
1429 					mod_timer(&pLed->BlinkTimer,
1430 						  jiffies + msecs_to_jiffies(LED_BLINK_NORMAL_INTERVAL));
1431 				}
1432 			}
1433 			break;
1434 
1435 		case LED_CTL_LINK:
1436 		case LED_CTL_NO_LINK:
1437 			/* LED1 settings */
1438 			if (LedAction == LED_CTL_LINK) {
1439 				if (pLed1->bLedWPSBlinkInProgress) {
1440 					pLed1->bLedWPSBlinkInProgress = false;
1441 					del_timer_sync(&pLed1->BlinkTimer);
1442 
1443 					pLed1->BlinkingLedState = RTW_LED_OFF;
1444 					pLed1->CurrLedState = RTW_LED_OFF;
1445 
1446 					if (pLed1->bLedOn)
1447 						mod_timer(&pLed->BlinkTimer, jiffies);
1448 				}
1449 			}
1450 
1451 			if (pLed->bLedNoLinkBlinkInProgress == false) {
1452 				if (pLed->CurrLedState == LED_BLINK_SCAN ||
1453 				    IS_LED_WPS_BLINKING(pLed)) {
1454 					return;
1455 				}
1456 				if (pLed->bLedBlinkInProgress == true) {
1457 					del_timer_sync(&pLed->BlinkTimer);
1458 					pLed->bLedBlinkInProgress = false;
1459 				}
1460 
1461 				pLed->bLedNoLinkBlinkInProgress = true;
1462 				pLed->CurrLedState = LED_BLINK_SLOWLY;
1463 				if (pLed->bLedOn)
1464 					pLed->BlinkingLedState = RTW_LED_OFF;
1465 				else
1466 					pLed->BlinkingLedState = RTW_LED_ON;
1467 				mod_timer(&pLed->BlinkTimer, jiffies +
1468 					  msecs_to_jiffies(LED_BLINK_NO_LINK_INTERVAL_ALPHA));
1469 			}
1470 			break;
1471 
1472 		case LED_CTL_SITE_SURVEY:
1473 			if (pmlmepriv->LinkDetectInfo.bBusyTraffic &&
1474 			    check_fwstate(pmlmepriv, _FW_LINKED))
1475 				;
1476 			else if (pLed->bLedScanBlinkInProgress == false) {
1477 				if (IS_LED_WPS_BLINKING(pLed))
1478 					return;
1479 
1480 				if (pLed->bLedNoLinkBlinkInProgress == true) {
1481 					del_timer_sync(&pLed->BlinkTimer);
1482 					pLed->bLedNoLinkBlinkInProgress = false;
1483 				}
1484 				if (pLed->bLedBlinkInProgress == true) {
1485 					del_timer_sync(&pLed->BlinkTimer);
1486 					pLed->bLedBlinkInProgress = false;
1487 				}
1488 				pLed->bLedScanBlinkInProgress = true;
1489 				pLed->CurrLedState = LED_BLINK_SCAN;
1490 				pLed->BlinkTimes = 24;
1491 				if (pLed->bLedOn)
1492 					pLed->BlinkingLedState = RTW_LED_OFF;
1493 				else
1494 					pLed->BlinkingLedState = RTW_LED_ON;
1495 				mod_timer(&pLed->BlinkTimer, jiffies +
1496 					  msecs_to_jiffies(LED_BLINK_SCAN_INTERVAL_ALPHA));
1497 			}
1498 			break;
1499 
1500 		case LED_CTL_TX:
1501 		case LED_CTL_RX:
1502 			if (pLed->bLedBlinkInProgress == false) {
1503 				if (pLed->CurrLedState == LED_BLINK_SCAN ||
1504 				    IS_LED_WPS_BLINKING(pLed)) {
1505 					return;
1506 				}
1507 				if (pLed->bLedNoLinkBlinkInProgress == true) {
1508 					del_timer_sync(&pLed->BlinkTimer);
1509 					pLed->bLedNoLinkBlinkInProgress = false;
1510 				}
1511 				pLed->bLedBlinkInProgress = true;
1512 				pLed->CurrLedState = LED_BLINK_TXRX;
1513 				pLed->BlinkTimes = 2;
1514 				if (pLed->bLedOn)
1515 					pLed->BlinkingLedState = RTW_LED_OFF;
1516 				else
1517 					pLed->BlinkingLedState = RTW_LED_ON;
1518 				mod_timer(&pLed->BlinkTimer, jiffies +
1519 					  msecs_to_jiffies(LED_BLINK_FASTER_INTERVAL_ALPHA));
1520 			}
1521 			break;
1522 
1523 		case LED_CTL_START_WPS: /* wait until xinpin finish */
1524 		case LED_CTL_START_WPS_BOTTON:
1525 			if (pLed1->bLedWPSBlinkInProgress) {
1526 				pLed1->bLedWPSBlinkInProgress = false;
1527 				del_timer_sync(&pLed1->BlinkTimer);
1528 
1529 				pLed1->BlinkingLedState = RTW_LED_OFF;
1530 				pLed1->CurrLedState = RTW_LED_OFF;
1531 
1532 				if (pLed1->bLedOn)
1533 					mod_timer(&pLed->BlinkTimer, jiffies);
1534 			}
1535 
1536 			if (pLed->bLedWPSBlinkInProgress == false) {
1537 				if (pLed->bLedNoLinkBlinkInProgress == true) {
1538 					del_timer_sync(&pLed->BlinkTimer);
1539 					pLed->bLedNoLinkBlinkInProgress = false;
1540 				}
1541 				if (pLed->bLedBlinkInProgress == true) {
1542 					del_timer_sync(&pLed->BlinkTimer);
1543 					pLed->bLedBlinkInProgress = false;
1544 				}
1545 				if (pLed->bLedScanBlinkInProgress == true) {
1546 					del_timer_sync(&pLed->BlinkTimer);
1547 					pLed->bLedScanBlinkInProgress = false;
1548 				}
1549 				pLed->bLedWPSBlinkInProgress = true;
1550 				pLed->CurrLedState = LED_BLINK_WPS;
1551 				if (pLed->bLedOn)
1552 				{
1553 					pLed->BlinkingLedState = RTW_LED_OFF;
1554 					mod_timer(&pLed->BlinkTimer, jiffies +
1555 						  msecs_to_jiffies(LED_BLINK_SLOWLY_INTERVAL));
1556 				} else {
1557 					pLed->BlinkingLedState = RTW_LED_ON;
1558 					mod_timer(&pLed->BlinkTimer, jiffies +
1559 						  msecs_to_jiffies(LED_BLINK_NORMAL_INTERVAL));
1560 				}
1561 			}
1562 			break;
1563 
1564 		case LED_CTL_STOP_WPS:	/* WPS connect success */
1565 			if (pLed->bLedWPSBlinkInProgress) {
1566 				del_timer_sync(&pLed->BlinkTimer);
1567 				pLed->bLedWPSBlinkInProgress = false;
1568 			}
1569 
1570 			pLed->bLedNoLinkBlinkInProgress = true;
1571 			pLed->CurrLedState = LED_BLINK_SLOWLY;
1572 			if (pLed->bLedOn)
1573 				pLed->BlinkingLedState = RTW_LED_OFF;
1574 			else
1575 				pLed->BlinkingLedState = RTW_LED_ON;
1576 			mod_timer(&pLed->BlinkTimer, jiffies +
1577 				  msecs_to_jiffies(LED_BLINK_NO_LINK_INTERVAL_ALPHA));
1578 			break;
1579 
1580 		case LED_CTL_STOP_WPS_FAIL:		/* WPS authentication fail */
1581 			if (pLed->bLedWPSBlinkInProgress) {
1582 				del_timer_sync(&pLed->BlinkTimer);
1583 				pLed->bLedWPSBlinkInProgress = false;
1584 			}
1585 
1586 			pLed->bLedNoLinkBlinkInProgress = true;
1587 			pLed->CurrLedState = LED_BLINK_SLOWLY;
1588 			if (pLed->bLedOn)
1589 				pLed->BlinkingLedState = RTW_LED_OFF;
1590 			else
1591 				pLed->BlinkingLedState = RTW_LED_ON;
1592 			mod_timer(&pLed->BlinkTimer, jiffies +
1593 				  msecs_to_jiffies(LED_BLINK_NO_LINK_INTERVAL_ALPHA));
1594 
1595 			/* LED1 settings */
1596 			if (pLed1->bLedWPSBlinkInProgress)
1597 				del_timer_sync(&pLed1->BlinkTimer);
1598 			else
1599 				pLed1->bLedWPSBlinkInProgress = true;
1600 
1601 			pLed1->CurrLedState = LED_BLINK_WPS_STOP;
1602 			if (pLed1->bLedOn)
1603 				pLed1->BlinkingLedState = RTW_LED_OFF;
1604 			else
1605 				pLed1->BlinkingLedState = RTW_LED_ON;
1606 			mod_timer(&pLed->BlinkTimer, jiffies +
1607 				  msecs_to_jiffies(LED_BLINK_NORMAL_INTERVAL));
1608 
1609 			break;
1610 
1611 		case LED_CTL_STOP_WPS_FAIL_OVERLAP:	/* WPS session overlap */
1612 			if (pLed->bLedWPSBlinkInProgress) {
1613 				del_timer_sync(&pLed->BlinkTimer);
1614 				pLed->bLedWPSBlinkInProgress = false;
1615 			}
1616 
1617 			pLed->bLedNoLinkBlinkInProgress = true;
1618 			pLed->CurrLedState = LED_BLINK_SLOWLY;
1619 			if (pLed->bLedOn)
1620 				pLed->BlinkingLedState = RTW_LED_OFF;
1621 			else
1622 				pLed->BlinkingLedState = RTW_LED_ON;
1623 			mod_timer(&pLed->BlinkTimer, jiffies +
1624 				  msecs_to_jiffies(LED_BLINK_NO_LINK_INTERVAL_ALPHA));
1625 
1626 			/* LED1 settings */
1627 			if (pLed1->bLedWPSBlinkInProgress)
1628 				del_timer_sync(&pLed1->BlinkTimer);
1629 			else
1630 				pLed1->bLedWPSBlinkInProgress = true;
1631 
1632 			pLed1->CurrLedState = LED_BLINK_WPS_STOP_OVERLAP;
1633 			pLed1->BlinkTimes = 10;
1634 			if (pLed1->bLedOn)
1635 				pLed1->BlinkingLedState = RTW_LED_OFF;
1636 			else
1637 				pLed1->BlinkingLedState = RTW_LED_ON;
1638 			mod_timer(&pLed->BlinkTimer, jiffies +
1639 				  msecs_to_jiffies(LED_BLINK_NORMAL_INTERVAL));
1640 
1641 			break;
1642 
1643 		case LED_CTL_POWER_OFF:
1644 			pLed->CurrLedState = RTW_LED_OFF;
1645 			pLed->BlinkingLedState = RTW_LED_OFF;
1646 
1647 			if (pLed->bLedNoLinkBlinkInProgress) {
1648 				del_timer_sync(&pLed->BlinkTimer);
1649 				pLed->bLedNoLinkBlinkInProgress = false;
1650 			}
1651 			if (pLed->bLedLinkBlinkInProgress) {
1652 				del_timer_sync(&pLed->BlinkTimer);
1653 				pLed->bLedLinkBlinkInProgress = false;
1654 			}
1655 			if (pLed->bLedBlinkInProgress) {
1656 				del_timer_sync(&pLed->BlinkTimer);
1657 				pLed->bLedBlinkInProgress = false;
1658 			}
1659 			if (pLed->bLedWPSBlinkInProgress) {
1660 				del_timer_sync(&pLed->BlinkTimer);
1661 				pLed->bLedWPSBlinkInProgress = false;
1662 			}
1663 			if (pLed->bLedScanBlinkInProgress) {
1664 				del_timer_sync(&pLed->BlinkTimer);
1665 				pLed->bLedScanBlinkInProgress = false;
1666 			}
1667 			if (pLed->bLedStartToLinkBlinkInProgress) {
1668 				del_timer_sync(&pLed->BlinkTimer);
1669 				pLed->bLedStartToLinkBlinkInProgress = false;
1670 			}
1671 
1672 			if (pLed1->bLedWPSBlinkInProgress) {
1673 				del_timer_sync(&pLed1->BlinkTimer);
1674 				pLed1->bLedWPSBlinkInProgress = false;
1675 			}
1676 
1677 			pLed1->BlinkingLedState = LED_UNKNOWN;
1678 			SwLedOff23a(padapter, pLed);
1679 			SwLedOff23a(padapter, pLed1);
1680 			break;
1681 
1682 		default:
1683 			break;
1684 
1685 	}
1686 
1687 	RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("Led %d\n", pLed->CurrLedState));
1688 }
1689 
1690  /* Sercomm-Belkin, added by chiyoko, 20090415 */
1691 static void
SwLedControlMode5(struct rtw_adapter * padapter,enum led_ctl_mode LedAction)1692 SwLedControlMode5(struct rtw_adapter *padapter, enum led_ctl_mode LedAction)
1693 {
1694 	struct led_priv *ledpriv = &padapter->ledpriv;
1695 	struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1696 	struct led_8723a *pLed = &ledpriv->SwLed0;
1697 
1698 	switch (LedAction)
1699 	{
1700 		case LED_CTL_POWER_ON:
1701 		case LED_CTL_NO_LINK:
1702 		case LED_CTL_LINK:	/* solid blue */
1703 			pLed->CurrLedState = RTW_LED_ON;
1704 			pLed->BlinkingLedState = RTW_LED_ON;
1705 
1706 			mod_timer(&pLed->BlinkTimer, jiffies);
1707 			break;
1708 
1709 		case LED_CTL_SITE_SURVEY:
1710 			if (pmlmepriv->LinkDetectInfo.bBusyTraffic &&
1711 			    check_fwstate(pmlmepriv, _FW_LINKED))
1712 				;
1713 			else if (pLed->bLedScanBlinkInProgress == false)
1714 			{
1715 				if (pLed->bLedBlinkInProgress == true)
1716 				{
1717 					del_timer_sync(&pLed->BlinkTimer);
1718 					pLed->bLedBlinkInProgress = false;
1719 				}
1720 				pLed->bLedScanBlinkInProgress = true;
1721 				pLed->CurrLedState = LED_BLINK_SCAN;
1722 				pLed->BlinkTimes = 24;
1723 				if (pLed->bLedOn)
1724 					pLed->BlinkingLedState = RTW_LED_OFF;
1725 				else
1726 					pLed->BlinkingLedState = RTW_LED_ON;
1727 				mod_timer(&pLed->BlinkTimer, jiffies +
1728 					  msecs_to_jiffies(LED_BLINK_SCAN_INTERVAL_ALPHA));
1729 			}
1730 			break;
1731 
1732 		case LED_CTL_TX:
1733 		case LED_CTL_RX:
1734 			if (pLed->bLedBlinkInProgress == false) {
1735 				if (pLed->CurrLedState == LED_BLINK_SCAN) {
1736 					return;
1737 				}
1738 				pLed->bLedBlinkInProgress = true;
1739 				pLed->CurrLedState = LED_BLINK_TXRX;
1740 				pLed->BlinkTimes = 2;
1741 				if (pLed->bLedOn)
1742 					pLed->BlinkingLedState = RTW_LED_OFF;
1743 				else
1744 					pLed->BlinkingLedState = RTW_LED_ON;
1745 				mod_timer(&pLed->BlinkTimer, jiffies +
1746 					  msecs_to_jiffies(LED_BLINK_FASTER_INTERVAL_ALPHA));
1747 			}
1748 			break;
1749 
1750 		case LED_CTL_POWER_OFF:
1751 			pLed->CurrLedState = RTW_LED_OFF;
1752 			pLed->BlinkingLedState = RTW_LED_OFF;
1753 
1754 			if (pLed->bLedBlinkInProgress) {
1755 				del_timer_sync(&pLed->BlinkTimer);
1756 				pLed->bLedBlinkInProgress = false;
1757 			}
1758 
1759 			SwLedOff23a(padapter, pLed);
1760 			break;
1761 
1762 		default:
1763 			break;
1764 
1765 	}
1766 
1767 	RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("Led %d\n", pLed->CurrLedState));
1768 }
1769 
1770  /* WNC-Corega, added by chiyoko, 20090902 */
SwLedControlMode6(struct rtw_adapter * padapter,enum led_ctl_mode LedAction)1771 static void SwLedControlMode6(struct rtw_adapter *padapter,
1772 			      enum led_ctl_mode LedAction)
1773 {
1774 	struct led_priv *ledpriv = &padapter->ledpriv;
1775 	struct led_8723a *pLed0 = &ledpriv->SwLed0;
1776 
1777 	switch (LedAction) {
1778 	case LED_CTL_POWER_ON:
1779 	case LED_CTL_LINK:
1780 	case LED_CTL_NO_LINK:
1781 		del_timer_sync(&pLed0->BlinkTimer);
1782 		pLed0->CurrLedState = RTW_LED_ON;
1783 		pLed0->BlinkingLedState = RTW_LED_ON;
1784 		mod_timer(&pLed0->BlinkTimer, jiffies);
1785 		break;
1786 	case LED_CTL_POWER_OFF:
1787 		SwLedOff23a(padapter, pLed0);
1788 		break;
1789 	default:
1790 		break;
1791 	}
1792 
1793 	RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("ledcontrol 6 Led %d\n", pLed0->CurrLedState));
1794 }
1795 
1796 /*  */
1797 /*	Description: */
1798 /*		Handler function of LED Blinking. */
1799 /*		We dispatch acture LED blink action according to LedStrategy. */
1800 /*  */
BlinkHandler23a(struct led_8723a * pLed)1801 void BlinkHandler23a(struct led_8723a *pLed)
1802 {
1803 	struct rtw_adapter *padapter = pLed->padapter;
1804 	struct led_priv *ledpriv = &padapter->ledpriv;
1805 
1806 	/* DBG_8723A("%s (%s:%d)\n", __func__, current->comm, current->pid); */
1807 
1808 	if ((padapter->bSurpriseRemoved) || (padapter->bDriverStopped))
1809 		return;
1810 
1811 	switch (ledpriv->LedStrategy) {
1812 	case SW_LED_MODE0:
1813 		SwLedBlink(pLed);
1814 		break;
1815 	case SW_LED_MODE1:
1816 		SwLedBlink1(pLed);
1817 		break;
1818 	case SW_LED_MODE2:
1819 		SwLedBlink2(pLed);
1820 		break;
1821 	case SW_LED_MODE3:
1822 		SwLedBlink3(pLed);
1823 		break;
1824 	case SW_LED_MODE4:
1825 		SwLedBlink4(pLed);
1826 		break;
1827 	case SW_LED_MODE5:
1828 		SwLedBlink5(pLed);
1829 		break;
1830 	case SW_LED_MODE6:
1831 		SwLedBlink6(pLed);
1832 		break;
1833 	default:
1834 		break;
1835 	}
1836 }
1837 
1838 void
LedControl871x23a(struct rtw_adapter * padapter,enum led_ctl_mode LedAction)1839 LedControl871x23a(struct rtw_adapter *padapter, enum led_ctl_mode LedAction) {
1840 	struct led_priv *ledpriv = &padapter->ledpriv;
1841 
1842 	if ((padapter->bSurpriseRemoved == true) ||
1843 	    (padapter->bDriverStopped == true) ||
1844 	    (padapter->hw_init_completed == false)) {
1845 		return;
1846 	}
1847 
1848 	if (ledpriv->bRegUseLed == false)
1849 		return;
1850 
1851 	/* if (!priv->up) */
1852 	/*	return; */
1853 
1854 	/* if (priv->bInHctTest) */
1855 	/*	return; */
1856 
1857 	if ((padapter->pwrctrlpriv.rf_pwrstate != rf_on &&
1858 	     padapter->pwrctrlpriv.rfoff_reason > RF_CHANGE_BY_PS) &&
1859 	    (LedAction == LED_CTL_TX || LedAction == LED_CTL_RX ||
1860 	     LedAction == LED_CTL_SITE_SURVEY ||
1861 	     LedAction == LED_CTL_LINK ||
1862 	     LedAction == LED_CTL_NO_LINK ||
1863 	     LedAction == LED_CTL_POWER_ON)) {
1864 		return;
1865 	}
1866 
1867 	switch (ledpriv->LedStrategy) {
1868 	case SW_LED_MODE0:
1869 		break;
1870 	case SW_LED_MODE1:
1871 		SwLedControlMode1(padapter, LedAction);
1872 		break;
1873 	case SW_LED_MODE2:
1874 		SwLedControlMode2(padapter, LedAction);
1875 		break;
1876 	case SW_LED_MODE3:
1877 		SwLedControlMode3(padapter, LedAction);
1878 		break;
1879 	case SW_LED_MODE4:
1880 		SwLedControlMode4(padapter, LedAction);
1881 		break;
1882 	case SW_LED_MODE5:
1883 		SwLedControlMode5(padapter, LedAction);
1884 		break;
1885 	case SW_LED_MODE6:
1886 		SwLedControlMode6(padapter, LedAction);
1887 		break;
1888 	default:
1889 		break;
1890 	}
1891 
1892 	RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("LedStrategy:%d, LedAction %d\n", ledpriv->LedStrategy, LedAction));
1893 }
1894