2 #include "phy_calibration.h"
5 #include <linux/slab.h>
8 * true : read command process successfully
9 * false : register not support
10 * RegisterNo : start base
11 * pRegisterData : data point
12 * NumberOfData : number of register data
13 * Flag : AUTO_INCREMENT - RegisterNo will auto increment 4
14 * NO_INCREMENT - Function will write data into the same register
16 unsigned char Wb35Reg_BurstWrite(struct hw_data
*pHwData
, u16 RegisterNo
,
17 u32
*pRegisterData
, u8 NumberOfData
, u8 Flag
)
19 struct wb35_reg
*reg
= &pHwData
->reg
;
20 struct urb
*urb
= NULL
;
21 struct wb35_reg_queue
*reg_queue
= NULL
;
23 struct usb_ctrlrequest
*dr
;
24 u16 i
, DataSize
= NumberOfData
* 4;
27 if (pHwData
->SurpriseRemove
)
30 /* Trying to use burst write function if use new hardware */
31 UrbSize
= sizeof(struct wb35_reg_queue
) + DataSize
+ sizeof(struct usb_ctrlrequest
);
32 reg_queue
= kzalloc(UrbSize
, GFP_ATOMIC
);
33 if (reg_queue
== NULL
)
36 urb
= usb_alloc_urb(0, GFP_ATOMIC
);
42 reg_queue
->DIRECT
= 2; /* burst write register */
43 reg_queue
->INDEX
= RegisterNo
;
44 reg_queue
->pBuffer
= (u32
*)((u8
*)reg_queue
+ sizeof(struct wb35_reg_queue
));
45 memcpy(reg_queue
->pBuffer
, pRegisterData
, DataSize
);
46 /* the function for reversing register data from little endian to big endian */
47 for (i
= 0; i
< NumberOfData
; i
++)
48 reg_queue
->pBuffer
[i
] = cpu_to_le32(reg_queue
->pBuffer
[i
]);
50 dr
= (struct usb_ctrlrequest
*)((u8
*)reg_queue
+ sizeof(struct wb35_reg_queue
) + DataSize
);
51 dr
->bRequestType
= USB_TYPE_VENDOR
| USB_DIR_OUT
| USB_RECIP_DEVICE
;
52 dr
->bRequest
= 0x04; /* USB or vendor-defined request code, burst mode */
53 dr
->wValue
= cpu_to_le16(Flag
); /* 0: Register number auto-increment, 1: No auto increment */
54 dr
->wIndex
= cpu_to_le16(RegisterNo
);
55 dr
->wLength
= cpu_to_le16(DataSize
);
56 reg_queue
->Next
= NULL
;
57 reg_queue
->pUsbReq
= dr
;
60 spin_lock_irq(®
->EP0VM_spin_lock
);
61 if (reg
->reg_first
== NULL
)
62 reg
->reg_first
= reg_queue
;
64 reg
->reg_last
->Next
= reg_queue
;
65 reg
->reg_last
= reg_queue
;
67 spin_unlock_irq(®
->EP0VM_spin_lock
);
70 Wb35Reg_EP0VM_start(pHwData
);
75 void Wb35Reg_Update(struct hw_data
*pHwData
, u16 RegisterNo
, u32 RegisterValue
)
77 struct wb35_reg
*reg
= &pHwData
->reg
;
79 case 0x3b0: reg
->U1B0
= RegisterValue
; break;
80 case 0x3bc: reg
->U1BC_LEDConfigure
= RegisterValue
; break;
81 case 0x400: reg
->D00_DmaControl
= RegisterValue
; break;
82 case 0x800: reg
->M00_MacControl
= RegisterValue
; break;
83 case 0x804: reg
->M04_MulticastAddress1
= RegisterValue
; break;
84 case 0x808: reg
->M08_MulticastAddress2
= RegisterValue
; break;
85 case 0x824: reg
->M24_MacControl
= RegisterValue
; break;
86 case 0x828: reg
->M28_MacControl
= RegisterValue
; break;
87 case 0x82c: reg
->M2C_MacControl
= RegisterValue
; break;
88 case 0x838: reg
->M38_MacControl
= RegisterValue
; break;
89 case 0x840: reg
->M40_MacControl
= RegisterValue
; break;
90 case 0x844: reg
->M44_MacControl
= RegisterValue
; break;
91 case 0x848: reg
->M48_MacControl
= RegisterValue
; break;
92 case 0x84c: reg
->M4C_MacStatus
= RegisterValue
; break;
93 case 0x860: reg
->M60_MacControl
= RegisterValue
; break;
94 case 0x868: reg
->M68_MacControl
= RegisterValue
; break;
95 case 0x870: reg
->M70_MacControl
= RegisterValue
; break;
96 case 0x874: reg
->M74_MacControl
= RegisterValue
; break;
97 case 0x878: reg
->M78_ERPInformation
= RegisterValue
; break;
98 case 0x87C: reg
->M7C_MacControl
= RegisterValue
; break;
99 case 0x880: reg
->M80_MacControl
= RegisterValue
; break;
100 case 0x884: reg
->M84_MacControl
= RegisterValue
; break;
101 case 0x888: reg
->M88_MacControl
= RegisterValue
; break;
102 case 0x898: reg
->M98_MacControl
= RegisterValue
; break;
103 case 0x100c: reg
->BB0C
= RegisterValue
; break;
104 case 0x102c: reg
->BB2C
= RegisterValue
; break;
105 case 0x1030: reg
->BB30
= RegisterValue
; break;
106 case 0x103c: reg
->BB3C
= RegisterValue
; break;
107 case 0x1048: reg
->BB48
= RegisterValue
; break;
108 case 0x104c: reg
->BB4C
= RegisterValue
; break;
109 case 0x1050: reg
->BB50
= RegisterValue
; break;
110 case 0x1054: reg
->BB54
= RegisterValue
; break;
111 case 0x1058: reg
->BB58
= RegisterValue
; break;
112 case 0x105c: reg
->BB5C
= RegisterValue
; break;
113 case 0x1060: reg
->BB60
= RegisterValue
; break;
118 * true : read command process successfully
119 * false : register not support
121 unsigned char Wb35Reg_WriteSync(struct hw_data
*pHwData
, u16 RegisterNo
,
124 struct wb35_reg
*reg
= &pHwData
->reg
;
127 /* Module shutdown */
128 if (pHwData
->SurpriseRemove
)
131 RegisterValue
= cpu_to_le32(RegisterValue
);
133 /* update the register by send usb message */
134 reg
->SyncIoPause
= 1;
136 /* Wait until EP0VM stop */
137 while (reg
->EP0vm_state
!= VM_STOP
)
140 /* Sync IoCallDriver */
141 reg
->EP0vm_state
= VM_RUNNING
;
142 ret
= usb_control_msg(pHwData
->udev
,
143 usb_sndctrlpipe(pHwData
->udev
, 0),
145 USB_TYPE_VENDOR
| USB_RECIP_DEVICE
| USB_DIR_OUT
,
146 0x0, RegisterNo
, &RegisterValue
, 4, HZ
* 100);
147 reg
->EP0vm_state
= VM_STOP
;
148 reg
->SyncIoPause
= 0;
150 Wb35Reg_EP0VM_start(pHwData
);
153 pr_debug("EP0 Write register usb message sending error\n");
154 pHwData
->SurpriseRemove
= 1;
161 * true : read command process successfully
162 * false : register not support
164 unsigned char Wb35Reg_Write(struct hw_data
*pHwData
, u16 RegisterNo
,
167 struct wb35_reg
*reg
= &pHwData
->reg
;
168 struct usb_ctrlrequest
*dr
;
169 struct urb
*urb
= NULL
;
170 struct wb35_reg_queue
*reg_queue
= NULL
;
173 /* Module shutdown */
174 if (pHwData
->SurpriseRemove
)
177 /* update the register by send urb request */
178 UrbSize
= sizeof(struct wb35_reg_queue
) + sizeof(struct usb_ctrlrequest
);
179 reg_queue
= kzalloc(UrbSize
, GFP_ATOMIC
);
180 if (reg_queue
== NULL
)
183 urb
= usb_alloc_urb(0, GFP_ATOMIC
);
189 reg_queue
->DIRECT
= 1; /* burst write register */
190 reg_queue
->INDEX
= RegisterNo
;
191 reg_queue
->VALUE
= cpu_to_le32(RegisterValue
);
192 reg_queue
->RESERVED_VALID
= false;
193 dr
= (struct usb_ctrlrequest
*)((u8
*)reg_queue
+ sizeof(struct wb35_reg_queue
));
194 dr
->bRequestType
= USB_TYPE_VENDOR
| USB_DIR_OUT
| USB_RECIP_DEVICE
;
195 dr
->bRequest
= 0x03; /* USB or vendor-defined request code, burst mode */
196 dr
->wValue
= cpu_to_le16(0x0);
197 dr
->wIndex
= cpu_to_le16(RegisterNo
);
198 dr
->wLength
= cpu_to_le16(4);
200 /* Enter the sending queue */
201 reg_queue
->Next
= NULL
;
202 reg_queue
->pUsbReq
= dr
;
203 reg_queue
->urb
= urb
;
205 spin_lock_irq(®
->EP0VM_spin_lock
);
206 if (reg
->reg_first
== NULL
)
207 reg
->reg_first
= reg_queue
;
209 reg
->reg_last
->Next
= reg_queue
;
210 reg
->reg_last
= reg_queue
;
212 spin_unlock_irq(®
->EP0VM_spin_lock
);
215 Wb35Reg_EP0VM_start(pHwData
);
221 * This command will be executed with a user defined value. When it completes,
222 * this value is useful. For example, hal_set_current_channel will use it.
223 * true : read command process successfully
224 * false : register not supported
226 unsigned char Wb35Reg_WriteWithCallbackValue(struct hw_data
*pHwData
,
232 struct wb35_reg
*reg
= &pHwData
->reg
;
233 struct usb_ctrlrequest
*dr
;
234 struct urb
*urb
= NULL
;
235 struct wb35_reg_queue
*reg_queue
= NULL
;
238 /* Module shutdown */
239 if (pHwData
->SurpriseRemove
)
242 /* update the register by send urb request */
243 UrbSize
= sizeof(struct wb35_reg_queue
) + sizeof(struct usb_ctrlrequest
);
244 reg_queue
= kzalloc(UrbSize
, GFP_ATOMIC
);
245 if (reg_queue
== NULL
)
248 urb
= usb_alloc_urb(0, GFP_ATOMIC
);
254 reg_queue
->DIRECT
= 1; /* burst write register */
255 reg_queue
->INDEX
= RegisterNo
;
256 reg_queue
->VALUE
= cpu_to_le32(RegisterValue
);
257 /* NOTE : Users must guarantee the size of value will not exceed the buffer size. */
258 memcpy(reg_queue
->RESERVED
, pValue
, Len
);
259 reg_queue
->RESERVED_VALID
= true;
260 dr
= (struct usb_ctrlrequest
*)((u8
*)reg_queue
+ sizeof(struct wb35_reg_queue
));
261 dr
->bRequestType
= USB_TYPE_VENDOR
| USB_DIR_OUT
| USB_RECIP_DEVICE
;
262 dr
->bRequest
= 0x03; /* USB or vendor-defined request code, burst mode */
263 dr
->wValue
= cpu_to_le16(0x0);
264 dr
->wIndex
= cpu_to_le16(RegisterNo
);
265 dr
->wLength
= cpu_to_le16(4);
267 /* Enter the sending queue */
268 reg_queue
->Next
= NULL
;
269 reg_queue
->pUsbReq
= dr
;
270 reg_queue
->urb
= urb
;
271 spin_lock_irq(®
->EP0VM_spin_lock
);
272 if (reg
->reg_first
== NULL
)
273 reg
->reg_first
= reg_queue
;
275 reg
->reg_last
->Next
= reg_queue
;
276 reg
->reg_last
= reg_queue
;
278 spin_unlock_irq(®
->EP0VM_spin_lock
);
281 Wb35Reg_EP0VM_start(pHwData
);
287 * true : read command process successfully
288 * false : register not support
289 * pRegisterValue : It must be a resident buffer due to
290 * asynchronous read register.
292 unsigned char Wb35Reg_ReadSync(struct hw_data
*pHwData
, u16 RegisterNo
,
295 struct wb35_reg
*reg
= &pHwData
->reg
;
296 u32
*pltmp
= pRegisterValue
;
299 /* Module shutdown */
300 if (pHwData
->SurpriseRemove
)
303 /* Read the register by send usb message */
304 reg
->SyncIoPause
= 1;
306 /* Wait until EP0VM stop */
307 while (reg
->EP0vm_state
!= VM_STOP
)
310 reg
->EP0vm_state
= VM_RUNNING
;
311 ret
= usb_control_msg(pHwData
->udev
,
312 usb_rcvctrlpipe(pHwData
->udev
, 0),
314 USB_TYPE_VENDOR
| USB_RECIP_DEVICE
| USB_DIR_IN
,
315 0x0, RegisterNo
, pltmp
, 4, HZ
* 100);
317 *pRegisterValue
= cpu_to_le32(*pltmp
);
319 reg
->EP0vm_state
= VM_STOP
;
321 Wb35Reg_Update(pHwData
, RegisterNo
, *pRegisterValue
);
322 reg
->SyncIoPause
= 0;
324 Wb35Reg_EP0VM_start(pHwData
);
327 pr_debug("EP0 Read register usb message sending error\n");
328 pHwData
->SurpriseRemove
= 1;
335 * true : read command process successfully
336 * false : register not support
337 * pRegisterValue : It must be a resident buffer due to
338 * asynchronous read register.
340 unsigned char Wb35Reg_Read(struct hw_data
*pHwData
, u16 RegisterNo
,
343 struct wb35_reg
*reg
= &pHwData
->reg
;
344 struct usb_ctrlrequest
*dr
;
346 struct wb35_reg_queue
*reg_queue
;
349 /* Module shutdown */
350 if (pHwData
->SurpriseRemove
)
353 /* update the variable by send Urb to read register */
354 UrbSize
= sizeof(struct wb35_reg_queue
) + sizeof(struct usb_ctrlrequest
);
355 reg_queue
= kzalloc(UrbSize
, GFP_ATOMIC
);
356 if (reg_queue
== NULL
)
359 urb
= usb_alloc_urb(0, GFP_ATOMIC
);
364 reg_queue
->DIRECT
= 0; /* read register */
365 reg_queue
->INDEX
= RegisterNo
;
366 reg_queue
->pBuffer
= pRegisterValue
;
367 dr
= (struct usb_ctrlrequest
*)((u8
*)reg_queue
+ sizeof(struct wb35_reg_queue
));
368 dr
->bRequestType
= USB_TYPE_VENDOR
| USB_RECIP_DEVICE
| USB_DIR_IN
;
369 dr
->bRequest
= 0x01; /* USB or vendor-defined request code, burst mode */
370 dr
->wValue
= cpu_to_le16(0x0);
371 dr
->wIndex
= cpu_to_le16(RegisterNo
);
372 dr
->wLength
= cpu_to_le16(4);
374 /* Enter the sending queue */
375 reg_queue
->Next
= NULL
;
376 reg_queue
->pUsbReq
= dr
;
377 reg_queue
->urb
= urb
;
378 spin_lock_irq(®
->EP0VM_spin_lock
);
379 if (reg
->reg_first
== NULL
)
380 reg
->reg_first
= reg_queue
;
382 reg
->reg_last
->Next
= reg_queue
;
383 reg
->reg_last
= reg_queue
;
385 spin_unlock_irq(®
->EP0VM_spin_lock
);
388 Wb35Reg_EP0VM_start(pHwData
);
394 void Wb35Reg_EP0VM_start(struct hw_data
*pHwData
)
396 struct wb35_reg
*reg
= &pHwData
->reg
;
398 if (atomic_inc_return(®
->RegFireCount
) == 1) {
399 reg
->EP0vm_state
= VM_RUNNING
;
400 Wb35Reg_EP0VM(pHwData
);
402 atomic_dec(®
->RegFireCount
);
405 void Wb35Reg_EP0VM(struct hw_data
*pHwData
)
407 struct wb35_reg
*reg
= &pHwData
->reg
;
409 struct usb_ctrlrequest
*dr
;
412 struct wb35_reg_queue
*reg_queue
;
415 if (reg
->SyncIoPause
)
418 if (pHwData
->SurpriseRemove
)
421 /* Get the register data and send to USB through Irp */
422 spin_lock_irq(®
->EP0VM_spin_lock
);
423 reg_queue
= reg
->reg_first
;
424 spin_unlock_irq(®
->EP0VM_spin_lock
);
429 /* Get an Urb, send it */
430 urb
= (struct urb
*)reg_queue
->urb
;
432 dr
= reg_queue
->pUsbReq
;
433 urb
= reg_queue
->urb
;
434 pBuffer
= reg_queue
->pBuffer
;
435 if (reg_queue
->DIRECT
== 1) /* output */
436 pBuffer
= ®_queue
->VALUE
;
438 usb_fill_control_urb(urb
, pHwData
->udev
,
439 REG_DIRECTION(pHwData
->udev
, reg_queue
),
440 (u8
*)dr
, pBuffer
, cpu_to_le16(dr
->wLength
),
441 Wb35Reg_EP0VM_complete
, (void *)pHwData
);
443 reg
->EP0vm_state
= VM_RUNNING
;
445 ret
= usb_submit_urb(urb
, GFP_ATOMIC
);
448 pr_debug("EP0 Irp sending error\n");
454 reg
->EP0vm_state
= VM_STOP
;
455 atomic_dec(®
->RegFireCount
);
459 void Wb35Reg_EP0VM_complete(struct urb
*urb
)
461 struct hw_data
*pHwData
= (struct hw_data
*)urb
->context
;
462 struct wb35_reg
*reg
= &pHwData
->reg
;
463 struct wb35_reg_queue
*reg_queue
;
466 /* Variable setting */
467 reg
->EP0vm_state
= VM_COMPLETED
;
468 reg
->EP0VM_status
= urb
->status
;
470 if (pHwData
->SurpriseRemove
) { /* Let WbWlanHalt to handle surprise remove */
471 reg
->EP0vm_state
= VM_STOP
;
472 atomic_dec(®
->RegFireCount
);
474 /* Complete to send, remove the URB from the first */
475 spin_lock_irq(®
->EP0VM_spin_lock
);
476 reg_queue
= reg
->reg_first
;
477 if (reg_queue
== reg
->reg_last
)
478 reg
->reg_last
= NULL
;
479 reg
->reg_first
= reg
->reg_first
->Next
;
480 spin_unlock_irq(®
->EP0VM_spin_lock
);
482 if (reg
->EP0VM_status
) {
483 pr_debug("EP0 IoCompleteRoutine return error\n");
484 reg
->EP0vm_state
= VM_STOP
;
485 pHwData
->SurpriseRemove
= 1;
487 /* Success. Update the result */
489 /* Start the next send */
490 Wb35Reg_EP0VM(pHwData
);
500 void Wb35Reg_destroy(struct hw_data
*pHwData
)
502 struct wb35_reg
*reg
= &pHwData
->reg
;
504 struct wb35_reg_queue
*reg_queue
;
506 Uxx_power_off_procedure(pHwData
);
508 /* Wait for Reg operation completed */
510 msleep(10); /* Delay for waiting function enter */
511 } while (reg
->EP0vm_state
!= VM_STOP
);
512 msleep(10); /* Delay for waiting function enter */
514 /* Release all the data in RegQueue */
515 spin_lock_irq(®
->EP0VM_spin_lock
);
516 reg_queue
= reg
->reg_first
;
518 if (reg_queue
== reg
->reg_last
)
519 reg
->reg_last
= NULL
;
520 reg
->reg_first
= reg
->reg_first
->Next
;
522 urb
= reg_queue
->urb
;
523 spin_unlock_irq(®
->EP0VM_spin_lock
);
528 pr_debug("EP0 queue release error\n");
530 spin_lock_irq(®
->EP0VM_spin_lock
);
532 reg_queue
= reg
->reg_first
;
534 spin_unlock_irq(®
->EP0VM_spin_lock
);
538 * =======================================================================
539 * The function can be run in passive-level only.
540 * =========================================================================
542 unsigned char Wb35Reg_initial(struct hw_data
*pHwData
)
544 struct wb35_reg
*reg
= &pHwData
->reg
;
546 u32 SoftwareSet
, VCO_trim
, TxVga
, Region_ScanInterval
;
548 /* Spin lock is acquired for read and write IRP command */
549 spin_lock_init(®
->EP0VM_spin_lock
);
551 /* Getting RF module type from EEPROM */
552 Wb35Reg_WriteSync(pHwData
, 0x03b4, 0x080d0000); /* Start EEPROM access + Read + address(0x0d) */
553 Wb35Reg_ReadSync(pHwData
, 0x03b4, <mp
);
555 /* Update RF module type and determine the PHY type by inf or EEPROM */
556 reg
->EEPROMPhyType
= (u8
)(ltmp
& 0xff);
558 * 0 V MAX2825, 1 V MAX2827, 2 V MAX2828, 3 V MAX2829
559 * 16V AL2230, 17 - AL7230, 18 - AL2230S
561 * 33 - W89RF242(TxVGA 0~19), 34 - W89RF242(TxVGA 0~34)
563 if (reg
->EEPROMPhyType
!= RF_DECIDE_BY_INF
) {
564 if ((reg
->EEPROMPhyType
== RF_MAXIM_2825
) ||
565 (reg
->EEPROMPhyType
== RF_MAXIM_2827
) ||
566 (reg
->EEPROMPhyType
== RF_MAXIM_2828
) ||
567 (reg
->EEPROMPhyType
== RF_MAXIM_2829
) ||
568 (reg
->EEPROMPhyType
== RF_MAXIM_V1
) ||
569 (reg
->EEPROMPhyType
== RF_AIROHA_2230
) ||
570 (reg
->EEPROMPhyType
== RF_AIROHA_2230S
) ||
571 (reg
->EEPROMPhyType
== RF_AIROHA_7230
) ||
572 (reg
->EEPROMPhyType
== RF_WB_242
) ||
573 (reg
->EEPROMPhyType
== RF_WB_242_1
))
574 pHwData
->phy_type
= reg
->EEPROMPhyType
;
577 /* Power On procedure running. The relative parameter will be set according to phy_type */
578 Uxx_power_on_procedure(pHwData
);
580 /* Reading MAC address */
581 Uxx_ReadEthernetAddress(pHwData
);
583 /* Read VCO trim for RF parameter */
584 Wb35Reg_WriteSync(pHwData
, 0x03b4, 0x08200000);
585 Wb35Reg_ReadSync(pHwData
, 0x03b4, &VCO_trim
);
587 /* Read Antenna On/Off of software flag */
588 Wb35Reg_WriteSync(pHwData
, 0x03b4, 0x08210000);
589 Wb35Reg_ReadSync(pHwData
, 0x03b4, &SoftwareSet
);
592 Wb35Reg_WriteSync(pHwData
, 0x03b4, 0x08100000);
593 Wb35Reg_ReadSync(pHwData
, 0x03b4, &TxVga
);
595 /* Get Scan interval setting from EEPROM offset 0x1c */
596 Wb35Reg_WriteSync(pHwData
, 0x03b4, 0x081d0000);
597 Wb35Reg_ReadSync(pHwData
, 0x03b4, &Region_ScanInterval
);
599 /* Update Ethernet address */
600 memcpy(pHwData
->CurrentMacAddress
, pHwData
->PermanentMacAddress
, ETH_ALEN
);
602 /* Update software variable */
603 pHwData
->SoftwareSet
= (u16
)(SoftwareSet
& 0xffff);
605 pHwData
->PowerIndexFromEEPROM
= (u8
)TxVga
;
606 pHwData
->VCO_trim
= (u8
)VCO_trim
& 0xff;
607 if (pHwData
->VCO_trim
== 0xff)
608 pHwData
->VCO_trim
= 0x28;
610 reg
->EEPROMRegion
= (u8
)(Region_ScanInterval
>> 8);
611 if (reg
->EEPROMRegion
< 1 || reg
->EEPROMRegion
> 6)
612 reg
->EEPROMRegion
= REGION_AUTO
;
614 /* For Get Tx VGA from EEPROM */
615 GetTxVgaFromEEPROM(pHwData
);
617 /* Set Scan Interval */
618 pHwData
->Scan_Interval
= (u8
)(Region_ScanInterval
& 0xff) * 10;
619 if ((pHwData
->Scan_Interval
== 2550) || (pHwData
->Scan_Interval
< 10)) /* Is default setting 0xff * 10 */
620 pHwData
->Scan_Interval
= SCAN_MAX_CHNL_TIME
;
622 /* Initial register */
623 RFSynthesizer_initial(pHwData
);
625 BBProcessor_initial(pHwData
); /* Async write, must wait until complete */
627 Wb35Reg_phy_calibration(pHwData
);
629 Mxx_initial(pHwData
);
630 Dxx_initial(pHwData
);
632 if (pHwData
->SurpriseRemove
)
635 return true; /* Initial fail */
639 * ================================================================
643 * Runs the AUTODIN II CRC algorithm on the buffers Buffer length.
646 * Buffer - the input buffer
647 * Length - the length of Buffer
650 * The 32-bit CRC value.
651 * ===================================================================
653 u32
CardComputeCrc(u8
*Buffer
, u32 Length
)
661 for (i
= 0; i
< Length
; i
++) {
663 for (j
= 0; j
< 8; j
++) {
664 Carry
= ((Crc
& 0x80000000) ? 1 : 0) ^ (CurByte
& 0x01);
668 Crc
= (Crc
^ 0x04c11db6) | Carry
;
676 * ==================================================================
678 * Reverse the bits in the input argument, dwData, which is
679 * regarded as a string of bits with the length, DataLength.
686 * The converted value.
687 * ==================================================================
689 u32
BitReverse(u32 dwData
, u32 DataLength
)
691 u32 HalfLength
, i
, j
;
695 return 0; /* No conversion is done. */
696 dwData
= dwData
& (0xffffffff >> (32 - DataLength
));
698 HalfLength
= DataLength
/ 2;
699 for (i
= 0, j
= DataLength
- 1; i
< HalfLength
; i
++, j
--) {
700 BitA
= GetBit(dwData
, i
);
701 BitB
= GetBit(dwData
, j
);
703 dwData
= ClearBit(dwData
, i
);
704 dwData
= SetBit(dwData
, j
);
705 } else if (!BitA
&& BitB
) {
706 dwData
= SetBit(dwData
, i
);
707 dwData
= ClearBit(dwData
, j
);
709 /* Do nothing since these two bits are of the save values. */
715 void Wb35Reg_phy_calibration(struct hw_data
*pHwData
)
719 if ((pHwData
->phy_type
== RF_WB_242
) ||
720 (pHwData
->phy_type
== RF_WB_242_1
)) {
721 phy_calibration_winbond(pHwData
, 2412); /* Sync operation */
722 Wb35Reg_ReadSync(pHwData
, 0x103c, &BB3c
);
723 Wb35Reg_ReadSync(pHwData
, 0x1054, &BB54
);
725 pHwData
->BB3c_cal
= BB3c
;
726 pHwData
->BB54_cal
= BB54
;
728 RFSynthesizer_initial(pHwData
);
729 BBProcessor_initial(pHwData
); /* Async operation */
731 Wb35Reg_WriteSync(pHwData
, 0x103c, BB3c
);
732 Wb35Reg_WriteSync(pHwData
, 0x1054, BB54
);