Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1777937imu; Wed, 12 Dec 2018 04:15:45 -0800 (PST) X-Google-Smtp-Source: AFSGD/XnbW/NGPO/k6fr6pgzSyshzQChJ+Yjs/xF3t6kvJ5ZUqvgfMs+VM1k8DXMwR0uU7OcnElX X-Received: by 2002:a63:3f44:: with SMTP id m65mr18553103pga.115.1544616945743; Wed, 12 Dec 2018 04:15:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544616945; cv=none; d=google.com; s=arc-20160816; b=mmEgawQCwjrCLMXQGgKPnNJbIlC1TiLusaD6ydjbEyEdpZwDNfbx+bvbNn7Qd25YTE 36yjmB5QYmYJIxP22RLmkWpSqcNsWx89ob46p0HGWPspedNfj9baLvPYlMKtfnxNHhYv kZB1z6qkHQ5T+5my+jSi9GqbvcdWLlBQQtbqfpq0Z/a7Yo9uwb9fUogls6/13Log6e+Z HLBQ7yEP3rTPO7tlbgXLzkJ7Jc8bEv+VCoi1eaPPFtG4dfcpr2qo7EhKwlGHh4opGYwE GzRG8kNJaAVXHwofvKiuMTWm8eOektH+S4ADQW/IWN/Hmilh75zYg4sDgFiMJC4nysib jEOg== 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=baa5vi1VIo34OhADSuQWgyCepGHp3cDNkLSOob0NgcM=; b=0REy995JgvgWm9ACGZDacasv2covpsw/XGok0LQS6/sMiQE4vgvQa4Sgs9dtaTHJPJ X7V1WaFjIjGP9TPKjlwBM06nCQWOxFPyo6VN8FYCNERmpthk05gndfA6jG/rLXRheP2L Brbtvv0V801ZZCesa/IUjOzTL1sQkEVhW5w9Upa0REdZY60SsC2YUi8B+dmKYT1JC0Eb 0iKpUQF4Gm/cRmY+c/h/I33O8LUohvWIxX6zuJxLZClGKy34pvOhyRuKvDS6YyREHrsL SxK+HSet+J9o6lv1hHG7RxNzWnBs0nvLetyhSiVCdkbuBUTWsakRWk5T12LXHpDkj5wi Dgtg== 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 24si14641214pgm.167.2018.12.12.04.15.09; Wed, 12 Dec 2018 04:15:45 -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 S1727322AbeLLMNE (ORCPT + 99 others); Wed, 12 Dec 2018 07:13:04 -0500 Received: from metis.ext.pengutronix.de ([85.220.165.71]:46121 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727091AbeLLMNE (ORCPT ); Wed, 12 Dec 2018 07:13:04 -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 1gX3Np-0002Oi-OR; Wed, 12 Dec 2018 13:12:57 +0100 Received: from ukl by ptx.hi.pengutronix.de with local (Exim 4.89) (envelope-from ) id 1gX3Nn-000436-QP; Wed, 12 Dec 2018 13:12:55 +0100 Date: Wed, 12 Dec 2018 13:12:55 +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?= , Linus Walleij Subject: Re: [RFC PATCH v3 2/2] pwm: imx: Configure output to GPIO in disabled state Message-ID: <20181212121255.yg6b4pw7qord7ebi@pengutronix.de> References: <1544103655-104466-1-git-send-email-michal.vokac@ysoft.com> <1544103655-104466-3-git-send-email-michal.vokac@ysoft.com> <20181212080154.kcfh57mulypwuscu@pengutronix.de> <52ed0614-d1f5-81cb-3b17-8eb137967872@ysoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <52ed0614-d1f5-81cb-3b17-8eb137967872@ysoft.com> 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 On Wed, Dec 12, 2018 at 11:42:17AM +0000, Vokáč Michal wrote: > On 12.12.2018 09:01, Uwe Kleine-König wrote: > > On Thu, Dec 06, 2018 at 01:41:31PM +0000, Vokáč Michal wrote: > >> Normally the PWM output is held LOW when PWM is disabled. This can cause > >> problems when inverted PWM signal polarity is needed. With this behavior > >> the connected circuit is fed by 100% duty cycle instead of being shut-off. > >> > >> Allow users to define a "pwm" and a "gpio" pinctrl states. The pwm pinctrl > >> state is selected when PWM is enabled and the gpio pinctrl state is > >> selected when PWM is disabled. In the gpio state the new pwm-gpios GPIO is > >> configured as input and the internal pull-up resistor is used to pull the > >> output level high. > >> > >> If all the pinctrl states and the pwm-gpios GPIO are not correctly > >> specified in DT the PWM work as usual. > >> > >> As an example, with this patch a PWM controlled backlight with inversed > >> signal polarity can be used in full brightness range. Without this patch > >> the backlight can not be turned off as brightness = 0 disables the PWM > >> and that in turn set PWM output LOW, that is full brightness. > >> > >> Inverted output of the PWM with "default" and with "pwm"+"gpio" pinctrl: > >> > >> +--------------+------------+---------------+----------- +-------------+ > >> | After reset | Bootloader | PWM probe | PWM | PWM | > >> | 100k pull-up | | | enable 30% | disable | > >> +--------------+------------+---------------+------------+-------------+ > >> | pinctrl | none | default | default | default | > >> | out H __________________ __ __ | > >> | out L \_________________/ \_/ \_/\____________ | > >> | ^ ^ ^ | > >> +--------------+------------+---------------+------------+-------------+ > >> | pinctrl | none | gpio | pwm | gpio | > >> | out H __________________________________ __ __ _____________ | > >> | out L \_/ \_/ \_/ | > >> | ^ ^ ^ | > >> +----------------------------------------------------------------------+ > >> > >> Signed-off-by: Michal Vokáč > >> --- > >> Changes in v3: > >> - Commit message update. > >> - Minor fix in code comment (Uwe) > >> - Align function arguments to the opening parentheses. (Uwe) > >> - Do not test devm_pinctrl_get for NULL. (Thierry) > >> - Convert all messages to dev_dbg() (Thierry) > >> - Do not actively drive the pin in gpio state. Configure it as input > >> and rely solely on the internal pull-up. (Thierry) > >> > >> Changes in v2: > >> - Utilize the "pwm" and "gpio" pinctrl states. > >> - Use the pwm-gpios signal to drive the output in "gpio" pinctrl state. > >> - Select the right pinctrl state in probe. > >> > >> drivers/pwm/pwm-imx.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++ > >> 1 file changed, 77 insertions(+) > >> > > [ snip ] > > > On thing I noticed while looking at the rcar driver is: This doesn't > > wait for the current period to end. Is this supposed to happen? Also for > > the enable case the hardware is configured for the desired duty cycle > > and only then the pinctrl is switched to pwm. Both might result in a > > spike that is not desired. > > The behavior should not change from how imx-pwm was working before. > When PWM is disabled the output is immediately gated off (put into > the idle state) independently on the period. I measured this. Oh really, I wasn't aware of that. This is another bug in the imx pwm then (I think). > For the enable case you would certainly not get any additional spikes. Yes, there is a possibility for a spike: If you configure for say 40%: _ _ pwm output : ___/ \__/ \__ muxing : GPIO| PWM_ actual output: ____/\__/ \__ > The worst thing that may happen is that the first period will be > slightly shorter depending on how long it takes to test the pinctrl > and switch the muxing. And this is unavoidable, it would happen even > if you wait for the start of a period. The test + muxing still takes > some time. You could first configure for duty_cycle 0 and a short period, then mux to PWM and then configure the correct duty cycle. Ditto for disable. Best regards Uwe -- Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | http://www.pengutronix.de/ |