From nobody Mon Feb 9 07:26:19 2026 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.2]) (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 2DF2C37E2E8; Wed, 14 Jan 2026 08:18:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.2 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768378723; cv=none; b=YeTceuif+r77ny2qMlo9uKoIhnVZnFiKm1bjs4R0zS4totV3l4Fva/kFgMRkQ89wCpWBZOJpifI0NrFYmM+Rrp46aeIVRutvGl4S/xzh47ba6IqysGfh6jeX5qPwoVU2dVM7tN9NMDj6+OJUffCRXJJ45QiZq5SfMW2B1RxQuQU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768378723; c=relaxed/simple; bh=WjsTHLjgxsy+mXRsoUwpiqJQYbq1MnNhmtWxtQbbl8g=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=atzFWqmjBMPlCRWSLcSXnIHJAxNZsol4P1wveMysJ3t87am6AhjOHZFuLCCyF2y+fWVIIiHLfPekmVXVIXdgG6tIgeGRbz06qs2zYwlWSVYZvEC/TjihEs3Ztg5UowCeP/omLPra8Sy3eUzudEpXw4Wx7rFOJWIa6VKo5LxlZQQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=fE05gDTs; arc=none smtp.client-ip=220.197.31.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="fE05gDTs" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-Id; bh=MHv2qgvbLAFuri5 w6URQ/pAxxfhBNmmanOC7CAD1enM=; b=fE05gDTsCE0IdTqSsN5vzGJqPKc3WaJ xNt21XoRVuXEPv+K5qnHpA+3kNvSof/MkEQh76A46vRzd35DKULxu/pYdmWMz1Wp uei0MQF9eEytTClMWYnbqaZWxPsX76OvYLWnkWx/Xp3I4ljcBWyhvq8EW16zo4UX nFVzyCALwSIs= Received: from localhost.localdomain (unknown []) by gzga-smtp-mtada-g1-2 (Coremail) with SMTP id _____wB3LaYsUWdpIIuhFg--.292S3; Wed, 14 Jan 2026 16:17:52 +0800 (CST) From: Wenliang Yan To: linux@roeck-us.net, Jean Delvare , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: Wenliang Yan , Jonathan Corbet , linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 RESEND 1/8] dt-bindings: hwmon: ti,ina3221: Add SQ52210 Date: Wed, 14 Jan 2026 03:17:34 -0500 Message-Id: <20260114081741.111340-2-wenliang202407@163.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20260114081741.111340-1-wenliang202407@163.com> References: <20260114081741.111340-1-wenliang202407@163.com> X-CM-TRANSID: _____wB3LaYsUWdpIIuhFg--.292S3 X-Coremail-Antispam: 1Uf129KBjvJXoW7Cw4UGFWkZr13Zw43Wr17ZFb_yoW8Xr43pF s3CFyUWrySqr1fZ39rKFsY9F15Jwn7ua12kFnrGw4SqF4DGa4Fq393Kw1qyFn8ArWfXFW7 WFWI9r4Fg397Ar7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0JUqjgxUUUUU= X-CM-SenderInfo: xzhqzxhdqjjiisuqlqqrwthudrp/xtbC6BGUaGlnUTHG4QAA3M Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add a compatible string for SQ52210, provide brief descriptions for both INA3221 and SQ52210, and define the compatibility relationship between SQ52210 and INA3221. SQ52210 is backward compatible with INA3221. Reviewed-by: Krzysztof Kozlowski Signed-off-by: Wenliang Yan --- .../devicetree/bindings/hwmon/ti,ina3221.yaml | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/hwmon/ti,ina3221.yaml b/Docu= mentation/devicetree/bindings/hwmon/ti,ina3221.yaml index 5f10f1207d69..2dd2fd148792 100644 --- a/Documentation/devicetree/bindings/hwmon/ti,ina3221.yaml +++ b/Documentation/devicetree/bindings/hwmon/ti,ina3221.yaml @@ -10,9 +10,22 @@ maintainers: - Jean Delvare - Guenter Roeck =20 +description: | + The INA3221 is a three-channel, high-side current and bus voltage monito= r. + + The Silergy SQ52210 is a power monitor that extends the functionality of + the INA3221 by adding additional current registers, power registers, and + alert registers. These features are configured internally by the driver + and require no board-level device tree configuration. + properties: compatible: - const: ti,ina3221 + oneOf: + - items: + - const: silergy,sq52210 + - const: ti,ina3221 + - items: + - const: ti,ina3221 =20 reg: maxItems: 1 --=20 2.17.1 From nobody Mon Feb 9 07:26:19 2026 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.4]) (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 43C4037E2F2; Wed, 14 Jan 2026 08:18:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768378725; cv=none; b=tga8Hu0kKf/DxACXIJRZcHL6K8/VCGoSiDhyVnIJk6NFl+qjnHN6zZZOky/EPyLwK9vGIZnuO8A17GCtLmi93f1xFYPzfHZAz1CmlUlwcyd3OS83L0JA1eWWOV7/HYD9LyYKQOj3Sr5Lo4IXAVa4i+Aua28ZQFt9jolLta0mZ7M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768378725; c=relaxed/simple; bh=H/w+6on8fYV8qpYT0kb7Mj2iA2mlwXEn1PrOId/TyGo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=M1Un6FcPty2HC4yept/H0XDoTBBP4GJtOTCT13pkdbsw48g+OFO+4MKWDQeYqqAIeoescAn+t+TUQRyT2KyShkfcx//+g8mq5biG7+QQJbx8JaS2tODMYB30BzSzGAW1tLA6c2p2IOby4o/Yf/MqA1XyxeT4O7HlQ6CJzqz1JJk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=KWs8YOp2; arc=none smtp.client-ip=220.197.31.4 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="KWs8YOp2" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-Id; bh=oQP23GsQvFrcqDF p4tVk7ny6xZlM2KY/EMMUq56/WtE=; b=KWs8YOp2cNK0dNfIkM3Ri8kt5IwqjD6 zSr/z3Saqur+5M2Htya4SNnEL857xAAqBKSHWR1MVLaCSRi8ouGsNvBBp/PssBAE 2uLR3wz3nJ1UAMn1KXW3p1NqTo1PPhK4IrMqKXA2SXU0Nd7wrvXreno2skcd1CE9 59iy8NPq/98o= Received: from localhost.localdomain (unknown []) by gzga-smtp-mtada-g1-2 (Coremail) with SMTP id _____wB3LaYsUWdpIIuhFg--.292S4; Wed, 14 Jan 2026 16:17:53 +0800 (CST) From: Wenliang Yan To: linux@roeck-us.net, Jean Delvare Cc: Wenliang Yan , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jonathan Corbet , linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 RESEND 2/8] hwmon: (ina3221) Add support for SQ52210 Date: Wed, 14 Jan 2026 03:17:35 -0500 Message-Id: <20260114081741.111340-3-wenliang202407@163.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20260114081741.111340-1-wenliang202407@163.com> References: <20260114081741.111340-1-wenliang202407@163.com> X-CM-TRANSID: _____wB3LaYsUWdpIIuhFg--.292S4 X-Coremail-Antispam: 1Uf129KBjvJXoWxXFW8Xr1UJFWDXrW3AF1kXwb_yoW5ur1fpa 1rAa4rtr45Xr4Ig3yfKFs5tF15tr4xW3yIvrnrK3yIvF4DAry0gF1rGw4vyF98ZFyfZFsr X34Iy3y8uwnrJr7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0pi_Ma5UUUUU= X-CM-SenderInfo: xzhqzxhdqjjiisuqlqqrwthudrp/xtbC5xKUaGlnUTLO+AAA3S Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add Compatible for SQ52210. Compared to the INA3221, the SQ52210 also has current registers, power registers, and limit-related registers. Signed-off-by: Wenliang Yan --- drivers/hwmon/ina3221.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/drivers/hwmon/ina3221.c b/drivers/hwmon/ina3221.c index 5ecc68dcf169..47ef4fe694ea 100644 --- a/drivers/hwmon/ina3221.c +++ b/drivers/hwmon/ina3221.c @@ -34,6 +34,17 @@ #define INA3221_SHUNT_SUM 0x0d #define INA3221_CRIT_SUM 0x0e #define INA3221_MASK_ENABLE 0x0f +#define SQ52210_ALERT_CONFIG 0x12 +#define SQ52210_CALIBRATION 0x14 +#define SQ52210_CURRENT1 0x15 +#define SQ52210_CURRENT2 0x16 +#define SQ52210_CURRENT3 0x17 +#define SQ52210_POWER1 0x18 +#define SQ52210_POWER2 0x19 +#define SQ52210_POWER3 0x1A +#define SQ52210_ALERT_LIMIT1 0x1B +#define SQ52210_ALERT_LIMIT2 0x1C +#define SQ52210_ALERT_LIMIT3 0x1D =20 #define INA3221_CONFIG_MODE_MASK GENMASK(2, 0) #define INA3221_CONFIG_MODE_POWERDOWN 0 @@ -108,8 +119,11 @@ struct ina3221_input { bool summation_disable; }; =20 +enum ina3221_ids { ina3221, sq52210 }; + /** * struct ina3221_data - device specific information + * @chip: Chip type identifier * @pm_dev: Device pointer for pm runtime * @regmap: Register map of the device * @fields: Register fields of the device @@ -120,6 +134,8 @@ struct ina3221_input { * @single_shot: running in single-shot operating mode */ struct ina3221_data { + enum ina3221_ids chip; + struct device *pm_dev; struct regmap *regmap; struct regmap_field *fields[F_MAX_FIELDS]; @@ -734,6 +750,7 @@ static const struct regmap_range ina3221_yes_ranges[] = =3D { regmap_reg_range(INA3221_CONFIG, INA3221_BUS3), regmap_reg_range(INA3221_SHUNT_SUM, INA3221_SHUNT_SUM), regmap_reg_range(INA3221_MASK_ENABLE, INA3221_MASK_ENABLE), + regmap_reg_range(SQ52210_ALERT_CONFIG, SQ52210_POWER3), }; =20 static const struct regmap_access_table ina3221_volatile_table =3D { @@ -818,13 +835,18 @@ static int ina3221_probe(struct i2c_client *client) struct device *dev =3D &client->dev; struct ina3221_data *ina; struct device *hwmon_dev; + enum ina3221_ids chip; char name[32]; int i, ret; =20 + chip =3D (uintptr_t)i2c_get_match_data(client); + ina =3D devm_kzalloc(dev, sizeof(*ina), GFP_KERNEL); if (!ina) return -ENOMEM; =20 + ina->chip =3D chip; + ina->regmap =3D devm_regmap_init_i2c(client, &ina3221_regmap_config); if (IS_ERR(ina->regmap)) { dev_err(dev, "Unable to allocate register map\n"); @@ -996,13 +1018,21 @@ static DEFINE_RUNTIME_DEV_PM_OPS(ina3221_pm, ina3221= _suspend, ina3221_resume, NULL); =20 static const struct of_device_id ina3221_of_match_table[] =3D { - { .compatible =3D "ti,ina3221", }, + { + .compatible =3D "silergy,sq52210", + .data =3D (void *)sq52210 + }, + { + .compatible =3D "ti,ina3221", + .data =3D (void *)ina3221 + }, { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, ina3221_of_match_table); =20 static const struct i2c_device_id ina3221_ids[] =3D { - { "ina3221" }, + { "ina3221", ina3221 }, + { "sq52210", sq52210 }, { /* sentinel */ } }; MODULE_DEVICE_TABLE(i2c, ina3221_ids); --=20 2.17.1 From nobody Mon Feb 9 07:26:19 2026 Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.3]) (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 CD55F37E2EF; Wed, 14 Jan 2026 08:18:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=117.135.210.3 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768378725; cv=none; b=HA4TNi6JgTxuNn2AGGdMDPaOnCfFAAU42LtCKrZifgUQ+WxugpPS7oD4l62WSWPLe/KWkVmXAuMUkpvvsv+IbSp4H778ECnoBega2Hmq7CueDQbkP/JFSFigitLxrLO9f7wyvGn7ADOfyaHN5Cet7Zh9iHBX+I7NNdju3guUYhU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768378725; c=relaxed/simple; bh=z6dbCNUriStuBV+KYYiPiE7y9WQMfgpr2xtzjWwHan8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=j9nh4CShlqoGYEJGGFeu5n2uWRrIieArZYQ10quZUxCtPC98ging4yDCB+ZBWLPMQhBpBEZKV8j/L3uemIxK9LKRrI+9gfUjx0U1dmZnZzhEmtcYlY9kgkrcS2BrmMTvIojK2F8eeROeFPmsYKSqva89dxgB9OcBnloAHD15nLo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=S/+z5Pb9; arc=none smtp.client-ip=117.135.210.3 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="S/+z5Pb9" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-Id; bh=WuEHeMrivFoEujO cr/xi2G/pphMy6vZiBBA1L4Xwt4w=; b=S/+z5Pb9RKKOvh6BPR9xTs/7f0gTuOH PrPdxBIcjsFSTLemPwkSJEkUctwdsZHe2EZowkC1o1Sx7he8BYxYmiSO9iXSyheO 74b81qQktgP0j7f9mka+yT6vqQ7F11cv3ft100fAdchp9E4VMGpQgVGMh/x8LKwE lUyRDlOXwCEs= Received: from localhost.localdomain (unknown []) by gzga-smtp-mtada-g1-2 (Coremail) with SMTP id _____wB3LaYsUWdpIIuhFg--.292S5; Wed, 14 Jan 2026 16:17:54 +0800 (CST) From: Wenliang Yan To: linux@roeck-us.net, Jean Delvare Cc: Wenliang Yan , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jonathan Corbet , linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 RESEND 3/8] hwmon: (ina3221) Pre-calculate current and power LSB Date: Wed, 14 Jan 2026 03:17:36 -0500 Message-Id: <20260114081741.111340-4-wenliang202407@163.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20260114081741.111340-1-wenliang202407@163.com> References: <20260114081741.111340-1-wenliang202407@163.com> X-CM-TRANSID: _____wB3LaYsUWdpIIuhFg--.292S5 X-Coremail-Antispam: 1Uf129KBjvJXoW3JryUAFy5JF4rtw4kAw13urg_yoW7Xry3pF 4fKryrta40qF1fKa9Ikw4xGF1rtr97Jr47KrZrGw1IqFsFkryqk3yrJFyDtFy5Ary5ZF17 X3y7tr4Duws2yaUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zRFD73UUUUU= X-CM-SenderInfo: xzhqzxhdqjjiisuqlqqrwthudrp/xtbC5xOUaGlnUTPPDAAA3n Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The LSB for current and power can be pre-calculated for data read/write operations. The current LSB is determined by the calibration value and shunt resistor value, with the calibration value fixed within the driver. The power LSB can be derived from the current LSB. Signed-off-by: Wenliang Yan --- drivers/hwmon/ina3221.c | 85 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/drivers/hwmon/ina3221.c b/drivers/hwmon/ina3221.c index 47ef4fe694ea..b5fa984a5a25 100644 --- a/drivers/hwmon/ina3221.c +++ b/drivers/hwmon/ina3221.c @@ -67,6 +67,7 @@ =20 #define INA3221_CONFIG_DEFAULT 0x7127 #define INA3221_RSHUNT_DEFAULT 10000 +#define SQ52210_SHUNT_LSB 40000000 /* pV/LSB */ =20 enum ina3221_fields { /* Configuration */ @@ -121,8 +122,16 @@ struct ina3221_input { =20 enum ina3221_ids { ina3221, sq52210 }; =20 +struct ina3221_config { + bool has_current; /* chip has internal current reg */ + bool has_power; /* chip has internal power reg */ + int calibration_value; /* calculate current_lsb */ + int power_lsb_factor; +}; + /** * struct ina3221_data - device specific information + * @config: Used to store characteristics of different chips * @chip: Chip type identifier * @pm_dev: Device pointer for pm runtime * @regmap: Register map of the device @@ -131,9 +140,12 @@ enum ina3221_ids { ina3221, sq52210 }; * @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 + * @current_lsb_uA: The value of one LSB corresponding to the current regi= ster + * @power_lsb_uW: The value of one LSB corresponding to the power register * @single_shot: running in single-shot operating mode */ struct ina3221_data { + const struct ina3221_config *config; enum ina3221_ids chip; =20 struct device *pm_dev; @@ -143,10 +155,30 @@ struct ina3221_data { u32 reg_config; int summation_shunt_resistor; u32 summation_channel_control; + long current_lsb_uA; + long power_lsb_uW; =20 bool single_shot; }; =20 +static const struct ina3221_config ina3221_config[] =3D { + [ina3221] =3D { + .has_current =3D false, + .has_power =3D false, + }, + [sq52210] =3D { + .has_current =3D true, + .has_power =3D true, + /* + * With this default value configuration, + * the following formula can be obtained: + * Current_LSB =3D Shunt_LSB / Rshunt + */ + .calibration_value =3D 256, + .power_lsb_factor =3D 20, + }, +}; + static inline bool ina3221_is_enabled(struct ina3221_data *ina, int channe= l) { /* Summation channel checks shunt resistor values */ @@ -697,6 +729,25 @@ static const struct hwmon_chip_info ina3221_chip_info = =3D { }; =20 /* Extra attribute groups */ + +/* + * Calculate the value corresponding to one LSB of the current and + * power registers. + * formula : Current_LSB =3D Shunt_LSB / Rshunt + * Power_LSB =3D power_lsb_factor * Current_LSB + */ +static int ina3221_set_shunt(struct ina3221_data *ina, unsigned long val) +{ + if (!val || val > SQ52210_SHUNT_LSB) + return -EINVAL; + + ina->current_lsb_uA =3D DIV_ROUND_CLOSEST(SQ52210_SHUNT_LSB, val); + ina->power_lsb_uW =3D ina->config->power_lsb_factor * + ina->current_lsb_uA; + + return 0; +} + static ssize_t ina3221_shunt_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -730,6 +781,17 @@ static ssize_t ina3221_shunt_store(struct device *dev, /* Update summation_shunt_resistor for summation channel */ ina->summation_shunt_resistor =3D ina3221_summation_shunt_resistor(ina); =20 + /* + * The current and power registers can only be used when + * all enabled channels have identical shunt resistors + */ + if (ina->summation_shunt_resistor) { + if (ina->config->has_current) { + ret =3D ina3221_set_shunt(ina, val); + if (ret < 0) + return ret; + } + } return count; } =20 @@ -846,6 +908,7 @@ static int ina3221_probe(struct i2c_client *client) return -ENOMEM; =20 ina->chip =3D chip; + ina->config =3D &ina3221_config[chip]; =20 ina->regmap =3D devm_regmap_init_i2c(client, &ina3221_regmap_config); if (IS_ERR(ina->regmap)) { @@ -892,6 +955,16 @@ static int ina3221_probe(struct i2c_client *client) ina->summation_channel_control |=3D BIT(14 - i); } =20 + /* + * The current and power registers can only be used when + * all enabled channels have identical shunt resistors + */ + if (ina->summation_shunt_resistor) { + ret =3D ina3221_set_shunt(ina, ina->summation_shunt_resistor); + if (ret < 0) + return ret; + } + ina->pm_dev =3D dev; dev_set_drvdata(dev, ina); =20 @@ -1009,6 +1082,18 @@ static int ina3221_resume(struct device *dev) dev_err(dev, "Unable to control summation channel\n"); return ret; } + /* + * The calibration register can only be enabled when all + * shunt resistor values are identical. + */ + if (ina->config->has_current) { + ret =3D regmap_write(ina->regmap, SQ52210_CALIBRATION, + ina->config->calibration_value); + if (ret) { + dev_err(dev, "Unable to set calibration value\n"); + return ret; + } + } } =20 return 0; --=20 2.17.1 From nobody Mon Feb 9 07:26:19 2026 Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.3]) (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 BFC1D26ED35; Wed, 14 Jan 2026 08:18:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=117.135.210.3 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768378723; cv=none; b=p9Vovx3+segAhpaAj1JO2GS55CiurY3wahzATRLYoVHMT64Of8NCejEAmkwoe+DPSFx5CHjfktr1eAJ0vonux9LqzpojrSvuvHDy/wNC7orQrRUo3+jQKMe2OmyFYs3fU20irBpeMvBuBtFjnh3tDO93tMWpQizWlnekqfOv7PA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768378723; c=relaxed/simple; bh=hBhvsuW3B/69apNkWMzqRnqNgKxIb4+zXZeq0VpfECM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=lbrWOlbH2xTaxNJHcc1hTbmbvEyVqoT+TWxm5NB5jWhxlb+D+gJKBeDR/JzkZnnt4Pt7S5TbXQKc4QRNjGqqUYVD+czYNDGxWm2iDa+AMVaThFBA3uF1sM0xIo9HK7vMDBt8wMZ2QqImh49o+z/0ehaAHA3TXsv/UfQnSwGEL5I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=qdJs0g86; arc=none smtp.client-ip=117.135.210.3 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="qdJs0g86" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-Id; bh=SeKIIdbs9uF8hF/ ORo4qkiW+uv23+t/MhSqLxns7ow0=; b=qdJs0g86KwfL6mtNUPnMaOSM+Ody4Br lRzp02s+0NgG6lAHWguI72RboVVSyHZhC9br34vd8KEMdnqxx+tVuf/xem3ya+e8 UYHjFKoZNSxpCNhs7t6jD9SJFNjsCC7J4lwYSw0YVvtvdKTeKGqlju4hAZHxGOM+ skp9hvl+8GAc= Received: from localhost.localdomain (unknown []) by gzga-smtp-mtada-g1-2 (Coremail) with SMTP id _____wB3LaYsUWdpIIuhFg--.292S6; Wed, 14 Jan 2026 16:17:55 +0800 (CST) From: Wenliang Yan To: linux@roeck-us.net, Jean Delvare Cc: Wenliang Yan , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jonathan Corbet , linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 RESEND 4/8] hwmon: (ina3221) Support alert configuration Date: Wed, 14 Jan 2026 03:17:37 -0500 Message-Id: <20260114081741.111340-5-wenliang202407@163.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20260114081741.111340-1-wenliang202407@163.com> References: <20260114081741.111340-1-wenliang202407@163.com> X-CM-TRANSID: _____wB3LaYsUWdpIIuhFg--.292S6 X-Coremail-Antispam: 1Uf129KBjvJXoWxCF48KrWUGrWkCF4furW3KFg_yoW5WFy5pF 4ak34rt3W2qF4Sgws7Kan5KFyFy34xWF47trnrW340qFsrJryjvw1kKa4DtFyYvFn5ZFyx tay7tr4UCanrAaUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0Jj3Ef5UUUUU= X-CM-SenderInfo: xzhqzxhdqjjiisuqlqqrwthudrp/xtbC5xSVaWlnUTTPJgAA3N Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add alert configuration for initialization and resume. Signed-off-by: Wenliang Yan --- drivers/hwmon/ina3221.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/drivers/hwmon/ina3221.c b/drivers/hwmon/ina3221.c index b5fa984a5a25..c82ef2d23056 100644 --- a/drivers/hwmon/ina3221.c +++ b/drivers/hwmon/ina3221.c @@ -65,6 +65,8 @@ =20 #define INA3221_MASK_ENABLE_SCC_MASK GENMASK(14, 12) =20 +#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 }; =20 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 regi= ster * @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; =20 @@ -163,10 +168,12 @@ struct ina3221_data { =20 static const struct ina3221_config ina3221_config[] =3D { [ina3221] =3D { + .has_alerts =3D false, .has_current =3D false, .has_power =3D false, }, [sq52210] =3D { + .has_alerts =3D true, .has_current =3D true, .has_power =3D true, /* @@ -948,6 +955,10 @@ static int ina3221_probe(struct i2c_client *client) ina->reg_config &=3D ~INA3221_CONFIG_CHx_EN(i); } =20 + /* Initialize alert_type_select */ + if (ina->config->has_alerts) + ina->alert_type_select =3D 0; + /* Initialize summation_shunt_resistor for summation channel control */ ina->summation_shunt_resistor =3D ina3221_summation_shunt_resistor(ina); for (i =3D 0; i < INA3221_NUM_CHANNELS; i++) { @@ -1096,6 +1107,17 @@ static int ina3221_resume(struct device *dev) } } =20 + /* Restore alert config register value to hardware */ + if (ina->config->has_alerts) { + ret =3D regmap_update_bits(ina->regmap, SQ52210_ALERT_CONFIG, + SQ52210_ALERT_CONFIG_MASK, + ina->alert_type_select & SQ52210_ALERT_CONFIG_MASK); + if (ret) { + dev_err(dev, "Unable to select alert type\n"); + return ret; + } + } + return 0; } =20 --=20 2.17.1 From nobody Mon Feb 9 07:26:19 2026 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.2]) (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 C2F922C1780; Wed, 14 Jan 2026 08:18:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.2 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768378733; cv=none; b=bAydjmDIEXIOtRATYRr9ejK4Q85cVGfnhgeDIGjATug8qfi4E8OO/GiQzNWMGIB3c6lSOVD5+G4XxANIlLW9ac6HZKLXWsjAe9gB/bOGt7SIRWuELPs8YkoMBN8g4SsNKzybh8EBoGbk8Pmea7blWwNS10X548+bg7OoZhg0WlM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768378733; c=relaxed/simple; bh=iZFAw0Zulc1kkPVmRb5SmjbByX5y3RuqBUYcV+I6NVo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=CPOIm/1e9Zg5wdvGHTMl47xXRMy24dyrV0lXlDAZ89hGCQZFhfBag9e/amW5S+sZDBxtthn7bup52YRpmV+qTcLz+hM/81GiDJvXbq87llU+YqV2vv9NP47l1jCPTPtOIpw37VDQy3vLacOLMEQOx0i6PdCtYfe2HTUI2LSLIG0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=K0VVTeuh; arc=none smtp.client-ip=220.197.31.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="K0VVTeuh" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-Id; bh=qeUmYFfRsJGAPjd nIs83M/R9EfS1RjUUdlnMQCHpzZE=; b=K0VVTeuhhpiPk3SUR1VR/ea4zNeu5aD uXtdSkFQ/w7VTJPPyqWpbj1GwEIXrXyvnitJSv4TYTRei5PLH0lhdyUUkgloXon9 SXnxG3GfSCJK40L7OxIVBgtGh407m5tW3ck3oFoo4obUFxfnn6xEFeq9yJZrnafK wP10sFlrb100= Received: from localhost.localdomain (unknown []) by gzga-smtp-mtada-g1-2 (Coremail) with SMTP id _____wB3LaYsUWdpIIuhFg--.292S7; Wed, 14 Jan 2026 16:17:57 +0800 (CST) From: Wenliang Yan To: linux@roeck-us.net, Jean Delvare Cc: Wenliang Yan , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jonathan Corbet , Shuah Khan , linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 RESEND 5/8] hwmon: (ina3221) Introduce power attribute and alert characteristics Date: Wed, 14 Jan 2026 03:17:38 -0500 Message-Id: <20260114081741.111340-6-wenliang202407@163.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20260114081741.111340-1-wenliang202407@163.com> References: <20260114081741.111340-1-wenliang202407@163.com> X-CM-TRANSID: _____wB3LaYsUWdpIIuhFg--.292S7 X-Coremail-Antispam: 1Uf129KBjvJXoWxtryfCryfCF48WFW5WF47CFg_yoW7XFW5pa ykX3yfJr18Ar93Zw4xKF4UXFn8t3yxGay7Jr1I9395J3ZrArnYqr48K3W0qF90kryfZr1F k34IqrWrGr13JrUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0Jj9MabUUUUU= X-CM-SenderInfo: xzhqzxhdqjjiisuqlqqrwthudrp/xtbC5xWVaWlnUTXPSgAA3h Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" SQ52210 has built-in current and power sensors as well as multiple alert functions. Add power attributes and different critical characteristics in hwmon to report the corresponding data. Signed-off-by: Wenliang Yan --- Documentation/hwmon/ina3221.rst | 24 ++++++++++++++ drivers/hwmon/ina3221.c | 57 ++++++++++++++++++++++++++++++--- 2 files changed, 77 insertions(+), 4 deletions(-) diff --git a/Documentation/hwmon/ina3221.rst b/Documentation/hwmon/ina3221.= rst index 8c12c54d2c24..224c6cf735ed 100644 --- a/Documentation/hwmon/ina3221.rst +++ b/Documentation/hwmon/ina3221.rst @@ -13,6 +13,13 @@ Supported chips: =20 https://www.ti.com/ =20 + * Silergy SQ52210 + + Prefix: 'SQ52210' + + Addresses: I2C 0x40 - 0x43 + + Author: Andrew F. Davis =20 Description @@ -23,6 +30,9 @@ side of up to three D.C. power supplies. The INA3221 moni= tors both shunt drop and supply voltage, with programmable conversion times and averaging, curr= ent and power are calculated host-side from these. =20 +The SQ52210 is a mostly compatible chip from Silergy. It incorporates inte= rnal +current and power registers, and provides an extra configurable alert func= tion. + Sysfs entries ------------- =20 @@ -72,3 +82,17 @@ update_interval Data conversion time in millisec= ond, following: Note that setting update_interval to 0ms sets both= BC and SC to 140 us (minimum conversion time). =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D + +Additional sysfs entries for sq52210 +------------------------------------- + +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D +in[123]_crit Critical high bus voltage +in[123]_crit_alarm Bus voltage critical high alarm +in[123]_lcrit Critical low bus voltage +in[123]_lcrit_alarm Bus voltage critical low alarm +curr[123]_lcrit Critical low current +curr[123]_lcrit_alarm Current critical low alarm +power[123]_input Current for channels 1, 2, and 3 respectively +power[123]_crit Critical high power +power[123]_crit_alarm Power critical high alarm diff --git a/drivers/hwmon/ina3221.c b/drivers/hwmon/ina3221.c index c82ef2d23056..4b2888be0ae2 100644 --- a/drivers/hwmon/ina3221.c +++ b/drivers/hwmon/ina3221.c @@ -645,6 +645,8 @@ static umode_t ina3221_is_visible(const void *drvdata, { const struct ina3221_data *ina =3D drvdata; const struct ina3221_input *input =3D NULL; + bool has_alerts =3D ina->config->has_alerts; + bool has_power =3D ina->config->has_power; =20 switch (type) { case hwmon_chip: @@ -672,6 +674,16 @@ static umode_t ina3221_is_visible(const void *drvdata, return 0444; case hwmon_in_enable: return 0644; + case hwmon_in_crit: + case hwmon_in_lcrit: + if (has_alerts) + return 0644; + return 0; + case hwmon_in_crit_alarm: + case hwmon_in_lcrit_alarm: + if (has_alerts) + return 0444; + return 0; default: return 0; } @@ -684,6 +696,31 @@ static umode_t ina3221_is_visible(const void *drvdata, case hwmon_curr_crit: case hwmon_curr_max: return 0644; + case hwmon_curr_lcrit: + if (has_alerts) + return 0644; + return 0; + case hwmon_curr_lcrit_alarm: + if (has_alerts) + return 0444; + return 0; + default: + return 0; + } + case hwmon_power: + switch (attr) { + case hwmon_power_input: + if (has_power) + return 0444; + return 0; + case hwmon_power_crit_alarm: + if (has_alerts) + return 0444; + return 0; + case hwmon_power_crit: + if (has_alerts) + return 0644; + return 0; default: return 0; } @@ -694,7 +731,14 @@ static umode_t ina3221_is_visible(const void *drvdata, =20 #define INA3221_HWMON_CURR_CONFIG (HWMON_C_INPUT | \ HWMON_C_CRIT | HWMON_C_CRIT_ALARM | \ - HWMON_C_MAX | HWMON_C_MAX_ALARM) + HWMON_C_MAX | HWMON_C_MAX_ALARM | \ + HWMON_C_LCRIT | HWMON_C_LCRIT_ALARM) +#define SQ52210_HWMON_POWER_CONFIG (HWMON_P_INPUT | \ + HWMON_P_CRIT | HWMON_P_CRIT_ALARM) +#define SQ52210_HWMON_BUS_CONFIG (HWMON_I_INPUT | \ + HWMON_I_ENABLE | HWMON_I_LABEL | \ + HWMON_I_LCRIT_ALARM | HWMON_I_LCRIT |\ + HWMON_I_CRIT_ALARM | HWMON_I_CRIT) =20 static const struct hwmon_channel_info * const ina3221_info[] =3D { HWMON_CHANNEL_INFO(chip, @@ -704,9 +748,9 @@ static const struct hwmon_channel_info * const ina3221_= info[] =3D { /* 0: dummy, skipped in is_visible */ HWMON_I_INPUT, /* 1-3: input voltage Channels */ - HWMON_I_INPUT | HWMON_I_ENABLE | HWMON_I_LABEL, - HWMON_I_INPUT | HWMON_I_ENABLE | HWMON_I_LABEL, - HWMON_I_INPUT | HWMON_I_ENABLE | HWMON_I_LABEL, + SQ52210_HWMON_BUS_CONFIG, + SQ52210_HWMON_BUS_CONFIG, + SQ52210_HWMON_BUS_CONFIG, /* 4-6: shunt voltage Channels */ HWMON_I_INPUT, HWMON_I_INPUT, @@ -720,6 +764,11 @@ static const struct hwmon_channel_info * const ina3221= _info[] =3D { INA3221_HWMON_CURR_CONFIG, /* 4: summation of current channels */ HWMON_C_INPUT | HWMON_C_CRIT | HWMON_C_CRIT_ALARM), + HWMON_CHANNEL_INFO(power, + /* 1-3: power channels*/ + SQ52210_HWMON_POWER_CONFIG, + SQ52210_HWMON_POWER_CONFIG, + SQ52210_HWMON_POWER_CONFIG), NULL }; =20 --=20 2.17.1 From nobody Mon Feb 9 07:26:19 2026 Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.3]) (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 CD61637E2F0; Wed, 14 Jan 2026 08:18:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=117.135.210.3 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768378725; cv=none; b=ffw+WY+Nx3BHorhaVJwc3YpAt/vLXSqZJv196ktbEZ6CpYx+aoQYay05COpbQ917M4wTLs7Kamucp+TV7NMkUk9MNYmhyoicd10ErhLdqQpWCrGSfaQJzyo64N0ZFHS9tXoSDJfPuxhXIsqErh5Eg12w57mrhwk61+nET7ledOE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768378725; c=relaxed/simple; bh=w/Y6f6SdcqZOM/5xlLUcGD4SK3+N7DTKbTwQyyFK8ic=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=YGUE3g7oY8xa/UAAu9NZipiDzHHMLg+dWXVs3KXKmx6D8NmUKN7lYEETUrcrehwtAwnM3B4mYHuL1p/WsAx1cZNeUWl1eEUi7Jq8FMTW9XLYdcudIGHa29x+TgnK6Jp0bI9jQvq1Qnu+C+tM4Cc+k9n6qQP+dMwHP+GjCez22Vo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=P+Rf0ILB; arc=none smtp.client-ip=117.135.210.3 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="P+Rf0ILB" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-Id; bh=b6N5JjTE6Adp8A0 d5t2oO4Hebrc0aW5+TFHtmcjf1KY=; b=P+Rf0ILBD1yk5+5RE6L7rvese3rS3cY LXoqlZDnzTptwkKCbI4WmrE7TyYrQL3MlnoN5v55s7B3flw49VuqJIYIyfWPElKg UaaNLJ7Skqz25MMyrTnqCDB6Uadivs2qfL0nNCOzC3ajmrV2mM7ashH0Pw21o42w qfaR/5u2YEOw= Received: from localhost.localdomain (unknown []) by gzga-smtp-mtada-g1-2 (Coremail) with SMTP id _____wB3LaYsUWdpIIuhFg--.292S8; Wed, 14 Jan 2026 16:17:58 +0800 (CST) From: Wenliang Yan To: linux@roeck-us.net, Jean Delvare Cc: Wenliang Yan , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jonathan Corbet , linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 RESEND 6/8] hwmon: (ina3221) Support for writing alert limit values and modify the 'ina3221_read_value' function Date: Wed, 14 Jan 2026 03:17:39 -0500 Message-Id: <20260114081741.111340-7-wenliang202407@163.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20260114081741.111340-1-wenliang202407@163.com> References: <20260114081741.111340-1-wenliang202407@163.com> X-CM-TRANSID: _____wB3LaYsUWdpIIuhFg--.292S8 X-Coremail-Antispam: 1Uf129KBjvJXoW3Jr4DKrykGr4Utr4rWr47CFg_yoWxuFW8p3 yfCF1rtr17tr4Svws2kFs5WFyrAr1xW3y2vr9rK3ySva1UA3W0grykta1Fyry5KFn3ZFsr X3srZF1UCanrJaDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0Jjn_-9UUUUU= X-CM-SenderInfo: xzhqzxhdqjjiisuqlqqrwthudrp/xtbC6BaVaWlnUTbHWgAA32 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" SQ52210 adds power, current, and limit registers. The ina3221_read_value function has been refactored to adapt to the new register data reading format. Each channel supports four new alert trigger modes, but only one trigger mode can be active at any given time. Alert values are stored in the same register. The sq52210_alert_limit_write function has been added to write alert threshold values and configure alert source type. Signed-off-by: Wenliang Yan --- drivers/hwmon/ina3221.c | 158 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 155 insertions(+), 3 deletions(-) diff --git a/drivers/hwmon/ina3221.c b/drivers/hwmon/ina3221.c index 4b2888be0ae2..38dbcd8046bd 100644 --- a/drivers/hwmon/ina3221.c +++ b/drivers/hwmon/ina3221.c @@ -66,6 +66,14 @@ #define INA3221_MASK_ENABLE_SCC_MASK GENMASK(14, 12) =20 #define SQ52210_ALERT_CONFIG_MASK GENMASK(15, 4) +#define SQ52210_MASK_ALERT_CHANNEL1 (BIT(15) | BIT(12) | BIT(9) | BIT(6)) +#define SQ52210_MASK_ALERT_CHANNEL2 (BIT(14) | BIT(11) | BIT(8) | BIT(5)) +#define SQ52210_MASK_ALERT_CHANNEL3 (BIT(13) | BIT(10) | BIT(7) | BIT(4)) + +#define SQ52210_ALERT_ALL_SUL_MASK (BIT(15) | BIT(14) | BIT(13)) +#define SQ52210_ALERT_ALL_BOL_MASK (BIT(12) | BIT(11) | BIT(10)) +#define SQ52210_ALERT_ALL_BUL_MASK (BIT(9) | BIT(8) | BIT(7)) +#define SQ52210_ALERT_ALL_POL_MASK (BIT(6) | BIT(5) | BIT(4)) =20 #define INA3221_CONFIG_DEFAULT 0x7127 #define INA3221_RSHUNT_DEFAULT 10000 @@ -108,6 +116,13 @@ enum ina3221_channels { INA3221_NUM_CHANNELS }; =20 +enum sq52210_alert_types { + SQ52210_ALERT_SUL, + SQ52210_ALERT_BOL, + SQ52210_ALERT_BUL, + SQ52210_ALERT_POL +}; + /** * struct ina3221_input - channel input source specific information * @label: label of channel input source @@ -272,6 +287,18 @@ static inline int ina3221_wait_for_data(struct ina3221= _data *ina) cvrf, cvrf, wait, wait * 2); } =20 +static const u32 alert_groups[] =3D { + SQ52210_MASK_ALERT_CHANNEL1, + SQ52210_MASK_ALERT_CHANNEL2, + SQ52210_MASK_ALERT_CHANNEL3, +}; + +static const u8 limit_regs[] =3D { + SQ52210_ALERT_LIMIT1, + SQ52210_ALERT_LIMIT2, + SQ52210_ALERT_LIMIT3, +}; + static int ina3221_read_value(struct ina3221_data *ina, unsigned int reg, int *val) { @@ -284,13 +311,55 @@ static int ina3221_read_value(struct ina3221_data *in= a, unsigned int reg, =20 /* * Shunt Voltage Sum register has 14-bit value with 1-bit shift + * Current registers have 15-bit value + * Power registers have 16-bit value + * ALERT_LIMIT registers have 16-bit value with 3-bit shift * Other Shunt Voltage registers have 12 bits with 3-bit shift */ - if (reg =3D=3D INA3221_SHUNT_SUM || reg =3D=3D INA3221_CRIT_SUM) + switch (reg) { + case INA3221_SHUNT_SUM: + case INA3221_CRIT_SUM: *val =3D sign_extend32(regval >> 1, 14); - else + break; + case SQ52210_CURRENT1: + case SQ52210_CURRENT2: + case SQ52210_CURRENT3: + *val =3D sign_extend32(regval, 15); + break; + case SQ52210_POWER1: + case SQ52210_POWER2: + case SQ52210_POWER3: + *val =3D regval; + break; + case INA3221_BUS1: + case INA3221_BUS2: + case INA3221_BUS3: + case INA3221_SHUNT1: + case INA3221_SHUNT2: + case INA3221_SHUNT3: + case INA3221_WARN1: + case INA3221_WARN2: + case INA3221_WARN3: + case INA3221_CRIT1: + case INA3221_CRIT2: + case INA3221_CRIT3: *val =3D sign_extend32(regval >> 3, 12); - + break; + case SQ52210_ALERT_LIMIT1: + case SQ52210_ALERT_LIMIT2: + case SQ52210_ALERT_LIMIT3: + if (ina->alert_type_select & SQ52210_ALERT_ALL_SUL_MASK) + *val =3D sign_extend32(regval, 15); + else if (ina->alert_type_select & (SQ52210_ALERT_ALL_BOL_MASK + | SQ52210_ALERT_ALL_BUL_MASK)) + *val =3D regval >> 3; + else if (ina->alert_type_select & SQ52210_ALERT_ALL_POL_MASK) + *val =3D regval; + break; + default: + *val =3D 0; + return -EOPNOTSUPP; + }; return 0; } =20 @@ -443,6 +512,89 @@ static int ina3221_read_curr(struct device *dev, u32 a= ttr, } } =20 +static int sq52210_alert_limit_write(struct ina3221_data *ina, + enum sq52210_alert_types type, int channel, long val) +{ + struct regmap *regmap =3D ina->regmap; + int item =3D channel % INA3221_NUM_CHANNELS; + u8 limit_reg; + u32 alert_group, alert_mask =3D 0; + int regval =3D 0; + int ret; + + if (item >=3D ARRAY_SIZE(alert_groups) || val < 0) + return -EINVAL; + + alert_group =3D alert_groups[item]; + limit_reg =3D limit_regs[item]; + + /* Clear alerts for this channel group first */ + ret =3D regmap_update_bits(regmap, SQ52210_ALERT_CONFIG, alert_group, 0); + if (ret) + return ret; + + /* Determine alert type and calculate register value */ + switch (type) { + /* + * The alert warning logic is implemented by comparing the limit register= values + * with the corresponding alert source register values. Since the current= register + * is a 15-bit signed register and the power register is a 16-bit unsigned + * register, but the lower 3 bits of the limit register default to 0, the= lower + * 3 bits will be forced to 0 when setting SUL and POL warning values. + * Formula to convert register value: + * bus_voltage: (regval / 8mV) << 3 + * current: (regval / current_lsb) & 0xfff8 + * power: (regval / current_lsb) & 0xfff8 + */ + case SQ52210_ALERT_SUL: + /* SUL: Shunt Under Limit - BIT(15), BIT(14), BIT(13) */ + alert_mask =3D BIT(15 - item); + /* Current Register, signed register, result in mA */ + regval =3D DIV_ROUND_CLOSEST(val * 1000, ina->current_lsb_uA) & 0xfff8; + regval =3D clamp_val(regval, -32760, 32760); + break; + case SQ52210_ALERT_BOL: + /* BOL: Bus Over Limit - BIT(12), BIT(11), BIT(10) */ + alert_mask =3D BIT(12 - item); + /* Bus Register, signed register, result in mV */ + regval =3D clamp_val(val, -32760, 32760); + break; + case SQ52210_ALERT_BUL: + /* BUL: Bus Under Limit - BIT(9), BIT(8), BIT(7) */ + alert_mask =3D BIT(9 - item); + /* Bus Register, signed register, result in mV */ + regval =3D clamp_val(val, -32760, 32760); + break; + case SQ52210_ALERT_POL: + /* POL: Power Over Limit - BIT(6), BIT(5), BIT(4) */ + alert_mask =3D BIT(6 - item); + /* Power Register, unsigned register, result in mW */ + regval =3D DIV_ROUND_CLOSEST(val * 1000, ina->power_lsb_uW) & 0xfff8; + regval =3D clamp_val(regval, 0, 65528); + break; + default: + /* For unsupported attributes, just clear the configuration */ + ina->alert_type_select &=3D ~alert_group; + return -EOPNOTSUPP; + } + + /* Write limit register value */ + ret =3D regmap_write(regmap, limit_reg, regval); + if (ret) + return ret; + + /* Update alert configuration if limit value is non-zero */ + if (regval) { + ina->alert_type_select =3D (ina->alert_type_select & ~alert_group) | ale= rt_mask; + ret =3D regmap_update_bits(regmap, SQ52210_ALERT_CONFIG, + alert_group, alert_mask); + } else { + ina->alert_type_select &=3D ~alert_group; + } + + return ret; +} + static int ina3221_write_chip(struct device *dev, u32 attr, long val) { struct ina3221_data *ina =3D dev_get_drvdata(dev); --=20 2.17.1 From nobody Mon Feb 9 07:26:19 2026 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.4]) (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 C8C4E36C0CA; Wed, 14 Jan 2026 08:18:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768378727; cv=none; b=Cm+M2TlGA7FkrMjVmRiyzyW9T9Erbzo9PYQjTUBOkHzO6wXBNv4hOjs3EYSf2kQuOm2UDaNTcbNsGvhlgM5naljznhX2OUTKY4OgOZzuOvpzLcqdiwSmpNslnTqniB3P7QYhDCesG74XhYkatuGkYz1CiLLAyVqs6XzTCLOufk8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768378727; c=relaxed/simple; bh=RH7ASWKQFsQ/K/ZQT1O576kfsspyIqlJhgko+1brvIY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=ppx28AlSAczFqGv+KdaVI6NaZFHwqsyU15GtQPJKKn+LGyxiUZwsoNdnJc7ZTPfwHKeXDAb0oD36+lDh9jG6zpGXriXNTp/KE/fD4h4kb/tkSkFcRPcpNxD5xpe9ueIhkH2SdiZ4oRgjUAsN9ksQ9EpNebmuUBBxZkalKiJyLt0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=BNgZ5EHi; arc=none smtp.client-ip=220.197.31.4 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="BNgZ5EHi" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-Id; bh=zZD1jx9ZKsatF5B 7bD5UlDyEA4YVAEsL4Vw/i6rSL2k=; b=BNgZ5EHimpnJ4DSumZFlb2dZ2RH/V2W 4eB9OhQbR6vpI1BoJyb16CIGD4ghY0dgBkBse9Jlkort6V/IbMl+TrTT+A9Nmz31 jTZbQZ2dk5f0fxt/eUoLeDf3B9FUyyH9FdlH+zBpC93iJH50AbPrOi24DqgZqck3 TbvgEQ2MGxTk= Received: from localhost.localdomain (unknown []) by gzga-smtp-mtada-g1-2 (Coremail) with SMTP id _____wB3LaYsUWdpIIuhFg--.292S9; Wed, 14 Jan 2026 16:17:59 +0800 (CST) From: Wenliang Yan To: linux@roeck-us.net, Jean Delvare Cc: Wenliang Yan , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jonathan Corbet , linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 RESEND 7/8] hwmon: (ina3221) Support write/read functions for 'power' attribute Date: Wed, 14 Jan 2026 03:17:40 -0500 Message-Id: <20260114081741.111340-8-wenliang202407@163.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20260114081741.111340-1-wenliang202407@163.com> References: <20260114081741.111340-1-wenliang202407@163.com> X-CM-TRANSID: _____wB3LaYsUWdpIIuhFg--.292S9 X-Coremail-Antispam: 1Uf129KBjvJXoWxXFy3tr48WFWxXw1UCw43Awb_yoWrWF4xp3 y0kFWrtr4jq3WS9wsakFs8Gw15tr4xX3y2yr9Fk3sava1UZrn0gFyrt3Wqya4UCry3Xr47 tayxAryru3ZrKr7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0JUXeOdUUUUU= X-CM-SenderInfo: xzhqzxhdqjjiisuqlqqrwthudrp/xtbC5xeVaWlnUTfPfgAA3V Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" SQ52210 adds power attributes to report power data and implements corresponding read/write functions for this purpose. This includes reading power values, reading alert thresholds, reading alert trigger status, and writing alert thresholds. Signed-off-by: Wenliang Yan --- drivers/hwmon/ina3221.c | 79 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/drivers/hwmon/ina3221.c b/drivers/hwmon/ina3221.c index 38dbcd8046bd..a1ac998378fb 100644 --- a/drivers/hwmon/ina3221.c +++ b/drivers/hwmon/ina3221.c @@ -92,6 +92,9 @@ enum ina3221_fields { /* Alert Flags: SF is the summation-alert flag */ F_SF, F_CF3, F_CF2, F_CF1, =20 + /* Alert Flags: AFF is the alert function flag */ + F_AFF3, F_AFF2, F_AFF1, + /* sentinel */ F_MAX_FIELDS }; @@ -107,6 +110,10 @@ static const struct reg_field ina3221_reg_fields[] =3D= { [F_CF3] =3D REG_FIELD(INA3221_MASK_ENABLE, 7, 7), [F_CF2] =3D REG_FIELD(INA3221_MASK_ENABLE, 8, 8), [F_CF1] =3D REG_FIELD(INA3221_MASK_ENABLE, 9, 9), + + [F_AFF3] =3D REG_FIELD(SQ52210_ALERT_CONFIG, 1, 1), + [F_AFF2] =3D REG_FIELD(SQ52210_ALERT_CONFIG, 2, 2), + [F_AFF1] =3D REG_FIELD(SQ52210_ALERT_CONFIG, 3, 3), }; =20 enum ina3221_channels { @@ -512,6 +519,60 @@ static int ina3221_read_curr(struct device *dev, u32 a= ttr, } } =20 +static const u8 ina3221_power_reg[][INA3221_NUM_CHANNELS] =3D { + [hwmon_power_input] =3D { SQ52210_POWER1, SQ52210_POWER2, SQ52210_POWER3 = }, + [hwmon_power_crit] =3D { SQ52210_ALERT_LIMIT1, SQ52210_ALERT_LIMIT2, + SQ52210_ALERT_LIMIT3 }, + [hwmon_power_crit_alarm] =3D { F_AFF1, F_AFF2, F_AFF3 }, +}; + +static int ina3221_read_power(struct device *dev, u32 attr, int channel, l= ong *val) +{ + struct ina3221_data *ina =3D dev_get_drvdata(dev); + u8 reg =3D ina3221_power_reg[attr][channel]; + int regval, ret; + + switch (attr) { + case hwmon_power_input: + if (!ina3221_is_enabled(ina, channel)) + return -ENODATA; + + /* Write CONFIG register to trigger a single-shot measurement */ + if (ina->single_shot) { + regmap_write(ina->regmap, INA3221_CONFIG, + ina->reg_config); + + ret =3D ina3221_wait_for_data(ina); + if (ret) + return ret; + } + + fallthrough; + case hwmon_power_crit: + ret =3D ina3221_read_value(ina, reg, ®val); + if (ret) + return ret; + /* Return power in mW */ + *val =3D DIV_ROUND_CLOSEST(regval * ina->power_lsb_uW, 1000); + return 0; + case hwmon_power_crit_alarm: + /* No actual register read if channel is disabled */ + if (!ina3221_is_enabled(ina, channel)) { + /* Return 0 for alert flags */ + *val =3D 0; + return 0; + } + + ret =3D regmap_field_read(ina->fields[reg], ®val); + if (ret) + return ret; + *val =3D regval; + return 0; + default: + return -EOPNOTSUPP; + } +} + static int sq52210_alert_limit_write(struct ina3221_data *ina, enum sq52210_alert_types type, int channel, long val) { @@ -731,6 +792,18 @@ static int ina3221_write_enable(struct device *dev, in= t channel, bool enable) return ret; } =20 +static int ina3221_write_power(struct device *dev, u32 attr, int channel, = long val) +{ + struct ina3221_data *ina =3D dev_get_drvdata(dev); + + switch (attr) { + case hwmon_power_crit: + return sq52210_alert_limit_write(ina, SQ52210_ALERT_POL, channel, val); + default: + return 0; + } +} + static int ina3221_read(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel, long *val) { @@ -747,6 +820,9 @@ static int ina3221_read(struct device *dev, enum hwmon_= sensor_types type, case hwmon_curr: ret =3D ina3221_read_curr(dev, attr, channel, val); break; + case hwmon_power: + ret =3D ina3221_read_power(dev, attr, channel, val); + break; default: ret =3D -EOPNOTSUPP; break; @@ -770,6 +846,9 @@ static int ina3221_write(struct device *dev, enum hwmon= _sensor_types type, case hwmon_curr: ret =3D ina3221_write_curr(dev, attr, channel, val); break; + case hwmon_power: + ret =3D ina3221_write_power(dev, attr, channel, val); + break; default: ret =3D -EOPNOTSUPP; break; --=20 2.17.1 From nobody Mon Feb 9 07:26:19 2026 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.5]) (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 DB32E37C11E; Wed, 14 Jan 2026 08:18:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768378722; cv=none; b=fOIWS+yWv1cxGkNbZIkrycHVOubexZDtGjOQY5ZjGMIylxLS46aYvVljgjjzBCEMd5CqD3+Cc+mhthyOQo94k1lmfQ8Gj9CvwMPsWQfj0wTnhdItNeDeeBBPH9hrBEnf4kPI/iI1kfYBSJLe2V2UaR0G3ecJJYRKtcLVjXEQNJY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768378722; c=relaxed/simple; bh=tKkHj585uRbwOBJnr4w4WFhS6cK3mEZfhTBJS3Gkwj0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=S7F6caxgAXcgu0NDzLNAjxjuQyFtEjZxEI4gJZAONfc/PnP2OGdJrDpmKVos6INmVc0RjVS3f686ygourbkEDOiflxNH1An/UdFK/f5ePswO7HtnVTOOJAG1tdkB+g9DmSc8TSwVplE8YxnPEtYKl1jZVYWs/dZWnGUjGxTPVZ0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=ODSNlQmI; arc=none smtp.client-ip=220.197.31.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="ODSNlQmI" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-Id; bh=UEnLV/mo+rvCzPn hi5Ysb5BkCmL3hyM1+qpTjHLGeh0=; b=ODSNlQmIBj0P78zyQoTy/fHZ9GjluPm o/idz0ECKQvqzmt3t33WbkYRtL4XjiWDF6odo6p5kl0pwCDKuZ1sN2MYHsThb9l/ FAVXNwoNtHB8QtbX6kvjitfVCJEvhx42mrdp5vsRN5JUGnyJk/ZfP6hlMLco0IWm OixGCt5awyvw= Received: from localhost.localdomain (unknown []) by gzga-smtp-mtada-g1-2 (Coremail) with SMTP id _____wB3LaYsUWdpIIuhFg--.292S10; Wed, 14 Jan 2026 16:18:00 +0800 (CST) From: Wenliang Yan To: linux@roeck-us.net, Jean Delvare Cc: Wenliang Yan , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jonathan Corbet , linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 RESEND 8/8] hwmon: (ina3221) Modify write/read functions for 'in' and 'curr' attribute Date: Wed, 14 Jan 2026 03:17:41 -0500 Message-Id: <20260114081741.111340-9-wenliang202407@163.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20260114081741.111340-1-wenliang202407@163.com> References: <20260114081741.111340-1-wenliang202407@163.com> X-CM-TRANSID: _____wB3LaYsUWdpIIuhFg--.292S10 X-Coremail-Antispam: 1Uf129KBjvJXoWxurW5uFy5GFW7urWDGF4DJwb_yoW7Jr1Dp3 yUGFWrtrWjq3WSgrs2kF4DWrn8tr4xW3y2yr9rK3sYva1UAryqkFyrG3Wq9345GryfWF4x JayxtFWUua1Dtr7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0JUXeOdUUUUU= X-CM-SenderInfo: xzhqzxhdqjjiisuqlqqrwthudrp/xtbC5xiWamlnUTjPlQAA3+ Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Modified the relevant read/write functions for 'in' and 'curr' attributes, adding support for crit, lcrit, crit_alarm, and lcrit_alarm features. Signed-off-by: Wenliang Yan --- drivers/hwmon/ina3221.c | 101 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 97 insertions(+), 4 deletions(-) diff --git a/drivers/hwmon/ina3221.c b/drivers/hwmon/ina3221.c index a1ac998378fb..9494518bf0b5 100644 --- a/drivers/hwmon/ina3221.c +++ b/drivers/hwmon/ina3221.c @@ -380,6 +380,12 @@ static const u8 ina3221_in_reg[] =3D { INA3221_SHUNT_SUM, }; =20 +static const u8 alert_flag[] =3D { + F_AFF1, + F_AFF2, + F_AFF3, +}; + static int ina3221_read_chip(struct device *dev, u32 attr, long *val) { struct ina3221_data *ina =3D dev_get_drvdata(dev); @@ -442,6 +448,40 @@ static int ina3221_read_in(struct device *dev, u32 att= r, int channel, long *val) case hwmon_in_enable: *val =3D ina3221_is_enabled(ina, channel); return 0; + case hwmon_in_crit: + case hwmon_in_lcrit: + if (channel >=3D INA3221_NUM_CHANNELS) + return -EOPNOTSUPP; + + if (!ina3221_is_enabled(ina, channel)) + return -ENODATA; + + reg =3D limit_regs[channel]; + ret =3D ina3221_read_value(ina, reg, ®val); + if (ret) + return ret; + /* + * Scale of bus voltage (mV): LSB is 8mV + */ + *val =3D regval * 8; + return 0; + case hwmon_in_crit_alarm: + case hwmon_in_lcrit_alarm: + if (channel >=3D INA3221_NUM_CHANNELS) + return -EOPNOTSUPP; + /* No actual register read if channel is disabled */ + if (!ina3221_is_enabled(ina, channel)) { + /* Return 0 for alert flags */ + *val =3D 0; + return 0; + } + + reg =3D alert_flag[channel]; + ret =3D regmap_field_read(ina->fields[reg], ®val); + if (ret) + return ret; + *val =3D regval; + return 0; default: return -EOPNOTSUPP; } @@ -501,6 +541,28 @@ static int ina3221_read_curr(struct device *dev, u32 a= ttr, /* Return current in mA */ *val =3D DIV_ROUND_CLOSEST(voltage_nv, resistance_uo); return 0; + case hwmon_curr_lcrit: + if (!resistance_uo) + return -ENODATA; + + if (channel >=3D INA3221_NUM_CHANNELS) + return -EOPNOTSUPP; + + reg =3D limit_regs[channel]; + ret =3D ina3221_read_value(ina, reg, ®val); + if (ret) + return ret; + + /* Return current in mA */ + *val =3D DIV_ROUND_CLOSEST(regval * ina->current_lsb_uA, 1000); + return 0; + case hwmon_curr_lcrit_alarm: + if (channel >=3D INA3221_NUM_CHANNELS) + return -EOPNOTSUPP; + + reg =3D alert_flag[channel]; + + fallthrough; case hwmon_curr_crit_alarm: case hwmon_curr_max_alarm: /* No actual register read if channel is disabled */ @@ -698,10 +760,9 @@ static int ina3221_write_chip(struct device *dev, u32 = attr, long val) } } =20 -static int ina3221_write_curr(struct device *dev, u32 attr, - int channel, long val) +static int ina3221_write_curr_shunt(struct ina3221_data *ina, u32 attr, + int channel, long val) { - struct ina3221_data *ina =3D dev_get_drvdata(dev); struct ina3221_input *input =3D ina->inputs; u8 reg =3D ina3221_curr_reg[attr][channel]; int resistance_uo, current_ma, voltage_uv; @@ -744,6 +805,22 @@ static int ina3221_write_curr(struct device *dev, u32 = attr, return regmap_write(ina->regmap, reg, regval); } =20 +static int ina3221_write_curr(struct device *dev, u32 attr, + int channel, long val) +{ + struct ina3221_data *ina =3D dev_get_drvdata(dev); + + switch (attr) { + case hwmon_curr_crit: + case hwmon_curr_max: + return ina3221_write_curr_shunt(ina, attr, channel, val); + case hwmon_curr_lcrit: + return sq52210_alert_limit_write(ina, SQ52210_ALERT_SUL, channel, val); + default: + return 0; + } +} + static int ina3221_write_enable(struct device *dev, int channel, bool enab= le) { struct ina3221_data *ina =3D dev_get_drvdata(dev); @@ -792,6 +869,22 @@ static int ina3221_write_enable(struct device *dev, in= t channel, bool enable) return ret; } =20 +static int ina3221_write_in(struct device *dev, u32 attr, int channel, lon= g val) +{ + struct ina3221_data *ina =3D dev_get_drvdata(dev); + + switch (attr) { + case hwmon_in_lcrit: + return sq52210_alert_limit_write(ina, SQ52210_ALERT_BUL, channel, val); + case hwmon_in_crit: + return sq52210_alert_limit_write(ina, SQ52210_ALERT_BOL, channel, val); + case hwmon_in_enable: + return ina3221_write_enable(dev, channel, val); + default: + return 0; + } +} + static int ina3221_write_power(struct device *dev, u32 attr, int channel, = long val) { struct ina3221_data *ina =3D dev_get_drvdata(dev); @@ -841,7 +934,7 @@ static int ina3221_write(struct device *dev, enum hwmon= _sensor_types type, break; case hwmon_in: /* 0-align channel ID */ - ret =3D ina3221_write_enable(dev, channel - 1, val); + ret =3D ina3221_write_in(dev, attr, channel - 1, val); break; case hwmon_curr: ret =3D ina3221_write_curr(dev, attr, channel, val); --=20 2.17.1