Tomasz Duszynski | c064416 | 2015-03-14 21:29:31 +0100 | [diff] [blame] | 1 | /* |
| 2 | * MS5611 pressure and temperature sensor driver |
| 3 | * |
| 4 | * Copyright (c) Tomasz Duszynski <tduszyns@gmail.com> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 as |
| 8 | * published by the Free Software Foundation. |
| 9 | * |
| 10 | */ |
| 11 | |
| 12 | #ifndef _MS5611_H |
| 13 | #define _MS5611_H |
| 14 | |
| 15 | #include <linux/device.h> |
| 16 | #include <linux/iio/iio.h> |
| 17 | #include <linux/mutex.h> |
| 18 | |
Gregor Boirie | 334ecdd | 2016-03-17 12:55:03 +0100 | [diff] [blame] | 19 | struct regulator; |
| 20 | |
Tomasz Duszynski | c064416 | 2015-03-14 21:29:31 +0100 | [diff] [blame] | 21 | #define MS5611_RESET 0x1e |
| 22 | #define MS5611_READ_ADC 0x00 |
| 23 | #define MS5611_READ_PROM_WORD 0xA0 |
Tomasz Duszynski | c064416 | 2015-03-14 21:29:31 +0100 | [diff] [blame] | 24 | #define MS5611_PROM_WORDS_NB 8 |
| 25 | |
Tomasz Duszynski | 9690d81a | 2015-06-23 20:45:48 +0200 | [diff] [blame] | 26 | enum { |
| 27 | MS5611, |
| 28 | MS5607, |
| 29 | }; |
| 30 | |
| 31 | struct ms5611_chip_info { |
| 32 | u16 prom[MS5611_PROM_WORDS_NB]; |
| 33 | |
| 34 | int (*temp_and_pressure_compensate)(struct ms5611_chip_info *chip_info, |
| 35 | s32 *temp, s32 *pressure); |
| 36 | }; |
| 37 | |
Gregor Boirie | 033691a | 2016-03-01 11:31:38 +0100 | [diff] [blame] | 38 | /* |
| 39 | * OverSampling Rate descriptor. |
| 40 | * Warning: cmd MUST be kept aligned on a word boundary (see |
| 41 | * m5611_spi_read_adc_temp_and_pressure in ms5611_spi.c). |
| 42 | */ |
| 43 | struct ms5611_osr { |
| 44 | unsigned long conv_usec; |
| 45 | u8 cmd; |
| 46 | unsigned short rate; |
| 47 | }; |
| 48 | |
Tomasz Duszynski | c064416 | 2015-03-14 21:29:31 +0100 | [diff] [blame] | 49 | struct ms5611_state { |
| 50 | void *client; |
| 51 | struct mutex lock; |
| 52 | |
Gregor Boirie | 033691a | 2016-03-01 11:31:38 +0100 | [diff] [blame] | 53 | const struct ms5611_osr *pressure_osr; |
| 54 | const struct ms5611_osr *temp_osr; |
| 55 | |
Tomasz Duszynski | c064416 | 2015-03-14 21:29:31 +0100 | [diff] [blame] | 56 | int (*reset)(struct device *dev); |
| 57 | int (*read_prom_word)(struct device *dev, int index, u16 *word); |
| 58 | int (*read_adc_temp_and_pressure)(struct device *dev, |
| 59 | s32 *temp, s32 *pressure); |
| 60 | |
Tomasz Duszynski | 9690d81a | 2015-06-23 20:45:48 +0200 | [diff] [blame] | 61 | struct ms5611_chip_info *chip_info; |
Gregor Boirie | 334ecdd | 2016-03-17 12:55:03 +0100 | [diff] [blame] | 62 | struct regulator *vdd; |
Tomasz Duszynski | c064416 | 2015-03-14 21:29:31 +0100 | [diff] [blame] | 63 | }; |
| 64 | |
Grégor Boirie | eac635e | 2016-02-17 18:52:50 +0100 | [diff] [blame] | 65 | int ms5611_probe(struct iio_dev *indio_dev, struct device *dev, |
| 66 | const char* name, int type); |
Daniel Baluta | 713bbb4 | 2016-02-03 18:50:38 +0200 | [diff] [blame] | 67 | int ms5611_remove(struct iio_dev *indio_dev); |
Tomasz Duszynski | c064416 | 2015-03-14 21:29:31 +0100 | [diff] [blame] | 68 | |
| 69 | #endif /* _MS5611_H */ |