From patchwork Tue Jun 11 09:36:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amna Waseem X-Patchwork-Id: 13693361 Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-db3eur04on2053.outbound.protection.outlook.com [40.107.6.53]) (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 D3B9617623D; Tue, 11 Jun 2024 09:36:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.6.53 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718098597; cv=fail; b=WMuQ0izuqlIfStOb1VztvfugaasATKYVdUqlUvZtwQRayv1xH/aEvgtg21Pa8/cDakfVRVq8QRE6mR80F+9/36au5wzGG70SOOH1nUpwtn8+GraEnKyuIMhBMNZNYqPoawVPzZipG/tvfVT2gaENWe9MrlxgSOG7wwPR1HDQm/I= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718098597; c=relaxed/simple; bh=/pLFLvsmTvstIusxiLOXn00gR8P/rtdCps+6C+6HuYg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-ID:References: In-Reply-To:To:CC; b=eqqXtY5nB5P+GoQVMooM953JllJo4H5oGSxt1+Km3+Y65kwYwAGYSoASRd/8U2o0oMGCZNEOFmYPQvUe16nNqVH4PDGCRNvGSOEtn/eQd/NRZvW0ZyO29pip9qzT8F/Qfl04wOkpTKFNHW2EeDu+C698M4xGbjjGwCIp987ZJG0= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=axis.com; spf=pass smtp.mailfrom=axis.com; dkim=pass (1024-bit key) header.d=axis.com header.i=@axis.com header.b=H0m8tWyo; arc=fail smtp.client-ip=40.107.6.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=axis.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=axis.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=axis.com header.i=@axis.com header.b="H0m8tWyo" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Anx5OQVF0fyeM6yWOZzTEiQcqJCXyXvot60Kt7rooK/awQsgthwZWwqzxj47TN65HnMqvplYl81g5GGHSx2qy7169nn0bgEjLjAXs0MM2ZzBsG31mI6pCltNqc8azOop91025aymArHaktMq/8mV4GdTm8somMfhvVrhVmo7V0Dog5YQWQDOJ5Zm0DugELzgptO7OB/C6D0w1jXwB0z45/GXIEt+fE31UC/a/afBOzsz6HfO9ppg44iokEShNNHGNxmsU/IQELJBqwPZtWGIBBKmwB5eH3H5PYSJLd8R4kc9kbQhbCxzO7nv4k794Wa/DSS1h1v4s+9kn0Ewip4X9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=3LISKJW0Ft8RRdvxUOaTd+tMKHmGv1hfXEUZAakyH90=; b=SBc0tkCXseq9/93zMuwOHrPg3+qYwmkVZPlIRoTNlYOc2HXxGGCS+IQiHHXsGsp0izTAKl0B5EJ2Xy0Fw59xyaANoN51Idi0+M8hC9ZNOGBvme20Uf0tpdYTHJR1Q9YOIsHGUgcH4onm8VzItTHnhh9V8N1LYEWJpjXxrxMQTt/MszCTrgtVWt3cgHHUdKFZ+1AGXRgHKYn/bZ/YYHHvYnGxoSBeQyvJRlrzVJiKNwEBNVjcaPSINJ9mRqSL5ckd7d+SP9U0ne3aSVpwKAO5j5TsfQ1pJYaSCGkkRSUxXGGWB8L2FEqPS7JD880dc+XNzhrByvZPTsr7IDkjVzA/GQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 195.60.68.100) smtp.rcpttodomain=kernel.org smtp.mailfrom=axis.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=axis.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axis.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=3LISKJW0Ft8RRdvxUOaTd+tMKHmGv1hfXEUZAakyH90=; b=H0m8tWyoM0z0m2qQvbuPWIho/4j5gjHuvtSCGBerGxVIdXefRQ5TAAPKhdjiqrVE50FPalfQWT29DQ8qY9tN8TfUfKazfUr+HQXd10+umMC7iYym073y5Bs9o/Ig6ZqBeTyAj7AKoY1XsjQVhQMJnsyBKs3NLYI+w4h/XJFJ2Uo= Received: from DUZPR01CA0175.eurprd01.prod.exchangelabs.com (2603:10a6:10:4b3::19) by PA4PR02MB8193.eurprd02.prod.outlook.com (2603:10a6:102:272::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.36; Tue, 11 Jun 2024 09:36:30 +0000 Received: from DB1PEPF000509ED.eurprd03.prod.outlook.com (2603:10a6:10:4b3:cafe::41) by DUZPR01CA0175.outlook.office365.com (2603:10a6:10:4b3::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7656.27 via Frontend Transport; Tue, 11 Jun 2024 09:36:25 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 195.60.68.100) smtp.mailfrom=axis.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=axis.com; Received-SPF: Pass (protection.outlook.com: domain of axis.com designates 195.60.68.100 as permitted sender) receiver=protection.outlook.com; client-ip=195.60.68.100; helo=mail.axis.com; pr=C Received: from mail.axis.com (195.60.68.100) by DB1PEPF000509ED.mail.protection.outlook.com (10.167.242.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7677.15 via Frontend Transport; Tue, 11 Jun 2024 09:36:28 +0000 Received: from se-mail02w.axis.com (10.20.40.8) by se-mail01w.axis.com (10.20.40.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Tue, 11 Jun 2024 11:36:28 +0200 Received: from se-intmail01x.se.axis.com (10.0.5.60) by se-mail02w.axis.com (10.20.40.8) with Microsoft SMTP Server id 15.1.2507.39 via Frontend Transport; Tue, 11 Jun 2024 11:36:28 +0200 Received: from lnxamnaw.se.axis.com (unknown [10.92.129.190]) by se-intmail01x.se.axis.com (Postfix) with ESMTP id 4A6D4574A; Tue, 11 Jun 2024 11:36:28 +0200 (CEST) Received: by lnxamnaw.se.axis.com (Postfix, from userid 12778) id 47A90207290; Tue, 11 Jun 2024 11:36:28 +0200 (CEST) From: Amna Waseem Date: Tue, 11 Jun 2024 11:36:26 +0200 Subject: [PATCH v4 2/2] hwmon: (ina2xx) Add device tree support to pass alert polarity Precedence: bulk X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <20240611-apol-ina2xx-fix-v4-2-8df1d2282fc5@axis.com> References: <20240611-apol-ina2xx-fix-v4-0-8df1d2282fc5@axis.com> In-Reply-To: <20240611-apol-ina2xx-fix-v4-0-8df1d2282fc5@axis.com> To: Jean Delvare , Guenter Roeck , "Rob Herring" , Krzysztof Kozlowski , "Conor Dooley" CC: Krzysztof Kozlowski , , , , Amna Waseem , X-Mailer: b4 0.13.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB1PEPF000509ED:EE_|PA4PR02MB8193:EE_ X-MS-Office365-Filtering-Correlation-Id: e9baa9c4-bf86-4c2b-2951-08dc89f9f893 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|82310400017|1800799015|376005|36860700004; X-Microsoft-Antispam-Message-Info: =?utf-8?q?dmA+ZgKiKRWuMxhQLp+WHL2WTzx73dO?= =?utf-8?q?MwiP0QbyG+/7qAZPjDRPl4b2O7dsDTPfGvsYla0bVf6ZBsX6g/VfZhLP16WEZfIrV?= =?utf-8?q?fOMm4uFG5zF5tOKMgeOFlvmILm4PJKSpUCTQquLWGgDKFyAexvBYytebB22dojImN?= =?utf-8?q?Fm8O2enVHpHAgQVyziS5pI7WTSL/j3liUBR/lQD0XAihckjEiMqpjz1hbCDx+Lifd?= =?utf-8?q?ZctHOWddHHZNDB0lZzjyE9Ez+y5TTu6r8iXgMYi+Ks9/cW3WfyM+YSqPJltAfoSRa?= =?utf-8?q?yEvZ+o2tkLkyqki8KZ+5CeQnY4kYvL7oyJ7e2Hw+IH6p8jlA9cQe2bFLfHXLF9x3Y?= =?utf-8?q?MQ6PPum0o8dNbtk3O1l+5/S5YH0ocsI3w2/8zOrF2zV0FanMTUxNsxPvbVBLbQGxb?= =?utf-8?q?Sc2ZBm5GjDOiL640x9M8jg2hqbQrHRhavFzPlriGi2Nov4E2kgDZmLIkD/7CkPPAr?= =?utf-8?q?QOlRoFiVcs7lwCeccoWXJ9Wd4vjUNrXbGkbvWCvbWfDaiqmU0MHQaav9RfhHS5JyM?= =?utf-8?q?GsGCC7cJCpiSsg7yUdzo49PvXKdeKtdAS0h+IMa4nA0aIsDok1jGA0c5RqqgR5YNl?= =?utf-8?q?UwmozkkQIZ53G0QgGbv272m6wJ2QoSlG3kVcpWcMQcppp3h5sgvhcTGzHdH9Y46lF?= =?utf-8?q?Grc8kfUEMi2PUVj+CCtfSlak9mIcvnEnT345COc8EwwaCzwlDJ1ThznGRoH/gTQU1?= =?utf-8?q?4XFsbr0iLvMybjCKxO+r7jhohnrQaeosUXx1FGjHcfZ6T9lHCeoZOLiX01rcRZSqb?= =?utf-8?q?Nf+d9TqwfkK9NE2a4GcEED8+Bo7FXMw0V7uk+YXtpiRqful+3wIMj1SBrVzzvy1i9?= =?utf-8?q?Eyd3CnkJWtJlFgBre3XhwaZtRy96JKqSnVjYQdHIatJO2fuIU2+el0zWI+3umahhI?= =?utf-8?q?o9z+WsXd6c2AADuIm0UDXCJO1dv7wpMbgA1SbyekimkJn83+WyY9gY9MB+iLRzUeO?= =?utf-8?q?9CtcjBeQbK7/gkRSeX2Ere7eqMWqDQawEZr4UA+MrqeUoCAqGCwqWtTNdNaFUiPAz?= =?utf-8?q?UQJZrnqZQx2ABFf5m06hNBx9JIqYg8cuiewi6DjY5o7HJO2dTh3heUK35kLpOIAT+?= =?utf-8?q?gBHLQU7ZWG42wwCMDOs3EP7+2q6WTiEMu2oU7h4dPE9rRTbDvPNPSTAO5lEaDExzT?= =?utf-8?q?Z4UjT4wvUzLqvGjeNMOaAMhz54rwsXBTuZSIgTwhWIHZn00QChSfCwV9cjOdAc2QK?= =?utf-8?q?p8REGNhHpRw6Mup79qjZRpwjH4w466uFW7ZqJtbTLCjLOtX+DcgHGZTaiGJlBStrl?= =?utf-8?q?iO+B5/27JnGVRqkZ/fVqRu/WGEzAn3EJ/Yk/hjL/G+RGapsweQATtuuwOZiCNyOg1?= =?utf-8?q?96hF1LFApwox+oeFEe4nlGBIO9Hdy4rlMw=3D=3D?= X-Forefront-Antispam-Report: CIP:195.60.68.100;CTRY:SE;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.axis.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(82310400017)(1800799015)(376005)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: axis.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Jun 2024 09:36:28.9243 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e9baa9c4-bf86-4c2b-2951-08dc89f9f893 X-MS-Exchange-CrossTenant-Id: 78703d3c-b907-432f-b066-88f7af9ca3af X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=78703d3c-b907-432f-b066-88f7af9ca3af;Ip=[195.60.68.100];Helo=[mail.axis.com] X-MS-Exchange-CrossTenant-AuthSource: DB1PEPF000509ED.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR02MB8193 The INA230 has an Alert pin which is asserted when the alert function selected in the Mask/Enable register exceeds the value programmed into the Alert Limit register. Assertion is based on the Alert Polarity Bit (APOL, bit 1 of the Mask/Enable register). It is default set to value 0 i.e Normal (active-low open collector). However, hardware can be designed in such a way that expects Alert pin to become active high if a user-defined threshold in Alert limit register has been exceeded. This patch adds a way to pass alert polarity value to the driver via device tree. Signed-off-by: Amna Waseem --- drivers/hwmon/ina2xx.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/drivers/hwmon/ina2xx.c b/drivers/hwmon/ina2xx.c index d8415d1f21fc..f26ba479bf5c 100644 --- a/drivers/hwmon/ina2xx.c +++ b/drivers/hwmon/ina2xx.c @@ -73,6 +73,11 @@ #define INA226_READ_AVG(reg) (((reg) & INA226_AVG_RD_MASK) >> 9) #define INA226_SHIFT_AVG(val) ((val) << 9) +#define INA226_ALERT_POLARITY_MASK 0x0002 +#define INA226_SHIFT_ALERT_POLARITY(val) ((val) << 1) +#define INA226_ALERT_POL_LOW 0 +#define INA226_ALERT_POL_HIGH 1 + /* bit number of alert functions in Mask/Enable Register */ #define INA226_SHUNT_OVER_VOLTAGE_BIT 15 #define INA226_SHUNT_UNDER_VOLTAGE_BIT 14 @@ -178,6 +183,14 @@ static u16 ina226_interval_to_reg(int interval) return INA226_SHIFT_AVG(avg_bits); } +static int ina2xx_set_alert_polarity(struct ina2xx_data *data, + unsigned long val) +{ + return regmap_update_bits(data->regmap, INA226_MASK_ENABLE, + INA226_ALERT_POLARITY_MASK, + INA226_SHIFT_ALERT_POLARITY(val)); +} + /* * Calibration register is set to the best value, which eliminates * truncation errors on calculating current register in hardware. @@ -659,6 +672,25 @@ static int ina2xx_probe(struct i2c_client *client) if (ret) return dev_err_probe(dev, ret, "failed to enable vs regulator\n"); + if (chip == ina226) { + if (of_property_read_bool(dev->of_node, "ti,alert-polarity-active-high")) { + ret = ina2xx_set_alert_polarity(data, + INA226_ALERT_POL_HIGH); + if (ret < 0) { + return dev_err_probe(dev, ret, + "failed to set alert polarity active high\n"); + } + } else { + /* Set default value i.e active low */ + ret = ina2xx_set_alert_polarity(data, + INA226_ALERT_POL_LOW); + if (ret < 0) { + return dev_err_probe(dev, ret, + "failed to set alert polarity active low\n"); + } + } + } + ret = ina2xx_init(data); if (ret < 0) { dev_err(dev, "error configuring the device: %d\n", ret);