From patchwork Fri Sep 6 06:14:16 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: 13793342 Received: from APC01-PSA-obe.outbound.protection.outlook.com (mail-psaapc01on2042.outbound.protection.outlook.com [40.107.255.42]) (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 25C9F12CDBF; Fri, 6 Sep 2024 06:14:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.255.42 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725603298; cv=fail; b=ksfDu+xX1j2+JmSvurLfQNvAXj0ars6TnkTk6RXfKYQTJmF027tNCSZABLrl9cjZT6yS4YzTjZP2wzoswVhEme/5j0pl4bquE6C83MVQQGGdzHnt8M8svhVSb914nmqg3S+hJCSyQEFPzDmVPjEONpCXeCssb6glIOgZoXbtNX4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725603298; c=relaxed/simple; bh=KXJ3sx2SMSQUXAA6dYszmvDTZTWlzrzxgUlyFJDTLXQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=ISfH/YhaF3W5hxH+23TFaRbLCFfr5kuZX6gjNeqa/xQygCBEj3J5sCF2Ge6U+20Ja+/RmruObQiFX8DfG2aEM5RTO/KLpQNToPDqZmJYIlUXbLL30V1D+i8Uey1cGRYSu5L1oxDDS4/9COauw8O7O6H3HxYaRL2qw9IxXQ7xkeI= 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=G6XpT2Bp; arc=fail smtp.client-ip=40.107.255.42 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="G6XpT2Bp" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=NieXIwEdvy5XXlUFMfYgqz7K9neJFb7yfBTWKaoXEyjTiRkP22o4F2nIvk1wQQkhNyY+Rxxl9J96nc7OjBiydyl1OnQNq2YauhvmrpMhb1c1qkb4sKe0ViK87f4wcJT5cMhkfIrrfpHEYKKZaFY50bR2kKthWiGX5dlVEea7UzVVwYBrLIxSv8QtTtlj8uHEMPosyu9fI4/5WiVXvoizaNnuYRAHdyXt0kfBHKvfYTzCl9d3oRHFBI+iZn8f5p6rD6ZoNNO1JqFDB93TyQw3jZTW+xPon2TJS7EwAwVsWk2Lj5DxymYFY0/1NwbjxYbRRvmknW0fpvdAgTt362ZaSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=y7ucJlfrlg+2C/BO13Tzapl5mJ5uI4gnw8ddYiin3aY=; b=HmvgRcZ16hsPLwJQtoWP3g5moalnERAygQwQCp3ZZvfao5AFrRzLjgrtjZU0i1kqPUU0GhfugGUa+geFwieY144NQgRxKusRpTr9WIJtnj6ppJvbRFeGj2mLSn0TKkijjNVoP8IgfZqaiax71SJ1gYRnoKXpDf1sSR2poPVE44xhoZuG6Ex/m+uF05mDkOiwFk5zcSwEwOyhn754XpVBaeRhuCPm5PA18VyHKMhSfy44V4NnX3Q/cO/7Js1UH33S7l3AehzHBhTdGBSfcNK0OQFHqpXsIOF4B1gmvKc8f7jrKcPH0b1tK4X2J1e5D6dTokfPYv0aePYWzZRpD8dqOQ== 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=y7ucJlfrlg+2C/BO13Tzapl5mJ5uI4gnw8ddYiin3aY=; b=G6XpT2BpqFH++n2iju806hbVoJPlR64shD16Z7DTHOJIEA3GJ/mhXU/27dYUfQdMxePz0IIYuCYIAKeDppEP5uTN1scBk5J2ir4hYdQ6WJtq1yGvS1op/xN5VpfZHN2+/NkOoKsOW0qsQIcbUOKkhKObI81A0sbtNa3rNKB9Arj9mYpfvf+lAzAZPy9KAjiWUv5EYHOZb3W4XICZogsOIBfDYL1z1clnqEg2RnRCsFLYq44TJJPjTskrzB4DXralcZ7ftu89bxp2TJs0iEUaUIBNcZrwciP2IpRP5d6yjWtef/p6i5sKo5O6iiIeJeGqOMkstsVOd1ZEHXpUU68q+g== Received: from PS2PR01CA0031.apcprd01.prod.exchangelabs.com (2603:1096:300:58::19) by JH0PR04MB7252.apcprd04.prod.outlook.com (2603:1096:990:37::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.28; Fri, 6 Sep 2024 06:14:49 +0000 Received: from HK2PEPF00006FB3.apcprd02.prod.outlook.com (2603:1096:300:58:cafe::df) by PS2PR01CA0031.outlook.office365.com (2603:1096:300:58::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.17 via Frontend Transport; Fri, 6 Sep 2024 06:14:49 +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.7918.13 via Frontend Transport; Fri, 6 Sep 2024 06:14:48 +0000 From: Delphine CC Chiu To: patrick@stwcx.xyz, Jean Delvare , Guenter Roeck , Jonathan Corbet , =?utf-8?q?Carsten_Spie=C3=9F?= , Geert Uytterhoeven , Magnus Damm Cc: Rob Herring , Krzysztof Kozlowski , Conor Dooley , linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-renesas-soc@vger.kernel.org Subject: [PATCH v6 1/3] hwmon: (isl28022) new driver for ISL28022 power monitor Date: Fri, 6 Sep 2024 14:14:16 +0800 Message-Id: <20240906061421.9392-2-Delphine_CC_Chiu@wiwynn.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240906061421.9392-1-Delphine_CC_Chiu@wiwynn.com> References: <20240906061421.9392-1-Delphine_CC_Chiu@wiwynn.com> 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_|JH0PR04MB7252:EE_ X-MS-Office365-Filtering-Correlation-Id: b0956ca9-daaa-4619-18fc-08dcce3b366e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|7416014|376014|82310400026|1800799024; X-Microsoft-Antispam-Message-Info: =?utf-8?q?gmj4SjsmAcOHeap0Hfua1ut/bIALXJ4?= =?utf-8?q?KWB//I+Xb2zZBa6HVuJu9Cvq4mwMHd/u6hjCN4xFc2o2gcWlAjtPwMH79wWWzQqNT?= =?utf-8?q?tQCBoVJrTMYXnbXjmqk7WpdL4ktgrPhI3dQAnEFjuaxAEs+KeV8X9ZuASnfk5782v?= =?utf-8?q?fLlVRtTENEfaI8zURnQG/9BVJdKaLracFGW0CVWzxZDXPDJcmjqlY6GXOYUaASETN?= =?utf-8?q?Vhvjcs5AM+rwIDE3NIxLlE7CRX6H8jIuuNATCSpO305MVV0UOwG+KdVDkP1gqgrvE?= =?utf-8?q?UUfM+21rGmEiIym73lCZe882rb0id7hkceyYWbNq6bgxSBBQy/loYEtIg9U9LLnkS?= =?utf-8?q?qEz/IF+jjLQj5q9NpNYB6ehu0eCAWkzfK7obRU4lZCxmQDICNwbiexzBBc3XEJKht?= =?utf-8?q?TUWXrfFGJuxYTNy9e656MP1hWfW7Jy9MbgVq3/xdAFIDXUmxHq4zcYVZTykma4beF?= =?utf-8?q?hUqJEz9dK7I9VSfRrkUnSsPE7g7u9OC7C0nb6FeTHAyK6ojYuQRxpUetzZZad/awN?= =?utf-8?q?5TTljOWMrRU2+fIZsQxTpzqnouGkISCK5hlrULIuJnKFkER5jeyJhBhaVhl0Pcecm?= =?utf-8?q?oxFq3YWWTRTE7DGwzm4WxXzKFqr3KUFvCVOOkyc7eskl309qpoM2o9PM8PLXmawkg?= =?utf-8?q?SvH3JdnSmsgRbGuOTKPTyWzmRBCdi4/bhHSYpJUGVvysd3o2GBs3UdIlNdPGhpEmm?= =?utf-8?q?RGuUuwKq5EST9PHaMtGXnrqe/X3oAtGsJgwkVLYuINIV987BuxK4MdmNVtfGwkz5L?= =?utf-8?q?MaaA+7qpPozFussPN7qOxbk3A4i52GMiD44UH3gJSU2v0I40mszF+TOS2T9jX7cF8?= =?utf-8?q?mrFx1m3yJ24Lf/ZU0C4hTbFb/P0/RLct+V/5E5i1wKciAfLevqCQiyfID6+qZmhz2?= =?utf-8?q?SvNPDGP0b/x+s6TJ9UhRU/Utqwf4spptaCGZ3r0k4zsNDV/wCvqZQJTxSeqZ15gz1?= =?utf-8?q?hXjGA4NBuhozPPgWiA5bNPMiksaqkrCJe6eVG4ZlKcyGAuIRxGzpFszhjIJf1dMZi?= =?utf-8?q?IqTrhNtLj78jpuFVmw0GWfko6ETc3tY2CDN1PS9F5OZttCI7zBv9CKc3VvAt9c5Qp?= =?utf-8?q?fB3bNuhHhdov6zi2p5rkgmeJ5nCJzQxUylvWjA6R2DgryVj0t2+UZOYTS4qLA//cx?= =?utf-8?q?0dZkiOcZ/Cpk6OVSYrzNdEVz/0hkRAj7D3XPfa+jHeqO0Yd0nzw25+cQpmq8r0ltf?= =?utf-8?q?Pa3UDskQliWBbPlcNQjKDciulSubawANZKibind3MBV4dNg7fINZHKJJE4+h2s7hY?= =?utf-8?q?Gsin16FYpkxsjjnqR97XCiWT+C75tveepfzE9Eq9f3MxyheaOTlMUaHdmdwKcDKMU?= =?utf-8?q?Q32sc7UCKHSkmuLekwAGG8vbprI80XfSbA=3D=3D?= 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:(13230040)(36860700013)(7416014)(376014)(82310400026)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: wiwynn.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Sep 2024 06:14:48.8532 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b0956ca9-daaa-4619-18fc-08dcce3b366e 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: JH0PR04MB7252 From: Carsten Spieß Driver for Renesas ISL28022 power monitor with I2C interface. The device monitors voltage, current via shunt resistor and calculated power. Signed-off-by: Carsten Spieß --- Documentation/hwmon/index.rst | 1 + Documentation/hwmon/isl28022.rst | 63 +++++ MAINTAINERS | 7 + drivers/hwmon/Kconfig | 11 + drivers/hwmon/Makefile | 1 + drivers/hwmon/isl28022.c | 471 +++++++++++++++++++++++++++++++ 6 files changed, 554 insertions(+) create mode 100644 Documentation/hwmon/isl28022.rst create mode 100644 drivers/hwmon/isl28022.c diff --git a/Documentation/hwmon/index.rst b/Documentation/hwmon/index.rst index 913c11390a45..ba297c43d902 100644 --- a/Documentation/hwmon/index.rst +++ b/Documentation/hwmon/index.rst @@ -96,6 +96,7 @@ Hardware Monitoring Kernel Drivers ir35221 ir38064 ir36021 + isl28022 isl68137 it87 jc42 diff --git a/Documentation/hwmon/isl28022.rst b/Documentation/hwmon/isl28022.rst new file mode 100644 index 000000000000..8d4422a2dacd --- /dev/null +++ b/Documentation/hwmon/isl28022.rst @@ -0,0 +1,63 @@ +.. SPDX-License-Identifier: GPL-2.0-or-later + +Kernel driver isl28022 +====================== + +Supported chips: + + * Renesas ISL28022 + + Prefix: 'isl28022' + + Addresses scanned: none + + Datasheet: Publicly available at the Renesas website + + https://www.renesas.com/us/en/www/doc/datasheet/isl28022.pdf + +Author: + Carsten Spieß + +Description +----------- + +The ISL28022 is a power monitor with I2C interface. The device monitors +voltage, current via shunt resistor and calculated power. + +Usage Notes +----------- + +This driver does not auto-detect devices. You will have to instantiate the +device explicitly. Please see Documentation/i2c/instantiating-devices.rst for +details. + +The shunt value in micro-ohms, shunt voltage range and averaging can be set +with device properties. +Please refer to the Documentation/devicetree/bindings/hwmon/isl,isl28022.yaml +for bindings if the device tree is used. + +The driver supports only shunt and bus continuous ADC mode at 15bit resolution. +Averaging can be set from 1 to 128 samples (power of 2) on both channels. +Shunt voltage range of 40, 80, 160 or 320mV is allowed +The bus voltage range is 60V fixed. + +Sysfs entries +------------- + +The following attributes are supported. All attributes are read-only. + +======================= ======================================================= +in0_input bus voltage (milli Volt) + +curr1_input current (milli Ampere) +power1_input power (micro Watt) +======================= ======================================================= + +Debugfs entries +--------------- + +The following attributes are supported. All attributes are read-only. + +======================= ======================================================= +shunt_voltage shunt voltage (micro Volt) +======================= ======================================================= diff --git a/MAINTAINERS b/MAINTAINERS index fe83ba7194ea..d39199ed51da 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -11932,6 +11932,13 @@ F: drivers/isdn/Makefile F: drivers/isdn/hardware/ F: drivers/isdn/mISDN/ +ISL28022 HARDWARE MONITORING DRIVER +M: Carsten Spieß +L: linux-hwmon@vger.kernel.org +S: Maintained +F: Documentation/hwmon/isl28022.rst +F: drivers/hwmon/isl28022.c + ISOFS FILESYSTEM M: Jan Kara L: linux-fsdevel@vger.kernel.org diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig index b60fe2e58ad6..adbbbb128afc 100644 --- a/drivers/hwmon/Kconfig +++ b/drivers/hwmon/Kconfig @@ -853,6 +853,17 @@ config SENSORS_CORETEMP sensor inside your CPU. Most of the family 6 CPUs are supported. Check Documentation/hwmon/coretemp.rst for details. +config SENSORS_ISL28022 + tristate "Renesas ISL28022" + depends on I2C + select REGMAP_I2C + help + If you say yes here you get support for ISL28022 power monitor. + Check Documentation/hwmon/isl28022.rst for details. + + This driver can also be built as a module. If so, the module + will be called isl28022. + config SENSORS_IT87 tristate "ITE IT87xx and compatibles" depends on HAS_IOPORT diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile index b1c7056c37db..51132b2b2c07 100644 --- a/drivers/hwmon/Makefile +++ b/drivers/hwmon/Makefile @@ -103,6 +103,7 @@ obj-$(CONFIG_SENSORS_INA2XX) += ina2xx.o obj-$(CONFIG_SENSORS_INA238) += ina238.o obj-$(CONFIG_SENSORS_INA3221) += ina3221.o obj-$(CONFIG_SENSORS_INTEL_M10_BMC_HWMON) += intel-m10-bmc-hwmon.o +obj-$(CONFIG_SENSORS_ISL28022) += isl28022.o obj-$(CONFIG_SENSORS_IT87) += it87.o obj-$(CONFIG_SENSORS_JC42) += jc42.o obj-$(CONFIG_SENSORS_K8TEMP) += k8temp.o diff --git a/drivers/hwmon/isl28022.c b/drivers/hwmon/isl28022.c new file mode 100644 index 000000000000..f0494c3bd483 --- /dev/null +++ b/drivers/hwmon/isl28022.c @@ -0,0 +1,471 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * isl28022.c - driver for Renesas ISL28022 power monitor chip monitoring + * + * Copyright (c) 2023 Carsten Spieß + */ + +#include +#include +#include +#include +#include +#include +#include + +/* ISL28022 registers */ +#define ISL28022_REG_CONFIG 0x00 +#define ISL28022_REG_SHUNT 0x01 +#define ISL28022_REG_BUS 0x02 +#define ISL28022_REG_POWER 0x03 +#define ISL28022_REG_CURRENT 0x04 +#define ISL28022_REG_CALIB 0x05 +#define ISL28022_REG_SHUNT_THR 0x06 +#define ISL28022_REG_BUS_THR 0x07 +#define ISL28022_REG_INT 0x08 +#define ISL28022_REG_AUX 0x09 +#define ISL28022_REG_MAX ISL28022_REG_AUX + +/* ISL28022 config flags */ +/* mode flags */ +#define ISL28022_MODE_SHIFT 0 +#define ISL28022_MODE_MASK 0x0007 + +#define ISL28022_MODE_PWR_DOWN 0x0 +#define ISL28022_MODE_TRG_S 0x1 +#define ISL28022_MODE_TRG_B 0x2 +#define ISL28022_MODE_TRG_SB 0x3 +#define ISL28022_MODE_ADC_OFF 0x4 +#define ISL28022_MODE_CONT_S 0x5 +#define ISL28022_MODE_CONT_B 0x6 +#define ISL28022_MODE_CONT_SB 0x7 + +/* shunt ADC settings */ +#define ISL28022_SADC_SHIFT 3 +#define ISL28022_SADC_MASK 0x0078 + +#define ISL28022_BADC_SHIFT 7 +#define ISL28022_BADC_MASK 0x0780 + +#define ISL28022_ADC_12 0x0 /* 12 bit ADC */ +#define ISL28022_ADC_13 0x1 /* 13 bit ADC */ +#define ISL28022_ADC_14 0x2 /* 14 bit ADC */ +#define ISL28022_ADC_15 0x3 /* 15 bit ADC */ +#define ISL28022_ADC_15_1 0x8 /* 15 bit ADC, 1 sample */ +#define ISL28022_ADC_15_2 0x9 /* 15 bit ADC, 2 samples */ +#define ISL28022_ADC_15_4 0xA /* 15 bit ADC, 4 samples */ +#define ISL28022_ADC_15_8 0xB /* 15 bit ADC, 8 samples */ +#define ISL28022_ADC_15_16 0xC /* 15 bit ADC, 16 samples */ +#define ISL28022_ADC_15_32 0xD /* 15 bit ADC, 32 samples */ +#define ISL28022_ADC_15_64 0xE /* 15 bit ADC, 64 samples */ +#define ISL28022_ADC_15_128 0xF /* 15 bit ADC, 128 samples */ + +/* shunt voltage range */ +#define ISL28022_PG_SHIFT 11 +#define ISL28022_PG_MASK 0x1800 + +#define ISL28022_PG_40 0x0 /* +/-40 mV */ +#define ISL28022_PG_80 0x1 /* +/-80 mV */ +#define ISL28022_PG_160 0x2 /* +/-160 mV */ +#define ISL28022_PG_320 0x3 /* +/-3200 mV */ + +/* bus voltage range */ +#define ISL28022_BRNG_SHIFT 13 +#define ISL28022_BRNG_MASK 0x6000 + +#define ISL28022_BRNG_16 0x0 /* 16 V */ +#define ISL28022_BRNG_32 0x1 /* 32 V */ +#define ISL28022_BRNG_60 0x3 /* 60 V */ + +/* reset */ +#define ISL28022_RESET 0x8000 + +struct isl28022_data { + struct regmap *regmap; + u32 shunt; + u32 gain; + u32 average; + u16 config; + u16 calib; +}; + +static int isl28022_read(struct device *dev, enum hwmon_sensor_types type, + u32 attr, int channel, long *val) +{ + struct isl28022_data *data = dev_get_drvdata(dev); + unsigned int regval; + int err; + + switch (type) { + case hwmon_in: + switch (attr) { + case hwmon_in_input: + err = regmap_read(data->regmap, + ISL28022_REG_BUS, ®val); + if (err < 0) + return err; + /* driver supports only 60V mode (BRNG 11) */ + *val = (long)(((u16)regval) & 0xFFFC); + break; + default: + return -EINVAL; + } + break; + case hwmon_curr: + switch (attr) { + case hwmon_curr_input: + err = regmap_read(data->regmap, + ISL28022_REG_CURRENT, ®val); + if (err < 0) + return err; + *val = ((long)regval * 1250L * (long)data->gain) / + (long)data->shunt; + break; + default: + return -EINVAL; + } + break; + case hwmon_power: + switch (attr) { + case hwmon_power_input: + err = regmap_read(data->regmap, + ISL28022_REG_POWER, ®val); + if (err < 0) + return err; + *val = ((51200000L * ((long)data->gain)) / + (long)data->shunt) * (long)regval; + break; + default: + return -EINVAL; + } + break; + default: + return -EINVAL; + } + + return 0; +} + +static umode_t isl28022_is_visible(const void *data, enum hwmon_sensor_types type, + u32 attr, int channel) +{ + switch (type) { + case hwmon_in: + switch (attr) { + case hwmon_in_input: + return 0444; + default: + break; + } + break; + case hwmon_curr: + switch (attr) { + case hwmon_curr_input: + return 0444; + default: + break; + } + break; + case hwmon_power: + switch (attr) { + case hwmon_power_input: + return 0444; + default: + break; + } + break; + default: + break; + } + return 0; +} + +static const struct hwmon_channel_info *isl28022_info[] = { + HWMON_CHANNEL_INFO(in, + HWMON_I_INPUT), /* channel 0: bus voltage (mV) */ + HWMON_CHANNEL_INFO(curr, + HWMON_C_INPUT), /* channel 1: current (mA) */ + HWMON_CHANNEL_INFO(power, + HWMON_P_INPUT), /* channel 1: power (µW) */ + NULL +}; + +static const struct hwmon_ops isl28022_hwmon_ops = { + .is_visible = isl28022_is_visible, + .read = isl28022_read, +}; + +static const struct hwmon_chip_info isl28022_chip_info = { + .ops = &isl28022_hwmon_ops, + .info = isl28022_info, +}; + +static bool isl28022_is_writeable_reg(struct device *dev, unsigned int reg) +{ + switch (reg) { + case ISL28022_REG_CONFIG: + case ISL28022_REG_CALIB: + case ISL28022_REG_SHUNT_THR: + case ISL28022_REG_BUS_THR: + case ISL28022_REG_INT: + case ISL28022_REG_AUX: + return true; + } + + return false; +} + +static bool isl28022_is_volatile_reg(struct device *dev, unsigned int reg) +{ + switch (reg) { + case ISL28022_REG_CONFIG: + case ISL28022_REG_SHUNT: + case ISL28022_REG_BUS: + case ISL28022_REG_POWER: + case ISL28022_REG_CURRENT: + case ISL28022_REG_INT: + case ISL28022_REG_AUX: + return true; + } + return true; +} + +static const struct regmap_config isl28022_regmap_config = { + .reg_bits = 8, + .val_bits = 16, + .max_register = ISL28022_REG_MAX, + .writeable_reg = isl28022_is_writeable_reg, + .volatile_reg = isl28022_is_volatile_reg, + .val_format_endian = REGMAP_ENDIAN_BIG, + .cache_type = REGCACHE_RBTREE, + .use_single_read = true, + .use_single_write = true, +}; + +static const struct i2c_device_id isl28022_ids[] = { + { "isl28022", 0}, + { /* LIST END */ } +}; +MODULE_DEVICE_TABLE(i2c, isl28022_ids); + +static int shunt_voltage_show(struct seq_file *seqf, void *unused) +{ + struct isl28022_data *data = seqf->private; + unsigned int regval; + int err; + + err = regmap_read(data->regmap, + ISL28022_REG_SHUNT, ®val); + if (err) + return err; + + /* print shunt voltage in micro volt */ + seq_printf(seqf, "%d\n", regval * 10); + + return 0; +} +DEFINE_SHOW_ATTRIBUTE(shunt_voltage); + +static struct dentry *isl28022_debugfs_root; + +static void isl28022_debugfs_remove(void *res) +{ + debugfs_remove_recursive(res); +} + +static void isl28022_debugfs_init(struct i2c_client *client, struct isl28022_data *data) +{ + char name[16]; + struct dentry *debugfs; + + scnprintf(name, sizeof(name), "%d-%04hx", client->adapter->nr, client->addr); + + debugfs = debugfs_create_dir(name, isl28022_debugfs_root); + debugfs_create_file("shunt_voltage", 0444, debugfs, data, &shunt_voltage_fops); + + devm_add_action_or_reset(&client->dev, isl28022_debugfs_remove, debugfs); +} + +/* + * read property values and make consistency checks. + * + * following values for shunt range and resistor are allowed: + * 40 mV -> gain 1, shunt min. 800 micro ohms + * 80 mV -> gain 2, shunt min. 1600 micro ohms + * 160 mV -> gain 4, shunt min. 3200 micro ohms + * 320 mV -> gain 8, shunt min. 6400 micro ohms + */ +static int isl28022_read_properties(struct device *dev, struct isl28022_data *data) +{ + u32 val; + int err; + + err = device_property_read_u32(dev, "shunt-resistor-micro-ohms", &val); + if (err == -EINVAL) + val = 10000; + else if (err < 0) + return err; + data->shunt = val; + + err = device_property_read_u32(dev, "renesas,shunt-range-microvolt", &val); + if (err == -EINVAL) + val = 320000; + else if (err < 0) + return err; + + switch (val) { + case 40000: + data->gain = 1; + if (data->shunt < 800) + goto shunt_invalid; + break; + case 80000: + data->gain = 2; + if (data->shunt < 1600) + goto shunt_invalid; + break; + case 160000: + data->gain = 4; + if (data->shunt < 3200) + goto shunt_invalid; + break; + case 320000: + data->gain = 8; + if (data->shunt < 6400) + goto shunt_invalid; + break; + default: + dev_err(dev, "renesas,shunt-range-microvolt invalid value %d\n", val); + return -EINVAL; + } + + err = device_property_read_u32(dev, "renesas,average-samples", &val); + if (err == -EINVAL) + val = 1; + else if (err < 0) + return err; + if (val > 128 || hweight32(val) != 1) { + dev_err(dev, "renesas,average-samples invalid value %d\n", val); + return -EINVAL; + } + data->average = val; + + return 0; + +shunt_invalid: + dev_err(dev, "renesas,shunt-resistor-microvolt invalid value %d\n", data->shunt); + return -EINVAL; +} + +/* + * write configuration and calibration registers + * + * The driver supports only shunt and bus continuous ADC mode at 15bit resolution + * with averaging from 1 to 128 samples (pow of 2) on both channels. + * Shunt voltage gain 1,2,4 or 8 is allowed. + * The bus voltage range is 60V fixed. + */ +static int isl28022_config(struct isl28022_data *data) +{ + int err; + + data->config = (ISL28022_MODE_CONT_SB << ISL28022_MODE_SHIFT) | + (ISL28022_BRNG_60 << ISL28022_BRNG_SHIFT) | + (__ffs(data->gain) << ISL28022_PG_SHIFT) | + ((ISL28022_ADC_15_1 + __ffs(data->average)) << ISL28022_SADC_SHIFT) | + ((ISL28022_ADC_15_1 + __ffs(data->average)) << ISL28022_BADC_SHIFT); + + data->calib = data->shunt ? 0x8000 / data->gain : 0; + + err = regmap_write(data->regmap, ISL28022_REG_CONFIG, data->config); + if (err < 0) + return err; + + err = regmap_write(data->regmap, ISL28022_REG_CALIB, data->calib); + if (err < 0) + return err; + + return 0; +} + +static int isl28022_probe(struct i2c_client *client) +{ + struct device *dev = &client->dev; + struct device *hwmon_dev; + struct isl28022_data *data; + int err; + + if (!i2c_check_functionality(client->adapter, + I2C_FUNC_SMBUS_BYTE_DATA | + I2C_FUNC_SMBUS_WORD_DATA)) + return -ENODEV; + + data = devm_kzalloc(dev, sizeof(struct isl28022_data), GFP_KERNEL); + if (!data) + return -ENOMEM; + + err = isl28022_read_properties(dev, data); + if (err) + return err; + + data->regmap = devm_regmap_init_i2c(client, &isl28022_regmap_config); + if (IS_ERR(data->regmap)) + return PTR_ERR(data->regmap); + + err = isl28022_config(data); + if (err) + return err; + + isl28022_debugfs_init(client, data); + + hwmon_dev = devm_hwmon_device_register_with_info(dev, "isl28022_hwmon", + data, &isl28022_chip_info, NULL); + if (IS_ERR(hwmon_dev)) + return PTR_ERR(hwmon_dev); + + dev_info(dev, "%s: sensor '%s'\n", dev_name(hwmon_dev), client->name); + return 0; +} + +static const struct of_device_id __maybe_unused isl28022_of_match[] = { + { .compatible = "renesas,isl28022"}, + { /* LIST END */ } +}; +MODULE_DEVICE_TABLE(of, isl28022_of_match); + +static struct i2c_driver isl28022_driver = { + .class = I2C_CLASS_HWMON, + .driver = { + .name = "isl28022", + }, + .probe_new = isl28022_probe, + .id_table = isl28022_ids, +}; + +static int __init +isl28022_init(void) +{ + int err; + + isl28022_debugfs_root = debugfs_create_dir("isl28022", NULL); + err = i2c_add_driver(&isl28022_driver); + if (!err) + return 0; + + debugfs_remove_recursive(isl28022_debugfs_root); + return err; +} + +static void __exit +isl28022_exit(void) +{ + i2c_del_driver(&isl28022_driver); + debugfs_remove_recursive(isl28022_debugfs_root); +} + +module_init(isl28022_init); +module_exit(isl28022_exit); + +MODULE_AUTHOR("Carsten Spieß "); +MODULE_DESCRIPTION("ISL28022 driver"); +MODULE_LICENSE("GPL"); From patchwork Fri Sep 6 06:14:17 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: 13793343 Received: from APC01-TYZ-obe.outbound.protection.outlook.com (mail-tyzapc01on2074.outbound.protection.outlook.com [40.107.117.74]) (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 032FA13D8B5; Fri, 6 Sep 2024 06:14:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.117.74 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725603300; cv=fail; b=YJUfIi9z/ROQTSGGI6DcmFJQD9wkY2ED2LkvhQsQl6/geCrjPIF4KovHCWcXO+5VrLxxwuqxffoJsiyrMAkJmOO5VKyssbWeds3+RPeAlO+ulQwxrzTWC869w/6ogTPx5L6a83qY7wJS8dyWVY2yNxoRDdqhRQ3gCanNDZfCEi4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725603300; c=relaxed/simple; bh=uXRTK5E/ZkYd/IejJmeE/1meXCAlHODbEcF6DbfbFAQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=De3hlIaMy8yTK3978P4s5eA6vPfm7jscqKVl5dNcmqAUNTNnpVcHCw1/Ctcq/9XNbs2kaKtSSIiCb2xTIhuZ+YbIYt8N+RVZ/crTXCMytbp7I93Uu/azB+6OD2fuVfJoGiFqr4YhU1Ib2QQcaaFD0kcNOVdOwD1dcM2Mjp1BZj4= 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=DUEuwVfH; arc=fail smtp.client-ip=40.107.117.74 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="DUEuwVfH" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=VXFA8u4TaMiSq+ut2vtgcxQG5/Jbi9yWj0GGord/9TQMzIXhZjlVjb7Hp1M3zgpRkAfsJP7TqgCEtc9nmbTuL/KYMuX/dtyxpCRP026TT//6r4HB+TD/OAPTUJ0GgWWCzGXvX3tR1kGDyivXQx+F12CV/J9fDYQfHHLnZgkhX5M33Clnfy7uQZoiduAjQg3NvClUMY5mscT9b5R/9fSSA9YqNe+wMhPiC+WFfviUCsxZ/+fVfSaJ7wSohv5kkq898qzUUEeDmdNFd0RV3GSYATrUHPcSL6HEjQM1Z54JZJjCcAmc+PFiSO4Vc+I6xfYIaZ8Bqrci1jTzPvUA0ZWbUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=NjSPiGVt5mrfI/V12S/7TXpE76spvcLvJ8nRI8PHiHw=; b=glprz1sPMyBsWD2yMLpPv3k20GcLYRLTnJ2X6a7F7ffUfWQ/ejALqHSV9b3V8mK1NiWzi4oejua+XeEpZxMBwuUucxgGAHbnQ5kTb1VFb7/BqKQ3actI1sFMDoe/SeS0G9nVgaQ1BSpyU57j+HTCv9zGWdOGhEDx7ofASlBh8QDYmvnksGyYhnw1MKb3FnGAJLG9bx5c6W9/GEGoJ+M/iJc1yPZ3JyqC7wy/Rl0Xs/d3sKKf/vCau3cxMYxrLeJ/w5eH9dtiYngUeR9UxwK/LjakeurOdl+nhOgCGxV16RL+h5EusfIjlsXC13mQZI2V/dsPQvwCuBO1+YzPkjOdrQ== 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=NjSPiGVt5mrfI/V12S/7TXpE76spvcLvJ8nRI8PHiHw=; b=DUEuwVfHN3TOKzjRBVbeaQGpZx65RZve3TRwi1JNQfKw/TUI1v9zm3+TmHrBdHhjh2dBQcrAM8vW9EEs9j9wmnEo3xjd6gEE4RVy8dH3AjDCaq7BDXZmr5QiGeCprzJduOkNtxAISB7Ae5TAI7KY+kpp813b/4qMqWzJQpoYfwIn8qTaA0tSTmKBCGum+2o3lKUdbCvaIW9SSjRMRQcUf72aPqz7Pkbuw/L/Q9mZNWzlFSRXVQ56YVTWXLuqN8PYSa57S4gSOOi7kZqlZkfCT6cC6nPiKY4ARwuu0TGGGF6rO1sNQouB/qKPS0Ssbhl8Z1T17K1fkvHV5Rfjg1pnzw== Received: from PS2PR01CA0040.apcprd01.prod.exchangelabs.com (2603:1096:300:58::28) by KL1PR04MB7163.apcprd04.prod.outlook.com (2603:1096:820:f9::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.22; Fri, 6 Sep 2024 06:14:53 +0000 Received: from HK2PEPF00006FB3.apcprd02.prod.outlook.com (2603:1096:300:58:cafe::15) by PS2PR01CA0040.outlook.office365.com (2603:1096:300:58::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.17 via Frontend Transport; Fri, 6 Sep 2024 06:14:53 +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.7918.13 via Frontend Transport; Fri, 6 Sep 2024 06:14:53 +0000 From: Delphine CC Chiu To: patrick@stwcx.xyz, =?utf-8?q?Carsten_Spie=C3=9F?= , Jean Delvare , Guenter Roeck , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Geert Uytterhoeven , Magnus Damm Cc: Krzysztof Kozlowski , Jonathan Corbet , linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-renesas-soc@vger.kernel.org Subject: [PATCH v6 2/3] dt-bindings: hwmon: add renesas,isl28022 Date: Fri, 6 Sep 2024 14:14:17 +0800 Message-Id: <20240906061421.9392-3-Delphine_CC_Chiu@wiwynn.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240906061421.9392-1-Delphine_CC_Chiu@wiwynn.com> References: <20240906061421.9392-1-Delphine_CC_Chiu@wiwynn.com> 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_|KL1PR04MB7163:EE_ X-MS-Office365-Filtering-Correlation-Id: 873b3221-1d01-4095-23b6-08dcce3b3900 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|376014|82310400026|1800799024|7416014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?K1/nTvehC+QFheguXWHn6o+b7yIXPF2?= =?utf-8?q?tSeJv6o1S/TupIa+GBfMaRFOSzaKXGzuqdgscM+itr0ESUoqlcvW6K7fzG/u0XMEI?= =?utf-8?q?MGv8/cFQgbVqbHmk6cpYt2VP/+BBcRIOwXwLR2fMPcAA2AOAX4tPyA6cZHxs+LKML?= =?utf-8?q?Un7HGBFqfiYEU1gPiWeizAZXYyhbsQ82v/01Ifunng5uynAFB2SvyTivN9T658ekz?= =?utf-8?q?TkogujKnVY2HzhZ+Fts5tv4Izfer8jyUKK99KVOUoROCNpyZGQ4btHUl0PowNAJg6?= =?utf-8?q?IxmT4QncTkafMaPS2IKE6n2b7ydiEAeCTgxw8n56bkww5qi/OfCEVOhxcxKmNA/Kj?= =?utf-8?q?WeBAB5ibNwzNbVK6HAF5uS281U5PFOknPB39vZ+mlCnqbIxWwL2f3SqaPjHi7VFrG?= =?utf-8?q?h8CjpLAmmz+ibNiPeCE+cRdmFEPba0EH4/UXGDbqBPQzgtsmWxOeJK86+MG4GcwtP?= =?utf-8?q?TCnjCBAyt4oIB6fyfOKNqdTsCpXk+26+Y2r2Af2GaEfBZKmVsio0AXtotB34T1LQ/?= =?utf-8?q?VzEx1F2nCm9yg+huUH0Eu5q7KZI/IVEoy8TIbQxnlaspuxHwEBp4Y+EUMmjXPTjOa?= =?utf-8?q?W5uMKI7xnN5D3PJoD5yVVWcCEvSq46TxA1Q+/MnM6Xp1gY4qaLGjl1t5Cq8m3Hh+v?= =?utf-8?q?7w1wk0ZOMf6yiZx+z5ZyNnsWJbegkm3i3puBu/Nq1LLltuhZKoCzhSuhZSDFHgNhi?= =?utf-8?q?1uUFffCQBMl3ilxtbdRmkdE/iODNF1NFh6GPxgqI+wQCLTl876AHQvsW1/aEWFKEu?= =?utf-8?q?822qmxYK7AYCWnzU8wk6HnBGDnaekiuvOTYhUVrmK17ayxM76ou2QPNC0qjvwlEZI?= =?utf-8?q?S9YqV2qnUQDbw6zKOf9IrV2ZvBNPtGBL+dwTN0QXn4RnTB3iDGDyYgSU8XaSLKjCV?= =?utf-8?q?JQxrC6k//Z3voeIDwzofXixnhUEkGjKvgWeV59tFoyXzFMlj5f8d9IcDLbA18CRFu?= =?utf-8?q?XtaPTYvnzXrZxRa5ie2CJStj75rduVdlIM2Coqp7PtjVgrnmGbB8ewrNf2fRL8e+m?= =?utf-8?q?Yh29wozk+Ggfql1+6i+0LUPnp6Ox1snYvNnG1RI6vhLv+thkoKUp996hDN1vxt4YL?= =?utf-8?q?jDYnW5H52HZzyEnhHlQqzoryGBmbNF7p4DKyRADZ3GEA0DvrUzYU2Ls32q2nmkjhg?= =?utf-8?q?RcOYi6unhFH7UWpaVAywne2/kglrm1HlvV4P6+QBSZoUcl/FdANcu23MXRZogMlkh?= =?utf-8?q?xW8zTQ13axtnRbYTbJaooOFRNVbctouM2fPddeuJ21DWXPHyIhx225kkJmHvGb/Zu?= =?utf-8?q?NmdmX14liqyK4cetsxopFM51rf3shHYne9cgFx8XxOwlAGAL5fHMtkUX/LDLDM7us?= =?utf-8?q?Wyt6thOQSQNQ?= 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:(13230040)(36860700013)(376014)(82310400026)(1800799024)(7416014);DIR:OUT;SFP:1101; X-OriginatorOrg: wiwynn.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Sep 2024 06:14:53.1501 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 873b3221-1d01-4095-23b6-08dcce3b3900 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: KL1PR04MB7163 From: Carsten Spieß Add dt-bindings for Renesas ISL28022 power monitor. Signed-off-by: Carsten Spieß Reviewed-by: Krzysztof Kozlowski --- .../bindings/hwmon/renesas,isl28022.yaml | 64 +++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 65 insertions(+) create mode 100644 Documentation/devicetree/bindings/hwmon/renesas,isl28022.yaml diff --git a/Documentation/devicetree/bindings/hwmon/renesas,isl28022.yaml b/Documentation/devicetree/bindings/hwmon/renesas,isl28022.yaml new file mode 100644 index 000000000000..dd82a80e4115 --- /dev/null +++ b/Documentation/devicetree/bindings/hwmon/renesas,isl28022.yaml @@ -0,0 +1,64 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/hwmon/renesas,isl28022.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Renesas ISL28022 power monitor + +maintainers: + - Carsten Spieß + +description: | + The ISL28022 is a power monitor with I2C interface. The device monitors + voltage, current via shunt resistor and calculated power. + + Datasheets: + https://www.renesas.com/us/en/www/doc/datasheet/isl28022.pdf + +properties: + compatible: + const: renesas,isl28022 + + reg: + maxItems: 1 + + shunt-resistor-micro-ohms: + description: + Shunt resistor value in micro-Ohm + minimum: 800 + default: 10000 + + renesas,shunt-range-microvolt: + description: + Maximal shunt voltage range of +/- 40 mV, 80 mV, 160 mV or 320 mV + default: 320000 + enum: [40000, 80000, 160000, 320000] + + renesas,average-samples: + description: + Number of samples to be used to report voltage, current and power values. + default: 1 + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [1, 2, 4, 8, 16, 32, 64, 128] + +required: + - compatible + - reg + +additionalProperties: false + +examples: + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + + power-monitor@40 { + compatible = "renesas,isl28022"; + reg = <0x40>; + shunt-resistor-micro-ohms = <8000>; + renesas,shunt-range-microvolt = <40000>; + renesas,average-samples = <128>; + }; + }; diff --git a/MAINTAINERS b/MAINTAINERS index d39199ed51da..d5809cf181ff 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -11936,6 +11936,7 @@ ISL28022 HARDWARE MONITORING DRIVER M: Carsten Spieß L: linux-hwmon@vger.kernel.org S: Maintained +F: Documentation/devicetree/bindings/hwmon/renesas,isl28022.yaml F: Documentation/hwmon/isl28022.rst F: drivers/hwmon/isl28022.c From patchwork Fri Sep 6 06:14:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Delphine CC Chiu X-Patchwork-Id: 13793344 Received: from APC01-SG2-obe.outbound.protection.outlook.com (mail-sgaapc01on2055.outbound.protection.outlook.com [40.107.215.55]) (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 32C7A13D2BE; Fri, 6 Sep 2024 06:15:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.215.55 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725603309; cv=fail; b=Uw9bAnaIQSKXGnBUk+L6I1oumF9Zbm9z36LqjeK05xnN2hy9yYHVGXvcq1labr44d2wFCGOTmaGbxJasYBqB+wVW6vQGCVMhRd07zCCNShtSmgTRFV7e81RWglwvuWniwhiE1EOeWL4anAW91YvVpq+SMiLk8Z3Y2rsQK8tiZiI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725603309; c=relaxed/simple; bh=tixLFoDRlOvZFLUwjZTvhCpnTkCm3ZcNdrF51v9zfXg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=AW3ZE4EyxU7WI18O05I7O9mEsKIMzzOJVYSm0IJpZrdvM6Oh7JF0jLFuoWAbre3jBlIRA8IwxmbN3j9J1Hlls5oPKeNqkg+fgBd/tlVXvrcJ3lsprhqCrnSv1+jyXQZga4Mn+xGjtBzUjb2QBjKpfDLefyrXUpE0NAeuQ/4hlEs= 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=YuWBRc64; arc=fail smtp.client-ip=40.107.215.55 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="YuWBRc64" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=CguR4EIHODDpHuxvYxg2LdbnRGSXmc2jVoi+ycpRgxMNMJ30m+KJqEyv18QFR72ZIXbUTV3a4RETxSurcOByLWSWitLBORyakGxpXrKSBF0oYLp8pnOAGg9xoUT58fGPaguGMC40VLYusaY/r87S6S3Kpt5Np5Yn3vwiDAswaPdySHeeXxax38z4i6TLwwa7WdEf4pwN8cU/iATt+I/81Jk3b2exkZGKaXhQ/P34rSBZ/LI2euVDni1Ar7P5LIk5e33UcLwVw9DGErA2uDTgkn+QCMNCi1QgsQ32P1dNkHYA59FoPGi6TxgUSzxKoVdkQE7BBo5HDJZqLa53GrhUqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=dDRNL8aqBLV1TuuBW7ADbrQVrbs0/GZw0WSSfkNDrCo=; b=uYzqdp/Wq5b2nUzyWbnP4RYeX3M8aLuAB9Le242UbwdlPUz8ZR9qpxevH1GbWPtW/oI1tnMIFXREtmW6SW6X4ir+FatHhyx6FLTnK0mEDPx7XYLlxgWtER2M5kV27AmpSc4KG3Dlp2oXxITo+4pNCAMVFsh5Xci/UarPfcwR6XAwKVrbIUHpzflNlx1vUrytXgvvjORzjY8+9LHVrOnKWE7C3MhQqvZxSNnxCnRrMImU1Yg0lwkgfl0TW0Ow+Q9jyJsAUY9S9l0ig2hCXfTjGbfR45/kECtuC7nApvqlSYZ2XrEB6ra1hzYw17xkjjXEf9/IMWrbCrLHJAmMpPeUIQ== 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=dDRNL8aqBLV1TuuBW7ADbrQVrbs0/GZw0WSSfkNDrCo=; b=YuWBRc64yhh3DelzsYtJZYmL56SZoUQaEv26rymJ3tJC7booIWLJ/ZpY7Jf8qcVrcB0hCu2dBV9BrzuENA4GwuLQycD2hBNOBSOXYbFU48plwXCE7Jda98eQ3rdoyAWEEFQ5VPe1i2pgc8yFknBHNsn1dueJhSkQ+xC55nEuVIMytkFozLMWvXAIB/DKOYxAC+P4LyX/WoaIQ6Zu/5Tt/cvo8HgKGPySabDdsT/tEYQOuOU8/P0RkDqJ9qg9Y2hFfD2hs2QhLxHIr28sSepSyBsWthHpHMOhH/dDYeYoHUApiynye2u59KnmVDNX73PouIPCVo8CkqjcXb/4KovnRQ== Received: from PS2PR01CA0025.apcprd01.prod.exchangelabs.com (2603:1096:300:58::13) by TYSPR04MB7566.apcprd04.prod.outlook.com (2603:1096:400:46e::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.25; Fri, 6 Sep 2024 06:14:58 +0000 Received: from HK2PEPF00006FB3.apcprd02.prod.outlook.com (2603:1096:300:58:cafe::ec) by PS2PR01CA0025.outlook.office365.com (2603:1096:300:58::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.17 via Frontend Transport; Fri, 6 Sep 2024 06:14:57 +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.7918.13 via Frontend Transport; Fri, 6 Sep 2024 06:14:57 +0000 From: Delphine CC Chiu To: patrick@stwcx.xyz, =?utf-8?q?Carsten_Spie=C3=9F?= , Jean Delvare , Guenter Roeck Cc: Delphine CC Chiu , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jonathan Corbet , Geert Uytterhoeven , Magnus Damm , linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-renesas-soc@vger.kernel.org Subject: [PATCH v6 3/3] hwmon: (isl28022) support shunt voltage for ISL28022 power monitor Date: Fri, 6 Sep 2024 14:14:18 +0800 Message-Id: <20240906061421.9392-4-Delphine_CC_Chiu@wiwynn.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240906061421.9392-1-Delphine_CC_Chiu@wiwynn.com> References: <20240906061421.9392-1-Delphine_CC_Chiu@wiwynn.com> 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_|TYSPR04MB7566:EE_ X-MS-Office365-Filtering-Correlation-Id: 8083e210-0cb1-4277-f37c-08dcce3b3b96 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|7416014|376014|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: xJ1dcAzHoWRcg17izxydOxFC8LyyC0oha+hyfedD2M6JbmGfsEJ9VXNwmom3eZfBwQv1DLkpHPwwatrTPMG4INjMiOmM05dBsxbVL0goQcHbKGxbvL73kY+a/ROw5xuQBVAZm+1JT0vJN28Nvd9e8QsUfJnrim2j5guo7pjmC1vD5hfzoFrHN/OZeP3RAlRn1T4tgoV1CFqvSxWUR9SkeOyY7XxQ3udU5Kzfe7eUqbasxvpp0oLyi8iziN0rUfALGbFhIWa4z1IXii2GYcJZpdACX1M2brcruGPYBoEhkYdQrzYCCG+1boedTRYLYwWX+b66NfJo9fO8eW00cVgWeJhRllE2x9mPc35GtUfHZPM0Pje1HvY5Ie/RQLaMQ/3r6QsxKQGUuaij7nWLzCxuyDLylwQN6+SuFEnyY2XlUxWbRL9tuU6NpCOONl7CToI1bnS8ogEpTA/snMVsbnlhAmc8rOsnBofNVN7s44qXgWgZ0UeV9siS0XfDFu+KUVSq1an3ENQjPAYghqH3DS/QVvLLgmNqyY3SJTNYt1AxMy0sG4/pM8xWXzUO+gXw1vhZqr6hIxcqiyOkjRJVTPzC0nGPQLBen0AzkaJK+94pnCuYTzJFGC0uJy1mt15CLC6Xu4xr3o4EWmst+j7u7UReW1RncRCvmn5M++/uDdQXXQ3gcIIPzVwX1YgQIZjfW+gSUXQ/FkHVeclnMe8ehFHocluoXTz9lIGLqZOblFuG81wjaP0Ru9WVH8XqgMzrGplGOWlBVC2pSKmUA1a2VrIPyFc8ilwH3GjSmt7Llc6KEUK6PISl/UD4wTE7xZlYmhQ6dptLEPiEZrNRVi+CXybIJ6XyZl4+obhlndx4ccMPbSiwQYFm6c7ZzPl9k51hPBQT+EnVuROPhTpRwuU0kMzDYzcT4eFjTu7JT3Qg3gspf5wg0c1c3T8B5oDJQW3C08tTZLXB9ak6zbLCMmhNqACX8x+y8TeCOv0Lf3p8ZeDHbL4CTIoUj07IcLjE/1PmC9kylo93YgF9/8afaZiSnTfT94FPTz4X83kuyJwtWzesLUrRWMF+7jH+T29EV+4aO2XTuL9nBqYooQ+f1HjwgsTWF8OGsiglAbDppR9NLJqNtwQaQ+DASrEKvp5WOCXenbgDz5Pi/Pu805Gsv2GyeVKds0kqMyAtG5ld3SM6i0s2kQYXu6Cap3UevqgOpcplc/IrDzEQHQZpjG4Iu4lnxky5twPtARNdqACJV6PhUiVjIZsJdAAh4/vXRFp8al18j+7+HGHXZpxgRUlvkOYploqESlGN1eV/Iq3VYGGlCOVEocu1QueAqMp67zor+PUnLLoJJpSY4fW9uCe1W2CELAm6rubZ5qaofEoUXiZCbtR2I3E5+QUCkvKwYvnbrZVIJaXN85IZMwKiDnOWPTbLXF/hnexTIiCyat+2HDA8gPH85Us6myz1i0n9UiwlpQuOY7D4 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:(13230040)(1800799024)(7416014)(376014)(36860700013)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: wiwynn.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Sep 2024 06:14:57.4939 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8083e210-0cb1-4277-f37c-08dcce3b3b96 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: TYSPR04MB7566 Added support reading shunt voltage in mV and revise code for Renesas ISL28022. Signed-off-by: Delphine CC Chiu --- drivers/hwmon/isl28022.c | 93 ++++++++++++++++++++++++++++------------ 1 file changed, 66 insertions(+), 27 deletions(-) diff --git a/drivers/hwmon/isl28022.c b/drivers/hwmon/isl28022.c index f0494c3bd483..01220fad813d 100644 --- a/drivers/hwmon/isl28022.c +++ b/drivers/hwmon/isl28022.c @@ -85,8 +85,6 @@ struct isl28022_data { u32 shunt; u32 gain; u32 average; - u16 config; - u16 calib; }; static int isl28022_read(struct device *dev, enum hwmon_sensor_types type, @@ -95,20 +93,61 @@ static int isl28022_read(struct device *dev, enum hwmon_sensor_types type, struct isl28022_data *data = dev_get_drvdata(dev); unsigned int regval; int err; + u16 sign_bit; switch (type) { case hwmon_in: - switch (attr) { - case hwmon_in_input: - err = regmap_read(data->regmap, - ISL28022_REG_BUS, ®val); - if (err < 0) - return err; - /* driver supports only 60V mode (BRNG 11) */ - *val = (long)(((u16)regval) & 0xFFFC); + switch (channel) { + case 0: + switch (attr) { + case hwmon_in_input: + err = regmap_read(data->regmap, + ISL28022_REG_BUS, ®val); + if (err < 0) + return err; + /* driver supports only 60V mode (BRNG 11) */ + *val = (long)(((u16)regval) & 0xFFFC); + break; + default: + return -EOPNOTSUPP; + } + break; + case 1: + switch (attr) { + case hwmon_in_input: + err = regmap_read(data->regmap, + ISL28022_REG_SHUNT, ®val); + if (err < 0) + return err; + switch (data->gain) { + case 8: + sign_bit = (regval >> 15) & 0x01; + *val = (long)((((u16)regval) & 0x7FFF) - + (sign_bit * 32768)) / 100; + break; + case 4: + sign_bit = (regval >> 14) & 0x01; + *val = (long)((((u16)regval) & 0x3FFF) - + (sign_bit * 16384)) / 100; + break; + case 2: + sign_bit = (regval >> 13) & 0x01; + *val = (long)((((u16)regval) & 0x1FFF) - + (sign_bit * 8192)) / 100; + break; + case 1: + sign_bit = (regval >> 12) & 0x01; + *val = (long)((((u16)regval) & 0x0FFF) - + (sign_bit * 4096)) / 100; + break; + } + break; + default: + return -EOPNOTSUPP; + } break; default: - return -EINVAL; + return -EOPNOTSUPP; } break; case hwmon_curr: @@ -122,7 +161,7 @@ static int isl28022_read(struct device *dev, enum hwmon_sensor_types type, (long)data->shunt; break; default: - return -EINVAL; + return -EOPNOTSUPP; } break; case hwmon_power: @@ -136,11 +175,11 @@ static int isl28022_read(struct device *dev, enum hwmon_sensor_types type, (long)data->shunt) * (long)regval; break; default: - return -EINVAL; + return -EOPNOTSUPP; } break; default: - return -EINVAL; + return -EOPNOTSUPP; } return 0; @@ -182,7 +221,8 @@ static umode_t isl28022_is_visible(const void *data, enum hwmon_sensor_types typ static const struct hwmon_channel_info *isl28022_info[] = { HWMON_CHANNEL_INFO(in, - HWMON_I_INPUT), /* channel 0: bus voltage (mV) */ + HWMON_I_INPUT, /* channel 0: bus voltage (mV) */ + HWMON_I_INPUT), /* channel 1: shunt voltage (mV) */ HWMON_CHANNEL_INFO(curr, HWMON_C_INPUT), /* channel 1: current (mA) */ HWMON_CHANNEL_INFO(power, @@ -368,24 +408,22 @@ static int isl28022_read_properties(struct device *dev, struct isl28022_data *da static int isl28022_config(struct isl28022_data *data) { int err; + u16 config; + u16 calib; - data->config = (ISL28022_MODE_CONT_SB << ISL28022_MODE_SHIFT) | + config = (ISL28022_MODE_CONT_SB << ISL28022_MODE_SHIFT) | (ISL28022_BRNG_60 << ISL28022_BRNG_SHIFT) | (__ffs(data->gain) << ISL28022_PG_SHIFT) | ((ISL28022_ADC_15_1 + __ffs(data->average)) << ISL28022_SADC_SHIFT) | ((ISL28022_ADC_15_1 + __ffs(data->average)) << ISL28022_BADC_SHIFT); - data->calib = data->shunt ? 0x8000 / data->gain : 0; - - err = regmap_write(data->regmap, ISL28022_REG_CONFIG, data->config); - if (err < 0) - return err; + calib = data->shunt ? 0x8000 / data->gain : 0; - err = regmap_write(data->regmap, ISL28022_REG_CALIB, data->calib); + err = regmap_write(data->regmap, ISL28022_REG_CONFIG, config); if (err < 0) return err; - return 0; + return regmap_write(data->regmap, ISL28022_REG_CALIB, calib); } static int isl28022_probe(struct i2c_client *client) @@ -396,8 +434,8 @@ static int isl28022_probe(struct i2c_client *client) int err; if (!i2c_check_functionality(client->adapter, - I2C_FUNC_SMBUS_BYTE_DATA | - I2C_FUNC_SMBUS_WORD_DATA)) + I2C_FUNC_SMBUS_BYTE_DATA | + I2C_FUNC_SMBUS_WORD_DATA)) return -ENODEV; data = devm_kzalloc(dev, sizeof(struct isl28022_data), GFP_KERNEL); @@ -418,7 +456,7 @@ static int isl28022_probe(struct i2c_client *client) isl28022_debugfs_init(client, data); - hwmon_dev = devm_hwmon_device_register_with_info(dev, "isl28022_hwmon", + hwmon_dev = devm_hwmon_device_register_with_info(dev, client->name, data, &isl28022_chip_info, NULL); if (IS_ERR(hwmon_dev)) return PTR_ERR(hwmon_dev); @@ -437,8 +475,9 @@ static struct i2c_driver isl28022_driver = { .class = I2C_CLASS_HWMON, .driver = { .name = "isl28022", + .of_match_table = of_match_ptr(isl28022_of_match), }, - .probe_new = isl28022_probe, + .probe = isl28022_probe, .id_table = isl28022_ids, };