From: Mehdi Djait <mehdi.djait.k@gmail.com>
To: jic23@kernel.org, mazziesaccount@gmail.com
Cc: krzysztof.kozlowski+dt@linaro.org,
andriy.shevchenko@linux.intel.com, robh+dt@kernel.org,
lars@metafoo.de, linux-iio@vger.kernel.org,
linux-kernel@vger.kernel.org, devicetree@vger.kernel.org,
Mehdi Djait <mehdi.djait.k@gmail.com>
Subject: [PATCH v8 6/7] iio: accel: kionix-kx022a: Add a function to retrieve number of bytes in buffer
Date: Wed, 23 Aug 2023 23:16:40 +0200 [thread overview]
Message-ID: <923d01408680f5ac88ca8ee565a990645578ee83.1692824815.git.mehdi.djait.k@gmail.com> (raw)
In-Reply-To: <cover.1692824815.git.mehdi.djait.k@gmail.com>
Since Kionix accelerometers use various numbers of bits to report data, a
device-specific function is required.
Implement the function as a callback in the device-specific chip_info structure
Reviewed-by: Matti Vaittinen <mazziesaccount@gmail.com>
Signed-off-by: Mehdi Djait <mehdi.djait.k@gmail.com>
---
v8:
v7:
- no changes
v6:
- directly return KX022A_FIFO_MAX_BYTES as suggested by Andy
v5:
- no changes
v4:
- removed the comment about "bogus value from i2c"
- removed regmap_get_device(data->regmap); dev is present in the
driver's private data
v3:
- no changes
v2:
- separated this change from the chip_info introduction and made it a patch in v2
- changed the function from generic implementation for to device-specific one
- removed blank lines pointed out by checkpatch
- changed the allocation of the "buffer" array in __kx022a_fifo_flush
drivers/iio/accel/kionix-kx022a.c | 28 ++++++++++++++++++----------
drivers/iio/accel/kionix-kx022a.h | 4 ++++
2 files changed, 22 insertions(+), 10 deletions(-)
diff --git a/drivers/iio/accel/kionix-kx022a.c b/drivers/iio/accel/kionix-kx022a.c
index 6bac618c63b4..458859ebc645 100644
--- a/drivers/iio/accel/kionix-kx022a.c
+++ b/drivers/iio/accel/kionix-kx022a.c
@@ -596,26 +596,33 @@ static int kx022a_drop_fifo_contents(struct kx022a_data *data)
return regmap_write(data->regmap, data->chip_info->buf_clear, 0x0);
}
+static int kx022a_get_fifo_bytes(struct kx022a_data *data)
+{
+ int ret, fifo_bytes;
+
+ ret = regmap_read(data->regmap, KX022A_REG_BUF_STATUS_1, &fifo_bytes);
+ if (ret) {
+ dev_err(data->dev, "Error reading buffer status\n");
+ return ret;
+ }
+
+ if (fifo_bytes == KX022A_FIFO_FULL_VALUE)
+ return KX022A_FIFO_MAX_BYTES;
+
+ return fifo_bytes;
+}
+
static int __kx022a_fifo_flush(struct iio_dev *idev, unsigned int samples,
bool irq)
{
struct kx022a_data *data = iio_priv(idev);
- struct device *dev = regmap_get_device(data->regmap);
uint64_t sample_period;
int count, fifo_bytes;
bool renable = false;
int64_t tstamp;
int ret, i;
- ret = regmap_read(data->regmap, KX022A_REG_BUF_STATUS_1, &fifo_bytes);
- if (ret) {
- dev_err(dev, "Error reading buffer status\n");
- return ret;
- }
-
- /* Let's not overflow if we for some reason get bogus value from i2c */
- if (fifo_bytes == KX022A_FIFO_FULL_VALUE)
- fifo_bytes = KX022A_FIFO_MAX_BYTES;
+ fifo_bytes = data->chip_info->get_fifo_bytes(data);
if (fifo_bytes % KX022A_FIFO_SAMPLES_SIZE_BYTES)
dev_warn(data->dev, "Bad FIFO alignment. Data may be corrupt\n");
@@ -1024,6 +1031,7 @@ const struct kx022a_chip_info kx022a_chip_info = {
.inc5 = KX022A_REG_INC5,
.inc6 = KX022A_REG_INC6,
.xout_l = KX022A_REG_XOUT_L,
+ .get_fifo_bytes = kx022a_get_fifo_bytes,
};
EXPORT_SYMBOL_NS_GPL(kx022a_chip_info, IIO_KX022A);
diff --git a/drivers/iio/accel/kionix-kx022a.h b/drivers/iio/accel/kionix-kx022a.h
index 0e5026019213..c9f9aee7e597 100644
--- a/drivers/iio/accel/kionix-kx022a.h
+++ b/drivers/iio/accel/kionix-kx022a.h
@@ -76,6 +76,8 @@
struct device;
+struct kx022a_data;
+
/**
* struct kx022a_chip_info - Kionix accelerometer chip specific information
*
@@ -99,6 +101,7 @@ struct device;
* @inc5: interrupt control register 5
* @inc6: interrupt control register 6
* @xout_l: x-axis output least significant byte
+ * @get_fifo_bytes: function pointer to get number of bytes in the FIFO buffer
*/
struct kx022a_chip_info {
const char *name;
@@ -121,6 +124,7 @@ struct kx022a_chip_info {
u8 inc5;
u8 inc6;
u8 xout_l;
+ int (*get_fifo_bytes)(struct kx022a_data *);
};
int kx022a_probe_internal(struct device *dev, const struct kx022a_chip_info *chip_info);
--
2.30.2
next prev parent reply other threads:[~2023-08-23 21:18 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-23 21:16 [PATCH v8 0/7] iio: accel: Add support for Kionix/ROHM KX132-1211 accelerometer Mehdi Djait
2023-08-23 21:16 ` [PATCH v8 1/7] dt-bindings: iio: Add " Mehdi Djait
2023-08-23 21:16 ` [PATCH v8 2/7] iio: accel: kionix-kx022a: Remove blank lines Mehdi Djait
2023-08-24 11:49 ` Andy Shevchenko
2023-08-23 21:16 ` [PATCH v8 3/7] iio: accel: kionix-kx022a: Warn on failed matches and assume compatibility Mehdi Djait
2023-08-24 11:51 ` Andy Shevchenko
2023-08-27 17:57 ` Jonathan Cameron
2023-08-23 21:16 ` [PATCH v8 4/7] iio: accel: kionix-kx022a: Add an i2c_device_id table Mehdi Djait
2023-08-24 11:52 ` Andy Shevchenko
2023-08-23 21:16 ` [PATCH v8 5/7] iio: accel: kionix-kx022a: Refactor driver and add chip_info structure Mehdi Djait
2023-08-24 11:55 ` Andy Shevchenko
2023-08-23 21:16 ` Mehdi Djait [this message]
2023-08-24 11:58 ` [PATCH v8 6/7] iio: accel: kionix-kx022a: Add a function to retrieve number of bytes in buffer Andy Shevchenko
2023-08-24 12:52 ` Matti Vaittinen
2023-08-24 13:39 ` Andy Shevchenko
2023-08-24 13:44 ` Mehdi Djait
2023-08-24 13:47 ` Andy Shevchenko
2023-08-24 14:23 ` Mehdi Djait
2023-08-24 14:39 ` Andy Shevchenko
2023-08-27 18:09 ` Jonathan Cameron
2023-08-28 6:24 ` Matti Vaittinen
2023-08-28 10:53 ` Andy Shevchenko
2023-08-29 6:33 ` Matti Vaittinen
2023-09-06 16:03 ` Andy Shevchenko
2023-09-07 6:33 ` Matti Vaittinen
2023-09-11 13:03 ` Andy Shevchenko
2023-08-23 21:16 ` [PATCH v8 7/7] iio: accel: Add support for Kionix/ROHM KX132-1211 accelerometer Mehdi Djait
2023-08-24 12:02 ` Andy Shevchenko
2023-08-24 12:51 ` Matti Vaittinen
2023-08-24 13:39 ` Andy Shevchenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=923d01408680f5ac88ca8ee565a990645578ee83.1692824815.git.mehdi.djait.k@gmail.com \
--to=mehdi.djait.k@gmail.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=devicetree@vger.kernel.org \
--cc=jic23@kernel.org \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mazziesaccount@gmail.com \
--cc=robh+dt@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).