Lines Matching +full:rx +full:- +full:device

1 // SPDX-License-Identifier: GPL-2.0-or-later
14 #include <linux/hwmon-sysfs.h>
17 #include <linux/device.h>
29 * struct sht21 - SHT21 device specific data
30 * @client: I2C client device
49 * sht21_temp_ticks_to_millicelsius() - convert raw temperature ticks to
57 * Formula T = -46.85 + 175.72 * ST / 2^16 from data sheet 6.2, in sht21_temp_ticks_to_millicelsius()
60 return ((21965 * ticks) >> 13) - 46850; in sht21_temp_ticks_to_millicelsius()
64 * sht21_rh_ticks_to_per_cent_mille() - convert raw humidity ticks to
65 * one-thousandths of a percent relative humidity
72 * Formula RH = -6 + 125 * SRH / 2^16 from data sheet 6.1, in sht21_rh_ticks_to_per_cent_mille()
75 return ((15625 * ticks) >> 13) - 6000; in sht21_rh_ticks_to_per_cent_mille()
79 * sht21_update_measurements() - get updated measurements from device
80 * @dev: device
84 static int sht21_update_measurements(struct device *dev) in sht21_update_measurements()
88 struct i2c_client *client = sht21->client; in sht21_update_measurements()
90 mutex_lock(&sht21->lock); in sht21_update_measurements()
93 * SHT2x should not be active for more than 10% of the time - e.g. in sht21_update_measurements()
96 if (time_after(jiffies, sht21->last_update + HZ / 2) || !sht21->valid) { in sht21_update_measurements()
101 sht21->temperature = sht21_temp_ticks_to_millicelsius(ret); in sht21_update_measurements()
106 sht21->humidity = sht21_rh_ticks_to_per_cent_mille(ret); in sht21_update_measurements()
107 sht21->last_update = jiffies; in sht21_update_measurements()
108 sht21->valid = true; in sht21_update_measurements()
111 mutex_unlock(&sht21->lock); in sht21_update_measurements()
117 * sht21_temperature_show() - show temperature measurement value in sysfs
118 * @dev: device
119 * @attr: device attribute
125 static ssize_t sht21_temperature_show(struct device *dev, in sht21_temperature_show()
135 return sprintf(buf, "%d\n", sht21->temperature); in sht21_temperature_show()
139 * sht21_humidity_show() - show humidity measurement value in sysfs
140 * @dev: device
141 * @attr: device attribute
147 static ssize_t sht21_humidity_show(struct device *dev, in sht21_humidity_show()
156 return sprintf(buf, "%d\n", sht21->humidity); in sht21_humidity_show()
161 struct i2c_client *client = sht21->client; in eic_read()
163 u8 rx[8]; in eic_read() local
167 .addr = client->addr, in eic_read()
173 .addr = client->addr, in eic_read()
176 .buf = rx, in eic_read()
183 ret = i2c_transfer(client->adapter, msgs, 2); in eic_read()
186 eic[2] = rx[0]; in eic_read()
187 eic[3] = rx[2]; in eic_read()
188 eic[4] = rx[4]; in eic_read()
189 eic[5] = rx[6]; in eic_read()
194 ret = i2c_transfer(client->adapter, msgs, 2); in eic_read()
197 eic[0] = rx[3]; in eic_read()
198 eic[1] = rx[4]; in eic_read()
199 eic[6] = rx[0]; in eic_read()
200 eic[7] = rx[1]; in eic_read()
202 ret = snprintf(sht21->eic, sizeof(sht21->eic), "%8phN\n", eic); in eic_read()
205 sht21->eic[0] = 0; in eic_read()
211 * eic_show() - show Electronic Identification Code in sysfs
212 * @dev: device
213 * @attr: device attribute
219 static ssize_t eic_show(struct device *dev, in eic_show()
226 ret = sizeof(sht21->eic) - 1; in eic_show()
227 mutex_lock(&sht21->lock); in eic_show()
228 if (!sht21->eic[0]) in eic_show()
231 memcpy(buf, sht21->eic, ret); in eic_show()
232 mutex_unlock(&sht21->lock); in eic_show()
252 struct device *dev = &client->dev; in sht21_probe()
253 struct device *hwmon_dev; in sht21_probe()
256 if (!i2c_check_functionality(client->adapter, in sht21_probe()
258 dev_err(&client->dev, in sht21_probe()
260 return -ENODEV; in sht21_probe()
265 return -ENOMEM; in sht21_probe()
267 sht21->client = client; in sht21_probe()
269 mutex_init(&sht21->lock); in sht21_probe()
271 hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, in sht21_probe()
276 /* Device ID table */