blob: 51d021966222f572dd4300a1f77c3ea0d5385d50 [file] [log] [blame]
Lorenzo Bianconie4a70e32016-10-13 22:06:04 +02001/*
2 * STMicroelectronics hts221 sensor driver
3 *
4 * Copyright 2016 STMicroelectronics Inc.
5 *
6 * Lorenzo Bianconi <lorenzo.bianconi@st.com>
7 *
8 * Licensed under the GPL-2.
9 */
10
11#ifndef HTS221_H
12#define HTS221_H
13
14#define HTS221_DEV_NAME "hts221"
15
16#include <linux/iio/iio.h>
17
18#define HTS221_RX_MAX_LENGTH 8
19#define HTS221_TX_MAX_LENGTH 8
20
21#define HTS221_DATA_SIZE 2
22
23struct hts221_transfer_buffer {
24 u8 rx_buf[HTS221_RX_MAX_LENGTH];
25 u8 tx_buf[HTS221_TX_MAX_LENGTH] ____cacheline_aligned;
26};
27
28struct hts221_transfer_function {
29 int (*read)(struct device *dev, u8 addr, int len, u8 *data);
30 int (*write)(struct device *dev, u8 addr, int len, u8 *data);
31};
32
Lorenzo Bianconie4a70e32016-10-13 22:06:04 +020033enum hts221_sensor_type {
34 HTS221_SENSOR_H,
35 HTS221_SENSOR_T,
36 HTS221_SENSOR_MAX,
37};
38
39struct hts221_sensor {
40 u8 cur_avg_idx;
41 int slope, b_gen;
42};
43
44struct hts221_hw {
45 const char *name;
46 struct device *dev;
47
48 struct mutex lock;
49 struct iio_trigger *trig;
50 int irq;
51
52 struct hts221_sensor sensors[HTS221_SENSOR_MAX];
53
Lorenzo Bianconib7079ee2017-05-14 17:45:44 +020054 bool enabled;
Lorenzo Bianconie4a70e32016-10-13 22:06:04 +020055 u8 odr;
56
57 const struct hts221_transfer_function *tf;
58 struct hts221_transfer_buffer tb;
59};
60
Lorenzo Bianconib7079ee2017-05-14 17:45:44 +020061extern const struct dev_pm_ops hts221_pm_ops;
62
Lorenzo Bianconie7b4b452017-07-17 19:39:01 +020063int hts221_write_with_mask(struct hts221_hw *hw, u8 addr, u8 mask, u8 val);
Lorenzo Bianconie4a70e32016-10-13 22:06:04 +020064int hts221_probe(struct iio_dev *iio_dev);
Lorenzo Bianconie3e25442017-07-17 19:39:00 +020065int hts221_set_enable(struct hts221_hw *hw, bool enable);
Lorenzo Bianconie4a70e32016-10-13 22:06:04 +020066int hts221_allocate_buffers(struct hts221_hw *hw);
67int hts221_allocate_trigger(struct hts221_hw *hw);
68
69#endif /* HTS221_H */