devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Martina Krasteva" <martinax.krasteva@linux.intel.com>
To: "'Sakari Ailus'" <sakari.ailus@linux.intel.com>
Cc: <linux-media@vger.kernel.org>, <mchehab@kernel.org>,
	<robh+dt@kernel.org>, <devicetree@vger.kernel.org>,
	<daniele.alessandrelli@linux.intel.com>,
	<paul.j.murphy@linux.intel.com>,
	<gjorgjix.rosikopulos@linux.intel.com>
Subject: RE: [PATCH v4 2/2] media: i2c: Add imx334 camera sensor driver
Date: Fri, 11 Dec 2020 11:51:05 -0000	[thread overview]
Message-ID: <011701d6cfb3$eaa5ac30$bff10490$@linux.intel.com> (raw)
In-Reply-To: <20201211113153.GA23771@paasikivi.fi.intel.com>

Hi Sakari,

> -----Original Message-----
> From: Sakari Ailus <sakari.ailus@linux.intel.com>
> Sent: Friday, December 11, 2020 11:32 AM
> To: Martina Krasteva <martinax.krasteva@linux.intel.com>
> Cc: linux-media@vger.kernel.org; mchehab@kernel.org; robh+dt@kernel.org;
> devicetree@vger.kernel.org; daniele.alessandrelli@linux.intel.com;
> paul.j.murphy@linux.intel.com; gjorgjix.rosikopulos@linux.intel.com
> Subject: Re: [PATCH v4 2/2] media: i2c: Add imx334 camera sensor driver
> 
> Hi Martina,
> 
> On Fri, Dec 11, 2020 at 10:56:33AM +0000, Martina Krasteva wrote:
> ...
> > +static int imx334_read_reg(struct imx334 *imx334, u16 reg, u32 len,
> > +u32 *val) {
> > +	struct i2c_client *client = v4l2_get_subdevdata(&imx334->sd);
> > +	struct i2c_msg msgs[2] = { 0 };
> > +	u8 addr_buf[2] = { 0 };
> > +	u8 data_buf[4] = { 0 };
> > +	int ret;
> > +
> > +	if (WARN_ON(len > 4))
> > +		return -EINVAL;
> > +
> > +	put_unaligned_be16(reg, addr_buf);
> > +
> > +	/* Write register address */
> > +	msgs[0].addr = client->addr;
> > +	msgs[0].flags = 0;
> > +	msgs[0].len = ARRAY_SIZE(addr_buf);
> > +	msgs[0].buf = addr_buf;
> > +
> > +	/* Read data from register */
> > +	msgs[1].addr = client->addr;
> > +	msgs[1].flags = I2C_M_RD;
> > +	msgs[1].len = len;
> > +	msgs[1].buf = &data_buf[4 - len];
> > +
> > +	ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
> > +	if (ret != ARRAY_SIZE(msgs))
> > +		return -EIO;
> > +
> > +	*val = get_unaligned_le32(data_buf + (4 - len));
> 
> Hmm. The device native endianness is big (on control interface) unless
> something very unexpected happened in hardware development.
> 
> You also can't do this as this will overrun data_buf.

Imx334 uses little endian so I have to convert the values. 
> 
> > +
> > +	return 0;
> > +}
> > +
> > +/**
> > + * imx334_write_reg() - Write register
> > + * @imx334: pointer to imx334 device
> > + * @reg: register address
> > + * @len: length of bytes. Max supported bytes is 4
> > + * @val: register value
> > + *
> > + * Return: 0 if successful, error code otherwise.
> > + */
> > +static int imx334_write_reg(struct imx334 *imx334, u16 reg, u32 len,
> > +u32 val) {
> > +	struct i2c_client *client = v4l2_get_subdevdata(&imx334->sd);
> > +	u8 buf[6] = {0};
> > +
> > +	if (WARN_ON(len > 4))
> > +		return -EINVAL;
> > +
> > +	put_unaligned_be16(reg, buf);
> > +	put_unaligned_le32(val, buf + 2);
> 
> Similar comment on this one.
> 
> --
> Kind regards,
> 
> Sakari Ailus


  reply	other threads:[~2020-12-11 11:54 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-11 10:56 [PATCH v4 0/2] IMX334 Camera Sensor Driver Martina Krasteva
2020-12-11 10:56 ` [PATCH v4 1/2] dt-bindings: media: Add bindings for imx334 Martina Krasteva
2020-12-11 10:56 ` [PATCH v4 2/2] media: i2c: Add imx334 camera sensor driver Martina Krasteva
2020-12-11 11:31   ` Sakari Ailus
2020-12-11 11:51     ` Martina Krasteva [this message]
2021-01-25 12:55       ` 'Sakari Ailus'
2021-01-25 16:37         ` Martina Krasteva
2021-01-25 13:08   ` Sakari Ailus
2021-01-25 17:14     ` Martina Krasteva

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='011701d6cfb3$eaa5ac30$bff10490$@linux.intel.com' \
    --to=martinax.krasteva@linux.intel.com \
    --cc=daniele.alessandrelli@linux.intel.com \
    --cc=devicetree@vger.kernel.org \
    --cc=gjorgjix.rosikopulos@linux.intel.com \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=paul.j.murphy@linux.intel.com \
    --cc=robh+dt@kernel.org \
    --cc=sakari.ailus@linux.intel.com \
    /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).