From 53a599de5560b95bf76bc12d17b93406c33e9f75 Mon Sep 17 00:00:00 2001 From: Hersen Wu Date: Fri, 22 Jun 2018 13:06:01 -0400 Subject: [PATCH] drm/amd/display: Linux hook test pattern through debufs bug fix: phy test PLTAT is special 80bit test pattern. The 80bit data should be hard coded within driver so that user does not need input the deata. previous driver does not have hard coded 80 bits pattern data for PLTPAT. Other than this PLTPAT, user has to input 80 bits pattern data. In case user input less than 10 bytes data, un-input data byte will be filled by 0x00. Signed-off-by: Hersen Wu Reviewed-by: Harry Wentland Signed-off-by: Alex Deucher --- .../amd/display/amdgpu_dm/amdgpu_dm_debugfs.c | 70 +++++++++++++++---- 1 file changed, 55 insertions(+), 15 deletions(-) diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_debugfs.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_debugfs.c index f20ba9d1c9e2..0276e09d0b82 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_debugfs.c +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_debugfs.c @@ -483,16 +483,22 @@ static ssize_t dp_phy_test_pattern_debugfs_write(struct file *f, const char __us char *wr_buf = NULL; char *wr_buf_ptr = NULL; uint32_t wr_buf_size = 100; + uint32_t wr_buf_count = 0; int r; int bytes_from_user; - char *sub_str; + char *sub_str = NULL; uint8_t param_index = 0; - long param[11]; + uint8_t param_nums = 0; + long param[11] = {0x0}; const char delimiter[3] = {' ', '\n', '\0'}; enum dp_test_pattern test_pattern = DP_TEST_PATTERN_UNSUPPORTED; bool disable_hpd = false; bool valid_test_pattern = false; - uint8_t custom_pattern[10] = {0}; + /* init with defalut 80bit custom pattern */ + uint8_t custom_pattern[10] = { + 0x1f, 0x7c, 0xf0, 0xc1, 0x07, + 0x1f, 0x7c, 0xf0, 0xc1, 0x07 + }; struct dc_link_settings prefer_link_settings = {LANE_COUNT_UNKNOWN, LINK_RATE_UNKNOWN, LINK_SPREAD_DISABLED}; struct dc_link_settings cur_link_settings = {LANE_COUNT_UNKNOWN, @@ -519,25 +525,51 @@ static ssize_t dp_phy_test_pattern_debugfs_write(struct file *f, const char __us bytes_from_user = wr_buf_size - r; - while (isspace(*wr_buf_ptr)) + /* check number of parameters. isspace could not differ space and \n */ + while ((*wr_buf_ptr != 0xa) && (wr_buf_count < wr_buf_size)) { + /* skip space*/ + while (isspace(*wr_buf_ptr) && (wr_buf_count < wr_buf_size)) { + wr_buf_ptr++; + wr_buf_count++; + } + + if (wr_buf_count == wr_buf_size) + break; + + /* skip non-space*/ + while ((!isspace(*wr_buf_ptr)) && (wr_buf_count < wr_buf_size)) { + wr_buf_ptr++; + wr_buf_count++; + } + + param_nums++; + + if (wr_buf_count == wr_buf_size) + break; + } + + /* max 11 parameters */ + if (param_nums > 11) + param_nums = 11; + + wr_buf_ptr = wr_buf; /* reset buf pinter */ + wr_buf_count = 0; /* number of char already checked */ + + while (isspace(*wr_buf_ptr) && (wr_buf_count < wr_buf_size)) { wr_buf_ptr++; + wr_buf_count++; + } - while ((*wr_buf_ptr != '\0') && (param_index < 1)) { + while (param_index < param_nums) { + /* after strsep, wr_buf_ptr will be moved to after space */ sub_str = strsep(&wr_buf_ptr, delimiter); + r = kstrtol(sub_str, 16, ¶m[param_index]); if (r) DRM_DEBUG_DRIVER("string to int convert error code: %d\n", r); param_index++; - while (isspace(*wr_buf_ptr)) - wr_buf_ptr++; - - /* DP_TEST_PATTERN_80BIT_CUSTOM need extra 80 bits - * whci are 10 bytes separte by space - */ - if (param[0] != 0x4) - break; } test_pattern = param[0]; @@ -575,8 +607,16 @@ static ssize_t dp_phy_test_pattern_debugfs_write(struct file *f, const char __us } if (test_pattern == DP_TEST_PATTERN_80BIT_CUSTOM) { - for (i = 0; i < 10; i++) - custom_pattern[i] = (uint8_t) param[i + 1]; + for (i = 0; i < 10; i++) { + if ((uint8_t) param[i + 1] != 0x0) + break; + } + + if (i < 10) { + /* not use default value */ + for (i = 0; i < 10; i++) + custom_pattern[i] = (uint8_t) param[i + 1]; + } } /* Usage: set DP physical test pattern using debugfs with normal DP -- GitLab