Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp5281913pxv; Tue, 6 Jul 2021 23:24:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxrOo0/+3P/z8nBpGhAgBysWPlPhUWQiXQQQz93dT1yGFkXNV+olmdzfB99ZIFdgdgxGFcd X-Received: by 2002:a17:907:2d0e:: with SMTP id gs14mr23203873ejc.49.1625639043209; Tue, 06 Jul 2021 23:24:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625639043; cv=none; d=google.com; s=arc-20160816; b=ipQNaewtkgddyZtaU7OtRMOrZsk//TQ48VonZbCyrKMPwy1/PEcniZmu6RZ5iZZ/rJ VrWudzMixDKShudkSONCaPLajT2iBSbTnWwJ2Gju2VrRASrxe+SfON8fH5txRteaUwl+ c9ZZco7XySkv+/7qy8XlZmz+vVWo0sUvO+m1K+e7ojamumeb/J6ZsmCB+83WlcfuP3Py mxEdeMOMiObyKGFGAvgEZ5A4oopefFEeNAxjNjxwAUFImT8pu9i+lvDamDztd+ftPFH3 koJ/wKikRrUwPtNoPsft/Q6NiqQPfp2vifIDzyaZMTExqah8ZPw/xsJErWS2M/TRv9sG D/sg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=5CK+xxcgCVcyJdTs2PwjQgjLdxzetnnGwEbeDvgPgAA=; b=WJzTVQBJCui/N51BEjbluHUWUxi8J8jKGZv3BoT/d16UcJVOZyh533XG6kVgqU+O6f cH4uR+JGuvPBO13mbabLO1M1OV0EXWw/NChWWQKEWUYOrY0DLAHgIVKvQtcEzRrA685P 7AU0cY7GEi8XoEfqO76deA0WuIdNR1PlHYe8K9Co1CT+XqYgiRgteG7E4ske+zw00/f0 RcryxFloME7LVwDbGeju8/8KzrSim2MECqBh82PMsTxQ9BsNx6qb0pDU/MTppC994ynu I8g+mnDTMqv9EOsBTq4PSZh0klUVSLkGI7/1tBDcCraiiLHGJuruTg+hlD8YoLeG1Zh8 CJuA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b21si15847892edx.337.2021.07.06.23.23.35; Tue, 06 Jul 2021 23:24:03 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230324AbhGGGZG (ORCPT + 99 others); Wed, 7 Jul 2021 02:25:06 -0400 Received: from mailgw01.mediatek.com ([60.244.123.138]:49500 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S230273AbhGGGZC (ORCPT ); Wed, 7 Jul 2021 02:25:02 -0400 X-UUID: 1f9428fe586d4e149dce97566de8c3e3-20210707 X-UUID: 1f9428fe586d4e149dce97566de8c3e3-20210707 Received: from mtkmbs10n1.mediatek.inc [(172.21.101.34)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 152082278; Wed, 07 Jul 2021 14:22:19 +0800 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs02n2.mediatek.inc (172.21.101.101) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 7 Jul 2021 14:22:16 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Wed, 7 Jul 2021 14:22:15 +0800 From: Yunfei Dong To: Yunfei Dong , Alexandre Courbot , Hans Verkuil , Tzung-Bi Shih , Tiffany Lin , Andrew-CT Chen , Mauro Carvalho Chehab , Rob Herring , Matthias Brugger , Tomasz Figa CC: Hsin-Yi Wang , Fritz Koenig , Irui Wang , , , , , , , Subject: [PATCH v1, 01/14] media: mtk-vcodec: Get numbers of register bases from DT Date: Wed, 7 Jul 2021 14:21:44 +0800 Message-ID: <20210707062157.21176-2-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20210707062157.21176-1-yunfei.dong@mediatek.com> References: <20210707062157.21176-1-yunfei.dong@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Different platform may has different numbers of register bases. Gets the numbers of register bases from DT (sizeof(u32) * 4 bytes for each). Signed-off-by: Yunfei Dong --- .../platform/mtk-vcodec/mtk_vcodec_dec_drv.c | 38 ++++++++++++++----- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c index 55ae198dbcf9..d3f34cd04759 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c @@ -78,6 +78,31 @@ static irqreturn_t mtk_vcodec_dec_irq_handler(int irq, void *priv) return IRQ_HANDLED; } +static int mtk_vcodec_get_reg_bases(struct mtk_vcodec_dev *dev) +{ + struct platform_device *pdev = dev->plat_dev; + int reg_num, i, ret = 0; + + /* Sizeof(u32) * 4 bytes for each register base. */ + reg_num = of_property_count_elems_of_size(pdev->dev.of_node, "reg", + sizeof(u32) * 4); + if (!reg_num || reg_num > NUM_MAX_VDEC_REG_BASE) { + dev_err(&pdev->dev, "Invalid register property size: %d\n", reg_num); + return -EINVAL; + } + + for (i = 0; i < reg_num; i++) { + dev->reg_base[i] = devm_platform_ioremap_resource(pdev, i); + if (IS_ERR((__force void *)dev->reg_base[i])) { + ret = PTR_ERR((__force void *)dev->reg_base[i]); + break; + } + mtk_v4l2_debug(2, "reg[%d] base=%p", i, dev->reg_base[i]); + } + + return ret; +} + static int fops_vcodec_open(struct file *file) { struct mtk_vcodec_dev *dev = video_drvdata(file); @@ -206,7 +231,7 @@ static int mtk_vcodec_probe(struct platform_device *pdev) struct resource *res; phandle rproc_phandle; enum mtk_vcodec_fw_type fw_type; - int i, ret; + int ret; dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); if (!dev) @@ -238,14 +263,9 @@ static int mtk_vcodec_probe(struct platform_device *pdev) goto err_dec_pm; } - for (i = 0; i < NUM_MAX_VDEC_REG_BASE; i++) { - dev->reg_base[i] = devm_platform_ioremap_resource(pdev, i); - if (IS_ERR((__force void *)dev->reg_base[i])) { - ret = PTR_ERR((__force void *)dev->reg_base[i]); - goto err_res; - } - mtk_v4l2_debug(2, "reg[%d] base=%p", i, dev->reg_base[i]); - } + ret = mtk_vcodec_get_reg_bases(dev); + if (ret) + goto err_res; res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); if (res == NULL) { -- 2.18.0