public inbox for devicetree@vger.kernel.org
 help / color / mirror / Atom feed
From: Marco Felsch <m.felsch@pengutronix.de>
To: mchehab@kernel.org, sakari.ailus@linux.intel.com,
	hans.verkuil@cisco.com, jacopo+renesas@jmondi.org,
	robh+dt@kernel.org, laurent.pinchart@ideasonboard.com
Cc: devicetree@vger.kernel.org, kernel@pengutronix.de,
	linux-media@vger.kernel.org
Subject: [PATCH v13 20/21] media: tvp5150: add support to limit sdtv standards
Date: Thu, 12 Mar 2020 11:31:55 +0100	[thread overview]
Message-ID: <20200312103156.3178-21-m.felsch@pengutronix.de> (raw)
In-Reply-To: <20200312103156.3178-1-m.felsch@pengutronix.de>

The tvp5150 accepts NTSC(M,J,4.43), PAL (B,D,G,H,I,M,N) and SECAM video
data and is able to auto-detect the input signal. The auto-detection
does not work if the connector does not receive an input signal and the
tvp5150 might not be configured correctly. This misconfiguration leads
into wrong decoded video streams if the tvp5150 gets powered on before
the video signal is present.

Limit the supported sdtv standards according to the actual selected
connector to avoid a misconfiguration.

Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
[1] https://patchwork.kernel.org/cover/10794703/

v12:
- use unique v4l2c naming
- move tv-norm check to new tvp5150_validate_connectors()

v11:
- address 80 character warnings by:
  - use struct v4l2_fwnode_connector *v4lc
  - add truct v4l2_fwnode_connector_analog *v4lca

v8:
- adapt commit message
- fix rebasing issue
- apdapt to new v4l2_fwnode_connector_analog naming
- fix cur_connector update during tvp5150_link_setup()
  -> Only update if we have of-connectors.
- fix supported_stds detection during tvp5150_s_std()
  -> use connectors_num to detect of-connectors presence

v5:
- probe() initialize supported tv-norms according the given connectors
  if they are available.
- check if media-controller is used. Don't limit the norm if it isn't
  used.
- add more logic to be smarter during connector changing so it is
  intuitiver for the user space.

v2-v4:
- nothing since the patch was squashed from series [1] into this
  series.
---
 drivers/media/i2c/tvp5150.c | 76 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 74 insertions(+), 2 deletions(-)

diff --git a/drivers/media/i2c/tvp5150.c b/drivers/media/i2c/tvp5150.c
index f28739d5830c..edf0c695bbee 100644
--- a/drivers/media/i2c/tvp5150.c
+++ b/drivers/media/i2c/tvp5150.c
@@ -34,6 +34,13 @@
 #define TVP5150_MBUS_FMT	MEDIA_BUS_FMT_UYVY8_2X8
 #define TVP5150_FIELD		V4L2_FIELD_ALTERNATE
 #define TVP5150_COLORSPACE	V4L2_COLORSPACE_SMPTE170M
+#define TVP5150_STD_MASK	(V4L2_STD_NTSC     | \
+				 V4L2_STD_NTSC_443 | \
+				 V4L2_STD_PAL      | \
+				 V4L2_STD_PAL_M    | \
+				 V4L2_STD_PAL_N    | \
+				 V4L2_STD_PAL_Nc   | \
+				 V4L2_STD_SECAM)
 
 #define TVP5150_MAX_CONNECTORS	3 /* Check dt-bindings for more information */
 
@@ -66,6 +73,7 @@ struct tvp5150 {
 
 	struct media_pad pads[TVP5150_NUM_PADS];
 	struct tvp5150_connector connectors[TVP5150_MAX_CONNECTORS];
+	struct tvp5150_connector *cur_connector;
 	unsigned int connectors_num;
 
 	struct v4l2_ctrl_handler hdl;
@@ -785,17 +793,33 @@ static int tvp5150_g_std(struct v4l2_subdev *sd, v4l2_std_id *std)
 static int tvp5150_s_std(struct v4l2_subdev *sd, v4l2_std_id std)
 {
 	struct tvp5150 *decoder = to_tvp5150(sd);
+	struct tvp5150_connector *cur_con = decoder->cur_connector;
+	v4l2_std_id supported_stds;
 
 	if (decoder->norm == std)
 		return 0;
 
+	/* In case of no of-connectors are available no limitations are made */
+	if (!decoder->connectors_num)
+		supported_stds = V4L2_STD_ALL;
+	else
+		supported_stds = cur_con->base.connector.analog.sdtv_stds;
+
+	/*
+	 * Check if requested std or group of std's is/are supported by the
+	 * connector.
+	 */
+	if ((supported_stds & std) == 0)
+		return -EINVAL;
+
 	/* Change cropping height limits */
 	if (std & V4L2_STD_525_60)
 		decoder->rect.height = TVP5150_V_MAX_525_60;
 	else
 		decoder->rect.height = TVP5150_V_MAX_OTHERS;
 
-	decoder->norm = std;
+	/* Set only the specific supported std in case of group of std's. */
+	decoder->norm = supported_stds & std;
 
 	return tvp5150_set_std(sd, std);
 }
@@ -1335,6 +1359,9 @@ static int tvp5150_link_setup(struct media_entity *entity,
 			  TVP5150_BLACK_SCREEN, 0);
 
 	if (flags & MEDIA_LNK_FL_ENABLED) {
+		struct v4l2_fwnode_connector_analog *v4l2ca;
+		u32 new_norm;
+
 		/*
 		 * S-Video connector is conneted to both ports AIP1A and AIP1B.
 		 * Both links must be enabled in one-shot regardless which link
@@ -1346,6 +1373,28 @@ static int tvp5150_link_setup(struct media_entity *entity,
 			if (err)
 				return err;
 		}
+
+		if (!decoder->connectors_num)
+			return 0;
+
+		/* Update the current connector */
+		decoder->cur_connector =
+			container_of(remote, struct tvp5150_connector, pad);
+
+		/*
+		 * Do nothing if the new connector supports the same tv-norms as
+		 * the old one.
+		 */
+		v4l2ca = &decoder->cur_connector->base.connector.analog;
+		new_norm = decoder->norm & v4l2ca->sdtv_stds;
+		if (decoder->norm == new_norm)
+			return 0;
+
+		/*
+		 * Fallback to the new connector tv-norms if we can't find any
+		 * common between the current tv-norm and the new one.
+		 */
+		tvp5150_s_std(sd, new_norm ? new_norm : v4l2ca->sdtv_stds);
 	}
 
 	return 0;
@@ -1604,6 +1653,8 @@ static int tvp5150_registered(struct v4l2_subdev *sd)
 				TVP5150_COMPOSITE1;
 
 			tvp5150_selmux(sd);
+			decoder->cur_connector = &decoder->connectors[i];
+			tvp5150_s_std(sd, v4l2c->connector.analog.sdtv_stds);
 		}
 	}
 
@@ -1928,6 +1979,12 @@ static int tvp5150_validate_connectors(struct tvp5150 *decoder)
 				return -EINVAL;
 			}
 		}
+
+		if (!(v4l2c->connector.analog.sdtv_stds & TVP5150_STD_MASK)) {
+			dev_err(dev, "Unsupported tv-norm on connector %s\n",
+				v4l2c->name);
+			return -EINVAL;
+		}
 	}
 
 	return 0;
@@ -2060,6 +2117,7 @@ static int tvp5150_probe(struct i2c_client *c)
 	struct v4l2_subdev *sd;
 	struct device_node *np = c->dev.of_node;
 	struct regmap *map;
+	unsigned int i;
 	int res;
 
 	/* Check if the adapter supports the needed features */
@@ -2104,7 +2162,21 @@ static int tvp5150_probe(struct i2c_client *c)
 	if (res < 0)
 		return res;
 
-	core->norm = V4L2_STD_ALL;	/* Default is autodetect */
+	/*
+	 * Iterate over all available connectors in case they are supported and
+	 * successfully parsed. Fallback to default autodetect in case they
+	 * aren't supported.
+	 */
+	for (i = 0; i < core->connectors_num; i++) {
+		struct v4l2_fwnode_connector *v4l2c;
+
+		v4l2c = &core->connectors[i].base;
+		core->norm |= v4l2c->connector.analog.sdtv_stds;
+	}
+
+	if (!core->connectors_num)
+		core->norm = V4L2_STD_ALL;
+
 	core->detected_norm = V4L2_STD_UNKNOWN;
 	core->input = TVP5150_COMPOSITE1;
 	core->enable = true;
-- 
2.20.1


  parent reply	other threads:[~2020-03-12 10:32 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-12 10:31 [PATCH v13 00/19] TVP5150 Features and Fixes Marco Felsch
2020-03-12 10:31 ` [PATCH v13 01/21] dt-bindings: connector: analog: add sdtv standards property Marco Felsch
2020-03-12 10:31 ` [PATCH v13 02/21] dt-bindings: display: add sdtv-standards defines Marco Felsch
2020-03-12 10:31 ` [PATCH v13 03/21] media: v4l: link dt-bindings and uapi Marco Felsch
2020-03-12 10:31 ` [PATCH v13 04/21] media: v4l2-fwnode: fix v4l2_fwnode_parse_link handling Marco Felsch
2020-03-12 10:37   ` Sakari Ailus
2020-03-12 10:42   ` Sakari Ailus
2020-03-12 10:43     ` Sakari Ailus
2020-03-12 11:14       ` Marco Felsch
2020-03-12 10:31 ` [PATCH v13 05/21] media: v4l2-fwnode: simplify v4l2_fwnode_parse_link Marco Felsch
2020-03-12 10:31 ` [PATCH v13 06/21] media: v4l2-fwnode: add endpoint id field to v4l2_fwnode_link Marco Felsch
2020-03-12 10:31 ` [PATCH v13 07/21] media: v4l2-fwnode: add v4l2_fwnode_connector Marco Felsch
2020-03-12 10:31 ` [PATCH v13 08/21] media: v4l2-fwnode: add initial connector parsing support Marco Felsch
2020-03-12 10:31 ` [PATCH v13 09/21] partial revert of "[media] tvp5150: add HW input connectors support" Marco Felsch
2020-03-12 10:31 ` [PATCH v13 10/21] media: tvp5150: add input source selection of_graph support Marco Felsch
2020-03-12 10:31 ` [PATCH v13 11/21] media: dt-bindings: tvp5150: Add input port connectors DT bindings Marco Felsch
2020-03-12 10:31 ` [PATCH v13 12/21] media: tvp5150: fix set_selection rectangle handling Marco Felsch
2020-03-12 10:31 ` [PATCH v13 13/21] media: tvp5150: add FORMAT_TRY support for get/set selection handlers Marco Felsch
2020-03-12 10:31 ` [PATCH v13 14/21] media: tvp5150: initialize subdev before parsing device tree Marco Felsch
2020-03-12 10:31 ` [PATCH v13 15/21] media: tvp5150: move irq en-/disable into runtime-pm ops Marco Felsch
2020-03-12 10:31 ` [PATCH v13 16/21] media: tvp5150: add v4l2-event support Marco Felsch
2020-03-12 10:31 ` [PATCH v13 17/21] media: tvp5150: add subdev open/close callbacks Marco Felsch
2020-03-12 10:31 ` [PATCH v13 18/21] media: dt-bindings: tvp5150: cleanup bindings stlye Marco Felsch
2020-03-12 10:31 ` [PATCH v13 19/21] media: dt-bindings: tvp5150: add optional sdtv standards documentation Marco Felsch
2020-03-12 10:31 ` Marco Felsch [this message]
2020-03-12 10:31 ` [PATCH v13 21/21] media: tvp5150: make debug output more readable Marco Felsch

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200312103156.3178-21-m.felsch@pengutronix.de \
    --to=m.felsch@pengutronix.de \
    --cc=devicetree@vger.kernel.org \
    --cc=hans.verkuil@cisco.com \
    --cc=jacopo+renesas@jmondi.org \
    --cc=kernel@pengutronix.de \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=robh+dt@kernel.org \
    --cc=sakari.ailus@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox