iio: Add helper functions for enum style channel attributes
Subsystems (5)
PATCH 1/18 iio: Add helper functions for enum style channel attributes
We often have the case were we do have a enum style channel attribute. These attributes have in common that they are a list of string values which usually map in a 1-to-1 fashion to integer values.
This patch implements some common helper code for implementing enum style channel attributes using extended channel attributes. The helper functions take care of converting between the string and integer values, as well providing a function for "_available" attributes which list all available enum items.
---
Changes since v1:
* Add documentation for struct iio_enum, IIO_ENUM and IIO_ENUM_AVAILABLE.
* Make set and get callbacks optional
--- drivers/iio/industrialio-core.c | 63 ++++++++++++++++++++++++++++++++++++++ include/linux/iio/iio.h | 64 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 127 insertions(+)
drivers/iio/industrialio-core.c +63 -0
@@ -289,6 +289,69 @@ static ssize_t iio_write_channel_ext_info(struct device *dev, this_attr->c, buf, len); } +ssize_t iio_enum_available_read (struct iio_dev *indio_dev, +uintptr_t priv,const struct iio_chan_spec *chan,char *buf) +{ +const struct iio_enum *e = (const struct iio_enum *)priv; +unsigned int i; +size_t len =0 ; + +if (!e->num_items) +return 0 ; + +for (i =0 ; i < e->num_items; ++i) + len +=snprintf (buf + len,PAGE_SIZE - len,"%s " , e->items[i]); + +/* replace last space with a newline */ + buf[len -1 ] ='\n' ; + +return len; +} +EXPORT_SYMBOL_GPL (iio_enum_available_read); + +ssize_t iio_enum_read (struct iio_dev *indio_dev, +uintptr_t priv,const struct iio_chan_spec *chan,char *buf) +{ +const struct iio_enum *e = (const struct iio_enum *)priv; +int i; + +if (!e->get) +return -EINVAL ; + + i = e->get (indio_dev, chan); +if (i <0 ) +return i; +else if (i >= e->num_items) +return -EINVAL ; + +return sprintf (buf,"%s\n" , e->items[i]); +} +EXPORT_SYMBOL_GPL (iio_enum_read); + +ssize_t iio_enum_write (struct iio_dev *indio_dev, +uintptr_t priv,const struct iio_chan_spec *chan,const char *buf, +size_t len) +{ +const struct iio_enum *e = (const struct iio_enum *)priv; +unsigned int i; +int ret; + +if (!e->set) +return -EINVAL ; + +for (i =0 ; i < e->num_items; i++) { +if (sysfs_streq (buf, e->items[i])) +break ; + } + +if (i == e->num_items) +return -EINVAL ; + + ret = e->set (indio_dev, chan, i); +return ret ? ret : len; +} +EXPORT_SYMBOL_GPL (iio_enum_write); +static ssize_t iio_read_channel_info (struct device *dev,struct device_attribute *attr,char *buf)
include/linux/iio/iio.h +64 -0
70 lines not on this page · raw message
Signature · 1 line
1.7.10
PATCH 2/18 staging:iio:dac:ad5064: Use iio_enum for powerdown modes
This allows us to remove some boilerplate code for comparing and formatting the enum strings.
--- drivers/staging/iio/dac/ad5064.c | 65 ++++++++++++-------------------------- 1 file changed, 21 insertions(+), 44 deletions(-)
drivers/staging/iio/dac/ad5064.c +21 -44
@@ -136,57 +136,42 @@ static int ad5064_sync_powerdown_mode(struct ad5064_state *st,return ret; } -static const char ad5064_powerdown_modes[][15 ] = { - [AD5064_LDAC_PWRDN_NONE ] ="" , - [AD5064_LDAC_PWRDN_1K ] ="1kohm_to_gnd" , - [AD5064_LDAC_PWRDN_100K ] ="100kohm_to_gnd" , - [AD5064_LDAC_PWRDN_3STATE ] ="three_state" , +static const char *const ad5064_powerdown_modes[] = { +"1kohm_to_gnd" , +"100kohm_to_gnd" , +"three_state" , }; -static ssize_t ad5064_read_powerdown_mode_available (struct iio_dev *indio_dev, -uintptr_t private,const struct iio_chan_spec *chan,char *buf) -{ -return sprintf (buf,"%s %s %s\n" , ad5064_powerdown_modes[1 ], - ad5064_powerdown_modes[2 ], ad5064_powerdown_modes[3 ]); -} - -static ssize_t ad5064_read_powerdown_mode (struct iio_dev *indio_dev, -uintptr_t private,const struct iio_chan_spec *chan,char *buf) +static int ad5064_get_powerdown_mode (struct iio_dev *indio_dev, +const struct iio_chan_spec *chan) {struct ad5064_state *st =iio_priv (indio_dev); -return sprintf (buf,"%s\n" , - ad5064_powerdown_modes[st->pwr_down_mode[chan->channel]]); +return st->pwr_down_mode[chan->channel] -1 ; } -static ssize_t ad5064_write_powerdown_mode (struct iio_dev *indio_dev, -uintptr_t private,const struct iio_chan_spec *chan,const char *buf, -size_t len) +static int ad5064_set_powerdown_mode (struct iio_dev *indio_dev, +const struct iio_chan_spec *chan,unsigned int mode) {struct ad5064_state *st =iio_priv (indio_dev); -unsigned int mode, i;int ret; - mode =0 ; - -for (i =1 ; i <ARRAY_SIZE (ad5064_powerdown_modes); ++i) { -if (sysfs_streq (buf, ad5064_powerdown_modes[i])) { - mode = i; -break ; - } - } -if (mode ==0 ) -return -EINVAL ; -mutex_lock (&indio_dev->mlock); - st->pwr_down_mode[chan->channel] = mode; + st->pwr_down_mode[chan->channel] = mode +1 ; ret =ad5064_sync_powerdown_mode (st, chan->channel);mutex_unlock (&indio_dev->mlock); -return ret ? ret : len; +return ret; } +static const struct iio_enum ad5064_powerdown_mode_enum = { + .items = ad5064_powerdown_modes, + .num_items =ARRAY_SIZE (ad5064_powerdown_modes), + .get = ad5064_get_powerdown_mode, + .set = ad5064_set_powerdown_mode, +}; +static ssize_t ad5064_read_dac_powerdown (struct iio_dev *indio_dev,uintptr_t private,const struct iio_chan_spec *chan,char *buf) {
@@ -286,22 +271,14 @@ static const struct iio_info ad5064_info = { .driver_module = THIS_MODULE, }; -static struct iio_chan_spec_ext_info ad5064_ext_info[] = { +static const struct iio_chan_spec_ext_info ad5064_ext_info[] = { { .name ="powerdown" , .read = ad5064_read_dac_powerdown, .write = ad5064_write_dac_powerdown, }, - { - .name ="powerdown_mode" , - .read = ad5064_read_powerdown_mode, - .write = ad5064_write_powerdown_mode, - }, - { - .name ="powerdown_mode_available" , - .shared = true, - .read = ad5064_read_powerdown_mode_available, - }, +IIO_ENUM ("powerdown_mode" , false, &ad5064_powerdown_mode_enum), +IIO_ENUM_AVAILABLE ("powerdown_mode" , &ad5064_powerdown_mode_enum), { }, };
Signature · 1 line
1.7.10
PATCH 3/18 staging:iio:dac:ad5446: Use iio_enum for powerdown modes
In reply to Lars-Peter ClausenThis allows us to remove some boilerplate code for comparing and formatting the enum strings.
--- drivers/staging/iio/dac/ad5446.c | 55 +++++++++++++------------------------- 1 file changed, 19 insertions(+), 36 deletions(-)
drivers/staging/iio/dac/ad5446.c +19 -36
@@ -42,47 +42,34 @@ static int ad5660_write(struct ad5446_state *st, unsigned val) }static const char *const ad5446_powerdown_modes[] = { -"" ,"1kohm_to_gnd" ,"100kohm_to_gnd" ,"three_state" +"1kohm_to_gnd" ,"100kohm_to_gnd" ,"three_state" }; -static ssize_t ad5446_read_powerdown_mode_available (struct iio_dev *indio_dev, -uintptr_t private,const struct iio_chan_spec *chan,char *buf) -{ -return sprintf (buf,"%s %s %s\n" , ad5446_powerdown_modes[1 ], - ad5446_powerdown_modes[2 ], ad5446_powerdown_modes[3 ]); -} - -static ssize_t ad5446_write_powerdown_mode (struct iio_dev *indio_dev, -uintptr_t private, -const struct iio_chan_spec *chan, -const char *buf,size_t len) +static int ad5446_set_powerdown_mode (struct iio_dev *indio_dev, +const struct iio_chan_spec *chan,unsigned int mode) {struct ad5446_state *st =iio_priv (indio_dev); -int i; - -for (i =1 ; i <ARRAY_SIZE (ad5446_powerdown_modes); i++) { -if (sysfs_streq (buf, ad5446_powerdown_modes[i])) { - st->pwr_down_mode = i; -break ; - } - } -if (i ==ARRAY_SIZE (ad5446_powerdown_modes)) -return -EINVAL ; + st->pwr_down_mode = mode +1 ; -return len; +return 0 ; } -static ssize_t ad5446_read_powerdown_mode (struct iio_dev *indio_dev, -uintptr_t private, -const struct iio_chan_spec *chan, -char *buf) +static int ad5446_get_powerdown_mode (struct iio_dev *indio_dev, +const struct iio_chan_spec *chan) {struct ad5446_state *st =iio_priv (indio_dev); -return sprintf (buf,"%s\n" , ad5446_powerdown_modes[st->pwr_down_mode]); +return st->pwr_down_mode -1 ; } +static const struct iio_enum ad5446_powerdown_mode_enum = { + .items = ad5446_powerdown_modes, + .num_items =ARRAY_SIZE (ad5446_powerdown_modes), + .get = ad5446_get_powerdown_mode, + .set = ad5446_set_powerdown_mode, +}; + static ssize_t ad5446_read_dac_powerdown(struct iio_dev *indio_dev, uintptr_t private, const struct iio_chan_spec *chan,
@@ -129,15 +116,9 @@ static const struct iio_chan_spec_ext_info ad5064_ext_info_powerdown[] = { .name = "powerdown", .read = ad5446_read_dac_powerdown, .write = ad5446_write_dac_powerdown, - }, { - .name = "powerdown_mode", - .read = ad5446_read_powerdown_mode, - .write = ad5446_write_powerdown_mode, - }, { - .name = "powerdown_mode_available", - .shared = true, - .read = ad5446_read_powerdown_mode_available, }, + IIO_ENUM("powerdown_mode", false, &ad5446_powerdown_mode_enum), + IIO_ENUM_AVAILABLE("powerdown_mode", &ad5446_powerdown_mode_enum), { }, };
@@ -321,6 +302,8 @@ static int __devinit ad5446_probe(struct spi_device *spi) indio_dev->channels = &st->chip_info->channel; indio_dev->num_channels =1 ; + st->pwr_down_mode = MODE_PWRDWN_1k; +if (st->chip_info->int_vref_mv) st->vref_mv = st->chip_info->int_vref_mv;else if (voltage_uv)
Signature · 1 line
1.7.10
PATCH 4/18 staging:iio:dac:ad5380: Convert to extended channel attributes
In reply to Lars-Peter ClausenUse extended channel attributes instead of raw sysfs files for the additional channel attributes. This allows us to remove some boilerplate code.
--- drivers/staging/iio/dac/ad5380.c | 250 ++++++++++++++++++-------------------- 1 file changed, 116 insertions(+), 134 deletions(-)
drivers/staging/iio/dac/ad5380.c +116 -134
@@ -81,103 +81,18 @@ enum ad5380_type { ID_AD5392_5, }; -#define AD5380_CHANNEL (_bits) { \ - .type = IIO_VOLTAGE, \ - .indexed = 1, \ - .output = 1, \ - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \ - IIO_CHAN_INFO_SCALE_SHARED_BIT | \ - IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT | \ - IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT, \ - .scan_type = IIO_ST('u', (_bits), 16, 14 - (_bits)) \ -} - -static const struct ad5380_chip_info ad5380_chip_info_tbl[] = { - [ID_AD5380_3 ] = { - .channel_template =AD5380_CHANNEL (14 ), - .num_channels =40 , - .int_vref =1250000 , - }, - [ID_AD5380_5 ] = { - .channel_template =AD5380_CHANNEL (14 ), - .num_channels =40 , - .int_vref =2500000 , - }, - [ID_AD5381_3 ] = { - .channel_template =AD5380_CHANNEL (12 ), - .num_channels =16 , - .int_vref =1250000 , - }, - [ID_AD5381_5 ] = { - .channel_template =AD5380_CHANNEL (12 ), - .num_channels =16 , - .int_vref =2500000 , - }, - [ID_AD5382_3 ] = { - .channel_template =AD5380_CHANNEL (14 ), - .num_channels =32 , - .int_vref =1250000 , - }, - [ID_AD5382_5 ] = { - .channel_template =AD5380_CHANNEL (14 ), - .num_channels =32 , - .int_vref =2500000 , - }, - [ID_AD5383_3 ] = { - .channel_template =AD5380_CHANNEL (12 ), - .num_channels =32 , - .int_vref =1250000 , - }, - [ID_AD5383_5 ] = { - .channel_template =AD5380_CHANNEL (12 ), - .num_channels =32 , - .int_vref =2500000 , - }, - [ID_AD5390_3 ] = { - .channel_template =AD5380_CHANNEL (14 ), - .num_channels =16 , - .int_vref =1250000 , - }, - [ID_AD5390_5 ] = { - .channel_template =AD5380_CHANNEL (14 ), - .num_channels =16 , - .int_vref =2500000 , - }, - [ID_AD5391_3 ] = { - .channel_template =AD5380_CHANNEL (12 ), - .num_channels =16 , - .int_vref =1250000 , - }, - [ID_AD5391_5 ] = { - .channel_template =AD5380_CHANNEL (12 ), - .num_channels =16 , - .int_vref =2500000 , - }, - [ID_AD5392_3 ] = { - .channel_template =AD5380_CHANNEL (14 ), - .num_channels =8 , - .int_vref =1250000 , - }, - [ID_AD5392_5 ] = { - .channel_template =AD5380_CHANNEL (14 ), - .num_channels =8 , - .int_vref =2500000 , - }, -}; - -static ssize_t ad5380_read_dac_powerdown (struct device *dev, -struct device_attribute *attr,char *buf) +static ssize_t ad5380_read_dac_powerdown (struct iio_dev *indio_dev, +uintptr_t private,const struct iio_chan_spec *chan,char *buf) { -struct iio_dev *indio_dev =dev_to_iio_dev (dev);struct ad5380_state *st =iio_priv (indio_dev);return sprintf (buf,"%d\n" , st->pwr_down); } -static ssize_t ad5380_write_dac_powerdown (struct device *dev, -struct device_attribute *attr,const char *buf,size_t len) +static ssize_t ad5380_write_dac_powerdown (struct iio_dev *indio_dev, +uintptr_t private,const struct iio_chan_spec *chan,const char *buf, +size_t len) { -struct iio_dev *indio_dev =dev_to_iio_dev (dev);struct ad5380_state *st =iio_priv (indio_dev);bool pwr_down;int ret;
@@ -200,20 +115,14 @@ static ssize_t ad5380_write_dac_powerdown(struct device *dev,return ret ? ret : len; } -static IIO_DEVICE_ATTR(out_voltage_powerdown, - S_IRUGO | S_IWUSR, - ad5380_read_dac_powerdown, - ad5380_write_dac_powerdown, 0); - -static const char ad5380_powerdown_modes[][15 ] = { - [0 ] ="100kohm_to_gnd" , - [1 ] ="three_state" , +static const char *const ad5380_powerdown_modes[] = { +"100kohm_to_gnd" , +"three_state" , }; -static ssize_t ad5380_read_powerdown_mode (struct device *dev, -struct device_attribute *attr,char *buf) +static int ad5380_get_powerdown_mode (struct iio_dev *indio_dev, +const struct iio_chan_spec *chan) { -struct iio_dev *indio_dev =dev_to_iio_dev (dev);struct ad5380_state *st =iio_priv (indio_dev);unsigned int mode;int ret;
@@ -224,49 +133,27 @@ static ssize_t ad5380_read_powerdown_mode(struct device *dev, mode = (mode >>AD5380_CTRL_PWR_DOWN_MODE_OFFSET ) &1 ; -return sprintf (buf,"%s\n" , ad5380_powerdown_modes[mode]); +return mode; } -static ssize_t ad5380_write_powerdown_mode (struct device *dev, -struct device_attribute *attr,const char *buf,size_t len) +static int ad5380_set_powerdown_mode (struct iio_dev *indio_dev, +const struct iio_chan_spec *chan,unsigned int mode) { -struct iio_dev *indio_dev =dev_to_iio_dev (dev);struct ad5380_state *st =iio_priv (indio_dev); -unsigned int i;int ret; -for (i =0 ; i <ARRAY_SIZE (ad5380_powerdown_modes); ++i) { -if (sysfs_streq (buf, ad5380_powerdown_modes[i])) -break ; - } - -if (i ==ARRAY_SIZE (ad5380_powerdown_modes)) -return -EINVAL ; - ret =regmap_update_bits (st->regmap,AD5380_REG_SF_CTRL ,1 <<AD5380_CTRL_PWR_DOWN_MODE_OFFSET , - i <<AD5380_CTRL_PWR_DOWN_MODE_OFFSET ); + mode <<AD5380_CTRL_PWR_DOWN_MODE_OFFSET ); -return ret ? ret : len; +return ret; } -static IIO_DEVICE_ATTR(out_voltage_powerdown_mode, - S_IRUGO | S_IWUSR, - ad5380_read_powerdown_mode, - ad5380_write_powerdown_mode, 0); - -static IIO_CONST_ATTR(out_voltage_powerdown_mode_available, - "100kohm_to_gnd three_state"); - -static struct attribute *ad5380_attributes[] = { - &iio_dev_attr_out_voltage_powerdown.dev_attr.attr, - &iio_dev_attr_out_voltage_powerdown_mode.dev_attr.attr, - &iio_const_attr_out_voltage_powerdown_mode_available.dev_attr.attr, -NULL , -}; - -static const struct attribute_group ad5380_attribute_group = { - .attrs = ad5380_attributes, +static const struct iio_enum ad5380_powerdown_mode_enum = { + .items = ad5380_powerdown_modes, + .num_items =ARRAY_SIZE (ad5380_powerdown_modes), + .get = ad5380_get_powerdown_mode, + .set = ad5380_set_powerdown_mode, }; static unsigned int ad5380_info_to_reg(struct iio_chan_spec const *chan,
@@ -354,10 +241,105 @@ static int ad5380_read_raw(struct iio_dev *indio_dev,static const struct iio_info ad5380_info = { .read_raw = ad5380_read_raw, .write_raw = ad5380_write_raw, - .attrs = &ad5380_attribute_group, .driver_module =THIS_MODULE , }; +static struct iio_chan_spec_ext_info ad5380_ext_info[] = { + { + .name ="powerdown" , + .read = ad5380_read_dac_powerdown, + .write = ad5380_write_dac_powerdown, + }, +IIO_ENUM ("powerdown_mode" , true, &ad5380_powerdown_mode_enum), +IIO_ENUM_AVAILABLE ("powerdown_mode" , &ad5380_powerdown_mode_enum), + { }, +}; + +#define AD5380_CHANNEL (_bits) { \ + .type = IIO_VOLTAGE, \ + .indexed = 1, \ + .output = 1, \ + .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \ + IIO_CHAN_INFO_SCALE_SHARED_BIT | \ + IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT | \ + IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT, \ + .scan_type = IIO_ST('u', (_bits), 16, 14 - (_bits)), \ + .ext_info = ad5380_ext_info, \ +} + +static const struct ad5380_chip_info ad5380_chip_info_tbl[] = { + [ID_AD5380_3 ] = { + .channel_template =AD5380_CHANNEL (14 ), + .num_channels =40 , + .int_vref =1250000 , + }, + [ID_AD5380_5 ] = { + .channel_template =AD5380_CHANNEL (14 ), + .num_channels =40 , + .int_vref =2500000 , + }, + [ID_AD5381_3 ] = { + .channel_template =AD5380_CHANNEL (12 ), + .num_channels =16 , + .int_vref =1250000 , + }, + [ID_AD5381_5 ] = { + .channel_template =AD5380_CHANNEL (12 ), + .num_channels =16 , + .int_vref =2500000 , + }, + [ID_AD5382_3 ] = { + .channel_template =AD5380_CHANNEL (14 ), + .num_channels =32 , + .int_vref =1250000 , + }, + [ID_AD5382_5 ] = { + .channel_template =AD5380_CHANNEL (14 ), + .num_channels =32 , + .int_vref =2500000 , + }, + [ID_AD5383_3 ] = { + .channel_template =AD5380_CHANNEL (12 ), + .num_channels =32 , + .int_vref =1250000 , + }, + [ID_AD5383_5 ] = { + .channel_template =AD5380_CHANNEL (12 ), + .num_channels =32 , + .int_vref =2500000 , + }, + [ID_AD5390_3 ] = { + .channel_template =AD5380_CHANNEL (14 ), + .num_channels =16 , + .int_vref =1250000 , + }, + [ID_AD5390_5 ] = { + .channel_template =AD5380_CHANNEL (14 ), + .num_channels =16 , + .int_vref =2500000 , + }, + [ID_AD5391_3 ] = { + .channel_template =AD5380_CHANNEL (12 ), + .num_channels =16 , + .int_vref =1250000 , + }, + [ID_AD5391_5 ] = { + .channel_template =AD5380_CHANNEL (12 ), + .num_channels =16 , + .int_vref =2500000 , + }, + [ID_AD5392_3 ] = { + .channel_template =AD5380_CHANNEL (14 ), + .num_channels =8 , + .int_vref =1250000 , + }, + [ID_AD5392_5 ] = { + .channel_template =AD5380_CHANNEL (14 ), + .num_channels =8 , + .int_vref =2500000 , + }, +}; +static int __devinit ad5380_alloc_channels (struct iio_dev *indio_dev) {struct ad5380_state *st =iio_priv (indio_dev);
Signature · 1 line
1.7.10
PATCH 5/18 staging:iio:dac:ad5504: Convert to extended channel attributes
In reply to Lars-Peter ClausenUse extended channel attributes instead of raw sysfs files for the additional channel attributes. This allows us to remove some boilerplate code.
--- drivers/staging/iio/dac/ad5504.c | 165 ++++++++++++++------------------------ 1 file changed, 59 insertions(+), 106 deletions(-)
drivers/staging/iio/dac/ad5504.c +59 -106
@@ -22,24 +22,6 @@#include "dac.h" #include "ad5504.h" -#define AD5504_CHANNEL (_chan) { \ - .type = IIO_VOLTAGE, \ - .indexed = 1, \ - .output = 1, \ - .channel = (_chan), \ - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \ - IIO_CHAN_INFO_SCALE_SHARED_BIT, \ - .address = AD5504_ADDR_DAC(_chan), \ - .scan_type = IIO_ST('u', 12, 16, 0), \ -} - -static const struct iio_chan_spec ad5504_channels[] = { -AD5504_CHANNEL (0 ), -AD5504_CHANNEL (1 ), -AD5504_CHANNEL (2 ), -AD5504_CHANNEL (3 ), -}; -static int ad5504_spi_write (struct spi_device *spi,u8 addr,u16 val) { u16 tmp = cpu_to_be16(AD5504_CMD_WRITE |
@@ -95,8 +77,8 @@ static int ad5504_read_raw(struct iio_dev *indio_dev, *val = scale_uv /1000 ; *val2 = (scale_uv %1000 ) *1000 ;return IIO_VAL_INT_PLUS_MICRO ; - } +return -EINVAL ; }
@@ -122,65 +104,61 @@ static int ad5504_write_raw(struct iio_dev *indio_dev,return -EINVAL ; } -static ssize_t ad5504_read_powerdown_mode (struct device *dev, -struct device_attribute *attr,char *buf) +static const char *const ad5504_powerdown_modes[] = { +"20kohm_to_gnd" , +"three_state" , +}; + +static int ad5504_get_powerdown_mode (struct iio_dev *indio_dev, +const struct iio_chan_spec *chan) { -struct iio_dev *indio_dev =dev_to_iio_dev (dev);struct ad5504_state *st =iio_priv (indio_dev); -const char mode[][14 ] = {"20kohm_to_gnd" ,"three_state" }; - -return sprintf (buf,"%s\n" , mode[st->pwr_down_mode]); +return st->pwr_down_mode; } -static ssize_t ad5504_write_powerdown_mode (struct device *dev, -struct device_attribute *attr, -const char *buf,size_t len) +static int ad5504_set_powerdown_mode (struct iio_dev *indio_dev, +const struct iio_chan_spec *chan,unsigned int mode) { -struct iio_dev *indio_dev =dev_to_iio_dev (dev);struct ad5504_state *st =iio_priv (indio_dev); -int ret; -if (sysfs_streq (buf,"20kohm_to_gnd" )) - st->pwr_down_mode =AD5504_DAC_PWRDN_20K ; -else if (sysfs_streq (buf,"three_state" )) - st->pwr_down_mode =AD5504_DAC_PWRDN_3STATE ; -else - ret = -EINVAL ; + st->pwr_down_mode = mode; -return ret ? ret : len; +return 0 ; } -static ssize_t ad5504_read_dac_powerdown (struct device *dev, -struct device_attribute *attr, -char *buf) +static const struct iio_enum ad5504_powerdown_mode_enum = { + .items = ad5504_powerdown_modes, + .num_items =ARRAY_SIZE (ad5504_powerdown_modes), + .get = ad5504_get_powerdown_mode, + .set = ad5504_set_powerdown_mode, +}; + +static ssize_t ad5504_read_dac_powerdown (struct iio_dev *indio_dev, +uintptr_t private,const struct iio_chan_spec *chan,char *buf) { -struct iio_dev *indio_dev =dev_to_iio_dev (dev);struct ad5504_state *st =iio_priv (indio_dev); -struct iio_dev_attr *this_attr =to_iio_dev_attr (attr);return sprintf (buf,"%d\n" , - !(st->pwr_down_mask & (1 << this_attr->address))); + !(st->pwr_down_mask & (1 << chan->channel))); } -static ssize_t ad5504_write_dac_powerdown (struct device *dev, -struct device_attribute *attr, -const char *buf,size_t len) +static ssize_t ad5504_write_dac_powerdown (struct iio_dev *indio_dev, +uintptr_t private,const struct iio_chan_spec *chan,const char *buf, +size_t len) {long readin;int ret; -struct iio_dev *indio_dev =dev_to_iio_dev (dev);struct ad5504_state *st =iio_priv (indio_dev); -struct iio_dev_attr *this_attr =to_iio_dev_attr (attr); ret =strict_strtol (buf,10 , &readin);if (ret)return ret;if (readin ==0 ) - st->pwr_down_mask |= (1 << this_attr->address); + st->pwr_down_mask |= (1 << chan->channel);else if (readin ==1 ) - st->pwr_down_mask &= ~(1 << this_attr->address); + st->pwr_down_mask &= ~(1 << chan->channel);else ret = -EINVAL ;
@@ -194,50 +172,6 @@ static ssize_t ad5504_write_dac_powerdown(struct device *dev,return ret ? ret : len; } -static IIO_DEVICE_ATTR(out_voltage_powerdown_mode, S_IRUGO | - S_IWUSR, ad5504_read_powerdown_mode, - ad5504_write_powerdown_mode, 0); - -static IIO_CONST_ATTR(out_voltage_powerdown_mode_available, - "20kohm_to_gnd three_state"); - -#define IIO_DEV_ATTR_DAC_POWERDOWN (_num, _show, _store, _addr) \ - IIO_DEVICE_ATTR(out_voltage##_num##_powerdown, \ - S_IRUGO | S_IWUSR, _show, _store, _addr) -static IIO_DEV_ATTR_DAC_POWERDOWN(0, ad5504_read_dac_powerdown, - ad5504_write_dac_powerdown, 0); -static IIO_DEV_ATTR_DAC_POWERDOWN(1, ad5504_read_dac_powerdown, - ad5504_write_dac_powerdown, 1); -static IIO_DEV_ATTR_DAC_POWERDOWN(2, ad5504_read_dac_powerdown, - ad5504_write_dac_powerdown, 2); -static IIO_DEV_ATTR_DAC_POWERDOWN(3, ad5504_read_dac_powerdown, - ad5504_write_dac_powerdown, 3); - -static struct attribute *ad5504_attributes[] = { - &iio_dev_attr_out_voltage0_powerdown.dev_attr.attr, - &iio_dev_attr_out_voltage1_powerdown.dev_attr.attr, - &iio_dev_attr_out_voltage2_powerdown.dev_attr.attr, - &iio_dev_attr_out_voltage3_powerdown.dev_attr.attr, - &iio_dev_attr_out_voltage_powerdown_mode.dev_attr.attr, - &iio_const_attr_out_voltage_powerdown_mode_available.dev_attr.attr, -NULL , -}; - -static const struct attribute_group ad5504_attribute_group = { - .attrs = ad5504_attributes, -}; - -static struct attribute *ad5501_attributes[] = { - &iio_dev_attr_out_voltage0_powerdown.dev_attr.attr, - &iio_dev_attr_out_voltage_powerdown_mode.dev_attr.attr, - &iio_const_attr_out_voltage_powerdown_mode_available.dev_attr.attr, -NULL , -}; - -static const struct attribute_group ad5501_attribute_group = { - .attrs = ad5501_attributes, -}; - static IIO_CONST_ATTR(temp0_thresh_rising_value, "110000"); static IIO_CONST_ATTR(temp0_thresh_rising_en, "1");
@@ -267,17 +201,38 @@ static irqreturn_t ad5504_event_handler(int irq, void *private)static const struct iio_info ad5504_info = { .write_raw = ad5504_write_raw, .read_raw = ad5504_read_raw, - .attrs = &ad5504_attribute_group, .event_attrs = &ad5504_ev_attribute_group, .driver_module =THIS_MODULE , }; -static const struct iio_info ad5501_info = { - .write_raw = ad5504_write_raw, - .read_raw = ad5504_read_raw, - .attrs = &ad5501_attribute_group, - .event_attrs = &ad5504_ev_attribute_group, - .driver_module =THIS_MODULE , +static const struct iio_chan_spec_ext_info ad5504_ext_info[] = { + { + .name ="powerdown" , + .read = ad5504_read_dac_powerdown, + .write = ad5504_write_dac_powerdown, + }, +IIO_ENUM ("powerdown_mode" , true, &ad5504_powerdown_mode_enum), +IIO_ENUM_AVAILABLE ("powerdown_mode" , &ad5504_powerdown_mode_enum), + { }, +}; + +#define AD5504_CHANNEL (_chan) { \ + .type = IIO_VOLTAGE, \ + .indexed = 1, \ + .output = 1, \ + .channel = (_chan), \ + .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \ + IIO_CHAN_INFO_SCALE_SHARED_BIT, \ + .address = AD5504_ADDR_DAC(_chan), \ + .scan_type = IIO_ST('u', 12, 16, 0), \ + .ext_info = ad5504_ext_info, \ +} + +static const struct iio_chan_spec ad5504_channels[] = { +AD5504_CHANNEL (0 ), +AD5504_CHANNEL (1 ), +AD5504_CHANNEL (2 ), +AD5504_CHANNEL (3 ), };static int __devinit ad5504_probe (struct spi_device *spi)
@@ -315,13 +270,11 @@ static int __devinit ad5504_probe(struct spi_device *spi) st->spi = spi; indio_dev->dev.parent = &spi->dev; indio_dev->name =spi_get_device_id (st->spi)->name; -if (spi_get_device_id (st->spi)->driver_data ==ID_AD5501 ) { - indio_dev->info = &ad5501_info; + indio_dev->info = &ad5504_info; +if (spi_get_device_id (st->spi)->driver_data ==ID_AD5501 ) indio_dev->num_channels =1 ; - }else { - indio_dev->info = &ad5504_info; +else indio_dev->num_channels =4 ; - } indio_dev->channels = ad5504_channels; indio_dev->modes =INDIO_DIRECT_MODE ;
Signature · 1 line
1.7.10
PATCH 6/18 staging:iio:dac:ad5624r: Convert to extended channel attributes
In reply to Lars-Peter ClausenUse extended channel attributes instead of raw sysfs files for the additional channel attributes. This allows us to remove some boilerplate code.
--- drivers/staging/iio/dac/ad5624r_spi.c | 208 ++++++++++++++------------------- 1 file changed, 90 insertions(+), 118 deletions(-)
drivers/staging/iio/dac/ad5624r_spi.c +90 -118
@@ -21,56 +21,6 @@#include "dac.h" #include "ad5624r.h" -#define AD5624R_CHANNEL (_chan, _bits) { \ - .type = IIO_VOLTAGE, \ - .indexed = 1, \ - .output = 1, \ - .channel = (_chan), \ - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \ - IIO_CHAN_INFO_SCALE_SHARED_BIT, \ - .address = (_chan), \ - .scan_type = IIO_ST('u', (_bits), 16, 16 - (_bits)), \ -} - -#define DECLARE_AD5624R_CHANNELS (_name, _bits) \ - const struct iio_chan_spec _name##_channels[] = { \ - AD5624R_CHANNEL(0, _bits), \ - AD5624R_CHANNEL(1, _bits), \ - AD5624R_CHANNEL(2, _bits), \ - AD5624R_CHANNEL(3, _bits), \ -} - -static DECLARE_AD5624R_CHANNELS(ad5624r, 12); -static DECLARE_AD5624R_CHANNELS(ad5644r, 14); -static DECLARE_AD5624R_CHANNELS(ad5664r, 16); - -static const struct ad5624r_chip_info ad5624r_chip_info_tbl[] = { - [ID_AD5624R3 ] = { - .channels = ad5624r_channels, - .int_vref_mv =1250 , - }, - [ID_AD5624R5 ] = { - .channels = ad5624r_channels, - .int_vref_mv =2500 , - }, - [ID_AD5644R3 ] = { - .channels = ad5644r_channels, - .int_vref_mv =1250 , - }, - [ID_AD5644R5 ] = { - .channels = ad5644r_channels, - .int_vref_mv =2500 , - }, - [ID_AD5664R3 ] = { - .channels = ad5664r_channels, - .int_vref_mv =1250 , - }, - [ID_AD5664R5 ] = { - .channels = ad5664r_channels, - .int_vref_mv =2500 , - }, -}; -static int ad5624r_spi_write (struct spi_device *spi,u8 cmd,u8 addr,u16 val,u8 len) {
@@ -138,67 +88,62 @@ static int ad5624r_write_raw(struct iio_dev *indio_dev,return -EINVAL ; } -static ssize_t ad5624r_read_powerdown_mode (struct device *dev, -struct device_attribute *attr,char *buf) +static const char *const ad5624r_powerdown_modes[] = { +"1kohm_to_gnd" , +"100kohm_to_gnd" , +"three_state" +}; + +static int ad5624r_get_powerdown_mode (struct iio_dev *indio_dev, +const struct iio_chan_spec *chan) { -struct iio_dev *indio_dev =dev_to_iio_dev (dev);struct ad5624r_state *st =iio_priv (indio_dev); -char mode[][15 ] = {"" ,"1kohm_to_gnd" ,"100kohm_to_gnd" ,"three_state" }; - -return sprintf (buf,"%s\n" , mode[st->pwr_down_mode]); +return st->pwr_down_mode; } -static ssize_t ad5624r_write_powerdown_mode (struct device *dev, -struct device_attribute *attr, -const char *buf,size_t len) +static int ad5624r_set_powerdown_mode (struct iio_dev *indio_dev, +const struct iio_chan_spec *chan,unsigned int mode) { -struct iio_dev *indio_dev =dev_to_iio_dev (dev);struct ad5624r_state *st =iio_priv (indio_dev); -int ret; -if (sysfs_streq (buf,"1kohm_to_gnd" )) - st->pwr_down_mode =AD5624R_LDAC_PWRDN_1K ; -else if (sysfs_streq (buf,"100kohm_to_gnd" )) - st->pwr_down_mode =AD5624R_LDAC_PWRDN_100K ; -else if (sysfs_streq (buf,"three_state" )) - st->pwr_down_mode =AD5624R_LDAC_PWRDN_3STATE ; -else - ret = -EINVAL ; + st->pwr_down_mode = mode; -return ret ? ret : len; +return 0 ; } -static ssize_t ad5624r_read_dac_powerdown (struct device *dev, -struct device_attribute *attr, -char *buf) +static const struct iio_enum ad5624r_powerdown_mode_enum = { + .items = ad5624r_powerdown_modes, + .num_items =ARRAY_SIZE (ad5624r_powerdown_modes), + .get = ad5624r_get_powerdown_mode, + .set = ad5624r_set_powerdown_mode, +}; + +static ssize_t ad5624r_read_dac_powerdown (struct iio_dev *indio_dev, +uintptr_t private,const struct iio_chan_spec *chan,char *buf) { -struct iio_dev *indio_dev =dev_to_iio_dev (dev);struct ad5624r_state *st =iio_priv (indio_dev); -struct iio_dev_attr *this_attr =to_iio_dev_attr (attr);return sprintf (buf,"%d\n" , - !!(st->pwr_down_mask & (1 << this_attr->address))); + !!(st->pwr_down_mask & (1 << chan->channel))); } -static ssize_t ad5624r_write_dac_powerdown (struct device *dev, -struct device_attribute *attr, -const char *buf,size_t len) +static ssize_t ad5624r_write_dac_powerdown (struct iio_dev *indio_dev, +uintptr_t private,const struct iio_chan_spec *chan,const char *buf, +size_t len) {long readin;int ret; -struct iio_dev *indio_dev =dev_to_iio_dev (dev);struct ad5624r_state *st =iio_priv (indio_dev); -struct iio_dev_attr *this_attr =to_iio_dev_attr (attr); ret =strict_strtol (buf,10 , &readin);if (ret)return ret;if (readin ==1 ) - st->pwr_down_mask |= (1 << this_attr->address); + st->pwr_down_mask |= (1 << chan->channel);else if (!readin) - st->pwr_down_mask &= ~(1 << this_attr->address); + st->pwr_down_mask &= ~(1 << chan->channel);else ret = -EINVAL ;
@@ -209,47 +154,74 @@ static ssize_t ad5624r_write_dac_powerdown(struct device *dev,return ret ? ret : len; } -static IIO_DEVICE_ATTR(out_voltage_powerdown_mode, S_IRUGO | - S_IWUSR, ad5624r_read_powerdown_mode, - ad5624r_write_powerdown_mode, 0); - -static IIO_CONST_ATTR(out_voltage_powerdown_mode_available, - "1kohm_to_gnd 100kohm_to_gnd three_state"); - -#define IIO_DEV_ATTR_DAC_POWERDOWN (_num, _show, _store, _addr) \ - IIO_DEVICE_ATTR(out_voltage##_num##_powerdown, \ - S_IRUGO | S_IWUSR, _show, _store, _addr) - -static IIO_DEV_ATTR_DAC_POWERDOWN(0, ad5624r_read_dac_powerdown, - ad5624r_write_dac_powerdown, 0); -static IIO_DEV_ATTR_DAC_POWERDOWN(1, ad5624r_read_dac_powerdown, - ad5624r_write_dac_powerdown, 1); -static IIO_DEV_ATTR_DAC_POWERDOWN(2, ad5624r_read_dac_powerdown, - ad5624r_write_dac_powerdown, 2); -static IIO_DEV_ATTR_DAC_POWERDOWN(3, ad5624r_read_dac_powerdown, - ad5624r_write_dac_powerdown, 3); - -static struct attribute *ad5624r_attributes[] = { - &iio_dev_attr_out_voltage0_powerdown.dev_attr.attr, - &iio_dev_attr_out_voltage1_powerdown.dev_attr.attr, - &iio_dev_attr_out_voltage2_powerdown.dev_attr.attr, - &iio_dev_attr_out_voltage3_powerdown.dev_attr.attr, - &iio_dev_attr_out_voltage_powerdown_mode.dev_attr.attr, - &iio_const_attr_out_voltage_powerdown_mode_available.dev_attr.attr, -NULL , -}; - -static const struct attribute_group ad5624r_attribute_group = { - .attrs = ad5624r_attributes, -}; -static const struct iio_info ad5624r_info = { .write_raw = ad5624r_write_raw, .read_raw = ad5624r_read_raw, - .attrs = &ad5624r_attribute_group, .driver_module =THIS_MODULE , }; +static const struct iio_chan_spec_ext_info ad5624r_ext_info[] = { + { + .name ="powerdown" , + .read = ad5624r_read_dac_powerdown, + .write = ad5624r_write_dac_powerdown, + }, +IIO_ENUM ("powerdown_mode" , true, &ad5624r_powerdown_mode_enum), +IIO_ENUM_AVAILABLE ("powerdown_mode" , &ad5624r_powerdown_mode_enum), + { }, +}; + +#define AD5624R_CHANNEL (_chan, _bits) { \ + .type = IIO_VOLTAGE, \ + .indexed = 1, \ + .output = 1, \ + .channel = (_chan), \ + .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \ + IIO_CHAN_INFO_SCALE_SHARED_BIT, \ + .address = (_chan), \ + .scan_type = IIO_ST('u', (_bits), 16, 16 - (_bits)), \ + .ext_info = ad5624r_ext_info, \ +} + +#define DECLARE_AD5624R_CHANNELS (_name, _bits) \ + const struct iio_chan_spec _name##_channels[] = { \ + AD5624R_CHANNEL(0, _bits), \ + AD5624R_CHANNEL(1, _bits), \ + AD5624R_CHANNEL(2, _bits), \ + AD5624R_CHANNEL(3, _bits), \ +} + +static DECLARE_AD5624R_CHANNELS(ad5624r, 12); +static DECLARE_AD5624R_CHANNELS(ad5644r, 14); +static DECLARE_AD5624R_CHANNELS(ad5664r, 16); + +static const struct ad5624r_chip_info ad5624r_chip_info_tbl[] = { + [ID_AD5624R3 ] = { + .channels = ad5624r_channels, + .int_vref_mv =1250 , + }, + [ID_AD5624R5 ] = { + .channels = ad5624r_channels, + .int_vref_mv =2500 , + }, + [ID_AD5644R3 ] = { + .channels = ad5644r_channels, + .int_vref_mv =1250 , + }, + [ID_AD5644R5 ] = { + .channels = ad5644r_channels, + .int_vref_mv =2500 , + }, + [ID_AD5664R3 ] = { + .channels = ad5664r_channels, + .int_vref_mv =1250 , + }, + [ID_AD5664R5 ] = { + .channels = ad5664r_channels, + .int_vref_mv =2500 , + }, +}; +static int __devinit ad5624r_probe (struct spi_device *spi) {struct ad5624r_state *st;
Signature · 1 line
1.7.10
PATCH 7/18 staging:iio:dac:ad5686: Convert to extended channel attributes
In reply to Lars-Peter ClausenUse extended channel attributes instead of raw sysfs files for the additional channel attributes. This allows us to remove some boilerplate code.
--- drivers/staging/iio/dac/ad5686.c | 196 ++++++++++++++++---------------------- 1 file changed, 80 insertions(+), 116 deletions(-)
drivers/staging/iio/dac/ad5686.c +80 -116
@@ -93,40 +93,6 @@ enum ad5686_supported_device_ids {ID_AD5685 , ID_AD5686, }; -#define AD5868_CHANNEL (chan, bits, shift) { \ - .type = IIO_VOLTAGE, \ - .indexed = 1, \ - .output = 1, \ - .channel = chan, \ - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \ - IIO_CHAN_INFO_SCALE_SHARED_BIT, \ - .address = AD5686_ADDR_DAC(chan), \ - .scan_type = IIO_ST('u', bits, 16, shift) \ -} -static const struct ad5686_chip_info ad5686_chip_info_tbl[] = { - [ID_AD5684 ] = { - .channel[0 ] =AD5868_CHANNEL (0 ,12 ,4 ), - .channel[1 ] =AD5868_CHANNEL (1 ,12 ,4 ), - .channel[2 ] =AD5868_CHANNEL (2 ,12 ,4 ), - .channel[3 ] =AD5868_CHANNEL (3 ,12 ,4 ), - .int_vref_mv =2500 , - }, - [ID_AD5685 ] = { - .channel[0 ] =AD5868_CHANNEL (0 ,14 ,2 ), - .channel[1 ] =AD5868_CHANNEL (1 ,14 ,2 ), - .channel[2 ] =AD5868_CHANNEL (2 ,14 ,2 ), - .channel[3 ] =AD5868_CHANNEL (3 ,14 ,2 ), - .int_vref_mv =2500 , - }, - [ID_AD5686 ] = { - .channel[0 ] =AD5868_CHANNEL (0 ,16 ,0 ), - .channel[1 ] =AD5868_CHANNEL (1 ,16 ,0 ), - .channel[2 ] =AD5868_CHANNEL (2 ,16 ,0 ), - .channel[3 ] =AD5868_CHANNEL (3 ,16 ,0 ), - .int_vref_mv =2500 , - }, -}; -static int ad5686_spi_write (struct ad5686_state *st,u8 cmd,u8 addr,u16 val,u8 shift) {
@@ -170,73 +136,63 @@ static int ad5686_spi_read(struct ad5686_state *st, u8 addr)return be32_to_cpu (st->data[2 ].d32); } -static ssize_t ad5686_read_powerdown_mode (struct device *dev, -struct device_attribute *attr,char *buf) +static const char *const ad5686_powerdown_modes[] = { +"1kohm_to_gnd" , +"100kohm_to_gnd" , +"three_state" +}; + +static int ad5686_get_powerdown_mode (struct iio_dev *indio_dev, +const struct iio_chan_spec *chan) { -struct iio_dev *indio_dev =dev_to_iio_dev (dev);struct ad5686_state *st =iio_priv (indio_dev); -struct iio_dev_attr *this_attr =to_iio_dev_attr (attr); -char mode[][15 ] = {"" ,"1kohm_to_gnd" ,"100kohm_to_gnd" ,"three_state" }; - -return sprintf (buf,"%s\n" , mode[(st->pwr_down_mode >> - (this_attr->address *2 )) &0x3 ]); +return ((st->pwr_down_mode >> (chan->channel *2 )) &0x3 ) -1 ; } -static ssize_t ad5686_write_powerdown_mode (struct device *dev, -struct device_attribute *attr, -const char *buf,size_t len) +static int ad5686_set_powerdown_mode (struct iio_dev *indio_dev, +const struct iio_chan_spec *chan,unsigned int mode) { -struct iio_dev *indio_dev =dev_to_iio_dev (dev);struct ad5686_state *st =iio_priv (indio_dev); -struct iio_dev_attr *this_attr =to_iio_dev_attr (attr); -unsigned mode; - -if (sysfs_streq (buf,"1kohm_to_gnd" )) - mode =AD5686_LDAC_PWRDN_1K ; -else if (sysfs_streq (buf,"100kohm_to_gnd" )) - mode =AD5686_LDAC_PWRDN_100K ; -else if (sysfs_streq (buf,"three_state" )) - mode =AD5686_LDAC_PWRDN_3STATE ; -else -return -EINVAL ; - st->pwr_down_mode &= ~(0x3 << (this_attr->address *2 )); - st->pwr_down_mode |= (mode << (this_attr->address *2 )); + st->pwr_down_mode &= ~(0x3 << (chan->channel *2 )); + st->pwr_down_mode |= ((mode +1 ) << (chan->channel *2 )); -return len; +return 0 ; } -static ssize_t ad5686_read_dac_powerdown (struct device *dev, -struct device_attribute *attr, -char *buf) +static const struct iio_enum ad5686_powerdown_mode_enum = { + .items = ad5686_powerdown_modes, + .num_items =ARRAY_SIZE (ad5686_powerdown_modes), + .get = ad5686_get_powerdown_mode, + .set = ad5686_set_powerdown_mode, +}; + +static ssize_t ad5686_read_dac_powerdown (struct iio_dev *indio_dev, +uintptr_t private,const struct iio_chan_spec *chan,char *buf) { -struct iio_dev *indio_dev =dev_to_iio_dev (dev);struct ad5686_state *st =iio_priv (indio_dev); -struct iio_dev_attr *this_attr =to_iio_dev_attr (attr);return sprintf (buf,"%d\n" , !!(st->pwr_down_mask & - (0x3 << (this_attr->address *2 )))); + (0x3 << (chan->channel *2 )))); } -static ssize_t ad5686_write_dac_powerdown (struct device *dev, -struct device_attribute *attr, -const char *buf,size_t len) +static ssize_t ad5686_write_dac_powerdown (struct iio_dev *indio_dev, +uintptr_t private,const struct iio_chan_spec *chan,const char *buf, +size_t len) {bool readin;int ret; -struct iio_dev *indio_dev =dev_to_iio_dev (dev);struct ad5686_state *st =iio_priv (indio_dev); -struct iio_dev_attr *this_attr =to_iio_dev_attr (attr); ret =strtobool (buf, &readin);if (ret)return ret;if (readin == true) - st->pwr_down_mask |= (0x3 << (this_attr->address *2 )); + st->pwr_down_mask |= (0x3 << (chan->channel *2 ));else - st->pwr_down_mask &= ~(0x3 << (this_attr->address *2 )); + st->pwr_down_mask &= ~(0x3 << (chan->channel *2 )); ret =ad5686_spi_write (st,AD5686_CMD_POWERDOWN_DAC ,0 , st->pwr_down_mask & st->pwr_down_mode,0 );
@@ -244,48 +200,6 @@ static ssize_t ad5686_write_dac_powerdown(struct device *dev,return ret ? ret : len; } -static IIO_CONST_ATTR(out_voltage_powerdown_mode_available, - "1kohm_to_gnd 100kohm_to_gnd three_state"); - -#define IIO_DEV_ATTR_DAC_POWERDOWN_MODE (_num) \ - IIO_DEVICE_ATTR(out_voltage##_num##_powerdown_mode, \ - S_IRUGO | S_IWUSR, \ - ad5686_read_powerdown_mode, \ - ad5686_write_powerdown_mode, _num) - -static IIO_DEV_ATTR_DAC_POWERDOWN_MODE(0); -static IIO_DEV_ATTR_DAC_POWERDOWN_MODE(1); -static IIO_DEV_ATTR_DAC_POWERDOWN_MODE(2); -static IIO_DEV_ATTR_DAC_POWERDOWN_MODE(3); - -#define IIO_DEV_ATTR_DAC_POWERDOWN (_num) \ - IIO_DEVICE_ATTR(out_voltage##_num##_powerdown, \ - S_IRUGO | S_IWUSR, \ - ad5686_read_dac_powerdown, \ - ad5686_write_dac_powerdown, _num) - -static IIO_DEV_ATTR_DAC_POWERDOWN(0); -static IIO_DEV_ATTR_DAC_POWERDOWN(1); -static IIO_DEV_ATTR_DAC_POWERDOWN(2); -static IIO_DEV_ATTR_DAC_POWERDOWN(3); - -static struct attribute *ad5686_attributes[] = { - &iio_dev_attr_out_voltage0_powerdown.dev_attr.attr, - &iio_dev_attr_out_voltage1_powerdown.dev_attr.attr, - &iio_dev_attr_out_voltage2_powerdown.dev_attr.attr, - &iio_dev_attr_out_voltage3_powerdown.dev_attr.attr, - &iio_dev_attr_out_voltage0_powerdown_mode.dev_attr.attr, - &iio_dev_attr_out_voltage1_powerdown_mode.dev_attr.attr, - &iio_dev_attr_out_voltage2_powerdown_mode.dev_attr.attr, - &iio_dev_attr_out_voltage3_powerdown_mode.dev_attr.attr, - &iio_const_attr_out_voltage_powerdown_mode_available.dev_attr.attr, -NULL , -}; - -static const struct attribute_group ad5686_attribute_group = { - .attrs = ad5686_attributes, -}; - static int ad5686_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val,
@@ -349,10 +263,57 @@ static int ad5686_write_raw(struct iio_dev *indio_dev,static const struct iio_info ad5686_info = { .read_raw = ad5686_read_raw, .write_raw = ad5686_write_raw, - .attrs = &ad5686_attribute_group, .driver_module =THIS_MODULE , }; +static const struct iio_chan_spec_ext_info ad5686_ext_info[] = { + { + .name ="powerdown" , + .read = ad5686_read_dac_powerdown, + .write = ad5686_write_dac_powerdown, + }, +IIO_ENUM ("powerdown_mode" , false, &ad5686_powerdown_mode_enum), +IIO_ENUM_AVAILABLE ("powerdown_mode" , &ad5686_powerdown_mode_enum), + { }, +}; + +#define AD5868_CHANNEL (chan, bits, shift) { \ + .type = IIO_VOLTAGE, \ + .indexed = 1, \ + .output = 1, \ + .channel = chan, \ + .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \ + IIO_CHAN_INFO_SCALE_SHARED_BIT, \ + .address = AD5686_ADDR_DAC(chan), \ + .scan_type = IIO_ST('u', bits, 16, shift), \ + .ext_info = ad5686_ext_info, \ +} + +static const struct ad5686_chip_info ad5686_chip_info_tbl[] = { + [ID_AD5684 ] = { + .channel[0 ] =AD5868_CHANNEL (0 ,12 ,4 ), + .channel[1 ] =AD5868_CHANNEL (1 ,12 ,4 ), + .channel[2 ] =AD5868_CHANNEL (2 ,12 ,4 ), + .channel[3 ] =AD5868_CHANNEL (3 ,12 ,4 ), + .int_vref_mv =2500 , + }, + [ID_AD5685 ] = { + .channel[0 ] =AD5868_CHANNEL (0 ,14 ,2 ), + .channel[1 ] =AD5868_CHANNEL (1 ,14 ,2 ), + .channel[2 ] =AD5868_CHANNEL (2 ,14 ,2 ), + .channel[3 ] =AD5868_CHANNEL (3 ,14 ,2 ), + .int_vref_mv =2500 , + }, + [ID_AD5686 ] = { + .channel[0 ] =AD5868_CHANNEL (0 ,16 ,0 ), + .channel[1 ] =AD5868_CHANNEL (1 ,16 ,0 ), + .channel[2 ] =AD5868_CHANNEL (2 ,16 ,0 ), + .channel[3 ] =AD5868_CHANNEL (3 ,16 ,0 ), + .int_vref_mv =2500 , + }, +}; + +static int __devinit ad5686_probe (struct spi_device *spi) {struct ad5686_state *st;
@@ -385,6 +346,9 @@ static int __devinit ad5686_probe(struct spi_device *spi) st->spi = spi; +/* Set all the power down mode for all channels to 1K pulldown */ + st->pwr_down_mode =0x55 ; + indio_dev->dev.parent = &spi->dev; indio_dev->name =spi_get_device_id (spi)->name; indio_dev->info = &ad5686_info;
Signature · 1 line
1.7.10
PATCH 8/18 staging:iio:dac:ad5791: Convert to extended channel attributes
In reply to Lars-Peter ClausenUse extended channel attributes instead of raw sysfs files for the additional channel attributes. This allows us to remove some boilerplate code.
--- drivers/staging/iio/dac/ad5791.c | 122 +++++++++++++++++--------------------- 1 file changed, 53 insertions(+), 69 deletions(-)
drivers/staging/iio/dac/ad5791.c +53 -69
@@ -72,71 +72,50 @@ static int ad5791_spi_read(struct spi_device *spi, u8 addr, u32 *val)return ret; } -#define AD5791_CHAN (bits, shift) { \ - .type = IIO_VOLTAGE, \ - .output = 1, \ - .indexed = 1, \ - .address = AD5791_ADDR_DAC0, \ - .channel = 0, \ - .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \ - IIO_CHAN_INFO_SCALE_SHARED_BIT | \ - IIO_CHAN_INFO_OFFSET_SHARED_BIT, \ - .scan_type = IIO_ST('u', bits, 24, shift) \ -} - -static const struct iio_chan_spec ad5791_channels[] = { - [ID_AD5760 ] =AD5791_CHAN (16 ,4 ), - [ID_AD5780 ] =AD5791_CHAN (18 ,2 ), - [ID_AD5781 ] =AD5791_CHAN (18 ,2 ), - [ID_AD5791 ] =AD5791_CHAN (20 ,0 ) +static const char *const ad5791_powerdown_modes[] = { +"6kohm_to_gnd" , +"three_state" , }; -static ssize_t ad5791_read_powerdown_mode (struct device *dev, -struct device_attribute *attr,char *buf) +static int ad5791_get_powerdown_mode (struct iio_dev *indio_dev, +const struct iio_chan_spec *chan) { -struct iio_dev *indio_dev =dev_to_iio_dev (dev);struct ad5791_state *st =iio_priv (indio_dev); -const char mode[][14 ] = {"6kohm_to_gnd" ,"three_state" }; - -return sprintf (buf,"%s\n" , mode[st->pwr_down_mode]); +return st->pwr_down_mode; } -static ssize_t ad5791_write_powerdown_mode (struct device *dev, -struct device_attribute *attr, -const char *buf,size_t len) +static int ad5791_set_powerdown_mode (struct iio_dev *indio_dev, +const struct iio_chan_spec *chan,unsigned int mode) { -struct iio_dev *indio_dev =dev_to_iio_dev (dev);struct ad5791_state *st =iio_priv (indio_dev); -int ret; -if (sysfs_streq (buf,"6kohm_to_gnd" )) - st->pwr_down_mode =AD5791_DAC_PWRDN_6K ; -else if (sysfs_streq (buf,"three_state" )) - st->pwr_down_mode =AD5791_DAC_PWRDN_3STATE ; -else - ret = -EINVAL ; + st->pwr_down_mode = mode; -return ret ? ret : len; +return 0 ; } -static ssize_t ad5791_read_dac_powerdown (struct device *dev, -struct device_attribute *attr, -char *buf) +static const struct iio_enum ad5791_powerdown_mode_enum = { + .items = ad5791_powerdown_modes, + .num_items =ARRAY_SIZE (ad5791_powerdown_modes), + .get = ad5791_get_powerdown_mode, + .set = ad5791_set_powerdown_mode, +}; + +static ssize_t ad5791_read_dac_powerdown (struct iio_dev *indio_dev, +uintptr_t private,const struct iio_chan_spec *chan,char *buf) { -struct iio_dev *indio_dev =dev_to_iio_dev (dev);struct ad5791_state *st =iio_priv (indio_dev);return sprintf (buf,"%d\n" , st->pwr_down); } -static ssize_t ad5791_write_dac_powerdown (struct device *dev, -struct device_attribute *attr, -const char *buf,size_t len) +static ssize_t ad5791_write_dac_powerdown (struct iio_dev *indio_dev, +uintptr_t private,const struct iio_chan_spec *chan,const char *buf, +size_t len) {long readin;int ret; -struct iio_dev *indio_dev =dev_to_iio_dev (dev);struct ad5791_state *st =iio_priv (indio_dev); ret =strict_strtol (buf,10 , &readin);
@@ -160,31 +139,6 @@ static ssize_t ad5791_write_dac_powerdown(struct device *dev,return ret ? ret : len; } -static IIO_DEVICE_ATTR(out_voltage_powerdown_mode, S_IRUGO | - S_IWUSR, ad5791_read_powerdown_mode, - ad5791_write_powerdown_mode, 0); - -static IIO_CONST_ATTR(out_voltage_powerdown_mode_available, - "6kohm_to_gnd three_state"); - -#define IIO_DEV_ATTR_DAC_POWERDOWN (_num, _show, _store, _addr) \ - IIO_DEVICE_ATTR(out_voltage##_num##_powerdown, \ - S_IRUGO | S_IWUSR, _show, _store, _addr) - -static IIO_DEV_ATTR_DAC_POWERDOWN(0, ad5791_read_dac_powerdown, - ad5791_write_dac_powerdown, 0); - -static struct attribute *ad5791_attributes[] = { - &iio_dev_attr_out_voltage0_powerdown.dev_attr.attr, - &iio_dev_attr_out_voltage_powerdown_mode.dev_attr.attr, - &iio_const_attr_out_voltage_powerdown_mode_available.dev_attr.attr, -NULL , -}; - -static const struct attribute_group ad5791_attribute_group = { - .attrs = ad5791_attributes, -}; -static int ad5791_get_lin_comp (unsigned int span) {if (span <=10000 )
@@ -254,6 +208,37 @@ static int ad5791_read_raw(struct iio_dev *indio_dev, }; +static const struct iio_chan_spec_ext_info ad5791_ext_info[] = { + { + .name ="powerdown" , + .shared = true, + .read = ad5791_read_dac_powerdown, + .write = ad5791_write_dac_powerdown, + }, +IIO_ENUM ("powerdown_mode" , true, &ad5791_powerdown_mode_enum), +IIO_ENUM_AVAILABLE ("powerdown_mode" , &ad5791_powerdown_mode_enum), + { }, +}; + +#define AD5791_CHAN (bits, shift) { \ + .type = IIO_VOLTAGE, \ + .output = 1, \ + .indexed = 1, \ + .address = AD5791_ADDR_DAC0, \ + .channel = 0, \ + .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \ + IIO_CHAN_INFO_SCALE_SHARED_BIT | \ + IIO_CHAN_INFO_OFFSET_SHARED_BIT, \ + .scan_type = IIO_ST('u', bits, 24, shift), \ + .ext_info = ad5791_ext_info, \ +} + +static const struct iio_chan_spec ad5791_channels[] = { + [ID_AD5760 ] =AD5791_CHAN (16 ,4 ), + [ID_AD5780 ] =AD5791_CHAN (18 ,2 ), + [ID_AD5781 ] =AD5791_CHAN (18 ,2 ), + [ID_AD5791 ] =AD5791_CHAN (20 ,0 ) +}; static int ad5791_write_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan,
@@ -278,7 +263,6 @@ static int ad5791_write_raw(struct iio_dev *indio_dev,static const struct iio_info ad5791_info = { .read_raw = &ad5791_read_raw, .write_raw = &ad5791_write_raw, - .attrs = &ad5791_attribute_group, .driver_module =THIS_MODULE , };
Signature · 1 line
1.7.10
PATCH 9/18 staging:iio:dac: Remove unused dac.h includes
In reply to Lars-Peter ClausenNone of these drivers use anything from dac.h, so remove the include.
--- drivers/staging/iio/dac/ad5064.c | 1 - drivers/staging/iio/dac/ad5360.c | 1 - drivers/staging/iio/dac/ad5380.c | 2 -- drivers/staging/iio/dac/ad5421.c | 1 - drivers/staging/iio/dac/ad5446.c | 1 - drivers/staging/iio/dac/ad5504.c | 2 +- drivers/staging/iio/dac/ad5624r_spi.c | 2 +- drivers/staging/iio/dac/ad5686.c | 1 - drivers/staging/iio/dac/ad5764.c | 1 - drivers/staging/iio/dac/ad5791.c | 2 +- 10 files changed, 3 insertions(+), 11 deletions(-)
drivers/staging/iio/dac/ad5064.c +0 -1
@@ -18,7 +18,6 @@#include <linux/iio/iio.h> #include <linux/iio/sysfs.h> -#include "dac.h" #define AD5064_MAX_DAC_CHANNELS 8#define AD5064_MAX_VREFS 4
drivers/staging/iio/dac/ad5360.c +0 -1
@@ -18,7 +18,6 @@#include <linux/iio/iio.h> #include <linux/iio/sysfs.h> -#include "dac.h" #define AD5360_CMD (x) ((x) << 22)#define AD5360_ADDR (x) ((x) << 16)
drivers/staging/iio/dac/ad5380.c +0 -2
@@ -20,8 +20,6 @@#include <linux/iio/iio.h> #include <linux/iio/sysfs.h> -#include "dac.h" -#define AD5380_REG_DATA (x) (((x) << 2) | 3)#define AD5380_REG_OFFSET (x) (((x) << 2) | 2)
drivers/staging/iio/dac/ad5421.c +0 -1
@@ -19,7 +19,6 @@#include <linux/iio/iio.h> #include <linux/iio/sysfs.h> #include <linux/iio/events.h> -#include "dac.h" #include "ad5421.h"
drivers/staging/iio/dac/ad5446.c +0 -1
@@ -20,7 +20,6 @@#include <linux/iio/iio.h> #include <linux/iio/sysfs.h> -#include "dac.h" #include "ad5446.h"
drivers/staging/iio/dac/ad5504.c +1 -1
@@ -19,7 +19,7 @@#include <linux/iio/iio.h> #include <linux/iio/sysfs.h> #include <linux/iio/events.h> -#include "dac.h" +#include "ad5504.h" static int ad5504_spi_write (struct spi_device *spi,u8 addr,u16 val)
drivers/staging/iio/dac/ad5624r_spi.c +1 -1
@@ -18,7 +18,7 @@#include <linux/iio/iio.h> #include <linux/iio/sysfs.h> -#include "dac.h" +#include "ad5624r.h" static int ad5624r_spi_write(struct spi_device *spi,
drivers/staging/iio/dac/ad5686.c +0 -1
@@ -18,7 +18,6 @@#include <linux/iio/iio.h> #include <linux/iio/sysfs.h> -#include "dac.h" #define AD5686_DAC_CHANNELS 4
drivers/staging/iio/dac/ad5764.c +0 -1
@@ -18,7 +18,6 @@#include <linux/iio/iio.h> #include <linux/iio/sysfs.h> -#include "dac.h" #define AD5764_REG_SF_NOP 0x0#define AD5764_REG_SF_CONFIG 0x1
drivers/staging/iio/dac/ad5791.c +1 -1
@@ -19,7 +19,7 @@#include <linux/iio/iio.h> #include <linux/iio/sysfs.h> -#include "dac.h" +#include "ad5791.h" static int ad5791_spi_write (struct spi_device *spi,u8 addr,u32 val)
Signature · 1 line
1.7.10
PATCH 10/18 staging:iio:dac:max517: Convert to channel spec
In reply to Lars-Peter ClausenConvert the max517 driver to channel spec. As part of the conversion the "out_voltage_1&2_raw" property, which updates both channel 1 and 2 simultaneously with the same value, is lost, since this is not really covered by the IIO spec and has only a limited use case in practice.
Also the channel index for the sysfs files is now zero based instead of one based, which means all channes numbers will be lower by one. E.g. "out_voltage_1_scale" instead of "out_voltage_2_scale"
---
Changes since v1:
* Fix a bug which would have caused the channels not to be updated properly. Writes to channel one would have had no effect, writes to channel two would have updated channel one. As part of this the support for updating both channels at once has been removed from max517_set_value since we weren't using that anymore anyway.
--- drivers/staging/iio/dac/max517.c | 172 ++++++++++++++------------------------ 1 file changed, 61 insertions(+), 111 deletions(-)
drivers/staging/iio/dac/max517.c +61 -111
@@ -27,7 +27,6 @@#include <linux/iio/iio.h> #include <linux/iio/sysfs.h> -#include "dac.h" #include "max517.h"
@@ -55,129 +54,67 @@ struct max517_data {* bit 1: channel 2 * (this way, it's possible to set both channels at once) */ -static ssize_t max517_set_value (struct device *dev, -struct device_attribute *attr, -const char *buf,size_t count,int channel) +static int max517_set_value (struct iio_dev *indio_dev, +long val,int channel) { -struct iio_dev *indio_dev =dev_to_iio_dev (dev);struct max517_data *data =iio_priv (indio_dev);struct i2c_client *client = data->client; -u8 outbuf[4 ];/* 1x or 2x command + value */ -int outbuf_size =0 ; +u8 outbuf[2 ];int res; -long val; - - res =strict_strtol (buf,10 , &val); - -if (res) -return res;if (val <0 || val >255 )return -EINVAL ; -if (channel &1 ) { - outbuf[outbuf_size++] =COMMAND_CHANNEL0 ; - outbuf[outbuf_size++] = val; - } -if (channel &2 ) { - outbuf[outbuf_size++] =COMMAND_CHANNEL1 ; - outbuf[outbuf_size++] = val; - } + outbuf[0 ] = channel; + outbuf[1 ] = val; -/* -* At this point, there are always 1 or 2 two-byte commands in -* outbuf. With 2 commands, the device can set two outputs -* simultaneously, latching the values upon the end of the I2C -* transfer. -*/ - - res =i2c_master_send (client, outbuf, outbuf_size); + res =i2c_master_send (client, outbuf,2 );if (res <0 )return res; - -return count; -} - -static ssize_t max517_set_value_1 (struct device *dev, -struct device_attribute *attr, -const char *buf,size_t count) -{ -return max517_set_value (dev, attr, buf, count,1 ); -} -static IIO_DEV_ATTR_OUT_RAW(1, max517_set_value_1, 0); - -static ssize_t max517_set_value_2 (struct device *dev, -struct device_attribute *attr, -const char *buf,size_t count) -{ -return max517_set_value (dev, attr, buf, count,2 ); -} -static IIO_DEV_ATTR_OUT_RAW(2, max517_set_value_2, 1); - -static ssize_t max517_set_value_both (struct device *dev, -struct device_attribute *attr, -const char *buf,size_t count) -{ -return max517_set_value (dev, attr, buf, count,3 ); +else if (res !=2 ) +return -EIO ; +else +return 0 ; } -static IIO_DEVICE_ATTR_NAMED(out_voltage1and2_raw, - out_voltage1&2_raw, S_IWUSR, NULL, - max517_set_value_both, -1); -static ssize_t max517_show_scale (struct device *dev, -struct device_attribute *attr, -char *buf,int channel) +static int max517_read_raw (struct iio_dev *indio_dev, +struct iio_chan_spec const *chan, +int *val, +int *val2, +long m) { -struct iio_dev *indio_dev =dev_to_iio_dev (dev);struct max517_data *data =iio_priv (indio_dev); -/* Corresponds to Vref / 2^(bits) */ -unsigned int scale_uv = (data->vref_mv[channel -1 ] *1000 ) >>8 ; - -return sprintf (buf,"%d.%03d\n" , scale_uv /1000 , scale_uv %1000 ); +unsigned int scale_uv; + +switch (m) { +case IIO_CHAN_INFO_SCALE : +/* Corresponds to Vref / 2^(bits) */ + scale_uv = (data->vref_mv[chan->channel] *1000 ) >>8 ; + *val = scale_uv /1000000 ; + *val2 = scale_uv %1000000 ; +return IIO_VAL_INT_PLUS_MICRO ; +default : +break ; + } +return -EINVAL ; } -static ssize_t max517_show_scale1 (struct device *dev, -struct device_attribute *attr, -char *buf) +static int max517_write_raw (struct iio_dev *indio_dev, +struct iio_chan_spec const *chan,int val,int val2,long mask) { -return max517_show_scale (dev, attr, buf,1 ); -} -static IIO_DEVICE_ATTR(out_voltage1_scale, S_IRUGO, - max517_show_scale1, NULL, 0); +int ret; + +switch (mask) { +case IIO_CHAN_INFO_RAW : + ret =max517_set_value (indio_dev, val, chan->channel); +break ; +default : + ret = -EINVAL ; +break ; + } -static ssize_t max517_show_scale2 (struct device *dev, -struct device_attribute *attr, -char *buf) -{ -return max517_show_scale (dev, attr, buf,2 ); +return ret; } -static IIO_DEVICE_ATTR(out_voltage2_scale, S_IRUGO, - max517_show_scale2, NULL, 0); - -/* On MAX517 variant, we have one output */ -static struct attribute *max517_attributes[] = { - &iio_dev_attr_out_voltage1_raw.dev_attr.attr, - &iio_dev_attr_out_voltage1_scale.dev_attr.attr, -NULL -}; - -static struct attribute_group max517_attribute_group = { - .attrs = max517_attributes, -}; - -/* On MAX518 and MAX519 variant, we have two outputs */ -static struct attribute *max518_attributes[] = { - &iio_dev_attr_out_voltage1_raw.dev_attr.attr, - &iio_dev_attr_out_voltage1_scale.dev_attr.attr, - &iio_dev_attr_out_voltage2_raw.dev_attr.attr, - &iio_dev_attr_out_voltage2_scale.dev_attr.attr, - &iio_dev_attr_out_voltage1and2_raw.dev_attr.attr, -NULL -}; - -static struct attribute_group max518_attribute_group = { - .attrs = max518_attributes, -};#ifdef CONFIG_PM_SLEEP static int max517_suspend (struct device *dev)
@@ -201,13 +138,24 @@ static SIMPLE_DEV_PM_OPS(max517_pm_ops, max517_suspend, max517_resume);#endif static const struct iio_info max517_info = { - .attrs = &max517_attribute_group, + .read_raw = max517_read_raw, + .write_raw = max517_write_raw, .driver_module =THIS_MODULE , }; -static const struct iio_info max518_info = { - .attrs = &max518_attribute_group, - .driver_module =THIS_MODULE , +#define MAX517_CHANNEL (chan) { \ + .type = IIO_VOLTAGE, \ + .indexed = 1, \ + .output = 1, \ + .channel = (chan), \ + .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \ + IIO_CHAN_INFO_SCALE_SEPARATE_BIT, \ + .scan_type = IIO_ST('u', 8, 8, 0), \ +} + +static const struct iio_chan_spec max517_channels[] = { +MAX517_CHANNEL (0 ), +MAX517_CHANNEL (1 ) }; static int max517_probe(struct i2c_client *client,
@@ -230,12 +178,14 @@ static int max517_probe(struct i2c_client *client,/* establish that the iio_dev is a child of the i2c device */ indio_dev->dev.parent = &client->dev; -/* reduced attribute set for MAX517 */ +/* reduced channel set for MAX517 */ if (id->driver_data ==ID_MAX517 ) - indio_dev->info = &max517_info; + indio_dev->num_channels =1 ;else - indio_dev->info = &max518_info; + indio_dev->num_channels =2 ; + indio_dev->channels = max517_channels; indio_dev->modes =INDIO_DIRECT_MODE ; + indio_dev->info = &max517_info;/* * Reference voltage on MAX518 and default is 5V, else take vref_mv
Signature · 1 line
1.7.10
Re: [PATCH 10/18] staging:iio:dac:max517: Convert to channel spec
Quoted 5 lines · Lars-Peter Clausen
Convert the max517 driver to channel spec. As part of the conversion the "out_voltage_1&2_raw" property, which updates both channel 1 and 2 simultaneously with the same value, is lost, since this is not really covered by the IIO spec and has only a limited use case in practice.
Quoted 7 lines
Also the channel index for the sysfs files is now zero based instead of one based, which means all channes numbers will be lower by one. E.g. "
out_voltage_1_scale" instead of "out_voltage_2_scale"Signed-off-by Lars-Peter Clausen <[email protected]>Cc Roland Stigge <[email protected]>Acked-by Jonathan Cameron <[email protected]>
Hi Roland,
Any chance to get a Acked-by from you for this patch
Thanks,
- Lars
Quoted 241 lines
---
Changes since v1:
* Fix a bug which would have caused the channels not to be updated properly. Writes to channel one would have had no effect, writes to channel two would have updated channel one. As part of this the support for updating both channels at once has been removed frommax517_set_valuesince we weren't using that anymore anyway.--- drivers/staging/iio/dac/max517.c | 172 ++++++++++++++------------------------ 1 file changed, 61 insertions(+), 111 deletions(-)drivers/staging/iio/dac/max517.c +61
-111@@ -27,7 +27,6 @@#include <linux/iio/iio.h> #include <linux/iio/sysfs.h> -#include "dac.h" #include "max517.h" @@ -55,129 +54,67 @@ struct max517_data {* bit 1: channel 2 * (this way, it's possible to set both channels at once) */ -static ssize_t max517_set_value (struct device *dev, -struct device_attribute *attr, -const char *buf,size_t count,int channel) +static int max517_set_value (struct iio_dev *indio_dev, +long val,int channel) { -struct iio_dev *indio_dev =dev_to_iio_dev (dev);struct max517_data *data =iio_priv (indio_dev);struct i2c_client *client = data->client; -u8 outbuf[4 ];/* 1x or 2x command + value */ -int outbuf_size =0 ; +u8 outbuf[2 ];int res; -long val; - - res =strict_strtol (buf,10 , &val); - -if (res) -return res;if (val <0 || val >255 )return -EINVAL ; -if (channel &1 ) { - outbuf[outbuf_size++] =COMMAND_CHANNEL0 ; - outbuf[outbuf_size++] = val; - } -if (channel &2 ) { - outbuf[outbuf_size++] =COMMAND_CHANNEL1 ; - outbuf[outbuf_size++] = val; - } + outbuf[0 ] = channel; + outbuf[1 ] = val; -/* -* At this point, there are always 1 or 2 two-byte commands in -* outbuf. With 2 commands, the device can set two outputs -* simultaneously, latching the values upon the end of the I2C -* transfer. -*/ - - res =i2c_master_send (client, outbuf, outbuf_size); + res =i2c_master_send (client, outbuf,2 );if (res <0 )return res; - -return count; -} - -static ssize_t max517_set_value_1 (struct device *dev, -struct device_attribute *attr, -const char *buf,size_t count) -{ -return max517_set_value (dev, attr, buf, count,1 ); -} -static IIO_DEV_ATTR_OUT_RAW(1, max517_set_value_1, 0); - -static ssize_t max517_set_value_2 (struct device *dev, -struct device_attribute *attr, -const char *buf,size_t count) -{ -return max517_set_value (dev, attr, buf, count,2 ); -} -static IIO_DEV_ATTR_OUT_RAW(2, max517_set_value_2, 1); - -static ssize_t max517_set_value_both (struct device *dev, -struct device_attribute *attr, -const char *buf,size_t count) -{ -return max517_set_value (dev, attr, buf, count,3 ); +else if (res !=2 ) +return -EIO ; +else +return 0 ; } -static IIO_DEVICE_ATTR_NAMED(out_voltage1and2_raw, - out_voltage1&2_raw, S_IWUSR, NULL, - max517_set_value_both, -1); -static ssize_t max517_show_scale (struct device *dev, -struct device_attribute *attr, -char *buf,int channel) +static int max517_read_raw (struct iio_dev *indio_dev, +struct iio_chan_spec const *chan, +int *val, +int *val2, +long m) { -struct iio_dev *indio_dev =dev_to_iio_dev (dev);struct max517_data *data =iio_priv (indio_dev); -/* Corresponds to Vref / 2^(bits) */ -unsigned int scale_uv = (data->vref_mv[channel -1 ] *1000 ) >>8 ; - -return sprintf (buf,"%d.%03d\n" , scale_uv /1000 , scale_uv %1000 ); +unsigned int scale_uv; + +switch (m) { +case IIO_CHAN_INFO_SCALE : +/* Corresponds to Vref / 2^(bits) */ + scale_uv = (data->vref_mv[chan->channel] *1000 ) >>8 ; + *val = scale_uv /1000000 ; + *val2 = scale_uv %1000000 ; +return IIO_VAL_INT_PLUS_MICRO ; +default : +break ; + } +return -EINVAL ; } -static ssize_t max517_show_scale1 (struct device *dev, -struct device_attribute *attr, -char *buf) +static int max517_write_raw (struct iio_dev *indio_dev, +struct iio_chan_spec const *chan,int val,int val2,long mask) { -return max517_show_scale (dev, attr, buf,1 ); -} -static IIO_DEVICE_ATTR(out_voltage1_scale, S_IRUGO, - max517_show_scale1, NULL, 0); +int ret; + +switch (mask) { +case IIO_CHAN_INFO_RAW : + ret =max517_set_value (indio_dev, val, chan->channel); +break ; +default : + ret = -EINVAL ; +break ; + } -static ssize_t max517_show_scale2 (struct device *dev, -struct device_attribute *attr, -char *buf) -{ -return max517_show_scale (dev, attr, buf,2 ); +return ret; } -static IIO_DEVICE_ATTR(out_voltage2_scale, S_IRUGO, - max517_show_scale2, NULL, 0); - -/* On MAX517 variant, we have one output */ -static struct attribute *max517_attributes[] = { - &iio_dev_attr_out_voltage1_raw.dev_attr.attr, - &iio_dev_attr_out_voltage1_scale.dev_attr.attr, -NULL -}; - -static struct attribute_group max517_attribute_group = { - .attrs = max517_attributes, -}; - -/* On MAX518 and MAX519 variant, we have two outputs */ -static struct attribute *max518_attributes[] = { - &iio_dev_attr_out_voltage1_raw.dev_attr.attr, - &iio_dev_attr_out_voltage1_scale.dev_attr.attr, - &iio_dev_attr_out_voltage2_raw.dev_attr.attr, - &iio_dev_attr_out_voltage2_scale.dev_attr.attr, - &iio_dev_attr_out_voltage1and2_raw.dev_attr.attr, -NULL -}; - -static struct attribute_group max518_attribute_group = { - .attrs = max518_attributes, -};#ifdef CONFIG_PM_SLEEP static int max517_suspend (struct device *dev)@@ -201,13 +138,24 @@ static SIMPLE_DEV_PM_OPS(max517_pm_ops, max517_suspend, max517_resume);#endif static const struct iio_info max517_info = { - .attrs = &max517_attribute_group, + .read_raw = max517_read_raw, + .write_raw = max517_write_raw, .driver_module =THIS_MODULE , }; -static const struct iio_info max518_info = { - .attrs = &max518_attribute_group, - .driver_module =THIS_MODULE , +#define MAX517_CHANNEL (chan) { \ + .type = IIO_VOLTAGE, \ + .indexed = 1, \ + .output = 1, \ + .channel = (chan), \ + .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \ + IIO_CHAN_INFO_SCALE_SEPARATE_BIT, \ + .scan_type = IIO_ST('u', 8, 8, 0), \ +} + +static const struct iio_chan_spec max517_channels[] = { +MAX517_CHANNEL (0 ), +MAX517_CHANNEL (1 ) }; static int max517_probe(struct i2c_client *client,@@ -230,12 +178,14 @@ static int max517_probe(struct i2c_client *client,/* establish that the iio_dev is a child of the i2c device */ indio_dev->dev.parent = &client->dev; -/* reduced attribute set for MAX517 */ +/* reduced channel set for MAX517 */ if (id->driver_data ==ID_MAX517 ) - indio_dev->info = &max517_info; + indio_dev->num_channels =1 ;else - indio_dev->info = &max518_info; + indio_dev->num_channels =2 ; + indio_dev->channels = max517_channels; indio_dev->modes =INDIO_DIRECT_MODE ; + indio_dev->info = &max517_info;/* * Reference voltage on MAX518 and default is 5V, else take vref_mv
Re: [PATCH 10/18] staging:iio:dac:max517: Convert to channel spec
In reply to Lars-Peter ClausenQuoted 5 lines · Lars-Peter Clausen
Convert the max517 driver to channel spec. As part of the conversion the "out_voltage_1&2_raw" property, which updates both channel 1 and 2 simultaneously with the same value, is lost, since this is not really covered by the IIO spec and has only a limited use case in practice.
Quoted 7 lines
Also the channel index for the sysfs files is now zero based instead of one based, which means all channes numbers will be lower by one. E.g. "
out_voltage_1_scale" instead of "out_voltage_2_scale"Signed-off-by Lars-Peter Clausen <[email protected]>Cc Roland Stigge <[email protected]>Acked-by Jonathan Cameron <[email protected]>
Quoted 241 lines
---
Changes since v1:
* Fix a bug which would have caused the channels not to be updated properly. Writes to channel one would have had no effect, writes to channel two would have updated channel one. As part of this the support for updating both channels at once has been removed frommax517_set_valuesince we weren't using that anymore anyway.--- drivers/staging/iio/dac/max517.c | 172 ++++++++++++++------------------------ 1 file changed, 61 insertions(+), 111 deletions(-)drivers/staging/iio/dac/max517.c +61
-111@@ -27,7 +27,6 @@#include <linux/iio/iio.h> #include <linux/iio/sysfs.h> -#include "dac.h" #include "max517.h" @@ -55,129 +54,67 @@ struct max517_data {* bit 1: channel 2 * (this way, it's possible to set both channels at once) */ -static ssize_t max517_set_value (struct device *dev, -struct device_attribute *attr, -const char *buf,size_t count,int channel) +static int max517_set_value (struct iio_dev *indio_dev, +long val,int channel) { -struct iio_dev *indio_dev =dev_to_iio_dev (dev);struct max517_data *data =iio_priv (indio_dev);struct i2c_client *client = data->client; -u8 outbuf[4 ];/* 1x or 2x command + value */ -int outbuf_size =0 ; +u8 outbuf[2 ];int res; -long val; - - res =strict_strtol (buf,10 , &val); - -if (res) -return res;if (val <0 || val >255 )return -EINVAL ; -if (channel &1 ) { - outbuf[outbuf_size++] =COMMAND_CHANNEL0 ; - outbuf[outbuf_size++] = val; - } -if (channel &2 ) { - outbuf[outbuf_size++] =COMMAND_CHANNEL1 ; - outbuf[outbuf_size++] = val; - } + outbuf[0 ] = channel; + outbuf[1 ] = val; -/* -* At this point, there are always 1 or 2 two-byte commands in -* outbuf. With 2 commands, the device can set two outputs -* simultaneously, latching the values upon the end of the I2C -* transfer. -*/ - - res =i2c_master_send (client, outbuf, outbuf_size); + res =i2c_master_send (client, outbuf,2 );if (res <0 )return res; - -return count; -} - -static ssize_t max517_set_value_1 (struct device *dev, -struct device_attribute *attr, -const char *buf,size_t count) -{ -return max517_set_value (dev, attr, buf, count,1 ); -} -static IIO_DEV_ATTR_OUT_RAW(1, max517_set_value_1, 0); - -static ssize_t max517_set_value_2 (struct device *dev, -struct device_attribute *attr, -const char *buf,size_t count) -{ -return max517_set_value (dev, attr, buf, count,2 ); -} -static IIO_DEV_ATTR_OUT_RAW(2, max517_set_value_2, 1); - -static ssize_t max517_set_value_both (struct device *dev, -struct device_attribute *attr, -const char *buf,size_t count) -{ -return max517_set_value (dev, attr, buf, count,3 ); +else if (res !=2 ) +return -EIO ; +else +return 0 ; } -static IIO_DEVICE_ATTR_NAMED(out_voltage1and2_raw, - out_voltage1&2_raw, S_IWUSR, NULL, - max517_set_value_both, -1); -static ssize_t max517_show_scale (struct device *dev, -struct device_attribute *attr, -char *buf,int channel) +static int max517_read_raw (struct iio_dev *indio_dev, +struct iio_chan_spec const *chan, +int *val, +int *val2, +long m) { -struct iio_dev *indio_dev =dev_to_iio_dev (dev);struct max517_data *data =iio_priv (indio_dev); -/* Corresponds to Vref / 2^(bits) */ -unsigned int scale_uv = (data->vref_mv[channel -1 ] *1000 ) >>8 ; - -return sprintf (buf,"%d.%03d\n" , scale_uv /1000 , scale_uv %1000 ); +unsigned int scale_uv; + +switch (m) { +case IIO_CHAN_INFO_SCALE : +/* Corresponds to Vref / 2^(bits) */ + scale_uv = (data->vref_mv[chan->channel] *1000 ) >>8 ; + *val = scale_uv /1000000 ; + *val2 = scale_uv %1000000 ; +return IIO_VAL_INT_PLUS_MICRO ; +default : +break ; + } +return -EINVAL ; } -static ssize_t max517_show_scale1 (struct device *dev, -struct device_attribute *attr, -char *buf) +static int max517_write_raw (struct iio_dev *indio_dev, +struct iio_chan_spec const *chan,int val,int val2,long mask) { -return max517_show_scale (dev, attr, buf,1 ); -} -static IIO_DEVICE_ATTR(out_voltage1_scale, S_IRUGO, - max517_show_scale1, NULL, 0); +int ret; + +switch (mask) { +case IIO_CHAN_INFO_RAW : + ret =max517_set_value (indio_dev, val, chan->channel); +break ; +default : + ret = -EINVAL ; +break ; + } -static ssize_t max517_show_scale2 (struct device *dev, -struct device_attribute *attr, -char *buf) -{ -return max517_show_scale (dev, attr, buf,2 ); +return ret; } -static IIO_DEVICE_ATTR(out_voltage2_scale, S_IRUGO, - max517_show_scale2, NULL, 0); - -/* On MAX517 variant, we have one output */ -static struct attribute *max517_attributes[] = { - &iio_dev_attr_out_voltage1_raw.dev_attr.attr, - &iio_dev_attr_out_voltage1_scale.dev_attr.attr, -NULL -}; - -static struct attribute_group max517_attribute_group = { - .attrs = max517_attributes, -}; - -/* On MAX518 and MAX519 variant, we have two outputs */ -static struct attribute *max518_attributes[] = { - &iio_dev_attr_out_voltage1_raw.dev_attr.attr, - &iio_dev_attr_out_voltage1_scale.dev_attr.attr, - &iio_dev_attr_out_voltage2_raw.dev_attr.attr, - &iio_dev_attr_out_voltage2_scale.dev_attr.attr, - &iio_dev_attr_out_voltage1and2_raw.dev_attr.attr, -NULL -}; - -static struct attribute_group max518_attribute_group = { - .attrs = max518_attributes, -};#ifdef CONFIG_PM_SLEEP static int max517_suspend (struct device *dev)@@ -201,13 +138,24 @@ static SIMPLE_DEV_PM_OPS(max517_pm_ops, max517_suspend, max517_resume);#endif static const struct iio_info max517_info = { - .attrs = &max517_attribute_group, + .read_raw = max517_read_raw, + .write_raw = max517_write_raw, .driver_module =THIS_MODULE , }; -static const struct iio_info max518_info = { - .attrs = &max518_attribute_group, - .driver_module =THIS_MODULE , +#define MAX517_CHANNEL (chan) { \ + .type = IIO_VOLTAGE, \ + .indexed = 1, \ + .output = 1, \ + .channel = (chan), \ + .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \ + IIO_CHAN_INFO_SCALE_SEPARATE_BIT, \ + .scan_type = IIO_ST('u', 8, 8, 0), \ +} + +static const struct iio_chan_spec max517_channels[] = { +MAX517_CHANNEL (0 ), +MAX517_CHANNEL (1 ) }; static int max517_probe(struct i2c_client *client,@@ -230,12 +178,14 @@ static int max517_probe(struct i2c_client *client,/* establish that the iio_dev is a child of the i2c device */ indio_dev->dev.parent = &client->dev; -/* reduced attribute set for MAX517 */ +/* reduced channel set for MAX517 */ if (id->driver_data ==ID_MAX517 ) - indio_dev->info = &max517_info; + indio_dev->num_channels =1 ;else - indio_dev->info = &max518_info; + indio_dev->num_channels =2 ; + indio_dev->channels = max517_channels; indio_dev->modes =INDIO_DIRECT_MODE ; + indio_dev->info = &max517_info;/* * Reference voltage on MAX518 and default is 5V, else take vref_mv
PATCH 11/18 staging:iio:dac: Remove dac.h
In reply to Lars-Peter ClausenNow that all drivers have been converted to channel spec, we can finally remove the dac.h file since it is no longer used.
--- drivers/staging/iio/dac/dac.h | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 drivers/staging/iio/dac/dac.h
drivers/staging/iio/dac/dac.h deleted +0 -6
@@ -1,6 +0,0 @@ -/* -* dac.h - sysfs attributes associated with DACs -*/ - -#define IIO_DEV_ATTR_OUT_RAW (_num, _store, _addr) \ - IIO_DEVICE_ATTR(out_voltage##_num##_raw, S_IWUSR, NULL, _store, _addr)
Signature · 1 line
1.7.10
PATCH 12/18 staging:iio:dac:ad5504: Use strtobool for boolean values
In reply to Lars-Peter ClausenUse strtobool for parsing the powerdown value instead of strict_strtol, since the powerdown attribute is a boolean value.
--- drivers/staging/iio/dac/ad5504.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/staging/iio/dac/ad5504.c +4 -6
@@ -147,20 +147,18 @@ static ssize_t ad5504_write_dac_powerdown(struct iio_dev *indio_dev, uintptr_t private, const struct iio_chan_spec *chan, const char *buf, size_t len) { - long readin; + bool pwr_down;int ret;struct ad5504_state *st =iio_priv (indio_dev); - ret =strict_strtol (buf,10 , &readin); + ret =strtobool (buf, &pwr_down);if (ret)return ret; -if (readin ==0 ) +if (pwr_down) st->pwr_down_mask |= (1 << chan->channel); -else if (readin ==1 ) - st->pwr_down_mask &= ~(1 << chan->channel);else - ret = -EINVAL ; + st->pwr_down_mask &= ~(1 << chan->channel); ret = ad5504_spi_write(st->spi, AD5504_ADDR_CTRL, AD5504_DAC_PWRDWN_MODE(st->pwr_down_mode) |
Signature · 1 line
1.7.10
PATCH 13/18 staging:iio:dac:ad5624r: Use strtobool for boolean values
In reply to Lars-Peter ClausenUse strtobool for parsing the powerdown value instead of strict_strtol, since the powerdown attribute is a boolean value.
--- drivers/staging/iio/dac/ad5624r_spi.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/staging/iio/dac/ad5624r_spi.c +4 -6
@@ -132,20 +132,18 @@ static ssize_t ad5624r_write_dac_powerdown(struct iio_dev *indio_dev, uintptr_t private, const struct iio_chan_spec *chan, const char *buf, size_t len) { - long readin; + bool pwr_down;int ret;struct ad5624r_state *st =iio_priv (indio_dev); - ret =strict_strtol (buf,10 , &readin); + ret =strtobool (buf, &pwr_down);if (ret)return ret; -if (readin ==1 ) +if (pwr_down) st->pwr_down_mask |= (1 << chan->channel); -else if (!readin) - st->pwr_down_mask &= ~(1 << chan->channel);else - ret = -EINVAL ; + st->pwr_down_mask &= ~(1 << chan->channel); ret = ad5624r_spi_write(st->us, AD5624R_CMD_POWERDOWN_DAC, 0, (st->pwr_down_mode << 4) |
Signature · 1 line
1.7.10
PATCH 14/18 staging:iio:dac:ad5791: Use strtobool for boolean values
In reply to Lars-Peter ClausenUse strtobool for parsing the powerdown value instead of strict_strtol, since the powerdown attribute is a boolean value.
--- drivers/staging/iio/dac/ad5791.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
drivers/staging/iio/dac/ad5791.c +6 -8
@@ -114,25 +114,23 @@ static ssize_t ad5791_write_dac_powerdown(struct iio_dev *indio_dev, uintptr_t private, const struct iio_chan_spec *chan, const char *buf, size_t len) { - long readin; + bool pwr_down;int ret;struct ad5791_state *st =iio_priv (indio_dev); - ret =strict_strtol (buf,10 , &readin); + ret =strtobool (buf, &pwr_down);if (ret)return ret; -if (readin ==0 ) { - st->pwr_down = false; +if (!pwr_down) { st->ctrl &= ~(AD5791_CTRL_OPGND |AD5791_CTRL_DACTRI ); - }else if (readin ==1 ) { - st->pwr_down = true; + }else {if (st->pwr_down_mode ==AD5791_DAC_PWRDN_6K ) st->ctrl |=AD5791_CTRL_OPGND ;else if (st->pwr_down_mode ==AD5791_DAC_PWRDN_3STATE ) st->ctrl |=AD5791_CTRL_DACTRI ; - }else - ret = -EINVAL ; + } + st->pwr_down = pwr_down; ret =ad5791_spi_write (st->spi,AD5791_ADDR_CTRL , st->ctrl);
Signature · 1 line
1.7.10
PATCH 15/18 staging:iio:dac:ad5504: Check if IRQ was requested before freeing it
In reply to Lars-Peter ClausenIRQ support is optional, so we have to check whether it was actually requested before we attempt to free it.
--- drivers/staging/iio/dac/ad5504.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/staging/iio/dac/ad5504.c +2 -1
@@ -294,7 +294,8 @@ static int __devinit ad5504_probe(struct spi_device *spi)return 0 ; error_free_irq: -free_irq (spi->irq, indio_dev); +if (spi->irq) +free_irq (spi->irq, indio_dev); error_disable_reg:if (!IS_ERR (reg))regulator_disable (reg);
Signature · 1 line
1.7.10
PATCH 16/18 staging:iio:dac:ad5504: Move private structs and defines from header to C file
In reply to Lars-Peter ClausenThe header for this driver contains some private structs and defines, which do not have to be shared between multiple source files, as well as the platform data struct for this driver, which has to be shared with other source files. Since there is no need to expose those private structs and defines move them to the source file.
--- drivers/staging/iio/dac/ad5504.c | 45 ++++++++++++++++++++++++++++++++++++++ drivers/staging/iio/dac/ad5504.h | 45 -------------------------------------- 2 files changed, 45 insertions(+), 45 deletions(-)
drivers/staging/iio/dac/ad5504.c +45 -0
@@ -22,6 +22,51 @@#include "ad5504.h" +#define AD5505_BITS 12 +#define AD5504_RES_MASK ((1 << (AD5505_BITS)) - 1) + +#define AD5504_CMD_READ (1 << 15) +#define AD5504_CMD_WRITE (0 << 15) +#define AD5504_ADDR (addr) ((addr) << 12) + +/* Registers */ +#define AD5504_ADDR_NOOP 0 +#define AD5504_ADDR_DAC (x) ((x) + 1) +#define AD5504_ADDR_ALL_DAC 5 +#define AD5504_ADDR_CTRL 7 + +/* Control Register */ +#define AD5504_DAC_PWR (ch) ((ch) << 2) +#define AD5504_DAC_PWRDWN_MODE (mode) ((mode) << 6) +#define AD5504_DAC_PWRDN_20K 0 +#define AD5504_DAC_PWRDN_3STATE 1 + +/** +* struct ad5446_state - driver instance specific data +* @us: spi_device +* @reg: supply regulator +* @vref_mv: actual reference voltage used +* @pwr_down_mask power down mask +* @pwr_down_mode current power down mode +*/ + +struct ad5504_state { +struct spi_device *spi; +struct regulator *reg; +unsigned short vref_mv; +unsigned pwr_down_mask; +unsigned pwr_down_mode; +}; + +/** +* ad5504_supported_device_ids: +*/ + +enum ad5504_supported_device_ids { +ID_AD5504 , +ID_AD5501 , +}; +static int ad5504_spi_write (struct spi_device *spi,u8 addr,u16 val) { u16 tmp = cpu_to_be16(AD5504_CMD_WRITE |
drivers/staging/iio/dac/ad5504.h +0 -45
55 lines not on this page · raw message
Signature · 1 line
1.7.10
Re: [PATCH 16/18] staging:iio:dac:ad5504: Move private structs and defines from header to C file
Quoted 5 lines · Lars-Peter Clausen
The header for this driver contains some private structs and defines, which do not have to be shared between multiple source files, as well as the platform data struct for this driver, which has to be shared with other source files. Since there is no need to expose those private structs and defines move them to the source file.
Sensible. Minor suggestion inline.
Quoted 2 lines
Signed-off-by Lars-Peter Clausen <[email protected]>
Quoted 30 lines
--- drivers/staging/iio/dac/ad5504.c | 45 ++++++++++++++++++++++++++++++++++++++ drivers/staging/iio/dac/ad5504.h | 45 -------------------------------------- 2 files changed, 45 insertions(+), 45 deletions(-)drivers/staging/iio/dac/ad5504.c +17
-0@@ -22,6 +22,51 @@#include "ad5504.h" +#define AD5505_BITS 12 +#define AD5504_RES_MASK ((1 << (AD5505_BITS)) - 1) + +#define AD5504_CMD_READ (1 << 15) +#define AD5504_CMD_WRITE (0 << 15) +#define AD5504_ADDR (addr) ((addr) << 12) + +/* Registers */ +#define AD5504_ADDR_NOOP 0 +#define AD5504_ADDR_DAC (x) ((x) + 1) +#define AD5504_ADDR_ALL_DAC 5 +#define AD5504_ADDR_CTRL 7 + +/* Control Register */ +#define AD5504_DAC_PWR (ch) ((ch) << 2) +#define AD5504_DAC_PWRDWN_MODE (mode) ((mode) << 6) +#define AD5504_DAC_PWRDN_20K 0
drivers/staging/iio/dac/ad5504.c line 51
Quoted 10 lines
drivers/staging/iio/dac/ad5504.c +10
-0+#define AD5504_DAC_PWRDN_3STATE 1 + +/** +* struct ad5446_state - driver instance specific data +* @us: spi_device +* @reg: supply regulator +* @vref_mv: actual reference voltage used +* @pwr_down_mask power down mask +* @pwr_down_mode current power down mode +*/
If we are being fussy, isn't convention no blank line here?
Quoted 82 lines
drivers/staging/iio/dac/ad5504.c +18
-0+ +struct ad5504_state { +struct spi_device *spi; +struct regulator *reg; +unsigned short vref_mv; +unsigned pwr_down_mask; +unsigned pwr_down_mode; +}; + +/** +* ad5504_supported_device_ids: +*/ + +enum ad5504_supported_device_ids { +ID_AD5504 , +ID_AD5501 , +}; +static int ad5504_spi_write (struct spi_device *spi,u8 addr,u16 val) { u16 tmp = cpu_to_be16(AD5504_CMD_WRITE |drivers/staging/iio/dac/ad5504.h +0
-45@@ -9,25 +9,6 @@#ifndef SPI_AD5504_H_ #define SPI_AD5504_H_ -#define AD5505_BITS 12 -#define AD5504_RES_MASK ((1 << (AD5505_BITS)) - 1) - -#define AD5504_CMD_READ (1 << 15) -#define AD5504_CMD_WRITE (0 << 15) -#define AD5504_ADDR (addr) ((addr) << 12) - -/* Registers */ -#define AD5504_ADDR_NOOP 0 -#define AD5504_ADDR_DAC (x) ((x) + 1) -#define AD5504_ADDR_ALL_DAC 5 -#define AD5504_ADDR_CTRL 7 - -/* Control Register */ -#define AD5504_DAC_PWR (ch) ((ch) << 2) -#define AD5504_DAC_PWRDWN_MODE (mode) ((mode) << 6) -#define AD5504_DAC_PWRDN_20K 0 -#define AD5504_DAC_PWRDN_3STATE 1 -/* * TODO: struct ad5504_platform_data needs to go into include/linux/iio */ @@ -36,30 +17,4 @@ struct ad5504_platform_data { u16 vref_mv; }; -/** -* struct ad5446_state - driver instance specific data -* @us: spi_device -* @reg: supply regulator -* @vref_mv: actual reference voltage used -* @pwr_down_mask power down mask -* @pwr_down_mode current power down mode -*/ - -struct ad5504_state { -struct spi_device *spi; -struct regulator *reg; -unsigned short vref_mv; -unsigned pwr_down_mask; -unsigned pwr_down_mode; -}; - -/** -* ad5504_supported_device_ids: -*/ - -enum ad5504_supported_device_ids { -ID_AD5504 , -ID_AD5501 , -}; -#endif /* SPI_AD5504_H_ */
PATCH 17/18 staging:iio:dac:ad5791: Move private structs and defines from header to C file
In reply to Lars-Peter ClausenThe header for this driver contains some private structs and defines, which do not have to be shared between multiple source files, as well as the platform data struct for this driver, which has to be shared with other source files. Since there is no need to expose those private structs and defines move them to the source file.
--- drivers/staging/iio/dac/ad5791.c | 83 ++++++++++++++++++++++++++++++++++++++ drivers/staging/iio/dac/ad5791.h | 83 -------------------------------------- 2 files changed, 83 insertions(+), 83 deletions(-)
drivers/staging/iio/dac/ad5791.c +83 -0
@@ -22,6 +22,89 @@#include "ad5791.h" +#define AD5791_RES_MASK (x) ((1 << (x)) - 1) +#define AD5791_DAC_MASK AD5791_RES_MASK(20) +#define AD5791_DAC_MSB (1 << 19) + +#define AD5791_CMD_READ (1 << 23) +#define AD5791_CMD_WRITE (0 << 23) +#define AD5791_ADDR (addr) ((addr) << 20) + +/* Registers */ +#define AD5791_ADDR_NOOP 0 +#define AD5791_ADDR_DAC0 1 +#define AD5791_ADDR_CTRL 2 +#define AD5791_ADDR_CLRCODE 3 +#define AD5791_ADDR_SW_CTRL 4 + +/* Control Register */ +#define AD5791_CTRL_RBUF (1 << 1) +#define AD5791_CTRL_OPGND (1 << 2) +#define AD5791_CTRL_DACTRI (1 << 3) +#define AD5791_CTRL_BIN2SC (1 << 4) +#define AD5791_CTRL_SDODIS (1 << 5) +#define AD5761_CTRL_LINCOMP (x) ((x) << 6) + +#define AD5791_LINCOMP_0_10 0 +#define AD5791_LINCOMP_10_12 1 +#define AD5791_LINCOMP_12_16 2 +#define AD5791_LINCOMP_16_19 3 +#define AD5791_LINCOMP_19_20 12 + +#define AD5780_LINCOMP_0_10 0 +#define AD5780_LINCOMP_10_20 12 + +/* Software Control Register */ +#define AD5791_SWCTRL_LDAC (1 << 0) +#define AD5791_SWCTRL_CLR (1 << 1) +#define AD5791_SWCTRL_RESET (1 << 2) + +#define AD5791_DAC_PWRDN_6K 0 +#define AD5791_DAC_PWRDN_3STATE 1 + +/** +* struct ad5791_chip_info - chip specific information +* @get_lin_comp: function pointer to the device specific function +*/ + +struct ad5791_chip_info { +int (*get_lin_comp) (unsigned int span); +}; + +/** +* struct ad5791_state - driver instance specific data +* @us: spi_device +* @reg_vdd: positive supply regulator +* @reg_vss: negative supply regulator +* @chip_info: chip model specific constants +* @vref_mv: actual reference voltage used +* @vref_neg_mv: voltage of the negative supply +* @pwr_down_mode current power down mode +*/ + +struct ad5791_state { +struct spi_device *spi; +struct regulator *reg_vdd; +struct regulator *reg_vss; +const struct ad5791_chip_info *chip_info; +unsigned short vref_mv; +unsigned int vref_neg_mv; +unsigned ctrl; +unsigned pwr_down_mode; +bool pwr_down; +}; + +/** +* ad5791_supported_device_ids: +*/ + +enum ad5791_supported_device_ids { +ID_AD5760 , +ID_AD5780 , +ID_AD5781 , +ID_AD5791 , +}; +static int ad5791_spi_write (struct spi_device *spi,u8 addr,u32 val) {union {
drivers/staging/iio/dac/ad5791.h +0 -83
93 lines not on this page · raw message
Signature · 1 line
1.7.10
Re: [PATCH 17/18] staging:iio:dac:ad5791: Move private structs and defines from header to C file
Quoted 5 lines · Lars-Peter Clausen
The header for this driver contains some private structs and defines, which do not have to be shared between multiple source files, as well as the platform data struct for this driver, which has to be shared with other source files. Since there is no need to expose those private structs and defines move them to the source file.
Another sensible move. Same comment applies as previous. Feel free to ignore as then you have a straight move of lines which may be clearer.
Quoted 2 lines
Signed-off-by Lars-Peter Clausen <[email protected]>
Quoted 198 lines
--- drivers/staging/iio/dac/ad5791.c | 83 ++++++++++++++++++++++++++++++++++++++ drivers/staging/iio/dac/ad5791.h | 83 -------------------------------------- 2 files changed, 83 insertions(+), 83 deletions(-)drivers/staging/iio/dac/ad5791.c +83
-0@@ -22,6 +22,89 @@#include "ad5791.h" +#define AD5791_RES_MASK (x) ((1 << (x)) - 1) +#define AD5791_DAC_MASK AD5791_RES_MASK(20) +#define AD5791_DAC_MSB (1 << 19) + +#define AD5791_CMD_READ (1 << 23) +#define AD5791_CMD_WRITE (0 << 23) +#define AD5791_ADDR (addr) ((addr) << 20) + +/* Registers */ +#define AD5791_ADDR_NOOP 0 +#define AD5791_ADDR_DAC0 1 +#define AD5791_ADDR_CTRL 2 +#define AD5791_ADDR_CLRCODE 3 +#define AD5791_ADDR_SW_CTRL 4 + +/* Control Register */ +#define AD5791_CTRL_RBUF (1 << 1) +#define AD5791_CTRL_OPGND (1 << 2) +#define AD5791_CTRL_DACTRI (1 << 3) +#define AD5791_CTRL_BIN2SC (1 << 4) +#define AD5791_CTRL_SDODIS (1 << 5) +#define AD5761_CTRL_LINCOMP (x) ((x) << 6) + +#define AD5791_LINCOMP_0_10 0 +#define AD5791_LINCOMP_10_12 1 +#define AD5791_LINCOMP_12_16 2 +#define AD5791_LINCOMP_16_19 3 +#define AD5791_LINCOMP_19_20 12 + +#define AD5780_LINCOMP_0_10 0 +#define AD5780_LINCOMP_10_20 12 + +/* Software Control Register */ +#define AD5791_SWCTRL_LDAC (1 << 0) +#define AD5791_SWCTRL_CLR (1 << 1) +#define AD5791_SWCTRL_RESET (1 << 2) + +#define AD5791_DAC_PWRDN_6K 0 +#define AD5791_DAC_PWRDN_3STATE 1 + +/** +* struct ad5791_chip_info - chip specific information +* @get_lin_comp: function pointer to the device specific function +*/ + +struct ad5791_chip_info { +int (*get_lin_comp) (unsigned int span); +}; + +/** +* struct ad5791_state - driver instance specific data +* @us: spi_device +* @reg_vdd: positive supply regulator +* @reg_vss: negative supply regulator +* @chip_info: chip model specific constants +* @vref_mv: actual reference voltage used +* @vref_neg_mv: voltage of the negative supply +* @pwr_down_mode current power down mode +*/ + +struct ad5791_state { +struct spi_device *spi; +struct regulator *reg_vdd; +struct regulator *reg_vss; +const struct ad5791_chip_info *chip_info; +unsigned short vref_mv; +unsigned int vref_neg_mv; +unsigned ctrl; +unsigned pwr_down_mode; +bool pwr_down; +}; + +/** +* ad5791_supported_device_ids: +*/ + +enum ad5791_supported_device_ids { +ID_AD5760 , +ID_AD5780 , +ID_AD5781 , +ID_AD5791 , +}; +static int ad5791_spi_write (struct spi_device *spi,u8 addr,u32 val) {union {drivers/staging/iio/dac/ad5791.h +0
-83@@ -9,46 +9,6 @@#ifndef SPI_AD5791_H_ #define SPI_AD5791_H_ -#define AD5791_RES_MASK (x) ((1 << (x)) - 1) -#define AD5791_DAC_MASK AD5791_RES_MASK(20) -#define AD5791_DAC_MSB (1 << 19) - -#define AD5791_CMD_READ (1 << 23) -#define AD5791_CMD_WRITE (0 << 23) -#define AD5791_ADDR (addr) ((addr) << 20) - -/* Registers */ -#define AD5791_ADDR_NOOP 0 -#define AD5791_ADDR_DAC0 1 -#define AD5791_ADDR_CTRL 2 -#define AD5791_ADDR_CLRCODE 3 -#define AD5791_ADDR_SW_CTRL 4 - -/* Control Register */ -#define AD5791_CTRL_RBUF (1 << 1) -#define AD5791_CTRL_OPGND (1 << 2) -#define AD5791_CTRL_DACTRI (1 << 3) -#define AD5791_CTRL_BIN2SC (1 << 4) -#define AD5791_CTRL_SDODIS (1 << 5) -#define AD5761_CTRL_LINCOMP (x) ((x) << 6) - -#define AD5791_LINCOMP_0_10 0 -#define AD5791_LINCOMP_10_12 1 -#define AD5791_LINCOMP_12_16 2 -#define AD5791_LINCOMP_16_19 3 -#define AD5791_LINCOMP_19_20 12 - -#define AD5780_LINCOMP_0_10 0 -#define AD5780_LINCOMP_10_20 12 - -/* Software Control Register */ -#define AD5791_SWCTRL_LDAC (1 << 0) -#define AD5791_SWCTRL_CLR (1 << 1) -#define AD5791_SWCTRL_RESET (1 << 2) - -#define AD5791_DAC_PWRDN_6K 0 -#define AD5791_DAC_PWRDN_3STATE 1 -/* * TODO: struct ad5791_platform_data needs to go into include/linux/iio */ @@ -66,47 +26,4 @@ struct ad5791_platform_data { bool use_rbuf_gain2; }; -/** -* struct ad5791_chip_info - chip specific information -* @get_lin_comp: function pointer to the device specific function -*/ - -struct ad5791_chip_info { -int (*get_lin_comp) (unsigned int span); -}; - -/** -* struct ad5791_state - driver instance specific data -* @us: spi_device -* @reg_vdd: positive supply regulator -* @reg_vss: negative supply regulator -* @chip_info: chip model specific constants -* @vref_mv: actual reference voltage used -* @vref_neg_mv: voltage of the negative supply -* @pwr_down_mode current power down mode -*/ - -struct ad5791_state { -struct spi_device *spi; -struct regulator *reg_vdd; -struct regulator *reg_vss; -const struct ad5791_chip_info *chip_info; -unsigned short vref_mv; -unsigned int vref_neg_mv; -unsigned ctrl; -unsigned pwr_down_mode; -bool pwr_down; -}; - -/** -* ad5791_supported_device_ids: -*/ - -enum ad5791_supported_device_ids { -ID_AD5760 , -ID_AD5780 , -ID_AD5781 , -ID_AD5791 , -}; -#endif /* SPI_AD5791_H_ */
PATCH 18/18 staging:iio: Move DAC drivers out of staging
In reply to Lars-Peter ClausenThe IIO DAC drivers are in a reasonably good shape. They all make use of channel spec and non of them provides non-documented sysfs attributes. Code style should be OK as well, both checkpatch and coccicheck only report trivial issues.
So lets move the whole folder out of staging.
---
drivers/iio/Kconfig | 1 +
drivers/iio/Makefile | 1 +
drivers/{staging => }/iio/dac/Kconfig | 0
drivers/{staging => }/iio/dac/Makefile | 0
drivers/{staging => }/iio/dac/ad5064.c | 0
drivers/{staging => }/iio/dac/ad5360.c | 0
drivers/{staging => }/iio/dac/ad5380.c | 0
drivers/{staging => }/iio/dac/ad5421.c | 2 +-
drivers/{staging => }/iio/dac/ad5446.c | 0
drivers/{staging => }/iio/dac/ad5446.h | 0
drivers/{staging => }/iio/dac/ad5504.c | 3 +--
drivers/{staging => }/iio/dac/ad5624r.h | 0
drivers/{staging => }/iio/dac/ad5624r_spi.c | 0
drivers/{staging => }/iio/dac/ad5686.c | 0
drivers/{staging => }/iio/dac/ad5764.c | 0
drivers/{staging => }/iio/dac/ad5791.c | 3 +--
drivers/{staging => }/iio/dac/max517.c | 3 +--
drivers/staging/iio/Kconfig | 1 -
drivers/staging/iio/Makefile | 1 -
{drivers/staging => include/linux}/iio/dac/ad5421.h | 4 ----
{drivers/staging => include/linux}/iio/dac/ad5504.h | 4 ----
{drivers/staging => include/linux}/iio/dac/ad5791.h | 4 ----
{drivers/staging => include/linux}/iio/dac/max517.h | 4 ----
23 files changed, 6 insertions(+), 25 deletions(-)
rename drivers/{staging => }/iio/dac/Kconfig (100%)
rename drivers/{staging => }/iio/dac/Makefile (100%)
rename drivers/{staging => }/iio/dac/ad5064.c (100%)
rename drivers/{staging => }/iio/dac/ad5360.c (100%)
rename drivers/{staging => }/iio/dac/ad5380.c (100%)
rename drivers/{staging => }/iio/dac/ad5421.c (99%)
rename drivers/{staging => }/iio/dac/ad5446.c (100%)
rename drivers/{staging => }/iio/dac/ad5446.h (100%)
rename drivers/{staging => }/iio/dac/ad5504.c (99%)
rename drivers/{staging => }/iio/dac/ad5624r.h (100%)
rename drivers/{staging => }/iio/dac/ad5624r_spi.c (100%)
rename drivers/{staging => }/iio/dac/ad5686.c (100%)
rename drivers/{staging => }/iio/dac/ad5764.c (100%)
rename drivers/{staging => }/iio/dac/ad5791.c (99%)
rename drivers/{staging => }/iio/dac/max517.c (99%)
rename {drivers/staging => include/linux}/iio/dac/ad5421.h (92%)
rename {drivers/staging => include/linux}/iio/dac/ad5504.h (74%)
rename {drivers/staging => include/linux}/iio/dac/ad5791.h (87%)
rename {drivers/staging => include/linux}/iio/dac/max517.h (76%)drivers/iio/Kconfig +1 -0
@@ -50,5 +50,6 @@ config IIO_CONSUMERS_PER_TRIGGER source "drivers/iio/adc/Kconfig" source "drivers/iio/amplifiers/Kconfig" +source "drivers/iio/dac/Kconfig" endif # IIO
drivers/iio/Makefile +1 -0
@@ -11,3 +11,4 @@ obj-$(CONFIG_IIO_KFIFO_BUF) += kfifo_buf.o obj-y += adc/ obj-y += amplifiers/ +obj-y += dac/
drivers/iio/dac/Kconfig renamed from drivers/staging/iio/dac/Kconfig +0 -0
drivers/iio/dac/Makefile renamed from drivers/staging/iio/dac/Makefile +0 -0
drivers/iio/dac/ad5064.c renamed from drivers/staging/iio/dac/ad5064.c +0 -0
drivers/iio/dac/ad5360.c renamed from drivers/staging/iio/dac/ad5360.c +0 -0
drivers/iio/dac/ad5380.c renamed from drivers/staging/iio/dac/ad5380.c +0 -0
drivers/iio/dac/ad5421.c renamed from drivers/staging/iio/dac/ad5421.c +1 -1
@@ -19,7 +19,7 @@#include <linux/iio/iio.h> #include <linux/iio/sysfs.h> #include <linux/iio/events.h> -#include "ad5421.h" +#include <linux/iio/dac/ad5421.h> #define AD5421_REG_DAC_DATA 0x1
drivers/iio/dac/ad5446.c renamed from drivers/staging/iio/dac/ad5446.c +0 -0
drivers/iio/dac/ad5446.h renamed from drivers/staging/iio/dac/ad5446.h +0 -0
drivers/iio/dac/ad5504.c renamed from drivers/staging/iio/dac/ad5504.c +1 -2
@@ -19,8 +19,7 @@#include <linux/iio/iio.h> #include <linux/iio/sysfs.h> #include <linux/iio/events.h> - -#include "ad5504.h" +#include <linux/iio/dac/ad5504.h> #define AD5505_BITS 12#define AD5504_RES_MASK ((1 << (AD5505_BITS)) - 1)
drivers/iio/dac/ad5624r.h renamed from drivers/staging/iio/dac/ad5624r.h +0 -0
drivers/iio/dac/ad5624r_spi.c renamed from drivers/staging/iio/dac/ad5624r_spi.c +0 -0
drivers/iio/dac/ad5686.c renamed from drivers/staging/iio/dac/ad5686.c +0 -0
drivers/iio/dac/ad5764.c renamed from drivers/staging/iio/dac/ad5764.c +0 -0
drivers/iio/dac/ad5791.c renamed from drivers/staging/iio/dac/ad5791.c +1 -2
@@ -19,8 +19,7 @@#include <linux/iio/iio.h> #include <linux/iio/sysfs.h> - -#include "ad5791.h" +#include <linux/iio/dac/ad5791.h> #define AD5791_RES_MASK (x) ((1 << (x)) - 1)#define AD5791_DAC_MASK AD5791_RES_MASK(20)
drivers/iio/dac/max517.c renamed from drivers/staging/iio/dac/max517.c +1 -2
@@ -27,8 +27,7 @@#include <linux/iio/iio.h> #include <linux/iio/sysfs.h> - -#include "max517.h" +#include <linux/iio/dac/max517.h> #define MAX517_DRV_NAME "max517"
drivers/staging/iio/Kconfig +0 -1
@@ -29,7 +29,6 @@ source "drivers/staging/iio/accel/Kconfig" source "drivers/staging/iio/adc/Kconfig" source "drivers/staging/iio/addac/Kconfig" source "drivers/staging/iio/cdc/Kconfig" -source "drivers/staging/iio/dac/Kconfig" source "drivers/staging/iio/frequency/Kconfig" source "drivers/staging/iio/gyro/Kconfig" source "drivers/staging/iio/impedance-analyzer/Kconfig"
drivers/staging/iio/Makefile +0 -1
@@ -17,7 +17,6 @@ obj-y += accel/ obj-y += adc/ obj-y += addac/ obj-y += cdc/ -obj-y += dac/ obj-y += frequency/ obj-y += gyro/ obj-y += impedance-analyzer/
include/linux/iio/dac/ad5421.h renamed from drivers/staging/iio/dac/ad5421.h +0 -4
@@ -1,10 +1,6 @@#ifndef __IIO_DAC_AD5421_H__#define __IIO_DAC_AD5421_H__ -/* -* TODO: This file needs to go into include/linux/iio -*/ -/** * enum ad5421_current_range - Current range the AD5421 is configured for. * @AD5421_CURRENT_RANGE_4mA_20mA: 4 mA to 20 mA (RANGE1,0 pins = 00)
include/linux/iio/dac/ad5504.h renamed from drivers/staging/iio/dac/ad5504.h +0 -4
@@ -9,10 +9,6 @@#ifndef SPI_AD5504_H_ #define SPI_AD5504_H_ -/* -* TODO: struct ad5504_platform_data needs to go into include/linux/iio -*/ -struct ad5504_platform_data {u16 vref_mv; };
include/linux/iio/dac/ad5791.h renamed from drivers/staging/iio/dac/ad5791.h +0 -4
@@ -9,10 +9,6 @@#ifndef SPI_AD5791_H_ #define SPI_AD5791_H_ -/* -* TODO: struct ad5791_platform_data needs to go into include/linux/iio -*/ -/** * struct ad5791_platform_data - platform specific information * @vref_pos_mv: Vdd Positive Analog Supply Volatge (mV)
include/linux/iio/dac/max517.h renamed from drivers/staging/iio/dac/max517.h +0 -4
@@ -8,10 +8,6 @@#ifndef IIO_DAC_MAX517_H_ #define IIO_DAC_MAX517_H_ -/* -* TODO: struct max517_platform_data needs to go into include/linux/iio -*/ -struct max517_platform_data {u16 vref_mv[2 ]; };
Signature · 1 line
1.7.10
Re: [PATCH 18/18] staging:iio: Move DAC drivers out of staging
Quoted 5 lines · Lars-Peter Clausen
The IIO DAC drivers are in a reasonably good shape. They all make use of channel spec and non of them provides non-documented sysfs attributes. Code style should be OK as well, both checkpatch and coccicheck only report trivial issues.
So lets move the whole folder out of staging.
Agreed.
There are a few bits in here that I feel should be handled better in general in the kernel, such as powerdown modes (as they apply to other types of output - if in a generally less critical fashion). But if that ever happens we can deprecate them and go through a slow removal in the IIO drivers.
Thanks for handling these Lars-Peter.
Obviously though it is very much up to Greg whether he wants to pull (and push on) this set given the merge window is open. They are all straight forward so he 'might'. If not, they will be ready nice and early for the next cycle :)
Quoted 2 lines
Signed-off-by Lars-Peter Clausen <[email protected]>
Quoted 272 lines
--- drivers/iio/Kconfig | 1 + drivers/iio/Makefile | 1 + drivers/{staging => }/iio/dac/Kconfig | 0 drivers/{staging => }/iio/dac/Makefile | 0 drivers/{staging => }/iio/dac/ad5064.c | 0 drivers/{staging => }/iio/dac/ad5360.c | 0 drivers/{staging => }/iio/dac/ad5380.c | 0 drivers/{staging => }/iio/dac/ad5421.c | 2 +- drivers/{staging => }/iio/dac/ad5446.c | 0 drivers/{staging => }/iio/dac/ad5446.h | 0 drivers/{staging => }/iio/dac/ad5504.c | 3 +-- drivers/{staging => }/iio/dac/ad5624r.h | 0 drivers/{staging => }/iio/dac/ad5624r_spi.c | 0 drivers/{staging => }/iio/dac/ad5686.c | 0 drivers/{staging => }/iio/dac/ad5764.c | 0 drivers/{staging => }/iio/dac/ad5791.c | 3 +-- drivers/{staging => }/iio/dac/max517.c | 3 +-- drivers/staging/iio/Kconfig | 1 - drivers/staging/iio/Makefile | 1 - {drivers/staging => include/linux}/iio/dac/ad5421.h | 4 ---- {drivers/staging => include/linux}/iio/dac/ad5504.h | 4 ---- {drivers/staging => include/linux}/iio/dac/ad5791.h | 4 ---- {drivers/staging => include/linux}/iio/dac/max517.h | 4 ---- 23 files changed, 6 insertions(+), 25 deletions(-) rename drivers/{staging => }/iio/dac/Kconfig (100%) rename drivers/{staging => }/iio/dac/Makefile (100%) rename drivers/{staging => }/iio/dac/ad5064.c (100%) rename drivers/{staging => }/iio/dac/ad5360.c (100%) rename drivers/{staging => }/iio/dac/ad5380.c (100%) rename drivers/{staging => }/iio/dac/ad5421.c (99%) rename drivers/{staging => }/iio/dac/ad5446.c (100%) rename drivers/{staging => }/iio/dac/ad5446.h (100%) rename drivers/{staging => }/iio/dac/ad5504.c (99%) rename drivers/{staging => }/iio/dac/ad5624r.h (100%) rename drivers/{staging => }/iio/dac/ad5624r_spi.c (100%) rename drivers/{staging => }/iio/dac/ad5686.c (100%) rename drivers/{staging => }/iio/dac/ad5764.c (100%) rename drivers/{staging => }/iio/dac/ad5791.c (99%) rename drivers/{staging => }/iio/dac/max517.c (99%) rename {drivers/staging => include/linux}/iio/dac/ad5421.h (92%) rename {drivers/staging => include/linux}/iio/dac/ad5504.h (74%) rename {drivers/staging => include/linux}/iio/dac/ad5791.h (87%) rename {drivers/staging => include/linux}/iio/dac/max517.h (76%)drivers/iio/Kconfig +1
-0@@ -50,5 +50,6 @@ config IIO_CONSUMERS_PER_TRIGGER source "drivers/iio/adc/Kconfig" source "drivers/iio/amplifiers/Kconfig" +source "drivers/iio/dac/Kconfig" endif # IIOdrivers/iio/Makefile +1
-0@@ -11,3 +11,4 @@ obj-$(CONFIG_IIO_KFIFO_BUF) += kfifo_buf.o obj-y += adc/ obj-y += amplifiers/ +obj-y += dac/drivers/iio/dac/Kconfig renamed from drivers/staging/iio/dac/Kconfig +0
-0drivers/iio/dac/Makefile renamed from drivers/staging/iio/dac/Makefile +0
-0drivers/iio/dac/ad5064.c renamed from drivers/staging/iio/dac/ad5064.c +0
-0drivers/iio/dac/ad5360.c renamed from drivers/staging/iio/dac/ad5360.c +0
-0drivers/iio/dac/ad5380.c renamed from drivers/staging/iio/dac/ad5380.c +0
-0drivers/iio/dac/ad5421.c renamed from drivers/staging/iio/dac/ad5421.c +1
-1@@ -19,7 +19,7 @@#include <linux/iio/iio.h> #include <linux/iio/sysfs.h> #include <linux/iio/events.h> -#include "ad5421.h" +#include <linux/iio/dac/ad5421.h> #define AD5421_REG_DAC_DATA 0x1drivers/iio/dac/ad5446.c renamed from drivers/staging/iio/dac/ad5446.c +0
-0drivers/iio/dac/ad5446.h renamed from drivers/staging/iio/dac/ad5446.h +0
-0drivers/iio/dac/ad5504.c renamed from drivers/staging/iio/dac/ad5504.c +1
-2@@ -19,8 +19,7 @@#include <linux/iio/iio.h> #include <linux/iio/sysfs.h> #include <linux/iio/events.h> - -#include "ad5504.h" +#include <linux/iio/dac/ad5504.h> #define AD5505_BITS 12#define AD5504_RES_MASK ((1 << (AD5505_BITS)) - 1)drivers/iio/dac/ad5624r.h renamed from drivers/staging/iio/dac/ad5624r.h +0
-0drivers/iio/dac/ad5624r_spi.c renamed from drivers/staging/iio/dac/ad5624r_spi.c +0
-0drivers/iio/dac/ad5686.c renamed from drivers/staging/iio/dac/ad5686.c +0
-0drivers/iio/dac/ad5764.c renamed from drivers/staging/iio/dac/ad5764.c +0
-0drivers/iio/dac/ad5791.c renamed from drivers/staging/iio/dac/ad5791.c +1
-2@@ -19,8 +19,7 @@#include <linux/iio/iio.h> #include <linux/iio/sysfs.h> - -#include "ad5791.h" +#include <linux/iio/dac/ad5791.h> #define AD5791_RES_MASK (x) ((1 << (x)) - 1)#define AD5791_DAC_MASK AD5791_RES_MASK(20)drivers/iio/dac/max517.c renamed from drivers/staging/iio/dac/max517.c +1
-2@@ -27,8 +27,7 @@#include <linux/iio/iio.h> #include <linux/iio/sysfs.h> - -#include "max517.h" +#include <linux/iio/dac/max517.h> #define MAX517_DRV_NAME "max517"drivers/staging/iio/Kconfig +0
-1@@ -29,7 +29,6 @@ source "drivers/staging/iio/accel/Kconfig" source "drivers/staging/iio/adc/Kconfig" source "drivers/staging/iio/addac/Kconfig" source "drivers/staging/iio/cdc/Kconfig" -source "drivers/staging/iio/dac/Kconfig" source "drivers/staging/iio/frequency/Kconfig" source "drivers/staging/iio/gyro/Kconfig" source "drivers/staging/iio/impedance-analyzer/Kconfig"drivers/staging/iio/Makefile +0
-1@@ -17,7 +17,6 @@ obj-y += accel/ obj-y += adc/ obj-y += addac/ obj-y += cdc/ -obj-y += dac/ obj-y += frequency/ obj-y += gyro/ obj-y += impedance-analyzer/include/linux/iio/dac/ad5421.h renamed from drivers/staging/iio/dac/ad5421.h +0
-4@@ -1,10 +1,6 @@#ifndef __IIO_DAC_AD5421_H__#define __IIO_DAC_AD5421_H__ -/* -* TODO: This file needs to go into include/linux/iio -*/ -/** * enum ad5421_current_range - Current range the AD5421 is configured for. * @AD5421_CURRENT_RANGE_4mA_20mA: 4 mA to 20 mA (RANGE1,0 pins = 00) include/linux/iio/dac/ad5504.h renamed from drivers/staging/iio/dac/ad5504.h +0
-4@@ -9,10 +9,6 @@#ifndef SPI_AD5504_H_ #define SPI_AD5504_H_ -/* -* TODO: struct ad5504_platform_data needs to go into include/linux/iio -*/ -struct ad5504_platform_data {u16 vref_mv; };include/linux/iio/dac/ad5791.h renamed from drivers/staging/iio/dac/ad5791.h +0
-4@@ -9,10 +9,6 @@#ifndef SPI_AD5791_H_ #define SPI_AD5791_H_ -/* -* TODO: struct ad5791_platform_data needs to go into include/linux/iio -*/ -/** * struct ad5791_platform_data - platform specific information * @vref_pos_mv: Vdd Positive Analog Supply Volatge (mV) include/linux/iio/dac/max517.h renamed from drivers/staging/iio/dac/max517.h +0
-4@@ -8,10 +8,6 @@#ifndef IIO_DAC_MAX517_H_ #define IIO_DAC_MAX517_H_ -/* -* TODO: struct max517_platform_data needs to go into include/linux/iio -*/ -struct max517_platform_data {u16 vref_mv[2 ]; };
Quoted 9 lines · Lars-Peter Clausen
We often have the case were we do have a enum style channel attribute. These attributes have in common that they are a list of string values which usually map in a 1-to-1 fashion to integer values.
This patch implements some common helper code for implementing enum style channel attributes using extended channel attributes. The helper functions take care of converting between the string and integer values, as well providing a function for "
_available" attributes which list all available enum items.
One trivial suggestion to mention the integers are unsigned inline... It's kind of obvious but never hurts to hammer the point home!
Quoted 1 line
Signed-off-by Lars-Peter Clausen <[email protected]>
Quoted 94 lines
---
Changes since v1:
* Add documentation for structiio_enum,IIO_ENUMandIIO_ENUM_AVAILABLE.
* Make set and get callbacks optionalSigned-off-by Lars-Peter Clausen <[email protected]>--- drivers/iio/industrialio-core.c | 63 ++++++++++++++++++++++++++++++++++++++ include/linux/iio/iio.h | 64 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 127 insertions(+)drivers/iio/industrialio-core.c +63
-0@@ -289,6 +289,69 @@ static ssize_t iio_write_channel_ext_info(struct device *dev, this_attr->c, buf, len); } +ssize_t iio_enum_available_read (struct iio_dev *indio_dev, +uintptr_t priv,const struct iio_chan_spec *chan,char *buf) +{ +const struct iio_enum *e = (const struct iio_enum *)priv; +unsigned int i; +size_t len =0 ; + +if (!e->num_items) +return 0 ; + +for (i =0 ; i < e->num_items; ++i) + len +=snprintf (buf + len,PAGE_SIZE - len,"%s " , e->items[i]); + +/* replace last space with a newline */ + buf[len -1 ] ='\n' ; + +return len; +} +EXPORT_SYMBOL_GPL (iio_enum_available_read); + +ssize_t iio_enum_read (struct iio_dev *indio_dev, +uintptr_t priv,const struct iio_chan_spec *chan,char *buf) +{ +const struct iio_enum *e = (const struct iio_enum *)priv; +int i; + +if (!e->get) +return -EINVAL ; + + i = e->get (indio_dev, chan); +if (i <0 ) +return i; +else if (i >= e->num_items) +return -EINVAL ; + +return sprintf (buf,"%s\n" , e->items[i]); +} +EXPORT_SYMBOL_GPL (iio_enum_read); + +ssize_t iio_enum_write (struct iio_dev *indio_dev, +uintptr_t priv,const struct iio_chan_spec *chan,const char *buf, +size_t len) +{ +const struct iio_enum *e = (const struct iio_enum *)priv; +unsigned int i; +int ret; + +if (!e->set) +return -EINVAL ; + +for (i =0 ; i < e->num_items; i++) { +if (sysfs_streq (buf, e->items[i])) +break ; + } + +if (i == e->num_items) +return -EINVAL ; + + ret = e->set (indio_dev, chan, i); +return ret ? ret : len; +} +EXPORT_SYMBOL_GPL (iio_enum_write); +static ssize_t iio_read_channel_info (struct device *dev,struct device_attribute *attr,char *buf)include/linux/iio/iio.h +0
-0@@ -130,6 +130,70 @@ struct iio_chan_spec_ext_info { };/**
include/linux/iio/iio.h struct iio_chan_spec_ext_info { · line 142
Quoted 10 lines
include/linux/iio/iio.h +10
-0+* struct iio_enum - Enum channel info attribute +* items: A array of strings. +* num_items: Length of the item array. +* set: Set callback function, may be NULL. +* get: Get callback function, may be NULL. +* +* The iio_enum struct can be used to implement enum style channel attributes. +* Enum style attributes are those which have a set of strings which map to +* integer values. The IIO enum helper code takes care of mapping between the +* integer
Trivial but they are restricted to unsigned integers by the set interface.
and string values as well as generating a "_available" file which
Quoted 57 lines
include/linux/iio/iio.h +54
-0+* contains a list of all available items. The set callback will be called when +* the attribute is updated. The last parameter is the index to the newly +* activated item. The get callback will be used to query the currently active +* item and is supposed to return the index for it. +*/ +struct iio_enum { +const char *const *items; +unsigned int num_items; +int (*set)(struct iio_dev *,const struct iio_chan_spec *,unsigned int ); +int (*get)(struct iio_dev *,const struct iio_chan_spec *); +}; + +ssize_t iio_enum_available_read (struct iio_dev *indio_dev, +uintptr_t priv,const struct iio_chan_spec *chan,char *buf); +ssize_t iio_enum_read (struct iio_dev *indio_dev, +uintptr_t priv,const struct iio_chan_spec *chan,char *buf); +ssize_t iio_enum_write (struct iio_dev *indio_dev, +uintptr_t priv,const struct iio_chan_spec *chan,const char *buf, +size_t len); + +/** +* IIO_ENUM() - Initialize enum extended channel attribute +* @_name: Attribute name +* @_shared: Whether the attribute is shared between all channels +* @_e: Pointer to a iio_enum struct +* +* This should usually be used together with IIO_ENUM_AVAILABLE() +*/ +#define IIO_ENUM (_name, _shared, _e) \ +{ \ + .name = (_name), \ + .shared = (_shared), \ + .read = iio_enum_read, \ + .write = iio_enum_write, \ + .private = (uintptr_t)(_e), \ +} + +/** +* IIO_ENUM_AVAILABLE() - Initialize enum available extended channel attribute +* @_name: Attribute name ("_available" will be appended to the name) +* @_e: Pointer to a iio_enum struct +* +* Creates a read only attribute which list all the available enum items in a +* space separated list. This should usually be used together with IIO_ENUM() +*/ +#define IIO_ENUM_AVAILABLE (_name, _e) \ +{ \ + .name = (_name "_available"), \ + .shared = true, \ + .read = iio_enum_available_read, \ + .private = (uintptr_t)(_e), \ +} + +/** * struct iio_chan_spec - specification of a single channel * @type: What type of measurement is the channel making. * @channel: What number or name do we wish to assign the channel.