Re: [PATCH v3 3/3] iio: adc: add driver for the MAX34417 Four-Channel High Dynamic Range Power Accumulator
From: Neil Armstrong
Date: Tue Oct 20 2026 - 05:20:05 EST
On 10/20/26 11:13, David Laight wrote:
On Tue, 13 Oct 2026 16:07:13 +0200
Neil Armstrong <neil.armstrong@xxxxxxxxxx> 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@xxxxxxxxxx>
+#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)
Right, I mean all this could work but I would like to keep using something
simpler and get_unaligned_be56 matches all this.
I don't think the need for performance is enough to use complex ways to get
the value.
Thanks,
Neil
David