Lines Matching +full:alarm +full:- +full:pol
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * ds1621.c - Part of lm_sensors, Linux kernel modules for hardware
5 * Christian W. Zuckschwerdt <zany@triq.net> 2000-11-23
10 * The DS1621 device is a digital temperature/thermometer with 9-bit
11 * resolution, a thermal alarm output (Tout), and user-defined minimum
30 #include <linux/hwmon-sysfs.h>
40 static int polarity = -1;
47 * - DS1621:
49 * |Done|THF |TLF |NVB | X | X |POL |1SHOT|
51 * - DS1625:
53 * |Done|THF |TLF |NVB | 1 | 0 |POL |1SHOT|
55 * - DS1631, DS1731:
57 * |Done|THF |TLF |NVB | R1 | R0 |POL |1SHOT|
59 * - DS1721:
61 * |Done| X | X | U | R1 | R0 |POL |1SHOT|
64 * - 'X' is Reserved
65 * - 'U' is Undefined
77 94, /* 9-bits (0.5, 93.75, RES[0..1] = 0 */
78 188, /* 10-bits (0.25, 187.5, RES[0..1] = 1 */
79 375, /* 11-bits (0.125, 375, RES[0..1] = 2 */
80 750, /* 12-bits (0.0625, 750, RES[0..1] = 3 */
87 #define DS1621_TEMP_MIN (-55000)
129 * TEMP: 0.001C/bit (-55C to +125C)
131 * - 1621, 1625: 0.5C/bit, 7 zero-bits
132 * - 1631, 1721, 1731: 0.0625C/bit, 4 zero-bits
137 temp = DIV_ROUND_CLOSEST(temp * (1 << (8 - zbits)), 1000) << zbits; in DS1621_TEMP_TO_REG()
159 switch (data->kind) { in ds1621_init_client()
161 data->update_interval = DS1625_CONVERSION_MAX; in ds1621_init_client()
162 data->zbits = 7; in ds1621_init_client()
170 data->update_interval = ds1721_convrates[resol]; in ds1621_init_client()
171 data->zbits = 7 - resol; in ds1621_init_client()
175 data->update_interval = DS1621_CONVERSION_MAX; in ds1621_init_client()
176 data->zbits = 7; in ds1621_init_client()
188 struct i2c_client *client = data->client; in ds1621_update_client()
191 mutex_lock(&data->update_lock); in ds1621_update_client()
193 if (time_after(jiffies, data->last_updated + data->update_interval) || in ds1621_update_client()
194 !data->valid) { in ds1621_update_client()
197 dev_dbg(&client->dev, "Starting ds1621 update\n"); in ds1621_update_client()
199 data->conf = i2c_smbus_read_byte_data(client, DS1621_REG_CONF); in ds1621_update_client()
201 for (i = 0; i < ARRAY_SIZE(data->temp); i++) in ds1621_update_client()
202 data->temp[i] = i2c_smbus_read_word_swapped(client, in ds1621_update_client()
206 new_conf = data->conf; in ds1621_update_client()
207 if (data->temp[0] > data->temp[1]) /* input > min */ in ds1621_update_client()
209 if (data->temp[0] < data->temp[2]) /* input < max */ in ds1621_update_client()
211 if (data->conf != new_conf) in ds1621_update_client()
215 data->last_updated = jiffies; in ds1621_update_client()
216 data->valid = true; in ds1621_update_client()
219 mutex_unlock(&data->update_lock); in ds1621_update_client()
230 DS1621_TEMP_FROM_REG(data->temp[attr->index])); in temp_show()
245 mutex_lock(&data->update_lock); in temp_store()
246 data->temp[attr->index] = DS1621_TEMP_TO_REG(val, data->zbits); in temp_store()
247 i2c_smbus_write_word_swapped(data->client, DS1621_REG_TEMP[attr->index], in temp_store()
248 data->temp[attr->index]); in temp_store()
249 mutex_unlock(&data->update_lock); in temp_store()
257 return sprintf(buf, "%d\n", ALARMS_FROM_REG(data->conf)); in alarms_show()
265 return sprintf(buf, "%d\n", !!(data->conf & attr->index)); in alarm_show()
272 return sysfs_emit(buf, "%hu\n", data->update_interval); in update_interval_show()
280 struct i2c_client *client = data->client; in update_interval_store()
290 while (resol < (ARRAY_SIZE(ds1721_convrates) - 1) && in update_interval_store()
294 mutex_lock(&data->update_lock); in update_interval_store()
295 data->conf = i2c_smbus_read_byte_data(client, DS1621_REG_CONF); in update_interval_store()
296 data->conf &= ~DS1621_REG_CONFIG_RESOL; in update_interval_store()
297 data->conf |= (resol << DS1621_REG_CONFIG_RESOL_SHIFT); in update_interval_store()
298 i2c_smbus_write_byte_data(client, DS1621_REG_CONF, data->conf); in update_interval_store()
299 data->update_interval = ds1721_convrates[resol]; in update_interval_store()
300 data->zbits = 7 - resol; in update_interval_store()
301 mutex_unlock(&data->update_lock); in update_interval_store()
312 static SENSOR_DEVICE_ATTR_RO(temp1_min_alarm, alarm, DS1621_ALARM_TEMP_LOW);
313 static SENSOR_DEVICE_ATTR_RO(temp1_max_alarm, alarm, DS1621_ALARM_TEMP_HIGH);
333 if (data->kind == ds1621 || data->kind == ds1625) in ds1621_attribute_visible()
336 return attr->mode; in ds1621_attribute_visible()
350 data = devm_kzalloc(&client->dev, sizeof(struct ds1621_data), in ds1621_probe()
353 return -ENOMEM; in ds1621_probe()
355 mutex_init(&data->update_lock); in ds1621_probe()
357 data->kind = (uintptr_t)i2c_get_match_data(client); in ds1621_probe()
358 data->client = client; in ds1621_probe()
363 hwmon_dev = devm_hwmon_device_register_with_groups(&client->dev, in ds1621_probe()
364 client->name, data, in ds1621_probe()