drm/tilcdc: Remove unnecessary tilcdc_crtc_disable() from tilcdc_unload()
[platform/kernel/linux-rpi.git] / drivers / gpu / drm / tilcdc / tilcdc_drv.c
index d612d03..1981ae9 100644 (file)
 
 static LIST_HEAD(module_list);
 
+static const u32 tilcdc_rev1_formats[] = { DRM_FORMAT_RGB565 };
+
+static const u32 tilcdc_straight_formats[] = { DRM_FORMAT_RGB565,
+                                              DRM_FORMAT_BGR888,
+                                              DRM_FORMAT_XBGR8888 };
+
+static const u32 tilcdc_crossed_formats[] = { DRM_FORMAT_BGR565,
+                                             DRM_FORMAT_RGB888,
+                                             DRM_FORMAT_XRGB8888 };
+
+static const u32 tilcdc_legacy_formats[] = { DRM_FORMAT_RGB565,
+                                            DRM_FORMAT_RGB888,
+                                            DRM_FORMAT_XRGB8888 };
+
 void tilcdc_module_init(struct tilcdc_module *mod, const char *name,
                const struct tilcdc_module_ops *funcs)
 {
@@ -113,12 +127,18 @@ static int tilcdc_commit(struct drm_device *dev,
         * current layout.
         */
 
+       /* Keep HW on while we commit the state. */
+       pm_runtime_get_sync(dev->dev);
+
        drm_atomic_helper_commit_modeset_disables(dev, state);
 
-       drm_atomic_helper_commit_planes(dev, state, false);
+       drm_atomic_helper_commit_planes(dev, state, 0);
 
        drm_atomic_helper_commit_modeset_enables(dev, state);
 
+       /* Now HW should remain on if need becase the crtc is enabled */
+       pm_runtime_put_sync(dev->dev);
+
        drm_atomic_helper_wait_for_vblanks(dev, state);
 
        drm_atomic_helper_cleanup_planes(dev, state);
@@ -164,12 +184,9 @@ static int cpufreq_transition(struct notifier_block *nb,
 {
        struct tilcdc_drm_private *priv = container_of(nb,
                        struct tilcdc_drm_private, freq_transition);
-       if (val == CPUFREQ_POSTCHANGE) {
-               if (priv->lcd_fck_rate != clk_get_rate(priv->clk)) {
-                       priv->lcd_fck_rate = clk_get_rate(priv->clk);
-                       tilcdc_crtc_update_clk(priv->crtc);
-               }
-       }
+
+       if (val == CPUFREQ_POSTCHANGE)
+               tilcdc_crtc_update_clk(priv->crtc);
 
        return 0;
 }
@@ -183,8 +200,6 @@ static int tilcdc_unload(struct drm_device *dev)
 {
        struct tilcdc_drm_private *priv = dev->dev_private;
 
-       tilcdc_crtc_dpms(priv->crtc, DRM_MODE_DPMS_OFF);
-
        tilcdc_remove_external_encoders(dev);
 
        drm_fbdev_cma_fini(priv->fbdev);
@@ -215,24 +230,17 @@ static int tilcdc_unload(struct drm_device *dev)
        return 0;
 }
 
-static size_t tilcdc_num_regs(void);
-
 static int tilcdc_load(struct drm_device *dev, unsigned long flags)
 {
        struct platform_device *pdev = dev->platformdev;
        struct device_node *node = pdev->dev.of_node;
        struct tilcdc_drm_private *priv;
-       struct tilcdc_module *mod;
        struct resource *res;
        u32 bpp = 0;
        int ret;
 
        priv = devm_kzalloc(dev->dev, sizeof(*priv), GFP_KERNEL);
-       if (priv)
-               priv->saved_register =
-                       devm_kcalloc(dev->dev, tilcdc_num_regs(),
-                                    sizeof(*priv->saved_register), GFP_KERNEL);
-       if (!priv || !priv->saved_register) {
+       if (!priv) {
                dev_err(dev->dev, "failed to allocate private data\n");
                return -ENOMEM;
        }
@@ -270,7 +278,6 @@ static int tilcdc_load(struct drm_device *dev, unsigned long flags)
        }
 
 #ifdef CONFIG_CPU_FREQ
-       priv->lcd_fck_rate = clk_get_rate(priv->clk);
        priv->freq_transition.notifier_call = cpufreq_transition;
        ret = cpufreq_register_notifier(&priv->freq_transition,
                        CPUFREQ_TRANSITION_NOTIFIER);
@@ -318,6 +325,37 @@ static int tilcdc_load(struct drm_device *dev, unsigned long flags)
 
        pm_runtime_put_sync(dev->dev);
 
+       if (priv->rev == 1) {
+               DBG("Revision 1 LCDC supports only RGB565 format");
+               priv->pixelformats = tilcdc_rev1_formats;
+               priv->num_pixelformats = ARRAY_SIZE(tilcdc_rev1_formats);
+               bpp = 16;
+       } else {
+               const char *str = "\0";
+
+               of_property_read_string(node, "blue-and-red-wiring", &str);
+               if (0 == strcmp(str, "crossed")) {
+                       DBG("Configured for crossed blue and red wires");
+                       priv->pixelformats = tilcdc_crossed_formats;
+                       priv->num_pixelformats =
+                               ARRAY_SIZE(tilcdc_crossed_formats);
+                       bpp = 32; /* Choose bpp with RGB support for fbdef */
+               } else if (0 == strcmp(str, "straight")) {
+                       DBG("Configured for straight blue and red wires");
+                       priv->pixelformats = tilcdc_straight_formats;
+                       priv->num_pixelformats =
+                               ARRAY_SIZE(tilcdc_straight_formats);
+                       bpp = 16; /* Choose bpp with RGB support for fbdef */
+               } else {
+                       DBG("Blue and red wiring '%s' unknown, use legacy mode",
+                           str);
+                       priv->pixelformats = tilcdc_legacy_formats;
+                       priv->num_pixelformats =
+                               ARRAY_SIZE(tilcdc_legacy_formats);
+                       bpp = 16; /* This is just a guess */
+               }
+       }
+
        ret = modeset_init(dev);
        if (ret < 0) {
                dev_err(dev->dev, "failed to initialize mode setting\n");
@@ -331,7 +369,7 @@ static int tilcdc_load(struct drm_device *dev, unsigned long flags)
                if (ret < 0)
                        goto fail_mode_config_cleanup;
 
-               ret = tilcdc_add_external_encoders(dev, &bpp);
+               ret = tilcdc_add_external_encoders(dev);
                if (ret < 0)
                        goto fail_component_cleanup;
        }
@@ -354,15 +392,6 @@ static int tilcdc_load(struct drm_device *dev, unsigned long flags)
                goto fail_vblank_cleanup;
        }
 
-       list_for_each_entry(mod, &module_list, list) {
-               DBG("%s: preferred_bpp: %d", mod->name, mod->preferred_bpp);
-               bpp = mod->preferred_bpp;
-               if (bpp > 0)
-                       break;
-       }
-
-       drm_helper_disable_unused_functions(dev);
-
        drm_mode_config_reset(dev);
 
        priv->fbdev = drm_fbdev_cma_init(dev, bpp,
@@ -439,7 +468,7 @@ static void tilcdc_disable_vblank(struct drm_device *dev, unsigned int pipe)
        return;
 }
 
-#if defined(CONFIG_DEBUG_FS) || defined(CONFIG_PM_SLEEP)
+#if defined(CONFIG_DEBUG_FS)
 static const struct {
        const char *name;
        uint8_t  rev;
@@ -470,15 +499,6 @@ static const struct {
 #undef REG
 };
 
-static size_t tilcdc_num_regs(void)
-{
-       return ARRAY_SIZE(registers);
-}
-#else
-static size_t tilcdc_num_regs(void)
-{
-       return 0;
-}
 #endif
 
 #ifdef CONFIG_DEBUG_FS
@@ -610,29 +630,12 @@ static int tilcdc_pm_suspend(struct device *dev)
 {
        struct drm_device *ddev = dev_get_drvdata(dev);
        struct tilcdc_drm_private *priv = ddev->dev_private;
-       unsigned i, n = 0;
 
-       drm_kms_helper_poll_disable(ddev);
+       priv->saved_state = drm_atomic_helper_suspend(ddev);
 
        /* Select sleep pin state */
        pinctrl_pm_select_sleep_state(dev);
 
-       if (pm_runtime_suspended(dev)) {
-               priv->ctx_valid = false;
-               return 0;
-       }
-
-       /* Disable the LCDC controller, to avoid locking up the PRCM */
-       priv->saved_dpms_state = tilcdc_crtc_current_dpms_state(priv->crtc);
-       tilcdc_crtc_dpms(priv->crtc, DRM_MODE_DPMS_OFF);
-
-       /* Save register state: */
-       for (i = 0; i < ARRAY_SIZE(registers); i++)
-               if (registers[i].save && (priv->rev >= registers[i].rev))
-                       priv->saved_register[n++] = tilcdc_read(ddev, registers[i].reg);
-
-       priv->ctx_valid = true;
-
        return 0;
 }
 
@@ -640,25 +643,15 @@ static int tilcdc_pm_resume(struct device *dev)
 {
        struct drm_device *ddev = dev_get_drvdata(dev);
        struct tilcdc_drm_private *priv = ddev->dev_private;
-       unsigned i, n = 0;
+       int ret = 0;
 
        /* Select default pin state */
        pinctrl_pm_select_default_state(dev);
 
-       if (priv->ctx_valid == true) {
-               /* Restore register state: */
-               for (i = 0; i < ARRAY_SIZE(registers); i++)
-                       if (registers[i].save &&
-                           (priv->rev >= registers[i].rev))
-                               tilcdc_write(ddev, registers[i].reg,
-                                            priv->saved_register[n++]);
-       }
+       if (priv->saved_state)
+               ret = drm_atomic_helper_resume(ddev, priv->saved_state);
 
-       tilcdc_crtc_dpms(priv->crtc, priv->saved_dpms_state);
-
-       drm_kms_helper_poll_enable(ddev);
-
-       return 0;
+       return ret;
 }
 #endif