Skip to content

Commit 5e41b01

Browse files
hsinyi527dianders
authored andcommitted
drm/panel: Add an API to allow drm to set orientation from panel
Panels usually call drm_connector_set_panel_orientation(), which is later than drm/kms driver calling drm_dev_register(). This leads to a WARN(). The orientation property is known earlier. For example, some panels parse the property through device tree during probe. Add an API to return the property from panel to drm/kms driver, so the drivers are able to call drm_connector_set_orientation_from_panel() before drm_dev_register(). Suggested-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Hsin-Yi Wang <hsinyi@chromium.org> Reviewed-by: Hans de Goede <hdegoede@redhat.com> Reviewed-by: Douglas Anderson <dianders@chromium.org> Reviewed-by: Stephen Boyd <swboyd@chromium.org> [dianders: removed space before tab] Signed-off-by: Douglas Anderson <dianders@chromium.org> Link: https://patchwork.freedesktop.org/patch/msgid/20220609072722.3488207-2-hsinyi@chromium.org
1 parent fb84efa commit 5e41b01

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

drivers/gpu/drm/drm_connector.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <drm/drm_connector.h>
2525
#include <drm/drm_edid.h>
2626
#include <drm/drm_encoder.h>
27+
#include <drm/drm_panel.h>
2728
#include <drm/drm_utils.h>
2829
#include <drm/drm_print.h>
2930
#include <drm/drm_drv.h>
@@ -2320,6 +2321,9 @@ EXPORT_SYMBOL(drm_connector_set_vrr_capable_property);
23202321
* It is allowed to call this function with a panel_orientation of
23212322
* DRM_MODE_PANEL_ORIENTATION_UNKNOWN, in which case it is a no-op.
23222323
*
2324+
* The function shouldn't be called in panel after drm is registered (i.e.
2325+
* drm_dev_register() is called in drm).
2326+
*
23232327
* Returns:
23242328
* Zero on success, negative errno on failure.
23252329
*/
@@ -2389,6 +2393,33 @@ int drm_connector_set_panel_orientation_with_quirk(
23892393
}
23902394
EXPORT_SYMBOL(drm_connector_set_panel_orientation_with_quirk);
23912395

2396+
/**
2397+
* drm_connector_set_orientation_from_panel -
2398+
* set the connector's panel_orientation from panel's callback.
2399+
* @connector: connector for which to init the panel-orientation property.
2400+
* @panel: panel that can provide orientation information.
2401+
*
2402+
* Drm drivers should call this function before drm_dev_register().
2403+
* Orientation is obtained from panel's .get_orientation() callback.
2404+
*
2405+
* Returns:
2406+
* Zero on success, negative errno on failure.
2407+
*/
2408+
int drm_connector_set_orientation_from_panel(
2409+
struct drm_connector *connector,
2410+
struct drm_panel *panel)
2411+
{
2412+
enum drm_panel_orientation orientation;
2413+
2414+
if (panel && panel->funcs && panel->funcs->get_orientation)
2415+
orientation = panel->funcs->get_orientation(panel);
2416+
else
2417+
orientation = DRM_MODE_PANEL_ORIENTATION_UNKNOWN;
2418+
2419+
return drm_connector_set_panel_orientation(connector, orientation);
2420+
}
2421+
EXPORT_SYMBOL(drm_connector_set_orientation_from_panel);
2422+
23922423
static const struct drm_prop_enum_list privacy_screen_enum[] = {
23932424
{ PRIVACY_SCREEN_DISABLED, "Disabled" },
23942425
{ PRIVACY_SCREEN_ENABLED, "Enabled" },

include/drm/drm_connector.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ struct drm_modeset_acquire_ctx;
3838
struct drm_device;
3939
struct drm_crtc;
4040
struct drm_encoder;
41+
struct drm_panel;
4142
struct drm_property;
4243
struct drm_property_blob;
4344
struct drm_printer;
@@ -1802,6 +1803,9 @@ int drm_connector_set_panel_orientation_with_quirk(
18021803
struct drm_connector *connector,
18031804
enum drm_panel_orientation panel_orientation,
18041805
int width, int height);
1806+
int drm_connector_set_orientation_from_panel(
1807+
struct drm_connector *connector,
1808+
struct drm_panel *panel);
18051809
int drm_connector_attach_max_bpc_property(struct drm_connector *connector,
18061810
int min, int max);
18071811
void drm_connector_create_privacy_screen_properties(struct drm_connector *conn);

include/drm/drm_panel.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,15 @@ struct drm_panel_funcs {
116116
int (*get_modes)(struct drm_panel *panel,
117117
struct drm_connector *connector);
118118

119+
/**
120+
* @get_orientation:
121+
*
122+
* Return the panel orientation set by device tree or EDID.
123+
*
124+
* This function is optional.
125+
*/
126+
enum drm_panel_orientation (*get_orientation)(struct drm_panel *panel);
127+
119128
/**
120129
* @get_timings:
121130
*

0 commit comments

Comments
 (0)