From: Sakari Ailus <sakari.ailus@linux.intel.com>
To: linux-media@vger.kernel.org
Cc: laurent.pinchart@ideasonboard.com,
Philipp Zabel <p.zabel@pengutronix.de>,
hverkuil@xs4all.nl, Francesco Dolcini <francesco@dolcini.it>,
aishwarya.kothari@toradex.com, Robert Foss <rfoss@kernel.org>,
Todor Tomov <todor.too@gmail.com>,
Hyun Kwon <hyun.kwon@xilinx.com>,
bingbu.cao@intel.com
Subject: [PATCH v2 20/31] media: v4l: async: Support fwnode endpoint list matching for subdevs
Date: Tue, 16 May 2023 12:55:06 +0300 [thread overview]
Message-ID: <20230516095517.611711-21-sakari.ailus@linux.intel.com> (raw)
In-Reply-To: <20230516095517.611711-1-sakari.ailus@linux.intel.com>
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 <sakari.ailus@linux.intel.com>
---
drivers/media/v4l2-core/v4l2-async.c | 41 +++++++++++++++++++++++++++
drivers/media/v4l2-core/v4l2-subdev.c | 13 +++++++++
include/media/v4l2-async.h | 29 +++++++++++++++++++
include/media/v4l2-subdev.h | 8 ++++--
4 files changed, 89 insertions(+), 2 deletions(-)
diff --git a/drivers/media/v4l2-core/v4l2-async.c b/drivers/media/v4l2-core/v4l2-async.c
index 4916f925792b3..8da7722feabcd 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;
@@ -886,6 +910,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 af02d63fa1ab4..fa64e34c05fc9 100644
--- a/include/media/v4l2-async.h
+++ b/include/media/v4l2-async.h
@@ -142,6 +142,17 @@ struct v4l2_async_notifier {
struct list_head notifier_entry;
};
+/**
+ * struct v4l2_async_subdev_endpoint - Entry in sub-device's fwnode list
+ *
+ * @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.
*
@@ -232,6 +243,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 d2cf9bbae2fb3..27dbc2ef621ff 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_entry or @notifier->done
* list.
+ * @async_subdev_endpoint_entry: List entry in async_ep_list of
+ * &struct v4l2_async_subdev_endpoint
* @asd: Pointer to respective &struct v4l2_async_connection.
* @notifier: Pointer to the managing notifier.
* @subdev_notifier: A sub-device notifier implicitly registered for the sub-
@@ -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_subdev *asd;
struct v4l2_async_notifier *notifier;
struct v4l2_async_notifier *subdev_notifier;
@@ -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);
--
2.30.2
next prev parent reply other threads:[~2023-05-16 9:56 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-16 9:54 [PATCH v2 00/31] Separate links and async sub-devices Sakari Ailus
2023-05-16 9:54 ` [PATCH v2 01/31] media: v4l: async: Drop v4l2_async_nf_parse_fwnode_endpoints() Sakari Ailus
2023-05-16 9:54 ` [PATCH v2 02/31] media: Documentation: v4l: Document missing async subdev function Sakari Ailus
2023-05-16 9:54 ` [PATCH v2 03/31] media: xilinx-vipp: Clean up bound async notifier callback Sakari Ailus
2023-05-16 9:54 ` [PATCH v2 04/31] media: v4l: async: Add some debug prints Sakari Ailus
2023-05-16 9:54 ` [PATCH v2 05/31] media: v4l: async: Clean testing for duplicated async subdevs Sakari Ailus
2023-05-16 9:54 ` [PATCH v2 06/31] media: v4l: async: Drop unneeded list entry initialisation Sakari Ailus
2023-05-16 9:54 ` [PATCH v2 07/31] media: v4l: async: Don't check whether asd is NULL in validity check Sakari Ailus
2023-05-16 9:54 ` [PATCH v2 08/31] media: v4l: async: Make V4L2 async match information a struct Sakari Ailus
2023-05-16 9:54 ` [PATCH v2 09/31] media: v4l: async: Rename V4L2_ASYNC_MATCH_ macros, add TYPE_ Sakari Ailus
2023-05-16 9:54 ` [PATCH v2 10/31] media: v4l: async: Only pass match information for async subdev validation Sakari Ailus
2023-05-16 9:54 ` [PATCH v2 11/31] media: v4l: async: Clean up list heads and entries Sakari Ailus
2023-05-16 9:54 ` [PATCH v2 12/31] media: v4l: async: Simplify async sub-device fwnode matching Sakari Ailus
2023-05-16 9:54 ` [PATCH v2 13/31] media: v4l: async: Rename v4l2_async_subdev as v4l2_async_connection Sakari Ailus
2023-05-16 9:55 ` [PATCH v2 14/31] media: v4l: async: Clean up error handling in v4l2_async_match_notify Sakari Ailus
2023-05-16 9:55 ` [PATCH v2 15/31] media: v4l: async: Drop duplicate handling when adding connections Sakari Ailus
2023-05-16 9:55 ` [PATCH v2 16/31] media: v4l: async: Rework internal lists Sakari Ailus
2023-05-16 9:55 ` [PATCH v2 17/31] media: v4l: async: Obtain async connection based on sub-device Sakari Ailus
2023-05-16 9:55 ` [PATCH v2 18/31] media: v4l: async: Differentiate connecting and creating sub-devices Sakari Ailus
2023-05-16 9:55 ` [PATCH v2 19/31] media: v4l: async: Try more connections Sakari Ailus
2023-05-16 9:55 ` Sakari Ailus [this message]
2023-05-16 9:55 ` [PATCH v2 21/31] media: adv748x: Return to endpoint matching Sakari Ailus
2023-05-16 9:55 ` [PATCH v2 22/31] media: pxa_camera: Fix probe error handling Sakari Ailus
2023-05-16 9:55 ` [PATCH v2 23/31] media: pxa_camera: Register V4L2 device early, fix " Sakari Ailus
2023-05-16 9:55 ` [PATCH v2 24/31] media: marvell: cafe: Register V4L2 device earlier Sakari Ailus
2023-05-16 9:55 ` [PATCH v2 25/31] media: am437x-vpfe: Register V4L2 device early Sakari Ailus
2023-05-16 9:55 ` [PATCH v2 26/31] media: omap3isp: Initialise V4L2 async notifier later Sakari Ailus
2023-05-16 9:55 ` [PATCH v2 27/31] media: xilinx-vipp: Init async notifier after registering V4L2 device Sakari Ailus
2023-05-16 9:55 ` [PATCH v2 28/31] media: davinci: " Sakari Ailus
2023-05-16 9:55 ` [PATCH v2 29/31] media: qcom: Initialise V4L2 async notifier later Sakari Ailus
2023-05-16 9:55 ` [PATCH v2 30/31] media: v4l: async: Set v4l2_device in async notifier init Sakari Ailus
2023-05-16 20:46 ` kernel test robot
2023-05-16 9:55 ` [PATCH v2 31/31] media: Documentation: v4l: Document sub-device notifiers Sakari Ailus
2023-05-17 7:57 ` [PATCH v2 00/31] Separate links and async sub-devices Alexander Stein
2023-05-17 9:15 ` Sakari Ailus
2023-05-17 9:16 ` Sakari Ailus
2023-05-17 9:43 ` Philipp Zabel
2023-05-17 11:24 ` Marcel Ziswiler
2023-05-17 12:06 ` Philipp Zabel
2023-05-17 21:33 ` Sakari Ailus
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=20230516095517.611711-21-sakari.ailus@linux.intel.com \
--to=sakari.ailus@linux.intel.com \
--cc=aishwarya.kothari@toradex.com \
--cc=bingbu.cao@intel.com \
--cc=francesco@dolcini.it \
--cc=hverkuil@xs4all.nl \
--cc=hyun.kwon@xilinx.com \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-media@vger.kernel.org \
--cc=p.zabel@pengutronix.de \
--cc=rfoss@kernel.org \
--cc=todor.too@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.