linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFCv2 PATCH 00/14] davinci: clean up input/output/subdev config
@ 2012-09-20 12:06 Hans Verkuil
  2012-09-20 12:06 ` [RFCv2 PATCH 01/14] vpif_capture: remove unused data structure Hans Verkuil
  2012-09-22 15:58 ` [RFCv2 PATCH 00/14] davinci: clean up input/output/subdev config Prabhakar Lad
  0 siblings, 2 replies; 19+ messages in thread
From: Hans Verkuil @ 2012-09-20 12:06 UTC (permalink / raw)
  To: linux-media; +Cc: Prabhakar Lad, DLOS

Hi Prabhakar,

This is the second patch series for a vpif driver cleanup.

The first version can be found here:

http://www.mail-archive.com/linux-media@vger.kernel.org/msg52136.html

Changes since RFCv1:

- rebased to a newer git repo:
  http://git.linuxtv.org/mhadli/v4l-dvb-davinci_devices.git/shortlog/refs/heads/da850_vpif_machine

- fixed probe() cleanup code in both display and capture that was seriously
  broken.

- fixed a broken s_routing implementation in the tvp514x driver: if there
  is no incoming video signal, then s_routing would return EINVAL and
  leave the driver with an inconsistent internal state. This has always
  been a problem, but with this patch series it suddenly became really
  noticable. s_routing shouldn't try to wait for a valid signal, that's
  not what s_routing should do.

This patch series does some driver cleanup and reorganizes the config
structs that are used to set up subdevices.

The current driver associates an input or output with a subdev, but multiple
inputs may use the same subdev and some inputs may not use a subdev at all
(this is the case for our hardware).

Several other things were also configured in the wrong structure. For
example the vpif_interface struct is really part of the channel config
and has nothing to do with the subdev.

What is missing here is that the output doesn't have the same flexibility
as the input when it comes to configuration. It would be good if someone
can pick this up as a follow-up since it's unlikely I'll be working on
that.

What would also be nice is that by leaving the inputs or outputs for the
second channel empty (NULL) in the configuration you can disable the second
video node, e.g. trying to use it will always result in ENODEV or something.

This patch series will at least make things more flexible.

Regards,

        Hans


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

* [RFCv2 PATCH 01/14] vpif_capture: remove unused data structure.
  2012-09-20 12:06 [RFCv2 PATCH 00/14] davinci: clean up input/output/subdev config Hans Verkuil
@ 2012-09-20 12:06 ` Hans Verkuil
  2012-09-20 12:06   ` [RFCv2 PATCH 02/14] vpif_display: remove unused data structures Hans Verkuil
                     ` (12 more replies)
  2012-09-22 15:58 ` [RFCv2 PATCH 00/14] davinci: clean up input/output/subdev config Prabhakar Lad
  1 sibling, 13 replies; 19+ messages in thread
From: Hans Verkuil @ 2012-09-20 12:06 UTC (permalink / raw)
  To: linux-media; +Cc: Prabhakar Lad, DLOS, Hans Verkuil

From: Hans Verkuil <hans.verkuil@cisco.com>

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/platform/davinci/vpif_capture.h |    6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/media/platform/davinci/vpif_capture.h b/drivers/media/platform/davinci/vpif_capture.h
index e4b54be..0a3904c 100644
--- a/drivers/media/platform/davinci/vpif_capture.h
+++ b/drivers/media/platform/davinci/vpif_capture.h
@@ -159,10 +159,6 @@ struct config_vpif_params {
 	u32 video_limit[VPIF_CAPTURE_NUM_CHANNELS];
 	u8 max_device_type;
 };
-/* Struct which keeps track of the line numbers for the sliced vbi service */
-struct vpif_service_line {
-	u16 service_id;
-	u16 service_line[2];
-};
+
 #endif				/* End of __KERNEL__ */
 #endif				/* VPIF_CAPTURE_H */
-- 
1.7.10.4


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

* [RFCv2 PATCH 02/14] vpif_display: remove unused data structures.
  2012-09-20 12:06 ` [RFCv2 PATCH 01/14] vpif_capture: remove unused data structure Hans Verkuil
@ 2012-09-20 12:06   ` Hans Verkuil
  2012-09-20 12:06   ` [RFCv2 PATCH 03/14] vpif_capture: move input_idx to channel_obj Hans Verkuil
                     ` (11 subsequent siblings)
  12 siblings, 0 replies; 19+ messages in thread
From: Hans Verkuil @ 2012-09-20 12:06 UTC (permalink / raw)
  To: linux-media; +Cc: Prabhakar Lad, DLOS, Hans Verkuil

From: Hans Verkuil <hans.verkuil@cisco.com>

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/platform/davinci/vpif_display.h |   15 ---------------
 1 file changed, 15 deletions(-)

diff --git a/drivers/media/platform/davinci/vpif_display.h b/drivers/media/platform/davinci/vpif_display.h
index 19c7976..8654002 100644
--- a/drivers/media/platform/davinci/vpif_display.h
+++ b/drivers/media/platform/davinci/vpif_display.h
@@ -65,12 +65,6 @@ struct video_obj {
 	u32 output_id;			/* Current output id */
 };
 
-struct vbi_obj {
-	int num_services;
-	struct vpif_vbi_params vbiparams;	/* vpif parameters for the raw
-						 * vbi data */
-};
-
 struct vpif_disp_buffer {
 	struct vb2_buffer vb;
 	struct list_head list;
@@ -136,7 +130,6 @@ struct channel_obj {
 	struct vpif_params vpifparams;
 	struct common_obj common[VPIF_NUMOBJECTS];
 	struct video_obj video;
-	struct vbi_obj vbi;
 };
 
 /* File handle structure */
@@ -168,12 +161,4 @@ struct config_vpif_params {
 	u8 min_numbuffers;
 };
 
-/* Struct which keeps track of the line numbers for the sliced vbi service */
-struct vpif_service_line {
-	u16 service_id;
-	u16 service_line[2];
-	u16 enc_service_id;
-	u8 bytestowrite;
-};
-
 #endif				/* DAVINCIHD_DISPLAY_H */
-- 
1.7.10.4


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

* [RFCv2 PATCH 03/14] vpif_capture: move input_idx to channel_obj.
  2012-09-20 12:06 ` [RFCv2 PATCH 01/14] vpif_capture: remove unused data structure Hans Verkuil
  2012-09-20 12:06   ` [RFCv2 PATCH 02/14] vpif_display: remove unused data structures Hans Verkuil
@ 2012-09-20 12:06   ` Hans Verkuil
  2012-09-20 12:06   ` [RFCv2 PATCH 04/14] vpif_display: move output_id " Hans Verkuil
                     ` (10 subsequent siblings)
  12 siblings, 0 replies; 19+ messages in thread
From: Hans Verkuil @ 2012-09-20 12:06 UTC (permalink / raw)
  To: linux-media; +Cc: Prabhakar Lad, DLOS, Hans Verkuil

From: Hans Verkuil <hans.verkuil@cisco.com>

input_idx does not belong to video_obj. Move it where it belongs.
Also remove the bogus code in the open() function that suddenly
changes the input to 0 for no reason.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/platform/davinci/vpif_capture.c |    9 ++-------
 drivers/media/platform/davinci/vpif_capture.h |    4 ++--
 2 files changed, 4 insertions(+), 9 deletions(-)

diff --git a/drivers/media/platform/davinci/vpif_capture.c b/drivers/media/platform/davinci/vpif_capture.c
index 78edd01..4233554 100644
--- a/drivers/media/platform/davinci/vpif_capture.c
+++ b/drivers/media/platform/davinci/vpif_capture.c
@@ -888,8 +888,6 @@ static int vpif_open(struct file *filep)
 			if (vpif_obj.sd[i]) {
 				/* the sub device is registered */
 				ch->curr_subdev_info = &config->subdev_info[i];
-				/* make first input as the current input */
-				vid_ch->input_idx = 0;
 				break;
 			}
 		}
@@ -1442,10 +1440,8 @@ static int vpif_g_input(struct file *file, void *priv, unsigned int *index)
 {
 	struct vpif_fh *fh = priv;
 	struct channel_obj *ch = fh->channel;
-	struct video_obj *vid_ch = &ch->video;
-
-	*index = vid_ch->input_idx;
 
+	*index = ch->input_idx;
 	return 0;
 }
 
@@ -1462,7 +1458,6 @@ static int vpif_s_input(struct file *file, void *priv, unsigned int index)
 	struct vpif_fh *fh = priv;
 	struct channel_obj *ch = fh->channel;
 	struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
-	struct video_obj *vid_ch = &ch->video;
 	struct vpif_subdev_info *subdev_info;
 	int ret = 0, sd_index = 0;
 	u32 input = 0, output = 0;
@@ -1517,7 +1512,7 @@ static int vpif_s_input(struct file *file, void *priv, unsigned int index)
 			return ret;
 		}
 	}
-	vid_ch->input_idx = index;
+	ch->input_idx = index;
 	ch->curr_subdev_info = subdev_info;
 	ch->curr_sd_index = sd_index;
 	/* copy interface parameters to vpif */
diff --git a/drivers/media/platform/davinci/vpif_capture.h b/drivers/media/platform/davinci/vpif_capture.h
index 0a3904c..a284667 100644
--- a/drivers/media/platform/davinci/vpif_capture.h
+++ b/drivers/media/platform/davinci/vpif_capture.h
@@ -54,8 +54,6 @@ struct video_obj {
 	/* Currently selected or default standard */
 	v4l2_std_id stdid;
 	struct v4l2_dv_timings dv_timings;
-	/* This is to track the last input that is passed to application */
-	u32 input_idx;
 };
 
 struct vpif_cap_buffer {
@@ -121,6 +119,8 @@ struct channel_obj {
 	enum vpif_channel_id channel_id;
 	/* index into sd table */
 	int curr_sd_index;
+	/* Current input */
+	u32 input_idx;
 	/* ptr to current sub device information */
 	struct vpif_subdev_info *curr_subdev_info;
 	/* vpif configuration params */
-- 
1.7.10.4


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

* [RFCv2 PATCH 04/14] vpif_display: move output_id to channel_obj.
  2012-09-20 12:06 ` [RFCv2 PATCH 01/14] vpif_capture: remove unused data structure Hans Verkuil
  2012-09-20 12:06   ` [RFCv2 PATCH 02/14] vpif_display: remove unused data structures Hans Verkuil
  2012-09-20 12:06   ` [RFCv2 PATCH 03/14] vpif_capture: move input_idx to channel_obj Hans Verkuil
@ 2012-09-20 12:06   ` Hans Verkuil
  2012-09-20 12:06   ` [RFCv2 PATCH 05/14] vpif_capture: remove unnecessary can_route flag Hans Verkuil
                     ` (9 subsequent siblings)
  12 siblings, 0 replies; 19+ messages in thread
From: Hans Verkuil @ 2012-09-20 12:06 UTC (permalink / raw)
  To: linux-media; +Cc: Prabhakar Lad, DLOS, Hans Verkuil

From: Hans Verkuil <hans.verkuil@cisco.com>

The output index does not belong to video_obj, it belongs to
channel_obj. Also rename to output_idx to be consistent with
the input_idx name used in vpif_capture.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/platform/davinci/vpif_display.c |   17 ++++++-----------
 drivers/media/platform/davinci/vpif_display.h |    2 +-
 2 files changed, 7 insertions(+), 12 deletions(-)

diff --git a/drivers/media/platform/davinci/vpif_display.c b/drivers/media/platform/davinci/vpif_display.c
index 2c06778..f394599 100644
--- a/drivers/media/platform/davinci/vpif_display.c
+++ b/drivers/media/platform/davinci/vpif_display.c
@@ -1231,7 +1231,6 @@ static int vpif_s_output(struct file *file, void *priv, unsigned int i)
 {
 	struct vpif_fh *fh = priv;
 	struct channel_obj *ch = fh->channel;
-	struct video_obj *vid_ch = &ch->video;
 	struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
 	int ret = 0;
 
@@ -1246,7 +1245,7 @@ static int vpif_s_output(struct file *file, void *priv, unsigned int i)
 	if (ret < 0)
 		vpif_err("Failed to set output standard\n");
 
-	vid_ch->output_id = i;
+	ch->output_idx = i;
 	return ret;
 }
 
@@ -1254,9 +1253,8 @@ static int vpif_g_output(struct file *file, void *priv, unsigned int *i)
 {
 	struct vpif_fh *fh = priv;
 	struct channel_obj *ch = fh->channel;
-	struct video_obj *vid_ch = &ch->video;
 
-	*i = vid_ch->output_id;
+	*i = ch->output_idx;
 
 	return 0;
 }
@@ -1291,9 +1289,8 @@ vpif_enum_dv_timings(struct file *file, void *priv,
 {
 	struct vpif_fh *fh = priv;
 	struct channel_obj *ch = fh->channel;
-	struct video_obj *vid_ch = &ch->video;
 
-	return v4l2_subdev_call(vpif_obj.sd[vid_ch->output_id],
+	return v4l2_subdev_call(vpif_obj.sd[ch->output_idx],
 			video, enum_dv_timings, timings);
 }
 
@@ -1320,7 +1317,7 @@ static int vpif_s_dv_timings(struct file *file, void *priv,
 	}
 
 	/* Configure subdevice timings, if any */
-	ret = v4l2_subdev_call(vpif_obj.sd[vid_ch->output_id],
+	ret = v4l2_subdev_call(vpif_obj.sd[ch->output_idx],
 			video, s_dv_timings, timings);
 	if (ret == -ENOIOCTLCMD) {
 		vpif_dbg(2, debug, "Custom DV timings not supported by "
@@ -1451,9 +1448,8 @@ static int vpif_dbg_g_register(struct file *file, void *priv,
 		struct v4l2_dbg_register *reg){
 	struct vpif_fh *fh = priv;
 	struct channel_obj *ch = fh->channel;
-	struct video_obj *vid_ch = &ch->video;
 
-	return v4l2_subdev_call(vpif_obj.sd[vid_ch->output_id], core,
+	return v4l2_subdev_call(vpif_obj.sd[ch->output_idx], core,
 			g_register, reg);
 }
 
@@ -1470,9 +1466,8 @@ static int vpif_dbg_s_register(struct file *file, void *priv,
 		struct v4l2_dbg_register *reg){
 	struct vpif_fh *fh = priv;
 	struct channel_obj *ch = fh->channel;
-	struct video_obj *vid_ch = &ch->video;
 
-	return v4l2_subdev_call(vpif_obj.sd[vid_ch->output_id], core,
+	return v4l2_subdev_call(vpif_obj.sd[ch->output_idx], core,
 			s_register, reg);
 }
 #endif
diff --git a/drivers/media/platform/davinci/vpif_display.h b/drivers/media/platform/davinci/vpif_display.h
index 8654002..805704c 100644
--- a/drivers/media/platform/davinci/vpif_display.h
+++ b/drivers/media/platform/davinci/vpif_display.h
@@ -62,7 +62,6 @@ struct video_obj {
 	v4l2_std_id stdid;		/* Currently selected or default
 					 * standard */
 	struct v4l2_dv_timings dv_timings;
-	u32 output_id;			/* Current output id */
 };
 
 struct vpif_disp_buffer {
@@ -125,6 +124,7 @@ struct channel_obj {
 					 * which is being displayed */
 	u8 initialized;			/* flag to indicate whether
 					 * encoder is initialized */
+	u32 output_idx;			/* Current output index */
 
 	enum vpif_channel_id channel_id;/* Identifies channel */
 	struct vpif_params vpifparams;
-- 
1.7.10.4


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

* [RFCv2 PATCH 05/14] vpif_capture: remove unnecessary can_route flag.
  2012-09-20 12:06 ` [RFCv2 PATCH 01/14] vpif_capture: remove unused data structure Hans Verkuil
                     ` (2 preceding siblings ...)
  2012-09-20 12:06   ` [RFCv2 PATCH 04/14] vpif_display: move output_id " Hans Verkuil
@ 2012-09-20 12:06   ` Hans Verkuil
  2012-10-03  8:43     ` Sekhar Nori
  2012-09-20 12:06   ` [RFCv2 PATCH 06/14] vpif_capture: move routing info from subdev to input Hans Verkuil
                     ` (8 subsequent siblings)
  12 siblings, 1 reply; 19+ messages in thread
From: Hans Verkuil @ 2012-09-20 12:06 UTC (permalink / raw)
  To: linux-media; +Cc: Prabhakar Lad, DLOS, Hans Verkuil

From: Hans Verkuil <hans.verkuil@cisco.com>

Calling a subdev op that isn't implemented will just return -ENOIOCTLCMD
No need to have a flag for that.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 arch/arm/mach-davinci/board-da850-evm.c       |    2 --
 arch/arm/mach-davinci/board-dm646x-evm.c      |    2 --
 drivers/media/platform/davinci/vpif_capture.c |   18 ++++++++----------
 include/media/davinci/vpif_types.h            |    1 -
 4 files changed, 8 insertions(+), 15 deletions(-)

diff --git a/arch/arm/mach-davinci/board-da850-evm.c b/arch/arm/mach-davinci/board-da850-evm.c
index d0954a2..d92e0ab 100644
--- a/arch/arm/mach-davinci/board-da850-evm.c
+++ b/arch/arm/mach-davinci/board-da850-evm.c
@@ -1209,7 +1209,6 @@ static struct vpif_subdev_info da850_vpif_capture_sdev_info[] = {
 		},
 		.input = INPUT_CVBS_VI2B,
 		.output = OUTPUT_10BIT_422_EMBEDDED_SYNC,
-		.can_route = 1,
 		.vpif_if = {
 			.if_type = VPIF_IF_BT656,
 			.hd_pol  = 1,
@@ -1225,7 +1224,6 @@ static struct vpif_subdev_info da850_vpif_capture_sdev_info[] = {
 		},
 		.input = INPUT_SVIDEO_VI2C_VI1C,
 		.output = OUTPUT_10BIT_422_EMBEDDED_SYNC,
-		.can_route = 1,
 		.vpif_if = {
 			.if_type = VPIF_IF_BT656,
 			.hd_pol  = 1,
diff --git a/arch/arm/mach-davinci/board-dm646x-evm.c b/arch/arm/mach-davinci/board-dm646x-evm.c
index 958679a..a0be63b 100644
--- a/arch/arm/mach-davinci/board-dm646x-evm.c
+++ b/arch/arm/mach-davinci/board-dm646x-evm.c
@@ -603,7 +603,6 @@ static struct vpif_subdev_info vpif_capture_sdev_info[] = {
 		},
 		.input = INPUT_CVBS_VI2B,
 		.output = OUTPUT_10BIT_422_EMBEDDED_SYNC,
-		.can_route = 1,
 		.vpif_if = {
 			.if_type = VPIF_IF_BT656,
 			.hd_pol = 1,
@@ -619,7 +618,6 @@ static struct vpif_subdev_info vpif_capture_sdev_info[] = {
 		},
 		.input = INPUT_SVIDEO_VI2C_VI1C,
 		.output = OUTPUT_10BIT_422_EMBEDDED_SYNC,
-		.can_route = 1,
 		.vpif_if = {
 			.if_type = VPIF_IF_BT656,
 			.hd_pol = 1,
diff --git a/drivers/media/platform/davinci/vpif_capture.c b/drivers/media/platform/davinci/vpif_capture.c
index 4233554..81ad6a2 100644
--- a/drivers/media/platform/davinci/vpif_capture.c
+++ b/drivers/media/platform/davinci/vpif_capture.c
@@ -1502,15 +1502,13 @@ static int vpif_s_input(struct file *file, void *priv, unsigned int index)
 		}
 	}
 
-	if (subdev_info->can_route) {
-		input = subdev_info->input;
-		output = subdev_info->output;
-		ret = v4l2_subdev_call(vpif_obj.sd[sd_index], video, s_routing,
-					input, output, 0);
-		if (ret < 0) {
-			vpif_dbg(1, debug, "Failed to set input\n");
-			return ret;
-		}
+	input = subdev_info->input;
+	output = subdev_info->output;
+	ret = v4l2_subdev_call(vpif_obj.sd[sd_index], video, s_routing,
+			input, output, 0);
+	if (ret < 0 && ret != -ENOIOCTLCMD) {
+		vpif_dbg(1, debug, "Failed to set input\n");
+		return ret;
 	}
 	ch->input_idx = index;
 	ch->curr_subdev_info = subdev_info;
@@ -1520,7 +1518,7 @@ static int vpif_s_input(struct file *file, void *priv, unsigned int index)
 
 	/* update tvnorms from the sub device input info */
 	ch->video_dev->tvnorms = chan_cfg->inputs[index].input.std;
-	return ret;
+	return 0;
 }
 
 /**
diff --git a/include/media/davinci/vpif_types.h b/include/media/davinci/vpif_types.h
index d8f6ab1..1fe46a5 100644
--- a/include/media/davinci/vpif_types.h
+++ b/include/media/davinci/vpif_types.h
@@ -39,7 +39,6 @@ struct vpif_subdev_info {
 	struct i2c_board_info board_info;
 	u32 input;
 	u32 output;
-	unsigned can_route:1;
 	struct vpif_interface vpif_if;
 };
 
-- 
1.7.10.4


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

* [RFCv2 PATCH 06/14] vpif_capture: move routing info from subdev to input.
  2012-09-20 12:06 ` [RFCv2 PATCH 01/14] vpif_capture: remove unused data structure Hans Verkuil
                     ` (3 preceding siblings ...)
  2012-09-20 12:06   ` [RFCv2 PATCH 05/14] vpif_capture: remove unnecessary can_route flag Hans Verkuil
@ 2012-09-20 12:06   ` Hans Verkuil
  2012-10-03  8:46     ` Sekhar Nori
  2012-09-20 12:06   ` [RFCv2 PATCH 07/14] vpif_capture: first init subdevs, then register device nodes Hans Verkuil
                     ` (7 subsequent siblings)
  12 siblings, 1 reply; 19+ messages in thread
From: Hans Verkuil @ 2012-09-20 12:06 UTC (permalink / raw)
  To: linux-media; +Cc: Prabhakar Lad, DLOS, Hans Verkuil

From: Hans Verkuil <hans.verkuil@cisco.com>

Routing information is a property of the input, not of the subdev.
One subdev may provide multiple inputs, each with its own routing
information.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 arch/arm/mach-davinci/board-da850-evm.c       |    8 ++++----
 arch/arm/mach-davinci/board-dm646x-evm.c      |    8 ++++----
 drivers/media/platform/davinci/vpif_capture.c |    7 +++++--
 include/media/davinci/vpif_types.h            |    4 ++--
 4 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/arch/arm/mach-davinci/board-da850-evm.c b/arch/arm/mach-davinci/board-da850-evm.c
index d92e0ab..514d4d4 100644
--- a/arch/arm/mach-davinci/board-da850-evm.c
+++ b/arch/arm/mach-davinci/board-da850-evm.c
@@ -1184,6 +1184,8 @@ static const struct vpif_input da850_ch0_inputs[] = {
 			.type  = V4L2_INPUT_TYPE_CAMERA,
 			.std   = TVP514X_STD_ALL,
 		},
+		.input_route = INPUT_CVBS_VI2B,
+		.output_route = OUTPUT_10BIT_422_EMBEDDED_SYNC,
 		.subdev_name = TVP5147_CH0,
 	},
 };
@@ -1196,6 +1198,8 @@ static const struct vpif_input da850_ch1_inputs[] = {
 			.type  = V4L2_INPUT_TYPE_CAMERA,
 			.std   = TVP514X_STD_ALL,
 		},
+		.input_route = INPUT_SVIDEO_VI2C_VI1C,
+		.output_route = OUTPUT_10BIT_422_EMBEDDED_SYNC,
 		.subdev_name = TVP5147_CH1,
 	},
 };
@@ -1207,8 +1211,6 @@ static struct vpif_subdev_info da850_vpif_capture_sdev_info[] = {
 			I2C_BOARD_INFO("tvp5146", 0x5d),
 			.platform_data = &tvp5146_pdata,
 		},
-		.input = INPUT_CVBS_VI2B,
-		.output = OUTPUT_10BIT_422_EMBEDDED_SYNC,
 		.vpif_if = {
 			.if_type = VPIF_IF_BT656,
 			.hd_pol  = 1,
@@ -1222,8 +1224,6 @@ static struct vpif_subdev_info da850_vpif_capture_sdev_info[] = {
 			I2C_BOARD_INFO("tvp5146", 0x5c),
 			.platform_data = &tvp5146_pdata,
 		},
-		.input = INPUT_SVIDEO_VI2C_VI1C,
-		.output = OUTPUT_10BIT_422_EMBEDDED_SYNC,
 		.vpif_if = {
 			.if_type = VPIF_IF_BT656,
 			.hd_pol  = 1,
diff --git a/arch/arm/mach-davinci/board-dm646x-evm.c b/arch/arm/mach-davinci/board-dm646x-evm.c
index a0be63b..0daec7e 100644
--- a/arch/arm/mach-davinci/board-dm646x-evm.c
+++ b/arch/arm/mach-davinci/board-dm646x-evm.c
@@ -601,8 +601,6 @@ static struct vpif_subdev_info vpif_capture_sdev_info[] = {
 			I2C_BOARD_INFO("tvp5146", 0x5d),
 			.platform_data = &tvp5146_pdata,
 		},
-		.input = INPUT_CVBS_VI2B,
-		.output = OUTPUT_10BIT_422_EMBEDDED_SYNC,
 		.vpif_if = {
 			.if_type = VPIF_IF_BT656,
 			.hd_pol = 1,
@@ -616,8 +614,6 @@ static struct vpif_subdev_info vpif_capture_sdev_info[] = {
 			I2C_BOARD_INFO("tvp5146", 0x5c),
 			.platform_data = &tvp5146_pdata,
 		},
-		.input = INPUT_SVIDEO_VI2C_VI1C,
-		.output = OUTPUT_10BIT_422_EMBEDDED_SYNC,
 		.vpif_if = {
 			.if_type = VPIF_IF_BT656,
 			.hd_pol = 1,
@@ -636,6 +632,8 @@ static const struct vpif_input dm6467_ch0_inputs[] = {
 			.std = TVP514X_STD_ALL,
 		},
 		.subdev_name = TVP5147_CH0,
+		.input_route = INPUT_CVBS_VI2B,
+		.output_route = OUTPUT_10BIT_422_EMBEDDED_SYNC,
 	},
 };
 
@@ -648,6 +646,8 @@ static const struct vpif_input dm6467_ch1_inputs[] = {
 			.std = TVP514X_STD_ALL,
 		},
 		.subdev_name = TVP5147_CH1,
+		.input_route = INPUT_SVIDEO_VI2C_VI1C,
+		.output_route = OUTPUT_10BIT_422_EMBEDDED_SYNC,
 	},
 };
 
diff --git a/drivers/media/platform/davinci/vpif_capture.c b/drivers/media/platform/davinci/vpif_capture.c
index 81ad6a2..e40eacd1 100644
--- a/drivers/media/platform/davinci/vpif_capture.c
+++ b/drivers/media/platform/davinci/vpif_capture.c
@@ -1464,6 +1464,9 @@ static int vpif_s_input(struct file *file, void *priv, unsigned int index)
 
 	chan_cfg = &config->chan_config[ch->channel_id];
 
+	if (index >= chan_cfg->input_count)
+		return -EINVAL;
+
 	if (common->started) {
 		vpif_err("Streaming in progress\n");
 		return -EBUSY;
@@ -1502,8 +1505,8 @@ static int vpif_s_input(struct file *file, void *priv, unsigned int index)
 		}
 	}
 
-	input = subdev_info->input;
-	output = subdev_info->output;
+	input = chan_cfg->inputs[index].input_route;
+	output = chan_cfg->inputs[index].output_route;
 	ret = v4l2_subdev_call(vpif_obj.sd[sd_index], video, s_routing,
 			input, output, 0);
 	if (ret < 0 && ret != -ENOIOCTLCMD) {
diff --git a/include/media/davinci/vpif_types.h b/include/media/davinci/vpif_types.h
index 1fe46a5..a422ed0 100644
--- a/include/media/davinci/vpif_types.h
+++ b/include/media/davinci/vpif_types.h
@@ -37,8 +37,6 @@ struct vpif_interface {
 struct vpif_subdev_info {
 	const char *name;
 	struct i2c_board_info board_info;
-	u32 input;
-	u32 output;
 	struct vpif_interface vpif_if;
 };
 
@@ -56,6 +54,8 @@ struct vpif_display_config {
 struct vpif_input {
 	struct v4l2_input input;
 	const char *subdev_name;
+	u32 input_route;
+	u32 output_route;
 };
 
 struct vpif_capture_chan_config {
-- 
1.7.10.4


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

* [RFCv2 PATCH 07/14] vpif_capture: first init subdevs, then register device nodes.
  2012-09-20 12:06 ` [RFCv2 PATCH 01/14] vpif_capture: remove unused data structure Hans Verkuil
                     ` (4 preceding siblings ...)
  2012-09-20 12:06   ` [RFCv2 PATCH 06/14] vpif_capture: move routing info from subdev to input Hans Verkuil
@ 2012-09-20 12:06   ` Hans Verkuil
  2012-09-20 12:06   ` [RFCv2 PATCH 08/14] vpif_display: " Hans Verkuil
                     ` (6 subsequent siblings)
  12 siblings, 0 replies; 19+ messages in thread
From: Hans Verkuil @ 2012-09-20 12:06 UTC (permalink / raw)
  To: linux-media; +Cc: Prabhakar Lad, DLOS, Hans Verkuil

From: Hans Verkuil <hans.verkuil@cisco.com>

When device nodes are registered they must be ready for use
immediately, so make sure the subdevs are loaded first.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/platform/davinci/vpif_capture.c |   47 +++++++++++--------------
 1 file changed, 20 insertions(+), 27 deletions(-)

diff --git a/drivers/media/platform/davinci/vpif_capture.c b/drivers/media/platform/davinci/vpif_capture.c
index e40eacd1..98423b5 100644
--- a/drivers/media/platform/davinci/vpif_capture.c
+++ b/drivers/media/platform/davinci/vpif_capture.c
@@ -2139,24 +2139,6 @@ static __init int vpif_probe(struct platform_device *pdev)
 		}
 	}
 
-	for (j = 0; j < VPIF_CAPTURE_MAX_DEVICES; j++) {
-		ch = vpif_obj.dev[j];
-		ch->channel_id = j;
-		common = &(ch->common[VPIF_VIDEO_INDEX]);
-		spin_lock_init(&common->irqlock);
-		mutex_init(&common->lock);
-		ch->video_dev->lock = &common->lock;
-		/* Initialize prio member of channel object */
-		v4l2_prio_init(&ch->prio);
-		err = video_register_device(ch->video_dev,
-					    VFL_TYPE_GRABBER, (j ? 1 : 0));
-		if (err)
-			goto probe_out;
-
-		video_set_drvdata(ch->video_dev, ch);
-
-	}
-
 	i2c_adap = i2c_get_adapter(1);
 	config = pdev->dev.platform_data;
 
@@ -2166,7 +2148,7 @@ static __init int vpif_probe(struct platform_device *pdev)
 	if (vpif_obj.sd == NULL) {
 		vpif_err("unable to allocate memory for subdevice pointers\n");
 		err = -ENOMEM;
-		goto probe_out;
+		goto vpif_dev_alloc_err;
 	}
 
 	for (i = 0; i < subdev_count; i++) {
@@ -2183,19 +2165,27 @@ static __init int vpif_probe(struct platform_device *pdev)
 		}
 		v4l2_info(&vpif_obj.v4l2_dev, "registered sub device %s\n",
 			  subdevdata->name);
-
-		if (vpif_obj.sd[i])
-			vpif_obj.sd[i]->grp_id = 1 << i;
 	}
 
+	for (j = 0; j < VPIF_CAPTURE_MAX_DEVICES; j++) {
+		ch = vpif_obj.dev[j];
+		ch->channel_id = j;
+		common = &(ch->common[VPIF_VIDEO_INDEX]);
+		spin_lock_init(&common->irqlock);
+		mutex_init(&common->lock);
+		ch->video_dev->lock = &common->lock;
+		/* Initialize prio member of channel object */
+		v4l2_prio_init(&ch->prio);
+		video_set_drvdata(ch->video_dev, ch);
+
+		err = video_register_device(ch->video_dev,
+					    VFL_TYPE_GRABBER, (j ? 1 : 0));
+		if (err)
+			goto probe_out;
+	}
 	v4l2_info(&vpif_obj.v4l2_dev, "VPIF capture driver initialized\n");
 	return 0;
 
-probe_subdev_out:
-	/* free sub devices memory */
-	kfree(vpif_obj.sd);
-
-	j = VPIF_CAPTURE_MAX_DEVICES;
 probe_out:
 	for (k = 0; k < j; k++) {
 		/* Get the pointer to the channel object */
@@ -2203,6 +2193,9 @@ probe_out:
 		/* Unregister video device */
 		video_unregister_device(ch->video_dev);
 	}
+probe_subdev_out:
+	/* free sub devices memory */
+	kfree(vpif_obj.sd);
 
 vpif_dev_alloc_err:
 	k = VPIF_CAPTURE_MAX_DEVICES-1;
-- 
1.7.10.4


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

* [RFCv2 PATCH 08/14] vpif_display: first init subdevs, then register device nodes.
  2012-09-20 12:06 ` [RFCv2 PATCH 01/14] vpif_capture: remove unused data structure Hans Verkuil
                     ` (5 preceding siblings ...)
  2012-09-20 12:06   ` [RFCv2 PATCH 07/14] vpif_capture: first init subdevs, then register device nodes Hans Verkuil
@ 2012-09-20 12:06   ` Hans Verkuil
  2012-09-20 12:06   ` [RFCv2 PATCH 09/14] vpif_display: fix cleanup code Hans Verkuil
                     ` (5 subsequent siblings)
  12 siblings, 0 replies; 19+ messages in thread
From: Hans Verkuil @ 2012-09-20 12:06 UTC (permalink / raw)
  To: linux-media; +Cc: Prabhakar Lad, DLOS, Hans Verkuil

From: Hans Verkuil <hans.verkuil@cisco.com>

When device nodes are registered they must be ready for use
immediately, so make sure the subdevs are loaded first.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/platform/davinci/vpif_display.c |   59 ++++++++++++-------------
 1 file changed, 29 insertions(+), 30 deletions(-)

diff --git a/drivers/media/platform/davinci/vpif_display.c b/drivers/media/platform/davinci/vpif_display.c
index f394599..e71c88f 100644
--- a/drivers/media/platform/davinci/vpif_display.c
+++ b/drivers/media/platform/davinci/vpif_display.c
@@ -1689,6 +1689,32 @@ static __init int vpif_probe(struct platform_device *pdev)
 		}
 	}
 
+	i2c_adap = i2c_get_adapter(1);
+	config = pdev->dev.platform_data;
+	subdev_count = config->subdev_count;
+	subdevdata = config->subdevinfo;
+	vpif_obj.sd = kzalloc(sizeof(struct v4l2_subdev *) * subdev_count,
+								GFP_KERNEL);
+	if (vpif_obj.sd == NULL) {
+		vpif_err("unable to allocate memory for subdevice pointers\n");
+		err = -ENOMEM;
+		goto vpif_int_err;
+	}
+
+	for (i = 0; i < subdev_count; i++) {
+		vpif_obj.sd[i] = v4l2_i2c_new_subdev_board(&vpif_obj.v4l2_dev,
+						i2c_adap,
+						&subdevdata[i].board_info,
+						NULL);
+		if (!vpif_obj.sd[i]) {
+			vpif_err("Error registering v4l2 subdevice\n");
+			goto probe_subdev_out;
+		}
+
+		if (vpif_obj.sd[i])
+			vpif_obj.sd[i]->grp_id = 1 << i;
+	}
+
 	for (j = 0; j < VPIF_DISPLAY_MAX_DEVICES; j++) {
 		ch = vpif_obj.dev[j];
 		/* Initialize field of the channel objects */
@@ -1724,6 +1750,7 @@ static __init int vpif_probe(struct platform_device *pdev)
 		ch->common[VPIF_VIDEO_INDEX].fmt.type =
 						V4L2_BUF_TYPE_VIDEO_OUTPUT;
 		ch->video_dev->lock = &common->lock;
+		video_set_drvdata(ch->video_dev, ch);
 
 		/* register video device */
 		vpif_dbg(1, debug, "channel=%x,channel->video_dev=%x\n",
@@ -1733,42 +1760,12 @@ static __init int vpif_probe(struct platform_device *pdev)
 					  VFL_TYPE_GRABBER, (j ? 3 : 2));
 		if (err < 0)
 			goto probe_out;
-
-		video_set_drvdata(ch->video_dev, ch);
-	}
-
-	i2c_adap = i2c_get_adapter(1);
-	config = pdev->dev.platform_data;
-	subdev_count = config->subdev_count;
-	subdevdata = config->subdevinfo;
-	vpif_obj.sd = kzalloc(sizeof(struct v4l2_subdev *) * subdev_count,
-								GFP_KERNEL);
-	if (vpif_obj.sd == NULL) {
-		vpif_err("unable to allocate memory for subdevice pointers\n");
-		err = -ENOMEM;
-		goto probe_out;
-	}
-
-	for (i = 0; i < subdev_count; i++) {
-		vpif_obj.sd[i] = v4l2_i2c_new_subdev_board(&vpif_obj.v4l2_dev,
-						i2c_adap,
-						&subdevdata[i].board_info,
-						NULL);
-		if (!vpif_obj.sd[i]) {
-			vpif_err("Error registering v4l2 subdevice\n");
-			goto probe_subdev_out;
-		}
-
-		if (vpif_obj.sd[i])
-			vpif_obj.sd[i]->grp_id = 1 << i;
 	}
 
 	v4l2_info(&vpif_obj.v4l2_dev,
 			" VPIF display driver initialized\n");
 	return 0;
 
-probe_subdev_out:
-	kfree(vpif_obj.sd);
 probe_out:
 	for (k = 0; k < j; k++) {
 		ch = vpif_obj.dev[k];
@@ -1776,6 +1773,8 @@ probe_out:
 		video_device_release(ch->video_dev);
 		ch->video_dev = NULL;
 	}
+probe_subdev_out:
+	kfree(vpif_obj.sd);
 vpif_int_err:
 	v4l2_device_unregister(&vpif_obj.v4l2_dev);
 	vpif_err("VPIF IRQ request failed\n");
-- 
1.7.10.4


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

* [RFCv2 PATCH 09/14] vpif_display: fix cleanup code.
  2012-09-20 12:06 ` [RFCv2 PATCH 01/14] vpif_capture: remove unused data structure Hans Verkuil
                     ` (6 preceding siblings ...)
  2012-09-20 12:06   ` [RFCv2 PATCH 08/14] vpif_display: " Hans Verkuil
@ 2012-09-20 12:06   ` Hans Verkuil
  2012-09-20 12:06   ` [RFCv2 PATCH 10/14] vpif_capture: " Hans Verkuil
                     ` (4 subsequent siblings)
  12 siblings, 0 replies; 19+ messages in thread
From: Hans Verkuil @ 2012-09-20 12:06 UTC (permalink / raw)
  To: linux-media; +Cc: Prabhakar Lad, DLOS, Hans Verkuil

From: Hans Verkuil <hans.verkuil@cisco.com>

The cleanup sequence was incorrect and could cause a kernel oops.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/platform/davinci/vpif_display.c |   30 +++++++++++++++----------
 1 file changed, 18 insertions(+), 12 deletions(-)

diff --git a/drivers/media/platform/davinci/vpif_display.c b/drivers/media/platform/davinci/vpif_display.c
index e71c88f..66b4b32 100644
--- a/drivers/media/platform/davinci/vpif_display.c
+++ b/drivers/media/platform/davinci/vpif_display.c
@@ -1607,7 +1607,8 @@ static __init int vpif_probe(struct platform_device *pdev)
 {
 	struct vpif_subdev_info *subdevdata;
 	struct vpif_display_config *config;
-	int i, j = 0, k, q, m, err = 0;
+	int i, j = 0, k, err = 0;
+	int res_idx = 0;
 	struct i2c_adapter *i2c_adap;
 	struct common_obj *common;
 	struct channel_obj *ch;
@@ -1630,21 +1631,21 @@ static __init int vpif_probe(struct platform_device *pdev)
 		return err;
 	}
 
-	k = 0;
-	while ((res = platform_get_resource(pdev, IORESOURCE_IRQ, k))) {
+	while ((res = platform_get_resource(pdev, IORESOURCE_IRQ, res_idx))) {
 		for (i = res->start; i <= res->end; i++) {
 			if (request_irq(i, vpif_channel_isr, IRQF_SHARED,
 					"VPIF_Display",
-				(void *)(&vpif_obj.dev[k]->channel_id))) {
+					(void *)(&vpif_obj.dev[res_idx]->channel_id))) {
 				err = -EBUSY;
+				for (j = 0; j < i; j++)
+					free_irq(j, (void *)(&vpif_obj.dev[res_idx]->channel_id));
 				goto vpif_int_err;
 			}
 		}
-		k++;
+		res_idx++;
 	}
 
 	for (i = 0; i < VPIF_DISPLAY_MAX_DEVICES; i++) {
-
 		/* Get the pointer to the channel object */
 		ch = vpif_obj.dev[i];
 
@@ -1698,7 +1699,7 @@ static __init int vpif_probe(struct platform_device *pdev)
 	if (vpif_obj.sd == NULL) {
 		vpif_err("unable to allocate memory for subdevice pointers\n");
 		err = -ENOMEM;
-		goto vpif_int_err;
+		goto vpif_sd_error;
 	}
 
 	for (i = 0; i < subdev_count; i++) {
@@ -1775,14 +1776,19 @@ probe_out:
 	}
 probe_subdev_out:
 	kfree(vpif_obj.sd);
+vpif_sd_error:
+	for (i = 0; i < VPIF_DISPLAY_MAX_DEVICES; i++) {
+		ch = vpif_obj.dev[i];
+		/* Note: does nothing if ch->video_dev == NULL */
+		video_device_release(ch->video_dev);
+	}
 vpif_int_err:
 	v4l2_device_unregister(&vpif_obj.v4l2_dev);
 	vpif_err("VPIF IRQ request failed\n");
-	for (q = k; k >= 0; k--) {
-		for (m = i; m >= res->start; m--)
-			free_irq(m, (void *)(&vpif_obj.dev[k]->channel_id));
-		res = platform_get_resource(pdev, IORESOURCE_IRQ, k-1);
-		m = res->end;
+	for (i = 0; i < res_idx; i++) {
+		res = platform_get_resource(pdev, IORESOURCE_IRQ, i);
+		for (j = res->start; j <= res->end; j++)
+			free_irq(j, (void *)(&vpif_obj.dev[i]->channel_id));
 	}
 
 	return err;
-- 
1.7.10.4


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

* [RFCv2 PATCH 10/14] vpif_capture: fix cleanup code.
  2012-09-20 12:06 ` [RFCv2 PATCH 01/14] vpif_capture: remove unused data structure Hans Verkuil
                     ` (7 preceding siblings ...)
  2012-09-20 12:06   ` [RFCv2 PATCH 09/14] vpif_display: fix cleanup code Hans Verkuil
@ 2012-09-20 12:06   ` Hans Verkuil
  2012-09-20 12:06   ` [RFCv2 PATCH 11/14] vpif_capture: separate subdev from input Hans Verkuil
                     ` (3 subsequent siblings)
  12 siblings, 0 replies; 19+ messages in thread
From: Hans Verkuil @ 2012-09-20 12:06 UTC (permalink / raw)
  To: linux-media; +Cc: Prabhakar Lad, DLOS, Hans Verkuil

From: Hans Verkuil <hans.verkuil@cisco.com>

The cleanup sequence was incorrect and could cause a kernel oops.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/platform/davinci/vpif_capture.c |   41 ++++++++++++-------------
 1 file changed, 20 insertions(+), 21 deletions(-)

diff --git a/drivers/media/platform/davinci/vpif_capture.c b/drivers/media/platform/davinci/vpif_capture.c
index 98423b5..5f81e0f 100644
--- a/drivers/media/platform/davinci/vpif_capture.c
+++ b/drivers/media/platform/davinci/vpif_capture.c
@@ -2060,7 +2060,8 @@ static __init int vpif_probe(struct platform_device *pdev)
 {
 	struct vpif_subdev_info *subdevdata;
 	struct vpif_capture_config *config;
-	int i, j, k, m, q, err;
+	int i, j, k, err;
+	int res_idx = 0;
 	struct i2c_adapter *i2c_adap;
 	struct channel_obj *ch;
 	struct common_obj *common;
@@ -2083,18 +2084,18 @@ static __init int vpif_probe(struct platform_device *pdev)
 		return err;
 	}
 
-	k = 0;
-	while ((res = platform_get_resource(pdev, IORESOURCE_IRQ, k))) {
+	while ((res = platform_get_resource(pdev, IORESOURCE_IRQ, res_idx))) {
 		for (i = res->start; i <= res->end; i++) {
 			if (request_irq(i, vpif_channel_isr, IRQF_SHARED,
 					"VPIF_Capture",
-				(void *)(&vpif_obj.dev[k]->channel_id))) {
+					(void *)(&vpif_obj.dev[res_idx]->channel_id))) {
 				err = -EBUSY;
-				i--;
+				for (j = 0; j < i; j++)
+					free_irq(j, (void *)(&vpif_obj.dev[res_idx]->channel_id));
 				goto vpif_int_err;
 			}
 		}
-		k++;
+		res_idx++;
 	}
 
 	for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) {
@@ -2108,7 +2109,7 @@ static __init int vpif_probe(struct platform_device *pdev)
 				video_device_release(ch->video_dev);
 			}
 			err = -ENOMEM;
-			goto vpif_dev_alloc_err;
+			goto vpif_int_err;
 		}
 
 		/* Initialize field of video device */
@@ -2148,7 +2149,7 @@ static __init int vpif_probe(struct platform_device *pdev)
 	if (vpif_obj.sd == NULL) {
 		vpif_err("unable to allocate memory for subdevice pointers\n");
 		err = -ENOMEM;
-		goto vpif_dev_alloc_err;
+		goto vpif_sd_error;
 	}
 
 	for (i = 0; i < subdev_count; i++) {
@@ -2197,21 +2198,19 @@ probe_subdev_out:
 	/* free sub devices memory */
 	kfree(vpif_obj.sd);
 
-vpif_dev_alloc_err:
-	k = VPIF_CAPTURE_MAX_DEVICES-1;
-	res = platform_get_resource(pdev, IORESOURCE_IRQ, k);
-	i = res->end;
-
-vpif_int_err:
-	for (q = k; q >= 0; q--) {
-		for (m = i; m >= (int)res->start; m--)
-			free_irq(m, (void *)(&vpif_obj.dev[q]->channel_id));
-
-		res = platform_get_resource(pdev, IORESOURCE_IRQ, q-1);
-		if (res)
-			i = res->end;
+vpif_sd_error:
+	for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) {
+		ch = vpif_obj.dev[i];
+		/* Note: does nothing if ch->video_dev == NULL */
+		video_device_release(ch->video_dev);
 	}
+vpif_int_err:
 	v4l2_device_unregister(&vpif_obj.v4l2_dev);
+	for (i = 0; i < res_idx; i++) {
+		res = platform_get_resource(pdev, IORESOURCE_IRQ, i);
+		for (j = res->start; j <= res->end; j++)
+			free_irq(j, (void *)(&vpif_obj.dev[i]->channel_id));
+	}
 	return err;
 }
 
-- 
1.7.10.4


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

* [RFCv2 PATCH 11/14] vpif_capture: separate subdev from input.
  2012-09-20 12:06 ` [RFCv2 PATCH 01/14] vpif_capture: remove unused data structure Hans Verkuil
                     ` (8 preceding siblings ...)
  2012-09-20 12:06   ` [RFCv2 PATCH 10/14] vpif_capture: " Hans Verkuil
@ 2012-09-20 12:06   ` Hans Verkuil
  2012-09-20 12:06   ` [RFCv2 PATCH 12/14] vpif_display: use a v4l2_subdev pointer to call a subdev Hans Verkuil
                     ` (2 subsequent siblings)
  12 siblings, 0 replies; 19+ messages in thread
From: Hans Verkuil @ 2012-09-20 12:06 UTC (permalink / raw)
  To: linux-media; +Cc: Prabhakar Lad, DLOS, Hans Verkuil

From: Hans Verkuil <hans.verkuil@cisco.com>

vpif_capture relied on a 1-1 mapping of input and subdev. This is not
necessarily the case. Separate the two. So there is a list of subdevs
and a list of inputs. Each input refers to a subdev and has routing
information. An input does not have to have a subdev.

The initial input for each channel is set to the fist input.

Currently missing is support for associating multiple subdevs with
an input.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/platform/davinci/vpif_capture.c |  239 ++++++++++++-------------
 drivers/media/platform/davinci/vpif_capture.h |    6 +-
 2 files changed, 113 insertions(+), 132 deletions(-)

diff --git a/drivers/media/platform/davinci/vpif_capture.c b/drivers/media/platform/davinci/vpif_capture.c
index 5f81e0f..f97eb0b 100644
--- a/drivers/media/platform/davinci/vpif_capture.c
+++ b/drivers/media/platform/davinci/vpif_capture.c
@@ -864,13 +864,11 @@ static unsigned int vpif_poll(struct file *filep, poll_table * wait)
  */
 static int vpif_open(struct file *filep)
 {
-	struct vpif_capture_config *config = vpif_dev->platform_data;
 	struct video_device *vdev = video_devdata(filep);
 	struct common_obj *common;
 	struct video_obj *vid_ch;
 	struct channel_obj *ch;
 	struct vpif_fh *fh;
-	int i;
 
 	vpif_dbg(2, debug, "vpif_open\n");
 
@@ -879,24 +877,6 @@ static int vpif_open(struct file *filep)
 	vid_ch = &ch->video;
 	common = &ch->common[VPIF_VIDEO_INDEX];
 
-	if (NULL == ch->curr_subdev_info) {
-		/**
-		 * search through the sub device to see a registered
-		 * sub device and make it as current sub device
-		 */
-		for (i = 0; i < config->subdev_count; i++) {
-			if (vpif_obj.sd[i]) {
-				/* the sub device is registered */
-				ch->curr_subdev_info = &config->subdev_info[i];
-				break;
-			}
-		}
-		if (i == config->subdev_count) {
-			vpif_err("No sub device registered\n");
-			return -ENOENT;
-		}
-	}
-
 	/* Allocate memory for the file handle object */
 	fh = kzalloc(sizeof(struct vpif_fh), GFP_KERNEL);
 	if (NULL == fh) {
@@ -1174,10 +1154,9 @@ static int vpif_streamon(struct file *file, void *priv,
 		return ret;
 
 	/* Enable streamon on the sub device */
-	ret = v4l2_subdev_call(vpif_obj.sd[ch->curr_sd_index], video,
-				s_stream, 1);
+	ret = v4l2_subdev_call(ch->sd, video, s_stream, 1);
 
-	if (ret && (ret != -ENOIOCTLCMD)) {
+	if (ret && ret != -ENOIOCTLCMD && ret != -ENODEV) {
 		vpif_dbg(1, debug, "stream on failed in subdev\n");
 		return ret;
 	}
@@ -1237,73 +1216,105 @@ static int vpif_streamoff(struct file *file, void *priv,
 
 	common->started = 0;
 
-	ret = v4l2_subdev_call(vpif_obj.sd[ch->curr_sd_index], video,
-				s_stream, 0);
+	ret = v4l2_subdev_call(ch->sd, video, s_stream, 0);
 
-	if (ret && (ret != -ENOIOCTLCMD))
+	if (ret && ret != -ENOIOCTLCMD && ret != -ENODEV)
 		vpif_dbg(1, debug, "stream off failed in subdev\n");
 
 	return vb2_streamoff(&common->buffer_queue, buftype);
 }
 
 /**
- * vpif_map_sub_device_to_input() - Maps sub device to input
- * @ch - ptr to channel
- * @config - ptr to capture configuration
+ * vpif_input_to_subdev() - Maps input to sub device
+ * @vpif_cfg - global config ptr
+ * @chan_cfg - channel config ptr
  * @input_index - Given input index from application
- * @sub_device_index - index into sd table
  *
  * lookup the sub device information for a given input index.
  * we report all the inputs to application. inputs table also
  * has sub device name for the each input
  */
-static struct vpif_subdev_info *vpif_map_sub_device_to_input(
-				struct channel_obj *ch,
-				struct vpif_capture_config *vpif_cfg,
-				int input_index,
-				int *sub_device_index)
+static int vpif_input_to_subdev(
+		struct vpif_capture_config *vpif_cfg,
+		struct vpif_capture_chan_config *chan_cfg,
+		int input_index)
 {
-	struct vpif_capture_chan_config *chan_cfg;
-	struct vpif_subdev_info *subdev_info = NULL;
-	const char *subdev_name = NULL;
+	struct vpif_subdev_info *subdev_info;
+	const char *subdev_name;
 	int i;
 
-	vpif_dbg(2, debug, "vpif_map_sub_device_to_input\n");
-
-	chan_cfg = &vpif_cfg->chan_config[ch->channel_id];
+	vpif_dbg(2, debug, "vpif_input_to_subdev\n");
 
-	/**
-	 * search through the inputs to find the sub device supporting
-	 * the input
-	 */
-	for (i = 0; i < chan_cfg->input_count; i++) {
-		/* For each sub device, loop through input */
-		if (i == input_index) {
-			subdev_name = chan_cfg->inputs[i].subdev_name;
-			break;
-		}
-	}
-
-	/* if reached maximum. return null */
-	if (i == chan_cfg->input_count || (NULL == subdev_name))
-		return subdev_info;
+	subdev_name = chan_cfg->inputs[input_index].subdev_name;
+	if (subdev_name == NULL)
+		return -1;
 
 	/* loop through the sub device list to get the sub device info */
 	for (i = 0; i < vpif_cfg->subdev_count; i++) {
 		subdev_info = &vpif_cfg->subdev_info[i];
 		if (!strcmp(subdev_info->name, subdev_name))
-			break;
+			return i;
+	}
+	return -1;
+}
+
+/**
+ * vpif_set_input() - Select an input
+ * @vpif_cfg - global config ptr
+ * @ch - channel
+ * @_index - Given input index from application
+ *
+ * Select the given input.
+ */
+static int vpif_set_input(
+		struct vpif_capture_config *vpif_cfg,
+		struct channel_obj *ch,
+		int index)
+{
+	struct vpif_capture_chan_config *chan_cfg =
+			&vpif_cfg->chan_config[ch->channel_id];
+	struct vpif_subdev_info *subdev_info = NULL;
+	struct v4l2_subdev *sd = NULL;
+	u32 input = 0, output = 0;
+	int sd_index;
+	int ret;
+
+	sd_index = vpif_input_to_subdev(vpif_cfg, chan_cfg, index);
+	if (sd_index >= 0) {
+		sd = vpif_obj.sd[sd_index];
+		subdev_info = &vpif_cfg->subdev_info[sd_index];
 	}
 
-	if (i == vpif_cfg->subdev_count)
-		return subdev_info;
+	/* first setup input path from sub device to vpif */
+	if (sd && vpif_cfg->setup_input_path) {
+		ret = vpif_cfg->setup_input_path(ch->channel_id,
+				       subdev_info->name);
+		if (ret < 0) {
+			vpif_dbg(1, debug, "couldn't setup input path for the"
+				" sub device %s, for input index %d\n",
+				subdev_info->name, index);
+			return ret;
+		}
+	}
 
-	/* check if the sub device is registered */
-	if (NULL == vpif_obj.sd[i])
-		return NULL;
+	if (sd) {
+		input = chan_cfg->inputs[index].input_route;
+		output = chan_cfg->inputs[index].output_route;
+		ret = v4l2_subdev_call(sd, video, s_routing,
+				input, output, 0);
+		if (ret < 0 && ret != -ENOIOCTLCMD) {
+			vpif_dbg(1, debug, "Failed to set input\n");
+			return ret;
+		}
+	}
+	ch->input_idx = index;
+	ch->sd = sd;
+	/* copy interface parameters to vpif */
+	ch->vpifparams.iface = subdev_info->vpif_if;
 
-	*sub_device_index = i;
-	return subdev_info;
+	/* update tvnorms from the sub device input info */
+	ch->video_dev->tvnorms = chan_cfg->inputs[index].input.std;
+	return 0;
 }
 
 /**
@@ -1323,12 +1334,16 @@ static int vpif_querystd(struct file *file, void *priv, v4l2_std_id *std_id)
 	vpif_dbg(2, debug, "vpif_querystd\n");
 
 	/* Call querystd function of decoder device */
-	ret = v4l2_subdev_call(vpif_obj.sd[ch->curr_sd_index], video,
-				querystd, std_id);
-	if (ret < 0)
-		vpif_dbg(1, debug, "Failed to set standard for sub devices\n");
+	ret = v4l2_subdev_call(ch->sd, video, querystd, std_id);
 
-	return ret;
+	if (ret == -ENOIOCTLCMD || ret == -ENODEV)
+		return -ENODATA;
+	if (ret) {
+		vpif_dbg(1, debug, "Failed to query standard for sub devices\n");
+		return ret;
+	}
+
+	return 0;
 }
 
 /**
@@ -1396,11 +1411,12 @@ static int vpif_s_std(struct file *file, void *priv, v4l2_std_id *std_id)
 	vpif_config_format(ch);
 
 	/* set standard in the sub device */
-	ret = v4l2_subdev_call(vpif_obj.sd[ch->curr_sd_index], core,
-				s_std, *std_id);
-	if (ret < 0)
+	ret = v4l2_subdev_call(ch->sd, core, s_std, *std_id);
+	if (ret && ret != -ENOIOCTLCMD && ret != -ENODEV) {
 		vpif_dbg(1, debug, "Failed to set standard for sub devices\n");
-	return ret;
+		return ret;
+	}
+	return 0;
 }
 
 /**
@@ -1458,9 +1474,7 @@ static int vpif_s_input(struct file *file, void *priv, unsigned int index)
 	struct vpif_fh *fh = priv;
 	struct channel_obj *ch = fh->channel;
 	struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
-	struct vpif_subdev_info *subdev_info;
-	int ret = 0, sd_index = 0;
-	u32 input = 0, output = 0;
+	int ret;
 
 	chan_cfg = &config->chan_config[ch->channel_id];
 
@@ -1485,43 +1499,7 @@ static int vpif_s_input(struct file *file, void *priv, unsigned int index)
 		return ret;
 
 	fh->initialized = 1;
-	subdev_info = vpif_map_sub_device_to_input(ch, config, index,
-						   &sd_index);
-	if (NULL == subdev_info) {
-		vpif_dbg(1, debug,
-			"couldn't lookup sub device for the input index\n");
-		return -EINVAL;
-	}
-
-	/* first setup input path from sub device to vpif */
-	if (config->setup_input_path) {
-		ret = config->setup_input_path(ch->channel_id,
-					       subdev_info->name);
-		if (ret < 0) {
-			vpif_dbg(1, debug, "couldn't setup input path for the"
-				" sub device %s, for input index %d\n",
-				subdev_info->name, index);
-			return ret;
-		}
-	}
-
-	input = chan_cfg->inputs[index].input_route;
-	output = chan_cfg->inputs[index].output_route;
-	ret = v4l2_subdev_call(vpif_obj.sd[sd_index], video, s_routing,
-			input, output, 0);
-	if (ret < 0 && ret != -ENOIOCTLCMD) {
-		vpif_dbg(1, debug, "Failed to set input\n");
-		return ret;
-	}
-	ch->input_idx = index;
-	ch->curr_subdev_info = subdev_info;
-	ch->curr_sd_index = sd_index;
-	/* copy interface parameters to vpif */
-	ch->vpifparams.iface = subdev_info->vpif_if;
-
-	/* update tvnorms from the sub device input info */
-	ch->video_dev->tvnorms = chan_cfg->inputs[index].input.std;
-	return 0;
+	return vpif_set_input(config, ch, index);
 }
 
 /**
@@ -1727,9 +1705,12 @@ vpif_enum_dv_timings(struct file *file, void *priv,
 {
 	struct vpif_fh *fh = priv;
 	struct channel_obj *ch = fh->channel;
+	int ret;
 
-	return v4l2_subdev_call(vpif_obj.sd[ch->curr_sd_index],
-				video, enum_dv_timings, timings);
+	ret = v4l2_subdev_call(ch->sd, video, enum_dv_timings, timings);
+	if (ret == -ENOIOCTLCMD && ret == -ENODEV)
+		return -EINVAL;
+	return ret;
 }
 
 /**
@@ -1744,9 +1725,12 @@ vpif_query_dv_timings(struct file *file, void *priv,
 {
 	struct vpif_fh *fh = priv;
 	struct channel_obj *ch = fh->channel;
+	int ret;
 
-	return v4l2_subdev_call(vpif_obj.sd[ch->curr_sd_index],
-				video, query_dv_timings, timings);
+	ret = v4l2_subdev_call(ch->sd, video, query_dv_timings, timings);
+	if (ret == -ENOIOCTLCMD && ret == -ENODEV)
+		return -ENODATA;
+	return ret;
 }
 
 /**
@@ -1772,13 +1756,9 @@ static int vpif_s_dv_timings(struct file *file, void *priv,
 	}
 
 	/* Configure subdevice timings, if any */
-	ret = v4l2_subdev_call(vpif_obj.sd[ch->curr_sd_index],
-			video, s_dv_timings, timings);
-	if (ret == -ENOIOCTLCMD) {
-		vpif_dbg(2, debug, "Custom DV timings not supported by "
-				"subdevice\n");
-		return -EINVAL;
-	}
+	ret = v4l2_subdev_call(ch->sd, video, s_dv_timings, timings);
+	if (ret == -ENOIOCTLCMD || ret == -ENODEV)
+		ret = 0;
 	if (ret < 0) {
 		vpif_dbg(2, debug, "Error setting custom DV timings\n");
 		return ret;
@@ -1903,8 +1883,7 @@ static int vpif_dbg_g_register(struct file *file, void *priv,
 	struct vpif_fh *fh = priv;
 	struct channel_obj *ch = fh->channel;
 
-	return v4l2_subdev_call(vpif_obj.sd[ch->curr_sd_index], core,
-			g_register, reg);
+	return v4l2_subdev_call(ch->sd, core, g_register, reg);
 }
 
 /*
@@ -1921,8 +1900,7 @@ static int vpif_dbg_s_register(struct file *file, void *priv,
 	struct vpif_fh *fh = priv;
 	struct channel_obj *ch = fh->channel;
 
-	return v4l2_subdev_call(vpif_obj.sd[ch->curr_sd_index], core,
-			s_register, reg);
+	return v4l2_subdev_call(ch->sd, core, s_register, reg);
 }
 #endif
 
@@ -2179,6 +2157,11 @@ static __init int vpif_probe(struct platform_device *pdev)
 		v4l2_prio_init(&ch->prio);
 		video_set_drvdata(ch->video_dev, ch);
 
+		/* select input 0 */
+		err = vpif_set_input(config, ch, 0);
+		if (err)
+			goto probe_out;
+
 		err = video_register_device(ch->video_dev,
 					    VFL_TYPE_GRABBER, (j ? 1 : 0));
 		if (err)
diff --git a/drivers/media/platform/davinci/vpif_capture.h b/drivers/media/platform/davinci/vpif_capture.h
index a284667..98c8e69 100644
--- a/drivers/media/platform/davinci/vpif_capture.h
+++ b/drivers/media/platform/davinci/vpif_capture.h
@@ -117,12 +117,10 @@ struct channel_obj {
 	u8 initialized;
 	/* Identifies channel */
 	enum vpif_channel_id channel_id;
-	/* index into sd table */
-	int curr_sd_index;
 	/* Current input */
 	u32 input_idx;
-	/* ptr to current sub device information */
-	struct vpif_subdev_info *curr_subdev_info;
+	/* subdev corresponding to the current input, may be NULL */
+	struct v4l2_subdev *sd;
 	/* vpif configuration params */
 	struct vpif_params vpifparams;
 	/* common object array */
-- 
1.7.10.4


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

* [RFCv2 PATCH 12/14] vpif_display: use a v4l2_subdev pointer to call a subdev.
  2012-09-20 12:06 ` [RFCv2 PATCH 01/14] vpif_capture: remove unused data structure Hans Verkuil
                     ` (9 preceding siblings ...)
  2012-09-20 12:06   ` [RFCv2 PATCH 11/14] vpif_capture: separate subdev from input Hans Verkuil
@ 2012-09-20 12:06   ` Hans Verkuil
  2012-09-20 12:06   ` [RFCv2 PATCH 13/14] davinci: move struct vpif_interface to chan_cfg Hans Verkuil
  2012-09-20 12:06   ` [RFCv2 PATCH 14/14] tvp514x: s_routing should just change routing, not try to detect a signal Hans Verkuil
  12 siblings, 0 replies; 19+ messages in thread
From: Hans Verkuil @ 2012-09-20 12:06 UTC (permalink / raw)
  To: linux-media; +Cc: Prabhakar Lad, DLOS, Hans Verkuil

From: Hans Verkuil <hans.verkuil@cisco.com>

This makes it easier to have outputs without subdevs.
This needs more work. The way the outputs are configured should be identical
to how inputs are configured.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/platform/davinci/vpif_display.c |   17 +++++++++--------
 drivers/media/platform/davinci/vpif_display.h |    1 +
 2 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/drivers/media/platform/davinci/vpif_display.c b/drivers/media/platform/davinci/vpif_display.c
index 66b4b32..8d1ce09 100644
--- a/drivers/media/platform/davinci/vpif_display.c
+++ b/drivers/media/platform/davinci/vpif_display.c
@@ -1246,6 +1246,8 @@ static int vpif_s_output(struct file *file, void *priv, unsigned int i)
 		vpif_err("Failed to set output standard\n");
 
 	ch->output_idx = i;
+	if (vpif_obj.sd[i])
+		ch->sd = vpif_obj.sd[i];
 	return ret;
 }
 
@@ -1317,14 +1319,13 @@ static int vpif_s_dv_timings(struct file *file, void *priv,
 	}
 
 	/* Configure subdevice timings, if any */
-	ret = v4l2_subdev_call(vpif_obj.sd[ch->output_idx],
-			video, s_dv_timings, timings);
+	ret = v4l2_subdev_call(ch->sd, video, s_dv_timings, timings);
 	if (ret == -ENOIOCTLCMD) {
 		vpif_dbg(2, debug, "Custom DV timings not supported by "
 				"subdevice\n");
-		return -EINVAL;
+		return -ENODATA;
 	}
-	if (ret < 0) {
+	if (ret < 0 && ret != -ENODEV) {
 		vpif_dbg(2, debug, "Error setting custom DV timings\n");
 		return ret;
 	}
@@ -1449,8 +1450,7 @@ static int vpif_dbg_g_register(struct file *file, void *priv,
 	struct vpif_fh *fh = priv;
 	struct channel_obj *ch = fh->channel;
 
-	return v4l2_subdev_call(vpif_obj.sd[ch->output_idx], core,
-			g_register, reg);
+	return v4l2_subdev_call(ch->sd, core, g_register, reg);
 }
 
 /*
@@ -1467,8 +1467,7 @@ static int vpif_dbg_s_register(struct file *file, void *priv,
 	struct vpif_fh *fh = priv;
 	struct channel_obj *ch = fh->channel;
 
-	return v4l2_subdev_call(vpif_obj.sd[ch->output_idx], core,
-			s_register, reg);
+	return v4l2_subdev_call(ch->sd, core, s_register, reg);
 }
 #endif
 
@@ -1737,6 +1736,8 @@ static __init int vpif_probe(struct platform_device *pdev)
 
 		}
 		ch->initialized = 0;
+		if (subdev_count)
+			ch->sd = vpif_obj.sd[0];
 		ch->channel_id = j;
 		if (j < 2)
 			ch->common[VPIF_VIDEO_INDEX].numbuffers =
diff --git a/drivers/media/platform/davinci/vpif_display.h b/drivers/media/platform/davinci/vpif_display.h
index 805704c..dca2a8c0 100644
--- a/drivers/media/platform/davinci/vpif_display.h
+++ b/drivers/media/platform/davinci/vpif_display.h
@@ -125,6 +125,7 @@ struct channel_obj {
 	u8 initialized;			/* flag to indicate whether
 					 * encoder is initialized */
 	u32 output_idx;			/* Current output index */
+	struct v4l2_subdev *sd;		/* Current output subdev (may be NULL) */
 
 	enum vpif_channel_id channel_id;/* Identifies channel */
 	struct vpif_params vpifparams;
-- 
1.7.10.4


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

* [RFCv2 PATCH 13/14] davinci: move struct vpif_interface to chan_cfg.
  2012-09-20 12:06 ` [RFCv2 PATCH 01/14] vpif_capture: remove unused data structure Hans Verkuil
                     ` (10 preceding siblings ...)
  2012-09-20 12:06   ` [RFCv2 PATCH 12/14] vpif_display: use a v4l2_subdev pointer to call a subdev Hans Verkuil
@ 2012-09-20 12:06   ` Hans Verkuil
  2012-10-03  8:55     ` Sekhar Nori
  2012-09-20 12:06   ` [RFCv2 PATCH 14/14] tvp514x: s_routing should just change routing, not try to detect a signal Hans Verkuil
  12 siblings, 1 reply; 19+ messages in thread
From: Hans Verkuil @ 2012-09-20 12:06 UTC (permalink / raw)
  To: linux-media; +Cc: Prabhakar Lad, DLOS, Hans Verkuil

From: Hans Verkuil <hans.verkuil@cisco.com>

struct vpif_interface is channel specific, not subdev specific.
Move it to the channel config.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 arch/arm/mach-davinci/board-da850-evm.c       |   24 ++++++++++++------------
 arch/arm/mach-davinci/board-dm646x-evm.c      |   24 ++++++++++++------------
 drivers/media/platform/davinci/vpif_capture.c |    2 +-
 include/media/davinci/vpif_types.h            |    2 +-
 4 files changed, 26 insertions(+), 26 deletions(-)

diff --git a/arch/arm/mach-davinci/board-da850-evm.c b/arch/arm/mach-davinci/board-da850-evm.c
index 514d4d4..3081ea4 100644
--- a/arch/arm/mach-davinci/board-da850-evm.c
+++ b/arch/arm/mach-davinci/board-da850-evm.c
@@ -1211,12 +1211,6 @@ static struct vpif_subdev_info da850_vpif_capture_sdev_info[] = {
 			I2C_BOARD_INFO("tvp5146", 0x5d),
 			.platform_data = &tvp5146_pdata,
 		},
-		.vpif_if = {
-			.if_type = VPIF_IF_BT656,
-			.hd_pol  = 1,
-			.vd_pol  = 1,
-			.fid_pol = 0,
-		},
 	},
 	{
 		.name = TVP5147_CH1,
@@ -1224,12 +1218,6 @@ static struct vpif_subdev_info da850_vpif_capture_sdev_info[] = {
 			I2C_BOARD_INFO("tvp5146", 0x5c),
 			.platform_data = &tvp5146_pdata,
 		},
-		.vpif_if = {
-			.if_type = VPIF_IF_BT656,
-			.hd_pol  = 1,
-			.vd_pol  = 1,
-			.fid_pol = 0,
-		},
 	},
 };
 
@@ -1239,10 +1227,22 @@ static struct vpif_capture_config da850_vpif_capture_config = {
 	.chan_config[0] = {
 		.inputs = da850_ch0_inputs,
 		.input_count = ARRAY_SIZE(da850_ch0_inputs),
+		.vpif_if = {
+			.if_type = VPIF_IF_BT656,
+			.hd_pol  = 1,
+			.vd_pol  = 1,
+			.fid_pol = 0,
+		},
 	},
 	.chan_config[1] = {
 		.inputs = da850_ch1_inputs,
 		.input_count = ARRAY_SIZE(da850_ch1_inputs),
+		.vpif_if = {
+			.if_type = VPIF_IF_BT656,
+			.hd_pol  = 1,
+			.vd_pol  = 1,
+			.fid_pol = 0,
+		},
 	},
 	.card_name = "DA850/OMAP-L138 Video Capture",
 };
diff --git a/arch/arm/mach-davinci/board-dm646x-evm.c b/arch/arm/mach-davinci/board-dm646x-evm.c
index 0daec7e..ad249c7 100644
--- a/arch/arm/mach-davinci/board-dm646x-evm.c
+++ b/arch/arm/mach-davinci/board-dm646x-evm.c
@@ -601,12 +601,6 @@ static struct vpif_subdev_info vpif_capture_sdev_info[] = {
 			I2C_BOARD_INFO("tvp5146", 0x5d),
 			.platform_data = &tvp5146_pdata,
 		},
-		.vpif_if = {
-			.if_type = VPIF_IF_BT656,
-			.hd_pol = 1,
-			.vd_pol = 1,
-			.fid_pol = 0,
-		},
 	},
 	{
 		.name	= TVP5147_CH1,
@@ -614,12 +608,6 @@ static struct vpif_subdev_info vpif_capture_sdev_info[] = {
 			I2C_BOARD_INFO("tvp5146", 0x5c),
 			.platform_data = &tvp5146_pdata,
 		},
-		.vpif_if = {
-			.if_type = VPIF_IF_BT656,
-			.hd_pol = 1,
-			.vd_pol = 1,
-			.fid_pol = 0,
-		},
 	},
 };
 
@@ -659,10 +647,22 @@ static struct vpif_capture_config dm646x_vpif_capture_cfg = {
 	.chan_config[0] = {
 		.inputs = dm6467_ch0_inputs,
 		.input_count = ARRAY_SIZE(dm6467_ch0_inputs),
+		.vpif_if = {
+			.if_type = VPIF_IF_BT656,
+			.hd_pol = 1,
+			.vd_pol = 1,
+			.fid_pol = 0,
+		},
 	},
 	.chan_config[1] = {
 		.inputs = dm6467_ch1_inputs,
 		.input_count = ARRAY_SIZE(dm6467_ch1_inputs),
+		.vpif_if = {
+			.if_type = VPIF_IF_BT656,
+			.hd_pol = 1,
+			.vd_pol = 1,
+			.fid_pol = 0,
+		},
 	},
 };
 
diff --git a/drivers/media/platform/davinci/vpif_capture.c b/drivers/media/platform/davinci/vpif_capture.c
index f97eb0b..4828888 100644
--- a/drivers/media/platform/davinci/vpif_capture.c
+++ b/drivers/media/platform/davinci/vpif_capture.c
@@ -1310,7 +1310,7 @@ static int vpif_set_input(
 	ch->input_idx = index;
 	ch->sd = sd;
 	/* copy interface parameters to vpif */
-	ch->vpifparams.iface = subdev_info->vpif_if;
+	ch->vpifparams.iface = chan_cfg->vpif_if;
 
 	/* update tvnorms from the sub device input info */
 	ch->video_dev->tvnorms = chan_cfg->inputs[index].input.std;
diff --git a/include/media/davinci/vpif_types.h b/include/media/davinci/vpif_types.h
index a422ed0..65e8fe1 100644
--- a/include/media/davinci/vpif_types.h
+++ b/include/media/davinci/vpif_types.h
@@ -37,7 +37,6 @@ struct vpif_interface {
 struct vpif_subdev_info {
 	const char *name;
 	struct i2c_board_info board_info;
-	struct vpif_interface vpif_if;
 };
 
 struct vpif_display_config {
@@ -59,6 +58,7 @@ struct vpif_input {
 };
 
 struct vpif_capture_chan_config {
+	struct vpif_interface vpif_if;
 	const struct vpif_input *inputs;
 	int input_count;
 };
-- 
1.7.10.4


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

* [RFCv2 PATCH 14/14] tvp514x: s_routing should just change routing, not try to detect a signal.
  2012-09-20 12:06 ` [RFCv2 PATCH 01/14] vpif_capture: remove unused data structure Hans Verkuil
                     ` (11 preceding siblings ...)
  2012-09-20 12:06   ` [RFCv2 PATCH 13/14] davinci: move struct vpif_interface to chan_cfg Hans Verkuil
@ 2012-09-20 12:06   ` Hans Verkuil
  12 siblings, 0 replies; 19+ messages in thread
From: Hans Verkuil @ 2012-09-20 12:06 UTC (permalink / raw)
  To: linux-media; +Cc: Prabhakar Lad, DLOS, Hans Verkuil

From: Hans Verkuil <hans.verkuil@cisco.com>

The s_routing function should not try to detect a signal. It is a really
bad idea to try to detect a valid video signal and return an error if
you can't. Changing input should do just that and nothing more.

Also don't power on the ADCs on s_routing, instead do that on querystd.

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

diff --git a/drivers/media/i2c/tvp514x.c b/drivers/media/i2c/tvp514x.c
index 1f3943b..d5e1021 100644
--- a/drivers/media/i2c/tvp514x.c
+++ b/drivers/media/i2c/tvp514x.c
@@ -519,6 +519,12 @@ static int tvp514x_querystd(struct v4l2_subdev *sd, v4l2_std_id *std_id)
 
 	*std_id = V4L2_STD_UNKNOWN;
 
+	/* To query the standard the TVP514x must power on the ADCs. */
+	if (!decoder->streaming) {
+		tvp514x_s_stream(sd, 1);
+		msleep(LOCK_RETRY_DELAY);
+	}
+
 	/* query the current standard */
 	current_std = tvp514x_query_current_std(sd);
 	if (current_std == STD_INVALID)
@@ -625,25 +631,12 @@ static int tvp514x_s_routing(struct v4l2_subdev *sd,
 	int err;
 	enum tvp514x_input input_sel;
 	enum tvp514x_output output_sel;
-	u8 sync_lock_status, lock_mask;
-	int try_count = LOCK_RETRY_COUNT;
 
 	if ((input >= INPUT_INVALID) ||
 			(output >= OUTPUT_INVALID))
 		/* Index out of bound */
 		return -EINVAL;
 
-	/*
-	 * For the sequence streamon -> streamoff and again s_input
-	 * it fails to lock the signal, since streamoff puts TVP514x
-	 * into power off state which leads to failure in sub-sequent s_input.
-	 *
-	 * So power up the TVP514x device here, since it is important to lock
-	 * the signal at this stage.
-	 */
-	if (!decoder->streaming)
-		tvp514x_s_stream(sd, 1);
-
 	input_sel = input;
 	output_sel = output;
 
@@ -660,64 +653,6 @@ static int tvp514x_s_routing(struct v4l2_subdev *sd,
 
 	decoder->tvp514x_regs[REG_INPUT_SEL].val = input_sel;
 	decoder->tvp514x_regs[REG_OUTPUT_FORMATTER1].val = output_sel;
-
-	/* Clear status */
-	msleep(LOCK_RETRY_DELAY);
-	err =
-	    tvp514x_write_reg(sd, REG_CLEAR_LOST_LOCK, 0x01);
-	if (err)
-		return err;
-
-	switch (input_sel) {
-	case INPUT_CVBS_VI1A:
-	case INPUT_CVBS_VI1B:
-	case INPUT_CVBS_VI1C:
-	case INPUT_CVBS_VI2A:
-	case INPUT_CVBS_VI2B:
-	case INPUT_CVBS_VI2C:
-	case INPUT_CVBS_VI3A:
-	case INPUT_CVBS_VI3B:
-	case INPUT_CVBS_VI3C:
-	case INPUT_CVBS_VI4A:
-		lock_mask = STATUS_CLR_SUBCAR_LOCK_BIT |
-			STATUS_HORZ_SYNC_LOCK_BIT |
-			STATUS_VIRT_SYNC_LOCK_BIT;
-		break;
-
-	case INPUT_SVIDEO_VI2A_VI1A:
-	case INPUT_SVIDEO_VI2B_VI1B:
-	case INPUT_SVIDEO_VI2C_VI1C:
-	case INPUT_SVIDEO_VI2A_VI3A:
-	case INPUT_SVIDEO_VI2B_VI3B:
-	case INPUT_SVIDEO_VI2C_VI3C:
-	case INPUT_SVIDEO_VI4A_VI1A:
-	case INPUT_SVIDEO_VI4A_VI1B:
-	case INPUT_SVIDEO_VI4A_VI1C:
-	case INPUT_SVIDEO_VI4A_VI3A:
-	case INPUT_SVIDEO_VI4A_VI3B:
-	case INPUT_SVIDEO_VI4A_VI3C:
-		lock_mask = STATUS_HORZ_SYNC_LOCK_BIT |
-			STATUS_VIRT_SYNC_LOCK_BIT;
-		break;
-	/* Need to add other interfaces*/
-	default:
-		return -EINVAL;
-	}
-
-	while (try_count-- > 0) {
-		/* Allow decoder to sync up with new input */
-		msleep(LOCK_RETRY_DELAY);
-
-		sync_lock_status = tvp514x_read_reg(sd,
-				REG_STATUS1);
-		if (lock_mask == (sync_lock_status & lock_mask))
-			/* Input detected */
-			break;
-	}
-
-	if (try_count < 0)
-		return -EINVAL;
-
 	decoder->input = input;
 	decoder->output = output;
 
-- 
1.7.10.4


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

* Re: [RFCv2 PATCH 00/14] davinci: clean up input/output/subdev config
  2012-09-20 12:06 [RFCv2 PATCH 00/14] davinci: clean up input/output/subdev config Hans Verkuil
  2012-09-20 12:06 ` [RFCv2 PATCH 01/14] vpif_capture: remove unused data structure Hans Verkuil
@ 2012-09-22 15:58 ` Prabhakar Lad
  1 sibling, 0 replies; 19+ messages in thread
From: Prabhakar Lad @ 2012-09-22 15:58 UTC (permalink / raw)
  To: Hans Verkuil; +Cc: linux-media, DLOS

Hi Hans,

Thanks for the patchset.

On Thu, Sep 20, 2012 at 5:36 PM, Hans Verkuil <hverkuil@xs4all.nl> wrote:
> Hi Prabhakar,
>
> This is the second patch series for a vpif driver cleanup.
>
> The first version can be found here:
>
> http://www.mail-archive.com/linux-media@vger.kernel.org/msg52136.html
>
> Changes since RFCv1:
>
> - rebased to a newer git repo:
>   http://git.linuxtv.org/mhadli/v4l-dvb-davinci_devices.git/shortlog/refs/heads/da850_vpif_machine
>
> - fixed probe() cleanup code in both display and capture that was seriously
>   broken.
>
> - fixed a broken s_routing implementation in the tvp514x driver: if there
>   is no incoming video signal, then s_routing would return EINVAL and
>   leave the driver with an inconsistent internal state. This has always
>   been a problem, but with this patch series it suddenly became really
>   noticable. s_routing shouldn't try to wait for a valid signal, that's
>   not what s_routing should do.
>
> This patch series does some driver cleanup and reorganizes the config
> structs that are used to set up subdevices.
>
> The current driver associates an input or output with a subdev, but multiple
> inputs may use the same subdev and some inputs may not use a subdev at all
> (this is the case for our hardware).
>
> Several other things were also configured in the wrong structure. For
> example the vpif_interface struct is really part of the channel config
> and has nothing to do with the subdev.
>

Acked-by: Prabhakar Lad <prabhakar.lad@ti.com>
Tested-by: Prabhakar Lad <prabhakar.lad@ti.com>

> What is missing here is that the output doesn't have the same flexibility
> as the input when it comes to configuration. It would be good if someone
> can pick this up as a follow-up since it's unlikely I'll be working on
> that.
>
Working on it.

Regards,
--Prabhakar Lad

> What would also be nice is that by leaving the inputs or outputs for the
> second channel empty (NULL) in the configuration you can disable the second
> video node, e.g. trying to use it will always result in ENODEV or something.
>
> This patch series will at least make things more flexible.
>
> Regards,
>
>         Hans
>

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

* Re: [RFCv2 PATCH 05/14] vpif_capture: remove unnecessary can_route flag.
  2012-09-20 12:06   ` [RFCv2 PATCH 05/14] vpif_capture: remove unnecessary can_route flag Hans Verkuil
@ 2012-10-03  8:43     ` Sekhar Nori
  0 siblings, 0 replies; 19+ messages in thread
From: Sekhar Nori @ 2012-10-03  8:43 UTC (permalink / raw)
  To: Hans Verkuil; +Cc: linux-media, Hans Verkuil, DLOS

On 9/20/2012 5:36 PM, Hans Verkuil wrote:
> From: Hans Verkuil <hans.verkuil@cisco.com>
> 
> Calling a subdev op that isn't implemented will just return -ENOIOCTLCMD
> No need to have a flag for that.
> 
> Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>

For the DaVinci platform change:

Acked-by: Sekhar Nori <nsekhar@ti.com>

Thanks,
Sekhar

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

* Re: [RFCv2 PATCH 06/14] vpif_capture: move routing info from subdev to input.
  2012-09-20 12:06   ` [RFCv2 PATCH 06/14] vpif_capture: move routing info from subdev to input Hans Verkuil
@ 2012-10-03  8:46     ` Sekhar Nori
  0 siblings, 0 replies; 19+ messages in thread
From: Sekhar Nori @ 2012-10-03  8:46 UTC (permalink / raw)
  To: Hans Verkuil; +Cc: linux-media, Hans Verkuil, DLOS

On 9/20/2012 5:36 PM, Hans Verkuil wrote:
> From: Hans Verkuil <hans.verkuil@cisco.com>
> 
> Routing information is a property of the input, not of the subdev.
> One subdev may provide multiple inputs, each with its own routing
> information.
> 
> Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>

For the DaVinci platform change:

Acked-by: Sekhar Nori <nsekhar@ti.com>

Thanks,
Sekhar

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

* Re: [RFCv2 PATCH 13/14] davinci: move struct vpif_interface to chan_cfg.
  2012-09-20 12:06   ` [RFCv2 PATCH 13/14] davinci: move struct vpif_interface to chan_cfg Hans Verkuil
@ 2012-10-03  8:55     ` Sekhar Nori
  0 siblings, 0 replies; 19+ messages in thread
From: Sekhar Nori @ 2012-10-03  8:55 UTC (permalink / raw)
  To: Hans Verkuil; +Cc: linux-media, Hans Verkuil, DLOS

On 9/20/2012 5:36 PM, Hans Verkuil wrote:
> From: Hans Verkuil <hans.verkuil@cisco.com>
> 
> struct vpif_interface is channel specific, not subdev specific.
> Move it to the channel config.
> 
> Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>

For the DaVinci platform changes:

Acked-by: Sekhar Nori <nsekhar@ti.com>

Thanks,
Sekhar

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

end of thread, other threads:[~2012-10-03  8:55 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-20 12:06 [RFCv2 PATCH 00/14] davinci: clean up input/output/subdev config Hans Verkuil
2012-09-20 12:06 ` [RFCv2 PATCH 01/14] vpif_capture: remove unused data structure Hans Verkuil
2012-09-20 12:06   ` [RFCv2 PATCH 02/14] vpif_display: remove unused data structures Hans Verkuil
2012-09-20 12:06   ` [RFCv2 PATCH 03/14] vpif_capture: move input_idx to channel_obj Hans Verkuil
2012-09-20 12:06   ` [RFCv2 PATCH 04/14] vpif_display: move output_id " Hans Verkuil
2012-09-20 12:06   ` [RFCv2 PATCH 05/14] vpif_capture: remove unnecessary can_route flag Hans Verkuil
2012-10-03  8:43     ` Sekhar Nori
2012-09-20 12:06   ` [RFCv2 PATCH 06/14] vpif_capture: move routing info from subdev to input Hans Verkuil
2012-10-03  8:46     ` Sekhar Nori
2012-09-20 12:06   ` [RFCv2 PATCH 07/14] vpif_capture: first init subdevs, then register device nodes Hans Verkuil
2012-09-20 12:06   ` [RFCv2 PATCH 08/14] vpif_display: " Hans Verkuil
2012-09-20 12:06   ` [RFCv2 PATCH 09/14] vpif_display: fix cleanup code Hans Verkuil
2012-09-20 12:06   ` [RFCv2 PATCH 10/14] vpif_capture: " Hans Verkuil
2012-09-20 12:06   ` [RFCv2 PATCH 11/14] vpif_capture: separate subdev from input Hans Verkuil
2012-09-20 12:06   ` [RFCv2 PATCH 12/14] vpif_display: use a v4l2_subdev pointer to call a subdev Hans Verkuil
2012-09-20 12:06   ` [RFCv2 PATCH 13/14] davinci: move struct vpif_interface to chan_cfg Hans Verkuil
2012-10-03  8:55     ` Sekhar Nori
2012-09-20 12:06   ` [RFCv2 PATCH 14/14] tvp514x: s_routing should just change routing, not try to detect a signal Hans Verkuil
2012-09-22 15:58 ` [RFCv2 PATCH 00/14] davinci: clean up input/output/subdev config Prabhakar Lad

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).