From patchwork Thu Oct 12 17:55:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Paul X-Patchwork-Id: 10002457 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 F22BA60216 for ; Thu, 12 Oct 2017 17:56:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E508A28E57 for ; Thu, 12 Oct 2017 17:56:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D9A8828E61; Thu, 12 Oct 2017 17:56:11 +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 402FA28E57 for ; Thu, 12 Oct 2017 17:56:08 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A428A6E8E8; Thu, 12 Oct 2017 17:56:07 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-qt0-x22d.google.com (mail-qt0-x22d.google.com [IPv6:2607:f8b0:400d:c0d::22d]) by gabe.freedesktop.org (Postfix) with ESMTPS id D6C3C6E8E8 for ; Thu, 12 Oct 2017 17:56:05 +0000 (UTC) Received: by mail-qt0-x22d.google.com with SMTP id 8so15158201qtv.1 for ; Thu, 12 Oct 2017 10:56:05 -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=5hmgg8dKaOZyQz+g4SKheywgjqV1B8SpWfPHcZ6jzOE=; b=TtNjXu9RhbBJgwJUqqZ5m1VCeGGvwMrAVnihUnR5p3wS1MhDZTDQT7/y8/+bFDiFzA ilT764pdklD7D9SfVWW1wrrJEUKBkgmRMdQbeicFwnQcrKJOmyHD2Z0Ms9nmZLEXoHmr evUAv/hta4QrC+ZyFrHdyQEro0eogAE/RpEls= 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=5hmgg8dKaOZyQz+g4SKheywgjqV1B8SpWfPHcZ6jzOE=; b=uJDeWgPqgzP0P19iUKzkunLMy6BvkgivQlvesFG+RSEJ6NTxZftxg7MqS87P68tHot QB6fNmTqXYdalFt4zkVMN3C4aOaCWaCgxKcMp37v2J94+Zbvs225+HohbmNXRSkHRcfF XUI9l7FmYfXYD9aCfrjWrWNsRZ2b7ZvuRda9Kq9Es0Jfln2yukh+YDy0+ib6nCmZ7ofn iH6Hnwz/hL/xbshKxB9IN7hjZ+Lh+VLDRmncLOapuCycXUHCn9wPwSCzDwRa7ExKR4Rf aU5P3/Rm/0bTk+jG1TkPMcwSp3sLDAaJ2kHqtcsffljC+BGkTt8ZXis7AyaRBF4OGOvb QYSQ== X-Gm-Message-State: AMCzsaWOGhC8kgVWJh2hsUr/rb6/iShdTs3BEF4C8c/tTLhk+3yktvxZ MVNW5A8BM8Vw/+0iKDiN1nVb43Q+ys4= X-Google-Smtp-Source: AOwi7QATgD9qid6Hf+q1e+uPkyexxCWvG9CppCGfMI6vP04nWyMuMDEzyk+rdTTrzZDfMPA2nnGiQw== X-Received: by 10.37.39.68 with SMTP id n65mr2323121ybn.90.1507830961810; Thu, 12 Oct 2017 10:56:01 -0700 (PDT) Received: from rosewood.cam.corp.google.com ([2620:0:1013:0:f685:3152:9ba1:429a]) by smtp.gmail.com with ESMTPSA id x140sm5853087ywd.60.2017.10.12.10.56.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Oct 2017 10:56:01 -0700 (PDT) From: Sean Paul To: dri-devel@lists.freedesktop.org Subject: [PATCH v2 01/10] drm/panel: Keep track of enabled/prepared Date: Thu, 12 Oct 2017 13:55:28 -0400 Message-Id: <20171012175546.21323-2-seanpaul@chromium.org> X-Mailer: git-send-email 2.15.0.rc0.271.g36b669edcc-goog In-Reply-To: <20171012175546.21323-1-seanpaul@chromium.org> References: <20171012175546.21323-1-seanpaul@chromium.org> Cc: 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 Cc: Andrzej Hajda Signed-off-by: Sean Paul Reviewed-by: Daniel Vetter --- drivers/gpu/drm/drm_panel.c | 1 + include/drm/drm_panel.h | 60 +++++++++++++++++++++++++++++++++++++++------ 2 files changed, 53 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/drm_panel.c b/drivers/gpu/drm/drm_panel.c index 308d442a531b..e5957e7da768 100644 --- a/drivers/gpu/drm/drm_panel.c +++ b/drivers/gpu/drm/drm_panel.c @@ -48,6 +48,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); diff --git a/include/drm/drm_panel.h b/include/drm/drm_panel.h index 14ac240a1f64..425461c4c574 100644 --- a/include/drm/drm_panel.h +++ b/include/drm/drm_panel.h @@ -24,6 +24,7 @@ #ifndef __DRM_PANEL_H__ #define __DRM_PANEL_H__ +#include #include #include @@ -84,6 +85,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 + * @power_state: keeps track of the panel power status */ struct drm_panel { struct drm_device *drm; @@ -93,6 +95,12 @@ struct drm_panel { const struct drm_panel_funcs *funcs; struct list_head list; + + enum { + DRM_PANEL_POWER_OFF, + DRM_PANEL_POWER_PREPARED, + DRM_PANEL_POWER_ENABLED + } state; }; /** @@ -104,12 +112,21 @@ struct drm_panel { * is usually no longer possible to communicate with the panel until another * call to drm_panel_prepare(). * + * Atomic framework should 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. */ static inline int drm_panel_unprepare(struct drm_panel *panel) { - if (panel && panel->funcs && panel->funcs->unprepare) - return panel->funcs->unprepare(panel); + WARN_ON(panel->state != DRM_PANEL_POWER_PREPARED); + + if (panel && panel->funcs && panel->funcs->unprepare) { + int ret = panel->funcs->unprepare(panel); + if (!ret) + panel->state = DRM_PANEL_POWER_OFF; + return ret; + } return panel ? -ENOSYS : -EINVAL; } @@ -122,12 +139,21 @@ static inline int drm_panel_unprepare(struct drm_panel *panel) * drivers. For smart panels it should still be possible to communicate with * the integrated circuitry via any command bus after this call. * + * Atomic framework should 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. */ static inline int drm_panel_disable(struct drm_panel *panel) { - if (panel && panel->funcs && panel->funcs->disable) - return panel->funcs->disable(panel); + WARN_ON(panel->state != DRM_PANEL_POWER_ENABLED); + + if (panel && panel->funcs && panel->funcs->disable) { + int ret = panel->funcs->disable(panel); + if (!ret) + panel->state = DRM_PANEL_POWER_PREPARED; + return ret; + } return panel ? -ENOSYS : -EINVAL; } @@ -140,12 +166,21 @@ static inline int drm_panel_disable(struct drm_panel *panel) * the panel. After this has completed it is possible to communicate with any * integrated circuitry via a command bus. * + * Atomic framework should 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. */ static inline int drm_panel_prepare(struct drm_panel *panel) { - if (panel && panel->funcs && panel->funcs->prepare) - return panel->funcs->prepare(panel); + WARN_ON(panel->state != DRM_PANEL_POWER_OFF); + + if (panel && panel->funcs && panel->funcs->prepare) { + int ret = panel->funcs->prepare(panel); + if (!ret) + panel->state = DRM_PANEL_POWER_PREPARED; + return ret; + } return panel ? -ENOSYS : -EINVAL; } @@ -158,12 +193,21 @@ static inline int drm_panel_prepare(struct drm_panel *panel) * and the backlight to be enabled. Content will be visible on screen after * this call completes. * + * Atomic framework should 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. */ static inline int drm_panel_enable(struct drm_panel *panel) { - if (panel && panel->funcs && panel->funcs->enable) - return panel->funcs->enable(panel); + WARN_ON(panel->state != DRM_PANEL_POWER_PREPARED); + + if (panel && panel->funcs && panel->funcs->enable) { + int ret = panel->funcs->enable(panel); + if (!ret) + panel->state = DRM_PANEL_POWER_ENABLED; + return ret; + } return panel ? -ENOSYS : -EINVAL; }