linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] media: imx: Parse MIPI CSI2 link frequency correctly
@ 2019-05-20 20:12 Marek Vasut
  0 siblings, 0 replies; only message in thread
From: Marek Vasut @ 2019-05-20 20:12 UTC (permalink / raw)
  To: linux-media
  Cc: Marek Vasut, Fabio Estevam, Hans Verkuil, Mauro Carvalho Chehab,
	Philipp Zabel, Steve Longerbeam

The current code did not extract the CSI2 link frequency from the menu
items correctly. Fix this.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Hans Verkuil <hans.verkuil@cisco.com>
Cc: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
Cc: Philipp Zabel <p.zabel@pengutronix.de>
Cc: Steve Longerbeam <steve_longerbeam@mentor.com>
To: linux-media@vger.kernel.org
---
 drivers/staging/media/imx/imx6-mipi-csi2.c | 28 ++++++++++++++++------
 1 file changed, 21 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/media/imx/imx6-mipi-csi2.c b/drivers/staging/media/imx/imx6-mipi-csi2.c
index f29e28df36ed..64d8229336dd 100644
--- a/drivers/staging/media/imx/imx6-mipi-csi2.c
+++ b/drivers/staging/media/imx/imx6-mipi-csi2.c
@@ -193,18 +193,32 @@ static int max_mbps_to_hsfreqrange_sel(u32 max_mbps)
 
 static int csi2_dphy_init(struct csi2_dev *csi2)
 {
+	struct v4l2_querymenu qm = { .id = V4L2_CID_LINK_FREQ };
 	struct v4l2_ctrl *ctrl;
-	u32 mbps_per_lane;
-	int sel;
+	u32 mbps_per_lane = CSI2_DEFAULT_MAX_MBPS;
+	int ret, sel;
 
 	ctrl = v4l2_ctrl_find(csi2->src_sd->ctrl_handler,
 			      V4L2_CID_LINK_FREQ);
-	if (!ctrl)
-		mbps_per_lane = CSI2_DEFAULT_MAX_MBPS;
-	else
-		mbps_per_lane = DIV_ROUND_UP_ULL(2 * ctrl->qmenu_int[ctrl->val],
-						 USEC_PER_SEC);
+	if (ctrl) {
+		qm.index = v4l2_ctrl_g_ctrl(ctrl);
+		ret = v4l2_querymenu(csi2->src_sd->ctrl_handler, &qm);
+		if (ret) {
+			v4l2_err(&csi2->sd,
+				 "failed to get V4L2_CID_LINK_FREQ menu item, using default.\n");
+			goto exit;
+		}
+
+		if (!qm.value) {
+			v4l2_err(&csi2->sd,
+				 "invalid V4L2_CID_LINK_FREQ, using default.\n");
+			goto exit;
+		}
+
+		mbps_per_lane = DIV_ROUND_UP_ULL(qm.value, USEC_PER_SEC);
+	}
 
+exit:
 	sel = max_mbps_to_hsfreqrange_sel(mbps_per_lane);
 	if (sel < 0)
 		return sel;
-- 
2.20.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2019-05-20 20:12 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-20 20:12 [PATCH] media: imx: Parse MIPI CSI2 link frequency correctly Marek Vasut

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).