diff mbox series

[v6,8/8] drm: Config orientation property if panel provides it

Message ID 20220608094816.2898692-9-hsinyi@chromium.org (mailing list archive)
State New, archived
Headers show
Series Add a panel API to set orientation properly | expand

Commit Message

Hsin-Yi Wang June 8, 2022, 9:48 a.m. UTC
Panel orientation property should be set before drm_dev_register().
Some drm driver calls drm_dev_register() in .bind(). However, most
panels sets orientation property relatively late, mostly in .get_modes()
callback, since this is when they are able to get the connector and
binds the orientation property to it, though the value should be known
when the panel is probed.

In drm_bridge_connector_init(), if a bridge is a panel bridge, use it to
set the connector's panel orientation property.

Suggested-by: Doug Anderson <dianders@chromium.org>
Signed-off-by: Hsin-Yi Wang <hsinyi@chromium.org>
---
v5->v6:
mtk_dsi is using panel bridge, we don't need to obtain the panel in
mtk_dsi. Instead, drm_connector_set_orientation_from_panel() can be
called from drm_bridge_connector_init().
---
 drivers/gpu/drm/bridge/panel.c         | 36 ++++++++++++++++++++++++++
 drivers/gpu/drm/drm_bridge_connector.c |  8 +++++-
 include/drm/drm_bridge.h               |  3 +++
 3 files changed, 46 insertions(+), 1 deletion(-)

Comments

Doug Anderson June 8, 2022, 2:16 p.m. UTC | #1
Hi,

On Wed, Jun 8, 2022 at 2:48 AM Hsin-Yi Wang <hsinyi@chromium.org> wrote:
>
> @@ -269,6 +280,31 @@ void drm_panel_bridge_remove(struct drm_bridge *bridge)
>  }
>  EXPORT_SYMBOL(drm_panel_bridge_remove);
>
> +/**
> + * drm_panel_bridge_set_orientation - Set the connector's panel orientation
> + * if the bridge is a panel bridge.
> + *
> + * @connector: The connector to be set panel orientation.
> + * @bridge: The drm_bridge to be transformed to panel bridge.

Ideally you should have a kernel doc to describe what you're returning.


> + */
> +int drm_panel_bridge_set_orientation(struct drm_connector *connector,
> +                                    struct drm_bridge *bridge)
> +{
> +       struct panel_bridge *panel_bridge;
> +
> +       if (!bridge)
> +               return 0;
> +
> +       if (bridge->funcs != &panel_bridge_bridge_funcs)
> +               return 0;

nit: Why do you need to handle NULL bridge and the case that someone
calls you with something other than a panel-bridge? I'm not convinced
that's useful. In general kernel style doesn't do massive validation
of parameters unless there's a reason for it. ...if we do need to
handle them then it feels like they should be returning -EINVAL or
something, not 0.


> @@ -917,10 +917,13 @@ void drm_bridge_hpd_notify(struct drm_bridge *bridge,
>                            enum drm_connector_status status);
>
>  #ifdef CONFIG_DRM_PANEL_BRIDGE
> +bool drm_bridge_is_panel(const struct drm_bridge *bridge);
>  struct drm_bridge *drm_panel_bridge_add(struct drm_panel *panel);
>  struct drm_bridge *drm_panel_bridge_add_typed(struct drm_panel *panel,
>                                               u32 connector_type);
>  void drm_panel_bridge_remove(struct drm_bridge *bridge);
> +int drm_panel_bridge_set_orientation(struct drm_connector *connector,
> +                                     struct drm_bridge *bridge);

I suspect that you need some dummy versions of your new functions
defined if "CONFIG_DRM_PANEL_BRIDGE" is not defined. Otherwise we're
going to be yelled at by the kernel robot eventually.

-Doug
Hsin-Yi Wang June 9, 2022, 3:13 a.m. UTC | #2
On Wed, Jun 8, 2022 at 10:17 PM Doug Anderson <dianders@chromium.org> wrote:
>
> Hi,
>
> On Wed, Jun 8, 2022 at 2:48 AM Hsin-Yi Wang <hsinyi@chromium.org> wrote:
> >
> > @@ -269,6 +280,31 @@ void drm_panel_bridge_remove(struct drm_bridge *bridge)
> >  }
> >  EXPORT_SYMBOL(drm_panel_bridge_remove);
> >
> > +/**
> > + * drm_panel_bridge_set_orientation - Set the connector's panel orientation
> > + * if the bridge is a panel bridge.
> > + *
> > + * @connector: The connector to be set panel orientation.
> > + * @bridge: The drm_bridge to be transformed to panel bridge.
>
> Ideally you should have a kernel doc to describe what you're returning.
>
>
> > + */
> > +int drm_panel_bridge_set_orientation(struct drm_connector *connector,
> > +                                    struct drm_bridge *bridge)
> > +{
> > +       struct panel_bridge *panel_bridge;
> > +
> > +       if (!bridge)
> > +               return 0;
> > +
> > +       if (bridge->funcs != &panel_bridge_bridge_funcs)
> > +               return 0;
>
> nit: Why do you need to handle NULL bridge and the case that someone
> calls you with something other than a panel-bridge? I'm not convinced
> that's useful. In general kernel style doesn't do massive validation
> of parameters unless there's a reason for it. ...if we do need to
> handle them then it feels like they should be returning -EINVAL or
> something, not 0.

The only caller had checked it. I can remove the check here.

>
>
> > @@ -917,10 +917,13 @@ void drm_bridge_hpd_notify(struct drm_bridge *bridge,
> >                            enum drm_connector_status status);
> >
> >  #ifdef CONFIG_DRM_PANEL_BRIDGE
> > +bool drm_bridge_is_panel(const struct drm_bridge *bridge);
> >  struct drm_bridge *drm_panel_bridge_add(struct drm_panel *panel);
> >  struct drm_bridge *drm_panel_bridge_add_typed(struct drm_panel *panel,
> >                                               u32 connector_type);
> >  void drm_panel_bridge_remove(struct drm_bridge *bridge);
> > +int drm_panel_bridge_set_orientation(struct drm_connector *connector,
> > +                                     struct drm_bridge *bridge);
>
> I suspect that you need some dummy versions of your new functions
> defined if "CONFIG_DRM_PANEL_BRIDGE" is not defined. Otherwise we're
> going to be yelled at by the kernel robot eventually.
>
> -Doug
diff mbox series

Patch

diff --git a/drivers/gpu/drm/bridge/panel.c b/drivers/gpu/drm/bridge/panel.c
index 0ee563eb2b6f..53c98cba719b 100644
--- a/drivers/gpu/drm/bridge/panel.c
+++ b/drivers/gpu/drm/bridge/panel.c
@@ -170,6 +170,17 @@  static const struct drm_bridge_funcs panel_bridge_bridge_funcs = {
 	.debugfs_init = panel_bridge_debugfs_init,
 };
 
+/**
+ * drm_bridge_is_panel - Checks if a drm_bridge is a panel_bridge.
+ *
+ * @bridge: The drm_bridge to be checked.
+ */
+bool drm_bridge_is_panel(const struct drm_bridge *bridge)
+{
+	return bridge->funcs == &panel_bridge_bridge_funcs;
+}
+EXPORT_SYMBOL(drm_bridge_is_panel);
+
 /**
  * drm_panel_bridge_add - Creates a &drm_bridge and &drm_connector that
  * just calls the appropriate functions from &drm_panel.
@@ -269,6 +280,31 @@  void drm_panel_bridge_remove(struct drm_bridge *bridge)
 }
 EXPORT_SYMBOL(drm_panel_bridge_remove);
 
+/**
+ * drm_panel_bridge_set_orientation - Set the connector's panel orientation
+ * if the bridge is a panel bridge.
+ *
+ * @connector: The connector to be set panel orientation.
+ * @bridge: The drm_bridge to be transformed to panel bridge.
+ */
+int drm_panel_bridge_set_orientation(struct drm_connector *connector,
+				     struct drm_bridge *bridge)
+{
+	struct panel_bridge *panel_bridge;
+
+	if (!bridge)
+		return 0;
+
+	if (bridge->funcs != &panel_bridge_bridge_funcs)
+		return 0;
+
+	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);
+
 static void devm_drm_panel_bridge_release(struct device *dev, void *res)
 {
 	struct drm_bridge **bridge = res;
diff --git a/drivers/gpu/drm/drm_bridge_connector.c b/drivers/gpu/drm/drm_bridge_connector.c
index 6b3dad03d77d..1c7d936523df 100644
--- a/drivers/gpu/drm/drm_bridge_connector.c
+++ b/drivers/gpu/drm/drm_bridge_connector.c
@@ -331,7 +331,7 @@  struct drm_connector *drm_bridge_connector_init(struct drm_device *drm,
 	struct drm_bridge_connector *bridge_connector;
 	struct drm_connector *connector;
 	struct i2c_adapter *ddc = NULL;
-	struct drm_bridge *bridge;
+	struct drm_bridge *bridge, *panel_bridge = NULL;
 	int connector_type;
 
 	bridge_connector = kzalloc(sizeof(*bridge_connector), GFP_KERNEL);
@@ -373,6 +373,9 @@  struct drm_connector *drm_bridge_connector_init(struct drm_device *drm,
 
 		if (bridge->ddc)
 			ddc = bridge->ddc;
+
+		if (drm_bridge_is_panel(bridge))
+			panel_bridge = bridge;
 	}
 
 	if (connector_type == DRM_MODE_CONNECTOR_Unknown) {
@@ -392,6 +395,9 @@  struct drm_connector *drm_bridge_connector_init(struct drm_device *drm,
 		connector->polled = DRM_CONNECTOR_POLL_CONNECT
 				  | DRM_CONNECTOR_POLL_DISCONNECT;
 
+	if (panel_bridge)
+		drm_panel_bridge_set_orientation(connector, panel_bridge);
+
 	return connector;
 }
 EXPORT_SYMBOL_GPL(drm_bridge_connector_init);
diff --git a/include/drm/drm_bridge.h b/include/drm/drm_bridge.h
index f27b4060faa2..b0691d728139 100644
--- a/include/drm/drm_bridge.h
+++ b/include/drm/drm_bridge.h
@@ -917,10 +917,13 @@  void drm_bridge_hpd_notify(struct drm_bridge *bridge,
 			   enum drm_connector_status status);
 
 #ifdef CONFIG_DRM_PANEL_BRIDGE
+bool drm_bridge_is_panel(const struct drm_bridge *bridge);
 struct drm_bridge *drm_panel_bridge_add(struct drm_panel *panel);
 struct drm_bridge *drm_panel_bridge_add_typed(struct drm_panel *panel,
 					      u32 connector_type);
 void drm_panel_bridge_remove(struct drm_bridge *bridge);
+int drm_panel_bridge_set_orientation(struct drm_connector *connector,
+                                     struct drm_bridge *bridge);
 struct drm_bridge *devm_drm_panel_bridge_add(struct device *dev,
 					     struct drm_panel *panel);
 struct drm_bridge *devm_drm_panel_bridge_add_typed(struct device *dev,