From patchwork Wed Aug 25 06:33:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eizan Miyamoto X-Patchwork-Id: 12456545 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 32B47C4320A for ; Wed, 25 Aug 2021 06:34:24 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 EB9B361245 for ; Wed, 25 Aug 2021 06:34:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org EB9B361245 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=dYEGV2DaGO71DSVLs7adMZ9wPjv/cT36hJiKcw0NN9s=; b=liwOLoNyIHVNva MHfw+FYnCWalWmeeIv//C9tUzzb1rlynzgcOxFLG+xlyCWeSx7O23KTiRtLek0b/xomhBlI1WQqdl O+eJpFe16vflKUd+gvTDQA7m7s9EospuamPnBW0e8HjVIhpwao1AJIsag4UHBc8l/mzCsvd0be3Kx WvfgcnrkuuY7saQDSI66gGbgdbDVHZWHgfzbFzIopmu63jvyqBv73kJ5jr+t4+3BhgvQj5Nt71s6X BWBvA+nUkIzcg+Hq16FpbDoCrm7mPxDs8htvKN5GbIarTflJm/jeECKp20G1Upzv8P5Bns/lEdf3j 8S9lf7fo/XAh3ggG9vCQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mImUD-005fa2-1W; Wed, 25 Aug 2021 06:34:09 +0000 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mImU1-005fTL-FF for linux-mediatek@lists.infradead.org; Wed, 25 Aug 2021 06:33:59 +0000 Received: by mail-pl1-x633.google.com with SMTP id a5so13727537plh.5 for ; Tue, 24 Aug 2021 23:33:55 -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=19laOyRbxi7dNQIHLVJQGG2qtMrhfAARdoeRSPPs6wk=; b=nDYrBNEmM/es46/uYQl/3rYZlfTcpxxYP6vnYd2xDkOqUT/fq7z6pG7X2RMioSmq7o 9R/sGspY+FJdy/JciwBzERjPkueL137nZVW6E9JM0ZLHCScOOfu99+4hVgduEFh5F4yE hogeetDjJ9jmbNqmXiUJDcTpz3kmfoU3DqjW0= 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=19laOyRbxi7dNQIHLVJQGG2qtMrhfAARdoeRSPPs6wk=; b=BPoFR028utJr6bQULkVnWZpryL5GqnnRZ041CjSb8MdUNJ7DM0dP5uboq/8ZWRTDwH 9uVRnBm02mMEGchSD0R2wuCpwXv73Bkf+nNFxvqtp83sFj28TroQFirl89W86POz4/nI DGj5Ela+iHm/MC55AEj8tJ06CxTqy3+EzWYkyyeLaOCn7MFt36GrmPpgMXrXXXZeVRPC ry+5TUOPX/zEBD6EAF0MOVHUj0bRHTeOfE8cWMX+0VeiS9JuwSeMpN57t257gc+LiUtE LoltG+WRVh7rX6ZcUECzs4kzk8Ky80TYtrRAOQLGGyq/5cZWdnSlgAwd5Mj/1dpcRHQS iWsg== X-Gm-Message-State: AOAM532RuEtJtyBGyypK4n5x5qmtX0z9pUr50L/8VLjYs7ENtj2iC3I3 xA6WY3xSRZmz8IJwlrqnPL7SPw== X-Google-Smtp-Source: ABdhPJyrxFL/qej64mhKdVLkwKxzB+fMwg3yrEloSGDFTMIWcN1QlDmlEtDyecQyZUswOV1dYkg8eQ== X-Received: by 2002:a17:902:8f97:b0:12f:fff9:bad4 with SMTP id z23-20020a1709028f9700b0012ffff9bad4mr26689750plo.65.1629873234821; Tue, 24 Aug 2021 23:33:54 -0700 (PDT) Received: from localhost ([2401:fa00:9:14:3f2f:9e23:8a5:952]) by smtp.gmail.com with UTF8SMTPSA id c15sm20830615pfl.181.2021.08.24.23.33.49 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 24 Aug 2021 23:33:54 -0700 (PDT) From: Eizan Miyamoto To: linux-kernel@vger.kernel.org Cc: chunkuang.hu@kernel.org, yong.wu@mediatek.com, wenst@chromium.org, ck.hu@mediatek.com, houlong.wei@mediatek.com, enric.balletbo@collabora.com, yongqiang.niu@mediatek.com, 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 v7 1/7] mtk-mdp: propagate errors from clock_on Date: Wed, 25 Aug 2021 16:33:17 +1000 Message-Id: <20210825163247.v7.1.I9db0d408ef79d300672ec0311a6bee9556801631@changeid> X-Mailer: git-send-email 2.33.0.rc2.250.ged5fa647cd-goog In-Reply-To: <20210825063323.3607738-1-eizan@chromium.org> References: <20210825063323.3607738-1-eizan@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210824_233357_542948_D2246FCC X-CRM114-Status: GOOD ( 17.43 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org Up until this change, many errors were logged but ignored when powering on clocks 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 Reviewed-by: Enric Balletbo i Serra Reviewed-by: Houlong Wei --- (no changes since v1) drivers/media/platform/mtk-mdp/mtk_mdp_comp.c | 25 ++++++++++++----- drivers/media/platform/mtk-mdp/mtk_mdp_comp.h | 2 +- drivers/media/platform/mtk-mdp/mtk_mdp_core.c | 27 ++++++++++++++----- 3 files changed, 39 insertions(+), 15 deletions(-) diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c index b3426a551bea..76e295c8d9bc 100644 --- a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c +++ b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c @@ -13,10 +13,9 @@ #include "mtk_mdp_comp.h" - -void mtk_mdp_comp_clock_on(struct device *dev, struct mtk_mdp_comp *comp) +int mtk_mdp_comp_clock_on(struct device *dev, struct mtk_mdp_comp *comp) { - int i, err; + int i, err, status; if (comp->larb_dev) { err = mtk_smi_larb_get(comp->larb_dev); @@ -30,11 +29,23 @@ void mtk_mdp_comp_clock_on(struct device *dev, struct mtk_mdp_comp *comp) if (IS_ERR(comp->clk[i])) continue; err = clk_prepare_enable(comp->clk[i]); - if (err) - dev_err(dev, - "failed to enable clock, err %d. type:%d i:%d\n", - err, comp->type, i); + if (err) { + status = err; + dev_err(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 device *dev, 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 7897766c96bb..92ab5249bcad 100644 --- a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h +++ b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h @@ -41,7 +41,7 @@ int mtk_mdp_comp_init(struct device *dev, struct device_node *node, struct mtk_mdp_comp *comp, enum mtk_mdp_comp_type comp_type); void mtk_mdp_comp_deinit(struct device *dev, struct mtk_mdp_comp *comp); -void mtk_mdp_comp_clock_on(struct device *dev, struct mtk_mdp_comp *comp); +int mtk_mdp_comp_clock_on(struct device *dev, struct mtk_mdp_comp *comp); void mtk_mdp_comp_clock_off(struct device *dev, struct mtk_mdp_comp *comp); diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_core.c b/drivers/media/platform/mtk-mdp/mtk_mdp_core.c index 976aa1f4829b..412bbec0f735 100644 --- a/drivers/media/platform/mtk-mdp/mtk_mdp_core.c +++ b/drivers/media/platform/mtk-mdp/mtk_mdp_core.c @@ -52,13 +52,28 @@ 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) { - struct device *dev = &mdp->pdev->dev; struct mtk_mdp_comp *comp_node; + int status; + struct device *dev = &mdp->pdev->dev; + int err; - list_for_each_entry(comp_node, &mdp->comp_list, node) - mtk_mdp_comp_clock_on(dev, comp_node); + list_for_each_entry(comp_node, &mdp->comp_list, node) { + err = mtk_mdp_comp_clock_on(dev, comp_node); + if (err) { + status = err; + goto err_mtk_mdp_comp_clock_on; + } + } + + return 0; + +err_mtk_mdp_comp_clock_on: + list_for_each_entry_continue_reverse(comp_node, &mdp->comp_list, node) + mtk_mdp_comp_clock_off(dev, comp_node); + + return status; } static void mtk_mdp_clock_off(struct mtk_mdp_dev *mdp) @@ -274,9 +289,7 @@ 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) From patchwork Wed Aug 25 06:33:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eizan Miyamoto X-Patchwork-Id: 12456547 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 48E20C4338F for ; Wed, 25 Aug 2021 06:34:56 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 1752261245 for ; Wed, 25 Aug 2021 06:34:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 1752261245 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=X2twJr1uuTuNDdOFk0v+BFlFt6PG3n7JdGzale+/wwo=; b=fzZb9SA3G41Lxv qu7DwySpvJ3GrbRtcUESP1CB5kczry4eNWdUy4Tubas32BlPkdMrV6yrw189FQr5vXMT7xAzhrCKB yCYvQrL6Z8PxAJLInZeZGCjtlSxMPa0K7ECDZutiXYADGG3IxT7wOOPh5YpAmJIEwFJ/w3ACKbYVP gkvm2npn1T9ry6qdodC0PXkNgMHQFVsVsAbtHKRxg12JMLawsnhqPIdi6xeivsf6HA8Un+eH3yYTI MfZH7Bg/yvXsi256GB6GKUehZjGwl3a3seRO65wW3z7D/2MZ8Ul6umLZNoFs3XXxuH21KGGiMopZQ sGeUdr14btHj64zceAjQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mImUg-005foZ-AZ; Wed, 25 Aug 2021 06:34:38 +0000 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mImU8-005fXQ-EN for linux-mediatek@lists.infradead.org; Wed, 25 Aug 2021 06:34:11 +0000 Received: by mail-pl1-x636.google.com with SMTP id n12so2288420plk.10 for ; Tue, 24 Aug 2021 23:34:03 -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=U9JKO7U4JZvk87LycMts9wqCGizhrGzAV+TMSf870Bk=; b=eDM9rVExYguvWuvJjoa8Z6vDNlVYxbdEV5KTlRJCMpNs1aKvr8wTkD7vejrKWrqC18 wPbDK9r6I9ZZoDxulTKhQlmX5Q/1jz2U4TaOhjypVeHMz/ifPH8agAVJx3dW7r9gJ8PO Pf+viRlrgA2uVd+kIi2GKG3IXwMFrUV9yHGbA= 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=U9JKO7U4JZvk87LycMts9wqCGizhrGzAV+TMSf870Bk=; b=PkxLBDHNFhvOc1g8DODaHAfCzMZqXqGcMijL1FqCTF1j5wqQjZVa9S4kSxh4cOHcqJ eTVK3SuWpPjcvVNtpJe8Z1CcJMaagShtejfAZZx/uPyD1WQzjnauFw3NqD7oxOVdM1Kc ZGo0vmBAmyP4B4/WthXPRFsYBjCkBVp2GFtuvAhhpQnIogUJDJyiWZv84TQGaqm4DUNK gSDNvmoFvyZjNZLUDk+naEIhnSXSTwg/5AwCN8OQj7jHcR7mLk6ctLO7PXyzdSqPSfAl GygEAdjIRyrygU6tKyZIrekOoAitJYHXfQ+9KgpwrySVTFRwbsiiFNi/IFlg2zqGwL8S vO4w== X-Gm-Message-State: AOAM533R/rZOnHkFhQMfD/upQwy519vhUi/637vrdMdGo9Wadmzg9bV1 FV4Z4gTaQEDljCpEN38nEMc1uA== X-Google-Smtp-Source: ABdhPJwpK41ZmRITsXuL8arn1VhfBI+NcUmGBFA6abRBOnBj/hZmfwyraNCJgRmOFlpwib9V0M78kA== X-Received: by 2002:a17:902:e543:b0:134:1c02:285e with SMTP id n3-20020a170902e54300b001341c02285emr13275678plf.43.1629873242517; Tue, 24 Aug 2021 23:34:02 -0700 (PDT) Received: from localhost ([2401:fa00:9:14:3f2f:9e23:8a5:952]) by smtp.gmail.com with UTF8SMTPSA id j17sm21730455pfn.148.2021.08.24.23.33.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 24 Aug 2021 23:34:02 -0700 (PDT) From: Eizan Miyamoto To: linux-kernel@vger.kernel.org Cc: chunkuang.hu@kernel.org, yong.wu@mediatek.com, wenst@chromium.org, ck.hu@mediatek.com, houlong.wei@mediatek.com, enric.balletbo@collabora.com, yongqiang.niu@mediatek.com, 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 v7 2/7] mtk-mdp: add driver to probe mdp components Date: Wed, 25 Aug 2021 16:33:18 +1000 Message-Id: <20210825163247.v7.2.Ie6d1e6e39cf9b5d6b2108ae1096af34c3d55880b@changeid> X-Mailer: git-send-email 2.33.0.rc2.250.ged5fa647cd-goog In-Reply-To: <20210825063323.3607738-1-eizan@chromium.org> References: <20210825063323.3607738-1-eizan@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210824_233404_559381_B5B2864A X-CRM114-Status: GOOD ( 39.27 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org Broadly, this patch (1) adds a driver for various MTK MDP components to go alongside the main MTK MDP driver, and (2) hooks them all together using the component framework. (1) Up until now, the MTK MDP driver controls 8 devices in the device tree on its own. When running tests for the hardware video decoder, we found that the iommus and LARBs were not being properly configured. To configure them, a driver for each be added to mtk_mdp_comp so that mtk_iommu_add_device() can (eventually) be called from dma_configure() inside really_probe(). (2) The integration into the component framework allows us to defer the registration with the v4l2 subsystem until all the MDP-related devices have been probed, so that the relevant device node does not become available until initialization of all the components is complete. Some notes about how the component framework has been integrated: - The driver for the rdma0 component serves double duty as the "master" (aggregate) driver as well as a component driver. This is a non-ideal compromise until a better solution is developed. This device is differentiated from the rest by checking for a "mediatek,vpu" property in the device node. - The list of mdp components remains hard-coded as mtk_mdp_comp_dt_ids[] in mtk_mdp_core.c, and as mtk_mdp_comp_driver_dt_match[] in mtk_mdp_comp.c. This unfortunate duplication of information is addressed in a following patch in this series. - The component driver calls component_add() for each device that is probed. - In mtk_mdp_probe (the "master" device), we scan the device tree for any matching nodes against mtk_mdp_comp_dt_ids, and add component matches for them. The match criteria is a matching device node pointer. - When the set of components devices that have been probed corresponds with the list that is generated by the "master", the callback to mtk_mdp_master_bind() is made, which then calls the component bind functions. - Inside mtk_mdp_master_bind(), once all the component bind functions have been called, we can then register our device to the v4l2 subsystem. - The call to pm_runtime_enable() in the master device is called after all the components have been registered by their bind() functions called by mtk_mtp_master_bind(). As a result, the list of components will not change while power management callbacks mtk_mdp_suspend()/ resume() are accessing the list of components. Signed-off-by: Eizan Miyamoto Reviewed-by: Enric Balletbo i Serra Reviewed-by: Houlong Wei --- (no changes since v1) drivers/media/platform/mtk-mdp/mtk_mdp_comp.c | 143 ++++++++++++-- drivers/media/platform/mtk-mdp/mtk_mdp_comp.h | 25 +-- drivers/media/platform/mtk-mdp/mtk_mdp_core.c | 174 +++++++++++++----- drivers/media/platform/mtk-mdp/mtk_mdp_core.h | 1 + 4 files changed, 252 insertions(+), 91 deletions(-) diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c index 76e295c8d9bc..7a0e3acffab9 100644 --- a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c +++ b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c @@ -5,13 +5,50 @@ */ #include +#include #include #include +#include #include #include #include #include "mtk_mdp_comp.h" +#include "mtk_mdp_core.h" + +/** + * enum mtk_mdp_comp_type - the MDP component + * @MTK_MDP_RDMA: Read DMA + * @MTK_MDP_RSZ: Reszer + * @MTK_MDP_WDMA: Write DMA + * @MTK_MDP_WROT: Write DMA with rotation + * @MTK_MDP_COMP_TYPE_MAX: Placeholder for num elems in this enum + */ +enum mtk_mdp_comp_type { + MTK_MDP_RDMA, + MTK_MDP_RSZ, + MTK_MDP_WDMA, + MTK_MDP_WROT, + MTK_MDP_COMP_TYPE_MAX, +}; + +static const struct of_device_id mtk_mdp_comp_driver_dt_match[] = { + { + .compatible = "mediatek,mt8173-mdp-rdma", + .data = (void *)MTK_MDP_RDMA + }, { + .compatible = "mediatek,mt8173-mdp-rsz", + .data = (void *)MTK_MDP_RSZ + }, { + .compatible = "mediatek,mt8173-mdp-wdma", + .data = (void *)MTK_MDP_WDMA + }, { + .compatible = "mediatek,mt8173-mdp-wrot", + .data = (void *)MTK_MDP_WROT + }, + { } +}; +MODULE_DEVICE_TABLE(of, mtk_mdp_comp_driver_dt_match); int mtk_mdp_comp_clock_on(struct device *dev, struct mtk_mdp_comp *comp) { @@ -20,9 +57,7 @@ int mtk_mdp_comp_clock_on(struct device *dev, struct mtk_mdp_comp *comp) if (comp->larb_dev) { err = mtk_smi_larb_get(comp->larb_dev); if (err) - dev_err(dev, - "failed to get larb, err %d. type:%d\n", - err, comp->type); + dev_err(dev, "failed to get larb, err %d.\n", err); } for (i = 0; i < ARRAY_SIZE(comp->clk); i++) { @@ -62,17 +97,41 @@ void mtk_mdp_comp_clock_off(struct device *dev, struct mtk_mdp_comp *comp) mtk_smi_larb_put(comp->larb_dev); } -int mtk_mdp_comp_init(struct device *dev, struct device_node *node, - struct mtk_mdp_comp *comp, - enum mtk_mdp_comp_type comp_type) +static int mtk_mdp_comp_bind(struct device *dev, struct device *master, void *data) +{ + struct mtk_mdp_comp *comp = dev_get_drvdata(dev); + struct mtk_mdp_dev *mdp = data; + + mtk_mdp_register_component(mdp, comp); + + return 0; +} + +static void mtk_mdp_comp_unbind(struct device *dev, struct device *master, + void *data) +{ + struct mtk_mdp_comp *comp = dev_get_drvdata(dev); + struct mtk_mdp_dev *mdp = data; + + mtk_mdp_unregister_component(mdp, comp); +} + +static const struct component_ops mtk_mdp_component_ops = { + .bind = mtk_mdp_comp_bind, + .unbind = mtk_mdp_comp_unbind, +}; + +int mtk_mdp_comp_init(struct mtk_mdp_comp *comp, struct device *dev) { struct device_node *larb_node; struct platform_device *larb_pdev; int ret; int i; + struct device_node *node = dev->of_node; + enum mtk_mdp_comp_type comp_type = + (enum mtk_mdp_comp_type)of_device_get_match_data(dev); - comp->dev_node = of_node_get(node); - comp->type = comp_type; + INIT_LIST_HEAD(&comp->node); for (i = 0; i < ARRAY_SIZE(comp->clk); i++) { comp->clk[i] = of_clk_get(node, i); @@ -80,19 +139,17 @@ int mtk_mdp_comp_init(struct device *dev, struct device_node *node, if (PTR_ERR(comp->clk[i]) != -EPROBE_DEFER) dev_err(dev, "Failed to get clock\n"); ret = PTR_ERR(comp->clk[i]); - goto put_dev; + goto err; } /* Only RDMA needs two clocks */ - if (comp->type != MTK_MDP_RDMA) + if (comp_type != MTK_MDP_RDMA) break; } /* Only DMA capable components need the LARB property */ comp->larb_dev = NULL; - if (comp->type != MTK_MDP_RDMA && - comp->type != MTK_MDP_WDMA && - comp->type != MTK_MDP_WROT) + if (comp_type != MTK_MDP_RDMA && comp_type != MTK_MDP_WDMA && comp_type != MTK_MDP_WROT) return 0; larb_node = of_parse_phandle(node, "mediatek,larb", 0); @@ -100,7 +157,7 @@ int mtk_mdp_comp_init(struct device *dev, struct device_node *node, dev_err(dev, "Missing mediadek,larb phandle in %pOF node\n", node); ret = -EINVAL; - goto put_dev; + goto err; } larb_pdev = of_find_device_by_node(larb_node); @@ -108,7 +165,7 @@ int mtk_mdp_comp_init(struct device *dev, struct device_node *node, dev_warn(dev, "Waiting for larb device %pOF\n", larb_node); of_node_put(larb_node); ret = -EPROBE_DEFER; - goto put_dev; + goto err; } of_node_put(larb_node); @@ -116,13 +173,59 @@ int mtk_mdp_comp_init(struct device *dev, struct device_node *node, return 0; -put_dev: - of_node_put(comp->dev_node); - +err: return ret; } -void mtk_mdp_comp_deinit(struct device *dev, struct mtk_mdp_comp *comp) +static int mtk_mdp_comp_probe(struct platform_device *pdev) { - of_node_put(comp->dev_node); + struct device *dev = &pdev->dev; + struct device_node *vpu_node; + int status; + struct mtk_mdp_comp *comp; + + vpu_node = of_parse_phandle(dev->of_node, "mediatek,vpu", 0); + if (vpu_node) { + of_node_put(vpu_node); + /* + * The device tree node with a mediatek,vpu property is deemed + * the MDP "master" device, we don't want to add a component + * for it in this function because the initialization for the + * master is done elsewhere. + */ + dev_info(dev, "vpu node found, not probing\n"); + return -ENODEV; + } + + comp = devm_kzalloc(dev, sizeof(*comp), GFP_KERNEL); + if (!comp) + return -ENOMEM; + + status = mtk_mdp_comp_init(comp, dev); + if (status) { + dev_err(dev, "Failed to initialize component: %d\n", status); + return status; + } + + dev_set_drvdata(dev, comp); + + return component_add(dev, &mtk_mdp_component_ops); } + +static int mtk_mdp_comp_remove(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + + component_del(dev, &mtk_mdp_component_ops); + return 0; +} + +struct platform_driver mtk_mdp_component_driver = { + .probe = mtk_mdp_comp_probe, + .remove = mtk_mdp_comp_remove, + .driver = { + .name = "mediatek-mdp-comp", + .owner = THIS_MODULE, + .of_match_table = mtk_mdp_comp_driver_dt_match, + }, +}; diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h index 92ab5249bcad..df5fc4c94f90 100644 --- a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h +++ b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h @@ -7,42 +7,23 @@ #ifndef __MTK_MDP_COMP_H__ #define __MTK_MDP_COMP_H__ -/** - * enum mtk_mdp_comp_type - the MDP component - * @MTK_MDP_RDMA: Read DMA - * @MTK_MDP_RSZ: Riszer - * @MTK_MDP_WDMA: Write DMA - * @MTK_MDP_WROT: Write DMA with rotation - */ -enum mtk_mdp_comp_type { - MTK_MDP_RDMA, - MTK_MDP_RSZ, - MTK_MDP_WDMA, - MTK_MDP_WROT, -}; - /** * struct mtk_mdp_comp - the MDP's function component data * @node: list node to track sibing MDP components - * @dev_node: component device node * @clk: clocks required for component * @larb_dev: SMI device required for component - * @type: component type */ struct mtk_mdp_comp { struct list_head node; - struct device_node *dev_node; struct clk *clk[2]; struct device *larb_dev; - enum mtk_mdp_comp_type type; }; -int mtk_mdp_comp_init(struct device *dev, struct device_node *node, - struct mtk_mdp_comp *comp, - enum mtk_mdp_comp_type comp_type); -void mtk_mdp_comp_deinit(struct device *dev, struct mtk_mdp_comp *comp); +int mtk_mdp_comp_init(struct mtk_mdp_comp *comp, struct device *dev); + int mtk_mdp_comp_clock_on(struct device *dev, struct mtk_mdp_comp *comp); void mtk_mdp_comp_clock_off(struct device *dev, struct mtk_mdp_comp *comp); +extern struct platform_driver mtk_mdp_component_driver; #endif /* __MTK_MDP_COMP_H__ */ diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_core.c b/drivers/media/platform/mtk-mdp/mtk_mdp_core.c index 412bbec0f735..b813a822439a 100644 --- a/drivers/media/platform/mtk-mdp/mtk_mdp_core.c +++ b/drivers/media/platform/mtk-mdp/mtk_mdp_core.c @@ -6,6 +6,7 @@ */ #include +#include #include #include #include @@ -19,6 +20,7 @@ #include #include +#include "mtk_mdp_comp.h" #include "mtk_mdp_core.h" #include "mtk_mdp_m2m.h" #include "mtk_vpu.h" @@ -32,16 +34,12 @@ module_param(mtk_mdp_dbg_level, int, 0644); static const struct of_device_id mtk_mdp_comp_dt_ids[] = { { .compatible = "mediatek,mt8173-mdp-rdma", - .data = (void *)MTK_MDP_RDMA }, { .compatible = "mediatek,mt8173-mdp-rsz", - .data = (void *)MTK_MDP_RSZ }, { .compatible = "mediatek,mt8173-mdp-wdma", - .data = (void *)MTK_MDP_WDMA }, { .compatible = "mediatek,mt8173-mdp-wrot", - .data = (void *)MTK_MDP_WROT }, { }, }; @@ -106,6 +104,63 @@ static void mtk_mdp_reset_handler(void *priv) queue_work(mdp->wdt_wq, &mdp->wdt_work); } +static int compare_of(struct device *dev, void *data) +{ + return dev->of_node == data; +} + +static void release_of(struct device *dev, void *data) +{ + of_node_put(data); +} + +static int mtk_mdp_master_bind(struct device *dev) +{ + int status; + struct mtk_mdp_dev *mdp = dev_get_drvdata(dev); + + mtk_mdp_register_component(mdp, &mdp->comp_self); + + status = component_bind_all(dev, mdp); + if (status) { + dev_err(dev, "Failed to bind all components: %d\n", status); + goto err_component_bind_all; + } + + status = mtk_mdp_register_m2m_device(mdp); + if (status) { + dev_err(dev, "Failed to register m2m device: %d\n", status); + goto err_mtk_mdp_register_m2m_device; + } + + pm_runtime_enable(dev); + + return 0; + +err_mtk_mdp_register_m2m_device: + component_unbind_all(dev, mdp); + +err_component_bind_all: + mtk_mdp_unregister_component(mdp, &mdp->comp_self); + + return status; +} + +static void mtk_mdp_master_unbind(struct device *dev) +{ + struct mtk_mdp_dev *mdp = dev_get_drvdata(dev); + + pm_runtime_disable(dev); + mtk_mdp_unregister_m2m_device(mdp); + component_unbind_all(dev, mdp); + mtk_mdp_unregister_component(mdp, &mdp->comp_self); +} + +static const struct component_master_ops mtk_mdp_com_ops = { + .bind = mtk_mdp_master_bind, + .unbind = mtk_mdp_master_unbind, +}; + void mtk_mdp_register_component(struct mtk_mdp_dev *mdp, struct mtk_mdp_comp *comp) { @@ -123,8 +178,8 @@ static int mtk_mdp_probe(struct platform_device *pdev) struct mtk_mdp_dev *mdp; struct device *dev = &pdev->dev; struct device_node *node, *parent; - struct mtk_mdp_comp *comp, *comp_temp; - int ret = 0; + int i, ret = 0; + struct component_match *match = NULL; mdp = devm_kzalloc(dev, sizeof(*mdp), GFP_KERNEL); if (!mdp) @@ -149,36 +204,43 @@ static int mtk_mdp_probe(struct platform_device *pdev) } /* Iterate over sibling MDP function blocks */ + i = 0; for_each_child_of_node(parent, node) { - const struct of_device_id *of_id; - enum mtk_mdp_comp_type comp_type; + struct platform_device *pdev; - of_id = of_match_node(mtk_mdp_comp_dt_ids, node); - if (!of_id) + if (!of_match_node(mtk_mdp_comp_dt_ids, node)) continue; - if (!of_device_is_available(node)) { - dev_err(dev, "Skipping disabled component %pOF\n", - node); + if (!of_device_is_available(node)) continue; - } - - comp_type = (enum mtk_mdp_comp_type)of_id->data; - comp = devm_kzalloc(dev, sizeof(*comp), GFP_KERNEL); - if (!comp) { - ret = -ENOMEM; - of_node_put(node); - goto err_comp; + pdev = of_find_device_by_node(node); + if (!pdev) { + dev_warn(dev, "Unable to find comp device %s\n", + node->full_name); + continue; } - ret = mtk_mdp_comp_init(dev, node, comp, comp_type); - if (ret) { - of_node_put(node); - goto err_comp; + /* + * Do not add a match for my own (rdma0) device node. + * I will be managing it directly instead using comp_self. + */ + if (&pdev->dev != dev) { + dev_dbg(dev, "adding match %d for: %pOF\n", i++, node); + component_match_add_release(dev, &match, release_of, + compare_of, + of_node_get(node)); } + } - mtk_mdp_register_component(mdp, comp); + /* + * Create a component for myself so that clocks can be toggled in + * clock_on(). + */ + ret = mtk_mdp_comp_init(&mdp->comp_self, dev); + if (ret) { + dev_err(dev, "Failed to initialize component\n"); + goto err_comp; } mdp->job_wq = create_singlethread_workqueue(MTK_MDP_MODULE_NAME); @@ -203,18 +265,12 @@ static int mtk_mdp_probe(struct platform_device *pdev) goto err_dev_register; } - ret = mtk_mdp_register_m2m_device(mdp); - if (ret) { - v4l2_err(&mdp->v4l2_dev, "Failed to init mem2mem device\n"); - goto err_m2m_register; - } - mdp->vpu_dev = vpu_get_plat_device(pdev); ret = vpu_wdt_reg_handler(mdp->vpu_dev, mtk_mdp_reset_handler, mdp, VPU_RST_MDP); if (ret) { dev_err(&pdev->dev, "Failed to register reset handler\n"); - goto err_m2m_register; + goto err_wdt_reg; } platform_set_drvdata(pdev, mdp); @@ -222,15 +278,25 @@ static int mtk_mdp_probe(struct platform_device *pdev) ret = vb2_dma_contig_set_max_seg_size(&pdev->dev, DMA_BIT_MASK(32)); if (ret) { dev_err(&pdev->dev, "Failed to set vb2 dma mag seg size\n"); - goto err_m2m_register; + goto err_set_max_seg_size; + } + + ret = component_master_add_with_match(dev, &mtk_mdp_com_ops, match); + if (ret) { + dev_err(dev, "Component master add failed\n"); + goto err_component_master_add; } - pm_runtime_enable(dev); dev_dbg(dev, "mdp-%d registered successfully\n", mdp->id); return 0; -err_m2m_register: +err_component_master_add: + vb2_dma_contig_clear_max_seg_size(&pdev->dev); + +err_set_max_seg_size: + +err_wdt_reg: v4l2_device_unregister(&mdp->v4l2_dev); err_dev_register: @@ -242,11 +308,6 @@ static int mtk_mdp_probe(struct platform_device *pdev) err_alloc_job_wq: err_comp: - list_for_each_entry_safe(comp, comp_temp, &mdp->comp_list, node) { - mtk_mdp_unregister_component(mdp, comp); - mtk_mdp_comp_deinit(dev, comp); - } - dev_dbg(dev, "err %d\n", ret); return ret; } @@ -254,11 +315,10 @@ static int mtk_mdp_probe(struct platform_device *pdev) static int mtk_mdp_remove(struct platform_device *pdev) { struct mtk_mdp_dev *mdp = platform_get_drvdata(pdev); - struct mtk_mdp_comp *comp, *comp_temp; - pm_runtime_disable(&pdev->dev); + component_master_del(&pdev->dev, &mtk_mdp_com_ops); + vb2_dma_contig_clear_max_seg_size(&pdev->dev); - mtk_mdp_unregister_m2m_device(mdp); v4l2_device_unregister(&mdp->v4l2_dev); flush_workqueue(mdp->wdt_wq); @@ -267,10 +327,8 @@ static int mtk_mdp_remove(struct platform_device *pdev) flush_workqueue(mdp->job_wq); destroy_workqueue(mdp->job_wq); - list_for_each_entry_safe(comp, comp_temp, &mdp->comp_list, node) { - mtk_mdp_unregister_component(mdp, comp); - mtk_mdp_comp_deinit(&pdev->dev, comp); - } + if (!list_empty(&mdp->comp_list)) + dev_warn(&pdev->dev, "not all components removed\n"); dev_dbg(&pdev->dev, "%s driver unloaded\n", pdev->name); return 0; @@ -323,7 +381,25 @@ static struct platform_driver mtk_mdp_driver = { } }; -module_platform_driver(mtk_mdp_driver); +static struct platform_driver * const mtk_mdp_drivers[] = { + &mtk_mdp_driver, + &mtk_mdp_component_driver, +}; + +static int __init mtk_mdp_init(void) +{ + return platform_register_drivers(mtk_mdp_drivers, + ARRAY_SIZE(mtk_mdp_drivers)); +} + +static void __exit mtk_mdp_exit(void) +{ + platform_unregister_drivers(mtk_mdp_drivers, + ARRAY_SIZE(mtk_mdp_drivers)); +} + +module_init(mtk_mdp_init); +module_exit(mtk_mdp_exit); MODULE_AUTHOR("Houlong Wei "); MODULE_DESCRIPTION("Mediatek image processor driver"); diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_core.h b/drivers/media/platform/mtk-mdp/mtk_mdp_core.h index a6e6dc36307b..8a52539b15d4 100644 --- a/drivers/media/platform/mtk-mdp/mtk_mdp_core.h +++ b/drivers/media/platform/mtk-mdp/mtk_mdp_core.h @@ -155,6 +155,7 @@ struct mtk_mdp_dev { struct mtk_mdp_variant *variant; u16 id; struct list_head comp_list; + struct mtk_mdp_comp comp_self; struct v4l2_m2m_dev *m2m_dev; struct list_head ctx_list; struct video_device *vdev; From patchwork Wed Aug 25 06:33:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eizan Miyamoto X-Patchwork-Id: 12456549 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C306FC4338F for ; Wed, 25 Aug 2021 06:35:17 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 8833561245 for ; Wed, 25 Aug 2021 06:35:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 8833561245 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=1az8RvU8OF+7/wf1wDr6IP7Un6X6yZFFPJaIJKYie28=; b=OmdyjNTN/1bhAr Nb5tljXQgFdb0+G2Fu85MZqSykr5yqiKG/JN5xcU0/wOLBbVd7lL/52nO8H9CMIV3fnDDhmoyOjia 6fxJTYMZC/X65UmkYKJ90TavQq1y5Ji5863W46/5vwKiXkl3oiBFtubdIQds8LbuerAz9DUZEk+m2 p9J7HUDUyAEu/c0s5zTZcQh4XEHLKCWsT1OJ0yd4+m88O6hmRdpm71VFtWj5BSpAQW6KgAU8/EyrY gox4y9vhUltptWFIhSza5/TfEgFAuKuq2U4oqab6rUoF4uRCu1w49F5sLW0pOKW+1XJgMnOUL6XkJ 8S1HYBgY2apkmpW4VtbA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mImV4-005g17-7p; Wed, 25 Aug 2021 06:35:02 +0000 Received: from mail-pg1-x529.google.com ([2607:f8b0:4864:20::529]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mImUF-005fbH-2R for linux-mediatek@lists.infradead.org; Wed, 25 Aug 2021 06:34:13 +0000 Received: by mail-pg1-x529.google.com with SMTP id n18so22109678pgm.12 for ; Tue, 24 Aug 2021 23:34:10 -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=ixHDKmGeCSJesMZEO8bPyQxduA9beIl1G8W4ggeif3s=; b=UFzNWstWEwqoHlxwHZq/zy8fqaXQhERaHgnYtMR1h6V02joaZGi/jbck/ainAk6p5f rsgMbI9Ratz7wC90swfqUq3bXI49E7KkGUSx0Q8S8shmkbiOH/cXqkbeFdX17r2tq8p+ uZvYs4oN56Jz+dMs/8c+nnWQNpYJzyVUfGcwo= 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=ixHDKmGeCSJesMZEO8bPyQxduA9beIl1G8W4ggeif3s=; b=US/RoiA201ltQUuHccC8hLGOl/3A0Z1TNqzlFY5Ks9N6Pn1fV1hNmsGLBsz5JxzalB 9FVf2MbKd2SE5lIl3kd6Y8oUMq8VYBRg92PDIbZrhnsYlPlqnqGy+YYc5lsTws9rjiBS PPv8QjdihgafHS66H10mX7XVfrZZJkp9lWLiTy2RQvdru1hSeTjmM4kn7HPEpt/3Hxxm NFg+1C5UPXXWXN7pp7bO/LAoiiQDiJ1kW7rpAuEGnVjeWcZII3C/QKxYSYh9UtiabDJj xkJJuN3jeYlpu9LRHcNR/lkODvdnVjBOeA6wJnQSRr6tQpQ5qHnWlN08E+R0h8C3I2TT ISdQ== X-Gm-Message-State: AOAM5321uB+83W98pmXQafbirNfl032nFmHfftmkTLg72Tg3iZJKCvf5 HVMx+oIzlT9yJSwmSNBS5AzhmQ== X-Google-Smtp-Source: ABdhPJyvVJDYGki03jdnj1yD9Qgmb/mevVghNumzF5IhoCieZdHTK0zUdGzBKTAiwgcinJxJgjJRwg== X-Received: by 2002:a62:be04:0:b029:3e0:3fca:2a8f with SMTP id l4-20020a62be040000b02903e03fca2a8fmr42638513pff.12.1629873250337; Tue, 24 Aug 2021 23:34:10 -0700 (PDT) Received: from localhost ([2401:fa00:9:14:3f2f:9e23:8a5:952]) by smtp.gmail.com with UTF8SMTPSA id v3sm3984882pjd.27.2021.08.24.23.34.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 24 Aug 2021 23:34:10 -0700 (PDT) From: Eizan Miyamoto To: linux-kernel@vger.kernel.org Cc: chunkuang.hu@kernel.org, yong.wu@mediatek.com, wenst@chromium.org, ck.hu@mediatek.com, houlong.wei@mediatek.com, enric.balletbo@collabora.com, yongqiang.niu@mediatek.com, 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 v7 3/7] mtk-mdp: use pm_runtime in MDP component driver Date: Wed, 25 Aug 2021 16:33:19 +1000 Message-Id: <20210825163247.v7.3.I909f5375d930f5d0cc877128e30e2a67078b674c@changeid> X-Mailer: git-send-email 2.33.0.rc2.250.ged5fa647cd-goog In-Reply-To: <20210825063323.3607738-1-eizan@chromium.org> References: <20210825063323.3607738-1-eizan@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210824_233411_160709_18718657 X-CRM114-Status: GOOD ( 24.24 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org Without this change, the MDP components are not fully integrated into the runtime power management subsystem, and the MDP driver does not work. For each of the component device drivers to be able to call pm_runtime_get/put_sync() a pointer to the component's device struct had to be added to struct mtk_mdp_comp, set by mtk_mdp_comp_init(). Note that the dev argument to mtk_mdp_comp_clock_on/off() has been removed. Those functions used to be called from the "master" mdp driver in mtk_mdp_core.c, but the component's device pointer no longer corresponds to the mdp master device pointer, which is not the right device to pass to pm_runtime_put/get_sync() which we had to add to get the driver to work properly. Signed-off-by: Eizan Miyamoto Reviewed-by: Enric Balletbo i Serra Reviewed-by: Houlong Wei --- (no changes since v1) drivers/media/platform/mtk-mdp/mtk_mdp_comp.c | 24 +++++++++++++++---- drivers/media/platform/mtk-mdp/mtk_mdp_comp.h | 6 +++-- drivers/media/platform/mtk-mdp/mtk_mdp_core.c | 7 +++--- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c index 7a0e3acffab9..472c261b01e8 100644 --- a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c +++ b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c @@ -12,6 +12,7 @@ #include #include #include +#include #include "mtk_mdp_comp.h" #include "mtk_mdp_core.h" @@ -50,14 +51,22 @@ static const struct of_device_id mtk_mdp_comp_driver_dt_match[] = { }; MODULE_DEVICE_TABLE(of, mtk_mdp_comp_driver_dt_match); -int mtk_mdp_comp_clock_on(struct device *dev, struct mtk_mdp_comp *comp) +int mtk_mdp_comp_clock_on(struct mtk_mdp_comp *comp) { int i, err, status; if (comp->larb_dev) { err = mtk_smi_larb_get(comp->larb_dev); if (err) - dev_err(dev, "failed to get larb, err %d.\n", err); + dev_err(comp->dev, "failed to get larb, err %d.\n", err); + } + + err = pm_runtime_get_sync(comp->dev); + if (err < 0) { + dev_err(comp->dev, + "failed to runtime get, err %d.\n", + err); + return err; } for (i = 0; i < ARRAY_SIZE(comp->clk); i++) { @@ -66,7 +75,7 @@ int mtk_mdp_comp_clock_on(struct device *dev, struct mtk_mdp_comp *comp) err = clk_prepare_enable(comp->clk[i]); if (err) { status = err; - dev_err(dev, "failed to enable clock, err %d. i:%d\n", err, i); + dev_err(comp->dev, "failed to enable clock, err %d. i:%d\n", err, i); goto err_clk_prepare_enable; } } @@ -80,10 +89,12 @@ int mtk_mdp_comp_clock_on(struct device *dev, struct mtk_mdp_comp *comp) clk_disable_unprepare(comp->clk[i]); } + pm_runtime_put_sync(comp->dev); + return status; } -void mtk_mdp_comp_clock_off(struct device *dev, struct mtk_mdp_comp *comp) +int mtk_mdp_comp_clock_off(struct mtk_mdp_comp *comp) { int i; @@ -95,6 +106,8 @@ void mtk_mdp_comp_clock_off(struct device *dev, struct mtk_mdp_comp *comp) if (comp->larb_dev) mtk_smi_larb_put(comp->larb_dev); + + return pm_runtime_put_sync(comp->dev); } static int mtk_mdp_comp_bind(struct device *dev, struct device *master, void *data) @@ -103,6 +116,7 @@ static int mtk_mdp_comp_bind(struct device *dev, struct device *master, void *da struct mtk_mdp_dev *mdp = data; mtk_mdp_register_component(mdp, comp); + pm_runtime_enable(dev); return 0; } @@ -113,6 +127,7 @@ static void mtk_mdp_comp_unbind(struct device *dev, struct device *master, struct mtk_mdp_comp *comp = dev_get_drvdata(dev); struct mtk_mdp_dev *mdp = data; + pm_runtime_disable(dev); mtk_mdp_unregister_component(mdp, comp); } @@ -132,6 +147,7 @@ int mtk_mdp_comp_init(struct mtk_mdp_comp *comp, struct device *dev) (enum mtk_mdp_comp_type)of_device_get_match_data(dev); INIT_LIST_HEAD(&comp->node); + comp->dev = dev; for (i = 0; i < ARRAY_SIZE(comp->clk); i++) { comp->clk[i] = of_clk_get(node, i); diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h index df5fc4c94f90..f2e22e7e7c45 100644 --- a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h +++ b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h @@ -12,17 +12,19 @@ * @node: list node to track sibing MDP components * @clk: clocks required for component * @larb_dev: SMI device required for component + * @dev: component's device */ struct mtk_mdp_comp { struct list_head node; struct clk *clk[2]; + struct device *dev; struct device *larb_dev; }; int mtk_mdp_comp_init(struct mtk_mdp_comp *comp, struct device *dev); -int mtk_mdp_comp_clock_on(struct device *dev, struct mtk_mdp_comp *comp); -void mtk_mdp_comp_clock_off(struct device *dev, struct mtk_mdp_comp *comp); +int mtk_mdp_comp_clock_on(struct mtk_mdp_comp *comp); +int 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 b813a822439a..714154450981 100644 --- a/drivers/media/platform/mtk-mdp/mtk_mdp_core.c +++ b/drivers/media/platform/mtk-mdp/mtk_mdp_core.c @@ -58,7 +58,7 @@ static int mtk_mdp_clock_on(struct mtk_mdp_dev *mdp) int err; list_for_each_entry(comp_node, &mdp->comp_list, node) { - err = mtk_mdp_comp_clock_on(dev, comp_node); + err = mtk_mdp_comp_clock_on(comp_node); if (err) { status = err; goto err_mtk_mdp_comp_clock_on; @@ -69,18 +69,17 @@ static int mtk_mdp_clock_on(struct mtk_mdp_dev *mdp) err_mtk_mdp_comp_clock_on: list_for_each_entry_continue_reverse(comp_node, &mdp->comp_list, node) - mtk_mdp_comp_clock_off(dev, comp_node); + mtk_mdp_comp_clock_off(comp_node); return status; } static void mtk_mdp_clock_off(struct mtk_mdp_dev *mdp) { - struct device *dev = &mdp->pdev->dev; struct mtk_mdp_comp *comp_node; list_for_each_entry(comp_node, &mdp->comp_list, node) - mtk_mdp_comp_clock_off(dev, comp_node); + mtk_mdp_comp_clock_off(comp_node); } static void mtk_mdp_wdt_worker(struct work_struct *work) From patchwork Wed Aug 25 06:33:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eizan Miyamoto X-Patchwork-Id: 12456551 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 781B0C4320A for ; Wed, 25 Aug 2021 06:35:19 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 476E8613A7 for ; Wed, 25 Aug 2021 06:35:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 476E8613A7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=vnihZ9zgiiWOBzV4XcJG4uJs4Wf6s61NtdlAmfAVi8Y=; b=QxcOYL9HN0dWMv SnGwtpEb3vGmlzrA+MRXYRRnwHmM+lPR+pJbZiXLTa2MCMnp0XOBsgdpllEut2VkcSq1QmaS4Wgjw /OQB/ii02ZdhEtbxXlSc/tVvR8d+DekTIImGaGuNKHNEYfNEUJDIfCerLe62TP9cvNtT7CDgGz9hT 3gStjaI2at11bVtIFtGIW+0Kg/sUkERpv09NnM0t/+X/0KhafokOPwN70Mt2/a4aqY6SG7Lspjzl0 obGVYgrBWE4YYt2UJ/e81vjz4iuCD2orl3xtvlXS3H71kTRwXZmfPKAR2FXYLwcinrbtWGQA31GXk qM/ICEZtoERJcJ6zfFzA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mImV5-005g20-Ns; Wed, 25 Aug 2021 06:35:03 +0000 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mImUM-005feP-NT for linux-mediatek@lists.infradead.org; Wed, 25 Aug 2021 06:34:22 +0000 Received: by mail-pj1-x102c.google.com with SMTP id fs6so2405846pjb.4 for ; Tue, 24 Aug 2021 23:34:18 -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=wU84M23F8XbuzFZjl6FoNSg9wYVt/dBsUxZeJ8oFat8=; b=bYEDw0RxGgcZlrM13Ceata/7fdhbDHYjyV8zsCp4r4mM08ie0cMqU9hi456Dhol3U6 DuQqEoWjxBeDfYQldWNp/cGAH4pW/vfvjisacm1pN/WCiGgIwOMDAltbpssL83NAD1ci 7EEefWctmRBDeBYTdR1n9qekhpmDgyv723KaU= 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=wU84M23F8XbuzFZjl6FoNSg9wYVt/dBsUxZeJ8oFat8=; b=Vedm6RVN9OnznF2LcXcuEHxJHZvWvW85CY3nwT21XGNnAiRxkB9AZFAGPPXd4ZVaw7 mtNBbq+YoSbrWEDRTgDyTCO0wMagemQ4Nu0uMO/51uTUKXRZfCBr4v55E2FE+prCl6t8 xnj0Li5YukWR4yt36n97oTysnvg/vbQ2LqxDdAFR/BNyZ5zFP240lpXX1rkTZAn1nWF/ K06nGNzLwid6wt2URJOHSKW34AhDooXwQw6B54l4xiiijVj9QAoy7pMCtJS2seNJxPnM I2KkOZwWurZshGuEeWyp4HIt99/ADAFXxcqb4AG8bH6Bb2vapOCM8SkwHGxRJxvca+3H o2pw== X-Gm-Message-State: AOAM533cHoqb7ZiXga6ofbNQra7ttX4X6wXSVTIuV0NVZyyocgp8Wi3e d8GNA58rxMkGzPtdS0pEVOY/Mg== X-Google-Smtp-Source: ABdhPJyQtmmIsrwa9pHU6jG08kEdbztCytln3wA+zf/Te2Uc+eDHVuhe7jDW/F194QiNRnTLYYu+gA== X-Received: by 2002:a17:90a:c88:: with SMTP id v8mr8905665pja.197.1629873257982; Tue, 24 Aug 2021 23:34:17 -0700 (PDT) Received: from localhost ([2401:fa00:9:14:3f2f:9e23:8a5:952]) by smtp.gmail.com with UTF8SMTPSA id r14sm21068943pff.106.2021.08.24.23.34.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 24 Aug 2021 23:34:17 -0700 (PDT) From: Eizan Miyamoto To: linux-kernel@vger.kernel.org Cc: chunkuang.hu@kernel.org, yong.wu@mediatek.com, wenst@chromium.org, ck.hu@mediatek.com, houlong.wei@mediatek.com, enric.balletbo@collabora.com, yongqiang.niu@mediatek.com, 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 v7 4/7] media: mtk-mdp: don't pm_run_time_get/put for master comp in clock_on Date: Wed, 25 Aug 2021 16:33:20 +1000 Message-Id: <20210825163247.v7.4.Ifd87681955689a08cce4c65e72ee5e8c6d09af95@changeid> X-Mailer: git-send-email 2.33.0.rc2.250.ged5fa647cd-goog In-Reply-To: <20210825063323.3607738-1-eizan@chromium.org> References: <20210825063323.3607738-1-eizan@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210824_233418_845662_550B004F X-CRM114-Status: GOOD ( 26.17 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org The original intent of commit 86698b9505bbc ("media: mtk-mdp: convert mtk_mdp_dev.comp array to list") was to create a list to track all the MDP components that needed to have their clocks enabled/disabled when calling mtk_mdp_comp_clock_on/off. However, there was a bug inside mtk_mdp_register_component where the args to a call to list_add were swapped. The result is that only one component was added to mtk_mdp_dev.comp_list because comp_list was instead being repeatedly added to the single element lists headed by each mtk_mdp_comp. The order of the args to list_add in mtk_mdp_register_component was fixed in https://patchwork.kernel.org/patch/11742895/ (Fix Null pointer dereference when calling list_add). Then, as a result of https://patchwork.kernel.org/patch/11530769/ (mtk-mdp: use pm_runtime in MDP component driver) if all the components are added to the component list, the mdp "master" / rdma0 component ends up having pm_runtime_get_sync() called on it twice recursively: rpm_resume+0x694/0x8f8 __pm_runtime_resume+0x7c/0xa0 ***NOTE*** mtk_mdp_comp_clock_on+0x48/0x104 [mtk_mdp] mtk_mdp_pm_resume+0x2c/0x44 [mtk_mdp] pm_generic_runtime_resume+0x34/0x48 __genpd_runtime_resume+0x6c/0x80 genpd_runtime_resume+0x104/0x1ac __rpm_callback+0x120/0x238 rpm_callback+0x34/0x8c rpm_resume+0x7a0/0x8f8 __pm_runtime_resume+0x7c/0xa0 ***NOTE*** mtk_mdp_m2m_start_streaming+0x2c/0x3c [mtk_mdp] (The calls to pm_runtime_get_sync are inlined and correspond to the calls to __pm_runtime_resume). It is not correct to have pm_runtime_get_sync called recursively and the second call will block indefinitely. As a result of all that, this change factors mtk_mdp_comp_clock_on/off into mtk_mdp_comp_power_on/off and moves the calls to pm_runtime_get/put into the power_on/off functions. This change then special-cases the master/rdma0 MDP component and does these things: - the master/rdma0 component is not added to mtk_mdp_dev.comp_list - the master/rdma0 component has its clocks (*but not power*) toggled by mtk_mpd_comp_clock_on/off inside mtk_mdp_clock_on/off. - the other components have their clocks *and* power toggled with mtk_mdp_comp_power_on/off. This change introduces the assumption that mtk_mdp_pm_resume will always be called though a callback from pm_runtime_get_sync made on the master / rdma0 component. Signed-off-by: Eizan Miyamoto Reviewed-by: Houlong Wei --- (no changes since v1) drivers/media/platform/mtk-mdp/mtk_mdp_comp.c | 57 ++++++++++++++--- drivers/media/platform/mtk-mdp/mtk_mdp_comp.h | 5 +- drivers/media/platform/mtk-mdp/mtk_mdp_core.c | 62 ++++++++++++++----- 3 files changed, 98 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 472c261b01e8..7b6c8a3f3455 100644 --- a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c +++ b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c @@ -51,9 +51,9 @@ static const struct of_device_id mtk_mdp_comp_driver_dt_match[] = { }; MODULE_DEVICE_TABLE(of, mtk_mdp_comp_driver_dt_match); -int mtk_mdp_comp_clock_on(struct mtk_mdp_comp *comp) +int mtk_mdp_comp_power_on(struct mtk_mdp_comp *comp) { - int i, err, status; + int status, err; if (comp->larb_dev) { err = mtk_smi_larb_get(comp->larb_dev); @@ -63,12 +63,54 @@ int mtk_mdp_comp_clock_on(struct mtk_mdp_comp *comp) err = pm_runtime_get_sync(comp->dev); if (err < 0) { - dev_err(comp->dev, - "failed to runtime get, err %d.\n", - err); + 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 0; + +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); + + return status; +} + +int mtk_mdp_comp_power_off(struct mtk_mdp_comp *comp) +{ + int status, err; + + mtk_mdp_comp_clock_off(comp); + + err = pm_runtime_put_sync(comp->dev); + 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; +} + +int mtk_mdp_comp_clock_on(struct mtk_mdp_comp *comp) +{ + int i, err, status; + for (i = 0; i < ARRAY_SIZE(comp->clk); i++) { if (IS_ERR(comp->clk[i])) continue; @@ -94,7 +136,8 @@ int mtk_mdp_comp_clock_on(struct mtk_mdp_comp *comp) return status; } -int mtk_mdp_comp_clock_off(struct mtk_mdp_comp *comp) + +void mtk_mdp_comp_clock_off(struct mtk_mdp_comp *comp) { int i; @@ -106,8 +149,6 @@ int mtk_mdp_comp_clock_off(struct mtk_mdp_comp *comp) if (comp->larb_dev) mtk_smi_larb_put(comp->larb_dev); - - return pm_runtime_put_sync(comp->dev); } static int mtk_mdp_comp_bind(struct device *dev, struct device *master, void *data) diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h index f2e22e7e7c45..e3d6aef52869 100644 --- a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h +++ b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h @@ -23,8 +23,11 @@ struct mtk_mdp_comp { int mtk_mdp_comp_init(struct mtk_mdp_comp *comp, struct device *dev); +int mtk_mdp_comp_power_on(struct mtk_mdp_comp *comp); +int mtk_mdp_comp_power_off(struct mtk_mdp_comp *comp); + int mtk_mdp_comp_clock_on(struct mtk_mdp_comp *comp); -int mtk_mdp_comp_clock_off(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 714154450981..a72a9ba41ea6 100644 --- a/drivers/media/platform/mtk-mdp/mtk_mdp_core.c +++ b/drivers/media/platform/mtk-mdp/mtk_mdp_core.c @@ -57,29 +57,64 @@ static int mtk_mdp_clock_on(struct mtk_mdp_dev *mdp) struct device *dev = &mdp->pdev->dev; int err; + /* + * The master / rdma0 component will have pm_runtime_get_sync called + * on it through mtk_mdp_m2m_start_streaming, making it unnecessary to + * have mtk_mdp_comp_power_on called on it. + */ + 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_clock_on(comp_node); + err = mtk_mdp_comp_power_on(comp_node); if (err) { status = err; - goto err_mtk_mdp_comp_clock_on; + goto err_mtk_mdp_comp_power_on; } } return 0; -err_mtk_mdp_comp_clock_on: - list_for_each_entry_continue_reverse(comp_node, &mdp->comp_list, node) - mtk_mdp_comp_clock_off(comp_node); - +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) { struct mtk_mdp_comp *comp_node; + int status, err; + + 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; + } + } - list_for_each_entry(comp_node, &mdp->comp_list, node) - mtk_mdp_comp_clock_off(comp_node); + /* + * The master / rdma0 component will have pm_runtime_put called + * on it through mtk_mdp_m2m_stop_streaming, making it unnecessary to + * 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) @@ -118,8 +153,6 @@ static int mtk_mdp_master_bind(struct device *dev) int status; struct mtk_mdp_dev *mdp = dev_get_drvdata(dev); - mtk_mdp_register_component(mdp, &mdp->comp_self); - status = component_bind_all(dev, mdp); if (status) { dev_err(dev, "Failed to bind all components: %d\n", status); @@ -140,8 +173,6 @@ static int mtk_mdp_master_bind(struct device *dev) component_unbind_all(dev, mdp); err_component_bind_all: - mtk_mdp_unregister_component(mdp, &mdp->comp_self); - return status; } @@ -152,7 +183,6 @@ static void mtk_mdp_master_unbind(struct device *dev) pm_runtime_disable(dev); mtk_mdp_unregister_m2m_device(mdp); component_unbind_all(dev, mdp); - mtk_mdp_unregister_component(mdp, &mdp->comp_self); } static const struct component_master_ops mtk_mdp_com_ops = { @@ -337,9 +367,7 @@ 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) From patchwork Wed Aug 25 06:33:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eizan Miyamoto X-Patchwork-Id: 12456553 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6E4CCC4338F for ; Wed, 25 Aug 2021 06:36:03 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 35C5C610CD for ; Wed, 25 Aug 2021 06:36:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 35C5C610CD Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=R6Pul2cG4xR+Xwa9RtMvuhqB/Jvpk5kQhaC7Ab180Po=; b=PIRnEb1MK3hYHe h91s7THAVwlUxuzAUwLFytfUbzruQIBrryt248h6LfIAq/GyYZYxsFoYmEu4ZJ+nfJQy8hcDXzdxK xtHkKF3f58p2B+HuutG+YgyfPXSQhyzT0hiH5ICWQNdfjjD8DI2OK/F7tggqCWXWcLPDz44dqkf04 okszOf7ZG6AcXjmdRe/mgMgLz2anpjl7uvX7Bn7fqPvS0cDY3DgbREcPHHHLMTMVBc8Y/j+KabMYu U4lpmoRmN3NDk5hSAyc/01NbVH6doOv9l8d7b4c3TVLIRWfbaPDLV/6hPY0kHWI1GZOjYPL58i0nB wDsUb6ke01ZrtZgRK8WQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mImVm-005gPA-4f; Wed, 25 Aug 2021 06:35:46 +0000 Received: from mail-pj1-x1033.google.com ([2607:f8b0:4864:20::1033]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mImUU-005fiz-Ns for linux-mediatek@lists.infradead.org; Wed, 25 Aug 2021 06:34:32 +0000 Received: by mail-pj1-x1033.google.com with SMTP id w19-20020a17090aaf9300b00191e6d10a19so3517554pjq.1 for ; Tue, 24 Aug 2021 23:34:26 -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=Bc1vFqHjzCK7JAt5HQQU7hmm2RPaPxlOEZFwyTbvTwg=; b=JidHSnvUqdOyo3NycPJUiVSsgk9ui7s5dR3TxQMYh5OKmHtvE9T25ZD1TGv7fENtvy vDQQltD484BJ1S2QuAS6lmeh0ksv9NTxNE+I4Eh9Jdf86m4+qd1vSy6mYiXjqxLCLH7O 7AuoOqTKAtxFUNOThJBlx46894O35WSCz7VBU= 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=Bc1vFqHjzCK7JAt5HQQU7hmm2RPaPxlOEZFwyTbvTwg=; b=Ick4PiNGmIAkf3xoN7r9Kh7aXzjV5IphThe0VfpMnrAzrwXp1Jjnj7b46wMcrppBjV F4SiZdM/6o+DCkZ6XKPiaYIpfmoC18zeW3MkWtH/lGkAMxhLwAfIaiV219FKjb8PpxtM 78dGKzJEhlHL4ti1jZ1Wa03aRFFIWcGP8FPYjBZ1ffit/LTRaNl0pvRGuAyK1NbWOa3k NeXVLh01gKuE7xOXuIE39rLy16vizCcEQlWrsgiPeWO38V0TksWVbazQFiYio1onpk4J HNc+WqjR1bA+CEHyTFyjs7L/DxYUrfKSkjrwNQC6vLvt/y1MuQnyr2YApAriESV6BLrm Avow== X-Gm-Message-State: AOAM5308cVrYrXZLChBCwWYHyCtU4SkwPrY5PRMVfBza2S4j4dQnCCue 3O7xjOzVU1c3gTmkq+G8jW6qdA== X-Google-Smtp-Source: ABdhPJzN26eiCrVV2PD3nFZJsJ55bLdIFAP+JTAb9z7owSI8OFnrr5SmkWobmLV8e4rvrj3oL1kC0g== X-Received: by 2002:a17:902:7c15:b029:12c:78ec:bb61 with SMTP id x21-20020a1709027c15b029012c78ecbb61mr36982899pll.61.1629873265910; Tue, 24 Aug 2021 23:34:25 -0700 (PDT) Received: from localhost ([2401:fa00:9:14:3f2f:9e23:8a5:952]) by smtp.gmail.com with UTF8SMTPSA id pj14sm3987939pjb.35.2021.08.24.23.34.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 24 Aug 2021 23:34:25 -0700 (PDT) From: Eizan Miyamoto To: linux-kernel@vger.kernel.org Cc: chunkuang.hu@kernel.org, yong.wu@mediatek.com, wenst@chromium.org, ck.hu@mediatek.com, houlong.wei@mediatek.com, enric.balletbo@collabora.com, yongqiang.niu@mediatek.com, 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 v7 5/7] mtk-mdp: make mdp driver to be loadable by platform_device_register*() Date: Wed, 25 Aug 2021 16:33:21 +1000 Message-Id: <20210825163247.v7.5.Iedb6b4f47788548b0cf7bfffae85cac917344c2f@changeid> X-Mailer: git-send-email 2.33.0.rc2.250.ged5fa647cd-goog In-Reply-To: <20210825063323.3607738-1-eizan@chromium.org> References: <20210825063323.3607738-1-eizan@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210824_233426_827162_D0CB0799 X-CRM114-Status: GOOD ( 38.28 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org Rather than hanging the MDP master component driver off of the rdma0 device, make it possible too create a "virtual" device by registering it with platform_device_register_*() to be probed by the mtk_mdp_core driver. Broadly, three interdependent things are done by this change: - Make it is possible to search for MDP devices in the device tree through the grandparent device's of_node. - v4l-related setup is moved into from the mtk_mdp_core driver to the mtk_mdp_comp driver. - Presence of a mediatek,vpu property in an MDP component device node is used to determine what device to use when dispatching DMA ops from the relevant ioctl, and also do V4L2 initialization in this case. Signed-off-by: Eizan Miyamoto Reviewed-by: Enric Balletbo i Serra Reviewed-by: Houlong Wei --- Changes in v7: - Drop last two changes from this series related to removing the vpu property from the mdp_rdma0 device node Changes in v6: - Don't propagate errors from clock_on/off as an afterthought. - Split apart modifying mdp driver to be loadable from mmsys from actually loading it from mmsys into two changs to make review easier. - Update devicetree bindings to reflect no longer needing the mediatek,vpu property in the mdp_rdma0 device node. - Some stylistic cleanups. Changes in v5: - rebase and test on 5.13-next @ e2f74b13dbe6 Changes in v4: - rebase and test on 5.13 - don't depend on https://patchwork.kernel.org/project/linux-mediatek/list/?series=464873 Changes in v3: - get mdp master from aliases instead of strcmp against of_node->name Changes in v2: - rebased onto Linux 5.12 - 100 char line length allowance was utilized in a few places - Removal of a redundant dev_err() print at the end of mtk_mdp_comp_init() - Instead of printing errors and ignoring them, I've added a patch to correctly propagate them. - Use of C style comments. - Three additional patches were added to eliminate dependency on the mediatek,vpu property inside the mdp_rdma0 device node. drivers/media/platform/mtk-mdp/mtk_mdp_comp.c | 51 ++++++++++----- drivers/media/platform/mtk-mdp/mtk_mdp_core.c | 62 ++++++------------- drivers/media/platform/mtk-mdp/mtk_mdp_core.h | 2 + drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c | 4 +- 4 files changed, 60 insertions(+), 59 deletions(-) diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c index 7b6c8a3f3455..85ef274841a3 100644 --- a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c +++ b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c @@ -155,8 +155,45 @@ static int mtk_mdp_comp_bind(struct device *dev, struct device *master, void *da { struct mtk_mdp_comp *comp = dev_get_drvdata(dev); struct mtk_mdp_dev *mdp = data; + struct device_node *vpu_node; mtk_mdp_register_component(mdp, comp); + + /* + * If this component has a "mediatek-vpu" property, it is responsible for + * notifying the mdp master driver about it so it can be further initialized + * later. + */ + vpu_node = of_parse_phandle(dev->of_node, "mediatek,vpu", 0); + if (vpu_node) { + int ret; + + mdp->vpu_dev = of_find_device_by_node(vpu_node); + if (WARN_ON(!mdp->vpu_dev)) { + dev_err(dev, "vpu pdev failed\n"); + of_node_put(vpu_node); + } + + ret = v4l2_device_register(dev, &mdp->v4l2_dev); + if (ret) { + dev_err(dev, "Failed to register v4l2 device\n"); + return -EINVAL; + } + + ret = vb2_dma_contig_set_max_seg_size(dev, DMA_BIT_MASK(32)); + if (ret) { + dev_err(dev, "Failed to set vb2 dma mag seg size\n"); + return -EINVAL; + } + + /* + * presence of the "mediatek,vpu" property in a device node + * indicates that it is the primary MDP rdma device and MDP DMA + * ops should be handled by its DMA callbacks. + */ + mdp->rdma_dev = dev; + } + pm_runtime_enable(dev); return 0; @@ -237,23 +274,9 @@ int mtk_mdp_comp_init(struct mtk_mdp_comp *comp, struct device *dev) static int mtk_mdp_comp_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; - struct device_node *vpu_node; int status; struct mtk_mdp_comp *comp; - vpu_node = of_parse_phandle(dev->of_node, "mediatek,vpu", 0); - if (vpu_node) { - of_node_put(vpu_node); - /* - * The device tree node with a mediatek,vpu property is deemed - * the MDP "master" device, we don't want to add a component - * for it in this function because the initialization for the - * master is done elsewhere. - */ - dev_info(dev, "vpu node found, not probing\n"); - return -ENODEV; - } - comp = devm_kzalloc(dev, sizeof(*comp), GFP_KERNEL); if (!comp) return -ENOMEM; diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_core.c b/drivers/media/platform/mtk-mdp/mtk_mdp_core.c index a72a9ba41ea6..50eafcc9993d 100644 --- a/drivers/media/platform/mtk-mdp/mtk_mdp_core.c +++ b/drivers/media/platform/mtk-mdp/mtk_mdp_core.c @@ -159,6 +159,17 @@ static int mtk_mdp_master_bind(struct device *dev) goto err_component_bind_all; } + if (mdp->vpu_dev) { + int ret = vpu_wdt_reg_handler(mdp->vpu_dev, mtk_mdp_reset_handler, mdp, + VPU_RST_MDP); + if (ret) { + dev_err(dev, "Failed to register reset handler\n"); + goto err_wdt_reg; + } + } else { + dev_err(dev, "no vpu_dev found\n"); + } + status = mtk_mdp_register_m2m_device(mdp); if (status) { dev_err(dev, "Failed to register m2m device: %d\n", status); @@ -170,6 +181,8 @@ static int mtk_mdp_master_bind(struct device *dev) return 0; err_mtk_mdp_register_m2m_device: + +err_wdt_reg: component_unbind_all(dev, mdp); err_component_bind_all: @@ -228,8 +241,13 @@ static int mtk_mdp_probe(struct platform_device *pdev) of_node_put(node); parent = dev->of_node; dev_warn(dev, "device tree is out of date\n"); - } else { + } else if (dev->of_node) { parent = dev->of_node->parent; + } else if (dev->parent) { + /* maybe we were created from a call to platform_device_register_data() */ + parent = dev->parent->parent->of_node; + } else { + return -ENODEV; } /* Iterate over sibling MDP function blocks */ @@ -262,16 +280,6 @@ static int mtk_mdp_probe(struct platform_device *pdev) } } - /* - * Create a component for myself so that clocks can be toggled in - * clock_on(). - */ - ret = mtk_mdp_comp_init(&mdp->comp_self, dev); - if (ret) { - dev_err(dev, "Failed to initialize component\n"); - goto err_comp; - } - mdp->job_wq = create_singlethread_workqueue(MTK_MDP_MODULE_NAME); if (!mdp->job_wq) { dev_err(&pdev->dev, "unable to alloc job workqueue\n"); @@ -287,29 +295,8 @@ static int mtk_mdp_probe(struct platform_device *pdev) } INIT_WORK(&mdp->wdt_work, mtk_mdp_wdt_worker); - ret = v4l2_device_register(dev, &mdp->v4l2_dev); - if (ret) { - dev_err(&pdev->dev, "Failed to register v4l2 device\n"); - ret = -EINVAL; - goto err_dev_register; - } - - mdp->vpu_dev = vpu_get_plat_device(pdev); - ret = vpu_wdt_reg_handler(mdp->vpu_dev, mtk_mdp_reset_handler, mdp, - VPU_RST_MDP); - if (ret) { - dev_err(&pdev->dev, "Failed to register reset handler\n"); - goto err_wdt_reg; - } - platform_set_drvdata(pdev, mdp); - ret = vb2_dma_contig_set_max_seg_size(&pdev->dev, DMA_BIT_MASK(32)); - if (ret) { - dev_err(&pdev->dev, "Failed to set vb2 dma mag seg size\n"); - goto err_set_max_seg_size; - } - ret = component_master_add_with_match(dev, &mtk_mdp_com_ops, match); if (ret) { dev_err(dev, "Component master add failed\n"); @@ -321,22 +308,12 @@ static int mtk_mdp_probe(struct platform_device *pdev) return 0; err_component_master_add: - vb2_dma_contig_clear_max_seg_size(&pdev->dev); - -err_set_max_seg_size: - -err_wdt_reg: - v4l2_device_unregister(&mdp->v4l2_dev); - -err_dev_register: destroy_workqueue(mdp->wdt_wq); err_alloc_wdt_wq: destroy_workqueue(mdp->job_wq); err_alloc_job_wq: - -err_comp: dev_dbg(dev, "err %d\n", ret); return ret; } @@ -404,7 +381,6 @@ static struct platform_driver mtk_mdp_driver = { .driver = { .name = MTK_MDP_MODULE_NAME, .pm = &mtk_mdp_pm_ops, - .of_match_table = mtk_mdp_of_ids, } }; diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_core.h b/drivers/media/platform/mtk-mdp/mtk_mdp_core.h index 8a52539b15d4..9fcd8b8e7c25 100644 --- a/drivers/media/platform/mtk-mdp/mtk_mdp_core.h +++ b/drivers/media/platform/mtk-mdp/mtk_mdp_core.h @@ -133,6 +133,7 @@ struct mtk_mdp_variant { * struct mtk_mdp_dev - abstraction for image processor entity * @lock: the mutex protecting this data structure * @vpulock: the mutex protecting the communication with VPU + * @rdma_dev: device pointer to rdma device for MDP * @pdev: pointer to the image processor platform device * @variant: the IP variant information * @id: image processor device index (0..MTK_MDP_MAX_DEVS) @@ -151,6 +152,7 @@ struct mtk_mdp_variant { struct mtk_mdp_dev { struct mutex lock; struct mutex vpulock; + struct device *rdma_dev; struct platform_device *pdev; struct mtk_mdp_variant *variant; u16 id; diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c b/drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c index f14779e7596e..9834d3bbe851 100644 --- a/drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c +++ b/drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c @@ -929,7 +929,7 @@ static int mtk_mdp_m2m_queue_init(void *priv, struct vb2_queue *src_vq, src_vq->mem_ops = &vb2_dma_contig_memops; src_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer); src_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY; - src_vq->dev = &ctx->mdp_dev->pdev->dev; + src_vq->dev = ctx->mdp_dev->rdma_dev; src_vq->lock = &ctx->mdp_dev->lock; ret = vb2_queue_init(src_vq); @@ -944,7 +944,7 @@ static int mtk_mdp_m2m_queue_init(void *priv, struct vb2_queue *src_vq, dst_vq->mem_ops = &vb2_dma_contig_memops; dst_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer); dst_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY; - dst_vq->dev = &ctx->mdp_dev->pdev->dev; + dst_vq->dev = ctx->mdp_dev->rdma_dev; dst_vq->lock = &ctx->mdp_dev->lock; return vb2_queue_init(dst_vq); From patchwork Wed Aug 25 06:33:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eizan Miyamoto X-Patchwork-Id: 12456555 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 67692C4338F for ; Wed, 25 Aug 2021 06:36:07 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 36766610E8 for ; Wed, 25 Aug 2021 06:36:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 36766610E8 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=QPdmVYBLLIU43jk/qgxzY0F3Brxudr9HRKokAKgosvQ=; b=1Dbij3xsNlQcCr DTFDV58WTomkh1iQF74vz3OLjLrvZHycwg7NLpLuS94Nz38fSWn8BA258edmHhtN+xUVJq1GQ2u11 4W0aMu7ZJBd5OGsqtH1XI+SgNdIp0k60wvjgGeZ4H0qdTmZ3PbddOlV4yUUFAmt9CKsfSz8MMLOAu BB+2j1/o4cYIPPdgBICM4Ku//9Gvvk6WGqKS6RLvuHnWHvurAsD2V2pveL04Syqs8MTr5uuF1wJUh nHjzrKcdDla6OkW6zhPAvlNGGOHS1l6WNr6M8sKLTBQk3QxHr4sezdwZoJ242rVCZAT3QaEDVQ4iH 7U1dz8pt3ddP7xdmWL/Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mImVs-005gSx-OX; Wed, 25 Aug 2021 06:35:52 +0000 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mImUb-005flu-5W for linux-mediatek@lists.infradead.org; Wed, 25 Aug 2021 06:34:37 +0000 Received: by mail-pf1-x436.google.com with SMTP id v123so5692587pfb.11 for ; Tue, 24 Aug 2021 23:34:32 -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=fzlvJ2pAHb+sQ8dhm6xnHR8froez4GvdycGHyMNLelc=; b=F5WiZhJXhxWF/mbzczkd9cNjwJ7S8d9ymOQjMsx98QRxA/cRwjk7CT7VlyyPZ8SMhW 6da0jFGq6g5+LO8kceKVimbN5cE10MTXCRR9QGTyuWnBhktP6IxBUmeDLqAnLqM7WKDK BDkqDUPZIyf2oas8jRvXhgZerNuyKQV0G0uSg= 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=fzlvJ2pAHb+sQ8dhm6xnHR8froez4GvdycGHyMNLelc=; b=scaBl+070g1TeiU7POGPiAWoVeRBGXuJz/popw6FNGR9+j4NqqHV6TEE5wfXO+Qd7a V5NQXAVLPrex0KVFhsyYs+tg/5EkqFzOMcqylYgoqltsJODpE9m5vpr4ku362viHXvbF CbgLCnSCCrdk6vpyr018QZ5GFwHoGUozaHRMs9wjR6bOQyf5Ulhj3aCmrwrXNUkk8QcF LiS76bcPLicawxXkiF5sni96UYmYaSpjuXoBgj+mVdze23g5JKqRYdFTfjeFX4RA/Qo3 UK9tdySlcJZOILVSfhe2aynhS56LuEeLa+aHY1xImuew+391R10sW3jaQIF15naFqOFo A0yQ== X-Gm-Message-State: AOAM531KS8wUb5EgWkolBv+BSO7uk5XsLDYDkl+8W00sO50lJqLLuFMv d8aP9jgKlQACDrqHWGeJxKFP5g== X-Google-Smtp-Source: ABdhPJx2TfFNIn39qLNwd5ZRKN9W2+I5qUl2jnGzviCUVZz+vZQt1XYHenjGJ99AZJTmbQntBR4yZA== X-Received: by 2002:a63:4206:: with SMTP id p6mr32630642pga.449.1629873272423; Tue, 24 Aug 2021 23:34:32 -0700 (PDT) Received: from localhost ([2401:fa00:9:14:3f2f:9e23:8a5:952]) by smtp.gmail.com with UTF8SMTPSA id b10sm21105718pfi.122.2021.08.24.23.34.28 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 24 Aug 2021 23:34:32 -0700 (PDT) From: Eizan Miyamoto To: linux-kernel@vger.kernel.org Cc: chunkuang.hu@kernel.org, yong.wu@mediatek.com, wenst@chromium.org, ck.hu@mediatek.com, houlong.wei@mediatek.com, enric.balletbo@collabora.com, yongqiang.niu@mediatek.com, Eizan Miyamoto , Matthias Brugger , linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org Subject: [PATCH v7 6/7] soc: mediatek: mmsys: instantiate mdp virtual device from mmsys Date: Wed, 25 Aug 2021 16:33:22 +1000 Message-Id: <20210825163247.v7.6.Ie4214d2cc73ab276dd7c41d4f63c98e011fb42d4@changeid> X-Mailer: git-send-email 2.33.0.rc2.250.ged5fa647cd-goog In-Reply-To: <20210825063323.3607738-1-eizan@chromium.org> References: <20210825063323.3607738-1-eizan@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210824_233433_225088_CC5E6218 X-CRM114-Status: GOOD ( 15.74 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org A virtual device that is probed by the mtk_mdp_core driver is instantiated by the mtk_mmsys driver. This better reflects the logical organization of the hardware and driver: there are a number of hardware blocks that are used by the MDP that have no strict hierarchy, and the software driver is responsible for driving them properly. Signed-off-by: Eizan Miyamoto Reviewed-by: Enric Balletbo i Serra Reviewed-by: Houlong Wei --- (no changes since v1) drivers/soc/mediatek/mtk-mmsys.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/drivers/soc/mediatek/mtk-mmsys.c b/drivers/soc/mediatek/mtk-mmsys.c index 080660ef11bf..e681029fe804 100644 --- a/drivers/soc/mediatek/mtk-mmsys.c +++ b/drivers/soc/mediatek/mtk-mmsys.c @@ -97,6 +97,7 @@ static int mtk_mmsys_probe(struct platform_device *pdev) struct platform_device *clks; struct platform_device *drm; struct mtk_mmsys *mmsys; + struct platform_device *mdp; int ret; mmsys = devm_kzalloc(dev, sizeof(*mmsys), GFP_KERNEL); @@ -122,10 +123,27 @@ static int mtk_mmsys_probe(struct platform_device *pdev) PLATFORM_DEVID_AUTO, NULL, 0); if (IS_ERR(drm)) { platform_device_unregister(clks); - return PTR_ERR(drm); + ret = PTR_ERR(drm); + goto err_drm; + } + + mdp = platform_device_register_data(&pdev->dev, "mtk-mdp", + PLATFORM_DEVID_AUTO, NULL, 0); + if (IS_ERR(mdp)) { + ret = PTR_ERR(mdp); + dev_err(dev, "Failed to register mdp: %d\n", ret); + goto err_mdp; } return 0; + +err_mdp: + platform_device_unregister(drm); + +err_drm: + platform_device_unregister(clks); + + return ret; } static const struct of_device_id of_match_mtk_mmsys[] = { From patchwork Wed Aug 25 06:33:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eizan Miyamoto X-Patchwork-Id: 12456557 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 57103C4338F for ; Wed, 25 Aug 2021 06:37:31 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 1CEF4610CD for ; Wed, 25 Aug 2021 06:37:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 1CEF4610CD Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=6SHjNemEL7XMN9mmuMbyR6dCEM9a5PPj1UgfsKCaWnw=; b=nq1JjoKjciE5Ss RX7Ec401Jsc+cRlmTAJJgqv/elU1Hk2/nis41kxubr4YfBoOxls0St1Cuar6z+xMVmMyvUiha29GB N3TnNOck5oMSS9nhefWBSPDIrFTg1s7CAgzrep77faeZdQs5tUjOSiUNOdEXXrgOKgpZrD0wG5APu qRtEp89OKcQfjc9Age/J0yFALje16HuvVuFTPhbBdZ5ZCVEfAGsywGCQV62xs94gErv8uNEv0MBPi H8ZyTyi3isA/Dpe9mo+EyX9xCmgo3NF4S6LKzgSJYIuyET17DcONkQxRgUBy84n1oH3W4FTezOW+c ul8uNYZ5zVRiVkyVsIoQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mImXF-005hG6-GW; Wed, 25 Aug 2021 06:37:17 +0000 Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mImUi-005fpr-Su for linux-mediatek@lists.infradead.org; Wed, 25 Aug 2021 06:34:43 +0000 Received: by mail-pf1-x432.google.com with SMTP id w68so20395767pfd.0 for ; Tue, 24 Aug 2021 23:34:40 -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=4XCVzr5iz0QopfEgURb1CQv1P9/gHJdLhnjxwl27c/s=; b=OSCABazIpuHyd7hIDQTR8xjHANpAJY8mVw/lMwMZAwBneWnPcgnttkDh2iZ/60ivoL pTrwGGLw7RTpT3FYMjCxF8x3hpVJaHrw9keEA77PxIv/Gbb49+gBlsptb8sCQ6GrBd4D 5qW6Kz21+aJnzT9z/MTpPBeMpeORXzsfr1FEg= 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=4XCVzr5iz0QopfEgURb1CQv1P9/gHJdLhnjxwl27c/s=; b=d2j76pXs/VUF4OrGHCn1P40gWnHb+UISOWk5z33fzhZHrG1bYjP8nYcAdeCQAYT86/ Q9Vom9lDVbnTIu/R95ypO3961VDUAiVq9zZck08qqIEbqCx6na88zJblO9Z0rIGe5EbE xcxovSlOhXoNHos2iiU5KzFwi7a7koV4gu5E5Fj7jymCC7PxSoNgF/Kw8R6zNek3k6Oa 4mrY3hKUwnT4Bv47YtQtDNMfBuwONlC/IYVDU9NLXOm3bhLHfykM9FEqEKaGDwXsi66M o9JC8A2taC9vClRK+GCQo8tiXaHeVhbKAy0gcf6UyfrfCyEeIL2iitVKNslTdD2jsn3h FsTw== X-Gm-Message-State: AOAM531yW0HVRD6+OY4LcquxpHO3cy9NBgIutXRZOczb2hr/kknJlrJ8 TP24KGv/Bm2CvW3mpbXxYfWAgQ== X-Google-Smtp-Source: ABdhPJy8M9Dz53jmqObH291x1MiXUcil2JzrRsRDjBq8VrwikvxUeuGojJOB0BY4rvcum4kLxMQzsg== X-Received: by 2002:a63:8f4a:: with SMTP id r10mr39177630pgn.337.1629873280107; Tue, 24 Aug 2021 23:34:40 -0700 (PDT) Received: from localhost ([2401:fa00:9:14:3f2f:9e23:8a5:952]) by smtp.gmail.com with UTF8SMTPSA id v1sm23681435pgj.40.2021.08.24.23.34.35 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 24 Aug 2021 23:34:39 -0700 (PDT) From: Eizan Miyamoto To: linux-kernel@vger.kernel.org Cc: chunkuang.hu@kernel.org, yong.wu@mediatek.com, wenst@chromium.org, ck.hu@mediatek.com, houlong.wei@mediatek.com, enric.balletbo@collabora.com, yongqiang.niu@mediatek.com, 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 v7 7/7] media: mtk-mdp: use mdp-rdma0 alias to point to MDP master Date: Wed, 25 Aug 2021 16:33:23 +1000 Message-Id: <20210825163247.v7.7.I2049e180dca12e0d1b3178bfc7292dcf9e05ac28@changeid> X-Mailer: git-send-email 2.33.0.rc2.250.ged5fa647cd-goog In-Reply-To: <20210825063323.3607738-1-eizan@chromium.org> References: <20210825063323.3607738-1-eizan@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210824_233441_005904_DA20D364 X-CRM114-Status: GOOD ( 27.25 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org ... Instead of depending on the presence of a mediatek,vpu property in the device node. That property was originally added to link to the vpu node so that the mtk_mdp_core driver could pass the right device to vpu_wdt_reg_handler(). However in a previous patch in this series, the driver has been modified to search the device tree for that node instead. That property was also used to indicate the primary MDP device, so that it can be passed to the V4L2 subsystem as well as register it to be used when setting up queues in the open() callback for the filesystem device node that is created. In this case, assuming that the primary MDP device is the one with a specific alias seems useable because the alternative is to add a property to the device tree which doesn't actually represent any facet of hardware (i.e., this being the primary MDP device is a software decision). In other words, this solution is equally as arbitrary, but at least it doesn't add a property to a device node where said property is unrelated to the hardware present. Signed-off-by: Eizan Miyamoto Reviewed-by: Enric Balletbo i Serra --- (no changes since v1) drivers/media/platform/mtk-mdp/mtk_mdp_comp.c | 56 +++++++++++++------ drivers/media/platform/mtk-mdp/mtk_mdp_core.c | 36 ++++++++---- 2 files changed, 64 insertions(+), 28 deletions(-) diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c index 85ef274841a3..9527649de98e 100644 --- a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c +++ b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c @@ -151,29 +151,50 @@ void mtk_mdp_comp_clock_off(struct mtk_mdp_comp *comp) mtk_smi_larb_put(comp->larb_dev); } -static int mtk_mdp_comp_bind(struct device *dev, struct device *master, void *data) +/* + * The MDP master device node is identified by the device tree alias + * "mdp-rdma0". + */ +static bool is_mdp_master(struct device *dev) +{ + struct device_node *aliases, *mdp_rdma0_node; + const char *mdp_rdma0_path; + + if (!dev->of_node) + return false; + + aliases = of_find_node_by_path("/aliases"); + if (!aliases) { + dev_err(dev, "no aliases found for mdp-rdma0"); + return false; + } + + mdp_rdma0_path = of_get_property(aliases, "mdp-rdma0", NULL); + if (!mdp_rdma0_path) { + dev_err(dev, "get mdp-rdma0 property of /aliases failed"); + return false; + } + + mdp_rdma0_node = of_find_node_by_path(mdp_rdma0_path); + if (!mdp_rdma0_node) { + dev_err(dev, "path resolution failed for %s", mdp_rdma0_path); + return false; + } + + return dev->of_node == mdp_rdma0_node; +} + +static int mtk_mdp_comp_bind(struct device *dev, struct device *master, + void *data) { struct mtk_mdp_comp *comp = dev_get_drvdata(dev); struct mtk_mdp_dev *mdp = data; - struct device_node *vpu_node; mtk_mdp_register_component(mdp, comp); - /* - * If this component has a "mediatek-vpu" property, it is responsible for - * notifying the mdp master driver about it so it can be further initialized - * later. - */ - vpu_node = of_parse_phandle(dev->of_node, "mediatek,vpu", 0); - if (vpu_node) { + if (is_mdp_master(dev)) { int ret; - mdp->vpu_dev = of_find_device_by_node(vpu_node); - if (WARN_ON(!mdp->vpu_dev)) { - dev_err(dev, "vpu pdev failed\n"); - of_node_put(vpu_node); - } - ret = v4l2_device_register(dev, &mdp->v4l2_dev); if (ret) { dev_err(dev, "Failed to register v4l2 device\n"); @@ -187,9 +208,8 @@ static int mtk_mdp_comp_bind(struct device *dev, struct device *master, void *da } /* - * presence of the "mediatek,vpu" property in a device node - * indicates that it is the primary MDP rdma device and MDP DMA - * ops should be handled by its DMA callbacks. + * MDP DMA ops will be handled by the DMA callbacks associated with this + * device; */ mdp->rdma_dev = dev; } diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_core.c b/drivers/media/platform/mtk-mdp/mtk_mdp_core.c index 50eafcc9993d..6a775463399c 100644 --- a/drivers/media/platform/mtk-mdp/mtk_mdp_core.c +++ b/drivers/media/platform/mtk-mdp/mtk_mdp_core.c @@ -150,8 +150,9 @@ static void release_of(struct device *dev, void *data) static int mtk_mdp_master_bind(struct device *dev) { - int status; struct mtk_mdp_dev *mdp = dev_get_drvdata(dev); + struct device_node *vpu_node; + int status; status = component_bind_all(dev, mdp); if (status) { @@ -159,15 +160,30 @@ static int mtk_mdp_master_bind(struct device *dev) goto err_component_bind_all; } - if (mdp->vpu_dev) { - int ret = vpu_wdt_reg_handler(mdp->vpu_dev, mtk_mdp_reset_handler, mdp, - VPU_RST_MDP); - if (ret) { - dev_err(dev, "Failed to register reset handler\n"); - goto err_wdt_reg; - } - } else { - dev_err(dev, "no vpu_dev found\n"); + if (mdp->rdma_dev == NULL) { + dev_err(dev, "Primary MDP device not found"); + status = -ENODEV; + goto err_component_bind_all; + } + + vpu_node = of_find_node_by_name(NULL, "vpu"); + if (!vpu_node) { + dev_err(dev, "unable to find vpu node"); + status = -ENODEV; + goto err_wdt_reg; + } + + mdp->vpu_dev = of_find_device_by_node(vpu_node); + if (!mdp->vpu_dev) { + dev_err(dev, "unable to find vpu device"); + status = -ENODEV; + goto err_wdt_reg; + } + + status = vpu_wdt_reg_handler(mdp->vpu_dev, mtk_mdp_reset_handler, mdp, VPU_RST_MDP); + if (status) { + dev_err(dev, "Failed to register reset handler\n"); + goto err_wdt_reg; } status = mtk_mdp_register_m2m_device(mdp);