linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v6 0/2] Driver for Microchip digital potentiometers
@ 2015-09-23 14:26 Peter Rosin
  2015-09-23 14:26 ` [PATCH v6 1/2] iio: resistance: Document that resistance can be output Peter Rosin
  2015-09-23 14:26 ` [PATCH v6 2/2] iio: mcp4531: Driver for Microchip digital potentiometers Peter Rosin
  0 siblings, 2 replies; 8+ messages in thread
From: Peter Rosin @ 2015-09-23 14:26 UTC (permalink / raw)
  To: linux-iio
  Cc: Peter Rosin, Crt Mori, Daniel Baluta, Andreas Dannenberg,
	Greg Kroah-Hartman, Jonathan Cameron, Hartmut Knaack,
	Lars-Peter Clausen, Peter Meerwald, Peter Rosin, linux-kernel

From: Peter Rosin <peda@axentia.se>

This is the sixth attempt for a driver for these chips.

Thanks for review comments from Greg Kroah-Hartman, Crt Mori,
Daniel Baluta, Lars-Peter Clauson, Andreas Dannenberg, Peter
Meerwald and Jonathan Cameron. I think and hope I got it all sorted.

Changes since v5:
- Use a symbolic name to index the cfg array (Lars-Peter)
- Consolidate handling of MCP4xx1 and MCP4xx2 (me)

Changes since v4:
- Less convoluted changelog (Jonathan)
- Use an index into an array of configs as dev_id (Jonathan)
- Drop .address and use .channel (Jonathan)
- Remove one layer of wrappers (Jonathan)
- Provide a scale (Jonathan, Lars-Peter)

Changes since v3:
- Use i2c_smbus_read_word_swapped (Peter)
- Use devm_iio_device_register and drop the mcp4531_remove op (Peter)
- Add defines for a few magic numbers (Peter)
- Deduplicate channel params with a macro (Peter)
- Mention the i2c client address options (Peter)
- Whitespace and other trivial nits (Peter)

Changes since v2:
- Change naming from mcp4xxx_dpot to mcp4531 (Daniel)
- Added links to datasheet in commit message and source (Daniel)
- Rename from pot to potentiometer (Daniel, Crt)
- Use IIO_RESISTANCE instead of IIO_STEPS (Crt, Lars-Peter)
- Don't use wildcards in MAINTAINERS and point to the iio list (Crt)
- Avoid races by not caching values (Crt)
- Spell Microchip correctly (Andreas)

Changes since v1:
- Make it an IIO driver instead (Greg)
- Don't convolute the code with big obscure macros (Greg)
- Inline the bits from mcp4xxx_dpot.h that are actually used
  and drop that file (me)
- Better Changelog (Greg)

Cheers,
Peter

Peter Rosin (2):
  iio: resistance: Document that resistance can be output
  iio: mcp4531: Driver for Microchip digital potentiometers

 Documentation/ABI/testing/sysfs-bus-iio |    2 +
 MAINTAINERS                             |    6 +
 drivers/iio/Kconfig                     |    1 +
 drivers/iio/Makefile                    |    1 +
 drivers/iio/potentiometer/Kconfig       |   20 +++
 drivers/iio/potentiometer/Makefile      |    6 +
 drivers/iio/potentiometer/mcp4531.c     |  231 +++++++++++++++++++++++++++++++
 7 files changed, 267 insertions(+)
 create mode 100644 drivers/iio/potentiometer/Kconfig
 create mode 100644 drivers/iio/potentiometer/Makefile
 create mode 100644 drivers/iio/potentiometer/mcp4531.c

-- 
1.7.10.4


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v6 1/2] iio: resistance: Document that resistance can be output
  2015-09-23 14:26 [PATCH v6 0/2] Driver for Microchip digital potentiometers Peter Rosin
@ 2015-09-23 14:26 ` Peter Rosin
  2015-09-27 15:46   ` Jonathan Cameron
  2015-09-23 14:26 ` [PATCH v6 2/2] iio: mcp4531: Driver for Microchip digital potentiometers Peter Rosin
  1 sibling, 1 reply; 8+ messages in thread
From: Peter Rosin @ 2015-09-23 14:26 UTC (permalink / raw)
  To: linux-iio
  Cc: Peter Rosin, Crt Mori, Daniel Baluta, Andreas Dannenberg,
	Greg Kroah-Hartman, Jonathan Cameron, Hartmut Knaack,
	Lars-Peter Clausen, Peter Meerwald, Peter Rosin, linux-kernel

From: Peter Rosin <peda@axentia.se>

Signed-off-by: Peter Rosin <peda@axentia.se>
---
 Documentation/ABI/testing/sysfs-bus-iio |    2 ++
 1 file changed, 2 insertions(+)

diff --git a/Documentation/ABI/testing/sysfs-bus-iio b/Documentation/ABI/testing/sysfs-bus-iio
index 9398484196c4..2eea468f704d 100644
--- a/Documentation/ABI/testing/sysfs-bus-iio
+++ b/Documentation/ABI/testing/sysfs-bus-iio
@@ -1475,6 +1475,8 @@ Description:
 
 What:		/sys/bus/iio/devices/iio:deviceX/in_resistance_raw
 What:		/sys/bus/iio/devices/iio:deviceX/in_resistanceX_raw
+What:		/sys/bus/iio/devices/iio:deviceX/out_resistance_raw
+What:		/sys/bus/iio/devices/iio:deviceX/out_resistanceX_raw
 KernelVersion:	4.3
 Contact:	linux-iio@vger.kernel.org
 Description:
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v6 2/2] iio: mcp4531: Driver for Microchip digital potentiometers
  2015-09-23 14:26 [PATCH v6 0/2] Driver for Microchip digital potentiometers Peter Rosin
  2015-09-23 14:26 ` [PATCH v6 1/2] iio: resistance: Document that resistance can be output Peter Rosin
@ 2015-09-23 14:26 ` Peter Rosin
  2015-09-27 15:50   ` Jonathan Cameron
  1 sibling, 1 reply; 8+ messages in thread
From: Peter Rosin @ 2015-09-23 14:26 UTC (permalink / raw)
  To: linux-iio
  Cc: Peter Rosin, Crt Mori, Daniel Baluta, Andreas Dannenberg,
	Greg Kroah-Hartman, Jonathan Cameron, Hartmut Knaack,
	Lars-Peter Clausen, Peter Meerwald, Peter Rosin, linux-kernel

From: Peter Rosin <peda@axentia.se>

Add support for Microchip digital potentiometers and rheostats
	MCP4531, MCP4532, MCP4551, MCP4552
	MCP4631, MCP4632, MCP4651, MCP4652

DEVICE   Wipers  Steps  Resistor Opts (kOhm)  i2c address
MCP4531  1       129    5, 10, 50, 100        010111x
MCP4532  1       129    5, 10, 50, 100        01011xx
MCP4551  1       257    5, 10, 50, 100        010111x
MCP4552  1       257    5, 10, 50, 100        01011xx
MCP4631  2       129    5, 10, 50, 100        0101xxx
MCP4632  2       129    5, 10, 50, 100        01011xx
MCP4651  2       257    5, 10, 50, 100        0101xxx
MCP4652  2       257    5, 10, 50, 100        01011xx

Datasheet: http://www.microchip.com/downloads/en/DeviceDoc/22096b.pdf

Signed-off-by: Peter Rosin <peda@axentia.se>
---
 MAINTAINERS                         |    6 +
 drivers/iio/Kconfig                 |    1 +
 drivers/iio/Makefile                |    1 +
 drivers/iio/potentiometer/Kconfig   |   20 +++
 drivers/iio/potentiometer/Makefile  |    6 +
 drivers/iio/potentiometer/mcp4531.c |  231 +++++++++++++++++++++++++++++++++++
 6 files changed, 265 insertions(+)
 create mode 100644 drivers/iio/potentiometer/Kconfig
 create mode 100644 drivers/iio/potentiometer/Makefile
 create mode 100644 drivers/iio/potentiometer/mcp4531.c

diff --git a/MAINTAINERS b/MAINTAINERS
index b60e2b2369d2..27862156c7a7 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -6600,6 +6600,12 @@ W:	http://linuxtv.org
 S:	Maintained
 F:	drivers/media/radio/radio-maxiradio*
 
+MCP4531 MICROCHIP DIGITAL POTENTIOMETER DRIVER
+M:	Peter Rosin <peda@axentia.se>
+L:	linux-iio@vger.kernel.org
+S:	Maintained
+F:	drivers/iio/potentiometer/mcp4531.c
+
 MEDIA DRIVERS FOR RENESAS - VSP1
 M:	Laurent Pinchart <laurent.pinchart@ideasonboard.com>
 L:	linux-media@vger.kernel.org
diff --git a/drivers/iio/Kconfig b/drivers/iio/Kconfig
index 4011effe4c05..7cc87f322655 100644
--- a/drivers/iio/Kconfig
+++ b/drivers/iio/Kconfig
@@ -73,6 +73,7 @@ source "drivers/iio/orientation/Kconfig"
 if IIO_TRIGGER
    source "drivers/iio/trigger/Kconfig"
 endif #IIO_TRIGGER
+source "drivers/iio/potentiometer/Kconfig"
 source "drivers/iio/pressure/Kconfig"
 source "drivers/iio/proximity/Kconfig"
 source "drivers/iio/temperature/Kconfig"
diff --git a/drivers/iio/Makefile b/drivers/iio/Makefile
index 698afc2d17ce..121c814e366b 100644
--- a/drivers/iio/Makefile
+++ b/drivers/iio/Makefile
@@ -23,6 +23,7 @@ obj-y += imu/
 obj-y += light/
 obj-y += magnetometer/
 obj-y += orientation/
+obj-y += potentiometer/
 obj-y += pressure/
 obj-y += proximity/
 obj-y += temperature/
diff --git a/drivers/iio/potentiometer/Kconfig b/drivers/iio/potentiometer/Kconfig
new file mode 100644
index 000000000000..fd75db73e582
--- /dev/null
+++ b/drivers/iio/potentiometer/Kconfig
@@ -0,0 +1,20 @@
+#
+# Potentiometer drivers
+#
+# When adding new entries keep the list in alphabetical order
+
+menu "Digital potentiometers"
+
+config MCP4531
+	tristate "Microchip MCP45xx/MCP46xx Digital Potentiometer driver"
+	depends on I2C
+	help
+	  Say yes here to build support for the Microchip
+	  MCP4531, MCP4532, MCP4551, MCP4552,
+	  MCP4631, MCP4632, MCP4651, MCP4652
+	  digital potentiomenter chips.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called mcp4531.
+
+endmenu
diff --git a/drivers/iio/potentiometer/Makefile b/drivers/iio/potentiometer/Makefile
new file mode 100644
index 000000000000..8afe49227012
--- /dev/null
+++ b/drivers/iio/potentiometer/Makefile
@@ -0,0 +1,6 @@
+#
+# Makefile for industrial I/O potentiometer drivers
+#
+
+# When adding new entries keep the list in alphabetical order
+obj-$(CONFIG_MCP4531) += mcp4531.o
diff --git a/drivers/iio/potentiometer/mcp4531.c b/drivers/iio/potentiometer/mcp4531.c
new file mode 100644
index 000000000000..a3f66874ee2e
--- /dev/null
+++ b/drivers/iio/potentiometer/mcp4531.c
@@ -0,0 +1,231 @@
+/*
+ * Industrial I/O driver for Microchip digital potentiometers
+ * Copyright (c) 2015  Axentia Technologies AB
+ * Author: Peter Rosin <peda@axentia.se>
+ *
+ * Datasheet: http://www.microchip.com/downloads/en/DeviceDoc/22096b.pdf
+ *
+ * DEVID	#Wipers	#Positions	Resistor Opts (kOhm)	i2c address
+ * mcp4531	1	129		5, 10, 50, 100          010111x
+ * mcp4532	1	129		5, 10, 50, 100          01011xx
+ * mcp4551	1	257		5, 10, 50, 100          010111x
+ * mcp4552	1	257		5, 10, 50, 100          01011xx
+ * mcp4631	2	129		5, 10, 50, 100          0101xxx
+ * mcp4632	2	129		5, 10, 50, 100          01011xx
+ * mcp4651	2	257		5, 10, 50, 100          0101xxx
+ * mcp4652	2	257		5, 10, 50, 100          01011xx
+ *
+ * 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 <linux/module.h>
+#include <linux/i2c.h>
+#include <linux/err.h>
+
+#include <linux/iio/iio.h>
+
+struct mcp4531_cfg {
+	int wipers;
+	int max_pos;
+	int kohms;
+};
+
+enum mcp4531_type {
+	MCP453x_502,
+	MCP453x_103,
+	MCP453x_503,
+	MCP453x_104,
+	MCP455x_502,
+	MCP455x_103,
+	MCP455x_503,
+	MCP455x_104,
+	MCP463x_502,
+	MCP463x_103,
+	MCP463x_503,
+	MCP463x_104,
+	MCP465x_502,
+	MCP465x_103,
+	MCP465x_503,
+	MCP465x_104,
+};
+
+static const struct mcp4531_cfg mcp4531_cfg[] = {
+	[MCP453x_502] = { .wipers = 1, .max_pos = 128, .kohms =   5, },
+	[MCP453x_103] = { .wipers = 1, .max_pos = 128, .kohms =  10, },
+	[MCP453x_503] = { .wipers = 1, .max_pos = 128, .kohms =  50, },
+	[MCP453x_104] = { .wipers = 1, .max_pos = 128, .kohms = 100, },
+	[MCP455x_502] = { .wipers = 1, .max_pos = 256, .kohms =   5, },
+	[MCP455x_103] = { .wipers = 1, .max_pos = 256, .kohms =  10, },
+	[MCP455x_503] = { .wipers = 1, .max_pos = 256, .kohms =  50, },
+	[MCP455x_104] = { .wipers = 1, .max_pos = 256, .kohms = 100, },
+	[MCP463x_502] = { .wipers = 2, .max_pos = 128, .kohms =   5, },
+	[MCP463x_103] = { .wipers = 2, .max_pos = 128, .kohms =  10, },
+	[MCP463x_503] = { .wipers = 2, .max_pos = 128, .kohms =  50, },
+	[MCP463x_104] = { .wipers = 2, .max_pos = 128, .kohms = 100, },
+	[MCP465x_502] = { .wipers = 2, .max_pos = 256, .kohms =   5, },
+	[MCP465x_103] = { .wipers = 2, .max_pos = 256, .kohms =  10, },
+	[MCP465x_503] = { .wipers = 2, .max_pos = 256, .kohms =  50, },
+	[MCP465x_104] = { .wipers = 2, .max_pos = 256, .kohms = 100, },
+};
+
+#define MCP4531_WRITE (0 << 2)
+#define MCP4531_INCR  (1 << 2)
+#define MCP4531_DECR  (2 << 2)
+#define MCP4531_READ  (3 << 2)
+
+#define MCP4531_WIPER_SHIFT (4)
+
+struct mcp4531_data {
+	struct i2c_client *client;
+	unsigned long devid;
+};
+
+#define MCP4531_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 mcp4531_channels[] = {
+	MCP4531_CHANNEL(0),
+	MCP4531_CHANNEL(1),
+};
+
+static int mcp4531_read_raw(struct iio_dev *indio_dev,
+			    struct iio_chan_spec const *chan,
+			    int *val, int *val2, long mask)
+{
+	struct mcp4531_data *data = iio_priv(indio_dev);
+	int address = chan->channel << MCP4531_WIPER_SHIFT;
+	s32 ret;
+
+	switch (mask) {
+	case IIO_CHAN_INFO_RAW:
+		ret = i2c_smbus_read_word_swapped(data->client,
+						  MCP4531_READ | address);
+		if (ret < 0)
+			return ret;
+		*val = ret;
+		return IIO_VAL_INT;
+	case IIO_CHAN_INFO_SCALE:
+		*val = 1000 * mcp4531_cfg[data->devid].kohms;
+		*val2 = mcp4531_cfg[data->devid].max_pos;
+		return IIO_VAL_FRACTIONAL;
+	}
+
+	return -EINVAL;
+}
+
+static int mcp4531_write_raw(struct iio_dev *indio_dev,
+			     struct iio_chan_spec const *chan,
+			     int val, int val2, long mask)
+{
+	struct mcp4531_data *data = iio_priv(indio_dev);
+	int address = chan->channel << MCP4531_WIPER_SHIFT;
+
+	switch (mask) {
+	case IIO_CHAN_INFO_RAW:
+		if (val > mcp4531_cfg[data->devid].max_pos || val < 0)
+			return -EINVAL;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	return i2c_smbus_write_byte_data(data->client,
+					 MCP4531_WRITE | address | (val >> 8),
+					 val & 0xff);
+}
+
+static const struct iio_info mcp4531_info = {
+	.read_raw = mcp4531_read_raw,
+	.write_raw = mcp4531_write_raw,
+	.driver_module = THIS_MODULE,
+};
+
+static int mcp4531_probe(struct i2c_client *client,
+			 const struct i2c_device_id *id)
+{
+	struct device *dev = &client->dev;
+	unsigned long devid = id->driver_data;
+	struct mcp4531_data *data;
+	struct iio_dev *indio_dev;
+
+	if (!i2c_check_functionality(client->adapter,
+				     I2C_FUNC_SMBUS_WORD_DATA)) {
+		dev_err(dev, "SMBUS Word Data not supported\n");
+		return -EIO;
+	}
+
+	indio_dev = devm_iio_device_alloc(dev, sizeof(*data));
+	if (!indio_dev)
+		return -ENOMEM;
+	data = iio_priv(indio_dev);
+	i2c_set_clientdata(client, indio_dev);
+	data->client = client;
+	data->devid = devid;
+
+	indio_dev->dev.parent = dev;
+	indio_dev->info = &mcp4531_info;
+	indio_dev->channels = mcp4531_channels;
+	indio_dev->num_channels = mcp4531_cfg[devid].wipers;
+	indio_dev->name = client->name;
+
+	return devm_iio_device_register(dev, indio_dev);
+}
+
+static const struct i2c_device_id mcp4531_id[] = {
+	{ "mcp4531-502", MCP453x_502 },
+	{ "mcp4531-103", MCP453x_103 },
+	{ "mcp4531-503", MCP453x_503 },
+	{ "mcp4531-104", MCP453x_104 },
+	{ "mcp4532-502", MCP453x_502 },
+	{ "mcp4532-103", MCP453x_103 },
+	{ "mcp4532-503", MCP453x_503 },
+	{ "mcp4532-104", MCP453x_104 },
+	{ "mcp4551-502", MCP455x_502 },
+	{ "mcp4551-103", MCP455x_103 },
+	{ "mcp4551-503", MCP455x_503 },
+	{ "mcp4551-104", MCP455x_104 },
+	{ "mcp4552-502", MCP455x_502 },
+	{ "mcp4552-103", MCP455x_103 },
+	{ "mcp4552-503", MCP455x_503 },
+	{ "mcp4552-104", MCP455x_104 },
+	{ "mcp4631-502", MCP463x_502 },
+	{ "mcp4631-103", MCP463x_103 },
+	{ "mcp4631-503", MCP463x_503 },
+	{ "mcp4631-104", MCP463x_104 },
+	{ "mcp4632-502", MCP463x_502 },
+	{ "mcp4632-103", MCP463x_103 },
+	{ "mcp4632-503", MCP463x_503 },
+	{ "mcp4632-104", MCP463x_104 },
+	{ "mcp4651-502", MCP465x_502 },
+	{ "mcp4651-103", MCP465x_103 },
+	{ "mcp4651-503", MCP465x_503 },
+	{ "mcp4651-104", MCP465x_104 },
+	{ "mcp4652-502", MCP465x_502 },
+	{ "mcp4652-103", MCP465x_103 },
+	{ "mcp4652-503", MCP465x_503 },
+	{ "mcp4652-104", MCP465x_104 },
+	{}
+};
+MODULE_DEVICE_TABLE(i2c, mcp4531_id);
+
+static struct i2c_driver mcp4531_driver = {
+	.driver = {
+		.name	= "mcp4531",
+	},
+	.probe		= mcp4531_probe,
+	.id_table	= mcp4531_id,
+};
+
+module_i2c_driver(mcp4531_driver);
+
+MODULE_AUTHOR("Peter Rosin <peda@axentia.se>");
+MODULE_DESCRIPTION("MCP4531 digital potentiometer");
+MODULE_LICENSE("GPL");
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v6 1/2] iio: resistance: Document that resistance can be output
  2015-09-23 14:26 ` [PATCH v6 1/2] iio: resistance: Document that resistance can be output Peter Rosin
@ 2015-09-27 15:46   ` Jonathan Cameron
  0 siblings, 0 replies; 8+ messages in thread
From: Jonathan Cameron @ 2015-09-27 15:46 UTC (permalink / raw)
  To: Peter Rosin, linux-iio
  Cc: Peter Rosin, Crt Mori, Daniel Baluta, Andreas Dannenberg,
	Greg Kroah-Hartman, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald, linux-kernel

On 23/09/15 15:26, Peter Rosin wrote:
> From: Peter Rosin <peda@axentia.se>
> 
> Signed-off-by: Peter Rosin <peda@axentia.se>
Applied to the togreg branch of iio.git - initially pushed out as testing
for the autobuilders to play with it.
Note will probably get rebased shortly once Greg has picked up last pull
request (assuming he does!)

Jonathan
> ---
>  Documentation/ABI/testing/sysfs-bus-iio |    2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/Documentation/ABI/testing/sysfs-bus-iio b/Documentation/ABI/testing/sysfs-bus-iio
> index 9398484196c4..2eea468f704d 100644
> --- a/Documentation/ABI/testing/sysfs-bus-iio
> +++ b/Documentation/ABI/testing/sysfs-bus-iio
> @@ -1475,6 +1475,8 @@ Description:
>  
>  What:		/sys/bus/iio/devices/iio:deviceX/in_resistance_raw
>  What:		/sys/bus/iio/devices/iio:deviceX/in_resistanceX_raw
> +What:		/sys/bus/iio/devices/iio:deviceX/out_resistance_raw
> +What:		/sys/bus/iio/devices/iio:deviceX/out_resistanceX_raw
>  KernelVersion:	4.3
>  Contact:	linux-iio@vger.kernel.org
>  Description:
> 


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v6 2/2] iio: mcp4531: Driver for Microchip digital potentiometers
  2015-09-23 14:26 ` [PATCH v6 2/2] iio: mcp4531: Driver for Microchip digital potentiometers Peter Rosin
@ 2015-09-27 15:50   ` Jonathan Cameron
  2015-09-28  7:59     ` Peter Rosin
  0 siblings, 1 reply; 8+ messages in thread
From: Jonathan Cameron @ 2015-09-27 15:50 UTC (permalink / raw)
  To: Peter Rosin, linux-iio
  Cc: Peter Rosin, Crt Mori, Daniel Baluta, Andreas Dannenberg,
	Greg Kroah-Hartman, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald, linux-kernel

On 23/09/15 15:26, Peter Rosin wrote:
> From: Peter Rosin <peda@axentia.se>
> 
> Add support for Microchip digital potentiometers and rheostats
> 	MCP4531, MCP4532, MCP4551, MCP4552
> 	MCP4631, MCP4632, MCP4651, MCP4652
> 
> DEVICE   Wipers  Steps  Resistor Opts (kOhm)  i2c address
> MCP4531  1       129    5, 10, 50, 100        010111x
> MCP4532  1       129    5, 10, 50, 100        01011xx
> MCP4551  1       257    5, 10, 50, 100        010111x
> MCP4552  1       257    5, 10, 50, 100        01011xx
> MCP4631  2       129    5, 10, 50, 100        0101xxx
> MCP4632  2       129    5, 10, 50, 100        01011xx
> MCP4651  2       257    5, 10, 50, 100        0101xxx
> MCP4652  2       257    5, 10, 50, 100        01011xx
> 
> Datasheet: http://www.microchip.com/downloads/en/DeviceDoc/22096b.pdf
Applied to the togreg branch of iio.git - initially pushed out as
testing for the autobuilders to play with it.

If anyone wants to add reviewed-by / acked-by then as I'll be
rebasing sometime in next few days anyway there is still time!

Jonathan
> 
> Signed-off-by: Peter Rosin <peda@axentia.se>
> ---
>  MAINTAINERS                         |    6 +
>  drivers/iio/Kconfig                 |    1 +
>  drivers/iio/Makefile                |    1 +
>  drivers/iio/potentiometer/Kconfig   |   20 +++
>  drivers/iio/potentiometer/Makefile  |    6 +
>  drivers/iio/potentiometer/mcp4531.c |  231 +++++++++++++++++++++++++++++++++++
>  6 files changed, 265 insertions(+)
>  create mode 100644 drivers/iio/potentiometer/Kconfig
>  create mode 100644 drivers/iio/potentiometer/Makefile
>  create mode 100644 drivers/iio/potentiometer/mcp4531.c
> 
> diff --git a/MAINTAINERS b/MAINTAINERS
> index b60e2b2369d2..27862156c7a7 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -6600,6 +6600,12 @@ W:	http://linuxtv.org
>  S:	Maintained
>  F:	drivers/media/radio/radio-maxiradio*
>  
> +MCP4531 MICROCHIP DIGITAL POTENTIOMETER DRIVER
> +M:	Peter Rosin <peda@axentia.se>
> +L:	linux-iio@vger.kernel.org
> +S:	Maintained
> +F:	drivers/iio/potentiometer/mcp4531.c
> +
>  MEDIA DRIVERS FOR RENESAS - VSP1
>  M:	Laurent Pinchart <laurent.pinchart@ideasonboard.com>
>  L:	linux-media@vger.kernel.org
> diff --git a/drivers/iio/Kconfig b/drivers/iio/Kconfig
> index 4011effe4c05..7cc87f322655 100644
> --- a/drivers/iio/Kconfig
> +++ b/drivers/iio/Kconfig
> @@ -73,6 +73,7 @@ source "drivers/iio/orientation/Kconfig"
>  if IIO_TRIGGER
>     source "drivers/iio/trigger/Kconfig"
>  endif #IIO_TRIGGER
> +source "drivers/iio/potentiometer/Kconfig"
>  source "drivers/iio/pressure/Kconfig"
>  source "drivers/iio/proximity/Kconfig"
>  source "drivers/iio/temperature/Kconfig"
> diff --git a/drivers/iio/Makefile b/drivers/iio/Makefile
> index 698afc2d17ce..121c814e366b 100644
> --- a/drivers/iio/Makefile
> +++ b/drivers/iio/Makefile
> @@ -23,6 +23,7 @@ obj-y += imu/
>  obj-y += light/
>  obj-y += magnetometer/
>  obj-y += orientation/
> +obj-y += potentiometer/
>  obj-y += pressure/
>  obj-y += proximity/
>  obj-y += temperature/
> diff --git a/drivers/iio/potentiometer/Kconfig b/drivers/iio/potentiometer/Kconfig
> new file mode 100644
> index 000000000000..fd75db73e582
> --- /dev/null
> +++ b/drivers/iio/potentiometer/Kconfig
> @@ -0,0 +1,20 @@
> +#
> +# Potentiometer drivers
> +#
> +# When adding new entries keep the list in alphabetical order
> +
> +menu "Digital potentiometers"
> +
> +config MCP4531
> +	tristate "Microchip MCP45xx/MCP46xx Digital Potentiometer driver"
> +	depends on I2C
> +	help
> +	  Say yes here to build support for the Microchip
> +	  MCP4531, MCP4532, MCP4551, MCP4552,
> +	  MCP4631, MCP4632, MCP4651, MCP4652
> +	  digital potentiomenter chips.
> +
> +	  To compile this driver as a module, choose M here: the
> +	  module will be called mcp4531.
> +
> +endmenu
> diff --git a/drivers/iio/potentiometer/Makefile b/drivers/iio/potentiometer/Makefile
> new file mode 100644
> index 000000000000..8afe49227012
> --- /dev/null
> +++ b/drivers/iio/potentiometer/Makefile
> @@ -0,0 +1,6 @@
> +#
> +# Makefile for industrial I/O potentiometer drivers
> +#
> +
> +# When adding new entries keep the list in alphabetical order
> +obj-$(CONFIG_MCP4531) += mcp4531.o
> diff --git a/drivers/iio/potentiometer/mcp4531.c b/drivers/iio/potentiometer/mcp4531.c
> new file mode 100644
> index 000000000000..a3f66874ee2e
> --- /dev/null
> +++ b/drivers/iio/potentiometer/mcp4531.c
> @@ -0,0 +1,231 @@
> +/*
> + * Industrial I/O driver for Microchip digital potentiometers
> + * Copyright (c) 2015  Axentia Technologies AB
> + * Author: Peter Rosin <peda@axentia.se>
> + *
> + * Datasheet: http://www.microchip.com/downloads/en/DeviceDoc/22096b.pdf
> + *
> + * DEVID	#Wipers	#Positions	Resistor Opts (kOhm)	i2c address
> + * mcp4531	1	129		5, 10, 50, 100          010111x
> + * mcp4532	1	129		5, 10, 50, 100          01011xx
> + * mcp4551	1	257		5, 10, 50, 100          010111x
> + * mcp4552	1	257		5, 10, 50, 100          01011xx
> + * mcp4631	2	129		5, 10, 50, 100          0101xxx
> + * mcp4632	2	129		5, 10, 50, 100          01011xx
> + * mcp4651	2	257		5, 10, 50, 100          0101xxx
> + * mcp4652	2	257		5, 10, 50, 100          01011xx
> + *
> + * 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 <linux/module.h>
> +#include <linux/i2c.h>
> +#include <linux/err.h>
> +
> +#include <linux/iio/iio.h>
> +
> +struct mcp4531_cfg {
> +	int wipers;
> +	int max_pos;
> +	int kohms;
> +};
> +
> +enum mcp4531_type {
> +	MCP453x_502,
> +	MCP453x_103,
> +	MCP453x_503,
> +	MCP453x_104,
> +	MCP455x_502,
> +	MCP455x_103,
> +	MCP455x_503,
> +	MCP455x_104,
> +	MCP463x_502,
> +	MCP463x_103,
> +	MCP463x_503,
> +	MCP463x_104,
> +	MCP465x_502,
> +	MCP465x_103,
> +	MCP465x_503,
> +	MCP465x_104,
> +};
> +
> +static const struct mcp4531_cfg mcp4531_cfg[] = {
> +	[MCP453x_502] = { .wipers = 1, .max_pos = 128, .kohms =   5, },
> +	[MCP453x_103] = { .wipers = 1, .max_pos = 128, .kohms =  10, },
> +	[MCP453x_503] = { .wipers = 1, .max_pos = 128, .kohms =  50, },
> +	[MCP453x_104] = { .wipers = 1, .max_pos = 128, .kohms = 100, },
> +	[MCP455x_502] = { .wipers = 1, .max_pos = 256, .kohms =   5, },
> +	[MCP455x_103] = { .wipers = 1, .max_pos = 256, .kohms =  10, },
> +	[MCP455x_503] = { .wipers = 1, .max_pos = 256, .kohms =  50, },
> +	[MCP455x_104] = { .wipers = 1, .max_pos = 256, .kohms = 100, },
> +	[MCP463x_502] = { .wipers = 2, .max_pos = 128, .kohms =   5, },
> +	[MCP463x_103] = { .wipers = 2, .max_pos = 128, .kohms =  10, },
> +	[MCP463x_503] = { .wipers = 2, .max_pos = 128, .kohms =  50, },
> +	[MCP463x_104] = { .wipers = 2, .max_pos = 128, .kohms = 100, },
> +	[MCP465x_502] = { .wipers = 2, .max_pos = 256, .kohms =   5, },
> +	[MCP465x_103] = { .wipers = 2, .max_pos = 256, .kohms =  10, },
> +	[MCP465x_503] = { .wipers = 2, .max_pos = 256, .kohms =  50, },
> +	[MCP465x_104] = { .wipers = 2, .max_pos = 256, .kohms = 100, },
> +};
> +
> +#define MCP4531_WRITE (0 << 2)
> +#define MCP4531_INCR  (1 << 2)
> +#define MCP4531_DECR  (2 << 2)
> +#define MCP4531_READ  (3 << 2)
> +
> +#define MCP4531_WIPER_SHIFT (4)
> +
> +struct mcp4531_data {
> +	struct i2c_client *client;
> +	unsigned long devid;
> +};
> +
> +#define MCP4531_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 mcp4531_channels[] = {
> +	MCP4531_CHANNEL(0),
> +	MCP4531_CHANNEL(1),
> +};
> +
> +static int mcp4531_read_raw(struct iio_dev *indio_dev,
> +			    struct iio_chan_spec const *chan,
> +			    int *val, int *val2, long mask)
> +{
> +	struct mcp4531_data *data = iio_priv(indio_dev);
> +	int address = chan->channel << MCP4531_WIPER_SHIFT;
> +	s32 ret;
> +
> +	switch (mask) {
> +	case IIO_CHAN_INFO_RAW:
> +		ret = i2c_smbus_read_word_swapped(data->client,
> +						  MCP4531_READ | address);
> +		if (ret < 0)
> +			return ret;
> +		*val = ret;
> +		return IIO_VAL_INT;
> +	case IIO_CHAN_INFO_SCALE:
> +		*val = 1000 * mcp4531_cfg[data->devid].kohms;
> +		*val2 = mcp4531_cfg[data->devid].max_pos;
> +		return IIO_VAL_FRACTIONAL;
> +	}
> +
> +	return -EINVAL;
> +}
> +
> +static int mcp4531_write_raw(struct iio_dev *indio_dev,
> +			     struct iio_chan_spec const *chan,
> +			     int val, int val2, long mask)
> +{
> +	struct mcp4531_data *data = iio_priv(indio_dev);
> +	int address = chan->channel << MCP4531_WIPER_SHIFT;
> +
> +	switch (mask) {
> +	case IIO_CHAN_INFO_RAW:
> +		if (val > mcp4531_cfg[data->devid].max_pos || val < 0)
> +			return -EINVAL;
> +		break;
> +	default:
> +		return -EINVAL;
> +	}
> +
> +	return i2c_smbus_write_byte_data(data->client,
> +					 MCP4531_WRITE | address | (val >> 8),
> +					 val & 0xff);
> +}
> +
> +static const struct iio_info mcp4531_info = {
> +	.read_raw = mcp4531_read_raw,
> +	.write_raw = mcp4531_write_raw,
> +	.driver_module = THIS_MODULE,
> +};
> +
> +static int mcp4531_probe(struct i2c_client *client,
> +			 const struct i2c_device_id *id)
> +{
> +	struct device *dev = &client->dev;
> +	unsigned long devid = id->driver_data;
> +	struct mcp4531_data *data;
> +	struct iio_dev *indio_dev;
> +
> +	if (!i2c_check_functionality(client->adapter,
> +				     I2C_FUNC_SMBUS_WORD_DATA)) {
> +		dev_err(dev, "SMBUS Word Data not supported\n");
> +		return -EIO;
> +	}
> +
> +	indio_dev = devm_iio_device_alloc(dev, sizeof(*data));
> +	if (!indio_dev)
> +		return -ENOMEM;
> +	data = iio_priv(indio_dev);
> +	i2c_set_clientdata(client, indio_dev);
> +	data->client = client;
> +	data->devid = devid;
> +
> +	indio_dev->dev.parent = dev;
> +	indio_dev->info = &mcp4531_info;
> +	indio_dev->channels = mcp4531_channels;
> +	indio_dev->num_channels = mcp4531_cfg[devid].wipers;
> +	indio_dev->name = client->name;
> +
> +	return devm_iio_device_register(dev, indio_dev);
> +}
> +
> +static const struct i2c_device_id mcp4531_id[] = {
> +	{ "mcp4531-502", MCP453x_502 },
> +	{ "mcp4531-103", MCP453x_103 },
> +	{ "mcp4531-503", MCP453x_503 },
> +	{ "mcp4531-104", MCP453x_104 },
> +	{ "mcp4532-502", MCP453x_502 },
> +	{ "mcp4532-103", MCP453x_103 },
> +	{ "mcp4532-503", MCP453x_503 },
> +	{ "mcp4532-104", MCP453x_104 },
> +	{ "mcp4551-502", MCP455x_502 },
> +	{ "mcp4551-103", MCP455x_103 },
> +	{ "mcp4551-503", MCP455x_503 },
> +	{ "mcp4551-104", MCP455x_104 },
> +	{ "mcp4552-502", MCP455x_502 },
> +	{ "mcp4552-103", MCP455x_103 },
> +	{ "mcp4552-503", MCP455x_503 },
> +	{ "mcp4552-104", MCP455x_104 },
> +	{ "mcp4631-502", MCP463x_502 },
> +	{ "mcp4631-103", MCP463x_103 },
> +	{ "mcp4631-503", MCP463x_503 },
> +	{ "mcp4631-104", MCP463x_104 },
> +	{ "mcp4632-502", MCP463x_502 },
> +	{ "mcp4632-103", MCP463x_103 },
> +	{ "mcp4632-503", MCP463x_503 },
> +	{ "mcp4632-104", MCP463x_104 },
> +	{ "mcp4651-502", MCP465x_502 },
> +	{ "mcp4651-103", MCP465x_103 },
> +	{ "mcp4651-503", MCP465x_503 },
> +	{ "mcp4651-104", MCP465x_104 },
> +	{ "mcp4652-502", MCP465x_502 },
> +	{ "mcp4652-103", MCP465x_103 },
> +	{ "mcp4652-503", MCP465x_503 },
> +	{ "mcp4652-104", MCP465x_104 },
> +	{}
> +};
> +MODULE_DEVICE_TABLE(i2c, mcp4531_id);
> +
> +static struct i2c_driver mcp4531_driver = {
> +	.driver = {
> +		.name	= "mcp4531",
> +	},
> +	.probe		= mcp4531_probe,
> +	.id_table	= mcp4531_id,
> +};
> +
> +module_i2c_driver(mcp4531_driver);
> +
> +MODULE_AUTHOR("Peter Rosin <peda@axentia.se>");
> +MODULE_DESCRIPTION("MCP4531 digital potentiometer");
> +MODULE_LICENSE("GPL");
> 


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v6 2/2] iio: mcp4531: Driver for Microchip digital potentiometers
  2015-09-27 15:50   ` Jonathan Cameron
@ 2015-09-28  7:59     ` Peter Rosin
  2015-09-28  8:11       ` Daniel Baluta
  0 siblings, 1 reply; 8+ messages in thread
From: Peter Rosin @ 2015-09-28  7:59 UTC (permalink / raw)
  To: Jonathan Cameron, linux-iio; +Cc: Peter Rosin, linux-kernel

On 2015-09-27 17:50, Jonathan Cameron wrote:
> On 23/09/15 15:26, Peter Rosin wrote:
>> From: Peter Rosin <peda@axentia.se>
>>
>> Add support for Microchip digital potentiometers and rheostats
>> 	MCP4531, MCP4532, MCP4551, MCP4552
>> 	MCP4631, MCP4632, MCP4651, MCP4652
>>
>> DEVICE   Wipers  Steps  Resistor Opts (kOhm)  i2c address
>> MCP4531  1       129    5, 10, 50, 100        010111x
>> MCP4532  1       129    5, 10, 50, 100        01011xx
>> MCP4551  1       257    5, 10, 50, 100        010111x
>> MCP4552  1       257    5, 10, 50, 100        01011xx
>> MCP4631  2       129    5, 10, 50, 100        0101xxx
>> MCP4632  2       129    5, 10, 50, 100        01011xx
>> MCP4651  2       257    5, 10, 50, 100        0101xxx
>> MCP4652  2       257    5, 10, 50, 100        01011xx
>>
>> Datasheet: http://www.microchip.com/downloads/en/DeviceDoc/22096b.pdf
> Applied to the togreg branch of iio.git - initially pushed out as
> testing for the autobuilders to play with it.
> 
> If anyone wants to add reviewed-by / acked-by then as I'll be
> rebasing sometime in next few days anyway there is still time!

Great, thanks,

but I don't see this where I expected it[1]. So, the question is if I'm
too impatient, if am I looking in the wrong place or if you perhaps forgot
to actually push it out? Or if something went totally wrong and the patches
got lost...

Cheers,
Peter

[1] http://git.kernel.org/cgit/linux/kernel/git/jic23/iio.git

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v6 2/2] iio: mcp4531: Driver for Microchip digital potentiometers
  2015-09-28  7:59     ` Peter Rosin
@ 2015-09-28  8:11       ` Daniel Baluta
       [not found]         ` <A33F263C-A366-4ED3-AA62-F464C02F4232@jic23.retrosnub.co.uk>
  0 siblings, 1 reply; 8+ messages in thread
From: Daniel Baluta @ 2015-09-28  8:11 UTC (permalink / raw)
  To: Peter Rosin
  Cc: Jonathan Cameron, linux-iio, Peter Rosin, Linux Kernel Mailing List

On Mon, Sep 28, 2015 at 10:59 AM, Peter Rosin <peda@lysator.liu.se> wrote:
> On 2015-09-27 17:50, Jonathan Cameron wrote:
>> On 23/09/15 15:26, Peter Rosin wrote:
>>> From: Peter Rosin <peda@axentia.se>
>>>
>>> Add support for Microchip digital potentiometers and rheostats
>>>      MCP4531, MCP4532, MCP4551, MCP4552
>>>      MCP4631, MCP4632, MCP4651, MCP4652
>>>
>>> DEVICE   Wipers  Steps  Resistor Opts (kOhm)  i2c address
>>> MCP4531  1       129    5, 10, 50, 100        010111x
>>> MCP4532  1       129    5, 10, 50, 100        01011xx
>>> MCP4551  1       257    5, 10, 50, 100        010111x
>>> MCP4552  1       257    5, 10, 50, 100        01011xx
>>> MCP4631  2       129    5, 10, 50, 100        0101xxx
>>> MCP4632  2       129    5, 10, 50, 100        01011xx
>>> MCP4651  2       257    5, 10, 50, 100        0101xxx
>>> MCP4652  2       257    5, 10, 50, 100        01011xx
>>>
>>> Datasheet: http://www.microchip.com/downloads/en/DeviceDoc/22096b.pdf
>> Applied to the togreg branch of iio.git - initially pushed out as
>> testing for the autobuilders to play with it.
>>
>> If anyone wants to add reviewed-by / acked-by then as I'll be
>> rebasing sometime in next few days anyway there is still time!
>
> Great, thanks,
>
> but I don't see this where I expected it[1]. So, the question is if I'm
> too impatient, if am I looking in the wrong place or if you perhaps forgot
> to actually push it out? Or if something went totally wrong and the patches
> got lost...

Make sure you look for the testing branch. Also, do not worry about this.

Sometimes, Jonathan  pushes the patches locally to his setup and later
syncs with the remote repo.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v6 2/2] iio: mcp4531: Driver for Microchip digital potentiometers
       [not found]         ` <A33F263C-A366-4ED3-AA62-F464C02F4232@jic23.retrosnub.co.uk>
@ 2015-09-28 21:15           ` Jonathan Cameron
  0 siblings, 0 replies; 8+ messages in thread
From: Jonathan Cameron @ 2015-09-28 21:15 UTC (permalink / raw)
  To: Jonathan Cameron, Daniel Baluta, Peter Rosin
  Cc: linux-iio, Peter Rosin, Linux Kernel Mailing List

On 28/09/15 10:01, Jonathan Cameron wrote:
> 
> 
> On 28 September 2015 09:11:09 BST, Daniel Baluta <daniel.baluta@gmail.com> wrote:
> 
>     On Mon, Sep 28, 2015 at 10:59 AM, Peter Rosin <peda@lysator.liu.se> wrote:
> 
>         On 2015-09-27 17:50, Jonathan Cameron wrote:
> 
>             On 23/09/15 15:26, Peter Rosin wrote:
> 
>                 From: Peter Rosin <peda@axentia.se>
> 
>                 Add support for Microchip digital potentiometers and rheostats
>                 MCP4531, MCP4532, MCP4551, MCP4552
>                 MCP4631, MCP4632, MCP4651, MCP4652
> 
>                 DEVICE Wipers Steps Resistor Opts (kOhm) i2c address
>                 MCP4531 1 129 5, 10, 50, 100 010111x
>                 MCP4532 1 129 5, 10, 50, 100 01011xx
>                 MCP4551 1 257 5, 10 , 50, 100 010111x
>                 MCP4552 1 257 5, 10, 50, 100 01011xx
>                 MCP4631 2 129 5, 10, 50, 100 0101xxx
>                 MCP4632 2 129 5, 10, 50, 100 01011xx
>                 MCP4651 2 257 5, 10, 50, 100 0101xxx
>                 MCP4652 2 257 5, 10, 50, 100 01011xx
> 
>                 Datasheet: http://www.microchip.com/downloads/en/DeviceDoc/22096b.pdf
> 
>             Applied to the togreg branch of iio.git - initially pushed out as
>             testing for the autobuilders to play with it.
> 
>             If anyone wants to add reviewed-by / acked-by then as I'll be
>             rebasing sometime in next few days anyway there is still time!
> 
> 
>         Great, thanks,
> 
>         but I don't see this where I expected it[1]. So, the question is if I'm
>         too impatient, if am I looking in the wrong place or if you perhaps forgot
>         to actually push it out? Or if something went totally wrong and the patches
>         got lost...
> 
> 
>     Make sure you look for the testing branch. Also, do not worry about this.
> 
>     Sometimes, Jonathan  pushes the patches locally to his setup and later
>     syncs with the remote repo.
> 
> 
> What Daniel is politely saying is sometimes I forget to push them out!
> Oops. Machine is at home and powered down so should push testing branch this
> evening if I remember.
Should be there (in the testing branch) now.


J
> 
> -- 
> Sent from my Android device with K-9 Mail. Please excuse my brevity.


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2015-09-28 21:15 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-23 14:26 [PATCH v6 0/2] Driver for Microchip digital potentiometers Peter Rosin
2015-09-23 14:26 ` [PATCH v6 1/2] iio: resistance: Document that resistance can be output Peter Rosin
2015-09-27 15:46   ` Jonathan Cameron
2015-09-23 14:26 ` [PATCH v6 2/2] iio: mcp4531: Driver for Microchip digital potentiometers Peter Rosin
2015-09-27 15:50   ` Jonathan Cameron
2015-09-28  7:59     ` Peter Rosin
2015-09-28  8:11       ` Daniel Baluta
     [not found]         ` <A33F263C-A366-4ED3-AA62-F464C02F4232@jic23.retrosnub.co.uk>
2015-09-28 21:15           ` 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).