iio: accel: add support for ADXL355
Subsystems (4)
v10 cover iio: accel: add support for ADXL355
Add the dt-bindings and the driver for ADXL355 3-axis MEMS Accelerometer.
Changes since v9:
1. Fix white space issues, remove extra lines.
2. Include bits.h and device.h
3. Add commas to non-terminal lines in structs etc.
Changes since v8:
1. Make scale and offset defines inline and remove them.
2. Change dt-binding doc to state interrupt polarity only for DRDY pin.
3. Remove triggered buffer support from this patch series.
Changes since v7:
1. Update MAINTAINERS to show all driver files.
2. Set CONFIGS for buffered support in Kconfig.
Changes since v6:
1. Use interrupt-names property in device tree document.
2. Add triggered buffer support.
3. Use a static table for offset and data registers.
4. Fix coding style issues.
5. move defines from header to c file.
Changes since v5:
1. Used get_unaligned_be24() and get_unaligned_be16() to parse acceleration and temperature data. This solves sparse errors and also make the code more understandable.
Changes since v4:
1. Fix errors reported by sparse.
Changes since v3:
1. Fix errors in yaml DT doc.
2. Change SPDX-License-Identifier to GPL-2.0-only OR BSD-2-Clause
Changes since v2:
1. Add separate DT binding doc in yaml.
2. Use ____cacheline_aligned buffer for regmap_bulk_read/write calls.
3. Make code consistent by using same style in switch case.
4. Use FIELD_PREP in place of custom macros.
5. Make Kconfig description more informative.
Changes since v1:
1. Remove the declarations for static regmap structures from adxl355.h. This was missed in the v1 and caused errors.
2. Make switch case statements consistent by directly returning from each case rather than saving the return in a variable.
3. Some coding style changes.
Changes since v0:
1. Move adxl355_hpf_3db_table to adxl355_data structure. This is done to make sure that each device gets its own table.
2. Make local regmap definitions private to adxl355_core.c.
3. Other minor coding style changes.
Puranjay Mohan (2):
dt-bindings: iio: accel: Add DT binding doc for ADXL355
iio: accel: Add driver support for ADXL355
.../bindings/iio/accel/adi,adxl355.yaml | 88 +++ MAINTAINERS | 10 + drivers/iio/accel/Kconfig | 29 + drivers/iio/accel/Makefile | 3 + drivers/iio/accel/adxl355.h | 20 + drivers/iio/accel/adxl355_core.c | 582 ++++++++++++++++++ drivers/iio/accel/adxl355_i2c.c | 62 ++ drivers/iio/accel/adxl355_spi.c | 65 ++ 8 files changed, 859 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/accel/adi,adxl355.yaml create mode 100644 drivers/iio/accel/adxl355.h create mode 100644 drivers/iio/accel/adxl355_core.c create mode 100644 drivers/iio/accel/adxl355_i2c.c create mode 100644 drivers/iio/accel/adxl355_spi.c
Signature · 1 line
2.30.1
PATCH v10 1/2 dt-bindings: iio: accel: Add DT binding doc for ADXL355
Add devicetree binding document for ADXL355, a 3-Axis MEMS Accelerometer.
--- .../bindings/iio/accel/adi,adxl355.yaml | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/accel/adi,adxl355.yaml
Documentation/devicetree/bindings/iio/accel/adi,adxl355.yaml new file +88 -0
@@ -0,0 +1,88 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/accel/adi,adxl355.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Analog Devices ADXL355 3-Axis, Low noise MEMS Accelerometer + +maintainers: + - Puranjay Mohan <[email protected]> + +description: | + Analog Devices ADXL355 3-Axis, Low noise MEMS Accelerometer that supports + both I2C & SPI interfaces + https://www.analog.com/en/products/adxl355.html + +properties: + compatible: + enum: + - adi,adxl355 + + reg: + maxItems: 1 + + interrupts: + minItems: 1 + maxItems: 3 + description: | + Type for DRDY should be IRQ_TYPE_EDGE_RISING. + Three configurable interrupt lines exist. + + interrupt-names: + description: Specify which interrupt line is in use. + items: + enum: + - INT1 + - INT2 + - DRDY + minItems: 1 + maxItems: 3 + + vdd-supply: + description: Regulator that provides power to the sensor + + vddio-supply: + description: Regulator that provides power to the bus + + spi-max-frequency: true + +required: + - compatible + - reg + +additionalProperties: false + +examples: + - | + #include <dt-bindings/gpio/gpio.h> + #include <dt-bindings/interrupt-controller/irq.h> + i2c { + #address-cells = <1>; + #size-cells = <0>; + + /* Example for a I2C device node */ + accelerometer@1d { + compatible = "adi,adxl355"; + reg = <0x1d>; + interrupt-parent = <&gpio>; + interrupts = <25 IRQ_TYPE_EDGE_RISING>; + interrupt-names = "DRDY"; + }; + }; + - | + #include <dt-bindings/gpio/gpio.h> + #include <dt-bindings/interrupt-controller/irq.h> + spi { + #address-cells = <1>; + #size-cells = <0>; + + accelerometer@0 { + compatible = "adi,adxl355"; + reg = <0>; + spi-max-frequency = <1000000>; + interrupt-parent = <&gpio>; + interrupts = <25 IRQ_TYPE_EDGE_RISING>; + interrupt-names = "DRDY"; + }; + };
Signature · 1 line
2.30.1
PATCH v10 2/2 iio: accel: Add driver support for ADXL355
In reply to Puranjay MohanADXL355 is a 3-axis MEMS Accelerometer. It offers low noise density, low 0g offset drift, low power with selectable measurement ranges. It also features programmable high-pass and low-pass filters.
Datasheet: https://www.analog.com/media/en/technical-documentation/data-sheets/adxl354_adxl355.pdf
--- MAINTAINERS | 10 + drivers/iio/accel/Kconfig | 29 ++ drivers/iio/accel/Makefile | 3 + drivers/iio/accel/adxl355.h | 20 ++ drivers/iio/accel/adxl355_core.c | 582 +++++++++++++++++++++++++++++++ drivers/iio/accel/adxl355_i2c.c | 62 ++++ drivers/iio/accel/adxl355_spi.c | 65 ++++ 7 files changed, 771 insertions(+) create mode 100644 drivers/iio/accel/adxl355.h create mode 100644 drivers/iio/accel/adxl355_core.c create mode 100644 drivers/iio/accel/adxl355_i2c.c create mode 100644 drivers/iio/accel/adxl355_spi.c
MAINTAINERS +10 -0
@@ -586,6 +586,16 @@ W: http://ez.analog.com/community/linux-device-drivers F: Documentation/devicetree/bindings/iio/accel/adi,adxl345.yaml F: drivers/input/misc/adxl34x.c +ADXL355 THREE-AXIS DIGITAL ACCELEROMETER DRIVER +M: Puranjay Mohan <[email protected]> +L: [email protected] +S: Supported +F: Documentation/devicetree/bindings/iio/accel/adi,adxl355.yaml +F: drivers/iio/accel/adxl355.h +F: drivers/iio/accel/adxl355_core.c +F: drivers/iio/accel/adxl355_i2c.c +F: drivers/iio/accel/adxl355_spi.c + ADXL372 THREE-AXIS DIGITAL ACCELEROMETER DRIVER M: Michael Hennerich <[email protected]> S: Supported
drivers/iio/accel/Kconfig +29 -0
@@ -61,6 +61,35 @@ config ADXL345_SPI will be called adxl345_spi and you will also get adxl345_core for the core module. +config ADXL355 + tristate + +config ADXL355_I2C + tristate "Analog Devices ADXL355 3-Axis Digital Accelerometer I2C Driver" + depends on I2C + select ADXL355 + select REGMAP_I2C + help + Say Y here if you want to build i2c support for the Analog Devices + ADXL355 3-axis digital accelerometer. + + To compile this driver as a module, choose M here: the module + will be called adxl355_i2c and you will also get adxl355_core + for the core module. + +config ADXL355_SPI + tristate "Analog Devices ADXL355 3-Axis Digital Accelerometer SPI Driver" + depends on SPI + select ADXL355 + select REGMAP_SPI + help + Say Y here if you want to build spi support for the Analog Devices + ADXL355 3-axis digital accelerometer. + + To compile this driver as a module, choose M here: the module + will be called adxl355_spi and you will also get adxl355_core + for the core module. + config ADXL372 tristate select IIO_BUFFER
drivers/iio/accel/Makefile +3 -0
@@ -9,6 +9,9 @@ obj-$(CONFIG_ADIS16209) += adis16209.o obj-$(CONFIG_ADXL345) += adxl345_core.o obj-$(CONFIG_ADXL345_I2C) += adxl345_i2c.o obj-$(CONFIG_ADXL345_SPI) += adxl345_spi.o +obj-$(CONFIG_ADXL355) += adxl355_core.o +obj-$(CONFIG_ADXL355_I2C) += adxl355_i2c.o +obj-$(CONFIG_ADXL355_SPI) += adxl355_spi.o obj-$(CONFIG_ADXL372) += adxl372.o obj-$(CONFIG_ADXL372_I2C) += adxl372_i2c.o obj-$(CONFIG_ADXL372_SPI) += adxl372_spi.o
drivers/iio/accel/adxl355.h new file +20 -0
@@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* ADXL355 3-Axis Digital Accelerometer +* +* Copyright (c) 2021 Puranjay Mohan <[email protected]> +*/ + +#ifndef _ADXL355_H_ +#define _ADXL355_H_ + +#include <linux/device.h> +#include <linux/regmap.h> + +extern const struct regmap_access_table adxl355_readable_regs_tbl; +extern const struct regmap_access_table adxl355_writeable_regs_tbl; + +int adxl355_core_probe (struct device *dev,struct regmap *regmap, +const char *name); + +#endif /* _ADXL355_H_ */
drivers/iio/accel/adxl355_core.c new file +582 -0
582 lines not on this page · raw message
drivers/iio/accel/adxl355_i2c.c new file +62 -0
62 lines not on this page · raw message
drivers/iio/accel/adxl355_spi.c new file +65 -0
65 lines not on this page · raw message
Signature · 1 line
2.30.1
Re: [PATCH v10 2/2] iio: accel: Add driver support for ADXL355
Quoted 4 lines · Puranjay Mohan
ADXL355 is a 3-axis MEMS Accelerometer. It offers low noise density, low 0g offset drift, low power with selectable measurement ranges. It also features programmable high-pass and low-pass filters.
Thanks for an update. Seems some of the comments left unaddressed.
...
Quoted 1 line
+#include <
linux/device.h>
No need. There is no user for that.
A forward declaration is enough.
Quoted 1 line
+#include <
linux/regmap.h>
...
drivers/iio/accel/adxl355_core.c line 191
Quoted 4 lines
drivers/iio/accel/adxl355_core.c new file +4
-0+u32 multiplier; +u64 div; +u64 odr; +u64 rem;
div and rem seems of the same nature, you may put them on one line.
drivers/iio/accel/adxl355_core.c line 204
Quoted 13 lines
drivers/iio/accel/adxl355_core.c new file +13
-0+int i; + + odr =mul_u64_u32_shr (adxl355_odr_table[data->odr][0 ],1000000 ,0 ) + + adxl355_odr_table[data->odr][1 ]; + +for (i =0 ; i <ARRAY_SIZE (adxl355_hpf_3db_multipliers); i++) { + multiplier = adxl355_hpf_3db_multipliers[i]; + div =div64_u64_rem (mul_u64_u32_shr (odr, multiplier,0 ), +100000000000000UL , &rem); + + data->adxl355_hpf_3db_table[i][0 ] = div; + data->adxl355_hpf_3db_table[i][1 ] =div_u64 (rem,100000000 ); + }
Here, I didn't get if those powers-of-two are some kind of units? If no, we may have locally defined SI prefexes for them.
Quoted 1 line
+}
...
drivers/iio/accel/adxl355_core.c line 319
Quoted 10 lines
drivers/iio/accel/adxl355_core.c new file +9
-0+static int adxl355_set_hpf_3db (struct adxl355_data *data, +enum adxl355_hpf_3db hpf) +{ +int ret =0 ; + +mutex_lock (&data->lock); + +if (data->hpf_3db == hpf) + goto unlock;
This...
drivers/iio/accel/adxl355_core.c line 294
Quoted 3 lines
drivers/iio/accel/adxl355_core.c new file +3
-0+ ret =adxl355_set_op_mode (data,ADXL355_STANDBY ); +if (ret <0 ) + goto out_unlock;
...and this are kinda easy to confuse. Please, give them better names.
Quoted 8 lines
drivers/iio/accel/adxl355_core.c new file +8
-0+ ret =regmap_update_bits (data->regmap,ADXL355_FILTER_REG , +ADXL355_FILTER_HPF_MSK , +FIELD_PREP (ADXL355_FILTER_HPF_MSK , hpf)); +if (!ret) + data->hpf_3db = hpf; + +out_unlock: + ret =adxl355_set_op_mode (data,ADXL355_MEASUREMENT );
drivers/iio/accel/adxl355_core.c line 341
Quoted 10 lines
drivers/iio/accel/adxl355_core.c new file +9
-0+unlock: +mutex_unlock (&data->lock); +return ret; +} + +static int adxl355_set_calibbias (struct adxl355_data *data, +enum adxl355_chans chan,int calibbias) +{ +int ret =0 ;
Redundant assignment.
...
Quoted 1 line
+out_unlock:
And as per above function, this one does more than simple unlock.
Quoted 4 lines
drivers/iio/accel/adxl355_core.c new file +4
-0+ ret =adxl355_set_op_mode (data,ADXL355_MEASUREMENT ); +mutex_unlock (&data->lock); +return ret; +}
...
drivers/iio/accel/adxl355_core.c line 503
Quoted 4 lines
drivers/iio/accel/adxl355_core.c new file +4
-0+static const struct iio_info adxl355_info = { + .read_raw = adxl355_read_raw, + .write_raw = adxl355_write_raw, + .read_avail = &adxl355_read_avail
+ comma.
Quoted 1 line
+};
Signature · 2 lines
With Best Regards, Andy Shevchenko