Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp1497702ybj; Tue, 5 May 2020 22:56:06 -0700 (PDT) X-Google-Smtp-Source: APiQypK0EZ+ZSAUtB5ZRnSxv2wuNqoNmF42fWH+EH716gSnP+wwo2SMSi1WOPs9XKW85nCDopDWL X-Received: by 2002:a17:906:4553:: with SMTP id s19mr5760134ejq.295.1588744566447; Tue, 05 May 2020 22:56:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588744566; cv=none; d=google.com; s=arc-20160816; b=nue9hXrP7nj6tXqLo8Ox5jipEMXaCpEDUJbq3DX2sQTUBJnNLMa+bZQ3Z1uyH4PAls ak/WHQOZVVU+SBsTxgAvSx+nuKHx/CvCxXXnyJnyCUP8mOxjRwvcf9mzhLi4hQ/ltHsr lE8YnrSwKVj61aBSyZz+Zt+4GPI+VMLmUfrMgK8BJLOVNZMpYJGauSb0ZYRl4RA1BMPz KjiQ+Be0HcSzmSTAOARSXop4b0jcK6lDik3enWjni3D4f9FtmxZ4k5YF6pj4tvNASM7O YnsMXq8jO6wS4adntUqfH3t1kP+Zpfln4hVd8Oykn2CPk39VuWGjmoawC685OnFYPCgP 1PiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=N+3HKYDk8zSz1EgIGEHUNCy96067qvgJ8sH43GuyxHY=; b=h4ZLVcAg+7I004OVsKRqzvys76VSvrKDhimcpQxue2iv62WtneX/ZhpFanUTl65KE/ H3AmeL0mmW9MUj4mn86UxuWKyQw7Cr+HnL+05EY8pbHe1RkxU8cuF648OX203O8AfdLa oJcHdvEyRTVDUEpZy0sSjtW/24jdu03dVoYf6AvoXaBsGB++n1yjrE4ws3efGqW4VibX 7JbaEPKF3g16uvY95oL+FaUaeEuwole2d0fEr41f2rD3pWQKkq1JWBlTptvPQHp3atd4 1UXMiheFZb6obxCvXKCyuujNpBq3gRgYlc+Uu3EiJBSxrTTCEADYiCkkwVGNAe0Tn1gZ YJ5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=eGmH0TQf; 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 p22si431496edx.177.2020.05.05.22.55.43; Tue, 05 May 2020 22:56:06 -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=eGmH0TQf; 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 S1727819AbgEFFug (ORCPT + 99 others); Wed, 6 May 2020 01:50:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1727810AbgEFFuf (ORCPT ); Wed, 6 May 2020 01:50:35 -0400 Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B4E52C061A10 for ; Tue, 5 May 2020 22:50:35 -0700 (PDT) Received: by mail-pf1-x442.google.com with SMTP id r14so470727pfg.2 for ; Tue, 05 May 2020 22:50:35 -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=N+3HKYDk8zSz1EgIGEHUNCy96067qvgJ8sH43GuyxHY=; b=eGmH0TQfxFAFuaUTYazwViNZFmQiKOHFXqvoy70Ph67/c7/kiny0X6SdQBU4laf2p8 8EvNzdlpfxO/quJTDIr6HfJ8AMhX85IjTiV7bwg+bDxhXc3McuS27NHNdpTyZzDrXX0Z ZGLMgcjpAolIT0hmEzKRL/p/0o0nmHV4bXdiU= 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=N+3HKYDk8zSz1EgIGEHUNCy96067qvgJ8sH43GuyxHY=; b=Qr7NvT2VptwIWqHjX0OjMsKktrl21TQdS+pQkukNHO/Npk+dzpZDDgbIBN7x7hNr7t 3z/fCesWYNrhvwG0bs+yfZ3W/CrvD/Z5Ln9lKsZZUvRZP/AHbl8H/qcJXoGDNsyXaIRp BA1pqiWgF5LJLCG4mg2XxrwzilzD+WuMtWEgrmvo8l66jxsm2XJ5Rb+2hP0xn5Shq9BT PbuB/0sGE5KinpVXeO1uJ79xBYlzUaBoQAonwVR3945NAumJ6zk/7YnilWFWVLUpfNXp HoqegSBc33m/163MTfMihBbnji3QiuM2DA+EfbC5ktnkWluuaXOjU+sFchW9wHD+F+4j iCXw== X-Gm-Message-State: AGi0PuYN7zlu4kVwJKX+vICwxi8BRi2KNhdFZ7MRxiDGhUOzA38F4+7U +3T6FXhmxPlYgRJLLngoIjyZSq4dUxo= X-Received: by 2002:a62:1dd8:: with SMTP id d207mr6757777pfd.3.1588744234818; Tue, 05 May 2020 22:50:34 -0700 (PDT) Received: from localhost ([2401:fa00:9:14:a92f:c47d:76a8:b09e]) by smtp.gmail.com with ESMTPSA id w125sm713693pgw.22.2020.05.05.22.50.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 05 May 2020 22:50:34 -0700 (PDT) From: Eizan Miyamoto To: LKML Cc: Eizan Miyamoto , Enric Balletbo I Serra , Andrew-CT Chen , Houlong Wei , Matthias Brugger , Mauro Carvalho Chehab , Minghsiu Tsai , linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org, linux-mediatek@lists.infradead.org Subject: [PATCH v2 4/5] [media] mtk-mdp: convert mtk_mdp_dev.comp array to list Date: Wed, 6 May 2020 15:49:19 +1000 Message-Id: <20200506154832.v2.4.I22b7dfc5e6977f5c149f82594832b5bd1d978af9@changeid> X-Mailer: git-send-email 2.26.2.526.g744177e7f7-goog In-Reply-To: <20200506054920.109738-1-eizan@chromium.org> References: <20200506054920.109738-1-eizan@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The functions mtk_mdp_register/unregister_component have been created to add / remove items from the list of components. This will eventually enable us to specify a list of components in the device tree instead of hardcoding them into this driver. The list is modified by a single thread at driver probe time, and will not be traversed by another thread until the call to pm_runtime_enable at the end of probing. Signed-off-by: eizan@chromium.org Reviewed-by: Enric Balletbo I Serra Signed-off-by: Eizan Miyamoto --- Changes in v1: None drivers/media/platform/mtk-mdp/mtk_mdp_comp.c | 1 + drivers/media/platform/mtk-mdp/mtk_mdp_comp.h | 2 + drivers/media/platform/mtk-mdp/mtk_mdp_core.c | 46 +++++++++++++------ drivers/media/platform/mtk-mdp/mtk_mdp_core.h | 10 +++- 4 files changed, 43 insertions(+), 16 deletions(-) diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c index c76cd61fb178..da2bdad7a8d1 100644 --- a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c +++ b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c @@ -103,6 +103,7 @@ int mtk_mdp_comp_init(struct device *dev, struct device_node *node, return -EINVAL; } + INIT_LIST_HEAD(&comp->node); comp->dev_node = of_node_get(node); comp->id = comp_id; comp->type = mtk_mdp_matches[comp_id].type; diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h index 3b83bd6e0d8b..1f745891c6c3 100644 --- a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h +++ b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h @@ -36,6 +36,7 @@ enum mtk_mdp_comp_id { /** * 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 @@ -43,6 +44,7 @@ enum mtk_mdp_comp_id { * @id: component ID */ struct mtk_mdp_comp { + struct list_head node; struct device_node *dev_node; struct clk *clk[2]; struct device *larb_dev; diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_core.c b/drivers/media/platform/mtk-mdp/mtk_mdp_core.c index 17d155219ba2..40b9fda8b03b 100644 --- a/drivers/media/platform/mtk-mdp/mtk_mdp_core.c +++ b/drivers/media/platform/mtk-mdp/mtk_mdp_core.c @@ -55,19 +55,19 @@ MODULE_DEVICE_TABLE(of, mtk_mdp_of_ids); static void mtk_mdp_clock_on(struct mtk_mdp_dev *mdp) { struct device *dev = &mdp->pdev->dev; - int i; + struct mtk_mdp_comp *comp_node; - for (i = 0; i < ARRAY_SIZE(mdp->comp); i++) - mtk_mdp_comp_clock_on(dev, mdp->comp[i]); + list_for_each_entry(comp_node, &mdp->comp_list, node) + mtk_mdp_comp_clock_on(dev, comp_node); } static void mtk_mdp_clock_off(struct mtk_mdp_dev *mdp) { struct device *dev = &mdp->pdev->dev; - int i; + struct mtk_mdp_comp *comp_node; - for (i = 0; i < ARRAY_SIZE(mdp->comp); i++) - mtk_mdp_comp_clock_off(dev, mdp->comp[i]); + list_for_each_entry(comp_node, &mdp->comp_list, node) + mtk_mdp_comp_clock_off(dev, comp_node); } static void mtk_mdp_wdt_worker(struct work_struct *work) @@ -91,12 +91,25 @@ static void mtk_mdp_reset_handler(void *priv) queue_work(mdp->wdt_wq, &mdp->wdt_work); } +void mtk_mdp_register_component(struct mtk_mdp_dev *mdp, + struct mtk_mdp_comp *comp) +{ + list_add(&mdp->comp_list, &comp->node); +} + +void mtk_mdp_unregister_component(struct mtk_mdp_dev *mdp, + struct mtk_mdp_comp *comp) +{ + list_del(&comp->node); +} + static int mtk_mdp_probe(struct platform_device *pdev) { struct mtk_mdp_dev *mdp; struct device *dev = &pdev->dev; struct device_node *node, *parent; - int i, ret = 0; + struct mtk_mdp_comp *comp, *comp_temp; + int ret = 0; mdp = devm_kzalloc(dev, sizeof(*mdp), GFP_KERNEL); if (!mdp) @@ -104,6 +117,7 @@ static int mtk_mdp_probe(struct platform_device *pdev) mdp->id = pdev->id; mdp->pdev = pdev; + INIT_LIST_HEAD(&mdp->comp_list); INIT_LIST_HEAD(&mdp->ctx_list); mutex_init(&mdp->lock); @@ -124,7 +138,6 @@ static int mtk_mdp_probe(struct platform_device *pdev) const struct of_device_id *of_id; enum mtk_mdp_comp_type comp_type; int comp_id; - struct mtk_mdp_comp *comp; of_id = of_match_node(mtk_mdp_comp_dt_ids, node); if (!of_id) @@ -150,13 +163,14 @@ static int mtk_mdp_probe(struct platform_device *pdev) of_node_put(node); goto err_comp; } - mdp->comp[comp_id] = comp; ret = mtk_mdp_comp_init(dev, node, comp, comp_id); if (ret) { of_node_put(node); goto err_comp; } + + mtk_mdp_register_component(mdp, comp); } mdp->job_wq = create_singlethread_workqueue(MTK_MDP_MODULE_NAME); @@ -220,8 +234,10 @@ static int mtk_mdp_probe(struct platform_device *pdev) err_alloc_job_wq: err_comp: - for (i = 0; i < ARRAY_SIZE(mdp->comp); i++) - mtk_mdp_comp_deinit(dev, mdp->comp[i]); + 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; @@ -230,7 +246,7 @@ 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); - int i; + struct mtk_mdp_comp *comp, *comp_temp; pm_runtime_disable(&pdev->dev); vb2_dma_contig_clear_max_seg_size(&pdev->dev); @@ -243,8 +259,10 @@ static int mtk_mdp_remove(struct platform_device *pdev) flush_workqueue(mdp->job_wq); destroy_workqueue(mdp->job_wq); - for (i = 0; i < ARRAY_SIZE(mdp->comp); i++) - mtk_mdp_comp_deinit(&pdev->dev, mdp->comp[i]); + 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); + } dev_dbg(&pdev->dev, "%s driver unloaded\n", pdev->name); return 0; diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_core.h b/drivers/media/platform/mtk-mdp/mtk_mdp_core.h index dd130cc218c9..a7da14b97077 100644 --- a/drivers/media/platform/mtk-mdp/mtk_mdp_core.h +++ b/drivers/media/platform/mtk-mdp/mtk_mdp_core.h @@ -136,7 +136,7 @@ struct mtk_mdp_variant { * @pdev: pointer to the image processor platform device * @variant: the IP variant information * @id: image processor device index (0..MTK_MDP_MAX_DEVS) - * @comp: MDP function components + * @comp_list: list of MDP function components * @m2m_dev: v4l2 memory-to-memory device data * @ctx_list: list of struct mtk_mdp_ctx * @vdev: video device for image processor driver @@ -154,7 +154,7 @@ struct mtk_mdp_dev { struct platform_device *pdev; struct mtk_mdp_variant *variant; u16 id; - struct mtk_mdp_comp *comp[MTK_MDP_COMP_ID_MAX]; + struct list_head comp_list; struct v4l2_m2m_dev *m2m_dev; struct list_head ctx_list; struct video_device *vdev; @@ -221,6 +221,12 @@ struct mtk_mdp_ctx { extern int mtk_mdp_dbg_level; +void mtk_mdp_register_component(struct mtk_mdp_dev *mdp, + struct mtk_mdp_comp *comp); + +void mtk_mdp_unregister_component(struct mtk_mdp_dev *mdp, + struct mtk_mdp_comp *comp); + #if defined(DEBUG) #define mtk_mdp_dbg(level, fmt, args...) \ -- 2.26.2.526.g744177e7f7-goog