Re: [PATCH v6 4/5] media: platform: broadcom: Add bcm2835-isp driver

From: Jai Luthra

Date: Wed Nov 18 2026 - 12:34:34 EST


Hi Sakari,

Thank you for the review.

Quoting Sakari Ailus (2026-11-16 19:12:52)
> Hi Jai, Naush,
>
> On Thu, Nov 12, 2026 at 04:56:32PM +0530, Jai Luthra wrote:
> > diff --git a/drivers/media/platform/broadcom/bcm2835-isp/bcm2835-isp-fmts.h b/drivers/media/platform/broadcom/bcm2835-isp/bcm2835-isp-fmts.h
> > new file mode 100644
> > index 000000000000..6f3333d33c4f
> > --- /dev/null
> > +++ b/drivers/media/platform/broadcom/bcm2835-isp/bcm2835-isp-fmts.h
> > @@ -0,0 +1,558 @@
> > +/* SPDX-License-Identifier: GPL-2.0 */
> > +/*
> > + * Broadcom BCM2835 ISP driver
> > + *
> > + * Copyright © 2019-2026 Raspberry Pi (Trading) Ltd.
> > + *
> > + * Author: Naushir Patuck (naush@xxxxxxxxxxxxxxx)
> > + *
> > + */
> > +
> > +#ifndef BCM2835_ISP_FMTS
> > +#define BCM2835_ISP_FMTS
> > +
> > +#include <linux/videodev2.h>
> > +#include <linux/raspberrypi/mmal-encodings.h>
> > +
> > +struct bcm2835_isp_fmt {
> > + u32 fourcc;
> > + int depth;
> > + int bytesperline_align;
> > + u32 mmal_fmt;
> > + int size_multiplier_x2;
> > + u32 colorspace_mask;
> > + enum v4l2_colorspace colorspace_default;
> > + unsigned int step_size;
> > +};
> > +
> > +#define V4L2_COLORSPACE_MASK(colorspace) BIT(colorspace)
>
> The V4L2 prefix shouldn't be used for declaring macros in drivers. Please
> use a driver specific prefix instead.
>

Will fix.

[...]

> > + return -EINVAL;
> > + }
> > +
> > + return 0;
> > +}
> > +
> > +static int bcm2835_isp_mmal_buf_cleanup(struct mmal_buffer *mmal_buf)
> > +{
> > + mmal_vchi_buffer_cleanup(mmal_buf);
> > +
> > + if (mmal_buf->dma_buf) {
> > + dma_buf_put(mmal_buf->dma_buf);
> > + mmal_buf->dma_buf = NULL;
> > + }
> > +
> > + return 0;
> > +}
> > +
> > +static int bcm2835_isp_node_queue_setup(struct vb2_queue *q,
> > + unsigned int *nbuffers,
> > + unsigned int *nplanes,
> > + unsigned int sizes[],
> > + struct device *alloc_devs[])
> > +{
> > + struct bcm2835_isp_node *node = vb2_get_drv_priv(q);
> > + unsigned int size;
> > +
> > + if (setup_mmal_port(node))
> > + return -EINVAL;
> > +
> > + size = node->q_data.sizeimage;
> > + if (size == 0) {
> > + v4l2_info(&node_get_dev(node)->v4l2_dev,
> > + "%s: Image size unset in queue_setup for node %s[%d]\n",
> > + __func__, node->name, node->id);
> > + return -EINVAL;
> > + }
> > +
> > + if (*nplanes)
> > + return sizes[0] < size ? -EINVAL : 0;
> > +
> > + *nplanes = 1;
> > + sizes[0] = size;
> > +
> > + node->port->current_buffer.size = size;
> > +
> > + if (*nbuffers < node->port->minimum_buffer.num)
> > + *nbuffers = node->port->minimum_buffer.num;
> > +
> > + node->port->current_buffer.num = *nbuffers;
> > +
> > + v4l2_dbg(2, debug, &node_get_dev(node)->v4l2_dev,
> > + "%s: Image size %u, nbuffers %u for node %s[%d]\n",
> > + __func__, sizes[0], *nbuffers, node->name, node->id);
> > + return 0;
> > +}
> > +
> > +static int bcm2835_isp_buf_init(struct vb2_buffer *vb)
> > +{
> > + struct bcm2835_isp_node *node = vb2_get_drv_priv(vb->vb2_queue);
> > + struct bcm2835_isp_dev *dev = node_get_dev(node);
> > + struct bcm2835_isp_buffer *buf =
> > + to_bcm2835_isp_buffer(to_vb2_v4l2_buffer(vb));
> > +
> > + v4l2_dbg(3, debug, &dev->v4l2_dev, "%s: vb %p\n", __func__, vb);
> > +
> > + buf->mmal.buffer = vb2_plane_vaddr(&buf->vb.vb2_buf, 0);
> > + buf->mmal.buffer_size = vb2_plane_size(&buf->vb.vb2_buf, 0);
> > + mmal_vchi_buffer_init(dev->mmal_instance, &buf->mmal);
> > + return 0;
> > +}
> > +
> > +static int bcm2835_isp_buf_prepare(struct vb2_buffer *vb)
> > +{
> > + struct bcm2835_isp_node *node = vb2_get_drv_priv(vb->vb2_queue);
> > + struct bcm2835_isp_dev *dev = node_get_dev(node);
> > + struct vb2_v4l2_buffer *vb2 = to_vb2_v4l2_buffer(vb);
> > + struct bcm2835_isp_buffer *buf = to_bcm2835_isp_buffer(vb2);
> > + struct dma_buf *dma_buf;
> > + int ret = 0;
> > +
> > + v4l2_dbg(3, debug, &dev->v4l2_dev, "%s: type: %d ptr %p\n",
> > + __func__, vb->vb2_queue->type, vb);
>
> Is this still appropriate after development time?
>

I don't think so, I'll drop this and other ones at v4l2_dbg level 3.

[...]

Ack on rest of the comments for prints as well.

> > diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
> > index 17ba1ae70735..1449de2b64b5 100644
> > --- a/drivers/media/v4l2-core/v4l2-ioctl.c
> > +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
> > @@ -1490,6 +1490,8 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)
> > case V4L2_META_FMT_GENERIC_CSI2_16: descr = "8-bit Generic Meta, 16b CSI-2"; break;
> > case V4L2_META_FMT_GENERIC_CSI2_20: descr = "8-bit Generic Meta, 20b CSI-2"; break;
> > case V4L2_META_FMT_GENERIC_CSI2_24: descr = "8-bit Generic Meta, 24b CSI-2"; break;
> > + case V4L2_META_FMT_BCM2835_ISP_STATS: descr = "BCM2835 ISP Image Statistics"; break;
> > + case V4L2_META_FMT_BCM2835_ISP_PARAMS: descr = "BCM2835 ISP Config Parameters"; break;
>
> What's the status of the documentation for these? Do we have something
> beyond the headers?
>

These are documented in metafmt-bcm2835-isp.rst, which in turn refers to
v4l2-isp.rst, and also refers to the actual parameter and stats structures
defined in the bcm2835-isp.h.

I'll add an actual C code example for reading AWB stats, as that seems to
be missing right now, even though it's straightforward.

[...]

> > +/**
> > + * struct bcm2835_isp_params_digital_gain - Digital gain parameters block
> > + *
> > + * @header: Block header (type = BCM2835_ISP_PARAM_BLOCK_DIGITAL_GAIN)
> > + * @digital_gain: Digital gain configuration
> > + */
> > +struct bcm2835_isp_params_digital_gain {
> > + struct v4l2_isp_params_block_header header;
> > + struct bcm2835_isp_digital_gain digital_gain;
> > +} __attribute__((aligned(8)));
> > +
> > +/**
> > + * define BCM2835_ISP_PARAMS_MAX_SIZE - Maximum size of all ISP parameters
>
> How about adding a build-time check to the driver the size remains
> unchanged? There are quite a few different fields there.
>
> I might do the same for the statistics.
>
> This can be all fixed on top though and doesn't affect the UAPI.
>

I'll add a static_assert() for both in the next revision.

> > + *
> > + * This defines the maximum size needed to accommodate all possible parameter
> > + * blocks in a single buffer. Drivers use this to allocate appropriately
> > + * sized buffers.
> > + */
> > +#define BCM2835_ISP_PARAMS_MAX_SIZE \
> > + (sizeof(struct bcm2835_isp_params_black_level) + \
> > + sizeof(struct bcm2835_isp_params_geq) + \
> > + sizeof(struct bcm2835_isp_params_gamma) + \
> > + sizeof(struct bcm2835_isp_params_denoise) + \
> > + sizeof(struct bcm2835_isp_params_sharpen) + \
> > + sizeof(struct bcm2835_isp_params_dpc) + \
> > + sizeof(struct bcm2835_isp_params_cdn) + \
> > + sizeof(struct bcm2835_isp_params_cc_matrix) + \
> > + sizeof(struct bcm2835_isp_params_lens_shading) + \
> > + sizeof(struct bcm2835_isp_params_awb_gains) + \
> > + sizeof(struct bcm2835_isp_params_digital_gain))
> > +
> >
>
> --
> Regards,
>
> Sakari Ailus

Thanks,
Jai