Lines Matching +full:south +full:- +full:field

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * vt8231.c - Part of lm_sensors, Linux kernel modules
12 * Supports VIA VT8231 South Bridge embedded sensors
24 #include <linux/hwmon-sysfs.h>
51 * -------- -------- -------- ------
64 /* fans numbered 0-1 */
68 /* Voltage inputs numbered 0-5 */
75 * Temperatures are numbered 1-6 according to the Linux kernel specification.
90 #define TEMP_FROM_REG(reg) (((253 * 4 - (reg)) * 550 + 105) / 210)
91 #define TEMP_MAXMIN_FROM_REG(reg) (((253 - (reg)) * 2200 + 105) / 210)
92 #define TEMP_MAXMIN_TO_REG(val) (253 - ((val) * 210 + 1100) / 2200)
103 * temps 0-5 as numbered in VIA datasheet - see later for mapping to Linux
108 /* voltages 0-5 */
116 * for the thermistor curves are board-specific and must go in the
123 * All the on-chip hardware temperature comparisons for the alarms are only
124 * 8-bits wide, and compare against the 8 MSBs of the temperature. The bits
169 return inb_p(data->addr + reg); in vt8231_read_value()
175 outb_p(value, data->addr + reg); in vt8231_write_value()
184 mutex_lock(&data->update_lock); in vt8231_update_device()
186 if (time_after(jiffies, data->last_updated + HZ + HZ / 2) in vt8231_update_device()
187 || !data->valid) { in vt8231_update_device()
189 if (ISVOLT(i, data->uch_config)) { in vt8231_update_device()
190 data->in[i] = vt8231_read_value(data, in vt8231_update_device()
192 data->in_min[i] = vt8231_read_value(data, in vt8231_update_device()
194 data->in_max[i] = vt8231_read_value(data, in vt8231_update_device()
199 data->fan[i] = vt8231_read_value(data, in vt8231_update_device()
201 data->fan_min[i] = vt8231_read_value(data, in vt8231_update_device()
209 if (ISTEMP(i, data->uch_config)) { in vt8231_update_device()
210 data->temp[i] = (vt8231_read_value(data, in vt8231_update_device()
213 data->temp_max[i] = vt8231_read_value(data, in vt8231_update_device()
215 data->temp_min[i] = vt8231_read_value(data, in vt8231_update_device()
221 data->fan_div[0] = (i >> 4) & 0x03; in vt8231_update_device()
222 data->fan_div[1] = i >> 6; in vt8231_update_device()
223 data->alarms = vt8231_read_value(data, VT8231_REG_ALARM1) | in vt8231_update_device()
227 if (!data->fan[0] && data->fan_min[0]) in vt8231_update_device()
228 data->alarms |= 0x40; in vt8231_update_device()
229 else if (data->fan[0] && !data->fan_min[0]) in vt8231_update_device()
230 data->alarms &= ~0x40; in vt8231_update_device()
232 if (!data->fan[1] && data->fan_min[1]) in vt8231_update_device()
233 data->alarms |= 0x80; in vt8231_update_device()
234 else if (data->fan[1] && !data->fan_min[1]) in vt8231_update_device()
235 data->alarms &= ~0x80; in vt8231_update_device()
237 data->last_updated = jiffies; in vt8231_update_device()
238 data->valid = true; in vt8231_update_device()
241 mutex_unlock(&data->update_lock); in vt8231_update_device()
251 int nr = sensor_attr->index; in in_show()
254 return sprintf(buf, "%d\n", ((data->in[nr] - 3) * 10000) / 958); in in_show()
261 int nr = sensor_attr->index; in in_min_show()
264 return sprintf(buf, "%d\n", ((data->in_min[nr] - 3) * 10000) / 958); in in_min_show()
271 int nr = sensor_attr->index; in in_max_show()
274 return sprintf(buf, "%d\n", (((data->in_max[nr] - 3) * 10000) / 958)); in in_max_show()
281 int nr = sensor_attr->index; in in_min_store()
290 mutex_lock(&data->update_lock); in in_min_store()
291 data->in_min[nr] = clamp_val(((val * 958) / 10000) + 3, 0, 255); in in_min_store()
292 vt8231_write_value(data, regvoltmin[nr], data->in_min[nr]); in in_min_store()
293 mutex_unlock(&data->update_lock); in in_min_store()
301 int nr = sensor_attr->index; in in_max_store()
310 mutex_lock(&data->update_lock); in in_max_store()
311 data->in_max[nr] = clamp_val(((val * 958) / 10000) + 3, 0, 255); in in_max_store()
312 vt8231_write_value(data, regvoltmax[nr], data->in_max[nr]); in in_max_store()
313 mutex_unlock(&data->update_lock); in in_max_store()
324 (((data->in[5] - 3) * 10000 * 54) / (958 * 34))); in in5_input_show()
333 (((data->in_min[5] - 3) * 10000 * 54) / (958 * 34))); in in5_min_show()
342 (((data->in_max[5] - 3) * 10000 * 54) / (958 * 34))); in in5_max_show()
357 mutex_lock(&data->update_lock); in in5_min_store()
358 data->in_min[5] = clamp_val(((val * 958 * 34) / (10000 * 54)) + 3, in in5_min_store()
360 vt8231_write_value(data, regvoltmin[5], data->in_min[5]); in in5_min_store()
361 mutex_unlock(&data->update_lock); in in5_min_store()
377 mutex_lock(&data->update_lock); in in5_max_store()
378 data->in_max[5] = clamp_val(((val * 958 * 34) / (10000 * 54)) + 3, in in5_max_store()
380 vt8231_write_value(data, regvoltmax[5], data->in_max[5]); in in5_max_store()
381 mutex_unlock(&data->update_lock); in in5_max_store()
410 return sprintf(buf, "%d\n", data->temp[0] * 250); in temp1_input_show()
417 return sprintf(buf, "%d\n", data->temp_max[0] * 1000); in temp1_max_show()
424 return sprintf(buf, "%d\n", data->temp_min[0] * 1000); in temp1_max_hyst_show()
439 mutex_lock(&data->update_lock); in temp1_max_store()
440 data->temp_max[0] = clamp_val((val + 500) / 1000, 0, 255); in temp1_max_store()
441 vt8231_write_value(data, regtempmax[0], data->temp_max[0]); in temp1_max_store()
442 mutex_unlock(&data->update_lock); in temp1_max_store()
457 mutex_lock(&data->update_lock); in temp1_max_hyst_store()
458 data->temp_min[0] = clamp_val((val + 500) / 1000, 0, 255); in temp1_max_hyst_store()
459 vt8231_write_value(data, regtempmin[0], data->temp_min[0]); in temp1_max_hyst_store()
460 mutex_unlock(&data->update_lock); in temp1_max_hyst_store()
468 int nr = sensor_attr->index; in temp_show()
470 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[nr])); in temp_show()
477 int nr = sensor_attr->index; in temp_max_show()
479 return sprintf(buf, "%d\n", TEMP_MAXMIN_FROM_REG(data->temp_max[nr])); in temp_max_show()
486 int nr = sensor_attr->index; in temp_min_show()
488 return sprintf(buf, "%d\n", TEMP_MAXMIN_FROM_REG(data->temp_min[nr])); in temp_min_show()
496 int nr = sensor_attr->index; in temp_max_store()
505 mutex_lock(&data->update_lock); in temp_max_store()
506 data->temp_max[nr] = clamp_val(TEMP_MAXMIN_TO_REG(val), 0, 255); in temp_max_store()
507 vt8231_write_value(data, regtempmax[nr], data->temp_max[nr]); in temp_max_store()
508 mutex_unlock(&data->update_lock); in temp_max_store()
516 int nr = sensor_attr->index; in temp_min_store()
525 mutex_lock(&data->update_lock); in temp_min_store()
526 data->temp_min[nr] = clamp_val(TEMP_MAXMIN_TO_REG(val), 0, 255); in temp_min_store()
527 vt8231_write_value(data, regtempmin[nr], data->temp_min[nr]); in temp_min_store()
528 mutex_unlock(&data->update_lock); in temp_min_store()
533 * Note that these map the Linux temperature sensor numbering (1-6) to the VIA
534 * temperature sensor numbering (0-5)
562 int nr = sensor_attr->index; in fan_show()
564 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr], in fan_show()
565 DIV_FROM_REG(data->fan_div[nr]))); in fan_show()
572 int nr = sensor_attr->index; in fan_min_show()
574 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[nr], in fan_min_show()
575 DIV_FROM_REG(data->fan_div[nr]))); in fan_min_show()
582 int nr = sensor_attr->index; in fan_div_show()
584 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr])); in fan_div_show()
592 int nr = sensor_attr->index; in fan_min_store()
601 mutex_lock(&data->update_lock); in fan_min_store()
602 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); in fan_min_store()
603 vt8231_write_value(data, VT8231_REG_FAN_MIN(nr), data->fan_min[nr]); in fan_min_store()
604 mutex_unlock(&data->update_lock); in fan_min_store()
615 int nr = sensor_attr->index; in fan_div_store()
617 long min = FAN_FROM_REG(data->fan_min[nr], in fan_div_store()
618 DIV_FROM_REG(data->fan_div[nr])); in fan_div_store()
625 mutex_lock(&data->update_lock); in fan_div_store()
628 data->fan_div[nr] = 0; in fan_div_store()
631 data->fan_div[nr] = 1; in fan_div_store()
634 data->fan_div[nr] = 2; in fan_div_store()
637 data->fan_div[nr] = 3; in fan_div_store()
643 mutex_unlock(&data->update_lock); in fan_div_store()
644 return -EINVAL; in fan_div_store()
648 data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); in fan_div_store()
649 vt8231_write_value(data, VT8231_REG_FAN_MIN(nr), data->fan_min[nr]); in fan_div_store()
651 old = (old & 0x0f) | (data->fan_div[1] << 6) | (data->fan_div[0] << 4); in fan_div_store()
653 mutex_unlock(&data->update_lock); in fan_div_store()
669 return sprintf(buf, "%d\n", data->alarms); in alarms_show()
676 int bitnr = to_sensor_dev_attr(attr)->index; in alarm_show()
678 return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1); in alarm_show()
699 return sprintf(buf, "%s\n", data->name); in name_show()
833 if (!devm_request_region(&pdev->dev, res->start, VT8231_EXTENT, in vt8231_probe()
835 dev_err(&pdev->dev, "Region 0x%lx-0x%lx already in use!\n", in vt8231_probe()
836 (unsigned long)res->start, (unsigned long)res->end); in vt8231_probe()
837 return -ENODEV; in vt8231_probe()
840 data = devm_kzalloc(&pdev->dev, sizeof(struct vt8231_data), GFP_KERNEL); in vt8231_probe()
842 return -ENOMEM; in vt8231_probe()
845 data->addr = res->start; in vt8231_probe()
846 data->name = DRIVER_NAME; in vt8231_probe()
848 mutex_init(&data->update_lock); in vt8231_probe()
852 err = sysfs_create_group(&pdev->dev.kobj, &vt8231_group); in vt8231_probe()
856 /* Must update device information to find out the config field */ in vt8231_probe()
857 data->uch_config = vt8231_read_value(data, VT8231_REG_UCH_CONFIG); in vt8231_probe()
860 if (ISTEMP(i, data->uch_config)) { in vt8231_probe()
861 err = sysfs_create_group(&pdev->dev.kobj, in vt8231_probe()
869 if (ISVOLT(i, data->uch_config)) { in vt8231_probe()
870 err = sysfs_create_group(&pdev->dev.kobj, in vt8231_probe()
877 data->hwmon_dev = hwmon_device_register(&pdev->dev); in vt8231_probe()
878 if (IS_ERR(data->hwmon_dev)) { in vt8231_probe()
879 err = PTR_ERR(data->hwmon_dev); in vt8231_probe()
886 sysfs_remove_group(&pdev->dev.kobj, &vt8231_group_volts[i]); in vt8231_probe()
889 sysfs_remove_group(&pdev->dev.kobj, &vt8231_group_temps[i]); in vt8231_probe()
891 sysfs_remove_group(&pdev->dev.kobj, &vt8231_group); in vt8231_probe()
900 hwmon_device_unregister(data->hwmon_dev); in vt8231_remove()
903 sysfs_remove_group(&pdev->dev.kobj, &vt8231_group_volts[i]); in vt8231_remove()
906 sysfs_remove_group(&pdev->dev.kobj, &vt8231_group_temps[i]); in vt8231_remove()
908 sysfs_remove_group(&pdev->dev.kobj, &vt8231_group); in vt8231_remove()
931 .end = address + VT8231_EXTENT - 1, in vt8231_device_add()
943 err = -ENOMEM; in vt8231_device_add()
976 dev_warn(&dev->dev, "Forcing ISA address 0x%x\n", in vt8231_pci_probe()
981 return -ENODEV; in vt8231_pci_probe()
986 return -ENODEV; in vt8231_pci_probe()
988 address = val & ~(VT8231_EXTENT - 1); in vt8231_pci_probe()
990 dev_err(&dev->dev, "base address not set - upgrade BIOS or use force_addr=0xaddr\n"); in vt8231_pci_probe()
991 return -ENODEV; in vt8231_pci_probe()
996 return -ENODEV; in vt8231_pci_probe()
999 dev_warn(&dev->dev, "enabling sensors\n"); in vt8231_pci_probe()
1002 return -ENODEV; in vt8231_pci_probe()
1023 return -ENODEV; in vt8231_pci_probe()
1028 return -ENODEV; in vt8231_pci_probe()