Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp4269958pxv; Tue, 27 Jul 2021 03:12:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwKAou6aTcdW2N192QeAcX38RCoSVYZ4NQrGB4DuKLQvIlnqmQDPZ3FOxsq1YdKTOU5IZsu X-Received: by 2002:a02:cce6:: with SMTP id l6mr20962679jaq.114.1627380765232; Tue, 27 Jul 2021 03:12:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627380765; cv=none; d=google.com; s=arc-20160816; b=NUxAHXyJhrSTEFTZShBYT1gZOSiYXbQ+KhxgfQgHe4LhXd4o20riq9wc25bWMnWU0e H5+G4+Y4BMLZD/r6TPBEgKn2EFNkbdZLGHgCOLNHX1fuSIAkP/P+11hPPvMT2xyYYR5o d/Ih48Typxr8oXnpyeZRvUkcdIiYR4dC7HxvuZTkgi8tHnYKb/22nZgmDrjvOjJnzUKN 7SEKbvVPv6ublLAKbHIxjjp5Wp1TgGA79GsehckU65ep110pI//42HPglG2y0csQmS47 /OHDIAAisO4kiXAV3/Lutfk0tEYe6u+6lSlpZx2mKWrYq/UlpXMGPftFVaCcimWcJeHD bJCA== 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=rJWo7AzAz3tFV0Qfux4YLXTGFN144KXACOGUIDYKcas=; b=LmCj0EwPoYUPrO3SEia7XfiRQ6GrTb3DzSFWT55eVX0FxcOhc6sPNM18c7v+Zuc0KY KG5Et7JzMdcPheSumFnhC6qcoEwK4aUuZ2AlQe/61Xm66YIKf0iecRP+9fdExNZxP5cq bPA1mm+Od7sNMyyO8w/hkaQ12enH8QrHrHPUEEE2NeXa9Lgydi8QrG/Cej5+KgHRcRqG 7DCuc11pZVpeLAYVEPjqNPL8FMOLaKi2HXgD0u+cOom79wlzRlSn8CVdSNy4QFBNIZkT bM+rvmOozvtaYZ/3CuFBkMOfOBJQzTg+Mt2GbKsjhJTMa3j0HXWI4yM0z/waWdzGLpJD xPBg== 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 s18si116872iln.27.2021.07.27.03.12.34; Tue, 27 Jul 2021 03:12:45 -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 S236263AbhG0KLe (ORCPT + 99 others); Tue, 27 Jul 2021 06:11:34 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:43430 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S236212AbhG0KLc (ORCPT ); Tue, 27 Jul 2021 06:11:32 -0400 X-UUID: 7c20961ec3e4489d8e3eafa40d68caee-20210727 X-UUID: 7c20961ec3e4489d8e3eafa40d68caee-20210727 Received: from mtkmbs10n1.mediatek.inc [(172.21.101.34)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1137978894; Tue, 27 Jul 2021 18:11:29 +0800 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs02n1.mediatek.inc (172.21.101.77) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 27 Jul 2021 18:11:26 +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; Tue, 27 Jul 2021 18:11:25 +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 v3, 01/15] media: mtk-vcodec: Get numbers of register bases from DT Date: Tue, 27 Jul 2021 18:10:37 +0800 Message-ID: <20210727101051.24418-2-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20210727101051.24418-1-yunfei.dong@mediatek.com> References: <20210727101051.24418-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 --- v3: fix return value --- .../platform/mtk-vcodec/mtk_vcodec_dec_drv.c | 37 ++++++++++++++----- 1 file changed, 28 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..c4172c18a61f 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,30 @@ 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 <= 0 || 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])) { + return PTR_ERR((__force void *)dev->reg_base[i]); + } + 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 +230,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 +262,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.25.1