Re: [PATCH v3] iio: potentiometer: add driver for Maxim Integrated DS1803
On 10/04/16 12:23, Slawomir Stepien wrote: > The following functions are supported: > - write, read potentiometer value > - potentiometer scale > > Datasheet: https://datasheets.maximintegrated.com/en/ds/DS1803.pdf > > Signed-off-by: Slawomir Stepien Applied to the togreg branch of iio.git - initially pushed out as testing for the autobuilders to play with it. Thanks, Jonathan > --- > Changes since v2: > - Use array of u8 as a result type for i2c_master_recv() call > > Changes since v1: > - Removed unnecessary include file > - Use i2c_master_recv() in place of i2c_smbus_read_word_swapped() > - On raw write make sure val2 is zero > - Use ARRAY_SIZE when possible > > .../bindings/iio/potentiometer/ds1803.txt | 21 +++ > drivers/iio/potentiometer/Kconfig | 10 ++ > drivers/iio/potentiometer/Makefile | 1 + > drivers/iio/potentiometer/ds1803.c | 173 > + > 4 files changed, 205 insertions(+) > create mode 100644 > Documentation/devicetree/bindings/iio/potentiometer/ds1803.txt > create mode 100644 drivers/iio/potentiometer/ds1803.c > > diff --git a/Documentation/devicetree/bindings/iio/potentiometer/ds1803.txt > b/Documentation/devicetree/bindings/iio/potentiometer/ds1803.txt > new file mode 100644 > index 000..df77bf5 > --- /dev/null > +++ b/Documentation/devicetree/bindings/iio/potentiometer/ds1803.txt > @@ -0,0 +1,21 @@ > +* Maxim Integrated DS1803 digital potentiometer driver > + > +The node for this driver must be a child node of a I2C controller, hence > +all mandatory properties for your controller must be specified. See > directory: > + > +Documentation/devicetree/bindings/i2c > + > +for more details. > + > +Required properties: > + - compatible: Must be one of the following, depending on the > + model: > + "maxim,ds1803-010", > + "maxim,ds1803-050", > + "maxim,ds1803-100" > + > +Example: > +ds1803: ds1803@1 { > + reg = <0x28>; > + compatible = "maxim,ds1803-010"; > +}; > diff --git a/drivers/iio/potentiometer/Kconfig > b/drivers/iio/potentiometer/Kconfig > index 7ea069b..6acb238 100644 > --- a/drivers/iio/potentiometer/Kconfig > +++ b/drivers/iio/potentiometer/Kconfig > @@ -5,6 +5,16 @@ > > menu "Digital potentiometers" > > +config DS1803 > + tristate "Maxim Integrated DS1803 Digital Potentiometer driver" > + depends on I2C > + help > + Say yes here to build support for the Maxim Integrated DS1803 > + digital potentiomenter chip. > + > + To compile this driver as a module, choose M here: the > + module will be called ds1803. > + > config MCP4131 > tristate "Microchip MCP413X/414X/415X/416X/423X/424X/425X/426X Digital > Potentiometer driver" > depends on SPI > diff --git a/drivers/iio/potentiometer/Makefile > b/drivers/iio/potentiometer/Makefile > index 91a80f8..6007faa 100644 > --- a/drivers/iio/potentiometer/Makefile > +++ b/drivers/iio/potentiometer/Makefile > @@ -3,6 +3,7 @@ > # > > # When adding new entries keep the list in alphabetical order > +obj-$(CONFIG_DS1803) += ds1803.o > obj-$(CONFIG_MCP4131) += mcp4131.o > obj-$(CONFIG_MCP4531) += mcp4531.o > obj-$(CONFIG_TPL0102) += tpl0102.o > diff --git a/drivers/iio/potentiometer/ds1803.c > b/drivers/iio/potentiometer/ds1803.c > new file mode 100644 > index 000..fb9e2a3 > --- /dev/null > +++ b/drivers/iio/potentiometer/ds1803.c > @@ -0,0 +1,173 @@ > +/* > + * Maxim Integrated DS1803 digital potentiometer driver > + * Copyright (c) 2016 Slawomir Stepien > + * > + * Datasheet: https://datasheets.maximintegrated.com/en/ds/DS1803.pdf > + * > + * DEVID #Wipers #Positions Resistor Opts (kOhm)i2c address > + * ds18032 256 10, 50, 100 0101xxx > + * > + * This program is free software; you can redistribute it and/or modify it > + * under the terms of the GNU General Public License version 2 as published > by > + * the Free Software Foundation. > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > + > +#define DS1803_MAX_POS 255 > +#define DS1803_WRITE(chan) (0xa8 | ((chan) + 1)) > + > +enum ds1803_type { > + DS1803_010, > + DS1803_050, > + DS1803_100, > +}; > + > +struct ds1803_cfg { > + int kohms; > +}; > + > +static const struct ds1803_cfg ds1803_cfg[] = { > + [DS1803_010] = { .kohms = 10, }, > + [DS1803_050] = { .kohms = 50, }, > + [DS1803_100] = { .kohms = 100, }, > +}; > + > +struct ds1803_data { > + struct i2c_client *client; > + const struct ds1803_cfg *cfg; > +}; > + > +#define DS1803_CHANNEL(ch) { \ > + .type = IIO_RESISTANCE, \ > + .indexed = 1, \ > + .output = 1,\ > + .channel = (ch
[PATCH v3] iio: potentiometer: add driver for Maxim Integrated DS1803
The following functions are supported: - write, read potentiometer value - potentiometer scale Datasheet: https://datasheets.maximintegrated.com/en/ds/DS1803.pdf Signed-off-by: Slawomir Stepien --- Changes since v2: - Use array of u8 as a result type for i2c_master_recv() call Changes since v1: - Removed unnecessary include file - Use i2c_master_recv() in place of i2c_smbus_read_word_swapped() - On raw write make sure val2 is zero - Use ARRAY_SIZE when possible .../bindings/iio/potentiometer/ds1803.txt | 21 +++ drivers/iio/potentiometer/Kconfig | 10 ++ drivers/iio/potentiometer/Makefile | 1 + drivers/iio/potentiometer/ds1803.c | 173 + 4 files changed, 205 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/potentiometer/ds1803.txt create mode 100644 drivers/iio/potentiometer/ds1803.c diff --git a/Documentation/devicetree/bindings/iio/potentiometer/ds1803.txt b/Documentation/devicetree/bindings/iio/potentiometer/ds1803.txt new file mode 100644 index 000..df77bf5 --- /dev/null +++ b/Documentation/devicetree/bindings/iio/potentiometer/ds1803.txt @@ -0,0 +1,21 @@ +* Maxim Integrated DS1803 digital potentiometer driver + +The node for this driver must be a child node of a I2C controller, hence +all mandatory properties for your controller must be specified. See directory: + +Documentation/devicetree/bindings/i2c + +for more details. + +Required properties: + - compatible: Must be one of the following, depending on the + model: + "maxim,ds1803-010", + "maxim,ds1803-050", + "maxim,ds1803-100" + +Example: +ds1803: ds1803@1 { + reg = <0x28>; + compatible = "maxim,ds1803-010"; +}; diff --git a/drivers/iio/potentiometer/Kconfig b/drivers/iio/potentiometer/Kconfig index 7ea069b..6acb238 100644 --- a/drivers/iio/potentiometer/Kconfig +++ b/drivers/iio/potentiometer/Kconfig @@ -5,6 +5,16 @@ menu "Digital potentiometers" +config DS1803 + tristate "Maxim Integrated DS1803 Digital Potentiometer driver" + depends on I2C + help + Say yes here to build support for the Maxim Integrated DS1803 + digital potentiomenter chip. + + To compile this driver as a module, choose M here: the + module will be called ds1803. + config MCP4131 tristate "Microchip MCP413X/414X/415X/416X/423X/424X/425X/426X Digital Potentiometer driver" depends on SPI diff --git a/drivers/iio/potentiometer/Makefile b/drivers/iio/potentiometer/Makefile index 91a80f8..6007faa 100644 --- a/drivers/iio/potentiometer/Makefile +++ b/drivers/iio/potentiometer/Makefile @@ -3,6 +3,7 @@ # # When adding new entries keep the list in alphabetical order +obj-$(CONFIG_DS1803) += ds1803.o obj-$(CONFIG_MCP4131) += mcp4131.o obj-$(CONFIG_MCP4531) += mcp4531.o obj-$(CONFIG_TPL0102) += tpl0102.o diff --git a/drivers/iio/potentiometer/ds1803.c b/drivers/iio/potentiometer/ds1803.c new file mode 100644 index 000..fb9e2a3 --- /dev/null +++ b/drivers/iio/potentiometer/ds1803.c @@ -0,0 +1,173 @@ +/* + * Maxim Integrated DS1803 digital potentiometer driver + * Copyright (c) 2016 Slawomir Stepien + * + * Datasheet: https://datasheets.maximintegrated.com/en/ds/DS1803.pdf + * + * DEVID #Wipers #Positions Resistor Opts (kOhm)i2c address + * ds1803 2 256 10, 50, 100 0101xxx + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published by + * the Free Software Foundation. + */ + +#include +#include +#include +#include +#include +#include + +#define DS1803_MAX_POS 255 +#define DS1803_WRITE(chan) (0xa8 | ((chan) + 1)) + +enum ds1803_type { + DS1803_010, + DS1803_050, + DS1803_100, +}; + +struct ds1803_cfg { + int kohms; +}; + +static const struct ds1803_cfg ds1803_cfg[] = { + [DS1803_010] = { .kohms = 10, }, + [DS1803_050] = { .kohms = 50, }, + [DS1803_100] = { .kohms = 100, }, +}; + +struct ds1803_data { + struct i2c_client *client; + const struct ds1803_cfg *cfg; +}; + +#define DS1803_CHANNEL(ch) { \ + .type = IIO_RESISTANCE, \ + .indexed = 1, \ + .output = 1,\ + .channel = (ch),\ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ +} + +static const struct iio_chan_spec ds1803_channels[] = { + DS1803_CHANNEL(0), + DS1803_CHANNEL(1), +}; + +static int ds1803_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, +