UPSTREAM: drm/dsi: Add a helper to get bits per pixel of MIPI DSI pixel format
authorLiu Ying <Ying.liu@freescale.com>
Fri, 20 Nov 2015 08:15:30 +0000 (16:15 +0800)
committerHuang, Tao <huangtao@rock-chips.com>
Fri, 18 Mar 2016 12:44:21 +0000 (20:44 +0800)
Add a helper that can be used to obtain the number of bits per pixel
corresponding to a given MIPI DSI pixel format. This is useful in
bandwidth calculations, for example.

Change-Id: I03b9f93044ed46a2b999ce82e5623396a6f4d2bc
Signed-off-by: Mark Yao <mark.yao@rock-chips.com>
Signed-off-by: Liu Ying <Ying.Liu@freescale.com>
Acked-by: Thierry Reding <treding@nvidia.com>
Signed-off-by: Chris Zhong <zyw@rock-chips.com>
[treding@nvidia.com: add kerneldoc comment and commit message]
Signed-off-by: Thierry Reding <treding@nvidia.com>
(cherry picked from commit ec26d9e9382f432225d76b3ff1c7f72e21192f7f)

include/drm/drm_mipi_dsi.h

index f1d8d0dbb4f162f9ea1c90dda44beedf14e4c175..4396c9f22af5998d7189da51aa35bcf1d9cf8159 100644 (file)
@@ -163,6 +163,31 @@ static inline struct mipi_dsi_device *to_mipi_dsi_device(struct device *dev)
        return container_of(dev, struct mipi_dsi_device, dev);
 }
 
+/**
+ * mipi_dsi_pixel_format_to_bpp - obtain the number of bits per pixel for any
+ *                                given pixel format defined by the MIPI DSI
+ *                                specification
+ * @fmt: MIPI DSI pixel format
+ *
+ * Returns: The number of bits per pixel of the given pixel format.
+ */
+static inline int mipi_dsi_pixel_format_to_bpp(enum mipi_dsi_pixel_format fmt)
+{
+       switch (fmt) {
+       case MIPI_DSI_FMT_RGB888:
+       case MIPI_DSI_FMT_RGB666:
+               return 24;
+
+       case MIPI_DSI_FMT_RGB666_PACKED:
+               return 18;
+
+       case MIPI_DSI_FMT_RGB565:
+               return 16;
+       }
+
+       return -EINVAL;
+}
+
 struct mipi_dsi_device *of_find_mipi_dsi_device_by_node(struct device_node *np);
 int mipi_dsi_attach(struct mipi_dsi_device *dsi);
 int mipi_dsi_detach(struct mipi_dsi_device *dsi);