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 3/8] staging:iio:dac:ad5446: Use iio_enum for powerdown modes
Date: Mon, 14 May 2012 18:55:13 +0100 [thread overview]
Message-ID: <4FB14701.8020608@kernel.org> (raw)
In-Reply-To: <1336751635-7934-3-git-send-email-lars@metafoo.de>
On 05/11/2012 04:53 PM, Lars-Peter Clausen wrote:
> This allows us to remove some boilerplate code for comparing and formatting the
> enum strings.
>
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Acked-by: Jonathan Cameron <jic23@kernel.org>
> ---
> drivers/staging/iio/dac/ad5446.c | 53 ++++++++++++--------------------------
> 1 file changed, 17 insertions(+), 36 deletions(-)
>
> diff --git a/drivers/staging/iio/dac/ad5446.c b/drivers/staging/iio/dac/ad5446.c
> index 3e53d0c..f769b74 100644
> --- a/drivers/staging/iio/dac/ad5446.c
> +++ b/drivers/staging/iio/dac/ad5446.c
> @@ -41,47 +41,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,
> @@ -128,15 +115,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),
> { },
> };
>
next prev parent reply other threads:[~2012-05-14 17:55 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 [this message]
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
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=4FB14701.8020608@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.