Message ID | 20230324151228.2778112-7-paul.kocialkowski@bootlin.com |
---|---|
State | New |
Headers | show |
Series | media: sun6i-csi/isp: Implement MC I/O support | expand |
Dne petek, 24. marec 2023 ob 16:12:25 CET je Paul Kocialkowski napisal(a): > This driver needs the media-controller API to operate and should not be > considered as a video-device-centric implementation. > > Properly report the IO_MC device cap and extend the enum_fmt > implementation to support enumeration with an explicit mbus_code. > > Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com> > --- > .../sunxi/sun6i-csi/sun6i_csi_capture.c | 36 ++++++++++++++++--- > 1 file changed, 32 insertions(+), 4 deletions(-) > > diff --git a/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_capture.c b/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_capture.c > index 6ce7f1d3ed57..9627030ff060 100644 > --- a/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_capture.c > +++ b/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_capture.c > @@ -777,13 +777,40 @@ static int sun6i_csi_capture_enum_fmt(struct file *file, void *private, > struct v4l2_fmtdesc *fmtdesc) > { > u32 index = fmtdesc->index; > + u32 mbus_code = fmtdesc->mbus_code; Nit: reverse christmas tree. Other than that: Reviewed-by: Jernej Skrabec <jernej.skrabec@gmail.com> Best regards, Jernej > + unsigned int index_valid = 0; > + unsigned int i; > + > + if (!mbus_code) { > + if (index >= ARRAY_SIZE(sun6i_csi_capture_formats)) > + return -EINVAL; > + > + fmtdesc->pixelformat = > + sun6i_csi_capture_formats[index].pixelformat; > + > + return 0; > + } > + > + /* Check capture pixel format matching with mbus code. */ > > - if (index >= ARRAY_SIZE(sun6i_csi_capture_formats)) > + if (!sun6i_csi_bridge_format_find(mbus_code)) > return -EINVAL; > > - fmtdesc->pixelformat = sun6i_csi_capture_formats[index].pixelformat; > + for (i = 0; i < ARRAY_SIZE(sun6i_csi_capture_formats); i++) { > + u32 pixelformat = sun6i_csi_capture_formats[i].pixelformat; > > - return 0; > + if (!sun6i_csi_capture_format_check(pixelformat, mbus_code)) > + continue; > + > + if (index == index_valid) { > + fmtdesc->pixelformat = pixelformat; > + return 0; > + } > + > + index_valid++; > + } > + > + return -EINVAL; > } > > static int sun6i_csi_capture_g_fmt(struct file *file, void *private, > @@ -1039,7 +1066,8 @@ int sun6i_csi_capture_setup(struct sun6i_csi_device *csi_dev) > > strscpy(video_dev->name, SUN6I_CSI_CAPTURE_NAME, > sizeof(video_dev->name)); > - video_dev->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING; > + video_dev->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING | > + V4L2_CAP_IO_MC; > video_dev->vfl_dir = VFL_DIR_RX; > video_dev->release = video_device_release_empty; > video_dev->fops = &sun6i_csi_capture_fops; > -- > 2.39.2 > >
Hi Paul, Thank you for the patch. On Fri, Mar 24, 2023 at 04:12:25PM +0100, Paul Kocialkowski wrote: > This driver needs the media-controller API to operate and should not be > considered as a video-device-centric implementation. > > Properly report the IO_MC device cap and extend the enum_fmt > implementation to support enumeration with an explicit mbus_code. > > Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com> > --- > .../sunxi/sun6i-csi/sun6i_csi_capture.c | 36 ++++++++++++++++--- > 1 file changed, 32 insertions(+), 4 deletions(-) > > diff --git a/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_capture.c b/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_capture.c > index 6ce7f1d3ed57..9627030ff060 100644 > --- a/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_capture.c > +++ b/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_capture.c > @@ -777,13 +777,40 @@ static int sun6i_csi_capture_enum_fmt(struct file *file, void *private, > struct v4l2_fmtdesc *fmtdesc) > { > u32 index = fmtdesc->index; > + u32 mbus_code = fmtdesc->mbus_code; > + unsigned int index_valid = 0; > + unsigned int i; > + > + if (!mbus_code) { > + if (index >= ARRAY_SIZE(sun6i_csi_capture_formats)) > + return -EINVAL; > + > + fmtdesc->pixelformat = > + sun6i_csi_capture_formats[index].pixelformat; > + > + return 0; > + } > + > + /* Check capture pixel format matching with mbus code. */ > > - if (index >= ARRAY_SIZE(sun6i_csi_capture_formats)) > + if (!sun6i_csi_bridge_format_find(mbus_code)) > return -EINVAL; > > - fmtdesc->pixelformat = sun6i_csi_capture_formats[index].pixelformat; > + for (i = 0; i < ARRAY_SIZE(sun6i_csi_capture_formats); i++) { > + u32 pixelformat = sun6i_csi_capture_formats[i].pixelformat; > > - return 0; > + if (!sun6i_csi_capture_format_check(pixelformat, mbus_code)) > + continue; I would probably have added compatible media bus codes to the sun6i_csi_capture_format structure. This should work though, even if it is more CPU-intensive. I'm OK with either option. > + > + if (index == index_valid) { You can replace this with if (index == 0) { and index_valid++; with index--; below, and drop the index_valid variable. > + fmtdesc->pixelformat = pixelformat; > + return 0; > + } > + > + index_valid++; > + } > + > + return -EINVAL; > } > > static int sun6i_csi_capture_g_fmt(struct file *file, void *private, > @@ -1039,7 +1066,8 @@ int sun6i_csi_capture_setup(struct sun6i_csi_device *csi_dev) > > strscpy(video_dev->name, SUN6I_CSI_CAPTURE_NAME, > sizeof(video_dev->name)); > - video_dev->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING; > + video_dev->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING | > + V4L2_CAP_IO_MC; > video_dev->vfl_dir = VFL_DIR_RX; > video_dev->release = video_device_release_empty;
diff --git a/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_capture.c b/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_capture.c index 6ce7f1d3ed57..9627030ff060 100644 --- a/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_capture.c +++ b/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_capture.c @@ -777,13 +777,40 @@ static int sun6i_csi_capture_enum_fmt(struct file *file, void *private, struct v4l2_fmtdesc *fmtdesc) { u32 index = fmtdesc->index; + u32 mbus_code = fmtdesc->mbus_code; + unsigned int index_valid = 0; + unsigned int i; + + if (!mbus_code) { + if (index >= ARRAY_SIZE(sun6i_csi_capture_formats)) + return -EINVAL; + + fmtdesc->pixelformat = + sun6i_csi_capture_formats[index].pixelformat; + + return 0; + } + + /* Check capture pixel format matching with mbus code. */ - if (index >= ARRAY_SIZE(sun6i_csi_capture_formats)) + if (!sun6i_csi_bridge_format_find(mbus_code)) return -EINVAL; - fmtdesc->pixelformat = sun6i_csi_capture_formats[index].pixelformat; + for (i = 0; i < ARRAY_SIZE(sun6i_csi_capture_formats); i++) { + u32 pixelformat = sun6i_csi_capture_formats[i].pixelformat; - return 0; + if (!sun6i_csi_capture_format_check(pixelformat, mbus_code)) + continue; + + if (index == index_valid) { + fmtdesc->pixelformat = pixelformat; + return 0; + } + + index_valid++; + } + + return -EINVAL; } static int sun6i_csi_capture_g_fmt(struct file *file, void *private, @@ -1039,7 +1066,8 @@ int sun6i_csi_capture_setup(struct sun6i_csi_device *csi_dev) strscpy(video_dev->name, SUN6I_CSI_CAPTURE_NAME, sizeof(video_dev->name)); - video_dev->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING; + video_dev->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING | + V4L2_CAP_IO_MC; video_dev->vfl_dir = VFL_DIR_RX; video_dev->release = video_device_release_empty; video_dev->fops = &sun6i_csi_capture_fops;
This driver needs the media-controller API to operate and should not be considered as a video-device-centric implementation. Properly report the IO_MC device cap and extend the enum_fmt implementation to support enumeration with an explicit mbus_code. Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com> --- .../sunxi/sun6i-csi/sun6i_csi_capture.c | 36 ++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-)