iio: accel: adxl345: Split driver into core and I2C then add SPI support
Subsystems (3)
v4 cover iio: accel: adxl345: Split driver into core and I2C then add SPI support
This patchset modifies the adxl345 to use regmap. In doing so, we can easily introduce SPI support and let regmap handle the rest.
Recap of basic features: read_raw for x, y and z axes, scale. After applying this series, driver now supports the SPI protocol and enumeration of device via device tree.
Changes from v3:
[PATCH 1/4] Documentation: dt-bindings: Document ADXL345 accelerometer binding
* None
[PATCH 2/4] iio: accel: adxl345: Use I2C regmap instead of direct I2C access
* Keep intact I2C client structure which was deleted from v3
* Make use of regmap_get_device to retrieve struct device, use these for debugging prints instead of &client->dev.
[PATCH 3/4] iio: accel: adxl345: Split driver into core and I2C
and
[PATCH 4/4] iio: accel: adxl345: Add SPI support
* Revert to explicit and separate I2C and SPI configuration
* Add OF match table, make it enumerable in ACPI environment (Andy's suggestion)
Changes from v2:
* Drop PATCH 4 iio: accel: adxl345: Add ACPI support
* Add OF match table on both I2C and SPI files and document them
Changes from v1:
[PATCH 1/4]
* Move other deletions from patch 2 in here -- make it clear what got deleted and/or modified that is hard to see previously
* Introduce the driver header file "adxl345.h" here instead of doing it in the next patch
* Completely omit traces of i2c_client and let this file (adxl345.c) mirror the core file on the next patch.
* Improve debugging print about invalid device ID in probe.
[PATCH 2/4]
* Update Kconfig to Jonathan's preferred style
* Improve similarity index from 78% to 100% (rename detection) [PATCH 4/4]
* Correct acpi_device_id: ADX0345 -> ADS0345
Eva Rachel Retuya (4):
Documentation: dt-bindings: Document ADXL345 accelerometer binding
iio: accel: adxl345: Use I2C regmap instead of direct I2C access
iio: accel: adxl345: Split driver into core and I2C
iio: accel: adxl345: Add SPI support
.../devicetree/bindings/iio/accel/adxl345.txt | 38 +++++++++
drivers/iio/accel/Kconfig | 26 ++++++-
drivers/iio/accel/Makefile | 4 +-
drivers/iio/accel/adxl345.h | 18 +++++
drivers/iio/accel/{adxl345.c => adxl345_core.c} | 89 +++++++++-------------
drivers/iio/accel/adxl345_i2c.c | 78 +++++++++++++++++++
drivers/iio/accel/adxl345_spi.c | 83 ++++++++++++++++++++
7 files changed, 281 insertions(+), 55 deletions(-)
create mode 100644 Documentation/devicetree/bindings/iio/accel/adxl345.txt
create mode 100644 drivers/iio/accel/adxl345.h
rename drivers/iio/accel/{adxl345.c => adxl345_core.c} (62%)
create mode 100644 drivers/iio/accel/adxl345_i2c.c
create mode 100644 drivers/iio/accel/adxl345_spi.cSignature · 6 lines
2.7.4 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v4 1/4 Documentation: dt-bindings: Document ADXL345 accelerometer binding
Add the device tree binding documentation for the ADXL345 3-axis digital accelerometer.
--- .../devicetree/bindings/iio/accel/adxl345.txt | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/accel/adxl345.txt
Documentation/devicetree/bindings/iio/accel/adxl345.txt new file +38 -0
@@ -0,0 +1,38 @@ +Analog Devices ADXL345 3-Axis, +/-(2g/4g/8g/16g) Digital Accelerometer + +http://www.analog.com/en/products/mems/accelerometers/adxl345.html + +Required properties: + - compatible : should be "adi,adxl345" + - reg : the I2C address or SPI chip select number of the sensor + +Required properties for SPI bus usage: + - spi-max-frequency : set maximum clock frequency, must be 5000000 + - spi-cpol and spi-cpha : must be defined for adxl345 to enable SPI mode 3 + +Optional properties: + - interrupt-parent : phandle to the parent interrupt controller as documented + in Documentation/devicetree/bindings/interrupt-controller/interrupts.txt + - interrupts: interrupt mapping for IRQ as documented in + Documentation/devicetree/bindings/interrupt-controller/interrupts.txt + +Example for a I2C device node: + + adxl345@2a { + compatible = "adi,adxl345"; + reg = <0x53>; + interrupt-parent = <&gpio1>; + interrupts = <0 IRQ_TYPE_LEVEL_HIGH>; + }; + +Example for a SPI device node: + + adxl345@0 { + compatible = "adi,adxl345"; + reg = <0>; + spi-max-frequency = <5000000>; + spi-cpol; + spi-cpha; + interrupt-parent = <&gpio1>; + interrupts = <0 IRQ_TYPE_LEVEL_HIGH>; + };
Signature · 1 line
2.7.4
PATCH v4 2/4 iio: accel: adxl345: Use I2C regmap instead of direct I2C access
In reply to Eva Rachel RetuyaConvert the driver to use regmap instead of I2C-specific functions. This is done in preparation for splitting this driver into core and I2C-specific code as well as introduction of SPI driver.
---
Changes from v3:
* Keep intact I2C client structure which was deleted from v3
* Make use of regmap_get_device to retrieve struct device, use these for debugging prints instead of &client->dev.
drivers/iio/accel/Kconfig | 1 + drivers/iio/accel/adxl345.c | 66 +++++++++++++++++++++++++++++---------------- 2 files changed, 44 insertions(+), 23 deletions(-)
drivers/iio/accel/Kconfig +1 -0
@@ -9,6 +9,7 @@ config ADXL345 tristate "Analog Devices ADXL345 3-Axis Digital Accelerometer Driver" depends on !(INPUT_ADXL34X=y || INPUT_ADXL34X=m) depends on I2C + select REGMAP_I2C help Say Y here if you want to build support for the Analog Devices ADXL345 3-axis digital accelerometer.
drivers/iio/accel/adxl345.c +43 -23
140 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v4 3/4 iio: accel: adxl345: Split driver into core and I2C
In reply to Eva Rachel RetuyaMove I2C-specific code into its own file and rely on regmap to access registers. The core code provides access to x, y, z and scale readings.
---
Changes from v3:
* Revert to explicit and separate I2C and SPI configuration
* Add OF match table, make it enumerable in ACPI environment (Andy's suggestion)
drivers/iio/accel/Kconfig | 11 +++-
drivers/iio/accel/Makefile | 3 +-
drivers/iio/accel/adxl345.h | 18 ++++++
drivers/iio/accel/{adxl345.c => adxl345_core.c} | 55 ++++-------------
drivers/iio/accel/adxl345_i2c.c | 78 +++++++++++++++++++++++++
5 files changed, 117 insertions(+), 48 deletions(-)
create mode 100644 drivers/iio/accel/adxl345.h
rename drivers/iio/accel/{adxl345.c => adxl345_core.c} (78%)
create mode 100644 drivers/iio/accel/adxl345_i2c.cdrivers/iio/accel/Kconfig +8 -3
@@ -6,16 +6,21 @@ menu "Accelerometers" config ADXL345 - tristate "Analog Devices ADXL345 3-Axis Digital Accelerometer Driver" + tristate + +config ADXL345_I2C + tristate "Analog Devices ADXL345 3-Axis Digital Accelerometer I2C Driver" depends on !(INPUT_ADXL34X=y || INPUT_ADXL34X=m) depends on I2C + select ADXL345 select REGMAP_I2C help Say Y here if you want to build support for the Analog Devices ADXL345 3-axis digital accelerometer. - To compile this driver as a module, choose M here: the - module will be called adxl345. + To compile this driver as a module, choose M here: the module + will be called adxl345_i2c and you will also get adxl345_core + for the core module. config BMA180 tristate "Bosch BMA180/BMA250 3-Axis Accelerometer Driver"
drivers/iio/accel/Makefile +2 -1
@@ -3,7 +3,8 @@ # # When adding new entries keep the list in alphabetical order -obj-$(CONFIG_ADXL345) += adxl345.o +obj-$(CONFIG_ADXL345) += adxl345_core.o +obj-$(CONFIG_ADXL345_I2C) += adxl345_i2c.o obj-$(CONFIG_BMA180) += bma180.o obj-$(CONFIG_BMA220) += bma220_spi.o obj-$(CONFIG_BMC150_ACCEL) += bmc150-accel-core.o
drivers/iio/accel/adxl345.h new file +18 -0
@@ -0,0 +1,18 @@ +/* +* ADXL345 3-Axis Digital Accelerometer +* +* Copyright (c) 2017 Eva Rachel Retuya <[email protected]> +* +* This file is subject to the terms and conditions of version 2 of +* the GNU General Public License. See the file COPYING in the main +* directory of this archive for more details. +*/ + +#ifndef _ADXL345_H_ +#define _ADXL345_H_ + +int adxl345_common_probe (struct device *dev,struct regmap *regmap, +const char *name); +int adxl345_common_remove (struct device *dev); + +#endif /* _ADXL345_H_ */
drivers/iio/accel/adxl345_core.c renamed from drivers/iio/accel/adxl345.c +11 -44
106 lines not on this page · raw message
drivers/iio/accel/adxl345_i2c.c new file +78 -0
78 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v4 4/4 iio: accel: adxl345: Add SPI support
In reply to Eva Rachel RetuyaAdd SPI driver that initializes SPI regmap for the adxl345 core driver. The driver supports the same functionality as I2C namely the x, y, z and scale readings.
---
Changes from v3:
* Revert to explicit and separate I2C and SPI configuration
* Add OF match table, make it enumerable in ACPI environment (Andy's suggestion)
drivers/iio/accel/Kconfig | 14 +++++++ drivers/iio/accel/Makefile | 1 + drivers/iio/accel/adxl345_spi.c | 83 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+) create mode 100644 drivers/iio/accel/adxl345_spi.c
drivers/iio/accel/Kconfig +14 -0
@@ -22,6 +22,20 @@ config ADXL345_I2C will be called adxl345_i2c and you will also get adxl345_core for the core module. +config ADXL345_SPI + tristate "Analog Devices ADXL345 3-Axis Digital Accelerometer SPI Driver" + depends on !(INPUT_ADXL34X=y || INPUT_ADXL34X=m) + depends on SPI + select ADXL345 + select REGMAP_SPI + help + Say Y here if you want to build support for the Analog Devices + ADXL345 3-axis digital accelerometer. + + To compile this driver as a module, choose M here: the module + will be called adxl345_spi and you will also get adxl345_core + for the core module. + config BMA180 tristate "Bosch BMA180/BMA250 3-Axis Accelerometer Driver" depends on I2C
drivers/iio/accel/Makefile +1 -0
@@ -5,6 +5,7 @@ # When adding new entries keep the list in alphabetical order obj-$(CONFIG_ADXL345) += adxl345_core.o obj-$(CONFIG_ADXL345_I2C) += adxl345_i2c.o +obj-$(CONFIG_ADXL345_SPI) += adxl345_spi.o obj-$(CONFIG_BMA180) += bma180.o obj-$(CONFIG_BMA220) += bma220_spi.o obj-$(CONFIG_BMC150_ACCEL) += bmc150-accel-core.o
drivers/iio/accel/adxl345_spi.c new file +83 -0
83 lines not on this page · raw message
Signature · 1 line
2.7.4
Quoted 6 lines · Eva Rachel Retuya
This patchset modifies the adxl345 to use regmap. In doing so, we can easily introduce SPI support and let regmap handle the rest.
Recap of basic features:
read_rawfor x, y and z axes, scale. After applying this series, driver now supports the SPI protocol and enumeration of device via device tree.
I did couple of rounds of review and found no major issues with the series (though, I would amend some style there and minor things). So, for moving forward FWIW:
Quoted 56 lines
Changes from v3:
[PATCH 1/4] Documentation: dt-bindings: Document ADXL345 accelerometer binding
* None
[PATCH 2/4] iio: accel: adxl345: Use I2C regmap instead of direct I2C access
* Keep intact I2C client structure which was deleted from v3
* Make use ofregmap_get_deviceto retrieve struct device, use these for debugging prints instead of&client->dev.
[PATCH 3/4] iio: accel: adxl345: Split driver into core and I2C
and
[PATCH 4/4] iio: accel: adxl345: Add SPI support
* Revert to explicit and separate I2C and SPI configuration
* Add OF match table, make it enumerable in ACPI environment (Andy's suggestion)Changes from v2:
* Drop PATCH 4 iio: accel: adxl345: Add ACPI support
* Add OF match table on both I2C and SPI files and document themChanges from v1:
[PATCH 1/4]
* Move other deletions from patch 2 in here -- make it clear what got deleted and/or modified that is hard to see previously
* Introduce the driver header file "adxl345.h" here instead of doing it in the next patch
* Completely omit traces ofi2c_clientand let this file (adxl345.c) mirror the core file on the next patch.
* Improve debugging print about invalid device ID in probe.
[PATCH 2/4]
* UpdateKconfigto Jonathan's preferred style
* Improve similarity index from 78% to 100% (rename detection) [PATCH 4/4]
* Correctacpi_device_id: ADX0345 -> ADS0345Eva Rachel Retuya (4):
Documentation: dt-bindings: Document ADXL345 accelerometer binding
iio: accel: adxl345: Use I2C regmap instead of direct I2C access
iio: accel: adxl345: Split driver into core and I2C
iio: accel: adxl345: Add SPI support.../devicetree/bindings/iio/accel/adxl345.txt | 38 +++++++++ drivers/iio/accel/Kconfig | 26 ++++++- drivers/iio/accel/Makefile | 4 +- drivers/iio/accel/adxl345.h | 18 +++++ drivers/iio/accel/{adxl345.c => adxl345_core.c} | 89 +++++++++------------- drivers/iio/accel/adxl345_i2c.c | 78 +++++++++++++++++++ drivers/iio/accel/adxl345_spi.c | 83 ++++++++++++++++++++ 7 files changed, 281 insertions(+), 55 deletions(-) create mode 100644 Documentation/devicetree/bindings/iio/accel/adxl345.txt create mode 100644 drivers/iio/accel/adxl345.h rename drivers/iio/accel/{adxl345.c => adxl345_core.c} (62%) create mode 100644 drivers/iio/accel/adxl345_i2c.c create mode 100644 drivers/iio/accel/adxl345_spi.c--
2.7.4
Signature · 2 lines
With Best Regards, Andy Shevchenko
Rob Herring
maintainerRe: [PATCH v4 1/4] Documentation: dt-bindings: Document ADXL345 accelerometer binding
In reply to Eva Rachel RetuyaQuoted 2 lines · Eva Rachel Retuya
Add the device tree binding documentation for the ADXL345 3-axis digital accelerometer.
Use "dt-bindings: iio: accel: ..." for the subject prefix.
Quoted 24 lines
Signed-off-by Eva Rachel Retuya <[email protected]>--- .../devicetree/bindings/iio/accel/adxl345.txt | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/accel/adxl345.txtDocumentation/devicetree/bindings/iio/accel/adxl345.txt new file +11
-0@@ -0,0 +1,38 @@ +Analog Devices ADXL345 3-Axis, +/-(2g/4g/8g/16g) Digital Accelerometer + +http://www.analog.com/en/products/mems/accelerometers/adxl345.html + +Required properties: + - compatible : should be "adi,adxl345" + - reg : the I2C address or SPI chip select number of the sensor + +Required properties for SPI bus usage: + - spi-max-frequency : set maximum clock frequency, must be 5000000 + - spi-cpol and spi-cpha : must be defined for adxl345 to enable SPI mode 3
Documentation/devicetree/bindings/iio/accel/adxl345.txt line 21
Quoted 10 lines
Documentation/devicetree/bindings/iio/accel/adxl345.txt new file +10
-0+ +Optional properties: + - interrupt-parent : phandle to the parent interrupt controller as documented + in Documentation/devicetree/bindings/interrupt-controller/interrupts.txt + - interrupts: interrupt mapping for IRQ as documented in + Documentation/devicetree/bindings/interrupt-controller/interrupts.txt + +Example for a I2C device node: + + adxl345@2a {
accelerometer@2a
Documentation/devicetree/bindings/iio/accel/adxl345.txt line 30
Quoted 9 lines
Documentation/devicetree/bindings/iio/accel/adxl345.txt new file +9
-0+ compatible = "adi,adxl345"; + reg = <0x53>; + interrupt-parent = <&gpio1>; + interrupts = <0 IRQ_TYPE_LEVEL_HIGH>; + }; + +Example for a SPI device node: + + adxl345@0 {
Same here.
Quoted 11 lines
Documentation/devicetree/bindings/iio/accel/adxl345.txt new file +8
-0+ compatible = "adi,adxl345"; + reg = <0>; + spi-max-frequency = <5000000>; + spi-cpol; + spi-cpha; + interrupt-parent = <&gpio1>; + interrupts = <0 IRQ_TYPE_LEVEL_HIGH>; + };Signature · 1 line
2.7.4
On Tue, Feb 28, 2017 at 12:41:50AM +0200, Andy Shevchenko wrote:
[...]
Quoted 5 lines
I did couple of rounds of review and found no major issues with the series (though, I would amend some style there and minor things). So, for moving forward FWIW:
Reviewed-by Andy Shevchenko <[email protected]>
Hello Andy, thank you for the previous feedback and for reviewing this series.
Eva
[...]