From: Chris Packham <chris.packham@alliedtelesis.co.nz>
To: jdelvare@suse.com, linux@roeck-us.net, robh@kernel.org,
krzk+dt@kernel.org, conor+dt@kernel.org, corbet@lwn.net,
wenliang202407@163.com, jre@pengutronix.de
Cc: linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org,
Chris Packham <chris.packham@alliedtelesis.co.nz>
Subject: [PATCH v3 3/4] hwmon: (ina238) Add ina238_config fields
Date: Fri, 29 Aug 2025 15:05:11 +1200 [thread overview]
Message-ID: <20250829030512.1179998-4-chris.packham@alliedtelesis.co.nz> (raw)
In-Reply-To: <20250829030512.1179998-1-chris.packham@alliedtelesis.co.nz>
In preparation for adding INA780 support add some required fields to
ina238_config and set the appropriate values for the existing chips.
Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
---
Notes:
Changes in v3:
- New. Split config struct changes from main patch
drivers/hwmon/ina238.c | 22 +++++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)
diff --git a/drivers/hwmon/ina238.c b/drivers/hwmon/ina238.c
index 4d3dc018ead9..930e12e64079 100644
--- a/drivers/hwmon/ina238.c
+++ b/drivers/hwmon/ina238.c
@@ -120,13 +120,17 @@ enum ina238_ids { ina238, ina237, sq52206, ina228 };
struct ina238_config {
bool has_20bit_voltage_current; /* vshunt, vbus and current are 20-bit fields */
+ bool has_shunt; /* has shunt resistor */
bool has_power_highest; /* chip detection power peak */
bool has_energy; /* chip detection energy */
+ bool has_curr_min_max; /* supports COL/CUL */
u8 temp_shift; /* fixed parameters for temp calculate */
u32 power_calculate_factor; /* fixed parameters for power calculate */
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_max; /* maximum configurable temp limit in mC */
+ int fixed_power_lsb; /* fixed power LSB value */
};
struct ina238_data {
@@ -141,43 +145,59 @@ struct ina238_data {
static const struct ina238_config ina238_config[] = {
[ina238] = {
.has_20bit_voltage_current = false,
+ .has_shunt = true,
.has_energy = false,
.has_power_highest = false,
+ .has_curr_min_max = false,
.temp_shift = 4,
.power_calculate_factor = 20,
.config_default = INA238_CONFIG_DEFAULT,
.bus_voltage_lsb = INA238_BUS_VOLTAGE_LSB,
.temp_lsb = INA238_DIE_TEMP_LSB,
+ .temp_max = 125000,
+ .fixed_power_lsb = 0,
},
[ina237] = {
.has_20bit_voltage_current = false,
+ .has_shunt = true,
.has_energy = false,
.has_power_highest = false,
+ .has_curr_min_max = false,
.temp_shift = 4,
.power_calculate_factor = 20,
.config_default = INA238_CONFIG_DEFAULT,
.bus_voltage_lsb = INA238_BUS_VOLTAGE_LSB,
.temp_lsb = INA238_DIE_TEMP_LSB,
+ .temp_max = 125000,
+ .fixed_power_lsb = 0,
},
[sq52206] = {
.has_20bit_voltage_current = false,
+ .has_shunt = true,
.has_energy = true,
.has_power_highest = true,
+ .has_curr_min_max = false,
.temp_shift = 0,
.power_calculate_factor = 24,
.config_default = SQ52206_CONFIG_DEFAULT,
.bus_voltage_lsb = SQ52206_BUS_VOLTAGE_LSB,
.temp_lsb = SQ52206_DIE_TEMP_LSB,
+ .temp_max = 125000,
+ .fixed_power_lsb = 0,
},
[ina228] = {
.has_20bit_voltage_current = true,
+ .has_shunt = true,
.has_energy = true,
.has_power_highest = false,
+ .has_curr_min_max = false,
.temp_shift = 0,
.power_calculate_factor = 20,
.config_default = INA238_CONFIG_DEFAULT,
.bus_voltage_lsb = INA238_BUS_VOLTAGE_LSB,
.temp_lsb = INA228_DIE_TEMP_LSB,
+ .temp_max = 125000,
+ .fixed_power_lsb = 0,
},
};
@@ -572,7 +592,7 @@ static int ina238_write_temp(struct device *dev, u32 attr, long val)
return -EOPNOTSUPP;
/* Signed */
- val = clamp_val(val, -40000, 125000);
+ val = clamp_val(val, -40000, data->config->temp_max);
regval = div_s64(val * 10000, data->config->temp_lsb) << data->config->temp_shift;
regval = clamp_val(regval, S16_MIN, S16_MAX) & (0xffff << data->config->temp_shift);
--
2.51.0
next prev parent reply other threads:[~2025-08-29 3:05 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-29 3:05 [PATCH v3 0/4] hwmon: Add support for INA780 Chris Packham
2025-08-29 3:05 ` [PATCH v3 1/4] dt-bindings: hwmon: ti,ina2xx: Add INA780 device Chris Packham
2025-08-31 22:35 ` Guenter Roeck
2025-08-29 3:05 ` [PATCH v3 2/4] hwmon: (ina238) Correctly clamp temperature Chris Packham
2025-08-29 9:55 ` Guenter Roeck
2025-08-31 21:12 ` Chris Packham
2025-08-31 22:09 ` Guenter Roeck
2025-08-31 22:34 ` Guenter Roeck
2025-08-29 3:05 ` Chris Packham [this message]
2025-08-29 15:56 ` [PATCH v3 3/4] hwmon: (ina238) Add ina238_config fields Guenter Roeck
2025-08-29 3:05 ` [PATCH v3 4/4] hwmon: (ina238) Add support for INA780 Chris Packham
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=20250829030512.1179998-4-chris.packham@alliedtelesis.co.nz \
--to=chris.packham@alliedtelesis.co.nz \
--cc=conor+dt@kernel.org \
--cc=corbet@lwn.net \
--cc=devicetree@vger.kernel.org \
--cc=jdelvare@suse.com \
--cc=jre@pengutronix.de \
--cc=krzk+dt@kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=robh@kernel.org \
--cc=wenliang202407@163.com \
/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;
as well as URLs for NNTP newsgroup(s).