media: atomisp: Add ia_css_frame_pad_width() helper function
authorHans de Goede <hdegoede@redhat.com>
Mon, 29 May 2023 10:37:33 +0000 (11:37 +0100)
committerMauro Carvalho Chehab <mchehab@kernel.org>
Fri, 9 Jun 2023 14:29:30 +0000 (15:29 +0100)
Factor the code to go from width to a properly aligned pitch out of
ia_css_frame_info_set_width().

This is a preparation patch to fix try_fmt() calls returning a bogus
bytesperline value.

Link: https://lore.kernel.org/r/20230529103741.11904-14-hdegoede@redhat.com
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
drivers/staging/media/atomisp/pci/runtime/frame/interface/ia_css_frame.h
drivers/staging/media/atomisp/pci/runtime/frame/src/frame.c

index 700070c58eda04c5ef5b20ed86cf688048ab143a..90c17884968b06e6b7c16eeb8ff478161413464c 100644 (file)
@@ -138,4 +138,6 @@ bool ia_css_frame_is_same_type(
 int ia_css_dma_configure_from_info(struct dma_port_config *config,
                                   const struct ia_css_frame_info *info);
 
+unsigned int ia_css_frame_pad_width(unsigned int width, enum ia_css_frame_format format);
+
 #endif /* __IA_CSS_FRAME_H__ */
index 1e374ae848e37609c5a94bfbc32ca8cce334246b..2d7fddb114f655b42f592b57e04b06fdbb9e0d77 100644 (file)
@@ -269,6 +269,34 @@ int ia_css_frame_init_planes(struct ia_css_frame *frame)
        return 0;
 }
 
+unsigned int ia_css_frame_pad_width(unsigned int width, enum ia_css_frame_format format)
+{
+       switch (format) {
+       /*
+        * Frames with a U and V plane of 8 bits per pixel need to have
+        * all planes aligned, this means double the alignment for the
+        * Y plane if the horizontal decimation is 2.
+        */
+       case IA_CSS_FRAME_FORMAT_YUV420:
+       case IA_CSS_FRAME_FORMAT_YV12:
+       case IA_CSS_FRAME_FORMAT_NV12:
+       case IA_CSS_FRAME_FORMAT_NV21:
+       case IA_CSS_FRAME_FORMAT_BINARY_8:
+       case IA_CSS_FRAME_FORMAT_YUV_LINE:
+               return CEIL_MUL(width, 2 * HIVE_ISP_DDR_WORD_BYTES);
+
+       case IA_CSS_FRAME_FORMAT_NV12_TILEY:
+               return CEIL_MUL(width, NV12_TILEY_TILE_WIDTH);
+
+       case IA_CSS_FRAME_FORMAT_RAW:
+       case IA_CSS_FRAME_FORMAT_RAW_PACKED:
+               return CEIL_MUL(width, 2 * ISP_VEC_NELEMS);
+
+       default:
+               return CEIL_MUL(width, HIVE_ISP_DDR_WORD_BYTES);
+       }
+}
+
 void ia_css_frame_info_set_width(struct ia_css_frame_info *info,
                                 unsigned int width,
                                 unsigned int min_padded_width)
@@ -285,25 +313,8 @@ void ia_css_frame_info_set_width(struct ia_css_frame_info *info,
        align = max(min_padded_width, width);
 
        info->res.width = width;
-       /* frames with a U and V plane of 8 bits per pixel need to have
-          all planes aligned, this means double the alignment for the
-          Y plane if the horizontal decimation is 2. */
-       if (info->format == IA_CSS_FRAME_FORMAT_YUV420 ||
-           info->format == IA_CSS_FRAME_FORMAT_YV12 ||
-           info->format == IA_CSS_FRAME_FORMAT_NV12 ||
-           info->format == IA_CSS_FRAME_FORMAT_NV21 ||
-           info->format == IA_CSS_FRAME_FORMAT_BINARY_8 ||
-           info->format == IA_CSS_FRAME_FORMAT_YUV_LINE)
-               info->padded_width =
-                   CEIL_MUL(align, 2 * HIVE_ISP_DDR_WORD_BYTES);
-       else if (info->format == IA_CSS_FRAME_FORMAT_NV12_TILEY)
-               info->padded_width = CEIL_MUL(align, NV12_TILEY_TILE_WIDTH);
-       else if (info->format == IA_CSS_FRAME_FORMAT_RAW ||
-                info->format == IA_CSS_FRAME_FORMAT_RAW_PACKED)
-               info->padded_width = CEIL_MUL(align, 2 * ISP_VEC_NELEMS);
-       else {
-               info->padded_width = CEIL_MUL(align, HIVE_ISP_DDR_WORD_BYTES);
-       }
+       info->padded_width = ia_css_frame_pad_width(align, info->format);
+
        IA_CSS_LEAVE_PRIVATE("");
 }