From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Hans Verkuil <hverkuil@xs4all.nl>
Cc: Todor Tomov <ttomov@mm-sol.com>,
Todor Tomov <todor.tomov@linaro.org>,
linux-media@vger.kernel.org
Subject: Re: [PATCH] media: Add a driver for the ov5645 camera sensor.
Date: Mon, 16 May 2016 15:13:41 +0300 [thread overview]
Message-ID: <1755291.v0jfUP1x0u@avalon> (raw)
In-Reply-To: <573986F1.1070109@xs4all.nl>
Hi Hans,
On Monday 16 May 2016 10:38:09 Hans Verkuil wrote:
> On 05/16/2016 10:23 AM, Todor Tomov wrote:
> > On 05/13/2016 10:02 AM, Hans Verkuil wrote:
> >> On 05/12/2016 04:59 PM, Todor Tomov wrote:
> >>> The ov5645 sensor from Omnivision supports up to 2592x1944
> >>> and CSI2 interface.
> >>>
> >>> The driver adds support for the following modes:
> >>> - 1280x960
> >>> - 1920x1080
> >>> - 2592x1944
> >>>
> >>> Output format is packed 8bit UYVY.
> >>>
> >>> Signed-off-by: Todor Tomov <todor.tomov@linaro.org>
> >>> ---
> >>>
> >>> .../devicetree/bindings/media/i2c/ov5645.txt | 54 +
> >>> drivers/media/i2c/Kconfig | 11 +
> >>> drivers/media/i2c/Makefile | 1 +
> >>> drivers/media/i2c/ov5645.c | 1344 +++++++++++++
> >>> 4 files changed, 1410 insertions(+)
> >>> create mode 100644
> >>> Documentation/devicetree/bindings/media/i2c/ov5645.txt
> >>> create mode 100644 drivers/media/i2c/ov5645.c
> >>>
> >>> +static int ov5645_open(struct v4l2_subdev *subdev, struct
> >>> v4l2_subdev_fh *fh) +{
> >>> + return ov5645_s_power(subdev, true);
> >>> +}
> >>> +
> >>> +static int ov5645_close(struct v4l2_subdev *subdev, struct
> >>> v4l2_subdev_fh *fh) +{
> >>> + return ov5645_s_power(subdev, false);
> >>> +}
> >>
> >> This won't work: you can open the v4l-subdev node multiple times, so if I
> >> open it twice then the next close will power down the chip and the last
> >> remaining open is in a bad state.
> >
> > Multiple power up/down are handled inside ov5645_s_power. There is
> > power_count reference counting variable. Do you see any problem with
> > this?
> >
> >>> +
> >>> +static int ov5645_s_stream(struct v4l2_subdev *subdev, int enable)
> >>> +{
> >>> + struct ov5645 *ov5645 = to_ov5645(subdev);
> >>> + int ret;
> >>> +
> >>> + dev_dbg(ov5645->dev, "%s: enable = %d\n", __func__, enable);
> >>> +
> >>> + if (enable) {
> >>> + ret = ov5645_change_mode(ov5645, ov5645->current_mode);
> >>> + if (ret < 0) {
> >>> + dev_err(ov5645->dev, "could not set mode %d\n",
> >>> + ov5645->current_mode);
> >>> + return ret;
> >>> + }
> >>> + ret = v4l2_ctrl_handler_setup(&ov5645->ctrls);
> >>> + if (ret < 0) {
> >>> + dev_err(ov5645->dev, "could not sync v4l2 controls\n");
> >>> + return ret;
> >>> + }
> >>> + ov5645_write_reg(ov5645, OV5645_SYSTEM_CTRL0,
> >>> + OV5645_SYSTEM_CTRL0_START);
> >>> + } else {
> >>> + ov5645_write_reg(ov5645, OV5645_SYSTEM_CTRL0,
> >>> + OV5645_SYSTEM_CTRL0_STOP);
> >>> + }
> >>> +
> >>> + return 0;
> >>> +}
> >>
> >> It might make more sense to power up on s_stream(true) or off on
> >> s_stream(false).
> >
> > When the sensor is powered up on open, it allows to open the subdev, set
> > any controls and have the result from configuring these controls in
> > hardware (without starting streaming). This is my reasoning behind this.
>
> It's fairly pointless. If you open the device, set controls, then close it,
> they are all lost again. You are already setting everything up again in
> s_stream anyway.
>
> Just don't bother with s_power in the open and close (or with refcounting
> for that matter).
In which case the .s_ctrl() handler will need to bail out early if power isn't
applied, with locking to ensure there's no race condition. Having a
.s_power(1) call in .open() solves that, and also allows userspace to power
the device on and set controls early if needed, as long as the file handle is
kept open.
> BTW, if I am not mistaken a bridge driver that calls this subdev and wants
> to start streaming also has to call s_power before s_stream. So to answer
> my own question: there is no need to call s_power in s_stream.
That I agree with.
--
Regards,
Laurent Pinchart
next prev parent reply other threads:[~2016-05-16 12:13 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-12 14:59 [PATCH] media: Add a driver for the ov5645 camera sensor Todor Tomov
2016-05-13 7:02 ` Hans Verkuil
2016-05-16 8:23 ` Todor Tomov
2016-05-16 8:38 ` Hans Verkuil
2016-05-16 12:13 ` Laurent Pinchart [this message]
2016-05-18 9:32 ` Todor Tomov
2016-05-15 9:53 ` Stanimir Varbanov
2016-05-17 14:58 ` Todor Tomov
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=1755291.v0jfUP1x0u@avalon \
--to=laurent.pinchart@ideasonboard.com \
--cc=hverkuil@xs4all.nl \
--cc=linux-media@vger.kernel.org \
--cc=todor.tomov@linaro.org \
--cc=ttomov@mm-sol.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).