From patchwork Tue Jan 23 06:17:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nylon Chen X-Patchwork-Id: 13526878 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 87D91C47DDF for ; Tue, 23 Jan 2024 06:18:21 +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=kMAmznsg+i4/2p67HSGoXmunF5RKocbKIB8JaQ9qzLw=; b=bvUWEOg3NjMZSV AEoe+HdXiPaJMi7XHLFtVPPc0Xil4HYS7gNciZ6IBQlmJn0ODEkyX/9JMz9fmVVs/n0x2WYQ+KCPU T+5rEEnoxfTzWKjg1vj8aJ4q2iWB3pTHlhuwp3HS+vD5URm3JDGXbkbsU02WTf3elF1GgGCgSi3M2 6ozjlj96ZdpVWkTncwZTjyRuns8//IrEnxxcxUD6AciBJkqrXC3EPrEkp3In7grJiitLOMEH1S7MP /m5dQ2WLrm1ZcBBIpayihIrBVMfaNERpUCOKKfMsymwyXUQ6OXXJfhSrqxin8mBI/+RXfbDUenvH8 nR5Xa9/CPbEHfWCkxYog==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rSA6o-00FEpr-2i; Tue, 23 Jan 2024 06:18:06 +0000 Received: from mail-pg1-x529.google.com ([2607:f8b0:4864:20::529]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rSA6k-00FEml-2D for linux-riscv@lists.infradead.org; Tue, 23 Jan 2024 06:18:04 +0000 Received: by mail-pg1-x529.google.com with SMTP id 41be03b00d2f7-5cfb81124ecso2799369a12.2 for ; Mon, 22 Jan 2024 22:17:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1705990679; x=1706595479; 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=ME8YwPbdKoUEBb8pwsupWQGlI6P3cfXncKX/A/ie+p0=; b=XhmQ+omHwbJWigVUh2MhfSD0+S0zLkqwFfNaYLb6vhOQukd1g043QagZdYqibIrSOB hFjUG+eDYyBMNjtYOghnEHshm+jCCSmZ86HzmndVBXXA4KcyzU/bFdDO7AqgjgeLQrMV R7+NJEOun0xP7E/YLf60JzDOPJDouR9rKkoID5jr95DePcKDkJurSIqUvrQ2GZjHQTp0 kKt9p7gkU9wMCsTS5S/8Jx3jlNC0Dpuu6Ojmz+QD7t+YKvewHjR0yjnAmvIcwG7VsRhV VOPPF2gDGqc/qHbbNrc7OMF0Fv/9yOtjvi1m93Ri6eihhuZQ8RNxIkDq9N4GUUcvFHd/ nBQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705990679; x=1706595479; 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=ME8YwPbdKoUEBb8pwsupWQGlI6P3cfXncKX/A/ie+p0=; b=FlFjBBiVn70yKi72p83iysDnAjWq3ueDEFG+wQ1wmi+h1lb0K24ofo+WI8WFLFigMy hsgssUk2xO5rN4D/XyeavmehB8B0n0qGzB8nZF2udW9YKQe9WwOfT12AiAFbUrnbmTP9 gOJIeWjnJHRDGVyiPUz4anjKuT7kRzB3ewiYZ6vN9zYAYyo5gyHA6kHtOmFW3k0OXYJ9 dOR6rtMR9Sq71ev3xvcwCO3Xhk986Ov7g0kGht0QVLL7l6L5Z0uoQcoTrK+hn+u7N8WK fzWugfDfqmxYvCCWL90bVZeuRtqRqt5FRXdDDhnYO49jDqcokeoMig5OGYriaaW+lKaG n3MA== X-Gm-Message-State: AOJu0Yy6/v2e8aautGe1HWwf26AU6GDfO9URC8AEXM5l3b2sNjyaXGNX 1XJvZDMkXRS7B+9s6AkPsehQVoe5nocH/e9pWqk+I2gVB8Xx0K4e+qpmmOf+LX5Sr2n2XAj7LYS 1qYGUnR3/CcLqHG7b8fp1ghnzXV3HkGr6WEidAFhHK15oRp2LV4BF3rcrx+nNgk9aCV5/yTcwuU mOOcDwkzKMA/qh6Ql21SyJZz+ijNXRSYBB8n8uhdPvFHZZTVN50EI= X-Google-Smtp-Source: AGHT+IGilp1NHJ+bOxCNhyXEG/4JAD2rrjQuIW5uobXx3C9HXC0+T93+AoaL+nis4sBdTei7ICbDBA== X-Received: by 2002:a05:6a20:4387:b0:19c:4fcd:fab6 with SMTP id i7-20020a056a20438700b0019c4fcdfab6mr1483066pzl.40.1705990678572; Mon, 22 Jan 2024 22:17:58 -0800 (PST) Received: from hsinchu15.internal.sifive.com (59-124-168-89.hinet-ip.hinet.net. [59.124.168.89]) by smtp.gmail.com with ESMTPSA id p7-20020a170902b08700b001d733c88646sm4425376plr.216.2024.01.22.22.17.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 22:17:58 -0800 (PST) From: Nylon Chen To: linux-riscv@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pwm@vger.kernel.org, conor@kernel.org, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, palmer@dabbelt.com, paul.walmsley@sifive.com, aou@eecs.berkeley.edu, thierry.reding@gmail.com, u.kleine-koenig@pengutronix.de Cc: vincent.chen@sifive.com, zong.li@sifve.com, nylon.chen@sifive.com, nylon7717@gmail.com Subject: [PATCH v7 1/3] riscv: dts: sifive: unleashed/unmatched: Remove PWM controlled LED's active-low properties Date: Tue, 23 Jan 2024 14:17:46 +0800 Message-ID: <20240123061748.8844-2-nylon.chen@sifive.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240123061748.8844-1-nylon.chen@sifive.com> References: <20240123061748.8844-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-20240122_221802_720465_17D6C7F6 X-CRM114-Status: UNSURE ( 8.17 ) 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] 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 --- 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 07387f9c135c..b328ee80693f 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 Jan 23 06:17:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nylon Chen X-Patchwork-Id: 13526877 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 4A1D8C47DDB for ; Tue, 23 Jan 2024 06:18:21 +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=FJv2YHnKX5rnLo2+S6z4iKc3N6EQdjw72YuI3Y4ADX8=; b=xpkJV+95uJHS1J Zle3I3xnX92hf1QfmmID+MDyo5crUULJ4GIBC86LqTJUO0LMbhEGtVfL0r4PD/LexIE5vCA+Rx9xy TpbRwzab2t67EqEFs/Ryub8mobIh+mtX56lMDzm9dpQOhuj1HgJvSB+p/JPPwn5xlcr5h4B8JfMfz PVDKOKjcuBMizru0NT9tkC6I0qV1f1DsDpYODl9g/Cf1GKTp/kst5ZiFJeF2AiLIRWc8OchDA7XxV YL1VifxjrfXr1LzvvCCj+Cci3bYvvOFhSlRhJG6IvHjGVa+Mimef490TWnBTAEkgprUdYrvZoJ945 ajs2sHrJM4eBikLAXuWw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rSA6r-00FEro-1u; Tue, 23 Jan 2024 06:18:09 +0000 Received: from mail-pg1-x535.google.com ([2607:f8b0:4864:20::535]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rSA6m-00FEoD-2b for linux-riscv@lists.infradead.org; Tue, 23 Jan 2024 06:18:06 +0000 Received: by mail-pg1-x535.google.com with SMTP id 41be03b00d2f7-5d3907ff128so170491a12.3 for ; Mon, 22 Jan 2024 22:18:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1705990683; x=1706595483; 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=cvJrbymRDVqsWiIagFJrDLqKjAGvymGFfMj4nY9d7Jo=; b=b1FPhErsRKRYa3jGL6i12pfpuDQvj1D3VUbUOACb+44MTFTatkQaqlLx4NU8T5jT8h zC4aUl7B2npp5n5Ib99+zpbs/IPVy/zj8TomDmSgEOiR7GCq1OnspP2pYWIvawsqPe7b XhEwDtWqpqyIVA/2Lq2xgRhijYA8UyRImd4OZ5DyTjb/zTLvp77TudpH3ZCYEBudmqnG fhKnHuZeyeb4WjfQEKnmb9mSRwfoG3F8vB5IhVemWrLetTT9gvVRPvfrREZh/9zvge7q pve0NoHvkn2IhiofD2RRQKua59gmZpUUd9v9l8JY8pXU+9ZKpBYli7jTflWGNiDVoYrn Bl7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705990683; x=1706595483; 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=cvJrbymRDVqsWiIagFJrDLqKjAGvymGFfMj4nY9d7Jo=; b=Jx5/pdT8/WtvMq5PnJDiwJLJPcH6whMokm3TQST/b3lFpDLngYwTJmMS5M9iQwzAtq 2a6mnkuEnLKl6O25lE9xd2UCnqWpgyiVu/Jr+uFstU3qTJAZC5NhDCYLjwjTsPVqdb5n lE7d3hN40aui9EUmNMyjwpUvv8Sua+5Wg2qHBiqNdr+eUdyokdGEXYpBuzK+xXufP1O7 KXudQVCPoZzOOPyMoNbmUrVqSQLQkGit7oeXOB40gI5uhEPXi6fLvhOAdnEtbGwm6WlR CatgxSdrfOgXajpVeEfAK8jO7BJMUfAa1TueCtfqE8vGzygnQRngXeehh8P9D81jgt+d JzJQ== X-Gm-Message-State: AOJu0YxPHsqjTe6M+B7bqOdfQjCbPZnqigLrfnfyD4z88gewjI7Nz803 /zpzulrBCUC6TJjtzg/n/PAwVM5KH7BHUlnbaNFwMJgEG/3UzQ2NuGWS09CRxZc2S4KdyDHv4qO rddqUIodKl4dBkGmi9XRSXlEMsKppj2o5oiWzmNKxafLvfp+y4T04MMF/grqzoHmZSWdu+P6Dz3 vqbErffom4/RqigblUjBh/0XPOSrqSQQ3IpFkGE57MBviHh9fbCC8= X-Google-Smtp-Source: AGHT+IEOZE+FU/vU9PCxfaGkCTPgaFa/4ycXAtuyVM2ziXvmuqSrHD4wV/6kejsabMmCEqh/hFuYzQ== X-Received: by 2002:a05:6a20:3d96:b0:19a:da41:9da with SMTP id s22-20020a056a203d9600b0019ada4109damr6938288pzi.13.1705990682643; Mon, 22 Jan 2024 22:18:02 -0800 (PST) Received: from hsinchu15.internal.sifive.com (59-124-168-89.hinet-ip.hinet.net. [59.124.168.89]) by smtp.gmail.com with ESMTPSA id p7-20020a170902b08700b001d733c88646sm4425376plr.216.2024.01.22.22.17.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 22:18:02 -0800 (PST) From: Nylon Chen To: linux-riscv@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pwm@vger.kernel.org, conor@kernel.org, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, palmer@dabbelt.com, paul.walmsley@sifive.com, aou@eecs.berkeley.edu, thierry.reding@gmail.com, u.kleine-koenig@pengutronix.de Cc: vincent.chen@sifive.com, zong.li@sifve.com, nylon.chen@sifive.com, nylon7717@gmail.com Subject: [PATCH v7 2/3] pwm: sifive: change the PWM controlled LED algorithm Date: Tue, 23 Jan 2024 14:17:47 +0800 Message-ID: <20240123061748.8844-3-nylon.chen@sifive.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240123061748.8844-1-nylon.chen@sifive.com> References: <20240123061748.8844-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-20240122_221804_845249_288211BE X-CRM114-Status: GOOD ( 10.58 ) 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 | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/pwm/pwm-sifive.c b/drivers/pwm/pwm-sifive.c index eabddb7c7820..b07c8598bb21 100644 --- a/drivers/pwm/pwm-sifive.c +++ b/drivers/pwm/pwm-sifive.c @@ -113,6 +113,7 @@ static int pwm_sifive_get_state(struct pwm_chip *chip, struct pwm_device *pwm, u32 duty, val; duty = readl(ddata->regs + PWM_SIFIVE_PWMCMP(pwm->hwpwm)); + duty = (1U << PWM_SIFIVE_CMPWIDTH) - 1 - duty; state->enabled = duty > 0; @@ -123,11 +124,10 @@ 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; } - static int pwm_sifive_apply(struct pwm_chip *chip, struct pwm_device *pwm, const struct pwm_state *state) { @@ -139,7 +139,7 @@ static int pwm_sifive_apply(struct pwm_chip *chip, struct pwm_device *pwm, int ret = 0; u32 frac; - if (state->polarity != PWM_POLARITY_INVERSED) + if (state->polarity != PWM_POLARITY_NORMAL) return -EINVAL; cur_state = pwm->state; @@ -159,6 +159,7 @@ static int pwm_sifive_apply(struct pwm_chip *chip, struct pwm_device *pwm, frac = DIV64_U64_ROUND_CLOSEST(num, state->period); /* The hardware cannot generate a 100% duty cycle */ frac = min(frac, (1U << PWM_SIFIVE_CMPWIDTH) - 1); + frac = (1U << PWM_SIFIVE_CMPWIDTH) - 1 - frac; mutex_lock(&ddata->lock); if (state->period != ddata->approx_period) { From patchwork Tue Jan 23 06:17:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nylon Chen X-Patchwork-Id: 13526876 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 732A4C47258 for ; Tue, 23 Jan 2024 06:18:21 +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=CO3Dbq8tbp9VaGvC3KS7qgxMiRyMVBH/naVESivXDxI=; b=UVelyP8ArXttv5 SpD+6aGRJGGpu4fqvzMtSwe/3GLt4BSXmkHLElzikH75aFt0RUtKvGwGDl4cvri96PwdKO3dFSiwi Ju5nn3dXpSI33IOAcb2m6+UNOULCy7xMtc6QoFkB/agaLhFjVtG2jo4s7KeKzZ1XbBHM0uHvKUvRI lVtymHvlcseo5j5DFHD6+7F7/PZXDiqK4cJBuh9C4ZaCurduE3pZvc6dyBZzotELjXd21fE1cu3zg KcP0y8CEdv/B4Pc1rkhuIo+0AYt0r9iovrsTByuf6MlNZ+mLhJ7LnWdanhX9pNeaw+OzB5revbmCX st5CCfnTbfZQa2PtG01A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rSA6u-00FEts-1o; Tue, 23 Jan 2024 06:18:12 +0000 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rSA6s-00FEqU-1M for linux-riscv@lists.infradead.org; Tue, 23 Jan 2024 06:18:11 +0000 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1d72f71f222so10752045ad.1 for ; Mon, 22 Jan 2024 22:18:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1705990687; x=1706595487; 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=nYo9wXWOZdh4xBQbuTEOxrcqZQMwofEU/9c/S0MDuwU=; b=cDMoyPUBoXDyLvXbqN/iYnz1LF1bV24bc8Y90Ueao8bwnEJR0JmhLE6z7b6InZ0mbT CPko+78MamWshwiCBHzRmuSCu0Dvc4F9k9qXHUwn5qdwZxqGRrq5OWNbolqi3fVcWmhs YsWdHoiB1MGlebGRxUP/zI84maKBzMLU1QX2lzxWtsxEjdprJ5JIf3xRM4Zgaw/mUoMn DZuk6pgYiiiAn3nAFX2Rf52AjL57mw2u/2MUHKGXgoFB0dcOw+f49ArLfe403hZfhh24 zD70f/bWKHNK1HH1PDoPf4Ioxca79wcmFvQgkWdrzhcvtjZFkIU8u8vMxBXmNLKUnNrj ArSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705990687; x=1706595487; 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=nYo9wXWOZdh4xBQbuTEOxrcqZQMwofEU/9c/S0MDuwU=; b=E5gCXUgROwyzCSklNm0I44vqoImUXLoOtvi2e3NLvZzgp8qDeBsfqPQL/vwRytAbd6 bptfvzjL+hgRYNA47IXVa2/Y7TsZmtF3cUNwtEak6dSY4ghQdu+Ob7MLJAl36ZaP+qUu 6Yuee3H1e9J9h/DsswkmfNwq54KN9svQxEN5N0PcKcH/O/UhbF46Kl78wDd/Xi+1tXJe VuxgStS/mXcL48AnPyrzZK8Dj17ev8AQB6Ucq75AzPnjEexdgjMorwzAqBwNw5nB0nPm Vd1T0oqNbEw7Lab0f4bwvnW37POEeu3rOy+NXCS7fubsOCHFiaoRdcMvof15LnVrst92 fvqQ== X-Gm-Message-State: AOJu0Yy5jwTgcMk25/H4B5o2FTohvq2s/EHcaGri/2Sba0LA88DaL4Yp lgcwJaIiGSYpLUHhE27xSUVOU2ZRsbEpJ6it/jZsE1gzAapZHeGwkW5Gyxufhvf00FaaUnZeIyc XsksznGYKSk0C7yfqIK4lNQMjzGxBTHo/aJpzecZeOAYRfzSZlh2GAfznozg3DMS6TU9KvG5vXQ KL2a4jNQCq/0BhACogmr6aGxxRf4lvT2xf22CgM8LIszJ5oPwUnHg= X-Google-Smtp-Source: AGHT+IFlNaztc63RI2VKYB9Y8YhdR8gD5UHFIk3F8bWliL75YvC4TOWoaqQeAhmdUbkd+zXMJ9ZT6w== X-Received: by 2002:a17:902:7897:b0:1d5:78db:4293 with SMTP id q23-20020a170902789700b001d578db4293mr3043550pll.29.1705990686972; Mon, 22 Jan 2024 22:18:06 -0800 (PST) Received: from hsinchu15.internal.sifive.com (59-124-168-89.hinet-ip.hinet.net. [59.124.168.89]) by smtp.gmail.com with ESMTPSA id p7-20020a170902b08700b001d733c88646sm4425376plr.216.2024.01.22.22.18.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 22:18:06 -0800 (PST) From: Nylon Chen To: linux-riscv@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pwm@vger.kernel.org, conor@kernel.org, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, palmer@dabbelt.com, paul.walmsley@sifive.com, aou@eecs.berkeley.edu, thierry.reding@gmail.com, u.kleine-koenig@pengutronix.de Cc: vincent.chen@sifive.com, zong.li@sifve.com, nylon.chen@sifive.com, nylon7717@gmail.com Subject: [PATCH v7 3/3] pwm: sifive: Fix the error in the idempotent test within the pwm_apply_state_debug function Date: Tue, 23 Jan 2024 14:17:48 +0800 Message-ID: <20240123061748.8844-4-nylon.chen@sifive.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240123061748.8844-1-nylon.chen@sifive.com> References: <20240123061748.8844-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-20240122_221810_462591_8E9C408B X-CRM114-Status: GOOD ( 11.17 ) 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 b07c8598bb21..7cf7a76cdb44 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->chip.dev, "New real_period = %u ns\n", ddata->real_period); }