Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp10826243rwp; Fri, 21 Jul 2023 05:42:41 -0700 (PDT) X-Google-Smtp-Source: APBJJlF6YjxJueoTG0VkNAbn+uWcm568nOCEbuCaobboi0s8Zaoh+P8pbAAHCu9ucxYZxtVd/eR7 X-Received: by 2002:a05:6830:1143:b0:6b9:a192:aaf3 with SMTP id x3-20020a056830114300b006b9a192aaf3mr1849855otq.17.1689943361601; Fri, 21 Jul 2023 05:42:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689943361; cv=none; d=google.com; s=arc-20160816; b=fLCkg0NWigf3mJS/svgPuMZ/6t5AKmS279lNVgK3IqRpPI2yR0sddvXyJSxh/jXSfP vetAvH3aCyy6NiNz1TqjFBLPH9GJkBlKsO25EAIyutKc2DnjwK/RinHfPxyc39cPyaQy Re2QKkXq3/HT2SOWnXHznpgflwHJZD3Y5QUSgEh5cPAEcYibMJQDSk1BAd+KwbH+FDuw 73Qedczo8cAMz7Y3nIgwiE6xBAyJ+rwDmIVbYPKtGatRj2ojhnkAzJmBbJh5XslxNxvU KpcnPPf5dkCbVCypXZi24qWubOtQw48w/VORl0tJplL0VPAwM3TD9vP6JOSFprz+SF+P YoZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=4ArmcI+MiZ5m7czOqaHrGM8yWFr07aDb2MfqTSakCKc=; fh=KWaBc9LeD/WsSjxO2k2TSEbOUX3GbsI3lsjEs//fhG4=; b=soejjznvK2T8Gadn4qP0dRkEm5Wopje2F90/bBUCys53yVljeBpGuON2WYtFSlZN0K 0EJIIKEniCF2u4awj+J425Zu8QeLeZ5f+YpHqgcn0qVVEZWZ9ZnqSydyVSwK+k3JWmLu IxMuTc9IR0x/ta5FUvIaTxgjZLjKlGqFH7ai08fkIUfp4x6cZqMOJxp8P5VTMpLSa9/U 5nWPkYGeemq5lPIT1ETYL7mQGdS6dc7jiXv7gSTYpMjZgK78Dst8gvpAQemrUppjDsPe lp3Tmjz8eVHg92u3/F+oBGiJicUAkmkLFtRxDuKs/nVL28gV79FABuphiAawpMyAsyQV BT6A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xs4all.nl Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a33-20020a631a61000000b0055b79986063si3003806pgm.300.2023.07.21.05.42.28; Fri, 21 Jul 2023 05:42:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xs4all.nl Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229866AbjGULoS (ORCPT + 99 others); Fri, 21 Jul 2023 07:44:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229653AbjGULoQ (ORCPT ); Fri, 21 Jul 2023 07:44:16 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B5701FD7; Fri, 21 Jul 2023 04:44:15 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 7D2B4618E5; Fri, 21 Jul 2023 11:44:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A0051C433C7; Fri, 21 Jul 2023 11:44:11 +0000 (UTC) Message-ID: Date: Fri, 21 Jul 2023 13:44:10 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: Re: [PATCH v5 5/7] media: mediatek: vcodec: Read HW active status from syscon Content-Language: en-US To: =?UTF-8?B?TsOtY29sYXMgRi4gUi4gQS4gUHJhZG8=?= , Matthias Brugger Cc: AngeloGioacchino Del Regno , kernel@collabora.com, Andrew-CT Chen , Mauro Carvalho Chehab , Tiffany Lin , Yunfei Dong , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-mediatek@lists.infradead.org References: <20230630151436.155586-1-nfraprado@collabora.com> <20230630151436.155586-6-nfraprado@collabora.com> From: Hans Verkuil In-Reply-To: <20230630151436.155586-6-nfraprado@collabora.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,NICE_REPLY_A,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 30/06/2023 17:14, NĂ­colas F. R. A. Prado wrote: > Remove the requirement of a VDEC_SYS reg iospace for both MT8173 and > MT8183. To achieve that, rely on a vdecsys syscon to be passed through > the DT, and use it to directly read the VDEC_HW_ACTIVE bit during IRQ > handling to check whether the HW is active. Also update the VP8 stateful > decoder to use the syscon, if present, for writes to VDEC_SYS. > > The old behavior is still present when reg-names aren't supplied, as > to keep backward compatibility. > > Signed-off-by: NĂ­colas F. R. A. Prado > > --- > > Changes in v5: > - Added explicit linux/bitfield.h include for FIELD_GET(), following > 0day report > > Changes in v4: > - Added new helper and updated VP8 stateful decoder to use it, so the > syscon can also be used by mt8173 > - Made handling cleaner > - Reworded commit > > Changes in v3: > - Switched handling of VDEC_HW_ACTIVE to use a syscon instead of the > 'active' clock > - Reworded commit > - Removed changes to subdev part of driver, since they aren't used by > MT8183 > > .../mediatek/vcodec/mtk_vcodec_dec_drv.c | 77 ++++++++++++++++--- > .../platform/mediatek/vcodec/mtk_vcodec_drv.h | 1 + > .../mediatek/vcodec/mtk_vcodec_util.c | 15 ++++ > .../mediatek/vcodec/mtk_vcodec_util.h | 2 + > .../mediatek/vcodec/vdec/vdec_vp8_if.c | 10 +-- > 5 files changed, 87 insertions(+), 18 deletions(-) > > diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_drv.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_drv.c > index 83780d29a9cf..742b6903d030 100644 > --- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_drv.c > +++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_drv.c > @@ -5,13 +5,16 @@ > * Tiffany Lin > */ > > +#include > #include > #include > #include > +#include > #include > #include > #include > #include > +#include > #include > #include > #include > @@ -38,22 +41,30 @@ static int mtk_vcodec_get_hw_count(struct mtk_vcodec_dev *dev) > } > } > > +static bool mtk_vcodec_is_hw_active(struct mtk_vcodec_dev *dev) > +{ > + u32 cg_status; > + > + if (dev->vdecsys_regmap) > + return !regmap_test_bits(dev->vdecsys_regmap, VDEC_HW_ACTIVE_ADDR, > + VDEC_HW_ACTIVE_MASK); > + > + cg_status = readl(dev->reg_base[VDEC_SYS] + VDEC_HW_ACTIVE_ADDR); > + return !FIELD_GET(VDEC_HW_ACTIVE_MASK, cg_status); > +} > + > static irqreturn_t mtk_vcodec_dec_irq_handler(int irq, void *priv) > { > struct mtk_vcodec_dev *dev = priv; > struct mtk_vcodec_ctx *ctx; > - u32 cg_status = 0; > unsigned int dec_done_status = 0; > void __iomem *vdec_misc_addr = dev->reg_base[VDEC_MISC] + > VDEC_IRQ_CFG_REG; > > ctx = mtk_vcodec_get_curr_ctx(dev, MTK_VDEC_CORE); > > - /* check if HW active or not */ > - cg_status = readl(dev->reg_base[0] + VDEC_HW_ACTIVE_ADDR); > - if ((cg_status & VDEC_HW_ACTIVE_MASK) != 0) { > - mtk_v4l2_err("DEC ISR, VDEC active is not 0x0 (0x%08x)", > - cg_status); > + if (!mtk_vcodec_is_hw_active(dev)) { > + mtk_v4l2_err("DEC ISR, VDEC active is not 0x0"); > return IRQ_HANDLED; > } > > @@ -82,6 +93,33 @@ static int mtk_vcodec_get_reg_bases(struct mtk_vcodec_dev *dev) > { > struct platform_device *pdev = dev->plat_dev; > int reg_num, i; > + struct resource *res; > + bool has_vdecsys_reg; > + static const char * const mtk_dec_reg_names[] = { > + "misc", > + "ld", > + "top", > + "cm", > + "ad", > + "av", > + "pp", > + "hwd", > + "hwq", > + "hwb", > + "hwg" > + }; > + > + /* > + * If we have reg-names in devicetree, this means that we're on a new > + * register organization, which implies that the VDEC_SYS iospace gets > + * R/W through a syscon (regmap). > + * Here we try to get the "misc" iostart only to check if we have reg-names > + */ > + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "misc"); > + if (res) > + has_vdecsys_reg = false; > + else > + has_vdecsys_reg = true; > > /* Sizeof(u32) * 4 bytes for each register base. */ > reg_num = of_property_count_elems_of_size(pdev->dev.of_node, "reg", > @@ -91,12 +129,29 @@ static int mtk_vcodec_get_reg_bases(struct mtk_vcodec_dev *dev) > return -EINVAL; > } > > - for (i = 0; i < reg_num; i++) { > - dev->reg_base[i] = devm_platform_ioremap_resource(pdev, i); > - if (IS_ERR(dev->reg_base[i])) > - return PTR_ERR(dev->reg_base[i]); > + if (has_vdecsys_reg) { > + for (i = 0; i < reg_num; i++) { > + dev->reg_base[i] = devm_platform_ioremap_resource(pdev, i); > + if (IS_ERR(dev->reg_base[i])) > + return PTR_ERR(dev->reg_base[i]); > + > + mtk_v4l2_debug(2, "reg[%d] base=%p", i, dev->reg_base[i]); > + } > + } else { > + for (i = 0; i < reg_num; i++) { > + dev->reg_base[i+1] = devm_platform_ioremap_resource_byname(pdev, mtk_dec_reg_names[i]); > + if (IS_ERR(dev->reg_base[i+1])) > + return PTR_ERR(dev->reg_base[i+1]); > > - mtk_v4l2_debug(2, "reg[%d] base=%p", i, dev->reg_base[i]); > + mtk_v4l2_debug(2, "reg[%d] base=%p", i+1, dev->reg_base[i+1]); > + } > + > + dev->vdecsys_regmap = syscon_regmap_lookup_by_phandle(pdev->dev.of_node, > + "mediatek,vdecsys"); > + if (IS_ERR(dev->vdecsys_regmap)) { > + dev_err(&pdev->dev, "Missing mediatek,vdecsys property"); > + return PTR_ERR(dev->vdecsys_regmap); > + } > } > > return 0; > diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h > index f17d67e781c9..0b430936f67d 100644 > --- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h > +++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h > @@ -489,6 +489,7 @@ struct mtk_vcodec_dev { > void __iomem *reg_base[NUM_MAX_VCODEC_REG_BASE]; > const struct mtk_vcodec_dec_pdata *vdec_pdata; > const struct mtk_vcodec_enc_pdata *venc_pdata; > + struct regmap *vdecsys_regmap; You forgot to add the kerneldoc documentation for this new field. If you just give me the documentation of this field then I can modify the patch. That's actually easier for me. Regards, Hans