From patchwork Thu Jun 2 01:48:19 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vinay Simha B N X-Patchwork-Id: 9149527 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 46AFE60221 for ; Thu, 2 Jun 2016 08:24:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3569B25D97 for ; Thu, 2 Jun 2016 08:24:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2A2622665D; Thu, 2 Jun 2016 08:24:21 +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=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, 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]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A5C2425D97 for ; Thu, 2 Jun 2016 08:24:20 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C8B456E3C0; Thu, 2 Jun 2016 08:24:00 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pf0-x244.google.com (mail-pf0-x244.google.com [IPv6:2607:f8b0:400e:c00::244]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2CF966EAF9 for ; Thu, 2 Jun 2016 01:48:43 +0000 (UTC) Received: by mail-pf0-x244.google.com with SMTP id 62so5946532pfd.3 for ; Wed, 01 Jun 2016 18:48:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=txpAPQi+hCQ26ZVdZUOmbDu7W6qEII3TjqY99d9jyeI=; b=WkotZJEd9OlpEZY9TTcS2IPJKgGWWMh/Xf35jCPSjAvFfRL+q0Vla4F+bM+CCt7oN6 GU6dX9fwRpdDz8e2aDeIzgXYClrsTKLJIHJF98yL3dRns43yIEylWdRUfsK9tATSunJ4 06CldWH9ZbEMUPZufwq7Khpiyh3tScTpzWhGZ+/PtWmPWZy3FNXhLmoRY9Grww3WP10x HU7Q8cann2lkrrrTg7HnuC5seNj4KP6efaGek+xs9Jhy9pyVtsNGQMG78oy/mXeLR4X7 37IjT9zpx6u1PCx4d2H534NMMbJ5H7PyE/Cvlu2yue4VMmyHa6DuRk1KxA8oZR9sWjbU /rkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=txpAPQi+hCQ26ZVdZUOmbDu7W6qEII3TjqY99d9jyeI=; b=loM9vaM8Y2CVB5q7uvTL1THNz+Oeq1QXpciE85mBaqR5jY7NyBW3X/vLrO0WyTrm7Z RXzaZl44Y+GK3Or1DvdpqyllbQ2SBqQSpZJkmd8Ie/B3ot+zIoP9vEnUPi5/7v2ZumsK CP7HqDvNObLaYOhUNjngMdF2Va+6moGMnegqGKb4RkMWVfSiu6JDzbeWDO2c/PVRqSbs MeALoa3f1vSDRySM6ho+TiDgJbjz8CVwymAyUvX7y05MNKoIMvJQQosxpY8Wm3ZncHSL 1Ru/vnUp44aqBdnuHwIQ4JdEfaD9R2+tBGOdUCwZbNeq0kmNo7wePaer/0dONRphXTeT 4rmA== X-Gm-Message-State: ALyK8tJy5IszN5roSrtp2p0wP53kLkBjGHPnIgx2tdggXW8l+6iLnqusAeMM9+PkaAfCjQ== X-Received: by 10.98.64.21 with SMTP id n21mr14489133pfa.161.1464832122189; Wed, 01 Jun 2016 18:48:42 -0700 (PDT) Received: from localhost.localdomain ([122.172.131.85]) by smtp.gmail.com with ESMTPSA id 74sm50977432pfv.8.2016.06.01.18.48.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 01 Jun 2016 18:48:41 -0700 (PDT) From: Vinay Simha BN To: Subject: [PATCH 2/2] drm/dsi: Implement dcs backlight brightness Date: Thu, 2 Jun 2016 07:18:19 +0530 Message-Id: <1464832099-22402-2-git-send-email-simhavcs@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1464832099-22402-1-git-send-email-simhavcs@gmail.com> References: <1464832099-22402-1-git-send-email-simhavcs@gmail.com> X-Mailman-Approved-At: Thu, 02 Jun 2016 08:23:59 +0000 Cc: open list , "open list:DRM DRIVERS" , Vinay Simha BN , Archit Taneja X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Provide a small convenience wrapper that set/get the backlight brightness control and creates the backlight device for the panel interface Cc: John Stultz Cc: Sumit Semwal Cc: Archit Taneja Cc: Rob Clark Signed-off-by: Vinay Simha BN --- v1: *tested in nexus7 2nd gen. --- drivers/gpu/drm/drm_mipi_dsi.c | 63 ++++++++++++++++++++++++++++++++++++++++++ include/drm/drm_mipi_dsi.h | 3 ++ 2 files changed, 66 insertions(+) diff --git a/drivers/gpu/drm/drm_mipi_dsi.c b/drivers/gpu/drm/drm_mipi_dsi.c index 2f0b85c..ac4521e 100644 --- a/drivers/gpu/drm/drm_mipi_dsi.c +++ b/drivers/gpu/drm/drm_mipi_dsi.c @@ -1026,6 +1026,69 @@ int mipi_dsi_dcs_set_pixel_format(struct mipi_dsi_device *dsi, u8 format) } EXPORT_SYMBOL(mipi_dsi_dcs_set_pixel_format); +static int dsi_dcs_bl_get_brightness(struct backlight_device *bl) +{ + struct mipi_dsi_device *dsi = bl_get_data(bl); + int ret; + u8 brightness; + + dsi->mode_flags &= ~MIPI_DSI_MODE_LPM; + + ret = mipi_dsi_dcs_read(dsi, MIPI_DCS_GET_DISPLAY_BRIGHTNESS, + &brightness, sizeof(brightness)); + if (ret < 0) + return ret; + + dsi->mode_flags |= MIPI_DSI_MODE_LPM; + + return brightness; +} + +static int dsi_dcs_bl_update_status(struct backlight_device *bl) +{ + struct mipi_dsi_device *dsi = bl_get_data(bl); + int ret; + u8 brightness = bl->props.brightness; + + dsi->mode_flags &= ~MIPI_DSI_MODE_LPM; + + ret = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_DISPLAY_BRIGHTNESS, + &brightness, sizeof(brightness)); + if (ret < 0) + return ret; + + dsi->mode_flags |= MIPI_DSI_MODE_LPM; + + return 0; +} + +static const struct backlight_ops dsi_bl_ops = { + .update_status = dsi_dcs_bl_update_status, + .get_brightness = dsi_dcs_bl_get_brightness, +}; + +/** + * drm_panel_create_dsi_backlight() - creates the backlight device for the panel + * @dsi: DSI peripheral device + * + * @return a struct backlight on success, or an ERR_PTR on error + */ +struct backlight_device + *drm_panel_create_dsi_backlight(struct mipi_dsi_device *dsi) +{ + struct device *dev = &dsi->dev; + struct backlight_properties props; + + memset(&props, 0, sizeof(props)); + props.type = BACKLIGHT_RAW; + props.brightness = 255; + props.max_brightness = 255; + + return devm_backlight_device_register(dev, dev_name(dev), dev, dsi, + &dsi_bl_ops, &props); +} +EXPORT_SYMBOL(drm_panel_create_dsi_backlight); + static int mipi_dsi_drv_probe(struct device *dev) { struct mipi_dsi_driver *drv = to_mipi_dsi_driver(dev->driver); diff --git a/include/drm/drm_mipi_dsi.h b/include/drm/drm_mipi_dsi.h index 2788dbe..9dd6a97 100644 --- a/include/drm/drm_mipi_dsi.h +++ b/include/drm/drm_mipi_dsi.h @@ -12,6 +12,7 @@ #ifndef __DRM_MIPI_DSI_H__ #define __DRM_MIPI_DSI_H__ +#include #include struct mipi_dsi_host; @@ -269,6 +270,8 @@ int mipi_dsi_dcs_set_tear_off(struct mipi_dsi_device *dsi); int mipi_dsi_dcs_set_tear_on(struct mipi_dsi_device *dsi, enum mipi_dsi_dcs_tear_mode mode); int mipi_dsi_dcs_set_pixel_format(struct mipi_dsi_device *dsi, u8 format); +struct backlight_device + *drm_panel_create_dsi_backlight(struct mipi_dsi_device *dsi); /** * struct mipi_dsi_driver - DSI driver