diff mbox series

[3/3] staging: iio: ad7780: generates pattern_mask from PAT bits

Message ID f7925df556f37f48ae0b1707239aff5a108fea1d.1541615978.git.giuliano.belinassi@usp.br (mailing list archive)
State New, archived
Headers show
Series staging: iio: ad7780: pattern generation and gain update | expand

Commit Message

Giuliano Belinassi Nov. 7, 2018, 6:50 p.m. UTC
Previously, all pattern_masks in the chip_info table were hardcoded. Now they
are generated using the PAT macros, as described in the datasheets.

Signed-off-by: Giuliano Belinassi <giuliano.belinassi@usp.br>
---
 drivers/staging/iio/adc/ad7780.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

Comments

Alexandru Ardelean Nov. 8, 2018, 7:45 a.m. UTC | #1
On Wed, 2018-11-07 at 16:50 -0200, Giuliano Belinassi wrote:
> Previously, all pattern_masks in the chip_info table were hardcoded. Now
> they
> are generated using the PAT macros, as described in the datasheets.
> 

I like this change :)
I only have nitpicks.
See inline.


> Signed-off-by: Giuliano Belinassi <giuliano.belinassi@usp.br>
> ---
>  drivers/staging/iio/adc/ad7780.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/staging/iio/adc/ad7780.c
> b/drivers/staging/iio/adc/ad7780.c
> index 0a473aae52f2..fa9e047b5191 100644
> --- a/drivers/staging/iio/adc/ad7780.c
> +++ b/drivers/staging/iio/adc/ad7780.c
> @@ -31,6 +31,8 @@
>  #define AD7780_PAT1	BIT(1)
>  #define AD7780_PAT0	BIT(0)
>  
> +#define AD7170_PAT2	BIT(2)
> +
>  struct ad7780_chip_info {
>  	struct iio_chan_spec	channel;
>  	unsigned int		pattern_mask;
> @@ -137,25 +139,25 @@ static const struct ad7780_chip_info
> ad7780_chip_info_tbl[] = {
>  	[ID_AD7170] = {
>  		.channel = AD7780_CHANNEL(12, 24),
>  		.pattern = 0x5,
> -		.pattern_mask = 0x7,
> +		.pattern_mask = AD7780_PAT0 | AD7780_PAT1 | AD7170_PAT2,

If you are updating these pattern masks, you should update the default
patterns as well with the macros to be consistent.

And to be a bit more compact, you could define:

#define AD7170_PATTERN_MASK	(AD7780_PAT0 | AD7780_PAT1 | AD7170_PAT2)
#d
efine AD7780_PATTERN_MASK	(AD7780_PAT0 | AD7780_PAT1)

#define AD7170_PATTERN		(AD7780_PAT1 | AD7170_PAT2)
#define AD7780_PATTERN		(AD7780_PAT0)

Then you can assign AD7170_PATTERN[_MASK] to AD7170/AD7171 & 
AD7780_PATTERN[_MASK] to AD7780/AD7781.

>  		.is_ad778x = false,
>  	},
>  	[ID_AD7171] = {
>  		.channel = AD7780_CHANNEL(16, 24),
>  		.pattern = 0x5,
> -		.pattern_mask = 0x7,
> +		.pattern_mask = AD7780_PAT0 | AD7780_PAT1 | AD7170_PAT2,
>  		.is_ad778x = false,
>  	},
>  	[ID_AD7780] = {
>  		.channel = AD7780_CHANNEL(24, 32),
>  		.pattern = 0x1,
> -		.pattern_mask = 0x3,
> +		.pattern_mask = AD7780_PAT0 | AD7780_PAT1,
>  		.is_ad778x = true,
>  	},
>  	[ID_AD7781] = {
>  		.channel = AD7780_CHANNEL(20, 32),
>  		.pattern = 0x1,
> -		.pattern_mask = 0x3,
> +		.pattern_mask = AD7780_PAT0 | AD7780_PAT1,
>  		.is_ad778x = true,
>  	},
>  };
diff mbox series

Patch

diff --git a/drivers/staging/iio/adc/ad7780.c b/drivers/staging/iio/adc/ad7780.c
index 0a473aae52f2..fa9e047b5191 100644
--- a/drivers/staging/iio/adc/ad7780.c
+++ b/drivers/staging/iio/adc/ad7780.c
@@ -31,6 +31,8 @@ 
 #define AD7780_PAT1	BIT(1)
 #define AD7780_PAT0	BIT(0)
 
+#define AD7170_PAT2	BIT(2)
+
 struct ad7780_chip_info {
 	struct iio_chan_spec	channel;
 	unsigned int		pattern_mask;
@@ -137,25 +139,25 @@  static const struct ad7780_chip_info ad7780_chip_info_tbl[] = {
 	[ID_AD7170] = {
 		.channel = AD7780_CHANNEL(12, 24),
 		.pattern = 0x5,
-		.pattern_mask = 0x7,
+		.pattern_mask = AD7780_PAT0 | AD7780_PAT1 | AD7170_PAT2,
 		.is_ad778x = false,
 	},
 	[ID_AD7171] = {
 		.channel = AD7780_CHANNEL(16, 24),
 		.pattern = 0x5,
-		.pattern_mask = 0x7,
+		.pattern_mask = AD7780_PAT0 | AD7780_PAT1 | AD7170_PAT2,
 		.is_ad778x = false,
 	},
 	[ID_AD7780] = {
 		.channel = AD7780_CHANNEL(24, 32),
 		.pattern = 0x1,
-		.pattern_mask = 0x3,
+		.pattern_mask = AD7780_PAT0 | AD7780_PAT1,
 		.is_ad778x = true,
 	},
 	[ID_AD7781] = {
 		.channel = AD7780_CHANNEL(20, 32),
 		.pattern = 0x1,
-		.pattern_mask = 0x3,
+		.pattern_mask = AD7780_PAT0 | AD7780_PAT1,
 		.is_ad778x = true,
 	},
 };