Lines Matching +full:temp +full:- +full:alarm

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (c) 2012 Guenter Roeck <linux@roeck-us.net>
15 #include <linux/hwmon-sysfs.h>
38 * Applies to alert register and over-temperature register.
59 #define MAX6581_OFFSET_MIN -31750
79 int update_interval; /* in milli-seconds */
87 u8 temp[8][4]; /* [nr][0]=temp [1]=ext [2]=max [3]=crit */ member
184 struct i2c_client *client = data->client; in max6697_update_device()
190 mutex_lock(&data->update_lock); in max6697_update_device()
192 if (data->valid && in max6697_update_device()
193 !time_after(jiffies, data->last_updated in max6697_update_device()
194 + msecs_to_jiffies(data->update_interval))) in max6697_update_device()
197 for (i = 0; i < data->chip->channels; i++) { in max6697_update_device()
198 if (data->chip->have_ext & (1 << i)) { in max6697_update_device()
205 data->temp[i][MAX6697_TEMP_EXT] = val; in max6697_update_device()
213 data->temp[i][MAX6697_TEMP_INPUT] = val; in max6697_update_device()
220 data->temp[i][MAX6697_TEMP_MAX] = val; in max6697_update_device()
222 if (data->chip->have_crit & (1 << i)) { in max6697_update_device()
229 data->temp[i][MAX6697_TEMP_CRIT] = val; in max6697_update_device()
242 data->alarms = alarms; in max6697_update_device()
243 data->last_updated = jiffies; in max6697_update_device()
244 data->valid = true; in max6697_update_device()
246 mutex_unlock(&data->update_lock); in max6697_update_device()
254 int index = to_sensor_dev_attr(devattr)->index; in temp_input_show()
256 int temp; in temp_input_show() local
261 temp = (data->temp[index][MAX6697_TEMP_INPUT] - data->temp_offset) << 3; in temp_input_show()
262 temp |= data->temp[index][MAX6697_TEMP_EXT] >> 5; in temp_input_show()
264 return sprintf(buf, "%d\n", temp * 125); in temp_input_show()
270 int nr = to_sensor_dev_attr_2(devattr)->nr; in temp_show()
271 int index = to_sensor_dev_attr_2(devattr)->index; in temp_show()
273 int temp; in temp_show() local
278 temp = data->temp[nr][index]; in temp_show()
279 temp -= data->temp_offset; in temp_show()
281 return sprintf(buf, "%d\n", temp * 1000); in temp_show()
287 int index = to_sensor_dev_attr(attr)->index; in alarm_show()
293 if (data->chip->alarm_map) in alarm_show()
294 index = data->chip->alarm_map[index]; in alarm_show()
296 return sprintf(buf, "%u\n", (data->alarms >> index) & 0x1); in alarm_show()
303 int nr = to_sensor_dev_attr_2(devattr)->nr; in temp_store()
304 int index = to_sensor_dev_attr_2(devattr)->index; in temp_store()
306 long temp; in temp_store() local
309 ret = kstrtol(buf, 10, &temp); in temp_store()
313 mutex_lock(&data->update_lock); in temp_store()
314 temp = DIV_ROUND_CLOSEST(temp, 1000) + data->temp_offset; in temp_store()
315 temp = clamp_val(temp, 0, data->type == max6581 ? 255 : 127); in temp_store()
316 data->temp[nr][index] = temp; in temp_store()
317 ret = i2c_smbus_write_byte_data(data->client, in temp_store()
320 temp); in temp_store()
321 mutex_unlock(&data->update_lock); in temp_store()
332 long temp; in offset_store() local
334 index = to_sensor_dev_attr(devattr)->index; in offset_store()
336 ret = kstrtol(buf, 10, &temp); in offset_store()
340 mutex_lock(&data->update_lock); in offset_store()
341 select = i2c_smbus_read_byte_data(data->client, MAX6581_REG_OFFSET_SELECT); in offset_store()
346 channel_enabled = (select & (1 << (index - 1))); in offset_store()
347 temp = clamp_val(temp, MAX6581_OFFSET_MIN, MAX6581_OFFSET_MAX); in offset_store()
348 val = DIV_ROUND_CLOSEST(temp, 250); in offset_store()
352 ret = i2c_smbus_write_byte_data(data->client, MAX6581_REG_OFFSET_SELECT, in offset_store()
353 select & ~(1 << (index - 1))); in offset_store()
358 ret = i2c_smbus_write_byte_data(data->client, MAX6581_REG_OFFSET_SELECT, in offset_store()
359 select | (1 << (index - 1))); in offset_store()
363 ret = i2c_smbus_write_byte_data(data->client, MAX6581_REG_OFFSET, val); in offset_store()
367 mutex_unlock(&data->update_lock); in offset_store()
376 index = to_sensor_dev_attr(devattr)->index; in offset_show()
378 mutex_lock(&data->update_lock); in offset_show()
379 select = i2c_smbus_read_byte_data(data->client, MAX6581_REG_OFFSET_SELECT); in offset_show()
382 else if (select & (1 << (index - 1))) in offset_show()
383 ret = i2c_smbus_read_byte_data(data->client, MAX6581_REG_OFFSET); in offset_show()
386 mutex_unlock(&data->update_lock); in offset_show()
391 static SENSOR_DEVICE_ATTR_2_RW(temp1_max, temp, 0, MAX6697_TEMP_MAX);
392 static SENSOR_DEVICE_ATTR_2_RW(temp1_crit, temp, 0, MAX6697_TEMP_CRIT);
395 static SENSOR_DEVICE_ATTR_2_RW(temp2_max, temp, 1, MAX6697_TEMP_MAX);
396 static SENSOR_DEVICE_ATTR_2_RW(temp2_crit, temp, 1, MAX6697_TEMP_CRIT);
399 static SENSOR_DEVICE_ATTR_2_RW(temp3_max, temp, 2, MAX6697_TEMP_MAX);
400 static SENSOR_DEVICE_ATTR_2_RW(temp3_crit, temp, 2, MAX6697_TEMP_CRIT);
403 static SENSOR_DEVICE_ATTR_2_RW(temp4_max, temp, 3, MAX6697_TEMP_MAX);
404 static SENSOR_DEVICE_ATTR_2_RW(temp4_crit, temp, 3, MAX6697_TEMP_CRIT);
407 static SENSOR_DEVICE_ATTR_2_RW(temp5_max, temp, 4, MAX6697_TEMP_MAX);
408 static SENSOR_DEVICE_ATTR_2_RW(temp5_crit, temp, 4, MAX6697_TEMP_CRIT);
411 static SENSOR_DEVICE_ATTR_2_RW(temp6_max, temp, 5, MAX6697_TEMP_MAX);
412 static SENSOR_DEVICE_ATTR_2_RW(temp6_crit, temp, 5, MAX6697_TEMP_CRIT);
415 static SENSOR_DEVICE_ATTR_2_RW(temp7_max, temp, 6, MAX6697_TEMP_MAX);
416 static SENSOR_DEVICE_ATTR_2_RW(temp7_crit, temp, 6, MAX6697_TEMP_CRIT);
419 static SENSOR_DEVICE_ATTR_2_RW(temp8_max, temp, 7, MAX6697_TEMP_MAX);
420 static SENSOR_DEVICE_ATTR_2_RW(temp8_crit, temp, 7, MAX6697_TEMP_CRIT);
422 static SENSOR_DEVICE_ATTR_RO(temp1_max_alarm, alarm, 22);
423 static SENSOR_DEVICE_ATTR_RO(temp2_max_alarm, alarm, 16);
424 static SENSOR_DEVICE_ATTR_RO(temp3_max_alarm, alarm, 17);
425 static SENSOR_DEVICE_ATTR_RO(temp4_max_alarm, alarm, 18);
426 static SENSOR_DEVICE_ATTR_RO(temp5_max_alarm, alarm, 19);
427 static SENSOR_DEVICE_ATTR_RO(temp6_max_alarm, alarm, 20);
428 static SENSOR_DEVICE_ATTR_RO(temp7_max_alarm, alarm, 21);
429 static SENSOR_DEVICE_ATTR_RO(temp8_max_alarm, alarm, 23);
431 static SENSOR_DEVICE_ATTR_RO(temp1_crit_alarm, alarm, 14);
432 static SENSOR_DEVICE_ATTR_RO(temp2_crit_alarm, alarm, 8);
433 static SENSOR_DEVICE_ATTR_RO(temp3_crit_alarm, alarm, 9);
434 static SENSOR_DEVICE_ATTR_RO(temp4_crit_alarm, alarm, 10);
435 static SENSOR_DEVICE_ATTR_RO(temp5_crit_alarm, alarm, 11);
436 static SENSOR_DEVICE_ATTR_RO(temp6_crit_alarm, alarm, 12);
437 static SENSOR_DEVICE_ATTR_RO(temp7_crit_alarm, alarm, 13);
438 static SENSOR_DEVICE_ATTR_RO(temp8_crit_alarm, alarm, 15);
440 static SENSOR_DEVICE_ATTR_RO(temp2_fault, alarm, 1);
441 static SENSOR_DEVICE_ATTR_RO(temp3_fault, alarm, 2);
442 static SENSOR_DEVICE_ATTR_RO(temp4_fault, alarm, 3);
443 static SENSOR_DEVICE_ATTR_RO(temp5_fault, alarm, 4);
444 static SENSOR_DEVICE_ATTR_RO(temp6_fault, alarm, 5);
445 static SENSOR_DEVICE_ATTR_RO(temp7_fault, alarm, 6);
446 static SENSOR_DEVICE_ATTR_RO(temp8_fault, alarm, 7);
464 const struct max6697_chip_data *chip = data->chip; in max6697_is_visible()
468 if (channel >= chip->channels) in max6697_is_visible()
471 if ((nr == 3 || nr == 4) && !(chip->have_crit & (1 << channel))) in max6697_is_visible()
473 if (nr == 5 && !(chip->have_fault & (1 << channel))) in max6697_is_visible()
477 if (data->type != max6581 || channel == 0) in max6697_is_visible()
480 return attr->mode; in max6697_is_visible()
566 pdata->smbus_timeout_disable = in max6697_get_config_of()
567 of_property_read_bool(node, "smbus-timeout-disable"); in max6697_get_config_of()
568 pdata->extended_range_enable = in max6697_get_config_of()
569 of_property_read_bool(node, "extended-range-enable"); in max6697_get_config_of()
570 pdata->beta_compensation = in max6697_get_config_of()
571 of_property_read_bool(node, "beta-compensation-enable"); in max6697_get_config_of()
573 prop = of_get_property(node, "alert-mask", &len); in max6697_get_config_of()
575 pdata->alert_mask = be32_to_cpu(prop[0]); in max6697_get_config_of()
576 prop = of_get_property(node, "over-temperature-mask", &len); in max6697_get_config_of()
578 pdata->over_temperature_mask = be32_to_cpu(prop[0]); in max6697_get_config_of()
579 prop = of_get_property(node, "resistance-cancellation", &len); in max6697_get_config_of()
582 pdata->resistance_cancellation = be32_to_cpu(prop[0]); in max6697_get_config_of()
584 pdata->resistance_cancellation = 0xfe; in max6697_get_config_of()
586 prop = of_get_property(node, "transistor-ideality", &len); in max6697_get_config_of()
588 pdata->ideality_mask = be32_to_cpu(prop[0]); in max6697_get_config_of()
589 pdata->ideality_value = be32_to_cpu(prop[1]); in max6697_get_config_of()
596 struct max6697_platform_data *pdata = dev_get_platdata(&client->dev); in max6697_init_chip()
598 const struct max6697_chip_data *chip = data->chip; in max6697_init_chip()
599 int factor = chip->channels; in max6697_init_chip()
607 if (!pdata && !client->dev.of_node) { in max6697_init_chip()
611 if (data->type == max6581) { in max6697_init_chip()
613 data->temp_offset = 64; in max6697_init_chip()
626 if (client->dev.of_node) { in max6697_init_chip()
628 max6697_get_config_of(client->dev.of_node, &p); in max6697_init_chip()
633 if (pdata->smbus_timeout_disable && in max6697_init_chip()
634 (chip->valid_conf & MAX6697_CONF_TIMEOUT)) { in max6697_init_chip()
637 if (pdata->extended_range_enable && in max6697_init_chip()
638 (chip->valid_conf & MAX6581_CONF_EXTENDED)) { in max6697_init_chip()
640 data->temp_offset = 64; in max6697_init_chip()
642 if (pdata->resistance_cancellation && in max6697_init_chip()
643 (chip->valid_conf & MAX6697_CONF_RESISTANCE)) { in max6697_init_chip()
647 if (pdata->beta_compensation && in max6697_init_chip()
648 (chip->valid_conf & MAX6693_CONF_BETA)) { in max6697_init_chip()
657 MAX6697_ALERT_MAP_BITS(pdata->alert_mask)); in max6697_init_chip()
662 MAX6697_OVERT_MAP_BITS(pdata->over_temperature_mask)); in max6697_init_chip()
666 if (data->type == max6581) { in max6697_init_chip()
667 factor += hweight8(pdata->resistance_cancellation >> 1); in max6697_init_chip()
669 pdata->resistance_cancellation >> 1); in max6697_init_chip()
673 pdata->ideality_value); in max6697_init_chip()
678 pdata->ideality_mask >> 1); in max6697_init_chip()
683 data->update_interval = factor * MAX6697_CONV_TIME; in max6697_init_chip()
691 struct i2c_adapter *adapter = client->adapter; in max6697_probe()
692 struct device *dev = &client->dev; in max6697_probe()
698 return -ENODEV; in max6697_probe()
702 return -ENOMEM; in max6697_probe()
704 if (client->dev.of_node) in max6697_probe()
705 data->type = (uintptr_t)of_device_get_match_data(&client->dev); in max6697_probe()
707 data->type = i2c_match_id(max6697_id, client)->driver_data; in max6697_probe()
708 data->chip = &max6697_chip_data[data->type]; in max6697_probe()
709 data->client = client; in max6697_probe()
710 mutex_init(&data->update_lock); in max6697_probe()
716 hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, in max6697_probe()
794 MODULE_AUTHOR("Guenter Roeck <linux@roeck-us.net>");