linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Christian Eggers <ceggers@arri.de>
Cc: Jonathan Cameron <Jonathan.Cameron@huawei.com>,
	Rob Herring <robh+dt@kernel.org>,
	Hartmut Knaack <knaack.h@gmx.de>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
	<linux-iio@vger.kernel.org>, <devicetree@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2 2/2] iio: light: as73211: New driver
Date: Sat, 1 Aug 2020 16:55:20 +0100	[thread overview]
Message-ID: <20200801165520.56b73fc2@archlinux> (raw)
In-Reply-To: <2665878.D8vGGo3OXt@n95hx1g2>

On Thu, 30 Jul 2020 12:18:56 +0200
Christian Eggers <ceggers@arri.de> wrote:

> Hi Jonathan.
> 
> got your review nearly simultaneous with Andy's. There are many overlaps
> between both. Most is already integrated, below I left only the open points.
> 
> On Tuesday, 28 July 2020, 20:01:14 CEST, Jonathan Cameron wrote:
> > Hi Christian,
> >
> > I took a fairly quick look. Not divided into the datasheet or anything yet!  
> 
> > Christian Eggers <ceggers@arri.de> wrote:  
> > > +/**
> > > + * struct as73211_data - Instance data for one AS73211
> > > + * @client: I2C client.
> > > + * @osr:    Cached Operational State Register.
> > > + * @creg1:  Cached Configuration Register 1.
> > > + * @creg2:  Cached Configuration Register 2.
> > > + * @creg3:  Cached Configuration Register 3.  
> >
> > Just a thought, but why not creg[3]?;  
> creg[3] would be indexed from 0 to 2. But the datasheet names them 1 to 3.
> 
> > > + * @buffer: Buffer for triggered measurements.  
> >
> > ?  Run kernel-doc, or build with W=1 and to check docs.  
> I ran "make htmldoc" and enabled W=1. Are there any errors I should see?
> 
> > > +static unsigned int as73211_integration_time_us(struct as73211_data
> > > *data)
> > > +{
> > > +   /* Integration time has 15 steps, the step size depends on the  
> clock. */
> > > +   unsigned int mul = 1 << (3 - (data->creg3 & 0b11));  /* 8 = 1.024  
> MHz, 4
> > > = 2.048 MHz ...*/ + unsigned int time_cycles =
> > > as73211_integration_time_cycles(data); +    unsigned int time_us =
> > > time_cycles * 125 * mul;  
> >
> > This would be easier to read as
> >
> >       unsigned int mul, time_cycles;
> >
> >       mul = ...
> >
> >       return time_cycles * 125 * mul;
> >  
> changed this according to Andy's proposal.
> 
> > > +static int as73211_read_raw(struct iio_dev *indio_dev,
> > > +                   struct iio_chan_spec const *chan,
> > > +                   int *val, int *val2, long mask)  
> >
> > Align parameters with opening bracket.  
> Mixed tabs(8) and spaces or only spaces?

Tabs and spaces.

> 
> > > +static int _as73211_write_raw(struct iio_dev *indio_dev,
> > > +                   struct iio_chan_spec const *chan  
> __always_unused,
> >
> > Whilst true, what's the benefit of marking that as __always_unused?
> >  
> I read somewhere in the process docs that I should build with EXTRA_CFLAGS=-W

Probably a bit paranoid for a callback, but doesn't really matter.

> 
> > > +           } else {
> > > +                   /* saturate all channels (useful for  
> overflows) */
> > > +                   iio_buffer[1] = 0xffff;
> > > +                   iio_buffer[2] = 0xffff;
> > > +                   iio_buffer[3] = 0xffff;  
> >
> > That is rather non standard.  
> How do other drivers handle measurement errors in buffered mode? The
> application needs to know about measurement overflows as the integration
> time and gain have to be adjusted in case.

It's actually pretty rare to have a device that reports and error.
Many just saturate.  So it's probably fine to mimic that here as long
as the issue is definitely saturation rather than some other error.
If it's another error, don't push data and log some sort of message.
Unfortunately there isn't really a standard interface for
reporting hardware faults in these sort of devices.

From what you have said I'll assume we are just looking at overflow
so can mimic saturation. In which case what you have done is fine.

> 
> > > +static IIO_DEV_ATTR_SAMP_FREQ_AVAIL(as73211_show_samp_freq_available);
> > > +static IIO_DEV_ATTR_INT_TIME_AVAIL(as73211_show_int_time_available);
> > > +static IIO_DEVICE_ATTR(hardwaregain_available, S_IRUGO,
> > > +           as73211_show_hardwaregain_available, NULL, 0);
> > > +static IIO_CONST_ATTR_TEMP_OFFSET("-66.9");
> > > +static IIO_CONST_ATTR_TEMP_SCALE("0.05");
> > > +
> > > +static struct attribute *as73211_attributes[] = {
> > > +   &iio_dev_attr_sampling_frequency_available.dev_attr.attr,
> > > +   &iio_dev_attr_integration_time_available.dev_attr.attr,
> > > +   &iio_dev_attr_hardwaregain_available.dev_attr.attr,
> > > +   &iio_const_attr_in_temp_offset.dev_attr.attr,
> > > +   &iio_const_attr_in_temp_scale.dev_attr.attr,  
> >
> > These should be handled via read_raw.  
> Only the last two ones?
Yup
> 
> > Ideally do the _available ones via the core callbacks
> > and _avail masks as well. For the more complex values,
> > compute the table on first read or at probe and cache it.  
> The list of available values can depend on the setting of other attributes
> (e.g. available integration times depends on sampling frequency).
That's not that unusual.  It's fine to calculate the values
returned as needed, or pick from a selection of options.

> 
> > > +   indio_dev->dev.parent = &client->dev;  
> >
> > That is now set by the IIO core, so no need to set it manually.  
> Can you please give me a pointer? Before removing this in my branch, I need to
> make sure that this is already available in the kernel I'm using (5.4.latest).
I think I mentioned in a later thread, that's in linux-next now.
Though there was a bit of a messup where we added it then accidentally broke
it again, then fixed it finally.

Jonathan

> 
> > > +buffer_cleanup:
> > > +   iio_triggered_buffer_cleanup(indio_dev);  
> >
> > Should we not powerdown on error?  
> yes, we should.
> 
> > Also rather feels like we should have a trivial powerup function to
> > match with powerdown.  
> changed as73211_powerdown() to as73211_power()
> 
> regards
> Christian
> 
> 
> 
> ________________________________
>  [http://assets.arri.com/media/sign/2020-04-03-E-mail-signature-Stellar2_V1.jpg] <https://microsites.arri.com/stellar/>
> 
> Get all the latest information from www.arri.com<https://www.arri.com/>, Facebook<https://www.facebook.com/TeamARRI>, Twitter<https://twitter.com/ARRIChannel>, Instagram<https://instagram.com/arri> and YouTube<https://www.youtube.com/user/ARRIChannel>.
> 
> Arnold & Richter Cine Technik GmbH & Co. Betriebs KG
> Sitz: München - Registergericht: Amtsgericht München - Handelsregisternummer: HRA 57918
> Persönlich haftender Gesellschafter: Arnold & Richter Cine Technik GmbH
> Sitz: München - Registergericht: Amtsgericht München - Handelsregisternummer: HRB 54477
> Geschäftsführer: Dr. Michael Neuhäuser; Stephan Schenk; Walter Trauninger; Markus Zeiler


      reply	other threads:[~2020-08-01 15:55 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-28  6:28 [PATCH v2 0/2] iio: light: Support AMS AS73211 digital XYZ sensor Christian Eggers
2020-07-28  6:28 ` [PATCH v2 1/2] dt-bindings: iio: light: add AMS AS73211 support Christian Eggers
2020-07-28  6:28 ` [PATCH v2 2/2] iio: light: as73211: New driver Christian Eggers
2020-07-28 18:00   ` Andy Shevchenko
2020-07-30 10:18     ` Christian Eggers
2020-07-28 18:01   ` Jonathan Cameron
2020-07-30 10:18     ` Christian Eggers
2020-08-01 15:55       ` Jonathan Cameron [this message]

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=20200801165520.56b73fc2@archlinux \
    --to=jic23@kernel.org \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=ceggers@arri.de \
    --cc=devicetree@vger.kernel.org \
    --cc=knaack.h@gmx.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 \
    /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).