From nobody Tue Oct 7 02:01:56 2025 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6B5602C08A8 for ; Tue, 15 Jul 2025 20:49:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752612565; cv=none; b=Hfa/fBt5XUyfFk5krn5OD82dxzjjBsp8CRSpyDBlStas6NwMGKtJldXdKmBt6Xtnn4JbpuLBaC7H7S08WeI2pqUNgMn/COHF/SnMDONkqJTH6bzWjmvrQIJCjLlmif6fkZWO+xjmj/p4Z85Vf+D/9oTrM/HiUOeDAnT7O3IMsgg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752612565; c=relaxed/simple; bh=1HTJF7mGCNgEMHWLWzAwyOkhpvpJhNMskIEhjSYFLw8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=rhqFlUIbvkcorD4e+t4AOt642gsJBxXy9YqJXfuCu1DbhOTjs9nzfnlYQg2DYXC2Z+IbI/Ib87oLL4nPAIIIAJ3A5uC26UQm73Eyj1x5YTmHNAmIKyIa7cT/bkiQ5t+WyGk1KUNh6kPNqg8rtTj5VC3IwZk2Thi1Q82VhWvDSts= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from dude04.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::ac]) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1ubmaI-0008KV-Dj; Tue, 15 Jul 2025 22:49:06 +0200 From: Jonas Rebmann Date: Tue, 15 Jul 2025 22:49:00 +0200 Subject: [PATCH 1/4] hwmon: ina238: Fix inconsistent whitespace Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250715-ina228-v1-1-3302fae4434b@pengutronix.de> References: <20250715-ina228-v1-0-3302fae4434b@pengutronix.de> In-Reply-To: <20250715-ina228-v1-0-3302fae4434b@pengutronix.de> To: Jean Delvare , Guenter Roeck , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, Krzysztof Kozlowski , devicetree@vger.kernel.org, kernel@pengutronix.de, Jonas Rebmann X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=5373; i=jre@pengutronix.de; h=from:subject:message-id; bh=1HTJF7mGCNgEMHWLWzAwyOkhpvpJhNMskIEhjSYFLw8=; b=owGbwMvMwCF2ZcYT3onnbjcwnlZLYsgo27dfqFEnJSdDQ1s3QNNYkl/M3aODJ1lPwXnGsQ0/W TYt2b22o5SFQYyDQVZMkSVWTU5ByNj/ulmlXSzMHFYmkCEMXJwCMJFnrxj+l0z49fL8ybm/f3OW x0exP9NaqxrncIuPZ5LSz+SFk+IZLRj+WV47r7qtXeLnvckHLGZ3J36Ov+Ztk9bgvs3yzWeLmbX ZXAA= X-Developer-Key: i=jre@pengutronix.de; a=openpgp; fpr=0B7B750D5D3CD21B3B130DE8B61515E135CD49B5 X-SA-Exim-Connect-IP: 2a0a:edc0:0:1101:1d::ac X-SA-Exim-Mail-From: jre@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Some purely cosmetic changes in ina238.c: - When aligning definitions, do so consistently with tab stop of 8. - Use spaces instead of tabs around operators. - Align wrapped lines. Signed-off-by: Jonas Rebmann --- drivers/hwmon/ina238.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/drivers/hwmon/ina238.c b/drivers/hwmon/ina238.c index 9a5fd16a4ec2a6d5a6cd5e8070d0442e1ef0135a..d603d4990c928984350c1f41443= 1219b1489a546 100644 --- a/drivers/hwmon/ina238.c +++ b/drivers/hwmon/ina238.c @@ -41,7 +41,7 @@ =20 #define INA238_CONFIG_ADCRANGE BIT(4) #define SQ52206_CONFIG_ADCRANGE_HIGH BIT(4) -#define SQ52206_CONFIG_ADCRANGE_LOW BIT(3) +#define SQ52206_CONFIG_ADCRANGE_LOW BIT(3) =20 #define INA238_DIAG_ALERT_TMPOL BIT(7) #define INA238_DIAG_ALERT_SHNTOL BIT(6) @@ -104,7 +104,7 @@ =20 #define INA238_SHUNT_VOLTAGE_LSB 5 /* 5 uV/lsb */ #define INA238_BUS_VOLTAGE_LSB 3125 /* 3.125 mV/lsb */ -#define INA238_DIE_TEMP_LSB 1250000 /* 125.0000 mC/lsb */ +#define INA238_DIE_TEMP_LSB 1250000 /* 125.0000 mC/lsb */ #define SQ52206_BUS_VOLTAGE_LSB 3750 /* 3.75 mV/lsb */ #define SQ52206_DIE_TEMP_LSB 78125 /* 7.8125 mC/lsb */ =20 @@ -118,12 +118,12 @@ enum ina238_ids { ina238, ina237, sq52206 }; =20 struct ina238_config { bool has_power_highest; /* chip detection power peak */ - bool has_energy; /* chip detection energy */ - u8 temp_shift; /* fixed parameters for temp calculate */ + bool has_energy; /* chip detection energy */ + u8 temp_shift; /* fixed parameters for temp calculate */ u32 power_calculate_factor; /* fixed parameters for power calculate */ - u16 config_default; /* Power-on default state */ + u16 config_default; /* Power-on default state */ int bus_voltage_lsb; /* use for temperature calculate, uV/lsb */ - int temp_lsb; /* use for temperature calculate */ + int temp_lsb; /* use for temperature calculate */ }; =20 struct ina238_data { @@ -271,7 +271,7 @@ static int ina238_read_in(struct device *dev, u32 attr,= int channel, if (channel =3D=3D 0) /* gain of 1 -> LSB / 4 */ *val =3D (regval * INA238_SHUNT_VOLTAGE_LSB) * - data->gain / (1000 * 4); + data->gain / (1000 * 4); else *val =3D (regval * data->config->bus_voltage_lsb) / 1000; break; @@ -370,7 +370,7 @@ static int ina238_read_power(struct device *dev, u32 at= tr, long *val) return err; =20 /* Fixed 1mA lsb, scaled by 1000000 to have result in uW */ - power =3D div_u64(regval * 1000ULL * INA238_FIXED_SHUNT * data->gain * + power =3D div_u64(regval * 1000ULL * INA238_FIXED_SHUNT * data->gain * data->config->power_calculate_factor, 4 * 100 * data->rshunt); /* Clamp value to maximum value of long */ *val =3D clamp_val(power, 0, LONG_MAX); @@ -381,7 +381,7 @@ static int ina238_read_power(struct device *dev, u32 at= tr, long *val) return err; =20 /* Fixed 1mA lsb, scaled by 1000000 to have result in uW */ - power =3D div_u64(regval * 1000ULL * INA238_FIXED_SHUNT * data->gain * + power =3D div_u64(regval * 1000ULL * INA238_FIXED_SHUNT * data->gain * data->config->power_calculate_factor, 4 * 100 * data->rshunt); /* Clamp value to maximum value of long */ *val =3D clamp_val(power, 0, LONG_MAX); @@ -395,7 +395,7 @@ static int ina238_read_power(struct device *dev, u32 at= tr, long *val) * Truncated 24-bit compare register, lower 8-bits are * truncated. Same conversion to/from uW as POWER register. */ - power =3D div_u64((regval << 8) * 1000ULL * INA238_FIXED_SHUNT * data->g= ain * + power =3D div_u64((regval << 8) * 1000ULL * INA238_FIXED_SHUNT * data->g= ain * data->config->power_calculate_factor, 4 * 100 * data->rshunt); /* Clamp value to maximum value of long */ *val =3D clamp_val(power, 0, LONG_MAX); @@ -448,7 +448,7 @@ static int ina238_read_temp(struct device *dev, u32 att= r, long *val) return err; /* Signed, result in mC */ *val =3D div_s64(((s64)((s16)regval) >> data->config->temp_shift) * - (s64)data->config->temp_lsb, 10000); + (s64)data->config->temp_lsb, 10000); break; case hwmon_temp_max: err =3D regmap_read(data->regmap, INA238_TEMP_LIMIT, ®val); @@ -456,7 +456,7 @@ static int ina238_read_temp(struct device *dev, u32 att= r, long *val) return err; /* Signed, result in mC */ *val =3D div_s64(((s64)((s16)regval) >> data->config->temp_shift) * - (s64)data->config->temp_lsb, 10000); + (s64)data->config->temp_lsb, 10000); break; case hwmon_temp_max_alarm: err =3D regmap_read(data->regmap, INA238_DIAG_ALERT, ®val); @@ -501,8 +501,8 @@ static ssize_t energy1_input_show(struct device *dev, return ret; =20 /* result in uJ */ - energy =3D div_u64(regval * INA238_FIXED_SHUNT * data->gain * 16 * 10 * - data->config->power_calculate_factor, 4 * data->rshunt); + energy =3D div_u64(regval * INA238_FIXED_SHUNT * data->gain * 16 * 10 * + data->config->power_calculate_factor, 4 * data->rshunt); =20 return sysfs_emit(buf, "%llu\n", energy); } @@ -776,7 +776,7 @@ MODULE_DEVICE_TABLE(of, ina238_of_match); =20 static struct i2c_driver ina238_driver =3D { .driver =3D { - .name =3D "ina238", + .name =3D "ina238", .of_match_table =3D of_match_ptr(ina238_of_match), }, .probe =3D ina238_probe, --=20 2.39.5 From nobody Tue Oct 7 02:01:56 2025 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E75B52C08A0 for ; Tue, 15 Jul 2025 20:49:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752612564; cv=none; b=Z7yyVhIzJ6jbaz5qUj7QN2LHJzrJiratpuf2P5nauq6zoN2okndJVjFJv95stiextq7C7LlHPkwdJJv+e59vFex8/LatS9r0N1vqK8TbxcUuBU6oWlHJkxSt2enP27t246nwD1ZxllLvqVW3wsrmVWRLB6uFjMwsUvGv9C8eTNo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752612564; c=relaxed/simple; bh=WssqkErbhL2T08N7gZu0oUt7u3JLlXLIOeaUBCh7otc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=PEXpSPbWQSfWx0lkdZpjMHra8dbKMhAvgXv64WPs32XJR2jVqgThQJAAbNy4FUSR7h81Tjur6i6Ql8Vop3eGKwIPTjPMUWUXWMIzS19lMfGGRyw5bue7j29SXveaEq5dZwmTAlyec0r0gFV4Vzd5gkDrTLqb6S03zSib51ZsKCU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from dude04.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::ac]) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1ubmaI-0008KV-HY; Tue, 15 Jul 2025 22:49:06 +0200 From: Jonas Rebmann Date: Tue, 15 Jul 2025 22:49:01 +0200 Subject: [PATCH 2/4] hwmon: ina238: Add label support for voltage inputs Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250715-ina228-v1-2-3302fae4434b@pengutronix.de> References: <20250715-ina228-v1-0-3302fae4434b@pengutronix.de> In-Reply-To: <20250715-ina228-v1-0-3302fae4434b@pengutronix.de> To: Jean Delvare , Guenter Roeck , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, Krzysztof Kozlowski , devicetree@vger.kernel.org, kernel@pengutronix.de, Jonas Rebmann X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2255; i=jre@pengutronix.de; h=from:subject:message-id; bh=WssqkErbhL2T08N7gZu0oUt7u3JLlXLIOeaUBCh7otc=; b=owGbwMvMwCF2ZcYT3onnbjcwnlZLYsgo23dgucWZjQ+ko5P4k31fMHbNMsxZnH6o1fn1GeO1J 1OV+wuVOkpZGMQ4GGTFFFli1eQUhIz9r5tV2sXCzGFlAhnCwMUpABNRLWZk+HRi4pdelsQ/n1je KHyNCnYvmrjnXeKd55ZiwXO2vm0MW8fIsG9KTIDLieNL4rbuOvQgQKhs0fEj2wTEzub5ZTifmrf hHBcA X-Developer-Key: i=jre@pengutronix.de; a=openpgp; fpr=0B7B750D5D3CD21B3B130DE8B61515E135CD49B5 X-SA-Exim-Connect-IP: 2a0a:edc0:0:1101:1d::ac X-SA-Exim-Mail-From: jre@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org The INA family of power monitors estimate power consumption based on two voltage measurements: across a shunt resistor and across the bus. Conveniently label them "Shunt Voltage" and "Bus Voltage". Signed-off-by: Jonas Rebmann --- drivers/hwmon/ina238.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/drivers/hwmon/ina238.c b/drivers/hwmon/ina238.c index d603d4990c928984350c1f414431219b1489a546..44f7ce3c1d7b5a91f67d12c1d29= e1e560024a04c 100644 --- a/drivers/hwmon/ina238.c +++ b/drivers/hwmon/ina238.c @@ -507,6 +507,27 @@ static ssize_t energy1_input_show(struct device *dev, return sysfs_emit(buf, "%llu\n", energy); } =20 +static int ina238_read_string(struct device *dev, enum hwmon_sensor_types = type, + u32 attr, int channel, const char **str) +{ + switch (type) { + case hwmon_in: + switch (channel) { + case 0: + *str =3D "Shunt Voltage"; + return 0; + case 1: + *str =3D "Bus Voltage"; + return 0; + default: + break; + } + default: + break; + } + return -EOPNOTSUPP; +} + static int ina238_read(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel, long *val) { @@ -565,6 +586,7 @@ static umode_t ina238_is_visible(const void *drvdata, case hwmon_in_input: case hwmon_in_max_alarm: case hwmon_in_min_alarm: + case hwmon_in_label: return 0444; case hwmon_in_max: case hwmon_in_min: @@ -615,9 +637,9 @@ static umode_t ina238_is_visible(const void *drvdata, static const struct hwmon_channel_info * const ina238_info[] =3D { HWMON_CHANNEL_INFO(in, /* 0: shunt voltage */ - INA238_HWMON_IN_CONFIG, + INA238_HWMON_IN_CONFIG | HWMON_I_LABEL, /* 1: bus voltage */ - INA238_HWMON_IN_CONFIG), + INA238_HWMON_IN_CONFIG | HWMON_I_LABEL), HWMON_CHANNEL_INFO(curr, /* 0: current through shunt */ HWMON_C_INPUT), @@ -633,6 +655,7 @@ static const struct hwmon_channel_info * const ina238_i= nfo[] =3D { =20 static const struct hwmon_ops ina238_hwmon_ops =3D { .is_visible =3D ina238_is_visible, + .read_string =3D ina238_read_string, .read =3D ina238_read, .write =3D ina238_write, }; --=20 2.39.5 From nobody Tue Oct 7 02:01:56 2025 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6024D2C08A2 for ; Tue, 15 Jul 2025 20:49:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752612565; cv=none; b=WiEXzQ1Wi+yKw9bTH/9XWZK4tuz1Ve+YkdCyMgAd0EjyiUPU4FnHczbwEcUITpuiTA268X4A/ADwisYgRld194qU3H1qjYT7OuvgVR39dbBZmqvmVrGmhYEpyTN4w34xelsO72M/Z8mrgbxECzSWm5WIrYBRoGmTvLJQilXK+98= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752612565; c=relaxed/simple; bh=szwuk6Vvp2AoqhAb91mYotzkuCuPX6KC/lPfB1lCQgU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=tn52QZN6wQFqXieTL+aeLNfTo7uFJTCe5yqZcosgdoGkSq0etW0Ba1iEh2g71oKFNHV44H4FVZzABMykczzx/LxluH07N1Fg4Oan+YAYQqErlZ6c3mk4ZmJLfdmyC866fi5IQb3dqtOSD2pA0YYOd1oE8KZpeYITmutZqIXOfNQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from dude04.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::ac]) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1ubmaI-0008KV-JA; Tue, 15 Jul 2025 22:49:06 +0200 From: Jonas Rebmann Date: Tue, 15 Jul 2025 22:49:02 +0200 Subject: [PATCH 3/4] dt-bindings: Add INA228 to ina2xx devicetree bindings Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250715-ina228-v1-3-3302fae4434b@pengutronix.de> References: <20250715-ina228-v1-0-3302fae4434b@pengutronix.de> In-Reply-To: <20250715-ina228-v1-0-3302fae4434b@pengutronix.de> To: Jean Delvare , Guenter Roeck , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, Krzysztof Kozlowski , devicetree@vger.kernel.org, kernel@pengutronix.de, Jonas Rebmann X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=951; i=jre@pengutronix.de; h=from:subject:message-id; bh=szwuk6Vvp2AoqhAb91mYotzkuCuPX6KC/lPfB1lCQgU=; b=owGbwMvMwCF2ZcYT3onnbjcwnlZLYsgo23dgzuHFSZuZ+gytKgrf6q54fdT36qdHbpK3fgYz5 HNP5V3Y2VHKwiDGwSArpsgSqyanIGTsf92s0i4WZg4rE8gQBi5OAZjI5euMDK3hXO3zJJ5dub5S ptC0c/O3aQ9f9pT6uPFw7oyvrJ+pl8jIcGJ+PHtCQtf3thbjFtaM3K3L7unEd4vfrtv0sPbpy1u 1nAA= X-Developer-Key: i=jre@pengutronix.de; a=openpgp; fpr=0B7B750D5D3CD21B3B130DE8B61515E135CD49B5 X-SA-Exim-Connect-IP: 2a0a:edc0:0:1101:1d::ac X-SA-Exim-Mail-From: jre@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Add the ina228 to ina2xx bindings. Signed-off-by: Jonas Rebmann Reviewed-by: Krzysztof Kozlowski --- Documentation/devicetree/bindings/hwmon/ti,ina2xx.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Documentation/devicetree/bindings/hwmon/ti,ina2xx.yaml b/Docum= entation/devicetree/bindings/hwmon/ti,ina2xx.yaml index d1fb7b9abda081113ac28ed999d9c28da9d4daf9..fa68b99ef2e292c0b7d618c1481= 9fa2bd64db7b8 100644 --- a/Documentation/devicetree/bindings/hwmon/ti,ina2xx.yaml +++ b/Documentation/devicetree/bindings/hwmon/ti,ina2xx.yaml @@ -25,6 +25,7 @@ properties: - ti,ina219 - ti,ina220 - ti,ina226 + - ti,ina228 - ti,ina230 - ti,ina231 - ti,ina233 @@ -107,6 +108,7 @@ allOf: - ti,ina219 - ti,ina220 - ti,ina226 + - ti,ina228 - ti,ina230 - ti,ina231 - ti,ina237 --=20 2.39.5 From nobody Tue Oct 7 02:01:56 2025 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 422472C08CC for ; Tue, 15 Jul 2025 20:49:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752612566; cv=none; b=mIjh1eYtAHDNroEMCv3/FVEmtEw+jrQxVb4JnBPT4HLfdbgpvhcBOX2NQGUzF2bEs+XxGNGgGf1gyq6nTOvw5cAAfLSN20miTKDzMinLsHE3I0qJpTJLiJH1QAjT7GHEktDV9FLJ9WZ3LcwP9rYGvob2731e1JtSiLWLPRLCHGE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752612566; c=relaxed/simple; bh=qeSiSEChF8vkI7U3jprp57CemwGFZH0pwj0CrxbU60w=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=eBPRTitd85/2T2KIo/hBtvmSf+NJ7ky8nEUQuZ3mbk3nlGQwI2L8Y7aHk6cYms15EXZXoD+Dk4eVXG98NY8nNGHo/tIA5qRVwhxxZnst3BNh2EFkEMzpkiXYDud0pz1Zo9GOqkqcElV0hMbLSrUnsAdM18KIfBC8iOt9B/OYUV4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from dude04.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::ac]) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1ubmaI-0008KV-KY; Tue, 15 Jul 2025 22:49:06 +0200 From: Jonas Rebmann Date: Tue, 15 Jul 2025 22:49:03 +0200 Subject: [PATCH 4/4] hwmon: ina238: Add support for INA228 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250715-ina228-v1-4-3302fae4434b@pengutronix.de> References: <20250715-ina228-v1-0-3302fae4434b@pengutronix.de> In-Reply-To: <20250715-ina228-v1-0-3302fae4434b@pengutronix.de> To: Jean Delvare , Guenter Roeck , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, Krzysztof Kozlowski , devicetree@vger.kernel.org, kernel@pengutronix.de, Jonas Rebmann X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=7020; i=jre@pengutronix.de; h=from:subject:message-id; bh=qeSiSEChF8vkI7U3jprp57CemwGFZH0pwj0CrxbU60w=; b=owGbwMvMwCF2ZcYT3onnbjcwnlZLYsgo23fwhFXjrqaVHNlptausf8kwHyy9VKmbk3o007v30 uyV32vXd5SyMIhxMMiKKbLEqskpCBn7XzertIuFmcPKBDKEgYtTACaibszIMMnsXqbGzBjvhEvH J+/ImFIerSCWelzKs7/WrGXTFBfxfkaGK+k64j8MNs0UWXmyP0X1bnb82dOu7n0/t+y+9qir+xg TEwA= X-Developer-Key: i=jre@pengutronix.de; a=openpgp; fpr=0B7B750D5D3CD21B3B130DE8B61515E135CD49B5 X-SA-Exim-Connect-IP: 2a0a:edc0:0:1101:1d::ac X-SA-Exim-Mail-From: jre@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Add support for the Texas Instruments INA228 Ultra-Precise Power/Energy/Charge Monitor. The INA228 is very similar to the INA238 but offers four bits of extra precision in the temperature, voltage and current measurement fields. It also supports energy and charge monitoring, the latter of which is not supported through this patch. While it seems in the datasheet that some constants such as LSB values differ between the 228 and the 238, they differ only for those registers where four bits of precision have been added and they differ by a factor of 16 (VBUS, VSHUNT, DIETEMP, CURRENT). Therefore, the INA238 constants are still applicable with regard to the bit of the same significance. Signed-off-by: Jonas Rebmann --- drivers/hwmon/ina238.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++= +--- 1 file changed, 93 insertions(+), 5 deletions(-) diff --git a/drivers/hwmon/ina238.c b/drivers/hwmon/ina238.c index 44f7ce3c1d7b5a91f67d12c1d29e1e560024a04c..f8c74317344a5bbdf933a32b8c7= e5aba13beda30 100644 --- a/drivers/hwmon/ina238.c +++ b/drivers/hwmon/ina238.c @@ -107,6 +107,7 @@ #define INA238_DIE_TEMP_LSB 1250000 /* 125.0000 mC/lsb */ #define SQ52206_BUS_VOLTAGE_LSB 3750 /* 3.75 mV/lsb */ #define SQ52206_DIE_TEMP_LSB 78125 /* 7.8125 mC/lsb */ +#define INA228_DIE_TEMP_LSB 78125 /* 7.8125 mC/lsb */ =20 static const struct regmap_config ina238_regmap_config =3D { .max_register =3D INA238_REGISTERS, @@ -114,9 +115,10 @@ static const struct regmap_config ina238_regmap_config= =3D { .val_bits =3D 16, }; =20 -enum ina238_ids { ina238, ina237, sq52206 }; +enum ina238_ids { ina238, ina237, sq52206, ina228 }; =20 struct ina238_config { + bool has_20bit_voltage_current; /* vshunt, vbus and current are 20-bit fi= elds */ bool has_power_highest; /* chip detection power peak */ bool has_energy; /* chip detection energy */ u8 temp_shift; /* fixed parameters for temp calculate */ @@ -137,6 +139,7 @@ struct ina238_data { =20 static const struct ina238_config ina238_config[] =3D { [ina238] =3D { + .has_20bit_voltage_current =3D false, .has_energy =3D false, .has_power_highest =3D false, .temp_shift =3D 4, @@ -146,6 +149,7 @@ static const struct ina238_config ina238_config[] =3D { .temp_lsb =3D INA238_DIE_TEMP_LSB, }, [ina237] =3D { + .has_20bit_voltage_current =3D false, .has_energy =3D false, .has_power_highest =3D false, .temp_shift =3D 4, @@ -155,6 +159,7 @@ static const struct ina238_config ina238_config[] =3D { .temp_lsb =3D INA238_DIE_TEMP_LSB, }, [sq52206] =3D { + .has_20bit_voltage_current =3D false, .has_energy =3D true, .has_power_highest =3D true, .temp_shift =3D 0, @@ -163,6 +168,16 @@ static const struct ina238_config ina238_config[] =3D { .bus_voltage_lsb =3D SQ52206_BUS_VOLTAGE_LSB, .temp_lsb =3D SQ52206_DIE_TEMP_LSB, }, + [ina228] =3D { + .has_20bit_voltage_current =3D true, + .has_energy =3D true, + .has_power_highest =3D false, + .temp_shift =3D 0, + .power_calculate_factor =3D 20, + .config_default =3D INA238_CONFIG_DEFAULT, + .bus_voltage_lsb =3D INA238_BUS_VOLTAGE_LSB, + .temp_lsb =3D INA228_DIE_TEMP_LSB, + }, }; =20 static int ina238_read_reg24(const struct i2c_client *client, u8 reg, u32 = *val) @@ -199,6 +214,56 @@ static int ina238_read_reg40(const struct i2c_client *= client, u8 reg, u64 *val) return 0; } =20 +static int ina228_read_shunt_voltage(struct device *dev, u32 attr, int cha= nnel, + long *val) +{ + struct ina238_data *data =3D dev_get_drvdata(dev); + int regval; + int field; + int err; + + err =3D ina238_read_reg24(data->client, INA238_SHUNT_VOLTAGE, ®val); + if (err) + return err; + + /* bits 3-0 Reserved, always zero */ + field =3D regval >> 4; + + /* + * gain of 1 -> LSB / 4 + * This field has 16 bit on ina238. ina228 adds another 4 bits of + * precision. ina238 conversion factors can still be applied when + * dividing by 16. + */ + *val =3D (field * INA238_SHUNT_VOLTAGE_LSB) * data->gain / (1000 * 4) / 1= 6; + return 0; +} + +static int ina228_read_bus_voltage(struct device *dev, u32 attr, int chann= el, + long *val) +{ + struct ina238_data *data =3D dev_get_drvdata(dev); + int regval; + int field; + int err; + + err =3D ina238_read_reg24(data->client, INA238_BUS_VOLTAGE, ®val); + if (err) + return err; + + /* bits 3-0 Reserved, always zero */ + field =3D regval >> 4; + + /* + * gain of 1 -> LSB / 4 + * This field has 16 bit on ina238. ina228 adds another 4 bits of + * precision. ina238 conversion factors can still be applied when + * dividing by 16. + */ + *val =3D (field * data->config->bus_voltage_lsb) / 1000 / 16; + return 0; +} + static int ina238_read_in(struct device *dev, u32 attr, int channel, long *val) { @@ -211,6 +276,8 @@ static int ina238_read_in(struct device *dev, u32 attr,= int channel, case 0: switch (attr) { case hwmon_in_input: + if (data->config->has_20bit_voltage_current) + return ina228_read_shunt_voltage(dev, attr, channel, val); reg =3D INA238_SHUNT_VOLTAGE; break; case hwmon_in_max: @@ -234,6 +301,8 @@ static int ina238_read_in(struct device *dev, u32 attr,= int channel, case 1: switch (attr) { case hwmon_in_input: + if (data->config->has_20bit_voltage_current) + return ina228_read_bus_voltage(dev, attr, channel, val); reg =3D INA238_BUS_VOLTAGE; break; case hwmon_in_max: @@ -341,13 +410,27 @@ static int ina238_read_current(struct device *dev, u3= 2 attr, long *val) =20 switch (attr) { case hwmon_curr_input: - err =3D regmap_read(data->regmap, INA238_CURRENT, ®val); - if (err < 0) - return err; + if (data->config->has_20bit_voltage_current) { + err =3D ina238_read_reg24(data->client, INA238_CURRENT, ®val); + if (err) + return err; + /* 4 Lowest 4 bits reserved zero */ + regval >>=3D 4; + } else { + err =3D regmap_read(data->regmap, INA238_CURRENT, ®val); + if (err < 0) + return err; + /* sign-extend */ + regval =3D (s16)regval; + } =20 /* Signed register, fixed 1mA current lsb. result in mA */ - *val =3D div_s64((s16)regval * INA238_FIXED_SHUNT * data->gain, + *val =3D div_s64(regval * INA238_FIXED_SHUNT * data->gain, data->rshunt * 4); + + /* Account for 4 bit offset */ + if (data->config->has_20bit_voltage_current) + *val /=3D 16; break; default: return -EOPNOTSUPP; @@ -773,6 +856,7 @@ static int ina238_probe(struct i2c_client *client) } =20 static const struct i2c_device_id ina238_id[] =3D { + { "ina228", ina228 }, { "ina237", ina237 }, { "ina238", ina238 }, { "sq52206", sq52206 }, @@ -781,6 +865,10 @@ static const struct i2c_device_id ina238_id[] =3D { MODULE_DEVICE_TABLE(i2c, ina238_id); =20 static const struct of_device_id __maybe_unused ina238_of_match[] =3D { + { + .compatible =3D "ti,ina228", + .data =3D (void *)ina228 + }, { .compatible =3D "ti,ina237", .data =3D (void *)ina237 --=20 2.39.5