Merge branch 'for-linus' of git://www.jni.nu/cris
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / staging / otus / 80211core / ledmgr.c
CommitLineData
4bd43f50
LR
1/*
2 * Copyright (c) 2007-2008 Atheros Communications Inc.
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#include "cprecomp.h"
18
19/************************************************************************/
20/* */
21/* FUNCTION DESCRIPTION zfLedCtrlType1 */
22/* Traditional single-LED state */
23/* */
24/* INPUTS */
25/* dev : device pointer */
26/* */
27/* OUTPUTS */
28/* None */
29/* */
30/* AUTHOR */
31/* Stephen Chen Atheros Communications, INC. 2007.6 */
32/* */
33/************************************************************************/
34// bit 15-12 : Toff for Scan state
35// 11-8 : Ton for Scan state
36// 7 : Reserved
37// 6 : mode
38//--------------------------------------
39// bit 6 = 0
40// 5-4 : Connect state
41// 00 => always off
42// 01 => always on
43// 10 => Idle off, acitve on
44// 11 => Idle on, active off
45//--------------------------------------
46// bit 6 = 1
47// 5-4 : freq
48// 00 => 1Hz
49// 01 => 0.5Hz
50// 10 => 0.25Hz
51// 11 => 0.125Hz
52//--------------------------------------
53// 3 : Power save state
54// 0 => always off in power save state
55// 1 => works as connect state
56// 2 : Disable state
57// 1 : Reserved
58// 0 : Power-on state
59void zfLedCtrlType1(zdev_t* dev)
60{
61 u16_t i;
62 u32_t ton, toff, tmp, period;
63 zmw_get_wlan_dev(dev);
64
65 for (i=0; i<ZM_MAX_LED_NUMBER; i++)
66 {
67 if (zfStaIsConnected(dev) != TRUE)
68 {
69 //Scan state
70 ton = ((wd->ledStruct.ledMode[i] & 0xf00) >> 8) * 5;
71 toff = ((wd->ledStruct.ledMode[i] & 0xf000) >> 12) * 5;
72
73 if ((ton + toff) != 0)
74 {
75 tmp = wd->ledStruct.counter / (ton+toff);
76 tmp = wd->ledStruct.counter - (tmp * (ton+toff));
77 if (tmp < ton)
78 {
79 zfHpLedCtrl(dev, i, 1);
80 }
81 else
82 {
83 zfHpLedCtrl(dev, i, 0);
84 }
85 }
86 }
87 else
88 {
89 if ((zfPowerSavingMgrIsSleeping(dev)) && ((wd->ledStruct.ledMode[i] & 0x8) == 0))
90 {
91 zfHpLedCtrl(dev, i, 0);
92 }
93 else
94 {
95 //Connect state
96 if ((wd->ledStruct.ledMode[i] & 0x40) == 0)
97 {
98 if ((wd->ledStruct.counter & 1) == 0)
99 {
100 zfHpLedCtrl(dev, i, (wd->ledStruct.ledMode[i] & 0x10) >> 4);
101 }
102 else
103 {
104 if ((wd->ledStruct.txTraffic > 0) || (wd->ledStruct.rxTraffic > 0))
105 {
106 wd->ledStruct.txTraffic = wd->ledStruct.rxTraffic = 0;
107 if ((wd->ledStruct.ledMode[i] & 0x20) != 0)
108 {
109 zfHpLedCtrl(dev, i, ((wd->ledStruct.ledMode[i] & 0x10) >> 4)^1);
110 }
111 }
112 }
113 }// if ((wd->ledStruct.ledMode[i] & 0x40) == 0)
114 else
115 {
116 period = 5 * (1 << ((wd->ledStruct.ledMode[i] & 0x30) >> 4));
117 tmp = wd->ledStruct.counter / (period*2);
118 tmp = wd->ledStruct.counter - (tmp * (period*2));
119 if (tmp < period)
120 {
121 if ((wd->ledStruct.counter & 1) == 0)
122 {
123 zfHpLedCtrl(dev, i, 0);
124 }
125 else
126 {
127 if ((wd->ledStruct.txTraffic > 0) || (wd->ledStruct.rxTraffic > 0))
128 {
129 wd->ledStruct.txTraffic = wd->ledStruct.rxTraffic = 0;
130 zfHpLedCtrl(dev, i, 1);
131 }
132 }
133 }
134 else
135 {
136 if ((wd->ledStruct.counter & 1) == 0)
137 {
138 zfHpLedCtrl(dev, i, 1);
139 }
140 else
141 {
142 if ((wd->ledStruct.txTraffic > 0) || (wd->ledStruct.rxTraffic > 0))
143 {
144 wd->ledStruct.txTraffic = wd->ledStruct.rxTraffic = 0;
145 zfHpLedCtrl(dev, i, 0);
146 }
147 }
148 }
149 } //else, if ((wd->ledStruct.ledMode[i] & 0x40) == 0)
150 } //else, if (zfPowerSavingMgrIsSleeping(dev))
151 } //else : if (zfStaIsConnected(dev) != TRUE)
152 } //for (i=0; i<ZM_MAX_LED_NUMBER; i++)
153}
154
155/******************************************************************************/
156/* */
157/* FUNCTION DESCRIPTION zfLedCtrlType2 */
158/* Customize for Netgear Dual-LED state ((bug#31292)) */
159/* */
160/* 1. Status: When dongle does not connect to 2.4G or 5G but in site */
161/* survey/association */
162/* LED status: Slow blinking, Amber then Blue per 500ms */
163/* 2. Status: Connection at 2.4G in site survey/association */
164/* LED status: Slow blinking, Amber/off per 500ms */
165/* 3. Status: Connection at 5G in site survey/association */
166/* LED status: Slow blinking, Blue/off per 500ms */
167/* 4. Status: When transfer the packet */
168/* LED status: Blink per packet, including TX and RX */
169/* 5. Status: When linking is established but no traffic */
170/* LED status: Always on */
171/* 6. Status: When linking is dropped but no re-connection */
172/* LED status: Always off */
173/* 7. Status: From one connection(2.4G or 5G) to change to another band */
174/* LED status: Amber/Blue =>Slow blinking, Amber then Blue per 500ms */
175/* */
176/* INPUTS */
177/* dev : device pointer */
178/* */
179/* OUTPUTS */
180/* None */
181/* */
182/* AUTHOR */
183/* Shang-Chun Liu Atheros Communications, INC. 2007.11 */
184/* */
185/******************************************************************************/
186void zfLedCtrlType2_scan(zdev_t* dev);
187
188void zfLedCtrlType2(zdev_t* dev)
189{
4bd43f50
LR
190 u16_t OperateLED;
191 zmw_get_wlan_dev(dev);
192
193 if (zfStaIsConnected(dev) != TRUE)
194 {
195 // Disconnect state
196 if(wd->ledStruct.counter % 4 != 0)
197 {
198 // Update LED each 400ms(4*100)
199 // Prevent this situation
200 // _______ ___
201 // LED[0] ON | | | x |
202 // ------ OFF->+-+-+-+-+-+-+-+-+-+-+-+->>>...
203 // LED[1] ON
204 //
205 return;
206 }
207
208 if (((wd->state == ZM_WLAN_STATE_DISABLED) && (wd->sta.bChannelScan))
209 || ((wd->state != ZM_WLAN_STATE_DISABLED) && (wd->sta.bAutoReconnect)))
210 {
211 // Scan/AutoReconnect state
212 zfLedCtrlType2_scan(dev);
213 }
214 else
215 {
216 // Neither Connected nor Scan
217 zfHpLedCtrl(dev, 0, 0);
218 zfHpLedCtrl(dev, 1, 0);
219 }
220 }
221 else
222 {
223 if( wd->sta.bChannelScan )
224 {
225 // Scan state
226 if(wd->ledStruct.counter % 4 != 0)
227 return;
228 zfLedCtrlType2_scan(dev);
229 return;
230 }
231
232 if(wd->frequency < 3000)
233 {
234 OperateLED = 0; // LED[0]: work on 2.4G (b/g band)
235 zfHpLedCtrl(dev, 1, 0);
236 }
237 else
238 {
239 OperateLED = 1; // LED[1]: work on 5G (a band)
240 zfHpLedCtrl(dev, 0, 0);
241 }
242
243 if ((zfPowerSavingMgrIsSleeping(dev)) && ((wd->ledStruct.ledMode[OperateLED] & 0x8) == 0))
244 {
245 // If Sleeping, turn OFF
246 zfHpLedCtrl(dev, OperateLED, 0);
247 }
248 else
249 {
250 //Connect state
251 if ((wd->ledStruct.counter & 1) == 0) // even
252 {
253 // No traffic, always ON
254 zfHpLedCtrl(dev, OperateLED, 1);
255 }
256 else // odd
257 {
258 if ((wd->ledStruct.txTraffic > 0) || (wd->ledStruct.rxTraffic > 0))
259 {
260 // If have traffic, turn OFF
261 // _____ _ _ _ _____
262 // LED[Operate] ON | | | | | | | |
263 // ------------ OFF->-+-+-+-+-+-+-+-+-+-+-+-+-+->>>...
264 //
265 wd->ledStruct.txTraffic = wd->ledStruct.rxTraffic = 0;
266 zfHpLedCtrl(dev, OperateLED, 0);
267 }
268 }
269 }
270 }
271}
272
273void zfLedCtrlType2_scan(zdev_t* dev)
274{
275 zmw_get_wlan_dev(dev);
276
277 // When doing scan, blink(Amber/Blue) and off per 500ms (about 400ms in our driver)
278 // _______ _______
279 // LED[0] ON | | 8 12 | |
280 // ------ OFF->-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+->>>...
281 // LED[1] ON 0 4 |_______| 0 3
282 //
283
284 switch(wd->ledStruct.counter % 16)
285 {
286 case 0: // case 0~3, LED[0] on
287 if(wd->supportMode & ZM_WIRELESS_MODE_24)
288 {
289 zfHpLedCtrl(dev, 0, 1);
290 zfHpLedCtrl(dev, 1, 0);
291 }
292 else
293 {
294 zfHpLedCtrl(dev, 1, 1);
295 zfHpLedCtrl(dev, 0, 0);
296 }
297 break;
298
299 case 8: // case 8~11, LED[1] on
300 if(wd->supportMode & ZM_WIRELESS_MODE_5)
301 {
302 zfHpLedCtrl(dev, 1, 1);
303 zfHpLedCtrl(dev, 0, 0);
304 }
305 else
306 {
307 zfHpLedCtrl(dev, 0, 1);
308 zfHpLedCtrl(dev, 1, 0);
309 }
310 break;
311
312 default: // others, all off
313 zfHpLedCtrl(dev, 0, 0);
314 zfHpLedCtrl(dev, 1, 0);
315 break;
316 }
317}
318
319/**********************************************************************************/
320/* */
321/* FUNCTION DESCRIPTION zfLedCtrlType3 */
322/* Customize for Netgear Single-LED state ((bug#32243)) */
323/* */
324