From: Sakari Ailus <sakari.ailus@linux.intel.com>
To: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: linux-media@vger.kernel.org,
Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Subject: Re: [PATCH] media: i2c: IMX296 camera sensor driver
Date: Mon, 4 Nov 2019 17:20:17 +0200 [thread overview]
Message-ID: <20191104152016.GG11844@kekkonen.localdomain> (raw)
In-Reply-To: <20191104133351.GB4913@pendragon.ideasonboard.com>
Hi Laurent,
On Mon, Nov 04, 2019 at 03:33:51PM +0200, Laurent Pinchart wrote:
...
> > > +static int imx296_read(struct imx296 *imx, u32 addr)
> > > +{
> > > + u8 data[3] = { 0, 0, 0 };
> > > + int ret;
> > > +
> > > + ret = regmap_raw_read(imx->regmap, addr & IMX296_REG_ADDR_MASK, data,
> > > + (addr >> IMX296_REG_SIZE_SHIFT) & 3);
> > > + if (ret < 0)
> > > + return ret;
> > > +
> > > + return (data[2] << 16) | (data[1] << 8) | data[0];
> >
> > Hmm. Don't you need to cast this to a wider type to avoid limiting this to
> > an 8-bit number?
>
> The C99 standard states in section 6.5.7 "Bitwise shift operators"
>
> "The integer promotions are performed on each of the operands. The type
> of the result is that of the promoted left operand."
>
> Section 6.3.1.1 "Boolean, characters, and integers" then states
>
> "If an int can represent all values of the original type, the value is
> converted to an int; otherwise, it is converted to an unsigned int.
> These are called the integer promotions. All other types are unchanged
> by the integer promotions."
>
> No cast is thus needed.
Ack. Thanks for the explanation.
...
> > > + /*
> > > + * HMAX and VMAX configure horizontal and vertical blanking by
> > > + * specifying the total line time and frame time respectively. The line
> > > + * time is specified in operational clock units (which appears to be the
> > > + * output of an internal PLL, fixed at 74.25 MHz regardless of the
> > > + * exernal clock frequency), while the frame time is specified as a
> > > + * number of lines.
> > > + *
> > > + * In the vertical direction the sensor outputs the following:
> > > + *
> > > + * - one line for the FS packet
> > > + * - two lines of embedded data (DT 0x12)
> > > + * - six null lines (DT 0x10)
> > > + * - four lines of vertical effective optical black (DT 0x37)
> > > + * - 8 to 1088 lines of active image data (RAW10, DT 0x2b)
> > > + * - one line for the FE packet
> > > + * - 16 or more lines of vertical blanking
> > > + */
> > > + imx296_write(imx, IMX296_HMAX, 1100, &ret);
> > > + imx296_write(imx, IMX296_VMAX, format->height + imx->vblank->cur.val,
> > > + &ret);
> > > +
> > > + for (i = 0; i < 4; ++i)
> >
> > It'd be nice to have e.g. NR_IMX296_INCKSEL or something instead of 4.
>
> How about ARRAY_SIZE(imx->clk_params->incksel) ?
Yes, please.
...
> > > +static int imx296_init_cfg(struct v4l2_subdev *sd,
> > > + struct v4l2_subdev_pad_config *cfg)
> > > +{
> > > + struct v4l2_subdev_selection sel = { 0 };
> > > + struct v4l2_subdev_format format = { 0 };
> > > +
> > > + sel.target = V4L2_SEL_TGT_CROP;
> > > + sel.which = cfg ? V4L2_SUBDEV_FORMAT_TRY : V4L2_SUBDEV_FORMAT_ACTIVE;
> > > + sel.r.width = IMX296_PIXEL_ARRAY_WIDTH;
> > > + sel.r.height = IMX296_PIXEL_ARRAY_HEIGHT;
> >
> > It'd be nicer to set these in variable declaration. Same below.
>
> It's partly a matter of style, but as this is a new driver and you
> maintain sensor drivers, I'll switch to your preferred style here.
It could be argued whether this is a (plain) style issue or not. Thanks in
any case.
...
> > > + const struct i2c_device_id *did)
> > > +{
> > > + struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
> > > + unsigned long clk_rate;
> > > + struct imx296 *imx;
> > > + unsigned int i;
> > > + int ret;
> > > +
> > > + if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
> > > + dev_warn(&adapter->dev,
> > > + "I2C-Adapter doesn't support I2C_FUNC_SMBUS_BYTE\n");
> > > + return -EIO;
> > > + }
> > > +
> > > + imx = devm_kzalloc(&client->dev, sizeof(*imx), GFP_KERNEL);
> > > + if (!imx)
> > > + return -ENOMEM;
> > > +
> > > + imx->dev = &client->dev;
> >
> > You can use &v4l2_get_subdevdata(sd)->dev to get the device, so no need for
> > the dev field.
>
> I could, but only after registering the subdev, and thus not in
> imx296_identify_model() for instance. I could pass the device pointer to
> that function, but I'd prefer accessing dev through a single method
> everywhere in the driver to make it less error-prone.
Fair enough.
--
Regards,
Sakari Ailus
sakari.ailus@linux.intel.com
next prev parent reply other threads:[~2019-11-04 15:23 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-31 13:23 [PATCH] media: i2c: IMX296 camera sensor driver Laurent Pinchart
2019-10-31 14:25 ` Sakari Ailus
2019-11-04 13:33 ` Laurent Pinchart
2019-11-04 15:20 ` Sakari Ailus [this message]
2019-11-04 18:59 ` Laurent Pinchart
2019-11-04 21:30 ` Sakari Ailus
2019-11-05 20:36 ` Laurent Pinchart
2019-11-05 20:59 ` Sakari Ailus
2019-11-01 14:52 ` Manivannan Sadhasivam
2019-11-01 17:37 ` Sakari Ailus
2019-11-04 13:42 ` Laurent Pinchart
2019-11-04 21:08 ` Rob Herring
2019-11-04 22:03 ` Laurent Pinchart
2019-11-04 22:15 ` Rob Herring
2019-11-05 15:03 ` Manivannan Sadhasivam
2019-11-05 17:24 ` Sakari Ailus
2019-11-05 20:38 ` Laurent Pinchart
2019-11-05 20:41 ` Laurent Pinchart
2020-11-26 15:59 ` Manivannan Sadhasivam
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=20191104152016.GG11844@kekkonen.localdomain \
--to=sakari.ailus@linux.intel.com \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-media@vger.kernel.org \
--cc=manivannan.sadhasivam@linaro.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