2019-05-27 09:55:01 +03:00
// SPDX-License-Identifier: GPL-2.0-or-later
2017-06-02 23:25:14 +03:00
/*
* Copyright ( C ) 2016 Laurent Pinchart < laurent . pinchart @ ideasonboard . com >
* Copyright ( C ) 2017 Broadcom
*/
# include <drm/drm_atomic_helper.h>
2019-08-26 18:26:29 +03:00
# include <drm/drm_bridge.h>
2017-06-02 23:25:14 +03:00
# include <drm/drm_connector.h>
# include <drm/drm_encoder.h>
2022-07-11 20:38:40 +03:00
# include <drm/drm_managed.h>
2017-06-02 23:25:14 +03:00
# include <drm/drm_modeset_helper_vtables.h>
2021-09-17 21:09:25 +03:00
# include <drm/drm_of.h>
2017-06-02 23:25:14 +03:00
# include <drm/drm_panel.h>
2019-05-19 21:36:36 +03:00
# include <drm/drm_print.h>
2019-05-16 18:25:56 +03:00
# include <drm/drm_probe_helper.h>
2017-06-02 23:25:14 +03:00
struct panel_bridge {
struct drm_bridge bridge ;
struct drm_connector connector ;
struct drm_panel * panel ;
u32 connector_type ;
} ;
static inline struct panel_bridge *
drm_bridge_to_panel_bridge ( struct drm_bridge * bridge )
{
return container_of ( bridge , struct panel_bridge , bridge ) ;
}
static inline struct panel_bridge *
drm_connector_to_panel_bridge ( struct drm_connector * connector )
{
return container_of ( connector , struct panel_bridge , connector ) ;
}
static int panel_bridge_connector_get_modes ( struct drm_connector * connector )
{
struct panel_bridge * panel_bridge =
drm_connector_to_panel_bridge ( connector ) ;
2019-12-07 17:03:34 +03:00
return drm_panel_get_modes ( panel_bridge - > panel , connector ) ;
2017-06-02 23:25:14 +03:00
}
static const struct drm_connector_helper_funcs
panel_bridge_connector_helper_funcs = {
. get_modes = panel_bridge_connector_get_modes ,
} ;
static const struct drm_connector_funcs panel_bridge_connector_funcs = {
. reset = drm_atomic_helper_connector_reset ,
. fill_modes = drm_helper_probe_single_connector_modes ,
. destroy = drm_connector_cleanup ,
. atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state ,
. atomic_destroy_state = drm_atomic_helper_connector_destroy_state ,
} ;
drm/bridge: Extend bridge API to disable connector creation
Most bridge drivers create a DRM connector to model the connector at the
output of the bridge. This model is historical and has worked pretty
well so far, but causes several issues:
- It prevents supporting more complex display pipelines where DRM
connector operations are split over multiple components. For instance a
pipeline with a bridge connected to the DDC signals to read EDID data,
and another one connected to the HPD signal to detect connection and
disconnection, will not be possible to support through this model.
- It requires every bridge driver to implement similar connector
handling code, resulting in code duplication.
- It assumes that a bridge will either be wired to a connector or to
another bridge, but doesn't support bridges that can be used in both
positions very well (although there is some ad-hoc support for this in
the analogix_dp bridge driver).
In order to solve these issues, ownership of the connector should be
moved to the display controller driver (where it can be implemented
using helpers provided by the core).
Extend the bridge API to allow disabling connector creation in bridge
drivers as a first step towards the new model. The new flags argument to
the bridge .attach() operation allows instructing the bridge driver to
skip creating a connector. Unconditionally set the new flags argument to
0 for now to keep the existing behaviour, and modify all existing bridge
drivers to return an error when connector creation is not requested as
they don't support this feature yet.
The change is based on the following semantic patch, with manual review
and edits.
@ rule1 @
identifier funcs;
identifier fn;
@@
struct drm_bridge_funcs funcs = {
...,
.attach = fn
};
@ depends on rule1 @
identifier rule1.fn;
identifier bridge;
statement S, S1;
@@
int fn(
struct drm_bridge *bridge
+ , enum drm_bridge_attach_flags flags
)
{
... when != S
+ if (flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR) {
+ DRM_ERROR("Fix bridge driver to make connector optional!");
+ return -EINVAL;
+ }
+
S1
...
}
@ depends on rule1 @
identifier rule1.fn;
identifier bridge, flags;
expression E1, E2, E3;
@@
int fn(
struct drm_bridge *bridge,
enum drm_bridge_attach_flags flags
) {
<...
drm_bridge_attach(E1, E2, E3
+ , flags
)
...>
}
@@
expression E1, E2, E3;
@@
drm_bridge_attach(E1, E2, E3
+ , 0
)
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Acked-by: Sam Ravnborg <sam@ravnborg.org>
Reviewed-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
Tested-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Reviewed-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20200226112514.12455-10-laurent.pinchart@ideasonboard.com
2020-02-26 14:24:29 +03:00
static int panel_bridge_attach ( struct drm_bridge * bridge ,
enum drm_bridge_attach_flags flags )
2017-06-02 23:25:14 +03:00
{
struct panel_bridge * panel_bridge = drm_bridge_to_panel_bridge ( bridge ) ;
struct drm_connector * connector = & panel_bridge - > connector ;
int ret ;
2020-02-26 14:24:37 +03:00
if ( flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR )
return 0 ;
drm/bridge: Extend bridge API to disable connector creation
Most bridge drivers create a DRM connector to model the connector at the
output of the bridge. This model is historical and has worked pretty
well so far, but causes several issues:
- It prevents supporting more complex display pipelines where DRM
connector operations are split over multiple components. For instance a
pipeline with a bridge connected to the DDC signals to read EDID data,
and another one connected to the HPD signal to detect connection and
disconnection, will not be possible to support through this model.
- It requires every bridge driver to implement similar connector
handling code, resulting in code duplication.
- It assumes that a bridge will either be wired to a connector or to
another bridge, but doesn't support bridges that can be used in both
positions very well (although there is some ad-hoc support for this in
the analogix_dp bridge driver).
In order to solve these issues, ownership of the connector should be
moved to the display controller driver (where it can be implemented
using helpers provided by the core).
Extend the bridge API to allow disabling connector creation in bridge
drivers as a first step towards the new model. The new flags argument to
the bridge .attach() operation allows instructing the bridge driver to
skip creating a connector. Unconditionally set the new flags argument to
0 for now to keep the existing behaviour, and modify all existing bridge
drivers to return an error when connector creation is not requested as
they don't support this feature yet.
The change is based on the following semantic patch, with manual review
and edits.
@ rule1 @
identifier funcs;
identifier fn;
@@
struct drm_bridge_funcs funcs = {
...,
.attach = fn
};
@ depends on rule1 @
identifier rule1.fn;
identifier bridge;
statement S, S1;
@@
int fn(
struct drm_bridge *bridge
+ , enum drm_bridge_attach_flags flags
)
{
... when != S
+ if (flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR) {
+ DRM_ERROR("Fix bridge driver to make connector optional!");
+ return -EINVAL;
+ }
+
S1
...
}
@ depends on rule1 @
identifier rule1.fn;
identifier bridge, flags;
expression E1, E2, E3;
@@
int fn(
struct drm_bridge *bridge,
enum drm_bridge_attach_flags flags
) {
<...
drm_bridge_attach(E1, E2, E3
+ , flags
)
...>
}
@@
expression E1, E2, E3;
@@
drm_bridge_attach(E1, E2, E3
+ , 0
)
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Acked-by: Sam Ravnborg <sam@ravnborg.org>
Reviewed-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
Tested-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Reviewed-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20200226112514.12455-10-laurent.pinchart@ideasonboard.com
2020-02-26 14:24:29 +03:00
2017-06-02 23:25:14 +03:00
if ( ! bridge - > encoder ) {
DRM_ERROR ( " Missing encoder \n " ) ;
return - ENODEV ;
}
drm_connector_helper_add ( connector ,
& panel_bridge_connector_helper_funcs ) ;
ret = drm_connector_init ( bridge - > dev , connector ,
& panel_bridge_connector_funcs ,
panel_bridge - > connector_type ) ;
if ( ret ) {
DRM_ERROR ( " Failed to initialize connector \n " ) ;
return ret ;
}
2023-01-20 14:43:12 +03:00
drm_panel_bridge_set_orientation ( connector , bridge ) ;
2018-07-09 11:40:07 +03:00
drm_connector_attach_encoder ( & panel_bridge - > connector ,
2017-06-02 23:25:14 +03:00
bridge - > encoder ) ;
2022-04-19 12:14:22 +03:00
if ( bridge - > dev - > registered ) {
if ( connector - > funcs - > reset )
connector - > funcs - > reset ( connector ) ;
drm_connector_register ( connector ) ;
}
2022-03-03 19:36:50 +03:00
2017-06-02 23:25:14 +03:00
return 0 ;
}
static void panel_bridge_detach ( struct drm_bridge * bridge )
{
2021-03-27 14:57:40 +03:00
struct panel_bridge * panel_bridge = drm_bridge_to_panel_bridge ( bridge ) ;
struct drm_connector * connector = & panel_bridge - > connector ;
/*
* Cleanup the connector if we know it was initialized .
*
* FIXME : This wouldn ' t be needed if the panel_bridge structure was
* allocated with drmm_kzalloc ( ) . This might be tricky since the
* drm_device pointer can only be retrieved when the bridge is attached .
*/
if ( connector - > dev )
drm_connector_cleanup ( connector ) ;
2017-06-02 23:25:14 +03:00
}
2023-03-02 19:33:05 +03:00
static void panel_bridge_atomic_pre_enable ( struct drm_bridge * bridge ,
struct drm_bridge_state * old_bridge_state )
2017-06-02 23:25:14 +03:00
{
struct panel_bridge * panel_bridge = drm_bridge_to_panel_bridge ( bridge ) ;
2023-03-02 19:33:06 +03:00
struct drm_atomic_state * atomic_state = old_bridge_state - > base . state ;
struct drm_encoder * encoder = bridge - > encoder ;
struct drm_crtc * crtc ;
struct drm_crtc_state * old_crtc_state ;
crtc = drm_atomic_get_new_crtc_for_encoder ( atomic_state , encoder ) ;
if ( ! crtc )
return ;
old_crtc_state = drm_atomic_get_old_crtc_state ( atomic_state , crtc ) ;
if ( old_crtc_state & & old_crtc_state - > self_refresh_active )
return ;
2017-06-02 23:25:14 +03:00
drm_panel_prepare ( panel_bridge - > panel ) ;
}
2023-03-02 19:33:05 +03:00
static void panel_bridge_atomic_enable ( struct drm_bridge * bridge ,
struct drm_bridge_state * old_bridge_state )
2017-06-02 23:25:14 +03:00
{
struct panel_bridge * panel_bridge = drm_bridge_to_panel_bridge ( bridge ) ;
2023-03-02 19:33:06 +03:00
struct drm_atomic_state * atomic_state = old_bridge_state - > base . state ;
struct drm_encoder * encoder = bridge - > encoder ;
struct drm_crtc * crtc ;
struct drm_crtc_state * old_crtc_state ;
crtc = drm_atomic_get_new_crtc_for_encoder ( atomic_state , encoder ) ;
if ( ! crtc )
return ;
old_crtc_state = drm_atomic_get_old_crtc_state ( atomic_state , crtc ) ;
if ( old_crtc_state & & old_crtc_state - > self_refresh_active )
return ;
2017-06-02 23:25:14 +03:00
drm_panel_enable ( panel_bridge - > panel ) ;
}
2023-03-02 19:33:05 +03:00
static void panel_bridge_atomic_disable ( struct drm_bridge * bridge ,
struct drm_bridge_state * old_bridge_state )
2017-06-02 23:25:14 +03:00
{
struct panel_bridge * panel_bridge = drm_bridge_to_panel_bridge ( bridge ) ;
2023-03-02 19:33:06 +03:00
struct drm_atomic_state * atomic_state = old_bridge_state - > base . state ;
struct drm_encoder * encoder = bridge - > encoder ;
struct drm_crtc * crtc ;
struct drm_crtc_state * new_crtc_state ;
crtc = drm_atomic_get_old_crtc_for_encoder ( atomic_state , encoder ) ;
if ( ! crtc )
return ;
new_crtc_state = drm_atomic_get_new_crtc_state ( atomic_state , crtc ) ;
if ( new_crtc_state & & new_crtc_state - > self_refresh_active )
return ;
2017-06-02 23:25:14 +03:00
drm_panel_disable ( panel_bridge - > panel ) ;
}
2023-03-02 19:33:05 +03:00
static void panel_bridge_atomic_post_disable ( struct drm_bridge * bridge ,
struct drm_bridge_state * old_bridge_state )
2017-06-02 23:25:14 +03:00
{
struct panel_bridge * panel_bridge = drm_bridge_to_panel_bridge ( bridge ) ;
2023-03-02 19:33:06 +03:00
struct drm_atomic_state * atomic_state = old_bridge_state - > base . state ;
struct drm_encoder * encoder = bridge - > encoder ;
struct drm_crtc * crtc ;
struct drm_crtc_state * new_crtc_state ;
crtc = drm_atomic_get_old_crtc_for_encoder ( atomic_state , encoder ) ;
if ( ! crtc )
return ;
new_crtc_state = drm_atomic_get_new_crtc_state ( atomic_state , crtc ) ;
if ( new_crtc_state & & new_crtc_state - > self_refresh_active )
return ;
2017-06-02 23:25:14 +03:00
drm_panel_unprepare ( panel_bridge - > panel ) ;
}
2020-02-26 14:24:37 +03:00
static int panel_bridge_get_modes ( struct drm_bridge * bridge ,
struct drm_connector * connector )
{
struct panel_bridge * panel_bridge = drm_bridge_to_panel_bridge ( bridge ) ;
return drm_panel_get_modes ( panel_bridge - > panel , connector ) ;
}
2022-02-05 03:13:41 +03:00
static void panel_bridge_debugfs_init ( struct drm_bridge * bridge ,
struct dentry * root )
{
struct panel_bridge * panel_bridge = drm_bridge_to_panel_bridge ( bridge ) ;
struct drm_panel * panel = panel_bridge - > panel ;
root = debugfs_create_dir ( " panel " , root ) ;
if ( panel - > funcs - > debugfs_init )
panel - > funcs - > debugfs_init ( panel , root ) ;
}
2017-06-02 23:25:14 +03:00
static const struct drm_bridge_funcs panel_bridge_bridge_funcs = {
. attach = panel_bridge_attach ,
. detach = panel_bridge_detach ,
2023-03-02 19:33:05 +03:00
. atomic_pre_enable = panel_bridge_atomic_pre_enable ,
. atomic_enable = panel_bridge_atomic_enable ,
. atomic_disable = panel_bridge_atomic_disable ,
. atomic_post_disable = panel_bridge_atomic_post_disable ,
2020-02-26 14:24:37 +03:00
. get_modes = panel_bridge_get_modes ,
2020-01-28 16:55:12 +03:00
. atomic_reset = drm_atomic_helper_bridge_reset ,
. atomic_duplicate_state = drm_atomic_helper_bridge_duplicate_state ,
. atomic_destroy_state = drm_atomic_helper_bridge_destroy_state ,
. atomic_get_input_bus_fmts = drm_atomic_helper_bridge_propagate_bus_fmt ,
2022-02-05 03:13:41 +03:00
. debugfs_init = panel_bridge_debugfs_init ,
2017-06-02 23:25:14 +03:00
} ;
2022-06-09 10:27:23 +03:00
/**
* drm_bridge_is_panel - Checks if a drm_bridge is a panel_bridge .
*
* @ bridge : The drm_bridge to be checked .
*
* Returns true if the bridge is a panel bridge , or false otherwise .
*/
bool drm_bridge_is_panel ( const struct drm_bridge * bridge )
{
return bridge - > funcs = = & panel_bridge_bridge_funcs ;
}
EXPORT_SYMBOL ( drm_bridge_is_panel ) ;
2017-06-02 23:25:14 +03:00
/**
2019-01-11 19:40:46 +03:00
* drm_panel_bridge_add - Creates a & drm_bridge and & drm_connector that
* just calls the appropriate functions from & drm_panel .
2017-06-02 23:25:14 +03:00
*
* @ panel : The drm_panel being wrapped . Must be non - NULL .
*
* For drivers converting from directly using drm_panel : The expected
* usage pattern is that during either encoder module probe or DSI
* host attach , a drm_panel will be looked up through
* drm_of_find_panel_or_bridge ( ) . drm_panel_bridge_add ( ) is used to
* wrap that panel in the new bridge , and the result can then be
* passed to drm_bridge_attach ( ) . The drm_panel_prepare ( ) and related
* functions can be dropped from the encoder driver ( they ' re now
* called by the KMS helpers before calling into the encoder ) , along
2019-01-11 19:40:46 +03:00
* with connector creation . When done with the bridge ( after
* drm_mode_config_cleanup ( ) if the bridge has already been attached ) , then
2017-06-02 23:25:14 +03:00
* drm_panel_bridge_remove ( ) to free it .
2019-01-11 19:40:46 +03:00
*
drm/bridge: panel: Infer connector type from panel by default
The drm panel bridge creates a connector using a connector type
explicitly passed by the display controller or bridge driver that
instantiates the panel bridge. Now that drm_panel reports its connector
type, we can use it to avoid passing an explicit (and often incorrect)
connector type to drm_panel_bridge_add() and
devm_drm_panel_bridge_add().
Several drivers report incorrect or unknown connector types to
userspace. Reporting a different type may result in a breakage. For that
reason, rename (devm_)drm_panel_bridge_add() to
(devm_)drm_panel_bridge_add_typed(), and add new
(devm_)drm_panel_bridge_add() functions that use the panel connector
type. Update all callers of (devm_)drm_panel_bridge_add() to the _typed
function, they will be converted one by one after testing.
The panel drivers have been updated with the following Coccinelle
semantic patch, with manual inspection and fixes to indentation.
@@
expression bridge;
expression dev;
expression panel;
identifier type;
@@
(
-bridge = drm_panel_bridge_add(panel, type);
+bridge = drm_panel_bridge_add_typed(panel, type);
|
-bridge = devm_drm_panel_bridge_add(dev, panel, type);
+bridge = devm_drm_panel_bridge_add_typed(dev, panel, type);
)
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20190904132804.29680-3-laurent.pinchart@ideasonboard.com
2019-09-04 16:28:04 +03:00
* The connector type is set to @ panel - > connector_type , which must be set to a
* known type . Calling this function with a panel whose connector type is
2020-04-17 00:06:54 +03:00
* DRM_MODE_CONNECTOR_Unknown will return ERR_PTR ( - EINVAL ) .
drm/bridge: panel: Infer connector type from panel by default
The drm panel bridge creates a connector using a connector type
explicitly passed by the display controller or bridge driver that
instantiates the panel bridge. Now that drm_panel reports its connector
type, we can use it to avoid passing an explicit (and often incorrect)
connector type to drm_panel_bridge_add() and
devm_drm_panel_bridge_add().
Several drivers report incorrect or unknown connector types to
userspace. Reporting a different type may result in a breakage. For that
reason, rename (devm_)drm_panel_bridge_add() to
(devm_)drm_panel_bridge_add_typed(), and add new
(devm_)drm_panel_bridge_add() functions that use the panel connector
type. Update all callers of (devm_)drm_panel_bridge_add() to the _typed
function, they will be converted one by one after testing.
The panel drivers have been updated with the following Coccinelle
semantic patch, with manual inspection and fixes to indentation.
@@
expression bridge;
expression dev;
expression panel;
identifier type;
@@
(
-bridge = drm_panel_bridge_add(panel, type);
+bridge = drm_panel_bridge_add_typed(panel, type);
|
-bridge = devm_drm_panel_bridge_add(dev, panel, type);
+bridge = devm_drm_panel_bridge_add_typed(dev, panel, type);
)
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20190904132804.29680-3-laurent.pinchart@ideasonboard.com
2019-09-04 16:28:04 +03:00
*
2019-12-18 15:12:23 +03:00
* See devm_drm_panel_bridge_add ( ) for an automatically managed version of this
2019-01-11 19:40:46 +03:00
* function .
2017-06-02 23:25:14 +03:00
*/
drm/bridge: panel: Infer connector type from panel by default
The drm panel bridge creates a connector using a connector type
explicitly passed by the display controller or bridge driver that
instantiates the panel bridge. Now that drm_panel reports its connector
type, we can use it to avoid passing an explicit (and often incorrect)
connector type to drm_panel_bridge_add() and
devm_drm_panel_bridge_add().
Several drivers report incorrect or unknown connector types to
userspace. Reporting a different type may result in a breakage. For that
reason, rename (devm_)drm_panel_bridge_add() to
(devm_)drm_panel_bridge_add_typed(), and add new
(devm_)drm_panel_bridge_add() functions that use the panel connector
type. Update all callers of (devm_)drm_panel_bridge_add() to the _typed
function, they will be converted one by one after testing.
The panel drivers have been updated with the following Coccinelle
semantic patch, with manual inspection and fixes to indentation.
@@
expression bridge;
expression dev;
expression panel;
identifier type;
@@
(
-bridge = drm_panel_bridge_add(panel, type);
+bridge = drm_panel_bridge_add_typed(panel, type);
|
-bridge = devm_drm_panel_bridge_add(dev, panel, type);
+bridge = devm_drm_panel_bridge_add_typed(dev, panel, type);
)
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20190904132804.29680-3-laurent.pinchart@ideasonboard.com
2019-09-04 16:28:04 +03:00
struct drm_bridge * drm_panel_bridge_add ( struct drm_panel * panel )
{
if ( WARN_ON ( panel - > connector_type = = DRM_MODE_CONNECTOR_Unknown ) )
2020-04-17 00:06:54 +03:00
return ERR_PTR ( - EINVAL ) ;
drm/bridge: panel: Infer connector type from panel by default
The drm panel bridge creates a connector using a connector type
explicitly passed by the display controller or bridge driver that
instantiates the panel bridge. Now that drm_panel reports its connector
type, we can use it to avoid passing an explicit (and often incorrect)
connector type to drm_panel_bridge_add() and
devm_drm_panel_bridge_add().
Several drivers report incorrect or unknown connector types to
userspace. Reporting a different type may result in a breakage. For that
reason, rename (devm_)drm_panel_bridge_add() to
(devm_)drm_panel_bridge_add_typed(), and add new
(devm_)drm_panel_bridge_add() functions that use the panel connector
type. Update all callers of (devm_)drm_panel_bridge_add() to the _typed
function, they will be converted one by one after testing.
The panel drivers have been updated with the following Coccinelle
semantic patch, with manual inspection and fixes to indentation.
@@
expression bridge;
expression dev;
expression panel;
identifier type;
@@
(
-bridge = drm_panel_bridge_add(panel, type);
+bridge = drm_panel_bridge_add_typed(panel, type);
|
-bridge = devm_drm_panel_bridge_add(dev, panel, type);
+bridge = devm_drm_panel_bridge_add_typed(dev, panel, type);
)
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20190904132804.29680-3-laurent.pinchart@ideasonboard.com
2019-09-04 16:28:04 +03:00
return drm_panel_bridge_add_typed ( panel , panel - > connector_type ) ;
}
EXPORT_SYMBOL ( drm_panel_bridge_add ) ;
/**
* drm_panel_bridge_add_typed - Creates a & drm_bridge and & drm_connector with
* an explicit connector type .
* @ panel : The drm_panel being wrapped . Must be non - NULL .
* @ connector_type : The connector type ( DRM_MODE_CONNECTOR_ * )
*
* This is just like drm_panel_bridge_add ( ) , but forces the connector type to
* @ connector_type instead of infering it from the panel .
*
* This function is deprecated and should not be used in new drivers . Use
* drm_panel_bridge_add ( ) instead , and fix panel drivers as necessary if they
* don ' t report a connector type .
*/
struct drm_bridge * drm_panel_bridge_add_typed ( struct drm_panel * panel ,
u32 connector_type )
2017-06-02 23:25:14 +03:00
{
struct panel_bridge * panel_bridge ;
if ( ! panel )
2017-06-15 20:54:23 +03:00
return ERR_PTR ( - EINVAL ) ;
2017-06-02 23:25:14 +03:00
panel_bridge = devm_kzalloc ( panel - > dev , sizeof ( * panel_bridge ) ,
GFP_KERNEL ) ;
if ( ! panel_bridge )
return ERR_PTR ( - ENOMEM ) ;
panel_bridge - > connector_type = connector_type ;
panel_bridge - > panel = panel ;
panel_bridge - > bridge . funcs = & panel_bridge_bridge_funcs ;
# ifdef CONFIG_OF
panel_bridge - > bridge . of_node = panel - > dev - > of_node ;
# endif
2020-02-26 14:24:37 +03:00
panel_bridge - > bridge . ops = DRM_BRIDGE_OP_MODES ;
panel_bridge - > bridge . type = connector_type ;
2017-06-02 23:25:14 +03:00
2017-07-03 11:42:22 +03:00
drm_bridge_add ( & panel_bridge - > bridge ) ;
2017-06-02 23:25:14 +03:00
return & panel_bridge - > bridge ;
}
drm/bridge: panel: Infer connector type from panel by default
The drm panel bridge creates a connector using a connector type
explicitly passed by the display controller or bridge driver that
instantiates the panel bridge. Now that drm_panel reports its connector
type, we can use it to avoid passing an explicit (and often incorrect)
connector type to drm_panel_bridge_add() and
devm_drm_panel_bridge_add().
Several drivers report incorrect or unknown connector types to
userspace. Reporting a different type may result in a breakage. For that
reason, rename (devm_)drm_panel_bridge_add() to
(devm_)drm_panel_bridge_add_typed(), and add new
(devm_)drm_panel_bridge_add() functions that use the panel connector
type. Update all callers of (devm_)drm_panel_bridge_add() to the _typed
function, they will be converted one by one after testing.
The panel drivers have been updated with the following Coccinelle
semantic patch, with manual inspection and fixes to indentation.
@@
expression bridge;
expression dev;
expression panel;
identifier type;
@@
(
-bridge = drm_panel_bridge_add(panel, type);
+bridge = drm_panel_bridge_add_typed(panel, type);
|
-bridge = devm_drm_panel_bridge_add(dev, panel, type);
+bridge = devm_drm_panel_bridge_add_typed(dev, panel, type);
)
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20190904132804.29680-3-laurent.pinchart@ideasonboard.com
2019-09-04 16:28:04 +03:00
EXPORT_SYMBOL ( drm_panel_bridge_add_typed ) ;
2017-06-02 23:25:14 +03:00
/**
* drm_panel_bridge_remove - Unregisters and frees a drm_bridge
* created by drm_panel_bridge_add ( ) .
*
* @ bridge : The drm_bridge being freed .
*/
void drm_panel_bridge_remove ( struct drm_bridge * bridge )
{
2017-10-02 12:32:31 +03:00
struct panel_bridge * panel_bridge ;
if ( ! bridge )
return ;
if ( bridge - > funcs ! = & panel_bridge_bridge_funcs )
return ;
panel_bridge = drm_bridge_to_panel_bridge ( bridge ) ;
2017-06-02 23:25:14 +03:00
drm_bridge_remove ( bridge ) ;
devm_kfree ( panel_bridge - > panel - > dev , bridge ) ;
}
EXPORT_SYMBOL ( drm_panel_bridge_remove ) ;
2017-07-19 00:05:06 +03:00
2022-06-09 10:27:23 +03:00
/**
* drm_panel_bridge_set_orientation - Set the connector ' s panel orientation
* from the bridge that can be transformed to panel bridge .
*
* @ connector : The connector to be set panel orientation .
* @ bridge : The drm_bridge to be transformed to panel bridge .
*
* Returns 0 on success , negative errno on failure .
*/
int drm_panel_bridge_set_orientation ( struct drm_connector * connector ,
struct drm_bridge * bridge )
{
struct panel_bridge * panel_bridge ;
panel_bridge = drm_bridge_to_panel_bridge ( bridge ) ;
return drm_connector_set_orientation_from_panel ( connector ,
panel_bridge - > panel ) ;
}
EXPORT_SYMBOL ( drm_panel_bridge_set_orientation ) ;
2017-07-19 00:05:06 +03:00
static void devm_drm_panel_bridge_release ( struct device * dev , void * res )
{
struct drm_bridge * * bridge = res ;
drm_panel_bridge_remove ( * bridge ) ;
}
2019-01-11 19:40:46 +03:00
/**
* devm_drm_panel_bridge_add - Creates a managed & drm_bridge and & drm_connector
* that just calls the appropriate functions from & drm_panel .
* @ dev : device to tie the bridge lifetime to
* @ panel : The drm_panel being wrapped . Must be non - NULL .
*
* This is the managed version of drm_panel_bridge_add ( ) which automatically
* calls drm_panel_bridge_remove ( ) when @ dev is unbound .
*/
2017-07-19 00:05:06 +03:00
struct drm_bridge * devm_drm_panel_bridge_add ( struct device * dev ,
drm/bridge: panel: Infer connector type from panel by default
The drm panel bridge creates a connector using a connector type
explicitly passed by the display controller or bridge driver that
instantiates the panel bridge. Now that drm_panel reports its connector
type, we can use it to avoid passing an explicit (and often incorrect)
connector type to drm_panel_bridge_add() and
devm_drm_panel_bridge_add().
Several drivers report incorrect or unknown connector types to
userspace. Reporting a different type may result in a breakage. For that
reason, rename (devm_)drm_panel_bridge_add() to
(devm_)drm_panel_bridge_add_typed(), and add new
(devm_)drm_panel_bridge_add() functions that use the panel connector
type. Update all callers of (devm_)drm_panel_bridge_add() to the _typed
function, they will be converted one by one after testing.
The panel drivers have been updated with the following Coccinelle
semantic patch, with manual inspection and fixes to indentation.
@@
expression bridge;
expression dev;
expression panel;
identifier type;
@@
(
-bridge = drm_panel_bridge_add(panel, type);
+bridge = drm_panel_bridge_add_typed(panel, type);
|
-bridge = devm_drm_panel_bridge_add(dev, panel, type);
+bridge = devm_drm_panel_bridge_add_typed(dev, panel, type);
)
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20190904132804.29680-3-laurent.pinchart@ideasonboard.com
2019-09-04 16:28:04 +03:00
struct drm_panel * panel )
{
if ( WARN_ON ( panel - > connector_type = = DRM_MODE_CONNECTOR_Unknown ) )
2020-04-17 00:06:54 +03:00
return ERR_PTR ( - EINVAL ) ;
drm/bridge: panel: Infer connector type from panel by default
The drm panel bridge creates a connector using a connector type
explicitly passed by the display controller or bridge driver that
instantiates the panel bridge. Now that drm_panel reports its connector
type, we can use it to avoid passing an explicit (and often incorrect)
connector type to drm_panel_bridge_add() and
devm_drm_panel_bridge_add().
Several drivers report incorrect or unknown connector types to
userspace. Reporting a different type may result in a breakage. For that
reason, rename (devm_)drm_panel_bridge_add() to
(devm_)drm_panel_bridge_add_typed(), and add new
(devm_)drm_panel_bridge_add() functions that use the panel connector
type. Update all callers of (devm_)drm_panel_bridge_add() to the _typed
function, they will be converted one by one after testing.
The panel drivers have been updated with the following Coccinelle
semantic patch, with manual inspection and fixes to indentation.
@@
expression bridge;
expression dev;
expression panel;
identifier type;
@@
(
-bridge = drm_panel_bridge_add(panel, type);
+bridge = drm_panel_bridge_add_typed(panel, type);
|
-bridge = devm_drm_panel_bridge_add(dev, panel, type);
+bridge = devm_drm_panel_bridge_add_typed(dev, panel, type);
)
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20190904132804.29680-3-laurent.pinchart@ideasonboard.com
2019-09-04 16:28:04 +03:00
return devm_drm_panel_bridge_add_typed ( dev , panel ,
panel - > connector_type ) ;
}
EXPORT_SYMBOL ( devm_drm_panel_bridge_add ) ;
/**
* devm_drm_panel_bridge_add_typed - Creates a managed & drm_bridge and
* & drm_connector with an explicit connector type .
* @ dev : device to tie the bridge lifetime to
* @ panel : The drm_panel being wrapped . Must be non - NULL .
* @ connector_type : The connector type ( DRM_MODE_CONNECTOR_ * )
*
* This is just like devm_drm_panel_bridge_add ( ) , but forces the connector type
* to @ connector_type instead of infering it from the panel .
*
* This function is deprecated and should not be used in new drivers . Use
* devm_drm_panel_bridge_add ( ) instead , and fix panel drivers as necessary if
* they don ' t report a connector type .
*/
struct drm_bridge * devm_drm_panel_bridge_add_typed ( struct device * dev ,
struct drm_panel * panel ,
u32 connector_type )
2017-07-19 00:05:06 +03:00
{
struct drm_bridge * * ptr , * bridge ;
ptr = devres_alloc ( devm_drm_panel_bridge_release , sizeof ( * ptr ) ,
GFP_KERNEL ) ;
if ( ! ptr )
return ERR_PTR ( - ENOMEM ) ;
drm/bridge: panel: Infer connector type from panel by default
The drm panel bridge creates a connector using a connector type
explicitly passed by the display controller or bridge driver that
instantiates the panel bridge. Now that drm_panel reports its connector
type, we can use it to avoid passing an explicit (and often incorrect)
connector type to drm_panel_bridge_add() and
devm_drm_panel_bridge_add().
Several drivers report incorrect or unknown connector types to
userspace. Reporting a different type may result in a breakage. For that
reason, rename (devm_)drm_panel_bridge_add() to
(devm_)drm_panel_bridge_add_typed(), and add new
(devm_)drm_panel_bridge_add() functions that use the panel connector
type. Update all callers of (devm_)drm_panel_bridge_add() to the _typed
function, they will be converted one by one after testing.
The panel drivers have been updated with the following Coccinelle
semantic patch, with manual inspection and fixes to indentation.
@@
expression bridge;
expression dev;
expression panel;
identifier type;
@@
(
-bridge = drm_panel_bridge_add(panel, type);
+bridge = drm_panel_bridge_add_typed(panel, type);
|
-bridge = devm_drm_panel_bridge_add(dev, panel, type);
+bridge = devm_drm_panel_bridge_add_typed(dev, panel, type);
)
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20190904132804.29680-3-laurent.pinchart@ideasonboard.com
2019-09-04 16:28:04 +03:00
bridge = drm_panel_bridge_add_typed ( panel , connector_type ) ;
2023-01-02 15:01:23 +03:00
if ( IS_ERR ( bridge ) ) {
2017-07-19 00:05:06 +03:00
devres_free ( ptr ) ;
2023-01-02 15:01:23 +03:00
return bridge ;
2017-07-19 00:05:06 +03:00
}
2022-12-05 20:33:27 +03:00
bridge - > pre_enable_prev_first = panel - > prepare_prev_first ;
2023-01-02 15:01:23 +03:00
* ptr = bridge ;
devres_add ( dev , ptr ) ;
2017-07-19 00:05:06 +03:00
return bridge ;
}
drm/bridge: panel: Infer connector type from panel by default
The drm panel bridge creates a connector using a connector type
explicitly passed by the display controller or bridge driver that
instantiates the panel bridge. Now that drm_panel reports its connector
type, we can use it to avoid passing an explicit (and often incorrect)
connector type to drm_panel_bridge_add() and
devm_drm_panel_bridge_add().
Several drivers report incorrect or unknown connector types to
userspace. Reporting a different type may result in a breakage. For that
reason, rename (devm_)drm_panel_bridge_add() to
(devm_)drm_panel_bridge_add_typed(), and add new
(devm_)drm_panel_bridge_add() functions that use the panel connector
type. Update all callers of (devm_)drm_panel_bridge_add() to the _typed
function, they will be converted one by one after testing.
The panel drivers have been updated with the following Coccinelle
semantic patch, with manual inspection and fixes to indentation.
@@
expression bridge;
expression dev;
expression panel;
identifier type;
@@
(
-bridge = drm_panel_bridge_add(panel, type);
+bridge = drm_panel_bridge_add_typed(panel, type);
|
-bridge = devm_drm_panel_bridge_add(dev, panel, type);
+bridge = devm_drm_panel_bridge_add_typed(dev, panel, type);
)
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20190904132804.29680-3-laurent.pinchart@ideasonboard.com
2019-09-04 16:28:04 +03:00
EXPORT_SYMBOL ( devm_drm_panel_bridge_add_typed ) ;
2019-12-07 17:03:32 +03:00
2022-07-11 20:38:40 +03:00
static void drmm_drm_panel_bridge_release ( struct drm_device * drm , void * ptr )
{
struct drm_bridge * bridge = ptr ;
drm_panel_bridge_remove ( bridge ) ;
}
/**
* drmm_panel_bridge_add - Creates a DRM - managed & drm_bridge and
* & drm_connector that just calls the
* appropriate functions from & drm_panel .
*
* @ drm : DRM device to tie the bridge lifetime to
* @ panel : The drm_panel being wrapped . Must be non - NULL .
*
* This is the DRM - managed version of drm_panel_bridge_add ( ) which
* automatically calls drm_panel_bridge_remove ( ) when @ dev is cleaned
* up .
*/
struct drm_bridge * drmm_panel_bridge_add ( struct drm_device * drm ,
struct drm_panel * panel )
{
struct drm_bridge * bridge ;
int ret ;
bridge = drm_panel_bridge_add_typed ( panel , panel - > connector_type ) ;
if ( IS_ERR ( bridge ) )
return bridge ;
ret = drmm_add_action_or_reset ( drm , drmm_drm_panel_bridge_release ,
bridge ) ;
if ( ret )
return ERR_PTR ( ret ) ;
2022-12-22 21:52:13 +03:00
bridge - > pre_enable_prev_first = panel - > prepare_prev_first ;
2022-07-11 20:38:40 +03:00
return bridge ;
}
EXPORT_SYMBOL ( drmm_panel_bridge_add ) ;
2019-12-07 17:03:32 +03:00
/**
* drm_panel_bridge_connector - return the connector for the panel bridge
2020-03-28 16:20:25 +03:00
* @ bridge : The drm_bridge .
2019-12-07 17:03:32 +03:00
*
* drm_panel_bridge creates the connector .
* This function gives external access to the connector .
*
* Returns : Pointer to drm_connector
*/
struct drm_connector * drm_panel_bridge_connector ( struct drm_bridge * bridge )
{
struct panel_bridge * panel_bridge ;
panel_bridge = drm_bridge_to_panel_bridge ( bridge ) ;
return & panel_bridge - > connector ;
}
2019-12-10 17:48:49 +03:00
EXPORT_SYMBOL ( drm_panel_bridge_connector ) ;
2021-09-17 21:09:25 +03:00
# ifdef CONFIG_OF
/**
* devm_drm_of_get_bridge - Return next bridge in the chain
* @ dev : device to tie the bridge lifetime to
* @ np : device tree node containing encoder output ports
* @ port : port in the device tree node
* @ endpoint : endpoint in the device tree node
*
* Given a DT node ' s port and endpoint number , finds the connected node
* and returns the associated bridge if any , or creates and returns a
* drm panel bridge instance if a panel is connected .
*
* Returns a pointer to the bridge if successful , or an error pointer
* otherwise .
*/
struct drm_bridge * devm_drm_of_get_bridge ( struct device * dev ,
struct device_node * np ,
u32 port , u32 endpoint )
{
struct drm_bridge * bridge ;
struct drm_panel * panel ;
int ret ;
ret = drm_of_find_panel_or_bridge ( np , port , endpoint ,
& panel , & bridge ) ;
if ( ret )
return ERR_PTR ( ret ) ;
if ( panel )
bridge = devm_drm_panel_bridge_add ( dev , panel ) ;
return bridge ;
}
EXPORT_SYMBOL ( devm_drm_of_get_bridge ) ;
2022-07-11 20:38:41 +03:00
/**
* drmm_of_get_bridge - Return next bridge in the chain
* @ drm : device to tie the bridge lifetime to
* @ np : device tree node containing encoder output ports
* @ port : port in the device tree node
* @ endpoint : endpoint in the device tree node
*
* Given a DT node ' s port and endpoint number , finds the connected node
* and returns the associated bridge if any , or creates and returns a
* drm panel bridge instance if a panel is connected .
*
* Returns a drmm managed pointer to the bridge if successful , or an error
* pointer otherwise .
*/
struct drm_bridge * drmm_of_get_bridge ( struct drm_device * drm ,
struct device_node * np ,
u32 port , u32 endpoint )
{
struct drm_bridge * bridge ;
struct drm_panel * panel ;
int ret ;
ret = drm_of_find_panel_or_bridge ( np , port , endpoint ,
& panel , & bridge ) ;
if ( ret )
return ERR_PTR ( ret ) ;
if ( panel )
bridge = drmm_panel_bridge_add ( drm , panel ) ;
return bridge ;
}
EXPORT_SYMBOL ( drmm_of_get_bridge ) ;
2021-09-17 21:09:25 +03:00
# endif