From patchwork Sun Aug 4 20:16:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Ravnborg X-Patchwork-Id: 11074951 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 C5508746 for ; Sun, 4 Aug 2019 20:19:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B381E287A0 for ; Sun, 4 Aug 2019 20:19:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A72D028823; Sun, 4 Aug 2019 20:19:33 +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,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 307DF287A0 for ; Sun, 4 Aug 2019 20:19:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=gi0QGBtUdSHUV5q3cCkIT4ects6qjCpnqr/wlPyZIyo=; b=LbH3OaV6o4fMYN fvSdPRKRmMdknY8jfFPPVSgIevOleU+0iOteiN89UKAzW9nY5VHXVFCqwxFOyTTt4S695K3FQXTbl PqkZvYZeKQ+N498EbZAGGrjiL2U6GqWFrAQiCfS00BI9BH3cqv0K9U9k+PCah/GuQD2zlBNWtrQW2 KHPszCx+f92xKQ73zS6+GU1KlFCrHRnmHJ/cACSQgOqB/SJpA1puBCC6mHX0jypaGqc65J5+/QGWP 39ho+hCLcgL2zXgBCjLxUJu78ChmP6Dsji5LFvKCQudhjgmDR1zkJ3fSQzUw14K4ut86WbGwz3Ex0 PD8jqkXdqmED2qOizB1g==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1huMya-00037m-Lx; Sun, 04 Aug 2019 20:19:32 +0000 Received: from mail-lj1-x243.google.com ([2a00:1450:4864:20::243]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1huMwn-0000a0-QC for linux-arm-kernel@lists.infradead.org; Sun, 04 Aug 2019 20:17:44 +0000 Received: by mail-lj1-x243.google.com with SMTP id p17so77443501ljg.1 for ; Sun, 04 Aug 2019 13:17:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hrCo/4/IXJ1Yj7iZxjXNzvDGpEFw4E2sYzii2ko4Lpc=; b=H21lvLH6tpUmdeSL+ZX13j4skteYo8F27F85lXg12JKWPkHdL9eQI/B0aLzSqteuZF JyDo1GkMya2KG2lCA+5ozRHKZoM8bI0aMUsUg5BtlHAYP91P4BmM0zzLa4mWzMlSnA7I qyT/LzC1eJL/P11buVSMfZh7ZhWipjYNxIRhgMf4ylvnGbNNefyfl7yHxVBGN2ZHpQ22 gUEEURWNc9F1uLD9qoAxlTK9z2PhqI2SkEfqyfuaRea3WQ1BR88k6Hn6mhvY6MQmx/oD Xi16syJcz/Ah5wLJDfB/ZZj2FJP5FKD8/fQopj0w00bxP4/2GIq+x6Nwr2fkLDpTy4ym dl6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=hrCo/4/IXJ1Yj7iZxjXNzvDGpEFw4E2sYzii2ko4Lpc=; b=IqJIWHSLgCHWmAjKqdesD/SFKdOW3A76S1+4Eu4NKOfVXPZ8S7sKZbgDvdIHPe6ya1 +E5dSBP/gacpBjdRBEXui3eR3fVNmPgTdZSlT0jeibmhPhz/xO73bDhPwp3G8xg6GoYd Bgtflwa9diaqdna5YVfTgpE+RfhQeJRDRwbScr9NIefz6iXDEjg4FJrfPe8DX64mvGnS cxeiW2oCyFI5CNj0zbgvlR+4MayeQzBm7znN0WMQoNqdq0GpVXpj4aHIYuHwYZ09gXcw 7BT6pHOibui+EvvhQOilMIsVcAco9f9U7ZmetzJcmTZp351AWwXddmR5ML6N+i5AFAqt MkTg== X-Gm-Message-State: APjAAAX6e7jTuFTFuN4ShcNOcOSivLkkwFFQXQSncq1tmNwDQzpg0O+v 1CxGUot7TdKPCzvaW+1rWUE= X-Google-Smtp-Source: APXvYqyTjMcUeH7cKtM9ez8brS0M2L7PogMF1Pn26x5fiPtQY2s/TzFZyoXXnejWHprywDHCWV88IA== X-Received: by 2002:a2e:9213:: with SMTP id k19mr73854900ljg.237.1564949860364; Sun, 04 Aug 2019 13:17:40 -0700 (PDT) Received: from saturn.lan (18.158-248-194.customer.lyse.net. [158.248.194.18]) by smtp.gmail.com with ESMTPSA id p87sm16540794ljp.50.2019.08.04.13.17.38 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sun, 04 Aug 2019 13:17:39 -0700 (PDT) From: Sam Ravnborg To: dri-devel@lists.freedesktop.org, Thierry Reding Subject: [PATCH v1 14/16] drm/panel: call prepare/enable only once Date: Sun, 4 Aug 2019 22:16:35 +0200 Message-Id: <20190804201637.1240-15-sam@ravnborg.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190804201637.1240-1-sam@ravnborg.org> References: <20190804201637.1240-1-sam@ravnborg.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190804_131742_015551_F1E886F5 X-CRM114-Status: GOOD ( 17.54 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Neil Armstrong , David Airlie , Linus Walleij , Stefan Agner , Andrzej Hajda , Laurent Pinchart , Benjamin Gaignard , Fabio Estevam , Marek Vasut , Laurent Pinchart , Joonyoung Shim , Sam Ravnborg , Krzysztof Kozlowski , Jonathan Hunter , Maxime Ripard , Kukjin Kim , Allison Randal , Philipp Zabel , NXP Linux Team , Pengutronix Kernel Team , Jonas Karlman , Sascha Hauer , Alison Wang , Maarten Lankhorst , Gwan-gyeong Mun , Inki Dae , Alexios Zavras , linux-samsung-soc@vger.kernel.org, linux-tegra@vger.kernel.org, Thomas Gleixner , Sean Paul , linux-arm-kernel@lists.infradead.org, Jernej Skrabec , Shawn Guo , Seung-Woo Kim , Vincent Abriou , Kyungmin Park , Daniel Vetter , Enrico Weigelt Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Many panel drivers duplicate logic to prevent prepare to be called for a panel that is already prepared. Likewise for enable. Implement this logic in drm_panel so the individual drivers no longer needs this. A panel is considered prepared/enabled only if the prepare/enable call succeeds. For disable/unprepare it is unconditionally considered disabled/unprepared. This allows calls to prepare/enable again, even if there were some issue disabling a regulator or similar during disable/unprepare. Signed-off-by: Sam Ravnborg Cc: Maarten Lankhorst Cc: Maxime Ripard Cc: Sean Paul Cc: Thierry Reding Cc: Sam Ravnborg Cc: David Airlie Cc: Daniel Vetter Acked-by: Laurent Pinchart --- drivers/gpu/drm/drm_panel.c | 66 ++++++++++++++++++++++++++++++------- include/drm/drm_panel.h | 21 ++++++++++++ 2 files changed, 75 insertions(+), 12 deletions(-) diff --git a/drivers/gpu/drm/drm_panel.c b/drivers/gpu/drm/drm_panel.c index da19d5b4a2f4..0853764040de 100644 --- a/drivers/gpu/drm/drm_panel.c +++ b/drivers/gpu/drm/drm_panel.c @@ -66,10 +66,21 @@ EXPORT_SYMBOL(drm_panel_init); */ int drm_panel_prepare(struct drm_panel *panel) { - if (panel && panel->funcs && panel->funcs->prepare) - return panel->funcs->prepare(panel); + int ret = -ENOSYS; - return panel ? -ENOSYS : -EINVAL; + if (!panel) + return -EINVAL; + + if (panel->prepared) + return 0; + + if (panel->funcs && panel->funcs->prepare) + ret = panel->funcs->prepare(panel); + + if (ret >= 0) + panel->prepared = true; + + return ret; } EXPORT_SYMBOL(drm_panel_prepare); @@ -85,10 +96,21 @@ EXPORT_SYMBOL(drm_panel_prepare); */ int drm_panel_enable(struct drm_panel *panel) { - if (panel && panel->funcs && panel->funcs->enable) - return panel->funcs->enable(panel); + int ret = -ENOSYS; - return panel ? -ENOSYS : -EINVAL; + if (!panel) + return -EINVAL; + + if (panel->enabled) + return 0; + + if (panel->funcs && panel->funcs->enable) + ret = panel->funcs->enable(panel); + + if (ret >= 0) + panel->enabled = true; + + return ret; } EXPORT_SYMBOL(drm_panel_enable); @@ -104,10 +126,20 @@ EXPORT_SYMBOL(drm_panel_enable); */ int drm_panel_disable(struct drm_panel *panel) { - if (panel && panel->funcs && panel->funcs->disable) - return panel->funcs->disable(panel); + int ret = -ENOSYS; - return panel ? -ENOSYS : -EINVAL; + if (!panel) + return -EINVAL; + + if (!panel->enabled) + return 0; + + if (panel->funcs && panel->funcs->disable) + ret = panel->funcs->disable(panel); + + panel->enabled = false; + + return ret; } EXPORT_SYMBOL(drm_panel_disable); @@ -124,10 +156,20 @@ EXPORT_SYMBOL(drm_panel_disable); */ int drm_panel_unprepare(struct drm_panel *panel) { - if (panel && panel->funcs && panel->funcs->unprepare) - return panel->funcs->unprepare(panel); + int ret = -ENOSYS; - return panel ? -ENOSYS : -EINVAL; + if (!panel) + return -EINVAL; + + if (!panel->prepared) + return 0; + + if (panel->funcs && panel->funcs->unprepare) + ret = panel->funcs->unprepare(panel); + + panel->prepared = false; + + return ret; } EXPORT_SYMBOL(drm_panel_unprepare); diff --git a/include/drm/drm_panel.h b/include/drm/drm_panel.h index 624bd15ecfab..7493500fc9bd 100644 --- a/include/drm/drm_panel.h +++ b/include/drm/drm_panel.h @@ -65,6 +65,9 @@ struct drm_panel_funcs { * @prepare: * * Turn on panel and perform set up. + * When the panel is successfully prepared the prepare() function + * will not be called again until the panel has been unprepared. + * */ int (*prepare)(struct drm_panel *panel); @@ -72,6 +75,8 @@ struct drm_panel_funcs { * @enable: * * Enable panel (turn on back light, etc.). + * When the panel is successfully enabled the enable() function + * will not be called again until the panel has been disabled. */ int (*enable)(struct drm_panel *panel); @@ -79,6 +84,7 @@ struct drm_panel_funcs { * @disable: * * Disable panel (turn off back light, etc.). + * If the panel is already disabled the disable() function is not called. */ int (*disable)(struct drm_panel *panel); @@ -86,6 +92,7 @@ struct drm_panel_funcs { * @unprepare: * * Turn off panel. + * If the panel is already unprepared the unprepare() function is not called. */ int (*unprepare)(struct drm_panel *panel); @@ -145,6 +152,20 @@ struct drm_panel { * Panel entry in registry. */ struct list_head list; + + /** + * @prepared: + * + * Set to true when the panel is successfully prepared. + */ + bool prepared; + + /** + * @enabled: + * + * Set to true when the panel is successfully enabled. + */ + bool enabled; }; void drm_panel_init(struct drm_panel *panel);