Source
x
MODULE_DESCRIPTION("Sensirion SHT21 humidity and temperature sensor driver");
// SPDX-License-Identifier: GPL-2.0-or-later
/* Sensirion SHT21 humidity and temperature sensor driver
*
* Copyright (C) 2010 Urs Fleisch <urs.fleisch@sensirion.com>
*
* Data sheet available at http://www.sensirion.com/file/datasheet_sht21
*/
/* I2C command bytes */
/**
* struct sht21 - SHT21 device specific data
* @client: I2C client device
* @lock: mutex to protect measurement values
* @last_update: time of last update (jiffies)
* @temperature: cached temperature measurement value
* @humidity: cached humidity measurement value
* @valid: only 0 before first measurement is taken
* @eic: cached electronic identification code text
*/
struct sht21 {
struct i2c_client *client;
struct mutex lock;
unsigned long last_update;
int temperature;
int humidity;
char valid;
char eic[18];
};
/**
* sht21_temp_ticks_to_millicelsius() - convert raw temperature ticks to
* milli celsius
* @ticks: temperature ticks value received from sensor
*/
static inline int sht21_temp_ticks_to_millicelsius(int ticks)
{
ticks &= ~0x0003; /* clear status bits */
/*
* Formula T = -46.85 + 175.72 * ST / 2^16 from data sheet 6.2,
* optimized for integer fixed point (3 digits) arithmetic
*/
return ((21965 * ticks) >> 13) - 46850;
}
/**
* sht21_rh_ticks_to_per_cent_mille() - convert raw humidity ticks to
* one-thousandths of a percent relative humidity
* @ticks: humidity ticks value received from sensor
*/
static inline int sht21_rh_ticks_to_per_cent_mille(int ticks)
{
ticks &= ~0x0003; /* clear status bits */
/*
* Formula RH = -6 + 125 * SRH / 2^16 from data sheet 6.1,
* optimized for integer fixed point (3 digits) arithmetic
*/
return ((15625 * ticks) >> 13) - 6000;
}
/**
* sht21_update_measurements() - get updated measurements from device
* @dev: device
*
* Returns 0 on success, else negative errno.
*/
static int sht21_update_measurements(struct device *dev)
{
int ret = 0;
struct sht21 *sht21 = dev_get_drvdata(dev);
struct i2c_client *client = sht21->client;
mutex_lock(&sht21->lock);
/*
* Data sheet 2.4: