* [PATCH v3 00/12] ad799x cleanup
@ 2014-06-12 4:54 Peter Meerwald
2014-06-12 4:54 ` [PATCH v3 01/12] iio:adc:ad799x: Fix reading and writing of event values, apply shift Peter Meerwald
` (11 more replies)
0 siblings, 12 replies; 31+ messages in thread
From: Peter Meerwald @ 2014-06-12 4:54 UTC (permalink / raw)
To: linux-iio; +Cc: jic23
v3 folds reading/writing event values and range checking into first patch
Peter Meerwald (12):
iio:adc:ad799x: Fix reading and writing of event values, apply shift
iio:adc:ad799x: Fix ad799x_chip_info kerneldoc
iio:adc:ad799x: Drop I2C access helper functions
iio:adc:ad799x: Save some lines in ad7997_8_update_scan_mode() exit
handling
iio:adc:ad799x: Use BIT() and GENMASK()
iio:adc:ad799x: Only expose event interface when IRQ is available
iio:adc:ad799x: Make chan_spec const in ad799x_chip_config struct
iio:adc:ad799x: Add helper function to read/write config register
iio:adc:ad799x: Write default config on probe and reset alert status
on probe
iio:adc:ad799x: Set conversion channels and rename
ad7997_8_update_scan_mode()
iio:adc:ad799x: Return more meaningful event enabled state
iio:adc:ad799x: Allow to write event config
drivers/iio/adc/ad799x.c | 509 ++++++++++++++++++++++++++++-------------------
1 file changed, 306 insertions(+), 203 deletions(-)
--
1.9.1
^ permalink raw reply [flat|nested] 31+ messages in thread
* [PATCH v3 01/12] iio:adc:ad799x: Fix reading and writing of event values, apply shift
2014-06-12 4:54 [PATCH v3 00/12] ad799x cleanup Peter Meerwald
@ 2014-06-12 4:54 ` Peter Meerwald
2014-06-12 8:07 ` Lars-Peter Clausen
2014-06-12 4:54 ` [PATCH v3 02/12] iio:adc:ad799x: Fix ad799x_chip_info kerneldoc Peter Meerwald
` (10 subsequent siblings)
11 siblings, 1 reply; 31+ messages in thread
From: Peter Meerwald @ 2014-06-12 4:54 UTC (permalink / raw)
To: linux-iio; +Cc: jic23, Peter Meerwald
last two bits of ADC and limit values are zero and should not be reported
(ad7993, ad7997); compare with read_raw()
event values are 10 (ad7993, ad7997) or 12 bit max., check the range on write
Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
---
drivers/iio/adc/ad799x.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/drivers/iio/adc/ad799x.c b/drivers/iio/adc/ad799x.c
index 39b4cb4..6eba301 100644
--- a/drivers/iio/adc/ad799x.c
+++ b/drivers/iio/adc/ad799x.c
@@ -427,9 +427,12 @@ static int ad799x_write_event_value(struct iio_dev *indio_dev,
int ret;
struct ad799x_state *st = iio_priv(indio_dev);
+ if (val < 0 || val > RES_MASK(chan->scan_type.realbits))
+ return -EINVAL;
+
mutex_lock(&indio_dev->mlock);
ret = ad799x_i2c_write16(st, ad799x_threshold_reg(chan, dir, info),
- val);
+ val << chan->scan_type.shift);
mutex_unlock(&indio_dev->mlock);
return ret;
@@ -452,7 +455,8 @@ static int ad799x_read_event_value(struct iio_dev *indio_dev,
mutex_unlock(&indio_dev->mlock);
if (ret < 0)
return ret;
- *val = valin;
+ *val = (valin >> chan->scan_type.shift) &
+ RES_MASK(chan->scan_type.realbits);
return IIO_VAL_INT;
}
--
1.9.1
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH v3 02/12] iio:adc:ad799x: Fix ad799x_chip_info kerneldoc
2014-06-12 4:54 [PATCH v3 00/12] ad799x cleanup Peter Meerwald
2014-06-12 4:54 ` [PATCH v3 01/12] iio:adc:ad799x: Fix reading and writing of event values, apply shift Peter Meerwald
@ 2014-06-12 4:54 ` Peter Meerwald
2014-06-14 14:21 ` Jonathan Cameron
2014-06-12 4:54 ` [PATCH v3 03/12] iio:adc:ad799x: Drop I2C access helper functions Peter Meerwald
` (9 subsequent siblings)
11 siblings, 1 reply; 31+ messages in thread
From: Peter Meerwald @ 2014-06-12 4:54 UTC (permalink / raw)
To: linux-iio; +Cc: jic23, Peter Meerwald
Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
Acked-by: Lars-Peter Clausen <lars@metafoo.de>
---
drivers/iio/adc/ad799x.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/iio/adc/ad799x.c b/drivers/iio/adc/ad799x.c
index 6eba301..6cf9ee1 100644
--- a/drivers/iio/adc/ad799x.c
+++ b/drivers/iio/adc/ad799x.c
@@ -105,9 +105,8 @@ enum {
* struct ad799x_chip_info - chip specific information
* @channel: channel specification
* @num_channels: number of channels
- * @monitor_mode: whether the chip supports monitor interrupts
* @default_config: device default configuration
- * @event_attrs: pointer to the monitor event attribute group
+ * @info: pointer to iio_info struct
*/
struct ad799x_chip_info {
struct iio_chan_spec channel[9];
--
1.9.1
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH v3 03/12] iio:adc:ad799x: Drop I2C access helper functions
2014-06-12 4:54 [PATCH v3 00/12] ad799x cleanup Peter Meerwald
2014-06-12 4:54 ` [PATCH v3 01/12] iio:adc:ad799x: Fix reading and writing of event values, apply shift Peter Meerwald
2014-06-12 4:54 ` [PATCH v3 02/12] iio:adc:ad799x: Fix ad799x_chip_info kerneldoc Peter Meerwald
@ 2014-06-12 4:54 ` Peter Meerwald
2014-06-12 8:10 ` Lars-Peter Clausen
2014-06-12 4:54 ` [PATCH v3 04/12] iio:adc:ad799x: Save some lines in ad7997_8_update_scan_mode() exit handling Peter Meerwald
` (8 subsequent siblings)
11 siblings, 1 reply; 31+ messages in thread
From: Peter Meerwald @ 2014-06-12 4:54 UTC (permalink / raw)
To: linux-iio; +Cc: jic23, Peter Meerwald
Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
---
drivers/iio/adc/ad799x.c | 119 +++++++++++------------------------------------
1 file changed, 26 insertions(+), 93 deletions(-)
diff --git a/drivers/iio/adc/ad799x.c b/drivers/iio/adc/ad799x.c
index 6cf9ee1..34d93a5 100644
--- a/drivers/iio/adc/ad799x.c
+++ b/drivers/iio/adc/ad799x.c
@@ -175,65 +175,6 @@ out:
return IRQ_HANDLED;
}
-/*
- * ad799x register access by I2C
- */
-static int ad799x_i2c_read16(struct ad799x_state *st, u8 reg, u16 *data)
-{
- struct i2c_client *client = st->client;
- int ret = 0;
-
- ret = i2c_smbus_read_word_swapped(client, reg);
- if (ret < 0) {
- dev_err(&client->dev, "I2C read error\n");
- return ret;
- }
-
- *data = (u16)ret;
-
- return 0;
-}
-
-static int ad799x_i2c_read8(struct ad799x_state *st, u8 reg, u8 *data)
-{
- struct i2c_client *client = st->client;
- int ret = 0;
-
- ret = i2c_smbus_read_byte_data(client, reg);
- if (ret < 0) {
- dev_err(&client->dev, "I2C read error\n");
- return ret;
- }
-
- *data = (u8)ret;
-
- return 0;
-}
-
-static int ad799x_i2c_write16(struct ad799x_state *st, u8 reg, u16 data)
-{
- struct i2c_client *client = st->client;
- int ret = 0;
-
- ret = i2c_smbus_write_word_swapped(client, reg, data);
- if (ret < 0)
- dev_err(&client->dev, "I2C write error\n");
-
- return ret;
-}
-
-static int ad799x_i2c_write8(struct ad799x_state *st, u8 reg, u8 data)
-{
- struct i2c_client *client = st->client;
- int ret = 0;
-
- ret = i2c_smbus_write_byte_data(client, reg, data);
- if (ret < 0)
- dev_err(&client->dev, "I2C write error\n");
-
- return ret;
-}
-
static int ad7997_8_update_scan_mode(struct iio_dev *indio_dev,
const unsigned long *scan_mask)
{
@@ -249,7 +190,7 @@ static int ad7997_8_update_scan_mode(struct iio_dev *indio_dev,
switch (st->id) {
case ad7997:
case ad7998:
- return ad799x_i2c_write16(st, AD7998_CONF_REG,
+ return i2c_smbus_write_word_swapped(st->client, AD7998_CONF_REG,
st->config | (*scan_mask << AD799X_CHANNEL_SHIFT));
default:
break;
@@ -260,9 +201,7 @@ static int ad7997_8_update_scan_mode(struct iio_dev *indio_dev,
static int ad799x_scan_direct(struct ad799x_state *st, unsigned ch)
{
- u16 rxbuf;
u8 cmd;
- int ret;
switch (st->id) {
case ad7991:
@@ -283,11 +222,7 @@ static int ad799x_scan_direct(struct ad799x_state *st, unsigned ch)
return -EINVAL;
}
- ret = ad799x_i2c_read16(st, cmd, &rxbuf);
- if (ret < 0)
- return ret;
-
- return rxbuf;
+ return i2c_smbus_read_word_swapped(st->client, cmd);
}
static int ad799x_read_raw(struct iio_dev *indio_dev,
@@ -332,6 +267,7 @@ static const unsigned int ad7998_frequencies[] = {
[AD7998_CYC_TCONF_1024] = 488,
[AD7998_CYC_TCONF_2048] = 244,
};
+
static ssize_t ad799x_read_frequency(struct device *dev,
struct device_attribute *attr,
char *buf)
@@ -339,15 +275,11 @@ static ssize_t ad799x_read_frequency(struct device *dev,
struct iio_dev *indio_dev = dev_to_iio_dev(dev);
struct ad799x_state *st = iio_priv(indio_dev);
- int ret;
- u8 val;
- ret = ad799x_i2c_read8(st, AD7998_CYCLE_TMR_REG, &val);
- if (ret)
+ int ret = i2c_smbus_read_byte_data(st->client, AD7998_CYCLE_TMR_REG);
+ if (ret < 0)
return ret;
- val &= AD7998_CYC_MASK;
-
- return sprintf(buf, "%u\n", ad7998_frequencies[val]);
+ return sprintf(buf, "%u\n", ad7998_frequencies[ret & AD7998_CYC_MASK]);
}
static ssize_t ad799x_write_frequency(struct device *dev,
@@ -360,18 +292,17 @@ static ssize_t ad799x_write_frequency(struct device *dev,
long val;
int ret, i;
- u8 t;
ret = kstrtol(buf, 10, &val);
if (ret)
return ret;
mutex_lock(&indio_dev->mlock);
- ret = ad799x_i2c_read8(st, AD7998_CYCLE_TMR_REG, &t);
- if (ret)
+ ret = i2c_smbus_read_byte_data(st->client, AD7998_CYCLE_TMR_REG);
+ if (ret < 0)
goto error_ret_mutex;
/* Wipe the bits clean */
- t &= ~AD7998_CYC_MASK;
+ ret &= ~AD7998_CYC_MASK;
for (i = 0; i < ARRAY_SIZE(ad7998_frequencies); i++)
if (val == ad7998_frequencies[i])
@@ -380,13 +311,17 @@ static ssize_t ad799x_write_frequency(struct device *dev,
ret = -EINVAL;
goto error_ret_mutex;
}
- t |= i;
- ret = ad799x_i2c_write8(st, AD7998_CYCLE_TMR_REG, t);
+
+ ret = i2c_smbus_write_byte_data(st->client, AD7998_CYCLE_TMR_REG,
+ ret | i);
+ if (ret < 0)
+ goto error_ret_mutex;
+ ret = len;
error_ret_mutex:
mutex_unlock(&indio_dev->mlock);
- return ret ? ret : len;
+ return ret;
}
static int ad799x_read_event_config(struct iio_dev *indio_dev,
@@ -430,7 +365,8 @@ static int ad799x_write_event_value(struct iio_dev *indio_dev,
return -EINVAL;
mutex_lock(&indio_dev->mlock);
- ret = ad799x_i2c_write16(st, ad799x_threshold_reg(chan, dir, info),
+ ret = i2c_smbus_write_word_swapped(st->client,
+ ad799x_threshold_reg(chan, dir, info),
val << chan->scan_type.shift);
mutex_unlock(&indio_dev->mlock);
@@ -446,15 +382,14 @@ static int ad799x_read_event_value(struct iio_dev *indio_dev,
{
int ret;
struct ad799x_state *st = iio_priv(indio_dev);
- u16 valin;
mutex_lock(&indio_dev->mlock);
- ret = ad799x_i2c_read16(st, ad799x_threshold_reg(chan, dir, info),
- &valin);
+ ret = i2c_smbus_read_word_swapped(st->client,
+ ad799x_threshold_reg(chan, dir, info));
mutex_unlock(&indio_dev->mlock);
if (ret < 0)
return ret;
- *val = (valin >> chan->scan_type.shift) &
+ *val = (ret >> chan->scan_type.shift) &
RES_MASK(chan->scan_type.realbits);
return IIO_VAL_INT;
@@ -464,20 +399,18 @@ static irqreturn_t ad799x_event_handler(int irq, void *private)
{
struct iio_dev *indio_dev = private;
struct ad799x_state *st = iio_priv(private);
- u8 status;
int i, ret;
- ret = ad799x_i2c_read8(st, AD7998_ALERT_STAT_REG, &status);
- if (ret)
+ ret = i2c_smbus_read_byte_data(st->client, AD7998_ALERT_STAT_REG);
+ if (ret <= 0)
goto done;
- if (!status)
+ if (i2c_smbus_write_byte_data(st->client, AD7998_ALERT_STAT_REG,
+ AD7998_ALERT_STAT_CLEAR) < 0)
goto done;
- ad799x_i2c_write8(st, AD7998_ALERT_STAT_REG, AD7998_ALERT_STAT_CLEAR);
-
for (i = 0; i < 8; i++) {
- if (status & (1 << i))
+ if (ret & (1 << i))
iio_push_event(indio_dev,
i & 0x1 ?
IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE,
--
1.9.1
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH v3 04/12] iio:adc:ad799x: Save some lines in ad7997_8_update_scan_mode() exit handling
2014-06-12 4:54 [PATCH v3 00/12] ad799x cleanup Peter Meerwald
` (2 preceding siblings ...)
2014-06-12 4:54 ` [PATCH v3 03/12] iio:adc:ad799x: Drop I2C access helper functions Peter Meerwald
@ 2014-06-12 4:54 ` Peter Meerwald
2014-07-13 20:56 ` Jonathan Cameron
2014-06-12 4:54 ` [PATCH v3 05/12] iio:adc:ad799x: Use BIT() and GENMASK() Peter Meerwald
` (7 subsequent siblings)
11 siblings, 1 reply; 31+ messages in thread
From: Peter Meerwald @ 2014-06-12 4:54 UTC (permalink / raw)
To: linux-iio; +Cc: jic23, Peter Meerwald
Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
Acked-by: Lars-Peter Clausen <lars@metafoo.de>
---
drivers/iio/adc/ad799x.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/drivers/iio/adc/ad799x.c b/drivers/iio/adc/ad799x.c
index 34d93a5..878400c 100644
--- a/drivers/iio/adc/ad799x.c
+++ b/drivers/iio/adc/ad799x.c
@@ -193,10 +193,8 @@ static int ad7997_8_update_scan_mode(struct iio_dev *indio_dev,
return i2c_smbus_write_word_swapped(st->client, AD7998_CONF_REG,
st->config | (*scan_mask << AD799X_CHANNEL_SHIFT));
default:
- break;
+ return 0;
}
-
- return 0;
}
static int ad799x_scan_direct(struct ad799x_state *st, unsigned ch)
--
1.9.1
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH v3 05/12] iio:adc:ad799x: Use BIT() and GENMASK()
2014-06-12 4:54 [PATCH v3 00/12] ad799x cleanup Peter Meerwald
` (3 preceding siblings ...)
2014-06-12 4:54 ` [PATCH v3 04/12] iio:adc:ad799x: Save some lines in ad7997_8_update_scan_mode() exit handling Peter Meerwald
@ 2014-06-12 4:54 ` Peter Meerwald
2014-07-13 20:56 ` Jonathan Cameron
2014-06-12 4:54 ` [PATCH v3 06/12] iio:adc:ad799x: Only expose event interface when IRQ is available Peter Meerwald
` (6 subsequent siblings)
11 siblings, 1 reply; 31+ messages in thread
From: Peter Meerwald @ 2014-06-12 4:54 UTC (permalink / raw)
To: linux-iio; +Cc: jic23, Peter Meerwald
Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
Acked-by: Lars-Peter Clausen <lars@metafoo.de>
---
drivers/iio/adc/ad799x.c | 31 +++++++++++++++----------------
1 file changed, 15 insertions(+), 16 deletions(-)
diff --git a/drivers/iio/adc/ad799x.c b/drivers/iio/adc/ad799x.c
index 878400c..b3799a8 100644
--- a/drivers/iio/adc/ad799x.c
+++ b/drivers/iio/adc/ad799x.c
@@ -32,6 +32,7 @@
#include <linux/types.h>
#include <linux/err.h>
#include <linux/module.h>
+#include <linux/bitops.h>
#include <linux/iio/iio.h>
#include <linux/iio/sysfs.h>
@@ -41,7 +42,7 @@
#include <linux/iio/triggered_buffer.h>
#define AD799X_CHANNEL_SHIFT 4
-#define AD799X_STORAGEBITS 16
+
/*
* AD7991, AD7995 and AD7999 defines
*/
@@ -55,10 +56,10 @@
* AD7992, AD7993, AD7994, AD7997 and AD7998 defines
*/
-#define AD7998_FLTR 0x08
-#define AD7998_ALERT_EN 0x04
-#define AD7998_BUSY_ALERT 0x02
-#define AD7998_BUSY_ALERT_POL 0x01
+#define AD7998_FLTR BIT(3)
+#define AD7998_ALERT_EN BIT(2)
+#define AD7998_BUSY_ALERT BIT(1)
+#define AD7998_BUSY_ALERT_POL BIT(0)
#define AD7998_CONV_RES_REG 0x0
#define AD7998_ALERT_STAT_REG 0x1
@@ -69,7 +70,7 @@
#define AD7998_DATAHIGH_REG(x) ((x) * 3 + 0x5)
#define AD7998_HYST_REG(x) ((x) * 3 + 0x6)
-#define AD7998_CYC_MASK 0x7
+#define AD7998_CYC_MASK GENMASK(2, 0)
#define AD7998_CYC_DIS 0x0
#define AD7998_CYC_TCONF_32 0x1
#define AD7998_CYC_TCONF_64 0x2
@@ -85,10 +86,8 @@
* AD7997 and AD7997 defines
*/
-#define AD7997_8_READ_SINGLE 0x80
-#define AD7997_8_READ_SEQUENCE 0x70
-/* TODO: move this into a common header */
-#define RES_MASK(bits) ((1 << (bits)) - 1)
+#define AD7997_8_READ_SINGLE BIT(7)
+#define AD7997_8_READ_SEQUENCE (BIT(6) | BIT(5) | BIT(4))
enum {
ad7991,
@@ -205,12 +204,12 @@ static int ad799x_scan_direct(struct ad799x_state *st, unsigned ch)
case ad7991:
case ad7995:
case ad7999:
- cmd = st->config | ((1 << ch) << AD799X_CHANNEL_SHIFT);
+ cmd = st->config | (BIT(ch) << AD799X_CHANNEL_SHIFT);
break;
case ad7992:
case ad7993:
case ad7994:
- cmd = (1 << ch) << AD799X_CHANNEL_SHIFT;
+ cmd = BIT(ch) << AD799X_CHANNEL_SHIFT;
break;
case ad7997:
case ad7998:
@@ -244,7 +243,7 @@ static int ad799x_read_raw(struct iio_dev *indio_dev,
if (ret < 0)
return ret;
*val = (ret >> chan->scan_type.shift) &
- RES_MASK(chan->scan_type.realbits);
+ GENMASK(chan->scan_type.realbits - 1, 0);
return IIO_VAL_INT;
case IIO_CHAN_INFO_SCALE:
ret = regulator_get_voltage(st->vref);
@@ -359,7 +358,7 @@ static int ad799x_write_event_value(struct iio_dev *indio_dev,
int ret;
struct ad799x_state *st = iio_priv(indio_dev);
- if (val < 0 || val > RES_MASK(chan->scan_type.realbits))
+ if (val < 0 || val > GENMASK(chan->scan_type.realbits - 1, 0))
return -EINVAL;
mutex_lock(&indio_dev->mlock);
@@ -388,7 +387,7 @@ static int ad799x_read_event_value(struct iio_dev *indio_dev,
if (ret < 0)
return ret;
*val = (ret >> chan->scan_type.shift) &
- RES_MASK(chan->scan_type.realbits);
+ GENMASK(chan->scan_type.realbits - 1 , 0);
return IIO_VAL_INT;
}
@@ -408,7 +407,7 @@ static irqreturn_t ad799x_event_handler(int irq, void *private)
goto done;
for (i = 0; i < 8; i++) {
- if (ret & (1 << i))
+ if (ret & BIT(i))
iio_push_event(indio_dev,
i & 0x1 ?
IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE,
--
1.9.1
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH v3 06/12] iio:adc:ad799x: Only expose event interface when IRQ is available
2014-06-12 4:54 [PATCH v3 00/12] ad799x cleanup Peter Meerwald
` (4 preceding siblings ...)
2014-06-12 4:54 ` [PATCH v3 05/12] iio:adc:ad799x: Use BIT() and GENMASK() Peter Meerwald
@ 2014-06-12 4:54 ` Peter Meerwald
2014-07-13 20:56 ` Jonathan Cameron
2014-06-12 4:54 ` [PATCH v3 07/12] iio:adc:ad799x: Make chan_spec const in ad799x_chip_config struct Peter Meerwald
` (5 subsequent siblings)
11 siblings, 1 reply; 31+ messages in thread
From: Peter Meerwald @ 2014-06-12 4:54 UTC (permalink / raw)
To: linux-iio; +Cc: jic23, Peter Meerwald
an IRQ is necessary to handle the ALERT condition; without
IRQ, the IIO event interface serves no purpose
Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
Acked-by: Lars-Peter Clausen <lars@metafoo.de>
---
drivers/iio/adc/ad799x.c | 265 ++++++++++++++++++++++++++++++++---------------
1 file changed, 179 insertions(+), 86 deletions(-)
diff --git a/drivers/iio/adc/ad799x.c b/drivers/iio/adc/ad799x.c
index b3799a8..b8a8117 100644
--- a/drivers/iio/adc/ad799x.c
+++ b/drivers/iio/adc/ad799x.c
@@ -101,22 +101,32 @@ enum {
};
/**
- * struct ad799x_chip_info - chip specific information
+ * struct ad799x_chip_config - chip specific information
* @channel: channel specification
- * @num_channels: number of channels
* @default_config: device default configuration
* @info: pointer to iio_info struct
*/
-struct ad799x_chip_info {
+struct ad799x_chip_config {
struct iio_chan_spec channel[9];
- int num_channels;
u16 default_config;
const struct iio_info *info;
};
+/**
+ * struct ad799x_chip_info - chip specific information
+ * @num_channels: number of channels
+ * @noirq_config: device configuration w/o IRQ
+ * @irq_config: device configuration w/IRQ
+ */
+struct ad799x_chip_info {
+ int num_channels;
+ const struct ad799x_chip_config noirq_config;
+ const struct ad799x_chip_config irq_config;
+};
+
struct ad799x_state {
struct i2c_client *client;
- const struct ad799x_chip_info *chip_info;
+ const struct ad799x_chip_config *chip_config;
struct regulator *reg;
struct regulator *vref;
unsigned id;
@@ -446,7 +456,13 @@ static const struct iio_info ad7991_info = {
.driver_module = THIS_MODULE,
};
-static const struct iio_info ad7993_4_7_8_info = {
+static const struct iio_info ad7993_4_7_8_noirq_info = {
+ .read_raw = &ad799x_read_raw,
+ .driver_module = THIS_MODULE,
+ .update_scan_mode = ad7997_8_update_scan_mode,
+};
+
+static const struct iio_info ad7993_4_7_8_irq_info = {
.read_raw = &ad799x_read_raw,
.event_attrs = &ad799x_event_attrs_group,
.read_event_config = &ad799x_read_event_config,
@@ -501,103 +517,175 @@ static const struct iio_event_spec ad799x_events[] = {
static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
[ad7991] = {
- .channel = {
- AD799X_CHANNEL(0, 12),
- AD799X_CHANNEL(1, 12),
- AD799X_CHANNEL(2, 12),
- AD799X_CHANNEL(3, 12),
- IIO_CHAN_SOFT_TIMESTAMP(4),
- },
.num_channels = 5,
- .info = &ad7991_info,
+ .noirq_config = {
+ .channel = {
+ AD799X_CHANNEL(0, 12),
+ AD799X_CHANNEL(1, 12),
+ AD799X_CHANNEL(2, 12),
+ AD799X_CHANNEL(3, 12),
+ IIO_CHAN_SOFT_TIMESTAMP(4),
+ },
+ .info = &ad7991_info,
+ },
},
[ad7995] = {
- .channel = {
- AD799X_CHANNEL(0, 10),
- AD799X_CHANNEL(1, 10),
- AD799X_CHANNEL(2, 10),
- AD799X_CHANNEL(3, 10),
- IIO_CHAN_SOFT_TIMESTAMP(4),
- },
.num_channels = 5,
- .info = &ad7991_info,
+ .noirq_config = {
+ .channel = {
+ AD799X_CHANNEL(0, 10),
+ AD799X_CHANNEL(1, 10),
+ AD799X_CHANNEL(2, 10),
+ AD799X_CHANNEL(3, 10),
+ IIO_CHAN_SOFT_TIMESTAMP(4),
+ },
+ .info = &ad7991_info,
+ },
},
[ad7999] = {
- .channel = {
- AD799X_CHANNEL(0, 8),
- AD799X_CHANNEL(1, 8),
- AD799X_CHANNEL(2, 8),
- AD799X_CHANNEL(3, 8),
- IIO_CHAN_SOFT_TIMESTAMP(4),
- },
.num_channels = 5,
- .info = &ad7991_info,
+ .noirq_config = {
+ .channel = {
+ AD799X_CHANNEL(0, 8),
+ AD799X_CHANNEL(1, 8),
+ AD799X_CHANNEL(2, 8),
+ AD799X_CHANNEL(3, 8),
+ IIO_CHAN_SOFT_TIMESTAMP(4),
+ },
+ .info = &ad7991_info,
+ },
},
[ad7992] = {
- .channel = {
- AD799X_CHANNEL_WITH_EVENTS(0, 12),
- AD799X_CHANNEL_WITH_EVENTS(1, 12),
- IIO_CHAN_SOFT_TIMESTAMP(3),
- },
.num_channels = 3,
- .default_config = AD7998_ALERT_EN,
- .info = &ad7993_4_7_8_info,
+ .noirq_config = {
+ .channel = {
+ AD799X_CHANNEL(0, 12),
+ AD799X_CHANNEL(1, 12),
+ IIO_CHAN_SOFT_TIMESTAMP(3),
+ },
+ .info = &ad7993_4_7_8_noirq_info,
+ },
+ .irq_config = {
+ .channel = {
+ AD799X_CHANNEL_WITH_EVENTS(0, 12),
+ AD799X_CHANNEL_WITH_EVENTS(1, 12),
+ IIO_CHAN_SOFT_TIMESTAMP(3),
+ },
+ .default_config = AD7998_ALERT_EN,
+ .info = &ad7993_4_7_8_irq_info,
+ },
},
[ad7993] = {
- .channel = {
- AD799X_CHANNEL_WITH_EVENTS(0, 10),
- AD799X_CHANNEL_WITH_EVENTS(1, 10),
- AD799X_CHANNEL_WITH_EVENTS(2, 10),
- AD799X_CHANNEL_WITH_EVENTS(3, 10),
- IIO_CHAN_SOFT_TIMESTAMP(4),
- },
.num_channels = 5,
- .default_config = AD7998_ALERT_EN,
- .info = &ad7993_4_7_8_info,
+ .noirq_config = {
+ .channel = {
+ AD799X_CHANNEL(0, 10),
+ AD799X_CHANNEL(1, 10),
+ AD799X_CHANNEL(2, 10),
+ AD799X_CHANNEL(3, 10),
+ IIO_CHAN_SOFT_TIMESTAMP(4),
+ },
+ .info = &ad7993_4_7_8_noirq_info,
+ },
+ .irq_config = {
+ .channel = {
+ AD799X_CHANNEL_WITH_EVENTS(0, 10),
+ AD799X_CHANNEL_WITH_EVENTS(1, 10),
+ AD799X_CHANNEL_WITH_EVENTS(2, 10),
+ AD799X_CHANNEL_WITH_EVENTS(3, 10),
+ IIO_CHAN_SOFT_TIMESTAMP(4),
+ },
+ .default_config = AD7998_ALERT_EN,
+ .info = &ad7993_4_7_8_irq_info,
+ },
},
[ad7994] = {
- .channel = {
- AD799X_CHANNEL_WITH_EVENTS(0, 12),
- AD799X_CHANNEL_WITH_EVENTS(1, 12),
- AD799X_CHANNEL_WITH_EVENTS(2, 12),
- AD799X_CHANNEL_WITH_EVENTS(3, 12),
- IIO_CHAN_SOFT_TIMESTAMP(4),
- },
.num_channels = 5,
- .default_config = AD7998_ALERT_EN,
- .info = &ad7993_4_7_8_info,
+ .noirq_config = {
+ .channel = {
+ AD799X_CHANNEL(0, 12),
+ AD799X_CHANNEL(1, 12),
+ AD799X_CHANNEL(2, 12),
+ AD799X_CHANNEL(3, 12),
+ IIO_CHAN_SOFT_TIMESTAMP(4),
+ },
+ .info = &ad7993_4_7_8_noirq_info,
+ },
+ .irq_config = {
+ .channel = {
+ AD799X_CHANNEL_WITH_EVENTS(0, 12),
+ AD799X_CHANNEL_WITH_EVENTS(1, 12),
+ AD799X_CHANNEL_WITH_EVENTS(2, 12),
+ AD799X_CHANNEL_WITH_EVENTS(3, 12),
+ IIO_CHAN_SOFT_TIMESTAMP(4),
+ },
+ .default_config = AD7998_ALERT_EN,
+ .info = &ad7993_4_7_8_irq_info,
+ },
},
[ad7997] = {
- .channel = {
- AD799X_CHANNEL_WITH_EVENTS(0, 10),
- AD799X_CHANNEL_WITH_EVENTS(1, 10),
- AD799X_CHANNEL_WITH_EVENTS(2, 10),
- AD799X_CHANNEL_WITH_EVENTS(3, 10),
- AD799X_CHANNEL(4, 10),
- AD799X_CHANNEL(5, 10),
- AD799X_CHANNEL(6, 10),
- AD799X_CHANNEL(7, 10),
- IIO_CHAN_SOFT_TIMESTAMP(8),
- },
.num_channels = 9,
- .default_config = AD7998_ALERT_EN,
- .info = &ad7993_4_7_8_info,
+ .noirq_config = {
+ .channel = {
+ AD799X_CHANNEL(0, 10),
+ AD799X_CHANNEL(1, 10),
+ AD799X_CHANNEL(2, 10),
+ AD799X_CHANNEL(3, 10),
+ AD799X_CHANNEL(4, 10),
+ AD799X_CHANNEL(5, 10),
+ AD799X_CHANNEL(6, 10),
+ AD799X_CHANNEL(7, 10),
+ IIO_CHAN_SOFT_TIMESTAMP(8),
+ },
+ .info = &ad7993_4_7_8_noirq_info,
+ },
+ .irq_config = {
+ .channel = {
+ AD799X_CHANNEL_WITH_EVENTS(0, 10),
+ AD799X_CHANNEL_WITH_EVENTS(1, 10),
+ AD799X_CHANNEL_WITH_EVENTS(2, 10),
+ AD799X_CHANNEL_WITH_EVENTS(3, 10),
+ AD799X_CHANNEL(4, 10),
+ AD799X_CHANNEL(5, 10),
+ AD799X_CHANNEL(6, 10),
+ AD799X_CHANNEL(7, 10),
+ IIO_CHAN_SOFT_TIMESTAMP(8),
+ },
+ .default_config = AD7998_ALERT_EN,
+ .info = &ad7993_4_7_8_irq_info,
+ },
},
[ad7998] = {
- .channel = {
- AD799X_CHANNEL_WITH_EVENTS(0, 12),
- AD799X_CHANNEL_WITH_EVENTS(1, 12),
- AD799X_CHANNEL_WITH_EVENTS(2, 12),
- AD799X_CHANNEL_WITH_EVENTS(3, 12),
- AD799X_CHANNEL(4, 12),
- AD799X_CHANNEL(5, 12),
- AD799X_CHANNEL(6, 12),
- AD799X_CHANNEL(7, 12),
- IIO_CHAN_SOFT_TIMESTAMP(8),
- },
.num_channels = 9,
- .default_config = AD7998_ALERT_EN,
- .info = &ad7993_4_7_8_info,
+ .noirq_config = {
+ .channel = {
+ AD799X_CHANNEL(0, 12),
+ AD799X_CHANNEL(1, 12),
+ AD799X_CHANNEL(2, 12),
+ AD799X_CHANNEL(3, 12),
+ AD799X_CHANNEL(4, 12),
+ AD799X_CHANNEL(5, 12),
+ AD799X_CHANNEL(6, 12),
+ AD799X_CHANNEL(7, 12),
+ IIO_CHAN_SOFT_TIMESTAMP(8),
+ },
+ .info = &ad7993_4_7_8_noirq_info,
+ },
+ .irq_config = {
+ .channel = {
+ AD799X_CHANNEL_WITH_EVENTS(0, 12),
+ AD799X_CHANNEL_WITH_EVENTS(1, 12),
+ AD799X_CHANNEL_WITH_EVENTS(2, 12),
+ AD799X_CHANNEL_WITH_EVENTS(3, 12),
+ AD799X_CHANNEL(4, 12),
+ AD799X_CHANNEL(5, 12),
+ AD799X_CHANNEL(6, 12),
+ AD799X_CHANNEL(7, 12),
+ IIO_CHAN_SOFT_TIMESTAMP(8),
+ },
+ .default_config = AD7998_ALERT_EN,
+ .info = &ad7993_4_7_8_irq_info,
+ },
},
};
@@ -607,6 +695,8 @@ static int ad799x_probe(struct i2c_client *client,
int ret;
struct ad799x_state *st;
struct iio_dev *indio_dev;
+ const struct ad799x_chip_info *chip_info =
+ &ad799x_chip_info_tbl[id->driver_data];
indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*st));
if (indio_dev == NULL)
@@ -617,8 +707,11 @@ static int ad799x_probe(struct i2c_client *client,
i2c_set_clientdata(client, indio_dev);
st->id = id->driver_data;
- st->chip_info = &ad799x_chip_info_tbl[st->id];
- st->config = st->chip_info->default_config;
+ if (client->irq > 0 && chip_info->irq_config.info)
+ st->chip_config = &chip_info->irq_config;
+ else
+ st->chip_config = &chip_info->noirq_config;
+ st->config = st->chip_config->default_config;
/* TODO: Add pdata options for filtering and bit delay */
@@ -641,11 +734,11 @@ static int ad799x_probe(struct i2c_client *client,
indio_dev->dev.parent = &client->dev;
indio_dev->name = id->name;
- indio_dev->info = st->chip_info->info;
+ indio_dev->info = st->chip_config->info;
indio_dev->modes = INDIO_DIRECT_MODE;
- indio_dev->channels = st->chip_info->channel;
- indio_dev->num_channels = st->chip_info->num_channels;
+ indio_dev->channels = st->chip_config->channel;
+ indio_dev->num_channels = chip_info->num_channels;
ret = iio_triggered_buffer_setup(indio_dev, NULL,
&ad799x_trigger_handler, NULL);
--
1.9.1
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH v3 07/12] iio:adc:ad799x: Make chan_spec const in ad799x_chip_config struct
2014-06-12 4:54 [PATCH v3 00/12] ad799x cleanup Peter Meerwald
` (5 preceding siblings ...)
2014-06-12 4:54 ` [PATCH v3 06/12] iio:adc:ad799x: Only expose event interface when IRQ is available Peter Meerwald
@ 2014-06-12 4:54 ` Peter Meerwald
2014-07-13 20:57 ` Jonathan Cameron
2014-06-12 4:54 ` [PATCH v3 08/12] iio:adc:ad799x: Add helper function to read/write config register Peter Meerwald
` (4 subsequent siblings)
11 siblings, 1 reply; 31+ messages in thread
From: Peter Meerwald @ 2014-06-12 4:54 UTC (permalink / raw)
To: linux-iio; +Cc: jic23, Peter Meerwald
Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
Acked-by: Lars-Peter Clausen <lars@metafoo.de>
---
drivers/iio/adc/ad799x.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/iio/adc/ad799x.c b/drivers/iio/adc/ad799x.c
index b8a8117..92401c9 100644
--- a/drivers/iio/adc/ad799x.c
+++ b/drivers/iio/adc/ad799x.c
@@ -107,7 +107,7 @@ enum {
* @info: pointer to iio_info struct
*/
struct ad799x_chip_config {
- struct iio_chan_spec channel[9];
+ const struct iio_chan_spec channel[9];
u16 default_config;
const struct iio_info *info;
};
--
1.9.1
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH v3 08/12] iio:adc:ad799x: Add helper function to read/write config register
2014-06-12 4:54 [PATCH v3 00/12] ad799x cleanup Peter Meerwald
` (6 preceding siblings ...)
2014-06-12 4:54 ` [PATCH v3 07/12] iio:adc:ad799x: Make chan_spec const in ad799x_chip_config struct Peter Meerwald
@ 2014-06-12 4:54 ` Peter Meerwald
2014-07-13 20:57 ` Jonathan Cameron
2014-06-12 4:54 ` [PATCH v3 09/12] iio:adc:ad799x: Write default config on probe and reset alert status on probe Peter Meerwald
` (3 subsequent siblings)
11 siblings, 1 reply; 31+ messages in thread
From: Peter Meerwald @ 2014-06-12 4:54 UTC (permalink / raw)
To: linux-iio; +Cc: jic23, Peter Meerwald
16-bit on ad7997/ad7998, 8-bit elsewhere
Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
Acked-by: Lars-Peter Clausen <lars@metafoo.de>
---
drivers/iio/adc/ad799x.c | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/drivers/iio/adc/ad799x.c b/drivers/iio/adc/ad799x.c
index 92401c9..fe2a9b1 100644
--- a/drivers/iio/adc/ad799x.c
+++ b/drivers/iio/adc/ad799x.c
@@ -136,6 +136,30 @@ struct ad799x_state {
unsigned int transfer_size;
};
+static int ad799x_write_config(struct ad799x_state *st, u16 val)
+{
+ switch (st->id) {
+ case ad7997:
+ case ad7998:
+ return i2c_smbus_write_word_swapped(st->client, AD7998_CONF_REG,
+ val);
+ default:
+ return i2c_smbus_write_byte_data(st->client, AD7998_CONF_REG,
+ val);
+ }
+}
+
+static int ad799x_read_config(struct ad799x_state *st)
+{
+ switch (st->id) {
+ case ad7997:
+ case ad7998:
+ return i2c_smbus_read_word_swapped(st->client, AD7998_CONF_REG);
+ default:
+ return i2c_smbus_read_byte_data(st->client, AD7998_CONF_REG);
+ }
+}
+
/**
* ad799x_trigger_handler() bh of trigger launched polling to ring buffer
*
--
1.9.1
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH v3 09/12] iio:adc:ad799x: Write default config on probe and reset alert status on probe
2014-06-12 4:54 [PATCH v3 00/12] ad799x cleanup Peter Meerwald
` (7 preceding siblings ...)
2014-06-12 4:54 ` [PATCH v3 08/12] iio:adc:ad799x: Add helper function to read/write config register Peter Meerwald
@ 2014-06-12 4:54 ` Peter Meerwald
2014-07-13 20:58 ` Jonathan Cameron
2014-06-12 4:54 ` [PATCH v3 10/12] iio:adc:ad799x: Set conversion channels and rename ad7997_8_update_scan_mode() Peter Meerwald
` (2 subsequent siblings)
11 siblings, 1 reply; 31+ messages in thread
From: Peter Meerwald @ 2014-06-12 4:54 UTC (permalink / raw)
To: linux-iio; +Cc: jic23, Peter Meerwald
writing ALERT_EN and BUSY_ALERT to the chip config register clears
pending alerts, BUSY_ALERT is cleared when reading back the register
Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
Acked-by: Lars-Peter Clausen <lars@metafoo.de>
---
drivers/iio/adc/ad799x.c | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/drivers/iio/adc/ad799x.c b/drivers/iio/adc/ad799x.c
index fe2a9b1..84ce9b4 100644
--- a/drivers/iio/adc/ad799x.c
+++ b/drivers/iio/adc/ad799x.c
@@ -595,7 +595,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
AD799X_CHANNEL_WITH_EVENTS(1, 12),
IIO_CHAN_SOFT_TIMESTAMP(3),
},
- .default_config = AD7998_ALERT_EN,
+ .default_config = AD7998_ALERT_EN | AD7998_BUSY_ALERT,
.info = &ad7993_4_7_8_irq_info,
},
},
@@ -619,7 +619,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
AD799X_CHANNEL_WITH_EVENTS(3, 10),
IIO_CHAN_SOFT_TIMESTAMP(4),
},
- .default_config = AD7998_ALERT_EN,
+ .default_config = AD7998_ALERT_EN | AD7998_BUSY_ALERT,
.info = &ad7993_4_7_8_irq_info,
},
},
@@ -643,7 +643,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
AD799X_CHANNEL_WITH_EVENTS(3, 12),
IIO_CHAN_SOFT_TIMESTAMP(4),
},
- .default_config = AD7998_ALERT_EN,
+ .default_config = AD7998_ALERT_EN | AD7998_BUSY_ALERT,
.info = &ad7993_4_7_8_irq_info,
},
},
@@ -675,7 +675,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
AD799X_CHANNEL(7, 10),
IIO_CHAN_SOFT_TIMESTAMP(8),
},
- .default_config = AD7998_ALERT_EN,
+ .default_config = AD7998_ALERT_EN | AD7998_BUSY_ALERT,
.info = &ad7993_4_7_8_irq_info,
},
},
@@ -707,7 +707,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
AD799X_CHANNEL(7, 12),
IIO_CHAN_SOFT_TIMESTAMP(8),
},
- .default_config = AD7998_ALERT_EN,
+ .default_config = AD7998_ALERT_EN | AD7998_BUSY_ALERT,
.info = &ad7993_4_7_8_irq_info,
},
},
@@ -735,7 +735,6 @@ static int ad799x_probe(struct i2c_client *client,
st->chip_config = &chip_info->irq_config;
else
st->chip_config = &chip_info->noirq_config;
- st->config = st->chip_config->default_config;
/* TODO: Add pdata options for filtering and bit delay */
@@ -764,6 +763,14 @@ static int ad799x_probe(struct i2c_client *client,
indio_dev->channels = st->chip_config->channel;
indio_dev->num_channels = chip_info->num_channels;
+ ret = ad799x_write_config(st, st->chip_config->default_config);
+ if (ret < 0)
+ goto error_disable_reg;
+ ret = ad799x_read_config(st);
+ if (ret < 0)
+ goto error_disable_reg;
+ st->config = ret;
+
ret = iio_triggered_buffer_setup(indio_dev, NULL,
&ad799x_trigger_handler, NULL);
if (ret)
--
1.9.1
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH v3 10/12] iio:adc:ad799x: Set conversion channels and rename ad7997_8_update_scan_mode()
2014-06-12 4:54 [PATCH v3 00/12] ad799x cleanup Peter Meerwald
` (8 preceding siblings ...)
2014-06-12 4:54 ` [PATCH v3 09/12] iio:adc:ad799x: Write default config on probe and reset alert status on probe Peter Meerwald
@ 2014-06-12 4:54 ` Peter Meerwald
2014-07-13 20:58 ` Jonathan Cameron
2014-06-12 4:54 ` [PATCH v3 11/12] iio:adc:ad799x: Return more meaningful event enabled state Peter Meerwald
2014-06-12 4:54 ` [PATCH v3 12/12] iio:adc:ad799x: Allow to write event config Peter Meerwald
11 siblings, 1 reply; 31+ messages in thread
From: Peter Meerwald @ 2014-06-12 4:54 UTC (permalink / raw)
To: linux-iio; +Cc: jic23, Peter Meerwald
rename since function is used by all chips with ALERT pin, not just ad7997/8
Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
Acked-by: Lars-Peter Clausen <lars@metafoo.de>
---
drivers/iio/adc/ad799x.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/drivers/iio/adc/ad799x.c b/drivers/iio/adc/ad799x.c
index 84ce9b4..abc36c8 100644
--- a/drivers/iio/adc/ad799x.c
+++ b/drivers/iio/adc/ad799x.c
@@ -208,7 +208,7 @@ out:
return IRQ_HANDLED;
}
-static int ad7997_8_update_scan_mode(struct iio_dev *indio_dev,
+static int ad799x_update_scan_mode(struct iio_dev *indio_dev,
const unsigned long *scan_mask)
{
struct ad799x_state *st = iio_priv(indio_dev);
@@ -221,10 +221,14 @@ static int ad7997_8_update_scan_mode(struct iio_dev *indio_dev,
st->transfer_size = bitmap_weight(scan_mask, indio_dev->masklength) * 2;
switch (st->id) {
+ case ad7992:
+ case ad7993:
+ case ad7994:
case ad7997:
case ad7998:
- return i2c_smbus_write_word_swapped(st->client, AD7998_CONF_REG,
- st->config | (*scan_mask << AD799X_CHANNEL_SHIFT));
+ st->config &= ~(GENMASK(7, 0) << AD799X_CHANNEL_SHIFT);
+ st->config |= (*scan_mask << AD799X_CHANNEL_SHIFT);
+ return ad799x_write_config(st, st->config);
default:
return 0;
}
@@ -483,7 +487,7 @@ static const struct iio_info ad7991_info = {
static const struct iio_info ad7993_4_7_8_noirq_info = {
.read_raw = &ad799x_read_raw,
.driver_module = THIS_MODULE,
- .update_scan_mode = ad7997_8_update_scan_mode,
+ .update_scan_mode = ad799x_update_scan_mode,
};
static const struct iio_info ad7993_4_7_8_irq_info = {
@@ -493,7 +497,7 @@ static const struct iio_info ad7993_4_7_8_irq_info = {
.read_event_value = &ad799x_read_event_value,
.write_event_value = &ad799x_write_event_value,
.driver_module = THIS_MODULE,
- .update_scan_mode = ad7997_8_update_scan_mode,
+ .update_scan_mode = ad799x_update_scan_mode,
};
static const struct iio_event_spec ad799x_events[] = {
--
1.9.1
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH v3 11/12] iio:adc:ad799x: Return more meaningful event enabled state
2014-06-12 4:54 [PATCH v3 00/12] ad799x cleanup Peter Meerwald
` (9 preceding siblings ...)
2014-06-12 4:54 ` [PATCH v3 10/12] iio:adc:ad799x: Set conversion channels and rename ad7997_8_update_scan_mode() Peter Meerwald
@ 2014-06-12 4:54 ` Peter Meerwald
2014-06-12 8:08 ` Lars-Peter Clausen
2014-06-12 4:54 ` [PATCH v3 12/12] iio:adc:ad799x: Allow to write event config Peter Meerwald
11 siblings, 1 reply; 31+ messages in thread
From: Peter Meerwald @ 2014-06-12 4:54 UTC (permalink / raw)
To: linux-iio; +Cc: jic23, Peter Meerwald
only report an event as enabled if it actually is enabled
Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
---
drivers/iio/adc/ad799x.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/drivers/iio/adc/ad799x.c b/drivers/iio/adc/ad799x.c
index abc36c8..08bcada3 100644
--- a/drivers/iio/adc/ad799x.c
+++ b/drivers/iio/adc/ad799x.c
@@ -364,7 +364,15 @@ static int ad799x_read_event_config(struct iio_dev *indio_dev,
enum iio_event_type type,
enum iio_event_direction dir)
{
- return 1;
+ struct ad799x_state *st = iio_priv(indio_dev);
+
+ if (!(st->config & AD7998_ALERT_EN))
+ return 0;
+
+ if ((st->config >> AD799X_CHANNEL_SHIFT) & BIT(chan->scan_index))
+ return 1;
+
+ return 0;
}
static unsigned int ad799x_threshold_reg(const struct iio_chan_spec *chan,
--
1.9.1
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH v3 12/12] iio:adc:ad799x: Allow to write event config
2014-06-12 4:54 [PATCH v3 00/12] ad799x cleanup Peter Meerwald
` (10 preceding siblings ...)
2014-06-12 4:54 ` [PATCH v3 11/12] iio:adc:ad799x: Return more meaningful event enabled state Peter Meerwald
@ 2014-06-12 4:54 ` Peter Meerwald
2014-06-12 8:08 ` Lars-Peter Clausen
11 siblings, 1 reply; 31+ messages in thread
From: Peter Meerwald @ 2014-06-12 4:54 UTC (permalink / raw)
To: linux-iio; +Cc: jic23, Peter Meerwald
allow to enable events
previously, events were always reported as enabled, but actually only
implicitly enabled when updating the buffer scan mode
Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
---
drivers/iio/adc/ad799x.c | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
diff --git a/drivers/iio/adc/ad799x.c b/drivers/iio/adc/ad799x.c
index 08bcada3..e37412d 100644
--- a/drivers/iio/adc/ad799x.c
+++ b/drivers/iio/adc/ad799x.c
@@ -375,6 +375,39 @@ static int ad799x_read_event_config(struct iio_dev *indio_dev,
return 0;
}
+static int ad799x_write_event_config(struct iio_dev *indio_dev,
+ const struct iio_chan_spec *chan,
+ enum iio_event_type type,
+ enum iio_event_direction dir,
+ int state)
+{
+ struct ad799x_state *st = iio_priv(indio_dev);
+ int ret;
+
+ mutex_lock(&indio_dev->mlock);
+ if (iio_buffer_enabled(indio_dev)) {
+ ret = -EBUSY;
+ goto done;
+ }
+
+ if (state)
+ st->config |= BIT(chan->scan_index) << AD799X_CHANNEL_SHIFT;
+ else
+ st->config &= ~(BIT(chan->scan_index) << AD799X_CHANNEL_SHIFT);
+
+ if (st->config >> AD799X_CHANNEL_SHIFT)
+ st->config |= AD7998_ALERT_EN;
+ else
+ st->config &= ~AD7998_ALERT_EN;
+
+ ret = ad799x_write_config(st, st->config);
+
+done:
+ mutex_unlock(&indio_dev->mlock);
+
+ return ret;
+}
+
static unsigned int ad799x_threshold_reg(const struct iio_chan_spec *chan,
enum iio_event_direction dir,
enum iio_event_info info)
@@ -502,6 +535,7 @@ static const struct iio_info ad7993_4_7_8_irq_info = {
.read_raw = &ad799x_read_raw,
.event_attrs = &ad799x_event_attrs_group,
.read_event_config = &ad799x_read_event_config,
+ .write_event_config = &ad799x_write_event_config,
.read_event_value = &ad799x_read_event_value,
.write_event_value = &ad799x_write_event_value,
.driver_module = THIS_MODULE,
--
1.9.1
^ permalink raw reply related [flat|nested] 31+ messages in thread
* Re: [PATCH v3 01/12] iio:adc:ad799x: Fix reading and writing of event values, apply shift
2014-06-12 4:54 ` [PATCH v3 01/12] iio:adc:ad799x: Fix reading and writing of event values, apply shift Peter Meerwald
@ 2014-06-12 8:07 ` Lars-Peter Clausen
2014-06-14 14:19 ` Jonathan Cameron
0 siblings, 1 reply; 31+ messages in thread
From: Lars-Peter Clausen @ 2014-06-12 8:07 UTC (permalink / raw)
To: Peter Meerwald; +Cc: linux-iio, jic23
On 06/12/2014 06:54 AM, Peter Meerwald wrote:
> last two bits of ADC and limit values are zero and should not be reported
> (ad7993, ad7997); compare with read_raw()
>
> event values are 10 (ad7993, ad7997) or 12 bit max., check the range on write
>
> Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
Acked-by: Lars-Peter Clausen <lars@metafoo.de>
Thanks.
> ---
> drivers/iio/adc/ad799x.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/iio/adc/ad799x.c b/drivers/iio/adc/ad799x.c
> index 39b4cb4..6eba301 100644
> --- a/drivers/iio/adc/ad799x.c
> +++ b/drivers/iio/adc/ad799x.c
> @@ -427,9 +427,12 @@ static int ad799x_write_event_value(struct iio_dev *indio_dev,
> int ret;
> struct ad799x_state *st = iio_priv(indio_dev);
>
> + if (val < 0 || val > RES_MASK(chan->scan_type.realbits))
> + return -EINVAL;
> +
> mutex_lock(&indio_dev->mlock);
> ret = ad799x_i2c_write16(st, ad799x_threshold_reg(chan, dir, info),
> - val);
> + val << chan->scan_type.shift);
> mutex_unlock(&indio_dev->mlock);
>
> return ret;
> @@ -452,7 +455,8 @@ static int ad799x_read_event_value(struct iio_dev *indio_dev,
> mutex_unlock(&indio_dev->mlock);
> if (ret < 0)
> return ret;
> - *val = valin;
> + *val = (valin >> chan->scan_type.shift) &
> + RES_MASK(chan->scan_type.realbits);
>
> return IIO_VAL_INT;
> }
>
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH v3 11/12] iio:adc:ad799x: Return more meaningful event enabled state
2014-06-12 4:54 ` [PATCH v3 11/12] iio:adc:ad799x: Return more meaningful event enabled state Peter Meerwald
@ 2014-06-12 8:08 ` Lars-Peter Clausen
2014-07-13 20:59 ` Jonathan Cameron
0 siblings, 1 reply; 31+ messages in thread
From: Lars-Peter Clausen @ 2014-06-12 8:08 UTC (permalink / raw)
To: Peter Meerwald; +Cc: linux-iio, jic23
On 06/12/2014 06:54 AM, Peter Meerwald wrote:
> only report an event as enabled if it actually is enabled
>
> Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
Acked-by: Lars-Peter Clausen <lars@metafoo.de>
Thanks.
> ---
> drivers/iio/adc/ad799x.c | 10 +++++++++-
> 1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/iio/adc/ad799x.c b/drivers/iio/adc/ad799x.c
> index abc36c8..08bcada3 100644
> --- a/drivers/iio/adc/ad799x.c
> +++ b/drivers/iio/adc/ad799x.c
> @@ -364,7 +364,15 @@ static int ad799x_read_event_config(struct iio_dev *indio_dev,
> enum iio_event_type type,
> enum iio_event_direction dir)
> {
> - return 1;
> + struct ad799x_state *st = iio_priv(indio_dev);
> +
> + if (!(st->config & AD7998_ALERT_EN))
> + return 0;
> +
> + if ((st->config >> AD799X_CHANNEL_SHIFT) & BIT(chan->scan_index))
> + return 1;
> +
> + return 0;
> }
>
> static unsigned int ad799x_threshold_reg(const struct iio_chan_spec *chan,
>
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH v3 12/12] iio:adc:ad799x: Allow to write event config
2014-06-12 4:54 ` [PATCH v3 12/12] iio:adc:ad799x: Allow to write event config Peter Meerwald
@ 2014-06-12 8:08 ` Lars-Peter Clausen
2014-07-13 21:01 ` Jonathan Cameron
0 siblings, 1 reply; 31+ messages in thread
From: Lars-Peter Clausen @ 2014-06-12 8:08 UTC (permalink / raw)
To: Peter Meerwald; +Cc: linux-iio, jic23
On 06/12/2014 06:54 AM, Peter Meerwald wrote:
> allow to enable events
>
> previously, events were always reported as enabled, but actually only
> implicitly enabled when updating the buffer scan mode
>
> Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
It's not perfect, but is an improvement over the current situation so,
Acked-by: Lars-Peter Clausen <lars@metafoo.de>
Thanks.
> ---
> drivers/iio/adc/ad799x.c | 34 ++++++++++++++++++++++++++++++++++
> 1 file changed, 34 insertions(+)
>
> diff --git a/drivers/iio/adc/ad799x.c b/drivers/iio/adc/ad799x.c
> index 08bcada3..e37412d 100644
> --- a/drivers/iio/adc/ad799x.c
> +++ b/drivers/iio/adc/ad799x.c
> @@ -375,6 +375,39 @@ static int ad799x_read_event_config(struct iio_dev *indio_dev,
> return 0;
> }
>
> +static int ad799x_write_event_config(struct iio_dev *indio_dev,
> + const struct iio_chan_spec *chan,
> + enum iio_event_type type,
> + enum iio_event_direction dir,
> + int state)
> +{
> + struct ad799x_state *st = iio_priv(indio_dev);
> + int ret;
> +
> + mutex_lock(&indio_dev->mlock);
> + if (iio_buffer_enabled(indio_dev)) {
> + ret = -EBUSY;
> + goto done;
> + }
> +
> + if (state)
> + st->config |= BIT(chan->scan_index) << AD799X_CHANNEL_SHIFT;
> + else
> + st->config &= ~(BIT(chan->scan_index) << AD799X_CHANNEL_SHIFT);
> +
> + if (st->config >> AD799X_CHANNEL_SHIFT)
> + st->config |= AD7998_ALERT_EN;
> + else
> + st->config &= ~AD7998_ALERT_EN;
> +
> + ret = ad799x_write_config(st, st->config);
> +
> +done:
> + mutex_unlock(&indio_dev->mlock);
> +
> + return ret;
> +}
> +
> static unsigned int ad799x_threshold_reg(const struct iio_chan_spec *chan,
> enum iio_event_direction dir,
> enum iio_event_info info)
> @@ -502,6 +535,7 @@ static const struct iio_info ad7993_4_7_8_irq_info = {
> .read_raw = &ad799x_read_raw,
> .event_attrs = &ad799x_event_attrs_group,
> .read_event_config = &ad799x_read_event_config,
> + .write_event_config = &ad799x_write_event_config,
> .read_event_value = &ad799x_read_event_value,
> .write_event_value = &ad799x_write_event_value,
> .driver_module = THIS_MODULE,
>
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH v3 03/12] iio:adc:ad799x: Drop I2C access helper functions
2014-06-12 4:54 ` [PATCH v3 03/12] iio:adc:ad799x: Drop I2C access helper functions Peter Meerwald
@ 2014-06-12 8:10 ` Lars-Peter Clausen
2014-06-14 14:26 ` Jonathan Cameron
2014-07-13 20:47 ` Jonathan Cameron
0 siblings, 2 replies; 31+ messages in thread
From: Lars-Peter Clausen @ 2014-06-12 8:10 UTC (permalink / raw)
To: Peter Meerwald; +Cc: linux-iio, jic23
On 06/12/2014 06:54 AM, Peter Meerwald wrote:
> Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
Acked-by: Lars-Peter Clausen <lars@metafoo.de>
Thanks.
> ---
> drivers/iio/adc/ad799x.c | 119 +++++++++++------------------------------------
> 1 file changed, 26 insertions(+), 93 deletions(-)
>
> diff --git a/drivers/iio/adc/ad799x.c b/drivers/iio/adc/ad799x.c
> index 6cf9ee1..34d93a5 100644
> --- a/drivers/iio/adc/ad799x.c
> +++ b/drivers/iio/adc/ad799x.c
> @@ -175,65 +175,6 @@ out:
> return IRQ_HANDLED;
> }
>
> -/*
> - * ad799x register access by I2C
> - */
> -static int ad799x_i2c_read16(struct ad799x_state *st, u8 reg, u16 *data)
> -{
> - struct i2c_client *client = st->client;
> - int ret = 0;
> -
> - ret = i2c_smbus_read_word_swapped(client, reg);
> - if (ret < 0) {
> - dev_err(&client->dev, "I2C read error\n");
> - return ret;
> - }
> -
> - *data = (u16)ret;
> -
> - return 0;
> -}
> -
> -static int ad799x_i2c_read8(struct ad799x_state *st, u8 reg, u8 *data)
> -{
> - struct i2c_client *client = st->client;
> - int ret = 0;
> -
> - ret = i2c_smbus_read_byte_data(client, reg);
> - if (ret < 0) {
> - dev_err(&client->dev, "I2C read error\n");
> - return ret;
> - }
> -
> - *data = (u8)ret;
> -
> - return 0;
> -}
> -
> -static int ad799x_i2c_write16(struct ad799x_state *st, u8 reg, u16 data)
> -{
> - struct i2c_client *client = st->client;
> - int ret = 0;
> -
> - ret = i2c_smbus_write_word_swapped(client, reg, data);
> - if (ret < 0)
> - dev_err(&client->dev, "I2C write error\n");
> -
> - return ret;
> -}
> -
> -static int ad799x_i2c_write8(struct ad799x_state *st, u8 reg, u8 data)
> -{
> - struct i2c_client *client = st->client;
> - int ret = 0;
> -
> - ret = i2c_smbus_write_byte_data(client, reg, data);
> - if (ret < 0)
> - dev_err(&client->dev, "I2C write error\n");
> -
> - return ret;
> -}
> -
> static int ad7997_8_update_scan_mode(struct iio_dev *indio_dev,
> const unsigned long *scan_mask)
> {
> @@ -249,7 +190,7 @@ static int ad7997_8_update_scan_mode(struct iio_dev *indio_dev,
> switch (st->id) {
> case ad7997:
> case ad7998:
> - return ad799x_i2c_write16(st, AD7998_CONF_REG,
> + return i2c_smbus_write_word_swapped(st->client, AD7998_CONF_REG,
> st->config | (*scan_mask << AD799X_CHANNEL_SHIFT));
> default:
> break;
> @@ -260,9 +201,7 @@ static int ad7997_8_update_scan_mode(struct iio_dev *indio_dev,
>
> static int ad799x_scan_direct(struct ad799x_state *st, unsigned ch)
> {
> - u16 rxbuf;
> u8 cmd;
> - int ret;
>
> switch (st->id) {
> case ad7991:
> @@ -283,11 +222,7 @@ static int ad799x_scan_direct(struct ad799x_state *st, unsigned ch)
> return -EINVAL;
> }
>
> - ret = ad799x_i2c_read16(st, cmd, &rxbuf);
> - if (ret < 0)
> - return ret;
> -
> - return rxbuf;
> + return i2c_smbus_read_word_swapped(st->client, cmd);
> }
>
> static int ad799x_read_raw(struct iio_dev *indio_dev,
> @@ -332,6 +267,7 @@ static const unsigned int ad7998_frequencies[] = {
> [AD7998_CYC_TCONF_1024] = 488,
> [AD7998_CYC_TCONF_2048] = 244,
> };
> +
> static ssize_t ad799x_read_frequency(struct device *dev,
> struct device_attribute *attr,
> char *buf)
> @@ -339,15 +275,11 @@ static ssize_t ad799x_read_frequency(struct device *dev,
> struct iio_dev *indio_dev = dev_to_iio_dev(dev);
> struct ad799x_state *st = iio_priv(indio_dev);
>
> - int ret;
> - u8 val;
> - ret = ad799x_i2c_read8(st, AD7998_CYCLE_TMR_REG, &val);
> - if (ret)
> + int ret = i2c_smbus_read_byte_data(st->client, AD7998_CYCLE_TMR_REG);
> + if (ret < 0)
> return ret;
>
> - val &= AD7998_CYC_MASK;
> -
> - return sprintf(buf, "%u\n", ad7998_frequencies[val]);
> + return sprintf(buf, "%u\n", ad7998_frequencies[ret & AD7998_CYC_MASK]);
> }
>
> static ssize_t ad799x_write_frequency(struct device *dev,
> @@ -360,18 +292,17 @@ static ssize_t ad799x_write_frequency(struct device *dev,
>
> long val;
> int ret, i;
> - u8 t;
>
> ret = kstrtol(buf, 10, &val);
> if (ret)
> return ret;
>
> mutex_lock(&indio_dev->mlock);
> - ret = ad799x_i2c_read8(st, AD7998_CYCLE_TMR_REG, &t);
> - if (ret)
> + ret = i2c_smbus_read_byte_data(st->client, AD7998_CYCLE_TMR_REG);
> + if (ret < 0)
> goto error_ret_mutex;
> /* Wipe the bits clean */
> - t &= ~AD7998_CYC_MASK;
> + ret &= ~AD7998_CYC_MASK;
>
> for (i = 0; i < ARRAY_SIZE(ad7998_frequencies); i++)
> if (val == ad7998_frequencies[i])
> @@ -380,13 +311,17 @@ static ssize_t ad799x_write_frequency(struct device *dev,
> ret = -EINVAL;
> goto error_ret_mutex;
> }
> - t |= i;
> - ret = ad799x_i2c_write8(st, AD7998_CYCLE_TMR_REG, t);
> +
> + ret = i2c_smbus_write_byte_data(st->client, AD7998_CYCLE_TMR_REG,
> + ret | i);
> + if (ret < 0)
> + goto error_ret_mutex;
> + ret = len;
>
> error_ret_mutex:
> mutex_unlock(&indio_dev->mlock);
>
> - return ret ? ret : len;
> + return ret;
> }
>
> static int ad799x_read_event_config(struct iio_dev *indio_dev,
> @@ -430,7 +365,8 @@ static int ad799x_write_event_value(struct iio_dev *indio_dev,
> return -EINVAL;
>
> mutex_lock(&indio_dev->mlock);
> - ret = ad799x_i2c_write16(st, ad799x_threshold_reg(chan, dir, info),
> + ret = i2c_smbus_write_word_swapped(st->client,
> + ad799x_threshold_reg(chan, dir, info),
> val << chan->scan_type.shift);
> mutex_unlock(&indio_dev->mlock);
>
> @@ -446,15 +382,14 @@ static int ad799x_read_event_value(struct iio_dev *indio_dev,
> {
> int ret;
> struct ad799x_state *st = iio_priv(indio_dev);
> - u16 valin;
>
> mutex_lock(&indio_dev->mlock);
> - ret = ad799x_i2c_read16(st, ad799x_threshold_reg(chan, dir, info),
> - &valin);
> + ret = i2c_smbus_read_word_swapped(st->client,
> + ad799x_threshold_reg(chan, dir, info));
> mutex_unlock(&indio_dev->mlock);
> if (ret < 0)
> return ret;
> - *val = (valin >> chan->scan_type.shift) &
> + *val = (ret >> chan->scan_type.shift) &
> RES_MASK(chan->scan_type.realbits);
>
> return IIO_VAL_INT;
> @@ -464,20 +399,18 @@ static irqreturn_t ad799x_event_handler(int irq, void *private)
> {
> struct iio_dev *indio_dev = private;
> struct ad799x_state *st = iio_priv(private);
> - u8 status;
> int i, ret;
>
> - ret = ad799x_i2c_read8(st, AD7998_ALERT_STAT_REG, &status);
> - if (ret)
> + ret = i2c_smbus_read_byte_data(st->client, AD7998_ALERT_STAT_REG);
> + if (ret <= 0)
> goto done;
>
> - if (!status)
> + if (i2c_smbus_write_byte_data(st->client, AD7998_ALERT_STAT_REG,
> + AD7998_ALERT_STAT_CLEAR) < 0)
> goto done;
>
> - ad799x_i2c_write8(st, AD7998_ALERT_STAT_REG, AD7998_ALERT_STAT_CLEAR);
> -
> for (i = 0; i < 8; i++) {
> - if (status & (1 << i))
> + if (ret & (1 << i))
> iio_push_event(indio_dev,
> i & 0x1 ?
> IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE,
>
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH v3 01/12] iio:adc:ad799x: Fix reading and writing of event values, apply shift
2014-06-12 8:07 ` Lars-Peter Clausen
@ 2014-06-14 14:19 ` Jonathan Cameron
2014-06-29 14:47 ` Jonathan Cameron
0 siblings, 1 reply; 31+ messages in thread
From: Jonathan Cameron @ 2014-06-14 14:19 UTC (permalink / raw)
To: Lars-Peter Clausen, Peter Meerwald; +Cc: linux-iio
On 12/06/14 09:07, Lars-Peter Clausen wrote:
> On 06/12/2014 06:54 AM, Peter Meerwald wrote:
>> last two bits of ADC and limit values are zero and should not be reported
>> (ad7993, ad7997); compare with read_raw()
>>
>> event values are 10 (ad7993, ad7997) or 12 bit max., check the range on write
>>
>> Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
>
> Acked-by: Lars-Peter Clausen <lars@metafoo.de>
Given I've been rather slow on pull requests yet, fixes-togreg has this file
in the wrong place at the moment. Hence I've applied this to
fixes-togreg-post-3.16-rc1.
I'll unwind this over the next day or so.
>
> Thanks.
>
>> ---
>> drivers/iio/adc/ad799x.c | 8 ++++++--
>> 1 file changed, 6 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/iio/adc/ad799x.c b/drivers/iio/adc/ad799x.c
>> index 39b4cb4..6eba301 100644
>> --- a/drivers/iio/adc/ad799x.c
>> +++ b/drivers/iio/adc/ad799x.c
>> @@ -427,9 +427,12 @@ static int ad799x_write_event_value(struct iio_dev *indio_dev,
>> int ret;
>> struct ad799x_state *st = iio_priv(indio_dev);
>>
>> + if (val < 0 || val > RES_MASK(chan->scan_type.realbits))
>> + return -EINVAL;
>> +
>> mutex_lock(&indio_dev->mlock);
>> ret = ad799x_i2c_write16(st, ad799x_threshold_reg(chan, dir, info),
>> - val);
>> + val << chan->scan_type.shift);
>> mutex_unlock(&indio_dev->mlock);
>>
>> return ret;
>> @@ -452,7 +455,8 @@ static int ad799x_read_event_value(struct iio_dev *indio_dev,
>> mutex_unlock(&indio_dev->mlock);
>> if (ret < 0)
>> return ret;
>> - *val = valin;
>> + *val = (valin >> chan->scan_type.shift) &
>> + RES_MASK(chan->scan_type.realbits);
>>
>> return IIO_VAL_INT;
>> }
>>
>
> --
> 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] 31+ messages in thread
* Re: [PATCH v3 02/12] iio:adc:ad799x: Fix ad799x_chip_info kerneldoc
2014-06-12 4:54 ` [PATCH v3 02/12] iio:adc:ad799x: Fix ad799x_chip_info kerneldoc Peter Meerwald
@ 2014-06-14 14:21 ` Jonathan Cameron
0 siblings, 0 replies; 31+ messages in thread
From: Jonathan Cameron @ 2014-06-14 14:21 UTC (permalink / raw)
To: Peter Meerwald, linux-iio
On 12/06/14 05:54, Peter Meerwald wrote:
> Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
> Acked-by: Lars-Peter Clausen <lars@metafoo.de>
Applied to the togreg branch of iio.git
Thanks,
> ---
> drivers/iio/adc/ad799x.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/iio/adc/ad799x.c b/drivers/iio/adc/ad799x.c
> index 6eba301..6cf9ee1 100644
> --- a/drivers/iio/adc/ad799x.c
> +++ b/drivers/iio/adc/ad799x.c
> @@ -105,9 +105,8 @@ enum {
> * struct ad799x_chip_info - chip specific information
> * @channel: channel specification
> * @num_channels: number of channels
> - * @monitor_mode: whether the chip supports monitor interrupts
> * @default_config: device default configuration
> - * @event_attrs: pointer to the monitor event attribute group
> + * @info: pointer to iio_info struct
> */
> struct ad799x_chip_info {
> struct iio_chan_spec channel[9];
>
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH v3 03/12] iio:adc:ad799x: Drop I2C access helper functions
2014-06-12 8:10 ` Lars-Peter Clausen
@ 2014-06-14 14:26 ` Jonathan Cameron
2014-07-13 20:47 ` Jonathan Cameron
1 sibling, 0 replies; 31+ messages in thread
From: Jonathan Cameron @ 2014-06-14 14:26 UTC (permalink / raw)
To: Lars-Peter Clausen, Peter Meerwald; +Cc: linux-iio
On 12/06/14 09:10, Lars-Peter Clausen wrote:
> On 06/12/2014 06:54 AM, Peter Meerwald wrote:
>> Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
>
> Acked-by: Lars-Peter Clausen <lars@metafoo.de>
This interacts with the fix in patch 1 so I'll stall applying the series
here until that works its way in. Might be a week or so, but given where
we are in this cycle, there is no particular rush.
J
>
> Thanks.
>
>> ---
>> drivers/iio/adc/ad799x.c | 119 +++++++++++------------------------------------
>> 1 file changed, 26 insertions(+), 93 deletions(-)
>>
>> diff --git a/drivers/iio/adc/ad799x.c b/drivers/iio/adc/ad799x.c
>> index 6cf9ee1..34d93a5 100644
>> --- a/drivers/iio/adc/ad799x.c
>> +++ b/drivers/iio/adc/ad799x.c
>> @@ -175,65 +175,6 @@ out:
>> return IRQ_HANDLED;
>> }
>>
>> -/*
>> - * ad799x register access by I2C
>> - */
>> -static int ad799x_i2c_read16(struct ad799x_state *st, u8 reg, u16 *data)
>> -{
>> - struct i2c_client *client = st->client;
>> - int ret = 0;
>> -
>> - ret = i2c_smbus_read_word_swapped(client, reg);
>> - if (ret < 0) {
>> - dev_err(&client->dev, "I2C read error\n");
>> - return ret;
>> - }
>> -
>> - *data = (u16)ret;
>> -
>> - return 0;
>> -}
>> -
>> -static int ad799x_i2c_read8(struct ad799x_state *st, u8 reg, u8 *data)
>> -{
>> - struct i2c_client *client = st->client;
>> - int ret = 0;
>> -
>> - ret = i2c_smbus_read_byte_data(client, reg);
>> - if (ret < 0) {
>> - dev_err(&client->dev, "I2C read error\n");
>> - return ret;
>> - }
>> -
>> - *data = (u8)ret;
>> -
>> - return 0;
>> -}
>> -
>> -static int ad799x_i2c_write16(struct ad799x_state *st, u8 reg, u16 data)
>> -{
>> - struct i2c_client *client = st->client;
>> - int ret = 0;
>> -
>> - ret = i2c_smbus_write_word_swapped(client, reg, data);
>> - if (ret < 0)
>> - dev_err(&client->dev, "I2C write error\n");
>> -
>> - return ret;
>> -}
>> -
>> -static int ad799x_i2c_write8(struct ad799x_state *st, u8 reg, u8 data)
>> -{
>> - struct i2c_client *client = st->client;
>> - int ret = 0;
>> -
>> - ret = i2c_smbus_write_byte_data(client, reg, data);
>> - if (ret < 0)
>> - dev_err(&client->dev, "I2C write error\n");
>> -
>> - return ret;
>> -}
>> -
>> static int ad7997_8_update_scan_mode(struct iio_dev *indio_dev,
>> const unsigned long *scan_mask)
>> {
>> @@ -249,7 +190,7 @@ static int ad7997_8_update_scan_mode(struct iio_dev *indio_dev,
>> switch (st->id) {
>> case ad7997:
>> case ad7998:
>> - return ad799x_i2c_write16(st, AD7998_CONF_REG,
>> + return i2c_smbus_write_word_swapped(st->client, AD7998_CONF_REG,
>> st->config | (*scan_mask << AD799X_CHANNEL_SHIFT));
>> default:
>> break;
>> @@ -260,9 +201,7 @@ static int ad7997_8_update_scan_mode(struct iio_dev *indio_dev,
>>
>> static int ad799x_scan_direct(struct ad799x_state *st, unsigned ch)
>> {
>> - u16 rxbuf;
>> u8 cmd;
>> - int ret;
>>
>> switch (st->id) {
>> case ad7991:
>> @@ -283,11 +222,7 @@ static int ad799x_scan_direct(struct ad799x_state *st, unsigned ch)
>> return -EINVAL;
>> }
>>
>> - ret = ad799x_i2c_read16(st, cmd, &rxbuf);
>> - if (ret < 0)
>> - return ret;
>> -
>> - return rxbuf;
>> + return i2c_smbus_read_word_swapped(st->client, cmd);
>> }
>>
>> static int ad799x_read_raw(struct iio_dev *indio_dev,
>> @@ -332,6 +267,7 @@ static const unsigned int ad7998_frequencies[] = {
>> [AD7998_CYC_TCONF_1024] = 488,
>> [AD7998_CYC_TCONF_2048] = 244,
>> };
>> +
>> static ssize_t ad799x_read_frequency(struct device *dev,
>> struct device_attribute *attr,
>> char *buf)
>> @@ -339,15 +275,11 @@ static ssize_t ad799x_read_frequency(struct device *dev,
>> struct iio_dev *indio_dev = dev_to_iio_dev(dev);
>> struct ad799x_state *st = iio_priv(indio_dev);
>>
>> - int ret;
>> - u8 val;
>> - ret = ad799x_i2c_read8(st, AD7998_CYCLE_TMR_REG, &val);
>> - if (ret)
>> + int ret = i2c_smbus_read_byte_data(st->client, AD7998_CYCLE_TMR_REG);
>> + if (ret < 0)
>> return ret;
>>
>> - val &= AD7998_CYC_MASK;
>> -
>> - return sprintf(buf, "%u\n", ad7998_frequencies[val]);
>> + return sprintf(buf, "%u\n", ad7998_frequencies[ret & AD7998_CYC_MASK]);
>> }
>>
>> static ssize_t ad799x_write_frequency(struct device *dev,
>> @@ -360,18 +292,17 @@ static ssize_t ad799x_write_frequency(struct device *dev,
>>
>> long val;
>> int ret, i;
>> - u8 t;
>>
>> ret = kstrtol(buf, 10, &val);
>> if (ret)
>> return ret;
>>
>> mutex_lock(&indio_dev->mlock);
>> - ret = ad799x_i2c_read8(st, AD7998_CYCLE_TMR_REG, &t);
>> - if (ret)
>> + ret = i2c_smbus_read_byte_data(st->client, AD7998_CYCLE_TMR_REG);
>> + if (ret < 0)
>> goto error_ret_mutex;
>> /* Wipe the bits clean */
>> - t &= ~AD7998_CYC_MASK;
>> + ret &= ~AD7998_CYC_MASK;
>>
>> for (i = 0; i < ARRAY_SIZE(ad7998_frequencies); i++)
>> if (val == ad7998_frequencies[i])
>> @@ -380,13 +311,17 @@ static ssize_t ad799x_write_frequency(struct device *dev,
>> ret = -EINVAL;
>> goto error_ret_mutex;
>> }
>> - t |= i;
>> - ret = ad799x_i2c_write8(st, AD7998_CYCLE_TMR_REG, t);
>> +
>> + ret = i2c_smbus_write_byte_data(st->client, AD7998_CYCLE_TMR_REG,
>> + ret | i);
>> + if (ret < 0)
>> + goto error_ret_mutex;
>> + ret = len;
>>
>> error_ret_mutex:
>> mutex_unlock(&indio_dev->mlock);
>>
>> - return ret ? ret : len;
>> + return ret;
>> }
>>
>> static int ad799x_read_event_config(struct iio_dev *indio_dev,
>> @@ -430,7 +365,8 @@ static int ad799x_write_event_value(struct iio_dev *indio_dev,
>> return -EINVAL;
>>
>> mutex_lock(&indio_dev->mlock);
>> - ret = ad799x_i2c_write16(st, ad799x_threshold_reg(chan, dir, info),
>> + ret = i2c_smbus_write_word_swapped(st->client,
>> + ad799x_threshold_reg(chan, dir, info),
>> val << chan->scan_type.shift);
>> mutex_unlock(&indio_dev->mlock);
>>
>> @@ -446,15 +382,14 @@ static int ad799x_read_event_value(struct iio_dev *indio_dev,
>> {
>> int ret;
>> struct ad799x_state *st = iio_priv(indio_dev);
>> - u16 valin;
>>
>> mutex_lock(&indio_dev->mlock);
>> - ret = ad799x_i2c_read16(st, ad799x_threshold_reg(chan, dir, info),
>> - &valin);
>> + ret = i2c_smbus_read_word_swapped(st->client,
>> + ad799x_threshold_reg(chan, dir, info));
>> mutex_unlock(&indio_dev->mlock);
>> if (ret < 0)
>> return ret;
>> - *val = (valin >> chan->scan_type.shift) &
>> + *val = (ret >> chan->scan_type.shift) &
>> RES_MASK(chan->scan_type.realbits);
>>
>> return IIO_VAL_INT;
>> @@ -464,20 +399,18 @@ static irqreturn_t ad799x_event_handler(int irq, void *private)
>> {
>> struct iio_dev *indio_dev = private;
>> struct ad799x_state *st = iio_priv(private);
>> - u8 status;
>> int i, ret;
>>
>> - ret = ad799x_i2c_read8(st, AD7998_ALERT_STAT_REG, &status);
>> - if (ret)
>> + ret = i2c_smbus_read_byte_data(st->client, AD7998_ALERT_STAT_REG);
>> + if (ret <= 0)
>> goto done;
>>
>> - if (!status)
>> + if (i2c_smbus_write_byte_data(st->client, AD7998_ALERT_STAT_REG,
>> + AD7998_ALERT_STAT_CLEAR) < 0)
>> goto done;
>>
>> - ad799x_i2c_write8(st, AD7998_ALERT_STAT_REG, AD7998_ALERT_STAT_CLEAR);
>> -
>> for (i = 0; i < 8; i++) {
>> - if (status & (1 << i))
>> + if (ret & (1 << i))
>> iio_push_event(indio_dev,
>> i & 0x1 ?
>> IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE,
>>
>
> --
> 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] 31+ messages in thread
* Re: [PATCH v3 01/12] iio:adc:ad799x: Fix reading and writing of event values, apply shift
2014-06-14 14:19 ` Jonathan Cameron
@ 2014-06-29 14:47 ` Jonathan Cameron
0 siblings, 0 replies; 31+ messages in thread
From: Jonathan Cameron @ 2014-06-29 14:47 UTC (permalink / raw)
To: Lars-Peter Clausen, Peter Meerwald; +Cc: linux-iio
On 14/06/14 15:19, Jonathan Cameron wrote:
> On 12/06/14 09:07, Lars-Peter Clausen wrote:
>> On 06/12/2014 06:54 AM, Peter Meerwald wrote:
>>> last two bits of ADC and limit values are zero and should not be reported
>>> (ad7993, ad7997); compare with read_raw()
>>>
>>> event values are 10 (ad7993, ad7997) or 12 bit max., check the range on write
>>>
>>> Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
>>
>> Acked-by: Lars-Peter Clausen <lars@metafoo.de>
> Given I've been rather slow on pull requests yet, fixes-togreg has this file
> in the wrong place at the moment. Hence I've applied this to
> fixes-togreg-post-3.16-rc1.
>
> I'll unwind this over the next day or so.
Oops, took me rather longer that that - sorry.
Anyhow, just sent pull request that includes this first patch so we
are underway!
>>
>> Thanks.
>>
>>> ---
>>> drivers/iio/adc/ad799x.c | 8 ++++++--
>>> 1 file changed, 6 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/drivers/iio/adc/ad799x.c b/drivers/iio/adc/ad799x.c
>>> index 39b4cb4..6eba301 100644
>>> --- a/drivers/iio/adc/ad799x.c
>>> +++ b/drivers/iio/adc/ad799x.c
>>> @@ -427,9 +427,12 @@ static int ad799x_write_event_value(struct iio_dev *indio_dev,
>>> int ret;
>>> struct ad799x_state *st = iio_priv(indio_dev);
>>>
>>> + if (val < 0 || val > RES_MASK(chan->scan_type.realbits))
>>> + return -EINVAL;
>>> +
>>> mutex_lock(&indio_dev->mlock);
>>> ret = ad799x_i2c_write16(st, ad799x_threshold_reg(chan, dir, info),
>>> - val);
>>> + val << chan->scan_type.shift);
>>> mutex_unlock(&indio_dev->mlock);
>>>
>>> return ret;
>>> @@ -452,7 +455,8 @@ static int ad799x_read_event_value(struct iio_dev *indio_dev,
>>> mutex_unlock(&indio_dev->mlock);
>>> if (ret < 0)
>>> return ret;
>>> - *val = valin;
>>> + *val = (valin >> chan->scan_type.shift) &
>>> + RES_MASK(chan->scan_type.realbits);
>>>
>>> return IIO_VAL_INT;
>>> }
>>>
>>
>> --
>> 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
>
> --
> 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] 31+ messages in thread
* Re: [PATCH v3 03/12] iio:adc:ad799x: Drop I2C access helper functions
2014-06-12 8:10 ` Lars-Peter Clausen
2014-06-14 14:26 ` Jonathan Cameron
@ 2014-07-13 20:47 ` Jonathan Cameron
1 sibling, 0 replies; 31+ messages in thread
From: Jonathan Cameron @ 2014-07-13 20:47 UTC (permalink / raw)
To: Lars-Peter Clausen, Peter Meerwald; +Cc: linux-iio
On 12/06/14 09:10, Lars-Peter Clausen wrote:
> On 06/12/2014 06:54 AM, Peter Meerwald wrote:
>> Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
>
> Acked-by: Lars-Peter Clausen <lars@metafoo.de>
Applied to the togreg branch of iio.git.
The relevant precursors are now in that branch so can pick these up.
Thanks,
Jonathan
>
> Thanks.
>
>> ---
>> drivers/iio/adc/ad799x.c | 119 +++++++++++------------------------------------
>> 1 file changed, 26 insertions(+), 93 deletions(-)
>>
>> diff --git a/drivers/iio/adc/ad799x.c b/drivers/iio/adc/ad799x.c
>> index 6cf9ee1..34d93a5 100644
>> --- a/drivers/iio/adc/ad799x.c
>> +++ b/drivers/iio/adc/ad799x.c
>> @@ -175,65 +175,6 @@ out:
>> return IRQ_HANDLED;
>> }
>>
>> -/*
>> - * ad799x register access by I2C
>> - */
>> -static int ad799x_i2c_read16(struct ad799x_state *st, u8 reg, u16 *data)
>> -{
>> - struct i2c_client *client = st->client;
>> - int ret = 0;
>> -
>> - ret = i2c_smbus_read_word_swapped(client, reg);
>> - if (ret < 0) {
>> - dev_err(&client->dev, "I2C read error\n");
>> - return ret;
>> - }
>> -
>> - *data = (u16)ret;
>> -
>> - return 0;
>> -}
>> -
>> -static int ad799x_i2c_read8(struct ad799x_state *st, u8 reg, u8 *data)
>> -{
>> - struct i2c_client *client = st->client;
>> - int ret = 0;
>> -
>> - ret = i2c_smbus_read_byte_data(client, reg);
>> - if (ret < 0) {
>> - dev_err(&client->dev, "I2C read error\n");
>> - return ret;
>> - }
>> -
>> - *data = (u8)ret;
>> -
>> - return 0;
>> -}
>> -
>> -static int ad799x_i2c_write16(struct ad799x_state *st, u8 reg, u16 data)
>> -{
>> - struct i2c_client *client = st->client;
>> - int ret = 0;
>> -
>> - ret = i2c_smbus_write_word_swapped(client, reg, data);
>> - if (ret < 0)
>> - dev_err(&client->dev, "I2C write error\n");
>> -
>> - return ret;
>> -}
>> -
>> -static int ad799x_i2c_write8(struct ad799x_state *st, u8 reg, u8 data)
>> -{
>> - struct i2c_client *client = st->client;
>> - int ret = 0;
>> -
>> - ret = i2c_smbus_write_byte_data(client, reg, data);
>> - if (ret < 0)
>> - dev_err(&client->dev, "I2C write error\n");
>> -
>> - return ret;
>> -}
>> -
>> static int ad7997_8_update_scan_mode(struct iio_dev *indio_dev,
>> const unsigned long *scan_mask)
>> {
>> @@ -249,7 +190,7 @@ static int ad7997_8_update_scan_mode(struct iio_dev *indio_dev,
>> switch (st->id) {
>> case ad7997:
>> case ad7998:
>> - return ad799x_i2c_write16(st, AD7998_CONF_REG,
>> + return i2c_smbus_write_word_swapped(st->client, AD7998_CONF_REG,
>> st->config | (*scan_mask << AD799X_CHANNEL_SHIFT));
>> default:
>> break;
>> @@ -260,9 +201,7 @@ static int ad7997_8_update_scan_mode(struct iio_dev *indio_dev,
>>
>> static int ad799x_scan_direct(struct ad799x_state *st, unsigned ch)
>> {
>> - u16 rxbuf;
>> u8 cmd;
>> - int ret;
>>
>> switch (st->id) {
>> case ad7991:
>> @@ -283,11 +222,7 @@ static int ad799x_scan_direct(struct ad799x_state *st, unsigned ch)
>> return -EINVAL;
>> }
>>
>> - ret = ad799x_i2c_read16(st, cmd, &rxbuf);
>> - if (ret < 0)
>> - return ret;
>> -
>> - return rxbuf;
>> + return i2c_smbus_read_word_swapped(st->client, cmd);
>> }
>>
>> static int ad799x_read_raw(struct iio_dev *indio_dev,
>> @@ -332,6 +267,7 @@ static const unsigned int ad7998_frequencies[] = {
>> [AD7998_CYC_TCONF_1024] = 488,
>> [AD7998_CYC_TCONF_2048] = 244,
>> };
>> +
>> static ssize_t ad799x_read_frequency(struct device *dev,
>> struct device_attribute *attr,
>> char *buf)
>> @@ -339,15 +275,11 @@ static ssize_t ad799x_read_frequency(struct device *dev,
>> struct iio_dev *indio_dev = dev_to_iio_dev(dev);
>> struct ad799x_state *st = iio_priv(indio_dev);
>>
>> - int ret;
>> - u8 val;
>> - ret = ad799x_i2c_read8(st, AD7998_CYCLE_TMR_REG, &val);
>> - if (ret)
>> + int ret = i2c_smbus_read_byte_data(st->client, AD7998_CYCLE_TMR_REG);
>> + if (ret < 0)
>> return ret;
>>
>> - val &= AD7998_CYC_MASK;
>> -
>> - return sprintf(buf, "%u\n", ad7998_frequencies[val]);
>> + return sprintf(buf, "%u\n", ad7998_frequencies[ret & AD7998_CYC_MASK]);
>> }
>>
>> static ssize_t ad799x_write_frequency(struct device *dev,
>> @@ -360,18 +292,17 @@ static ssize_t ad799x_write_frequency(struct device *dev,
>>
>> long val;
>> int ret, i;
>> - u8 t;
>>
>> ret = kstrtol(buf, 10, &val);
>> if (ret)
>> return ret;
>>
>> mutex_lock(&indio_dev->mlock);
>> - ret = ad799x_i2c_read8(st, AD7998_CYCLE_TMR_REG, &t);
>> - if (ret)
>> + ret = i2c_smbus_read_byte_data(st->client, AD7998_CYCLE_TMR_REG);
>> + if (ret < 0)
>> goto error_ret_mutex;
>> /* Wipe the bits clean */
>> - t &= ~AD7998_CYC_MASK;
>> + ret &= ~AD7998_CYC_MASK;
>>
>> for (i = 0; i < ARRAY_SIZE(ad7998_frequencies); i++)
>> if (val == ad7998_frequencies[i])
>> @@ -380,13 +311,17 @@ static ssize_t ad799x_write_frequency(struct device *dev,
>> ret = -EINVAL;
>> goto error_ret_mutex;
>> }
>> - t |= i;
>> - ret = ad799x_i2c_write8(st, AD7998_CYCLE_TMR_REG, t);
>> +
>> + ret = i2c_smbus_write_byte_data(st->client, AD7998_CYCLE_TMR_REG,
>> + ret | i);
>> + if (ret < 0)
>> + goto error_ret_mutex;
>> + ret = len;
>>
>> error_ret_mutex:
>> mutex_unlock(&indio_dev->mlock);
>>
>> - return ret ? ret : len;
>> + return ret;
>> }
>>
>> static int ad799x_read_event_config(struct iio_dev *indio_dev,
>> @@ -430,7 +365,8 @@ static int ad799x_write_event_value(struct iio_dev *indio_dev,
>> return -EINVAL;
>>
>> mutex_lock(&indio_dev->mlock);
>> - ret = ad799x_i2c_write16(st, ad799x_threshold_reg(chan, dir, info),
>> + ret = i2c_smbus_write_word_swapped(st->client,
>> + ad799x_threshold_reg(chan, dir, info),
>> val << chan->scan_type.shift);
>> mutex_unlock(&indio_dev->mlock);
>>
>> @@ -446,15 +382,14 @@ static int ad799x_read_event_value(struct iio_dev *indio_dev,
>> {
>> int ret;
>> struct ad799x_state *st = iio_priv(indio_dev);
>> - u16 valin;
>>
>> mutex_lock(&indio_dev->mlock);
>> - ret = ad799x_i2c_read16(st, ad799x_threshold_reg(chan, dir, info),
>> - &valin);
>> + ret = i2c_smbus_read_word_swapped(st->client,
>> + ad799x_threshold_reg(chan, dir, info));
>> mutex_unlock(&indio_dev->mlock);
>> if (ret < 0)
>> return ret;
>> - *val = (valin >> chan->scan_type.shift) &
>> + *val = (ret >> chan->scan_type.shift) &
>> RES_MASK(chan->scan_type.realbits);
>>
>> return IIO_VAL_INT;
>> @@ -464,20 +399,18 @@ static irqreturn_t ad799x_event_handler(int irq, void *private)
>> {
>> struct iio_dev *indio_dev = private;
>> struct ad799x_state *st = iio_priv(private);
>> - u8 status;
>> int i, ret;
>>
>> - ret = ad799x_i2c_read8(st, AD7998_ALERT_STAT_REG, &status);
>> - if (ret)
>> + ret = i2c_smbus_read_byte_data(st->client, AD7998_ALERT_STAT_REG);
>> + if (ret <= 0)
>> goto done;
>>
>> - if (!status)
>> + if (i2c_smbus_write_byte_data(st->client, AD7998_ALERT_STAT_REG,
>> + AD7998_ALERT_STAT_CLEAR) < 0)
>> goto done;
>>
>> - ad799x_i2c_write8(st, AD7998_ALERT_STAT_REG, AD7998_ALERT_STAT_CLEAR);
>> -
>> for (i = 0; i < 8; i++) {
>> - if (status & (1 << i))
>> + if (ret & (1 << i))
>> iio_push_event(indio_dev,
>> i & 0x1 ?
>> IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE,
>>
>
> --
> 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] 31+ messages in thread
* Re: [PATCH v3 04/12] iio:adc:ad799x: Save some lines in ad7997_8_update_scan_mode() exit handling
2014-06-12 4:54 ` [PATCH v3 04/12] iio:adc:ad799x: Save some lines in ad7997_8_update_scan_mode() exit handling Peter Meerwald
@ 2014-07-13 20:56 ` Jonathan Cameron
0 siblings, 0 replies; 31+ messages in thread
From: Jonathan Cameron @ 2014-07-13 20:56 UTC (permalink / raw)
To: Peter Meerwald, linux-iio
On 12/06/14 05:54, Peter Meerwald wrote:
> Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
> Acked-by: Lars-Peter Clausen <lars@metafoo.de>
Applied
> ---
> drivers/iio/adc/ad799x.c | 4 +---
> 1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/drivers/iio/adc/ad799x.c b/drivers/iio/adc/ad799x.c
> index 34d93a5..878400c 100644
> --- a/drivers/iio/adc/ad799x.c
> +++ b/drivers/iio/adc/ad799x.c
> @@ -193,10 +193,8 @@ static int ad7997_8_update_scan_mode(struct iio_dev *indio_dev,
> return i2c_smbus_write_word_swapped(st->client, AD7998_CONF_REG,
> st->config | (*scan_mask << AD799X_CHANNEL_SHIFT));
> default:
> - break;
> + return 0;
> }
> -
> - return 0;
> }
>
> static int ad799x_scan_direct(struct ad799x_state *st, unsigned ch)
>
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH v3 05/12] iio:adc:ad799x: Use BIT() and GENMASK()
2014-06-12 4:54 ` [PATCH v3 05/12] iio:adc:ad799x: Use BIT() and GENMASK() Peter Meerwald
@ 2014-07-13 20:56 ` Jonathan Cameron
0 siblings, 0 replies; 31+ messages in thread
From: Jonathan Cameron @ 2014-07-13 20:56 UTC (permalink / raw)
To: Peter Meerwald, linux-iio
On 12/06/14 05:54, Peter Meerwald wrote:
> Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
> Acked-by: Lars-Peter Clausen <lars@metafoo.de>
Applied
> ---
> drivers/iio/adc/ad799x.c | 31 +++++++++++++++----------------
> 1 file changed, 15 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/iio/adc/ad799x.c b/drivers/iio/adc/ad799x.c
> index 878400c..b3799a8 100644
> --- a/drivers/iio/adc/ad799x.c
> +++ b/drivers/iio/adc/ad799x.c
> @@ -32,6 +32,7 @@
> #include <linux/types.h>
> #include <linux/err.h>
> #include <linux/module.h>
> +#include <linux/bitops.h>
>
> #include <linux/iio/iio.h>
> #include <linux/iio/sysfs.h>
> @@ -41,7 +42,7 @@
> #include <linux/iio/triggered_buffer.h>
>
> #define AD799X_CHANNEL_SHIFT 4
> -#define AD799X_STORAGEBITS 16
> +
> /*
> * AD7991, AD7995 and AD7999 defines
> */
> @@ -55,10 +56,10 @@
> * AD7992, AD7993, AD7994, AD7997 and AD7998 defines
> */
>
> -#define AD7998_FLTR 0x08
> -#define AD7998_ALERT_EN 0x04
> -#define AD7998_BUSY_ALERT 0x02
> -#define AD7998_BUSY_ALERT_POL 0x01
> +#define AD7998_FLTR BIT(3)
> +#define AD7998_ALERT_EN BIT(2)
> +#define AD7998_BUSY_ALERT BIT(1)
> +#define AD7998_BUSY_ALERT_POL BIT(0)
>
> #define AD7998_CONV_RES_REG 0x0
> #define AD7998_ALERT_STAT_REG 0x1
> @@ -69,7 +70,7 @@
> #define AD7998_DATAHIGH_REG(x) ((x) * 3 + 0x5)
> #define AD7998_HYST_REG(x) ((x) * 3 + 0x6)
>
> -#define AD7998_CYC_MASK 0x7
> +#define AD7998_CYC_MASK GENMASK(2, 0)
> #define AD7998_CYC_DIS 0x0
> #define AD7998_CYC_TCONF_32 0x1
> #define AD7998_CYC_TCONF_64 0x2
> @@ -85,10 +86,8 @@
> * AD7997 and AD7997 defines
> */
>
> -#define AD7997_8_READ_SINGLE 0x80
> -#define AD7997_8_READ_SEQUENCE 0x70
> -/* TODO: move this into a common header */
> -#define RES_MASK(bits) ((1 << (bits)) - 1)
> +#define AD7997_8_READ_SINGLE BIT(7)
> +#define AD7997_8_READ_SEQUENCE (BIT(6) | BIT(5) | BIT(4))
>
> enum {
> ad7991,
> @@ -205,12 +204,12 @@ static int ad799x_scan_direct(struct ad799x_state *st, unsigned ch)
> case ad7991:
> case ad7995:
> case ad7999:
> - cmd = st->config | ((1 << ch) << AD799X_CHANNEL_SHIFT);
> + cmd = st->config | (BIT(ch) << AD799X_CHANNEL_SHIFT);
> break;
> case ad7992:
> case ad7993:
> case ad7994:
> - cmd = (1 << ch) << AD799X_CHANNEL_SHIFT;
> + cmd = BIT(ch) << AD799X_CHANNEL_SHIFT;
> break;
> case ad7997:
> case ad7998:
> @@ -244,7 +243,7 @@ static int ad799x_read_raw(struct iio_dev *indio_dev,
> if (ret < 0)
> return ret;
> *val = (ret >> chan->scan_type.shift) &
> - RES_MASK(chan->scan_type.realbits);
> + GENMASK(chan->scan_type.realbits - 1, 0);
> return IIO_VAL_INT;
> case IIO_CHAN_INFO_SCALE:
> ret = regulator_get_voltage(st->vref);
> @@ -359,7 +358,7 @@ static int ad799x_write_event_value(struct iio_dev *indio_dev,
> int ret;
> struct ad799x_state *st = iio_priv(indio_dev);
>
> - if (val < 0 || val > RES_MASK(chan->scan_type.realbits))
> + if (val < 0 || val > GENMASK(chan->scan_type.realbits - 1, 0))
> return -EINVAL;
>
> mutex_lock(&indio_dev->mlock);
> @@ -388,7 +387,7 @@ static int ad799x_read_event_value(struct iio_dev *indio_dev,
> if (ret < 0)
> return ret;
> *val = (ret >> chan->scan_type.shift) &
> - RES_MASK(chan->scan_type.realbits);
> + GENMASK(chan->scan_type.realbits - 1 , 0);
>
> return IIO_VAL_INT;
> }
> @@ -408,7 +407,7 @@ static irqreturn_t ad799x_event_handler(int irq, void *private)
> goto done;
>
> for (i = 0; i < 8; i++) {
> - if (ret & (1 << i))
> + if (ret & BIT(i))
> iio_push_event(indio_dev,
> i & 0x1 ?
> IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE,
>
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH v3 06/12] iio:adc:ad799x: Only expose event interface when IRQ is available
2014-06-12 4:54 ` [PATCH v3 06/12] iio:adc:ad799x: Only expose event interface when IRQ is available Peter Meerwald
@ 2014-07-13 20:56 ` Jonathan Cameron
0 siblings, 0 replies; 31+ messages in thread
From: Jonathan Cameron @ 2014-07-13 20:56 UTC (permalink / raw)
To: Peter Meerwald, linux-iio
On 12/06/14 05:54, Peter Meerwald wrote:
> an IRQ is necessary to handle the ALERT condition; without
> IRQ, the IIO event interface serves no purpose
>
> Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
> Acked-by: Lars-Peter Clausen <lars@metafoo.de>
Applied.
> ---
> drivers/iio/adc/ad799x.c | 265 ++++++++++++++++++++++++++++++++---------------
> 1 file changed, 179 insertions(+), 86 deletions(-)
>
> diff --git a/drivers/iio/adc/ad799x.c b/drivers/iio/adc/ad799x.c
> index b3799a8..b8a8117 100644
> --- a/drivers/iio/adc/ad799x.c
> +++ b/drivers/iio/adc/ad799x.c
> @@ -101,22 +101,32 @@ enum {
> };
>
> /**
> - * struct ad799x_chip_info - chip specific information
> + * struct ad799x_chip_config - chip specific information
> * @channel: channel specification
> - * @num_channels: number of channels
> * @default_config: device default configuration
> * @info: pointer to iio_info struct
> */
> -struct ad799x_chip_info {
> +struct ad799x_chip_config {
> struct iio_chan_spec channel[9];
> - int num_channels;
> u16 default_config;
> const struct iio_info *info;
> };
>
> +/**
> + * struct ad799x_chip_info - chip specific information
> + * @num_channels: number of channels
> + * @noirq_config: device configuration w/o IRQ
> + * @irq_config: device configuration w/IRQ
> + */
> +struct ad799x_chip_info {
> + int num_channels;
> + const struct ad799x_chip_config noirq_config;
> + const struct ad799x_chip_config irq_config;
> +};
> +
> struct ad799x_state {
> struct i2c_client *client;
> - const struct ad799x_chip_info *chip_info;
> + const struct ad799x_chip_config *chip_config;
> struct regulator *reg;
> struct regulator *vref;
> unsigned id;
> @@ -446,7 +456,13 @@ static const struct iio_info ad7991_info = {
> .driver_module = THIS_MODULE,
> };
>
> -static const struct iio_info ad7993_4_7_8_info = {
> +static const struct iio_info ad7993_4_7_8_noirq_info = {
> + .read_raw = &ad799x_read_raw,
> + .driver_module = THIS_MODULE,
> + .update_scan_mode = ad7997_8_update_scan_mode,
> +};
> +
> +static const struct iio_info ad7993_4_7_8_irq_info = {
> .read_raw = &ad799x_read_raw,
> .event_attrs = &ad799x_event_attrs_group,
> .read_event_config = &ad799x_read_event_config,
> @@ -501,103 +517,175 @@ static const struct iio_event_spec ad799x_events[] = {
>
> static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
> [ad7991] = {
> - .channel = {
> - AD799X_CHANNEL(0, 12),
> - AD799X_CHANNEL(1, 12),
> - AD799X_CHANNEL(2, 12),
> - AD799X_CHANNEL(3, 12),
> - IIO_CHAN_SOFT_TIMESTAMP(4),
> - },
> .num_channels = 5,
> - .info = &ad7991_info,
> + .noirq_config = {
> + .channel = {
> + AD799X_CHANNEL(0, 12),
> + AD799X_CHANNEL(1, 12),
> + AD799X_CHANNEL(2, 12),
> + AD799X_CHANNEL(3, 12),
> + IIO_CHAN_SOFT_TIMESTAMP(4),
> + },
> + .info = &ad7991_info,
> + },
> },
> [ad7995] = {
> - .channel = {
> - AD799X_CHANNEL(0, 10),
> - AD799X_CHANNEL(1, 10),
> - AD799X_CHANNEL(2, 10),
> - AD799X_CHANNEL(3, 10),
> - IIO_CHAN_SOFT_TIMESTAMP(4),
> - },
> .num_channels = 5,
> - .info = &ad7991_info,
> + .noirq_config = {
> + .channel = {
> + AD799X_CHANNEL(0, 10),
> + AD799X_CHANNEL(1, 10),
> + AD799X_CHANNEL(2, 10),
> + AD799X_CHANNEL(3, 10),
> + IIO_CHAN_SOFT_TIMESTAMP(4),
> + },
> + .info = &ad7991_info,
> + },
> },
> [ad7999] = {
> - .channel = {
> - AD799X_CHANNEL(0, 8),
> - AD799X_CHANNEL(1, 8),
> - AD799X_CHANNEL(2, 8),
> - AD799X_CHANNEL(3, 8),
> - IIO_CHAN_SOFT_TIMESTAMP(4),
> - },
> .num_channels = 5,
> - .info = &ad7991_info,
> + .noirq_config = {
> + .channel = {
> + AD799X_CHANNEL(0, 8),
> + AD799X_CHANNEL(1, 8),
> + AD799X_CHANNEL(2, 8),
> + AD799X_CHANNEL(3, 8),
> + IIO_CHAN_SOFT_TIMESTAMP(4),
> + },
> + .info = &ad7991_info,
> + },
> },
> [ad7992] = {
> - .channel = {
> - AD799X_CHANNEL_WITH_EVENTS(0, 12),
> - AD799X_CHANNEL_WITH_EVENTS(1, 12),
> - IIO_CHAN_SOFT_TIMESTAMP(3),
> - },
> .num_channels = 3,
> - .default_config = AD7998_ALERT_EN,
> - .info = &ad7993_4_7_8_info,
> + .noirq_config = {
> + .channel = {
> + AD799X_CHANNEL(0, 12),
> + AD799X_CHANNEL(1, 12),
> + IIO_CHAN_SOFT_TIMESTAMP(3),
> + },
> + .info = &ad7993_4_7_8_noirq_info,
> + },
> + .irq_config = {
> + .channel = {
> + AD799X_CHANNEL_WITH_EVENTS(0, 12),
> + AD799X_CHANNEL_WITH_EVENTS(1, 12),
> + IIO_CHAN_SOFT_TIMESTAMP(3),
> + },
> + .default_config = AD7998_ALERT_EN,
> + .info = &ad7993_4_7_8_irq_info,
> + },
> },
> [ad7993] = {
> - .channel = {
> - AD799X_CHANNEL_WITH_EVENTS(0, 10),
> - AD799X_CHANNEL_WITH_EVENTS(1, 10),
> - AD799X_CHANNEL_WITH_EVENTS(2, 10),
> - AD799X_CHANNEL_WITH_EVENTS(3, 10),
> - IIO_CHAN_SOFT_TIMESTAMP(4),
> - },
> .num_channels = 5,
> - .default_config = AD7998_ALERT_EN,
> - .info = &ad7993_4_7_8_info,
> + .noirq_config = {
> + .channel = {
> + AD799X_CHANNEL(0, 10),
> + AD799X_CHANNEL(1, 10),
> + AD799X_CHANNEL(2, 10),
> + AD799X_CHANNEL(3, 10),
> + IIO_CHAN_SOFT_TIMESTAMP(4),
> + },
> + .info = &ad7993_4_7_8_noirq_info,
> + },
> + .irq_config = {
> + .channel = {
> + AD799X_CHANNEL_WITH_EVENTS(0, 10),
> + AD799X_CHANNEL_WITH_EVENTS(1, 10),
> + AD799X_CHANNEL_WITH_EVENTS(2, 10),
> + AD799X_CHANNEL_WITH_EVENTS(3, 10),
> + IIO_CHAN_SOFT_TIMESTAMP(4),
> + },
> + .default_config = AD7998_ALERT_EN,
> + .info = &ad7993_4_7_8_irq_info,
> + },
> },
> [ad7994] = {
> - .channel = {
> - AD799X_CHANNEL_WITH_EVENTS(0, 12),
> - AD799X_CHANNEL_WITH_EVENTS(1, 12),
> - AD799X_CHANNEL_WITH_EVENTS(2, 12),
> - AD799X_CHANNEL_WITH_EVENTS(3, 12),
> - IIO_CHAN_SOFT_TIMESTAMP(4),
> - },
> .num_channels = 5,
> - .default_config = AD7998_ALERT_EN,
> - .info = &ad7993_4_7_8_info,
> + .noirq_config = {
> + .channel = {
> + AD799X_CHANNEL(0, 12),
> + AD799X_CHANNEL(1, 12),
> + AD799X_CHANNEL(2, 12),
> + AD799X_CHANNEL(3, 12),
> + IIO_CHAN_SOFT_TIMESTAMP(4),
> + },
> + .info = &ad7993_4_7_8_noirq_info,
> + },
> + .irq_config = {
> + .channel = {
> + AD799X_CHANNEL_WITH_EVENTS(0, 12),
> + AD799X_CHANNEL_WITH_EVENTS(1, 12),
> + AD799X_CHANNEL_WITH_EVENTS(2, 12),
> + AD799X_CHANNEL_WITH_EVENTS(3, 12),
> + IIO_CHAN_SOFT_TIMESTAMP(4),
> + },
> + .default_config = AD7998_ALERT_EN,
> + .info = &ad7993_4_7_8_irq_info,
> + },
> },
> [ad7997] = {
> - .channel = {
> - AD799X_CHANNEL_WITH_EVENTS(0, 10),
> - AD799X_CHANNEL_WITH_EVENTS(1, 10),
> - AD799X_CHANNEL_WITH_EVENTS(2, 10),
> - AD799X_CHANNEL_WITH_EVENTS(3, 10),
> - AD799X_CHANNEL(4, 10),
> - AD799X_CHANNEL(5, 10),
> - AD799X_CHANNEL(6, 10),
> - AD799X_CHANNEL(7, 10),
> - IIO_CHAN_SOFT_TIMESTAMP(8),
> - },
> .num_channels = 9,
> - .default_config = AD7998_ALERT_EN,
> - .info = &ad7993_4_7_8_info,
> + .noirq_config = {
> + .channel = {
> + AD799X_CHANNEL(0, 10),
> + AD799X_CHANNEL(1, 10),
> + AD799X_CHANNEL(2, 10),
> + AD799X_CHANNEL(3, 10),
> + AD799X_CHANNEL(4, 10),
> + AD799X_CHANNEL(5, 10),
> + AD799X_CHANNEL(6, 10),
> + AD799X_CHANNEL(7, 10),
> + IIO_CHAN_SOFT_TIMESTAMP(8),
> + },
> + .info = &ad7993_4_7_8_noirq_info,
> + },
> + .irq_config = {
> + .channel = {
> + AD799X_CHANNEL_WITH_EVENTS(0, 10),
> + AD799X_CHANNEL_WITH_EVENTS(1, 10),
> + AD799X_CHANNEL_WITH_EVENTS(2, 10),
> + AD799X_CHANNEL_WITH_EVENTS(3, 10),
> + AD799X_CHANNEL(4, 10),
> + AD799X_CHANNEL(5, 10),
> + AD799X_CHANNEL(6, 10),
> + AD799X_CHANNEL(7, 10),
> + IIO_CHAN_SOFT_TIMESTAMP(8),
> + },
> + .default_config = AD7998_ALERT_EN,
> + .info = &ad7993_4_7_8_irq_info,
> + },
> },
> [ad7998] = {
> - .channel = {
> - AD799X_CHANNEL_WITH_EVENTS(0, 12),
> - AD799X_CHANNEL_WITH_EVENTS(1, 12),
> - AD799X_CHANNEL_WITH_EVENTS(2, 12),
> - AD799X_CHANNEL_WITH_EVENTS(3, 12),
> - AD799X_CHANNEL(4, 12),
> - AD799X_CHANNEL(5, 12),
> - AD799X_CHANNEL(6, 12),
> - AD799X_CHANNEL(7, 12),
> - IIO_CHAN_SOFT_TIMESTAMP(8),
> - },
> .num_channels = 9,
> - .default_config = AD7998_ALERT_EN,
> - .info = &ad7993_4_7_8_info,
> + .noirq_config = {
> + .channel = {
> + AD799X_CHANNEL(0, 12),
> + AD799X_CHANNEL(1, 12),
> + AD799X_CHANNEL(2, 12),
> + AD799X_CHANNEL(3, 12),
> + AD799X_CHANNEL(4, 12),
> + AD799X_CHANNEL(5, 12),
> + AD799X_CHANNEL(6, 12),
> + AD799X_CHANNEL(7, 12),
> + IIO_CHAN_SOFT_TIMESTAMP(8),
> + },
> + .info = &ad7993_4_7_8_noirq_info,
> + },
> + .irq_config = {
> + .channel = {
> + AD799X_CHANNEL_WITH_EVENTS(0, 12),
> + AD799X_CHANNEL_WITH_EVENTS(1, 12),
> + AD799X_CHANNEL_WITH_EVENTS(2, 12),
> + AD799X_CHANNEL_WITH_EVENTS(3, 12),
> + AD799X_CHANNEL(4, 12),
> + AD799X_CHANNEL(5, 12),
> + AD799X_CHANNEL(6, 12),
> + AD799X_CHANNEL(7, 12),
> + IIO_CHAN_SOFT_TIMESTAMP(8),
> + },
> + .default_config = AD7998_ALERT_EN,
> + .info = &ad7993_4_7_8_irq_info,
> + },
> },
> };
>
> @@ -607,6 +695,8 @@ static int ad799x_probe(struct i2c_client *client,
> int ret;
> struct ad799x_state *st;
> struct iio_dev *indio_dev;
> + const struct ad799x_chip_info *chip_info =
> + &ad799x_chip_info_tbl[id->driver_data];
>
> indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*st));
> if (indio_dev == NULL)
> @@ -617,8 +707,11 @@ static int ad799x_probe(struct i2c_client *client,
> i2c_set_clientdata(client, indio_dev);
>
> st->id = id->driver_data;
> - st->chip_info = &ad799x_chip_info_tbl[st->id];
> - st->config = st->chip_info->default_config;
> + if (client->irq > 0 && chip_info->irq_config.info)
> + st->chip_config = &chip_info->irq_config;
> + else
> + st->chip_config = &chip_info->noirq_config;
> + st->config = st->chip_config->default_config;
>
> /* TODO: Add pdata options for filtering and bit delay */
>
> @@ -641,11 +734,11 @@ static int ad799x_probe(struct i2c_client *client,
>
> indio_dev->dev.parent = &client->dev;
> indio_dev->name = id->name;
> - indio_dev->info = st->chip_info->info;
> + indio_dev->info = st->chip_config->info;
>
> indio_dev->modes = INDIO_DIRECT_MODE;
> - indio_dev->channels = st->chip_info->channel;
> - indio_dev->num_channels = st->chip_info->num_channels;
> + indio_dev->channels = st->chip_config->channel;
> + indio_dev->num_channels = chip_info->num_channels;
>
> ret = iio_triggered_buffer_setup(indio_dev, NULL,
> &ad799x_trigger_handler, NULL);
>
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH v3 07/12] iio:adc:ad799x: Make chan_spec const in ad799x_chip_config struct
2014-06-12 4:54 ` [PATCH v3 07/12] iio:adc:ad799x: Make chan_spec const in ad799x_chip_config struct Peter Meerwald
@ 2014-07-13 20:57 ` Jonathan Cameron
0 siblings, 0 replies; 31+ messages in thread
From: Jonathan Cameron @ 2014-07-13 20:57 UTC (permalink / raw)
To: Peter Meerwald, linux-iio
On 12/06/14 05:54, Peter Meerwald wrote:
> Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
> Acked-by: Lars-Peter Clausen <lars@metafoo.de>
applied
> ---
> drivers/iio/adc/ad799x.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/iio/adc/ad799x.c b/drivers/iio/adc/ad799x.c
> index b8a8117..92401c9 100644
> --- a/drivers/iio/adc/ad799x.c
> +++ b/drivers/iio/adc/ad799x.c
> @@ -107,7 +107,7 @@ enum {
> * @info: pointer to iio_info struct
> */
> struct ad799x_chip_config {
> - struct iio_chan_spec channel[9];
> + const struct iio_chan_spec channel[9];
> u16 default_config;
> const struct iio_info *info;
> };
>
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH v3 08/12] iio:adc:ad799x: Add helper function to read/write config register
2014-06-12 4:54 ` [PATCH v3 08/12] iio:adc:ad799x: Add helper function to read/write config register Peter Meerwald
@ 2014-07-13 20:57 ` Jonathan Cameron
0 siblings, 0 replies; 31+ messages in thread
From: Jonathan Cameron @ 2014-07-13 20:57 UTC (permalink / raw)
To: Peter Meerwald, linux-iio
On 12/06/14 05:54, Peter Meerwald wrote:
> 16-bit on ad7997/ad7998, 8-bit elsewhere
>
> Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
> Acked-by: Lars-Peter Clausen <lars@metafoo.de>
Applied.
> ---
> drivers/iio/adc/ad799x.c | 24 ++++++++++++++++++++++++
> 1 file changed, 24 insertions(+)
>
> diff --git a/drivers/iio/adc/ad799x.c b/drivers/iio/adc/ad799x.c
> index 92401c9..fe2a9b1 100644
> --- a/drivers/iio/adc/ad799x.c
> +++ b/drivers/iio/adc/ad799x.c
> @@ -136,6 +136,30 @@ struct ad799x_state {
> unsigned int transfer_size;
> };
>
> +static int ad799x_write_config(struct ad799x_state *st, u16 val)
> +{
> + switch (st->id) {
> + case ad7997:
> + case ad7998:
> + return i2c_smbus_write_word_swapped(st->client, AD7998_CONF_REG,
> + val);
> + default:
> + return i2c_smbus_write_byte_data(st->client, AD7998_CONF_REG,
> + val);
> + }
> +}
> +
> +static int ad799x_read_config(struct ad799x_state *st)
> +{
> + switch (st->id) {
> + case ad7997:
> + case ad7998:
> + return i2c_smbus_read_word_swapped(st->client, AD7998_CONF_REG);
> + default:
> + return i2c_smbus_read_byte_data(st->client, AD7998_CONF_REG);
> + }
> +}
> +
> /**
> * ad799x_trigger_handler() bh of trigger launched polling to ring buffer
> *
>
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH v3 09/12] iio:adc:ad799x: Write default config on probe and reset alert status on probe
2014-06-12 4:54 ` [PATCH v3 09/12] iio:adc:ad799x: Write default config on probe and reset alert status on probe Peter Meerwald
@ 2014-07-13 20:58 ` Jonathan Cameron
0 siblings, 0 replies; 31+ messages in thread
From: Jonathan Cameron @ 2014-07-13 20:58 UTC (permalink / raw)
To: Peter Meerwald, linux-iio
On 12/06/14 05:54, Peter Meerwald wrote:
> writing ALERT_EN and BUSY_ALERT to the chip config register clears
> pending alerts, BUSY_ALERT is cleared when reading back the register
>
> Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
> Acked-by: Lars-Peter Clausen <lars@metafoo.de>
Applied.
> ---
> drivers/iio/adc/ad799x.c | 19 +++++++++++++------
> 1 file changed, 13 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/iio/adc/ad799x.c b/drivers/iio/adc/ad799x.c
> index fe2a9b1..84ce9b4 100644
> --- a/drivers/iio/adc/ad799x.c
> +++ b/drivers/iio/adc/ad799x.c
> @@ -595,7 +595,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
> AD799X_CHANNEL_WITH_EVENTS(1, 12),
> IIO_CHAN_SOFT_TIMESTAMP(3),
> },
> - .default_config = AD7998_ALERT_EN,
> + .default_config = AD7998_ALERT_EN | AD7998_BUSY_ALERT,
> .info = &ad7993_4_7_8_irq_info,
> },
> },
> @@ -619,7 +619,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
> AD799X_CHANNEL_WITH_EVENTS(3, 10),
> IIO_CHAN_SOFT_TIMESTAMP(4),
> },
> - .default_config = AD7998_ALERT_EN,
> + .default_config = AD7998_ALERT_EN | AD7998_BUSY_ALERT,
> .info = &ad7993_4_7_8_irq_info,
> },
> },
> @@ -643,7 +643,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
> AD799X_CHANNEL_WITH_EVENTS(3, 12),
> IIO_CHAN_SOFT_TIMESTAMP(4),
> },
> - .default_config = AD7998_ALERT_EN,
> + .default_config = AD7998_ALERT_EN | AD7998_BUSY_ALERT,
> .info = &ad7993_4_7_8_irq_info,
> },
> },
> @@ -675,7 +675,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
> AD799X_CHANNEL(7, 10),
> IIO_CHAN_SOFT_TIMESTAMP(8),
> },
> - .default_config = AD7998_ALERT_EN,
> + .default_config = AD7998_ALERT_EN | AD7998_BUSY_ALERT,
> .info = &ad7993_4_7_8_irq_info,
> },
> },
> @@ -707,7 +707,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
> AD799X_CHANNEL(7, 12),
> IIO_CHAN_SOFT_TIMESTAMP(8),
> },
> - .default_config = AD7998_ALERT_EN,
> + .default_config = AD7998_ALERT_EN | AD7998_BUSY_ALERT,
> .info = &ad7993_4_7_8_irq_info,
> },
> },
> @@ -735,7 +735,6 @@ static int ad799x_probe(struct i2c_client *client,
> st->chip_config = &chip_info->irq_config;
> else
> st->chip_config = &chip_info->noirq_config;
> - st->config = st->chip_config->default_config;
>
> /* TODO: Add pdata options for filtering and bit delay */
>
> @@ -764,6 +763,14 @@ static int ad799x_probe(struct i2c_client *client,
> indio_dev->channels = st->chip_config->channel;
> indio_dev->num_channels = chip_info->num_channels;
>
> + ret = ad799x_write_config(st, st->chip_config->default_config);
> + if (ret < 0)
> + goto error_disable_reg;
> + ret = ad799x_read_config(st);
> + if (ret < 0)
> + goto error_disable_reg;
> + st->config = ret;
> +
> ret = iio_triggered_buffer_setup(indio_dev, NULL,
> &ad799x_trigger_handler, NULL);
> if (ret)
>
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH v3 10/12] iio:adc:ad799x: Set conversion channels and rename ad7997_8_update_scan_mode()
2014-06-12 4:54 ` [PATCH v3 10/12] iio:adc:ad799x: Set conversion channels and rename ad7997_8_update_scan_mode() Peter Meerwald
@ 2014-07-13 20:58 ` Jonathan Cameron
0 siblings, 0 replies; 31+ messages in thread
From: Jonathan Cameron @ 2014-07-13 20:58 UTC (permalink / raw)
To: Peter Meerwald, linux-iio
On 12/06/14 05:54, Peter Meerwald wrote:
> rename since function is used by all chips with ALERT pin, not just ad7997/8
>
> Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
> Acked-by: Lars-Peter Clausen <lars@metafoo.de>
Applied.
> ---
> drivers/iio/adc/ad799x.c | 14 +++++++++-----
> 1 file changed, 9 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/iio/adc/ad799x.c b/drivers/iio/adc/ad799x.c
> index 84ce9b4..abc36c8 100644
> --- a/drivers/iio/adc/ad799x.c
> +++ b/drivers/iio/adc/ad799x.c
> @@ -208,7 +208,7 @@ out:
> return IRQ_HANDLED;
> }
>
> -static int ad7997_8_update_scan_mode(struct iio_dev *indio_dev,
> +static int ad799x_update_scan_mode(struct iio_dev *indio_dev,
> const unsigned long *scan_mask)
> {
> struct ad799x_state *st = iio_priv(indio_dev);
> @@ -221,10 +221,14 @@ static int ad7997_8_update_scan_mode(struct iio_dev *indio_dev,
> st->transfer_size = bitmap_weight(scan_mask, indio_dev->masklength) * 2;
>
> switch (st->id) {
> + case ad7992:
> + case ad7993:
> + case ad7994:
> case ad7997:
> case ad7998:
> - return i2c_smbus_write_word_swapped(st->client, AD7998_CONF_REG,
> - st->config | (*scan_mask << AD799X_CHANNEL_SHIFT));
> + st->config &= ~(GENMASK(7, 0) << AD799X_CHANNEL_SHIFT);
> + st->config |= (*scan_mask << AD799X_CHANNEL_SHIFT);
> + return ad799x_write_config(st, st->config);
> default:
> return 0;
> }
> @@ -483,7 +487,7 @@ static const struct iio_info ad7991_info = {
> static const struct iio_info ad7993_4_7_8_noirq_info = {
> .read_raw = &ad799x_read_raw,
> .driver_module = THIS_MODULE,
> - .update_scan_mode = ad7997_8_update_scan_mode,
> + .update_scan_mode = ad799x_update_scan_mode,
> };
>
> static const struct iio_info ad7993_4_7_8_irq_info = {
> @@ -493,7 +497,7 @@ static const struct iio_info ad7993_4_7_8_irq_info = {
> .read_event_value = &ad799x_read_event_value,
> .write_event_value = &ad799x_write_event_value,
> .driver_module = THIS_MODULE,
> - .update_scan_mode = ad7997_8_update_scan_mode,
> + .update_scan_mode = ad799x_update_scan_mode,
> };
>
> static const struct iio_event_spec ad799x_events[] = {
>
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH v3 11/12] iio:adc:ad799x: Return more meaningful event enabled state
2014-06-12 8:08 ` Lars-Peter Clausen
@ 2014-07-13 20:59 ` Jonathan Cameron
0 siblings, 0 replies; 31+ messages in thread
From: Jonathan Cameron @ 2014-07-13 20:59 UTC (permalink / raw)
To: Lars-Peter Clausen, Peter Meerwald; +Cc: linux-iio
On 12/06/14 09:08, Lars-Peter Clausen wrote:
> On 06/12/2014 06:54 AM, Peter Meerwald wrote:
>> only report an event as enabled if it actually is enabled
>>
>> Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
>
> Acked-by: Lars-Peter Clausen <lars@metafoo.de>
Applied.
>
> Thanks.
>
>> ---
>> drivers/iio/adc/ad799x.c | 10 +++++++++-
>> 1 file changed, 9 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/iio/adc/ad799x.c b/drivers/iio/adc/ad799x.c
>> index abc36c8..08bcada3 100644
>> --- a/drivers/iio/adc/ad799x.c
>> +++ b/drivers/iio/adc/ad799x.c
>> @@ -364,7 +364,15 @@ static int ad799x_read_event_config(struct iio_dev *indio_dev,
>> enum iio_event_type type,
>> enum iio_event_direction dir)
>> {
>> - return 1;
>> + struct ad799x_state *st = iio_priv(indio_dev);
>> +
>> + if (!(st->config & AD7998_ALERT_EN))
>> + return 0;
>> +
>> + if ((st->config >> AD799X_CHANNEL_SHIFT) & BIT(chan->scan_index))
>> + return 1;
>> +
>> + return 0;
>> }
>>
>> static unsigned int ad799x_threshold_reg(const struct iio_chan_spec *chan,
>>
>
> --
> 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] 31+ messages in thread
* Re: [PATCH v3 12/12] iio:adc:ad799x: Allow to write event config
2014-06-12 8:08 ` Lars-Peter Clausen
@ 2014-07-13 21:01 ` Jonathan Cameron
0 siblings, 0 replies; 31+ messages in thread
From: Jonathan Cameron @ 2014-07-13 21:01 UTC (permalink / raw)
To: Lars-Peter Clausen, Peter Meerwald; +Cc: linux-iio
On 12/06/14 09:08, Lars-Peter Clausen wrote:
> On 06/12/2014 06:54 AM, Peter Meerwald wrote:
>> allow to enable events
>>
>> previously, events were always reported as enabled, but actually only
>> implicitly enabled when updating the buffer scan mode
>>
>> Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
>
> It's not perfect, but is an improvement over the current situation so,
>
> Acked-by: Lars-Peter Clausen <lars@metafoo.de>
>
> Thanks.
Applied (with a little bit of description editing).
As ever, these will all get pushed out to testing for the autobuilders
to play. I will probably send them on to Greg sometime next weekend.
Thanks,
Jonathan
>
>> ---
>> drivers/iio/adc/ad799x.c | 34 ++++++++++++++++++++++++++++++++++
>> 1 file changed, 34 insertions(+)
>>
>> diff --git a/drivers/iio/adc/ad799x.c b/drivers/iio/adc/ad799x.c
>> index 08bcada3..e37412d 100644
>> --- a/drivers/iio/adc/ad799x.c
>> +++ b/drivers/iio/adc/ad799x.c
>> @@ -375,6 +375,39 @@ static int ad799x_read_event_config(struct iio_dev *indio_dev,
>> return 0;
>> }
>>
>> +static int ad799x_write_event_config(struct iio_dev *indio_dev,
>> + const struct iio_chan_spec *chan,
>> + enum iio_event_type type,
>> + enum iio_event_direction dir,
>> + int state)
>> +{
>> + struct ad799x_state *st = iio_priv(indio_dev);
>> + int ret;
>> +
>> + mutex_lock(&indio_dev->mlock);
>> + if (iio_buffer_enabled(indio_dev)) {
>> + ret = -EBUSY;
>> + goto done;
>> + }
>> +
>> + if (state)
>> + st->config |= BIT(chan->scan_index) << AD799X_CHANNEL_SHIFT;
>> + else
>> + st->config &= ~(BIT(chan->scan_index) << AD799X_CHANNEL_SHIFT);
>> +
>> + if (st->config >> AD799X_CHANNEL_SHIFT)
>> + st->config |= AD7998_ALERT_EN;
>> + else
>> + st->config &= ~AD7998_ALERT_EN;
>> +
>> + ret = ad799x_write_config(st, st->config);
>> +
>> +done:
>> + mutex_unlock(&indio_dev->mlock);
>> +
>> + return ret;
>> +}
>> +
>> static unsigned int ad799x_threshold_reg(const struct iio_chan_spec *chan,
>> enum iio_event_direction dir,
>> enum iio_event_info info)
>> @@ -502,6 +535,7 @@ static const struct iio_info ad7993_4_7_8_irq_info = {
>> .read_raw = &ad799x_read_raw,
>> .event_attrs = &ad799x_event_attrs_group,
>> .read_event_config = &ad799x_read_event_config,
>> + .write_event_config = &ad799x_write_event_config,
>> .read_event_value = &ad799x_read_event_value,
>> .write_event_value = &ad799x_write_event_value,
>> .driver_module = THIS_MODULE,
>>
>
> --
> 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] 31+ messages in thread
end of thread, other threads:[~2014-07-13 20:59 UTC | newest]
Thread overview: 31+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-12 4:54 [PATCH v3 00/12] ad799x cleanup Peter Meerwald
2014-06-12 4:54 ` [PATCH v3 01/12] iio:adc:ad799x: Fix reading and writing of event values, apply shift Peter Meerwald
2014-06-12 8:07 ` Lars-Peter Clausen
2014-06-14 14:19 ` Jonathan Cameron
2014-06-29 14:47 ` Jonathan Cameron
2014-06-12 4:54 ` [PATCH v3 02/12] iio:adc:ad799x: Fix ad799x_chip_info kerneldoc Peter Meerwald
2014-06-14 14:21 ` Jonathan Cameron
2014-06-12 4:54 ` [PATCH v3 03/12] iio:adc:ad799x: Drop I2C access helper functions Peter Meerwald
2014-06-12 8:10 ` Lars-Peter Clausen
2014-06-14 14:26 ` Jonathan Cameron
2014-07-13 20:47 ` Jonathan Cameron
2014-06-12 4:54 ` [PATCH v3 04/12] iio:adc:ad799x: Save some lines in ad7997_8_update_scan_mode() exit handling Peter Meerwald
2014-07-13 20:56 ` Jonathan Cameron
2014-06-12 4:54 ` [PATCH v3 05/12] iio:adc:ad799x: Use BIT() and GENMASK() Peter Meerwald
2014-07-13 20:56 ` Jonathan Cameron
2014-06-12 4:54 ` [PATCH v3 06/12] iio:adc:ad799x: Only expose event interface when IRQ is available Peter Meerwald
2014-07-13 20:56 ` Jonathan Cameron
2014-06-12 4:54 ` [PATCH v3 07/12] iio:adc:ad799x: Make chan_spec const in ad799x_chip_config struct Peter Meerwald
2014-07-13 20:57 ` Jonathan Cameron
2014-06-12 4:54 ` [PATCH v3 08/12] iio:adc:ad799x: Add helper function to read/write config register Peter Meerwald
2014-07-13 20:57 ` Jonathan Cameron
2014-06-12 4:54 ` [PATCH v3 09/12] iio:adc:ad799x: Write default config on probe and reset alert status on probe Peter Meerwald
2014-07-13 20:58 ` Jonathan Cameron
2014-06-12 4:54 ` [PATCH v3 10/12] iio:adc:ad799x: Set conversion channels and rename ad7997_8_update_scan_mode() Peter Meerwald
2014-07-13 20:58 ` Jonathan Cameron
2014-06-12 4:54 ` [PATCH v3 11/12] iio:adc:ad799x: Return more meaningful event enabled state Peter Meerwald
2014-06-12 8:08 ` Lars-Peter Clausen
2014-07-13 20:59 ` Jonathan Cameron
2014-06-12 4:54 ` [PATCH v3 12/12] iio:adc:ad799x: Allow to write event config Peter Meerwald
2014-06-12 8:08 ` Lars-Peter Clausen
2014-07-13 21:01 ` 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.