Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp29405329rwd; Wed, 5 Jul 2023 11:18:41 -0700 (PDT) X-Google-Smtp-Source: APBJJlFc5DDLgKzS7xPrsGaG/BeyLkQNf0ieR4aOSdd3w/dzwJkuWs+4gnTE+xoKnpi1Fzx39Fcl X-Received: by 2002:a17:902:f7c9:b0:1b8:b288:626e with SMTP id h9-20020a170902f7c900b001b8b288626emr1945541plw.35.1688581121506; Wed, 05 Jul 2023 11:18:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688581121; cv=none; d=google.com; s=arc-20160816; b=SVoI6DQ0mZCcDwzVolstgFUmxevop6g6nxHy/s5O7lyDMkrxlMixssJoGrkL0E5hAu pZFK/yo86ZGsN0oX79MMRE+UQas51Fmz3rfeG5cywiw2RjeDA68J2rHbRKAoqrKxh/CX aWjPu4UrBssEpt2lESxujbGGPa96ayBvCDRB876yJ7L8xz1pTf3TGEcBy8UhOloe9nLy vlzyioK0rjIxE8Y3T+0yFIX6EVwlSXm12BYJ3xRkO2nVoAVff7TQPFdryAYE8+KbobvV Ay1HmKVhe4q9jtYlgT5xwe/GPiVM3OTG23bDP0Kr8dmGTVc6QHoXwrLb72JeEuHLuUJP rtrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature :dkim-signature; bh=iBBtnRklVqMQ6mkde8T1v6wMY0Ar5kLbR8KuMGyUvyw=; fh=Rk2flDvpYeWJZ8+8FzO306AAd3840bn2mKp6FaZtg0o=; b=IacFrqyta7nnefkHDaoJbXHRTS5/vHLqamb0q0YTnswvH3GlitbaHiNa0oSoSnRaoK xXHFM0GEcmUSqu7pCqRq+9bM2iNc/LXKTYnOZXVM3SiyIBnHgBH8xVDM78Qe3/RhyYt2 3Y8cODaE+/aMCvQMgjLsnEqUf4qGy0BFYRiCdAnomaBn9kqNKkQnj5nLNKqUZ/7jBYPp 83O9m5pcOkH8fafBui0VlDSy6vI5Muy94iYblxSGcONHiz8kITVJHroM1Hdl5NCI9LC7 MEwE9uia/owIiJT0pN2B/pCUSDPTIIPdy1E0ttOWW3/GNpKmyCgXlIozjUo+6RbDSPxv AMKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ravnborg.org header.s=rsa1 header.b=GF90gPCv; dkim=neutral (no key) header.i=@ravnborg.org; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m1-20020a170902db0100b001b88e609e56si9411120plx.488.2023.07.05.11.18.28; Wed, 05 Jul 2023 11:18:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ravnborg.org header.s=rsa1 header.b=GF90gPCv; dkim=neutral (no key) header.i=@ravnborg.org; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232770AbjGER4o (ORCPT + 99 others); Wed, 5 Jul 2023 13:56:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232371AbjGER4m (ORCPT ); Wed, 5 Jul 2023 13:56:42 -0400 Received: from mailrelay2-1.pub.mailoutpod2-cph3.one.com (mailrelay2-1.pub.mailoutpod2-cph3.one.com [IPv6:2a02:2350:5:401::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DDB76199E for ; Wed, 5 Jul 2023 10:56:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ravnborg.org; s=rsa1; h=in-reply-to:content-type:mime-version:references:message-id:subject:cc:to: from:date:from; bh=iBBtnRklVqMQ6mkde8T1v6wMY0Ar5kLbR8KuMGyUvyw=; b=GF90gPCvd8mEOngfUgQ59M+s5yRlPK7b2PnKpmpMnIjBFMszO4/vVi8TdAIN+T4XXNDIBa1cEljQA OaSgSWv9V4iO8aiBOkixFILrXIigudR1NAANlPev2komLg+lvFqYkKOVyw7dU7ciKRpuqOHuixtnCW azZqlkQw7SLDnFd7RdJeupMSRKwpLduu1VjDes2+Uu4ZiuWiF5OVKEMq/tcdLBTBfw+JfSicHqDQRF IYTpvxpmZ4rv107iezXfjqLdQ70qXOdVeeOroTWIh77DcdHy3MseQ9mAmn9v98uk2Ze+Mtd90bG0HJ Rb3zZy+8jWl2H1z2nLf+tQcWtCzHKvg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ravnborg.org; s=ed1; h=in-reply-to:content-type:mime-version:references:message-id:subject:cc:to: from:date:from; bh=iBBtnRklVqMQ6mkde8T1v6wMY0Ar5kLbR8KuMGyUvyw=; b=/U4cLTc4mm2o+4LrKjw/bJrmBsg6NMPgQJ9mg4yrxISURD04T/fLHemun271zeTYH/jq/QmT2Kf1V /gOZs4QCA== X-HalOne-ID: 4359365c-1b5d-11ee-87e5-5ba399456a4a Received: from ravnborg.org (2-105-2-98-cable.dk.customer.tdc.net [2.105.2.98]) by mailrelay2 (Halon) with ESMTPSA id 4359365c-1b5d-11ee-87e5-5ba399456a4a; Wed, 05 Jul 2023 17:56:28 +0000 (UTC) Date: Wed, 5 Jul 2023 19:56:27 +0200 From: Sam Ravnborg To: Daniel Thompson Cc: Mans Rullgard , linux-fbdev@vger.kernel.org, Jingoo Han , Helge Deller , Lee Jones , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Tomi Valkeinen Subject: Re: [PATCH] backlight: led_bl: fix initial power state Message-ID: <20230705175627.GD106478@ravnborg.org> References: <20230704140750.25799-1-mans@mansr.com> <20230704150310.GA385243@aspen.lan> <20230704170731.GB940443@ravnborg.org> <20230705140731.GB6265@aspen.lan> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230705140731.GB6265@aspen.lan> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_PASS,SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Daniel, On Wed, Jul 05, 2023 at 03:07:31PM +0100, Daniel Thompson wrote: > On Tue, Jul 04, 2023 at 07:07:31PM +0200, Sam Ravnborg wrote: > > Hi Daniel, > > > > > > @@ -200,8 +200,8 @@ static int led_bl_probe(struct platform_device *pdev) > > > > props.type = BACKLIGHT_RAW; > > > > props.max_brightness = priv->max_brightness; > > > > props.brightness = priv->default_brightness; > > > > - props.power = (priv->default_brightness > 0) ? FB_BLANK_POWERDOWN : > > > > - FB_BLANK_UNBLANK; > > > > + props.power = (priv->default_brightness > 0) ? FB_BLANK_UNBLANK : > > > > + FB_BLANK_POWERDOWN; > > > > > > The logic was wrong before but I think will still be wrong after the > > > change too (e.g. the bogus logic is probably avoiding backlight flicker > > > in some use cases). > > > > > > The logic here needs to be similar to what pwm_bl.c implements in > > > pwm_backlight_initial_power_state(). Whilst it might be better > > > to implement this in led_bl_get_leds() let me show what I mean > > > in code that fits in the current line: > > > > > > /* > > > * Activate the backlight if the LEDs are already lit *or* > > > * there is no phandle link (meaning the backlight power > > > * state cannot be synced with the display state). > > > */ > > > props.power = (active_at_boot || !dev->node->phandle) ? > > > FB_BLANK_UNBLANK : FB_BLANK_POWERDOWN; > > > > > The following code does the same using helpers: > > > > if (active_at_boot || !dev->node->phandle)) > > backlight_enable(bd); > > else > > backlight_disable(bd); > > > > The code needs to execute after backlight_device_register() so maybe not > > so great an idea?!? > > It would introduce a need for a bunch of new locks since userspace > could get in between device creation and the call to the helpers. I thought we were safe while in the probe function, but I have been fooled by the driver model before. > > Additionally, it is even correct for a driver to forcefully set > fb_blank to powerdown during the probe? All current drivers set > fb_blank to unblank during the probe. fb_blank is more or less unused. I thought that Lee applied the patch set to eliminate most users, but I see that this is not the case. I need to resend one day. Some (at least one) drivers update .power after registering the device, so if this is racy then these drivers could use some care. Anyway, looking at how many drivers access backlight_properties direct is is futile to try to avoid it. So the approach you suggest seems the best way to do it. Sam