From patchwork Fri Dec 14 17:27:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Saenz Julienne X-Patchwork-Id: 10732855 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1A2DF14E2 for ; Mon, 17 Dec 2018 07:53:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 11D36299DD for ; Mon, 17 Dec 2018 07:53:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 06140299E1; Mon, 17 Dec 2018 07:53:35 +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.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED 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 968E8299DF for ; Mon, 17 Dec 2018 07:53:34 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 49A7F6E2B7; Mon, 17 Dec 2018 07:53:01 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mx1.suse.de (mx2.suse.de [195.135.220.15]) by gabe.freedesktop.org (Postfix) with ESMTPS id AF5E36F600 for ; Fri, 14 Dec 2018 17:27:18 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id D6BA0AD7E; Fri, 14 Dec 2018 17:27:16 +0000 (UTC) From: Nicolas Saenz Julienne To: Thierry Reding Subject: [PATCH] drm/panel: rpi-touchscreen: Add backlight support Date: Fri, 14 Dec 2018 18:27:04 +0100 Message-Id: <20181214172704.7936-1-nsaenzjulienne@suse.de> X-Mailer: git-send-email 2.19.2 MIME-Version: 1.0 X-Mailman-Approved-At: Mon, 17 Dec 2018 07:52:24 +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: stefan.wahren@i2se.com, David Airlie , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-rpi-kernel@lists.infradead.org, Nicolas Saenz Julienne Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP This patch exposes backlight control into userspace by creating a backlight device instead of directly accessing the PWM registers. The backlight driver can't go on a separate file as it shares the I2C bus & address with the panel. Signed-off-by: Nicolas Saenz Julienne --- .../drm/panel/panel-raspberrypi-touchscreen.c | 33 +++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c b/drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c index 2c9c9722734f..838b5c8767bc 100644 --- a/drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c +++ b/drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c @@ -52,6 +52,7 @@ #include #include #include +#include #include #include @@ -196,6 +197,7 @@ struct rpi_touchscreen { struct drm_panel base; struct mipi_dsi_device *dsi; struct i2c_client *i2c; + struct backlight_device *backlight; }; static const struct drm_display_mode rpi_touchscreen_modes[] = { @@ -256,7 +258,8 @@ static int rpi_touchscreen_disable(struct drm_panel *panel) { struct rpi_touchscreen *ts = panel_to_ts(panel); - rpi_touchscreen_i2c_write(ts, REG_PWM, 0); + ts->backlight->props.brightness = 0; + backlight_update_status(ts->backlight); rpi_touchscreen_i2c_write(ts, REG_POWERON, 0); udelay(1); @@ -300,7 +303,8 @@ static int rpi_touchscreen_enable(struct drm_panel *panel) msleep(100); /* Turn on the backlight. */ - rpi_touchscreen_i2c_write(ts, REG_PWM, 255); + ts->backlight->props.brightness = 255; + backlight_update_status(ts->backlight); /* Default to the same orientation as the closed source * firmware used for the panel. Runtime rotation @@ -358,12 +362,26 @@ static const struct drm_panel_funcs rpi_touchscreen_funcs = { .get_modes = rpi_touchscreen_get_modes, }; +static int raspberrypi_bl_update_status(struct backlight_device *bl) +{ + struct rpi_touchscreen *ts = bl_get_data(bl); + + rpi_touchscreen_i2c_write(ts, REG_PWM, bl->props.brightness); + + return 0; +} + +static const struct backlight_ops raspberrypi_bl_ops = { + .update_status = raspberrypi_bl_update_status, +}; + static int rpi_touchscreen_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { struct device *dev = &i2c->dev; struct rpi_touchscreen *ts; struct device_node *endpoint, *dsi_host_node; + struct backlight_properties props; struct mipi_dsi_host *host; int ret, ver; struct mipi_dsi_device_info info = { @@ -398,6 +416,17 @@ static int rpi_touchscreen_probe(struct i2c_client *i2c, /* Turn off at boot, so we can cleanly sequence powering on. */ rpi_touchscreen_i2c_write(ts, REG_POWERON, 0); + memset(&props, 0, sizeof(props)); + props.type = BACKLIGHT_RAW; + props.max_brightness = 255; + ts->backlight = devm_backlight_device_register(dev, dev_name(dev), dev, + ts, &raspberrypi_bl_ops, + &props); + if (IS_ERR(ts->backlight)) { + dev_err(dev, "Failed to create backlight device\n"); + return PTR_ERR(ts->backlight); + } + /* Look up the DSI host. It needs to probe before we do. */ endpoint = of_graph_get_next_endpoint(dev->of_node, NULL); dsi_host_node = of_graph_get_remote_port_parent(endpoint);