Linux IIO development
 help / color / mirror / Atom feed
* [PATCH 1/2] IIO-onwards: ADC: AD7887: Convert to new channel registration method.
@ 2011-04-18 13:03 michael.hennerich
  2011-04-18 13:03 ` [PATCH 2/2] IIO-onwards: ADC: AD7887: Use private data space from iio_allocate_device michael.hennerich
  2011-04-18 13:36 ` [PATCH 1/2] IIO-onwards: ADC: AD7887: Convert to new channel registration method Jonathan Cameron
  0 siblings, 2 replies; 4+ messages in thread
From: michael.hennerich @ 2011-04-18 13:03 UTC (permalink / raw)
  To: jic23; +Cc: linux-iio, drivers, device-drivers-devel, Michael Hennerich

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

Convert to new channel registration method
Update / change license copyright header
Add missing call to iio_trigger_notify_done()

Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
---
 drivers/staging/iio/adc/ad7887.h      |   14 ++--
 drivers/staging/iio/adc/ad7887_core.c |  123 ++++++++++++++-------------------
 drivers/staging/iio/adc/ad7887_ring.c |   71 +++-----------------
 3 files changed, 69 insertions(+), 139 deletions(-)

diff --git a/drivers/staging/iio/adc/ad7887.h b/drivers/staging/iio/adc/ad7887.h
index ffff403..a0c3742 100644
--- a/drivers/staging/iio/adc/ad7887.h
+++ b/drivers/staging/iio/adc/ad7887.h
@@ -48,12 +48,15 @@ struct ad7887_platform_data {
 	bool				use_onchip_ref;
 };
 
+/**
+ * struct ad7887_chip_info - chip specifc information
+ * @int_vref_mv:	the internal reference voltage
+ * @channel:		channel specification
+ */
+
 struct ad7887_chip_info {
-	u8				bits;		/* number of ADC bits */
-	u8				storagebits;	/* number of bits read from the ADC */
-	u8				left_shift;	/* number of bits the sample must be shifted */
-	char				sign;		/* [s]igned or [u]nsigned */
-	u16				int_vref_mv;	/* internal reference voltage */
+	u16				int_vref_mv;
+	struct iio_chan_spec		channel[3];
 };
 
 struct ad7887_state {
@@ -63,7 +66,6 @@ struct ad7887_state {
 	struct regulator		*reg;
 	size_t				d_size;
 	u16				int_vref_mv;
-	bool				en_dual;
 	struct spi_transfer		xfer[4];
 	struct spi_message		msg[3];
 	struct spi_message		*ring_msg;
diff --git a/drivers/staging/iio/adc/ad7887_core.c b/drivers/staging/iio/adc/ad7887_core.c
index 27adff4..68301de 100644
--- a/drivers/staging/iio/adc/ad7887_core.c
+++ b/drivers/staging/iio/adc/ad7887_core.c
@@ -1,9 +1,9 @@
 /*
  * AD7887 SPI ADC driver
  *
- * Copyright 2010 Analog Devices Inc.
+ * Copyright 2010-2011 Analog Devices Inc.
  *
- * Licensed under the GPL-2 or later.
+ * Licensed under the GPL-2.
  */
 
 #include <linux/interrupt.h>
@@ -33,81 +33,55 @@ static int ad7887_scan_direct(struct ad7887_state *st, unsigned ch)
 	return (st->data[(ch * 2)] << 8) | st->data[(ch * 2) + 1];
 }
 
-static ssize_t ad7887_scan(struct device *dev,
-			    struct device_attribute *attr,
-			    char *buf)
+static int ad7887_read_raw(struct iio_dev *dev_info,
+			   struct iio_chan_spec const *chan,
+			   int *val,
+			   int *val2,
+			   long m)
 {
-	struct iio_dev *dev_info = dev_get_drvdata(dev);
-	struct ad7887_state *st = dev_info->dev_data;
-	struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
 	int ret;
+	struct ad7887_state *st = dev_info->dev_data;
+	unsigned int scale_uv;
 
-	mutex_lock(&dev_info->mlock);
-	if (iio_ring_enabled(dev_info))
-		ret = ad7887_scan_from_ring(st, 1 << this_attr->address);
-	else
-		ret = ad7887_scan_direct(st, this_attr->address);
-	mutex_unlock(&dev_info->mlock);
-
-	if (ret < 0)
-		return ret;
-
-	return sprintf(buf, "%d\n", (ret >> st->chip_info->left_shift) &
-		       RES_MASK(st->chip_info->bits));
-}
-static IIO_DEV_ATTR_IN_RAW(0, ad7887_scan, 0);
-static IIO_DEV_ATTR_IN_RAW(1, ad7887_scan, 1);
-
-static ssize_t ad7887_show_scale(struct device *dev,
-				struct device_attribute *attr,
-				char *buf)
-{
-	/* Driver currently only support internal vref */
-	struct iio_dev *dev_info = dev_get_drvdata(dev);
-	struct ad7887_state *st = iio_dev_get_devdata(dev_info);
-	/* Corresponds to Vref / 2^(bits) */
-	unsigned int scale_uv = (st->int_vref_mv * 1000) >> st->chip_info->bits;
-
-	return sprintf(buf, "%d.%03d\n", scale_uv / 1000, scale_uv % 1000);
-}
-static IIO_DEVICE_ATTR(in_scale, S_IRUGO, ad7887_show_scale, NULL, 0);
-
-static struct attribute *ad7887_attributes[] = {
-	&iio_dev_attr_in0_raw.dev_attr.attr,
-	&iio_dev_attr_in1_raw.dev_attr.attr,
-	&iio_dev_attr_in_scale.dev_attr.attr,
-	NULL,
-};
-
-static mode_t ad7887_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 ad7887_state *st = iio_dev_get_devdata(dev_info);
-
-	mode_t mode = attr->mode;
-
-	if ((attr == &iio_dev_attr_in1_raw.dev_attr.attr) && !st->en_dual)
-			mode = 0;
-
-	return mode;
+	switch (m) {
+	case 0:
+		mutex_lock(&dev_info->mlock);
+		if (iio_ring_enabled(dev_info))
+			ret = ad7887_scan_from_ring(st, 1 << chan->address);
+		else
+			ret = ad7887_scan_direct(st, chan->address);
+		mutex_unlock(&dev_info->mlock);
+
+		if (ret < 0)
+			return ret;
+		*val = (ret >> st->chip_info->channel[0].scan_type.shift) &
+			RES_MASK(st->chip_info->channel[0].scan_type.realbits);
+		return IIO_VAL_INT;
+	case (1 << IIO_CHAN_INFO_SCALE_SHARED):
+		scale_uv = (st->int_vref_mv * 1000)
+			>> st->chip_info->channel[0].scan_type.realbits;
+		*val =  scale_uv/1000;
+		*val2 = (scale_uv%1000)*1000;
+		return IIO_VAL_INT_PLUS_MICRO;
+	}
+	return -EINVAL;
 }
 
-static const struct attribute_group ad7887_attribute_group = {
-	.attrs = ad7887_attributes,
-	.is_visible = ad7887_attr_is_visible,
-};
 
 static const struct ad7887_chip_info ad7887_chip_info_tbl[] = {
 	/*
 	 * More devices added in future
 	 */
 	[ID_AD7887] = {
-		.bits = 12,
-		.storagebits = 16,
-		.left_shift = 0,
-		.sign = IIO_SCAN_EL_TYPE_UNSIGNED,
+		.channel[0] = IIO_CHAN_EV(IIO_IN, 1,
+					  (1 << IIO_CHAN_INFO_SCALE_SHARED),
+					  1, 1, IIO_ST('u', 12, 16, 0), 0),
+
+		.channel[1] = IIO_CHAN_EV(IIO_IN, 0,
+					  (1 << IIO_CHAN_INFO_SCALE_SHARED),
+					  0, 0, IIO_ST('u', 12, 16, 0), 0),
+
+		.channel[2] = IIO_CHAN_SOFT_TIMESTAMP(2),
 		.int_vref_mv = 2500,
 	},
 };
@@ -149,8 +123,11 @@ static int __devinit ad7887_probe(struct spi_device *spi)
 	/* Estabilish that the iio_dev is a child of the spi device */
 	st->indio_dev->dev.parent = &spi->dev;
 	st->indio_dev->name = spi_get_device_id(spi)->name;
-	st->indio_dev->attrs = &ad7887_attribute_group;
 	st->indio_dev->dev_data = (void *)(st);
+	st->indio_dev->channels = st->chip_info->channel;
+	st->indio_dev->num_channels = 3;
+	st->indio_dev->read_raw = &ad7887_read_raw;
+
 	st->indio_dev->driver_module = THIS_MODULE;
 	st->indio_dev->modes = INDIO_DIRECT_MODE;
 
@@ -196,8 +173,6 @@ static int __devinit ad7887_probe(struct spi_device *spi)
 		spi_message_init(&st->msg[AD7887_CH1]);
 		spi_message_add_tail(&st->xfer[3], &st->msg[AD7887_CH1]);
 
-		st->en_dual = true;
-
 		if (pdata && pdata->vref_mv)
 			st->int_vref_mv = pdata->vref_mv;
 		else if (voltage_uv)
@@ -205,6 +180,8 @@ static int __devinit ad7887_probe(struct spi_device *spi)
 		else
 			dev_warn(&spi->dev, "reference voltage unspecified\n");
 
+		st->indio_dev->channels = st->chip_info->channel;
+		st->indio_dev->num_channels = 3;
 	} else {
 		if (pdata && pdata->vref_mv)
 			st->int_vref_mv = pdata->vref_mv;
@@ -212,8 +189,10 @@ static int __devinit ad7887_probe(struct spi_device *spi)
 			st->int_vref_mv = st->chip_info->int_vref_mv;
 		else
 			dev_warn(&spi->dev, "reference voltage unspecified\n");
-	}
 
+		st->indio_dev->channels = &st->chip_info->channel[1];
+		st->indio_dev->num_channels = 2;
+	}
 
 	ret = ad7887_register_ring_funcs_and_init(st->indio_dev);
 	if (ret)
@@ -223,7 +202,9 @@ static int __devinit ad7887_probe(struct spi_device *spi)
 	if (ret)
 		goto error_free_device;
 
-	ret = iio_ring_buffer_register(st->indio_dev->ring, 0);
+	ret = iio_ring_buffer_register_ex(st->indio_dev->ring, 0,
+					  st->indio_dev->channels,
+					  st->indio_dev->num_channels);
 	if (ret)
 		goto error_cleanup_ring;
 	return 0;
diff --git a/drivers/staging/iio/adc/ad7887_ring.c b/drivers/staging/iio/adc/ad7887_ring.c
index 8e3653c..e4fe03d 100644
--- a/drivers/staging/iio/adc/ad7887_ring.c
+++ b/drivers/staging/iio/adc/ad7887_ring.c
@@ -1,8 +1,8 @@
 /*
- * Copyright 2010 Analog Devices Inc.
+ * Copyright 2010-2011 Analog Devices Inc.
  * Copyright (C) 2008 Jonathan Cameron
  *
- * Licensed under the GPL-2 or later.
+ * Licensed under the GPL-2.
  *
  * ad7887_ring.c
  */
@@ -25,61 +25,6 @@
 
 #include "ad7887.h"
 
-static IIO_SCAN_EL_C(in0, 0, 0, NULL);
-static IIO_SCAN_EL_C(in1, 1, 0, NULL);
-static IIO_SCAN_EL_TIMESTAMP(2);
-static IIO_CONST_ATTR_SCAN_EL_TYPE(timestamp, s, 64, 64);
-
-static ssize_t ad7887_show_type(struct device *dev,
-				struct device_attribute *attr,
-				char *buf)
-{
-	struct iio_ring_buffer *ring = dev_get_drvdata(dev);
-	struct iio_dev *indio_dev = ring->indio_dev;
-	struct ad7887_state *st = indio_dev->dev_data;
-
-	return sprintf(buf, "%c%d/%d>>%d\n", st->chip_info->sign,
-		       st->chip_info->bits, st->chip_info->storagebits,
-		       st->chip_info->left_shift);
-}
-static IIO_DEVICE_ATTR(in_type, S_IRUGO, ad7887_show_type, NULL, 0);
-
-static struct attribute *ad7887_scan_el_attrs[] = {
-	&iio_scan_el_in0.dev_attr.attr,
-	&iio_const_attr_in0_index.dev_attr.attr,
-	&iio_scan_el_in1.dev_attr.attr,
-	&iio_const_attr_in1_index.dev_attr.attr,
-	&iio_const_attr_timestamp_index.dev_attr.attr,
-	&iio_scan_el_timestamp.dev_attr.attr,
-	&iio_const_attr_timestamp_type.dev_attr.attr,
-	&iio_dev_attr_in_type.dev_attr.attr,
-	NULL,
-};
-
-static mode_t ad7887_scan_el_attr_is_visible(struct kobject *kobj,
-				     struct attribute *attr, int n)
-{
-	struct device *dev = container_of(kobj, struct device, kobj);
-	struct iio_ring_buffer *ring = dev_get_drvdata(dev);
-	struct iio_dev *indio_dev = ring->indio_dev;
-	struct ad7887_state *st = indio_dev->dev_data;
-
-	mode_t mode = attr->mode;
-
-	if ((attr == &iio_scan_el_in1.dev_attr.attr) ||
-		(attr == &iio_const_attr_in1_index.dev_attr.attr))
-		if (!st->en_dual)
-			mode = 0;
-
-	return mode;
-}
-
-static struct attribute_group ad7887_scan_el_group = {
-	.name = "scan_elements",
-	.attrs = ad7887_scan_el_attrs,
-	.is_visible = ad7887_scan_el_attr_is_visible,
-};
-
 int ad7887_scan_from_ring(struct ad7887_state *st, long mask)
 {
 	struct iio_ring_buffer *ring = st->indio_dev->ring;
@@ -124,7 +69,8 @@ static int ad7887_ring_preenable(struct iio_dev *indio_dev)
 	struct ad7887_state *st = indio_dev->dev_data;
 	struct iio_ring_buffer *ring = indio_dev->ring;
 
-	st->d_size = ring->scan_count * st->chip_info->storagebits / 8;
+	st->d_size = ring->scan_count *
+		st->chip_info->channel[0].scan_type.storagebits / 8;
 
 	if (ring->scan_timestamp) {
 		st->d_size += sizeof(s64);
@@ -179,7 +125,8 @@ static irqreturn_t ad7887_trigger_handler(int irq, void *p)
 	__u8 *buf;
 	int b_sent;
 
-	unsigned int bytes = ring->scan_count * st->chip_info->storagebits / 8;
+	unsigned int bytes = ring->scan_count *
+		st->chip_info->channel[0].scan_type.storagebits / 8;
 
 	buf = kzalloc(st->d_size, GFP_KERNEL);
 	if (buf == NULL)
@@ -193,11 +140,13 @@ static irqreturn_t ad7887_trigger_handler(int irq, void *p)
 
 	memcpy(buf, st->data, bytes);
 	if (ring->scan_timestamp)
-		memcpy(buf + st->d_size - sizeof(s64), &time_ns, sizeof(time_ns));
+		memcpy(buf + st->d_size - sizeof(s64),
+			&time_ns, sizeof(time_ns));
 
 	indio_dev->ring->access.store_to(&sw_ring->buf, buf, time_ns);
 done:
 	kfree(buf);
+	iio_trigger_notify_done(indio_dev->trig);
 
 	return IRQ_HANDLED;
 }
@@ -235,8 +184,6 @@ int ad7887_register_ring_funcs_and_init(struct iio_dev *indio_dev)
 	indio_dev->ring->postenable = &iio_triggered_ring_postenable;
 	indio_dev->ring->predisable = &iio_triggered_ring_predisable;
 	indio_dev->ring->postdisable = &ad7887_ring_postdisable;
-	indio_dev->ring->scan_el_attrs = &ad7887_scan_el_group;
-	indio_dev->ring->scan_timestamp = true;
 
 	/* Flag that polled ring buffering is possible */
 	indio_dev->modes |= INDIO_RING_TRIGGERED;
-- 
1.6.0.2

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

* [PATCH 2/2] IIO-onwards: ADC: AD7887: Use private data space from iio_allocate_device
  2011-04-18 13:03 [PATCH 1/2] IIO-onwards: ADC: AD7887: Convert to new channel registration method michael.hennerich
@ 2011-04-18 13:03 ` michael.hennerich
  2011-04-18 13:38   ` Jonathan Cameron
  2011-04-18 13:36 ` [PATCH 1/2] IIO-onwards: ADC: AD7887: Convert to new channel registration method Jonathan Cameron
  1 sibling, 1 reply; 4+ messages in thread
From: michael.hennerich @ 2011-04-18 13:03 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/adc/ad7887.h      |    1 -
 drivers/staging/iio/adc/ad7887_core.c |   80 +++++++++++++++------------------
 drivers/staging/iio/adc/ad7887_ring.c |    2 +-
 3 files changed, 37 insertions(+), 46 deletions(-)

diff --git a/drivers/staging/iio/adc/ad7887.h b/drivers/staging/iio/adc/ad7887.h
index a0c3742..837046c 100644
--- a/drivers/staging/iio/adc/ad7887.h
+++ b/drivers/staging/iio/adc/ad7887.h
@@ -60,7 +60,6 @@ struct ad7887_chip_info {
 };
 
 struct ad7887_state {
-	struct iio_dev			*indio_dev;
 	struct spi_device		*spi;
 	const struct ad7887_chip_info	*chip_info;
 	struct regulator		*reg;
diff --git a/drivers/staging/iio/adc/ad7887_core.c b/drivers/staging/iio/adc/ad7887_core.c
index 68301de..228ef7c 100644
--- a/drivers/staging/iio/adc/ad7887_core.c
+++ b/drivers/staging/iio/adc/ad7887_core.c
@@ -90,13 +90,13 @@ static int __devinit ad7887_probe(struct spi_device *spi)
 {
 	struct ad7887_platform_data *pdata = spi->dev.platform_data;
 	struct ad7887_state *st;
-	int ret, voltage_uv = 0;
+	int ret, voltage_uv = 0, regdone = 0;
+	struct iio_dev *indio_dev = iio_allocate_device(sizeof(*st));
 
-	st = kzalloc(sizeof(*st), GFP_KERNEL);
-	if (st == NULL) {
-		ret = -ENOMEM;
-		goto error_ret;
-	}
+	if (indio_dev == NULL)
+		return -ENOMEM;
+
+	st = iio_priv(indio_dev);
 
 	st->reg = regulator_get(&spi->dev, "vcc");
 	if (!IS_ERR(st->reg)) {
@@ -110,26 +110,16 @@ static int __devinit ad7887_probe(struct spi_device *spi)
 	st->chip_info =
 		&ad7887_chip_info_tbl[spi_get_device_id(spi)->driver_data];
 
-	spi_set_drvdata(spi, st);
-
+	spi_set_drvdata(spi, indio_dev);
 	st->spi = spi;
 
-	st->indio_dev = iio_allocate_device(0);
-	if (st->indio_dev == NULL) {
-		ret = -ENOMEM;
-		goto error_disable_reg;
-	}
-
 	/* Estabilish that the iio_dev is a child of the spi device */
-	st->indio_dev->dev.parent = &spi->dev;
-	st->indio_dev->name = spi_get_device_id(spi)->name;
-	st->indio_dev->dev_data = (void *)(st);
-	st->indio_dev->channels = st->chip_info->channel;
-	st->indio_dev->num_channels = 3;
-	st->indio_dev->read_raw = &ad7887_read_raw;
-
-	st->indio_dev->driver_module = THIS_MODULE;
-	st->indio_dev->modes = INDIO_DIRECT_MODE;
+	indio_dev->dev.parent = &spi->dev;
+	indio_dev->name = spi_get_device_id(spi)->name;
+	indio_dev->dev_data = (void *)(st);
+	indio_dev->read_raw = &ad7887_read_raw;
+	indio_dev->driver_module = THIS_MODULE;
+	indio_dev->modes = INDIO_DIRECT_MODE;
 
 	/* Setup default message */
 
@@ -180,8 +170,8 @@ static int __devinit ad7887_probe(struct spi_device *spi)
 		else
 			dev_warn(&spi->dev, "reference voltage unspecified\n");
 
-		st->indio_dev->channels = st->chip_info->channel;
-		st->indio_dev->num_channels = 3;
+		indio_dev->channels = st->chip_info->channel;
+		indio_dev->num_channels = 3;
 	} else {
 		if (pdata && pdata->vref_mv)
 			st->int_vref_mv = pdata->vref_mv;
@@ -190,53 +180,55 @@ static int __devinit ad7887_probe(struct spi_device *spi)
 		else
 			dev_warn(&spi->dev, "reference voltage unspecified\n");
 
-		st->indio_dev->channels = &st->chip_info->channel[1];
-		st->indio_dev->num_channels = 2;
+		indio_dev->channels = &st->chip_info->channel[1];
+		indio_dev->num_channels = 2;
 	}
 
-	ret = ad7887_register_ring_funcs_and_init(st->indio_dev);
+	ret = ad7887_register_ring_funcs_and_init(indio_dev);
 	if (ret)
-		goto error_free_device;
+		goto error_disable_reg;
 
-	ret = iio_device_register(st->indio_dev);
+	ret = iio_device_register(indio_dev);
 	if (ret)
-		goto error_free_device;
+		goto error_disable_reg;
+	regdone = 1;
 
-	ret = iio_ring_buffer_register_ex(st->indio_dev->ring, 0,
-					  st->indio_dev->channels,
-					  st->indio_dev->num_channels);
+	ret = iio_ring_buffer_register_ex(indio_dev->ring, 0,
+					  indio_dev->channels,
+					  indio_dev->num_channels);
 	if (ret)
 		goto error_cleanup_ring;
 	return 0;
 
 error_cleanup_ring:
-	ad7887_ring_cleanup(st->indio_dev);
-	iio_device_unregister(st->indio_dev);
-error_free_device:
-	iio_free_device(st->indio_dev);
+	ad7887_ring_cleanup(indio_dev);
 error_disable_reg:
 	if (!IS_ERR(st->reg))
 		regulator_disable(st->reg);
 error_put_reg:
 	if (!IS_ERR(st->reg))
 		regulator_put(st->reg);
-	kfree(st);
-error_ret:
+	if (regdone)
+		iio_device_unregister(indio_dev);
+	else
+		iio_free_device(indio_dev);
+
 	return ret;
 }
 
 static int ad7887_remove(struct spi_device *spi)
 {
-	struct ad7887_state *st = spi_get_drvdata(spi);
-	struct iio_dev *indio_dev = st->indio_dev;
+	struct iio_dev *indio_dev = spi_get_drvdata(spi);
+	struct ad7887_state *st = iio_priv(indio_dev);
+
 	iio_ring_buffer_unregister(indio_dev->ring);
 	ad7887_ring_cleanup(indio_dev);
-	iio_device_unregister(indio_dev);
 	if (!IS_ERR(st->reg)) {
 		regulator_disable(st->reg);
 		regulator_put(st->reg);
 	}
-	kfree(st);
+	iio_device_unregister(indio_dev);
+
 	return 0;
 }
 
diff --git a/drivers/staging/iio/adc/ad7887_ring.c b/drivers/staging/iio/adc/ad7887_ring.c
index e4fe03d..e1f4cb3 100644
--- a/drivers/staging/iio/adc/ad7887_ring.c
+++ b/drivers/staging/iio/adc/ad7887_ring.c
@@ -27,7 +27,7 @@
 
 int ad7887_scan_from_ring(struct ad7887_state *st, long mask)
 {
-	struct iio_ring_buffer *ring = st->indio_dev->ring;
+	struct iio_ring_buffer *ring = iio_priv_to_dev(st)->ring;
 	int count = 0, ret;
 	u16 *ring_data;
 
-- 
1.6.0.2

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

* Re: [PATCH 1/2] IIO-onwards: ADC: AD7887: Convert to new channel registration method.
  2011-04-18 13:03 [PATCH 1/2] IIO-onwards: ADC: AD7887: Convert to new channel registration method michael.hennerich
  2011-04-18 13:03 ` [PATCH 2/2] IIO-onwards: ADC: AD7887: Use private data space from iio_allocate_device michael.hennerich
@ 2011-04-18 13:36 ` Jonathan Cameron
  1 sibling, 0 replies; 4+ messages in thread
From: Jonathan Cameron @ 2011-04-18 13:36 UTC (permalink / raw)
  To: michael.hennerich; +Cc: linux-iio, drivers, device-drivers-devel

On 04/18/11 14:03, michael.hennerich@analog.com wrote:
> From: Michael Hennerich <michael.hennerich@analog.com>
> 
> Convert to new channel registration method
> Update / change license copyright header
> Add missing call to iio_trigger_notify_done()
Looks good.  I wonder if it would make more sense to have the channel
definitions external to the chip_info structure (have a pointer and size
parameter in there.)  That would allow the driver to handle devices with
different numbers of channels.  Right now it's irrelevant though and can
be easily enough fixed when/if it becomes an issue.

Thanks,

Will slot this one into relevant spot in iio-onwards.
> 
> Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
Acked-by: Jonathan Cameron <jic23@cam.ac.uk>
> ---
>  drivers/staging/iio/adc/ad7887.h      |   14 ++--
>  drivers/staging/iio/adc/ad7887_core.c |  123 ++++++++++++++-------------------
>  drivers/staging/iio/adc/ad7887_ring.c |   71 +++-----------------
>  3 files changed, 69 insertions(+), 139 deletions(-)

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

* Re: [PATCH 2/2] IIO-onwards: ADC: AD7887: Use private data space from iio_allocate_device
  2011-04-18 13:03 ` [PATCH 2/2] IIO-onwards: ADC: AD7887: Use private data space from iio_allocate_device michael.hennerich
@ 2011-04-18 13:38   ` Jonathan Cameron
  0 siblings, 0 replies; 4+ messages in thread
From: Jonathan Cameron @ 2011-04-18 13:38 UTC (permalink / raw)
  To: michael.hennerich; +Cc: linux-iio, drivers, device-drivers-devel

On 04/18/11 14:03, michael.hennerich@analog.com wrote:
> From: Michael Hennerich <michael.hennerich@analog.com>
> 
Will put this one after the other in iio-onwards.
> Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
Acked-by: Jonathan Cameron <jic23@cam.ac.uk>

Thanks for doing these.
> ---
>  drivers/staging/iio/adc/ad7887.h      |    1 -
>  drivers/staging/iio/adc/ad7887_core.c |   80 +++++++++++++++------------------
>  drivers/staging/iio/adc/ad7887_ring.c |    2 +-
>  3 files changed, 37 insertions(+), 46 deletions(-)
> 
> diff --git a/drivers/staging/iio/adc/ad7887.h b/drivers/staging/iio/adc/ad7887.h
> index a0c3742..837046c 100644
> --- a/drivers/staging/iio/adc/ad7887.h
> +++ b/drivers/staging/iio/adc/ad7887.h
> @@ -60,7 +60,6 @@ struct ad7887_chip_info {
>  };
>  
>  struct ad7887_state {
> -	struct iio_dev			*indio_dev;
>  	struct spi_device		*spi;
>  	const struct ad7887_chip_info	*chip_info;
>  	struct regulator		*reg;
> diff --git a/drivers/staging/iio/adc/ad7887_core.c b/drivers/staging/iio/adc/ad7887_core.c
> index 68301de..228ef7c 100644
> --- a/drivers/staging/iio/adc/ad7887_core.c
> +++ b/drivers/staging/iio/adc/ad7887_core.c
> @@ -90,13 +90,13 @@ static int __devinit ad7887_probe(struct spi_device *spi)
>  {
>  	struct ad7887_platform_data *pdata = spi->dev.platform_data;
>  	struct ad7887_state *st;
> -	int ret, voltage_uv = 0;
> +	int ret, voltage_uv = 0, regdone = 0;
> +	struct iio_dev *indio_dev = iio_allocate_device(sizeof(*st));
>  
> -	st = kzalloc(sizeof(*st), GFP_KERNEL);
> -	if (st == NULL) {
> -		ret = -ENOMEM;
> -		goto error_ret;
> -	}
> +	if (indio_dev == NULL)
> +		return -ENOMEM;
> +
> +	st = iio_priv(indio_dev);
>  
>  	st->reg = regulator_get(&spi->dev, "vcc");
>  	if (!IS_ERR(st->reg)) {
> @@ -110,26 +110,16 @@ static int __devinit ad7887_probe(struct spi_device *spi)
>  	st->chip_info =
>  		&ad7887_chip_info_tbl[spi_get_device_id(spi)->driver_data];
>  
> -	spi_set_drvdata(spi, st);
> -
> +	spi_set_drvdata(spi, indio_dev);
>  	st->spi = spi;
>  
> -	st->indio_dev = iio_allocate_device(0);
> -	if (st->indio_dev == NULL) {
> -		ret = -ENOMEM;
> -		goto error_disable_reg;
> -	}
> -
>  	/* Estabilish that the iio_dev is a child of the spi device */
> -	st->indio_dev->dev.parent = &spi->dev;
> -	st->indio_dev->name = spi_get_device_id(spi)->name;
> -	st->indio_dev->dev_data = (void *)(st);
> -	st->indio_dev->channels = st->chip_info->channel;
> -	st->indio_dev->num_channels = 3;
> -	st->indio_dev->read_raw = &ad7887_read_raw;
> -
> -	st->indio_dev->driver_module = THIS_MODULE;
> -	st->indio_dev->modes = INDIO_DIRECT_MODE;
> +	indio_dev->dev.parent = &spi->dev;
> +	indio_dev->name = spi_get_device_id(spi)->name;
> +	indio_dev->dev_data = (void *)(st);
> +	indio_dev->read_raw = &ad7887_read_raw;
> +	indio_dev->driver_module = THIS_MODULE;
> +	indio_dev->modes = INDIO_DIRECT_MODE;
>  
>  	/* Setup default message */
>  
> @@ -180,8 +170,8 @@ static int __devinit ad7887_probe(struct spi_device *spi)
>  		else
>  			dev_warn(&spi->dev, "reference voltage unspecified\n");
>  
> -		st->indio_dev->channels = st->chip_info->channel;
> -		st->indio_dev->num_channels = 3;
> +		indio_dev->channels = st->chip_info->channel;
> +		indio_dev->num_channels = 3;
>  	} else {
>  		if (pdata && pdata->vref_mv)
>  			st->int_vref_mv = pdata->vref_mv;
> @@ -190,53 +180,55 @@ static int __devinit ad7887_probe(struct spi_device *spi)
>  		else
>  			dev_warn(&spi->dev, "reference voltage unspecified\n");
>  
> -		st->indio_dev->channels = &st->chip_info->channel[1];
> -		st->indio_dev->num_channels = 2;
> +		indio_dev->channels = &st->chip_info->channel[1];
> +		indio_dev->num_channels = 2;
>  	}
>  
> -	ret = ad7887_register_ring_funcs_and_init(st->indio_dev);
> +	ret = ad7887_register_ring_funcs_and_init(indio_dev);
>  	if (ret)
> -		goto error_free_device;
> +		goto error_disable_reg;
>  
> -	ret = iio_device_register(st->indio_dev);
> +	ret = iio_device_register(indio_dev);
>  	if (ret)
> -		goto error_free_device;
> +		goto error_disable_reg;
> +	regdone = 1;
>  
> -	ret = iio_ring_buffer_register_ex(st->indio_dev->ring, 0,
> -					  st->indio_dev->channels,
> -					  st->indio_dev->num_channels);
> +	ret = iio_ring_buffer_register_ex(indio_dev->ring, 0,
> +					  indio_dev->channels,
> +					  indio_dev->num_channels);
>  	if (ret)
>  		goto error_cleanup_ring;
>  	return 0;
>  
>  error_cleanup_ring:
> -	ad7887_ring_cleanup(st->indio_dev);
> -	iio_device_unregister(st->indio_dev);
> -error_free_device:
> -	iio_free_device(st->indio_dev);
> +	ad7887_ring_cleanup(indio_dev);
>  error_disable_reg:
>  	if (!IS_ERR(st->reg))
>  		regulator_disable(st->reg);
>  error_put_reg:
>  	if (!IS_ERR(st->reg))
>  		regulator_put(st->reg);
> -	kfree(st);
> -error_ret:
> +	if (regdone)
> +		iio_device_unregister(indio_dev);
> +	else
> +		iio_free_device(indio_dev);
> +
>  	return ret;
>  }
>  
>  static int ad7887_remove(struct spi_device *spi)
>  {
> -	struct ad7887_state *st = spi_get_drvdata(spi);
> -	struct iio_dev *indio_dev = st->indio_dev;
> +	struct iio_dev *indio_dev = spi_get_drvdata(spi);
> +	struct ad7887_state *st = iio_priv(indio_dev);
> +
>  	iio_ring_buffer_unregister(indio_dev->ring);
>  	ad7887_ring_cleanup(indio_dev);
> -	iio_device_unregister(indio_dev);
>  	if (!IS_ERR(st->reg)) {
>  		regulator_disable(st->reg);
>  		regulator_put(st->reg);
>  	}
> -	kfree(st);
> +	iio_device_unregister(indio_dev);
> +
>  	return 0;
>  }
>  
> diff --git a/drivers/staging/iio/adc/ad7887_ring.c b/drivers/staging/iio/adc/ad7887_ring.c
> index e4fe03d..e1f4cb3 100644
> --- a/drivers/staging/iio/adc/ad7887_ring.c
> +++ b/drivers/staging/iio/adc/ad7887_ring.c
> @@ -27,7 +27,7 @@
>  
>  int ad7887_scan_from_ring(struct ad7887_state *st, long mask)
>  {
> -	struct iio_ring_buffer *ring = st->indio_dev->ring;
> +	struct iio_ring_buffer *ring = iio_priv_to_dev(st)->ring;
>  	int count = 0, ret;
>  	u16 *ring_data;
>  


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

end of thread, other threads:[~2011-04-18 13:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-04-18 13:03 [PATCH 1/2] IIO-onwards: ADC: AD7887: Convert to new channel registration method michael.hennerich
2011-04-18 13:03 ` [PATCH 2/2] IIO-onwards: ADC: AD7887: Use private data space from iio_allocate_device michael.hennerich
2011-04-18 13:38   ` Jonathan Cameron
2011-04-18 13:36 ` [PATCH 1/2] IIO-onwards: ADC: AD7887: Convert to new channel registration method Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox