linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lorenzo Bianconi <lorenzo@kernel.org>
To: Martin Kepplinger <martin.kepplinger@puri.sm>
Cc: Jonathan Cameron <jic23@kernel.org>,
	lorenzo.bianconi@redhat.com, linux-iio@vger.kernel.org
Subject: Re: [BUG] Re: [PATCH] iio: imu: st_lsm6dsx: remove invalid gain value for LSM9DS1
Date: Fri, 30 Aug 2019 09:23:54 +0200	[thread overview]
Message-ID: <20190830072354.GA5910@localhost.localdomain> (raw)
In-Reply-To: <f34694f0-ea7c-0327-532d-7a2904952771@puri.sm>

[-- Attachment #1: Type: text/plain, Size: 14587 bytes --]

> On 29.08.19 10:37, Lorenzo Bianconi wrote:
> >> On 27.08.19 22:08, Jonathan Cameron wrote:
> >>> On Tue, 27 Aug 2019 10:26:35 +0200
> >>> Lorenzo Bianconi <lorenzo@kernel.org> wrote:
> >>>
> >>>> Get rid of invalid sensitivity value for LSM9DS1 gyro sensor
> >>>>
> >>>> Fixes: 687a60feb9c6 ("iio: imu: st_lsm6dsx: add support for accel/gyro unit of lsm9ds1")
> >>>> Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
> >>> The zero degree scale is certainly odd otherwise, so good to tidy
> >>> this up.
> >>>
> >>> Applied to the togreg branch of iio.git.
> >>>

[...]

> > struct st_lsm6dsx_fs_table_entry in st_lsm6dsx_settings will always have 4
> > elements for fs_avl array and since the array is defined as static the
> > uninitialized elements are set to 0.
> > 
> > Could you please share the ops you are getting?
> > 
> 
> How this oops during startup can look like is appended below. I know
> that exactly this change causes it. Can you test this too please?

I did it but I have no issues

> 
> Given the cleanup nature of this patch, I think it's best to revert it
> in case of any doubt.
> 
> thanks,
> 
>                           martin
> 

is it the full ops? It seems some parts are missing.
Are you running some userspace aps reading in_anglvel_scale_available or reading/writing in in_anglvel_scale?
Could you please double check if the following patch helps? (just compiled)

Regards,
Lorenzo

---
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h      |  1 +
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 28 +++++++++++++-------
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c |  3 ++-
 3 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
index 5e3cd96b0059..a6cd736fd273 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
@@ -100,6 +100,7 @@ struct st_lsm6dsx_fs {
 struct st_lsm6dsx_fs_table_entry {
 	struct st_lsm6dsx_reg reg;
 	struct st_lsm6dsx_fs fs_avl[ST_LSM6DSX_FS_LIST_SIZE];
+	int len;
 };
 
 /**
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
index 2d3495560136..37a2aa211757 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
@@ -145,6 +145,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 },
 				.fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 },
 				.fs_avl[3] = { IIO_G_TO_M_S_2(732), 0x1 },
+				.len = 4,
 			},
 			[ST_LSM6DSX_ID_GYRO] = {
 				.reg = {
@@ -154,6 +155,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.fs_avl[0] = {  IIO_DEGREE_TO_RAD(245), 0x0 },
 				.fs_avl[1] = {  IIO_DEGREE_TO_RAD(500), 0x1 },
 				.fs_avl[2] = { IIO_DEGREE_TO_RAD(2000), 0x3 },
+				.len = 3,
 			},
 		},
 	},
@@ -215,6 +217,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 },
 				.fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 },
 				.fs_avl[3] = { IIO_G_TO_M_S_2(488), 0x1 },
+				.len = 4,
 			},
 			[ST_LSM6DSX_ID_GYRO] = {
 				.reg = {
@@ -225,6 +228,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 },
 				.fs_avl[2] = { IIO_DEGREE_TO_RAD(35000), 0x2 },
 				.fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 },
+				.len = 4,
 			},
 		},
 		.decimator = {
@@ -327,6 +331,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 },
 				.fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 },
 				.fs_avl[3] = { IIO_G_TO_M_S_2(488), 0x1 },
+				.len = 4,
 			},
 			[ST_LSM6DSX_ID_GYRO] = {
 				.reg = {
@@ -337,6 +342,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 },
 				.fs_avl[2] = { IIO_DEGREE_TO_RAD(35000), 0x2 },
 				.fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 },
+				.len = 4,
 			},
 		},
 		.decimator = {
@@ -448,6 +454,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 },
 				.fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 },
 				.fs_avl[3] = { IIO_G_TO_M_S_2(488), 0x1 },
+				.len = 4,
 			},
 			[ST_LSM6DSX_ID_GYRO] = {
 				.reg = {
@@ -458,6 +465,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 },
 				.fs_avl[2] = { IIO_DEGREE_TO_RAD(35000), 0x2 },
 				.fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 },
+				.len = 4,
 			},
 		},
 		.decimator = {
@@ -563,6 +571,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 },
 				.fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 },
 				.fs_avl[3] = { IIO_G_TO_M_S_2(488), 0x1 },
+				.len = 4,
 			},
 			[ST_LSM6DSX_ID_GYRO] = {
 				.reg = {
@@ -573,6 +582,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 },
 				.fs_avl[2] = { IIO_DEGREE_TO_RAD(35000), 0x2 },
 				.fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 },
+				.len = 4,
 			},
 		},
 		.batch = {
@@ -693,6 +703,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 },
 				.fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 },
 				.fs_avl[3] = { IIO_G_TO_M_S_2(488), 0x1 },
+				.len = 4,
 			},
 			[ST_LSM6DSX_ID_GYRO] = {
 				.reg = {
@@ -703,6 +714,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 },
 				.fs_avl[2] = { IIO_DEGREE_TO_RAD(35000), 0x2 },
 				.fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 },
+				.len = 4,
 			},
 		},
 		.batch = {
@@ -800,6 +812,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 },
 				.fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 },
 				.fs_avl[3] = { IIO_G_TO_M_S_2(488), 0x1 },
+				.len = 4,
 			},
 			[ST_LSM6DSX_ID_GYRO] = {
 				.reg = {
@@ -810,6 +823,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 },
 				.fs_avl[2] = { IIO_DEGREE_TO_RAD(35000), 0x2 },
 				.fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 },
+				.len = 4,
 			},
 		},
 		.batch = {
@@ -933,11 +947,12 @@ static int st_lsm6dsx_set_full_scale(struct st_lsm6dsx_sensor *sensor,
 	int i, err;
 
 	fs_table = &sensor->hw->settings->fs_table[sensor->id];
-	for (i = 0; i < ST_LSM6DSX_FS_LIST_SIZE; i++)
+	for (i = 0; i < fs_table->len; i++) {
 		if (fs_table->fs_avl[i].gain == gain)
 			break;
+	}
 
-	if (i == ST_LSM6DSX_FS_LIST_SIZE)
+	if (i == fs_table->len)
 		return -EINVAL;
 
 	data = ST_LSM6DSX_SHIFT_VAL(fs_table->fs_avl[i].val,
@@ -1196,18 +1211,13 @@ static ssize_t st_lsm6dsx_sysfs_scale_avail(struct device *dev,
 {
 	struct st_lsm6dsx_sensor *sensor = iio_priv(dev_get_drvdata(dev));
 	const struct st_lsm6dsx_fs_table_entry *fs_table;
-	enum st_lsm6dsx_sensor_id id = sensor->id;
 	struct st_lsm6dsx_hw *hw = sensor->hw;
 	int i, len = 0;
 
-	fs_table = &hw->settings->fs_table[id];
-	for (i = 0; i < ST_LSM6DSX_FS_LIST_SIZE; i++) {
-		if (!fs_table->fs_avl[i].gain)
-			break;
-
+	fs_table = &hw->settings->fs_table[sensor->id];
+	for (i = 0; i < fs_table->len; i++)
 		len += scnprintf(buf + len, PAGE_SIZE - len, "0.%06u ",
 				 fs_table->fs_avl[i].gain);
-	}
 	buf[len - 1] = '\n';
 
 	return len;
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c
index 66fbcd94642d..dcf349278e8f 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c
@@ -61,6 +61,7 @@ static const struct st_lsm6dsx_ext_dev_settings st_lsm6dsx_ext_dev_table[] = {
 				.gain = 1500,
 				.val = 0x0,
 			}, /* 1500 uG/LSB */
+			.len = 1,
 		},
 		.temp_comp = {
 			.addr = 0x60,
@@ -555,7 +556,7 @@ static ssize_t st_lsm6dsx_shub_scale_avail(struct device *dev,
 	int i, len = 0;
 
 	settings = sensor->ext_info.settings;
-	for (i = 0; i < ST_LSM6DSX_FS_LIST_SIZE; i++) {
+	for (i = 0; i < settings->fs_table.len; i++) {
 		u16 val = settings->fs_table.fs_avl[i].gain;
 
 		if (val > 0)
-- 
2.21.0


> 
> 
> Feb 14 10:12:00 pureos kernel: [    4.056014] Data abort info:
> Feb 14 10:12:00 pureos kernel: [    4.061361] bq25890-charger 0-006b:
> Capacity for 4184000 is 99%
> Feb 14 10:12:00 pureos kernel: [    4.064751]   ISV = 0, ISS = 0x00000004
> Feb 14 10:12:00 pureos kernel: [    4.070942]   CM = 0, WnR = 0
> Feb 14 10:12:00 pureos kernel: [    4.076588] user pgtable: 4k pages,
> 48-bit VAs, pgdp=00000000e4fa6000
> Feb 14 10:12:00 pureos kernel: [    4.086256] [0000000000000018]
> pgd=0000000000000000
> Feb 14 10:12:00 pureos kernel: [    4.100224] Internal error: Oops:
> 96000004 [#1] PREEMPT SMP
> Feb 14 10:12:00 pureos kernel: [    4.101985] Goodix-TS 2-005d: ID 5688,
> version: 0100
> Feb 14 10:12:00 pureos kernel: [    4.106038] Modules linked in:
> crct10dif_ce(+) st_magn_i2c(+) st_lsm6dsx_i2c(+) st_magn st_lsm6dsx
> snd_soc_sgtl5000(+) st_sensors_i2c st_sensors tcpci
> industrialio_triggered_buffer vcnl4000 kfifo_buf snd_soc_simple_card
> snd_soc_fsl_sai tcpm ghash_ce bq25890_charger snd_soc_gtm601
> snd_soc_simple_card_utils imx_pcm_dma goodix(+) roles snd_soc_core typec
> sha2_ce snd_pcm_dmaengine snd_pcm imx_sdma imx2_wdt sha1_ce snvs_pwrkey
> gpio_vibra qoriq_thermal virt_dma snd_timer watchdog snd soundcore
> usb_f_acm u_serial usb_f_rndis g_multi usb_f_mass_storage u_ether
> libcomposite ip_tables x_tables ipv6 nf_defrag_ipv6 xhci_plat_hcd
> xhci_hcd usbcore dwc3 ulpi udc_core usb_common phy_fsl_imx8mq_usb
> Feb 14 10:12:00 pureos kernel: [    4.113252] Goodix-TS 2-005d: Direct
> firmware load for goodix_5688_cfg.bin failed with error -2
> Feb 14 10:12:00 pureos kernel: [    4.174094] CPU: 2 PID: 341 Comm:
> systemd-udevd Tainted: G        W         5.3.0-rc2-gc652c7f46913 #141
> Feb 14 10:12:00 pureos kernel: [    4.174096] Hardware name: Purism
> Librem 5 devkit (DT)
> Feb 14 10:12:00 pureos kernel: [    4.174100] pstate: 80000005 (Nzcv
> daif -PAN -UAO)
> Feb 14 10:12:00 pureos kernel: [    4.174113] pc :
> st_lsm6dsx_i2c_probe+0x18/0x80 [st_lsm6dsx_i2c]
> Feb 14 10:12:00 pureos kernel: [    4.174124] lr :
> i2c_device_probe+0x1f0/0x2b8
> Feb 14 10:12:00 pureos kernel: [    4.174126] sp : ffff8000a4837970
> Feb 14 10:12:00 pureos kernel: [    4.174128] x29: ffff8000a4837970 x28:
> 0000000000000000
> Feb 14 10:12:00 pureos kernel: [    4.174132] x27: ffff000010b70000 x26:
> ffff8000a4837d68
> Feb 14 10:12:00 pureos kernel: [    4.174135] x25: ffff000010860000 x24:
> ffff000008a94038
> Feb 14 10:12:00 pureos kernel: [    4.174139] x23: ffff000008a94038 x22:
> ffff000008a94000
> Feb 14 10:12:00 pureos kernel: [    4.174142] x21: ffff8000a55a0400 x20:
> ffff000008a92000
> Feb 14 10:12:00 pureos kernel: [    4.174146] x19: ffff8000a55a0400 x18:
> ffffffffffffffff
> Feb 14 10:12:00 pureos kernel: [    4.174149] x17: 0000000000000000 x16:
> 0000000000000000
> Feb 14 10:12:00 pureos kernel: [    4.174152] x15: 0000000000040000 x14:
> 00000000fffffff0
> Feb 14 10:12:00 pureos kernel: [    4.174156] x13: 0000000000000001 x12:
> 0000000000000000
> Feb 14 10:12:00 pureos kernel: [    4.174159] x11: 0000000000000000 x10:
> 0101010101010101
> Feb 14 10:12:00 pureos kernel: [    4.174162] x9 : fffffffffffffffc x8 :
> 0000000000000008
> Feb 14 10:12:00 pureos kernel: [    4.174166] x7 : 0000000000000004 x6 :
> 1e0e1a00f2ade4ef
> Feb 14 10:12:00 pureos kernel: [    4.174169] x5 : 6f642d72001a0e1e x4 :
> 8080808000000000
> Feb 14 10:12:00 pureos kernel: [    4.174173] x3 : 0000000000000000 x2 :
> ffff000008a93000
> Feb 14 10:12:00 pureos kernel: [    4.193031] driver: 'Goodix-TS':
> driver_bound: bound to device '2-005d'
> Feb 14 10:12:00 pureos kernel: [    4.193105] x1 : 0000000000000000 x0 :
> ffff8000a55a0400
> Feb 14 10:12:00 pureos kernel: [    4.199343] bus: 'i2c': really_probe:
> bound device 2-005d to driver Goodix-TS
> Feb 14 10:12:00 pureos kernel: [    4.203445] Call trace:
> Feb 14 10:12:00 pureos kernel: [    4.203456]
> st_lsm6dsx_i2c_probe+0x18/0x80 [st_lsm6dsx_i2c]
> Feb 14 10:12:00 pureos kernel: [    4.203462]  i2c_device_probe+0x1f0/0x2b8
> Feb 14 10:12:00 pureos kernel: [    4.203468]  really_probe+0x168/0x368
> Feb 14 10:12:00 pureos kernel: [    4.203471]
> driver_probe_device.part.2+0x10c/0x128
> Feb 14 10:12:00 pureos kernel: [    4.203475]
> device_driver_attach+0x74/0xa0
> Feb 14 10:12:00 pureos kernel: [    4.203478]  __driver_attach+0x84/0x130
> Feb 14 10:12:00 pureos kernel: [    4.203481]  bus_for_each_dev+0x68/0xc8
> Feb 14 10:12:00 pureos kernel: [    4.203484]  driver_attach+0x20/0x28
> Feb 14 10:12:00 pureos kernel: [    4.203487]  bus_add_driver+0xd4/0x1f8
> Feb 14 10:12:00 pureos kernel: [    4.203490]  driver_register+0x60/0x110
> Feb 14 10:12:00 pureos kernel: [    4.203497]  i2c_register_driver+0x44/0x98
> Feb 14 10:12:00 pureos kernel: [    4.216908] devices_kset: Moving sound
> to end of list
> Feb 14 10:12:00 pureos kernel: [    4.217738]
> st_lsm6dsx_driver_init+0x1c/0x1000 [st_lsm6dsx_i2c]
> Feb 14 10:12:00 pureos kernel: [    4.217744]  do_one_initcall+0x58/0x1a8
> Feb 14 10:12:00 pureos kernel: [    4.217749]  do_init_module+0x54/0x1d4
> Feb 14 10:12:00 pureos kernel: [    4.217752]  load_module+0x1998/0x1c40
> Feb 14 10:12:00 pureos kernel: [    4.217755]
> __se_sys_finit_module+0xc0/0xd8
> Feb 14 10:12:00 pureos kernel: [    4.217761]
> __arm64_sys_finit_module+0x14/0x20
> Feb 14 10:12:00 pureos kernel: [    4.223515] PM: Moving platform:sound
> to end of list
> Feb 14 10:12:00 pureos kernel: [    4.228823]
> el0_svc_common.constprop.0+0xb0/0x168
> Feb 14 10:12:00 pureos kernel: [    4.228827]  el0_svc_handler+0x18/0x20
> Feb 14 10:12:00 pureos kernel: [    4.228830]  el0_svc+0x8/0xc
> Feb 14 10:12:00 pureos kernel: [    4.228838] Code: d2800003 910003fd
> a90153f3 aa0003f3 (f9400c34)
> Feb 14 10:12:00 pureos kernel: [    4.228843] ---[ end trace
> 4933f7b108d54662 ]---
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

  reply	other threads:[~2019-08-30  7:24 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-27  8:26 [PATCH] iio: imu: st_lsm6dsx: remove invalid gain value for LSM9DS1 Lorenzo Bianconi
2019-08-27 20:08 ` Jonathan Cameron
2019-08-29  5:27   ` [BUG] " Martin Kepplinger
2019-08-29  5:50     ` [PATCH] Revert "iio: imu: st_lsm6dsx: remove invalid gain value for LSM9DS1" Martin Kepplinger
2019-08-29  8:37     ` [BUG] Re: [PATCH] iio: imu: st_lsm6dsx: remove invalid gain value for LSM9DS1 Lorenzo Bianconi
2019-08-30  6:01       ` Martin Kepplinger
2019-08-30  7:23         ` Lorenzo Bianconi [this message]
2019-08-30 12:53           ` Martin Kepplinger
2019-08-31  9:32             ` Lorenzo Bianconi
2019-09-01 14:50               ` Jonathan Cameron
2019-09-03  5:22                 ` Martin Kepplinger
2019-09-03 12:37                   ` Jonathan Cameron

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190830072354.GA5910@localhost.localdomain \
    --to=lorenzo@kernel.org \
    --cc=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=lorenzo.bianconi@redhat.com \
    --cc=martin.kepplinger@puri.sm \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).