Skip to contentSkip to conversation

iio: accel: adxl345: Split driver into core and I2C then add SPI support

PATCH Superseded Eva Rachel Retuya 1 participant 6 messages Feb 20, 2017 – Feb 21, 2017

Subsystems (2)

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v2 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 ACPI.

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):
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
iio: accel: adxl345: Add ACPI support

 drivers/iio/accel/Kconfig        |  18 +++-
 drivers/iio/accel/Makefile       |   4 +-
 drivers/iio/accel/adxl345.c      | 194 ---------------------------------------
 drivers/iio/accel/adxl345.h      |  18 ++++
 drivers/iio/accel/adxl345_core.c | 182 ++++++++++++++++++++++++++++++++++++
 drivers/iio/accel/adxl345_i2c.c  |  79 ++++++++++++++++
 drivers/iio/accel/adxl345_spi.c  |  84 +++++++++++++++++
 7 files changed, 381 insertions(+), 198 deletions(-)
 delete mode 100644 drivers/iio/accel/adxl345.c
 create mode 100644 drivers/iio/accel/adxl345.h
 create mode 100644 drivers/iio/accel/adxl345_core.c
 create mode 100644 drivers/iio/accel/adxl345_i2c.c
 create mode 100644 drivers/iio/accel/adxl345_spi.c
Signature · 1 line
2.7.4
#1 lore raw

PATCH v2 1/4 iio: accel: adxl345: Use I2C regmap instead of direct I2C access

Convert the driver to use regmap instead of I2C-specific functions. Also, introduce the header file "adxl345.h" and export the probe and remove 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 v1:
* 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.

 drivers/iio/accel/Kconfig   |  1 +
 drivers/iio/accel/adxl345.c | 88 ++++++++++++++++++++-------------------------
 drivers/iio/accel/adxl345.h | 18 ++++++++++
 3 files changed, 57 insertions(+), 50 deletions(-)
 create mode 100644 drivers/iio/accel/adxl345.h
drivers/iio/accel/Kconfig +1 -0
index 2308bac..26b8614 100644
@@ -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 +38 -50

174 lines not on this page · raw message

drivers/iio/accel/adxl345.h new file +18 -0
new file mode 100644
index 0000000..fca3e25
@@ -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_ */
Signature · 1 line
2.7.4
#2 lore raw

PATCH v2 2/4 iio: accel: adxl345: Split driver into core and I2C

In reply to Eva Rachel Retuya

Move 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 v1:
* Update Kconfig to Jonathan's preferred style
* Improve similarity index from 78% to 100% (rename detection)

 drivers/iio/accel/Kconfig                       | 13 +++--
 drivers/iio/accel/Makefile                      |  3 +-
 drivers/iio/accel/{adxl345.c => adxl345_core.c} |  0
 drivers/iio/accel/adxl345_i2c.c                 | 70 +++++++++++++++++++++++++
 4 files changed, 81 insertions(+), 5 deletions(-)
 rename drivers/iio/accel/{adxl345.c => adxl345_core.c} (100%)
 create mode 100644 drivers/iio/accel/adxl345_i2c.c
drivers/iio/accel/Kconfig +9 -4
index 26b8614..ffb0a63 100644
@@ -8,14 +8,19 @@ menu "Accelerometers"
 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
+	select REGMAP
+	select ADXL345_I2C if 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 core
+	  module will be called adxl345_core and you will also get
+	  adxl345_i2c for I2C.
+
+config ADXL345_I2C
+	tristate
+	select REGMAP_I2C
 
 config BMA180
 	tristate "Bosch BMA180/BMA250 3-Axis Accelerometer Driver"
drivers/iio/accel/Makefile +2 -1
index 618488d..3f4a6d6 100644
@@ -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_core.c renamed from drivers/iio/accel/adxl345.c +0 -0
similarity index 100%
rename from drivers/iio/accel/adxl345.c
rename to drivers/iio/accel/adxl345_core.c
drivers/iio/accel/adxl345_i2c.c new file +70 -0

70 lines not on this page · raw message

Signature · 1 line
2.7.4
#3 lore raw

PATCH v2 3/4 iio: accel: adxl345: Add SPI support

In reply to Eva Rachel Retuya

Add 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.

---
 drivers/iio/accel/Kconfig       |  8 ++++-
 drivers/iio/accel/Makefile      |  1 +
 drivers/iio/accel/adxl345_spi.c | 75 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 83 insertions(+), 1 deletion(-)
 create mode 100644 drivers/iio/accel/adxl345_spi.c
drivers/iio/accel/Kconfig +7 -1
index ffb0a63..454aeff 100644
@@ -8,20 +8,26 @@ menu "Accelerometers"
 config ADXL345
 	tristate "Analog Devices ADXL345 3-Axis Digital Accelerometer Driver"
 	depends on !(INPUT_ADXL34X=y || INPUT_ADXL34X=m)
+	depends on (I2C || SPI)
 	select REGMAP
 	select ADXL345_I2C if I2C
+	select ADXL345_SPI if 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 core
 	  module will be called adxl345_core and you will also get
-	  adxl345_i2c for I2C.
+	  adxl345_i2c for I2C and/or adxl345_spi for SPI.
 
 config ADXL345_I2C
 	tristate
 	select REGMAP_I2C
 
+config ADXL345_SPI
+	tristate
+	select REGMAP_SPI
+
 config BMA180
 	tristate "Bosch BMA180/BMA250 3-Axis Accelerometer Driver"
 	depends on I2C
drivers/iio/accel/Makefile +1 -0
index 3f4a6d6..31fba19 100644
@@ -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 +75 -0

75 lines not on this page · raw message

Signature · 1 line
2.7.4
#4 lore raw

PATCH v2 4/4 iio: accel: adxl345: Add ACPI support

In reply to Eva Rachel Retuya

Allow probing the adxl345 on both I2C and SPI protocols using ACPI.

---
Change from v1:
* Correct acpi_device_id: ADX0345 -> ADS0345

 drivers/iio/accel/adxl345_i2c.c | 9 +++++++++
 drivers/iio/accel/adxl345_spi.c | 9 +++++++++
 2 files changed, 18 insertions(+)
drivers/iio/accel/adxl345_i2c.c +9 -0
index b114eb0..03b6df9 100644
@@ -12,6 +12,7 @@
  * 0x53 (ALT ADDRESS pin grounded)
  */
 
+#include <linux/acpi.h>
 #include <linux/i2c.h>
 #include <linux/module.h>
 #include <linux/regmap.h>
@@ -54,9 +55,17 @@ static const struct i2c_device_id adxl345_i2c_id[] = {
 
 MODULE_DEVICE_TABLE(i2c, adxl345_i2c_id);
 
+static const struct acpi_device_id adxl345_acpi_id[] = {
+	{ "ADS0345", 0 },
+	{ }
+};
+
+MODULE_DEVICE_TABLE(acpi, adxl345_acpi_id);
+
 static struct i2c_driver adxl345_i2c_driver = {
 	.driver = {
 		.name	= "adxl345_i2c",
+		.acpi_match_table = ACPI_PTR(adxl345_acpi_id),
 	},
 	.probe		= adxl345_i2c_probe,
 	.remove		= adxl345_i2c_remove,
drivers/iio/accel/adxl345_spi.c +9 -0
index 5fcd1fa..a3c5d49 100644
@@ -10,6 +10,7 @@
  * SPI driver for ADXL345
  */
 
+#include <linux/acpi.h>
 #include <linux/module.h>
 #include <linux/regmap.h>
 #include <linux/spi/spi.h>
@@ -59,9 +60,17 @@ static const struct spi_device_id adxl345_spi_id[] = {
 
 MODULE_DEVICE_TABLE(spi, adxl345_spi_id);
 
+static const struct acpi_device_id adxl345_acpi_id[] = {
+	{ "ADS0345", 0 },
+	{ }
+};
+
+MODULE_DEVICE_TABLE(acpi, adxl345_acpi_id);
+
 static struct spi_driver adxl345_spi_driver = {
 	.driver = {
 		.name	= "adxl345_spi",
+		.acpi_match_table = ACPI_PTR(adxl345_acpi_id),
 	},
 	.probe		= adxl345_spi_probe,
 	.remove		= adxl345_spi_remove,
Signature · 1 line
2.7.4
#5 lore raw
In reply to Eva Rachel Retuya
Quoted 7 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_raw for x, y and z axes, scale. After applying this series, driver now supports the SPI protocol and enumeration of device via ACPI.

Hello all,

Kindly disregard this. Will submit a v3 because I have to drop ACPI and switch to DT method of enumeration.

Thanks,
Eva

Quoted 38 lines

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):
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
iio: accel: adxl345: Add ACPI support

 drivers/iio/accel/Kconfig        |  18 +++-
 drivers/iio/accel/Makefile       |   4 +-
 drivers/iio/accel/adxl345.c      | 194 ---------------------------------------
 drivers/iio/accel/adxl345.h      |  18 ++++
 drivers/iio/accel/adxl345_core.c | 182 ++++++++++++++++++++++++++++++++++++
 drivers/iio/accel/adxl345_i2c.c  |  79 ++++++++++++++++
 drivers/iio/accel/adxl345_spi.c  |  84 +++++++++++++++++
 7 files changed, 381 insertions(+), 198 deletions(-)
 delete mode 100644 drivers/iio/accel/adxl345.c
 create mode 100644 drivers/iio/accel/adxl345.h
 create mode 100644 drivers/iio/accel/adxl345_core.c
 create mode 100644 drivers/iio/accel/adxl345_i2c.c
 create mode 100644 drivers/iio/accel/adxl345_spi.c
Signature · 1 line
2.7.4