linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: "Nishanth Menon" <nm@ti.com>,
	"Javier Martinez Canillas" <javier@osg.samsung.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Christophe JAILLET" <christophe.jaillet@wanadoo.fr>,
	"Alexandru Ardelean" <ardeleanalex@gmail.com>,
	"Lars-Peter Clausen" <lars@metafoo.de>,
	"Linux Kernel Mailing List" <linux-kernel@vger.kernel.org>,
	linux-iio <linux-iio@vger.kernel.org>,
	Stable <stable@vger.kernel.org>
Subject: Re: [PATCH] iio: adc: ti-adc128s052: Fix number of channels when device tree is used
Date: Fri, 1 Jul 2022 17:31:53 +0100	[thread overview]
Message-ID: <20220701173153.04711237@jic23-huawei> (raw)
In-Reply-To: <CAHp75Vfm+NDzZEB1Qp-3+mbj=NOko=5jjcHr_A4J6-jMpTykhg@mail.gmail.com>

On Fri, 1 Jul 2022 12:13:24 +0200
Andy Shevchenko <andy.shevchenko@gmail.com> wrote:

> On Fri, Jul 1, 2022 at 1:02 AM Nishanth Menon <nm@ti.com> wrote:
> >
> > When device_match_data is called - with device tree, of_match list is  
> 
> device_get_match_data() ?
> 
> > looked up to find the data, which by default is 0. So, no matter which
> > kind of device compatible we use, we match with config 0 which implies
> > we enable 8 channels even on devices that do not have 8 channels.
> >
> > Solve it by providing the match data similar to what we do with the ACPI
> > lookup information.
> >
> > Fixes: 9e611c9e5a20 ("iio: adc128s052: Add OF match table")
> > Cc: <stable@vger.kernel.org> # 5.0+
> > Signed-off-by: Nishanth Menon <nm@ti.com>  
> 
> ...
> 
> > +       { .compatible = "ti,adc128s052", .data = 0},  
> 
> No assignment, 0 _is_ the default here.
> 
> > +       { .compatible = "ti,adc122s021", .data = 1},
> > +       { .compatible = "ti,adc122s051", .data = 1},
> > +       { .compatible = "ti,adc122s101", .data = 1},
> > +       { .compatible = "ti,adc124s021", .data = 2},
> > +       { .compatible = "ti,adc124s051", .data = 2},
> > +       { .compatible = "ti,adc124s101", .data = 2},  
> 
> What you need _ideally_ is rather use pointers to data structure where
> each of that chip is defined, then it will be as simple as
> 
> 
> const struct my_custom_drvdata *data;
> 
> data = device_get_match_data(dev);
> 
> Where my_custom_drvdata::num_of_channels will be already assigned to
> whatever you want on a per chip basis.

Agreed. That's much nicer and a not a lot larger change so still suitable as a fix.

> 
> If the number of channels is the only data you have, then yes, cast it
> to void * in the OF ID table and

It's not just the number of channels.  This is an index into an array of chip
type specific structures. Hence the driver is half way to what you suggested.
Using a pointer for the ACPI and DT paths is the right way to do this.
For the spi_device_id table, you could stick with an index, or move to casting
a pointer to an integer, I don't really mind.

Thanks,

Jonathan

> 
> num = (uintptr_t)device_get_match_data(dev);
> 
> will suffice.
> 


  reply	other threads:[~2022-07-01 16:22 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-30 23:01 [PATCH] iio: adc: ti-adc128s052: Fix number of channels when device tree is used Nishanth Menon
2022-07-01  3:38 ` Nishanth Menon
2022-07-01 10:08   ` Andy Shevchenko
2022-07-01 10:13 ` Andy Shevchenko
2022-07-01 16:31   ` Jonathan Cameron [this message]
2022-07-05 17:47 ` kernel test robot

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=20220701173153.04711237@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=andy.shevchenko@gmail.com \
    --cc=ardeleanalex@gmail.com \
    --cc=christophe.jaillet@wanadoo.fr \
    --cc=javier@osg.samsung.com \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nm@ti.com \
    --cc=nuno.sa@analog.com \
    --cc=stable@vger.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).