]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
media: rcar-csi2: Use v4l2_get_link_freq()
authorTomi Valkeinen <tomi.valkeinen+renesas@ideasonboard.com>
Mon, 20 Jan 2025 13:10:37 +0000 (15:10 +0200)
committerHans Verkuil <hverkuil@xs4all.nl>
Tue, 4 Mar 2025 12:35:33 +0000 (13:35 +0100)
Instead of directly using V4L2_CID_PIXEL_RATE and calculating the mbps
from that, use v4l2_get_link_freq(), which also supports
V4L2_CID_LINK_FREQ.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen+renesas@ideasonboard.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
drivers/media/platform/renesas/rcar-csi2.c

index 52d4e333c73524c80c01e6ff4c4835d866b2a0f4..84e6194fed6c4717bb5b4b13183ab9ae68d6e843 100644 (file)
@@ -8,6 +8,7 @@
 #include <linux/delay.h>
 #include <linux/interrupt.h>
 #include <linux/io.h>
+#include <linux/math64.h>
 #include <linux/module.h>
 #include <linux/of.h>
 #include <linux/of_graph.h>
@@ -15,6 +16,7 @@
 #include <linux/pm_runtime.h>
 #include <linux/reset.h>
 #include <linux/sys_soc.h>
+#include <linux/units.h>
 
 #include <media/mipi-csi2.h>
 #include <media/v4l2-ctrls.h>
@@ -953,7 +955,7 @@ static int rcsi2_calc_mbps(struct rcar_csi2 *priv, unsigned int bpp,
                           unsigned int lanes)
 {
        struct v4l2_subdev *source;
-       struct v4l2_ctrl *ctrl;
+       s64 freq;
        u64 mbps;
 
        if (!priv->remote)
@@ -961,21 +963,17 @@ static int rcsi2_calc_mbps(struct rcar_csi2 *priv, unsigned int bpp,
 
        source = priv->remote;
 
-       /* Read the pixel rate control from remote. */
-       ctrl = v4l2_ctrl_find(source->ctrl_handler, V4L2_CID_PIXEL_RATE);
-       if (!ctrl) {
-               dev_err(priv->dev, "no pixel rate control in subdev %s\n",
-                       source->name);
-               return -EINVAL;
+       freq = v4l2_get_link_freq(source->ctrl_handler, bpp, 2 * lanes);
+       if (freq < 0) {
+               int ret = (int)freq;
+
+               dev_err(priv->dev, "failed to get link freq for %s: %d\n",
+                       source->name, ret);
+
+               return ret;
        }
 
-       /*
-        * Calculate the phypll in mbps.
-        * link_freq = (pixel_rate * bits_per_sample) / (2 * nr_of_lanes)
-        * bps = link_freq * 2
-        */
-       mbps = v4l2_ctrl_g_ctrl_int64(ctrl) * bpp;
-       do_div(mbps, lanes * 1000000);
+       mbps = div_u64(freq * 2, MEGA);
 
        /* Adjust for C-PHY, divide by 2.8. */
        if (priv->cphy)