]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - drivers/gpu/drm/stm/ltdc.c
drm/stm: ltdc: Cleanup signal polarity defines
[mirror_ubuntu-bionic-kernel.git] / drivers / gpu / drm / stm / ltdc.c
index 1b9483d4f2a4ec3b80dea15acdd38ca730733381..50e8a896b0ed5ef7e89fff167edec7a162c539c7 100644 (file)
@@ -21,7 +21,7 @@
 #include <drm/drm_fb_cma_helper.h>
 #include <drm/drm_gem_cma_helper.h>
 #include <drm/drm_of.h>
-#include <drm/drm_panel.h>
+#include <drm/drm_bridge.h>
 #include <drm/drm_plane_helper.h>
 
 #include <video/videomode.h>
 
 #define GCR_LTDCEN     BIT(0)          /* LTDC ENable */
 #define GCR_DEN                BIT(16)         /* Dither ENable */
-#define GCR_PCPOL      BIT(28)         /* Pixel Clock POLarity */
-#define GCR_DEPOL      BIT(29)         /* Data Enable POLarity */
-#define GCR_VSPOL      BIT(30)         /* Vertical Synchro POLarity */
-#define GCR_HSPOL      BIT(31)         /* Horizontal Synchro POLarity */
+#define GCR_PCPOL      BIT(28)         /* Pixel Clock POLarity-Inverted */
+#define GCR_DEPOL      BIT(29)         /* Data Enable POLarity-High */
+#define GCR_VSPOL      BIT(30)         /* Vertical Synchro POLarity-High */
+#define GCR_HSPOL      BIT(31)         /* Horizontal Synchro POLarity-High */
 
 #define GC1R_WBCH      GENMASK(3, 0)   /* Width of Blue CHannel output */
 #define GC1R_WGCH      GENMASK(7, 4)   /* Width of Green Channel output */
 
 #define LXCFBLNR_CFBLN GENMASK(10, 0)   /* Color Frame Buffer Line Number */
 
-#define HSPOL_AL   0           /* Horizontal Sync POLarity Active Low */
-#define VSPOL_AL   0           /* Vertical Sync POLarity Active Low */
-#define DEPOL_AL   0           /* Data Enable POLarity Active Low */
-#define PCPOL_IPC  0           /* Input Pixel Clock */
-#define HSPOL_AH   GCR_HSPOL   /* Horizontal Sync POLarity Active High */
-#define VSPOL_AH   GCR_VSPOL   /* Vertical Sync POLarity Active High */
-#define DEPOL_AH   GCR_DEPOL   /* Data Enable POLarity Active High */
-#define PCPOL_IIPC GCR_PCPOL   /* Inverted Input Pixel Clock */
 #define CONSTA_MAX 0xFF                /* CONSTant Alpha MAX= 1.0 */
 #define BF1_PAXCA  0x600       /* Pixel Alpha x Constant Alpha */
 #define BF1_CA     0x400       /* Constant Alpha */
@@ -269,11 +261,6 @@ static inline struct ltdc_device *encoder_to_ltdc(struct drm_encoder *enc)
        return (struct ltdc_device *)enc->dev->dev_private;
 }
 
-static inline struct ltdc_device *connector_to_ltdc(struct drm_connector *con)
-{
-       return (struct ltdc_device *)con->dev->dev_private;
-}
-
 static inline enum ltdc_pix_fmt to_ltdc_pixelformat(u32 drm_fmt)
 {
        enum ltdc_pix_fmt pf;
@@ -386,7 +373,8 @@ static void ltdc_crtc_load_lut(struct drm_crtc *crtc)
                                  ldev->clut[i]);
 }
 
-static void ltdc_crtc_enable(struct drm_crtc *crtc)
+static void ltdc_crtc_atomic_enable(struct drm_crtc *crtc,
+                                   struct drm_crtc_state *old_state)
 {
        struct ltdc_device *ldev = crtc_to_ltdc(crtc);
 
@@ -407,7 +395,8 @@ static void ltdc_crtc_enable(struct drm_crtc *crtc)
        drm_crtc_vblank_on(crtc);
 }
 
-static void ltdc_crtc_disable(struct drm_crtc *crtc)
+static void ltdc_crtc_atomic_disable(struct drm_crtc *crtc,
+                                    struct drm_crtc_state *old_state)
 {
        struct ltdc_device *ldev = crtc_to_ltdc(crtc);
 
@@ -462,20 +451,20 @@ static void ltdc_crtc_mode_set_nofb(struct drm_crtc *crtc)
 
        clk_enable(ldev->pixel_clk);
 
-       /* Configures the HS, VS, DE and PC polarities. */
-       val = HSPOL_AL | VSPOL_AL | DEPOL_AL | PCPOL_IPC;
+       /* Configures the HS, VS, DE and PC polarities. Default Active Low */
+       val = 0;
 
        if (vm.flags & DISPLAY_FLAGS_HSYNC_HIGH)
-               val |= HSPOL_AH;
+               val |= GCR_HSPOL;
 
        if (vm.flags & DISPLAY_FLAGS_VSYNC_HIGH)
-               val |= VSPOL_AH;
+               val |= GCR_VSPOL;
 
        if (vm.flags & DISPLAY_FLAGS_DE_HIGH)
-               val |= DEPOL_AH;
+               val |= GCR_DEPOL;
 
        if (vm.flags & DISPLAY_FLAGS_PIXDATA_NEGEDGE)
-               val |= PCPOL_IIPC;
+               val |= GCR_PCPOL;
 
        reg_update_bits(ldev->regs, LTDC_GCR,
                        GCR_HSPOL | GCR_VSPOL | GCR_DEPOL | GCR_PCPOL, val);
@@ -524,10 +513,10 @@ static void ltdc_crtc_atomic_flush(struct drm_crtc *crtc,
 
 static struct drm_crtc_helper_funcs ltdc_crtc_helper_funcs = {
        .load_lut = ltdc_crtc_load_lut,
-       .enable = ltdc_crtc_enable,
-       .disable = ltdc_crtc_disable,
        .mode_set_nofb = ltdc_crtc_mode_set_nofb,
        .atomic_flush = ltdc_crtc_atomic_flush,
+       .atomic_enable = ltdc_crtc_atomic_enable,
+       .atomic_disable = ltdc_crtc_atomic_disable,
 };
 
 int ltdc_crtc_enable_vblank(struct drm_device *ddev, unsigned int pipe)
@@ -813,130 +802,35 @@ cleanup:
  * DRM_ENCODER
  */
 
-static void ltdc_rgb_encoder_enable(struct drm_encoder *encoder)
-{
-       struct ltdc_device *ldev = encoder_to_ltdc(encoder);
-
-       DRM_DEBUG_DRIVER("\n");
-
-       drm_panel_prepare(ldev->panel);
-       drm_panel_enable(ldev->panel);
-}
-
-static void ltdc_rgb_encoder_disable(struct drm_encoder *encoder)
-{
-       struct ltdc_device *ldev = encoder_to_ltdc(encoder);
-
-       DRM_DEBUG_DRIVER("\n");
-
-       drm_panel_disable(ldev->panel);
-       drm_panel_unprepare(ldev->panel);
-}
-
-static const struct drm_encoder_helper_funcs ltdc_rgb_encoder_helper_funcs = {
-       .enable = ltdc_rgb_encoder_enable,
-       .disable = ltdc_rgb_encoder_disable,
-};
-
-static const struct drm_encoder_funcs ltdc_rgb_encoder_funcs = {
+static const struct drm_encoder_funcs ltdc_encoder_funcs = {
        .destroy = drm_encoder_cleanup,
 };
 
-static struct drm_encoder *ltdc_rgb_encoder_create(struct drm_device *ddev)
+static int ltdc_encoder_init(struct drm_device *ddev)
 {
+       struct ltdc_device *ldev = ddev->dev_private;
        struct drm_encoder *encoder;
+       int ret;
 
        encoder = devm_kzalloc(ddev->dev, sizeof(*encoder), GFP_KERNEL);
        if (!encoder)
-               return NULL;
+               return -ENOMEM;
 
        encoder->possible_crtcs = CRTC_MASK;
        encoder->possible_clones = 0; /* No cloning support */
 
-       drm_encoder_init(ddev, encoder, &ltdc_rgb_encoder_funcs,
+       drm_encoder_init(ddev, encoder, &ltdc_encoder_funcs,
                         DRM_MODE_ENCODER_DPI, NULL);
 
-       drm_encoder_helper_add(encoder, &ltdc_rgb_encoder_helper_funcs);
-
-       DRM_DEBUG_DRIVER("RGB encoder:%d created\n", encoder->base.id);
-
-       return encoder;
-}
-
-/*
- * DRM_CONNECTOR
- */
-
-static int ltdc_rgb_connector_get_modes(struct drm_connector *connector)
-{
-       struct drm_device *ddev = connector->dev;
-       struct ltdc_device *ldev = ddev->dev_private;
-       int ret = 0;
-
-       DRM_DEBUG_DRIVER("\n");
-
-       if (ldev->panel)
-               ret = drm_panel_get_modes(ldev->panel);
-
-       return ret < 0 ? 0 : ret;
-}
-
-static struct drm_connector_helper_funcs ltdc_rgb_connector_helper_funcs = {
-       .get_modes = ltdc_rgb_connector_get_modes,
-};
-
-static enum drm_connector_status
-ltdc_rgb_connector_detect(struct drm_connector *connector, bool force)
-{
-       struct ltdc_device *ldev = connector_to_ltdc(connector);
-
-       return ldev->panel ? connector_status_connected :
-              connector_status_disconnected;
-}
-
-static void ltdc_rgb_connector_destroy(struct drm_connector *connector)
-{
-       DRM_DEBUG_DRIVER("\n");
-
-       drm_connector_unregister(connector);
-       drm_connector_cleanup(connector);
-}
-
-static const struct drm_connector_funcs ltdc_rgb_connector_funcs = {
-       .dpms = drm_atomic_helper_connector_dpms,
-       .fill_modes = drm_helper_probe_single_connector_modes,
-       .detect = ltdc_rgb_connector_detect,
-       .destroy = ltdc_rgb_connector_destroy,
-       .reset = drm_atomic_helper_connector_reset,
-       .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
-       .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
-};
-
-struct drm_connector *ltdc_rgb_connector_create(struct drm_device *ddev)
-{
-       struct drm_connector *connector;
-       int err;
-
-       connector = devm_kzalloc(ddev->dev, sizeof(*connector), GFP_KERNEL);
-       if (!connector) {
-               DRM_ERROR("Failed to allocate connector\n");
-               return NULL;
-       }
-
-       connector->polled = DRM_CONNECTOR_POLL_HPD;
-
-       err = drm_connector_init(ddev, connector, &ltdc_rgb_connector_funcs,
-                                DRM_MODE_CONNECTOR_DPI);
-       if (err) {
-               DRM_ERROR("Failed to initialize connector\n");
-               return NULL;
+       ret = drm_bridge_attach(encoder, ldev->bridge, NULL);
+       if (ret) {
+               drm_encoder_cleanup(encoder);
+               return -EINVAL;
        }
 
-       drm_connector_helper_add(connector, &ltdc_rgb_connector_helper_funcs);
-
-       DRM_DEBUG_DRIVER("RGB connector:%d created\n", connector->base.id);
+       DRM_DEBUG_DRIVER("Bridge encoder:%d created\n", encoder->base.id);
 
-       return connector;
+       return 0;
 }
 
 static int ltdc_get_caps(struct drm_device *ddev)
@@ -972,49 +866,14 @@ static int ltdc_get_caps(struct drm_device *ddev)
        return 0;
 }
 
-static struct drm_panel *ltdc_get_panel(struct drm_device *ddev)
-{
-       struct device *dev = ddev->dev;
-       struct device_node *np = dev->of_node;
-       struct device_node *entity, *port = NULL;
-       struct drm_panel *panel = NULL;
-
-       DRM_DEBUG_DRIVER("\n");
-
-       /*
-        * Parse ltdc node to get remote port and find RGB panel / HDMI slave
-        * If a dsi or a bridge (hdmi, lvds...) is connected to ltdc,
-        * a remote port & RGB panel will not be found.
-        */
-       for_each_endpoint_of_node(np, entity) {
-               if (!of_device_is_available(entity))
-                       continue;
-
-               port = of_graph_get_remote_port_parent(entity);
-               if (port) {
-                       panel = of_drm_find_panel(port);
-                       of_node_put(port);
-                       if (panel) {
-                               DRM_DEBUG_DRIVER("remote panel %s\n",
-                                                port->full_name);
-                       } else {
-                               DRM_DEBUG_DRIVER("panel missing\n");
-                               of_node_put(entity);
-                       }
-               }
-       }
-
-       return panel;
-}
-
 int ltdc_load(struct drm_device *ddev)
 {
        struct platform_device *pdev = to_platform_device(ddev->dev);
        struct ltdc_device *ldev = ddev->dev_private;
        struct device *dev = ddev->dev;
        struct device_node *np = dev->of_node;
-       struct drm_encoder *encoder;
-       struct drm_connector *connector = NULL;
+       struct drm_bridge *bridge;
+       struct drm_panel *panel;
        struct drm_crtc *crtc;
        struct reset_control *rstc;
        struct resource res;
@@ -1022,9 +881,9 @@ int ltdc_load(struct drm_device *ddev)
 
        DRM_DEBUG_DRIVER("\n");
 
-       ldev->panel = ltdc_get_panel(ddev);
-       if (!ldev->panel)
-               return -EPROBE_DEFER;
+       ret = drm_of_find_panel_or_bridge(np, 0, 0, &panel, &bridge);
+       if (ret)
+               return ret;
 
        rstc = of_reset_control_get(np, NULL);
 
@@ -1043,13 +902,15 @@ int ltdc_load(struct drm_device *ddev)
 
        if (of_address_to_resource(np, 0, &res)) {
                DRM_ERROR("Unable to get resource\n");
-               return -ENODEV;
+               ret = -ENODEV;
+               goto err;
        }
 
        ldev->regs = devm_ioremap_resource(dev, &res);
        if (IS_ERR(ldev->regs)) {
                DRM_ERROR("Unable to get ltdc registers\n");
-               return PTR_ERR(ldev->regs);
+               ret = PTR_ERR(ldev->regs);
+               goto err;
        }
 
        for (i = 0; i < MAX_IRQ; i++) {
@@ -1062,7 +923,7 @@ int ltdc_load(struct drm_device *ddev)
                                                dev_name(dev), ddev);
                if (ret) {
                        DRM_ERROR("Failed to register LTDC interrupt\n");
-                       return ret;
+                       goto err;
                }
        }
 
@@ -1077,33 +938,27 @@ int ltdc_load(struct drm_device *ddev)
        if (ret) {
                DRM_ERROR("hardware identifier (0x%08x) not supported!\n",
                          ldev->caps.hw_version);
-               return ret;
+               goto err;
        }
 
        DRM_INFO("ltdc hw version 0x%08x - ready\n", ldev->caps.hw_version);
 
-       if (ldev->panel) {
-               encoder = ltdc_rgb_encoder_create(ddev);
-               if (!encoder) {
-                       DRM_ERROR("Failed to create RGB encoder\n");
-                       ret = -EINVAL;
-                       goto err;
-               }
-
-               connector = ltdc_rgb_connector_create(ddev);
-               if (!connector) {
-                       DRM_ERROR("Failed to create RGB connector\n");
-                       ret = -EINVAL;
+       if (panel) {
+               bridge = drm_panel_bridge_add(panel, DRM_MODE_CONNECTOR_DPI);
+               if (IS_ERR(bridge)) {
+                       DRM_ERROR("Failed to create panel-bridge\n");
+                       ret = PTR_ERR(bridge);
                        goto err;
                }
+               ldev->is_panel_bridge = true;
+       }
 
-               ret = drm_mode_connector_attach_encoder(connector, encoder);
-               if (ret) {
-                       DRM_ERROR("Failed to attach connector to encoder\n");
-                       goto err;
-               }
+       ldev->bridge = bridge;
 
-               drm_panel_attach(ldev->panel, connector);
+       ret = ltdc_encoder_init(ddev);
+       if (ret) {
+               DRM_ERROR("Failed to init encoder\n");
+               goto err;
        }
 
        crtc = devm_kzalloc(dev, sizeof(*crtc), GFP_KERNEL);
@@ -1129,9 +984,10 @@ int ltdc_load(struct drm_device *ddev)
        ddev->irq_enabled = 1;
 
        return 0;
+
 err:
-       if (ldev->panel)
-               drm_panel_detach(ldev->panel);
+       if (ldev->is_panel_bridge)
+               drm_panel_bridge_remove(bridge);
 
        clk_disable_unprepare(ldev->pixel_clk);
 
@@ -1144,8 +1000,8 @@ void ltdc_unload(struct drm_device *ddev)
 
        DRM_DEBUG_DRIVER("\n");
 
-       if (ldev->panel)
-               drm_panel_detach(ldev->panel);
+       if (ldev->is_panel_bridge)
+               drm_panel_bridge_remove(ldev->bridge);
 
        clk_disable_unprepare(ldev->pixel_clk);
 }