Skip to contentSkip to conversation

adis16209 driver cleanup

PATCH In review Shreeya Patel 4 participants 13 messages Feb 17, 2018 – Feb 18, 2018

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover adis16209 driver cleanup

This patchset has been introduced for the cleanup of adis16209 driver.
This patchset cleans up miscellaneous code fragments and improves the code readability.

Shreeya Patel (3):
Staging: iio: adis16209: Use SPDX identifier
Staging: iio: adis16209: Remove unnecessary comments and add suitable
suffix
Staging: iio: adis16209: Use sign_extend32 and adjust a switch
statement

 drivers/staging/iio/accel/adis16209.c | 231 ++++++++++++----------------------
 1 file changed, 82 insertions(+), 149 deletions(-)
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/3 Staging: iio: adis16209: Use SPDX identifier

Use SPDX identifier format instead of GPLv2. Also rearrange the headers in alphabetical order.

---
 drivers/staging/iio/accel/adis16209.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/staging/iio/accel/adis16209.c +3 -4
index 7fcef9a..e3d9f80 100644
@@ -1,19 +1,18 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * ADIS16209 Dual-Axis Digital Inclinometer and Accelerometer
  *
  * Copyright 2010 Analog Devices Inc.
- *
- * Licensed under the GPL-2 or later.
  */
 
 #include <linux/delay.h>
 #include <linux/device.h>
 #include <linux/kernel.h>
+#include <linux/list.h>
+#include <linux/module.h>
 #include <linux/spi/spi.h>
 #include <linux/slab.h>
 #include <linux/sysfs.h>
-#include <linux/list.h>
-#include <linux/module.h>
 
 #include <linux/iio/iio.h>
 #include <linux/iio/sysfs.h>
Signature · 1 line
2.7.4
#9 lore raw

PATCH 2/3 Staging: iio: adis16209: Remove unnecessary comments and add suitable suffix

In reply to Shreeya Patel

Remove some unnecessary comments and therefore, add _REG suffix for registers. Group the control register and register field macros together.
Also, align function arguments to match open parentheses using tabs.

---
 drivers/staging/iio/accel/adis16209.c | 209 +++++++++++-----------------------
 1 file changed, 69 insertions(+), 140 deletions(-)
drivers/staging/iio/accel/adis16209.c +69 -140
index e3d9f80..6101212 100644
@@ -19,136 +19,67 @@
 #include <linux/iio/buffer.h>
 #include <linux/iio/imu/adis.h>
 
-#define ADIS16209_STARTUP_DELAY	220 /* ms */
-
-/* Flash memory write count */
-#define ADIS16209_FLASH_CNT      0x00
-
-/* Output, power supply */
-#define ADIS16209_SUPPLY_OUT     0x02
-
-/* Output, x-axis accelerometer */
-#define ADIS16209_XACCL_OUT      0x04
-
-/* Output, y-axis accelerometer */
-#define ADIS16209_YACCL_OUT      0x06
-
-/* Output, auxiliary ADC input */
-#define ADIS16209_AUX_ADC        0x08
-
-/* Output, temperature */
-#define ADIS16209_TEMP_OUT       0x0A
-
-/* Output, x-axis inclination */
-#define ADIS16209_XINCL_OUT      0x0C
-
-/* Output, y-axis inclination */
-#define ADIS16209_YINCL_OUT      0x0E
-
-/* Output, +/-180 vertical rotational position */
-#define ADIS16209_ROT_OUT        0x10
-
-/* Calibration, x-axis acceleration offset null */
-#define ADIS16209_XACCL_NULL     0x12
-
-/* Calibration, y-axis acceleration offset null */
-#define ADIS16209_YACCL_NULL     0x14
-
-/* Calibration, x-axis inclination offset null */
-#define ADIS16209_XINCL_NULL     0x16
-
-/* Calibration, y-axis inclination offset null */
-#define ADIS16209_YINCL_NULL     0x18
-
-/* Calibration, vertical rotation offset null */
-#define ADIS16209_ROT_NULL       0x1A
-
-/* Alarm 1 amplitude threshold */
-#define ADIS16209_ALM_MAG1       0x20
-
-/* Alarm 2 amplitude threshold */
-#define ADIS16209_ALM_MAG2       0x22
-
-/* Alarm 1, sample period */
-#define ADIS16209_ALM_SMPL1      0x24
-
-/* Alarm 2, sample period */
-#define ADIS16209_ALM_SMPL2      0x26
-
-/* Alarm control */
-#define ADIS16209_ALM_CTRL       0x28
-
-/* Auxiliary DAC data */
-#define ADIS16209_AUX_DAC        0x30
-
-/* General-purpose digital input/output control */
-#define ADIS16209_GPIO_CTRL      0x32
-
-/* Miscellaneous control */
-#define ADIS16209_MSC_CTRL       0x34
-
-/* Internal sample period (rate) control */
-#define ADIS16209_SMPL_PRD       0x36
-
-/* Operation, filter configuration */
-#define ADIS16209_AVG_CNT        0x38
-
-/* Operation, sleep mode control */
-#define ADIS16209_SLP_CNT        0x3A
-
-/* Diagnostics, system status register */
-#define ADIS16209_DIAG_STAT      0x3C
-
-/* Operation, system command register */
-#define ADIS16209_GLOB_CMD       0x3E
+#define ADIS16209_STARTUP_DELAY_MS	220
+#define ADIS16209_FLASH_CNT_REG		0x00
+
+/* Data Output Register Definitions */
+#define ADIS16209_SUPPLY_OUT_REG	0x02
+#define ADIS16209_XACCL_OUT_REG		0x04
+#define ADIS16209_YACCL_OUT_REG		0x06
+#define ADIS16209_AUX_ADC_REG		0x08
+#define ADIS16209_TEMP_OUT_REG		0x0A
+#define ADIS16209_XINCL_OUT_REG		0x0C
+#define ADIS16209_YINCL_OUT_REG		0x0E
+#define ADIS16209_ROT_OUT_REG		0x10
+
+/* Calibration Register Definitions */
+#define ADIS16209_XACCL_NULL_REG	0x12
+#define ADIS16209_YACCL_NULL_REG	0x14
+#define ADIS16209_XINCL_NULL_REG	0x16
+#define ADIS16209_YINCL_NULL_REG	0x18
+#define ADIS16209_ROT_NULL_REG		0x1A
+
+/* Alarm Register Definitions */
+#define ADIS16209_ALM_MAG1_REG		0x20
+#define ADIS16209_ALM_MAG2_REG		0x22
+#define ADIS16209_ALM_SMPL1_REG		0x24
+#define ADIS16209_ALM_SMPL2_REG		0x26
+#define ADIS16209_ALM_CTRL_REG		0x28
+
+#define ADIS16209_AUX_DAC_REG		0x30
+#define ADIS16209_GPIO_CTRL_REG		0x32
+#define ADIS16209_SMPL_PRD_REG		0x36
+#define ADIS16209_AVG_CNT_REG		0x38
+#define ADIS16209_SLP_CNT_REG		0x3A
 
 /* MSC_CTRL */
 
-/* Self-test at power-on: 1 = disabled, 0 = enabled */
+#define ADIS16209_MSC_CTRL_REG			0x34
 #define ADIS16209_MSC_CTRL_PWRUP_SELF_TEST	BIT(10)
-
-/* Self-test enable */
-#define ADIS16209_MSC_CTRL_SELF_TEST_EN	        BIT(8)
-
-/* Data-ready enable: 1 = enabled, 0 = disabled */
-#define ADIS16209_MSC_CTRL_DATA_RDY_EN	        BIT(2)
-
-/* Data-ready polarity: 1 = active high, 0 = active low */
-#define ADIS16209_MSC_CTRL_ACTIVE_HIGH	        BIT(1)
-
-/* Data-ready line selection: 1 = DIO2, 0 = DIO1 */
-#define ADIS16209_MSC_CTRL_DATA_RDY_DIO2	BIT(0)
+#define ADIS16209_MSC_CTRL_SELF_TEST_EN		BIT(8)
+#define ADIS16209_MSC_CTRL_DATA_RDY_EN		BIT(2)
+#define ADIS16209_MSC_CTRL_ACTIVE_HIGH		BIT(1)
+#define ADIS16209_MSC_CTRL_DATA_RDY_DIO1	BIT(0)
 
 /* DIAG_STAT */
 
-/* Alarm 2 status: 1 = alarm active, 0 = alarm inactive */
-#define ADIS16209_DIAG_STAT_ALARM2        BIT(9)
-
-/* Alarm 1 status: 1 = alarm active, 0 = alarm inactive */
-#define ADIS16209_DIAG_STAT_ALARM1        BIT(8)
-
-/* Self-test diagnostic error flag: 1 = error condition, 0 = normal operation */
+#define ADIS16209_DIAG_STAT_REG			0x3C
+#define ADIS16209_DIAG_STAT_ALARM2		BIT(9)
+#define ADIS16209_DIAG_STAT_ALARM1		BIT(8)
 #define ADIS16209_DIAG_STAT_SELFTEST_FAIL_BIT	5
-
-/* SPI communications failure */
 #define ADIS16209_DIAG_STAT_SPI_FAIL_BIT	3
-
-/* Flash update failure */
 #define ADIS16209_DIAG_STAT_FLASH_UPT_BIT	2
-
-/* Power supply above 3.625 V */
 #define ADIS16209_DIAG_STAT_POWER_HIGH_BIT	1
-
-/* Power supply below 3.15 V */
 #define ADIS16209_DIAG_STAT_POWER_LOW_BIT	0
 
 /* GLOB_CMD */
 
-#define ADIS16209_GLOB_CMD_SW_RESET	BIT(7)
-#define ADIS16209_GLOB_CMD_CLEAR_STAT	BIT(4)
-#define ADIS16209_GLOB_CMD_FACTORY_CAL	BIT(1)
+#define ADIS16209_GLOB_CMD_REG			0x3E
+#define ADIS16209_GLOB_CMD_SW_RESET		BIT(7)
+#define ADIS16209_GLOB_CMD_CLEAR_STAT		BIT(4)
+#define ADIS16209_GLOB_CMD_FACTORY_CAL		BIT(1)
 
-#define ADIS16209_ERROR_ACTIVE          BIT(14)
+#define ADIS16209_ERROR_ACTIVE			BIT(14)
 
 enum adis16209_scan {
 	ADIS16209_SCAN_SUPPLY,
@@ -164,10 +95,10 @@ enum adis16209_scan {
 static const u8 adis16209_addresses[8][1] = {
 	[ADIS16209_SCAN_SUPPLY] = { },
 	[ADIS16209_SCAN_AUX_ADC] = { },
-	[ADIS16209_SCAN_ACC_X] = { ADIS16209_XACCL_NULL },
-	[ADIS16209_SCAN_ACC_Y] = { ADIS16209_YACCL_NULL },
-	[ADIS16209_SCAN_INCLI_X] = { ADIS16209_XINCL_NULL },
-	[ADIS16209_SCAN_INCLI_Y] = { ADIS16209_YINCL_NULL },
+	[ADIS16209_SCAN_ACC_X] = { ADIS16209_XACCL_NULL_REG },
+	[ADIS16209_SCAN_ACC_Y] = { ADIS16209_YACCL_NULL_REG },
+	[ADIS16209_SCAN_INCLI_X] = { ADIS16209_XINCL_NULL_REG },
+	[ADIS16209_SCAN_INCLI_Y] = { ADIS16209_YINCL_NULL_REG },
 	[ADIS16209_SCAN_ROT] = { },
 	[ADIS16209_SCAN_TEMP] = { },
 };
@@ -214,35 +145,35 @@ static int adis16209_read_raw(struct iio_dev *indio_dev,
 	switch (mask) {
 	case IIO_CHAN_INFO_RAW:
 		return adis_single_conversion(indio_dev, chan,
-			ADIS16209_ERROR_ACTIVE, val);
+					      ADIS16209_ERROR_ACTIVE, val);
 	case IIO_CHAN_INFO_SCALE:
 		switch (chan->type) {
 		case IIO_VOLTAGE:
 			*val = 0;
 			if (chan->channel == 0)
-				*val2 = 305180; /* 0.30518 mV */
+				*val2 = 305180;
 			else
-				*val2 = 610500; /* 0.6105 mV */
+				*val2 = 610500;
 			return IIO_VAL_INT_PLUS_MICRO;
 		case IIO_TEMP:
-			*val = -470; /* -0.47 C */
+			*val = -470;
 			*val2 = 0;
 			return IIO_VAL_INT_PLUS_MICRO;
 		case IIO_ACCEL:
 			*val = 0;
-			*val2 = IIO_G_TO_M_S_2(244140); /* 0.244140 mg */
+			*val2 = IIO_G_TO_M_S_2(244140);
 			return IIO_VAL_INT_PLUS_NANO;
 		case IIO_INCLI:
 		case IIO_ROT:
 			*val = 0;
-			*val2 = 25000; /* 0.025 degree */
+			*val2 = 25000;
 			return IIO_VAL_INT_PLUS_MICRO;
 		default:
 			return -EINVAL;
 		}
 		break;
 	case IIO_CHAN_INFO_OFFSET:
-		*val = 25000 / -470 - 0x4FE; /* 25 C = 0x4FE */
+		*val = 25000 / -470 - 0x4FE;
 		return IIO_VAL_INT;
 	case IIO_CHAN_INFO_CALIBBIAS:
 		switch (chan->type) {
@@ -265,18 +196,19 @@ static int adis16209_read_raw(struct iio_dev *indio_dev,
 }
 
 static const struct iio_chan_spec adis16209_channels[] = {
-	ADIS_SUPPLY_CHAN(ADIS16209_SUPPLY_OUT, ADIS16209_SCAN_SUPPLY, 0, 14),
-	ADIS_TEMP_CHAN(ADIS16209_TEMP_OUT, ADIS16209_SCAN_TEMP, 0, 12),
-	ADIS_ACCEL_CHAN(X, ADIS16209_XACCL_OUT, ADIS16209_SCAN_ACC_X,
+	ADIS_SUPPLY_CHAN(ADIS16209_SUPPLY_OUT_REG, ADIS16209_SCAN_SUPPLY,
+			 0, 14),
+	ADIS_TEMP_CHAN(ADIS16209_TEMP_OUT_REG, ADIS16209_SCAN_TEMP, 0, 12),
+	ADIS_ACCEL_CHAN(X, ADIS16209_XACCL_OUT_REG, ADIS16209_SCAN_ACC_X,
 			BIT(IIO_CHAN_INFO_CALIBBIAS), 0, 14),
-	ADIS_ACCEL_CHAN(Y, ADIS16209_YACCL_OUT, ADIS16209_SCAN_ACC_Y,
+	ADIS_ACCEL_CHAN(Y, ADIS16209_YACCL_OUT_REG, ADIS16209_SCAN_ACC_Y,
 			BIT(IIO_CHAN_INFO_CALIBBIAS), 0, 14),
-	ADIS_AUX_ADC_CHAN(ADIS16209_AUX_ADC, ADIS16209_SCAN_AUX_ADC, 0, 12),
-	ADIS_INCLI_CHAN(X, ADIS16209_XINCL_OUT, ADIS16209_SCAN_INCLI_X,
+	ADIS_AUX_ADC_CHAN(ADIS16209_AUX_ADC_REG, ADIS16209_SCAN_AUX_ADC, 0, 12),
+	ADIS_INCLI_CHAN(X, ADIS16209_XINCL_OUT_REG, ADIS16209_SCAN_INCLI_X,
 			0, 0, 14),
-	ADIS_INCLI_CHAN(Y, ADIS16209_YINCL_OUT, ADIS16209_SCAN_INCLI_Y,
+	ADIS_INCLI_CHAN(Y, ADIS16209_YINCL_OUT_REG, ADIS16209_SCAN_INCLI_Y,
 			0, 0, 14),
-	ADIS_ROT_CHAN(X, ADIS16209_ROT_OUT, ADIS16209_SCAN_ROT, 0, 0, 14),
+	ADIS_ROT_CHAN(X, ADIS16209_ROT_OUT_REG, ADIS16209_SCAN_ROT, 0, 0, 14),
 	IIO_CHAN_SOFT_TIMESTAMP(8)
 };
 
@@ -296,13 +228,13 @@ static const char * const adis16209_status_error_msgs[] = {
 
 static const struct adis_data adis16209_data = {
 	.read_delay = 30,
-	.msc_ctrl_reg = ADIS16209_MSC_CTRL,
-	.glob_cmd_reg = ADIS16209_GLOB_CMD,
-	.diag_stat_reg = ADIS16209_DIAG_STAT,
+	.msc_ctrl_reg = ADIS16209_MSC_CTRL_REG,
+	.glob_cmd_reg = ADIS16209_GLOB_CMD_REG,
+	.diag_stat_reg = ADIS16209_DIAG_STAT_REG,
 
 	.self_test_mask = ADIS16209_MSC_CTRL_SELF_TEST_EN,
 	.self_test_no_autoclear = true,
-	.startup_delay = ADIS16209_STARTUP_DELAY,
+	.startup_delay = ADIS16209_STARTUP_DELAY_MS,
 
 	.status_error_msgs = adis16209_status_error_msgs,
 	.status_error_mask = BIT(ADIS16209_DIAG_STAT_SELFTEST_FAIL_BIT) |
@@ -318,12 +250,10 @@ static int adis16209_probe(struct spi_device *spi)
 	struct adis *st;
 	struct iio_dev *indio_dev;
 
-	/* setup the industrialio driver allocated elements */
 	indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
 	if (!indio_dev)
 		return -ENOMEM;
 	st = iio_priv(indio_dev);
-	/* this is only used for removal purposes */
 	spi_set_drvdata(spi, indio_dev);
 
 	indio_dev->name = spi->dev.driver->name;
@@ -340,7 +270,6 @@ static int adis16209_probe(struct spi_device *spi)
 	if (ret)
 		return ret;
 
-	/* Get the device into a sane initial state */
 	ret = adis_initial_startup(st);
 	if (ret)
 		goto error_cleanup_buffer_trigger;
Signature · 1 line
2.7.4
#11 lore raw

PATCH 3/3 Staging: iio: adis16209: Use sign_extend32 and adjust a switch statement

In reply to Shreeya Patel

Use sign_extend32 function instead of manually coding it. Also, adjust a switch block to explicitly match channels and return -EINVAL as default case which improves code readability.

---
 drivers/staging/iio/accel/adis16209.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
drivers/staging/iio/accel/adis16209.c +10 -5
index 6101212..f7c228b 100644
@@ -150,10 +150,16 @@ static int adis16209_read_raw(struct iio_dev *indio_dev,
 		switch (chan->type) {
 		case IIO_VOLTAGE:
 			*val = 0;
-			if (chan->channel == 0)
+			switch (chan->channel) {
+			case 0:
 				*val2 = 305180;
-			else
+				break;
+			case 1:
 				*val2 = 610500;
+				break;
+			default:
+				return -EINVAL;
+			}
 			return IIO_VAL_INT_PLUS_MICRO;
 		case IIO_TEMP:
 			*val = -470;
@@ -187,9 +193,8 @@ static int adis16209_read_raw(struct iio_dev *indio_dev,
 		ret = adis_read_reg_16(st, addr, &val16);
 		if (ret)
 			return ret;
-		val16 &= (1 << bits) - 1;
-		val16 = (s16)(val16 << (16 - bits)) >> (16 - bits);
-		*val = val16;
+
+		*val = sign_extend32(val16, bits - 1);
 		return IIO_VAL_INT;
 	}
 	return -EINVAL;
Signature · 1 line
2.7.4
#2 lore raw

Re: [PATCH 1/3] Staging: iio: adis16209: Use SPDX identifier

In reply to Shreeya Patel

Hi Shreeya,

Quoted 13 lines · Shreeya Patel

Use SPDX identifier format instead of GPLv2. Also rearrange the headers in alphabetical order.

---
 drivers/staging/iio/accel/adis16209.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/staging/iio/accel/adis16209.c +0 -0
index 7fcef9a..e3d9f80 100644

drivers/staging/iio/accel/adis16209.c line 6

Quoted 7 lines
drivers/staging/iio/accel/adis16209.c +1 -2
@@ -1,19 +1,18 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * ADIS16209 Dual-Axis Digital Inclinometer and Accelerometer
  *
  * Copyright 2010 Analog Devices Inc.
- *
- * Licensed under the GPL-2 or later.

I see that you too are doing similar cleanup which I did a while ago
https://lkml.org/lkml/2018/2/12/255
where I got some update suggestions for the patch series. It would be great if you could update this patch series consistent with the reviewers.

For eg: in this patch you changed

+// SPDX-License-Identifier: GPL-2.0+

and therefore

MODULE_LICENSE("GPL v2");

should also be changed to

MODULE_LICENSE("GPL");

as explained by Philippe Ombredanne to me in my patch series.

I am not sure if you're subscribed to the IIO mailing list but you can find all the update suggestions from the above link. :)

Signature · 2 lines
Thanks
Himanshu Jha
#3 lore raw

Re: [PATCH 1/3] Staging: iio: adis16209: Use SPDX identifier

Quoted 2 lines · Himanshu Jha

Hi Shreeya,

Hi Himanshu,

Quoted 10 lines · Shreeya Patel
Quoted 9 lines

Use SPDX identifier format instead of GPLv2. Also rearrange the headers in alphabetical order.

---
 drivers/staging/iio/accel/adis16209.c | 7 +++----

 1 file changed, 3 insertions(+), 4 deletions(-)
Quoted 15 lines

drivers/staging/iio/accel/adis16209.c line 6

Quoted 13 lines
drivers/staging/iio/accel/adis16209.c +1 -2
index 7fcef9a..e3d9f80 100644
@@ -1,19 +1,18 @@
+// SPDX-License-Identifier: GPL-2.0+
  /*
   * ADIS16209 Dual-Axis Digital Inclinometer and Accelerometer
   *
   * Copyright 2010 Analog Devices Inc.
- *
- * Licensed under the GPL-2 or later.

I see that you too are doing similar cleanup which I did a while ago
https://lkml.org/lkml/2018/2/12/255

Yes, Jonathan suggested me to work on adis16209.
Your patches were quite useful for me :)

Quoted 10 lines

where I got some update suggestions for the patch series. It would be great if you could update this patch series consistent with the reviewers.

For eg: in this patch you changed

+// SPDX-License-Identifier: GPL-2.0+

and therefore

Quoted 7 lines

MODULE_LICENSE("GPL v2");

should also be changed to

MODULE_LICENSE("GPL");

as explained by Philippe Ombredanne to me in my patch series.

Great.
I'll make the necessary changes.

Quoted 4 lines

I am not sure if you're subscribed to the IIO mailing list but you can find
all the update suggestions from the above link. :)

Thanks for your suggestions

Quoted 1 line
maintainer
#4 lore raw

Re: [PATCH 1/3] Staging: iio: adis16209: Use SPDX identifier

Quoted 31 lines · On Sun, 18 Feb 2018 17:07:57 +0530 Shreeya Patel…
Quoted 2 lines · Himanshu Jha

Hi Shreeya,

Hi Himanshu,

Quoted 10 lines · Shreeya Patel
Quoted 9 lines

Use SPDX identifier format instead of GPLv2. Also rearrange the headers in alphabetical order.

---
 drivers/staging/iio/accel/adis16209.c | 7 +++----

 1 file changed, 3 insertions(+), 4 deletions(-)
Quoted 15 lines

drivers/staging/iio/accel/adis16209.c line 6

Quoted 13 lines
drivers/staging/iio/accel/adis16209.c +1 -2
index 7fcef9a..e3d9f80 100644
@@ -1,19 +1,18 @@
+// SPDX-License-Identifier: GPL-2.0+
  /*
   * ADIS16209 Dual-Axis Digital Inclinometer and Accelerometer
   *
   * Copyright 2010 Analog Devices Inc.
- *
- * Licensed under the GPL-2 or later.  

I see that you too are doing similar cleanup which I did a while ago
https://lkml.org/lkml/2018/2/12/255

Quoted 21 lines

Yes, Jonathan suggested me to work on adis16209.
Your patches were quite useful for me :)

Quoted 17 lines

where I got some update suggestions for the patch series. It would be great if you could update this patch series consistent with the reviewers.

For eg: in this patch you changed

+// SPDX-License-Identifier: GPL-2.0+

and therefore

MODULE_LICENSE("GPL v2");

should also be changed to

MODULE_LICENSE("GPL");

as explained by Philippe Ombredanne to me in my patch series.

I'm not sure that was exactly what Philippe was suggesting. He was making the point that the licensing was inconsistent without saying which option should be chosen.

We will need to seek clarification from Analog Devices on what their opinion on this is.

Lars / Michael, any clarification on the right way to resolve this inconsistency?

Quoted 14 lines

Great.
I'll make the necessary changes.

Quoted 4 lines

I am not sure if you're subscribed to the IIO mailing list but you can find
all the update suggestions from the above link. :)

Thanks for your suggestions

Quoted 1 line

--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

maintainer
#8 lore raw

Re: [PATCH 1/3] Staging: iio: adis16209: Use SPDX identifier

In reply to Shreeya Patel
Quoted 2 lines · On Sat, 17 Feb 2018 21:34:56 +0530 Shreeya Patel…

Use SPDX identifier format instead of GPLv2. Also rearrange the headers in alphabetical order.

As Dan pointed out for the Himanshu Jha's patches, the moment we see the word 'also' in a patch it pretty much makes it obvious that the author knows it is doing two things.

Two patches please. This is all about making the changes trivial to review. Sometimes it may seem silly where we have two small changes like here, but when you are reviewing hundreds of patches it really does help.

Jonathan

Quoted 33 lines
---
 drivers/staging/iio/accel/adis16209.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/staging/iio/accel/adis16209.c +3 -4
index 7fcef9a..e3d9f80 100644
@@ -1,19 +1,18 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * ADIS16209 Dual-Axis Digital Inclinometer and Accelerometer
  *
  * Copyright 2010 Analog Devices Inc.
- *
- * Licensed under the GPL-2 or later.
  */
 
 #include <linux/delay.h>
 #include <linux/device.h>
 #include <linux/kernel.h>
+#include <linux/list.h>
+#include <linux/module.h>
 #include <linux/spi/spi.h>
 #include <linux/slab.h>
 #include <linux/sysfs.h>
-#include <linux/list.h>
-#include <linux/module.h>
 
 #include <linux/iio/iio.h>
 #include <linux/iio/sysfs.h>
#5 lore raw

Re: [PATCH 1/3] Staging: iio: adis16209: Use SPDX identifier

In reply to Jonathan Cameron
Quoted 59 lines · Jonathan Cameron
Quoted 31 lines · On Sun, 18 Feb 2018 17:07:57 +0530 Shreeya Patel…
Quoted 2 lines · Himanshu Jha

Hi Shreeya,

Hi Himanshu,

Quoted 10 lines · Shreeya Patel
Quoted 9 lines

Use SPDX identifier format instead of GPLv2. Also rearrange the headers in alphabetical order.

---
 drivers/staging/iio/accel/adis16209.c | 7 +++----

 1 file changed, 3 insertions(+), 4 deletions(-)
Quoted 15 lines

drivers/staging/iio/accel/adis16209.c line 6

Quoted 13 lines
drivers/staging/iio/accel/adis16209.c +1 -2
index 7fcef9a..e3d9f80 100644
@@ -1,19 +1,18 @@
+// SPDX-License-Identifier: GPL-2.0+
  /*
   * ADIS16209 Dual-Axis Digital Inclinometer and Accelerometer
   *
   * Copyright 2010 Analog Devices Inc.
- *
- * Licensed under the GPL-2 or later.  

I see that you too are doing similar cleanup which I did a while ago
https://lkml.org/lkml/2018/2/12/255

Quoted 21 lines

Yes, Jonathan suggested me to work on adis16209.
Your patches were quite useful for me :)

Quoted 17 lines

where I got some update suggestions for the patch series. It would be great if you could update this patch series consistent with the reviewers.

For eg: in this patch you changed

+// SPDX-License-Identifier: GPL-2.0+

and therefore

MODULE_LICENSE("GPL v2");

should also be changed to

MODULE_LICENSE("GPL");

as explained by Philippe Ombredanne to me in my patch series.

I'm not sure that was exactly what Philippe was suggesting. He was making the point that the licensing was inconsistent without saying which option should be chosen.

Quoted 5 lines

We will need to seek clarification from Analog Devices on what their opinion on this is.

Lars / Michael, any clarification on the right way to resolve this inconsistency?

I can't speak for the intended license for code I wasn't involved in.

But I'd in general if there are conflicting licensing information and you want to be on the safe side choose the more restrictive license. E.g. GPL2+ is compatible with GPL2, but GPL2 is not compatible with GPL2+. So to be compatible with both choose GPL2.

#6 lore raw

Re: [PATCH 1/3] Staging: iio: adis16209: Use SPDX identifier

Quoted 66 lines · Lars-Peter Clausen
Quoted 59 lines · Jonathan Cameron
Quoted 31 lines · On Sun, 18 Feb 2018 17:07:57 +0530 Shreeya Patel…
Quoted 2 lines · Himanshu Jha

Hi Shreeya,

Hi Himanshu,

Quoted 10 lines · Shreeya Patel
Quoted 9 lines

Use SPDX identifier format instead of GPLv2. Also rearrange the headers in alphabetical order.

---
 drivers/staging/iio/accel/adis16209.c | 7 +++----

 1 file changed, 3 insertions(+), 4 deletions(-)
Quoted 15 lines

drivers/staging/iio/accel/adis16209.c line 6

Quoted 13 lines
drivers/staging/iio/accel/adis16209.c +1 -2
index 7fcef9a..e3d9f80 100644
@@ -1,19 +1,18 @@
+// SPDX-License-Identifier: GPL-2.0+
  /*
   * ADIS16209 Dual-Axis Digital Inclinometer and Accelerometer
   *
   * Copyright 2010 Analog Devices Inc.
- *
- * Licensed under the GPL-2 or later.  

I see that you too are doing similar cleanup which I did a while ago
https://lkml.org/lkml/2018/2/12/255

Quoted 21 lines

Yes, Jonathan suggested me to work on adis16209.
Your patches were quite useful for me :)

Quoted 17 lines

where I got some update suggestions for the patch series. It would be great if you could update this patch series consistent with the reviewers.

For eg: in this patch you changed

+// SPDX-License-Identifier: GPL-2.0+

and therefore

MODULE_LICENSE("GPL v2");

should also be changed to

MODULE_LICENSE("GPL");

as explained by Philippe Ombredanne to me in my patch series.

I'm not sure that was exactly what Philippe was suggesting. He was making the point that the licensing was inconsistent without saying which option should be chosen.

Quoted 5 lines

We will need to seek clarification from Analog Devices on what their opinion on this is.

Lars / Michael, any clarification on the right way to resolve this inconsistency?

Quoted 6 lines

I can't speak for the intended license for code I wasn't involved in.

But I'd in general if there are conflicting licensing information and you want to be on the safe side choose the more restrictive license. E.g. GPL2+ is compatible with GPL2, but GPL2 is not compatible with GPL2+. So to be compatible with both choose GPL2.

This is not legal advice btw.

I personally would stay away from messing with the licenses of code I do not own. Not everybody seems to agree yet that a SPDX tag is equivalent to a explicit licensing statement.

maintainer
#10 lore raw

Re: [PATCH 2/3] Staging: iio: adis16209: Remove unnecessary comments and add suitable suffix

In reply to Shreeya Patel
Quoted 5 lines · On Sat, 17 Feb 2018 21:37:37 +0530 Shreeya Patel…

Remove some unnecessary comments and therefore, add _REG suffix for registers. Group the control register and register field macros together.
Also, align function arguments to match open parentheses using tabs.

Lots of different changes in here - one patch per change type please. (so probably 3 here)

A few comments inline.

Jonathan

Quoted 87 lines
---
 drivers/staging/iio/accel/adis16209.c | 209 +++++++++++-----------------------
 1 file changed, 69 insertions(+), 140 deletions(-)
drivers/staging/iio/accel/adis16209.c +0 -73
index e3d9f80..6101212 100644
@@ -19,136 +19,67 @@
 #include <linux/iio/buffer.h>
 #include <linux/iio/imu/adis.h>
 
-#define ADIS16209_STARTUP_DELAY	220 /* ms */
-
-/* Flash memory write count */
-#define ADIS16209_FLASH_CNT      0x00
-
-/* Output, power supply */
-#define ADIS16209_SUPPLY_OUT     0x02
-
-/* Output, x-axis accelerometer */
-#define ADIS16209_XACCL_OUT      0x04
-
-/* Output, y-axis accelerometer */
-#define ADIS16209_YACCL_OUT      0x06
-
-/* Output, auxiliary ADC input */
-#define ADIS16209_AUX_ADC        0x08
-
-/* Output, temperature */
-#define ADIS16209_TEMP_OUT       0x0A
-
-/* Output, x-axis inclination */
-#define ADIS16209_XINCL_OUT      0x0C
-
-/* Output, y-axis inclination */
-#define ADIS16209_YINCL_OUT      0x0E
-
-/* Output, +/-180 vertical rotational position */
-#define ADIS16209_ROT_OUT        0x10
-
-/* Calibration, x-axis acceleration offset null */
-#define ADIS16209_XACCL_NULL     0x12
-
-/* Calibration, y-axis acceleration offset null */
-#define ADIS16209_YACCL_NULL     0x14
-
-/* Calibration, x-axis inclination offset null */
-#define ADIS16209_XINCL_NULL     0x16
-
-/* Calibration, y-axis inclination offset null */
-#define ADIS16209_YINCL_NULL     0x18
-
-/* Calibration, vertical rotation offset null */
-#define ADIS16209_ROT_NULL       0x1A
-
-/* Alarm 1 amplitude threshold */
-#define ADIS16209_ALM_MAG1       0x20
-
-/* Alarm 2 amplitude threshold */
-#define ADIS16209_ALM_MAG2       0x22
-
-/* Alarm 1, sample period */
-#define ADIS16209_ALM_SMPL1      0x24
-
-/* Alarm 2, sample period */
-#define ADIS16209_ALM_SMPL2      0x26
-
-/* Alarm control */
-#define ADIS16209_ALM_CTRL       0x28
-
-/* Auxiliary DAC data */
-#define ADIS16209_AUX_DAC        0x30
-
-/* General-purpose digital input/output control */
-#define ADIS16209_GPIO_CTRL      0x32
-
-/* Miscellaneous control */
-#define ADIS16209_MSC_CTRL       0x34
-
-/* Internal sample period (rate) control */
-#define ADIS16209_SMPL_PRD       0x36
-
-/* Operation, filter configuration */
-#define ADIS16209_AVG_CNT        0x38

drivers/staging/iio/accel/adis16209.c line 22

Quoted 10 lines
drivers/staging/iio/accel/adis16209.c +1 -9
-
-/* Operation, sleep mode control */
-#define ADIS16209_SLP_CNT        0x3A
-
-/* Diagnostics, system status register */
-#define ADIS16209_DIAG_STAT      0x3C
-
-/* Operation, system command register */
-#define ADIS16209_GLOB_CMD       0x3E
+#define ADIS16209_STARTUP_DELAY_MS	220

This one is a different type of change to the others, I would break it out in another patch.

drivers/staging/iio/accel/adis16209.c line 31

Quoted 9 lines
drivers/staging/iio/accel/adis16209.c +9 -0
+#define ADIS16209_FLASH_CNT_REG		0x00
+
+/* Data Output Register Definitions */
+#define ADIS16209_SUPPLY_OUT_REG	0x02
+#define ADIS16209_XACCL_OUT_REG		0x04
+#define ADIS16209_YACCL_OUT_REG		0x06
+#define ADIS16209_AUX_ADC_REG		0x08
+#define ADIS16209_TEMP_OUT_REG		0x0A
+#define ADIS16209_XINCL_OUT_REG		0x0C

For these last 3 I'm not sure that it is obvious what they are - I had to look at the datasheet. Perhaps a comment block explaining how these relate to the orientation of the device would be a useful addition. This may be a little 'controversial' so would be good to have this clearly laid out.

drivers/staging/iio/accel/adis16209.c line 40

Quoted 9 lines
drivers/staging/iio/accel/adis16209.c +9 -0
+#define ADIS16209_YINCL_OUT_REG		0x0E
+#define ADIS16209_ROT_OUT_REG		0x10
+
+/* Calibration Register Definitions */
+#define ADIS16209_XACCL_NULL_REG	0x12
+#define ADIS16209_YACCL_NULL_REG	0x14
+#define ADIS16209_XINCL_NULL_REG	0x16
+#define ADIS16209_YINCL_NULL_REG	0x18
+#define ADIS16209_ROT_NULL_REG		0x1A

This group are not necessarily clear in meaning. I would explain in the comment what is meant by NULL in this case.

drivers/staging/iio/accel/adis16209.c line 47

Quoted 7 lines
drivers/staging/iio/accel/adis16209.c +7 -0
+
+/* Alarm Register Definitions */
+#define ADIS16209_ALM_MAG1_REG		0x20
+#define ADIS16209_ALM_MAG2_REG		0x22
+#define ADIS16209_ALM_SMPL1_REG		0x24
+#define ADIS16209_ALM_SMPL2_REG		0x26
+#define ADIS16209_ALM_CTRL_REG		0x28

Hmm. This is an interesting trade off. There isn't actually enough defined here to allow implementation of the ALM functionality (and I wouldn't suggest trying to do so without hardware access) - so does having this set of defines provide any useful information? I'm not sure I care either way!

drivers/staging/iio/accel/adis16209.c line 55

Quoted 8 lines
drivers/staging/iio/accel/adis16209.c +6 -0
+
+#define ADIS16209_AUX_DAC_REG		0x30
+#define ADIS16209_GPIO_CTRL_REG		0x32
+#define ADIS16209_SMPL_PRD_REG		0x36
+#define ADIS16209_AVG_CNT_REG		0x38
+#define ADIS16209_SLP_CNT_REG		0x3A
 
 /* MSC_CTRL */

This one is obvious given the register name.

Quoted 7 lines
drivers/staging/iio/accel/adis16209.c +1 -4
-/* Self-test at power-on: 1 = disabled, 0 = enabled */
+#define ADIS16209_MSC_CTRL_REG			0x34
 #define ADIS16209_MSC_CTRL_PWRUP_SELF_TEST	BIT(10)
-
-/* Self-test enable */
-#define ADIS16209_MSC_CTRL_SELF_TEST_EN	        BIT(8)

drivers/staging/iio/accel/adis16209.c line 59

Quoted 10 lines
drivers/staging/iio/accel/adis16209.c +1 -9
-
-/* Data-ready enable: 1 = enabled, 0 = disabled */
-#define ADIS16209_MSC_CTRL_DATA_RDY_EN	        BIT(2)
-
-/* Data-ready polarity: 1 = active high, 0 = active low */
-#define ADIS16209_MSC_CTRL_ACTIVE_HIGH	        BIT(1)
-
-/* Data-ready line selection: 1 = DIO2, 0 = DIO1 */
-#define ADIS16209_MSC_CTRL_DATA_RDY_DIO2	BIT(0)
+#define ADIS16209_MSC_CTRL_SELF_TEST_EN		BIT(8)

One comment trick that I think improves readability is to slightly indent the field definitions to make them clearly different from the register addresses.
#define ADIS16209_MSC_CTRL_REG 0x34
#define ADIS16209_MSC_CTRL_PWRUP_SELF_TEST BIT(10)
#define ADIS16209_MSC_CTRL_SELF_TEST_EN ...

There are other ways of doing this but I think this one is subtle but effective.

drivers/staging/iio/accel/adis16209.c line 64

Quoted 5 lines
drivers/staging/iio/accel/adis16209.c +3 -0
+#define ADIS16209_MSC_CTRL_DATA_RDY_EN		BIT(2)
+#define ADIS16209_MSC_CTRL_ACTIVE_HIGH		BIT(1)
+#define ADIS16209_MSC_CTRL_DATA_RDY_DIO1	BIT(0)
 
 /* DIAG_STAT */

Again, the register name makes this clear so no need for the comment. Just use a blank line to separate this block from previous.

Quoted 16 lines
drivers/staging/iio/accel/adis16209.c +3 -10
-/* Alarm 2 status: 1 = alarm active, 0 = alarm inactive */
-#define ADIS16209_DIAG_STAT_ALARM2        BIT(9)
-
-/* Alarm 1 status: 1 = alarm active, 0 = alarm inactive */
-#define ADIS16209_DIAG_STAT_ALARM1        BIT(8)
-
-/* Self-test diagnostic error flag: 1 = error condition, 0 = normal operation */
+#define ADIS16209_DIAG_STAT_REG			0x3C
+#define ADIS16209_DIAG_STAT_ALARM2		BIT(9)
+#define ADIS16209_DIAG_STAT_ALARM1		BIT(8)
 #define ADIS16209_DIAG_STAT_SELFTEST_FAIL_BIT	5
-
-/* SPI communications failure */
 #define ADIS16209_DIAG_STAT_SPI_FAIL_BIT	3
-

drivers/staging/iio/accel/adis16209.c line 75

Quoted 10 lines
drivers/staging/iio/accel/adis16209.c +0 -5
-/* Flash update failure */
 #define ADIS16209_DIAG_STAT_FLASH_UPT_BIT	2
-
-/* Power supply above 3.625 V */
 #define ADIS16209_DIAG_STAT_POWER_HIGH_BIT	1
-
-/* Power supply below 3.15 V */
 #define ADIS16209_DIAG_STAT_POWER_LOW_BIT	0
 
 /* GLOB_CMD */

Again, the register name makes this clear. It's not 'special' compared to the other registers so doesn't need an additional comment.

Quoted 30 lines
drivers/staging/iio/accel/adis16209.c +9 -8
-#define ADIS16209_GLOB_CMD_SW_RESET	BIT(7)
-#define ADIS16209_GLOB_CMD_CLEAR_STAT	BIT(4)
-#define ADIS16209_GLOB_CMD_FACTORY_CAL	BIT(1)
+#define ADIS16209_GLOB_CMD_REG			0x3E
+#define ADIS16209_GLOB_CMD_SW_RESET		BIT(7)
+#define ADIS16209_GLOB_CMD_CLEAR_STAT		BIT(4)
+#define ADIS16209_GLOB_CMD_FACTORY_CAL		BIT(1)
 
-#define ADIS16209_ERROR_ACTIVE          BIT(14)
+#define ADIS16209_ERROR_ACTIVE			BIT(14)
 
 enum adis16209_scan {
 	ADIS16209_SCAN_SUPPLY,
@@ -164,10 +95,10 @@ enum adis16209_scan {
 static const u8 adis16209_addresses[8][1] = {
 	[ADIS16209_SCAN_SUPPLY] = { },
 	[ADIS16209_SCAN_AUX_ADC] = { },
-	[ADIS16209_SCAN_ACC_X] = { ADIS16209_XACCL_NULL },
-	[ADIS16209_SCAN_ACC_Y] = { ADIS16209_YACCL_NULL },
-	[ADIS16209_SCAN_INCLI_X] = { ADIS16209_XINCL_NULL },
-	[ADIS16209_SCAN_INCLI_Y] = { ADIS16209_YINCL_NULL },
+	[ADIS16209_SCAN_ACC_X] = { ADIS16209_XACCL_NULL_REG },
+	[ADIS16209_SCAN_ACC_Y] = { ADIS16209_YACCL_NULL_REG },
+	[ADIS16209_SCAN_INCLI_X] = { ADIS16209_XINCL_NULL_REG },
+	[ADIS16209_SCAN_INCLI_Y] = { ADIS16209_YINCL_NULL_REG },
 	[ADIS16209_SCAN_ROT] = { },
 	[ADIS16209_SCAN_TEMP] = { },
 };

drivers/staging/iio/accel/adis16209.c static int adis16209_read_raw(struct iio_dev *indio_dev, · line 148

Quoted 5 lines
drivers/staging/iio/accel/adis16209.c +1 -1
@@ -214,35 +145,35 @@ static int adis16209_read_raw(struct iio_dev *indio_dev,
 	switch (mask) {
 	case IIO_CHAN_INFO_RAW:
 		return adis_single_conversion(indio_dev, chan,
-			ADIS16209_ERROR_ACTIVE, val);
+					      ADIS16209_ERROR_ACTIVE, val);

This is a different type of change. Should be in a different patch.

drivers/staging/iio/accel/adis16209.c static int adis16209_read_raw(struct iio_dev *indio_dev, · line 223

Quoted 6 lines
drivers/staging/iio/accel/adis16209.c +0 -1
 	case IIO_CHAN_INFO_SCALE:
 		switch (chan->type) {
 		case IIO_VOLTAGE:
 			*val = 0;
 			if (chan->channel == 0)
-				*val2 = 305180; /* 0.30518 mV */

Again, I think Dan was right in his earlier review in that these do provide some value, but I think it can be improved by adding fuller comments.

drivers/staging/iio/accel/adis16209.c static int adis16209_read_raw(struct iio_dev *indio_dev, · line 160

Quoted 9 lines
drivers/staging/iio/accel/adis16209.c +3 -2
+				*val2 = 305180;
 			else
-				*val2 = 610500; /* 0.6105 mV */
+				*val2 = 610500;
 			return IIO_VAL_INT_PLUS_MICRO;
 		case IIO_TEMP:
-			*val = -470; /* -0.47 C */
+			*val = -470;
 			*val2 = 0;

This one is interesting...

drivers/staging/iio/accel/adis16209.c static int adis16209_read_raw(struct iio_dev *indio_dev, · line 164

Quoted 5 lines
drivers/staging/iio/accel/adis16209.c +1 -1
 			return IIO_VAL_INT_PLUS_MICRO;
 		case IIO_ACCEL:
 			*val = 0;
-			*val2 = IIO_G_TO_M_S_2(244140); /* 0.244140 mg */
+			*val2 = IIO_G_TO_M_S_2(244140);

As below, perhaps what we really want is a useful comment rather than no comment.

drivers/staging/iio/accel/adis16209.c static int adis16209_read_raw(struct iio_dev *indio_dev, · line 238

Quoted 5 lines
drivers/staging/iio/accel/adis16209.c +0 -1
 			return IIO_VAL_INT_PLUS_NANO;
 		case IIO_INCLI:
 		case IIO_ROT:
 			*val = 0;
-			*val2 = 25000; /* 0.025 degree */

Dan commented on these and I think he is correct in that it is useful to have some description here of what is going on.

However, I'd like something more along the lines of:
/*
* IIO base units for rotation are degrees.
* 1 LSB represents 0.025 milli degrees.
*/
Or more interestingly does it given that I just checked our ABI docs Documentation/ABI/testing/sysfs-bus-iio and rot_raw is not defined?

Would be great to:
1) Check what the various drivers with rotation channels are actually using.
2) Document it properly.

drivers/staging/iio/accel/adis16209.c static int adis16209_read_raw(struct iio_dev *indio_dev, · line 176

Quoted 9 lines
drivers/staging/iio/accel/adis16209.c +2 -1
+			*val2 = 25000;
 			return IIO_VAL_INT_PLUS_MICRO;
 		default:
 			return -EINVAL;
 		}
 		break;
 	case IIO_CHAN_INFO_OFFSET:
-		*val = 25000 / -470 - 0x4FE; /* 25 C = 0x4FE */
+		*val = 25000 / -470 - 0x4FE;

On this one I think it is sufficiently non obvious that we want to go the other way and explain 'why' the offset is as described. The comment is not that much help as it stands.
It is all very well knowing it should be 0x45e at 25 degrees but where did that scale factor of -470 come from?

Quoted 70 lines
drivers/staging/iio/accel/adis16209.c +13 -15
 		return IIO_VAL_INT;
 	case IIO_CHAN_INFO_CALIBBIAS:
 		switch (chan->type) {
@@ -265,18 +196,19 @@ static int adis16209_read_raw(struct iio_dev *indio_dev,
 }
 
 static const struct iio_chan_spec adis16209_channels[] = {
-	ADIS_SUPPLY_CHAN(ADIS16209_SUPPLY_OUT, ADIS16209_SCAN_SUPPLY, 0, 14),
-	ADIS_TEMP_CHAN(ADIS16209_TEMP_OUT, ADIS16209_SCAN_TEMP, 0, 12),
-	ADIS_ACCEL_CHAN(X, ADIS16209_XACCL_OUT, ADIS16209_SCAN_ACC_X,
+	ADIS_SUPPLY_CHAN(ADIS16209_SUPPLY_OUT_REG, ADIS16209_SCAN_SUPPLY,
+			 0, 14),
+	ADIS_TEMP_CHAN(ADIS16209_TEMP_OUT_REG, ADIS16209_SCAN_TEMP, 0, 12),
+	ADIS_ACCEL_CHAN(X, ADIS16209_XACCL_OUT_REG, ADIS16209_SCAN_ACC_X,
 			BIT(IIO_CHAN_INFO_CALIBBIAS), 0, 14),
-	ADIS_ACCEL_CHAN(Y, ADIS16209_YACCL_OUT, ADIS16209_SCAN_ACC_Y,
+	ADIS_ACCEL_CHAN(Y, ADIS16209_YACCL_OUT_REG, ADIS16209_SCAN_ACC_Y,
 			BIT(IIO_CHAN_INFO_CALIBBIAS), 0, 14),
-	ADIS_AUX_ADC_CHAN(ADIS16209_AUX_ADC, ADIS16209_SCAN_AUX_ADC, 0, 12),
-	ADIS_INCLI_CHAN(X, ADIS16209_XINCL_OUT, ADIS16209_SCAN_INCLI_X,
+	ADIS_AUX_ADC_CHAN(ADIS16209_AUX_ADC_REG, ADIS16209_SCAN_AUX_ADC, 0, 12),
+	ADIS_INCLI_CHAN(X, ADIS16209_XINCL_OUT_REG, ADIS16209_SCAN_INCLI_X,
 			0, 0, 14),
-	ADIS_INCLI_CHAN(Y, ADIS16209_YINCL_OUT, ADIS16209_SCAN_INCLI_Y,
+	ADIS_INCLI_CHAN(Y, ADIS16209_YINCL_OUT_REG, ADIS16209_SCAN_INCLI_Y,
 			0, 0, 14),
-	ADIS_ROT_CHAN(X, ADIS16209_ROT_OUT, ADIS16209_SCAN_ROT, 0, 0, 14),
+	ADIS_ROT_CHAN(X, ADIS16209_ROT_OUT_REG, ADIS16209_SCAN_ROT, 0, 0, 14),
 	IIO_CHAN_SOFT_TIMESTAMP(8)
 };
 
@@ -296,13 +228,13 @@ static const char * const adis16209_status_error_msgs[] = {
 
 static const struct adis_data adis16209_data = {
 	.read_delay = 30,
-	.msc_ctrl_reg = ADIS16209_MSC_CTRL,
-	.glob_cmd_reg = ADIS16209_GLOB_CMD,
-	.diag_stat_reg = ADIS16209_DIAG_STAT,
+	.msc_ctrl_reg = ADIS16209_MSC_CTRL_REG,
+	.glob_cmd_reg = ADIS16209_GLOB_CMD_REG,
+	.diag_stat_reg = ADIS16209_DIAG_STAT_REG,
 
 	.self_test_mask = ADIS16209_MSC_CTRL_SELF_TEST_EN,
 	.self_test_no_autoclear = true,
-	.startup_delay = ADIS16209_STARTUP_DELAY,
+	.startup_delay = ADIS16209_STARTUP_DELAY_MS,
 
 	.status_error_msgs = adis16209_status_error_msgs,
 	.status_error_mask = BIT(ADIS16209_DIAG_STAT_SELFTEST_FAIL_BIT) |
@@ -318,12 +250,10 @@ static int adis16209_probe(struct spi_device *spi)
 	struct adis *st;
 	struct iio_dev *indio_dev;
 
-	/* setup the industrialio driver allocated elements */
 	indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
 	if (!indio_dev)
 		return -ENOMEM;
 	st = iio_priv(indio_dev);
-	/* this is only used for removal purposes */
 	spi_set_drvdata(spi, indio_dev);
 
 	indio_dev->name = spi->dev.driver->name;
@@ -340,7 +270,6 @@ static int adis16209_probe(struct spi_device *spi)
 	if (ret)
 		return ret;
 
-	/* Get the device into a sane initial state */
 	ret = adis_initial_startup(st);
 	if (ret)
 		goto error_cleanup_buffer_trigger;
maintainer
#12 lore raw

Re: [PATCH 3/3] Staging: iio: adis16209: Use sign_extend32 and adjust a switch statement

In reply to Shreeya Patel
Quoted 3 lines · On Sat, 17 Feb 2018 21:51:35 +0530 Shreeya Patel…

Use sign_extend32 function instead of manually coding it. Also, adjust a switch block to explicitly match channels and return -EINVAL as default case which improves code readability.

Two items, two patches please.

The -EINVAL is a bit of an odd one. We know it can never happen and in reality we only add it to suppress the static checker warnings that may otherwise ensue. I would definitely not say that it helps readability. The change to the switch statement makes it clear there are only two channels so is semantically clearer to my mind and it is that which I argued improved readability.

Jonathan

Quoted 41 lines
---
 drivers/staging/iio/accel/adis16209.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
drivers/staging/iio/accel/adis16209.c +10 -5
index 6101212..f7c228b 100644
@@ -150,10 +150,16 @@ static int adis16209_read_raw(struct iio_dev *indio_dev,
 		switch (chan->type) {
 		case IIO_VOLTAGE:
 			*val = 0;
-			if (chan->channel == 0)
+			switch (chan->channel) {
+			case 0:
 				*val2 = 305180;
-			else
+				break;
+			case 1:
 				*val2 = 610500;
+				break;
+			default:
+				return -EINVAL;
+			}
 			return IIO_VAL_INT_PLUS_MICRO;
 		case IIO_TEMP:
 			*val = -470;
@@ -187,9 +193,8 @@ static int adis16209_read_raw(struct iio_dev *indio_dev,
 		ret = adis_read_reg_16(st, addr, &val16);
 		if (ret)
 			return ret;
-		val16 &= (1 << bits) - 1;
-		val16 = (s16)(val16 << (16 - bits)) >> (16 - bits);
-		*val = val16;
+
+		*val = sign_extend32(val16, bits - 1);
 		return IIO_VAL_INT;
 	}
 	return -EINVAL;
maintainer
#7 lore raw

Re: [PATCH 1/3] Staging: iio: adis16209: Use SPDX identifier

In reply to Lars-Peter Clausen
Quoted 74 lines · On Sun, 18 Feb 2018 13:14:27 +0100 Lars-Peter Clausen <[email protected]> wrote:
Quoted 66 lines · Lars-Peter Clausen
Quoted 59 lines · Jonathan Cameron
Quoted 31 lines · On Sun, 18 Feb 2018 17:07:57 +0530 Shreeya Patel…
Quoted 2 lines · Himanshu Jha

Hi Shreeya,

Hi Himanshu,

Quoted 10 lines · Shreeya Patel
Quoted 9 lines

Use SPDX identifier format instead of GPLv2. Also rearrange the headers in alphabetical order.

---
 drivers/staging/iio/accel/adis16209.c | 7 +++----

 1 file changed, 3 insertions(+), 4 deletions(-)
Quoted 15 lines

drivers/staging/iio/accel/adis16209.c line 6

Quoted 13 lines
drivers/staging/iio/accel/adis16209.c +1 -2
index 7fcef9a..e3d9f80 100644
@@ -1,19 +1,18 @@
+// SPDX-License-Identifier: GPL-2.0+
  /*
   * ADIS16209 Dual-Axis Digital Inclinometer and Accelerometer
   *
   * Copyright 2010 Analog Devices Inc.
- *
- * Licensed under the GPL-2 or later.    

I see that you too are doing similar cleanup which I did a while ago
https://lkml.org/lkml/2018/2/12/255

Quoted 21 lines

Yes, Jonathan suggested me to work on adis16209.
Your patches were quite useful for me :)

Quoted 17 lines

where I got some update suggestions for the patch series. It would be great if you could update this patch series consistent with the reviewers.

For eg: in this patch you changed

+// SPDX-License-Identifier: GPL-2.0+

and therefore

MODULE_LICENSE("GPL v2");

should also be changed to

MODULE_LICENSE("GPL");

as explained by Philippe Ombredanne to me in my patch series.

I'm not sure that was exactly what Philippe was suggesting. He was making the point that the licensing was inconsistent without saying which option should be chosen.

Quoted 5 lines

We will need to seek clarification from Analog Devices on what their opinion on this is.

Lars / Michael, any clarification on the right way to resolve this inconsistency?

Quoted 6 lines

I can't speak for the intended license for code I wasn't involved in.

But I'd in general if there are conflicting licensing information and you want to be on the safe side choose the more restrictive license. E.g. GPL2+ is compatible with GPL2, but GPL2 is not compatible with GPL2+. So to be compatible with both choose GPL2.

Quoted 6 lines

This is not legal advice btw.

I personally would stay away from messing with the licenses of code I do not own. Not everybody seems to agree yet that a SPDX tag is equivalent to a explicit licensing statement.

OK, in that case let's not do the spdx conversions for these drivers. We probably need to fix the inconsistency however between the text and the module license tag. Doesn't need to be part of moving it out of staging however.

Jonathan