linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Lukas Wunner <lukas@wunner.de>
Cc: Hartmut Knaack <knaack.h@gmx.de>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
	Mathias Duckeck <m.duckeck@kunbus.de>,
	Phil Elwell <phil@raspberrypi.org>,
	linux-iio@vger.kernel.org
Subject: Re: [PATCH v2 3/3] iio: dac: ti-dac082s085: Read chip spec from device table
Date: Sat, 21 Oct 2017 20:38:05 +0100	[thread overview]
Message-ID: <20171021203805.1418d51a@archlinux> (raw)
In-Reply-To: <43bd5525f1db09764a40f4e225a772b30603c3f5.1508232186.git.lukas@wunner.de>

On Tue, 17 Oct 2017 12:42:00 +0200
Lukas Wunner <lukas@wunner.de> wrote:

> The two properties unique to each supported chip, resolution and number
> of channels, are currently gleaned from the chip's name.
> E.g. dac102s085 is a dual channel 10-bit DAC.
>         ^^^
> This was deemed unmaintainable by the subsystem maintainer once the
> driver is extended to support further chips, hence it was requested
> to add an explicit table for chip-specific information and use an
> enum to reference into it.
> 
> This adds 17 LoC without any immediate gain, so make the change in a
> separate commit which can be reverted if we determine in 10 years that
> it was unnecessary.
> 
Good luck with that ;) 
> Signed-off-by: Lukas Wunner <lukas@wunner.de>
Applied to the togreg branch of iio.git and pushed out as testing for
the autobuilders to play with it.

Thanks,

Jonathan
> ---
>  drivers/iio/dac/ti-dac082s085.c | 35 ++++++++++++++++++++++++++---------
>  1 file changed, 26 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/iio/dac/ti-dac082s085.c b/drivers/iio/dac/ti-dac082s085.c
> index 0fefb110be69..2c1556f32574 100644
> --- a/drivers/iio/dac/ti-dac082s085.c
> +++ b/drivers/iio/dac/ti-dac082s085.c
> @@ -20,6 +20,22 @@
>  #include <linux/regulator/consumer.h>
>  #include <linux/spi/spi.h>
>  
> +enum { dual_8bit, dual_10bit, dual_12bit, quad_8bit, quad_10bit, quad_12bit };
> +
> +struct ti_dac_spec {
> +	u8 num_channels;
> +	u8 resolution;
> +};
> +
> +static const struct ti_dac_spec ti_dac_spec[] = {
> +	[dual_8bit]  = { .num_channels = 2, .resolution = 8  },
> +	[dual_10bit] = { .num_channels = 2, .resolution = 10 },
> +	[dual_12bit] = { .num_channels = 2, .resolution = 12 },
> +	[quad_8bit]  = { .num_channels = 4, .resolution = 8  },
> +	[quad_10bit] = { .num_channels = 4, .resolution = 10 },
> +	[quad_12bit] = { .num_channels = 4, .resolution = 12 },
> +};
> +
>  /**
>   * struct ti_dac_chip - TI DAC chip
>   * @lock: protects write sequences
> @@ -246,6 +262,7 @@ static const struct iio_info ti_dac_info = {
>  static int ti_dac_probe(struct spi_device *spi)
>  {
>  	struct device *dev = &spi->dev;
> +	const struct ti_dac_spec *spec;
>  	struct ti_dac_chip *ti_dac;
>  	struct iio_dev *indio_dev;
>  	int ret;
> @@ -267,9 +284,9 @@ static int ti_dac_probe(struct spi_device *spi)
>  	spi_message_init_with_transfers(&ti_dac->mesg, &ti_dac->xfer, 1);
>  	ti_dac->mesg.spi = spi;
>  
> -	ret = sscanf(spi->modalias, "dac%2hhu%1d",
> -		     &ti_dac->resolution, &indio_dev->num_channels);
> -	WARN_ON(ret != 2);
> +	spec = &ti_dac_spec[spi_get_device_id(spi)->driver_data];
> +	indio_dev->num_channels = spec->num_channels;
> +	ti_dac->resolution = spec->resolution;
>  
>  	ti_dac->vref = devm_regulator_get(dev, "vref");
>  	if (IS_ERR(ti_dac->vref))
> @@ -325,12 +342,12 @@ MODULE_DEVICE_TABLE(of, ti_dac_of_id);
>  #endif
>  
>  static const struct spi_device_id ti_dac_spi_id[] = {
> -	{ "dac082s085" },
> -	{ "dac102s085" },
> -	{ "dac122s085" },
> -	{ "dac084s085" },
> -	{ "dac104s085" },
> -	{ "dac124s085" },
> +	{ "dac082s085", dual_8bit  },
> +	{ "dac102s085", dual_10bit },
> +	{ "dac122s085", dual_12bit },
> +	{ "dac084s085", quad_8bit  },
> +	{ "dac104s085", quad_10bit },
> +	{ "dac124s085", quad_12bit },
>  	{ }
>  };
>  MODULE_DEVICE_TABLE(spi, ti_dac_spi_id);


      reply	other threads:[~2017-10-21 19:38 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-17 10:42 [PATCH v2 0/3] Texas Instruments 8/10/12-bit 2/4-channel DAC driver Lukas Wunner
2017-10-17 10:42 ` [PATCH v2 2/3] iio: dac: Add " Lukas Wunner
2017-10-21 19:33   ` Jonathan Cameron
2017-10-22  9:48     ` Lukas Wunner
2017-10-26 15:35       ` Jonathan Cameron
2017-10-17 10:42 ` [PATCH v2 1/3] dt-bindings: iio: dac: ti-dac082s085: Document new driver Lukas Wunner
2017-10-21 19:27   ` Jonathan Cameron
2017-10-17 10:42 ` [PATCH v2 3/3] iio: dac: ti-dac082s085: Read chip spec from device table Lukas Wunner
2017-10-21 19:38   ` 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=20171021203805.1418d51a@archlinux \
    --to=jic23@kernel.org \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=lukas@wunner.de \
    --cc=m.duckeck@kunbus.de \
    --cc=phil@raspberrypi.org \
    --cc=pmeerw@pmeerw.net \
    /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).