Commit 774c3fab authored by Mehdi Djait's avatar Mehdi Djait Committed by Jonathan Cameron

iio: accel: kionix-kx022a: Add a function to retrieve number of bytes in buffer

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: default avatarMatti Vaittinen <mazziesaccount@gmail.com>
Signed-off-by: default avatarMehdi Djait <mehdi.djait.k@gmail.com>
Link: https://lore.kernel.org/r/9c550fb28e34915d473e379f812c7753f7643bae.1694867379.git.mehdi.djait.k@gmail.comSigned-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent e7123a4d
...@@ -585,26 +585,33 @@ static int kx022a_drop_fifo_contents(struct kx022a_data *data) ...@@ -585,26 +585,33 @@ static int kx022a_drop_fifo_contents(struct kx022a_data *data)
return regmap_write(data->regmap, data->chip_info->buf_clear, 0x0); return regmap_write(data->regmap, data->chip_info->buf_clear, 0x0);
} }
static int kx022a_get_fifo_bytes_available(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, static int __kx022a_fifo_flush(struct iio_dev *idev, unsigned int samples,
bool irq) bool irq)
{ {
struct kx022a_data *data = iio_priv(idev); struct kx022a_data *data = iio_priv(idev);
struct device *dev = regmap_get_device(data->regmap);
uint64_t sample_period; uint64_t sample_period;
int count, fifo_bytes; int count, fifo_bytes;
bool renable = false; bool renable = false;
int64_t tstamp; int64_t tstamp;
int ret, i; int ret, i;
ret = regmap_read(data->regmap, KX022A_REG_BUF_STATUS_1, &fifo_bytes); fifo_bytes = data->chip_info->get_fifo_bytes_available(data);
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;
if (fifo_bytes % KX022A_FIFO_SAMPLES_SIZE_BYTES) if (fifo_bytes % KX022A_FIFO_SAMPLES_SIZE_BYTES)
dev_warn(data->dev, "Bad FIFO alignment. Data may be corrupt\n"); dev_warn(data->dev, "Bad FIFO alignment. Data may be corrupt\n");
...@@ -1013,6 +1020,7 @@ const struct kx022a_chip_info kx022a_chip_info = { ...@@ -1013,6 +1020,7 @@ const struct kx022a_chip_info kx022a_chip_info = {
.inc5 = KX022A_REG_INC5, .inc5 = KX022A_REG_INC5,
.inc6 = KX022A_REG_INC6, .inc6 = KX022A_REG_INC6,
.xout_l = KX022A_REG_XOUT_L, .xout_l = KX022A_REG_XOUT_L,
.get_fifo_bytes_available = kx022a_get_fifo_bytes_available,
}; };
EXPORT_SYMBOL_NS_GPL(kx022a_chip_info, IIO_KX022A); EXPORT_SYMBOL_NS_GPL(kx022a_chip_info, IIO_KX022A);
......
...@@ -76,6 +76,8 @@ ...@@ -76,6 +76,8 @@
struct device; struct device;
struct kx022a_data;
/** /**
* struct kx022a_chip_info - Kionix accelerometer chip specific information * struct kx022a_chip_info - Kionix accelerometer chip specific information
* *
...@@ -99,6 +101,9 @@ struct device; ...@@ -99,6 +101,9 @@ struct device;
* @inc5: interrupt control register 5 * @inc5: interrupt control register 5
* @inc6: interrupt control register 6 * @inc6: interrupt control register 6
* @xout_l: x-axis output least significant byte * @xout_l: x-axis output least significant byte
* @get_fifo_bytes_available: function pointer to get amount of acceleration
* data bytes currently stored in the sensor's FIFO
* buffer
*/ */
struct kx022a_chip_info { struct kx022a_chip_info {
const char *name; const char *name;
...@@ -121,6 +126,7 @@ struct kx022a_chip_info { ...@@ -121,6 +126,7 @@ struct kx022a_chip_info {
u8 inc5; u8 inc5;
u8 inc6; u8 inc6;
u8 xout_l; u8 xout_l;
int (*get_fifo_bytes_available)(struct kx022a_data *);
}; };
int kx022a_probe_internal(struct device *dev, const struct kx022a_chip_info *chip_info); int kx022a_probe_internal(struct device *dev, const struct kx022a_chip_info *chip_info);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment