Received: by 2002:a05:7412:b795:b0:e2:908c:2ebd with SMTP id iv21csp223310rdb; Thu, 2 Nov 2023 01:30:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGU6djTZrY5x0Cn1wPk5JdleKpxMhyW/OCgQh8mnSetSXFdd9Vl9MKXrX2EXiUTQ+NEI/AD X-Received: by 2002:a17:90a:ce8b:b0:27d:7887:ddc5 with SMTP id g11-20020a17090ace8b00b0027d7887ddc5mr10562995pju.32.1698913853584; Thu, 02 Nov 2023 01:30:53 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1698913853; cv=pass; d=google.com; s=arc-20160816; b=rcdih4HJwMPZNVhe6b3D34TmILLJN52Q5YpZt1hI+ZrIf84Ryo+v9OZh/Y9YB5vHtH jyU3PPvupLQccMG08L3CJpSSKaxVlopelU+Xn/cnO89GxlafkYVNoVw3Jj3TyYD1K57/ cY7lBWZQbDweqSq2h17tNz0sM5oj1cknNX327/nG2a+o1glhFzxkCykvtv6aaKFGpYmm MHHl6d8ZTWJDN1A+PWak1gIvrwoN6BLpWFsZAnT+JatCMnvcoxcwqemsn90ZiHYBGPUe sexQhqaV3cWkqpYZTLeGL/cwV6sZQKXEXiooDNSc1QaJ7uliTVJuDM2HIzzFagtCBF9n Ss6w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=2B/LaJXYfe0Z7H/8Zgl9w9YnK4JI/a1utXV39Qi1W9g=; fh=SLJSzIF+Z+iVyesmds+8sI6typcjo5nH3xAPiw3hzLs=; b=hYC+ZYTmNX5shyXqGbKXtB/+yqCfzf3xIUkRGkoIZwlwQJvr2y5CnEWTWu8u0mHc9J LR+2Yb9ewFv+F0R0WqPj81d1wWKUokrVOIZesZ4HE2+kSxV910/auSzG/rYamu/8BU7o AaHxTTKO199Wss1QY1tcgHCkNieGMFEVumvaj8NrD7Hu8LqIyAcO2OcvtGyXDRbx67sv 4fO6AHLYSblmHolHrs0WyCa/bMDcZuM+FR+Azj0hC/WMCM3yCbR/jYWFZsOkkNYd0Md9 Bjl2qpuUwClOclD0XdymplEMoLuEIpx25nsDbuatYLlyZRPGay8wDebo8Tfi3AkWnpGz +pDA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@wiwynn.com header.s=selector2 header.b=bbSo7pqh; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=wiwynn.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id rj9-20020a17090b3e8900b0027d0bf1eef1si2579192pjb.98.2023.11.02.01.30.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Nov 2023 01:30:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@wiwynn.com header.s=selector2 header.b=bbSo7pqh; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=wiwynn.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id A863E80A8B48; Wed, 1 Nov 2023 20:29:05 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231574AbjKBD27 (ORCPT + 99 others); Wed, 1 Nov 2023 23:28:59 -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 Content-Transfer-Encoding: 8bit X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SG1PEPF000082E1:EE_|KL1PR0401MB4276:EE_ Content-Type: text/plain 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 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 01 Nov 2023 20:29:05 -0700 (PDT) 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 */ -- 2.25.1