1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * Honeywell TruStability HSC Series pressure/temperature sensor
4 *
5 * Copyright (c) 2023 Petre Rodan <petre.rodan@subdimension.ro>
6 */
7
8#ifndef _HSC030PA_H
9#define _HSC030PA_H
10
11#include <linux/types.h>
12
13#include <linux/iio/iio.h>
14
15#define HSC_REG_MEASUREMENT_RD_SIZE 4
16#define HSC_RESP_TIME_MS 2
17
18struct device;
19
20struct iio_chan_spec;
21struct iio_dev;
22
23struct hsc_data;
24struct hsc_chip_data;
25
26typedef int (*hsc_recv_fn)(struct hsc_data *);
27
28/**
29 * struct hsc_data
30 * @dev: current device structure
31 * @chip: structure containing chip's channel properties
32 * @recv_cb: function that implements the chip reads
33 * @is_valid: true if last transfer has been validated
34 * @pmin: minimum measurable pressure limit
35 * @pmax: maximum measurable pressure limit
36 * @outmin: minimum raw pressure in counts (based on transfer function)
37 * @outmax: maximum raw pressure in counts (based on transfer function)
38 * @function: transfer function
39 * @p_scale: pressure scale
40 * @p_scale_dec: pressure scale, decimal places
41 * @p_offset: pressure offset
42 * @p_offset_dec: pressure offset, decimal places
43 * @buffer: raw conversion data
44 */
45struct hsc_data {
46 struct device *dev;
47 const struct hsc_chip_data *chip;
48 hsc_recv_fn recv_cb;
49 bool is_valid;
50 s32 pmin;
51 s32 pmax;
52 u32 outmin;
53 u32 outmax;
54 u32 function;
55 s64 p_scale;
56 s32 p_scale_dec;
57 s64 p_offset;
58 s32 p_offset_dec;
59 struct {
60 __be16 chan[2];
61 s64 timestamp __aligned(8);
62 } scan;
63 u8 buffer[HSC_REG_MEASUREMENT_RD_SIZE] __aligned(IIO_DMA_MINALIGN);
64};
65
66struct hsc_chip_data {
67 bool (*valid)(struct hsc_data *data);
68 const struct iio_chan_spec *channels;
69 u8 num_channels;
70};
71
72enum hsc_func_id {
73 HSC_FUNCTION_A,
74 HSC_FUNCTION_B,
75 HSC_FUNCTION_C,
76 HSC_FUNCTION_F,
77};
78
79int hsc_common_probe(struct device *dev, hsc_recv_fn recv);
80
81#endif
82

source code of linux/drivers/iio/pressure/hsc030pa.h