diff options
author | Peter Meerwald <pmeerw@pmeerw.net> | 2014-12-06 00:54:00 -0500 |
---|---|---|
committer | Jonathan Cameron <jic23@kernel.org> | 2014-07-13 16:55:42 -0400 |
commit | e1c6e2a2173c88c1be6a43df407567ae1c11cc22 (patch) | |
tree | c4e6f514cb6c54e7b6b1bc8f946234887627e859 /drivers/iio/adc/ad799x.c | |
parent | bd3bd4328a6743b836c9759f7510cd0ad6580a23 (diff) |
iio:adc:ad799x: Use BIT() and GENMASK()
Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
Acked-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Diffstat (limited to 'drivers/iio/adc/ad799x.c')
-rw-r--r-- | drivers/iio/adc/ad799x.c | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/drivers/iio/adc/ad799x.c b/drivers/iio/adc/ad799x.c index 878400c33137..b3799a8056c8 100644 --- a/drivers/iio/adc/ad799x.c +++ b/drivers/iio/adc/ad799x.c | |||
@@ -32,6 +32,7 @@ | |||
32 | #include <linux/types.h> | 32 | #include <linux/types.h> |
33 | #include <linux/err.h> | 33 | #include <linux/err.h> |
34 | #include <linux/module.h> | 34 | #include <linux/module.h> |
35 | #include <linux/bitops.h> | ||
35 | 36 | ||
36 | #include <linux/iio/iio.h> | 37 | #include <linux/iio/iio.h> |
37 | #include <linux/iio/sysfs.h> | 38 | #include <linux/iio/sysfs.h> |
@@ -41,7 +42,7 @@ | |||
41 | #include <linux/iio/triggered_buffer.h> | 42 | #include <linux/iio/triggered_buffer.h> |
42 | 43 | ||
43 | #define AD799X_CHANNEL_SHIFT 4 | 44 | #define AD799X_CHANNEL_SHIFT 4 |
44 | #define AD799X_STORAGEBITS 16 | 45 | |
45 | /* | 46 | /* |
46 | * AD7991, AD7995 and AD7999 defines | 47 | * AD7991, AD7995 and AD7999 defines |
47 | */ | 48 | */ |
@@ -55,10 +56,10 @@ | |||
55 | * AD7992, AD7993, AD7994, AD7997 and AD7998 defines | 56 | * AD7992, AD7993, AD7994, AD7997 and AD7998 defines |
56 | */ | 57 | */ |
57 | 58 | ||
58 | #define AD7998_FLTR 0x08 | 59 | #define AD7998_FLTR BIT(3) |
59 | #define AD7998_ALERT_EN 0x04 | 60 | #define AD7998_ALERT_EN BIT(2) |
60 | #define AD7998_BUSY_ALERT 0x02 | 61 | #define AD7998_BUSY_ALERT BIT(1) |
61 | #define AD7998_BUSY_ALERT_POL 0x01 | 62 | #define AD7998_BUSY_ALERT_POL BIT(0) |
62 | 63 | ||
63 | #define AD7998_CONV_RES_REG 0x0 | 64 | #define AD7998_CONV_RES_REG 0x0 |
64 | #define AD7998_ALERT_STAT_REG 0x1 | 65 | #define AD7998_ALERT_STAT_REG 0x1 |
@@ -69,7 +70,7 @@ | |||
69 | #define AD7998_DATAHIGH_REG(x) ((x) * 3 + 0x5) | 70 | #define AD7998_DATAHIGH_REG(x) ((x) * 3 + 0x5) |
70 | #define AD7998_HYST_REG(x) ((x) * 3 + 0x6) | 71 | #define AD7998_HYST_REG(x) ((x) * 3 + 0x6) |
71 | 72 | ||
72 | #define AD7998_CYC_MASK 0x7 | 73 | #define AD7998_CYC_MASK GENMASK(2, 0) |
73 | #define AD7998_CYC_DIS 0x0 | 74 | #define AD7998_CYC_DIS 0x0 |
74 | #define AD7998_CYC_TCONF_32 0x1 | 75 | #define AD7998_CYC_TCONF_32 0x1 |
75 | #define AD7998_CYC_TCONF_64 0x2 | 76 | #define AD7998_CYC_TCONF_64 0x2 |
@@ -85,10 +86,8 @@ | |||
85 | * AD7997 and AD7997 defines | 86 | * AD7997 and AD7997 defines |
86 | */ | 87 | */ |
87 | 88 | ||
88 | #define AD7997_8_READ_SINGLE 0x80 | 89 | #define AD7997_8_READ_SINGLE BIT(7) |
89 | #define AD7997_8_READ_SEQUENCE 0x70 | 90 | #define AD7997_8_READ_SEQUENCE (BIT(6) | BIT(5) | BIT(4)) |
90 | /* TODO: move this into a common header */ | ||
91 | #define RES_MASK(bits) ((1 << (bits)) - 1) | ||
92 | 91 | ||
93 | enum { | 92 | enum { |
94 | ad7991, | 93 | ad7991, |
@@ -205,12 +204,12 @@ static int ad799x_scan_direct(struct ad799x_state *st, unsigned ch) | |||
205 | case ad7991: | 204 | case ad7991: |
206 | case ad7995: | 205 | case ad7995: |
207 | case ad7999: | 206 | case ad7999: |
208 | cmd = st->config | ((1 << ch) << AD799X_CHANNEL_SHIFT); | 207 | cmd = st->config | (BIT(ch) << AD799X_CHANNEL_SHIFT); |
209 | break; | 208 | break; |
210 | case ad7992: | 209 | case ad7992: |
211 | case ad7993: | 210 | case ad7993: |
212 | case ad7994: | 211 | case ad7994: |
213 | cmd = (1 << ch) << AD799X_CHANNEL_SHIFT; | 212 | cmd = BIT(ch) << AD799X_CHANNEL_SHIFT; |
214 | break; | 213 | break; |
215 | case ad7997: | 214 | case ad7997: |
216 | case ad7998: | 215 | case ad7998: |
@@ -244,7 +243,7 @@ static int ad799x_read_raw(struct iio_dev *indio_dev, | |||
244 | if (ret < 0) | 243 | if (ret < 0) |
245 | return ret; | 244 | return ret; |
246 | *val = (ret >> chan->scan_type.shift) & | 245 | *val = (ret >> chan->scan_type.shift) & |
247 | RES_MASK(chan->scan_type.realbits); | 246 | GENMASK(chan->scan_type.realbits - 1, 0); |
248 | return IIO_VAL_INT; | 247 | return IIO_VAL_INT; |
249 | case IIO_CHAN_INFO_SCALE: | 248 | case IIO_CHAN_INFO_SCALE: |
250 | ret = regulator_get_voltage(st->vref); | 249 | ret = regulator_get_voltage(st->vref); |
@@ -359,7 +358,7 @@ static int ad799x_write_event_value(struct iio_dev *indio_dev, | |||
359 | int ret; | 358 | int ret; |
360 | struct ad799x_state *st = iio_priv(indio_dev); | 359 | struct ad799x_state *st = iio_priv(indio_dev); |
361 | 360 | ||
362 | if (val < 0 || val > RES_MASK(chan->scan_type.realbits)) | 361 | if (val < 0 || val > GENMASK(chan->scan_type.realbits - 1, 0)) |
363 | return -EINVAL; | 362 | return -EINVAL; |
364 | 363 | ||
365 | mutex_lock(&indio_dev->mlock); | 364 | mutex_lock(&indio_dev->mlock); |
@@ -388,7 +387,7 @@ static int ad799x_read_event_value(struct iio_dev *indio_dev, | |||
388 | if (ret < 0) | 387 | if (ret < 0) |
389 | return ret; | 388 | return ret; |
390 | *val = (ret >> chan->scan_type.shift) & | 389 | *val = (ret >> chan->scan_type.shift) & |
391 | RES_MASK(chan->scan_type.realbits); | 390 | GENMASK(chan->scan_type.realbits - 1 , 0); |
392 | 391 | ||
393 | return IIO_VAL_INT; | 392 | return IIO_VAL_INT; |
394 | } | 393 | } |
@@ -408,7 +407,7 @@ static irqreturn_t ad799x_event_handler(int irq, void *private) | |||
408 | goto done; | 407 | goto done; |
409 | 408 | ||
410 | for (i = 0; i < 8; i++) { | 409 | for (i = 0; i < 8; i++) { |
411 | if (ret & (1 << i)) | 410 | if (ret & BIT(i)) |
412 | iio_push_event(indio_dev, | 411 | iio_push_event(indio_dev, |
413 | i & 0x1 ? | 412 | i & 0x1 ? |
414 | IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE, | 413 | IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE, |