From patchwork Fri Oct 29 13:26:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AngeloGioacchino Del Regno X-Patchwork-Id: 12592703 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6312AC433F5 for ; Fri, 29 Oct 2021 13:27:18 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 29BF4610A0 for ; Fri, 29 Oct 2021 13:27:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 29BF4610A0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=collabora.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6E7136EA5C; Fri, 29 Oct 2021 13:27:12 +0000 (UTC) Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by gabe.freedesktop.org (Postfix) with ESMTPS id 207DD6EA58 for ; Fri, 29 Oct 2021 13:27:11 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: kholk11) with ESMTPSA id 0DC271F45A6E From: AngeloGioacchino Del Regno To: a.hajda@samsung.com Cc: narmstrong@baylibre.com, robert.foss@linaro.org, Laurent.pinchart@ideasonboard.com, jonas@kwiboo.se, jernej.skrabec@gmail.com, airlied@linux.ie, daniel@ffwll.ch, dri-devel@lists.freedesktop.org, kernel@collabora.com, linux-kernel@vger.kernel.org, AngeloGioacchino Del Regno Subject: [PATCH 1/3] drm/bridge: parade-ps8640: Don't try to enable VDO if poweron fails Date: Fri, 29 Oct 2021 15:26:48 +0200 Message-Id: <20211029132650.918761-1-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" If the bridge cannot get powered on, there's no reason to try to communicate with it: change the ps8640_bridge_poweron function to return an error value to the caller, so that we can avoid calling ps8640_bridge_vdo_control() in ps8640_pre_enable() if the poweron sequence fails. Signed-off-by: AngeloGioacchino Del Regno --- drivers/gpu/drm/bridge/parade-ps8640.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/bridge/parade-ps8640.c b/drivers/gpu/drm/bridge/parade-ps8640.c index 4b36e4dc78f1..8c5402947b3c 100644 --- a/drivers/gpu/drm/bridge/parade-ps8640.c +++ b/drivers/gpu/drm/bridge/parade-ps8640.c @@ -293,19 +293,19 @@ static int ps8640_bridge_vdo_control(struct ps8640 *ps_bridge, return 0; } -static void ps8640_bridge_poweron(struct ps8640 *ps_bridge) +static int ps8640_bridge_poweron(struct ps8640 *ps_bridge) { struct regmap *map = ps_bridge->regmap[PAGE2_TOP_CNTL]; int ret, status; if (ps_bridge->powered) - return; + return 0; ret = regulator_bulk_enable(ARRAY_SIZE(ps_bridge->supplies), ps_bridge->supplies); if (ret < 0) { DRM_ERROR("cannot enable regulators %d\n", ret); - return; + return ret; } gpiod_set_value(ps_bridge->gpio_powerdown, 0); @@ -352,11 +352,13 @@ static void ps8640_bridge_poweron(struct ps8640 *ps_bridge) ps_bridge->powered = true; - return; + return 0; err_regulators_disable: regulator_bulk_disable(ARRAY_SIZE(ps_bridge->supplies), ps_bridge->supplies); + + return ret; } static void ps8640_bridge_poweroff(struct ps8640 *ps_bridge) @@ -381,7 +383,9 @@ static void ps8640_pre_enable(struct drm_bridge *bridge) struct ps8640 *ps_bridge = bridge_to_ps8640(bridge); int ret; - ps8640_bridge_poweron(ps_bridge); + ret = ps8640_bridge_poweron(ps_bridge); + if (ret) + return; ret = ps8640_bridge_vdo_control(ps_bridge, ENABLE); if (ret < 0) From patchwork Fri Oct 29 13:26:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AngeloGioacchino Del Regno X-Patchwork-Id: 12592701 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CDE7EC433F5 for ; Fri, 29 Oct 2021 13:27:12 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 893DD60C51 for ; Fri, 29 Oct 2021 13:27:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 893DD60C51 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=collabora.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E49326EA58; Fri, 29 Oct 2021 13:27:11 +0000 (UTC) Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by gabe.freedesktop.org (Postfix) with ESMTPS id 867376EA58 for ; Fri, 29 Oct 2021 13:27:11 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: kholk11) with ESMTPSA id A44491F45A6F From: AngeloGioacchino Del Regno To: a.hajda@samsung.com Cc: narmstrong@baylibre.com, robert.foss@linaro.org, Laurent.pinchart@ideasonboard.com, jonas@kwiboo.se, jernej.skrabec@gmail.com, airlied@linux.ie, daniel@ffwll.ch, dri-devel@lists.freedesktop.org, kernel@collabora.com, linux-kernel@vger.kernel.org, AngeloGioacchino Del Regno Subject: [PATCH 2/3] drm/bridge: parade-ps8640: Move real poweroff action to new function Date: Fri, 29 Oct 2021 15:26:49 +0200 Message-Id: <20211029132650.918761-2-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211029132650.918761-1-angelogioacchino.delregno@collabora.com> References: <20211029132650.918761-1-angelogioacchino.delregno@collabora.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" In preparation for varying the poweron error handling in function ps8640_bridge_poweron(), move function ps8640_bridge_poweroff() up and also move the actual logic to power off the chip to a new __ps8640_bridge_poweroff() function. Signed-off-by: AngeloGioacchino Del Regno Reported-by: kernel test robot Reported-by: kernel test robot --- drivers/gpu/drm/bridge/parade-ps8640.c | 39 +++++++++++++++----------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/drivers/gpu/drm/bridge/parade-ps8640.c b/drivers/gpu/drm/bridge/parade-ps8640.c index 8c5402947b3c..9334217d02c9 100644 --- a/drivers/gpu/drm/bridge/parade-ps8640.c +++ b/drivers/gpu/drm/bridge/parade-ps8640.c @@ -293,6 +293,28 @@ static int ps8640_bridge_vdo_control(struct ps8640 *ps_bridge, return 0; } +static void __ps8640_bridge_poweroff(struct ps8640 *ps_bridge) +{ + int ret; + + gpiod_set_value(ps_bridge->gpio_reset, 1); + gpiod_set_value(ps_bridge->gpio_powerdown, 1); + if (regulator_bulk_disable(ARRAY_SIZE(ps_bridge->supplies), + ps_bridge->supplies)) { + DRM_ERROR("cannot disable regulators %d\n", ret); + } +} + +static void ps8640_bridge_poweroff(struct ps8640 *ps_bridge) +{ + if (!ps_bridge->powered) + return; + + __ps8640_bridge_poweroff(ps_bridge); + + ps_bridge->powered = false; +} + static int ps8640_bridge_poweron(struct ps8640 *ps_bridge) { struct regmap *map = ps_bridge->regmap[PAGE2_TOP_CNTL]; @@ -361,23 +383,6 @@ static int ps8640_bridge_poweron(struct ps8640 *ps_bridge) return ret; } -static void ps8640_bridge_poweroff(struct ps8640 *ps_bridge) -{ - int ret; - - if (!ps_bridge->powered) - return; - - gpiod_set_value(ps_bridge->gpio_reset, 1); - gpiod_set_value(ps_bridge->gpio_powerdown, 1); - ret = regulator_bulk_disable(ARRAY_SIZE(ps_bridge->supplies), - ps_bridge->supplies); - if (ret < 0) - DRM_ERROR("cannot disable regulators %d\n", ret); - - ps_bridge->powered = false; -} - static void ps8640_pre_enable(struct drm_bridge *bridge) { struct ps8640 *ps_bridge = bridge_to_ps8640(bridge); From patchwork Fri Oct 29 13:26:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AngeloGioacchino Del Regno X-Patchwork-Id: 12592705 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DE654C433F5 for ; Fri, 29 Oct 2021 13:27:21 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A5A71610E5 for ; Fri, 29 Oct 2021 13:27:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org A5A71610E5 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=collabora.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6A9966EA5B; Fri, 29 Oct 2021 13:27:13 +0000 (UTC) Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by gabe.freedesktop.org (Postfix) with ESMTPS id E863B6EA5B for ; Fri, 29 Oct 2021 13:27:11 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: kholk11) with ESMTPSA id 4CD2C1F45A72 From: AngeloGioacchino Del Regno To: a.hajda@samsung.com Cc: narmstrong@baylibre.com, robert.foss@linaro.org, Laurent.pinchart@ideasonboard.com, jonas@kwiboo.se, jernej.skrabec@gmail.com, airlied@linux.ie, daniel@ffwll.ch, dri-devel@lists.freedesktop.org, kernel@collabora.com, linux-kernel@vger.kernel.org, AngeloGioacchino Del Regno Subject: [PATCH 3/3] drm/bridge: parade-ps8640: Perform full poweroff if poweron fails Date: Fri, 29 Oct 2021 15:26:50 +0200 Message-Id: <20211029132650.918761-3-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211029132650.918761-1-angelogioacchino.delregno@collabora.com> References: <20211029132650.918761-1-angelogioacchino.delregno@collabora.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" In function ps8640_bridge_poweron(), in case of a failure not relative to the regulators enablement, the code was disabling the regulators but the gpio changes that happened during the poweron sequence were not being reverted back to a clean poweroff state. Since it is expected that, when we enter ps8640_bridge_poweron(), the powerdown and reset GPIOs are both in active state exactly as they were left in the poweroff function before, we can simply call function __ps8640_bridge_poweroff() in the failure case, reverting every change that was done during the power on sequence. Of course it was chosen to call the poweroff function instead of adding code to revert the GPIO changes to the poweron one to avoid duplicating code, as we would be doing exactly what the poweroff function does. Signed-off-by: AngeloGioacchino Del Regno --- drivers/gpu/drm/bridge/parade-ps8640.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/bridge/parade-ps8640.c b/drivers/gpu/drm/bridge/parade-ps8640.c index 9334217d02c9..8b54b515828a 100644 --- a/drivers/gpu/drm/bridge/parade-ps8640.c +++ b/drivers/gpu/drm/bridge/parade-ps8640.c @@ -346,7 +346,7 @@ static int ps8640_bridge_poweron(struct ps8640 *ps_bridge) if (ret < 0) { DRM_ERROR("failed read PAGE2_GPIO_H: %d\n", ret); - goto err_regulators_disable; + goto err_poweroff; } msleep(50); @@ -362,23 +362,22 @@ static int ps8640_bridge_poweron(struct ps8640 *ps_bridge) ret = regmap_update_bits(map, PAGE2_MCS_EN, MCS_EN, 0); if (ret < 0) { DRM_ERROR("failed write PAGE2_MCS_EN: %d\n", ret); - goto err_regulators_disable; + goto err_poweroff; } /* Switch access edp panel's edid through i2c */ ret = regmap_write(map, PAGE2_I2C_BYPASS, I2C_BYPASS_EN); if (ret < 0) { DRM_ERROR("failed write PAGE2_I2C_BYPASS: %d\n", ret); - goto err_regulators_disable; + goto err_poweroff; } ps_bridge->powered = true; return 0; -err_regulators_disable: - regulator_bulk_disable(ARRAY_SIZE(ps_bridge->supplies), - ps_bridge->supplies); +err_poweroff: + __ps8640_bridge_poweroff(ps_bridge); return ret; }