/* ** API : Ve890GetRev() ** Desp : Get 890 series dev revision ** input : Realtek device obj pointer ** return : pcn */ int Ve890GetRev(RTKDevObj *pDev) { unsigned char res[VP890_RCN_PCN_LEN]={0}; unsigned int devicePcn; bool runHvCheck = TRUE; VpMpiCmdWrapper(pDev->dev_id, VP890_EC_CH1, VP890_RCN_PCN_RD, VP890_RCN_PCN_LEN, res); /* Simple check to see if we're even talking to the device */ if (((res[0] == 0x00) && (res[1] == 0x00)) || ((res[0] == 0xFF) && (res[1] == 0xFF))) { return FAILED; } PRINT_MSG("deviceId: %x, Revision: %x:%x\n",pDev->dev_id ,res[0],res[1]); devicePcn = (unsigned int)res[VP890_PCN_LOCATION]; /* * Is the PCN one that we recognize as 890 (note: 89010 has same PCN as the * 89316, but the enumeration is different and invalid from the device) */ if ((devicePcn >= VP890_LAST_PCN) || (devicePcn == VP890_DEV_PCN_89010)) { PRINT_R("Error: pcn 0x%02x\n",devicePcn); return FAILED; } /* Check for FXO line Types */ if (devicePcn == VP890_DEV_PCN_89316) { uint8 check89010[VP890_FUSE5_REG_LEN]; VpMpiCmdWrapper(pDev->dev_id, VP890_EC_CH1, VP890_FUSE5_REG_RD, VP890_FUSE5_REG_LEN, check89010); /* * Normally, the fuse register is a trim value of vref and never 1. It's * only 1 if the device is being "marked" as FXO only. */ if (check89010[0] == 0x01) { res[VP890_PCN_LOCATION] = VP890_DEV_PCN_89010; /* * pDevObj->stateInt |= (VP890_LINE1_IS_FXO | VP890_IS_FXO_ONLY); * pDevObj->staticInfo.maxChannels = 2; */ runHvCheck = FALSE; /* PRINT_R("dual channel 1 0x%02x\n",devicePcn); */ } else { /* * pDevObj->stateInt |= VP890_LINE1_IS_FXO | VP890_WIDEBAND; * pDevObj->staticInfo.maxChannels = 2; */ /* PRINT_R("dual channel 2 0x%02x\n",devicePcn); */ } } else { /* * pDevObj->stateInt |= VP890_WIDEBAND | VP890_IS_SINGLE_CHANNEL; * pDevObj->staticInfo.maxChannels = 1; * PRINT_R("single channel 0x%02x\n",devicePcn); */ } if (runHvCheck == TRUE) { uint8 checkHv[VP890_FUSE1_REG_LEN]; uint8 ecTestValue = (VP890_EC_TEST_MODE_EN | VP890_EC_CH1); uint8 testReg1Data[VP890_TEST_REG1_LEN] = {VP890_TEST_REG1_FUSE_TEST}; VpMpiCmdWrapper(pDev->dev_id, ecTestValue, VP890_TEST_REG1_WRT, VP890_TEST_REG1_LEN, testReg1Data); VpMpiCmdWrapper(pDev->dev_id, ecTestValue, VP890_FUSE1_REG_RD, VP890_FUSE1_REG_LEN, checkHv); /* * A non-blown fuse reads as '1'. So if it is blown (reads = '0') it is * marked as a HV device. */ if (!(checkHv[0] & VP890_FUSE1_REG_ILAF_TRIM)) { /* pDevObj->stateInt |= VP890_IS_HIGH_VOLTAGE; */ if (res[VP890_PCN_LOCATION] == VP890_DEV_PCN_89116) { res[VP890_PCN_LOCATION] = VP890_DEV_PCN_89136; } else if (res[VP890_PCN_LOCATION] == VP890_DEV_PCN_89316) { res[VP890_PCN_LOCATION] = VP890_DEV_PCN_89336; } } checkHv[0] = 0x00; VpMpiCmdWrapper(pDev->dev_id, VP890_EC_CH1, VP890_TEST_REG1_WRT, VP890_TEST_REG1_LEN, checkHv); } devicePcn = (unsigned int)res[VP890_PCN_LOCATION]; switch(devicePcn) { case VP890_DEV_PCN_89116: /**< FXS - Wideband */ PRINT_MSG("VP890_DEV_PCN_89116\n"); break; case VP890_DEV_PCN_89316: /**< FXO/FXS-Tracker - Wideband */ PRINT_MSG("VP890_DEV_PCN_89316\n"); break; #if 1 /* We need to do more test to recognize 89010 */ case VP890_DEV_PCN_89010: /**< Single Channel FXO */ PRINT_MSG("VP890_DEV_PCN_89010\n"); break; /* * HV devices have the same silicon PCN has their LV equivalent. The SW has * to determine if HV/LV and set the PCN value returned by GetDeviceInfo(). */ #endif case VP890_DEV_PCN_89136: /**< HV FXS - Wideband */ PRINT_MSG("VP890_DEV_PCN_89136\n"); break; case VP890_DEV_PCN_89336: /**< FXO/FXS-Tracker - Wideband */ PRINT_MSG("VP890_DEV_PCN_89336\n"); break; default: PRINT_MSG("unknown!\n"); return FAILED; } return devicePcn; }
/** * Vp790ConfigLine * This function reloads a line of a device with the specified parameters. * * Preconditions: * The device associated with this line must be initialized. * * Postconditions: * The line pointed to by the line context passed is initialized with the * profile data specified. This function returns the success code if the device * associated with this line is initialized. */ VpStatusType Vp790ConfigLine( VpLineCtxType *pLineCtx, VpProfilePtrType pAcProfile, /**< Pointer to AC coefficient data or * profile index to be applied to this line. */ VpProfilePtrType pDcOrFxoProfile, /**< Pointer to DC Feed (FXS) or Cfg * (FX0) profile or profile index to be * applied to this line. */ VpProfilePtrType pRingProfile) /**< Pointer to Ringing profile or profile * index to apply to this line */ { Vp790LineObjectType *pLineObj = pLineCtx->pLineObj; VpDevCtxType *pDevCtx = pLineCtx->pDevCtx; Vp790DeviceObjectType *pDevObj = pDevCtx->pDevObj; VpProfileDataType *pCurrentProf; uint8 profIndex = VP_PROFILE_MPI_LEN; uint8 ioReg[VP790_IO_REG_LEN]; uint8 ccr4[VP790_CCR4_LEN], ccr4Temp[VP790_CCR4_LEN]; uint8 defaultVals[VP790_LOOP_SUP_LEN] = {0x0D, 0x64, 0x0D, 0x01, 0x30, 0x00, 0x10, 0x0D}; uint8 ecVal[] = {VP790_EC_CH1, VP790_EC_CH2, VP790_EC_CH3, VP790_EC_CH4}; uint8 channelId = pLineObj->channelId; VpDeviceIdType deviceId = pDevObj->deviceId; VpProfilePtrType pAcProf = VP_PTABLE_NULL; VpProfilePtrType pDcFxoCfgProf = VP_PTABLE_NULL; VpProfilePtrType pRingProf = VP_PTABLE_NULL; /* Proceed if initialized or in progress, and not calibrating */ if (pDevObj->status.state & (VP_DEV_INIT_CMP | VP_DEV_INIT_IN_PROGRESS)) { if (pDevObj->status.state & VP_DEV_IN_CAL) { return VP_STATUS_DEVICE_BUSY; } } else { return VP_STATUS_DEV_NOT_INITIALIZED; } /* Check the legality of the AC profile */ if (!VpCSLACIsProfileValid(VP_PROFILE_AC, VP_CSLAC_AC_PROF_TABLE_SIZE, pDevObj->profEntry.acProfEntry, pDevObj->devProfileTable.pAcProfileTable, pAcProfile, &pAcProf)) { return VP_STATUS_ERR_PROFILE; } /* Check the legality of the DC profile */ if (!VpCSLACIsProfileValid(VP_PROFILE_DC, VP_CSLAC_DC_PROF_TABLE_SIZE, pDevObj->profEntry.dcProfEntry, pDevObj->devProfileTable.pDcProfileTable, pDcOrFxoProfile, &pDcFxoCfgProf)) { return VP_STATUS_ERR_PROFILE; } /* Check the legality of the Ringing profile */ if (!VpCSLACIsProfileValid(VP_PROFILE_RING, VP_CSLAC_RINGING_PROF_TABLE_SIZE, pDevObj->profEntry.ringingProfEntry, pDevObj->devProfileTable.pRingingProfileTable, pRingProfile, &pRingProf)) { return VP_STATUS_ERR_PROFILE; } VpSysEnterCritical(deviceId, VP_CODE_CRITICAL_SEC); /* If no AC Profile exists use whatever exists in the device */ if (pAcProfile != VP_PTABLE_NULL) { pCurrentProf = (VpProfileDataType *)pAcProfile; VpMpiCmdWrapper(deviceId, ecVal[channelId], NOOP_CMD, pCurrentProf[profIndex], &pCurrentProf[profIndex + 1]); } /* * The Ring Profile may contain content (command 0x68) that affects * bits controlled only by the API-II. So read the register first, then * determine what bits are allowed to change, and set the register to * the new value. */ VpMpiCmdWrapper(deviceId, ecVal[channelId], VP790_CCR4_RD, VP790_CCR4_LEN, ccr4Temp); /* If no Ringing Profile exists use whatever exists in the device */ if (pRingProfile != VP_PTABLE_NULL) { pCurrentProf = (VpProfileDataType *)pRingProfile; VpMpiCmdWrapper(deviceId, ecVal[channelId], NOOP_CMD, pCurrentProf[profIndex], &pCurrentProf[profIndex + 1]); } /* * Read what ccr4 is now set to. We'll need to adjust because some bits * may not be allowed to be changed by the Ringing Profile */ VpMpiCmdWrapper(deviceId, ecVal[channelId], VP790_CCR4_RD, VP790_CCR4_LEN, ccr4); /* Zero out those bits not controlled by the profile */ ccr4[0] &= (VP790_EXT_RINGING | VP790_CCR4_RTM); /* * Or in the bits controlled by API-II as they existed before this profile * was sent. */ ccr4Temp[0] &= (uint8)(~(VP790_EXT_RINGING | VP790_CCR4_RTM)); ccr4[0] |= ccr4Temp[0]; /* * If we are set to external ringing, RD2 has to be set for auto mode. * Otherwise it's set for manual */ VpMpiCmdWrapper(deviceId, ecVal[channelId], VP790_IO_REG_RD, VP790_IO_REG_LEN, ioReg); /* Set remaining values of ccr4 based on API-II settings */ if (ccr4[0] & VP790_EXT_RINGING) { ioReg[0] |= VP790_IO_REG_RD2_AUTO; if(pLineObj->ringCtrl.zeroCross == VP_OPTION_ZC_NONE) { ccr4[0] |= VP790_CCR4_ZXR_DIS; } else { ccr4[0] &= ~VP790_CCR4_ZXR_DIS; } } else { ioReg[0] &= ~VP790_IO_REG_RD2_AUTO; if(pLineObj->ringCtrl.zeroCross == VP_OPTION_ZC_NONE) { ccr4[0] &= ~VP790_CCR4_ZXR_DIS; } else { ccr4[0] |= VP790_CCR4_ZXR_DIS; } } VpMpiCmdWrapper(deviceId, ecVal[channelId], VP790_CCR4_WRT, VP790_CCR4_LEN, ccr4); VpMpiCmdWrapper(deviceId, ecVal[channelId], VP790_IO_REG_WRT, VP790_IO_REG_LEN, ioReg); /* If no DC Feed Profile exists use whatever the device default value is */ if (pDcFxoCfgProf != VP_PTABLE_NULL) { pCurrentProf = (VpProfileDataType *)pDcFxoCfgProf; VpMpiCmdWrapper(deviceId, ecVal[channelId], NOOP_CMD, pCurrentProf[profIndex], &pCurrentProf[profIndex + 1]); } else { VpMpiCmdWrapper(deviceId, ecVal[channelId], VP790_LOOP_SUP_WRT, VP790_LOOP_SUP_LEN, defaultVals); } VpSysExitCritical(deviceId, VP_CODE_CRITICAL_SEC); return VP_STATUS_SUCCESS; }
/** * Vp790InitDevice * This function initializes the device and all lines associated with this * device (if line profiles are passed to this function). * * Preconditions: * None (device context is not NULL and is of Vp790 type, which is handled in * higher level software) * * Postconditions: * This device is initialized to the configuration specified in the device * profile and the FXS lines associated with this device are initialized by the * FXS specific AC, DC, and Ringing profiles passed. This function returns an * error code if the device profile trying to be used for initialization is * VP_PTABLE_NULL (either passed or by a non-initialized index). */ VpStatusType Vp790InitDevice( VpDevCtxType *pDevCtx, VpProfilePtrType pDevProfile, /**< The profile pointer for the device * configuration parameters */ VpProfilePtrType pAcProfile, /**< The profile pointer (or index) for * the AC characteristic to apply to the * FXS lines */ VpProfilePtrType pDcProfile, /**< The profile pointer (or index) for * the DC characteristic to apply to the * FXS lines */ VpProfilePtrType pRingProfile, /**< The profile pointer (or index) for * the Ringing characteristic to apply to * the FXS lines */ VpProfilePtrType pFxoAcProfile, /**< The profile pointer (or index) for * the AC characteristic to apply to the * FXO lines */ VpProfilePtrType pFxoCfgProfile)/**< The profile pointer for the FXO * specific supervision paramaters. */ { VpLineCtxType *pLineCtx; Vp790DeviceObjectType *pDevObj = pDevCtx->pDevObj; VpDeviceIdType deviceId = pDevObj->deviceId; uint8 ecVal[] = {VP790_EC_CH1, VP790_EC_CH2, VP790_EC_CH3, VP790_EC_CH4}; uint8 gpioDir[] = {VP790_GIO_DIR_ALL_OUTPUT}; uint8 maxChan = pDevObj->staticInfo.maxChannels; VpProfilePtrType pDevProf; uint8 chan; VpStatusType status = VP_STATUS_SUCCESS; int profIndex = VpGetProfileIndex(pDevProfile); /* * Get Profile Index returns -1 if the profile passed is a pointer or * of VP_PTABLE_NULL type. Otherwise it returns the index */ if (profIndex < 0) { /* * A pointer is passed or VP_PTABLE_NULL. If it's a pointer, make * sure the content is valid for the profile type. */ if (pDevProfile != VP_PTABLE_NULL) { if(VpVerifyProfileType(VP_PROFILE_DEVICE, pDevProfile) != TRUE) { return VP_STATUS_ERR_PROFILE; } } pDevProf = pDevProfile; } else if (profIndex < VP_CSLAC_DEV_PROF_TABLE_SIZE) { pDevProf = pDevObj->devProfileTable.pDevProfileTable[profIndex]; if ((pDevProf == VP_PTABLE_NULL) || (!(pDevObj->profEntry.devProfEntry & (0x01 << profIndex)))) { return VP_STATUS_ERR_PROFILE; } } else { return VP_STATUS_ERR_PROFILE; } VpSysEnterCritical(deviceId, VP_CODE_CRITICAL_SEC); pDevObj->status.globStatReg = 0; pDevObj->status.calibrating = 0; pDevObj->timeStamp = 0; pDevObj->status.state = VP_DEV_INIT_IN_PROGRESS; if (pDevProf != VP_PTABLE_NULL) { pDevObj->devProfileData.pcmClkRate = (uint16)(((pDevProf[VP790_DEV_PROFILE_PCLK_MSB] << 8) & 0xFF00) | (pDevProf[VP790_DEV_PROFILE_PCLK_LSB] & 0x00FF)); pDevObj->devProfileData.devCfg1 = (uint8)(pDevProf[VP790_DEV_PROFILE_DEVCFG1]); pDevObj->devProfileData.mClkCorrection = (uint8)(pDevProf[VP790_DEV_PROFILE_MCLK_CORR]); pDevObj->devProfileData.clockSlot = (uint8)(pDevProf[VP790_DEV_PROFILE_CLOCK_SLOT]); pDevObj->devProfileData.maxNumInterrupts = (uint8)(pDevProf[VP790_DEV_PROFILE_MAX_EVENTS]); pDevObj->devProfileData.tickRate = (uint16)(((pDevProf[VP790_DEV_PROFILE_TICKRATE_MSB] << 8) & 0xFF00) | (pDevProf[VP790_DEV_PROFILE_TICKRATE_LSB] & 0x00FF)); pDevObj->devProfileData.calibrationTime = MS_TO_TICKRATE(20, pDevObj->devProfileData.tickRate); } else { pDevObj->status.state &= ~VP_DEV_INIT_IN_PROGRESS; VpSysExitCritical(deviceId, VP_CODE_CRITICAL_SEC); return VP_STATUS_ERR_PROFILE; } /* Initialize device */ /* * If not successful, the Clock Fail bit did not clear so return error code */ if ((status = Vp790Init(pDevCtx)) != VP_STATUS_SUCCESS) { pDevObj->status.state &= ~(VP_DEV_INIT_IN_PROGRESS | VP_DEV_INIT_CMP); /* * Clear the tickRate, which is used by VpApiTick() to indicate VpInitDevice() was * completed. This prevents VpApiTick() from generating events on a non-initialized device * context/object. */ pDevObj->devProfileData.tickRate = 0; VpSysExitCritical(deviceId, VP_CODE_CRITICAL_SEC); return status; } VpMpiCmdWrapper(deviceId, ecVal[0], VP790_GIO_DIR_WRT, VP790_GIO_DIR_LEN, gpioDir); if (pDevProf[VP_PROFILE_VERSION] >= VP_CSLAC_DEV_PROFILE_VERSION_LINECARD_PARAM) { /* This profile contains the Linecard parameters value */ VpMpiCmdWrapper(deviceId, ecVal[0], VP790_LINECARD_PARAM_WRT, VP790_LINECARD_PARAM_LEN, (VpProfileDataType *)(&pDevProf[VP790_DEV_PROFILE_LINECARD_PARAM_DATA0])); } /* Initialize each channel */ for (chan = 0; chan < maxChan; chan++) { /* * For Init Line to work, the device cannot be non-initialized because * the init line function tries to set the line state. Therefore, * temporarily set the device init flag to TRUE then immediately after * line init, set back to FALSE until device init is complete */ pLineCtx = pDevCtx->pLineCtx[chan]; if (pLineCtx != VP_NULL) { status = Vp790InitLine(pLineCtx, pAcProfile, pDcProfile, pRingProfile); if (status != VP_STATUS_SUCCESS) { pDevObj->status.state &= ~(VP_DEV_INIT_IN_PROGRESS | VP_DEV_INIT_CMP); /* * Clear the tickRate, which is used by VpApiTick() to indicate VpInitDevice() was * completed. This prevents VpApiTick() from generating events on a non-initialized * device context/object. */ pDevObj->devProfileData.tickRate = 0; VpSysExitCritical(deviceId, VP_CODE_CRITICAL_SEC); return status; } } } VpImplementDefaultSettings(pDevCtx, VP_NULL); /* * This clears the Init Line Events and any other erroneous event that * may have been created due to initialization */ Vp790FlushEvents(pDevCtx); /* Start the device Calibration */ Vp790CalCodecInt(pDevCtx); VpSysExitCritical(deviceId, VP_CODE_CRITICAL_SEC); return VP_STATUS_SUCCESS; } /* Vp790InitDevice */
/** * Vp790InitLine * This function initializes a line of a device with the specified parameters * and API default values. It is a "Line Reset". * * Preconditions: * The device associated with this line must be initialized. * * Postconditions: * The line pointed to be the line context passed is initialized with the * profile data specified. This function returns the success code if the device * associated with this line is initialized. */ VpStatusType Vp790InitLine( VpLineCtxType *pLineCtx, VpProfilePtrType pAcProfile, /**< Pointer to AC coefficient data or * profile index to be applied to this line. */ VpProfilePtrType pDcOrFxoProfile, /**< Pointer to DC Feed (FXS) or Cfg * (FX0) profile or profile index to be * applied to this line. */ VpProfilePtrType pRingProfile) /**< Pointer to Ringing profile or profile * index to apply to this line */ { Vp790LineObjectType *pLineObj = pLineCtx->pLineObj; VpDevCtxType *pDevCtx = pLineCtx->pDevCtx; Vp790DeviceObjectType *pDevObj = pDevCtx->pDevObj; uint8 ecVal[] = {VP790_EC_CH1, VP790_EC_CH2, VP790_EC_CH3, VP790_EC_CH4}; uint8 channelId = pLineObj->channelId; uint8 data; #ifdef VP_CSLAC_SEQ_EN uint8 seqByte; #endif uint8 ioReg[VP790_IO_REG_LEN]; uint8 disableVals[VP790_LOOP_SUP_LEN] = {0x0D, 0x64, 0x0D, 0x01, 0x30, 0x00, 0x00, 0x7F}; VpDeviceIdType deviceId = pDevObj->deviceId; /* Proceed if initialized or in progress, and not calibrating */ if (pDevObj->status.state & (VP_DEV_INIT_CMP | VP_DEV_INIT_IN_PROGRESS)) { if (pDevObj->status.state & VP_DEV_IN_CAL) { return VP_STATUS_DEVICE_BUSY; } } else { return VP_STATUS_DEV_NOT_INITIALIZED; } VpSysEnterCritical(deviceId, VP_CODE_CRITICAL_SEC); #ifdef VP_CSLAC_SEQ_EN for (seqByte = 0; seqByte < VP790_INT_SEQ_LEN; seqByte++) { pLineObj->intSequence[seqByte] = 0x00; } pLineObj->callerId.status = VP_CID_RESET_VALUE; pLineObj->thisFskCid = FALSE; #endif pLineObj->pRingingCadence = VP_PTABLE_NULL; pLineObj->pCidProfileType1 = VP_PTABLE_NULL; pLineObj->pCidProfileType2 = VP_PTABLE_NULL; pLineObj->lineState.currentState = VP_LINE_DISCONNECT; pLineObj->lineState.previous = VP_LINE_DISCONNECT; pLineObj->codec = VP_NUM_OPTION_CODEC_TYPE_IDS; pLineObj->lineTimers.type = VP_CSLAC_FXS_TIMER; InitTimerVars(pLineCtx); #ifdef VP_CSLAC_SEQ_EN VpMemSet(&pLineObj->cadence, 0, sizeof(VpSeqDataType)); #endif /* Software reset the channel */ VpMpiCmdWrapper(deviceId, ecVal[channelId], VP790_SW_RESET_CMD, NO_DATA, &data); VpSysWait(3); VpMpiCmdWrapper(deviceId, ecVal[channelId], VP790_LOOP_SUP_WRT, VP790_LOOP_SUP_LEN, disableVals); VpSysWait(1); /* Set the default line state */ Vp790SetLineState(pLineCtx, VP_LINE_DISCONNECT); /* Deactiveate the CODEC for the channel */ VpMpiCmdWrapper(deviceId, ecVal[channelId], VP790_DEACTIVATE_CMD, NO_DATA, &data); /***************** C3 Operational Issue 3 ******************/ /* This errata fix does not harm D3 operation */ data = 0x00; VpMpiCmdWrapper(deviceId, ecVal[channelId], VP790_CCR9_WRT, VP790_CCR9_LEN, &data); /* We've already deactivated the device */ VpSysWait(3); /**************** End Operational Issue 3 ******************/ pLineObj->ringCtrl.zeroCross = VP_OPTION_DEFAULT_ZERO_CROSS; Vp790ConfigLine(pLineCtx, pAcProfile, pDcOrFxoProfile, pRingProfile); VpMpiCmdWrapper(deviceId, ecVal[channelId], VP790_IO_REG_RD, VP790_IO_REG_LEN, ioReg); ioReg[0] |= VP790_IO_REG_RD1_MANUAL; VpMpiCmdWrapper(deviceId, ecVal[channelId], VP790_IO_REG_WRT, VP790_IO_REG_LEN, ioReg); VpImplementDefaultSettings(VP_NULL, pLineCtx); /* Force an initial test of the hook state */ pLineObj->lineState.condition = VP_CSLAC_STATUS_INVALID; pLineObj->dpStruct.hookSt = FALSE; VpInitDP(&pLineObj->dpStruct); /* Re-activate the channel due to a silicon bug -- and it doesn't hurt */ VpMpiCmdWrapper(deviceId, ecVal[channelId], VP790_ACTIVATE_CMD, NO_DATA, VP_NULL); /* Post the line init complete event */ pLineObj->lineEvents.response |= VP_LINE_EVID_LINE_INIT_CMP; VpSysExitCritical(deviceId, VP_CODE_CRITICAL_SEC); return VP_STATUS_SUCCESS; } /* Vp790InitLine */
/** * Vp790Init * This function initializes the device, and (contrary to InitDevice) does * not initialize any channels. This function should be called internal to the * API only. * * Preconditions: * The device context must be of a Vp790 device type. * * Postconditions: * This function returns a failure code if the clock configuration is not set * correctly based on the device data set in InitDevice. */ VpStatusType Vp790Init( VpDevCtxType *pDevCtx) { Vp790DeviceObjectType *pDevObj = pDevCtx->pDevObj; VpDeviceIdType deviceId = pDevObj->deviceId; uint8 data, gdStat; uint8 deviceFailure; uint8 testCount; uint8 mpiReset[] = { VP790_NO_OP, VP790_NO_OP, VP790_NO_OP, VP790_NO_OP, VP790_NO_OP, VP790_NO_OP, VP790_NO_OP, VP790_NO_OP, VP790_NO_OP, VP790_NO_OP, VP790_NO_OP, VP790_NO_OP, VP790_NO_OP, VP790_NO_OP, VP790_NO_OP, VP790_NO_OP }; /* Initialize the API's device dynamic variables */ pDevObj->dynamicInfo.lastChan = 0; /*********** Errata D2.1 and/or C3.9-10 (Part 1)************/ /* * If the MPI Bus gets out of sequence for any reason, a HW reset command * will not work and this function may fail. To be sure a reset occurs, the * following sequence is required. */ VpMpiCmdWrapper(deviceId, VP790_EC_CH1, VP790_NO_OP, 16, mpiReset); VpMpiCmdWrapper(deviceId, VP790_EC_CH1, VP790_HW_RESET_CMD, 0, VP_NULL); VpSysWait(20); VpMpiCmdWrapper(deviceId, VP790_EC_CH1, VP790_DEVTYPE_CMD, VP790_DEVTYPE_LEN, pDevObj->staticInfo.rcnPcn); if ((pDevObj->staticInfo.rcnPcn[0] == 0x00) || (pDevObj->staticInfo.rcnPcn[0] == 0xFF)) { return VP_STATUS_FAILURE; } /*************** End Errata D2.1 (Part 1) ******************/ /* * Setup mclk. The MCLK mask set the mclk frequency, sets the mclk source * (the MCLK pin or the PCLK pin), and sets the interrupt pin output drive * mode (TTL or open collector) */ data = pDevObj->devProfileData.devCfg1; VpMpiCmdWrapper(deviceId, VP790_EC_CH1, VP790_DCR1_WRT, VP790_DCR1_LEN, &data); /* * The MCLK correction register is used if the desired MCLK frequency is * NOT a multipal of 512kHz (for example 1.544MHz != n*512kHz, n an integer) */ data = pDevObj->devProfileData.mClkCorrection; VpMpiCmdWrapper(deviceId, VP790_EC_CH1, VP790_MCCR_WRT, VP790_MCCR_LEN, &data); /* * Wait for the CFAIL bit to clear before proceding. If the CFAIL bit * does not clear after several trys, give up and return an error * condition. Wait between each read of the status register. */ /* Setup parameters to clear interrupts .. or at least try */ deviceFailure = VP790_GD_STAT_CFAIL; testCount = MAX_CFAIL_TEST*10; while(deviceFailure && (--testCount) != 0) { VpSysWait(CFAIL_TEST_INTERVAL); VpMpiCmdWrapper(deviceId, VP790_EC_CH1, VP790_GD_STAT_RD, VP790_GD_STAT_LEN, &data); deviceFailure = data & VP790_GD_STAT_CFAIL; VpMpiCmdWrapper(deviceId, VP790_EC_CH1, VP790_INTRPT_RD, VP790_INTRPT_LEN, &data); } /* * The CFAIL bit did not clear so the part will not complete initialization. * Return error status to indicate failure. */ if(deviceFailure) { return VP_STATUS_FAILURE; } /* * The PCM mask tells the device which clock edge to grab and xmit the * PCM data on and also which clock period LSB of the PCM data starts on */ data = pDevObj->devProfileData.clockSlot; VpMpiCmdWrapper(deviceId, VP790_EC_CH1, VP790_XR_CS_WRT, VP790_XR_CS_LEN, &data); /* Clear all Device Interrupt Masks except Pos Bat */ data = VP790_GD_MASK_PINT; VpMpiCmdWrapper(deviceId, VP790_EC_CH1, VP790_GD_MASK_WRT, VP790_GD_MASK_LEN, &data); /* Clear all interrupts that resulted from power-up and reset */ data = 0x01; while(data != 0x00) { VpSysWait(2); VpMpiCmdWrapper(deviceId, VP790_EC_CH1, VP790_INTRPT_RD, VP790_INTRPT_LEN, &data); /* Clear a device interrupt if one is pending */ if(data & VP790_INTR_GLOB) { VpMpiCmdWrapper(deviceId, VP790_EC_CH1, VP790_GD_STAT_RD, VP790_GD_STAT_LEN, &gdStat); } } return VP_STATUS_SUCCESS; } /* Vp790Init */