public inbox for linux-iio@vger.kernel.org
 help / color / mirror / Atom feed
From: Matt Walker <mattofak@gmail.com>
To: unlisted-recipients:; (no To-header on input)
Cc: Matt Walker <mattofak@gmail.com>,
	Jonathan Cameron <jic23@kernel.org>,
	Hartmut Knaack <knaack.h@gmx.de>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
	Marcus Folkesson <marcus.folkesson@gmail.com>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] IIO: extend dac/MCP4922 to MCP49x1 devices
Date: Thu,  8 Nov 2018 15:36:53 -0500	[thread overview]
Message-ID: <20181108203655.17448-1-mattofak@gmail.com> (raw)

Extend the existing dual channel MCP4922 DAC driver to single channel
MCP49x1 devices. These devices are simple and write only. The most
significant bit of the transfer dictates what channel to write to.

Although there is no danger in writing to the non existant channel in
the single channel devices, it's better to not register it at all.
Therefore extend the driver to know how many channels a device has at
probe time based on the ID table.

Signed-off-by: Matt Walker <mattofak@gmail.com>
---
 drivers/iio/dac/mcp4922.c | 30 ++++++++++++++++++++++++------
 1 file changed, 24 insertions(+), 6 deletions(-)

diff --git a/drivers/iio/dac/mcp4922.c b/drivers/iio/dac/mcp4922.c
index b5190d1dae8e..094f7dd560ca 100644
--- a/drivers/iio/dac/mcp4922.c
+++ b/drivers/iio/dac/mcp4922.c
@@ -29,8 +29,11 @@
 #define MCP4922_NUM_CHANNELS	2
 
 enum mcp4922_supported_device_ids {
+	ID_MCP4901,
 	ID_MCP4902,
+	ID_MCP4911,
 	ID_MCP4912,
+	ID_MCP4921,
 	ID_MCP4922,
 };
 
@@ -115,10 +118,22 @@ static int mcp4922_write_raw(struct iio_dev *indio_dev,
 	}
 }
 
-static const struct iio_chan_spec mcp4922_channels[3][MCP4922_NUM_CHANNELS] = {
-	[ID_MCP4902] = { MCP4922_CHAN(0, 8),	MCP4922_CHAN(1, 8) },
-	[ID_MCP4912] = { MCP4922_CHAN(0, 10),	MCP4922_CHAN(1, 10) },
-	[ID_MCP4922] = { MCP4922_CHAN(0, 12),	MCP4922_CHAN(1, 12) },
+static const unsigned int mcp4922_channel_counts[6] = {
+	[ID_MCP4901] = 1,
+	[ID_MCP4902] = 2,
+	[ID_MCP4911] = 1,
+	[ID_MCP4912] = 2,
+	[ID_MCP4921] = 1,
+	[ID_MCP4922] = 2,
+};
+
+static const struct iio_chan_spec mcp4922_channels[6][MCP4922_NUM_CHANNELS] = {
+	[ID_MCP4901] = { MCP4922_CHAN(0, 8),  {} },
+	[ID_MCP4902] = { MCP4922_CHAN(0, 8),  MCP4922_CHAN(1, 8) },
+	[ID_MCP4911] = { MCP4922_CHAN(0, 10), {} },
+	[ID_MCP4912] = { MCP4922_CHAN(0, 10), MCP4922_CHAN(1, 10) },
+	[ID_MCP4921] = { MCP4922_CHAN(0, 12), {} },
+	[ID_MCP4922] = { MCP4922_CHAN(0, 12), MCP4922_CHAN(1, 12) },
 };
 
 static const struct iio_info mcp4922_info = {
@@ -166,7 +181,7 @@ static int mcp4922_probe(struct spi_device *spi)
 	indio_dev->info = &mcp4922_info;
 	indio_dev->modes = INDIO_DIRECT_MODE;
 	indio_dev->channels = mcp4922_channels[id->driver_data];
-	indio_dev->num_channels = MCP4922_NUM_CHANNELS;
+	indio_dev->num_channels = mcp4922_channel_counts[id->driver_data];
 	indio_dev->name = id->name;
 
 	ret = iio_device_register(indio_dev);
@@ -197,8 +212,11 @@ static int mcp4922_remove(struct spi_device *spi)
 }
 
 static const struct spi_device_id mcp4922_id[] = {
+	{"mcp4901", ID_MCP4901},
 	{"mcp4902", ID_MCP4902},
+	{"mcp4911", ID_MCP4911},
 	{"mcp4912", ID_MCP4912},
+	{"mcp4921", ID_MCP4921},
 	{"mcp4922", ID_MCP4922},
 	{}
 };
@@ -215,5 +233,5 @@ static struct spi_driver mcp4922_driver = {
 module_spi_driver(mcp4922_driver);
 
 MODULE_AUTHOR("Michael Welling <mwelling@ieee.org>");
-MODULE_DESCRIPTION("Microchip MCP4902, MCP4912, MCP4922 DAC");
+MODULE_DESCRIPTION("Microchip MCP49xx DAC");
 MODULE_LICENSE("GPL v2");
-- 
2.17.1

             reply	other threads:[~2018-11-09  6:15 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-08 20:36 Matt Walker [this message]
2018-11-11 12:49 ` [PATCH] IIO: extend dac/MCP4922 to MCP49x1 devices 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=20181108203655.17448-1-mattofak@gmail.com \
    --to=mattofak@gmail.com \
    --cc=jic23@kernel.org \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marcus.folkesson@gmail.com \
    --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