From patchwork Thu Feb 22 08:12:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nylon Chen X-Patchwork-Id: 13566846 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 94734C48BEB for ; Thu, 22 Feb 2024 08:12: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=FPdIHb0vFTmr28qpHV3Lk7NPX6oEa6EAGDHaMy3Oatg=; b=oAUwiFPgmG7tvm HJ2hAr+I5HEEJdpM3pIrBpzPMIVu/GY4eFp7XLVRjT1lyPH0pzNrnHrTEQkYDzuiE8roKykhS9+Gx qVW87ccItq2eWhFG05usRZg4opCJqI74hcPFVrNAouv+dFAPdZg1R9M0stPjlZ8/iXgCqmHObWpZN 67HZzti9gm4rPATYw6t4zritCIpzgfTLKbQ0whSWsQPmCtuOWlJBRpOjboWslQ0hoyrNkHIH/yD8Y epmXlZ0RHD62aDtOWHTxnwinC0vlLlg2TA+XshEY91d3S+YfvoU3UbTPxOCzg8mLdeD43oZxbP73h QxQAFFnANzyPKjPB08kg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rd4CH-00000003wyH-43mt; Thu, 22 Feb 2024 08:12:49 +0000 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rd4CF-00000003wxo-11WY for linux-riscv@lists.infradead.org; Thu, 22 Feb 2024 08:12:48 +0000 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1d746856d85so50564465ad.0 for ; Thu, 22 Feb 2024 00:12:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1708589566; x=1709194366; 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=71zlVIznaIfi5FluR/+lVnei3BjKa6CskewcKRtvea4=; b=Ft57101Rf6IEHxy5lJ/X3MC19NF6evwlELlo4dwOo+LFXKASbcwcd+A2fhfMmoSsJ6 uHmAyLe9myYj11aSaRM54tvSk7YGOaVy980DryZPPsCvKe093tg6ShRrbqPm6homrWv4 WgxmSgwPcrtPBt8gMNZjBUsAf/euqCK3R45cLlCXBCouYExcuzPaZ+ElevHKRNeiR2qY 9f/onBxBeCY1Lr+3TCI9J5zrdsu7zC1eFyWx8R+trIwRnRqptQOrGcgANDTQOdFKsTvQ M6nPVP1Zm+e3hiQF77I2+gV9tYIqiQBhdaCEtTGGGEM7Im/mjCWZtNm9LiyGltOE5RGV vn+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708589566; x=1709194366; 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=71zlVIznaIfi5FluR/+lVnei3BjKa6CskewcKRtvea4=; b=gFFpKw1mMfHtndc96s8G6CYPcvwcahHnlLO6sJoeAWhSQCn5fVE3YGEEBBcv6eoW1T VQcp38sFqi4VmgYZdx0GczprsXHBV8e12mXafJKhZrATJ4+SNnArMcNYpezTeDLiPyun WyZtc2UjljgrKcscOvyhSUY0EYQqSSCB37oO/kqeVpn64kEiishi9nE6SAV315bdcpUv TZMIicttSauJVPiWeqZR37Znr9yk/H+/27SysAPO4GMoPLBSAhy7zugBuZaxtm2xJap7 TmhtatgTvlJYn8tsQt/OhNDxSDGoGR+8kdZLBRr/sj/EMebL+UmDyc0mZ4JzeIL+6H57 aJCA== X-Gm-Message-State: AOJu0YyzJGnqTnqU8kmL5gGsLlxA3BZ0Zykl1mEAi9kvobR5sFkjXU4l aoOYgU9TzvyNvQ3gk3TdkSyMN7H1jurln/ITSpA4oSxr9jJoVE3haXprH9cGaxafvjFOLRiZoZm zADDrkb7iS5Hf8HVowffINJ71QHkTZvCksNgl2lXEETVQYBBEQT0zpNBtS5NGbN1MERYHGDyR2E 0rps9Sk6YC0sgY9y9SF3rbJbHZcW4oNQvtvqt1SwGiQ1OZNCMY0n8= X-Google-Smtp-Source: AGHT+IHPAJL6cu7RSH3WE6fAmuaVyPcr1z1aP7UDfSisRlzZCtIioRHasqYMwaX0+k6zz4u5vDTy8Q== X-Received: by 2002:a17:902:ecc1:b0:1dc:19e:3d9d with SMTP id a1-20020a170902ecc100b001dc019e3d9dmr11278580plh.30.1708589565722; Thu, 22 Feb 2024 00:12:45 -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 lf8-20020a170902fb4800b001db5ea825b2sm9412796plb.123.2024.02.22.00.12.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 00:12:45 -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@sifive.com, nylon.chen@sifive.com, nylon7717@gmail.com Subject: [PATCH v9 1/3] riscv: dts: sifive: unleashed/unmatched: Remove PWM controlled LED's active-low properties Date: Thu, 22 Feb 2024 16:12:29 +0800 Message-ID: <20240222081231.213406-2-nylon.chen@sifive.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240222081231.213406-1-nylon.chen@sifive.com> References: <20240222081231.213406-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-20240222_001247_305263_FA23D80B X-CRM114-Status: UNSURE ( 8.33 ) 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 Thu Feb 22 08:12:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nylon Chen X-Patchwork-Id: 13566847 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 F1535C48BF8 for ; Thu, 22 Feb 2024 08:13:00 +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=vLBbt7IjtBJEDO3NlYkY4ljMFgb+TfcSg+jRWnw5a4Y=; b=Cq2l3Byip4lwRS XoM3sPaIOJmXHNGV3TP4r+2uXKa6jCdaOSFoDP8OwNBsZzq7xDWN2K+Ihh5auZoosZ+v7bjSQO6Fx DluukqZwRiecPB7SiWlOat7CIgFsgvxgEYe8DdQVYb6jqlAww+r3dKrnUyJNMjvQicN2F2Ge79IpH yMbxGlX2R5HAuGlz3KMGJppXHhAcI5lZDpWHI2QDzHRHqg7WwzAn8bxqWtbO9PDPONWC04V+ZMeyA g5G+AV+kMhOyQvJYoPH+mxdvomezZi0q5M5TDdaGSPJ3XD1oxkAh7PyB8urRf8AkKzKndfZDGnoM2 E2wcPzjtBUpB7nqrWOuQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rd4CM-00000003wzt-35KR; Thu, 22 Feb 2024 08:12:54 +0000 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rd4CJ-00000003wyc-2hSf for linux-riscv@lists.infradead.org; Thu, 22 Feb 2024 08:12:53 +0000 Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1dc1e7c0e29so16702955ad.1 for ; Thu, 22 Feb 2024 00:12:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1708589570; x=1709194370; 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=Thj6USXv+zFZqbn9GMP05XSRBqohJA11glRlwlO2t8E=; b=Wzk5J1VnfmErJycvD61RvULJihgjBXEXmWTAIQyobQLqGsEHfvmdZ8OtTYU9s+bunP BoUcI957l7KLW0upuwxcnPJ3+YRSYuQ4WaC0p8QrTnd111L1IkGfsnop9pFSIKZrMp9t tA0VJGe961N03uymJY4KCCQU2ks+3unedhyJGrnPIJ1gypkf8lQngvcnjmqYyWjouHB+ RBG1xQOLigYAwRneDSllC3AiahOIK3n50uAE5/7Q0ivQxgBx25q6Er4ReTOW3Spcm1pK bnz6+x9zTbUr7PZbe9C33S1wVb6gXz/0mVwxUA4Zy/R6kRkDww7nhTNqawcDJt6nXdHg KZlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708589570; x=1709194370; 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=Thj6USXv+zFZqbn9GMP05XSRBqohJA11glRlwlO2t8E=; b=CHP7QijVRSRqKX1x9JPChxE5FkETRfjO3febaTtr5bqDxyH+etJicnsvAe74xmTNu2 kJcBApjhu4T336z25DJjZk9W6DkMYJsUrcAPXB+1GGL6fHWHLHGDhIh5ZXv5s/YEcGqs nXCv1IajGiC2Evj46ycTK0HJCKJhNHVVASe7cEwZDpnZmFLNkOAkMRkxXqhnnOR32ol/ HXJcyLM682ELOf8Ief8oScHcvqvrIQWHU1gY+FEAu6K7hbSzh67ZcjAHl5uUiNlgEeeP 3o/twzDWaWFam1Ko92yUrmucHbPhuxNjsWh9b0iJonfNIhW7J6mkm+Qg3YjPj10nq/fp 4Rzg== X-Gm-Message-State: AOJu0YxQPEWtmgOCBWBwalaZXtOsdm5kS2YbtX5OEtOQjvQb+ZN1HVvU Dg7T+0dGSBOs29PjCy42XeFA/1Kn4KFcIvCtLgHUM7EZG1/oECUo0BtKtOozE/RvE7gEI9Lemq4 PL9Vq1st8JzFRT59bn3VswwnWurI3Pn+64gqCYyE01VnztMLlkJ7AyAsAz1c+W/IToUIEaq9lUE CkP/La+lx2AHwVN1SyGirZqI0CW9g/oy3Se1gGNXsgpw7lk13uHO8= X-Google-Smtp-Source: AGHT+IGQEH1Pckgyx97VaV3qo9MCG5UniieyW2RPfQREJEuRYUX82wG9nTv/Om2GeygIf4u8y9Tjhw== X-Received: by 2002:a17:902:e751:b0:1dc:1e4f:9b3f with SMTP id p17-20020a170902e75100b001dc1e4f9b3fmr7654206plf.24.1708589570167; Thu, 22 Feb 2024 00:12:50 -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 lf8-20020a170902fb4800b001db5ea825b2sm9412796plb.123.2024.02.22.00.12.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 00:12:49 -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@sifive.com, nylon.chen@sifive.com, nylon7717@gmail.com Subject: [PATCH v9 2/3] pwm: sifive: change the PWM algorithm Date: Thu, 22 Feb 2024 16:12:30 +0800 Message-ID: <20240222081231.213406-3-nylon.chen@sifive.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240222081231.213406-1-nylon.chen@sifive.com> References: <20240222081231.213406-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-20240222_001251_709266_042324FA X-CRM114-Status: GOOD ( 11.55 ) 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 | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/pwm/pwm-sifive.c b/drivers/pwm/pwm-sifive.c index eabddb7c7820..a586cfe4191b 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; } @@ -139,7 +140,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 +160,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 Thu Feb 22 08:12:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nylon Chen X-Patchwork-Id: 13566848 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 B9DDEC5478C for ; Thu, 22 Feb 2024 08:13:02 +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=6DYN4ocmb78vhqDCRP7TuzFrcmjusiw7LrjuJLPYJwE=; b=MzcZLhotuCy0o+ 3cIRUicin5FSdjCSIWvSW3b791D+W3jTLvcR48I1Nur04/uq9wpR9PQAVfKmdPNzFgJOdkW8P/LCX MR+Uq3fZKDRiuk7GDl/D4o2hndbYSQuj+jk4LMK2vAZr6z7gGUzk8KLsCypC08q1q103Z2P9pf2mE /4Co4A47Rii6UDIIAEUxh+GP/Xj/c4iUSJAvNyX5Z7fymbw3RHYJBltm789DOe8U4f3Ruh8z7/taF VlDlavcNB8xCOKQki6D/3R/ZFXqdVYLBCxTWIZYi0sj39dr+SbGhGVDwYfIR8fCpYtUf3ke/UJMu7 dIWdGCpZXhxAgoc2ExJQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rd4CQ-00000003x1I-0Wkh; Thu, 22 Feb 2024 08:12:58 +0000 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rd4CN-00000003x0B-3jHa for linux-riscv@lists.infradead.org; Thu, 22 Feb 2024 08:12:57 +0000 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1d934c8f8f7so70940375ad.2 for ; Thu, 22 Feb 2024 00:12:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1708589574; x=1709194374; 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=OzNGUpNoXsKa0F+bV/ekx8aAYd7ltTcTmTe5buoxy74=; b=icfzpIMH7H8lQ2oUEMfWR30vlkhtrlgfdEZCrz4hqaiIhPU4WId3Zg7fIZMvZ/EuvJ WAp1svzOTItXt/h3S1uWtQ4ajlpUGm0SEHhGrTEvXHYemEbvqHyGvATgq1TZ2/DdQz5T mfZLZbmLWqFhO2t6mVUKS99k24jc9i2OfhkVAL9teqvd6tk7C4AZuVEFs+Wr96jk8Sm1 oiz9uga0wHxycFWdfbrERQFJBeixgtgOLGIB2DXEJMSmFBicufKvC6pVRu4rPgKcyxHt AAUsWu0mDLHNMxjVv2ibTVpixZ6vjWU9Wvs/h6uk1C/RiMffe0wj+MRPjM1N+QnTuJwn ENTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708589574; x=1709194374; 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=OzNGUpNoXsKa0F+bV/ekx8aAYd7ltTcTmTe5buoxy74=; b=DmT30a59IikyC2f/df7VO+c1Pp2faTWqx+25zwSKydvGh0s6uDyA4EuqRqjA+jj2K5 nVazIjD55TTAAoWZj4GmgCaHakichzUwsASj9wAsGsJTnM7HY9dvo8B3FaXj4DWnotae 64us6HOC98KFqtIkgUSqA3kXZENc9iEdzBFNGWq4N2GwjQUZ6MBpUsJWdAVlCLe63VbT EVMSCDUif/cZvIyiZWmfPEX+xkK3nMkc+rwasWnrVYOrqS+tFSv1O/WQdkqqb7nmBtni jcSDu35DycMsbcZLcmHETg4CeGHX0+2Ver0dy/hMY8Z6dwOtuFmBybAr/vxaQRgvxTGU iQ7Q== X-Gm-Message-State: AOJu0YzBrA9uwb/H1RIBZ639CXRqmADRyqBdCDqQn6saPvw4Ig9rdwbu 8yg7/9xgNITNkSRaYkbN+3K4rnrM0E0ByOTDz7IKZW4t9v5ZWSH4fQVf/uYM3/SOqIuddjhoxpM ZWGCr0qGgdjN2rC0s2Q/IdJN6Viaq6b8lnwfwd8m1HGNLMGN2gUpaaY0ssnBtPFvYu7SR8ZSMIa mx2PQV2nSES7eJ+NjKQ/HZi8o9nWbcfBsU34vICkdTnX9IOS0t+RM= X-Google-Smtp-Source: AGHT+IEz666lsZSApoJrluiCUnkDERHUYNU92etsFfiWP0DNhuFqgQPyMZWzIbTM8mytE5tfogyXLA== X-Received: by 2002:a17:903:22c6:b0:1db:d42f:fde9 with SMTP id y6-20020a17090322c600b001dbd42ffde9mr16038641plg.41.1708589574353; Thu, 22 Feb 2024 00:12:54 -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 lf8-20020a170902fb4800b001db5ea825b2sm9412796plb.123.2024.02.22.00.12.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 00:12:53 -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@sifive.com, nylon.chen@sifive.com, nylon7717@gmail.com Subject: [PATCH v9 3/3] pwm: sifive: Fix the error in the idempotent test within the pwm_apply_state_debug function Date: Thu, 22 Feb 2024 16:12:31 +0800 Message-ID: <20240222081231.213406-4-nylon.chen@sifive.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240222081231.213406-1-nylon.chen@sifive.com> References: <20240222081231.213406-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-20240222_001255_951786_B2EFF1AA X-CRM114-Status: GOOD ( 11.35 ) 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 a586cfe4191b..bebcbebacccd 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); }