Lines Matching +full:sens +full:-
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * w83781d.c - Part of lm_sensors, Linux kernel modules for hardware
5 * Copyright (c) 1998 - 2001 Frodo Looijaard <frodol@dds.nl>,
8 * Copyright (c) 2007 - 2008 Jean Delvare <jdelvare@suse.de>
17 * w83781d 7 3 0 3 0x10-1 0x5ca3 yes yes
18 * w83782d 9 3 2-4 3 0x30 0x5ca3 yes yes
19 * w83783s 5-6 3 2 1-2 0x40 0x5ca3 yes no
31 #include <linux/hwmon-vid.h>
32 #include <linux/hwmon-sysfs.h>
77 (0x554 + (((nr) - 7) * 2)))
79 (0x555 + (((nr) - 7) * 2)))
81 (0x550 + (nr) - 7))
107 /* Real-time status (W83782D, W83783S) */
127 /* PWM 782D (1-4) and 783S (1-2) only */
139 /* Sensor selection - not on 781d */
165 return -1; in FAN_FROM_REG()
171 #define TEMP_TO_REG(val) clamp_val((val) / 1000, -127, 128)
212 u8 in[9]; /* Register value - 8 & 9 for 782D only */
213 u8 in_max[9]; /* Register value - 8 & 9 for 782D only */
214 u8 in_min[9]; /* Register value - 8 & 9 for 782D only */
229 u16 sens[3]; /* member
253 (long)IN_FROM_REG(data->reg[attr->index])); \
265 int nr = attr->index; \
270 mutex_lock(&data->update_lock); \
271 data->in_##reg[nr] = IN_TO_REG(val); \
273 data->in_##reg[nr]); \
275 mutex_unlock(&data->update_lock); \
306 FAN_FROM_REG(data->reg[attr->index], \
307 DIV_FROM_REG(data->fan_div[attr->index]))); \
318 int nr = attr->index; in store_fan_min()
326 mutex_lock(&data->update_lock); in store_fan_min()
327 data->fan_min[nr] = in store_fan_min()
328 FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); in store_fan_min()
330 data->fan_min[nr]); in store_fan_min()
332 mutex_unlock(&data->update_lock); in store_fan_min()
352 int nr = attr->index; \
355 LM75_TEMP_FROM_REG(data->reg##_add[nr-2])); \
357 return sprintf(buf, "%ld\n", (long)TEMP_FROM_REG(data->reg)); \
370 int nr = attr->index; \
375 mutex_lock(&data->update_lock); \
378 data->temp_##reg##_add[nr-2] = LM75_TEMP_TO_REG(val); \
380 data->temp_##reg##_add[nr-2]); \
382 data->temp_##reg = TEMP_TO_REG(val); \
384 data->temp_##reg); \
387 mutex_unlock(&data->update_lock); \
409 return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm)); in cpu0_vid_show()
418 return sprintf(buf, "%ld\n", (long) data->vrm); in vrm_show()
432 data->vrm = clamp_val(val, 0, 255); in vrm_store()
443 return sprintf(buf, "%u\n", data->alarms); in alarms_show()
452 int bitnr = to_sensor_dev_attr(attr)->index; in show_alarm()
453 return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1); in show_alarm()
461 int bitnr = (data->type == w83781d) ? 5 : 13; in show_temp3_alarm()
462 return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1); in show_temp3_alarm()
486 (long)BEEP_MASK_FROM_REG(data->beep_mask, data->type)); in beep_mask_show()
501 mutex_lock(&data->update_lock); in beep_mask_store()
502 data->beep_mask &= 0x8000; /* preserve beep enable */ in beep_mask_store()
503 data->beep_mask |= BEEP_MASK_TO_REG(val, data->type); in beep_mask_store()
505 data->beep_mask & 0xff); in beep_mask_store()
507 (data->beep_mask >> 8) & 0xff); in beep_mask_store()
508 if (data->type != w83781d && data->type != as99127f) { in beep_mask_store()
510 ((data->beep_mask) >> 16) & 0xff); in beep_mask_store()
512 mutex_unlock(&data->update_lock); in beep_mask_store()
523 int bitnr = to_sensor_dev_attr(attr)->index; in show_beep()
524 return sprintf(buf, "%u\n", (data->beep_mask >> bitnr) & 1); in show_beep()
532 int bitnr = to_sensor_dev_attr(attr)->index; in store_beep()
542 return -EINVAL; in store_beep()
544 mutex_lock(&data->update_lock); in store_beep()
546 data->beep_mask |= (1 << bitnr); in store_beep()
548 data->beep_mask &= ~(1 << bitnr); in store_beep()
560 reg |= (1 << (bitnr - 8)); in store_beep()
562 reg &= ~(1 << (bitnr - 8)); in store_beep()
567 reg |= (1 << (bitnr - 16)); in store_beep()
569 reg &= ~(1 << (bitnr - 16)); in store_beep()
572 mutex_unlock(&data->update_lock); in store_beep()
582 int bitnr = (data->type == w83781d) ? 5 : 13; in show_temp3_beep()
583 return sprintf(buf, "%u\n", (data->beep_mask >> bitnr) & 1); in show_temp3_beep()
625 (long) DIV_FROM_REG(data->fan_div[attr->index])); in show_fan_div()
641 int nr = attr->index; in store_fan_div()
650 mutex_lock(&data->update_lock); in store_fan_div()
653 min = FAN_FROM_REG(data->fan_min[nr], in store_fan_div()
654 DIV_FROM_REG(data->fan_div[nr])); in store_fan_div()
656 data->fan_div[nr] = DIV_TO_REG(val, data->type); in store_fan_div()
661 | ((data->fan_div[nr] & 0x03) << (nr == 0 ? 4 : 6)); in store_fan_div()
666 if (data->type != w83781d && data->type != as99127f) { in store_fan_div()
669 | ((data->fan_div[nr] & 0x04) << (3 + nr)); in store_fan_div()
674 data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); in store_fan_div()
675 w83781d_write_value(data, W83781D_REG_FAN_MIN(nr), data->fan_min[nr]); in store_fan_div()
677 mutex_unlock(&data->update_lock); in store_fan_div()
693 return sprintf(buf, "%d\n", (int)data->pwm[attr->index]); in show_pwm()
700 return sprintf(buf, "%d\n", (int)data->pwm2_enable); in pwm2_enable_show()
709 int nr = attr->index; in store_pwm()
717 mutex_lock(&data->update_lock); in store_pwm()
718 data->pwm[nr] = clamp_val(val, 0, 255); in store_pwm()
719 w83781d_write_value(data, W83781D_REG_PWM[nr], data->pwm[nr]); in store_pwm()
720 mutex_unlock(&data->update_lock); in store_pwm()
737 mutex_lock(&data->update_lock); in pwm2_enable_store()
750 data->pwm2_enable = val; in pwm2_enable_store()
754 mutex_unlock(&data->update_lock); in pwm2_enable_store()
755 return -EINVAL; in pwm2_enable_store()
758 mutex_unlock(&data->update_lock); in pwm2_enable_store()
774 return sprintf(buf, "%d\n", (int)data->sens[attr->index]); in show_sensor()
783 int nr = attr->index; in store_sensor()
792 mutex_lock(&data->update_lock); in store_sensor()
802 data->sens[nr] = val; in store_sensor()
811 data->sens[nr] = val; in store_sensor()
822 data->sens[nr] = val; in store_sensor()
830 mutex_unlock(&data->update_lock); in store_sensor()
850 int address = new_client->addr; in w83781d_detect_subclients()
852 struct i2c_adapter *adapter = new_client->adapter; in w83781d_detect_subclients()
854 enum chips kind = data->type; in w83781d_detect_subclients()
863 dev_err(&new_client->dev, in w83781d_detect_subclients()
864 "Invalid subclient address %d; must be 0x48-0x4f\n", in w83781d_detect_subclients()
866 err = -EINVAL; in w83781d_detect_subclients()
888 dev_err(&new_client->dev, in w83781d_detect_subclients()
891 err = -EBUSY; in w83781d_detect_subclients()
897 data->lm75[i] = i2c_new_dummy_device(adapter, sc_addr[i]); in w83781d_detect_subclients()
898 if (IS_ERR(data->lm75[i])) { in w83781d_detect_subclients()
899 dev_err(&new_client->dev, in w83781d_detect_subclients()
902 err = PTR_ERR(data->lm75[i]); in w83781d_detect_subclients()
913 i2c_unregister_device(data->lm75[0]); in w83781d_detect_subclients()
1023 err = sysfs_create_group(&dev->kobj, &w83781d_group); in w83781d_create_files()
1028 err = sysfs_create_group(&dev->kobj, &w83781d_group_in1); in w83781d_create_files()
1033 err = sysfs_create_group(&dev->kobj, &w83781d_group_in78); in w83781d_create_files()
1038 err = sysfs_create_group(&dev->kobj, &w83781d_group_temp3); in w83781d_create_files()
1043 err = sysfs_chmod_file(&dev->kobj, in w83781d_create_files()
1052 err = sysfs_create_group(&dev->kobj, &w83781d_group_pwm12); in w83781d_create_files()
1057 err = sysfs_create_group(&dev->kobj, &w83781d_group_pwm34); in w83781d_create_files()
1082 /* Return 0 if detection is successful, -ENODEV otherwise */
1088 struct i2c_adapter *adapter = client->adapter; in w83781d_detect()
1089 int address = client->addr; in w83781d_detect()
1094 return -ENODEV; in w83781d_detect()
1102 mutex_lock(&isa->update_lock); in w83781d_detect()
1105 dev_dbg(&adapter->dev, in w83781d_detect()
1116 dev_dbg(&adapter->dev, in w83781d_detect()
1128 dev_dbg(&adapter->dev, in w83781d_detect()
1146 dev_dbg(&adapter->dev, in w83781d_detect()
1165 dev_dbg(&adapter->dev, in w83781d_detect()
1172 mutex_unlock(&isa->update_lock); in w83781d_detect()
1174 strscpy(info->type, client_name, I2C_NAME_SIZE); in w83781d_detect()
1180 mutex_unlock(&isa->update_lock); in w83781d_detect()
1181 return -ENODEV; in w83781d_detect()
1186 sysfs_remove_group(&dev->kobj, &w83781d_group); in w83781d_remove_files()
1187 sysfs_remove_group(&dev->kobj, &w83781d_group_in1); in w83781d_remove_files()
1188 sysfs_remove_group(&dev->kobj, &w83781d_group_in78); in w83781d_remove_files()
1189 sysfs_remove_group(&dev->kobj, &w83781d_group_temp3); in w83781d_remove_files()
1190 sysfs_remove_group(&dev->kobj, &w83781d_group_pwm12); in w83781d_remove_files()
1191 sysfs_remove_group(&dev->kobj, &w83781d_group_pwm34); in w83781d_remove_files()
1192 sysfs_remove_group(&dev->kobj, &w83781d_group_other); in w83781d_remove_files()
1197 struct device *dev = &client->dev; in w83781d_probe()
1203 return -ENOMEM; in w83781d_probe()
1206 mutex_init(&data->lock); in w83781d_probe()
1207 mutex_init(&data->update_lock); in w83781d_probe()
1209 data->type = (uintptr_t)i2c_get_match_data(client); in w83781d_probe()
1210 data->client = client; in w83781d_probe()
1212 /* attach secondary i2c lm75-like clients */ in w83781d_probe()
1221 err = w83781d_create_files(dev, data->type, 0); in w83781d_probe()
1225 data->hwmon_dev = hwmon_device_register(dev); in w83781d_probe()
1226 if (IS_ERR(data->hwmon_dev)) { in w83781d_probe()
1227 err = PTR_ERR(data->hwmon_dev); in w83781d_probe()
1235 i2c_unregister_device(data->lm75[0]); in w83781d_probe()
1236 i2c_unregister_device(data->lm75[1]); in w83781d_probe()
1244 struct device *dev = &client->dev; in w83781d_remove()
1246 hwmon_device_unregister(data->hwmon_dev); in w83781d_remove()
1249 i2c_unregister_device(data->lm75[0]); in w83781d_remove()
1250 i2c_unregister_device(data->lm75[1]); in w83781d_remove()
1256 struct i2c_client *client = data->client; in w83781d_read_value_i2c()
1269 cl = data->lm75[bank - 1]; in w83781d_read_value_i2c()
1296 struct i2c_client *client = data->client; in w83781d_write_value_i2c()
1310 cl = data->lm75[bank - 1]; in w83781d_write_value_i2c()
1335 int type = data->type; in w83781d_init_device()
1358 * This sets fan-divs to 2, among others in w83781d_init_device()
1362 * Restore the registers and disable power-on abnormal beep. in w83781d_init_device()
1368 * Disable master beep-enable (reset turns it on). in w83781d_init_device()
1376 * Disable power-on abnormal beep, as advised by the datasheet. in w83781d_init_device()
1384 data->vrm = vid_which_vrm(); in w83781d_init_device()
1389 if (!(tmp & BIT_SCFG1[i - 1])) { in w83781d_init_device()
1390 data->sens[i - 1] = 4; in w83781d_init_device()
1394 W83781D_REG_SCFG2) & BIT_SCFG2[i - 1]) in w83781d_init_device()
1395 data->sens[i - 1] = 1; in w83781d_init_device()
1397 data->sens[i - 1] = 2; in w83781d_init_device()
1435 data->fan_min[i] = w83781d_read_value(data, in w83781d_init_device()
1439 mutex_init(&data->update_lock); in w83781d_init_device()
1445 struct i2c_client *client = data->client; in w83781d_update_device()
1448 mutex_lock(&data->update_lock); in w83781d_update_device()
1450 if (time_after(jiffies, data->last_updated + HZ + HZ / 2) in w83781d_update_device()
1451 || !data->valid) { in w83781d_update_device()
1455 if (data->type == w83783s && i == 1) in w83781d_update_device()
1457 data->in[i] = in w83781d_update_device()
1459 data->in_min[i] = in w83781d_update_device()
1461 data->in_max[i] = in w83781d_update_device()
1463 if ((data->type != w83782d) && (i == 6)) in w83781d_update_device()
1467 data->fan[i] = in w83781d_update_device()
1469 data->fan_min[i] = in w83781d_update_device()
1472 if (data->type != w83781d && data->type != as99127f) { in w83781d_update_device()
1474 data->pwm[i] = in w83781d_update_device()
1478 if ((data->type != w83782d || !client) in w83781d_update_device()
1483 data->pwm2_enable = (w83781d_read_value(data, in w83781d_update_device()
1487 data->temp = w83781d_read_value(data, W83781D_REG_TEMP(1)); in w83781d_update_device()
1488 data->temp_max = in w83781d_update_device()
1490 data->temp_max_hyst = in w83781d_update_device()
1492 data->temp_add[0] = in w83781d_update_device()
1494 data->temp_max_add[0] = in w83781d_update_device()
1496 data->temp_max_hyst_add[0] = in w83781d_update_device()
1498 if (data->type != w83783s) { in w83781d_update_device()
1499 data->temp_add[1] = in w83781d_update_device()
1501 data->temp_max_add[1] = in w83781d_update_device()
1504 data->temp_max_hyst_add[1] = in w83781d_update_device()
1509 data->vid = i & 0x0f; in w83781d_update_device()
1510 data->vid |= (w83781d_read_value(data, in w83781d_update_device()
1512 data->fan_div[0] = (i >> 4) & 0x03; in w83781d_update_device()
1513 data->fan_div[1] = (i >> 6) & 0x03; in w83781d_update_device()
1514 data->fan_div[2] = (w83781d_read_value(data, in w83781d_update_device()
1516 if ((data->type != w83781d) && (data->type != as99127f)) { in w83781d_update_device()
1518 data->fan_div[0] |= (i >> 3) & 0x04; in w83781d_update_device()
1519 data->fan_div[1] |= (i >> 4) & 0x04; in w83781d_update_device()
1520 data->fan_div[2] |= (i >> 5) & 0x04; in w83781d_update_device()
1522 if (data->type == w83782d) { in w83781d_update_device()
1523 data->alarms = w83781d_read_value(data, in w83781d_update_device()
1529 } else if (data->type == w83783s) { in w83781d_update_device()
1530 data->alarms = w83781d_read_value(data, in w83781d_update_device()
1536 * No real-time status registers, fall back to in w83781d_update_device()
1539 data->alarms = w83781d_read_value(data, in w83781d_update_device()
1545 data->beep_mask = (i << 8) + in w83781d_update_device()
1547 if ((data->type != w83781d) && (data->type != as99127f)) { in w83781d_update_device()
1548 data->beep_mask |= in w83781d_update_device()
1552 data->last_updated = jiffies; in w83781d_update_device()
1553 data->valid = true; in w83781d_update_device()
1556 mutex_unlock(&data->update_lock); in w83781d_update_device()
1611 return sprintf(buf, "%s\n", data->name); in name_show()
1631 if (w83781d_read_value(isa, W83781D_REG_I2C_ADDR) != client->addr) in w83781d_alias_detect()
1669 data->isa_addr + W83781D_ADDR_REG_OFFSET); in w83781d_read_value_isa()
1671 data->isa_addr + W83781D_DATA_REG_OFFSET); in w83781d_read_value_isa()
1673 outb_p(reg & 0xff, data->isa_addr + W83781D_ADDR_REG_OFFSET); in w83781d_read_value_isa()
1674 res = inb_p(data->isa_addr + W83781D_DATA_REG_OFFSET); in w83781d_read_value_isa()
1677 data->isa_addr + W83781D_ADDR_REG_OFFSET); in w83781d_read_value_isa()
1679 (res << 8) + inb_p(data->isa_addr + in w83781d_read_value_isa()
1684 data->isa_addr + W83781D_ADDR_REG_OFFSET); in w83781d_read_value_isa()
1685 outb_p(0, data->isa_addr + W83781D_DATA_REG_OFFSET); in w83781d_read_value_isa()
1701 data->isa_addr + W83781D_ADDR_REG_OFFSET); in w83781d_write_value_isa()
1703 data->isa_addr + W83781D_DATA_REG_OFFSET); in w83781d_write_value_isa()
1705 outb_p(reg & 0xff, data->isa_addr + W83781D_ADDR_REG_OFFSET); in w83781d_write_value_isa()
1708 data->isa_addr + W83781D_DATA_REG_OFFSET); in w83781d_write_value_isa()
1710 data->isa_addr + W83781D_ADDR_REG_OFFSET); in w83781d_write_value_isa()
1712 outb_p(value & 0xff, data->isa_addr + W83781D_DATA_REG_OFFSET); in w83781d_write_value_isa()
1715 data->isa_addr + W83781D_ADDR_REG_OFFSET); in w83781d_write_value_isa()
1716 outb_p(0, data->isa_addr + W83781D_DATA_REG_OFFSET); in w83781d_write_value_isa()
1723 * We ignore the W83781D BUSY flag at this moment - it could lead to deadlocks,
1725 * There are some ugly typecasts here, but the good news is - they should
1731 struct i2c_client *client = data->client; in w83781d_read_value()
1734 mutex_lock(&data->lock); in w83781d_read_value()
1739 mutex_unlock(&data->lock); in w83781d_read_value()
1746 struct i2c_client *client = data->client; in w83781d_write_value()
1748 mutex_lock(&data->lock); in w83781d_write_value()
1753 mutex_unlock(&data->lock); in w83781d_write_value()
1766 if (!devm_request_region(&pdev->dev, in w83781d_isa_probe()
1767 res->start + W83781D_ADDR_REG_OFFSET, 2, in w83781d_isa_probe()
1769 return -EBUSY; in w83781d_isa_probe()
1771 data = devm_kzalloc(&pdev->dev, sizeof(struct w83781d_data), in w83781d_isa_probe()
1774 return -ENOMEM; in w83781d_isa_probe()
1776 mutex_init(&data->lock); in w83781d_isa_probe()
1777 data->isa_addr = res->start; in w83781d_isa_probe()
1783 data->type = w83782d; in w83781d_isa_probe()
1784 data->name = "w83782d"; in w83781d_isa_probe()
1787 data->type = w83781d; in w83781d_isa_probe()
1788 data->name = "w83781d"; in w83781d_isa_probe()
1792 w83781d_init_device(&pdev->dev); in w83781d_isa_probe()
1795 err = w83781d_create_files(&pdev->dev, data->type, 1); in w83781d_isa_probe()
1799 err = device_create_file(&pdev->dev, &dev_attr_name); in w83781d_isa_probe()
1803 data->hwmon_dev = hwmon_device_register(&pdev->dev); in w83781d_isa_probe()
1804 if (IS_ERR(data->hwmon_dev)) { in w83781d_isa_probe()
1805 err = PTR_ERR(data->hwmon_dev); in w83781d_isa_probe()
1812 w83781d_remove_files(&pdev->dev); in w83781d_isa_probe()
1813 device_remove_file(&pdev->dev, &dev_attr_name); in w83781d_isa_probe()
1821 hwmon_device_unregister(data->hwmon_dev); in w83781d_isa_remove()
1822 w83781d_remove_files(&pdev->dev); in w83781d_isa_remove()
1823 device_remove_file(&pdev->dev, &dev_attr_name); in w83781d_isa_remove()
1855 * We need the timeouts for at least some W83781D-like in w83781d_isa_found()
1928 for (port--; port >= address; port--) in w83781d_isa_found()
1938 .end = address + W83781D_EXTENT - 1, in w83781d_isa_device_add()
1946 err = -ENOMEM; in w83781d_isa_device_add()
2022 mutex_lock(&data->lock); in w83781d_read_value()
2024 mutex_unlock(&data->lock); in w83781d_read_value()
2032 mutex_lock(&data->lock); in w83781d_write_value()
2034 mutex_unlock(&data->lock); in w83781d_write_value()