Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3222041imu; Wed, 7 Nov 2018 07:02:51 -0800 (PST) X-Google-Smtp-Source: AJdET5f80vmMVwZjf2vTYME9FWX5uJUdmRCnjR07QVjccF9OtbMu0599rohkx45kYXHP91cPcYlj X-Received: by 2002:a62:401:: with SMTP id 1-v6mr546617pfe.156.1541602971488; Wed, 07 Nov 2018 07:02:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541602971; cv=none; d=google.com; s=arc-20160816; b=yfJqXLQasa1L4qV+WFfoWTJDMrjpScX5efLQANX9QDYjAWNEKzYG/igzv49sQxeLBR qHgP/3ymYKTqT9oC7RLYbubSfSNy+FyHVaBA9u4d8LE7QMvrTcy+QBrobO1hNpa6Jlj/ Rfn7yRR57bogcEOeAf2Vj/GWGGguKbYAG3/rpPStw7YoNyNE4SrWfOTFygYKbHtjj+xd n14xF5SjRZvy/MkaV8oRdO0YTg1xyFz1g1KOqGe4ll5jHM0dH2nXA8oFgNHfGnr/ZgbD GtAnyRCdKBCDOTRcMAYmZLIpNOrUKayc2rSHwZF06mVDotE32jjqHKwKYQHzYxg7WJGA Ga5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=PPPEB5A2/Q7GQ5+cKmi7We2IhePZ/qXyYhfeCMFOE6o=; b=KV5evd2YshWylW0DVlzqQqqKpJuYQmLOvMGi4wY3tAJrFGAIXnb50iUSsVjzJiRHmG fTvDFJ1KWkTuL48hrzTXsRzgr883zVgavl3P0s3T5eu4Ry2tj5Cg38rjxjts/ttummpJ VewImJUjsa4pkzvJgSKkOJSBKGO06vpxpQrw6MnifHNDD68WB7RlECUtCNVIGlexVOQ0 HOBh/c9j9MEYpWa7fdJa1mFE5X0u0iOlQ/B3FIflGeVcKoXZE8t6VwzQ3ODWffEE6WuC 6Yk8Jjjfoq87uBlK5UvXLcPreIyV42La5c3TEW10vvxSGolMSjfLBJsTtb9CLV1lbI4/ oggg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o3si792459pgi.388.2018.11.07.07.02.35; Wed, 07 Nov 2018 07:02:51 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387793AbeKHAcR (ORCPT + 99 others); Wed, 7 Nov 2018 19:32:17 -0500 Received: from metis.ext.pengutronix.de ([85.220.165.71]:50885 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731109AbeKHAcR (ORCPT ); Wed, 7 Nov 2018 19:32:17 -0500 Received: from ptx.hi.pengutronix.de ([2001:67c:670:100:1d::c0]) by metis.ext.pengutronix.de with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gKPKg-0003cE-QM; Wed, 07 Nov 2018 16:01:26 +0100 Received: from ukl by ptx.hi.pengutronix.de with local (Exim 4.89) (envelope-from ) id 1gKPKf-0002au-Ei; Wed, 07 Nov 2018 16:01:25 +0100 Date: Wed, 7 Nov 2018 16:01:25 +0100 From: Uwe =?iso-8859-1?Q?Kleine-K=F6nig?= To: =?utf-8?B?Vm9rw6HEjQ==?= Michal Cc: Thierry Reding , Rob Herring , Mark Rutland , "devicetree@vger.kernel.org" , "linux-pwm@vger.kernel.org" , "linux-kernel@vger.kernel.org" , Lukasz Majewski , Fabio Estevam , Lothar =?iso-8859-1?Q?Wa=DFmann?= , "kernel@pengutronix.de" Subject: Re: =?iso-8859-1?B?W1JDRqBQQVRDSCx2Miwy?= =?iso-8859-1?B?LzJd?= pwm: imx: Configure output to GPIO in disabled state Message-ID: <20181107150125.7cpd4v5t7yi2254c@pengutronix.de> References: <1539163920-9442-3-git-send-email-michal.vokac@ysoft.com> <20181012085720.GA9451@taurus.defre.kleine-koenig.org> <20181012160854.hmgpokxgsrqdzobx@pengutronix.de> <20181107093355.e4n3irrnkybqsjvc@pengutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: NeoMutt/20170113 (1.7.2) X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::c0 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello Michal, On Wed, Nov 07, 2018 at 01:32:10PM +0000, Vokáč Michal wrote: > On 7.11.2018 10:33, Uwe Kleine-König wrote: > > Hello Michal, > > > > just to state it more explicitly, I think the following patch (not even > > compile tested) is much preferable over your approach: > > Interesting idea. I just wonder why nobody else did not come up with such > a simple solution before. I think I mentioned it already in this thread, but it went unnoticed :-) > > diff --git a/drivers/pwm/pwm-imx.c b/drivers/pwm/pwm-imx.c > > index 1d5242c9cde0..af88644b5efb 100644 > > --- a/drivers/pwm/pwm-imx.c > > +++ b/drivers/pwm/pwm-imx.c > > @@ -216,7 +216,14 @@ static int imx_pwm_apply_v2(struct pwm_chip *chip, struct pwm_device *pwm, > > cr |= MX3_PWMCR_POUTC; > > > > writel(cr, imx->mmio_base + MX3_PWMCR); > > - } else if (cstate.enabled) { > > + } else if (cstate.enabled && state->polarity == PWM_POLARITY_NORMAL) { > > + /* > > + * When disabled in hardware the output pin goes to 0 > > + * independant of the polarity setting. The expectation of some > > + * people however is that after disabling the pin goes to the > > + * inactive level which isn't given for an inversed pwm, so > > + * only disable for normal polarity. > > + */ > > writel(0, imx->mmio_base + MX3_PWMCR); > > > > clk_disable_unprepare(imx->clk_per); > > I tested your patch. It does not work as you expected. > > In v4.20-rc1 the pwm-backlight driver has been converted to atomic API. > So the pwm_apply_v2 function is called only once to set new period/duty > and state. With your patch that means that "echo 0 > brightness" has no > visible effect. It leaves the PWM chip enabled with period/duty set to > however it was. But the core thinks it was reconfigured: Then the patch isn't correct yet. The idea is always keep the hardware running and only disable it if it's uninverted. > > # cat /sys/class/backlight/backight/brightness > 0 > > # cat /sys/kernel/debug/pwm > platform/2080000.pwm, 1 PWM device > pwm-0 (backlight ): requested period: 500000 ns duty: 0 ns polarity: inverse > > > I think it solves most if not all problems you want to address with the > > pinctrl stuff. > > Unfortunately not. I also tested your patch on v4.19. It works as you > probably intended - it is possible to disable backlight without the PWM > chip being disabled. But it does not solve the time frame between > imx_pwm_probe() and imx_pwm_apply_v2(). In imx_pwm_probe it's not yet known what the polarity is supposed to be, right? So the right thing to do there is to not touch the configuration of the pwm. I think all states that are problematic then are also problematic with the gpio/pinmux approach. (I might be wrong here, so feel free to invest some brain cycles to prove me wrong. But I'd be surprised if there are problems that are relevant.) > In probe you do not have any users yet. So you do not know the requested > output polarity. With "default" pinctrl the PWM output would be muxed to > the selected pin and since the PWM chip is most probably disabled > (unless you enabled it in bootloader) you would get low level on the pin. > That means your backlight is fully enabled until the first call to > imx_pwm_apply_v2(). On my system this is 2 seconds. With the gpio/pinmux approach you don't know the intended polarity either and maybe enable the display, too. For both the solution is to let the bootloader enable the pwm with the right output level. Am I missing something? > It might not be a big issue for backlight but for motor control it is > not the right thing to do. > > The other thing is I would prefer to make the change optional. With your > approach you are changing the behavior for all current users of inverted > PWM. I do not think all imx6 users are aware of the problem so they might > not be OK with the sudden change in the behavior. Isn't my change an improvement for all users? What state do you have in mind that make things worse than they are now? Best regards Uwe -- Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | http://www.pengutronix.de/ |