Message ID | 20240920124115.375748-3-dan.scally@ideasonboard.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | Extend RAW format support for rzg2l-cru driver | expand |
Hi Dan On Fri, Sep 20, 2024 at 01:41:13PM GMT, Daniel Scally wrote: > From: Daniel Scally <dan.scally+renesas@ideasonboard.com> > > The rzg2l_csi2_calc_mbps() function currently tries to calculate the > link frequency for a CSI2 bus using the V4L2_CID_PIXEL_RATE control > of the remote subdevice. Switch the function to v4l2_get_link_freq() > which correctly targets V4L2_CID_LINK_FREQ before falling back on > V4L2_CID_PIXEL_RATE if the former is unavailable. > > Signed-off-by: Daniel Scally <dan.scally+renesas@ideasonboard.com> Seems correct, Prabhakar maybe could test to confirm this still works with drivers that use PIXEL_RATE Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com> > --- > .../platform/renesas/rzg2l-cru/rzg2l-csi2.c | 25 ++++++++----------- > 1 file changed, 10 insertions(+), 15 deletions(-) > > diff --git a/drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c b/drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c > index d46f0bd10cec..9609ca2a2f67 100644 > --- a/drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c > +++ b/drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c > @@ -242,28 +242,23 @@ static int rzg2l_csi2_calc_mbps(struct rzg2l_csi2 *csi2) > const struct rzg2l_csi2_format *format; > const struct v4l2_mbus_framefmt *fmt; > struct v4l2_subdev_state *state; > - struct v4l2_ctrl *ctrl; > u64 mbps; > > - /* Read the pixel rate control from remote. */ > - ctrl = v4l2_ctrl_find(source->ctrl_handler, V4L2_CID_PIXEL_RATE); > - if (!ctrl) { > - dev_err(csi2->dev, "no pixel rate control in subdev %s\n", > - source->name); > - return -EINVAL; > - } > - > state = v4l2_subdev_lock_and_get_active_state(&csi2->subdev); > fmt = v4l2_subdev_state_get_format(state, RZG2L_CSI2_SINK); > format = rzg2l_csi2_code_to_fmt(fmt->code); > v4l2_subdev_unlock_state(state); > > - /* > - * Calculate hsfreq in Mbps > - * hsfreq = (pixel_rate * bits_per_sample) / number_of_lanes > - */ > - mbps = v4l2_ctrl_g_ctrl_int64(ctrl) * format->bpp; > - do_div(mbps, csi2->lanes * 1000000); > + /* Read the link frequency from remote subdevice. */ > + mbps = v4l2_get_link_freq(source->ctrl_handler, format->bpp, > + csi2->lanes); > + if (mbps < 0) { > + dev_err(csi2->dev, "can't retrieve link freq from subdev %s\n", > + source->name); > + return -EINVAL; > + } > + > + do_div(mbps, 1000000); > > return mbps; > } > -- > 2.34.1 > >
Hi Dan, Thank you for the patch. On Fri, Sep 20, 2024 at 01:41:13PM +0100, Daniel Scally wrote: > From: Daniel Scally <dan.scally+renesas@ideasonboard.com> > > The rzg2l_csi2_calc_mbps() function currently tries to calculate the > link frequency for a CSI2 bus using the V4L2_CID_PIXEL_RATE control > of the remote subdevice. Switch the function to v4l2_get_link_freq() > which correctly targets V4L2_CID_LINK_FREQ before falling back on > V4L2_CID_PIXEL_RATE if the former is unavailable. > > Signed-off-by: Daniel Scally <dan.scally+renesas@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com> > --- > .../platform/renesas/rzg2l-cru/rzg2l-csi2.c | 25 ++++++++----------- > 1 file changed, 10 insertions(+), 15 deletions(-) > > diff --git a/drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c b/drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c > index d46f0bd10cec..9609ca2a2f67 100644 > --- a/drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c > +++ b/drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c > @@ -242,28 +242,23 @@ static int rzg2l_csi2_calc_mbps(struct rzg2l_csi2 *csi2) > const struct rzg2l_csi2_format *format; > const struct v4l2_mbus_framefmt *fmt; > struct v4l2_subdev_state *state; > - struct v4l2_ctrl *ctrl; > u64 mbps; > > - /* Read the pixel rate control from remote. */ > - ctrl = v4l2_ctrl_find(source->ctrl_handler, V4L2_CID_PIXEL_RATE); > - if (!ctrl) { > - dev_err(csi2->dev, "no pixel rate control in subdev %s\n", > - source->name); > - return -EINVAL; > - } > - > state = v4l2_subdev_lock_and_get_active_state(&csi2->subdev); > fmt = v4l2_subdev_state_get_format(state, RZG2L_CSI2_SINK); > format = rzg2l_csi2_code_to_fmt(fmt->code); > v4l2_subdev_unlock_state(state); > > - /* > - * Calculate hsfreq in Mbps > - * hsfreq = (pixel_rate * bits_per_sample) / number_of_lanes > - */ > - mbps = v4l2_ctrl_g_ctrl_int64(ctrl) * format->bpp; > - do_div(mbps, csi2->lanes * 1000000); > + /* Read the link frequency from remote subdevice. */ > + mbps = v4l2_get_link_freq(source->ctrl_handler, format->bpp, > + csi2->lanes); > + if (mbps < 0) { > + dev_err(csi2->dev, "can't retrieve link freq from subdev %s\n", > + source->name); > + return -EINVAL; > + } > + > + do_div(mbps, 1000000); > > return mbps; > }
Hi Daniel, Thank you for the patch. > From: Daniel Scally <dan.scally+renesas@ideasonboard.com> > > The rzg2l_csi2_calc_mbps() function currently tries to calculate the link > frequency for a CSI2 bus using the V4L2_CID_PIXEL_RATE control of the > remote subdevice. Switch the function to v4l2_get_link_freq() which > correctly targets V4L2_CID_LINK_FREQ before falling back on > V4L2_CID_PIXEL_RATE if the former is unavailable. > > Signed-off-by: Daniel Scally <dan.scally+renesas@ideasonboard.com> > --- > .../platform/renesas/rzg2l-cru/rzg2l-csi2.c | 25 ++++++++----------- > 1 file changed, 10 insertions(+), 15 deletions(-) > Reviewed-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com> Tested-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com> Cheers, Prabhakar > diff --git a/drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c > b/drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c > index d46f0bd10cec..9609ca2a2f67 100644 > --- a/drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c > +++ b/drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c > @@ -242,28 +242,23 @@ static int rzg2l_csi2_calc_mbps(struct rzg2l_csi2 > *csi2) > const struct rzg2l_csi2_format *format; > const struct v4l2_mbus_framefmt *fmt; > struct v4l2_subdev_state *state; > - struct v4l2_ctrl *ctrl; > u64 mbps; > > - /* Read the pixel rate control from remote. */ > - ctrl = v4l2_ctrl_find(source->ctrl_handler, V4L2_CID_PIXEL_RATE); > - if (!ctrl) { > - dev_err(csi2->dev, "no pixel rate control in subdev %s\n", > - source->name); > - return -EINVAL; > - } > - > state = v4l2_subdev_lock_and_get_active_state(&csi2->subdev); > fmt = v4l2_subdev_state_get_format(state, RZG2L_CSI2_SINK); > format = rzg2l_csi2_code_to_fmt(fmt->code); > v4l2_subdev_unlock_state(state); > > - /* > - * Calculate hsfreq in Mbps > - * hsfreq = (pixel_rate * bits_per_sample) / number_of_lanes > - */ > - mbps = v4l2_ctrl_g_ctrl_int64(ctrl) * format->bpp; > - do_div(mbps, csi2->lanes * 1000000); > + /* Read the link frequency from remote subdevice. */ > + mbps = v4l2_get_link_freq(source->ctrl_handler, format->bpp, > + csi2->lanes); > + if (mbps < 0) { > + dev_err(csi2->dev, "can't retrieve link freq from subdev > %s\n", > + source->name); > + return -EINVAL; > + } > + > + do_div(mbps, 1000000); > > return mbps; > } > -- > 2.34.1
diff --git a/drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c b/drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c index d46f0bd10cec..9609ca2a2f67 100644 --- a/drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c +++ b/drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c @@ -242,28 +242,23 @@ static int rzg2l_csi2_calc_mbps(struct rzg2l_csi2 *csi2) const struct rzg2l_csi2_format *format; const struct v4l2_mbus_framefmt *fmt; struct v4l2_subdev_state *state; - struct v4l2_ctrl *ctrl; u64 mbps; - /* Read the pixel rate control from remote. */ - ctrl = v4l2_ctrl_find(source->ctrl_handler, V4L2_CID_PIXEL_RATE); - if (!ctrl) { - dev_err(csi2->dev, "no pixel rate control in subdev %s\n", - source->name); - return -EINVAL; - } - state = v4l2_subdev_lock_and_get_active_state(&csi2->subdev); fmt = v4l2_subdev_state_get_format(state, RZG2L_CSI2_SINK); format = rzg2l_csi2_code_to_fmt(fmt->code); v4l2_subdev_unlock_state(state); - /* - * Calculate hsfreq in Mbps - * hsfreq = (pixel_rate * bits_per_sample) / number_of_lanes - */ - mbps = v4l2_ctrl_g_ctrl_int64(ctrl) * format->bpp; - do_div(mbps, csi2->lanes * 1000000); + /* Read the link frequency from remote subdevice. */ + mbps = v4l2_get_link_freq(source->ctrl_handler, format->bpp, + csi2->lanes); + if (mbps < 0) { + dev_err(csi2->dev, "can't retrieve link freq from subdev %s\n", + source->name); + return -EINVAL; + } + + do_div(mbps, 1000000); return mbps; }