Devicetree
 help / color / mirror / Atom feed
From: Anthony McGivern <anthony.mcgivern@arm.com>
To: linux-media@vger.kernel.org, devicetree@vger.kernel.org,
	 linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org
Cc: Anthony McGivern <anthony.mcgivern@arm.com>,
	 Vincenzo Frascino <vincenzo.frascino@arm.com>,
	 Nayden Kanchev <nayden.kanchev@arm.com>,
	 Konstantin Babin <konstantin.babin@arm.com>,
	 Linus Walleij <linusw@kernel.org>,
	jacopo.mondi@ideasonboard.com,  kieran.bingham@ideasonboard.com,
	laurent.pinchart@ideasonboard.com,  dan.scally@ideasonboard.com,
	Sakari Ailus <sakari.ailus@linux.intel.com>,
	 Rob Herring <robh@kernel.org>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	 Hans Verkuil <hverkuil@kernel.org>,
	 Krzysztof Kozlowski <krzk+dt@kernel.org>,
	 Conor Dooley <conor+dt@kernel.org>,
	 Anthony McGivern <Anthony.McGivern@arm.com>
Subject: [PATCH 10/24] media: mali-c720: Add ISP and human vision subdevices
Date: Tue, 24 Nov 2026 17:07:38 +0000	[thread overview]
Message-ID: <20261124-b4-initial-upstream-candidate-v1-10-0cb9bde1bd30@arm.com> (raw)
In-Reply-To: <20261124-b4-initial-upstream-candidate-v1-0-0cb9bde1bd30@arm.com>

From: Anthony McGivern <Anthony.McGivern@arm.com>

Add subdevices for the ISP input pipeline and human vision (HV)
pipeline. HV processes images intended for human viewing, while the
computer vision (CV) pipeline targets machine-processing applications.
This initial driver supports only the HV path.

Expose frame-start events for sensor control timing.

Signed-off-by: Anthony McGivern <Anthony.McGivern@arm.com>
---
 .../platform/arm/mali-c720/mali-c720-common.h      |  38 ++
 .../platform/arm/mali-c720/mali-c720-interrupts.c  |   2 +
 .../media/platform/arm/mali-c720/mali-c720-isp.c   | 422 +++++++++++++++++++++
 .../platform/arm/mali-c720/mali-c720-vision-pipe.c | 260 +++++++++++++
 4 files changed, 722 insertions(+)

diff --git a/drivers/media/platform/arm/mali-c720/mali-c720-common.h b/drivers/media/platform/arm/mali-c720/mali-c720-common.h
index 6f5ddb94398d76888edb992000a4d6012e960675..1037949d45e4eb8520254cd9addcbfce45def92d 100644
--- a/drivers/media/platform/arm/mali-c720/mali-c720-common.h
+++ b/drivers/media/platform/arm/mali-c720/mali-c720-common.h
@@ -69,6 +69,30 @@ struct mali_c720_input {
 	struct mali_c720_slot_input slot_input;
 };
 
+enum mali_c720_isp_pads {
+	MALI_C720_ISP_PAD_SINK_VIDEO,
+	MALI_C720_ISP_PAD_SOURCE_HV,
+	MALI_C720_ISP_NUM_PADS,
+};
+
+struct mali_c720_isp {
+	struct mali_c720_subdev mdev;
+	struct media_pad pads[MALI_C720_ISP_NUM_PADS];
+	struct media_pad *remote_src;
+	bool enabled;
+};
+
+enum mali_c720_vision_pipe_pads {
+	MALI_C720_VISION_PIPE_PAD_SINK_VIDEO,
+	MALI_C720_VISION_PIPE_PAD_SOURCE_RGB,
+	MALI_C720_VISION_PIPE_NUM_PADS,
+};
+
+struct mali_c720_vision_pipe {
+	struct mali_c720_subdev mdev;
+	struct media_pad pads[MALI_C720_VISION_PIPE_NUM_PADS];
+};
+
 enum mali_c720_cap_devs {
 	MALI_C720_CAP_DEV_FR0_RGB,
 	MALI_C720_CAP_DEV_FR0_YUV,
@@ -126,6 +150,8 @@ struct mali_c720 {
 	struct v4l2_device v4l2_dev;
 
 	struct mali_c720_input input;
+	struct mali_c720_isp isp;
+	struct mali_c720_vision_pipe vision_pipe;
 
 	struct mali_c720_registers registers;
 	u8 *default_regs;
@@ -145,8 +171,20 @@ struct mali_c720 {
 	spinlock_t irq_lock;
 };
 
+/* ISP subdevice registration functions */
+
 int mali_c720_register_input(struct mali_c720 *mali_c720);
 void mali_c720_unregister_input(struct mali_c720 *mali_c720);
 void mali_c720_cleanup_input(struct mali_c720 *mali_c720);
 
+int mali_c720_register_isp(struct mali_c720 *mali_c720);
+void mali_c720_unregister_isp(struct mali_c720 *mali_c720);
+void mali_c720_cleanup_isp(struct mali_c720 *mali_c720);
+
+int mali_c720_register_vision_pipe(struct mali_c720 *mali_c720);
+void mali_c720_unregister_vision_pipe(struct mali_c720 *mali_c720);
+void mali_c720_cleanup_vision_pipe(struct mali_c720 *mali_c720);
+
+void mali_c720_isp_queue_event_sof(struct mali_c720 *mali_c720, u32 sequence);
+
 #endif /* MALI_C720_COMMON_H */
diff --git a/drivers/media/platform/arm/mali-c720/mali-c720-interrupts.c b/drivers/media/platform/arm/mali-c720/mali-c720-interrupts.c
index 63589989478650f65c3cc06bee0a48a53b92b051..bd1e5189b276e59a33cda63f40ceffa3b7a2520c 100644
--- a/drivers/media/platform/arm/mali-c720/mali-c720-interrupts.c
+++ b/drivers/media/platform/arm/mali-c720/mali-c720-interrupts.c
@@ -156,6 +156,8 @@ static void mali_c720_handle_input_frame_start(struct mali_c720 *mali_c720,
 	entry->sequence = sequence;
 	entry->timestamp = timestamp;
 	entry->valid = true;
+
+	mali_c720_isp_queue_event_sof(mali_c720, sequence);
 }
 
 static void mali_c720_update_frame_timestamp(struct mali_c720_context *ctx)
diff --git a/drivers/media/platform/arm/mali-c720/mali-c720-isp.c b/drivers/media/platform/arm/mali-c720/mali-c720-isp.c
new file mode 100644
index 0000000000000000000000000000000000000000..962a2215543b49a6f90159fcb75ac253727cf2b6
--- /dev/null
+++ b/drivers/media/platform/arm/mali-c720/mali-c720-isp.c
@@ -0,0 +1,422 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * ARM Mali-C720 ISP Driver - Image signal processor
+ *
+ * Copyright (C) 2026 Arm Ltd
+ */
+
+#include <linux/bitops.h>
+#include <linux/string.h>
+
+#include <media/media-entity.h>
+#include <media/v4l2-common.h>
+#include <media/v4l2-event.h>
+
+#include "mali-c720-common.h"
+
+static int mali_c720_isp_enum_mbus_code(struct v4l2_subdev *sd,
+					struct v4l2_subdev_state *state,
+					struct v4l2_subdev_mbus_code_enum *code)
+{
+	const struct mali_c720_mbus_format_info *cfg;
+	struct v4l2_mbus_framefmt *sink_fmt;
+	struct mali_c720_mbus_format_match match;
+
+	/* HV uses the sink Bayer order at the internal 16-bit precision. */
+	if (code->pad == MALI_C720_ISP_PAD_SOURCE_HV) {
+		if (code->index)
+			return -EINVAL;
+
+		sink_fmt = v4l2_subdev_state_get_format(state, MALI_C720_ISP_PAD_SINK_VIDEO);
+		if (!sink_fmt)
+			return -EINVAL;
+
+		cfg = mali_c720_get_mbus_config_by_code(sink_fmt->code);
+		if (!cfg)
+			return -EINVAL;
+
+		cfg = mali_c720_shift_mbus_format(cfg, MALI_C720_FORMAT_16BIT);
+		if (!cfg)
+			return -EINVAL;
+
+		code->code = cfg->code;
+	} else if (code->pad == MALI_C720_ISP_PAD_SINK_VIDEO) {
+		match.type_mask = MALI_C720_FORMAT_BAYER;
+		match.depth_mask = MALI_C720_FORMAT_24BIT;
+
+		cfg = mali_c720_get_mbus_config_by_matched_index(code->index, &match);
+		if (!cfg)
+			return -EINVAL;
+
+		code->code = cfg->code;
+	} else {
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static int mali_c720_isp_enum_frame_size(struct v4l2_subdev *sd,
+					 struct v4l2_subdev_state *state,
+					 struct v4l2_subdev_frame_size_enum *fse)
+{
+	const struct mali_c720_mbus_format_info *cfg;
+	struct v4l2_mbus_framefmt *sink_fmt;
+	struct mali_c720_mbus_format_match match;
+
+	if (fse->index)
+		return -EINVAL;
+
+	switch (fse->pad) {
+	case MALI_C720_ISP_PAD_SOURCE_HV:
+		sink_fmt = v4l2_subdev_state_get_format(state, MALI_C720_ISP_PAD_SINK_VIDEO);
+		if (!sink_fmt)
+			return -EINVAL;
+
+		cfg = mali_c720_get_mbus_config_by_code(sink_fmt->code);
+		if (!cfg)
+			return -EINVAL;
+
+		cfg = mali_c720_shift_mbus_format(cfg, MALI_C720_FORMAT_16BIT);
+		if (!cfg || fse->code != cfg->code)
+			return -EINVAL;
+		break;
+	case MALI_C720_ISP_PAD_SINK_VIDEO:
+		match.type_mask = MALI_C720_FORMAT_BAYER;
+		match.depth_mask = MALI_C720_FORMAT_24BIT;
+
+		cfg = mali_c720_get_mbus_config_by_code(fse->code);
+		if (!cfg || !mali_c720_validate_mbus_format_match(cfg, &match))
+			return -EINVAL;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	fse->min_width = MALI_C720_MIN_INPUT_WIDTH;
+	fse->min_height = MALI_C720_MIN_INPUT_HEIGHT;
+	fse->max_width = MALI_C720_MAX_WIDTH;
+	fse->max_height = MALI_C720_MAX_HEIGHT;
+
+	return 0;
+}
+
+static int mali_c720_isp_set_fmt(struct v4l2_subdev *sd,
+				 const struct v4l2_subdev_client_info *ci,
+				 struct v4l2_subdev_state *state,
+				 struct v4l2_subdev_format *format)
+{
+	struct v4l2_mbus_framefmt *fmt = &format->format;
+	struct v4l2_mbus_framefmt *src_fmt, *sink_fmt;
+	const struct mali_c720_mbus_format_info *cfg;
+	struct mali_c720_mbus_format_match match;
+
+	if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE &&
+	    media_entity_is_streaming(&sd->entity))
+		return -EBUSY;
+
+	/* Only the video sink pad format can be changed. */
+	if (format->pad != MALI_C720_ISP_PAD_SINK_VIDEO)
+		return v4l2_subdev_get_fmt(sd, state, format);
+
+	sink_fmt = v4l2_subdev_state_get_format(state, MALI_C720_ISP_PAD_SINK_VIDEO);
+	if (!sink_fmt)
+		return -EINVAL;
+
+	match.type_mask = MALI_C720_FORMAT_BAYER;
+	match.depth_mask = MALI_C720_FORMAT_24BIT;
+
+	cfg = mali_c720_get_mbus_config_by_code(fmt->code);
+	if (!cfg || !mali_c720_validate_mbus_format_match(cfg, &match))
+		cfg = mali_c720_get_mbus_config_by_code(MEDIA_BUS_FMT_SRGGB24_1X24);
+
+	sink_fmt->code = cfg->code;
+
+	sink_fmt->width = fmt->width;
+	sink_fmt->height = fmt->height;
+	v4l_bound_align_image(&sink_fmt->width, MALI_C720_MIN_INPUT_WIDTH,
+			      MALI_C720_MAX_WIDTH, 2,
+			      &sink_fmt->height, MALI_C720_MIN_INPUT_HEIGHT,
+			      MALI_C720_MAX_HEIGHT, 2, 0);
+
+	*fmt = *sink_fmt;
+
+	/* Propagate the input size and Bayer order to the HV output. */
+	src_fmt = v4l2_subdev_state_get_format(state, MALI_C720_ISP_PAD_SOURCE_HV);
+	src_fmt->width = sink_fmt->width;
+	src_fmt->height = sink_fmt->height;
+	src_fmt->code = mali_c720_shift_mbus_format(cfg, MALI_C720_FORMAT_16BIT)->code;
+
+	return 0;
+}
+
+static void mali_c720_isp_stop(struct mali_c720 *mali_c720)
+{
+	struct mali_c720_context *ctx = mali_c720_get_active_context(mali_c720);
+
+	mali_c720_ctx_mgr_stop_context(ctx);
+}
+
+static int mali_c720_isp_start(struct mali_c720_isp *isp,
+			       struct v4l2_subdev_state *state)
+{
+	struct mali_c720 *mali_c720 = isp->mdev.mali_c720;
+	struct mali_c720_context *ctx = mali_c720_get_active_context(mali_c720);
+	const struct mali_c720_mbus_format_info *cfg;
+	const struct v4l2_mbus_framefmt *fmt;
+	struct mali_c720_top_cfg top_cfg;
+	struct media_pad *sink_pad;
+	struct v4l2_subdev *src_sd;
+	int ret;
+
+	fmt = v4l2_subdev_state_get_format(state, MALI_C720_ISP_PAD_SINK_VIDEO);
+	cfg = mali_c720_get_mbus_config_by_code(fmt->code);
+	if (!cfg)
+		return -EINVAL;
+
+	top_cfg.width = fmt->width;
+	top_cfg.height = fmt->height;
+	top_cfg.rggb_start = (u32)__ffs(cfg->type);
+
+	mali_c720_ctx_mgr_configure_context(ctx, &top_cfg);
+
+	sink_pad = &isp->pads[MALI_C720_ISP_PAD_SINK_VIDEO];
+	isp->remote_src = media_pad_remote_pad_unique(sink_pad);
+	ret = PTR_ERR_OR_ZERO(isp->remote_src);
+	if (ret)
+		return ret;
+
+	src_sd = media_entity_to_v4l2_subdev(isp->remote_src->entity);
+	ret = v4l2_subdev_enable_streams(src_sd, isp->remote_src->index, BIT(0));
+	if (ret && ret != -EALREADY) {
+		dev_err(mali_c720->dev, "Failed to start ISP source\n");
+		return ret;
+	}
+
+	return 0;
+}
+
+static int mali_c720_isp_enable_streams(struct v4l2_subdev *sd,
+					struct v4l2_subdev_state *state, u32 pad,
+					u64 streams_mask)
+{
+	struct mali_c720_subdev *mdev = v4l2_sd_to_mali_c720_sd(sd);
+	struct mali_c720_isp *isp = mali_c720_sd_to_sd(mdev, struct mali_c720_isp);
+	int ret;
+
+	/* Enable the stream but only start the ISP once. */
+	if (isp->enabled)
+		return 0;
+
+	ret = mali_c720_isp_start(isp, state);
+	if (ret)
+		return ret;
+
+	isp->enabled = true;
+
+	return 0;
+}
+
+static int mali_c720_isp_disable_streams(struct v4l2_subdev *sd,
+					 struct v4l2_subdev_state *state, u32 pad,
+					 u64 streams_mask)
+{
+	struct mali_c720_subdev *mdev = v4l2_sd_to_mali_c720_sd(sd);
+	struct mali_c720_isp *isp = mali_c720_sd_to_sd(mdev, struct mali_c720_isp);
+	struct mali_c720 *mali_c720 = mdev->mali_c720;
+	struct v4l2_subdev *src_sd;
+
+	if (!isp->enabled)
+		return 0;
+
+	mali_c720_isp_stop(mali_c720);
+
+	if (isp->remote_src) {
+		src_sd = media_entity_to_v4l2_subdev(isp->remote_src->entity);
+		v4l2_subdev_disable_streams(src_sd, isp->remote_src->index,
+					    BIT(0));
+	}
+	isp->remote_src = NULL;
+	isp->enabled = false;
+
+	return 0;
+}
+
+static const struct v4l2_subdev_pad_ops mali_c720_isp_pad_ops = {
+	.enum_mbus_code		= mali_c720_isp_enum_mbus_code,
+	.enum_frame_size	= mali_c720_isp_enum_frame_size,
+	.get_fmt		= v4l2_subdev_get_fmt,
+	.set_fmt		= mali_c720_isp_set_fmt,
+	.link_validate		= v4l2_subdev_link_validate_default,
+	.enable_streams		= mali_c720_isp_enable_streams,
+	.disable_streams	= mali_c720_isp_disable_streams,
+};
+
+void mali_c720_isp_queue_event_sof(struct mali_c720 *mali_c720, u32 sequence)
+{
+	struct mali_c720_isp *isp = &mali_c720->isp;
+	struct mali_c720_subdev *mdev = &isp->mdev;
+
+	struct v4l2_event event = {
+		.type = V4L2_EVENT_FRAME_SYNC,
+	};
+
+	event.u.frame_sync.frame_sequence = sequence;
+	v4l2_event_queue(mdev->sd.devnode, &event);
+}
+
+static int
+mali_c720_isp_subscribe_event(struct v4l2_subdev *sd, struct v4l2_fh *fh,
+			      struct v4l2_event_subscription *sub)
+{
+	if (sub->type != V4L2_EVENT_FRAME_SYNC)
+		return -EINVAL;
+
+	/* V4L2_EVENT_FRAME_SYNC doesn't require an id, so zero should be set */
+	if (sub->id != 0)
+		return -EINVAL;
+
+	return v4l2_event_subscribe(fh, sub, 0, NULL);
+}
+
+static const struct v4l2_subdev_core_ops mali_c720_isp_core_ops = {
+	.subscribe_event = mali_c720_isp_subscribe_event,
+	.unsubscribe_event = v4l2_event_subdev_unsubscribe,
+};
+
+static const struct v4l2_subdev_ops mali_c720_isp_ops = {
+	.pad	= &mali_c720_isp_pad_ops,
+	.core	= &mali_c720_isp_core_ops,
+};
+
+static int mali_c720_isp_init_state(struct v4l2_subdev *sd,
+				    struct v4l2_subdev_state *state)
+{
+	struct v4l2_mbus_framefmt *sink_fmt, *src_fmt;
+
+	sink_fmt = v4l2_subdev_state_get_format(state, MALI_C720_ISP_PAD_SINK_VIDEO);
+	sink_fmt->width = MALI_C720_DEFAULT_WIDTH;
+	sink_fmt->height = MALI_C720_DEFAULT_HEIGHT;
+	sink_fmt->field = V4L2_FIELD_NONE;
+	sink_fmt->code = MEDIA_BUS_FMT_SRGGB24_1X24;
+	sink_fmt->colorspace = V4L2_COLORSPACE_RAW;
+	sink_fmt->xfer_func = V4L2_MAP_XFER_FUNC_DEFAULT(sink_fmt->colorspace);
+	sink_fmt->ycbcr_enc = V4L2_MAP_YCBCR_ENC_DEFAULT(sink_fmt->colorspace);
+	sink_fmt->quantization = V4L2_QUANTIZATION_FULL_RANGE;
+
+	src_fmt = v4l2_subdev_state_get_format(state, MALI_C720_ISP_PAD_SOURCE_HV);
+	*src_fmt = *sink_fmt;
+	src_fmt->code = MEDIA_BUS_FMT_SRGGB16_1X16;
+
+	return 0;
+}
+
+static const struct v4l2_subdev_internal_ops mali_c720_isp_internal_ops = {
+	.init_state = mali_c720_isp_init_state,
+};
+
+static int mali_c720_isp_subdev_link_setup(struct media_entity *entity,
+					   const struct media_pad *local,
+					   const struct media_pad *remote,
+					   u32 flags)
+{
+	struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
+	struct mali_c720 *mali_c720 = v4l2_sd_to_mali_c720_sd(sd)->mali_c720;
+	struct media_pad *remote_src;
+
+	if (local->index != MALI_C720_ISP_PAD_SINK_VIDEO)
+		return 0;
+
+	if (flags & MEDIA_LNK_FL_ENABLED) {
+		remote_src = media_pad_remote_pad_unique(local);
+
+		/* No previous link connected */
+		if (IS_ERR(remote_src))
+			return 0;
+
+		if (remote_src != remote) {
+			dev_err(mali_c720->dev,
+				"ISP sink pad %u is already connected to another source\n",
+				local->index);
+			return -EBUSY;
+		}
+	}
+
+	return 0;
+}
+
+static const struct media_entity_operations mali_c720_isp_media_ops = {
+	.link_setup		= mali_c720_isp_subdev_link_setup,
+	.link_validate		= v4l2_subdev_link_validate,
+};
+
+int mali_c720_register_isp(struct mali_c720 *mali_c720)
+{
+	struct mali_c720_isp *isp = &mali_c720->isp;
+	struct mali_c720_subdev *mdev = &isp->mdev;
+	struct v4l2_subdev *sd = &mdev->sd;
+	int ret;
+
+	mdev->mali_c720 = mali_c720;
+
+	v4l2_subdev_init(sd, &mali_c720_isp_ops);
+	sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE |
+		     V4L2_SUBDEV_FL_HAS_EVENTS;
+	sd->entity.ops = &mali_c720_isp_media_ops;
+	sd->entity.function = MEDIA_ENT_F_PROC_VIDEO_ISP;
+	sd->internal_ops = &mali_c720_isp_internal_ops;
+	strscpy(sd->name, "mali-c720 isp", sizeof(sd->name));
+
+	isp->pads[MALI_C720_ISP_PAD_SINK_VIDEO].flags = MEDIA_PAD_FL_SINK |
+							MEDIA_PAD_FL_MUST_CONNECT;
+	isp->pads[MALI_C720_ISP_PAD_SOURCE_HV].flags = MEDIA_PAD_FL_SOURCE;
+
+	ret = media_entity_pads_init(&sd->entity,
+				     MALI_C720_ISP_NUM_PADS,
+				     isp->pads);
+	if (ret)
+		goto err_clear_parent;
+
+	ret = v4l2_subdev_init_finalize(sd);
+	if (ret)
+		goto err_cleanup_media_entity;
+
+	ret = v4l2_device_register_subdev(&mali_c720->v4l2_dev, sd);
+	if (ret)
+		goto err_cleanup_subdev;
+
+	return 0;
+
+err_cleanup_subdev:
+	v4l2_subdev_cleanup(sd);
+err_cleanup_media_entity:
+	media_entity_cleanup(&sd->entity);
+err_clear_parent:
+	mdev->mali_c720 = NULL;
+
+	return ret;
+}
+
+void mali_c720_unregister_isp(struct mali_c720 *mali_c720)
+{
+	struct mali_c720_isp *isp = &mali_c720->isp;
+	struct mali_c720_subdev *mdev = &isp->mdev;
+
+	if (!mdev->mali_c720)
+		return;
+
+	v4l2_device_unregister_subdev(&mdev->sd);
+}
+
+void mali_c720_cleanup_isp(struct mali_c720 *mali_c720)
+{
+	struct mali_c720_isp *isp = &mali_c720->isp;
+	struct mali_c720_subdev *mdev = &isp->mdev;
+
+	if (!mdev->mali_c720)
+		return;
+
+	v4l2_subdev_cleanup(&mdev->sd);
+	media_entity_cleanup(&mdev->sd.entity);
+	mdev->mali_c720 = NULL;
+}
diff --git a/drivers/media/platform/arm/mali-c720/mali-c720-vision-pipe.c b/drivers/media/platform/arm/mali-c720/mali-c720-vision-pipe.c
new file mode 100644
index 0000000000000000000000000000000000000000..1a0ff0486dca1637fc3112009894e719312cfc82
--- /dev/null
+++ b/drivers/media/platform/arm/mali-c720/mali-c720-vision-pipe.c
@@ -0,0 +1,260 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * ARM Mali-C720 ISP Driver - Image signal processor
+ *
+ * Copyright (C) 2026 Arm Ltd
+ */
+
+#include <linux/string.h>
+
+#include <media/media-entity.h>
+#include <media/v4l2-common.h>
+
+#include "mali-c720-common.h"
+
+static int mali_c720_vision_pipe_enum_mbus_code(struct v4l2_subdev *sd,
+						struct v4l2_subdev_state *state,
+						struct v4l2_subdev_mbus_code_enum *code)
+{
+	const struct mali_c720_mbus_format_info *cfg;
+	struct mali_c720_mbus_format_match match;
+
+	switch (code->pad) {
+	case MALI_C720_VISION_PIPE_PAD_SOURCE_RGB:
+		if (code->index)
+			return -EINVAL;
+		code->code = MEDIA_BUS_FMT_RGB121212_1X36;
+		break;
+	case MALI_C720_VISION_PIPE_PAD_SINK_VIDEO:
+		match.type_mask = MALI_C720_FORMAT_BAYER;
+		match.depth_mask = MALI_C720_FORMAT_16BIT;
+
+		cfg = mali_c720_get_mbus_config_by_matched_index(code->index, &match);
+		if (!cfg)
+			return -EINVAL;
+		code->code = cfg->code;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static int mali_c720_vision_pipe_enum_frame_size(struct v4l2_subdev *sd,
+						 struct v4l2_subdev_state *state,
+						 struct v4l2_subdev_frame_size_enum *fse)
+{
+	const struct mali_c720_mbus_format_info *cfg;
+	struct mali_c720_mbus_format_match match;
+
+	if (fse->index)
+		return -EINVAL;
+
+	switch (fse->pad) {
+	case MALI_C720_VISION_PIPE_PAD_SOURCE_RGB:
+		if (fse->code != MEDIA_BUS_FMT_RGB121212_1X36)
+			return -EINVAL;
+		break;
+	case MALI_C720_VISION_PIPE_PAD_SINK_VIDEO:
+		match.type_mask = MALI_C720_FORMAT_BAYER;
+		match.depth_mask = MALI_C720_FORMAT_16BIT;
+
+		cfg = mali_c720_get_mbus_config_by_code(fse->code);
+		if (!cfg || !mali_c720_validate_mbus_format_match(cfg, &match))
+			return -EINVAL;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	fse->min_width = MALI_C720_MIN_INPUT_WIDTH;
+	fse->min_height = MALI_C720_MIN_INPUT_HEIGHT;
+	fse->max_width = MALI_C720_MAX_WIDTH;
+	fse->max_height = MALI_C720_MAX_HEIGHT;
+
+	return 0;
+}
+
+static int mali_c720_vision_pipe_set_fmt(struct v4l2_subdev *sd,
+					 const struct v4l2_subdev_client_info *ci,
+					 struct v4l2_subdev_state *state,
+					 struct v4l2_subdev_format *format)
+{
+	struct v4l2_mbus_framefmt *fmt = &format->format;
+	struct v4l2_mbus_framefmt *src_fmt, *sink_fmt;
+	const struct mali_c720_mbus_format_info *cfg;
+	struct mali_c720_mbus_format_match match;
+
+	if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE &&
+	    media_entity_is_streaming(&sd->entity))
+		return -EBUSY;
+
+	/*
+	 * Disallow set_fmt on the source pad; size is derived from the sink
+	 * pad, while the RGB source format is fixed.
+	 */
+	if (format->pad != MALI_C720_VISION_PIPE_PAD_SINK_VIDEO)
+		return v4l2_subdev_get_fmt(sd, state, format);
+
+	sink_fmt = v4l2_subdev_state_get_format(state, MALI_C720_VISION_PIPE_PAD_SINK_VIDEO);
+
+	match.type_mask = MALI_C720_FORMAT_BAYER;
+	match.depth_mask = MALI_C720_FORMAT_16BIT;
+
+	cfg = mali_c720_get_mbus_config_by_code(fmt->code);
+	if (!cfg || !mali_c720_validate_mbus_format_match(cfg, &match))
+		cfg = mali_c720_get_mbus_config_by_code(MEDIA_BUS_FMT_SRGGB16_1X16);
+
+	sink_fmt->code = cfg->code;
+
+	sink_fmt->width = fmt->width;
+	sink_fmt->height = fmt->height;
+	v4l_bound_align_image(&sink_fmt->width, MALI_C720_MIN_INPUT_WIDTH,
+			      MALI_C720_MAX_WIDTH, 1,
+			      &sink_fmt->height, MALI_C720_MIN_INPUT_HEIGHT,
+			      MALI_C720_MAX_HEIGHT, 1, 0);
+
+	*fmt = *sink_fmt;
+
+	/* Propagate the input dimensions to the RGB output. */
+	src_fmt = v4l2_subdev_state_get_format(state,
+					       MALI_C720_VISION_PIPE_PAD_SOURCE_RGB);
+	src_fmt->width = sink_fmt->width;
+	src_fmt->height = sink_fmt->height;
+
+	return 0;
+}
+
+static int mali_c720_vision_pipe_enable_streams(struct v4l2_subdev *sd,
+						struct v4l2_subdev_state *state,
+						u32 pad, u64 streams_mask)
+{
+	return 0;
+}
+
+static int mali_c720_vision_pipe_disable_streams(struct v4l2_subdev *sd,
+						 struct v4l2_subdev_state *state,
+						 u32 pad, u64 streams_mask)
+{
+	return 0;
+}
+
+static const struct v4l2_subdev_pad_ops mali_c720_vision_pipe_pad_ops = {
+	.enum_mbus_code		= mali_c720_vision_pipe_enum_mbus_code,
+	.enum_frame_size	= mali_c720_vision_pipe_enum_frame_size,
+	.get_fmt		= v4l2_subdev_get_fmt,
+	.set_fmt		= mali_c720_vision_pipe_set_fmt,
+	.link_validate		= v4l2_subdev_link_validate_default,
+	.enable_streams		= mali_c720_vision_pipe_enable_streams,
+	.disable_streams	= mali_c720_vision_pipe_disable_streams,
+};
+
+static const struct v4l2_subdev_ops mali_c720_vision_pipe_ops = {
+	.pad = &mali_c720_vision_pipe_pad_ops,
+};
+
+static int mali_c720_vision_pipe_init_state(struct v4l2_subdev *sd,
+					    struct v4l2_subdev_state *state)
+{
+	struct v4l2_mbus_framefmt *sink_fmt, *src_fmt;
+
+	sink_fmt = v4l2_subdev_state_get_format(state, MALI_C720_VISION_PIPE_PAD_SINK_VIDEO);
+	sink_fmt->width = MALI_C720_DEFAULT_WIDTH;
+	sink_fmt->height = MALI_C720_DEFAULT_HEIGHT;
+	sink_fmt->field = V4L2_FIELD_NONE;
+	sink_fmt->code = MEDIA_BUS_FMT_SRGGB16_1X16;
+	sink_fmt->colorspace = V4L2_COLORSPACE_RAW;
+	sink_fmt->xfer_func = V4L2_MAP_XFER_FUNC_DEFAULT(sink_fmt->colorspace);
+	sink_fmt->ycbcr_enc = V4L2_MAP_YCBCR_ENC_DEFAULT(sink_fmt->colorspace);
+	sink_fmt->quantization = V4L2_QUANTIZATION_FULL_RANGE;
+
+	src_fmt = v4l2_subdev_state_get_format(state, MALI_C720_VISION_PIPE_PAD_SOURCE_RGB);
+	*src_fmt = *sink_fmt;
+	src_fmt->code = MEDIA_BUS_FMT_RGB121212_1X36;
+	src_fmt->colorspace = V4L2_COLORSPACE_SRGB;
+	src_fmt->xfer_func = V4L2_MAP_XFER_FUNC_DEFAULT(src_fmt->colorspace);
+	src_fmt->ycbcr_enc = V4L2_MAP_YCBCR_ENC_DEFAULT(src_fmt->colorspace);
+	src_fmt->quantization =
+		V4L2_MAP_QUANTIZATION_DEFAULT(true, src_fmt->colorspace,
+					      src_fmt->ycbcr_enc);
+
+	return 0;
+}
+
+static const struct v4l2_subdev_internal_ops mali_c720_vision_pipe_internal_ops = {
+	.init_state = mali_c720_vision_pipe_init_state,
+};
+
+static const struct media_entity_operations mali_c720_vision_pipe_media_ops = {
+	.link_validate		= v4l2_subdev_link_validate,
+};
+
+int mali_c720_register_vision_pipe(struct mali_c720 *mali_c720)
+{
+	struct mali_c720_vision_pipe *pipe = &mali_c720->vision_pipe;
+	struct mali_c720_subdev *mdev = &pipe->mdev;
+	struct v4l2_subdev *sd = &mdev->sd;
+	int ret;
+
+	mdev->mali_c720 = mali_c720;
+
+	v4l2_subdev_init(sd, &mali_c720_vision_pipe_ops);
+	sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
+	sd->entity.ops = &mali_c720_vision_pipe_media_ops;
+	sd->entity.function = MEDIA_ENT_F_PROC_VIDEO_ISP;
+	sd->internal_ops = &mali_c720_vision_pipe_internal_ops;
+	strscpy(sd->name, "mali-c720 hv pipe", sizeof(sd->name));
+
+	pipe->pads[MALI_C720_VISION_PIPE_PAD_SINK_VIDEO].flags = MEDIA_PAD_FL_SINK |
+								 MEDIA_PAD_FL_MUST_CONNECT;
+	pipe->pads[MALI_C720_VISION_PIPE_PAD_SOURCE_RGB].flags = MEDIA_PAD_FL_SOURCE;
+	ret = media_entity_pads_init(&sd->entity,
+				     MALI_C720_VISION_PIPE_NUM_PADS,
+				     pipe->pads);
+	if (ret)
+		goto err_clear_parent;
+
+	ret = v4l2_subdev_init_finalize(sd);
+	if (ret)
+		goto err_cleanup_media_entity;
+
+	ret = v4l2_device_register_subdev(&mali_c720->v4l2_dev, sd);
+	if (ret)
+		goto err_cleanup_subdev;
+
+	return 0;
+
+err_cleanup_subdev:
+	v4l2_subdev_cleanup(sd);
+err_cleanup_media_entity:
+	media_entity_cleanup(&sd->entity);
+err_clear_parent:
+	mdev->mali_c720 = NULL;
+
+	return ret;
+}
+
+void mali_c720_unregister_vision_pipe(struct mali_c720 *mali_c720)
+{
+	struct mali_c720_vision_pipe *pipe = &mali_c720->vision_pipe;
+	struct mali_c720_subdev *mdev = &pipe->mdev;
+
+	if (!mdev->mali_c720)
+		return;
+
+	v4l2_device_unregister_subdev(&mdev->sd);
+}
+
+void mali_c720_cleanup_vision_pipe(struct mali_c720 *mali_c720)
+{
+	struct mali_c720_vision_pipe *pipe = &mali_c720->vision_pipe;
+	struct mali_c720_subdev *mdev = &pipe->mdev;
+
+	if (!mdev->mali_c720)
+		return;
+
+	v4l2_subdev_cleanup(&mdev->sd);
+	media_entity_cleanup(&mdev->sd.entity);
+	mdev->mali_c720 = NULL;
+}

-- 
2.55.0


  parent reply	other threads:[~2026-11-24 17:08 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24 17:07 [PATCH 00/24] Add Arm Mali-C720 Image Signal Processor Driver Anthony McGivern
2026-11-24 17:07 ` [PATCH 01/24] media: uapi: Add 24-bit Bayer media bus formats Anthony McGivern
2026-11-24 17:07 ` [PATCH 02/24] dt-bindings: media: Add bindings for Arm Mali-C720 Anthony McGivern
2026-11-24 17:07 ` [PATCH 03/24] media: uapi: Add a control ID base for Mali-C720 ISP Anthony McGivern
2026-11-24 17:07 ` [PATCH 04/24] media: mali-c720: Add register access helpers Anthony McGivern
2026-11-24 17:07 ` [PATCH 05/24] media: mali-c720: Add hardware identification Anthony McGivern
2026-11-24 17:07 ` [PATCH 06/24] media: mali-c720: Add format handling Anthony McGivern
2026-11-24 17:07 ` [PATCH 07/24] media: mali-c720: Add hardware discovery support Anthony McGivern
2026-11-24 17:07 ` [PATCH 08/24] media: mali-c720: Add context manager and interrupt handling Anthony McGivern
2026-11-24 17:07 ` [PATCH 09/24] media: mali-c720: Add input frontend subdevice Anthony McGivern
2026-11-24 17:07 ` Anthony McGivern [this message]
2026-11-24 17:07 ` [PATCH 11/24] media: mali-c720: Add full-resolution output subdevice Anthony McGivern
2026-11-24 17:07 ` [PATCH 12/24] media: mali-c720: Add video capture nodes Anthony McGivern
2026-11-24 17:07 ` [PATCH 13/24] media: mali-c720: Add Mali-C720 ISP driver Anthony McGivern
2026-11-24 17:07 ` [PATCH 14/24] media: mali-c720: Add test pattern generator subdevices Anthony McGivern
2026-11-24 17:07 ` [PATCH 15/24] media: Documentation: Add Mali-C720 ISP documentation Anthony McGivern
2026-11-24 17:07 ` [PATCH 16/24] media: uapi: Add Mali-C720 statistics meta format Anthony McGivern
2026-11-24 17:07 ` [PATCH 17/24] media: uapi: Add statistics structs to mali-c720-config.h Anthony McGivern
2026-11-24 17:07 ` [PATCH 18/24] media: mali-c720: Add 3A statistics video node Anthony McGivern
2026-11-24 17:07 ` [PATCH 19/24] media: Documentation: Document Mali-C720 statistics capture Anthony McGivern
2026-11-24 17:07 ` [PATCH 20/24] media: uapi: Add Mali-C720 parameters meta format Anthony McGivern
2026-11-24 17:07 ` [PATCH 21/24] media: uapi: Add parameter structs to mali-c720-config.h Anthony McGivern
2026-11-24 17:07 ` [PATCH 22/24] media: mali-c720: Add parameters video node Anthony McGivern
2026-11-24 17:07 ` [PATCH 23/24] media: Documentation: Document Mali-C720 parameter settings Anthony McGivern
2026-11-24 17:07 ` [PATCH 24/24] MAINTAINERS: Add entry for mali-c720 driver Anthony McGivern

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261124-b4-initial-upstream-candidate-v1-10-0cb9bde1bd30@arm.com \
    --to=anthony.mcgivern@arm.com \
    --cc=conor+dt@kernel.org \
    --cc=dan.scally@ideasonboard.com \
    --cc=devicetree@vger.kernel.org \
    --cc=hverkuil@kernel.org \
    --cc=jacopo.mondi@ideasonboard.com \
    --cc=kieran.bingham@ideasonboard.com \
    --cc=konstantin.babin@arm.com \
    --cc=krzk+dt@kernel.org \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linusw@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=nayden.kanchev@arm.com \
    --cc=robh@kernel.org \
    --cc=sakari.ailus@linux.intel.com \
    --cc=vincenzo.frascino@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox