public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH 00/22] adv7842: fixes
@ 2013-12-10 15:03 Hans Verkuil
  2013-12-10 15:03 ` [RFC PATCH 01/22] adv7842: Re-worked query_dv_timings() Hans Verkuil
  0 siblings, 1 reply; 27+ messages in thread
From: Hans Verkuil @ 2013-12-10 15:03 UTC (permalink / raw)
  To: linux-media

This patch series updates the adv7842 driver with the latest fixes
from our internal tree.

Regards,

	Hans


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [RFC PATCH 01/22] adv7842: Re-worked query_dv_timings()
  2013-12-10 15:03 [RFC PATCH 00/22] adv7842: fixes Hans Verkuil
@ 2013-12-10 15:03 ` Hans Verkuil
  2013-12-10 15:03   ` [RFC PATCH 02/22] adv7842: corrected setting of cp-register 0x91 and 0x8f Hans Verkuil
                     ` (20 more replies)
  0 siblings, 21 replies; 27+ messages in thread
From: Hans Verkuil @ 2013-12-10 15:03 UTC (permalink / raw)
  To: linux-media; +Cc: Martin Bugge, Hans Verkuil

From: Martin Bugge <marbugge@cisco.com>

This simplified the code quite a bit.

Signed-off-by: Martin Bugge <marbugge@cisco.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/i2c/adv7842.c | 112 ++++++++++++++------------------------------
 1 file changed, 35 insertions(+), 77 deletions(-)

diff --git a/drivers/media/i2c/adv7842.c b/drivers/media/i2c/adv7842.c
index b154f36..22fa4ca 100644
--- a/drivers/media/i2c/adv7842.c
+++ b/drivers/media/i2c/adv7842.c
@@ -1314,6 +1314,8 @@ static int adv7842_query_dv_timings(struct v4l2_subdev *sd,
 	struct v4l2_bt_timings *bt = &timings->bt;
 	struct stdi_readback stdi = { 0 };
 
+	v4l2_dbg(1, debug, sd, "%s:\n", __func__);
+
 	/* SDP block */
 	if (state->mode == ADV7842_MODE_SDP)
 		return -ENODATA;
@@ -1325,92 +1327,46 @@ static int adv7842_query_dv_timings(struct v4l2_subdev *sd,
 	}
 	bt->interlaced = stdi.interlaced ?
 		V4L2_DV_INTERLACED : V4L2_DV_PROGRESSIVE;
-	bt->polarities = ((hdmi_read(sd, 0x05) & 0x10) ? V4L2_DV_VSYNC_POS_POL : 0) |
-		((hdmi_read(sd, 0x05) & 0x20) ? V4L2_DV_HSYNC_POS_POL : 0);
-	bt->vsync = stdi.lcvs;
 
 	if (is_digital_input(sd)) {
-		bool lock = hdmi_read(sd, 0x04) & 0x02;
-		bool interlaced = hdmi_read(sd, 0x0b) & 0x20;
-		unsigned w = (hdmi_read(sd, 0x07) & 0x1f) * 256 + hdmi_read(sd, 0x08);
-		unsigned h = (hdmi_read(sd, 0x09) & 0x1f) * 256 + hdmi_read(sd, 0x0a);
-		unsigned w_total = (hdmi_read(sd, 0x1e) & 0x3f) * 256 +
-			hdmi_read(sd, 0x1f);
-		unsigned h_total = ((hdmi_read(sd, 0x26) & 0x3f) * 256 +
-				    hdmi_read(sd, 0x27)) / 2;
-		unsigned freq = (((hdmi_read(sd, 0x51) << 1) +
-					(hdmi_read(sd, 0x52) >> 7)) * 1000000) +
-			((hdmi_read(sd, 0x52) & 0x7f) * 1000000) / 128;
-		int i;
+		uint32_t freq;
+
+		timings->type = V4L2_DV_BT_656_1120;
+		bt->width = (hdmi_read(sd, 0x07) & 0x0f) * 256 + hdmi_read(sd, 0x08);
+		bt->height = (hdmi_read(sd, 0x09) & 0x0f) * 256 + hdmi_read(sd, 0x0a);
+		freq = (hdmi_read(sd, 0x06) * 1000000) +
+		       ((hdmi_read(sd, 0x3b) & 0x30) >> 4) * 250000;
 
 		if (is_hdmi(sd)) {
 			/* adjust for deep color mode */
-			freq = freq * 8 / (((hdmi_read(sd, 0x0b) & 0xc0)>>6) * 2 + 8);
-		}
-
-		/* No lock? */
-		if (!lock) {
-			v4l2_dbg(1, debug, sd, "%s: no lock on TMDS signal\n", __func__);
-			return -ENOLCK;
+			freq = freq * 8 / (((hdmi_read(sd, 0x0b) & 0xc0) >> 5) + 8);
 		}
-		/* Interlaced? */
-		if (interlaced) {
-			v4l2_dbg(1, debug, sd, "%s: interlaced video not supported\n", __func__);
-			return -ERANGE;
-		}
-
-		for (i = 0; v4l2_dv_timings_presets[i].bt.width; i++) {
-			const struct v4l2_bt_timings *bt = &v4l2_dv_timings_presets[i].bt;
-
-			if (!v4l2_valid_dv_timings(&v4l2_dv_timings_presets[i],
-						   adv7842_get_dv_timings_cap(sd),
-						   adv7842_check_dv_timings, NULL))
-				continue;
-			if (w_total != htotal(bt) || h_total != vtotal(bt))
-				continue;
-
-			if (w != bt->width || h != bt->height)
-				continue;
-
-			if (abs(freq - bt->pixelclock) > 1000000)
-				continue;
-			*timings = v4l2_dv_timings_presets[i];
-			return 0;
-		}
-
-		timings->type = V4L2_DV_BT_656_1120;
-
-		bt->width = w;
-		bt->height = h;
-		bt->interlaced = (hdmi_read(sd, 0x0b) & 0x20) ?
-			V4L2_DV_INTERLACED : V4L2_DV_PROGRESSIVE;
-		bt->polarities = ((hdmi_read(sd, 0x05) & 0x10) ?
-			V4L2_DV_VSYNC_POS_POL : 0) | ((hdmi_read(sd, 0x05) & 0x20) ?
-			V4L2_DV_HSYNC_POS_POL : 0);
-		bt->pixelclock = (((hdmi_read(sd, 0x51) << 1) +
-				   (hdmi_read(sd, 0x52) >> 7)) * 1000000) +
-				 ((hdmi_read(sd, 0x52) & 0x7f) * 1000000) / 128;
-		bt->hfrontporch = (hdmi_read(sd, 0x20) & 0x1f) * 256 +
+		bt->pixelclock = freq;
+		bt->hfrontporch = (hdmi_read(sd, 0x20) & 0x03) * 256 +
 			hdmi_read(sd, 0x21);
-		bt->hsync = (hdmi_read(sd, 0x22) & 0x1f) * 256 +
+		bt->hsync = (hdmi_read(sd, 0x22) & 0x03) * 256 +
 			hdmi_read(sd, 0x23);
-		bt->hbackporch = (hdmi_read(sd, 0x24) & 0x1f) * 256 +
+		bt->hbackporch = (hdmi_read(sd, 0x24) & 0x03) * 256 +
 			hdmi_read(sd, 0x25);
-		bt->vfrontporch = ((hdmi_read(sd, 0x2a) & 0x3f) * 256 +
-				   hdmi_read(sd, 0x2b)) / 2;
-		bt->il_vfrontporch = ((hdmi_read(sd, 0x2c) & 0x3f) * 256 +
-				      hdmi_read(sd, 0x2d)) / 2;
-		bt->vsync = ((hdmi_read(sd, 0x2e) & 0x3f) * 256 +
-			     hdmi_read(sd, 0x2f)) / 2;
-		bt->il_vsync = ((hdmi_read(sd, 0x30) & 0x3f) * 256 +
-				hdmi_read(sd, 0x31)) / 2;
-		bt->vbackporch = ((hdmi_read(sd, 0x32) & 0x3f) * 256 +
-				  hdmi_read(sd, 0x33)) / 2;
-		bt->il_vbackporch = ((hdmi_read(sd, 0x34) & 0x3f) * 256 +
-				     hdmi_read(sd, 0x35)) / 2;
-
-		bt->standards = 0;
-		bt->flags = 0;
+		bt->vfrontporch = ((hdmi_read(sd, 0x2a) & 0x1f) * 256 +
+			hdmi_read(sd, 0x2b)) / 2;
+		bt->vsync = ((hdmi_read(sd, 0x2e) & 0x1f) * 256 +
+			hdmi_read(sd, 0x2f)) / 2;
+		bt->vbackporch = ((hdmi_read(sd, 0x32) & 0x1f) * 256 +
+			hdmi_read(sd, 0x33)) / 2;
+		bt->polarities = ((hdmi_read(sd, 0x05) & 0x10) ? V4L2_DV_VSYNC_POS_POL : 0) |
+			((hdmi_read(sd, 0x05) & 0x20) ? V4L2_DV_HSYNC_POS_POL : 0);
+		if (bt->interlaced == V4L2_DV_INTERLACED) {
+			bt->height += (hdmi_read(sd, 0x0b) & 0x0f) * 256 +
+					hdmi_read(sd, 0x0c);
+			bt->il_vfrontporch = ((hdmi_read(sd, 0x2c) & 0x1f) * 256 +
+					hdmi_read(sd, 0x2d)) / 2;
+			bt->il_vsync = ((hdmi_read(sd, 0x30) & 0x1f) * 256 +
+					hdmi_read(sd, 0x31)) / 2;
+			bt->vbackporch = ((hdmi_read(sd, 0x34) & 0x1f) * 256 +
+					hdmi_read(sd, 0x35)) / 2;
+		}
+		adv7842_fill_optional_dv_timings_fields(sd, timings);
 	} else {
 		/* Interlaced? */
 		if (stdi.interlaced) {
@@ -1437,6 +1393,8 @@ static int adv7842_s_dv_timings(struct v4l2_subdev *sd,
 	struct v4l2_bt_timings *bt;
 	int err;
 
+	v4l2_dbg(1, debug, sd, "%s:\n", __func__);
+
 	if (state->mode == ADV7842_MODE_SDP)
 		return -ENODATA;
 
-- 
1.8.4.rc3


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [RFC PATCH 02/22] adv7842: corrected setting of cp-register 0x91 and 0x8f.
  2013-12-10 15:03 ` [RFC PATCH 01/22] adv7842: Re-worked query_dv_timings() Hans Verkuil
@ 2013-12-10 15:03   ` Hans Verkuil
  2013-12-10 15:03   ` [RFC PATCH 03/22] adv7842: properly enable/disable the irqs Hans Verkuil
                     ` (19 subsequent siblings)
  20 siblings, 0 replies; 27+ messages in thread
From: Hans Verkuil @ 2013-12-10 15:03 UTC (permalink / raw)
  To: linux-media; +Cc: Martin Bugge, Hans Verkuil

From: Martin Bugge <marbugge@cisco.com>

Bit 6 of register 0x8f was cleared incorrectly (must be 1), and bit 4
of register 0x91 was set incorrectly (must be 0).

These bits are undocumented, so we shouldn't modify them to values different
from what the datasheet specifies.

Signed-off-by: Martin Bugge <marbugge@cisco.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/i2c/adv7842.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/i2c/adv7842.c b/drivers/media/i2c/adv7842.c
index 22fa4ca..6434a93 100644
--- a/drivers/media/i2c/adv7842.c
+++ b/drivers/media/i2c/adv7842.c
@@ -927,7 +927,7 @@ static int configure_predefined_video_timings(struct v4l2_subdev *sd,
 	cp_write(sd, 0x27, 0x00);
 	cp_write(sd, 0x28, 0x00);
 	cp_write(sd, 0x29, 0x00);
-	cp_write(sd, 0x8f, 0x00);
+	cp_write(sd, 0x8f, 0x40);
 	cp_write(sd, 0x90, 0x00);
 	cp_write(sd, 0xa5, 0x00);
 	cp_write(sd, 0xa6, 0x00);
@@ -1408,7 +1408,7 @@ static int adv7842_s_dv_timings(struct v4l2_subdev *sd,
 
 	state->timings = *timings;
 
-	cp_write(sd, 0x91, bt->interlaced ? 0x50 : 0x10);
+	cp_write(sd, 0x91, bt->interlaced ? 0x40 : 0x00);
 
 	/* Use prim_mode and vid_std when available */
 	err = configure_predefined_video_timings(sd, timings);
-- 
1.8.4.rc3


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [RFC PATCH 03/22] adv7842: properly enable/disable the irqs.
  2013-12-10 15:03 ` [RFC PATCH 01/22] adv7842: Re-worked query_dv_timings() Hans Verkuil
  2013-12-10 15:03   ` [RFC PATCH 02/22] adv7842: corrected setting of cp-register 0x91 and 0x8f Hans Verkuil
@ 2013-12-10 15:03   ` Hans Verkuil
  2013-12-10 15:03   ` [RFC PATCH 04/22] adv7842: save platform data in state struct Hans Verkuil
                     ` (18 subsequent siblings)
  20 siblings, 0 replies; 27+ messages in thread
From: Hans Verkuil @ 2013-12-10 15:03 UTC (permalink / raw)
  To: linux-media; +Cc: Martin Bugge, Hans Verkuil

From: Martin Bugge <marbugge@cisco.com>

The method of disabling the irq-output pin caused many "empty"
interrupts. Instead, actually disable/enable the interrupts by
changing the interrupt masks.

Also enable STORE_MASKED_IRQ in INT1 configuration.

Signed-off-by: Martin Bugge <marbugge@cisco.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/i2c/adv7842.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/drivers/media/i2c/adv7842.c b/drivers/media/i2c/adv7842.c
index 6434a93..cbbfa77 100644
--- a/drivers/media/i2c/adv7842.c
+++ b/drivers/media/i2c/adv7842.c
@@ -1786,10 +1786,8 @@ static int adv7842_isr(struct v4l2_subdev *sd, u32 status, bool *handled)
 	struct adv7842_state *state = to_state(sd);
 	u8 fmt_change_cp, fmt_change_digital, fmt_change_sdp;
 	u8 irq_status[5];
-	u8 irq_cfg = io_read(sd, 0x40);
 
-	/* disable irq-pin output */
-	io_write(sd, 0x40, irq_cfg | 0x3);
+	adv7842_irq_enable(sd, false);
 
 	/* read status */
 	irq_status[0] = io_read(sd, 0x43);
@@ -1810,6 +1808,8 @@ static int adv7842_isr(struct v4l2_subdev *sd, u32 status, bool *handled)
 	if (irq_status[4])
 		io_write(sd, 0x9e, irq_status[4]);
 
+	adv7842_irq_enable(sd, true);
+
 	v4l2_dbg(1, debug, sd, "%s: irq %x, %x, %x, %x, %x\n", __func__,
 		 irq_status[0], irq_status[1], irq_status[2],
 		 irq_status[3], irq_status[4]);
@@ -1845,9 +1845,6 @@ static int adv7842_isr(struct v4l2_subdev *sd, u32 status, bool *handled)
 	if (handled)
 		*handled = true;
 
-	/* re-enable irq-pin output */
-	io_write(sd, 0x40, irq_cfg);
-
 	return 0;
 }
 
@@ -2446,7 +2443,7 @@ static int adv7842_core_init(struct v4l2_subdev *sd,
 	io_write(sd, 0x33, 0x40);
 
 	/* interrupts */
-	io_write(sd, 0x40, 0xe2); /* Configure INT1 */
+	io_write(sd, 0x40, 0xf2); /* Configure INT1 */
 
 	adv7842_irq_enable(sd, true);
 
-- 
1.8.4.rc3


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [RFC PATCH 04/22] adv7842: save platform data in state struct
  2013-12-10 15:03 ` [RFC PATCH 01/22] adv7842: Re-worked query_dv_timings() Hans Verkuil
  2013-12-10 15:03   ` [RFC PATCH 02/22] adv7842: corrected setting of cp-register 0x91 and 0x8f Hans Verkuil
  2013-12-10 15:03   ` [RFC PATCH 03/22] adv7842: properly enable/disable the irqs Hans Verkuil
@ 2013-12-10 15:03   ` Hans Verkuil
  2013-12-10 15:03   ` [RFC PATCH 05/22] adv7842: support YCrCb analog input Hans Verkuil
                     ` (17 subsequent siblings)
  20 siblings, 0 replies; 27+ messages in thread
From: Hans Verkuil @ 2013-12-10 15:03 UTC (permalink / raw)
  To: linux-media; +Cc: Martin Bugge, Hans Verkuil

From: Martin Bugge <marbugge@cisco.com>

Signed-off-by: Martin Bugge <marbugge@cisco.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/i2c/adv7842.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/media/i2c/adv7842.c b/drivers/media/i2c/adv7842.c
index cbbfa77..4f93526 100644
--- a/drivers/media/i2c/adv7842.c
+++ b/drivers/media/i2c/adv7842.c
@@ -61,6 +61,7 @@ MODULE_LICENSE("GPL");
 */
 
 struct adv7842_state {
+	struct adv7842_platform_data pdata;
 	struct v4l2_subdev sd;
 	struct media_pad pad;
 	struct v4l2_ctrl_handler hdl;
@@ -2730,6 +2731,9 @@ static int adv7842_probe(struct i2c_client *client,
 		return -ENOMEM;
 	}
 
+	/* platform data */
+	state->pdata = *pdata;
+
 	sd = &state->sd;
 	v4l2_i2c_subdev_init(sd, client, &adv7842_ops);
 	sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
@@ -2834,7 +2838,7 @@ static int adv7842_probe(struct i2c_client *client,
 	if (err)
 		goto err_work_queues;
 
-	err = adv7842_core_init(sd, pdata);
+	err = adv7842_core_init(sd);
 	if (err)
 		goto err_entity;
 
-- 
1.8.4.rc3


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [RFC PATCH 05/22] adv7842: support YCrCb analog input.
  2013-12-10 15:03 ` [RFC PATCH 01/22] adv7842: Re-worked query_dv_timings() Hans Verkuil
                     ` (2 preceding siblings ...)
  2013-12-10 15:03   ` [RFC PATCH 04/22] adv7842: save platform data in state struct Hans Verkuil
@ 2013-12-10 15:03   ` Hans Verkuil
  2013-12-10 15:03   ` [RFC PATCH 06/22] adv7842: added DE vertical position in SDP-io-sync Hans Verkuil
                     ` (16 subsequent siblings)
  20 siblings, 0 replies; 27+ messages in thread
From: Hans Verkuil @ 2013-12-10 15:03 UTC (permalink / raw)
  To: linux-media; +Cc: Martin Bugge, Hans Verkuil

From: Martin Bugge <marbugge@cisco.com>

Signed-off-by: Martin Bugge <marbugge@cisco.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/i2c/adv7842.c | 40 +++++++++++++++++++++++++++++-----------
 include/media/adv7842.h     |  3 ---
 2 files changed, 29 insertions(+), 14 deletions(-)

diff --git a/drivers/media/i2c/adv7842.c b/drivers/media/i2c/adv7842.c
index 4f93526..d350c86 100644
--- a/drivers/media/i2c/adv7842.c
+++ b/drivers/media/i2c/adv7842.c
@@ -1056,12 +1056,22 @@ static void set_rgb_quantization_range(struct v4l2_subdev *sd)
 		}
 		break;
 	case V4L2_DV_RGB_RANGE_LIMITED:
-		/* RGB limited range (16-235) */
-		io_write_and_or(sd, 0x02, 0x0f, 0x00);
+		if (state->mode == ADV7842_MODE_COMP) {
+			/* YCrCb limited range (16-235) */
+			io_write_and_or(sd, 0x02, 0x0f, 0x20);
+		} else {
+			/* RGB limited range (16-235) */
+			io_write_and_or(sd, 0x02, 0x0f, 0x00);
+		}
 		break;
 	case V4L2_DV_RGB_RANGE_FULL:
-		/* RGB full range (0-255) */
-		io_write_and_or(sd, 0x02, 0x0f, 0x10);
+		if (state->mode == ADV7842_MODE_COMP) {
+			/* YCrCb full range (0-255) */
+			io_write_and_or(sd, 0x02, 0x0f, 0x60);
+		} else {
+			/* RGB full range (0-255) */
+			io_write_and_or(sd, 0x02, 0x0f, 0x10);
+		}
 		break;
 	}
 }
@@ -1586,6 +1596,13 @@ static void select_input(struct v4l2_subdev *sd,
 
 		afe_write(sd, 0x00, 0x00); /* power up ADC */
 		afe_write(sd, 0xc8, 0x00); /* phase control */
+		if (state->mode == ADV7842_MODE_COMP) {
+			/* force to YCrCb */
+			io_write_and_or(sd, 0x02, 0x0f, 0x60);
+		} else {
+			/* force to RGB */
+			io_write_and_or(sd, 0x02, 0x0f, 0x10);
+		}
 
 		/* set ADI recommended settings for digitizer */
 		/* "ADV7842 Register Settings Recommendations
@@ -1681,19 +1698,19 @@ static int adv7842_s_routing(struct v4l2_subdev *sd,
 
 	switch (input) {
 	case ADV7842_SELECT_HDMI_PORT_A:
-		/* TODO select HDMI_COMP or HDMI_GR */
 		state->mode = ADV7842_MODE_HDMI;
 		state->vid_std_select = ADV7842_HDMI_COMP_VID_STD_HD_1250P;
 		state->hdmi_port_a = true;
 		break;
 	case ADV7842_SELECT_HDMI_PORT_B:
-		/* TODO select HDMI_COMP or HDMI_GR */
 		state->mode = ADV7842_MODE_HDMI;
 		state->vid_std_select = ADV7842_HDMI_COMP_VID_STD_HD_1250P;
 		state->hdmi_port_a = false;
 		break;
 	case ADV7842_SELECT_VGA_COMP:
-		v4l2_info(sd, "%s: VGA component: todo\n", __func__);
+		state->mode = ADV7842_MODE_COMP;
+		state->vid_std_select = ADV7842_RGB_VID_STD_AUTO_GRAPH_MODE;
+		break;
 	case ADV7842_SELECT_VGA_RGB:
 		state->mode = ADV7842_MODE_RGB;
 		state->vid_std_select = ADV7842_RGB_VID_STD_AUTO_GRAPH_MODE;
@@ -2341,9 +2358,10 @@ static int adv7842_g_std(struct v4l2_subdev *sd, v4l2_std_id *norm)
 
 /* ----------------------------------------------------------------------- */
 
-static int adv7842_core_init(struct v4l2_subdev *sd,
-		const struct adv7842_platform_data *pdata)
+static int adv7842_core_init(struct v4l2_subdev *sd)
 {
+	struct adv7842_state *state = to_state(sd);
+	struct adv7842_platform_data *pdata = &state->pdata;
 	hdmi_write(sd, 0x48,
 		   (pdata->disable_pwrdnb ? 0x80 : 0) |
 		   (pdata->disable_cable_det_rst ? 0x40 : 0));
@@ -2356,7 +2374,7 @@ static int adv7842_core_init(struct v4l2_subdev *sd,
 
 	/* video format */
 	io_write(sd, 0x02,
-		 pdata->inp_color_space << 4 |
+		 0xf0 |
 		 pdata->alt_gamma << 3 |
 		 pdata->op_656_range << 2 |
 		 pdata->rgb_out << 1 |
@@ -2566,7 +2584,7 @@ static int adv7842_command_ram_test(struct v4l2_subdev *sd)
 	adv7842_rewrite_i2c_addresses(sd, pdata);
 
 	/* and re-init chip and state */
-	adv7842_core_init(sd, pdata);
+	adv7842_core_init(sd);
 
 	disable_input(sd);
 
diff --git a/include/media/adv7842.h b/include/media/adv7842.h
index c02201d..b0cfc5f 100644
--- a/include/media/adv7842.h
+++ b/include/media/adv7842.h
@@ -159,9 +159,6 @@ struct adv7842_platform_data {
 	/* Video standard */
 	enum adv7842_vid_std_select vid_std_select;
 
-	/* Input Color Space */
-	enum adv7842_inp_color_space inp_color_space;
-
 	/* Select output format */
 	enum adv7842_op_format_sel op_format_sel;
 
-- 
1.8.4.rc3


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [RFC PATCH 06/22] adv7842: added DE vertical position in SDP-io-sync
  2013-12-10 15:03 ` [RFC PATCH 01/22] adv7842: Re-worked query_dv_timings() Hans Verkuil
                     ` (3 preceding siblings ...)
  2013-12-10 15:03   ` [RFC PATCH 05/22] adv7842: support YCrCb analog input Hans Verkuil
@ 2013-12-10 15:03   ` Hans Verkuil
  2013-12-10 15:03   ` [RFC PATCH 07/22] adv7842: Receive CEA formats as RGB on VGA (RGB) input Hans Verkuil
                     ` (15 subsequent siblings)
  20 siblings, 0 replies; 27+ messages in thread
From: Hans Verkuil @ 2013-12-10 15:03 UTC (permalink / raw)
  To: linux-media; +Cc: Martin Bugge, Hans Verkuil

From: Martin Bugge <marbugge@cisco.com>

Signed-off-by: Martin Bugge <marbugge@cisco.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/i2c/adv7842.c | 4 ++++
 include/media/adv7842.h     | 4 ++++
 2 files changed, 8 insertions(+)

diff --git a/drivers/media/i2c/adv7842.c b/drivers/media/i2c/adv7842.c
index d350c86..828fd23 100644
--- a/drivers/media/i2c/adv7842.c
+++ b/drivers/media/i2c/adv7842.c
@@ -2415,6 +2415,10 @@ static int adv7842_core_init(struct v4l2_subdev *sd)
 		sdp_io_write(sd, 0x99, s->de_beg & 0xff);
 		sdp_io_write(sd, 0x9a, (s->de_end>>8) & 0xf);
 		sdp_io_write(sd, 0x9b, s->de_end & 0xff);
+		sdp_io_write(sd, 0xac, s->de_v_beg_o);
+		sdp_io_write(sd, 0xad, s->de_v_beg_e);
+		sdp_io_write(sd, 0xae, s->de_v_end_o);
+		sdp_io_write(sd, 0xaf, s->de_v_end_e);
 	}
 
 	/* todo, improve settings for sdram */
diff --git a/include/media/adv7842.h b/include/media/adv7842.h
index b0cfc5f..f4e9d0d 100644
--- a/include/media/adv7842.h
+++ b/include/media/adv7842.h
@@ -131,6 +131,10 @@ struct adv7842_sdp_io_sync_adjustment {
 	uint16_t hs_width;
 	uint16_t de_beg;
 	uint16_t de_end;
+	uint8_t de_v_beg_o;
+	uint8_t de_v_beg_e;
+	uint8_t de_v_end_o;
+	uint8_t de_v_end_e;
 };
 
 /* Platform dependent definition */
-- 
1.8.4.rc3


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [RFC PATCH 07/22] adv7842: Receive CEA formats as RGB on VGA (RGB) input
  2013-12-10 15:03 ` [RFC PATCH 01/22] adv7842: Re-worked query_dv_timings() Hans Verkuil
                     ` (4 preceding siblings ...)
  2013-12-10 15:03   ` [RFC PATCH 06/22] adv7842: added DE vertical position in SDP-io-sync Hans Verkuil
@ 2013-12-10 15:03   ` Hans Verkuil
  2013-12-10 15:03   ` [RFC PATCH 08/22] adv7842: set defaults spa-location Hans Verkuil
                     ` (14 subsequent siblings)
  20 siblings, 0 replies; 27+ messages in thread
From: Hans Verkuil @ 2013-12-10 15:03 UTC (permalink / raw)
  To: linux-media; +Cc: Mats Randgaard, Hans Verkuil

From: Mats Randgaard <matrandg@cisco.com>

If input is ADV7842_MODE_RGB and RGB quantization range is set to
V4L2_DV_RGB_RANGE_AUTO, then video with CEA timings will be received
as RGB. For ADV7842_MODE_COMP, automatic CSC mode will be selected.

See table 48 on page 281 in "ADV7842 Hardware Manual, Rev. 0, January 2011"
for details.

Signed-off-by: Mats Randgaard <matrandg@cisco.com>
Reviewed-by: Martin Bugge <marbugge@cisco.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/i2c/adv7842.c | 52 +++++++++++++++++++++++++++++----------------
 1 file changed, 34 insertions(+), 18 deletions(-)

diff --git a/drivers/media/i2c/adv7842.c b/drivers/media/i2c/adv7842.c
index 828fd23..59e7ef5 100644
--- a/drivers/media/i2c/adv7842.c
+++ b/drivers/media/i2c/adv7842.c
@@ -1034,25 +1034,41 @@ static void set_rgb_quantization_range(struct v4l2_subdev *sd)
 {
 	struct adv7842_state *state = to_state(sd);
 
+	v4l2_dbg(2, debug, sd, "%s: rgb_quantization_range = %d\n",
+		       __func__, state->rgb_quantization_range);
+
 	switch (state->rgb_quantization_range) {
 	case V4L2_DV_RGB_RANGE_AUTO:
-		/* automatic */
-		if (is_digital_input(sd) && !(hdmi_read(sd, 0x05) & 0x80)) {
-			/* receiving DVI-D signal */
-
-			/* ADV7842 selects RGB limited range regardless of
-			   input format (CE/IT) in automatic mode */
-			if (state->timings.bt.standards & V4L2_DV_BT_STD_CEA861) {
-				/* RGB limited range (16-235) */
-				io_write_and_or(sd, 0x02, 0x0f, 0x00);
-
-			} else {
-				/* RGB full range (0-255) */
-				io_write_and_or(sd, 0x02, 0x0f, 0x10);
-			}
-		} else {
-			/* receiving HDMI or analog signal, set automode */
+		if (state->mode == ADV7842_MODE_RGB) {
+			/* Receiving analog RGB signal
+			 * Set RGB full range (0-255) */
+			io_write_and_or(sd, 0x02, 0x0f, 0x10);
+			break;
+		}
+
+		if (state->mode == ADV7842_MODE_COMP) {
+			/* Receiving analog YPbPr signal
+			 * Set automode */
 			io_write_and_or(sd, 0x02, 0x0f, 0xf0);
+			break;
+		}
+
+		if (hdmi_read(sd, 0x05) & 0x80) {
+			/* Receiving HDMI signal
+			 * Set automode */
+			io_write_and_or(sd, 0x02, 0x0f, 0xf0);
+			break;
+		}
+
+		/* Receiving DVI-D signal
+		 * ADV7842 selects RGB limited range regardless of
+		 * input format (CE/IT) in automatic mode */
+		if (state->timings.bt.standards & V4L2_DV_BT_STD_CEA861) {
+			/* RGB limited range (16-235) */
+			io_write_and_or(sd, 0x02, 0x0f, 0x00);
+		} else {
+			/* RGB full range (0-255) */
+			io_write_and_or(sd, 0x02, 0x0f, 0x10);
 		}
 		break;
 	case V4L2_DV_RGB_RANGE_LIMITED:
@@ -1309,7 +1325,7 @@ static int adv7842_dv_timings_cap(struct v4l2_subdev *sd,
 }
 
 /* Fill the optional fields .standards and .flags in struct v4l2_dv_timings
-   if the format is listed in adv7604_timings[] */
+   if the format is listed in adv7842_timings[] */
 static void adv7842_fill_optional_dv_timings_fields(struct v4l2_subdev *sd,
 		struct v4l2_dv_timings *timings)
 {
@@ -2129,7 +2145,7 @@ static int adv7842_cp_log_status(struct v4l2_subdev *sd)
 	static const char * const input_color_space_txt[16] = {
 		"RGB limited range (16-235)", "RGB full range (0-255)",
 		"YCbCr Bt.601 (16-235)", "YCbCr Bt.709 (16-235)",
-		"XvYCC Bt.601", "XvYCC Bt.709",
+		"xvYCC Bt.601", "xvYCC Bt.709",
 		"YCbCr Bt.601 (0-255)", "YCbCr Bt.709 (0-255)",
 		"invalid", "invalid", "invalid", "invalid", "invalid",
 		"invalid", "invalid", "automatic"
-- 
1.8.4.rc3


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [RFC PATCH 08/22] adv7842: set defaults spa-location.
  2013-12-10 15:03 ` [RFC PATCH 01/22] adv7842: Re-worked query_dv_timings() Hans Verkuil
                     ` (5 preceding siblings ...)
  2013-12-10 15:03   ` [RFC PATCH 07/22] adv7842: Receive CEA formats as RGB on VGA (RGB) input Hans Verkuil
@ 2013-12-10 15:03   ` Hans Verkuil
  2013-12-10 15:03   ` [RFC PATCH 09/22] adv7842: 625/525 line standard jitter fix Hans Verkuil
                     ` (13 subsequent siblings)
  20 siblings, 0 replies; 27+ messages in thread
From: Hans Verkuil @ 2013-12-10 15:03 UTC (permalink / raw)
  To: linux-media; +Cc: Martin Bugge, Mats Randgaard, Hans Verkuil

From: Martin Bugge <marbugge@cisco.com>

For edid with no Source Physical Address (spa), set
spa-location to default and use correct values from edid.

Signed-off-by: Martin Bugge <marbugge@cisco.com>
Cc: Mats Randgaard <matrandg@cisco.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/i2c/adv7842.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/media/i2c/adv7842.c b/drivers/media/i2c/adv7842.c
index 59e7ef5..6335d9f 100644
--- a/drivers/media/i2c/adv7842.c
+++ b/drivers/media/i2c/adv7842.c
@@ -716,15 +716,15 @@ static int edid_write_hdmi_segment(struct v4l2_subdev *sd, u8 port)
 		}
 		rep_write(sd, 0x76, spa_loc);
 	} else {
-		/* default register values for SPA */
+		/* Edid values for SPA location */
 		if (port == 0) {
-			/* port A SPA */
-			rep_write(sd, 0x72, 0);
-			rep_write(sd, 0x73, 0);
+			/* port A */
+			rep_write(sd, 0x72, val[0xc0]);
+			rep_write(sd, 0x73, val[0xc1]);
 		} else {
-			/* port B SPA */
-			rep_write(sd, 0x74, 0);
-			rep_write(sd, 0x75, 0);
+			/* port B */
+			rep_write(sd, 0x74, val[0xc0]);
+			rep_write(sd, 0x75, val[0xc1]);
 		}
 		rep_write(sd, 0x76, 0xc0);
 	}
-- 
1.8.4.rc3


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [RFC PATCH 09/22] adv7842: 625/525 line standard jitter fix.
  2013-12-10 15:03 ` [RFC PATCH 01/22] adv7842: Re-worked query_dv_timings() Hans Verkuil
                     ` (6 preceding siblings ...)
  2013-12-10 15:03   ` [RFC PATCH 08/22] adv7842: set defaults spa-location Hans Verkuil
@ 2013-12-10 15:03   ` Hans Verkuil
  2013-12-10 15:03   ` [RFC PATCH 10/22] adv7842: set default input in platform-data Hans Verkuil
                     ` (12 subsequent siblings)
  20 siblings, 0 replies; 27+ messages in thread
From: Hans Verkuil @ 2013-12-10 15:03 UTC (permalink / raw)
  To: linux-media; +Cc: Martin Bugge, Hans Verkuil

From: Martin Bugge <marbugge@cisco.com>

Both the PAL and NTSC standards are interlaced where a
frame consist of two fields. Total number of lines in a frame in both systems
are an odd number so the two fields will have different length.

In the 625 line standard ("PAL") the odd field of the frame is transmitted first,
while in the 525 standard ("NTSC") the even field is transmitted first.

This adds the possibility to change output config between the fields and standards.

This setting will reduce the "format-jitter" on the signal sent by the pixelport
moving the difference between the fields to vertical front/back-porch only.

Signed-off-by: Martin Bugge <marbugge@cisco.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/i2c/adv7842.c | 56 ++++++++++++++++++++++++++++++++-------------
 include/media/adv7842.h     |  3 ++-
 2 files changed, 42 insertions(+), 17 deletions(-)

diff --git a/drivers/media/i2c/adv7842.c b/drivers/media/i2c/adv7842.c
index 6335d9f..3e8d7cc 100644
--- a/drivers/media/i2c/adv7842.c
+++ b/drivers/media/i2c/adv7842.c
@@ -2343,15 +2343,55 @@ static int adv7842_querystd(struct v4l2_subdev *sd, v4l2_std_id *std)
 	return 0;
 }
 
+static void adv7842_s_sdp_io(struct v4l2_subdev *sd, struct adv7842_sdp_io_sync_adjustment *s)
+{
+	if (s && s->adjust) {
+		sdp_io_write(sd, 0x94, (s->hs_beg >> 8) & 0xf);
+		sdp_io_write(sd, 0x95, s->hs_beg & 0xff);
+		sdp_io_write(sd, 0x96, (s->hs_width >> 8) & 0xf);
+		sdp_io_write(sd, 0x97, s->hs_width & 0xff);
+		sdp_io_write(sd, 0x98, (s->de_beg >> 8) & 0xf);
+		sdp_io_write(sd, 0x99, s->de_beg & 0xff);
+		sdp_io_write(sd, 0x9a, (s->de_end >> 8) & 0xf);
+		sdp_io_write(sd, 0x9b, s->de_end & 0xff);
+		sdp_io_write(sd, 0xac, s->de_v_beg_o);
+		sdp_io_write(sd, 0xad, s->de_v_beg_e);
+		sdp_io_write(sd, 0xae, s->de_v_end_o);
+		sdp_io_write(sd, 0xaf, s->de_v_end_e);
+	} else {
+		/* set to default */
+		sdp_io_write(sd, 0x94, 0x00);
+		sdp_io_write(sd, 0x95, 0x00);
+		sdp_io_write(sd, 0x96, 0x00);
+		sdp_io_write(sd, 0x97, 0x20);
+		sdp_io_write(sd, 0x98, 0x00);
+		sdp_io_write(sd, 0x99, 0x00);
+		sdp_io_write(sd, 0x9a, 0x00);
+		sdp_io_write(sd, 0x9b, 0x00);
+		sdp_io_write(sd, 0xac, 0x04);
+		sdp_io_write(sd, 0xad, 0x04);
+		sdp_io_write(sd, 0xae, 0x04);
+		sdp_io_write(sd, 0xaf, 0x04);
+	}
+}
+
 static int adv7842_s_std(struct v4l2_subdev *sd, v4l2_std_id norm)
 {
 	struct adv7842_state *state = to_state(sd);
+	struct adv7842_platform_data *pdata = &state->pdata;
 
 	v4l2_dbg(1, debug, sd, "%s:\n", __func__);
 
 	if (state->mode != ADV7842_MODE_SDP)
 		return -ENODATA;
 
+	if (norm & V4L2_STD_625_50)
+		adv7842_s_sdp_io(sd, &pdata->sdp_io_sync_625);
+	else if (norm & V4L2_STD_525_60)
+		adv7842_s_sdp_io(sd, &pdata->sdp_io_sync_525);
+	else
+		adv7842_s_sdp_io(sd, NULL);
+
 	if (norm & V4L2_STD_ALL) {
 		state->norm = norm;
 		return 0;
@@ -2421,22 +2461,6 @@ static int adv7842_core_init(struct v4l2_subdev *sd)
 
 	sdp_csc_coeff(sd, &pdata->sdp_csc_coeff);
 
-	if (pdata->sdp_io_sync.adjust) {
-		const struct adv7842_sdp_io_sync_adjustment *s = &pdata->sdp_io_sync;
-		sdp_io_write(sd, 0x94, (s->hs_beg>>8) & 0xf);
-		sdp_io_write(sd, 0x95, s->hs_beg & 0xff);
-		sdp_io_write(sd, 0x96, (s->hs_width>>8) & 0xf);
-		sdp_io_write(sd, 0x97, s->hs_width & 0xff);
-		sdp_io_write(sd, 0x98, (s->de_beg>>8) & 0xf);
-		sdp_io_write(sd, 0x99, s->de_beg & 0xff);
-		sdp_io_write(sd, 0x9a, (s->de_end>>8) & 0xf);
-		sdp_io_write(sd, 0x9b, s->de_end & 0xff);
-		sdp_io_write(sd, 0xac, s->de_v_beg_o);
-		sdp_io_write(sd, 0xad, s->de_v_beg_e);
-		sdp_io_write(sd, 0xae, s->de_v_end_o);
-		sdp_io_write(sd, 0xaf, s->de_v_end_e);
-	}
-
 	/* todo, improve settings for sdram */
 	if (pdata->sd_ram_size >= 128) {
 		sdp_write(sd, 0x12, 0x0d); /* Frame TBC,3D comb enabled */
diff --git a/include/media/adv7842.h b/include/media/adv7842.h
index f4e9d0d..5327ba3 100644
--- a/include/media/adv7842.h
+++ b/include/media/adv7842.h
@@ -197,7 +197,8 @@ struct adv7842_platform_data {
 
 	struct adv7842_sdp_csc_coeff sdp_csc_coeff;
 
-	struct adv7842_sdp_io_sync_adjustment sdp_io_sync;
+	struct adv7842_sdp_io_sync_adjustment sdp_io_sync_625;
+	struct adv7842_sdp_io_sync_adjustment sdp_io_sync_525;
 
 	/* i2c addresses */
 	u8 i2c_sdp_io;
-- 
1.8.4.rc3


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [RFC PATCH 10/22] adv7842: set default input in platform-data
  2013-12-10 15:03 ` [RFC PATCH 01/22] adv7842: Re-worked query_dv_timings() Hans Verkuil
                     ` (7 preceding siblings ...)
  2013-12-10 15:03   ` [RFC PATCH 09/22] adv7842: 625/525 line standard jitter fix Hans Verkuil
@ 2013-12-10 15:03   ` Hans Verkuil
  2013-12-10 15:03   ` [RFC PATCH 11/22] adv7842: increase wait time Hans Verkuil
                     ` (11 subsequent siblings)
  20 siblings, 0 replies; 27+ messages in thread
From: Hans Verkuil @ 2013-12-10 15:03 UTC (permalink / raw)
  To: linux-media; +Cc: Martin Bugge, Hans Verkuil

From: Martin Bugge <marbugge@cisco.com>

Signed-off-by: Martin Bugge <marbugge@cisco.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/i2c/adv7842.c | 2 +-
 include/media/adv7842.h     | 3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/media/i2c/adv7842.c b/drivers/media/i2c/adv7842.c
index 3e8d7cc..4fa2e23 100644
--- a/drivers/media/i2c/adv7842.c
+++ b/drivers/media/i2c/adv7842.c
@@ -2802,7 +2802,7 @@ static int adv7842_probe(struct i2c_client *client,
 	state->connector_hdmi = pdata->connector_hdmi;
 	state->mode = pdata->mode;
 
-	state->hdmi_port_a = true;
+	state->hdmi_port_a = pdata->input == ADV7842_SELECT_HDMI_PORT_A;
 
 	/* i2c access to adv7842? */
 	rev = adv_smbus_read_byte_data_check(client, 0xea, false) << 8 |
diff --git a/include/media/adv7842.h b/include/media/adv7842.h
index 5327ba3..c12de2d 100644
--- a/include/media/adv7842.h
+++ b/include/media/adv7842.h
@@ -160,6 +160,9 @@ struct adv7842_platform_data {
 	/* Default mode */
 	enum adv7842_mode mode;
 
+	/* Default input */
+	unsigned input;
+
 	/* Video standard */
 	enum adv7842_vid_std_select vid_std_select;
 
-- 
1.8.4.rc3


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [RFC PATCH 11/22] adv7842: increase wait time.
  2013-12-10 15:03 ` [RFC PATCH 01/22] adv7842: Re-worked query_dv_timings() Hans Verkuil
                     ` (8 preceding siblings ...)
  2013-12-10 15:03   ` [RFC PATCH 10/22] adv7842: set default input in platform-data Hans Verkuil
@ 2013-12-10 15:03   ` Hans Verkuil
  2013-12-10 15:03   ` [RFC PATCH 12/22] adv7842: remove connector type. Never used for anything useful Hans Verkuil
                     ` (10 subsequent siblings)
  20 siblings, 0 replies; 27+ messages in thread
From: Hans Verkuil @ 2013-12-10 15:03 UTC (permalink / raw)
  To: linux-media; +Cc: Martin Bugge, Hans Verkuil

From: Martin Bugge <marbugge@cisco.com>

Wait 5ms after main reset. The data-sheet doesn't specify the wait
after i2c-controlled reset, so using same value as after pin-controlled
reset.

Signed-off-by: Martin Bugge <marbugge@cisco.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/i2c/adv7842.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/i2c/adv7842.c b/drivers/media/i2c/adv7842.c
index 4fa2e23..60f2320 100644
--- a/drivers/media/i2c/adv7842.c
+++ b/drivers/media/i2c/adv7842.c
@@ -533,7 +533,7 @@ static void main_reset(struct v4l2_subdev *sd)
 
 	adv_smbus_write_byte_no_check(client, 0xff, 0x80);
 
-	mdelay(2);
+	mdelay(5);
 }
 
 /* ----------------------------------------------------------------------- */
-- 
1.8.4.rc3


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [RFC PATCH 12/22] adv7842: remove connector type. Never used for anything useful
  2013-12-10 15:03 ` [RFC PATCH 01/22] adv7842: Re-worked query_dv_timings() Hans Verkuil
                     ` (9 preceding siblings ...)
  2013-12-10 15:03   ` [RFC PATCH 11/22] adv7842: increase wait time Hans Verkuil
@ 2013-12-10 15:03   ` Hans Verkuil
  2013-12-10 15:03   ` [RFC PATCH 13/22] adv7842: Use defines to select EDID port Hans Verkuil
                     ` (9 subsequent siblings)
  20 siblings, 0 replies; 27+ messages in thread
From: Hans Verkuil @ 2013-12-10 15:03 UTC (permalink / raw)
  To: linux-media; +Cc: Mats Randgaard, Hans Verkuil

From: Mats Randgaard <matrandg@cisco.com>

May also be wrong if the receiver is connected to more than one connector.

Signed-off-by: Mats Randgaard <matrandg@cisco.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/i2c/adv7842.c | 4 ----
 include/media/adv7842.h     | 3 ---
 2 files changed, 7 deletions(-)

diff --git a/drivers/media/i2c/adv7842.c b/drivers/media/i2c/adv7842.c
index 60f2320..8e75c3b 100644
--- a/drivers/media/i2c/adv7842.c
+++ b/drivers/media/i2c/adv7842.c
@@ -82,7 +82,6 @@ struct adv7842_state {
 	bool is_cea_format;
 	struct workqueue_struct *work_queues;
 	struct delayed_work delayed_work_enable_hotplug;
-	bool connector_hdmi;
 	bool hdmi_port_a;
 
 	/* i2c clients */
@@ -2164,8 +2163,6 @@ static int adv7842_cp_log_status(struct v4l2_subdev *sd)
 
 	v4l2_info(sd, "-----Chip status-----\n");
 	v4l2_info(sd, "Chip power: %s\n", no_power(sd) ? "off" : "on");
-	v4l2_info(sd, "Connector type: %s\n", state->connector_hdmi ?
-			"HDMI" : (is_digital_input(sd) ? "DVI-D" : "DVI-A"));
 	v4l2_info(sd, "HDMI/DVI-D port selected: %s\n",
 			state->hdmi_port_a ? "A" : "B");
 	v4l2_info(sd, "EDID A %s, B %s\n",
@@ -2799,7 +2796,6 @@ static int adv7842_probe(struct i2c_client *client,
 	sd = &state->sd;
 	v4l2_i2c_subdev_init(sd, client, &adv7842_ops);
 	sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
-	state->connector_hdmi = pdata->connector_hdmi;
 	state->mode = pdata->mode;
 
 	state->hdmi_port_a = pdata->input == ADV7842_SELECT_HDMI_PORT_A;
diff --git a/include/media/adv7842.h b/include/media/adv7842.h
index c12de2d..24fed11 100644
--- a/include/media/adv7842.h
+++ b/include/media/adv7842.h
@@ -139,9 +139,6 @@ struct adv7842_sdp_io_sync_adjustment {
 
 /* Platform dependent definition */
 struct adv7842_platform_data {
-	/* connector - HDMI or DVI? */
-	unsigned connector_hdmi:1;
-
 	/* chip reset during probe */
 	unsigned chip_reset:1;
 
-- 
1.8.4.rc3


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [RFC PATCH 13/22] adv7842: Use defines to select EDID port
  2013-12-10 15:03 ` [RFC PATCH 01/22] adv7842: Re-worked query_dv_timings() Hans Verkuil
                     ` (10 preceding siblings ...)
  2013-12-10 15:03   ` [RFC PATCH 12/22] adv7842: remove connector type. Never used for anything useful Hans Verkuil
@ 2013-12-10 15:03   ` Hans Verkuil
  2013-12-10 15:04   ` [RFC PATCH 14/22] adv7842: mute audio before switching inputs to avoid noise/pops Hans Verkuil
                     ` (8 subsequent siblings)
  20 siblings, 0 replies; 27+ messages in thread
From: Hans Verkuil @ 2013-12-10 15:03 UTC (permalink / raw)
  To: linux-media; +Cc: Mats Randgaard, Hans Verkuil

From: Mats Randgaard <matrandg@cisco.com>

Signed-off-by: Mats Randgaard <matrandg@cisco.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/i2c/adv7842.c | 77 ++++++++++++++++++++-------------------------
 include/media/adv7842.h     |  4 +++
 2 files changed, 38 insertions(+), 43 deletions(-)

diff --git a/drivers/media/i2c/adv7842.c b/drivers/media/i2c/adv7842.c
index 8e75c3b..77b1696 100644
--- a/drivers/media/i2c/adv7842.c
+++ b/drivers/media/i2c/adv7842.c
@@ -22,8 +22,8 @@
  * References (c = chapter, p = page):
  * REF_01 - Analog devices, ADV7842, Register Settings Recommendations,
  *		Revision 2.5, June 2010
- * REF_02 - Analog devices, Register map documentation, Documentation of
- *		the register maps, Software manual, Rev. F, June 2010
+ * REF_02 - Analog devices, Software User Guide, UG-206,
+ *		ADV7842 I2C Register Maps, Rev. 0, November 2010
  */
 
 
@@ -587,10 +587,10 @@ static void adv7842_delayed_work_enable_hotplug(struct work_struct *work)
 	v4l2_dbg(2, debug, sd, "%s: enable hotplug on ports: 0x%x\n",
 			__func__, present);
 
-	if (present & 0x1)
-		mask |= 0x20; /* port A */
-	if (present & 0x2)
-		mask |= 0x10; /* port B */
+	if (present & (0x04 << ADV7842_EDID_PORT_A))
+		mask |= 0x20;
+	if (present & (0x04 << ADV7842_EDID_PORT_B))
+		mask |= 0x10;
 	io_write_and_or(sd, 0x20, 0xcf, mask);
 }
 
@@ -679,14 +679,12 @@ static int edid_write_hdmi_segment(struct v4l2_subdev *sd, u8 port)
 	struct i2c_client *client = v4l2_get_subdevdata(sd);
 	struct adv7842_state *state = to_state(sd);
 	const u8 *val = state->hdmi_edid.edid;
-	u8 cur_mask = rep_read(sd, 0x77) & 0x0c;
-	u8 mask = port == 0 ? 0x4 : 0x8;
 	int spa_loc = edid_spa_location(val);
 	int err = 0;
 	int i;
 
-	v4l2_dbg(2, debug, sd, "%s: write EDID on port %d (spa at 0x%x)\n",
-			__func__, port, spa_loc);
+	v4l2_dbg(2, debug, sd, "%s: write EDID on port %c (spa at 0x%x)\n",
+			__func__, (port == ADV7842_EDID_PORT_A) ? 'A' : 'B', spa_loc);
 
 	/* HPA disable on port A and B */
 	io_write_and_or(sd, 0x20, 0xcf, 0x00);
@@ -703,44 +701,32 @@ static int edid_write_hdmi_segment(struct v4l2_subdev *sd, u8 port)
 	if (err)
 		return err;
 
-	if (spa_loc > 0) {
-		if (port == 0) {
-			/* port A SPA */
-			rep_write(sd, 0x72, val[spa_loc]);
-			rep_write(sd, 0x73, val[spa_loc + 1]);
-		} else {
-			/* port B SPA */
-			rep_write(sd, 0x74, val[spa_loc]);
-			rep_write(sd, 0x75, val[spa_loc + 1]);
-		}
-		rep_write(sd, 0x76, spa_loc);
+	if (spa_loc < 0)
+		spa_loc = 0xc0; /* Default value [REF_02, p. 199] */
+
+	if (port == ADV7842_EDID_PORT_A) {
+		rep_write(sd, 0x72, val[spa_loc]);
+		rep_write(sd, 0x73, val[spa_loc + 1]);
 	} else {
-		/* Edid values for SPA location */
-		if (port == 0) {
-			/* port A */
-			rep_write(sd, 0x72, val[0xc0]);
-			rep_write(sd, 0x73, val[0xc1]);
-		} else {
-			/* port B */
-			rep_write(sd, 0x74, val[0xc0]);
-			rep_write(sd, 0x75, val[0xc1]);
-		}
-		rep_write(sd, 0x76, 0xc0);
+		rep_write(sd, 0x74, val[spa_loc]);
+		rep_write(sd, 0x75, val[spa_loc + 1]);
 	}
-	rep_write_and_or(sd, 0x77, 0xbf, 0x00);
+	rep_write(sd, 0x76, spa_loc & 0xff);
+	rep_write_and_or(sd, 0x77, 0xbf, (spa_loc >> 2) & 0x40);
 
 	/* Calculates the checksums and enables I2C access to internal
 	 * EDID ram from HDMI DDC ports
 	 */
-	rep_write_and_or(sd, 0x77, 0xf3, mask | cur_mask);
+	rep_write_and_or(sd, 0x77, 0xf3, state->hdmi_edid.present);
 
 	for (i = 0; i < 1000; i++) {
-		if (rep_read(sd, 0x7d) & mask)
+		if (rep_read(sd, 0x7d) & state->hdmi_edid.present)
 			break;
 		mdelay(1);
 	}
 	if (i == 1000) {
-		v4l_err(client, "error enabling edid on port %d\n", port);
+		v4l_err(client, "error enabling edid on port %c\n",
+				(port == ADV7842_EDID_PORT_A) ? 'A' : 'B');
 		return -EIO;
 	}
 
@@ -1886,7 +1872,7 @@ static int adv7842_set_edid(struct v4l2_subdev *sd, struct v4l2_subdev_edid *e)
 	struct adv7842_state *state = to_state(sd);
 	int err = 0;
 
-	if (e->pad > 2)
+	if (e->pad > ADV7842_EDID_PORT_VGA)
 		return -EINVAL;
 	if (e->start_block != 0)
 		return -EINVAL;
@@ -1899,20 +1885,25 @@ static int adv7842_set_edid(struct v4l2_subdev *sd, struct v4l2_subdev_edid *e)
 	state->aspect_ratio = v4l2_calc_aspect_ratio(e->edid[0x15],
 			e->edid[0x16]);
 
-	if (e->pad == 2) {
+	switch (e->pad) {
+	case ADV7842_EDID_PORT_VGA:
 		memset(&state->vga_edid.edid, 0, 256);
 		state->vga_edid.present = e->blocks ? 0x1 : 0x0;
 		memcpy(&state->vga_edid.edid, e->edid, 128 * e->blocks);
 		err = edid_write_vga_segment(sd);
-	} else {
-		u32 mask = 0x1<<e->pad;
+		break;
+	case ADV7842_EDID_PORT_A:
+	case ADV7842_EDID_PORT_B:
 		memset(&state->hdmi_edid.edid, 0, 256);
 		if (e->blocks)
-			state->hdmi_edid.present |= mask;
+			state->hdmi_edid.present |= 0x04 << e->pad;
 		else
-			state->hdmi_edid.present &= ~mask;
-		memcpy(&state->hdmi_edid.edid, e->edid, 128*e->blocks);
+			state->hdmi_edid.present &= ~(0x04 << e->pad);
+		memcpy(&state->hdmi_edid.edid, e->edid, 128 * e->blocks);
 		err = edid_write_hdmi_segment(sd, e->pad);
+		break;
+	default:
+		return -EINVAL;
 	}
 	if (err < 0)
 		v4l2_err(sd, "error %d writing edid on port %d\n", err, e->pad);
diff --git a/include/media/adv7842.h b/include/media/adv7842.h
index 24fed11..a4851bf 100644
--- a/include/media/adv7842.h
+++ b/include/media/adv7842.h
@@ -225,4 +225,8 @@ struct adv7842_platform_data {
  * deinterlacer. */
 #define ADV7842_CMD_RAM_TEST _IO('V', BASE_VIDIOC_PRIVATE)
 
+#define ADV7842_EDID_PORT_A   0
+#define ADV7842_EDID_PORT_B   1
+#define ADV7842_EDID_PORT_VGA 2
+
 #endif
-- 
1.8.4.rc3


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [RFC PATCH 14/22] adv7842: mute audio before switching inputs to avoid noise/pops
  2013-12-10 15:03 ` [RFC PATCH 01/22] adv7842: Re-worked query_dv_timings() Hans Verkuil
                     ` (11 preceding siblings ...)
  2013-12-10 15:03   ` [RFC PATCH 13/22] adv7842: Use defines to select EDID port Hans Verkuil
@ 2013-12-10 15:04   ` Hans Verkuil
  2013-12-10 15:04   ` [RFC PATCH 15/22] adv7842: clear edid, if no edid just disable Edid-DDC access Hans Verkuil
                     ` (7 subsequent siblings)
  20 siblings, 0 replies; 27+ messages in thread
From: Hans Verkuil @ 2013-12-10 15:04 UTC (permalink / raw)
  To: linux-media; +Cc: Mats Randgaard, Hans Verkuil

From: Mats Randgaard <matrandg@cisco.com>

Signed-off-by: Mats Randgaard <matrandg@cisco.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/i2c/adv7842.c | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/drivers/media/i2c/adv7842.c b/drivers/media/i2c/adv7842.c
index 77b1696..943e578 100644
--- a/drivers/media/i2c/adv7842.c
+++ b/drivers/media/i2c/adv7842.c
@@ -20,10 +20,13 @@
 
 /*
  * References (c = chapter, p = page):
- * REF_01 - Analog devices, ADV7842, Register Settings Recommendations,
- *		Revision 2.5, June 2010
+ * REF_01 - Analog devices, ADV7842,
+ *		Register Settings Recommendations, Rev. 1.9, April 2011
  * REF_02 - Analog devices, Software User Guide, UG-206,
  *		ADV7842 I2C Register Maps, Rev. 0, November 2010
+ * REF_03 - Analog devices, Hardware User Guide, UG-214,
+ *		ADV7842 Fast Switching 2:1 HDMI 1.4 Receiver with 3D-Comb
+ *		Decoder and Digitizer , Rev. 0, January 2011
  */
 
 
@@ -491,6 +494,11 @@ static inline int hdmi_write(struct v4l2_subdev *sd, u8 reg, u8 val)
 	return adv_smbus_write_byte_data(state->i2c_hdmi, reg, val);
 }
 
+static inline int hdmi_write_and_or(struct v4l2_subdev *sd, u8 reg, u8 mask, u8 val)
+{
+	return hdmi_write(sd, reg, (hdmi_read(sd, reg) & mask) | val);
+}
+
 static inline int cp_read(struct v4l2_subdev *sd, u8 reg)
 {
 	struct adv7842_state *state = to_state(sd);
@@ -1457,14 +1465,12 @@ static void enable_input(struct v4l2_subdev *sd)
 	case ADV7842_MODE_SDP:
 	case ADV7842_MODE_COMP:
 	case ADV7842_MODE_RGB:
-		/* enable */
 		io_write(sd, 0x15, 0xb0);   /* Disable Tristate of Pins (no audio) */
 		break;
 	case ADV7842_MODE_HDMI:
-		/* enable */
-		hdmi_write(sd, 0x1a, 0x0a); /* Unmute audio */
 		hdmi_write(sd, 0x01, 0x00); /* Enable HDMI clock terminators */
 		io_write(sd, 0x15, 0xa0);   /* Disable Tristate of Pins */
+		hdmi_write_and_or(sd, 0x1a, 0xef, 0x00); /* Unmute audio */
 		break;
 	default:
 		v4l2_dbg(2, debug, sd, "%s: Unknown mode %d\n",
@@ -1475,9 +1481,9 @@ static void enable_input(struct v4l2_subdev *sd)
 
 static void disable_input(struct v4l2_subdev *sd)
 {
-	/* disable */
+	hdmi_write_and_or(sd, 0x1a, 0xef, 0x10); /* Mute audio [REF_01, c. 2.2.2] */
+	msleep(16); /* 512 samples with >= 32 kHz sample rate [REF_03, c. 8.29] */
 	io_write(sd, 0x15, 0xbe);   /* Tristate all outputs from video core */
-	hdmi_write(sd, 0x1a, 0x1a); /* Mute audio */
 	hdmi_write(sd, 0x01, 0x78); /* Disable HDMI clock terminators */
 }
 
@@ -2430,6 +2436,9 @@ static int adv7842_core_init(struct v4l2_subdev *sd)
 			pdata->replicate_av_codes << 1 |
 			pdata->invert_cbcr << 0);
 
+	/* HDMI audio */
+	hdmi_write_and_or(sd, 0x1a, 0xf1, 0x08); /* Wait 1 s before unmute */
+
 	/* Drive strength */
 	io_write_and_or(sd, 0x14, 0xc0, pdata->drive_strength.data<<4 |
 			pdata->drive_strength.clock<<2 |
-- 
1.8.4.rc3


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [RFC PATCH 15/22] adv7842: clear edid, if no edid just disable Edid-DDC access
  2013-12-10 15:03 ` [RFC PATCH 01/22] adv7842: Re-worked query_dv_timings() Hans Verkuil
                     ` (12 preceding siblings ...)
  2013-12-10 15:04   ` [RFC PATCH 14/22] adv7842: mute audio before switching inputs to avoid noise/pops Hans Verkuil
@ 2013-12-10 15:04   ` Hans Verkuil
  2013-12-10 15:04   ` [RFC PATCH 16/22] adv7842: restart STDI once if format is not found Hans Verkuil
                     ` (6 subsequent siblings)
  20 siblings, 0 replies; 27+ messages in thread
From: Hans Verkuil @ 2013-12-10 15:04 UTC (permalink / raw)
  To: linux-media; +Cc: Martin Bugge, Mats Randgaard, Hans Verkuil

From: Martin Bugge <marbugge@cisco.com>

Signed-off-by: Martin Bugge <marbugge@cisco.com>
Cc: Mats Randgaard <matrandg@cisco.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/i2c/adv7842.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/media/i2c/adv7842.c b/drivers/media/i2c/adv7842.c
index 943e578..bff8314 100644
--- a/drivers/media/i2c/adv7842.c
+++ b/drivers/media/i2c/adv7842.c
@@ -700,6 +700,9 @@ static int edid_write_hdmi_segment(struct v4l2_subdev *sd, u8 port)
 	/* Disable I2C access to internal EDID ram from HDMI DDC ports */
 	rep_write_and_or(sd, 0x77, 0xf3, 0x00);
 
+	if (!state->hdmi_edid.present)
+		return 0;
+
 	/* edid segment pointer '0' for HDMI ports */
 	rep_write_and_or(sd, 0x77, 0xef, 0x00);
 
@@ -2636,8 +2639,8 @@ static int adv7842_command_ram_test(struct v4l2_subdev *sd)
 	adv7842_s_dv_timings(sd, &state->timings);
 
 	edid_write_vga_segment(sd);
-	edid_write_hdmi_segment(sd, 0);
-	edid_write_hdmi_segment(sd, 1);
+	edid_write_hdmi_segment(sd, ADV7842_EDID_PORT_A);
+	edid_write_hdmi_segment(sd, ADV7842_EDID_PORT_B);
 
 	return ret;
 }
-- 
1.8.4.rc3


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [RFC PATCH 16/22] adv7842: restart STDI once if format is not found.
  2013-12-10 15:03 ` [RFC PATCH 01/22] adv7842: Re-worked query_dv_timings() Hans Verkuil
                     ` (13 preceding siblings ...)
  2013-12-10 15:04   ` [RFC PATCH 15/22] adv7842: clear edid, if no edid just disable Edid-DDC access Hans Verkuil
@ 2013-12-10 15:04   ` Hans Verkuil
  2013-12-10 15:04   ` [RFC PATCH 17/22] adv7842: support g_edid ioctl Hans Verkuil
                     ` (5 subsequent siblings)
  20 siblings, 0 replies; 27+ messages in thread
From: Hans Verkuil @ 2013-12-10 15:04 UTC (permalink / raw)
  To: linux-media; +Cc: Martin Bugge, Mats Randgaard, Hans Verkuil

From: Martin Bugge <marbugge@cisco.com>

The STDI block may measure wrong values, especially for lcvs and lcf.
If the driver can not find any valid timing, the STDI block is restarted
to measure the video timings again. The function will return an error,
but the restart of STDI will generate a new STDI interrupt and the format
detection process will restart.

Copied from adv7604.

Signed-off-by: Martin Bugge <marbugge@cisco.com>
Cc: Mats Randgaard <matrandg@cisco.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/i2c/adv7842.c | 49 +++++++++++++++++++++++++++++++++++++--------
 1 file changed, 41 insertions(+), 8 deletions(-)

diff --git a/drivers/media/i2c/adv7842.c b/drivers/media/i2c/adv7842.c
index bff8314..8390b93 100644
--- a/drivers/media/i2c/adv7842.c
+++ b/drivers/media/i2c/adv7842.c
@@ -85,6 +85,7 @@ struct adv7842_state {
 	bool is_cea_format;
 	struct workqueue_struct *work_queues;
 	struct delayed_work delayed_work_enable_hotplug;
+	bool restart_stdi_once;
 	bool hdmi_port_a;
 
 	/* i2c clients */
@@ -1345,6 +1346,7 @@ static int adv7842_query_dv_timings(struct v4l2_subdev *sd,
 
 	/* read STDI */
 	if (read_stdi(sd, &stdi)) {
+		state->restart_stdi_once = true;
 		v4l2_dbg(1, debug, sd, "%s: no valid signal\n", __func__);
 		return -ENOLINK;
 	}
@@ -1355,6 +1357,7 @@ static int adv7842_query_dv_timings(struct v4l2_subdev *sd,
 		uint32_t freq;
 
 		timings->type = V4L2_DV_BT_656_1120;
+
 		bt->width = (hdmi_read(sd, 0x07) & 0x0f) * 256 + hdmi_read(sd, 0x08);
 		bt->height = (hdmi_read(sd, 0x09) & 0x0f) * 256 + hdmi_read(sd, 0x0a);
 		freq = (hdmi_read(sd, 0x06) * 1000000) +
@@ -1391,21 +1394,50 @@ static int adv7842_query_dv_timings(struct v4l2_subdev *sd,
 		}
 		adv7842_fill_optional_dv_timings_fields(sd, timings);
 	} else {
-		/* Interlaced? */
-		if (stdi.interlaced) {
-			v4l2_dbg(1, debug, sd, "%s: interlaced video not supported\n", __func__);
-			return -ERANGE;
-		}
-
+		/* find format
+		 * Since LCVS values are inaccurate [REF_03, p. 339-340],
+		 * stdi2dv_timings() is called with lcvs +-1 if the first attempt fails.
+		 */
+		if (!stdi2dv_timings(sd, &stdi, timings))
+			goto found;
+		stdi.lcvs += 1;
+		v4l2_dbg(1, debug, sd, "%s: lcvs + 1 = %d\n", __func__, stdi.lcvs);
+		if (!stdi2dv_timings(sd, &stdi, timings))
+			goto found;
+		stdi.lcvs -= 2;
+		v4l2_dbg(1, debug, sd, "%s: lcvs - 1 = %d\n", __func__, stdi.lcvs);
 		if (stdi2dv_timings(sd, &stdi, timings)) {
+			/*
+			 * The STDI block may measure wrong values, especially
+			 * for lcvs and lcf. If the driver can not find any
+			 * valid timing, the STDI block is restarted to measure
+			 * the video timings again. The function will return an
+			 * error, but the restart of STDI will generate a new
+			 * STDI interrupt and the format detection process will
+			 * restart.
+			 */
+			if (state->restart_stdi_once) {
+				v4l2_dbg(1, debug, sd, "%s: restart STDI\n", __func__);
+				/* TODO restart STDI for Sync Channel 2 */
+				/* enter one-shot mode */
+				cp_write_and_or(sd, 0x86, 0xf9, 0x00);
+				/* trigger STDI restart */
+				cp_write_and_or(sd, 0x86, 0xf9, 0x04);
+				/* reset to continuous mode */
+				cp_write_and_or(sd, 0x86, 0xf9, 0x02);
+				state->restart_stdi_once = false;
+				return -ENOLINK;
+			}
 			v4l2_dbg(1, debug, sd, "%s: format not supported\n", __func__);
 			return -ERANGE;
 		}
+		state->restart_stdi_once = true;
 	}
+found:
 
 	if (debug > 1)
-		v4l2_print_dv_timings(sd->name, "adv7842_query_dv_timings: ",
-				      timings, true);
+		v4l2_print_dv_timings(sd->name, "adv7842_query_dv_timings:",
+				timings, true);
 	return 0;
 }
 
@@ -2802,6 +2834,7 @@ static int adv7842_probe(struct i2c_client *client,
 	state->mode = pdata->mode;
 
 	state->hdmi_port_a = pdata->input == ADV7842_SELECT_HDMI_PORT_A;
+	state->restart_stdi_once = true;
 
 	/* i2c access to adv7842? */
 	rev = adv_smbus_read_byte_data_check(client, 0xea, false) << 8 |
-- 
1.8.4.rc3


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [RFC PATCH 17/22] adv7842: support g_edid ioctl
  2013-12-10 15:03 ` [RFC PATCH 01/22] adv7842: Re-worked query_dv_timings() Hans Verkuil
                     ` (14 preceding siblings ...)
  2013-12-10 15:04   ` [RFC PATCH 16/22] adv7842: restart STDI once if format is not found Hans Verkuil
@ 2013-12-10 15:04   ` Hans Verkuil
  2013-12-10 15:04   ` [RFC PATCH 18/22] adv7842: i2c dummy clients registration Hans Verkuil
                     ` (4 subsequent siblings)
  20 siblings, 0 replies; 27+ messages in thread
From: Hans Verkuil @ 2013-12-10 15:04 UTC (permalink / raw)
  To: linux-media; +Cc: Martin Bugge, Hans Verkuil

From: Martin Bugge <marbugge@cisco.com>

Signed-off-by: Martin Bugge <marbugge@cisco.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/i2c/adv7842.c | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/drivers/media/i2c/adv7842.c b/drivers/media/i2c/adv7842.c
index 8390b93..c3ac4e9 100644
--- a/drivers/media/i2c/adv7842.c
+++ b/drivers/media/i2c/adv7842.c
@@ -1908,6 +1908,46 @@ static int adv7842_isr(struct v4l2_subdev *sd, u32 status, bool *handled)
 	return 0;
 }
 
+static int adv7842_get_edid(struct v4l2_subdev *sd, struct v4l2_subdev_edid *edid)
+{
+	struct adv7842_state *state = to_state(sd);
+	u8 *data = NULL;
+
+	if (edid->pad > ADV7842_EDID_PORT_VGA)
+		return -EINVAL;
+	if (edid->blocks == 0)
+		return -EINVAL;
+	if (edid->blocks > 2)
+		return -EINVAL;
+	if (edid->start_block > 1)
+		return -EINVAL;
+	if (edid->start_block == 1)
+		edid->blocks = 1;
+	if (!edid->edid)
+		return -EINVAL;
+
+	switch (edid->pad) {
+	case ADV7842_EDID_PORT_A:
+	case ADV7842_EDID_PORT_B:
+		if (state->hdmi_edid.present & (0x04 << edid->pad))
+			data = state->hdmi_edid.edid;
+		break;
+	case ADV7842_EDID_PORT_VGA:
+		if (state->vga_edid.present)
+			data = state->vga_edid.edid;
+		break;
+	default:
+		return -EINVAL;
+	}
+	if (!data)
+		return -ENODATA;
+
+	memcpy(edid->edid,
+	       data + edid->start_block * 128,
+	       edid->blocks * 128);
+	return 0;
+}
+
 static int adv7842_set_edid(struct v4l2_subdev *sd, struct v4l2_subdev_edid *e)
 {
 	struct adv7842_state *state = to_state(sd);
@@ -2720,6 +2760,7 @@ static const struct v4l2_subdev_video_ops adv7842_video_ops = {
 };
 
 static const struct v4l2_subdev_pad_ops adv7842_pad_ops = {
+	.get_edid = adv7842_get_edid,
 	.set_edid = adv7842_set_edid,
 };
 
-- 
1.8.4.rc3


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [RFC PATCH 18/22] adv7842: i2c dummy clients registration.
  2013-12-10 15:03 ` [RFC PATCH 01/22] adv7842: Re-worked query_dv_timings() Hans Verkuil
                     ` (15 preceding siblings ...)
  2013-12-10 15:04   ` [RFC PATCH 17/22] adv7842: support g_edid ioctl Hans Verkuil
@ 2013-12-10 15:04   ` Hans Verkuil
  2013-12-10 15:04   ` [RFC PATCH 19/22] adv7842: enable HDMI/DVI mode irq Hans Verkuil
                     ` (3 subsequent siblings)
  20 siblings, 0 replies; 27+ messages in thread
From: Hans Verkuil @ 2013-12-10 15:04 UTC (permalink / raw)
  To: linux-media; +Cc: Martin Bugge, Hans Verkuil

From: Martin Bugge <marbugge@cisco.com>

Clear i2c_clients ptr when unregistered.
Warn if configured i2c-addr is zero.

Signed-off-by: Martin Bugge <marbugge@cisco.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/i2c/adv7842.c | 83 ++++++++++++++++++++++++++++++++++-----------
 1 file changed, 63 insertions(+), 20 deletions(-)

diff --git a/drivers/media/i2c/adv7842.c b/drivers/media/i2c/adv7842.c
index c3ac4e9..64f0611 100644
--- a/drivers/media/i2c/adv7842.c
+++ b/drivers/media/i2c/adv7842.c
@@ -2803,8 +2803,9 @@ static const struct v4l2_ctrl_config adv7842_ctrl_free_run_color = {
 };
 
 
-static void adv7842_unregister_clients(struct adv7842_state *state)
+static void adv7842_unregister_clients(struct v4l2_subdev *sd)
 {
+	struct adv7842_state *state = to_state(sd);
 	if (state->i2c_avlink)
 		i2c_unregister_device(state->i2c_avlink);
 	if (state->i2c_cec)
@@ -2827,15 +2828,71 @@ static void adv7842_unregister_clients(struct adv7842_state *state)
 		i2c_unregister_device(state->i2c_cp);
 	if (state->i2c_vdp)
 		i2c_unregister_device(state->i2c_vdp);
+
+	state->i2c_avlink = NULL;
+	state->i2c_cec = NULL;
+	state->i2c_infoframe = NULL;
+	state->i2c_sdp_io = NULL;
+	state->i2c_sdp = NULL;
+	state->i2c_afe = NULL;
+	state->i2c_repeater = NULL;
+	state->i2c_edid = NULL;
+	state->i2c_hdmi = NULL;
+	state->i2c_cp = NULL;
+	state->i2c_vdp = NULL;
 }
 
-static struct i2c_client *adv7842_dummy_client(struct v4l2_subdev *sd,
+static struct i2c_client *adv7842_dummy_client(struct v4l2_subdev *sd, const char *desc,
 					       u8 addr, u8 io_reg)
 {
 	struct i2c_client *client = v4l2_get_subdevdata(sd);
+	struct i2c_client *cp;
 
 	io_write(sd, io_reg, addr << 1);
-	return i2c_new_dummy(client->adapter, io_read(sd, io_reg) >> 1);
+
+	if (addr == 0) {
+		v4l2_err(sd, "no %s i2c addr configured\n", desc);
+		return NULL;
+	}
+
+	cp = i2c_new_dummy(client->adapter, io_read(sd, io_reg) >> 1);
+	if (!cp)
+		v4l2_err(sd, "register %s on i2c addr 0x%x failed\n", desc, addr);
+
+	return cp;
+}
+
+static int adv7842_register_clients(struct v4l2_subdev *sd)
+{
+	struct adv7842_state *state = to_state(sd);
+	struct adv7842_platform_data *pdata = &state->pdata;
+
+	state->i2c_avlink = adv7842_dummy_client(sd, "avlink", pdata->i2c_avlink, 0xf3);
+	state->i2c_cec = adv7842_dummy_client(sd, "cec", pdata->i2c_cec, 0xf4);
+	state->i2c_infoframe = adv7842_dummy_client(sd, "infoframe", pdata->i2c_infoframe, 0xf5);
+	state->i2c_sdp_io = adv7842_dummy_client(sd, "sdp_io", pdata->i2c_sdp_io, 0xf2);
+	state->i2c_sdp = adv7842_dummy_client(sd, "sdp", pdata->i2c_sdp, 0xf1);
+	state->i2c_afe = adv7842_dummy_client(sd, "afe", pdata->i2c_afe, 0xf8);
+	state->i2c_repeater = adv7842_dummy_client(sd, "repeater", pdata->i2c_repeater, 0xf9);
+	state->i2c_edid = adv7842_dummy_client(sd, "edid", pdata->i2c_edid, 0xfa);
+	state->i2c_hdmi = adv7842_dummy_client(sd, "hdmi", pdata->i2c_hdmi, 0xfb);
+	state->i2c_cp = adv7842_dummy_client(sd, "cp", pdata->i2c_cp, 0xfd);
+	state->i2c_vdp = adv7842_dummy_client(sd, "vdp", pdata->i2c_vdp, 0xfe);
+
+	if (!state->i2c_avlink ||
+	    !state->i2c_cec ||
+	    !state->i2c_infoframe ||
+	    !state->i2c_sdp_io ||
+	    !state->i2c_sdp ||
+	    !state->i2c_afe ||
+	    !state->i2c_repeater ||
+	    !state->i2c_edid ||
+	    !state->i2c_hdmi ||
+	    !state->i2c_cp ||
+	    !state->i2c_vdp)
+		return -1;
+
+	return 0;
 }
 
 static int adv7842_probe(struct i2c_client *client,
@@ -2937,21 +2994,7 @@ static int adv7842_probe(struct i2c_client *client,
 		goto err_hdl;
 	}
 
-	state->i2c_avlink = adv7842_dummy_client(sd, pdata->i2c_avlink, 0xf3);
-	state->i2c_cec = adv7842_dummy_client(sd, pdata->i2c_cec, 0xf4);
-	state->i2c_infoframe = adv7842_dummy_client(sd, pdata->i2c_infoframe, 0xf5);
-	state->i2c_sdp_io = adv7842_dummy_client(sd, pdata->i2c_sdp_io, 0xf2);
-	state->i2c_sdp = adv7842_dummy_client(sd, pdata->i2c_sdp, 0xf1);
-	state->i2c_afe = adv7842_dummy_client(sd, pdata->i2c_afe, 0xf8);
-	state->i2c_repeater = adv7842_dummy_client(sd, pdata->i2c_repeater, 0xf9);
-	state->i2c_edid = adv7842_dummy_client(sd, pdata->i2c_edid, 0xfa);
-	state->i2c_hdmi = adv7842_dummy_client(sd, pdata->i2c_hdmi, 0xfb);
-	state->i2c_cp = adv7842_dummy_client(sd, pdata->i2c_cp, 0xfd);
-	state->i2c_vdp = adv7842_dummy_client(sd, pdata->i2c_vdp, 0xfe);
-	if (!state->i2c_avlink || !state->i2c_cec || !state->i2c_infoframe ||
-	    !state->i2c_sdp_io || !state->i2c_sdp || !state->i2c_afe ||
-	    !state->i2c_repeater || !state->i2c_edid || !state->i2c_hdmi ||
-	    !state->i2c_cp || !state->i2c_vdp) {
+	if (adv7842_register_clients(sd) < 0) {
 		err = -ENOMEM;
 		v4l2_err(sd, "failed to create all i2c clients\n");
 		goto err_i2c;
@@ -2987,7 +3030,7 @@ err_work_queues:
 	cancel_delayed_work(&state->delayed_work_enable_hotplug);
 	destroy_workqueue(state->work_queues);
 err_i2c:
-	adv7842_unregister_clients(state);
+	adv7842_unregister_clients(sd);
 err_hdl:
 	v4l2_ctrl_handler_free(hdl);
 	return err;
@@ -3006,7 +3049,7 @@ static int adv7842_remove(struct i2c_client *client)
 	destroy_workqueue(state->work_queues);
 	v4l2_device_unregister_subdev(sd);
 	media_entity_cleanup(&sd->entity);
-	adv7842_unregister_clients(to_state(sd));
+	adv7842_unregister_clients(sd);
 	v4l2_ctrl_handler_free(sd->ctrl_handler);
 	return 0;
 }
-- 
1.8.4.rc3


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [RFC PATCH 19/22] adv7842: enable HDMI/DVI mode irq
  2013-12-10 15:03 ` [RFC PATCH 01/22] adv7842: Re-worked query_dv_timings() Hans Verkuil
                     ` (16 preceding siblings ...)
  2013-12-10 15:04   ` [RFC PATCH 18/22] adv7842: i2c dummy clients registration Hans Verkuil
@ 2013-12-10 15:04   ` Hans Verkuil
  2013-12-10 15:04   ` [RFC PATCH 20/22] adv7842: composite sd-ram test, clear timings before setting Hans Verkuil
                     ` (2 subsequent siblings)
  20 siblings, 0 replies; 27+ messages in thread
From: Hans Verkuil @ 2013-12-10 15:04 UTC (permalink / raw)
  To: linux-media; +Cc: Martin Bugge, Hans Verkuil

From: Martin Bugge <marbugge@cisco.com>

Signed-off-by: Martin Bugge <marbugge@cisco.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/i2c/adv7842.c | 36 ++++++++++++++++++++++++++----------
 1 file changed, 26 insertions(+), 10 deletions(-)

diff --git a/drivers/media/i2c/adv7842.c b/drivers/media/i2c/adv7842.c
index 64f0611..9f45928 100644
--- a/drivers/media/i2c/adv7842.c
+++ b/drivers/media/i2c/adv7842.c
@@ -1832,12 +1832,15 @@ static void adv7842_irq_enable(struct v4l2_subdev *sd, bool enable)
 		io_write(sd, 0x78, 0x03);
 		/* Enable SDP Standard Detection Change and SDP Video Detected */
 		io_write(sd, 0xa0, 0x09);
+		/* Enable HDMI_MODE interrupt */
+		io_write(sd, 0x69, 0x08);
 	} else {
 		io_write(sd, 0x46, 0x0);
 		io_write(sd, 0x5a, 0x0);
 		io_write(sd, 0x73, 0x0);
 		io_write(sd, 0x78, 0x0);
 		io_write(sd, 0xa0, 0x0);
+		io_write(sd, 0x69, 0x0);
 	}
 }
 
@@ -1845,7 +1848,7 @@ static int adv7842_isr(struct v4l2_subdev *sd, u32 status, bool *handled)
 {
 	struct adv7842_state *state = to_state(sd);
 	u8 fmt_change_cp, fmt_change_digital, fmt_change_sdp;
-	u8 irq_status[5];
+	u8 irq_status[6];
 
 	adv7842_irq_enable(sd, false);
 
@@ -1855,6 +1858,7 @@ static int adv7842_isr(struct v4l2_subdev *sd, u32 status, bool *handled)
 	irq_status[2] = io_read(sd, 0x70);
 	irq_status[3] = io_read(sd, 0x75);
 	irq_status[4] = io_read(sd, 0x9d);
+	irq_status[5] = io_read(sd, 0x66);
 
 	/* and clear */
 	if (irq_status[0])
@@ -1867,12 +1871,14 @@ static int adv7842_isr(struct v4l2_subdev *sd, u32 status, bool *handled)
 		io_write(sd, 0x76, irq_status[3]);
 	if (irq_status[4])
 		io_write(sd, 0x9e, irq_status[4]);
+	if (irq_status[5])
+		io_write(sd, 0x67, irq_status[5]);
 
 	adv7842_irq_enable(sd, true);
 
-	v4l2_dbg(1, debug, sd, "%s: irq %x, %x, %x, %x, %x\n", __func__,
+	v4l2_dbg(1, debug, sd, "%s: irq %x, %x, %x, %x, %x, %x\n", __func__,
 		 irq_status[0], irq_status[1], irq_status[2],
-		 irq_status[3], irq_status[4]);
+		 irq_status[3], irq_status[4], irq_status[5]);
 
 	/* format change CP */
 	fmt_change_cp = irq_status[0] & 0x9c;
@@ -1889,22 +1895,32 @@ static int adv7842_isr(struct v4l2_subdev *sd, u32 status, bool *handled)
 	else
 		fmt_change_digital = 0;
 
-	/* notify */
+	/* format change */
 	if (fmt_change_cp || fmt_change_digital || fmt_change_sdp) {
 		v4l2_dbg(1, debug, sd,
 			 "%s: fmt_change_cp = 0x%x, fmt_change_digital = 0x%x, fmt_change_sdp = 0x%x\n",
 			 __func__, fmt_change_cp, fmt_change_digital,
 			 fmt_change_sdp);
 		v4l2_subdev_notify(sd, ADV7842_FMT_CHANGE, NULL);
+		if (handled)
+			*handled = true;
 	}
 
-	/* 5v cable detect */
-	if (irq_status[2])
-		adv7842_s_detect_tx_5v_ctrl(sd);
-
-	if (handled)
-		*handled = true;
+	/* HDMI/DVI mode */
+	if (irq_status[5] & 0x08) {
+		v4l2_dbg(1, debug, sd, "%s: irq %s mode\n", __func__,
+			 (io_read(sd, 0x65) & 0x08) ? "HDMI" : "DVI");
+		if (handled)
+			*handled = true;
+	}
 
+	/* tx 5v detect */
+	if (irq_status[2] & 0x3) {
+		v4l2_dbg(1, debug, sd, "%s: irq tx_5v\n", __func__);
+		adv7842_s_detect_tx_5v_ctrl(sd);
+		if (handled)
+			*handled = true;
+	}
 	return 0;
 }
 
-- 
1.8.4.rc3


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [RFC PATCH 20/22] adv7842: composite sd-ram test, clear timings before setting.
  2013-12-10 15:03 ` [RFC PATCH 01/22] adv7842: Re-worked query_dv_timings() Hans Verkuil
                     ` (17 preceding siblings ...)
  2013-12-10 15:04   ` [RFC PATCH 19/22] adv7842: enable HDMI/DVI mode irq Hans Verkuil
@ 2013-12-10 15:04   ` Hans Verkuil
  2013-12-10 15:04   ` [RFC PATCH 21/22] adv7842: obtain free-run mode from the platform_data Hans Verkuil
  2013-12-10 15:04   ` [RFC PATCH 22/22] adv7842: Composite sync adjustment Hans Verkuil
  20 siblings, 0 replies; 27+ messages in thread
From: Hans Verkuil @ 2013-12-10 15:04 UTC (permalink / raw)
  To: linux-media; +Cc: Martin Bugge, Hans Verkuil

From: Martin Bugge <marbugge@cisco.com>

Must clear timings before setting after test to recover.

Signed-off-by: Martin Bugge <marbugge@cisco.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/i2c/adv7842.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/media/i2c/adv7842.c b/drivers/media/i2c/adv7842.c
index 9f45928..8b4e369 100644
--- a/drivers/media/i2c/adv7842.c
+++ b/drivers/media/i2c/adv7842.c
@@ -2694,6 +2694,7 @@ static int adv7842_command_ram_test(struct v4l2_subdev *sd)
 	struct i2c_client *client = v4l2_get_subdevdata(sd);
 	struct adv7842_state *state = to_state(sd);
 	struct adv7842_platform_data *pdata = client->dev.platform_data;
+	struct v4l2_dv_timings timings;
 	int ret = 0;
 
 	if (!pdata)
@@ -2724,12 +2725,16 @@ static int adv7842_command_ram_test(struct v4l2_subdev *sd)
 
 	enable_input(sd);
 
-	adv7842_s_dv_timings(sd, &state->timings);
-
 	edid_write_vga_segment(sd);
 	edid_write_hdmi_segment(sd, ADV7842_EDID_PORT_A);
 	edid_write_hdmi_segment(sd, ADV7842_EDID_PORT_B);
 
+	timings = state->timings;
+
+	memset(&state->timings, 0, sizeof(struct v4l2_dv_timings));
+
+	adv7842_s_dv_timings(sd, &timings);
+
 	return ret;
 }
 
-- 
1.8.4.rc3


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [RFC PATCH 21/22] adv7842: obtain free-run mode from the platform_data.
  2013-12-10 15:03 ` [RFC PATCH 01/22] adv7842: Re-worked query_dv_timings() Hans Verkuil
                     ` (18 preceding siblings ...)
  2013-12-10 15:04   ` [RFC PATCH 20/22] adv7842: composite sd-ram test, clear timings before setting Hans Verkuil
@ 2013-12-10 15:04   ` Hans Verkuil
  2013-12-10 15:04   ` [RFC PATCH 22/22] adv7842: Composite sync adjustment Hans Verkuil
  20 siblings, 0 replies; 27+ messages in thread
From: Hans Verkuil @ 2013-12-10 15:04 UTC (permalink / raw)
  To: linux-media; +Cc: Martin Bugge, Hans Verkuil

From: Martin Bugge <marbugge@cisco.com>

The free-run mode can be board-specific.

Signed-off-by: Martin Bugge <marbugge@cisco.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/i2c/adv7842.c | 7 ++++---
 include/media/adv7842.h     | 7 +++++--
 2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/drivers/media/i2c/adv7842.c b/drivers/media/i2c/adv7842.c
index 8b4e369..fac5c4f 100644
--- a/drivers/media/i2c/adv7842.c
+++ b/drivers/media/i2c/adv7842.c
@@ -1622,8 +1622,6 @@ static void select_input(struct v4l2_subdev *sd,
 		/* deinterlacer enabled and 3D comb */
 		sdp_write_and_or(sd, 0x12, 0xf6, 0x09);
 
-		sdp_write(sd, 0xdd, 0x08); /* free run auto */
-
 		break;
 
 	case ADV7842_MODE_COMP:
@@ -2536,7 +2534,10 @@ static int adv7842_core_init(struct v4l2_subdev *sd)
 			pdata->drive_strength.sync);
 
 	/* HDMI free run */
-	cp_write(sd, 0xba, (pdata->hdmi_free_run_mode << 1) | 0x01);
+	cp_write_and_or(sd, 0xba, 0xfc, pdata->hdmi_free_run & 0x03);
+
+	/* SPD free run */
+	sdp_write_and_or(sd, 0xdd, 0xf0, pdata->sdp_free_run & 0x0f);
 
 	/* TODO from platform data */
 	cp_write(sd, 0x69, 0x14);   /* Enable CP CSC */
diff --git a/include/media/adv7842.h b/include/media/adv7842.h
index a4851bf..4e36496 100644
--- a/include/media/adv7842.h
+++ b/include/media/adv7842.h
@@ -192,8 +192,11 @@ struct adv7842_platform_data {
 	unsigned sd_ram_size; /* ram size in MB */
 	unsigned sd_ram_ddr:1; /* ddr or sdr sdram */
 
-	/* Free run */
-	unsigned hdmi_free_run_mode;
+	/* HDMI free run, CP-reg 0xBA */
+	unsigned hdmi_free_run;
+
+	/* SDP free run, CP-reg 0xDD */
+	unsigned sdp_free_run;
 
 	struct adv7842_sdp_csc_coeff sdp_csc_coeff;
 
-- 
1.8.4.rc3


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [RFC PATCH 22/22] adv7842: Composite sync adjustment
  2013-12-10 15:03 ` [RFC PATCH 01/22] adv7842: Re-worked query_dv_timings() Hans Verkuil
                     ` (19 preceding siblings ...)
  2013-12-10 15:04   ` [RFC PATCH 21/22] adv7842: obtain free-run mode from the platform_data Hans Verkuil
@ 2013-12-10 15:04   ` Hans Verkuil
  2013-12-17 13:16     ` [RFC PATCH 23/22] adv7842: return 0 if no change in s_dv_timings Hans Verkuil
                       ` (2 more replies)
  20 siblings, 3 replies; 27+ messages in thread
From: Hans Verkuil @ 2013-12-10 15:04 UTC (permalink / raw)
  To: linux-media; +Cc: Martin Bugge, Hans Verkuil

From: Martin Bugge <marbugge@cisco.com>

Signed-off-by: Martin Bugge <marbugge@cisco.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/i2c/adv7842.c | 8 ++++++++
 include/media/adv7842.h     | 4 ++++
 2 files changed, 12 insertions(+)

diff --git a/drivers/media/i2c/adv7842.c b/drivers/media/i2c/adv7842.c
index fac5c4f..bafe3b5 100644
--- a/drivers/media/i2c/adv7842.c
+++ b/drivers/media/i2c/adv7842.c
@@ -2437,6 +2437,10 @@ static void adv7842_s_sdp_io(struct v4l2_subdev *sd, struct adv7842_sdp_io_sync_
 		sdp_io_write(sd, 0x99, s->de_beg & 0xff);
 		sdp_io_write(sd, 0x9a, (s->de_end >> 8) & 0xf);
 		sdp_io_write(sd, 0x9b, s->de_end & 0xff);
+		sdp_io_write(sd, 0xa8, s->vs_beg_o);
+		sdp_io_write(sd, 0xa9, s->vs_beg_e);
+		sdp_io_write(sd, 0xaa, s->vs_end_o);
+		sdp_io_write(sd, 0xab, s->vs_end_e);
 		sdp_io_write(sd, 0xac, s->de_v_beg_o);
 		sdp_io_write(sd, 0xad, s->de_v_beg_e);
 		sdp_io_write(sd, 0xae, s->de_v_end_o);
@@ -2451,6 +2455,10 @@ static void adv7842_s_sdp_io(struct v4l2_subdev *sd, struct adv7842_sdp_io_sync_
 		sdp_io_write(sd, 0x99, 0x00);
 		sdp_io_write(sd, 0x9a, 0x00);
 		sdp_io_write(sd, 0x9b, 0x00);
+		sdp_io_write(sd, 0xa8, 0x04);
+		sdp_io_write(sd, 0xa9, 0x04);
+		sdp_io_write(sd, 0xaa, 0x04);
+		sdp_io_write(sd, 0xab, 0x04);
 		sdp_io_write(sd, 0xac, 0x04);
 		sdp_io_write(sd, 0xad, 0x04);
 		sdp_io_write(sd, 0xae, 0x04);
diff --git a/include/media/adv7842.h b/include/media/adv7842.h
index 4e36496..8b336ab 100644
--- a/include/media/adv7842.h
+++ b/include/media/adv7842.h
@@ -131,6 +131,10 @@ struct adv7842_sdp_io_sync_adjustment {
 	uint16_t hs_width;
 	uint16_t de_beg;
 	uint16_t de_end;
+	uint8_t vs_beg_o;
+	uint8_t vs_beg_e;
+	uint8_t vs_end_o;
+	uint8_t vs_end_e;
 	uint8_t de_v_beg_o;
 	uint8_t de_v_beg_e;
 	uint8_t de_v_end_o;
-- 
1.8.4.rc3


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [RFC PATCH 23/22] adv7842: return 0 if no change in s_dv_timings
  2013-12-10 15:04   ` [RFC PATCH 22/22] adv7842: Composite sync adjustment Hans Verkuil
@ 2013-12-17 13:16     ` Hans Verkuil
  2013-12-17 13:17     ` [RFC PATCH 24/22] adv7842: set LLC DLL phase from platform_data Hans Verkuil
  2013-12-17 13:17     ` [RFC PATCH 25/22] adv7842: initialize timings to CEA 640x480p59.94 Hans Verkuil
  2 siblings, 0 replies; 27+ messages in thread
From: Hans Verkuil @ 2013-12-17 13:16 UTC (permalink / raw)
  To: linux-media; +Cc: Martin Bugge, Hans Verkuil

Return 0 if the new timings are equal to the current timings as
it caused extra cp-loss/lock interrupts.

Signed-off-by: Martin Bugge <marbugge@cisco.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/i2c/adv7842.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/media/i2c/adv7842.c b/drivers/media/i2c/adv7842.c
index bafe3b5..82c57d7 100644
--- a/drivers/media/i2c/adv7842.c
+++ b/drivers/media/i2c/adv7842.c
@@ -1453,6 +1453,11 @@ static int adv7842_s_dv_timings(struct v4l2_subdev *sd,
 	if (state->mode == ADV7842_MODE_SDP)
 		return -ENODATA;
 
+	if (v4l2_match_dv_timings(&state->timings, timings, 0)) {
+		v4l2_dbg(1, debug, sd, "%s: no change\n", __func__);
+		return 0;
+	}
+
 	bt = &timings->bt;
 
 	if (!v4l2_valid_dv_timings(timings, adv7842_get_dv_timings_cap(sd),
-- 
1.8.4.rc3



^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [RFC PATCH 24/22] adv7842: set LLC DLL phase from platform_data
  2013-12-10 15:04   ` [RFC PATCH 22/22] adv7842: Composite sync adjustment Hans Verkuil
  2013-12-17 13:16     ` [RFC PATCH 23/22] adv7842: return 0 if no change in s_dv_timings Hans Verkuil
@ 2013-12-17 13:17     ` Hans Verkuil
  2013-12-17 20:59       ` Antti Palosaari
  2013-12-17 13:17     ` [RFC PATCH 25/22] adv7842: initialize timings to CEA 640x480p59.94 Hans Verkuil
  2 siblings, 1 reply; 27+ messages in thread
From: Hans Verkuil @ 2013-12-17 13:17 UTC (permalink / raw)
  To: linux-media; +Cc: Martin Bugge, Hans Verkuil

The correct LLC DLL phase depends on the board layout, so this
should be part of the platform_data.

Verified-by: Martin Bugge <marbugge@cisco.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/i2c/adv7842.c | 6 +-----
 include/media/adv7842.h     | 6 ++++++
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/media/i2c/adv7842.c b/drivers/media/i2c/adv7842.c
index 82c57d7..2eb4058 100644
--- a/drivers/media/i2c/adv7842.c
+++ b/drivers/media/i2c/adv7842.c
@@ -1591,9 +1591,6 @@ static void select_input(struct v4l2_subdev *sd,
 		afe_write(sd, 0x00, 0x00); /* power up ADC */
 		afe_write(sd, 0xc8, 0x00); /* phase control */
 
-		io_write(sd, 0x19, 0x83); /* LLC DLL phase */
-		io_write(sd, 0x33, 0x40); /* LLC DLL enable */
-
 		io_write(sd, 0xdd, 0x90); /* Manual 2x output clock */
 		/* script says register 0xde, which don't exist in manual */
 
@@ -2603,8 +2600,7 @@ static int adv7842_core_init(struct v4l2_subdev *sd)
 	io_write_and_or(sd, 0x20, 0xcf, 0x00);
 
 	/* LLC */
-	/* Set phase to 16. TODO: get this from platform_data */
-	io_write(sd, 0x19, 0x90);
+	io_write(sd, 0x19, 0x80 | pdata->llc_dll_phase);
 	io_write(sd, 0x33, 0x40);
 
 	/* interrupts */
diff --git a/include/media/adv7842.h b/include/media/adv7842.h
index 8b336ab..c67051a 100644
--- a/include/media/adv7842.h
+++ b/include/media/adv7842.h
@@ -192,6 +192,12 @@ struct adv7842_platform_data {
 		unsigned sync:2;
 	} drive_strength;
 
+	/*
+	 * IO register 0x19: Adjustment to the LLC DLL phase in
+	 * increments of 1/32 of a clock period.
+	 */
+	unsigned llc_dll_phase:5;
+
 	/* External RAM for 3-D comb or frame synchronizer */
 	unsigned sd_ram_size; /* ram size in MB */
 	unsigned sd_ram_ddr:1; /* ddr or sdr sdram */
-- 
1.8.4.rc3



^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [RFC PATCH 25/22] adv7842: initialize timings to CEA 640x480p59.94.
  2013-12-10 15:04   ` [RFC PATCH 22/22] adv7842: Composite sync adjustment Hans Verkuil
  2013-12-17 13:16     ` [RFC PATCH 23/22] adv7842: return 0 if no change in s_dv_timings Hans Verkuil
  2013-12-17 13:17     ` [RFC PATCH 24/22] adv7842: set LLC DLL phase from platform_data Hans Verkuil
@ 2013-12-17 13:17     ` Hans Verkuil
  2 siblings, 0 replies; 27+ messages in thread
From: Hans Verkuil @ 2013-12-17 13:17 UTC (permalink / raw)
  To: linux-media; +Cc: Martin Bugge, Hans Verkuil

This timing must be supported by all HDMI equipment, so that's a
reasonable default.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/i2c/adv7842.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/media/i2c/adv7842.c b/drivers/media/i2c/adv7842.c
index 2eb4058..4bd6915 100644
--- a/drivers/media/i2c/adv7842.c
+++ b/drivers/media/i2c/adv7842.c
@@ -2930,6 +2930,8 @@ static int adv7842_probe(struct i2c_client *client,
 			 const struct i2c_device_id *id)
 {
 	struct adv7842_state *state;
+	static const struct v4l2_dv_timings cea640x480 =
+		V4L2_DV_BT_CEA_640X480P59_94;
 	struct adv7842_platform_data *pdata = client->dev.platform_data;
 	struct v4l2_ctrl_handler *hdl;
 	struct v4l2_subdev *sd;
@@ -2956,6 +2958,7 @@ static int adv7842_probe(struct i2c_client *client,
 
 	/* platform data */
 	state->pdata = *pdata;
+	state->timings = cea640x480;
 
 	sd = &state->sd;
 	v4l2_i2c_subdev_init(sd, client, &adv7842_ops);
-- 
1.8.4.rc3



^ permalink raw reply related	[flat|nested] 27+ messages in thread

* Re: [RFC PATCH 24/22] adv7842: set LLC DLL phase from platform_data
  2013-12-17 13:17     ` [RFC PATCH 24/22] adv7842: set LLC DLL phase from platform_data Hans Verkuil
@ 2013-12-17 20:59       ` Antti Palosaari
  0 siblings, 0 replies; 27+ messages in thread
From: Antti Palosaari @ 2013-12-17 20:59 UTC (permalink / raw)
  To: Hans Verkuil, linux-media; +Cc: Martin Bugge, Hans Verkuil

On 17.12.2013 15:17, Hans Verkuil wrote:
> The correct LLC DLL phase depends on the board layout, so this
> should be part of the platform_data.
>
> Verified-by: Martin Bugge <marbugge@cisco.com>

Nit, but the documentation says correct tag is Tested-by :)

regards
Antti

-- 
http://palosaari.fi/

^ permalink raw reply	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2013-12-17 20:59 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-12-10 15:03 [RFC PATCH 00/22] adv7842: fixes Hans Verkuil
2013-12-10 15:03 ` [RFC PATCH 01/22] adv7842: Re-worked query_dv_timings() Hans Verkuil
2013-12-10 15:03   ` [RFC PATCH 02/22] adv7842: corrected setting of cp-register 0x91 and 0x8f Hans Verkuil
2013-12-10 15:03   ` [RFC PATCH 03/22] adv7842: properly enable/disable the irqs Hans Verkuil
2013-12-10 15:03   ` [RFC PATCH 04/22] adv7842: save platform data in state struct Hans Verkuil
2013-12-10 15:03   ` [RFC PATCH 05/22] adv7842: support YCrCb analog input Hans Verkuil
2013-12-10 15:03   ` [RFC PATCH 06/22] adv7842: added DE vertical position in SDP-io-sync Hans Verkuil
2013-12-10 15:03   ` [RFC PATCH 07/22] adv7842: Receive CEA formats as RGB on VGA (RGB) input Hans Verkuil
2013-12-10 15:03   ` [RFC PATCH 08/22] adv7842: set defaults spa-location Hans Verkuil
2013-12-10 15:03   ` [RFC PATCH 09/22] adv7842: 625/525 line standard jitter fix Hans Verkuil
2013-12-10 15:03   ` [RFC PATCH 10/22] adv7842: set default input in platform-data Hans Verkuil
2013-12-10 15:03   ` [RFC PATCH 11/22] adv7842: increase wait time Hans Verkuil
2013-12-10 15:03   ` [RFC PATCH 12/22] adv7842: remove connector type. Never used for anything useful Hans Verkuil
2013-12-10 15:03   ` [RFC PATCH 13/22] adv7842: Use defines to select EDID port Hans Verkuil
2013-12-10 15:04   ` [RFC PATCH 14/22] adv7842: mute audio before switching inputs to avoid noise/pops Hans Verkuil
2013-12-10 15:04   ` [RFC PATCH 15/22] adv7842: clear edid, if no edid just disable Edid-DDC access Hans Verkuil
2013-12-10 15:04   ` [RFC PATCH 16/22] adv7842: restart STDI once if format is not found Hans Verkuil
2013-12-10 15:04   ` [RFC PATCH 17/22] adv7842: support g_edid ioctl Hans Verkuil
2013-12-10 15:04   ` [RFC PATCH 18/22] adv7842: i2c dummy clients registration Hans Verkuil
2013-12-10 15:04   ` [RFC PATCH 19/22] adv7842: enable HDMI/DVI mode irq Hans Verkuil
2013-12-10 15:04   ` [RFC PATCH 20/22] adv7842: composite sd-ram test, clear timings before setting Hans Verkuil
2013-12-10 15:04   ` [RFC PATCH 21/22] adv7842: obtain free-run mode from the platform_data Hans Verkuil
2013-12-10 15:04   ` [RFC PATCH 22/22] adv7842: Composite sync adjustment Hans Verkuil
2013-12-17 13:16     ` [RFC PATCH 23/22] adv7842: return 0 if no change in s_dv_timings Hans Verkuil
2013-12-17 13:17     ` [RFC PATCH 24/22] adv7842: set LLC DLL phase from platform_data Hans Verkuil
2013-12-17 20:59       ` Antti Palosaari
2013-12-17 13:17     ` [RFC PATCH 25/22] adv7842: initialize timings to CEA 640x480p59.94 Hans Verkuil

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox