⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mconfig.c

📁 atheros ar5001 5002 driver
💻 C
📖 第 1 页 / 共 5 页
字号:
		if (pLibParamsInfo->artAniEnable == ART_ANI_ENABLED) {
			enableArtAniSetup(devNum);
		} else {
			disableArtAniSetup(devNum);
		}
	}

	pLibDev->artAniSetup.Reuse = pLibParamsInfo->artAniReuse;
#else
	pLibParamsInfo->artAniEnable = ART_ANI_DISABLED;
#endif

	memcpy(&(pLibDev->libCfgParams), pLibParamsInfo, sizeof(LIB_PARAMS));
	return;
}

/**************************************************************************
* getDeviceInfo - get a subset of the device info for display
	*
*/
MANLIB_API void getDeviceInfo
(
 A_UINT32 devNum, 
 SUB_DEV_INFO *pInfoStruct		//pointer to caller assigned struct
)
{
    LIB_DEV_INFO *pLibDev = gLibInfo.pLibDevArray[devNum];
	A_UINT32	strLength;

	if(pLibDev->ar5kInitIndex == UNKNOWN_INIT_INDEX) {
		mError(devNum, EIO, "Device Number %d:getDeviceInfo fail, run resetDevice first\n", devNum);
		return;
	}
	pInfoStruct->aRevID = pLibDev->aRevID;
	pInfoStruct->hwDevID = pLibDev->hwDevID;
	pInfoStruct->swDevID = ar5kInitData[pLibDev->ar5kInitIndex].swDeviceID;
	pInfoStruct->bbRevID = pLibDev->bbRevID;
	pInfoStruct->macRev = pLibDev->macRev;
	pInfoStruct->subSystemID = pLibDev->subSystemID;
	strLength = strlen(pLibDev->regFilename);
	if (strLength) {
		strcpy(pInfoStruct->regFilename, pLibDev->regFilename);
		pInfoStruct->defaultConfig = 0;
	}
	else {
		//copy in the default
		if (ar5kInitData[pLibDev->ar5kInitIndex].pCfgFileVersion) {
			strcpy(pInfoStruct->regFilename, ar5kInitData[pLibDev->ar5kInitIndex].pCfgFileVersion);
		} else {
			pInfoStruct->regFilename[0]='\0';
		}
		pInfoStruct->defaultConfig = 1;
	}
	sprintf(pInfoStruct->libRevStr, DEVLIB_VER1); 

}

static A_BOOL analogRevMatch
(
	A_UINT32 index,
	A_UINT32 aRevID
)
{
	A_UINT16 i;
	A_UCHAR  aProduct = (A_UCHAR)(aRevID & 0xf);
	A_UCHAR  aRevision = (A_UCHAR)((aRevID >> 4) & 0xf);

	if(ar5kInitData[index].pAnalogRevs == NULL) {
		return(TRUE);
	}

	for (i = 0; i < ar5kInitData[index].numAnalogRevs; i++) {
		if((aProduct == ar5kInitData[index].pAnalogRevs[i].productID) &&
			(aRevision == ar5kInitData[index].pAnalogRevs[i].revID)) {
			return (TRUE);
		}
	}
	return(FALSE);
}

static A_BOOL macRevMatch
(
	A_UINT32 index,
	A_UINT32 macRev
)
{
	A_UINT16 i;
	
	if(ar5kInitData[index].pMacRevs == NULL) {
		return (TRUE);
	}

	for(i = 0; i < ar5kInitData[index].numMacRevs; i++) {
		if(macRev == ar5kInitData[index].pMacRevs[i]) {
			return(TRUE);
		}
	}
	return(FALSE);
}

A_INT32 findDevTableEntry
(
	A_UINT32 devNum
)
{
	A_UINT32 i;
	LIB_DEV_INFO *pLibDev;

	pLibDev = gLibInfo.pLibDevArray[devNum];

	//FJC: 07/24/03 this function can now be called from outside resetDevice
	//so it needs to read the hw info incase it has not been read.
	//have copied this from resetDevice rather than move it to minimize
	//inpact.  Should readly optimize this so don't do the same stuff twice.
	pLibDev->hwDevID = (pLibDev->devMap.OScfgRead(devNum, 0) >> 16) & 0xffff;

	 /* Reset the device. */
	 /* Masking the board specific part of the device id */
	 switch (pLibDev->hwDevID & 0xff)	{
		case 0x0007:
#ifndef __ATH_DJGPPDOS__
			hwResetAr5210(devNum, BUS_RESET | BB_RESET | MAC_RESET);
#endif
			break;
		case 0x0011:
		case 0x0012:
		case 0x0013:
		case 0x0014:
		case 0x0015:
        case 0x0016: 
        case 0x0017: 
		case 0xa014:
		case 0xa016:
			hwResetAr5211(devNum, BUS_RESET | BB_RESET | MAC_RESET);
			break;
	}

	/* Read macRev register */
	#if defined(SPIRIT_AP) || defined(FREEDOM_AP)
		pLibDev->macRev = (sysRegRead(AR531X_REV) >> REV_WMAC_MIN_S) & 0xff;
	#else
		pLibDev->macRev = REGR(devNum, F2_SREV) & F2_SREV_ID_M;
	#endif

	// Needed for venice FPGA 
	if ((pLibDev->hwDevID == 0xf013) || (pLibDev->hwDevID == 0xfb13) 
		|| (pLibDev->hwDevID == 0xf016) || (pLibDev->hwDevID == 0xff16)) {
		REGW(devNum, 0x4014, 0x3);
		REGW(devNum, 0x4018, 0x0);
		REGW(devNum, 0xd87c, 0x16);
		mSleep(100);
	}

	// set it to ofdm mode for reading the analog rev id for 11b fpga
	if (pLibDev->hwDevID == 0xf11b) {	
		REGW(devNum, 0xa200, 0);
		REGW(devNum, 0x987c, 0x19) ;
		mSleep(20);
	}

   	//read the baseband revision 
	pLibDev->bbRevID = REGR(devNum, PHY_CHIP_ID);

	//Needed so that analog revID write will work.
	if((pLibDev->hwDevID & 0xff) >= 0x0012) {
		REGW(devNum, 0x9800, 0x07);
	}
	else {
		REGW(devNum, 0x9800, 0x47);
	}

	//read the analog revIDs
    REGW(devNum, (PHY_BASE+(0x34<<2)), 0x00001c16);
    for (i=0; i<8; i++) {   
       REGW(devNum, (PHY_BASE+(0x20<<2)), 0x00010000);
    }
    pLibDev->aRevID = (REGR(devNum, PHY_BASE + (256<<2)) >> 24) & 0xff;   
    pLibDev->aRevID = reverseBits(pLibDev->aRevID, 8);

	for (i = 0; i < numDeviceIDs; i++)	{

		if (((pLibDev->hwDevID == ar5kInitData[i].deviceID) || (ar5kInitData[i].deviceID == DONT_MATCH) ) && 
            analogRevMatch(i, pLibDev->aRevID) && macRevMatch(i, pLibDev->macRev) )
		{
			break;
		}
	}


    if(i == numDeviceIDs) {
       	mError(devNum, EIO, "Device Number %d:unable to find device init details for deviceID 0x%04lx, analog rev 0x%02lx, mac rev 0x%04lx, bb rev 0x%04lx\n", devNum, 
		pLibDev->hwDevID, pLibDev->aRevID, pLibDev->macRev, pLibDev->bbRevID);
		return -1;
    }

	//read the subsystemID, this has been moved from above, so can read 
	//this from eeprom 
	//force the eeprom size incase blank card
	if(ar5kInitData[i].swDeviceID >= 0x0012) {
		REGW(devNum, 0x6010, REGR(devNum, 0x6010) | 0x3);
	}
	pLibDev->subSystemID = ar5kInitData[i].pMacAPI->eepromRead(devNum, 0x7);

#ifndef NO_LIB_PRINT		
   	if (!pLibDev->regFileRead) {
		printf(DEVLIB_VER1);
		printf("\n\n                     ===============================================\n");
		printf("                     |               ");                                   
		switch(pLibDev->subSystemID) {
			case 0x1021  :  printf("AR5001a_cb                    "); break;
			case 0x1022  :  printf("AR5001x_cb                    "); break;
			case 0x2022  :  printf("AR5001x_mb                    "); break;
			case 0x2023  :  printf("AR5001a_mb                    "); break;
			case 0xa021  :  printf("AR5001ap_ap                   "); break;

			case 0x1025  :  printf("AR5001g_cb21g                 "); break;
			case 0x1026  :  printf("AR5001x2_cb22ag               "); break;
			case 0x2025  :  printf("AR5001g_mb21g                 "); break;
			case 0x2026  :  printf("AR5001x2_mb22ag               "); break;

			case  0x2030 :	printf("AR5002g_mb31g (de-stuffed)    "); break;        
			case  0x2031 :  printf("AR5002x_mb32ag                "); break;               
			case  0x2027 :	printf("AR5001g_mb22g (de-stuffed)    "); break;        
			case  0x2029 :	printf("AR5001x_mb22ag (single-sided) "); break;        
			case  0x2024 :  printf("AR5001x_mb23j                 "); break;                 
			case  0x1030 :	printf("AR5002g_cb31g (de-stuffed)    "); break;        
			case  0x1031 :  printf("AR5002x_cb32ag                "); break;               
			case  0x1027 :	printf("AR5001g_cb22g (de-stuffed)    "); break;        
			case  0x1029 :	printf("AR5001x_cb22ag (single-sided) "); break;        
			case  0xa032 :  printf("AR5002a_ap30                  "); break;                 
			case  0xa034 :  printf("AR5002a_ap30  (040)           "); break;                 

			default: printf("UNKNOWN TYPE"); break;
		}
		printf("|\n");                                   
		printf("                     ===============================================\n\n");
		printf("Devices detected:\n");
		printf("   PCI deviceID     : 0x%04lx\t", pLibDev->hwDevID);
		printf("Sub systemID     : 0x%04lx\n", pLibDev->subSystemID);
		printf("   MAC revisionID   : 0x%02lx\t", pLibDev->macRev & 0xff);
		printf("BB  revisionID   : 0x%02lx\n", pLibDev->bbRevID & 0xff);
		printf("   RF  productID    : 0x%01lx\t", pLibDev->aRevID & 0xf);
		printf("RF  revisionID   : 0x%01lx\n", (pLibDev->aRevID >> 4) & 0xf);
		if((0x0012 == ar5kInitData[i].swDeviceID) || (ar5kInitData[i].swDeviceID == 0x0013) ) {
			printf("   Beanie productID : 0x%01lx\t", pLibDev->aBeanieRevID & 0xf);
			printf("Beanie revisionID: 0x%01lx\n\n", (pLibDev->aBeanieRevID >> 4) & 0xf);
		} else {
			printf("\n");
		}
	}
#endif //NO_LIB_PRINT

	return i;
}



A_BOOL loadCfgData(A_UINT32 devNum, A_UINT32 freq) {

LIB_DEV_INFO *pLibDev = gLibInfo.pLibDevArray[devNum];
A_UINT32 devTableIndex;
A_BOOL   earHere = FALSE;
A_UINT32 jj;

    if (!pLibDev->regFileRead) {
        devTableIndex = findDevTableEntry(devNum);

        if (devTableIndex == -1) {
            return 0;
        }

        pLibDev->ar5kInitIndex = devTableIndex;
        //try to read the eeprom to see if there is an ear
		if (pLibDev->eePromLoad) {
        if(setupEEPromMap(devNum)) {
            if(pLibDev->p16kEepHeader->majorVersion >= 4) {
                earHere = ar5212IsEarEngaged(devNum, pLibDev->pEarHead, freq);
            }
            //If we are loading the EAR, then move onto the next structure
            //so we point to the "frozen" config file contents, then load ear on that
            if(earHere && (pLibDev->libCfgParams.loadEar)) {
                if(((ar5kInitData[devTableIndex].swDeviceID & 0xff) == 0x0016) || ((ar5kInitData[devTableIndex].swDeviceID & 0xff) == 0x0017) ){
                    devTableIndex++;
                }
            }
        }
		}

        //set devTableIndex again incase it moved
        pLibDev->ar5kInitIndex = devTableIndex;
        pLibDev->sizeRegArray = ar5kInitData[devTableIndex].sizeArray;

    //  pLibDev->regArray = ar5kInitData[devTableIndex].pInitRegs;
        if(pLibDev->regArray) {
            free(pLibDev->regArray);
        }
        pLibDev->regArray = (ATHEROS_REG_FILE *)malloc(sizeof(ATHEROS_REG_FILE) *  pLibDev->sizeRegArray);
        if (!pLibDev->regArray) {
            mError(devNum, ENOMEM, "Device Number %d:resetDevice Failed to allocate memory for regArray \n", devNum);
            return 0;
        }
        memcpy(pLibDev->regArray, ar5kInitData[devTableIndex].pInitRegs, (sizeof(ATHEROS_REG_FILE) *  pLibDev->sizeRegArray));

        pLibDev->sizeModeArray = ar5kInitData[devTableIndex].sizeModeArray;

        //    pLibDev->pModeArray = ar5kInitData[devTableIndex].pModeValues;
        if (pLibDev->pModeArray) {
            free(pLibDev->pModeArray);
        }
        pLibDev->pModeArray = (MODE_INFO *)malloc(sizeof(MODE_INFO)*pLibDev->sizeModeArray);
        if (!pLibDev->pModeArray) {
            mError(devNum, ENOMEM, "Device Number %d:resetDevice Failed to allocate memory for modeArray \n", devNum);
            return 0;
        }
        memcpy(pLibDev->pModeArray, ar5kInitData[devTableIndex].pModeValues,sizeof(MODE_INFO)*pLibDev->sizeModeArray);


        pLibDev->swDevID = ar5kInitData[devTableIndex].swDeviceID;

        if (!parseAtherosRegFile(pLibDev, pLibDev->regFilename)) {
                mError(devNum, EIO, "Device Number %d:resetDevice: Unable to open atheros register file\n", devNum);
            return 0;
        }

        if (!createPciRegWrites(devNum)) {
                mError(devNum, EIO, "Device Number %d:resetDevice: Unable to convert atheros register file to pci write values\n", devNum);
                return 0;
        }
        pLibDev->regFileRead = 1;

        //initialize the API
        ar5kInitData[pLibDev->ar5kInitIndex].pMacAPI->macAPIInit(devNum);

        //zero out the key cache
        for(jj = 0x8800; jj < 0x97ff; jj+=4) {
            REGW(devNum, jj, 0);
        }
    }

	return 1;
}

/**************************************************************************
* resetDevice - reset the device and initialize all registers
*
*/
MANLIB_API void resetDevice
(
 A_UINT32 devNum, 
 A_UCHAR *mac, 
 A_UCHAR *bss, 
 A_UINT32 freq, 
 A_UINT32 turbo
)
{
   	LIB_DEV_INFO *pLibDev = gLibInfo.pLibDevArray[devNum];
	A_INT32 i;
	A_UINT32  *pValue = NULL;
	A_UINT32  newThreshold, newThresholdTurbo;
	A_UINT32 temp1, temp2;
	A_UINT32 modifier;
	A_BOOL   earHere = FALSE;
	A_UINT32 prev_freq;

	prev_freq = pLibDev->freqForResetDevice;

	pLibDev->turbo = 0;
	pLibDev->mdkErrno = 0;
	if (checkDevNum(devNum) == FALSE) {
		mError(devNum, EINVAL, "Device Number %d:resetDevice\n", devNum);
		return;
	}
   	if (gLibInfo.pLibDevArray[devNum]->devState < INIT_STATE) {
		mError(devNum, EILSEQ, "Device Number %d:resetDevice: Device should be initialized before calling reset\n", devNum);
		return;
	}

	pLibDev->hwDevID = (pLibDev->devMap.OScfgRead(devNum, 0) >> 16) & 0xffff;

// Dont call the driver init code for now
#if (MDK_AP) || (CUSTOMER_REL)
	pLibDev->use_init = !DRIVER_INIT_CODE;
#endif

	if (pLibDev->use_init == DRIVER_INIT_CODE) {
#ifndef CUSTOMER_REL
#ifndef NO_LIB_PRINT
       printf("resetDevice::Using Driver init code\n"); 
#endif

	   if (m_ar5212Reset(pLibDev, mac, bss, freq, turbo) != 0) {

       }
       if (!loadCfgData(devNum, freq)) return;
		if(!setupEEPromMap(devNum)) {
			mError(devNum, EIO, "Error: unable to load EEPROM\n");
			return;
		}
#endif //CUSTOMER_REL
	}
	else {

#ifndef NO_LIB_PRINT
#endif
	 /* Reset the device. */
	 /* Masking the board specific part of the device id */
	 switch (pLibDev->hwDevID & 0xff)	{
		case 0x0007:
#ifndef __ATH_DJGPPDOS__
			hwResetAr5210(devNum, BUS_RESET | BB_RESET | MAC_RESET);
#endif
			break;
		case 0x0011:
		case 0x0012:
		case 0x0013:
		case 0x0014:
		case 0x0015:
        case 0x0016: 
        case 0x0017: 
		case 0xa014:
		case 0xa016:
			hwResetAr5211(devNum, BUS_RESET | BB_RESET | MAC_RESET);
			break;
	}

	/* Read macRev register */
	#if defined(SPIRIT_AP) || defined(FREEDOM_AP)
		pLibDev->macRev = (sysRegRead(AR531X_REV) >> REV_WMAC_MIN_S) & 0xff;
	#else
		pLibDev->macRev = REGR(devNum, F2_SREV) & F2_SREV_ID_M;
	#endif

	// Needed for venice FPGA 
	if ((pLibDev->hwDevID == 0xf013) || (pLibDev->hwDevID == 0xfb13) 
		|| (pLibDev->hwDevID == 0xf016) || (pLibDev->hwDevID == 0xff16)) {
		REGW(devNum, 0x4014, 0x3);
		REGW(devNum, 0x4018, 0x0);
		REGW(devNum, 0xd87c, 0x16);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -