build/patch/kernel/archive/sunxi-5.15/patches.megous/media-sun6i-csi-Make-the-video-device-respect-user-passed-bytes.patch

65 lines
2.4 KiB
Diff

From 1c174f3f369a259e7dedf9e39b4aa762690ca44a Mon Sep 17 00:00:00 2001
From: Ondrej Jirman <megous@megous.com>
Date: Fri, 24 Jan 2020 18:24:22 +0100
Subject: [PATCH 156/478] media: sun6i-csi: Make the video device respect user
passed bytesperline
WIP!!!
It is useful to be able to set bytesperline for YUYV and friends formats,
so that CSI can output frames with line alignment that's directly
useable by the rotation engine.
Allow this.
Signed-off-by: Ondrej Jirman <megous@megous.com>
---
drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c | 3 +--
drivers/media/platform/sunxi/sun6i-csi/sun6i_video.c | 9 ++++++++-
2 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c b/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c
index 673502d3977a..462ee433832c 100644
--- a/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c
+++ b/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c
@@ -564,8 +564,7 @@ static void sun6i_csi_set_window(struct sun6i_csi_dev *sdev)
dev_dbg(sdev->dev,
"Calculating pixelformat(0x%x)'s bytesperline as a packed format\n",
config->pixelformat);
- bytesperline_y = (sun6i_csi_get_bpp(config->pixelformat) *
- config->width) / 8;
+ bytesperline_y = sdev->csi.video.fmt.fmt.pix.bytesperline;
bytesperline_c = 0;
planar_offset[1] = -1;
planar_offset[2] = -1;
diff --git a/drivers/media/platform/sunxi/sun6i-csi/sun6i_video.c b/drivers/media/platform/sunxi/sun6i-csi/sun6i_video.c
index cdc6c557ef12..0129dee798b4 100644
--- a/drivers/media/platform/sunxi/sun6i-csi/sun6i_video.c
+++ b/drivers/media/platform/sunxi/sun6i-csi/sun6i_video.c
@@ -359,6 +359,7 @@ static int sun6i_video_try_fmt(struct sun6i_video *video,
{
struct v4l2_pix_format *pixfmt = &f->fmt.pix;
int bpp;
+ u32 bpl_packed;
if (!is_pixformat_valid(pixfmt->pixelformat))
pixfmt->pixelformat = supported_pixformats[0];
@@ -367,7 +368,13 @@ static int sun6i_video_try_fmt(struct sun6i_video *video,
&pixfmt->height, MIN_HEIGHT, MAX_WIDTH, 1, 1);
bpp = sun6i_csi_get_bpp(pixfmt->pixelformat);
- pixfmt->bytesperline = (pixfmt->width * bpp) >> 3;
+ bpl_packed = (pixfmt->width * bpp) / 8;
+
+ //XXX: only allow for YUYV and friends
+ if (pixfmt->bytesperline < bpl_packed
+ || pixfmt->bytesperline > bpl_packed + 256)
+ pixfmt->bytesperline = bpl_packed;
+
pixfmt->sizeimage = pixfmt->bytesperline * pixfmt->height;
if (pixfmt->field == V4L2_FIELD_ANY)
--
2.35.3