All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oleksij Rempel <o.rempel@pengutronix.de>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: devicetree <devicetree@vger.kernel.org>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
	linux-iio <linux-iio@vger.kernel.org>,
	Robin van der Gracht <robin@protonic.nl>,
	Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Rob Herring <robh+dt@kernel.org>,
	Pengutronix Kernel Team <kernel@pengutronix.de>,
	David Jander <david@protonic.nl>,
	Jonathan Cameron <jic23@kernel.org>
Subject: Re: [PATCH v3 3/3] iio: adc: add ADC driver for the TI TSC2046 controller
Date: Mon, 22 Mar 2021 15:08:14 +0100	[thread overview]
Message-ID: <20210322140814.kp23m4b3xx7bapag@pengutronix.de> (raw)
In-Reply-To: <CAHp75VeemLnMJWQOHL8qrqaher2kOn1xTye1tK2OPtpSHhwOcA@mail.gmail.com>

On Mon, Mar 22, 2021 at 03:41:22PM +0200, Andy Shevchenko wrote:
> On Mon, Mar 22, 2021 at 12:30 PM Oleksij Rempel <o.rempel@pengutronix.de> wrote:
> > On Fri, Mar 19, 2021 at 07:42:41PM +0200, Andy Shevchenko wrote:
> > > On Fri, Mar 19, 2021 at 4:45 PM Oleksij Rempel <o.rempel@pengutronix.de> wrote:
> 
> ...
> 
> > > > +static u16 tsc2046_adc_get_value(struct tsc2046_adc_atom *buf)
> > > > +{
> > > > +       /* Last 3 bits on the wire are empty */
> > >
> > > Last?! You meant Least significant?
> >
> > ACK. LSB
> >
> > > Also, don't we lose precision if a new compatible chip appears that
> > > does fill those bits?
> >
> > ACK. All of controllers supported by this driver:
> > drivers/input/touchscreen/ads7846.c:
> > - ti,tsc2046
> > - ti,ads7843
> > - ti,ads7845
> > - ti,ads7846
> > - ti,ads7873 (hm, there is no ti,ads7873, is it actually analog devices AD7873?)
> >
> > support 8- or 12-bit resolution. Only 12 bit mode is supported by this
> > driver. It is possible that some one can produce a resistive touchscreen
> > controller based on X > 12bit ADC, but this will probably not increase precision
> > of this construction (there is a lot of noise any ways...). With other
> > words, it is possible, but not probably that some one will really do it.
> >
> > > Perhaps define the constant and put a comment why it's like this.
> 
> Okay, and what happens here is something like cutting LSBs, but it
> sounds strange to me. If you get 16 bit values, the MSBs should not be
> used?
> 
> So, a good comment is required to explain the logic behind.
> 
> > > > +       return get_unaligned_be16(&buf->data) >> 3;
> > > > +}
> 
> ...
> 
> > > > +static size_t tsc2046_adc_group_set_layout(struct tsc2046_adc_priv *priv,
> > > > +                                          unsigned int group,
> > > > +                                          unsigned int ch_idx)
> > > > +{
> > > > +       struct tsc2046_adc_ch_cfg *ch = &priv->ch_cfg[ch_idx];
> > > > +       struct tsc2046_adc_group_layout *prev, *cur;
> > > > +       unsigned int max_count, count_skip;
> > > > +       unsigned int offset = 0;
> > > > +
> > > > +       if (group) {
> > > > +               prev = &priv->l[group - 1];
> > > > +               offset = prev->offset + prev->count;
> > > > +       }
> > >
> > > I guess you may easily refactor this by supplying a pointer to the
> > > current layout + current size.
> >
> > Sure, but this will not make code more readable and it will not affect
> > the performance. Are there any other reason to do it? Just to make one
> > line instead of two?
> 
> It's still N - 1 unneeded checks and code is slightly harder to read.

fixed

> > > > +       cur = &priv->l[group];
> > >
> > > Also, can you move it down closer to the (single?) caller.
> > >
> > > > +}
> 
> ...
> 
> > > > +               dev_err_ratelimited(dev, "SPI transfer filed: %pe\n",
> > > > +                                   ERR_PTR(ret));
> > >
> > > One line?
> >
> > it will exceed the 80 char rule
> 
> It's fine here.

fixed

> ...
> 
> > > > +       spin_lock_irqsave(&priv->trig_lock, flags);
> > > > +
> > > > +       disable_irq_nosync(priv->spi->irq);
> > >
> > > > +       atomic_inc(&priv->trig_more_count);
> > >
> > > You already have a spin lock, do you need to use the atomic API?
> >
> > I can only pass review comment from my other driver:
> > Memory locations that are concurrently accessed needs to be
> > marked as such, otherwise the compiler is allowed to funky stuff:
> > https://lore.kernel.org/lkml/CAGzjT4ez+gWr3BFQsEr-wma+vs6UZNJ+mRARx_BWoAKEJSsN=w@mail.gmail.com/
> >
> > And here is one more link:
> > https://lwn.net/Articles/793253/#How%20Real%20Is%20All%20This?
> >
> > Starting with commit 62e8a3258bda atomic API is using READ/WRITE_ONCE,
> > so I assume, I do nothing wrong by using it. Correct?
> 
> Hmm... What I don't understand here is why you need a second level of
> atomicity. spin lock already makes this access atomic (at least I have
> checked couple of places and in both the variable is being accessed
> under spin lock).

fixed

> > > > +       iio_trigger_poll(priv->trig);
> > > > +
> > > > +       spin_unlock_irqrestore(&priv->trig_lock, flags);
> 
> ...
> 
> > > > +       name = devm_kasprintf(dev, GFP_KERNEL, "%s-%s",
> > > > +                             TI_TSC2046_NAME, dev_name(dev));
> > >
> > > No NULL check?
> > > Should be added or justified.
> >
> > name is set not optionally  by the spi_add_device()->spi_dev_set_name()
> 
> I didn't get it.
> You allocate memory and haven't checked against NULL. Why?

> If the name field is optional and having it's NULL is okay (non-fatal
> error), put a comment.

ah... I missed the point. You was talking about name == NULL, i was
thinking about dev_name(dev) == NULL.

fixed

> ...
> 
> > > > +       trig->dev.parent = indio_dev->dev.parent;
> > >
> > > Don't we have this done by core (some recent patches in upstream)?
> >
> > can you please point to the code which is doing it?
> 
> I believe it's this one:
> 
> commit 970108185a0be29d1dbb25202d8c12d798e1c3a5
> Author: Gwendal Grignou <gwendal@chromium.org>
> Date:   Tue Mar 9 11:36:13 2021 -0800
> 
>    iio: set default trig->dev.parent

ok, found it on iio/testing and rebased against it..

fixed

Thank you,
Oleksij
-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

  reply	other threads:[~2021-03-22 14:09 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-19 14:45 [PATCH v3 0/3] mainline ti tsc2046 adc driver Oleksij Rempel
2021-03-19 14:45 ` [PATCH v3 1/3] dt-bindings:iio:adc: add generic settling-time-us and oversampling-ratio channel properties Oleksij Rempel
2021-03-19 14:45 ` [PATCH v3 2/3] dt-bindings:iio:adc: add documentation for TI TSC2046 controller Oleksij Rempel
2021-03-19 14:45 ` [PATCH v3 3/3] iio: adc: add ADC driver for the " Oleksij Rempel
2021-03-19 16:35   ` kernel test robot
2021-03-19 16:35     ` kernel test robot
2021-03-19 17:42   ` Andy Shevchenko
2021-03-22 10:30     ` Oleksij Rempel
2021-03-22 13:41       ` Andy Shevchenko
2021-03-22 14:08         ` Oleksij Rempel [this message]
2021-03-20 15:46   ` Jonathan Cameron
2021-03-22 11:56     ` Oleksij Rempel
2021-03-22 14:27       ` Jonathan Cameron
2021-03-29  7:38         ` Oleksij Rempel
2021-03-29 10:23           ` Jonathan Cameron

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=20210322140814.kp23m4b3xx7bapag@pengutronix.de \
    --to=o.rempel@pengutronix.de \
    --cc=andy.shevchenko@gmail.com \
    --cc=david@protonic.nl \
    --cc=devicetree@vger.kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=jic23@kernel.org \
    --cc=kernel@pengutronix.de \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pmeerw@pmeerw.net \
    --cc=robh+dt@kernel.org \
    --cc=robin@protonic.nl \
    /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.