[PATCH 02/13] drm/kms/mode/bridge-tc358767: using helper func drm_display_mode_to_videomode for calculating timing parameters

From: Satendra Singh Thakur
Date: Thu May 03 2018 - 04:37:44 EST


To avoid duplicate logic for timing parameters

Signed-off-by: Satendra Singh Thakur <satendra.t@xxxxxxxxxxx>
Cc: Madhur Verma <madhur.verma@xxxxxxxxxxx>
Cc: Hemanshu Srivastava <hemanshu.s@xxxxxxxxxxx>
---
drivers/gpu/drm/bridge/tc358767.c | 42 ++++++++++++++++++---------------------
1 file changed, 19 insertions(+), 23 deletions(-)

diff --git a/drivers/gpu/drm/bridge/tc358767.c b/drivers/gpu/drm/bridge/tc358767.c
index 08ab7d6a..d90ac27 100644
--- a/drivers/gpu/drm/bridge/tc358767.c
+++ b/drivers/gpu/drm/bridge/tc358767.c
@@ -39,6 +39,7 @@
#include <drm/drm_edid.h>
#include <drm/drm_of.h>
#include <drm/drm_panel.h>
+#include <video/videomode.h>

/* Registers */

@@ -653,14 +654,9 @@ static int tc_set_video_mode(struct tc_data *tc, struct drm_display_mode *mode)
int ret;
int vid_sync_dly;
int max_tu_symbol;
+ struct videomode vm;

- int left_margin = mode->htotal - mode->hsync_end;
- int right_margin = mode->hsync_start - mode->hdisplay;
- int hsync_len = mode->hsync_end - mode->hsync_start;
- int upper_margin = mode->vtotal - mode->vsync_end;
- int lower_margin = mode->vsync_start - mode->vdisplay;
- int vsync_len = mode->vsync_end - mode->vsync_start;
-
+ drm_display_mode_to_videomode(mode, &vm);
/*
* Recommended maximum number of symbols transferred in a transfer unit:
* DIV_ROUND_UP((input active video bandwidth in bytes) * tu_size,
@@ -670,11 +666,11 @@ static int tc_set_video_mode(struct tc_data *tc, struct drm_display_mode *mode)
max_tu_symbol = TU_SIZE_RECOMMENDED - 1;

dev_dbg(tc->dev, "set mode %dx%d\n",
- mode->hdisplay, mode->vdisplay);
+ vm.hactive, vm.vactive);
dev_dbg(tc->dev, "H margin %d,%d sync %d\n",
- left_margin, right_margin, hsync_len);
+ vm.hback_porch, vm.hfront_porch, vm.hsync_len);
dev_dbg(tc->dev, "V margin %d,%d sync %d\n",
- upper_margin, lower_margin, vsync_len);
+ vm.vback_porch, vm.vfront_porch, vm.vsync_len);
dev_dbg(tc->dev, "total: %dx%d\n", mode->htotal, mode->vtotal);


@@ -686,14 +682,14 @@ static int tc_set_video_mode(struct tc_data *tc, struct drm_display_mode *mode)
*/
tc_write(VPCTRL0, (0 << 20) /* VSDELAY */ |
OPXLFMT_RGB888 | FRMSYNC_DISABLED | MSF_DISABLED);
- tc_write(HTIM01, (ALIGN(left_margin, 2) << 16) | /* H back porch */
- (ALIGN(hsync_len, 2) << 0)); /* Hsync */
- tc_write(HTIM02, (ALIGN(right_margin, 2) << 16) | /* H front porch */
- (ALIGN(mode->hdisplay, 2) << 0)); /* width */
- tc_write(VTIM01, (upper_margin << 16) | /* V back porch */
- (vsync_len << 0)); /* Vsync */
- tc_write(VTIM02, (lower_margin << 16) | /* V front porch */
- (mode->vdisplay << 0)); /* height */
+ tc_write(HTIM01, (ALIGN(vm.hback_porch, 2) << 16) | /* H back porch */
+ (ALIGN(vm.hsync_len, 2) << 0)); /* Hsync */
+ tc_write(HTIM02, (ALIGN(vm.hfront_porch, 2) << 16) | /* H front porch */
+ (ALIGN(vm.hactive, 2) << 0)); /* width */
+ tc_write(VTIM01, (vm.vback_porch << 16) | /* V back porch */
+ (vm.vsync_len << 0)); /* Vsync */
+ tc_write(VTIM02, (vm.vfront_porch << 16) | /* V front porch */
+ (vm.vactive << 0)); /* height */
tc_write(VFUEN0, VFUEN); /* update settings */

/* Test pattern settings */
@@ -706,7 +702,7 @@ static int tc_set_video_mode(struct tc_data *tc, struct drm_display_mode *mode)
0);

/* DP Main Stream Attributes */
- vid_sync_dly = hsync_len + left_margin + mode->hdisplay;
+ vid_sync_dly = vm.hsync_len + vm.hback_porch + vm.hactive;
tc_write(DP0_VIDSYNCDELAY,
(max_tu_symbol << 16) | /* thresh_dly */
(vid_sync_dly << 0));
@@ -714,12 +710,12 @@ static int tc_set_video_mode(struct tc_data *tc, struct drm_display_mode *mode)
tc_write(DP0_TOTALVAL, (mode->vtotal << 16) | (mode->htotal));

tc_write(DP0_STARTVAL,
- ((upper_margin + vsync_len) << 16) |
- ((left_margin + hsync_len) << 0));
+ ((vm.vback_porch + vm.vsync_len) << 16) |
+ ((vm.hback_porch + vm.hsync_len) << 0));

- tc_write(DP0_ACTIVEVAL, (mode->vdisplay << 16) | (mode->hdisplay));
+ tc_write(DP0_ACTIVEVAL, (vm.vactive << 16) | (vm.hactive));

- tc_write(DP0_SYNCVAL, (vsync_len << 16) | (hsync_len << 0));
+ tc_write(DP0_SYNCVAL, (vm.vsync_len << 16) | (vm.hsync_len << 0));

tc_write(DPIPXLFMT, VS_POL_ACTIVE_LOW | HS_POL_ACTIVE_LOW |
DE_POL_ACTIVE_HIGH | SUB_CFG_TYPE_CONFIG1 | DPI_BPP_RGB888);
--
2.7.4