Re: [RFC PATCH] drm/panel: Make backlight attachment lazy
From: Bjorn Andersson
Date: Tue Dec 08 2020 - 16:40:57 EST
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@xxxxxxxxxx>
> > ---
> > 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