23 #include <linux/module.h>
25 #include <linux/slab.h>
26 #include <linux/i2c.h>
31 #include <linux/device.h>
35 #define SHT21_TRIG_T_MEASUREMENT_HM 0xe3
36 #define SHT21_TRIG_RH_MEASUREMENT_HM 0xe5
61 static inline int sht21_temp_ticks_to_millicelsius(
int ticks)
68 return ((21965 * ticks) >> 13) - 46850;
76 static inline int sht21_rh_ticks_to_per_cent_mille(
int ticks)
83 return ((15625 * ticks) >> 13) - 6000;
95 struct sht21 *
sht21 = i2c_get_clientdata(client);
104 ret = i2c_smbus_read_word_swapped(client,
108 sht21->
temperature = sht21_temp_ticks_to_millicelsius(ret);
109 ret = i2c_smbus_read_word_swapped(client,
113 sht21->
humidity = sht21_rh_ticks_to_per_cent_mille(ret);
120 return ret >= 0 ? 0 :
ret;
137 struct sht21 *sht21 = i2c_get_clientdata(client);
138 int ret = sht21_update_measurements(client);
158 struct sht21 *sht21 = i2c_get_clientdata(client);
159 int ret = sht21_update_measurements(client);
171 static struct attribute *sht21_attributes[] = {
172 &sensor_dev_attr_temp1_input.dev_attr.attr,
173 &sensor_dev_attr_humidity1_input.dev_attr.attr,
178 .attrs = sht21_attributes,
196 if (!i2c_check_functionality(client->
adapter,
199 "adapter does not support SMBus word transactions\n");
207 i2c_set_clientdata(client, sht21);
213 dev_dbg(&client->
dev,
"could not create sysfs files\n");
218 dev_dbg(&client->
dev,
"unable to register hwmon device\n");
220 goto fail_remove_sysfs;
238 struct sht21 *sht21 = i2c_get_clientdata(client);
254 .driver.name =
"sht21",
255 .probe = sht21_probe,
257 .id_table = sht21_id,