From patchwork Thu Nov 2 03:28:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Delphine CC Chiu X-Patchwork-Id: 13443359 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DDF34C4332F for ; Thu, 2 Nov 2023 03:28:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235571AbjKBD26 (ORCPT ); Wed, 1 Nov 2023 23:28:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346757AbjKBD25 (ORCPT ); Wed, 1 Nov 2023 23:28:57 -0400 Received: from APC01-PSA-obe.outbound.protection.outlook.com (mail-psaapc01on2057.outbound.protection.outlook.com [40.107.255.57]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2EB5F113; Wed, 1 Nov 2023 20:28:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IsFVwqXJ3HjNoz/aZT+6SLusTTh14SXdf4cei1FvtJC9wBaOCBbGoFK2YLojzKy5ELhqcpHvbB0TCaMcjdL2dsYU3F5KfNO3NhuYo5hKCMBAhK4ceUrBZrItwDDouV6vh56CqmkLtmlFRytlGoddfQjiuyPsOe/2BtxOhCJyMSZoV25RpYMTn7jIg26K4+QLLtbIAPyCBMQRWp6I9VYcowaoLcj2QkooHWFOX2T4WkrqYS2mY6hfHzvN7he49uhc65DZ2FQVackyY3isf7LXn2sbAlZGqcg0AzyjPCa//lqhznLeE45bKCJoOxBXHUxOQbXB0a6OidtiWI8fjpt72g== 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=2B/LaJXYfe0Z7H/8Zgl9w9YnK4JI/a1utXV39Qi1W9g=; b=HzZF5aNgWhIh3Aj+A+KOTY1RJHSPqLj4gbEMSITqY7Ul7YT9fmog+xpPYiScj1UjNCJGj8MODA5h6Ht10necs7rkcHk6YDgaMswyZvt63hNkNpJSSDMPML48uLNVEHqhai4RHfVulA/Ibjfzq1DHPREQqSmYURpCJq7gQNMdHu4zVAp3CFhI+llKR2pnPQC8b0hImcVMabGLlnG3uI/Y9NlqDhqvRxaVLYV6epPuSanhaYRiZEA6JkGoNZH5dmasUHqjiSgZMecHfGiZMUGx/cP252jmEWiUtAyy4JQPSi+3KuDhyCiteAA0672fNJQXSfEK0UB2Ch9nqCiwKtSRQw== 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=2B/LaJXYfe0Z7H/8Zgl9w9YnK4JI/a1utXV39Qi1W9g=; b=bbSo7pqh26hw5nbpWm/d4BChEDvE9XqwfSoCFp7Cqf4YdFtmesGZd8s9O2wQKeTzGkalJ2TNjUWgSk4fiuq/vM2vFLPi9Zgf2kByPA/84Ma1+K2GD2l0kjP1Xc+Fo6erX0itXRZaIItEu3cpLTTBQ+C2KpHgwaOPVLg0c/6Qtfbcilt/S3IPtZWL5qxzSkm0gIBXLXPqdcsCNO3sW5zjXoSGX8fmFCJZyu6KKd/uSnKpSI8ciwKc7HbzbkJMix7mb72A56MAhaEXh9ufWlXZIOHfIq8jrHlng5DTKSon12zLn3bmnECXOPKNhMi4MHJewdJTdxoMENLAK6TTgjCv3g== Received: from SG2PR02CA0009.apcprd02.prod.outlook.com (2603:1096:3:17::21) by KL1PR0401MB4276.apcprd04.prod.outlook.com (2603:1096:820:24::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6954.19; Thu, 2 Nov 2023 03:28:45 +0000 Received: from SG1PEPF000082E1.apcprd02.prod.outlook.com (2603:1096:3:17:cafe::ab) by SG2PR02CA0009.outlook.office365.com (2603:1096:3:17::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6954.19 via Frontend Transport; Thu, 2 Nov 2023 03:28:45 +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 SG1PEPF000082E1.mail.protection.outlook.com (10.167.240.4) with Microsoft SMTP Server id 15.20.6954.19 via Frontend Transport; Thu, 2 Nov 2023 03:28:44 +0000 From: Delphine CC Chiu To: patrick@stwcx.xyz, Delphine CC Chiu , Jean Delvare , Guenter Roeck Cc: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jonathan Corbet , linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Subject: [PATCH v4 1/3] hwmon: max31790: support to config PWM as TACH Date: Thu, 2 Nov 2023 11:28:30 +0800 Message-Id: <20231102032834.3827289-2-Delphine_CC_Chiu@wiwynn.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231102032834.3827289-1-Delphine_CC_Chiu@wiwynn.com> References: <20231102032834.3827289-1-Delphine_CC_Chiu@wiwynn.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SG1PEPF000082E1:EE_|KL1PR0401MB4276:EE_ X-MS-Office365-Filtering-Correlation-Id: 3b9726b6-1829-44e7-9a20-08dbdb53d1e9 X-MS-Exchange-AtpMessageProperties: SA X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 3vFtcxr2iRnYNGoBUShqcRMzcGzNuCbA7J7pi4ojsAKVBqnTcN0Mpwy6ljL5nhKrB0mS6jA/Fa7I7LUFfXQjL1uT6dLBuFGJMZim+Nc3gShVhgkGriBV8ZzkDT7NNGehiqSasHLWFz9dQBIEAigX762xQ5yPXsJg/X0MWXxT492PsPjYhmshvmLUXrmzdMyDbsJXtZ1x5ZsA9GKCrW1NM9lcHPerEbzF7MODMd0ZOQxnuTULfwkwMOFN+D1v64/7U6OrWDLO1Gvr6yOCMLrKrGAgXjn3zj4YVS/lEYJFjv12pWkbPv3PHOA6qcT1PVwbc4YSeX1lYpkKHKTJzRk8e30Z5wictvC6ywl4wEOG3+Rho8KYLXqPTWaNVHKKwoNeh3jOr2l3h+27cnKertKl2GU1p99R2a1z2h0Xr4ITTwh70Cs71npaNPMqkSlVg+QntId9GEFA2LzcCtsNWAFNWLeiPzz+sQkXPTpRQMlLZRNhFjb9wWQX/srakVuUX5Yi8cq0Xq6mCW7GhLymJDY6eLbSKj7DwL1qbikwm1YLwm25RGSYglNsbqo7EtXsN0j15o8HePL4QVNPbrKDhhMu5VO284khoQlsH5B5KGaPHkWItsTpBSodVUxeSw4QSGfRtG9KQta43Eahibe2uOF/ExJyYu6KWuu1bFvZn+1FIirnvzTDaM1kcyo+LfpdbKILr6KcOOPklXiIlwC2KlSDLA== 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)(6069001)(4636009)(376002)(136003)(39860400002)(396003)(346002)(186009)(451199024)(1800799009)(64100799003)(82310400011)(36840700001)(46966006)(83380400001)(26005)(2616005)(1076003)(110136005)(316002)(36736006)(70586007)(86362001)(356005)(336012)(82740400003)(70206006)(54906003)(41300700001)(956004)(81166007)(36756003)(7416002)(8676002)(36860700001)(47076005)(5660300002)(4326008)(2906002)(8936002)(6512007)(9316004)(40480700001)(6666004)(6486002)(6506007)(478600001);DIR:OUT;SFP:1101; X-OriginatorOrg: wiwynn.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Nov 2023 03:28:44.6541 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3b9726b6-1829-44e7-9a20-08dbdb53d1e9 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: SG1PEPF000082E1.apcprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: KL1PR0401MB4276 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org The PWM outputs of max31790 could be used as tachometer inputs by setting the fan configuration register, but the driver doesn't support to config the PWM outputs as tachometer inputs currently. Add a function to get properties of the setting of max31790 to config PWM outputs as tachometer inputs before initializing max31790. Signed-off-by: Delphine CC Chiu --- Changelog: v4 - No change. v3 - Use 'sensor-type' in 'channel' node to config pwm as tach. v2 - Remove unnecessary parentheses. - Add more error handling. - Change the type of "pwm-as-tach" from u8 to u32 to match binding document. v1 - Support to config PWM as TACH --- drivers/hwmon/max31790.c | 83 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/drivers/hwmon/max31790.c b/drivers/hwmon/max31790.c index 0cd44c1e998a..378ff32c7c1e 100644 --- a/drivers/hwmon/max31790.c +++ b/drivers/hwmon/max31790.c @@ -480,6 +480,85 @@ static const struct hwmon_chip_info max31790_chip_info = { .info = max31790_info, }; +static int max31790_config_pwm_as_tach(struct i2c_client *client, + struct device *dev, + struct device_node *node) +{ + int ret, channel; + u32 reg; + u8 fan_config; + const char *type_str; + + if (!node->name || of_node_cmp(node->name, "channel")) + return 0; + + if (of_property_read_u32(node, "reg", ®)) { + dev_err(dev, "Could not read reg value for '%s'\n", + node->full_name); + return -EINVAL; + } + + if (reg > NR_CHANNEL || reg == 0) { + dev_err(dev, "Invalid reg (%u) in '%s'\n", reg, + node->full_name); + return -EINVAL; + } + + channel = (int)reg - 1; + + if (of_property_read_string(node, "sensor-type", &type_str)) { + dev_info( + dev, + "No sensor-type for '%s', use default setting as PWM output.\n", + node->full_name); + return 0; + } + + if (!strcmp(type_str, "TACH")) { + ret = i2c_smbus_read_byte_data( + client, MAX31790_REG_FAN_CONFIG(channel)); + if (ret < 0) { + dev_err(dev, "Read fan config for channel %d failed.\n", + channel); + return ret; + } + fan_config = ret; + fan_config |= (MAX31790_FAN_CFG_CTRL_MON | + MAX31790_FAN_CFG_TACH_INPUT); + + ret = i2c_smbus_write_byte_data( + client, MAX31790_REG_FAN_CONFIG(channel), fan_config); + if (ret < 0) { + dev_err(dev, + "Write fan config for channel %d failed.\n", + channel); + return ret; + } + } + + return 0; +} + +static int max31790_configure_channels(struct i2c_client *client, + struct device *dev) +{ + struct device_node *node; + int err; + + if (dev->of_node) { + for_each_child_of_node(dev->of_node, node) { + err = max31790_config_pwm_as_tach(client, dev, node); + if (err) { + dev_err(dev, "Configure for %s failed.\n", + node->full_name); + return err; + } + } + } + + return 0; +} + static int max31790_init_client(struct i2c_client *client, struct max31790_data *data) { @@ -521,6 +600,10 @@ static int max31790_probe(struct i2c_client *client) data->client = client; mutex_init(&data->update_lock); + err = max31790_configure_channels(client, dev); + if (err) + dev_crit(dev, "Config PWM as TACH failed.\n"); + /* * Initialize the max31790 chip */ From patchwork Thu Nov 2 03:28:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Delphine CC Chiu X-Patchwork-Id: 13443360 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A714DC41535 for ; Thu, 2 Nov 2023 03:29:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348305AbjKBD3C (ORCPT ); Wed, 1 Nov 2023 23:29:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346757AbjKBD3B (ORCPT ); Wed, 1 Nov 2023 23:29:01 -0400 Received: from APC01-PSA-obe.outbound.protection.outlook.com (mail-psaapc01on2064.outbound.protection.outlook.com [40.107.255.64]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE6D5123; Wed, 1 Nov 2023 20:28:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KUcADIc8+lb/q7bKdaZCwNS6FnLyM4klGEfTaeAint5QQCNy9vDiVmlPk848F+WzD4FG0pQcb5n9GmPMXOKO44fHt/yAlBrdb0cyUGOmVBA+eGeMfi6c5vhOctBnZ3nf4hgqnO05LO+bF46GHBVpwLECUdsV4b12MplrCSCFwy6GS15HfvMb0BFE3l0Uvq2RBoE56Tndxwc/LEDoeGSgW44bSUfjKygLgNqArh84kHKzsaATc0xG2JX7HvCb04j2go7ex+32FP4n8QZunpk5J8ZmwDErclQrlZCrbGc5LFdROpRQ9UHLpNprlA4+bulbE20Hdd5SBWuAxN/dTeXb6g== 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=dEe8KtCVsQG/oRnOaYIPaZejyuib5zC9/ZH5CGkblLQ=; b=WVG8v8bpZyauEImfYoHrCR2ZQBGdOcB/d3p+nFVPbX8M3WEpUD3nbQIphgvkxemZhO5hyjuUC6mjKqY2qrqpOKpA/2ilH/em0u28v9y7a+eZMA8EMeJGnR56xb+dOa05yPDrDGLiPdthxiJndj7327PYHmTeKeoXy3ARQj+Jro7mVeyo/QxKso2ZJ1CNsXc6AwrvWc1W5jX4ST7pIlu1pOG3NsIxuV7bOABuPXItrY/g4vkTvpDuwiyPF28m2IDmFJmdUWS9hkiLw1RN7+0XW8M+qS+FEuYIDA/wvxok/Zi40YqEG0qPE4q2s2f+vElDFm8zFM1/vs8AdyUh6hxgOQ== 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=dEe8KtCVsQG/oRnOaYIPaZejyuib5zC9/ZH5CGkblLQ=; b=SkxmyFcpjga+2iaUWXnlJTVHIaqDYtZvoa9VhlubELqrhc7245W2woeLE2P0hZp9YN0YK//xyg67Tbzjuw0daI20Liobb9mKOuBnIqmiqu5a9WIq5b9rFYgy/rwGVVx6HOJLysFAUU1CaqUFyiDVjP2fg9DzjowuD8wIPyQf8aQfpWz/icoUbdQGSmjaAMH5xE8cPhxxHTHS8Yb6dOIW9gDzjvJ2gfWeFfCwBdYjg/EK5jY+i7bQA6WsMo3Ky68yNV/so7IFsdelnsPzzqlaZO/TLHJqAgrNZakkyXPk1OqLTihilLDTg9Hk1W9SiHB9WBcHds+WLSQAvp+bBv/C5A== Received: from SG2PR02CA0004.apcprd02.prod.outlook.com (2603:1096:3:17::16) by TYZPR04MB7194.apcprd04.prod.outlook.com (2603:1096:400:463::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6954.19; Thu, 2 Nov 2023 03:28:49 +0000 Received: from SG1PEPF000082E1.apcprd02.prod.outlook.com (2603:1096:3:17:cafe::9) by SG2PR02CA0004.outlook.office365.com (2603:1096:3:17::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6954.19 via Frontend Transport; Thu, 2 Nov 2023 03:28: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 SG1PEPF000082E1.mail.protection.outlook.com (10.167.240.4) with Microsoft SMTP Server id 15.20.6954.19 via Frontend Transport; Thu, 2 Nov 2023 03:28:48 +0000 From: Delphine CC Chiu To: patrick@stwcx.xyz, Delphine CC Chiu , Jean Delvare , Guenter Roeck , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: Jonathan Corbet , linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Subject: [PATCH v4 2/3] dt-bindings: hwmon: add MAX31790 Date: Thu, 2 Nov 2023 11:28:31 +0800 Message-Id: <20231102032834.3827289-3-Delphine_CC_Chiu@wiwynn.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231102032834.3827289-1-Delphine_CC_Chiu@wiwynn.com> References: <20231102032834.3827289-1-Delphine_CC_Chiu@wiwynn.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SG1PEPF000082E1:EE_|TYZPR04MB7194:EE_ X-MS-Office365-Filtering-Correlation-Id: a339b738-13db-4d09-f5a4-08dbdb53d44b X-MS-Exchange-AtpMessageProperties: SA X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +LCtR8gf6vRjZbL0Oy5rflF+RWnFi6JOLnbly8aAkXzMukNLer7YM7TvR7YRpUs7d5VD68j5v5gnDADZTsp4ssaal4+TBLkcXw1zmo+zSL0AUl2K6PIZnsIipEuHKZvtD43Ket4E2HkZhNIg5M3a9CaKsl/b9JEugJAIN9PrmyjERW7PYqubOczsiH14SiY6s1FqYpuUoS+c5rR/I71exvfEyy92JOj7ggM7o6nR50um7IbDWYJ34Qkhwok3S70s8LGV6lKnPOU9I8uad3FDOLxlvQvvRiuws5TW0BW/ETjWWU6HQKtm6CW3MGRhT9ND1Uigfdp3yt4vewFy6f+npA5/rEsSHPUBnNveVTB4jXJMYUnzLyHdbLlkOjxIPt4EIBdq7k54Ki94+ytXdnY4GR4+qVDpwn6p4NGnGFg81iXxHVQVG/k0KdrS8EyoIerV5CEJ3PyOSlU+4UPZ3Xr+G0exnmiAf4pTE2CnWL2UKEbScIpH7OV02r+Zl7q+1VB0RKtEvRISoXlk4cr24fYY4JojPyxjjMJKSuR6HbFzvu3JmMnuliS2l6XUMHNUFm4SCnujgrEZL4xfbMK/+99HMvAQFXhb4PSlI2p9cnXZHpGme/0+RrnXf866OfM+r5h0rjP9GbIykd6RWjf46nAypELvQt6FjUI88cnb4IHDRNcXhIV12Z4naBaPWbou+mgveJW69b7oW57YSY1gBuvgyczS8owzgNO3xmp6XY++jPY= 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)(6069001)(4636009)(346002)(136003)(376002)(396003)(39850400004)(230273577357003)(230173577357003)(82310400011)(64100799003)(186009)(1800799009)(451199024)(46966006)(36840700001)(336012)(6512007)(70206006)(36736006)(966005)(6486002)(86362001)(26005)(1076003)(8676002)(36756003)(40480700001)(8936002)(4326008)(6506007)(110136005)(6666004)(956004)(316002)(70586007)(2616005)(478600001)(47076005)(5660300002)(36860700001)(7416002)(2906002)(41300700001)(81166007)(9316004)(356005)(82740400003);DIR:OUT;SFP:1101; X-OriginatorOrg: wiwynn.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Nov 2023 03:28:48.6698 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a339b738-13db-4d09-f5a4-08dbdb53d44b 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: SG1PEPF000082E1.apcprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYZPR04MB7194 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Add dt-bindings for the MAXIM MAX31790. Signed-off-by: Delphine CC Chiu --- Changelog: v4 - No change. v3 - Use 'sensor-type' in 'channel' node to config pwm as tach. - Changed the status in MAINTAINERS to 'Maintained'. v2 - Add dt-bindings for the MAXIM MAX31790. --- .../bindings/hwmon/maxim,max31790.yaml | 89 +++++++++++++++++++ MAINTAINERS | 6 ++ 2 files changed, 95 insertions(+) create mode 100644 Documentation/devicetree/bindings/hwmon/maxim,max31790.yaml diff --git a/Documentation/devicetree/bindings/hwmon/maxim,max31790.yaml b/Documentation/devicetree/bindings/hwmon/maxim,max31790.yaml new file mode 100644 index 000000000000..7f717ab4caac --- /dev/null +++ b/Documentation/devicetree/bindings/hwmon/maxim,max31790.yaml @@ -0,0 +1,89 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- + +$id: http://devicetree.org/schemas/hwmon/maxim,max31790.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Maxim max31790 + +maintainers: + - Delphine CC Chiu + +description: | + The MAX31790 controls the speeds of up to six fans using + six independent PWM outputs. The desired fan speeds (or PWM duty cycles) + are written through the I2C interface. + The outputs drive “4-wire” fans directly, or can be used to modulate + the fan’s power terminals using an external pass transistor. + + Datasheets: + https://datasheets.maximintegrated.com/en/ds/MAX31790.pdf + +additionalProperties: false + +properties: + compatible: + enum: + - maxim,max31790 + + reg: + maxItems: 1 + + "#address-cells": + const: 1 + + "#size-cells": + const: 0 + +patternProperties: + "^channel@[1-6]$": + type: object + + additionalProperties: false + + properties: + reg: + items: + - enum: [1, 2, 3, 4, 5, 6] + + # There are 6 PWM output channel in MAX31790 that allows to be configured + # as a TACH input by setting the Fan Configuration register. + # The default setting will be PWM output. + sensor-type: + items: + - enum: + - PWM + - TACH + + required: + - reg + +required: + - compatible + - reg + +examples: + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + + pwm@20 { + compatible = "maxim,max31790"; + reg = <0x20>; + + #address-cells = <1>; + #size-cells = <0>; + + channel@3 { + reg = <3>; + sensor-type = "TACH"; + }; + + channel@6 { + reg = <6>; + sensor-type = "TACH"; + }; + }; + }; diff --git a/MAINTAINERS b/MAINTAINERS index 43c5ed3c4508..707f1b903f60 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1371,6 +1371,12 @@ F: Documentation/devicetree/bindings/hwmon/adi,max31760.yaml F: Documentation/hwmon/max31760.rst F: drivers/hwmon/max31760.c +ANALOG DEVICES INC MAX31790 DRIVER +M: Delphine CC Chiu +S: Maintained +F: Documentation/devicetree/bindings/hwmon/maxim,max31790.yaml +F: drivers/hwmon/max31790.c + ANALOGBITS PLL LIBRARIES M: Paul Walmsley S: Supported From patchwork Thu Nov 2 03:28:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Delphine CC Chiu X-Patchwork-Id: 13443361 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 592A1C4167D for ; Thu, 2 Nov 2023 03:29:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348336AbjKBD3H (ORCPT ); Wed, 1 Nov 2023 23:29:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46334 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348366AbjKBD3F (ORCPT ); Wed, 1 Nov 2023 23:29:05 -0400 Received: from APC01-TYZ-obe.outbound.protection.outlook.com (mail-tyzapc01on2074.outbound.protection.outlook.com [40.107.117.74]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7271120; Wed, 1 Nov 2023 20:28:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=d4jyK9OPDGNyvBffIxxrNkrOVzmMIA8+uWiPyZoSQXSOL4jSzazIr7DOZqDBAZYUICrJ6tY6iJN3N0heJ1Yq5ptQ8+AIfPPbNFMkcBTwwFrEcEfzUujZ+UolervugGGYeOokyQMoj9ewYkY83CzJ73hfM7G9a99awE6ghFp2JKqLf1OE2ZE7bipkaNa2XxjhJMAehctkYihOMQ3TocFk0yCib2TOrvvfL+WMdZ1pVm1tiDKAecM7Edr6kbEG3dx4mZsISecicjZ74uB/sP06FduAjRzcWtbM5OxTInw6xW2FP8+tWe/GAOQCseq3NNxuH6SPj9meaeH5kTq6mMixag== 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=y5A+YGxARtmjO8LaEC8NMjLhxNaKIJpF8nCOyDvjQDU=; b=MSzqU+WE5Mr+qBwjrGcJ3exx9f5keLhME9t9dKFUehwXzAMYW37c7AJ+WRgqq8DKUBAheBtB8fA0Z3NLzFsczUsUpyk4Lok05xyIjsPQk5uMZdqkwIn69YipG2fYSlHEkC9e49W33Xda9btVq5O4tj/KiTYcOta0FPFK+pu0yrONFbmq3c7jmemkrlqCdumWyg+h7NrMwzQx5JbREmcUmmJlsuxEbUuezRj1xo8eGKs7Xcl9F9R11BL3F7PHDj4+noqqdSYVROzuSSUGF27SqAHr53Lftlx82MvHigHyvahC+Uta44KmY+L0Q5UTDUPxjSZrqEIl43uEJxZfv4nxVg== 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=y5A+YGxARtmjO8LaEC8NMjLhxNaKIJpF8nCOyDvjQDU=; b=j/Kizps3EQQZgFpPz5BnREpxQcL8eQSkqiqQzrkImSvzWRmUPyCxtGKm0P8PxFwSTC9jCN+GQF4fkQFp5aOgQBzq7PBfcdVq8IlWqWosRnf77CQtBhJUIc27WNC12Ie31vapK6sUsNf0TuqH8HUTJtJdt8m0cffzOtscTcqOATR7DDi2zyl7MN+M72BuufPmKWfPxWmcyArVN+pC4deOauYFHYz68ygKvm9dXtz8FhXqr/AKyiPPArAD83n9TGj2og3iuOJWKmjaErAoQDenagP09DjiWuwGC/fSpuFAyvXEAzaM9I0MDMRY8UmYwD1F9b3b8i5MwtofnizhqaEX8Q== Received: from SG2PR02CA0013.apcprd02.prod.outlook.com (2603:1096:3:17::25) by SEZPR04MB7529.apcprd04.prod.outlook.com (2603:1096:101:1f1::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6954.19; Thu, 2 Nov 2023 03:28:53 +0000 Received: from SG1PEPF000082E1.apcprd02.prod.outlook.com (2603:1096:3:17:cafe::93) by SG2PR02CA0013.outlook.office365.com (2603:1096:3:17::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6954.19 via Frontend Transport; Thu, 2 Nov 2023 03:28: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 SG1PEPF000082E1.mail.protection.outlook.com (10.167.240.4) with Microsoft SMTP Server id 15.20.6954.19 via Frontend Transport; Thu, 2 Nov 2023 03:28:52 +0000 From: Delphine CC Chiu To: patrick@stwcx.xyz, Jean Delvare , Guenter Roeck , Jonathan Corbet , Delphine CC Chiu 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 Subject: [PATCH v4 3/3] hwmon: max31790: add fanN_enable for all fans Date: Thu, 2 Nov 2023 11:28:32 +0800 Message-Id: <20231102032834.3827289-4-Delphine_CC_Chiu@wiwynn.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231102032834.3827289-1-Delphine_CC_Chiu@wiwynn.com> References: <20231102032834.3827289-1-Delphine_CC_Chiu@wiwynn.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SG1PEPF000082E1:EE_|SEZPR04MB7529:EE_ X-MS-Office365-Filtering-Correlation-Id: e7862ea2-64d8-41ff-9e03-08dbdb53d6db X-MS-Exchange-AtpMessageProperties: SA X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2fiSQejBDy+8c4cA+2WthpFHju5S2Dvy7otkpsbi8uWFp2Q33Ln8raC+dluw/h9/zbF8wDWviwCqcATSUA3V5VgQxIgmMw6Kkke+W6Ov7Wc/P58L88P/zuYzp2AjKVwktmF+G81DzVBwdC8zW8Gkt1F795rfvYHzBrIUi4O1ymkGICwit0I8njIhCxbsa9WFX+UNKWiqFY06tbVwHg+xKYI1LnBY3csQJxnogcSCCzOPq77bgtAnvuVD5VGdZsREb4Q+RRsuS+fnceSHlv+JhfrKnuNI5OerrcnI/kbsHnHy8IcbZ6F4cHaD6WzSmzedp+/r8xMKZj3HcERoCju74WKaJ4bR7JewEk3bc3oF74mx5FqNz/qTzzQ3lj7T6xWLyOdIXxuG///7qMmC5u2RRGLPpmNgjpMXGXr47VBtY8VuEYqXKBdl3O0mBIS4IxecweuaRH2kC/5g9o14MrQr1MT4zVA0jTRwBj5W5WAilg9Ni+pcTYiHaOp+5v6twEhFRiwdEE2xUty+7xXva96WAj5Sq23pOCEdPDRWtQGDoj01PEJZsK0cbMTDxQmF66uwNtGpWmpVHhD0DavGwQH4cCz9cuSqlSO8rWidEZWQZRa7WE3LI8QOH3JqHe4lnXvbRWPpjlu18NOBkTF6raKMsTVvh+L5KQgU/jQT/DvxAMq5YKa6kkXvW+3dHpCOXWfrsOUHBZXy7FGytCTv7qIL3g== 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)(6069001)(4636009)(396003)(39860400002)(136003)(346002)(376002)(451199024)(186009)(1800799009)(82310400011)(64100799003)(46966006)(36840700001)(54906003)(110136005)(70586007)(70206006)(316002)(36736006)(336012)(6506007)(478600001)(82740400003)(1076003)(6666004)(2616005)(4326008)(26005)(956004)(40480700001)(7049001)(8936002)(83380400001)(8676002)(6486002)(6512007)(5660300002)(36756003)(47076005)(2906002)(7416002)(9316004)(81166007)(356005)(41300700001)(36860700001)(86362001);DIR:OUT;SFP:1101; X-OriginatorOrg: wiwynn.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Nov 2023 03:28:52.9667 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e7862ea2-64d8-41ff-9e03-08dbdb53d6db 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: SG1PEPF000082E1.apcprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SEZPR04MB7529 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org The fanN_enable will be set in dbus-sensors service according to the index of TACH that filled in the configuration of entity-manager. Add fanN_enable for all fans to prevent dbus-sensors service couldn't find the corresponding fanN_enable for fanN_input. Signed-off-by: Delphine CC Chiu --- Changelog: v4 - Add fanN_enable for all fans. --- Documentation/hwmon/max31790.rst | 2 +- drivers/hwmon/max31790.c | 57 +++++++++++++++++--------------- 2 files changed, 32 insertions(+), 27 deletions(-) diff --git a/Documentation/hwmon/max31790.rst b/Documentation/hwmon/max31790.rst index 33c5c7330efc..510d5691b18b 100644 --- a/Documentation/hwmon/max31790.rst +++ b/Documentation/hwmon/max31790.rst @@ -38,7 +38,7 @@ Sysfs entries fan[1-12]_input RO fan tachometer speed in RPM fan[1-12]_fault RO fan experienced fault fan[1-6]_target RW desired fan speed in RPM -fan[1-6]_enable RW enable or disable the tachometer input +fan[1-12]_enable RW enable or disable the tachometer input pwm[1-6]_enable RW regulator mode, 0=disabled (duty cycle=0%), 1=manual mode, 2=rpm mode pwm[1-6] RW read: current pwm duty cycle, write: target pwm duty cycle (0-255) diff --git a/drivers/hwmon/max31790.c b/drivers/hwmon/max31790.c index 378ff32c7c1e..fa31e108c7ce 100644 --- a/drivers/hwmon/max31790.c +++ b/drivers/hwmon/max31790.c @@ -203,7 +203,8 @@ static int max31790_read_fan(struct device *dev, u32 attr, int channel, mutex_unlock(&data->update_lock); return 0; case hwmon_fan_enable: - *val = !!(data->fan_config[channel] & MAX31790_FAN_CFG_TACH_INPUT_EN); + *val = !!(data->fan_config[channel % NR_CHANNEL] & + MAX31790_FAN_CFG_TACH_INPUT_EN); return 0; default: return -EOPNOTSUPP; @@ -242,12 +243,12 @@ static int max31790_write_fan(struct device *dev, u32 attr, int channel, data->target_count[channel] = target_count << 5; - err = i2c_smbus_write_word_swapped(client, - MAX31790_REG_TARGET_COUNT(channel), - data->target_count[channel]); + err = i2c_smbus_write_word_swapped( + client, MAX31790_REG_TARGET_COUNT(channel), + data->target_count[channel]); break; case hwmon_fan_enable: - fan_config = data->fan_config[channel]; + fan_config = data->fan_config[channel % NR_CHANNEL]; if (val == 0) { fan_config &= ~MAX31790_FAN_CFG_TACH_INPUT_EN; } else if (val == 1) { @@ -256,11 +257,14 @@ static int max31790_write_fan(struct device *dev, u32 attr, int channel, err = -EINVAL; break; } - if (fan_config != data->fan_config[channel]) { - err = i2c_smbus_write_byte_data(client, MAX31790_REG_FAN_CONFIG(channel), - fan_config); + if (fan_config != data->fan_config[channel % NR_CHANNEL]) { + err = i2c_smbus_write_byte_data( + client, + MAX31790_REG_FAN_CONFIG(channel % NR_CHANNEL), + fan_config); if (!err) - data->fan_config[channel] = fan_config; + data->fan_config[channel % NR_CHANNEL] = + fan_config; } break; default: @@ -291,7 +295,8 @@ static umode_t max31790_fan_is_visible(const void *_data, u32 attr, int channel) return 0644; return 0; case hwmon_fan_enable: - if (channel < NR_CHANNEL) + if (channel < NR_CHANNEL || + (fan_config & MAX31790_FAN_CFG_TACH_INPUT)) return 0644; return 0; default: @@ -445,22 +450,22 @@ static umode_t max31790_is_visible(const void *data, } } -static const struct hwmon_channel_info * const max31790_info[] = { - HWMON_CHANNEL_INFO(fan, - HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT | HWMON_F_ENABLE, - HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT | HWMON_F_ENABLE, - HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT | HWMON_F_ENABLE, - HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT | HWMON_F_ENABLE, - HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT | HWMON_F_ENABLE, - HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT | HWMON_F_ENABLE, - HWMON_F_INPUT | HWMON_F_FAULT, - HWMON_F_INPUT | HWMON_F_FAULT, - HWMON_F_INPUT | HWMON_F_FAULT, - HWMON_F_INPUT | HWMON_F_FAULT, - HWMON_F_INPUT | HWMON_F_FAULT, - HWMON_F_INPUT | HWMON_F_FAULT), - HWMON_CHANNEL_INFO(pwm, - HWMON_PWM_INPUT | HWMON_PWM_ENABLE, +static const struct hwmon_channel_info *const max31790_info[] = { + HWMON_CHANNEL_INFO( + fan, + HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT | HWMON_F_ENABLE, + HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT | HWMON_F_ENABLE, + HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT | HWMON_F_ENABLE, + HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT | HWMON_F_ENABLE, + HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT | HWMON_F_ENABLE, + HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT | HWMON_F_ENABLE, + HWMON_F_INPUT | HWMON_F_FAULT | HWMON_F_ENABLE, + HWMON_F_INPUT | HWMON_F_FAULT | HWMON_F_ENABLE, + HWMON_F_INPUT | HWMON_F_FAULT | HWMON_F_ENABLE, + HWMON_F_INPUT | HWMON_F_FAULT | HWMON_F_ENABLE, + HWMON_F_INPUT | HWMON_F_FAULT | HWMON_F_ENABLE, + HWMON_F_INPUT | HWMON_F_FAULT | HWMON_F_ENABLE), + HWMON_CHANNEL_INFO(pwm, HWMON_PWM_INPUT | HWMON_PWM_ENABLE, HWMON_PWM_INPUT | HWMON_PWM_ENABLE, HWMON_PWM_INPUT | HWMON_PWM_ENABLE, HWMON_PWM_INPUT | HWMON_PWM_ENABLE,