From patchwork Sun Mar 24 22:08:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 783921 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8E1A83BB32 for ; Sun, 24 Mar 2024 22:09:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711318160; cv=none; b=N2YCqGmzKkXJA/Bnz9vQXwYnjdKUQbqt2OLkk8jON5idPqsrJVEgECia4PzKkxcgeqXontX7/9iKY0mmf/pDcCeaSP+9seJ8TMesbI6fmI6bnRGftk3bxoydOcCBmyb2D9g9ZFWA+uZAa1ejXckkXcb20SmkCZ4nyCB5w4hDRG0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711318160; c=relaxed/simple; bh=X96dr56ihnMIcJGUHevqAI72YWJlRxX+/kBx1HAF7pw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZpIrEam/Q+qwnu+jvzeATtVGW38p1NIhAPSiwtG79PW1dorP3reb3KqjFg59u0Y57Vxl4NVhPaUuH/1RQ1G44lBnHEcGUrsI7ImbR33oogBKdM4/bfD5Uhx45aBbsE9NH8wsKbNUWGCwgnezr7Lzw3vQA0BzlUYGmH0IyGumBwI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=tTQPI9a8; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="tTQPI9a8" Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 4974D2D63; Sun, 24 Mar 2024 23:08:39 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1711318119; bh=X96dr56ihnMIcJGUHevqAI72YWJlRxX+/kBx1HAF7pw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tTQPI9a80HZ8ODEJWReNltzfDxDKCJHHOsWaNdJmDfKLixJrJ4TJ/urwCW3m2Dq17 ZSlOmBnz0YXL6hW+K055nLFeYr7SxRuCc6VhAWuUeMi/vhFDuY57vo9JcfjMrXNV1Q XVp0zvDsjP9E/MeVJonkf2gV4R59x7yh48+t3c74= From: Laurent Pinchart To: linux-media@vger.kernel.org Cc: Dave Stevenson , David Plowman , Jean-Michel Hautbois , Hans Verkuil , Naushir Patuck , Sakari Ailus , kernel-list@raspberrypi.com, linux-rpi-kernel@lists.infradead.org, Florian Fainelli , Ray Jui , Scott Branden , bcm-kernel-feedback-list@broadcom.com Subject: [PATCH v7 04/15] media: i2c: imx219: Report streams using frame descriptors Date: Mon, 25 Mar 2024 00:08:40 +0200 Message-ID: <20240324220854.15010-5-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240324220854.15010-1-laurent.pinchart@ideasonboard.com> References: <20240324220854.15010-1-laurent.pinchart@ideasonboard.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 Reviewed-by: Jacopo Mondi --- 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 #include +#include #include #include #include @@ -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 = {