]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/staging/winbond/wbhal.c
c8da1a3fcd1a301d1266d47d271a0881e92e1415
[linux-2.6-omap-h63xx.git] / drivers / staging / winbond / wbhal.c
1 #include "os_common.h"
2
3 void hal_get_ethernet_address( phw_data_t pHwData, u8 *current_address )
4 {
5         if( pHwData->SurpriseRemove ) return;
6
7         memcpy( current_address, pHwData->CurrentMacAddress, ETH_LENGTH_OF_ADDRESS );
8 }
9
10 void hal_set_ethernet_address( phw_data_t pHwData, u8 *current_address )
11 {
12         u32 ltmp[2];
13
14         if( pHwData->SurpriseRemove ) return;
15
16         memcpy( pHwData->CurrentMacAddress, current_address, ETH_LENGTH_OF_ADDRESS );
17
18         ltmp[0]= cpu_to_le32( *(u32 *)pHwData->CurrentMacAddress );
19         ltmp[1]= cpu_to_le32( *(u32 *)(pHwData->CurrentMacAddress + 4) ) & 0xffff;
20
21         Wb35Reg_BurstWrite( pHwData, 0x03e8, ltmp, 2, AUTO_INCREMENT );
22 }
23
24 void hal_get_permanent_address( phw_data_t pHwData, u8 *pethernet_address )
25 {
26         if( pHwData->SurpriseRemove ) return;
27
28         memcpy( pethernet_address, pHwData->PermanentMacAddress, 6 );
29 }
30
31 u8 hal_init_hardware(phw_data_t pHwData, struct wb35_adapter * adapter)
32 {
33         u16 SoftwareSet;
34         pHwData->adapter = adapter;
35
36         // Initial the variable
37         pHwData->MaxReceiveLifeTime = DEFAULT_MSDU_LIFE_TIME; // Setting Rx maximum MSDU life time
38         pHwData->FragmentThreshold = DEFAULT_FRAGMENT_THRESHOLD; // Setting default fragment threshold
39
40         pHwData->InitialResource = 1;
41         if( Wb35Reg_initial(pHwData)) {
42                 pHwData->InitialResource = 2;
43                 if (Wb35Tx_initial(pHwData)) {
44                         pHwData->InitialResource = 3;
45                         if (Wb35Rx_initial(pHwData)) {
46                                 pHwData->InitialResource = 4;
47                                 OS_TIMER_INITIAL( &pHwData->LEDTimer, hal_led_control, pHwData );
48                                 OS_TIMER_SET( &pHwData->LEDTimer, 1000 ); // 20060623
49
50                                 //
51                                 // For restrict to vendor's hardware
52                                 //
53                                 SoftwareSet = hal_software_set( pHwData );
54
55                                 #ifdef Vendor2
56                                 // Try to make sure the EEPROM contain
57                                 SoftwareSet >>= 8;
58                                 if( SoftwareSet != 0x82 )
59                                         return FALSE;
60                                 #endif
61
62                                 Wb35Rx_start( pHwData );
63                                 Wb35Tx_EP2VM_start( pHwData );
64
65                                 return TRUE;
66                         }
67                 }
68         }
69
70         pHwData->SurpriseRemove = 1;
71         return FALSE;
72 }
73
74
75 void hal_halt(phw_data_t pHwData, void *ppa_data)
76 {
77         switch( pHwData->InitialResource )
78         {
79                 case 4:
80                 case 3: OS_TIMER_CANCEL( &pHwData->LEDTimer, &cancel );
81                         msleep(100); // Wait for Timer DPC exit 940623.2
82                         Wb35Rx_destroy( pHwData ); // Release the Rx
83                 case 2: Wb35Tx_destroy( pHwData ); // Release the Tx
84                 case 1: Wb35Reg_destroy( pHwData ); // Release the Wb35 Regisster resources
85         }
86 }
87
88 //---------------------------------------------------------------------------------------------------
89 void hal_set_rates(phw_data_t pHwData, u8 *pbss_rates,
90                    u8 length, unsigned char basic_rate_set)
91 {
92         struct wb35_reg *reg = &pHwData->reg;
93         u32             tmp, tmp1;
94         u8              Rate[12]={ 2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108 };
95         u8              SupportedRate[16];
96         u8              i, j, k, Count1, Count2, Byte;
97
98         if( pHwData->SurpriseRemove ) return;
99
100         if (basic_rate_set) {
101                 reg->M28_MacControl &= ~0x000fff00;
102                 tmp1 = 0x00000100;
103         } else {
104                 reg->M28_MacControl &= ~0xfff00000;
105                 tmp1 = 0x00100000;
106         }
107
108         tmp = 0;
109         for (i=0; i<length; i++) {
110                 Byte = pbss_rates[i] & 0x7f;
111                 for (j=0; j<12; j++) {
112                         if( Byte == Rate[j] )
113                                 break;
114                 }
115
116                 if (j < 12)
117                         tmp |= (tmp1<<j);
118         }
119
120         reg->M28_MacControl |= tmp;
121         Wb35Reg_Write( pHwData, 0x0828, reg->M28_MacControl );
122
123         // 930206.2.c M78 setting
124         j = k = Count1 = Count2 = 0;
125         memset( SupportedRate, 0, 16 );
126         tmp = 0x00100000;
127         tmp1 = 0x00000100;
128         for (i=0; i<12; i++) { // Get the supported rate
129                 if (tmp & reg->M28_MacControl) {
130                         SupportedRate[j] = Rate[i];
131
132                         if (tmp1 & reg->M28_MacControl)
133                                 SupportedRate[j] |= 0x80;
134
135                         if (k)
136                                 Count2++;
137                         else
138                                 Count1++;
139
140                         j++;
141                 }
142
143                 if (i==4 && k==0) {
144                         if( !(reg->M28_MacControl & 0x000ff000) ) // if basic rate in 11g domain)
145                         {
146                                 k = 1;
147                                 j = 8;
148                         }
149                 }
150
151                 tmp <<= 1;
152                 tmp1 <<= 1;
153         }
154
155         // Fill data into support rate until buffer full
156         //---20060926 add by anson's endian
157         for (i=0; i<4; i++)
158                 *(u32 *)(SupportedRate+(i<<2)) = cpu_to_le32( *(u32 *)(SupportedRate+(i<<2)) );
159         //--- end 20060926 add by anson's endian
160         Wb35Reg_BurstWrite( pHwData,0x087c, (u32 *)SupportedRate, 4, AUTO_INCREMENT );
161         reg->M7C_MacControl = ((u32 *)SupportedRate)[0];
162         reg->M80_MacControl = ((u32 *)SupportedRate)[1];
163         reg->M84_MacControl = ((u32 *)SupportedRate)[2];
164         reg->M88_MacControl = ((u32 *)SupportedRate)[3];
165
166         // Fill length
167         tmp = Count1<<28 | Count2<<24;
168         reg->M78_ERPInformation &= ~0xff000000;
169         reg->M78_ERPInformation |= tmp;
170         Wb35Reg_Write( pHwData, 0x0878, reg->M78_ERPInformation );
171 }
172
173
174 //---------------------------------------------------------------------------------------------------
175 void hal_set_beacon_period(  phw_data_t pHwData,  u16 beacon_period )
176 {
177         u32     tmp;
178
179         if( pHwData->SurpriseRemove ) return;
180
181         pHwData->BeaconPeriod = beacon_period;
182         tmp = pHwData->BeaconPeriod << 16;
183         tmp |= pHwData->ProbeDelay;
184         Wb35Reg_Write( pHwData, 0x0848, tmp );
185 }
186
187
188 void hal_set_current_channel_ex(  phw_data_t pHwData,  ChanInfo channel )
189 {
190         struct wb35_reg *reg = &pHwData->reg;
191
192         if( pHwData->SurpriseRemove )
193                 return;
194
195         printk("Going to channel: %d/%d\n", channel.band, channel.ChanNo);
196
197         RFSynthesizer_SwitchingChannel( pHwData, channel );// Switch channel
198         pHwData->Channel = channel.ChanNo;
199         pHwData->band = channel.band;
200         #ifdef _PE_STATE_DUMP_
201         WBDEBUG(("Set channel is %d, band =%d\n", pHwData->Channel, pHwData->band));
202         #endif
203         reg->M28_MacControl &= ~0xff; // Clean channel information field
204         reg->M28_MacControl |= channel.ChanNo;
205         Wb35Reg_WriteWithCallbackValue( pHwData, 0x0828, reg->M28_MacControl,
206                                         (s8 *)&channel, sizeof(ChanInfo));
207 }
208 //---------------------------------------------------------------------------------------------------
209 void hal_set_current_channel(  phw_data_t pHwData,  ChanInfo channel )
210 {
211         hal_set_current_channel_ex( pHwData, channel );
212 }
213 //---------------------------------------------------------------------------------------------------
214 void hal_get_current_channel(  phw_data_t pHwData,  ChanInfo *channel )
215 {
216         channel->ChanNo = pHwData->Channel;
217         channel->band = pHwData->band;
218 }
219 //---------------------------------------------------------------------------------------------------
220 void hal_set_accept_broadcast(  phw_data_t pHwData,  u8 enable )
221 {
222         struct wb35_reg *reg = &pHwData->reg;
223
224         if( pHwData->SurpriseRemove ) return;
225
226         reg->M00_MacControl &= ~0x02000000;//The HW value
227
228         if (enable)
229                 reg->M00_MacControl |= 0x02000000;//The HW value
230
231         Wb35Reg_Write( pHwData, 0x0800, reg->M00_MacControl );
232 }
233
234 //for wep key error detection, we need to accept broadcast packets to be received temporary.
235 void hal_set_accept_promiscuous( phw_data_t pHwData,  u8 enable)
236 {
237         struct wb35_reg *reg = &pHwData->reg;
238
239         if (pHwData->SurpriseRemove) return;
240         if (enable) {
241                 reg->M00_MacControl |= 0x00400000;
242                 Wb35Reg_Write( pHwData, 0x0800, reg->M00_MacControl );
243         } else {
244                 reg->M00_MacControl&=~0x00400000;
245                 Wb35Reg_Write( pHwData, 0x0800, reg->M00_MacControl );
246         }
247 }
248
249 void hal_set_accept_multicast(  phw_data_t pHwData,  u8 enable )
250 {
251         struct wb35_reg *reg = &pHwData->reg;
252
253         if( pHwData->SurpriseRemove ) return;
254
255         reg->M00_MacControl &= ~0x01000000;//The HW value
256         if (enable)  reg->M00_MacControl |= 0x01000000;//The HW value
257         Wb35Reg_Write( pHwData, 0x0800, reg->M00_MacControl );
258 }
259
260 void hal_set_accept_beacon(  phw_data_t pHwData,  u8 enable )
261 {
262         struct wb35_reg *reg = &pHwData->reg;
263
264         if( pHwData->SurpriseRemove ) return;
265
266         // 20040108 debug
267         if( !enable )//Due to SME and MLME are not suitable for 35
268                 return;
269
270         reg->M00_MacControl &= ~0x04000000;//The HW value
271         if( enable )
272                 reg->M00_MacControl |= 0x04000000;//The HW value
273
274         Wb35Reg_Write( pHwData, 0x0800, reg->M00_MacControl );
275 }
276 //---------------------------------------------------------------------------------------------------
277 void hal_set_multicast_address( phw_data_t pHwData, u8 *address, u8 number )
278 {
279         struct wb35_reg *reg = &pHwData->reg;
280         u8              Byte, Bit;
281
282         if( pHwData->SurpriseRemove ) return;
283
284         //Erases and refills the card multicast registers. Used when an address
285         //    has been deleted and all bits must be recomputed.
286         reg->M04_MulticastAddress1 = 0;
287         reg->M08_MulticastAddress2 = 0;
288
289         while( number )
290         {
291                 number--;
292                 CardGetMulticastBit( (address+(number*ETH_LENGTH_OF_ADDRESS)), &Byte, &Bit);
293                 reg->Multicast[Byte] |= Bit;
294         }
295
296         // Updating register
297         Wb35Reg_BurstWrite( pHwData, 0x0804, (u32 *)reg->Multicast, 2, AUTO_INCREMENT );
298 }
299 //---------------------------------------------------------------------------------------------------
300 u8 hal_get_accept_beacon(  phw_data_t pHwData )
301 {
302         struct wb35_reg *reg = &pHwData->reg;
303
304         if( pHwData->SurpriseRemove ) return 0;
305
306         if( reg->M00_MacControl & 0x04000000 )
307                 return 1;
308         else
309                 return 0;
310 }
311
312 unsigned char hal_reset_hardware( phw_data_t pHwData, void* ppa )
313 {
314         // Not implement yet
315         return TRUE;
316 }
317
318 void hal_stop(  phw_data_t pHwData )
319 {
320         struct wb35_reg *reg = &pHwData->reg;
321
322         pHwData->Wb35Rx.rx_halt = 1;
323         Wb35Rx_stop( pHwData );
324
325         pHwData->Wb35Tx.tx_halt = 1;
326         Wb35Tx_stop( pHwData );
327
328         reg->D00_DmaControl &= ~0xc0000000;//Tx Off, Rx Off
329         Wb35Reg_Write( pHwData, 0x0400, reg->D00_DmaControl );
330 }
331
332 unsigned char hal_idle(phw_data_t pHwData)
333 {
334         struct wb35_reg *reg = &pHwData->reg;
335         PWBUSB  pWbUsb = &pHwData->WbUsb;
336
337         if( !pHwData->SurpriseRemove && ( pWbUsb->DetectCount || reg->EP0vm_state!=VM_STOP ) )
338                 return FALSE;
339
340         return TRUE;
341 }
342 //---------------------------------------------------------------------------------------------------
343 void hal_set_cwmin(  phw_data_t pHwData,  u8    cwin_min )
344 {
345         struct wb35_reg *reg = &pHwData->reg;
346
347         if( pHwData->SurpriseRemove ) return;
348
349         pHwData->cwmin = cwin_min;
350         reg->M2C_MacControl &= ~0x7c00; //bit 10 ~ 14
351         reg->M2C_MacControl |= (pHwData->cwmin<<10);
352         Wb35Reg_Write( pHwData, 0x082c, reg->M2C_MacControl );
353 }
354
355 s32 hal_get_rssi(  phw_data_t pHwData,  u32 *HalRssiArry,  u8 Count )
356 {
357         struct wb35_reg *reg = &pHwData->reg;
358         R01_DESCRIPTOR  r01;
359         s32 ltmp = 0, tmp;
360         u8      i;
361
362         if( pHwData->SurpriseRemove ) return -200;
363         if( Count > MAX_ACC_RSSI_COUNT ) // Because the TS may use this funtion
364                 Count = MAX_ACC_RSSI_COUNT;
365
366         // RSSI = C1 + C2 * (agc_state[7:0] + offset_map(lna_state[1:0]))
367         // C1 = -195, C2 = 0.66 = 85/128
368         for (i=0; i<Count; i++)
369         {
370                 r01.value = HalRssiArry[i];
371                 tmp = ((( r01.R01_AGC_state + reg->LNAValue[r01.R01_LNA_state]) * 85 ) >>7 ) - 195;
372                 ltmp += tmp;
373         }
374         ltmp /= Count;
375         if( pHwData->phy_type == RF_AIROHA_2230 ) ltmp -= 5; // 10;
376         if( pHwData->phy_type == RF_AIROHA_2230S ) ltmp -= 5; // 10; 20060420 Add this
377
378         //if( ltmp < -200 ) ltmp = -200;
379         if( ltmp < -110 ) ltmp = -110;// 1.0.24.0 For NJRC
380
381         return ltmp;
382 }
383 //----------------------------------------------------------------------------------------------------
384 s32 hal_get_rssi_bss(  phw_data_t pHwData,  u16 idx,  u8 Count )
385 {
386         struct wb35_reg *reg = &pHwData->reg;
387         R01_DESCRIPTOR  r01;
388         s32 ltmp = 0, tmp;
389         u8      i, j;
390         struct wb35_adapter *   adapter = pHwData->adapter;
391 //      u32 *HalRssiArry = psBSS(idx)->HalRssi;
392
393         if( pHwData->SurpriseRemove ) return -200;
394         if( Count > MAX_ACC_RSSI_COUNT ) // Because the TS may use this funtion
395                 Count = MAX_ACC_RSSI_COUNT;
396
397         // RSSI = C1 + C2 * (agc_state[7:0] + offset_map(lna_state[1:0]))
398         // C1 = -195, C2 = 0.66 = 85/128
399 #if 0
400         for (i=0; i<Count; i++)
401         {
402                 r01.value = HalRssiArry[i];
403                 tmp = ((( r01.R01_AGC_state + reg->LNAValue[r01.R01_LNA_state]) * 85 ) >>7 ) - 195;
404                 ltmp += tmp;
405         }
406 #else
407         if (psBSS(idx)->HalRssiIndex == 0)
408                 psBSS(idx)->HalRssiIndex = MAX_ACC_RSSI_COUNT;
409         j = (u8)psBSS(idx)->HalRssiIndex-1;
410
411         for (i=0; i<Count; i++)
412         {
413                 r01.value = psBSS(idx)->HalRssi[j];
414                 tmp = ((( r01.R01_AGC_state + reg->LNAValue[r01.R01_LNA_state]) * 85 ) >>7 ) - 195;
415                 ltmp += tmp;
416                 if (j == 0)
417                 {
418                         j = MAX_ACC_RSSI_COUNT;
419                 }
420                 j--;
421         }
422 #endif
423         ltmp /= Count;
424         if( pHwData->phy_type == RF_AIROHA_2230 ) ltmp -= 5; // 10;
425         if( pHwData->phy_type == RF_AIROHA_2230S ) ltmp -= 5; // 10; 20060420 Add this
426
427         //if( ltmp < -200 ) ltmp = -200;
428         if( ltmp < -110 ) ltmp = -110;// 1.0.24.0 For NJRC
429
430         return ltmp;
431 }
432
433 //---------------------------------------------------------------------------
434 void hal_led_control_1a(  phw_data_t pHwData )
435 {
436         hal_led_control( NULL, pHwData, NULL, NULL );
437 }
438
439 void hal_led_control(  void* S1,  phw_data_t pHwData,  void* S3,  void* S4 )
440 {
441         struct wb35_adapter *   adapter = pHwData->adapter;
442         struct wb35_reg *reg = &pHwData->reg;
443         u32     LEDSet = (pHwData->SoftwareSet & HAL_LED_SET_MASK) >> HAL_LED_SET_SHIFT;
444         u8      LEDgray[20] = { 0,3,4,6,8,10,11,12,13,14,15,14,13,12,11,10,8,6,4,2 };
445         u8      LEDgray2[30] = { 7,8,9,10,11,12,13,14,15,0,0,0,0,0,0,0,0,0,0,0,0,0,15,14,13,12,11,10,9,8 };
446         u32     TimeInterval = 500, ltmp, ltmp2;
447         ltmp=0;
448
449         if( pHwData->SurpriseRemove ) return;
450
451         if( pHwData->LED_control ) {
452                 ltmp2 = pHwData->LED_control & 0xff;
453                 if( ltmp2 == 5 ) // 5 is WPS mode
454                 {
455                         TimeInterval = 100;
456                         ltmp2 = (pHwData->LED_control>>8) & 0xff;
457                         switch( ltmp2 )
458                         {
459                                 case 1: // [0.2 On][0.1 Off]...
460                                         pHwData->LED_Blinking %= 3;
461                                         ltmp = 0x1010; // Led 1 & 0 Green and Red
462                                         if( pHwData->LED_Blinking == 2 ) // Turn off
463                                                 ltmp = 0;
464                                         break;
465                                 case 2: // [0.1 On][0.1 Off]...
466                                         pHwData->LED_Blinking %= 2;
467                                         ltmp = 0x0010; // Led 0 red color
468                                         if( pHwData->LED_Blinking ) // Turn off
469                                                 ltmp = 0;
470                                         break;
471                                 case 3: // [0.1 On][0.1 Off][0.1 On][0.1 Off][0.1 On][0.1 Off][0.1 On][0.1 Off][0.1 On][0.1 Off][0.5 Off]...
472                                         pHwData->LED_Blinking %= 15;
473                                         ltmp = 0x0010; // Led 0 red color
474                                         if( (pHwData->LED_Blinking >= 9) || (pHwData->LED_Blinking%2) ) // Turn off 0.6 sec
475                                                 ltmp = 0;
476                                         break;
477                                 case 4: // [300 On][ off ]
478                                         ltmp = 0x1000; // Led 1 Green color
479                                         if( pHwData->LED_Blinking >= 3000 )
480                                                 ltmp = 0; // led maybe on after 300sec * 32bit counter overlap.
481                                         break;
482                         }
483                         pHwData->LED_Blinking++;
484
485                         reg->U1BC_LEDConfigure = ltmp;
486                         if( LEDSet != 7 ) // Only 111 mode has 2 LEDs on PCB.
487                         {
488                                 reg->U1BC_LEDConfigure |= (ltmp &0xff)<<8; // Copy LED result to each LED control register
489                                 reg->U1BC_LEDConfigure |= (ltmp &0xff00)>>8;
490                         }
491                         Wb35Reg_Write( pHwData, 0x03bc, reg->U1BC_LEDConfigure );
492                 }
493         }
494         else if( pHwData->CurrentRadioSw || pHwData->CurrentRadioHw ) // If radio off
495         {
496                 if( reg->U1BC_LEDConfigure & 0x1010 )
497                 {
498                         reg->U1BC_LEDConfigure &= ~0x1010;
499                         Wb35Reg_Write( pHwData, 0x03bc, reg->U1BC_LEDConfigure );
500                 }
501         }
502         else
503         {
504                 switch( LEDSet )
505                 {
506                         case 4: // [100] Only 1 Led be placed on PCB and use pin 21 of IC. Use LED_0 for showing
507                                 if( !pHwData->LED_LinkOn ) // Blink only if not Link On
508                                 {
509                                         // Blinking if scanning is on progress
510                                         if( pHwData->LED_Scanning )
511                                         {
512                                                 if( pHwData->LED_Blinking == 0 )
513                                                 {
514                                                         reg->U1BC_LEDConfigure |= 0x10;
515                                                         Wb35Reg_Write( pHwData, 0x03bc, reg->U1BC_LEDConfigure ); // LED_0 On
516                                                         pHwData->LED_Blinking = 1;
517                                                         TimeInterval = 300;
518                                                 }
519                                                 else
520                                                 {
521                                                         reg->U1BC_LEDConfigure &= ~0x10;
522                                                         Wb35Reg_Write( pHwData, 0x03bc, reg->U1BC_LEDConfigure ); // LED_0 Off
523                                                         pHwData->LED_Blinking = 0;
524                                                         TimeInterval = 300;
525                                                 }
526                                         }
527                                         else
528                                         {
529                                                 //Turn Off LED_0
530                                                 if( reg->U1BC_LEDConfigure & 0x10 )
531                                                 {
532                                                         reg->U1BC_LEDConfigure &= ~0x10;
533                                                         Wb35Reg_Write( pHwData, 0x03bc, reg->U1BC_LEDConfigure ); // LED_0 Off
534                                                 }
535                                         }
536                                 }
537                                 else
538                                 {
539                                         // Turn On LED_0
540                                         if( (reg->U1BC_LEDConfigure & 0x10) == 0 )
541                                         {
542                                                 reg->U1BC_LEDConfigure |= 0x10;
543                                                 Wb35Reg_Write( pHwData, 0x03bc, reg->U1BC_LEDConfigure ); // LED_0 Off
544                                         }
545                                 }
546                                 break;
547
548                         case 6: // [110] Only 1 Led be placed on PCB and use pin 21 of IC. Use LED_0 for showing
549                                 if( !pHwData->LED_LinkOn ) // Blink only if not Link On
550                                 {
551                                         // Blinking if scanning is on progress
552                                         if( pHwData->LED_Scanning )
553                                         {
554                                                 if( pHwData->LED_Blinking == 0 )
555                                                 {
556                                                         reg->U1BC_LEDConfigure &= ~0xf;
557                                                         reg->U1BC_LEDConfigure |= 0x10;
558                                                         Wb35Reg_Write( pHwData, 0x03bc, reg->U1BC_LEDConfigure ); // LED_0 On
559                                                         pHwData->LED_Blinking = 1;
560                                                         TimeInterval = 300;
561                                                 }
562                                                 else
563                                                 {
564                                                         reg->U1BC_LEDConfigure &= ~0x1f;
565                                                         Wb35Reg_Write( pHwData, 0x03bc, reg->U1BC_LEDConfigure ); // LED_0 Off
566                                                         pHwData->LED_Blinking = 0;
567                                                         TimeInterval = 300;
568                                                 }
569                                         }
570                                         else
571                                         {
572                                                 // 20060901 Gray blinking if in disconnect state and not scanning
573                                                 ltmp = reg->U1BC_LEDConfigure;
574                                                 reg->U1BC_LEDConfigure &= ~0x1f;
575                                                 if( LEDgray2[(pHwData->LED_Blinking%30)] )
576                                                 {
577                                                         reg->U1BC_LEDConfigure |= 0x10;
578                                                         reg->U1BC_LEDConfigure |= LEDgray2[ (pHwData->LED_Blinking%30) ];
579                                                 }
580                                                 pHwData->LED_Blinking++;
581                                                 if( reg->U1BC_LEDConfigure != ltmp )
582                                                         Wb35Reg_Write( pHwData, 0x03bc, reg->U1BC_LEDConfigure ); // LED_0 Off
583                                                 TimeInterval = 100;
584                                         }
585                                 }
586                                 else
587                                 {
588                                         // Turn On LED_0
589                                         if( (reg->U1BC_LEDConfigure & 0x10) == 0 )
590                                         {
591                                                 reg->U1BC_LEDConfigure |= 0x10;
592                                                 Wb35Reg_Write( pHwData, 0x03bc, reg->U1BC_LEDConfigure ); // LED_0 Off
593                                         }
594                                 }
595                                 break;
596
597                         case 5: // [101] Only 1 Led be placed on PCB and use LED_1 for showing
598                                 if( !pHwData->LED_LinkOn ) // Blink only if not Link On
599                                 {
600                                         // Blinking if scanning is on progress
601                                         if( pHwData->LED_Scanning )
602                                         {
603                                                 if( pHwData->LED_Blinking == 0 )
604                                                 {
605                                                         reg->U1BC_LEDConfigure |= 0x1000;
606                                                         Wb35Reg_Write( pHwData, 0x03bc, reg->U1BC_LEDConfigure ); // LED_1 On
607                                                         pHwData->LED_Blinking = 1;
608                                                         TimeInterval = 300;
609                                                 }
610                                                 else
611                                                 {
612                                                         reg->U1BC_LEDConfigure &= ~0x1000;
613                                                         Wb35Reg_Write( pHwData, 0x03bc, reg->U1BC_LEDConfigure ); // LED_1 Off
614                                                         pHwData->LED_Blinking = 0;
615                                                         TimeInterval = 300;
616                                                 }
617                                         }
618                                         else
619                                         {
620                                                 //Turn Off LED_1
621                                                 if( reg->U1BC_LEDConfigure & 0x1000 )
622                                                 {
623                                                         reg->U1BC_LEDConfigure &= ~0x1000;
624                                                         Wb35Reg_Write( pHwData, 0x03bc, reg->U1BC_LEDConfigure ); // LED_1 Off
625                                                 }
626                                         }
627                                 }
628                                 else
629                                 {
630                                         // Is transmitting/receiving ??
631                                         if( (OS_CURRENT_RX_BYTE( adapter ) != pHwData->RxByteCountLast ) ||
632                                                 (OS_CURRENT_TX_BYTE( adapter ) != pHwData->TxByteCountLast ) )
633                                         {
634                                                 if( (reg->U1BC_LEDConfigure & 0x3000) != 0x3000 )
635                                                 {
636                                                         reg->U1BC_LEDConfigure |= 0x3000;
637                                                         Wb35Reg_Write( pHwData, 0x03bc, reg->U1BC_LEDConfigure ); // LED_1 On
638                                                 }
639
640                                                 // Update variable
641                                                 pHwData->RxByteCountLast = OS_CURRENT_RX_BYTE( adapter );
642                                                 pHwData->TxByteCountLast = OS_CURRENT_TX_BYTE( adapter );
643                                                 TimeInterval = 200;
644                                         }
645                                         else
646                                         {
647                                                 // Turn On LED_1 and blinking if transmitting/receiving
648                                                  if( (reg->U1BC_LEDConfigure & 0x3000) != 0x1000 )
649                                                  {
650                                                          reg->U1BC_LEDConfigure &= ~0x3000;
651                                                          reg->U1BC_LEDConfigure |= 0x1000;
652                                                          Wb35Reg_Write( pHwData, 0x03bc, reg->U1BC_LEDConfigure ); // LED_1 On
653                                                  }
654                                         }
655                                 }
656                                 break;
657
658                         default: // Default setting. 2 LED be placed on PCB. LED_0: Link On LED_1 Active
659                                 if( (reg->U1BC_LEDConfigure & 0x3000) != 0x3000 )
660                                 {
661                                         reg->U1BC_LEDConfigure |= 0x3000;// LED_1 is always on and event enable
662                                         Wb35Reg_Write( pHwData, 0x03bc, reg->U1BC_LEDConfigure );
663                                 }
664
665                                 if( pHwData->LED_Blinking )
666                                 {
667                                         // Gray blinking
668                                         reg->U1BC_LEDConfigure &= ~0x0f;
669                                         reg->U1BC_LEDConfigure |= 0x10;
670                                         reg->U1BC_LEDConfigure |= LEDgray[ (pHwData->LED_Blinking-1)%20 ];
671                                         Wb35Reg_Write( pHwData, 0x03bc, reg->U1BC_LEDConfigure );
672
673                                         pHwData->LED_Blinking += 2;
674                                         if( pHwData->LED_Blinking < 40 )
675                                                 TimeInterval = 100;
676                                         else
677                                         {
678                                                 pHwData->LED_Blinking = 0; // Stop blinking
679                                                 reg->U1BC_LEDConfigure &= ~0x0f;
680                                                 Wb35Reg_Write( pHwData, 0x03bc, reg->U1BC_LEDConfigure );
681                                         }
682                                         break;
683                                 }
684
685                                 if( pHwData->LED_LinkOn )
686                                 {
687                                         if( !(reg->U1BC_LEDConfigure & 0x10) ) // Check the LED_0
688                                         {
689                                                 //Try to turn ON LED_0 after gray blinking
690                                                 reg->U1BC_LEDConfigure |= 0x10;
691                                                 pHwData->LED_Blinking = 1; //Start blinking
692                                                 TimeInterval = 50;
693                                         }
694                                 }
695                                 else
696                                 {
697                                         if( reg->U1BC_LEDConfigure & 0x10 ) // Check the LED_0
698                                         {
699                                                 reg->U1BC_LEDConfigure &= ~0x10;
700                                                 Wb35Reg_Write( pHwData, 0x03bc, reg->U1BC_LEDConfigure );
701                                         }
702                                 }
703                                 break;
704                 }
705
706                 //20060828.1 Active send null packet to avoid AP disconnect
707                 if( pHwData->LED_LinkOn )
708                 {
709                         pHwData->NullPacketCount += TimeInterval;
710                         if( pHwData->NullPacketCount >= DEFAULT_NULL_PACKET_COUNT )
711                         {
712                                 pHwData->NullPacketCount = 0;
713                         }
714                 }
715         }
716
717         pHwData->time_count += TimeInterval;
718         Wb35Tx_CurrentTime( pHwData, pHwData->time_count ); // 20060928 add
719         OS_TIMER_SET( &pHwData->LEDTimer, TimeInterval ); // 20060623.1
720 }
721
722
723 void hal_set_phy_type(  phw_data_t pHwData,  u8 PhyType )
724 {
725         pHwData->phy_type = PhyType;
726 }
727
728 void hal_get_phy_type(  phw_data_t pHwData,  u8 *PhyType )
729 {
730         *PhyType = pHwData->phy_type;
731 }
732
733 void hal_reset_counter(  phw_data_t pHwData )
734 {
735         pHwData->dto_tx_retry_count = 0;
736         pHwData->dto_tx_frag_count = 0;
737         memset( pHwData->tx_retry_count, 0, 8);
738 }
739
740 void hal_set_radio_mode( phw_data_t pHwData,  unsigned char radio_off)
741 {
742         struct wb35_reg *reg = &pHwData->reg;
743
744         if( pHwData->SurpriseRemove ) return;
745
746         if (radio_off)  //disable Baseband receive off
747         {
748                 pHwData->CurrentRadioSw = 1; // off
749                 reg->M24_MacControl &= 0xffffffbf;
750         }
751         else
752         {
753                 pHwData->CurrentRadioSw = 0; // on
754                 reg->M24_MacControl |= 0x00000040;
755         }
756         Wb35Reg_Write( pHwData, 0x0824, reg->M24_MacControl );
757 }
758
759 u8 hal_get_antenna_number(  phw_data_t pHwData )
760 {
761         struct wb35_reg *reg = &pHwData->reg;
762
763         if ((reg->BB2C & BIT(11)) == 0)
764                 return 0;
765         else
766                 return 1;
767 }
768
769 void hal_set_antenna_number(  phw_data_t pHwData, u8 number )
770 {
771
772         struct wb35_reg *reg = &pHwData->reg;
773
774         if (number == 1) {
775                 reg->BB2C |= BIT(11);
776         } else {
777                 reg->BB2C &= ~BIT(11);
778         }
779         Wb35Reg_Write( pHwData, 0x102c, reg->BB2C );
780 #ifdef _PE_STATE_DUMP_
781         WBDEBUG(("Current antenna number : %d\n", number));
782 #endif
783 }
784
785 //----------------------------------------------------------------------------------------------------
786 //0 : radio on; 1: radio off
787 u8 hal_get_hw_radio_off(  phw_data_t pHwData )
788 {
789         struct wb35_reg *reg = &pHwData->reg;
790
791         if( pHwData->SurpriseRemove ) return 1;
792
793         //read the bit16 of register U1B0
794         Wb35Reg_Read( pHwData, 0x3b0, &reg->U1B0 );
795         if ((reg->U1B0 & 0x00010000)) {
796                 pHwData->CurrentRadioHw = 1;
797                 return 1;
798         } else {
799                 pHwData->CurrentRadioHw = 0;
800                 return 0;
801         }
802 }
803
804 unsigned char hal_get_dxx_reg(  phw_data_t pHwData,  u16 number,  u32 * pValue )
805 {
806         if( number < 0x1000 )
807                 number += 0x1000;
808         return Wb35Reg_ReadSync( pHwData, number, pValue );
809 }
810
811 unsigned char hal_set_dxx_reg(  phw_data_t pHwData,  u16 number,  u32 value )
812 {
813         unsigned char   ret;
814
815         if( number < 0x1000 )
816                 number += 0x1000;
817         ret = Wb35Reg_WriteSync( pHwData, number, value );
818         return ret;
819 }
820
821 void hal_scan_status_indicate(phw_data_t pHwData, unsigned char IsOnProgress)
822 {
823         if( pHwData->SurpriseRemove ) return;
824         pHwData->LED_Scanning = IsOnProgress ? 1 : 0;
825 }
826
827 void hal_system_power_change(phw_data_t pHwData, u32 PowerState)
828 {
829         if( PowerState != 0 )
830         {
831                 pHwData->SurpriseRemove = 1;
832                 if( pHwData->WbUsb.IsUsb20 )
833                         hal_stop( pHwData );
834         }
835         else
836         {
837                 if( !pHwData->WbUsb.IsUsb20 )
838                         hal_stop( pHwData );
839         }
840 }
841
842 void hal_surprise_remove(  phw_data_t pHwData )
843 {
844         struct wb35_adapter * adapter = pHwData->adapter;
845         if (OS_ATOMIC_INC( adapter, &pHwData->SurpriseRemoveCount ) == 1) {
846                 #ifdef _PE_STATE_DUMP_
847                 WBDEBUG(("Calling hal_surprise_remove\n"));
848                 #endif
849                 OS_STOP( adapter );
850         }
851 }
852
853 void hal_rate_change(  phw_data_t pHwData ) // Notify the HAL rate is changing 20060613.1
854 {
855         struct wb35_adapter *   adapter = pHwData->adapter;
856         u8              rate = CURRENT_TX_RATE;
857
858         BBProcessor_RateChanging( pHwData, rate );
859 }
860
861 void hal_set_rf_power(phw_data_t pHwData, u8 PowerIndex)
862 {
863         RFSynthesizer_SetPowerIndex( pHwData, PowerIndex );
864 }
865
866 unsigned char hal_set_LED(phw_data_t pHwData, u32 Mode) // 20061108 for WPS led control
867 {
868         pHwData->LED_Blinking = 0;
869         pHwData->LED_control = Mode;
870         OS_TIMER_SET( &pHwData->LEDTimer, 10 ); // 20060623
871         return TRUE;
872 }
873