Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp5321345pxv; Wed, 7 Jul 2021 00:37:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyJXMwCpE0UwYarh5nVOScBHlSGQXVdDMm7S8zujyJU7zcrgmt8yUI74NFX16gSw4JvHMXS X-Received: by 2002:a05:6638:4199:: with SMTP id az25mr20565207jab.45.1625643439274; Wed, 07 Jul 2021 00:37:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625643439; cv=none; d=google.com; s=arc-20160816; b=BKQTym4XsrBWbUhwO8y1sKtsSdXXbDbBTBowaddhvg25ppixuQuCFLE0ejh26XY2g/ 45GTUYBbNZb2qTrJCN0CaIWNs6H8Hsn3xsJK+NGwoZ2Z5y0FHEkHzphAS6I+lQakVVHI LZIWPFZ18j2In6a730rePklkPP3Kzsn85SIqeJJ6NkX32IcUdSPcUcGgtdgdZzDrYGeh nrwlAEwDdcL4W8qHP2FZPuHa2wgGP/XLTqfh7SlvDezkvX45a8hda4OXwXJ9IQNAeDGg XxGlH3p+7SxlX4Z5NPxmSmEvPER1apzOnxFS+eUid9xOVF7vQW3VwF8LnSvUiAqusyK6 WpPw== 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=jErpp84GwQGNzBBNWcnsVoe6gUCqeLHOzonns3HylCY=; b=BwRJAG8k3G5FHqpjFWp0sXuAp4F9GanHB6foPXXfOnoeqdV7D0CGiU/4xMZvBmQn9/ +4rJ4S1pXbDgpEJw6HO2cXySe6y1mN2N0A0/N2swwtCeD1QGeqxN4ZR2AvwJVBv6py6l JcrV1Qy2VWVo1xKmbCLZdraf+4DeQubqAz6/dsUxjadgoyktVzIvcXWBcwV1guNrOpwR wxn0MudQeRAcN16KhrjdjyjKfIzYPae1k8X1m86h4ls9XPqL1RJp++sFjc7E07Z3ENiT BUqHtaq5GssN9VNCQmae60ek6JEbHhHInYq6FhW/6xeiunxVaD4CC5saDq5HdqMu08f9 BGqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=ndzMNQdw; 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 x4si11918997ilj.43.2021.07.07.00.37.08; Wed, 07 Jul 2021 00:37:19 -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=ndzMNQdw; 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 S230526AbhGGHh4 (ORCPT + 99 others); Wed, 7 Jul 2021 03:37:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230519AbhGGHh4 (ORCPT ); Wed, 7 Jul 2021 03:37:56 -0400 Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B6E18C06175F for ; Wed, 7 Jul 2021 00:35:15 -0700 (PDT) Received: by mail-pj1-x102b.google.com with SMTP id mn20-20020a17090b1894b02901707fc074e8so3020299pjb.0 for ; Wed, 07 Jul 2021 00:35:15 -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=jErpp84GwQGNzBBNWcnsVoe6gUCqeLHOzonns3HylCY=; b=ndzMNQdwvoK07+UcIU4Chgpe5L5yVFSB+oBNoR+8gB1nIi50PYP0R+Cw2PYC8ZUHfy blfPHEiL0IJR1Tu2u8WjE+J8VIuIxIC+979xU+QCWa4gnOVXK5l+K1wPwPsO27RaVqVB rW9hTesQ8GAE3ZhqUho2TP2FqnSff7QNMI27Q= 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=jErpp84GwQGNzBBNWcnsVoe6gUCqeLHOzonns3HylCY=; b=ONJw0UZxosFIoODVsPyuIfPiRv1oAtEW8Pd8DOvJeoY2bYIGC0uoEPCzwDViWAZTg/ t7LINrJOuWJkDDGWpMbI9jpDDruptwiViXStg6/4UM4ADiOGdABpHviXmWiE46u9BpvX 6DrLRsmWIpekGHxNTKTZLz1PfFCHyPYS4tBy2iL+/HA25Z/ybLS6RmEEUtdpiGhhl1NZ jC1LhqEsiOPFVrS4O+nTfjKlFmV+Hxu5ZTnDkR/0F56cKMziciegHm5YuPjP1SxGlzLy 042A5g3iXPqizI13fKLeGxSZfgCU0f2GnX+y0hNJxA/XVzHNLo9W8NPHwIP44mnpgHtE FBIw== X-Gm-Message-State: AOAM530mri4D3LQPHTCr6oZOA52H5v7hNtgBW70H5QZom1wyZDsh8nEo HIPK75ZeWelefcZd9LxYEBlPIg7TDqnmzg== X-Received: by 2002:a17:902:f242:b029:129:9911:30e8 with SMTP id j2-20020a170902f242b0290129991130e8mr9444392plc.44.1625643315053; Wed, 07 Jul 2021 00:35:15 -0700 (PDT) Received: from localhost ([2401:fa00:9:14:ccb9:d95f:4dac:dbc4]) by smtp.gmail.com with UTF8SMTPSA id k19sm17072916pji.32.2021.07.07.00.35.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 07 Jul 2021 00:35:14 -0700 (PDT) From: Eizan Miyamoto To: linux-kernel@vger.kernel.org Cc: houlong.wei@mediatek.com, enric.balletbo@collabora.com, wenst@chromium.org, 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 v4 6/8] media: mtk-mdp: propagate errors better in pm_suspend/resume Date: Wed, 7 Jul 2021 17:34:08 +1000 Message-Id: <20210707173108.v4.6.If7d6a147afd8880940c42d7998e47ed3869e8805@changeid> X-Mailer: git-send-email 2.32.0.93.g670b81a890-goog In-Reply-To: <20210707073410.999625-1-eizan@chromium.org> References: <20210707073410.999625-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.93.g670b81a890-goog