Lines Matching +full:scaled +full:- +full:sync
2 * vt1211.c - driver for the VIA VT1211 Super-I/O chip integrated hardware
32 #include <linux/hwmon-sysfs.h>
33 #include <linux/hwmon-vid.h>
40 static int uch_config = -1;
44 static int int_mode = -1;
56 /* ---------------------------------------------------------------------
62 * -------- ------------ --------- --------------------------
72 * --------------------------------------------------------------------- */
74 /* Voltages (in) numbered 0-5 (ix) */
79 /* Temperatures (temp) numbered 0-6 (ix) */
84 /* Fans numbered 0-1 (ix) */
89 /* PWMs numbered 0-1 (ix) */
90 /* Auto points numbered 0-3 (ap) */
94 #define VT1211_REG_PWM_AUTO_TEMP(ap) (0x55 - (ap))
95 #define VT1211_REG_PWM_AUTO_PWM(ix, ap) (0x58 + 2 * (ix) - (ap))
111 /* ---------------------------------------------------------------------
113 * --------------------------------------------------------------------- */
146 /* ix = [0-5] */
150 /* ix = [0-6] */
155 * in5 (ix = 5) is special. It's the internal 3.3V so it's scaled in the
159 (((reg) - 3) * 15882 + 479) / 958 : \
160 (((reg) - 3) * 10000 + 479) / 958)
166 * temp1 (ix = 0) is an intel thermal diode which is scaled in user space.
167 * temp2 (ix = 1) is the internal temp diode so it's scaled in the driver
169 * temp3-7 are thermistor based so the driver returns the voltage measured at
170 * the pin (range 0V - 2.2V).
174 ((reg) - 51) * 1000 : \
175 ((253 - (reg)) * 2200 + 105) / 210)
179 253 - ((val) * 210 + 1100) / 2200), 0, 255)
189 /* ---------------------------------------------------------------------
190 * Super-I/O constants and functions
191 * --------------------------------------------------------------------- */
232 return -EBUSY; in superio_enter()
246 /* ---------------------------------------------------------------------
248 * --------------------------------------------------------------------- */
252 return inb(data->addr + reg); in vt1211_read8()
257 outb(val, data->addr + reg); in vt1211_write8()
265 mutex_lock(&data->update_lock); in vt1211_update_device()
268 if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { in vt1211_update_device()
270 data->vid = vt1211_read8(data, VT1211_REG_VID) & 0x1f; in vt1211_update_device()
273 for (ix = 0; ix < ARRAY_SIZE(data->in); ix++) { in vt1211_update_device()
274 if (ISVOLT(ix, data->uch_config)) { in vt1211_update_device()
275 data->in[ix] = vt1211_read8(data, in vt1211_update_device()
277 data->in_min[ix] = vt1211_read8(data, in vt1211_update_device()
279 data->in_max[ix] = vt1211_read8(data, in vt1211_update_device()
285 for (ix = 0; ix < ARRAY_SIZE(data->temp); ix++) { in vt1211_update_device()
286 if (ISTEMP(ix, data->uch_config)) { in vt1211_update_device()
287 data->temp[ix] = vt1211_read8(data, in vt1211_update_device()
289 data->temp_max[ix] = vt1211_read8(data, in vt1211_update_device()
291 data->temp_hyst[ix] = vt1211_read8(data, in vt1211_update_device()
297 for (ix = 0; ix < ARRAY_SIZE(data->fan); ix++) { in vt1211_update_device()
298 data->fan[ix] = vt1211_read8(data, in vt1211_update_device()
300 data->fan_min[ix] = vt1211_read8(data, in vt1211_update_device()
302 data->pwm[ix] = vt1211_read8(data, in vt1211_update_device()
306 data->fan_div[0] = (val >> 4) & 3; in vt1211_update_device()
307 data->fan_div[1] = (val >> 6) & 3; in vt1211_update_device()
308 data->fan_ctl = val & 0xf; in vt1211_update_device()
311 data->pwm_ctl[0] = val & 0xf; in vt1211_update_device()
312 data->pwm_ctl[1] = (val >> 4) & 0xf; in vt1211_update_device()
314 data->pwm_clk = vt1211_read8(data, VT1211_REG_PWM_CLK); in vt1211_update_device()
317 data->pwm_auto_pwm[0][1] = vt1211_read8(data, in vt1211_update_device()
319 data->pwm_auto_pwm[0][2] = vt1211_read8(data, in vt1211_update_device()
321 data->pwm_auto_pwm[1][1] = vt1211_read8(data, in vt1211_update_device()
323 data->pwm_auto_pwm[1][2] = vt1211_read8(data, in vt1211_update_device()
325 for (ix = 0; ix < ARRAY_SIZE(data->pwm_auto_temp); ix++) { in vt1211_update_device()
326 data->pwm_auto_temp[ix] = vt1211_read8(data, in vt1211_update_device()
331 data->alarms = (vt1211_read8(data, VT1211_REG_ALARM2) << 8) | in vt1211_update_device()
334 data->last_updated = jiffies; in vt1211_update_device()
335 data->valid = 1; in vt1211_update_device()
338 mutex_unlock(&data->update_lock); in vt1211_update_device()
343 /* ---------------------------------------------------------------------
345 * ix = [0-5]
346 * --------------------------------------------------------------------- */
359 int ix = sensor_attr_2->index; in show_in()
360 int fn = sensor_attr_2->nr; in show_in()
365 res = IN_FROM_REG(ix, data->in[ix]); in show_in()
368 res = IN_FROM_REG(ix, data->in_min[ix]); in show_in()
371 res = IN_FROM_REG(ix, data->in_max[ix]); in show_in()
374 res = (data->alarms >> bitalarmin[ix]) & 1; in show_in()
390 int ix = sensor_attr_2->index; in set_in()
391 int fn = sensor_attr_2->nr; in set_in()
399 mutex_lock(&data->update_lock); in set_in()
402 data->in_min[ix] = IN_TO_REG(ix, val); in set_in()
403 vt1211_write8(data, VT1211_REG_IN_MIN(ix), data->in_min[ix]); in set_in()
406 data->in_max[ix] = IN_TO_REG(ix, val); in set_in()
407 vt1211_write8(data, VT1211_REG_IN_MAX(ix), data->in_max[ix]); in set_in()
412 mutex_unlock(&data->update_lock); in set_in()
417 /* ---------------------------------------------------------------------
419 * ix = [0-6]
420 * --------------------------------------------------------------------- */
433 int ix = sensor_attr_2->index; in show_temp()
434 int fn = sensor_attr_2->nr; in show_temp()
439 res = TEMP_FROM_REG(ix, data->temp[ix]); in show_temp()
442 res = TEMP_FROM_REG(ix, data->temp_max[ix]); in show_temp()
445 res = TEMP_FROM_REG(ix, data->temp_hyst[ix]); in show_temp()
448 res = (data->alarms >> bitalarmtemp[ix]) & 1; in show_temp()
464 int ix = sensor_attr_2->index; in set_temp()
465 int fn = sensor_attr_2->nr; in set_temp()
473 mutex_lock(&data->update_lock); in set_temp()
476 data->temp_max[ix] = TEMP_TO_REG(ix, val); in set_temp()
478 data->temp_max[ix]); in set_temp()
481 data->temp_hyst[ix] = TEMP_TO_REG(ix, val); in set_temp()
483 data->temp_hyst[ix]); in set_temp()
488 mutex_unlock(&data->update_lock); in set_temp()
493 /* ---------------------------------------------------------------------
495 * ix = [0-1]
496 * --------------------------------------------------------------------- */
509 int ix = sensor_attr_2->index; in show_fan()
510 int fn = sensor_attr_2->nr; in show_fan()
515 res = RPM_FROM_REG(data->fan[ix], data->fan_div[ix]); in show_fan()
518 res = RPM_FROM_REG(data->fan_min[ix], data->fan_div[ix]); in show_fan()
521 res = DIV_FROM_REG(data->fan_div[ix]); in show_fan()
524 res = (data->alarms >> bitalarmfan[ix]) & 1; in show_fan()
540 int ix = sensor_attr_2->index; in set_fan()
541 int fn = sensor_attr_2->nr; in set_fan()
550 mutex_lock(&data->update_lock); in set_fan()
552 /* sync the data cache */ in set_fan()
554 data->fan_div[0] = (reg >> 4) & 3; in set_fan()
555 data->fan_div[1] = (reg >> 6) & 3; in set_fan()
556 data->fan_ctl = reg & 0xf; in set_fan()
560 data->fan_min[ix] = RPM_TO_REG(val, data->fan_div[ix]); in set_fan()
562 data->fan_min[ix]); in set_fan()
567 data->fan_div[ix] = 0; in set_fan()
570 data->fan_div[ix] = 1; in set_fan()
573 data->fan_div[ix] = 2; in set_fan()
576 data->fan_div[ix] = 3; in set_fan()
579 count = -EINVAL; in set_fan()
586 ((data->fan_div[1] << 6) | in set_fan()
587 (data->fan_div[0] << 4) | in set_fan()
588 data->fan_ctl)); in set_fan()
595 mutex_unlock(&data->update_lock); in set_fan()
599 /* ---------------------------------------------------------------------
601 * ix = [0-1]
602 * --------------------------------------------------------------------- */
615 int ix = sensor_attr_2->index; in show_pwm()
616 int fn = sensor_attr_2->nr; in show_pwm()
621 res = data->pwm[ix]; in show_pwm()
624 res = ((data->pwm_ctl[ix] >> 3) & 1) ? 2 : 0; in show_pwm()
627 res = 90000 >> (data->pwm_clk & 7); in show_pwm()
630 res = (data->pwm_ctl[ix] & 7) + 1; in show_pwm()
646 int ix = sensor_attr_2->index; in set_pwm()
647 int fn = sensor_attr_2->nr; in set_pwm()
656 mutex_lock(&data->update_lock); in set_pwm()
660 /* sync the data cache */ in set_pwm()
662 data->fan_div[0] = (reg >> 4) & 3; in set_pwm()
663 data->fan_div[1] = (reg >> 6) & 3; in set_pwm()
664 data->fan_ctl = reg & 0xf; in set_pwm()
666 data->pwm_ctl[0] = reg & 0xf; in set_pwm()
667 data->pwm_ctl[1] = (reg >> 4) & 0xf; in set_pwm()
670 data->pwm_ctl[ix] &= 7; in set_pwm()
675 if ((data->pwm_ctl[ix ^ 1] & 1) == 0) in set_pwm()
676 data->fan_ctl &= 0xe; in set_pwm()
679 data->pwm_ctl[ix] |= 8; in set_pwm()
680 data->fan_ctl |= 1; in set_pwm()
683 count = -EINVAL; in set_pwm()
690 ((data->pwm_ctl[1] << 4) | in set_pwm()
691 data->pwm_ctl[0])); in set_pwm()
693 ((data->fan_div[1] << 6) | in set_pwm()
694 (data->fan_div[0] << 4) | in set_pwm()
695 data->fan_ctl)); in set_pwm()
703 /* sync the data cache */ in set_pwm()
705 data->pwm_clk = (reg & 0xf8) | tmp; in set_pwm()
706 vt1211_write8(data, VT1211_REG_PWM_CLK, data->pwm_clk); in set_pwm()
710 count = -EINVAL; in set_pwm()
716 if (!ISTEMP(val - 1, data->uch_config)) { in set_pwm()
717 count = -EINVAL; in set_pwm()
722 /* sync the data cache */ in set_pwm()
724 data->pwm_ctl[0] = reg & 0xf; in set_pwm()
725 data->pwm_ctl[1] = (reg >> 4) & 0xf; in set_pwm()
726 data->pwm_ctl[ix] = (data->pwm_ctl[ix] & 8) | (val - 1); in set_pwm()
728 ((data->pwm_ctl[1] << 4) | data->pwm_ctl[0])); in set_pwm()
735 mutex_unlock(&data->update_lock); in set_pwm()
739 /* ---------------------------------------------------------------------
741 * ix = [0-1]
742 * ap = [0-3]
743 * --------------------------------------------------------------------- */
752 * -------------------
770 int ix = sensor_attr_2->index; in show_pwm_auto_point_temp()
771 int ap = sensor_attr_2->nr; in show_pwm_auto_point_temp()
773 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->pwm_ctl[ix] & 7, in show_pwm_auto_point_temp()
774 data->pwm_auto_temp[ap])); in show_pwm_auto_point_temp()
784 int ix = sensor_attr_2->index; in set_pwm_auto_point_temp()
785 int ap = sensor_attr_2->nr; in set_pwm_auto_point_temp()
795 mutex_lock(&data->update_lock); in set_pwm_auto_point_temp()
797 /* sync the data cache */ in set_pwm_auto_point_temp()
799 data->pwm_ctl[0] = reg & 0xf; in set_pwm_auto_point_temp()
800 data->pwm_ctl[1] = (reg >> 4) & 0xf; in set_pwm_auto_point_temp()
802 data->pwm_auto_temp[ap] = TEMP_TO_REG(data->pwm_ctl[ix] & 7, val); in set_pwm_auto_point_temp()
804 data->pwm_auto_temp[ap]); in set_pwm_auto_point_temp()
805 mutex_unlock(&data->update_lock); in set_pwm_auto_point_temp()
812 * Note that the PWM auto points 0 & 3 are hard-wired in the VT1211 and can't
816 * -------------------
817 * 0 0 : pwm1 off (pwm_auto_pwm[0][0], hard-wired to 0)
820 * 0 3 : pwm1 full speed (pwm_auto_pwm[0][3], hard-wired to 255)
821 * 1 0 : pwm2 off (pwm_auto_pwm[1][0], hard-wired to 0)
824 * 1 3 : pwm2 full speed (pwm_auto_pwm[1][3], hard-wired to 255)
834 int ix = sensor_attr_2->index; in show_pwm_auto_point_pwm()
835 int ap = sensor_attr_2->nr; in show_pwm_auto_point_pwm()
837 return sprintf(buf, "%d\n", data->pwm_auto_pwm[ix][ap]); in show_pwm_auto_point_pwm()
847 int ix = sensor_attr_2->index; in set_pwm_auto_point_pwm()
848 int ap = sensor_attr_2->nr; in set_pwm_auto_point_pwm()
856 mutex_lock(&data->update_lock); in set_pwm_auto_point_pwm()
857 data->pwm_auto_pwm[ix][ap] = clamp_val(val, 0, 255); in set_pwm_auto_point_pwm()
859 data->pwm_auto_pwm[ix][ap]); in set_pwm_auto_point_pwm()
860 mutex_unlock(&data->update_lock); in set_pwm_auto_point_pwm()
865 /* ---------------------------------------------------------------------
867 * --------------------------------------------------------------------- */
874 return sprintf(buf, "%d\n", data->vrm); in show_vrm()
889 return -EINVAL; in set_vrm()
891 data->vrm = val; in set_vrm()
901 return sprintf(buf, "%d\n", vid_from_reg(data->vid, data->vrm)); in show_vid()
909 return sprintf(buf, "%s\n", data->name); in show_name()
917 return sprintf(buf, "%d\n", data->alarms); in show_alarms()
920 /* ---------------------------------------------------------------------
922 * --------------------------------------------------------------------- */
972 show_temp, NULL, SHOW_TEMP_INPUT, ix-1), \
974 show_temp, set_temp, SHOW_SET_TEMP_MAX, ix-1), \
976 show_temp, set_temp, SHOW_SET_TEMP_MAX_HYST, ix-1), \
978 show_temp, NULL, SHOW_TEMP_ALARM, ix-1) \
1021 show_fan, NULL, SHOW_FAN_INPUT, ix-1), \
1023 show_fan, set_fan, SHOW_SET_FAN_MIN, ix-1), \
1025 show_fan, set_fan, SHOW_SET_FAN_DIV, ix-1), \
1027 show_fan, NULL, SHOW_FAN_ALARM, ix-1)
1031 show_pwm, NULL, SHOW_PWM, ix-1), \
1033 show_pwm, set_pwm, SHOW_SET_PWM_ENABLE, ix-1), \
1035 show_pwm, set_pwm, SHOW_SET_PWM_AUTO_CHANNELS_TEMP, ix-1)
1039 show_pwm, set_pwm, SHOW_SET_PWM_FREQ, ix-1)
1043 show_pwm, NULL, SHOW_SET_PWM_FREQ, ix-1)
1048 ap-1, ix-1)
1053 ap-1, ix-1)
1058 ap-1, ix-1)
1063 ap-1, ix-1)
1097 /* ---------------------------------------------------------------------
1099 * --------------------------------------------------------------------- */
1104 data->vrm = vid_which_vrm(); in vt1211_init_device()
1107 data->uch_config = vt1211_read8(data, VT1211_REG_UCH_CONFIG); in vt1211_init_device()
1108 if (uch_config > -1) { in vt1211_init_device()
1109 data->uch_config = (data->uch_config & 0x83) | in vt1211_init_device()
1111 vt1211_write8(data, VT1211_REG_UCH_CONFIG, data->uch_config); in vt1211_init_device()
1133 data->pwm_auto_pwm[0][3] = 255; in vt1211_init_device()
1134 data->pwm_auto_pwm[1][3] = 255; in vt1211_init_device()
1139 struct device *dev = &pdev->dev; in vt1211_remove_sysfs()
1143 sysfs_remove_group(&dev->kobj, &vt1211_in_attr_group[i]); in vt1211_remove_sysfs()
1146 sysfs_remove_group(&dev->kobj, &vt1211_temp_attr_group[i]); in vt1211_remove_sysfs()
1158 struct device *dev = &pdev->dev; in vt1211_probe()
1165 return -ENOMEM; in vt1211_probe()
1168 if (!devm_request_region(dev, res->start, resource_size(res), in vt1211_probe()
1170 dev_err(dev, "Failed to request region 0x%lx-0x%lx\n", in vt1211_probe()
1171 (unsigned long)res->start, (unsigned long)res->end); in vt1211_probe()
1172 return -EBUSY; in vt1211_probe()
1174 data->addr = res->start; in vt1211_probe()
1175 data->name = DRVNAME; in vt1211_probe()
1176 mutex_init(&data->update_lock); in vt1211_probe()
1185 if (ISVOLT(i, data->uch_config)) { in vt1211_probe()
1186 err = sysfs_create_group(&dev->kobj, in vt1211_probe()
1193 if (ISTEMP(i, data->uch_config)) { in vt1211_probe()
1194 err = sysfs_create_group(&dev->kobj, in vt1211_probe()
1214 data->hwmon_dev = hwmon_device_register(dev); in vt1211_probe()
1215 if (IS_ERR(data->hwmon_dev)) { in vt1211_probe()
1216 err = PTR_ERR(data->hwmon_dev); in vt1211_probe()
1234 hwmon_device_unregister(data->hwmon_dev); in vt1211_remove()
1259 err = -ENOMEM; in vt1211_device_add()
1264 res.name = pdev->name; in vt1211_device_add()
1298 err = -ENODEV; in vt1211_find()
1338 if ((uch_config < -1) || (uch_config > 31)) { in vt1211_init()
1339 err = -EINVAL; in vt1211_init()
1345 if ((int_mode < -1) || (int_mode > 0)) { in vt1211_init()
1346 err = -EINVAL; in vt1211_init()