From patchwork Tue May 14 09:22:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Delphine CC Chiu X-Patchwork-Id: 13663899 Received: from APC01-PSA-obe.outbound.protection.outlook.com (mail-psaapc01on2052.outbound.protection.outlook.com [40.107.255.52]) (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 CAFD1537FF; Tue, 14 May 2024 09:22:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.255.52 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715678574; cv=fail; b=uLqnfCXTbmy+qTbaAsCg5R+0Lpa9c6XC87SDoo2fZE7MF4MtRb0eQByt19V1POE2yvRimrzZ3+eKdXvCV0PM/EjcWiVVr1+3nfU+oTmBUpdOs2DNwkM3fTR9WFpGLwbY887FEK+KKT6vij+CEhxNrRM0MKq374lN+VnGCxm444A= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715678574; c=relaxed/simple; bh=MMdhuDHz3q7n2UdBy+o6QjLOutATyAMtgB4XaFAoc0Y=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Content-Type; b=kD+h8pay8qva+m/CfKWd/YugkTg+sINs2ieDOCU1MYtSvcRUnUHd6fHe27BHTvB0VAsM1cNqE+ru+RJsi9cP9zXg9wM2CGO30fjIJL5M3uHZfZRnr2WXsDLOFM71zZLnoyrgvX/59oC2r+l7vF+85gy1FU4OUTXGzOoT7QhsaAM= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wiwynn.com; spf=pass smtp.mailfrom=wiwynn.com; dkim=pass (2048-bit key) header.d=wiwynn.com header.i=@wiwynn.com header.b=RHocDRCL; arc=fail smtp.client-ip=40.107.255.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wiwynn.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wiwynn.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wiwynn.com header.i=@wiwynn.com header.b="RHocDRCL" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mkS0loKnkBpJfuge5E30EQ4RRWEELugj1rf3r4qmw7TpMsppCBdvAoIy21xmZNGtw87OhC+RS6pTnKV9nsGZx5lSBASfqw/hfB2rXeKybHclkCMr9PwAzdmVMZNrzNcUQ7x12Jd7c3r6ddUBZ35kjg2z24i8sv4s1uHbahaBZ2wbtAoGiLGIZsqHBMldIaaJB0TUxpypBx9B8Jd+zc2i675hGUC+hS7yxfpbmWEzUYjZROFsuJ9NDMEJHFInieJyrrENxin97B9PFuy9CwB1of4Qs0qyaLhyVFMO1uKrfbmYVTihoP3dMJqDWT8PUP2ZBI3doWu4HUbrMqKzF0O26w== 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=4ERQ1A6ZjlFfEEZPsxOc3FefacY8EY6BhaM+pjLt03g=; b=kM/rwpC+ibMINlYDs+TxYT2F5XR5tgC+cjSPsNx/1lkzZMwtcHNHiL2L7itR9imlSA5BlLTwAaFDqHd39QAsBTnHdEh73qAPVgh/vGDjK0hIbQX1VsTyla82ntxtvzxYbFwOECgn2w46HfCtHQos5xvm4f11Yo93wNq7pvrwVyJBJH3XH2+t7PLtjyOM5cfZi/ZoFukrBNd6Shx0+tXtuHP6EsNc1pUsIpB9vZeV4ubbfol/4yEHiNeylcAzXZ+8kFVe6qzyBCY2OLdHoL9cThaiURGHEeoTRNFHu1voYnEDkeyLhxFg/8xomQw/JYImobadgAyNLH+YyMt0sB9jOw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=fail (sender ip is 211.20.1.79) smtp.rcpttodomain=stwcx.xyz smtp.mailfrom=wiwynn.com; dmarc=fail (p=quarantine sp=quarantine pct=100) action=quarantine header.from=wiwynn.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wiwynn.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=4ERQ1A6ZjlFfEEZPsxOc3FefacY8EY6BhaM+pjLt03g=; b=RHocDRCL07GllcyvhHcETu1b8hgYG8PYyoeedyh0dGogWRDnQfRSAiWgVCwm7fRCoOp0ekIWigz5IJmZTPcnwXLNPZ6TMqkuN2hUaFLKy6BX4PDz7CJBjTKLZQKaQr8bIbAiX7rdHZ4+KWeoYJwMnq3Fb6W20DErG9kbDWjfmFj2lgOb/ShLYIomFtimbXD30UCwFxwcRdy6yS3oXKTNFvsTvQl3Rr5RpFVW4SJ3MbuuXU3sRtpFm0UMYe+Nikh2a/LOMnTz02BDinyzgFqXHCySOPuuABB0ixBcW1FDFfE19KL9cswVZ/uVVHBBlwr/M020+6RCCQRbdDOHrtlxAA== Received: from SG2PR02CA0051.apcprd02.prod.outlook.com (2603:1096:4:54::15) by JH0PR04MB8108.apcprd04.prod.outlook.com (2603:1096:990:a2::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.55; Tue, 14 May 2024 09:22:48 +0000 Received: from HK2PEPF00006FB3.apcprd02.prod.outlook.com (2603:1096:4:54:cafe::9) by SG2PR02CA0051.outlook.office365.com (2603:1096:4:54::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.55 via Frontend Transport; Tue, 14 May 2024 09:22:47 +0000 X-MS-Exchange-Authentication-Results: spf=fail (sender IP is 211.20.1.79) smtp.mailfrom=wiwynn.com; dkim=none (message not signed) header.d=none;dmarc=fail action=quarantine header.from=wiwynn.com; Received-SPF: Fail (protection.outlook.com: domain of wiwynn.com does not designate 211.20.1.79 as permitted sender) receiver=protection.outlook.com; client-ip=211.20.1.79; helo=localhost.localdomain; Received: from localhost.localdomain (211.20.1.79) by HK2PEPF00006FB3.mail.protection.outlook.com (10.167.8.9) with Microsoft SMTP Server id 15.20.7587.21 via Frontend Transport; Tue, 14 May 2024 09:22:46 +0000 From: Delphine CC Chiu To: patrick@stwcx.xyz Cc: Delphine CC Chiu , Jean Delvare , Guenter Roeck , linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] hwmon: Add support for ina233 Date: Tue, 14 May 2024 17:22:40 +0800 Message-Id: <20240514092242.2739662-1-Delphine_CC_Chiu@wiwynn.com> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: HK2PEPF00006FB3:EE_|JH0PR04MB8108:EE_ X-MS-Office365-Filtering-Correlation-Id: 6c99bb41-a955-47a3-34f1-08dc73f76af5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|82310400017|36860700004|376005|1800799015; X-Microsoft-Antispam-Message-Info: =?utf-8?q?oT4AiElZMsiTBIMB3+4fPVsQU9cjJXi?= =?utf-8?q?5Mb/jsXlRI5cgkhHvtFsXIFir3oO6FeKpTt8xJpxIclo9ygJnHidWtpqGcRvWvM2c?= =?utf-8?q?GlDiUXY968mtQoCnwp4kTWBDBAlAWlB3bwvPF7llm4NPw9qJOj97535KjfvM0vRqh?= =?utf-8?q?QrIIHYX/FUgeTMQKtQxKyNF0WDpg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ptlfn8K/naYqVzvCjBUQADLE6bWEaMYQWp30mtX?= =?utf-8?q?e0IfLNz+5/8naH7PWR4sDw631DS7YuT8UIS3qSjkHCkEgs6od4xK523izW2wXolFm?= =?utf-8?q?mDWRiLNESWhm6UEpQS1/1bRi+yMbg3105hEpgIZmD7YSwXgxiiJLErSThfdy8qSHt?= =?utf-8?q?160GcgRlyp5+wp+M4wHh5y6+VYJVmagdR3pukr1HWOO0KlldEqORpTEoAMJi0fLAA?= =?utf-8?q?NiIhUAb/AHgBTK4VqwGsrKRNuP27MVeVHREO5RqBTelFcREpCPbI5TnK9Z7MDTFfl?= =?utf-8?q?wy5fglNvFAbq?= X-Forefront-Antispam-Report: CIP:211.20.1.79;CTRY:TW;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:localhost.localdomain;PTR:211-20-1-79.hinet-ip.hinet.net;CAT:NONE;SFS:(13230031)(82310400017)(36860700004)(376005)(1800799015);DIR:OUT;SFP:1101; X-OriginatorOrg: wiwynn.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 May 2024 09:22:46.7088 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6c99bb41-a955-47a3-34f1-08dc73f76af5 X-MS-Exchange-CrossTenant-Id: da6e0628-fc83-4caf-9dd2-73061cbab167 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=da6e0628-fc83-4caf-9dd2-73061cbab167;Ip=[211.20.1.79];Helo=[localhost.localdomain] X-MS-Exchange-CrossTenant-AuthSource: HK2PEPF00006FB3.apcprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: JH0PR04MB8108 Support ina233 with vshunt Signed-off-by: Delphine CC Chiu --- drivers/hwmon/pmbus/ina233.c | 37 +++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/drivers/hwmon/pmbus/ina233.c b/drivers/hwmon/pmbus/ina233.c index d5c7d7408ac3..33736e5049a9 100644 --- a/drivers/hwmon/pmbus/ina233.c +++ b/drivers/hwmon/pmbus/ina233.c @@ -11,9 +11,43 @@ #include #include #include +#include #include "pmbus.h" #define MFR_CALIBRATION 0xd4 +#define MFR_READ_VSHUNT 0xd1 + +#define HIGHEST_BIT 15 + +static ssize_t ina233_vshunt_show(struct device *dev, + struct device_attribute *devattr, char *buf) +{ + int shunt_volt; + struct i2c_client *client = to_i2c_client(dev->parent); + + shunt_volt = i2c_smbus_read_word_data(client, MFR_READ_VSHUNT); + if (shunt_volt < 0) + return shunt_volt; + + // Is negative + if (shunt_volt & (1 << HIGHEST_BIT)) + shunt_volt = ~(shunt_volt & ~(1 << HIGHEST_BIT)) + 1; + + // This unit is mV. + // LSB 2.5 μV is reference from spec 7.6.3.2 MFR_READ_VSHUNT + int val = DIV_ROUND_UP(shunt_volt * 25, 10000); + + return sysfs_emit(buf, "%d\n", val); +} + +static SENSOR_DEVICE_ATTR_RO(vshunt, ina233_vshunt, 1); + +static struct attribute *ina233_attrs[] = { + &sensor_dev_attr_vshunt.dev_attr.attr, + NULL, +}; + +ATTRIBUTE_GROUPS(ina233); struct pmbus_driver_info ina233_info = { .pages = 1, @@ -29,6 +63,7 @@ struct pmbus_driver_info ina233_info = { .m[PSC_VOLTAGE_OUT] = 8, .R[PSC_VOLTAGE_IN] = 2, .R[PSC_VOLTAGE_OUT] = 2, + .groups = ina233_groups, }; static int ina233_probe(struct i2c_client *client) @@ -82,7 +117,7 @@ static struct i2c_driver ina233_driver = { module_i2c_driver(ina233_driver); -MODULE_AUTHOR("Eli Huang "); +MODULE_AUTHOR("Delphine_CC_Chiu "); MODULE_DESCRIPTION("PMBus driver for Texas Instruments INA233 and compatible chips"); MODULE_LICENSE("GPL"); MODULE_IMPORT_NS(PMBUS);