From nobody Wed Dec 17 11:50:58 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9281EC77B72 for ; Thu, 20 Apr 2023 09:35:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234349AbjDTJfU (ORCPT ); Thu, 20 Apr 2023 05:35:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234224AbjDTJfK (ORCPT ); Thu, 20 Apr 2023 05:35:10 -0400 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 419D32D78 for ; Thu, 20 Apr 2023 02:35:09 -0700 (PDT) Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-63b52ad6311so1038546b3a.2 for ; Thu, 20 Apr 2023 02:35:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1681983309; x=1684575309; 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=IHPuRLA5WWcEQWx1cI3sgBTHdUDt8lS20i2hj6DWJQM=; b=I0GuHV+xeH4hhf9jmjGqJqjMpaB3h4iLZtZOerQDLrCVSiopbDOjRVrVZZ5dsbzGmN sLotILAXSjHXXK3WU9LkaXmo8tzCu6nBCZDoDoQlmWh4adXl0ZgSaPoW07ydRmJyTk36 VtGBYQDDtrg0iO8/PeRl1i5eT8yknBGSmWcpX+mcYa0y78oQIKV2R4pVlHqI2nMd82zH BzVGp3v3p3ZviovrlTw1GMuT3PSZNishGIDWkXXmXMEowKlTothFnR7Qf8nO+WcHGcoX WGaDp7SwmktKS614Oz10TiFpoVJ3VTfiH5rK0/QOGs/BZshnFPYsWY6AJf6Db+o6mkaQ 0Yhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681983309; x=1684575309; 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=IHPuRLA5WWcEQWx1cI3sgBTHdUDt8lS20i2hj6DWJQM=; b=RLGvspp1K/JwYzLPnXnEiZPIiyP7gBbDclR19KMig+mviXVI/Z+/9AdnK6DatA6SVz +NxL4WoecBduk0XMI0HjCA3czp3brOKteHv7F0eNktL2YTWgIbfaNJsyfBSwxH7A/aPh byhQXHQ9r1XQ1LY15Z5og3xP2eU+xGYYQAV5+qQFMJGGBpTgvHsMM7eFy7lxh3bJb6UD jdFK8WL4XBG06+JUXHxRk3hkDRylFoCHi6GZLiZTTHDPuzgOhx28WkoyQhK5u0aQUbnM sDOGSBHQULi2nBiDvrGauX52hMX35r2tQQqOLAuxZMsgL6NzKTANyvYyCRYdSxw2zI11 R9Bw== X-Gm-Message-State: AAQBX9e3pKQi8HZqeNh5szyBj7YN0EuBObGvtjsagiJP5Hz18zmimQvV QtONCMzxtP1A9wYOLE5gTKaaGg== X-Google-Smtp-Source: AKy350abeBDWDHJdXZTQE7s0QOikL+2ciqc/t7yvCQxyX1OhaD11p0xvKBUUC0LwfASK7s01JPRGQA== X-Received: by 2002:a05:6a20:a59a:b0:f0:1255:781b with SMTP id bc26-20020a056a20a59a00b000f01255781bmr1511257pzb.29.1681983308729; Thu, 20 Apr 2023 02:35:08 -0700 (PDT) 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 p5-20020a63c145000000b0051ba9d772f9sm781551pgi.59.2023.04.20.02.35.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Apr 2023 02:35:08 -0700 (PDT) From: Nylon Chen To: aou@eecs.berkeley.edu, conor@kernel.org, emil.renner.berthing@canonical.com, geert+renesas@glider.be, heiko@sntech.de, krzysztof.kozlowski+dt@linaro.org, palmer@dabbelt.com, paul.walmsley@sifive.com, robh+dt@kernel.org, thierry.reding@gmail.com, u.kleine-koenig@pengutronix.de, devicetree@vger.kernel.org, linux-pwm@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: nylon.chen@sifive.com, nylon7717@gmail.com, zong.li@sifive.com, greentime.hu@sifive.com, vincent.chen@sifive.com, Conor Dooley Subject: [PATCH v3 1/2] riscv: dts: sifive: unleashed/unmatched: Remove PWM controlled LED's active-low properties Date: Thu, 20 Apr 2023 17:34:56 +0800 Message-Id: <20230420093457.18936-2-nylon.chen@sifive.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230420093457.18936-1-nylon.chen@sifive.com> References: <20230420093457.18936-1-nylon.chen@sifive.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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-schematic= s-v3.pdf[1]. Link: https://sifive.cdn.prismic.io/sifive/c52a8e32-05ce-4aaf-95c8-7bf8453f= 8698_hifive-unleashed-a00-schematics-1.pdf [0] Link: https://sifive.cdn.prismic.io/sifive/6a06d6c0-6e66-49b5-8e9e-e68ce76f= 4192_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 | 4 ---- arch/riscv/boot/dts/sifive/hifive-unmatched-a00.dts | 4 ---- 2 files changed, 8 deletions(-) diff --git a/arch/riscv/boot/dts/sifive/hifive-unleashed-a00.dts b/arch/ris= cv/boot/dts/sifive/hifive-unleashed-a00.dts index 900a50526d77..7a9f336a391c 100644 --- a/arch/riscv/boot/dts/sifive/hifive-unleashed-a00.dts +++ b/arch/riscv/boot/dts/sifive/hifive-unleashed-a00.dts @@ -50,7 +50,6 @@ led-controller { =20 led-d1 { pwms =3D <&pwm0 0 7812500 PWM_POLARITY_INVERTED>; - active-low; color =3D ; max-brightness =3D <255>; label =3D "d1"; @@ -58,7 +57,6 @@ led-d1 { =20 led-d2 { pwms =3D <&pwm0 1 7812500 PWM_POLARITY_INVERTED>; - active-low; color =3D ; max-brightness =3D <255>; label =3D "d2"; @@ -66,7 +64,6 @@ led-d2 { =20 led-d3 { pwms =3D <&pwm0 2 7812500 PWM_POLARITY_INVERTED>; - active-low; color =3D ; max-brightness =3D <255>; label =3D "d3"; @@ -74,7 +71,6 @@ led-d3 { =20 led-d4 { pwms =3D <&pwm0 3 7812500 PWM_POLARITY_INVERTED>; - active-low; color =3D ; max-brightness =3D <255>; label =3D "d4"; diff --git a/arch/riscv/boot/dts/sifive/hifive-unmatched-a00.dts b/arch/ris= cv/boot/dts/sifive/hifive-unmatched-a00.dts index 07387f9c135c..11f08a545ee6 100644 --- a/arch/riscv/boot/dts/sifive/hifive-unmatched-a00.dts +++ b/arch/riscv/boot/dts/sifive/hifive-unmatched-a00.dts @@ -52,7 +52,6 @@ led-controller-1 { =20 led-d12 { pwms =3D <&pwm0 0 7812500 PWM_POLARITY_INVERTED>; - active-low; color =3D ; max-brightness =3D <255>; label =3D "d12"; @@ -69,19 +68,16 @@ multi-led { =20 led-red { pwms =3D <&pwm0 2 7812500 PWM_POLARITY_INVERTED>; - active-low; color =3D ; }; =20 led-green { pwms =3D <&pwm0 1 7812500 PWM_POLARITY_INVERTED>; - active-low; color =3D ; }; =20 led-blue { pwms =3D <&pwm0 3 7812500 PWM_POLARITY_INVERTED>; - active-low; color =3D ; }; }; --=20 2.40.0 From nobody Wed Dec 17 11:50:58 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2D7CCC77B72 for ; Thu, 20 Apr 2023 09:35:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233777AbjDTJfp (ORCPT ); Thu, 20 Apr 2023 05:35:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234261AbjDTJfQ (ORCPT ); Thu, 20 Apr 2023 05:35:16 -0400 Received: from mail-pg1-x533.google.com (mail-pg1-x533.google.com [IPv6:2607:f8b0:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 672722D5A for ; Thu, 20 Apr 2023 02:35:14 -0700 (PDT) Received: by mail-pg1-x533.google.com with SMTP id 41be03b00d2f7-5144043d9d1so579401a12.3 for ; Thu, 20 Apr 2023 02:35:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1681983314; x=1684575314; 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=Ryva+FQmb09SgOiCE7P4pQBiT6BdeSdh3y4Qn91oZ9M=; b=d4ER6huQjMtUV4wHdMb9ME9KpU3d2FGtvqsgiDTUlUyLvDePcXJ0PKh98S6NEnsa2G XpQA1rCPbkz2/bCmmRIw/iKSY7Jc/iG598aSV3OIGqyeUx4IBcGUZKtO4vIBwSqT9r0P p5FSKMM0VYyfyGjMat2EmIyNNAimvy6yE8WNCYrKGxEhDc/YAWf+Pc70ybdNvL8zO+JA QpNju3Pf0hJEFC4gFdxrSa9X6mz6r/WWX5OMVqulCgrYK2qAWDlWa525eBQUcoKAVN9a K70k1rCm/C/aU30qmXDSBl7EG/LeuOhixKwJILpFQprjgRGLNArBduUmQD/Zx6K1YSUy l2Eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681983314; x=1684575314; 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=Ryva+FQmb09SgOiCE7P4pQBiT6BdeSdh3y4Qn91oZ9M=; b=ASuFW4UE6ex0l5cIowIvDm8gh8ccNsRAT6exORwywLDLucjrL9xuOuD5oJaITaxnXB dT/q1Eyn1H29JYIGsAFAiTxRuxVXbJYp899e7OmhPEpISrDyLXZ52hEcgAjCj8cpVzMF vi2cQfnJEqE8Hg9y7EJ95K8q0KYccVKJSrRrEFpFG1znVQfBIkMjIiy8a8ekJYtXPZtw F1KlRT1LNjaWAt3fPg1XGEJNA3AuIKSqtZ6BsZDIM82Qvk7idHjxX3ONgHr36EeTIJBY qlXJz54b/t4qe2t3mhnls7E7SJDo8gV8syRqoE8qUqP0oyTf2XchYM+6ourQwNpLCY/1 PDxA== X-Gm-Message-State: AAQBX9duMGPl2pJWdO9GzQExfKytt+JZFQmTyVoDVxBuj5wdjwVrRkc4 Oc/tnh0dmBmPaZIgzkr70+TNrg== X-Google-Smtp-Source: AKy350br6fKdRCr0Nj4YKMv9Nvtjoq+VqjzrOMC15lETcCmUtAqFU5evu54VS9v+FLXPiour7tCHKQ== X-Received: by 2002:a17:90b:10c:b0:23f:9fac:6b35 with SMTP id p12-20020a17090b010c00b0023f9fac6b35mr1017558pjz.39.1681983313820; Thu, 20 Apr 2023 02:35:13 -0700 (PDT) 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 p5-20020a63c145000000b0051ba9d772f9sm781551pgi.59.2023.04.20.02.35.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Apr 2023 02:35:13 -0700 (PDT) From: Nylon Chen To: aou@eecs.berkeley.edu, conor@kernel.org, emil.renner.berthing@canonical.com, geert+renesas@glider.be, heiko@sntech.de, krzysztof.kozlowski+dt@linaro.org, palmer@dabbelt.com, paul.walmsley@sifive.com, robh+dt@kernel.org, thierry.reding@gmail.com, u.kleine-koenig@pengutronix.de, devicetree@vger.kernel.org, linux-pwm@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: nylon.chen@sifive.com, nylon7717@gmail.com, zong.li@sifive.com, greentime.hu@sifive.com, vincent.chen@sifive.com, Conor Dooley Subject: [PATCH v3 2/2] pwm: sifive: change the PWM controlled LED algorithm Date: Thu, 20 Apr 2023 17:34:57 +0800 Message-Id: <20230420093457.18936-3-nylon.chen@sifive.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230420093457.18936-1-nylon.chen@sifive.com> References: <20230420093457.18936-1-nylon.chen@sifive.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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-86ed8b16= acba_fu740-c000-manual-v1p6.pdf [0] Acked-by: Conor Dooley Reviewed-by: Conor Dooley Signed-off-by: Nylon Chen Signed-off-by: Vincent Chen --- drivers/pwm/pwm-sifive.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/pwm/pwm-sifive.c b/drivers/pwm/pwm-sifive.c index 393a4b97fc19..d5d5f36da297 100644 --- a/drivers/pwm/pwm-sifive.c +++ b/drivers/pwm/pwm-sifive.c @@ -132,13 +132,13 @@ static int pwm_sifive_apply(struct pwm_chip *chip, st= ruct pwm_device *pwm, { struct pwm_sifive_ddata *ddata =3D pwm_sifive_chip_to_ddata(chip); struct pwm_state cur_state; - unsigned int duty_cycle; + unsigned int duty_cycle, period; unsigned long long num; bool enabled; int ret =3D 0; u32 frac; =20 - if (state->polarity !=3D PWM_POLARITY_INVERSED) + if (state->polarity !=3D PWM_POLARITY_NORMAL && state->polarity !=3D PWM_= POLARITY_INVERSED) return -EINVAL; =20 cur_state =3D pwm->state; @@ -154,10 +154,13 @@ static int pwm_sifive_apply(struct pwm_chip *chip, st= ruct pwm_device *pwm, * calculating the register values first and then writing them * consecutively */ + period =3D max(state->period, ddata->approx_period); num =3D (u64)duty_cycle * (1U << PWM_SIFIVE_CMPWIDTH); frac =3D DIV64_U64_ROUND_CLOSEST(num, state->period); - /* The hardware cannot generate a 100% duty cycle */ frac =3D min(frac, (1U << PWM_SIFIVE_CMPWIDTH) - 1); + /* The hardware cannot generate a 100% duty cycle */ + frac =3D (1U << PWM_SIFIVE_CMPWIDTH) - 1 - frac; + =20 mutex_lock(&ddata->lock); if (state->period !=3D ddata->approx_period) { --=20 2.40.0