arm: tegra: fb: Update fix line_length
Shashank Sharma [Thu, 25 Oct 2012 09:41:39 +0000 (14:41 +0530)]
Update framebuffer's fix line_length parameter when changing
video mode dynamically.The new line_length should be according
to new x resolution. On addition, check the return value from
dc driver while setting a mode.

Bug 1163682
Bug 1056767
Bug 1056782
Signed-off-by: Shashank Sharma <shashanks@nvidia.com>
Change-Id: Ib0ab48474f0af3235556a7f7f0d8354af3b50994
Reviewed-on: http://git-master/r/147511
Reviewed-by: Simone Willett <swillett@nvidia.com>
Tested-by: Simone Willett <swillett@nvidia.com>

drivers/video/tegra/fb.c

index 6bc84d1..9995d2a 100644 (file)
@@ -139,17 +139,30 @@ static int tegra_fb_set_par(struct fb_info *info)
 
        if (var->pixclock) {
                bool stereo;
+               unsigned old_len = 0;
                struct fb_videomode m;
+               struct fb_videomode *old_mode = NULL;
 
                fb_var_to_videomode(&m, var);
 
+               /* Load framebuffer info with new mode details*/
+               old_mode = info->mode;
+               old_len  = info->fix.line_length;
+
                info->mode = (struct fb_videomode *)
                        fb_find_nearest_mode(&m, &info->modelist);
                if (!info->mode) {
                        dev_warn(&tegra_fb->ndev->dev, "can't match video mode\n");
+                       info->mode = old_mode;
                        return -EINVAL;
                }
 
+               /* Update fix line_length and window stride as per new mode */
+               info->fix.line_length = var->xres * var->bits_per_pixel / 8;
+               info->fix.line_length = round_up(info->fix.line_length,
+                       TEGRA_LINEAR_PITCH_ALIGNMENT);
+               tegra_fb->win->stride = info->fix.line_length;
+
                /*
                 * only enable stereo if the mode supports it and
                 * client requests it
@@ -161,7 +174,16 @@ static int tegra_fb_set_par(struct fb_info *info)
                                        FB_VMODE_STEREO_LEFT_RIGHT);
 #endif
 
-               tegra_dc_set_fb_mode(dc, info->mode, stereo);
+               /* Configure DC with new mode */
+               if (tegra_dc_set_fb_mode(dc, info->mode, stereo)) {
+                       /* Error while configuring DC, fallback to old mode */
+                       dev_warn(&tegra_fb->ndev->dev, "can't configure dc with mode %ux%u\n",
+                               info->mode->xres, info->mode->yres);
+                       info->mode = old_mode;
+                       info->fix.line_length = old_len;
+                       tegra_fb->win->stride = old_len;
+                       return -EINVAL;
+               }
 
                /* Reflect mode chnage on DC HW */
                if (dc->enabled)