From: "Yeh, Andy" <andy.yeh@intel.com>
To: "Kao, Ben" <ben.kao@intel.com>, "Tu, ShawnX" <shawnx.tu@intel.com>
Cc: Linux Media Mailing List <linux-media@vger.kernel.org>,
Sakari Ailus <sakari.ailus@linux.intel.com>,
Tomasz Figa <tfiga@chromium.org>
Subject: RE: [PATCH v2] media: ov8856: Add support for OV8856 sensor
Date: Tue, 15 Jan 2019 05:18:15 +0000 [thread overview]
Message-ID: <8E0971CCB6EA9D41AF58191A2D3978B61D883FA5@PGSMSX111.gar.corp.intel.com> (raw)
In-Reply-To: <CAAFQd5B1nkEDou9Jj78sMnB-pc+qx-76i8hk0mdb-sjj6TkCfw@mail.gmail.com>
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@chromium.org]
>Sent: Tuesday, January 15, 2019 11:23 AM
>To: Kao, Ben <ben.kao@intel.com>
>Cc: Linux Media Mailing List <linux-media@vger.kernel.org>; Sakari Ailus
><sakari.ailus@linux.intel.com>; Yeh, Andy <andy.yeh@intel.com>
>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@intel.com> 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
prev parent reply other threads:[~2019-01-15 5:18 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-11 3:15 [PATCH v2] media: ov8856: Add support for OV8856 sensor Ben Kao
2019-01-14 14:32 ` Sakari Ailus
2019-01-15 3:22 ` Tomasz Figa
2019-01-15 5:18 ` Yeh, Andy [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8E0971CCB6EA9D41AF58191A2D3978B61D883FA5@PGSMSX111.gar.corp.intel.com \
--to=andy.yeh@intel.com \
--cc=ben.kao@intel.com \
--cc=linux-media@vger.kernel.org \
--cc=sakari.ailus@linux.intel.com \
--cc=shawnx.tu@intel.com \
--cc=tfiga@chromium.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).