Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1944000imu; Sun, 18 Nov 2018 12:09:44 -0800 (PST) X-Google-Smtp-Source: AJdET5eW4mPhaza8m2uTk7KMTnjKKpilgL/MrLlfN+OcTmOA6xqEt809exP3Pquru0TP8Tv1g2FA X-Received: by 2002:a17:902:c5:: with SMTP id a63-v6mr19556111pla.201.1542571784289; Sun, 18 Nov 2018 12:09:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542571784; cv=none; d=google.com; s=arc-20160816; b=jGLXuV5nk3OxbLUnBxvuXiAJYUX46bz+dbV6iybMJmKzoDNlPVBxtzZDkgCzx2qv4+ 6CPoV5IwqDOv6ZhAWp3yzLrebv65PS+9Q6Hz+RyAAjiDXUAIAgoyC1Gf6f18+lqMvMwj FRt9dqUe8O4FXD1/N14lkNzOI70TrldGD1ww8cV2J7nXblNudnhf6E0YC2pR+iS0L5XY C5kM8465/TvMtS5TKVZYiSIY0AuE0ftelIUE10cx8ZWZjBzJ5op3wdslF1qyU7ANaoZ+ qUq0Q95I3+s4NhsN1p6IYAWx74SQOzVtgVRwdurSPDK2PAM0Dku3JJCqB5Z92SfI++UZ wVPQ== 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=2CY+OpIVRZI7yCc4nO/JPSm6DdMN02xndlFDlX8DT9E=; b=zBp++iXbG8jL4Vm7oM1+O1LhIkfvK6dK1l9XSIowjKD3rZ9gR8pqvYrsb+qsfQg0yX VWsfyc7OwipNpIEhOmC0JYHXl9lf0y8jmuH5Na6+0gdpMWj595RD+lbv+NZuL6MQrEeu sJsLaW0c8XmEbyaBZF2TlpW8smhBBgXVZj1zlq1kOXZmZSxpiJsynbuhynKvPFWr6oXZ XChH2R6HHcdJhyMObALQpjOAl+nFEzaEKKVTCIQRudRux/H1sSUH+mbs2AjDorTmucVF JBw2nHtMDjw/Dy6e+8pKlNtE4XM2m85DZPR5Gv/wxgsMqAAGhvGWoyfcF9+khr9JjBYC nowA== 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 194si34568156pgg.519.2018.11.18.12.09.28; Sun, 18 Nov 2018 12:09:44 -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 S1727045AbeKSG3h (ORCPT + 99 others); Mon, 19 Nov 2018 01:29:37 -0500 Received: from metis.ext.pengutronix.de ([85.220.165.71]:55451 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725805AbeKSG3h (ORCPT ); Mon, 19 Nov 2018 01:29:37 -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 1gOTMg-0000Xm-0H; Sun, 18 Nov 2018 21:08:18 +0100 Received: from ukl by ptx.hi.pengutronix.de with local (Exim 4.89) (envelope-from ) id 1gOTMd-0000l1-Lb; Sun, 18 Nov 2018 21:08:15 +0100 Date: Sun, 18 Nov 2018 21:08:15 +0100 From: Uwe =?iso-8859-1?Q?Kleine-K=F6nig?= To: Thierry Reding Cc: =?utf-8?B?Vm9rw6HEjQ==?= Michal , Mark Rutland , "devicetree@vger.kernel.org" , "linux-pwm@vger.kernel.org" , Lukasz Majewski , "linux-kernel@vger.kernel.org" , Rob Herring , "kernel@pengutronix.de" , Fabio Estevam , Lothar =?iso-8859-1?Q?Wa=DFmann?= , Linus Walleij Subject: Re: =?iso-8859-1?B?W1JDRqBQQVRDSCx2Miwy?= =?iso-8859-1?B?LzJd?= pwm: imx: Configure output to GPIO in disabled state Message-ID: <20181118200815.a6hkokt3otfm4yl4@pengutronix.de> References: <20181108191855.zuon3ecv4yjfbs7g@pengutronix.de> <283cfef3-16d0-8bd4-e306-6e34d44c3a86@ysoft.com> <20181109165555.vqbiwh4hlcnozdna@pengutronix.de> <20181114113449.GB2620@ulmo> <20181114215120.vddykljqyavm64wj@pengutronix.de> <20181115152545.GA8611@ulmo> <20181115203733.qvonika6yhn2bsnb@pengutronix.de> <20181116095124.GA28631@ulmo> <20181116103929.cxfvuc2te7cadhp2@pengutronix.de> <20181116122445.GA25386@ulmo> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20181116122445.GA25386@ulmo> 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 Thierry, On Fri, Nov 16, 2018 at 01:24:45PM +0100, Thierry Reding wrote: > On Fri, Nov 16, 2018 at 11:39:29AM +0100, Uwe Kleine-König wrote: > > On Fri, Nov 16, 2018 at 10:51:24AM +0100, Thierry Reding wrote: > > > On Thu, Nov 15, 2018 at 09:37:33PM +0100, Uwe Kleine-König wrote: > > > > On Thu, Nov 15, 2018 at 04:25:45PM +0100, Thierry Reding wrote: > > > > > On Wed, Nov 14, 2018 at 10:51:20PM +0100, Uwe Kleine-König wrote: > > > > > > On Wed, Nov 14, 2018 at 12:34:49PM +0100, Thierry Reding wrote: > > > > > > > On Fri, Nov 09, 2018 at 05:55:55PM +0100, Uwe Kleine-König wrote: > > > > > > > > On Fri, Nov 09, 2018 at 02:24:42PM +0000, Vokáč Michal wrote: > > > > > > > > > On 8.11.2018 20:18, Uwe Kleine-König wrote: > > > > > > > > > > Taking your example with the backlight device you specify an "init" and > > > > > > > > > > a "default" pinctrl and only "default" contains the muxing for the PWM > > > > > > > > > > pin everything should be as smooth as necessary: The pwm is only muxed > > > > > > > > > > when the backlight device is successfully bound. > > > > > > > > > > > > > > > > > > Have you tried that Uwe? The bad news is I tested that before and now > > > > > > > > > again and it does not work like that. We already discussed that earlier. > > > > > > > > > > > > > > > > The key is that the pinmux setting for the PWM pin should be part of the > > > > > > > > bl pinctrl, not the pwm pinctrl. Then "default" is only setup when the > > > > > > > > bl device is successfully bound which is after the bl's .probe callback > > > > > > > > called pwm_apply(). > > > > > > > > > > > > > > No, that's not at all correct. Pinmux settings should reside with the > > > > > > > consumer of the pin. In this case, the PWM is the consumer of the pin, > > > > > > > whereas the backlight is the consumer of the *PWM*. > > > > > > > > > > > > This is news to me. Adding Linus W. to Cc, maybe he can comment?! > > > > > > > > > > > > Grepping through the arm device trees it really seems common to put the > > > > > > pinctrl for the pwm pin into the pwm device. I didn't search in depth, > > > > > > but I didn't find a counter example. > > > > > > > > > > > > For GPIOs it is common that the pinmuxing is included in the GPIO's > > > > > > consumer pinctrl. Ditto for mdio busses whose pinctrl is included in the > > > > > > ethernet pinctrl. > > > > > > > > > > GPIO is different from PWM in that the GPIO is already the pin itself > > > > > and is otherwise generic. So typically you put the pinmuxing options > > > > > into the device tree node for the consumer of the GPIO, because it is > > > > > only when the consumer uses the GPIO that you need to configure that > > > > > pin as GPIO. > > > > > > > > > > For PWM, however, the PWM consumer is only the consumer of the PWM, but > > > > > the PWM device itself is the real consumer of the pin that outputs the > > > > > PWM signal. So the PWM determines when the pinmux states need to be > > > > > applied, whereas the consumer of the PWM only deals with the PWM. > > > > > > > > > > For MDIO busses, I think they are usually part of, and driven by, the > > > > > ethernet controller, so again it makes sense to put the pinmux into the > > > > > node of the ethernet controller, because the ethernet controller is the > > > > > user of the pins. > > > > > > > > Maybe it was a bad idea to broaden the discussion to talk about gpios > > > > and ethernet stuff here. I'd still consider it a valid construct to put > > > > the pwm pin into the backlight's pinctrl unless Linux W. disagrees. > > > > > > But why? The backlight doesn't care about the specific pinmuxing of the > > > PWM pin. All it cares about is the PWM signal. That's the level of > > > abstraction that the PWM consumer expects, anything lower level belongs > > > in the PWM driver. > > > > The backlight driver cares about the PWM pin muxing because if it's > > wrongly muxed the backlight doesn't work as intended. > > It shouldn't care about that. It should only care about the PWM and the > PWM should make sure that the pin is correctly muxed because otherwise > it can't work as expected. > > > > > > > > The problem with making the PWM mode the "default" pinctrl state is that > > > > > > > the default state will be applied before the driver is even probed. That > > > > > > > makes it unsuitable for this case. I think what we really want here is > > > > > > > explicitly "active" and "inactive" states for pinctrl where the PWM > > > > > > > driver controls when exactly each state is applied. > > > > > > > > > > > > Note that this problem goes away nicely if the pwm pin is attached to > > > > > > the backlight. Because it's the backlight's driver that "knows" when the > > > > > > pwm is configured correctly and so the already existing mechanisms that > > > > > > setup the mux when the bl is correctly probed do the right thing at the > > > > > > right time. > > > > > > > > > > Actually that's not exactly true. The default pinctrl state will be > > > > > applied before the driver's ->probe() implementation, so the pinctrl > > > > > state will be active some time before even the backlight driver gets > > > > > around to setting up the PWM. If you look at drivers/base/dd.c you'll > > > > > see that really_probe() calls pinctrl_bind_pins() before calling the > > > > > driver's ->probe() and will select the default state (unless there's > > > > > also an "init" state defined, in which case that will get applied and > > > > > only after successful probe will the default state be selected). > > > > > > > > > > So if you use only a default state, then you could even get into a > > > > > situation where ->probe() return -EPROBE_DEFER and it would potentially > > > > > take several seconds before the driver is reprobed, during which time > > > > > the pinmux will already be set up but the PWM not configured properly > > > > > and potentially outputting the wrong level. > > > > > > > > If you reread my suggestion to Michal completely you will notice I got > > > > that right. > > > > > > > > > > > This solves the problem quite nicely because by default the pinctrl > > > > > > > state isn't touched. For the case where the bootloader didn't initialize > > > > > > > the PWM pin at all, the driver core won't do anything and keep it at the > > > > > > > 100k pull-up default. > > > > > > > > > > > > Ditto if the pwm pinctrl is attached to the consumer without having to > > > > > > introduce new pwm-specific stuff. > > > > > > > > > > Well yes, but you'd obviously also have to avoid using the "default" > > > > > state, otherwise you'd run into the issues that I described above. > > > > > > > > I'd need "default" and "init", right. > > > > > > > > > > > > > > No I meant the pwm. Well, it's as easy as that: Whenever with your > > > > > > > > > > approach you configure the pin as GPIO with the output set to low, > > > > > > > > > > instead configure the pwm with duty_cycle to zero (or disable it). > > > > > > > > > > Whenever with your approach you configure the pin as GPIO with the > > > > > > > > > > output set to high, configure the pwm with duty_cycle to 100%. (Keeping > > > > > > > > > > out inverted PWMs for the ease of discussion, but the procedure can be > > > > > > > > > > adapted accordingly.) The only difference then is that with your > > > > > > > > > > approach you already "know" in pwm-imx's .probe the idle level and can > > > > > > > > > > configure the GPIO accordingly. With my approach you just have to wait > > > > > > > > > > until the first pwm_apply which (as described above) works just as well. > > > > > > > > > > > > > > > > > > While here I am quite confident you are talking about kernel code, right? > > > > > > > > > If yes, then your approach is clear to me. > > > > > > > > > > > > > > > > > > The problem is I am quite sure your approach does not solve the cases > > > > > > > > > the pinctrl solution does. And according to my tests so far it does not > > > > > > > > > work at all because the "init" and "default" states does not work as you > > > > > > > > > are saying. > > > > > > > > > > > > > > > > That's as pointed out above, because you're looking at the pwm's pinctrl > > > > > > > > and I at the pwm-consumer's pinctrl. > > > > > > > > > > > > > > > > Note that a sysfs consumer cannot be operated smoothly here, because > > > > > > > > there is no pinctrl node to add the PWM mode to that only gets active > > > > > > > > after the first configuration. This however is something that should not > > > > > > > > be addressed in the imx driver but in the pwm core (if at all). > > > > > > > > > > > > > > With the pinctrl-based solution outlined above you can even operate a > > > > > > > sysfs consumer properly. The pinctrl states are where they belong, with > > > > > > > the PWM device and therefore they can be properly set when the PWM is > > > > > > > used, rather than waiting for a PWM consumer to muck with the pinmux. > > > > > > > > > > > > > > Note how all the pieces are suddenly falling into place. In my > > > > > > > experience that's usually a good indication that you're on the right > > > > > > > track. > > > > > > > > > > > > OK, sysfs is the only point where the "put pinctrl stuff into the pwm > > > > > > core (or driver)" is superior to the already existing and otherwise > > > > > > completely working status quo. (Apart from bugs that need fixing in > > > > > > your scenario, too.) > > > > > > > > > > Nope, sorry. It's superior in all of the other cases as well. You've > > > > > said elsewhere already that the prerequisite for the current solution to > > > > > support inverse polarity with the i.MX driver is to keep the driver > > > > > running, even after the PWM is no longer used. Sorry but that's just not > > > > > an option for me. > > > > > > > > You want that after pwm_disable() the pin still keeps the idle level. As > > > > the hardware doesn't provide this feature "as is" something has to be > > > > done about it. This can be reached either by operating the pin as PWM > > > > with 0% duty cycle or by switching to GPIO that is configured to the > > > > desired level. From the PWM driver's POV the first is the more natural, > > > > as this can be accomplished with the registers this driver cares about > > > > anyhow. > > > > > > We've been over this before. Yes, as long as you operate the pin as PWM > > > it's okay to just actively drive it. But once you no longer use the pin, > > > why would you want to still actively drive it? > > > > This is because you say the pin should keep its level as inactive even > > though that's not what the hardware does without keeping care. > > > > I say this is strange: The consumer specifies if the pwm should be > > inverted or not because the pwm alone doesn't know that. Then with the > > consumer gone *you* want the pwm to "remember" its last user requested > > inversion and so the pin should stay at 1. > > > > To answer your question: I don't want to actively drive the pin when the > > user is gone. That's a requirement comming from you. > > That's not actually what I'm suggesting. What I'm saying is that the PWM > should not actively drive the pin at all. I'm a tad annoyed and grumpy here. We're discussing since quite some time about what is the right thing to do on pwm_disable(). Up to now I understood you that it should make the pin drive the inactive level. Thinking a bit about this it doesn't really matter for the consumer if the pin stays in the idle level because there is a pull into the right direction and the PWM is high-Z or if the PWM pulls actively in the right direction. Also for pwm_config(pwm, 0, 100) the PWM could disable its output in the presence of a pull, so the property says true that the effects of pwm_config(pwm, 0, 100) and pwm_disable(pwm) should be the same. And so my claim that pwm_disable is a part of the API that doesn't give any value stays true. > That's my entire point here. > If the device gets out of boot, nobody is actively driving the pin > either, so it has that 100k pull-up to make sure it is high by default, > which in turn causes the backlight to remain off. I'm saying that that > is exactly the state that the pin should be put back into when nobody is > using the PWM. > > So in other words I'm saying that that pin should be passively driven by > that 100k pull-up if it is not actively used by the PWM. > > What you are saying is that either we actively drive irrespective of > whether there are any users, or that we leave it undefined what we do > with a pin when it is no longer used. I think those are both wrong > because the former doesn't allow you to properly shut down the system > and the latter gives you undefined results, which is pretty useless > because it is completely non-deterministic. I think shut down doesn't matter because on shutdown the backlight driver doesn't release the pwm and so it continues to keep the intended level. > > If it was my decision, I'd say: If the backlight driver calls > > > > pwm_config(pwm, 0, 100); > > pwm_disable(pwm); > > > > I'd interpret that as: The consumer doesn't use the pin any more, so I'm > > not bound to keep the pin at a certain level. If however after > > pwm_disable the consumer is still considered to use the pin, then > > implementing it the same way as pwm_config(pwm, 0, 100) is the right > > thing to do. This applies then to all pwm implementations and so should > > be solved in the pwm core, not in the imx driver. In this case the > > concept of "disabling a PWM" can go away completely. > > But again, why should PWMs be special? You turn off all other resources > when you no longer need them, right? If you power your panel with a > regulator, then when the panel is disabled you want to disable the > regulator, right? Similarily if you don't use your I2C controller you > want to turn off the clock that drives it, right? This is the same for > any resource in your system: if you no longer need it, disable it. The > fact that "disabling" the PWM is not straightforward on i.MX doesn't > mean that we should simply ignore it. I don't say we should ignore it. I say we shouldn't disable the hardware if the consumer calls pwm_disable() if disabling the hardware results in a state that shouldn't happen on pwm_disable(). Also note, that there are two different "disable" you are talking about. One is disable in the sense of "pwm_disable". This is about the pwm to stop oscillating. And the other is about unsetting the enable bit in a control register and stopping the input clock. Even though both usually go hand in hand, if you still have requirements on the hardware state after pwm_disable that are not given if you disable the hardware it is stupid to require to disable the hardware and then implement something else on top to undo this unwanted result. > > In another mail you wrote: > > > Your example of keeping an LED in the current state is actually an > > > example of where the consumer still needs it. As long as you want to use > > > the LED you need to keep the LED driver around, and as long as the LED > > > driver is around you have a consumer for the PWM. > > > > With an analog reasoning I'd say: As long as the backlight driver cares > > about the backlight being off, it should not disable (or put) the PWM. > > It shouldn't put the PWM because it still needs it. But it should be > totally fine to disable it. Disabling a PWM should result in the PWM not > outputting any power. > > > > > Also note this is similar in the pwm-bcm-kona driver that doesn't seem > > > > to have the concept of "disable" at all. kona_pwmc_disable() just sets > > > > up 0% duty cycle. In my eyes this is an argument that is good enough to > > > > at least nack the imx-specific implementation of that pinctrl stuff. > > > > > > It's not a good enough argument for me. It's certainly possible that not > > > all PWM driver can be made to behave exactly as needed. pwm-bcm-kona > > > might be one of those, but that doesn't mean that everybody else should > > > be restricted to the same behaviour. If we can make i.MX behave exactly > > > right, then we should do that. > > > > And if we can make the imx-specific implementation right in a generic > > way in the pwm core that might help the bcm-kona driver for free. > > It may, but we don't know that. Look at the .disable callback of the bcm-kona driver. The way it is written together with the comments in it makes it obvious that this driver also actively drives the pin after disable. > Look, I'm not generally opposed to do this in the core, but I'm not > going to implement it in the core until I'm convinced that it is > useful in a large number of cases. One or two are not large numbers. Last time I suggested to implement this is in the core you said: "So I try not to attempt genericity until there are at least two or more use-cases that can be the basis for a generic solution." Now that I found a 2nd driver that can benefit you suddenly request "a large number of cases". I believe one reason for Linux being as good as it is today is, that usually with this kind of scenario things are done in the generic way even if there is only a single user up to now. And even if this solution doesn't 100% satisfies the needs for the next user, it is much easier for the next one to adapt and adopt generic code than to first cut it out from a hardware driver. And until the second user appears the separation helps to better understand the code because it is not bound to a hardware driver that a reviewer might not know. > > > > If the pinctrl idea is implemented in the pwm core, I won't object. > > > > > > Let me see if I get this straight: you're not objecting to the idea of > > > implementing the pinctrl solution, your only objection is to put it in > > > the i.MX driver? > > > > Given that the pinctrl solution is a generic solution that might help > > other drivers, too, I think it should not go into the imx specific > > driver just because for now this is the only driver that might benefit > > from it. > > > > I still don't think it's the best solution for the imx problem but as I > > care more for imx in general than for pwm in general I'm interested in > > keeping the imx driver focused to the imx specific parts. I won't repeat > > the advantages of putting generic stuff into a generic location instead > > of its first user. > > We can debate this for another few weeks, but I don't think you're going > to be able to convince me, so let's cut this short: pinctrl support goes > in the i.MX driver for now. Let's move on. OK, you're taking out your maintainer's club. That's sad because I'm convinced you're forcing a solution that is not optimal. I accept that the pinctrl stuff solves the problem, but I'm sure it's wrong to put it into a hardware driver. > > > > > > Also dts writes don't need to lookup the needed GPIO numbers and pinctrl. > > > > > > > > > > Just to clarify: I don't think that we need to get the GPIO number > > > > > involved in this case, because we don't have to reconfigure the pin as > > > > > GPIO to make this work. The only reason that Michal's proposal did that > > > > > is because that was believed to be necessary. But if the pin can just be > > > > > configured with a 100k pull-up, that's enough to pull the pin high when > > > > > we need it. > > > > > > > > Unless the gpio happens to be configured as output at the wrong value. > > > > Further I'm not sure if the pwm in disabled state actively pulls to 0 > > > > and if in this state the PU of the pin is good enough to ensure a one > > > > here. That would need verification first. > > > > > > The idea is to *not* configure the GPIO as output and output the wrong > > > value. The idea is to not use the GPIO at all and instead use whatever > > > the hardware default is that makes it such that the backlight is off by > > > default at boot. > > > > Which might be possible with Lothar's idea for some machines, but not > > for all users of the pwm-imx driver. > > > > Also note that you don't include the poor souls where there is no > > hardware pullup into the right direction. > > The poor souls should speak up and then we can look into finding a good > solution for them. I'm pretty sure there must be some equivalent that > can be used for other users. I think one of the boards that I'm working with has an enabled backlight at power on until the bootloader actively drives the related pwm to the right level (either using the pwm or the gpio function of the pin). I will double check that but assuming that is right, just disabling the output won't work here. Best regards Uwe -- Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | http://www.pengutronix.de/ |