static s32 balong_i2c_status_check(struct balong_i2c_ctrl *i2c_master) { u32 reg_value; s32 timeout=I2C_STATUS_TIMEOUT; /*Does bus transfer over */ do { reg_value= readl(i2c_master->regs+HI_I2C_SR_OFFSET); /*判断是否收到ACK中断*/ if(reg_value&HI_I2C_SR_ACKERR){ i2c_print_error("i2c hasn't receive ack!\n"); } /*判断是否有总线仲裁失败的情况*/ if(reg_value&HI_I2C_SR_ABITR){ i2c_print_error("i2c has abitrage ERROR!\n"); } }while((!(reg_value &HI_I2C_SR_INTDONE)) && (--timeout > 0)); if(0 == timeout) { i2c_print_error("I2C: Timeout! \n"); return I2C_ERROR; } balong_i2c_all_mask(i2c_master); return OK; }
static void balong_i2c_message_start(struct balong_i2c_ctrl *i2c_master,u8 device_id) { /*lint -save -e958*/ u32 addr=0; u32 tmp=0; /*lint -restore*/ if(NULL == i2c_master){ i2c_print_error("i2c master is null\n"); return ; } /*set high high level cycle*/ balong_i2c_scl_high(i2c_master); /* set high low level cycle */ balong_i2c_scl_low(i2c_master); /* clear all interrupt */ balong_i2c_all_mask(i2c_master); /* set i2c ctrl*/ balong_i2c_enable(i2c_master); /* set the first message ,and put it in the TXR register*/ addr=(device_id&SLAVE_ID_MASK)<<1; writel(addr,i2c_master->regs+HI_I2C_TXR_OFFSET); /* send start command and write command */ tmp=HI_I2C_COM_START|HI_I2C_COM_WRITE; writel(tmp,i2c_master->regs+HI_I2C_COM_OFFSET); return ; }
/***************************************************************************** fun_name : balong_i2c_status_check function : get i2c bus transfer status para_in : no para_out : no back_val : 0:success -1:fail modify log : date : 2013-3-14 Modification : create file *****************************************************************************/ s32 balong_i2c_status_check(struct balong_i2c_ctrl *i2c_master) { u32 reg_value; s32 timeout=I2C_STATUS_TIMEOUT; /*Does bus transfer over */ do { reg_value= readl(i2c_master->regs+HI_I2C_SR_OFFSET); /*ÅжÏÊÇ·ñÊÕµ½ACKÖжÏ*/ if(reg_value&HI_I2C_SR_ACKERR){ cprintf("i2c hasn't receive ack!status_register is:0x%x\n",reg_value); } /*ÅжÏÊÇ·ñÓÐ×ÜÏßÖÙ²Ãʧ°ÜµÄÇé¿ö*/ if(reg_value&HI_I2C_SR_ABITR){ cprintf("i2c has abitrage ERROR!status_register is:0x%x\n",reg_value); return I2C_ERROR; } }while((!(reg_value &HI_I2C_SR_INTDONE)) && (--timeout > 0)); if(0 == timeout) { cprintf("I2C: Timeout! \n"); return I2C_ERROR; } balong_i2c_all_mask(i2c_master); return OK; }