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 /** 38 * struct mpr_chan 39 * @pres: pressure value 40 * @ts: timestamp 41 */ 42 struct mpr_chan { 43 s32 pres; 44 s64 ts; 45 }; 46 47 enum mpr_func_id { 48 MPR_FUNCTION_A, 49 MPR_FUNCTION_B, 50 MPR_FUNCTION_C, 51 }; 52 53 /** 54 * struct mpr_data 55 * @dev: current device structure 56 * @ops: functions that implement the sensor reads/writes, bus init 57 * @lock: access to device during read 58 * @pmin: minimal pressure in pascal 59 * @pmax: maximal pressure in pascal 60 * @function: transfer function 61 * @outmin: minimum raw pressure in counts (based on transfer function) 62 * @outmax: maximum raw pressure in counts (based on transfer function) 63 * @scale: pressure scale 64 * @scale2: pressure scale, decimal number 65 * @offset: pressure offset 66 * @offset2: pressure offset, decimal number 67 * @gpiod_reset: reset 68 * @irq: end of conversion irq. used to distinguish between irq mode and 69 * reading in a loop until data is ready 70 * @completion: handshake from irq to read 71 * @chan: channel values for buffered mode 72 * @buffer: raw conversion data 73 */ 74 struct mpr_data { 75 struct device *dev; 76 const struct mpr_ops *ops; 77 struct mutex lock; 78 u32 pmin; 79 u32 pmax; 80 enum mpr_func_id function; 81 u32 outmin; 82 u32 outmax; 83 int scale; 84 int scale2; 85 int offset; 86 int offset2; 87 struct gpio_desc *gpiod_reset; 88 int irq; 89 struct completion completion; 90 struct mpr_chan chan; 91 u8 buffer[MPR_MEASUREMENT_RD_SIZE] __aligned(IIO_DMA_MINALIGN); 92 }; 93 94 struct mpr_ops { 95 int (*init)(struct device *dev); 96 int (*read)(struct mpr_data *data, const u8 cmd, const u8 cnt); 97 int (*write)(struct mpr_data *data, const u8 cmd, const u8 cnt); 98 }; 99 100 int mpr_common_probe(struct device *dev, const struct mpr_ops *ops, int irq); 101 102 #endif 103