summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomi Valkeinen <tomi.valkeinen+renesas@ideasonboard.com>2026-01-15 13:07:00 +0300
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>2026-03-11 03:05:31 +0300
commit21bcc9355cae73637e42865ee2c61d48d209a91d (patch)
tree2cf1f635cb7ed0ac3e11d227aea0ab4518afa53d
parent0ffd7f4c4c3b4ab55b34d6f27b15e65ba75c10ea (diff)
downloadlinux-21bcc9355cae73637e42865ee2c61d48d209a91d.tar.xz
media: rcar-csi2: Simplify rcsi2_calc_mbps()
Instead of taking the bpp and the number of lanes as parameters to rcsi2_calc_mbps(), change the function to get those parameters inside the function. This centralizes the code a bit and makes it easier to add streams support. Also, in the future when the legacy (non-link-freq) code is removed, there will be no need to change rcsi2_calc_mbps() parameters. Signed-off-by: Tomi Valkeinen <tomi.valkeinen+renesas@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se> Tested-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
-rw-r--r--drivers/media/platform/renesas/rcar-csi2.c45
1 files changed, 24 insertions, 21 deletions
diff --git a/drivers/media/platform/renesas/rcar-csi2.c b/drivers/media/platform/renesas/rcar-csi2.c
index 8032fa4f7a8a..a2a87c5bfd7c 100644
--- a/drivers/media/platform/renesas/rcar-csi2.c
+++ b/drivers/media/platform/renesas/rcar-csi2.c
@@ -1003,13 +1003,18 @@ static int rcsi2_get_active_lanes(struct rcar_csi2 *priv,
return 0;
}
-static int rcsi2_calc_mbps(struct rcar_csi2 *priv, unsigned int bpp,
- unsigned int lanes)
+static int rcsi2_calc_mbps(struct rcar_csi2 *priv,
+ struct v4l2_subdev_state *state)
{
+ const struct rcar_csi2_format *format;
+ struct v4l2_mbus_framefmt *fmt;
struct media_pad *remote_pad;
struct v4l2_subdev *source;
+ unsigned int lanes;
+ unsigned int bpp;
s64 freq;
u64 mbps;
+ int ret;
if (!priv->remote)
return -ENODEV;
@@ -1017,6 +1022,20 @@ static int rcsi2_calc_mbps(struct rcar_csi2 *priv, unsigned int bpp,
source = priv->remote;
remote_pad = &source->entity.pads[priv->remote_pad];
+ ret = rcsi2_get_active_lanes(priv, &lanes);
+ if (ret)
+ return ret;
+
+ fmt = v4l2_subdev_state_get_format(state, RCAR_CSI2_SINK);
+ if (!fmt)
+ return -EINVAL;
+
+ format = rcsi2_code_to_fmt(fmt->code);
+ if (!format)
+ return -EINVAL;
+
+ bpp = format->bpp;
+
freq = v4l2_get_link_freq(remote_pad, bpp, 2 * lanes);
if (freq < 0) {
int ret = (int)freq;
@@ -1093,7 +1112,7 @@ static int rcsi2_start_receiver_gen3(struct rcar_csi2 *priv,
phycnt = PHYCNT_ENABLECLK;
phycnt |= (1 << lanes) - 1;
- mbps = rcsi2_calc_mbps(priv, format->bpp, lanes);
+ mbps = rcsi2_calc_mbps(priv, state);
if (mbps < 0)
return mbps;
@@ -1475,23 +1494,15 @@ static int rcsi2_start_receiver_v4h(struct rcar_csi2 *priv,
struct v4l2_subdev_state *state)
{
const struct rcsi2_cphy_setting *cphy = NULL;
- const struct rcar_csi2_format *format;
- const struct v4l2_mbus_framefmt *fmt;
unsigned int lanes;
int mbps;
int ret;
- /* Use the format on the sink pad to compute the receiver config. */
- fmt = v4l2_subdev_state_get_format(state, RCAR_CSI2_SINK);
- format = rcsi2_code_to_fmt(fmt->code);
- if (!format)
- return -EINVAL;
-
ret = rcsi2_get_active_lanes(priv, &lanes);
if (ret)
return ret;
- mbps = rcsi2_calc_mbps(priv, format->bpp, lanes);
+ mbps = rcsi2_calc_mbps(priv, state);
if (mbps < 0)
return mbps;
@@ -1732,23 +1743,15 @@ static int rcsi2_init_common_v4m(struct rcar_csi2 *priv, unsigned int mbps)
static int rcsi2_start_receiver_v4m(struct rcar_csi2 *priv,
struct v4l2_subdev_state *state)
{
- const struct rcar_csi2_format *format;
- const struct v4l2_mbus_framefmt *fmt;
unsigned int lanes;
int mbps;
int ret;
- /* Calculate parameters */
- fmt = v4l2_subdev_state_get_format(state, RCAR_CSI2_SINK);
- format = rcsi2_code_to_fmt(fmt->code);
- if (!format)
- return -EINVAL;
-
ret = rcsi2_get_active_lanes(priv, &lanes);
if (ret)
return ret;
- mbps = rcsi2_calc_mbps(priv, format->bpp, lanes);
+ mbps = rcsi2_calc_mbps(priv, state);
if (mbps < 0)
return mbps;