Lines Matching +full:in7 +full:- +full:in6

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * w83792d.c - Part of lm_sensors, Linux kernel modules for hardware
13 * calculation method to in6-in7(measured value, limits) is a little
30 #include <linux/hwmon-sysfs.h>
153 0x87, /* (bit3-0)SmartFan Fan1 tolerance */
154 0x87, /* (bit7-4)SmartFan Fan2 tolerance */
155 0x97 /* (bit3-0)SmartFan Fan3 tolerance */
174 { 0x88, /* (bit3-0) SmartFanII: Fan1 Non-Stop */
175 0x88, /* (bit7-4) SmartFanII: Fan1 Level 1 */
176 0xE0, /* (bit7-4) SmartFanII: Fan1 Level 2 */
177 0xE0 }, /* (bit3-0) SmartFanII: Fan1 Level 3 */
178 { 0x89, /* (bit3-0) SmartFanII: Fan2 Non-Stop */
179 0x89, /* (bit7-4) SmartFanII: Fan2 Level 1 */
180 0xE1, /* (bit7-4) SmartFanII: Fan2 Level 2 */
181 0xE1 }, /* (bit3-0) SmartFanII: Fan2 Level 3 */
182 { 0x98, /* (bit3-0) SmartFanII: Fan3 Non-Stop */
183 0x98, /* (bit7-4) SmartFanII: Fan3 Level 1 */
184 0xE2, /* (bit7-4) SmartFanII: Fan3 Level 2 */
185 0xE2 } /* (bit3-0) SmartFanII: Fan3 Level 3 */
229 #define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : \
236 #define TEMP1_FROM_REG(val) (((val) & 0x80 ? (val)-0x100 : (val)) * 1000)
239 ((((val1) & 0x80 ? (val1)-0x100 \
270 u16 low_bits; /* Additional resolution to voltage in6-0 */
318 /* in7 and in8 do not have low bits, but the formula still works */ in in_count_from_reg()
319 return (data->in[nr] << 2) | ((data->low_bits >> (2 * nr)) & 0x03); in in_count_from_reg()
343 int nr = sensor_attr->index; in show_in()
355 int nr = sensor_attr->index; \
358 (long)(IN_FROM_REG(nr, data->reg[nr]) * 4)); \
371 int nr = sensor_attr->index; \
378 mutex_lock(&data->update_lock); \
379 data->in_##reg[nr] = clamp_val(IN_TO_REG(nr, val) / 4, 0, 255); \
381 data->in_##reg[nr]); \
382 mutex_unlock(&data->update_lock); \
395 int nr = sensor_attr->index - 1; \
398 FAN_FROM_REG(data->reg[nr], DIV_FROM_REG(data->fan_div[nr]))); \
409 int nr = sensor_attr->index - 1; in store_fan_min()
419 mutex_lock(&data->update_lock); in store_fan_min()
420 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); in store_fan_min()
422 data->fan_min[nr]); in store_fan_min()
423 mutex_unlock(&data->update_lock); in store_fan_min()
433 int nr = sensor_attr->index; in show_fan_div()
435 return sprintf(buf, "%u\n", DIV_FROM_REG(data->fan_div[nr - 1])); in show_fan_div()
449 int nr = sensor_attr->index - 1; in store_fan_div()
464 mutex_lock(&data->update_lock); in store_fan_div()
465 min = FAN_FROM_REG(data->fan_min[nr], in store_fan_div()
466 DIV_FROM_REG(data->fan_div[nr])); in store_fan_div()
468 data->fan_div[nr] = DIV_TO_REG(val); in store_fan_div()
472 tmp_fan_div = (nr & 0x01) ? (((data->fan_div[nr]) << 4) & 0x70) in store_fan_div()
473 : ((data->fan_div[nr]) & 0x07); in store_fan_div()
478 data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); in store_fan_div()
479 w83792d_write_value(client, W83792D_REG_FAN_MIN[nr], data->fan_min[nr]); in store_fan_div()
480 mutex_unlock(&data->update_lock); in store_fan_div()
491 int nr = sensor_attr->index; in show_temp1()
493 return sprintf(buf, "%d\n", TEMP1_FROM_REG(data->temp1[nr])); in show_temp1()
500 int nr = sensor_attr->index; in store_temp1()
510 mutex_lock(&data->update_lock); in store_temp1()
511 data->temp1[nr] = TEMP1_TO_REG(val); in store_temp1()
513 data->temp1[nr]); in store_temp1()
514 mutex_unlock(&data->update_lock); in store_temp1()
519 /* read/write the temperature2-3, includes measured value and limits */
526 int nr = sensor_attr->nr; in show_temp23()
527 int index = sensor_attr->index; in show_temp23()
530 (long)TEMP_ADD_FROM_REG(data->temp_add[nr][index], in show_temp23()
531 data->temp_add[nr][index+1])); in show_temp23()
539 int nr = sensor_attr->nr; in store_temp23()
540 int index = sensor_attr->index; in store_temp23()
550 mutex_lock(&data->update_lock); in store_temp23()
551 data->temp_add[nr][index] = TEMP_ADD_TO_REG_HIGH(val); in store_temp23()
552 data->temp_add[nr][index+1] = TEMP_ADD_TO_REG_LOW(val); in store_temp23()
554 data->temp_add[nr][index]); in store_temp23()
556 data->temp_add[nr][index+1]); in store_temp23()
557 mutex_unlock(&data->update_lock); in store_temp23()
567 return sprintf(buf, "%d\n", data->alarms); in alarms_show()
574 int nr = sensor_attr->index; in show_alarm()
576 return sprintf(buf, "%d\n", (data->alarms >> nr) & 1); in show_alarm()
584 int nr = sensor_attr->index; in show_pwm()
586 return sprintf(buf, "%d\n", (data->pwm[nr] & 0x0f) << 4); in show_pwm()
594 int nr = sensor_attr->index - 1; in show_pwmenable()
598 switch (data->pwmenable[nr]) { in show_pwmenable()
618 int nr = sensor_attr->index; in store_pwm()
629 mutex_lock(&data->update_lock); in store_pwm()
631 data->pwm[nr] = val; in store_pwm()
632 w83792d_write_value(client, W83792D_REG_PWM[nr], data->pwm[nr]); in store_pwm()
633 mutex_unlock(&data->update_lock); in store_pwm()
643 int nr = sensor_attr->index - 1; in store_pwmenable()
655 return -EINVAL; in store_pwmenable()
657 mutex_lock(&data->update_lock); in store_pwmenable()
660 data->pwmenable[nr] = 0; /* manual mode */ in store_pwmenable()
663 data->pwmenable[nr] = 2; /* Smart Fan II */ in store_pwmenable()
666 data->pwmenable[nr] = 1; /* thermal cruise/Smart Fan I */ in store_pwmenable()
669 cfg1_tmp = data->pwmenable[0]; in store_pwmenable()
670 cfg2_tmp = (data->pwmenable[1]) << 2; in store_pwmenable()
671 cfg3_tmp = (data->pwmenable[2]) << 4; in store_pwmenable()
675 mutex_unlock(&data->update_lock); in store_pwmenable()
685 int nr = sensor_attr->index; in show_pwm_mode()
687 return sprintf(buf, "%d\n", data->pwm[nr] >> 7); in show_pwm_mode()
695 int nr = sensor_attr->index; in store_pwm_mode()
705 return -EINVAL; in store_pwm_mode()
707 mutex_lock(&data->update_lock); in store_pwm_mode()
708 data->pwm[nr] = w83792d_read_value(client, W83792D_REG_PWM[nr]); in store_pwm_mode()
710 data->pwm[nr] |= 0x80; in store_pwm_mode()
712 data->pwm[nr] &= 0x7f; in store_pwm_mode()
714 w83792d_write_value(client, W83792D_REG_PWM[nr], data->pwm[nr]); in store_pwm_mode()
715 mutex_unlock(&data->update_lock); in store_pwm_mode()
725 return sprintf(buf, "%d\n", data->chassis); in intrusion0_alarm_show()
738 return -EINVAL; in intrusion0_alarm_store()
740 mutex_lock(&data->update_lock); in intrusion0_alarm_store()
743 data->valid = false; /* Force cache refresh */ in intrusion0_alarm_store()
744 mutex_unlock(&data->update_lock); in intrusion0_alarm_store()
755 int nr = sensor_attr->index; in show_thermal_cruise()
757 return sprintf(buf, "%ld\n", (long)data->thermal_cruise[nr-1]); in show_thermal_cruise()
765 int nr = sensor_attr->index - 1; in store_thermal_cruise()
778 mutex_lock(&data->update_lock); in store_thermal_cruise()
781 data->thermal_cruise[nr] = clamp_val(target_tmp, 0, 255); in store_thermal_cruise()
783 (data->thermal_cruise[nr]) | target_mask); in store_thermal_cruise()
784 mutex_unlock(&data->update_lock); in store_thermal_cruise()
795 int nr = sensor_attr->index; in show_tolerance()
797 return sprintf(buf, "%ld\n", (long)data->tolerance[nr-1]); in show_tolerance()
805 int nr = sensor_attr->index - 1; in store_tolerance()
816 mutex_lock(&data->update_lock); in store_tolerance()
821 data->tolerance[nr] = tol_tmp; in store_tolerance()
826 mutex_unlock(&data->update_lock); in store_tolerance()
838 int nr = sensor_attr->nr; in show_sf2_point()
839 int index = sensor_attr->index; in show_sf2_point()
841 return sprintf(buf, "%ld\n", (long)data->sf2_points[index-1][nr-1]); in show_sf2_point()
850 int nr = sensor_attr->nr - 1; in store_sf2_point()
851 int index = sensor_attr->index - 1; in store_sf2_point()
862 mutex_lock(&data->update_lock); in store_sf2_point()
863 data->sf2_points[index][nr] = clamp_val(val, 0, 127); in store_sf2_point()
867 mask_tmp|data->sf2_points[index][nr]); in store_sf2_point()
868 mutex_unlock(&data->update_lock); in store_sf2_point()
879 int nr = sensor_attr->nr; in show_sf2_level()
880 int index = sensor_attr->index; in show_sf2_level()
883 (((data->sf2_levels[index-1][nr]) * 100) / 15)); in show_sf2_level()
892 int nr = sensor_attr->nr; in store_sf2_level()
893 int index = sensor_attr->index - 1; in store_sf2_level()
904 mutex_lock(&data->update_lock); in store_sf2_level()
905 data->sf2_levels[index][nr] = clamp_val((val * 15) / 100, 0, 15); in store_sf2_level()
909 level_tmp = data->sf2_levels[index][nr]; in store_sf2_level()
911 level_tmp = data->sf2_levels[index][nr] << 4; in store_sf2_level()
914 mutex_unlock(&data->update_lock); in store_sf2_level()
924 int address = new_client->addr; in w83792d_detect_subclients()
926 struct i2c_adapter *adapter = new_client->adapter; in w83792d_detect_subclients()
933 dev_err(&new_client->dev, in w83792d_detect_subclients()
934 "invalid subclient address %d; must be 0x48-0x4f\n", in w83792d_detect_subclients()
936 return -ENODEV; in w83792d_detect_subclients()
947 dev_err(&new_client->dev, in w83792d_detect_subclients()
949 return -ENODEV; in w83792d_detect_subclients()
953 devm_i2c_new_dummy_device(&new_client->dev, adapter, 0x48 + (val & 0x7)); in w83792d_detect_subclients()
956 devm_i2c_new_dummy_device(&new_client->dev, adapter, 0x48 + ((val >> 4) & 0x7)); in w83792d_detect_subclients()
1308 /* Return 0 if detection is successful, -ENODEV otherwise */
1312 struct i2c_adapter *adapter = client->adapter; in w83792d_detect()
1314 unsigned short address = client->addr; in w83792d_detect()
1317 return -ENODEV; in w83792d_detect()
1320 return -ENODEV; in w83792d_detect()
1328 return -ENODEV; in w83792d_detect()
1335 return -ENODEV; in w83792d_detect()
1347 return -ENODEV; in w83792d_detect()
1349 strscpy(info->type, "w83792d", I2C_NAME_SIZE); in w83792d_detect()
1358 struct device *dev = &client->dev; in w83792d_probe()
1363 return -ENOMEM; in w83792d_probe()
1366 mutex_init(&data->update_lock); in w83792d_probe()
1377 data->fan_min[i] = w83792d_read_value(client, in w83792d_probe()
1382 err = sysfs_create_group(&dev->kobj, &w83792d_group); in w83792d_probe()
1393 err = sysfs_create_group(&dev->kobj, &w83792d_group_fan[0]); in w83792d_probe()
1399 err = sysfs_create_group(&dev->kobj, &w83792d_group_fan[1]); in w83792d_probe()
1406 err = sysfs_create_group(&dev->kobj, &w83792d_group_fan[2]); in w83792d_probe()
1412 err = sysfs_create_group(&dev->kobj, &w83792d_group_fan[3]); in w83792d_probe()
1417 data->hwmon_dev = hwmon_device_register(dev); in w83792d_probe()
1418 if (IS_ERR(data->hwmon_dev)) { in w83792d_probe()
1419 err = PTR_ERR(data->hwmon_dev); in w83792d_probe()
1426 sysfs_remove_group(&dev->kobj, &w83792d_group); in w83792d_probe()
1428 sysfs_remove_group(&dev->kobj, &w83792d_group_fan[i]); in w83792d_probe()
1438 hwmon_device_unregister(data->hwmon_dev); in w83792d_remove()
1439 sysfs_remove_group(&client->dev.kobj, &w83792d_group); in w83792d_remove()
1441 sysfs_remove_group(&client->dev.kobj, in w83792d_remove()
1458 * vin0/vin1 auto-updated, can NOT be modified by user. in w83792d_init_client()
1485 mutex_lock(&data->update_lock); in w83792d_update_device()
1488 (jiffies - data->last_updated, (unsigned long) (HZ * 3)) in w83792d_update_device()
1489 || time_before(jiffies, data->last_updated) || !data->valid) { in w83792d_update_device()
1494 data->in[i] = w83792d_read_value(client, in w83792d_update_device()
1496 data->in_max[i] = w83792d_read_value(client, in w83792d_update_device()
1498 data->in_min[i] = w83792d_read_value(client, in w83792d_update_device()
1501 data->low_bits = w83792d_read_value(client, in w83792d_update_device()
1507 data->fan[i] = w83792d_read_value(client, in w83792d_update_device()
1509 data->fan_min[i] = w83792d_read_value(client, in w83792d_update_device()
1512 data->pwm[i] = w83792d_read_value(client, in w83792d_update_device()
1517 data->pwmenable[0] = reg_tmp & 0x03; in w83792d_update_device()
1518 data->pwmenable[1] = (reg_tmp>>2) & 0x03; in w83792d_update_device()
1519 data->pwmenable[2] = (reg_tmp>>4) & 0x03; in w83792d_update_device()
1522 data->temp1[i] = w83792d_read_value(client, in w83792d_update_device()
1527 data->temp_add[i][j] = w83792d_read_value( in w83792d_update_device()
1537 data->fan_div[0] = reg_array_tmp[0] & 0x07; in w83792d_update_device()
1538 data->fan_div[1] = (reg_array_tmp[0] >> 4) & 0x07; in w83792d_update_device()
1539 data->fan_div[2] = reg_array_tmp[1] & 0x07; in w83792d_update_device()
1540 data->fan_div[3] = (reg_array_tmp[1] >> 4) & 0x07; in w83792d_update_device()
1541 data->fan_div[4] = reg_array_tmp[2] & 0x07; in w83792d_update_device()
1542 data->fan_div[5] = (reg_array_tmp[2] >> 4) & 0x07; in w83792d_update_device()
1543 data->fan_div[6] = reg_array_tmp[3] & 0x07; in w83792d_update_device()
1546 data->alarms = w83792d_read_value(client, W83792D_REG_ALARM1) + in w83792d_update_device()
1551 data->chassis = (w83792d_read_value(client, in w83792d_update_device()
1556 data->thermal_cruise[i] = in w83792d_update_device()
1563 data->tolerance[0] = reg_tmp & 0x0f; in w83792d_update_device()
1564 data->tolerance[1] = (reg_tmp >> 4) & 0x0f; in w83792d_update_device()
1565 data->tolerance[2] = w83792d_read_value(client, in w83792d_update_device()
1571 data->sf2_points[i][j] in w83792d_update_device()
1581 data->sf2_levels[i][0] = reg_tmp & 0x0f; in w83792d_update_device()
1582 data->sf2_levels[i][1] = (reg_tmp >> 4) & 0x0f; in w83792d_update_device()
1585 data->sf2_levels[i][2] = (reg_tmp >> 4) & 0x0f; in w83792d_update_device()
1586 data->sf2_levels[i][3] = reg_tmp & 0x0f; in w83792d_update_device()
1589 data->last_updated = jiffies; in w83792d_update_device()
1590 data->valid = true; in w83792d_update_device()
1593 mutex_unlock(&data->update_lock); in w83792d_update_device()
1609 dev_dbg(dev, "vin[%d] is: 0x%x\n", i, data->in[i]); in w83792d_print_debug()
1610 dev_dbg(dev, "vin[%d] max is: 0x%x\n", i, data->in_max[i]); in w83792d_print_debug()
1611 dev_dbg(dev, "vin[%d] min is: 0x%x\n", i, data->in_min[i]); in w83792d_print_debug()
1613 dev_dbg(dev, "Low Bit1 is: 0x%x\n", data->low_bits & 0xff); in w83792d_print_debug()
1614 dev_dbg(dev, "Low Bit2 is: 0x%x\n", data->low_bits >> 8); in w83792d_print_debug()
1617 dev_dbg(dev, "fan[%d] is: 0x%x\n", i, data->fan[i]); in w83792d_print_debug()
1618 dev_dbg(dev, "fan[%d] min is: 0x%x\n", i, data->fan_min[i]); in w83792d_print_debug()
1619 dev_dbg(dev, "pwm[%d] is: 0x%x\n", i, data->pwm[i]); in w83792d_print_debug()
1623 dev_dbg(dev, "temp1[%d] is: 0x%x\n", i, data->temp1[i]); in w83792d_print_debug()
1628 data->temp_add[i][j]); in w83792d_print_debug()
1633 dev_dbg(dev, "fan_div[%d] is: 0x%x\n", i, data->fan_div[i]); in w83792d_print_debug()
1643 MODULE_DESCRIPTION("W83792AD/D driver for linux-2.6");