From patchwork Tue Oct 17 21:13:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Paul X-Patchwork-Id: 10012869 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 85157600CC for ; Tue, 17 Oct 2017 21:13:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7725828A3F for ; Tue, 17 Oct 2017 21:13:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6B63E28A41; Tue, 17 Oct 2017 21:13:56 +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 B392D28A3F for ; Tue, 17 Oct 2017 21:13:55 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 18AD96E777; Tue, 17 Oct 2017 21:13:55 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-it0-x22e.google.com (mail-it0-x22e.google.com [IPv6:2607:f8b0:4001:c0b::22e]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5B36E6E777 for ; Tue, 17 Oct 2017 21:13:53 +0000 (UTC) Received: by mail-it0-x22e.google.com with SMTP id o135so4027486itb.0 for ; Tue, 17 Oct 2017 14:13:53 -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=X6qCiYEln08drG++wqkiHyTas587BAFegFBQPOIFhPI=; b=k/w+qiM86Yq/iNnWcgFp33yceFUCj3hVm1lFumej3yC+ykl0SNj58ZWr/M31+uEDOP PAWZyKqDE+gG1knxrTbmJ8Kcfmg9fx4lJcbAnXRIyU7Ge7BoZjfWyjG0/zaj95VL+st1 QkVYkebENOLhqvjjexOK1tU2WVTDENvcNxoOY= 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=X6qCiYEln08drG++wqkiHyTas587BAFegFBQPOIFhPI=; b=fgduFbOvcPG+QDPEQujubmxjtSDZuZSSxYnboUscXQqvWO0rKXEplaMX2ZGlghclMH letyoAWIhjFY7GC4qma1tc2oX+fDaRYDzWmQV6X83gEQQvsvOXLS177HqD8xtCXoSypG yiB1QqJSo/9FglqG3mJVIUs8KUxpl8iYW/LFXCy224AWwm7HIFWRRVxkwBJo90SXKpAs 5JQjt490cAPln5ZJMjJXSUUp+bCckalVF0u/E/TSSbAWKZB/J0iVZTZzyUScLx28u6hZ OSIcwRAtB/PIABd2rfAFhl+nx1EgkN2yVC3bK9+ZbWe3xVGhSaRXNk2CaJSxzAVn0X5R Rj7g== X-Gm-Message-State: AMCzsaWFW2PBqOxXRyo8edVJKcGHVTCE4b9oaRxEgnJo6lZ5N18k3y6u j6Q9wJ41fQ9dle+s6kL2hNUnnX+wlqw= X-Google-Smtp-Source: ABhQp+SjV0VhzQXxHWLPbMi/S5Y3ZgQ4/9qivY4RzgO4+qyDz99N1HjLUFjKIm1yaYU/CyuS/DzrBA== X-Received: by 10.36.210.198 with SMTP id z189mr6982260itf.65.1508274832400; Tue, 17 Oct 2017 14:13:52 -0700 (PDT) Received: from rosewood.cam.corp.google.com ([2620:0:1013:0:f685:3152:9ba1:429a]) by smtp.gmail.com with ESMTPSA id f2sm5220677ioj.73.2017.10.17.14.13.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Oct 2017 14:13:51 -0700 (PDT) From: Sean Paul To: dri-devel@lists.freedesktop.org Subject: [PATCH v3 03/12] drm/panel: Keep track of enabled/prepared Date: Tue, 17 Oct 2017 17:13:06 -0400 Message-Id: <20171017211321.7992-4-seanpaul@chromium.org> X-Mailer: git-send-email 2.15.0.rc1.287.g2b38de12cc-goog In-Reply-To: <20171017211321.7992-1-seanpaul@chromium.org> References: <20171017211321.7992-1-seanpaul@chromium.org> Cc: Daniel Vetter , thierry.reding@gmail.com, Daniel Vetter 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 adds state tracking to the drm_panel functions which keep track of enabled and prepared. If the calls are unbalanced, a WARNING is issued. The motivation for this change is that a number of panel drivers (including panel-simple) all do this to protect their regulator refcounts. The atomic framework ensures the calls are balanced, and there aren't any panel drivers being used by legacy drivers. As such, these checks are useless, but let's add a WARNING just in case something crazy happens (like a legacy driver using a panel). Less code == better. Changes in v2: - Reduced enabled/prepared bools to one enum (Andrzej) - Don't update state if the operation fails (Andrzej) - Issue warning even if operation is not implemented Changes in v3: - Functions no longer static inline (Daniel) - Added a helper function to share state change code (Andrzej) - Only warn when a panel is present (Daniel) - Update state if function is not implemented (Andrzej) Cc: Andrzej Hajda Cc: Daniel Vetter Signed-off-by: Sean Paul --- drivers/gpu/drm/drm_panel.c | 63 ++++++++++++++++++++++++++++++++++++--------- include/drm/drm_panel.h | 15 +++++++++++ 2 files changed, 66 insertions(+), 12 deletions(-) diff --git a/drivers/gpu/drm/drm_panel.c b/drivers/gpu/drm/drm_panel.c index 6f28598a5d0e..6547850b5e80 100644 --- a/drivers/gpu/drm/drm_panel.c +++ b/drivers/gpu/drm/drm_panel.c @@ -21,6 +21,7 @@ * DEALINGS IN THE SOFTWARE. */ +#include #include #include @@ -48,6 +49,7 @@ static LIST_HEAD(panel_list); void drm_panel_init(struct drm_panel *panel) { INIT_LIST_HEAD(&panel->list); + panel->state = DRM_PANEL_POWER_OFF; } EXPORT_SYMBOL(drm_panel_init); @@ -126,6 +128,23 @@ int drm_panel_detach(struct drm_panel *panel) } EXPORT_SYMBOL(drm_panel_detach); +static int drm_panel_change_state(struct drm_panel *panel, + enum drm_panel_state cur_state, + enum drm_panel_state new_state, + int (*hook)(struct drm_panel *panel)) +{ + int ret; + + WARN_ON(panel->state != cur_state); + if (hook) + ret = hook(panel); + else + ret = -ENOSYS; + + panel->state = new_state; + return ret; +} + /** * drm_panel_unprepare - power off a panel * @panel: DRM panel @@ -135,14 +154,19 @@ EXPORT_SYMBOL(drm_panel_detach); * is usually no longer possible to communicate with the panel until another * call to drm_panel_prepare(). * + * Atomic framework will ensure that prepare/unprepare are properly balanced. + * If this is not the case, a WARNING will be issued. + * * Return: 0 on success or a negative error code on failure. */ int drm_panel_unprepare(struct drm_panel *panel) { - if (panel && panel->funcs && panel->funcs->unprepare) - return panel->funcs->unprepare(panel); + if (!panel) + return -EINVAL; - return panel ? -ENOSYS : -EINVAL; + return drm_panel_change_state(panel, DRM_PANEL_POWER_PREPARED, + DRM_PANEL_POWER_OFF, + panel->funcs ? panel->funcs->unprepare : NULL); } EXPORT_SYMBOL(drm_panel_unprepare); @@ -154,14 +178,19 @@ EXPORT_SYMBOL(drm_panel_unprepare); * drivers. For smart panels it should still be possible to communicate with * the integrated circuitry via any command bus after this call. * + * Atomic framework will ensure that enable/disable are properly balanced. + * If this is not the case, a WARNING will be issued. + * * Return: 0 on success or a negative error code on failure. */ int drm_panel_disable(struct drm_panel *panel) { - if (panel && panel->funcs && panel->funcs->disable) - return panel->funcs->disable(panel); + if (!panel) + return -EINVAL; - return panel ? -ENOSYS : -EINVAL; + return drm_panel_change_state(panel, DRM_PANEL_POWER_ENABLED, + DRM_PANEL_POWER_PREPARED, + panel->funcs ? panel->funcs->disable : NULL); } EXPORT_SYMBOL(drm_panel_disable); @@ -173,14 +202,19 @@ EXPORT_SYMBOL(drm_panel_disable); * the panel. After this has completed it is possible to communicate with any * integrated circuitry via a command bus. * + * Atomic framework will ensure that prepare/unprepare are properly balanced. + * If this is not the case, a WARNING will be issued. + * * Return: 0 on success or a negative error code on failure. */ int drm_panel_prepare(struct drm_panel *panel) { - if (panel && panel->funcs && panel->funcs->prepare) - return panel->funcs->prepare(panel); + if (!panel) + return -EINVAL; - return panel ? -ENOSYS : -EINVAL; + return drm_panel_change_state(panel, DRM_PANEL_POWER_OFF, + DRM_PANEL_POWER_PREPARED, + panel->funcs ? panel->funcs->prepare: NULL); } EXPORT_SYMBOL(drm_panel_prepare); @@ -192,14 +226,19 @@ EXPORT_SYMBOL(drm_panel_prepare); * and the backlight to be enabled. Content will be visible on screen after * this call completes. * + * Atomic framework will ensure that enable/disable are properly balanced. + * If this is not the case, a WARNING will be issued. + * * Return: 0 on success or a negative error code on failure. */ int drm_panel_enable(struct drm_panel *panel) { - if (panel && panel->funcs && panel->funcs->enable) - return panel->funcs->enable(panel); + if (!panel) + return -EINVAL; - return panel ? -ENOSYS : -EINVAL; + return drm_panel_change_state(panel, DRM_PANEL_POWER_PREPARED, + DRM_PANEL_POWER_ENABLED, + panel->funcs ? panel->funcs->enable: NULL); } EXPORT_SYMBOL(drm_panel_enable); diff --git a/include/drm/drm_panel.h b/include/drm/drm_panel.h index 0a9442069d3c..7e6a552005d7 100644 --- a/include/drm/drm_panel.h +++ b/include/drm/drm_panel.h @@ -77,6 +77,18 @@ struct drm_panel_funcs { struct display_timing *timings); }; +/** + * enum drm_panel_state - describes the state of a panel + * @DRM_PANEL_POWER_OFF: panel is currently off (accessible from PREPARED) + * @DRM_PANEL_POWER_PREPARED: panel is prepared (accessible from OFF || ENABLED) + * @DRM_PANEL_POWER_ENABLED: panel is enabled (accessible from PREPARED) + */ +enum drm_panel_state { + DRM_PANEL_POWER_OFF, + DRM_PANEL_POWER_PREPARED, + DRM_PANEL_POWER_ENABLED +}; + /** * struct drm_panel - DRM panel object * @drm: DRM device owning the panel @@ -84,6 +96,7 @@ struct drm_panel_funcs { * @dev: parent device of the panel * @funcs: operations that can be performed on the panel * @list: panel entry in registry + * @state: keeps track of the panel power status */ struct drm_panel { struct drm_device *drm; @@ -93,6 +106,8 @@ struct drm_panel { const struct drm_panel_funcs *funcs; struct list_head list; + + enum drm_panel_state state; }; /**