From: Guenter Roeck <linux@roeck-us.net>
To: W_Armin@gmx.de
Cc: jdelvare@suse.com, linux-hwmon@vger.kernel.org
Subject: Re: [PATCH RESEND] hwmon: (i5500_temp) Convert to devm_hwmon_device_register_with_info
Date: Sat, 4 Sep 2021 08:05:56 -0700 [thread overview]
Message-ID: <20210904150556.GA3637780@roeck-us.net> (raw)
In-Reply-To: <20210823170724.7662-1-W_Armin@gmx.de>
On Mon, Aug 23, 2021 at 07:07:24PM +0200, W_Armin@gmx.de wrote:
> From: Armin Wolf <W_Armin@gmx.de>
>
> Use devm_hwmon_device_register_with_info() to simplify code
> and use register defines instead of hardcoded values.
> Also use the BIT() macro for the alarms.
>
> Only compile-tested.
>
> Signed-off-by: Armin Wolf <W_Armin@gmx.de>
I'll queue this patch up for v5.16. Let's hope it gets some test
coverage.
Guenter
> ---
> drivers/hwmon/i5500_temp.c | 114 ++++++++++++++++++++-----------------
> 1 file changed, 61 insertions(+), 53 deletions(-)
>
> --
> 2.20.1
>
> diff --git a/drivers/hwmon/i5500_temp.c b/drivers/hwmon/i5500_temp.c
> index 360f5aee1394..05f68e9c9477 100644
> --- a/drivers/hwmon/i5500_temp.c
> +++ b/drivers/hwmon/i5500_temp.c
> @@ -5,6 +5,7 @@
> * Copyright (C) 2012, 2014 Jean Delvare <jdelvare@suse.de>
> */
>
> +#include <linux/bitops.h>
> #include <linux/module.h>
> #include <linux/init.h>
> #include <linux/slab.h>
> @@ -12,7 +13,6 @@
> #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>
>
> @@ -29,69 +29,78 @@
> #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 umode_t i5500_is_visible(const void *drvdata, enum hwmon_sensor_types type, u32 attr,
> + int channel)
> {
> - 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);
> + return 0444;
> }
>
> -static ssize_t thresh_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);
> - 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 alarm_show(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 = {
> + .is_visible = i5500_is_visible,
> + .read = i5500_read,
> +};
>
> -static DEVICE_ATTR_RO(temp1_input);
> -static SENSOR_DEVICE_ATTR_RO(temp1_crit, thresh, 0xE2);
> -static SENSOR_DEVICE_ATTR_RO(temp1_max_hyst, thresh, 0xEC);
> -static SENSOR_DEVICE_ATTR_RO(temp1_max, thresh, 0xEE);
> -static SENSOR_DEVICE_ATTR_RO(temp1_crit_alarm, alarm, 0);
> -static SENSOR_DEVICE_ATTR_RO(temp1_max_alarm, alarm, 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 *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) },
> @@ -121,9 +130,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);
> }
prev parent reply other threads:[~2021-09-04 15:06 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-23 17:07 [PATCH RESEND] hwmon: (i5500_temp) Convert to devm_hwmon_device_register_with_info W_Armin
2021-08-24 20:45 ` Guenter Roeck
2021-09-04 15:05 ` Guenter Roeck [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210904150556.GA3637780@roeck-us.net \
--to=linux@roeck-us.net \
--cc=W_Armin@gmx.de \
--cc=jdelvare@suse.com \
--cc=linux-hwmon@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox