linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Peter Meerwald <pmeerw@pmeerw.net>, linux-iio@vger.kernel.org
Subject: Re: [PATCH v3 05/12] iio:adc:ad799x: Use BIT() and GENMASK()
Date: Sun, 13 Jul 2014 21:56:28 +0100	[thread overview]
Message-ID: <53C2F27C.2080800@kernel.org> (raw)
In-Reply-To: <1402548856-3564-6-git-send-email-pmeerw@pmeerw.net>

On 12/06/14 05:54, Peter Meerwald wrote:
> Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
> Acked-by: Lars-Peter Clausen <lars@metafoo.de>
Applied
> ---
>   drivers/iio/adc/ad799x.c | 31 +++++++++++++++----------------
>   1 file changed, 15 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/iio/adc/ad799x.c b/drivers/iio/adc/ad799x.c
> index 878400c..b3799a8 100644
> --- a/drivers/iio/adc/ad799x.c
> +++ b/drivers/iio/adc/ad799x.c
> @@ -32,6 +32,7 @@
>   #include <linux/types.h>
>   #include <linux/err.h>
>   #include <linux/module.h>
> +#include <linux/bitops.h>
>
>   #include <linux/iio/iio.h>
>   #include <linux/iio/sysfs.h>
> @@ -41,7 +42,7 @@
>   #include <linux/iio/triggered_buffer.h>
>
>   #define AD799X_CHANNEL_SHIFT			4
> -#define AD799X_STORAGEBITS			16
> +
>   /*
>    * AD7991, AD7995 and AD7999 defines
>    */
> @@ -55,10 +56,10 @@
>    * AD7992, AD7993, AD7994, AD7997 and AD7998 defines
>    */
>
> -#define AD7998_FLTR				0x08
> -#define AD7998_ALERT_EN				0x04
> -#define AD7998_BUSY_ALERT			0x02
> -#define AD7998_BUSY_ALERT_POL			0x01
> +#define AD7998_FLTR				BIT(3)
> +#define AD7998_ALERT_EN				BIT(2)
> +#define AD7998_BUSY_ALERT			BIT(1)
> +#define AD7998_BUSY_ALERT_POL			BIT(0)
>
>   #define AD7998_CONV_RES_REG			0x0
>   #define AD7998_ALERT_STAT_REG			0x1
> @@ -69,7 +70,7 @@
>   #define AD7998_DATAHIGH_REG(x)			((x) * 3 + 0x5)
>   #define AD7998_HYST_REG(x)			((x) * 3 + 0x6)
>
> -#define AD7998_CYC_MASK				0x7
> +#define AD7998_CYC_MASK				GENMASK(2, 0)
>   #define AD7998_CYC_DIS				0x0
>   #define AD7998_CYC_TCONF_32			0x1
>   #define AD7998_CYC_TCONF_64			0x2
> @@ -85,10 +86,8 @@
>    * AD7997 and AD7997 defines
>    */
>
> -#define AD7997_8_READ_SINGLE			0x80
> -#define AD7997_8_READ_SEQUENCE			0x70
> -/* TODO: move this into a common header */
> -#define RES_MASK(bits)	((1 << (bits)) - 1)
> +#define AD7997_8_READ_SINGLE			BIT(7)
> +#define AD7997_8_READ_SEQUENCE			(BIT(6) | BIT(5) | BIT(4))
>
>   enum {
>   	ad7991,
> @@ -205,12 +204,12 @@ static int ad799x_scan_direct(struct ad799x_state *st, unsigned ch)
>   	case ad7991:
>   	case ad7995:
>   	case ad7999:
> -		cmd = st->config | ((1 << ch) << AD799X_CHANNEL_SHIFT);
> +		cmd = st->config | (BIT(ch) << AD799X_CHANNEL_SHIFT);
>   		break;
>   	case ad7992:
>   	case ad7993:
>   	case ad7994:
> -		cmd = (1 << ch) << AD799X_CHANNEL_SHIFT;
> +		cmd = BIT(ch) << AD799X_CHANNEL_SHIFT;
>   		break;
>   	case ad7997:
>   	case ad7998:
> @@ -244,7 +243,7 @@ static int ad799x_read_raw(struct iio_dev *indio_dev,
>   		if (ret < 0)
>   			return ret;
>   		*val = (ret >> chan->scan_type.shift) &
> -			RES_MASK(chan->scan_type.realbits);
> +			GENMASK(chan->scan_type.realbits - 1, 0);
>   		return IIO_VAL_INT;
>   	case IIO_CHAN_INFO_SCALE:
>   		ret = regulator_get_voltage(st->vref);
> @@ -359,7 +358,7 @@ static int ad799x_write_event_value(struct iio_dev *indio_dev,
>   	int ret;
>   	struct ad799x_state *st = iio_priv(indio_dev);
>
> -	if (val < 0 || val > RES_MASK(chan->scan_type.realbits))
> +	if (val < 0 || val > GENMASK(chan->scan_type.realbits - 1, 0))
>   		return -EINVAL;
>
>   	mutex_lock(&indio_dev->mlock);
> @@ -388,7 +387,7 @@ static int ad799x_read_event_value(struct iio_dev *indio_dev,
>   	if (ret < 0)
>   		return ret;
>   	*val = (ret >> chan->scan_type.shift) &
> -		RES_MASK(chan->scan_type.realbits);
> +		GENMASK(chan->scan_type.realbits - 1 , 0);
>
>   	return IIO_VAL_INT;
>   }
> @@ -408,7 +407,7 @@ static irqreturn_t ad799x_event_handler(int irq, void *private)
>   		goto done;
>
>   	for (i = 0; i < 8; i++) {
> -		if (ret & (1 << i))
> +		if (ret & BIT(i))
>   			iio_push_event(indio_dev,
>   				       i & 0x1 ?
>   				       IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE,
>


  reply	other threads:[~2014-07-13 20:54 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-12  4:54 [PATCH v3 00/12] ad799x cleanup Peter Meerwald
2014-06-12  4:54 ` [PATCH v3 01/12] iio:adc:ad799x: Fix reading and writing of event values, apply shift Peter Meerwald
2014-06-12  8:07   ` Lars-Peter Clausen
2014-06-14 14:19     ` Jonathan Cameron
2014-06-29 14:47       ` Jonathan Cameron
2014-06-12  4:54 ` [PATCH v3 02/12] iio:adc:ad799x: Fix ad799x_chip_info kerneldoc Peter Meerwald
2014-06-14 14:21   ` Jonathan Cameron
2014-06-12  4:54 ` [PATCH v3 03/12] iio:adc:ad799x: Drop I2C access helper functions Peter Meerwald
2014-06-12  8:10   ` Lars-Peter Clausen
2014-06-14 14:26     ` Jonathan Cameron
2014-07-13 20:47     ` Jonathan Cameron
2014-06-12  4:54 ` [PATCH v3 04/12] iio:adc:ad799x: Save some lines in ad7997_8_update_scan_mode() exit handling Peter Meerwald
2014-07-13 20:56   ` Jonathan Cameron
2014-06-12  4:54 ` [PATCH v3 05/12] iio:adc:ad799x: Use BIT() and GENMASK() Peter Meerwald
2014-07-13 20:56   ` Jonathan Cameron [this message]
2014-06-12  4:54 ` [PATCH v3 06/12] iio:adc:ad799x: Only expose event interface when IRQ is available Peter Meerwald
2014-07-13 20:56   ` Jonathan Cameron
2014-06-12  4:54 ` [PATCH v3 07/12] iio:adc:ad799x: Make chan_spec const in ad799x_chip_config struct Peter Meerwald
2014-07-13 20:57   ` Jonathan Cameron
2014-06-12  4:54 ` [PATCH v3 08/12] iio:adc:ad799x: Add helper function to read/write config register Peter Meerwald
2014-07-13 20:57   ` Jonathan Cameron
2014-06-12  4:54 ` [PATCH v3 09/12] iio:adc:ad799x: Write default config on probe and reset alert status on probe Peter Meerwald
2014-07-13 20:58   ` Jonathan Cameron
2014-06-12  4:54 ` [PATCH v3 10/12] iio:adc:ad799x: Set conversion channels and rename ad7997_8_update_scan_mode() Peter Meerwald
2014-07-13 20:58   ` Jonathan Cameron
2014-06-12  4:54 ` [PATCH v3 11/12] iio:adc:ad799x: Return more meaningful event enabled state Peter Meerwald
2014-06-12  8:08   ` Lars-Peter Clausen
2014-07-13 20:59     ` Jonathan Cameron
2014-06-12  4:54 ` [PATCH v3 12/12] iio:adc:ad799x: Allow to write event config Peter Meerwald
2014-06-12  8:08   ` Lars-Peter Clausen
2014-07-13 21:01     ` 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=53C2F27C.2080800@kernel.org \
    --to=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=pmeerw@pmeerw.net \
    /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).