diff options
Diffstat (limited to 'drivers/hwmon/i5500_temp.c')
| -rw-r--r-- | drivers/hwmon/i5500_temp.c | 130 |
1 files changed, 60 insertions, 70 deletions
diff --git a/drivers/hwmon/i5500_temp.c b/drivers/hwmon/i5500_temp.c index 400e0675a90b..bf006cb272b1 100644 --- a/drivers/hwmon/i5500_temp.c +++ b/drivers/hwmon/i5500_temp.c @@ -1,29 +1,17 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * i5500_temp - Driver for Intel 5500/5520/X58 chipset thermal sensor * * Copyright (C) 2012, 2014 Jean Delvare <jdelvare@suse.de> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. */ +#include <linux/bitops.h> #include <linux/module.h> #include <linux/init.h> -#include <linux/slab.h> -#include <linux/jiffies.h> #include <linux/device.h> #include <linux/pci.h> #include <linux/hwmon.h> -#include <linux/hwmon-sysfs.h> #include <linux/err.h> -#include <linux/mutex.h> /* Register definitions from datasheet */ #define REG_TSTHRCATA 0xE2 @@ -38,69 +26,72 @@ #define REG_CTCTRL 0xF7 #define REG_TSTIMER 0xF8 -/* - * Sysfs stuff - */ - -/* Sensor resolution : 0.5 degree C */ -static ssize_t temp1_input_show(struct device *dev, - struct device_attribute *devattr, char *buf) +static int i5500_read(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel, + long *val) { struct pci_dev *pdev = to_pci_dev(dev->parent); - long temp; - u16 tsthrhi; - s8 tsfsc; - - pci_read_config_word(pdev, REG_TSTHRHI, &tsthrhi); - pci_read_config_byte(pdev, REG_TSFSC, &tsfsc); - temp = ((long)tsthrhi - tsfsc) * 500; - - return sprintf(buf, "%ld\n", temp); -} - -static ssize_t show_thresh(struct device *dev, - struct device_attribute *devattr, char *buf) -{ - struct pci_dev *pdev = to_pci_dev(dev->parent); - int reg = to_sensor_dev_attr(devattr)->index; - long temp; u16 tsthr; + s8 tsfsc; + u8 ctsts; - pci_read_config_word(pdev, reg, &tsthr); - temp = tsthr * 500; + switch (type) { + case hwmon_temp: + switch (attr) { + /* Sensor resolution : 0.5 degree C */ + case hwmon_temp_input: + pci_read_config_word(pdev, REG_TSTHRHI, &tsthr); + pci_read_config_byte(pdev, REG_TSFSC, &tsfsc); + *val = (tsthr - tsfsc) * 500; + return 0; + case hwmon_temp_max: + pci_read_config_word(pdev, REG_TSTHRHI, &tsthr); + *val = tsthr * 500; + return 0; + case hwmon_temp_max_hyst: + pci_read_config_word(pdev, REG_TSTHRLO, &tsthr); + *val = tsthr * 500; + return 0; + case hwmon_temp_crit: + pci_read_config_word(pdev, REG_TSTHRCATA, &tsthr); + *val = tsthr * 500; + return 0; + case hwmon_temp_max_alarm: + pci_read_config_byte(pdev, REG_CTSTS, &ctsts); + *val = !!(ctsts & BIT(1)); + return 0; + case hwmon_temp_crit_alarm: + pci_read_config_byte(pdev, REG_CTSTS, &ctsts); + *val = !!(ctsts & BIT(0)); + return 0; + default: + break; + } + break; + default: + break; + } - return sprintf(buf, "%ld\n", temp); + return -EOPNOTSUPP; } -static ssize_t show_alarm(struct device *dev, - struct device_attribute *devattr, char *buf) -{ - struct pci_dev *pdev = to_pci_dev(dev->parent); - int nr = to_sensor_dev_attr(devattr)->index; - u8 ctsts; - - pci_read_config_byte(pdev, REG_CTSTS, &ctsts); - return sprintf(buf, "%u\n", (unsigned int)ctsts & (1 << nr)); -} +static const struct hwmon_ops i5500_ops = { + .visible = 0444, + .read = i5500_read, +}; -static DEVICE_ATTR_RO(temp1_input); -static SENSOR_DEVICE_ATTR(temp1_crit, S_IRUGO, show_thresh, NULL, 0xE2); -static SENSOR_DEVICE_ATTR(temp1_max_hyst, S_IRUGO, show_thresh, NULL, 0xEC); -static SENSOR_DEVICE_ATTR(temp1_max, S_IRUGO, show_thresh, NULL, 0xEE); -static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 0); -static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 1); - -static struct attribute *i5500_temp_attrs[] = { - &dev_attr_temp1_input.attr, - &sensor_dev_attr_temp1_crit.dev_attr.attr, - &sensor_dev_attr_temp1_max_hyst.dev_attr.attr, - &sensor_dev_attr_temp1_max.dev_attr.attr, - &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr, - &sensor_dev_attr_temp1_max_alarm.dev_attr.attr, +static const struct hwmon_channel_info * const i5500_info[] = { + HWMON_CHANNEL_INFO(chip, HWMON_C_REGISTER_TZ), + HWMON_CHANNEL_INFO(temp, + HWMON_T_INPUT | HWMON_T_MAX | HWMON_T_MAX_HYST | HWMON_T_CRIT | + HWMON_T_MAX_ALARM | HWMON_T_CRIT_ALARM + ), NULL }; -ATTRIBUTE_GROUPS(i5500_temp); +static const struct hwmon_chip_info i5500_chip_info = { + .ops = &i5500_ops, + .info = i5500_info, +}; static const struct pci_device_id i5500_temp_ids[] = { { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x3438) }, @@ -117,7 +108,7 @@ static int i5500_temp_probe(struct pci_dev *pdev, u32 tstimer; s8 tsfsc; - err = pci_enable_device(pdev); + err = pcim_enable_device(pdev); if (err) { dev_err(&pdev->dev, "Failed to enable device\n"); return err; @@ -130,9 +121,8 @@ static int i5500_temp_probe(struct pci_dev *pdev, return -ENODEV; } - hwmon_dev = devm_hwmon_device_register_with_groups(&pdev->dev, - "intel5500", NULL, - i5500_temp_groups); + hwmon_dev = devm_hwmon_device_register_with_info(&pdev->dev, "intel5500", NULL, + &i5500_chip_info, NULL); return PTR_ERR_OR_ZERO(hwmon_dev); } |
