From patchwork Sun Sep 20 18:09:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Barker X-Patchwork-Id: 11787989 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D897C59D for ; Sun, 20 Sep 2020 18:09:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BB4D620874 for ; Sun, 20 Sep 2020 18:09:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=konsulko.com header.i=@konsulko.com header.b="P3T1VNit" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726654AbgITSJ5 (ORCPT ); Sun, 20 Sep 2020 14:09:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726333AbgITSJ5 (ORCPT ); Sun, 20 Sep 2020 14:09:57 -0400 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04F75C061755 for ; Sun, 20 Sep 2020 11:09:57 -0700 (PDT) Received: by mail-wr1-x441.google.com with SMTP id z4so10453512wrr.4 for ; Sun, 20 Sep 2020 11:09:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=konsulko.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RhsFwh0Xf746HqZw1ov1Te1cJJL//OI9FdvirfvR/J0=; b=P3T1VNit7YRch2zqqUzWKRcDaR/gZAOkDwhecbf+wXZKwnUMWof4h1azv6BxV/Lb6j +x0F0a2UOEyKl3Ml5SQmv49L9JzpqArWijmpfw2Q7o8f6P9tkayzcYYRBiw/5mocZ3DG s/n7oJTatXlyNPymhPqCojjmANy/EKQyCu3W0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=RhsFwh0Xf746HqZw1ov1Te1cJJL//OI9FdvirfvR/J0=; b=cs3TXF6OeBqfeOiTieCdAomwxuhW4JI2LNHoIqcnpAZbfoZl3hPsD6rRGFxF+CWkR9 yujp5Mq/2QhC0/8rn1vBWQwRjOKLHXz4Dt+E+2XHjWTTEM8ghBS64Tnb0+wiWAWDW/IL XX+FbKrhtmcfj2GFN3DPa9h+WcZk/H0LltIHR2mOcOKXO2LA6CEwWI4YSeBpdG8MVLeF LCEbPihilQA6TOE2SOF7RaqAlzmot9oU+kS0yYhc28wIUmbziqpXOJt660f4qudzxz7I 9elFM4bRkwmy+WsyiBIz4G5XbsdPc+HVFyFG+TepxFIjbSa1mzxkMdn2a3lVQJnldh6i wTIQ== X-Gm-Message-State: AOAM530sOECg3MwGHbHk84IDzk2bEmxWmvpVSFMZqNje+MgsiWoclpQW xBfVs0E+HYDUAFBbvxLuFLos0w== X-Google-Smtp-Source: ABdhPJxzGkGUwoRRauQ6T3Dmh06fz+pp8J+JQyUtB9N2x/mwpA4ZxxWZiRexuMZFTB0Izq4qkCj3Sg== X-Received: by 2002:a5d:69c9:: with SMTP id s9mr48266043wrw.348.1600625395596; Sun, 20 Sep 2020 11:09:55 -0700 (PDT) Received: from ar2.home.b5net.uk ([213.48.11.149]) by smtp.gmail.com with ESMTPSA id h186sm15823702wmf.24.2020.09.20.11.09.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Sep 2020 11:09:55 -0700 (PDT) From: Paul Barker To: Kamil Debski , Bartlomiej Zolnierkiewicz , Jean Delvare , Guenter Roeck , Rob Herring Cc: Paul Barker , linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH 1/1] dt-bindings: hwmon: pwm-fan: Support multiple fan tachometer inputs Date: Sun, 20 Sep 2020 19:09:40 +0100 Message-Id: <20200920180943.352526-2-pbarker@konsulko.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200920180943.352526-1-pbarker@konsulko.com> References: <20200920180943.352526-1-pbarker@konsulko.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Document and give an example of how to define multiple fan tachometer inputs for the pwm-fan driver. Signed-off-by: Paul Barker Reviewed-by: Rob Herring --- .../devicetree/bindings/hwmon/pwm-fan.txt | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/Documentation/devicetree/bindings/hwmon/pwm-fan.txt b/Documentation/devicetree/bindings/hwmon/pwm-fan.txt index 41b76762953a..4509e688623a 100644 --- a/Documentation/devicetree/bindings/hwmon/pwm-fan.txt +++ b/Documentation/devicetree/bindings/hwmon/pwm-fan.txt @@ -8,15 +8,16 @@ Required properties: Optional properties: - fan-supply : phandle to the regulator that provides power to the fan -- interrupts : This contains a single interrupt specifier which - describes the tachometer output of the fan as an - interrupt source. The output signal must generate a - defined number of interrupts per fan revolution, which - require that it must be self resetting edge interrupts. - See interrupt-controller/interrupts.txt for the format. -- pulses-per-revolution : define the tachometer pulses per fan revolution as - an integer (default is 2 interrupts per revolution). - The value must be greater than zero. +- interrupts : This contains an interrupt specifier for each fan + tachometer output connected to an interrupt source. + The output signal must generate a defined number of + interrupts per fan revolution, which require that + it must be self resetting edge interrupts. See + interrupt-controller/interrupts.txt for the format. +- pulses-per-revolution : define the number of pulses per fan revolution for + each tachometer input as an integer (default is 2 + interrupts per revolution). The value must be + greater than zero. Example: fan0: pwm-fan { @@ -55,3 +56,12 @@ Example 2: interrupts = <1 IRQ_TYPE_EDGE_FALLING>; pulses-per-revolution = <2>; }; + +Example 3: + fan0: pwm-fan { + compatible = "pwm-fan"; + pwms = <&pwm1 0 25000 0>; + interrupts-extended = <&gpio1 1 IRQ_TYPE_EDGE_FALLING>, + <&gpio2 5 IRQ_TYPE_EDGE_FALLING>; + pulses-per-revolution = <2>, <1>; + }; From patchwork Sun Sep 20 18:09:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Barker X-Patchwork-Id: 11787993 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B73F6618 for ; Sun, 20 Sep 2020 18:10:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9B78B20866 for ; Sun, 20 Sep 2020 18:10:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=konsulko.com header.i=@konsulko.com header.b="ZW7d3oqI" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726657AbgITSKA (ORCPT ); Sun, 20 Sep 2020 14:10:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726333AbgITSKA (ORCPT ); Sun, 20 Sep 2020 14:10:00 -0400 Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F366CC061755 for ; Sun, 20 Sep 2020 11:09:59 -0700 (PDT) Received: by mail-wm1-x343.google.com with SMTP id l15so10147114wmh.1 for ; Sun, 20 Sep 2020 11:09:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=konsulko.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=U/3y8aL8xjaXoF5g8eBJHDwrEWSj6qaH/5qg/WgNfb4=; b=ZW7d3oqIcEZauhNIVxQ4aPHCTYU5uxTbAVNygwKqonp6VJewXYz+IVpRcB75KKT4aC sYaSYu12Z9rs8y3JuDXtHPeSs/1aVEZcqr2qdY+xNuoQr1SGL5JPKUWV2jedZDILWHBe phFrC9wZQUiEI4mS0qC9ftRG7EwOBHE83b/hE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=U/3y8aL8xjaXoF5g8eBJHDwrEWSj6qaH/5qg/WgNfb4=; b=sH6eYNgCO84zN8cyPfWJuBYCsio4p9LbzcWy6TRfqEi7/E4Z21xi3HBQyqcTR/7p2K WtjO2wJ93fe2EGPJBUh2hKqeCrrgGhkb/bgupaP2gS6pn4Eusd3DB7iHohuOwXVwv1kG xxrZStOmt1Gu8yft1X9XDzD8d5Z2zmZbgGq6AzPJGcduLwJ5dKoOU2kd8liAVDoV39tA PSlVZ9iOpyvVE0sZ+zyLwYkF5QU3eEtoAJTdTKYrmxAsLonM+u090REs7c+F2p/7ZzTX p9p4DwLQVIaniRXkuC/pBkUhYaZhyzIwevVoPPWZKpM/fl4T+yaXcOzWIIE5uq3smq+y hMew== X-Gm-Message-State: AOAM531R9GPxfXbnZHyao3jsx0bxzE/dvx2GEwnQ7Bgh/XJ5AgAUbAUg qc8SOH8gs8B6CGpb48/3G5Nr2VlmHLTHjQ== X-Google-Smtp-Source: ABdhPJxTSoh6uhWTEEQhAiaFxpDd3IF2UtVH5inGnGlS0fLIY5EA8zmnLM+Bz1V1NIs5P7uaDMnO0w== X-Received: by 2002:a1c:f20b:: with SMTP id s11mr27041641wmc.144.1600625398666; Sun, 20 Sep 2020 11:09:58 -0700 (PDT) Received: from ar2.home.b5net.uk ([213.48.11.149]) by smtp.gmail.com with ESMTPSA id h186sm15823702wmf.24.2020.09.20.11.09.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Sep 2020 11:09:58 -0700 (PDT) From: Paul Barker To: Kamil Debski , Bartlomiej Zolnierkiewicz , Jean Delvare , Guenter Roeck Cc: Paul Barker , linux-hwmon@vger.kernel.org Subject: [PATCH 2/2] hwmon: pwm-fan: Fix RPM calculation Date: Sun, 20 Sep 2020 19:09:43 +0100 Message-Id: <20200920180943.352526-5-pbarker@konsulko.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200920180943.352526-1-pbarker@konsulko.com> References: <20200920180943.352526-1-pbarker@konsulko.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org To convert the number of pulses counted into an RPM estimation, we need to divide by the width of our measurement interval instead of multiplying by it. We also don't need to do 64-bit division, with 32-bits we can handle a fan running at over 4 million RPM. Signed-off-by: Paul Barker --- drivers/hwmon/pwm-fan.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/drivers/hwmon/pwm-fan.c b/drivers/hwmon/pwm-fan.c index d7f8c11b4543..2649f6bf1a26 100644 --- a/drivers/hwmon/pwm-fan.c +++ b/drivers/hwmon/pwm-fan.c @@ -65,19 +65,18 @@ static void sample_timer(struct timer_list *t) { struct pwm_fan_ctx *ctx = from_timer(ctx, t, rpm_timer); ktime_t now = ktime_get(); + unsigned int delta = ktime_ms_delta(now, ctx->sample_start); int i; for (i = 0; i < ctx->tach_count; i++) { struct pwm_fan_tach *tach; - int pulses; - u64 tmp; + unsigned int pulses; tach = &ctx->tachs[i]; pulses = atomic_read(&tach->pulses); atomic_sub(pulses, &tach->pulses); - tmp = (u64)pulses * ktime_ms_delta(now, ctx->sample_start) * 60; - do_div(tmp, tach->pulses_per_revolution * 1000); - tach->rpm = tmp; + tach->rpm = (pulses * 1000 * 60) / + (tach->pulses_per_revolution * delta); } ctx->sample_start = now;