From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Ariana Lazar <ariana.lazar@microchip.com>
Cc: "Jonathan Cameron" <jic23@kernel.org>,
"Guenter Roeck" <linux@roeck-us.net>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org
Subject: Re: [PATCH v3 2/2] iio: adc: add support for PAC1711
Date: Wed, 9 Sep 2026 16:38:03 +0300 [thread overview]
Message-ID: <aqFhO3LCjsZkpNfg@ashevche-desk.local> (raw)
In-Reply-To: <20260909-pac1711-v3-2-dff81003b82f@microchip.com>
On Wed, Sep 09, 2026 at 03:23:35PM +0300, Ariana Lazar wrote:
> This is the iio driver for Microchip PAC1711, PAC1721, PAC1811 and
> PAC1821 single-channel power monitors with accumulator. The PAC1711 and
> PAC1721 devices use 12-bit resolution for voltage and current measurements
> and 24 bits for power calculations, while PAC1811 and PAC1821 have 16-bit
> resolution and use 32 bits for power calculations. The 56-bit accumulator
> register accumulates power (energy) or current (Coulomb counter).
>
> PAC1711 and PAC1811 measure up to 42V Full-Scale Range, respectively 9V for
> PAC1721 and PAC1821.
...
> +#include <linux/array_size.h>
> +#include <linux/bits.h>
> +#include <linux/bitfield.h>
> +#include <linux/byteorder/generic.h>
No, it should be asm/byteorder.h...
> +#include <linux/cleanup.h>
> +#include <linux/delay.h>
> +#include <linux/device.h>
> +#include <linux/err.h>
> +#include <linux/i2c.h>
> +#include <linux/kstrtox.h>
> +#include <linux/module.h>
> +#include <linux/mod_devicetable.h>
> +#include <linux/math64.h>
> +#include <linux/mutex.h>
> +#include <linux/overflow.h>
> +#include <linux/property.h>
> +#include <linux/types.h>
> +#include <linux/unaligned.h>
> +#include <linux/units.h>
> +#include <linux/workqueue.h>
...somewhere here.
> +#include <linux/iio/iio.h>
> +#include <linux/iio/sysfs.h>
...
> +#define PAC1711_MAX_RFSH_LIMIT_MS 60000
60 * MSEC_PER_SEC
> +/* 50msec is the timeout for validity of the cached registers */
> +#define PAC1711_MIN_POLLING_TIME_MS 50
> +/*
> + * 1000usec is the minimum wait time for normal conversions when sample
1 ms
> + * rate doesn't change
Missing period at the end.
> + */
> +#define PAC1711_MIN_UPDATE_WAIT_TIME_US 1000
1 * USEC_PER_MSEC
...
> +/* 42000mV */
42 * MILLI
> +#define PAC1711_VOLTAGE_MILLIVOLTS_MAX 42000
> +#define PAC1721_VOLTAGE_MILLIVOLTS_MAX 9000
9 * MILLI
...
> +/* Maximum power-product value - 42 V * 0.1 V */
> +#define PAC1711_PRODUCT_VOLTAGE_PV_FSR (4200ULL * NANO)
> +#define PAC1721_PRODUCT_VOLTAGE_PV_FSR (900ULL * NANO)
The comment and the values are not in sync. I'm confused, for example,
by how NANO appears at all there.
...
> +#define PAC1711_DEV_ATTR(name) (&iio_dev_attr_##name.dev_attr.attr)
Unneeded, please use the values directly, do not hide the rest.
...
> +static const int pac1711_vbus_range_tbl[2][3][2] = {
> + [PAC1711_VOLTAGE_RANGE_IDX] = {
> + [PAC1711_FULL_RANGE_UNIPOLAR] = { 0, 42000000 },
> + [PAC1711_FULL_RANGE_BIPOLAR] = { -42000000, 42000000 },
> + [PAC1711_HALF_RANGE_BIPOLAR] = { -21000000, 21000000 },
> + },
> + [PAC1721_VOLTAGE_RANGE_IDX] = {
> + [PAC1711_FULL_RANGE_UNIPOLAR] = { 0, 9000000 },
> + [PAC1711_FULL_RANGE_BIPOLAR] = { -9000000, 9000000 },
> + [PAC1711_HALF_RANGE_BIPOLAR] = { -4500000, 4500000 },
> + },
> +};
> +
> +static const int pac1711_vsense_range_tbl[3][2] = {
> + [PAC1711_FULL_RANGE_UNIPOLAR] = { 0, 100000 },
> + [PAC1711_FULL_RANGE_BIPOLAR] = { -100000, 100000 },
> + [PAC1711_HALF_RANGE_BIPOLAR] = { -50000, 50000 },
> +};
Perhaps above needs more definitions as I see the similarities with
the existing ones.
...
> +struct reg_data {
> + s64 vacc;
> + s64 acc_val;
> + s64 vpower;
> + s32 vsense;
> + s32 vbus;
> + u32 acc_count;
> + unsigned long jiffies_tstamp;
I would put variadic size variables at the bottom as they doesn't sound
like HW related.
> + u16 ctrl_act_reg;
> + u16 ctrl_lat_reg;
> + u8 meas_regs[PAC1711_MEAS_REG_SNAPSHOT_LEN];
> +};
...
> +static inline u64 pac1711_get_unaligned_be56(u8 *p)
const u8 *p
> +{
> + return (u64)p[0] << 48 | (u64)p[1] << 40 | (u64)p[2] << 32 |
> + (u64)p[3] << 24 | p[4] << 16 | p[5] << 8 | p[6];
> +}
Currently it seems this will be the first user (maybe some more are hiding somewhere)
of this. Nevertheless I would dare to put it directly into include/linux/unaligned.h.
This will eliminate possible duplication in the future.
...
For now I stopped here. Can you split this patch at least to two (introduce a
basic support for some part number(s) followed by the other part numbers to be
added and maybe some optional features?
...
> +static struct i2c_driver pac1711_driver = {
> + .driver = {
> + .name = "pac1711",
> + .of_match_table = pac1711_of_match,
> + },
> + .probe = pac1711_probe,
> + .id_table = pac1711_id,
> +};
> +
Unneeded blank line.
> +module_i2c_driver(pac1711_driver);
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2026-09-09 13:38 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-09 12:23 [PATCH v3 0/2] Add support for Microchip PAC1711 Power Monitor Ariana Lazar
2026-09-09 12:23 ` [PATCH v3 1/2] dt-bindings: iio: adc: add support for PAC1711 Ariana Lazar
2026-09-09 12:35 ` sashiko-bot
2026-09-10 11:55 ` Conor Dooley
2026-09-10 14:52 ` Ariana.Lazar
2026-09-12 10:17 ` Conor Dooley
2026-09-09 12:23 ` [PATCH v3 2/2] " Ariana Lazar
2026-09-09 12:35 ` sashiko-bot
2026-09-09 13:38 ` Andy Shevchenko [this message]
2026-09-09 14:22 ` Uwe Kleine-König
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=aqFhO3LCjsZkpNfg@ashevche-desk.local \
--to=andriy.shevchenko@intel.com \
--cc=andy@kernel.org \
--cc=ariana.lazar@microchip.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=nuno.sa@analog.com \
--cc=robh@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.