]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
iio: pressure: mprls0025pa: introduce tx buffer
authorPetre Rodan <petre.rodan@subdimension.ro>
Wed, 14 Jan 2026 16:55:38 +0000 (18:55 +0200)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Fri, 16 Jan 2026 17:40:40 +0000 (17:40 +0000)
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>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/pressure/mprls0025pa.c
drivers/iio/pressure/mprls0025pa.h
drivers/iio/pressure/mprls0025pa_i2c.c
drivers/iio/pressure/mprls0025pa_spi.c

index 245d7ed82b6bfe7501ba78794fca894c0cda3ad0..2bcd339dc84e99e21d8f2a4f636aa08e2aa44e61 100644 (file)
@@ -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)
index 119ebb0ba567ee5570822a01572dcde7ae2cb46b..9f43273e635fc872e01e00b26a116bdcfbb9eb7d 100644 (file)
@@ -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);
 };
index 36da0059b19fccf55f1b8bfe7f4ea0ee9a1ce7b1..a0bbc6af928312c2fe0b0b021c8b70c7bd7c560a 100644 (file)
 
 #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,
 };
index 247b65226bb9e942e34f1bd5e7e2b94ca06a7338..8c8c726f703f6ced1e64ca37f02755ddec57a2b8 100644 (file)
 
 #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,
 };