From patchwork Thu Mar 16 22:08:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Paul X-Patchwork-Id: 9629365 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 21F9660132 for ; Thu, 16 Mar 2017 22:09:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 118B328647 for ; Thu, 16 Mar 2017 22:09:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0563D28654; Thu, 16 Mar 2017 22:09:15 +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_SIGNED, 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 4D80928647 for ; Thu, 16 Mar 2017 22:09:14 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A3A9A6EC12; Thu, 16 Mar 2017 22:09:13 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-qk0-x22f.google.com (mail-qk0-x22f.google.com [IPv6:2607:f8b0:400d:c09::22f]) by gabe.freedesktop.org (Postfix) with ESMTPS id 921886EC12 for ; Thu, 16 Mar 2017 22:09:12 +0000 (UTC) Received: by mail-qk0-x22f.google.com with SMTP id y76so51622827qkb.0 for ; Thu, 16 Mar 2017 15:09:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=GBNVOxGQ3r50UMPINZ9edt4wvecIHR+bC+4sfiaupKQ=; b=LY+1fmd5NZPUaL8oX3+LVFOwfCcyIqb/a4yHL7jsPJ+hcChCq+40ROhurIb0Re5t4N XLP9xIqKUkw21P+Rlm6KMBviowvIDIAw94BFexlQV4PvQOJAbLu5SZZ8lB3RCvcrB6bn T454lA792+OQgQpy0iN25d5c/q1UcJEqOox3Y= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=GBNVOxGQ3r50UMPINZ9edt4wvecIHR+bC+4sfiaupKQ=; b=UDe7hzfjsWlzlrgwsFE4FT4UL/20GSEpU9TBF34yKAmjluKdb8miDq2GioGQAe5JX7 QtL7Ws1hU6h38YDOM219mymrPqOkPe+quOxn7CLXj7vJeGvBSmIO0mU0VzXdY61J3SRW 5jlhlHCW9h4gl4CPZHi+Vp+48HI7jLI8oR/a0851EnlIU84k0ee0pAEicHJj1zqBQrLQ csbG+xRfOx99uLScRuUrKk2kGzII+YBvdBT6b3hWZ6NcwkZn4tsvD+mnD9XR9R8Ni/tQ 6zNvgEA//2siD/v9zNKVV8d4Je+MiWlXezf2LJboK0rmA/1NOiSlLaDZcwXb8gnlLwqi ysAQ== X-Gm-Message-State: AFeK/H27mXXL7eJb5iMfKN8wwvJYPs7P9P0CwDh06W8B0BHkiMUqhQO8XDHGzBYIn48vrsr7 X-Received: by 10.55.32.66 with SMTP id g63mr11108263qkg.92.1489702151262; Thu, 16 Mar 2017 15:09:11 -0700 (PDT) Received: from boxwood.roam.corp.google.com (cpe-75-189-128-87.nc.res.rr.com. [75.189.128.87]) by smtp.gmail.com with ESMTPSA id y33sm4585425qta.27.2017.03.16.15.09.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 16 Mar 2017 15:09:10 -0700 (PDT) From: Sean Paul To: dri-devel@lists.freedesktop.org Subject: [RFC PATCH 1/3] drm/panel: Pull common panel code out into helpers Date: Thu, 16 Mar 2017 18:08:31 -0400 Message-Id: <20170316220837.17347-2-seanpaul@chromium.org> X-Mailer: git-send-email 2.12.0.367.g23dc2f6d3c-goog In-Reply-To: <20170316220837.17347-1-seanpaul@chromium.org> References: <20170316220837.17347-1-seanpaul@chromium.org> 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 This patch pulls the regulator/backlight/enable_gpio code out of panel-simple and creates a new panel-common helper with it. This helper will be useful to the more complicated drivers which cannot use panel-simple. Signed-off-by: Sean Paul --- drivers/gpu/drm/panel/Kconfig | 20 +++-- drivers/gpu/drm/panel/Makefile | 1 + drivers/gpu/drm/panel/panel-common.c | 149 +++++++++++++++++++++++++++++++++++ drivers/gpu/drm/panel/panel-common.h | 44 +++++++++++ drivers/gpu/drm/panel/panel-simple.c | 112 ++++---------------------- 5 files changed, 225 insertions(+), 101 deletions(-) create mode 100644 drivers/gpu/drm/panel/panel-common.c create mode 100644 drivers/gpu/drm/panel/panel-common.h diff --git a/drivers/gpu/drm/panel/Kconfig b/drivers/gpu/drm/panel/Kconfig index 62aba976e744..be8590724042 100644 --- a/drivers/gpu/drm/panel/Kconfig +++ b/drivers/gpu/drm/panel/Kconfig @@ -7,16 +7,26 @@ config DRM_PANEL menu "Display Panels" depends on DRM && DRM_PANEL +config DRM_PANEL_COMMON + bool + depends on OF + depends on BACKLIGHT_CLASS_DEVICE + select VIDEOMODE_HELPERS + help + Common DRM panel helpers for panels using a regulator and a GPIO to + be powered up. Optionally a backlight can be attached so that it can + be automatically turned off when the panel goes into a low power + state. + config DRM_PANEL_SIMPLE tristate "support for simple panels" depends on OF - depends on BACKLIGHT_CLASS_DEVICE + select DRM_PANEL_COMMON select VIDEOMODE_HELPERS help - DRM panel driver for dumb panels that need at most a regulator and - a GPIO to be powered up. Optionally a backlight can be attached so - that it can be automatically turned off when the panel goes into a - low power state. + DRM panel driver for dumb panels that are not more complicated than + what the common helpers provide for power on/off. Allows for mode + probing via ddc bus, or using fixed modes. config DRM_PANEL_JDI_LT070ME05000 tristate "JDI LT070ME05000 WUXGA DSI panel" diff --git a/drivers/gpu/drm/panel/Makefile b/drivers/gpu/drm/panel/Makefile index a5c7ec0236e0..48c84db88c48 100644 --- a/drivers/gpu/drm/panel/Makefile +++ b/drivers/gpu/drm/panel/Makefile @@ -1,3 +1,4 @@ +obj-$(CONFIG_DRM_PANEL_COMMON) += panel-common.o obj-$(CONFIG_DRM_PANEL_SIMPLE) += panel-simple.o obj-$(CONFIG_DRM_PANEL_JDI_LT070ME05000) += panel-jdi-lt070me05000.o obj-$(CONFIG_DRM_PANEL_LG_LG4573) += panel-lg-lg4573.o diff --git a/drivers/gpu/drm/panel/panel-common.c b/drivers/gpu/drm/panel/panel-common.c new file mode 100644 index 000000000000..2979d7439bdc --- /dev/null +++ b/drivers/gpu/drm/panel/panel-common.c @@ -0,0 +1,149 @@ +/* + * Copyright (C) 2017 Google, Inc. + * + * This software is licensed under the terms of the GNU General Public + * License version 2, as published by the Free Software Foundation, and + * may be copied, distributed, and modified under those terms. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include +#include +#include +#include + +#include + +#include "panel-common.h" + +int panel_common_init(struct device *dev, struct panel_common *common, + const char *supply_name, const char *gpio_name, + const char *backlight_name) +{ + struct device_node *backlight; + int err; + + common->dev = dev; + common->enabled = false; + common->prepared = false; + + common->supply = devm_regulator_get(dev, supply_name); + if (IS_ERR(common->supply)) + return PTR_ERR(common->supply); + + common->enable_gpio = devm_gpiod_get_optional(dev, gpio_name, + GPIOD_OUT_LOW); + if (IS_ERR(common->enable_gpio)) { + err = PTR_ERR(common->enable_gpio); + dev_err(dev, "failed to request GPIO: %d\n", err); + return err; + } + + backlight = of_parse_phandle(dev->of_node, backlight_name, 0); + if (backlight) { + common->backlight = of_find_backlight_by_node(backlight); + of_node_put(backlight); + + if (!common->backlight) + return -EPROBE_DEFER; + } + + return 0; +} +EXPORT_SYMBOL(panel_common_init); + +void panel_common_fini(struct panel_common *common) +{ + if (common->backlight) + put_device(&common->backlight->dev); +} +EXPORT_SYMBOL(panel_common_fini); + +int panel_common_prepare(struct panel_common *common, unsigned int delay) +{ + int err; + + if (common->prepared) + return 0; + + err = regulator_enable(common->supply); + if (err < 0) { + dev_err(common->dev, "failed to enable supply: %d\n", err); + return err; + } + + if (common->enable_gpio) + gpiod_set_value_cansleep(common->enable_gpio, 1); + + if (delay) + msleep(delay); + + common->prepared = true; + + return 0; +} +EXPORT_SYMBOL(panel_common_prepare); + +int panel_common_unprepare(struct panel_common *common, unsigned int delay) +{ + if (!common->prepared) + return 0; + + if (common->enable_gpio) + gpiod_set_value_cansleep(common->enable_gpio, 0); + + regulator_disable(common->supply); + + if (delay) + msleep(delay); + + common->prepared = false; + + return 0; +} +EXPORT_SYMBOL(panel_common_unprepare); + +int panel_common_enable(struct panel_common *common, unsigned int delay) +{ + if (common->enabled) + return 0; + + if (delay) + msleep(delay); + + if (common->backlight) { + common->backlight->props.state &= ~BL_CORE_FBBLANK; + common->backlight->props.power = FB_BLANK_UNBLANK; + backlight_update_status(common->backlight); + } + + common->enabled = true; + + return 0; +} +EXPORT_SYMBOL(panel_common_enable); + +int panel_common_disable(struct panel_common *common, unsigned int delay) +{ + if (!common->enabled) + return 0; + + if (common->backlight) { + common->backlight->props.power = FB_BLANK_POWERDOWN; + common->backlight->props.state |= BL_CORE_FBBLANK; + backlight_update_status(common->backlight); + } + + if (delay) + msleep(delay); + + common->enabled = false; + + return 0; +} +EXPORT_SYMBOL(panel_common_disable); diff --git a/drivers/gpu/drm/panel/panel-common.h b/drivers/gpu/drm/panel/panel-common.h new file mode 100644 index 000000000000..dc3b24ac2938 --- /dev/null +++ b/drivers/gpu/drm/panel/panel-common.h @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2017 Google, Inc. + * + * This software is licensed under the terms of the GNU General Public + * License version 2, as published by the Free Software Foundation, and + * may be copied, distributed, and modified under those terms. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#ifndef _PANEL_COMMON_H_ +#define _PANEL_COMMON_H_ + +struct backlight_device; +struct regulator; +struct i2c_adapter; +struct gpio_desc; + +struct panel_common { + struct device *dev; + + bool prepared; + bool enabled; + + struct backlight_device *backlight; + struct regulator *supply; + + struct gpio_desc *enable_gpio; +}; + +int panel_common_init(struct device *dev, struct panel_common *common, + const char *supply_name, const char *gpio_name, + const char *backlight_name); +void panel_common_fini(struct panel_common *common); + +int panel_common_prepare(struct panel_common *common, unsigned int delay); +int panel_common_unprepare(struct panel_common *common, unsigned int delay); +int panel_common_enable(struct panel_common *common, unsigned int delay); +int panel_common_disable(struct panel_common *common, unsigned int delay); + +#endif // _PANEL_COMMON_H_ diff --git a/drivers/gpu/drm/panel/panel-simple.c b/drivers/gpu/drm/panel/panel-simple.c index 89eb0422821c..1c21ff2dcd36 100644 --- a/drivers/gpu/drm/panel/panel-simple.c +++ b/drivers/gpu/drm/panel/panel-simple.c @@ -21,12 +21,9 @@ * DEALINGS IN THE SOFTWARE. */ -#include -#include #include #include #include -#include #include #include @@ -36,6 +33,8 @@ #include