From patchwork Tue Dec 24 09:38:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nylon Chen X-Patchwork-Id: 13919775 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BB25AE77188 for ; Tue, 24 Dec 2024 09:28:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=xfes7NonDdquEMvvUde49BZaA0o1BvleMcFw5AqFXSE=; b=nWBeA/RN28y4Ol WFsJ/otoHDHMcMXcqRlmWf6nKpN7Ly8toh+pPAMj5T/zfoGSw3R4pzZeIR9/My8AsP6Hs8EeLOrg2 7p1JFl/SbJKFDQW5Kbx7ffDo9nQUlpdh2olvBLGwWz+3QUP3L08LEPPsDD7Je4cMEtyJebmNmVWj/ l0HgroGEaYbAb2UKFTj3Z0JhkEHboSOQTHI+fW4DCX4SrStZ3QBD4ItkVYK9nHwpbksStIerjXJ/7 7YMrXZg4Qw1Ttju9x/YA/zZN0V91jLZLTHYTv63SOHkYgVvZtkfOY6aU+hSx/rnTXrY0tUrGD3wYe k052sgXOVRUjMOV2GjzA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tQ1D0-0000000BaLG-2uEz; Tue, 24 Dec 2024 09:28:10 +0000 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tQ1Cy-0000000BaKl-3p1y for linux-riscv@lists.infradead.org; Tue, 24 Dec 2024 09:28:10 +0000 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-2161eb94cceso35005075ad.2 for ; Tue, 24 Dec 2024 01:28:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1735032488; x=1735637288; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=l3iCEA8tjYiThU7Rin4dKsTFv6XsSOzMIb0/FuGpw2E=; b=dyEc8FBSCINlxLCbjwmr7nu1ZLOb8zhXPuNrZDvjRr3ums+5ot6++pq2wezkxlqXkE pmQCT6u7jzuy6LjysKEjFTadKvNME44q2iufG2FFM+9EzZIs5KDi9wr/A3Bqsp4/8PGG ajWPvcLczy18igonTEzzkAjDMOg8YRa9IqfnJORnsdcYRKoa5MpYGi1xqDzB9b+USOJA FvQO4um4RtLUMjPcYDo11dLY9JwYYmx/bqtG9oZqLKxJeZUhvyaCO3Ac4ByMb6GFRi3P +xze3J01tRBwWT3RXlG4R78uzs5iwT70X/Jtec+z31O9U7yLUMGAovwz7TxhAEbgTv7u ec3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735032488; x=1735637288; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=l3iCEA8tjYiThU7Rin4dKsTFv6XsSOzMIb0/FuGpw2E=; b=EIjAjfxyzCIZd7rvObCeOQk5PabANNtmHGmdNKnOwLGW5XcJ10URlpA0U4sx6pPSih oPq4yTolhpI1E+grCoxs69zdj5dVl4SrKS/JByWJ54G9KFvCiwSbSGEN9NCIqS+qXSJn UFW/ErTYUArxTOMH6S0BWzOySUZIyH/ipMvgO4bwPyV8Vlj3So/LZhZBysqvD9l5+8eT Xu1TaUagLGbxnABHUCb3qq+bfS9QPrGxD6YO7CLsxPfVqfzCmqJSFP0PXGT+VNx3wgsd p+ArH2Y3sfb8zTT2cgSjEt65BNhHkUH4OjzlTyV7TX8E6uifFlDNPoHEM0EsRDeKGzwk Q+SQ== X-Forwarded-Encrypted: i=1; AJvYcCWm+9X3vkXzYmG96jUNK0K1VKQzUQc6rrUhopeSunp3O9L/I6/icMRd7iYa9zCwZN/OgYMDXoR1zu1UqQ==@lists.infradead.org X-Gm-Message-State: AOJu0Ywj3iEb42CLaYD8b8+gBfqxVlD41jxoCTtyNoTPENQyMdkXXMSJ 9Zw1nSiRYoQP80rL2czQb0rvAhlMqnx7v5UvYoBfy0tToPNNFBAv0a0UcSuS/Ac= X-Gm-Gg: ASbGncuAuWvytOxhx2VZFCvBJ0qXrBXDVhwr987P4dF7B8edIpAHQuuobRqMzfNXgrm viguTaYJZwETlkld/79i6jUycLi9TrJ1SzZboby47n5PX/P4aF80F0ZGD4N/8UmeghJJdlePGeh 0vysOesOMTlKwcS+xAkp5cy1pOTlVhZkkmaTEyvCxLjXDVUm8vwqq5SkzKcU32t0ibUYM9M/T6l jqlGgNE97CrgWjdWBZP1hHtQr4af3Dbfq2uvA0yH0C/vgGOFGG9odlwp3toDAeteW9LebfHMjG9 xkfaRScSh1MeG5Pizw== X-Google-Smtp-Source: AGHT+IF0zLvXg0En0J308WC3QLi6iR0zwk8h6v6PO7AKPZZqdQ2DFuER2UQDgneMceWfSmVNHYy5yA== X-Received: by 2002:a05:6a00:4485:b0:725:c8ea:b320 with SMTP id d2e1a72fcca58-72abde0f951mr22397563b3a.14.1735032488180; Tue, 24 Dec 2024 01:28:08 -0800 (PST) Received: from hsinchu36-syssw02.internal.sifive.com ([210.176.154.34]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72af8dcff60sm516341b3a.152.2024.12.24.01.28.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Dec 2024 01:28:07 -0800 (PST) From: Nylon Chen To: linux-kernel@vger.kernel.org, linux-pwm@vger.kernel.org, devicetree@vger.kernel.org Cc: Nylon Chen , Conor Dooley , Vincent Chen , Conor Dooley , Rob Herring , Krzysztof Kozlowski , Paul Walmsley , Palmer Dabbelt , Albert Ou , Samuel Holland , linux-riscv@lists.infradead.org Subject: [PATCH v10 1/3] riscv: dts: sifive: unleashed/unmatched: Remove PWM controlled LED's active-low properties Date: Tue, 24 Dec 2024 17:38:59 +0800 Message-Id: <20241224093902.1632627-2-nylon.chen@sifive.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241224093902.1632627-1-nylon.chen@sifive.com> References: <20241224093902.1632627-1-nylon.chen@sifive.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241224_012808_954827_4DFB36D3 X-CRM114-Status: UNSURE ( 8.22 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org This removes the active-low properties of the PWM-controlled LEDs in the HiFive Unmatched device tree. The reference is hifive-unleashed-a00.pdf[0] and hifive-unmatched-schematics-v3.pdf[1]. Link: https://sifive.cdn.prismic.io/sifive/c52a8e32-05ce-4aaf-95c8-7bf8453f8698_hifive-unleashed-a00-schematics-1.pdf [0] Link: https://sifive.cdn.prismic.io/sifive/6a06d6c0-6e66-49b5-8e9e-e68ce76f4192_hifive-unmatched-schematics-v3.pdf [1] Acked-by: Conor Dooley Reviewed-by: Conor Dooley Signed-off-by: Vincent Chen Signed-off-by: Nylon Chen --- arch/riscv/boot/dts/sifive/hifive-unleashed-a00.dts | 12 ++++-------- arch/riscv/boot/dts/sifive/hifive-unmatched-a00.dts | 12 ++++-------- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/arch/riscv/boot/dts/sifive/hifive-unleashed-a00.dts b/arch/riscv/boot/dts/sifive/hifive-unleashed-a00.dts index 900a50526d77..06731b8c7bc3 100644 --- a/arch/riscv/boot/dts/sifive/hifive-unleashed-a00.dts +++ b/arch/riscv/boot/dts/sifive/hifive-unleashed-a00.dts @@ -49,32 +49,28 @@ led-controller { compatible = "pwm-leds"; led-d1 { - pwms = <&pwm0 0 7812500 PWM_POLARITY_INVERTED>; - active-low; + pwms = <&pwm0 0 7812500 0>; color = ; max-brightness = <255>; label = "d1"; }; led-d2 { - pwms = <&pwm0 1 7812500 PWM_POLARITY_INVERTED>; - active-low; + pwms = <&pwm0 1 7812500 0>; color = ; max-brightness = <255>; label = "d2"; }; led-d3 { - pwms = <&pwm0 2 7812500 PWM_POLARITY_INVERTED>; - active-low; + pwms = <&pwm0 2 7812500 0>; color = ; max-brightness = <255>; label = "d3"; }; led-d4 { - pwms = <&pwm0 3 7812500 PWM_POLARITY_INVERTED>; - active-low; + pwms = <&pwm0 3 7812500 0>; color = ; max-brightness = <255>; label = "d4"; diff --git a/arch/riscv/boot/dts/sifive/hifive-unmatched-a00.dts b/arch/riscv/boot/dts/sifive/hifive-unmatched-a00.dts index 72b87b08ab44..03ce2cee4e97 100644 --- a/arch/riscv/boot/dts/sifive/hifive-unmatched-a00.dts +++ b/arch/riscv/boot/dts/sifive/hifive-unmatched-a00.dts @@ -51,8 +51,7 @@ led-controller-1 { compatible = "pwm-leds"; led-d12 { - pwms = <&pwm0 0 7812500 PWM_POLARITY_INVERTED>; - active-low; + pwms = <&pwm0 0 7812500 0>; color = ; max-brightness = <255>; label = "d12"; @@ -68,20 +67,17 @@ multi-led { label = "d2"; led-red { - pwms = <&pwm0 2 7812500 PWM_POLARITY_INVERTED>; - active-low; + pwms = <&pwm0 2 7812500 0>; color = ; }; led-green { - pwms = <&pwm0 1 7812500 PWM_POLARITY_INVERTED>; - active-low; + pwms = <&pwm0 1 7812500 0>; color = ; }; led-blue { - pwms = <&pwm0 3 7812500 PWM_POLARITY_INVERTED>; - active-low; + pwms = <&pwm0 3 7812500 0>; color = ; }; }; From patchwork Tue Dec 24 09:39:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nylon Chen X-Patchwork-Id: 13919776 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BACB6E77188 for ; Tue, 24 Dec 2024 09:28:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=M3uPq89FDl0LgFpDCV+ST6I6Va8N2R9VejzKeQAAEfA=; b=O/ZrNyN3hPw9cD GaZYdV9N3PtYIlPLptxeYgIpuVrHMqvlKmyn2741/bTlGVCUt8TV++6OFXjKmjM7dkVvln67/x1Tt gdLJ675H5/xLQtJxtgnIAcpiRKDsLbIYkBEuDEEDWHcys/NsP0SH00Oy7jP/ZfAyktDhdX0Geb/fl ueVKdB6c4tMDvNMTsiBwnBkykoa3sDiQAcoVJeFVVIw0ag/pBUmeuPrJP7KHx0JEGyNZCn4jcNhsv cpXDSLqA3+6aeHjIqUpgAfL+C7NbsizqL3Me9BdwBWCL5mwkkfGk9+SzPvHcmPTVM5E8YjFFW6eqE HnIAYsU6nRz8tlOtgMsg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tQ1D9-0000000BaOo-1QNc; Tue, 24 Dec 2024 09:28:19 +0000 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tQ1D5-0000000BaND-2wZB for linux-riscv@lists.infradead.org; Tue, 24 Dec 2024 09:28:17 +0000 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-21683192bf9so55063035ad.3 for ; Tue, 24 Dec 2024 01:28:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1735032495; x=1735637295; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=foFQx7pLXh9yW9AzrGBy+50v7YD42XfIXa2v/75AelA=; b=HAW6U67Al9EmOWqwSz0WVW73EWZCnj8bKQpUvVGbIMRUGn1VKt/glO/+c1HiGoSD5C CfuHiobS74+VwE7oYGmMz+YEnD1ClDJ/LygnEMtQRYuzII/p9izNa/ORI/TgdOwvZS8S k/dYWJnQt4WtajCmmGq/YJ2qrW+xifar2/KghT+z3j0f595Z/Vb/Uj8u35p6vYBBMcZU tsPq9uQQv2XMi8e0A5o/XU7WCZjZwU2/MvdaaR6Rc1a9m+jMPu50G6mtbeSTCxRJL00x oD7tSfWVG92IHvv4rET0E4qY4qYJmtdVZh1smMLYCLC/aMGaqnQxBYcQF4CdrnxFwdKX OENg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735032495; x=1735637295; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=foFQx7pLXh9yW9AzrGBy+50v7YD42XfIXa2v/75AelA=; b=oztzFa++uQ4PRIOQbjq8MdbYVRAOHyXB9wLE6FIzsYd6VywacfR8EmRBvNbnqLEeFO Axnl7fzDtmlPW7ioP1FaiHHsvUiiGYNzzNYGPP4Y9yGK4UTICN2D0cmVBZmT2Bp4d1JY 6IjF6mqLqQ6Ez24FwtjfY5rQ/5MoIgxabow+0XImlfMsiGhUHx9fxFmDqmCaqtlYNVTZ 70Rk30StmBryMl4wE1DTKCvhKSyg+KWMLsWoytrrxdhS1oIl/ktzQixuEkwkKm6DwwnD uOj66hG1CPgOeHQ33YyzQi5stTYhwwPVS05jvc6NiCx0qE5vINqdoAxcQXsIjlNAQRy0 2lKA== X-Forwarded-Encrypted: i=1; AJvYcCXf1UzAqzoYUZ1kkBasiZiLLPLXQ1gk9BOYZyJCo05LSbFsiBNCwgLErUG9jMqDbT/ntvn+0r9tJj/bLw==@lists.infradead.org X-Gm-Message-State: AOJu0Yy4nczCBucvlRDoXGscAUWOp0J/9B/FyqScZah3l+uWnYLSa52x cOmDKPfkv/Q3YaIj/DyAMQYvNOIrMS44XOjb+PVsZCZ5nApaBEqbD6AcGJVBln4= X-Gm-Gg: ASbGncvsuBDcSYv17cWQDwTj6Hd8EjkhazA5h2MXNSgqd8KlMj+/IqK4Gk7mdzXs1np Dz0ciBthxS7CMTYDDD29+uJ4oXJszL5EU5PZCGfm1qCpUnIBnbM2s5BNI9Lrqaci/YSff9F2OYb IKkE/sFqmwiDp4qU24BZ8NxWfp4LZ16Zz580cW7U1zWsTFwNXPfoO0//zX3KtWDWlWCW+km9wkY pX85QGt8Hm519alGy4qjncOD34nW6S/nO4OjPJRGSF93uENUPGRcIIBxnby1b1nZgwVOLWYQDvE N6Uo9TM2GTqP91o23A== X-Google-Smtp-Source: AGHT+IElaW7KRvjzzkaa9PnzdUfH1pw/EWBS66svqEXCyWXdLzH5EuyNp84u4FNtb41a24nBilQU3w== X-Received: by 2002:a05:6a20:1588:b0:1e1:e2d9:307 with SMTP id adf61e73a8af0-1e5e0802532mr20282867637.33.1735032494734; Tue, 24 Dec 2024 01:28:14 -0800 (PST) Received: from hsinchu36-syssw02.internal.sifive.com ([210.176.154.34]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72af8dcff60sm516341b3a.152.2024.12.24.01.28.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Dec 2024 01:28:14 -0800 (PST) From: Nylon Chen To: linux-kernel@vger.kernel.org, linux-pwm@vger.kernel.org, devicetree@vger.kernel.org Cc: Nylon Chen , Zong Li , Vincent Chen , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Paul Walmsley , Samuel Holland , linux-riscv@lists.infradead.org Subject: [PATCH v10 2/3] pwm: sifive: change the PWM algorithm Date: Tue, 24 Dec 2024 17:39:00 +0800 Message-Id: <20241224093902.1632627-3-nylon.chen@sifive.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241224093902.1632627-1-nylon.chen@sifive.com> References: <20241224093902.1632627-1-nylon.chen@sifive.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241224_012815_751460_D4CE9036 X-CRM114-Status: GOOD ( 11.15 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org The `frac` variable represents the pulse inactive time, and the result of this algorithm is the pulse active time. Therefore, we must reverse the result. The reference is SiFive FU740-C000 Manual[0] Link: https://sifive.cdn.prismic.io/sifive/1a82e600-1f93-4f41-b2d8-86ed8b16acba_fu740-c000-manual-v1p6.pdf [0] Co-developed-by: Zong Li Signed-off-by: Zong Li Co-developed-by: Vincent Chen Signed-off-by: Vincent Chen Signed-off-by: Nylon Chen --- drivers/pwm/pwm-sifive.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/drivers/pwm/pwm-sifive.c b/drivers/pwm/pwm-sifive.c index d5b647e6be78..bb9146267bc5 100644 --- a/drivers/pwm/pwm-sifive.c +++ b/drivers/pwm/pwm-sifive.c @@ -110,9 +110,10 @@ static int pwm_sifive_get_state(struct pwm_chip *chip, struct pwm_device *pwm, struct pwm_state *state) { struct pwm_sifive_ddata *ddata = pwm_sifive_chip_to_ddata(chip); - u32 duty, val; + u32 duty, val, inactive; - duty = readl(ddata->regs + PWM_SIFIVE_PWMCMP(pwm->hwpwm)); + inactive = readl(ddata->regs + PWM_SIFIVE_PWMCMP(pwm->hwpwm)); + duty = (1U << PWM_SIFIVE_CMPWIDTH) - 1 - inactive; state->enabled = duty > 0; @@ -123,7 +124,7 @@ static int pwm_sifive_get_state(struct pwm_chip *chip, struct pwm_device *pwm, state->period = ddata->real_period; state->duty_cycle = (u64)duty * ddata->real_period >> PWM_SIFIVE_CMPWIDTH; - state->polarity = PWM_POLARITY_INVERSED; + state->polarity = PWM_POLARITY_NORMAL; return 0; } @@ -137,9 +138,9 @@ static int pwm_sifive_apply(struct pwm_chip *chip, struct pwm_device *pwm, unsigned long long num; bool enabled; int ret = 0; - u32 frac; + u32 frac, inactive; - if (state->polarity != PWM_POLARITY_INVERSED) + if (state->polarity != PWM_POLARITY_NORMAL) return -EINVAL; cur_state = pwm->state; @@ -157,8 +158,9 @@ static int pwm_sifive_apply(struct pwm_chip *chip, struct pwm_device *pwm, */ num = (u64)duty_cycle * (1U << PWM_SIFIVE_CMPWIDTH); frac = DIV64_U64_ROUND_CLOSEST(num, state->period); - /* The hardware cannot generate a 100% duty cycle */ + /* The hardware cannot generate a 0% duty cycle */ frac = min(frac, (1U << PWM_SIFIVE_CMPWIDTH) - 1); + inactive = (1U << PWM_SIFIVE_CMPWIDTH) - 1 - frac; mutex_lock(&ddata->lock); if (state->period != ddata->approx_period) { @@ -190,7 +192,7 @@ static int pwm_sifive_apply(struct pwm_chip *chip, struct pwm_device *pwm, } } - writel(frac, ddata->regs + PWM_SIFIVE_PWMCMP(pwm->hwpwm)); + writel(inactive, ddata->regs + PWM_SIFIVE_PWMCMP(pwm->hwpwm)); if (!state->enabled) clk_disable(ddata->clk); From patchwork Tue Dec 24 09:39:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nylon Chen X-Patchwork-Id: 13919777 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DD13BE7718D for ; Tue, 24 Dec 2024 09:28:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=/xlYYNxyrbcxNSgAoZZpBXIFn394bhgsgfBqwsCMjKA=; b=1x+u53VRUIovyW mpi+K6tFXoqVHels+XLEIsA4MxzpWg4f8oIC5Gd7PLHvTC0dKzWNwS/C8+MmIKx1wSSiWMirytcoF PgTZoGbVkTGZ/W4l0p/pnBFk/lELvkcSnF398I1ZKx55Df4jf0c/Geomknk3RXqbyRANvdZVGgezt 92V3PxKwIrRkXTqfTHgkrSMmc6cJW07ZI8UW9Tqh5yW/sJz9HAXargNetp92pliXYwgcCtCJFipEa aEw81JmCTAXOtMU0FlDO09iB1Mm5xZNKH2vGBGb/lRqGso3NAlAZ6iR8WjjISCEZmbBwZnxmpb3xv Bp/lhHpIrgN9gGGvg2vw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tQ1DE-0000000BaS6-09iF; Tue, 24 Dec 2024 09:28:24 +0000 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tQ1DA-0000000BaPo-2F5U for linux-riscv@lists.infradead.org; Tue, 24 Dec 2024 09:28:22 +0000 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-215770613dbso36319435ad.2 for ; Tue, 24 Dec 2024 01:28:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1735032500; x=1735637300; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/Cqj4QIom4PNiBzVEbYX0WUBXZ7DUraiDzK4MrzGYzY=; b=WmXe0ZW+KIWbU9TWEbO7ui+XOTWOASeyyZutsOfF12nlU7gqdcKgpL1NSk+HAs+KY+ uG4TdXWOy/uFZiJ+ovUQn/8gtOUtwuVOsH6ayPUE3mjDYohonYr8KrWBNeFsH9DRAdeA 4kRr28a3gZR1xdkYvII4jnQFPllXz6RJfwbJBWfBvQcpnng/W73UyICUH/WxWdMvC+Zo SZrcTah09zcE2EK1/KGUNMTmczhyyZqiu7xpNam2hWrPl+TCvrSz1YkzpNQmRjk5iJ/R JWanqGTYMW85wlqgESsCIiuC90dFZK5YJJke+7Xk/xO3qw/B04c6xud3R/5KXlSxrRGc AxQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735032500; x=1735637300; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/Cqj4QIom4PNiBzVEbYX0WUBXZ7DUraiDzK4MrzGYzY=; b=RIYwfOUzBJr7Ar5Oxs9irxusVOfEmIkL0zGW3DhpGOMErdUbupYJewpD01ZnURvYqf 4TWyNYxHLffAZTTvPjA5rkeC0y+zy+iAAPi02sRT9f5DNQb/jROGbswTBHW/lCEv55VT LsNLKECIxjRRUaFWeHRIF7pDpFc1Xf4PSMyL4wg48TXxFFdAWW2fD5tKsXnRKcaw71Tm B8wPyWe5EfeYzqanKrK12dbg0HHfViQcS/x7iEYNO2qIPbzTPK0I76ovUMUCCduneYHK RabIWpiB0mR18h7az1//TxbuMR/nJ2HilbHu+PublsL8jP4oonJ42nnh0cRivmewIZfW kdyA== X-Forwarded-Encrypted: i=1; AJvYcCXD2Qa3LJ5qa1eNG/J9OnvgCpj9TE+FIrqGnB/1YbjmkXRNxv/hmiypPKJQIOu8WARHrUi1y965N6bddQ==@lists.infradead.org X-Gm-Message-State: AOJu0Yz73dL9xkiRCq3KknXPV88ntyruKWs/cDy6/JeeYz7amgFlENM/ TabQlT1VnUXBHCb9u+GL/LeJhaVk0RWOTMvUR4i/f851dtiKB8fpZ9QwlX8siNY= X-Gm-Gg: ASbGncvWQiLnnJgoeWPJTisx7a+SQk6NHJ77PIvmqEmPcgmdeHZVHCp8YaK27e7kXah enG+fnKqtf9CN0I0kgO4JyOaL+j0Ia25kwiJMflk8wHVUfB3KL5JjQPP22VwjmobfP5UlFp9azm WY8ewjcpA/X4gE08t60wIAFLRNNsXm6jd3A2iDkKFtY135APl9LdMJ6iY2tqj6Lp8SRBPqm5340 qGs4BjXHeSztaY21YrAXSAzGPQYJgj1qE4vjvZs0F05Dkileb8pVLmtNmc6e/JzyXJF4PO/uNKZ JuQ2wyUfWtVVdv63Bg== X-Google-Smtp-Source: AGHT+IEa+eM9lY5Aysf3MKkJti9gL8QjP+GyONH2JGutRyVpSEtvumQ8tbWG/KyFFjxNZfvlfPun/g== X-Received: by 2002:a05:6a21:6da9:b0:1db:e338:ab0a with SMTP id adf61e73a8af0-1e5e0447f5bmr29850414637.8.1735032499994; Tue, 24 Dec 2024 01:28:19 -0800 (PST) Received: from hsinchu36-syssw02.internal.sifive.com ([210.176.154.34]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72af8dcff60sm516341b3a.152.2024.12.24.01.28.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Dec 2024 01:28:19 -0800 (PST) From: Nylon Chen To: linux-kernel@vger.kernel.org, linux-pwm@vger.kernel.org, devicetree@vger.kernel.org Cc: Nylon Chen , Zong Li , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Paul Walmsley , Samuel Holland , linux-riscv@lists.infradead.org Subject: [PATCH v10 3/3] pwm: sifive: Fix the error in the idempotent test within the pwm_apply_state_debug function Date: Tue, 24 Dec 2024 17:39:01 +0800 Message-Id: <20241224093902.1632627-4-nylon.chen@sifive.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241224093902.1632627-1-nylon.chen@sifive.com> References: <20241224093902.1632627-1-nylon.chen@sifive.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241224_012820_590963_060FBC77 X-CRM114-Status: GOOD ( 10.96 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Round the result to the nearest whole number. This ensures that real_period is always a reasonable integer that is not lower than the actual value. e.g. $ echo 110 > /sys/devices/platform/led-controller-1/leds/d12/brightness $ .apply is not idempotent (ena=1 pol=0 1739692/4032985) -> (ena=1 pol=0 1739630/4032985) Co-developed-by: Zong Li Signed-off-by: Zong Li Signed-off-by: Nylon Chen --- drivers/pwm/pwm-sifive.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/pwm/pwm-sifive.c b/drivers/pwm/pwm-sifive.c index bb9146267bc5..6259f8500f71 100644 --- a/drivers/pwm/pwm-sifive.c +++ b/drivers/pwm/pwm-sifive.c @@ -101,7 +101,7 @@ static void pwm_sifive_update_clock(struct pwm_sifive_ddata *ddata, /* As scale <= 15 the shift operation cannot overflow. */ num = (unsigned long long)NSEC_PER_SEC << (PWM_SIFIVE_CMPWIDTH + scale); - ddata->real_period = div64_ul(num, rate); + ddata->real_period = DIV_ROUND_UP_ULL(num, rate); dev_dbg(ddata->parent, "New real_period = %u ns\n", ddata->real_period); }