From d702741ef144d86f17f680148bf4a5bb4f8454d4 Mon Sep 17 00:00:00 2001 From: Andrzej Hajda Date: Fri, 8 Jul 2016 13:31:45 +0200 Subject: [PATCH] drm/panel/s6e3ha2: add locking to brightness update Brightness update can be called asynchronously, so access to device should be synchronized. To do this callback should be split into backlight callback and device specific part, which can be called from other places. Change-Id: Ib0c9d81ccaffe63b650dcd948c3ca1e770d03763 Signed-off-by: Andrzej Hajda --- drivers/gpu/drm/panel/panel-s6e3ha2.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/drivers/gpu/drm/panel/panel-s6e3ha2.c b/drivers/gpu/drm/panel/panel-s6e3ha2.c index 3d6683e..cf11128 100644 --- a/drivers/gpu/drm/panel/panel-s6e3ha2.c +++ b/drivers/gpu/drm/panel/panel-s6e3ha2.c @@ -532,37 +532,49 @@ static void s6e3ha2_update_gamma(struct s6e3ha2 *ctx, unsigned int brightness) ctx->bl_dev->props.brightness = brightness; } -static int s6e3ha2_set_brightness(struct backlight_device *bl_dev) +static void s6e3ha2_set_brightness(struct s6e3ha2 *ctx) +{ + s6e3ha2_test_key_on_f0(ctx); + s6e3ha2_update_gamma(ctx, ctx->bl_dev->props.brightness); + s6e3ha2_aor_control(ctx); + s6e3ha2_set_vint(ctx); + s6e3ha2_test_key_off_f0(ctx); +} + +static int s6e3ha2_bl_update_status(struct backlight_device *bl_dev) { struct s6e3ha2 *ctx = (struct s6e3ha2 *)bl_get_data(bl_dev); unsigned int brightness = bl_dev->props.brightness; int ret; + mutex_lock(&ctx->lock); + if (brightness < MIN_BRIGHTNESS || brightness > bl_dev->props.max_brightness) { dev_err(ctx->dev, "Invalid brightness: %u\n", brightness); - return -EINVAL; + ret = -EINVAL; + goto end; } if (bl_dev->props.power > FB_BLANK_NORMAL) { dev_err(ctx->dev, "panel must be at least in fb blank normal state\n"); - return -EPERM; + ret = -EPERM; + goto end; } - s6e3ha2_test_key_on_f0(ctx); - s6e3ha2_update_gamma(ctx, brightness); - s6e3ha2_aor_control(ctx); - s6e3ha2_set_vint(ctx); + s6e3ha2_set_brightness(ctx); + ret = s6e3ha2_clear_error(ctx); - s6e3ha2_test_key_off_f0(ctx); +end: + mutex_unlock(&ctx->lock); - return 0; + return ret; } static const struct backlight_ops s6e3ha2_bl_ops = { .get_brightness = s6e3ha2_get_brightness, - .update_status = s6e3ha2_set_brightness, + .update_status = s6e3ha2_bl_update_status, }; static void s6e3ha2_panel_init(struct s6e3ha2 *ctx) @@ -715,7 +727,7 @@ static int s6e3ha2_enable(struct drm_panel *panel) /* brightness setting */ - s6e3ha2_set_brightness(ctx->bl_dev); + s6e3ha2_set_brightness(ctx); s6e3ha2_aor_control(ctx); s6e3ha2_caps_elvss_set(ctx); s6e3ha2_gamma_update(ctx); -- 2.7.4