NDIS_STATUS AsicBBPWriteWithRxChain( IN RTMP_ADAPTER *pAd, IN UCHAR bbpId, IN CHAR bbpVal, IN RX_CHAIN_IDX rx_ch_idx) { UCHAR idx = 0, val = 0; if (((pAd->MACVersion & 0xf0000000) < 0x28830000) || (pAd->Antenna.field.RxPath == 1)) { RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, bbpId, bbpVal); return NDIS_STATUS_SUCCESS; } while (rx_ch_idx != 0) { if (idx >= pAd->Antenna.field.RxPath) break; if (rx_ch_idx & 0x01) { RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R27, &val); val = (val & (~0x60)) | (idx << 5); #ifdef RTMP_MAC_USB if ((IS_USB_INF(pAd)) && (RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R27, val) == STATUS_SUCCESS)) { RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, bbpId, bbpVal); } #endif /* RTMP_MAC_USB */ DBGPRINT(RT_DEBUG_INFO, ("%s(Idx):Write(R%d,val:0x%x) to Chain(0x%x, idx:%d)\n", __FUNCTION__, bbpId, bbpVal, rx_ch_idx, idx)); } rx_ch_idx >>= 1; idx++; } return NDIS_STATUS_SUCCESS; }
NDIS_STATUS AsicBBPReadWithRxChain( IN RTMP_ADAPTER *pAd, IN UCHAR bbpId, IN CHAR *pBbpVal, IN RX_CHAIN_IDX rx_ch_idx) { UCHAR idx, val; if (((pAd->MACVersion & 0xffff0000) < 0x28830000) || (pAd->Antenna.field.RxPath == 1)) { RTMP_BBP_IO_READ8_BY_REG_ID(pAd, bbpId, pBbpVal); return NDIS_STATUS_SUCCESS; } idx = 0; while(rx_ch_idx != 0) { if (idx >= pAd->Antenna.field.RxPath) break; if (rx_ch_idx & 0x01) { val = 0; RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R27, &val); val = (val & (~0x60)) | (idx << 5); #ifdef RTMP_MAC_USB if ((IS_USB_INF(pAd)) && (RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R27, val) == STATUS_SUCCESS)) { RTMP_BBP_IO_READ8_BY_REG_ID(pAd, bbpId, pBbpVal); } #endif /* RTMP_MAC_USB */ break; } rx_ch_idx >>= 1; idx++; } return NDIS_STATUS_SUCCESS; }
NDIS_STATUS rlt_rf_write( IN PRTMP_ADAPTER pAd, IN UCHAR bank, IN UCHAR regID, IN UCHAR value) { RF_CSR_CFG_STRUC rfcsr = { { 0 } }; NDIS_STATUS ret; #ifdef RTMP_MAC_PCI if ((pAd->bPCIclkOff == TRUE) || (pAd->LastMCUCmd == SLEEP_MCU_CMD)) { DBGPRINT_ERR(("rlt_rf_write. Not allow to write RF 0x%x : fail\n", regID)); return STATUS_UNSUCCESSFUL; } #endif /* RTMP_MAC_PCI */ #ifdef RLT_MAC // TODO: shiang-usw, why we need to check this for MT7601?? Get these code from MT7601! if (pAd->chipCap.hif_type == HIF_RLT) { if (pAd->WlanFunCtrl.field.WLAN_EN == 0) { DBGPRINT_ERR(("rlt_rf_write. Not allow to write RF 0x%x : fail\n", regID)); return STATUS_UNSUCCESSFUL; } } #endif /* RLT_MAC */ #ifdef RTMP_MAC_USB if (IS_USB_INF(pAd)) { RTMP_SEM_EVENT_WAIT(&pAd->reg_atomic, ret); if (ret != 0) { DBGPRINT(RT_DEBUG_ERROR, ("reg_atomic get failed(ret=%d)\n", ret)); return STATUS_UNSUCCESSFUL; } } #endif /* RTMP_MAC_USB */ ASSERT((regID <= pAd->chipCap.MaxNumOfRfId)); ret = STATUS_UNSUCCESSFUL; if (rf_csr_poll_idle(pAd, &rfcsr.word) != IDLE) goto done; #ifdef RT6352 if (IS_RT6352(pAd)) { rfcsr.bank_6352.RF_CSR_WR = 1; rfcsr.bank_6352.RF_CSR_KICK = 1; rfcsr.bank_6352.TESTCSR_RFACC_REGNUM = (regID | (bank << 6)); rfcsr.bank_6352.RF_CSR_DATA = value; } else #endif /* RT6352 */ #ifdef RT65xx if (IS_RT65XX(pAd)) { rfcsr.bank_65xx.RF_CSR_WR = 1; rfcsr.bank_65xx.RF_CSR_KICK = 1; rfcsr.bank_65xx.RF_CSR_REG_BANK = bank; rfcsr.bank_65xx.RF_CSR_REG_ID = regID; rfcsr.bank_65xx.RF_CSR_DATA = value; } else #endif /* RT65xx */ { DBGPRINT_ERR(("%s():RF write with wrong handler!\n", __FUNCTION__)); goto done; } RTMP_IO_WRITE32(pAd, RF_CSR_CFG, rfcsr.word); ret = NDIS_STATUS_SUCCESS; done: #ifdef RTMP_MAC_USB if (IS_USB_INF(pAd)) { RTMP_SEM_EVENT_UP(&pAd->reg_atomic); } #endif /* RTMP_MAC_USB */ return ret; }
/* ======================================================================== Routine Description: Read RF register through MAC Arguments: Return Value: IRQL = Note: ======================================================================== */ NDIS_STATUS rlt_rf_read( IN RTMP_ADAPTER *pAd, IN UCHAR bank, IN UCHAR regID, IN UCHAR *pValue) { RF_CSR_CFG_STRUC rfcsr = { { 0 } }; UINT i=0, k=0; BOOLEAN rf_status; NDIS_STATUS ret = STATUS_UNSUCCESSFUL; #ifdef MT76x0 if (IS_MT7610U(pAd)) { BANK_RF_REG_PAIR reg; reg.Bank = bank; reg.Register = regID; RF_RANDOM_READ(pAd, ®, 1); *pValue = reg.Value; return NDIS_STATUS_SUCCESS; } #endif /* MT76x0 */ #ifdef RTMP_MAC_PCI if ((pAd->bPCIclkOff == TRUE) || (pAd->LastMCUCmd == SLEEP_MCU_CMD)) { DBGPRINT_ERR(("RT30xxReadRFRegister. Not allow to read RF 0x%x : fail\n", regID)); return STATUS_UNSUCCESSFUL; } #endif /* RTMP_MAC_PCI */ #ifdef RTMP_MAC_USB if (IS_USB_INF(pAd)) { RTMP_SEM_EVENT_WAIT(&pAd->reg_atomic, i); if (i != 0) { DBGPRINT(RT_DEBUG_ERROR, ("reg_atomic get failed(ret=%d)\n", i)); return STATUS_UNSUCCESSFUL; } } #endif /* RTMP_MAC_USB */ ASSERT((regID <= pAd->chipCap.MaxNumOfRfId)); rfcsr.word = 0; for (i=0; i<MAX_BUSY_COUNT; i++) { if(RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) goto done; rf_status = rf_csr_poll_idle(pAd, &rfcsr.word); if ( rf_status == BUSY) break; rfcsr.word = 0; #ifdef RT6352 if (IS_RT6352(pAd)) { rfcsr.bank_6352.RF_CSR_WR = 0; rfcsr.bank_6352.RF_CSR_KICK = 1; rfcsr.bank_6352.TESTCSR_RFACC_REGNUM = (regID | (bank << 6)); } else #endif /* RT6352 */ #ifdef RT65xx if (IS_RT65XX(pAd)) { rfcsr.bank_65xx.RF_CSR_WR = 0; rfcsr.bank_65xx.RF_CSR_KICK = 1; rfcsr.bank_65xx.RF_CSR_REG_ID = regID; rfcsr.bank_65xx.RF_CSR_REG_BANK = bank; } else #endif /* RT65xx */ { DBGPRINT_ERR(("RF[%d] read function for non-supported chip[0x%x]\n", regID, pAd->MACVersion)); break; } RTMP_IO_WRITE32(pAd, RF_CSR_CFG, rfcsr.word); rf_status = rf_csr_poll_idle(pAd, &rfcsr.word); if (rf_status == IDLE) { #ifdef RT6352 if (IS_RT6352(pAd) && ((rfcsr.bank_6352.TESTCSR_RFACC_REGNUM & 0x3F) == regID)) { *pValue = (UCHAR)(rfcsr.bank_6352.RF_CSR_DATA); break; } #endif /* RT6352 */ #ifdef RT65xx if (IS_RT65XX(pAd) && (rfcsr.bank_65xx.RF_CSR_REG_ID == regID) && (rfcsr.bank_65xx.RF_CSR_REG_BANK == bank)) { *pValue = (UCHAR)(rfcsr.bank_65xx.RF_CSR_DATA); break; } #endif /* RT65xx */ } } if (rf_status == BUSY) { DBGPRINT_ERR(("RF read R%d=0x%X fail, i[%d], k[%d]\n", regID, rfcsr.word,i,k)); goto done; } ret = STATUS_SUCCESS; #if 0 if (bank >= RF_BANK4) { printk("TESTCSR_RFACC_REGNUM = %x, RF_CSR_DATA = %x !!!\n", rfcsr.field.TESTCSR_RFACC_REGNUM, rfcsr.field.RF_CSR_DATA); } #endif done: #ifdef RTMP_MAC_USB if (IS_USB_INF(pAd)) { RTMP_SEM_EVENT_UP(&pAd->reg_atomic); } #endif /* RTMP_MAC_USB */ return ret; }
NDIS_STATUS MT7601_BBP_read( IN RTMP_ADAPTER *pAd, IN UCHAR regID, IN UCHAR *pValue) { BBP_CSR_CFG_STRUC BbpCsr = { { 0 } }; UINT i=0, k=0; NDIS_STATUS ret = STATUS_UNSUCCESSFUL; if (pAd->WlanFunCtrl.field.WLAN_EN == 0) { DBGPRINT_ERR(("MT7601_BBP_read. Not allow to read BBP 0x%x : fail\n", regID)); return STATUS_UNSUCCESSFUL; } #ifdef RTMP_MAC_USB if (IS_USB_INF(pAd)) { RTMP_SEM_EVENT_WAIT(&pAd->reg_atomic, i); if (i != 0) { DBGPRINT(RT_DEBUG_ERROR, ("reg_atomic get failed(ret=%d)\n", i)); return STATUS_UNSUCCESSFUL; } } #endif /* RTMP_MAC_USB */ ASSERT((regID <= pAd->chipCap.MaxNumOfBbpId)); for (i=0; i<MAX_BUSY_COUNT; i++) { if(RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) goto done; RTMP_IO_READ32(pAd, BBP_CSR_CFG, &BbpCsr.word); if (BbpCsr.field.Busy == BUSY) continue; BbpCsr.word = 0; BbpCsr.field.fRead = 1; BbpCsr.field.BBP_RW_MODE = 1; BbpCsr.field.Busy = 1; BbpCsr.field.RegNum = regID; RTMP_IO_WRITE32(pAd, BBP_CSR_CFG, BbpCsr.word); for (k=0; k<MAX_BUSY_COUNT; k++) { if(RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) goto done; RTMP_IO_READ32(pAd, BBP_CSR_CFG, &BbpCsr.word); if (BbpCsr.field.Busy == IDLE) break; } if ((BbpCsr.field.Busy == IDLE) && (BbpCsr.field.RegNum == regID) ) { *pValue = (UCHAR)(BbpCsr.field.Value); break; } } if (BbpCsr.field.Busy == BUSY) { DBGPRINT_ERR(("BBP read R%d=0x%X fail, i[%d], k[%d]\n", regID, BbpCsr.word,i,k)); goto done; } ret = STATUS_SUCCESS; done: #ifdef RTMP_MAC_USB if (IS_USB_INF(pAd)) { RTMP_SEM_EVENT_UP(&pAd->reg_atomic); } #endif /* RTMP_MAC_USB */ return ret; }
NDIS_STATUS MT7601_BBP_write( IN PRTMP_ADAPTER pAd, IN UCHAR regID, IN UCHAR value) { BBP_CSR_CFG_STRUC BbpCsr = { { 0 } }; UINT i = 0; NDIS_STATUS ret; #ifdef MT7601FPGA return; #endif /*MT7601FPGA */ if (pAd->WlanFunCtrl.field.WLAN_EN == 0) { DBGPRINT_ERR(("rlt_rf_write. Not allow to write BBP 0x%x : fail\n", regID)); return STATUS_UNSUCCESSFUL; } #ifdef RTMP_MAC_USB if (IS_USB_INF(pAd)) { RTMP_SEM_EVENT_WAIT(&pAd->reg_atomic, ret); if (ret != 0) { DBGPRINT(RT_DEBUG_ERROR, ("reg_atomic get failed(ret=%d)\n", ret)); return STATUS_UNSUCCESSFUL; } } #endif /* RTMP_MAC_USB */ ASSERT((regID <= pAd->chipCap.MaxNumOfBbpId)); ret = STATUS_UNSUCCESSFUL; do { RTMP_IO_READ32(pAd, BBP_CSR_CFG, &BbpCsr.word); if (!BbpCsr.field.Busy) break; i++; } while ((i < MAX_BUSY_COUNT) && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST))); if ((i == MAX_BUSY_COUNT) || (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST))) { DBGPRINT_RAW(RT_DEBUG_ERROR, ("Retry count exhausted or device removed!!!\n")); goto done; } BbpCsr.word = 0; BbpCsr.field.fRead = 0; BbpCsr.field.BBP_RW_MODE = 1; BbpCsr.field.Busy = 1; BbpCsr.field.Value = value; BbpCsr.field.RegNum = regID; RTMP_IO_WRITE32(pAd, BBP_CSR_CFG, BbpCsr.word); ret = NDIS_STATUS_SUCCESS; done: #ifdef RTMP_MAC_USB if (IS_USB_INF(pAd)) { RTMP_SEM_EVENT_UP(&pAd->reg_atomic); } #endif /* RTMP_MAC_USB */ return ret; }
/* ======================================================================== Routine Description: Read RT30xx RF register through MAC Arguments: Return Value: IRQL = Note: ======================================================================== */ NDIS_STATUS RT30xxReadRFRegister( IN PRTMP_ADAPTER pAd, IN UCHAR regID, IN PUCHAR pValue) { RF_CSR_CFG_STRUC rfcsr = { { 0 } }; UINT i=0, k=0; NDIS_STATUS ret = STATUS_UNSUCCESSFUL; ASSERT((regID <= pAd->chipCap.MaxNumOfRfId)); #ifdef RTMP_MAC_USB if (IS_USB_INF(pAd)) { RTMP_SEM_EVENT_WAIT(&pAd->reg_atomic, i); if (i != 0) { DBGPRINT(RT_DEBUG_ERROR, ("reg_atomic get failed(ret=%d)\n", i)); return STATUS_UNSUCCESSFUL; } } #endif /* RTMP_MAC_USB */ for (i=0; i<MAX_BUSY_COUNT; i++) { if(RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) goto done; RTMP_IO_READ32(pAd, RF_CSR_CFG, &rfcsr.word); if (rfcsr.field.RF_CSR_KICK == BUSY) continue; rfcsr.word = 0; rfcsr.field.RF_CSR_WR = 0; rfcsr.field.RF_CSR_KICK = 1; rfcsr.field.TESTCSR_RFACC_REGNUM = regID; RTMP_IO_WRITE32(pAd, RF_CSR_CFG, rfcsr.word); for (k=0; k<MAX_BUSY_COUNT; k++) { if(RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) goto done; RTMP_IO_READ32(pAd, RF_CSR_CFG, &rfcsr.word); if (rfcsr.field.RF_CSR_KICK == IDLE) break; } if ((rfcsr.field.RF_CSR_KICK == IDLE) && (rfcsr.field.TESTCSR_RFACC_REGNUM == regID)) { *pValue = (UCHAR)(rfcsr.field.RF_CSR_DATA); break; } } if (rfcsr.field.RF_CSR_KICK == BUSY) { DBGPRINT_ERR(("RF read R%d=0x%X fail, i[%d], k[%d]\n", regID, rfcsr.word,i,k)); goto done; } ret = STATUS_SUCCESS; done: #ifdef RTMP_MAC_USB if (IS_USB_INF(pAd)) { RTMP_SEM_EVENT_UP(&pAd->reg_atomic); } #endif /* RTMP_MAC_USB */ return ret; }
/* ======================================================================== Routine Description: Write RT30xx RF register through MAC Arguments: Return Value: IRQL = Note: ======================================================================== */ NDIS_STATUS RT30xxWriteRFRegister( IN PRTMP_ADAPTER pAd, IN UCHAR regID, IN UCHAR value) { RF_CSR_CFG_STRUC rfcsr = { { 0 } }; UINT i = 0; NDIS_STATUS ret; ASSERT((regID <= pAd->chipCap.MaxNumOfRfId)); #ifdef RTMP_MAC_USB if (IS_USB_INF(pAd)) { RTMP_SEM_EVENT_WAIT(&pAd->reg_atomic, ret); if (ret != 0) { DBGPRINT(RT_DEBUG_ERROR, ("reg_atomic get failed(ret=%d)\n", ret)); return STATUS_UNSUCCESSFUL; } } #endif /* RTMP_MAC_USB */ ret = STATUS_UNSUCCESSFUL; do { RTMP_IO_READ32(pAd, RF_CSR_CFG, &rfcsr.word); if (!rfcsr.field.RF_CSR_KICK) break; i++; } while ((i < MAX_BUSY_COUNT) && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST))); if ((i == MAX_BUSY_COUNT) || (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST))) { DBGPRINT_RAW(RT_DEBUG_ERROR, ("Retry count exhausted or device removed!!!\n")); goto done; } rfcsr.field.RF_CSR_WR = 1; rfcsr.field.RF_CSR_KICK = 1; rfcsr.field.TESTCSR_RFACC_REGNUM = regID; if ((pAd->chipCap.RfReg17WtMethod == RF_REG_WT_METHOD_STEP_ON) && (regID == RF_R17)) { UCHAR IdRf; UCHAR RfValue; BOOLEAN beAdd; RT30xxReadRFRegister(pAd, RF_R17, &RfValue); beAdd = (RfValue < value) ? TRUE : FALSE; IdRf = RfValue; while(IdRf != value) { if (beAdd) IdRf++; else IdRf--; rfcsr.field.RF_CSR_DATA = IdRf; RTMP_IO_WRITE32(pAd, RF_CSR_CFG, rfcsr.word); RtmpOsMsDelay(1); } } rfcsr.field.RF_CSR_DATA = value; RTMP_IO_WRITE32(pAd, RF_CSR_CFG, rfcsr.word); ret = NDIS_STATUS_SUCCESS; done: #ifdef RTMP_MAC_USB if (IS_USB_INF(pAd)) { RTMP_SEM_EVENT_UP(&pAd->reg_atomic); } #endif /* RTMP_MAC_USB */ return ret; }