* [PATCH v4 0/2] iio: ad5272: Add support for Analog Devices digital potentiometers @ 2018-01-29 13:12 Phil Reid [not found] ` <1517231574-92777-1-git-send-email-preid-qgqNFa1JUf/o2iN0hyhwsIdd74u8MsAO@public.gmane.org> 0 siblings, 1 reply; 9+ messages in thread From: Phil Reid @ 2018-01-29 13:12 UTC (permalink / raw) To: jic23-DgEjT+Ai2ygdnm+yROfE0A, knaack.h-Mmb7MZpHnFY, lars-Qo5EllUWu/uELgA04lAiVw, pmeerw-jW+XmwGofnusTnJN9+BGXg, robh+dt-DgEjT+Ai2ygdnm+yROfE0A, mark.rutland-5wv7dgnIgG8, Michael.Hennerich-OyLXuOCK7orQT0dZR+AlfA, preid-qgqNFa1JUf/o2iN0hyhwsIdd74u8MsAO, linux-iio-u79uwXL29TY76Z2rM5mHXA, devicetree-u79uwXL29TY76Z2rM5mHXA Add documentation and driver for the Analog Devices 5272. Driver currently doesn't support programing the RDAC position to non-volatile memory. Changes from v3: - move SPDX-License-Identifier to line 1 - add AD5274 to Kconfig description - Add missing empty line before return Changes from v2: - docs: Fix polarity of reset-gpio example to match driver - Use a cached aligned buffer for i2c - remove old invalid comment from c&p Changes from v1: - Use spdx license id - Use sizeof for i2c buffer lens - Condense code a little when setting up i2c buf - check val2 in raw write - Add reset function. Perform a software reset if gpio reset pin is not defined - remove THIS_MODULE assignment - change of data to use index as per i2c device table Phil Reid (2): dt-bindings: ad5272: Add bindings for Analog Devices digital potentiometers iio: ad5272: Add support for Analog Devices digital potentiometers .../bindings/iio/potentiometer/ad5272.txt | 27 +++ drivers/iio/potentiometer/Kconfig | 10 + drivers/iio/potentiometer/Makefile | 1 + drivers/iio/potentiometer/ad5272.c | 227 +++++++++++++++++++++ 4 files changed, 265 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/potentiometer/ad5272.txt create mode 100644 drivers/iio/potentiometer/ad5272.c -- 1.8.3.1 ^ permalink raw reply [flat|nested] 9+ messages in thread
[parent not found: <1517231574-92777-1-git-send-email-preid-qgqNFa1JUf/o2iN0hyhwsIdd74u8MsAO@public.gmane.org>]
* [PATCH v4 1/2] dt-bindings: ad5272: Add bindings for Analog Devices digital potentiometers [not found] ` <1517231574-92777-1-git-send-email-preid-qgqNFa1JUf/o2iN0hyhwsIdd74u8MsAO@public.gmane.org> @ 2018-01-29 13:12 ` Phil Reid [not found] ` <1517231574-92777-2-git-send-email-preid-qgqNFa1JUf/o2iN0hyhwsIdd74u8MsAO@public.gmane.org> 2018-01-29 13:12 ` [PATCH v4 2/2] iio: ad5272: Add support " Phil Reid 1 sibling, 1 reply; 9+ messages in thread From: Phil Reid @ 2018-01-29 13:12 UTC (permalink / raw) To: jic23-DgEjT+Ai2ygdnm+yROfE0A, knaack.h-Mmb7MZpHnFY, lars-Qo5EllUWu/uELgA04lAiVw, pmeerw-jW+XmwGofnusTnJN9+BGXg, robh+dt-DgEjT+Ai2ygdnm+yROfE0A, mark.rutland-5wv7dgnIgG8, Michael.Hennerich-OyLXuOCK7orQT0dZR+AlfA, preid-qgqNFa1JUf/o2iN0hyhwsIdd74u8MsAO, linux-iio-u79uwXL29TY76Z2rM5mHXA, devicetree-u79uwXL29TY76Z2rM5mHXA Add binding documentation for Analog Devices AD5272 and AD5274 digital potentiometer devices. Signed-off-by: Phil Reid <preid-qgqNFa1JUf/o2iN0hyhwsIdd74u8MsAO@public.gmane.org> --- .../bindings/iio/potentiometer/ad5272.txt | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/potentiometer/ad5272.txt diff --git a/Documentation/devicetree/bindings/iio/potentiometer/ad5272.txt b/Documentation/devicetree/bindings/iio/potentiometer/ad5272.txt new file mode 100644 index 0000000..11e804c --- /dev/null +++ b/Documentation/devicetree/bindings/iio/potentiometer/ad5272.txt @@ -0,0 +1,27 @@ +* Analog Devices AD5272 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: + adi,ad5272-020 + adi,ad5272-050 + adi,ad5272-100 + adi,ad5274-020 + adi,ad5274-100 + +Optional properties: + - reset-gpios: GPIO specification for the RESET input. This is an + active low signal to the PCA953x. + +Example: +ad5272: ad5272@2f { + reg = <0x2F>; + compatible = "adi,ad5272-020"; + reset-gpios = <&gpio3 6 GPIO_ACTIVE_HIGH>; +}; -- 1.8.3.1 ^ permalink raw reply related [flat|nested] 9+ messages in thread
[parent not found: <1517231574-92777-2-git-send-email-preid-qgqNFa1JUf/o2iN0hyhwsIdd74u8MsAO@public.gmane.org>]
* Re: [PATCH v4 1/2] dt-bindings: ad5272: Add bindings for Analog Devices digital potentiometers [not found] ` <1517231574-92777-2-git-send-email-preid-qgqNFa1JUf/o2iN0hyhwsIdd74u8MsAO@public.gmane.org> @ 2018-02-04 10:34 ` Jonathan Cameron 2018-02-05 6:07 ` Rob Herring 2018-02-05 8:34 ` Brandon Martin 2 siblings, 0 replies; 9+ messages in thread From: Jonathan Cameron @ 2018-02-04 10:34 UTC (permalink / raw) To: Phil Reid Cc: knaack.h-Mmb7MZpHnFY, lars-Qo5EllUWu/uELgA04lAiVw, pmeerw-jW+XmwGofnusTnJN9+BGXg, robh+dt-DgEjT+Ai2ygdnm+yROfE0A, mark.rutland-5wv7dgnIgG8, Michael.Hennerich-OyLXuOCK7orQT0dZR+AlfA, linux-iio-u79uwXL29TY76Z2rM5mHXA, devicetree-u79uwXL29TY76Z2rM5mHXA On Mon, 29 Jan 2018 21:12:53 +0800 Phil Reid <preid-qgqNFa1JUf/o2iN0hyhwsIdd74u8MsAO@public.gmane.org> wrote: > Add binding documentation for Analog Devices AD5272 and AD5274 digital > potentiometer devices. > > Signed-off-by: Phil Reid <preid-qgqNFa1JUf/o2iN0hyhwsIdd74u8MsAO@public.gmane.org> This is simply enough that I doubt Rob or Mark is that bothered about reviewing it. Obviously any reviews are still welcome though as it will be in a rebaseable tree probably until after the merge window closes. Applied to the togreg branch of iio.git and pushed out as testing. Thanks, Jonathan > --- > .../bindings/iio/potentiometer/ad5272.txt | 27 ++++++++++++++++++++++ > 1 file changed, 27 insertions(+) > create mode 100644 Documentation/devicetree/bindings/iio/potentiometer/ad5272.txt > > diff --git a/Documentation/devicetree/bindings/iio/potentiometer/ad5272.txt b/Documentation/devicetree/bindings/iio/potentiometer/ad5272.txt > new file mode 100644 > index 0000000..11e804c > --- /dev/null > +++ b/Documentation/devicetree/bindings/iio/potentiometer/ad5272.txt > @@ -0,0 +1,27 @@ > +* Analog Devices AD5272 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: > + adi,ad5272-020 > + adi,ad5272-050 > + adi,ad5272-100 > + adi,ad5274-020 > + adi,ad5274-100 > + > +Optional properties: > + - reset-gpios: GPIO specification for the RESET input. This is an > + active low signal to the PCA953x. > + > +Example: > +ad5272: ad5272@2f { > + reg = <0x2F>; > + compatible = "adi,ad5272-020"; > + reset-gpios = <&gpio3 6 GPIO_ACTIVE_HIGH>; > +}; ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v4 1/2] dt-bindings: ad5272: Add bindings for Analog Devices digital potentiometers [not found] ` <1517231574-92777-2-git-send-email-preid-qgqNFa1JUf/o2iN0hyhwsIdd74u8MsAO@public.gmane.org> 2018-02-04 10:34 ` Jonathan Cameron @ 2018-02-05 6:07 ` Rob Herring 2018-02-05 7:25 ` Phil Reid 2018-02-05 8:34 ` Brandon Martin 2 siblings, 1 reply; 9+ messages in thread From: Rob Herring @ 2018-02-05 6:07 UTC (permalink / raw) To: Phil Reid Cc: jic23-DgEjT+Ai2ygdnm+yROfE0A, knaack.h-Mmb7MZpHnFY, lars-Qo5EllUWu/uELgA04lAiVw, pmeerw-jW+XmwGofnusTnJN9+BGXg, mark.rutland-5wv7dgnIgG8, Michael.Hennerich-OyLXuOCK7orQT0dZR+AlfA, linux-iio-u79uwXL29TY76Z2rM5mHXA, devicetree-u79uwXL29TY76Z2rM5mHXA On Mon, Jan 29, 2018 at 09:12:53PM +0800, Phil Reid wrote: > Add binding documentation for Analog Devices AD5272 and AD5274 digital > potentiometer devices. > > Signed-off-by: Phil Reid <preid-qgqNFa1JUf/o2iN0hyhwsIdd74u8MsAO@public.gmane.org> > --- > .../bindings/iio/potentiometer/ad5272.txt | 27 ++++++++++++++++++++++ > 1 file changed, 27 insertions(+) > create mode 100644 Documentation/devicetree/bindings/iio/potentiometer/ad5272.txt > > diff --git a/Documentation/devicetree/bindings/iio/potentiometer/ad5272.txt b/Documentation/devicetree/bindings/iio/potentiometer/ad5272.txt > new file mode 100644 > index 0000000..11e804c > --- /dev/null > +++ b/Documentation/devicetree/bindings/iio/potentiometer/ad5272.txt > @@ -0,0 +1,27 @@ > +* Analog Devices AD5272 digital potentiometer driver Bindings describe h/w not drivers. > + > +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: > + adi,ad5272-020 > + adi,ad5272-050 > + adi,ad5272-100 > + adi,ad5274-020 > + adi,ad5274-100 > + > +Optional properties: > + - reset-gpios: GPIO specification for the RESET input. This is an > + active low signal to the PCA953x. > + > +Example: > +ad5272: ad5272@2f { potentiometer@2f Probably a node name we need to add to the spec. > + reg = <0x2F>; > + compatible = "adi,ad5272-020"; > + reset-gpios = <&gpio3 6 GPIO_ACTIVE_HIGH>; > +}; > -- > 1.8.3.1 > ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v4 1/2] dt-bindings: ad5272: Add bindings for Analog Devices digital potentiometers 2018-02-05 6:07 ` Rob Herring @ 2018-02-05 7:25 ` Phil Reid [not found] ` <f1d2bf62-c4b7-9cd4-4962-3c07c22bdb5e-qgqNFa1JUf/o2iN0hyhwsIdd74u8MsAO@public.gmane.org> 0 siblings, 1 reply; 9+ messages in thread From: Phil Reid @ 2018-02-05 7:25 UTC (permalink / raw) To: Rob Herring Cc: jic23-DgEjT+Ai2ygdnm+yROfE0A, knaack.h-Mmb7MZpHnFY, lars-Qo5EllUWu/uELgA04lAiVw, pmeerw-jW+XmwGofnusTnJN9+BGXg, mark.rutland-5wv7dgnIgG8, Michael.Hennerich-OyLXuOCK7orQT0dZR+AlfA, linux-iio-u79uwXL29TY76Z2rM5mHXA, devicetree-u79uwXL29TY76Z2rM5mHXA On 5/02/2018 14:07, Rob Herring wrote: > On Mon, Jan 29, 2018 at 09:12:53PM +0800, Phil Reid wrote: >> Add binding documentation for Analog Devices AD5272 and AD5274 digital >> potentiometer devices. >> >> Signed-off-by: Phil Reid <preid-qgqNFa1JUf/o2iN0hyhwsIdd74u8MsAO@public.gmane.org> >> --- >> .../bindings/iio/potentiometer/ad5272.txt | 27 ++++++++++++++++++++++ >> 1 file changed, 27 insertions(+) >> create mode 100644 Documentation/devicetree/bindings/iio/potentiometer/ad5272.txt >> >> diff --git a/Documentation/devicetree/bindings/iio/potentiometer/ad5272.txt b/Documentation/devicetree/bindings/iio/potentiometer/ad5272.txt >> new file mode 100644 >> index 0000000..11e804c >> --- /dev/null >> +++ b/Documentation/devicetree/bindings/iio/potentiometer/ad5272.txt >> @@ -0,0 +1,27 @@ >> +* Analog Devices AD5272 digital potentiometer driver > > Bindings describe h/w not drivers. ok > >> + >> +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: >> + adi,ad5272-020 >> + adi,ad5272-050 >> + adi,ad5272-100 >> + adi,ad5274-020 >> + adi,ad5274-100 >> + >> +Optional properties: >> + - reset-gpios: GPIO specification for the RESET input. This is an >> + active low signal to the PCA953x. >> + >> +Example: >> +ad5272: ad5272@2f { > > potentiometer@2f ok > > Probably a node name we need to add to the spec. > >> + reg = <0x2F>; >> + compatible = "adi,ad5272-020"; >> + reset-gpios = <&gpio3 6 GPIO_ACTIVE_HIGH>; >> +}; >> -- >> 1.8.3.1 >> > > Jonathan, How would you like me to fix this as you've applied it to togreg already? A patch on top of this or a v5. -- Regards Phil Reid -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 9+ messages in thread
[parent not found: <f1d2bf62-c4b7-9cd4-4962-3c07c22bdb5e-qgqNFa1JUf/o2iN0hyhwsIdd74u8MsAO@public.gmane.org>]
* Re: [PATCH v4 1/2] dt-bindings: ad5272: Add bindings for Analog Devices digital potentiometers [not found] ` <f1d2bf62-c4b7-9cd4-4962-3c07c22bdb5e-qgqNFa1JUf/o2iN0hyhwsIdd74u8MsAO@public.gmane.org> @ 2018-02-07 10:50 ` Jonathan Cameron 0 siblings, 0 replies; 9+ messages in thread From: Jonathan Cameron @ 2018-02-07 10:50 UTC (permalink / raw) To: Phil Reid Cc: Rob Herring, jic23-DgEjT+Ai2ygdnm+yROfE0A, knaack.h-Mmb7MZpHnFY, lars-Qo5EllUWu/uELgA04lAiVw, pmeerw-jW+XmwGofnusTnJN9+BGXg, mark.rutland-5wv7dgnIgG8, Michael.Hennerich-OyLXuOCK7orQT0dZR+AlfA, linux-iio-u79uwXL29TY76Z2rM5mHXA, devicetree-u79uwXL29TY76Z2rM5mHXA On Mon, 5 Feb 2018 15:25:59 +0800 Phil Reid <preid-qgqNFa1JUf/o2iN0hyhwsIdd74u8MsAO@public.gmane.org> wrote: > On 5/02/2018 14:07, Rob Herring wrote: > > On Mon, Jan 29, 2018 at 09:12:53PM +0800, Phil Reid wrote: > >> Add binding documentation for Analog Devices AD5272 and AD5274 digital > >> potentiometer devices. > >> > >> Signed-off-by: Phil Reid <preid-qgqNFa1JUf/o2iN0hyhwsIdd74u8MsAO@public.gmane.org> > >> --- > >> .../bindings/iio/potentiometer/ad5272.txt | 27 ++++++++++++++++++++++ > >> 1 file changed, 27 insertions(+) > >> create mode 100644 Documentation/devicetree/bindings/iio/potentiometer/ad5272.txt > >> > >> diff --git a/Documentation/devicetree/bindings/iio/potentiometer/ad5272.txt b/Documentation/devicetree/bindings/iio/potentiometer/ad5272.txt > >> new file mode 100644 > >> index 0000000..11e804c > >> --- /dev/null > >> +++ b/Documentation/devicetree/bindings/iio/potentiometer/ad5272.txt > >> @@ -0,0 +1,27 @@ > >> +* Analog Devices AD5272 digital potentiometer driver > > > > Bindings describe h/w not drivers. > ok > > > > >> + > >> +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: > >> + adi,ad5272-020 > >> + adi,ad5272-050 > >> + adi,ad5272-100 > >> + adi,ad5274-020 > >> + adi,ad5274-100 > >> + > >> +Optional properties: > >> + - reset-gpios: GPIO specification for the RESET input. This is an > >> + active low signal to the PCA953x. > >> + > >> +Example: > >> +ad5272: ad5272@2f { > > > > potentiometer@2f > ok > > > > > Probably a node name we need to add to the spec. > > > >> + reg = <0x2F>; > >> + compatible = "adi,ad5272-020"; > >> + reset-gpios = <&gpio3 6 GPIO_ACTIVE_HIGH>; > >> +}; > >> -- > >> 1.8.3.1 > >> > > > > > Jonathan, > > How would you like me to fix this as you've applied it to togreg already? > A patch on top of this or a v5. > Do a v5, I'll drop v4 and pick it up if Rob is happy. Jonathan > ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v4 1/2] dt-bindings: ad5272: Add bindings for Analog Devices digital potentiometers [not found] ` <1517231574-92777-2-git-send-email-preid-qgqNFa1JUf/o2iN0hyhwsIdd74u8MsAO@public.gmane.org> 2018-02-04 10:34 ` Jonathan Cameron 2018-02-05 6:07 ` Rob Herring @ 2018-02-05 8:34 ` Brandon Martin 2 siblings, 0 replies; 9+ messages in thread From: Brandon Martin @ 2018-02-05 8:34 UTC (permalink / raw) To: Phil Reid; +Cc: devicetree-u79uwXL29TY76Z2rM5mHXA On 01/29/2018 08:12 AM, Phil Reid wrote: > +Optional properties: > + - reset-gpios: GPIO specification for the RESET input. This is an > + active low signal to the PCA953x. Copy/paste error? Should maybe be "This is an active low signal to the AD527x."? -- Brandon Martin Mothic Technologies 317-565-1357 x7000 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v4 2/2] iio: ad5272: Add support for Analog Devices digital potentiometers [not found] ` <1517231574-92777-1-git-send-email-preid-qgqNFa1JUf/o2iN0hyhwsIdd74u8MsAO@public.gmane.org> 2018-01-29 13:12 ` [PATCH v4 1/2] dt-bindings: ad5272: Add bindings " Phil Reid @ 2018-01-29 13:12 ` Phil Reid [not found] ` <1517231574-92777-3-git-send-email-preid-qgqNFa1JUf/o2iN0hyhwsIdd74u8MsAO@public.gmane.org> 1 sibling, 1 reply; 9+ messages in thread From: Phil Reid @ 2018-01-29 13:12 UTC (permalink / raw) To: jic23-DgEjT+Ai2ygdnm+yROfE0A, knaack.h-Mmb7MZpHnFY, lars-Qo5EllUWu/uELgA04lAiVw, pmeerw-jW+XmwGofnusTnJN9+BGXg, robh+dt-DgEjT+Ai2ygdnm+yROfE0A, mark.rutland-5wv7dgnIgG8, Michael.Hennerich-OyLXuOCK7orQT0dZR+AlfA, preid-qgqNFa1JUf/o2iN0hyhwsIdd74u8MsAO, linux-iio-u79uwXL29TY76Z2rM5mHXA, devicetree-u79uwXL29TY76Z2rM5mHXA Add implementation for Analog Devices AD5272 and AD5274 digital potentiometer devices. Signed-off-by: Phil Reid <preid-qgqNFa1JUf/o2iN0hyhwsIdd74u8MsAO@public.gmane.org> --- drivers/iio/potentiometer/Kconfig | 10 ++ drivers/iio/potentiometer/Makefile | 1 + drivers/iio/potentiometer/ad5272.c | 231 +++++++++++++++++++++++++++++++++++++ 3 files changed, 242 insertions(+) create mode 100644 drivers/iio/potentiometer/ad5272.c diff --git a/drivers/iio/potentiometer/Kconfig b/drivers/iio/potentiometer/Kconfig index 8bf2825..8daf6d1 100644 --- a/drivers/iio/potentiometer/Kconfig +++ b/drivers/iio/potentiometer/Kconfig @@ -5,6 +5,16 @@ menu "Digital potentiometers" +config AD5272 + tristate "Analog Devices AD5272 and similar Digital Potentiometer driver" + depends on I2C + help + Say yes here to build support for the Analog Devices AD5272 and AD5274 + digital potentiometer chip. + + To compile this driver as a module, choose M here: the + module will be called ad5272. + config DS1803 tristate "Maxim Integrated DS1803 Digital Potentiometer driver" depends on I2C diff --git a/drivers/iio/potentiometer/Makefile b/drivers/iio/potentiometer/Makefile index 2260d40..498bbb8 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_AD5272) += ad5272.o obj-$(CONFIG_DS1803) += ds1803.o obj-$(CONFIG_MAX5481) += max5481.o obj-$(CONFIG_MAX5487) += max5487.o diff --git a/drivers/iio/potentiometer/ad5272.c b/drivers/iio/potentiometer/ad5272.c new file mode 100644 index 0000000..0175fd5 --- /dev/null +++ b/drivers/iio/potentiometer/ad5272.c @@ -0,0 +1,231 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Analog Devices AD5372 digital potentiometer driver + * Copyright (C) 2018 Phil Reid <preid-qgqNFa1JUf/o2iN0hyhwsIdd74u8MsAO@public.gmane.org> + * + * Datasheet: http://www.analog.com/media/en/technical-documentation/data-sheets/AD5272_5274.pdf + * + * DEVID #Wipers #Positions Resistor Opts (kOhm) i2c address + * ad5272 1 1024 20, 50, 100 01011xx + * ad5274 1 256 20, 100 01011xx + */ + +#include <linux/delay.h> +#include <linux/gpio/consumer.h> +#include <linux/i2c.h> +#include <linux/iio/iio.h> +#include <linux/module.h> + +#define AD5272_RDAC_WR 1 +#define AD5272_RDAC_RD 2 +#define AD5272_RESET 4 +#define AD5272_CTL 7 + +#define AD5272_RDAC_WR_EN BIT(1) + +struct ad5272_cfg { + int max_pos; + int kohms; + int shift; +}; + +enum ad5272_type { + AD5272_020, + AD5272_050, + AD5272_100, + AD5274_020, + AD5274_100, +}; + +static const struct ad5272_cfg ad5272_cfg[] = { + [AD5272_020] = { .max_pos = 1024, .kohms = 20 }, + [AD5272_050] = { .max_pos = 1024, .kohms = 50 }, + [AD5272_100] = { .max_pos = 1024, .kohms = 100 }, + [AD5274_020] = { .max_pos = 256, .kohms = 20, .shift = 2 }, + [AD5274_100] = { .max_pos = 256, .kohms = 100, .shift = 2 }, +}; + +struct ad5272_data { + struct i2c_client *client; + struct mutex lock; + const struct ad5272_cfg *cfg; + u8 buf[2] ____cacheline_aligned; +}; + +static const struct iio_chan_spec ad5272_channel = { + .type = IIO_RESISTANCE, + .output = 1, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), +}; + +static int ad5272_write(struct ad5272_data *data, int reg, int val) +{ + int ret; + + data->buf[0] = (reg << 2) | ((val >> 8) & 0x3); + data->buf[1] = (u8)val; + + mutex_lock(&data->lock); + ret = i2c_master_send(data->client, data->buf, sizeof(data->buf)); + mutex_unlock(&data->lock); + return ret < 0 ? ret : 0; +} + +static int ad5272_read(struct ad5272_data *data, int reg, int *val) +{ + int ret; + + data->buf[0] = reg << 2; + data->buf[1] = 0; + + mutex_lock(&data->lock); + ret = i2c_master_send(data->client, data->buf, sizeof(data->buf)); + if (ret < 0) + goto error; + + ret = i2c_master_recv(data->client, data->buf, sizeof(data->buf)); + if (ret < 0) + goto error; + + *val = ((data->buf[0] & 0x3) << 8) | data->buf[1]; + ret = 0; +error: + mutex_unlock(&data->lock); + return ret; +} + +static int ad5272_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int *val, int *val2, long mask) +{ + struct ad5272_data *data = iio_priv(indio_dev); + int ret; + + switch (mask) { + case IIO_CHAN_INFO_RAW: { + ret = ad5272_read(data, AD5272_RDAC_RD, val); + *val = *val >> data->cfg->shift; + return ret ? ret : IIO_VAL_INT; + } + case IIO_CHAN_INFO_SCALE: + *val = 1000 * data->cfg->kohms; + *val2 = data->cfg->max_pos; + return IIO_VAL_FRACTIONAL; + } + + return -EINVAL; +} + +static int ad5272_write_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int val, int val2, long mask) +{ + struct ad5272_data *data = iio_priv(indio_dev); + + if (mask != IIO_CHAN_INFO_RAW) + return -EINVAL; + + if (val >= data->cfg->max_pos || val < 0 || val2) + return -EINVAL; + + return ad5272_write(data, AD5272_RDAC_WR, val << data->cfg->shift); +} + +static const struct iio_info ad5272_info = { + .read_raw = ad5272_read_raw, + .write_raw = ad5272_write_raw, +}; + +static int ad5272_reset(struct ad5272_data *data) +{ + struct gpio_desc *reset_gpio; + + reset_gpio = devm_gpiod_get_optional(&data->client->dev, "reset", + GPIOD_OUT_LOW); + if (IS_ERR(reset_gpio)) + return PTR_ERR(reset_gpio); + + if (reset_gpio) { + udelay(1); + gpiod_set_value(reset_gpio, 1); + } else { + ad5272_write(data, AD5272_RESET, 0); + } + usleep_range(1000, 2000); + + return 0; +} + +static int ad5272_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct device *dev = &client->dev; + struct iio_dev *indio_dev; + struct ad5272_data *data; + int ret; + + indio_dev = devm_iio_device_alloc(dev, sizeof(*data)); + if (!indio_dev) + return -ENOMEM; + + i2c_set_clientdata(client, indio_dev); + + data = iio_priv(indio_dev); + data->client = client; + mutex_init(&data->lock); + data->cfg = &ad5272_cfg[id->driver_data]; + + ret = ad5272_reset(data); + if (ret) + return ret; + + ret = ad5272_write(data, AD5272_CTL, AD5272_RDAC_WR_EN); + if (ret < 0) + return -ENODEV; + + indio_dev->dev.parent = dev; + indio_dev->info = &ad5272_info; + indio_dev->channels = &ad5272_channel; + indio_dev->num_channels = 1; + indio_dev->name = client->name; + + return devm_iio_device_register(dev, indio_dev); +} + +#if defined(CONFIG_OF) +static const struct of_device_id ad5272_dt_ids[] = { + { .compatible = "adi,ad5272-020", .data = (void *)AD5272_020 }, + { .compatible = "adi,ad5272-050", .data = (void *)AD5272_050 }, + { .compatible = "adi,ad5272-100", .data = (void *)AD5272_100 }, + { .compatible = "adi,ad5274-020", .data = (void *)AD5274_020 }, + { .compatible = "adi,ad5274-100", .data = (void *)AD5274_100 }, + {} +}; +MODULE_DEVICE_TABLE(of, ad5272_dt_ids); +#endif /* CONFIG_OF */ + +static const struct i2c_device_id ad5272_id[] = { + { "ad5272-020", AD5272_020 }, + { "ad5272-050", AD5272_050 }, + { "ad5272-100", AD5272_100 }, + { "ad5274-020", AD5274_020 }, + { "ad5274-100", AD5274_100 }, + {} +}; +MODULE_DEVICE_TABLE(i2c, ad5272_id); + +static struct i2c_driver ad5272_driver = { + .driver = { + .name = "ad5272", + .of_match_table = of_match_ptr(ad5272_dt_ids), + }, + .probe = ad5272_probe, + .id_table = ad5272_id, +}; + +module_i2c_driver(ad5272_driver); + +MODULE_AUTHOR("Phil Reid <preid-TeWIRZsGUAnP+dxuUfoltA@public.gmane.org>"); +MODULE_DESCRIPTION("AD5272 digital potentiometer"); +MODULE_LICENSE("GPL v2"); -- 1.8.3.1 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply related [flat|nested] 9+ messages in thread
[parent not found: <1517231574-92777-3-git-send-email-preid-qgqNFa1JUf/o2iN0hyhwsIdd74u8MsAO@public.gmane.org>]
* Re: [PATCH v4 2/2] iio: ad5272: Add support for Analog Devices digital potentiometers [not found] ` <1517231574-92777-3-git-send-email-preid-qgqNFa1JUf/o2iN0hyhwsIdd74u8MsAO@public.gmane.org> @ 2018-02-04 10:57 ` Jonathan Cameron 0 siblings, 0 replies; 9+ messages in thread From: Jonathan Cameron @ 2018-02-04 10:57 UTC (permalink / raw) To: Phil Reid Cc: knaack.h-Mmb7MZpHnFY, lars-Qo5EllUWu/uELgA04lAiVw, pmeerw-jW+XmwGofnusTnJN9+BGXg, robh+dt-DgEjT+Ai2ygdnm+yROfE0A, mark.rutland-5wv7dgnIgG8, Michael.Hennerich-OyLXuOCK7orQT0dZR+AlfA, linux-iio-u79uwXL29TY76Z2rM5mHXA, devicetree-u79uwXL29TY76Z2rM5mHXA On Mon, 29 Jan 2018 21:12:54 +0800 Phil Reid <preid-qgqNFa1JUf/o2iN0hyhwsIdd74u8MsAO@public.gmane.org> wrote: > Add implementation for Analog Devices AD5272 and AD5274 digital > potentiometer devices. > > Signed-off-by: Phil Reid <preid-qgqNFa1JUf/o2iN0hyhwsIdd74u8MsAO@public.gmane.org> Nice little driver - thanks. Applied to the togreg branch of iio.git and pushed out as testing for the autobuilders to play with it. Thanks, Jonathan > --- > drivers/iio/potentiometer/Kconfig | 10 ++ > drivers/iio/potentiometer/Makefile | 1 + > drivers/iio/potentiometer/ad5272.c | 231 +++++++++++++++++++++++++++++++++++++ > 3 files changed, 242 insertions(+) > create mode 100644 drivers/iio/potentiometer/ad5272.c > > diff --git a/drivers/iio/potentiometer/Kconfig b/drivers/iio/potentiometer/Kconfig > index 8bf2825..8daf6d1 100644 > --- a/drivers/iio/potentiometer/Kconfig > +++ b/drivers/iio/potentiometer/Kconfig > @@ -5,6 +5,16 @@ > > menu "Digital potentiometers" > > +config AD5272 > + tristate "Analog Devices AD5272 and similar Digital Potentiometer driver" > + depends on I2C > + help > + Say yes here to build support for the Analog Devices AD5272 and AD5274 > + digital potentiometer chip. > + > + To compile this driver as a module, choose M here: the > + module will be called ad5272. > + > config DS1803 > tristate "Maxim Integrated DS1803 Digital Potentiometer driver" > depends on I2C > diff --git a/drivers/iio/potentiometer/Makefile b/drivers/iio/potentiometer/Makefile > index 2260d40..498bbb8 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_AD5272) += ad5272.o > obj-$(CONFIG_DS1803) += ds1803.o > obj-$(CONFIG_MAX5481) += max5481.o > obj-$(CONFIG_MAX5487) += max5487.o > diff --git a/drivers/iio/potentiometer/ad5272.c b/drivers/iio/potentiometer/ad5272.c > new file mode 100644 > index 0000000..0175fd5 > --- /dev/null > +++ b/drivers/iio/potentiometer/ad5272.c > @@ -0,0 +1,231 @@ > +// SPDX-License-Identifier: GPL-2.0+ > +/* > + * Analog Devices AD5372 digital potentiometer driver > + * Copyright (C) 2018 Phil Reid <preid-qgqNFa1JUf/o2iN0hyhwsIdd74u8MsAO@public.gmane.org> > + * > + * Datasheet: http://www.analog.com/media/en/technical-documentation/data-sheets/AD5272_5274.pdf > + * > + * DEVID #Wipers #Positions Resistor Opts (kOhm) i2c address > + * ad5272 1 1024 20, 50, 100 01011xx > + * ad5274 1 256 20, 100 01011xx > + */ > + > +#include <linux/delay.h> > +#include <linux/gpio/consumer.h> > +#include <linux/i2c.h> > +#include <linux/iio/iio.h> > +#include <linux/module.h> > + > +#define AD5272_RDAC_WR 1 > +#define AD5272_RDAC_RD 2 > +#define AD5272_RESET 4 > +#define AD5272_CTL 7 > + > +#define AD5272_RDAC_WR_EN BIT(1) > + > +struct ad5272_cfg { > + int max_pos; > + int kohms; > + int shift; > +}; > + > +enum ad5272_type { > + AD5272_020, > + AD5272_050, > + AD5272_100, > + AD5274_020, > + AD5274_100, > +}; > + > +static const struct ad5272_cfg ad5272_cfg[] = { > + [AD5272_020] = { .max_pos = 1024, .kohms = 20 }, > + [AD5272_050] = { .max_pos = 1024, .kohms = 50 }, > + [AD5272_100] = { .max_pos = 1024, .kohms = 100 }, > + [AD5274_020] = { .max_pos = 256, .kohms = 20, .shift = 2 }, > + [AD5274_100] = { .max_pos = 256, .kohms = 100, .shift = 2 }, > +}; > + > +struct ad5272_data { > + struct i2c_client *client; > + struct mutex lock; > + const struct ad5272_cfg *cfg; > + u8 buf[2] ____cacheline_aligned; > +}; > + > +static const struct iio_chan_spec ad5272_channel = { > + .type = IIO_RESISTANCE, > + .output = 1, > + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), > + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), > +}; > + > +static int ad5272_write(struct ad5272_data *data, int reg, int val) > +{ > + int ret; > + > + data->buf[0] = (reg << 2) | ((val >> 8) & 0x3); > + data->buf[1] = (u8)val; > + > + mutex_lock(&data->lock); > + ret = i2c_master_send(data->client, data->buf, sizeof(data->buf)); > + mutex_unlock(&data->lock); > + return ret < 0 ? ret : 0; > +} > + > +static int ad5272_read(struct ad5272_data *data, int reg, int *val) > +{ > + int ret; > + > + data->buf[0] = reg << 2; > + data->buf[1] = 0; > + > + mutex_lock(&data->lock); > + ret = i2c_master_send(data->client, data->buf, sizeof(data->buf)); > + if (ret < 0) > + goto error; > + > + ret = i2c_master_recv(data->client, data->buf, sizeof(data->buf)); > + if (ret < 0) > + goto error; > + > + *val = ((data->buf[0] & 0x3) << 8) | data->buf[1]; > + ret = 0; > +error: > + mutex_unlock(&data->lock); > + return ret; > +} > + > +static int ad5272_read_raw(struct iio_dev *indio_dev, > + struct iio_chan_spec const *chan, > + int *val, int *val2, long mask) > +{ > + struct ad5272_data *data = iio_priv(indio_dev); > + int ret; > + > + switch (mask) { > + case IIO_CHAN_INFO_RAW: { > + ret = ad5272_read(data, AD5272_RDAC_RD, val); > + *val = *val >> data->cfg->shift; > + return ret ? ret : IIO_VAL_INT; > + } > + case IIO_CHAN_INFO_SCALE: > + *val = 1000 * data->cfg->kohms; > + *val2 = data->cfg->max_pos; > + return IIO_VAL_FRACTIONAL; > + } > + > + return -EINVAL; > +} > + > +static int ad5272_write_raw(struct iio_dev *indio_dev, > + struct iio_chan_spec const *chan, > + int val, int val2, long mask) > +{ > + struct ad5272_data *data = iio_priv(indio_dev); > + > + if (mask != IIO_CHAN_INFO_RAW) > + return -EINVAL; > + > + if (val >= data->cfg->max_pos || val < 0 || val2) > + return -EINVAL; > + > + return ad5272_write(data, AD5272_RDAC_WR, val << data->cfg->shift); > +} > + > +static const struct iio_info ad5272_info = { > + .read_raw = ad5272_read_raw, > + .write_raw = ad5272_write_raw, > +}; > + > +static int ad5272_reset(struct ad5272_data *data) > +{ > + struct gpio_desc *reset_gpio; > + > + reset_gpio = devm_gpiod_get_optional(&data->client->dev, "reset", > + GPIOD_OUT_LOW); > + if (IS_ERR(reset_gpio)) > + return PTR_ERR(reset_gpio); > + > + if (reset_gpio) { > + udelay(1); > + gpiod_set_value(reset_gpio, 1); > + } else { > + ad5272_write(data, AD5272_RESET, 0); > + } > + usleep_range(1000, 2000); > + > + return 0; > +} > + > +static int ad5272_probe(struct i2c_client *client, > + const struct i2c_device_id *id) > +{ > + struct device *dev = &client->dev; > + struct iio_dev *indio_dev; > + struct ad5272_data *data; > + int ret; > + > + indio_dev = devm_iio_device_alloc(dev, sizeof(*data)); > + if (!indio_dev) > + return -ENOMEM; > + > + i2c_set_clientdata(client, indio_dev); > + > + data = iio_priv(indio_dev); > + data->client = client; > + mutex_init(&data->lock); > + data->cfg = &ad5272_cfg[id->driver_data]; > + > + ret = ad5272_reset(data); > + if (ret) > + return ret; > + > + ret = ad5272_write(data, AD5272_CTL, AD5272_RDAC_WR_EN); > + if (ret < 0) > + return -ENODEV; > + > + indio_dev->dev.parent = dev; > + indio_dev->info = &ad5272_info; > + indio_dev->channels = &ad5272_channel; > + indio_dev->num_channels = 1; > + indio_dev->name = client->name; > + > + return devm_iio_device_register(dev, indio_dev); > +} > + > +#if defined(CONFIG_OF) > +static const struct of_device_id ad5272_dt_ids[] = { > + { .compatible = "adi,ad5272-020", .data = (void *)AD5272_020 }, > + { .compatible = "adi,ad5272-050", .data = (void *)AD5272_050 }, > + { .compatible = "adi,ad5272-100", .data = (void *)AD5272_100 }, > + { .compatible = "adi,ad5274-020", .data = (void *)AD5274_020 }, > + { .compatible = "adi,ad5274-100", .data = (void *)AD5274_100 }, > + {} > +}; > +MODULE_DEVICE_TABLE(of, ad5272_dt_ids); > +#endif /* CONFIG_OF */ > + > +static const struct i2c_device_id ad5272_id[] = { > + { "ad5272-020", AD5272_020 }, > + { "ad5272-050", AD5272_050 }, > + { "ad5272-100", AD5272_100 }, > + { "ad5274-020", AD5274_020 }, > + { "ad5274-100", AD5274_100 }, > + {} > +}; > +MODULE_DEVICE_TABLE(i2c, ad5272_id); > + > +static struct i2c_driver ad5272_driver = { > + .driver = { > + .name = "ad5272", > + .of_match_table = of_match_ptr(ad5272_dt_ids), > + }, > + .probe = ad5272_probe, > + .id_table = ad5272_id, > +}; > + > +module_i2c_driver(ad5272_driver); > + > +MODULE_AUTHOR("Phil Reid <preid-TeWIRZsGUAnP+dxuUfoltA@public.gmane.org>"); > +MODULE_DESCRIPTION("AD5272 digital potentiometer"); > +MODULE_LICENSE("GPL v2"); -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2018-02-07 10:50 UTC | newest] Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2018-01-29 13:12 [PATCH v4 0/2] iio: ad5272: Add support for Analog Devices digital potentiometers Phil Reid [not found] ` <1517231574-92777-1-git-send-email-preid-qgqNFa1JUf/o2iN0hyhwsIdd74u8MsAO@public.gmane.org> 2018-01-29 13:12 ` [PATCH v4 1/2] dt-bindings: ad5272: Add bindings " Phil Reid [not found] ` <1517231574-92777-2-git-send-email-preid-qgqNFa1JUf/o2iN0hyhwsIdd74u8MsAO@public.gmane.org> 2018-02-04 10:34 ` Jonathan Cameron 2018-02-05 6:07 ` Rob Herring 2018-02-05 7:25 ` Phil Reid [not found] ` <f1d2bf62-c4b7-9cd4-4962-3c07c22bdb5e-qgqNFa1JUf/o2iN0hyhwsIdd74u8MsAO@public.gmane.org> 2018-02-07 10:50 ` Jonathan Cameron 2018-02-05 8:34 ` Brandon Martin 2018-01-29 13:12 ` [PATCH v4 2/2] iio: ad5272: Add support " Phil Reid [not found] ` <1517231574-92777-3-git-send-email-preid-qgqNFa1JUf/o2iN0hyhwsIdd74u8MsAO@public.gmane.org> 2018-02-04 10:57 ` Jonathan Cameron
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).