media: ipu3-imgu: Refactor bytesperpixel calculation
authorRicardo Ribalda <ribalda@chromium.org>
Wed, 6 Oct 2021 22:26:19 +0000 (00:26 +0200)
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Fri, 8 Oct 2021 11:30:09 +0000 (13:30 +0200)
Move the calculation to an inline function, to it can be used by other
parts of the driver.

Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
drivers/staging/media/ipu3/ipu3-css.c
drivers/staging/media/ipu3/ipu3-css.h
drivers/staging/media/ipu3/ipu3.h

index 608dcacf12b2c5154ded0e548291a61deec50da3..8c70497d744c9f64f3188f29e157d894d0c024cc 100644 (file)
@@ -5,6 +5,7 @@
 #include <linux/iopoll.h>
 #include <linux/slab.h>
 
+#include "ipu3.h"
 #include "ipu3-css.h"
 #include "ipu3-css-fw.h"
 #include "ipu3-css-params.h"
@@ -53,7 +54,6 @@ static const struct imgu_css_format imgu_css_formats[] = {
                .frame_format = IMGU_ABI_FRAME_FORMAT_NV12,
                .osys_format = IMGU_ABI_OSYS_FORMAT_NV12,
                .osys_tiling = IMGU_ABI_OSYS_TILING_NONE,
-               .bytesperpixel_num = 1 * IPU3_CSS_FORMAT_BPP_DEN,
                .chroma_decim = 4,
                .width_align = IPU3_UAPI_ISP_VEC_ELEMS,
                .flags = IPU3_CSS_FORMAT_FL_OUT | IPU3_CSS_FORMAT_FL_VF,
@@ -64,7 +64,6 @@ static const struct imgu_css_format imgu_css_formats[] = {
                .frame_format = IMGU_ABI_FRAME_FORMAT_RAW_PACKED,
                .bayer_order = IMGU_ABI_BAYER_ORDER_BGGR,
                .bit_depth = 10,
-               .bytesperpixel_num = 64,
                .width_align = 2 * IPU3_UAPI_ISP_VEC_ELEMS,
                .flags = IPU3_CSS_FORMAT_FL_IN,
        }, {
@@ -73,7 +72,6 @@ static const struct imgu_css_format imgu_css_formats[] = {
                .frame_format = IMGU_ABI_FRAME_FORMAT_RAW_PACKED,
                .bayer_order = IMGU_ABI_BAYER_ORDER_GBRG,
                .bit_depth = 10,
-               .bytesperpixel_num = 64,
                .width_align = 2 * IPU3_UAPI_ISP_VEC_ELEMS,
                .flags = IPU3_CSS_FORMAT_FL_IN,
        }, {
@@ -82,7 +80,6 @@ static const struct imgu_css_format imgu_css_formats[] = {
                .frame_format = IMGU_ABI_FRAME_FORMAT_RAW_PACKED,
                .bayer_order = IMGU_ABI_BAYER_ORDER_GRBG,
                .bit_depth = 10,
-               .bytesperpixel_num = 64,
                .width_align = 2 * IPU3_UAPI_ISP_VEC_ELEMS,
                .flags = IPU3_CSS_FORMAT_FL_IN,
        }, {
@@ -91,7 +88,6 @@ static const struct imgu_css_format imgu_css_formats[] = {
                .frame_format = IMGU_ABI_FRAME_FORMAT_RAW_PACKED,
                .bayer_order = IMGU_ABI_BAYER_ORDER_RGGB,
                .bit_depth = 10,
-               .bytesperpixel_num = 64,
                .width_align = 2 * IPU3_UAPI_ISP_VEC_ELEMS,
                .flags = IPU3_CSS_FORMAT_FL_IN,
        },
@@ -150,17 +146,8 @@ static int imgu_css_queue_init(struct imgu_css_queue *queue,
        f->height = ALIGN(clamp_t(u32, f->height,
                                  IPU3_CSS_MIN_RES, IPU3_CSS_MAX_H), 2);
        queue->width_pad = ALIGN(f->width, queue->css_fmt->width_align);
-       if (queue->css_fmt->frame_format != IMGU_ABI_FRAME_FORMAT_RAW_PACKED)
-               f->plane_fmt[0].bytesperline = DIV_ROUND_UP(queue->width_pad *
-                                       queue->css_fmt->bytesperpixel_num,
-                                       IPU3_CSS_FORMAT_BPP_DEN);
-       else
-               /* For packed raw, alignment for bpl is by 50 to the width */
-               f->plane_fmt[0].bytesperline =
-                               DIV_ROUND_UP(f->width,
-                                            IPU3_CSS_FORMAT_BPP_DEN) *
-                                            queue->css_fmt->bytesperpixel_num;
-
+       f->plane_fmt[0].bytesperline =
+               imgu_bytesperline(f->width, queue->css_fmt->frame_format);
        sizeimage = f->height * f->plane_fmt[0].bytesperline;
        if (queue->css_fmt->chroma_decim)
                sizeimage += 2 * sizeimage / queue->css_fmt->chroma_decim;
index 6108a068b228fc709c270436695f6ee1a32d3ec4..ab64e9521203274afba15d31b69fb3c8566dcc3c 100644 (file)
@@ -82,7 +82,6 @@ struct imgu_css_format {
        enum imgu_abi_bayer_order bayer_order;
        enum imgu_abi_osys_format osys_format;
        enum imgu_abi_osys_tiling osys_tiling;
-       u32 bytesperpixel_num;  /* Bytes per pixel in first plane * 50 */
        u8 bit_depth;           /* Effective bits per pixel */
        u8 chroma_decim;        /* Chroma plane decimation, 0=no chroma plane */
        u8 width_align;         /* Alignment requirement for width_pad */
index eb46b527dd2336391dd9526e04dae1ac07a9a52e..d2ad0a95c5aabc1832728d56e9665fa36c9f753f 100644 (file)
@@ -164,4 +164,16 @@ void imgu_v4l2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state);
 
 int imgu_s_stream(struct imgu_device *imgu, int enable);
 
+static inline u32 imgu_bytesperline(const unsigned int width,
+                                   enum imgu_abi_frame_format frame_format)
+{
+       if (frame_format == IMGU_ABI_FRAME_FORMAT_NV12)
+               return ALIGN(width, IPU3_UAPI_ISP_VEC_ELEMS);
+       /*
+        * 64 bytes for every 50 pixels, the line length
+        * in bytes is multiple of 64 (line end alignment).
+        */
+       return DIV_ROUND_UP(width, 50) * 64;
+}
+
 #endif