From patchwork Mon Oct 9 12:05:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 731290 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 EEF2DE95A91 for ; Mon, 9 Oct 2023 12:05:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346452AbjJIMFh (ORCPT ); Mon, 9 Oct 2023 08:05:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346445AbjJIMFf (ORCPT ); Mon, 9 Oct 2023 08:05:35 -0400 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B3208B4 for ; Mon, 9 Oct 2023 05:05:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1696853135; x=1728389135; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=rr8eaXcYtci4MIUnxgJplu+CGOcDsdx0Ws3VZvKbuS8=; b=nTmKhkDoug47uUo9ZUCw9t9CKTUnqAKEjweF/++EE13SRTyFNvY/Li3U WHqcfXVpD6TlMY9OpYkVPurRaTU7Ppz+XtTjpABVDPValAY28NeR8Sd3S WeRNhPQBCrKels57xMTwNMNzNZ93HVfEFJQkcr8UZbdSPHviiG4S3av0b OnvUpLxJWyTIATzQqNwa0YnWr1NzpzIk5DSqiSE4bi2B9xnnW9XZHhW5Y z9eEBdrmQQjv+/HVQ0p2KORzVmjxkT5nmO30jU7NU7X/tTzGQdJjA93y2 bsCPLcgM3RnM3QZeZB9171IC+WxTLYMURzLmXPmhc5ZRkJcQzMiNsyDbG w==; X-IronPort-AV: E=McAfee;i="6600,9927,10858"; a="2725500" X-IronPort-AV: E=Sophos;i="6.03,210,1694761200"; d="scan'208";a="2725500" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Oct 2023 05:05:34 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10858"; a="869216196" X-IronPort-AV: E=Sophos;i="6.03,210,1694761200"; d="scan'208";a="869216196" Received: from turnipsi.fi.intel.com (HELO kekkonen.fi.intel.com) ([10.237.72.44]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Oct 2023 05:05:31 -0700 Received: from svinhufvud.ger.corp.intel.com (localhost [IPv6:::1]) by kekkonen.fi.intel.com (Postfix) with ESMTP id 62A1D11F9E8; Mon, 9 Oct 2023 15:05:27 +0300 (EEST) From: Sakari Ailus To: linux-media@vger.kernel.org Cc: Laurent Pinchart , tomi.valkeinen@ideasonboard.com Subject: [PATCH 1/4] media: v4l: subdev: Set sub-device active state earlier Date: Mon, 9 Oct 2023 15:05:22 +0300 Message-Id: <20231009120525.202957-2-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231009120525.202957-1-sakari.ailus@linux.intel.com> References: <20231009120525.202957-1-sakari.ailus@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Set sub-device active state earlier in order to have it available to the sub-device driver when driver's init_cfg operation is called. Signed-off-by: Sakari Ailus --- drivers/media/v4l2-core/v4l2-subdev.c | 14 +++++++++----- include/media/v4l2-subdev.h | 3 ++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c index d295a4e87b66..cd590951c393 100644 --- a/drivers/media/v4l2-core/v4l2-subdev.c +++ b/drivers/media/v4l2-core/v4l2-subdev.c @@ -53,7 +53,7 @@ static int subdev_fh_init(struct v4l2_subdev_fh *fh, struct v4l2_subdev *sd) struct v4l2_subdev_state *state; static struct lock_class_key key; - state = __v4l2_subdev_state_alloc(sd, "fh->state->lock", &key); + state = __v4l2_subdev_state_alloc(sd, "fh->state->lock", &key, false); if (IS_ERR(state)) return PTR_ERR(state); @@ -1426,7 +1426,7 @@ EXPORT_SYMBOL_GPL(v4l2_subdev_has_pad_interdep); struct v4l2_subdev_state * __v4l2_subdev_state_alloc(struct v4l2_subdev *sd, const char *lock_name, - struct lock_class_key *lock_key) + struct lock_class_key *lock_key, bool active) { struct v4l2_subdev_state *state; int ret; @@ -1451,6 +1451,9 @@ __v4l2_subdev_state_alloc(struct v4l2_subdev *sd, const char *lock_name, } } + if (active) + sd->active_state = state; + /* * There can be no race at this point, but we lock the state anyway to * satisfy lockdep checks. @@ -1470,6 +1473,9 @@ __v4l2_subdev_state_alloc(struct v4l2_subdev *sd, const char *lock_name, kfree(state); + if (active) + sd->active_state = NULL; + return ERR_PTR(ret); } EXPORT_SYMBOL_GPL(__v4l2_subdev_state_alloc); @@ -1493,12 +1499,10 @@ int __v4l2_subdev_init_finalize(struct v4l2_subdev *sd, const char *name, { struct v4l2_subdev_state *state; - state = __v4l2_subdev_state_alloc(sd, name, key); + state = __v4l2_subdev_state_alloc(sd, name, key, true); if (IS_ERR(state)) return PTR_ERR(state); - sd->active_state = state; - return 0; } EXPORT_SYMBOL_GPL(__v4l2_subdev_init_finalize); diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h index c1f90c1223a7..ea05b70389b3 100644 --- a/include/media/v4l2-subdev.h +++ b/include/media/v4l2-subdev.h @@ -1346,7 +1346,8 @@ bool v4l2_subdev_has_pad_interdep(struct media_entity *entity, */ struct v4l2_subdev_state *__v4l2_subdev_state_alloc(struct v4l2_subdev *sd, const char *lock_name, - struct lock_class_key *key); + struct lock_class_key *key, + bool active); /** * __v4l2_subdev_state_free - free a v4l2_subdev_state From patchwork Mon Oct 9 12:05:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 731289 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 C3FD8E95A8E for ; Mon, 9 Oct 2023 12:05:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346449AbjJIMFk (ORCPT ); Mon, 9 Oct 2023 08:05:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346447AbjJIMFh (ORCPT ); Mon, 9 Oct 2023 08:05:37 -0400 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB89694 for ; Mon, 9 Oct 2023 05:05:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1696853136; x=1728389136; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8unoJ2CF6b7ZuIxRpKSJzquoipvjGCHV6k77AhsjWdU=; b=YN1FruR8EzptWMf5iY1EWLgDhpucPlvcE7XCzDRGBLhKDiBEFWro9Pus yynmEA+jXBeH3D+z3jgL0tuAi5fwDgXjCA8StUDZV5JIHGuZ1m8DYMwIl CLZVuC3mfe26UrSUEU+Y17nuP49LSmvzGP0+Yw1dtiGpdoslZ/VAEh0uu Mlni+o+iu/G4vGhPkrwl98gtJFXwDzMKPk7msK6dSPVCctUN0H6NPLX/w M3MlunkAJrjHYkAYPOzMNNekELZuY3a4RI5MBP+4FafFhcWIO3bzGYuhX CoYQ0qS+ZC0FSwWVNLodgUTiCkIxZoc7f/L/fWOasgL157lITQ+NLFvvk A==; X-IronPort-AV: E=McAfee;i="6600,9927,10858"; a="2725509" X-IronPort-AV: E=Sophos;i="6.03,210,1694761200"; d="scan'208";a="2725509" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Oct 2023 05:05:35 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10858"; a="869216202" X-IronPort-AV: E=Sophos;i="6.03,210,1694761200"; d="scan'208";a="869216202" Received: from turnipsi.fi.intel.com (HELO kekkonen.fi.intel.com) ([10.237.72.44]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Oct 2023 05:05:33 -0700 Received: from svinhufvud.ger.corp.intel.com (localhost [IPv6:::1]) by kekkonen.fi.intel.com (Postfix) with ESMTP id 47BB01206B6; Mon, 9 Oct 2023 15:05:29 +0300 (EEST) From: Sakari Ailus To: linux-media@vger.kernel.org Cc: Laurent Pinchart , tomi.valkeinen@ideasonboard.com Subject: [PATCH 3/4] media: ccs: Rework initialising sub-device state Date: Mon, 9 Oct 2023 15:05:24 +0300 Message-Id: <20231009120525.202957-4-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231009120525.202957-1-sakari.ailus@linux.intel.com> References: <20231009120525.202957-1-sakari.ailus@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Initialise sub-device state in init_cfg callback using ccs_propagate() to the extent it covers of the initialisation. This fixes a bug where the driver configuration was incorrectly initialised. Fixes: 4b05b1baae3e ("media: ccs: Use sub-device active state") Signed-off-by: Sakari Ailus --- drivers/media/i2c/ccs/ccs-core.c | 47 ++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/drivers/media/i2c/ccs/ccs-core.c b/drivers/media/i2c/ccs/ccs-core.c index 2abfd5932e02..6589b0d84e06 100644 --- a/drivers/media/i2c/ccs/ccs-core.c +++ b/drivers/media/i2c/ccs/ccs-core.c @@ -2075,6 +2075,7 @@ static void ccs_propagate(struct v4l2_subdev *subdev, struct ccs_sensor *sensor = to_ccs_sensor(subdev); struct ccs_subdev *ssd = to_ccs_subdev(subdev); struct v4l2_rect *comp, *crops[CCS_PADS]; + struct v4l2_mbus_framefmt *fmt; ccs_get_crop_compose(subdev, sd_state, crops, &comp); @@ -2096,6 +2097,9 @@ static void ccs_propagate(struct v4l2_subdev *subdev, fallthrough; case V4L2_SEL_TGT_COMPOSE: *crops[CCS_PAD_SRC] = *comp; + fmt = v4l2_subdev_get_pad_format(subdev, sd_state, CCS_PAD_SRC); + fmt->width = comp->width; + fmt->height = comp->height; if (which == V4L2_SUBDEV_FORMAT_ACTIVE && ssd == sensor->src) sensor->src_src = *crops[CCS_PAD_SRC]; break; @@ -3003,31 +3007,40 @@ static int ccs_init_cfg(struct v4l2_subdev *sd, { struct ccs_subdev *ssd = to_ccs_subdev(sd); struct ccs_sensor *sensor = ssd->sensor; - unsigned int i; + unsigned int pad = ssd == sensor->pixel_array ? + CCS_PA_PAD_SRC : CCS_PAD_SINK; + struct v4l2_mbus_framefmt *fmt = + v4l2_subdev_get_pad_format(sd, sd_state, pad); + struct v4l2_rect *crop = + v4l2_subdev_get_pad_crop(sd, sd_state, pad); mutex_lock(&sensor->mutex); - for (i = 0; i < ssd->npads; i++) { - struct v4l2_mbus_framefmt *fmt = - v4l2_subdev_get_pad_format(sd, sd_state, i); - struct v4l2_rect *crop = - v4l2_subdev_get_pad_crop(sd, sd_state, i); - struct v4l2_rect *comp; - - ccs_get_native_size(ssd, crop); + ccs_get_native_size(ssd, crop); - fmt->width = crop->width; - fmt->height = crop->height; - fmt->code = sensor->internal_csi_format->code; - fmt->field = V4L2_FIELD_NONE; + fmt->width = crop->width; + fmt->height = crop->height; + fmt->code = sensor->internal_csi_format->code; + fmt->field = V4L2_FIELD_NONE; - if (ssd == sensor->pixel_array) - continue; + if (ssd == sensor->pixel_array) { + if (v4l2_subdev_state_whence(sd, sd_state) == + V4L2_SUBDEV_FORMAT_ACTIVE) + sensor->pa_src = *crop; - comp = v4l2_subdev_get_pad_compose(sd, sd_state, i); - *comp = *crop; + mutex_unlock(&sensor->mutex); + return 0; } + fmt = v4l2_subdev_get_pad_format(sd, sd_state, CCS_PAD_SRC); + fmt->code = ssd == sensor->src ? + sensor->csi_format->code : sensor->internal_csi_format->code; + fmt->field = V4L2_FIELD_NONE; + + ccs_propagate(sd, sd_state, + v4l2_subdev_state_whence(sd, sd_state), + V4L2_SEL_TGT_CROP); + mutex_unlock(&sensor->mutex); return 0;