MLK-16353-4 video: fbdev: dcss: add scale ratio check
authorFancy Fang <chen.fang@nxp.com>
Mon, 4 Sep 2017 07:19:32 +0000 (15:19 +0800)
committerNitin Garg <nitin.garg@nxp.com>
Mon, 19 Mar 2018 20:38:27 +0000 (15:38 -0500)
According to the DCSS spec, the maximum scaling down
ratio supported by SCALER is 1/7. So add this check
when checking fb var info.

Signed-off-by: Fancy Fang <chen.fang@nxp.com>
drivers/video/fbdev/mxc/imx_dcss.c

index 3239dc0..96b79b2 100644 (file)
@@ -2399,12 +2399,15 @@ static int dcss_check_var(struct fb_var_screeninfo *var,
                          struct fb_info *fbi)
 {
        uint32_t fb_size;
+       uint32_t scale_ratio_mode_x, scale_ratio_mode_y;
+       uint32_t scale_ratio_x, scale_ratio_y;
        struct dcss_channel_info *cinfo = fbi->par;
        struct dcss_info *info = cinfo->dev_data;
        struct platform_device *pdev = info->pdev;
        const struct fb_bitfield *rgb = NULL;
        const struct pix_fmt_info *format = NULL;
        struct fb_fix_screeninfo *fix = &fbi->fix;
+       const struct fb_videomode *dmode = info->dft_disp_mode;
 
        if (var->xres > MAX_WIDTH || var->yres > MAX_HEIGHT) {
                dev_err(&pdev->dev, "unsupport display resolution\n");
@@ -2454,6 +2457,54 @@ static int dcss_check_var(struct fb_var_screeninfo *var,
                return -EINVAL;
        }
 
+       /* Add scale ratio check:
+        * Maximum scale down ratio is 1/7;
+        * Maximum scale up   ratio is 8;
+        */
+       if (dmode->xres > var->xres) {
+               /* upscaling */
+               scale_ratio_mode_x = dmode->xres % var->xres;
+               scale_ratio_mode_y = dmode->yres % var->yres;
+               scale_ratio_x = (dmode->xres - scale_ratio_mode_x) / var->xres;
+               scale_ratio_y = (dmode->yres - scale_ratio_mode_y) / var->yres;
+               if (scale_ratio_x >= 8) {
+                       if ((scale_ratio_x == 8 && scale_ratio_mode_x > 0) ||
+                           (scale_ratio_x > 8)) {
+                               dev_err(&pdev->dev, "unsupport scaling ration for width\n");
+                               return -EINVAL;
+                       }
+               }
+
+               if (scale_ratio_y >= 8) {
+                       if ((scale_ratio_y == 8 && scale_ratio_mode_y > 0) ||
+                           (scale_ratio_y > 8)) {
+                               dev_err(&pdev->dev, "unsupport scaling ration for height\n");
+                               return -EINVAL;
+                       }
+               }
+       } else {
+               /* downscaling */
+               scale_ratio_mode_x = var->xres % dmode->xres;
+               scale_ratio_mode_y = var->yres % dmode->yres;
+               scale_ratio_x = (var->xres - scale_ratio_mode_x) / dmode->xres;
+               scale_ratio_y = (var->yres - scale_ratio_mode_y) / dmode->yres;
+               if (scale_ratio_x >= 7) {
+                       if ((scale_ratio_x == 7 && scale_ratio_mode_x > 0) ||
+                           (scale_ratio_x > 7)) {
+                               dev_err(&pdev->dev, "unsupport scaling ration for width\n");
+                               return -EINVAL;
+                       }
+               }
+
+               if (scale_ratio_y >= 7) {
+                       if ((scale_ratio_y == 7 && scale_ratio_mode_y > 0) ||
+                           (scale_ratio_y > 7)) {
+                               dev_err(&pdev->dev, "unsupport scaling ration for height\n");
+                               return -EINVAL;
+                       }
+               }
+       }
+
        fix->line_length = var->xres * (var->bits_per_pixel >> 3);
        fb_size = var->yres_virtual * fix->line_length;