From: Guenter Roeck <linux@roeck-us.net>
To: Wilken Gottwalt <wilken.gottwalt@posteo.net>
Cc: linux-kernel@vger.kernel.org, Jean Delvare <jdelvare@suse.com>,
Jonathan Corbet <corbet@lwn.net>,
linux-hwmon@vger.kernel.org
Subject: Re: [PATCH] hwmon: corsair-psu: update calculation of LINEAR11 values
Date: Thu, 11 Mar 2021 13:39:33 -0800 [thread overview]
Message-ID: <20210311213933.GA35601@roeck-us.net> (raw)
In-Reply-To: <YDoSMqFbgoTXyoru@monster.powergraphx.local>
On Sat, Feb 27, 2021 at 10:34:42AM +0100, Wilken Gottwalt wrote:
> Changes the way how LINEAR11 values are calculated. The new method
> increases the precision of 2-3 digits.
>
> old method:
> corsairpsu-hid-3-1
> Adapter: HID adapter
> v_in: 230.00 V
> v_out +12v: 12.00 V
> v_out +5v: 5.00 V
> v_out +3.3v: 3.00 V
> psu fan: 0 RPM
> vrm temp: +44.0°C
> case temp: +37.0°C
> power total: 152.00 W
> power +12v: 112.00 W
> power +5v: 38.00 W
> power +3.3v: 5.00 W
> curr in: N/A
> curr +12v: 9.00 A
> curr +5v: 7.00 A
> curr +3.3v: 1000.00 mA
>
> new method:
> corsairpsu-hid-3-1
> Adapter: HID adapter
> v_in: 230.00 V
> v_out +12v: 12.16 V
> v_out +5v: 5.01 V
> v_out +3.3v: 3.30 V
> psu fan: 0 RPM
> vrm temp: +44.5°C
> case temp: +37.8°C
> power total: 148.00 W
> power +12v: 108.00 W
> power +5v: 37.00 W
> power +3.3v: 4.50 W
> curr in: N/A
> curr +12v: 9.25 A
> curr +5v: 7.50 A
> curr +3.3v: 1.50 A
>
> Co-developed-by: Jack Doan <me@jackdoan.com>
> Signed-off-by: Jack Doan <me@jackdoan.com>
> Signed-off-by: Wilken Gottwalt <wilken.gottwalt@posteo.net>
Applied.
Thanks,
Guenter
> ---
> drivers/hwmon/corsair-psu.c | 30 ++++++++----------------------
> 1 file changed, 8 insertions(+), 22 deletions(-)
>
> diff --git a/drivers/hwmon/corsair-psu.c b/drivers/hwmon/corsair-psu.c
> index 99494056f4bd..b0953eeeb2d3 100644
> --- a/drivers/hwmon/corsair-psu.c
> +++ b/drivers/hwmon/corsair-psu.c
> @@ -119,27 +119,13 @@ struct corsairpsu_data {
> };
>
> /* some values are SMBus LINEAR11 data which need a conversion */
> -static int corsairpsu_linear11_to_int(const int val)
> +static int corsairpsu_linear11_to_int(const u16 val, const int scale)
> {
> - int exp = (val & 0xFFFF) >> 0x0B;
> - int mant = val & 0x7FF;
> - int i;
> -
> - if (exp > 0x0F)
> - exp -= 0x20;
> - if (mant > 0x3FF)
> - mant -= 0x800;
> - if ((mant & 0x01) == 1)
> - ++mant;
> - if (exp < 0) {
> - for (i = 0; i < -exp; ++i)
> - mant /= 2;
> - } else {
> - for (i = 0; i < exp; ++i)
> - mant *= 2;
> - }
> + const int exp = ((s16)val) >> 11;
> + const int mant = (((s16)(val & 0x7ff)) << 5) >> 5;
> + const int result = mant * scale;
>
> - return mant;
> + return (exp >= 0) ? (result << exp) : (result >> -exp);
> }
>
> static int corsairpsu_usb_cmd(struct corsairpsu_data *priv, u8 p0, u8 p1, u8 p2, void *data)
> @@ -249,14 +235,14 @@ static int corsairpsu_get_value(struct corsairpsu_data *priv, u8 cmd, u8 rail, l
> case PSU_CMD_RAIL_AMPS:
> case PSU_CMD_TEMP0:
> case PSU_CMD_TEMP1:
> - *val = corsairpsu_linear11_to_int(tmp & 0xFFFF) * 1000;
> + *val = corsairpsu_linear11_to_int(tmp & 0xFFFF, 1000);
> break;
> case PSU_CMD_FAN:
> - *val = corsairpsu_linear11_to_int(tmp & 0xFFFF);
> + *val = corsairpsu_linear11_to_int(tmp & 0xFFFF, 1);
> break;
> case PSU_CMD_RAIL_WATTS:
> case PSU_CMD_TOTAL_WATTS:
> - *val = corsairpsu_linear11_to_int(tmp & 0xFFFF) * 1000000;
> + *val = corsairpsu_linear11_to_int(tmp & 0xFFFF, 1000000);
> break;
> case PSU_CMD_TOTAL_UPTIME:
> case PSU_CMD_UPTIME:
prev parent reply other threads:[~2021-03-11 21:40 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-27 9:34 [PATCH] hwmon: corsair-psu: update calculation of LINEAR11 values Wilken Gottwalt
2021-03-11 21:39 ` 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=20210311213933.GA35601@roeck-us.net \
--to=linux@roeck-us.net \
--cc=corbet@lwn.net \
--cc=jdelvare@suse.com \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=wilken.gottwalt@posteo.net \
/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