On 05/11/2012 04:53 PM, Lars-Peter Clausen wrote: > Use extended channel attributes instead of raw sysfs files for the additional > channel attributes. This allows us to remove some boilerplate code. A nice patch set. I do wonder if we ultimately need to find common ground for these power down commands with other subsystems. I have a vague feeling that the pinmux stuff will overlap with this at somepoint. Afterall it's not uncommon to have these sorts of controls on gpio's or other pins on a SoC. Probably just a question of keeping an eye on progress elsewhere for now... > > Signed-off-by: Lars-Peter Clausen <lars@xxxxxxxxxx> Acked-by: Jonathan Cameron <jic23@xxxxxxxxxx> > --- > drivers/staging/iio/dac/ad5791.c | 122 +++++++++++++++++--------------------- > 1 file changed, 53 insertions(+), 69 deletions(-) > > diff --git a/drivers/staging/iio/dac/ad5791.c b/drivers/staging/iio/dac/ad5791.c > index 8628964..4e955ed 100644 > --- a/drivers/staging/iio/dac/ad5791.c > +++ b/drivers/staging/iio/dac/ad5791.c > @@ -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_get_drvdata(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_get_drvdata(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_get_drvdata(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_get_drvdata(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, > }; > -- To unsubscribe from this list: send the line "unsubscribe linux-iio" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html