2 * Copyright (c) 2007-2008 Atheros Communications Inc.
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.
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.
16 #include "../80211core/cprecomp.h"
21 extern const u32_t zcFwImage[];
22 extern const u32_t zcFwImageSize;
23 extern const u32_t zcDKFwImage[];
24 extern const u32_t zcDKFwImageSize;
25 extern const u32_t zcFwImageSPI[];
26 extern const u32_t zcFwImageSPISize;
28 #ifdef ZM_OTUS_LINUX_PHASE_2
29 extern const u32_t zcFwBufImage[];
30 extern const u32_t zcFwBufImageSize;
31 extern const u32_t zcP2FwImage[];
32 extern const u32_t zcP2FwImageSize;
34 extern void zfInitCmdQueue(zdev_t* dev);
35 extern u16_t zfIssueCmd(zdev_t* dev, u32_t* cmd, u16_t cmdLen,
36 u16_t src, u8_t* buf);
37 extern void zfIdlRsp(zdev_t* dev, u32_t* rsp, u16_t rspLen);
38 extern u16_t zfDelayWriteInternalReg(zdev_t* dev, u32_t addr, u32_t val);
39 extern u16_t zfFlushDelayWrite(zdev_t* dev);
40 extern void zfUsbInit(zdev_t* dev);
41 extern u16_t zfFirmwareDownload(zdev_t* dev, u32_t* fw, u32_t len, u32_t offset);
42 extern u16_t zfFirmwareDownloadNotJump(zdev_t* dev, u32_t* fw, u32_t len, u32_t offset);
43 extern void zfUsbFree(zdev_t* dev);
44 extern u16_t zfCwmIsExtChanBusy(u32_t ctlBusy, u32_t extBusy);
45 extern void zfCoreCwmBusy(zdev_t* dev, u16_t busy);
48 void zfInitRf(zdev_t* dev, u32_t frequency);
49 void zfInitPhy(zdev_t* dev, u32_t frequency, u8_t bw40);
50 void zfInitMac(zdev_t* dev);
52 void zfSetPowerCalTable(zdev_t* dev, u32_t frequency, u8_t bw40, u8_t extOffset);
53 void zfInitPowerCal(zdev_t* dev);
55 #ifdef ZM_DRV_INIT_USB_MODE
56 void zfInitUsbMode(zdev_t* dev);
57 u16_t zfHpUsbReset(zdev_t* dev);
60 /* Bank 0 1 2 3 5 6 7 */
61 void zfSetRfRegs(zdev_t* dev, u32_t frequency);
63 void zfSetBank4AndPowerTable(zdev_t* dev, u32_t frequency, u8_t bw40,
65 /* Get param for turnoffdyn */
66 void zfGetHwTurnOffdynParam(zdev_t* dev,
67 u32_t frequency, u8_t bw40, u8_t extOffset,
68 int* delta_slope_coeff_exp,
69 int* delta_slope_coeff_man,
70 int* delta_slope_coeff_exp_shgi,
71 int* delta_slope_coeff_man_shgi);
73 void zfSelAdcClk(zdev_t* dev, u8_t bw40, u32_t frequency);
74 u32_t zfHpEchoCommand(zdev_t* dev, u32_t value);
78 #define zm_hp_priv(x) (((struct zsHpPriv*)wd->hpPrivate)->x)
79 struct zsHpPriv zgHpPriv;
81 #define ZM_FIRMWARE_WLAN_ADDR 0x200000
82 #define ZM_FIRMWARE_SPI_ADDR 0x114000
83 /* 0: real chip 1: FPGA test */
86 #define reg_write(addr, val) zfDelayWriteInternalReg(dev, addr+0x1bc000, val)
87 #define zm_min(A, B) ((A>B)? B:A)
90 /******************** Intialization ********************/
91 u16_t zfHpInit(zdev_t* dev, u32_t frequency)
94 zmw_get_wlan_dev(dev);
96 /* Initializa HAL Plus private variables */
97 wd->hpPrivate = &zgHpPriv;
99 ((struct zsHpPriv*)wd->hpPrivate)->halCapability = ZM_HP_CAP_11N;
101 ((struct zsHpPriv*)wd->hpPrivate)->hwFrequency = 0;
102 ((struct zsHpPriv*)wd->hpPrivate)->hwBw40 = 0;
103 ((struct zsHpPriv*)wd->hpPrivate)->hwExtOffset = 0;
105 ((struct zsHpPriv*)wd->hpPrivate)->disableDfsCh = 0;
107 ((struct zsHpPriv*)wd->hpPrivate)->ledMode[0] = 1;
108 ((struct zsHpPriv*)wd->hpPrivate)->ledMode[1] = 1;
109 ((struct zsHpPriv*)wd->hpPrivate)->strongRSSI = 0;
110 ((struct zsHpPriv*)wd->hpPrivate)->rxStrongRSSI = 0;
112 ((struct zsHpPriv*)wd->hpPrivate)->slotType = 1;
113 ((struct zsHpPriv*)wd->hpPrivate)->aggPktNum = 0x10000a;
115 ((struct zsHpPriv*)wd->hpPrivate)->eepromImageIndex = 0;
118 ((struct zsHpPriv*)wd->hpPrivate)->eepromImageRdReq = 0;
119 #ifdef ZM_OTUS_RX_STREAM_MODE
120 ((struct zsHpPriv*)wd->hpPrivate)->remainBuf = NULL;
121 ((struct zsHpPriv*)wd->hpPrivate)->usbRxRemainLen = 0;
122 ((struct zsHpPriv*)wd->hpPrivate)->usbRxPktLen = 0;
123 ((struct zsHpPriv*)wd->hpPrivate)->usbRxPadLen = 0;
124 ((struct zsHpPriv*)wd->hpPrivate)->usbRxTransferLen = 0;
127 ((struct zsHpPriv*)wd->hpPrivate)->enableBBHeavyClip = 1;
128 ((struct zsHpPriv*)wd->hpPrivate)->hwBBHeavyClip = 1; // force enable 8107
129 ((struct zsHpPriv*)wd->hpPrivate)->doBBHeavyClip = 0;
130 ((struct zsHpPriv*)wd->hpPrivate)->setValueHeavyClip = 0;
133 /* Initialize driver core */
139 #if ZM_SW_LOOP_BACK != 1
141 /* TODO : [Download FW] */
142 if (wd->modeMDKEnable)
144 /* download the MDK firmware */
145 if ((ret = zfFirmwareDownload(dev, (u32_t*)zcDKFwImage,
146 (u32_t)zcDKFwImageSize, ZM_FIRMWARE_WLAN_ADDR)) != ZM_SUCCESS)
148 /* TODO : exception handling */
154 #ifndef ZM_OTUS_LINUX_PHASE_2
155 /* donwload the normal frimware */
156 if ((ret = zfFirmwareDownload(dev, (u32_t*)zcFwImage,
157 (u32_t)zcFwImageSize, ZM_FIRMWARE_WLAN_ADDR)) != ZM_SUCCESS)
159 /* TODO : exception handling */
164 // 1-PH fw: ReadMac() store some global variable
165 if ((ret = zfFirmwareDownloadNotJump(dev, (u32_t*)zcFwBufImage,
166 (u32_t)zcFwBufImageSize, 0x102800)) != ZM_SUCCESS)
168 DbgPrint("Dl zcFwBufImage failed!");
173 if ((ret = zfFirmwareDownload(dev, (u32_t*)zcFwImage,
174 (u32_t)zcFwImageSize, ZM_FIRMWARE_WLAN_ADDR)) != ZM_SUCCESS)
176 DbgPrint("Dl zcFwBufImage failed!");
182 #ifdef ZM_DRV_INIT_USB_MODE
186 /* Do the USB Reset */
190 /* Register setting */
191 /* ZM_DRIVER_MODEL_TYPE_MDK
192 * 1=>for MDK, disable init RF, PHY, and MAC,
195 //#if ((ZM_SW_LOOP_BACK != 1) && (ZM_DRIVER_MODEL_TYPE_MDK !=1))
196 #if ZM_SW_LOOP_BACK != 1
197 if(!wd->modeMDKEnable)
202 #if ZM_FW_LOOP_BACK != 1
204 zfInitPhy(dev, frequency, 0);
207 zfInitRf(dev, frequency);
211 //zfDelayWriteInternalReg(dev, 0x9800+0x1bc000, 0x10000007);
212 //zfFlushDelayWrite(dev);
215 #endif /* end of ZM_FW_LOOP_BACK != 1 */
217 #endif /* end of ((ZM_SW_LOOP_BACK != 1) && (ZM_DRIVER_MODEL_TYPE_MDK !=1)) */
219 zfHpEchoCommand(dev, 0xAABBCCDD);
225 u16_t zfHpReinit(zdev_t* dev, u32_t frequency)
228 zmw_get_wlan_dev(dev);
230 ((struct zsHpPriv*)wd->hpPrivate)->halReInit = 1;
232 ((struct zsHpPriv*)wd->hpPrivate)->strongRSSI = 0;
233 ((struct zsHpPriv*)wd->hpPrivate)->rxStrongRSSI = 0;
235 #ifdef ZM_OTUS_RX_STREAM_MODE
236 if (((struct zsHpPriv*)wd->hpPrivate)->remainBuf != NULL)
238 zfwBufFree(dev, ((struct zsHpPriv*)wd->hpPrivate)->remainBuf, 0);
240 ((struct zsHpPriv*)wd->hpPrivate)->remainBuf = NULL;
241 ((struct zsHpPriv*)wd->hpPrivate)->usbRxRemainLen = 0;
242 ((struct zsHpPriv*)wd->hpPrivate)->usbRxPktLen = 0;
243 ((struct zsHpPriv*)wd->hpPrivate)->usbRxPadLen = 0;
244 ((struct zsHpPriv*)wd->hpPrivate)->usbRxTransferLen = 0;
250 #ifndef ZM_OTUS_LINUX_PHASE_2
251 /* Download firmware */
252 if ((ret = zfFirmwareDownload(dev, (u32_t*)zcFwImage,
253 (u32_t)zcFwImageSize, ZM_FIRMWARE_WLAN_ADDR)) != ZM_SUCCESS)
255 /* TODO : exception handling */
259 if ((ret = zfFirmwareDownload(dev, (u32_t*)zcP2FwImage,
260 (u32_t)zcP2FwImageSize, ZM_FIRMWARE_WLAN_ADDR)) != ZM_SUCCESS)
262 /* TODO : exception handling */
267 #ifdef ZM_DRV_INIT_USB_MODE
271 /* Do the USB Reset */
279 zfInitPhy(dev, frequency, 0);
281 zfInitRf(dev, frequency);
285 //zfDelayWriteInternalReg(dev, 0x9800+0x1bc000, 0x10000007);
286 //zfFlushDelayWrite(dev);
289 zfHpEchoCommand(dev, 0xAABBCCDD);
295 u16_t zfHpRelease(zdev_t* dev)
297 /* Free USB resource */
303 /* MDK mode setting for dontRetransmit */
304 void zfHpConfigFM(zdev_t* dev, u32_t RxMaxSize, u32_t DontRetransmit)
309 cmd[0] = 8 | (ZM_CMD_CONFIG << 8);
310 cmd[1] = RxMaxSize; /* zgRxMaxSize */
311 cmd[2] = DontRetransmit; /* zgDontRetransmit */
313 ret = zfIssueCmd(dev, cmd, 12, ZM_OID_INTERNAL_WRITE, 0);
316 const u8_t zcXpdToPd[16] =
318 /* 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xA, 0xB, 0xC, 0xD, 0xE, 0xF */
319 0x2, 0x2, 0x2, 0x1, 0x2, 0x2, 0x6, 0x2, 0x2, 0x3, 0x7, 0x2, 0xB, 0x2, 0x2, 0x2
322 /******************** RF and PHY ********************/
324 void zfInitPhy(zdev_t* dev, u32_t frequency, u8_t bw40)
328 u16_t modesIndex = 0;
331 zmw_get_wlan_dev(dev);
332 struct zsHpPriv* hpPriv=wd->hpPrivate;
333 u32_t eepromBoardData[15][6] = {
334 /* Register A-20 A-20/40 G-20/40 G-20 G-Turbo */
335 {0x9964, 0, 0, 0, 0, 0},
336 {0x9960, 0, 0, 0, 0, 0},
337 {0xb960, 0, 0, 0, 0, 0},
338 {0x9844, 0, 0, 0, 0, 0},
339 {0x9850, 0, 0, 0, 0, 0},
340 {0x9834, 0, 0, 0, 0, 0},
341 {0x9828, 0, 0, 0, 0, 0},
342 {0xc864, 0, 0, 0, 0, 0},
343 {0x9848, 0, 0, 0, 0, 0},
344 {0xb848, 0, 0, 0, 0, 0},
345 {0xa20c, 0, 0, 0, 0, 0},
346 {0xc20c, 0, 0, 0, 0, 0},
347 {0x9920, 0, 0, 0, 0, 0},
348 {0xb920, 0, 0, 0, 0, 0},
349 {0xa258, 0, 0, 0, 0, 0},
352 /* #1 Save the initial value of the related RIFS register settings */
353 //((struct zsHpPriv*)wd->hpPrivate)->isInitialPhy++;
356 * Setup the indices for the next set of register array writes
357 * PHY mode is static20 / 2040
358 * Frequency is 2.4GHz (B) / 5GHz (A)
360 if ( frequency > ZM_CH_G_14 )
367 zm_debug_msg0("init ar5416Modes in 2: A-20/40");
372 zm_debug_msg0("init ar5416Modes in 1: A-20");
382 zm_debug_msg0("init ar5416Modes in 3: G-20/40");
387 zm_debug_msg0("init ar5416Modes in 4: G-20");
393 /* Starting External Hainan Register Initialization */
400 *Set correct Baseband to analog shift setting to access analog chips.
402 //reg_write(PHY_BASE, 0x00000007);
403 // reg_write(0x9800, 0x00000007);
408 // do this in firmware
412 /* Zeroize board data */
417 eepromBoardData[j][k] = 0;
421 * Register setting by mode
424 entries = sizeof(ar5416Modes) / sizeof(*ar5416Modes);
425 zm_msg1_scan(ZM_LV_2, "Modes register setting entries=", entries);
426 for (i=0; i<entries; i++)
429 if ( ((struct zsHpPriv*)wd->hpPrivate)->hwNotFirstInit && (ar5416Modes[i][0] == 0xa27c) )
431 /* Force disable CR671 bit20 / 7823 */
432 /* The bug has to do with the polarity of the pdadc offset calibration. There */
433 /* is an initial calibration that is OK, and there is a continuous */
434 /* calibration that updates the pddac with the wrong polarity. Fortunately */
435 /* the second loop can be disabled with a bit called en_pd_dc_offset_thr. */
437 reg_write(ar5416Modes[i][0], (ar5416Modes[i][modesIndex]& 0xffefffff) );
438 ((struct zsHpPriv*)wd->hpPrivate)->hwNotFirstInit = 1;
443 /* FirstTime Init or not 0xa27c(CR671) */
444 reg_write(ar5416Modes[i][0], ar5416Modes[i][modesIndex]);
446 /* Initialize board data */
449 if (ar5416Modes[i][0] == eepromBoardData[j][0])
453 eepromBoardData[j][k] = ar5416Modes[i][k];
457 /* #1 Save the initial value of the related RIFS register settings */
458 //if( ((struct zsHpPriv*)wd->hpPrivate)->isInitialPhy == 1 )
460 switch(ar5416Modes[i][0])
463 ((struct zsHpPriv*)wd->hpPrivate)->initDesiredSigSize = ar5416Modes[i][modesIndex];
466 ((struct zsHpPriv*)wd->hpPrivate)->initAGC = ar5416Modes[i][modesIndex];
469 ((struct zsHpPriv*)wd->hpPrivate)->initAgcControl = ar5416Modes[i][modesIndex];
472 ((struct zsHpPriv*)wd->hpPrivate)->initSearchStartDelay = ar5416Modes[i][modesIndex];
475 ((struct zsHpPriv*)wd->hpPrivate)->initRIFSSearchParams = ar5416Modes[i][modesIndex];
478 ((struct zsHpPriv*)wd->hpPrivate)->initFastChannelChangeControl = ar5416Modes[i][modesIndex];
485 zfFlushDelayWrite(dev);
488 * Common Register setting
490 entries = sizeof(ar5416Common) / sizeof(*ar5416Common);
491 for (i=0; i<entries; i++)
493 reg_write(ar5416Common[i][0], ar5416Common[i][1]);
495 zfFlushDelayWrite(dev);
498 * RF Gain setting by freqIndex
500 entries = sizeof(ar5416BB_RfGain) / sizeof(*ar5416BB_RfGain);
501 for (i=0; i<entries; i++)
503 reg_write(ar5416BB_RfGain[i][0], ar5416BB_RfGain[i][freqIndex]);
505 zfFlushDelayWrite(dev);
508 * Moved ar5416InitChainMask() here to ensure the swap bit is set before
509 * the pdadc table is written. Swap must occur before any radio dependent
510 * replicated register access. The pdadc curve addressing in particular
511 * depends on the consistent setting of the swap bit.
513 //ar5416InitChainMask(pDev);
515 /* Setup the transmit power values. */
519 /* Update 5G board data */
521 tmp = hpPriv->eepromImage[0x100+0x144*2/4];
522 eepromBoardData[0][1] = tmp;
523 eepromBoardData[0][2] = tmp;
524 //Ant control chain 0
525 tmp = hpPriv->eepromImage[0x100+0x140*2/4];
526 eepromBoardData[1][1] = tmp;
527 eepromBoardData[1][2] = tmp;
528 //Ant control chain 2
529 tmp = hpPriv->eepromImage[0x100+0x142*2/4];
530 eepromBoardData[2][1] = tmp;
531 eepromBoardData[2][2] = tmp;
533 tmp = hpPriv->eepromImage[0x100+0x146*2/4];
534 tmp = (tmp >> 16) & 0x7f;
535 eepromBoardData[3][1] &= (~((u32_t)0x3f80));
536 eepromBoardData[3][1] |= (tmp << 7);
539 tmp = hpPriv->eepromImage[0x100+0x158*2/4];
541 eepromBoardData[3][2] &= (~((u32_t)0x3f80));
542 eepromBoardData[3][2] |= (tmp << 7);
544 //adcDesired, pdaDesired
545 tmp = hpPriv->eepromImage[0x100+0x148*2/4];
547 tmp1 = hpPriv->eepromImage[0x100+0x14a*2/4];
549 tmp = tmp + (tmp1<<8);
550 eepromBoardData[4][1] &= (~((u32_t)0xffff));
551 eepromBoardData[4][1] |= tmp;
552 eepromBoardData[4][2] &= (~((u32_t)0xffff));
553 eepromBoardData[4][2] |= tmp;
554 //TxEndToXpaOff, TxFrameToXpaOn
555 tmp = hpPriv->eepromImage[0x100+0x14a*2/4];
556 tmp = (tmp >> 24) & 0xff;
557 tmp1 = hpPriv->eepromImage[0x100+0x14c*2/4];
558 tmp1 = (tmp1 >> 8) & 0xff;
559 tmp = (tmp<<24) + (tmp<<16) + (tmp1<<8) + tmp1;
560 eepromBoardData[5][1] = tmp;
561 eepromBoardData[5][2] = tmp;
563 tmp = hpPriv->eepromImage[0x100+0x14c*2/4] & 0xff;
564 eepromBoardData[6][1] &= (~((u32_t)0xff0000));
565 eepromBoardData[6][1] |= (tmp<<16);
566 eepromBoardData[6][2] &= (~((u32_t)0xff0000));
567 eepromBoardData[6][2] |= (tmp<<16);
569 tmp = hpPriv->eepromImage[0x100+0x14c*2/4];
570 tmp = (tmp >> 16) & 0x7f;
571 eepromBoardData[7][1] &= (~((u32_t)0x7f000));
572 eepromBoardData[7][1] |= (tmp<<12);
573 eepromBoardData[7][2] &= (~((u32_t)0x7f000));
574 eepromBoardData[7][2] |= (tmp<<12);
576 tmp = hpPriv->eepromImage[0x100+0x146*2/4];
577 tmp = (tmp >> 24) & 0x3f;
578 eepromBoardData[8][1] &= (~((u32_t)0x3f000));
579 eepromBoardData[8][1] |= (tmp<<12);
580 eepromBoardData[8][2] &= (~((u32_t)0x3f000));
581 eepromBoardData[8][2] |= (tmp<<12);
583 tmp = hpPriv->eepromImage[0x100+0x148*2/4] & 0x3f;
584 eepromBoardData[9][1] &= (~((u32_t)0x3f000));
585 eepromBoardData[9][1] |= (tmp<<12);
586 eepromBoardData[9][2] &= (~((u32_t)0x3f000));
587 eepromBoardData[9][2] |= (tmp<<12);
589 tmp = hpPriv->eepromImage[0x100+0x148*2/4];
590 tmp = (tmp >> 8) & 0x3f;
591 eepromBoardData[10][1] &= (~((u32_t)0xfc0000));
592 eepromBoardData[10][1] |= (tmp<<18);
593 eepromBoardData[10][2] &= (~((u32_t)0xfc0000));
594 eepromBoardData[10][2] |= (tmp<<18);
596 tmp = hpPriv->eepromImage[0x100+0x148*2/4];
597 tmp = (tmp >> 16) & 0x3f;
598 eepromBoardData[11][1] &= (~((u32_t)0xfc0000));
599 eepromBoardData[11][1] |= (tmp<<18);
600 eepromBoardData[11][2] &= (~((u32_t)0xfc0000));
601 eepromBoardData[11][2] |= (tmp<<18);
602 //iqCall chain_0, iqCallQ chain_0
603 tmp = hpPriv->eepromImage[0x100+0x14e*2/4];
604 tmp = (tmp >> 24) & 0x3f;
605 tmp1 = hpPriv->eepromImage[0x100+0x150*2/4];
606 tmp1 = (tmp1 >> 8) & 0x1f;
607 tmp = (tmp<<5) + tmp1;
608 eepromBoardData[12][1] &= (~((u32_t)0x7ff));
609 eepromBoardData[12][1] |= (tmp);
610 eepromBoardData[12][2] &= (~((u32_t)0x7ff));
611 eepromBoardData[12][2] |= (tmp);
612 //iqCall chain_2, iqCallQ chain_2
613 tmp = hpPriv->eepromImage[0x100+0x150*2/4];
615 tmp1 = hpPriv->eepromImage[0x100+0x150*2/4];
616 tmp1 = (tmp1 >> 16) & 0x1f;
617 tmp = (tmp<<5) + tmp1;
618 eepromBoardData[13][1] &= (~((u32_t)0x7ff));
619 eepromBoardData[13][1] |= (tmp);
620 eepromBoardData[13][2] &= (~((u32_t)0x7ff));
621 eepromBoardData[13][2] |= (tmp);
623 tmp = hpPriv->eepromImage[0x100+0x156*2/4];
624 tmp = (tmp >> 16) & 0xf;
625 eepromBoardData[10][1] &= (~((u32_t)0x3c00));
626 eepromBoardData[10][1] |= (tmp << 10);
627 eepromBoardData[10][2] &= (~((u32_t)0x3c00));
628 eepromBoardData[10][2] |= (tmp << 10);
630 tmp = hpPriv->eepromImage[0x100+0x14e*2/4];
631 tmp = (tmp >> 8) & 0xf;
632 eepromBoardData[14][1] &= (~((u32_t)0xf0000));
633 eepromBoardData[14][1] |= (zcXpdToPd[tmp] << 16);
634 eepromBoardData[14][2] &= (~((u32_t)0xf0000));
635 eepromBoardData[14][2] |= (zcXpdToPd[tmp] << 16);
638 tmp = hpPriv->eepromImage[0x100+0x156*2/4];
640 eepromBoardData[10][1] &= (~((u32_t)0x1f));
641 eepromBoardData[10][1] |= (tmp);
642 eepromBoardData[10][2] &= (~((u32_t)0x1f));
643 eepromBoardData[10][2] |= (tmp);
645 tmp = hpPriv->eepromImage[0x100+0x156*2/4];
646 tmp = (tmp >> 24) & 0xf;
647 eepromBoardData[11][1] &= (~((u32_t)0x3c00));
648 eepromBoardData[11][1] |= (tmp << 10);
649 eepromBoardData[11][2] &= (~((u32_t)0x3c00));
650 eepromBoardData[11][2] |= (tmp << 10);
652 tmp = hpPriv->eepromImage[0x100+0x156*2/4];
653 tmp = (tmp >> 8) & 0x1f;
654 eepromBoardData[11][1] &= (~((u32_t)0x1f));
655 eepromBoardData[11][1] |= (tmp);
656 eepromBoardData[11][2] &= (~((u32_t)0x1f));
657 eepromBoardData[11][2] |= (tmp);
660 /* Update 2.4G board data */
662 tmp = hpPriv->eepromImage[0x100+0x170*2/4];
664 tmp1 = hpPriv->eepromImage[0x100+0x172*2/4];
665 tmp = tmp + (tmp1 << 8);
666 eepromBoardData[0][3] = tmp;
667 eepromBoardData[0][4] = tmp;
668 //Ant control chain 0
669 tmp = hpPriv->eepromImage[0x100+0x16c*2/4];
671 tmp1 = hpPriv->eepromImage[0x100+0x16e*2/4];
672 tmp = tmp + (tmp1 << 8);
673 eepromBoardData[1][3] = tmp;
674 eepromBoardData[1][4] = tmp;
675 //Ant control chain 2
676 tmp = hpPriv->eepromImage[0x100+0x16e*2/4];
678 tmp1 = hpPriv->eepromImage[0x100+0x170*2/4];
679 tmp = tmp + (tmp1 << 8);
680 eepromBoardData[2][3] = tmp;
681 eepromBoardData[2][4] = tmp;
683 tmp = hpPriv->eepromImage[0x100+0x174*2/4];
684 tmp = (tmp >> 8) & 0x7f;
685 eepromBoardData[3][4] &= (~((u32_t)0x3f80));
686 eepromBoardData[3][4] |= (tmp << 7);
689 tmp = hpPriv->eepromImage[0x100+0x184*2/4];
690 tmp = (tmp >> 24) & 0x7f;
691 eepromBoardData[3][3] &= (~((u32_t)0x3f80));
692 eepromBoardData[3][3] |= (tmp << 7);
694 //adcDesired, pdaDesired
695 tmp = hpPriv->eepromImage[0x100+0x176*2/4];
696 tmp = (tmp >> 16) & 0xff;
697 tmp1 = hpPriv->eepromImage[0x100+0x176*2/4];
699 tmp = tmp + (tmp1<<8);
700 eepromBoardData[4][3] &= (~((u32_t)0xffff));
701 eepromBoardData[4][3] |= tmp;
702 eepromBoardData[4][4] &= (~((u32_t)0xffff));
703 eepromBoardData[4][4] |= tmp;
704 //TxEndToXpaOff, TxFrameToXpaOn
705 tmp = hpPriv->eepromImage[0x100+0x178*2/4];
706 tmp = (tmp >> 16) & 0xff;
707 tmp1 = hpPriv->eepromImage[0x100+0x17a*2/4];
709 tmp = (tmp << 24) + (tmp << 16) + (tmp1 << 8) + tmp1;
710 eepromBoardData[5][3] = tmp;
711 eepromBoardData[5][4] = tmp;
713 tmp = hpPriv->eepromImage[0x100+0x178*2/4];
715 eepromBoardData[6][3] &= (~((u32_t)0xff0000));
716 eepromBoardData[6][3] |= (tmp<<16);
717 eepromBoardData[6][4] &= (~((u32_t)0xff0000));
718 eepromBoardData[6][4] |= (tmp<<16);
720 tmp = hpPriv->eepromImage[0x100+0x17a*2/4];
721 tmp = (tmp >> 8) & 0x7f;
722 eepromBoardData[7][3] &= (~((u32_t)0x7f000));
723 eepromBoardData[7][3] |= (tmp<<12);
724 eepromBoardData[7][4] &= (~((u32_t)0x7f000));
725 eepromBoardData[7][4] |= (tmp<<12);
727 tmp = hpPriv->eepromImage[0x100+0x174*2/4];
728 tmp = (tmp >> 16) & 0x3f;
729 eepromBoardData[8][3] &= (~((u32_t)0x3f000));
730 eepromBoardData[8][3] |= (tmp<<12);
731 eepromBoardData[8][4] &= (~((u32_t)0x3f000));
732 eepromBoardData[8][4] |= (tmp<<12);
734 tmp = hpPriv->eepromImage[0x100+0x174*2/4];
735 tmp = (tmp >> 24) & 0x3f;
736 eepromBoardData[9][3] &= (~((u32_t)0x3f000));
737 eepromBoardData[9][3] |= (tmp<<12);
738 eepromBoardData[9][4] &= (~((u32_t)0x3f000));
739 eepromBoardData[9][4] |= (tmp<<12);
741 tmp = hpPriv->eepromImage[0x100+0x176*2/4];
743 eepromBoardData[10][3] &= (~((u32_t)0xfc0000));
744 eepromBoardData[10][3] |= (tmp<<18);
745 eepromBoardData[10][4] &= (~((u32_t)0xfc0000));
746 eepromBoardData[10][4] |= (tmp<<18);
748 tmp = hpPriv->eepromImage[0x100+0x176*2/4];
749 tmp = (tmp >> 8) & 0x3f;
750 eepromBoardData[11][3] &= (~((u32_t)0xfc0000));
751 eepromBoardData[11][3] |= (tmp<<18);
752 eepromBoardData[11][4] &= (~((u32_t)0xfc0000));
753 eepromBoardData[11][4] |= (tmp<<18);
754 //iqCall chain_0, iqCallQ chain_0
755 tmp = hpPriv->eepromImage[0x100+0x17c*2/4];
756 tmp = (tmp >> 16) & 0x3f;
757 tmp1 = hpPriv->eepromImage[0x100+0x17e*2/4];
758 tmp1 = (tmp1) & 0x1f;
759 tmp = (tmp<<5) + tmp1;
760 eepromBoardData[12][3] &= (~((u32_t)0x7ff));
761 eepromBoardData[12][3] |= (tmp);
762 eepromBoardData[12][4] &= (~((u32_t)0x7ff));
763 eepromBoardData[12][4] |= (tmp);
764 //iqCall chain_2, iqCallQ chain_2
765 tmp = hpPriv->eepromImage[0x100+0x17c*2/4];
766 tmp = (tmp>>24) & 0x3f;
767 tmp1 = hpPriv->eepromImage[0x100+0x17e*2/4];
768 tmp1 = (tmp1 >> 8) & 0x1f;
769 tmp = (tmp<<5) + tmp1;
770 eepromBoardData[13][3] &= (~((u32_t)0x7ff));
771 eepromBoardData[13][3] |= (tmp);
772 eepromBoardData[13][4] &= (~((u32_t)0x7ff));
773 eepromBoardData[13][4] |= (tmp);
775 tmp = hpPriv->eepromImage[0x100+0x17c*2/4];
777 DbgPrint("xpd=0x%x, pd=0x%x\n", tmp, zcXpdToPd[tmp]);
778 eepromBoardData[14][3] &= (~((u32_t)0xf0000));
779 eepromBoardData[14][3] |= (zcXpdToPd[tmp] << 16);
780 eepromBoardData[14][4] &= (~((u32_t)0xf0000));
781 eepromBoardData[14][4] |= (zcXpdToPd[tmp] << 16);
784 tmp = hpPriv->eepromImage[0x100+0x184*2/4];
785 tmp = (tmp >> 8) & 0xf;
786 eepromBoardData[10][3] &= (~((u32_t)0x3c00));
787 eepromBoardData[10][3] |= (tmp << 10);
788 eepromBoardData[10][4] &= (~((u32_t)0x3c00));
789 eepromBoardData[10][4] |= (tmp << 10);
791 tmp = hpPriv->eepromImage[0x100+0x182*2/4];
792 tmp = (tmp>>24) & 0x1f;
793 eepromBoardData[10][3] &= (~((u32_t)0x1f));
794 eepromBoardData[10][3] |= (tmp);
795 eepromBoardData[10][4] &= (~((u32_t)0x1f));
796 eepromBoardData[10][4] |= (tmp);
798 tmp = hpPriv->eepromImage[0x100+0x184*2/4];
799 tmp = (tmp >> 16) & 0xf;
800 eepromBoardData[11][3] &= (~((u32_t)0x3c00));
801 eepromBoardData[11][3] |= (tmp << 10);
802 eepromBoardData[11][4] &= (~((u32_t)0x3c00));
803 eepromBoardData[11][4] |= (tmp << 10);
805 tmp = hpPriv->eepromImage[0x100+0x184*2/4];
807 eepromBoardData[11][3] &= (~((u32_t)0x1f));
808 eepromBoardData[11][3] |= (tmp);
809 eepromBoardData[11][4] &= (~((u32_t)0x1f));
810 eepromBoardData[11][4] |= (tmp);
816 DbgPrint("%04x, %08x, %08x, %08x, %08x\n", eepromBoardData[j][0], eepromBoardData[j][1], eepromBoardData[j][2], eepromBoardData[j][3], eepromBoardData[j][4]);
820 if ((hpPriv->eepromImage[0x100+0x110*2/4]&0xff) == 0x80) //FEM TYPE
822 /* Update board data to registers */
825 reg_write(eepromBoardData[j][0], eepromBoardData[j][modesIndex]);
827 /* #1 Save the initial value of the related RIFS register settings */
828 //if( ((struct zsHpPriv*)wd->hpPrivate)->isInitialPhy == 1 )
830 switch(eepromBoardData[j][0])
833 ((struct zsHpPriv*)wd->hpPrivate)->initDesiredSigSize = eepromBoardData[j][modesIndex];
836 ((struct zsHpPriv*)wd->hpPrivate)->initAGC = eepromBoardData[j][modesIndex];
839 ((struct zsHpPriv*)wd->hpPrivate)->initAgcControl = eepromBoardData[j][modesIndex];
842 ((struct zsHpPriv*)wd->hpPrivate)->initSearchStartDelay = eepromBoardData[j][modesIndex];
845 ((struct zsHpPriv*)wd->hpPrivate)->initRIFSSearchParams = eepromBoardData[j][modesIndex];
848 ((struct zsHpPriv*)wd->hpPrivate)->initFastChannelChangeControl = eepromBoardData[j][modesIndex];
854 } /* if ((hpPriv->eepromImage[0x100+0x110*2/4]&0xff) == 0x80) //FEM TYPE */
857 /* Bringup issue : force tx gain */
858 //reg_write(0xa258, 0x0cc65381);
859 //reg_write(0xa274, 0x0a1a7c15);
862 if(frequency > ZM_CH_G_14)
864 zfDelayWriteInternalReg(dev, 0x1d4014, 0x5143);
868 zfDelayWriteInternalReg(dev, 0x1d4014, 0x5163);
871 zfFlushDelayWrite(dev);
875 void zfInitRf(zdev_t* dev, u32_t frequency)
879 int delta_slope_coeff_exp;
880 int delta_slope_coeff_man;
881 int delta_slope_coeff_exp_shgi;
882 int delta_slope_coeff_man_shgi;
884 zmw_get_wlan_dev(dev);
886 zm_debug_msg1(" initRf frequency = ", frequency);
893 /* Bank 0 1 2 3 5 6 7 */
894 zfSetRfRegs(dev, frequency);
896 zfSetBank4AndPowerTable(dev, frequency, 0, 0);
898 /* stroe frequency */
899 ((struct zsHpPriv*)wd->hpPrivate)->hwFrequency = (u16_t)frequency;
901 zfGetHwTurnOffdynParam(dev,
903 &delta_slope_coeff_exp,
904 &delta_slope_coeff_man,
905 &delta_slope_coeff_exp_shgi,
906 &delta_slope_coeff_man_shgi);
908 /* related functions */
909 frequency = frequency*1000;
910 cmd[0] = 28 | (ZM_CMD_RF_INIT << 8);
912 cmd[2] = 0;//((struct zsHpPriv*)wd->hpPrivate)->hw_DYNAMIC_HT2040_EN;
913 cmd[3] = 1;//((wd->ExtOffset << 2) | ((struct zsHpPriv*)wd->hpPrivate)->hw_HT_ENABLE);
914 cmd[4] = delta_slope_coeff_exp;
915 cmd[5] = delta_slope_coeff_man;
916 cmd[6] = delta_slope_coeff_exp_shgi;
917 cmd[7] = delta_slope_coeff_man_shgi;
919 ret = zfIssueCmd(dev, cmd, 32, ZM_OID_INTERNAL_WRITE, 0);
921 // delay temporarily, wait for new PHY and RF
935 /*int zfFloor(double indata)
938 return (int)indata-1;
943 u32_t reverse_bits(u32_t chan_sel)
950 chansel |= ((chan_sel>>(7-i) & 0x1) << i);
954 /* Bank 0 1 2 3 5 6 7 */
955 void zfSetRfRegs(zdev_t* dev, u32_t frequency)
961 //zmw_get_wlan_dev(dev);
963 if ( frequency > ZM_CH_G_14 )
967 zm_msg0_scan(ZM_LV_2, "Set to 5GHz");
974 zm_msg0_scan(ZM_LV_2, "Set to 2.4GHz");
978 entries = sizeof(otusBank) / sizeof(*otusBank);
979 for (i=0; i<entries; i++)
981 reg_write(otusBank[i][0], otusBank[i][freqIndex]);
985 entries = sizeof(ar5416Bank0) / sizeof(*ar5416Bank0);
986 for (i=0; i<entries; i++)
988 reg_write(ar5416Bank0[i][0], ar5416Bank0[i][1]);
991 entries = sizeof(ar5416Bank1) / sizeof(*ar5416Bank1);
992 for (i=0; i<entries; i++)
994 reg_write(ar5416Bank1[i][0], ar5416Bank1[i][1]);
997 entries = sizeof(ar5416Bank2) / sizeof(*ar5416Bank2);
998 for (i=0; i<entries; i++)
1000 reg_write(ar5416Bank2[i][0], ar5416Bank2[i][1]);
1003 entries = sizeof(ar5416Bank3) / sizeof(*ar5416Bank3);
1004 for (i=0; i<entries; i++)
1006 reg_write(ar5416Bank3[i][0], ar5416Bank3[i][freqIndex]);
1009 reg_write (0x98b0, 0x00000013);
1010 reg_write (0x98e4, 0x00000002);
1012 entries = sizeof(ar5416Bank6) / sizeof(*ar5416Bank6);
1013 for (i=0; i<entries; i++)
1015 reg_write(ar5416Bank6[i][0], ar5416Bank6[i][freqIndex]);
1018 entries = sizeof(ar5416Bank7) / sizeof(*ar5416Bank7);
1019 for (i=0; i<entries; i++)
1021 reg_write(ar5416Bank7[i][0], ar5416Bank7[i][1]);
1025 zfFlushDelayWrite(dev);
1029 void zfSetBank4AndPowerTable(zdev_t* dev, u32_t frequency, u8_t bw40,
1033 u32_t bmode_LF_synth_freq = 0;
1034 u32_t amode_refsel_1 = 0;
1035 u32_t amode_refsel_0 = 1;
1049 u32_t temp_chan_sel;
1053 zmw_get_wlan_dev(dev);
1056 /* if enable 802.11h, need to record curent channel index in channel array */
1057 if (wd->sta.DFSEnable)
1059 for (i = 0; i < wd->regulationTable.allowChannelCnt; i++)
1061 if (wd->regulationTable.allowChannel[i].channel == frequency)
1064 wd->regulationTable.CurChIndex = i;
1081 if ( frequency > 3000 )
1083 if ( frequency % 10 )
1086 chan_sel = (u8_t)((frequency - 4800)/5);
1087 chan_sel = (u8_t)(chan_sel & 0xff);
1088 chansel = (u8_t)reverse_bits(chan_sel);
1092 /* 10M : improve Tx EVM */
1093 chan_sel = (u8_t)((frequency - 4800)/10);
1094 chan_sel = (u8_t)(chan_sel & 0xff)<<1;
1095 chansel = (u8_t)reverse_bits(chan_sel);
1103 //temp_chan_sel = (((frequency - 672)*2) - 3040)/10;
1104 if (frequency == 2484)
1106 temp_chan_sel = 10 + (frequency - 2274)/5 ;
1107 bmode_LF_synth_freq = 1;
1111 temp_chan_sel = 16 + (frequency - 2272)/5 ;
1112 bmode_LF_synth_freq = 0;
1114 chan_sel = (u8_t)(temp_chan_sel << 2) & 0xff;
1115 chansel = (u8_t)reverse_bits(chan_sel);
1118 d1 = chansel; //# 8 bits of chan
1119 d0 = addr0<<7 | addr1<<6 | addr2<<5
1120 | amode_refsel_0<<3 | amode_refsel_1<<2
1121 | bmode_LF_synth_freq<<1 | chup;
1123 tmp_0 = d0 & 0x1f; //# 5-1
1124 tmp_1 = d1 & 0x1f; //# 5-1
1125 data0 = tmp_1<<5 | tmp_0;
1127 tmp_0 = d0>>5 & 0x7; //# 8-6
1128 tmp_1 = d1>>5 & 0x7; //# 8-6
1129 data1 = tmp_1<<5 | tmp_0;
1132 reg_write (0x9800+(0x2c<<2), data0);
1133 reg_write (0x9800+(0x3a<<2), data1);
1134 //zm_debug_msg1("0x9800+(0x2c<<2 = ", data0);
1135 //zm_debug_msg1("0x9800+(0x3a<<2 = ", data1);
1138 zfFlushDelayWrite(dev);
1146 struct zsPhyFreqPara
1150 u32_t coeff_exp_shgi;
1151 u32_t coeff_man_shgi;
1154 struct zsPhyFreqTable
1157 struct zsPhyFreqPara FpgaDynamicHT;
1158 struct zsPhyFreqPara FpgaStaticHT;
1159 struct zsPhyFreqPara ChipST20Mhz;
1160 struct zsPhyFreqPara Chip2040Mhz;
1161 struct zsPhyFreqPara Chip2040ExtAbove;
1164 const struct zsPhyFreqTable zgPhyFreqCoeff[] =
1166 /*Index freq FPGA DYNAMIC_HT2040_EN FPGA STATIC_HT20 Real Chip static20MHz Real Chip 2040MHz Real Chip 2040Mhz */
1167 /* fclk = 10.8 21.6 40 ext below 40 ext above 40 */
1168 /* 0 */ {2412, {5, 23476, 5, 21128}, {4, 23476, 4, 21128}, {3, 21737, 3, 19563}, {3, 21827, 3, 19644}, {3, 21647, 3, 19482}},
1169 /* 1 */ {2417, {5, 23427, 5, 21084}, {4, 23427, 4, 21084}, {3, 21692, 3, 19523}, {3, 21782, 3, 19604}, {3, 21602, 3, 19442}},
1170 /* 2 */ {2422, {5, 23379, 5, 21041}, {4, 23379, 4, 21041}, {3, 21647, 3, 19482}, {3, 21737, 3, 19563}, {3, 21558, 3, 19402}},
1171 /* 3 */ {2427, {5, 23330, 5, 20997}, {4, 23330, 4, 20997}, {3, 21602, 3, 19442}, {3, 21692, 3, 19523}, {3, 21514, 3, 19362}},
1172 /* 4 */ {2432, {5, 23283, 5, 20954}, {4, 23283, 4, 20954}, {3, 21558, 3, 19402}, {3, 21647, 3, 19482}, {3, 21470, 3, 19323}},
1173 /* 5 */ {2437, {5, 23235, 5, 20911}, {4, 23235, 4, 20911}, {3, 21514, 3, 19362}, {3, 21602, 3, 19442}, {3, 21426, 3, 19283}},
1174 /* 6 */ {2442, {5, 23187, 5, 20868}, {4, 23187, 4, 20868}, {3, 21470, 3, 19323}, {3, 21558, 3, 19402}, {3, 21382, 3, 19244}},
1175 /* 7 */ {2447, {5, 23140, 5, 20826}, {4, 23140, 4, 20826}, {3, 21426, 3, 19283}, {3, 21514, 3, 19362}, {3, 21339, 3, 19205}},
1176 /* 8 */ {2452, {5, 23093, 5, 20783}, {4, 23093, 4, 20783}, {3, 21382, 3, 19244}, {3, 21470, 3, 19323}, {3, 21295, 3, 19166}},
1177 /* 9 */ {2457, {5, 23046, 5, 20741}, {4, 23046, 4, 20741}, {3, 21339, 3, 19205}, {3, 21426, 3, 19283}, {3, 21252, 3, 19127}},
1178 /* 10 */ {2462, {5, 22999, 5, 20699}, {4, 22999, 4, 20699}, {3, 21295, 3, 19166}, {3, 21382, 3, 19244}, {3, 21209, 3, 19088}},
1179 /* 11 */ {2467, {5, 22952, 5, 20657}, {4, 22952, 4, 20657}, {3, 21252, 3, 19127}, {3, 21339, 3, 19205}, {3, 21166, 3, 19050}},
1180 /* 12 */ {2472, {5, 22906, 5, 20615}, {4, 22906, 4, 20615}, {3, 21209, 3, 19088}, {3, 21295, 3, 19166}, {3, 21124, 3, 19011}},
1181 /* 13 */ {2484, {5, 22795, 5, 20516}, {4, 22795, 4, 20516}, {3, 21107, 3, 18996}, {3, 21192, 3, 19073}, {3, 21022, 3, 18920}},
1182 /* 14 */ {4920, {6, 23018, 6, 20716}, {5, 23018, 5, 20716}, {4, 21313, 4, 19181}, {4, 21356, 4, 19220}, {4, 21269, 4, 19142}},
1183 /* 15 */ {4940, {6, 22924, 6, 20632}, {5, 22924, 5, 20632}, {4, 21226, 4, 19104}, {4, 21269, 4, 19142}, {4, 21183, 4, 19065}},
1184 /* 16 */ {4960, {6, 22832, 6, 20549}, {5, 22832, 5, 20549}, {4, 21141, 4, 19027}, {4, 21183, 4, 19065}, {4, 21098, 4, 18988}},
1185 /* 17 */ {4980, {6, 22740, 6, 20466}, {5, 22740, 5, 20466}, {4, 21056, 4, 18950}, {4, 21098, 4, 18988}, {4, 21014, 4, 18912}},
1186 /* 18 */ {5040, {6, 22469, 6, 20223}, {5, 22469, 5, 20223}, {4, 20805, 4, 18725}, {4, 20846, 4, 18762}, {4, 20764, 4, 18687}},
1187 /* 19 */ {5060, {6, 22381, 6, 20143}, {5, 22381, 5, 20143}, {4, 20723, 4, 18651}, {4, 20764, 4, 18687}, {4, 20682, 4, 18614}},
1188 /* 20 */ {5080, {6, 22293, 6, 20063}, {5, 22293, 5, 20063}, {4, 20641, 4, 18577}, {4, 20682, 4, 18614}, {4, 20601, 4, 18541}},
1189 /* 21 */ {5180, {6, 21862, 6, 19676}, {5, 21862, 5, 19676}, {4, 20243, 4, 18219}, {4, 20282, 4, 18254}, {4, 20204, 4, 18183}},
1190 /* 22 */ {5200, {6, 21778, 6, 19600}, {5, 21778, 5, 19600}, {4, 20165, 4, 18148}, {4, 20204, 4, 18183}, {4, 20126, 4, 18114}},
1191 /* 23 */ {5220, {6, 21695, 6, 19525}, {5, 21695, 5, 19525}, {4, 20088, 4, 18079}, {4, 20126, 4, 18114}, {4, 20049, 4, 18044}},
1192 /* 24 */ {5240, {6, 21612, 6, 19451}, {5, 21612, 5, 19451}, {4, 20011, 4, 18010}, {4, 20049, 4, 18044}, {4, 19973, 4, 17976}},
1193 /* 25 */ {5260, {6, 21530, 6, 19377}, {5, 21530, 5, 19377}, {4, 19935, 4, 17941}, {4, 19973, 4, 17976}, {4, 19897, 4, 17907}},
1194 /* 26 */ {5280, {6, 21448, 6, 19303}, {5, 21448, 5, 19303}, {4, 19859, 4, 17873}, {4, 19897, 4, 17907}, {4, 19822, 4, 17840}},
1195 /* 27 */ {5300, {6, 21367, 6, 19230}, {5, 21367, 5, 19230}, {4, 19784, 4, 17806}, {4, 19822, 4, 17840}, {4, 19747, 4, 17772}},
1196 /* 28 */ {5320, {6, 21287, 6, 19158}, {5, 21287, 5, 19158}, {4, 19710, 4, 17739}, {4, 19747, 4, 17772}, {4, 19673, 4, 17706}},
1197 /* 29 */ {5500, {6, 20590, 6, 18531}, {5, 20590, 5, 18531}, {4, 19065, 4, 17159}, {4, 19100, 4, 17190}, {4, 19030, 4, 17127}},
1198 /* 30 */ {5520, {6, 20516, 6, 18464}, {5, 20516, 5, 18464}, {4, 18996, 4, 17096}, {4, 19030, 4, 17127}, {4, 18962, 4, 17065}},
1199 /* 31 */ {5540, {6, 20442, 6, 18397}, {5, 20442, 5, 18397}, {4, 18927, 4, 17035}, {4, 18962, 4, 17065}, {4, 18893, 4, 17004}},
1200 /* 32 */ {5560, {6, 20368, 6, 18331}, {5, 20368, 5, 18331}, {4, 18859, 4, 16973}, {4, 18893, 4, 17004}, {4, 18825, 4, 16943}},
1201 /* 33 */ {5580, {6, 20295, 6, 18266}, {5, 20295, 5, 18266}, {4, 18792, 4, 16913}, {4, 18825, 4, 16943}, {4, 18758, 4, 16882}},
1202 /* 34 */ {5600, {6, 20223, 6, 18200}, {5, 20223, 5, 18200}, {4, 18725, 4, 16852}, {4, 18758, 4, 16882}, {4, 18691, 4, 16822}},
1203 /* 35 */ {5620, {6, 20151, 6, 18136}, {5, 20151, 5, 18136}, {4, 18658, 4, 16792}, {4, 18691, 4, 16822}, {4, 18625, 4, 16762}},
1204 /* 36 */ {5640, {6, 20079, 6, 18071}, {5, 20079, 5, 18071}, {4, 18592, 4, 16733}, {4, 18625, 4, 16762}, {4, 18559, 4, 16703}},
1205 /* 37 */ {5660, {6, 20008, 6, 18007}, {5, 20008, 5, 18007}, {4, 18526, 4, 16673}, {4, 18559, 4, 16703}, {4, 18493, 4, 16644}},
1206 /* 38 */ {5680, {6, 19938, 6, 17944}, {5, 19938, 5, 17944}, {4, 18461, 4, 16615}, {4, 18493, 4, 16644}, {4, 18428, 4, 16586}},
1207 /* 39 */ {5700, {6, 19868, 6, 17881}, {5, 19868, 5, 17881}, {4, 18396, 4, 16556}, {4, 18428, 4, 16586}, {4, 18364, 4, 16527}},
1208 /* 40 */ {5745, {6, 19712, 6, 17741}, {5, 19712, 5, 17741}, {4, 18252, 4, 16427}, {4, 18284, 4, 16455}, {4, 18220, 4, 16398}},
1209 /* 41 */ {5765, {6, 19644, 6, 17679}, {5, 19644, 5, 17679}, {4, 18189, 5, 32740}, {4, 18220, 4, 16398}, {4, 18157, 5, 32683}},
1210 /* 42 */ {5785, {6, 19576, 6, 17618}, {5, 19576, 5, 17618}, {4, 18126, 5, 32626}, {4, 18157, 5, 32683}, {4, 18094, 5, 32570}},
1211 /* 43 */ {5805, {6, 19508, 6, 17558}, {5, 19508, 5, 17558}, {4, 18063, 5, 32514}, {4, 18094, 5, 32570}, {4, 18032, 5, 32458}},
1212 /* 44 */ {5825, {6, 19441, 6, 17497}, {5, 19441, 5, 17497}, {4, 18001, 5, 32402}, {4, 18032, 5, 32458}, {4, 17970, 5, 32347}},
1213 /* 45 */ {5170, {6, 21904, 6, 19714}, {5, 21904, 5, 19714}, {4, 20282, 4, 18254}, {4, 20321, 4, 18289}, {4, 20243, 4, 18219}},
1214 /* 46 */ {5190, {6, 21820, 6, 19638}, {5, 21820, 5, 19638}, {4, 20204, 4, 18183}, {4, 20243, 4, 18219}, {4, 20165, 4, 18148}},
1215 /* 47 */ {5210, {6, 21736, 6, 19563}, {5, 21736, 5, 19563}, {4, 20126, 4, 18114}, {4, 20165, 4, 18148}, {4, 20088, 4, 18079}},
1216 /* 48 */ {5230, {6, 21653, 6, 19488}, {5, 21653, 5, 19488}, {4, 20049, 4, 18044}, {4, 20088, 4, 18079}, {4, 20011, 4, 18010}}
1218 /* to reduce search time, please modify this define if you add or delete channel in table */
1219 #define First5GChannelIndex 14
1221 void zfGetHwTurnOffdynParam(zdev_t* dev,
1222 u32_t frequency, u8_t bw40, u8_t extOffset,
1223 int* delta_slope_coeff_exp,
1224 int* delta_slope_coeff_man,
1225 int* delta_slope_coeff_exp_shgi,
1226 int* delta_slope_coeff_man_shgi)
1228 /* Get param for turnoffdyn */
1231 //zmw_get_wlan_dev(dev);
1233 arraySize = sizeof(zgPhyFreqCoeff)/sizeof(struct zsPhyFreqTable);
1234 if (frequency < 3000)
1236 /* 2.4GHz Channel */
1237 for (i = 0; i < First5GChannelIndex; i++)
1239 if (frequency == zgPhyFreqCoeff[i].frequency)
1243 if (i < First5GChannelIndex)
1248 zm_msg1_scan(ZM_LV_0, "Unsupported 2.4G frequency = ", frequency);
1255 for (i = First5GChannelIndex; i < arraySize; i++)
1257 if (frequency == zgPhyFreqCoeff[i].frequency)
1266 zm_msg1_scan(ZM_LV_0, "Unsupported 5G frequency = ", frequency);
1271 /* FPGA DYNAMIC_HT2040_EN fclk = 10.8 */
1272 /* FPGA STATIC_HT20_ fclk = 21.6 */
1273 /* Real Chip fclk = 40 */
1274 #if ZM_FPGA_PHY == 1
1276 *delta_slope_coeff_exp = zgPhyFreqCoeff[i].FpgaDynamicHT.coeff_exp;
1277 *delta_slope_coeff_man = zgPhyFreqCoeff[i].FpgaDynamicHT.coeff_man;
1278 *delta_slope_coeff_exp_shgi = zgPhyFreqCoeff[i].FpgaDynamicHT.coeff_exp_shgi;
1279 *delta_slope_coeff_man_shgi = zgPhyFreqCoeff[i].FpgaDynamicHT.coeff_man_shgi;
1285 if (extOffset == 1) {
1286 *delta_slope_coeff_exp = zgPhyFreqCoeff[i].Chip2040ExtAbove.coeff_exp;
1287 *delta_slope_coeff_man = zgPhyFreqCoeff[i].Chip2040ExtAbove.coeff_man;
1288 *delta_slope_coeff_exp_shgi = zgPhyFreqCoeff[i].Chip2040ExtAbove.coeff_exp_shgi;
1289 *delta_slope_coeff_man_shgi = zgPhyFreqCoeff[i].Chip2040ExtAbove.coeff_man_shgi;
1292 *delta_slope_coeff_exp = zgPhyFreqCoeff[i].Chip2040Mhz.coeff_exp;
1293 *delta_slope_coeff_man = zgPhyFreqCoeff[i].Chip2040Mhz.coeff_man;
1294 *delta_slope_coeff_exp_shgi = zgPhyFreqCoeff[i].Chip2040Mhz.coeff_exp_shgi;
1295 *delta_slope_coeff_man_shgi = zgPhyFreqCoeff[i].Chip2040Mhz.coeff_man_shgi;
1301 *delta_slope_coeff_exp = zgPhyFreqCoeff[i].ChipST20Mhz.coeff_exp;
1302 *delta_slope_coeff_man = zgPhyFreqCoeff[i].ChipST20Mhz.coeff_man;
1303 *delta_slope_coeff_exp_shgi = zgPhyFreqCoeff[i].ChipST20Mhz.coeff_exp_shgi;
1304 *delta_slope_coeff_man_shgi = zgPhyFreqCoeff[i].ChipST20Mhz.coeff_man_shgi;
1309 /* Main routin frequency setting function */
1310 /* If 2.4G/5G switch, PHY need resetting BB and RF for band switch */
1311 /* Do the setting switch in zfSendFrequencyCmd() */
1312 void zfHpSetFrequencyEx(zdev_t* dev, u32_t frequency, u8_t bw40,
1313 u8_t extOffset, u8_t initRF)
1320 u32_t checkLoopCount;
1323 int delta_slope_coeff_exp;
1324 int delta_slope_coeff_man;
1325 int delta_slope_coeff_exp_shgi;
1326 int delta_slope_coeff_man_shgi;
1328 zmw_get_wlan_dev(dev);
1329 struct zsHpPriv* hpPriv = wd->hpPrivate;
1331 zm_msg1_scan(ZM_LV_1, "Frequency = ", frequency);
1332 zm_msg1_scan(ZM_LV_1, "bw40 = ", bw40);
1333 zm_msg1_scan(ZM_LV_1, "extOffset = ", extOffset);
1335 if ( hpPriv->coldResetNeedFreq )
1337 hpPriv->coldResetNeedFreq = 0;
1339 zm_debug_msg0("zfHpSetFrequencyEx: Do ColdReset ");
1341 if ( hpPriv->isSiteSurvey == 2 )
1343 /* wait time for AGC and noise calibration : not in sitesurvey and connected */
1344 checkLoopCount = 2000; /* 2000*100 = 200ms */
1348 /* wait time for AGC and noise calibration : in sitesurvey */
1349 checkLoopCount = 1000; /* 1000*100 = 100ms */
1352 hpPriv->latestFrequency = frequency;
1353 hpPriv->latestBw40 = bw40;
1354 hpPriv->latestExtOffset = extOffset;
1356 if ((hpPriv->dot11Mode == ZM_HAL_80211_MODE_IBSS_GENERAL) ||
1357 (hpPriv->dot11Mode == ZM_HAL_80211_MODE_IBSS_WPA2PSK))
1359 if ( frequency <= ZM_CH_G_14 )
1361 /* workaround for 11g Ad Hoc beacon distribution */
1362 zfDelayWriteInternalReg(dev, ZM_MAC_REG_AC0_CW, 0x7f0007);
1363 //zfDelayWriteInternalReg(dev, ZM_MAC_REG_AC1_AC0_AIFS, 0x1c04901c);
1367 /* AHB, DAC, ADC clock selection by static20/ht2040 */
1368 zfSelAdcClk(dev, bw40, frequency);
1370 /* clear bb_heavy_clip_enable */
1371 reg_write(0x99e0, 0x200);
1372 zfFlushDelayWrite(dev);
1374 /* Set CTS/RTS rate */
1375 if ( frequency > ZM_CH_G_14 )
1377 //zfHpSetRTSCTSRate(dev, 0x10b010b); /* OFDM 6M */
1382 //zfHpSetRTSCTSRate(dev, 0x30003); /* CCK 11M */
1386 if (((struct zsHpPriv*)wd->hpPrivate)->hwFrequency > ZM_CH_G_14)
1391 //Workaround for 2.4GHz only device
1392 if ((hpPriv->OpFlags & 0x1) == 0)
1394 if ((((struct zsHpPriv*)wd->hpPrivate)->hwFrequency == ZM_CH_G_1) && (frequency == ZM_CH_G_2))
1396 /* Force to do band switching */
1401 /* Notify channel switch to firmware */
1402 /* TX/RX must be stopped by now */
1403 cmd[0] = 0 | (ZM_CMD_FREQ_STRAT << 8);
1404 ret = zfIssueCmd(dev, cmd, 8, ZM_OID_INTERNAL_WRITE, 0);
1406 if ((initRF != 0) || (new_band != old_band)
1407 || (((struct zsHpPriv*)wd->hpPrivate)->hwBw40 != bw40))
1410 zm_msg0_scan(ZM_LV_1, "=====band switch=====");
1414 //Cold reset BB/ADDA
1415 zfDelayWriteInternalReg(dev, 0x1d4004, 0x800);
1416 zfFlushDelayWrite(dev);
1417 zm_msg0_scan(ZM_LV_1, "Do cold reset BB/ADDA");
1421 //Warm reset BB/ADDA
1422 zfDelayWriteInternalReg(dev, 0x1d4004, 0x400);
1423 zfFlushDelayWrite(dev);
1426 /* reset workaround state to default */
1427 hpPriv->rxStrongRSSI = 0;
1428 hpPriv->strongRSSI = 0;
1430 zfDelayWriteInternalReg(dev, 0x1d4004, 0x0);
1431 zfFlushDelayWrite(dev);
1433 zfInitPhy(dev, frequency, bw40);
1435 // zfiCheckRifs(dev);
1437 /* Bank 0 1 2 3 5 6 7 */
1438 zfSetRfRegs(dev, frequency);
1440 zfSetBank4AndPowerTable(dev, frequency, bw40, extOffset);
1442 cmd[0] = 32 | (ZM_CMD_RF_INIT << 8);
1444 else //((new_band == old_band) && !initRF)
1448 /* Force disable CR671 bit20 / 7823 */
1449 /* The bug has to do with the polarity of the pdadc offset calibration. There */
1450 /* is an initial calibration that is OK, and there is a continuous */
1451 /* calibration that updates the pddac with the wrong polarity. Fortunately */
1452 /* the second loop can be disabled with a bit called en_pd_dc_offset_thr. */
1454 cmdB[0] = 8 | (ZM_CMD_BITAND << 8);;
1455 cmdB[1] = (0xa27c + 0x1bc000);
1456 cmdB[2] = 0xffefffff;
1457 ret = zfIssueCmd(dev, cmdB, 12, ZM_OID_INTERNAL_WRITE, 0);
1461 zfSetBank4AndPowerTable(dev, frequency, bw40, extOffset);
1464 cmd[0] = 32 | (ZM_CMD_FREQUENCY << 8);
1467 /* Compatibility for new layout UB83 */
1468 /* Setting code at CR1 here move from the func:zfHwHTEnable() in firmware */
1469 if (((struct zsHpPriv*)wd->hpPrivate)->halCapability & ZM_HP_CAP_11N_ONE_TX_STREAM)
1471 /* UB83 : one stream */
1476 /* UB81, UB82 : two stream */
1480 if (1) //if (((struct zsHpPriv*)wd->hpPrivate)->hw_HT_ENABLE == 1)
1484 if (extOffset == 1) {
1485 reg_write(0x9804, tmpValue | 0x2d4); //3d4 for real
1488 reg_write(0x9804, tmpValue | 0x2c4); //3c4 for real
1490 //# Dyn HT2040.Refer to Reg 1.
1491 //#[3]:single length (4us) 1st HT long training symbol; use Walsh spatial spreading for 2 chains 2 streams TX
1492 //#[c]:allow short GI for HT40 packets; enable HT detection.
1493 //#[4]:enable 20/40 MHz channel detection.
1497 reg_write(0x9804, tmpValue | 0x240);
1499 //#[3]:single length (4us) 1st HT long training symbol; use Walsh spatial spreading for 2 chains 2 streams TX
1500 //#[4]:Otus don't allow short GI for HT20 packets yet; enable HT detection.
1501 //#[0]:disable 20/40 MHz channel detection.
1506 reg_write(0x9804, 0x0);
1507 //# Legacy;# Direct Mapping for each chain.
1508 //#Be modified by Oligo to add dynanic for legacy.
1511 reg_write(0x9804, 0x4); //# Dyn Legacy .Refer to reg 1.
1515 reg_write(0x9804, 0x0); //# Static Legacy
1518 zfFlushDelayWrite(dev);
1519 /* end of ub83 compatibility */
1521 /* Set Power, TPC, Gain table... */
1522 zfSetPowerCalTable(dev, frequency, bw40, extOffset);
1525 /* store frequency */
1526 ((struct zsHpPriv*)wd->hpPrivate)->hwFrequency = (u16_t)frequency;
1527 ((struct zsHpPriv*)wd->hpPrivate)->hwBw40 = bw40;
1528 ((struct zsHpPriv*)wd->hpPrivate)->hwExtOffset = extOffset;
1530 zfGetHwTurnOffdynParam(dev,
1531 frequency, bw40, extOffset,
1532 &delta_slope_coeff_exp,
1533 &delta_slope_coeff_man,
1534 &delta_slope_coeff_exp_shgi,
1535 &delta_slope_coeff_man_shgi);
1537 /* related functions */
1538 frequency = frequency*1000;
1539 /* len[36] : type[0x30] : seq[?] */
1540 // cmd[0] = 28 | (ZM_CMD_FREQUENCY << 8);
1542 cmd[2] = bw40;//((struct zsHpPriv*)wd->hpPrivate)->hw_DYNAMIC_HT2040_EN;
1543 cmd[3] = (extOffset<<2)|0x1;//((wd->ExtOffset << 2) | ((struct zsHpPriv*)wd->hpPrivate)->hw_HT_ENABLE);
1544 cmd[4] = delta_slope_coeff_exp;
1545 cmd[5] = delta_slope_coeff_man;
1546 cmd[6] = delta_slope_coeff_exp_shgi;
1547 cmd[7] = delta_slope_coeff_man_shgi;
1548 cmd[8] = checkLoopCount;
1550 ret = zfIssueCmd(dev, cmd, 36, ZM_CMD_SET_FREQUENCY, 0);
1552 // delay temporarily, wait for new PHY and RF
1553 //zfwSleep(dev, 1000);
1557 /******************** Key ********************/
1559 u16_t zfHpResetKeyCache(zdev_t* dev)
1562 u32_t key[4] = {0, 0, 0, 0};
1564 zmw_get_wlan_dev(dev);
1565 struct zsHpPriv* hpPriv=wd->hpPrivate;
1569 zfHpSetDefaultKey(dev, i, ZM_WEP64, key, NULL);
1571 zfDelayWriteInternalReg(dev, ZM_MAC_REG_ROLL_CALL_TBL_L, 0x00);
1572 zfDelayWriteInternalReg(dev, ZM_MAC_REG_ROLL_CALL_TBL_H, 0x00);
1573 zfFlushDelayWrite(dev);
1575 hpPriv->camRollCallTable = (u64_t) 0;
1581 /************************************************************************/
1583 /* FUNCTION DESCRIPTION zfSetKey */
1587 /* dev : device pointer */
1594 /* Stephen Chen ZyDAS Technology Corporation 2006.1 */
1596 /************************************************************************/
1597 /* ! please use zfCoreSetKey() in 80211Core for SetKey */
1598 u32_t zfHpSetKey(zdev_t* dev, u8_t user, u8_t keyId, u8_t type,
1599 u16_t* mac, u32_t* key)
1601 u32_t cmd[(ZM_MAX_CMD_SIZE/4)];
1605 zmw_get_wlan_dev(dev);
1606 struct zsHpPriv* hpPriv=wd->hpPrivate;
1608 #if 0 /* remove to zfCoreSetKey() */
1609 zmw_declare_for_critical_section();
1611 zmw_enter_critical_section(dev);
1612 wd->sta.flagKeyChanging++;
1613 zm_debug_msg1(" zfHpSetKey++++ ", wd->sta.flagKeyChanging);
1614 zmw_leave_critical_section(dev);
1617 cmd[0] = 0x0000281C;
1618 cmd[1] = ((u32_t)keyId<<16) + (u32_t)user;
1619 cmd[2] = ((u32_t)mac[0]<<16) + (u32_t)type;
1620 cmd[3] = ((u32_t)mac[2]<<16) + ((u32_t)mac[1]);
1629 hpPriv->camRollCallTable |= ((u64_t) 1) << user;
1632 //ret = zfIssueCmd(dev, cmd, 32, ZM_OID_INTERNAL_WRITE, NULL);
1633 ret = zfIssueCmd(dev, cmd, 32, ZM_CMD_SET_KEY, NULL);
1638 u32_t zfHpSetApPairwiseKey(zdev_t* dev, u16_t* staMacAddr, u8_t type,
1639 u32_t* key, u32_t* micKey, u16_t staAid)
1641 if ((staAid!=0) && (staAid<64))
1643 zfHpSetKey(dev, (staAid-1), 0, type, staMacAddr, key);
1644 if ((type == ZM_TKIP)
1645 #ifdef ZM_ENABLE_CENC
1646 || (type == ZM_CENC)
1647 #endif //ZM_ENABLE_CENC
1649 zfHpSetKey(dev, (staAid-1), 1, type, staMacAddr, micKey);
1655 u32_t zfHpSetApGroupKey(zdev_t* dev, u16_t* apMacAddr, u8_t type,
1656 u32_t* key, u32_t* micKey, u16_t vapId)
1658 zfHpSetKey(dev, ZM_USER_KEY_DEFAULT - 1 - vapId, 0, type, apMacAddr, key); // 6D18 modify from 0 to 1 ??
1659 if ((type == ZM_TKIP)
1660 #ifdef ZM_ENABLE_CENC
1661 || (type == ZM_CENC)
1662 #endif //ZM_ENABLE_CENC
1664 zfHpSetKey(dev, ZM_USER_KEY_DEFAULT - 1 - vapId, 1, type, apMacAddr, micKey);
1668 u32_t zfHpSetDefaultKey(zdev_t* dev, u8_t keyId, u8_t type, u32_t* key, u32_t* micKey)
1670 u16_t macAddr[3] = {0, 0, 0};
1672 #ifdef ZM_ENABLE_IBSS_WPA2PSK
1673 zmw_get_wlan_dev(dev);
1674 struct zsHpPriv* hpPriv = wd->hpPrivate;
1676 if ( hpPriv->dot11Mode == ZM_HAL_80211_MODE_IBSS_WPA2PSK )
1677 { /* If not wpa2psk , use traditional */
1678 /* Because the bug of chip , defaultkey should follow the key map rule in register 700 */
1680 zfHpSetKey(dev, ZM_USER_KEY_DEFAULT+keyId, 0, type, macAddr, key);
1682 zfHpSetKey(dev, ZM_USER_KEY_DEFAULT+keyId, 1, type, macAddr, key);
1685 zfHpSetKey(dev, ZM_USER_KEY_DEFAULT+keyId, 0, type, macAddr, key);
1687 zfHpSetKey(dev, ZM_USER_KEY_DEFAULT+keyId, 0, type, macAddr, key);
1689 if ((type == ZM_TKIP)
1691 #ifdef ZM_ENABLE_CENC
1692 || (type == ZM_CENC)
1693 #endif //ZM_ENABLE_CENC
1696 zfHpSetKey(dev, ZM_USER_KEY_DEFAULT+keyId, 1, type, macAddr, micKey);
1702 u32_t zfHpSetPerUserKey(zdev_t* dev, u8_t user, u8_t keyId, u8_t* mac, u8_t type, u32_t* key, u32_t* micKey)
1704 #ifdef ZM_ENABLE_IBSS_WPA2PSK
1705 zmw_get_wlan_dev(dev);
1706 struct zsHpPriv* hpPriv = wd->hpPrivate;
1708 if ( hpPriv->dot11Mode == ZM_HAL_80211_MODE_IBSS_WPA2PSK )
1709 { /* If not wpa2psk , use traditional */
1711 { /* Set Group Key */
1712 zfHpSetKey(dev, user, 1, type, (u16_t *)mac, key);
1715 { /* Set Pairwise Key */
1716 zfHpSetKey(dev, user, 0, type, (u16_t *)mac, key);
1721 zfHpSetKey(dev, user, keyId, type, (u16_t *)mac, key);
1724 zfHpSetKey(dev, user, keyId, type, (u16_t *)mac, key);
1727 if ((type == ZM_TKIP)
1728 #ifdef ZM_ENABLE_CENC
1729 || (type == ZM_CENC)
1730 #endif //ZM_ENABLE_CENC
1733 zfHpSetKey(dev, user, keyId + 1, type, (u16_t *)mac, micKey);
1738 /************************************************************************/
1740 /* FUNCTION DESCRIPTION zfHpRemoveKey */
1744 /* dev : device pointer */
1751 /* Yuan-Gu Wei ZyDAS Technology Corporation 2006.6 */
1753 /************************************************************************/
1754 u16_t zfHpRemoveKey(zdev_t* dev, u16_t user)
1756 u32_t cmd[(ZM_MAX_CMD_SIZE/4)];
1759 cmd[0] = 0x00002904;
1760 cmd[1] = (u32_t)user;
1762 ret = zfIssueCmd(dev, cmd, 8, ZM_OID_INTERNAL_WRITE, NULL);
1768 /******************** DMA ********************/
1769 u16_t zfHpStartRecv(zdev_t* dev)
1771 zfDelayWriteInternalReg(dev, 0x1c3d30, 0x100);
1772 zfFlushDelayWrite(dev);
1777 u16_t zfHpStopRecv(zdev_t* dev)
1783 /******************** MAC ********************/
1784 void zfInitMac(zdev_t* dev)
1786 /* ACK extension register */
1787 // jhlee temp : change value 0x2c -> 0x40
1788 // honda resolve short preamble problem : 0x40 -> 0x75
1789 zfDelayWriteInternalReg(dev, ZM_MAC_REG_ACK_EXTENSION, 0x40); // 0x28 -> 0x2c 6522:yflee
1791 /* TxQ0/1/2/3 Retry MAX=2 => transmit 3 times and degrade rate for retry */
1792 /* PB42 AP crash issue: */
1793 /* Workaround the crash issue by CTS/RTS, set retry max to zero for */
1794 /* workaround tx underrun which enable CTS/RTS */
1795 zfDelayWriteInternalReg(dev, ZM_MAC_REG_RETRY_MAX, 0); // 0x11111 => 0
1797 /* use hardware MIC check */
1798 zfDelayWriteInternalReg(dev, ZM_MAC_REG_SNIFFER, 0x2000000);
1800 /* Set Rx threshold to 1600 */
1801 #if ZM_LARGEPAYLOAD_TEST == 1
1802 zfDelayWriteInternalReg(dev, ZM_MAC_REG_RX_THRESHOLD, 0xc4000);
1804 #ifndef ZM_DISABLE_AMSDU8K_SUPPORT
1805 /* The maximum A-MSDU length is 3839/7935 */
1806 zfDelayWriteInternalReg(dev, ZM_MAC_REG_RX_THRESHOLD, 0xc1f80);
1808 zfDelayWriteInternalReg(dev, ZM_MAC_REG_RX_THRESHOLD, 0xc0f80);
1812 //zfDelayWriteInternalReg(dev, ZM_MAC_REG_DYNAMIC_SIFS_ACK, 0x10A);
1813 zfDelayWriteInternalReg(dev, ZM_MAC_REG_RX_PE_DELAY, 0x70);
1814 zfDelayWriteInternalReg(dev, ZM_MAC_REG_EIFS_AND_SIFS, 0xa144000);
1815 zfDelayWriteInternalReg(dev, ZM_MAC_REG_SLOT_TIME, 9<<10);
1818 zfDelayWriteInternalReg(dev, 0x1c3b2c, 0x19000000);
1820 //NAV protects ACK only (in TXOP)
1821 zfDelayWriteInternalReg(dev, 0x1c3b38, 0x201);
1824 /* Set Beacon PHY CTRL's TPC to 0x7, TA1=1 */
1825 /* OTUS set AM to 0x1 */
1826 zfDelayWriteInternalReg(dev, ZM_MAC_REG_BCN_HT1, 0x8000170);
1828 /* TODO : wep backoff protection 0x63c */
1829 zfDelayWriteInternalReg(dev, ZM_MAC_REG_BACKOFF_PROTECT, 0x105);
1832 /* Aggregation MAX number and timeout */
1833 zfDelayWriteInternalReg(dev, 0x1c3b9c, 0x10000a);
1834 /* Filter any control frames, BAR is bit 24 */
1835 zfDelayWriteInternalReg(dev, 0x1c368c, 0x0500ffff);
1836 /* Enable deaggregator */
1837 zfDelayWriteInternalReg(dev, 0x1c3c40, 0x1);
1840 zfDelayWriteInternalReg(dev, ZM_MAC_REG_BASIC_RATE, 0x150f);
1841 zfDelayWriteInternalReg(dev, ZM_MAC_REG_MANDATORY_RATE, 0x150f);
1842 zfDelayWriteInternalReg(dev, ZM_MAC_REG_RTS_CTS_RATE, 0x10b01bb);
1844 /* MIMO resposne control */
1845 zfDelayWriteInternalReg(dev, 0x1c3694, 0x4003C1E);/* bit 26~28 otus-AM */
1847 /* Enable LED0 and LED1 */
1848 zfDelayWriteInternalReg(dev, 0x1d0100, 0x3);
1849 zfDelayWriteInternalReg(dev, 0x1d0104, 0x3);
1851 /* switch MAC to OTUS interface */
1852 zfDelayWriteInternalReg(dev, 0x1c3600, 0x3);
1854 /* RXMAC A-MPDU length threshold */
1855 zfDelayWriteInternalReg(dev, 0x1c3c50, 0xffff);
1857 /* Phy register read timeout */
1858 zfDelayWriteInternalReg(dev, 0x1c3680, 0xf00008);
1860 /* Disable Rx TimeOut : workaround for BB.
1861 * OTUS would interrupt the rx frame that sent by OWL TxUnderRun
1862 * because OTUS rx timeout behavior, then OTUS would not ack the BA for
1863 * this AMPDU from OWL.
1864 * Fix by Perry Hwang. 2007/05/10.
1865 * 0x1c362c : Rx timeout value : bit 27~16
1867 zfDelayWriteInternalReg(dev, 0x1c362c, 0x0);
1869 //Set USB Rx stream mode MAX packet number to 2
1870 // Max packet number = *0x1e1110 + 1
1871 zfDelayWriteInternalReg(dev, 0x1e1110, 0x4);
1872 //Set USB Rx stream mode timeout to 10us
1873 zfDelayWriteInternalReg(dev, 0x1e1114, 0x80);
1875 //Set CPU clock frequency to 88/80MHz
1876 zfDelayWriteInternalReg(dev, 0x1D4008, 0x73);
1878 //Set WLAN DMA interrupt mode : generate int per packet
1879 zfDelayWriteInternalReg(dev, 0x1c3d7c, 0x110011);
1882 /* enable func : Reset FIFO1 and FIFO2 when queue-gnt is low */
1884 /* Disable SwReset in firmware for TxHang, enable reset FIFO func. */
1885 zfDelayWriteInternalReg(dev, 0x1c3bb0, 0x4);
1887 /* Disables the CF_END frame */
1888 zfDelayWriteInternalReg(dev, ZM_MAC_REG_TXOP_NOT_ENOUGH_INDICATION, 0x141E0F48);
1890 /* Disable the SW Decrypt*/
1891 zfDelayWriteInternalReg(dev, 0x1c3678, 0x70);
1892 zfFlushDelayWrite(dev);
1893 //---------------------
1895 /* Set TxQs CWMIN, CWMAX, AIFS and TXO to WME STA default. */
1896 zfUpdateDefaultQosParameter(dev, 0);
1898 //zfSelAdcClk(dev, 0);
1904 u16_t zfHpSetSnifferMode(zdev_t* dev, u16_t on)
1908 zfDelayWriteInternalReg(dev, ZM_MAC_REG_SNIFFER, 0x2000001);
1912 zfDelayWriteInternalReg(dev, ZM_MAC_REG_SNIFFER, 0x2000000);
1914 zfFlushDelayWrite(dev);
1919 u16_t zfHpSetApStaMode(zdev_t* dev, u8_t mode)
1921 zmw_get_wlan_dev(dev);
1923 struct zsHpPriv* hpPriv = wd->hpPrivate;
1924 hpPriv->dot11Mode = mode;
1928 case ZM_HAL_80211_MODE_AP:
1929 zfDelayWriteInternalReg(dev, 0x1c3700, 0x0f0000a1);
1930 zfDelayWriteInternalReg(dev, 0x1c3c40, 0x1);
1933 case ZM_HAL_80211_MODE_STA:
1934 zfDelayWriteInternalReg(dev, 0x1c3700, 0x0f000002);
1935 zfDelayWriteInternalReg(dev, 0x1c3c40, 0x1);
1938 case ZM_HAL_80211_MODE_IBSS_GENERAL:
1939 zfDelayWriteInternalReg(dev, 0x1c3700, 0x0f000000);
1940 zfDelayWriteInternalReg(dev, 0x1c3c40, 0x1);
1943 case ZM_HAL_80211_MODE_IBSS_WPA2PSK:
1944 zfDelayWriteInternalReg(dev, 0x1c3700, 0x0f0000e0);
1945 zfDelayWriteInternalReg(dev, 0x1c3c40, 0x41); // for multiple ( > 2 ) stations IBSS network
1952 zfFlushDelayWrite(dev);
1959 u16_t zfHpSetBssid(zdev_t* dev, u8_t* bssidSrc)
1962 u16_t *bssid = (u16_t *)bssidSrc;
1964 address = bssid[0] + (((u32_t)bssid[1]) << 16);
1965 zfDelayWriteInternalReg(dev, 0x1c3618, address);
1967 address = (u32_t)bssid[2];
1968 zfDelayWriteInternalReg(dev, 0x1c361C, address);
1969 zfFlushDelayWrite(dev);
1974 /************************************************************************/
1976 /* FUNCTION DESCRIPTION zfHpUpdateQosParameter */
1977 /* Update TxQs CWMIN, CWMAX, AIFS and TXOP. */
1980 /* dev : device pointer */
1981 /* cwminTbl : CWMIN parameter for TxQs */
1982 /* cwmaxTbl : CWMAX parameter for TxQs */
1983 /* aifsTbl: AIFS parameter for TxQs */
1984 /* txopTbl : TXOP parameter for TxQs */
1990 /* Stephen ZyDAS Technology Corporation 2006.6 */
1992 /************************************************************************/
1993 u8_t zfHpUpdateQosParameter(zdev_t* dev, u16_t* cwminTbl, u16_t* cwmaxTbl,
1994 u16_t* aifsTbl, u16_t* txopTbl)
1996 zmw_get_wlan_dev(dev);
1997 struct zsHpPriv* hpPriv = wd->hpPrivate;
1999 zm_msg0_mm(ZM_LV_0, "zfHalUpdateQosParameter()");
2001 /* Note : Do not change cwmin for Q0 in Ad Hoc mode */
2002 /* otherwise driver will fail in Wifi beacon distribution */
2003 if (hpPriv->dot11Mode == ZM_HAL_80211_MODE_STA)
2005 #if 0 //Restore CWmin to improve down link throughput
2006 //cheating in BE traffic
2007 if (wd->sta.EnableHT == 1)
2009 //cheating in BE traffic
2010 cwminTbl[0] = 7;//15;
2013 cwmaxTbl[0] = 127;//1023;
2014 aifsTbl[0] = 2*9+10;//3 * 9 + 10;
2017 /* CWMIN and CWMAX */
2018 zfDelayWriteInternalReg(dev, ZM_MAC_REG_AC0_CW, cwminTbl[0]
2019 + ((u32_t)cwmaxTbl[0]<<16));
2020 zfDelayWriteInternalReg(dev, ZM_MAC_REG_AC1_CW, cwminTbl[1]
2021 + ((u32_t)cwmaxTbl[1]<<16));
2022 zfDelayWriteInternalReg(dev, ZM_MAC_REG_AC2_CW, cwminTbl[2]
2023 + ((u32_t)cwmaxTbl[2]<<16));
2024 zfDelayWriteInternalReg(dev, ZM_MAC_REG_AC3_CW, cwminTbl[3]
2025 + ((u32_t)cwmaxTbl[3]<<16));
2026 zfDelayWriteInternalReg(dev, ZM_MAC_REG_AC4_CW, cwminTbl[4]
2027 + ((u32_t)cwmaxTbl[4]<<16));
2030 zfDelayWriteInternalReg(dev, ZM_MAC_REG_AC1_AC0_AIFS, aifsTbl[0]
2031 +((u32_t)aifsTbl[0]<<12)+((u32_t)aifsTbl[0]<<24));
2032 zfDelayWriteInternalReg(dev, ZM_MAC_REG_AC3_AC2_AIFS, (aifsTbl[0]>>8)
2033 +((u32_t)aifsTbl[0]<<4)+((u32_t)aifsTbl[0]<<16));
2036 zfDelayWriteInternalReg(dev, ZM_MAC_REG_AC1_AC0_TXOP, txopTbl[0]
2037 + ((u32_t)txopTbl[1]<<16));
2038 zfDelayWriteInternalReg(dev, ZM_MAC_REG_AC3_AC2_TXOP, txopTbl[2]
2039 + ((u32_t)txopTbl[3]<<16));
2041 zfFlushDelayWrite(dev);
2043 hpPriv->txop[0] = txopTbl[0];
2044 hpPriv->txop[1] = txopTbl[1];
2045 hpPriv->txop[2] = txopTbl[2];
2046 hpPriv->txop[3] = txopTbl[3];
2047 hpPriv->cwmin[0] = cwminTbl[0];
2048 hpPriv->cwmax[0] = cwmaxTbl[0];
2049 hpPriv->cwmin[1] = cwminTbl[1];
2050 hpPriv->cwmax[1] = cwmaxTbl[1];
2056 void zfHpSetAtimWindow(zdev_t* dev, u16_t atimWin)
2058 zm_msg1_mm(ZM_LV_0, "Set ATIM window to ", atimWin);
2059 zfDelayWriteInternalReg(dev, ZM_MAC_REG_ATIM_WINDOW, atimWin);
2060 zfFlushDelayWrite(dev);
2064 void zfHpSetBasicRateSet(zdev_t* dev, u16_t bRateBasic, u16_t gRateBasic)
2066 zfDelayWriteInternalReg(dev, ZM_MAC_REG_BASIC_RATE, bRateBasic
2067 | ((u16_t)gRateBasic<<8));
2068 zfFlushDelayWrite(dev);
2072 /* HT40 send by OFDM 6M */
2073 /* otherwise use reg 0x638 */
2074 void zfHpSetRTSCTSRate(zdev_t* dev, u32_t rate)
2076 zfDelayWriteInternalReg(dev, ZM_MAC_REG_RTS_CTS_RATE, rate);
2077 zfFlushDelayWrite(dev);
2080 void zfHpSetMacAddress(zdev_t* dev, u16_t* macAddr, u16_t macAddrId)
2084 zfDelayWriteInternalReg(dev, ZM_MAC_REG_MAC_ADDR_L,
2085 (((u32_t)macAddr[1])<<16) | macAddr[0]);
2086 zfDelayWriteInternalReg(dev, ZM_MAC_REG_MAC_ADDR_H, macAddr[2]);
2088 else if (macAddrId <= 7)
2090 zfDelayWriteInternalReg(dev, ZM_MAC_REG_ACK_TABLE+((macAddrId-1)*8),
2091 macAddr[0] + ((u32_t)macAddr[1]<<16));
2092 zfDelayWriteInternalReg(dev, ZM_MAC_REG_ACK_TABLE+((macAddrId-1)*8)+4,
2095 zfFlushDelayWrite(dev);
2098 void zfHpSetMulticastList(zdev_t* dev, u8_t size, u8_t* pList, u8_t bAllMulticast)
2100 struct zsMulticastAddr* pMacList = (struct zsMulticastAddr*) pList;
2103 u32_t swRegMulHashValueH, swRegMulHashValueL;
2105 swRegMulHashValueH = 0x80000000;
2106 swRegMulHashValueL = 0;
2108 if ( bAllMulticast )
2110 swRegMulHashValueH = swRegMulHashValueL = ~0;
2114 for(i=0; i<size; i++)
2116 value = pMacList[i].addr[5] >> 2;
2120 swRegMulHashValueL |= (1 << value);
2124 swRegMulHashValueH |= (1 << (value-32));
2129 zfDelayWriteInternalReg(dev, ZM_MAC_REG_GROUP_HASH_TBL_L,
2130 swRegMulHashValueL);
2131 zfDelayWriteInternalReg(dev, ZM_MAC_REG_GROUP_HASH_TBL_H,
2132 swRegMulHashValueH);
2133 zfFlushDelayWrite(dev);
2137 /******************** Beacon ********************/
2138 void zfHpEnableBeacon(zdev_t* dev, u16_t mode, u16_t bcnInterval, u16_t dtim, u8_t enableAtim)
2142 zmw_get_wlan_dev(dev);
2145 zfDelayWriteInternalReg(dev, ZM_MAC_REG_BCN_CTRL, 0);
2146 /* Beacon DMA buffer address */
2147 zfDelayWriteInternalReg(dev, ZM_MAC_REG_BCN_ADDR, ZM_BEACON_BUFFER_ADDRESS);
2149 value = bcnInterval;
2151 value |= (((u32_t) dtim) << 16);
2153 if (mode == ZM_MODE_AP)
2158 else if (mode == ZM_MODE_IBSS)
2166 ((struct zsHpPriv*)wd->hpPrivate)->ibssBcnEnabled = 1;
2167 ((struct zsHpPriv*)wd->hpPrivate)->ibssBcnInterval = value;
2169 zfDelayWriteInternalReg(dev, ZM_MAC_REG_PRETBTT, (bcnInterval-6)<<16);
2171 /* Beacon period and beacon enable */
2172 zfDelayWriteInternalReg(dev, ZM_MAC_REG_BCN_PERIOD, value);
2173 zfFlushDelayWrite(dev);
2176 void zfHpDisableBeacon(zdev_t* dev)
2178 zmw_get_wlan_dev(dev);
2180 ((struct zsHpPriv*)wd->hpPrivate)->ibssBcnEnabled = 0;
2182 zfDelayWriteInternalReg(dev, ZM_MAC_REG_BCN_PERIOD, 0);
2183 zfFlushDelayWrite(dev);
2186 void zfHpLedCtrl(zdev_t* dev, u16_t ledId, u8_t mode)
2189 zmw_get_wlan_dev(dev);
2191 //zm_debug_msg1("LED ID=", ledId);
2192 //zm_debug_msg1("LED mode=", mode);
2195 if (((struct zsHpPriv*)wd->hpPrivate)->ledMode[ledId] != mode)
2197 ((struct zsHpPriv*)wd->hpPrivate)->ledMode[ledId] = mode;
2199 state = ((struct zsHpPriv*)wd->hpPrivate)->ledMode[0]
2200 | (((struct zsHpPriv*)wd->hpPrivate)->ledMode[1]<<1);
2201 zfDelayWriteInternalReg(dev, 0x1d0104, state);
2202 zfFlushDelayWrite(dev);
2203 //zm_debug_msg0("Update LED");
2208 /************************************************************************/
2210 /* FUNCTION DESCRIPTION zfHpResetTxRx */
2211 /* Reset Tx and Rx Desc. */
2214 /* dev : device pointer */
2221 /* Chao-Wen Yang ZyDAS Technology Corporation 2007.3 */
2223 /************************************************************************/
2224 u16_t zfHpUsbReset(zdev_t* dev)
2226 u32_t cmd[(ZM_MAX_CMD_SIZE/4)];
2229 //zm_debug_msg0("CWY - Reset Tx and Rx");
2231 cmd[0] = 0 | (ZM_CMD_RESET << 8);
2233 ret = zfIssueCmd(dev, cmd, 4, ZM_OID_INTERNAL_WRITE, NULL);
2237 u16_t zfHpDKReset(zdev_t* dev, u8_t flag)
2239 u32_t cmd[(ZM_MAX_CMD_SIZE/4)];
2242 //zm_debug_msg0("CWY - Reset Tx and Rx");
2244 cmd[0] = 4 | (ZM_CMD_DKRESET << 8);
2247 ret = zfIssueCmd(dev, cmd, 8, ZM_OID_INTERNAL_WRITE, NULL);
2251 u32_t zfHpCwmUpdate(zdev_t* dev)
2256 //cmd[0] = 0x00000008;
2257 //cmd[1] = 0x1c36e8;
2258 //cmd[2] = 0x1c36ec;
2260 //ret = zfIssueCmd(dev, cmd, 12, ZM_CWM_READ, 0);
2262 zmw_get_wlan_dev(dev);
2264 struct zsHpPriv* hpPriv=wd->hpPrivate;
2266 zfCoreCwmBusy(dev, zfCwmIsExtChanBusy(hpPriv->ctlBusy, hpPriv->extBusy));
2268 hpPriv->ctlBusy = 0;
2269 hpPriv->extBusy = 0;
2274 u32_t zfHpAniUpdate(zdev_t* dev)
2279 cmd[0] = 0x00000010;
2285 ret = zfIssueCmd(dev, cmd, 20, ZM_ANI_READ, 0);
2290 * Update Beacon RSSI in ANI
2292 u32_t zfHpAniUpdateRssi(zdev_t* dev, u8_t rssi)
2294 zmw_get_wlan_dev(dev);
2296 struct zsHpPriv* hpPriv=wd->hpPrivate;
2298 hpPriv->stats.ast_nodestats.ns_avgbrssi = rssi;
2303 #define ZM_SEEPROM_MAC_ADDRESS_OFFSET (0x1400 + (0x106<<1))
2304 #define ZM_SEEPROM_REGDOMAIN_OFFSET (0x1400 + (0x104<<1))
2305 #define ZM_SEEPROM_VERISON_OFFSET (0x1400 + (0x102<<1))
2306 #define ZM_SEEPROM_HARDWARE_TYPE_OFFSET (0x1374)
2307 #define ZM_SEEPROM_HW_HEAVY_CLIP (0x161c)
2309 u32_t zfHpGetMacAddress(zdev_t* dev)
2314 cmd[0] = 0x00000000 | 24;
2315 cmd[1] = ZM_SEEPROM_MAC_ADDRESS_OFFSET;
2316 cmd[2] = ZM_SEEPROM_MAC_ADDRESS_OFFSET+4;
2317 cmd[3] = ZM_SEEPROM_REGDOMAIN_OFFSET;
2318 cmd[4] = ZM_SEEPROM_VERISON_OFFSET;
2319 cmd[5] = ZM_SEEPROM_HARDWARE_TYPE_OFFSET;
2320 cmd[6] = ZM_SEEPROM_HW_HEAVY_CLIP;
2322 ret = zfIssueCmd(dev, cmd, 28, ZM_MAC_READ, 0);
2326 u32_t zfHpGetTransmitPower(zdev_t* dev)
2328 zmw_get_wlan_dev(dev);
2330 struct zsHpPriv* hpPriv = wd->hpPrivate;
2333 if (hpPriv->hwFrequency < 3000) {
2334 tpc = hpPriv->tPow2x2g[0] & 0x3f;
2335 wd->maxTxPower2 &= 0x3f;
2336 tpc = (tpc > wd->maxTxPower2)? wd->maxTxPower2 : tpc;
2338 tpc = hpPriv->tPow2x5g[0] & 0x3f;
2339 wd->maxTxPower5 &= 0x3f;
2340 tpc = (tpc > wd->maxTxPower5)? wd->maxTxPower5 : tpc;
2346 u8_t zfHpGetMinTxPower(zdev_t* dev)
2348 zmw_get_wlan_dev(dev);
2350 struct zsHpPriv* hpPriv = wd->hpPrivate;
2353 if (hpPriv->hwFrequency < 3000)
2358 tpc = (hpPriv->tPow2x2gHt40[7]&0x3f);
2363 tpc = (hpPriv->tPow2x2gHt20[7]&0x3f);
2371 tpc = (hpPriv->tPow2x5gHt40[7]&0x3f);
2376 tpc = (hpPriv->tPow2x5gHt20[7]&0x3f);
2383 u8_t zfHpGetMaxTxPower(zdev_t* dev)
2385 zmw_get_wlan_dev(dev);
2387 struct zsHpPriv* hpPriv = wd->hpPrivate;
2390 if (hpPriv->hwFrequency < 3000)
2392 tpc = (hpPriv->tPow2xCck[0]&0x3f);
2396 tpc =(hpPriv->tPow2x5g[0]&0x3f);
2402 u32_t zfHpLoadEEPROMFromFW(zdev_t* dev)
2406 zmw_get_wlan_dev(dev);
2408 i = ((struct zsHpPriv*)wd->hpPrivate)->eepromImageRdReq;
2410 cmd[0] = ZM_HAL_MAX_EEPROM_PRQ*4;
2412 for (j=0; j<ZM_HAL_MAX_EEPROM_PRQ; j++)
2414 cmd[j+1] = 0x1000 + (((i*ZM_HAL_MAX_EEPROM_PRQ) + j)*4);
2417 ret = zfIssueCmd(dev, cmd, (ZM_HAL_MAX_EEPROM_PRQ+1)*4, ZM_EEPROM_READ, 0);
2422 void zfHpHeartBeat(zdev_t* dev)
2424 zmw_get_wlan_dev(dev);
2425 struct zsHpPriv* hpPriv=wd->hpPrivate;
2429 /* Workaround : Make OTUS fire more beacon in ad hoc mode in 2.4GHz */
2430 if (hpPriv->ibssBcnEnabled != 0)
2432 if (hpPriv->hwFrequency <= ZM_CH_G_14)
2434 if ((wd->tick % 10) == 0)
2436 if ((wd->tick % 40) == 0)
2438 zfDelayWriteInternalReg(dev, ZM_MAC_REG_BCN_PERIOD, hpPriv->ibssBcnInterval-1);
2443 zfDelayWriteInternalReg(dev, ZM_MAC_REG_BCN_PERIOD, hpPriv->ibssBcnInterval);
2450 if ((wd->tick & 0x3f) == 0x25)
2452 /* Workaround for beacon stuck after SW reset */
2453 if (hpPriv->ibssBcnEnabled != 0)
2455 zfDelayWriteInternalReg(dev, ZM_MAC_REG_BCN_ADDR, ZM_BEACON_BUFFER_ADDRESS);
2459 //DbgPrint("hpPriv->aggMaxDurationBE=%d", hpPriv->aggMaxDurationBE);
2460 //DbgPrint("wd->sta.avgSizeOfReceivePackets=%d", wd->sta.avgSizeOfReceivePackets);
2461 if (( wd->wlanMode == ZM_MODE_INFRASTRUCTURE )
2462 && (zfStaIsConnected(dev))
2463 && (wd->sta.EnableHT == 1) //11n mode
2464 && (wd->BandWidth40 == 1) //40MHz mode
2465 && (wd->sta.enableDrvBA ==0) //Marvel AP
2466 && (hpPriv->aggMaxDurationBE > 2000) //BE TXOP > 2ms
2467 && (wd->sta.avgSizeOfReceivePackets > 1420))
2469 zfDelayWriteInternalReg(dev, 0x1c3b9c, 0x8000a);
2474 zfDelayWriteInternalReg(dev, 0x1c3b9c, hpPriv->aggPktNum);
2478 if (wd->dynamicSIFSEnable == 0)
2480 if (( wd->wlanMode == ZM_MODE_INFRASTRUCTURE )
2481 && (zfStaIsConnected(dev))
2482 && (wd->sta.EnableHT == 1) //11n mode
2483 && (wd->BandWidth40 == 0) //20MHz mode
2484 && (wd->sta.enableDrvBA ==0)) //Marvel AP
2486 zfDelayWriteInternalReg(dev, 0x1c3698, 0x5144000);
2491 zfDelayWriteInternalReg(dev, 0x1c3698, 0xA144000);
2497 if (( wd->wlanMode == ZM_MODE_INFRASTRUCTURE )
2498 && (zfStaIsConnected(dev))
2499 && (wd->sta.EnableHT == 1) //11n mode
2500 && (wd->sta.athOwlAp == 1)) //Atheros AP
2502 if (hpPriv->retransmissionEvent)
2504 switch(hpPriv->latestSIFS)
2507 hpPriv->latestSIFS = 1;
2508 zfDelayWriteInternalReg(dev, ZM_MAC_REG_EIFS_AND_SIFS, 0x8144000);
2511 hpPriv->latestSIFS = 2;
2512 zfDelayWriteInternalReg(dev, ZM_MAC_REG_EIFS_AND_SIFS, 0xa144000);
2515 hpPriv->latestSIFS = 3;
2516 zfDelayWriteInternalReg(dev, ZM_MAC_REG_EIFS_AND_SIFS, 0xc144000);
2519 hpPriv->latestSIFS = 0;
2520 zfDelayWriteInternalReg(dev, ZM_MAC_REG_EIFS_AND_SIFS, 0xa144000);
2523 hpPriv->latestSIFS = 0;
2524 zfDelayWriteInternalReg(dev, ZM_MAC_REG_EIFS_AND_SIFS, 0xa144000);
2528 zm_debug_msg1("##### Correct Tx retransmission issue #####, ", hpPriv->latestSIFS);
2529 hpPriv->retransmissionEvent = 0;
2534 hpPriv->latestSIFS = 0;
2535 hpPriv->retransmissionEvent = 0;
2536 zfDelayWriteInternalReg(dev, 0x1c3698, 0xA144000);
2541 if ((wd->sta.bScheduleScan == FALSE) && (wd->sta.bChannelScan == FALSE))
2543 #define ZM_SIGNAL_THRESHOLD 66
2544 if (( wd->wlanMode == ZM_MODE_INFRASTRUCTURE )
2545 && (zfStaIsConnected(dev))
2546 && (wd->SignalStrength > ZM_SIGNAL_THRESHOLD))
2548 /* remove state handle, always rewrite register setting */
2549 //if (hpPriv->strongRSSI == 0)
2551 hpPriv->strongRSSI = 1;
2552 /* Strong RSSI, set ACK to one Tx stream and lower Tx power 7dbm */
2553 if (hpPriv->currentAckRtsTpc > (14+10))
2555 ackTpc = hpPriv->currentAckRtsTpc - 14;
2561 zfDelayWriteInternalReg(dev, 0x1c3694, ((ackTpc) << 20) | (0x1<<26));
2562 zfDelayWriteInternalReg(dev, 0x1c3bb4, ((ackTpc) << 5 ) | (0x1<<11) |
2563 ((ackTpc) << 21) | (0x1<<27) );
2569 /* remove state handle, always rewrite register setting */
2570 //if (hpPriv->strongRSSI == 1)
2572 hpPriv->strongRSSI = 0;
2573 if (hpPriv->halCapability & ZM_HP_CAP_11N_ONE_TX_STREAM)
2575 zfDelayWriteInternalReg(dev, 0x1c3694, ((hpPriv->currentAckRtsTpc&0x3f) << 20) | (0x1<<26));
2576 zfDelayWriteInternalReg(dev, 0x1c3bb4, ((hpPriv->currentAckRtsTpc&0x3f) << 5 ) | (0x1<<11) |
2577 ((hpPriv->currentAckRtsTpc&0x3f) << 21) | (0x1<<27) );
2581 zfDelayWriteInternalReg(dev, 0x1c3694, ((hpPriv->currentAckRtsTpc&0x3f) << 20) | (0x5<<26));
2582 zfDelayWriteInternalReg(dev, 0x1c3bb4, ((hpPriv->currentAckRtsTpc&0x3f) << 5 ) | (0x5<<11) |
2583 ((hpPriv->currentAckRtsTpc&0x3f) << 21) | (0x5<<27) );
2588 #undef ZM_SIGNAL_THRESHOLD
2591 if ((hpPriv->halCapability & ZM_HP_CAP_11N_ONE_TX_STREAM) == 0)
2593 if ((wd->sta.bScheduleScan == FALSE) && (wd->sta.bChannelScan == FALSE))
2595 #define ZM_RX_SIGNAL_THRESHOLD_H 71
2596 #define ZM_RX_SIGNAL_THRESHOLD_L 66
2597 u8_t rxSignalThresholdH = ZM_RX_SIGNAL_THRESHOLD_H;
2598 u8_t rxSignalThresholdL = ZM_RX_SIGNAL_THRESHOLD_L;
2599 #undef ZM_RX_SIGNAL_THRESHOLD_H
2600 #undef ZM_RX_SIGNAL_THRESHOLD_L
2602 if (( wd->wlanMode == ZM_MODE_INFRASTRUCTURE )
2603 && (zfStaIsConnected(dev))
2604 && (wd->SignalStrength > rxSignalThresholdH)
2605 )//&& (hpPriv->rxStrongRSSI == 0))
2607 hpPriv->rxStrongRSSI = 1;
2608 //zfDelayWriteInternalReg(dev, 0x1c5964, 0x1220);
2609 //zfDelayWriteInternalReg(dev, 0x1c5960, 0x900);
2610 //zfDelayWriteInternalReg(dev, 0x1c6960, 0x900);
2611 //zfDelayWriteInternalReg(dev, 0x1c7960, 0x900);
2612 if ((hpPriv->eepromImage[0x100+0x110*2/4]&0xff) == 0x80) //FEM TYPE
2614 if (hpPriv->hwFrequency <= ZM_CH_G_14)
2616 zfDelayWriteInternalReg(dev, 0x1c8960, 0x900);
2620 zfDelayWriteInternalReg(dev, 0x1c8960, 0x9b49);
2625 zfDelayWriteInternalReg(dev, 0x1c8960, 0x0900);
2629 else if (( wd->wlanMode == ZM_MODE_INFRASTRUCTURE )
2630 && (zfStaIsConnected(dev))
2631 && (wd->SignalStrength > rxSignalThresholdL)
2632 )//&& (hpPriv->rxStrongRSSI == 1))
2634 //Do nothing to prevent frequently Rx switching
2638 /* remove state handle, always rewrite register setting */
2639 //if (hpPriv->rxStrongRSSI == 1)
2641 hpPriv->rxStrongRSSI = 0;
2642 //zfDelayWriteInternalReg(dev, 0x1c5964, 0x1120);
2643 //zfDelayWriteInternalReg(dev, 0x1c5960, 0x9b40);
2644 //zfDelayWriteInternalReg(dev, 0x1c6960, 0x9b40);
2645 //zfDelayWriteInternalReg(dev, 0x1c7960, 0x9b40);
2646 if ((hpPriv->eepromImage[0x100+0x110*2/4]&0xff) == 0x80) //FEM TYPE
2648 if (hpPriv->hwFrequency <= ZM_CH_G_14)
2650 zfDelayWriteInternalReg(dev, 0x1c8960, 0x9b49);
2654 zfDelayWriteInternalReg(dev, 0x1c8960, 0x0900);
2659 zfDelayWriteInternalReg(dev, 0x1c8960, 0x9b40);
2668 if (hpPriv->usbAcSendBytes[3] > (hpPriv->usbAcSendBytes[0]*2))
2670 zfDelayWriteInternalReg(dev, ZM_MAC_REG_AC1_AC0_TXOP, hpPriv->txop[3]);
2673 else if (hpPriv->usbAcSendBytes[2] > (hpPriv->usbAcSendBytes[0]*2))
2675 zfDelayWriteInternalReg(dev, ZM_MAC_REG_AC1_AC0_TXOP, hpPriv->txop[2]);
2678 else if (hpPriv->usbAcSendBytes[1] > (hpPriv->usbAcSendBytes[0]*2))
2680 zfDelayWriteInternalReg(dev, ZM_MAC_REG_AC0_CW, hpPriv->cwmin[1]+((u32_t)hpPriv->cwmax[1]<<16));
2685 if (hpPriv->slotType == 1)
2687 if ((wd->sta.enableDrvBA ==0) //Marvel AP
2688 && (hpPriv->aggMaxDurationBE > 2000)) //BE TXOP > 2ms
2690 zfDelayWriteInternalReg(dev, ZM_MAC_REG_AC0_CW, (hpPriv->cwmin[0]/2)+((u32_t)hpPriv->cwmax[0]<<16));
2694 zfDelayWriteInternalReg(dev, ZM_MAC_REG_AC0_CW, hpPriv->cwmin[0]+((u32_t)hpPriv->cwmax[0]<<16));
2700 /* Compensation for 20us slot time */
2701 //zfDelayWriteInternalReg(dev, ZM_MAC_REG_AC0_CW, 58+((u32_t)hpPriv->cwmax[0]<<16));
2702 zfDelayWriteInternalReg(dev, ZM_MAC_REG_AC0_CW, hpPriv->cwmin[0]+((u32_t)hpPriv->cwmax[0]<<16));
2706 if ((wd->sta.SWEncryptEnable & (ZM_SW_TKIP_ENCRY_EN|ZM_SW_WEP_ENCRY_EN)) == 0)
2708 zfDelayWriteInternalReg(dev, ZM_MAC_REG_AC1_AC0_TXOP, hpPriv->txop[0]);
2713 zfDelayWriteInternalReg(dev, ZM_MAC_REG_AC1_AC0_TXOP, 0x30);
2718 hpPriv->usbAcSendBytes[3] = 0;
2719 hpPriv->usbAcSendBytes[2] = 0;
2720 hpPriv->usbAcSendBytes[1] = 0;
2721 hpPriv->usbAcSendBytes[0] = 0;
2726 zfFlushDelayWrite(dev);
2733 * 0x1d4008 : AHB, DAC, ADC clock selection
2734 * bit1~0 AHB_CLK : AHB clock selection,
2736 * 01 : 20MHz in A mode, 22MHz in G mode;
2737 * 10 : 40MHz in A mode, 44MHz in G mode;
2738 * 11 : 80MHz in A mode, 88MHz in G mode.
2739 * bit3~2 CLK_SEL : Select the clock source of clk160 in ADDAC.
2740 * 00 : PLL divider's output;
2741 * 01 : PLL divider's output divided by 2;
2742 * 10 : PLL divider's output divided by 4;
2743 * 11 : REFCLK from XTALOSCPAD.
2745 void zfSelAdcClk(zdev_t* dev, u8_t bw40, u32_t frequency)
2749 //zfDelayWriteInternalReg(dev, 0x1D4008, 0x73);
2750 zfDelayWriteInternalReg(dev, ZM_MAC_REG_DYNAMIC_SIFS_ACK, 0x10A);
2751 zfFlushDelayWrite(dev);
2755 //zfDelayWriteInternalReg(dev, 0x1D4008, 0x70);
2756 if ( frequency <= ZM_CH_G_14 )
2758 zfDelayWriteInternalReg(dev, ZM_MAC_REG_DYNAMIC_SIFS_ACK, 0x105);
2762 zfDelayWriteInternalReg(dev, ZM_MAC_REG_DYNAMIC_SIFS_ACK, 0x104);
2764 zfFlushDelayWrite(dev);
2768 u32_t zfHpEchoCommand(zdev_t* dev, u32_t value)
2773 cmd[0] = 0x00008004;
2776 ret = zfIssueCmd(dev, cmd, 8, ZM_CMD_ECHO, NULL);
2780 #ifdef ZM_DRV_INIT_USB_MODE
2782 #define ZM_USB_US_STREAM_MODE 0x00000000
2783 #define ZM_USB_US_PACKET_MODE 0x00000008
2784 #define ZM_USB_DS_ENABLE 0x00000001
2785 #define ZM_USB_US_ENABLE 0x00000002
2787 #define ZM_USB_RX_STREAM_4K 0x00000000
2788 #define ZM_USB_RX_STREAM_8K 0x00000010
2789 #define ZM_USB_RX_STREAM_16K 0x00000020
2790 #define ZM_USB_RX_STREAM_32K 0x00000030
2792 #define ZM_USB_TX_STREAM_MODE 0x00000040
2794 #define ZM_USB_MODE_CTRL_REG 0x001E1108
2796 void zfInitUsbMode(zdev_t* dev)
2799 zmw_get_wlan_dev(dev);
2801 /* TODO: Set USB mode by reading registery */
2802 mode = ZM_USB_DS_ENABLE | ZM_USB_US_ENABLE | ZM_USB_US_PACKET_MODE;
2804 zfDelayWriteInternalReg(dev, ZM_USB_MODE_CTRL_REG, mode);
2805 zfFlushDelayWrite(dev);
2809 void zfDumpEepBandEdges(struct ar5416Eeprom* eepromImage);
2810 void zfPrintTargetPower2G(u8_t* tPow2xCck, u8_t* tPow2x2g, u8_t* tPow2x2gHt20, u8_t* tPow2x2gHt40);
2811 void zfPrintTargetPower5G(u8_t* tPow2x5g, u8_t* tPow2x5gHt20, u8_t* tPow2x5gHt40);
2814 s32_t zfInterpolateFunc(s32_t x, s32_t x1, s32_t y1, s32_t x2, s32_t y2)
2832 y = y1 + (((y2-y1) * (x-x1))/(x2-x1));
2842 //#define ZM_ENABLE_TPC_WINDOWS_DEBUG
2843 //#define ZM_ENABLE_BANDEDGES_WINDOWS_DEBUG
2845 /* the tx power offset workaround for ART vs NDIS/MDK */
2846 #define HALTX_POWER_OFFSET 0
2848 u8_t zfInterpolateFuncX(u8_t x, u8_t x1, u8_t y1, u8_t x2, u8_t y2)
2853 #define ZM_MULTIPLIER 8
2854 y = zfInterpolateFunc((s32_t)x<<ZM_MULTIPLIER,
2855 (s32_t)x1<<ZM_MULTIPLIER,
2856 (s32_t)y1<<ZM_MULTIPLIER,
2857 (s32_t)x2<<ZM_MULTIPLIER,
2858 (s32_t)y2<<ZM_MULTIPLIER);
2860 inc = (y & (1<<(ZM_MULTIPLIER-1))) >> (ZM_MULTIPLIER-1);
2861 y = (y >> ZM_MULTIPLIER) + inc;
2862 #undef ZM_MULTIPLIER
2867 u8_t zfGetInterpolatedValue(u8_t x, u8_t* x_array, u8_t* y_array)
2872 if (x <= x_array[1])
2876 else if (x <= x_array[2])
2880 else if (x <= x_array[3])
2884 else //(x > x_array[3])
2889 y = zfInterpolateFuncX(x,
2898 u8_t zfFindFreqIndex(u8_t f, u8_t* fArray, u8_t fArraySize)
2901 #ifdef ZM_ENABLE_TPC_WINDOWS_DEBUG
2902 DbgPrint("f=%d ", f);
2903 for (i=0; i<fArraySize; i++)
2905 DbgPrint("%d ", fArray[i]);
2930 void zfInitPowerCal(zdev_t* dev)
2932 //Program PHY Tx power relatives registers
2933 #define zm_write_phy_reg(cr, val) reg_write((cr*4)+0x9800, val)
2935 zm_write_phy_reg(79, 0x7f);
2936 zm_write_phy_reg(77, 0x3f3f3f3f);
2937 zm_write_phy_reg(78, 0x3f3f3f3f);
2938 zm_write_phy_reg(653, 0x3f3f3f3f);
2939 zm_write_phy_reg(654, 0x3f3f3f3f);
2940 zm_write_phy_reg(739, 0x3f3f3f3f);
2941 zm_write_phy_reg(740, 0x3f3f3f3f);
2942 zm_write_phy_reg(755, 0x3f3f3f3f);
2943 zm_write_phy_reg(756, 0x3f3f3f3f);
2944 zm_write_phy_reg(757, 0x3f3f3f3f);
2946 #undef zm_write_phy_reg
2951 void zfPrintTp(u8_t* pwr0, u8_t* vpd0, u8_t* pwr1, u8_t* vpd1)
2953 #ifdef ZM_ENABLE_TPC_WINDOWS_DEBUG
2954 DbgPrint("pwr0 : %d, %d, %d, %d ,%d\n", pwr0[0], pwr0[1], pwr0[2], pwr0[3], pwr0[4]);
2955 DbgPrint("vpd0 : %d, %d, %d, %d ,%d\n", vpd0[0], vpd0[1], vpd0[2], vpd0[3], vpd0[4]);
2956 DbgPrint("pwr1 : %d, %d, %d, %d ,%d\n", pwr1[0], pwr1[1], pwr1[2], pwr1[3], pwr1[4]);
2957 DbgPrint("vpd1 : %d, %d, %d, %d ,%d\n", vpd1[0], vpd1[1], vpd1[2], vpd1[3], vpd1[4]);
2963 * To find CTL index(0~23)
2964 * return 24(AR5416_NUM_CTLS)=>no desired index found
2966 u8_t zfFindCtlEdgesIndex(zdev_t* dev, u8_t desired_CtlIndex)
2969 struct zsHpPriv* hpPriv;
2970 struct ar5416Eeprom* eepromImage;
2972 zmw_get_wlan_dev(dev);
2974 hpPriv = wd->hpPrivate;
2976 eepromImage = (struct ar5416Eeprom*)&(hpPriv->eepromImage[(1024+512)/4]);
2978 //for (i = 0; (i < AR5416_NUM_CTLS) && eepromImage->ctlIndex[i]; i++)
2979 for (i = 0; i < AR5416_NUM_CTLS; i++)
2981 if(desired_CtlIndex == eepromImage->ctlIndex[i])
2987 /**************************************************************************
2990 * Get channel value from binary representation held in eeprom
2991 * RETURNS: the frequency in MHz
2994 fbin2freq(u8_t fbin, u8_t is2GHz)
2997 * Reserved value 0xFF provides an empty definition both as
2998 * an fbin and as a frequency - do not convert
3000 if (fbin == AR5416_BCHAN_UNUSED) {
3004 return (u32_t)((is2GHz==1) ? (2300 + fbin) : (4800 + 5 * fbin));
3008 u8_t zfGetMaxEdgePower(zdev_t* dev, CAL_CTL_EDGES *pCtlEdges, u32_t freq)
3013 struct zsHpPriv* hpPriv;
3014 struct ar5416Eeprom* eepromImage;
3016 zmw_get_wlan_dev(dev);
3018 hpPriv = wd->hpPrivate;
3020 eepromImage = (struct ar5416Eeprom*)&(hpPriv->eepromImage[(1024+512)/4]);
3022 if(freq > ZM_CH_G_14)
3027 maxEdgePower = AR5416_MAX_RATE_POWER;
3029 /* Get the edge power */
3030 for (i = 0; (i < AR5416_NUM_BAND_EDGES) && (pCtlEdges[i].bChannel != AR5416_BCHAN_UNUSED) ; i++)
3033 * If there's an exact channel match or an inband flag set
3034 * on the lower channel use the given rdEdgePower
3036 if (freq == fbin2freq(pCtlEdges[i].bChannel, is2GHz))
3038 maxEdgePower = pCtlEdges[i].tPower;
3039 #ifdef ZM_ENABLE_BANDEDGES_WINDOWS_DEBUG
3040 zm_dbg(("zfGetMaxEdgePower index i = %d \n", i));
3044 else if ((i > 0) && (freq < fbin2freq(pCtlEdges[i].bChannel, is2GHz)))
3046 if (fbin2freq(pCtlEdges[i - 1].bChannel, is2GHz) < freq && pCtlEdges[i - 1].flag)
3048 maxEdgePower = pCtlEdges[i - 1].tPower;
3049 #ifdef ZM_ENABLE_BANDEDGES_WINDOWS_DEBUG
3050 zm_dbg(("zfGetMaxEdgePower index i-1 = %d \n", i-1));
3053 /* Leave loop - no more affecting edges possible in this monotonic increasing list */
3059 if( i == AR5416_NUM_BAND_EDGES )
3061 if (freq > fbin2freq(pCtlEdges[i - 1].bChannel, is2GHz) && pCtlEdges[i - 1].flag)
3063 maxEdgePower = pCtlEdges[i - 1].tPower;
3064 #ifdef ZM_ENABLE_BANDEDGES_WINDOWS_DEBUG
3065 zm_dbg(("zfGetMaxEdgePower index=>i-1 = %d \n", i-1));
3070 zm_assert(maxEdgePower > 0);
3072 #ifdef ZM_ENABLE_BANDEDGES_WINDOWS_DEBUG
3073 if ( maxEdgePower == AR5416_MAX_RATE_POWER )
3075 zm_dbg(("zfGetMaxEdgePower = %d !!!\n", AR5416_MAX_RATE_POWER));
3078 return maxEdgePower;
3081 u32_t zfAdjustHT40FreqOffset(zdev_t* dev, u32_t frequency, u8_t bw40, u8_t extOffset)
3083 u32_t newFreq = frequency;
3099 u32_t zfHpCheckDoHeavyClip(zdev_t* dev, u32_t freq, CAL_CTL_EDGES *pCtlEdges, u8_t bw40)
3104 struct zsHpPriv* hpPriv;
3106 zmw_get_wlan_dev(dev);
3108 hpPriv = wd->hpPrivate;
3110 if(freq > ZM_CH_G_14)
3115 /* HT40 force enable heavy clip */
3121 /* HT20 : frequency bandedge */
3122 for (i = 0; (i < AR5416_NUM_BAND_EDGES) && (pCtlEdges[i].bChannel != AR5416_BCHAN_UNUSED) ; i++)
3124 if (freq == fbin2freq(pCtlEdges[i].bChannel, is2GHz))
3126 if (pCtlEdges[i].flag == 0)
3139 void zfSetPowerCalTable(zdev_t* dev, u32_t frequency, u8_t bw40, u8_t extOffset)
3141 struct ar5416Eeprom* eepromImage;
3146 u8_t vpd_chain1[128];
3147 u8_t vpd_chain3[128];
3148 u16_t boundary1 = 18; //CR 667
3149 u16_t powerTxMax = 63; //CR 79
3151 struct zsHpPriv* hpPriv;
3153 u8_t index, max2gIndex, max5gIndex;
3154 u8_t chain0pwrPdg0[5];
3155 u8_t chain0vpdPdg0[5];
3156 u8_t chain0pwrPdg1[5];
3157 u8_t chain0vpdPdg1[5];
3158 u8_t chain2pwrPdg0[5];
3159 u8_t chain2vpdPdg0[5];
3160 u8_t chain2pwrPdg1[5];
3161 u8_t chain2vpdPdg1[5];
3166 u8_t desired_CtlIndex;
3168 u8_t ctlEdgesMaxPowerCCK = AR5416_MAX_RATE_POWER;
3169 u8_t ctlEdgesMaxPower2G = AR5416_MAX_RATE_POWER;
3170 u8_t ctlEdgesMaxPower2GHT20 = AR5416_MAX_RATE_POWER;
3171 u8_t ctlEdgesMaxPower2GHT40 = AR5416_MAX_RATE_POWER;
3172 u8_t ctlEdgesMaxPower5G = AR5416_MAX_RATE_POWER;
3173 u8_t ctlEdgesMaxPower5GHT20 = AR5416_MAX_RATE_POWER;
3174 u8_t ctlEdgesMaxPower5GHT40 = AR5416_MAX_RATE_POWER;
3178 zmw_get_wlan_dev(dev);
3180 hpPriv = wd->hpPrivate;
3182 eepromImage = (struct ar5416Eeprom*)&(hpPriv->eepromImage[(1024+512)/4]);
3184 // Check the total bytes of the EEPROM structure to see the dongle have been calibrated or not.
3185 if (eepromImage->baseEepHeader.length == 0xffff)
3187 #ifdef ZM_ENABLE_BANDEDGES_WINDOWS_DEBUG
3188 zm_dbg(("Warning! This dongle not been calibrated\n"));
3193 #ifdef ZM_ENABLE_TPC_WINDOWS_DEBUG
3194 DbgPrint("-----zfSetPowerCalTable : frequency=%d-----\n", frequency);
3196 /* TODO : 1. boundary1 and powerTxMax should be refered to CR667 and CR79 */
3197 /* in otus.ini file */
3199 #ifdef ZM_ENABLE_TPC_WINDOWS_DEBUG
3200 /* 2. Interpolate pwr and vpd test points from frequency */
3201 DbgPrint("calFreqPier5G : %d, %d, %d, %d ,%d, %d, %d, %d\n",
3202 eepromImage->calFreqPier5G[0]*5+4800,
3203 eepromImage->calFreqPier5G[1]*5+4800,
3204 eepromImage->calFreqPier5G[2]*5+4800,
3205 eepromImage->calFreqPier5G[3]*5+4800,
3206 eepromImage->calFreqPier5G[4]*5+4800,
3207 eepromImage->calFreqPier5G[5]*5+4800,
3208 eepromImage->calFreqPier5G[6]*5+4800,
3209 eepromImage->calFreqPier5G[7]*5+4800
3211 DbgPrint("calFreqPier2G : %d, %d, %d, %d\n",
3212 eepromImage->calFreqPier2G[0]+2300,
3213 eepromImage->calFreqPier2G[1]+2300,
3214 eepromImage->calFreqPier2G[2]+2300,
3215 eepromImage->calFreqPier2G[3]+2300
3218 if (frequency < 3000)
3222 if (eepromImage->calFreqPier2G[i] == 0xff)
3228 #ifdef ZM_ENABLE_TPC_WINDOWS_DEBUG
3229 DbgPrint("max2gIndex : %d\n", max2gIndex);
3231 fbin = (u8_t)(frequency - 2300);
3232 index = zfFindFreqIndex(fbin, eepromImage->calFreqPier2G, max2gIndex);
3233 #ifdef ZM_ENABLE_TPC_WINDOWS_DEBUG
3234 DbgPrint("2G index : %d\n", index);
3235 DbgPrint("chain 0 index\n");
3237 zfPrintTp(&eepromImage->calPierData2G[0][index].pwrPdg[0][0],
3238 &eepromImage->calPierData2G[0][index].vpdPdg[0][0],
3239 &eepromImage->calPierData2G[0][index].pwrPdg[1][0],
3240 &eepromImage->calPierData2G[0][index].vpdPdg[1][0]
3242 #ifdef ZM_ENABLE_TPC_WINDOWS_DEBUG
3243 DbgPrint("chain 0 index+1\n");
3245 zfPrintTp(&eepromImage->calPierData2G[0][index+1].pwrPdg[0][0],
3246 &eepromImage->calPierData2G[0][index+1].vpdPdg[0][0],
3247 &eepromImage->calPierData2G[0][index+1].pwrPdg[1][0],
3248 &eepromImage->calPierData2G[0][index+1].vpdPdg[1][0]
3253 chain0pwrPdg0[i] = zfInterpolateFuncX(fbin,
3254 eepromImage->calFreqPier2G[index],
3255 eepromImage->calPierData2G[0][index].pwrPdg[0][i],
3256 eepromImage->calFreqPier2G[index+1],
3257 eepromImage->calPierData2G[0][index+1].pwrPdg[0][i]
3259 chain0vpdPdg0[i] = zfInterpolateFuncX(fbin,
3260 eepromImage->calFreqPier2G[index],
3261 eepromImage->calPierData2G[0][index].vpdPdg[0][i],
3262 eepromImage->calFreqPier2G[index+1],
3263 eepromImage->calPierData2G[0][index+1].vpdPdg[0][i]
3265 chain0pwrPdg1[i] = zfInterpolateFuncX(fbin,
3266 eepromImage->calFreqPier2G[index],
3267 eepromImage->calPierData2G[0][index].pwrPdg[1][i],
3268 eepromImage->calFreqPier2G[index+1],
3269 eepromImage->calPierData2G[0][index+1].pwrPdg[1][i]
3271 chain0vpdPdg1[i] = zfInterpolateFuncX(fbin,
3272 eepromImage->calFreqPier2G[index],
3273 eepromImage->calPierData2G[0][index].vpdPdg[1][i],
3274 eepromImage->calFreqPier2G[index+1],
3275 eepromImage->calPierData2G[0][index+1].vpdPdg[1][i]
3278 chain2pwrPdg0[i] = zfInterpolateFuncX(fbin,
3279 eepromImage->calFreqPier2G[index],
3280 eepromImage->calPierData2G[1][index].pwrPdg[0][i],
3281 eepromImage->calFreqPier2G[index+1],
3282 eepromImage->calPierData2G[1][index+1].pwrPdg[0][i]
3284 chain2vpdPdg0[i] = zfInterpolateFuncX(fbin,
3285 eepromImage->calFreqPier2G[index],
3286 eepromImage->calPierData2G[1][index].vpdPdg[0][i],
3287 eepromImage->calFreqPier2G[index+1],
3288 eepromImage->calPierData2G[1][index+1].vpdPdg[0][i]
3290 chain2pwrPdg1[i] = zfInterpolateFuncX(fbin,
3291 eepromImage->calFreqPier2G[index],
3292 eepromImage->calPierData2G[1][index].pwrPdg[1][i],
3293 eepromImage->calFreqPier2G[index+1],
3294 eepromImage->calPierData2G[1][index+1].pwrPdg[1][i]
3296 chain2vpdPdg1[i] = zfInterpolateFuncX(fbin,
3297 eepromImage->calFreqPier2G[index],
3298 eepromImage->calPierData2G[1][index].vpdPdg[1][i],
3299 eepromImage->calFreqPier2G[index+1],
3300 eepromImage->calPierData2G[1][index+1].vpdPdg[1][i]
3308 if (eepromImage->calFreqPier5G[i] == 0xff)
3314 #ifdef ZM_ENABLE_TPC_WINDOWS_DEBUG
3315 DbgPrint("max5gIndex : %d\n", max5gIndex);
3317 fbin = (u8_t)((frequency - 4800)/5);
3318 index = zfFindFreqIndex(fbin, eepromImage->calFreqPier5G, max5gIndex);
3319 #ifdef ZM_ENABLE_TPC_WINDOWS_DEBUG
3320 DbgPrint("5G index : %d\n", index);
3325 chain0pwrPdg0[i] = zfInterpolateFuncX(fbin,
3326 eepromImage->calFreqPier5G[index],
3327 eepromImage->calPierData5G[0][index].pwrPdg[0][i],
3328 eepromImage->calFreqPier5G[index+1],
3329 eepromImage->calPierData5G[0][index+1].pwrPdg[0][i]
3331 chain0vpdPdg0[i] = zfInterpolateFuncX(fbin,
3332 eepromImage->calFreqPier5G[index],
3333 eepromImage->calPierData5G[0][index].vpdPdg[0][i],
3334 eepromImage->calFreqPier5G[index+1],
3335 eepromImage->calPierData5G[0][index+1].vpdPdg[0][i]
3337 chain0pwrPdg1[i] = zfInterpolateFuncX(fbin,
3338 eepromImage->calFreqPier5G[index],
3339 eepromImage->calPierData5G[0][index].pwrPdg[1][i],
3340 eepromImage->calFreqPier5G[index+1],
3341 eepromImage->calPierData5G[0][index+1].pwrPdg[1][i]
3343 chain0vpdPdg1[i] = zfInterpolateFuncX(fbin,
3344 eepromImage->calFreqPier5G[index],
3345 eepromImage->calPierData5G[0][index].vpdPdg[1][i],
3346 eepromImage->calFreqPier5G[index+1],
3347 eepromImage->calPierData5G[0][index+1].vpdPdg[1][i]
3350 chain2pwrPdg0[i] = zfInterpolateFuncX(fbin,
3351 eepromImage->calFreqPier5G[index],
3352 eepromImage->calPierData5G[1][index].pwrPdg[0][i],
3353 eepromImage->calFreqPier5G[index+1],
3354 eepromImage->calPierData5G[1][index+1].pwrPdg[0][i]
3356 chain2vpdPdg0[i] = zfInterpolateFuncX(fbin,
3357 eepromImage->calFreqPier5G[index],
3358 eepromImage->calPierData5G[1][index].vpdPdg[0][i],
3359 eepromImage->calFreqPier5G[index+1],
3360 eepromImage->calPierData5G[1][index+1].vpdPdg[0][i]
3362 chain2pwrPdg1[i] = zfInterpolateFuncX(fbin,
3363 eepromImage->calFreqPier5G[index],
3364 eepromImage->calPierData5G[1][index].pwrPdg[1][i],
3365 eepromImage->calFreqPier5G[index+1],
3366 eepromImage->calPierData5G[1][index+1].pwrPdg[1][i]
3368 chain2vpdPdg1[i] = zfInterpolateFuncX(fbin,
3369 eepromImage->calFreqPier5G[index],
3370 eepromImage->calPierData5G[1][index].vpdPdg[1][i],
3371 eepromImage->calFreqPier5G[index+1],
3372 eepromImage->calPierData5G[1][index+1].vpdPdg[1][i]
3380 /* Get pwr and vpd test points from frequency */
3383 pwr0[i] = chain0pwrPdg0[i]>>1;
3384 vpd0[i] = chain0vpdPdg0[i];
3385 pwr1[i] = chain0pwrPdg1[i]>>1;
3386 vpd1[i] = chain0vpdPdg1[i];
3388 #ifdef ZM_ENABLE_TPC_WINDOWS_DEBUG
3389 DbgPrint("Test Points\n");
3390 DbgPrint("pwr0 : %d, %d, %d, %d ,%d\n", pwr0[0], pwr0[1], pwr0[2], pwr0[3], pwr0[4]);
3391 DbgPrint("vpd0 : %d, %d, %d, %d ,%d\n", vpd0[0], vpd0[1], vpd0[2], vpd0[3], vpd0[4]);
3392 DbgPrint("pwr1 : %d, %d, %d, %d ,%d\n", pwr1[0], pwr1[1], pwr1[2], pwr1[3], pwr1[4]);
3393 DbgPrint("vpd1 : %d, %d, %d, %d ,%d\n", vpd1[0], vpd1[1], vpd1[2], vpd1[3], vpd1[4]);
3395 /* Generate the vpd arrays */
3396 for (i=0; i<boundary1+1+6; i++)
3398 vpd_chain1[i] = zfGetInterpolatedValue(i, &pwr0[0], &vpd0[0]);
3400 for (; i<powerTxMax+1+6+6; i++)
3402 vpd_chain1[i] = zfGetInterpolatedValue(i-6-6, &pwr1[0], &vpd1[0]);
3404 #ifdef ZM_ENABLE_TPC_WINDOWS_DEBUG
3405 DbgPrint("vpd_chain1\n");
3406 for (i=0; i<powerTxMax+1+6+6; i+=10)
3408 DbgPrint("%d, %d, %d, %d ,%d, %d, %d, %d, %d, %d\n",
3409 vpd_chain1[i+0], vpd_chain1[i+1], vpd_chain1[i+2], vpd_chain1[i+3], vpd_chain1[i+4],
3410 vpd_chain1[i+5], vpd_chain1[i+6], vpd_chain1[i+7], vpd_chain1[i+8], vpd_chain1[i+9]);
3413 /* Write PHY regs 672-703 */
3414 for (i=0; i<128; i+=4)
3416 u32_t regAddr = 0x9800 + (672 * 4);
3419 val = ((u32_t)vpd_chain1[i+3]<<24) |
3420 ((u32_t)vpd_chain1[i+2]<<16) |
3421 ((u32_t)vpd_chain1[i+1]<<8) |
3422 ((u32_t)vpd_chain1[i]);
3424 #ifndef ZM_OTUS_LINUX_PHASE_2
3425 reg_write(regAddr + i, val); /* CR672 */
3430 /* Get pwr and vpd test points from frequency */
3433 pwr0[i] = chain2pwrPdg0[i]>>1;
3434 vpd0[i] = chain2vpdPdg0[i];
3435 pwr1[i] = chain2pwrPdg1[i]>>1;
3436 vpd1[i] = chain2vpdPdg1[i];
3438 #ifdef ZM_ENABLE_TPC_WINDOWS_DEBUG
3439 DbgPrint("Test Points\n");
3440 DbgPrint("pwr0 : %d, %d, %d, %d ,%d\n", pwr0[0], pwr0[1], pwr0[2], pwr0[3], pwr0[4]);
3441 DbgPrint("vpd0 : %d, %d, %d, %d ,%d\n", vpd0[0], vpd0[1], vpd0[2], vpd0[3], vpd0[4]);
3442 DbgPrint("pwr1 : %d, %d, %d, %d ,%d\n", pwr1[0], pwr1[1], pwr1[2], pwr1[3], pwr1[4]);
3443 DbgPrint("vpd1 : %d, %d, %d, %d ,%d\n", vpd1[0], vpd1[1], vpd1[2], vpd1[3], vpd1[4]);
3445 /* Generate the vpd arrays */
3446 for (i=0; i<boundary1+1+6; i++)
3448 vpd_chain3[i] = zfGetInterpolatedValue(i, &pwr0[0], &vpd0[0]);
3450 for (; i<powerTxMax+1+6+6; i++)
3452 vpd_chain3[i] = zfGetInterpolatedValue(i-6-6, &pwr1[0], &vpd1[0]);
3454 #ifdef ZM_ENABLE_TPC_WINDOWS_DEBUG
3455 DbgPrint("vpd_chain3\n");
3456 for (i=0; i<powerTxMax+1+6+6; i+=10)
3458 DbgPrint("%d, %d, %d, %d ,%d, %d, %d, %d, %d, %d\n",
3459 vpd_chain3[i+0], vpd_chain3[i+1], vpd_chain3[i+2], vpd_chain3[i+3], vpd_chain3[i+4],
3460 vpd_chain3[i+5], vpd_chain3[i+6], vpd_chain3[i+7], vpd_chain3[i+8], vpd_chain3[i+9]);
3464 /* Write PHY regs 672-703 + 0x1000 */
3465 for (i=0; i<128; i+=4)
3467 u32_t regAddr = 0x9800 + (672 * 4) + 0x1000;
3470 val = ((u32_t)vpd_chain3[i+3]<<24) |
3471 ((u32_t)vpd_chain3[i+2]<<16) |
3472 ((u32_t)vpd_chain3[i+1]<<8) |
3473 ((u32_t)vpd_chain3[i]);
3475 #ifndef ZM_OTUS_LINUX_PHASE_2
3476 reg_write(regAddr + i, val); /* CR672 */
3480 zfFlushDelayWrite(dev);
3482 /* 3. Generate target power table */
3483 if (frequency < 3000)
3487 if (eepromImage->calTargetPowerCck[i].bChannel != 0xff)
3489 fbinArray[i] = eepromImage->calTargetPowerCck[i].bChannel;
3497 index = zfFindFreqIndex(fbin, fbinArray, i);
3498 #ifdef ZM_ENABLE_TPC_WINDOWS_DEBUG
3499 DbgPrint("CCK index=%d\n", index);
3503 hpPriv->tPow2xCck[i] = zfInterpolateFuncX(fbin,
3504 eepromImage->calTargetPowerCck[index].bChannel,
3505 eepromImage->calTargetPowerCck[index].tPow2x[i],
3506 eepromImage->calTargetPowerCck[index+1].bChannel,
3507 eepromImage->calTargetPowerCck[index+1].tPow2x[i]
3513 if (eepromImage->calTargetPower2G[i].bChannel != 0xff)
3515 fbinArray[i] = eepromImage->calTargetPower2G[i].bChannel;
3523 index = zfFindFreqIndex(fbin, fbinArray, i);
3524 #ifdef ZM_ENABLE_TPC_WINDOWS_DEBUG
3525 DbgPrint("2G index=%d\n", index);
3529 hpPriv->tPow2x2g[i] = zfInterpolateFuncX(fbin,
3530 eepromImage->calTargetPower2G[index].bChannel,
3531 eepromImage->calTargetPower2G[index].tPow2x[i],
3532 eepromImage->calTargetPower2G[index+1].bChannel,
3533 eepromImage->calTargetPower2G[index+1].tPow2x[i]
3539 if (eepromImage->calTargetPower2GHT20[i].bChannel != 0xff)
3541 fbinArray[i] = eepromImage->calTargetPower2GHT20[i].bChannel;
3549 index = zfFindFreqIndex(fbin, fbinArray, i);
3550 #ifdef ZM_ENABLE_TPC_WINDOWS_DEBUG
3551 DbgPrint("2G HT20 index=%d\n", index);
3555 hpPriv->tPow2x2gHt20[i] = zfInterpolateFuncX(fbin,
3556 eepromImage->calTargetPower2GHT20[index].bChannel,
3557 eepromImage->calTargetPower2GHT20[index].tPow2x[i],
3558 eepromImage->calTargetPower2GHT20[index+1].bChannel,
3559 eepromImage->calTargetPower2GHT20[index+1].tPow2x[i]
3565 if (eepromImage->calTargetPower2GHT40[i].bChannel != 0xff)
3567 fbinArray[i] = eepromImage->calTargetPower2GHT40[i].bChannel;
3575 index = zfFindFreqIndex( (u8_t)zfAdjustHT40FreqOffset(dev, fbin, bw40, extOffset), fbinArray, i);
3576 #ifdef ZM_ENABLE_TPC_WINDOWS_DEBUG
3577 DbgPrint("2G HT40 index=%d\n", index);
3581 hpPriv->tPow2x2gHt40[i] = zfInterpolateFuncX(
3582 (u8_t)zfAdjustHT40FreqOffset(dev, fbin, bw40, extOffset),
3583 eepromImage->calTargetPower2GHT40[index].bChannel,
3584 eepromImage->calTargetPower2GHT40[index].tPow2x[i],
3585 eepromImage->calTargetPower2GHT40[index+1].bChannel,
3586 eepromImage->calTargetPower2GHT40[index+1].tPow2x[i]
3590 zfPrintTargetPower2G(hpPriv->tPow2xCck,
3592 hpPriv->tPow2x2gHt20,
3593 hpPriv->tPow2x2gHt40);
3600 if (eepromImage->calTargetPower5G[i].bChannel != 0xff)
3602 fbinArray[i] = eepromImage->calTargetPower5G[i].bChannel;
3610 index = zfFindFreqIndex(fbin, fbinArray, i);
3611 #ifdef ZM_ENABLE_TPC_WINDOWS_DEBUG
3612 DbgPrint("5G index=%d\n", index);
3616 hpPriv->tPow2x5g[i] = zfInterpolateFuncX(fbin,
3617 eepromImage->calTargetPower5G[index].bChannel,
3618 eepromImage->calTargetPower5G[index].tPow2x[i],
3619 eepromImage->calTargetPower5G[index+1].bChannel,
3620 eepromImage->calTargetPower5G[index+1].tPow2x[i]
3626 if (eepromImage->calTargetPower5GHT20[i].bChannel != 0xff)
3628 fbinArray[i] = eepromImage->calTargetPower5GHT20[i].bChannel;
3636 index = zfFindFreqIndex(fbin, fbinArray, i);
3637 #ifdef ZM_ENABLE_TPC_WINDOWS_DEBUG
3638 DbgPrint("5G HT20 index=%d\n", index);
3642 hpPriv->tPow2x5gHt20[i] = zfInterpolateFuncX(fbin,
3643 eepromImage->calTargetPower5GHT20[index].bChannel,
3644 eepromImage->calTargetPower5GHT20[index].tPow2x[i],
3645 eepromImage->calTargetPower5GHT20[index+1].bChannel,
3646 eepromImage->calTargetPower5GHT20[index+1].tPow2x[i]
3652 if (eepromImage->calTargetPower5GHT40[i].bChannel != 0xff)
3654 fbinArray[i] = eepromImage->calTargetPower5GHT40[i].bChannel;
3662 index = zfFindFreqIndex((u8_t)zfAdjustHT40FreqOffset(dev, fbin, bw40, extOffset), fbinArray, i);
3663 #ifdef ZM_ENABLE_TPC_WINDOWS_DEBUG
3664 DbgPrint("5G HT40 index=%d\n", index);
3668 hpPriv->tPow2x5gHt40[i] = zfInterpolateFuncX(
3669 (u8_t)zfAdjustHT40FreqOffset(dev, fbin, bw40, extOffset),
3670 eepromImage->calTargetPower5GHT40[index].bChannel,
3671 eepromImage->calTargetPower5GHT40[index].tPow2x[i],
3672 eepromImage->calTargetPower5GHT40[index+1].bChannel,
3673 eepromImage->calTargetPower5GHT40[index+1].tPow2x[i]
3677 zfPrintTargetPower5G(
3679 hpPriv->tPow2x5gHt20,
3680 hpPriv->tPow2x5gHt40);
3687 * 4.1 Get the bandedges tx power by frequency
3688 * 2.4G we get ctlEdgesMaxPowerCCK
3689 * ctlEdgesMaxPower2G
3690 * ctlEdgesMaxPower2GHT20
3691 * ctlEdgesMaxPower2GHT40
3692 * 5G we get ctlEdgesMaxPower5G
3693 * ctlEdgesMaxPower5GHT20
3694 * ctlEdgesMaxPower5GHT40
3695 * 4.2 Update (3.) target power table by 4.1
3696 * 4.3 Tx power offset for ART - NDIS/MDK
3697 * 4.4 Write MAC reg 0x694 for ACK's TPC
3701 //zfDumpEepBandEdges(eepromImage);
3703 /* get the cfg from Eeprom: regionCode => RegulatoryDomain : 0x10-FFC 0x30-eu 0x40-jap */
3704 desired_CtlIndex = zfHpGetRegulatoryDomain(dev);
3705 if ((desired_CtlIndex == 0x30) || (desired_CtlIndex == 0x40) || (desired_CtlIndex == 0x0))
3707 /* skip CTL and heavy clip */
3708 hpPriv->enableBBHeavyClip = 0;
3709 #ifdef ZM_ENABLE_BANDEDGES_WINDOWS_DEBUG
3710 zm_dbg(("RegulatoryDomain = 0, skip CTL and heavy clip\n"));
3715 hpPriv->enableBBHeavyClip = 1;
3717 if (desired_CtlIndex == 0xff)
3719 /* desired index not found */
3720 desired_CtlIndex = 0x10;
3723 /* first part : 2.4G */
3724 if (frequency <= ZM_CH_G_14)
3726 /* 2.4G - CTL_11B */
3727 ctl_i = zfFindCtlEdgesIndex(dev, desired_CtlIndex|CTL_11B);
3728 if(ctl_i<AR5416_NUM_CTLS)
3730 ctlEdgesMaxPowerCCK = zfGetMaxEdgePower(dev, eepromImage->ctlData[ctl_i].ctlEdges[1], frequency);
3732 #ifdef ZM_ENABLE_BANDEDGES_WINDOWS_DEBUG
3733 zm_dbg(("CTL_11B ctl_i = %d\n", ctl_i));
3736 /* 2.4G - CTL_11G */
3737 ctl_i = zfFindCtlEdgesIndex(dev, desired_CtlIndex|CTL_11G);
3738 if(ctl_i<AR5416_NUM_CTLS)
3740 ctlEdgesMaxPower2G = zfGetMaxEdgePower(dev, eepromImage->ctlData[ctl_i].ctlEdges[1], frequency);
3742 #ifdef ZM_ENABLE_BANDEDGES_WINDOWS_DEBUG
3743 zm_dbg(("CTL_11G ctl_i = %d\n", ctl_i));
3746 /* 2.4G - CTL_2GHT20 */
3747 ctl_i = zfFindCtlEdgesIndex(dev, desired_CtlIndex|CTL_2GHT20);
3748 if(ctl_i<AR5416_NUM_CTLS)
3750 ctlEdgesMaxPower2GHT20 = zfGetMaxEdgePower(dev, eepromImage->ctlData[ctl_i].ctlEdges[1], frequency);
3754 /* workaround for no data in Eeprom, replace by normal 2G */
3755 ctlEdgesMaxPower2GHT20 = ctlEdgesMaxPower2G;
3757 #ifdef ZM_ENABLE_BANDEDGES_WINDOWS_DEBUG
3758 zm_dbg(("CTL_2GHT20 ctl_i = %d\n", ctl_i));
3761 /* 2.4G - CTL_2GHT40 */
3762 ctl_i = zfFindCtlEdgesIndex(dev, desired_CtlIndex|CTL_2GHT40);
3763 if(ctl_i<AR5416_NUM_CTLS)
3765 ctlEdgesMaxPower2GHT40 = zfGetMaxEdgePower(dev, eepromImage->ctlData[ctl_i].ctlEdges[1],
3766 zfAdjustHT40FreqOffset(dev, frequency, bw40, extOffset));
3770 /* workaround for no data in Eeprom, replace by normal 2G */
3771 ctlEdgesMaxPower2GHT40 = ctlEdgesMaxPower2G;
3773 #ifdef ZM_ENABLE_BANDEDGES_WINDOWS_DEBUG
3774 zm_dbg(("CTL_2GHT40 ctl_i = %d\n", ctl_i));
3779 /* Max power (dBm) for channel range when using DFS define by madwifi*/
3780 for (i=0; i<wd->regulationTable.allowChannelCnt; i++)
3782 if (wd->regulationTable.allowChannel[i].channel == frequency)
3784 if (zfHpIsDfsChannel(dev, (u16_t)frequency))
3786 zm_debug_msg1("frequency use DFS -- ", frequency);
3787 ctlEdgesMaxPowerCCK = zm_min(ctlEdgesMaxPowerCCK, wd->regulationTable.allowChannel[i].maxRegTxPower*2);
3788 ctlEdgesMaxPower2G = zm_min(ctlEdgesMaxPower2G, wd->regulationTable.allowChannel[i].maxRegTxPower*2);
3789 ctlEdgesMaxPower2GHT20 = zm_min(ctlEdgesMaxPower2GHT20, wd->regulationTable.allowChannel[i].maxRegTxPower*2);
3790 ctlEdgesMaxPower2GHT40 = zm_min(ctlEdgesMaxPower2GHT40, wd->regulationTable.allowChannel[i].maxRegTxPower*2);
3796 /* Apply ctl mode to correct target power set */
3797 #ifdef ZM_ENABLE_BANDEDGES_WINDOWS_DEBUG
3798 zm_debug_msg1("ctlEdgesMaxPowerCCK = ", ctlEdgesMaxPowerCCK);
3799 zm_debug_msg1("ctlEdgesMaxPower2G = ", ctlEdgesMaxPower2G);
3800 zm_debug_msg1("ctlEdgesMaxPower2GHT20 = ", ctlEdgesMaxPower2GHT20);
3801 zm_debug_msg1("ctlEdgesMaxPower2GHT40 = ", ctlEdgesMaxPower2GHT40);
3805 hpPriv->tPow2xCck[i] = zm_min(hpPriv->tPow2xCck[i], ctlEdgesMaxPowerCCK) + HALTX_POWER_OFFSET;
3807 hpPriv->tPow2x2g24HeavyClipOffset = 0;
3808 if (hpPriv->enableBBHeavyClip)
3818 if (((frequency == 2412) || (frequency == 2462)))
3822 hpPriv->tPow2x2g[i] = zm_min(hpPriv->tPow2x2g[i], ctlEdgesMaxPower2G-ctlOffset) + HALTX_POWER_OFFSET;
3826 hpPriv->tPow2x2g[i] = zm_min(hpPriv->tPow2x2g[i], ctlEdgesMaxPower2G) + HALTX_POWER_OFFSET;
3827 if (hpPriv->tPow2x2g[i] > (ctlEdgesMaxPower2G-ctlOffset))
3829 hpPriv->tPow2x2g24HeavyClipOffset = hpPriv->tPow2x2g[i] - (ctlEdgesMaxPower2G-ctlOffset);
3835 hpPriv->tPow2x2g[i] = zm_min(hpPriv->tPow2x2g[i], ctlEdgesMaxPower2G) + HALTX_POWER_OFFSET;
3840 if (((frequency == 2412) || (frequency == 2462)) && (i>=3))
3842 hpPriv->tPow2x2gHt20[i] = zm_min(hpPriv->tPow2x2gHt20[i], ctlEdgesMaxPower2GHT20-ctlOffset) + HALTX_POWER_OFFSET;
3846 hpPriv->tPow2x2gHt20[i] = zm_min(hpPriv->tPow2x2gHt20[i], ctlEdgesMaxPower2GHT20) + HALTX_POWER_OFFSET;
3851 if ((frequency == 2412) && (i>=3))
3853 hpPriv->tPow2x2gHt40[i] = zm_min(hpPriv->tPow2x2gHt40[i], ctlEdgesMaxPower2GHT40-ctlOffset) + HALTX_POWER_OFFSET;
3855 else if ((frequency == 2462) && (i>=3))
3857 hpPriv->tPow2x2gHt40[i] = zm_min(hpPriv->tPow2x2gHt40[i], ctlEdgesMaxPower2GHT40-(ctlOffset*2)) + HALTX_POWER_OFFSET;
3861 hpPriv->tPow2x2gHt40[i] = zm_min(hpPriv->tPow2x2gHt40[i], ctlEdgesMaxPower2GHT40) + HALTX_POWER_OFFSET;
3868 ctl_i = zfFindCtlEdgesIndex(dev, desired_CtlIndex|CTL_11A);
3869 if(ctl_i<AR5416_NUM_CTLS)
3871 ctlEdgesMaxPower5G = zfGetMaxEdgePower(dev, eepromImage->ctlData[ctl_i].ctlEdges[1], frequency);
3873 #ifdef ZM_ENABLE_BANDEDGES_WINDOWS_DEBUG
3874 zm_dbg(("CTL_11A ctl_i = %d\n", ctl_i));
3877 /* 5G - CTL_5GHT20 */
3878 ctl_i = zfFindCtlEdgesIndex(dev, desired_CtlIndex|CTL_5GHT20);
3879 if(ctl_i<AR5416_NUM_CTLS)
3881 ctlEdgesMaxPower5GHT20 = zfGetMaxEdgePower(dev, eepromImage->ctlData[ctl_i].ctlEdges[1], frequency);
3885 /* workaround for no data in Eeprom, replace by normal 5G */
3886 ctlEdgesMaxPower5GHT20 = ctlEdgesMaxPower5G;
3888 #ifdef ZM_ENABLE_BANDEDGES_WINDOWS_DEBUG
3889 zm_dbg(("CTL_5GHT20 ctl_i = %d\n", ctl_i));
3892 /* 5G - CTL_5GHT40 */
3893 ctl_i = zfFindCtlEdgesIndex(dev, desired_CtlIndex|CTL_5GHT40);
3894 if(ctl_i<AR5416_NUM_CTLS)
3896 ctlEdgesMaxPower5GHT40 = zfGetMaxEdgePower(dev, eepromImage->ctlData[ctl_i].ctlEdges[1],
3897 zfAdjustHT40FreqOffset(dev, frequency, bw40, extOffset));
3901 /* workaround for no data in Eeprom, replace by normal 5G */
3902 ctlEdgesMaxPower5GHT40 = ctlEdgesMaxPower5G;
3904 #ifdef ZM_ENABLE_BANDEDGES_WINDOWS_DEBUG
3905 zm_dbg(("CTL_5GHT40 ctl_i = %d\n", ctl_i));
3909 /* Max power (dBm) for channel range when using DFS define by madwifi*/
3910 for (i=0; i<wd->regulationTable.allowChannelCnt; i++)
3912 if (wd->regulationTable.allowChannel[i].channel == frequency)
3914 if (zfHpIsDfsChannel(dev, (u16_t)frequency))
3916 zm_debug_msg1("frequency use DFS -- ", frequency);
3917 ctlEdgesMaxPower5G = zm_min(ctlEdgesMaxPower5G, wd->regulationTable.allowChannel[i].maxRegTxPower*2);
3918 ctlEdgesMaxPower5GHT20 = zm_min(ctlEdgesMaxPower5GHT20, wd->regulationTable.allowChannel[i].maxRegTxPower*2);
3919 ctlEdgesMaxPower5GHT40 = zm_min(ctlEdgesMaxPower5GHT40, wd->regulationTable.allowChannel[i].maxRegTxPower*2);
3926 /* Apply ctl mode to correct target power set */
3927 #ifdef ZM_ENABLE_BANDEDGES_WINDOWS_DEBUG
3928 zm_debug_msg1("ctlEdgesMaxPower5G = ", ctlEdgesMaxPower5G);
3929 zm_debug_msg1("ctlEdgesMaxPower5GHT20 = ", ctlEdgesMaxPower5GHT20);
3930 zm_debug_msg1("ctlEdgesMaxPower5GHT40 = ", ctlEdgesMaxPower5GHT40);
3934 hpPriv->tPow2x5g[i] = zm_min(hpPriv->tPow2x5g[i], ctlEdgesMaxPower5G) + HALTX_POWER_OFFSET;
3938 hpPriv->tPow2x5gHt20[i] = zm_min(hpPriv->tPow2x5gHt20[i], ctlEdgesMaxPower5GHT20) + HALTX_POWER_OFFSET;
3942 hpPriv->tPow2x5gHt40[i] = zm_min(hpPriv->tPow2x5gHt40[i], ctlEdgesMaxPower5GHT40) + HALTX_POWER_OFFSET;
3945 }/* end of bandedges of 5G */
3946 }/* end of if ((desired_CtlIndex = zfHpGetRegulatoryDomain(dev)) == 0) */
3949 /* 5. BB heavy clip */
3950 /* only 2.4G do heavy clip */
3951 if (hpPriv->enableBBHeavyClip && hpPriv->hwBBHeavyClip && (frequency <= ZM_CH_G_14))
3953 if (frequency <= ZM_CH_G_14)
3955 ctl_i = zfFindCtlEdgesIndex(dev, desired_CtlIndex|CTL_11G);
3959 ctl_i = zfFindCtlEdgesIndex(dev, desired_CtlIndex|CTL_11A);
3962 hpPriv->setValueHeavyClip = zfHpCheckDoHeavyClip(dev, frequency, eepromImage->ctlData[ctl_i].ctlEdges[1], bw40);
3964 if (hpPriv->setValueHeavyClip)
3966 hpPriv->doBBHeavyClip = 1;
3970 hpPriv->doBBHeavyClip = 0;
3972 #ifdef ZM_ENABLE_BANDEDGES_WINDOWS_DEBUG
3973 zm_dbg(("zfHpCheckDoHeavyClip ret = %02x, doBBHeavyClip = %d\n",
3974 hpPriv->setValueHeavyClip, hpPriv->doBBHeavyClip));
3977 if (hpPriv->doBBHeavyClip)
3979 if (hpPriv->setValueHeavyClip & 0xf0)
3981 hpPriv->tPow2x2gHt40[0] -= 1;
3982 hpPriv->tPow2x2gHt40[1] -= 1;
3983 hpPriv->tPow2x2gHt40[2] -= 1;
3986 if (hpPriv->setValueHeavyClip & 0xf)
3988 hpPriv->tPow2x2gHt20[0] += 1;
3989 hpPriv->tPow2x2gHt20[1] += 1;
3990 hpPriv->tPow2x2gHt20[2] += 1;
3996 hpPriv->doBBHeavyClip = 0;
3997 hpPriv->setValueHeavyClip = 0;
4000 /* Final : write MAC register for some ctrl frame Tx power */
4001 /* first part : 2.4G */
4002 if (frequency <= ZM_CH_G_14)
4004 /* Write MAC reg 0x694 for ACK's TPC */
4005 /* Write MAC reg 0xbb4 RTS and SF-CTS frame power control */
4006 /* Always use two stream for low legacy rate */
4008 //if (hpPriv->halCapability & ZM_HP_CAP_11N_ONE_TX_STREAM)
4010 zfDelayWriteInternalReg(dev, 0x1c3694, ((hpPriv->tPow2x2g[0]&0x3f) << 20) | (0x1<<26));
4011 zfDelayWriteInternalReg(dev, 0x1c3bb4, ((hpPriv->tPow2x2g[0]&0x3f) << 5 ) | (0x1<<11) |
4012 ((hpPriv->tPow2x2g[0]&0x3f) << 21) | (0x1<<27) );
4018 #ifndef ZM_OTUS_LINUX_PHASE_2
4019 zfDelayWriteInternalReg(dev, 0x1c3694, ((hpPriv->tPow2x2g[0]&0x3f) << 20) | (0x5<<26));
4020 zfDelayWriteInternalReg(dev, 0x1c3bb4, ((hpPriv->tPow2x2g[0]&0x3f) << 5 ) | (0x5<<11) |
4021 ((hpPriv->tPow2x2g[0]&0x3f) << 21) | (0x5<<27) );
4023 hpPriv->currentAckRtsTpc = hpPriv->tPow2x2g[0];
4026 zfFlushDelayWrite(dev);
4028 zfPrintTargetPower2G(hpPriv->tPow2xCck,
4030 hpPriv->tPow2x2gHt20,
4031 hpPriv->tPow2x2gHt40);
4035 /* Write MAC reg 0x694 for ACK's TPC */
4036 /* Write MAC reg 0xbb4 RTS and SF-CTS frame power control */
4037 /* Always use two stream for low legacy rate */
4038 if (hpPriv->halCapability & ZM_HP_CAP_11N_ONE_TX_STREAM)
4040 #ifndef ZM_OTUS_LINUX_PHASE_2
4041 zfDelayWriteInternalReg(dev, 0x1c3694, ((hpPriv->tPow2x5g[0]&0x3f) << 20) | (0x1<<26));
4042 zfDelayWriteInternalReg(dev, 0x1c3bb4, ((hpPriv->tPow2x5g[0]&0x3f) << 5 ) | (0x1<<11) |
4043 ((hpPriv->tPow2x5g[0]&0x3f) << 21) | (0x1<<27) );
4048 #ifndef ZM_OTUS_LINUX_PHASE_2
4049 zfDelayWriteInternalReg(dev, 0x1c3694, ((hpPriv->tPow2x5g[0]&0x3f) << 20) | (0x5<<26));
4050 zfDelayWriteInternalReg(dev, 0x1c3bb4, ((hpPriv->tPow2x5g[0]&0x3f) << 5 ) | (0x5<<11) |
4051 ((hpPriv->tPow2x5g[0]&0x3f) << 21) | (0x5<<27) );
4053 hpPriv->currentAckRtsTpc = hpPriv->tPow2x2g[0];
4057 zfFlushDelayWrite(dev);
4059 zfPrintTargetPower5G(
4061 hpPriv->tPow2x5gHt20,
4062 hpPriv->tPow2x5gHt40);
4063 }/* end of bandedges of 5G */
4067 void zfDumpEepBandEdges(struct ar5416Eeprom* eepromImage)
4069 #ifdef ZM_ENABLE_BANDEDGES_WINDOWS_DEBUG
4073 zm_dbg(("\n === BandEdges index dump ==== \n"));
4075 for (i = 0; i < AR5416_NUM_CTLS; i++)
4077 zm_dbg(("%02x ", eepromImage->ctlIndex[i]));
4080 zm_dbg(("\n === BandEdges data dump ==== \n"));
4082 for (i = 0; i < AR5416_NUM_CTLS; i++)
4084 for (j = 0; j < 2; j++)
4086 for(k = 0; k < AR5416_NUM_BAND_EDGES; k++)
4088 u8_t *pdata = (u8_t*)&(eepromImage->ctlData[i].ctlEdges[j][k]);
4089 zm_dbg(("(%02x %02x)", pdata[0], pdata[1]));
4095 zm_dbg(("\n === BandEdges index dump ==== \n"));
4096 for (i = 0; i < 24; i+=8)
4098 zm_dbg(("%02x %02x %02x %02x %02x %02x %02x %02x",
4099 eepromImage->ctlIndex[i+0], eepromImage->ctlIndex[i+1], eepromImage->ctlIndex[i+2], eepromImage->ctlIndex[i+3],
4100 eepromImage->ctlIndex[i+4], eepromImage->ctlIndex[i+5], eepromImage->ctlIndex[i+6], eepromImage->ctlIndex[i+7]
4104 zm_dbg(("\n === BandEdges data dump ==== \n"));
4106 for (i = 0; i < AR5416_NUM_CTLS; i++)
4108 for (j = 0; j < 2; j++)
4110 u8_t *pdata = (u8_t*)&(eepromImage->ctlData[i].ctlEdges[j]);
4111 zm_dbg(("(%03d %02x) (%03d %02x) (%03d %02x) (%03d %02x) \n",
4112 pdata[0], pdata[1], pdata[2], pdata[3],
4113 pdata[4], pdata[5], pdata[6], pdata[7]
4115 zm_dbg(("(%03d %02x) (%03d %02x) (%03d %02x) (%03d %02x) \n",
4116 pdata[8], pdata[9], pdata[10], pdata[11],
4117 pdata[12], pdata[13], pdata[14], pdata[15]
4125 void zfPrintTargetPower2G(u8_t* tPow2xCck, u8_t* tPow2x2g, u8_t* tPow2x2gHt20, u8_t* tPow2x2gHt40)
4127 //#ifdef ZM_ENABLE_TPC_WINDOWS_DEBUG
4128 #ifdef ZM_ENABLE_BANDEDGES_WINDOWS_DEBUG
4129 DbgPrint("targetPwr CCK : %d, %d, %d, %d\n",
4135 DbgPrint("targetPwr 2G : %d, %d, %d, %d\n",
4141 DbgPrint("targetPwr 2GHT20 : %d, %d, %d, %d, %d, %d, %d, %d\n",
4151 DbgPrint("targetPwr 2GHT40 : %d, %d, %d, %d, %d, %d, %d, %d\n",
4165 void zfPrintTargetPower5G(u8_t* tPow2x5g, u8_t* tPow2x5gHt20, u8_t* tPow2x5gHt40)
4167 //#ifdef ZM_ENABLE_TPC_WINDOWS_DEBUG
4168 #ifdef ZM_ENABLE_BANDEDGES_WINDOWS_DEBUG
4169 DbgPrint("targetPwr 5G : %d, %d, %d, %d\n",
4175 DbgPrint("targetPwr 5GHT20 : %d, %d, %d, %d, %d, %d, %d, %d\n",
4185 DbgPrint("targetPwr 5GHT40 : %d, %d, %d, %d, %d, %d, %d, %d\n",
4199 void zfHpPowerSaveSetMode(zdev_t* dev, u8_t staMode, u8_t psMode, u16_t bcnInterval)
4205 // Turn off pre-TBTT interrupt
4206 zfDelayWriteInternalReg(dev, ZM_MAC_REG_PRETBTT, 0);
4207 zfDelayWriteInternalReg(dev, ZM_MAC_REG_BCN_PERIOD, 0);
4208 zfFlushDelayWrite(dev);
4212 // Turn on pre-TBTT interrupt
4213 zfDelayWriteInternalReg(dev, ZM_MAC_REG_PRETBTT, (bcnInterval-6)<<16);
4214 zfDelayWriteInternalReg(dev, ZM_MAC_REG_BCN_PERIOD, bcnInterval);
4215 zfFlushDelayWrite(dev);
4220 void zfHpPowerSaveSetState(zdev_t* dev, u8_t psState)
4222 zmw_get_wlan_dev(dev);
4223 struct zsHpPriv* hpPriv = wd->hpPrivate;
4225 //DbgPrint("INTO zfHpPowerSaveSetState");
4227 if ( psState == 0 ) //power up
4229 //DbgPrint("zfHpPowerSaveSetState Wake up from PS\n");
4230 reg_write(0x982C, 0x0000a000); //wake up ADDAC
4231 reg_write(0x9808, 0x0); //enable all agc gain and offset updates to a2
4233 if (((struct zsHpPriv*)wd->hpPrivate)->hwFrequency <= ZM_CH_G_14)
4236 //reg_write (0x98f0, 0x01c00018);
4237 reg_write (0x98f0, 0x01c20098);//syn_on+RX_ON
4242 //reg_write (0x98f0, 0x01400018);
4243 reg_write (0x98f0, 0x01420098);//syn_on+RX_ON
4247 //reg_write(0x98b0, 0x00000013);
4248 //reg_write(0x98e4, 0x00000002);
4251 zfFlushDelayWrite(dev);
4255 //DbgPrint("zfHpPowerSaveSetState Go to PS\n");
4256 //reg_write(0x982C, 0xa000a000);
4257 reg_write(0x9808, 0x8000000); //disable all agc gain and offset updates to a2
4258 reg_write(0x982C, 0xa000a000); //power down ADDAC
4260 if (((struct zsHpPriv*)wd->hpPrivate)->hwFrequency <= ZM_CH_G_14)
4263 reg_write (0x98f0, 0x00c00018);//syn_off+RX_off
4268 reg_write (0x98f0, 0x00400018);//syn_off+RX_off
4272 //reg_write(0x98b0, 0x000e0013);
4273 //reg_write(0x98e4, 0x00018002);
4276 zfFlushDelayWrite(dev);
4280 void zfHpSetAggPktNum(zdev_t* dev, u32_t num)
4282 zmw_get_wlan_dev(dev);
4283 struct zsHpPriv* hpPriv = wd->hpPrivate;
4285 num = (num << 16) | (0xa);
4287 hpPriv->aggPktNum = num;
4289 //aggregation number will be update in HAL heart beat
4290 //zfDelayWriteInternalReg(dev, 0x1c3b9c, num);
4291 //zfFlushDelayWrite(dev);
4294 void zfHpSetMPDUDensity(zdev_t* dev, u8_t density)
4298 if (density > ZM_MPDU_DENSITY_8US)
4303 /* Default value in this register */
4304 value = 0x140A00 | density;
4306 zfDelayWriteInternalReg(dev, 0x1c3ba0, value);
4307 zfFlushDelayWrite(dev);
4311 void zfHpSetSlotTime(zdev_t* dev, u8_t type)
4313 zmw_get_wlan_dev(dev);
4314 struct zsHpPriv* hpPriv = wd->hpPrivate;
4318 //normal slot = 20us
4319 hpPriv->slotType = 0;
4321 else //if (type == 1)
4324 hpPriv->slotType = 1;
4330 void zfHpSetSlotTimeRegister(zdev_t* dev, u8_t type)
4334 //normal slot = 20us
4335 zfDelayWriteInternalReg(dev, ZM_MAC_REG_SLOT_TIME, 20<<10);
4340 zfDelayWriteInternalReg(dev, ZM_MAC_REG_SLOT_TIME, 9<<10);
4344 void zfHpSetRifs(zdev_t* dev, u8_t ht_enable, u8_t ht2040, u8_t g_mode)
4346 zfDelayWriteInternalReg(dev, 0x1c6388, 0x0c000000);
4348 zfDelayWriteInternalReg(dev, 0x1c59ec, 0x0cc80caa);
4354 zfDelayWriteInternalReg(dev, 0x1c5918, 40);
4358 zfDelayWriteInternalReg(dev, 0x1c5918, 20);
4364 zfDelayWriteInternalReg(dev, 0x1c5850, 0xec08b4e2);
4365 zfDelayWriteInternalReg(dev, 0x1c585c, 0x313a5d5e);
4369 zfDelayWriteInternalReg(dev, 0x1c5850, 0xede8b4e0);
4370 zfDelayWriteInternalReg(dev, 0x1c585c, 0x3139605e);
4373 zfFlushDelayWrite(dev);
4377 void zfHpBeginSiteSurvey(zdev_t* dev, u8_t status)
4379 zmw_get_wlan_dev(dev);
4380 struct zsHpPriv* hpPriv=wd->hpPrivate;
4384 hpPriv->isSiteSurvey = 1;
4388 hpPriv->isSiteSurvey = 0;
4391 /* reset workaround state to default */
4392 // if (hpPriv->rxStrongRSSI == 1)
4394 hpPriv->rxStrongRSSI = 0;
4395 if ((hpPriv->eepromImage[0x100+0x110*2/4]&0xff) == 0x80) //FEM TYPE
4397 if (hpPriv->hwFrequency <= ZM_CH_G_14)
4399 zfDelayWriteInternalReg(dev, 0x1c8960, 0x9b49);
4403 zfDelayWriteInternalReg(dev, 0x1c8960, 0x0900);
4408 zfDelayWriteInternalReg(dev, 0x1c8960, 0x9b40);
4410 zfFlushDelayWrite(dev);
4412 // if (hpPriv->strongRSSI == 1)
4414 hpPriv->strongRSSI = 0;
4415 zfDelayWriteInternalReg(dev, 0x1c3694, ((hpPriv->currentAckRtsTpc&0x3f) << 20) | (0x5<<26));
4416 zfDelayWriteInternalReg(dev, 0x1c3bb4, ((hpPriv->currentAckRtsTpc&0x3f) << 5 ) | (0x5<<11) |
4417 ((hpPriv->currentAckRtsTpc&0x3f) << 21) | (0x5<<27) );
4418 zfFlushDelayWrite(dev);
4422 void zfHpFinishSiteSurvey(zdev_t* dev, u8_t status)
4424 zmw_get_wlan_dev(dev);
4425 struct zsHpPriv* hpPriv=wd->hpPrivate;
4427 zmw_declare_for_critical_section();
4429 zmw_enter_critical_section(dev);
4432 hpPriv->isSiteSurvey = 2;
4436 hpPriv->isSiteSurvey = 0;
4438 zmw_leave_critical_section(dev);
4441 u16_t zfFwRetry(zdev_t* dev, u8_t enable)
4443 u32_t cmd[(ZM_MAX_CMD_SIZE/4)];
4446 cmd[0] = 4 | (0x92 << 8);
4447 cmd[1] = (enable == 1) ? 0x01 : 0x00;
4449 ret = zfIssueCmd(dev, cmd, 8, ZM_OID_INTERNAL_WRITE, NULL);
4453 u16_t zfHpEnableHwRetry(zdev_t* dev)
4457 ret = zfFwRetry(dev, 0);
4459 zfDelayWriteInternalReg(dev, 0x1c3b28, 0x33333);
4460 zfFlushDelayWrite(dev);
4465 u16_t zfHpDisableHwRetry(zdev_t* dev)
4469 ret = zfFwRetry(dev, 1);
4471 zfDelayWriteInternalReg(dev, 0x1c3b28, 0x00000);
4472 zfFlushDelayWrite(dev);
4477 /* Download SPI Fw */
4478 #define ZM_FIRMWARE_WLAN 0
4479 #define ZM_FIRMWARE_SPI_FLASH 1
4482 u16_t zfHpFirmwareDownload(zdev_t* dev, u8_t fwType)
4484 u16_t ret = ZM_SUCCESS;
4486 if (fwType == ZM_FIRMWARE_WLAN)
4488 ret = zfFirmwareDownload(dev, (u32_t*)zcFwImage,
4489 (u32_t)zcFwImageSize, ZM_FIRMWARE_WLAN_ADDR);
4491 else if (fwType == ZM_FIRMWARE_SPI_FLASH)
4493 ret = zfFirmwareDownload(dev, (u32_t*)zcFwImageSPI,
4494 (u32_t)zcFwImageSPISize, ZM_FIRMWARE_SPI_ADDR);
4498 zm_debug_msg1("Unknown firmware type = ", fwType);
4499 ret = ZM_ERR_FIRMWARE_WRONG_TYPE;
4505 /* Enable software decryption */
4506 void zfHpSWDecrypt(zdev_t* dev, u8_t enable)
4510 /* Bit 4 for enable software decryption */
4516 zfDelayWriteInternalReg(dev, 0x1c3678, value);
4517 zfFlushDelayWrite(dev);
4520 /* Enable software encryption */
4521 void zfHpSWEncrypt(zdev_t* dev, u8_t enable)
4523 /* Because encryption by software or hardware is judged by driver in Otus,
4524 we don't need to do anything in the HAL layer.
4528 u32_t zfHpCapability(zdev_t* dev)
4530 zmw_get_wlan_dev(dev);
4531 struct zsHpPriv* hpPriv=wd->hpPrivate;
4533 return hpPriv->halCapability;
4536 void zfHpSetRollCallTable(zdev_t* dev)
4538 zmw_get_wlan_dev(dev);
4539 struct zsHpPriv* hpPriv=wd->hpPrivate;
4541 if (hpPriv->camRollCallTable != (u64_t) 0)
4543 zfDelayWriteInternalReg(dev, ZM_MAC_REG_ROLL_CALL_TBL_L, (u32_t)(hpPriv->camRollCallTable & 0xffffffff));
4544 zfDelayWriteInternalReg(dev, ZM_MAC_REG_ROLL_CALL_TBL_H, (u32_t)((hpPriv->camRollCallTable >> 32) & 0xffffffff));
4545 zfFlushDelayWrite(dev);
4549 void zfHpSetTTSIFSTime(zdev_t* dev, u8_t sifs_time)
4551 u32_t reg_value = 0;
4552 zmw_get_wlan_dev(dev);
4555 reg_value = 0x14400b | (((u32_t)sifs_time)<<24);
4557 zfDelayWriteInternalReg(dev, ZM_MAC_REG_EIFS_AND_SIFS, reg_value);
4558 zfFlushDelayWrite(dev);
4561 /* #3 Enable RIFS function if the RIFS pattern matched ! */
4562 void zfHpEnableRifs(zdev_t* dev, u8_t mode24g, u8_t modeHt, u8_t modeHt2040)
4565 /* # Enable Reset TDOMAIN
4566 * $rddata = &$phyreg_read(0x9800+(738<<2));
4567 * $wrdata = $rddata | (0x1 << 26) | (0x1 << 27);
4568 * &$phyreg_write(0x9800+(738<<2), $wrdata);
4570 reg_write (0x9800+(738<<2), 0x08000000 | (0x1 << 26) | (0x1 << 27));
4571 //reg_write (0x9800+(738<<2), 0x08000000 | (0x1 << 26));
4573 /* # reg 123: heavy clip factor, xr / RIFS search parameters */
4574 reg_write (0x99ec, 0x0cc80caa);
4576 /* # Reduce Search Start Delay for RIFS */
4577 if (modeHt == 1) /* ($HT_ENABLE == 1) */
4579 if (modeHt2040 == 0x1) /* ($DYNAMIC_HT2040_EN == 0x1) */
4581 reg_write(0x9800+(70<<2), 40);/*40*/
4585 reg_write(0x9800+(70<<2), 20);
4588 /* $rddata = &$phyreg_read(0x9800+(24<<2));#0x9860;0x1c5860
4589 *$wrdata = ($rddata & 0xffffffc7) | (0x4 << 3);
4590 * &$phyreg_write(0x9800+(24<<2), $wrdata);
4592 reg_write(0x9800+(24<<2), (0x0004dd10 & 0xffffffc7) | (0x4 << 3));
4599 reg_write(0x9850, 0xece8b4e4);/*org*/
4600 //reg_write(0x9850, 0xece8b4e2);
4601 reg_write(0x985c, 0x313a5d5e);
4605 reg_write(0x9850, 0xede8b4e4);
4606 reg_write(0x985c, 0x3139605e);
4609 zfFlushDelayWrite(dev);
4614 /* #4 Disable RIFS function if the RIFS timer is timeout ! */
4615 void zfHpDisableRifs(zdev_t* dev)
4617 zmw_get_wlan_dev(dev);
4619 /* Disable RIFS function is to store these HW register initial value while the device plug-in and
4620 re-write to these register if the RIFS function is disabled */
4623 reg_write(0x9850, ((struct zsHpPriv*)wd->hpPrivate)->initDesiredSigSize);
4626 reg_write(0x985c, ((struct zsHpPriv*)wd->hpPrivate)->initAGC);
4629 reg_write(0x9800+(24<<2), ((struct zsHpPriv*)wd->hpPrivate)->initAgcControl);
4632 reg_write(0x9800+(70<<2), ((struct zsHpPriv*)wd->hpPrivate)->initSearchStartDelay);
4635 reg_write (0x99ec, ((struct zsHpPriv*)wd->hpPrivate)->initRIFSSearchParams);
4638 reg_write (0x9800+(738<<2), ((struct zsHpPriv*)wd->hpPrivate)->initFastChannelChangeControl);
4640 zfFlushDelayWrite(dev);