From patchwork Sat Apr 14 07:25:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abhinav Kumar X-Patchwork-Id: 10340931 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7B90B60153 for ; Sat, 14 Apr 2018 07:25:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 641A328A56 for ; Sat, 14 Apr 2018 07:25:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 58A4028A6E; Sat, 14 Apr 2018 07:25:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id DF8D728A56 for ; Sat, 14 Apr 2018 07:25:26 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 876EB6E016; Sat, 14 Apr 2018 07:25:23 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from smtp.codeaurora.org (smtp.codeaurora.org [198.145.29.96]) by gabe.freedesktop.org (Postfix) with ESMTPS id AFD606E004; Sat, 14 Apr 2018 07:25:22 +0000 (UTC) Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 975A860F5C; Sat, 14 Apr 2018 07:25:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1523690722; bh=GTl3B6bfjClk2zPUphrHkSCUKHfzpTfne59bUtXv6gk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oBifQGjZtQROP1BG8kD6AS+e3GtlpMvZ0YR1uMhuXyer9v3XVzuI++GBkNzEEbmg7 ub7AHmdsEUsfOWvEVcRF2VdUa5YB1zA2wOUUC0QoVJ3mkEwBH7YpIDWu+dAYZ2J1jZ orLmbJYI5glC8s4tX0KoHwjOBwwXEaD8/TdZiL90= Received: from abhinavk-linux.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: abhinavk@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id AC7D6603AF; Sat, 14 Apr 2018 07:25:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1523690722; bh=GTl3B6bfjClk2zPUphrHkSCUKHfzpTfne59bUtXv6gk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oBifQGjZtQROP1BG8kD6AS+e3GtlpMvZ0YR1uMhuXyer9v3XVzuI++GBkNzEEbmg7 ub7AHmdsEUsfOWvEVcRF2VdUa5YB1zA2wOUUC0QoVJ3mkEwBH7YpIDWu+dAYZ2J1jZ orLmbJYI5glC8s4tX0KoHwjOBwwXEaD8/TdZiL90= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org AC7D6603AF Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=abhinavk@codeaurora.org From: Abhinav Kumar To: dri-devel@lists.freedesktop.org, freedreno@lists.freedesktop.org, linux-arm-msm@vger.kernel.org Subject: [DPU PATCH v2 2/2] drm/panel: add backlight control support for truly panel Date: Sat, 14 Apr 2018 00:25:13 -0700 Message-Id: <1523690713-22543-2-git-send-email-abhinavk@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1523690713-22543-1-git-send-email-abhinavk@codeaurora.org> References: <1523690713-22543-1-git-send-email-abhinavk@codeaurora.org> 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: jeykumar@quicinc.com, Abhinav Kumar , hoegsberg@google.com, chandanu@codeaurora.org MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Register truly panel as a backlight led device and provide methods to control its backlight operation. Changes in v2: - Removed redundant NULL checks - Arranged headers alphabetically - Formatting fixes Signed-off-by: Abhinav Kumar --- drivers/gpu/drm/panel/panel-truly-nt35597.c | 91 +++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/drivers/gpu/drm/panel/panel-truly-nt35597.c b/drivers/gpu/drm/panel/panel-truly-nt35597.c index 5bd5fdc..ec9f973 100644 --- a/drivers/gpu/drm/panel/panel-truly-nt35597.c +++ b/drivers/gpu/drm/panel/panel-truly-nt35597.c @@ -13,6 +13,7 @@ */ #include +#include #include #include #include @@ -25,6 +26,9 @@ #include #include +#define BL_NODE_NAME_SIZE 32 +#define PRIM_DISPLAY_NODE 0 + static const char * const regulator_names[] = { "vdda", "vdispp", @@ -51,6 +55,8 @@ struct truly_wqxga { struct gpio_desc *mode_gpio; struct backlight_device *backlight; + /* WLED params */ + struct led_trigger *wled; struct videomode vm; struct mipi_dsi_device *dsi[2]; @@ -454,6 +460,82 @@ static void truly_wqxga_panel_del(struct truly_wqxga *ctx) drm_panel_remove(&ctx->panel); } +static void truly_wqxga_bkl_unregister(struct truly_wqxga *ctx) +{ + if (ctx->backlight) + put_device(&ctx->backlight->dev); +} + +static int truly_backlight_device_update_status(struct backlight_device *bd) +{ + int brightness; + int max_brightness; + int rc = 0; + struct truly_wqxga *ctx = dev_get_drvdata(&bd->dev); + + brightness = bd->props.brightness; + max_brightness = bd->props.max_brightness; + + if ((bd->props.power != FB_BLANK_UNBLANK) || + (bd->props.state & BL_CORE_FBBLANK) || + (bd->props.state & BL_CORE_SUSPENDED)) + brightness = 0; + + if (brightness > max_brightness) + brightness = max_brightness; + + if (ctx->wled) + led_trigger_event(ctx->wled, brightness); + + return rc; +} + +static int truly_backlight_device_get_brightness(struct backlight_device *bd) +{ + return bd->props.brightness; +} + +static const struct backlight_ops truly_backlight_device_ops = { + .update_status = truly_backlight_device_update_status, + .get_brightness = truly_backlight_device_get_brightness, +}; + +static int truly_backlight_setup(struct truly_wqxga *ctx) +{ + struct backlight_properties props; + char bl_node_name[BL_NODE_NAME_SIZE]; + + if (!ctx->backlight) { + memset(&props, 0, sizeof(props)); + props.type = BACKLIGHT_RAW; + props.power = FB_BLANK_UNBLANK; + props.max_brightness = 4096; + + snprintf(bl_node_name, BL_NODE_NAME_SIZE, "panel%u-backlight", + PRIM_DISPLAY_NODE); + + ctx->backlight = backlight_device_register(bl_node_name, + ctx->dev, ctx, + &truly_backlight_device_ops, &props); + + if (IS_ERR_OR_NULL(ctx->backlight)) { + pr_err("Failed to register backlight\n"); + ctx->backlight = NULL; + return -ENODEV; + } + + /* Register with the LED driver interface */ + led_trigger_register_simple("bkl-trigger", &ctx->wled); + + if (!ctx->wled) { + pr_err("backlight led registration failed\n"); + return -ENODEV; + } + } + + return 0; +} + static int truly_wqxga_probe(struct mipi_dsi_device *dsi) { struct device *dev = &dsi->dev; @@ -530,6 +612,12 @@ static int truly_wqxga_probe(struct mipi_dsi_device *dsi) goto err_panel_add; } + ret = truly_backlight_setup(ctx); + if (ret) { + dev_err(dev, "backlight setup failed\n"); + goto err_backlight; + } + ret = mipi_dsi_attach(dsi); if (ret < 0) { dev_err(dev, "master dsi attach failed\n"); @@ -549,6 +637,8 @@ static int truly_wqxga_probe(struct mipi_dsi_device *dsi) err_dsi_attach_sec: mipi_dsi_detach(ctx->dsi[0]); err_dsi_attach: + truly_wqxga_bkl_unregister(ctx); +err_backlight: truly_wqxga_panel_del(ctx); err_panel_add: mipi_dsi_device_unregister(secondary); @@ -570,6 +660,7 @@ static int truly_wqxga_remove(struct mipi_dsi_device *dsi) mipi_dsi_detach(ctx->dsi[1]); mipi_dsi_device_unregister(ctx->dsi[1]); } + truly_wqxga_bkl_unregister(ctx); truly_wqxga_panel_del(ctx); kfree(ctx); }