[PATCH v2 09/13] iio: pressure: mprls0025pa: introduce tx buffer

Petre Rodan
2026-01-14T10:07:53Z

Use a tx_buf that is part of the priv struct for transferring data to
the sensor instead of relying on a devm_kzalloc()-ed array.
Remove the .init operation in the process.

Reviewed-by: Marcelo Schmitt <marcelo.schmitt1@gmail.com>
Signed-off-by: Petre Rodan <petre.rodan@subdimension.ro>
---
v1 -> v2 no functional change
---
drivers/iio/pressure/mprls0025pa.c | 4 ----
drivers/iio/pressure/mprls0025pa.h | 3 ++-
drivers/iio/pressure/mprls0025pa_i2c.c | 10 ++--------
drivers/iio/pressure/mprls0025pa_spi.c | 24 ++----------------------
4 files changed, 6 insertions(+), 35 deletions(-)

diff --git a/drivers/iio/pressure/mprls0025pa.c b/drivers/iio/pressure/mprls0025pa.c
index fd9c8ea61eb3..7532b2e74413 100644
--- a/drivers/iio/pressure/mprls0025pa.c
+++ b/drivers/iio/pressure/mprls0025pa.c
@@ -363,10 +363,6 @@ int mpr_common_probe(struct device *dev, const struct mpr_ops *ops, int irq)
return dev_err_probe(dev, ret,
"can't get and enable vdd supply\n");

- ret = data->ops->init(data->dev);
- if (ret)
- return ret;
-
ret = device_property_read_u32(dev,
"honeywell,transfer-function", &func);
if (ret)
diff --git a/drivers/iio/pressure/mprls0025pa.h b/drivers/iio/pressure/mprls0025pa.h
index 119ebb0ba567..9f43273e635f 100644
--- a/drivers/iio/pressure/mprls0025pa.h
+++ b/drivers/iio/pressure/mprls0025pa.h
@@ -55,6 +55,7 @@ enum mpr_func_id {
* @chan.pres: pressure value
* @chan.ts: timestamp
* @rx_buf: raw conversion data
+ * @tx_buf: output buffer
*/
struct mpr_data {
struct device *dev;
@@ -76,10 +77,10 @@ struct mpr_data {
aligned_s64 ts;
} chan;
u8 rx_buf[MPR_MEASUREMENT_RD_SIZE] __aligned(IIO_DMA_MINALIGN);
+ u8 tx_buf[MPR_MEASUREMENT_RD_SIZE];
};

struct mpr_ops {
- int (*init)(struct device *dev);
int (*read)(struct mpr_data *data, const u8 cmd, const u8 cnt);
int (*write)(struct mpr_data *data, const u8 cmd, const u8 cnt);
};
diff --git a/drivers/iio/pressure/mprls0025pa_i2c.c b/drivers/iio/pressure/mprls0025pa_i2c.c
index 36da0059b19f..a0bbc6af9283 100644
--- a/drivers/iio/pressure/mprls0025pa_i2c.c
+++ b/drivers/iio/pressure/mprls0025pa_i2c.c
@@ -17,11 +17,6 @@

#include "mprls0025pa.h"

-static int mpr_i2c_init(struct device *unused)
-{
- return 0;
-}
-
static int mpr_i2c_read(struct mpr_data *data, const u8 unused, const u8 cnt)
{
int ret;
@@ -44,9 +39,9 @@ static int mpr_i2c_write(struct mpr_data *data, const u8 cmd, const u8 unused)
{
int ret;
struct i2c_client *client = to_i2c_client(data->dev);
- u8 wdata[MPR_PKT_SYNC_LEN] = { cmd };

- ret = i2c_master_send(client, wdata, MPR_PKT_SYNC_LEN);
+ data->tx_buf[0] = cmd;
+ ret = i2c_master_send(client, data->tx_buf, MPR_PKT_SYNC_LEN);
if (ret < 0)
return ret;
else if (ret != MPR_PKT_SYNC_LEN)
@@ -56,7 +51,6 @@ static int mpr_i2c_write(struct mpr_data *data, const u8 cmd, const u8 unused)
}

static const struct mpr_ops mpr_i2c_ops = {
- .init = mpr_i2c_init,
.read = mpr_i2c_read,
.write = mpr_i2c_write,
};
diff --git a/drivers/iio/pressure/mprls0025pa_spi.c b/drivers/iio/pressure/mprls0025pa_spi.c
index 247b65226bb9..8c8c726f703f 100644
--- a/drivers/iio/pressure/mprls0025pa_spi.c
+++ b/drivers/iio/pressure/mprls0025pa_spi.c
@@ -19,34 +19,15 @@

#include "mprls0025pa.h"

-struct mpr_spi_buf {
- u8 tx[MPR_MEASUREMENT_RD_SIZE] __aligned(IIO_DMA_MINALIGN);
-};
-
-static int mpr_spi_init(struct device *dev)
-{
- struct spi_device *spi = to_spi_device(dev);
- struct mpr_spi_buf *buf;
-
- buf = devm_kzalloc(dev, sizeof(*buf), GFP_KERNEL);
- if (!buf)
- return -ENOMEM;
-
- spi_set_drvdata(spi, buf);
-
- return 0;
-}
-
static int mpr_spi_xfer(struct mpr_data *data, const u8 cmd, const u8 pkt_len)
{
struct spi_device *spi = to_spi_device(data->dev);
- struct mpr_spi_buf *buf = spi_get_drvdata(spi);
struct spi_transfer xfers[2] = { };

if (pkt_len > MPR_MEASUREMENT_RD_SIZE)
return -EOVERFLOW;

- buf->tx[0] = cmd;
+ data->tx_buf[0] = cmd;

/*
* Dummy transfer with no data, just cause a 2.5us+ delay between the CS assert
@@ -55,7 +36,7 @@ static int mpr_spi_xfer(struct mpr_data *data, const u8 cmd, const u8 pkt_len)
xfers[0].delay.value = 2500;
xfers[0].delay.unit = SPI_DELAY_UNIT_NSECS;

- xfers[1].tx_buf = buf->tx;
+ xfers[1].tx_buf = data->tx_buf;
xfers[1].rx_buf = data->rx_buf;
xfers[1].len = pkt_len;

@@ -63,7 +44,6 @@ static int mpr_spi_xfer(struct mpr_data *data, const u8 cmd, const u8 pkt_len)
}

static const struct mpr_ops mpr_spi_ops = {
- .init = mpr_spi_init,
.read = mpr_spi_xfer,
.write = mpr_spi_xfer,
};

--
2.52.0