All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] IIO: DAC: AD5446: Add missing ID table entries
@ 2011-03-10 11:52 michael.hennerich
  2011-03-10 11:52 ` [PATCH 2/3] IIO: DAC: AD5446: Add power down support michael.hennerich
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: michael.hennerich @ 2011-03-10 11:52 UTC (permalink / raw)
  To: jic23; +Cc: linux-iio, drivers, device-drivers-devel, Michael Hennerich

From: Michael Hennerich <michael.hennerich@analog.com>


Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
---
 drivers/staging/iio/dac/ad5446.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/drivers/staging/iio/dac/ad5446.c b/drivers/staging/iio/dac/ad5446.c
index dcec297..4f1d881 100644
--- a/drivers/staging/iio/dac/ad5446.c
+++ b/drivers/staging/iio/dac/ad5446.c
@@ -295,8 +295,10 @@ static int ad5446_remove(struct spi_device *spi)
 static const struct spi_device_id ad5446_id[] = {
 	{"ad5444", ID_AD5444},
 	{"ad5446", ID_AD5446},
-	{"ad5542a", ID_AD5542A},
 	{"ad5512a", ID_AD5512A},
+	{"ad5542a", ID_AD5542A},
+	{"ad5543", ID_AD5543},
+	{"ad5553", ID_AD5553},
 	{"ad5620-2500", ID_AD5620_2500}, /* AD5620/40/60: */
 	{"ad5620-1250", ID_AD5620_1250}, /* part numbers may look differently */
 	{"ad5640-2500", ID_AD5640_2500},
-- 
1.6.0.2

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

* [PATCH 2/3] IIO: DAC: AD5446: Add power down support
  2011-03-10 11:52 [PATCH 1/3] IIO: DAC: AD5446: Add missing ID table entries michael.hennerich
@ 2011-03-10 11:52 ` michael.hennerich
  2011-03-10 12:10   ` Jonathan Cameron
  2011-03-10 11:52 ` [PATCH 3/3] IIO: DAC: AD5446: Add support for AD5601/AD5611/AD5621 michael.hennerich
  2011-03-10 12:08 ` [PATCH 1/3] IIO: DAC: AD5446: Add missing ID table entries Jonathan Cameron
  2 siblings, 1 reply; 7+ messages in thread
From: michael.hennerich @ 2011-03-10 11:52 UTC (permalink / raw)
  To: jic23; +Cc: linux-iio, drivers, device-drivers-devel, Michael Hennerich

From: Michael Hennerich <michael.hennerich@analog.com>


Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
---
 drivers/staging/iio/dac/ad5446.c |  153 ++++++++++++++++++++++++++++++++++----
 drivers/staging/iio/dac/ad5446.h |   19 ++++-
 2 files changed, 153 insertions(+), 19 deletions(-)

diff --git a/drivers/staging/iio/dac/ad5446.c b/drivers/staging/iio/dac/ad5446.c
index 4f1d881..861a7ea 100644
--- a/drivers/staging/iio/dac/ad5446.c
+++ b/drivers/staging/iio/dac/ad5446.c
@@ -48,6 +48,20 @@ static void ad5660_store_sample(struct ad5446_state *st, unsigned val)
 	st->data.d24[2] = val & 0xFF;
 }
 
+static void ad5620_store_pwr_down(struct ad5446_state *st, unsigned mode)
+{
+	st->data.d16 = cpu_to_be16(mode << 14);
+}
+
+static void ad5660_store_pwr_down(struct ad5446_state *st, unsigned mode)
+{
+	unsigned val = mode << 16;
+
+	st->data.d24[0] = (val >> 16) & 0xFF;
+	st->data.d24[1] = (val >> 8) & 0xFF;
+	st->data.d24[2] = val & 0xFF;
+}
+
 static ssize_t ad5446_write(struct device *dev,
 		struct device_attribute *attr,
 		const char *buf,
@@ -68,6 +82,7 @@ static ssize_t ad5446_write(struct device *dev,
 	}
 
 	mutex_lock(&dev_info->mlock);
+	st->cached_val = val;
 	st->chip_info->store_sample(st, val);
 	ret = spi_sync(st->spi, &st->msg);
 	mutex_unlock(&dev_info->mlock);
@@ -102,15 +117,119 @@ static ssize_t ad5446_show_name(struct device *dev,
 }
 static IIO_DEVICE_ATTR(name, S_IRUGO, ad5446_show_name, NULL, 0);
 
+static ssize_t ad5446_write_powerdown_mode(struct device *dev,
+				       struct device_attribute *attr,
+				       const char *buf, size_t len)
+{
+	struct iio_dev *dev_info = dev_get_drvdata(dev);
+	struct ad5446_state *st = dev_info->dev_data;
+
+	if (sysfs_streq(buf, "1kohm_to_gnd"))
+		st->pwr_down_mode = MODE_PWRDWN_1k;
+	else if (sysfs_streq(buf, "100kohm_to_gnd"))
+		st->pwr_down_mode = MODE_PWRDWN_100k;
+	else if (sysfs_streq(buf, "three_state"))
+		st->pwr_down_mode = MODE_PWRDWN_TRISTATE;
+	else
+		return -EINVAL;
+
+	return len;
+}
+
+static ssize_t ad5446_read_powerdown_mode(struct device *dev,
+				      struct device_attribute *attr, char *buf)
+{
+	struct iio_dev *dev_info = dev_get_drvdata(dev);
+	struct ad5446_state *st = dev_info->dev_data;
+
+	char mode[][15] = {"", "1kohm_to_gnd", "100kohm_to_gnd", "three_state"};
+
+	return sprintf(buf, "%s\n", mode[st->pwr_down_mode]);
+}
+
+static ssize_t ad5446_read_dac_powerdown(struct device *dev,
+					   struct device_attribute *attr,
+					   char *buf)
+{
+	struct iio_dev *dev_info = dev_get_drvdata(dev);
+	struct ad5446_state *st = dev_info->dev_data;
+
+	return sprintf(buf, "%d\n", st->pwr_down);
+}
+
+static ssize_t ad5446_write_dac_powerdown(struct device *dev,
+					    struct device_attribute *attr,
+					    const char *buf, size_t len)
+{
+	struct iio_dev *dev_info = dev_get_drvdata(dev);
+	struct ad5446_state *st = dev_info->dev_data;
+	unsigned long readin;
+	int ret;
+
+	ret = strict_strtol(buf, 10, &readin);
+	if (ret)
+		return ret;
+
+	if (readin > 1)
+		ret = -EINVAL;
+
+	mutex_lock(&dev_info->mlock);
+	st->pwr_down = readin;
+
+	if (st->pwr_down)
+		st->chip_info->store_pwr_down(st, st->pwr_down_mode);
+	else
+		st->chip_info->store_sample(st, st->cached_val);
+
+	ret = spi_sync(st->spi, &st->msg);
+	mutex_unlock(&dev_info->mlock);
+
+	return ret ? ret : len;
+}
+
+static IIO_DEVICE_ATTR(out_powerdown_mode, S_IRUGO | S_IWUSR,
+			ad5446_read_powerdown_mode,
+			ad5446_write_powerdown_mode, 0);
+
+static IIO_CONST_ATTR(out_powerdown_mode_available,
+			"1kohm_to_gnd 100kohm_to_gnd three_state");
+
+static IIO_DEVICE_ATTR(out0_powerdown, S_IRUGO | S_IWUSR,
+			ad5446_read_dac_powerdown,
+			ad5446_write_dac_powerdown, 0);
+
 static struct attribute *ad5446_attributes[] = {
 	&iio_dev_attr_out0_raw.dev_attr.attr,
 	&iio_dev_attr_out_scale.dev_attr.attr,
+	&iio_dev_attr_out0_powerdown.dev_attr.attr,
+	&iio_dev_attr_out_powerdown_mode.dev_attr.attr,
+	&iio_const_attr_out_powerdown_mode_available.dev_attr.attr,
 	&iio_dev_attr_name.dev_attr.attr,
 	NULL,
 };
 
+static mode_t ad5446_attr_is_visible(struct kobject *kobj,
+				     struct attribute *attr, int n)
+{
+	struct device *dev = container_of(kobj, struct device, kobj);
+	struct iio_dev *dev_info = dev_get_drvdata(dev);
+	struct ad5446_state *st = iio_dev_get_devdata(dev_info);
+
+	mode_t mode = attr->mode;
+
+	if (!st->chip_info->store_pwr_down &&
+		(attr == &iio_dev_attr_out0_powerdown.dev_attr.attr ||
+		attr == &iio_dev_attr_out_powerdown_mode.dev_attr.attr ||
+		attr ==
+		&iio_const_attr_out_powerdown_mode_available.dev_attr.attr))
+		mode = 0;
+
+	return mode;
+}
+
 static const struct attribute_group ad5446_attribute_group = {
 	.attrs = ad5446_attributes,
+	.is_visible = ad5446_attr_is_visible,
 };
 
 static const struct ad5446_chip_info ad5446_chip_info_tbl[] = {
@@ -156,6 +275,7 @@ static const struct ad5446_chip_info ad5446_chip_info_tbl[] = {
 		.left_shift = 2,
 		.int_vref_mv = 2500,
 		.store_sample = ad5620_store_sample,
+		.store_pwr_down = ad5620_store_pwr_down,
 	},
 	[ID_AD5620_1250] = {
 		.bits = 12,
@@ -163,6 +283,7 @@ static const struct ad5446_chip_info ad5446_chip_info_tbl[] = {
 		.left_shift = 2,
 		.int_vref_mv = 1250,
 		.store_sample = ad5620_store_sample,
+		.store_pwr_down = ad5620_store_pwr_down,
 	},
 	[ID_AD5640_2500] = {
 		.bits = 14,
@@ -170,6 +291,7 @@ static const struct ad5446_chip_info ad5446_chip_info_tbl[] = {
 		.left_shift = 0,
 		.int_vref_mv = 2500,
 		.store_sample = ad5620_store_sample,
+		.store_pwr_down = ad5620_store_pwr_down,
 	},
 	[ID_AD5640_1250] = {
 		.bits = 14,
@@ -177,6 +299,7 @@ static const struct ad5446_chip_info ad5446_chip_info_tbl[] = {
 		.left_shift = 0,
 		.int_vref_mv = 1250,
 		.store_sample = ad5620_store_sample,
+		.store_pwr_down = ad5620_store_pwr_down,
 	},
 	[ID_AD5660_2500] = {
 		.bits = 16,
@@ -184,6 +307,7 @@ static const struct ad5446_chip_info ad5446_chip_info_tbl[] = {
 		.left_shift = 0,
 		.int_vref_mv = 2500,
 		.store_sample = ad5660_store_sample,
+		.store_pwr_down = ad5660_store_pwr_down,
 	},
 	[ID_AD5660_1250] = {
 		.bits = 16,
@@ -191,6 +315,7 @@ static const struct ad5446_chip_info ad5446_chip_info_tbl[] = {
 		.left_shift = 0,
 		.int_vref_mv = 1250,
 		.store_sample = ad5660_store_sample,
+		.store_pwr_down = ad5660_store_pwr_down,
 	},
 };
 
@@ -243,20 +368,20 @@ static int __devinit ad5446_probe(struct spi_device *spi)
 	spi_message_add_tail(&st->xfer, &st->msg);
 
 	switch (spi_get_device_id(spi)->driver_data) {
-		case ID_AD5620_2500:
-		case ID_AD5620_1250:
-		case ID_AD5640_2500:
-		case ID_AD5640_1250:
-		case ID_AD5660_2500:
-		case ID_AD5660_1250:
-			st->vref_mv = st->chip_info->int_vref_mv;
-			break;
-		default:
-			if (voltage_uv)
-				st->vref_mv = voltage_uv / 1000;
-			else
-				dev_warn(&spi->dev,
-					 "reference voltage unspecified\n");
+	case ID_AD5620_2500:
+	case ID_AD5620_1250:
+	case ID_AD5640_2500:
+	case ID_AD5640_1250:
+	case ID_AD5660_2500:
+	case ID_AD5660_1250:
+		st->vref_mv = st->chip_info->int_vref_mv;
+		break;
+	default:
+		if (voltage_uv)
+			st->vref_mv = voltage_uv / 1000;
+		else
+			dev_warn(&spi->dev,
+				 "reference voltage unspecified\n");
 	}
 
 	ret = iio_device_register(st->indio_dev);
diff --git a/drivers/staging/iio/dac/ad5446.h b/drivers/staging/iio/dac/ad5446.h
index 0cb9c14..e9397a6 100644
--- a/drivers/staging/iio/dac/ad5446.h
+++ b/drivers/staging/iio/dac/ad5446.h
@@ -27,6 +27,10 @@
 
 #define RES_MASK(bits)	((1 << (bits)) - 1)
 
+#define MODE_PWRDWN_1k		0x1
+#define MODE_PWRDWN_100k	0x2
+#define MODE_PWRDWN_TRISTATE	0x3
+
 /**
  * struct ad5446_state - driver instance specific data
  * @indio_dev:		the industrial I/O device
@@ -47,6 +51,9 @@ struct ad5446_state {
 	struct regulator		*reg;
 	struct work_struct		poll_work;
 	unsigned short			vref_mv;
+	unsigned			cached_val;
+	unsigned			pwr_down_mode;
+	unsigned			pwr_down;
 	struct spi_transfer		xfer;
 	struct spi_message		msg;
 	union {
@@ -62,14 +69,16 @@ struct ad5446_state {
  * @left_shift:		number of bits the datum must be shifted
  * @int_vref_mv:	AD5620/40/60: the internal reference voltage
  * @store_sample:	chip specific helper function to store the datum
+ * @store_sample:	chip specific helper function to store the powerpown cmd
  */
 
 struct ad5446_chip_info {
-	u8				bits;
-	u8				storagebits;
-	u8				left_shift;
-	u16				int_vref_mv;
-	void (*store_sample)		(struct ad5446_state *st, unsigned val);
+	u8			bits;
+	u8			storagebits;
+	u8			left_shift;
+	u16			int_vref_mv;
+	void (*store_sample)	(struct ad5446_state *st, unsigned val);
+	void (*store_pwr_down)	(struct ad5446_state *st, unsigned mode);
 };
 
 /**
-- 
1.6.0.2

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

* [PATCH 3/3] IIO: DAC: AD5446: Add support for AD5601/AD5611/AD5621
  2011-03-10 11:52 [PATCH 1/3] IIO: DAC: AD5446: Add missing ID table entries michael.hennerich
  2011-03-10 11:52 ` [PATCH 2/3] IIO: DAC: AD5446: Add power down support michael.hennerich
@ 2011-03-10 11:52 ` michael.hennerich
  2011-03-10 12:14   ` Jonathan Cameron
  2011-03-10 12:08 ` [PATCH 1/3] IIO: DAC: AD5446: Add missing ID table entries Jonathan Cameron
  2 siblings, 1 reply; 7+ messages in thread
From: michael.hennerich @ 2011-03-10 11:52 UTC (permalink / raw)
  To: jic23; +Cc: linux-iio, drivers, device-drivers-devel, Michael Hennerich

From: Michael Hennerich <michael.hennerich@analog.com>

This patch adds support for the AD5601/AD5611/AD5621 single channel,
8-/10-/12-bit, buffered voltage output DACs.

Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
---
 drivers/staging/iio/dac/Kconfig  |    3 ++-
 drivers/staging/iio/dac/ad5446.c |   24 ++++++++++++++++++++++++
 drivers/staging/iio/dac/ad5446.h |    3 +++
 3 files changed, 29 insertions(+), 1 deletions(-)

diff --git a/drivers/staging/iio/dac/Kconfig b/drivers/staging/iio/dac/Kconfig
index 3c72871..9539545 100644
--- a/drivers/staging/iio/dac/Kconfig
+++ b/drivers/staging/iio/dac/Kconfig
@@ -15,7 +15,8 @@ config AD5446
 	depends on SPI
 	help
 	  Say yes here to build support for Analog Devices AD5444, AD5446,
-	  AD5512A, AD5542A, AD5543, AD5553, AD5620, AD5640, AD5660 DACs.
+	  AD5512A, AD5542A, AD5543, AD5553, AD5601, AD5611, AD5621, AD5620,
+	  AD5640, AD5660 DACs.
 
 	  To compile this driver as a module, choose M here: the
 	  module will be called ad5446.
diff --git a/drivers/staging/iio/dac/ad5446.c b/drivers/staging/iio/dac/ad5446.c
index 861a7ea..8623a72 100644
--- a/drivers/staging/iio/dac/ad5446.c
+++ b/drivers/staging/iio/dac/ad5446.c
@@ -269,6 +269,27 @@ static const struct ad5446_chip_info ad5446_chip_info_tbl[] = {
 		.left_shift = 0,
 		.store_sample = ad5542_store_sample,
 	},
+	[ID_AD5601] = {
+		.bits = 8,
+		.storagebits = 16,
+		.left_shift = 6,
+		.store_sample = ad5542_store_sample,
+		.store_pwr_down = ad5620_store_pwr_down,
+	},
+	[ID_AD5611] = {
+		.bits = 10,
+		.storagebits = 16,
+		.left_shift = 4,
+		.store_sample = ad5542_store_sample,
+		.store_pwr_down = ad5620_store_pwr_down,
+	},
+	[ID_AD5621] = {
+		.bits = 12,
+		.storagebits = 16,
+		.left_shift = 2,
+		.store_sample = ad5542_store_sample,
+		.store_pwr_down = ad5620_store_pwr_down,
+	},
 	[ID_AD5620_2500] = {
 		.bits = 12,
 		.storagebits = 16,
@@ -424,6 +445,9 @@ static const struct spi_device_id ad5446_id[] = {
 	{"ad5542a", ID_AD5542A},
 	{"ad5543", ID_AD5543},
 	{"ad5553", ID_AD5553},
+	{"ad5601", ID_AD5601},
+	{"ad5611", ID_AD5611},
+	{"ad5621", ID_AD5621},
 	{"ad5620-2500", ID_AD5620_2500}, /* AD5620/40/60: */
 	{"ad5620-1250", ID_AD5620_1250}, /* part numbers may look differently */
 	{"ad5640-2500", ID_AD5640_2500},
diff --git a/drivers/staging/iio/dac/ad5446.h b/drivers/staging/iio/dac/ad5446.h
index e9397a6..7ac63ab 100644
--- a/drivers/staging/iio/dac/ad5446.h
+++ b/drivers/staging/iio/dac/ad5446.h
@@ -96,6 +96,9 @@ enum ad5446_supported_device_ids {
 	ID_AD5543,
 	ID_AD5512A,
 	ID_AD5553,
+	ID_AD5601,
+	ID_AD5611,
+	ID_AD5621,
 	ID_AD5620_2500,
 	ID_AD5620_1250,
 	ID_AD5640_2500,
-- 
1.6.0.2

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

* Re: [PATCH 1/3] IIO: DAC: AD5446: Add missing ID table entries
  2011-03-10 11:52 [PATCH 1/3] IIO: DAC: AD5446: Add missing ID table entries michael.hennerich
  2011-03-10 11:52 ` [PATCH 2/3] IIO: DAC: AD5446: Add power down support michael.hennerich
  2011-03-10 11:52 ` [PATCH 3/3] IIO: DAC: AD5446: Add support for AD5601/AD5611/AD5621 michael.hennerich
@ 2011-03-10 12:08 ` Jonathan Cameron
  2 siblings, 0 replies; 7+ messages in thread
From: Jonathan Cameron @ 2011-03-10 12:08 UTC (permalink / raw)
  To: michael.hennerich; +Cc: linux-iio, drivers, device-drivers-devel

On 03/10/11 11:52, michael.hennerich@analog.com wrote:
> From: Michael Hennerich <michael.hennerich@analog.com>
> 
> 
> Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
Acked-by: Jonathan Cameron <jic23@cam.ac.uk>
> ---
>  drivers/staging/iio/dac/ad5446.c |    4 +++-
>  1 files changed, 3 insertions(+), 1 deletions(-)
> 
> diff --git a/drivers/staging/iio/dac/ad5446.c b/drivers/staging/iio/dac/ad5446.c
> index dcec297..4f1d881 100644
> --- a/drivers/staging/iio/dac/ad5446.c
> +++ b/drivers/staging/iio/dac/ad5446.c
> @@ -295,8 +295,10 @@ static int ad5446_remove(struct spi_device *spi)
>  static const struct spi_device_id ad5446_id[] = {
>  	{"ad5444", ID_AD5444},
>  	{"ad5446", ID_AD5446},
> -	{"ad5542a", ID_AD5542A},
>  	{"ad5512a", ID_AD5512A},
> +	{"ad5542a", ID_AD5542A},
> +	{"ad5543", ID_AD5543},
> +	{"ad5553", ID_AD5553},
>  	{"ad5620-2500", ID_AD5620_2500}, /* AD5620/40/60: */
>  	{"ad5620-1250", ID_AD5620_1250}, /* part numbers may look differently */
>  	{"ad5640-2500", ID_AD5640_2500},


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

* Re: [PATCH 2/3] IIO: DAC: AD5446: Add power down support
  2011-03-10 11:52 ` [PATCH 2/3] IIO: DAC: AD5446: Add power down support michael.hennerich
@ 2011-03-10 12:10   ` Jonathan Cameron
  0 siblings, 0 replies; 7+ messages in thread
From: Jonathan Cameron @ 2011-03-10 12:10 UTC (permalink / raw)
  To: michael.hennerich; +Cc: linux-iio, drivers, device-drivers-devel

On 03/10/11 11:52, michael.hennerich@analog.com wrote:
> From: Michael Hennerich <michael.hennerich@analog.com>
> 
> 
> Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
Acked-by: Jonathan Cameron <jic23@cam.ac.uk>
> ---
>  drivers/staging/iio/dac/ad5446.c |  153 ++++++++++++++++++++++++++++++++++----
>  drivers/staging/iio/dac/ad5446.h |   19 ++++-
>  2 files changed, 153 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/staging/iio/dac/ad5446.c b/drivers/staging/iio/dac/ad5446.c
> index 4f1d881..861a7ea 100644
> --- a/drivers/staging/iio/dac/ad5446.c
> +++ b/drivers/staging/iio/dac/ad5446.c
> @@ -48,6 +48,20 @@ static void ad5660_store_sample(struct ad5446_state *st, unsigned val)
>  	st->data.d24[2] = val & 0xFF;
>  }
>  
> +static void ad5620_store_pwr_down(struct ad5446_state *st, unsigned mode)
> +{
> +	st->data.d16 = cpu_to_be16(mode << 14);
> +}
> +
> +static void ad5660_store_pwr_down(struct ad5446_state *st, unsigned mode)
> +{
> +	unsigned val = mode << 16;
> +
> +	st->data.d24[0] = (val >> 16) & 0xFF;
> +	st->data.d24[1] = (val >> 8) & 0xFF;
> +	st->data.d24[2] = val & 0xFF;
> +}
> +
>  static ssize_t ad5446_write(struct device *dev,
>  		struct device_attribute *attr,
>  		const char *buf,
> @@ -68,6 +82,7 @@ static ssize_t ad5446_write(struct device *dev,
>  	}
>  
>  	mutex_lock(&dev_info->mlock);
> +	st->cached_val = val;
>  	st->chip_info->store_sample(st, val);
>  	ret = spi_sync(st->spi, &st->msg);
>  	mutex_unlock(&dev_info->mlock);
> @@ -102,15 +117,119 @@ static ssize_t ad5446_show_name(struct device *dev,
>  }
>  static IIO_DEVICE_ATTR(name, S_IRUGO, ad5446_show_name, NULL, 0);
>  
> +static ssize_t ad5446_write_powerdown_mode(struct device *dev,
> +				       struct device_attribute *attr,
> +				       const char *buf, size_t len)
> +{
> +	struct iio_dev *dev_info = dev_get_drvdata(dev);
> +	struct ad5446_state *st = dev_info->dev_data;
> +
> +	if (sysfs_streq(buf, "1kohm_to_gnd"))
> +		st->pwr_down_mode = MODE_PWRDWN_1k;
> +	else if (sysfs_streq(buf, "100kohm_to_gnd"))
> +		st->pwr_down_mode = MODE_PWRDWN_100k;
> +	else if (sysfs_streq(buf, "three_state"))
> +		st->pwr_down_mode = MODE_PWRDWN_TRISTATE;
> +	else
> +		return -EINVAL;
> +
> +	return len;
> +}
> +
> +static ssize_t ad5446_read_powerdown_mode(struct device *dev,
> +				      struct device_attribute *attr, char *buf)
> +{
> +	struct iio_dev *dev_info = dev_get_drvdata(dev);
> +	struct ad5446_state *st = dev_info->dev_data;
> +
> +	char mode[][15] = {"", "1kohm_to_gnd", "100kohm_to_gnd", "three_state"};
> +
> +	return sprintf(buf, "%s\n", mode[st->pwr_down_mode]);
> +}
> +
> +static ssize_t ad5446_read_dac_powerdown(struct device *dev,
> +					   struct device_attribute *attr,
> +					   char *buf)
> +{
> +	struct iio_dev *dev_info = dev_get_drvdata(dev);
> +	struct ad5446_state *st = dev_info->dev_data;
> +
> +	return sprintf(buf, "%d\n", st->pwr_down);
> +}
> +
> +static ssize_t ad5446_write_dac_powerdown(struct device *dev,
> +					    struct device_attribute *attr,
> +					    const char *buf, size_t len)
> +{
> +	struct iio_dev *dev_info = dev_get_drvdata(dev);
> +	struct ad5446_state *st = dev_info->dev_data;
> +	unsigned long readin;
> +	int ret;
> +
> +	ret = strict_strtol(buf, 10, &readin);
> +	if (ret)
> +		return ret;
> +
> +	if (readin > 1)
> +		ret = -EINVAL;
> +
> +	mutex_lock(&dev_info->mlock);
> +	st->pwr_down = readin;
> +
> +	if (st->pwr_down)
> +		st->chip_info->store_pwr_down(st, st->pwr_down_mode);
> +	else
> +		st->chip_info->store_sample(st, st->cached_val);
> +
> +	ret = spi_sync(st->spi, &st->msg);
> +	mutex_unlock(&dev_info->mlock);
> +
> +	return ret ? ret : len;
> +}
> +
> +static IIO_DEVICE_ATTR(out_powerdown_mode, S_IRUGO | S_IWUSR,
> +			ad5446_read_powerdown_mode,
> +			ad5446_write_powerdown_mode, 0);
> +
> +static IIO_CONST_ATTR(out_powerdown_mode_available,
> +			"1kohm_to_gnd 100kohm_to_gnd three_state");
> +
> +static IIO_DEVICE_ATTR(out0_powerdown, S_IRUGO | S_IWUSR,
> +			ad5446_read_dac_powerdown,
> +			ad5446_write_dac_powerdown, 0);
> +
>  static struct attribute *ad5446_attributes[] = {
>  	&iio_dev_attr_out0_raw.dev_attr.attr,
>  	&iio_dev_attr_out_scale.dev_attr.attr,
> +	&iio_dev_attr_out0_powerdown.dev_attr.attr,
> +	&iio_dev_attr_out_powerdown_mode.dev_attr.attr,
> +	&iio_const_attr_out_powerdown_mode_available.dev_attr.attr,
>  	&iio_dev_attr_name.dev_attr.attr,
>  	NULL,
>  };
>  
> +static mode_t ad5446_attr_is_visible(struct kobject *kobj,
> +				     struct attribute *attr, int n)
> +{
> +	struct device *dev = container_of(kobj, struct device, kobj);
> +	struct iio_dev *dev_info = dev_get_drvdata(dev);
> +	struct ad5446_state *st = iio_dev_get_devdata(dev_info);
> +
> +	mode_t mode = attr->mode;
> +
> +	if (!st->chip_info->store_pwr_down &&
> +		(attr == &iio_dev_attr_out0_powerdown.dev_attr.attr ||
> +		attr == &iio_dev_attr_out_powerdown_mode.dev_attr.attr ||
> +		attr ==
> +		&iio_const_attr_out_powerdown_mode_available.dev_attr.attr))
> +		mode = 0;
> +
> +	return mode;
> +}
> +
>  static const struct attribute_group ad5446_attribute_group = {
>  	.attrs = ad5446_attributes,
> +	.is_visible = ad5446_attr_is_visible,
>  };
>  
>  static const struct ad5446_chip_info ad5446_chip_info_tbl[] = {
> @@ -156,6 +275,7 @@ static const struct ad5446_chip_info ad5446_chip_info_tbl[] = {
>  		.left_shift = 2,
>  		.int_vref_mv = 2500,
>  		.store_sample = ad5620_store_sample,
> +		.store_pwr_down = ad5620_store_pwr_down,
>  	},
>  	[ID_AD5620_1250] = {
>  		.bits = 12,
> @@ -163,6 +283,7 @@ static const struct ad5446_chip_info ad5446_chip_info_tbl[] = {
>  		.left_shift = 2,
>  		.int_vref_mv = 1250,
>  		.store_sample = ad5620_store_sample,
> +		.store_pwr_down = ad5620_store_pwr_down,
>  	},
>  	[ID_AD5640_2500] = {
>  		.bits = 14,
> @@ -170,6 +291,7 @@ static const struct ad5446_chip_info ad5446_chip_info_tbl[] = {
>  		.left_shift = 0,
>  		.int_vref_mv = 2500,
>  		.store_sample = ad5620_store_sample,
> +		.store_pwr_down = ad5620_store_pwr_down,
>  	},
>  	[ID_AD5640_1250] = {
>  		.bits = 14,
> @@ -177,6 +299,7 @@ static const struct ad5446_chip_info ad5446_chip_info_tbl[] = {
>  		.left_shift = 0,
>  		.int_vref_mv = 1250,
>  		.store_sample = ad5620_store_sample,
> +		.store_pwr_down = ad5620_store_pwr_down,
>  	},
>  	[ID_AD5660_2500] = {
>  		.bits = 16,
> @@ -184,6 +307,7 @@ static const struct ad5446_chip_info ad5446_chip_info_tbl[] = {
>  		.left_shift = 0,
>  		.int_vref_mv = 2500,
>  		.store_sample = ad5660_store_sample,
> +		.store_pwr_down = ad5660_store_pwr_down,
>  	},
>  	[ID_AD5660_1250] = {
>  		.bits = 16,
> @@ -191,6 +315,7 @@ static const struct ad5446_chip_info ad5446_chip_info_tbl[] = {
>  		.left_shift = 0,
>  		.int_vref_mv = 1250,
>  		.store_sample = ad5660_store_sample,
> +		.store_pwr_down = ad5660_store_pwr_down,
>  	},
>  };
>  
> @@ -243,20 +368,20 @@ static int __devinit ad5446_probe(struct spi_device *spi)
>  	spi_message_add_tail(&st->xfer, &st->msg);
>  
>  	switch (spi_get_device_id(spi)->driver_data) {
> -		case ID_AD5620_2500:
> -		case ID_AD5620_1250:
> -		case ID_AD5640_2500:
> -		case ID_AD5640_1250:
> -		case ID_AD5660_2500:
> -		case ID_AD5660_1250:
> -			st->vref_mv = st->chip_info->int_vref_mv;
> -			break;
> -		default:
> -			if (voltage_uv)
> -				st->vref_mv = voltage_uv / 1000;
> -			else
> -				dev_warn(&spi->dev,
> -					 "reference voltage unspecified\n");
> +	case ID_AD5620_2500:
> +	case ID_AD5620_1250:
> +	case ID_AD5640_2500:
> +	case ID_AD5640_1250:
> +	case ID_AD5660_2500:
> +	case ID_AD5660_1250:
> +		st->vref_mv = st->chip_info->int_vref_mv;
> +		break;
> +	default:
> +		if (voltage_uv)
> +			st->vref_mv = voltage_uv / 1000;
> +		else
> +			dev_warn(&spi->dev,
> +				 "reference voltage unspecified\n");
>  	}
>  
>  	ret = iio_device_register(st->indio_dev);
> diff --git a/drivers/staging/iio/dac/ad5446.h b/drivers/staging/iio/dac/ad5446.h
> index 0cb9c14..e9397a6 100644
> --- a/drivers/staging/iio/dac/ad5446.h
> +++ b/drivers/staging/iio/dac/ad5446.h
> @@ -27,6 +27,10 @@
>  
>  #define RES_MASK(bits)	((1 << (bits)) - 1)
>  
> +#define MODE_PWRDWN_1k		0x1
> +#define MODE_PWRDWN_100k	0x2
> +#define MODE_PWRDWN_TRISTATE	0x3
> +
>  /**
>   * struct ad5446_state - driver instance specific data
>   * @indio_dev:		the industrial I/O device
> @@ -47,6 +51,9 @@ struct ad5446_state {
>  	struct regulator		*reg;
>  	struct work_struct		poll_work;
>  	unsigned short			vref_mv;
> +	unsigned			cached_val;
> +	unsigned			pwr_down_mode;
> +	unsigned			pwr_down;
>  	struct spi_transfer		xfer;
>  	struct spi_message		msg;
>  	union {
> @@ -62,14 +69,16 @@ struct ad5446_state {
>   * @left_shift:		number of bits the datum must be shifted
>   * @int_vref_mv:	AD5620/40/60: the internal reference voltage
>   * @store_sample:	chip specific helper function to store the datum
> + * @store_sample:	chip specific helper function to store the powerpown cmd
>   */
>  
>  struct ad5446_chip_info {
> -	u8				bits;
> -	u8				storagebits;
> -	u8				left_shift;
> -	u16				int_vref_mv;
> -	void (*store_sample)		(struct ad5446_state *st, unsigned val);
> +	u8			bits;
> +	u8			storagebits;
> +	u8			left_shift;
> +	u16			int_vref_mv;
> +	void (*store_sample)	(struct ad5446_state *st, unsigned val);
> +	void (*store_pwr_down)	(struct ad5446_state *st, unsigned mode);
>  };
>  
>  /**


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

* Re: [PATCH 3/3] IIO: DAC: AD5446: Add support for AD5601/AD5611/AD5621
  2011-03-10 11:52 ` [PATCH 3/3] IIO: DAC: AD5446: Add support for AD5601/AD5611/AD5621 michael.hennerich
@ 2011-03-10 12:14   ` Jonathan Cameron
  0 siblings, 0 replies; 7+ messages in thread
From: Jonathan Cameron @ 2011-03-10 12:14 UTC (permalink / raw)
  To: michael.hennerich; +Cc: linux-iio, drivers, device-drivers-devel

On 03/10/11 11:52, michael.hennerich@analog.com wrote:
> From: Michael Hennerich <michael.hennerich@analog.com>
> 
> This patch adds support for the AD5601/AD5611/AD5621 single channel,
> 8-/10-/12-bit, buffered voltage output DACs.
> 
Queries on ordering of part numbers in line.  Nitpick though so up to
you whether you want to have them sorted by number or grouped in some
other way.
> Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
Acked-by: Jonathan Cameron <jic23@cam.ac.uk>
> ---
>  drivers/staging/iio/dac/Kconfig  |    3 ++-
>  drivers/staging/iio/dac/ad5446.c |   24 ++++++++++++++++++++++++
>  drivers/staging/iio/dac/ad5446.h |    3 +++
>  3 files changed, 29 insertions(+), 1 deletions(-)
> 
> diff --git a/drivers/staging/iio/dac/Kconfig b/drivers/staging/iio/dac/Kconfig
> index 3c72871..9539545 100644
> --- a/drivers/staging/iio/dac/Kconfig
> +++ b/drivers/staging/iio/dac/Kconfig
> @@ -15,7 +15,8 @@ config AD5446
>  	depends on SPI
>  	help
>  	  Say yes here to build support for Analog Devices AD5444, AD5446,
> -	  AD5512A, AD5542A, AD5543, AD5553, AD5620, AD5640, AD5660 DACs.
> +	  AD5512A, AD5542A, AD5543, AD5553, AD5601, AD5611, AD5621, AD5620,
Slightly odd ordering at end of line above...  If the intent is numerical order
then you'll want to fix that.

> +	  AD5640, AD5660 DACs.
>  
>  	  To compile this driver as a module, choose M here: the
>  	  module will be called ad5446.
> diff --git a/drivers/staging/iio/dac/ad5446.c b/drivers/staging/iio/dac/ad5446.c
> index 861a7ea..8623a72 100644
> --- a/drivers/staging/iio/dac/ad5446.c
> +++ b/drivers/staging/iio/dac/ad5446.c
> @@ -269,6 +269,27 @@ static const struct ad5446_chip_info ad5446_chip_info_tbl[] = {
>  		.left_shift = 0,
>  		.store_sample = ad5542_store_sample,
>  	},
> +	[ID_AD5601] = {
> +		.bits = 8,
> +		.storagebits = 16,
> +		.left_shift = 6,
> +		.store_sample = ad5542_store_sample,
> +		.store_pwr_down = ad5620_store_pwr_down,
> +	},
> +	[ID_AD5611] = {
> +		.bits = 10,
> +		.storagebits = 16,
> +		.left_shift = 4,
> +		.store_sample = ad5542_store_sample,
> +		.store_pwr_down = ad5620_store_pwr_down,
> +	},
Again, is the intent numerical order here?
> +	[ID_AD5621] = {
> +		.bits = 12,
> +		.storagebits = 16,
> +		.left_shift = 2,
> +		.store_sample = ad5542_store_sample,
> +		.store_pwr_down = ad5620_store_pwr_down,
> +	},
>  	[ID_AD5620_2500] = {
>  		.bits = 12,
>  		.storagebits = 16,
> @@ -424,6 +445,9 @@ static const struct spi_device_id ad5446_id[] = {
>  	{"ad5542a", ID_AD5542A},
>  	{"ad5543", ID_AD5543},
>  	{"ad5553", ID_AD5553},
> +	{"ad5601", ID_AD5601},
> +	{"ad5611", ID_AD5611},
> +	{"ad5621", ID_AD5621},
and here?
>  	{"ad5620-2500", ID_AD5620_2500}, /* AD5620/40/60: */
>  	{"ad5620-1250", ID_AD5620_1250}, /* part numbers may look differently */
>  	{"ad5640-2500", ID_AD5640_2500},
> diff --git a/drivers/staging/iio/dac/ad5446.h b/drivers/staging/iio/dac/ad5446.h
> index e9397a6..7ac63ab 100644
> --- a/drivers/staging/iio/dac/ad5446.h
> +++ b/drivers/staging/iio/dac/ad5446.h
> @@ -96,6 +96,9 @@ enum ad5446_supported_device_ids {
>  	ID_AD5543,
>  	ID_AD5512A,
>  	ID_AD5553,
> +	ID_AD5601,
> +	ID_AD5611,
> +	ID_AD5621,
>  	ID_AD5620_2500,
>  	ID_AD5620_1250,
>  	ID_AD5640_2500,


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

* [PATCH 2/3] IIO: DAC: AD5446: Add power down support
  2011-03-10 12:26 michael.hennerich
@ 2011-03-10 12:26 ` michael.hennerich
  0 siblings, 0 replies; 7+ messages in thread
From: michael.hennerich @ 2011-03-10 12:26 UTC (permalink / raw)
  To: greg; +Cc: linux-iio, drivers, jic23, device-drivers-devel,
	Michael Hennerich

From: Michael Hennerich <michael.hennerich@analog.com>


Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
Acked-by: Jonathan Cameron <jic23@cam.ac.uk>
---
 drivers/staging/iio/dac/ad5446.c |  153 ++++++++++++++++++++++++++++++++++----
 drivers/staging/iio/dac/ad5446.h |   19 ++++-
 2 files changed, 153 insertions(+), 19 deletions(-)

diff --git a/drivers/staging/iio/dac/ad5446.c b/drivers/staging/iio/dac/ad5446.c
index 4f1d881..861a7ea 100644
--- a/drivers/staging/iio/dac/ad5446.c
+++ b/drivers/staging/iio/dac/ad5446.c
@@ -48,6 +48,20 @@ static void ad5660_store_sample(struct ad5446_state *st, unsigned val)
 	st->data.d24[2] = val & 0xFF;
 }

+static void ad5620_store_pwr_down(struct ad5446_state *st, unsigned mode)
+{
+	st->data.d16 = cpu_to_be16(mode << 14);
+}
+
+static void ad5660_store_pwr_down(struct ad5446_state *st, unsigned mode)
+{
+	unsigned val = mode << 16;
+
+	st->data.d24[0] = (val >> 16) & 0xFF;
+	st->data.d24[1] = (val >> 8) & 0xFF;
+	st->data.d24[2] = val & 0xFF;
+}
+
 static ssize_t ad5446_write(struct device *dev,
 		struct device_attribute *attr,
 		const char *buf,
@@ -68,6 +82,7 @@ static ssize_t ad5446_write(struct device *dev,
 	}

 	mutex_lock(&dev_info->mlock);
+	st->cached_val = val;
 	st->chip_info->store_sample(st, val);
 	ret = spi_sync(st->spi, &st->msg);
 	mutex_unlock(&dev_info->mlock);
@@ -102,15 +117,119 @@ static ssize_t ad5446_show_name(struct device *dev,
 }
 static IIO_DEVICE_ATTR(name, S_IRUGO, ad5446_show_name, NULL, 0);

+static ssize_t ad5446_write_powerdown_mode(struct device *dev,
+				       struct device_attribute *attr,
+				       const char *buf, size_t len)
+{
+	struct iio_dev *dev_info = dev_get_drvdata(dev);
+	struct ad5446_state *st = dev_info->dev_data;
+
+	if (sysfs_streq(buf, "1kohm_to_gnd"))
+		st->pwr_down_mode = MODE_PWRDWN_1k;
+	else if (sysfs_streq(buf, "100kohm_to_gnd"))
+		st->pwr_down_mode = MODE_PWRDWN_100k;
+	else if (sysfs_streq(buf, "three_state"))
+		st->pwr_down_mode = MODE_PWRDWN_TRISTATE;
+	else
+		return -EINVAL;
+
+	return len;
+}
+
+static ssize_t ad5446_read_powerdown_mode(struct device *dev,
+				      struct device_attribute *attr, char *buf)
+{
+	struct iio_dev *dev_info = dev_get_drvdata(dev);
+	struct ad5446_state *st = dev_info->dev_data;
+
+	char mode[][15] = {"", "1kohm_to_gnd", "100kohm_to_gnd", "three_state"};
+
+	return sprintf(buf, "%s\n", mode[st->pwr_down_mode]);
+}
+
+static ssize_t ad5446_read_dac_powerdown(struct device *dev,
+					   struct device_attribute *attr,
+					   char *buf)
+{
+	struct iio_dev *dev_info = dev_get_drvdata(dev);
+	struct ad5446_state *st = dev_info->dev_data;
+
+	return sprintf(buf, "%d\n", st->pwr_down);
+}
+
+static ssize_t ad5446_write_dac_powerdown(struct device *dev,
+					    struct device_attribute *attr,
+					    const char *buf, size_t len)
+{
+	struct iio_dev *dev_info = dev_get_drvdata(dev);
+	struct ad5446_state *st = dev_info->dev_data;
+	unsigned long readin;
+	int ret;
+
+	ret = strict_strtol(buf, 10, &readin);
+	if (ret)
+		return ret;
+
+	if (readin > 1)
+		ret = -EINVAL;
+
+	mutex_lock(&dev_info->mlock);
+	st->pwr_down = readin;
+
+	if (st->pwr_down)
+		st->chip_info->store_pwr_down(st, st->pwr_down_mode);
+	else
+		st->chip_info->store_sample(st, st->cached_val);
+
+	ret = spi_sync(st->spi, &st->msg);
+	mutex_unlock(&dev_info->mlock);
+
+	return ret ? ret : len;
+}
+
+static IIO_DEVICE_ATTR(out_powerdown_mode, S_IRUGO | S_IWUSR,
+			ad5446_read_powerdown_mode,
+			ad5446_write_powerdown_mode, 0);
+
+static IIO_CONST_ATTR(out_powerdown_mode_available,
+			"1kohm_to_gnd 100kohm_to_gnd three_state");
+
+static IIO_DEVICE_ATTR(out0_powerdown, S_IRUGO | S_IWUSR,
+			ad5446_read_dac_powerdown,
+			ad5446_write_dac_powerdown, 0);
+
 static struct attribute *ad5446_attributes[] = {
 	&iio_dev_attr_out0_raw.dev_attr.attr,
 	&iio_dev_attr_out_scale.dev_attr.attr,
+	&iio_dev_attr_out0_powerdown.dev_attr.attr,
+	&iio_dev_attr_out_powerdown_mode.dev_attr.attr,
+	&iio_const_attr_out_powerdown_mode_available.dev_attr.attr,
 	&iio_dev_attr_name.dev_attr.attr,
 	NULL,
 };

+static mode_t ad5446_attr_is_visible(struct kobject *kobj,
+				     struct attribute *attr, int n)
+{
+	struct device *dev = container_of(kobj, struct device, kobj);
+	struct iio_dev *dev_info = dev_get_drvdata(dev);
+	struct ad5446_state *st = iio_dev_get_devdata(dev_info);
+
+	mode_t mode = attr->mode;
+
+	if (!st->chip_info->store_pwr_down &&
+		(attr == &iio_dev_attr_out0_powerdown.dev_attr.attr ||
+		attr == &iio_dev_attr_out_powerdown_mode.dev_attr.attr ||
+		attr ==
+		&iio_const_attr_out_powerdown_mode_available.dev_attr.attr))
+		mode = 0;
+
+	return mode;
+}
+
 static const struct attribute_group ad5446_attribute_group = {
 	.attrs = ad5446_attributes,
+	.is_visible = ad5446_attr_is_visible,
 };

 static const struct ad5446_chip_info ad5446_chip_info_tbl[] = {
@@ -156,6 +275,7 @@ static const struct ad5446_chip_info ad5446_chip_info_tbl[] = {
 		.left_shift = 2,
 		.int_vref_mv = 2500,
 		.store_sample = ad5620_store_sample,
+		.store_pwr_down = ad5620_store_pwr_down,
 	},
 	[ID_AD5620_1250] = {
 		.bits = 12,
@@ -163,6 +283,7 @@ static const struct ad5446_chip_info ad5446_chip_info_tbl[] = {
 		.left_shift = 2,
 		.int_vref_mv = 1250,
 		.store_sample = ad5620_store_sample,
+		.store_pwr_down = ad5620_store_pwr_down,
 	},
 	[ID_AD5640_2500] = {
 		.bits = 14,
@@ -170,6 +291,7 @@ static const struct ad5446_chip_info ad5446_chip_info_tbl[] = {
 		.left_shift = 0,
 		.int_vref_mv = 2500,
 		.store_sample = ad5620_store_sample,
+		.store_pwr_down = ad5620_store_pwr_down,
 	},
 	[ID_AD5640_1250] = {
 		.bits = 14,
@@ -177,6 +299,7 @@ static const struct ad5446_chip_info ad5446_chip_info_tbl[] = {
 		.left_shift = 0,
 		.int_vref_mv = 1250,
 		.store_sample = ad5620_store_sample,
+		.store_pwr_down = ad5620_store_pwr_down,
 	},
 	[ID_AD5660_2500] = {
 		.bits = 16,
@@ -184,6 +307,7 @@ static const struct ad5446_chip_info ad5446_chip_info_tbl[] = {
 		.left_shift = 0,
 		.int_vref_mv = 2500,
 		.store_sample = ad5660_store_sample,
+		.store_pwr_down = ad5660_store_pwr_down,
 	},
 	[ID_AD5660_1250] = {
 		.bits = 16,
@@ -191,6 +315,7 @@ static const struct ad5446_chip_info ad5446_chip_info_tbl[] = {
 		.left_shift = 0,
 		.int_vref_mv = 1250,
 		.store_sample = ad5660_store_sample,
+		.store_pwr_down = ad5660_store_pwr_down,
 	},
 };

@@ -243,20 +368,20 @@ static int __devinit ad5446_probe(struct spi_device *spi)
 	spi_message_add_tail(&st->xfer, &st->msg);

 	switch (spi_get_device_id(spi)->driver_data) {
-		case ID_AD5620_2500:
-		case ID_AD5620_1250:
-		case ID_AD5640_2500:
-		case ID_AD5640_1250:
-		case ID_AD5660_2500:
-		case ID_AD5660_1250:
-			st->vref_mv = st->chip_info->int_vref_mv;
-			break;
-		default:
-			if (voltage_uv)
-				st->vref_mv = voltage_uv / 1000;
-			else
-				dev_warn(&spi->dev,
-					 "reference voltage unspecified\n");
+	case ID_AD5620_2500:
+	case ID_AD5620_1250:
+	case ID_AD5640_2500:
+	case ID_AD5640_1250:
+	case ID_AD5660_2500:
+	case ID_AD5660_1250:
+		st->vref_mv = st->chip_info->int_vref_mv;
+		break;
+	default:
+		if (voltage_uv)
+			st->vref_mv = voltage_uv / 1000;
+		else
+			dev_warn(&spi->dev,
+				 "reference voltage unspecified\n");
 	}

 	ret = iio_device_register(st->indio_dev);
diff --git a/drivers/staging/iio/dac/ad5446.h b/drivers/staging/iio/dac/ad5446.h
index 0cb9c14..e9397a6 100644
--- a/drivers/staging/iio/dac/ad5446.h
+++ b/drivers/staging/iio/dac/ad5446.h
@@ -27,6 +27,10 @@

 #define RES_MASK(bits)	((1 << (bits)) - 1)

+#define MODE_PWRDWN_1k		0x1
+#define MODE_PWRDWN_100k	0x2
+#define MODE_PWRDWN_TRISTATE	0x3
+
 /**
  * struct ad5446_state - driver instance specific data
  * @indio_dev:		the industrial I/O device
@@ -47,6 +51,9 @@ struct ad5446_state {
 	struct regulator		*reg;
 	struct work_struct		poll_work;
 	unsigned short			vref_mv;
+	unsigned			cached_val;
+	unsigned			pwr_down_mode;
+	unsigned			pwr_down;
 	struct spi_transfer		xfer;
 	struct spi_message		msg;
 	union {
@@ -62,14 +69,16 @@ struct ad5446_state {
  * @left_shift:		number of bits the datum must be shifted
  * @int_vref_mv:	AD5620/40/60: the internal reference voltage
  * @store_sample:	chip specific helper function to store the datum
+ * @store_sample:	chip specific helper function to store the powerpown cmd
  */

 struct ad5446_chip_info {
-	u8				bits;
-	u8				storagebits;
-	u8				left_shift;
-	u16				int_vref_mv;
-	void (*store_sample)		(struct ad5446_state *st, unsigned val);
+	u8			bits;
+	u8			storagebits;
+	u8			left_shift;
+	u16			int_vref_mv;
+	void (*store_sample)	(struct ad5446_state *st, unsigned val);
+	void (*store_pwr_down)	(struct ad5446_state *st, unsigned mode);
 };

 /**
--
1.6.0.2

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

end of thread, other threads:[~2011-03-10 12:26 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-10 11:52 [PATCH 1/3] IIO: DAC: AD5446: Add missing ID table entries michael.hennerich
2011-03-10 11:52 ` [PATCH 2/3] IIO: DAC: AD5446: Add power down support michael.hennerich
2011-03-10 12:10   ` Jonathan Cameron
2011-03-10 11:52 ` [PATCH 3/3] IIO: DAC: AD5446: Add support for AD5601/AD5611/AD5621 michael.hennerich
2011-03-10 12:14   ` Jonathan Cameron
2011-03-10 12:08 ` [PATCH 1/3] IIO: DAC: AD5446: Add missing ID table entries Jonathan Cameron
  -- strict thread matches above, loose matches on Subject: below --
2011-03-10 12:26 michael.hennerich
2011-03-10 12:26 ` [PATCH 2/3] IIO: DAC: AD5446: Add power down support michael.hennerich

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.