Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * Measurements Specialties common sensor driver
0004  *
0005  * Copyright (c) 2015 Measurement-Specialties
0006  */
0007 
0008 #ifndef _MS_SENSORS_I2C_H
0009 #define _MS_SENSORS_I2C_H
0010 
0011 #include <linux/i2c.h>
0012 #include <linux/mutex.h>
0013 
0014 #define MS_SENSORS_TP_PROM_WORDS_NB     8
0015 
0016 /**
0017  * struct ms_ht_dev - Humidity/Temperature sensor device structure
0018  * @client: i2c client
0019  * @lock:   lock protecting the i2c conversion
0020  * @res_index:  index to selected sensor resolution
0021  */
0022 struct ms_ht_dev {
0023     struct i2c_client *client;
0024     struct mutex lock;
0025     u8 res_index;
0026 };
0027 
0028 /**
0029  * struct ms_hw_data - Temperature/Pressure sensor hardware data
0030  * @prom_len:       number of words in the PROM
0031  * @max_res_index:  maximum sensor resolution index
0032  */
0033 struct ms_tp_hw_data {
0034     u8 prom_len;
0035     u8 max_res_index;
0036 };
0037 
0038 /**
0039  * struct ms_tp_dev - Temperature/Pressure sensor device structure
0040  * @client: i2c client
0041  * @lock:   lock protecting the i2c conversion
0042  * @prom:   array of PROM coefficients used for conversion. Added element
0043  *              for CRC computation
0044  * @res_index:  index to selected sensor resolution
0045  */
0046 struct ms_tp_dev {
0047     struct i2c_client *client;
0048     struct mutex lock;
0049     const struct ms_tp_hw_data *hw;
0050     u16 prom[MS_SENSORS_TP_PROM_WORDS_NB];
0051     u8 res_index;
0052 };
0053 
0054 int ms_sensors_reset(void *cli, u8 cmd, unsigned int delay);
0055 int ms_sensors_read_prom_word(void *cli, int cmd, u16 *word);
0056 int ms_sensors_convert_and_read(void *cli, u8 conv, u8 rd,
0057                 unsigned int delay, u32 *adc);
0058 int ms_sensors_read_serial(struct i2c_client *client, u64 *sn);
0059 ssize_t ms_sensors_show_serial(struct ms_ht_dev *dev_data, char *buf);
0060 ssize_t ms_sensors_write_resolution(struct ms_ht_dev *dev_data, u8 i);
0061 ssize_t ms_sensors_show_battery_low(struct ms_ht_dev *dev_data, char *buf);
0062 ssize_t ms_sensors_show_heater(struct ms_ht_dev *dev_data, char *buf);
0063 ssize_t ms_sensors_write_heater(struct ms_ht_dev *dev_data,
0064                 const char *buf, size_t len);
0065 int ms_sensors_ht_read_temperature(struct ms_ht_dev *dev_data,
0066                    s32 *temperature);
0067 int ms_sensors_ht_read_humidity(struct ms_ht_dev *dev_data,
0068                 u32 *humidity);
0069 int ms_sensors_tp_read_prom(struct ms_tp_dev *dev_data);
0070 int ms_sensors_read_temp_and_pressure(struct ms_tp_dev *dev_data,
0071                       int *temperature,
0072                       unsigned int *pressure);
0073 
0074 #endif /* _MS_SENSORS_I2C_H */