From patchwork Thu Jun 22 11:40:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 695157 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 20513EB64D8 for ; Thu, 22 Jun 2023 11:42:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230421AbjFVLmF (ORCPT ); Thu, 22 Jun 2023 07:42:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229866AbjFVLmD (ORCPT ); Thu, 22 Jun 2023 07:42:03 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A29B21FE1 for ; Thu, 22 Jun 2023 04:41:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1687434100; x=1718970100; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fEB3C+pPcNe1+OJmSCc+QADC6GZMneOzFMRqVN8M09M=; b=Gg61fkTW7Zl0Q3vniIbJ/yIRrh6sFvZKOf1CO9sdRWSM2+xkBftHN7G1 xq6ZHx4uMIQkO+HHbyCGuTX9MS3uux6AiqpZETxLigH0E6vptENaIn3vO ixtIFPEZMTzv9a1VPEJKX8L3+SyN8dtCPjS+LC3NFw1tsBE5atGFXNLwx xYu1GiXNbZR7rTft8mozytamcYChKxyva6oFkbDzgYnYtFx7k6Mc9eaDb 6Gw7KudE6R+SBBNK/HaXxj3V5lbY0C1FO2JeiJzDzQA21xFqOBBt2C4s+ qDeaiulJ9yX9Gp3N3BeICnU5hMXs/IMOnREN5iIP0YNdXztxi0zBQtWnb Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10748"; a="340800476" X-IronPort-AV: E=Sophos;i="6.00,263,1681196400"; d="scan'208";a="340800476" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jun 2023 04:41:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10748"; a="839013559" X-IronPort-AV: E=Sophos;i="6.00,263,1681196400"; d="scan'208";a="839013559" Received: from turnipsi.fi.intel.com (HELO kekkonen.fi.intel.com) ([10.237.72.44]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jun 2023 04:41:12 -0700 Received: from punajuuri.localdomain (punajuuri.localdomain [192.168.240.130]) by kekkonen.fi.intel.com (Postfix) with ESMTP id 42DF0120EC6; Thu, 22 Jun 2023 14:40:51 +0300 (EEST) Received: from sailus by punajuuri.localdomain with local (Exim 4.96) (envelope-from ) id 1qCIg3-003oU2-0a; Thu, 22 Jun 2023 14:40:39 +0300 From: Sakari Ailus To: linux-media@vger.kernel.org Cc: laurent.pinchart@ideasonboard.com, Philipp Zabel , hverkuil@xs4all.nl, Francesco Dolcini , aishwarya.kothari@toradex.com, Robert Foss , Todor Tomov , Hyun Kwon , bingbu.cao@intel.com, niklas.soderlund@ragnatech.se, Kieran Bingham , Benjamin Mugnier , Sylvain Petinot , Eugen Hristev , Nicolas Ferre , Maxime Ripard , Rui Miguel Silva , Fabio Estevam , Bryan O'Donoghue , Sylwester Nawrocki , Dafna Hirschfeld , Hugues Fruchet , Yong Deng , Paul Kocialkowski , "Lad, Prabhakar" , Benoit Parrot , Steve Longerbeam , Thierry Reding , Jonathan Hunter , Sowjanya Komatineni , Marco Felsch Subject: [PATCH v4 27/38] media: v4l: async: Support fwnode endpoint list matching for subdevs Date: Thu, 22 Jun 2023 14:40:17 +0300 Message-Id: <20230622114028.908825-28-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230622114028.908825-1-sakari.ailus@linux.intel.com> References: <20230622114028.908825-1-sakari.ailus@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Support matching V4L2 async sub-devices based on particular fwnode endpoint. This makes it possible to instantiate multiple V4L2 sub-devices based on given fwnode endpoints from a single device, based on driver needs. Signed-off-by: Sakari Ailus Tested-by: Philipp Zabel # imx6qp Tested_by: Niklas Söderlund # rcar + adv746x Tested-by: Aishwarya Kothari # Apalis i.MX6Q with TC358743 --- drivers/media/v4l2-core/v4l2-async.c | 41 +++++++++++++++++++++++++++ drivers/media/v4l2-core/v4l2-subdev.c | 13 +++++++++ include/media/v4l2-async.h | 30 ++++++++++++++++++++ include/media/v4l2-subdev.h | 8 ++++-- 4 files changed, 90 insertions(+), 2 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-async.c b/drivers/media/v4l2-core/v4l2-async.c index 6b3c02d27ebf0..ea27e04f0f753 100644 --- a/drivers/media/v4l2-core/v4l2-async.c +++ b/drivers/media/v4l2-core/v4l2-async.c @@ -134,6 +134,30 @@ static bool match_fwnode(struct v4l2_async_notifier *notifier, "v4l2-async: matching for notifier %pfw, sd fwnode %pfw\n", dev_fwnode(notifier_dev(notifier)), sd->fwnode); + if (!list_empty(&sd->async_subdev_endpoint_list)) { + struct v4l2_async_subdev_endpoint *ase; + + dev_dbg(sd->dev, + "v4l2-async: endpoint fwnode list available, looking for %pfw\n", + match->fwnode); + + list_for_each_entry(ase, &sd->async_subdev_endpoint_list, + async_subdev_endpoint_entry) { + bool matched = ase->endpoint == match->fwnode; + + dev_dbg(sd->dev, + "v4l2-async: endpoint-endpoint match %sfound with %pfw\n", + matched ? "" : "not ", ase->endpoint); + + if (matched) + return true; + } + + dev_dbg(sd->dev, "async: no endpoint matched\n"); + + return false; + } + if (match_fwnode_one(notifier, sd, sd->fwnode, match)) return true; @@ -745,6 +769,23 @@ __v4l2_async_nf_add_i2c(struct v4l2_async_notifier *notifier, int adapter_id, } EXPORT_SYMBOL_GPL(__v4l2_async_nf_add_i2c); +int v4l2_async_subdev_endpoint_add(struct v4l2_subdev *sd, + struct fwnode_handle *fwnode) +{ + struct v4l2_async_subdev_endpoint *ase; + + ase = kmalloc(sizeof(*ase), GFP_KERNEL); + if (!ase) + return -ENOMEM; + + ase->endpoint = fwnode; + list_add(&ase->async_subdev_endpoint_entry, + &sd->async_subdev_endpoint_list); + + return 0; +} +EXPORT_SYMBOL_GPL(v4l2_async_subdev_endpoint_add); + struct v4l2_async_connection * v4l2_async_connection_unique(struct v4l2_subdev *sd) { diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c index 2ec179cd12643..217b8019fb9b6 100644 --- a/drivers/media/v4l2-core/v4l2-subdev.c +++ b/drivers/media/v4l2-core/v4l2-subdev.c @@ -1467,8 +1467,20 @@ EXPORT_SYMBOL_GPL(__v4l2_subdev_init_finalize); void v4l2_subdev_cleanup(struct v4l2_subdev *sd) { + struct v4l2_async_subdev_endpoint *ase, *ase_tmp; + __v4l2_subdev_state_free(sd->active_state); sd->active_state = NULL; + + if (list_empty(&sd->async_subdev_endpoint_list)) + return; + + list_for_each_entry_safe(ase, ase_tmp, &sd->async_subdev_endpoint_list, + async_subdev_endpoint_entry) { + list_del(&ase->async_subdev_endpoint_entry); + + kfree(ase); + } } EXPORT_SYMBOL_GPL(v4l2_subdev_cleanup); @@ -2182,6 +2194,7 @@ void v4l2_subdev_init(struct v4l2_subdev *sd, const struct v4l2_subdev_ops *ops) sd->dev_priv = NULL; sd->host_priv = NULL; sd->privacy_led = NULL; + INIT_LIST_HEAD(&sd->async_subdev_endpoint_list); #if defined(CONFIG_MEDIA_CONTROLLER) sd->entity.name = sd->name; sd->entity.obj_type = MEDIA_ENTITY_TYPE_V4L2_SUBDEV; diff --git a/include/media/v4l2-async.h b/include/media/v4l2-async.h index 8670b8e448513..41a9c4bada8a7 100644 --- a/include/media/v4l2-async.h +++ b/include/media/v4l2-async.h @@ -125,6 +125,18 @@ struct v4l2_async_notifier { struct list_head notifier_entry; }; +/** + * struct v4l2_async_subdev_endpoint - Entry in sub-device's fwnode list + * + * @async_subdev_endpoint_entry: An entry in async_subdev_endpoint_list of + * &struct v4l2_subdev + * @endpoint: Endpoint fwnode agains which to match the sub-device + */ +struct v4l2_async_subdev_endpoint { + struct list_head async_subdev_endpoint_entry; + struct fwnode_handle *endpoint; +}; + /** * v4l2_async_debug_init - Initialize debugging tools. * @@ -215,6 +227,24 @@ __v4l2_async_nf_add_i2c(struct v4l2_async_notifier *notifier, ((type *)__v4l2_async_nf_add_i2c(notifier, adapter, address, \ sizeof(type))) +/** + * v4l2_async_subdev_endpoint_add - Add an endpoint fwnode to async sub-device + * matching list + * + * @sd: the sub-device + * @fwnode: the endpoint fwnode to match + * + * Add a fwnode to the async sub-device's matching list. This allows registering + * multiple async sub-devices from a single device. + * + * Note that calling v4l2_subdev_cleanup() as part of the sub-device's cleanup + * if endpoints have been added to the sub-device's fwnode matching list. + * + * Returns an error on failure, 0 on success. + */ +int v4l2_async_subdev_endpoint_add(struct v4l2_subdev *sd, + struct fwnode_handle *fwnode); + /** * v4l2_async_connection_unique - return a unique &struct v4l2_async_connection * for a sub-device diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h index a8078ae995966..a012741cc876f 100644 --- a/include/media/v4l2-subdev.h +++ b/include/media/v4l2-subdev.h @@ -1022,6 +1022,8 @@ struct v4l2_subdev_platform_data { * either dev->of_node->fwnode or dev->fwnode (whichever is non-NULL). * @async_list: Links this subdev to a global subdev_list or * @notifier->done_list list. + * @async_subdev_endpoint_list: List entry in async_subdev_endpoint_entry of + * &struct v4l2_async_subdev_endpoint. * @subdev_notifier: A sub-device notifier implicitly registered for the sub- * device using v4l2_async_register_subdev_sensor(). * @asc_list: Async connection list, of &struct @@ -1065,6 +1067,7 @@ struct v4l2_subdev { struct device *dev; struct fwnode_handle *fwnode; struct list_head async_list; + struct list_head async_subdev_endpoint_list; struct v4l2_async_notifier *subdev_notifier; struct list_head asc_list; struct v4l2_subdev_platform_data *pdata; @@ -1382,8 +1385,9 @@ int __v4l2_subdev_init_finalize(struct v4l2_subdev *sd, const char *name, * v4l2_subdev_cleanup() - Releases the resources allocated by the subdevice * @sd: The subdevice * - * This function will release the resources allocated in - * v4l2_subdev_init_finalize. + * Clean up a V4L2 async sub-device. Must be called for a sub-device as part of + * its release if resources have been associated with it using + * v4l2_async_subdev_endpoint_add() or v4l2_subdev_init_finalize(). */ void v4l2_subdev_cleanup(struct v4l2_subdev *sd);