[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20241117182651.115056-12-l.rubusch@gmail.com>
Date: Sun, 17 Nov 2024 18:26:40 +0000
From: Lothar Rubusch <l.rubusch@...il.com>
To: lars@...afoo.de,
Michael.Hennerich@...log.com,
jic23@...nel.org
Cc: linux-iio@...r.kernel.org,
linux-kernel@...r.kernel.org,
eraretuya@...il.com,
l.rubusch@...il.com
Subject: [PATCH v2 11/22] iio: accel: adxl345: import adxl345 general data
Use struct adxl34x_platform_data from the included public header of the
input driver for ADXL34x with the following argumentation for this
approach:
- The iio driver for the ADXL34x covers features also implemented in
the older input driver. The iio driver will implement the same
features but can also benefit from including the common header and
struct adxl34x_platform_data. Once complete, the input driver could
be faded out.
- The fields in the input driver are identical to the fields the IIO
implementation will need. Including the header over reimplementing,
avoids a duplication of almost identical headers in IIO and iio.
- The header for the input driver is public. It provides a public
interface for adxl34x related implementation and is not private to
the input system.
Signed-off-by: Lothar Rubusch <l.rubusch@...il.com>
---
drivers/iio/accel/adxl345_core.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c
index 32163cfe6f..b16887ec1c 100644
--- a/drivers/iio/accel/adxl345_core.c
+++ b/drivers/iio/accel/adxl345_core.c
@@ -16,6 +16,8 @@
#include <linux/iio/iio.h>
#include <linux/iio/sysfs.h>
+#include <linux/input/adxl34x.h>
+
#include "adxl345.h"
/* ADXL345 register map */
@@ -126,10 +128,15 @@
*/
#define ADXL34x_FIFO_SIZE 33
+static const struct adxl34x_platform_data adxl345_default_init = {
+ .tap_axis_control = ADXL_TAP_X_EN | ADXL_TAP_Y_EN | ADXL_TAP_Z_EN,
+};
+
struct adxl34x_state {
int irq;
const struct adxl345_chip_info *info;
struct regmap *regmap;
+ struct adxl34x_platform_data data; /* watermark, fifo_mode, etc */
bool fifo_delay; /* delay: delay is needed for SPI */
u8 intio;
};
@@ -331,6 +338,7 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap,
unsigned int data_format_mask = (ADXL345_DATA_FORMAT_RANGE |
ADXL345_DATA_FORMAT_FULL_RES |
ADXL345_DATA_FORMAT_SELF_TEST);
+ const struct adxl34x_platform_data *data;
int ret;
indio_dev = devm_iio_device_alloc(dev, sizeof(*st));
@@ -346,6 +354,16 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap,
return -ENODEV;
st->fifo_delay = fifo_delay_default;
+ data = dev_get_platdata(dev);
+ if (!data) {
+ dev_dbg(dev, "No platform data: Using default initialization\n");
+ data = &adxl345_default_init;
+ }
+ st->data = *data;
+
+ /* some reasonable pre-initialization */
+ st->data.act_axis_control = 0xFF;
+
st->intio = ADXL345_INT1;
indio_dev->name = st->info->name;
--
2.39.5
Powered by blists - more mailing lists