From patchwork Wed Nov 2 18:08:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Jernej_=C5=A0krabec?= X-Patchwork-Id: 13028759 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C2AE3C433FE for ; Wed, 2 Nov 2022 18:13:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=iEqz91DOoOgrN/yhaatIrEt6Zh5CWcPcxXEyXglYIZQ=; b=zHiQr73LPtJw79 YjKy/wVYU0ycYi9bmRAstHc5eZlDt3iw46gKET5F1TewSnXdQXOZgsYh4sV9DApLQicbyadYTZ0oD bZ2lip0hPVg4KXNjNE3RXCZlqyplSROnf/18QnaupSXqHSHX6SYkm2LNUNOsDulq0Ff+k+3VdiQz9 p143irXWTemrii/tAgRl85IOAjnNRLcQWShDaMP2e4l0bYaVJYl8XCoOcV1GdC6zeFsQEfBi6KhQ/ H/N/bAbn6jyFmNQf40kris2xsdig0QYiuOCx0dmefuo2fwCCAht+AiQdZy1tcnaXLCpevT4H6pkHr OZNVOS+FYBuGs/XDeyrQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oqIDO-00Cr6O-Q9; Wed, 02 Nov 2022 18:11:51 +0000 Received: from mail-ej1-x62f.google.com ([2a00:1450:4864:20::62f]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oqIA4-00Cogq-8W for linux-arm-kernel@lists.infradead.org; Wed, 02 Nov 2022 18:08:26 +0000 Received: by mail-ej1-x62f.google.com with SMTP id f27so47486141eje.1 for ; Wed, 02 Nov 2022 11:08:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8SBm3d04GFk4/+H9PR8aMvqp5TW7eO4YQt832cb+sCg=; b=WR0l2Xt1Y0GAn95DiTLQh6MHGWr8qXgYV/chfa2ugXr4bZT9SQriyRPo6YpT2gASTF UTFPmCNDfFjbM0MfC29UFzhsYwt9b4qmh385Lm7OdlXG4DYX3jlbtCsTcKRqXpqT27j1 OxJpQ8gHoQq/KxIh/yiXTDfjiC3rbAlChB6D7Txv/j9b9ofaQ5KaFjecy7dm2QXnqn9C GCFw4IZD2AFUFXDb+9TiX/9cTvH7xmlwcZ7Emetbqi0nvrlg+S9UYLlgzFgHDmrGSQmF SFjGi+pWDE+Nw/rBjt8ZYzPo3B/h/DLiZB4PjNCVpdMwgCDA6Ud6tVxrntBBP+o9rRGv dCHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8SBm3d04GFk4/+H9PR8aMvqp5TW7eO4YQt832cb+sCg=; b=g40xjDRysmzlQ457Y9Pvrl34rYTLK+eawoDQtK5AvnYuWlts6GeMxl4bmJA8GbhuHK zTGX0/YuLNr69WbuqX6Rm+dyWjtNv23DL23nyYkUTfKAxdUyBpDf757AHBBzw3WbCZqv 4jSmW72WdcmsMZwGEIhr/kWLYNOTcI034eqF17k99aZ3KSE1TqYeGCXF4n2tW3BwaM+N lv7ShhqyXe6/ZAEjiRQCZxtlf9adqZ5vnJ4bSfrToa0G4+ZyO8DWWlXv406UHNZnVcHw ffMQbdKn96pR4pAziLChw/L5JKzSPSUKroQqO+5z/uHhG7DNdZsmWWeizdw8jrQVs47A d15w== X-Gm-Message-State: ACrzQf1WmkZ+s3JO9xtelvTFrVOLIIHYmGAM2n2brtNfR/M0Empwv8cI gKt+pID8O+bwuTdtplawv7g= X-Google-Smtp-Source: AMsMyM5gSMtm7ldxt7yqChPSJ46+ccpg2ZkAAR31xOqTldaMLBY+vUaGSN5+YW6/Te0XXBcGS4fvHA== X-Received: by 2002:a17:907:3206:b0:780:a882:a9ac with SMTP id xg6-20020a170907320600b00780a882a9acmr24800867ejb.765.1667412502028; Wed, 02 Nov 2022 11:08:22 -0700 (PDT) Received: from kista.localdomain (82-149-19-102.dynamic.telemach.net. [82.149.19.102]) by smtp.gmail.com with ESMTPSA id gy8-20020a170906f24800b007317f017e64sm5677460ejb.134.2022.11.02.11.08.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Nov 2022 11:08:21 -0700 (PDT) From: Jernej Skrabec To: mripard@kernel.org, paul.kocialkowski@bootlin.com Cc: mchehab@kernel.org, gregkh@linuxfoundation.org, wens@csie.org, samuel@sholland.org, hverkuil-cisco@xs4all.nl, linux-media@vger.kernel.org, linux-staging@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, Jernej Skrabec Subject: [PATCH v2 04/11] media: cedrus: Add helper for checking capabilities Date: Wed, 2 Nov 2022 19:08:03 +0100 Message-Id: <20221102180810.267252-5-jernej.skrabec@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221102180810.267252-1-jernej.skrabec@gmail.com> References: <20221102180810.267252-1-jernej.skrabec@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221102_110824_359130_108F53DA X-CRM114-Status: GOOD ( 18.22 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org There is several different Cedrus cores with varying capabilities, so some operations like listing formats depends on checks if feature is supported or not. Currently check for capabilities is only in format handling functions, but it will be used also elsewhere later. Let's convert this check to helper and while at it, also simplify it. There is no need to check if capability mask is zero, condition will still work properly. No functional changes intended. Signed-off-by: Jernej Skrabec --- drivers/staging/media/sunxi/cedrus/cedrus.h | 6 +++++ .../staging/media/sunxi/cedrus/cedrus_video.c | 24 +++++++------------ 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/drivers/staging/media/sunxi/cedrus/cedrus.h b/drivers/staging/media/sunxi/cedrus/cedrus.h index 9cffaf228422..1a98790a99af 100644 --- a/drivers/staging/media/sunxi/cedrus/cedrus.h +++ b/drivers/staging/media/sunxi/cedrus/cedrus.h @@ -268,6 +268,12 @@ vb2_to_cedrus_buffer(const struct vb2_buffer *p) return vb2_v4l2_to_cedrus_buffer(to_vb2_v4l2_buffer(p)); } +static inline bool +cedrus_is_capable(struct cedrus_ctx *ctx, unsigned int capabilities) +{ + return (ctx->dev->capabilities & capabilities) == capabilities; +} + void *cedrus_find_control_data(struct cedrus_ctx *ctx, u32 id); u32 cedrus_get_num_of_controls(struct cedrus_ctx *ctx, u32 id); diff --git a/drivers/staging/media/sunxi/cedrus/cedrus_video.c b/drivers/staging/media/sunxi/cedrus/cedrus_video.c index 27a7120fa6fb..192d51397fd2 100644 --- a/drivers/staging/media/sunxi/cedrus/cedrus_video.c +++ b/drivers/staging/media/sunxi/cedrus/cedrus_video.c @@ -73,8 +73,8 @@ static inline struct cedrus_ctx *cedrus_file2ctx(struct file *file) return container_of(file->private_data, struct cedrus_ctx, fh); } -static struct cedrus_format *cedrus_find_format(u32 pixelformat, u32 directions, - unsigned int capabilities) +static struct cedrus_format *cedrus_find_format(struct cedrus_ctx *ctx, + u32 pixelformat, u32 directions) { struct cedrus_format *first_valid_fmt = NULL; struct cedrus_format *fmt; @@ -83,7 +83,7 @@ static struct cedrus_format *cedrus_find_format(u32 pixelformat, u32 directions, for (i = 0; i < CEDRUS_FORMATS_COUNT; i++) { fmt = &cedrus_formats[i]; - if ((fmt->capabilities & capabilities) != fmt->capabilities || + if (!cedrus_is_capable(ctx, fmt->capabilities) || !(fmt->directions & directions)) continue; @@ -177,19 +177,13 @@ static int cedrus_enum_fmt(struct file *file, struct v4l2_fmtdesc *f, u32 direction) { struct cedrus_ctx *ctx = cedrus_file2ctx(file); - struct cedrus_dev *dev = ctx->dev; - unsigned int capabilities = dev->capabilities; - struct cedrus_format *fmt; unsigned int i, index; /* Index among formats that match the requested direction. */ index = 0; for (i = 0; i < CEDRUS_FORMATS_COUNT; i++) { - fmt = &cedrus_formats[i]; - - if (fmt->capabilities && (fmt->capabilities & capabilities) != - fmt->capabilities) + if (!cedrus_is_capable(ctx, cedrus_formats[i].capabilities)) continue; if (!(cedrus_formats[i].directions & direction)) @@ -244,10 +238,9 @@ static int cedrus_g_fmt_vid_out(struct file *file, void *priv, static int cedrus_try_fmt_vid_cap_p(struct cedrus_ctx *ctx, struct v4l2_pix_format *pix_fmt) { - struct cedrus_dev *dev = ctx->dev; struct cedrus_format *fmt = - cedrus_find_format(pix_fmt->pixelformat, CEDRUS_DECODE_DST, - dev->capabilities); + cedrus_find_format(ctx, pix_fmt->pixelformat, + CEDRUS_DECODE_DST); if (!fmt) return -EINVAL; @@ -269,10 +262,9 @@ static int cedrus_try_fmt_vid_cap(struct file *file, void *priv, static int cedrus_try_fmt_vid_out_p(struct cedrus_ctx *ctx, struct v4l2_pix_format *pix_fmt) { - struct cedrus_dev *dev = ctx->dev; struct cedrus_format *fmt = - cedrus_find_format(pix_fmt->pixelformat, CEDRUS_DECODE_SRC, - dev->capabilities); + cedrus_find_format(ctx, pix_fmt->pixelformat, + CEDRUS_DECODE_SRC); if (!fmt) return -EINVAL;