Re: [PATCH 2/2] iio: accel: Add driver for Murata SCA3300 accelerometer
( On Mon, Apr 19, 2021 at 11:15 PM Jonathan Cameron wrote: > > On Mon, 19 Apr 2021 20:45:08 +0100 > Jonathan Cameron wrote: > > > On Mon, 19 Apr 2021 16:34:35 +0300 > > Tomas Melin wrote: > > > > > Hi, > > > > > > On 4/18/21 1:03 PM, Jonathan Cameron wrote: > > > > On Fri, 16 Apr 2021 15:21:14 +0300 > > > > Tomas Melin wrote: > > > > > > > >> Updated email-address for Alexandru. > > > >> > > > >> > > > >> On 4/16/21 3:17 PM, Tomas Melin wrote: > > > >>> On 4/15/21 11:41 AM, Tomas Melin wrote: > > > >>> > > > While working on updates I did notice something new which I cannot > > > > > > reproduce on older (5.10.17 kernel) version. If compiling this as a > > > module, getting error while > > > > > > unloading module: > > > > > > [ 40.200084] Unable to handle kernel NULL pointer dereference at > > > virtual address 0104 > > > ... > > > > > > [ 40.510054] Backtrace: > > > [ 40.512502] [] (iio_device_ioctl_handler_unregister) > > > from [] (iio_buffers_free_sysfs_and_mask+0x2c/0x6c) > > > [ 40.523735] [] (iio_buffers_free_sysfs_and_mask) from > > > [] (iio_device_unregister+0xa8/0xac) > > > [ 40.533746] r5:c1811228 r4:c1811000 > > > [ 40.537318] [] (iio_device_unregister) from [] > > > (devm_iio_device_unreg+0x1c/0x20) > > > [ 40.546461] r5:c2415000 r4:c25bab80 > > > [ 40.550025] [] (devm_iio_device_unreg) from [] > > > (release_nodes+0x1c0/0x1f0) > > > [ 40.558654] [] (release_nodes) from [] > > > (devres_release_all+0x40/0x60) > > > [ 40.566847] r10:0081 r9:c235 r8:c0100264 r7:0081 > > > r6:bf00c010 r5:c19be000 > > > [ 40.574669] r4:c1a91c00 > > > [ 40.577194] [] (devres_release_all) from [] > > > (device_release_driver_internal+0x120/0x1cc) > > > [ 40.587031] r5:c19be000 r4:c1a91c00 > > > [ 40.590596] [] (device_release_driver_internal) from > > > [] (driver_detach+0x54/0x90) > > > [ 40.599828] r7:0081 r6: r5:bf00c010 r4:c1a91c00 > > > [ 40.605482] [] (driver_detach) from [] > > > (bus_remove_driver+0x5c/0xb0) > > > [ 40.613583] r5:0800 r4:bf00c010 > > > [ 40.617148] [] (bus_remove_driver) from [] > > > (driver_unregister+0x38/0x5c) > > > [ 40.625596] r5:0800 r4:bf00c010 > > > [ 40.629161] [] (driver_unregister) from [] > > > (sca3300_driver_exit+0x14/0x8b4 [sca3300]) > > > [ 40.638747] r5:0800 r4:bf00c080 > > > [ 40.642311] [] (sca3300_driver_exit [sca3300]) from > > > [] (sys_delete_module+0x16c/0x238) > > > [ 40.651990] [] (sys_delete_module) from [] > > > (__sys_trace_return+0x0/0x1c) > > > [ 40.660435] Exception stack(0xc2351fa8 to 0xc2351ff0) > > > [ 40.665484] 1fa0: 0050e5a8 0050e5e4 > > > 0800 081d4b00 bec18af4 > > > [ 40.673661] 1fc0: 0050e5a8 bec18b50 0081 bec18e51 > > > 0050e190 0001 bec18d3c > > > [ 40.681834] 1fe0: 0050cf70 bec18afc 004f1ec8 b6ecb27c > > > [ 40.686887] r6:bec18b50 r5: r4:0050e5a8 > > > [ 40.691507] Code: e8bd4000 e1c020d0 e3a0cc01 e3001122 (e5823004) > > > [ 40.707675] ---[ end trace 189882b050077333 ]--- > > > > > > This happens when building against linux-next > > > 5.12.0-rc6-next-20210409. I'm failing to see what is wrong. Any > > > ideas? > > > > > > Thanks, > > > > > > Tomas > > > >>> > > > >>> Tested further that for this driver, loading and unloading as module > > > >>> works fine until commit: > > > >>> > > > >>> commit f73f7f4da581875f9b1f2fb8ebd1ab15ed634488 > > > >>> Author: Alexandru Ardelean > > > >>> Date: Mon Feb 15 12:40:39 2021 +0200 > > > >>> > > > >>> iio: buffer: add ioctl() to support opening extra buffers for IIO > > > >>> device > > > >>> > > > >>> > > > >>> Any thoughts what causes this issue? > > > > Is this still happening after fixing the ordering in probe / remove? > > > > (devm_iio_triggered_buffer_setup() being easiest way) > > > > > > > > As driver currently stands it's calling iio_triggered_buffer_cleanup > > > > before the managed cleanup of the iio_device_register() call. That > > > > should never happen so would be where I'd look for problems here. > > > > > > > > It is possible Alex's work is relying on that ordering being correct > > > > a little more than we previously were. I could be wrong though > > > > and could be something else going on! > > > > > > > > Jonathan > > > > > > > > +CC Alex's other email address. > > > > > > This is still happening with v3 of driver patchset, which uses only devm_* > > > > > > versions in probing. v5.12-rc7 works ok, I'm currently only seeing this > > > using linux-next. > > > > Thanks for checking. I've just fired up a VM and confirmed that the same > > thing is happening with creating and removing instances of the
[PATCH 2/2] iio: accel: Add driver for Murata SCA3300 accelerometer
On Mon, 19 Apr 2021 20:45:08 +0100 Jonathan Cameron wrote: > On Mon, 19 Apr 2021 16:34:35 +0300 > Tomas Melin wrote: > > > Hi, > > > > On 4/18/21 1:03 PM, Jonathan Cameron wrote: > > > On Fri, 16 Apr 2021 15:21:14 +0300 > > > Tomas Melin wrote: > > > > > >> Updated email-address for Alexandru. > > >> > > >> > > >> On 4/16/21 3:17 PM, Tomas Melin wrote: > > >>> On 4/15/21 11:41 AM, Tomas Melin wrote: > > >>> > > While working on updates I did notice something new which I cannot > > > > reproduce on older (5.10.17 kernel) version. If compiling this as a > > module, getting error while > > > > unloading module: > > > > [ 40.200084] Unable to handle kernel NULL pointer dereference at > > virtual address 0104 > > ... > > > > [ 40.510054] Backtrace: > > [ 40.512502] [] (iio_device_ioctl_handler_unregister) > > from [] (iio_buffers_free_sysfs_and_mask+0x2c/0x6c) > > [ 40.523735] [] (iio_buffers_free_sysfs_and_mask) from > > [] (iio_device_unregister+0xa8/0xac) > > [ 40.533746] r5:c1811228 r4:c1811000 > > [ 40.537318] [] (iio_device_unregister) from [] > > (devm_iio_device_unreg+0x1c/0x20) > > [ 40.546461] r5:c2415000 r4:c25bab80 > > [ 40.550025] [] (devm_iio_device_unreg) from [] > > (release_nodes+0x1c0/0x1f0) > > [ 40.558654] [] (release_nodes) from [] > > (devres_release_all+0x40/0x60) > > [ 40.566847] r10:0081 r9:c235 r8:c0100264 r7:0081 > > r6:bf00c010 r5:c19be000 > > [ 40.574669] r4:c1a91c00 > > [ 40.577194] [] (devres_release_all) from [] > > (device_release_driver_internal+0x120/0x1cc) > > [ 40.587031] r5:c19be000 r4:c1a91c00 > > [ 40.590596] [] (device_release_driver_internal) from > > [] (driver_detach+0x54/0x90) > > [ 40.599828] r7:0081 r6: r5:bf00c010 r4:c1a91c00 > > [ 40.605482] [] (driver_detach) from [] > > (bus_remove_driver+0x5c/0xb0) > > [ 40.613583] r5:0800 r4:bf00c010 > > [ 40.617148] [] (bus_remove_driver) from [] > > (driver_unregister+0x38/0x5c) > > [ 40.625596] r5:0800 r4:bf00c010 > > [ 40.629161] [] (driver_unregister) from [] > > (sca3300_driver_exit+0x14/0x8b4 [sca3300]) > > [ 40.638747] r5:0800 r4:bf00c080 > > [ 40.642311] [] (sca3300_driver_exit [sca3300]) from > > [] (sys_delete_module+0x16c/0x238) > > [ 40.651990] [] (sys_delete_module) from [] > > (__sys_trace_return+0x0/0x1c) > > [ 40.660435] Exception stack(0xc2351fa8 to 0xc2351ff0) > > [ 40.665484] 1fa0: 0050e5a8 0050e5e4 > > 0800 081d4b00 bec18af4 > > [ 40.673661] 1fc0: 0050e5a8 bec18b50 0081 bec18e51 > > 0050e190 0001 bec18d3c > > [ 40.681834] 1fe0: 0050cf70 bec18afc 004f1ec8 b6ecb27c > > [ 40.686887] r6:bec18b50 r5: r4:0050e5a8 > > [ 40.691507] Code: e8bd4000 e1c020d0 e3a0cc01 e3001122 (e5823004) > > [ 40.707675] ---[ end trace 189882b050077333 ]--- > > > > This happens when building against linux-next > > 5.12.0-rc6-next-20210409. I'm failing to see what is wrong. Any ideas? > > > > Thanks, > > > > Tomas > > >>> > > >>> Tested further that for this driver, loading and unloading as module > > >>> works fine until commit: > > >>> > > >>> commit f73f7f4da581875f9b1f2fb8ebd1ab15ed634488 > > >>> Author: Alexandru Ardelean > > >>> Date: Mon Feb 15 12:40:39 2021 +0200 > > >>> > > >>> iio: buffer: add ioctl() to support opening extra buffers for IIO > > >>> device > > >>> > > >>> > > >>> Any thoughts what causes this issue? > > > Is this still happening after fixing the ordering in probe / remove? > > > (devm_iio_triggered_buffer_setup() being easiest way) > > > > > > As driver currently stands it's calling iio_triggered_buffer_cleanup > > > before the managed cleanup of the iio_device_register() call. That > > > should never happen so would be where I'd look for problems here. > > > > > > It is possible Alex's work is relying on that ordering being correct > > > a little more than we previously were. I could be wrong though > > > and could be something else going on! > > > > > > Jonathan > > > > > > +CC Alex's other email address. > > > > This is still happening with v3 of driver patchset, which uses only devm_* > > > > versions in probing. v5.12-rc7 works ok, I'm currently only seeing this > > using linux-next. > > Thanks for checking. I've just fired up a VM and confirmed that the same > thing is happening with creating and removing instances of the dummy driver. > > Will see if I can figure out what's going wrong. So the issue proved reasonably easy to track down. We remove the buffer ioctl handler twice. First in iio_device_unregister() in a loop over the list, and again later in
Re: [PATCH 2/2] iio: accel: Add driver for Murata SCA3300 accelerometer
On Mon, 19 Apr 2021 16:34:35 +0300 Tomas Melin wrote: > Hi, > > On 4/18/21 1:03 PM, Jonathan Cameron wrote: > > On Fri, 16 Apr 2021 15:21:14 +0300 > > Tomas Melin wrote: > > > >> Updated email-address for Alexandru. > >> > >> > >> On 4/16/21 3:17 PM, Tomas Melin wrote: > >>> On 4/15/21 11:41 AM, Tomas Melin wrote: > >>> > While working on updates I did notice something new which I cannot > > reproduce on older (5.10.17 kernel) version. If compiling this as a > module, getting error while > > unloading module: > > [ 40.200084] Unable to handle kernel NULL pointer dereference at > virtual address 0104 > ... > > [ 40.510054] Backtrace: > [ 40.512502] [] (iio_device_ioctl_handler_unregister) > from [] (iio_buffers_free_sysfs_and_mask+0x2c/0x6c) > [ 40.523735] [] (iio_buffers_free_sysfs_and_mask) from > [] (iio_device_unregister+0xa8/0xac) > [ 40.533746] r5:c1811228 r4:c1811000 > [ 40.537318] [] (iio_device_unregister) from [] > (devm_iio_device_unreg+0x1c/0x20) > [ 40.546461] r5:c2415000 r4:c25bab80 > [ 40.550025] [] (devm_iio_device_unreg) from [] > (release_nodes+0x1c0/0x1f0) > [ 40.558654] [] (release_nodes) from [] > (devres_release_all+0x40/0x60) > [ 40.566847] r10:0081 r9:c235 r8:c0100264 r7:0081 > r6:bf00c010 r5:c19be000 > [ 40.574669] r4:c1a91c00 > [ 40.577194] [] (devres_release_all) from [] > (device_release_driver_internal+0x120/0x1cc) > [ 40.587031] r5:c19be000 r4:c1a91c00 > [ 40.590596] [] (device_release_driver_internal) from > [] (driver_detach+0x54/0x90) > [ 40.599828] r7:0081 r6: r5:bf00c010 r4:c1a91c00 > [ 40.605482] [] (driver_detach) from [] > (bus_remove_driver+0x5c/0xb0) > [ 40.613583] r5:0800 r4:bf00c010 > [ 40.617148] [] (bus_remove_driver) from [] > (driver_unregister+0x38/0x5c) > [ 40.625596] r5:0800 r4:bf00c010 > [ 40.629161] [] (driver_unregister) from [] > (sca3300_driver_exit+0x14/0x8b4 [sca3300]) > [ 40.638747] r5:0800 r4:bf00c080 > [ 40.642311] [] (sca3300_driver_exit [sca3300]) from > [] (sys_delete_module+0x16c/0x238) > [ 40.651990] [] (sys_delete_module) from [] > (__sys_trace_return+0x0/0x1c) > [ 40.660435] Exception stack(0xc2351fa8 to 0xc2351ff0) > [ 40.665484] 1fa0: 0050e5a8 0050e5e4 > 0800 081d4b00 bec18af4 > [ 40.673661] 1fc0: 0050e5a8 bec18b50 0081 bec18e51 > 0050e190 0001 bec18d3c > [ 40.681834] 1fe0: 0050cf70 bec18afc 004f1ec8 b6ecb27c > [ 40.686887] r6:bec18b50 r5: r4:0050e5a8 > [ 40.691507] Code: e8bd4000 e1c020d0 e3a0cc01 e3001122 (e5823004) > [ 40.707675] ---[ end trace 189882b050077333 ]--- > > This happens when building against linux-next > 5.12.0-rc6-next-20210409. I'm failing to see what is wrong. Any ideas? > > Thanks, > > Tomas > >>> > >>> Tested further that for this driver, loading and unloading as module > >>> works fine until commit: > >>> > >>> commit f73f7f4da581875f9b1f2fb8ebd1ab15ed634488 > >>> Author: Alexandru Ardelean > >>> Date: Mon Feb 15 12:40:39 2021 +0200 > >>> > >>> iio: buffer: add ioctl() to support opening extra buffers for IIO > >>> device > >>> > >>> > >>> Any thoughts what causes this issue? > > Is this still happening after fixing the ordering in probe / remove? > > (devm_iio_triggered_buffer_setup() being easiest way) > > > > As driver currently stands it's calling iio_triggered_buffer_cleanup > > before the managed cleanup of the iio_device_register() call. That > > should never happen so would be where I'd look for problems here. > > > > It is possible Alex's work is relying on that ordering being correct > > a little more than we previously were. I could be wrong though > > and could be something else going on! > > > > Jonathan > > > > +CC Alex's other email address. > > This is still happening with v3 of driver patchset, which uses only devm_* > > versions in probing. v5.12-rc7 works ok, I'm currently only seeing this > using linux-next. Thanks for checking. I've just fired up a VM and confirmed that the same thing is happening with creating and removing instances of the dummy driver. Will see if I can figure out what's going wrong. Jonathan > > Thanks, > > Tomas > > > >>> Thanks, > >>> > >>> Tomas > >>> > >>> > >>> > > > > >> --- > >> drivers/iio/accel/Kconfig | 13 ++ > >> drivers/iio/accel/Makefile | 1 + > >> drivers/iio/accel/sca3300.c | 434 > >> > >> 3 files changed, 448 insertions(+) > >> create mode 100644 drivers/iio/accel/sca3300.c > >> > >> diff --git a/drivers/iio/accel/Kconfig
Re: [PATCH 2/2] iio: accel: Add driver for Murata SCA3300 accelerometer
Hi, On 4/18/21 1:03 PM, Jonathan Cameron wrote: On Fri, 16 Apr 2021 15:21:14 +0300 Tomas Melin wrote: Updated email-address for Alexandru. On 4/16/21 3:17 PM, Tomas Melin wrote: On 4/15/21 11:41 AM, Tomas Melin wrote: While working on updates I did notice something new which I cannot reproduce on older (5.10.17 kernel) version. If compiling this as a module, getting error while unloading module: [ 40.200084] Unable to handle kernel NULL pointer dereference at virtual address 0104 ... [ 40.510054] Backtrace: [ 40.512502] [] (iio_device_ioctl_handler_unregister) from [] (iio_buffers_free_sysfs_and_mask+0x2c/0x6c) [ 40.523735] [] (iio_buffers_free_sysfs_and_mask) from [] (iio_device_unregister+0xa8/0xac) [ 40.533746] r5:c1811228 r4:c1811000 [ 40.537318] [] (iio_device_unregister) from [] (devm_iio_device_unreg+0x1c/0x20) [ 40.546461] r5:c2415000 r4:c25bab80 [ 40.550025] [] (devm_iio_device_unreg) from [] (release_nodes+0x1c0/0x1f0) [ 40.558654] [] (release_nodes) from [] (devres_release_all+0x40/0x60) [ 40.566847] r10:0081 r9:c235 r8:c0100264 r7:0081 r6:bf00c010 r5:c19be000 [ 40.574669] r4:c1a91c00 [ 40.577194] [] (devres_release_all) from [] (device_release_driver_internal+0x120/0x1cc) [ 40.587031] r5:c19be000 r4:c1a91c00 [ 40.590596] [] (device_release_driver_internal) from [] (driver_detach+0x54/0x90) [ 40.599828] r7:0081 r6: r5:bf00c010 r4:c1a91c00 [ 40.605482] [] (driver_detach) from [] (bus_remove_driver+0x5c/0xb0) [ 40.613583] r5:0800 r4:bf00c010 [ 40.617148] [] (bus_remove_driver) from [] (driver_unregister+0x38/0x5c) [ 40.625596] r5:0800 r4:bf00c010 [ 40.629161] [] (driver_unregister) from [] (sca3300_driver_exit+0x14/0x8b4 [sca3300]) [ 40.638747] r5:0800 r4:bf00c080 [ 40.642311] [] (sca3300_driver_exit [sca3300]) from [] (sys_delete_module+0x16c/0x238) [ 40.651990] [] (sys_delete_module) from [] (__sys_trace_return+0x0/0x1c) [ 40.660435] Exception stack(0xc2351fa8 to 0xc2351ff0) [ 40.665484] 1fa0: 0050e5a8 0050e5e4 0800 081d4b00 bec18af4 [ 40.673661] 1fc0: 0050e5a8 bec18b50 0081 bec18e51 0050e190 0001 bec18d3c [ 40.681834] 1fe0: 0050cf70 bec18afc 004f1ec8 b6ecb27c [ 40.686887] r6:bec18b50 r5: r4:0050e5a8 [ 40.691507] Code: e8bd4000 e1c020d0 e3a0cc01 e3001122 (e5823004) [ 40.707675] ---[ end trace 189882b050077333 ]--- This happens when building against linux-next 5.12.0-rc6-next-20210409. I'm failing to see what is wrong. Any ideas? Thanks, Tomas Tested further that for this driver, loading and unloading as module works fine until commit: commit f73f7f4da581875f9b1f2fb8ebd1ab15ed634488 Author: Alexandru Ardelean Date: Mon Feb 15 12:40:39 2021 +0200 iio: buffer: add ioctl() to support opening extra buffers for IIO device Any thoughts what causes this issue? Is this still happening after fixing the ordering in probe / remove? (devm_iio_triggered_buffer_setup() being easiest way) As driver currently stands it's calling iio_triggered_buffer_cleanup before the managed cleanup of the iio_device_register() call. That should never happen so would be where I'd look for problems here. It is possible Alex's work is relying on that ordering being correct a little more than we previously were. I could be wrong though and could be something else going on! Jonathan +CC Alex's other email address. This is still happening with v3 of driver patchset, which uses only devm_* versions in probing. v5.12-rc7 works ok, I'm currently only seeing this using linux-next. Thanks, Tomas Thanks, Tomas --- drivers/iio/accel/Kconfig | 13 ++ drivers/iio/accel/Makefile | 1 + drivers/iio/accel/sca3300.c | 434 3 files changed, 448 insertions(+) create mode 100644 drivers/iio/accel/sca3300.c diff --git a/drivers/iio/accel/Kconfig b/drivers/iio/accel/Kconfig index cceda3cecbcf..0dbf7b648e8a 100644 --- a/drivers/iio/accel/Kconfig +++ b/drivers/iio/accel/Kconfig @@ -450,6 +450,19 @@ config SCA3000 To compile this driver as a module, say M here: the module will be called sca3000. +config SCA3300 + tristate "Murata SCA3300 3-Axis Accelerometer Driver" + depends on SPI + select CRC8 + select IIO_BUFFER + select IIO_TRIGGERED_BUFFER + help + Say yes here to build support for Murata SCA3300 3-Axis + accelerometer. + + To compile this driver as a module, choose M here: the module will be + called sca3300. + config STK8312 tristate "Sensortek STK8312 3-Axis Accelerometer Driver" depends on I2C diff --git a/drivers/iio/accel/Makefile b/drivers/iio/accel/Makefile index 32cd1342a31a..4b56527a2b97 100644 --- a/drivers/iio/accel/Makefile +++ b/drivers/iio/accel/Makefile @@ -50,6 +50,7 @@ obj-$(CONFIG_MXC4005) += mxc4005.o obj-$(CONFIG_MXC6255) += mxc6255.o
Re: [PATCH 2/2] iio: accel: Add driver for Murata SCA3300 accelerometer
On Fri, 16 Apr 2021 15:21:14 +0300 Tomas Melin wrote: > Updated email-address for Alexandru. > > > On 4/16/21 3:17 PM, Tomas Melin wrote: > > On 4/15/21 11:41 AM, Tomas Melin wrote: > > > >> > >> While working on updates I did notice something new which I cannot > >> > >> reproduce on older (5.10.17 kernel) version. If compiling this as a > >> module, getting error while > >> > >> unloading module: > >> > >> [ 40.200084] Unable to handle kernel NULL pointer dereference at > >> virtual address 0104 > >> ... > >> > >> [ 40.510054] Backtrace: > >> [ 40.512502] [] (iio_device_ioctl_handler_unregister) > >> from [] (iio_buffers_free_sysfs_and_mask+0x2c/0x6c) > >> [ 40.523735] [] (iio_buffers_free_sysfs_and_mask) from > >> [] (iio_device_unregister+0xa8/0xac) > >> [ 40.533746] r5:c1811228 r4:c1811000 > >> [ 40.537318] [] (iio_device_unregister) from [] > >> (devm_iio_device_unreg+0x1c/0x20) > >> [ 40.546461] r5:c2415000 r4:c25bab80 > >> [ 40.550025] [] (devm_iio_device_unreg) from [] > >> (release_nodes+0x1c0/0x1f0) > >> [ 40.558654] [] (release_nodes) from [] > >> (devres_release_all+0x40/0x60) > >> [ 40.566847] r10:0081 r9:c235 r8:c0100264 r7:0081 > >> r6:bf00c010 r5:c19be000 > >> [ 40.574669] r4:c1a91c00 > >> [ 40.577194] [] (devres_release_all) from [] > >> (device_release_driver_internal+0x120/0x1cc) > >> [ 40.587031] r5:c19be000 r4:c1a91c00 > >> [ 40.590596] [] (device_release_driver_internal) from > >> [] (driver_detach+0x54/0x90) > >> [ 40.599828] r7:0081 r6: r5:bf00c010 r4:c1a91c00 > >> [ 40.605482] [] (driver_detach) from [] > >> (bus_remove_driver+0x5c/0xb0) > >> [ 40.613583] r5:0800 r4:bf00c010 > >> [ 40.617148] [] (bus_remove_driver) from [] > >> (driver_unregister+0x38/0x5c) > >> [ 40.625596] r5:0800 r4:bf00c010 > >> [ 40.629161] [] (driver_unregister) from [] > >> (sca3300_driver_exit+0x14/0x8b4 [sca3300]) > >> [ 40.638747] r5:0800 r4:bf00c080 > >> [ 40.642311] [] (sca3300_driver_exit [sca3300]) from > >> [] (sys_delete_module+0x16c/0x238) > >> [ 40.651990] [] (sys_delete_module) from [] > >> (__sys_trace_return+0x0/0x1c) > >> [ 40.660435] Exception stack(0xc2351fa8 to 0xc2351ff0) > >> [ 40.665484] 1fa0: 0050e5a8 0050e5e4 > >> 0800 081d4b00 bec18af4 > >> [ 40.673661] 1fc0: 0050e5a8 bec18b50 0081 bec18e51 > >> 0050e190 0001 bec18d3c > >> [ 40.681834] 1fe0: 0050cf70 bec18afc 004f1ec8 b6ecb27c > >> [ 40.686887] r6:bec18b50 r5: r4:0050e5a8 > >> [ 40.691507] Code: e8bd4000 e1c020d0 e3a0cc01 e3001122 (e5823004) > >> [ 40.707675] ---[ end trace 189882b050077333 ]--- > >> > >> This happens when building against linux-next > >> 5.12.0-rc6-next-20210409. I'm failing to see what is wrong. Any ideas? > >> > >> Thanks, > >> > >> Tomas > > > > > > Tested further that for this driver, loading and unloading as module > > works fine until commit: > > > > commit f73f7f4da581875f9b1f2fb8ebd1ab15ed634488 > > Author: Alexandru Ardelean > > Date: Mon Feb 15 12:40:39 2021 +0200 > > > > iio: buffer: add ioctl() to support opening extra buffers for IIO > > device > > > > > > Any thoughts what causes this issue? Is this still happening after fixing the ordering in probe / remove? (devm_iio_triggered_buffer_setup() being easiest way) As driver currently stands it's calling iio_triggered_buffer_cleanup before the managed cleanup of the iio_device_register() call. That should never happen so would be where I'd look for problems here. It is possible Alex's work is relying on that ordering being correct a little more than we previously were. I could be wrong though and could be something else going on! Jonathan +CC Alex's other email address. > > > > Thanks, > > > > Tomas > > > > > > > >> > >> > >>> > --- > drivers/iio/accel/Kconfig | 13 ++ > drivers/iio/accel/Makefile | 1 + > drivers/iio/accel/sca3300.c | 434 > > 3 files changed, 448 insertions(+) > create mode 100644 drivers/iio/accel/sca3300.c > > diff --git a/drivers/iio/accel/Kconfig b/drivers/iio/accel/Kconfig > index cceda3cecbcf..0dbf7b648e8a 100644 > --- a/drivers/iio/accel/Kconfig > +++ b/drivers/iio/accel/Kconfig > @@ -450,6 +450,19 @@ config SCA3000 > To compile this driver as a module, say M here: the module > will be > called sca3000. > +config SCA3300 > + tristate "Murata SCA3300 3-Axis Accelerometer Driver" > + depends on SPI > + select CRC8 > + select IIO_BUFFER > + select IIO_TRIGGERED_BUFFER > + help > + Say yes here to build support for Murata SCA3300 3-Axis > + accelerometer. > + > + To compile this driver as a module, choose M here: the > module will be > + called sca3300. > + >
Re: [PATCH 2/2] iio: accel: Add driver for Murata SCA3300 accelerometer
Updated email-address for Alexandru. On 4/16/21 3:17 PM, Tomas Melin wrote: On 4/15/21 11:41 AM, Tomas Melin wrote: While working on updates I did notice something new which I cannot reproduce on older (5.10.17 kernel) version. If compiling this as a module, getting error while unloading module: [ 40.200084] Unable to handle kernel NULL pointer dereference at virtual address 0104 ... [ 40.510054] Backtrace: [ 40.512502] [] (iio_device_ioctl_handler_unregister) from [] (iio_buffers_free_sysfs_and_mask+0x2c/0x6c) [ 40.523735] [] (iio_buffers_free_sysfs_and_mask) from [] (iio_device_unregister+0xa8/0xac) [ 40.533746] r5:c1811228 r4:c1811000 [ 40.537318] [] (iio_device_unregister) from [] (devm_iio_device_unreg+0x1c/0x20) [ 40.546461] r5:c2415000 r4:c25bab80 [ 40.550025] [] (devm_iio_device_unreg) from [] (release_nodes+0x1c0/0x1f0) [ 40.558654] [] (release_nodes) from [] (devres_release_all+0x40/0x60) [ 40.566847] r10:0081 r9:c235 r8:c0100264 r7:0081 r6:bf00c010 r5:c19be000 [ 40.574669] r4:c1a91c00 [ 40.577194] [] (devres_release_all) from [] (device_release_driver_internal+0x120/0x1cc) [ 40.587031] r5:c19be000 r4:c1a91c00 [ 40.590596] [] (device_release_driver_internal) from [] (driver_detach+0x54/0x90) [ 40.599828] r7:0081 r6: r5:bf00c010 r4:c1a91c00 [ 40.605482] [] (driver_detach) from [] (bus_remove_driver+0x5c/0xb0) [ 40.613583] r5:0800 r4:bf00c010 [ 40.617148] [] (bus_remove_driver) from [] (driver_unregister+0x38/0x5c) [ 40.625596] r5:0800 r4:bf00c010 [ 40.629161] [] (driver_unregister) from [] (sca3300_driver_exit+0x14/0x8b4 [sca3300]) [ 40.638747] r5:0800 r4:bf00c080 [ 40.642311] [] (sca3300_driver_exit [sca3300]) from [] (sys_delete_module+0x16c/0x238) [ 40.651990] [] (sys_delete_module) from [] (__sys_trace_return+0x0/0x1c) [ 40.660435] Exception stack(0xc2351fa8 to 0xc2351ff0) [ 40.665484] 1fa0: 0050e5a8 0050e5e4 0800 081d4b00 bec18af4 [ 40.673661] 1fc0: 0050e5a8 bec18b50 0081 bec18e51 0050e190 0001 bec18d3c [ 40.681834] 1fe0: 0050cf70 bec18afc 004f1ec8 b6ecb27c [ 40.686887] r6:bec18b50 r5: r4:0050e5a8 [ 40.691507] Code: e8bd4000 e1c020d0 e3a0cc01 e3001122 (e5823004) [ 40.707675] ---[ end trace 189882b050077333 ]--- This happens when building against linux-next 5.12.0-rc6-next-20210409. I'm failing to see what is wrong. Any ideas? Thanks, Tomas Tested further that for this driver, loading and unloading as module works fine until commit: commit f73f7f4da581875f9b1f2fb8ebd1ab15ed634488 Author: Alexandru Ardelean Date: Mon Feb 15 12:40:39 2021 +0200 iio: buffer: add ioctl() to support opening extra buffers for IIO device Any thoughts what causes this issue? Thanks, Tomas --- drivers/iio/accel/Kconfig | 13 ++ drivers/iio/accel/Makefile | 1 + drivers/iio/accel/sca3300.c | 434 3 files changed, 448 insertions(+) create mode 100644 drivers/iio/accel/sca3300.c diff --git a/drivers/iio/accel/Kconfig b/drivers/iio/accel/Kconfig index cceda3cecbcf..0dbf7b648e8a 100644 --- a/drivers/iio/accel/Kconfig +++ b/drivers/iio/accel/Kconfig @@ -450,6 +450,19 @@ config SCA3000 To compile this driver as a module, say M here: the module will be called sca3000. +config SCA3300 + tristate "Murata SCA3300 3-Axis Accelerometer Driver" + depends on SPI + select CRC8 + select IIO_BUFFER + select IIO_TRIGGERED_BUFFER + help + Say yes here to build support for Murata SCA3300 3-Axis + accelerometer. + + To compile this driver as a module, choose M here: the module will be + called sca3300. + config STK8312 tristate "Sensortek STK8312 3-Axis Accelerometer Driver" depends on I2C diff --git a/drivers/iio/accel/Makefile b/drivers/iio/accel/Makefile index 32cd1342a31a..4b56527a2b97 100644 --- a/drivers/iio/accel/Makefile +++ b/drivers/iio/accel/Makefile @@ -50,6 +50,7 @@ obj-$(CONFIG_MXC4005) += mxc4005.o obj-$(CONFIG_MXC6255) += mxc6255.o obj-$(CONFIG_SCA3000) += sca3000.o +obj-$(CONFIG_SCA3300) += sca3300.o obj-$(CONFIG_STK8312) += stk8312.o obj-$(CONFIG_STK8BA50) += stk8ba50.o diff --git a/drivers/iio/accel/sca3300.c b/drivers/iio/accel/sca3300.c new file mode 100644 index ..112fb88ecd3a --- /dev/null +++ b/drivers/iio/accel/sca3300.c @@ -0,0 +1,434 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (c) Vaisala Oyj. All rights reserved. Give a year for the copyright notice if you can. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define SCA3300_ALIAS "sca3300" + +#define SCA3300_REG_STATUS 0x6 +#define SCA3300_REG_MODE 0xd +#define SCA3300_REG_WHOAMI 0x10 +#define SCA3300_VALUE_SW_RESET 0x20 +#define
Re: [PATCH 2/2] iio: accel: Add driver for Murata SCA3300 accelerometer
On 4/15/21 11:41 AM, Tomas Melin wrote: While working on updates I did notice something new which I cannot reproduce on older (5.10.17 kernel) version. If compiling this as a module, getting error while unloading module: [ 40.200084] Unable to handle kernel NULL pointer dereference at virtual address 0104 ... [ 40.510054] Backtrace: [ 40.512502] [] (iio_device_ioctl_handler_unregister) from [] (iio_buffers_free_sysfs_and_mask+0x2c/0x6c) [ 40.523735] [] (iio_buffers_free_sysfs_and_mask) from [] (iio_device_unregister+0xa8/0xac) [ 40.533746] r5:c1811228 r4:c1811000 [ 40.537318] [] (iio_device_unregister) from [] (devm_iio_device_unreg+0x1c/0x20) [ 40.546461] r5:c2415000 r4:c25bab80 [ 40.550025] [] (devm_iio_device_unreg) from [] (release_nodes+0x1c0/0x1f0) [ 40.558654] [] (release_nodes) from [] (devres_release_all+0x40/0x60) [ 40.566847] r10:0081 r9:c235 r8:c0100264 r7:0081 r6:bf00c010 r5:c19be000 [ 40.574669] r4:c1a91c00 [ 40.577194] [] (devres_release_all) from [] (device_release_driver_internal+0x120/0x1cc) [ 40.587031] r5:c19be000 r4:c1a91c00 [ 40.590596] [] (device_release_driver_internal) from [] (driver_detach+0x54/0x90) [ 40.599828] r7:0081 r6: r5:bf00c010 r4:c1a91c00 [ 40.605482] [] (driver_detach) from [] (bus_remove_driver+0x5c/0xb0) [ 40.613583] r5:0800 r4:bf00c010 [ 40.617148] [] (bus_remove_driver) from [] (driver_unregister+0x38/0x5c) [ 40.625596] r5:0800 r4:bf00c010 [ 40.629161] [] (driver_unregister) from [] (sca3300_driver_exit+0x14/0x8b4 [sca3300]) [ 40.638747] r5:0800 r4:bf00c080 [ 40.642311] [] (sca3300_driver_exit [sca3300]) from [] (sys_delete_module+0x16c/0x238) [ 40.651990] [] (sys_delete_module) from [] (__sys_trace_return+0x0/0x1c) [ 40.660435] Exception stack(0xc2351fa8 to 0xc2351ff0) [ 40.665484] 1fa0: 0050e5a8 0050e5e4 0800 081d4b00 bec18af4 [ 40.673661] 1fc0: 0050e5a8 bec18b50 0081 bec18e51 0050e190 0001 bec18d3c [ 40.681834] 1fe0: 0050cf70 bec18afc 004f1ec8 b6ecb27c [ 40.686887] r6:bec18b50 r5: r4:0050e5a8 [ 40.691507] Code: e8bd4000 e1c020d0 e3a0cc01 e3001122 (e5823004) [ 40.707675] ---[ end trace 189882b050077333 ]--- This happens when building against linux-next 5.12.0-rc6-next-20210409. I'm failing to see what is wrong. Any ideas? Thanks, Tomas Tested further that for this driver, loading and unloading as module works fine until commit: commit f73f7f4da581875f9b1f2fb8ebd1ab15ed634488 Author: Alexandru Ardelean Date: Mon Feb 15 12:40:39 2021 +0200 iio: buffer: add ioctl() to support opening extra buffers for IIO device Any thoughts what causes this issue? Thanks, Tomas --- drivers/iio/accel/Kconfig | 13 ++ drivers/iio/accel/Makefile | 1 + drivers/iio/accel/sca3300.c | 434 3 files changed, 448 insertions(+) create mode 100644 drivers/iio/accel/sca3300.c diff --git a/drivers/iio/accel/Kconfig b/drivers/iio/accel/Kconfig index cceda3cecbcf..0dbf7b648e8a 100644 --- a/drivers/iio/accel/Kconfig +++ b/drivers/iio/accel/Kconfig @@ -450,6 +450,19 @@ config SCA3000 To compile this driver as a module, say M here: the module will be called sca3000. +config SCA3300 + tristate "Murata SCA3300 3-Axis Accelerometer Driver" + depends on SPI + select CRC8 + select IIO_BUFFER + select IIO_TRIGGERED_BUFFER + help + Say yes here to build support for Murata SCA3300 3-Axis + accelerometer. + + To compile this driver as a module, choose M here: the module will be + called sca3300. + config STK8312 tristate "Sensortek STK8312 3-Axis Accelerometer Driver" depends on I2C diff --git a/drivers/iio/accel/Makefile b/drivers/iio/accel/Makefile index 32cd1342a31a..4b56527a2b97 100644 --- a/drivers/iio/accel/Makefile +++ b/drivers/iio/accel/Makefile @@ -50,6 +50,7 @@ obj-$(CONFIG_MXC4005) += mxc4005.o obj-$(CONFIG_MXC6255) += mxc6255.o obj-$(CONFIG_SCA3000) += sca3000.o +obj-$(CONFIG_SCA3300) += sca3300.o obj-$(CONFIG_STK8312) += stk8312.o obj-$(CONFIG_STK8BA50) += stk8ba50.o diff --git a/drivers/iio/accel/sca3300.c b/drivers/iio/accel/sca3300.c new file mode 100644 index ..112fb88ecd3a --- /dev/null +++ b/drivers/iio/accel/sca3300.c @@ -0,0 +1,434 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (c) Vaisala Oyj. All rights reserved. Give a year for the copyright notice if you can. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define SCA3300_ALIAS "sca3300" + +#define SCA3300_REG_STATUS 0x6 +#define SCA3300_REG_MODE 0xd +#define SCA3300_REG_WHOAMI 0x10 +#define SCA3300_VALUE_SW_RESET 0x20 +#define SCA3300_CRC8_POLYNOMIAL 0x1d +#define SCA3300_X_READ 0 I wouldn't bother defining this.
Re: [PATCH 2/2] iio: accel: Add driver for Murata SCA3300 accelerometer
On 4/12/21 2:08 PM, Jonathan Cameron wrote: On Mon, 12 Apr 2021 10:50:56 +0300 Tomas Melin wrote: Add initial support for Murata SCA3300 3-axis industrial accelerometer with digital SPI interface. This device also provides a temperature measurement. Device product page including datasheet can be found at: https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.murata.com%2Fen-global%2Fproducts%2Fsensor%2Faccel%2Fsca3300data=04%7C01%7Ctomas.melin%40vaisala.com%7Ca66811c95e6c404aa5a208d8fda3743c%7C6d7393e041f54c2e9b124c2be5da5c57%7C0%7C0%7C637538225758011604%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000sdata=7bvCd52SFuYdFVlhYrknp0769%2B6hBpxdP6ln0OgKTrE%3Dreserved=0 Signed-off-by: Tomas Melin Hi Tomas, Comments below. Thanks, Jonathan Hi Jonathan, Thanks for your comments! I'll get back with a v2. While working on updates I did notice something new which I cannot reproduce on older (5.10.17 kernel) version. If compiling this as a module, getting error while unloading module: [ 40.200084] Unable to handle kernel NULL pointer dereference at virtual address 0104 ... [ 40.510054] Backtrace: [ 40.512502] [] (iio_device_ioctl_handler_unregister) from [] (iio_buffers_free_sysfs_and_mask+0x2c/0x6c) [ 40.523735] [] (iio_buffers_free_sysfs_and_mask) from [] (iio_device_unregister+0xa8/0xac) [ 40.533746] r5:c1811228 r4:c1811000 [ 40.537318] [] (iio_device_unregister) from [] (devm_iio_device_unreg+0x1c/0x20) [ 40.546461] r5:c2415000 r4:c25bab80 [ 40.550025] [] (devm_iio_device_unreg) from [] (release_nodes+0x1c0/0x1f0) [ 40.558654] [] (release_nodes) from [] (devres_release_all+0x40/0x60) [ 40.566847] r10:0081 r9:c235 r8:c0100264 r7:0081 r6:bf00c010 r5:c19be000 [ 40.574669] r4:c1a91c00 [ 40.577194] [] (devres_release_all) from [] (device_release_driver_internal+0x120/0x1cc) [ 40.587031] r5:c19be000 r4:c1a91c00 [ 40.590596] [] (device_release_driver_internal) from [] (driver_detach+0x54/0x90) [ 40.599828] r7:0081 r6: r5:bf00c010 r4:c1a91c00 [ 40.605482] [] (driver_detach) from [] (bus_remove_driver+0x5c/0xb0) [ 40.613583] r5:0800 r4:bf00c010 [ 40.617148] [] (bus_remove_driver) from [] (driver_unregister+0x38/0x5c) [ 40.625596] r5:0800 r4:bf00c010 [ 40.629161] [] (driver_unregister) from [] (sca3300_driver_exit+0x14/0x8b4 [sca3300]) [ 40.638747] r5:0800 r4:bf00c080 [ 40.642311] [] (sca3300_driver_exit [sca3300]) from [] (sys_delete_module+0x16c/0x238) [ 40.651990] [] (sys_delete_module) from [] (__sys_trace_return+0x0/0x1c) [ 40.660435] Exception stack(0xc2351fa8 to 0xc2351ff0) [ 40.665484] 1fa0: 0050e5a8 0050e5e4 0800 081d4b00 bec18af4 [ 40.673661] 1fc0: 0050e5a8 bec18b50 0081 bec18e51 0050e190 0001 bec18d3c [ 40.681834] 1fe0: 0050cf70 bec18afc 004f1ec8 b6ecb27c [ 40.686887] r6:bec18b50 r5: r4:0050e5a8 [ 40.691507] Code: e8bd4000 e1c020d0 e3a0cc01 e3001122 (e5823004) [ 40.707675] ---[ end trace 189882b050077333 ]--- This happens when building against linux-next 5.12.0-rc6-next-20210409. I'm failing to see what is wrong. Any ideas? Thanks, Tomas --- drivers/iio/accel/Kconfig | 13 ++ drivers/iio/accel/Makefile | 1 + drivers/iio/accel/sca3300.c | 434 3 files changed, 448 insertions(+) create mode 100644 drivers/iio/accel/sca3300.c diff --git a/drivers/iio/accel/Kconfig b/drivers/iio/accel/Kconfig index cceda3cecbcf..0dbf7b648e8a 100644 --- a/drivers/iio/accel/Kconfig +++ b/drivers/iio/accel/Kconfig @@ -450,6 +450,19 @@ config SCA3000 To compile this driver as a module, say M here: the module will be called sca3000. +config SCA3300 + tristate "Murata SCA3300 3-Axis Accelerometer Driver" + depends on SPI + select CRC8 + select IIO_BUFFER + select IIO_TRIGGERED_BUFFER + help + Say yes here to build support for Murata SCA3300 3-Axis + accelerometer. + + To compile this driver as a module, choose M here: the module will be + called sca3300. + config STK8312 tristate "Sensortek STK8312 3-Axis Accelerometer Driver" depends on I2C diff --git a/drivers/iio/accel/Makefile b/drivers/iio/accel/Makefile index 32cd1342a31a..4b56527a2b97 100644 --- a/drivers/iio/accel/Makefile +++ b/drivers/iio/accel/Makefile @@ -50,6 +50,7 @@ obj-$(CONFIG_MXC4005) += mxc4005.o obj-$(CONFIG_MXC6255) += mxc6255.o obj-$(CONFIG_SCA3000) += sca3000.o +obj-$(CONFIG_SCA3300) += sca3300.o obj-$(CONFIG_STK8312) += stk8312.o obj-$(CONFIG_STK8BA50)+= stk8ba50.o diff --git a/drivers/iio/accel/sca3300.c b/drivers/iio/accel/sca3300.c new file mode 100644 index ..112fb88ecd3a --- /dev/null +++ b/drivers/iio/accel/sca3300.c @@ -0,0 +1,434 @@ +//
Re: [PATCH 2/2] iio: accel: Add driver for Murata SCA3300 accelerometer
On Mon, 12 Apr 2021 10:50:56 +0300 Tomas Melin wrote: > Add initial support for Murata SCA3300 3-axis industrial > accelerometer with digital SPI interface. This device also > provides a temperature measurement. > > Device product page including datasheet can be found at: > https://www.murata.com/en-global/products/sensor/accel/sca3300 > > Signed-off-by: Tomas Melin Hi Tomas, Comments below. Thanks, Jonathan > --- > drivers/iio/accel/Kconfig | 13 ++ > drivers/iio/accel/Makefile | 1 + > drivers/iio/accel/sca3300.c | 434 > 3 files changed, 448 insertions(+) > create mode 100644 drivers/iio/accel/sca3300.c > > diff --git a/drivers/iio/accel/Kconfig b/drivers/iio/accel/Kconfig > index cceda3cecbcf..0dbf7b648e8a 100644 > --- a/drivers/iio/accel/Kconfig > +++ b/drivers/iio/accel/Kconfig > @@ -450,6 +450,19 @@ config SCA3000 > To compile this driver as a module, say M here: the module will be > called sca3000. > > +config SCA3300 > + tristate "Murata SCA3300 3-Axis Accelerometer Driver" > + depends on SPI > + select CRC8 > + select IIO_BUFFER > + select IIO_TRIGGERED_BUFFER > + help > + Say yes here to build support for Murata SCA3300 3-Axis > + accelerometer. > + > + To compile this driver as a module, choose M here: the module will be > + called sca3300. > + > config STK8312 > tristate "Sensortek STK8312 3-Axis Accelerometer Driver" > depends on I2C > diff --git a/drivers/iio/accel/Makefile b/drivers/iio/accel/Makefile > index 32cd1342a31a..4b56527a2b97 100644 > --- a/drivers/iio/accel/Makefile > +++ b/drivers/iio/accel/Makefile > @@ -50,6 +50,7 @@ obj-$(CONFIG_MXC4005) += mxc4005.o > obj-$(CONFIG_MXC6255)+= mxc6255.o > > obj-$(CONFIG_SCA3000)+= sca3000.o > +obj-$(CONFIG_SCA3300)+= sca3300.o > > obj-$(CONFIG_STK8312)+= stk8312.o > obj-$(CONFIG_STK8BA50) += stk8ba50.o > diff --git a/drivers/iio/accel/sca3300.c b/drivers/iio/accel/sca3300.c > new file mode 100644 > index ..112fb88ecd3a > --- /dev/null > +++ b/drivers/iio/accel/sca3300.c > @@ -0,0 +1,434 @@ > +// SPDX-License-Identifier: GPL-2.0-only > +/* > + * Copyright (c) Vaisala Oyj. All rights reserved. Give a year for the copyright notice if you can. > + */ > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#define SCA3300_ALIAS "sca3300" > + > +#define SCA3300_REG_STATUS 0x6 > +#define SCA3300_REG_MODE 0xd > +#define SCA3300_REG_WHOAMI 0x10 > +#define SCA3300_VALUE_SW_RESET 0x20 > +#define SCA3300_CRC8_POLYNOMIAL 0x1d > +#define SCA3300_X_READ 0 I wouldn't bother defining this. > +#define SCA3300_X_WRITE BIT(7) Even this one is something I'd just put inline with a comment. > +#define SCA3300_DEVICE_ID 0x51 > +#define SCA3300_RS_ERROR 0x3 > + > +enum sca3300_scan_indexes { > + SCA3300_ACC_X = 0, > + SCA3300_ACC_Y, > + SCA3300_ACC_Z, > + SCA3300_TEMP, > + SCA3300_TIMESTAMP, > +}; > + > +#define SCA3300_ACCEL_CHANNEL(index, reg, axis) {\ > + .type = IIO_ACCEL, \ > + .address = reg, \ > + .modified = 1, \ > + .channel2 = IIO_MOD_##axis, \ > + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ > + BIT(IIO_CHAN_INFO_PROCESSED), \ As mentioned below, don't provide PROCESSED. Userspace is better at handling the conversion so leave it to them. > + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ > + .scan_index = index,\ > + .scan_type = { \ > + .sign = 's',\ > + .realbits = 16, \ > + .storagebits = 16, \ > + .shift = 0, \ > + .endianness = IIO_CPU, \ > + }, \ > + } > + > +static const struct iio_chan_spec sca3300_channels[] = { > + SCA3300_ACCEL_CHANNEL(SCA3300_ACC_X, 0x1, X), > + SCA3300_ACCEL_CHANNEL(SCA3300_ACC_Y, 0x2, Y), > + SCA3300_ACCEL_CHANNEL(SCA3300_ACC_Z, 0x3, Z), > + { > + .type = IIO_TEMP, > + .address = 0x5, > + .scan_index = SCA3300_TEMP, > + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), > + .scan_type = { > + .sign = 's', > + .realbits = 16, > +
[PATCH 2/2] iio: accel: Add driver for Murata SCA3300 accelerometer
Add initial support for Murata SCA3300 3-axis industrial accelerometer with digital SPI interface. This device also provides a temperature measurement. Device product page including datasheet can be found at: https://www.murata.com/en-global/products/sensor/accel/sca3300 Signed-off-by: Tomas Melin --- drivers/iio/accel/Kconfig | 13 ++ drivers/iio/accel/Makefile | 1 + drivers/iio/accel/sca3300.c | 434 3 files changed, 448 insertions(+) create mode 100644 drivers/iio/accel/sca3300.c diff --git a/drivers/iio/accel/Kconfig b/drivers/iio/accel/Kconfig index cceda3cecbcf..0dbf7b648e8a 100644 --- a/drivers/iio/accel/Kconfig +++ b/drivers/iio/accel/Kconfig @@ -450,6 +450,19 @@ config SCA3000 To compile this driver as a module, say M here: the module will be called sca3000. +config SCA3300 + tristate "Murata SCA3300 3-Axis Accelerometer Driver" + depends on SPI + select CRC8 + select IIO_BUFFER + select IIO_TRIGGERED_BUFFER + help + Say yes here to build support for Murata SCA3300 3-Axis + accelerometer. + + To compile this driver as a module, choose M here: the module will be + called sca3300. + config STK8312 tristate "Sensortek STK8312 3-Axis Accelerometer Driver" depends on I2C diff --git a/drivers/iio/accel/Makefile b/drivers/iio/accel/Makefile index 32cd1342a31a..4b56527a2b97 100644 --- a/drivers/iio/accel/Makefile +++ b/drivers/iio/accel/Makefile @@ -50,6 +50,7 @@ obj-$(CONFIG_MXC4005) += mxc4005.o obj-$(CONFIG_MXC6255) += mxc6255.o obj-$(CONFIG_SCA3000) += sca3000.o +obj-$(CONFIG_SCA3300) += sca3300.o obj-$(CONFIG_STK8312) += stk8312.o obj-$(CONFIG_STK8BA50) += stk8ba50.o diff --git a/drivers/iio/accel/sca3300.c b/drivers/iio/accel/sca3300.c new file mode 100644 index ..112fb88ecd3a --- /dev/null +++ b/drivers/iio/accel/sca3300.c @@ -0,0 +1,434 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (c) Vaisala Oyj. All rights reserved. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define SCA3300_ALIAS "sca3300" + +#define SCA3300_REG_STATUS 0x6 +#define SCA3300_REG_MODE 0xd +#define SCA3300_REG_WHOAMI 0x10 +#define SCA3300_VALUE_SW_RESET 0x20 +#define SCA3300_CRC8_POLYNOMIAL 0x1d +#define SCA3300_X_READ 0 +#define SCA3300_X_WRITE BIT(7) +#define SCA3300_DEVICE_ID 0x51 +#define SCA3300_RS_ERROR 0x3 + +enum sca3300_scan_indexes { + SCA3300_ACC_X = 0, + SCA3300_ACC_Y, + SCA3300_ACC_Z, + SCA3300_TEMP, + SCA3300_TIMESTAMP, +}; + +#define SCA3300_ACCEL_CHANNEL(index, reg, axis) { \ + .type = IIO_ACCEL, \ + .address = reg, \ + .modified = 1, \ + .channel2 = IIO_MOD_##axis, \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ + BIT(IIO_CHAN_INFO_PROCESSED), \ + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ + .scan_index = index,\ + .scan_type = { \ + .sign = 's',\ + .realbits = 16, \ + .storagebits = 16, \ + .shift = 0, \ + .endianness = IIO_CPU, \ + }, \ + } + +static const struct iio_chan_spec sca3300_channels[] = { + SCA3300_ACCEL_CHANNEL(SCA3300_ACC_X, 0x1, X), + SCA3300_ACCEL_CHANNEL(SCA3300_ACC_Y, 0x2, Y), + SCA3300_ACCEL_CHANNEL(SCA3300_ACC_Z, 0x3, Z), + { + .type = IIO_TEMP, + .address = 0x5, + .scan_index = SCA3300_TEMP, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), + .scan_type = { + .sign = 's', + .realbits = 16, + .storagebits = 16, + .shift = 0, + .endianness = IIO_CPU, + }, + }, + IIO_CHAN_SOFT_TIMESTAMP(4), +}; + +static const int sca3300_accel_scale[] = {2700, 1350, 5400, 5400}; + +static const unsigned long sca3300_scan_masks[] = { + BIT(SCA3300_ACC_X) | BIT(SCA3300_ACC_Y) | BIT(SCA3300_ACC_Z) | + BIT(SCA3300_TEMP), + 0}; + +/** + * SCA3300 device data + * + * @spi SPI device structure + * @opmode Device operation mode + * @lock Data buffer lock + * @txbuf Transmit buffer +