Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp309534pxv; Thu, 8 Jul 2021 03:05:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxV4f84QI+oJ9RLXwxFCAsvC8wajb9niXcXZpFMxhYfPR8h76Zrx8awo9GxeVNa8VyAr6WD X-Received: by 2002:a05:6e02:c74:: with SMTP id f20mr21972614ilj.85.1625738743479; Thu, 08 Jul 2021 03:05:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625738743; cv=none; d=google.com; s=arc-20160816; b=vxV1OUTlqoKHy5LYYW7PKCDx3RR1yyQE1sRIdlC1FRrlyaVURda/V68IB7HY/egFbH e9HOze/FzULoPIdAsZ+jrt70b663G0o/3aeAvfyFe80jT6YvbtJLxkHQ6xoXQt7JMIUF aoHxmETgSSsD+yOg3hhsksHUh4+u8e1HBgqPyktzQJlsCFuQWgP+5xESFLGyNonYxkPO 3r/ycjzulRjOyMbgwDAV5zW75PD91qCRxiTLPpvMMreLksSziEWAajmgxC5yJnWlHEhO 72OWrZU+yWY8pC07ROJQ6lTeRbmXWeMH2dXC5cKJoJo8fBmJDYTyN9WzzXRcxc0r0zrT 8U7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=5IYDrTEMCDwnKyJ3pPqsfquwkNIQ3KZz5NeM09+NirQ=; b=zfxZKqtjUswwaY4H6b+8oABPP7Y2v8Bo0PLHStIl2jHPxvsYlTdAaj2/v2D0VB/8g5 J6DANBKaeTOBxVVouxCZOXMV2MwnhZ9jxM6YhW+vSgUjWRbRDTwmQvGhWYcyvZFuaEn+ xOkvlKNPfyA8avikoM6i+zLpnW2wmls2bVCJ1k5MhK1UtXlt3UOz/F6kStqJ7/aWxxLx sBCq9y6zBVnTgGSjgKcV4bkdqRZrDrCOOffcDE6ySOl/nJL1aj59kGwxBw7lEhhU/vnl edTNMQw1NedXlOdemo2iw3d/tj1RbgKtTRaJnsRDKMGLigeBNRTYR2ftyaj9VzgCrfpH NH5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=WT0IEe21; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m6si1753659iol.83.2021.07.08.03.05.30; Thu, 08 Jul 2021 03:05:43 -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=@google.com header.s=20161025 header.b=WT0IEe21; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231392AbhGHKHl (ORCPT + 99 others); Thu, 8 Jul 2021 06:07:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231324AbhGHKHl (ORCPT ); Thu, 8 Jul 2021 06:07:41 -0400 Received: from mail-il1-x12b.google.com (mail-il1-x12b.google.com [IPv6:2607:f8b0:4864:20::12b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B99DAC061760 for ; Thu, 8 Jul 2021 03:04:58 -0700 (PDT) Received: by mail-il1-x12b.google.com with SMTP id o8so6034194ilf.12 for ; Thu, 08 Jul 2021 03:04:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=5IYDrTEMCDwnKyJ3pPqsfquwkNIQ3KZz5NeM09+NirQ=; b=WT0IEe21WXTnQTiqpmOB+Z7yiM37k35gUjaW8q23hwFIywW2R2O7AFYBYWpcVr/+Es YmKVFiMUfMAiwklQ2WYfEOX+1AzVmj9HIlAtY5tP3B/D370620P9O8uqI4w7idZcoJzb mFD6oAx2w9DekQ0F48e2kH5ZJzTFTxb41fXfnwqRcmracyx6S+h4KwMD8p/N1Qb7aOlr QM0+8o+Ciq5rgy6rSpW62cXas0FgzJvkZrwnmnyZkccPk8Z7zXjQl4SSv+4PEgROGeqW UULK4pSaFMwqw6SHGqyAPdwIusNrevhgnIybsjDnZmKlBwOvpBQMvDoGL7ssMgG/5joI iBHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=5IYDrTEMCDwnKyJ3pPqsfquwkNIQ3KZz5NeM09+NirQ=; b=sL8NB8ITe9A9Zy4SntLgLnSr5Vyp7/EnR/ErzBW9KhHlNvThpZ3xEHBQda6GdXYEYs aVu0Kn5MAfsl/tEmrDkgKaDQjoDE59UsPeEVd3R1gFSzoabSyUyngds8YlvGlGcyrHBI Pgjdnb3KGTznNaa7MkmedPzlpmdB3P0AyS2OtF668zbhJvtHxIAYRPMJKiCtOTySH+sH bJ0ojDp3O1EFGV5DGNKJQMRbp+UjOL4HiIiIH5ssOBOgE4RccvjZ9SZCe4fYFqZN2FL+ Mp97l7G3du6JKNcQWj+Kl1n8cjCr8BKT8vCOeN9Mo+eWRU3lvZFlrKvZJypgKmST0Kfo +mHg== X-Gm-Message-State: AOAM530xbqS2xA3xpFijihbY59gSsX1VlKzg1Gu/4lliYqZ0nu9A34V1 joeY2LeThRgSFPVN3GBIKDREMNXopX59cPQVZKxBpQ== X-Received: by 2002:a92:de12:: with SMTP id x18mr21843666ilm.302.1625738697789; Thu, 08 Jul 2021 03:04:57 -0700 (PDT) MIME-Version: 1.0 References: <20210707062157.21176-1-yunfei.dong@mediatek.com> <20210707062157.21176-4-yunfei.dong@mediatek.com> In-Reply-To: <20210707062157.21176-4-yunfei.dong@mediatek.com> From: Tzung-Bi Shih Date: Thu, 8 Jul 2021 18:04:46 +0800 Message-ID: Subject: Re: [PATCH v1, 03/14] media: mtk-vcodec: Use component framework to manage each hardware information To: Yunfei Dong Cc: Alexandre Courbot , Hans Verkuil , Tzung-Bi Shih , Tiffany Lin , Andrew-CT Chen , Mauro Carvalho Chehab , Rob Herring , Matthias Brugger , Tomasz Figa , Hsin-Yi Wang , Fritz Koenig , Irui Wang , linux-media@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, srv_heupstream@mediatek.com, linux-mediatek@lists.infradead.org, Project_Global_Chrome_Upstream_Group@mediatek.com Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jul 7, 2021 at 2:22 PM Yunfei Dong wrote: > +#include "mtk_vcodec_util.h" > + > #include > +#include > #include The changes look like independent ones. If any .c files need the headers, include them in the .c files instead of here. > + comp_node = of_find_compatible_node(NULL, NULL, > + mtk_vdec_drv_ids[i].compatible); > + if (!comp_node) > + continue; > + > + if (!of_device_is_available(comp_node)) { > + of_node_put(comp_node); > + dev_err(&pdev->dev, "Fail to get MMSYS node\n"); > + continue; > + } > + > + of_id = of_match_node(mtk_vdec_drv_ids, comp_node); > + if (!of_id) { Doesn't it need to call of_node_put(comp_node)? > +static int mtk_vcodec_init_master(struct mtk_vcodec_dev *dev) > +{ > + struct platform_device *pdev = dev->plat_dev; > + struct component_match *match; > + int ret = 0; ret doesn't need to be initialized. > + match = mtk_vcodec_match_add(dev); > + if (IS_ERR_OR_NULL(match)) > + return -EINVAL; > + > + platform_set_drvdata(pdev, dev); Why does platform_set_drvdata() need to be here? The function neither creates pdev nor dev. > +static int mtk_vcodec_init_dec_params(struct mtk_vcodec_dev *dev) > +{ > + struct platform_device *pdev = dev->plat_dev; > + struct resource *res; > + int ret = 0; ret doesn't need to be initialized. > + if (!dev->is_support_comp) { > + res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); > + if (res == NULL) { !res, res is not used BTW. > + dev->dec_irq = platform_get_irq(dev->plat_dev, 0); Check return value. > + irq_set_status_flags(dev->dec_irq, IRQ_NOAUTOEN); > + ret = devm_request_irq(&pdev->dev, dev->dec_irq, > + mtk_vcodec_dec_irq_handler, 0, pdev->name, dev); > + if (ret) { > + dev_err(&pdev->dev, "failed to install dev->dec_irq %d (%d)", > + dev->dec_irq, > + ret); Can join to previous line. > + if (!of_find_compatible_node(NULL, NULL, "mediatek,mtk-vcodec-core")) > + dev->is_support_comp = false; > + else > + dev->is_support_comp = true; Need a DT binding document patch for the attribute. Does it really need to call of_find_compatible_node() for parsing an attribute? If so, it needs to call of_node_put() afterward. > @@ -319,7 +434,6 @@ static int mtk_vcodec_probe(struct platform_device *pdev) > MTK_VCODEC_DEC_NAME); > video_set_drvdata(vfd_dec, dev); > dev->vfd_dec = vfd_dec; > - platform_set_drvdata(pdev, dev); Why does it need to remove platform_set_drvdata()? > @@ -370,8 +484,17 @@ static int mtk_vcodec_probe(struct platform_device *pdev) > mtk_v4l2_debug(0, "decoder registered as /dev/video%d", > vfd_dec->num); > > - return 0; > + if (dev->is_support_comp) { > + ret = mtk_vcodec_init_master(dev); > + if (ret < 0) > + goto err_component_match; > + } else { > + platform_set_drvdata(pdev, dev); > + } mtk_vcodec_init_master() also calls platform_set_drvdata(). What is the difference? > + /* clear interrupt */ > + writel((readl(vdec_misc_addr) | VDEC_IRQ_CFG), vdec_misc_addr); > + writel((readl(vdec_misc_addr) & ~VDEC_IRQ_CLR), vdec_misc_addr); Can remove 1 parenthese pair. > +static int mtk_vdec_comp_probe(struct platform_device *pdev) > +{ > + struct mtk_vdec_comp_dev *dev; > + int ret; > + > + dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); > + if (!dev) > + return -ENOMEM; > + > + dev->plat_dev = pdev; > + spin_lock_init(&dev->irqlock); > + > + ret = mtk_vcodec_init_dec_pm(dev->plat_dev, &dev->pm); To be concise, use pdev. > + dev->reg_base[VDEC_COMP_MISC] = > + devm_platform_ioremap_resource(pdev, 0); Confusing about the index 0, where: VDEC_COMP_SYS = 0 VDEC_COMP_MISC = 1 > +#ifndef _MTK_VCODEC_DEC_HW_H_ > +#define _MTK_VCODEC_DEC_HW_H_ > + > +#include Does it really need to include component.h? > +/** > + * enum mtk_comp_hw_reg_idx - component register base index > + */ > +enum mtk_comp_hw_reg_idx { > + VDEC_COMP_SYS, > + VDEC_COMP_MISC, > + NUM_MAX_COMP_VCODEC_REG_BASE The name is suboptimal. How about VDEC_COMP_MAX or VDEC_COMP_LAST? > +#include > +#include > #include > #include > #include The newly added code in the file doesn't look like it needs anything from component.h and io.h. > @@ -404,6 +422,7 @@ struct mtk_vcodec_enc_pdata { > * > * @fw_handler: used to communicate with the firmware. > * @id_counter: used to identify current opened instance > + * @is_support_comp: 1: using compoent framework, 0: not support is_support_comp is a boolean. Use true and false instead of 1 and 0. > @@ -422,6 +441,10 @@ struct mtk_vcodec_enc_pdata { > * @pm: power management control > * @dec_capability: used to identify decode capability, ex: 4k > * @enc_capability: used to identify encode capability > + * > + * comp_dev: component hardware device > + * component_node: component node > + * comp_idx: component index To be neat, missing "@" before each symbol name.