mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Bjorn Andersson <bjorn.andersson@linaro.org>
To: Sam Ravnborg <sam@ravnborg.org>
Cc: Thierry Reding <thierry.reding@gmail.com>,
	Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	Maxime Ripard <mripard@kernel.org>,
	Thomas Zimmermann <tzimmermann@suse.de>,
	David Airlie <airlied@linux.ie>, Daniel Vetter <daniel@ffwll.ch>,
	dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH] drm/panel: Make backlight attachment lazy
Date: Tue, 8 Dec 2020 15:39:57 -0600	[thread overview]
Message-ID: <X8/yrXmEwuq6YZaD@builder.lan> (raw)
In-Reply-To: <20201208054855.GA18863@ravnborg.org>

On Mon 07 Dec 23:48 CST 2020, Sam Ravnborg wrote:

> Hi Bjorn,
> On Mon, Dec 07, 2020 at 10:44:46PM -0600, Bjorn Andersson wrote:
> > Some bridge chips, such as the TI SN65DSI86 DSI/eDP bridge, provides
> > means of generating a PWM signal for backlight control of the attached
> > panel. The provided PWM chip is typically controlled by the
> > pwm-backlight driver, which if tied to the panel will provide DPMS.
> > 
> > But with the current implementation the panel will refuse to probe
> > because the bridge driver has yet to probe and register the PWM chip,
> > and the bridge driver will refuse to probe because it's unable to find
> > the panel.
> > 
> > Mitigate this catch-22 situation by allowing the panel driver to probe
> > and retry the attachment of the backlight as the panel is turned on or
> > off.
> > 
> > Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
> > ---
> >  drivers/gpu/drm/drm_panel.c | 47 +++++++++++++++++++++++++++----------
> >  include/drm/drm_panel.h     |  8 +++++++
> >  2 files changed, 43 insertions(+), 12 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/drm_panel.c b/drivers/gpu/drm/drm_panel.c
> > index f634371c717a..7487329bd22d 100644
> > --- a/drivers/gpu/drm/drm_panel.c
> > +++ b/drivers/gpu/drm/drm_panel.c
> > @@ -43,6 +43,34 @@ static LIST_HEAD(panel_list);
> >   * take look at drm_panel_bridge_add() and devm_drm_panel_bridge_add().
> >   */
> >  
> > +#if IS_REACHABLE(CONFIG_BACKLIGHT_CLASS_DEVICE)
> > +static int drm_panel_of_backlight_lazy(struct drm_panel *panel)
> > +{
> > +	struct backlight_device *backlight;
> > +
> > +	if (!panel || !panel->dev)
> > +		return -EINVAL;
> > +
> > +	backlight = devm_of_find_backlight(panel->dev);
> > +
> > +	if (IS_ERR(backlight)) {
> > +		if (PTR_ERR(backlight) == -EPROBE_DEFER) {
> > +			panel->backlight_init_pending = true;
> > +			return 0;
> > +		}
> > +
> > +		return PTR_ERR(backlight);
> Use dev_err_probe()
> 

I need special handling of EPROBE_DEFER, both in terms of remembering
that we should retry and to not pass the error back to the panel driver.

I also don't want to introduce an error print here.

> > +	}
> > +
> > +	panel->backlight = backlight;
> > +	panel->backlight_init_pending = false;
> > +
> > +	return 0;
> > +}
> > +#else
> > +static int drm_panel_of_backlight_lazy(struct drm_panel *panel) { return 0; }
> > +#endif
> > +
> >  /**
> >   * drm_panel_init - initialize a panel
> >   * @panel: DRM panel
> > @@ -161,6 +189,9 @@ int drm_panel_enable(struct drm_panel *panel)
> >  			return ret;
> >  	}
> >  
> > +	if (panel->backlight_init_pending)
> > +		drm_panel_of_backlight_lazy(panel);
> > +
> >  	ret = backlight_enable(panel->backlight);
> >  	if (ret < 0)
> >  		DRM_DEV_INFO(panel->dev, "failed to enable backlight: %d\n",
> > @@ -187,6 +218,9 @@ int drm_panel_disable(struct drm_panel *panel)
> >  	if (!panel)
> >  		return -EINVAL;
> >  
> > +	if (panel->backlight_init_pending)
> > +		drm_panel_of_backlight_lazy(panel);
> > +
> >  	ret = backlight_disable(panel->backlight);
> >  	if (ret < 0)
> >  		DRM_DEV_INFO(panel->dev, "failed to disable backlight: %d\n",
> > @@ -328,18 +362,7 @@ EXPORT_SYMBOL(of_drm_get_panel_orientation);
> >   */
> >  int drm_panel_of_backlight(struct drm_panel *panel)
> >  {
> > -	struct backlight_device *backlight;
> > -
> > -	if (!panel || !panel->dev)
> > -		return -EINVAL;
> > -
> > -	backlight = devm_of_find_backlight(panel->dev);
> > -
> > -	if (IS_ERR(backlight))
> > -		return PTR_ERR(backlight);
> > -
> > -	panel->backlight = backlight;
> > -	return 0;
> > +	return drm_panel_of_backlight_lazy(panel);
> Could you update the drm_panel_of_backlight() implementation (and
> do not forget the documentation) and avoid drm_panel_of_backlight_lazy()?
> 

That sounds reasonable, there's not really a reason for introducing a
new function for what I'm doing.

> 
> >  }
> >  EXPORT_SYMBOL(drm_panel_of_backlight);
> >  #endif
> > diff --git a/include/drm/drm_panel.h b/include/drm/drm_panel.h
> > index 33605c3f0eba..b126abebb2f3 100644
> > --- a/include/drm/drm_panel.h
> > +++ b/include/drm/drm_panel.h
> > @@ -149,6 +149,14 @@ struct drm_panel {
> >  	 */
> >  	struct backlight_device *backlight;
> >  
> > +	/**
> > +	 * @backlight_init_pending
> > +	 *
> > +	 * Backlight driver is not yet available so further attempts to
> > +	 * initialize @backlight is necessary.
> > +	 */
> > +	bool backlight_init_pending;
> > +
> 
> We have not done so today for other fields, but it would be good
> to document this is for drm_panel use only and drivers shall not touch.
> 

Of course.

Thanks,
Bjorn

  reply	other threads:[~2020-12-08 21:40 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-08  4:44 Bjorn Andersson
2020-12-08  5:48 ` Sam Ravnborg
2020-12-08 21:39   ` Bjorn Andersson [this message]
2020-12-08 12:47 ` Thierry Reding
2020-12-08 22:02   ` Bjorn Andersson
2020-12-08 23:52     ` Daniel Vetter
2020-12-09 20:28       ` Bjorn Andersson
2020-12-10 10:15         ` Daniel Vetter
2020-12-10 16:44           ` Thierry Reding
2020-12-10 16:50             ` Daniel Vetter
2020-12-10 17:18               ` Thierry Reding

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=X8/yrXmEwuq6YZaD@builder.lan \
    --to=bjorn.andersson@linaro.org \
    --cc=airlied@linux.ie \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=sam@ravnborg.org \
    --cc=thierry.reding@gmail.com \
    --cc=tzimmermann@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome