iio: potentiometer: add a driver for Maxim 5432-5435
Subsystems (2)
PATCH 1/1 iio: potentiometer: add a driver for Maxim 5432-5435
Add a driver for the Maxim Integrated MAX5432-MAX5435 family of digital potentiometers.
These potentiometers are connected via I2C and have 32 wiper positions.
Supported functionality
- set the volatile wiper position
- read the potentiometer scale
Datasheet:
https://datasheets.maximintegrated.com/en/ds/MAX5432-MAX5435.pdf
--- .../bindings/iio/potentiometer/max5432.txt | 22 ++++ drivers/iio/potentiometer/Kconfig | 11 ++ drivers/iio/potentiometer/Makefile | 1 + drivers/iio/potentiometer/max5432.c | 131 +++++++++++++++++++++ 4 files changed, 165 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/potentiometer/max5432.txt create mode 100644 drivers/iio/potentiometer/max5432.c
Documentation/devicetree/bindings/iio/potentiometer/max5432.txt new file +22 -0
@@ -0,0 +1,22 @@ +* Maxim Integrated MAX5432-MAX5435 Digital Potentiometers. + +The node for this driver must be a child node of an 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,max5432" + "maxim,max5433" + "maxim,max5434" + "maxim,max5435" + +Example: +max5434@28 { + compatible = "maxim,max5434"; + reg = <0x28>; +};
drivers/iio/potentiometer/Kconfig +11 -0
@@ -26,6 +26,17 @@ config DS1803 To compile this driver as a module, choose M here: the module will be called ds1803. +config MAX5432 + tristate "Maxim MAX5432-MAX5435 Digital Potentiometer driver" + depends on I2C + help + Say yes here to build support for the Maxim + MAX5432, MAX5433, MAX5434 and MAX5435 digital + potentiometer chips. + + To compile this driver as a module, choose M here: the + module will be called max5432. + config MAX5481 tristate "Maxim MAX5481-MAX5484 Digital Potentiometer driver" depends on SPI
drivers/iio/potentiometer/Makefile +1 -0
@@ -6,6 +6,7 @@ # When adding new entries keep the list in alphabetical order obj-$(CONFIG_AD5272) += ad5272.o obj-$(CONFIG_DS1803) += ds1803.o +obj-$(CONFIG_MAX5432) += max5432.o obj-$(CONFIG_MAX5481) += max5481.o obj-$(CONFIG_MAX5487) += max5487.o obj-$(CONFIG_MCP4018) += mcp4018.o
drivers/iio/potentiometer/max5432.c new file +131 -0
131 lines not on this page · raw message
Signature · 1 line
2.11.0
Quoted 8 lines · Martin Kaiser
Add a driver for the Maxim Integrated MAX5432-MAX5435 family of digital potentiometers.
These potentiometers are connected via I2C and have 32 wiper positions.
Supported functionality
- set the volatile wiper position
- read the potentiometer scale
please see some minor comment below
Quoted 91 lines
Datasheet:
https://datasheets.maximintegrated.com/en/ds/MAX5432-MAX5435.pdfSigned-off-by Martin Kaiser <[email protected]>--- .../bindings/iio/potentiometer/max5432.txt | 22 ++++ drivers/iio/potentiometer/Kconfig | 11 ++ drivers/iio/potentiometer/Makefile | 1 + drivers/iio/potentiometer/max5432.c | 131 +++++++++++++++++++++ 4 files changed, 165 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/potentiometer/max5432.txt create mode 100644 drivers/iio/potentiometer/max5432.cDocumentation/devicetree/bindings/iio/potentiometer/max5432.txt new file +22
-0@@ -0,0 +1,22 @@ +* Maxim Integrated MAX5432-MAX5435 Digital Potentiometers. + +The node for this driver must be a child node of an 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,max5432" + "maxim,max5433" + "maxim,max5434" + "maxim,max5435" + +Example: +max5434@28 { + compatible = "maxim,max5434"; + reg = <0x28>; +};drivers/iio/potentiometer/Kconfig +11
-0@@ -26,6 +26,17 @@ config DS1803 To compile this driver as a module, choose M here: the module will be called ds1803. +config MAX5432 + tristate "Maxim MAX5432-MAX5435 Digital Potentiometer driver" + depends on I2C + help + Say yes here to build support for the Maxim + MAX5432, MAX5433, MAX5434 and MAX5435 digital + potentiometer chips. + + To compile this driver as a module, choose M here: the + module will be called max5432. + config MAX5481 tristate "Maxim MAX5481-MAX5484 Digital Potentiometer driver" depends on SPIdrivers/iio/potentiometer/Makefile +1
-0@@ -6,6 +6,7 @@ # When adding new entries keep the list in alphabetical order obj-$(CONFIG_AD5272) += ad5272.o obj-$(CONFIG_DS1803) += ds1803.o +obj-$(CONFIG_MAX5432) += max5432.o obj-$(CONFIG_MAX5481) += max5481.o obj-$(CONFIG_MAX5487) += max5487.o obj-$(CONFIG_MCP4018) += mcp4018.odrivers/iio/potentiometer/max5432.c new file +10
-0@@ -0,0 +1,131 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Maxim Integrated MAX5432-MAX5435 digital potentiometer driver +* Copyright (C) 2019 Martin Kaiser <[email protected]> +* +* Datasheet: +* https://datasheets.maximintegrated.com/en/ds/MAX5432-MAX5435.pdf +*/ + +#include <linux/i2c.h>
drivers/iio/potentiometer/max5432.c line 20
Quoted 10 lines
drivers/iio/potentiometer/max5432.c new file +10
-0+#include <linux/iio/iio.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/of_device.h> + +/* All chip variants have 32 wiper positions. */ +#define MAX5432_MAX_POS 31 + +#define OHM_50K (50 * 1000) +#define OHM_100K (100 * 1000)
MAX5432_ prefix please
drivers/iio/potentiometer/max5432.c line 23
Quoted 3 lines
drivers/iio/potentiometer/max5432.c new file +3
-0+ +/* Update the volatile (currently active) setting. */ +#define CMD_VREG 0x11
MAX5432_ prefix please
Quoted 109 lines
drivers/iio/potentiometer/max5432.c new file +108
-0+ +struct max5432_data { +struct i2c_client *client; +u32 ohm; +}; + +static const struct iio_chan_spec max5432_channels[] = { + { + .type =IIO_RESISTANCE , + .indexed =1 , + .output =1 , + .channel =0 , + .address =CMD_VREG , + .info_mask_separate =BIT (IIO_CHAN_INFO_RAW ), + .info_mask_shared_by_type =BIT (IIO_CHAN_INFO_SCALE ), + } +}; + +static int max5432_read_raw (struct iio_dev *indio_dev, +struct iio_chan_spec const *chan, +int *val,int *val2,long mask) +{ +struct max5432_data *data =iio_priv (indio_dev); + +if (mask !=IIO_CHAN_INFO_SCALE ) +return -EINVAL ; + + *val = data->ohm; + *val2 =MAX5432_MAX_POS ; + +return IIO_VAL_FRACTIONAL ; +} + +static int max5432_write_raw (struct iio_dev *indio_dev, +struct iio_chan_spec const *chan, +int val,int val2,long mask) +{ +struct max5432_data *data =iio_priv (indio_dev); +u8 data_byte; + +if (mask !=IIO_CHAN_INFO_RAW ) +return -EINVAL ; + +if (val <0 || val >MAX5432_MAX_POS ) +return -EINVAL ; + +if (val2 !=0 ) +return -EINVAL ; + +/* Wiper position is in bits D7-D3. (D2-D0 are don't care bits.) */ + data_byte = val <<3 ; +return i2c_smbus_write_byte_data ( + data->client, chan->address, data_byte); +} + +static const struct iio_info max5432_info = { + .read_raw = max5432_read_raw, + .write_raw = max5432_write_raw, +}; + +static int max5432_probe ( +struct i2c_client *client,const struct i2c_device_id *id) +{ +struct device *dev = &client->dev; +struct iio_dev *indio_dev; +struct max5432_data *data; + + indio_dev =devm_iio_device_alloc (dev,sizeof (struct max5432_data )); +if (!indio_dev) +return -ENOMEM ; + +i2c_set_clientdata (client, indio_dev); + + data =iio_priv (indio_dev); + data->client = client; + data->ohm = (u32 )of_device_get_match_data (dev); + + indio_dev->dev.parent = dev; + indio_dev->info = &max5432_info; + indio_dev->channels = max5432_channels; + indio_dev->num_channels =ARRAY_SIZE (max5432_channels); + indio_dev->name = client->name; + +return devm_iio_device_register (dev, indio_dev); +} + +static const struct of_device_id max5432_dt_ids[] = { + { .compatible ="maxim,max5432" , .data = (void *)OHM_50K }, + { .compatible ="maxim,max5433" , .data = (void *)OHM_100K }, + { .compatible ="maxim,max5434" , .data = (void *)OHM_50K }, + { .compatible ="maxim,max5435" , .data = (void *)OHM_100K }, + {/* sentinel */ } +}; +MODULE_DEVICE_TABLE (of, max5432_dt_ids); + +static struct i2c_driver max5432_driver = { + .driver = { + .name ="max5432" , + .of_match_table =of_match_ptr (max5432_dt_ids), + }, + .probe = max5432_probe, +}; + +module_i2c_driver (max5432_driver); + +MODULE_AUTHOR ("Martin Kaiser <[email protected]>" ); +MODULE_DESCRIPTION ("max5432-max5435 digital potentiometers" ); +MODULE_LICENSE ("GPL v2" );
Signature · 2 lines
Peter Meerwald-Stadler Mobile: +43 664 24 44 418
kbuild test robot
build botThank you for the patch! Perhaps something to improve:
Hi Martin,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on linus/master]
[also build test WARNING on v5.3-rc1 next-20190722]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Martin-Kaiser/iio-potentiometer-add-a-driver-for-Maxim-5432-5435/20190723-024214
config: arm64-allmodconfig (attached as .config)
compiler: aarch64-linux-gcc (GCC) 7.4.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=7.4.0 make.cross ARCH=arm64
If you fix the issue, kindly add following tag
All warnings (new ones prefixed by >>):
drivers/iio/potentiometer/max5432.c: In function 'max5432_probe':
>> drivers/iio/potentiometer/max5432.c:99:14: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
data->ohm = (u32)of_device_get_match_data(dev);
^vim +99 drivers/iio/potentiometer/max5432.c
83
84 static int max5432_probe(
85 struct i2c_client *client, const struct i2c_device_id *id)
86 {
87 struct device *dev = &client->dev;
88 struct iio_dev *indio_dev;
89 struct max5432_data *data;
90
91 indio_dev = devm_iio_device_alloc(dev, sizeof(struct max5432_data));
92 if (!indio_dev)
93 return -ENOMEM;
94
95 i2c_set_clientdata(client, indio_dev);
96
97 data = iio_priv(indio_dev);
98 data->client = client;
> 99 data->ohm = (u32)of_device_get_match_data(dev); 100
101 indio_dev->dev.parent = dev;
102 indio_dev->info = &max5432_info;
103 indio_dev->channels = max5432_channels;
104 indio_dev->num_channels = ARRAY_SIZE(max5432_channels);
105 indio_dev->name = client->name;
106
107 return devm_iio_device_register(dev, indio_dev);
108 }
109
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
PATCH v2 1/1 iio: potentiometer: add a driver for Maxim 5432-5435
In reply to Martin KaiserAdd a driver for the Maxim Integrated MAX5432-MAX5435 family of digital potentiometers.
These potentiometers are connected via I2C and have 32 wiper positions.
Supported functionality
- set the volatile wiper position
- read the potentiometer scale
Datasheet:
https://datasheets.maximintegrated.com/en/ds/MAX5432-MAX5435.pdf
---
changes in v2
- use MAX5432_ prefix for all defines
- fix indentation
- convert void * to unsigned long, not to u32
(warning from kbuild test robot)
.../bindings/iio/potentiometer/max5432.txt | 21 ++++ drivers/iio/potentiometer/Kconfig | 11 ++ drivers/iio/potentiometer/Makefile | 1 + drivers/iio/potentiometer/max5432.c | 135 +++++++++++++++++++++ 4 files changed, 168 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/potentiometer/max5432.txt create mode 100644 drivers/iio/potentiometer/max5432.c
Documentation/devicetree/bindings/iio/potentiometer/max5432.txt new file +21 -0
@@ -0,0 +1,21 @@ +* Maxim Integrated MAX5432-MAX5435 Digital Potentiometers. + +The node for this driver must be a child node of an 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,max5432" + "maxim,max5433" + "maxim,max5434" + "maxim,max5435" + +Example: +max5434@28 { + compatible = "maxim,max5434"; + reg = <0x28>; +};
drivers/iio/potentiometer/Kconfig +11 -0
@@ -26,6 +26,17 @@ config DS1803 To compile this driver as a module, choose M here: the module will be called ds1803. +config MAX5432 + tristate "Maxim MAX5432-MAX5435 Digital Potentiometer driver" + depends on I2C + help + Say yes here to build support for the Maxim + MAX5432, MAX5433, MAX5434 and MAX5435 digital + potentiometer chips. + + To compile this driver as a module, choose M here: the + module will be called max5432. + config MAX5481 tristate "Maxim MAX5481-MAX5484 Digital Potentiometer driver" depends on SPI
drivers/iio/potentiometer/Makefile +1 -0
@@ -6,6 +6,7 @@ # When adding new entries keep the list in alphabetical order obj-$(CONFIG_AD5272) += ad5272.o obj-$(CONFIG_DS1803) += ds1803.o +obj-$(CONFIG_MAX5432) += max5432.o obj-$(CONFIG_MAX5481) += max5481.o obj-$(CONFIG_MAX5487) += max5487.o obj-$(CONFIG_MCP4018) += mcp4018.o
drivers/iio/potentiometer/max5432.c new file +135 -0
135 lines not on this page · raw message
Signature · 1 line
2.11.0
Jonathan Cameron
maintainerQuoted 5 lines · On Tue, 23 Jul 2019 10:53:24 +0200 Martin Kaiser <[email protected]> wrote:
Add a driver for the Maxim Integrated MAX5432-MAX5435 family of digital potentiometers.
These potentiometers are connected via I2C and have 32 wiper positions.
Quoted 8 lines
Supported functionality
- set the volatile wiper position
- read the potentiometer scaleDatasheet:
https://datasheets.maximintegrated.com/en/ds/MAX5432-MAX5435.pdfSigned-off-by Martin Kaiser <[email protected]>
A few trivials and I'm afraid you posted after I'd made the decision to only accept new DT bindings for IIO in yaml format.
Thanks,
Jonathan
Documentation/devicetree/bindings/iio/potentiometer/max5432.txt
Quoted 20 lines
---
changes in v2
- useMAX5432_prefix for all defines
- fix indentation
- convert void * to unsigned long, not to u32
(warning from kbuild test robot).../bindings/iio/potentiometer/max5432.txt | 21 ++++ drivers/iio/potentiometer/Kconfig | 11 ++ drivers/iio/potentiometer/Makefile | 1 + drivers/iio/potentiometer/max5432.c | 135 +++++++++++++++++++++ 4 files changed, 168 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/potentiometer/max5432.txt create mode 100644 drivers/iio/potentiometer/max5432.cDocumentation/devicetree/bindings/iio/potentiometer/max5432.txt new file +0
-0
We have made the move to yaml for all new IIO related bindings. Please convert this one over. Also, all bindings should be in separate patches and CC the devicetree binding maintainers and list. This just makes them easier for them to pick out and review - shouldn't be a problem here given it's really simple :)
Quoted 132 lines
Documentation/devicetree/bindings/iio/potentiometer/max5432.txt new file +21
-0@@ -0,0 +1,21 @@ +* Maxim Integrated MAX5432-MAX5435 Digital Potentiometers. + +The node for this driver must be a child node of an 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,max5432" + "maxim,max5433" + "maxim,max5434" + "maxim,max5435" + +Example: +max5434@28 { + compatible = "maxim,max5434"; + reg = <0x28>; +};drivers/iio/potentiometer/Kconfig +11
-0@@ -26,6 +26,17 @@ config DS1803 To compile this driver as a module, choose M here: the module will be called ds1803. +config MAX5432 + tristate "Maxim MAX5432-MAX5435 Digital Potentiometer driver" + depends on I2C + help + Say yes here to build support for the Maxim + MAX5432, MAX5433, MAX5434 and MAX5435 digital + potentiometer chips. + + To compile this driver as a module, choose M here: the + module will be called max5432. + config MAX5481 tristate "Maxim MAX5481-MAX5484 Digital Potentiometer driver" depends on SPIdrivers/iio/potentiometer/Makefile +1
-0@@ -6,6 +6,7 @@ # When adding new entries keep the list in alphabetical order obj-$(CONFIG_AD5272) += ad5272.o obj-$(CONFIG_DS1803) += ds1803.o +obj-$(CONFIG_MAX5432) += max5432.o obj-$(CONFIG_MAX5481) += max5481.o obj-$(CONFIG_MAX5487) += max5487.o obj-$(CONFIG_MCP4018) += mcp4018.odrivers/iio/potentiometer/max5432.c new file +70
-0@@ -0,0 +1,135 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Maxim Integrated MAX5432-MAX5435 digital potentiometer driver +* Copyright (C) 2019 Martin Kaiser <[email protected]> +* +* Datasheet: +* https://datasheets.maximintegrated.com/en/ds/MAX5432-MAX5435.pdf +*/ + +#include <linux/i2c.h> +#include <linux/iio/iio.h> +#include <linux/limits.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/of_device.h> + +/* All chip variants have 32 wiper positions. */ +#define MAX5432_MAX_POS 31 + +#define MAX5432_OHM_50K (50 * 1000) +#define MAX5432_OHM_100K (100 * 1000) + +/* Update the volatile (currently active) setting. */ +#define MAX5432_CMD_VREG 0x11 + +struct max5432_data { +struct i2c_client *client; +unsigned long ohm; +}; + +static const struct iio_chan_spec max5432_channels[] = { + { + .type =IIO_RESISTANCE , + .indexed =1 , + .output =1 , + .channel =0 , + .address =MAX5432_CMD_VREG , + .info_mask_separate =BIT (IIO_CHAN_INFO_RAW ), + .info_mask_shared_by_type =BIT (IIO_CHAN_INFO_SCALE ), + } +}; + +static int max5432_read_raw (struct iio_dev *indio_dev, +struct iio_chan_spec const *chan, +int *val,int *val2,long mask) +{ +struct max5432_data *data =iio_priv (indio_dev); + +if (mask !=IIO_CHAN_INFO_SCALE ) +return -EINVAL ; + +if (unlikely (data->ohm >INT_MAX )) +return -ERANGE ; + + *val = data->ohm; + *val2 =MAX5432_MAX_POS ; + +return IIO_VAL_FRACTIONAL ; +} + +static int max5432_write_raw (struct iio_dev *indio_dev, +struct iio_chan_spec const *chan, +int val,int val2,long mask) +{ +struct max5432_data *data =iio_priv (indio_dev); +u8 data_byte; + +if (mask !=IIO_CHAN_INFO_RAW ) +return -EINVAL ; +
drivers/iio/potentiometer/max5432.c line 80
Quoted 10 lines
drivers/iio/potentiometer/max5432.c new file +10
-0+if (val <0 || val >MAX5432_MAX_POS ) +return -EINVAL ; + +if (val2 !=0 ) +return -EINVAL ; + +/* Wiper position is in bits D7-D3. (D2-D0 are don't care bits.) */ + data_byte = val <<3 ; +return i2c_smbus_write_byte_data ( + data->client, chan->address, data_byte);
As below, break after "address," rather than the bracket.
drivers/iio/potentiometer/max5432.c line 89
Quoted 9 lines
drivers/iio/potentiometer/max5432.c new file +9
-0+} + +static const struct iio_info max5432_info = { + .read_raw = max5432_read_raw, + .write_raw = max5432_write_raw, +}; + +static int max5432_probe ( +struct i2c_client *client,const struct i2c_device_id *id)
That formatting is rather non standard for kernel code.
I would break the line after "client," as it will still be well under 80 chars.
Quoted 46 lines
drivers/iio/potentiometer/max5432.c new file +46
-0+{ +struct device *dev = &client->dev; +struct iio_dev *indio_dev; +struct max5432_data *data; + + indio_dev =devm_iio_device_alloc (dev,sizeof (struct max5432_data )); +if (!indio_dev) +return -ENOMEM ; + +i2c_set_clientdata (client, indio_dev); + + data =iio_priv (indio_dev); + data->client = client; + data->ohm = (unsigned long )of_device_get_match_data (dev); + + indio_dev->dev.parent = dev; + indio_dev->info = &max5432_info; + indio_dev->channels = max5432_channels; + indio_dev->num_channels =ARRAY_SIZE (max5432_channels); + indio_dev->name = client->name; + +return devm_iio_device_register (dev, indio_dev); +} + +static const struct of_device_id max5432_dt_ids[] = { + { .compatible ="maxim,max5432" , .data = (void *)MAX5432_OHM_50K }, + { .compatible ="maxim,max5433" , .data = (void *)MAX5432_OHM_100K }, + { .compatible ="maxim,max5434" , .data = (void *)MAX5432_OHM_50K }, + { .compatible ="maxim,max5435" , .data = (void *)MAX5432_OHM_100K }, + {/* sentinel */ } +}; +MODULE_DEVICE_TABLE (of, max5432_dt_ids); + +static struct i2c_driver max5432_driver = { + .driver = { + .name ="max5432" , + .of_match_table =of_match_ptr (max5432_dt_ids), + }, + .probe = max5432_probe, +}; + +module_i2c_driver (max5432_driver); + +MODULE_AUTHOR ("Martin Kaiser <[email protected]>" ); +MODULE_DESCRIPTION ("max5432-max5435 digital potentiometers" ); +MODULE_LICENSE ("GPL v2" );
PATCH v3 1/2 iio: potentiometer: add a driver for Maxim 5432-5435
In reply to Martin KaiserAdd a driver for the Maxim Integrated MAX5432-MAX5435 family of digital potentiometers.
These potentiometers are connected via I2C and have 32 wiper positions.
Supported functionality
- set the volatile wiper position
- read the potentiometer scale
Datasheet:
https://datasheets.maximintegrated.com/en/ds/MAX5432-MAX5435.pdf
---
changes in v3
- split dt bindings and driver code into separate patches
- use yaml format for dt bindings
- fix formatting of parameter lists
changes in v2
- use MAX5432_ prefix for all defines
- fix indentation
- convert void * to unsigned long, not to u32
(warning from kbuild test robot)
drivers/iio/potentiometer/Kconfig | 11 +++ drivers/iio/potentiometer/Makefile | 1 + drivers/iio/potentiometer/max5432.c | 135 ++++++++++++++++++++++++++++++++++++ 3 files changed, 147 insertions(+) create mode 100644 drivers/iio/potentiometer/max5432.c
drivers/iio/potentiometer/Kconfig +11 -0
@@ -26,6 +26,17 @@ config DS1803 To compile this driver as a module, choose M here: the module will be called ds1803. +config MAX5432 + tristate "Maxim MAX5432-MAX5435 Digital Potentiometer driver" + depends on I2C + help + Say yes here to build support for the Maxim + MAX5432, MAX5433, MAX5434 and MAX5435 digital + potentiometer chips. + + To compile this driver as a module, choose M here: the + module will be called max5432. + config MAX5481 tristate "Maxim MAX5481-MAX5484 Digital Potentiometer driver" depends on SPI
drivers/iio/potentiometer/Makefile +1 -0
@@ -6,6 +6,7 @@ # When adding new entries keep the list in alphabetical order obj-$(CONFIG_AD5272) += ad5272.o obj-$(CONFIG_DS1803) += ds1803.o +obj-$(CONFIG_MAX5432) += max5432.o obj-$(CONFIG_MAX5481) += max5481.o obj-$(CONFIG_MAX5487) += max5487.o obj-$(CONFIG_MCP4018) += mcp4018.o
drivers/iio/potentiometer/max5432.c new file +135 -0
135 lines not on this page · raw message
Signature · 1 line
2.11.0
PATCH v3 2/2 dt-bindings: iio: potentiometer: add max5432.yaml binding
Add a binding for the Maxim Integrated MAX5432-MAX5435 family of digital potentiometers.
---
changes in v3
- split dt bindings and driver code into separate patches
- use yaml format for dt bindings
- fix formatting of parameter lists
changes in v2
- use MAX5432_ prefix for all defines
- fix indentation
- convert void * to unsigned long, not to u32
(warning from kbuild test robot)
.../bindings/iio/potentiometer/max5432.yaml | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/potentiometer/max5432.yaml
Documentation/devicetree/bindings/iio/potentiometer/max5432.yaml new file +35 -0
@@ -0,0 +1,35 @@ +# SPDX-License-Identifier: GPL-2.0 +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/potentiometer/max5432.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Maxim Integrated MAX5432-MAX5435 Digital Potentiometers + +maintainers: + - Martin Kaiser <[email protected]> + +description: | + Maxim Integrated MAX5432-MAX5435 Digital Potentiometers connected via I2C + + Datasheet: + https://datasheets.maximintegrated.com/en/ds/MAX5432-MAX5435.pdf + +properties: + compatible: + enum: + - maxim,max5432 + - maxim,max5433 + - maxim,max5434 + - maxim,max5435 + +examples: + - | + i2c0 { + #address-cells = <1>; + #size-cells = <0>; + max5434@28 { + compatible = "maxim,max5434"; + reg = <0x28>; + }; + };
Signature · 1 line
2.11.0
Re: [PATCH v3 2/2] dt-bindings: iio: potentiometer: add max5432.yaml binding
Quoted 42 lines · Martin Kaiser
Add a binding for the Maxim Integrated MAX5432-MAX5435 family of digital potentiometers.
Signed-off-by Martin Kaiser <[email protected]>---
changes in v3
- split dt bindings and driver code into separate patches
- use yaml format for dt bindings
- fix formatting of parameter listschanges in v2
- useMAX5432_prefix for all defines
- fix indentation
- convert void * to unsigned long, not to u32
(warning from kbuild test robot).../bindings/iio/potentiometer/max5432.yaml | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/potentiometer/max5432.yamlDocumentation/devicetree/bindings/iio/potentiometer/max5432.yaml new file +15
-0@@ -0,0 +1,35 @@ +# SPDX-License-Identifier: GPL-2.0 +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/potentiometer/max5432.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Maxim Integrated MAX5432-MAX5435 Digital Potentiometers + +maintainers: + - Martin Kaiser <[email protected]> + +description: | + Maxim Integrated MAX5432-MAX5435 Digital Potentiometers connected via I2C + + Datasheet:
Documentation/devicetree/bindings/iio/potentiometer/max5432.yaml line 25
Quoted 10 lines
Documentation/devicetree/bindings/iio/potentiometer/max5432.yaml new file +10
-0+ https://datasheets.maximintegrated.com/en/ds/MAX5432-MAX5435.pdf + +properties: + compatible: + enum: + - maxim,max5432 + - maxim,max5433 + - maxim,max5434 + - maxim,max5435 +
reg?
Also, add an 'additionalProperties: false' line. This means other properties can't be present (except 'status' and a few we automatically add).
Documentation/devicetree/bindings/iio/potentiometer/max5432.yaml line 28
Quoted 3 lines
Documentation/devicetree/bindings/iio/potentiometer/max5432.yaml new file +3
-0+examples: + - | + i2c0 {
i2c {
Quoted 10 lines
Documentation/devicetree/bindings/iio/potentiometer/max5432.yaml new file +7
-1+ #address-cells = <1>; + #size-cells = <0>; + max5434@28 { + compatible = "maxim,max5434"; + reg = <0x28>; + }; + }; --2.11.0
PATCH v4 1/2 iio: potentiometer: add a driver for Maxim 5432-5435
In reply to Martin KaiserAdd a driver for the Maxim Integrated MAX5432-MAX5435 family of digital potentiometers.
These potentiometers are connected via I2C and have 32 wiper positions.
Supported functionality
- set the volatile wiper position
- read the potentiometer scale
Datasheet:
https://datasheets.maximintegrated.com/en/ds/MAX5432-MAX5435.pdf
---
changes in v4
- fix the dt bindings
- replace ic20 with i2c
- document the reg property
- add additionalProperties and required
changes in v3
- split dt bindings and driver code into separate patches
- use yaml format for dt bindings
- fix formatting of parameter lists
changes in v2
- use MAX5432_ prefix for all defines
- fix indentation
- convert void * to unsigned long, not to u32
(warning from kbuild test robot)
drivers/iio/potentiometer/Kconfig | 11 +++ drivers/iio/potentiometer/Makefile | 1 + drivers/iio/potentiometer/max5432.c | 135 ++++++++++++++++++++++++++++++++++++ 3 files changed, 147 insertions(+) create mode 100644 drivers/iio/potentiometer/max5432.c
drivers/iio/potentiometer/Kconfig +11 -0
@@ -26,6 +26,17 @@ config DS1803 To compile this driver as a module, choose M here: the module will be called ds1803. +config MAX5432 + tristate "Maxim MAX5432-MAX5435 Digital Potentiometer driver" + depends on I2C + help + Say yes here to build support for the Maxim + MAX5432, MAX5433, MAX5434 and MAX5435 digital + potentiometer chips. + + To compile this driver as a module, choose M here: the + module will be called max5432. + config MAX5481 tristate "Maxim MAX5481-MAX5484 Digital Potentiometer driver" depends on SPI
drivers/iio/potentiometer/Makefile +1 -0
@@ -6,6 +6,7 @@ # When adding new entries keep the list in alphabetical order obj-$(CONFIG_AD5272) += ad5272.o obj-$(CONFIG_DS1803) += ds1803.o +obj-$(CONFIG_MAX5432) += max5432.o obj-$(CONFIG_MAX5481) += max5481.o obj-$(CONFIG_MAX5487) += max5487.o obj-$(CONFIG_MCP4018) += mcp4018.o
drivers/iio/potentiometer/max5432.c new file +135 -0
135 lines not on this page · raw message
Signature · 1 line
2.11.0
PATCH v4 2/2 dt-bindings: iio: potentiometer: add max5432.yaml binding
Add a binding for the Maxim Integrated MAX5432-MAX5435 family of digital potentiometers.
---
changes in v4
- fix the dt bindings
- replace ic20 with i2c
- document the reg property
- add additionalProperties and required
changes in v3
- split dt bindings and driver code into separate patches
- use yaml format for dt bindings
- fix formatting of parameter lists
changes in v2
- use MAX5432_ prefix for all defines
- fix indentation
- convert void * to unsigned long, not to u32
(warning from kbuild test robot)
.../bindings/iio/potentiometer/max5432.yaml | 44 ++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/potentiometer/max5432.yaml
Documentation/devicetree/bindings/iio/potentiometer/max5432.yaml new file +44 -0
@@ -0,0 +1,44 @@ +# SPDX-License-Identifier: GPL-2.0 +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/potentiometer/max5432.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Maxim Integrated MAX5432-MAX5435 Digital Potentiometers + +maintainers: + - Martin Kaiser <[email protected]> + +description: | + Maxim Integrated MAX5432-MAX5435 Digital Potentiometers connected via I2C + + Datasheet: + https://datasheets.maximintegrated.com/en/ds/MAX5432-MAX5435.pdf + +properties: + compatible: + enum: + - maxim,max5432 + - maxim,max5433 + - maxim,max5434 + - maxim,max5435 + + reg: + maxItems: 1 + +required: + - compatible + - reg + +additionalProperties: false + +examples: + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + max5434@28 { + compatible = "maxim,max5434"; + reg = <0x28>; + }; + };
Signature · 1 line
2.11.0
Re: [PATCH v4 2/2] dt-bindings: iio: potentiometer: add max5432.yaml binding
Quoted 23 lines · Martin Kaiser
Add a binding for the Maxim Integrated MAX5432-MAX5435 family of digital potentiometers.
Signed-off-by Martin Kaiser <[email protected]>---
changes in v4
- fix the dt bindings
- replace ic20 with i2c
- document the reg property
- add additionalProperties and requiredchanges in v3
- split dt bindings and driver code into separate patches
- use yaml format for dt bindings
- fix formatting of parameter listschanges in v2
- useMAX5432_prefix for all defines
- fix indentation
- convert void * to unsigned long, not to u32
(warning from kbuild test robot)
Quoted 3 lines
.../bindings/iio/potentiometer/max5432.yaml | 44 ++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/potentiometer/max5432.yaml
Jonathan Cameron
maintainerQuoted 6 lines · On Wed, 31 Jul 2019 16:07:05 +0200 Martin Kaiser <[email protected]> wrote:
Add a driver for the Maxim Integrated MAX5432-MAX5435 family of digital potentiometers.
These potentiometers are connected via I2C and have 32 wiper positions.
Quoted 8 lines
Supported functionality
- set the volatile wiper position
- read the potentiometer scaleDatasheet:
https://datasheets.maximintegrated.com/en/ds/MAX5432-MAX5435.pdfSigned-off-by Martin Kaiser <[email protected]>
Looks good.
Applied to the togreg branch of iio.git and pushed out as testing for the autobuilders to play with it.
Thanks,
Jonathan
Quoted 199 lines
---
changes in v4
- fix the dt bindings
- replace ic20 with i2c
- document the reg property
- add additionalProperties and requiredchanges in v3
- split dt bindings and driver code into separate patches
- use yaml format for dt bindings
- fix formatting of parameter listschanges in v2
- useMAX5432_prefix for all defines
- fix indentation
- convert void * to unsigned long, not to u32
(warning from kbuild test robot)drivers/iio/potentiometer/Kconfig | 11 +++ drivers/iio/potentiometer/Makefile | 1 + drivers/iio/potentiometer/max5432.c | 135 ++++++++++++++++++++++++++++++++++++ 3 files changed, 147 insertions(+) create mode 100644 drivers/iio/potentiometer/max5432.cdrivers/iio/potentiometer/Kconfig +11
-0@@ -26,6 +26,17 @@ config DS1803 To compile this driver as a module, choose M here: the module will be called ds1803. +config MAX5432 + tristate "Maxim MAX5432-MAX5435 Digital Potentiometer driver" + depends on I2C + help + Say yes here to build support for the Maxim + MAX5432, MAX5433, MAX5434 and MAX5435 digital + potentiometer chips. + + To compile this driver as a module, choose M here: the + module will be called max5432. + config MAX5481 tristate "Maxim MAX5481-MAX5484 Digital Potentiometer driver" depends on SPIdrivers/iio/potentiometer/Makefile +1
-0@@ -6,6 +6,7 @@ # When adding new entries keep the list in alphabetical order obj-$(CONFIG_AD5272) += ad5272.o obj-$(CONFIG_DS1803) += ds1803.o +obj-$(CONFIG_MAX5432) += max5432.o obj-$(CONFIG_MAX5481) += max5481.o obj-$(CONFIG_MAX5487) += max5487.o obj-$(CONFIG_MCP4018) += mcp4018.odrivers/iio/potentiometer/max5432.c new file +135
-0@@ -0,0 +1,135 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Maxim Integrated MAX5432-MAX5435 digital potentiometer driver +* Copyright (C) 2019 Martin Kaiser <[email protected]> +* +* Datasheet: +* https://datasheets.maximintegrated.com/en/ds/MAX5432-MAX5435.pdf +*/ + +#include <linux/i2c.h> +#include <linux/iio/iio.h> +#include <linux/limits.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/of_device.h> + +/* All chip variants have 32 wiper positions. */ +#define MAX5432_MAX_POS 31 + +#define MAX5432_OHM_50K (50 * 1000) +#define MAX5432_OHM_100K (100 * 1000) + +/* Update the volatile (currently active) setting. */ +#define MAX5432_CMD_VREG 0x11 + +struct max5432_data { +struct i2c_client *client; +unsigned long ohm; +}; + +static const struct iio_chan_spec max5432_channels[] = { + { + .type =IIO_RESISTANCE , + .indexed =1 , + .output =1 , + .channel =0 , + .address =MAX5432_CMD_VREG , + .info_mask_separate =BIT (IIO_CHAN_INFO_RAW ), + .info_mask_shared_by_type =BIT (IIO_CHAN_INFO_SCALE ), + } +}; + +static int max5432_read_raw (struct iio_dev *indio_dev, +struct iio_chan_spec const *chan, +int *val,int *val2,long mask) +{ +struct max5432_data *data =iio_priv (indio_dev); + +if (mask !=IIO_CHAN_INFO_SCALE ) +return -EINVAL ; + +if (unlikely (data->ohm >INT_MAX )) +return -ERANGE ; + + *val = data->ohm; + *val2 =MAX5432_MAX_POS ; + +return IIO_VAL_FRACTIONAL ; +} + +static int max5432_write_raw (struct iio_dev *indio_dev, +struct iio_chan_spec const *chan, +int val,int val2,long mask) +{ +struct max5432_data *data =iio_priv (indio_dev); +u8 data_byte; + +if (mask !=IIO_CHAN_INFO_RAW ) +return -EINVAL ; + +if (val <0 || val >MAX5432_MAX_POS ) +return -EINVAL ; + +if (val2 !=0 ) +return -EINVAL ; + +/* Wiper position is in bits D7-D3. (D2-D0 are don't care bits.) */ + data_byte = val <<3 ; +return i2c_smbus_write_byte_data (data->client, chan->address, + data_byte); +} + +static const struct iio_info max5432_info = { + .read_raw = max5432_read_raw, + .write_raw = max5432_write_raw, +}; + +static int max5432_probe (struct i2c_client *client, +const struct i2c_device_id *id) +{ +struct device *dev = &client->dev; +struct iio_dev *indio_dev; +struct max5432_data *data; + + indio_dev =devm_iio_device_alloc (dev,sizeof (struct max5432_data )); +if (!indio_dev) +return -ENOMEM ; + +i2c_set_clientdata (client, indio_dev); + + data =iio_priv (indio_dev); + data->client = client; + data->ohm = (unsigned long )of_device_get_match_data (dev); + + indio_dev->dev.parent = dev; + indio_dev->info = &max5432_info; + indio_dev->channels = max5432_channels; + indio_dev->num_channels =ARRAY_SIZE (max5432_channels); + indio_dev->name = client->name; + +return devm_iio_device_register (dev, indio_dev); +} + +static const struct of_device_id max5432_dt_ids[] = { + { .compatible ="maxim,max5432" , .data = (void *)MAX5432_OHM_50K }, + { .compatible ="maxim,max5433" , .data = (void *)MAX5432_OHM_100K }, + { .compatible ="maxim,max5434" , .data = (void *)MAX5432_OHM_50K }, + { .compatible ="maxim,max5435" , .data = (void *)MAX5432_OHM_100K }, + {/* sentinel */ } +}; +MODULE_DEVICE_TABLE (of, max5432_dt_ids); + +static struct i2c_driver max5432_driver = { + .driver = { + .name ="max5432" , + .of_match_table =of_match_ptr (max5432_dt_ids), + }, + .probe = max5432_probe, +}; + +module_i2c_driver (max5432_driver); + +MODULE_AUTHOR ("Martin Kaiser <[email protected]>" ); +MODULE_DESCRIPTION ("max5432-max5435 digital potentiometers" ); +MODULE_LICENSE ("GPL v2" );
Jonathan Cameron
maintainerRe: [PATCH v4 2/2] dt-bindings: iio: potentiometer: add max5432.yaml binding
In reply to Rob HerringQuoted 24 lines · On Wed, 31 Jul 2019 10:50:36 -0600 Rob Herring <[email protected]> wrote:
Quoted 23 lines · Martin Kaiser
Add a binding for the Maxim Integrated MAX5432-MAX5435 family of digital potentiometers.
Signed-off-by Martin Kaiser <[email protected]>---
changes in v4
- fix the dt bindings
- replace ic20 with i2c
- document the reg property
- add additionalProperties and requiredchanges in v3
- split dt bindings and driver code into separate patches
- use yaml format for dt bindings
- fix formatting of parameter listschanges in v2
- useMAX5432_prefix for all defines
- fix indentation
- convert void * to unsigned long, not to u32
(warning from kbuild test robot)
Quoted 5 lines
Quoted 3 lines
.../bindings/iio/potentiometer/max5432.yaml | 44 ++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/potentiometer/max5432.yamlReviewed-by Rob Herring <[email protected]>
Applied to the togreg branch of iio.git and pushed out as testing for the autobuilders to play with it.
Thanks,
Jonathan