Lines Matching +full:invert +full:- +full:ext
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * adm1031.c - Part of lm_sensors, Linux kernel modules for hardware
17 #include <linux/hwmon-sysfs.h>
43 #define ADM1031_CONF1_PWM_INVERT 0x08 /* PWM Invert */
110 struct i2c_client *client = data->client; in adm1031_update_device()
114 mutex_lock(&data->update_lock); in adm1031_update_device()
116 next_update = data->last_updated in adm1031_update_device()
117 + msecs_to_jiffies(data->update_interval); in adm1031_update_device()
118 if (time_after(jiffies, next_update) || !data->valid) { in adm1031_update_device()
120 dev_dbg(&client->dev, "Starting adm1031 update\n"); in adm1031_update_device()
122 chan < ((data->chip_type == adm1031) ? 3 : 2); chan++) { in adm1031_update_device()
127 data->ext_temp[chan] = in adm1031_update_device()
132 data->ext_temp[chan] = in adm1031_update_device()
142 dev_warn(&client->dev, in adm1031_update_device()
146 data->temp[chan] = newh; in adm1031_update_device()
148 data->temp_offset[chan] = in adm1031_update_device()
151 data->temp_min[chan] = in adm1031_update_device()
154 data->temp_max[chan] = in adm1031_update_device()
157 data->temp_crit[chan] = in adm1031_update_device()
160 data->auto_temp[chan] = in adm1031_update_device()
166 data->conf1 = adm1031_read_value(client, ADM1031_REG_CONF1); in adm1031_update_device()
167 data->conf2 = adm1031_read_value(client, ADM1031_REG_CONF2); in adm1031_update_device()
169 data->alarm = adm1031_read_value(client, ADM1031_REG_STATUS(0)) in adm1031_update_device()
171 if (data->chip_type == adm1030) in adm1031_update_device()
172 data->alarm &= 0xc0ff; in adm1031_update_device()
174 for (chan = 0; chan < (data->chip_type == adm1030 ? 1 : 2); in adm1031_update_device()
176 data->fan_div[chan] = in adm1031_update_device()
179 data->fan_min[chan] = in adm1031_update_device()
182 data->fan[chan] = in adm1031_update_device()
185 data->pwm[chan] = in adm1031_update_device()
189 data->last_updated = jiffies; in adm1031_update_device()
190 data->valid = true; in adm1031_update_device()
193 mutex_unlock(&data->update_lock); in adm1031_update_device()
198 #define TEMP_TO_REG(val) (((val) < 0 ? ((val - 500) / 1000) : \
203 #define TEMP_FROM_REG_EXT(val, ext) (TEMP_FROM_REG(val) + (ext) * 125) argument
236 (AUTO_TEMP_MIN_FROM_REG(reg) - 5000)
245 int range = ((val - AUTO_TEMP_MIN_FROM_REG(reg)) * 10) / (16 - pwm); in AUTO_TEMP_MAX_TO_REG()
256 (*(data)->chan_select_table)[FAN_CHAN_FROM_REG((data)->conf1)][idx % 2]
288 int first_match = -1, exact_match = -1; in get_fan_auto_nearest()
290 (*data->chan_select_table)[FAN_CHAN_FROM_REG(reg)][chan ? 0 : 1]; in get_fan_auto_nearest()
296 if ((val == (*data->chan_select_table)[i][chan]) && in get_fan_auto_nearest()
297 ((*data->chan_select_table)[i][chan ? 0 : 1] == in get_fan_auto_nearest()
302 } else if (val == (*data->chan_select_table)[i][chan] && in get_fan_auto_nearest()
303 first_match == -1) { in get_fan_auto_nearest()
317 return -EINVAL; in get_fan_auto_nearest()
323 int nr = to_sensor_dev_attr(attr)->index; in fan_auto_channel_show()
333 struct i2c_client *client = data->client; in fan_auto_channel_store()
334 int nr = to_sensor_dev_attr(attr)->index; in fan_auto_channel_store()
344 old_fan_mode = data->conf1; in fan_auto_channel_store()
346 mutex_lock(&data->update_lock); in fan_auto_channel_store()
348 ret = get_fan_auto_nearest(data, nr, val, data->conf1); in fan_auto_channel_store()
350 mutex_unlock(&data->update_lock); in fan_auto_channel_store()
354 data->conf1 = FAN_CHAN_TO_REG(reg, data->conf1); in fan_auto_channel_store()
355 if ((data->conf1 & ADM1031_CONF1_AUTO_MODE) ^ in fan_auto_channel_store()
357 if (data->conf1 & ADM1031_CONF1_AUTO_MODE) { in fan_auto_channel_store()
363 data->old_pwm[0] = data->pwm[0]; in fan_auto_channel_store()
364 data->old_pwm[1] = data->pwm[1]; in fan_auto_channel_store()
368 data->pwm[0] = data->old_pwm[0]; in fan_auto_channel_store()
369 data->pwm[1] = data->old_pwm[1]; in fan_auto_channel_store()
372 data->pwm[0] | (data->pwm[1] << 4)); in fan_auto_channel_store()
375 data->conf1 = FAN_CHAN_TO_REG(reg, data->conf1); in fan_auto_channel_store()
376 adm1031_write_value(client, ADM1031_REG_CONF1, data->conf1); in fan_auto_channel_store()
377 mutex_unlock(&data->update_lock); in fan_auto_channel_store()
388 int nr = to_sensor_dev_attr(attr)->index; in auto_temp_off_show()
391 AUTO_TEMP_OFF_FROM_REG(data->auto_temp[nr])); in auto_temp_off_show()
396 int nr = to_sensor_dev_attr(attr)->index; in auto_temp_min_show()
399 AUTO_TEMP_MIN_FROM_REG(data->auto_temp[nr])); in auto_temp_min_show()
406 struct i2c_client *client = data->client; in auto_temp_min_store()
407 int nr = to_sensor_dev_attr(attr)->index; in auto_temp_min_store()
416 mutex_lock(&data->update_lock); in auto_temp_min_store()
417 data->auto_temp[nr] = AUTO_TEMP_MIN_TO_REG(val, data->auto_temp[nr]); in auto_temp_min_store()
419 data->auto_temp[nr]); in auto_temp_min_store()
420 mutex_unlock(&data->update_lock); in auto_temp_min_store()
426 int nr = to_sensor_dev_attr(attr)->index; in auto_temp_max_show()
429 AUTO_TEMP_MAX_FROM_REG(data->auto_temp[nr])); in auto_temp_max_show()
436 struct i2c_client *client = data->client; in auto_temp_max_store()
437 int nr = to_sensor_dev_attr(attr)->index; in auto_temp_max_store()
446 mutex_lock(&data->update_lock); in auto_temp_max_store()
447 data->temp_max[nr] = AUTO_TEMP_MAX_TO_REG(val, data->auto_temp[nr], in auto_temp_max_store()
448 data->pwm[nr]); in auto_temp_max_store()
450 data->temp_max[nr]); in auto_temp_max_store()
451 mutex_unlock(&data->update_lock); in auto_temp_max_store()
469 int nr = to_sensor_dev_attr(attr)->index; in pwm_show()
471 return sprintf(buf, "%d\n", PWM_FROM_REG(data->pwm[nr])); in pwm_show()
477 struct i2c_client *client = data->client; in pwm_store()
478 int nr = to_sensor_dev_attr(attr)->index; in pwm_store()
486 mutex_lock(&data->update_lock); in pwm_store()
487 if ((data->conf1 & ADM1031_CONF1_AUTO_MODE) && in pwm_store()
490 mutex_unlock(&data->update_lock); in pwm_store()
491 return -EINVAL; in pwm_store()
493 data->pwm[nr] = PWM_TO_REG(val); in pwm_store()
496 nr ? ((data->pwm[nr] << 4) & 0xf0) | (reg & 0xf) in pwm_store()
497 : (data->pwm[nr] & 0xf) | (reg & 0xf0)); in pwm_store()
498 mutex_unlock(&data->update_lock); in pwm_store()
518 if (data->conf1 & ADM1031_CONF1_AUTO_MODE) { in trust_fan_readings()
519 switch (data->conf1 & 0x60) { in trust_fan_readings()
525 res = data->temp[chan+1] >= in trust_fan_readings()
526 AUTO_TEMP_MIN_FROM_REG_DEG(data->auto_temp[chan+1]); in trust_fan_readings()
530 data->temp[1] >= in trust_fan_readings()
531 AUTO_TEMP_MIN_FROM_REG_DEG(data->auto_temp[1]); in trust_fan_readings()
535 data->temp[2] >= in trust_fan_readings()
536 AUTO_TEMP_MIN_FROM_REG_DEG(data->auto_temp[2]); in trust_fan_readings()
540 data->temp[0] >= in trust_fan_readings()
541 AUTO_TEMP_MIN_FROM_REG_DEG(data->auto_temp[0]) in trust_fan_readings()
542 || data->temp[1] >= in trust_fan_readings()
543 AUTO_TEMP_MIN_FROM_REG_DEG(data->auto_temp[1]) in trust_fan_readings()
544 || (data->chip_type == adm1031 in trust_fan_readings()
545 && data->temp[2] >= in trust_fan_readings()
546 AUTO_TEMP_MIN_FROM_REG_DEG(data->auto_temp[2])); in trust_fan_readings()
550 res = data->pwm[chan] > 0; in trust_fan_readings()
558 int nr = to_sensor_dev_attr(attr)->index; in fan_show()
562 value = trust_fan_readings(data, nr) ? FAN_FROM_REG(data->fan[nr], in fan_show()
563 FAN_DIV_FROM_REG(data->fan_div[nr])) : 0; in fan_show()
570 int nr = to_sensor_dev_attr(attr)->index; in fan_div_show()
572 return sprintf(buf, "%d\n", FAN_DIV_FROM_REG(data->fan_div[nr])); in fan_div_show()
577 int nr = to_sensor_dev_attr(attr)->index; in fan_min_show()
580 FAN_FROM_REG(data->fan_min[nr], in fan_min_show()
581 FAN_DIV_FROM_REG(data->fan_div[nr]))); in fan_min_show()
588 struct i2c_client *client = data->client; in fan_min_store()
589 int nr = to_sensor_dev_attr(attr)->index; in fan_min_store()
597 mutex_lock(&data->update_lock); in fan_min_store()
599 data->fan_min[nr] = in fan_min_store()
600 FAN_TO_REG(val, FAN_DIV_FROM_REG(data->fan_div[nr])); in fan_min_store()
602 data->fan_min[nr] = 0xff; in fan_min_store()
604 adm1031_write_value(client, ADM1031_REG_FAN_MIN(nr), data->fan_min[nr]); in fan_min_store()
605 mutex_unlock(&data->update_lock); in fan_min_store()
613 struct i2c_client *client = data->client; in fan_div_store()
614 int nr = to_sensor_dev_attr(attr)->index; in fan_div_store()
631 return -EINVAL; in fan_div_store()
633 mutex_lock(&data->update_lock); in fan_div_store()
635 data->fan_div[nr] = adm1031_read_value(client, in fan_div_store()
637 data->fan_min[nr] = adm1031_read_value(client, in fan_div_store()
641 old_div = FAN_DIV_FROM_REG(data->fan_div[nr]); in fan_div_store()
642 data->fan_div[nr] = tmp | (0x3f & data->fan_div[nr]); in fan_div_store()
643 new_min = data->fan_min[nr] * old_div / val; in fan_div_store()
644 data->fan_min[nr] = new_min > 0xff ? 0xff : new_min; in fan_div_store()
647 data->fan_div[nr]); in fan_div_store()
649 data->fan_min[nr]); in fan_div_store()
652 data->valid = false; in fan_div_store()
653 mutex_unlock(&data->update_lock); in fan_div_store()
668 int nr = to_sensor_dev_attr(attr)->index; in temp_show()
670 int ext; in temp_show() local
671 ext = nr == 0 ? in temp_show()
672 ((data->ext_temp[nr] >> 6) & 0x3) * 2 : in temp_show()
673 (((data->ext_temp[nr] >> ((nr - 1) * 3)) & 7)); in temp_show()
674 return sprintf(buf, "%d\n", TEMP_FROM_REG_EXT(data->temp[nr], ext)); in temp_show()
679 int nr = to_sensor_dev_attr(attr)->index; in temp_offset_show()
682 TEMP_OFFSET_FROM_REG(data->temp_offset[nr])); in temp_offset_show()
687 int nr = to_sensor_dev_attr(attr)->index; in temp_min_show()
689 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[nr])); in temp_min_show()
694 int nr = to_sensor_dev_attr(attr)->index; in temp_max_show()
696 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[nr])); in temp_max_show()
701 int nr = to_sensor_dev_attr(attr)->index; in temp_crit_show()
703 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_crit[nr])); in temp_crit_show()
710 struct i2c_client *client = data->client; in temp_offset_store()
711 int nr = to_sensor_dev_attr(attr)->index; in temp_offset_store()
719 val = clamp_val(val, -15000, 15000); in temp_offset_store()
720 mutex_lock(&data->update_lock); in temp_offset_store()
721 data->temp_offset[nr] = TEMP_OFFSET_TO_REG(val); in temp_offset_store()
723 data->temp_offset[nr]); in temp_offset_store()
724 mutex_unlock(&data->update_lock); in temp_offset_store()
732 struct i2c_client *client = data->client; in temp_min_store()
733 int nr = to_sensor_dev_attr(attr)->index; in temp_min_store()
741 val = clamp_val(val, -55000, 127000); in temp_min_store()
742 mutex_lock(&data->update_lock); in temp_min_store()
743 data->temp_min[nr] = TEMP_TO_REG(val); in temp_min_store()
745 data->temp_min[nr]); in temp_min_store()
746 mutex_unlock(&data->update_lock); in temp_min_store()
754 struct i2c_client *client = data->client; in temp_max_store()
755 int nr = to_sensor_dev_attr(attr)->index; in temp_max_store()
763 val = clamp_val(val, -55000, 127000); in temp_max_store()
764 mutex_lock(&data->update_lock); in temp_max_store()
765 data->temp_max[nr] = TEMP_TO_REG(val); in temp_max_store()
767 data->temp_max[nr]); in temp_max_store()
768 mutex_unlock(&data->update_lock); in temp_max_store()
776 struct i2c_client *client = data->client; in temp_crit_store()
777 int nr = to_sensor_dev_attr(attr)->index; in temp_crit_store()
785 val = clamp_val(val, -55000, 127000); in temp_crit_store()
786 mutex_lock(&data->update_lock); in temp_crit_store()
787 data->temp_crit[nr] = TEMP_TO_REG(val); in temp_crit_store()
789 data->temp_crit[nr]); in temp_crit_store()
790 mutex_unlock(&data->update_lock); in temp_crit_store()
815 return sprintf(buf, "%d\n", data->alarm); in alarms_show()
823 int bitnr = to_sensor_dev_attr(attr)->index; in alarm_show()
825 return sprintf(buf, "%d\n", (data->alarm >> bitnr) & 1); in alarm_show()
854 return sprintf(buf, "%u\n", data->update_interval); in update_interval_show()
862 struct i2c_client *client = data->client; in update_interval_store()
875 for (i = 0; i < ARRAY_SIZE(update_intervals) - 1; i++) { in update_interval_store()
887 mutex_lock(&data->update_lock); in update_interval_store()
888 data->update_interval = update_intervals[i]; in update_interval_store()
889 mutex_unlock(&data->update_lock); in update_interval_store()
970 /* Return 0 if detection is successful, -ENODEV otherwise */
974 struct i2c_adapter *adapter = client->adapter; in adm1031_detect()
979 return -ENODEV; in adm1031_detect()
985 return -ENODEV; in adm1031_detect()
988 strscpy(info->type, name, I2C_NAME_SIZE); in adm1031_detect()
1001 if (data->chip_type == adm1031) { in adm1031_init_client()
1021 data->update_interval = update_intervals[i]; in adm1031_init_client()
1026 struct device *dev = &client->dev; in adm1031_probe()
1032 return -ENOMEM; in adm1031_probe()
1035 data->client = client; in adm1031_probe()
1036 data->chip_type = (uintptr_t)i2c_get_match_data(client); in adm1031_probe()
1037 mutex_init(&data->update_lock); in adm1031_probe()
1039 if (data->chip_type == adm1030) in adm1031_probe()
1040 data->chan_select_table = &auto_channel_select_table_adm1030; in adm1031_probe()
1042 data->chan_select_table = &auto_channel_select_table_adm1031; in adm1031_probe()
1048 data->groups[0] = &adm1031_group; in adm1031_probe()
1049 if (data->chip_type == adm1031) in adm1031_probe()
1050 data->groups[1] = &adm1031_group_opt; in adm1031_probe()
1052 hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, in adm1031_probe()
1053 data, data->groups); in adm1031_probe()