linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jagath Jog J <jagathjog1996@gmail.com>
To: jic23@kernel.org, lars@metafoo.de, andy.shevchenko@gmail.com,
	sst@poczta.fm, robh+dt@kernel.org
Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH v5 6/7] iio: potentiometer: Add support for Maxim DS3502
Date: Wed, 23 Feb 2022 22:05:24 +0530	[thread overview]
Message-ID: <20220223163525.13399-7-jagathjog1996@gmail.com> (raw)
In-Reply-To: <20220223163525.13399-1-jagathjog1996@gmail.com>

The DS3502 is a 7-bit, nonvolatile digital potentiometer featuring
an output voltage range of up to 15.5V. DS3502 support is added
into existing DS1803 driver.

Datasheet: https://datasheets.maximintegrated.com/en/ds/DS3502.pdf
Signed-off-by: Jagath Jog J <jagathjog1996@gmail.com>
---
 drivers/iio/potentiometer/Kconfig  |  6 ++---
 drivers/iio/potentiometer/ds1803.c | 37 +++++++++++++++++++++++++++++-
 2 files changed, 39 insertions(+), 4 deletions(-)

diff --git a/drivers/iio/potentiometer/Kconfig b/drivers/iio/potentiometer/Kconfig
index 832df8da2bc6..01dd3f858d99 100644
--- a/drivers/iio/potentiometer/Kconfig
+++ b/drivers/iio/potentiometer/Kconfig
@@ -27,11 +27,11 @@ config AD5272
 	  module will be called ad5272.
 
 config DS1803
-	tristate "Maxim Integrated DS1803 Digital Potentiometer driver"
+	tristate "Maxim Integrated DS1803 and similar Digital Potentiometer driver"
 	depends on I2C
 	help
-	  Say yes here to build support for the Maxim Integrated DS1803
-	  digital potentiometer chip.
+	  Say yes here to build support for the Maxim Integrated DS1803 and
+	  DS3502 digital potentiometer chip.
 
 	  To compile this driver as a module, choose M here: the
 	  module will be called ds1803.
diff --git a/drivers/iio/potentiometer/ds1803.c b/drivers/iio/potentiometer/ds1803.c
index 878188351f8f..81456b7d314b 100644
--- a/drivers/iio/potentiometer/ds1803.c
+++ b/drivers/iio/potentiometer/ds1803.c
@@ -1,12 +1,15 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
- * Maxim Integrated DS1803 digital potentiometer driver
+ * Maxim Integrated DS1803 and similar digital potentiometer driver
  * Copyright (c) 2016 Slawomir Stepien
+ * Copyright (c) 2022 Jagath Jog J
  *
  * Datasheet: https://datasheets.maximintegrated.com/en/ds/DS1803.pdf
+ * Datasheet: https://datasheets.maximintegrated.com/en/ds/DS3502.pdf
  *
  * DEVID	#Wipers	#Positions	Resistor Opts (kOhm)	i2c address
  * ds1803	2	256		10, 50, 100		0101xxx
+ * ds3502	1	128		10			01010xx
  */
 
 #include <linux/err.h>
@@ -19,11 +22,13 @@
 
 #define DS1803_WIPER_0         0xA9
 #define DS1803_WIPER_1         0xAA
+#define DS3502_WR_IVR          0x00
 
 enum ds1803_type {
 	DS1803_010,
 	DS1803_050,
 	DS1803_100,
+	DS3502,
 };
 
 struct ds1803_cfg {
@@ -57,6 +62,10 @@ static const struct iio_chan_spec ds1803_channels[] = {
 	DS1803_CHANNEL(1, DS1803_WIPER_1),
 };
 
+static const struct iio_chan_spec ds3502_channels[] = {
+	DS1803_CHANNEL(0, DS3502_WR_IVR),
+};
+
 static int ds1803_read(struct iio_dev *indio_dev,
 		       struct iio_chan_spec const *chan,
 		       int *val)
@@ -73,6 +82,21 @@ static int ds1803_read(struct iio_dev *indio_dev,
 	return ret;
 }
 
+static int ds3502_read(struct iio_dev *indio_dev,
+		       struct iio_chan_spec const *chan,
+		       int *val)
+{
+	struct ds1803_data *data = iio_priv(indio_dev);
+	int ret;
+
+	ret = i2c_smbus_read_byte_data(data->client, chan->address);
+	if (ret < 0)
+		return ret;
+
+	*val = ret;
+	return ret;
+}
+
 static const struct ds1803_cfg ds1803_cfg[] = {
 	[DS1803_010] = {
 	  .wipers = 2,
@@ -98,6 +122,14 @@ static const struct ds1803_cfg ds1803_cfg[] = {
 	  .num_channels = ARRAY_SIZE(ds1803_channels),
 	  .read = ds1803_read,
 	},
+	[DS3502] = {
+	  .wipers = 1,
+	  .avail = { 0, 1, 127 },
+	  .kohms =  10,
+	  .channels = ds3502_channels,
+	  .num_channels = ARRAY_SIZE(ds3502_channels),
+	  .read = ds3502_read,
+	},
 };
 
 static int ds1803_read_raw(struct iio_dev *indio_dev,
@@ -199,6 +231,7 @@ static const struct of_device_id ds1803_dt_ids[] = {
 	{ .compatible = "maxim,ds1803-010", .data = &ds1803_cfg[DS1803_010] },
 	{ .compatible = "maxim,ds1803-050", .data = &ds1803_cfg[DS1803_050] },
 	{ .compatible = "maxim,ds1803-100", .data = &ds1803_cfg[DS1803_100] },
+	{ .compatible = "maxim,ds3502", .data = &ds1803_cfg[DS3502] },
 	{}
 };
 MODULE_DEVICE_TABLE(of, ds1803_dt_ids);
@@ -207,6 +240,7 @@ static const struct i2c_device_id ds1803_id[] = {
 	{ "ds1803-010", DS1803_010 },
 	{ "ds1803-050", DS1803_050 },
 	{ "ds1803-100", DS1803_100 },
+	{ "ds3502", DS3502 },
 	{}
 };
 MODULE_DEVICE_TABLE(i2c, ds1803_id);
@@ -223,5 +257,6 @@ static struct i2c_driver ds1803_driver = {
 module_i2c_driver(ds1803_driver);
 
 MODULE_AUTHOR("Slawomir Stepien <sst@poczta.fm>");
+MODULE_AUTHOR("Jagath Jog J <jagathjog1996@gmail.com>");
 MODULE_DESCRIPTION("DS1803 digital potentiometer");
 MODULE_LICENSE("GPL v2");
-- 
2.17.1


  parent reply	other threads:[~2022-02-23 16:36 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-23 16:35 [PATCH v5 0/7] iio: potentiometer: Add support for DS3502 Jagath Jog J
2022-02-23 16:35 ` [PATCH v5 1/7] iio: potentiometer: Alignment to match the open parenthesis Jagath Jog J
2022-02-26 18:35   ` Jonathan Cameron
2022-02-23 16:35 ` [PATCH v5 2/7] iio: potentiometer: Add available functionality Jagath Jog J
2022-02-26 18:40   ` Jonathan Cameron
2022-02-23 16:35 ` [PATCH v5 3/7] iio: potentiometer: Add channel information in device data Jagath Jog J
2022-02-23 16:35 ` [PATCH v5 4/7] iio: potentiometer: Change to firmware provided data Jagath Jog J
2022-02-23 16:35 ` [PATCH v5 5/7] iio: potentiometer: Add device specific read_raw function Jagath Jog J
2022-02-24  0:46   ` Andy Shevchenko
2022-02-26 18:39     ` Jonathan Cameron
2022-02-23 16:35 ` Jagath Jog J [this message]
2022-02-23 16:35 ` [PATCH v5 7/7] dt-bindings: iio: potentiometer: Add Maxim DS3502 in trivial-devices Jagath Jog J
2022-02-24  0:47 ` [PATCH v5 0/7] iio: potentiometer: Add support for DS3502 Andy Shevchenko
2022-02-26 18:41   ` 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=20220223163525.13399-7-jagathjog1996@gmail.com \
    --to=jagathjog1996@gmail.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=devicetree@vger.kernel.org \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robh+dt@kernel.org \
    --cc=sst@poczta.fm \
    /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).