From: "Sascha Hauer" <s.hauer@pengutronix.de>
To: "Philipp Zabel" <p.zabel@pengutronix.de>
Cc: "Sascha Hauer" <s.hauer@pengutronix.de>,
"Lucas Sinn" <lucas.sinn@wolfvision.net>,
"Mauro Carvalho Chehab" <mchehab@kernel.org>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"Heiko Stuebner" <heiko@sntech.de>,
linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org,
devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v7 2/4] media: rockchip: Add JPEG decoder driver
Date: Mon, 23 Nov 2026 14:37:17 +0000 [thread overview]
Message-ID: <20c75d45-0b9b-4465-83aa-3ef24b90309b@pengutronix.de> (raw)
In-Reply-To: <266c9fe4a9aca943c2c2be39a7dc0f3bea2df362.camel@pengutronix.de>
On 2026-11-20 15:58, Philipp Zabel wrote:
> > +
> > +/* Error status bits used to decide whether a hardware reset is needed */
> > +#define VDPU720_ERR_MASK (VDPU720_BUS_ERR | VDPU720_DEC_ERR | \
> > + VDPU720_TIMEOUT | VDPU720_BUF_EMPTY)
> > +
> > +/*
> > + * VPU720 IRQ clear mask.
> > + *
> > + * Some revisions require a two-step IRQ acknowledgment before checking
> > + * VDPU720_IRQ_RAW: write the status back with only the enable and control
> > + * bits kept, then write 0 to fully clear. The downstream BSP computes the
> > + * first value as
> > + *
> > + * clr = (~(0x00fe7f40 & status)) & (0xff0180bf & status)
> > + *
> > + * The two masks are complements, so that is status & 0xff0180bf: bits 0-5,
> > + * 7, 15, 16 and 24-31 are kept, IRQ_RAW and the status bits 8-14 dropped.
> > + *
> > + * It is applied unconditionally here. The BSP gates it on the revision in
> > + * VDPU720_REG_VERSION matching 0xdb1f0006 exactly, and the RK3588 reports
> > + * 0xdb1f0005, so it is not needed on that part. The extra write is
> > + * harmless there and saves a revision check that would need silicon we do
> > + * not have to validate.
> > + */
> > +#define VDPU720_IRQ_CLR_KEEP 0xff0180bf
> > +
> > +#define VDPU720_REG_SYS 0x008
> > +#define VDPU720_FORCE_SOFTRST BIT(17) /* set when dec_e=0 before soft-reset */
> > +#define VDPU720_FILL_DOWN_E BIT(24) /* fill bottom padding rows */
> > +#define VDPU720_FILL_RIGHT_E BIT(25)
> > +#define VDPU720_OUT_SEQ BIT(26) /* 0=raster, 1=tile */
> > +#define VDPU720_YUV_OUT_FMT GENMASK(29, 27)
> > +#define VDPU720_YUV_OUT_FMT_NATIVE 0 /* no format conversion */
>
> This is never used.
It will be in v8 due to adding NV16 support ;)
>
> > +#define VDPU720_YUV_OUT_FMT_NV12 3 /* output as NV12 */
> > +
> > +#define VDPU720_REG_PIC_SIZE 0x00c
> > +#define VDPU720_PIC_W_M1 GENMASK(15, 0)
> > +#define VDPU720_PIC_H_M1 GENMASK(31, 16)
> > +
> > +#define VDPU720_REG_PIC_FMT 0x010
> > +#define VDPU720_JPEG_MODE GENMASK(2, 0)
> > +#define VDPU720_JPEG_MODE_YUV400 0
> > +#define VDPU720_JPEG_MODE_YUV411 1
> > +#define VDPU720_JPEG_MODE_YUV420 2
> > +#define VDPU720_JPEG_MODE_YUV422 3
> > +#define VDPU720_JPEG_MODE_YUV440 4
> > +#define VDPU720_JPEG_MODE_YUV444 5
>
> So the driver can decode 4:4:4 JPEGs but always subsamples and outputs
> them as 4:2:0 (NV12)?
For simplicity, yes. I added NV16 support for 4:2:2 sampling for the
next round, as that's a common format for webcams. I'll leave 4:4:4
to NV24 for a later exercise.
> > +#include <media/v4l2-jpeg.h>
> > +#include <media/v4l2-mem2mem.h>
> > +#include <media/videobuf2-core.h>
> > +#include <media/videobuf2-dma-contig.h>
> > +
> > +#include "rkjpegd-vdpu720-regs.h"
> > +
> > +#define RKJPEGD_NAME "rockchip-jpegd"
> > +
> > +/*
> > + * The reference manual gives 48x48 to 65536x65536, and a frame header cannot
> > + * describe more than 65535. The coded format steps in RKJPEGD_CODED_STEP.
> > + * Beyond that only the decoded frame has to fit a 32 bit sizeimage, see
> > + * rkjpegd_raw_fits().
> > + */
> > +#define RKJPEGD_MIN_WIDTH 48
> > +#define RKJPEGD_MIN_HEIGHT 48
> > +#define RKJPEGD_MAX_SIZE 65528
>
> This seems inconsistent. Why not MIN_SIZE or MAX_WIDTH/HEIGHT?
Ok, will change to RKJPEGD_MIN_SIZE
>
>
> [...]
> > +/* The capture format and crop a frame decodes to. */
> > +static void rkjpegd_fill_hdr_fmt(struct v4l2_pix_format_mplane *pix_mp,
> > + struct v4l2_rect *crop,
> > + const struct v4l2_jpeg_header *hdr)
> > +{
> > + rkjpegd_fill_raw_fmt(pix_mp, rkjpegd_raw_pixelformat(hdr),
> > + ALIGN(hdr->frame.width, RKJPEGD_RAW_STEP),
> > + ALIGN(hdr->frame.height, RKJPEGD_RAW_STEP));
>
> Aligning to 16 is safe, but for e.g. grayscale (or YUV 4:4:4) I'd
> expect aligning to 8 to be enough (see vdpu720_mcu_width/height()).
The width has to stay at 16 pixel alignment, as the hardware takes its
stride in units of 16 pixels.
For the height I'd say we have to play around with the FILL_DOWN_E bit.
When set, the reference manual says: "Fill picture height to multiple of
16 pixels". Right now we always have this bit set, same as the Rockchip
driver does. I'd rather leave this up for a later exercise to dig deeper
into that.
>
> > + crop->left = 0;
> > + crop->top = 0;
> > + crop->width = hdr->frame.width;
> > + crop->height = hdr->frame.height;
> > +}
> > +
> [...]
> > +/*
> > + * The capture format as userspace sees it. Once the decoder stopped at a
> > + * format change, that is the one of the frame it stopped in front of.
> > + */
> > +static void rkjpegd_get_cap_fmt(struct rkjpegd_ctx *ctx,
> > + struct v4l2_pix_format_mplane *pix_mp,
> > + struct v4l2_rect *crop)
> > +{
> > + struct vb2_v4l2_buffer *src;
> > +
> > + if (READ_ONCE(ctx->stopped_at_change)) {
>
> Why does TRY_FMT depend on decoder state?
The format is dictated by the JPEG stream. It depends on the decoder
state to support a midstream format change. When stopped at a format
change we have to report the new format, otherwise the current format.
>
> > + src = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx);
> > + rkjpegd_fill_hdr_fmt(pix_mp, crop,
> > + &vb2_to_rkjpegd_src_buf(&src->vb2_buf)->header);
> > + return;
> > + }
> > +
> > + *pix_mp = ctx->dst_fmt;
> > + *crop = ctx->crop;
> > +}
> [...]
> > +static int rkjpegd_enum_framesizes(struct file *file, void *priv,
> > + struct v4l2_frmsizeenum *fsize)
> > +{
> > + /* The decoded format follows the bitstream, nothing to enumerate. */
> > + if (fsize->pixel_format == V4L2_PIX_FMT_NV12 ||
> > + fsize->pixel_format == V4L2_PIX_FMT_GREY)
> > + return -ENOTTY;
> > +
> > + if (fsize->pixel_format != V4L2_PIX_FMT_JPEG)
> > + return -EINVAL;
> > +
> > + if (fsize->index)
> > + return -EINVAL;
> > +
> > + fsize->type = V4L2_FRMSIZE_TYPE_STEPWISE;
> > + fsize->stepwise.min_width = RKJPEGD_MIN_WIDTH;
> > + fsize->stepwise.max_width = RKJPEGD_MAX_SIZE;
> > + fsize->stepwise.step_width = RKJPEGD_CODED_STEP;
> > + fsize->stepwise.min_height = RKJPEGD_MIN_HEIGHT;
> > + fsize->stepwise.max_height = RKJPEGD_MAX_SIZE;
> > + fsize->stepwise.step_height = RKJPEGD_CODED_STEP;
>
> This is the coded size. I'd expect this to be continuous. You just have
> to make sure that the decoded buffer is properly aligned and set the
> PADDED selection rectangle accordingly.
Oh, yes. That can indeed be continuous. Will change.
> > +
> [...]
> > +
> > + rkjpegd_irq_done(jpegd, state);
>
> Why is this hidden in a separate function call?
Likely historic reasons. I'll inline the code here.
>
> > + return IRQ_HANDLED;
> > +}
> > +
> > +static void rkjpegd_watchdog(struct work_struct *work)
> > +{
> > + struct rkjpegd_dev *jpegd = container_of(to_delayed_work(work),
> > + struct rkjpegd_dev,
> > + watchdog_work);
> > + /* Only armed while a job runs, so there is always a context. */
> > + struct rkjpegd_ctx *ctx = v4l2_m2m_get_curr_priv(jpegd->m2m_dev);
> > +
> > + dev_err(jpegd->dev, "frame processing timed out\n");
> > +
> > + rkjpegd_vdpu720_reset(ctx);
> > + rkjpegd_job_finish(ctx, VB2_BUF_STATE_ERROR);
> > +}
> [...]
> > +static int rkjpegd_buf_out_validate(struct vb2_buffer *vb)
> > +{
> > + struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
> > +
> > + vbuf->field = V4L2_FIELD_NONE;
>
> Hmm, "drivers can use this to validate userspace-provided information".
> Is this really validation?
>
> It seems a lot of drivers have exactly the same function:
>
> vpu_vb2_buf_out_validate()
> cedrus_buf_out_validate()
> mdp_m2m_buf_out_validate()
> vb2ops_venc_buf_out_validate()
> tegra_buf_out_validate()
> dw100_buf_out_validate()
> mxc_jpeg_buf_out_validate()
> rkvdec_buf_out_validate()
> hantro_buf_out_validate()
> vicodec_buf_out_validate()
> visl_buf_out_validate()
>
> At least e5010_buf_out_validate() and
> dma2d_buf_out_validate() warn or fail, respectively, if the field value
> is invalid.
>
> Is overwriting field to NONE what this callback was designed for, and
> if so, does this warrant a common helper?
1f2f510753be ("media: vivid: add buf_out_validate callback") which Hans
upstreamed along with the patch adding the buf_out_validate hook
suggests it's really for validation rather than normalisation.
However, buf_out contains the coded stream. The field order has no
meaning in a coded stream, which is why I think that most decoder
drivers just normalize to a sane value.
Yes, this sounds an opportunity to add a generic helper function. If
that's desired I would add one as a separate series though.
>
> > +
> > + return 0;
> > +}
> >
> [...]
> > +
> > +static int rkjpegd_resume(struct device *dev)
> > +{
> > + struct rkjpegd_dev *jpegd = dev_get_drvdata(dev);
> > + int ret;
> > +
> > + ret = pm_runtime_force_resume(dev);
>
> I'd expect this to not call v4l2_m2m_resume() if runtime PM resume
> failed.
Yes. Will change to return early when it fails.
Regards,
Sascha
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
next prev parent reply other threads:[~2026-11-23 14:37 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-22 11:06 [PATCH v7 0/4] " Sascha Hauer
2026-10-22 11:06 ` [PATCH v7 1/4] media: dt-bindings: Add Rockchip JPEG decoder Sascha Hauer
2026-10-22 11:06 ` [PATCH v7 2/4] media: rockchip: Add JPEG decoder driver Sascha Hauer
2026-10-22 17:00 ` Torsten Duwe
2026-10-23 6:59 ` Sascha Hauer
2026-10-28 19:53 ` Nicolas Dufresne
2026-11-07 13:38 ` Sergei Khomenkov
2026-11-18 14:27 ` Sascha Hauer
2026-11-19 16:00 ` Nicolas Dufresne
2026-11-20 13:49 ` Sascha Hauer
2026-11-19 20:19 ` Sergei Khomenkov
2026-11-20 13:54 ` Sascha Hauer
2026-11-20 14:58 ` Philipp Zabel
2026-11-23 14:37 ` Sascha Hauer [this message]
2026-10-22 11:06 ` [PATCH v7 3/4] arm64: dts: rockchip: rk3588: Add JPEG decoder node Sascha Hauer
2026-10-22 11:06 ` [PATCH v7 4/4] arm64: dts: rockchip: rk356x: " Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20c75d45-0b9b-4465-83aa-3ef24b90309b@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=heiko@sntech.de \
--cc=krzk+dt@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-rockchip@lists.infradead.org \
--cc=lucas.sinn@wolfvision.net \
--cc=mchehab@kernel.org \
--cc=p.zabel@pengutronix.de \
--cc=robh@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®