Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp4524252rdb; Fri, 15 Sep 2023 05:08:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEbCp60w28O8EDh7IBNZPllODMrMmNchLyBzarDXVwvf5X+J0vHBmA3AVWPbllyjYilDL2n X-Received: by 2002:a5d:9c46:0:b0:794:e11c:d8c3 with SMTP id 6-20020a5d9c46000000b00794e11cd8c3mr1526421iof.16.1694779691306; Fri, 15 Sep 2023 05:08:11 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1694779691; cv=pass; d=google.com; s=arc-20160816; b=YjIDLwjtRYoHCfM9OtJPKISzb2235/9xtJdaxwJERxvPn1nmwNVarqbqLqo31jMY9L PvDcd35/4iA8vVl212au0qJhy4Vw6Ek+WfgqXqIypI3CrvoShUhP64DSpuR5UHo0BstS WjwcbUnkeqEhojwKQgKcoO1He85assR2giq6070a52ZaguuNIfQumlS4iAcImLImJYtI FJl3fkqLca0bhY82cP6dlRq8fTx8BlV1bG77GBslh+3T07ljBj4T9FpcQ4q59d6EUiVm gnOyZL9j5oFOEjN+g7nKaOOdkTvSsWpSxsP31TeHw67PcPqK4tbOsW5NAz57deHE/qd3 N/cg== 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=CFDqZCYrA0aklQDE11Blsokis2MVHnDcqZwbL2HaPAY=; fh=8Rj0bA0PuccEfV1DGka4QhPRchBVYb9gHQqXO3gKukA=; b=s4FfsBcasJf8dPmN0u5GK+D8FJafO9pU1Fk0sYqTY3BbN0Wu0qlVj8/cPZ1yA89pXq d/9o7JsH4ARKC1VmPVRCOlHQgynUq3gV6vpiI0R1S/g7vq/ZXj+LBQsZi4nzPq363t7N QETtwW/pwFIOzZu9JZh/vGzLJaZAwtEiKj4ivcCauZE3Cd2xdZCvrVFjVAu/InIcdJxs LUhaOTYZ0+ku9gNjxz/UorsDYkNYQ3EvHUccFzpZd+YhVW/oeoPgxZIciy+m6nvv4WWF 3t+PC7cH5JTZUmXGgqpW7gFUhJ8IVdaGcXBVSarQMgFCHkUgq99iJ7KEGGMiTT++7O+q ryNQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@wiwynn.com header.s=selector2 header.b=DbIQP9Jw; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id w8-20020a63f508000000b0056c4189d6cbsi3254186pgh.171.2023.09.15.05.08.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 05:08:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@wiwynn.com header.s=selector2 header.b=DbIQP9Jw; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (Postfix) with ESMTP id 1C1ED837433B; Thu, 14 Sep 2023 23:29:50 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232271AbjIOG3s (ORCPT + 99 others); Fri, 15 Sep 2023 02:29:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230101AbjIOG3q (ORCPT ); Fri, 15 Sep 2023 02:29:46 -0400 Received: from APC01-TYZ-obe.outbound.protection.outlook.com (mail-tyzapc01on2058.outbound.protection.outlook.com [40.107.117.58]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77296CCD; Thu, 14 Sep 2023 23:29:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GaZLobU1NmJLRxDjFZXJVU0ppMXwwqC2KZxE/kaqf+HchWVkXC+H0ygNx9iUD+9NxwdV7N+hKRls2g4PO49EhTkFlsiXSvJ6V8qmZOvR3Pq5pD31VnamEDBw1aylfKbcN72bZ1FIZh9ReH3sbQgsAAlUGyvBwsLMsy1eDfMl7+v3dbSsd5iEVmEtI6p7zz1oRLt1O2g5VgLcClS9PoCuxURNvlCALvoS6xpRQk731Qt5dnNSbaJVelU2giVfgkfPRpqInDcTFIfcjVuCm/raO54HTnDK0t0a4e7Qcm3xQOZuVAXgyc1ca+pLKOEE8Bl2XOnThCW4g/SyTM8tVECtAw== 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=CFDqZCYrA0aklQDE11Blsokis2MVHnDcqZwbL2HaPAY=; b=K01coJsF5egboDFm4QVwiq4zIC7h8rj3bg/TiNMiGmqkE/3LWy8KBgkqtoJIDrrn7EDIK2DA+7fOsuxV3MzLzEP+1eFaQ41h3nQxXVehgO4b91/EhukFIZav871Ei0L0VTRJLD4CEtNavdEhLc7iK7QbABkVGm2AGo3XBl8tDaBxmnw6uzdebHId5TIr+6dOWCbNQF4dxz3z6AVp936dsodSDU+VcHEOT+fpkrb7brHywwYLtlVZbQB+LeaOiuBfR+RaypEmZzenbZ4f5AiMm3t60wJQoFvzofwi6hLSpDRUZz502VX1tjbP/BAvBikSJuR8Bjdu3NNU1G+DpFbfRw== 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 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=CFDqZCYrA0aklQDE11Blsokis2MVHnDcqZwbL2HaPAY=; b=DbIQP9JwMrSRcuM/YxbMJBVto+FVYK5J4c1kgRsmeLQ0sxkHGbenlqqzFnRD8udXH9OvsGzyZtcuz3vFuc7KuTQBoqmVHiFEJT8KnTDD6wkSOc4gs0bDpGm5MRTR7+UMUAEvG4QCO7nToZsrLwDorZhr9gVWLry7IwW+k8HGBX0xOcDyDm/FPu9lHp+4qjmsJUxmfF/v+5sK2TwknLhQLIubobblmv0vP/aEjSCcqizo7jQpjrYm7Ucfw/k+hmQJ8NKHgd8SH3Cjag2PvlyTBdkbhq5cyaWxKS5h+qwvWJNrFxXM5e18WxajtyZ8owtiwIEoEJUxMbHhkqbZeMY26g== Received: from SG2PR02CA0042.apcprd02.prod.outlook.com (2603:1096:3:18::30) by TYZPR04MB5974.apcprd04.prod.outlook.com (2603:1096:400:201::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6768.30; Fri, 15 Sep 2023 06:29:35 +0000 Received: from SG1PEPF000082E1.apcprd02.prod.outlook.com (2603:1096:3:18:cafe::33) by SG2PR02CA0042.outlook.office365.com (2603:1096:3:18::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.21 via Frontend Transport; Fri, 15 Sep 2023 06:29:35 +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.6792.20 via Frontend Transport; Fri, 15 Sep 2023 06:29:34 +0000 From: Delphine CC Chiu To: patrick@stwcx.xyz, Delphine CC Chiu , Jean Delvare , Guenter Roeck Cc: Rob Herring , Krzysztof Kozlowski , Conor Dooley , linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/2] hwmon: max31790: support to config PWM as TACH Date: Fri, 15 Sep 2023 14:29:23 +0800 Message-Id: <20230915062926.2460502-2-Delphine_CC_Chiu@wiwynn.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230915062926.2460502-1-Delphine_CC_Chiu@wiwynn.com> References: <20230915062926.2460502-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_|TYZPR04MB5974:EE_ Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: 029950d5-3b78-4b0a-ba49-08dbb5b52143 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: iw1/p7HBw84nQxwJ0blDp3QVB1ef7Sxw2PsKNGMGtIIauBqM7HelCDDBUNHNSHJVlDCDQ6YRA3pihu+V6N1XfurkVQop4zYYTbqVjRXPA13ofqefFDaYZ+JzbJoHlJg2mcACyHhUta7TLn2Q3n2TWd3jC59PkBush/m2iY3dZrwFUOFlO/gMwpaLd9eYq0no7aVcRMhNq/FyyMmXqriCLxs6lNQZSjgwp7pPv7MmTZjvOVdcjDYCAHaHFtFb6epj/GbgwB1Pv5gRSX6yllUCrNztAq4QghITA9GWbUladmW0n1NJNv06d1FgQYQD8FEdhAX9BLPR21ndATnr7ZqafiiKwMiLcdGWxikGj1Re29OF4GtamfbQVHwa58ZqPhkadPWQ6aKf5cgBDM3kiuZpWgZ4tJrwWhG+IFOSDZ2LG12JDlV+ReTF+5/y0uDkp7ppq8ilzqF4Ah5cc6cGAGcVaNXV0p2GIhsOdFraurX5qb0k9v6hNXEHr214JWnnB7rd3rupC3dpsLHGkmr5COEeRapcl3zy0hn9iDlZQFwlzq/UsXqI9NdvCT/TqWhWA33qtqFm+ib2eG4OLC/Bcb/vCfX8BEach3sWgJcdqaBooX6/t8TvItXNUnBlWipcItTKdYJ1WgA5gShv3gLURQwpSddtLdBKTZEuWVS7q8UjMRLI6M821k+9WgYS/ebpFF7SqdDOgqk0/axQWuJXvdULpw== 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)(396003)(39850400004)(376002)(136003)(1800799009)(451199024)(82310400011)(186009)(46966006)(36840700001)(36860700001)(336012)(83380400001)(26005)(2616005)(1076003)(47076005)(956004)(6512007)(6666004)(5660300002)(6486002)(9316004)(6506007)(356005)(82740400003)(110136005)(2906002)(8936002)(40480700001)(70586007)(478600001)(70206006)(4326008)(8676002)(36756003)(316002)(54906003)(36736006)(81166007)(41300700001)(86362001);DIR:OUT;SFP:1101; X-OriginatorOrg: wiwynn.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Sep 2023 06:29:34.8914 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 029950d5-3b78-4b0a-ba49-08dbb5b52143 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: TYZPR04MB5974 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email 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 (groat.vger.email [0.0.0.0]); Thu, 14 Sep 2023 23:29:50 -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. For example: set `pwm-as-tach = <2 5>` in DTS for max31790 and the driver will config PWMOUT2 and PWMOUT5 as TACH8 and TACH11. Signed-off-by: Delphine CC Chiu --- Changelog: 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 | 58 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/drivers/hwmon/max31790.c b/drivers/hwmon/max31790.c index 0cd44c1e998a..7826d94306c5 100644 --- a/drivers/hwmon/max31790.c +++ b/drivers/hwmon/max31790.c @@ -480,6 +480,60 @@ static const struct hwmon_chip_info max31790_chip_info = { .info = max31790_info, }; +static int max31790_config_pwm_as_tach(struct device *dev, + struct i2c_client *client) +{ + struct device_node *np = dev->of_node; + int i, ret, size, channel; + u32 pwm_index[NR_CHANNEL] = { 0 }; + u8 fan_config; + + size = of_property_count_u32_elems(np, "pwm-as-tach"); + + if (size > 0 && size <= NR_CHANNEL) { + ret = of_property_read_u32_array(np, "pwm-as-tach", pwm_index, + size); + if (ret) { + dev_err(dev, + "Property 'pwm-as-tach' cannot be read.\n"); + return ret; + } + + for (i = 0; i < size; i++) { + if (pwm_index[i] == 0 || pwm_index[i] > NR_CHANNEL) { + dev_err(dev, "Not support to config PWM %x.\n", + pwm_index[i]); + return -EOPNOTSUPP; + } + + channel = pwm_index[i] - 1; + 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_init_client(struct i2c_client *client, struct max31790_data *data) { @@ -521,6 +575,10 @@ static int max31790_probe(struct i2c_client *client) data->client = client; mutex_init(&data->update_lock); + err = max31790_config_pwm_as_tach(dev, client); + if (err) + dev_crit(dev, "Config PWM as TACH failed.\n"); + /* * Initialize the max31790 chip */ -- 2.25.1