linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Lars-Peter Clausen <lars@metafoo.de>
Cc: linux-iio@vger.kernel.org
Subject: Re: [PATCH v2 19/20] staging:iio:ad7291: Use event spec for threshold hysteresis
Date: Sat, 12 Oct 2013 13:04:41 +0100	[thread overview]
Message-ID: <52593AD9.600@kernel.org> (raw)
In-Reply-To: <1381155094-20166-19-git-send-email-lars@metafoo.de>

On 10/07/13 15:11, Lars-Peter Clausen wrote:
> Register the event threshold hysteresis attributes by using the new
> IIO_EV_INFO_HYSTERESIS event spec type. This allows us to throw away a good
> portion of boiler-plate code.
> 
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Applied thanks.
> ---
>  drivers/staging/iio/adc/ad7291.c | 139 ++++++++-------------------------------
>  1 file changed, 28 insertions(+), 111 deletions(-)
> 
> diff --git a/drivers/staging/iio/adc/ad7291.c b/drivers/staging/iio/adc/ad7291.c
> index be4d93a..d13f8ae 100644
> --- a/drivers/staging/iio/adc/ad7291.c
> +++ b/drivers/staging/iio/adc/ad7291.c
> @@ -164,92 +164,8 @@ static irqreturn_t ad7291_event_handler(int irq, void *private)
>  	return IRQ_HANDLED;
>  }
>  
> -static inline ssize_t ad7291_show_hyst(struct device *dev,
> -		struct device_attribute *attr,
> -		char *buf)
> -{
> -	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
> -	struct ad7291_chip_info *chip = iio_priv(indio_dev);
> -	struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
> -	u16 data;
> -	int ret;
> -
> -	ret = ad7291_i2c_read(chip, this_attr->address, &data);
> -	if (ret < 0)
> -		return ret;
> -
> -	return sprintf(buf, "%d\n", data & AD7291_VALUE_MASK);
> -}
> -
> -static inline ssize_t ad7291_set_hyst(struct device *dev,
> -				      struct device_attribute *attr,
> -				      const char *buf,
> -				      size_t len)
> -{
> -	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
> -	struct ad7291_chip_info *chip = iio_priv(indio_dev);
> -	struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
> -	u16 data;
> -	int ret;
> -
> -	ret = kstrtou16(buf, 10, &data);
> -
> -	if (ret < 0)
> -		return ret;
> -	if (data > AD7291_VALUE_MASK)
> -		return -EINVAL;
> -
> -	ret = ad7291_i2c_write(chip, this_attr->address, data);
> -	if (ret < 0)
> -		return ret;
> -
> -	return len;
> -}
> -
> -static IIO_DEVICE_ATTR(in_temp0_thresh_both_hyst_raw,
> -		       S_IRUGO | S_IWUSR,
> -		       ad7291_show_hyst, ad7291_set_hyst,
> -		       AD7291_HYST(8));
> -static IIO_DEVICE_ATTR(in_voltage0_thresh_both_hyst_raw,
> -		       S_IRUGO | S_IWUSR,
> -		       ad7291_show_hyst, ad7291_set_hyst, AD7291_HYST(0));
> -static IIO_DEVICE_ATTR(in_voltage1_thresh_both_hyst_raw,
> -		       S_IRUGO | S_IWUSR,
> -		       ad7291_show_hyst, ad7291_set_hyst, AD7291_HYST(1));
> -static IIO_DEVICE_ATTR(in_voltage2_thresh_both_hyst_raw,
> -		       S_IRUGO | S_IWUSR,
> -		       ad7291_show_hyst, ad7291_set_hyst, AD7291_HYST(2));
> -static IIO_DEVICE_ATTR(in_voltage3_thresh_both_hyst_raw,
> -		       S_IRUGO | S_IWUSR,
> -		       ad7291_show_hyst, ad7291_set_hyst, AD7291_HYST(3));
> -static IIO_DEVICE_ATTR(in_voltage4_thresh_both_hyst_raw,
> -		       S_IRUGO | S_IWUSR,
> -		       ad7291_show_hyst, ad7291_set_hyst, AD7291_HYST(4));
> -static IIO_DEVICE_ATTR(in_voltage5_thresh_both_hyst_raw,
> -		       S_IRUGO | S_IWUSR,
> -		       ad7291_show_hyst, ad7291_set_hyst, AD7291_HYST(5));
> -static IIO_DEVICE_ATTR(in_voltage6_thresh_both_hyst_raw,
> -		       S_IRUGO | S_IWUSR,
> -		       ad7291_show_hyst, ad7291_set_hyst, AD7291_HYST(6));
> -static IIO_DEVICE_ATTR(in_voltage7_thresh_both_hyst_raw,
> -		       S_IRUGO | S_IWUSR,
> -		       ad7291_show_hyst, ad7291_set_hyst, AD7291_HYST(7));
> -
> -static struct attribute *ad7291_event_attributes[] = {
> -	&iio_dev_attr_in_temp0_thresh_both_hyst_raw.dev_attr.attr,
> -	&iio_dev_attr_in_voltage0_thresh_both_hyst_raw.dev_attr.attr,
> -	&iio_dev_attr_in_voltage1_thresh_both_hyst_raw.dev_attr.attr,
> -	&iio_dev_attr_in_voltage2_thresh_both_hyst_raw.dev_attr.attr,
> -	&iio_dev_attr_in_voltage3_thresh_both_hyst_raw.dev_attr.attr,
> -	&iio_dev_attr_in_voltage4_thresh_both_hyst_raw.dev_attr.attr,
> -	&iio_dev_attr_in_voltage5_thresh_both_hyst_raw.dev_attr.attr,
> -	&iio_dev_attr_in_voltage6_thresh_both_hyst_raw.dev_attr.attr,
> -	&iio_dev_attr_in_voltage7_thresh_both_hyst_raw.dev_attr.attr,
> -	NULL,
> -};
> -
>  static unsigned int ad7291_threshold_reg(const struct iio_chan_spec *chan,
> -	enum iio_event_direction dir)
> +	enum iio_event_direction dir, enum iio_event_info info)
>  {
>  	unsigned int offset;
>  
> @@ -264,10 +180,18 @@ static unsigned int ad7291_threshold_reg(const struct iio_chan_spec *chan,
>  	    return 0;
>  	}
>  
> -	if (dir == IIO_EV_DIR_FALLING)
> -		return AD7291_DATA_LOW(offset);
> -	else
> -		return AD7291_DATA_HIGH(offset);
> +	switch (info) {
> +	case IIO_EV_INFO_VALUE:
> +			if (dir == IIO_EV_DIR_FALLING)
> +					return AD7291_DATA_HIGH(offset);
> +			else
> +					return AD7291_DATA_LOW(offset);
> +	case IIO_EV_INFO_HYSTERESIS:
> +			return AD7291_HYST(offset);
> +	default:
> +			break;
> +	}
> +	return 0;
>  }
>  
>  static int ad7291_read_event_value(struct iio_dev *indio_dev,
> @@ -281,20 +205,18 @@ static int ad7291_read_event_value(struct iio_dev *indio_dev,
>  	int ret;
>  	u16 uval;
>  
> -	ret = ad7291_i2c_read(chip, ad7291_threshold_reg(chan, dir), &uval);
> +	ret = ad7291_i2c_read(chip, ad7291_threshold_reg(chan, dir, info),
> +		&uval);
>  	if (ret < 0)
>  		return ret;
>  
> -	switch (chan->type) {
> -	case IIO_VOLTAGE:
> +	if (info == IIO_EV_INFO_HYSTERESIS || chan->type == IIO_VOLTAGE)
>  		*val = uval & AD7291_VALUE_MASK;
> -		return IIO_VAL_INT;
> -	case IIO_TEMP:
> +
> +	else
>  		*val = sign_extend32(uval, 11);
> -		return IIO_VAL_INT;
> -	default:
> -		return -EINVAL;
> -	};
> +
> +	return IIO_VAL_INT;
>  }
>  
>  static int ad7291_write_event_value(struct iio_dev *indio_dev,
> @@ -306,20 +228,16 @@ static int ad7291_write_event_value(struct iio_dev *indio_dev,
>  {
>  	struct ad7291_chip_info *chip = iio_priv(indio_dev);
>  
> -	switch (chan->type) {
> -	case IIO_VOLTAGE:
> +	if (info == IIO_EV_INFO_HYSTERESIS || chan->type == IIO_VOLTAGE) {
>  		if (val > AD7291_VALUE_MASK || val < 0)
>  			return -EINVAL;
> -		break;
> -	case IIO_TEMP:
> +	} else {
>  		if (val > 2047 || val < -2048)
>  			return -EINVAL;
> -		break;
> -	default:
> -		return -EINVAL;
>  	}
>  
> -	return ad7291_i2c_write(chip, ad7291_threshold_reg(chan, dir), val);
> +	return ad7291_i2c_write(chip, ad7291_threshold_reg(chan, dir, info),
> +		val);
>  }
>  
>  static int ad7291_read_event_config(struct iio_dev *indio_dev,
> @@ -493,6 +411,10 @@ static const struct iio_event_spec ad7291_events[] = {
>  		.dir = IIO_EV_DIR_FALLING,
>  		.mask_separate = BIT(IIO_EV_INFO_VALUE) |
>  			BIT(IIO_EV_INFO_ENABLE),
> +	}, {
> +		.type = IIO_EV_TYPE_THRESH,
> +		.dir = IIO_EV_DIR_EITHER,
> +		.mask_separate = BIT(IIO_EV_INFO_HYSTERESIS),
>  	},
>  };
>  
> @@ -528,17 +450,12 @@ static const struct iio_chan_spec ad7291_channels[] = {
>  	}
>  };
>  
> -static struct attribute_group ad7291_event_attribute_group = {
> -	.attrs = ad7291_event_attributes,
> -};
> -
>  static const struct iio_info ad7291_info = {
>  	.read_raw = &ad7291_read_raw,
>  	.read_event_config_new = &ad7291_read_event_config,
>  	.write_event_config_new = &ad7291_write_event_config,
>  	.read_event_value_new = &ad7291_read_event_value,
>  	.write_event_value_new = &ad7291_write_event_value,
> -	.event_attrs = &ad7291_event_attribute_group,
>  	.driver_module = THIS_MODULE,
>  };
>  
> 

  reply	other threads:[~2013-10-12 11:04 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-07 14:11 [PATCH v2 01/20] iio: Factor IIO value formating into its own function Lars-Peter Clausen
2013-10-07 14:11 ` [PATCH v2 02/20] iio: Extend the event config interface Lars-Peter Clausen
2013-10-12 11:33   ` Jonathan Cameron
2013-10-07 14:11 ` [PATCH v2 03/20] iio:max1363: Switch to new " Lars-Peter Clausen
2013-10-12 11:34   ` Jonathan Cameron
2013-10-07 14:11 ` [PATCH v2 04/20] iio:ad5421: " Lars-Peter Clausen
2013-10-12 11:35   ` Jonathan Cameron
2013-10-07 14:11 ` [PATCH v2 05/20] iio:gp2ap020a00f: " Lars-Peter Clausen
2013-10-12 11:36   ` Jonathan Cameron
2013-10-07 14:11 ` [PATCH v2 06/20] iio:tsl2563: " Lars-Peter Clausen
2013-10-12 11:39   ` Jonathan Cameron
2013-10-07 14:11 ` [PATCH v2 07/20] iio:apds9300: Use " Lars-Peter Clausen
2013-10-12 11:41   ` Jonathan Cameron
2013-10-07 14:11 ` [PATCH v2 08/20] staging:iio:lis3l02dq: Switch to " Lars-Peter Clausen
2013-10-12 11:42   ` Jonathan Cameron
2013-10-07 14:11 ` [PATCH v2 09/20] staging:iio:lis2l02dq: Share threshold value between axis Lars-Peter Clausen
2013-10-12 11:43   ` Jonathan Cameron
2013-10-12 11:45   ` Jonathan Cameron
2013-10-12 10:51     ` Lars-Peter Clausen
2013-10-07 14:11 ` [PATCH v2 10/20] staging:iio:sca3000: Switch to new config interface Lars-Peter Clausen
2013-10-12 11:46   ` Jonathan Cameron
2013-10-07 14:11 ` [PATCH v2 11/20] staging:iio:ad7291: Switch to new event " Lars-Peter Clausen
2013-10-12 11:46   ` Jonathan Cameron
2013-10-07 14:11 ` [PATCH v2 12/20] staging:iio:ad799x: " Lars-Peter Clausen
2013-10-12 11:47   ` Jonathan Cameron
2013-10-07 14:11 ` [PATCH v2 13/20] staging:iio:ad7150: " Lars-Peter Clausen
2013-10-12 11:48   ` Jonathan Cameron
2013-10-07 14:11 ` [PATCH v2 14/20] staging:iio:simple_dummy: " Lars-Peter Clausen
2013-10-12 11:50   ` Jonathan Cameron
2013-10-07 14:11 ` [PATCH v2 15/20] staging:iio:tsl2x7x: " Lars-Peter Clausen
2013-10-12 11:50   ` Jonathan Cameron
2013-10-07 14:11 ` [PATCH v2 16/20] iio: Add a hysteresis event info attribute Lars-Peter Clausen
2013-10-12 11:51   ` Jonathan Cameron
2013-10-07 14:11 ` [PATCH v2 17/20] staging:iio:ad799x: Simplify threshold register look-up Lars-Peter Clausen
2013-10-12 11:52   ` Jonathan Cameron
2013-10-07 14:11 ` [PATCH v2 18/20] staging:iio:ad799x: Use event spec for threshold hysteresis Lars-Peter Clausen
2013-10-12 12:02   ` Jonathan Cameron
2013-10-12 11:40     ` Lars-Peter Clausen
2013-10-12 13:05       ` Jonathan Cameron
2013-10-07 14:11 ` [PATCH v2 19/20] staging:iio:ad7291: " Lars-Peter Clausen
2013-10-12 12:04   ` Jonathan Cameron [this message]
2013-10-07 14:11 ` [PATCH v2 20/20] iio: Remove support for the legacy event config interface Lars-Peter Clausen
2013-10-12 11:24 ` [PATCH v2 01/20] iio: Factor IIO value formating into its own function Jonathan Cameron

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=52593AD9.600@kernel.org \
    --to=jic23@kernel.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).