public inbox for devicetree@vger.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
To: Lukas Wunner <lukas-JFq808J9C/izQB+pC5nmwQ@public.gmane.org>
Cc: Hartmut Knaack <knaack.h-Mmb7MZpHnFY@public.gmane.org>,
	Lars-Peter Clausen <lars-Qo5EllUWu/uELgA04lAiVw@public.gmane.org>,
	Peter Meerwald-Stadler
	<pmeerw-jW+XmwGofnusTnJN9+BGXg@public.gmane.org>,
	Mathias Duckeck
	<m.duckeck-XB/JSsFECOqzQB+pC5nmwQ@public.gmane.org>,
	Phil Elwell <phil-FnsA7b+Nu9XbIbC87yuRow@public.gmane.org>,
	"Andrew F. Davis" <afd-l0cyMroinI0@public.gmane.org>,
	linux-iio-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Rob Herring <robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
	Mark Rutland <mark.rutland-5wv7dgnIgG8@public.gmane.org>
Subject: Re: [PATCH 2/2] iio: dac: Add Texas Instruments 8/10/12-bit 2/4-channel DAC driver
Date: Sun, 8 Oct 2017 11:15:06 +0100	[thread overview]
Message-ID: <20171008111506.78fe5e60@archlinux> (raw)
In-Reply-To: <20171007091312.GA6890-JFq808J9C/izQB+pC5nmwQ@public.gmane.org>

On Sat, 7 Oct 2017 11:13:12 +0200
Lukas Wunner <lukas-JFq808J9C/izQB+pC5nmwQ@public.gmane.org> wrote:

> On Sun, Sep 10, 2017 at 04:11:08PM +0100, Jonathan Cameron wrote:
> > On Tue, 5 Sep 2017 11:27:00 +0200 Lukas Wunner <lukas-JFq808J9C/izQB+pC5nmwQ@public.gmane.org> wrote:  
> > > The DACrrcS085 (rr = 08/10/12, c = 2/4) family of SPI DACs was
> > > inherited by TI when they acquired National Semiconductor in 2011.  
> > 
> > Very nice.  A few really minor comments inline.  
> 
> D'accord on all your comments except this one:
> 
> 
> > > +	ret = sscanf(spi->modalias, "dac%2hhu%1d",
> > > +		     &ti_dac->resolution, &indio_dev->num_channels);
> > > +	WARN_ON(ret != 2);  
> > 
> > Whilst this seems nice and clear now, it may not work if this driver
> > had additional parts added in future. 
> > 
> > I would prefer an explicit table with this information in it and
> > use an enum to reference into it.
> > 
> > This is a bit 'too clever' :)  
> 
> Hm, I looked at the other SPI DACs available from TI and their programming
> interface is sufficiently different that they don't lend themselves all
> too well for integration into this driver.  There might be DACs from other
> vendors with a similar programming interface.
> 
> What I *could* do is encode the resolution and number of channels in the
> driver_data field of the spi MODULE_DEVICE_TABLE like this:
> 
> static const struct spi_device_id ti_dac_spi_id[] = {
> 	{ "dac082s085",  8 << 8 + 2 },
> 	{ "dac102s085", 10 << 8 + 2 },
> 	...
> 
> Then instead of reading the information from the modalias I'd read them
> from driver_data.  However it looks a bit redundant and silly to me.
> Can we add this extra complexity when the need for it actually arises?

Do it the simple if slightly more lengthy way. It's easier to review
and less likely to be fragile in future.

enum dac082s085_devices {
	DAC082S085,
	DAC102S085
};

struct dac082s085_device_info {
	int resolution;
	int num_channels;
};

static const struct
	dac082s085_device_info dac082s085_devices[dac082s085_devices] = {
		DAC082S085 = {
			.resolution = 8,
			.num_channels = 2,
		},
	....		
};

Then pick the relevant structure when you probe.

It's long code, but it is really easy to tell if it is correct.
Here we are trading off verbosity for maintainability.

Jonathan

> 
> Thanks,
> 
> Lukas
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2017-10-08 10:15 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-05  9:27 [PATCH 1/2] dt-bindings: iio: dac: ti-dac082s085: Document new driver Lukas Wunner
     [not found] ` <cceeb1a985343d36dc90d2708371f3e1a73264f6.1504602350.git.lukas-JFq808J9C/izQB+pC5nmwQ@public.gmane.org>
2017-09-05  9:27   ` [PATCH 2/2] iio: dac: Add Texas Instruments 8/10/12-bit 2/4-channel DAC driver Lukas Wunner
     [not found]     ` <5d861035569248ac4ae971638ce7fd1e50947232.1504602350.git.lukas-JFq808J9C/izQB+pC5nmwQ@public.gmane.org>
2017-09-10 15:11       ` Jonathan Cameron
2017-10-07  9:13         ` Lukas Wunner
     [not found]           ` <20171007091312.GA6890-JFq808J9C/izQB+pC5nmwQ@public.gmane.org>
2017-10-08 10:15             ` Jonathan Cameron [this message]
2017-09-10 15:12   ` [PATCH 1/2] dt-bindings: iio: dac: ti-dac082s085: Document new driver Jonathan Cameron
2017-09-12 21:51   ` Rob Herring

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=20171008111506.78fe5e60@archlinux \
    --to=jic23-dgejt+ai2ygdnm+yrofe0a@public.gmane.org \
    --cc=afd-l0cyMroinI0@public.gmane.org \
    --cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=knaack.h-Mmb7MZpHnFY@public.gmane.org \
    --cc=lars-Qo5EllUWu/uELgA04lAiVw@public.gmane.org \
    --cc=linux-iio-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=lukas-JFq808J9C/izQB+pC5nmwQ@public.gmane.org \
    --cc=m.duckeck-XB/JSsFECOqzQB+pC5nmwQ@public.gmane.org \
    --cc=mark.rutland-5wv7dgnIgG8@public.gmane.org \
    --cc=phil-FnsA7b+Nu9XbIbC87yuRow@public.gmane.org \
    --cc=pmeerw-jW+XmwGofnusTnJN9+BGXg@public.gmane.org \
    --cc=robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.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