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()
297 /* ------------------------------------------------------- */
354 u8 nr; member
359 bool s2; /* true if both index and nr are used */
385 .u.s.nr = _nr, \
419 return ERR_PTR(-EINVAL); in nct6683_create_attr_group()
421 t = tg->templates; in nct6683_create_attr_group()
426 return ERR_PTR(-EINVAL); in nct6683_create_attr_group()
430 return ERR_PTR(-ENOMEM); in nct6683_create_attr_group()
435 return ERR_PTR(-ENOMEM); in nct6683_create_attr_group()
440 return ERR_PTR(-ENOMEM); in nct6683_create_attr_group()
442 group->attrs = attrs; in nct6683_create_attr_group()
443 group->is_visible = tg->is_visible; in nct6683_create_attr_group()
446 t = tg->templates; in nct6683_create_attr_group()
448 snprintf(su->name, sizeof(su->name), in nct6683_create_attr_group()
449 (*t)->dev_attr.attr.name, tg->base + i); in nct6683_create_attr_group()
450 if ((*t)->s2) { in nct6683_create_attr_group()
451 a2 = &su->u.a2; in nct6683_create_attr_group()
452 sysfs_attr_init(&a2->dev_attr.attr); in nct6683_create_attr_group()
453 a2->dev_attr.attr.name = su->name; in nct6683_create_attr_group()
454 a2->nr = (*t)->u.s.nr + i; in nct6683_create_attr_group()
455 a2->index = (*t)->u.s.index; in nct6683_create_attr_group()
456 a2->dev_attr.attr.mode = in nct6683_create_attr_group()
457 (*t)->dev_attr.attr.mode; in nct6683_create_attr_group()
458 a2->dev_attr.show = (*t)->dev_attr.show; in nct6683_create_attr_group()
459 a2->dev_attr.store = (*t)->dev_attr.store; in nct6683_create_attr_group()
460 *attrs = &a2->dev_attr.attr; in nct6683_create_attr_group()
462 a = &su->u.a1; in nct6683_create_attr_group()
463 sysfs_attr_init(&a->dev_attr.attr); in nct6683_create_attr_group()
464 a->dev_attr.attr.name = su->name; in nct6683_create_attr_group()
465 a->index = (*t)->u.index + i; in nct6683_create_attr_group()
466 a->dev_attr.attr.mode = in nct6683_create_attr_group()
467 (*t)->dev_attr.attr.mode; in nct6683_create_attr_group()
468 a->dev_attr.show = (*t)->dev_attr.show; in nct6683_create_attr_group()
469 a->dev_attr.store = (*t)->dev_attr.store; in nct6683_create_attr_group()
470 *attrs = &a->dev_attr.attr; in nct6683_create_attr_group()
501 outb_p(0xff, data->addr + EC_PAGE_REG); /* unlock */ in nct6683_read()
502 outb_p(reg >> 8, data->addr + EC_PAGE_REG); in nct6683_read()
503 outb_p(reg & 0xff, data->addr + EC_INDEX_REG); in nct6683_read()
504 res = inb_p(data->addr + EC_DATA_REG); in nct6683_read()
515 outb_p(0xff, data->addr + EC_PAGE_REG); /* unlock */ in nct6683_write()
516 outb_p(reg >> 8, data->addr + EC_PAGE_REG); in nct6683_write()
517 outb_p(reg & 0xff, data->addr + EC_INDEX_REG); in nct6683_write()
518 outb_p(value & 0xff, data->addr + EC_DATA_REG); in nct6683_write()
521 static int get_in_reg(struct nct6683_data *data, int nr, int index) in get_in_reg() argument
523 int ch = data->in_index[index]; in get_in_reg()
524 int reg = -EINVAL; in get_in_reg()
526 switch (nr) { in get_in_reg()
531 if (data->customer_id != NCT6683_CUSTOMER_ID_INTEL) in get_in_reg()
535 if (data->customer_id != NCT6683_CUSTOMER_ID_INTEL) in get_in_reg()
544 static int get_temp_reg(struct nct6683_data *data, int nr, int index) in get_temp_reg() argument
546 int ch = data->temp_index[index]; in get_temp_reg()
547 int reg = -EINVAL; in get_temp_reg()
549 switch (data->customer_id) { in get_temp_reg()
551 switch (nr) { in get_temp_reg()
563 switch (nr) { in get_temp_reg()
589 if (!(data->have_pwm & (1 << i))) in nct6683_update_pwm()
591 data->pwm[i] = nct6683_read(data, NCT6683_REG_PWM(i)); in nct6683_update_pwm()
600 mutex_lock(&data->update_lock); in nct6683_update_device()
602 if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { in nct6683_update_device()
604 for (i = 0; i < data->in_num; i++) { in nct6683_update_device()
609 data->in[j][i] = in nct6683_update_device()
615 for (i = 0; i < data->temp_num; i++) { in nct6683_update_device()
616 u8 ch = data->temp_index[i]; in nct6683_update_device()
618 data->temp_in[i] = nct6683_read16(data, in nct6683_update_device()
624 data->temp[j][i] = in nct6683_update_device()
630 for (i = 0; i < ARRAY_SIZE(data->rpm); i++) { in nct6683_update_device()
631 if (!(data->have_fan & (1 << i))) in nct6683_update_device()
634 data->rpm[i] = nct6683_read16(data, in nct6683_update_device()
636 data->fan_min[i] = nct6683_read16(data, in nct6683_update_device()
642 data->last_updated = jiffies; in nct6683_update_device()
643 data->valid = true; in nct6683_update_device()
646 mutex_unlock(&data->update_lock); in nct6683_update_device()
658 int nr = sattr->index; in show_in_label() local
660 return sprintf(buf, "%s\n", nct6683_mon_label[data->in_src[nr]]); in show_in_label()
668 int index = sattr->index; in show_in_reg()
669 int nr = sattr->nr; in show_in_reg() local
672 in_from_reg(data->in[index][nr], data->in_index[index])); in show_in_reg()
680 int nr = index % 4; /* attribute */ in nct6683_in_is_visible() local
686 if ((nr == 2 || nr == 3) && in nct6683_in_is_visible()
687 data->customer_id == NCT6683_CUSTOMER_ID_INTEL) in nct6683_in_is_visible()
690 return attr->mode; in nct6683_in_is_visible()
717 return sprintf(buf, "%d\n", data->rpm[sattr->index]); in show_fan()
725 int nr = sattr->index; in show_fan_min() local
727 return sprintf(buf, "%d\n", data->fan_min[nr]); in show_fan_min()
737 ((data->fanin_cfg[sattr->index] >> 5) & 0x03) + 1); in show_fan_pulses()
746 int nr = index % 3; /* attribute index */ in nct6683_fan_is_visible() local
748 if (!(data->have_fan & (1 << fan))) in nct6683_fan_is_visible()
755 if (nr == 2 && data->customer_id == NCT6683_CUSTOMER_ID_INTEL) in nct6683_fan_is_visible()
758 return attr->mode; in nct6683_fan_is_visible()
788 int nr = sattr->index; in show_temp_label() local
790 return sprintf(buf, "%s\n", nct6683_mon_label[data->temp_src[nr]]); in show_temp_label()
798 int index = sattr->index; in show_temp8()
799 int nr = sattr->nr; in show_temp8() local
801 return sprintf(buf, "%d\n", data->temp[index][nr] * 1000); in show_temp8()
809 int nr = sattr->index; in show_temp_hyst() local
810 int temp = data->temp[1][nr] - data->temp[2][nr]; in show_temp_hyst()
820 int index = sattr->index; in show_temp16()
822 return sprintf(buf, "%d\n", (data->temp_in[index] / 128) * 500); in show_temp16()
854 int nr = sattr->index; in show_temp_type() local
855 return sprintf(buf, "%d\n", get_temp_type(data->temp_src[nr])); in show_temp_type()
864 int nr = index % 7; /* attribute index */ in nct6683_temp_is_visible() local
870 if ((nr == 2 || nr == 4) && in nct6683_temp_is_visible()
871 data->customer_id == NCT6683_CUSTOMER_ID_INTEL) in nct6683_temp_is_visible()
874 if (nr == 6 && get_temp_type(data->temp_src[temp]) == 0) in nct6683_temp_is_visible()
877 return attr->mode; in nct6683_temp_is_visible()
916 int index = sattr->index; in show_pwm()
918 return sprintf(buf, "%d\n", data->pwm[index]); in show_pwm()
927 int index = sattr->index; in store_pwm()
931 return -EINVAL; in store_pwm()
933 mutex_lock(&data->update_lock); in store_pwm()
938 mutex_unlock(&data->update_lock); in store_pwm()
952 if (!(data->have_pwm & (1 << pwm))) in nct6683_pwm_is_visible()
956 if (data->customer_id == NCT6683_CUSTOMER_ID_MITAC) in nct6683_pwm_is_visible()
957 return attr->mode | S_IWUSR; in nct6683_pwm_is_visible()
959 return attr->mode; in nct6683_pwm_is_visible()
980 mutex_lock(&data->update_lock); in beep_enable_show()
982 ret = superio_enter(data->sioreg); in beep_enable_show()
985 superio_select(data->sioreg, NCT6683_LD_HWM); in beep_enable_show()
986 reg = superio_inb(data->sioreg, NCT6683_REG_CR_BEEP); in beep_enable_show()
987 superio_exit(data->sioreg); in beep_enable_show()
989 mutex_unlock(&data->update_lock); in beep_enable_show()
994 mutex_unlock(&data->update_lock); in beep_enable_show()
1008 return -EINVAL; in beep_enable_store()
1010 mutex_lock(&data->update_lock); in beep_enable_store()
1012 ret = superio_enter(data->sioreg); in beep_enable_store()
1018 superio_select(data->sioreg, NCT6683_LD_HWM); in beep_enable_store()
1019 reg = superio_inb(data->sioreg, NCT6683_REG_CR_BEEP); in beep_enable_store()
1024 superio_outb(data->sioreg, NCT6683_REG_CR_BEEP, reg); in beep_enable_store()
1025 superio_exit(data->sioreg); in beep_enable_store()
1027 mutex_unlock(&data->update_lock); in beep_enable_store()
1041 mutex_lock(&data->update_lock); in intrusion0_alarm_show()
1043 ret = superio_enter(data->sioreg); in intrusion0_alarm_show()
1046 superio_select(data->sioreg, NCT6683_LD_ACPI); in intrusion0_alarm_show()
1047 reg = superio_inb(data->sioreg, NCT6683_REG_CR_CASEOPEN); in intrusion0_alarm_show()
1048 superio_exit(data->sioreg); in intrusion0_alarm_show()
1050 mutex_unlock(&data->update_lock); in intrusion0_alarm_show()
1055 mutex_unlock(&data->update_lock); in intrusion0_alarm_show()
1069 return -EINVAL; in intrusion0_alarm_store()
1071 mutex_lock(&data->update_lock); in intrusion0_alarm_store()
1078 ret = superio_enter(data->sioreg); in intrusion0_alarm_store()
1084 superio_select(data->sioreg, NCT6683_LD_ACPI); in intrusion0_alarm_store()
1085 reg = superio_inb(data->sioreg, NCT6683_REG_CR_CASEOPEN); in intrusion0_alarm_store()
1087 superio_outb(data->sioreg, NCT6683_REG_CR_CASEOPEN, reg); in intrusion0_alarm_store()
1089 superio_outb(data->sioreg, NCT6683_REG_CR_CASEOPEN, reg); in intrusion0_alarm_store()
1090 superio_exit(data->sioreg); in intrusion0_alarm_store()
1092 data->valid = false; /* Force cache refresh */ in intrusion0_alarm_store()
1094 mutex_unlock(&data->update_lock); in intrusion0_alarm_store()
1124 * or as output. A maximum of 16 inputs and 8 outputs is configurable.
1135 data->have_fan |= 1 << i; in nct6683_setup_fans()
1136 data->fanin_cfg[i] = reg; in nct6683_setup_fans()
1141 data->have_pwm |= 1 << i; in nct6683_setup_fans()
1142 data->fanout_cfg[i] = reg; in nct6683_setup_fans()
1167 data->temp_num = 0; in nct6683_setup_sensors()
1168 data->in_num = 0; in nct6683_setup_sensors()
1178 data->temp_index[data->temp_num] = i; in nct6683_setup_sensors()
1179 data->temp_src[data->temp_num] = reg; in nct6683_setup_sensors()
1180 data->temp_num++; in nct6683_setup_sensors()
1182 data->in_index[data->in_num] = i; in nct6683_setup_sensors()
1183 data->in_src[data->in_num] = reg; in nct6683_setup_sensors()
1184 data->in_num++; in nct6683_setup_sensors()
1191 struct device *dev = &pdev->dev; in nct6683_probe()
1192 struct nct6683_sio_data *sio_data = dev->platform_data; in nct6683_probe()
1201 if (!devm_request_region(dev, res->start, IOREGION_LENGTH, DRVNAME)) in nct6683_probe()
1202 return -EBUSY; in nct6683_probe()
1206 return -ENOMEM; in nct6683_probe()
1208 data->kind = sio_data->kind; in nct6683_probe()
1209 data->sioreg = sio_data->sioreg; in nct6683_probe()
1210 data->addr = res->start; in nct6683_probe()
1211 mutex_init(&data->update_lock); in nct6683_probe()
1214 data->customer_id = nct6683_read16(data, NCT6683_REG_CUSTOMER_ID); in nct6683_probe()
1217 switch (data->customer_id) { in nct6683_probe()
1232 return -ENODEV; in nct6683_probe()
1241 if (data->have_pwm) { in nct6683_probe()
1244 fls(data->have_pwm)); in nct6683_probe()
1247 data->groups[groups++] = group; in nct6683_probe()
1250 if (data->in_num) { in nct6683_probe()
1253 data->in_num); in nct6683_probe()
1256 data->groups[groups++] = group; in nct6683_probe()
1259 if (data->have_fan) { in nct6683_probe()
1262 fls(data->have_fan)); in nct6683_probe()
1265 data->groups[groups++] = group; in nct6683_probe()
1268 if (data->temp_num) { in nct6683_probe()
1271 data->temp_num); in nct6683_probe()
1274 data->groups[groups++] = group; in nct6683_probe()
1276 data->groups[groups++] = &nct6683_group_other; in nct6683_probe()
1278 if (data->customer_id == NCT6683_CUSTOMER_ID_INTEL) in nct6683_probe()
1290 nct6683_chip_names[data->kind], in nct6683_probe()
1296 nct6683_device_names[data->kind], data, data->groups); in nct6683_probe()
1305 mutex_lock(&data->update_lock); in nct6683_suspend()
1306 data->hwm_cfg = nct6683_read(data, NCT6683_HWM_CFG); in nct6683_suspend()
1307 mutex_unlock(&data->update_lock); in nct6683_suspend()
1316 mutex_lock(&data->update_lock); in nct6683_resume()
1318 nct6683_write(data, NCT6683_HWM_CFG, data->hwm_cfg); in nct6683_resume()
1320 /* Force re-reading all values */ in nct6683_resume()
1321 data->valid = false; in nct6683_resume()
1322 mutex_unlock(&data->update_lock); in nct6683_resume()
1362 sio_data->kind = nct6683; in nct6683_find()
1365 sio_data->kind = nct6686; in nct6683_find()
1368 sio_data->kind = nct6687; in nct6683_find()
1395 nct6683_chip_names[sio_data->kind], sioaddr, addr); in nct6683_find()
1396 sio_data->sioreg = sioaddr; in nct6683_find()
1402 return -ENODEV; in nct6683_find()
1406 * when Super-I/O functions move to a separate file, the Super-I/O
1427 * initialize sio_data->kind and sio_data->sioreg. in sensors_nct6683_init()
1429 * when Super-I/O functions move to a separate file, the Super-I/O in sensors_nct6683_init()
1430 * driver will probe 0x2e and 0x4e and auto-detect the presence of a in sensors_nct6683_init()
1442 err = -ENOMEM; in sensors_nct6683_init()
1454 res.end = address + IOREGION_OFFSET + IOREGION_LENGTH - 1; in sensors_nct6683_init()
1474 err = -ENODEV; in sensors_nct6683_init()
1483 while (--i >= 0) { in sensors_nct6683_init()
1503 MODULE_AUTHOR("Guenter Roeck <linux@roeck-us.net>");