Lines Matching +full:smart +full:- +full:sensors
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * w83791d.c - Part of lm_sensors, Linux kernel modules for hardware
6 * Copyright (C) 2006-2007 Charles Spirakis <bezaur@gmail.com>
19 * The w83791g chip is the same as the w83791d but lead-free.
27 #include <linux/hwmon-vid.h>
28 #include <linux/hwmon-sysfs.h>
64 0x25, /* -12VIN in DataSheet */
65 0x26, /* -5VIN in DataSheet */
77 0x35, /* -12VIN High Limit in DataSheet */
78 0x37, /* -5VIN High Limit in DataSheet */
89 0x36, /* -12VIN Low Limit in DataSheet */
90 0x38, /* -5VIN Low Limit in DataSheet */
221 #define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : \
225 /* for temp1 which is 8-bit resolution, LSB = 1 degree Celsius */
227 #define TEMP1_TO_REG(val) ((val) <= -128000 ? -128 : \
229 (val) < 0 ? ((val) - 500) / 1000 : \
233 * for temp2 and temp3 which are 9-bit resolution, LSB = 0.5 degree Celsius
239 #define TEMP23_TO_REG(val) (DIV_ROUND_CLOSEST(clamp_val((val), -128000, \
242 /* for thermal cruise target temp, 7-bits, LSB = 1 degree Celsius */
246 /* for thermal cruise temp tolerance, 4-bits, LSB = 1 degree Celsius */
286 /* Temperature sensors */
294 * two sensors with three values
300 u8 pwm_enable[3]; /* pwm enable status for fan 1-3
301 * (fan 4-5 only support manual mode)
304 u8 temp_target[3]; /* pwm 1-3 target temperature */
305 u8 temp_tolerance[3]; /* pwm 1-3 temperature tolerance */
312 u8 vrm; /* hwmon-vid */
356 int nr = sensor_attr->index; \
357 return sprintf(buf, "%d\n", IN_FROM_REG(data->reg[nr])); \
373 int nr = sensor_attr->index; \
378 mutex_lock(&data->update_lock); \
379 data->in_##reg[nr] = IN_TO_REG(val); \
380 w83791d_write(client, W83791D_REG_IN_##REG[nr], data->in_##reg[nr]); \
381 mutex_unlock(&data->update_lock); \
434 int bitnr = sensor_attr->index; in show_beep()
436 return sprintf(buf, "%d\n", (data->beep_mask >> bitnr) & 1); in show_beep()
446 int bitnr = sensor_attr->index; in store_beep()
457 mutex_lock(&data->update_lock); in store_beep()
459 data->beep_mask &= ~(0xff << (bytenr * 8)); in store_beep()
460 data->beep_mask |= w83791d_read(client, W83791D_REG_BEEP_CTRL[bytenr]) in store_beep()
463 data->beep_mask &= ~(1 << bitnr); in store_beep()
464 data->beep_mask |= val << bitnr; in store_beep()
467 (data->beep_mask >> (bytenr * 8)) & 0xff); in store_beep()
469 mutex_unlock(&data->update_lock); in store_beep()
480 int bitnr = sensor_attr->index; in show_alarm()
482 return sprintf(buf, "%d\n", (data->alarms >> bitnr) & 1); in show_alarm()
522 int nr = sensor_attr->index; \
524 FAN_FROM_REG(data->reg[nr], DIV_FROM_REG(data->fan_div[nr]))); \
536 int nr = sensor_attr->index; in store_fan_min()
544 mutex_lock(&data->update_lock); in store_fan_min()
545 data->fan_min[nr] = fan_to_reg(val, DIV_FROM_REG(data->fan_div[nr])); in store_fan_min()
546 w83791d_write(client, W83791D_REG_FAN_MIN[nr], data->fan_min[nr]); in store_fan_min()
547 mutex_unlock(&data->update_lock); in store_fan_min()
556 int nr = sensor_attr->index; in show_fan_div()
558 return sprintf(buf, "%u\n", DIV_FROM_REG(data->fan_div[nr])); in show_fan_div()
573 int nr = sensor_attr->index; in store_fan_div()
589 min = FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr])); in store_fan_div()
591 mutex_lock(&data->update_lock); in store_fan_div()
592 data->fan_div[nr] = div_to_reg(nr, val); in store_fan_div()
623 count = -EINVAL; in store_fan_div()
630 tmp_fan_div = (data->fan_div[nr] << new_shift) & ~keep_mask; in store_fan_div()
635 /* Bit 2 of fans 0-2 is stored in the vbat register (bits 5-7) */ in store_fan_div()
640 tmp_fan_div = (data->fan_div[nr] << (3 + nr)) & ~keep_mask; in store_fan_div()
646 data->fan_min[nr] = fan_to_reg(min, DIV_FROM_REG(data->fan_div[nr])); in store_fan_div()
647 w83791d_write(client, W83791D_REG_FAN_MIN[nr], data->fan_min[nr]); in store_fan_div()
652 mutex_unlock(&data->update_lock); in store_fan_div()
712 int nr = sensor_attr->index; in show_pwm()
714 return sprintf(buf, "%u\n", data->pwm[nr]); in show_pwm()
723 int nr = sensor_attr->index; in store_pwm()
727 return -EINVAL; in store_pwm()
729 mutex_lock(&data->update_lock); in store_pwm()
730 data->pwm[nr] = clamp_val(val, 0, 255); in store_pwm()
731 w83791d_write(client, W83791D_REG_PWM[nr], data->pwm[nr]); in store_pwm()
732 mutex_unlock(&data->update_lock); in store_pwm()
753 int nr = sensor_attr->index; in show_pwmenable()
755 return sprintf(buf, "%u\n", data->pwm_enable[nr] + 1); in show_pwmenable()
764 int nr = sensor_attr->index; in store_pwmenable()
774 return -EINVAL; in store_pwmenable()
776 mutex_lock(&data->update_lock); in store_pwmenable()
777 data->pwm_enable[nr] = val - 1; in store_pwmenable()
798 data->pwm_enable[nr] << val_shift; in store_pwmenable()
801 mutex_unlock(&data->update_lock); in store_pwmenable()
814 /* For Smart Fan I / Thermal Cruise */
820 int nr = sensor_attr->index; in show_temp_target()
821 return sprintf(buf, "%d\n", TEMP1_FROM_REG(data->temp_target[nr])); in show_temp_target()
830 int nr = sensor_attr->index; in store_temp_target()
835 return -EINVAL; in store_temp_target()
837 mutex_lock(&data->update_lock); in store_temp_target()
838 data->temp_target[nr] = TARGET_TEMP_TO_REG(val); in store_temp_target()
842 data->temp_target[nr] | target_mask); in store_temp_target()
843 mutex_unlock(&data->update_lock); in store_temp_target()
861 int nr = sensor_attr->index; in show_temp_tolerance()
862 return sprintf(buf, "%d\n", TEMP1_FROM_REG(data->temp_tolerance[nr])); in show_temp_tolerance()
871 int nr = sensor_attr->index; in store_temp_tolerance()
879 return -EINVAL; in store_temp_tolerance()
899 mutex_lock(&data->update_lock); in store_temp_tolerance()
900 data->temp_tolerance[nr] = TOL_TEMP_TO_REG(val); in store_temp_tolerance()
904 (data->temp_tolerance[nr] << val_shift) | target_mask); in store_temp_tolerance()
905 mutex_unlock(&data->update_lock); in store_temp_tolerance()
924 return sprintf(buf, "%d\n", TEMP1_FROM_REG(data->temp1[attr->index])); in show_temp1()
933 int nr = attr->index; in store_temp1()
941 mutex_lock(&data->update_lock); in store_temp1()
942 data->temp1[nr] = TEMP1_TO_REG(val); in store_temp1()
943 w83791d_write(client, W83791D_REG_TEMP1[nr], data->temp1[nr]); in store_temp1()
944 mutex_unlock(&data->update_lock); in store_temp1()
948 /* read/write temperature2-3, includes measured value and limits */
954 int nr = attr->nr; in show_temp23()
955 int index = attr->index; in show_temp23()
956 return sprintf(buf, "%d\n", TEMP23_FROM_REG(data->temp_add[nr][index])); in show_temp23()
968 int nr = attr->nr; in store_temp23()
969 int index = attr->index; in store_temp23()
975 mutex_lock(&data->update_lock); in store_temp23()
976 data->temp_add[nr][index] = TEMP23_TO_REG(val); in store_temp23()
978 data->temp_add[nr][index] >> 8); in store_temp23()
980 data->temp_add[nr][index] & 0x80); in store_temp23()
981 mutex_unlock(&data->update_lock); in store_temp23()
1026 /* get realtime status of all sensors items: voltage, temp, fan */
1031 return sprintf(buf, "%u\n", data->alarms); in alarms_show()
1045 return sprintf(buf, "%d\n", data->beep_enable); in show_beep_enable()
1052 return sprintf(buf, "%d\n", BEEP_MASK_FROM_REG(data->beep_mask)); in show_beep_mask()
1070 mutex_lock(&data->update_lock); in store_beep_mask()
1076 data->beep_mask = BEEP_MASK_TO_REG(val) & ~GLOBAL_BEEP_ENABLE_MASK; in store_beep_mask()
1077 data->beep_mask |= (data->beep_enable << GLOBAL_BEEP_ENABLE_SHIFT); in store_beep_mask()
1079 val = data->beep_mask; in store_beep_mask()
1086 mutex_unlock(&data->update_lock); in store_beep_mask()
1104 mutex_lock(&data->update_lock); in store_beep_enable()
1106 data->beep_enable = val ? 1 : 0; in store_beep_enable()
1109 data->beep_mask &= ~GLOBAL_BEEP_ENABLE_MASK; in store_beep_enable()
1110 data->beep_mask |= (data->beep_enable << GLOBAL_BEEP_ENABLE_SHIFT); in store_beep_enable()
1116 val = (data->beep_mask >> 8) & 0xff; in store_beep_enable()
1120 mutex_unlock(&data->update_lock); in store_beep_enable()
1137 return sprintf(buf, "%d\n", vid_from_reg(data->vid, data->vrm)); in cpu0_vid_show()
1146 return sprintf(buf, "%d\n", data->vrm); in vrm_show()
1167 return -EINVAL; in vrm_store()
1169 data->vrm = val; in vrm_store()
1238 * Separate group of attributes for fan/pwm 4-5. Their pins can also be
1239 * in use for GPIO in which case their sysfs-interface should not be made
1256 struct i2c_adapter *adapter = client->adapter; in w83791d_detect_subclients()
1257 int address = client->addr; in w83791d_detect_subclients()
1266 dev_err(&client->dev, in w83791d_detect_subclients()
1268 "address %d; must be 0x48-0x4f\n", in w83791d_detect_subclients()
1270 return -ENODEV; in w83791d_detect_subclients()
1281 dev_err(&client->dev, in w83791d_detect_subclients()
1283 return -ENODEV; in w83791d_detect_subclients()
1287 devm_i2c_new_dummy_device(&client->dev, adapter, 0x48 + (val & 0x7)); in w83791d_detect_subclients()
1290 devm_i2c_new_dummy_device(&client->dev, adapter, 0x48 + ((val >> 4) & 0x7)); in w83791d_detect_subclients()
1296 /* Return 0 if detection is successful, -ENODEV otherwise */
1300 struct i2c_adapter *adapter = client->adapter; in w83791d_detect()
1302 unsigned short address = client->addr; in w83791d_detect()
1305 return -ENODEV; in w83791d_detect()
1308 return -ENODEV; in w83791d_detect()
1316 return -ENODEV; in w83791d_detect()
1324 return -ENODEV; in w83791d_detect()
1334 return -ENODEV; in w83791d_detect()
1336 strscpy(info->type, "w83791d", I2C_NAME_SIZE); in w83791d_detect()
1344 struct device *dev = &client->dev; in w83791d_probe()
1355 data = devm_kzalloc(&client->dev, sizeof(struct w83791d_data), in w83791d_probe()
1358 return -ENOMEM; in w83791d_probe()
1361 mutex_init(&data->update_lock); in w83791d_probe()
1375 data->fan_min[i] = w83791d_read(client, W83791D_REG_FAN_MIN[i]); in w83791d_probe()
1378 err = sysfs_create_group(&client->dev.kobj, &w83791d_group); in w83791d_probe()
1382 /* Check if pins of fan/pwm 4-5 are in use as GPIO */ in w83791d_probe()
1385 err = sysfs_create_group(&client->dev.kobj, in w83791d_probe()
1392 data->hwmon_dev = hwmon_device_register(dev); in w83791d_probe()
1393 if (IS_ERR(data->hwmon_dev)) { in w83791d_probe()
1394 err = PTR_ERR(data->hwmon_dev); in w83791d_probe()
1402 sysfs_remove_group(&client->dev.kobj, &w83791d_group_fanpwm45); in w83791d_probe()
1404 sysfs_remove_group(&client->dev.kobj, &w83791d_group); in w83791d_probe()
1412 hwmon_device_unregister(data->hwmon_dev); in w83791d_remove()
1413 sysfs_remove_group(&client->dev.kobj, &w83791d_group); in w83791d_remove()
1433 * the hard reset puts everything into a power-on state so I'm in w83791d_init_client()
1445 /* ... disable power-on abnormal beep */ in w83791d_init_client()
1453 /* Make sure monitoring is turned on for add-ons */ in w83791d_init_client()
1472 data->vrm = vid_which_vrm(); in w83791d_init_client()
1483 mutex_lock(&data->update_lock); in w83791d_update_device()
1485 if (time_after(jiffies, data->last_updated + (HZ * 3)) in w83791d_update_device()
1486 || !data->valid) { in w83791d_update_device()
1491 data->in[i] = w83791d_read(client, in w83791d_update_device()
1493 data->in_max[i] = w83791d_read(client, in w83791d_update_device()
1495 data->in_min[i] = w83791d_read(client, in w83791d_update_device()
1502 data->fan[i] = w83791d_read(client, in w83791d_update_device()
1504 data->fan_min[i] = w83791d_read(client, in w83791d_update_device()
1513 data->fan_div[0] = (reg_array_tmp[0] >> 4) & 0x03; in w83791d_update_device()
1514 data->fan_div[1] = (reg_array_tmp[0] >> 6) & 0x03; in w83791d_update_device()
1515 data->fan_div[2] = (reg_array_tmp[1] >> 6) & 0x03; in w83791d_update_device()
1516 data->fan_div[3] = reg_array_tmp[2] & 0x07; in w83791d_update_device()
1517 data->fan_div[4] = (reg_array_tmp[2] >> 4) & 0x07; in w83791d_update_device()
1520 * The fan divisor for fans 0-2 get bit 2 from in w83791d_update_device()
1521 * bits 5-7 respectively of vbat register in w83791d_update_device()
1525 data->fan_div[i] |= (vbat_reg >> (3 + i)) & 0x04; in w83791d_update_device()
1529 data->pwm[i] = w83791d_read(client, in w83791d_update_device()
1538 data->pwm_enable[0] = (reg_array_tmp[0] >> 2) & 0x03; in w83791d_update_device()
1539 data->pwm_enable[1] = (reg_array_tmp[0] >> 4) & 0x03; in w83791d_update_device()
1540 data->pwm_enable[2] = (reg_array_tmp[1] >> 2) & 0x03; in w83791d_update_device()
1544 data->temp_target[i] = w83791d_read(client, in w83791d_update_device()
1553 data->temp_tolerance[0] = reg_array_tmp[0] & 0x0f; in w83791d_update_device()
1554 data->temp_tolerance[1] = (reg_array_tmp[0] >> 4) & 0x0f; in w83791d_update_device()
1555 data->temp_tolerance[2] = reg_array_tmp[1] & 0x0f; in w83791d_update_device()
1559 data->temp1[i] = w83791d_read(client, in w83791d_update_device()
1563 /* Update the rest of the temperature sensors */ in w83791d_update_device()
1566 data->temp_add[i][j] = in w83791d_update_device()
1575 data->alarms = in w83791d_update_device()
1581 data->beep_mask = in w83791d_update_device()
1587 data->beep_enable = in w83791d_update_device()
1588 (data->beep_mask >> GLOBAL_BEEP_ENABLE_SHIFT) & 0x01; in w83791d_update_device()
1592 data->vid = i & 0x0f; in w83791d_update_device()
1593 data->vid |= (w83791d_read(client, W83791D_REG_DID_VID4) & 0x01) in w83791d_update_device()
1596 data->last_updated = jiffies; in w83791d_update_device()
1597 data->valid = true; in w83791d_update_device()
1600 mutex_unlock(&data->update_lock); in w83791d_update_device()
1617 dev_dbg(dev, "vin[%d] is: 0x%02x\n", i, data->in[i]); in w83791d_print_debug()
1618 dev_dbg(dev, "vin[%d] min is: 0x%02x\n", i, data->in_min[i]); in w83791d_print_debug()
1619 dev_dbg(dev, "vin[%d] max is: 0x%02x\n", i, data->in_max[i]); in w83791d_print_debug()
1623 dev_dbg(dev, "fan[%d] is: 0x%02x\n", i, data->fan[i]); in w83791d_print_debug()
1624 dev_dbg(dev, "fan[%d] min is: 0x%02x\n", i, data->fan_min[i]); in w83791d_print_debug()
1625 dev_dbg(dev, "fan_div[%d] is: 0x%02x\n", i, data->fan_div[i]); in w83791d_print_debug()
1634 dev_dbg(dev, "temp1[%d] is: 0x%02x\n", i, (u8) data->temp1[i]); in w83791d_print_debug()
1638 (u16) data->temp_add[i][j]); in w83791d_print_debug()
1643 dev_dbg(dev, "alarm is: 0x%08x\n", data->alarms); in w83791d_print_debug()
1644 dev_dbg(dev, "beep_mask is: 0x%08x\n", data->beep_mask); in w83791d_print_debug()
1645 dev_dbg(dev, "beep_enable is: %d\n", data->beep_enable); in w83791d_print_debug()
1646 dev_dbg(dev, "vid is: 0x%02x\n", data->vid); in w83791d_print_debug()
1647 dev_dbg(dev, "vrm is: 0x%02x\n", data->vrm); in w83791d_print_debug()