From: "Carsten Spieß" <mail@carsten-spiess.de>
To: Guenter Roeck <linux@roeck-us.net>,
Jean Delvare <jdelvare@suse.com>,
Jonathan Corbet <corbet@lwn.net>,
Geert Uytterhoeven <geert+renesas@glider.be>,
Magnus Damm <magnus.damm@gmail.com>
Cc: linux-hwmon@vger.kernel.org, linux-doc@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org
Subject: Re: [PATCH 1/2] hwmon: (isl28022) new driver for ISL28022 power monitor
Date: Thu, 27 Jul 2023 09:35:36 +0200 [thread overview]
Message-ID: <20230727093536.4cd2f84f.mail@carsten-spiess.de> (raw)
In-Reply-To: <206ad774-bf6f-aed3-81a7-3d9c8f80a69e@roeck-us.net>
[-- Attachment #1: Type: text/plain, Size: 4603 bytes --]
On 7/26/23 18:14, Gueter Roeck wrote:
> On 7/26/23 08:22, Carsten Spieß wrote:
> > +The shunt value in micro-ohms, shunt gain and averaging can be set
> > +via device tree at compile-time.
>
> At _compile-time_ ?
How to explain better that it isn't set at runtime?
Other drivers use the same term.
> I'd argue that shunt voltage is all but useless, but if you want to have it supported
> it _has_ to be in mV.
That's a problem.
In my case the ER-6P has a 8 milli Ohm (or 8000 micro Ohm) shunt and a powersupply with
max. 2.5 A. This gives a max shunt voltage of 20 mV at 2.5 A.
The device normaly consumes between 200 and 500 mA. (typ ~250 mA).
This results in shunt voltage of 1.6 to 4.0 mV (typ ~2mV).
Having no fractions will make it useless.
Unfortunately there is no possibility to give a scaling factor.
Or returning float values (i know, this can't and shouldn't be changed)
> Why not support limit attributes ?
Due to limited time, left for later enhancement.
> > +#define ISL28022_REG_SHUNT 0x01
> > +#define ISL28022_REG_BUS 0x02
> > + switch (type) {
> > + case hwmon_in:
> > + switch (attr) {
> > + case hwmon_in_input:
> > + err = regmap_read(data->regmap,
> > + ISL28022_REG_SHUNT + channel, ®val);
>
> That never reads REG_BUS.
Hmm,
channel 0: ISL28022_REG_SHUNT + 0 == 0x01
channel 1: ISL28022_REG_SHUNT + 1 == 0x02 == ISL28022_REG_BUS
or do i miss something?
> > + if (err < 0)
> > + return err;
> > + *val = (channel == 0) ?
> > + (long)((s16)((u16)regval)) * 10 :
> > + (long)(((u16)regval) & 0xFFFC);
>
> I don't think the sign extensions are correct based on the datasheet.
> This will have to use sign_extend.
From my understading (see table 11 on page 16 of the ISL28022 datasheet)
shunt value is already sign extended, (D15-D12 is sign)
bus value (table 12 on page 16) is unsigned.
> > + err = regmap_read(data->regmap,
> > + ISL28022_REG_CURRENT, ®val);
> > + if (err < 0)
> > + return err;
> > + if (!data->shunt)
> > + return -EINVAL;
>
> Getting an error message each time the "sensors" command is executed ?
> Unacceptable.
o.k., will change to set *val = 0;
> > + err = regmap_read(data->regmap,
> > + ISL28022_REG_POWER, ®val);
> > + if (err < 0)
> > + return err;
> > + if (!data->shunt)
> > + return -EINVAL;
>
> Unacceptable.
o.k., as above
> > + *val = ((long)regval * 409600000L * (long)data->gain) /
> > + (long)(8 * data->shunt);
>
> I don't think this was checked for overflows.
Yes, i must first divide then multiply.
I have to think about how to keep accuracy on high shunt resistor values.
> > +static int isl28022_config(struct device *dev)
> > +{
> > + struct isl28022_data *data = dev_get_drvdata(dev);
> > +
> > + if (!dev || !data)
> > + return -EINVAL;
>
> How would this ever happen ?
Shouldn't, but i'm carefully (i had it once during development due to an error
(using dev instead of hwmon_dev) on calling this function
> > + regmap_write(data->regmap, ISL28022_REG_CONFIG, data->config);
> > + regmap_write(data->regmap, ISL28022_REG_CALIB, data->calib);
>
> Error checking needed.
o.k. will add.
> > +static int isl28022_probe(struct i2c_client *client)
> > +{
> > + if (!i2c_check_functionality(client->adapter,
> > + I2C_FUNC_SMBUS_BYTE_DATA |
> > + I2C_FUNC_SMBUS_WORD_DATA))
> > + return -EIO;
>
> This is not an IO error. Return -ENODEV as most other drivers do.
o.k.
> > + of_property_read_u32(dev->of_node, "shunt-gain", &data->gain);
> > + of_property_read_u32(dev->of_node, "average", &data->average);
>
> Check for errors and provide defaults if properties are not set.
o.k.
> Also please use device_property_read_u32() to enable use from non-devicetree
> systems.
o.k. Never used this, have to look for an example on using it.
Many (old) drivers are using the of_property_* functions, is it intended to replace it.
What about backporting this driver to e.g. 5.15, will it affect it?
> > + status = isl28022_config(hwmon_dev);
> > + if (status)
> > + return status;
>
> That has to happen before the call to devm_hwmon_device_register_with_info()
> to avoid race conditions.
o.k.
> > +static struct i2c_driver isl28022_driver = {
> > + .class = I2C_CLASS_HWMON,
> > + .driver = {
> > + .name = "isl28022",
> > + .of_match_table = of_match_ptr(isl28022_of_match),
>
> Drop of_match_ptr()
Most drivers have this, why drop?
Regards, Carsten
[-- Attachment #2: Digitale Signatur von OpenPGP --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2023-07-27 7:44 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20230726152235.249569-1-mail@carsten-spiess.de>
2023-07-26 15:22 ` Carsten Spieß
2023-07-26 16:14 ` Guenter Roeck
2023-07-27 7:35 ` Carsten Spieß [this message]
2023-07-27 14:30 ` Guenter Roeck
2023-07-27 15:13 ` Carsten Spieß
2023-07-26 16:19 ` Guenter Roeck
2023-07-27 7:35 ` Carsten Spieß
2023-07-27 15:28 ` Carsten Spieß
2023-07-26 20:16 ` Randy Dunlap
2023-07-26 15:22 ` [PATCH 2/2] dt-bindings: hwmon: add renesas,isl28022 Carsten Spieß
2023-07-26 16:14 ` Krzysztof Kozlowski
2023-07-26 16:19 ` Krzysztof Kozlowski
2023-07-26 18:19 ` Guenter Roeck
2023-07-26 18:27 ` Krzysztof Kozlowski
2023-07-26 18:59 ` Guenter Roeck
2023-07-26 19:05 ` Krzysztof Kozlowski
2023-07-26 16:16 ` Guenter Roeck
2023-07-27 7:35 ` Carsten Spieß
2023-07-27 8:07 ` Conor Dooley
2023-07-27 8:25 ` Krzysztof Kozlowski
2023-07-27 9:30 ` Carsten Spieß
2023-07-27 13:55 ` Guenter Roeck
2023-07-26 17:13 ` Rob Herring
[not found] <20230727194813.2245116-1-mail@carsten-spiess.de>
2023-07-27 19:48 ` [PATCH 1/2] hwmon: (isl28022) new driver for ISL28022 power monitor Carsten Spieß
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=20230727093536.4cd2f84f.mail@carsten-spiess.de \
--to=mail@carsten-spiess.de \
--cc=corbet@lwn.net \
--cc=geert+renesas@glider.be \
--cc=jdelvare@suse.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=magnus.damm@gmail.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
all inboxes | Powered by JetHome®