From: David Laight <david.laight.linux@gmail.com>
To: Neil Armstrong <neil.armstrong@linaro.org>
Cc: "Jonathan Cameron" <jic23@kernel.org>,
"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 3/3] iio: adc: add driver for the MAX34417 Four-Channel High Dynamic Range Power Accumulator
Date: Tue, 20 Oct 2026 10:13:12 +0100 [thread overview]
Message-ID: <20261020101312.47d2eaf0@pumpkin> (raw)
In-Reply-To: <20261013-topic-sm8x50-iio-max34417-adc-v3-3-d3604ae4a229@linaro.org>
On Tue, 13 Oct 2026 16:07:13 +0200
Neil Armstrong <neil.armstrong@linaro.org> wrote:
> The MAX34417 is a specialized current and voltage monitor used to
> determine power consumption of portable systems. The driver support
> getting the channels voltage, average power and accumulated average
> power and energy over an I2C/SMBUS serial interface.
>
> The MAX34417 datasheet only specified on how to calculate the
> accumulated average power, but with the Sample Per Second rate
> we can easily get accumulated Energy in mJ.
>
> By default the IIO driver only supports single-shot Voltage
> and Power sensing, but the accumulation can be enabled by
> enabling the Energy IIO channel which then enables the
> Continuous Accumulation Mode.
>
> The counter is common to all channels, so when reading a single
> channel we will copy all accumulators to registers, so in order
> to permit reading individual channels we must accumulate the
> other channels in the driver when Continuous Accumulation Mode
> is enabled.
>
> Signed-off-by: Neil Armstrong <neil.armstrong@linaro.org>
...
> +#define MAX34417_POWER_READ_LENGTH 8
> +#define MAX34417_POWER_READ_OFFSET 1
...
> +static int max34417_read_acc_power(struct max34417_data *max34417, unsigned int address,
> + u64 *acc_power)
> +{
> + u8 buf[MAX34417_POWER_READ_LENGTH];
> + int rc;
> +
> + rc = regmap_noinc_read(max34417->regmap, address, &buf, sizeof(buf));
> + if (rc)
> + return rc;
> +
> + /* Ignore byte0 */
> + *acc_power = get_unaligned_be56(&buf[MAX34417_POWER_READ_OFFSET]);
> +
> + return 0;
> +}
I was thinking:
struct { u64 pad:8; val:56 } buf;
then using bswap64(buf.val) >> 8 on LE.
But why not just:
u64 buf;
and be64toh(buf) & (BITULL(56) - 1)
David
next prev parent reply other threads:[~2026-10-20 9:13 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-13 14:07 [PATCH v3 0/3] iio: adc: add support for the MAX34417 Four-Channel High Dynamic Range Power Accumulator Neil Armstrong
2026-10-13 14:07 ` [PATCH v3 1/3] dt-bindings: iio: add: document " Neil Armstrong
2026-10-13 16:28 ` Conor Dooley
2026-10-14 7:34 ` Neil Armstrong
2026-10-13 14:07 ` [PATCH v3 2/3] unaligned: introduce be56 unaligned accessors Neil Armstrong
2026-10-13 14:18 ` Andy Shevchenko
2026-10-13 14:07 ` [PATCH v3 3/3] iio: adc: add driver for the MAX34417 Four-Channel High Dynamic Range Power Accumulator Neil Armstrong
2026-10-13 14:19 ` sashiko-bot
2026-10-13 14:23 ` Neil Armstrong
2026-10-13 14:53 ` Andy Shevchenko
2026-10-14 8:38 ` Neil Armstrong
2026-10-14 13:28 ` Andy Shevchenko
2026-10-17 22:47 ` Jonathan Cameron
2026-10-19 14:33 ` Neil Armstrong
2026-10-20 9:13 ` David Laight [this message]
2026-10-20 9:18 ` Neil Armstrong
2026-10-20 9:32 ` Andy Shevchenko
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=20261020101312.47d2eaf0@pumpkin \
--to=david.laight.linux@gmail.com \
--cc=andy@kernel.org \
--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=neil.armstrong@linaro.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox