Message ID | 20221024205213.327001-2-paul@crapouillou.net |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp707032wru; Mon, 24 Oct 2022 16:43:26 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7UAxbqc9wys/uQCu62fiOz+PcAiV4iE0PRFNx1Iy6se+jrl6O8KD3Ueo3qT2yX6z1ps5hm X-Received: by 2002:a17:902:f54f:b0:186:a987:c733 with SMTP id h15-20020a170902f54f00b00186a987c733mr7610305plf.170.1666655006596; Mon, 24 Oct 2022 16:43:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666655006; cv=none; d=google.com; s=arc-20160816; b=vPuGolf3D63mr3qJajaKs7d305A0MEpY1UU0+rI/jqKvoU1jD7RikSGqzzJmuoZMqX IG2FbStKMHgANcC855gc8NAk/RAIhuVZvOjovhN+ZNvAWlWtlXABnPNjXj1v6T1tRl1C NiHm+VT0o2o29cqMuGXnF85njGXpE17k4zlswpxUsRF6Cxd6a4G+k3rEnv3haPOLZ0ez S0qek9rTdX6BGW4yJvdfXFplHH2q9SO17U2OVrTwpY4ZRxSb6B5DJoW+tavq3HPh60Jt cpoF/Fxgq/gOAIp7FSjk97qodndR0xbBC5vO/d5XqgvA5cGYj5NGRcUpu7Uer8+G0ChV m66Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=avcN02YNvaxpZRdy8N6BP2+uTVrnwX31SrzsZGCAp0c=; b=GQcB8HFttUEhuRzYaSCXaXjxeQcjWJf6/kvvos3HlkyO6S4ZB0BfqcvQQMyDIE91/c dS19gAJWy5xtSpQH1cL0d9XBaLb9zUce4maoIb2X+cUCp3mWRB+9D1X6pCBv4Ss6wOdd Wlr2+kQ+TSd4/D2W4XMgRBdb2WPK9OQWM7GVGb01mrPz4xpV3pYtMvS3Q3tt9HKyHvOt gkK/7jlsZESWCBUJuJKmoDdArvF1mGRV2Eftx8XZy+UnPmzNUU7jcViES2vbZXKXizoq qstT9HZRUM+W7WBffDqCLhenqdJcvTw3E2TShxeWC20hUSkVES+rsKCm4cRPi6YHM+MX ZUHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@crapouillou.net header.s=mail header.b=Bmyh2YOh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=crapouillou.net Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y10-20020a170902d64a00b0017f5ea2e8easi893226plh.357.2022.10.24.16.43.14; Mon, 24 Oct 2022 16:43:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@crapouillou.net header.s=mail header.b=Bmyh2YOh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=crapouillou.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231384AbiJXXdE (ORCPT <rfc822;pwkd43@gmail.com> + 99 others); Mon, 24 Oct 2022 19:33:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230405AbiJXXcZ (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 24 Oct 2022 19:32:25 -0400 Received: from aposti.net (aposti.net [89.234.176.197]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE040107A8C; Mon, 24 Oct 2022 14:53:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=crapouillou.net; s=mail; t=1666644740; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=avcN02YNvaxpZRdy8N6BP2+uTVrnwX31SrzsZGCAp0c=; b=Bmyh2YOhAjfg1GSy4ncnAj+0uagLOdl4JNbxAeyUKnYnHQsPI4htDWCoHQuYlBqCsqa7qz a1TvbaO2+3VP3gUDS4UmlqXfBkR5Tze5O7MPfwSi++v+pk0pHtro5AQCZftppjugDkmdxZ IqWyRrP0D7KxE5peHD5QjkDZvR7LGAI= From: Paul Cercueil <paul@crapouillou.net> To: Thierry Reding <thierry.reding@gmail.com>, =?utf-8?q?Uwe_Kleine-K=C3=B6n?= =?utf-8?q?ig?= <u.kleine-koenig@pengutronix.de> Cc: od@opendingux.net, linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, Paul Cercueil <paul@crapouillou.net>, stable@vger.kernel.org Subject: [PATCH 1/5] pwm: jz4740: Fix pin level of disabled TCU2 channels, part 1 Date: Mon, 24 Oct 2022 21:52:09 +0100 Message-Id: <20221024205213.327001-2-paul@crapouillou.net> In-Reply-To: <20221024205213.327001-1-paul@crapouillou.net> References: <20221024205213.327001-1-paul@crapouillou.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747614439856556216?= X-GMAIL-MSGID: =?utf-8?q?1747614439856556216?= |
Series |
pwm: jz4740: Fixes and some light changes
|
|
Commit Message
Paul Cercueil
Oct. 24, 2022, 8:52 p.m. UTC
The "duty > cycle" trick to force the pin level of a disabled TCU2
channel would only work when the channel had been enabled previously.
Address this issue by enabling the PWM mode in jz4740_pwm_disable
(I know, right) so that the "duty > cycle" trick works before disabling
the PWM channel right after.
This issue went unnoticed, as the PWM pins on the majority of the boards
tested would default to the inactive level once the corresponding TCU
clock was enabled, so the first call to jz4740_pwm_disable() would not
actually change the pin levels.
On the GCW Zero however, the PWM pin for the backlight (PWM1, which is
a TCU2 channel) goes active as soon as the timer1 clock is enabled.
Since the jz4740_pwm_disable() function did not work on channels not
previously enabled, the backlight would shine at full brightness from
the moment the backlight driver would probe, until the backlight driver
tried to *enable* the PWM output.
With this fix, the PWM pins will be forced inactive as soon as
jz4740_pwm_apply() is called (and might be reconfigured to active if
dictated by the pwm_state). This means that there is still a tiny time
frame between the .request() and .apply() callbacks where the PWM pin
might be active. Sadly, there is no way to fix this issue: it is
impossible to write a PWM channel's registers if the corresponding clock
is not enabled, and enabling the clock is what causes the PWM pin to go
active.
There is a workaround, though, which complements this fix: simply
starting the backlight driver (or any PWM client driver) with a "init"
pinctrl state that sets the pin as an inactive GPIO. Once the driver is
probed and the pinctrl state switches to "default", the regular PWM pin
configuration can be used as it will be properly driven.
Fixes: c2693514a0a1 ("pwm: jz4740: Obtain regmap from parent node")
Signed-off-by: Paul Cercueil <paul@crapouillou.net>
Cc: stable@vger.kernel.org
---
drivers/pwm/pwm-jz4740.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
Comments
Hello, On Mon, Oct 24, 2022 at 09:52:09PM +0100, Paul Cercueil wrote: > The "duty > cycle" trick to force the pin level of a disabled TCU2 > channel would only work when the channel had been enabled previously. > > Address this issue by enabling the PWM mode in jz4740_pwm_disable > (I know, right) so that the "duty > cycle" trick works before disabling > the PWM channel right after. > > This issue went unnoticed, as the PWM pins on the majority of the boards > tested would default to the inactive level once the corresponding TCU > clock was enabled, so the first call to jz4740_pwm_disable() would not > actually change the pin levels. > > On the GCW Zero however, the PWM pin for the backlight (PWM1, which is > a TCU2 channel) goes active as soon as the timer1 clock is enabled. > Since the jz4740_pwm_disable() function did not work on channels not > previously enabled, the backlight would shine at full brightness from > the moment the backlight driver would probe, until the backlight driver > tried to *enable* the PWM output. > > With this fix, the PWM pins will be forced inactive as soon as > jz4740_pwm_apply() is called (and might be reconfigured to active if > dictated by the pwm_state). This means that there is still a tiny time > frame between the .request() and .apply() callbacks where the PWM pin > might be active. Sadly, there is no way to fix this issue: it is > impossible to write a PWM channel's registers if the corresponding clock > is not enabled, and enabling the clock is what causes the PWM pin to go > active. > > There is a workaround, though, which complements this fix: simply > starting the backlight driver (or any PWM client driver) with a "init" > pinctrl state that sets the pin as an inactive GPIO. Once the driver is > probed and the pinctrl state switches to "default", the regular PWM pin > configuration can be used as it will be properly driven. > > Fixes: c2693514a0a1 ("pwm: jz4740: Obtain regmap from parent node") > Signed-off-by: Paul Cercueil <paul@crapouillou.net> > Cc: stable@vger.kernel.org OK, understood the issue. I think there is another similar issue: The clk is get and enabled only in the .request() callback. The result is (I think---depends on a few further conditions) that if you have the backlight driver as a module and the bootloader enables the backlight to show a splash screen, the backlight goes off because of the clk_disable_unused initcall. So the right thing to do is to get the clock in .probe(), and ensure it is kept on if the PWM is running already. Then you can also enable the counter in .probe() and don't care for it in the enable and disable functions. The init pinctrl then has to be on the PWM then, but that's IMHO ok. Best regards Uwe PS: While looking into the driver I noticed that .request() uses dev_err_probe(). That's wrong, this function is only supposed to be used in .probe().
Le mar. 25 oct. 2022 à 08:21:29 +0200, Uwe Kleine-König <u.kleine-koenig@pengutronix.de> a écrit : > Hello, > > On Mon, Oct 24, 2022 at 09:52:09PM +0100, Paul Cercueil wrote: >> The "duty > cycle" trick to force the pin level of a disabled TCU2 >> channel would only work when the channel had been enabled >> previously. >> >> Address this issue by enabling the PWM mode in jz4740_pwm_disable >> (I know, right) so that the "duty > cycle" trick works before >> disabling >> the PWM channel right after. >> >> This issue went unnoticed, as the PWM pins on the majority of the >> boards >> tested would default to the inactive level once the corresponding >> TCU >> clock was enabled, so the first call to jz4740_pwm_disable() would >> not >> actually change the pin levels. >> >> On the GCW Zero however, the PWM pin for the backlight (PWM1, which >> is >> a TCU2 channel) goes active as soon as the timer1 clock is enabled. >> Since the jz4740_pwm_disable() function did not work on channels not >> previously enabled, the backlight would shine at full brightness >> from >> the moment the backlight driver would probe, until the backlight >> driver >> tried to *enable* the PWM output. >> >> With this fix, the PWM pins will be forced inactive as soon as >> jz4740_pwm_apply() is called (and might be reconfigured to active if >> dictated by the pwm_state). This means that there is still a tiny >> time >> frame between the .request() and .apply() callbacks where the PWM >> pin >> might be active. Sadly, there is no way to fix this issue: it is >> impossible to write a PWM channel's registers if the corresponding >> clock >> is not enabled, and enabling the clock is what causes the PWM pin >> to go >> active. >> >> There is a workaround, though, which complements this fix: simply >> starting the backlight driver (or any PWM client driver) with a >> "init" >> pinctrl state that sets the pin as an inactive GPIO. Once the >> driver is >> probed and the pinctrl state switches to "default", the regular PWM >> pin >> configuration can be used as it will be properly driven. >> >> Fixes: c2693514a0a1 ("pwm: jz4740: Obtain regmap from parent node") >> Signed-off-by: Paul Cercueil <paul@crapouillou.net> >> Cc: stable@vger.kernel.org > > OK, understood the issue. I think there is another similar issue: The > clk is get and enabled only in the .request() callback. The result is > (I > think---depends on a few further conditions) that if you have the > backlight driver as a module and the bootloader enables the backlight > to > show a splash screen, the backlight goes off because of the > clk_disable_unused initcall. I will have to verify, but I'm pretty sure disabling the clock doesn't change the pin level back to inactive. -Paul > So the right thing to do is to get the clock in .probe(), and ensure > it > is kept on if the PWM is running already. Then you can also enable the > counter in .probe() and don't care for it in the enable and disable > functions. > > The init pinctrl then has to be on the PWM then, but that's IMHO ok. > > Best regards > Uwe > > PS: While looking into the driver I noticed that .request() uses > dev_err_probe(). That's wrong, this function is only supposed to be > used > in .probe(). > > -- > Pengutronix e.K. | Uwe Kleine-König > | > Industrial Linux Solutions | > https://www.pengutronix.de/ |
Hello Paul, On Tue, Oct 25, 2022 at 11:02:00AM +0100, Paul Cercueil wrote: > Le mar. 25 oct. 2022 à 08:21:29 +0200, Uwe Kleine-König > <u.kleine-koenig@pengutronix.de> a écrit : > > Hello, > > > > On Mon, Oct 24, 2022 at 09:52:09PM +0100, Paul Cercueil wrote: > > > The "duty > cycle" trick to force the pin level of a disabled TCU2 > > > channel would only work when the channel had been enabled > > > previously. > > > > > > Address this issue by enabling the PWM mode in jz4740_pwm_disable > > > (I know, right) so that the "duty > cycle" trick works before > > > disabling > > > the PWM channel right after. > > > > > > This issue went unnoticed, as the PWM pins on the majority of the > > > boards > > > tested would default to the inactive level once the corresponding > > > TCU > > > clock was enabled, so the first call to jz4740_pwm_disable() would > > > not > > > actually change the pin levels. > > > > > > On the GCW Zero however, the PWM pin for the backlight (PWM1, which > > > is > > > a TCU2 channel) goes active as soon as the timer1 clock is enabled. > > > Since the jz4740_pwm_disable() function did not work on channels not > > > previously enabled, the backlight would shine at full brightness > > > from > > > the moment the backlight driver would probe, until the backlight > > > driver > > > tried to *enable* the PWM output. > > > > > > With this fix, the PWM pins will be forced inactive as soon as > > > jz4740_pwm_apply() is called (and might be reconfigured to active if > > > dictated by the pwm_state). This means that there is still a tiny > > > time > > > frame between the .request() and .apply() callbacks where the PWM > > > pin > > > might be active. Sadly, there is no way to fix this issue: it is > > > impossible to write a PWM channel's registers if the corresponding > > > clock > > > is not enabled, and enabling the clock is what causes the PWM pin > > > to go > > > active. > > > > > > There is a workaround, though, which complements this fix: simply > > > starting the backlight driver (or any PWM client driver) with a > > > "init" > > > pinctrl state that sets the pin as an inactive GPIO. Once the > > > driver is > > > probed and the pinctrl state switches to "default", the regular PWM > > > pin > > > configuration can be used as it will be properly driven. > > > > > > Fixes: c2693514a0a1 ("pwm: jz4740: Obtain regmap from parent node") > > > Signed-off-by: Paul Cercueil <paul@crapouillou.net> > > > Cc: stable@vger.kernel.org > > > > OK, understood the issue. I think there is another similar issue: The > > clk is get and enabled only in the .request() callback. The result is (I > > think---depends on a few further conditions) that if you have the > > backlight driver as a module and the bootloader enables the backlight to > > show a splash screen, the backlight goes off because of the > > clk_disable_unused initcall. > > I will have to verify, but I'm pretty sure disabling the clock doesn't > change the pin level back to inactive. Given that you set the clk's rate depending on the period to apply, I'd claim that you need to keep the clk on. Maybe it doesn't hurt, because another component of the system keeps the clk running, but it's wrong anyhow. Assumptions like these tend to break on new chip revisions. Best regards Uwe
Hi Uwe, Le jeu. 17 nov. 2022 à 14:29:27 +0100, Uwe Kleine-König <u.kleine-koenig@pengutronix.de> a écrit : > Hello Paul, > > On Tue, Oct 25, 2022 at 11:02:00AM +0100, Paul Cercueil wrote: >> Le mar. 25 oct. 2022 à 08:21:29 +0200, Uwe Kleine-König >> <u.kleine-koenig@pengutronix.de> a écrit : >> > Hello, >> > >> > On Mon, Oct 24, 2022 at 09:52:09PM +0100, Paul Cercueil wrote: >> > > The "duty > cycle" trick to force the pin level of a disabled >> TCU2 >> > > channel would only work when the channel had been enabled >> > > previously. >> > > >> > > Address this issue by enabling the PWM mode in >> jz4740_pwm_disable >> > > (I know, right) so that the "duty > cycle" trick works before >> > > disabling >> > > the PWM channel right after. >> > > >> > > This issue went unnoticed, as the PWM pins on the majority of >> the >> > > boards >> > > tested would default to the inactive level once the >> corresponding >> > > TCU >> > > clock was enabled, so the first call to jz4740_pwm_disable() >> would >> > > not >> > > actually change the pin levels. >> > > >> > > On the GCW Zero however, the PWM pin for the backlight (PWM1, >> which >> > > is >> > > a TCU2 channel) goes active as soon as the timer1 clock is >> enabled. >> > > Since the jz4740_pwm_disable() function did not work on >> channels not >> > > previously enabled, the backlight would shine at full >> brightness >> > > from >> > > the moment the backlight driver would probe, until the >> backlight >> > > driver >> > > tried to *enable* the PWM output. >> > > >> > > With this fix, the PWM pins will be forced inactive as soon as >> > > jz4740_pwm_apply() is called (and might be reconfigured to >> active if >> > > dictated by the pwm_state). This means that there is still a >> tiny >> > > time >> > > frame between the .request() and .apply() callbacks where the >> PWM >> > > pin >> > > might be active. Sadly, there is no way to fix this issue: it >> is >> > > impossible to write a PWM channel's registers if the >> corresponding >> > > clock >> > > is not enabled, and enabling the clock is what causes the PWM >> pin >> > > to go >> > > active. >> > > >> > > There is a workaround, though, which complements this fix: >> simply >> > > starting the backlight driver (or any PWM client driver) with a >> > > "init" >> > > pinctrl state that sets the pin as an inactive GPIO. Once the >> > > driver is >> > > probed and the pinctrl state switches to "default", the >> regular PWM >> > > pin >> > > configuration can be used as it will be properly driven. >> > > >> > > Fixes: c2693514a0a1 ("pwm: jz4740: Obtain regmap from parent >> node") >> > > Signed-off-by: Paul Cercueil <paul@crapouillou.net> >> > > Cc: stable@vger.kernel.org >> > >> > OK, understood the issue. I think there is another similar issue: >> The >> > clk is get and enabled only in the .request() callback. The >> result is (I >> > think---depends on a few further conditions) that if you have the >> > backlight driver as a module and the bootloader enables the >> backlight to >> > show a splash screen, the backlight goes off because of the >> > clk_disable_unused initcall. >> >> I will have to verify, but I'm pretty sure disabling the clock >> doesn't >> change the pin level back to inactive. > > Given that you set the clk's rate depending on the period to apply, > I'd > claim that you need to keep the clk on. Maybe it doesn't hurt, because > another component of the system keeps the clk running, but it's wrong > anyhow. Assumptions like these tend to break on new chip revisions. If the backlight driver is a module then it will probe before the clk_disable_unused initcall, unless something is really wrong. So the backlight would stay ON if it was enabled by the bootloader, unless the DTB decides it doesn't have to be. Anyway, I can try your suggestion, and move the trick to force-disable PWM pins in the probe(). After that, the clocks can be safely disabled, so I can disable them (for the disabled PWMs) at the end of the probe and re-enable them again in their respective .request() callback. Cheers, -Paul
Hello Paul, On Fri, Nov 18, 2022 at 09:55:40AM +0000, Paul Cercueil wrote: > Le jeu. 17 nov. 2022 à 14:29:27 +0100, Uwe Kleine-König > <u.kleine-koenig@pengutronix.de> a écrit : > > Hello Paul, > > > > On Tue, Oct 25, 2022 at 11:02:00AM +0100, Paul Cercueil wrote: > > > Le mar. 25 oct. 2022 à 08:21:29 +0200, Uwe Kleine-König > > > <u.kleine-koenig@pengutronix.de> a écrit : > > > > Hello, > > > > > > > > On Mon, Oct 24, 2022 at 09:52:09PM +0100, Paul Cercueil wrote: > > > > > The "duty > cycle" trick to force the pin level of a disabled > > > TCU2 > > > > > channel would only work when the channel had been enabled > > > > > previously. > > > > > > > > > > Address this issue by enabling the PWM mode in > > > jz4740_pwm_disable > > > > > (I know, right) so that the "duty > cycle" trick works before > > > > > disabling > > > > > the PWM channel right after. > > > > > > > > > > This issue went unnoticed, as the PWM pins on the majority of > > > the > > > > > boards > > > > > tested would default to the inactive level once the > > > corresponding > > > > > TCU > > > > > clock was enabled, so the first call to jz4740_pwm_disable() > > > would > > > > > not > > > > > actually change the pin levels. > > > > > > > > > > On the GCW Zero however, the PWM pin for the backlight (PWM1, > > > which > > > > > is > > > > > a TCU2 channel) goes active as soon as the timer1 clock is > > > enabled. > > > > > Since the jz4740_pwm_disable() function did not work on > > > channels not > > > > > previously enabled, the backlight would shine at full > > > brightness > > > > > from > > > > > the moment the backlight driver would probe, until the > > > backlight > > > > > driver > > > > > tried to *enable* the PWM output. > > > > > > > > > > With this fix, the PWM pins will be forced inactive as soon as > > > > > jz4740_pwm_apply() is called (and might be reconfigured to > > > active if > > > > > dictated by the pwm_state). This means that there is still a > > > tiny > > > > > time > > > > > frame between the .request() and .apply() callbacks where the > > > PWM > > > > > pin > > > > > might be active. Sadly, there is no way to fix this issue: it > > > is > > > > > impossible to write a PWM channel's registers if the > > > corresponding > > > > > clock > > > > > is not enabled, and enabling the clock is what causes the PWM > > > pin > > > > > to go > > > > > active. > > > > > > > > > > There is a workaround, though, which complements this fix: > > > simply > > > > > starting the backlight driver (or any PWM client driver) with a > > > > > "init" > > > > > pinctrl state that sets the pin as an inactive GPIO. Once the > > > > > driver is > > > > > probed and the pinctrl state switches to "default", the > > > regular PWM > > > > > pin > > > > > configuration can be used as it will be properly driven. > > > > > > > > > > Fixes: c2693514a0a1 ("pwm: jz4740: Obtain regmap from parent > > > node") > > > > > Signed-off-by: Paul Cercueil <paul@crapouillou.net> > > > > > Cc: stable@vger.kernel.org > > > > > > > > OK, understood the issue. I think there is another similar issue: > > > The > > > > clk is get and enabled only in the .request() callback. The > > > result is (I > > > > think---depends on a few further conditions) that if you have the > > > > backlight driver as a module and the bootloader enables the > > > backlight to > > > > show a splash screen, the backlight goes off because of the > > > > clk_disable_unused initcall. > > > > > > I will have to verify, but I'm pretty sure disabling the clock > > > doesn't > > > change the pin level back to inactive. > > > > Given that you set the clk's rate depending on the period to apply, I'd > > claim that you need to keep the clk on. Maybe it doesn't hurt, because > > another component of the system keeps the clk running, but it's wrong > > anyhow. Assumptions like these tend to break on new chip revisions. > > If the backlight driver is a module then it will probe before the > clk_disable_unused initcall, unless something is really wrong. I'd claim the clk_disable_unused initcall is called before userspace starts and so before the module can be loaded. Who is wrong here? > So the backlight would stay ON if it was enabled by the bootloader, > unless the DTB decides it doesn't have to be. Don't understand that. How could hte DTB decide the backlight can be disabled? > Anyway, I can try your suggestion, and move the trick to force-disable PWM > pins in the probe(). After that, the clocks can be safely disabled, so I can > disable them (for the disabled PWMs) at the end of the probe and re-enable > them again in their respective .request() callback. I really lost track of the problem here and would appreciate a new submission of the remaining (and improved?) patches. Best regards Uwe
Hi Uwe, Le mardi 17 janvier 2023 à 22:35 +0100, Uwe Kleine-König a écrit : > Hello Paul, > > On Fri, Nov 18, 2022 at 09:55:40AM +0000, Paul Cercueil wrote: > > Le jeu. 17 nov. 2022 à 14:29:27 +0100, Uwe Kleine-König > > <u.kleine-koenig@pengutronix.de> a écrit : > > > Hello Paul, > > > > > > On Tue, Oct 25, 2022 at 11:02:00AM +0100, Paul Cercueil wrote: > > > > Le mar. 25 oct. 2022 à 08:21:29 +0200, Uwe Kleine-König > > > > <u.kleine-koenig@pengutronix.de> a écrit : > > > > > Hello, > > > > > > > > > > On Mon, Oct 24, 2022 at 09:52:09PM +0100, Paul Cercueil > > > > wrote: > > > > > > The "duty > cycle" trick to force the pin level of a > > > > disabled > > > > TCU2 > > > > > > channel would only work when the channel had been enabled > > > > > > previously. > > > > > > > > > > > > Address this issue by enabling the PWM mode in > > > > jz4740_pwm_disable > > > > > > (I know, right) so that the "duty > cycle" trick works > > > > before > > > > > > disabling > > > > > > the PWM channel right after. > > > > > > > > > > > > This issue went unnoticed, as the PWM pins on the > > > > majority of > > > > the > > > > > > boards > > > > > > tested would default to the inactive level once the > > > > corresponding > > > > > > TCU > > > > > > clock was enabled, so the first call to > > > > jz4740_pwm_disable() > > > > would > > > > > > not > > > > > > actually change the pin levels. > > > > > > > > > > > > On the GCW Zero however, the PWM pin for the backlight > > > > (PWM1, > > > > which > > > > > > is > > > > > > a TCU2 channel) goes active as soon as the timer1 clock > > > > is > > > > enabled. > > > > > > Since the jz4740_pwm_disable() function did not work on > > > > channels not > > > > > > previously enabled, the backlight would shine at full > > > > brightness > > > > > > from > > > > > > the moment the backlight driver would probe, until the > > > > backlight > > > > > > driver > > > > > > tried to *enable* the PWM output. > > > > > > > > > > > > With this fix, the PWM pins will be forced inactive as > > > > soon as > > > > > > jz4740_pwm_apply() is called (and might be reconfigured > > > > to > > > > active if > > > > > > dictated by the pwm_state). This means that there is > > > > still a > > > > tiny > > > > > > time > > > > > > frame between the .request() and .apply() callbacks where > > > > the > > > > PWM > > > > > > pin > > > > > > might be active. Sadly, there is no way to fix this > > > > issue: it > > > > is > > > > > > impossible to write a PWM channel's registers if the > > > > corresponding > > > > > > clock > > > > > > is not enabled, and enabling the clock is what causes the > > > > PWM > > > > pin > > > > > > to go > > > > > > active. > > > > > > > > > > > > There is a workaround, though, which complements this > > > > fix: > > > > simply > > > > > > starting the backlight driver (or any PWM client driver) > > > > with a > > > > > > "init" > > > > > > pinctrl state that sets the pin as an inactive GPIO. Once > > > > the > > > > > > driver is > > > > > > probed and the pinctrl state switches to "default", the > > > > regular PWM > > > > > > pin > > > > > > configuration can be used as it will be properly driven. > > > > > > > > > > > > Fixes: c2693514a0a1 ("pwm: jz4740: Obtain regmap from > > > > parent > > > > node") > > > > > > Signed-off-by: Paul Cercueil <paul@crapouillou.net> > > > > > > Cc: stable@vger.kernel.org > > > > > > > > > > OK, understood the issue. I think there is another similar > > > > issue: > > > > The > > > > > clk is get and enabled only in the .request() callback. The > > > > result is (I > > > > > think---depends on a few further conditions) that if you > > > > have the > > > > > backlight driver as a module and the bootloader enables the > > > > backlight to > > > > > show a splash screen, the backlight goes off because of the > > > > > clk_disable_unused initcall. > > > > > > > > I will have to verify, but I'm pretty sure disabling the clock > > > > doesn't > > > > change the pin level back to inactive. > > > > > > Given that you set the clk's rate depending on the period to > > > apply, I'd > > > claim that you need to keep the clk on. Maybe it doesn't hurt, > > > because > > > another component of the system keeps the clk running, but it's > > > wrong > > > anyhow. Assumptions like these tend to break on new chip > > > revisions. > > > > If the backlight driver is a module then it will probe before the > > clk_disable_unused initcall, unless something is really wrong. > > I'd claim the clk_disable_unused initcall is called before userspace > starts and so before the module can be loaded. Who is wrong here? Probably me. > > So the backlight would stay ON if it was enabled by the bootloader, > > unless the DTB decides it doesn't have to be. > > Don't understand that. How could hte DTB decide the backlight can be > disabled? I don't remember what I meant by that :) > > Anyway, I can try your suggestion, and move the trick to force- > > disable PWM > > pins in the probe(). After that, the clocks can be safely disabled, > > so I can > > disable them (for the disabled PWMs) at the end of the probe and > > re-enable > > them again in their respective .request() callback. > > I really lost track of the problem here and would appreciate a new > submission of the remaining (and improved?) patches. Sure. I still have the patchset on the backburner and plan to (eventually) send an updated version. If you are fishing for patches I think you can take patches 3/5 and 4/5 of this patchset. Then I won't have to send them again in v2. Cheers, -Paul
Hello Paul, On Tue, Jan 17, 2023 at 11:05:10PM +0000, Paul Cercueil wrote: > > I really lost track of the problem here and would appreciate a new > > submission of the remaining (and improved?) patches. > > Sure. I still have the patchset on the backburner and plan to > (eventually) send an updated version. > > If you are fishing for patches I think you can take patches 3/5 and 4/5 > of this patchset. Then I won't have to send them again in v2. These are already in Linus' tree :-) Best regards Uwe
diff --git a/drivers/pwm/pwm-jz4740.c b/drivers/pwm/pwm-jz4740.c index a5fdf97c0d2e..228eb104bf1e 100644 --- a/drivers/pwm/pwm-jz4740.c +++ b/drivers/pwm/pwm-jz4740.c @@ -102,11 +102,14 @@ static void jz4740_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm) struct jz4740_pwm_chip *jz = to_jz4740(chip); /* - * Set duty > period. This trick allows the TCU channels in TCU2 mode to - * properly return to their init level. + * Set duty > period, then enable PWM mode and start the counter. + * This trick allows to force the inactive pin level for the TCU2 + * channels. */ regmap_write(jz->map, TCU_REG_TDHRc(pwm->hwpwm), 0xffff); regmap_write(jz->map, TCU_REG_TDFRc(pwm->hwpwm), 0x0); + regmap_set_bits(jz->map, TCU_REG_TCSRc(pwm->hwpwm), TCU_TCSR_PWM_EN); + regmap_write(jz->map, TCU_REG_TESR, BIT(pwm->hwpwm)); /* * Disable PWM output.