1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* 3 * Measurements Specialties common sensor driver 4 * 5 * Copyright (c) 2015 Measurement-Specialties 6 */ 7 8 #ifndef _MS_SENSORS_I2C_H 9 #define _MS_SENSORS_I2C_H 10 11 #include <linux/i2c.h> 12 #include <linux/mutex.h> 13 14 #define MS_SENSORS_TP_PROM_WORDS_NB 8 15 16 /** 17 * struct ms_ht_dev - Humidity/Temperature sensor device structure 18 * @client: i2c client 19 * @lock: lock protecting the i2c conversion 20 * @res_index: index to selected sensor resolution 21 */ 22 struct ms_ht_dev { 23 struct i2c_client *client; 24 struct mutex lock; 25 u8 res_index; 26 }; 27 28 /** 29 * struct ms_hw_data - Temperature/Pressure sensor hardware data 30 * @prom_len: number of words in the PROM 31 * @max_res_index: maximum sensor resolution index 32 */ 33 struct ms_tp_hw_data { 34 u8 prom_len; 35 u8 max_res_index; 36 }; 37 38 /** 39 * struct ms_tp_dev - Temperature/Pressure sensor device structure 40 * @client: i2c client 41 * @lock: lock protecting the i2c conversion 42 * @prom: array of PROM coefficients used for conversion. Added element 43 * for CRC computation 44 * @res_index: index to selected sensor resolution 45 */ 46 struct ms_tp_dev { 47 struct i2c_client *client; 48 struct mutex lock; 49 const struct ms_tp_hw_data *hw; 50 u16 prom[MS_SENSORS_TP_PROM_WORDS_NB]; 51 u8 res_index; 52 }; 53 54 int ms_sensors_reset(void *cli, u8 cmd, unsigned int delay); 55 int ms_sensors_read_prom_word(void *cli, int cmd, u16 *word); 56 int ms_sensors_convert_and_read(void *cli, u8 conv, u8 rd, 57 unsigned int delay, u32 *adc); 58 int ms_sensors_read_serial(struct i2c_client *client, u64 *sn); 59 ssize_t ms_sensors_show_serial(struct ms_ht_dev *dev_data, char *buf); 60 ssize_t ms_sensors_write_resolution(struct ms_ht_dev *dev_data, u8 i); 61 ssize_t ms_sensors_show_battery_low(struct ms_ht_dev *dev_data, char *buf); 62 ssize_t ms_sensors_show_heater(struct ms_ht_dev *dev_data, char *buf); 63 ssize_t ms_sensors_write_heater(struct ms_ht_dev *dev_data, 64 const char *buf, size_t len); 65 int ms_sensors_ht_read_temperature(struct ms_ht_dev *dev_data, 66 s32 *temperature); 67 int ms_sensors_ht_read_humidity(struct ms_ht_dev *dev_data, 68 u32 *humidity); 69 int ms_sensors_tp_read_prom(struct ms_tp_dev *dev_data); 70 int ms_sensors_read_temp_and_pressure(struct ms_tp_dev *dev_data, 71 int *temperature, 72 unsigned int *pressure); 73 74 #endif /* _MS_SENSORS_I2C_H */ 75