Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3519613imu; Mon, 10 Dec 2018 03:39:01 -0800 (PST) X-Google-Smtp-Source: AFSGD/VECCYLYhtTUOEYAnXBGxGn2Khj7pmcm6LjPz9tkVEDc8bjH/Uoyig6af6KXIMjSiq/yqW1 X-Received: by 2002:a63:9306:: with SMTP id b6mr10099608pge.36.1544441941386; Mon, 10 Dec 2018 03:39:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544441941; cv=none; d=google.com; s=arc-20160816; b=lwmpMfmP+blBINKbtmiGJXwo2yM8EkOSEG/cFpD1OvvvSROiddZyofI7k/tTL8xDYj +mMUvmXTcMqV7Gy/g0hgqwo9ehoNQntFHmwpqrZ7Ja6Hotqam89N2Y78tUThcfNCTmUo zCDx3bb9B756oAw5HM1NsCBUuUIc4v6T8CatHvSyIFECeVwm/rA6RsqPbK28kKwjsuW+ LFOp/6U3JgwqYMlzxXsmEaKv+Uj1+3uurcPmNsTEMLzadLnVsYLANzPvor3t+iP1UPWC TpUjUZnXLAwHRaEQunZ9pD3ZIJi0SrzF0oOHI+zrn1lSSD5oExNgw3EHHPPl1RRrXXqa vqww== 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=zpVkZXsoPCUjt5iQM+DmHvdoKBNR1DQB9SKKjYqFewk=; b=eRCpRniw0S+jECPUmmoQiTNzUElQcDFXEqLxotLNN3f4/uFtbI006Ht6jcvqOI0yl9 oZ8DOyavwgLcJdKh849wIbX5eE4YuqlgLu7TBM7Bs6bDh3VoBP4iZmM1wNlHZSHUoe4A 5BVn3xr4UxVqfyNoxcJL9a/71dsEgR/eHvxXkyRytod+JUgnX5zLRVTPUfHqmmzyKebL nw2IC4ds2z7L1yT6WPPdQ7G2Zyulfua/GfvXHwX7EhcWraEwGsiFIN5TajAhGQv2iOCC BZ/fTlMMy2WSsT/NG/Hg4gquRaGasJ9YZHOjtA/59I0WQj1ocwhU8BRtVadlZsHIE+I+ BDbw== 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 v4si9907332pfm.71.2018.12.10.03.38.43; Mon, 10 Dec 2018 03:39:01 -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 S1727396AbeLJLRy (ORCPT + 99 others); Mon, 10 Dec 2018 06:17:54 -0500 Received: from metis.ext.pengutronix.de ([85.220.165.71]:51555 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727384AbeLJLRx (ORCPT ); Mon, 10 Dec 2018 06:17:53 -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 1gWJZL-0004uF-Uc; Mon, 10 Dec 2018 12:17:47 +0100 Received: from ukl by ptx.hi.pengutronix.de with local (Exim 4.89) (envelope-from ) id 1gWJZK-0002Nl-B4; Mon, 10 Dec 2018 12:17:46 +0100 Date: Mon, 10 Dec 2018 12:17:46 +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: <20181210111746.36zyedeaajfcdfeh@pengutronix.de> References: <1544103655-104466-1-git-send-email-michal.vokac@ysoft.com> <1544103655-104466-3-git-send-email-michal.vokac@ysoft.com> <20181206135902.un2nbreqfmi6mpd6@pengutronix.de> <01aaa6ff-fb3e-37a7-0e72-099ad013ee2a@ysoft.com> <20181206161622.okpfiecfphar77jk@pengutronix.de> <8b88d225-efc7-623a-d1a6-8b3cfcfd5e07@ysoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <8b88d225-efc7-623a-d1a6-8b3cfcfd5e07@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 Mon, Dec 10, 2018 at 11:15:05AM +0000, Vokáč Michal wrote: > On 6.12.2018 17:16, Uwe Kleine-König wrote: > > On Thu, Dec 06, 2018 at 03:37:55PM +0000, Vokáč Michal wrote: > >> On 6.12.2018 14:59, Uwe Kleine-König wrote: > >>> On Thu, Dec 06, 2018 at 01:41:31PM +0000, Vokáč Michal wrote: > >>> > >>> Can it happen, that pinctrl_pins_pwm is PTR_ERR(-EPROBE_DEFER)? > >> > >> No. The pinctrl_lookup_state either returns pointer to the pinctrl state > >> or ERR_PTR(-ENODEV). But I do not explicitly test the pinctrl_pins_pwm > >> for PTR_ERR(-EPROBE_DEFER), or do I? > > > > You don't, I just wondered if this could happen and the function should > > return -EPROBE_DEFER in this case, too. > > OK. > > >>> Maybe you only want to ignore PTR_ERR(-ENODEV) and for example propagate > >>> -EIO? I think you want to put the gpio if the failure is because there > >>> is a pinctrl related error. > >> > >> I think that is what I am doing. In case the GPIO is not ready the probe > >> is deferred. In case of any other error with the GPIO or pinctrl failure > >> I put the pinctrl. Or maybe I do not really understand what you mean. > > > > Yes, you put the pinctrl, but not the GPIO. I.e. you're not undoing > > devm_gpiod_get_optional(). Maybe only do this if the pinctrl stuff > > succeeded to not touch the GPIO if it won't be used? > > OK, I agree it seems better to get the pinctrl first and if it succeeds > only then try to get the GPIO. In that case I need to use the non-optional > variant of devm_gpio_get(). Note that then I do not really need to put the > GPIO in the error path as it means I did not get it. > The code would look like: > > +static int imx_pwm_init_pinctrl_info(struct imx_chip *imx_chip, > + struct platform_device *pdev) > +{ > + imx_chip->pinctrl = devm_pinctrl_get(&pdev->dev); > + if (IS_ERR(imx_chip->pinctrl)) { > + dev_dbg(&pdev->dev, "can not get pinctrl\n"); > + return PTR_ERR(imx_chip->pinctrl); > + } > + > + imx_chip->pinctrl_pins_pwm = pinctrl_lookup_state(imx_chip->pinctrl, > + "pwm"); > + imx_chip->pinctrl_pins_gpio = pinctrl_lookup_state(imx_chip->pinctrl, > + "gpio"); > + > + if (IS_ERR(imx_chip->pinctrl_pins_pwm) || > + IS_ERR(imx_chip->pinctrl_pins_gpio)) { > + dev_dbg(&pdev->dev, "pinctrl information incomplete\n"); > + goto out; > + } > + > + imx_chip->pwm_gpiod = devm_gpiod_get(&pdev->dev, "pwm", GPIOD_IN); > + if (PTR_ERR(imx_chip->pwm_gpiod) == -EPROBE_DEFER) { > + return -EPROBE_DEFER; > + } else if (IS_ERR(imx_chip->pwm_gpiod)) { > + dev_dbg(&pdev->dev, "GPIO information incomplete\n"); > + goto out; > + } > + > + return 0; > + > +out: > + devm_pinctrl_put(imx_chip->pinctrl); > + imx_chip->pinctrl = NULL; > + > + return 0; > +} This looks right. > >>> ISTR that there was a patch that implements get_state for imx. Is there > >>> a dependency on that one? Otherwise the state returned by > >>> pwm_get_state() might not be what is actually configured. > >> > >> No, it should be independent. One can go without the other. I tested all > >> three combinations (mainline with .get_state, mainline with this series, > >> mainline with .get_state AND this series) and got the expected results. > >> Without the .get_state() patch the core always returns the default which > >> is disabled state so the gpio pinctrl state is selected in probe. > > > > Without .get_state it won't be possible to smoothly take over a running > > PWM. > > But that is exactly how the current pwm-imx code works, right? But then at least the pwm would run until the first consumer reconfigures it. Best regards Uwe -- Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | http://www.pengutronix.de/ |