Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

iio: pressure: mprls0025pa: introduce tx buffer

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>

authored by

Petre Rodan and committed by
Jonathan Cameron
cf322f80 7071f9f0

+6 -35
-4
drivers/iio/pressure/mprls0025pa.c
··· 363 363 return dev_err_probe(dev, ret, 364 364 "can't get and enable vdd supply\n"); 365 365 366 - ret = data->ops->init(data->dev); 367 - if (ret) 368 - return ret; 369 - 370 366 ret = device_property_read_u32(dev, 371 367 "honeywell,transfer-function", &func); 372 368 if (ret)
+2 -1
drivers/iio/pressure/mprls0025pa.h
··· 55 55 * @chan.pres: pressure value 56 56 * @chan.ts: timestamp 57 57 * @rx_buf: raw conversion data 58 + * @tx_buf: output buffer 58 59 */ 59 60 struct mpr_data { 60 61 struct device *dev; ··· 77 76 aligned_s64 ts; 78 77 } chan; 79 78 u8 rx_buf[MPR_MEASUREMENT_RD_SIZE] __aligned(IIO_DMA_MINALIGN); 79 + u8 tx_buf[MPR_MEASUREMENT_RD_SIZE]; 80 80 }; 81 81 82 82 struct mpr_ops { 83 - int (*init)(struct device *dev); 84 83 int (*read)(struct mpr_data *data, const u8 cmd, const u8 cnt); 85 84 int (*write)(struct mpr_data *data, const u8 cmd, const u8 cnt); 86 85 };
+2 -8
drivers/iio/pressure/mprls0025pa_i2c.c
··· 17 17 18 18 #include "mprls0025pa.h" 19 19 20 - static int mpr_i2c_init(struct device *unused) 21 - { 22 - return 0; 23 - } 24 - 25 20 static int mpr_i2c_read(struct mpr_data *data, const u8 unused, const u8 cnt) 26 21 { 27 22 int ret; ··· 39 44 { 40 45 int ret; 41 46 struct i2c_client *client = to_i2c_client(data->dev); 42 - u8 wdata[MPR_PKT_SYNC_LEN] = { cmd }; 43 47 44 - ret = i2c_master_send(client, wdata, MPR_PKT_SYNC_LEN); 48 + data->tx_buf[0] = cmd; 49 + ret = i2c_master_send(client, data->tx_buf, MPR_PKT_SYNC_LEN); 45 50 if (ret < 0) 46 51 return ret; 47 52 else if (ret != MPR_PKT_SYNC_LEN) ··· 51 56 } 52 57 53 58 static const struct mpr_ops mpr_i2c_ops = { 54 - .init = mpr_i2c_init, 55 59 .read = mpr_i2c_read, 56 60 .write = mpr_i2c_write, 57 61 };
+2 -22
drivers/iio/pressure/mprls0025pa_spi.c
··· 19 19 20 20 #include "mprls0025pa.h" 21 21 22 - struct mpr_spi_buf { 23 - u8 tx[MPR_MEASUREMENT_RD_SIZE] __aligned(IIO_DMA_MINALIGN); 24 - }; 25 - 26 - static int mpr_spi_init(struct device *dev) 27 - { 28 - struct spi_device *spi = to_spi_device(dev); 29 - struct mpr_spi_buf *buf; 30 - 31 - buf = devm_kzalloc(dev, sizeof(*buf), GFP_KERNEL); 32 - if (!buf) 33 - return -ENOMEM; 34 - 35 - spi_set_drvdata(spi, buf); 36 - 37 - return 0; 38 - } 39 - 40 22 static int mpr_spi_xfer(struct mpr_data *data, const u8 cmd, const u8 pkt_len) 41 23 { 42 24 struct spi_device *spi = to_spi_device(data->dev); 43 - struct mpr_spi_buf *buf = spi_get_drvdata(spi); 44 25 struct spi_transfer xfers[2] = { }; 45 26 46 27 if (pkt_len > MPR_MEASUREMENT_RD_SIZE) 47 28 return -EOVERFLOW; 48 29 49 - buf->tx[0] = cmd; 30 + data->tx_buf[0] = cmd; 50 31 51 32 /* 52 33 * Dummy transfer with no data, just cause a 2.5us+ delay between the CS assert ··· 36 55 xfers[0].delay.value = 2500; 37 56 xfers[0].delay.unit = SPI_DELAY_UNIT_NSECS; 38 57 39 - xfers[1].tx_buf = buf->tx; 58 + xfers[1].tx_buf = data->tx_buf; 40 59 xfers[1].rx_buf = data->rx_buf; 41 60 xfers[1].len = pkt_len; 42 61 ··· 44 63 } 45 64 46 65 static const struct mpr_ops mpr_spi_ops = { 47 - .init = mpr_spi_init, 48 66 .read = mpr_spi_xfer, 49 67 .write = mpr_spi_xfer, 50 68 };