From: "Nuno Sá" <noname.nuno@gmail.com>
To: Radu Sabau <radu.sabau@analog.com>,
Jean Delvare <jdelvare@suse.com>,
Guenter Roeck <linux@roeck-us.net>,
Jonathan Corbet <corbet@lwn.net>,
linux-hwmon@vger.kernel.org, linux-doc@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] drivers: hwmon: max31827: Add PEC support
Date: Wed, 22 May 2024 15:08:51 +0200 [thread overview]
Message-ID: <fc29f19a1ecbceef64bf219a9441eb5b9f09503a.camel@gmail.com> (raw)
In-Reply-To: <20240522123923.22320-2-radu.sabau@analog.com>
On Wed, 2024-05-22 at 15:39 +0300, Radu Sabau wrote:
> Add support for PEC by attaching PEC attribute to the i2c device.
> Add pec_store and pec_show function for accesing the "pec" file.
>
> Signed-off-by: Radu Sabau <radu.sabau@analog.com>
> ---
> Documentation/hwmon/max31827.rst | 13 ++++-
> drivers/hwmon/max31827.c | 95 +++++++++++++++++++++++++++-----
> 2 files changed, 92 insertions(+), 16 deletions(-)
>
> diff --git a/Documentation/hwmon/max31827.rst b/Documentation/hwmon/max31827.rst
> index 44ab9dc064cb..9c11a9518c67 100644
> --- a/Documentation/hwmon/max31827.rst
> +++ b/Documentation/hwmon/max31827.rst
> @@ -131,7 +131,14 @@ The Fault Queue bits select how many consecutive temperature
> faults must occur
> before overtemperature or undertemperature faults are indicated in the
> corresponding status bits.
>
> -Notes
> ------
> +PEC Support
> +-----------
> +
> +When reading a register value, the PEC byte is computed and sent by the chip.
> +
> +PEC on word data transaction respresents a signifcant increase in bandwitdh
> +usage (+33% for both write and reads) in normal conditions.
>
> -PEC is not implemented.
> +Since this operation implies there will be an extra delay to each
> +transaction, PEC can be disabled or enabled through sysfs.
> +Just write 1 to the "pec" file for enabling PEC and 0 for disabling it.
> diff --git a/drivers/hwmon/max31827.c b/drivers/hwmon/max31827.c
> index f8a13b30f100..16a1524413db 100644
> --- a/drivers/hwmon/max31827.c
> +++ b/drivers/hwmon/max31827.c
> @@ -11,19 +11,20 @@
> #include <linux/hwmon.h>
> #include <linux/i2c.h>
> #include <linux/mutex.h>
> -#include <linux/of_device.h>
> #include <linux/regmap.h>
> #include <linux/regulator/consumer.h>
> +#include <linux/of_device.h>
>
Looks like unrelated change...
> -#define MAX31827_T_REG 0x0
> +#define MAX31827_T_REG 0x0
> #define MAX31827_CONFIGURATION_REG 0x2
> -#define MAX31827_TH_REG 0x4
> -#define MAX31827_TL_REG 0x6
> -#define MAX31827_TH_HYST_REG 0x8
> -#define MAX31827_TL_HYST_REG 0xA
> +#define MAX31827_TH_REG 0x4
> +#define MAX31827_TL_REG 0x6
> +#define MAX31827_TH_HYST_REG 0x8
> +#define MAX31827_TL_HYST_REG 0xA
ditto for all the other places
...
>
> +static ssize_t pec_show(struct device *dev, struct device_attribute *devattr,
> + char *buf)
> +{
> + struct i2c_client *client = to_i2c_client(dev);
> +
> + return scnprintf(buf, PAGE_SIZE, "%d\n", !!(client->flags &
> I2C_CLIENT_PEC));
sysfs_emit()
> +}
> +
> +static ssize_t pec_store(struct device *dev, struct device_attribute *devattr,
> + const char *buf, size_t count)
> +{
> + struct max31827_state *st = dev_get_drvdata(dev);
> + struct i2c_client *client = to_i2c_client(dev);
> + unsigned int val, val2;
> + int err;
> +
> + err = kstrtouint(buf, 10, &val);
> + if (err < 0)
> + return err;
> +
> + val2 = FIELD_PREP(MAX31827_CONFIGURATION_PEC_EN_MASK, !!val);
> +
Why not just val?
> + switch (val) {
> + case 0:
> + err = regmap_update_bits(st->regmap, MAX31827_CONFIGURATION_REG,
> + MAX31827_CONFIGURATION_PEC_EN_MASK,
> + val2);
> + if (err)
> + return err;
> +
> + client->flags &= ~I2C_CLIENT_PEC;
> + break;
> + case 1:
> + err = regmap_update_bits(st->regmap, MAX31827_CONFIGURATION_REG,
> + MAX31827_CONFIGURATION_PEC_EN_MASK,
> + val2);
> + if (err)
> + return err;
> +
> + client->flags |= I2C_CLIENT_PEC;
> + break;
> + default:
> + return -EINVAL;
> + }
> +
> + return count;
> +}
> +static DEVICE_ATTR_RW(pec);
> +
> static struct attribute *max31827_attrs[] = {
> &dev_attr_temp1_resolution.attr,
> + &dev_attr_pec.attr,
Do we need it in here??
- Nuno Sá
next prev parent reply other threads:[~2024-05-22 13:08 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-22 12:39 [PATCH 0/2] Update MAX31827 driver Radu Sabau
2024-05-22 12:39 ` [PATCH 1/2] drivers: hwmon: max31827: Add PEC support Radu Sabau
2024-05-22 13:08 ` Nuno Sá [this message]
2024-05-23 4:37 ` kernel test robot
2024-05-23 5:11 ` Guenter Roeck
2024-05-22 12:39 ` [PATCH 2/2] drivers: hwmon: max31827: Add debugfs support Radu Sabau
2024-05-22 13:10 ` Nuno Sá
2024-05-23 4:53 ` Guenter Roeck
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=fc29f19a1ecbceef64bf219a9441eb5b9f09503a.camel@gmail.com \
--to=noname.nuno@gmail.com \
--cc=corbet@lwn.net \
--cc=jdelvare@suse.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=radu.sabau@analog.com \
/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