linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] staging:iio:impedance-analyzer:ad5933: Macro replacement Cleanups.
@ 2018-06-25 19:11 Karim Eshapa
  2018-06-30 17:22 ` Jonathan Cameron
  0 siblings, 1 reply; 2+ messages in thread
From: Karim Eshapa @ 2018-06-25 19:11 UTC (permalink / raw)
  To: lars
  Cc: Michael.Hennerich, jic23, knaack.h, pmeerw, gregkh, linux-iio,
	devel, linux-kernel, Karim Eshapa

Doing some macro replacement to start an array of structures
so it can be reused by manipulating it with different values.

Signed-off-by: Karim Eshapa <karim.eshapa@gmail.com>
---
 .../staging/iio/impedance-analyzer/ad5933.c   | 57 +++++++------------
 1 file changed, 19 insertions(+), 38 deletions(-)

diff --git a/drivers/staging/iio/impedance-analyzer/ad5933.c b/drivers/staging/iio/impedance-analyzer/ad5933.c
index 3bcf49466361..14df89510396 100644
--- a/drivers/staging/iio/impedance-analyzer/ad5933.c
+++ b/drivers/staging/iio/impedance-analyzer/ad5933.c
@@ -116,45 +116,26 @@ static struct ad5933_platform_data ad5933_default_pdata  = {
 	.vref_mv = 3300,
 };
 
+#define AD5933_CHANNEL(_type, _extend_name, _info_mask_separate, _address, \
+		_scan_index, _realbits) { \
+	.type = (_type), \
+	.extend_name = (_extend_name), \
+	.info_mask_separate = (_info_mask_separate), \
+	.address = (_address), \
+	.scan_index = (_scan_index), \
+	.scan_type = { \
+		.sign = 's', \
+		.realbits = (_realbits), \
+		.storagebits = 16, \
+	}, \
+}
+
 static const struct iio_chan_spec ad5933_channels[] = {
-	{
-		.type = IIO_TEMP,
-		.indexed = 1,
-		.channel = 0,
-		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
-			BIT(IIO_CHAN_INFO_SCALE),
-		.address = AD5933_REG_TEMP_DATA,
-		.scan_index = -1,
-		.scan_type = {
-			.sign = 's',
-			.realbits = 14,
-			.storagebits = 16,
-		},
-	}, { /* Ring Channels */
-		.type = IIO_VOLTAGE,
-		.indexed = 1,
-		.channel = 0,
-		.extend_name = "real",
-		.address = AD5933_REG_REAL_DATA,
-		.scan_index = 0,
-		.scan_type = {
-			.sign = 's',
-			.realbits = 16,
-			.storagebits = 16,
-		},
-	}, {
-		.type = IIO_VOLTAGE,
-		.indexed = 1,
-		.channel = 0,
-		.extend_name = "imag",
-		.address = AD5933_REG_IMAG_DATA,
-		.scan_index = 1,
-		.scan_type = {
-			.sign = 's',
-			.realbits = 16,
-			.storagebits = 16,
-		},
-	},
+	AD5933_CHANNEL(IIO_TEMP, NULL, BIT(IIO_CHAN_INFO_RAW) |
+		BIT(IIO_CHAN_INFO_SCALE), AD5933_REG_TEMP_DATA, -1, 14),
+	/* Ring Channels */
+	AD5933_CHANNEL(IIO_VOLTAGE, "real", 0, AD5933_REG_REAL_DATA, 0, 16),
+	AD5933_CHANNEL(IIO_VOLTAGE, "imag", 0, AD5933_REG_IMAG_DATA, 1, 16),
 };
 
 static int ad5933_i2c_write(struct i2c_client *client, u8 reg, u8 len, u8 *data)
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] staging:iio:impedance-analyzer:ad5933: Macro replacement Cleanups.
  2018-06-25 19:11 [PATCH v2] staging:iio:impedance-analyzer:ad5933: Macro replacement Cleanups Karim Eshapa
@ 2018-06-30 17:22 ` Jonathan Cameron
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2018-06-30 17:22 UTC (permalink / raw)
  To: Karim Eshapa
  Cc: lars, Michael.Hennerich, knaack.h, pmeerw, gregkh, linux-iio,
	devel, linux-kernel

On Mon, 25 Jun 2018 21:11:23 +0200
Karim Eshapa <karim.eshapa@gmail.com> wrote:

> Doing some macro replacement to start an array of structures
> so it can be reused by manipulating it with different values.
> 
> Signed-off-by: Karim Eshapa <karim.eshapa@gmail.com>
There are all sorts of issues with the ABI this driver is providing to
userspace, but this isn't a bad bit of cleanup none the less.

Applied to the togreg branch of iio.git and pushed out as testing
for the autobuilders to play with it.

Thanks,

Jonathan

> ---
>  .../staging/iio/impedance-analyzer/ad5933.c   | 57 +++++++------------
>  1 file changed, 19 insertions(+), 38 deletions(-)
> 
> diff --git a/drivers/staging/iio/impedance-analyzer/ad5933.c b/drivers/staging/iio/impedance-analyzer/ad5933.c
> index 3bcf49466361..14df89510396 100644
> --- a/drivers/staging/iio/impedance-analyzer/ad5933.c
> +++ b/drivers/staging/iio/impedance-analyzer/ad5933.c
> @@ -116,45 +116,26 @@ static struct ad5933_platform_data ad5933_default_pdata  = {
>  	.vref_mv = 3300,
>  };
>  
> +#define AD5933_CHANNEL(_type, _extend_name, _info_mask_separate, _address, \
> +		_scan_index, _realbits) { \
> +	.type = (_type), \
> +	.extend_name = (_extend_name), \
> +	.info_mask_separate = (_info_mask_separate), \
> +	.address = (_address), \
> +	.scan_index = (_scan_index), \
> +	.scan_type = { \
> +		.sign = 's', \
> +		.realbits = (_realbits), \
> +		.storagebits = 16, \
> +	}, \
> +}
> +
>  static const struct iio_chan_spec ad5933_channels[] = {
> -	{
> -		.type = IIO_TEMP,
> -		.indexed = 1,
> -		.channel = 0,
> -		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
> -			BIT(IIO_CHAN_INFO_SCALE),
> -		.address = AD5933_REG_TEMP_DATA,
> -		.scan_index = -1,
> -		.scan_type = {
> -			.sign = 's',
> -			.realbits = 14,
> -			.storagebits = 16,
> -		},
> -	}, { /* Ring Channels */
> -		.type = IIO_VOLTAGE,
> -		.indexed = 1,
> -		.channel = 0,
> -		.extend_name = "real",
> -		.address = AD5933_REG_REAL_DATA,
> -		.scan_index = 0,
> -		.scan_type = {
> -			.sign = 's',
> -			.realbits = 16,
> -			.storagebits = 16,
> -		},
> -	}, {
> -		.type = IIO_VOLTAGE,
> -		.indexed = 1,
> -		.channel = 0,
> -		.extend_name = "imag",
> -		.address = AD5933_REG_IMAG_DATA,
> -		.scan_index = 1,
> -		.scan_type = {
> -			.sign = 's',
> -			.realbits = 16,
> -			.storagebits = 16,
> -		},
> -	},
> +	AD5933_CHANNEL(IIO_TEMP, NULL, BIT(IIO_CHAN_INFO_RAW) |
> +		BIT(IIO_CHAN_INFO_SCALE), AD5933_REG_TEMP_DATA, -1, 14),
> +	/* Ring Channels */
> +	AD5933_CHANNEL(IIO_VOLTAGE, "real", 0, AD5933_REG_REAL_DATA, 0, 16),
> +	AD5933_CHANNEL(IIO_VOLTAGE, "imag", 0, AD5933_REG_IMAG_DATA, 1, 16),
>  };
>  
>  static int ad5933_i2c_write(struct i2c_client *client, u8 reg, u8 len, u8 *data)


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-06-30 17:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-06-25 19:11 [PATCH v2] staging:iio:impedance-analyzer:ad5933: Macro replacement Cleanups Karim Eshapa
2018-06-30 17:22 ` Jonathan Cameron

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).