Tomasz Duszynski | 6cfdb15 | 2018-09-01 21:52:14 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Tomasz Duszynski | c0644160a | 2015-03-14 21:29:31 +0100 | [diff] [blame] | 2 | /* |
| 3 | * MS5611 pressure and temperature sensor driver |
| 4 | * |
| 5 | * Copyright (c) Tomasz Duszynski <tduszyns@gmail.com> |
| 6 | * |
Tomasz Duszynski | c0644160a | 2015-03-14 21:29:31 +0100 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #ifndef _MS5611_H |
| 10 | #define _MS5611_H |
| 11 | |
| 12 | #include <linux/device.h> |
| 13 | #include <linux/iio/iio.h> |
| 14 | #include <linux/mutex.h> |
| 15 | |
Gregor Boirie | 334ecdd | 2016-03-17 12:55:03 +0100 | [diff] [blame] | 16 | struct regulator; |
| 17 | |
Tomasz Duszynski | c0644160a | 2015-03-14 21:29:31 +0100 | [diff] [blame] | 18 | #define MS5611_RESET 0x1e |
| 19 | #define MS5611_READ_ADC 0x00 |
| 20 | #define MS5611_READ_PROM_WORD 0xA0 |
Tomasz Duszynski | c0644160a | 2015-03-14 21:29:31 +0100 | [diff] [blame] | 21 | #define MS5611_PROM_WORDS_NB 8 |
| 22 | |
Tomasz Duszynski | 9690d81a | 2015-06-23 20:45:48 +0200 | [diff] [blame] | 23 | enum { |
| 24 | MS5611, |
| 25 | MS5607, |
| 26 | }; |
| 27 | |
| 28 | struct ms5611_chip_info { |
| 29 | u16 prom[MS5611_PROM_WORDS_NB]; |
| 30 | |
| 31 | int (*temp_and_pressure_compensate)(struct ms5611_chip_info *chip_info, |
| 32 | s32 *temp, s32 *pressure); |
| 33 | }; |
| 34 | |
Gregor Boirie | 033691a9 | 2016-03-01 11:31:38 +0100 | [diff] [blame] | 35 | /* |
| 36 | * OverSampling Rate descriptor. |
| 37 | * Warning: cmd MUST be kept aligned on a word boundary (see |
| 38 | * m5611_spi_read_adc_temp_and_pressure in ms5611_spi.c). |
| 39 | */ |
| 40 | struct ms5611_osr { |
| 41 | unsigned long conv_usec; |
| 42 | u8 cmd; |
| 43 | unsigned short rate; |
| 44 | }; |
| 45 | |
Tomasz Duszynski | c0644160a | 2015-03-14 21:29:31 +0100 | [diff] [blame] | 46 | struct ms5611_state { |
| 47 | void *client; |
| 48 | struct mutex lock; |
| 49 | |
Gregor Boirie | 033691a9 | 2016-03-01 11:31:38 +0100 | [diff] [blame] | 50 | const struct ms5611_osr *pressure_osr; |
| 51 | const struct ms5611_osr *temp_osr; |
| 52 | |
Lars-Peter Clausen | dc19fa6 | 2021-10-20 16:21:10 +0200 | [diff] [blame] | 53 | int (*reset)(struct ms5611_state *st); |
| 54 | int (*read_prom_word)(struct ms5611_state *st, int index, u16 *word); |
| 55 | int (*read_adc_temp_and_pressure)(struct ms5611_state *st, |
Tomasz Duszynski | c0644160a | 2015-03-14 21:29:31 +0100 | [diff] [blame] | 56 | s32 *temp, s32 *pressure); |
| 57 | |
Tomasz Duszynski | 9690d81a | 2015-06-23 20:45:48 +0200 | [diff] [blame] | 58 | struct ms5611_chip_info *chip_info; |
Gregor Boirie | 334ecdd | 2016-03-17 12:55:03 +0100 | [diff] [blame] | 59 | struct regulator *vdd; |
Tomasz Duszynski | c0644160a | 2015-03-14 21:29:31 +0100 | [diff] [blame] | 60 | }; |
| 61 | |
Grégor Boirie | eac635e | 2016-02-17 18:52:50 +0100 | [diff] [blame] | 62 | int ms5611_probe(struct iio_dev *indio_dev, struct device *dev, |
rodrigosiqueira | 1482705 | 2018-02-16 17:44:41 -0200 | [diff] [blame] | 63 | const char *name, int type); |
Uwe Kleine-König | f840cbe | 2021-10-13 22:32:23 +0200 | [diff] [blame] | 64 | void ms5611_remove(struct iio_dev *indio_dev); |
Tomasz Duszynski | c0644160a | 2015-03-14 21:29:31 +0100 | [diff] [blame] | 65 | |
| 66 | #endif /* _MS5611_H */ |