iio: accel: sca3300: Accelerometer support and binding docs
Subsystems (2)
v4 cover iio: accel: sca3300: Accelerometer support and binding docs
Patch series adds driver and dt-bindings for Murata SCA3300 accelerometer.
Device is a 3-axis Accelerometer with digital SPI interface.
Patches are tested and based on linux-next.
Changes V4:
Addressed comments from Andy Shevchenko
- Regrouped and renamed #define statements
- Added cacheline alignment for tx/rx buffers
- Changed irq handler print to be ratelimited
- Commented use of goto in irq handler
- Removed redundant 0x0 value
- Spacing errors fixed
- Removed redundant return statement
Changes V3:
Addressed comments from Jonathan Cameron and Andy Shevchenko
- Grouped include statements
- Revised SCA* define naming and grouped statements
- Changed to GENMASK() for masks
- Indentation fix for ACCEL_CHANNEL define
- Remove field declarations using default values
- Change to if(ret) style for checking return values
- Add defined mask value SCA3300_MASK_STATUS for return status
- Remove redundant casts
- Clarify comment wording
- Refactor to remove variable idx and redundant else branches
- Unify sleep in device init, separate sleeps not needed since operation mode change dropped
- Drop redundant memory allocation error message in probe
- dev.parent is set by iio core, removed from driver probe
- Drop of_match_ptr()
Changes V2:
Addressed comments from Jonathan Cameron
- Add manufacturer name to dt-binding file
- Update spdx license statement for dt-bindings
- Remove murata,opmode devicetree property in favor of driver scale + frequency properties
- Add copyright year for driver
- Remove X_READ and X_WRITE defines
- Add _available sysfs attributes
- Fix errors in documentation formatting
- Use ARRAY_SIZE where applicable
- Use get/put_unaligned_be16() helpers where applicable
- Factor out error handling to separate function
- Return only negative values from transfer function
- Fix INFO_SCALE to return multiplier instead of inverted value
- Change INFO_SCALE values to be actual scale instead of mode value
- Do not provide INFO_PROCESSED values for user space
- Add error message for failed data read in irq handler
- Move trigger handler timestamping as part of pushing data to buffers
- Document startup sequence, providing reference to data sheet section
- Convert iio_triggered_buffer_setup to devm_iio_triggered_buffer_setup, making remove() obsolete
Tomas Melin (2):
dt-bindings: iio: accel: Add SCA3300 documentation
iio: accel: Add driver for Murata SCA3300 accelerometer
.../bindings/iio/accel/murata,sca3300.yaml | 44 ++ drivers/iio/accel/Kconfig | 13 + drivers/iio/accel/Makefile | 1 + drivers/iio/accel/sca3300.c | 470 ++++++++++++++++++ 4 files changed, 528 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/accel/murata,sca3300.yaml create mode 100644 drivers/iio/accel/sca3300.c
Signature · 1 line
2.21.3
PATCH v4 1/2 dt-bindings: iio: accel: Add SCA3300 documentation
initial DT bindings for Murata SCA3300 Accelerometer.
--- .../bindings/iio/accel/murata,sca3300.yaml | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/accel/murata,sca3300.yaml
Documentation/devicetree/bindings/iio/accel/murata,sca3300.yaml new file +44 -0
@@ -0,0 +1,44 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/accel/murata,sca3300.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Murata SCA3300 Accelerometer + +description: | + 3-axis industrial accelerometer with digital SPI interface + https://www.murata.com/en-global/products/sensor/accel/sca3300 + +maintainers: + - Tomas Melin <[email protected]> + +properties: + compatible: + enum: + - murata,sca3300 + + reg: + maxItems: 1 + + spi-max-frequency: + maximum: 8000000 + +required: + - compatible + - reg + +additionalProperties: false + +examples: + - | + spi { + #address-cells = <1>; + #size-cells = <0>; + accelerometer@0 { + compatible = "murata,sca3300"; + reg = <0x0>; + spi-max-frequency = <4000000>; + }; + }; +...
Signature · 1 line
2.21.3
Re: [PATCH v4 1/2] dt-bindings: iio: accel: Add SCA3300 documentation
Quoted 8 lines · Tomas Melin
initial DT bindings for Murata SCA3300 Accelerometer.
Signed-off-by Tomas Melin <[email protected]>--- .../bindings/iio/accel/murata,sca3300.yaml | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/accel/murata,sca3300.yaml
PATCH v4 2/2 iio: accel: Add driver for Murata SCA3300 accelerometer
In reply to Tomas MelinAdd initial support for Murata SCA3300 3-axis industrial accelerometer with digital SPI interface. This device also provides a temperature measurement.
Datasheet: https://www.murata.com/en-global/products/sensor/accel/sca3300
--- drivers/iio/accel/Kconfig | 13 + drivers/iio/accel/Makefile | 1 + drivers/iio/accel/sca3300.c | 470 ++++++++++++++++++++++++++++++++++++ 3 files changed, 484 insertions(+) create mode 100644 drivers/iio/accel/sca3300.c
drivers/iio/accel/Kconfig +13 -0
@@ -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
drivers/iio/accel/Makefile +1 -0
@@ -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
drivers/iio/accel/sca3300.c new file +470 -0
470 lines not on this page · raw message
Signature · 1 line
2.21.3
Re: [PATCH v4 2/2] iio: accel: Add driver for Murata SCA3300 accelerometer
Quoted 4 lines · Tomas Melin
Add initial support for Murata SCA3300 3-axis industrial accelerometer with digital SPI interface. This device also provides a temperature measurement.
Thanks for an update, my comments below.
They can be addressed as followups, but I think regmap API can be considered right now.
...
Quoted 20 lines
drivers/iio/accel/sca3300.c new file +20
-0+static int sca3300_read_reg (struct sca3300_data *sca_data,u8 reg,int *val) +{ +int ret; + +mutex_lock (&sca_data->lock); + sca_data->txbuf[0 ] = reg <<2 ; + ret =sca3300_transfer (sca_data, val); +mutex_unlock (&sca_data->lock); +if (ret != -EINVAL ) +return ret; + +return sca3300_error_handler (sca_data); +} + +static int sca3300_write_reg (struct sca3300_data *sca_data,u8 reg,int val) +{ +int reg_val =0 ; +int ret; + +mutex_lock (&sca_data->lock);
drivers/iio/accel/sca3300.c line 224
Quoted 10 lines
drivers/iio/accel/sca3300.c new file +10
-0+/* BIT(7) for write operation */ + sca_data->txbuf[0 ] =BIT (7 ) | (reg <<2 ); +put_unaligned_be16 (val, &sca_data->txbuf[1 ]); + ret =sca3300_transfer (sca_data, ®_val); +mutex_unlock (&sca_data->lock); +if (ret != -EINVAL ) +return ret; + +return sca3300_error_handler (sca_data); +}
Okay, BIT(7) for write/read is pretty much standard stuff for such sensors. If you transform your driver to use REGMAP_SPI, you will get it thru regmap configuration. Also, you will get a locking there, in case you don't need to have several I/O in a row atomically.
..
drivers/iio/accel/sca3300.c line 301
Quoted 2 lines
drivers/iio/accel/sca3300.c new file +2
-0+for_each_set_bit (bit, indio_dev->active_scan_mask, + indio_dev->masklength) {
One line?
Quoted 10 lines
drivers/iio/accel/sca3300.c new file +10
-0+ ret =sca3300_read_reg (data, sca3300_channels[bit].address, + &val); +if (ret) { +dev_err_ratelimited (&data->spi->dev, +"failed to read register, error: %d\n" , ret); +/* handled, but bailing out due to errors */ + goto out; + } + data->scan.channels[i++] = val; + }
...
Review
Quoted 2 lines
(quoted diff) +2
-0+ int ret; + int value = 0;
Reversed xmas tree ordering?
...
drivers/iio/accel/sca3300.c line 340
Quoted 5 lines
drivers/iio/accel/sca3300.c new file +5
-0+/* +* Wait 1ms after SW-reset command. +* Wait 15ms for settling of signal paths. +*/ +usleep_range (16e3 ,50e3 );
Hmm... Perhaps re-use msleep_range()
https://elixir.bootlin.com/linux/latest/source/drivers/media/i2c/imx274.c#L601?
...
Quoted 1 line
+ .debugfs_reg_access =
&sca3300_debugfs_reg_access,
Reading of the registers you will get as a bonus when switching over to regmap SPI API.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Jonathan Cameron
maintainerRe: [PATCH v4 2/2] iio: accel: Add driver for Murata SCA3300 accelerometer
Quoted 10 lines · On Fri, 23 Apr 2021 19:06:30 +0300 Andy Shevchenko <[email protected]>…
Quoted 4 lines · Tomas Melin
Add initial support for Murata SCA3300 3-axis industrial accelerometer with digital SPI interface. This device also provides a temperature measurement.
Thanks for an update, my comments below.
They can be addressed as followups, but I think regmap API can be considered right now.
It's not a totally clear cut case of regmap making sense for this particular device. I think you'd have do a custom regmap to support
the cs_change = 1, needed for transfers and once you are going down that route the advantages of regmap have to be balanced against needing custom callbacks anyway.
Without actually implementing it I'm not certain whether it would be a good thing here or not. It should be fairly easy to try though if Tomas wants to.
Jonathan
Quoted 82 lines
...
Quoted 20 lines
drivers/iio/accel/sca3300.c new file +20
-0+static int sca3300_read_reg (struct sca3300_data *sca_data,u8 reg,int *val) +{ +int ret; + +mutex_lock (&sca_data->lock); + sca_data->txbuf[0 ] = reg <<2 ; + ret =sca3300_transfer (sca_data, val); +mutex_unlock (&sca_data->lock); +if (ret != -EINVAL ) +return ret; + +return sca3300_error_handler (sca_data); +} + +static int sca3300_write_reg (struct sca3300_data *sca_data,u8 reg,int val) +{ +int reg_val =0 ; +int ret; + +mutex_lock (&sca_data->lock);drivers/iio/accel/sca3300.c line 224
Quoted 10 lines
drivers/iio/accel/sca3300.c new file +10
-0+/* BIT(7) for write operation */ + sca_data->txbuf[0 ] =BIT (7 ) | (reg <<2 ); +put_unaligned_be16 (val, &sca_data->txbuf[1 ]); + ret =sca3300_transfer (sca_data, ®_val); +mutex_unlock (&sca_data->lock); +if (ret != -EINVAL ) +return ret; + +return sca3300_error_handler (sca_data); +}Okay, BIT(7) for write/read is pretty much standard stuff for such sensors. If you transform your driver to use
REGMAP_SPI, you will get it thru regmap configuration. Also, you will get a locking there, in case you don't need to have several I/O in a row atomically...
drivers/iio/accel/sca3300.c line 301
Quoted 2 lines
drivers/iio/accel/sca3300.c new file +2
-0+for_each_set_bit (bit, indio_dev->active_scan_mask, + indio_dev->masklength) {One line?
Quoted 10 lines
drivers/iio/accel/sca3300.c new file +10
-0+ ret =sca3300_read_reg (data, sca3300_channels[bit].address, + &val); +if (ret) { +dev_err_ratelimited (&data->spi->dev, +"failed to read register, error: %d\n" , ret); +/* handled, but bailing out due to errors */ + goto out; + } + data->scan.channels[i++] = val; + }...
Review
Quoted 2 lines
(quoted diff) +2
-0+ int ret; + int value = 0;Reversed xmas tree ordering?
...
drivers/iio/accel/sca3300.c line 340
Quoted 5 lines
drivers/iio/accel/sca3300.c new file +5
-0+/* +* Wait 1ms after SW-reset command. +* Wait 15ms for settling of signal paths. +*/ +usleep_range (16e3 ,50e3 );Hmm... Perhaps re-use
msleep_range()
https://elixir.bootlin.com/linux/latest/source/drivers/media/i2c/imx274.c#L601?...
Quoted 1 line
+ .debugfs_reg_access =
&sca3300_debugfs_reg_access,Reading of the registers you will get as a bonus when switching over to regmap SPI API.
Re: [PATCH v4 2/2] iio: accel: Add driver for Murata SCA3300 accelerometer
Quoted 9 lines · Jonathan Cameron
Quoted 6 lines · On Fri, 23 Apr 2021 19:06:30 +0300 Andy Shevchenko <[email protected]>…
Quoted 3 lines · Tomas Melin
Add initial support for Murata SCA3300 3-axis industrial accelerometer with digital SPI interface. This device also provides a temperature measurement.
Thanks for an update, my comments below.
Quoted 7 lines
Quoted 2 lines
They can be addressed as followups, but I think regmap API can be considered right now.
It's not a totally clear cut case of regmap making sense for this particular device. I think you'd have do a custom regmap to support
thecs_change= 1, needed for transfers and once you are going down that route the advantages of regmap have to be balanced against needing custom callbacks anyway.
Considered regmap, but given that it seems to require custom read/write
functions and that there is only SPI version of the device, I concluded that it did
not seem like a great fit for this driver.
I will implement the other changes suggested, and post a new version.
Thanks,
Tomas
Quoted 82 lines
Without actually implementing it I'm not certain whether it would be a good thing here or not. It should be fairly easy to try though if Tomas wants to.
Jonathan
Quoted 75 lines
...
Quoted 20 lines
drivers/iio/accel/sca3300.c new file +20
-0+static int sca3300_read_reg (struct sca3300_data *sca_data,u8 reg,int *val) +{ +int ret; + +mutex_lock (&sca_data->lock); + sca_data->txbuf[0 ] = reg <<2 ; + ret =sca3300_transfer (sca_data, val); +mutex_unlock (&sca_data->lock); +if (ret != -EINVAL ) +return ret; + +return sca3300_error_handler (sca_data); +} + +static int sca3300_write_reg (struct sca3300_data *sca_data,u8 reg,int val) +{ +int reg_val =0 ; +int ret; + +mutex_lock (&sca_data->lock);drivers/iio/accel/sca3300.c line 224
Quoted 10 lines
drivers/iio/accel/sca3300.c new file +10
-0+/* BIT(7) for write operation */ + sca_data->txbuf[0 ] =BIT (7 ) | (reg <<2 ); +put_unaligned_be16 (val, &sca_data->txbuf[1 ]); + ret =sca3300_transfer (sca_data, ®_val); +mutex_unlock (&sca_data->lock); +if (ret != -EINVAL ) +return ret; + +return sca3300_error_handler (sca_data); +}Okay, BIT(7) for write/read is pretty much standard stuff for such sensors. If you transform your driver to use
REGMAP_SPI, you will get it thru regmap configuration. Also, you will get a locking there, in case you don't need to have several I/O in a row atomically...
drivers/iio/accel/sca3300.c line 301
Quoted 2 lines
drivers/iio/accel/sca3300.c new file +2
-0+for_each_set_bit (bit, indio_dev->active_scan_mask, + indio_dev->masklength) {One line?
Quoted 10 lines
drivers/iio/accel/sca3300.c new file +10
-0+ ret =sca3300_read_reg (data, sca3300_channels[bit].address, + &val); +if (ret) { +dev_err_ratelimited (&data->spi->dev, +"failed to read register, error: %d\n" , ret); +/* handled, but bailing out due to errors */ + goto out; + } + data->scan.channels[i++] = val; + }...
Review
Quoted 2 lines
(quoted diff) +2
-0+ int ret; + int value = 0;Reversed xmas tree ordering?
...
drivers/iio/accel/sca3300.c line 340
Quoted 5 lines
drivers/iio/accel/sca3300.c new file +5
-0+/* +* Wait 1ms after SW-reset command. +* Wait 15ms for settling of signal paths. +*/ +usleep_range (16e3 ,50e3 );...
Quoted 1 line
+ .debugfs_reg_access =
&sca3300_debugfs_reg_access,Reading of the registers you will get as a bonus when switching over to regmap SPI API.
Re: [PATCH v4 2/2] iio: accel: Add driver for Murata SCA3300 accelerometer
In reply to Andy ShevchenkoHi,
Quoted 25 lines · Andy Shevchenko
Quoted 3 lines · Tomas Melin
Add initial support for Murata SCA3300 3-axis industrial accelerometer with digital SPI interface. This device also provides a temperature measurement.
..
drivers/iio/accel/sca3300.c line 301
Quoted 2 lines
drivers/iio/accel/sca3300.c new file +2
-0+for_each_set_bit (bit, indio_dev->active_scan_mask, + indio_dev->masklength) {One line?
80 if one line.
drivers/iio/accel/sca3300.c line 311
Quoted 10 lines
drivers/iio/accel/sca3300.c new file +10
-0+ ret =sca3300_read_reg (data, sca3300_channels[bit].address, + &val); +if (ret) { +dev_err_ratelimited (&data->spi->dev, +"failed to read register, error: %d\n" , ret); +/* handled, but bailing out due to errors */ + goto out; + } + data->scan.channels[i++] = val; + }
Quoted 5 lines
...
Review
Quoted 2 lines
(quoted diff) +2
-0+ int ret; + int value = 0;Reversed xmas tree ordering?
ok.
Quoted 10 lines
...
drivers/iio/accel/sca3300.c line 340
Quoted 5 lines
drivers/iio/accel/sca3300.c new file +5
-0+/* +* Wait 1ms after SW-reset command. +* Wait 15ms for settling of signal paths. +*/ +usleep_range (16e3 ,50e3 );
Checked that, but not sure if that would make this call any clearer? Delay is now only in this place and well documented. If you have some specific formatting in mind for this, please let me know. Otherwise keeping as is.
Thanks,
Tomas