Lines Matching +full:beta +full:- +full:compensation
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 */
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()
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()
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()
278 temp = data->temp[nr][index]; in temp_show()
279 temp -= data->temp_offset; 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()
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()
321 mutex_unlock(&data->update_lock); in temp_store()
334 index = to_sensor_dev_attr(devattr)->index; 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()
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()
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>");