Skip to content

Commit

Permalink
iio: potentiometer: ds1803: Add support for Maxim DS3502
Browse files Browse the repository at this point in the history
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>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Link: https://lore.kernel.org/r/20220223163525.13399-7-jagathjog1996@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
  • Loading branch information
Jagath Jog J authored and Jonathan Cameron committed Feb 26, 2022
1 parent 9b68725 commit 73c1698
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
6 changes: 3 additions & 3 deletions drivers/iio/potentiometer/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
37 changes: 36 additions & 1 deletion drivers/iio/potentiometer/ds1803.c
Original file line number Diff line number Diff line change
@@ -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>
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -200,6 +232,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);
Expand All @@ -208,6 +241,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);
Expand All @@ -224,5 +258,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");

0 comments on commit 73c1698

Please sign in to comment.