MLK-19158-1 drm/imx: sec-dsim_imx: add bus format check for ENCODER
authorFancy Fang <chen.fang@nxp.com>
Fri, 10 Aug 2018 14:40:18 +0000 (22:40 +0800)
committerLeonard Crestez <leonard.crestez@nxp.com>
Wed, 17 Apr 2019 23:51:34 +0000 (02:51 +0300)
The connector's 'display_info' usually includes all the bus
formats the display peripheral device can be accepted. And
the DRM adjusted display mode's 'private_flags' includes
bus format the DSIM bridge requested according to the DSI
device display format. Add the bus format check to the DSIM
encoder's atomic check to make sure these two bus formats
have intersection.

Signed-off-by: Fancy Fang <chen.fang@nxp.com>
(cherry picked from commit 6d804db82b95411ebad9fcfb43b3acecee5941d9)
(cherry picked from commit db574fd09da97c5f5c2f12b0aa47519969edd06f)

drivers/gpu/drm/imx/sec_mipi_dsim-imx.c

index bc985dd..548c356 100644 (file)
@@ -132,8 +132,30 @@ static int imx_sec_dsim_encoder_helper_atomic_check(struct drm_encoder *encoder,
                                                    struct drm_crtc_state *crtc_state,
                                                    struct drm_connector_state *conn_state)
 {
+       int i;
+       u32 bus_format;
+       unsigned int num_bus_formats;
+       struct imx_sec_dsim_device *dsim_dev = enc_to_dsim(encoder);
        struct drm_display_mode *adjusted_mode = &crtc_state->adjusted_mode;
        struct imx_crtc_state *imx_crtc_state = to_imx_crtc_state(crtc_state);
+       struct drm_display_info *display_info = &conn_state->connector->display_info;
+
+       num_bus_formats = display_info->num_bus_formats;
+       if (unlikely(!num_bus_formats))
+               dev_warn(dsim_dev->dev, "no bus formats assigned by connector\n");
+
+       bus_format = adjusted_mode->private_flags & 0xffff;
+
+       for (i = 0; i < num_bus_formats; i++) {
+               if (display_info->bus_formats[i] != bus_format)
+                       continue;
+               break;
+       }
+
+       if (i && i == num_bus_formats) {
+               dev_err(dsim_dev->dev, "invalid bus format for connector\n");
+               return -EINVAL;
+       }
 
        /* sec dsim can only accept active hight DE */
        imx_crtc_state->bus_flags |= DRM_BUS_FLAG_DE_HIGH;
@@ -144,7 +166,11 @@ static int imx_sec_dsim_encoder_helper_atomic_check(struct drm_encoder *encoder,
         */
        imx_crtc_state->bus_flags |= DRM_BUS_FLAG_PIXDATA_NEGEDGE;
 
-       imx_crtc_state->bus_format = adjusted_mode->private_flags & 0xffff;
+       /* set the bus format for CRTC output which should be
+        * the same as the bus format between dsim and connector,
+        * since dsim cannot do any pixel conversions.
+        */
+       imx_crtc_state->bus_format = bus_format;
 
        return 0;
 }