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 = clamp_val(temp, -1000000, 1000000); /* prevent underflow */ in temp_store()
315 temp = DIV_ROUND_CLOSEST(temp, 1000) + data->temp_offset; in temp_store()
316 temp = clamp_val(temp, 0, data->type == max6581 ? 255 : 127); in temp_store()
317 data->temp[nr][index] = temp; in temp_store()
318 ret = i2c_smbus_write_byte_data(data->client, in temp_store()
322 mutex_unlock(&data->update_lock); in temp_store()
335 index = to_sensor_dev_attr(devattr)->index; in offset_store()
341 mutex_lock(&data->update_lock); in offset_store()
342 select = i2c_smbus_read_byte_data(data->client, MAX6581_REG_OFFSET_SELECT); in offset_store()
347 channel_enabled = (select & (1 << (index - 1))); in offset_store()
353 ret = i2c_smbus_write_byte_data(data->client, MAX6581_REG_OFFSET_SELECT, in offset_store()
354 select & ~(1 << (index - 1))); in offset_store()
359 ret = i2c_smbus_write_byte_data(data->client, MAX6581_REG_OFFSET_SELECT, in offset_store()
360 select | (1 << (index - 1))); in offset_store()
364 ret = i2c_smbus_write_byte_data(data->client, MAX6581_REG_OFFSET, val); in offset_store()
368 mutex_unlock(&data->update_lock); in offset_store()
377 index = to_sensor_dev_attr(devattr)->index; in offset_show()
379 mutex_lock(&data->update_lock); in offset_show()
380 select = i2c_smbus_read_byte_data(data->client, MAX6581_REG_OFFSET_SELECT); in offset_show()
383 else if (select & (1 << (index - 1))) in offset_show()
384 ret = i2c_smbus_read_byte_data(data->client, MAX6581_REG_OFFSET); in offset_show()
387 mutex_unlock(&data->update_lock); in offset_show()
465 const struct max6697_chip_data *chip = data->chip; in max6697_is_visible()
469 if (channel >= chip->channels) in max6697_is_visible()
472 if ((nr == 3 || nr == 4) && !(chip->have_crit & (1 << channel))) in max6697_is_visible()
474 if (nr == 5 && !(chip->have_fault & (1 << channel))) in max6697_is_visible()
478 if (data->type != max6581 || channel == 0) in max6697_is_visible()
481 return attr->mode; in max6697_is_visible()
567 pdata->smbus_timeout_disable = in max6697_get_config_of()
568 of_property_read_bool(node, "smbus-timeout-disable"); in max6697_get_config_of()
569 pdata->extended_range_enable = in max6697_get_config_of()
570 of_property_read_bool(node, "extended-range-enable"); in max6697_get_config_of()
571 pdata->beta_compensation = in max6697_get_config_of()
572 of_property_read_bool(node, "beta-compensation-enable"); in max6697_get_config_of()
574 prop = of_get_property(node, "alert-mask", &len); in max6697_get_config_of()
576 pdata->alert_mask = be32_to_cpu(prop[0]); in max6697_get_config_of()
577 prop = of_get_property(node, "over-temperature-mask", &len); in max6697_get_config_of()
579 pdata->over_temperature_mask = be32_to_cpu(prop[0]); in max6697_get_config_of()
580 prop = of_get_property(node, "resistance-cancellation", &len); in max6697_get_config_of()
583 pdata->resistance_cancellation = be32_to_cpu(prop[0]); in max6697_get_config_of()
585 pdata->resistance_cancellation = 0xfe; in max6697_get_config_of()
587 prop = of_get_property(node, "transistor-ideality", &len); in max6697_get_config_of()
589 pdata->ideality_mask = be32_to_cpu(prop[0]); in max6697_get_config_of()
590 pdata->ideality_value = be32_to_cpu(prop[1]); in max6697_get_config_of()
597 struct max6697_platform_data *pdata = dev_get_platdata(&client->dev); in max6697_init_chip()
599 const struct max6697_chip_data *chip = data->chip; in max6697_init_chip()
600 int factor = chip->channels; in max6697_init_chip()
608 if (!pdata && !client->dev.of_node) { in max6697_init_chip()
612 if (data->type == max6581) { in max6697_init_chip()
614 data->temp_offset = 64; in max6697_init_chip()
627 if (client->dev.of_node) { in max6697_init_chip()
629 max6697_get_config_of(client->dev.of_node, &p); in max6697_init_chip()
634 if (pdata->smbus_timeout_disable && in max6697_init_chip()
635 (chip->valid_conf & MAX6697_CONF_TIMEOUT)) { in max6697_init_chip()
638 if (pdata->extended_range_enable && in max6697_init_chip()
639 (chip->valid_conf & MAX6581_CONF_EXTENDED)) { in max6697_init_chip()
641 data->temp_offset = 64; in max6697_init_chip()
643 if (pdata->resistance_cancellation && in max6697_init_chip()
644 (chip->valid_conf & MAX6697_CONF_RESISTANCE)) { in max6697_init_chip()
648 if (pdata->beta_compensation && in max6697_init_chip()
649 (chip->valid_conf & MAX6693_CONF_BETA)) { in max6697_init_chip()
658 MAX6697_ALERT_MAP_BITS(pdata->alert_mask)); in max6697_init_chip()
663 MAX6697_OVERT_MAP_BITS(pdata->over_temperature_mask)); in max6697_init_chip()
667 if (data->type == max6581) { in max6697_init_chip()
668 factor += hweight8(pdata->resistance_cancellation >> 1); in max6697_init_chip()
670 pdata->resistance_cancellation >> 1); in max6697_init_chip()
674 pdata->ideality_value); in max6697_init_chip()
679 pdata->ideality_mask >> 1); in max6697_init_chip()
684 data->update_interval = factor * MAX6697_CONV_TIME; in max6697_init_chip()
692 struct i2c_adapter *adapter = client->adapter; in max6697_probe()
693 struct device *dev = &client->dev; in max6697_probe()
699 return -ENODEV; in max6697_probe()
703 return -ENOMEM; in max6697_probe()
705 if (client->dev.of_node) in max6697_probe()
706 data->type = (uintptr_t)of_device_get_match_data(&client->dev); in max6697_probe()
708 data->type = i2c_match_id(max6697_id, client)->driver_data; in max6697_probe()
709 data->chip = &max6697_chip_data[data->type]; in max6697_probe()
710 data->client = client; in max6697_probe()
711 mutex_init(&data->update_lock); in max6697_probe()
717 hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, in max6697_probe()
795 MODULE_AUTHOR("Guenter Roeck <linux@roeck-us.net>");