From: Jonathan Cameron <jic23@kernel.org>
To: Lars-Peter Clausen <lars@metafoo.de>
Cc: Jonathan Cameron <jic23@cam.ac.uk>, linux-iio@vger.kernel.org
Subject: Re: [RFC 8/8] staging:iio:dac:ad5791: Convert to extended channel attributes
Date: Mon, 14 May 2012 19:21:26 +0100 [thread overview]
Message-ID: <4FB14D26.9000101@kernel.org> (raw)
In-Reply-To: <1336751635-7934-8-git-send-email-lars@metafoo.de>
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@metafoo.de>
Acked-by: Jonathan Cameron <jic23@kernel.org>
> ---
> 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,
> };
>
next prev parent reply other threads:[~2012-05-14 18:21 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-11 15:53 [RFC 1/8] iio: Add helper functions for enum style channel attributes Lars-Peter Clausen
2012-05-11 15:53 ` [RFC 2/8] staging:iio:dac:ad5064: Use iio_enum for powerdown modes Lars-Peter Clausen
2012-05-14 17:48 ` Jonathan Cameron
2012-05-11 15:53 ` [RFC 3/8] staging:iio:dac:ad5446: " Lars-Peter Clausen
2012-05-14 17:55 ` Jonathan Cameron
2012-05-11 15:53 ` [RFC 4/8] staging:iio:dac:ad5380: Convert to extended channel attributes Lars-Peter Clausen
2012-05-14 18:11 ` Jonathan Cameron
2012-05-11 15:53 ` [RFC 5/8] staging:iio:dac:ad5504: " Lars-Peter Clausen
2012-05-14 18:14 ` Jonathan Cameron
2012-05-11 15:53 ` [RFC 6/8] staging:iio:dac:ad5624r: " Lars-Peter Clausen
2012-05-14 18:16 ` Jonathan Cameron
2012-05-11 15:53 ` [RFC 7/8] staging:iio:dac:ad5686: " Lars-Peter Clausen
2012-05-14 18:18 ` Jonathan Cameron
2012-05-11 15:53 ` [RFC 8/8] staging:iio:dac:ad5791: " Lars-Peter Clausen
2012-05-14 18:21 ` Jonathan Cameron [this message]
2012-05-14 17:42 ` [RFC 1/8] iio: Add helper functions for enum style " Jonathan Cameron
2012-05-14 18:15 ` Lars-Peter Clausen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4FB14D26.9000101@kernel.org \
--to=jic23@kernel.org \
--cc=jic23@cam.ac.uk \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.