Clean up the function a bit, mainly by doing the mode_valid_check dance
once in the beginning of the function, and grouping the calculations
wrt. sync/event mode a bit better.

Signed-off-by: Tomi Valkeinen <tomi.valkei...@ideasonboard.com>
---
 drivers/gpu/drm/bridge/cadence/cdns-dsi-core.c | 48 ++++++++++++--------------
 1 file changed, 22 insertions(+), 26 deletions(-)

diff --git a/drivers/gpu/drm/bridge/cadence/cdns-dsi-core.c 
b/drivers/gpu/drm/bridge/cadence/cdns-dsi-core.c
index 9238acf69823..0aaa1d06b21c 100644
--- a/drivers/gpu/drm/bridge/cadence/cdns-dsi-core.c
+++ b/drivers/gpu/drm/bridge/cadence/cdns-dsi-core.c
@@ -481,42 +481,38 @@ static int cdns_dsi_mode2cfg(struct cdns_dsi *dsi,
                             bool mode_valid_check)
 {
        struct cdns_dsi_output *output = &dsi->output;
-       unsigned int tmp;
-       bool sync_pulse = false;
+       u32 dpi_hsa, dpi_hbp, dpi_hfp, dpi_hact;
+       bool sync_pulse;
        int bpp;
 
+       if (mode_valid_check) {
+               dpi_hsa = mode->hsync_end - mode->hsync_start;
+               dpi_hbp = mode->htotal - mode->hsync_end;
+               dpi_hfp = mode->hsync_start - mode->hdisplay;
+               dpi_hact = mode->hdisplay;
+       } else {
+               dpi_hsa = mode->crtc_hsync_end - mode->crtc_hsync_start;
+               dpi_hbp = mode->crtc_htotal - mode->crtc_hsync_end;
+               dpi_hfp =  mode->crtc_hsync_start - mode->crtc_hdisplay;
+               dpi_hact = mode->crtc_hdisplay;
+       }
+
        memset(dsi_cfg, 0, sizeof(*dsi_cfg));
 
-       if (output->dev->mode_flags & MIPI_DSI_MODE_VIDEO_SYNC_PULSE)
-               sync_pulse = true;
+       sync_pulse = output->dev->mode_flags & MIPI_DSI_MODE_VIDEO_SYNC_PULSE;
 
        bpp = mipi_dsi_pixel_format_to_bpp(output->dev->format);
 
-       if (mode_valid_check)
-               tmp = mode->htotal -
-                     (sync_pulse ? mode->hsync_end : mode->hsync_start);
-       else
-               tmp = mode->crtc_htotal -
-                     (sync_pulse ?
-                      mode->crtc_hsync_end : mode->crtc_hsync_start);
-
-       dsi_cfg->hbp = dpi_to_dsi_timing(tmp, bpp, DSI_HBP_FRAME_OVERHEAD);
+       dsi_cfg->hbp = dpi_to_dsi_timing(dpi_hbp + (sync_pulse ? 0 : dpi_hsa),
+                                        bpp, DSI_HBP_FRAME_OVERHEAD);
 
-       if (sync_pulse) {
-               if (mode_valid_check)
-                       tmp = mode->hsync_end - mode->hsync_start;
-               else
-                       tmp = mode->crtc_hsync_end - mode->crtc_hsync_start;
+       if (sync_pulse)
+               dsi_cfg->hsa =
+                       dpi_to_dsi_timing(dpi_hsa, bpp, DSI_HSA_FRAME_OVERHEAD);
 
-               dsi_cfg->hsa = dpi_to_dsi_timing(tmp, bpp,
-                                                DSI_HSA_FRAME_OVERHEAD);
-       }
+       dsi_cfg->hact = dpi_to_dsi_timing(dpi_hact, bpp, 0);
 
-       dsi_cfg->hact = dpi_to_dsi_timing(mode_valid_check ?
-                                         mode->hdisplay : mode->crtc_hdisplay,
-                                         bpp, 0);
-       dsi_cfg->hfp = dpi_to_dsi_timing(mode_to_dpi_hfp(mode, 
mode_valid_check),
-                                        bpp, DSI_HFP_FRAME_OVERHEAD);
+       dsi_cfg->hfp = dpi_to_dsi_timing(dpi_hfp, bpp, DSI_HFP_FRAME_OVERHEAD);
 
        return 0;
 }

-- 
2.43.0

Reply via email to