From 144cf8273e8586dde1701a25603d1c47bb282539 Mon Sep 17 00:00:00 2001
From: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
Date: Tue, 20 Oct 2009 16:02:44 +0200
Subject: [PATCH 11/15] imagebus: add byteswapped pixel codes and high and low padding

When sending more than 8 and fewer than 16 bits of data over 8 data lines we
have to know in which order the bytes are sent (LE / BE) and where in the high
byte padding bits are located. This patch adds necessary pixel codes and a new
packing.

Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
---
 drivers/media/video/mt9m111.c       |   10 +++++-----
 drivers/media/video/v4l2-imagebus.c |   23 ++++++++++++++++++++++-
 include/media/v4l2-imagebus.h       |    6 +++++-
 3 files changed, 32 insertions(+), 7 deletions(-)

diff --git a/drivers/media/video/mt9m111.c b/drivers/media/video/mt9m111.c
index 9f53196..b5147e8 100644
--- a/drivers/media/video/mt9m111.c
+++ b/drivers/media/video/mt9m111.c
@@ -138,7 +138,7 @@ static const enum v4l2_imgbus_pixelcode mt9m111_colour_codes[] = {
 	V4L2_IMGBUS_FMT_YVYU,
 	V4L2_IMGBUS_FMT_RGB565,
 	V4L2_IMGBUS_FMT_RGB555,
-	V4L2_IMGBUS_FMT_SBGGR10_2X8,
+	V4L2_IMGBUS_FMT_SBGGR10_2X8_PADHI_LE,
 	V4L2_IMGBUS_FMT_SBGGR8,
 };
 
@@ -259,7 +259,7 @@ static int mt9m111_setup_rect(struct i2c_client *client,
 	int height = rect->height;
 
 	if (mt9m111->code == V4L2_IMGBUS_FMT_SBGGR8 ||
-	    mt9m111->code == V4L2_IMGBUS_FMT_SBGGR10_2X8)
+	    mt9m111->code == V4L2_IMGBUS_FMT_SBGGR10_2X8_PADHI_LE)
 		is_raw_format = 1;
 	else
 		is_raw_format = 0;
@@ -403,7 +403,7 @@ static int mt9m111_make_rect(struct i2c_client *client,
 	struct mt9m111 *mt9m111 = to_mt9m111(client);
 
 	if (mt9m111->code == V4L2_IMGBUS_FMT_SBGGR8 ||
-	    mt9m111->code == V4L2_IMGBUS_FMT_SBGGR10_2X8) {
+	    mt9m111->code == V4L2_IMGBUS_FMT_SBGGR10_2X8_PADHI_LE) {
 		/* Bayer format - even size lengths */
 		rect->width	= ALIGN(rect->width, 2);
 		rect->height	= ALIGN(rect->height, 2);
@@ -485,7 +485,7 @@ static int mt9m111_set_pixfmt(struct i2c_client *client,
 	case V4L2_IMGBUS_FMT_SBGGR8:
 		ret = mt9m111_setfmt_bayer8(client);
 		break;
-	case V4L2_IMGBUS_FMT_SBGGR10_2X8:
+	case V4L2_IMGBUS_FMT_SBGGR10_2X8_PADHI_LE:
 		ret = mt9m111_setfmt_bayer10(client);
 		break;
 	case V4L2_IMGBUS_FMT_RGB555:
@@ -555,7 +555,7 @@ static int mt9m111_try_fmt(struct v4l2_subdev *sd,
 			   struct v4l2_imgbus_framefmt *imgf)
 {
 	bool bayer = imgf->code == V4L2_IMGBUS_FMT_SBGGR8 ||
-		imgf->code == V4L2_IMGBUS_FMT_SBGGR10_2X8;
+		imgf->code == V4L2_IMGBUS_FMT_SBGGR10_2X8_PADHI_LE;
 
 	/*
 	 * With Bayer format enforce even side lengths, but let the user play
diff --git a/drivers/media/video/v4l2-imagebus.c b/drivers/media/video/v4l2-imagebus.c
index e3dc48b..41cfbeb 100644
--- a/drivers/media/video/v4l2-imagebus.c
+++ b/drivers/media/video/v4l2-imagebus.c
@@ -162,13 +162,34 @@ static const struct v4l2_imgbus_pixelfmt imgbus_fmt[] = {
 		.bits_per_sample	= 10,
 		.packing		= V4L2_IMGBUS_PACKING_EXTEND16,
 		.order			= V4L2_IMGBUS_ORDER_LE,
-	}, [V4L2_IMGBUS_FMT_SBGGR10_2X8] = {
+	}, [V4L2_IMGBUS_FMT_SBGGR10_2X8_PADHI_LE] = {
 		.fourcc			= V4L2_PIX_FMT_SBGGR10,
 		.colorspace		= V4L2_COLORSPACE_SRGB,
 		.name			= "Bayer 10 BGGR",
 		.bits_per_sample	= 8,
 		.packing		= V4L2_IMGBUS_PACKING_2X8,
 		.order			= V4L2_IMGBUS_ORDER_LE,
+	}, [V4L2_IMGBUS_FMT_SBGGR10_2X8_PADLO_LE] = {
+		.fourcc			= V4L2_PIX_FMT_SBGGR10,
+		.colorspace		= V4L2_COLORSPACE_SRGB,
+		.name			= "Bayer 10 BGGR",
+		.bits_per_sample	= 8,
+		.packing		= V4L2_IMGBUS_PACKING_2X8_PADLO,
+		.order			= V4L2_IMGBUS_ORDER_LE,
+	}, [V4L2_IMGBUS_FMT_SBGGR10_2X8_PADHI_BE] = {
+		.fourcc			= V4L2_PIX_FMT_SBGGR10,
+		.colorspace		= V4L2_COLORSPACE_SRGB,
+		.name			= "Bayer 10 BGGR",
+		.bits_per_sample	= 8,
+		.packing		= V4L2_IMGBUS_PACKING_2X8,
+		.order			= V4L2_IMGBUS_ORDER_BE,
+	}, [V4L2_IMGBUS_FMT_SBGGR10_2X8_PADLO_BE] = {
+		.fourcc			= V4L2_PIX_FMT_SBGGR10,
+		.colorspace		= V4L2_COLORSPACE_SRGB,
+		.name			= "Bayer 10 BGGR",
+		.bits_per_sample	= 8,
+		.packing		= V4L2_IMGBUS_PACKING_2X8_PADLO,
+		.order			= V4L2_IMGBUS_ORDER_BE,
 	},
 };
 
diff --git a/include/media/v4l2-imagebus.h b/include/media/v4l2-imagebus.h
index d8c0fb8..45962af 100644
--- a/include/media/v4l2-imagebus.h
+++ b/include/media/v4l2-imagebus.h
@@ -14,6 +14,7 @@
 enum v4l2_imgbus_packing {
 	V4L2_IMGBUS_PACKING_NONE,
 	V4L2_IMGBUS_PACKING_2X8,
+	V4L2_IMGBUS_PACKING_2X8_PADLO,
 	V4L2_IMGBUS_PACKING_EXTEND16,
 };
 
@@ -44,7 +45,10 @@ enum v4l2_imgbus_pixelcode {
 	V4L2_IMGBUS_FMT_GREY,
 	V4L2_IMGBUS_FMT_Y16,
 	V4L2_IMGBUS_FMT_Y10,
-	V4L2_IMGBUS_FMT_SBGGR10_2X8,
+	V4L2_IMGBUS_FMT_SBGGR10_2X8_PADHI_BE,
+	V4L2_IMGBUS_FMT_SBGGR10_2X8_PADLO_BE,
+	V4L2_IMGBUS_FMT_SBGGR10_2X8_PADHI_LE,
+	V4L2_IMGBUS_FMT_SBGGR10_2X8_PADLO_LE,
 };
 
 /**
-- 
1.6.2.4

