[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20251118125148.95603-5-wenliang202407@163.com>
Date: Tue, 18 Nov 2025 07:51:44 -0500
From: Wenliang Yan <wenliang202407@....com>
To: linux@...ck-us.net,
Jean Delvare <jdelvare@...e.com>
Cc: Wenliang Yan <wenliang202407@....com>,
Rob Herring <robh@...nel.org>,
Krzysztof Kozlowski <krzk+dt@...nel.org>,
Conor Dooley <conor+dt@...nel.org>,
Jonathan Corbet <corbet@....net>,
linux-hwmon@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: [PATCH v2 4/8] hwmon: (ina3221) Support alert configuration
Add alert configuration during chip initialization.
Signed-off-by: Wenliang Yan <wenliang202407@....com>
---
drivers/hwmon/ina3221.c | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/drivers/hwmon/ina3221.c b/drivers/hwmon/ina3221.c
index b5fa984a5a25..8ea75f407055 100644
--- a/drivers/hwmon/ina3221.c
+++ b/drivers/hwmon/ina3221.c
@@ -65,6 +65,8 @@
#define INA3221_MASK_ENABLE_SCC_MASK GENMASK(14, 12)
+#define SQ52210_ALERT_CONFIG_MASK GENMASK(15, 4)
+
#define INA3221_CONFIG_DEFAULT 0x7127
#define INA3221_RSHUNT_DEFAULT 10000
#define SQ52210_SHUNT_LSB 40000000 /* pV/LSB */
@@ -123,6 +125,7 @@ struct ina3221_input {
enum ina3221_ids { ina3221, sq52210 };
struct ina3221_config {
+ bool has_alerts; /* chip supports alerts and limits */
bool has_current; /* chip has internal current reg */
bool has_power; /* chip has internal power reg */
int calibration_value; /* calculate current_lsb */
@@ -140,6 +143,7 @@ struct ina3221_config {
* @reg_config: Register value of INA3221_CONFIG
* @summation_shunt_resistor: equivalent shunt resistor value for summation
* @summation_channel_control: Value written to SCC field in INA3221_MASK_ENABLE
+ * @alert_type_select: Used to store the alert trigger type
* @current_lsb_uA: The value of one LSB corresponding to the current register
* @power_lsb_uW: The value of one LSB corresponding to the power register
* @single_shot: running in single-shot operating mode
@@ -155,6 +159,7 @@ struct ina3221_data {
u32 reg_config;
int summation_shunt_resistor;
u32 summation_channel_control;
+ u32 alert_type_select;
long current_lsb_uA;
long power_lsb_uW;
@@ -163,10 +168,12 @@ struct ina3221_data {
static const struct ina3221_config ina3221_config[] = {
[ina3221] = {
+ .has_alerts = false,
.has_current = false,
.has_power = false,
},
[sq52210] = {
+ .has_alerts = true,
.has_current = true,
.has_power = true,
/*
@@ -780,7 +787,6 @@ static ssize_t ina3221_shunt_store(struct device *dev,
/* Update summation_shunt_resistor for summation channel */
ina->summation_shunt_resistor = ina3221_summation_shunt_resistor(ina);
-
/*
* The current and power registers can only be used when
* all enabled channels have identical shunt resistors
@@ -1096,6 +1102,17 @@ static int ina3221_resume(struct device *dev)
}
}
+ /* Restore alert config register value to hardware */
+ if (ina->config->has_alerts) {
+ ret = regmap_update_bits(ina->regmap, SQ52210_ALERT_CONFIG,
+ SQ52210_ALERT_CONFIG_MASK,
+ ina->alert_type_select);
+ if (ret) {
+ dev_err(dev, "Unable to select alert type\n");
+ return ret;
+ }
+ }
+
return 0;
}
--
2.17.1
Powered by blists - more mailing lists