From patchwork Fri Sep 22 14:22:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 725485 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E415CE6FE3A for ; Fri, 22 Sep 2023 14:23:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234271AbjIVOXO (ORCPT ); Fri, 22 Sep 2023 10:23:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234272AbjIVOXM (ORCPT ); Fri, 22 Sep 2023 10:23:12 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B768100 for ; Fri, 22 Sep 2023 07:23:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695392586; x=1726928586; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fKrqt/oVHxujyEDtQ/2VaWPFvNlfU4S6H9l/Pn0mQsY=; b=hAqiCcpBVw+OYQyKwm6q7OcgN5VzQjDEMUaiccGg3nBYC+CbRchJT9fY 6AeP1yqIMcZfGRQxExzlrBwdTDxORFH3BkKXgqc9F20VxhTMSHtxRTVwS lcUaVh+MvIPE+ZNQIz4T0dHI7iCOEoc8JJV+c7K3nEuYIv+yczUjwmWgy 1yezHs7KRCLmqkG32AOoJua0O9jRbWmqhpUCjhbG5OMCpExH3Zaeyn9Nm HkQOqNpYbmj4251DyCQ2EAbtrJCaInarbu2NfqJlDNHM9bU/K2btMQdxA Dw6p8CGaRNTUJb29zPoevLrVvm2xLUUlU1xDGObIRF+K6Kr+eIxZkC085 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10841"; a="360218935" X-IronPort-AV: E=Sophos;i="6.03,167,1694761200"; d="scan'208";a="360218935" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2023 07:23:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10841"; a="741112466" X-IronPort-AV: E=Sophos;i="6.03,167,1694761200"; d="scan'208";a="741112466" Received: from turnipsi.fi.intel.com (HELO kekkonen.fi.intel.com) ([10.237.72.44]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2023 07:23:02 -0700 Received: from svinhufvud.ger.corp.intel.com (localhost [IPv6:::1]) by kekkonen.fi.intel.com (Postfix) with ESMTP id 8FA641208F8; Fri, 22 Sep 2023 17:22:58 +0300 (EEST) From: Sakari Ailus To: linux-media@vger.kernel.org Cc: Laurent Pinchart , tomi.valkeinen@ideasonboard.com, bingbu.cao@intel.com, hongju.wang@intel.com, hverkuil@xs4all.nl, Andrey Konovalov , Jacopo Mondi , Dmitry Perchanov , "Ng, Khai Wen" Subject: [PATCH v4 12/23] media: v4l: subdev: Add helpers for format, crop and compose pointers Date: Fri, 22 Sep 2023 17:22:28 +0300 Message-Id: <20230922142239.259425-13-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230922142239.259425-1-sakari.ailus@linux.intel.com> References: <20230922142239.259425-1-sakari.ailus@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Add a helper for obtaining format, crop and compose pointers. These are convenient for drivers, independently of the driver uses streams or not. Signed-off-by: Sakari Ailus --- drivers/media/v4l2-core/v4l2-subdev.c | 54 ++++++++++++++++++++++---- include/media/v4l2-subdev.h | 56 +++++++++++++++++++++++++++ 2 files changed, 102 insertions(+), 8 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c index d295a4e87b66..854f9d4db923 100644 --- a/drivers/media/v4l2-core/v4l2-subdev.c +++ b/drivers/media/v4l2-core/v4l2-subdev.c @@ -1573,19 +1573,57 @@ v4l2_subdev_init_stream_configs(struct v4l2_subdev_stream_configs *stream_config return 0; } +struct v4l2_mbus_framefmt +*v4l2_subdev_get_fmt_ptr(struct v4l2_subdev *sd, + struct v4l2_subdev_state *state, unsigned int pad, + unsigned int stream) +{ + if (sd->flags & V4L2_SUBDEV_FL_STREAMS) + return v4l2_subdev_state_get_stream_format(state, pad, stream); + + if (pad < sd->entity.num_pads && stream == 0) + return v4l2_subdev_get_pad_format(sd, state, pad); + + return NULL; +} +EXPORT_SYMBOL_GPL(v4l2_subdev_get_fmt_ptr); + +struct v4l2_rect +*v4l2_subdev_get_crop_ptr(struct v4l2_subdev *sd, + struct v4l2_subdev_state *state, unsigned int pad, + unsigned int stream) +{ + if (sd->flags & V4L2_SUBDEV_FL_STREAMS) + return v4l2_subdev_state_get_stream_crop(state, pad, stream); + + if (pad < sd->entity.num_pads && stream == 0) + return v4l2_subdev_get_pad_crop(sd, state, pad); + + return NULL; +} +EXPORT_SYMBOL_GPL(v4l2_subdev_get_crop_ptr); + +struct v4l2_rect +*v4l2_subdev_get_compose_ptr(struct v4l2_subdev *sd, + struct v4l2_subdev_state *state, unsigned int pad, + unsigned int stream) +{ + if (sd->flags & V4L2_SUBDEV_FL_STREAMS) + return v4l2_subdev_state_get_stream_compose(state, pad, stream); + + if (pad < sd->entity.num_pads && stream == 0) + return v4l2_subdev_get_pad_compose(sd, state, pad); + + return NULL; +} +EXPORT_SYMBOL_GPL(v4l2_subdev_get_compose_ptr); + int v4l2_subdev_get_fmt(struct v4l2_subdev *sd, struct v4l2_subdev_state *state, struct v4l2_subdev_format *format) { struct v4l2_mbus_framefmt *fmt; - if (sd->flags & V4L2_SUBDEV_FL_STREAMS) - fmt = v4l2_subdev_state_get_stream_format(state, format->pad, - format->stream); - else if (format->pad < sd->entity.num_pads && format->stream == 0) - fmt = v4l2_subdev_get_pad_format(sd, state, format->pad); - else - fmt = NULL; - + fmt = v4l2_subdev_get_fmt_ptr(sd, state, format->pad, format->stream); if (!fmt) return -EINVAL; diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h index 5f59ff0796b7..7c34243ffed9 100644 --- a/include/media/v4l2-subdev.h +++ b/include/media/v4l2-subdev.h @@ -1479,6 +1479,62 @@ v4l2_subdev_lock_and_get_active_state(struct v4l2_subdev *sd) #if defined(CONFIG_VIDEO_V4L2_SUBDEV_API) +/** + * v4l2_subdev_get_fmt_ptr - Obtain a pointer to V4L2 sub-device format for pad + * and stream + * @sd: subdevice + * @state: subdevice state + * @pad: the pad on the sub-device + * @stream: stream in the pad + * + * For given pad and stream, obtain a pointer to the mbus format from the + * sub-device. + * + * Returns NULL if the format is not found or the parameters are invalid. + */ +struct v4l2_mbus_framefmt * +v4l2_subdev_get_fmt_ptr(struct v4l2_subdev *sd, + struct v4l2_subdev_state *state, unsigned int pad, + unsigned int stream); + +/** + * v4l2_subdev_get_crop_ptr - Obtain a pointer to V4L2 sub-device crop + * rectangle for pad and stream + * @sd: subdevice + * @state: subdevice state + * @pad: the pad on the sub-device + * @stream: stream in the pad + * + * For given pad and stream, obtain a pointer to the crop selection rectangle + * from the sub-device. + * + * Returns NULL if the selection rectangle is not found or the parameters are + * invalid. + */ +struct v4l2_rect * +v4l2_subdev_get_crop_ptr(struct v4l2_subdev *sd, + struct v4l2_subdev_state *state, unsigned int pad, + unsigned int stream); + +/** + * v4l2_subdev_get_compose_ptr - Obtain a pointer to V4L2 sub-device compose + * rectangle for pad and stream + * @sd: subdevice + * @state: subdevice state + * @pad: the pad on the sub-device + * @stream: stream in the pad + * + * For given pad and stream, obtain a pointer to the compose selection rectangle + * from the sub-device. + * + * Returns NULL if the selection rectangle is not found or the parameters are + * invalid. + */ +struct v4l2_rect * +v4l2_subdev_get_compose_ptr(struct v4l2_subdev *sd, + struct v4l2_subdev_state *state, unsigned int pad, + unsigned int stream); + /** * v4l2_subdev_get_fmt() - Fill format based on state * @sd: subdevice