Lines Matching +full:hard +full:- +full:wired
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * vt1211.c - driver for the VIA VT1211 Super-I/O chip integrated hardware
19 #include <linux/hwmon-sysfs.h>
20 #include <linux/hwmon-vid.h>
27 static int uch_config = -1;
31 static int int_mode = -1;
43 /* ---------------------------------------------------------------------
49 * -------- ------------ --------- --------------------------
59 * --------------------------------------------------------------------- */
61 /* Voltages (in) numbered 0-5 (ix) */
66 /* Temperatures (temp) numbered 0-6 (ix) */
71 /* Fans numbered 0-1 (ix) */
76 /* PWMs numbered 0-1 (ix) */
77 /* Auto points numbered 0-3 (ap) */
81 #define VT1211_REG_PWM_AUTO_TEMP(ap) (0x55 - (ap))
82 #define VT1211_REG_PWM_AUTO_PWM(ix, ap) (0x58 + 2 * (ix) - (ap))
98 /* ---------------------------------------------------------------------
100 * --------------------------------------------------------------------- */
133 /* ix = [0-5] */
137 /* ix = [0-6] */
146 (((reg) - 3) * 15882 + 479) / 958 : \
147 (((reg) - 3) * 10000 + 479) / 958)
156 * temp3-7 are thermistor based so the driver returns the voltage measured at
157 * the pin (range 0V - 2.2V).
161 ((reg) - 51) * 1000 : \
162 ((253 - (reg)) * 2200 + 105) / 210)
166 253 - ((val) * 210 + 1100) / 2200), 0, 255)
176 /* ---------------------------------------------------------------------
177 * Super-I/O constants and functions
178 * --------------------------------------------------------------------- */
213 return -EBUSY; in superio_enter()
227 /* ---------------------------------------------------------------------
229 * --------------------------------------------------------------------- */
233 return inb(data->addr + reg); in vt1211_read8()
238 outb(val, data->addr + reg); in vt1211_write8()
246 mutex_lock(&data->update_lock); in vt1211_update_device()
249 if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { in vt1211_update_device()
251 data->vid = vt1211_read8(data, VT1211_REG_VID) & 0x1f; in vt1211_update_device()
254 for (ix = 0; ix < ARRAY_SIZE(data->in); ix++) { in vt1211_update_device()
255 if (ISVOLT(ix, data->uch_config)) { in vt1211_update_device()
256 data->in[ix] = vt1211_read8(data, in vt1211_update_device()
258 data->in_min[ix] = vt1211_read8(data, in vt1211_update_device()
260 data->in_max[ix] = vt1211_read8(data, in vt1211_update_device()
266 for (ix = 0; ix < ARRAY_SIZE(data->temp); ix++) { in vt1211_update_device()
267 if (ISTEMP(ix, data->uch_config)) { in vt1211_update_device()
268 data->temp[ix] = vt1211_read8(data, in vt1211_update_device()
270 data->temp_max[ix] = vt1211_read8(data, in vt1211_update_device()
272 data->temp_hyst[ix] = vt1211_read8(data, in vt1211_update_device()
278 for (ix = 0; ix < ARRAY_SIZE(data->fan); ix++) { in vt1211_update_device()
279 data->fan[ix] = vt1211_read8(data, in vt1211_update_device()
281 data->fan_min[ix] = vt1211_read8(data, in vt1211_update_device()
283 data->pwm[ix] = vt1211_read8(data, in vt1211_update_device()
287 data->fan_div[0] = (val >> 4) & 3; in vt1211_update_device()
288 data->fan_div[1] = (val >> 6) & 3; in vt1211_update_device()
289 data->fan_ctl = val & 0xf; in vt1211_update_device()
292 data->pwm_ctl[0] = val & 0xf; in vt1211_update_device()
293 data->pwm_ctl[1] = (val >> 4) & 0xf; in vt1211_update_device()
295 data->pwm_clk = vt1211_read8(data, VT1211_REG_PWM_CLK); in vt1211_update_device()
298 data->pwm_auto_pwm[0][1] = vt1211_read8(data, in vt1211_update_device()
300 data->pwm_auto_pwm[0][2] = vt1211_read8(data, in vt1211_update_device()
302 data->pwm_auto_pwm[1][1] = vt1211_read8(data, in vt1211_update_device()
304 data->pwm_auto_pwm[1][2] = vt1211_read8(data, in vt1211_update_device()
306 for (ix = 0; ix < ARRAY_SIZE(data->pwm_auto_temp); ix++) { in vt1211_update_device()
307 data->pwm_auto_temp[ix] = vt1211_read8(data, in vt1211_update_device()
312 data->alarms = (vt1211_read8(data, VT1211_REG_ALARM2) << 8) | in vt1211_update_device()
315 data->last_updated = jiffies; in vt1211_update_device()
316 data->valid = true; in vt1211_update_device()
319 mutex_unlock(&data->update_lock); in vt1211_update_device()
324 /* ---------------------------------------------------------------------
326 * ix = [0-5]
327 * --------------------------------------------------------------------- */
340 int ix = sensor_attr_2->index; in show_in()
341 int fn = sensor_attr_2->nr; in show_in()
346 res = IN_FROM_REG(ix, data->in[ix]); in show_in()
349 res = IN_FROM_REG(ix, data->in_min[ix]); in show_in()
352 res = IN_FROM_REG(ix, data->in_max[ix]); in show_in()
355 res = (data->alarms >> bitalarmin[ix]) & 1; in show_in()
371 int ix = sensor_attr_2->index; in set_in()
372 int fn = sensor_attr_2->nr; in set_in()
380 mutex_lock(&data->update_lock); in set_in()
383 data->in_min[ix] = IN_TO_REG(ix, val); in set_in()
384 vt1211_write8(data, VT1211_REG_IN_MIN(ix), data->in_min[ix]); in set_in()
387 data->in_max[ix] = IN_TO_REG(ix, val); in set_in()
388 vt1211_write8(data, VT1211_REG_IN_MAX(ix), data->in_max[ix]); in set_in()
393 mutex_unlock(&data->update_lock); in set_in()
398 /* ---------------------------------------------------------------------
400 * ix = [0-6]
401 * --------------------------------------------------------------------- */
414 int ix = sensor_attr_2->index; in show_temp()
415 int fn = sensor_attr_2->nr; in show_temp()
420 res = TEMP_FROM_REG(ix, data->temp[ix]); in show_temp()
423 res = TEMP_FROM_REG(ix, data->temp_max[ix]); in show_temp()
426 res = TEMP_FROM_REG(ix, data->temp_hyst[ix]); in show_temp()
429 res = (data->alarms >> bitalarmtemp[ix]) & 1; in show_temp()
445 int ix = sensor_attr_2->index; in set_temp()
446 int fn = sensor_attr_2->nr; in set_temp()
454 mutex_lock(&data->update_lock); in set_temp()
457 data->temp_max[ix] = TEMP_TO_REG(ix, val); in set_temp()
459 data->temp_max[ix]); in set_temp()
462 data->temp_hyst[ix] = TEMP_TO_REG(ix, val); in set_temp()
464 data->temp_hyst[ix]); in set_temp()
469 mutex_unlock(&data->update_lock); in set_temp()
474 /* ---------------------------------------------------------------------
476 * ix = [0-1]
477 * --------------------------------------------------------------------- */
490 int ix = sensor_attr_2->index; in show_fan()
491 int fn = sensor_attr_2->nr; in show_fan()
496 res = RPM_FROM_REG(data->fan[ix], data->fan_div[ix]); in show_fan()
499 res = RPM_FROM_REG(data->fan_min[ix], data->fan_div[ix]); in show_fan()
502 res = DIV_FROM_REG(data->fan_div[ix]); in show_fan()
505 res = (data->alarms >> bitalarmfan[ix]) & 1; in show_fan()
521 int ix = sensor_attr_2->index; in set_fan()
522 int fn = sensor_attr_2->nr; in set_fan()
531 mutex_lock(&data->update_lock); in set_fan()
535 data->fan_div[0] = (reg >> 4) & 3; in set_fan()
536 data->fan_div[1] = (reg >> 6) & 3; in set_fan()
537 data->fan_ctl = reg & 0xf; in set_fan()
541 data->fan_min[ix] = RPM_TO_REG(val, data->fan_div[ix]); in set_fan()
543 data->fan_min[ix]); in set_fan()
548 data->fan_div[ix] = 0; in set_fan()
551 data->fan_div[ix] = 1; in set_fan()
554 data->fan_div[ix] = 2; in set_fan()
557 data->fan_div[ix] = 3; in set_fan()
560 count = -EINVAL; in set_fan()
567 ((data->fan_div[1] << 6) | in set_fan()
568 (data->fan_div[0] << 4) | in set_fan()
569 data->fan_ctl)); in set_fan()
576 mutex_unlock(&data->update_lock); in set_fan()
580 /* ---------------------------------------------------------------------
582 * ix = [0-1]
583 * --------------------------------------------------------------------- */
596 int ix = sensor_attr_2->index; in show_pwm()
597 int fn = sensor_attr_2->nr; in show_pwm()
602 res = data->pwm[ix]; in show_pwm()
605 res = ((data->pwm_ctl[ix] >> 3) & 1) ? 2 : 0; in show_pwm()
608 res = 90000 >> (data->pwm_clk & 7); in show_pwm()
611 res = (data->pwm_ctl[ix] & 7) + 1; in show_pwm()
627 int ix = sensor_attr_2->index; in set_pwm()
628 int fn = sensor_attr_2->nr; in set_pwm()
637 mutex_lock(&data->update_lock); in set_pwm()
643 data->fan_div[0] = (reg >> 4) & 3; in set_pwm()
644 data->fan_div[1] = (reg >> 6) & 3; in set_pwm()
645 data->fan_ctl = reg & 0xf; in set_pwm()
647 data->pwm_ctl[0] = reg & 0xf; in set_pwm()
648 data->pwm_ctl[1] = (reg >> 4) & 0xf; in set_pwm()
651 data->pwm_ctl[ix] &= 7; in set_pwm()
656 if ((data->pwm_ctl[ix ^ 1] & 1) == 0) in set_pwm()
657 data->fan_ctl &= 0xe; in set_pwm()
660 data->pwm_ctl[ix] |= 8; in set_pwm()
661 data->fan_ctl |= 1; in set_pwm()
664 count = -EINVAL; in set_pwm()
671 ((data->pwm_ctl[1] << 4) | in set_pwm()
672 data->pwm_ctl[0])); in set_pwm()
674 ((data->fan_div[1] << 6) | in set_pwm()
675 (data->fan_div[0] << 4) | in set_pwm()
676 data->fan_ctl)); in set_pwm()
686 data->pwm_clk = (reg & 0xf8) | tmp; in set_pwm()
687 vt1211_write8(data, VT1211_REG_PWM_CLK, data->pwm_clk); in set_pwm()
691 count = -EINVAL; in set_pwm()
697 if (!ISTEMP(val - 1, data->uch_config)) { in set_pwm()
698 count = -EINVAL; in set_pwm()
705 data->pwm_ctl[0] = reg & 0xf; in set_pwm()
706 data->pwm_ctl[1] = (reg >> 4) & 0xf; in set_pwm()
707 data->pwm_ctl[ix] = (data->pwm_ctl[ix] & 8) | (val - 1); in set_pwm()
709 ((data->pwm_ctl[1] << 4) | data->pwm_ctl[0])); in set_pwm()
716 mutex_unlock(&data->update_lock); in set_pwm()
720 /* ---------------------------------------------------------------------
722 * ix = [0-1]
723 * ap = [0-3]
724 * --------------------------------------------------------------------- */
733 * -------------------
751 int ix = sensor_attr_2->index; in show_pwm_auto_point_temp()
752 int ap = sensor_attr_2->nr; in show_pwm_auto_point_temp()
754 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->pwm_ctl[ix] & 7, in show_pwm_auto_point_temp()
755 data->pwm_auto_temp[ap])); in show_pwm_auto_point_temp()
765 int ix = sensor_attr_2->index; in set_pwm_auto_point_temp()
766 int ap = sensor_attr_2->nr; in set_pwm_auto_point_temp()
776 mutex_lock(&data->update_lock); in set_pwm_auto_point_temp()
780 data->pwm_ctl[0] = reg & 0xf; in set_pwm_auto_point_temp()
781 data->pwm_ctl[1] = (reg >> 4) & 0xf; in set_pwm_auto_point_temp()
783 data->pwm_auto_temp[ap] = TEMP_TO_REG(data->pwm_ctl[ix] & 7, val); in set_pwm_auto_point_temp()
785 data->pwm_auto_temp[ap]); in set_pwm_auto_point_temp()
786 mutex_unlock(&data->update_lock); in set_pwm_auto_point_temp()
793 * Note that the PWM auto points 0 & 3 are hard-wired in the VT1211 and can't
797 * -------------------
798 * 0 0 : pwm1 off (pwm_auto_pwm[0][0], hard-wired to 0)
801 * 0 3 : pwm1 full speed (pwm_auto_pwm[0][3], hard-wired to 255)
802 * 1 0 : pwm2 off (pwm_auto_pwm[1][0], hard-wired to 0)
805 * 1 3 : pwm2 full speed (pwm_auto_pwm[1][3], hard-wired to 255)
815 int ix = sensor_attr_2->index; in show_pwm_auto_point_pwm()
816 int ap = sensor_attr_2->nr; in show_pwm_auto_point_pwm()
818 return sprintf(buf, "%d\n", data->pwm_auto_pwm[ix][ap]); in show_pwm_auto_point_pwm()
828 int ix = sensor_attr_2->index; in set_pwm_auto_point_pwm()
829 int ap = sensor_attr_2->nr; in set_pwm_auto_point_pwm()
837 mutex_lock(&data->update_lock); in set_pwm_auto_point_pwm()
838 data->pwm_auto_pwm[ix][ap] = clamp_val(val, 0, 255); in set_pwm_auto_point_pwm()
840 data->pwm_auto_pwm[ix][ap]); in set_pwm_auto_point_pwm()
841 mutex_unlock(&data->update_lock); in set_pwm_auto_point_pwm()
846 /* ---------------------------------------------------------------------
848 * --------------------------------------------------------------------- */
855 return sprintf(buf, "%d\n", data->vrm); in show_vrm()
870 return -EINVAL; in set_vrm()
872 data->vrm = val; in set_vrm()
882 return sprintf(buf, "%d\n", vid_from_reg(data->vid, data->vrm)); in show_vid()
890 return sprintf(buf, "%s\n", data->name); in show_name()
898 return sprintf(buf, "%d\n", data->alarms); in show_alarms()
901 /* ---------------------------------------------------------------------
903 * --------------------------------------------------------------------- */
953 show_temp, NULL, SHOW_TEMP_INPUT, ix-1), \
955 show_temp, set_temp, SHOW_SET_TEMP_MAX, ix-1), \
957 show_temp, set_temp, SHOW_SET_TEMP_MAX_HYST, ix-1), \
959 show_temp, NULL, SHOW_TEMP_ALARM, ix-1) \
1002 show_fan, NULL, SHOW_FAN_INPUT, ix-1), \
1004 show_fan, set_fan, SHOW_SET_FAN_MIN, ix-1), \
1006 show_fan, set_fan, SHOW_SET_FAN_DIV, ix-1), \
1008 show_fan, NULL, SHOW_FAN_ALARM, ix-1)
1012 show_pwm, NULL, SHOW_PWM, ix-1), \
1014 show_pwm, set_pwm, SHOW_SET_PWM_ENABLE, ix-1), \
1016 show_pwm, set_pwm, SHOW_SET_PWM_AUTO_CHANNELS_TEMP, ix-1)
1020 show_pwm, set_pwm, SHOW_SET_PWM_FREQ, ix-1)
1024 show_pwm, NULL, SHOW_SET_PWM_FREQ, ix-1)
1029 ap-1, ix-1)
1034 ap-1, ix-1)
1039 ap-1, ix-1)
1044 ap-1, ix-1)
1078 /* ---------------------------------------------------------------------
1080 * --------------------------------------------------------------------- */
1085 data->vrm = vid_which_vrm(); in vt1211_init_device()
1088 data->uch_config = vt1211_read8(data, VT1211_REG_UCH_CONFIG); in vt1211_init_device()
1089 if (uch_config > -1) { in vt1211_init_device()
1090 data->uch_config = (data->uch_config & 0x83) | in vt1211_init_device()
1092 vt1211_write8(data, VT1211_REG_UCH_CONFIG, data->uch_config); in vt1211_init_device()
1113 /* Fill in some hard wired values into our data struct */ in vt1211_init_device()
1114 data->pwm_auto_pwm[0][3] = 255; in vt1211_init_device()
1115 data->pwm_auto_pwm[1][3] = 255; in vt1211_init_device()
1120 struct device *dev = &pdev->dev; in vt1211_remove_sysfs()
1124 sysfs_remove_group(&dev->kobj, &vt1211_in_attr_group[i]); in vt1211_remove_sysfs()
1127 sysfs_remove_group(&dev->kobj, &vt1211_temp_attr_group[i]); in vt1211_remove_sysfs()
1139 struct device *dev = &pdev->dev; in vt1211_probe()
1146 return -ENOMEM; in vt1211_probe()
1149 if (!devm_request_region(dev, res->start, resource_size(res), in vt1211_probe()
1151 dev_err(dev, "Failed to request region 0x%lx-0x%lx\n", in vt1211_probe()
1152 (unsigned long)res->start, (unsigned long)res->end); in vt1211_probe()
1153 return -EBUSY; in vt1211_probe()
1155 data->addr = res->start; in vt1211_probe()
1156 data->name = DRVNAME; in vt1211_probe()
1157 mutex_init(&data->update_lock); in vt1211_probe()
1166 if (ISVOLT(i, data->uch_config)) { in vt1211_probe()
1167 err = sysfs_create_group(&dev->kobj, in vt1211_probe()
1174 if (ISTEMP(i, data->uch_config)) { in vt1211_probe()
1175 err = sysfs_create_group(&dev->kobj, in vt1211_probe()
1195 data->hwmon_dev = hwmon_device_register(dev); in vt1211_probe()
1196 if (IS_ERR(data->hwmon_dev)) { in vt1211_probe()
1197 err = PTR_ERR(data->hwmon_dev); in vt1211_probe()
1215 hwmon_device_unregister(data->hwmon_dev); in vt1211_remove()
1238 err = -ENOMEM; in vt1211_device_add()
1243 res.name = pdev->name; in vt1211_device_add()
1277 err = -ENODEV; in vt1211_find()
1317 if ((uch_config < -1) || (uch_config > 31)) { in vt1211_init()
1318 err = -EINVAL; in vt1211_init()
1324 if ((int_mode < -1) || (int_mode > 0)) { in vt1211_init()
1325 err = -EINVAL; in vt1211_init()