/** * This function sets up the I2C controller and uses it to initialize the DP159. * * @param InstancePtr is a pointer to the XIic instance representing the * I2C controller connected to the same I2C bus which the DP159 is * is addressable from. * @param DeviceId is the device ID of the I2C controller. * * @return * - XST_SUCCESS if the I2C controller and the DP159 retimer have * been successfully set up and initialized. * - XST_FAILURE otherwise. * * @note None. * *******************************************************************************/ static u32 Dprx_Dp159Setup(XIic *InstancePtr, u16 DeviceId) { u32 Status; XIic_Config *ConfigPtr; ConfigPtr = XIic_LookupConfig(IIC_DEVICE_ID); if (!ConfigPtr) { return XST_FAILURE; } Status = XIic_CfgInitialize(InstancePtr, ConfigPtr, ConfigPtr->BaseAddress); if (Status != XST_SUCCESS) { return XST_FAILURE; } XIic_DynInit(InstancePtr->BaseAddress); /* This is hardware system specific - it is up to the user to implement * this function if needed. In some systems, a GPIO controller can reset * the DP159. In other systems, the reset functionality may be * accomplished using: * void XVidC_Dp159Reset(XIic *InstancePtr, u8 Reset); */ Dprx_Dp159Reset(); /*******************/ Status = XVidC_Dp159Initialize(InstancePtr); return Status; }
/****************************************************************************** * This function initializes the IIC controller. * * @param CoreAddress contains the address of the IIC core. * * @return If successfull, returns 1. Otherwise, returns 0. * * @note None. * ******************************************************************************/ int fmc_iic_axi_init( fmc_iic_t *pIIC, char szName[], Xuint32 CoreAddress ) { XStatus Status; Xuint8 StatusReg; Xuint32 timeout = 10000; //fmc_iic_axi_t *pContext = (fmc_iic_axi_t *)malloc( sizeof(fmc_iic_axi_t) ); //if ( pContext == NULL ) //{ // xil_printf("Failed to allocate context data for FMC-IIC-AXI implementation\n\r" ); // return 0; //} fmc_iic_axi_t *pContext = (fmc_iic_axi_t *) (pIIC->ContextBuffer); if ( sizeof(fmc_iic_axi_t) > FMC_IIC_CONTEXT_BUFFER_SIZE ) { printf("FMC_IIC_CONTEXT_BUFFER_SIZE is not large enough for fic_iic_xps_t structure (increase to %d)\n\r", sizeof(fmc_iic_axi_t) ); return 0; } pContext->CoreAddress = CoreAddress; /* * Initialize the IIC Core. */ Status = XIic_DynInit(pContext->CoreAddress); if(Status != XST_SUCCESS) { printf("Failed to initialize I2C chain\n\r" ); return 0; } /* * Check to see if the core was initialized successfully */ do { StatusReg = Xil_In8(pContext->CoreAddress + XIIC_SR_REG_OFFSET); //xil_printf("[%s] Xil_In8(pContext->CoreAddress + XIIC_SR_REG_OFFSET) => 0x%02X\n\r", pContext->szName, StatusReg ); StatusReg = StatusReg & (XIIC_SR_RX_FIFO_EMPTY_MASK | XIIC_SR_TX_FIFO_EMPTY_MASK | XIIC_SR_BUS_BUSY_MASK); } while ( (timeout-- > 0) && (StatusReg != (XIIC_SR_RX_FIFO_EMPTY_MASK | XIIC_SR_TX_FIFO_EMPTY_MASK)) ); /* * Initialize the IIC structure */ pIIC->uVersion = 1; strcpy( pIIC->szName, szName ); pIIC->pContext = (void *)pContext; pIIC->fpGpoRead = &fmc_iic_axi_GpoRead; pIIC->fpGpoWrite = &fmc_iic_axi_GpoWrite; pIIC->fpIicRead = &fmc_iic_axi_IicRead; pIIC->fpIicWrite = &fmc_iic_axi_IicWrite; pIIC->fpIicERead = &fmc_iic_axi_IicERead; pIIC->fpIicEWrite = &fmc_iic_axi_IicEWrite; return 1; }
/****************************************************************************** * * Initialize the IIC core for Dynamic Functionality. * * @param InstancePtr points to the Iic instance to be worked on. * * @return XST_SUCCESS if Successful else XST_FAILURE. * * @note None. * ******************************************************************************/ int XIic_DynamicInitialize(XIic *InstancePtr) { int Status; Xil_AssertNonvoid(InstancePtr != NULL); Status = XIic_DynInit(InstancePtr->BaseAddress); if (Status != XST_SUCCESS) { return XST_FAILURE; } return XST_SUCCESS; }
/****************************************************************************** * This function initializes the IIC controller. * * @param CoreAddress contains the address of the IIC core. * * @return If successfull, returns 1. Otherwise, returns 0. * * @note None. * ******************************************************************************/ int fmc_ipmi_iic_init( Xuint32 CoreAddress ) { XStatus Status; /* * Initialize the IIC Core. */ Status = XIic_DynInit(CoreAddress); if(Status != XST_SUCCESS) { xil_printf("Failed to initialize I2C chain\n\r" ); return 0; } return 1; }