Some devices may have more than 16 bits of status. This patch allows the user
to specify the size of the DIAG_STAT register. It defaults to 2 if not
specified. This is mainly for backward compatibility.
Co-developed-by: Ramona Gradinariu <ramona.gradinariu@analog.com>
Signed-off-by: Ramona Gradinariu <ramona.gradinariu@analog.com>
Co-developed-by: Antoniu Miclaus <antoniu.miclaus@analog.com>
Signed-off-by: Antoniu Miclaus <antoniu.miclaus@analog.com>
Signed-off-by: Nuno Sá <nuno.sa@analog.com>
Signed-off-by: Robert Budai <robert.budai@analog.com>
---
drivers/iio/imu/adis.c | 19 ++++++++++++++++---
include/linux/iio/imu/adis.h | 3 +++
2 files changed, 19 insertions(+), 3 deletions(-)
diff --git a/drivers/iio/imu/adis.c b/drivers/iio/imu/adis.c
index 84344f052..b3f074116 100644
--- a/drivers/iio/imu/adis.c
+++ b/drivers/iio/imu/adis.c
@@ -304,11 +304,21 @@ EXPORT_SYMBOL_NS(__adis_enable_irq, "IIO_ADISLIB");
*/
int __adis_check_status(struct adis *adis)
{
- u16 status;
+ unsigned int status;
+ int diag_stat_bits;
+ u16 status_16;
int ret;
int i;
- ret = __adis_read_reg_16(adis, adis->data->diag_stat_reg, &status);
+ if (adis->data->diag_stat_size)
+ ret = adis->ops->read(adis, adis->data->diag_stat_reg, &status,
+ adis->data->diag_stat_size);
+ else
+ {
+ ret = __adis_read_reg_16(adis, adis->data->diag_stat_reg,
+ status_16);
+ status = status_16;
+ }
if (ret)
return ret;
@@ -317,7 +327,10 @@ int __adis_check_status(struct adis *adis)
if (status == 0)
return 0;
- for (i = 0; i < 16; ++i) {
+ diag_stat_bits = BITS_PER_BYTE * (adis->data->diag_stat_size ?
+ adis->data->diag_stat_size : 2);
+
+ for (i = 0; i < diag_stat_bits; ++i) {
if (status & BIT(i)) {
dev_err(&adis->spi->dev, "%s.\n",
adis->data->status_error_msgs[i]);
diff --git a/include/linux/iio/imu/adis.h b/include/linux/iio/imu/adis.h
index 52652f51d..35797fe93 100644
--- a/include/linux/iio/imu/adis.h
+++ b/include/linux/iio/imu/adis.h
@@ -44,6 +44,8 @@ struct adis_timeout {
* @glob_cmd_reg: Register address of the GLOB_CMD register
* @msc_ctrl_reg: Register address of the MSC_CTRL register
* @diag_stat_reg: Register address of the DIAG_STAT register
+ * @diag_stat_size: Length (in bytes) of the DIAG_STAT register. If 0 the
+ * default length is 2 bytes long.
* @prod_id_reg: Register address of the PROD_ID register
* @prod_id: Product ID code that should be expected when reading @prod_id_reg
* @self_test_mask: Bitmask of supported self-test operations
@@ -70,6 +72,7 @@ struct adis_data {
unsigned int glob_cmd_reg;
unsigned int msc_ctrl_reg;
unsigned int diag_stat_reg;
+ unsigned int diag_stat_size;
unsigned int prod_id_reg;
unsigned int prod_id;
--
2.34.1
On Tue, 11 Feb 2025 19:57:00 +0200
Robert Budai <robert.budai@analog.com> wrote:
> Some devices may have more than 16 bits of status. This patch allows the user
> to specify the size of the DIAG_STAT register. It defaults to 2 if not
> specified. This is mainly for backward compatibility.
>
> Co-developed-by: Ramona Gradinariu <ramona.gradinariu@analog.com>
> Signed-off-by: Ramona Gradinariu <ramona.gradinariu@analog.com>
> Co-developed-by: Antoniu Miclaus <antoniu.miclaus@analog.com>
> Signed-off-by: Antoniu Miclaus <antoniu.miclaus@analog.com>
> Signed-off-by: Nuno Sá <nuno.sa@analog.com>
> Signed-off-by: Robert Budai <robert.budai@analog.com>
> ---
> drivers/iio/imu/adis.c | 19 ++++++++++++++++---
> include/linux/iio/imu/adis.h | 3 +++
> 2 files changed, 19 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/iio/imu/adis.c b/drivers/iio/imu/adis.c
> index 84344f052..b3f074116 100644
> --- a/drivers/iio/imu/adis.c
> +++ b/drivers/iio/imu/adis.c
> @@ -304,11 +304,21 @@ EXPORT_SYMBOL_NS(__adis_enable_irq, "IIO_ADISLIB");
> */
> int __adis_check_status(struct adis *adis)
> {
> - u16 status;
> + unsigned int status;
> + int diag_stat_bits;
> + u16 status_16;
> int ret;
> int i;
>
> - ret = __adis_read_reg_16(adis, adis->data->diag_stat_reg, &status);
> + if (adis->data->diag_stat_size)
> + ret = adis->ops->read(adis, adis->data->diag_stat_reg, &status,
> + adis->data->diag_stat_size);
> + else
> + {
This doesn't match kernel style.
if (adis->data->diag_stat_size) {
ret = adis->ops->read(adis, adis->data->diag_stat_reg, &status,
adis->data->diag_stat_size);
} else {
ret = __adis_read_reg_16(adis, adis->data->diag_stat_reg,
&status_16);
status = status_16;
}
Also the integer instead of pointer issue 0-day found.
Jonathan
> + ret = __adis_read_reg_16(adis, adis->data->diag_stat_reg,
> + status_16);
> + status = status_16;
> + }
> if (ret)
> return ret;
>
> @@ -317,7 +327,10 @@ int __adis_check_status(struct adis *adis)
> if (status == 0)
> return 0;
>
> - for (i = 0; i < 16; ++i) {
> + diag_stat_bits = BITS_PER_BYTE * (adis->data->diag_stat_size ?
> + adis->data->diag_stat_size : 2);
> +
> + for (i = 0; i < diag_stat_bits; ++i) {
> if (status & BIT(i)) {
> dev_err(&adis->spi->dev, "%s.\n",
> adis->data->status_error_msgs[i]);
> diff --git a/include/linux/iio/imu/adis.h b/include/linux/iio/imu/adis.h
> index 52652f51d..35797fe93 100644
> --- a/include/linux/iio/imu/adis.h
> +++ b/include/linux/iio/imu/adis.h
> @@ -44,6 +44,8 @@ struct adis_timeout {
> * @glob_cmd_reg: Register address of the GLOB_CMD register
> * @msc_ctrl_reg: Register address of the MSC_CTRL register
> * @diag_stat_reg: Register address of the DIAG_STAT register
> + * @diag_stat_size: Length (in bytes) of the DIAG_STAT register. If 0 the
> + * default length is 2 bytes long.
> * @prod_id_reg: Register address of the PROD_ID register
> * @prod_id: Product ID code that should be expected when reading @prod_id_reg
> * @self_test_mask: Bitmask of supported self-test operations
> @@ -70,6 +72,7 @@ struct adis_data {
> unsigned int glob_cmd_reg;
> unsigned int msc_ctrl_reg;
> unsigned int diag_stat_reg;
> + unsigned int diag_stat_size;
> unsigned int prod_id_reg;
>
> unsigned int prod_id;
Hi Robert,
kernel test robot noticed the following build warnings:
[auto build test WARNING on jic23-iio/togreg]
[also build test WARNING on linus/master v6.14-rc2 next-20250212]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Robert-Budai/iio-imu-adis-Add-custom-ops-struct/20250212-040235
base: https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git togreg
patch link: https://lore.kernel.org/r/20250211175706.276987-4-robert.budai%40analog.com
patch subject: [PATCH v7 3/6] iio: imu: adis: Add DIAG_STAT register
config: arc-randconfig-001-20250213 (https://download.01.org/0day-ci/archive/20250213/202502131146.rXrTvgZr-lkp@intel.com/config)
compiler: arc-elf-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250213/202502131146.rXrTvgZr-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202502131146.rXrTvgZr-lkp@intel.com/
All warnings (new ones prefixed by >>):
drivers/iio/imu/adis.c: In function '__adis_check_status':
>> drivers/iio/imu/adis.c:319:42: warning: passing argument 3 of '__adis_read_reg_16' makes pointer from integer without a cast [-Wint-conversion]
319 | status_16);
| ^~~~~~~~~
| |
| u16 {aka short unsigned int}
In file included from drivers/iio/imu/adis.c:19:
include/linux/iio/imu/adis.h:225:43: note: expected 'u16 *' {aka 'short unsigned int *'} but argument is of type 'u16' {aka 'short unsigned int'}
225 | u16 *val)
| ~~~~~^~~
vim +/__adis_read_reg_16 +319 drivers/iio/imu/adis.c
298
299 /**
300 * __adis_check_status() - Check the device for error conditions (unlocked)
301 * @adis: The adis device
302 *
303 * Returns 0 on success, a negative error code otherwise
304 */
305 int __adis_check_status(struct adis *adis)
306 {
307 unsigned int status;
308 int diag_stat_bits;
309 u16 status_16;
310 int ret;
311 int i;
312
313 if (adis->data->diag_stat_size)
314 ret = adis->ops->read(adis, adis->data->diag_stat_reg, &status,
315 adis->data->diag_stat_size);
316 else
317 {
318 ret = __adis_read_reg_16(adis, adis->data->diag_stat_reg,
> 319 status_16);
320 status = status_16;
321 }
322 if (ret)
323 return ret;
324
325 status &= adis->data->status_error_mask;
326
327 if (status == 0)
328 return 0;
329
330 diag_stat_bits = BITS_PER_BYTE * (adis->data->diag_stat_size ?
331 adis->data->diag_stat_size : 2);
332
333 for (i = 0; i < diag_stat_bits; ++i) {
334 if (status & BIT(i)) {
335 dev_err(&adis->spi->dev, "%s.\n",
336 adis->data->status_error_msgs[i]);
337 }
338 }
339
340 return -EIO;
341 }
342 EXPORT_SYMBOL_NS_GPL(__adis_check_status, "IIO_ADISLIB");
343
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Hi Robert,
kernel test robot noticed the following build errors:
[auto build test ERROR on jic23-iio/togreg]
[also build test ERROR on linus/master v6.14-rc2 next-20250212]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Robert-Budai/iio-imu-adis-Add-custom-ops-struct/20250212-040235
base: https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git togreg
patch link: https://lore.kernel.org/r/20250211175706.276987-4-robert.budai%40analog.com
patch subject: [PATCH v7 3/6] iio: imu: adis: Add DIAG_STAT register
config: sh-randconfig-001-20250213 (https://download.01.org/0day-ci/archive/20250213/202502131226.6CIBwO2c-lkp@intel.com/config)
compiler: sh4-linux-gcc (GCC) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250213/202502131226.6CIBwO2c-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202502131226.6CIBwO2c-lkp@intel.com/
All errors (new ones prefixed by >>):
drivers/iio/imu/adis.c: In function '__adis_check_status':
>> drivers/iio/imu/adis.c:319:42: error: passing argument 3 of '__adis_read_reg_16' makes pointer from integer without a cast [-Wint-conversion]
319 | status_16);
| ^~~~~~~~~
| |
| u16 {aka short unsigned int}
In file included from drivers/iio/imu/adis.c:19:
include/linux/iio/imu/adis.h:225:43: note: expected 'u16 *' {aka 'short unsigned int *'} but argument is of type 'u16' {aka 'short unsigned int'}
225 | u16 *val)
| ~~~~~^~~
vim +/__adis_read_reg_16 +319 drivers/iio/imu/adis.c
298
299 /**
300 * __adis_check_status() - Check the device for error conditions (unlocked)
301 * @adis: The adis device
302 *
303 * Returns 0 on success, a negative error code otherwise
304 */
305 int __adis_check_status(struct adis *adis)
306 {
307 unsigned int status;
308 int diag_stat_bits;
309 u16 status_16;
310 int ret;
311 int i;
312
313 if (adis->data->diag_stat_size)
314 ret = adis->ops->read(adis, adis->data->diag_stat_reg, &status,
315 adis->data->diag_stat_size);
316 else
317 {
318 ret = __adis_read_reg_16(adis, adis->data->diag_stat_reg,
> 319 status_16);
320 status = status_16;
321 }
322 if (ret)
323 return ret;
324
325 status &= adis->data->status_error_mask;
326
327 if (status == 0)
328 return 0;
329
330 diag_stat_bits = BITS_PER_BYTE * (adis->data->diag_stat_size ?
331 adis->data->diag_stat_size : 2);
332
333 for (i = 0; i < diag_stat_bits; ++i) {
334 if (status & BIT(i)) {
335 dev_err(&adis->spi->dev, "%s.\n",
336 adis->data->status_error_msgs[i]);
337 }
338 }
339
340 return -EIO;
341 }
342 EXPORT_SYMBOL_NS_GPL(__adis_check_status, "IIO_ADISLIB");
343
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Hi Robert,
kernel test robot noticed the following build errors:
[auto build test ERROR on jic23-iio/togreg]
[also build test ERROR on linus/master v6.14-rc2 next-20250212]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Robert-Budai/iio-imu-adis-Add-custom-ops-struct/20250212-040235
base: https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git togreg
patch link: https://lore.kernel.org/r/20250211175706.276987-4-robert.budai%40analog.com
patch subject: [PATCH v7 3/6] iio: imu: adis: Add DIAG_STAT register
config: i386-buildonly-randconfig-002-20250213 (https://download.01.org/0day-ci/archive/20250213/202502131358.EsqgzVi7-lkp@intel.com/config)
compiler: clang version 19.1.3 (https://github.com/llvm/llvm-project ab51eccf88f5321e7c60591c5546b254b6afab99)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250213/202502131358.EsqgzVi7-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202502131358.EsqgzVi7-lkp@intel.com/
All errors (new ones prefixed by >>):
>> drivers/iio/imu/adis.c:319:7: error: incompatible integer to pointer conversion passing 'u16' (aka 'unsigned short') to parameter of type 'u16 *' (aka 'unsigned short *'); take the address with & [-Wint-conversion]
319 | status_16);
| ^~~~~~~~~
| &
include/linux/iio/imu/adis.h:225:15: note: passing argument to parameter 'val' here
225 | u16 *val)
| ^
1 error generated.
vim +319 drivers/iio/imu/adis.c
298
299 /**
300 * __adis_check_status() - Check the device for error conditions (unlocked)
301 * @adis: The adis device
302 *
303 * Returns 0 on success, a negative error code otherwise
304 */
305 int __adis_check_status(struct adis *adis)
306 {
307 unsigned int status;
308 int diag_stat_bits;
309 u16 status_16;
310 int ret;
311 int i;
312
313 if (adis->data->diag_stat_size)
314 ret = adis->ops->read(adis, adis->data->diag_stat_reg, &status,
315 adis->data->diag_stat_size);
316 else
317 {
318 ret = __adis_read_reg_16(adis, adis->data->diag_stat_reg,
> 319 status_16);
320 status = status_16;
321 }
322 if (ret)
323 return ret;
324
325 status &= adis->data->status_error_mask;
326
327 if (status == 0)
328 return 0;
329
330 diag_stat_bits = BITS_PER_BYTE * (adis->data->diag_stat_size ?
331 adis->data->diag_stat_size : 2);
332
333 for (i = 0; i < diag_stat_bits; ++i) {
334 if (status & BIT(i)) {
335 dev_err(&adis->spi->dev, "%s.\n",
336 adis->data->status_error_msgs[i]);
337 }
338 }
339
340 return -EIO;
341 }
342 EXPORT_SYMBOL_NS_GPL(__adis_check_status, "IIO_ADISLIB");
343
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Hi Robert,
kernel test robot noticed the following build warnings:
[auto build test WARNING on jic23-iio/togreg]
[also build test WARNING on linus/master v6.14-rc2 next-20250213]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Robert-Budai/iio-imu-adis-Add-custom-ops-struct/20250212-040235
base: https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git togreg
patch link: https://lore.kernel.org/r/20250211175706.276987-4-robert.budai%40analog.com
patch subject: [PATCH v7 3/6] iio: imu: adis: Add DIAG_STAT register
config: arc-randconfig-r112-20250213 (https://download.01.org/0day-ci/archive/20250214/202502140107.SF1UwFxM-lkp@intel.com/config)
compiler: arceb-elf-gcc (GCC) 13.2.0
reproduce: (https://download.01.org/0day-ci/archive/20250214/202502140107.SF1UwFxM-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202502140107.SF1UwFxM-lkp@intel.com/
sparse warnings: (new ones prefixed by >>)
>> drivers/iio/imu/adis.c:319:42: sparse: sparse: incorrect type in argument 3 (different base types) @@ expected unsigned short [usertype] *val @@ got unsigned short [usertype] status_16 @@
drivers/iio/imu/adis.c:319:42: sparse: expected unsigned short [usertype] *val
drivers/iio/imu/adis.c:319:42: sparse: got unsigned short [usertype] status_16
>> drivers/iio/imu/adis.c:319:42: sparse: sparse: non size-preserving integer to pointer cast
vim +319 drivers/iio/imu/adis.c
298
299 /**
300 * __adis_check_status() - Check the device for error conditions (unlocked)
301 * @adis: The adis device
302 *
303 * Returns 0 on success, a negative error code otherwise
304 */
305 int __adis_check_status(struct adis *adis)
306 {
307 unsigned int status;
308 int diag_stat_bits;
309 u16 status_16;
310 int ret;
311 int i;
312
313 if (adis->data->diag_stat_size)
314 ret = adis->ops->read(adis, adis->data->diag_stat_reg, &status,
315 adis->data->diag_stat_size);
316 else
317 {
318 ret = __adis_read_reg_16(adis, adis->data->diag_stat_reg,
> 319 status_16);
320 status = status_16;
321 }
322 if (ret)
323 return ret;
324
325 status &= adis->data->status_error_mask;
326
327 if (status == 0)
328 return 0;
329
330 diag_stat_bits = BITS_PER_BYTE * (adis->data->diag_stat_size ?
331 adis->data->diag_stat_size : 2);
332
333 for (i = 0; i < diag_stat_bits; ++i) {
334 if (status & BIT(i)) {
335 dev_err(&adis->spi->dev, "%s.\n",
336 adis->data->status_error_msgs[i]);
337 }
338 }
339
340 return -EIO;
341 }
342 EXPORT_SYMBOL_NS_GPL(__adis_check_status, "IIO_ADISLIB");
343
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
© 2016 - 2026 Red Hat, Inc.