Debian Codegraph @

drivers/iio/pressure/mprls0025pa_spi.c

raw
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * MPRLS0025PA - Honeywell MicroPressure MPR series SPI sensor driver
4 *
5 * Copyright (c) 2024 Petre Rodan <[email protected]>
6 *
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 */
10
11 #include <linux/array_size.h>
12 #include <linux/device.h>
13 #include <linux/errno.h>
14 #include <linux/mod_devicetable.h>
15 #include <linux/module.h>
16 #include <linux/spi/spi.h>
17 #include <linux/stddef.h>
18 #include <linux/types.h>
19
20 #include "mprls0025pa.h"
21
22 static int mpr_spi_xfer(struct mpr_data *data, const u8 cmd, const u8 pkt_len)
23 {
24 struct spi_device *spi = to_spi_device(data->dev);
25 struct spi_transfer xfers[2] = { };
26
27 if (pkt_len > MPR_MEASUREMENT_RD_SIZE)
28 return -EOVERFLOW;
29
30 data->tx_buf[0] = cmd;
31
32 /*
33 * Dummy transfer with no data, just cause a 2.5us+ delay between the CS assert
34 * and the first clock edge as per the datasheet tHDSS timing requirement.
35 */
36 xfers[0].delay.value = 2500;
37 xfers[0].delay.unit = SPI_DELAY_UNIT_NSECS;
38
39 xfers[1].tx_buf = data->tx_buf;
40 xfers[1].rx_buf = data->rx_buf;
41 xfers[1].len = pkt_len;
42
43 return spi_sync_transfer(spi, xfers, ARRAY_SIZE(xfers));
44 }
45
46 static const struct mpr_ops mpr_spi_ops = {
47 .read = mpr_spi_xfer,
48 .write = mpr_spi_xfer,
49 };
50
51 static int mpr_spi_probe(struct spi_device *spi)
52 {
53 return mpr_common_probe(&spi->dev, &mpr_spi_ops, spi->irq);
54 }
55
56 static const struct of_device_id mpr_spi_match[] = {
57 { .compatible = "honeywell,mprls0025pa" },
58 { }
59 };
60 MODULE_DEVICE_TABLE(of, mpr_spi_match);
61
62 static const struct spi_device_id mpr_spi_id[] = {
63 { "mprls0025pa" },
64 { }
65 };
66 MODULE_DEVICE_TABLE(spi, mpr_spi_id);
67
68 static struct spi_driver mpr_spi_driver = {
69 .driver = {
70 .name = "mprls0025pa",
71 .of_match_table = mpr_spi_match,
72 },
73 .probe = mpr_spi_probe,
74 .id_table = mpr_spi_id,
75 };
76 module_spi_driver(mpr_spi_driver);
77
78 MODULE_AUTHOR("Petre Rodan <[email protected]>");
79 MODULE_DESCRIPTION("Honeywell MPR pressure sensor spi driver");
80 MODULE_LICENSE("GPL");
81 MODULE_IMPORT_NS("IIO_HONEYWELL_MPRLS0025PA");