#include <linux/module.h>
#include <linux/iio/iio.h>
#include <linux/iio/sysfs.h>
#include <linux/util_macros.h>
#define HP206C_CMD_SOFT_RST 0x06
#define HP206C_CMD_ADC_CVT 0x40
#define HP206C_CMD_ADC_CVT_OSR_4096 0x00
#define HP206C_CMD_ADC_CVT_OSR_2048 0x04
#define HP206C_CMD_ADC_CVT_OSR_1024 0x08
#define HP206C_CMD_ADC_CVT_OSR_512 0x0c
#define HP206C_CMD_ADC_CVT_OSR_256 0x10
#define HP206C_CMD_ADC_CVT_OSR_128 0x14
#define HP206C_CMD_ADC_CVT_CHNL_PT 0x00
#define HP206C_CMD_ADC_CVT_CHNL_T 0x02
#define HP206C_CMD_READ_P 0x30
#define HP206C_CMD_READ_T 0x32
#define HP206C_CMD_READ_REG 0x80
#define HP206C_CMD_WRITE_REG 0xc0
#define HP206C_REG_INT_EN 0x0b
#define HP206C_REG_INT_CFG 0x0c
#define HP206C_REG_INT_SRC 0x0d
#define HP206C_FLAG_DEV_RDY 0x40
#define HP206C_REG_PARA 0x0f
#define HP206C_FLAG_CMPS_EN 0x80
#define HP206C_MAX_DEV_RDY_WAIT_COUNT 20
#define HP206C_DEV_RDY_WAIT_US 20000
struct i2c_client *client;
struct hp206c_osr_setting {
unsigned int temp_conv_time_us;
unsigned int pres_conv_time_us;
static const struct hp206c_osr_setting hp206c_osr_settings[] = {
{ HP206C_CMD_ADC_CVT_OSR_4096, 65600, 131100 },
{ HP206C_CMD_ADC_CVT_OSR_2048, 32800, 65600 },
{ HP206C_CMD_ADC_CVT_OSR_1024, 16400, 32800 },
{ HP206C_CMD_ADC_CVT_OSR_512, 8200, 16400 },
{ HP206C_CMD_ADC_CVT_OSR_256, 4100, 8200 },
{ HP206C_CMD_ADC_CVT_OSR_128, 2100, 4100 },
static const int hp206c_osr_rates[] = { 4096, 2048, 1024, 512, 256, 128 };
static const char hp206c_osr_rates_str[] = "4096 2048 1024 512 256 128";
static inline int hp206c_read_reg(struct i2c_client *client, u8 reg)
return i2c_smbus_read_byte_data(client, HP206C_CMD_READ_REG | reg);
static inline int hp206c_write_reg(struct i2c_client *client, u8 reg, u8 val)
return i2c_smbus_write_byte_data(client,
HP206C_CMD_WRITE_REG | reg, val);