Commit 868e0862 authored by Lars-Peter Clausen's avatar Lars-Peter Clausen Committed by Greg Kroah-Hartman

staging:iio:dac:ad5380: Convert to extended channel attributes

Use extended channel attributes instead of raw sysfs files for the additional
channel attributes. This allows us to remove some boilerplate code.
Signed-off-by: default avatarLars-Peter Clausen <lars@metafoo.de>
Acked-by: default avatarJonathan Cameron <jic23@kernel.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 09d48aa9
...@@ -81,103 +81,18 @@ enum ad5380_type { ...@@ -81,103 +81,18 @@ enum ad5380_type {
ID_AD5392_5, ID_AD5392_5,
}; };
#define AD5380_CHANNEL(_bits) { \ static ssize_t ad5380_read_dac_powerdown(struct iio_dev *indio_dev,
.type = IIO_VOLTAGE, \ uintptr_t private, const struct iio_chan_spec *chan, char *buf)
.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)
{ {
struct iio_dev *indio_dev = dev_to_iio_dev(dev);
struct ad5380_state *st = iio_priv(indio_dev); struct ad5380_state *st = iio_priv(indio_dev);
return sprintf(buf, "%d\n", st->pwr_down); return sprintf(buf, "%d\n", st->pwr_down);
} }
static ssize_t ad5380_write_dac_powerdown(struct device *dev, static ssize_t ad5380_write_dac_powerdown(struct iio_dev *indio_dev,
struct device_attribute *attr, const char *buf, size_t len) 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); struct ad5380_state *st = iio_priv(indio_dev);
bool pwr_down; bool pwr_down;
int ret; int ret;
...@@ -200,20 +115,14 @@ static ssize_t ad5380_write_dac_powerdown(struct device *dev, ...@@ -200,20 +115,14 @@ static ssize_t ad5380_write_dac_powerdown(struct device *dev,
return ret ? ret : len; return ret ? ret : len;
} }
static IIO_DEVICE_ATTR(out_voltage_powerdown, static const char * const ad5380_powerdown_modes[] = {
S_IRUGO | S_IWUSR, "100kohm_to_gnd",
ad5380_read_dac_powerdown, "three_state",
ad5380_write_dac_powerdown, 0);
static const char ad5380_powerdown_modes[][15] = {
[0] = "100kohm_to_gnd",
[1] = "three_state",
}; };
static ssize_t ad5380_read_powerdown_mode(struct device *dev, static int ad5380_get_powerdown_mode(struct iio_dev *indio_dev,
struct device_attribute *attr, char *buf) const struct iio_chan_spec *chan)
{ {
struct iio_dev *indio_dev = dev_to_iio_dev(dev);
struct ad5380_state *st = iio_priv(indio_dev); struct ad5380_state *st = iio_priv(indio_dev);
unsigned int mode; unsigned int mode;
int ret; int ret;
...@@ -224,49 +133,27 @@ static ssize_t ad5380_read_powerdown_mode(struct device *dev, ...@@ -224,49 +133,27 @@ static ssize_t ad5380_read_powerdown_mode(struct device *dev,
mode = (mode >> AD5380_CTRL_PWR_DOWN_MODE_OFFSET) & 1; 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, static int ad5380_set_powerdown_mode(struct iio_dev *indio_dev,
struct device_attribute *attr, const char *buf, size_t len) 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); struct ad5380_state *st = iio_priv(indio_dev);
unsigned int i;
int ret; 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, ret = regmap_update_bits(st->regmap, AD5380_REG_SF_CTRL,
1 << AD5380_CTRL_PWR_DOWN_MODE_OFFSET, 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, static const struct iio_enum ad5380_powerdown_mode_enum = {
S_IRUGO | S_IWUSR, .items = ad5380_powerdown_modes,
ad5380_read_powerdown_mode, .num_items = ARRAY_SIZE(ad5380_powerdown_modes),
ad5380_write_powerdown_mode, 0); .get = ad5380_get_powerdown_mode,
.set = ad5380_set_powerdown_mode,
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 unsigned int ad5380_info_to_reg(struct iio_chan_spec const *chan, 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, ...@@ -354,10 +241,105 @@ static int ad5380_read_raw(struct iio_dev *indio_dev,
static const struct iio_info ad5380_info = { static const struct iio_info ad5380_info = {
.read_raw = ad5380_read_raw, .read_raw = ad5380_read_raw,
.write_raw = ad5380_write_raw, .write_raw = ad5380_write_raw,
.attrs = &ad5380_attribute_group,
.driver_module = THIS_MODULE, .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) static int __devinit ad5380_alloc_channels(struct iio_dev *indio_dev)
{ {
struct ad5380_state *st = iio_priv(indio_dev); struct ad5380_state *st = iio_priv(indio_dev);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment