All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sakari Ailus <sakari.ailus@linux.intel.com>
To: Grant Grundler <grundler@chromium.org>
Cc: ping-chung.chen@intel.com, linux-media@vger.kernel.org,
	andy.yeh@intel.com, jim.lai@intel.com, tfiga@chromium.org,
	rajmohan.mani@intel.com
Subject: Re: [PATCH v5] media: imx208: Add imx208 camera sensor driver
Date: Tue, 18 Sep 2018 13:52:59 +0300	[thread overview]
Message-ID: <20180918105258.vmnfkenpzlieycxq@paasikivi.fi.intel.com> (raw)
In-Reply-To: <CANEJEGsP7hYtpEVpJrDSjUML_Xja2kj4+oFb98S2ZXn8C+CLNw@mail.gmail.com>

Hi Grant,

On Mon, Sep 17, 2018 at 03:52:30PM -0700, Grant Grundler wrote:
> On Fri, Sep 14, 2018 at 4:41 AM Sakari Ailus
> <sakari.ailus@linux.intel.com> wrote:
> >
> > Hi Ping-chung,
> >
> > My apologies for the late review.
> 
> Yeah...I had the impression this was already accepted. Though it
> should be straight forward to fix up additional things as normal
> patches.

The remaining issues are rather small and there's still time to get the
driver to v4.20, so I see no need to postpone these either.

> 
> [sorry pruning heavily]
> ...
> > > +/* HBLANK control - read only */
> > > +#define IMX208_PPL_384MHZ            2248
> > > +#define IMX208_PPL_96MHZ             2248
> >
> > Does this generally depend on the link frequency?
> 
> This was discussed in earlier patch version: in a nutshell, yes.
> 
> ...
> > > +/* Configurations for supported link frequencies */
> > > +#define IMX208_MHZ                   (1000*1000ULL)
> > > +#define IMX208_LINK_FREQ_384MHZ              (384ULL * IMX208_MHZ)
> > > +#define IMX208_LINK_FREQ_96MHZ               (96ULL * IMX208_MHZ)
> >
> > You could simply write these as 384000000 and 96000000.
> 
> The original code did that. I agree IMX208_MHZ makes this much easier to read.

It is not customary to add driver specific defines for that sort of things;
mostly if you need a plain number you do write a plain number. A sort of an
exception are the SZ_* macros.

The above breaks grep, too.

> 
> ...
> > > +     /* Current mode */
> > > +     const struct imx208_mode *cur_mode;
> > > +
> > > +     /*
> > > +      * Mutex for serialized access:
> > > +      * Protect sensor set pad format and start/stop streaming safely.
> > > +      * Protect access to sensor v4l2 controls.
> > > +      */
> > > +     struct mutex imx208_mx;
> >
> > How about calling it simply e.g. a "mutex"? The struct is already specific
> > to imx208.
> 
> I specifically asked the code not use "mutex" because trying to find
> this specific use of "mutex" with cscope (ctags) is impossible.

The mutex is local to the driver, and in this case also to the file.
Mutexes are commonly called either "mutex" or "lock".

> 
> Defining "mutex" in multiple name spaces is asking for trouble even
> though technically it's "safe" to do.
> 
> ...
> > > +static int imx208_set_pad_format(struct v4l2_subdev *sd,
> > > +                    struct v4l2_subdev_pad_config *cfg,
> > > +                    struct v4l2_subdev_format *fmt)
> > > +{
> > > +     struct imx208 *imx208 = to_imx208(sd);
> > > +     const struct imx208_mode *mode;
> > > +     s32 vblank_def;
> > > +     s32 vblank_min;
> > > +     s64 h_blank;
> > > +     s64 pixel_rate;
> > > +     s64 link_freq;
> > > +
> > > +     mutex_lock(&imx208->imx208_mx);
> > > +
> > > +     fmt->format.code = imx208_get_format_code(imx208);
> > > +     mode = v4l2_find_nearest_size(
> > > +             supported_modes, ARRAY_SIZE(supported_modes), width, height,
> > > +             fmt->format.width, fmt->format.height);
> > > +     imx208_mode_to_pad_format(imx208, mode, fmt);
> > > +     if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
> > > +             *v4l2_subdev_get_try_format(sd, cfg, fmt->pad) = fmt->format;
> > > +     } else {
> > > +             imx208->cur_mode = mode;
> > > +             __v4l2_ctrl_s_ctrl(imx208->link_freq, mode->link_freq_index);
> > > +             link_freq = link_freq_menu_items[mode->link_freq_index];
> >
> > Same as on the imx319 driver --- the link frequencies that are available
> > need to reflect what is specified in firmware.
> 
> <Someone needs to comment here.>  :)
> 
> ...
> > > +static int imx208_set_stream(struct v4l2_subdev *sd, int enable)
> > > +{
> > > +     struct imx208 *imx208 = to_imx208(sd);
> > > +     struct i2c_client *client = v4l2_get_subdevdata(sd);
> > > +     int ret = 0;
> > > +
> > > +     mutex_lock(&imx208->imx208_mx);
> > > +     if (imx208->streaming == enable) {
> > > +             mutex_unlock(&imx208->imx208_mx);
> > > +             return 0;
> > > +     }
> > > +
> > > +     if (enable) {
> > > +             ret = pm_runtime_get_sync(&client->dev);
> > > +             if (ret < 0)
> > > +                     goto err_rpm_put;
> > > +
> > > +             /*
> > > +              * Apply default & customized values
> > > +              * and then start streaming.
> > > +              */
> > > +             ret = imx208_start_streaming(imx208);
> > > +             if (ret)
> > > +                     goto err_rpm_put;
> > > +     } else {
> > > +             imx208_stop_streaming(imx208);
> > > +             pm_runtime_put(&client->dev);
> > > +     }
> > > +
> > > +     imx208->streaming = enable;
> > > +     mutex_unlock(&imx208->imx208_mx);
> > > +
> > > +     /* vflip and hflip cannot change during streaming */
> > > +     v4l2_ctrl_grab(imx208->vflip, enable);
> > > +     v4l2_ctrl_grab(imx208->hflip, enable);
> >
> > Please grab before releasing the lock; use __v4l2_ctrl_grab() here:
> >
> > <URL:https://git.linuxtv.org/sailus/media_tree.git/log/?h=unlocked-ctrl-grab>
> 
> Is the current implementation not correct or is this just the
> preferred way to "grab"?

The problem with the above is that the controls have not been grabbed
before the lock is released, therefore allowing them to be changed just
after starting streaming.

> (And thanks for pointing at the patch which adds the new "API")
> 
> (and I'm ignoring the remaining nit on the assumption it can be
> addressed in the next patch)

-- 
Kind regards,

Sakari Ailus
sakari.ailus@linux.intel.com

  reply	other threads:[~2018-09-18 16:29 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-08  7:16 [PATCH v5] media: imx208: Add imx208 camera sensor driver Ping-chung Chen
2018-09-14 11:41 ` Sakari Ailus
2018-09-17 22:52   ` Grant Grundler
2018-09-18 10:52     ` Sakari Ailus [this message]
2018-09-20  8:51 ` Tomasz Figa
2018-09-20 16:49   ` Grant Grundler
2018-09-20 20:16     ` Sylwester Nawrocki
2018-09-20 21:00       ` Laurent Pinchart
2018-09-21  7:23         ` Helmut Grohne
2018-09-28 13:49           ` Laurent Pinchart
2018-10-01 10:50             ` Helmut Grohne
2018-10-01 12:04               ` Philippe De Muyter
2018-09-20 20:56   ` Sakari Ailus
2018-09-20 21:12     ` Laurent Pinchart
2018-09-20 21:55       ` Ricardo Ribalda Delgado
2018-09-21  7:06         ` Chen, Ping-chung
2018-09-21  7:08         ` Chen, Ping-chung
2018-09-25  9:25           ` Sakari Ailus
2018-09-25 10:17             ` Chen, Ping-chung
2018-09-25 21:54               ` Sakari Ailus
2018-09-26  2:27                 ` Chen, Ping-chung
2018-09-26 10:11                   ` Sakari Ailus
2018-09-26 15:19                     ` Yeh, Andy
2018-09-27  3:19                       ` Chen, Ping-chung
2018-10-04 15:57                         ` Sakari Ailus
2021-04-22  7:21                           ` Tu, ShawnX

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=20180918105258.vmnfkenpzlieycxq@paasikivi.fi.intel.com \
    --to=sakari.ailus@linux.intel.com \
    --cc=andy.yeh@intel.com \
    --cc=grundler@chromium.org \
    --cc=jim.lai@intel.com \
    --cc=linux-media@vger.kernel.org \
    --cc=ping-chung.chen@intel.com \
    --cc=rajmohan.mani@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.