drm/sun4i: Add bridge support
authorMaxime Ripard <maxime.ripard@free-electrons.com>
Mon, 11 Apr 2016 10:16:33 +0000 (12:16 +0200)
committerMaxime Ripard <maxime.ripard@free-electrons.com>
Mon, 22 Aug 2016 13:34:18 +0000 (15:34 +0200)
Our RGB bus can be either connected to a bridge or a panel. While the panel
support was already there, the bridge was not.

Fix that.

Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
drivers/gpu/drm/sun4i/sun4i_drv.c
drivers/gpu/drm/sun4i/sun4i_rgb.c
drivers/gpu/drm/sun4i/sun4i_tcon.c
drivers/gpu/drm/sun4i/sun4i_tcon.h

index 7092daaf6c432b8fa8d2bb93bda63785cf307f01..942f62e2441c2a560fd1f0d9ae743701cdb29377 100644 (file)
@@ -257,8 +257,8 @@ static int sun4i_drv_add_endpoints(struct device *dev,
                }
 
                /*
-                * If the node is our TCON, the first port is used for our
-                * panel, and will not be part of the
+                * If the node is our TCON, the first port is used for
+                * panel or bridges, and will not be part of the
                 * component framework.
                 */
                if (sun4i_drv_node_is_tcon(node)) {
index d32f08f9ce5f48db04e81e2ed92f94103bb82d62..d4e52522ec531bff8d9f02dbfd4dd73d7dff1107 100644 (file)
@@ -151,7 +151,12 @@ static void sun4i_rgb_encoder_enable(struct drm_encoder *encoder)
 
        DRM_DEBUG_DRIVER("Enabling RGB output\n");
 
-       drm_panel_enable(tcon->panel);
+       if (!IS_ERR(tcon->panel))
+               drm_panel_enable(tcon->panel);
+
+       if (!IS_ERR(encoder->bridge))
+               drm_bridge_enable(encoder->bridge);
+
        sun4i_tcon_channel_enable(tcon, 0);
 }
 
@@ -164,7 +169,12 @@ static void sun4i_rgb_encoder_disable(struct drm_encoder *encoder)
        DRM_DEBUG_DRIVER("Disabling RGB output\n");
 
        sun4i_tcon_channel_disable(tcon, 0);
-       drm_panel_disable(tcon->panel);
+
+       if (!IS_ERR(encoder->bridge))
+               drm_bridge_disable(encoder->bridge);
+
+       if (!IS_ERR(tcon->panel))
+               drm_panel_disable(tcon->panel);
 }
 
 static void sun4i_rgb_encoder_mode_set(struct drm_encoder *encoder,
@@ -203,6 +213,7 @@ int sun4i_rgb_init(struct drm_device *drm)
 {
        struct sun4i_drv *drv = drm->dev_private;
        struct sun4i_tcon *tcon = drv->tcon;
+       struct drm_encoder *encoder;
        struct sun4i_rgb *rgb;
        int ret;
 
@@ -210,10 +221,12 @@ int sun4i_rgb_init(struct drm_device *drm)
        if (!rgb)
                return -ENOMEM;
        rgb->drv = drv;
+       encoder = &rgb->encoder;
 
        tcon->panel = sun4i_tcon_find_panel(tcon->dev->of_node);
-       if (IS_ERR(tcon->panel)) {
-               dev_info(drm->dev, "No panel found... RGB output disabled\n");
+       encoder->bridge = sun4i_tcon_find_bridge(tcon->dev->of_node);
+       if (IS_ERR(tcon->panel) && IS_ERR(encoder->bridge)) {
+               dev_info(drm->dev, "No panel or bridge found... RGB output disabled\n");
                return 0;
        }
 
@@ -232,19 +245,36 @@ int sun4i_rgb_init(struct drm_device *drm)
        /* The RGB encoder can only work with the TCON channel 0 */
        rgb->encoder.possible_crtcs = BIT(0);
 
-       drm_connector_helper_add(&rgb->connector,
-                                &sun4i_rgb_con_helper_funcs);
-       ret = drm_connector_init(drm, &rgb->connector,
-                                &sun4i_rgb_con_funcs,
-                                DRM_MODE_CONNECTOR_Unknown);
-       if (ret) {
-               dev_err(drm->dev, "Couldn't initialise the rgb connector\n");
-               goto err_cleanup_connector;
+       if (!IS_ERR(tcon->panel)) {
+               drm_connector_helper_add(&rgb->connector,
+                                        &sun4i_rgb_con_helper_funcs);
+               ret = drm_connector_init(drm, &rgb->connector,
+                                        &sun4i_rgb_con_funcs,
+                                        DRM_MODE_CONNECTOR_Unknown);
+               if (ret) {
+                       dev_err(drm->dev, "Couldn't initialise the rgb connector\n");
+                       goto err_cleanup_connector;
+               }
+
+               drm_mode_connector_attach_encoder(&rgb->connector,
+                                                 &rgb->encoder);
+
+               ret = drm_panel_attach(tcon->panel, &rgb->connector);
+               if (ret) {
+                       dev_err(drm->dev, "Couldn't attach our panel\n");
+                       goto err_cleanup_connector;
+               }
        }
 
-       drm_mode_connector_attach_encoder(&rgb->connector, &rgb->encoder);
+       if (!IS_ERR(encoder->bridge)) {
+               encoder->bridge->encoder = &rgb->encoder;
 
-       drm_panel_attach(tcon->panel, &rgb->connector);
+               ret = drm_bridge_attach(drm, encoder->bridge);
+               if (ret) {
+                       dev_err(drm->dev, "Couldn't attach our bridge\n");
+                       goto err_cleanup_connector;
+               }
+       }
 
        return 0;
 
index d2f7489d29a5a2d2e9a4f22e8c940e9d75602d6c..2145ecf2cf5d9b983186f2331c0feac32fbf1bc5 100644 (file)
@@ -432,6 +432,40 @@ struct drm_panel *sun4i_tcon_find_panel(struct device_node *node)
        return of_drm_find_panel(remote) ?: ERR_PTR(-EPROBE_DEFER);
 }
 
+struct drm_bridge *sun4i_tcon_find_bridge(struct device_node *node)
+{
+       struct device_node *port, *remote, *child;
+       struct device_node *end_node = NULL;
+
+       /* Inputs are listed first, then outputs */
+       port = of_graph_get_port_by_id(node, 1);
+
+       /*
+        * Our first output is the RGB interface where the panel will
+        * be connected.
+        */
+       for_each_child_of_node(port, child) {
+               u32 reg;
+
+               of_property_read_u32(child, "reg", &reg);
+               if (reg == 0)
+                       end_node = child;
+       }
+
+       if (!end_node) {
+               DRM_DEBUG_DRIVER("Missing bridge endpoint\n");
+               return ERR_PTR(-ENODEV);
+       }
+
+       remote = of_graph_get_remote_port_parent(end_node);
+       if (!remote) {
+               DRM_DEBUG_DRIVER("Enable to parse remote node\n");
+               return ERR_PTR(-EINVAL);
+       }
+
+       return of_drm_find_bridge(remote) ?: ERR_PTR(-EPROBE_DEFER);
+}
+
 static int sun4i_tcon_bind(struct device *dev, struct device *master,
                           void *data)
 {
@@ -514,19 +548,22 @@ static struct component_ops sun4i_tcon_ops = {
 static int sun4i_tcon_probe(struct platform_device *pdev)
 {
        struct device_node *node = pdev->dev.of_node;
+       struct drm_bridge *bridge;
        struct drm_panel *panel;
 
        /*
-        * The panel is not ready.
+        * Neither the bridge or the panel is ready.
         * Defer the probe.
         */
        panel = sun4i_tcon_find_panel(node);
+       bridge = sun4i_tcon_find_bridge(node);
 
        /*
         * If we don't have a panel endpoint, just go on
         */
-       if (PTR_ERR(panel) == -EPROBE_DEFER) {
-               DRM_DEBUG_DRIVER("Still waiting for our panel. Deferring...\n");
+       if ((PTR_ERR(panel) == -EPROBE_DEFER) &&
+           (PTR_ERR(bridge) == -EPROBE_DEFER)) {
+               DRM_DEBUG_DRIVER("Still waiting for our panel/bridge. Deferring...\n");
                return -EPROBE_DEFER;
        }
 
index 4f81d86ee5a41a6855c984d4968b36d7e4f3f842..100bfa093277952aca9392ca58999e1480656a91 100644 (file)
@@ -166,6 +166,7 @@ struct sun4i_tcon {
        struct drm_panel                *panel;
 };
 
+struct drm_bridge *sun4i_tcon_find_bridge(struct device_node *node);
 struct drm_panel *sun4i_tcon_find_panel(struct device_node *node);
 
 /* Global Control */