* [PATCH v2 0/3] media: qcom: camss: Fix PIX BPL alignment handling in CAMSS
@ 2026-03-13 19:51 Loic Poulain
2026-03-13 19:51 ` [PATCH v2 1/3] media: qcom: camss: Add per-format BPL alignment helper Loic Poulain
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Loic Poulain @ 2026-03-13 19:51 UTC (permalink / raw)
To: bryan.odonoghue, vladimir.zapolskiy
Cc: linux-media, linux-arm-msm, mchehab, Loic Poulain
Refines the bytes-per-line (BPL) alignment logic across the CAMSS
pipeline. The current implementation relies on ALIGN(), which only
works for power-of-two alignment values. This is fine for RDI
interfaces, which typically use 64-bit or 128-bit alignment, but it
fails for PIX interfaces with Bayer formats such as RAW10 or RAW12
that require non-power-of-two byte alignment, causing hardware config
violations.
The series introduces a per-format alignment helper, updates the VFE
code to use proper rounding for non-power-of-two cases, and makes the
PIX BPL alignment logic format-based on CAMSS_2290.
Changes in V2:
Move from switch-case to an LCM based expression to compute BPL alignment
in a universal way, as suggested by Konrad. That also means we don't need
to handle any error, as we should support any format/bpp.
Loic Poulain (3):
media: qcom: camss: Add per-format BPL alignment helper
media: qcom: camss: Use proper BPL alignment helper and
non-power-of-two rounding
media: qcom: camss: vfe: Make PIX BPL alignment format-based on
CAMSS_2290
.../media/platform/qcom/camss/camss-format.c | 14 ++++++++++
.../media/platform/qcom/camss/camss-format.h | 1 +
drivers/media/platform/qcom/camss/camss-vfe.c | 28 ++++++++++++++++---
.../media/platform/qcom/camss/camss-video.c | 13 +++++++--
4 files changed, 49 insertions(+), 7 deletions(-)
--
2.34.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2 1/3] media: qcom: camss: Add per-format BPL alignment helper
2026-03-13 19:51 [PATCH v2 0/3] media: qcom: camss: Fix PIX BPL alignment handling in CAMSS Loic Poulain
@ 2026-03-13 19:51 ` Loic Poulain
2026-03-13 19:51 ` [PATCH v2 2/3] media: qcom: camss: Use proper BPL alignment helper and non-power-of-two rounding Loic Poulain
2026-03-13 19:51 ` [PATCH v2 3/3] media: qcom: camss: vfe: Make PIX BPL alignment format-based on CAMSS_2290 Loic Poulain
2 siblings, 0 replies; 4+ messages in thread
From: Loic Poulain @ 2026-03-13 19:51 UTC (permalink / raw)
To: bryan.odonoghue, vladimir.zapolskiy
Cc: linux-media, linux-arm-msm, mchehab, Loic Poulain
Add camss_format_get_bpl_alignment(), a helper that returns the
bytes-per-line (BPL) alignment requirement for a given CAMSS format.
Different RAW Bayer packing schemes impose different BPL alignment
constraints (e.g. RAW10 requires multiples of 5 bytes, RAW12 multiples of
3 bytes, RAW14 multiples of 7 bytes, etc.). Centralizing this logic
makes the alignment rules explicit and avoids duplicating them across
the pipeline.
This will allow PIX paths and buffer preparation code to correctly
round up BPL values to hardware-required boundaries.
Signed-off-by: Loic Poulain <loic.poulain@oss.qualcomm.com>
---
drivers/media/platform/qcom/camss/camss-format.c | 14 ++++++++++++++
drivers/media/platform/qcom/camss/camss-format.h | 1 +
2 files changed, 15 insertions(+)
diff --git a/drivers/media/platform/qcom/camss/camss-format.c b/drivers/media/platform/qcom/camss/camss-format.c
index 4a3d5549615c..52cb01306ee0 100644
--- a/drivers/media/platform/qcom/camss/camss-format.c
+++ b/drivers/media/platform/qcom/camss/camss-format.c
@@ -7,8 +7,10 @@
* Copyright (c) 2023, The Linux Foundation. All rights reserved.
* Copyright (c) 2023 Qualcomm Technologies, Inc.
*/
+#include <linux/bits.h>
#include <linux/bug.h>
#include <linux/errno.h>
+#include <linux/lcm.h>
#include "camss-format.h"
@@ -33,6 +35,18 @@ u8 camss_format_get_bpp(const struct camss_format_info *formats, unsigned int nf
return formats[0].mbus_bpp;
}
+/*
+ * camss_format_get_bpl_alignment - Retrieve required BPL alignment for a given format.
+ * @format: a pointer to the format
+ *
+ * Return the required alignment, in bytes.
+ */
+unsigned int camss_format_get_bpl_alignment(const struct camss_format_info *format)
+{
+ /* Minimal number of bytes required to keep the line length an integer number of pixels */
+ return lcm_not_zero(format->mbus_bpp, BITS_PER_BYTE) / BITS_PER_BYTE;
+}
+
/*
* camss_format_find_code - Find a format code in an array
* @code: a pointer to media bus format codes array
diff --git a/drivers/media/platform/qcom/camss/camss-format.h b/drivers/media/platform/qcom/camss/camss-format.h
index 923a48c9c3fb..4f87ac8c4975 100644
--- a/drivers/media/platform/qcom/camss/camss-format.h
+++ b/drivers/media/platform/qcom/camss/camss-format.h
@@ -55,6 +55,7 @@ struct camss_formats {
};
u8 camss_format_get_bpp(const struct camss_format_info *formats, unsigned int nformats, u32 code);
+unsigned int camss_format_get_bpl_alignment(const struct camss_format_info *f);
u32 camss_format_find_code(u32 *code, unsigned int n_code, unsigned int index, u32 req_code);
int camss_format_find_format(u32 code, u32 pixelformat, const struct camss_format_info *formats,
unsigned int nformats);
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v2 2/3] media: qcom: camss: Use proper BPL alignment helper and non-power-of-two rounding
2026-03-13 19:51 [PATCH v2 0/3] media: qcom: camss: Fix PIX BPL alignment handling in CAMSS Loic Poulain
2026-03-13 19:51 ` [PATCH v2 1/3] media: qcom: camss: Add per-format BPL alignment helper Loic Poulain
@ 2026-03-13 19:51 ` Loic Poulain
2026-03-13 19:51 ` [PATCH v2 3/3] media: qcom: camss: vfe: Make PIX BPL alignment format-based on CAMSS_2290 Loic Poulain
2 siblings, 0 replies; 4+ messages in thread
From: Loic Poulain @ 2026-03-13 19:51 UTC (permalink / raw)
To: bryan.odonoghue, vladimir.zapolskiy
Cc: linux-media, linux-arm-msm, mchehab, Loic Poulain
Bytes-per-line (BPL) alignment in CAMSS currently uses ALIGN(), which
only works correctly for power-of-two values. Some RAW Bayer packing
formats (e.g. RAW10/12/14) require non-power-of-two alignment such as
3, 5, or 7-byte multiples, so ALIGN() produces incorrect results.
Introduce the use of roundup() with the per-format alignment returned by
camss_format_get_bpl_alignment() when no hardware alignment is enforced
(video->bpl_alignment).
Signed-off-by: Loic Poulain <loic.poulain@oss.qualcomm.com>
---
drivers/media/platform/qcom/camss/camss-video.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/drivers/media/platform/qcom/camss/camss-video.c b/drivers/media/platform/qcom/camss/camss-video.c
index f52d8e84f970..0852eb6f1315 100644
--- a/drivers/media/platform/qcom/camss/camss-video.c
+++ b/drivers/media/platform/qcom/camss/camss-video.c
@@ -47,6 +47,9 @@ static int video_mbus_to_pix_mp(const struct v4l2_mbus_framefmt *mbus,
unsigned int i;
u32 bytesperline;
+ if (!alignment)
+ alignment = camss_format_get_bpl_alignment(f);
+
memset(pix, 0, sizeof(*pix));
v4l2_fill_pix_format_mplane(pix, mbus);
pix->pixelformat = f->pixelformat;
@@ -54,7 +57,7 @@ static int video_mbus_to_pix_mp(const struct v4l2_mbus_framefmt *mbus,
for (i = 0; i < pix->num_planes; i++) {
bytesperline = pix->width / f->hsub[i].numerator *
f->hsub[i].denominator * f->bpp[i] / 8;
- bytesperline = ALIGN(bytesperline, alignment);
+ bytesperline = roundup(bytesperline, alignment);
pix->plane_fmt[i].bytesperline = bytesperline;
pix->plane_fmt[i].sizeimage = pix->height /
f->vsub[i].numerator * f->vsub[i].denominator *
@@ -459,6 +462,7 @@ static int video_g_fmt(struct file *file, void *fh, struct v4l2_format *f)
static int __video_try_fmt(struct camss_video *video, struct v4l2_format *f)
{
+ unsigned int alignment = video->bpl_alignment;
struct v4l2_pix_format_mplane *pix_mp;
const struct camss_format_info *fi;
struct v4l2_plane_pix_format *p;
@@ -491,6 +495,9 @@ static int __video_try_fmt(struct camss_video *video, struct v4l2_format *f)
width = pix_mp->width;
height = pix_mp->height;
+ if (!alignment)
+ alignment = camss_format_get_bpl_alignment(fi);
+
memset(pix_mp, 0, sizeof(*pix_mp));
pix_mp->pixelformat = fi->pixelformat;
@@ -500,7 +507,7 @@ static int __video_try_fmt(struct camss_video *video, struct v4l2_format *f)
for (i = 0; i < pix_mp->num_planes; i++) {
bpl = pix_mp->width / fi->hsub[i].numerator *
fi->hsub[i].denominator * fi->bpp[i] / 8;
- bpl = ALIGN(bpl, video->bpl_alignment);
+ bpl = roundup(bpl, alignment);
pix_mp->plane_fmt[i].bytesperline = bpl;
pix_mp->plane_fmt[i].sizeimage = pix_mp->height /
fi->vsub[i].numerator * fi->vsub[i].denominator * bpl;
@@ -525,7 +532,7 @@ static int __video_try_fmt(struct camss_video *video, struct v4l2_format *f)
lines = p->sizeimage / p->bytesperline;
if (p->bytesperline < bytesperline[i])
- p->bytesperline = ALIGN(bytesperline[i], 8);
+ p->bytesperline = roundup(bytesperline[i], alignment);
if (p->sizeimage < p->bytesperline * lines)
p->sizeimage = p->bytesperline * lines;
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v2 3/3] media: qcom: camss: vfe: Make PIX BPL alignment format-based on CAMSS_2290
2026-03-13 19:51 [PATCH v2 0/3] media: qcom: camss: Fix PIX BPL alignment handling in CAMSS Loic Poulain
2026-03-13 19:51 ` [PATCH v2 1/3] media: qcom: camss: Add per-format BPL alignment helper Loic Poulain
2026-03-13 19:51 ` [PATCH v2 2/3] media: qcom: camss: Use proper BPL alignment helper and non-power-of-two rounding Loic Poulain
@ 2026-03-13 19:51 ` Loic Poulain
2 siblings, 0 replies; 4+ messages in thread
From: Loic Poulain @ 2026-03-13 19:51 UTC (permalink / raw)
To: bryan.odonoghue, vladimir.zapolskiy
Cc: linux-media, linux-arm-msm, mchehab, Loic Poulain
Split the VFE bytes-per-line (BPL) alignment logic into separate
helpers for RDI and PIX paths. RDI is usually aligned on RDI write
engine bus constraint such as 64-bit or 128-bit. But PIX engine
is usually (at least on platform I looked at) based on pixel format.
On CAMSS_2290, PIX BPL alignment is set to 0 to indicate that the
alignment must be derived from the pixel format. This allows the
pipeline to use camss_format_get_bpl_alignment().
For other platforms, retain the legacy PIX default (16 bytes), until
PIX is properly tested/enabled.
A future improvement would be to remove platform-specific conditionals
from the VFE code and move the alignment requirements into the
per-platform VFE resource data.
Signed-off-by: Loic Poulain <loic.poulain@oss.qualcomm.com>
Reviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
---
drivers/media/platform/qcom/camss/camss-vfe.c | 28 ++++++++++++++++---
1 file changed, 24 insertions(+), 4 deletions(-)
diff --git a/drivers/media/platform/qcom/camss/camss-vfe.c b/drivers/media/platform/qcom/camss/camss-vfe.c
index 9c7ad8aa4058..c174c7d706e2 100644
--- a/drivers/media/platform/qcom/camss/camss-vfe.c
+++ b/drivers/media/platform/qcom/camss/camss-vfe.c
@@ -1996,7 +1996,7 @@ static const struct media_entity_operations vfe_media_ops = {
.link_validate = v4l2_subdev_link_validate,
};
-static int vfe_bpl_align(struct vfe_device *vfe)
+static int vfe_bpl_align_rdi(struct vfe_device *vfe)
{
int ret = 8;
@@ -2019,6 +2019,25 @@ static int vfe_bpl_align(struct vfe_device *vfe)
return ret;
}
+static int vfe_bpl_align_pix(struct vfe_device *vfe)
+{
+ int ret = 16;
+
+ switch (vfe->camss->res->version) {
+ case CAMSS_2290:
+ /* The alignment/bpl depends solely on the pixel format and is
+ * computed dynamically in camss_format_get_bpl_alignment().
+ */
+ ret = 0;
+ break;
+ default:
+ break;
+ }
+
+ return ret;
+}
+
+
/*
* msm_vfe_register_entities - Register subdev node for VFE module
* @vfe: VFE device
@@ -2085,11 +2104,12 @@ int msm_vfe_register_entities(struct vfe_device *vfe,
}
video_out->ops = &vfe->video_ops;
- video_out->bpl_alignment = vfe_bpl_align(vfe);
- video_out->line_based = 0;
if (i == VFE_LINE_PIX) {
- video_out->bpl_alignment = 16;
+ video_out->bpl_alignment = vfe_bpl_align_pix(vfe);
video_out->line_based = 1;
+ } else {
+ video_out->bpl_alignment = vfe_bpl_align_rdi(vfe);
+ video_out->line_based = 0;
}
video_out->nformats = vfe->line[i].nformats;
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-03-13 19:52 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-13 19:51 [PATCH v2 0/3] media: qcom: camss: Fix PIX BPL alignment handling in CAMSS Loic Poulain
2026-03-13 19:51 ` [PATCH v2 1/3] media: qcom: camss: Add per-format BPL alignment helper Loic Poulain
2026-03-13 19:51 ` [PATCH v2 2/3] media: qcom: camss: Use proper BPL alignment helper and non-power-of-two rounding Loic Poulain
2026-03-13 19:51 ` [PATCH v2 3/3] media: qcom: camss: vfe: Make PIX BPL alignment format-based on CAMSS_2290 Loic Poulain
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox