drm/panel: Make backlight attachment lazy
Subsystems (3)
RFC PATCH 1/1 drm/panel: Make backlight attachment lazy
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.
--- drivers/gpu/drm/drm_panel.c | 47 +++++++++++++++++++++++++++---------- include/drm/drm_panel.h | 8 +++++++ 2 files changed, 43 insertions(+), 12 deletions(-)
drivers/gpu/drm/drm_panel.c +35 -12
@@ -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); + } + + 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); }EXPORT_SYMBOL (drm_panel_of_backlight);#endif
include/drm/drm_panel.h +8 -0
@@ -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; +/** * @funcs: *
Signature · 1 line
2.29.2
Hi Bjorn,
Quoted 35 lines · Bjorn Andersson
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 <[email protected]>--- drivers/gpu/drm/drm_panel.c | 47 +++++++++++++++++++++++++++---------- include/drm/drm_panel.h | 8 +++++++ 2 files changed, 43 insertions(+), 12 deletions(-)drivers/gpu/drm/drm_panel.c +7
-0@@ -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 ;
drivers/gpu/drm/drm_panel.c static LIST_HEAD(panel_list); · line 62
Quoted 10 lines
drivers/gpu/drm/drm_panel.c +10
-0+ + 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()
Quoted 41 lines
drivers/gpu/drm/drm_panel.c +17
-3+ } + + 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)
drivers/gpu/drm/drm_panel.c EXPORT_SYMBOL(of_drm_get_panel_orientation); · line 365
Quoted 10 lines
drivers/gpu/drm/drm_panel.c +1
-9-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()?
Sam
Quoted 9 lines
drivers/gpu/drm/drm_panel.c +0
-0}EXPORT_SYMBOL (drm_panel_of_backlight);#endif include/drm/drm_panel.h +0
-0@@ -149,6 +149,14 @@ struct drm_panel {*/
include/drm/drm_panel.h struct drm_panel { · line 159
Quoted 10 lines
include/drm/drm_panel.h +8
-0struct 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.
Sam
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 40 lines · Sam Ravnborg
Hi Bjorn,
Quoted 38 lines · Bjorn Andersson
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 <[email protected]>--- drivers/gpu/drm/drm_panel.c | 47 +++++++++++++++++++++++++++---------- include/drm/drm_panel.h | 8 +++++++ 2 files changed, 43 insertions(+), 12 deletions(-)drivers/gpu/drm/drm_panel.c +10
-0@@ -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); +
Quoted 9 lines
drivers/gpu/drm/drm_panel.c static LIST_HEAD(panel_list); · line 62
Quoted 7 lines
drivers/gpu/drm/drm_panel.c +7
-0+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.
Quoted 45 lines
Quoted 45 lines
drivers/gpu/drm/drm_panel.c +17
-7+ } + + 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); -
Quoted 9 lines
drivers/gpu/drm/drm_panel.c EXPORT_SYMBOL(of_drm_get_panel_orientation); · line 365
Quoted 6 lines
drivers/gpu/drm/drm_panel.c +1
-5-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 avoiddrm_panel_of_backlight_lazy()?
That sounds reasonable, there's not really a reason for introducing a new function for what I'm doing.
Quoted 12 lines
Quoted 12 lines
drivers/gpu/drm/drm_panel.c +0
-0}EXPORT_SYMBOL (drm_panel_of_backlight);#endif include/drm/drm_panel.h +0
-0@@ -149,6 +149,14 @@ struct drm_panel {*/ struct backlight_device *backlight;
Quoted 12 lines
include/drm/drm_panel.h struct drm_panel { · line 159
Quoted 8 lines
include/drm/drm_panel.h +8
-0+/** +* @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_paneluse only and drivers shall not touch.
Of course.
Thanks,
Bjorn
Quoted 9 lines · Bjorn Andersson
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.
What you're describing is basically a circular dependency. Can't we get rid of that in some other way? Why exactly does the bridge driver refuse to probe if the panel can't be found?
In other words, I see how the bridge would /use/ the panel in that it forward a video stream to it. But how does the panel /use/ the bridge?
Thierry
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 11 lines · Thierry Reding
Quoted 9 lines · Bjorn Andersson
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.
Quoted 7 lines
What you're describing is basically a circular dependency. Can't we get rid of that in some other way? Why exactly does the bridge driver refuse to probe if the panel can't be found?
In other words, I see how the bridge would /use/ the panel in that it forward a video stream to it. But how does the panel /use/ the bridge?
Yes, this is indeed a circular dependency between the components.
The involved parts are:
* the bridge driver that implements the PWM chip probe defers on drm_of_find_panel_or_bridge() failing to find the panel.
* the pwm-backlight driver that consumes the PWM channel probe defer because the pwm_chip was not registered by the bridge.
* the panel that uses the backlight for DPMS purposes probe defer because drm_panel_of_backlight() fails to find the pwm-backlight.
I looked at means of postponing drm_of_find_panel_or_bridge() to drm_bridge_funcs->attach(), but at that time "deferral" would be fatal. I looked at registering the pwm_chip earlier, but that would depend on a guarantee of the pwm-backlight and panel driver to probe concurrently. And the current solution of not tying the backlight to the panel means that when userspace decides to DPMS the display the backlight stays on.
The proposed solution (hack?) means that DPMS operations happening before the pwm-backlight has probed will be missed, so it's not perfect. It does however allow the backlight on my laptop to turn off, which is a big improvement.
But I'm certainly welcome to suggestions.
Regards,
Bjorn
Quoted 39 lines · Bjorn Andersson
Quoted 11 lines · Thierry Reding
Quoted 9 lines · Bjorn Andersson
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.
Quoted 7 lines
What you're describing is basically a circular dependency. Can't we get rid of that in some other way? Why exactly does the bridge driver refuse to probe if the panel can't be found?
In other words, I see how the bridge would /use/ the panel in that it forward a video stream to it. But how does the panel /use/ the bridge?
Yes, this is indeed a circular dependency between the components.
The involved parts are:
* the bridge driver that implements the PWM chip probe defers ondrm_of_find_panel_or_bridge()failing to find the panel.
* the pwm-backlight driver that consumes the PWM channel probe defer because thepwm_chipwas not registered by the bridge.
* the panel that uses the backlight for DPMS purposes probe defer becausedrm_panel_of_backlight()fails to find the pwm-backlight.I looked at means of postponing
drm_of_find_panel_or_bridge()todrm_bridge_funcs->attach(), but at that time "deferral" would be fatal. I looked at registering thepwm_chipearlier, but that would depend on a guarantee of the pwm-backlight and panel driver to probe concurrently. And the current solution of not tying the backlight to the panel means that when userspace decides to DPMS the display the backlight stays on.
Quoted 6 lines
The proposed solution (hack?) means that DPMS operations happening before the pwm-backlight has probed will be missed, so it's not perfect. It does however allow the backlight on my laptop to turn off, which is a big improvement.
But I'm certainly welcome to suggestions.
Entirely hand-waving, why doesn't the following work:
1. driver for the platform device which is the bridge loads
2. that platform driver registers the pwm
3. it registers some magic for later on (more below)
4. panel driver has deferred loading until step 2 happened
5. panel driver registers drm_panel
6. the magic from step 3 picks up (after having been deferred for a few times probably) grabs the panel, and sets up the actual drm_bridge driver
Everyone happy, or not? From the description it looks like the problem that the pwm that we need for the backlight is tied to the same driver as the drm_bridge, and always torn down too if the drm_bridge setup fails somehow for a reason. And that reason is the circular dependency this creates.
Now for the magic in step 3, there's options:
- change DT to split out that pwm as a separate platform_device, that way bridge and panel can load indepedently (hopefully)
- convert bridge to a multi-function device (mfd), essentially a way to instantiate more devices with their drivers at runtime. Then the actual pwm and drm_bridge parts of your bridge driver bind against those sub-functions, and can defer indepedently
- we could create a callback/wait function for "pls wait for any panel to show up". Then your bridge driver could launch a work_struct with that wait function, which will do the bridge setup once the panel has shown up. The pwm will be registered right away. It's essentially hand-rolling EPROBE_DEFERRED for work_struct in drm/panel. Maybe we might even have that exported from the driver core, e.g.
register_bridge_fn(struct work *)
{
do_wait_probe_defer();
panel = drm_of_find_panel_or_bridge();
if (!panel) {
schedule_work(); /* want to restart the work so it can be stopped on driver unload */
return;
}
/* we have the panel now, register drm_bridge */
}- cobble something together with component.c, but that's more for collecting unrelated struct device into a logical one than splitting it up more.
tldr; I think you can split this loop here at the bridge by untangling the pwm from the drm_bridge part sufficiently.
-Daniel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 63 lines · Daniel Vetter
Quoted 39 lines · Bjorn Andersson
Quoted 11 lines · Thierry Reding
Quoted 9 lines · Bjorn Andersson
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.
Quoted 7 lines
What you're describing is basically a circular dependency. Can't we get rid of that in some other way? Why exactly does the bridge driver refuse to probe if the panel can't be found?
In other words, I see how the bridge would /use/ the panel in that it forward a video stream to it. But how does the panel /use/ the bridge?
Yes, this is indeed a circular dependency between the components.
The involved parts are:
* the bridge driver that implements the PWM chip probe defers ondrm_of_find_panel_or_bridge()failing to find the panel.
* the pwm-backlight driver that consumes the PWM channel probe defer because thepwm_chipwas not registered by the bridge.
* the panel that uses the backlight for DPMS purposes probe defer becausedrm_panel_of_backlight()fails to find the pwm-backlight.I looked at means of postponing
drm_of_find_panel_or_bridge()todrm_bridge_funcs->attach(), but at that time "deferral" would be fatal. I looked at registering thepwm_chipearlier, but that would depend on a guarantee of the pwm-backlight and panel driver to probe concurrently. And the current solution of not tying the backlight to the panel means that when userspace decides to DPMS the display the backlight stays on.Quoted 6 lines
The proposed solution (hack?) means that DPMS operations happening before the pwm-backlight has probed will be missed, so it's not perfect. It does however allow the backlight on my laptop to turn off, which is a big improvement.
But I'm certainly welcome to suggestions.
Entirely hand-waving, why doesn't the following work:
1. driver for the platform device which is the bridge loads
2. that platform driver registers the pwm
3. it registers some magic for later on (more below)
4. panel driver has deferred loading until step 2 happened
5. panel driver registersdrm_panel
6. the magic from step 3 picks up (after having been deferred for a few times probably) grabs the panel, and sets up the actualdrm_bridgedriverEveryone happy, or not? From the description it looks like the problem that the pwm that we need for the backlight is tied to the same driver as the
drm_bridge, and always torn down too if thedrm_bridgesetup fails somehow for a reason. And that reason is the circular dependency this creates.
Quoted 4 lines
Now for the magic in step 3, there's options:
- change DT to split out that pwm as a separateplatform_device, that way bridge and panel can load indepedently (hopefully)
This is an i2c device, so describing it multiple times would mean we have multiple devices with the same address...
Quoted 5 lines
- convert bridge to a multi-function device (mfd), essentially a way to instantiate more devices with their drivers at runtime. Then the actual pwm and
drm_bridgeparts of your bridge driver bind against those sub-functions, and can defer indepedently
But, this sounds reasonable and would rely on the existing probe deferral logic and if there's ever any improvements in this area we would directly benefit from it.
Quoted 19 lines
- we could create a callback/wait function for "pls wait for any panel to show up". Then your bridge driver could launch a
work_structwith that wait function, which will do the bridge setup once the panel has shown up. The pwm will be registered right away. It's essentially hand-rollingEPROBE_DEFERREDforwork_structin drm/panel. Maybe we might even have that exported from the driver core, e.g.
register_bridge_fn(struct work *){ do_wait_probe_defer(); panel = drm_of_find_panel_or_bridge(); if (!panel) { schedule_work(); /* want to restart the work so it can be stopped on driver unload */ return; } /* we have the panel now, register drm_bridge */ }
Quoted 6 lines
- cobble something together with
component.c, but that's more for collecting unrelated struct device into a logical one than splitting it up more.tldr; I think you can split this loop here at the bridge by untangling the pwm from the
drm_bridgepart sufficiently.
Yes, it seems like a reasonable path forward. But I wanted some input before refactoring the whole thing.
Thank you,
Bjorn
Quoted 106 lines · Bjorn Andersson
Quoted 63 lines · Daniel Vetter
Quoted 39 lines · Bjorn Andersson
Quoted 11 lines · Thierry Reding
Quoted 9 lines · Bjorn Andersson
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.
Quoted 7 lines
What you're describing is basically a circular dependency. Can't we get rid of that in some other way? Why exactly does the bridge driver refuse to probe if the panel can't be found?
In other words, I see how the bridge would /use/ the panel in that it forward a video stream to it. But how does the panel /use/ the bridge?
Yes, this is indeed a circular dependency between the components.
The involved parts are:
* the bridge driver that implements the PWM chip probe defers ondrm_of_find_panel_or_bridge()failing to find the panel.
* the pwm-backlight driver that consumes the PWM channel probe defer because thepwm_chipwas not registered by the bridge.
* the panel that uses the backlight for DPMS purposes probe defer becausedrm_panel_of_backlight()fails to find the pwm-backlight.I looked at means of postponing
drm_of_find_panel_or_bridge()todrm_bridge_funcs->attach(), but at that time "deferral" would be fatal. I looked at registering thepwm_chipearlier, but that would depend on a guarantee of the pwm-backlight and panel driver to probe concurrently. And the current solution of not tying the backlight to the panel means that when userspace decides to DPMS the display the backlight stays on.Quoted 6 lines
The proposed solution (hack?) means that DPMS operations happening before the pwm-backlight has probed will be missed, so it's not perfect. It does however allow the backlight on my laptop to turn off, which is a big improvement.
But I'm certainly welcome to suggestions.
Entirely hand-waving, why doesn't the following work:
1. driver for the platform device which is the bridge loads
2. that platform driver registers the pwm
3. it registers some magic for later on (more below)
4. panel driver has deferred loading until step 2 happened
5. panel driver registersdrm_panel
6. the magic from step 3 picks up (after having been deferred for a few times probably) grabs the panel, and sets up the actualdrm_bridgedriverEveryone happy, or not? From the description it looks like the problem that the pwm that we need for the backlight is tied to the same driver as the
drm_bridge, and always torn down too if thedrm_bridgesetup fails somehow for a reason. And that reason is the circular dependency this creates.Quoted 4 lines
Now for the magic in step 3, there's options:
- change DT to split out that pwm as a separateplatform_device, that way bridge and panel can load indepedently (hopefully)This is an i2c device, so describing it multiple times would mean we have multiple devices with the same address...
Quoted 5 lines
- convert bridge to a multi-function device (mfd), essentially a way to instantiate more devices with their drivers at runtime. Then the actual pwm and
drm_bridgeparts of your bridge driver bind against those sub-functions, and can defer indepedentlyBut, this sounds reasonable and would rely on the existing probe deferral logic and if there's ever any improvements in this area we would directly benefit from it.
Quoted 23 lines
- we could create a callback/wait function for "pls wait for any panel to show up". Then your bridge driver could launch a
work_structwith that wait function, which will do the bridge setup once the panel has shown up. The pwm will be registered right away. It's essentially hand-rollingEPROBE_DEFERREDforwork_structin drm/panel. Maybe we might even have that exported from the driver core, e.g.
register_bridge_fn(struct work *){ do_wait_probe_defer(); panel = drm_of_find_panel_or_bridge(); if (!panel) { schedule_work(); /* want to restart the work so it can be stopped on driver unload */ return; } /* we have the panel now, register drm_bridge */ }- cobble something together with
component.c, but that's more for collecting unrelated struct device into a logical one than splitting it up more.
Quoted 5 lines
Quoted 2 lines
tldr; I think you can split this loop here at the bridge by untangling the pwm from the
drm_bridgepart sufficiently.Yes, it seems like a reasonable path forward. But I wanted some input before refactoring the whole thing.
Yeah it's unfortunately a bit of work. But I think it's the proper approach since EPROBE_DEFERRED is fundamentally linked to struct device and bound drivers. So we do need a struct device for every part in our dependency graph to make sure we can resolve the dependencies all correctly with reprobing.
-Daniel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 110 lines · Daniel Vetter
Quoted 109 lines · Bjorn Andersson
Quoted 63 lines · Daniel Vetter
Quoted 39 lines · Bjorn Andersson
Quoted 11 lines · Thierry Reding
Quoted 9 lines · Bjorn Andersson
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.
Quoted 7 lines
What you're describing is basically a circular dependency. Can't we get rid of that in some other way? Why exactly does the bridge driver refuse to probe if the panel can't be found?
In other words, I see how the bridge would /use/ the panel in that it forward a video stream to it. But how does the panel /use/ the bridge?
Yes, this is indeed a circular dependency between the components.
The involved parts are:
* the bridge driver that implements the PWM chip probe defers ondrm_of_find_panel_or_bridge()failing to find the panel.
* the pwm-backlight driver that consumes the PWM channel probe defer because thepwm_chipwas not registered by the bridge.
* the panel that uses the backlight for DPMS purposes probe defer becausedrm_panel_of_backlight()fails to find the pwm-backlight.I looked at means of postponing
drm_of_find_panel_or_bridge()todrm_bridge_funcs->attach(), but at that time "deferral" would be fatal. I looked at registering thepwm_chipearlier, but that would depend on a guarantee of the pwm-backlight and panel driver to probe concurrently. And the current solution of not tying the backlight to the panel means that when userspace decides to DPMS the display the backlight stays on.Quoted 6 lines
The proposed solution (hack?) means that DPMS operations happening before the pwm-backlight has probed will be missed, so it's not perfect. It does however allow the backlight on my laptop to turn off, which is a big improvement.
But I'm certainly welcome to suggestions.
Entirely hand-waving, why doesn't the following work:
1. driver for the platform device which is the bridge loads
2. that platform driver registers the pwm
3. it registers some magic for later on (more below)
4. panel driver has deferred loading until step 2 happened
5. panel driver registersdrm_panel
6. the magic from step 3 picks up (after having been deferred for a few times probably) grabs the panel, and sets up the actualdrm_bridgedriverEveryone happy, or not? From the description it looks like the problem that the pwm that we need for the backlight is tied to the same driver as the
drm_bridge, and always torn down too if thedrm_bridgesetup fails somehow for a reason. And that reason is the circular dependency this creates.Quoted 4 lines
Now for the magic in step 3, there's options:
- change DT to split out that pwm as a separateplatform_device, that way bridge and panel can load indepedently (hopefully)This is an i2c device, so describing it multiple times would mean we have multiple devices with the same address...
Quoted 5 lines
- convert bridge to a multi-function device (mfd), essentially a way to instantiate more devices with their drivers at runtime. Then the actual pwm and
drm_bridgeparts of your bridge driver bind against those sub-functions, and can defer indepedentlyBut, this sounds reasonable and would rely on the existing probe deferral logic and if there's ever any improvements in this area we would directly benefit from it.
Quoted 25 lines
- we could create a callback/wait function for "pls wait for any panel to show up". Then your bridge driver could launch a
work_structwith that wait function, which will do the bridge setup once the panel has shown up. The pwm will be registered right away. It's essentially hand-rollingEPROBE_DEFERREDforwork_structin drm/panel. Maybe we might even have that exported from the driver core, e.g.
register_bridge_fn(struct work *){ do_wait_probe_defer(); panel = drm_of_find_panel_or_bridge(); if (!panel) { schedule_work(); /* want to restart the work so it can be stopped on driver unload */ return; } /* we have the panel now, register drm_bridge */ }- cobble something together with
component.c, but that's more for collecting unrelated struct device into a logical one than splitting it up more.tldr; I think you can split this loop here at the bridge by untangling the pwm from the
drm_bridgepart sufficiently.
Quoted 8 lines
Quoted 2 lines
Yes, it seems like a reasonable path forward. But I wanted some input before refactoring the whole thing.
Yeah it's unfortunately a bit of work. But I think it's the proper approach since
EPROBE_DEFERREDis fundamentally linked to struct device and bound drivers. So we do need a struct device for every part in our dependency graph to make sure we can resolve the dependencies all correctly with reprobing.
Can we not turn things around and make the bridge driver independent of the panel? To me it sounds like these loosely follow a hierarchy where it makes sense to probe the bridge first, without any dependency on the panel that's being used. I think this makes sense because this example shows that panels may depend on resources provided by the bridge. In this case it's a backlight, but I could also imagine the bridge providing some sort of I2C bus that the panel driver may need to use in order to query the panel's EDID.
The way I imagine that this would work is that the panel would probe separately from the bridge driver but use the OF graph to look up the bridge that has the resources (backlight, I2C bus, ...) that it needs to proceed. As long as that bridge has not been probed, the panel would need to defer, which is the standard way that provider/consumer pairs work. Once the bridge has probed, the panel can also proceed to probe because it can now find the necessary resources.
The only missing thing that I don't think we have right now is a way for the panel to then register with its parent bridge, but that should be fairly easy to add. I suspect this might get a bit tricky around the connector state paths because we can now get into a situation where the connector can have a complete bridge path set up but may be missing the panel (which I think in the current model can't happen because the bridge always relies on the panel being there, although it sounds like it could happen with Daniel's proposal as well). But that ultimately is not very different from how we deal with monitors on more standard interfaces like HDMI or DP where we emit a hotplug event when the monitor becomes available, so perhaps that infrastructure could be reused for this.
Thierry
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 130 lines · Thierry Reding
Quoted 110 lines · Daniel Vetter
Quoted 109 lines · Bjorn Andersson
Quoted 63 lines · Daniel Vetter
Quoted 39 lines · Bjorn Andersson
Quoted 11 lines · Thierry Reding
Quoted 9 lines · Bjorn Andersson
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.
Quoted 7 lines
What you're describing is basically a circular dependency. Can't we get rid of that in some other way? Why exactly does the bridge driver refuse to probe if the panel can't be found?
In other words, I see how the bridge would /use/ the panel in that it forward a video stream to it. But how does the panel /use/ the bridge?
Yes, this is indeed a circular dependency between the components.
The involved parts are:
* the bridge driver that implements the PWM chip probe defers ondrm_of_find_panel_or_bridge()failing to find the panel.
* the pwm-backlight driver that consumes the PWM channel probe defer because thepwm_chipwas not registered by the bridge.
* the panel that uses the backlight for DPMS purposes probe defer becausedrm_panel_of_backlight()fails to find the pwm-backlight.I looked at means of postponing
drm_of_find_panel_or_bridge()todrm_bridge_funcs->attach(), but at that time "deferral" would be fatal. I looked at registering thepwm_chipearlier, but that would depend on a guarantee of the pwm-backlight and panel driver to probe concurrently. And the current solution of not tying the backlight to the panel means that when userspace decides to DPMS the display the backlight stays on.Quoted 6 lines
The proposed solution (hack?) means that DPMS operations happening before the pwm-backlight has probed will be missed, so it's not perfect. It does however allow the backlight on my laptop to turn off, which is a big improvement.
But I'm certainly welcome to suggestions.
Entirely hand-waving, why doesn't the following work:
1. driver for the platform device which is the bridge loads
2. that platform driver registers the pwm
3. it registers some magic for later on (more below)
4. panel driver has deferred loading until step 2 happened
5. panel driver registersdrm_panel
6. the magic from step 3 picks up (after having been deferred for a few times probably) grabs the panel, and sets up the actualdrm_bridgedriverEveryone happy, or not? From the description it looks like the problem that the pwm that we need for the backlight is tied to the same driver as the
drm_bridge, and always torn down too if thedrm_bridgesetup fails somehow for a reason. And that reason is the circular dependency this creates.Quoted 4 lines
Now for the magic in step 3, there's options:
- change DT to split out that pwm as a separateplatform_device, that way bridge and panel can load indepedently (hopefully)This is an i2c device, so describing it multiple times would mean we have multiple devices with the same address...
Quoted 5 lines
- convert bridge to a multi-function device (mfd), essentially a way to instantiate more devices with their drivers at runtime. Then the actual pwm and
drm_bridgeparts of your bridge driver bind against those sub-functions, and can defer indepedentlyBut, this sounds reasonable and would rely on the existing probe deferral logic and if there's ever any improvements in this area we would directly benefit from it.
Quoted 25 lines
- we could create a callback/wait function for "pls wait for any panel to show up". Then your bridge driver could launch a
work_structwith that wait function, which will do the bridge setup once the panel has shown up. The pwm will be registered right away. It's essentially hand-rollingEPROBE_DEFERREDforwork_structin drm/panel. Maybe we might even have that exported from the driver core, e.g.
register_bridge_fn(struct work *)
{
do_wait_probe_defer();
panel =drm_of_find_panel_or_bridge();if (!panel) { schedule_work(); /* want to restart the work so it can be stopped on driver unload */ return;}
/* we have the panel now, register
drm_bridge*/
}- cobble something together with
component.c, but that's more for collecting unrelated struct device into a logical one than splitting it up more.tldr; I think you can split this loop here at the bridge by untangling the pwm from the
drm_bridgepart sufficiently.Quoted 8 lines
Quoted 2 lines
Yes, it seems like a reasonable path forward. But I wanted some input before refactoring the whole thing.
Yeah it's unfortunately a bit of work. But I think it's the proper approach since
EPROBE_DEFERREDis fundamentally linked to struct device and bound drivers. So we do need a struct device for every part in our dependency graph to make sure we can resolve the dependencies all correctly with reprobing.Can we not turn things around and make the bridge driver independent of the panel? To me it sounds like these loosely follow a hierarchy where it makes sense to probe the bridge first, without any dependency on the panel that's being used. I think this makes sense because this example shows that panels may depend on resources provided by the bridge. In this case it's a backlight, but I could also imagine the bridge providing some sort of I2C bus that the panel driver may need to use in order to query the panel's EDID.
Quoted 7 lines
The way I imagine that this would work is that the panel would probe separately from the bridge driver but use the OF graph to look up the bridge that has the resources (backlight, I2C bus, ...) that it needs to proceed. As long as that bridge has not been probed, the panel would need to defer, which is the standard way that provider/consumer pairs work. Once the bridge has probed, the panel can also proceed to probe because it can now find the necessary resources.
Yeah that might be the other option, treat the panel as a bridge (we have the panel bridge already), then build up the entire thing as a bridge chain. Not sure how much this is "just works" territory or not.
Quoted 4 lines
The only missing thing that I don't think we have right now is a way for the panel to then register with its parent bridge, but that should be fairly easy to add. I suspect this might get a bit tricky around the connector state paths because we can now get into a situation where the
Quoted 8 lines
connector can have a complete bridge path set up but may be missing the panel (which I think in the current model can't happen because the bridge always relies on the panel being there, although it sounds like it could happen with Daniel's proposal as well). But that ultimately is not very different from how we deal with monitors on more standard interfaces like HDMI or DP where we emit a hotplug event when the monitor becomes available, so perhaps that infrastructure could be reused for this.
Generally we try really hard to make sure panels are always there and never hotplug in/out. Not sure whether there's even userspace/desktops relying on this. So hotplugging the panel later on does not sound good. Bjorn's patch here does a light version of that with the backlight, and we're having this sprawling thread because that's bit suboptimal - userspace could boot real fast, see there's no backlight, and then not expose backlight adjusters if we're unlucky. -Daniel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 156 lines · Daniel Vetter
Quoted 130 lines · Thierry Reding
Quoted 110 lines · Daniel Vetter
Quoted 109 lines · Bjorn Andersson
Quoted 63 lines · Daniel Vetter
Quoted 39 lines · Bjorn Andersson
Quoted 11 lines · Thierry Reding
Quoted 9 lines · Bjorn Andersson
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.
Quoted 7 lines
What you're describing is basically a circular dependency. Can't we get rid of that in some other way? Why exactly does the bridge driver refuse to probe if the panel can't be found?
In other words, I see how the bridge would /use/ the panel in that it forward a video stream to it. But how does the panel /use/ the bridge?
Yes, this is indeed a circular dependency between the components.
The involved parts are:
* the bridge driver that implements the PWM chip probe defers ondrm_of_find_panel_or_bridge()failing to find the panel.
* the pwm-backlight driver that consumes the PWM channel probe defer because thepwm_chipwas not registered by the bridge.
* the panel that uses the backlight for DPMS purposes probe defer becausedrm_panel_of_backlight()fails to find the pwm-backlight.I looked at means of postponing
drm_of_find_panel_or_bridge()todrm_bridge_funcs->attach(), but at that time "deferral" would be fatal. I looked at registering thepwm_chipearlier, but that would depend on a guarantee of the pwm-backlight and panel driver to probe concurrently. And the current solution of not tying the backlight to the panel means that when userspace decides to DPMS the display the backlight stays on.Quoted 6 lines
The proposed solution (hack?) means that DPMS operations happening before the pwm-backlight has probed will be missed, so it's not perfect. It does however allow the backlight on my laptop to turn off, which is a big improvement.
But I'm certainly welcome to suggestions.
Entirely hand-waving, why doesn't the following work:
1. driver for the platform device which is the bridge loads
2. that platform driver registers the pwm
3. it registers some magic for later on (more below)
4. panel driver has deferred loading until step 2 happened
5. panel driver registersdrm_panel
6. the magic from step 3 picks up (after having been deferred for a few times probably) grabs the panel, and sets up the actualdrm_bridgedriverEveryone happy, or not? From the description it looks like the problem that the pwm that we need for the backlight is tied to the same driver as the
drm_bridge, and always torn down too if thedrm_bridgesetup fails somehow for a reason. And that reason is the circular dependency this creates.Quoted 4 lines
Now for the magic in step 3, there's options:
- change DT to split out that pwm as a separateplatform_device, that way bridge and panel can load indepedently (hopefully)This is an i2c device, so describing it multiple times would mean we have multiple devices with the same address...
Quoted 5 lines
- convert bridge to a multi-function device (mfd), essentially a way to instantiate more devices with their drivers at runtime. Then the actual pwm and
drm_bridgeparts of your bridge driver bind against those sub-functions, and can defer indepedentlyBut, this sounds reasonable and would rely on the existing probe deferral logic and if there's ever any improvements in this area we would directly benefit from it.
Quoted 25 lines
- we could create a callback/wait function for "pls wait for any panel to show up". Then your bridge driver could launch a
work_structwith that wait function, which will do the bridge setup once the panel has shown up. The pwm will be registered right away. It's essentially hand-rollingEPROBE_DEFERREDforwork_structin drm/panel. Maybe we might even have that exported from the driver core, e.g.
register_bridge_fn(struct work *)
{
do_wait_probe_defer();
panel =drm_of_find_panel_or_bridge();if (!panel) { schedule_work(); /* want to restart the work so it can be stopped on driver unload */ return;}
/* we have the panel now, register
drm_bridge*/
}- cobble something together with
component.c, but that's more for collecting unrelated struct device into a logical one than splitting it up more.tldr; I think you can split this loop here at the bridge by untangling the pwm from the
drm_bridgepart sufficiently.Quoted 8 lines
Quoted 2 lines
Yes, it seems like a reasonable path forward. But I wanted some input before refactoring the whole thing.
Yeah it's unfortunately a bit of work. But I think it's the proper approach since
EPROBE_DEFERREDis fundamentally linked to struct device and bound drivers. So we do need a struct device for every part in our dependency graph to make sure we can resolve the dependencies all correctly with reprobing.Can we not turn things around and make the bridge driver independent of the panel? To me it sounds like these loosely follow a hierarchy where it makes sense to probe the bridge first, without any dependency on the panel that's being used. I think this makes sense because this example shows that panels may depend on resources provided by the bridge. In this case it's a backlight, but I could also imagine the bridge providing some sort of I2C bus that the panel driver may need to use in order to query the panel's EDID.
Quoted 7 lines
The way I imagine that this would work is that the panel would probe separately from the bridge driver but use the OF graph to look up the bridge that has the resources (backlight, I2C bus, ...) that it needs to proceed. As long as that bridge has not been probed, the panel would need to defer, which is the standard way that provider/consumer pairs work. Once the bridge has probed, the panel can also proceed to probe because it can now find the necessary resources.
Yeah that might be the other option, treat the panel as a bridge (we have the panel bridge already), then build up the entire thing as a bridge chain. Not sure how much this is "just works" territory or not.
Quoted 4 lines
The only missing thing that I don't think we have right now is a way for the panel to then register with its parent bridge, but that should be fairly easy to add. I suspect this might get a bit tricky around the connector state paths because we can now get into a situation where the
Quoted 8 lines
connector can have a complete bridge path set up but may be missing the panel (which I think in the current model can't happen because the bridge always relies on the panel being there, although it sounds like it could happen with Daniel's proposal as well). But that ultimately is not very different from how we deal with monitors on more standard interfaces like HDMI or DP where we emit a hotplug event when the monitor becomes available, so perhaps that infrastructure could be reused for this.
Quoted 7 lines
Generally we try really hard to make sure panels are always there and never hotplug in/out. Not sure whether there's even userspace/desktops relying on this. So hotplugging the panel later on does not sound good. Bjorn's patch here does a light version of that with the backlight, and we're having this sprawling thread because that's bit suboptimal - userspace could boot real fast, see there's no backlight, and then not expose backlight adjusters if we're unlucky.
Yeah, hotplugging a panel would certainly be unusual. But I have never come across userspace that distinguishes by connector type in how it deals with hotplug events, so this might just work.
Irrespective of that, it shouldn't be necessary to hotplug panels. We could always have the connector driver defer probe as long as the bridge/panel chain has not been fully established. That way the whole DRM device wouldn't show up until the panel has been connected, so it should never be necessary to hotplug the panel in that case.
Thierry
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel