diff mbox series

[2/2] media: i2c: ov5640: Add support for BT656 mode

Message ID 1596187487-31403-3-git-send-email-prabhakar.mahadev-lad.rj@bp.renesas.com (mailing list archive)
State New
Delegated to: Kieran Bingham
Headers show
Series media: ov5640 feature enhancement and fixes | expand

Commit Message

Prabhakar July 31, 2020, 9:24 a.m. UTC
Enable support for BT656 mode.

Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
Reviewed-by: Biju Das <biju.das.jz@bp.renesas.com>
---
 drivers/media/i2c/ov5640.c | 48 +++++++++++++++++++++++++++++++---------------
 1 file changed, 33 insertions(+), 15 deletions(-)

Comments

Sakari Ailus July 31, 2020, 3:23 p.m. UTC | #1
Hi Prabhakar,

On Fri, Jul 31, 2020 at 10:24:47AM +0100, Lad Prabhakar wrote:
> @@ -2875,8 +2891,10 @@ static int ov5640_s_stream(struct v4l2_subdev *sd, int enable)
>  
>  		if (sensor->ep.bus_type == V4L2_MBUS_CSI2_DPHY)
>  			ret = ov5640_set_stream_mipi(sensor, enable);
> -		else
> +		else if (sensor->ep.bus_type == V4L2_MBUS_PARALLEL)
>  			ret = ov5640_set_stream_dvp(sensor, enable);
> +		else
> +			ret = ov5640_set_stream_bt656(sensor, enable);

I'd also check for the Bt.656 mode here, rather than assuming it. 

Could you also update the DT bindings, given that the sensor appears to
support Bt.656 as well? I believe this requires the bus-type property, too.

>  
>  		if (!ret)
>  			sensor->streaming = enable;
Lad, Prabhakar July 31, 2020, 3:28 p.m. UTC | #2
Hi Sakari,

Thank you for the review.

On Fri, Jul 31, 2020 at 4:23 PM Sakari Ailus
<sakari.ailus@linux.intel.com> wrote:
>
> Hi Prabhakar,
>
> On Fri, Jul 31, 2020 at 10:24:47AM +0100, Lad Prabhakar wrote:
> > @@ -2875,8 +2891,10 @@ static int ov5640_s_stream(struct v4l2_subdev *sd, int enable)
> >
> >               if (sensor->ep.bus_type == V4L2_MBUS_CSI2_DPHY)
> >                       ret = ov5640_set_stream_mipi(sensor, enable);
> > -             else
> > +             else if (sensor->ep.bus_type == V4L2_MBUS_PARALLEL)
> >                       ret = ov5640_set_stream_dvp(sensor, enable);
> > +             else
> > +                     ret = ov5640_set_stream_bt656(sensor, enable);
>
> I'd also check for the Bt.656 mode here, rather than assuming it.
>
Sure will do.

> Could you also update the DT bindings, given that the sensor appears to
> support Bt.656 as well? I believe this requires the bus-type property, too.
>
Aha I ignored because this wasnt updated when DVP support was added to
the driver, but will do now.

Cheers,
Prabhakar

> >
> >               if (!ret)
> >                       sensor->streaming = enable;
>
> --
> Kind regards,
>
> Sakari Ailus
diff mbox series

Patch

diff --git a/drivers/media/i2c/ov5640.c b/drivers/media/i2c/ov5640.c
index ac305a5..2b23988 100644
--- a/drivers/media/i2c/ov5640.c
+++ b/drivers/media/i2c/ov5640.c
@@ -82,6 +82,7 @@ 
 #define OV5640_REG_VFIFO_HSIZE		0x4602
 #define OV5640_REG_VFIFO_VSIZE		0x4604
 #define OV5640_REG_JPG_MODE_SELECT	0x4713
+#define OV5640_REG_CCIR656_CTRL00	0x4730
 #define OV5640_REG_POLARITY_CTRL00	0x4740
 #define OV5640_REG_MIPI_CTRL00		0x4800
 #define OV5640_REG_DEBUG_MODE		0x4814
@@ -1213,6 +1214,17 @@  static int ov5640_set_stream_dvp(struct ov5640_dev *sensor, bool on)
 	return ov5640_write_reg(sensor, OV5640_REG_SYS_CTRL0, on ? 0x2 : 0x42);
 }
 
+static int ov5640_set_stream_bt656(struct ov5640_dev *sensor, bool on)
+{
+	int ret;
+
+	ret = ov5640_write_reg(sensor, OV5640_REG_CCIR656_CTRL00, on ? 0x1 : 0x00);
+	if (ret)
+		return ret;
+
+	return ov5640_write_reg(sensor, OV5640_REG_SYS_CTRL0, on ? 0x2 : 0x42);
+}
+
 static int ov5640_set_stream_mipi(struct ov5640_dev *sensor, bool on)
 {
 	int ret;
@@ -1998,18 +2010,21 @@  static int ov5640_set_power(struct ov5640_dev *sensor, bool on)
 			 *		datasheet and hardware, 0 is active high
 			 *		and 1 is active low...)
 			 */
-			if (flags & V4L2_MBUS_PCLK_SAMPLE_RISING)
-				pclk_pol = 1;
-			if (flags & V4L2_MBUS_HSYNC_ACTIVE_HIGH)
-				hsync_pol = 1;
-			if (flags & V4L2_MBUS_VSYNC_ACTIVE_LOW)
-				vsync_pol = 1;
-
-			ret = ov5640_write_reg(sensor, OV5640_REG_POLARITY_CTRL00,
-					       (pclk_pol << 5) | (hsync_pol << 1) | vsync_pol);
-
-			if (ret)
-				goto power_off;
+			if (sensor->ep.bus_type == V4L2_MBUS_PARALLEL) {
+				if (flags & V4L2_MBUS_PCLK_SAMPLE_RISING)
+					pclk_pol = 1;
+				if (flags & V4L2_MBUS_HSYNC_ACTIVE_HIGH)
+					hsync_pol = 1;
+				if (flags & V4L2_MBUS_VSYNC_ACTIVE_LOW)
+					vsync_pol = 1;
+
+				ret = ov5640_write_reg(sensor, OV5640_REG_POLARITY_CTRL00,
+						       (pclk_pol << 5) | (hsync_pol << 1) |
+						       vsync_pol);
+
+				if (ret)
+					goto power_off;
+			}
 
 			/*
 			 * powerdown MIPI TX/RX PHY & disable MIPI
@@ -2033,7 +2048,9 @@  static int ov5640_set_power(struct ov5640_dev *sensor, bool on)
 			 * - 4:		PCLK output enable
 			 * - [3:0]:	D[9:6] output enable
 			 */
-			ret = ov5640_write_reg(sensor, OV5640_REG_PAD_OUTPUT_ENABLE01, 0x7f);
+			ret = ov5640_write_reg(sensor, OV5640_REG_PAD_OUTPUT_ENABLE01,
+					       sensor->ep.bus_type == V4L2_MBUS_PARALLEL ?
+					       0x7f : 0x1f);
 			if (ret)
 				goto power_off;
 
@@ -2047,7 +2064,6 @@  static int ov5640_set_power(struct ov5640_dev *sensor, bool on)
 			if (ret)
 				goto power_off;
 		}
-
 	} else {
 		if (sensor->ep.bus_type == V4L2_MBUS_CSI2_DPHY) {
 			/* Reset MIPI bus settings to their default values. */
@@ -2875,8 +2891,10 @@  static int ov5640_s_stream(struct v4l2_subdev *sd, int enable)
 
 		if (sensor->ep.bus_type == V4L2_MBUS_CSI2_DPHY)
 			ret = ov5640_set_stream_mipi(sensor, enable);
-		else
+		else if (sensor->ep.bus_type == V4L2_MBUS_PARALLEL)
 			ret = ov5640_set_stream_dvp(sensor, enable);
+		else
+			ret = ov5640_set_stream_bt656(sensor, enable);
 
 		if (!ret)
 			sensor->streaming = enable;