From patchwork Sat Sep 21 12:48:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Joonas_Kylm=C3=A4l=C3=A4?= X-Patchwork-Id: 11156101 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0D0CC13BD for ; Mon, 23 Sep 2019 06:55:35 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E9A452087C for ; Mon, 23 Sep 2019 06:55:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E9A452087C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=iki.fi Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 978EC6E0ED; Mon, 23 Sep 2019 06:55:23 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org X-Greylist: delayed 442 seconds by postgrey-1.36 at gabe; Sat, 21 Sep 2019 12:57:36 UTC Received: from mx1.riseup.net (mx1.riseup.net [198.252.153.129]) by gabe.freedesktop.org (Postfix) with ESMTPS id 47A7D6E04A for ; Sat, 21 Sep 2019 12:57:36 +0000 (UTC) Received: from capuchin.riseup.net (capuchin-pn.riseup.net [10.0.1.176]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (Client CN "*.riseup.net", Issuer "COMODO RSA Domain Validation Secure Server CA" (verified OK)) by mx1.riseup.net (Postfix) with ESMTPS id 5F6C51B932C; Sat, 21 Sep 2019 05:49:40 -0700 (PDT) X-Riseup-User-ID: E904BF54A9D00DEAC807850919DC7C9386AA0504DF66F720342B6B7C22BA1A3A Received: from [127.0.0.1] (localhost [127.0.0.1]) by capuchin.riseup.net (Postfix) with ESMTPSA id A3A7F120063; Sat, 21 Sep 2019 05:49:36 -0700 (PDT) From: =?utf-8?q?Joonas_Kylm=C3=A4l=C3=A4?= To: Thierry Reding , Sam Ravnborg , David Airlie , Daniel Vetter , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH] drm/panel: samsung: s6e8aa0: Add backlight control support Date: Sat, 21 Sep 2019 15:48:43 +0300 Message-Id: <20190921124843.6967-1-joonas.kylmala@iki.fi> MIME-Version: 1.0 X-Mailman-Approved-At: Mon, 23 Sep 2019 06:55:22 +0000 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: paul.kocialkowski@bootlin.com, =?utf-8?q?Joonas_Kylm=C3=A4l=C3=A4?= , GNUtoo@cyberdimension.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" This makes the backlight brightness controllable from the userspace. Signed-off-by: Joonas Kylmälä --- drivers/gpu/drm/panel/panel-samsung-s6e8aa0.c | 82 ++++++++++++++++++++------- 1 file changed, 60 insertions(+), 22 deletions(-) diff --git a/drivers/gpu/drm/panel/panel-samsung-s6e8aa0.c b/drivers/gpu/drm/panel/panel-samsung-s6e8aa0.c index dbced6501204..aa75934f5bed 100644 --- a/drivers/gpu/drm/panel/panel-samsung-s6e8aa0.c +++ b/drivers/gpu/drm/panel/panel-samsung-s6e8aa0.c @@ -10,8 +10,12 @@ * Eunchul Kim * Tomasz Figa * Andrzej Hajda + * + * Derived from panel-samsung-s6e63m0.c: + * Copyright (C) 2019 Paweł Chmiel */ +#include #include #include #include @@ -85,6 +89,8 @@ #define AID_2 (0x6) #define AID_3 (0x7) +#define MAX_BRIGHTNESS (GAMMA_LEVEL_NUM - 1) + typedef u8 s6e8aa0_gamma_table[GAMMA_TABLE_LEN]; struct s6e8aa0_variant { @@ -95,6 +101,7 @@ struct s6e8aa0_variant { struct s6e8aa0 { struct device *dev; struct drm_panel panel; + struct backlight_device *bl_dev; struct regulator_bulk_data supplies[2]; struct gpio_desc *reset_gpio; @@ -110,7 +117,6 @@ struct s6e8aa0 { u8 version; u8 id; const struct s6e8aa0_variant *variant; - int brightness; /* This field is tested by functions directly accessing DSI bus before * transfer, transfer is skipped if it is set. In case of transfer @@ -321,9 +327,10 @@ static void s6e8aa0_etc_elvss_control(struct s6e8aa0 *ctx) static void s6e8aa0_elvss_nvm_set_v142(struct s6e8aa0 *ctx) { + struct backlight_device *bd = ctx->bl_dev; u8 br; - switch (ctx->brightness) { + switch (bd->props.brightness) { case 0 ... 6: /* 30cd ~ 100cd */ br = 0xdf; break; @@ -762,24 +769,6 @@ static const struct s6e8aa0_variant s6e8aa0_variants[] = { } }; -static void s6e8aa0_brightness_set(struct s6e8aa0 *ctx) -{ - const u8 *gamma; - - if (ctx->error) - return; - - gamma = ctx->variant->gamma_tables[ctx->brightness]; - - if (ctx->version >= 142) - s6e8aa0_elvss_nvm_set(ctx); - - s6e8aa0_dcs_write(ctx, gamma, GAMMA_TABLE_LEN); - - /* update gamma table. */ - s6e8aa0_dcs_write_seq_static(ctx, 0xf7, 0x03); -} - static void s6e8aa0_panel_init(struct s6e8aa0 *ctx) { s6e8aa0_apply_level_1_key(ctx); @@ -791,7 +780,7 @@ static void s6e8aa0_panel_init(struct s6e8aa0 *ctx) s6e8aa0_panel_cond_set(ctx); s6e8aa0_display_condition_set(ctx); - s6e8aa0_brightness_set(ctx); + backlight_enable(ctx->bl_dev); s6e8aa0_etc_source_control(ctx); s6e8aa0_etc_pentile_control(ctx); s6e8aa0_elvss_nvm_set(ctx); @@ -974,6 +963,53 @@ static int s6e8aa0_parse_dt(struct s6e8aa0 *ctx) return 0; } +static int s6e8aa0_set_brightness(struct backlight_device *bd) +{ + struct s6e8aa0 *ctx = bl_get_data(bd); + const u8 *gamma; + + if (ctx->error) + return; + + gamma = ctx->variant->gamma_tables[bd->props.brightness]; + + if (ctx->version >= 142) + s6e8aa0_elvss_nvm_set(ctx); + + s6e8aa0_dcs_write(ctx, gamma, GAMMA_TABLE_LEN); + + /* update gamma table. */ + s6e8aa0_dcs_write_seq_static(ctx, 0xf7, 0x03); + + return s6e8aa0_clear_error(ctx); +} + +static const struct backlight_ops s6e8aa0_backlight_ops = { + .update_status = s6e8aa0_set_brightness, +}; + +static int s6e8aa0_backlight_register(struct s6e8aa0 *ctx) +{ + struct backlight_properties props = { + .type = BACKLIGHT_RAW, + .brightness = MAX_BRIGHTNESS, + .max_brightness = MAX_BRIGHTNESS + }; + struct device *dev = ctx->dev; + int ret = 0; + + ctx->bl_dev = devm_backlight_device_register(dev, "panel", dev, ctx, + &s6e8aa0_backlight_ops, + &props); + if (IS_ERR(ctx->bl_dev)) { + ret = PTR_ERR(ctx->bl_dev); + DRM_DEV_ERROR(dev, "error registering backlight device (%d)\n", + ret); + } + + return ret; +} + static int s6e8aa0_probe(struct mipi_dsi_device *dsi) { struct device *dev = &dsi->dev; @@ -1015,7 +1051,9 @@ static int s6e8aa0_probe(struct mipi_dsi_device *dsi) return PTR_ERR(ctx->reset_gpio); } - ctx->brightness = GAMMA_LEVEL_NUM - 1; + ret = s6e8aa0_backlight_register(ctx); + if (ret < 0) + return ret; drm_panel_init(&ctx->panel, dev, &s6e8aa0_drm_funcs, DRM_MODE_CONNECTOR_DSI);