From 86bc7636b08cf7dbeb6c900beedd24dac29c6e2d Mon Sep 17 00:00:00 2001 From: Kijun Kim Date: Tue, 23 Apr 2019 10:57:09 +0900 Subject: [PATCH] [ERD][NEUS7920-140] [9610] fbdev: dpu20: dsim: sysfs for read and write panel addr Change-Id: I994bddac72d82567982e4f3aceca0f90e628f40e Signed-off-by: Kijun Kim --- drivers/video/fbdev/exynos/dpu20/dsim.h | 3 + drivers/video/fbdev/exynos/dpu20/dsim_drv.c | 184 +++++++++++++++++++- 2 files changed, 185 insertions(+), 2 deletions(-) diff --git a/drivers/video/fbdev/exynos/dpu20/dsim.h b/drivers/video/fbdev/exynos/dpu20/dsim.h index 2da6191d655c..396872e93c44 100644 --- a/drivers/video/fbdev/exynos/dpu20/dsim.h +++ b/drivers/video/fbdev/exynos/dpu20/dsim.h @@ -240,6 +240,9 @@ struct dsim_device { int max_brightness; int brightness; int log_brightness; + + unsigned int ddi_seq_size; + unsigned char ddi_seq[512]; }; struct dsim_lcd_driver { diff --git a/drivers/video/fbdev/exynos/dpu20/dsim_drv.c b/drivers/video/fbdev/exynos/dpu20/dsim_drv.c index bd8c49b368c3..0514dbe3f868 100644 --- a/drivers/video/fbdev/exynos/dpu20/dsim_drv.c +++ b/drivers/video/fbdev/exynos/dpu20/dsim_drv.c @@ -40,7 +40,7 @@ #if defined(CONFIG_SUPPORT_LEGACY_ION) #include #endif - +#include #include #include "../../../../../mm/internal.h" @@ -1294,14 +1294,194 @@ static ssize_t dsim_cmd_sysfs_store(struct device *dev, } static DEVICE_ATTR(cmd_rw, 0644, dsim_cmd_sysfs_show, dsim_cmd_sysfs_store); +static ssize_t dsim_ddi_addr_sysfs_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct dsim_device *dsim = dev_get_drvdata(dev); + int size = 0; + int count; + + size = (ssize_t)sprintf(buf, "addr : 0x%02x ", dsim->ddi_seq[0]); + size = (ssize_t)sprintf(buf + size, "size : %d\n", dsim->ddi_seq_size); + + count = strlen(buf); + return count; +} + +static ssize_t dsim_ddi_addr_sysfs_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) +{ + struct dsim_device *dsim = dev_get_drvdata(dev); + unsigned int res; + int ret; + + char *cnt; + char *addr; + + cnt = (char *)buf; + addr = strsep(&cnt, " "); + if (addr == NULL) { + dsim_err("Usage : echo addr size > sysfs\n"); + goto end_func; + } + + ret = kstrtoint(addr, 0, &res); + if ((ret != 0) || (res > 255)) { + dsim_err("Fail : addr(0x%x) value should be less than 0xFF\n", res); + goto end_func; + } + dsim->ddi_seq[0] = (unsigned char)res; + + ret = kstrtoint(cnt, 0, &res); + if (ret != 0) { + dsim_err("Fail : cnt wrong value\n"); + goto end_func; + } + dsim->ddi_seq_size = res; + + dsim_info("ddi_addr : 0x%x\n", dsim->ddi_seq[0]); + dsim_info("ddi_seq_size : 0x%x\n", dsim->ddi_seq_size); + +end_func: + return count; +} +static DEVICE_ATTR(ddi_addr, 0600, dsim_ddi_addr_sysfs_show, dsim_ddi_addr_sysfs_store); + +static ssize_t dsim_ddi_read_sysfs_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct dsim_device *dsim = dev_get_drvdata(dev); + int ret = 0; + int offset = 0; + int i; + int count; + + /* dsim read */ + ret = dsim_read_data(dsim, MIPI_DSI_DCS_READ, dsim->ddi_seq[0], dsim->ddi_seq_size, &dsim->ddi_seq[1]); + + if (ret < 0) { + dsim_err("Failed to write test data!\n"); + count = 0; + goto end_func; + } else + dsim_dbg("Succeeded to write test data!\n"); + + + /* print */ + for (i = 1; i <= dsim->ddi_seq_size; i++) { + ret = sprintf(buf + offset, "0x%02x ", dsim->ddi_seq[i]); + offset = offset + ret; + } + ret = sprintf(buf + offset, "\n"); + count = strlen(buf); + +end_func: + return count; +} +static DEVICE_ATTR(ddi_read, 0400, dsim_ddi_read_sysfs_show, NULL); + +static ssize_t dsim_ddi_write_sysfs_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) +{ + struct dsim_device *dsim = dev_get_drvdata(dev); + + char *start; + char *find; + char token[] = "\0\0\0\0\0\0\0\0\0\0"; + unsigned int num; + unsigned int exit = 1; + + unsigned int val; + int ret; + int i = 0; + + start = (char *)buf; + + while (exit) { + /* parsing */ + find = strchr(start, ' '); + if (find == NULL) { + find = strchr(start, '\0'); + exit = 0; + } + + num = find - start; + strncpy(token, start, num); + token[num] = '\0'; + + find++; + start = find; + + /* convert str to number */ + if ((strncmp("0x", token, 2) == 0) || (strncmp("0X", token, 2) == 0)) + ret = kstrtouint(token+2, 16, &val); + else + ret = kstrtouint(token, 16, &val); + + if (ret != 0) { + dsim_err("Fail : data(%d) wrong value (should 0 ~ 0xff)\n", (unsigned int)val); + goto end_func; + } + + if (val > 255) { + dsim_err("Fail : data(%d) value should be less than 0xFF\n", (unsigned int)val); + goto end_func; + } + + dsim->ddi_seq[i] = (unsigned char)val; + dsim_info("%d\n", (unsigned int)dsim->ddi_seq[i]); // for debug + i++; + } + dsim->ddi_seq_size = i - 1; // for except addr + + /* dsim write */ + if (dsim->ddi_seq_size == 1) + ret = dsim_write_data(dsim, MIPI_DSI_DCS_SHORT_WRITE, dsim->ddi_seq[0], 0); + else if (dsim->ddi_seq_size == 2) + ret = dsim_write_data(dsim, MIPI_DSI_DCS_SHORT_WRITE_PARAM, dsim->ddi_seq[0], dsim->ddi_seq[1]); + else + ret = dsim_write_data(dsim, MIPI_DSI_DCS_LONG_WRITE, + (unsigned long)dsim->ddi_seq, dsim->ddi_seq_size + 1); + + if (ret < 0) + dsim_err("Failed to write test data!\n"); + else + dsim_dbg("Succeeded to write test data!\n"); + +end_func: + return count; +} +static DEVICE_ATTR(ddi_write, 0200, NULL, dsim_ddi_write_sysfs_store); + int dsim_create_cmd_rw_sysfs(struct dsim_device *dsim) { int ret = 0; ret = device_create_file(dsim->dev, &dev_attr_cmd_rw); - if (ret) + if (ret) { dsim_err("failed to create command read & write sysfs\n"); + goto error; + } + + ret = device_create_file(dsim->dev, &dev_attr_ddi_addr); + if (ret) { + dsim_err("failed to create ddi_addr sysfs\n"); + goto error; + } + + ret = device_create_file(dsim->dev, &dev_attr_ddi_read); + if (ret) { + dsim_err("failed to create ddi_read sysfs\n"); + goto error; + } + + ret = device_create_file(dsim->dev, &dev_attr_ddi_write); + if (ret) { + dsim_err("failed to create ddi_write sysfs\n"); + goto error; + } +error: return ret; } -- 2.20.1