media: qcom: camss: vfe-340: Support for PIX client

Add support for the vfe-340 PIX write engine, enabling frame capture
through the PIX video device (e.g. msm_vfe0_pix). The PIX path requires
a separate configuration flow from RDI, including cropping setup, line-
based write engine configuration, and the correct packer format based
on the input pixel format.

In contrast to RDI, the PIX interface embeds a lightweight processing
engine we can use for cropping, configuring custom stride/alignment,
and, in the future, extracting frame statistics.

The functionality has been validated on Arduino-Uno-Q with:
media-ctl -d /dev/media0 --reset
media-ctl -d /dev/media0 -l '"msm_csiphy0":1->"msm_csid0":0[1],"msm_csid0":4->"msm_vfe0_pix":0[1]'
media-ctl -d /dev/media0 -V '"imx219 1-0010":0[fmt:SRGGB8_1X8/640x480 field:none]'
media-ctl -d /dev/media0 -V '"msm_csiphy0":0[fmt:SRGGB8_1X8/640x480 field:none]'
media-ctl -d /dev/media0 -V '"msm_csid0":0[fmt:SRGGB8_1X8/640x480 field:none]'
media-ctl -d /dev/media0 -V '"msm_vfe0_pix":0[fmt:SRGGB8_1X8/640x480 field:none]'
yavta -B capture-mplane --capture=3 -n 3 -f SRGGB8 -s 640x480 /dev/video3

Signed-off-by: Loic Poulain <loic.poulain@oss.qualcomm.com>
[bod: Squash down fix for bpp unused in vfe_packer_format]
Signed-off-by: Bryan O'Donoghue <bod@kernel.org>
This commit is contained in:
Loic Poulain 2026-04-14 20:52:02 +02:00 committed by Bryan O'Donoghue
parent 880a3e4033
commit 6a75e3d4f6

View File

@ -54,6 +54,7 @@
#define TFE_BUS_CLIENT_CFG(c) BUS_REG(0x200 + (c) * 0x100)
#define TFE_BUS_CLIENT_CFG_EN BIT(0)
#define TFE_BUS_CLIENT_CFG_AUTORECOVER BIT(4)
#define TFE_BUS_CLIENT_CFG_MODE_FRAME BIT(16)
#define TFE_BUS_IMAGE_ADDR(c) BUS_REG(0x204 + (c) * 0x100)
#define TFE_BUS_FRAME_INCR(c) BUS_REG(0x208 + (c) * 0x100)
@ -63,12 +64,23 @@
#define TFE_BUS_IMAGE_CFG_2(c) BUS_REG(0x214 + (c) * 0x100)
#define TFE_BUS_IMAGE_CFG_2_DEFAULT 0xffff
#define TFE_BUS_PACKER_CFG(c) BUS_REG(0x218 + (c) * 0x100)
#define TFE_BUS_PACKER_CFG_FMT_PLAIN8 0x1
#define TFE_BUS_PACKER_CFG_FMT_PLAIN64 0xa
#define TFE_BUS_PACKER_CFG_FMT_MIPI10 0xc
#define TFE_BUS_PACKER_CFG_FMT_MIPI12 0xd
#define TFE_BUS_IRQ_SUBSAMPLE_CFG_0(c) BUS_REG(0x230 + (c) * 0x100)
#define TFE_BUS_IRQ_SUBSAMPLE_CFG_1(c) BUS_REG(0x234 + (c) * 0x100)
#define TFE_BUS_FRAMEDROP_CFG_0(c) BUS_REG(0x238 + (c) * 0x100)
#define TFE_BUS_FRAMEDROP_CFG_1(c) BUS_REG(0x23c + (c) * 0x100)
#define PP_CROP_REG(a) (0x2800 + (a))
#define TFE_PP_CROP_CFG PP_CROP_REG(0x60)
#define TFE_PP_CROP_CFG_EN (BIT(0) | BIT(9))
#define TFE_PP_CROP_LINE_CFG PP_CROP_REG(0x68)
#define TFE_PP_CROP_FIRST GENMASK(29, 16)
#define TFE_PP_CROP_LAST GENMASK(13, 0)
#define TFE_PP_CROP_PIX_CFG PP_CROP_REG(0x6C)
enum tfe_client {
TFE_CLI_BAYER,
TFE_CLI_IDEAL_RAW,
@ -245,18 +257,69 @@ static void vfe_wm_update(struct vfe_device *vfe, u8 wm, u32 addr,
writel_relaxed(addr, vfe->base + TFE_BUS_IMAGE_ADDR(client));
}
static u32 vfe_packer_format(struct vfe_device *vfe, u32 pixelformat)
{
const struct camss_formats *fmt = vfe->res->formats_rdi;
unsigned int bpp = 0;
int i;
for (i = 0; i < fmt->nformats; i++) {
if (fmt->formats[i].pixelformat == pixelformat) {
bpp = fmt->formats[i].mbus_bpp;
break;
}
}
switch (bpp) {
case 10:
return TFE_BUS_PACKER_CFG_FMT_MIPI10;
case 12:
return TFE_BUS_PACKER_CFG_FMT_MIPI12;
default:
return TFE_BUS_PACKER_CFG_FMT_PLAIN8;
}
}
static void vfe_wm_start(struct vfe_device *vfe, u8 wm, struct vfe_line *line)
{
struct v4l2_pix_format_mplane *pix = &line->video_out.active_fmt.fmt.pix_mp;
u32 stride = pix->plane_fmt[0].bytesperline;
u8 client = tfe_wm_client_map[wm];
u32 cfg = TFE_BUS_CLIENT_CFG_EN;
/* Configuration for plain RDI frames */
writel_relaxed(TFE_BUS_IMAGE_CFG_0_DEFAULT, vfe->base + TFE_BUS_IMAGE_CFG_0(client));
writel_relaxed(0u, vfe->base + TFE_BUS_IMAGE_CFG_1(client));
writel_relaxed(TFE_BUS_IMAGE_CFG_2_DEFAULT, vfe->base + TFE_BUS_IMAGE_CFG_2(client));
writel_relaxed(stride * pix->height, vfe->base + TFE_BUS_FRAME_INCR(client));
writel_relaxed(TFE_BUS_PACKER_CFG_FMT_PLAIN64, vfe->base + TFE_BUS_PACKER_CFG(client));
if (client == TFE_CLI_BAYER) { /* PIX - Line based */
struct v4l2_rect *crop = &line->crop;
/* Cropping */
writel_relaxed(TFE_PP_CROP_CFG_EN, vfe->base + TFE_PP_CROP_CFG);
writel_relaxed(FIELD_PREP(TFE_PP_CROP_FIRST, crop->top) |
FIELD_PREP(TFE_PP_CROP_LAST, crop->top + crop->height - 1),
vfe->base + TFE_PP_CROP_LINE_CFG);
writel_relaxed(FIELD_PREP(TFE_PP_CROP_FIRST, crop->left) |
FIELD_PREP(TFE_PP_CROP_LAST, crop->left + crop->width - 1),
vfe->base + TFE_PP_CROP_PIX_CFG);
/* Write Engine */
writel_relaxed(pix->width | (pix->height << 16),
vfe->base + TFE_BUS_IMAGE_CFG_0(client));
writel_relaxed(0u, vfe->base + TFE_BUS_IMAGE_CFG_1(client));
writel_relaxed(stride, vfe->base + TFE_BUS_IMAGE_CFG_2(client));
writel_relaxed(stride * pix->height, vfe->base + TFE_BUS_FRAME_INCR(client));
writel_relaxed(vfe_packer_format(vfe, pix->pixelformat),
vfe->base + TFE_BUS_PACKER_CFG(client));
cfg |= TFE_BUS_CLIENT_CFG_AUTORECOVER;
} else { /* RDI - Frame based */
writel_relaxed(TFE_BUS_IMAGE_CFG_0_DEFAULT,
vfe->base + TFE_BUS_IMAGE_CFG_0(client));
writel_relaxed(0u, vfe->base + TFE_BUS_IMAGE_CFG_1(client));
writel_relaxed(TFE_BUS_IMAGE_CFG_2_DEFAULT,
vfe->base + TFE_BUS_IMAGE_CFG_2(client));
writel_relaxed(stride * pix->height, vfe->base + TFE_BUS_FRAME_INCR(client));
writel_relaxed(TFE_BUS_PACKER_CFG_FMT_PLAIN64,
vfe->base + TFE_BUS_PACKER_CFG(client));
cfg |= TFE_BUS_CLIENT_CFG_MODE_FRAME;
}
/* No dropped frames, one irq per frame */
writel_relaxed(0, vfe->base + TFE_BUS_FRAMEDROP_CFG_0(client));
@ -266,11 +329,10 @@ static void vfe_wm_start(struct vfe_device *vfe, u8 wm, struct vfe_line *line)
vfe_enable_irq(vfe);
writel(TFE_BUS_CLIENT_CFG_EN | TFE_BUS_CLIENT_CFG_MODE_FRAME,
vfe->base + TFE_BUS_CLIENT_CFG(client));
writel(cfg, vfe->base + TFE_BUS_CLIENT_CFG(client));
dev_dbg(vfe->camss->dev, "VFE%u: Started client %u width %u height %u stride %u\n",
vfe->id, client, pix->width, pix->height, client);
vfe->id, client, pix->width, pix->height, stride);
}
static void vfe_wm_stop(struct vfe_device *vfe, u8 wm)