iio: accel: add support for ADXL355
Subsystems (4)
v11 cover iio: accel: add support for ADXL355
Add the dt-bindings and the driver for ADXL355 3-axis MEMS Accelerometer.
Changes since v10:
1. Use macros for powers-of-10 in fill_3db_frequency_tbl().
2. Change names of gotos.
3. add commas to non-terminal lines.
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 | 19 + drivers/iio/accel/adxl355_core.c | 584 ++++++++++++++++++ drivers/iio/accel/adxl355_i2c.c | 62 ++ drivers/iio/accel/adxl355_spi.c | 65 ++ 8 files changed, 860 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 v11 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 v11 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 | 19 + drivers/iio/accel/adxl355_core.c | 584 +++++++++++++++++++++++++++++++ drivers/iio/accel/adxl355_i2c.c | 62 ++++ drivers/iio/accel/adxl355_spi.c | 65 ++++ 7 files changed, 772 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 +19 -0
@@ -0,0 +1,19 @@ +/* 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/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 +584 -0
584 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 v11 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! My comments below.
After addressing, feel free to add
...
drivers/iio/accel/adxl355.h line 11
Quoted 4 lines
drivers/iio/accel/adxl355.h new file +4
-0+#ifndef _ADXL355_H_ +#define _ADXL355_H_ + +#include <linux/regmap.h>
What I meant here is you need to add a forward declaration, i.e.
struct device;
line.
Quoted 7 lines
drivers/iio/accel/adxl355.h new file +7
-0+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 line 58
Quoted 2 lines
drivers/iio/accel/adxl355_core.c new file +2
-0+#define MEGA (x) ((x) * 1000000) +#define TERA (x) ((x) * 1000000000000UL)
What I meant is to define just constants. It will be easier to move this to a global space (I have a patch, btw, but it may be applied later). So, just
#define MEGA 1000000UL
#define TERA 1000000000000UUL
And note that the second one should have a ULL suffix.
...
drivers/iio/accel/adxl355_core.c line 355
Quoted 3 lines
drivers/iio/accel/adxl355_core.c new file +3
-0+ ret =regmap_bulk_write (data->regmap, + adxl355_chans[chan].offset_reg, + data->transf_buf,2 );
ARRAY_SIZE() ?
Quoted 2 lines
drivers/iio/accel/adxl355_core.c new file +2
-0+if (ret) + goto set_opmode_unlock;
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v11 2/2] iio: accel: Add driver support for ADXL355
Quoted 13 lines · Andy Shevchenko
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! My comments below.
After addressing, feel free to addReviewed-by Andy Shevchenko <[email protected]>...
Quoted 8 lines
drivers/iio/accel/adxl355.h line 11
Quoted 4 lines
drivers/iio/accel/adxl355.h new file +4
-0+#ifndef _ADXL355_H_ +#define _ADXL355_H_ + +#include <linux/regmap.h> What I meant here is you need to add a forward declaration, i.e.
struct device;
okay, I will add this.
Quoted 20 lines
line.
Quoted 7 lines
drivers/iio/accel/adxl355.h new file +7
-0+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 line 58
Quoted 2 lines
drivers/iio/accel/adxl355_core.c new file +2
-0+#define MEGA (x) ((x) * 1000000) +#define TERA (x) ((x) * 1000000000000UL)What I meant is to define just constants. It will be easier to move this to a global space (I have a patch, btw, but it may be applied later). So, just
Quoted 2 lines
#define MEGA 1000000UL
#define TERA 1000000000000UUL
will change in v12
Quoted 10 lines
And note that the second one should have a ULL suffix.
...
drivers/iio/accel/adxl355_core.c line 355
Quoted 3 lines
drivers/iio/accel/adxl355_core.c new file +3
-0+ ret =regmap_bulk_write (data->regmap, + adxl355_chans[chan].offset_reg, + data->transf_buf,2 );
ARRAY_SIZE()?
ARRAY SIZE is 3, but here we need to transfer 2 bytes only.
Quoted 7 lines
drivers/iio/accel/adxl355_core.c line 357
Quoted 3 lines
drivers/iio/accel/adxl355_core.c new file +2
-0+if (ret) + goto set_opmode_unlock;--
With Best Regards,
Andy Shevchenko
Signature · 5 lines
Thanks and Regards Yours Truly, Puranjay Mohan