Skip to contentSkip to conversation

adis16209 driver cleanup

PATCH Applied Shreeya Patel 2 participants 16 messages Mar 2, 2018 – Mar 3, 2018

Subsystems (4)

v1 of 6 Applied Latest is v6 →

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 (6):
Staging: iio: adis16209: Arrange headers in alphabetical order
Staging: iio: adis16209: Change the definition name
Staging: iio: adis16209: Add _REG postfix for registers
Staging: iio: adis16209: Remove unnecessary comments and group the
definitions
Staging: iio: adis16209: Add some informatic comments
Staging: iio: adis16209: Use sign_extend32 and adjust a switch
statement

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

PATCH 1/6 Staging: iio: adis16209: Arrange headers in alphabetical order

Arrange the headers in alphabetical order for cleanup purpose.

---
 drivers/staging/iio/accel/adis16209.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/iio/accel/adis16209.c +2 -2
index 7fcef9a..58f604d 100644
@@ -9,11 +9,11 @@
 #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 · 6 lines
2.7.4

_______________________________________________
devel mailing list
[email protected]
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
#3 lore raw

PATCH 2/6 Staging: iio: adis16209: Change the definition name

In reply to Shreeya Patel

The change in the definition name makes it then obvious what the units are throughout the driver and there will be no need of the comment.

---
 drivers/staging/iio/accel/adis16209.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/iio/accel/adis16209.c +2 -2
index 58f604d..830c278 100644
@@ -20,7 +20,7 @@
 #include <linux/iio/buffer.h>
 #include <linux/iio/imu/adis.h>
 
-#define ADIS16209_STARTUP_DELAY	220 /* ms */
+#define ADIS16209_STARTUP_DELAY_MS	220
 
 /* Flash memory write count */
 #define ADIS16209_FLASH_CNT      0x00
@@ -303,7 +303,7 @@ static const struct adis_data adis16209_data = {
 
 	.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) |
Signature · 1 line
2.7.4
#5 lore raw

PATCH 3/6 Staging: iio: adis16209: Add _REG postfix for registers

In reply to Shreeya Patel

The defined names for registers does not make it very clear that they are registers and hence, add _REG postfix. This improves the readability of the code.

---
 drivers/staging/iio/accel/adis16209.c | 85 ++++++++++++++++++-----------------
 1 file changed, 43 insertions(+), 42 deletions(-)
drivers/staging/iio/accel/adis16209.c +43 -42
index 830c278..151120f 100644
@@ -23,85 +23,85 @@
 #define ADIS16209_STARTUP_DELAY_MS	220
 
 /* Flash memory write count */
-#define ADIS16209_FLASH_CNT      0x00
+#define ADIS16209_FLASH_CNT_REG		0x00
 
 /* Output, power supply */
-#define ADIS16209_SUPPLY_OUT     0x02
+#define ADIS16209_SUPPLY_OUT_REG	0x02
 
 /* Output, x-axis accelerometer */
-#define ADIS16209_XACCL_OUT      0x04
+#define ADIS16209_XACCL_OUT_REG		0x04
 
 /* Output, y-axis accelerometer */
-#define ADIS16209_YACCL_OUT      0x06
+#define ADIS16209_YACCL_OUT_REG		0x06
 
 /* Output, auxiliary ADC input */
-#define ADIS16209_AUX_ADC        0x08
+#define ADIS16209_AUX_ADC_REG		0x08
 
 /* Output, temperature */
-#define ADIS16209_TEMP_OUT       0x0A
+#define ADIS16209_TEMP_OUT_REG		0x0A
 
 /* Output, x-axis inclination */
-#define ADIS16209_XINCL_OUT      0x0C
+#define ADIS16209_XINCL_OUT_REG		0x0C
 
 /* Output, y-axis inclination */
-#define ADIS16209_YINCL_OUT      0x0E
+#define ADIS16209_YINCL_OUT_REG		0x0E
 
 /* Output, +/-180 vertical rotational position */
-#define ADIS16209_ROT_OUT        0x10
+#define ADIS16209_ROT_OUT_REG		0x10
 
 /* Calibration, x-axis acceleration offset null */
-#define ADIS16209_XACCL_NULL     0x12
+#define ADIS16209_XACCL_NULL_REG	0x12
 
 /* Calibration, y-axis acceleration offset null */
-#define ADIS16209_YACCL_NULL     0x14
+#define ADIS16209_YACCL_NULL_REG	0x14
 
 /* Calibration, x-axis inclination offset null */
-#define ADIS16209_XINCL_NULL     0x16
+#define ADIS16209_XINCL_NULL_REG	0x16
 
 /* Calibration, y-axis inclination offset null */
-#define ADIS16209_YINCL_NULL     0x18
+#define ADIS16209_YINCL_NULL_REG	0x18
 
 /* Calibration, vertical rotation offset null */
-#define ADIS16209_ROT_NULL       0x1A
+#define ADIS16209_ROT_NULL_REG		0x1A
 
 /* Alarm 1 amplitude threshold */
-#define ADIS16209_ALM_MAG1       0x20
+#define ADIS16209_ALM_MAG1_REG		0x20
 
 /* Alarm 2 amplitude threshold */
-#define ADIS16209_ALM_MAG2       0x22
+#define ADIS16209_ALM_MAG2_REG		0x22
 
 /* Alarm 1, sample period */
-#define ADIS16209_ALM_SMPL1      0x24
+#define ADIS16209_ALM_SMPL1_REG		0x24
 
 /* Alarm 2, sample period */
-#define ADIS16209_ALM_SMPL2      0x26
+#define ADIS16209_ALM_SMPL2_REG		0x26
 
 /* Alarm control */
-#define ADIS16209_ALM_CTRL       0x28
+#define ADIS16209_ALM_CTRL_REG		0x28
 
 /* Auxiliary DAC data */
-#define ADIS16209_AUX_DAC        0x30
+#define ADIS16209_AUX_DAC_REG		0x30
 
 /* General-purpose digital input/output control */
-#define ADIS16209_GPIO_CTRL      0x32
+#define ADIS16209_GPIO_CTRL_REG		0x32
 
 /* Miscellaneous control */
-#define ADIS16209_MSC_CTRL       0x34
+#define ADIS16209_MSC_CTRL_REG		0x34
 
 /* Internal sample period (rate) control */
-#define ADIS16209_SMPL_PRD       0x36
+#define ADIS16209_SMPL_PRD_REG		0x36
 
 /* Operation, filter configuration */
-#define ADIS16209_AVG_CNT        0x38
+#define ADIS16209_AVG_CNT_REG		0x38
 
 /* Operation, sleep mode control */
-#define ADIS16209_SLP_CNT        0x3A
+#define ADIS16209_SLP_CNT_REG		0x3A
 
 /* Diagnostics, system status register */
-#define ADIS16209_DIAG_STAT      0x3C
+#define ADIS16209_DIAG_STAT_REG		0x3C
 
 /* Operation, system command register */
-#define ADIS16209_GLOB_CMD       0x3E
+#define ADIS16209_GLOB_CMD_REG		0x3E
 
 /* MSC_CTRL */
 
@@ -165,10 +165,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] = { },
 };
@@ -266,18 +266,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)
 };
 
@@ -297,9 +298,9 @@ 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,
Signature · 1 line
2.7.4
#7 lore raw

PATCH 4/6 Staging: iio: adis16209: Remove unnecessary comments and group the definitions

In reply to Shreeya Patel

Remove some unnecessay comments and group the control register and register field macros together.

---
 drivers/staging/iio/accel/adis16209.c | 116 ++++++----------------------------
 1 file changed, 19 insertions(+), 97 deletions(-)
drivers/staging/iio/accel/adis16209.c +19 -97
index 151120f..d2d1254 100644
@@ -21,135 +21,60 @@
 #include <linux/iio/imu/adis.h>
 
 #define ADIS16209_STARTUP_DELAY_MS	220
-
-/* Flash memory write count */
 #define ADIS16209_FLASH_CNT_REG		0x00
 
-/* Output, power supply */
+/* Data Output Register Definitions */
 #define ADIS16209_SUPPLY_OUT_REG	0x02
-
-/* Output, x-axis accelerometer */
 #define ADIS16209_XACCL_OUT_REG		0x04
-
-/* Output, y-axis accelerometer */
 #define ADIS16209_YACCL_OUT_REG		0x06
-
-/* Output, auxiliary ADC input */
 #define ADIS16209_AUX_ADC_REG		0x08
-
-/* Output, temperature */
 #define ADIS16209_TEMP_OUT_REG		0x0A
-
-/* Output, x-axis inclination */
 #define ADIS16209_XINCL_OUT_REG		0x0C
-
-/* Output, y-axis inclination */
 #define ADIS16209_YINCL_OUT_REG		0x0E
-
-/* Output, +/-180 vertical rotational position */
 #define ADIS16209_ROT_OUT_REG		0x10
 
-/* Calibration, x-axis acceleration offset null */
+/* Calibration Register Definitions */
 #define ADIS16209_XACCL_NULL_REG	0x12
-
-/* Calibration, y-axis acceleration offset null */
 #define ADIS16209_YACCL_NULL_REG	0x14
-
-/* Calibration, x-axis inclination offset null */
 #define ADIS16209_XINCL_NULL_REG	0x16
-
-/* Calibration, y-axis inclination offset null */
 #define ADIS16209_YINCL_NULL_REG	0x18
-
-/* Calibration, vertical rotation offset null */
 #define ADIS16209_ROT_NULL_REG		0x1A
 
-/* Alarm 1 amplitude threshold */
+/* Alarm Register Definitions */
 #define ADIS16209_ALM_MAG1_REG		0x20
-
-/* Alarm 2 amplitude threshold */
 #define ADIS16209_ALM_MAG2_REG		0x22
-
-/* Alarm 1, sample period */
 #define ADIS16209_ALM_SMPL1_REG		0x24
-
-/* Alarm 2, sample period */
 #define ADIS16209_ALM_SMPL2_REG		0x26
-
-/* Alarm control */
 #define ADIS16209_ALM_CTRL_REG		0x28
 
-/* Auxiliary DAC data */
 #define ADIS16209_AUX_DAC_REG		0x30
-
-/* General-purpose digital input/output control */
 #define ADIS16209_GPIO_CTRL_REG		0x32
-
-/* Miscellaneous control */
-#define ADIS16209_MSC_CTRL_REG		0x34
-
-/* Internal sample period (rate) control */
 #define ADIS16209_SMPL_PRD_REG		0x36
-
-/* Operation, filter configuration */
 #define ADIS16209_AVG_CNT_REG		0x38
-
-/* Operation, sleep mode control */
 #define ADIS16209_SLP_CNT_REG		0x3A
 
-/* Diagnostics, system status register */
-#define ADIS16209_DIAG_STAT_REG		0x3C
-
-/* Operation, system command register */
-#define ADIS16209_GLOB_CMD_REG		0x3E
-
-/* MSC_CTRL */
-
-/* Self-test at power-on: 1 = disabled, 0 = enabled */
-#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)
+#define ADIS16209_MSC_CTRL_REG			0x34
+#define  ADIS16209_MSC_CTRL_PWRUP_SELF_TEST	BIT(10)
+#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_DIO2	BIT(0)
 
-/* Data-ready line selection: 1 = DIO2, 0 = DIO1 */
-#define ADIS16209_MSC_CTRL_DATA_RDY_DIO2	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,
@@ -226,7 +151,7 @@ static int adis16209_read_raw(struct iio_dev *indio_dev,
 				*val2 = 610500; /* 0.6105 mV */
 			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:
@@ -243,7 +168,7 @@ static int adis16209_read_raw(struct iio_dev *indio_dev,
 		}
 		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) {
@@ -320,12 +245,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;
@@ -342,7 +265,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
#9 lore raw

PATCH 5/6 Staging: iio: adis16209: Add some informatic comments

In reply to Shreeya Patel

Some of the register names does not make it's puporse very clear and hence, add some comments for more information.
Also there are certain unit based comments which are not providing sufficient information, so expand those comments.

---
 drivers/staging/iio/accel/adis16209.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)
drivers/staging/iio/accel/adis16209.c +18 -3
index d2d1254..7363fd0 100644
@@ -27,13 +27,18 @@
 #define ADIS16209_SUPPLY_OUT_REG	0x02
 #define ADIS16209_XACCL_OUT_REG		0x04
 #define ADIS16209_YACCL_OUT_REG		0x06
+/* Output, auxiliary ADC */
 #define ADIS16209_AUX_ADC_REG		0x08
+/* Output, temperature */
 #define ADIS16209_TEMP_OUT_REG		0x0A
+/* Output, +/- 90 degrees X-axis inclination */
 #define ADIS16209_XINCL_OUT_REG		0x0C
 #define ADIS16209_YINCL_OUT_REG		0x0E
 #define ADIS16209_ROT_OUT_REG		0x10
 
-/* Calibration Register Definitions */
+/* Calibration Register Definitions.
+ * Acceleration, inclination or rotation offset null.
+ */
 #define ADIS16209_XACCL_NULL_REG	0x12
 #define ADIS16209_YACCL_NULL_REG	0x14
 #define ADIS16209_XINCL_NULL_REG	0x16
@@ -155,19 +160,29 @@ static int adis16209_read_raw(struct iio_dev *indio_dev,
 			*val2 = 0;
 			return IIO_VAL_INT_PLUS_MICRO;
 		case IIO_ACCEL:
+			/*
+			 * IIO base unit for sensitivity of accelerometer
+			 * is milligram.
+			 * 1 LSB represents 0.244 milligrams.
+			 */
 			*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:
+			/*
+			 * IIO base units for rotation are degrees.
+			 * 1 LSB represents 0.025 milli degrees.
+			 */
 			*val = 0;
-			*val2 = 25000; /* 0.025 degree */
+			*val2 = 25000;
 			return IIO_VAL_INT_PLUS_MICRO;
 		default:
 			return -EINVAL;
 		}
 		break;
 	case IIO_CHAN_INFO_OFFSET:
+		/* TEMP_OUT_REG has a scale factor of -0.47 degrees celcius. */
 		*val = 25000 / -470 - 0x4FE;
 		return IIO_VAL_INT;
 	case IIO_CHAN_INFO_CALIBBIAS:
Signature · 1 line
2.7.4
#12 lore raw

PATCH 6/6 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 makes the code semantically more clear.

---
 drivers/staging/iio/accel/adis16209.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
drivers/staging/iio/accel/adis16209.c +10 -5
index 7363fd0..5ab44a4 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; /* 0.30518 mV */
-			else
+				break;
+			case 1:
 				*val2 = 610500; /* 0.6105 mV */
+				break;
+			default:
+				return -EINVAL;
+			}
 			return IIO_VAL_INT_PLUS_MICRO;
 		case IIO_TEMP:
 			*val = -470;
@@ -197,9 +203,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
#11 lore raw

Re: [PATCH 5/6] Staging: iio: adis16209: Add some informatic comments

In reply to Jonathan Cameron
Quoted 61 lines · Jonathan Cameron
Quoted 6 lines · On Fri,  2 Mar 2018 19:02:48 +0530 Shreeya Patel…

Some of the register names does not make it's puporse very clear and hence, add some comments for more information.
Also there are certain unit based comments which are not providing sufficient information, so expand those comments.

Ah - serves me right for not reading on before commenting on the previous
patch.  It would have been preferable to have merged at least some of this
in there as they needed to be read together.

One comment in here doesn't quite cover everything I think should be explained.

Please fix that and merge this down with the previous patch (interactive rebase and marking it as a fixup makes this easy).

Thanks,

Jonathan

Quoted 36 lines

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

 1 file changed, 18 insertions(+), 3 deletions(-)
drivers/staging/iio/accel/adis16209.c +3 -0
index d2d1254..7363fd0 100644
@@ -27,13 +27,18 @@
  #define ADIS16209_SUPPLY_OUT_REG	0x02
  #define ADIS16209_XACCL_OUT_REG		0x04
  #define ADIS16209_YACCL_OUT_REG		0x06
+/* Output, auxiliary ADC */
  #define ADIS16209_AUX_ADC_REG		0x08
+/* Output, temperature */
  #define ADIS16209_TEMP_OUT_REG		0x0A
+/* Output, +/- 90 degrees X-axis inclination */
  #define ADIS16209_XINCL_OUT_REG		0x0C
  #define ADIS16209_YINCL_OUT_REG		0x0E
  #define ADIS16209_ROT_OUT_REG		0x10

drivers/staging/iio/accel/adis16209.c +3 -1
-/* Calibration Register Definitions */
+/* Calibration Register Definitions.
+ * Acceleration, inclination or rotation offset null.
+ */

 #define ADIS16209_XACCL_NULL_REG 0x12
 #define ADIS16209_YACCL_NULL_REG 0x14
 #define ADIS16209_XINCL_NULL_REG 0x16

drivers/staging/iio/accel/adis16209.c +0 -0
@@ -155,19 +160,29 @@ static int adis16209_read_raw(struct iio_dev
 *indio_dev,
  			*val2 = 0;
  			return IIO_VAL_INT_PLUS_MICRO;
Quoted 8 lines

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

Quoted 6 lines

  case IIO_ACCEL:

drivers/staging/iio/accel/adis16209.c +2 -0
+			/*
+			 * IIO base unit for sensitivity of

accelerometer

drivers/staging/iio/accel/adis16209.c +2 -0
+			 * is milligram.
+			 * 1 LSB represents 0.244 milligrams.

Not miligrams. Milli g where 1 g is the 'standard' acceleration due to gravity.

Ah!!
Should have used my common sense here :(
Sorry for such mistake.

Quoted 32 lines
Quoted 25 lines
drivers/staging/iio/accel/adis16209.c +1 -0
+			 */

  *val = 0;

drivers/staging/iio/accel/adis16209.c +0 -1
-			*val2 = IIO_G_TO_M_S_2(244140); /*

0.244140 mg */

drivers/staging/iio/accel/adis16209.c +1 -0
+			*val2 = IIO_G_TO_M_S_2(244140);

  return IIO_VAL_INT_PLUS_NANO; case IIO_INCLI:
  case IIO_ROT:

drivers/staging/iio/accel/adis16209.c +2 -0
+			/*
+			 * IIO base units for rotation are

degrees.

drivers/staging/iio/accel/adis16209.c +2 -0
+			 * 1 LSB represents 0.025 milli degrees.
+			 */

  *val = 0;

drivers/staging/iio/accel/adis16209.c +1 -1
-			*val2 = 25000; /* 0.025 degree */
+			*val2 = 25000;

  return IIO_VAL_INT_PLUS_MICRO; default:
  return -EINVAL;
  }
  break;
  case IIO_CHAN_INFO_OFFSET:

drivers/staging/iio/accel/adis16209.c +1 -0
+		/* TEMP_OUT_REG has a scale factor of -0.47
Quoted 1 line

degrees celcius. */

This doesn't explain the magic 0x4FE so that needs doing as well.

Quoted 4 lines

  *val = 25000 / -470 - 0x4FE;
  return IIO_VAL_INT;
  case IIO_CHAN_INFO_CALIBBIAS:

#14 lore raw

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

In reply to Jonathan Cameron
Quoted 10 lines · Jonathan Cameron
Quoted 7 lines · On Fri,  2 Mar 2018 19:04:49 +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 makes the code semantically more clear.

Quoted 8 lines

Changes are fine, but 2 changes to different things should be in 2 patches.  Please split. I'd probably have taken this anyway if it hadn't been queued behind the requested changes to the previous 2 patches anyway.

Good work on this series though so looking forward to v3. Note please mark the set as [PATCH v3] to make it clear it is the 3rd version of some of this.

Yes, I'll do the changes.

Do I need to include the patches which have been merged from this series in v3?

Thanks

Quoted 45 lines
Quoted 45 lines

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

 1 file changed, 10 insertions(+), 5 deletions(-)
drivers/staging/iio/accel/adis16209.c +0 -0
index 7363fd0..5ab44a4 100644
@@ -150,10 +150,16 @@ static int adis16209_read_raw(struct iio_dev
 *indio_dev,
  		switch (chan->type) {

  case IIO_VOLTAGE:
  *val = 0;

drivers/staging/iio/accel/adis16209.c +2 -1
-			if (chan->channel == 0)
+			switch (chan->channel) {
+			case 0:

  *val2 = 305180; /* 0.30518 mV */

drivers/staging/iio/accel/adis16209.c +2 -1
-			else
+				break;
+			case 1:

  *val2 = 610500; /* 0.6105 mV */

drivers/staging/iio/accel/adis16209.c +4 -0
+				break;
+			default:
+				return -EINVAL;
+			}

  return IIO_VAL_INT_PLUS_MICRO; case IIO_TEMP:
  *val = -470;

drivers/staging/iio/accel/adis16209.c +2 -3
@@ -197,9 +203,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
#2 lore raw

Re: [PATCH 1/6] Staging: iio: adis16209: Arrange headers in alphabetical order

In reply to Shreeya Patel
Quoted 4 lines · On Fri, 2 Mar 2018 18:49:23 +0530 Shreeya Patel…

Arrange the headers in alphabetical order for cleanup purpose.

Applied to the togreg branch of iio.git and pushed out as testing (mostly to test other patches as I'd be really surprised if this one broke anything :)

Jonathan

Quoted 22 lines
---
 drivers/staging/iio/accel/adis16209.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/iio/accel/adis16209.c +2 -2
index 7fcef9a..58f604d 100644
@@ -9,11 +9,11 @@
 #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>
maintainer
#4 lore raw

Re: [PATCH 2/6] Staging: iio: adis16209: Change the definition name

In reply to Shreeya Patel
Quoted 5 lines · On Fri, 2 Mar 2018 18:53:41 +0530 Shreeya Patel…

The change in the definition name makes it then obvious what the units are throughout the driver and there will be no need of the comment.

Applied to the togreg branch of iio.git and pushed out as testing.

Thanks,

Jonathan

Quoted 18 lines
---
 drivers/staging/iio/accel/adis16209.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/iio/accel/adis16209.c +1 -1
index 58f604d..830c278 100644
@@ -20,7 +20,7 @@
 #include <linux/iio/buffer.h>
 #include <linux/iio/imu/adis.h>
 
-#define ADIS16209_STARTUP_DELAY	220 /* ms */
+#define ADIS16209_STARTUP_DELAY_MS	220
 
 /* Flash memory write count */
 #define ADIS16209_FLASH_CNT      0x00

drivers/staging/iio/accel/adis16209.c static const struct adis_data adis16209_data = { · line 309

Quoted 8 lines
drivers/staging/iio/accel/adis16209.c +1 -1
@@ -303,7 +303,7 @@ static const struct adis_data adis16209_data = {
 
 	.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) |

_______________________________________________
devel mailing list
[email protected]
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

maintainer Applied
#6 lore raw

Re: [PATCH 3/6] Staging: iio: adis16209: Add _REG postfix for registers

In reply to Shreeya Patel
Quoted 5 lines · On Fri, 2 Mar 2018 18:55:56 +0530 Shreeya Patel…

The defined names for registers does not make it very clear that they are registers and hence, add _REG postfix. This improves the readability of the code.

Applied to the togreg branch of iio.git and pushed out as testing.

Thanks,

Jonathan

Quoted 167 lines
---
 drivers/staging/iio/accel/adis16209.c | 85 ++++++++++++++++++-----------------
 1 file changed, 43 insertions(+), 42 deletions(-)
drivers/staging/iio/accel/adis16209.c +40 -39
index 830c278..151120f 100644
@@ -23,85 +23,85 @@
 #define ADIS16209_STARTUP_DELAY_MS	220
 
 /* Flash memory write count */
-#define ADIS16209_FLASH_CNT      0x00
+#define ADIS16209_FLASH_CNT_REG		0x00
 
 /* Output, power supply */
-#define ADIS16209_SUPPLY_OUT     0x02
+#define ADIS16209_SUPPLY_OUT_REG	0x02
 
 /* Output, x-axis accelerometer */
-#define ADIS16209_XACCL_OUT      0x04
+#define ADIS16209_XACCL_OUT_REG		0x04
 
 /* Output, y-axis accelerometer */
-#define ADIS16209_YACCL_OUT      0x06
+#define ADIS16209_YACCL_OUT_REG		0x06
 
 /* Output, auxiliary ADC input */
-#define ADIS16209_AUX_ADC        0x08
+#define ADIS16209_AUX_ADC_REG		0x08
 
 /* Output, temperature */
-#define ADIS16209_TEMP_OUT       0x0A
+#define ADIS16209_TEMP_OUT_REG		0x0A
 
 /* Output, x-axis inclination */
-#define ADIS16209_XINCL_OUT      0x0C
+#define ADIS16209_XINCL_OUT_REG		0x0C
 
 /* Output, y-axis inclination */
-#define ADIS16209_YINCL_OUT      0x0E
+#define ADIS16209_YINCL_OUT_REG		0x0E
 
 /* Output, +/-180 vertical rotational position */
-#define ADIS16209_ROT_OUT        0x10
+#define ADIS16209_ROT_OUT_REG		0x10
 
 /* Calibration, x-axis acceleration offset null */
-#define ADIS16209_XACCL_NULL     0x12
+#define ADIS16209_XACCL_NULL_REG	0x12
 
 /* Calibration, y-axis acceleration offset null */
-#define ADIS16209_YACCL_NULL     0x14
+#define ADIS16209_YACCL_NULL_REG	0x14
 
 /* Calibration, x-axis inclination offset null */
-#define ADIS16209_XINCL_NULL     0x16
+#define ADIS16209_XINCL_NULL_REG	0x16
 
 /* Calibration, y-axis inclination offset null */
-#define ADIS16209_YINCL_NULL     0x18
+#define ADIS16209_YINCL_NULL_REG	0x18
 
 /* Calibration, vertical rotation offset null */
-#define ADIS16209_ROT_NULL       0x1A
+#define ADIS16209_ROT_NULL_REG		0x1A
 
 /* Alarm 1 amplitude threshold */
-#define ADIS16209_ALM_MAG1       0x20
+#define ADIS16209_ALM_MAG1_REG		0x20
 
 /* Alarm 2 amplitude threshold */
-#define ADIS16209_ALM_MAG2       0x22
+#define ADIS16209_ALM_MAG2_REG		0x22
 
 /* Alarm 1, sample period */
-#define ADIS16209_ALM_SMPL1      0x24
+#define ADIS16209_ALM_SMPL1_REG		0x24
 
 /* Alarm 2, sample period */
-#define ADIS16209_ALM_SMPL2      0x26
+#define ADIS16209_ALM_SMPL2_REG		0x26
 
 /* Alarm control */
-#define ADIS16209_ALM_CTRL       0x28
+#define ADIS16209_ALM_CTRL_REG		0x28
 
 /* Auxiliary DAC data */
-#define ADIS16209_AUX_DAC        0x30
+#define ADIS16209_AUX_DAC_REG		0x30
 
 /* General-purpose digital input/output control */
-#define ADIS16209_GPIO_CTRL      0x32
+#define ADIS16209_GPIO_CTRL_REG		0x32
 
 /* Miscellaneous control */
-#define ADIS16209_MSC_CTRL       0x34
+#define ADIS16209_MSC_CTRL_REG		0x34
 
 /* Internal sample period (rate) control */
-#define ADIS16209_SMPL_PRD       0x36
+#define ADIS16209_SMPL_PRD_REG		0x36
 
 /* Operation, filter configuration */
-#define ADIS16209_AVG_CNT        0x38
+#define ADIS16209_AVG_CNT_REG		0x38
 
 /* Operation, sleep mode control */
-#define ADIS16209_SLP_CNT        0x3A
+#define ADIS16209_SLP_CNT_REG		0x3A
 
 /* Diagnostics, system status register */
-#define ADIS16209_DIAG_STAT      0x3C
+#define ADIS16209_DIAG_STAT_REG		0x3C
 
 /* Operation, system command register */
-#define ADIS16209_GLOB_CMD       0x3E
+#define ADIS16209_GLOB_CMD_REG		0x3E
 
 /* MSC_CTRL */
 
@@ -165,10 +165,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] = { },
 };
@@ -266,18 +266,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)
 };
 
@@ -297,9 +298,9 @@ static const char * const adis16209_status_error_msgs[] = {
 
 static const struct adis_data adis16209_data = {

drivers/staging/iio/accel/adis16209.c static const char * const adis16209_status_error_msgs[] = { · line 306

Quoted 10 lines
drivers/staging/iio/accel/adis16209.c +3 -3
 	.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,

_______________________________________________
devel mailing list
[email protected]
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

maintainer
#8 lore raw

Re: [PATCH 4/6] Staging: iio: adis16209: Remove unnecessary comments and group the definitions

In reply to Shreeya Patel
Quoted 4 lines · On Fri, 2 Mar 2018 18:58:55 +0530 Shreeya Patel…

Remove some unnecessay comments and group the control register and register field macros together.

Hi Shreeya,

Nice patch.

As you have probably already seen comment removal (and addition) is always open to debate. I think a few of the removed comments are useful and should remain or in one or two cases be expanded to become useful.

In other cases a slight tweak to the name of the define makes it self explanatory.

Thanks,

Jonathan

Quoted 30 lines
---
 drivers/staging/iio/accel/adis16209.c | 116 ++++++----------------------------
 1 file changed, 19 insertions(+), 97 deletions(-)
drivers/staging/iio/accel/adis16209.c +1 -11
index 151120f..d2d1254 100644
@@ -21,135 +21,60 @@
 #include <linux/iio/imu/adis.h>
 
 #define ADIS16209_STARTUP_DELAY_MS	220
-
-/* Flash memory write count */
 #define ADIS16209_FLASH_CNT_REG		0x00
 
-/* Output, power supply */
+/* Data Output Register Definitions */
 #define ADIS16209_SUPPLY_OUT_REG	0x02
-
-/* Output, x-axis accelerometer */
 #define ADIS16209_XACCL_OUT_REG		0x04
-
-/* Output, y-axis accelerometer */
 #define ADIS16209_YACCL_OUT_REG		0x06
-
-/* Output, auxiliary ADC input */
 #define ADIS16209_AUX_ADC_REG		0x08
-
-/* Output, temperature */

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

Quoted 10 lines
drivers/staging/iio/accel/adis16209.c +0 -6
 #define ADIS16209_TEMP_OUT_REG		0x0A
-
-/* Output, x-axis inclination */
 #define ADIS16209_XINCL_OUT_REG		0x0C
-
-/* Output, y-axis inclination */
 #define ADIS16209_YINCL_OUT_REG		0x0E
-
-/* Output, +/-180 vertical rotational position */
 #define ADIS16209_ROT_OUT_REG		0x10

This one is 'odd' enough I think it is worth keeping some sort of description...

Quoted 65 lines
drivers/staging/iio/accel/adis16209.c +2 -44
-/* Calibration, x-axis acceleration offset null */
+/* Calibration Register Definitions */
 #define ADIS16209_XACCL_NULL_REG	0x12
-
-/* Calibration, y-axis acceleration offset null */
 #define ADIS16209_YACCL_NULL_REG	0x14
-
-/* Calibration, x-axis inclination offset null */
 #define ADIS16209_XINCL_NULL_REG	0x16
-
-/* Calibration, y-axis inclination offset null */
 #define ADIS16209_YINCL_NULL_REG	0x18
-
-/* Calibration, vertical rotation offset null */
 #define ADIS16209_ROT_NULL_REG		0x1A
 
-/* Alarm 1 amplitude threshold */
+/* Alarm Register Definitions */
 #define ADIS16209_ALM_MAG1_REG		0x20
-
-/* Alarm 2 amplitude threshold */
 #define ADIS16209_ALM_MAG2_REG		0x22
-
-/* Alarm 1, sample period */
 #define ADIS16209_ALM_SMPL1_REG		0x24
-
-/* Alarm 2, sample period */
 #define ADIS16209_ALM_SMPL2_REG		0x26
-
-/* Alarm control */
 #define ADIS16209_ALM_CTRL_REG		0x28
 
-/* Auxiliary DAC data */
 #define ADIS16209_AUX_DAC_REG		0x30
-
-/* General-purpose digital input/output control */
 #define ADIS16209_GPIO_CTRL_REG		0x32
-
-/* Miscellaneous control */
-#define ADIS16209_MSC_CTRL_REG		0x34
-
-/* Internal sample period (rate) control */
 #define ADIS16209_SMPL_PRD_REG		0x36
-
-/* Operation, filter configuration */
 #define ADIS16209_AVG_CNT_REG		0x38
-
-/* Operation, sleep mode control */
 #define ADIS16209_SLP_CNT_REG		0x3A
 
-/* Diagnostics, system status register */
-#define ADIS16209_DIAG_STAT_REG		0x3C
-
-/* Operation, system command register */
-#define ADIS16209_GLOB_CMD_REG		0x3E
-
-/* MSC_CTRL */
-
-/* Self-test at power-on: 1 = disabled, 0 = enabled */
-#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 60

Quoted 10 lines
drivers/staging/iio/accel/adis16209.c +5 -5
-/* 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)
+#define ADIS16209_MSC_CTRL_REG			0x34
+#define  ADIS16209_MSC_CTRL_PWRUP_SELF_TEST	BIT(10)
+#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)

This one isn't named well enough to make it obvious what it is controlling. Either leave the comment or tweak the anme to something like:

ADIS16209_MSC_CTRL_DATA_RDY_ACTIVE_HIGH

Quoted 14 lines
drivers/staging/iio/accel/adis16209.c +1 -12
+#define  ADIS16209_MSC_CTRL_DATA_RDY_DIO2	BIT(0)
 
-/* Data-ready line selection: 1 = DIO2, 0 = DIO1 */
-#define ADIS16209_MSC_CTRL_DATA_RDY_DIO2	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 */

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

Quoted 10 lines
drivers/staging/iio/accel/adis16209.c +3 -4
+#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

Another question I had earlier was about this bit so I'll give the same comment here. It's really not well named (as was pointed out to me!) as it reflects a failure and the name doesn't imply this.

There is also the curious point that the register is called simply STATUS on the data sheet (not DIAG stat).

All this family have subtly different naming for somethings (presumably it evolved over time) but that name is nicer than the DIAG_STAT naming to my mind so perhaps worth a change?

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

Quoted 3 lines
drivers/staging/iio/accel/adis16209.c +0 -2
-
-/* Power supply above 3.625 V */
 #define ADIS16209_DIAG_STAT_POWER_HIGH_BIT	1

This comment conveys meaning not expressed in the
name so I would keep it (same with the next one).

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

Quoted 10 lines
drivers/staging/iio/accel/adis16209.c +1 -7
-
-/* 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

This one is interesting. I have no idea where the naming GLOB_CMD came from given it's COMMAND on the current data sheet.

Current naming is pretty clear though I guess so up to you on whether you want to change it.

Quoted 19 lines
drivers/staging/iio/accel/adis16209.c +5 -2
+#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,
@@ -226,7 +151,7 @@ static int adis16209_read_raw(struct iio_dev *indio_dev,
 				*val2 = 610500; /* 0.6105 mV */
 			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:

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

Quoted 5 lines
drivers/staging/iio/accel/adis16209.c +1 -1
@@ -243,7 +168,7 @@ static int adis16209_read_raw(struct iio_dev *indio_dev,
 		}
 		break;
 	case IIO_CHAN_INFO_OFFSET:
-		*val = 25000 / -470 - 0x4FE; /* 25 C = 0x4FE */
+		*val = 25000 / -470 - 0x4FE;

Whilst I don't like the existing comment, I do feel that some explanation of the logic here would be useful.

Perhaps something like:

/*
* The raw ADC value is 0x4FE when the temperature is 45 degrees and
* the scale factor per milli degree C is -470.
*/

Quoted 17 lines
drivers/staging/iio/accel/adis16209.c +0 -2
 		return IIO_VAL_INT;
 	case IIO_CHAN_INFO_CALIBBIAS:
 		switch (chan->type) {
@@ -320,12 +245,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;

drivers/staging/iio/accel/adis16209.c static int adis16209_probe(struct spi_device *spi) · line 270

Quoted 7 lines
drivers/staging/iio/accel/adis16209.c +0 -1
@@ -342,7 +265,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;

_______________________________________________
devel mailing list
[email protected]
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

maintainer
#10 lore raw

Re: [PATCH 5/6] Staging: iio: adis16209: Add some informatic comments

In reply to Shreeya Patel
Quoted 5 lines · On Fri, 2 Mar 2018 19:02:48 +0530 Shreeya Patel…

Some of the register names does not make it's puporse very clear and hence, add some comments for more information.
Also there are certain unit based comments which are not providing sufficient information, so expand those comments.

Ah - serves me right for not reading on before commenting on the previous patch. It would have been preferable to have merged at least some of this in there as they needed to be read together.

One comment in here doesn't quite cover everything I think should be explained.

Please fix that and merge this down with the previous patch (interactive rebase and marking it as a fixup makes this easy).

Thanks,

Jonathan

Quoted 31 lines
---
 drivers/staging/iio/accel/adis16209.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)
drivers/staging/iio/accel/adis16209.c +6 -1
index d2d1254..7363fd0 100644
@@ -27,13 +27,18 @@
 #define ADIS16209_SUPPLY_OUT_REG	0x02
 #define ADIS16209_XACCL_OUT_REG		0x04
 #define ADIS16209_YACCL_OUT_REG		0x06
+/* Output, auxiliary ADC */
 #define ADIS16209_AUX_ADC_REG		0x08
+/* Output, temperature */
 #define ADIS16209_TEMP_OUT_REG		0x0A
+/* Output, +/- 90 degrees X-axis inclination */
 #define ADIS16209_XINCL_OUT_REG		0x0C
 #define ADIS16209_YINCL_OUT_REG		0x0E
 #define ADIS16209_ROT_OUT_REG		0x10
 
-/* Calibration Register Definitions */
+/* Calibration Register Definitions.
+ * Acceleration, inclination or rotation offset null.
+ */
 #define ADIS16209_XACCL_NULL_REG	0x12
 #define ADIS16209_YACCL_NULL_REG	0x14
 #define ADIS16209_XINCL_NULL_REG	0x16

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

Quoted 7 lines
drivers/staging/iio/accel/adis16209.c +4 -0
@@ -155,19 +160,29 @@ static int adis16209_read_raw(struct iio_dev *indio_dev,
 			*val2 = 0;
 			return IIO_VAL_INT_PLUS_MICRO;
 		case IIO_ACCEL:
+			/*
+			 * IIO base unit for sensitivity of accelerometer
+			 * is milligram.
+			 * 1 LSB represents 0.244 milligrams.

Not miligrams. Milli g where 1 g is the 'standard' acceleration due to gravity.

Quoted 11 lines
drivers/staging/iio/accel/adis16209.c +6 -1
+			 */
 			*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:
+			/*
+			 * IIO base units for rotation are degrees.
+			 * 1 LSB represents 0.025 milli degrees.
+			 */

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

Quoted 10 lines
drivers/staging/iio/accel/adis16209.c +2 -1
 			*val = 0;
-			*val2 = 25000; /* 0.025 degree */
+			*val2 = 25000;
 			return IIO_VAL_INT_PLUS_MICRO;
 		default:
 			return -EINVAL;
 		}
 		break;
 	case IIO_CHAN_INFO_OFFSET:
+		/* TEMP_OUT_REG has a scale factor of -0.47 degrees celcius. */

This doesn't explain the magic 0x4FE so that needs doing as well.

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

Quoted 3 lines
drivers/staging/iio/accel/adis16209.c +0 -0
 		*val = 25000 / -470 - 0x4FE;
 		return IIO_VAL_INT;
 	case IIO_CHAN_INFO_CALIBBIAS:

_______________________________________________
devel mailing list
[email protected]
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

maintainer
#13 lore raw

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

In reply to Shreeya Patel
Quoted 6 lines · On Fri, 2 Mar 2018 19:04:49 +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 makes the code semantically more clear.

Changes are fine, but 2 changes to different things should be in 2 patches. Please split. I'd probably have taken this anyway if it hadn't been queued behind the requested changes to the previous 2 patches anyway.

Good work on this series though so looking forward to v3. Note please mark the set as [PATCH v3] to make it clear it is the 3rd version of some of this.

Quoted 29 lines
---
 drivers/staging/iio/accel/adis16209.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
drivers/staging/iio/accel/adis16209.c +8 -2
index 7363fd0..5ab44a4 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; /* 0.30518 mV */
-			else
+				break;
+			case 1:
 				*val2 = 610500; /* 0.6105 mV */
+				break;
+			default:
+				return -EINVAL;
+			}
 			return IIO_VAL_INT_PLUS_MICRO;
 		case IIO_TEMP:
 			*val = -470;
@@ -197,9 +203,8 @@ static int adis16209_read_raw(struct iio_dev *indio_dev,
 		ret = adis_read_reg_16(st, addr, &val16);

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

Quoted 10 lines
drivers/staging/iio/accel/adis16209.c +2 -3
 		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;

_______________________________________________
devel mailing list
[email protected]
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

maintainer
#15 lore raw

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

In reply to Shreeya Patel
Quoted 16 lines · On Sat, 03 Mar 2018 21:07:53 +0530 Shreeya Patel…
Quoted 15 lines · Jonathan Cameron
Quoted 7 lines · On Fri,  2 Mar 2018 19:04:49 +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 makes the code semantically more clear.

Changes are fine, but 2 changes to different things should be in 2 patches.  Please split. I'd probably have taken this anyway if it hadn't been queued behind the requested changes to the previous 2 patches anyway.

Quoted 9 lines
Quoted 3 lines

Good work on this series though so looking forward to v3. Note please mark the set as [PATCH v3] to make it clear it is the 3rd version of some of this.

Yes, I'll do the changes.

Do I need to include the patches which have been merged from this series in v3?

No, just the ones that haven't merged yet.

Thanks,

Jonathan

Quoted 42 lines

Thanks

Quoted 41 lines
Quoted 41 lines

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

 1 file changed, 10 insertions(+), 5 deletions(-)
drivers/staging/iio/accel/adis16209.c +0 -0
index 7363fd0..5ab44a4 100644
@@ -150,10 +150,16 @@ static int adis16209_read_raw(struct iio_dev
 *indio_dev,
  		switch (chan->type) {

  case IIO_VOLTAGE:
  *val = 0;

drivers/staging/iio/accel/adis16209.c +2 -1
-			if (chan->channel == 0)
+			switch (chan->channel) {
+			case 0:

  *val2 = 305180; /* 0.30518 mV */

drivers/staging/iio/accel/adis16209.c +2 -1
-			else
+				break;
+			case 1:

  *val2 = 610500; /* 0.6105 mV */

drivers/staging/iio/accel/adis16209.c +4 -0
+				break;
+			default:
+				return -EINVAL;
+			}

  return IIO_VAL_INT_PLUS_MICRO; case IIO_TEMP:
  *val = -470;

drivers/staging/iio/accel/adis16209.c +1 -3
@@ -197,9 +203,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;
+
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
drivers/staging/iio/accel/adis16209.c +1 -0
+		*val = sign_extend32(val16, bits - 1);
  		return IIO_VAL_INT;

  }
  return -EINVAL;

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

_______________________________________________
devel mailing list
[email protected]
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel