Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp3355946ybd; Tue, 25 Jun 2019 00:53:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqx/oAjZXM6FNAK7+I5lS2nvJBzVEInwbFMBvlfHevgkkZ371RLVoIDxVokgG3V2Hf8APYbo X-Received: by 2002:a63:2310:: with SMTP id j16mr13672939pgj.238.1561449218943; Tue, 25 Jun 2019 00:53:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561449218; cv=none; d=google.com; s=arc-20160816; b=txzw9kfFkYC81K+4DIV0m1eAKup/nnjPylIvZqzTI2QUyYOXSjZCekaq93rppsXM+5 +3DQ37ivZZLxBP2CmJTKL/8QTGRE0kqKs690rwauL1dr44ZiIGtGeSSzR8QHyXJdWrVy Nwh5bMlTiCNwPMXg9KJXUV/3ZZFmpnyxVE6QN5uTJA9FnV7TJx4HHZQauQ6Er4KI43Dh cKcgIdC18jo2ApWlI+kqjNzZM7FFZ0LYsEtyoxaEZ7EBpOmSVCcQTDqaYTxICNvnUmcs eOefEzVygeZewQ5J/2QzjxmIkZsbDh1C0HRGxN/mz71SaYOjBn8t8VAI17DImNBHrGwY k7LQ== 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=zSUIbA/Bu2sxn0TqodjvLeSULVAGh49gNW9KbBql2ag=; b=shrnGnqkqplkaWcJdMxtHOLrWE2eoo2HWYRicfOgtOD6e87LXXn0TEUig8II4FUiWS OUom2Cm7UGZnqpahWKH5f36cz+B62sxfb09FL7jyp/97bv7C4j9GnI3sq9Gdyw62ElSg Ss4vVCiPX+YvOfHtWYa5E9z0gVp+ac5JZI6e5fdOl3ucLBomX1ysMpkP1Lvd3gbFKOhH RQFiElVoJtiDWg2AUoGXGN2lzhnl14k4mnqRieC0Ac5CoaGuyr3+egYEg0ALEm3m0GEa 9Z9rhJ3x4kc/LJQ5TmzKeS3952iEScDn0NZkTMTGCx53dx9gw+O4Sg2DuitBsdluRzrV nSjg== 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 v10si13468936plg.320.2019.06.25.00.53.23; Tue, 25 Jun 2019 00:53:38 -0700 (PDT) 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 S1728983AbfFYHmg (ORCPT + 99 others); Tue, 25 Jun 2019 03:42:36 -0400 Received: from metis.ext.pengutronix.de ([85.220.165.71]:40349 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728771AbfFYHmf (ORCPT ); Tue, 25 Jun 2019 03:42:35 -0400 Received: from pty.hi.pengutronix.de ([2001:67c:670:100:1d::c5]) by metis.ext.pengutronix.de with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1hfg5v-0004yl-BO; Tue, 25 Jun 2019 09:42:23 +0200 Received: from ukl by pty.hi.pengutronix.de with local (Exim 4.89) (envelope-from ) id 1hfg5s-0005kx-EO; Tue, 25 Jun 2019 09:42:20 +0200 Date: Tue, 25 Jun 2019 09:42:20 +0200 From: Uwe =?iso-8859-1?Q?Kleine-K=F6nig?= To: Paul Cercueil Cc: Thierry Reding , Lee Jones , Daniel Thompson , Jingoo Han , Bartlomiej Zolnierkiewicz , od@zcrc.me, linux-pwm@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@pengutronix.de Subject: Re: [PATCH] backlight: pwm_bl: Set pin to sleep state when powered down Message-ID: <20190625074220.ckj7e7gwbszwknaa@pengutronix.de> References: <20190522163428.7078-1-paul@crapouillou.net> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20190522163428.7078-1-paul@crapouillou.net> User-Agent: NeoMutt/20170113 (1.7.2) X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::c5 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, May 22, 2019 at 06:34:28PM +0200, Paul Cercueil wrote: > When the driver probes, the PWM pin is automatically configured to its > default state, which should be the "pwm" function. However, at this > point we don't know the actual level of the pin, which may be active or > inactive. As a result, if the driver probes without enabling the > backlight, the PWM pin might be active, and the backlight would be > lit way before being officially enabled. I'm not sure I understand the problem completely here. Let me try to summarize the problem you solve here: The backlight device's default pinctrl contains the PWM function of the PWM pin. As the PWM is (or at least might be) in an undefined state the default pinctrl should only be switched to when it's clear if the backlight should be on or off. So you use the "init"-pinctrl to keep the PWM pin in some (undriven?) state and by switching to "sleep" you prevent "default" getting active. Did I get this right? If not, please correct me. What is the PWM pin configured to in "init" in your case? Is the pinctrl just empty? Or is it a gpio-mode (together with a gpio-hog)? My thoughts to this is are: a) This is a general problem that applies (I think) to most if not all PWM consumers. If the PWM drives a motor, or makes your mobile vibrate, or drives an LED, or a clk, the PWM shouldn't start to do something before its consumer is ready. b) Thierry made it quite clear[1] that the PWM pin should be configured in a pinctrl of the pwm device, not the backlight (or more general: the consumer) device. While I don't entirely agree with b) I think that even a) alone justifies to think a bit more about the problem and preferably come up with a solution that helps other consumers, too. Ideally if the bootloader sets up the PWM to do something sensible, probing the lowlevel PWM driver and the consumer driver should not interfere with the bootloader's intention until the situation reaches a controlled state. (I.e. if the backlight was left on by the bootloader to show a nice logo, it should not flicker until a userspace program takes over the display device.) A PWM is special in contrast to other devices as its intended behaviour is only fixed once a consumer is present. Without a consumer it is unknown if the PWM is inverted or not. And so the common approach that pinctrl is setup by the device core only doesn't work without drawbacks for PWMs. So if a PWM driver is probing and the PWM hardware already runs at say constant one, some instance must define if the pin is supposed to be configured in its "default" or "sleep" pinctrl. IMHO this isn't possible in general without knowing the polarity of the PWM. (And even if it were known that the polarity is inversed, it might be hard to say if your PWM's hardware doesn't implement a disabled state and has to simulate that using a 0% duty cycle.) Another thing that complicates the matter is that at least pwm-imx27 has the annoying property that disabling it (in hardware) drives the pin low irrespective of the configured polarity. So if you want this type of device to behave properly on disable, it must first drive a 0% duty cycle, then switch the pinctrl state and only then disable the hardware. This rules out that the lowlevel driver is unaware of the pinctrl stuff which would be nice (or an inverted PWM won't be disabled in hardware or you need an ugly sequence of callbacks to disable glitch-free). Also if there is no sleep state, you better don't disable an inversed pwm-imx27 at all (in hardware)? (Alternatively we could drop the (undocumented) guarantee that a disabled PWM results in the pin staying in its idle level.) What are the ways out? I think that if we go and apply your patch, we should at least write some documentation with the details to provide some "standard" way to solve similar problems. Also it might be a good idea to let a PWM know if it is inverted or not such that even without the presence of a consumer it can determine if the hardware is active or not at probe time (in most cases at least). Best regards Uwe [1] https://www.spinics.net/lists/linux-pwm/msg08246.html -- Pengutronix e.K. | Uwe Kleine-K?nig | Industrial Linux Solutions | http://www.pengutronix.de/ |