drm/panel: Support panel detection
Subsystems (5)
cover drm/panel: Support panel detection
Some panels are connected through extension boards an provide an easy way for the main board to detect when they are present (like checking for a working I2C communication with a device and making sure a specific reg in this device has a consistent value).
When this is the case, we might want to support dynamic panel detection and only expose the display (and its display modes) when the panel is detected, similar to the monitor detection we use for regular connectors (HDMI, DVI, ...).
This solves a problem we have on the Rpi when the panel is not connected to the board but described in the DT. This prevents the whole display pipeline from being exposed because one of the element (the panel) is missing.
This was posted as an RFC because I'm not sure dynamically detecting panels or supporting panel hotplug is actually something we want to do.
Thierry, and DRM folks in general, feel free to give your opinion on this approach, and/or propose others solution to solve the "DSI panel not connected" problem we have on RPi. Oh, and before someone suggests it, IIRC, Eric wanted to avoid relying on DT overlays to do that, I don't remember why though.
Regards,
Boris
Boris Brezillon (3):
drm/panel: Support panel detection
drm/bridge: panel: Make use of the panel detection infrastructure drm/panel: rpi-touchscreen: Implement ->detect()
drivers/gpu/drm/bridge/panel.c | 13 +++++ .../gpu/drm/panel/panel-raspberrypi-touchscreen.c | 62 ++++++++++++++++++---- include/drm/drm_panel.h | 12 +++++ 3 files changed, 78 insertions(+), 9 deletions(-)
Signature · 6 lines
2.14.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
RFC PATCH 1/3 drm/panel: Support panel detection
Some panels might be connected through extension boards and might not be available when the system boots. Extend the panel interface to support panel detection.
An optional ->detect() hook is added and, if implemented, will be called every time the panel user wants to know if the panel is connected or disconnected.
We also add a ->polled field which should encode the type of polling the DRM core should do (DRM_CONNECTOR_POLL_HPD, DRM_CONNECTOR_POLL_CONNECT and DRM_CONNECTOR_POLL_DISCONNECT flags).
--- include/drm/drm_panel.h | 12 ++++++++++++ 1 file changed, 12 insertions(+)
include/drm/drm_panel.h +12 -0
@@ -24,6 +24,7 @@#ifndef __DRM_PANEL_H__#define __DRM_PANEL_H__ +#include <drm/drm_connector.h> #include <linux/errno.h> #include <linux/list.h>
@@ -68,6 +69,7 @@ struct display_timing;* the panel. This is the job of the .unprepare() function. */ struct drm_panel_funcs { +int (*detect)(struct drm_panel *panel);int (*disable)(struct drm_panel *panel);int (*unprepare)(struct drm_panel *panel);int (*prepare)(struct drm_panel *panel);
@@ -90,6 +92,7 @@ struct drm_panel {struct drm_connector *connector;struct device *dev; +u8 polled;const struct drm_panel_funcs *funcs;struct list_head list;
@@ -186,6 +189,15 @@ static inline int drm_panel_get_modes(struct drm_panel *panel)return panel ? -ENOSYS : -EINVAL ; } +static inline int drm_panel_detect (struct drm_panel *panel) +{ +if (panel && panel->funcs && panel->funcs->detect) +return panel->funcs->detect (panel); + +/* Consider the panel as connected by default. */ +return panel ? connector_status_connected : -EINVAL ; +} +void drm_panel_init (struct drm_panel *panel);int drm_panel_add (struct drm_panel *panel);
Signature · 6 lines
2.14.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
RFC PATCH 2/3 drm/bridge: panel: Make use of the panel detection infrastructure
In reply to Boris BrezillonThe DRM panel framework now exposes a way to know whether a panel is connected or disconnected.
Use this panel detection logic to implement the connector->detect_ctx() method and allow one to report when a panel is connected or disconnected which is particularly useful to support panels connected through extension boards.
--- drivers/gpu/drm/bridge/panel.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
drivers/gpu/drm/bridge/panel.c +13 -0
@@ -44,9 +44,21 @@ static int panel_bridge_connector_get_modes(struct drm_connector *connector)return drm_panel_get_modes (panel_bridge->panel); } +static int +panel_bridge_connector_detect_ctx (struct drm_connector *connector, +struct drm_modeset_acquire_ctx *ctx, +bool force) +{ +struct panel_bridge *panel_bridge = +drm_connector_to_panel_bridge (connector); + +return drm_panel_detect (panel_bridge->panel); +} +static const struct drm_connector_helper_funcs panel_bridge_connector_helper_funcs = { .get_modes = panel_bridge_connector_get_modes, + .detect_ctx = panel_bridge_connector_detect_ctx, };static const struct drm_connector_funcs panel_bridge_connector_funcs = {
@@ -68,6 +80,7 @@ static int panel_bridge_attach(struct drm_bridge *bridge)return -ENODEV ; } + connector->polled = panel_bridge->panel->polled;drm_connector_helper_add (connector, &panel_bridge_connector_helper_funcs);
Signature · 6 lines
2.14.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
RFC PATCH 3/3 drm/panel: rpi-touchscreen: Implement ->detect()
In reply to Boris BrezillonImplement a way to determine when the panel is connected. This is done by reading REG_ID through I2C. We consider the panel as disconnect until we retrieve a valid ID.
--- .../gpu/drm/panel/panel-raspberrypi-touchscreen.c | 62 ++++++++++++++++++---- 1 file changed, 53 insertions(+), 9 deletions(-)
drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c +53 -9
@@ -196,6 +196,7 @@ struct rpi_touchscreen {struct drm_panel base;struct mipi_dsi_device *dsi;struct i2c_client *i2c; +bool connected; };static const struct drm_display_mode rpi_touchscreen_modes[] = {
@@ -255,6 +256,9 @@ static int rpi_touchscreen_write(struct rpi_touchscreen *ts, u16 reg, u32 val)mipi_dsi_dcs_write_buffer (ts->dsi, msg,sizeof (msg));#else +if (!ts->connected) +return 0 ; +rpi_touchscreen_i2c_write (ts,REG_WR_ADDRH , reg >>8 );rpi_touchscreen_i2c_write (ts,REG_WR_ADDRL , reg);rpi_touchscreen_i2c_write (ts,REG_WRITEH , val >>8 );
@@ -268,6 +272,9 @@ static int rpi_touchscreen_disable(struct drm_panel *panel) {struct rpi_touchscreen *ts =panel_to_ts (panel); +if (!ts->connected) +return 0 ; +rpi_touchscreen_i2c_write (ts,REG_PWM ,0 );rpi_touchscreen_i2c_write (ts,REG_POWERON ,0 );
@@ -286,6 +293,9 @@ static int rpi_touchscreen_enable(struct drm_panel *panel)struct rpi_touchscreen *ts =panel_to_ts (panel);int i; +if (!ts->connected) +return 0 ; +rpi_touchscreen_i2c_write (ts,REG_POWERON ,1 );/* Wait for nPWRDWN to go low to indicate poweron is done. */ for (i =0 ; i <100 ; i++) {
@@ -330,6 +340,10 @@ static int rpi_touchscreen_get_modes(struct drm_panel *panel)struct drm_device *drm = panel->drm;unsigned int i, num =0 ;static const u32 bus_format =MEDIA_BUS_FMT_RGB888_1X24 ; +struct rpi_touchscreen *ts =panel_to_ts (panel); + +if (!ts->connected) +return 0 ;for (i =0 ; i <ARRAY_SIZE (rpi_touchscreen_modes); i++) {const struct drm_display_mode *m = &rpi_touchscreen_modes[i];
@@ -362,7 +376,34 @@ static int rpi_touchscreen_get_modes(struct drm_panel *panel)return num; } +static int rpi_touchscreen_detect (struct drm_panel *panel) +{ +struct rpi_touchscreen *ts =panel_to_ts (panel); +int ver; + +if (ts->connected) +return connector_status_connected; + + ver =rpi_touchscreen_i2c_read (ts,REG_ID ); +switch (ver) { +case 0xde :/* ver 1 */ +case 0xc3 :/* ver 2 */ + ts->connected = true; + +/* Turn off at boot, so we can cleanly sequence powering on. */ +rpi_touchscreen_i2c_write (ts,REG_POWERON ,0 ); + +return connector_status_connected; + +default : +break ; + } + +return connector_status_disconnected; +} +static const struct drm_panel_funcs rpi_touchscreen_funcs = { + .detect = rpi_touchscreen_detect, .disable = rpi_touchscreen_disable, .unprepare = rpi_touchscreen_noop, .prepare = rpi_touchscreen_noop,
@@ -393,22 +434,24 @@ static int rpi_touchscreen_probe(struct i2c_client *i2c, ts->i2c = i2c; ver =rpi_touchscreen_i2c_read (ts,REG_ID ); -if (ver <0 ) { -dev_err (dev,"Atmel I2C read failed: %d\n" , ver); -return -ENODEV ; - } -switch (ver) {case 0xde :/* ver 1 */ case 0xc3 :/* ver 2 */ + ts->connected = true; + +/* Turn off at boot, so we can cleanly sequence powering on. */ +rpi_touchscreen_i2c_write (ts,REG_POWERON ,0 );break ;default : -dev_err (dev,"Unknown Atmel firmware revision: 0x%02x\n" , ver); -return -ENODEV ; +if (ver <0 ) +dev_err (dev,"Atmel I2C read failed: %d\n" , ver); +else +dev_err (dev, +"Unknown Atmel firmware revision: 0x%02x\n" , + ver); +break ; } -/* Turn off at boot, so we can cleanly sequence powering on. */ -rpi_touchscreen_i2c_write (ts,REG_POWERON ,0 );/* Look up the DSI host. It needs to probe before we do. */ endpoint =of_graph_get_next_endpoint (dev->of_node,NULL );
@@ -432,6 +475,7 @@ static int rpi_touchscreen_probe(struct i2c_client *i2c, ts->base.dev = dev; ts->base.funcs = &rpi_touchscreen_funcs; + ts->base.polled =DRM_CONNECTOR_POLL_CONNECT ;/* This appears last, as it's what will unblock the DSI host * driver's component bind function.
Signature · 6 lines
2.14.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 8 lines · Boris Brezillon
Some panels might be connected through extension boards and might not be available when the system boots. Extend the panel interface to support panel detection.
An optional ->detect() hook is added and, if implemented, will be called every time the panel user wants to know if the panel is connected or disconnected.
Quoted 5 lines
We also add a ->polled field which should encode the type of polling the DRM core should do (
DRM_CONNECTOR_POLL_HPD,DRM_CONNECTOR_POLL_CONNECTandDRM_CONNECTOR_POLL_DISCONNECTflags).Signed-off-by Boris Brezillon <[email protected]>
Hm, not sure panel detection makes much sense, the entire idea behind drm_panel is to hard-code a fixed/built-in panel. The only thing panels may report through the connection status is whether the lid is closed or not. Yes we should probably document that somewhere.
If you have a panel-that-can-be-hotplugged a drm_bridge that implemens the drm_connector is probably the way to go.
Quoted 17 lines
--- include/drm/drm_panel.h | 12 ++++++++++++ 1 file changed, 12 insertions(+)include/drm/drm_panel.h +1
-0@@ -24,6 +24,7 @@#ifndef __DRM_PANEL_H__#define __DRM_PANEL_H__ +#include <drm/drm_connector.h> #include <linux/errno.h> #include <linux/list.h>
include/drm/drm_panel.h struct display_timing; · line 72
Quoted 4 lines
include/drm/drm_panel.h +1
-0@@ -68,6 +69,7 @@ struct display_timing;* the panel. This is the job of the .unprepare() function. */ struct drm_panel_funcs { +int (*detect)(struct drm_panel *panel);
Kerneldoc for this please. Would also be really good to switch this struct of function pointers over to the in-line style, and put the paragraphs relevant for a given callback into it's dedicated comment. -Daniel
Quoted 30 lines
include/drm/drm_panel.h +10
-0int (*disable)(struct drm_panel *panel);int (*unprepare)(struct drm_panel *panel);int (*prepare)(struct drm_panel *panel);@@ -90,6 +92,7 @@ struct drm_panel {struct drm_connector *connector;struct device *dev; +u8 polled;const struct drm_panel_funcs *funcs;struct list_head list;@@ -186,6 +189,15 @@ static inline int drm_panel_get_modes(struct drm_panel *panel)return panel ? -ENOSYS : -EINVAL ; } +static inline int drm_panel_detect (struct drm_panel *panel) +{ +if (panel && panel->funcs && panel->funcs->detect) +return panel->funcs->detect (panel); + +/* Consider the panel as connected by default. */ +return panel ? connector_status_connected : -EINVAL ; +} +void drm_panel_init (struct drm_panel *panel);int drm_panel_add (struct drm_panel *panel);Signature · 1 line
2.14.1
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
Hi Daniel,
Quoted 15 lines · On Mon, 30 Apr 2018 18:08:47 +0200 Daniel Vetter <[email protected]> wrote:
Quoted 8 lines · Boris Brezillon
Some panels might be connected through extension boards and might not be available when the system boots. Extend the panel interface to support panel detection.
An optional ->detect() hook is added and, if implemented, will be called every time the panel user wants to know if the panel is connected or disconnected.
Quoted 5 lines
We also add a ->polled field which should encode the type of polling the DRM core should do (
DRM_CONNECTOR_POLL_HPD,DRM_CONNECTOR_POLL_CONNECTandDRM_CONNECTOR_POLL_DISCONNECTflags).Signed-off-by Boris Brezillon <[email protected]>
Quoted 7 lines
Hm, not sure panel detection makes much sense, the entire idea behind
drm_panelis to hard-code a fixed/built-in panel. The only thing panels may report through the connection status is whether the lid is closed or not. Yes we should probably document that somewhere.If you have a panel-that-can-be-hotplugged a
drm_bridgethat implemens thedrm_connectoris probably the way to go.
That does not really work for the rpi panel case because we use an I2C message to detect the presence of the panel. So, unless we decide to attach the I2C client to the bridge device instead of attaching it to the panel that's not really possible, and I'm not sure doing that is a good thing either.
I guess the only alternative to solve the issue I'm trying to solve is drm_bridge hotplug, so that we allow the DRM device to be registered even if not all of its leaf nodes (i.e. bridges and connectors) are ready to be used.
Quoted 17 lines
Quoted 17 lines
--- include/drm/drm_panel.h | 12 ++++++++++++ 1 file changed, 12 insertions(+)include/drm/drm_panel.h +1
-0@@ -24,6 +24,7 @@#ifndef __DRM_PANEL_H__#define __DRM_PANEL_H__ +#include <drm/drm_connector.h> #include <linux/errno.h> #include <linux/list.h>
Quoted 9 lines
include/drm/drm_panel.h struct display_timing; · line 72
Quoted 5 lines
include/drm/drm_panel.h +1
-0@@ -68,6 +69,7 @@ struct display_timing;* the panel. This is the job of the .unprepare() function. */ struct drm_panel_funcs { +int (*detect)(struct drm_panel *panel);Kerneldoc for this please. Would also be really good to switch this struct of function pointers over to the in-line style, and put the paragraphs relevant for a given callback into it's dedicated comment.
Not useful anymore since the idea appeared to be bad ;-).
Thanks for the quick feedback.
Boris
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 10 lines · Boris Brezillon
Some panels are connected through extension boards an provide an easy way for the main board to detect when they are present (like checking for a working I2C communication with a device and making sure a specific reg in this device has a consistent value).
When this is the case, we might want to support dynamic panel detection and only expose the display (and its display modes) when the panel is detected, similar to the monitor detection we use for regular connectors (HDMI, DVI, ...).
Quoted 7 lines
This solves a problem we have on the Rpi when the panel is not connected to the board but described in the DT. This prevents the whole display pipeline from being exposed because one of the element (the panel) is missing.
This was posted as an RFC because I'm not sure dynamically detecting panels or supporting panel hotplug is actually something we want to do.
I want to clarify here: we're not trying to do panel hotplug. We're trying to boot-time-only detection of whether or not the standard panel is plugged in.
Since this is something like the 6th variation of trying to get this driver to work whether or not the panel is plugged in at boot, I'm leaning toward just asking the closed source firmware to hack the DT to add/remove the panel's node depending on whether it can probe it on I2C. Relying on more closed source software in order to work around something so trivial is really frustrating, though.
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 24 lines · On Mon, 30 Apr 2018 10:22:19 -0700 Eric Anholt <[email protected]> wrote:
Quoted 10 lines · Boris Brezillon
Some panels are connected through extension boards an provide an easy way for the main board to detect when they are present (like checking for a working I2C communication with a device and making sure a specific reg in this device has a consistent value).
When this is the case, we might want to support dynamic panel detection and only expose the display (and its display modes) when the panel is detected, similar to the monitor detection we use for regular connectors (HDMI, DVI, ...).
Quoted 7 lines
This solves a problem we have on the Rpi when the panel is not connected to the board but described in the DT. This prevents the whole display pipeline from being exposed because one of the element (the panel) is missing.
This was posted as an RFC because I'm not sure dynamically detecting panels or supporting panel hotplug is actually something we want to do.
I want to clarify here: we're not trying to do panel hotplug. We're trying to boot-time-only detection of whether or not the standard panel is plugged in.
Quoted 6 lines
Since this is something like the 6th variation of trying to get this driver to work whether or not the panel is plugged in at boot, I'm leaning toward just asking the closed source firmware to hack the DT to add/remove the panel's node depending on whether it can probe it on I2C. Relying on more closed source software in order to work around something so trivial is really frustrating, though.
Well, we could still have this hack in the rpi-touchscreen-panel driver and expose the panel without any display modes when the device is actually not responding on the I2C bus. This way we could have the DRM device registered and the panel display would just be unusable.
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 27 lines · Boris Brezillon
Quoted 24 lines · On Mon, 30 Apr 2018 10:22:19 -0700 Eric Anholt <[email protected]> wrote:
Quoted 10 lines · Boris Brezillon
Some panels are connected through extension boards an provide an easy way for the main board to detect when they are present (like checking for a working I2C communication with a device and making sure a specific reg in this device has a consistent value).
When this is the case, we might want to support dynamic panel detection and only expose the display (and its display modes) when the panel is detected, similar to the monitor detection we use for regular connectors (HDMI, DVI, ...).
Quoted 7 lines
This solves a problem we have on the Rpi when the panel is not connected to the board but described in the DT. This prevents the whole display pipeline from being exposed because one of the element (the panel) is missing.
This was posted as an RFC because I'm not sure dynamically detecting panels or supporting panel hotplug is actually something we want to do.
I want to clarify here: we're not trying to do panel hotplug. We're trying to boot-time-only detection of whether or not the standard panel is plugged in.
Quoted 6 lines
Quoted 6 lines
Since this is something like the 6th variation of trying to get this driver to work whether or not the panel is plugged in at boot, I'm leaning toward just asking the closed source firmware to hack the DT to add/remove the panel's node depending on whether it can probe it on I2C. Relying on more closed source software in order to work around something so trivial is really frustrating, though.
Ugh, sorry, I didn't remember the entire story here when I replied.
Quoted 4 lines
Well, we could still have this hack in the rpi-touchscreen-panel driver and expose the panel without any display modes when the device is actually not responding on the I2C bus. This way we could have the DRM device registered and the panel display would just be unusable.
Yeah that sounds like a reasonable hack to me, but I have no idea whether this was one of the earlier pile of ideas or not. Another thing that I just thought of (so might be bogus) would be a dummy bridge which only exists to transport an errno, which would then be returned from drm_of_find_panel_or_bridge instead of 0. Probably only reasonable case would be to return -ENODEV. No good idea though how to somewhat cleanly wire this through the entire stack, simplest might be to add an in errno to drm_panel. Since we use an embedded list for of_drm_find_panel we can't do the usual trick of storing the errno in the pointer.
Hm, maybe we could encode panel->funcs == NULL as "sorry this panel isn't really there" and use that. Assuming we only ever want to encode ENODEV and not a pile of other errno values.
-Daniel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel