[PATCH v6 09/17] media: rkvdec: Add variant specific coded formats list

Jonas Karlman jonas at kwiboo.se
Wed Dec 17 15:37:20 PST 2025


Hi Detlev,

On 12/17/2025 6:40 PM, Detlev Casanova wrote:
> Prepare for adding new variants of the decoder and support specific
> formats and format ops per variant.
> 
> Tested-by: Diederik de Haas <didi.debian at cknow.org>  # Rock 5B
> Signed-off-by: Detlev Casanova <detlev.casanova at collabora.com>
> ---
>  .../media/platform/rockchip/rkvdec/rkvdec.c   | 35 ++++++++++++-------
>  .../media/platform/rockchip/rkvdec/rkvdec.h   |  2 ++
>  2 files changed, 24 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/media/platform/rockchip/rkvdec/rkvdec.c b/drivers/media/platform/rockchip/rkvdec/rkvdec.c
> index 776149f871b0..968982f6e62c 100644
> --- a/drivers/media/platform/rockchip/rkvdec/rkvdec.c
> +++ b/drivers/media/platform/rockchip/rkvdec/rkvdec.c
> @@ -373,15 +373,16 @@ static bool rkvdec_is_capable(struct rkvdec_ctx *ctx, unsigned int capability)
>  static const struct rkvdec_coded_fmt_desc *
>  rkvdec_enum_coded_fmt_desc(struct rkvdec_ctx *ctx, int index)
>  {
> +	const struct rkvdec_variant *variant = ctx->dev->variant;
>  	int fmt_idx = -1;
>  	unsigned int i;
>  
> -	for (i = 0; i < ARRAY_SIZE(rkvdec_coded_fmts); i++) {
> -		if (!rkvdec_is_capable(ctx, rkvdec_coded_fmts[i].capability))
> +	for (i = 0; i < variant->num_coded_fmts; i++) {
> +		if (!rkvdec_is_capable(ctx, variant->coded_fmts[i].capability))
>  			continue;
>  		fmt_idx++;
>  		if (index == fmt_idx)
> -			return &rkvdec_coded_fmts[i];
> +			return &variant->coded_fmts[i];
>  	}
>  
>  	return NULL;
> @@ -390,12 +391,13 @@ rkvdec_enum_coded_fmt_desc(struct rkvdec_ctx *ctx, int index)
>  static const struct rkvdec_coded_fmt_desc *
>  rkvdec_find_coded_fmt_desc(struct rkvdec_ctx *ctx, u32 fourcc)
>  {
> +	const struct rkvdec_variant *variant = ctx->dev->variant;
>  	unsigned int i;
>  
> -	for (i = 0; i < ARRAY_SIZE(rkvdec_coded_fmts); i++) {
> -		if (rkvdec_is_capable(ctx, rkvdec_coded_fmts[i].capability) &&
> -		    rkvdec_coded_fmts[i].fourcc == fourcc)
> -			return &rkvdec_coded_fmts[i];
> +	for (i = 0; i < variant->num_coded_fmts; i++) {
> +		if (rkvdec_is_capable(ctx, variant->coded_fmts[i].capability) &&
> +		    variant->coded_fmts[i].fourcc == fourcc)
> +			return &variant->coded_fmts[i];
>  	}
>  
>  	return NULL;
> @@ -1014,18 +1016,19 @@ static int rkvdec_add_ctrls(struct rkvdec_ctx *ctx,
>  
>  static int rkvdec_init_ctrls(struct rkvdec_ctx *ctx)
>  {
> +	const struct rkvdec_variant *variant = ctx->dev->variant;
>  	unsigned int i, nctrls = 0;
>  	int ret;
>  
> -	for (i = 0; i < ARRAY_SIZE(rkvdec_coded_fmts); i++)
> -		if (rkvdec_is_capable(ctx, rkvdec_coded_fmts[i].capability))
> -			nctrls += rkvdec_coded_fmts[i].ctrls->num_ctrls;
> +	for (i = 0; i < variant->num_coded_fmts; i++)
> +		if (rkvdec_is_capable(ctx, variant->coded_fmts[i].capability))
> +			nctrls += variant->coded_fmts[i].ctrls->num_ctrls;
>  
>  	v4l2_ctrl_handler_init(&ctx->ctrl_hdl, nctrls);
>  
> -	for (i = 0; i < ARRAY_SIZE(rkvdec_coded_fmts); i++) {
> -		if (rkvdec_is_capable(ctx, rkvdec_coded_fmts[i].capability)) {
> -			ret = rkvdec_add_ctrls(ctx, rkvdec_coded_fmts[i].ctrls);
> +	for (i = 0; i < variant->num_coded_fmts; i++) {
> +		if (rkvdec_is_capable(ctx, variant->coded_fmts[i].capability)) {
> +			ret = rkvdec_add_ctrls(ctx, variant->coded_fmts[i].ctrls);
>  			if (ret)
>  				goto err_free_handler;
>  		}
> @@ -1242,11 +1245,15 @@ static void rkvdec_watchdog_func(struct work_struct *work)
>  
>  static const struct rkvdec_variant rk3288_rkvdec_variant = {
>  	.num_regs = 68,
> +	.coded_fmts = rkvdec_coded_fmts,
> +	.num_coded_fmts = ARRAY_SIZE(rkvdec_coded_fmts),
>  	.capabilities = RKVDEC_CAPABILITY_HEVC,

Looks like we could drop the capabilities flags handling now that we
use a per variant coded_fmts ?

Maybe a rk3288_coded_fmts should be added and used here, or in a cleanup
patch that drops the capabilities flag handling.

Regards,
Jonas

>  };
>  
>  static const struct rkvdec_variant rk3328_rkvdec_variant = {
>  	.num_regs = 109,
> +	.coded_fmts = rkvdec_coded_fmts,
> +	.num_coded_fmts = ARRAY_SIZE(rkvdec_coded_fmts),
>  	.capabilities = RKVDEC_CAPABILITY_HEVC |
>  			RKVDEC_CAPABILITY_H264 |
>  			RKVDEC_CAPABILITY_VP9,
> @@ -1255,6 +1262,8 @@ static const struct rkvdec_variant rk3328_rkvdec_variant = {
>  
>  static const struct rkvdec_variant rk3399_rkvdec_variant = {
>  	.num_regs = 78,
> +	.coded_fmts = rkvdec_coded_fmts,
> +	.num_coded_fmts = ARRAY_SIZE(rkvdec_coded_fmts),
>  	.capabilities = RKVDEC_CAPABILITY_HEVC |
>  			RKVDEC_CAPABILITY_H264 |
>  			RKVDEC_CAPABILITY_VP9,
> diff --git a/drivers/media/platform/rockchip/rkvdec/rkvdec.h b/drivers/media/platform/rockchip/rkvdec/rkvdec.h
> index f35f6e80ea2e..aac6cba4c623 100644
> --- a/drivers/media/platform/rockchip/rkvdec/rkvdec.h
> +++ b/drivers/media/platform/rockchip/rkvdec/rkvdec.h
> @@ -71,6 +71,8 @@ vb2_to_rkvdec_decoded_buf(struct vb2_buffer *buf)
>  
>  struct rkvdec_variant {
>  	unsigned int num_regs;
> +	const struct rkvdec_coded_fmt_desc *coded_fmts;
> +	size_t num_coded_fmts;
>  	unsigned int capabilities;
>  	unsigned int quirks;
>  };




More information about the Linux-rockchip mailing list