]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
media: qcom: camss: Add per-format BPL alignment helper
authorLoic Poulain <loic.poulain@oss.qualcomm.com>
Fri, 13 Mar 2026 19:51:50 +0000 (20:51 +0100)
committerBryan O'Donoghue <bod@kernel.org>
Fri, 8 May 2026 23:22:59 +0000 (00:22 +0100)
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>
Reviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Bryan O'Donoghue <bod@kernel.org>
drivers/media/platform/qcom/camss/camss-format.c
drivers/media/platform/qcom/camss/camss-format.h

index 4a3d5549615cf84f6f2b7265a32f8c96f910d20a..52cb01306ee0b2109e4dc8ce9e4123e43211c5c9 100644 (file)
@@ -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
index 923a48c9c3fb6d0e9c0c1f087509f70f68049e4b..4f87ac8c497511b951ff8ca6769bb6da6a7031f8 100644 (file)
@@ -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);