Lines Matching +full:thermal +full:- +full:diode

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * nct6683 - Driver for the hardware monitoring functionality of
6 * Copyright (C) 2013 Guenter Roeck <linux@roeck-us.net>
9 * Copyright (C) 2012, 2013 Guenter Roeck <linux@roeck-us.net>
31 #include <linux/hwmon-sysfs.h>
58 * Super-I/O constants and functions
104 return -EBUSY; in superio_enter()
198 "Diode 0 (curr)",
199 "Diode 1 (curr)",
200 "Diode 2 (curr)",
201 "Diode 0 (volt)",
202 "Diode 1 (volt)",
203 "Diode 2 (volt)",
299 /* ------------------------------------------------------- */
421 return ERR_PTR(-EINVAL); in nct6683_create_attr_group()
423 t = tg->templates; in nct6683_create_attr_group()
428 return ERR_PTR(-EINVAL); in nct6683_create_attr_group()
432 return ERR_PTR(-ENOMEM); in nct6683_create_attr_group()
437 return ERR_PTR(-ENOMEM); in nct6683_create_attr_group()
442 return ERR_PTR(-ENOMEM); in nct6683_create_attr_group()
444 group->attrs = attrs; in nct6683_create_attr_group()
445 group->is_visible = tg->is_visible; in nct6683_create_attr_group()
448 t = tg->templates; in nct6683_create_attr_group()
450 snprintf(su->name, sizeof(su->name), in nct6683_create_attr_group()
451 (*t)->dev_attr.attr.name, tg->base + i); in nct6683_create_attr_group()
452 if ((*t)->s2) { in nct6683_create_attr_group()
453 a2 = &su->u.a2; in nct6683_create_attr_group()
454 sysfs_attr_init(&a2->dev_attr.attr); in nct6683_create_attr_group()
455 a2->dev_attr.attr.name = su->name; in nct6683_create_attr_group()
456 a2->nr = (*t)->u.s.nr + i; in nct6683_create_attr_group()
457 a2->index = (*t)->u.s.index; in nct6683_create_attr_group()
458 a2->dev_attr.attr.mode = in nct6683_create_attr_group()
459 (*t)->dev_attr.attr.mode; in nct6683_create_attr_group()
460 a2->dev_attr.show = (*t)->dev_attr.show; in nct6683_create_attr_group()
461 a2->dev_attr.store = (*t)->dev_attr.store; in nct6683_create_attr_group()
462 *attrs = &a2->dev_attr.attr; in nct6683_create_attr_group()
464 a = &su->u.a1; in nct6683_create_attr_group()
465 sysfs_attr_init(&a->dev_attr.attr); in nct6683_create_attr_group()
466 a->dev_attr.attr.name = su->name; in nct6683_create_attr_group()
467 a->index = (*t)->u.index + i; in nct6683_create_attr_group()
468 a->dev_attr.attr.mode = in nct6683_create_attr_group()
469 (*t)->dev_attr.attr.mode; in nct6683_create_attr_group()
470 a->dev_attr.show = (*t)->dev_attr.show; in nct6683_create_attr_group()
471 a->dev_attr.store = (*t)->dev_attr.store; in nct6683_create_attr_group()
472 *attrs = &a->dev_attr.attr; in nct6683_create_attr_group()
503 outb_p(0xff, data->addr + EC_PAGE_REG); /* unlock */ in nct6683_read()
504 outb_p(reg >> 8, data->addr + EC_PAGE_REG); in nct6683_read()
505 outb_p(reg & 0xff, data->addr + EC_INDEX_REG); in nct6683_read()
506 res = inb_p(data->addr + EC_DATA_REG); in nct6683_read()
517 outb_p(0xff, data->addr + EC_PAGE_REG); /* unlock */ in nct6683_write()
518 outb_p(reg >> 8, data->addr + EC_PAGE_REG); in nct6683_write()
519 outb_p(reg & 0xff, data->addr + EC_INDEX_REG); in nct6683_write()
520 outb_p(value & 0xff, data->addr + EC_DATA_REG); in nct6683_write()
525 int ch = data->in_index[index]; in get_in_reg()
526 int reg = -EINVAL; in get_in_reg()
533 if (data->customer_id != NCT6683_CUSTOMER_ID_INTEL) in get_in_reg()
537 if (data->customer_id != NCT6683_CUSTOMER_ID_INTEL) in get_in_reg()
548 int ch = data->temp_index[index]; in get_temp_reg()
549 int reg = -EINVAL; in get_temp_reg()
551 switch (data->customer_id) { in get_temp_reg()
591 if (!(data->have_pwm & (1 << i))) in nct6683_update_pwm()
593 data->pwm[i] = nct6683_read(data, NCT6683_REG_PWM(i)); in nct6683_update_pwm()
602 mutex_lock(&data->update_lock); in nct6683_update_device()
604 if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { in nct6683_update_device()
606 for (i = 0; i < data->in_num; i++) { in nct6683_update_device()
611 data->in[j][i] = in nct6683_update_device()
617 for (i = 0; i < data->temp_num; i++) { in nct6683_update_device()
618 u8 ch = data->temp_index[i]; in nct6683_update_device()
620 data->temp_in[i] = nct6683_read16(data, in nct6683_update_device()
626 data->temp[j][i] = in nct6683_update_device()
632 for (i = 0; i < ARRAY_SIZE(data->rpm); i++) { in nct6683_update_device()
633 if (!(data->have_fan & (1 << i))) in nct6683_update_device()
636 data->rpm[i] = nct6683_read16(data, in nct6683_update_device()
638 data->fan_min[i] = nct6683_read16(data, in nct6683_update_device()
644 data->last_updated = jiffies; in nct6683_update_device()
645 data->valid = true; in nct6683_update_device()
648 mutex_unlock(&data->update_lock); in nct6683_update_device()
660 int nr = sattr->index; in show_in_label()
662 return sprintf(buf, "%s\n", nct6683_mon_label[data->in_src[nr]]); in show_in_label()
670 int index = sattr->index; in show_in_reg()
671 int nr = sattr->nr; in show_in_reg()
674 in_from_reg(data->in[index][nr], data->in_index[index])); in show_in_reg()
689 data->customer_id == NCT6683_CUSTOMER_ID_INTEL) in nct6683_in_is_visible()
692 return attr->mode; in nct6683_in_is_visible()
719 return sprintf(buf, "%d\n", data->rpm[sattr->index]); in show_fan()
727 int nr = sattr->index; in show_fan_min()
729 return sprintf(buf, "%d\n", data->fan_min[nr]); in show_fan_min()
739 ((data->fanin_cfg[sattr->index] >> 5) & 0x03) + 1); in show_fan_pulses()
750 if (!(data->have_fan & (1 << fan))) in nct6683_fan_is_visible()
757 if (nr == 2 && data->customer_id == NCT6683_CUSTOMER_ID_INTEL) in nct6683_fan_is_visible()
760 return attr->mode; in nct6683_fan_is_visible()
790 int nr = sattr->index; in show_temp_label()
792 return sprintf(buf, "%s\n", nct6683_mon_label[data->temp_src[nr]]); in show_temp_label()
800 int index = sattr->index; in show_temp8()
801 int nr = sattr->nr; in show_temp8()
803 return sprintf(buf, "%d\n", data->temp[index][nr] * 1000); in show_temp8()
811 int nr = sattr->index; in show_temp_hyst()
812 int temp = data->temp[1][nr] - data->temp[2][nr]; in show_temp_hyst()
822 int index = sattr->index; in show_temp16()
824 return sprintf(buf, "%d\n", (data->temp_in[index] / 128) * 500); in show_temp16()
830 * 0x02..0x07: Thermal diode
840 return 3; /* thermal diode */ in get_temp_type()
856 int nr = sattr->index; in show_temp_type()
857 return sprintf(buf, "%d\n", get_temp_type(data->temp_src[nr])); in show_temp_type()
873 data->customer_id == NCT6683_CUSTOMER_ID_INTEL) in nct6683_temp_is_visible()
876 if (nr == 6 && get_temp_type(data->temp_src[temp]) == 0) in nct6683_temp_is_visible()
879 return attr->mode; in nct6683_temp_is_visible()
918 int index = sattr->index; in show_pwm()
920 return sprintf(buf, "%d\n", data->pwm[index]); in show_pwm()
929 int index = sattr->index; in store_pwm()
933 return -EINVAL; in store_pwm()
935 mutex_lock(&data->update_lock); in store_pwm()
940 mutex_unlock(&data->update_lock); in store_pwm()
954 if (!(data->have_pwm & (1 << pwm))) in nct6683_pwm_is_visible()
958 if (data->customer_id == NCT6683_CUSTOMER_ID_MITAC) in nct6683_pwm_is_visible()
959 return attr->mode | S_IWUSR; in nct6683_pwm_is_visible()
961 return attr->mode; in nct6683_pwm_is_visible()
982 mutex_lock(&data->update_lock); in beep_enable_show()
984 ret = superio_enter(data->sioreg); in beep_enable_show()
987 superio_select(data->sioreg, NCT6683_LD_HWM); in beep_enable_show()
988 reg = superio_inb(data->sioreg, NCT6683_REG_CR_BEEP); in beep_enable_show()
989 superio_exit(data->sioreg); in beep_enable_show()
991 mutex_unlock(&data->update_lock); in beep_enable_show()
996 mutex_unlock(&data->update_lock); in beep_enable_show()
1010 return -EINVAL; in beep_enable_store()
1012 mutex_lock(&data->update_lock); in beep_enable_store()
1014 ret = superio_enter(data->sioreg); in beep_enable_store()
1020 superio_select(data->sioreg, NCT6683_LD_HWM); in beep_enable_store()
1021 reg = superio_inb(data->sioreg, NCT6683_REG_CR_BEEP); in beep_enable_store()
1026 superio_outb(data->sioreg, NCT6683_REG_CR_BEEP, reg); in beep_enable_store()
1027 superio_exit(data->sioreg); in beep_enable_store()
1029 mutex_unlock(&data->update_lock); in beep_enable_store()
1043 mutex_lock(&data->update_lock); in intrusion0_alarm_show()
1045 ret = superio_enter(data->sioreg); in intrusion0_alarm_show()
1048 superio_select(data->sioreg, NCT6683_LD_ACPI); in intrusion0_alarm_show()
1049 reg = superio_inb(data->sioreg, NCT6683_REG_CR_CASEOPEN); in intrusion0_alarm_show()
1050 superio_exit(data->sioreg); in intrusion0_alarm_show()
1052 mutex_unlock(&data->update_lock); in intrusion0_alarm_show()
1057 mutex_unlock(&data->update_lock); in intrusion0_alarm_show()
1071 return -EINVAL; in intrusion0_alarm_store()
1073 mutex_lock(&data->update_lock); in intrusion0_alarm_store()
1080 ret = superio_enter(data->sioreg); in intrusion0_alarm_store()
1086 superio_select(data->sioreg, NCT6683_LD_ACPI); in intrusion0_alarm_store()
1087 reg = superio_inb(data->sioreg, NCT6683_REG_CR_CASEOPEN); in intrusion0_alarm_store()
1089 superio_outb(data->sioreg, NCT6683_REG_CR_CASEOPEN, reg); in intrusion0_alarm_store()
1091 superio_outb(data->sioreg, NCT6683_REG_CR_CASEOPEN, reg); in intrusion0_alarm_store()
1092 superio_exit(data->sioreg); in intrusion0_alarm_store()
1094 data->valid = false; /* Force cache refresh */ in intrusion0_alarm_store()
1096 mutex_unlock(&data->update_lock); in intrusion0_alarm_store()
1137 data->have_fan |= 1 << i; in nct6683_setup_fans()
1138 data->fanin_cfg[i] = reg; in nct6683_setup_fans()
1143 data->have_pwm |= 1 << i; in nct6683_setup_fans()
1144 data->fanout_cfg[i] = reg; in nct6683_setup_fans()
1169 data->temp_num = 0; in nct6683_setup_sensors()
1170 data->in_num = 0; in nct6683_setup_sensors()
1180 data->temp_index[data->temp_num] = i; in nct6683_setup_sensors()
1181 data->temp_src[data->temp_num] = reg; in nct6683_setup_sensors()
1182 data->temp_num++; in nct6683_setup_sensors()
1184 data->in_index[data->in_num] = i; in nct6683_setup_sensors()
1185 data->in_src[data->in_num] = reg; in nct6683_setup_sensors()
1186 data->in_num++; in nct6683_setup_sensors()
1193 struct device *dev = &pdev->dev; in nct6683_probe()
1194 struct nct6683_sio_data *sio_data = dev->platform_data; in nct6683_probe()
1203 if (!devm_request_region(dev, res->start, IOREGION_LENGTH, DRVNAME)) in nct6683_probe()
1204 return -EBUSY; in nct6683_probe()
1208 return -ENOMEM; in nct6683_probe()
1210 data->kind = sio_data->kind; in nct6683_probe()
1211 data->sioreg = sio_data->sioreg; in nct6683_probe()
1212 data->addr = res->start; in nct6683_probe()
1213 mutex_init(&data->update_lock); in nct6683_probe()
1216 data->customer_id = nct6683_read16(data, NCT6683_REG_CUSTOMER_ID); in nct6683_probe()
1219 switch (data->customer_id) { in nct6683_probe()
1238 return -ENODEV; in nct6683_probe()
1239 dev_warn(dev, "Enabling support for unknown customer ID 0x%04x\n", data->customer_id); in nct6683_probe()
1249 if (data->have_pwm) { in nct6683_probe()
1252 fls(data->have_pwm)); in nct6683_probe()
1255 data->groups[groups++] = group; in nct6683_probe()
1258 if (data->in_num) { in nct6683_probe()
1261 data->in_num); in nct6683_probe()
1264 data->groups[groups++] = group; in nct6683_probe()
1267 if (data->have_fan) { in nct6683_probe()
1270 fls(data->have_fan)); in nct6683_probe()
1273 data->groups[groups++] = group; in nct6683_probe()
1276 if (data->temp_num) { in nct6683_probe()
1279 data->temp_num); in nct6683_probe()
1282 data->groups[groups++] = group; in nct6683_probe()
1284 data->groups[groups++] = &nct6683_group_other; in nct6683_probe()
1286 if (data->customer_id == NCT6683_CUSTOMER_ID_INTEL) in nct6683_probe()
1298 nct6683_chip_names[data->kind], in nct6683_probe()
1304 nct6683_device_names[data->kind], data, data->groups); in nct6683_probe()
1313 mutex_lock(&data->update_lock); in nct6683_suspend()
1314 data->hwm_cfg = nct6683_read(data, NCT6683_HWM_CFG); in nct6683_suspend()
1315 mutex_unlock(&data->update_lock); in nct6683_suspend()
1324 mutex_lock(&data->update_lock); in nct6683_resume()
1326 nct6683_write(data, NCT6683_HWM_CFG, data->hwm_cfg); in nct6683_resume()
1328 /* Force re-reading all values */ in nct6683_resume()
1329 data->valid = false; in nct6683_resume()
1330 mutex_unlock(&data->update_lock); in nct6683_resume()
1370 sio_data->kind = nct6683; in nct6683_find()
1373 sio_data->kind = nct6686; in nct6683_find()
1376 sio_data->kind = nct6687; in nct6683_find()
1403 nct6683_chip_names[sio_data->kind], sioaddr, addr); in nct6683_find()
1404 sio_data->sioreg = sioaddr; in nct6683_find()
1410 return -ENODEV; in nct6683_find()
1414 * when Super-I/O functions move to a separate file, the Super-I/O
1435 * initialize sio_data->kind and sio_data->sioreg. in sensors_nct6683_init()
1437 * when Super-I/O functions move to a separate file, the Super-I/O in sensors_nct6683_init()
1438 * driver will probe 0x2e and 0x4e and auto-detect the presence of a in sensors_nct6683_init()
1450 err = -ENOMEM; in sensors_nct6683_init()
1462 res.end = address + IOREGION_OFFSET + IOREGION_LENGTH - 1; in sensors_nct6683_init()
1482 err = -ENODEV; in sensors_nct6683_init()
1491 while (--i >= 0) { in sensors_nct6683_init()
1511 MODULE_AUTHOR("Guenter Roeck <linux@roeck-us.net>");