* [PATCH 01/12] iio: ad7291: fix channel mapping
@ 2011-08-31 10:57 michael.hennerich
2011-08-31 10:57 ` [PATCH 02/12] iio: ad7291: Fix typos, change kconfig description and file header michael.hennerich
` (11 more replies)
0 siblings, 12 replies; 29+ messages in thread
From: michael.hennerich @ 2011-08-31 10:57 UTC (permalink / raw)
To: jic23; +Cc: linux-iio, device-drivers-devel, drivers, Michael Hennerich
From: Michael Hennerich <michael.hennerich@analog.com>
ideally in_voltageX_raw should map to AD7291 VINX.
Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
---
drivers/staging/iio/adc/ad7291.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/drivers/staging/iio/adc/ad7291.c b/drivers/staging/iio/adc/ad7291.c
index b6be672..32944f3 100644
--- a/drivers/staging/iio/adc/ad7291.c
+++ b/drivers/staging/iio/adc/ad7291.c
@@ -434,7 +434,7 @@ static int ad7291_read_raw(struct iio_dev *indio_dev,
}
/* Enable this channel alone */
regval = chip->command & (~AD7291_VOLTAGE_MASK);
- regval |= 1 << (chan->channel + 8);
+ regval |= 1 << (15 - chan->channel);
ret = ad7291_i2c_write(chip, AD7291_COMMAND, regval);
if (ret < 0) {
mutex_unlock(&chip->state_lock);
--
1.7.0.4
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [PATCH 02/12] iio: ad7291: Fix typos, change kconfig description and file header
2011-08-31 10:57 [PATCH 01/12] iio: ad7291: fix channel mapping michael.hennerich
@ 2011-08-31 10:57 ` michael.hennerich
2011-08-31 11:18 ` Jonathan Cameron
2011-08-31 10:57 ` [PATCH 03/12] iio: ad7291: Fix AD7291_T_SENSE_MASK michael.hennerich
` (10 subsequent siblings)
11 siblings, 1 reply; 29+ messages in thread
From: michael.hennerich @ 2011-08-31 10:57 UTC (permalink / raw)
To: jic23; +Cc: linux-iio, device-drivers-devel, drivers, Michael Hennerich
From: Michael Hennerich <michael.hennerich@analog.com>
Make clear the AD7291 is primarily an ADC, and not a temp sensor.
Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
---
drivers/staging/iio/adc/Kconfig | 4 ++--
drivers/staging/iio/adc/ad7291.c | 14 +++++++-------
2 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/drivers/staging/iio/adc/Kconfig b/drivers/staging/iio/adc/Kconfig
index 25566c6..7867ab1 100644
--- a/drivers/staging/iio/adc/Kconfig
+++ b/drivers/staging/iio/adc/Kconfig
@@ -18,11 +18,11 @@ config AD7152
(ad7152, ad7153) Provides direct access via sysfs.
config AD7291
- tristate "Analog Devices AD7291 temperature sensor driver"
+ tristate "Analog Devices AD7291 ADC driver"
depends on I2C
help
Say yes here to build support for Analog Devices AD7291
- temperature sensors.
+ 8 Channel ADC with temperature sensor.
config AD7298
tristate "Analog Devices AD7298 ADC driver"
diff --git a/drivers/staging/iio/adc/ad7291.c b/drivers/staging/iio/adc/ad7291.c
index 32944f3..d47df4a 100644
--- a/drivers/staging/iio/adc/ad7291.c
+++ b/drivers/staging/iio/adc/ad7291.c
@@ -1,7 +1,7 @@
/*
- * AD7291 digital temperature sensor driver supporting AD7291
+ * AD7291 8-Channel, I2C, 12-Bit SAR ADC with Temperature Sensor
*
- * Copyright 2010 Analog Devices Inc.
+ * Copyright 2010-2011 Analog Devices Inc.
*
* Licensed under the GPL-2 or later.
*/
@@ -48,8 +48,8 @@
*/
#define AD7291_AUTOCYCLE 0x1
#define AD7291_RESET 0x2
-#define AD7291_ALART_CLEAR 0x4
-#define AD7291_ALART_POLARITY 0x8
+#define AD7291_ALERT_CLEAR 0x4
+#define AD7291_ALERT_POLARITY 0x8
#define AD7291_EXT_REF 0x10
#define AD7291_NOISE_DELAY 0x20
#define AD7291_T_SENSE_MASK 0x40
@@ -134,10 +134,10 @@ static irqreturn_t ad7291_event_handler(int irq, void *private)
if (!(t_status || v_status))
return IRQ_HANDLED;
- command = chip->command | AD7291_ALART_CLEAR;
+ command = chip->command | AD7291_ALERT_CLEAR;
ad7291_i2c_write(chip, AD7291_COMMAND, command);
- command = chip->command & ~AD7291_ALART_CLEAR;
+ command = chip->command & ~AD7291_ALERT_CLEAR;
ad7291_i2c_write(chip, AD7291_COMMAND, command);
/* For now treat t_sense and t_sense_average the same */
@@ -558,7 +558,7 @@ static int __devinit ad7291_probe(struct i2c_client *client,
goto error_free_dev;
/* set irq polarity low level */
- chip->command |= AD7291_ALART_POLARITY;
+ chip->command |= AD7291_ALERT_POLARITY;
}
ret = ad7291_i2c_write(chip, AD7291_COMMAND, chip->command);
--
1.7.0.4
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [PATCH 03/12] iio: ad7291: Fix AD7291_T_SENSE_MASK
2011-08-31 10:57 [PATCH 01/12] iio: ad7291: fix channel mapping michael.hennerich
2011-08-31 10:57 ` [PATCH 02/12] iio: ad7291: Fix typos, change kconfig description and file header michael.hennerich
@ 2011-08-31 10:57 ` michael.hennerich
2011-08-31 11:19 ` Jonathan Cameron
2011-08-31 10:57 ` [PATCH 04/12] iio: ad7291: Add regulator, reference voltage and scale handling michael.hennerich
` (9 subsequent siblings)
11 siblings, 1 reply; 29+ messages in thread
From: michael.hennerich @ 2011-08-31 10:57 UTC (permalink / raw)
To: jic23; +Cc: linux-iio, device-drivers-devel, drivers, Michael Hennerich
From: Michael Hennerich <michael.hennerich@analog.com>
AD7291_T_SENSE_MASK must set bit-7.
Change definition style.
Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
---
drivers/staging/iio/adc/ad7291.c | 28 ++++++++++++++--------------
1 files changed, 14 insertions(+), 14 deletions(-)
diff --git a/drivers/staging/iio/adc/ad7291.c b/drivers/staging/iio/adc/ad7291.c
index d47df4a..dda6bcb 100644
--- a/drivers/staging/iio/adc/ad7291.c
+++ b/drivers/staging/iio/adc/ad7291.c
@@ -37,30 +37,30 @@
#define AD7291_T_AVERAGE 3
#define AD7291_VOLTAGE_LIMIT_BASE 4
#define AD7291_VOLTAGE_LIMIT_COUNT 8
-#define AD7291_T_SENSE_HIGH 0x1c
-#define AD7291_T_SENSE_LOW 0x1d
-#define AD7291_T_SENSE_HYST 0x1e
-#define AD7291_VOLTAGE_ALERT_STATUS 0x1f
+#define AD7291_T_SENSE_HIGH 0x1C
+#define AD7291_T_SENSE_LOW 0x1D
+#define AD7291_T_SENSE_HYST 0x1E
+#define AD7291_VOLTAGE_ALERT_STATUS 0x1F
#define AD7291_T_ALERT_STATUS 0x20
/*
* AD7291 command
*/
-#define AD7291_AUTOCYCLE 0x1
-#define AD7291_RESET 0x2
-#define AD7291_ALERT_CLEAR 0x4
-#define AD7291_ALERT_POLARITY 0x8
-#define AD7291_EXT_REF 0x10
-#define AD7291_NOISE_DELAY 0x20
-#define AD7291_T_SENSE_MASK 0x40
-#define AD7291_VOLTAGE_MASK 0xff00
+#define AD7291_AUTOCYCLE (1 << 0)
+#define AD7291_RESET (1 << 1)
+#define AD7291_ALERT_CLEAR (1 << 2)
+#define AD7291_ALERT_POLARITY (1 << 3)
+#define AD7291_EXT_REF (1 << 4)
+#define AD7291_NOISE_DELAY (1 << 5)
+#define AD7291_T_SENSE_MASK (1 << 7)
+#define AD7291_VOLTAGE_MASK 0xFF00
#define AD7291_VOLTAGE_OFFSET 0x8
/*
* AD7291 value masks
*/
-#define AD7291_CHANNEL_MASK 0xf000
-#define AD7291_VALUE_MASK 0xfff
+#define AD7291_CHANNEL_MASK 0xF000
+#define AD7291_VALUE_MASK 0xFFF
#define AD7291_T_VALUE_SIGN 0x400
#define AD7291_T_VALUE_FLOAT_OFFSET 2
#define AD7291_T_VALUE_FLOAT_MASK 0x2
--
1.7.0.4
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [PATCH 04/12] iio: ad7291: Add regulator, reference voltage and scale handling
2011-08-31 10:57 [PATCH 01/12] iio: ad7291: fix channel mapping michael.hennerich
2011-08-31 10:57 ` [PATCH 02/12] iio: ad7291: Fix typos, change kconfig description and file header michael.hennerich
2011-08-31 10:57 ` [PATCH 03/12] iio: ad7291: Fix AD7291_T_SENSE_MASK michael.hennerich
@ 2011-08-31 10:57 ` michael.hennerich
2011-08-31 11:22 ` Jonathan Cameron
2011-08-31 10:57 ` [PATCH 05/12] iio: ad7291: don't swab results twice and introduce more register defines michael.hennerich
` (8 subsequent siblings)
11 siblings, 1 reply; 29+ messages in thread
From: michael.hennerich @ 2011-08-31 10:57 UTC (permalink / raw)
To: jic23; +Cc: linux-iio, device-drivers-devel, drivers, Michael Hennerich
From: Michael Hennerich <michael.hennerich@analog.com>
Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
---
drivers/staging/iio/adc/ad7291.c | 61 ++++++++++++++++++++++++++++++++-----
1 files changed, 52 insertions(+), 9 deletions(-)
diff --git a/drivers/staging/iio/adc/ad7291.c b/drivers/staging/iio/adc/ad7291.c
index dda6bcb..382ca3e 100644
--- a/drivers/staging/iio/adc/ad7291.c
+++ b/drivers/staging/iio/adc/ad7291.c
@@ -13,6 +13,8 @@
#include <linux/sysfs.h>
#include <linux/i2c.h>
#include <linux/mutex.h>
+#include <linux/regulator/consumer.h>
+#include <linux/err.h>
#include "../iio.h"
#include "../sysfs.h"
@@ -26,8 +28,8 @@
*
* The noise-delayed bit as per datasheet suggestion is always enabled.
*
- * Extref control should be based on regulator provision - not handled.
*/
+
/*
* AD7291 registers definition
*/
@@ -60,16 +62,21 @@
* AD7291 value masks
*/
#define AD7291_CHANNEL_MASK 0xF000
+#define AD7291_BITS 12
#define AD7291_VALUE_MASK 0xFFF
#define AD7291_T_VALUE_SIGN 0x400
#define AD7291_T_VALUE_FLOAT_OFFSET 2
#define AD7291_T_VALUE_FLOAT_MASK 0x2
+#define AD7291_BITS 12
+
struct ad7291_chip_info {
- struct i2c_client *client;
- u16 command;
- u8 c_mask; /* Active voltage channels for events */
- struct mutex state_lock;
+ struct i2c_client *client;
+ struct regulator *reg;
+ u16 int_vref_mv;
+ u16 command;
+ u8 c_mask; /* Active voltage channels for events */
+ struct mutex state_lock;
};
static int ad7291_i2c_read(struct ad7291_chip_info *chip, u8 reg, u16 *data)
@@ -419,6 +426,7 @@ static int ad7291_read_raw(struct iio_dev *indio_dev,
{
int ret;
struct ad7291_chip_info *chip = iio_priv(indio_dev);
+ unsigned int scale_uv;
u16 regval;
s16 signval;
@@ -470,6 +478,11 @@ static int ad7291_read_raw(struct iio_dev *indio_dev,
signval = (s16)((swab16((u16)ret) & 0x0FFF) << 4) >> 4;
*val = signval;
return IIO_VAL_INT;
+ case (1 << IIO_CHAN_INFO_SCALE_SHARED):
+ scale_uv = (chip->int_vref_mv * 1000) >> AD7291_BITS;
+ *val = scale_uv / 1000;
+ *val2 = (scale_uv % 1000) * 1000;
+ return IIO_VAL_INT_PLUS_MICRO;
default:
return -EINVAL;
}
@@ -478,6 +491,7 @@ static int ad7291_read_raw(struct iio_dev *indio_dev,
#define AD7291_VOLTAGE_CHAN(_chan) \
{ \
.type = IIO_VOLTAGE, \
+ .info_mask = (1 << IIO_CHAN_INFO_SCALE_SHARED), \
.indexed = 1, \
.channel = _chan, \
.event_mask = IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING)|\
@@ -523,7 +537,7 @@ static int __devinit ad7291_probe(struct i2c_client *client,
{
struct ad7291_chip_info *chip;
struct iio_dev *indio_dev;
- int ret = 0;
+ int ret = 0, voltage_uv = 0;
indio_dev = iio_allocate_device(sizeof(*chip));
if (indio_dev == NULL) {
@@ -531,6 +545,15 @@ static int __devinit ad7291_probe(struct i2c_client *client,
goto error_ret;
}
chip = iio_priv(indio_dev);
+
+ chip->reg = regulator_get(&client->dev, "vcc");
+ if (!IS_ERR(chip->reg)) {
+ ret = regulator_enable(chip->reg);
+ if (ret)
+ goto error_put_reg;
+ voltage_uv = regulator_get_voltage(chip->reg);
+ }
+
mutex_init(&chip->state_lock);
/* this is only used for device removal purposes */
i2c_set_clientdata(client, indio_dev);
@@ -539,6 +562,13 @@ static int __devinit ad7291_probe(struct i2c_client *client,
/* Tsense always enabled */
chip->command = AD7291_NOISE_DELAY | AD7291_T_SENSE_MASK;
+ if (voltage_uv) {
+ chip->int_vref_mv = voltage_uv / 1000;
+ chip->command |= AD7291_EXT_REF;
+ } else {
+ chip->int_vref_mv = 2500; /* Build-in ref */
+ }
+
indio_dev->name = id->name;
indio_dev->channels = ad7291_channels;
indio_dev->num_channels = ARRAY_SIZE(ad7291_channels);
@@ -555,7 +585,7 @@ static int __devinit ad7291_probe(struct i2c_client *client,
id->name,
indio_dev);
if (ret)
- goto error_free_dev;
+ goto error_disable_reg;
/* set irq polarity low level */
chip->command |= AD7291_ALERT_POLARITY;
@@ -571,7 +601,7 @@ static int __devinit ad7291_probe(struct i2c_client *client,
if (ret)
goto error_unreg_irq;
- dev_info(&client->dev, "%s temperature sensor registered.\n",
+ dev_info(&client->dev, "%s ADC registered.\n",
id->name);
return 0;
@@ -579,7 +609,13 @@ static int __devinit ad7291_probe(struct i2c_client *client,
error_unreg_irq:
if (client->irq)
free_irq(client->irq, indio_dev);
-error_free_dev:
+error_disable_reg:
+ if (!IS_ERR(chip->reg))
+ regulator_disable(chip->reg);
+error_put_reg:
+ if (!IS_ERR(chip->reg))
+ regulator_put(chip->reg);
+
iio_free_device(indio_dev);
error_ret:
return ret;
@@ -588,9 +624,16 @@ error_ret:
static int __devexit ad7291_remove(struct i2c_client *client)
{
struct iio_dev *indio_dev = i2c_get_clientdata(client);
+ struct ad7291_chip_info *chip = iio_priv(indio_dev);
if (client->irq)
free_irq(client->irq, indio_dev);
+
+ if (!IS_ERR(chip->reg)) {
+ regulator_disable(chip->reg);
+ regulator_put(chip->reg);
+ }
+
iio_device_unregister(indio_dev);
return 0;
--
1.7.0.4
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [PATCH 05/12] iio: ad7291: don't swab results twice and introduce more register defines
2011-08-31 10:57 [PATCH 01/12] iio: ad7291: fix channel mapping michael.hennerich
` (2 preceding siblings ...)
2011-08-31 10:57 ` [PATCH 04/12] iio: ad7291: Add regulator, reference voltage and scale handling michael.hennerich
@ 2011-08-31 10:57 ` michael.hennerich
2011-08-31 11:28 ` Jonathan Cameron
2011-08-31 10:57 ` [PATCH 06/12] iio: ad7291: fix mask bit generation michael.hennerich
` (7 subsequent siblings)
11 siblings, 1 reply; 29+ messages in thread
From: michael.hennerich @ 2011-08-31 10:57 UTC (permalink / raw)
To: jic23; +Cc: linux-iio, device-drivers-devel, drivers, Michael Hennerich
From: Michael Hennerich <michael.hennerich@analog.com>
Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
---
drivers/staging/iio/adc/ad7291.c | 90 ++++++++++++++++++++++++-------------
1 files changed, 58 insertions(+), 32 deletions(-)
diff --git a/drivers/staging/iio/adc/ad7291.c b/drivers/staging/iio/adc/ad7291.c
index 382ca3e..2fafca7 100644
--- a/drivers/staging/iio/adc/ad7291.c
+++ b/drivers/staging/iio/adc/ad7291.c
@@ -33,18 +33,43 @@
/*
* AD7291 registers definition
*/
-#define AD7291_COMMAND 0
-#define AD7291_VOLTAGE 1
-#define AD7291_T_SENSE 2
-#define AD7291_T_AVERAGE 3
-#define AD7291_VOLTAGE_LIMIT_BASE 4
-#define AD7291_VOLTAGE_LIMIT_COUNT 8
+#define AD7291_COMMAND 0x00
+#define AD7291_VOLTAGE 0x01
+#define AD7291_T_SENSE 0x02
+#define AD7291_T_AVERAGE 0x03
+#define AD7291_CH0_DATA_HIGH 0x04
+#define AD7291_CH0_DATA_LOW 0x05
+#define AD7291_CH0_HYST 0x06
+#define AD7291_CH1_DATA_HIGH 0x07
+#define AD7291_CH1_DATA_LOW 0x08
+#define AD7291_CH1_HYST 0x09
+#define AD7291_CH2_DATA_HIGH 0x0A
+#define AD7291_CH2_DATA_LOW 0x0B
+#define AD7291_CH2_HYST 0x0C
+#define AD7291_CH3_DATA_HIGH 0x0D
+#define AD7291_CH3_DATA_LOW 0x0E
+#define AD7291_CH3_HYST 0x0F
+#define AD7291_CH4_DATA_HIGH 0x10
+#define AD7291_CH4_DATA_LOW 0x11
+#define AD7291_CH4_HYST 0x12
+#define AD7291_CH5_DATA_HIGH 0x13
+#define AD7291_CH5_DATA_LOW 0x14
+#define AD7291_CH5_HYST 0x15
+#define AD7291_CH6_DATA_HIGH 0x16
+#define AD7291_CH6_DATA_LOW 0x17
+#define AD7291_CH6_HYST 0x18
+#define AD7291_CH7_DATA_HIGH 0x19
+#define AD7291_CH7_DATA_LOW 0x1A
+#define AD7291_CH7_HYST 0x2B
#define AD7291_T_SENSE_HIGH 0x1C
#define AD7291_T_SENSE_LOW 0x1D
#define AD7291_T_SENSE_HYST 0x1E
#define AD7291_VOLTAGE_ALERT_STATUS 0x1F
#define AD7291_T_ALERT_STATUS 0x20
+#define AD7291_VOLTAGE_LIMIT_COUNT 8
+
+
/*
* AD7291 command
*/
@@ -197,7 +222,7 @@ static inline ssize_t ad7291_show_hyst(struct device *dev,
if (ret < 0)
return ret;
- return sprintf(buf, "%d\n", data & 0x0FFF);
+ return sprintf(buf, "%d\n", data & AD7291_VALUE_MASK);
}
static inline ssize_t ad7291_set_hyst(struct device *dev,
@@ -227,28 +252,28 @@ static IIO_DEVICE_ATTR(in_temp0_thresh_both_hyst_raw,
AD7291_T_SENSE_HYST);
static IIO_DEVICE_ATTR(in_voltage0_thresh_both_hyst_raw,
S_IRUGO | S_IWUSR,
- ad7291_show_hyst, ad7291_set_hyst, 0x06);
+ ad7291_show_hyst, ad7291_set_hyst, AD7291_CH0_HYST);
static IIO_DEVICE_ATTR(in_voltage1_thresh_both_hyst_raw,
S_IRUGO | S_IWUSR,
- ad7291_show_hyst, ad7291_set_hyst, 0x09);
+ ad7291_show_hyst, ad7291_set_hyst, AD7291_CH1_HYST);
static IIO_DEVICE_ATTR(in_voltage2_thresh_both_hyst_raw,
S_IRUGO | S_IWUSR,
- ad7291_show_hyst, ad7291_set_hyst, 0x0C);
+ ad7291_show_hyst, ad7291_set_hyst, AD7291_CH2_HYST);
static IIO_DEVICE_ATTR(in_voltage3_thresh_both_hyst_raw,
S_IRUGO | S_IWUSR,
- ad7291_show_hyst, ad7291_set_hyst, 0x0F);
+ ad7291_show_hyst, ad7291_set_hyst, AD7291_CH3_HYST);
static IIO_DEVICE_ATTR(in_voltage4_thresh_both_hyst_raw,
S_IRUGO | S_IWUSR,
- ad7291_show_hyst, ad7291_set_hyst, 0x12);
+ ad7291_show_hyst, ad7291_set_hyst, AD7291_CH4_HYST);
static IIO_DEVICE_ATTR(in_voltage5_thresh_both_hyst_raw,
S_IRUGO | S_IWUSR,
- ad7291_show_hyst, ad7291_set_hyst, 0x15);
+ ad7291_show_hyst, ad7291_set_hyst, AD7291_CH5_HYST);
static IIO_DEVICE_ATTR(in_voltage6_thresh_both_hyst_raw,
S_IRUGO | S_IWUSR,
- ad7291_show_hyst, ad7291_set_hyst, 0x18);
+ ad7291_show_hyst, ad7291_set_hyst, AD7291_CH6_HYST);
static IIO_DEVICE_ATTR(in_voltage7_thresh_both_hyst_raw,
S_IRUGO | S_IWUSR,
- ad7291_show_hyst, ad7291_set_hyst, 0x1B);
+ ad7291_show_hyst, ad7291_set_hyst, AD7291_CH7_HYST);
static struct attribute *ad7291_event_attributes[] = {
&iio_dev_attr_in_temp0_thresh_both_hyst_raw.dev_attr.attr,
@@ -265,16 +290,16 @@ static struct attribute *ad7291_event_attributes[] = {
/* high / low */
static u8 ad7291_limit_regs[9][2] = {
- { 0x04, 0x05 },
- { 0x07, 0x08 },
- { 0x0A, 0x0B },
- { 0x0E, 0x0D }, /* note reversed order */
- { 0x10, 0x11 },
- { 0x13, 0x14 },
- { 0x16, 0x17 },
- { 0x19, 0x1A },
+ { AD7291_CH0_DATA_HIGH, AD7291_CH0_DATA_LOW },
+ { AD7291_CH1_DATA_HIGH, AD7291_CH1_DATA_LOW },
+ { AD7291_CH2_DATA_HIGH, AD7291_CH2_DATA_LOW },
+ { AD7291_CH3_DATA_HIGH, AD7291_CH3_DATA_LOW }, /* FIXME: ? */
+ { AD7291_CH4_DATA_HIGH, AD7291_CH4_DATA_LOW },
+ { AD7291_CH5_DATA_HIGH, AD7291_CH5_DATA_LOW },
+ { AD7291_CH6_DATA_HIGH, AD7291_CH6_DATA_LOW },
+ { AD7291_CH7_DATA_HIGH, AD7291_CH7_DATA_LOW },
/* temp */
- { 0x1C, 0x1D },
+ { AD7291_T_SENSE_HIGH, AD7291_T_SENSE_LOW },
};
static int ad7291_read_event_value(struct iio_dev *indio_dev,
@@ -297,7 +322,7 @@ static int ad7291_read_event_value(struct iio_dev *indio_dev,
ret = ad7291_i2c_read(chip, reg, &uval);
if (ret < 0)
return ret;
- *val = swab16(uval) & 0x0FFF;
+ *val = uval & AD7291_VALUE_MASK;
return 0;
case IIO_TEMP:
@@ -308,7 +333,7 @@ static int ad7291_read_event_value(struct iio_dev *indio_dev,
ret = ad7291_i2c_read(chip, reg, &signval);
if (ret < 0)
return ret;
- signval = (s16)((swab16(signval) & 0x0FFF) << 4) >> 4;
+ signval = (s16)((signval & AD7291_VALUE_MASK) << 4) >> 4;
*val = signval;
return 0;
default:
@@ -331,9 +356,7 @@ static int ad7291_write_event_value(struct iio_dev *indio_dev,
reg = ad7291_limit_regs[IIO_EVENT_CODE_EXTRACT_NUM(event_code)]
[!(IIO_EVENT_CODE_EXTRACT_DIR(event_code) ==
IIO_EV_DIR_RISING)];
-
return ad7291_i2c_write(chip, reg, val);
-
case IIO_TEMP:
if (val > 2047 || val < -2048)
return -EINVAL;
@@ -385,6 +408,7 @@ static int ad7291_write_event_config(struct iio_dev *indio_dev,
* use continuous sampling mode.
* Possible to disable temp as well but that makes single read tricky.
*/
+
switch (IIO_EVENT_CODE_EXTRACT_TYPE(event_code)) {
case IIO_VOLTAGE:
if ((!state) && (chip->c_mask &
@@ -398,7 +422,7 @@ static int ad7291_write_event_config(struct iio_dev *indio_dev,
else
break;
- regval &= 0xFFFE;
+ regval &= ~AD7291_AUTOCYCLE;
regval |= ((u16)chip->c_mask << 8);
if (chip->c_mask) /* Enable autocycle? */
regval |= AD7291_AUTOCYCLE;
@@ -455,7 +479,7 @@ static int ad7291_read_raw(struct iio_dev *indio_dev,
mutex_unlock(&chip->state_lock);
return ret;
}
- *val = swab16((u16)ret) & 0x0FFF;
+ *val = swab16((u16)ret) & AD7291_VALUE_MASK;
mutex_unlock(&chip->state_lock);
return IIO_VAL_INT;
case IIO_TEMP:
@@ -464,7 +488,8 @@ static int ad7291_read_raw(struct iio_dev *indio_dev,
AD7291_T_SENSE);
if (ret < 0)
return ret;
- signval = (s16)((swab16((u16)ret) & 0x0FFF) << 4) >> 4;
+ signval = (s16)((swab16((u16)ret) &
+ AD7291_VALUE_MASK) << 4) >> 4;
*val = signval;
return IIO_VAL_INT;
default:
@@ -475,7 +500,8 @@ static int ad7291_read_raw(struct iio_dev *indio_dev,
AD7291_T_AVERAGE);
if (ret < 0)
return ret;
- signval = (s16)((swab16((u16)ret) & 0x0FFF) << 4) >> 4;
+ signval = (s16)((swab16((u16)ret) &
+ AD7291_VALUE_MASK) << 4) >> 4;
*val = signval;
return IIO_VAL_INT;
case (1 << IIO_CHAN_INFO_SCALE_SHARED):
--
1.7.0.4
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [PATCH 06/12] iio: ad7291: fix mask bit generation
2011-08-31 10:57 [PATCH 01/12] iio: ad7291: fix channel mapping michael.hennerich
` (3 preceding siblings ...)
2011-08-31 10:57 ` [PATCH 05/12] iio: ad7291: don't swab results twice and introduce more register defines michael.hennerich
@ 2011-08-31 10:57 ` michael.hennerich
2011-08-31 11:29 ` Jonathan Cameron
2011-08-31 10:57 ` [PATCH 07/12] iio: ad7291: introduce IIO_EVENT_CODE_EXTRACT_CHAN_TYPE and use accordingly michael.hennerich
` (6 subsequent siblings)
11 siblings, 1 reply; 29+ messages in thread
From: michael.hennerich @ 2011-08-31 10:57 UTC (permalink / raw)
To: jic23; +Cc: linux-iio, device-drivers-devel, drivers, Michael Hennerich
From: Michael Hennerich <michael.hennerich@analog.com>
Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
---
drivers/staging/iio/adc/ad7291.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/drivers/staging/iio/adc/ad7291.c b/drivers/staging/iio/adc/ad7291.c
index 2fafca7..7dfdc27 100644
--- a/drivers/staging/iio/adc/ad7291.c
+++ b/drivers/staging/iio/adc/ad7291.c
@@ -417,7 +417,7 @@ static int ad7291_write_event_config(struct iio_dev *indio_dev,
~(1 << IIO_EVENT_CODE_EXTRACT_NUM(event_code));
else if (state && (!(chip->c_mask &
(1 << IIO_EVENT_CODE_EXTRACT_NUM(event_code)))))
- chip->c_mask &=
+ chip->c_mask |=
(1 << IIO_EVENT_CODE_EXTRACT_NUM(event_code));
else
break;
--
1.7.0.4
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [PATCH 07/12] iio: ad7291: introduce IIO_EVENT_CODE_EXTRACT_CHAN_TYPE and use accordingly
2011-08-31 10:57 [PATCH 01/12] iio: ad7291: fix channel mapping michael.hennerich
` (4 preceding siblings ...)
2011-08-31 10:57 ` [PATCH 06/12] iio: ad7291: fix mask bit generation michael.hennerich
@ 2011-08-31 10:57 ` michael.hennerich
2011-08-31 11:33 ` Jonathan Cameron
2011-08-31 10:57 ` [PATCH 08/12] iio: ad7291: fix channel mapping for event enables michael.hennerich
` (5 subsequent siblings)
11 siblings, 1 reply; 29+ messages in thread
From: michael.hennerich @ 2011-08-31 10:57 UTC (permalink / raw)
To: jic23; +Cc: linux-iio, device-drivers-devel, drivers, Michael Hennerich
From: Michael Hennerich <michael.hennerich@analog.com>
Fix channel type handling
Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
---
drivers/staging/iio/adc/ad7291.c | 6 +++---
drivers/staging/iio/sysfs.h | 1 +
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/staging/iio/adc/ad7291.c b/drivers/staging/iio/adc/ad7291.c
index 7dfdc27..b365a74 100644
--- a/drivers/staging/iio/adc/ad7291.c
+++ b/drivers/staging/iio/adc/ad7291.c
@@ -313,7 +313,7 @@ static int ad7291_read_event_value(struct iio_dev *indio_dev,
u16 uval;
s16 signval;
- switch (IIO_EVENT_CODE_EXTRACT_TYPE(event_code)) {
+ switch (IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(event_code)) {
case IIO_VOLTAGE:
reg = ad7291_limit_regs[IIO_EVENT_CODE_EXTRACT_NUM(event_code)]
[!(IIO_EVENT_CODE_EXTRACT_DIR(event_code) ==
@@ -349,7 +349,7 @@ static int ad7291_write_event_value(struct iio_dev *indio_dev,
u8 reg;
s16 signval;
- switch (IIO_EVENT_CODE_EXTRACT_TYPE(event_code)) {
+ switch (IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(event_code)) {
case IIO_VOLTAGE:
if (val > 0xFFF || val < 0)
return -EINVAL;
@@ -377,7 +377,7 @@ static int ad7291_read_event_config(struct iio_dev *indio_dev,
/* To be enabled the channel must simply be on. If any are enabled
we are in continuous sampling mode */
- switch (IIO_EVENT_CODE_EXTRACT_TYPE(event_code)) {
+ switch (IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(event_code)) {
case IIO_VOLTAGE:
if (chip->c_mask &
(1 << IIO_EVENT_CODE_EXTRACT_NUM(event_code)))
diff --git a/drivers/staging/iio/sysfs.h b/drivers/staging/iio/sysfs.h
index aad1f4b..d98d12d 100644
--- a/drivers/staging/iio/sysfs.h
+++ b/drivers/staging/iio/sysfs.h
@@ -147,6 +147,7 @@ enum iio_event_direction {
#define IIO_EVENT_CODE_EXTRACT_TYPE(mask) ((mask >> 56) & 0xFF)
#define IIO_EVENT_CODE_EXTRACT_DIR(mask) ((mask >> 48) & 0xFF)
+#define IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(mask) ((mask >> 32) & 0xFF)
/* Event code number extraction depends on which type of event we have.
* Perhaps review this function in the future*/
--
1.7.0.4
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [PATCH 08/12] iio: ad7291: fix channel mapping for event enables
2011-08-31 10:57 [PATCH 01/12] iio: ad7291: fix channel mapping michael.hennerich
` (5 preceding siblings ...)
2011-08-31 10:57 ` [PATCH 07/12] iio: ad7291: introduce IIO_EVENT_CODE_EXTRACT_CHAN_TYPE and use accordingly michael.hennerich
@ 2011-08-31 10:57 ` michael.hennerich
2011-08-31 11:34 ` Jonathan Cameron
2011-08-31 10:57 ` [PATCH 09/12] iio: core: fix IIO_EVENT_CODE_EXTRACT_DIR definition michael.hennerich
` (4 subsequent siblings)
11 siblings, 1 reply; 29+ messages in thread
From: michael.hennerich @ 2011-08-31 10:57 UTC (permalink / raw)
To: jic23; +Cc: linux-iio, device-drivers-devel, drivers, Michael Hennerich
From: Michael Hennerich <michael.hennerich@analog.com>
Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
---
drivers/staging/iio/adc/ad7291.c | 24 ++++++++++++------------
1 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/drivers/staging/iio/adc/ad7291.c b/drivers/staging/iio/adc/ad7291.c
index b365a74..1a2fa66 100644
--- a/drivers/staging/iio/adc/ad7291.c
+++ b/drivers/staging/iio/adc/ad7291.c
@@ -100,7 +100,7 @@ struct ad7291_chip_info {
struct regulator *reg;
u16 int_vref_mv;
u16 command;
- u8 c_mask; /* Active voltage channels for events */
+ u16 c_mask; /* Active voltage channels for events */
struct mutex state_lock;
};
@@ -380,7 +380,7 @@ static int ad7291_read_event_config(struct iio_dev *indio_dev,
switch (IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(event_code)) {
case IIO_VOLTAGE:
if (chip->c_mask &
- (1 << IIO_EVENT_CODE_EXTRACT_NUM(event_code)))
+ (1 << (15 - IIO_EVENT_CODE_EXTRACT_NUM(event_code))))
return 1;
else
return 0;
@@ -411,19 +411,19 @@ static int ad7291_write_event_config(struct iio_dev *indio_dev,
switch (IIO_EVENT_CODE_EXTRACT_TYPE(event_code)) {
case IIO_VOLTAGE:
- if ((!state) && (chip->c_mask &
- (1 << IIO_EVENT_CODE_EXTRACT_NUM(event_code))))
- chip->c_mask &=
- ~(1 << IIO_EVENT_CODE_EXTRACT_NUM(event_code));
- else if (state && (!(chip->c_mask &
- (1 << IIO_EVENT_CODE_EXTRACT_NUM(event_code)))))
- chip->c_mask |=
- (1 << IIO_EVENT_CODE_EXTRACT_NUM(event_code));
+ if ((!state) && (chip->c_mask & (1 << (15 -
+ IIO_EVENT_CODE_EXTRACT_NUM(event_code)))))
+ chip->c_mask &= ~(1 << (15 - IIO_EVENT_CODE_EXTRACT_NUM
+ (event_code)));
+ else if (state && (!(chip->c_mask & (1 << (15 -
+ IIO_EVENT_CODE_EXTRACT_NUM(event_code))))))
+ chip->c_mask |= (1 << (15 - IIO_EVENT_CODE_EXTRACT_NUM
+ (event_code)));
else
break;
regval &= ~AD7291_AUTOCYCLE;
- regval |= ((u16)chip->c_mask << 8);
+ regval |= chip->c_mask;
if (chip->c_mask) /* Enable autocycle? */
regval |= AD7291_AUTOCYCLE;
@@ -460,7 +460,7 @@ static int ad7291_read_raw(struct iio_dev *indio_dev,
case IIO_VOLTAGE:
mutex_lock(&chip->state_lock);
/* If in autocycle mode drop through */
- if (chip->command & 0x1) {
+ if (chip->command & AD7291_AUTOCYCLE) {
mutex_unlock(&chip->state_lock);
return -EBUSY;
}
--
1.7.0.4
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [PATCH 09/12] iio: core: fix IIO_EVENT_CODE_EXTRACT_DIR definition
2011-08-31 10:57 [PATCH 01/12] iio: ad7291: fix channel mapping michael.hennerich
` (6 preceding siblings ...)
2011-08-31 10:57 ` [PATCH 08/12] iio: ad7291: fix channel mapping for event enables michael.hennerich
@ 2011-08-31 10:57 ` michael.hennerich
2011-08-31 11:15 ` Jonathan Cameron
2011-08-31 10:57 ` [PATCH 10/12] iio: ad7192: return len and fix out of range checking michael.hennerich
` (3 subsequent siblings)
11 siblings, 1 reply; 29+ messages in thread
From: michael.hennerich @ 2011-08-31 10:57 UTC (permalink / raw)
To: jic23; +Cc: linux-iio, device-drivers-devel, drivers, Michael Hennerich
From: Michael Hennerich <michael.hennerich@analog.com>
Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
---
drivers/staging/iio/sysfs.h | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/drivers/staging/iio/sysfs.h b/drivers/staging/iio/sysfs.h
index d98d12d..8de6a65 100644
--- a/drivers/staging/iio/sysfs.h
+++ b/drivers/staging/iio/sysfs.h
@@ -146,7 +146,7 @@ enum iio_event_direction {
IIO_EVENT_CODE(channelclass, 0, 0, direction, type, number, 0, 0)
#define IIO_EVENT_CODE_EXTRACT_TYPE(mask) ((mask >> 56) & 0xFF)
-#define IIO_EVENT_CODE_EXTRACT_DIR(mask) ((mask >> 48) & 0xFF)
+#define IIO_EVENT_CODE_EXTRACT_DIR(mask) ((mask >> 47) & 0xFF)
#define IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(mask) ((mask >> 32) & 0xFF)
/* Event code number extraction depends on which type of event we have.
--
1.7.0.4
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [PATCH 10/12] iio: ad7192: return len and fix out of range checking
2011-08-31 10:57 [PATCH 01/12] iio: ad7291: fix channel mapping michael.hennerich
` (7 preceding siblings ...)
2011-08-31 10:57 ` [PATCH 09/12] iio: core: fix IIO_EVENT_CODE_EXTRACT_DIR definition michael.hennerich
@ 2011-08-31 10:57 ` michael.hennerich
2011-08-31 11:37 ` Jonathan Cameron
2011-08-31 10:57 ` [PATCH 11/12] iio: ad7291: reset device and setup irq before it is enabled michael.hennerich
` (2 subsequent siblings)
11 siblings, 1 reply; 29+ messages in thread
From: michael.hennerich @ 2011-08-31 10:57 UTC (permalink / raw)
To: jic23; +Cc: linux-iio, device-drivers-devel, drivers, Michael Hennerich
From: Michael Hennerich <michael.hennerich@analog.com>
Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
---
drivers/staging/iio/adc/ad7291.c | 10 +++++++---
1 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/drivers/staging/iio/adc/ad7291.c b/drivers/staging/iio/adc/ad7291.c
index 1a2fa66..334951c 100644
--- a/drivers/staging/iio/adc/ad7291.c
+++ b/drivers/staging/iio/adc/ad7291.c
@@ -240,10 +240,14 @@ static inline ssize_t ad7291_set_hyst(struct device *dev,
if (ret < 0)
return ret;
- if (data < 4096)
+ if (data > AD7291_VALUE_MASK)
return -EINVAL;
- return ad7291_i2c_write(chip, this_attr->address, data);
+ ret = ad7291_i2c_write(chip, this_attr->address, data);
+ if (ret < 0)
+ return ret;
+
+ return len;
}
static IIO_DEVICE_ATTR(in_temp0_thresh_both_hyst_raw,
@@ -351,7 +355,7 @@ static int ad7291_write_event_value(struct iio_dev *indio_dev,
switch (IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(event_code)) {
case IIO_VOLTAGE:
- if (val > 0xFFF || val < 0)
+ if (val > AD7291_VALUE_MASK || val < 0)
return -EINVAL;
reg = ad7291_limit_regs[IIO_EVENT_CODE_EXTRACT_NUM(event_code)]
[!(IIO_EVENT_CODE_EXTRACT_DIR(event_code) ==
--
1.7.0.4
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [PATCH 11/12] iio: ad7291: reset device and setup irq before it is enabled
2011-08-31 10:57 [PATCH 01/12] iio: ad7291: fix channel mapping michael.hennerich
` (8 preceding siblings ...)
2011-08-31 10:57 ` [PATCH 10/12] iio: ad7192: return len and fix out of range checking michael.hennerich
@ 2011-08-31 10:57 ` michael.hennerich
2011-08-31 11:39 ` Jonathan Cameron
2011-08-31 10:57 ` [PATCH 12/12] iio: ad7192: add temp_scale attribute, change module description michael.hennerich
2011-08-31 11:14 ` [PATCH 01/12] iio: ad7291: fix channel mapping Jonathan Cameron
11 siblings, 1 reply; 29+ messages in thread
From: michael.hennerich @ 2011-08-31 10:57 UTC (permalink / raw)
To: jic23; +Cc: linux-iio, device-drivers-devel, drivers, Michael Hennerich
From: Michael Hennerich <michael.hennerich@analog.com>
Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
---
drivers/staging/iio/adc/ad7291.c | 27 ++++++++++++++++-----------
1 files changed, 16 insertions(+), 11 deletions(-)
diff --git a/drivers/staging/iio/adc/ad7291.c b/drivers/staging/iio/adc/ad7291.c
index 334951c..0811c5e 100644
--- a/drivers/staging/iio/adc/ad7291.c
+++ b/drivers/staging/iio/adc/ad7291.c
@@ -589,8 +589,10 @@ static int __devinit ad7291_probe(struct i2c_client *client,
i2c_set_clientdata(client, indio_dev);
chip->client = client;
- /* Tsense always enabled */
- chip->command = AD7291_NOISE_DELAY | AD7291_T_SENSE_MASK;
+
+ chip->command = AD7291_NOISE_DELAY |
+ AD7291_T_SENSE_MASK | /* Tsense always enabled */
+ AD7291_ALERT_POLARITY; /* set irq polarity low level */
if (voltage_uv) {
chip->int_vref_mv = voltage_uv / 1000;
@@ -607,6 +609,18 @@ static int __devinit ad7291_probe(struct i2c_client *client,
indio_dev->info = &ad7291_info;
indio_dev->modes = INDIO_DIRECT_MODE;
+ ret = ad7291_i2c_write(chip, AD7291_COMMAND, AD7291_RESET);
+ if (ret) {
+ ret = -EIO;
+ goto error_disable_reg;
+ }
+
+ ret = ad7291_i2c_write(chip, AD7291_COMMAND, chip->command);
+ if (ret) {
+ ret = -EIO;
+ goto error_disable_reg;
+ }
+
if (client->irq > 0) {
ret = request_threaded_irq(client->irq,
NULL,
@@ -616,15 +630,6 @@ static int __devinit ad7291_probe(struct i2c_client *client,
indio_dev);
if (ret)
goto error_disable_reg;
-
- /* set irq polarity low level */
- chip->command |= AD7291_ALERT_POLARITY;
- }
-
- ret = ad7291_i2c_write(chip, AD7291_COMMAND, chip->command);
- if (ret) {
- ret = -EIO;
- goto error_unreg_irq;
}
ret = iio_device_register(indio_dev);
--
1.7.0.4
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [PATCH 12/12] iio: ad7192: add temp_scale attribute, change module description
2011-08-31 10:57 [PATCH 01/12] iio: ad7291: fix channel mapping michael.hennerich
` (9 preceding siblings ...)
2011-08-31 10:57 ` [PATCH 11/12] iio: ad7291: reset device and setup irq before it is enabled michael.hennerich
@ 2011-08-31 10:57 ` michael.hennerich
2011-08-31 11:52 ` Jonathan Cameron
2011-08-31 11:14 ` [PATCH 01/12] iio: ad7291: fix channel mapping Jonathan Cameron
11 siblings, 1 reply; 29+ messages in thread
From: michael.hennerich @ 2011-08-31 10:57 UTC (permalink / raw)
To: jic23; +Cc: linux-iio, device-drivers-devel, drivers, Michael Hennerich
From: Michael Hennerich <michael.hennerich@analog.com>
Use KBUILD_MODNAME
Fix indention style
Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
---
drivers/staging/iio/adc/ad7291.c | 17 ++++++++++++-----
1 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/drivers/staging/iio/adc/ad7291.c b/drivers/staging/iio/adc/ad7291.c
index 0811c5e..636e635 100644
--- a/drivers/staging/iio/adc/ad7291.c
+++ b/drivers/staging/iio/adc/ad7291.c
@@ -101,7 +101,7 @@ struct ad7291_chip_info {
u16 int_vref_mv;
u16 command;
u16 c_mask; /* Active voltage channels for events */
- struct mutex state_lock;
+ struct mutex state_lock;
};
static int ad7291_i2c_read(struct ad7291_chip_info *chip, u8 reg, u16 *data)
@@ -513,6 +513,13 @@ static int ad7291_read_raw(struct iio_dev *indio_dev,
*val = scale_uv / 1000;
*val2 = (scale_uv % 1000) * 1000;
return IIO_VAL_INT_PLUS_MICRO;
+ case (1 << IIO_CHAN_INFO_SCALE_SEPARATE):
+ /*
+ * One LSB of the ADC corresponds to 0.25 deg C.
+ * The temperature reading is in 12-bit twos complement format
+ */
+ *val = 250;
+ return IIO_VAL_INT;
default:
return -EINVAL;
}
@@ -539,7 +546,8 @@ static const struct iio_chan_spec ad7291_channels[] = {
AD7291_VOLTAGE_CHAN(7),
{
.type = IIO_TEMP,
- .info_mask = (1 << IIO_CHAN_INFO_AVERAGE_RAW_SEPARATE),
+ .info_mask = (1 << IIO_CHAN_INFO_AVERAGE_RAW_SEPARATE) |
+ (1 << IIO_CHAN_INFO_SCALE_SEPARATE),
.indexed = 1,
.channel = 0,
.event_mask =
@@ -683,7 +691,7 @@ MODULE_DEVICE_TABLE(i2c, ad7291_id);
static struct i2c_driver ad7291_driver = {
.driver = {
- .name = "ad7291",
+ .name = KBUILD_MODNAME,
},
.probe = ad7291_probe,
.remove = __devexit_p(ad7291_remove),
@@ -701,8 +709,7 @@ static __exit void ad7291_exit(void)
}
MODULE_AUTHOR("Sonic Zhang <sonic.zhang@analog.com>");
-MODULE_DESCRIPTION("Analog Devices AD7291 digital"
- " temperature sensor driver");
+MODULE_DESCRIPTION("Analog Devices AD7291 ADC driver");
MODULE_LICENSE("GPL v2");
module_init(ad7291_init);
--
1.7.0.4
^ permalink raw reply related [flat|nested] 29+ messages in thread
* Re: [PATCH 01/12] iio: ad7291: fix channel mapping
2011-08-31 10:57 [PATCH 01/12] iio: ad7291: fix channel mapping michael.hennerich
` (10 preceding siblings ...)
2011-08-31 10:57 ` [PATCH 12/12] iio: ad7192: add temp_scale attribute, change module description michael.hennerich
@ 2011-08-31 11:14 ` Jonathan Cameron
11 siblings, 0 replies; 29+ messages in thread
From: Jonathan Cameron @ 2011-08-31 11:14 UTC (permalink / raw)
To: michael.hennerich; +Cc: linux-iio, device-drivers-devel, drivers
On 08/31/11 11:57, michael.hennerich@analog.com wrote:
> From: Michael Hennerich <michael.hennerich@analog.com>
>
> ideally in_voltageX_raw should map to AD7291 VINX.
>
Indeed, that's more logical.
> Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
Merged to iio-blue.
> ---
> drivers/staging/iio/adc/ad7291.c | 2 +-
> 1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/drivers/staging/iio/adc/ad7291.c b/drivers/staging/iio/adc/ad7291.c
> index b6be672..32944f3 100644
> --- a/drivers/staging/iio/adc/ad7291.c
> +++ b/drivers/staging/iio/adc/ad7291.c
> @@ -434,7 +434,7 @@ static int ad7291_read_raw(struct iio_dev *indio_dev,
> }
> /* Enable this channel alone */
> regval = chip->command & (~AD7291_VOLTAGE_MASK);
> - regval |= 1 << (chan->channel + 8);
> + regval |= 1 << (15 - chan->channel);
> ret = ad7291_i2c_write(chip, AD7291_COMMAND, regval);
> if (ret < 0) {
> mutex_unlock(&chip->state_lock);
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATCH 09/12] iio: core: fix IIO_EVENT_CODE_EXTRACT_DIR definition
2011-08-31 10:57 ` [PATCH 09/12] iio: core: fix IIO_EVENT_CODE_EXTRACT_DIR definition michael.hennerich
@ 2011-08-31 11:15 ` Jonathan Cameron
2011-08-31 12:01 ` Jonathan Cameron
0 siblings, 1 reply; 29+ messages in thread
From: Jonathan Cameron @ 2011-08-31 11:15 UTC (permalink / raw)
To: michael.hennerich; +Cc: linux-iio, device-drivers-devel, drivers
On 08/31/11 11:57, michael.hennerich@analog.com wrote:
> From: Michael Hennerich <michael.hennerich@analog.com>
>
>
Gah and good spot. I'll merge that one down into the patch that introduced it
with appropriate comment.
> Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
> ---
> drivers/staging/iio/sysfs.h | 2 +-
> 1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/drivers/staging/iio/sysfs.h b/drivers/staging/iio/sysfs.h
> index d98d12d..8de6a65 100644
> --- a/drivers/staging/iio/sysfs.h
> +++ b/drivers/staging/iio/sysfs.h
> @@ -146,7 +146,7 @@ enum iio_event_direction {
> IIO_EVENT_CODE(channelclass, 0, 0, direction, type, number, 0, 0)
>
> #define IIO_EVENT_CODE_EXTRACT_TYPE(mask) ((mask >> 56) & 0xFF)
> -#define IIO_EVENT_CODE_EXTRACT_DIR(mask) ((mask >> 48) & 0xFF)
> +#define IIO_EVENT_CODE_EXTRACT_DIR(mask) ((mask >> 47) & 0xFF)
> #define IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(mask) ((mask >> 32) & 0xFF)
>
> /* Event code number extraction depends on which type of event we have.
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATCH 02/12] iio: ad7291: Fix typos, change kconfig description and file header
2011-08-31 10:57 ` [PATCH 02/12] iio: ad7291: Fix typos, change kconfig description and file header michael.hennerich
@ 2011-08-31 11:18 ` Jonathan Cameron
0 siblings, 0 replies; 29+ messages in thread
From: Jonathan Cameron @ 2011-08-31 11:18 UTC (permalink / raw)
To: michael.hennerich; +Cc: linux-iio, device-drivers-devel, drivers
On 08/31/11 11:57, michael.hennerich@analog.com wrote:
> From: Michael Hennerich <michael.hennerich@analog.com>
>
> Make clear the AD7291 is primarily an ADC, and not a temp sensor.
Good point. As a note I'm renaming all these patches to slightly to
make them fit with the rest of the updates series they will go in.
Trivial to do whilst signing off on them anyway!
>
> Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
merged.
> ---
> drivers/staging/iio/adc/Kconfig | 4 ++--
> drivers/staging/iio/adc/ad7291.c | 14 +++++++-------
> 2 files changed, 9 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/staging/iio/adc/Kconfig b/drivers/staging/iio/adc/Kconfig
> index 25566c6..7867ab1 100644
> --- a/drivers/staging/iio/adc/Kconfig
> +++ b/drivers/staging/iio/adc/Kconfig
> @@ -18,11 +18,11 @@ config AD7152
> (ad7152, ad7153) Provides direct access via sysfs.
>
> config AD7291
> - tristate "Analog Devices AD7291 temperature sensor driver"
> + tristate "Analog Devices AD7291 ADC driver"
> depends on I2C
> help
> Say yes here to build support for Analog Devices AD7291
> - temperature sensors.
> + 8 Channel ADC with temperature sensor.
>
> config AD7298
> tristate "Analog Devices AD7298 ADC driver"
> diff --git a/drivers/staging/iio/adc/ad7291.c b/drivers/staging/iio/adc/ad7291.c
> index 32944f3..d47df4a 100644
> --- a/drivers/staging/iio/adc/ad7291.c
> +++ b/drivers/staging/iio/adc/ad7291.c
> @@ -1,7 +1,7 @@
> /*
> - * AD7291 digital temperature sensor driver supporting AD7291
> + * AD7291 8-Channel, I2C, 12-Bit SAR ADC with Temperature Sensor
> *
> - * Copyright 2010 Analog Devices Inc.
> + * Copyright 2010-2011 Analog Devices Inc.
> *
> * Licensed under the GPL-2 or later.
> */
> @@ -48,8 +48,8 @@
> */
> #define AD7291_AUTOCYCLE 0x1
> #define AD7291_RESET 0x2
> -#define AD7291_ALART_CLEAR 0x4
> -#define AD7291_ALART_POLARITY 0x8
> +#define AD7291_ALERT_CLEAR 0x4
> +#define AD7291_ALERT_POLARITY 0x8
> #define AD7291_EXT_REF 0x10
> #define AD7291_NOISE_DELAY 0x20
> #define AD7291_T_SENSE_MASK 0x40
> @@ -134,10 +134,10 @@ static irqreturn_t ad7291_event_handler(int irq, void *private)
> if (!(t_status || v_status))
> return IRQ_HANDLED;
>
> - command = chip->command | AD7291_ALART_CLEAR;
> + command = chip->command | AD7291_ALERT_CLEAR;
> ad7291_i2c_write(chip, AD7291_COMMAND, command);
>
> - command = chip->command & ~AD7291_ALART_CLEAR;
> + command = chip->command & ~AD7291_ALERT_CLEAR;
> ad7291_i2c_write(chip, AD7291_COMMAND, command);
>
> /* For now treat t_sense and t_sense_average the same */
> @@ -558,7 +558,7 @@ static int __devinit ad7291_probe(struct i2c_client *client,
> goto error_free_dev;
>
> /* set irq polarity low level */
> - chip->command |= AD7291_ALART_POLARITY;
> + chip->command |= AD7291_ALERT_POLARITY;
> }
>
> ret = ad7291_i2c_write(chip, AD7291_COMMAND, chip->command);
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATCH 03/12] iio: ad7291: Fix AD7291_T_SENSE_MASK
2011-08-31 10:57 ` [PATCH 03/12] iio: ad7291: Fix AD7291_T_SENSE_MASK michael.hennerich
@ 2011-08-31 11:19 ` Jonathan Cameron
0 siblings, 0 replies; 29+ messages in thread
From: Jonathan Cameron @ 2011-08-31 11:19 UTC (permalink / raw)
To: michael.hennerich; +Cc: linux-iio, device-drivers-devel, drivers
On 08/31/11 11:57, michael.hennerich@analog.com wrote:
> From: Michael Hennerich <michael.hennerich@analog.com>
>
> AD7291_T_SENSE_MASK must set bit-7.
> Change definition style.
>
> Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
Merged
> ---
> drivers/staging/iio/adc/ad7291.c | 28 ++++++++++++++--------------
> 1 files changed, 14 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/staging/iio/adc/ad7291.c b/drivers/staging/iio/adc/ad7291.c
> index d47df4a..dda6bcb 100644
> --- a/drivers/staging/iio/adc/ad7291.c
> +++ b/drivers/staging/iio/adc/ad7291.c
> @@ -37,30 +37,30 @@
> #define AD7291_T_AVERAGE 3
> #define AD7291_VOLTAGE_LIMIT_BASE 4
> #define AD7291_VOLTAGE_LIMIT_COUNT 8
> -#define AD7291_T_SENSE_HIGH 0x1c
> -#define AD7291_T_SENSE_LOW 0x1d
> -#define AD7291_T_SENSE_HYST 0x1e
> -#define AD7291_VOLTAGE_ALERT_STATUS 0x1f
> +#define AD7291_T_SENSE_HIGH 0x1C
> +#define AD7291_T_SENSE_LOW 0x1D
> +#define AD7291_T_SENSE_HYST 0x1E
> +#define AD7291_VOLTAGE_ALERT_STATUS 0x1F
> #define AD7291_T_ALERT_STATUS 0x20
>
> /*
> * AD7291 command
> */
> -#define AD7291_AUTOCYCLE 0x1
> -#define AD7291_RESET 0x2
> -#define AD7291_ALERT_CLEAR 0x4
> -#define AD7291_ALERT_POLARITY 0x8
> -#define AD7291_EXT_REF 0x10
> -#define AD7291_NOISE_DELAY 0x20
> -#define AD7291_T_SENSE_MASK 0x40
> -#define AD7291_VOLTAGE_MASK 0xff00
> +#define AD7291_AUTOCYCLE (1 << 0)
> +#define AD7291_RESET (1 << 1)
> +#define AD7291_ALERT_CLEAR (1 << 2)
> +#define AD7291_ALERT_POLARITY (1 << 3)
> +#define AD7291_EXT_REF (1 << 4)
> +#define AD7291_NOISE_DELAY (1 << 5)
> +#define AD7291_T_SENSE_MASK (1 << 7)
> +#define AD7291_VOLTAGE_MASK 0xFF00
> #define AD7291_VOLTAGE_OFFSET 0x8
>
> /*
> * AD7291 value masks
> */
> -#define AD7291_CHANNEL_MASK 0xf000
> -#define AD7291_VALUE_MASK 0xfff
> +#define AD7291_CHANNEL_MASK 0xF000
> +#define AD7291_VALUE_MASK 0xFFF
> #define AD7291_T_VALUE_SIGN 0x400
> #define AD7291_T_VALUE_FLOAT_OFFSET 2
> #define AD7291_T_VALUE_FLOAT_MASK 0x2
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATCH 04/12] iio: ad7291: Add regulator, reference voltage and scale handling
2011-08-31 10:57 ` [PATCH 04/12] iio: ad7291: Add regulator, reference voltage and scale handling michael.hennerich
@ 2011-08-31 11:22 ` Jonathan Cameron
0 siblings, 0 replies; 29+ messages in thread
From: Jonathan Cameron @ 2011-08-31 11:22 UTC (permalink / raw)
To: michael.hennerich; +Cc: linux-iio, device-drivers-devel, drivers
On 08/31/11 11:57, michael.hennerich@analog.com wrote:
> From: Michael Hennerich <michael.hennerich@analog.com>
>
Technically the temp -> adc message change should have been in the earlier
patch fixing that elsewhere, but frankly who cares ;)
Good patch all in all. Thanks.
>
> Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
merged.
> ---
> drivers/staging/iio/adc/ad7291.c | 61 ++++++++++++++++++++++++++++++++-----
> 1 files changed, 52 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/staging/iio/adc/ad7291.c b/drivers/staging/iio/adc/ad7291.c
> index dda6bcb..382ca3e 100644
> --- a/drivers/staging/iio/adc/ad7291.c
> +++ b/drivers/staging/iio/adc/ad7291.c
> @@ -13,6 +13,8 @@
> #include <linux/sysfs.h>
> #include <linux/i2c.h>
> #include <linux/mutex.h>
> +#include <linux/regulator/consumer.h>
> +#include <linux/err.h>
>
> #include "../iio.h"
> #include "../sysfs.h"
> @@ -26,8 +28,8 @@
> *
> * The noise-delayed bit as per datasheet suggestion is always enabled.
> *
> - * Extref control should be based on regulator provision - not handled.
> */
> +
> /*
> * AD7291 registers definition
> */
> @@ -60,16 +62,21 @@
> * AD7291 value masks
> */
> #define AD7291_CHANNEL_MASK 0xF000
> +#define AD7291_BITS 12
> #define AD7291_VALUE_MASK 0xFFF
> #define AD7291_T_VALUE_SIGN 0x400
> #define AD7291_T_VALUE_FLOAT_OFFSET 2
> #define AD7291_T_VALUE_FLOAT_MASK 0x2
>
> +#define AD7291_BITS 12
> +
> struct ad7291_chip_info {
> - struct i2c_client *client;
> - u16 command;
> - u8 c_mask; /* Active voltage channels for events */
> - struct mutex state_lock;
> + struct i2c_client *client;
> + struct regulator *reg;
> + u16 int_vref_mv;
> + u16 command;
> + u8 c_mask; /* Active voltage channels for events */
> + struct mutex state_lock;
> };
>
> static int ad7291_i2c_read(struct ad7291_chip_info *chip, u8 reg, u16 *data)
> @@ -419,6 +426,7 @@ static int ad7291_read_raw(struct iio_dev *indio_dev,
> {
> int ret;
> struct ad7291_chip_info *chip = iio_priv(indio_dev);
> + unsigned int scale_uv;
> u16 regval;
> s16 signval;
>
> @@ -470,6 +478,11 @@ static int ad7291_read_raw(struct iio_dev *indio_dev,
> signval = (s16)((swab16((u16)ret) & 0x0FFF) << 4) >> 4;
> *val = signval;
> return IIO_VAL_INT;
> + case (1 << IIO_CHAN_INFO_SCALE_SHARED):
> + scale_uv = (chip->int_vref_mv * 1000) >> AD7291_BITS;
> + *val = scale_uv / 1000;
> + *val2 = (scale_uv % 1000) * 1000;
> + return IIO_VAL_INT_PLUS_MICRO;
> default:
> return -EINVAL;
> }
> @@ -478,6 +491,7 @@ static int ad7291_read_raw(struct iio_dev *indio_dev,
> #define AD7291_VOLTAGE_CHAN(_chan) \
> { \
> .type = IIO_VOLTAGE, \
> + .info_mask = (1 << IIO_CHAN_INFO_SCALE_SHARED), \
> .indexed = 1, \
> .channel = _chan, \
> .event_mask = IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING)|\
> @@ -523,7 +537,7 @@ static int __devinit ad7291_probe(struct i2c_client *client,
> {
> struct ad7291_chip_info *chip;
> struct iio_dev *indio_dev;
> - int ret = 0;
> + int ret = 0, voltage_uv = 0;
>
> indio_dev = iio_allocate_device(sizeof(*chip));
> if (indio_dev == NULL) {
> @@ -531,6 +545,15 @@ static int __devinit ad7291_probe(struct i2c_client *client,
> goto error_ret;
> }
> chip = iio_priv(indio_dev);
> +
> + chip->reg = regulator_get(&client->dev, "vcc");
> + if (!IS_ERR(chip->reg)) {
> + ret = regulator_enable(chip->reg);
> + if (ret)
> + goto error_put_reg;
> + voltage_uv = regulator_get_voltage(chip->reg);
> + }
> +
> mutex_init(&chip->state_lock);
> /* this is only used for device removal purposes */
> i2c_set_clientdata(client, indio_dev);
> @@ -539,6 +562,13 @@ static int __devinit ad7291_probe(struct i2c_client *client,
> /* Tsense always enabled */
> chip->command = AD7291_NOISE_DELAY | AD7291_T_SENSE_MASK;
>
> + if (voltage_uv) {
> + chip->int_vref_mv = voltage_uv / 1000;
> + chip->command |= AD7291_EXT_REF;
> + } else {
> + chip->int_vref_mv = 2500; /* Build-in ref */
> + }
> +
> indio_dev->name = id->name;
> indio_dev->channels = ad7291_channels;
> indio_dev->num_channels = ARRAY_SIZE(ad7291_channels);
> @@ -555,7 +585,7 @@ static int __devinit ad7291_probe(struct i2c_client *client,
> id->name,
> indio_dev);
> if (ret)
> - goto error_free_dev;
> + goto error_disable_reg;
>
> /* set irq polarity low level */
> chip->command |= AD7291_ALERT_POLARITY;
> @@ -571,7 +601,7 @@ static int __devinit ad7291_probe(struct i2c_client *client,
> if (ret)
> goto error_unreg_irq;
>
> - dev_info(&client->dev, "%s temperature sensor registered.\n",
> + dev_info(&client->dev, "%s ADC registered.\n",
> id->name);
>
> return 0;
> @@ -579,7 +609,13 @@ static int __devinit ad7291_probe(struct i2c_client *client,
> error_unreg_irq:
> if (client->irq)
> free_irq(client->irq, indio_dev);
> -error_free_dev:
> +error_disable_reg:
> + if (!IS_ERR(chip->reg))
> + regulator_disable(chip->reg);
> +error_put_reg:
> + if (!IS_ERR(chip->reg))
> + regulator_put(chip->reg);
> +
> iio_free_device(indio_dev);
> error_ret:
> return ret;
> @@ -588,9 +624,16 @@ error_ret:
> static int __devexit ad7291_remove(struct i2c_client *client)
> {
> struct iio_dev *indio_dev = i2c_get_clientdata(client);
> + struct ad7291_chip_info *chip = iio_priv(indio_dev);
>
> if (client->irq)
> free_irq(client->irq, indio_dev);
> +
> + if (!IS_ERR(chip->reg)) {
> + regulator_disable(chip->reg);
> + regulator_put(chip->reg);
> + }
> +
> iio_device_unregister(indio_dev);
>
> return 0;
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATCH 05/12] iio: ad7291: don't swab results twice and introduce more register defines
2011-08-31 10:57 ` [PATCH 05/12] iio: ad7291: don't swab results twice and introduce more register defines michael.hennerich
@ 2011-08-31 11:28 ` Jonathan Cameron
2011-08-31 11:49 ` Hennerich, Michael
0 siblings, 1 reply; 29+ messages in thread
From: Jonathan Cameron @ 2011-08-31 11:28 UTC (permalink / raw)
To: michael.hennerich; +Cc: linux-iio, device-drivers-devel, drivers
On 08/31/11 11:57, michael.hennerich@analog.com wrote:
> From: Michael Hennerich <michael.hennerich@analog.com>
>
oops. my bad on the double swab I think.
Anyhow all looks sane an good. That fixme with the reverse register order
is odd. Guessing you are chasing that down with the hardware guys?
>
> Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
merged
> ---
> drivers/staging/iio/adc/ad7291.c | 90 ++++++++++++++++++++++++-------------
> 1 files changed, 58 insertions(+), 32 deletions(-)
>
> diff --git a/drivers/staging/iio/adc/ad7291.c b/drivers/staging/iio/adc/ad7291.c
> index 382ca3e..2fafca7 100644
> --- a/drivers/staging/iio/adc/ad7291.c
> +++ b/drivers/staging/iio/adc/ad7291.c
> @@ -33,18 +33,43 @@
> /*
> * AD7291 registers definition
> */
> -#define AD7291_COMMAND 0
> -#define AD7291_VOLTAGE 1
> -#define AD7291_T_SENSE 2
> -#define AD7291_T_AVERAGE 3
> -#define AD7291_VOLTAGE_LIMIT_BASE 4
> -#define AD7291_VOLTAGE_LIMIT_COUNT 8
> +#define AD7291_COMMAND 0x00
> +#define AD7291_VOLTAGE 0x01
> +#define AD7291_T_SENSE 0x02
> +#define AD7291_T_AVERAGE 0x03
> +#define AD7291_CH0_DATA_HIGH 0x04
> +#define AD7291_CH0_DATA_LOW 0x05
> +#define AD7291_CH0_HYST 0x06
> +#define AD7291_CH1_DATA_HIGH 0x07
> +#define AD7291_CH1_DATA_LOW 0x08
> +#define AD7291_CH1_HYST 0x09
> +#define AD7291_CH2_DATA_HIGH 0x0A
> +#define AD7291_CH2_DATA_LOW 0x0B
> +#define AD7291_CH2_HYST 0x0C
> +#define AD7291_CH3_DATA_HIGH 0x0D
> +#define AD7291_CH3_DATA_LOW 0x0E
> +#define AD7291_CH3_HYST 0x0F
> +#define AD7291_CH4_DATA_HIGH 0x10
> +#define AD7291_CH4_DATA_LOW 0x11
> +#define AD7291_CH4_HYST 0x12
> +#define AD7291_CH5_DATA_HIGH 0x13
> +#define AD7291_CH5_DATA_LOW 0x14
> +#define AD7291_CH5_HYST 0x15
> +#define AD7291_CH6_DATA_HIGH 0x16
> +#define AD7291_CH6_DATA_LOW 0x17
> +#define AD7291_CH6_HYST 0x18
> +#define AD7291_CH7_DATA_HIGH 0x19
> +#define AD7291_CH7_DATA_LOW 0x1A
> +#define AD7291_CH7_HYST 0x2B
> #define AD7291_T_SENSE_HIGH 0x1C
> #define AD7291_T_SENSE_LOW 0x1D
> #define AD7291_T_SENSE_HYST 0x1E
> #define AD7291_VOLTAGE_ALERT_STATUS 0x1F
> #define AD7291_T_ALERT_STATUS 0x20
>
> +#define AD7291_VOLTAGE_LIMIT_COUNT 8
> +
> +
> /*
> * AD7291 command
> */
> @@ -197,7 +222,7 @@ static inline ssize_t ad7291_show_hyst(struct device *dev,
> if (ret < 0)
> return ret;
>
> - return sprintf(buf, "%d\n", data & 0x0FFF);
> + return sprintf(buf, "%d\n", data & AD7291_VALUE_MASK);
> }
>
> static inline ssize_t ad7291_set_hyst(struct device *dev,
> @@ -227,28 +252,28 @@ static IIO_DEVICE_ATTR(in_temp0_thresh_both_hyst_raw,
> AD7291_T_SENSE_HYST);
> static IIO_DEVICE_ATTR(in_voltage0_thresh_both_hyst_raw,
> S_IRUGO | S_IWUSR,
> - ad7291_show_hyst, ad7291_set_hyst, 0x06);
> + ad7291_show_hyst, ad7291_set_hyst, AD7291_CH0_HYST);
> static IIO_DEVICE_ATTR(in_voltage1_thresh_both_hyst_raw,
> S_IRUGO | S_IWUSR,
> - ad7291_show_hyst, ad7291_set_hyst, 0x09);
> + ad7291_show_hyst, ad7291_set_hyst, AD7291_CH1_HYST);
> static IIO_DEVICE_ATTR(in_voltage2_thresh_both_hyst_raw,
> S_IRUGO | S_IWUSR,
> - ad7291_show_hyst, ad7291_set_hyst, 0x0C);
> + ad7291_show_hyst, ad7291_set_hyst, AD7291_CH2_HYST);
> static IIO_DEVICE_ATTR(in_voltage3_thresh_both_hyst_raw,
> S_IRUGO | S_IWUSR,
> - ad7291_show_hyst, ad7291_set_hyst, 0x0F);
> + ad7291_show_hyst, ad7291_set_hyst, AD7291_CH3_HYST);
> static IIO_DEVICE_ATTR(in_voltage4_thresh_both_hyst_raw,
> S_IRUGO | S_IWUSR,
> - ad7291_show_hyst, ad7291_set_hyst, 0x12);
> + ad7291_show_hyst, ad7291_set_hyst, AD7291_CH4_HYST);
> static IIO_DEVICE_ATTR(in_voltage5_thresh_both_hyst_raw,
> S_IRUGO | S_IWUSR,
> - ad7291_show_hyst, ad7291_set_hyst, 0x15);
> + ad7291_show_hyst, ad7291_set_hyst, AD7291_CH5_HYST);
> static IIO_DEVICE_ATTR(in_voltage6_thresh_both_hyst_raw,
> S_IRUGO | S_IWUSR,
> - ad7291_show_hyst, ad7291_set_hyst, 0x18);
> + ad7291_show_hyst, ad7291_set_hyst, AD7291_CH6_HYST);
> static IIO_DEVICE_ATTR(in_voltage7_thresh_both_hyst_raw,
> S_IRUGO | S_IWUSR,
> - ad7291_show_hyst, ad7291_set_hyst, 0x1B);
> + ad7291_show_hyst, ad7291_set_hyst, AD7291_CH7_HYST);
>
> static struct attribute *ad7291_event_attributes[] = {
> &iio_dev_attr_in_temp0_thresh_both_hyst_raw.dev_attr.attr,
> @@ -265,16 +290,16 @@ static struct attribute *ad7291_event_attributes[] = {
>
> /* high / low */
> static u8 ad7291_limit_regs[9][2] = {
> - { 0x04, 0x05 },
> - { 0x07, 0x08 },
> - { 0x0A, 0x0B },
> - { 0x0E, 0x0D }, /* note reversed order */
> - { 0x10, 0x11 },
> - { 0x13, 0x14 },
> - { 0x16, 0x17 },
> - { 0x19, 0x1A },
> + { AD7291_CH0_DATA_HIGH, AD7291_CH0_DATA_LOW },
> + { AD7291_CH1_DATA_HIGH, AD7291_CH1_DATA_LOW },
> + { AD7291_CH2_DATA_HIGH, AD7291_CH2_DATA_LOW },
> + { AD7291_CH3_DATA_HIGH, AD7291_CH3_DATA_LOW }, /* FIXME: ? */
> + { AD7291_CH4_DATA_HIGH, AD7291_CH4_DATA_LOW },
> + { AD7291_CH5_DATA_HIGH, AD7291_CH5_DATA_LOW },
> + { AD7291_CH6_DATA_HIGH, AD7291_CH6_DATA_LOW },
> + { AD7291_CH7_DATA_HIGH, AD7291_CH7_DATA_LOW },
> /* temp */
> - { 0x1C, 0x1D },
> + { AD7291_T_SENSE_HIGH, AD7291_T_SENSE_LOW },
> };
>
> static int ad7291_read_event_value(struct iio_dev *indio_dev,
> @@ -297,7 +322,7 @@ static int ad7291_read_event_value(struct iio_dev *indio_dev,
> ret = ad7291_i2c_read(chip, reg, &uval);
> if (ret < 0)
> return ret;
> - *val = swab16(uval) & 0x0FFF;
> + *val = uval & AD7291_VALUE_MASK;
> return 0;
>
> case IIO_TEMP:
> @@ -308,7 +333,7 @@ static int ad7291_read_event_value(struct iio_dev *indio_dev,
> ret = ad7291_i2c_read(chip, reg, &signval);
> if (ret < 0)
> return ret;
> - signval = (s16)((swab16(signval) & 0x0FFF) << 4) >> 4;
> + signval = (s16)((signval & AD7291_VALUE_MASK) << 4) >> 4;
> *val = signval;
> return 0;
> default:
> @@ -331,9 +356,7 @@ static int ad7291_write_event_value(struct iio_dev *indio_dev,
> reg = ad7291_limit_regs[IIO_EVENT_CODE_EXTRACT_NUM(event_code)]
> [!(IIO_EVENT_CODE_EXTRACT_DIR(event_code) ==
> IIO_EV_DIR_RISING)];
> -
> return ad7291_i2c_write(chip, reg, val);
> -
> case IIO_TEMP:
> if (val > 2047 || val < -2048)
> return -EINVAL;
> @@ -385,6 +408,7 @@ static int ad7291_write_event_config(struct iio_dev *indio_dev,
> * use continuous sampling mode.
> * Possible to disable temp as well but that makes single read tricky.
> */
> +
> switch (IIO_EVENT_CODE_EXTRACT_TYPE(event_code)) {
> case IIO_VOLTAGE:
> if ((!state) && (chip->c_mask &
> @@ -398,7 +422,7 @@ static int ad7291_write_event_config(struct iio_dev *indio_dev,
> else
> break;
>
> - regval &= 0xFFFE;
> + regval &= ~AD7291_AUTOCYCLE;
> regval |= ((u16)chip->c_mask << 8);
> if (chip->c_mask) /* Enable autocycle? */
> regval |= AD7291_AUTOCYCLE;
> @@ -455,7 +479,7 @@ static int ad7291_read_raw(struct iio_dev *indio_dev,
> mutex_unlock(&chip->state_lock);
> return ret;
> }
> - *val = swab16((u16)ret) & 0x0FFF;
> + *val = swab16((u16)ret) & AD7291_VALUE_MASK;
> mutex_unlock(&chip->state_lock);
> return IIO_VAL_INT;
> case IIO_TEMP:
> @@ -464,7 +488,8 @@ static int ad7291_read_raw(struct iio_dev *indio_dev,
> AD7291_T_SENSE);
> if (ret < 0)
> return ret;
> - signval = (s16)((swab16((u16)ret) & 0x0FFF) << 4) >> 4;
> + signval = (s16)((swab16((u16)ret) &
> + AD7291_VALUE_MASK) << 4) >> 4;
> *val = signval;
> return IIO_VAL_INT;
> default:
> @@ -475,7 +500,8 @@ static int ad7291_read_raw(struct iio_dev *indio_dev,
> AD7291_T_AVERAGE);
> if (ret < 0)
> return ret;
> - signval = (s16)((swab16((u16)ret) & 0x0FFF) << 4) >> 4;
> + signval = (s16)((swab16((u16)ret) &
> + AD7291_VALUE_MASK) << 4) >> 4;
> *val = signval;
> return IIO_VAL_INT;
> case (1 << IIO_CHAN_INFO_SCALE_SHARED):
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATCH 06/12] iio: ad7291: fix mask bit generation
2011-08-31 10:57 ` [PATCH 06/12] iio: ad7291: fix mask bit generation michael.hennerich
@ 2011-08-31 11:29 ` Jonathan Cameron
0 siblings, 0 replies; 29+ messages in thread
From: Jonathan Cameron @ 2011-08-31 11:29 UTC (permalink / raw)
To: michael.hennerich; +Cc: linux-iio, device-drivers-devel, drivers
On 08/31/11 11:57, michael.hennerich@analog.com wrote:
> From: Michael Hennerich <michael.hennerich@analog.com>
>
oops, another clanger from me. Good spot and thanks.
>
> Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
merged
> ---
> drivers/staging/iio/adc/ad7291.c | 2 +-
> 1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/drivers/staging/iio/adc/ad7291.c b/drivers/staging/iio/adc/ad7291.c
> index 2fafca7..7dfdc27 100644
> --- a/drivers/staging/iio/adc/ad7291.c
> +++ b/drivers/staging/iio/adc/ad7291.c
> @@ -417,7 +417,7 @@ static int ad7291_write_event_config(struct iio_dev *indio_dev,
> ~(1 << IIO_EVENT_CODE_EXTRACT_NUM(event_code));
> else if (state && (!(chip->c_mask &
> (1 << IIO_EVENT_CODE_EXTRACT_NUM(event_code)))))
> - chip->c_mask &=
> + chip->c_mask |=
> (1 << IIO_EVENT_CODE_EXTRACT_NUM(event_code));
> else
> break;
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATCH 07/12] iio: ad7291: introduce IIO_EVENT_CODE_EXTRACT_CHAN_TYPE and use accordingly
2011-08-31 10:57 ` [PATCH 07/12] iio: ad7291: introduce IIO_EVENT_CODE_EXTRACT_CHAN_TYPE and use accordingly michael.hennerich
@ 2011-08-31 11:33 ` Jonathan Cameron
0 siblings, 0 replies; 29+ messages in thread
From: Jonathan Cameron @ 2011-08-31 11:33 UTC (permalink / raw)
To: michael.hennerich; +Cc: linux-iio, device-drivers-devel, drivers
On 08/31/11 11:57, michael.hennerich@analog.com wrote:
> From: Michael Hennerich <michael.hennerich@analog.com>
>
> Fix channel type handling
Gah. Yet another stupid error. Good spot. Certainly implies my naming
of those macros may leave something to be desired if even I assume they
mean something different from what they actually do...
>
> Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
merged.
> ---
> drivers/staging/iio/adc/ad7291.c | 6 +++---
> drivers/staging/iio/sysfs.h | 1 +
> 2 files changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/staging/iio/adc/ad7291.c b/drivers/staging/iio/adc/ad7291.c
> index 7dfdc27..b365a74 100644
> --- a/drivers/staging/iio/adc/ad7291.c
> +++ b/drivers/staging/iio/adc/ad7291.c
> @@ -313,7 +313,7 @@ static int ad7291_read_event_value(struct iio_dev *indio_dev,
> u16 uval;
> s16 signval;
>
> - switch (IIO_EVENT_CODE_EXTRACT_TYPE(event_code)) {
> + switch (IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(event_code)) {
> case IIO_VOLTAGE:
> reg = ad7291_limit_regs[IIO_EVENT_CODE_EXTRACT_NUM(event_code)]
> [!(IIO_EVENT_CODE_EXTRACT_DIR(event_code) ==
> @@ -349,7 +349,7 @@ static int ad7291_write_event_value(struct iio_dev *indio_dev,
> u8 reg;
> s16 signval;
>
> - switch (IIO_EVENT_CODE_EXTRACT_TYPE(event_code)) {
> + switch (IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(event_code)) {
> case IIO_VOLTAGE:
> if (val > 0xFFF || val < 0)
> return -EINVAL;
> @@ -377,7 +377,7 @@ static int ad7291_read_event_config(struct iio_dev *indio_dev,
> /* To be enabled the channel must simply be on. If any are enabled
> we are in continuous sampling mode */
>
> - switch (IIO_EVENT_CODE_EXTRACT_TYPE(event_code)) {
> + switch (IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(event_code)) {
> case IIO_VOLTAGE:
> if (chip->c_mask &
> (1 << IIO_EVENT_CODE_EXTRACT_NUM(event_code)))
> diff --git a/drivers/staging/iio/sysfs.h b/drivers/staging/iio/sysfs.h
> index aad1f4b..d98d12d 100644
> --- a/drivers/staging/iio/sysfs.h
> +++ b/drivers/staging/iio/sysfs.h
> @@ -147,6 +147,7 @@ enum iio_event_direction {
>
> #define IIO_EVENT_CODE_EXTRACT_TYPE(mask) ((mask >> 56) & 0xFF)
> #define IIO_EVENT_CODE_EXTRACT_DIR(mask) ((mask >> 48) & 0xFF)
> +#define IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(mask) ((mask >> 32) & 0xFF)
>
> /* Event code number extraction depends on which type of event we have.
> * Perhaps review this function in the future*/
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATCH 08/12] iio: ad7291: fix channel mapping for event enables
2011-08-31 10:57 ` [PATCH 08/12] iio: ad7291: fix channel mapping for event enables michael.hennerich
@ 2011-08-31 11:34 ` Jonathan Cameron
0 siblings, 0 replies; 29+ messages in thread
From: Jonathan Cameron @ 2011-08-31 11:34 UTC (permalink / raw)
To: michael.hennerich; +Cc: linux-iio, device-drivers-devel, drivers
On 08/31/11 11:57, michael.hennerich@analog.com wrote:
> From: Michael Hennerich <michael.hennerich@analog.com>
Pretty closely tied to the previous patch on the channel mapping, but as things
will at least build in between its fine to have it here I guess.
>
>
> Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
merged.
> ---
> drivers/staging/iio/adc/ad7291.c | 24 ++++++++++++------------
> 1 files changed, 12 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/staging/iio/adc/ad7291.c b/drivers/staging/iio/adc/ad7291.c
> index b365a74..1a2fa66 100644
> --- a/drivers/staging/iio/adc/ad7291.c
> +++ b/drivers/staging/iio/adc/ad7291.c
> @@ -100,7 +100,7 @@ struct ad7291_chip_info {
> struct regulator *reg;
> u16 int_vref_mv;
> u16 command;
> - u8 c_mask; /* Active voltage channels for events */
> + u16 c_mask; /* Active voltage channels for events */
> struct mutex state_lock;
> };
>
> @@ -380,7 +380,7 @@ static int ad7291_read_event_config(struct iio_dev *indio_dev,
> switch (IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(event_code)) {
> case IIO_VOLTAGE:
> if (chip->c_mask &
> - (1 << IIO_EVENT_CODE_EXTRACT_NUM(event_code)))
> + (1 << (15 - IIO_EVENT_CODE_EXTRACT_NUM(event_code))))
> return 1;
> else
> return 0;
> @@ -411,19 +411,19 @@ static int ad7291_write_event_config(struct iio_dev *indio_dev,
>
> switch (IIO_EVENT_CODE_EXTRACT_TYPE(event_code)) {
> case IIO_VOLTAGE:
> - if ((!state) && (chip->c_mask &
> - (1 << IIO_EVENT_CODE_EXTRACT_NUM(event_code))))
> - chip->c_mask &=
> - ~(1 << IIO_EVENT_CODE_EXTRACT_NUM(event_code));
> - else if (state && (!(chip->c_mask &
> - (1 << IIO_EVENT_CODE_EXTRACT_NUM(event_code)))))
> - chip->c_mask |=
> - (1 << IIO_EVENT_CODE_EXTRACT_NUM(event_code));
> + if ((!state) && (chip->c_mask & (1 << (15 -
> + IIO_EVENT_CODE_EXTRACT_NUM(event_code)))))
> + chip->c_mask &= ~(1 << (15 - IIO_EVENT_CODE_EXTRACT_NUM
> + (event_code)));
> + else if (state && (!(chip->c_mask & (1 << (15 -
> + IIO_EVENT_CODE_EXTRACT_NUM(event_code))))))
> + chip->c_mask |= (1 << (15 - IIO_EVENT_CODE_EXTRACT_NUM
> + (event_code)));
> else
> break;
>
> regval &= ~AD7291_AUTOCYCLE;
> - regval |= ((u16)chip->c_mask << 8);
> + regval |= chip->c_mask;
> if (chip->c_mask) /* Enable autocycle? */
> regval |= AD7291_AUTOCYCLE;
>
> @@ -460,7 +460,7 @@ static int ad7291_read_raw(struct iio_dev *indio_dev,
> case IIO_VOLTAGE:
> mutex_lock(&chip->state_lock);
> /* If in autocycle mode drop through */
> - if (chip->command & 0x1) {
> + if (chip->command & AD7291_AUTOCYCLE) {
> mutex_unlock(&chip->state_lock);
> return -EBUSY;
> }
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATCH 10/12] iio: ad7192: return len and fix out of range checking
2011-08-31 10:57 ` [PATCH 10/12] iio: ad7192: return len and fix out of range checking michael.hennerich
@ 2011-08-31 11:37 ` Jonathan Cameron
2011-08-31 11:47 ` Hennerich, Michael
0 siblings, 1 reply; 29+ messages in thread
From: Jonathan Cameron @ 2011-08-31 11:37 UTC (permalink / raw)
To: michael.hennerich; +Cc: linux-iio, device-drivers-devel, drivers
On 08/31/11 11:57, michael.hennerich@analog.com wrote:
> From: Michael Hennerich <michael.hennerich@analog.com>
>
>
Is 4096 a valid value? I thought we only had 12 bits (hence the 0xFFF)
That would make maximum 4095
> Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
> ---
> drivers/staging/iio/adc/ad7291.c | 10 +++++++---
> 1 files changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/staging/iio/adc/ad7291.c b/drivers/staging/iio/adc/ad7291.c
> index 1a2fa66..334951c 100644
> --- a/drivers/staging/iio/adc/ad7291.c
> +++ b/drivers/staging/iio/adc/ad7291.c
> @@ -240,10 +240,14 @@ static inline ssize_t ad7291_set_hyst(struct device *dev,
>
> if (ret < 0)
> return ret;
> - if (data < 4096)
> + if (data > AD7291_VALUE_MASK)
> return -EINVAL;
>
> - return ad7291_i2c_write(chip, this_attr->address, data);
> + ret = ad7291_i2c_write(chip, this_attr->address, data);
> + if (ret < 0)
> + return ret;
> +
> + return len;
> }
>
> static IIO_DEVICE_ATTR(in_temp0_thresh_both_hyst_raw,
> @@ -351,7 +355,7 @@ static int ad7291_write_event_value(struct iio_dev *indio_dev,
>
> switch (IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(event_code)) {
> case IIO_VOLTAGE:
> - if (val > 0xFFF || val < 0)
> + if (val > AD7291_VALUE_MASK || val < 0)
> return -EINVAL;
> reg = ad7291_limit_regs[IIO_EVENT_CODE_EXTRACT_NUM(event_code)]
> [!(IIO_EVENT_CODE_EXTRACT_DIR(event_code) ==
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATCH 11/12] iio: ad7291: reset device and setup irq before it is enabled
2011-08-31 10:57 ` [PATCH 11/12] iio: ad7291: reset device and setup irq before it is enabled michael.hennerich
@ 2011-08-31 11:39 ` Jonathan Cameron
0 siblings, 0 replies; 29+ messages in thread
From: Jonathan Cameron @ 2011-08-31 11:39 UTC (permalink / raw)
To: michael.hennerich; +Cc: linux-iio, device-drivers-devel, drivers
On 08/31/11 11:57, michael.hennerich@analog.com wrote:
> From: Michael Hennerich <michael.hennerich@analog.com>
>
Looks right.
>
> Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
merged
> ---
> drivers/staging/iio/adc/ad7291.c | 27 ++++++++++++++++-----------
> 1 files changed, 16 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/staging/iio/adc/ad7291.c b/drivers/staging/iio/adc/ad7291.c
> index 334951c..0811c5e 100644
> --- a/drivers/staging/iio/adc/ad7291.c
> +++ b/drivers/staging/iio/adc/ad7291.c
> @@ -589,8 +589,10 @@ static int __devinit ad7291_probe(struct i2c_client *client,
> i2c_set_clientdata(client, indio_dev);
>
> chip->client = client;
> - /* Tsense always enabled */
> - chip->command = AD7291_NOISE_DELAY | AD7291_T_SENSE_MASK;
> +
> + chip->command = AD7291_NOISE_DELAY |
> + AD7291_T_SENSE_MASK | /* Tsense always enabled */
> + AD7291_ALERT_POLARITY; /* set irq polarity low level */
>
> if (voltage_uv) {
> chip->int_vref_mv = voltage_uv / 1000;
> @@ -607,6 +609,18 @@ static int __devinit ad7291_probe(struct i2c_client *client,
> indio_dev->info = &ad7291_info;
> indio_dev->modes = INDIO_DIRECT_MODE;
>
> + ret = ad7291_i2c_write(chip, AD7291_COMMAND, AD7291_RESET);
> + if (ret) {
> + ret = -EIO;
> + goto error_disable_reg;
> + }
> +
> + ret = ad7291_i2c_write(chip, AD7291_COMMAND, chip->command);
> + if (ret) {
> + ret = -EIO;
> + goto error_disable_reg;
> + }
> +
> if (client->irq > 0) {
> ret = request_threaded_irq(client->irq,
> NULL,
> @@ -616,15 +630,6 @@ static int __devinit ad7291_probe(struct i2c_client *client,
> indio_dev);
> if (ret)
> goto error_disable_reg;
> -
> - /* set irq polarity low level */
> - chip->command |= AD7291_ALERT_POLARITY;
> - }
> -
> - ret = ad7291_i2c_write(chip, AD7291_COMMAND, chip->command);
> - if (ret) {
> - ret = -EIO;
> - goto error_unreg_irq;
> }
>
> ret = iio_device_register(indio_dev);
^ permalink raw reply [flat|nested] 29+ messages in thread
* RE: [PATCH 10/12] iio: ad7192: return len and fix out of range checking
2011-08-31 11:37 ` Jonathan Cameron
@ 2011-08-31 11:47 ` Hennerich, Michael
2011-08-31 11:59 ` Jonathan Cameron
0 siblings, 1 reply; 29+ messages in thread
From: Hennerich, Michael @ 2011-08-31 11:47 UTC (permalink / raw)
To: Jonathan Cameron; +Cc: linux-iio, device-drivers-devel, Drivers
Jonathan Cameron wrote on 2011-08-31:
> On 08/31/11 11:57, michael.hennerich@analog.com wrote:
>> From: Michael Hennerich <michael.hennerich@analog.com>
>>
>>
> Is 4096 a valid value? I thought we only had 12 bits (hence the 0xFFF)
> That would make maximum 4095
Where do you see the 4096?
There was a invalid check for smaller 4096 causing a return EINVAL.
I removed the line and added the check for > 0xFFF....
>> Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
>> ---
>> drivers/staging/iio/adc/ad7291.c | 10 +++++++---
>> 1 files changed, 7 insertions(+), 3 deletions(-)
>> diff --git a/drivers/staging/iio/adc/ad7291.c
>> b/drivers/staging/iio/adc/ad7291.c index 1a2fa66..334951c 100644 ---
>> a/drivers/staging/iio/adc/ad7291.c +++
>> b/drivers/staging/iio/adc/ad7291.c @@ -240,10 +240,14 @@ static inline
>> ssize_t ad7291_set_hyst(struct device *dev,
>>
>> if (ret < 0)
>> return ret;
>> - if (data < 4096)
>> + if (data > AD7291_VALUE_MASK)
>> return -EINVAL;
>> - return ad7291_i2c_write(chip, this_attr->address, data);
>> + ret =3D ad7291_i2c_write(chip, this_attr->address, data);
>> + if (ret < 0)
>> + return ret;
>> +
>> + return len;
>> }
>>
>> static IIO_DEVICE_ATTR(in_temp0_thresh_both_hyst_raw,
>> @@ -351,7 +355,7 @@ static int ad7291_write_event_value(struct iio_dev
>> *indio_dev,
>>
>> switch (IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(event_code)) {
>> case IIO_VOLTAGE:
>> - if (val > 0xFFF || val < 0)
>> + if (val > AD7291_VALUE_MASK || val < 0)
>> return -EINVAL; reg =3D
>> ad7291_limit_regs[IIO_EVENT_CODE_EXTRACT_NUM(event_code)]
>> [!(IIO_EVENT_CODE_EXTRACT_DIR(event_code) =3D=3D
>
Greetings,
Michael
--
Analog Devices GmbH Wilhelm-Wagenfeld-Str. 6 80807 Muenchen
Sitz der Gesellschaft: Muenchen; Registergericht: Muenchen HRB 40368;
Geschaeftsfuehrer:Dr.Carsten Suckrow, Thomas Wessel, William A. Martin, Mar=
garet Seif
^ permalink raw reply [flat|nested] 29+ messages in thread
* RE: [PATCH 05/12] iio: ad7291: don't swab results twice and introduce more register defines
2011-08-31 11:28 ` Jonathan Cameron
@ 2011-08-31 11:49 ` Hennerich, Michael
2011-08-31 12:01 ` Jonathan Cameron
0 siblings, 1 reply; 29+ messages in thread
From: Hennerich, Michael @ 2011-08-31 11:49 UTC (permalink / raw)
To: Jonathan Cameron; +Cc: linux-iio, device-drivers-devel, Drivers
Jonathan Cameron wrote on 2011-08-31:
> On 08/31/11 11:57, michael.hennerich@analog.com wrote:
>> From: Michael Hennerich <michael.hennerich@analog.com>
>>
> oops. my bad on the double swab I think. Anyhow all looks sane an good.
> That fixme with the reverse register order is odd. Guessing you are
> chasing that down with the hardware guys?
If you like you can remove the FIXME.
I checked the behavior on hardware, and it seems to be a datasheet errata.
>>
>> Signed-off-by: Michael Hennerich <michael.hennerich@analog.com> merged
>> ---
>> drivers/staging/iio/adc/ad7291.c | 90 ++++++++++++++++++++++++----
>> --------- 1 files changed, 58 insertions(+), 32 deletions(-)
>> diff --git a/drivers/staging/iio/adc/ad7291.c
>> b/drivers/staging/iio/adc/ad7291.c index 382ca3e..2fafca7 100644 ---
>> a/drivers/staging/iio/adc/ad7291.c +++
>> b/drivers/staging/iio/adc/ad7291.c @@ -33,18 +33,43 @@
>> /*
>> * AD7291 registers definition
>> */
>> -#define AD7291_COMMAND 0
>> -#define AD7291_VOLTAGE 1
>> -#define AD7291_T_SENSE 2
>> -#define AD7291_T_AVERAGE 3
>> -#define AD7291_VOLTAGE_LIMIT_BASE 4
>> -#define AD7291_VOLTAGE_LIMIT_COUNT 8
>> +#define AD7291_COMMAND 0x00
>> +#define AD7291_VOLTAGE 0x01
>> +#define AD7291_T_SENSE 0x02
>> +#define AD7291_T_AVERAGE 0x03
>> +#define AD7291_CH0_DATA_HIGH 0x04
>> +#define AD7291_CH0_DATA_LOW 0x05
>> +#define AD7291_CH0_HYST 0x06
>> +#define AD7291_CH1_DATA_HIGH 0x07
>> +#define AD7291_CH1_DATA_LOW 0x08
>> +#define AD7291_CH1_HYST 0x09
>> +#define AD7291_CH2_DATA_HIGH 0x0A
>> +#define AD7291_CH2_DATA_LOW 0x0B
>> +#define AD7291_CH2_HYST 0x0C
>> +#define AD7291_CH3_DATA_HIGH 0x0D
>> +#define AD7291_CH3_DATA_LOW 0x0E
>> +#define AD7291_CH3_HYST 0x0F
>> +#define AD7291_CH4_DATA_HIGH 0x10
>> +#define AD7291_CH4_DATA_LOW 0x11
>> +#define AD7291_CH4_HYST 0x12
>> +#define AD7291_CH5_DATA_HIGH 0x13
>> +#define AD7291_CH5_DATA_LOW 0x14
>> +#define AD7291_CH5_HYST 0x15
>> +#define AD7291_CH6_DATA_HIGH 0x16
>> +#define AD7291_CH6_DATA_LOW 0x17
>> +#define AD7291_CH6_HYST 0x18
>> +#define AD7291_CH7_DATA_HIGH 0x19
>> +#define AD7291_CH7_DATA_LOW 0x1A
>> +#define AD7291_CH7_HYST 0x2B
>> #define AD7291_T_SENSE_HIGH 0x1C
>> #define AD7291_T_SENSE_LOW 0x1D
>> #define AD7291_T_SENSE_HYST 0x1E
>> #define AD7291_VOLTAGE_ALERT_STATUS 0x1F
>> #define AD7291_T_ALERT_STATUS 0x20
>> +#define AD7291_VOLTAGE_LIMIT_COUNT 8
>> +
>> +
>> /*
>> * AD7291 command
>> */
>> @@ -197,7 +222,7 @@ static inline ssize_t ad7291_show_hyst(struct
> device *dev,
>> if (ret < 0)
>> return ret;
>> - return sprintf(buf, "%d\n", data & 0x0FFF);
>> + return sprintf(buf, "%d\n", data & AD7291_VALUE_MASK);
>> }
>>
>> static inline ssize_t ad7291_set_hyst(struct device *dev,
>> @@ -227,28 +252,28 @@ static
> IIO_DEVICE_ATTR(in_temp0_thresh_both_hyst_raw,
>> AD7291_T_SENSE_HYST);
>> static IIO_DEVICE_ATTR(in_voltage0_thresh_both_hyst_raw,
>> S_IRUGO | S_IWUSR,
>> - ad7291_show_hyst, ad7291_set_hyst, 0x06);
>> + ad7291_show_hyst, ad7291_set_hyst, AD7291_CH0_HYST);
>> static IIO_DEVICE_ATTR(in_voltage1_thresh_both_hyst_raw,
>> S_IRUGO | S_IWUSR,
>> - ad7291_show_hyst, ad7291_set_hyst, 0x09);
>> + ad7291_show_hyst, ad7291_set_hyst, AD7291_CH1_HYST);
>> static IIO_DEVICE_ATTR(in_voltage2_thresh_both_hyst_raw,
>> S_IRUGO | S_IWUSR,
>> - ad7291_show_hyst, ad7291_set_hyst, 0x0C);
>> + ad7291_show_hyst, ad7291_set_hyst, AD7291_CH2_HYST);
>> static IIO_DEVICE_ATTR(in_voltage3_thresh_both_hyst_raw,
>> S_IRUGO | S_IWUSR,
>> - ad7291_show_hyst, ad7291_set_hyst, 0x0F);
>> + ad7291_show_hyst, ad7291_set_hyst, AD7291_CH3_HYST);
>> static IIO_DEVICE_ATTR(in_voltage4_thresh_both_hyst_raw,
>> S_IRUGO | S_IWUSR,
>> - ad7291_show_hyst, ad7291_set_hyst, 0x12);
>> + ad7291_show_hyst, ad7291_set_hyst, AD7291_CH4_HYST);
>> static IIO_DEVICE_ATTR(in_voltage5_thresh_both_hyst_raw,
>> S_IRUGO | S_IWUSR,
>> - ad7291_show_hyst, ad7291_set_hyst, 0x15);
>> + ad7291_show_hyst, ad7291_set_hyst, AD7291_CH5_HYST);
>> static IIO_DEVICE_ATTR(in_voltage6_thresh_both_hyst_raw,
>> S_IRUGO | S_IWUSR,
>> - ad7291_show_hyst, ad7291_set_hyst, 0x18);
>> + ad7291_show_hyst, ad7291_set_hyst, AD7291_CH6_HYST);
>> static IIO_DEVICE_ATTR(in_voltage7_thresh_both_hyst_raw,
>> S_IRUGO | S_IWUSR,
>> - ad7291_show_hyst, ad7291_set_hyst, 0x1B);
>> + ad7291_show_hyst, ad7291_set_hyst, AD7291_CH7_HYST);
>>
>> static struct attribute *ad7291_event_attributes[] = {
>> &iio_dev_attr_in_temp0_thresh_both_hyst_raw.dev_attr.attr,
>> @@ -265,16 +290,16 @@ static struct attribute
>> *ad7291_event_attributes[] = {
>>
>> /* high / low */
>> static u8 ad7291_limit_regs[9][2] = {
>> - { 0x04, 0x05 },
>> - { 0x07, 0x08 },
>> - { 0x0A, 0x0B },
>> - { 0x0E, 0x0D }, /* note reversed order */
>> - { 0x10, 0x11 },
>> - { 0x13, 0x14 },
>> - { 0x16, 0x17 },
>> - { 0x19, 0x1A },
>> + { AD7291_CH0_DATA_HIGH, AD7291_CH0_DATA_LOW },
>> + { AD7291_CH1_DATA_HIGH, AD7291_CH1_DATA_LOW },
>> + { AD7291_CH2_DATA_HIGH, AD7291_CH2_DATA_LOW },
>> + { AD7291_CH3_DATA_HIGH, AD7291_CH3_DATA_LOW }, /* FIXME: ? */
>> + { AD7291_CH4_DATA_HIGH, AD7291_CH4_DATA_LOW },
>> + { AD7291_CH5_DATA_HIGH, AD7291_CH5_DATA_LOW },
>> + { AD7291_CH6_DATA_HIGH, AD7291_CH6_DATA_LOW },
>> + { AD7291_CH7_DATA_HIGH, AD7291_CH7_DATA_LOW },
>> /* temp */
>> - { 0x1C, 0x1D },
>> + { AD7291_T_SENSE_HIGH, AD7291_T_SENSE_LOW },
>> };
>>
>> static int ad7291_read_event_value(struct iio_dev *indio_dev,
>> @@ -297,7 +322,7 @@ static int ad7291_read_event_value(struct iio_dev
> *indio_dev,
>> ret = ad7291_i2c_read(chip, reg, &uval);
>> if (ret < 0)
>> return ret;
>> - *val = swab16(uval) & 0x0FFF;
>> + *val = uval & AD7291_VALUE_MASK;
>> return 0;
>>
>> case IIO_TEMP:
>> @@ -308,7 +333,7 @@ static int ad7291_read_event_value(struct iio_dev
> *indio_dev,
>> ret = ad7291_i2c_read(chip, reg, &signval);
>> if (ret < 0)
>> return ret;
>> - signval = (s16)((swab16(signval) & 0x0FFF) << 4) >> 4;
>> + signval = (s16)((signval & AD7291_VALUE_MASK) << 4) >> 4;
>> *val = signval;
>> return 0;
>> default:
>> @@ -331,9 +356,7 @@ static int ad7291_write_event_value(struct
> iio_dev *indio_dev,
>> reg = ad7291_limit_regs[IIO_EVENT_CODE_EXTRACT_NUM(event_code)]
>> [!(IIO_EVENT_CODE_EXTRACT_DIR(event_code) ==
>> IIO_EV_DIR_RISING)]; - return ad7291_i2c_write(chip, reg, val); -
>> case IIO_TEMP: if (val > 2047 || val < -2048) return -EINVAL;
>> @@ -385,6 +408,7 @@ static int ad7291_write_event_config(struct
> iio_dev *indio_dev,
>> * use continuous sampling mode. * Possible to disable temp as well
>> but that makes single read tricky. */ + switch
>> (IIO_EVENT_CODE_EXTRACT_TYPE(event_code)) { case IIO_VOLTAGE: if
>> ((!state) && (chip->c_mask &
>> @@ -398,7 +422,7 @@ static int ad7291_write_event_config(struct
> iio_dev *indio_dev,
>> else
>> break;
>> - regval &= 0xFFFE;
>> + regval &= ~AD7291_AUTOCYCLE;
>> regval |= ((u16)chip->c_mask << 8);
>> if (chip->c_mask) /* Enable autocycle? */
>> regval |= AD7291_AUTOCYCLE;
>> @@ -455,7 +479,7 @@ static int ad7291_read_raw(struct iio_dev
> *indio_dev,
>> mutex_unlock(&chip->state_lock);
>> return ret;
>> }
>> - *val = swab16((u16)ret) & 0x0FFF;
>> + *val = swab16((u16)ret) & AD7291_VALUE_MASK;
>> mutex_unlock(&chip->state_lock);
>> return IIO_VAL_INT;
>> case IIO_TEMP:
>> @@ -464,7 +488,8 @@ static int ad7291_read_raw(struct iio_dev
> *indio_dev,
>> AD7291_T_SENSE);
>> if (ret < 0)
>> return ret;
>> - signval = (s16)((swab16((u16)ret) & 0x0FFF) << 4) >> 4; + signval
>> = (s16)((swab16((u16)ret) & + AD7291_VALUE_MASK) << 4) >> 4;
>> *val = signval;
>> return IIO_VAL_INT;
>> default:
>> @@ -475,7 +500,8 @@ static int ad7291_read_raw(struct iio_dev
> *indio_dev,
>> AD7291_T_AVERAGE);
>> if (ret < 0)
>> return ret;
>> - signval = (s16)((swab16((u16)ret) & 0x0FFF) << 4) >> 4; + signval
>> = (s16)((swab16((u16)ret) & + AD7291_VALUE_MASK) << 4) >> 4;
>> *val = signval;
>> return IIO_VAL_INT;
>> case (1 << IIO_CHAN_INFO_SCALE_SHARED):
>
Greetings,
Michael
--
Analog Devices GmbH Wilhelm-Wagenfeld-Str. 6 80807 Muenchen
Sitz der Gesellschaft: Muenchen; Registergericht: Muenchen HRB 40368;
Geschaeftsfuehrer:Dr.Carsten Suckrow, Thomas Wessel, William A. Martin, Margaret Seif
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATCH 12/12] iio: ad7192: add temp_scale attribute, change module description
2011-08-31 10:57 ` [PATCH 12/12] iio: ad7192: add temp_scale attribute, change module description michael.hennerich
@ 2011-08-31 11:52 ` Jonathan Cameron
0 siblings, 0 replies; 29+ messages in thread
From: Jonathan Cameron @ 2011-08-31 11:52 UTC (permalink / raw)
To: michael.hennerich; +Cc: linux-iio, device-drivers-devel, drivers
On 08/31/11 11:57, michael.hennerich@analog.com wrote:
> From: Michael Hennerich <michael.hennerich@analog.com>
>
> Use KBUILD_MODNAME
> Fix indention style
Again, not all in the right place in the series, but it's so
trivial we'll leave it be. I'll probably fix up that mutex whitespace
issue where it occurred.
>
> Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
merged
> ---
> drivers/staging/iio/adc/ad7291.c | 17 ++++++++++++-----
> 1 files changed, 12 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/staging/iio/adc/ad7291.c b/drivers/staging/iio/adc/ad7291.c
> index 0811c5e..636e635 100644
> --- a/drivers/staging/iio/adc/ad7291.c
> +++ b/drivers/staging/iio/adc/ad7291.c
> @@ -101,7 +101,7 @@ struct ad7291_chip_info {
> u16 int_vref_mv;
> u16 command;
> u16 c_mask; /* Active voltage channels for events */
> - struct mutex state_lock;
> + struct mutex state_lock;
> };
>
> static int ad7291_i2c_read(struct ad7291_chip_info *chip, u8 reg, u16 *data)
> @@ -513,6 +513,13 @@ static int ad7291_read_raw(struct iio_dev *indio_dev,
> *val = scale_uv / 1000;
> *val2 = (scale_uv % 1000) * 1000;
> return IIO_VAL_INT_PLUS_MICRO;
> + case (1 << IIO_CHAN_INFO_SCALE_SEPARATE):
> + /*
> + * One LSB of the ADC corresponds to 0.25 deg C.
> + * The temperature reading is in 12-bit twos complement format
> + */
> + *val = 250;
> + return IIO_VAL_INT;
> default:
> return -EINVAL;
> }
> @@ -539,7 +546,8 @@ static const struct iio_chan_spec ad7291_channels[] = {
> AD7291_VOLTAGE_CHAN(7),
> {
> .type = IIO_TEMP,
> - .info_mask = (1 << IIO_CHAN_INFO_AVERAGE_RAW_SEPARATE),
> + .info_mask = (1 << IIO_CHAN_INFO_AVERAGE_RAW_SEPARATE) |
> + (1 << IIO_CHAN_INFO_SCALE_SEPARATE),
> .indexed = 1,
> .channel = 0,
> .event_mask =
> @@ -683,7 +691,7 @@ MODULE_DEVICE_TABLE(i2c, ad7291_id);
>
> static struct i2c_driver ad7291_driver = {
> .driver = {
> - .name = "ad7291",
> + .name = KBUILD_MODNAME,
> },
> .probe = ad7291_probe,
> .remove = __devexit_p(ad7291_remove),
> @@ -701,8 +709,7 @@ static __exit void ad7291_exit(void)
> }
>
> MODULE_AUTHOR("Sonic Zhang <sonic.zhang@analog.com>");
> -MODULE_DESCRIPTION("Analog Devices AD7291 digital"
> - " temperature sensor driver");
> +MODULE_DESCRIPTION("Analog Devices AD7291 ADC driver");
> MODULE_LICENSE("GPL v2");
>
> module_init(ad7291_init);
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATCH 10/12] iio: ad7192: return len and fix out of range checking
2011-08-31 11:47 ` Hennerich, Michael
@ 2011-08-31 11:59 ` Jonathan Cameron
0 siblings, 0 replies; 29+ messages in thread
From: Jonathan Cameron @ 2011-08-31 11:59 UTC (permalink / raw)
To: Hennerich, Michael; +Cc: linux-iio, device-drivers-devel, Drivers
On 08/31/11 12:47, Hennerich, Michael wrote:
> Jonathan Cameron wrote on 2011-08-31:
>> On 08/31/11 11:57, michael.hennerich@analog.com wrote:
>>> From: Michael Hennerich <michael.hennerich@analog.com>
>>>
>>>
>> Is 4096 a valid value? I thought we only had 12 bits (hence the 0xFFF)
>> That would make maximum 4095
>
> Where do you see the 4096?
> There was a invalid check for smaller 4096 causing a return EINVAL.
Doh! + and - sign missread. Makes more sense now. Clearly need lunch an coffee!
>
> I removed the line and added the check for > 0xFFF....
>
>>> Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
merged.
>>> ---
>>> drivers/staging/iio/adc/ad7291.c | 10 +++++++---
>>> 1 files changed, 7 insertions(+), 3 deletions(-)
>>> diff --git a/drivers/staging/iio/adc/ad7291.c
>>> b/drivers/staging/iio/adc/ad7291.c index 1a2fa66..334951c 100644 ---
>>> a/drivers/staging/iio/adc/ad7291.c +++
>>> b/drivers/staging/iio/adc/ad7291.c @@ -240,10 +240,14 @@ static inline
>>> ssize_t ad7291_set_hyst(struct device *dev,
>>>
>>> if (ret < 0)
>>> return ret;
>>> - if (data < 4096)
>>> + if (data > AD7291_VALUE_MASK)
>>> return -EINVAL;
>>> - return ad7291_i2c_write(chip, this_attr->address, data);
>>> + ret = ad7291_i2c_write(chip, this_attr->address, data);
>>> + if (ret < 0)
>>> + return ret;
>>> +
>>> + return len;
>>> }
>>>
>>> static IIO_DEVICE_ATTR(in_temp0_thresh_both_hyst_raw,
>>> @@ -351,7 +355,7 @@ static int ad7291_write_event_value(struct iio_dev
>>> *indio_dev,
>>>
>>> switch (IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(event_code)) {
>>> case IIO_VOLTAGE:
>>> - if (val > 0xFFF || val < 0)
>>> + if (val > AD7291_VALUE_MASK || val < 0)
>>> return -EINVAL; reg =
>>> ad7291_limit_regs[IIO_EVENT_CODE_EXTRACT_NUM(event_code)]
>>> [!(IIO_EVENT_CODE_EXTRACT_DIR(event_code) ==
>>
>
> Greetings,
> Michael
>
> --
> Analog Devices GmbH Wilhelm-Wagenfeld-Str. 6 80807 Muenchen
> Sitz der Gesellschaft: Muenchen; Registergericht: Muenchen HRB 40368;
> Geschaeftsfuehrer:Dr.Carsten Suckrow, Thomas Wessel, William A. Martin, Margaret Seif
>
>
>
>
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATCH 09/12] iio: core: fix IIO_EVENT_CODE_EXTRACT_DIR definition
2011-08-31 11:15 ` Jonathan Cameron
@ 2011-08-31 12:01 ` Jonathan Cameron
0 siblings, 0 replies; 29+ messages in thread
From: Jonathan Cameron @ 2011-08-31 12:01 UTC (permalink / raw)
To: Jonathan Cameron
Cc: michael.hennerich, linux-iio, device-drivers-devel, drivers
On 08/31/11 12:15, Jonathan Cameron wrote:
> On 08/31/11 11:57, michael.hennerich@analog.com wrote:
>> From: Michael Hennerich <michael.hennerich@analog.com>
>>
>>
> Gah and good spot. I'll merge that one down into the patch that introduced it
> with appropriate comment.
On closer inspection you are right that there is an issue here, but
it's not quite what you've fixed.
diff should be 1 bit, and direction 7. Right now, diff is 7 and direction 1.
fix is something like IIO_EVENT_CODE(chan_type, diff, modifier, direction, \
type, chan, chan1, chan2) \
- (((u64)type << 56) | ((u64)direction << 48) | ((u64)modifier << 40) | \
+ (((u64)type << 56) | ((u64)diff << 55) | \
+ ((u64)direction << 48) | ((u64)modifier << 40) | \
((u64)chan_type << 32) | (chan2 << 16) | chan1 | chan)
Will merge into the original patch and repost that in a mo.
Thanks,
Jonathan
>> Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
>> ---
>> drivers/staging/iio/sysfs.h | 2 +-
>> 1 files changed, 1 insertions(+), 1 deletions(-)
>>
>> diff --git a/drivers/staging/iio/sysfs.h b/drivers/staging/iio/sysfs.h
>> index d98d12d..8de6a65 100644
>> --- a/drivers/staging/iio/sysfs.h
>> +++ b/drivers/staging/iio/sysfs.h
>> @@ -146,7 +146,7 @@ enum iio_event_direction {
>> IIO_EVENT_CODE(channelclass, 0, 0, direction, type, number, 0, 0)
>>
>> #define IIO_EVENT_CODE_EXTRACT_TYPE(mask) ((mask >> 56) & 0xFF)
>> -#define IIO_EVENT_CODE_EXTRACT_DIR(mask) ((mask >> 48) & 0xFF)
>> +#define IIO_EVENT_CODE_EXTRACT_DIR(mask) ((mask >> 47) & 0xFF)
>> #define IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(mask) ((mask >> 32) & 0xFF)
>>
>> /* Event code number extraction depends on which type of event we have.
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATCH 05/12] iio: ad7291: don't swab results twice and introduce more register defines
2011-08-31 11:49 ` Hennerich, Michael
@ 2011-08-31 12:01 ` Jonathan Cameron
0 siblings, 0 replies; 29+ messages in thread
From: Jonathan Cameron @ 2011-08-31 12:01 UTC (permalink / raw)
To: Hennerich, Michael; +Cc: linux-iio, device-drivers-devel, Drivers
On 08/31/11 12:49, Hennerich, Michael wrote:
> Jonathan Cameron wrote on 2011-08-31:
>> On 08/31/11 11:57, michael.hennerich@analog.com wrote:
>>> From: Michael Hennerich <michael.hennerich@analog.com>
>>>
>> oops. my bad on the double swab I think. Anyhow all looks sane an good.
>> That fixme with the reverse register order is odd. Guessing you are
>> chasing that down with the hardware guys?
>
> If you like you can remove the FIXME.
> I checked the behavior on hardware, and it seems to be a datasheet errata.
cool. Seemed pretty implausible!
>
>>>
>>> Signed-off-by: Michael Hennerich <michael.hennerich@analog.com> merged
>>> ---
>>> drivers/staging/iio/adc/ad7291.c | 90 ++++++++++++++++++++++++----
>>> --------- 1 files changed, 58 insertions(+), 32 deletions(-)
>>> diff --git a/drivers/staging/iio/adc/ad7291.c
>>> b/drivers/staging/iio/adc/ad7291.c index 382ca3e..2fafca7 100644 ---
>>> a/drivers/staging/iio/adc/ad7291.c +++
>>> b/drivers/staging/iio/adc/ad7291.c @@ -33,18 +33,43 @@
>>> /*
>>> * AD7291 registers definition
>>> */
>>> -#define AD7291_COMMAND 0
>>> -#define AD7291_VOLTAGE 1
>>> -#define AD7291_T_SENSE 2
>>> -#define AD7291_T_AVERAGE 3
>>> -#define AD7291_VOLTAGE_LIMIT_BASE 4
>>> -#define AD7291_VOLTAGE_LIMIT_COUNT 8
>>> +#define AD7291_COMMAND 0x00
>>> +#define AD7291_VOLTAGE 0x01
>>> +#define AD7291_T_SENSE 0x02
>>> +#define AD7291_T_AVERAGE 0x03
>>> +#define AD7291_CH0_DATA_HIGH 0x04
>>> +#define AD7291_CH0_DATA_LOW 0x05
>>> +#define AD7291_CH0_HYST 0x06
>>> +#define AD7291_CH1_DATA_HIGH 0x07
>>> +#define AD7291_CH1_DATA_LOW 0x08
>>> +#define AD7291_CH1_HYST 0x09
>>> +#define AD7291_CH2_DATA_HIGH 0x0A
>>> +#define AD7291_CH2_DATA_LOW 0x0B
>>> +#define AD7291_CH2_HYST 0x0C
>>> +#define AD7291_CH3_DATA_HIGH 0x0D
>>> +#define AD7291_CH3_DATA_LOW 0x0E
>>> +#define AD7291_CH3_HYST 0x0F
>>> +#define AD7291_CH4_DATA_HIGH 0x10
>>> +#define AD7291_CH4_DATA_LOW 0x11
>>> +#define AD7291_CH4_HYST 0x12
>>> +#define AD7291_CH5_DATA_HIGH 0x13
>>> +#define AD7291_CH5_DATA_LOW 0x14
>>> +#define AD7291_CH5_HYST 0x15
>>> +#define AD7291_CH6_DATA_HIGH 0x16
>>> +#define AD7291_CH6_DATA_LOW 0x17
>>> +#define AD7291_CH6_HYST 0x18
>>> +#define AD7291_CH7_DATA_HIGH 0x19
>>> +#define AD7291_CH7_DATA_LOW 0x1A
>>> +#define AD7291_CH7_HYST 0x2B
>>> #define AD7291_T_SENSE_HIGH 0x1C
>>> #define AD7291_T_SENSE_LOW 0x1D
>>> #define AD7291_T_SENSE_HYST 0x1E
>>> #define AD7291_VOLTAGE_ALERT_STATUS 0x1F
>>> #define AD7291_T_ALERT_STATUS 0x20
>>> +#define AD7291_VOLTAGE_LIMIT_COUNT 8
>>> +
>>> +
>>> /*
>>> * AD7291 command
>>> */
>>> @@ -197,7 +222,7 @@ static inline ssize_t ad7291_show_hyst(struct
>> device *dev,
>>> if (ret < 0)
>>> return ret;
>>> - return sprintf(buf, "%d\n", data & 0x0FFF);
>>> + return sprintf(buf, "%d\n", data & AD7291_VALUE_MASK);
>>> }
>>>
>>> static inline ssize_t ad7291_set_hyst(struct device *dev,
>>> @@ -227,28 +252,28 @@ static
>> IIO_DEVICE_ATTR(in_temp0_thresh_both_hyst_raw,
>>> AD7291_T_SENSE_HYST);
>>> static IIO_DEVICE_ATTR(in_voltage0_thresh_both_hyst_raw,
>>> S_IRUGO | S_IWUSR,
>>> - ad7291_show_hyst, ad7291_set_hyst, 0x06);
>>> + ad7291_show_hyst, ad7291_set_hyst, AD7291_CH0_HYST);
>>> static IIO_DEVICE_ATTR(in_voltage1_thresh_both_hyst_raw,
>>> S_IRUGO | S_IWUSR,
>>> - ad7291_show_hyst, ad7291_set_hyst, 0x09);
>>> + ad7291_show_hyst, ad7291_set_hyst, AD7291_CH1_HYST);
>>> static IIO_DEVICE_ATTR(in_voltage2_thresh_both_hyst_raw,
>>> S_IRUGO | S_IWUSR,
>>> - ad7291_show_hyst, ad7291_set_hyst, 0x0C);
>>> + ad7291_show_hyst, ad7291_set_hyst, AD7291_CH2_HYST);
>>> static IIO_DEVICE_ATTR(in_voltage3_thresh_both_hyst_raw,
>>> S_IRUGO | S_IWUSR,
>>> - ad7291_show_hyst, ad7291_set_hyst, 0x0F);
>>> + ad7291_show_hyst, ad7291_set_hyst, AD7291_CH3_HYST);
>>> static IIO_DEVICE_ATTR(in_voltage4_thresh_both_hyst_raw,
>>> S_IRUGO | S_IWUSR,
>>> - ad7291_show_hyst, ad7291_set_hyst, 0x12);
>>> + ad7291_show_hyst, ad7291_set_hyst, AD7291_CH4_HYST);
>>> static IIO_DEVICE_ATTR(in_voltage5_thresh_both_hyst_raw,
>>> S_IRUGO | S_IWUSR,
>>> - ad7291_show_hyst, ad7291_set_hyst, 0x15);
>>> + ad7291_show_hyst, ad7291_set_hyst, AD7291_CH5_HYST);
>>> static IIO_DEVICE_ATTR(in_voltage6_thresh_both_hyst_raw,
>>> S_IRUGO | S_IWUSR,
>>> - ad7291_show_hyst, ad7291_set_hyst, 0x18);
>>> + ad7291_show_hyst, ad7291_set_hyst, AD7291_CH6_HYST);
>>> static IIO_DEVICE_ATTR(in_voltage7_thresh_both_hyst_raw,
>>> S_IRUGO | S_IWUSR,
>>> - ad7291_show_hyst, ad7291_set_hyst, 0x1B);
>>> + ad7291_show_hyst, ad7291_set_hyst, AD7291_CH7_HYST);
>>>
>>> static struct attribute *ad7291_event_attributes[] = {
>>> &iio_dev_attr_in_temp0_thresh_both_hyst_raw.dev_attr.attr,
>>> @@ -265,16 +290,16 @@ static struct attribute
>>> *ad7291_event_attributes[] = {
>>>
>>> /* high / low */
>>> static u8 ad7291_limit_regs[9][2] = {
>>> - { 0x04, 0x05 },
>>> - { 0x07, 0x08 },
>>> - { 0x0A, 0x0B },
>>> - { 0x0E, 0x0D }, /* note reversed order */
>>> - { 0x10, 0x11 },
>>> - { 0x13, 0x14 },
>>> - { 0x16, 0x17 },
>>> - { 0x19, 0x1A },
>>> + { AD7291_CH0_DATA_HIGH, AD7291_CH0_DATA_LOW },
>>> + { AD7291_CH1_DATA_HIGH, AD7291_CH1_DATA_LOW },
>>> + { AD7291_CH2_DATA_HIGH, AD7291_CH2_DATA_LOW },
>>> + { AD7291_CH3_DATA_HIGH, AD7291_CH3_DATA_LOW }, /* FIXME: ? */
>>> + { AD7291_CH4_DATA_HIGH, AD7291_CH4_DATA_LOW },
>>> + { AD7291_CH5_DATA_HIGH, AD7291_CH5_DATA_LOW },
>>> + { AD7291_CH6_DATA_HIGH, AD7291_CH6_DATA_LOW },
>>> + { AD7291_CH7_DATA_HIGH, AD7291_CH7_DATA_LOW },
>>> /* temp */
>>> - { 0x1C, 0x1D },
>>> + { AD7291_T_SENSE_HIGH, AD7291_T_SENSE_LOW },
>>> };
>>>
>>> static int ad7291_read_event_value(struct iio_dev *indio_dev,
>>> @@ -297,7 +322,7 @@ static int ad7291_read_event_value(struct iio_dev
>> *indio_dev,
>>> ret = ad7291_i2c_read(chip, reg, &uval);
>>> if (ret < 0)
>>> return ret;
>>> - *val = swab16(uval) & 0x0FFF;
>>> + *val = uval & AD7291_VALUE_MASK;
>>> return 0;
>>>
>>> case IIO_TEMP:
>>> @@ -308,7 +333,7 @@ static int ad7291_read_event_value(struct iio_dev
>> *indio_dev,
>>> ret = ad7291_i2c_read(chip, reg, &signval);
>>> if (ret < 0)
>>> return ret;
>>> - signval = (s16)((swab16(signval) & 0x0FFF) << 4) >> 4;
>>> + signval = (s16)((signval & AD7291_VALUE_MASK) << 4) >> 4;
>>> *val = signval;
>>> return 0;
>>> default:
>>> @@ -331,9 +356,7 @@ static int ad7291_write_event_value(struct
>> iio_dev *indio_dev,
>>> reg = ad7291_limit_regs[IIO_EVENT_CODE_EXTRACT_NUM(event_code)]
>>> [!(IIO_EVENT_CODE_EXTRACT_DIR(event_code) ==
>>> IIO_EV_DIR_RISING)]; - return ad7291_i2c_write(chip, reg, val); -
>>> case IIO_TEMP: if (val > 2047 || val < -2048) return -EINVAL;
>>> @@ -385,6 +408,7 @@ static int ad7291_write_event_config(struct
>> iio_dev *indio_dev,
>>> * use continuous sampling mode. * Possible to disable temp as well
>>> but that makes single read tricky. */ + switch
>>> (IIO_EVENT_CODE_EXTRACT_TYPE(event_code)) { case IIO_VOLTAGE: if
>>> ((!state) && (chip->c_mask &
>>> @@ -398,7 +422,7 @@ static int ad7291_write_event_config(struct
>> iio_dev *indio_dev,
>>> else
>>> break;
>>> - regval &= 0xFFFE;
>>> + regval &= ~AD7291_AUTOCYCLE;
>>> regval |= ((u16)chip->c_mask << 8);
>>> if (chip->c_mask) /* Enable autocycle? */
>>> regval |= AD7291_AUTOCYCLE;
>>> @@ -455,7 +479,7 @@ static int ad7291_read_raw(struct iio_dev
>> *indio_dev,
>>> mutex_unlock(&chip->state_lock);
>>> return ret;
>>> }
>>> - *val = swab16((u16)ret) & 0x0FFF;
>>> + *val = swab16((u16)ret) & AD7291_VALUE_MASK;
>>> mutex_unlock(&chip->state_lock);
>>> return IIO_VAL_INT;
>>> case IIO_TEMP:
>>> @@ -464,7 +488,8 @@ static int ad7291_read_raw(struct iio_dev
>> *indio_dev,
>>> AD7291_T_SENSE);
>>> if (ret < 0)
>>> return ret;
>>> - signval = (s16)((swab16((u16)ret) & 0x0FFF) << 4) >> 4; + signval
>>> = (s16)((swab16((u16)ret) & + AD7291_VALUE_MASK) << 4) >> 4;
>>> *val = signval;
>>> return IIO_VAL_INT;
>>> default:
>>> @@ -475,7 +500,8 @@ static int ad7291_read_raw(struct iio_dev
>> *indio_dev,
>>> AD7291_T_AVERAGE);
>>> if (ret < 0)
>>> return ret;
>>> - signval = (s16)((swab16((u16)ret) & 0x0FFF) << 4) >> 4; + signval
>>> = (s16)((swab16((u16)ret) & + AD7291_VALUE_MASK) << 4) >> 4;
>>> *val = signval;
>>> return IIO_VAL_INT;
>>> case (1 << IIO_CHAN_INFO_SCALE_SHARED):
>>
>
> Greetings,
> Michael
>
> --
> Analog Devices GmbH Wilhelm-Wagenfeld-Str. 6 80807 Muenchen
> Sitz der Gesellschaft: Muenchen; Registergericht: Muenchen HRB 40368;
> Geschaeftsfuehrer:Dr.Carsten Suckrow, Thomas Wessel, William A. Martin, Margaret Seif
>
>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply [flat|nested] 29+ messages in thread
end of thread, other threads:[~2011-08-31 12:01 UTC | newest]
Thread overview: 29+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-31 10:57 [PATCH 01/12] iio: ad7291: fix channel mapping michael.hennerich
2011-08-31 10:57 ` [PATCH 02/12] iio: ad7291: Fix typos, change kconfig description and file header michael.hennerich
2011-08-31 11:18 ` Jonathan Cameron
2011-08-31 10:57 ` [PATCH 03/12] iio: ad7291: Fix AD7291_T_SENSE_MASK michael.hennerich
2011-08-31 11:19 ` Jonathan Cameron
2011-08-31 10:57 ` [PATCH 04/12] iio: ad7291: Add regulator, reference voltage and scale handling michael.hennerich
2011-08-31 11:22 ` Jonathan Cameron
2011-08-31 10:57 ` [PATCH 05/12] iio: ad7291: don't swab results twice and introduce more register defines michael.hennerich
2011-08-31 11:28 ` Jonathan Cameron
2011-08-31 11:49 ` Hennerich, Michael
2011-08-31 12:01 ` Jonathan Cameron
2011-08-31 10:57 ` [PATCH 06/12] iio: ad7291: fix mask bit generation michael.hennerich
2011-08-31 11:29 ` Jonathan Cameron
2011-08-31 10:57 ` [PATCH 07/12] iio: ad7291: introduce IIO_EVENT_CODE_EXTRACT_CHAN_TYPE and use accordingly michael.hennerich
2011-08-31 11:33 ` Jonathan Cameron
2011-08-31 10:57 ` [PATCH 08/12] iio: ad7291: fix channel mapping for event enables michael.hennerich
2011-08-31 11:34 ` Jonathan Cameron
2011-08-31 10:57 ` [PATCH 09/12] iio: core: fix IIO_EVENT_CODE_EXTRACT_DIR definition michael.hennerich
2011-08-31 11:15 ` Jonathan Cameron
2011-08-31 12:01 ` Jonathan Cameron
2011-08-31 10:57 ` [PATCH 10/12] iio: ad7192: return len and fix out of range checking michael.hennerich
2011-08-31 11:37 ` Jonathan Cameron
2011-08-31 11:47 ` Hennerich, Michael
2011-08-31 11:59 ` Jonathan Cameron
2011-08-31 10:57 ` [PATCH 11/12] iio: ad7291: reset device and setup irq before it is enabled michael.hennerich
2011-08-31 11:39 ` Jonathan Cameron
2011-08-31 10:57 ` [PATCH 12/12] iio: ad7192: add temp_scale attribute, change module description michael.hennerich
2011-08-31 11:52 ` Jonathan Cameron
2011-08-31 11:14 ` [PATCH 01/12] iio: ad7291: fix channel mapping Jonathan Cameron
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.