diff --git a/drivers/media/platform/raspberrypi/pisp_be/pisp_be.c b/drivers/media/platform/raspberrypi/pisp_be/pisp_be.c index 2df41fa97084ed..7dce1f83de4b18 100644 --- a/drivers/media/platform/raspberrypi/pisp_be/pisp_be.c +++ b/drivers/media/platform/raspberrypi/pisp_be/pisp_be.c @@ -1104,9 +1104,16 @@ static void pispbe_set_plane_params(struct v4l2_format *f, for (unsigned int i = 0; i < nplanes; i++) { struct v4l2_plane_pix_format *p = &f->fmt.pix_mp.plane_fmt[i]; unsigned int bpl, plane_size; + /* + * If a stride has been provided, ensure it meets the minimal + * alignment constraints. If not provided, use an optimal stride + * alignment for efficiency. + */ + const unsigned int align = + p->bytesperline ? fmt->min_align : fmt->opt_align; bpl = (f->fmt.pix_mp.width * fmt->bit_depth) >> 3; - bpl = ALIGN(max(p->bytesperline, bpl), fmt->align); + bpl = ALIGN(max(p->bytesperline, bpl), align); plane_size = bpl * f->fmt.pix_mp.height * (nplanes > 1 ? fmt->plane_factor[i] : total_plane_factor); diff --git a/drivers/media/platform/raspberrypi/pisp_be/pisp_be_formats.h b/drivers/media/platform/raspberrypi/pisp_be/pisp_be_formats.h index 09edc2774668b5..b8a9e21eedbb3a 100644 --- a/drivers/media/platform/raspberrypi/pisp_be/pisp_be_formats.h +++ b/drivers/media/platform/raspberrypi/pisp_be/pisp_be_formats.h @@ -16,7 +16,8 @@ struct pisp_be_format { unsigned int fourcc; - unsigned int align; + unsigned int opt_align; + unsigned int min_align; unsigned int bit_depth; /* 0P3 factor for plane sizing */ unsigned int plane_factor[PISPBE_MAX_PLANES]; @@ -58,7 +59,8 @@ static const struct pisp_be_format supported_formats[] = { { .fourcc = V4L2_PIX_FMT_YUV420, /* 128 alignment to ensure U/V planes are 64 byte aligned. */ - .align = 128, + .opt_align = 128, + .min_align = 32, .bit_depth = 8, .plane_factor = { P3(1), P3(0.25), P3(0.25) }, .num_planes = 1, @@ -68,7 +70,8 @@ static const struct pisp_be_format supported_formats[] = { { .fourcc = V4L2_PIX_FMT_YVU420, /* 128 alignment to ensure U/V planes are 64 byte aligned. */ - .align = 128, + .opt_align = 128, + .min_align = 32, .bit_depth = 8, .plane_factor = { P3(1), P3(0.25), P3(0.25) }, .num_planes = 1, @@ -77,7 +80,8 @@ static const struct pisp_be_format supported_formats[] = { }, { .fourcc = V4L2_PIX_FMT_NV12, - .align = 32, + .opt_align = 32, + .min_align = 16, .bit_depth = 8, .plane_factor = { P3(1), P3(0.5) }, .num_planes = 1, @@ -86,7 +90,8 @@ static const struct pisp_be_format supported_formats[] = { }, { .fourcc = V4L2_PIX_FMT_NV21, - .align = 32, + .opt_align = 32, + .min_align = 16, .bit_depth = 8, .plane_factor = { P3(1), P3(0.5) }, .num_planes = 1, @@ -95,7 +100,8 @@ static const struct pisp_be_format supported_formats[] = { }, { .fourcc = V4L2_PIX_FMT_YUYV, - .align = 64, + .opt_align = 64, + .min_align = 16, .bit_depth = 16, .plane_factor = { P3(1) }, .num_planes = 1, @@ -104,7 +110,8 @@ static const struct pisp_be_format supported_formats[] = { }, { .fourcc = V4L2_PIX_FMT_UYVY, - .align = 64, + .opt_align = 64, + .min_align = 16, .bit_depth = 16, .plane_factor = { P3(1) }, .num_planes = 1, @@ -113,7 +120,8 @@ static const struct pisp_be_format supported_formats[] = { }, { .fourcc = V4L2_PIX_FMT_YVYU, - .align = 64, + .opt_align = 64, + .min_align = 16, .bit_depth = 16, .plane_factor = { P3(1) }, .num_planes = 1, @@ -122,7 +130,8 @@ static const struct pisp_be_format supported_formats[] = { }, { .fourcc = V4L2_PIX_FMT_VYUY, - .align = 64, + .opt_align = 64, + .min_align = 16, .bit_depth = 16, .plane_factor = { P3(1) }, .num_planes = 1, @@ -132,7 +141,8 @@ static const struct pisp_be_format supported_formats[] = { { .fourcc = V4L2_PIX_FMT_YUV422P, /* 128 alignment to ensure U/V planes are 64 byte aligned. */ - .align = 128, + .opt_align = 128, + .min_align = 32, .bit_depth = 8, .plane_factor = { P3(1), P3(0.5), P3(0.5) }, .num_planes = 1, @@ -142,7 +152,8 @@ static const struct pisp_be_format supported_formats[] = { /* Multiplane YUV formats */ { .fourcc = V4L2_PIX_FMT_YUV420M, - .align = 64, + .opt_align = 64, + .min_align = 16, .bit_depth = 8, .plane_factor = { P3(1), P3(0.25), P3(0.25) }, .num_planes = 3, @@ -151,7 +162,8 @@ static const struct pisp_be_format supported_formats[] = { }, { .fourcc = V4L2_PIX_FMT_NV12M, - .align = 32, + .opt_align = 32, + .min_align = 16, .bit_depth = 8, .plane_factor = { P3(1), P3(0.5) }, .num_planes = 2, @@ -160,7 +172,8 @@ static const struct pisp_be_format supported_formats[] = { }, { .fourcc = V4L2_PIX_FMT_NV21M, - .align = 32, + .opt_align = 32, + .min_align = 16, .bit_depth = 8, .plane_factor = { P3(1), P3(0.5) }, .num_planes = 2, @@ -169,7 +182,8 @@ static const struct pisp_be_format supported_formats[] = { }, { .fourcc = V4L2_PIX_FMT_YVU420M, - .align = 64, + .opt_align = 64, + .min_align = 16, .bit_depth = 8, .plane_factor = { P3(1), P3(0.25), P3(0.25) }, .num_planes = 3, @@ -178,7 +192,8 @@ static const struct pisp_be_format supported_formats[] = { }, { .fourcc = V4L2_PIX_FMT_YUV422M, - .align = 64, + .opt_align = 64, + .min_align = 16, .bit_depth = 8, .plane_factor = { P3(1), P3(0.5), P3(0.5) }, .num_planes = 3, @@ -187,7 +202,8 @@ static const struct pisp_be_format supported_formats[] = { }, { .fourcc = V4L2_PIX_FMT_YVU422M, - .align = 64, + .opt_align = 64, + .min_align = 16, .bit_depth = 8, .plane_factor = { P3(1), P3(0.5), P3(0.5) }, .num_planes = 3, @@ -196,7 +212,8 @@ static const struct pisp_be_format supported_formats[] = { }, { .fourcc = V4L2_PIX_FMT_YUV444M, - .align = 64, + .opt_align = 64, + .min_align = 16, .bit_depth = 8, .plane_factor = { P3(1), P3(1), P3(1) }, .num_planes = 3, @@ -205,7 +222,8 @@ static const struct pisp_be_format supported_formats[] = { }, { .fourcc = V4L2_PIX_FMT_YVU444M, - .align = 64, + .opt_align = 64, + .min_align = 16, .bit_depth = 8, .plane_factor = { P3(1), P3(1), P3(1) }, .num_planes = 3, @@ -215,7 +233,8 @@ static const struct pisp_be_format supported_formats[] = { /* RGB formats */ { .fourcc = V4L2_PIX_FMT_RGB24, - .align = 32, + .opt_align = 32, + .min_align = 16, .bit_depth = 24, .plane_factor = { P3(1.0) }, .num_planes = 1, @@ -224,7 +243,8 @@ static const struct pisp_be_format supported_formats[] = { }, { .fourcc = V4L2_PIX_FMT_BGR24, - .align = 32, + .opt_align = 32, + .min_align = 16, .bit_depth = 24, .plane_factor = { P3(1.0) }, .num_planes = 1, @@ -233,7 +253,8 @@ static const struct pisp_be_format supported_formats[] = { }, { .fourcc = V4L2_PIX_FMT_XBGR32, - .align = 64, + .opt_align = 64, + .min_align = 16, .bit_depth = 32, .plane_factor = { P3(1.0) }, .num_planes = 1, @@ -242,7 +263,8 @@ static const struct pisp_be_format supported_formats[] = { }, { .fourcc = V4L2_PIX_FMT_RGBX32, - .align = 64, + .opt_align = 64, + .min_align = 16, .bit_depth = 32, .plane_factor = { P3(1.0) }, .num_planes = 1, @@ -251,7 +273,8 @@ static const struct pisp_be_format supported_formats[] = { }, { .fourcc = V4L2_PIX_FMT_RGB48, - .align = 64, + .opt_align = 64, + .min_align = 16, .bit_depth = 48, .plane_factor = { P3(1.0) }, .num_planes = 1, @@ -260,7 +283,8 @@ static const struct pisp_be_format supported_formats[] = { }, { .fourcc = V4L2_PIX_FMT_BGR48, - .align = 64, + .opt_align = 64, + .min_align = 16, .bit_depth = 48, .plane_factor = { P3(1.0) }, .num_planes = 1, @@ -271,7 +295,8 @@ static const struct pisp_be_format supported_formats[] = { { .fourcc = V4L2_PIX_FMT_SRGGB8, .bit_depth = 8, - .align = 32, + .opt_align = 16, + .min_align = 32, .plane_factor = { P3(1.0) }, .num_planes = 1, .colorspace_mask = V4L2_COLORSPACE_MASK_RAW, @@ -280,7 +305,8 @@ static const struct pisp_be_format supported_formats[] = { { .fourcc = V4L2_PIX_FMT_SBGGR8, .bit_depth = 8, - .align = 32, + .opt_align = 16, + .min_align = 32, .plane_factor = { P3(1.0) }, .num_planes = 1, .colorspace_mask = V4L2_COLORSPACE_MASK_RAW, @@ -289,7 +315,8 @@ static const struct pisp_be_format supported_formats[] = { { .fourcc = V4L2_PIX_FMT_SGRBG8, .bit_depth = 8, - .align = 32, + .opt_align = 32, + .min_align = 16, .plane_factor = { P3(1.0) }, .num_planes = 1, .colorspace_mask = V4L2_COLORSPACE_MASK_RAW, @@ -298,7 +325,8 @@ static const struct pisp_be_format supported_formats[] = { { .fourcc = V4L2_PIX_FMT_SGBRG8, .bit_depth = 8, - .align = 32, + .opt_align = 32, + .min_align = 16, .plane_factor = { P3(1.0) }, .num_planes = 1, .colorspace_mask = V4L2_COLORSPACE_MASK_RAW, @@ -308,7 +336,8 @@ static const struct pisp_be_format supported_formats[] = { { .fourcc = V4L2_PIX_FMT_SRGGB16, .bit_depth = 16, - .align = 32, + .opt_align = 32, + .min_align = 16, .plane_factor = { P3(1.0) }, .num_planes = 1, .colorspace_mask = V4L2_COLORSPACE_MASK_RAW, @@ -317,7 +346,8 @@ static const struct pisp_be_format supported_formats[] = { { .fourcc = V4L2_PIX_FMT_SBGGR16, .bit_depth = 16, - .align = 32, + .opt_align = 32, + .min_align = 16, .plane_factor = { P3(1.0) }, .num_planes = 1, .colorspace_mask = V4L2_COLORSPACE_MASK_RAW, @@ -326,7 +356,8 @@ static const struct pisp_be_format supported_formats[] = { { .fourcc = V4L2_PIX_FMT_SGRBG16, .bit_depth = 16, - .align = 32, + .opt_align = 32, + .min_align = 16, .plane_factor = { P3(1.0) }, .num_planes = 1, .colorspace_mask = V4L2_COLORSPACE_MASK_RAW, @@ -335,7 +366,8 @@ static const struct pisp_be_format supported_formats[] = { { .fourcc = V4L2_PIX_FMT_SGBRG16, .bit_depth = 16, - .align = 32, + .opt_align = 32, + .min_align = 16, .plane_factor = { P3(1.0) }, .num_planes = 1, .colorspace_mask = V4L2_COLORSPACE_MASK_RAW, @@ -346,7 +378,8 @@ static const struct pisp_be_format supported_formats[] = { /* 10 bit */ .fourcc = V4L2_PIX_FMT_SRGGB10, .bit_depth = 16, - .align = 32, + .opt_align = 32, + .min_align = 16, .plane_factor = { P3(1.0) }, .num_planes = 1, .colorspace_mask = V4L2_COLORSPACE_MASK_RAW, @@ -355,7 +388,8 @@ static const struct pisp_be_format supported_formats[] = { { .fourcc = V4L2_PIX_FMT_SBGGR10, .bit_depth = 16, - .align = 32, + .opt_align = 32, + .min_align = 16, .plane_factor = { P3(1.0) }, .num_planes = 1, .colorspace_mask = V4L2_COLORSPACE_MASK_RAW, @@ -364,7 +398,8 @@ static const struct pisp_be_format supported_formats[] = { { .fourcc = V4L2_PIX_FMT_SGRBG10, .bit_depth = 16, - .align = 32, + .opt_align = 32, + .min_align = 16, .plane_factor = { P3(1.0) }, .num_planes = 1, .colorspace_mask = V4L2_COLORSPACE_MASK_RAW, @@ -373,7 +408,8 @@ static const struct pisp_be_format supported_formats[] = { { .fourcc = V4L2_PIX_FMT_SGBRG10, .bit_depth = 16, - .align = 32, + .opt_align = 32, + .min_align = 16, .plane_factor = { P3(1.0) }, .num_planes = 1, .colorspace_mask = V4L2_COLORSPACE_MASK_RAW, @@ -383,7 +419,8 @@ static const struct pisp_be_format supported_formats[] = { /* 12 bit */ .fourcc = V4L2_PIX_FMT_SRGGB12, .bit_depth = 16, - .align = 32, + .opt_align = 32, + .min_align = 16, .plane_factor = { P3(1.0) }, .num_planes = 1, .colorspace_mask = V4L2_COLORSPACE_MASK_RAW, @@ -392,7 +429,8 @@ static const struct pisp_be_format supported_formats[] = { { .fourcc = V4L2_PIX_FMT_SBGGR12, .bit_depth = 16, - .align = 32, + .opt_align = 32, + .min_align = 16, .plane_factor = { P3(1.0) }, .num_planes = 1, .colorspace_mask = V4L2_COLORSPACE_MASK_RAW, @@ -401,7 +439,8 @@ static const struct pisp_be_format supported_formats[] = { { .fourcc = V4L2_PIX_FMT_SGRBG12, .bit_depth = 16, - .align = 32, + .opt_align = 32, + .min_align = 16, .plane_factor = { P3(1.0) }, .num_planes = 1, .colorspace_mask = V4L2_COLORSPACE_MASK_RAW, @@ -410,7 +449,8 @@ static const struct pisp_be_format supported_formats[] = { { .fourcc = V4L2_PIX_FMT_SGBRG12, .bit_depth = 16, - .align = 32, + .opt_align = 32, + .min_align = 16, .plane_factor = { P3(1.0) }, .num_planes = 1, .colorspace_mask = V4L2_COLORSPACE_MASK_RAW, @@ -420,7 +460,8 @@ static const struct pisp_be_format supported_formats[] = { /* 14 bit */ .fourcc = V4L2_PIX_FMT_SRGGB14, .bit_depth = 16, - .align = 32, + .opt_align = 32, + .min_align = 16, .plane_factor = { P3(1.0) }, .num_planes = 1, .colorspace_mask = V4L2_COLORSPACE_MASK_RAW, @@ -429,7 +470,8 @@ static const struct pisp_be_format supported_formats[] = { { .fourcc = V4L2_PIX_FMT_SBGGR14, .bit_depth = 16, - .align = 32, + .opt_align = 32, + .min_align = 16, .plane_factor = { P3(1.0) }, .num_planes = 1, .colorspace_mask = V4L2_COLORSPACE_MASK_RAW, @@ -438,7 +480,8 @@ static const struct pisp_be_format supported_formats[] = { { .fourcc = V4L2_PIX_FMT_SGRBG14, .bit_depth = 16, - .align = 32, + .opt_align = 32, + .min_align = 16, .plane_factor = { P3(1.0) }, .num_planes = 1, .colorspace_mask = V4L2_COLORSPACE_MASK_RAW, @@ -447,7 +490,8 @@ static const struct pisp_be_format supported_formats[] = { { .fourcc = V4L2_PIX_FMT_SGBRG14, .bit_depth = 16, - .align = 32, + .opt_align = 32, + .min_align = 16, .plane_factor = { P3(1.0) }, .num_planes = 1, .colorspace_mask = V4L2_COLORSPACE_MASK_RAW, @@ -457,7 +501,8 @@ static const struct pisp_be_format supported_formats[] = { { .fourcc = V4L2_PIX_FMT_PISP_COMP1_BGGR, .bit_depth = 8, - .align = 32, + .opt_align = 32, + .min_align = 16, .plane_factor = { P3(1.0) }, .num_planes = 1, .colorspace_mask = V4L2_COLORSPACE_MASK_RAW, @@ -466,7 +511,8 @@ static const struct pisp_be_format supported_formats[] = { { .fourcc = V4L2_PIX_FMT_PISP_COMP1_RGGB, .bit_depth = 8, - .align = 32, + .opt_align = 32, + .min_align = 16, .plane_factor = { P3(1.0) }, .num_planes = 1, .colorspace_mask = V4L2_COLORSPACE_MASK_RAW, @@ -475,7 +521,8 @@ static const struct pisp_be_format supported_formats[] = { { .fourcc = V4L2_PIX_FMT_PISP_COMP1_GRBG, .bit_depth = 8, - .align = 32, + .opt_align = 32, + .min_align = 16, .plane_factor = { P3(1.0) }, .num_planes = 1, .colorspace_mask = V4L2_COLORSPACE_MASK_RAW, @@ -484,7 +531,8 @@ static const struct pisp_be_format supported_formats[] = { { .fourcc = V4L2_PIX_FMT_PISP_COMP1_GBRG, .bit_depth = 8, - .align = 32, + .opt_align = 32, + .min_align = 16, .plane_factor = { P3(1.0) }, .num_planes = 1, .colorspace_mask = V4L2_COLORSPACE_MASK_RAW, @@ -494,7 +542,8 @@ static const struct pisp_be_format supported_formats[] = { { .fourcc = V4L2_PIX_FMT_GREY, .bit_depth = 8, - .align = 32, + .opt_align = 32, + .min_align = 16, .num_planes = 1, .colorspace_mask = V4L2_COLORSPACE_MASK_RAW, .colorspace_default = V4L2_COLORSPACE_RAW, @@ -502,7 +551,8 @@ static const struct pisp_be_format supported_formats[] = { { .fourcc = V4L2_PIX_FMT_Y16, .bit_depth = 16, - .align = 32, + .opt_align = 32, + .min_align = 16, .plane_factor = { P3(1.0) }, .num_planes = 1, .colorspace_mask = V4L2_COLORSPACE_MASK_RAW, @@ -511,7 +561,8 @@ static const struct pisp_be_format supported_formats[] = { { .fourcc = V4L2_PIX_FMT_PISP_COMP1_MONO, .bit_depth = 8, - .align = 32, + .opt_align = 32, + .min_align = 16, .plane_factor = { P3(1.0) }, .num_planes = 1, .colorspace_mask = V4L2_COLORSPACE_MASK_RAW,