Re: [PATCH v2] media: i2c: ov5640: Implement get_mbus_config

From: Sakari Ailus
Date: Tue Mar 14 2023 - 08:52:18 EST


Hi Francesco,

On Tue, Mar 14, 2023 at 01:32:16PM +0100, Francesco Dolcini wrote:
> Hello Sakari,
>
> On Tue, Mar 14, 2023 at 02:13:46PM +0200, Sakari Ailus wrote:
> > On Mon, Mar 06, 2023 at 07:36:49AM +0100, Marcel Ziswiler wrote:
> > > From: Aishwarya Kothari <aishwarya.kothari@xxxxxxxxxxx>
> > >
> > > Implement the introduced get_mbus_config operation to report the
> > > config of the MIPI CSI-2, BT.656 and Parallel interface.
> > >
> > > Signed-off-by: Aishwarya Kothari <aishwarya.kothari@xxxxxxxxxxx>
> > > Signed-off-by: Marcel Ziswiler <marcel.ziswiler@xxxxxxxxxxx>
> > >
> > > ---
> > >
> > > Changes in v2:
> > > - Take care of MIPI CSI-2, BT.656 and Parallel interface as
> > > pointed out by Jacopo. Thanks!
> > >
> > > drivers/media/i2c/ov5640.c | 19 +++++++++++++++++++
> > > 1 file changed, 19 insertions(+)
> > >
> > > diff --git a/drivers/media/i2c/ov5640.c b/drivers/media/i2c/ov5640.c
> > > index 1536649b9e90..43373416fcba 100644
> > > --- a/drivers/media/i2c/ov5640.c
> > > +++ b/drivers/media/i2c/ov5640.c
> > > @@ -3774,6 +3774,24 @@ static int ov5640_init_cfg(struct v4l2_subdev *sd,
> > > return 0;
> > > }
> > >
> > > +static int ov5640_get_mbus_config(struct v4l2_subdev *sd,
> > > + unsigned int pad,
> > > + struct v4l2_mbus_config *cfg)
> > > +{
> > > + struct ov5640_dev *sensor = to_ov5640_dev(sd);
> > > +
> > > + cfg->type = sensor->ep.bus_type;
> > > + if (ov5640_is_csi2(sensor)) {
> > > + cfg->bus.mipi_csi2.num_data_lanes =
> > > + sensor->ep.bus.mipi_csi2.num_data_lanes;
> > > + cfg->bus.mipi_csi2.flags = sensor->ep.bus.mipi_csi2.flags;
> > > + } else {
> > > + cfg->bus.parallel.flags = sensor->ep.bus.parallel.flags;
> > > + }
> > > +
> > > + return 0;
> > > +}
> > > +
> > > static const struct v4l2_subdev_core_ops ov5640_core_ops = {
> > > .log_status = v4l2_ctrl_subdev_log_status,
> > > .subscribe_event = v4l2_ctrl_subdev_subscribe_event,
> > > @@ -3794,6 +3812,7 @@ static const struct v4l2_subdev_pad_ops ov5640_pad_ops = {
> > > .get_selection = ov5640_get_selection,
> > > .enum_frame_size = ov5640_enum_frame_size,
> > > .enum_frame_interval = ov5640_enum_frame_interval,
> > > + .get_mbus_config = ov5640_get_mbus_config,
> >
> > What's the reasoning for this patch?
>
> Without this it's not possible to use it on i.MX6,
> drivers/staging/media/imx/imx6-mipi-csi2.c requires it, some more
> details from Jacopo here [0].
>
> Everything used to work fine up to v5.18, after that kernel version
> various changes broke it [1][2] (I assume you are pretty much aware of
> the history here, you commented on a few emails).
>
> [0] https://lore.kernel.org/all/20230128100611.7ulsfqqqgscg54gy@uno.localdomain/
> [1] https://lore.kernel.org/all/081cc2d3-1f3a-6c14-6dc7-53f976be7b2b@xxxxxxxxx/
> [2] https://lore.kernel.org/all/cacfe146-101b-35b3-5f66-1a1cabfd342f@xxxxxxxxx/
>
> > Drivers that don't have e.g. dynamic lane configuration shouldn't need to
> > implement get_mbus_config.

Not even for staging drivers. The driver should be fixed to get that
information from the endpoint instead.

I don't object having a helper in the framework to do this though. There
are many receiver drivers that need this to work with those devices that
have variable number of lanes.

--
Regards,

Sakari Ailus