ENGR00306783 video: mxsfb: Add a new 32bit RGB fb pix fmt for 18bit display
authorLiu Ying <Ying.Liu@freescale.com>
Thu, 27 Mar 2014 09:20:56 +0000 (17:20 +0800)
committerNitin Garg <nitin.garg@freescale.com>
Wed, 16 Apr 2014 13:58:19 +0000 (08:58 -0500)
This patch adds a new 32bit RGB framebuffer pixel format support for
18bit display.  The pixel format's components can be described by the
following table:
 -----------------------------
|        |  length  |  offset |
 -----------------------------
|  red   |   8bit   |  16bit  |
 -----------------------------
| green  |   8bit   |  8bit   |
 -----------------------------
|  blue  |   8bit   |    0    |
 -----------------------------
| transp |    0     |   N/A   |
 -----------------------------

Userland should specify each component's length and offset to use
this pixel format, otherwise the default 32bit pixel format which
can be described by the following table will be active:
 -----------------------------
|        |  length  |  offset |
 -----------------------------
|  red   |   6bit   |  16bit  |
 -----------------------------
| green  |   6bit   |  8bit   |
 -----------------------------
|  blue  |   6bit   |    0    |
 -----------------------------
| transp |    0     |   N/A   |
 -----------------------------

Signed-off-by: Liu Ying <Ying.Liu@freescale.com>
drivers/video/mxsfb.c

index 82eb82e28e91f6517952a39d9ceb8c3838d01aac..60a760b0a6dae847626432602179e01c6a7a7f05 100644 (file)
@@ -343,6 +343,19 @@ static const struct fb_bitfield def_rgb888[] = {
        }
 };
 
+#define bitfield_is_equal(f1, f2)  (!memcmp(&(f1), &(f2), sizeof(f1)))
+
+static inline bool pixfmt_is_equal(struct fb_var_screeninfo *var,
+                                  const struct fb_bitfield *f)
+{
+       if (bitfield_is_equal(var->red, f[RED]) &&
+           bitfield_is_equal(var->green, f[GREEN]) &&
+           bitfield_is_equal(var->blue, f[BLUE]))
+               return true;
+
+       return false;
+}
+
 static inline unsigned chan_to_field(unsigned chan, struct fb_bitfield *bf)
 {
        chan &= 0xffff;
@@ -413,10 +426,16 @@ static int mxsfb_check_var(struct fb_var_screeninfo *var,
                        pr_debug("Unsupported LCD bus width mapping\n");
                        break;
                case STMLCDIF_16BIT:
-               case STMLCDIF_18BIT:
                        /* 24 bit to 18 bit mapping */
                        rgb = def_rgb666;
                        break;
+               case STMLCDIF_18BIT:
+                       if (pixfmt_is_equal(var, def_rgb888))
+                               rgb = def_rgb888;
+                       else
+                               /* 24 bit to 18 bit mapping */
+                               rgb = def_rgb666;
+                       break;
                case STMLCDIF_24BIT:
                        /* real 24 bit */
                        rgb = def_rgb888;
@@ -608,12 +627,20 @@ static int mxsfb_set_par(struct fb_info *fb_info)
                                        "Unsupported LCD bus width mapping\n");
                        return -EINVAL;
                case STMLCDIF_16BIT:
-               case STMLCDIF_18BIT:
                        /* 24 bit to 18 bit mapping */
                        ctrl |= CTRL_DF24; /* ignore the upper 2 bits in
                                            *  each colour component
                                            */
                        break;
+               case STMLCDIF_18BIT:
+                       if (pixfmt_is_equal(&fb_info->var, def_rgb888))
+                               break;
+                       else
+                               /* 24 bit to 18 bit mapping */
+                               ctrl |= CTRL_DF24; /* ignore the upper 2 bits in
+                                                   *  each colour component
+                                                   */
+                       break;
                case STMLCDIF_24BIT:
                        /* real 24 bit */
                        break;