/******************************************************************************* * Function Name : OTGD_FS_FlushRxFifo * Description : Flush a Rx FIFO * Input : None * Output : None * Return : status *******************************************************************************/ USB_OTG_Status OTGD_FS_FlushRxFifo( void ) { USB_OTG_Status status = USB_OTG_OK; __IO USB_OTG_GRSTCTL_TypeDef greset; uint32_t timeout = 0; greset.d32 = 0; greset.b.rxfflsh = 1; USB_OTG_WRITE_REG32( &USB_OTG_FS_regs.GREGS->GRSTCTL, greset.d32 ); do { greset.d32 = USB_OTG_READ_REG32( &USB_OTG_FS_regs.GREGS->GRSTCTL); if (++timeout > USB_OTG_TIMEOUT) { break; } } while (greset.b.rxfflsh == 1); /* Wait for 3 PHY Clocks*/ uDELAY(5); return status; }
/******************************************************************************* * Function Name : OTGD_FS_FlushRxFifo * Description : Flush a Rx FIFO * Input : None * Output : None * Return : status *******************************************************************************/ USB_OTG_Status OTGD_FS_FlushRxFifo( void ) { USB_OTG_Status status = USB_OTG_OK; __IO USB_OTG_rst_ctl_data greset; int count = 0; greset.d32 = 0; greset.b.rxfflsh = 1; WRITE_REG32( &core_regs.common_regs->rst_ctl, greset.d32 ); do { greset.d32 = READ_REG32( &core_regs.common_regs->rst_ctl); if (++count > 200000) { break; } } while (greset.b.rxfflsh == 1); /* Wait for 3 PHY Clocks*/ uDELAY(3); return status; }
int iWriteRegI2C(u8 *a_pSendData , u16 a_sizeSendData, u16 i2cId) { int i4RetValue = 0; int retry = 3; // PK_DBG("Addr : 0x%x,Val : 0x%x \n",a_u2Addr,a_u4Data); //KD_IMGSENSOR_PROFILE_INIT(); spin_lock(&kdsensor_drv_lock); g_pstI2Cclient->addr = (i2cId >> 1); spin_unlock(&kdsensor_drv_lock); // do { i4RetValue = i2c_master_send(g_pstI2Cclient, a_pSendData, a_sizeSendData); if (i4RetValue != a_sizeSendData) { PK_DBG("[CAMERA SENSOR] I2C send failed!!, Addr = 0x%x, Data = 0x%x \n", a_pSendData[0], a_pSendData[1] ); } else { break; } uDELAY(50); } while ((retry--) > 0); //KD_IMGSENSOR_PROFILE("iWriteRegI2C"); return 0; }
/******************************************************************************* * Function Name : OTGD_FS_CoreReset * Description : Soft reset of the core * Input : None * Output : None * Return : Status *******************************************************************************/ static USB_OTG_Status OTGD_FS_CoreReset(void) { USB_OTG_Status status = USB_OTG_OK; __IO USB_OTG_GRSTCTL_TypeDef greset; uint32_t timeout = 0; greset.d32 = 0; /* Wait for AHB master IDLE state. */ do { uDELAY(5); greset.d32 = USB_OTG_READ_REG32(&USB_OTG_FS_regs.GREGS->GRSTCTL); if (++timeout > USB_OTG_TIMEOUT) { return USB_OTG_OK; } } while (greset.b.ahbidle == 0); /* Core Soft Reset */ timeout = 0; greset.b.csftrst = 1; USB_OTG_WRITE_REG32(&USB_OTG_FS_regs.GREGS->GRSTCTL, greset.d32 ); do { greset.d32 = USB_OTG_READ_REG32(&USB_OTG_FS_regs.GREGS->GRSTCTL); if (++timeout > USB_OTG_TIMEOUT) { break; } } while (greset.b.csftrst == 1); /* Wait for 3 PHY Clocks*/ uDELAY(5); return status; }
/******************************************************************************* * Function Name : OTGD_FS_CoreReset * Description : Soft reset of the core * Input : None * Output : None * Return : Status *******************************************************************************/ static USB_OTG_Status OTGD_FS_CoreReset(void) { USB_OTG_Status status = USB_OTG_OK; __IO USB_OTG_rst_ctl_data greset; uint32_t count = 0; greset.d32 = 0; /* Wait for AHB master IDLE state. */ do { uDELAY(3); greset.d32 = READ_REG32(&core_regs.common_regs->rst_ctl); if (++count > 200000) { return USB_OTG_OK; } } while (greset.b.ahbidle == 0); /* Core Soft Reset */ count = 0; greset.b.csftrst = 1; WRITE_REG32(&core_regs.common_regs->rst_ctl, greset.d32 ); do { greset.d32 = READ_REG32(&core_regs.common_regs->rst_ctl); if (++count > 200000) { break; } } while (greset.b.csftrst == 1); /* Wait for 3 PHY Clocks*/ uDELAY(10); return status; }
int iWriteReg(u16 a_u2Addr , u32 a_u4Data , u32 a_u4Bytes , u16 i2cId) { int i4RetValue = 0; int u4Index = 0; u8 * puDataInBytes = (u8 *)&a_u4Data; int retry = 3; char puSendCmd[6] = {(char)(a_u2Addr >> 8) , (char)(a_u2Addr & 0xFF) , 0 , 0 , 0 , 0}; // PK_DBG("Addr : 0x%x,Val : 0x%x \n",a_u2Addr,a_u4Data); //KD_IMGSENSOR_PROFILE_INIT(); spin_lock(&kdsensor_drv_lock); g_pstI2Cclient->addr = (i2cId >> 1); spin_unlock(&kdsensor_drv_lock); if(a_u4Bytes > 2) { PK_DBG("[CAMERA SENSOR] exceed 2 bytes \n"); return -1; } if(a_u4Data >> (a_u4Bytes << 3)) { PK_DBG("[CAMERA SENSOR] warning!! some data is not sent!! \n"); } for(u4Index = 0 ; u4Index < a_u4Bytes ; u4Index += 1 ) { puSendCmd[(u4Index + 2)] = puDataInBytes[(a_u4Bytes - u4Index-1)]; } // do { i4RetValue = i2c_master_send(g_pstI2Cclient, puSendCmd, (a_u4Bytes + 2)); if (i4RetValue != (a_u4Bytes + 2)) { PK_DBG("[CAMERA SENSOR] I2C send failed addr = 0x%x, data = 0x%x !! \n", a_u2Addr, a_u4Data); } else { break; } uDELAY(50); } while ((retry --) > 0); //KD_IMGSENSOR_PROFILE("iWriteReg"); return 0; }