From a25350b7fe076a5709698fc60cfd4ed0db39cfd1 Mon Sep 17 00:00:00 2001 From: hwangjae lee Date: Thu, 25 Oct 2018 11:26:28 +0900 Subject: [PATCH] [Robusta2] fbdev: dpu20: panel: max_brightness constraints is added for thermal solution Change-Id: Ibad5a40d9c1c33c458e676a1a9d0f06298f8874e Signed-off-by: hwangjae lee --- drivers/video/fbdev/exynos/dpu20/dsim.h | 1 + .../exynos/dpu20/panels/nt36672a_mipi_lcd.c | 129 +++++++++++++++++- .../exynos/dpu20/panels/s6e3fa0_mipi_lcd.c | 38 ++++-- 3 files changed, 148 insertions(+), 20 deletions(-) diff --git a/drivers/video/fbdev/exynos/dpu20/dsim.h b/drivers/video/fbdev/exynos/dpu20/dsim.h index 843719690ca2..349d6d1d036e 100755 --- a/drivers/video/fbdev/exynos/dpu20/dsim.h +++ b/drivers/video/fbdev/exynos/dpu20/dsim.h @@ -245,6 +245,7 @@ struct dsim_device { unsigned int ddi_seq_size; unsigned char ddi_seq[512]; + int user_brightness; }; struct dsim_lcd_driver { diff --git a/drivers/video/fbdev/exynos/dpu20/panels/nt36672a_mipi_lcd.c b/drivers/video/fbdev/exynos/dpu20/panels/nt36672a_mipi_lcd.c index f6611936df0d..760340667a04 100755 --- a/drivers/video/fbdev/exynos/dpu20/panels/nt36672a_mipi_lcd.c +++ b/drivers/video/fbdev/exynos/dpu20/panels/nt36672a_mipi_lcd.c @@ -29,7 +29,6 @@ static struct dsim_device *dsim_base; static struct backlight_device *bd; -#if defined(CONFIG_EXYNOS_PANEL_CABC) struct panel_device { struct device *dev; struct dsim_device *dsim; @@ -39,7 +38,6 @@ struct panel_device { struct panel_device *nt36672a_panel_drvdata; struct class *nt36672a_panel_class; -#endif static int nt36672a_get_brightness(struct backlight_device *bd) { @@ -161,13 +159,24 @@ static int nt36672a_update_brightness(int brightness) static int nt36672a_set_brightness(struct backlight_device *bd) { + struct dsim_device *dsim; int brightness = bd->props.brightness; + dsim = get_dsim_drvdata(0); + if (brightness < MIN_BRIGHTNESS || brightness > MAX_BRIGHTNESS) { pr_err("Brightness should be in the range of 0 ~ 255\n"); return -EINVAL; } + + dsim->user_brightness = brightness; + if ((brightness > dsim->max_brightness) && + (brightness <= MAX_BRIGHTNESS)) { + brightness = dsim->max_brightness; + } + nt36672a_update_brightness(brightness); + dsim->brightness = brightness; return 0; } @@ -234,6 +243,7 @@ static int nt36672a_cabc_mode(struct dsim_device *dsim, int mode) return count; } +#endif static ssize_t panel_cabc_mode_show(struct device *dev, struct device_attribute *attr, char *buf) @@ -244,8 +254,9 @@ static ssize_t panel_cabc_mode_show(struct device *dev, mutex_lock(&panel->lock); +#if defined(CONFIG_EXYNOS_PANEL_CABC) ret = nt36672a_cabc_mode(panel->dsim, CABC_READ_MODE); - +#endif mutex_unlock(&panel->lock); count = snprintf(buf, PAGE_SIZE, "cabc_mode = %d, ret = %d\n", @@ -270,16 +281,117 @@ static ssize_t panel_cabc_mode_store(struct device *dev, mutex_unlock(&panel->lock); pr_info("%s: %d\n", __func__, value); - +#if defined(CONFIG_EXYNOS_PANEL_CABC) nt36672a_cabc_mode(panel->dsim, panel->cabc_mode); +#endif + return count; +} + +static ssize_t panel_max_brightness_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + ssize_t count = 0; + struct dsim_device *dsim = get_dsim_drvdata(0); + + count = snprintf(buf, PAGE_SIZE, "max_brightness = %d\n", + dsim->max_brightness); + + return count; +} + +static ssize_t panel_max_brightness_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) +{ + int ret; + unsigned int value = 0; + struct dsim_device *dsim = get_dsim_drvdata(0); + int old_brightness; + + ret = kstrtouint(buf, 0, &value); + if (ret < 0) + return ret; + + mutex_lock(&dsim->bl_lock); + + old_brightness = dsim->brightness; + + if (value > MAX_BRIGHTNESS) { + dsim->max_brightness = MAX_BRIGHTNESS; + dsim->brightness = dsim->user_brightness; + } else if ((value >= MIN_BRIGHTNESS) && (value <= MAX_BRIGHTNESS)) { + dsim->max_brightness = value; + if (dsim->user_brightness > dsim->max_brightness) + dsim->brightness = dsim->max_brightness; + else + dsim->brightness = dsim->user_brightness; + } else { + goto end; + } + + if (old_brightness != dsim->brightness) { + nt36672a_update_brightness(dsim->brightness); + } + +end: + mutex_unlock(&dsim->bl_lock); + + pr_info("%s: %d\n", __func__, dsim->max_brightness); return count; } +static DEVICE_ATTR(max_brightness, 0660, panel_max_brightness_show, + panel_max_brightness_store); + + +static ssize_t panel_brightness_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + ssize_t count = 0; + struct dsim_device *dsim = get_dsim_drvdata(0); + + count = snprintf(buf, PAGE_SIZE, "brightness = %d\n", + dsim->brightness); + + return count; +} + +static ssize_t panel_brightness_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) +{ + int ret; + unsigned int value = 0; + struct dsim_device *dsim = get_dsim_drvdata(0); + + ret = kstrtouint(buf, 0, &value); + if (ret < 0) + return ret; + + mutex_lock(&dsim->bl_lock); + + if (value <= dsim->max_brightness) { + dsim->brightness = value; + nt36672a_update_brightness(dsim->brightness); + } else if (value <= MAX_BRIGHTNESS) { + dsim->user_brightness = value; + } else { + pr_err("%s, brightness value is wrong[%d]\n", + __func__, value); + } + + mutex_unlock(&dsim->bl_lock); + + pr_info("%s: %d\n", __func__, dsim->brightness); + + return count; +} + +static DEVICE_ATTR(brightness, 0660, panel_brightness_show, + panel_brightness_store); + static DEVICE_ATTR(cabc_mode, 0660, panel_cabc_mode_show, panel_cabc_mode_store); -#endif static ssize_t lcd_panel_supplier_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -294,6 +406,8 @@ static DEVICE_ATTR(panel_supplier, 0644, lcd_panel_supplier_show,NULL); static struct attribute *panel_attrs[] = { &dev_attr_cabc_mode.attr, &dev_attr_panel_supplier.attr, + &dev_attr_max_brightness.attr, + &dev_attr_brightness.attr, NULL, }; ATTRIBUTE_GROUPS(panel); @@ -327,8 +441,9 @@ static int nt36672a_probe(struct dsim_device *dsim) bd->props.max_brightness = MAX_BRIGHTNESS; bd->props.brightness = DEFAULT_BRIGHTNESS; + dsim->max_brightness = MAX_BRIGHTNESS; + dsim->brightness = DEFAULT_BRIGHTNESS; nt36672a_create_sysfs(dsim); -#if defined(CONFIG_EXYNOS_PANEL_CABC) panel = kzalloc(sizeof(struct panel_device), GFP_KERNEL); if (!panel) { pr_err("failed to allocate panel\n"); @@ -361,6 +476,7 @@ static int nt36672a_probe(struct dsim_device *dsim) } mutex_init(&panel->lock); + mutex_init(&dsim->bl_lock); dev_set_drvdata(panel->dev, panel); panel_no++; @@ -372,7 +488,6 @@ exit2: exit1: kfree(panel); exit0: -#endif return ret; } diff --git a/drivers/video/fbdev/exynos/dpu20/panels/s6e3fa0_mipi_lcd.c b/drivers/video/fbdev/exynos/dpu20/panels/s6e3fa0_mipi_lcd.c index 2e93d7f934be..52b4a4a1f204 100644 --- a/drivers/video/fbdev/exynos/dpu20/panels/s6e3fa0_mipi_lcd.c +++ b/drivers/video/fbdev/exynos/dpu20/panels/s6e3fa0_mipi_lcd.c @@ -171,7 +171,7 @@ static int s6e3fa0_get_backlight_level(int brightness) return backlightlevel; } -static int s6e3fa0_update_brightness(struct dsim_device *dsim, int brightness) +static int s6e3fa0_update_brightness(int brightness) { int backlightlevel; @@ -218,7 +218,13 @@ static int s6e3fa0_set_brightness(struct backlight_device *bd) brightness = dsim->max_brightness; } - s6e3fa0_update_brightness(dsim, brightness); + dsim->user_brightness = brightness; + if ((brightness > dsim->max_brightness) && + (brightness <= MAX_BRIGHTNESS)) { + brightness = dsim->max_brightness; + } + + s6e3fa0_update_brightness(brightness); dsim->brightness = brightness; return 1; @@ -352,6 +358,7 @@ static ssize_t panel_max_brightness_store(struct device *dev, int ret; unsigned int value = 0; struct dsim_device *dsim = get_dsim_drvdata(0); + int old_brightness; ret = kstrtouint(buf, 0, &value); if (ret < 0) @@ -359,22 +366,26 @@ static ssize_t panel_max_brightness_store(struct device *dev, mutex_lock(&dsim->bl_lock); + old_brightness = dsim->brightness; + if (value > MAX_BRIGHTNESS) { dsim->max_brightness = MAX_BRIGHTNESS; - if (dsim->log_brightness > 0) - dsim->brightness = dsim->log_brightness; - dsim->bd->props.brightness = dsim->brightness; - s6e3fa0_set_brightness(dsim->bd); - } - - if ((value >= MIN_BRIGHTNESS) && (value <= MAX_BRIGHTNESS)) + dsim->brightness = dsim->user_brightness; + } else if ((value >= MIN_BRIGHTNESS) && (value <= MAX_BRIGHTNESS)) { dsim->max_brightness = value; + if (dsim->user_brightness > dsim->max_brightness) + dsim->brightness = dsim->max_brightness; + else + dsim->brightness = dsim->user_brightness; + } else { + goto end; + } - if (dsim->brightness > dsim->max_brightness) { - dsim->brightness = dsim->max_brightness; - s6e3fa0_update_brightness(dsim, dsim->brightness); + if (old_brightness != dsim->brightness) { + s6e3fa0_update_brightness(dsim->brightness); } +end: mutex_unlock(&dsim->bl_lock); pr_info("%s: %d\n", __func__, dsim->max_brightness); @@ -416,7 +427,7 @@ static ssize_t panel_brightness_store(struct device *dev, dsim->bd->props.brightness = dsim->brightness; s6e3fa0_set_brightness(dsim->bd); } else if (value <= MAX_BRIGHTNESS) { - dsim->log_brightness = value; + dsim->user_brightness = value; } else { pr_err("%s, brightness value is wrong[%d]\n", __func__, value); @@ -489,6 +500,7 @@ static int s6e3fa0_probe(struct dsim_device *dsim) } mutex_init(&panel->lock); + mutex_init(&dsim->bl_lock); dev_set_drvdata(panel->dev, panel); panel_no++; -- 2.20.1