Hi Ben, You are referring to older type of sensor i2c control. You can refer to IMX258 driver. drivers/media/i2c/imx258.c /* Write registers up to 2 at a time */ static int imx258_write_reg(struct imx258 *imx258, u16 reg, u32 len, u32 val) { struct i2c_client *client = v4l2_get_subdevdata(&imx258->sd); u8 buf[6]; if (len > 4) return -EINVAL; put_unaligned_be16(reg, buf); put_unaligned_be32(val << (8 * (4 - len)), buf + 2); if (i2c_master_send(client, buf, len + 2) != len + 2) return -EIO; return 0; } Regards, Andy >-----Original Message----- >From: Tomasz Figa [mailto:tfiga@xxxxxxxxxxxx] >Sent: Tuesday, January 15, 2019 11:23 AM >To: Kao, Ben <ben.kao@xxxxxxxxx> >Cc: Linux Media Mailing List <linux-media@xxxxxxxxxxxxxxx>; Sakari Ailus ><sakari.ailus@xxxxxxxxxxxxxxx>; Yeh, Andy <andy.yeh@xxxxxxxxx> >Subject: Re: [PATCH v2] media: ov8856: Add support for OV8856 sensor > >Hi Ben, > >On Fri, Jan 11, 2019 at 12:12 PM Ben Kao <ben.kao@xxxxxxxxx> wrote: >> >> This patch adds driver for Omnivision's ov8856 sensor, the driver >> supports following features: >[snip] >> +static int ov8856_write_reg(struct ov8856 *ov8856, u16 reg, u16 len, >> +u32 __val) { >> + struct i2c_client *client = v4l2_get_subdevdata(&ov8856->sd); >> + unsigned int buf_i, val_i; >> + u8 buf[6]; >> + u8 *val_p; >> + __be32 val; >> + >> + if (len > 4) >> + return -EINVAL; >> + >> + buf[0] = reg >> 8; >> + buf[1] = reg & 0xff; > >The two lines above can be simplified into one put_unaligned_be16(reg, buf); > >> + >> + val = cpu_to_be32(__val); >> + val_p = (u8 *)&val; >> + buf_i = 2; >> + val_i = 4 - len; >> + >> + while (val_i < 4) >> + buf[buf_i++] = val_p[val_i++]; > >All the code above can be simplified into: > >val <<= 8 * (4 - len); >put_unaligned_be32(val, buf + 2); > >> + >> + if (i2c_master_send(client, buf, len + 2) != len + 2) >> + return -EIO; >> + >> + return 0; >> +} > >Best regards, >Tomasz