From patchwork Tue Jan 16 04:10:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nylon Chen X-Patchwork-Id: 13520400 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 6B310C4706C for ; Tue, 16 Jan 2024 04:11:56 +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=V+USSoIdbe/xx1jQsX4VTxttr9lr+kb6CXHQ9zxkvCw=; b=j8O77QYDBzzE3X wL9ZZtpBUkbgN0efXQW2np6Jo+de+xU3ilct5ewNcA1TU60NhNZqaB1mT/oMZK2IjeWLzYfS5Fs8s XU8BSJWVOEgFMOznKwciuQ8FCEiEvNPQ1Ef4lqlPcUS8gc5gcOoV/jmkMSTVsKwtHStHDYjrWolKa lXcAPdcLI0n+FXdhHr4dV8gnE/b3GiAZN0GAIn1z5u1EtzRtGJfkFW7J8Z2yeY6ELHeIe8JE4E/AH ZRBnJpaR5UbZN9oo1kvlN1h6sg3kpdNIP4oTc6qPsXaYxIOlbAHDXaUBxcwgd1HZsyf0j9LJoMOoC NCIH9OFM4ZqcLc6P1zAQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rPanG-00AtSz-1M; Tue, 16 Jan 2024 04:11:18 +0000 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rPanC-00AtRs-0F for linux-riscv@lists.infradead.org; Tue, 16 Jan 2024 04:11:16 +0000 Received: by mail-pj1-x102e.google.com with SMTP id 98e67ed59e1d1-28c0565df34so4762349a91.0 for ; Mon, 15 Jan 2024 20:11:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1705378270; x=1705983070; 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=lNWOGH7VpQY6V8fQKtozhdwdDDbXnjZtAA+yG72Gg0I=; b=H6tj0xlHtJjTrXEJtrHsUpTQXfqOSCeOHh60EBagGvBX0xfrWSzqfXkWNbagbVX8/h crRM3TPqjgytjoQ916C8k8u0FSWAuN92RTAOirv/MZAP5Z0TlNRYWfUyICyAijb3frnP 6DnqCK9zVBUOY6G1p0PKWtN7M60jEEEEJv7fYa845Xl2heZw83Kfrib+PDAr283jbs01 fvlZDiabaITtWRvUR5carrzjzQNVJqtC9SAQ36BkQuzPGB/9O+Shia2R2BF40rMuyubp Ni48pv7dYoCuMQj5dKEpp0UOkhonFMWN8VQ1oeeS87b3ROYpfOde+CGlhiEupwNbT2cv eOew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705378270; x=1705983070; 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=lNWOGH7VpQY6V8fQKtozhdwdDDbXnjZtAA+yG72Gg0I=; b=aunP58hUDa9TMxu+N1ceQ67xWOB5dKau6T1PAVDGMUfpRcKAx5mDU7XhluNh7mRoH8 lqeFezoQHqDOtYkQ1tSTQgSems9lozZ5OT5yVE5hcY/jxfgquhHWbPf6TFscz909TjDc GLte+2UqaxtDfeF534jHSdDkIJOkWbWy4/fqh32m8ZhZmZKTOrust9sjNeP4g43dXmL1 QJFz3eU2MwjXNEnHCGyNvpmzWB3c/hLJDcBkS1iWMXWijmtdhJi8aBrKJVrz/sH46nvN UE/liNTbfeVrQwbEovWxdl/DYWDngnUvIlfZb/WIO8tjNTqHjelye8FN/eIKbCRaht5z 3uQA== X-Gm-Message-State: AOJu0YwfZ9H8yAkQ9RaltjykVMzo7Ce6vI58J0zHmtRxvyOIefvCtRQ7 3EQRiTIBD4NMfj0N4Msi2kJuKux96WKgOg== X-Google-Smtp-Source: AGHT+IHdLaq3l3g4Pmg80E7WRUhrwEdvo239qSRGLCobH/JD2z9cKN13WMng5fzHJO29R4gzkXw4UQ== X-Received: by 2002:a05:6a00:4f8c:b0:6d9:aa4b:3800 with SMTP id ld12-20020a056a004f8c00b006d9aa4b3800mr3973757pfb.19.1705378270417; Mon, 15 Jan 2024 20:11:10 -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 e3-20020a056a0000c300b006da14f68ac1sm8348585pfj.198.2024.01.15.20.11.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jan 2024 20:11:10 -0800 (PST) From: Nylon Chen To: paul.walmsley@sifive.com, palmer@dabbelt.com, conor+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, robh+dt@kernel.org, u.kleine-koenig@pengutronix.de, thierry.reding@gmail.com, aou@eecs.berkeley.edu Cc: zong.li@sifve.com, vincent.chen@sifive.com, linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, devicetree@vger.kernel.org, nylon7717@gmail.com, Nylon Chen , Conor Dooley Subject: [v6 1/3] riscv: dts: sifive: unleashed/unmatched: Remove PWM controlled LED's active-low properties Date: Tue, 16 Jan 2024 12:10:52 +0800 Message-ID: <20240116041054.11641-2-nylon.chen@sifive.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240116041054.11641-1-nylon.chen@sifive.com> References: <20240116041054.11641-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-20240115_201114_113796_462ED315 X-CRM114-Status: UNSURE ( 8.81 ) 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 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 | 8 ++++---- arch/riscv/boot/dts/sifive/hifive-unmatched-a00.dts | 12 ++++-------- 2 files changed, 8 insertions(+), 12 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..11e7ac1c54bb 100644 --- a/arch/riscv/boot/dts/sifive/hifive-unleashed-a00.dts +++ b/arch/riscv/boot/dts/sifive/hifive-unleashed-a00.dts @@ -49,7 +49,7 @@ led-controller { compatible = "pwm-leds"; led-d1 { - pwms = <&pwm0 0 7812500 PWM_POLARITY_INVERTED>; + pwms = <&pwm0 0 7812500 0>; active-low; color = ; max-brightness = <255>; @@ -57,7 +57,7 @@ led-d1 { }; led-d2 { - pwms = <&pwm0 1 7812500 PWM_POLARITY_INVERTED>; + pwms = <&pwm0 1 7812500 0>; active-low; color = ; max-brightness = <255>; @@ -65,7 +65,7 @@ led-d2 { }; led-d3 { - pwms = <&pwm0 2 7812500 PWM_POLARITY_INVERTED>; + pwms = <&pwm0 2 7812500 0>; active-low; color = ; max-brightness = <255>; @@ -73,7 +73,7 @@ led-d3 { }; led-d4 { - pwms = <&pwm0 3 7812500 PWM_POLARITY_INVERTED>; + pwms = <&pwm0 3 7812500 0>; active-low; color = ; max-brightness = <255>; 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 16 04:10:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nylon Chen X-Patchwork-Id: 13520399 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 7CBB6C47077 for ; Tue, 16 Jan 2024 04:11:54 +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=APcQ3s6xluK/bx Q1JX4wWAcXZMnNSsSnOv8KcZdtkEg21Nzb+JhdA19wJCH8cbmxz9Kls9d9oRQTDIxl+8mZq8XEcgH WEnkOBNKewGdDT43FKUfBZMFS4Md1W8lNF8K1ui6fYAUBcks/Auzcd9RSd7IqFgQYz3RDW3R6mpeh 4ROCYa/Kobx+WlZ3vTa/HUoLriruVlP4hMf08hVgTWvvmkfCWwjmDHEYmpsBqTEUAiLuGrgbOoFBH 3H6hheDvwqHLtS472iu2D0L6RBB4Sqd1sRaDFyDbTK4VtefDoXGIPpC7NFzC4fF4LimntHvpxBxb1 O8rAWrTRRmtaRGkGMACA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rPanJ-00AtTq-0C; Tue, 16 Jan 2024 04:11:21 +0000 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rPanF-00AtSj-2j for linux-riscv@lists.infradead.org; Tue, 16 Jan 2024 04:11:19 +0000 Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-6d9b050e88cso5024838b3a.0 for ; Mon, 15 Jan 2024 20:11:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1705378277; x=1705983077; 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=H+I8dl3zWNAtXc5HNBauaEoiD8wugUT9KSTA4jNn2q1WsDKMV1B6Ppbz7XiNCGvnzv 2+8Md28+yehCQkkgDe92KQx1ip6/63SlOVw7vBngUM7YuViRFhjAi3khFrTIjZyyGb7r VyJBjDQERdg2u9wM6RllEmB4senICWSlR9r8XuX/m08pbC7RZ8Q4nTB0Q6Krd5z//7H2 L3yum2sGm+cYquCmojtqOujd696nPaD3+oecOOQnbCflLQfKTnilw4LbRTDRctHvq19T 17rDc4q0Y8hv5fnVxu4JJagjAV8efY4dCiXsc5cE9VvSd5K1BJpl+zjgd8d3Hi+fFSwT X4lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705378277; x=1705983077; 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=Y5LUNy/BC455C171zWgqFET8KdAECrFRo/8XOPKgp6UwK4E6uX+SIzHmLT07YJ46si Js/J4s9rdoscKMfIiceQR+KPwUMa7pWMu1pnrtuJcqKum1khjAcQkLCZxhoZPmxoUH2l /28GNYUL/8rq/s9em2oBcVp9uJhzG8LJPkxXTaXp0Em2KMaHRZ4Z2whPdZ1mEG69ynZA u57ZqRfhbVyYD1q77Yps+u9mS+f2o2/mZBTS9i7qrHeg3tyf7MRCGSYMJX/nOfQEYDAD BYJJM2fOZIKiJRRnSCGAC7oGBsAlM75HRQ4Vgly/M09ZxfVAnSnb590SAnXYw8l9vYhu Sjnw== X-Gm-Message-State: AOJu0YxXvRj4p74QxWyyRjKwE4iZerreVPzGqNDr+dxtvHr/8a6vU/PV RVb1+24O4j8ahQ8bZ79NHDitgzJnhe7riA== X-Google-Smtp-Source: AGHT+IG4zOe8NzCeVSultkWt1XQwNctUoDlTJ4OIW6NLAkI0tLrSKUSMFFkhBRuhQ882cjQ7OEj/Sw== X-Received: by 2002:a05:6a00:2a04:b0:6da:b010:e863 with SMTP id ce4-20020a056a002a0400b006dab010e863mr3534499pfb.55.1705378276814; Mon, 15 Jan 2024 20:11:16 -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 e3-20020a056a0000c300b006da14f68ac1sm8348585pfj.198.2024.01.15.20.11.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jan 2024 20:11:16 -0800 (PST) From: Nylon Chen To: paul.walmsley@sifive.com, palmer@dabbelt.com, conor+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, robh+dt@kernel.org, u.kleine-koenig@pengutronix.de, thierry.reding@gmail.com, aou@eecs.berkeley.edu Cc: zong.li@sifve.com, vincent.chen@sifive.com, linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, devicetree@vger.kernel.org, nylon7717@gmail.com, Nylon Chen Subject: [v6 2/3] pwm: sifive: change the PWM controlled LED algorithm Date: Tue, 16 Jan 2024 12:10:53 +0800 Message-ID: <20240116041054.11641-3-nylon.chen@sifive.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240116041054.11641-1-nylon.chen@sifive.com> References: <20240116041054.11641-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-20240115_201117_883633_8270504A X-CRM114-Status: GOOD ( 10.26 ) 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 16 04:10:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nylon Chen X-Patchwork-Id: 13520402 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 23E76C4706C for ; Tue, 16 Jan 2024 04:12:48 +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=n4SedTHosP/X0i eQy9kh2yh6VyoBUmkKtvArSfVbYSS774iCTFx/9lhw2RVurxKAnZp20HGw1EfBWBp3haim7RCeeLH /zYQMvGz3jNFTYms6TvgNrP+kfB1bBpzY2yJX/HrIHXKIz6iw6KAjmvxtAxqrULc7bTzkH613K35N 2F/h3K5bB6UTWF2kQj5UoKG7WQvrNrV7J79nRK/Fh0OhIwfnLK4SAFgVOELe48crVftwBUWXSmD7S K7ycZyE95aHLsGZTK+7SUqJebvHoqJEoIL0jgu1WAM74QPd2Kw+6tFPWyoLH10GsFlUDe/OJ9cB7k 3wOkYmQ1EUDk8vx48nTg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rPaoN-00Atn7-1e; Tue, 16 Jan 2024 04:12:27 +0000 Received: from mail-oo1-f42.google.com ([209.85.161.42]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rPaoK-00Atlf-39 for linux-riscv@lists.infradead.org; Tue, 16 Jan 2024 04:12:26 +0000 Received: by mail-oo1-f42.google.com with SMTP id 006d021491bc7-5990de0ea91so451381eaf.1 for ; Mon, 15 Jan 2024 20:12:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1705378283; x=1705983083; 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=l8NurvZMYZvaEjoSK1fBBEdl7EN+J4LBfSjCwxoF6J1uGjx3mLupMyq/cjBhb8KhHW Cxw3Gn45UjQqMlkBsHaP1pVpe/r3oAAgy2Y1PxX9wSSgyfe9UzuqI1wBjDch5eXGz5+P sLP4rhalv9Yjg+XFjPKzOvKWk/S83cWdNuPFjN3T7rsqLBO74BpCZ5bNS7JEiVACld8t QqO30wsEbESYnaQbvyXSbqkHCH5u7FDWcRK3IiUJA5077GAc/fa4eGwKeTzOHMkAy4Un W6YV5fUJd4l3ECZdbHDY9nJsQeGTYSpCnc4E5qD3uukle8wKmj8kHgO03b9EkL4OKNg5 dc9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705378283; x=1705983083; 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=Lr1t3UrO3vzzO6w1KXdDUulniA4x2hvN7w0BAZJrAZMX4gInOxg8RqXRt9d4UdHyW7 0ZxlPiONpf19dkpN4y4+m5UvBQPIBY3uZDWTwuKszsLkqxq0qHFS06Dxx+f+QuX8WCXo r5z/JTY6OWKSDG3hhk9WehBRMgaJpwqaRNuiXaakiCpD3IXxBW7XNwSr2ESMm7bF73eR wnG+WuyGMBZ2iaigrguqh6igCDIPjyujI7u5zey/LAY0Z5wmkTeGiIgleIz4UV6KgIgK cJ+ZFt0FCaNVspA1ByBGotoJ+qTIxVUDiM1k7mJO5k4M/7/XEf7lZoopU2RCVO36gue2 l6Ag== X-Gm-Message-State: AOJu0Yycu7Fbd8CsHG7chakUJWcfMCAyqsKm9mqB2CfQCXg2v1/d1rmM yG++bjl0i58k5EdfJqxr29v1izpRp8LsGA== X-Google-Smtp-Source: AGHT+IHY8wqSPbSfWTDr8kZnGoqer2JRIbsG2vuaQFhUvm3Jtx2vE59XTqMvUSiKzXWuROP6xyBF3Q== X-Received: by 2002:a05:6358:924:b0:175:d42f:6c63 with SMTP id r36-20020a056358092400b00175d42f6c63mr4731065rwi.36.1705378282820; Mon, 15 Jan 2024 20:11:22 -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 e3-20020a056a0000c300b006da14f68ac1sm8348585pfj.198.2024.01.15.20.11.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jan 2024 20:11:22 -0800 (PST) From: Nylon Chen To: paul.walmsley@sifive.com, palmer@dabbelt.com, conor+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, robh+dt@kernel.org, u.kleine-koenig@pengutronix.de, thierry.reding@gmail.com, aou@eecs.berkeley.edu Cc: zong.li@sifve.com, vincent.chen@sifive.com, linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, devicetree@vger.kernel.org, nylon7717@gmail.com, Nylon Chen Subject: [v6 3/3] pwm: sifive: Fix the error in the idempotent test within the pwm_apply_state_debug function Date: Tue, 16 Jan 2024 12:10:54 +0800 Message-ID: <20240116041054.11641-4-nylon.chen@sifive.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240116041054.11641-1-nylon.chen@sifive.com> References: <20240116041054.11641-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-20240115_201225_010700_741E6C1B X-CRM114-Status: GOOD ( 10.64 ) 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); }