HKA_S32 ISPWriteI2CData(HKA_U8 u8I2cDev, HKA_U8 u8DevAddr, HKA_U32 u32RegAddr,
HKA_U32 u32RegAddrByteNum, HKA_U32 u32Data, HKA_U32 u32DataByteNum)
{
int ret = 0;
struct i2c_adapter *padap = NULL;
struct i2c_msg msg;
char buf[8];
int count = 0;
padap = i2c_get_adapter(u8I2cDev);
if (!padap)
{
pr_err("I2C adapter[%d] get error\n", u8I2cDev);
return -ENODEV;
}
switch (u32RegAddrByteNum)
{
case 1:
buf[count++] = u32RegAddr & 0xFF;
break;
case 2:
buf[count++] = (u32RegAddr >> 8) & 0xFF;
buf[count++] = u32RegAddr & 0xFF;
break;
default:
pr_err("I2C addr bytenum error\n");
ret = -EINVAL;
goto err;
}
switch (u32DataByteNum)
{
case 1:
buf[count++] = u32Data & 0xFF;
break;
case 2:
buf[count++] = (u32Data >> 8) & 0xFF;
buf[count++] = u32Data & 0xFF;
break;
default:
pr_err("I2C addr bytenum error\n");
ret = -EINVAL;
goto err;
}
msg.addr = u8DevAddr;
msg.flags = 0;
msg.len = count;
msg.buf = (char *)buf;
ret = i2c_transfer(padap, &msg, 1);
if (ret < 0)
{
pr_err("I2c: count:%d, addrsize:%d, datasize:%d\n", count, u32RegAddrByteNum, u32DataByteNum);
pr_err("I2C write error, dev:%#x, reg:%#x,data:%#x, ret=%d\n", u8DevAddr, u32RegAddr, u32Data, ret);
ret = -EIO;
goto err;
}
// else
// {
pr_debug("[SDK_ISP_DRV]old I2C write OK,reg:%#x,data:%#x \n", u32RegAddr, u32Data);
// }
i2c_put_adapter(padap);
return 0;
err:
i2c_put_adapter(padap);
return ret;
}
标签:count,HKA,err,ret,linux,msg,驱动,I2C,buf
From: https://www.cnblogs.com/lattelover/p/17329588.html