Lines Matching +full:multi +full:- +full:attr

1 // SPDX-License-Identifier: GPL-2.0-only
6 * sht4x.c - Linux hwmon driver for SHT4x Temperature and Humidity sensor
14 #include <linux/hwmon-sysfs.h>
48 #define SHT4X_MIN_TEMPERATURE -45000
56 * struct sht4x_data - All the data required to operate an SHT4X chip
74 u32 heater_power; /* in milli-watts */
75 u32 heater_time; /* in milli-seconds */
77 long update_interval; /* in milli-seconds */
84 * sht4x_read_values() - read and parse the raw data from the SHT4X
86 * Return: 0 if successful, -ERRNO if not
93 struct i2c_client *client = data->client; in sht4x_read_values()
99 mutex_lock(&data->lock); in sht4x_read_values()
102 if (time_before(curr_jiffies, data->heating_complete)) in sht4x_read_values()
103 msleep(jiffies_to_msecs(data->heating_complete - curr_jiffies)); in sht4x_read_values()
105 if (data->data_pending && in sht4x_read_values()
106 time_before(jiffies, data->heating_complete + data->update_interval)) { in sht4x_read_values()
107 data->data_pending = false; in sht4x_read_values()
109 next_update = data->last_updated + in sht4x_read_values()
110 msecs_to_jiffies(data->update_interval); in sht4x_read_values()
112 if (data->valid && time_before_eq(jiffies, next_update)) in sht4x_read_values()
125 ret = -ENODATA; in sht4x_read_values()
134 dev_err(&client->dev, "data integrity check failed\n"); in sht4x_read_values()
135 ret = -EIO; in sht4x_read_values()
141 dev_err(&client->dev, "data integrity check failed\n"); in sht4x_read_values()
142 ret = -EIO; in sht4x_read_values()
146 data->temperature = ((21875 * (int32_t)t_ticks) >> 13) - 45000; in sht4x_read_values()
147 data->humidity = ((15625 * (int32_t)rh_ticks) >> 13) - 6000; in sht4x_read_values()
148 data->last_updated = jiffies; in sht4x_read_values()
149 data->valid = true; in sht4x_read_values()
153 mutex_unlock(&data->lock); in sht4x_read_values()
159 data->update_interval = clamp_val(val, SHT4X_MIN_POLL_INTERVAL, INT_MAX); in sht4x_interval_write()
164 /* sht4x_interval_read() - read the minimum poll interval in milliseconds */
167 *val = data->update_interval; in sht4x_interval_read()
171 /* sht4x_temperature1_read() - read the temperature in millidegrees */
180 *val = data->temperature; in sht4x_temperature1_read()
185 /* sht4x_humidity1_read() - read a relative humidity in millipercent */
194 *val = data->humidity; in sht4x_humidity1_read()
201 u32 attr, int channel) in sht4x_hwmon_visible() argument
215 u32 attr, int channel, long *val) in sht4x_hwmon_read() argument
227 return -EOPNOTSUPP; in sht4x_hwmon_read()
232 u32 attr, int channel, long val) in sht4x_hwmon_write() argument
240 return -EOPNOTSUPP; in sht4x_hwmon_write()
245 struct device_attribute *attr, in heater_enable_show() argument
250 return sysfs_emit(buf, "%u\n", time_before(jiffies, data->heating_complete)); in heater_enable_show()
254 struct device_attribute *attr, in heater_enable_store() argument
268 return -EINVAL; in heater_enable_store()
270 if (data->heater_time == 100) { in heater_enable_store()
271 if (data->heater_power == 20) in heater_enable_store()
273 else if (data->heater_power == 110) in heater_enable_store()
275 else /* data->heater_power == 200 */ in heater_enable_store()
279 } else { /* data->heater_time == 1000 */ in heater_enable_store()
280 if (data->heater_power == 20) in heater_enable_store()
282 else if (data->heater_power == 110) in heater_enable_store()
284 else /* data->heater_power == 200 */ in heater_enable_store()
290 mutex_lock(&data->lock); in heater_enable_store()
292 if (time_before(jiffies, data->heating_complete)) { in heater_enable_store()
293 ret = -EBUSY; in heater_enable_store()
297 ret = i2c_master_send(data->client, &cmd, SHT4X_CMD_LEN); in heater_enable_store()
301 data->heating_complete = jiffies + msecs_to_jiffies(heating_time_bound); in heater_enable_store()
302 data->data_pending = true; in heater_enable_store()
304 mutex_unlock(&data->lock); in heater_enable_store()
309 struct device_attribute *attr, in heater_power_show() argument
314 return sysfs_emit(buf, "%u\n", data->heater_power); in heater_power_show()
318 struct device_attribute *attr, in heater_power_store() argument
331 return -EINVAL; in heater_power_store()
333 data->heater_power = power; in heater_power_store()
339 struct device_attribute *attr, in heater_time_show() argument
344 return sysfs_emit(buf, "%u\n", data->heater_time); in heater_time_show()
348 struct device_attribute *attr, in heater_time_store() argument
361 return -EINVAL; in heater_time_store()
363 data->heater_time = time; in heater_time_store()
373 &dev_attr_heater_enable.attr,
374 &dev_attr_heater_power.attr,
375 &dev_attr_heater_time.attr,
401 struct device *device = &client->dev; in sht4x_probe()
408 * we require full i2c support since the sht4x uses multi-byte read and in sht4x_probe()
409 * writes as well as multi-byte commands which are not supported by in sht4x_probe()
412 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) in sht4x_probe()
413 return -EOPNOTSUPP; in sht4x_probe()
417 return -ENOMEM; in sht4x_probe()
419 data->update_interval = SHT4X_MIN_POLL_INTERVAL; in sht4x_probe()
420 data->client = client; in sht4x_probe()
421 data->heater_power = 200; in sht4x_probe()
422 data->heater_time = 1000; in sht4x_probe()
423 data->heating_complete = jiffies; in sht4x_probe()
425 mutex_init(&data->lock); in sht4x_probe()
433 return -EIO; in sht4x_probe()
436 client->name, in sht4x_probe()