Lines Matching +full:resistance +full:- +full:temp +full:- +full:table

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * nct7802 - Driver for Nuvoton NCT7802Y
5 * Copyright (C) 2014 Guenter Roeck <linux@roeck-us.net>
14 #include <linux/hwmon-sysfs.h>
55 * Resistance temperature detector (RTD) modes according to 7.2.32 Mode
77 struct mutex access_lock; /* for multi-byte read and write operations */
90 ret = regmap_read(data->regmap, REG_MODE, &mode); in temp_type_show()
94 return sprintf(buf, "%u\n", (mode >> (2 * sattr->index) & 3) + 2); in temp_type_show()
109 if (sattr->index == 2 && type != 4) /* RD3 */ in temp_type_store()
110 return -EINVAL; in temp_type_store()
112 return -EINVAL; in temp_type_store()
113 err = regmap_update_bits(data->regmap, REG_MODE, in temp_type_store()
114 3 << 2 * sattr->index, (type - 2) << 2 * sattr->index); in temp_type_store()
126 if (sattr->index > 1) in pwm_mode_show()
129 ret = regmap_read(data->regmap, 0x5E, &regval); in pwm_mode_show()
133 return sprintf(buf, "%u\n", !(regval & (1 << sattr->index))); in pwm_mode_show()
144 if (!attr->index) in pwm_show()
147 ret = regmap_read(data->regmap, attr->index, &val); in pwm_show()
166 err = regmap_write(data->regmap, attr->index, val); in pwm_store()
178 ret = regmap_read(data->regmap, REG_SMARTFAN_EN(sattr->index), &reg); in pwm_enable_show()
181 enabled = reg >> SMARTFAN_EN_SHIFT(sattr->index) & 1; in pwm_enable_show()
198 return -EINVAL; in pwm_enable_store()
199 ret = regmap_update_bits(data->regmap, REG_SMARTFAN_EN(sattr->index), in pwm_enable_store()
200 1 << SMARTFAN_EN_SHIFT(sattr->index), in pwm_enable_store()
201 (val - 1) << SMARTFAN_EN_SHIFT(sattr->index)); in pwm_enable_store()
206 u8 reg_temp, u8 reg_temp_low, int *temp) in nct7802_read_temp() argument
211 *temp = 0; in nct7802_read_temp()
213 mutex_lock(&data->access_lock); in nct7802_read_temp()
214 err = regmap_read(data->regmap, reg_temp, &t1); in nct7802_read_temp()
219 err = regmap_read(data->regmap, reg_temp_low, &t2); in nct7802_read_temp()
224 *temp = (s16)t1 / 32 * 125; in nct7802_read_temp()
226 mutex_unlock(&data->access_lock); in nct7802_read_temp()
236 ret = regmap_multi_reg_read(data->regmap, regs, f, 2); in nct7802_read_fan()
255 ret = regmap_multi_reg_read(data->regmap, regs, f, 2); in nct7802_read_fan_min()
281 mutex_lock(&data->access_lock); in nct7802_write_fan_min()
282 err = regmap_write(data->regmap, reg_fan_low, limit & 0xff); in nct7802_write_fan_min()
286 err = regmap_write(data->regmap, reg_fan_high, (limit & 0x1f00) >> 5); in nct7802_write_fan_min()
288 mutex_unlock(&data->access_lock); in nct7802_write_fan_min()
302 ret = regmap_multi_reg_read(data->regmap, regs, v, 2); in nct7802_read_voltage()
307 int shift = 8 - REG_VOLTAGE_LIMIT_MSB_SHIFT[index - 1][nr]; in nct7802_read_voltage()
308 unsigned int regs[2] = {REG_VOLTAGE_LIMIT_LSB[index - 1][nr], in nct7802_read_voltage()
311 ret = regmap_multi_reg_read(data->regmap, regs, v, 2); in nct7802_read_voltage()
322 int shift = 8 - REG_VOLTAGE_LIMIT_MSB_SHIFT[index - 1][nr]; in nct7802_write_voltage()
328 mutex_lock(&data->access_lock); in nct7802_write_voltage()
329 err = regmap_write(data->regmap, in nct7802_write_voltage()
330 REG_VOLTAGE_LIMIT_LSB[index - 1][nr], in nct7802_write_voltage()
335 err = regmap_update_bits(data->regmap, REG_VOLTAGE_LIMIT_MSB[nr], in nct7802_write_voltage()
338 mutex_unlock(&data->access_lock); in nct7802_write_voltage()
349 voltage = nct7802_read_voltage(data, sattr->nr, sattr->index); in in_show()
361 int index = sattr->index; in in_store()
362 int nr = sattr->nr; in in_store()
382 mutex_lock(&data->in_alarm_lock); in in_alarm_show()
396 ret = regmap_read(data->regmap, 0x1e, &val); /* SMI Voltage status */ in in_alarm_show()
401 data->in_status &= ~((val & 0x0f) << 4); in in_alarm_show()
404 if (!(data->in_status & (0x10 << sattr->index))) { in in_alarm_show()
405 ret = nct7802_read_voltage(data, sattr->nr, 0); in in_alarm_show()
410 ret = nct7802_read_voltage(data, sattr->nr, 1); in in_alarm_show()
415 ret = nct7802_read_voltage(data, sattr->nr, 2); in in_alarm_show()
421 data->in_status |= (1 << sattr->index); in in_alarm_show()
423 data->in_status &= ~(1 << sattr->index); in in_alarm_show()
425 data->in_status |= 0x10 << sattr->index; in in_alarm_show()
428 ret = sprintf(buf, "%u\n", !!(data->in_status & (1 << sattr->index))); in in_alarm_show()
430 mutex_unlock(&data->in_alarm_lock); in in_alarm_show()
439 int err, temp; in temp_show() local
441 err = nct7802_read_temp(data, sattr->nr, sattr->index, &temp); in temp_show()
445 return sprintf(buf, "%d\n", temp); in temp_show()
453 int nr = sattr->nr; in temp_store()
461 val = DIV_ROUND_CLOSEST(clamp_val(val, -128000, 127000), 1000); in temp_store()
463 err = regmap_write(data->regmap, nr, val & 0xff); in temp_store()
474 speed = nct7802_read_fan(data, sattr->index); in fan_show()
488 speed = nct7802_read_fan_min(data, sattr->nr, sattr->index); in fan_min_show()
508 err = nct7802_write_fan_min(data, sattr->nr, sattr->index, val); in fan_min_store()
517 int bit = sattr->index; in alarm_show()
521 ret = regmap_read(data->regmap, sattr->nr, &val); in alarm_show()
536 err = regmap_read(data->regmap, sattr->nr, &regval); in beep_show()
540 return sprintf(buf, "%u\n", !!(regval & (1 << sattr->index))); in beep_show()
556 return -EINVAL; in beep_store()
558 err = regmap_update_bits(data->regmap, sattr->nr, 1 << sattr->index, in beep_store()
559 val ? 1 << sattr->index : 0); in beep_store()
564 static SENSOR_DEVICE_ATTR_2_RO(temp1_input, temp, 0x01, REG_TEMP_LSB);
565 static SENSOR_DEVICE_ATTR_2_RW(temp1_min, temp, 0x31, 0);
566 static SENSOR_DEVICE_ATTR_2_RW(temp1_max, temp, 0x30, 0);
567 static SENSOR_DEVICE_ATTR_2_RW(temp1_crit, temp, 0x3a, 0);
570 static SENSOR_DEVICE_ATTR_2_RO(temp2_input, temp, 0x02, REG_TEMP_LSB);
571 static SENSOR_DEVICE_ATTR_2_RW(temp2_min, temp, 0x33, 0);
572 static SENSOR_DEVICE_ATTR_2_RW(temp2_max, temp, 0x32, 0);
573 static SENSOR_DEVICE_ATTR_2_RW(temp2_crit, temp, 0x3b, 0);
576 static SENSOR_DEVICE_ATTR_2_RO(temp3_input, temp, 0x03, REG_TEMP_LSB);
577 static SENSOR_DEVICE_ATTR_2_RW(temp3_min, temp, 0x35, 0);
578 static SENSOR_DEVICE_ATTR_2_RW(temp3_max, temp, 0x34, 0);
579 static SENSOR_DEVICE_ATTR_2_RW(temp3_crit, temp, 0x3c, 0);
581 static SENSOR_DEVICE_ATTR_2_RO(temp4_input, temp, 0x04, 0);
582 static SENSOR_DEVICE_ATTR_2_RW(temp4_min, temp, 0x37, 0);
583 static SENSOR_DEVICE_ATTR_2_RW(temp4_max, temp, 0x36, 0);
584 static SENSOR_DEVICE_ATTR_2_RW(temp4_crit, temp, 0x3d, 0);
586 static SENSOR_DEVICE_ATTR_2_RO(temp5_input, temp, 0x06, REG_TEMP_PECI_LSB);
587 static SENSOR_DEVICE_ATTR_2_RW(temp5_min, temp, 0x39, 0);
588 static SENSOR_DEVICE_ATTR_2_RW(temp5_max, temp, 0x38, 0);
589 static SENSOR_DEVICE_ATTR_2_RW(temp5_crit, temp, 0x3e, 0);
591 static SENSOR_DEVICE_ATTR_2_RO(temp6_input, temp, 0x07, REG_TEMP_PECI_LSB);
688 err = regmap_read(data->regmap, REG_MODE, &reg); in nct7802_temp_is_visible()
703 return attr->mode; in nct7802_temp_is_visible()
705 err = regmap_read(data->regmap, REG_PECI_ENABLE, &reg); in nct7802_temp_is_visible()
715 return attr->mode; in nct7802_temp_is_visible()
788 return attr->mode; in nct7802_in_is_visible()
790 err = regmap_read(data->regmap, REG_MODE, &reg); in nct7802_in_is_visible()
801 return attr->mode; in nct7802_in_is_visible()
863 err = regmap_read(data->regmap, REG_FAN_ENABLE, &reg); in nct7802_fan_is_visible()
867 return attr->mode; in nct7802_fan_is_visible()
892 /* 7.2.115... 0x80-0x83, 0x84 Temperature (X-axis) transition */
893 static SENSOR_DEVICE_ATTR_2_RW(pwm1_auto_point1_temp, temp, 0x80, 0);
894 static SENSOR_DEVICE_ATTR_2_RW(pwm1_auto_point2_temp, temp, 0x81, 0);
895 static SENSOR_DEVICE_ATTR_2_RW(pwm1_auto_point3_temp, temp, 0x82, 0);
896 static SENSOR_DEVICE_ATTR_2_RW(pwm1_auto_point4_temp, temp, 0x83, 0);
897 static SENSOR_DEVICE_ATTR_2_RW(pwm1_auto_point5_temp, temp, 0x84, 0);
899 /* 7.2.120... 0x85-0x88 PWM (Y-axis) transition */
906 /* 7.2.124 Table 2 X-axis Transition Point 1 Register */
907 static SENSOR_DEVICE_ATTR_2_RW(pwm2_auto_point1_temp, temp, 0x90, 0);
908 static SENSOR_DEVICE_ATTR_2_RW(pwm2_auto_point2_temp, temp, 0x91, 0);
909 static SENSOR_DEVICE_ATTR_2_RW(pwm2_auto_point3_temp, temp, 0x92, 0);
910 static SENSOR_DEVICE_ATTR_2_RW(pwm2_auto_point4_temp, temp, 0x93, 0);
911 static SENSOR_DEVICE_ATTR_2_RW(pwm2_auto_point5_temp, temp, 0x94, 0);
913 /* 7.2.129 Table 2 Y-axis Transition Point 1 Register */
920 /* 7.2.133 Table 3 X-axis Transition Point 1 Register */
921 static SENSOR_DEVICE_ATTR_2_RW(pwm3_auto_point1_temp, temp, 0xA0, 0);
922 static SENSOR_DEVICE_ATTR_2_RW(pwm3_auto_point2_temp, temp, 0xA1, 0);
923 static SENSOR_DEVICE_ATTR_2_RW(pwm3_auto_point3_temp, temp, 0xA2, 0);
924 static SENSOR_DEVICE_ATTR_2_RW(pwm3_auto_point4_temp, temp, 0xA3, 0);
925 static SENSOR_DEVICE_ATTR_2_RW(pwm3_auto_point5_temp, temp, 0xA4, 0);
927 /* 7.2.138 Table 3 Y-axis Transition Point 1 Register */
998 return -ENODEV; in nct7802_detect()
1002 return -ENODEV; in nct7802_detect()
1006 return -ENODEV; in nct7802_detect()
1010 return -ENODEV; in nct7802_detect()
1015 return -ENODEV; in nct7802_detect()
1019 return -ENODEV; in nct7802_detect()
1023 return -ENODEV; in nct7802_detect()
1025 strscpy(info->type, "nct7802", I2C_NAME_SIZE); in nct7802_detect()
1050 if (!node->name || of_node_cmp(node->name, "channel")) in nct7802_get_channel_config()
1055 node->full_name); in nct7802_get_channel_config()
1056 return -EINVAL; in nct7802_get_channel_config()
1061 node->full_name); in nct7802_get_channel_config()
1062 return -EINVAL; in nct7802_get_channel_config()
1077 *mode_val &= ~(MODE_RTD_MASK << MODE_BIT_OFFSET_RTD(reg - 1)); in nct7802_get_channel_config()
1078 *mode_mask |= MODE_RTD_MASK << MODE_BIT_OFFSET_RTD(reg - 1); in nct7802_get_channel_config()
1082 if (of_property_read_string(node, "sensor-type", &type_str)) { in nct7802_get_channel_config()
1083 dev_err(dev, "No type for '%s'\n", node->full_name); in nct7802_get_channel_config()
1084 return -EINVAL; in nct7802_get_channel_config()
1089 << MODE_BIT_OFFSET_RTD(reg - 1); in nct7802_get_channel_config()
1090 *mode_mask |= MODE_RTD_MASK << MODE_BIT_OFFSET_RTD(reg - 1); in nct7802_get_channel_config()
1096 node->full_name); in nct7802_get_channel_config()
1097 return -EINVAL; in nct7802_get_channel_config()
1104 if (of_property_read_string(node, "temperature-mode", in nct7802_get_channel_config()
1106 dev_err(dev, "No mode for '%s'\n", node->full_name); in nct7802_get_channel_config()
1107 return -EINVAL; in nct7802_get_channel_config()
1110 if (!strcmp(md_str, "thermal-diode")) in nct7802_get_channel_config()
1116 node->full_name); in nct7802_get_channel_config()
1117 return -EINVAL; in nct7802_get_channel_config()
1121 *mode_val |= (md & MODE_RTD_MASK) << MODE_BIT_OFFSET_RTD(reg - 1); in nct7802_get_channel_config()
1122 *mode_mask |= MODE_RTD_MASK << MODE_BIT_OFFSET_RTD(reg - 1); in nct7802_get_channel_config()
1134 if (dev->of_node) { in nct7802_configure_channels()
1135 for_each_child_of_node_scoped(dev->of_node, node) { in nct7802_configure_channels()
1143 return regmap_update_bits(data->regmap, REG_MODE, mode_mask, mode_val); in nct7802_configure_channels()
1151 err = regmap_update_bits(data->regmap, REG_START, 0x01, 0x01); in nct7802_init_chip()
1160 return regmap_update_bits(data->regmap, REG_VMON_ENABLE, 0x03, 0x03); in nct7802_init_chip()
1165 struct device *dev = &client->dev; in nct7802_probe()
1172 return -ENOMEM; in nct7802_probe()
1174 data->regmap = devm_regmap_init_i2c(client, &nct7802_regmap_config); in nct7802_probe()
1175 if (IS_ERR(data->regmap)) in nct7802_probe()
1176 return PTR_ERR(data->regmap); in nct7802_probe()
1178 mutex_init(&data->access_lock); in nct7802_probe()
1179 mutex_init(&data->in_alarm_lock); in nct7802_probe()
1185 hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, in nct7802_probe()
1214 MODULE_AUTHOR("Guenter Roeck <linux@roeck-us.net>");