Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp247977pxj; Thu, 10 Jun 2021 21:06:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw0QPgnR64FbD01qpYRb11AVbYUBE3hnceMmoeTT8J0Hwbosq71ez6h5UpgKayY74WIISR+ X-Received: by 2002:a17:906:a245:: with SMTP id bi5mr1728943ejb.316.1623384362509; Thu, 10 Jun 2021 21:06:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623384362; cv=none; d=google.com; s=arc-20160816; b=Lnnu2P8V7Ow7RazrTe1n1bMraaWkbzlAXDV1OblpQy4O/+L7gmjNiUm/780UGcK56K q/hxAplrmj1zMDhJyHSiXfGMIu+I+M0ueWIhYSRGPSIcC2OljJd5jp3ySXqLROz7Q/KE u8pfhc4+g0ooXe59Gz+Ia4i4iCTTSoQuz1ScFMfdgPPNyWFSNx9Zm+xy2nkOefNOCufp 0P8hxWfpDNrRiPCRywGJXw0AcrTeNAaZjAzPltRs4RIKeuDfqZjqlFkFE9Q7vFELAJ7L MuUJwdrDxd371xqnDLKXXPd4vwPOMU215nrGtZGBmqy/lD3JCF/3YECYYtf/HxfJ+SRo H/Pw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=+3+Gndgp0/tMOoNPMocbbgZOkKhwbWpoRPVA8+JYgko=; b=DMITjHwp0DJZnYqr82bE0ZhuP64g7xGEqBE2i8O50KmYh2eGjT5RmoY9HAM6z1Tkqg RW1O6ty7xxsVehsb86yRGDpOxgZJMs69Tb0rN4y62ZfeB/1TlRz9PA1w1Q2OB1A6KBap pYSMsYZd2zOfv5bqQvicm1n3wmmP59Jx1MSTBJMp9Add8qn6pCm7g9BMUcVs87plUiHI 4EzAUitm2d8A3qIo/8CziVM2yiTjEEQPnjXVVqF2c3X8Ssus4LviSB2QzqdDOKZ8Fy6v AFRzCtf2mCxRqwEmUJkpawSlh/aan3Zgt+2obU9e48PCxcb3JlxEjIyByzpLx3PDX26b M9Eg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=TcBorTOM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c23si3655150ejc.734.2021.06.10.21.05.39; Thu, 10 Jun 2021 21:06:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=TcBorTOM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231600AbhFKEFs (ORCPT + 99 others); Fri, 11 Jun 2021 00:05:48 -0400 Received: from mail-pg1-f181.google.com ([209.85.215.181]:35772 "EHLO mail-pg1-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231621AbhFKEFq (ORCPT ); Fri, 11 Jun 2021 00:05:46 -0400 Received: by mail-pg1-f181.google.com with SMTP id o9so1420675pgd.2 for ; Thu, 10 Jun 2021 21:03:49 -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 :mime-version:content-transfer-encoding; bh=+3+Gndgp0/tMOoNPMocbbgZOkKhwbWpoRPVA8+JYgko=; b=TcBorTOMlysmNHNu0MlyOQGrbwtJvS25dVRY+79aHZmpMnytbVQ9ZX54picFRWzu0p ZvTxUDL9rCJeG57HWN/4LgCYV73QIiuQ6bwARtiwx2DcJPOGYmShBPj3tvZCRQ1lK8WU gG2DhG0uUVjXOqpRhspcj6PgFDX8y3WSiBJHU= 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:mime-version:content-transfer-encoding; bh=+3+Gndgp0/tMOoNPMocbbgZOkKhwbWpoRPVA8+JYgko=; b=CI7m4m+tjveE/p8OqLfFbPOQRUNcL2C/Nc8r0C+96Clqqc3NtpPLQgCepTCreyIDMY y2++pXrvTxOl5upKwuPJhWRyTQuNO+I+IP6R3T3l8jkWut02MDCyzUb8/qHoucFdzvJy 9iPvA7LrWeo9fzOogCw20eA9oLKy7J23S26kOWAJqAEVMUwxm3ce2l1rKzQJ3yABMRyO goQrFlxTPqaCdDamTPi8Hbl/x4i2Yx8FsOxnl/rsFwWzdAjvTJt6sAQMXn3erhn6FeWi l+wTXJeprhkmU9i1HmOI260GAMaO3h0vpRSw91od09tOgmTAqKtNnHa7/aZ3MZkYoe67 3gMw== X-Gm-Message-State: AOAM530EG8/2J+/sQnKHpLY0OI16a49QpB8W95utT/+xU8jgsxqokqsg 5OdLyY2e635AgGmGig9hB7JyH6DLY2rmat8r X-Received: by 2002:a63:1453:: with SMTP id 19mr1627162pgu.270.1623384168646; Thu, 10 Jun 2021 21:02:48 -0700 (PDT) Received: from localhost ([2401:fa00:9:14:db52:e918:e5f9:9e14]) by smtp.gmail.com with UTF8SMTPSA id s24sm9196478pju.9.2021.06.10.21.02.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 10 Jun 2021 21:02:47 -0700 (PDT) From: Eizan Miyamoto To: linux-kernel@vger.kernel.org Cc: houlong.wei@mediatek.com, enric.balletbo@collabora.com, yong.wu@mediatek.com, chunkuang.hu@kernel.org, Eizan Miyamoto , Andrew-CT Chen , Matthias Brugger , Mauro Carvalho Chehab , Minghsiu Tsai , linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org, linux-mediatek@lists.infradead.org Subject: [PATCH v2 6/8] media: mtk-mdp: propagate errors better in pm_suspend/resume Date: Fri, 11 Jun 2021 14:01:43 +1000 Message-Id: <20210611140124.v2.6.If7d6a147afd8880940c42d7998e47ed3869e8805@changeid> X-Mailer: git-send-email 2.32.0.272.g935e593368-goog In-Reply-To: <20210611040145.2085329-1-eizan@chromium.org> References: <20210611040145.2085329-1-eizan@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Up until this change, many errors were logged but ignored when powering on clocks and calling pm_runtime_get/put() inside mtk_mdp_core. This change tries to do a better job at propagating errors back to the power management framework. Signed-off-by: Eizan Miyamoto --- (no changes since v1) drivers/media/platform/mtk-mdp/mtk_mdp_comp.c | 62 ++++++++++++++++--- drivers/media/platform/mtk-mdp/mtk_mdp_comp.h | 6 +- drivers/media/platform/mtk-mdp/mtk_mdp_core.c | 57 +++++++++++++---- 3 files changed, 99 insertions(+), 26 deletions(-) diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c index 3d9bb7265159..59911ee063c1 100644 --- a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c +++ b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c @@ -53,39 +53,81 @@ static const struct of_device_id mtk_mdp_comp_driver_dt_match[] = { }; MODULE_DEVICE_TABLE(of, mtk_mdp_comp_driver_dt_match); -void mtk_mdp_comp_power_on(struct mtk_mdp_comp *comp) +int mtk_mdp_comp_power_on(struct mtk_mdp_comp *comp) { - int err; + int status, err; err = pm_runtime_get_sync(comp->dev); - if (err < 0) + if (err < 0) { dev_err(comp->dev, "failed to runtime get, err %d.\n", err); + return err; + } + + err = mtk_mdp_comp_clock_on(comp); + if (err) { + dev_err(comp->dev, "failed to turn on clock. err=%d", err); + status = err; + goto err_mtk_mdp_comp_clock_on; + } + + return err; + +err_mtk_mdp_comp_clock_on: + err = pm_runtime_put_sync(comp->dev); + if (err) + dev_err(comp->dev, "failed to runtime put in cleanup. err=%d", err); - mtk_mdp_comp_clock_on(comp); + return status; } -void mtk_mdp_comp_power_off(struct mtk_mdp_comp *comp) +int mtk_mdp_comp_power_off(struct mtk_mdp_comp *comp) { - int err; + int status, err; mtk_mdp_comp_clock_off(comp); err = pm_runtime_put_sync(comp->dev); - if (err < 0) + if (err < 0) { dev_err(comp->dev, "failed to runtime put, err %d.\n", err); + status = err; + goto err_pm_runtime_put_sync; + } + + return 0; + +err_pm_runtime_put_sync: + err = mtk_mdp_comp_clock_on(comp); + if (err) + dev_err(comp->dev, "failed to turn on clock in cleanup. err=%d", err); + + return status; } -void mtk_mdp_comp_clock_on(struct mtk_mdp_comp *comp) +int mtk_mdp_comp_clock_on(struct mtk_mdp_comp *comp) { - int i, err; + int i, err, status; for (i = 0; i < ARRAY_SIZE(comp->clk); i++) { if (IS_ERR(comp->clk[i])) continue; err = clk_prepare_enable(comp->clk[i]); - if (err) + if (err) { + status = err; dev_err(comp->dev, "failed to enable clock, err %d. i:%d\n", err, i); + goto err_clk_prepare_enable; + } + } + + return 0; + +err_clk_prepare_enable: + for (--i; i >= 0; i--) { + if (IS_ERR(comp->clk[i])) + continue; + clk_disable_unprepare(comp->clk[i]); } + + return status; } void mtk_mdp_comp_clock_off(struct mtk_mdp_comp *comp) diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h index 7ad9b06bb11b..2bd229cc7eae 100644 --- a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h +++ b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h @@ -21,10 +21,10 @@ struct mtk_mdp_comp { int mtk_mdp_comp_init(struct mtk_mdp_comp *comp, struct device *dev); -void mtk_mdp_comp_power_on(struct mtk_mdp_comp *comp); -void mtk_mdp_comp_power_off(struct mtk_mdp_comp *comp); +int mtk_mdp_comp_power_on(struct mtk_mdp_comp *comp); +int mtk_mdp_comp_power_off(struct mtk_mdp_comp *comp); -void mtk_mdp_comp_clock_on(struct mtk_mdp_comp *comp); +int mtk_mdp_comp_clock_on(struct mtk_mdp_comp *comp); void mtk_mdp_comp_clock_off(struct mtk_mdp_comp *comp); extern struct platform_driver mtk_mdp_component_driver; diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_core.c b/drivers/media/platform/mtk-mdp/mtk_mdp_core.c index 48e9a557c446..523e3c2798e1 100644 --- a/drivers/media/platform/mtk-mdp/mtk_mdp_core.c +++ b/drivers/media/platform/mtk-mdp/mtk_mdp_core.c @@ -49,8 +49,9 @@ static const struct of_device_id mtk_mdp_of_ids[] = { }; MODULE_DEVICE_TABLE(of, mtk_mdp_of_ids); -static void mtk_mdp_clock_on(struct mtk_mdp_dev *mdp) +static int mtk_mdp_clock_on(struct mtk_mdp_dev *mdp) { + int err, status; struct mtk_mdp_comp *comp_node; /* @@ -58,18 +59,41 @@ static void mtk_mdp_clock_on(struct mtk_mdp_dev *mdp) * on it through mtk_mdp_m2m_start_streaming, making it unnecessary to * have mtk_mdp_comp_power_on called on it. */ - mtk_mdp_comp_clock_on(&mdp->comp_self); + err = mtk_mdp_comp_clock_on(&mdp->comp_self); + if (err) + return err; + + list_for_each_entry(comp_node, &mdp->comp_list, node) { + err = mtk_mdp_comp_power_on(comp_node); + if (err) { + status = err; + goto err_mtk_mdp_comp_power_on; + } + } - list_for_each_entry(comp_node, &mdp->comp_list, node) - mtk_mdp_comp_power_on(comp_node); + return 0; + +err_mtk_mdp_comp_power_on: + list_for_each_entry_continue_reverse(comp_node, &mdp->comp_list, node) { + err = mtk_mdp_comp_power_off(comp_node); + if (err) + dev_err(&mdp->pdev->dev, "failed to power off after error. err=%d", err); + } + return status; } -static void mtk_mdp_clock_off(struct mtk_mdp_dev *mdp) +static int mtk_mdp_clock_off(struct mtk_mdp_dev *mdp) { + int status, err; struct mtk_mdp_comp *comp_node; - list_for_each_entry(comp_node, &mdp->comp_list, node) - mtk_mdp_comp_power_off(comp_node); + list_for_each_entry(comp_node, &mdp->comp_list, node) { + err = mtk_mdp_comp_power_off(comp_node); + if (err) { + status = err; + goto err_mtk_mdp_comp_power_off; + } + } /* * The master / rdma0 component will have pm_runtime_put called @@ -77,6 +101,17 @@ static void mtk_mdp_clock_off(struct mtk_mdp_dev *mdp) * have mtk_mdp_comp_power_off called on it. */ mtk_mdp_comp_clock_off(&mdp->comp_self); + + return 0; + +err_mtk_mdp_comp_power_off: + list_for_each_entry_continue_reverse(comp_node, &mdp->comp_list, node) { + err = mtk_mdp_comp_power_on(comp_node); + if (err) + dev_err(&mdp->pdev->dev, "failed to power on after error. err=%d", err); + } + + return status; } static void mtk_mdp_wdt_worker(struct work_struct *work) @@ -317,18 +352,14 @@ static int __maybe_unused mtk_mdp_pm_suspend(struct device *dev) { struct mtk_mdp_dev *mdp = dev_get_drvdata(dev); - mtk_mdp_clock_off(mdp); - - return 0; + return mtk_mdp_clock_off(mdp); } static int __maybe_unused mtk_mdp_pm_resume(struct device *dev) { struct mtk_mdp_dev *mdp = dev_get_drvdata(dev); - mtk_mdp_clock_on(mdp); - - return 0; + return mtk_mdp_clock_on(mdp); } static int __maybe_unused mtk_mdp_suspend(struct device *dev) -- 2.32.0.272.g935e593368-goog