Merge tag 'clk-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux.git] / drivers / iio / pressure / mprls0025pa_spi.c
blob09f724c76d706e3167e0e7e34333cafac6bbd978
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * MPRLS0025PA - Honeywell MicroPressure MPR series SPI sensor driver
5 * Copyright (c) 2024 Petre Rodan <petre.rodan@subdimension.ro>
7 * Data sheet:
8 * https://prod-edam.honeywell.com/content/dam/honeywell-edam/sps/siot/en-us/products/sensors/pressure-sensors/board-mount-pressure-sensors/micropressure-mpr-series/documents/sps-siot-mpr-series-datasheet-32332628-ciid-172626.pdf
9 */
11 #include <linux/device.h>
12 #include <linux/errno.h>
13 #include <linux/mod_devicetable.h>
14 #include <linux/module.h>
15 #include <linux/spi/spi.h>
16 #include <linux/stddef.h>
17 #include <linux/types.h>
19 #include "mprls0025pa.h"
21 struct mpr_spi_buf {
22 u8 tx[MPR_MEASUREMENT_RD_SIZE] __aligned(IIO_DMA_MINALIGN);
25 static int mpr_spi_init(struct device *dev)
27 struct spi_device *spi = to_spi_device(dev);
28 struct mpr_spi_buf *buf;
30 buf = devm_kzalloc(dev, sizeof(*buf), GFP_KERNEL);
31 if (!buf)
32 return -ENOMEM;
34 spi_set_drvdata(spi, buf);
36 return 0;
39 static int mpr_spi_xfer(struct mpr_data *data, const u8 cmd, const u8 pkt_len)
41 struct spi_device *spi = to_spi_device(data->dev);
42 struct mpr_spi_buf *buf = spi_get_drvdata(spi);
43 struct spi_transfer xfer;
45 if (pkt_len > MPR_MEASUREMENT_RD_SIZE)
46 return -EOVERFLOW;
48 buf->tx[0] = cmd;
49 xfer.tx_buf = buf->tx;
50 xfer.rx_buf = data->buffer;
51 xfer.len = pkt_len;
53 return spi_sync_transfer(spi, &xfer, 1);
56 static const struct mpr_ops mpr_spi_ops = {
57 .init = mpr_spi_init,
58 .read = mpr_spi_xfer,
59 .write = mpr_spi_xfer,
62 static int mpr_spi_probe(struct spi_device *spi)
64 return mpr_common_probe(&spi->dev, &mpr_spi_ops, spi->irq);
67 static const struct of_device_id mpr_spi_match[] = {
68 { .compatible = "honeywell,mprls0025pa" },
71 MODULE_DEVICE_TABLE(of, mpr_spi_match);
73 static const struct spi_device_id mpr_spi_id[] = {
74 { "mprls0025pa" },
77 MODULE_DEVICE_TABLE(spi, mpr_spi_id);
79 static struct spi_driver mpr_spi_driver = {
80 .driver = {
81 .name = "mprls0025pa",
82 .of_match_table = mpr_spi_match,
84 .probe = mpr_spi_probe,
85 .id_table = mpr_spi_id,
87 module_spi_driver(mpr_spi_driver);
89 MODULE_AUTHOR("Petre Rodan <petre.rodan@subdimension.ro>");
90 MODULE_DESCRIPTION("Honeywell MPR pressure sensor spi driver");
91 MODULE_LICENSE("GPL");
92 MODULE_IMPORT_NS("IIO_HONEYWELL_MPRLS0025PA");