Message ID | 20240324220854.15010-5-laurent.pinchart@ideasonboard.com |
---|---|
State | New |
Headers | show |
Series | media: Add driver for the Raspberry Pi <5 CSI-2 receiver | expand |
Hi Tomi, On Wed, Mar 27, 2024 at 12:08:22PM +0200, Tomi Valkeinen wrote: > On 25/03/2024 00:08, Laurent Pinchart wrote: > > Implement the .get_frame_desc() subdev operation to report information > > about streams to the connected CSI-2 receiver. This is required to let > > the CSI-2 receiver driver know about virtual channels and data types for > > each stream. > > > > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> > > Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com> > > --- > > Changes since v6: > > > > - Replace v4l2_subdev_state_get_stream_format() with > > v4l2_subdev_state_get_format() > > - Make imx219_format_bpp() return an unsigned int > > --- > > drivers/media/i2c/imx219.c | 67 ++++++++++++++++++++++++++++---------- > > 1 file changed, 50 insertions(+), 17 deletions(-) > > > > diff --git a/drivers/media/i2c/imx219.c b/drivers/media/i2c/imx219.c > > index 6602250834be..fa64bc402c9a 100644 > > --- a/drivers/media/i2c/imx219.c > > +++ b/drivers/media/i2c/imx219.c > > @@ -23,6 +23,7 @@ > > #include <linux/pm_runtime.h> > > #include <linux/regulator/consumer.h> > > > > +#include <media/mipi-csi2.h> > > #include <media/v4l2-cci.h> > > #include <media/v4l2-ctrls.h> > > #include <media/v4l2-device.h> > > @@ -591,6 +592,24 @@ static void imx219_free_controls(struct imx219 *imx219) > > * Subdev operations > > */ > > > > +static unsigned int imx219_format_bpp(u32 code) > > +{ > > + switch (code) { > > + case MEDIA_BUS_FMT_SRGGB8_1X8: > > + case MEDIA_BUS_FMT_SGRBG8_1X8: > > + case MEDIA_BUS_FMT_SGBRG8_1X8: > > + case MEDIA_BUS_FMT_SBGGR8_1X8: > > + return 8; > > + > > + case MEDIA_BUS_FMT_SRGGB10_1X10: > > + case MEDIA_BUS_FMT_SGRBG10_1X10: > > + case MEDIA_BUS_FMT_SGBRG10_1X10: > > + case MEDIA_BUS_FMT_SBGGR10_1X10: > > + default: > > + return 10; > > + } > > +} > > + > > static int imx219_set_framefmt(struct imx219 *imx219, > > struct v4l2_subdev_state *state) > > { > > @@ -602,23 +621,7 @@ static int imx219_set_framefmt(struct imx219 *imx219, > > > > format = v4l2_subdev_state_get_format(state, IMX219_PAD_SOURCE); > > crop = v4l2_subdev_state_get_crop(state, IMX219_PAD_IMAGE); > > - > > - switch (format->code) { > > - case MEDIA_BUS_FMT_SRGGB8_1X8: > > - case MEDIA_BUS_FMT_SGRBG8_1X8: > > - case MEDIA_BUS_FMT_SGBRG8_1X8: > > - case MEDIA_BUS_FMT_SBGGR8_1X8: > > - bpp = 8; > > - break; > > - > > - case MEDIA_BUS_FMT_SRGGB10_1X10: > > - case MEDIA_BUS_FMT_SGRBG10_1X10: > > - case MEDIA_BUS_FMT_SGBRG10_1X10: > > - case MEDIA_BUS_FMT_SBGGR10_1X10: > > - default: > > - bpp = 10; > > - break; > > - } > > + bpp = imx219_format_bpp(format->code); > > > > cci_write(imx219->regmap, IMX219_REG_X_ADD_STA_A, > > crop->left - IMX219_PIXEL_ARRAY_LEFT, &ret); > > @@ -1029,6 +1032,35 @@ static int imx219_init_state(struct v4l2_subdev *sd, > > return 0; > > } > > > > +static int imx219_get_frame_desc(struct v4l2_subdev *sd, unsigned int pad, > > + struct v4l2_mbus_frame_desc *fd) > > +{ > > + const struct v4l2_mbus_framefmt *fmt; > > + struct v4l2_subdev_state *state; > > + u32 code; > > + > > + if (pad != IMX219_PAD_SOURCE) > > + return -EINVAL; > > + > > + state = v4l2_subdev_lock_and_get_active_state(sd); > > + fmt = v4l2_subdev_state_get_format(state, IMX219_PAD_SOURCE, 0); > > I was going to say change 0 to IMX219_STREAM_IMAGE, but you only add it > in the next patch. Perhaps a pointless reshuffling, but you could > introduce IMX219_STREAM_IMAGE in patch 3, or maybe as a separate patch, > so that in patch 5 (embedded data) you don't need to convert the lines > related to the image stream. I'll introduce IMX219_STREAM_IMAGE in a separate patch. > > + code = fmt->code; > > + v4l2_subdev_unlock_state(state); > > + > > + fd->type = V4L2_MBUS_FRAME_DESC_TYPE_CSI2; > > + fd->num_entries = 1; > > + > > + memset(fd->entry, 0, sizeof(fd->entry)); > > The whole fd has been already cleared in call_get_frame_desc(). I'll drop the memset(). > > + > > + fd->entry[0].pixelcode = code; > > + fd->entry[0].stream = 0; > > + fd->entry[0].bus.csi2.vc = 0; > > + fd->entry[0].bus.csi2.dt = imx219_format_bpp(code) == 8 > > + ? MIPI_CSI2_DT_RAW8 : MIPI_CSI2_DT_RAW10; > > + > > + return 0; > > +} > > + > > static const struct v4l2_subdev_core_ops imx219_core_ops = { > > .subscribe_event = v4l2_ctrl_subdev_subscribe_event, > > .unsubscribe_event = v4l2_event_subdev_unsubscribe, > > @@ -1044,6 +1076,7 @@ static const struct v4l2_subdev_pad_ops imx219_pad_ops = { > > .set_fmt = imx219_set_pad_format, > > .get_selection = imx219_get_selection, > > .enum_frame_size = imx219_enum_frame_size, > > + .get_frame_desc = imx219_get_frame_desc, > > }; > > > > static const struct v4l2_subdev_ops imx219_subdev_ops = {
diff --git a/drivers/media/i2c/imx219.c b/drivers/media/i2c/imx219.c index 6602250834be..fa64bc402c9a 100644 --- a/drivers/media/i2c/imx219.c +++ b/drivers/media/i2c/imx219.c @@ -23,6 +23,7 @@ #include <linux/pm_runtime.h> #include <linux/regulator/consumer.h> +#include <media/mipi-csi2.h> #include <media/v4l2-cci.h> #include <media/v4l2-ctrls.h> #include <media/v4l2-device.h> @@ -591,6 +592,24 @@ static void imx219_free_controls(struct imx219 *imx219) * Subdev operations */ +static unsigned int imx219_format_bpp(u32 code) +{ + switch (code) { + case MEDIA_BUS_FMT_SRGGB8_1X8: + case MEDIA_BUS_FMT_SGRBG8_1X8: + case MEDIA_BUS_FMT_SGBRG8_1X8: + case MEDIA_BUS_FMT_SBGGR8_1X8: + return 8; + + case MEDIA_BUS_FMT_SRGGB10_1X10: + case MEDIA_BUS_FMT_SGRBG10_1X10: + case MEDIA_BUS_FMT_SGBRG10_1X10: + case MEDIA_BUS_FMT_SBGGR10_1X10: + default: + return 10; + } +} + static int imx219_set_framefmt(struct imx219 *imx219, struct v4l2_subdev_state *state) { @@ -602,23 +621,7 @@ static int imx219_set_framefmt(struct imx219 *imx219, format = v4l2_subdev_state_get_format(state, IMX219_PAD_SOURCE); crop = v4l2_subdev_state_get_crop(state, IMX219_PAD_IMAGE); - - switch (format->code) { - case MEDIA_BUS_FMT_SRGGB8_1X8: - case MEDIA_BUS_FMT_SGRBG8_1X8: - case MEDIA_BUS_FMT_SGBRG8_1X8: - case MEDIA_BUS_FMT_SBGGR8_1X8: - bpp = 8; - break; - - case MEDIA_BUS_FMT_SRGGB10_1X10: - case MEDIA_BUS_FMT_SGRBG10_1X10: - case MEDIA_BUS_FMT_SGBRG10_1X10: - case MEDIA_BUS_FMT_SBGGR10_1X10: - default: - bpp = 10; - break; - } + bpp = imx219_format_bpp(format->code); cci_write(imx219->regmap, IMX219_REG_X_ADD_STA_A, crop->left - IMX219_PIXEL_ARRAY_LEFT, &ret); @@ -1029,6 +1032,35 @@ static int imx219_init_state(struct v4l2_subdev *sd, return 0; } +static int imx219_get_frame_desc(struct v4l2_subdev *sd, unsigned int pad, + struct v4l2_mbus_frame_desc *fd) +{ + const struct v4l2_mbus_framefmt *fmt; + struct v4l2_subdev_state *state; + u32 code; + + if (pad != IMX219_PAD_SOURCE) + return -EINVAL; + + state = v4l2_subdev_lock_and_get_active_state(sd); + fmt = v4l2_subdev_state_get_format(state, IMX219_PAD_SOURCE, 0); + code = fmt->code; + v4l2_subdev_unlock_state(state); + + fd->type = V4L2_MBUS_FRAME_DESC_TYPE_CSI2; + fd->num_entries = 1; + + memset(fd->entry, 0, sizeof(fd->entry)); + + fd->entry[0].pixelcode = code; + fd->entry[0].stream = 0; + fd->entry[0].bus.csi2.vc = 0; + fd->entry[0].bus.csi2.dt = imx219_format_bpp(code) == 8 + ? MIPI_CSI2_DT_RAW8 : MIPI_CSI2_DT_RAW10; + + return 0; +} + static const struct v4l2_subdev_core_ops imx219_core_ops = { .subscribe_event = v4l2_ctrl_subdev_subscribe_event, .unsubscribe_event = v4l2_event_subdev_unsubscribe, @@ -1044,6 +1076,7 @@ static const struct v4l2_subdev_pad_ops imx219_pad_ops = { .set_fmt = imx219_set_pad_format, .get_selection = imx219_get_selection, .enum_frame_size = imx219_enum_frame_size, + .get_frame_desc = imx219_get_frame_desc, }; static const struct v4l2_subdev_ops imx219_subdev_ops = {