Lines Matching +full:nr +full:- +full:outputs

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()
296 /* ------------------------------------------------------- */
353 u8 nr; member
358 bool s2; /* true if both index and nr are used */
384 .u.s.nr = _nr, \
418 return ERR_PTR(-EINVAL); in nct6683_create_attr_group()
420 t = tg->templates; in nct6683_create_attr_group()
425 return ERR_PTR(-EINVAL); in nct6683_create_attr_group()
429 return ERR_PTR(-ENOMEM); in nct6683_create_attr_group()
434 return ERR_PTR(-ENOMEM); in nct6683_create_attr_group()
439 return ERR_PTR(-ENOMEM); in nct6683_create_attr_group()
441 group->attrs = attrs; in nct6683_create_attr_group()
442 group->is_visible = tg->is_visible; in nct6683_create_attr_group()
445 t = tg->templates; in nct6683_create_attr_group()
447 snprintf(su->name, sizeof(su->name), in nct6683_create_attr_group()
448 (*t)->dev_attr.attr.name, tg->base + i); in nct6683_create_attr_group()
449 if ((*t)->s2) { in nct6683_create_attr_group()
450 a2 = &su->u.a2; in nct6683_create_attr_group()
451 sysfs_attr_init(&a2->dev_attr.attr); in nct6683_create_attr_group()
452 a2->dev_attr.attr.name = su->name; in nct6683_create_attr_group()
453 a2->nr = (*t)->u.s.nr + i; in nct6683_create_attr_group()
454 a2->index = (*t)->u.s.index; in nct6683_create_attr_group()
455 a2->dev_attr.attr.mode = in nct6683_create_attr_group()
456 (*t)->dev_attr.attr.mode; in nct6683_create_attr_group()
457 a2->dev_attr.show = (*t)->dev_attr.show; in nct6683_create_attr_group()
458 a2->dev_attr.store = (*t)->dev_attr.store; in nct6683_create_attr_group()
459 *attrs = &a2->dev_attr.attr; in nct6683_create_attr_group()
461 a = &su->u.a1; in nct6683_create_attr_group()
462 sysfs_attr_init(&a->dev_attr.attr); in nct6683_create_attr_group()
463 a->dev_attr.attr.name = su->name; in nct6683_create_attr_group()
464 a->index = (*t)->u.index + i; in nct6683_create_attr_group()
465 a->dev_attr.attr.mode = in nct6683_create_attr_group()
466 (*t)->dev_attr.attr.mode; in nct6683_create_attr_group()
467 a->dev_attr.show = (*t)->dev_attr.show; in nct6683_create_attr_group()
468 a->dev_attr.store = (*t)->dev_attr.store; in nct6683_create_attr_group()
469 *attrs = &a->dev_attr.attr; in nct6683_create_attr_group()
500 outb_p(0xff, data->addr + EC_PAGE_REG); /* unlock */ in nct6683_read()
501 outb_p(reg >> 8, data->addr + EC_PAGE_REG); in nct6683_read()
502 outb_p(reg & 0xff, data->addr + EC_INDEX_REG); in nct6683_read()
503 res = inb_p(data->addr + EC_DATA_REG); in nct6683_read()
514 outb_p(0xff, data->addr + EC_PAGE_REG); /* unlock */ in nct6683_write()
515 outb_p(reg >> 8, data->addr + EC_PAGE_REG); in nct6683_write()
516 outb_p(reg & 0xff, data->addr + EC_INDEX_REG); in nct6683_write()
517 outb_p(value & 0xff, data->addr + EC_DATA_REG); in nct6683_write()
520 static int get_in_reg(struct nct6683_data *data, int nr, int index) in get_in_reg() argument
522 int ch = data->in_index[index]; in get_in_reg()
523 int reg = -EINVAL; in get_in_reg()
525 switch (nr) { in get_in_reg()
530 if (data->customer_id != NCT6683_CUSTOMER_ID_INTEL) in get_in_reg()
534 if (data->customer_id != NCT6683_CUSTOMER_ID_INTEL) in get_in_reg()
543 static int get_temp_reg(struct nct6683_data *data, int nr, int index) in get_temp_reg() argument
545 int ch = data->temp_index[index]; in get_temp_reg()
546 int reg = -EINVAL; in get_temp_reg()
548 switch (data->customer_id) { in get_temp_reg()
550 switch (nr) { in get_temp_reg()
562 switch (nr) { in get_temp_reg()
588 if (!(data->have_pwm & (1 << i))) in nct6683_update_pwm()
590 data->pwm[i] = nct6683_read(data, NCT6683_REG_PWM(i)); in nct6683_update_pwm()
599 mutex_lock(&data->update_lock); in nct6683_update_device()
601 if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { in nct6683_update_device()
603 for (i = 0; i < data->in_num; i++) { in nct6683_update_device()
608 data->in[j][i] = in nct6683_update_device()
614 for (i = 0; i < data->temp_num; i++) { in nct6683_update_device()
615 u8 ch = data->temp_index[i]; in nct6683_update_device()
617 data->temp_in[i] = nct6683_read16(data, in nct6683_update_device()
623 data->temp[j][i] = in nct6683_update_device()
629 for (i = 0; i < ARRAY_SIZE(data->rpm); i++) { in nct6683_update_device()
630 if (!(data->have_fan & (1 << i))) in nct6683_update_device()
633 data->rpm[i] = nct6683_read16(data, in nct6683_update_device()
635 data->fan_min[i] = nct6683_read16(data, in nct6683_update_device()
641 data->last_updated = jiffies; in nct6683_update_device()
642 data->valid = true; in nct6683_update_device()
645 mutex_unlock(&data->update_lock); in nct6683_update_device()
657 int nr = sattr->index; in show_in_label() local
659 return sprintf(buf, "%s\n", nct6683_mon_label[data->in_src[nr]]); in show_in_label()
667 int index = sattr->index; in show_in_reg()
668 int nr = sattr->nr; in show_in_reg() local
671 in_from_reg(data->in[index][nr], data->in_index[index])); in show_in_reg()
679 int nr = index % 4; /* attribute */ in nct6683_in_is_visible() local
685 if ((nr == 2 || nr == 3) && in nct6683_in_is_visible()
686 data->customer_id == NCT6683_CUSTOMER_ID_INTEL) in nct6683_in_is_visible()
689 return attr->mode; in nct6683_in_is_visible()
716 return sprintf(buf, "%d\n", data->rpm[sattr->index]); in show_fan()
724 int nr = sattr->index; in show_fan_min() local
726 return sprintf(buf, "%d\n", data->fan_min[nr]); in show_fan_min()
736 ((data->fanin_cfg[sattr->index] >> 5) & 0x03) + 1); in show_fan_pulses()
745 int nr = index % 3; /* attribute index */ in nct6683_fan_is_visible() local
747 if (!(data->have_fan & (1 << fan))) in nct6683_fan_is_visible()
754 if (nr == 2 && data->customer_id == NCT6683_CUSTOMER_ID_INTEL) in nct6683_fan_is_visible()
757 return attr->mode; in nct6683_fan_is_visible()
787 int nr = sattr->index; in show_temp_label() local
789 return sprintf(buf, "%s\n", nct6683_mon_label[data->temp_src[nr]]); in show_temp_label()
797 int index = sattr->index; in show_temp8()
798 int nr = sattr->nr; in show_temp8() local
800 return sprintf(buf, "%d\n", data->temp[index][nr] * 1000); in show_temp8()
808 int nr = sattr->index; in show_temp_hyst() local
809 int temp = data->temp[1][nr] - data->temp[2][nr]; in show_temp_hyst()
819 int index = sattr->index; in show_temp16()
821 return sprintf(buf, "%d\n", (data->temp_in[index] / 128) * 500); in show_temp16()
853 int nr = sattr->index; in show_temp_type() local
854 return sprintf(buf, "%d\n", get_temp_type(data->temp_src[nr])); in show_temp_type()
863 int nr = index % 7; /* attribute index */ in nct6683_temp_is_visible() local
869 if ((nr == 2 || nr == 4) && in nct6683_temp_is_visible()
870 data->customer_id == NCT6683_CUSTOMER_ID_INTEL) in nct6683_temp_is_visible()
873 if (nr == 6 && get_temp_type(data->temp_src[temp]) == 0) in nct6683_temp_is_visible()
876 return attr->mode; in nct6683_temp_is_visible()
915 int index = sattr->index; in show_pwm()
917 return sprintf(buf, "%d\n", data->pwm[index]); in show_pwm()
926 int index = sattr->index; in store_pwm()
930 return -EINVAL; in store_pwm()
932 mutex_lock(&data->update_lock); in store_pwm()
937 mutex_unlock(&data->update_lock); in store_pwm()
951 if (!(data->have_pwm & (1 << pwm))) in nct6683_pwm_is_visible()
955 if (data->customer_id == NCT6683_CUSTOMER_ID_MITAC) in nct6683_pwm_is_visible()
956 return attr->mode | S_IWUSR; in nct6683_pwm_is_visible()
958 return attr->mode; in nct6683_pwm_is_visible()
979 mutex_lock(&data->update_lock); in beep_enable_show()
981 ret = superio_enter(data->sioreg); in beep_enable_show()
984 superio_select(data->sioreg, NCT6683_LD_HWM); in beep_enable_show()
985 reg = superio_inb(data->sioreg, NCT6683_REG_CR_BEEP); in beep_enable_show()
986 superio_exit(data->sioreg); in beep_enable_show()
988 mutex_unlock(&data->update_lock); in beep_enable_show()
993 mutex_unlock(&data->update_lock); in beep_enable_show()
1007 return -EINVAL; in beep_enable_store()
1009 mutex_lock(&data->update_lock); in beep_enable_store()
1011 ret = superio_enter(data->sioreg); in beep_enable_store()
1017 superio_select(data->sioreg, NCT6683_LD_HWM); in beep_enable_store()
1018 reg = superio_inb(data->sioreg, NCT6683_REG_CR_BEEP); in beep_enable_store()
1023 superio_outb(data->sioreg, NCT6683_REG_CR_BEEP, reg); in beep_enable_store()
1024 superio_exit(data->sioreg); in beep_enable_store()
1026 mutex_unlock(&data->update_lock); in beep_enable_store()
1040 mutex_lock(&data->update_lock); in intrusion0_alarm_show()
1042 ret = superio_enter(data->sioreg); in intrusion0_alarm_show()
1045 superio_select(data->sioreg, NCT6683_LD_ACPI); in intrusion0_alarm_show()
1046 reg = superio_inb(data->sioreg, NCT6683_REG_CR_CASEOPEN); in intrusion0_alarm_show()
1047 superio_exit(data->sioreg); in intrusion0_alarm_show()
1049 mutex_unlock(&data->update_lock); in intrusion0_alarm_show()
1054 mutex_unlock(&data->update_lock); in intrusion0_alarm_show()
1068 return -EINVAL; in intrusion0_alarm_store()
1070 mutex_lock(&data->update_lock); in intrusion0_alarm_store()
1077 ret = superio_enter(data->sioreg); in intrusion0_alarm_store()
1083 superio_select(data->sioreg, NCT6683_LD_ACPI); in intrusion0_alarm_store()
1084 reg = superio_inb(data->sioreg, NCT6683_REG_CR_CASEOPEN); in intrusion0_alarm_store()
1086 superio_outb(data->sioreg, NCT6683_REG_CR_CASEOPEN, reg); in intrusion0_alarm_store()
1088 superio_outb(data->sioreg, NCT6683_REG_CR_CASEOPEN, reg); in intrusion0_alarm_store()
1089 superio_exit(data->sioreg); in intrusion0_alarm_store()
1091 data->valid = false; /* Force cache refresh */ in intrusion0_alarm_store()
1093 mutex_unlock(&data->update_lock); in intrusion0_alarm_store()
1123 * or as output. A maximum of 16 inputs and 8 outputs is configurable.
1134 data->have_fan |= 1 << i; in nct6683_setup_fans()
1135 data->fanin_cfg[i] = reg; in nct6683_setup_fans()
1140 data->have_pwm |= 1 << i; in nct6683_setup_fans()
1141 data->fanout_cfg[i] = reg; in nct6683_setup_fans()
1166 data->temp_num = 0; in nct6683_setup_sensors()
1167 data->in_num = 0; in nct6683_setup_sensors()
1177 data->temp_index[data->temp_num] = i; in nct6683_setup_sensors()
1178 data->temp_src[data->temp_num] = reg; in nct6683_setup_sensors()
1179 data->temp_num++; in nct6683_setup_sensors()
1181 data->in_index[data->in_num] = i; in nct6683_setup_sensors()
1182 data->in_src[data->in_num] = reg; in nct6683_setup_sensors()
1183 data->in_num++; in nct6683_setup_sensors()
1190 struct device *dev = &pdev->dev; in nct6683_probe()
1191 struct nct6683_sio_data *sio_data = dev->platform_data; in nct6683_probe()
1200 if (!devm_request_region(dev, res->start, IOREGION_LENGTH, DRVNAME)) in nct6683_probe()
1201 return -EBUSY; in nct6683_probe()
1205 return -ENOMEM; in nct6683_probe()
1207 data->kind = sio_data->kind; in nct6683_probe()
1208 data->sioreg = sio_data->sioreg; in nct6683_probe()
1209 data->addr = res->start; in nct6683_probe()
1210 mutex_init(&data->update_lock); in nct6683_probe()
1213 data->customer_id = nct6683_read16(data, NCT6683_REG_CUSTOMER_ID); in nct6683_probe()
1216 switch (data->customer_id) { in nct6683_probe()
1229 return -ENODEV; in nct6683_probe()
1238 if (data->have_pwm) { in nct6683_probe()
1241 fls(data->have_pwm)); in nct6683_probe()
1244 data->groups[groups++] = group; in nct6683_probe()
1247 if (data->in_num) { in nct6683_probe()
1250 data->in_num); in nct6683_probe()
1253 data->groups[groups++] = group; in nct6683_probe()
1256 if (data->have_fan) { in nct6683_probe()
1259 fls(data->have_fan)); in nct6683_probe()
1262 data->groups[groups++] = group; in nct6683_probe()
1265 if (data->temp_num) { in nct6683_probe()
1268 data->temp_num); in nct6683_probe()
1271 data->groups[groups++] = group; in nct6683_probe()
1273 data->groups[groups++] = &nct6683_group_other; in nct6683_probe()
1275 if (data->customer_id == NCT6683_CUSTOMER_ID_INTEL) in nct6683_probe()
1287 nct6683_chip_names[data->kind], in nct6683_probe()
1293 nct6683_device_names[data->kind], data, data->groups); in nct6683_probe()
1302 mutex_lock(&data->update_lock); in nct6683_suspend()
1303 data->hwm_cfg = nct6683_read(data, NCT6683_HWM_CFG); in nct6683_suspend()
1304 mutex_unlock(&data->update_lock); in nct6683_suspend()
1313 mutex_lock(&data->update_lock); in nct6683_resume()
1315 nct6683_write(data, NCT6683_HWM_CFG, data->hwm_cfg); in nct6683_resume()
1317 /* Force re-reading all values */ in nct6683_resume()
1318 data->valid = false; in nct6683_resume()
1319 mutex_unlock(&data->update_lock); in nct6683_resume()
1359 sio_data->kind = nct6683; in nct6683_find()
1362 sio_data->kind = nct6686; in nct6683_find()
1365 sio_data->kind = nct6687; in nct6683_find()
1392 nct6683_chip_names[sio_data->kind], sioaddr, addr); in nct6683_find()
1393 sio_data->sioreg = sioaddr; in nct6683_find()
1399 return -ENODEV; in nct6683_find()
1403 * when Super-I/O functions move to a separate file, the Super-I/O
1424 * initialize sio_data->kind and sio_data->sioreg. in sensors_nct6683_init()
1426 * when Super-I/O functions move to a separate file, the Super-I/O in sensors_nct6683_init()
1427 * driver will probe 0x2e and 0x4e and auto-detect the presence of a in sensors_nct6683_init()
1439 err = -ENOMEM; in sensors_nct6683_init()
1451 res.end = address + IOREGION_OFFSET + IOREGION_LENGTH - 1; in sensors_nct6683_init()
1471 err = -ENODEV; in sensors_nct6683_init()
1480 while (--i >= 0) { in sensors_nct6683_init()
1500 MODULE_AUTHOR("Guenter Roeck <linux@roeck-us.net>");