xref: /linux/drivers/iio/pressure/mprls0025pa.h (revision 914a1fe5f818bff5abb0e792bc0addf0c7c274f4)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * MPRLS0025PA - Honeywell MicroPressure pressure sensor series driver
4  *
5  * Copyright (c) Andreas Klinger <ak@it-klinger.de>
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 #ifndef _MPRLS0025PA_H
12 #define _MPRLS0025PA_H
13 
14 #include <linux/completion.h>
15 #include <linux/delay.h>
16 #include <linux/device.h>
17 #include <linux/mutex.h>
18 #include <linux/stddef.h>
19 #include <linux/types.h>
20 
21 #include <linux/iio/iio.h>
22 
23 #define MPR_MEASUREMENT_RD_SIZE 4
24 #define MPR_CMD_NOP      0xf0
25 #define MPR_CMD_SYNC     0xaa
26 #define MPR_PKT_NOP_LEN  MPR_MEASUREMENT_RD_SIZE
27 #define MPR_PKT_SYNC_LEN 3
28 
29 struct device;
30 
31 struct iio_chan_spec;
32 struct iio_dev;
33 
34 struct mpr_data;
35 struct mpr_ops;
36 
37 enum mpr_func_id {
38 	MPR_FUNCTION_A,
39 	MPR_FUNCTION_B,
40 	MPR_FUNCTION_C,
41 };
42 
43 /**
44  * struct mpr_data
45  * @dev: current device structure
46  * @ops: functions that implement the sensor reads/writes, bus init
47  * @lock: access to device during read
48  * @pmin: minimal pressure in pascal
49  * @pmax: maximal pressure in pascal
50  * @function: transfer function
51  * @outmin: minimum raw pressure in counts (based on transfer function)
52  * @outmax: maximum raw pressure in counts (based on transfer function)
53  * @scale: pressure scale
54  * @scale2: pressure scale, decimal number
55  * @offset: pressure offset
56  * @offset2: pressure offset, decimal number
57  * @gpiod_reset: reset
58  * @irq: end of conversion irq. used to distinguish between irq mode and
59  *       reading in a loop until data is ready
60  * @completion: handshake from irq to read
61  * @chan: channel values for buffered mode
62  * @chan.pres: pressure value
63  * @chan.ts: timestamp
64  * @buffer: raw conversion data
65  */
66 struct mpr_data {
67 	struct device		*dev;
68 	const struct mpr_ops	*ops;
69 	struct mutex		lock;
70 	u32			pmin;
71 	u32			pmax;
72 	enum mpr_func_id	function;
73 	u32			outmin;
74 	u32			outmax;
75 	int			scale;
76 	int			scale2;
77 	int			offset;
78 	int			offset2;
79 	struct gpio_desc	*gpiod_reset;
80 	int			irq;
81 	struct completion	completion;
82 	struct {
83 		s32 pres;
84 		aligned_s64 ts;
85 	} chan;
86 	u8	    buffer[MPR_MEASUREMENT_RD_SIZE] __aligned(IIO_DMA_MINALIGN);
87 };
88 
89 struct mpr_ops {
90 	int (*init)(struct device *dev);
91 	int (*read)(struct mpr_data *data, const u8 cmd, const u8 cnt);
92 	int (*write)(struct mpr_data *data, const u8 cmd, const u8 cnt);
93 };
94 
95 int mpr_common_probe(struct device *dev, const struct mpr_ops *ops, int irq);
96 
97 #endif
98