Thread (16 messages) 16 messages, 3 authors, 2026-02-21

Re: [PATCH v5 0/3] hwmon: Add support for the LTC4283 Hot Swap Controller

From: Nuno Sá <hidden>
Date: 2026-02-02 09:39:38
Also in: linux-doc, linux-gpio, linux-hwmon

On Wed, 2026-01-28 at 10:22 -0800, Guenter Roeck wrote:
On Wed, Jan 28, 2026 at 06:07:24PM +0000, Nuno Sá wrote:
quoted
quoted
[ ... ]
quoted
+static int ltc4283_read_power_word(const struct ltc4283_hwmon *st,
+				   u32 reg, long *val)
+{
+	u64 temp = (u64)LTC4283_ADC1_FS_uV * LTC4283_ADC2_FS_mV * DECA * MILLI;
+	unsigned int __raw;
+	int ret;
+
+	ret = regmap_read(st->map_word, reg, &__raw);
+	if (ret)
+		return ret;
+
+	/*
+	 * Power is given by:
+	 *     P = CODE(16b) * 32.768mV * 2.048V / (2^16 * Rsense)
+	 */
+	*val = DIV64_U64_ROUND_CLOSEST(temp * __raw, BIT_ULL(16) * st->rsense);
Does this overflow *val on 32-bit systems if the calculated power exceeds
2000 Watts (approx 2^31 microWatts)?  The intermediate calculation is
u64, but the result is assigned to a signed long.
I'll have to double check this one but IIRC 2000W is not a realistic value for
these applications. One thing that could overflow is power_max given that the default
register value is 0xff but we do write the proper max value depending on
rsense (I actually need to check how will this behave in case we use a default
rsense value - ie with no DT property).
I have been wondering if I should introduce a hwmon_power64 sensor type, similar to
hwmon_energy64. WDYT ?
No strong opinion. As I said, not sure if it's needed here but OTOH given that power is
microWatts I guess it's a matter of time. Anyways, if you do it, I might as well just play safe
and use it in here (and ltc4282 should also be converted - likely).

- Nuno Sá
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help