All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tomasz Figa <tfiga@chromium.org>
To: Sakari Ailus <sakari.ailus@iki.fi>
Cc: Yong Zhi <yong.zhi@intel.com>,
	Linux Media Mailing List <linux-media@vger.kernel.org>,
	Sakari Ailus <sakari.ailus@linux.intel.com>,
	"Zheng, Jian Xu" <jian.xu.zheng@intel.com>,
	"Mani, Rajmohan" <rajmohan.mani@intel.com>,
	"Toivonen, Tuukka" <tuukka.toivonen@intel.com>,
	Hans Verkuil <hverkuil@xs4all.nl>,
	"Yang, Hyungwoo" <hyungwoo.yang@intel.com>
Subject: Re: [PATCH v2 3/3] [media] intel-ipu3: cio2: Add new MIPI-CSI2 driver
Date: Tue, 27 Jun 2017 18:33:13 +0900	[thread overview]
Message-ID: <CAAFQd5AGEYRZye3ShEGLrLTyG67jRzSU2-dN6=wmo5DuVxvGaw@mail.gmail.com> (raw)
In-Reply-To: <20170626145105.GN12407@valkosipuli.retiisi.org.uk>

On Mon, Jun 26, 2017 at 11:51 PM, Sakari Ailus <sakari.ailus@iki.fi> wrote:
> On Mon, Jun 12, 2017 at 06:59:18PM +0900, Tomasz Figa wrote:
>
>>
>> > +       if (WARN_ON(freq <= 0))
>> > +               return -EINVAL;
>>
>> It generally doesn't make sense for the frequency to be negative, so
>> maybe the argument should have been unsigned to start with? (And
>> 32-bit if we don't expect frequencies higher than 4 GHz anyway.)
>
> The value comes from a 64-bit integer V4L2 control so that implies the value
> range of s64 as well.

Okay, if there is no way to enforce this at control level, then I
guess we have to keep this here.

>
>>
>> > +
>> > +       /* b could be 0, -2 or -8, so r < 500000000 */
>>
>> Definitely. Anything <= 0 is also less than 500000000. Let's take a
>> look at the computation below again:
>>
>> 1) accinv is multiplied by b,
>> 2) 500000000 is divided by 256 (=== shift right by 8 bits) = 1953125,
>> 3) accinv*b is multiplied by 1953125 to form the value of r.
>>
>> Now let's see at possible maximum absolute values for particular steps:
>> 1) 16 * -8 = -128 (signed 8 bits),
>> 2) 1953125 (unsigned 21 bits),
>> 3) -128 * 1953125 = -249999872 (signed 29 bits).
>>
>> So I think the important thing to note in the comment is:
>>
>> /* b could be 0, -2 or -8, so |accinv * b| is always less than (1 <<
>> ds) and thus |r| < 500000000. */
>>
>> > +       r = accinv * b * (500000000 >> ds);
>>
>> On the other hand, you lose some precision here. If you used s64
>> instead and did the divide shift at the end ((accinv * b * 500000000)
>> >> ds), for the example above you would get -250007629. (Depending on
>> how big freq is, it might not matter, though.)
>>
>
> The frequency is typically hundreds of mega-Hertz.

I think it still would make sense to have the calculation a bit more precise.

>
>> Also nit: What is 500000000? We have local constants defined above, I
>> think it could also make sense to do the same for this one. The
>> compiler should do constant propagation and simplify respective
>> calculations anyway.
>
> COUNT_ACC in the formula in the comment a few decalines above is in
> nanoseconds. Performing the calculations in integer arithmetics results in
> having 500000000 in the resulting formula.
>
> So this is actually a constant related to the hardware but it does not have
> a pre-determined name because it is derived from COUNT_ACC.

Which, I believe, doesn't stop us from naming it.

>> > +static int cio2_v4l2_querycap(struct file *file, void *fh,
>> > +                             struct v4l2_capability *cap)
>> > +{
>> > +       struct cio2_device *cio2 = video_drvdata(file);
>> > +
>> > +       strlcpy(cap->driver, CIO2_NAME, sizeof(cap->driver));
>> > +       strlcpy(cap->card, CIO2_DEVICE_NAME, sizeof(cap->card));
>> > +       snprintf(cap->bus_info, sizeof(cap->bus_info),
>> > +                "PCI:%s", pci_name(cio2->pci_dev));
>> > +       cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING;
>>
>> Hmm, I thought single plane queue type was deprecated these days and
>> _MPLANE recommended for all new drivers. I'll defer this to other
>> reviewers, though.
>
> If the device supports single plane formats only, I don't see a reason to
> use MPLANE buffer types.

On the other hand, if a further new revision of the hardware (or
amendment of supported feature set of current hardware) actually adds
support for multiple planes, changing it to MPLANE will require
keeping a non-MPLANE variant of the code, due to userspace
compatibility concerns...

Best regards,
Tomasz

  reply	other threads:[~2017-06-27  9:33 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-07  1:34 [PATCH v2 0/3] [media] add IPU3 CIO2 CSI2 driver Yong Zhi
2017-06-07  1:34 ` [PATCH v2 1/3] [media] videodev2.h, v4l2-ioctl: add IPU3 raw10 color format Yong Zhi
2017-06-07  1:34 ` [PATCH v2 2/3] [media] doc-rst: add IPU3 raw10 bayer pixel format definitions Yong Zhi
2017-06-07 17:55   ` Alan Cox
2017-06-07  1:34 ` [PATCH v2 3/3] [media] intel-ipu3: cio2: Add new MIPI-CSI2 driver Yong Zhi
2017-06-12  9:59   ` Tomasz Figa
2017-06-13  8:58     ` Tuukka Toivonen
2017-06-13  9:18       ` Tomasz Figa
2017-06-16 11:48     ` Sakari Ailus
2017-06-26 14:51     ` Sakari Ailus
2017-06-27  9:33       ` Tomasz Figa [this message]
2017-06-28 13:31         ` Sakari Ailus
2017-06-28 13:36           ` Tomasz Figa
2017-06-28 14:55             ` Sakari Ailus
     [not found]           ` <CGME20170628154447epcas5p28ba0ff617f6e640185fada0e955e24b0@epcas5p2.samsung.com>
2017-06-28 15:44             ` Sylwester Nawrocki
2017-06-28 15:56               ` Sakari Ailus
2017-10-06 19:19     ` Zhi, Yong

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='CAAFQd5AGEYRZye3ShEGLrLTyG67jRzSU2-dN6=wmo5DuVxvGaw@mail.gmail.com' \
    --to=tfiga@chromium.org \
    --cc=hverkuil@xs4all.nl \
    --cc=hyungwoo.yang@intel.com \
    --cc=jian.xu.zheng@intel.com \
    --cc=linux-media@vger.kernel.org \
    --cc=rajmohan.mani@intel.com \
    --cc=sakari.ailus@iki.fi \
    --cc=sakari.ailus@linux.intel.com \
    --cc=tuukka.toivonen@intel.com \
    --cc=yong.zhi@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 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.