1 // SPDX-License-Identifier: GPL-2.0-only
3 * V4L2 asynchronous subdevice registration API
8 #include <linux/debugfs.h>
9 #include <linux/device.h>
10 #include <linux/err.h>
11 #include <linux/i2c.h>
12 #include <linux/list.h>
14 #include <linux/module.h>
15 #include <linux/mutex.h>
17 #include <linux/platform_device.h>
18 #include <linux/seq_file.h>
19 #include <linux/slab.h>
20 #include <linux/types.h>
22 #include <media/v4l2-async.h>
23 #include <media/v4l2-device.h>
24 #include <media/v4l2-fwnode.h>
25 #include <media/v4l2-subdev.h>
27 #include "v4l2-subdev-priv.h"
29 static int v4l2_async_nf_call_bound(struct v4l2_async_notifier *n,
30 struct v4l2_subdev *subdev,
31 struct v4l2_async_connection *asc)
33 if (!n->ops || !n->ops->bound)
36 return n->ops->bound(n, subdev, asc);
39 static void v4l2_async_nf_call_unbind(struct v4l2_async_notifier *n,
40 struct v4l2_subdev *subdev,
41 struct v4l2_async_connection *asc)
43 if (!n->ops || !n->ops->unbind)
46 n->ops->unbind(n, subdev, asc);
49 static int v4l2_async_nf_call_complete(struct v4l2_async_notifier *n)
51 if (!n->ops || !n->ops->complete)
54 return n->ops->complete(n);
57 static void v4l2_async_nf_call_destroy(struct v4l2_async_notifier *n,
58 struct v4l2_async_connection *asc)
60 if (!n->ops || !n->ops->destroy)
66 static bool match_i2c(struct v4l2_async_notifier *notifier,
67 struct v4l2_subdev *sd,
68 struct v4l2_async_match_desc *match)
70 #if IS_ENABLED(CONFIG_I2C)
71 struct i2c_client *client = i2c_verify_client(sd->dev);
74 match->i2c.adapter_id == client->adapter->nr &&
75 match->i2c.address == client->addr;
81 static struct device *notifier_dev(struct v4l2_async_notifier *notifier)
84 return notifier->sd->dev;
86 if (notifier->v4l2_dev)
87 return notifier->v4l2_dev->dev;
93 match_fwnode_one(struct v4l2_async_notifier *notifier,
94 struct v4l2_subdev *sd, struct fwnode_handle *sd_fwnode,
95 struct v4l2_async_match_desc *match)
97 struct fwnode_handle *asd_dev_fwnode;
100 dev_dbg(notifier_dev(notifier),
101 "v4l2-async: fwnode match: need %pfw, trying %pfw\n",
102 sd_fwnode, match->fwnode);
104 if (sd_fwnode == match->fwnode) {
105 dev_dbg(notifier_dev(notifier),
106 "v4l2-async: direct match found\n");
110 if (!fwnode_graph_is_endpoint(match->fwnode)) {
111 dev_dbg(notifier_dev(notifier),
112 "v4l2-async: direct match not found\n");
116 asd_dev_fwnode = fwnode_graph_get_port_parent(match->fwnode);
118 ret = sd_fwnode == asd_dev_fwnode;
120 fwnode_handle_put(asd_dev_fwnode);
122 dev_dbg(notifier_dev(notifier),
123 "v4l2-async: device--endpoint match %sfound\n",
129 static bool match_fwnode(struct v4l2_async_notifier *notifier,
130 struct v4l2_subdev *sd,
131 struct v4l2_async_match_desc *match)
133 dev_dbg(notifier_dev(notifier),
134 "v4l2-async: matching for notifier %pfw, sd fwnode %pfw\n",
135 dev_fwnode(notifier_dev(notifier)), sd->fwnode);
137 if (!list_empty(&sd->async_subdev_endpoint_list)) {
138 struct v4l2_async_subdev_endpoint *ase;
141 "v4l2-async: endpoint fwnode list available, looking for %pfw\n",
144 list_for_each_entry(ase, &sd->async_subdev_endpoint_list,
145 async_subdev_endpoint_entry) {
146 bool matched = ase->endpoint == match->fwnode;
149 "v4l2-async: endpoint-endpoint match %sfound with %pfw\n",
150 matched ? "" : "not ", ase->endpoint);
156 dev_dbg(sd->dev, "async: no endpoint matched\n");
161 if (match_fwnode_one(notifier, sd, sd->fwnode, match))
164 /* Also check the secondary fwnode. */
165 if (IS_ERR_OR_NULL(sd->fwnode->secondary))
168 dev_dbg(notifier_dev(notifier),
169 "v4l2-async: trying secondary fwnode match\n");
171 return match_fwnode_one(notifier, sd, sd->fwnode->secondary, match);
174 static LIST_HEAD(subdev_list);
175 static LIST_HEAD(notifier_list);
176 static DEFINE_MUTEX(list_lock);
178 static struct v4l2_async_connection *
179 v4l2_async_find_match(struct v4l2_async_notifier *notifier,
180 struct v4l2_subdev *sd)
182 bool (*match)(struct v4l2_async_notifier *notifier,
183 struct v4l2_subdev *sd,
184 struct v4l2_async_match_desc *match);
185 struct v4l2_async_connection *asc;
187 list_for_each_entry(asc, ¬ifier->waiting_list, asc_entry) {
188 /* bus_type has been verified valid before */
189 switch (asc->match.type) {
190 case V4L2_ASYNC_MATCH_TYPE_I2C:
193 case V4L2_ASYNC_MATCH_TYPE_FWNODE:
194 match = match_fwnode;
197 /* Cannot happen, unless someone breaks us */
202 /* match cannot be NULL here */
203 if (match(notifier, sd, &asc->match))
210 /* Compare two async match descriptors for equivalence */
211 static bool v4l2_async_match_equal(struct v4l2_async_match_desc *match1,
212 struct v4l2_async_match_desc *match2)
214 if (match1->type != match2->type)
217 switch (match1->type) {
218 case V4L2_ASYNC_MATCH_TYPE_I2C:
219 return match1->i2c.adapter_id == match2->i2c.adapter_id &&
220 match1->i2c.address == match2->i2c.address;
221 case V4L2_ASYNC_MATCH_TYPE_FWNODE:
222 return match1->fwnode == match2->fwnode;
230 /* Find the sub-device notifier registered by a sub-device driver. */
231 static struct v4l2_async_notifier *
232 v4l2_async_find_subdev_notifier(struct v4l2_subdev *sd)
234 struct v4l2_async_notifier *n;
236 list_for_each_entry(n, ¬ifier_list, notifier_entry)
243 /* Get v4l2_device related to the notifier if one can be found. */
244 static struct v4l2_device *
245 v4l2_async_nf_find_v4l2_dev(struct v4l2_async_notifier *notifier)
247 while (notifier->parent)
248 notifier = notifier->parent;
250 return notifier->v4l2_dev;
254 * Return true if all child sub-device notifiers are complete, false otherwise.
257 v4l2_async_nf_can_complete(struct v4l2_async_notifier *notifier)
259 struct v4l2_async_connection *asc;
261 if (!list_empty(¬ifier->waiting_list))
264 list_for_each_entry(asc, ¬ifier->done_list, asc_entry) {
265 struct v4l2_async_notifier *subdev_notifier =
266 v4l2_async_find_subdev_notifier(asc->sd);
268 if (subdev_notifier &&
269 !v4l2_async_nf_can_complete(subdev_notifier))
277 * Complete the master notifier if possible. This is done when all async
278 * sub-devices have been bound; v4l2_device is also available then.
281 v4l2_async_nf_try_complete(struct v4l2_async_notifier *notifier)
283 struct v4l2_async_notifier *__notifier = notifier;
285 /* Quick check whether there are still more sub-devices here. */
286 if (!list_empty(¬ifier->waiting_list))
290 dev_dbg(notifier_dev(notifier),
291 "v4l2-async: trying to complete\n");
293 /* Check the entire notifier tree; find the root notifier first. */
294 while (notifier->parent)
295 notifier = notifier->parent;
297 /* This is root if it has v4l2_dev. */
298 if (!notifier->v4l2_dev) {
299 dev_dbg(notifier_dev(__notifier),
300 "v4l2-async: V4L2 device not available\n");
304 /* Is everything ready? */
305 if (!v4l2_async_nf_can_complete(notifier))
308 dev_dbg(notifier_dev(__notifier), "v4l2-async: complete\n");
310 return v4l2_async_nf_call_complete(notifier);
314 v4l2_async_nf_try_all_subdevs(struct v4l2_async_notifier *notifier);
316 static int v4l2_async_create_ancillary_links(struct v4l2_async_notifier *n,
317 struct v4l2_subdev *sd)
319 #if IS_ENABLED(CONFIG_MEDIA_CONTROLLER)
320 struct media_link *link;
322 if (sd->entity.function != MEDIA_ENT_F_LENS &&
323 sd->entity.function != MEDIA_ENT_F_FLASH)
327 dev_warn(notifier_dev(n),
328 "not a sub-device notifier, not creating an ancillary link for %s!\n",
333 link = media_create_ancillary_link(&n->sd->entity, &sd->entity);
335 return IS_ERR(link) ? PTR_ERR(link) : 0;
341 static int v4l2_async_match_notify(struct v4l2_async_notifier *notifier,
342 struct v4l2_device *v4l2_dev,
343 struct v4l2_subdev *sd,
344 struct v4l2_async_connection *asc)
346 struct v4l2_async_notifier *subdev_notifier;
347 bool registered = false;
350 if (list_empty(&sd->asc_list)) {
351 ret = __v4l2_device_register_subdev(v4l2_dev, sd, sd->owner);
357 ret = v4l2_async_nf_call_bound(notifier, sd, asc);
359 if (asc->match.type == V4L2_ASYNC_MATCH_TYPE_FWNODE)
360 dev_dbg(notifier_dev(notifier),
361 "failed binding %pfw (%d)\n",
362 asc->match.fwnode, ret);
363 goto err_unregister_subdev;
368 * Depending of the function of the entities involved, we may
369 * want to create links between them (for example between a
370 * sensor and its lens or between a sensor's source pad and the
371 * connected device's sink pad).
373 ret = v4l2_async_create_ancillary_links(notifier, sd);
375 if (asc->match.type == V4L2_ASYNC_MATCH_TYPE_FWNODE)
376 dev_dbg(notifier_dev(notifier),
377 "failed creating links for %pfw (%d)\n",
378 asc->match.fwnode, ret);
379 goto err_call_unbind;
383 list_add(&asc->asc_subdev_entry, &sd->asc_list);
386 /* Move from the waiting list to notifier's done */
387 list_move(&asc->asc_entry, ¬ifier->done_list);
389 dev_dbg(notifier_dev(notifier), "v4l2-async: %s bound (ret %d)\n",
390 dev_name(sd->dev), ret);
393 * See if the sub-device has a notifier. If not, return here.
395 subdev_notifier = v4l2_async_find_subdev_notifier(sd);
396 if (!subdev_notifier || subdev_notifier->parent)
400 * Proceed with checking for the sub-device notifier's async
401 * sub-devices, and return the result. The error will be handled by the
404 subdev_notifier->parent = notifier;
406 return v4l2_async_nf_try_all_subdevs(subdev_notifier);
409 v4l2_async_nf_call_unbind(notifier, sd, asc);
410 list_del(&asc->asc_subdev_entry);
412 err_unregister_subdev:
414 v4l2_device_unregister_subdev(sd);
419 /* Test all async sub-devices in a notifier for a match. */
421 v4l2_async_nf_try_all_subdevs(struct v4l2_async_notifier *notifier)
423 struct v4l2_device *v4l2_dev =
424 v4l2_async_nf_find_v4l2_dev(notifier);
425 struct v4l2_subdev *sd;
430 dev_dbg(notifier_dev(notifier), "v4l2-async: trying all sub-devices\n");
433 list_for_each_entry(sd, &subdev_list, async_list) {
434 struct v4l2_async_connection *asc;
437 asc = v4l2_async_find_match(notifier, sd);
441 dev_dbg(notifier_dev(notifier),
442 "v4l2-async: match found, subdev %s\n", sd->name);
444 ret = v4l2_async_match_notify(notifier, v4l2_dev, sd, asc);
449 * v4l2_async_match_notify() may lead to registering a
450 * new notifier and thus changing the async subdevs
451 * list. In order to proceed safely from here, restart
452 * parsing the list from the beginning.
460 static void v4l2_async_unbind_subdev_one(struct v4l2_async_notifier *notifier,
461 struct v4l2_async_connection *asc)
463 list_move_tail(&asc->asc_entry, ¬ifier->waiting_list);
464 if (list_is_singular(&asc->asc_subdev_entry)) {
465 v4l2_async_nf_call_unbind(notifier, asc->sd, asc);
466 v4l2_device_unregister_subdev(asc->sd);
469 list_del(&asc->asc_subdev_entry);
472 /* Unbind all sub-devices in the notifier tree. */
474 v4l2_async_nf_unbind_all_subdevs(struct v4l2_async_notifier *notifier)
476 struct v4l2_async_connection *asc, *asc_tmp;
478 list_for_each_entry_safe(asc, asc_tmp, ¬ifier->done_list,
480 struct v4l2_async_notifier *subdev_notifier =
481 v4l2_async_find_subdev_notifier(asc->sd);
484 v4l2_async_nf_unbind_all_subdevs(subdev_notifier);
486 v4l2_async_unbind_subdev_one(notifier, asc);
489 notifier->parent = NULL;
492 /* See if an async sub-device can be found in a notifier's lists. */
494 v4l2_async_nf_has_async_match_entry(struct v4l2_async_notifier *notifier,
495 struct v4l2_async_match_desc *match)
497 struct v4l2_async_connection *asc;
499 list_for_each_entry(asc, ¬ifier->waiting_list, asc_entry)
500 if (v4l2_async_match_equal(&asc->match, match))
503 list_for_each_entry(asc, ¬ifier->done_list, asc_entry)
504 if (v4l2_async_match_equal(&asc->match, match))
511 * Find out whether an async sub-device was set up already or whether it exists
512 * in a given notifier.
515 v4l2_async_nf_has_async_match(struct v4l2_async_notifier *notifier,
516 struct v4l2_async_match_desc *match)
518 struct list_head *heads[] = {
519 ¬ifier->waiting_list,
520 ¬ifier->done_list,
524 lockdep_assert_held(&list_lock);
526 /* Check that an asd is not being added more than once. */
527 for (i = 0; i < ARRAY_SIZE(heads); i++) {
528 struct v4l2_async_connection *asc;
530 list_for_each_entry(asc, heads[i], asc_entry) {
531 if (&asc->match == match)
533 if (v4l2_async_match_equal(&asc->match, match))
538 /* Check that an asc does not exist in other notifiers. */
539 list_for_each_entry(notifier, ¬ifier_list, notifier_entry)
540 if (v4l2_async_nf_has_async_match_entry(notifier, match))
546 static int v4l2_async_nf_match_valid(struct v4l2_async_notifier *notifier,
547 struct v4l2_async_match_desc *match)
549 struct device *dev = notifier_dev(notifier);
551 switch (match->type) {
552 case V4L2_ASYNC_MATCH_TYPE_I2C:
553 case V4L2_ASYNC_MATCH_TYPE_FWNODE:
554 if (v4l2_async_nf_has_async_match(notifier, match)) {
555 dev_dbg(dev, "v4l2-async: match descriptor already listed in a notifier\n");
560 dev_err(dev, "v4l2-async: Invalid match type %u on %p\n",
568 void v4l2_async_nf_init(struct v4l2_async_notifier *notifier,
569 struct v4l2_device *v4l2_dev)
571 INIT_LIST_HEAD(¬ifier->waiting_list);
572 INIT_LIST_HEAD(¬ifier->done_list);
573 INIT_LIST_HEAD(¬ifier->notifier_entry);
574 notifier->v4l2_dev = v4l2_dev;
576 EXPORT_SYMBOL(v4l2_async_nf_init);
578 void v4l2_async_subdev_nf_init(struct v4l2_async_notifier *notifier,
579 struct v4l2_subdev *sd)
581 INIT_LIST_HEAD(¬ifier->waiting_list);
582 INIT_LIST_HEAD(¬ifier->done_list);
583 INIT_LIST_HEAD(¬ifier->notifier_entry);
586 EXPORT_SYMBOL_GPL(v4l2_async_subdev_nf_init);
588 static int __v4l2_async_nf_register(struct v4l2_async_notifier *notifier)
590 struct v4l2_async_connection *asc;
593 mutex_lock(&list_lock);
595 list_for_each_entry(asc, ¬ifier->waiting_list, asc_entry) {
596 ret = v4l2_async_nf_match_valid(notifier, &asc->match);
601 ret = v4l2_async_nf_try_all_subdevs(notifier);
605 ret = v4l2_async_nf_try_complete(notifier);
609 /* Keep also completed notifiers on the list */
610 list_add(¬ifier->notifier_entry, ¬ifier_list);
612 mutex_unlock(&list_lock);
618 * On failure, unbind all sub-devices registered through this notifier.
620 v4l2_async_nf_unbind_all_subdevs(notifier);
623 mutex_unlock(&list_lock);
628 int v4l2_async_nf_register(struct v4l2_async_notifier *notifier)
630 if (WARN_ON(!notifier->v4l2_dev == !notifier->sd))
633 return __v4l2_async_nf_register(notifier);
635 EXPORT_SYMBOL(v4l2_async_nf_register);
638 __v4l2_async_nf_unregister(struct v4l2_async_notifier *notifier)
640 if (!notifier || (!notifier->v4l2_dev && !notifier->sd))
643 v4l2_async_nf_unbind_all_subdevs(notifier);
645 list_del_init(¬ifier->notifier_entry);
648 void v4l2_async_nf_unregister(struct v4l2_async_notifier *notifier)
650 mutex_lock(&list_lock);
652 __v4l2_async_nf_unregister(notifier);
654 mutex_unlock(&list_lock);
656 EXPORT_SYMBOL(v4l2_async_nf_unregister);
658 static void __v4l2_async_nf_cleanup(struct v4l2_async_notifier *notifier)
660 struct v4l2_async_connection *asc, *tmp;
662 if (!notifier || !notifier->waiting_list.next)
665 WARN_ON(!list_empty(¬ifier->done_list));
667 list_for_each_entry_safe(asc, tmp, ¬ifier->waiting_list, asc_entry) {
668 list_del(&asc->asc_entry);
669 v4l2_async_nf_call_destroy(notifier, asc);
671 if (asc->match.type == V4L2_ASYNC_MATCH_TYPE_FWNODE)
672 fwnode_handle_put(asc->match.fwnode);
678 notifier->v4l2_dev = NULL;
681 void v4l2_async_nf_cleanup(struct v4l2_async_notifier *notifier)
683 mutex_lock(&list_lock);
685 __v4l2_async_nf_cleanup(notifier);
687 mutex_unlock(&list_lock);
689 EXPORT_SYMBOL_GPL(v4l2_async_nf_cleanup);
691 static void __v4l2_async_nf_add_connection(struct v4l2_async_notifier *notifier,
692 struct v4l2_async_connection *asc)
694 mutex_lock(&list_lock);
696 list_add_tail(&asc->asc_entry, ¬ifier->waiting_list);
698 mutex_unlock(&list_lock);
701 struct v4l2_async_connection *
702 __v4l2_async_nf_add_fwnode(struct v4l2_async_notifier *notifier,
703 struct fwnode_handle *fwnode,
704 unsigned int asc_struct_size)
706 struct v4l2_async_connection *asc;
708 asc = kzalloc(asc_struct_size, GFP_KERNEL);
710 return ERR_PTR(-ENOMEM);
712 asc->notifier = notifier;
713 asc->match.type = V4L2_ASYNC_MATCH_TYPE_FWNODE;
714 asc->match.fwnode = fwnode_handle_get(fwnode);
716 __v4l2_async_nf_add_connection(notifier, asc);
720 EXPORT_SYMBOL_GPL(__v4l2_async_nf_add_fwnode);
722 struct v4l2_async_connection *
723 __v4l2_async_nf_add_fwnode_remote(struct v4l2_async_notifier *notif,
724 struct fwnode_handle *endpoint,
725 unsigned int asc_struct_size)
727 struct v4l2_async_connection *asc;
728 struct fwnode_handle *remote;
730 remote = fwnode_graph_get_remote_endpoint(endpoint);
732 return ERR_PTR(-ENOTCONN);
734 asc = __v4l2_async_nf_add_fwnode(notif, remote, asc_struct_size);
736 * Calling __v4l2_async_nf_add_fwnode grabs a refcount,
737 * so drop the one we got in fwnode_graph_get_remote_port_parent.
739 fwnode_handle_put(remote);
742 EXPORT_SYMBOL_GPL(__v4l2_async_nf_add_fwnode_remote);
744 struct v4l2_async_connection *
745 __v4l2_async_nf_add_i2c(struct v4l2_async_notifier *notifier, int adapter_id,
746 unsigned short address, unsigned int asc_struct_size)
748 struct v4l2_async_connection *asc;
750 asc = kzalloc(asc_struct_size, GFP_KERNEL);
752 return ERR_PTR(-ENOMEM);
754 asc->notifier = notifier;
755 asc->match.type = V4L2_ASYNC_MATCH_TYPE_I2C;
756 asc->match.i2c.adapter_id = adapter_id;
757 asc->match.i2c.address = address;
759 __v4l2_async_nf_add_connection(notifier, asc);
763 EXPORT_SYMBOL_GPL(__v4l2_async_nf_add_i2c);
765 int v4l2_async_subdev_endpoint_add(struct v4l2_subdev *sd,
766 struct fwnode_handle *fwnode)
768 struct v4l2_async_subdev_endpoint *ase;
770 ase = kmalloc(sizeof(*ase), GFP_KERNEL);
774 ase->endpoint = fwnode;
775 list_add(&ase->async_subdev_endpoint_entry,
776 &sd->async_subdev_endpoint_list);
780 EXPORT_SYMBOL_GPL(v4l2_async_subdev_endpoint_add);
782 struct v4l2_async_connection *
783 v4l2_async_connection_unique(struct v4l2_subdev *sd)
785 if (!list_is_singular(&sd->asc_list))
788 return list_first_entry(&sd->asc_list,
789 struct v4l2_async_connection, asc_subdev_entry);
791 EXPORT_SYMBOL_GPL(v4l2_async_connection_unique);
793 int __v4l2_async_register_subdev(struct v4l2_subdev *sd, struct module *module)
795 struct v4l2_async_notifier *subdev_notifier;
796 struct v4l2_async_notifier *notifier;
797 struct v4l2_async_connection *asc;
800 INIT_LIST_HEAD(&sd->asc_list);
803 * No reference taken. The reference is held by the device (struct
804 * v4l2_subdev.dev), and async sub-device does not exist independently
805 * of the device at any point of time.
807 * The async sub-device shall always be registered for its device node,
808 * not the endpoint node.
810 if (!sd->fwnode && sd->dev) {
811 sd->fwnode = dev_fwnode(sd->dev);
812 } else if (fwnode_graph_is_endpoint(sd->fwnode)) {
813 dev_warn(sd->dev, "sub-device fwnode is an endpoint!\n");
819 mutex_lock(&list_lock);
821 list_for_each_entry(notifier, ¬ifier_list, notifier_entry) {
822 struct v4l2_device *v4l2_dev =
823 v4l2_async_nf_find_v4l2_dev(notifier);
828 while ((asc = v4l2_async_find_match(notifier, sd))) {
829 ret = v4l2_async_match_notify(notifier, v4l2_dev, sd,
834 ret = v4l2_async_nf_try_complete(notifier);
840 /* None matched, wait for hot-plugging */
841 list_add(&sd->async_list, &subdev_list);
843 mutex_unlock(&list_lock);
849 * Complete failed. Unbind the sub-devices bound through registering
850 * this async sub-device.
852 subdev_notifier = v4l2_async_find_subdev_notifier(sd);
854 v4l2_async_nf_unbind_all_subdevs(subdev_notifier);
857 v4l2_async_unbind_subdev_one(notifier, asc);
859 mutex_unlock(&list_lock);
865 EXPORT_SYMBOL(__v4l2_async_register_subdev);
867 void v4l2_async_unregister_subdev(struct v4l2_subdev *sd)
869 struct v4l2_async_connection *asc, *asc_tmp;
871 if (!sd->async_list.next)
874 v4l2_subdev_put_privacy_led(sd);
876 mutex_lock(&list_lock);
878 __v4l2_async_nf_unregister(sd->subdev_notifier);
879 __v4l2_async_nf_cleanup(sd->subdev_notifier);
880 kfree(sd->subdev_notifier);
881 sd->subdev_notifier = NULL;
883 if (sd->asc_list.next) {
884 list_for_each_entry_safe(asc, asc_tmp, &sd->asc_list,
886 v4l2_async_unbind_subdev_one(asc->notifier, asc);
890 list_del(&sd->async_list);
891 sd->async_list.next = NULL;
893 mutex_unlock(&list_lock);
895 EXPORT_SYMBOL(v4l2_async_unregister_subdev);
897 static void print_waiting_match(struct seq_file *s,
898 struct v4l2_async_match_desc *match)
900 switch (match->type) {
901 case V4L2_ASYNC_MATCH_TYPE_I2C:
902 seq_printf(s, " [i2c] dev=%d-%04x\n", match->i2c.adapter_id,
905 case V4L2_ASYNC_MATCH_TYPE_FWNODE: {
906 struct fwnode_handle *devnode, *fwnode = match->fwnode;
908 devnode = fwnode_graph_is_endpoint(fwnode) ?
909 fwnode_graph_get_port_parent(fwnode) :
910 fwnode_handle_get(fwnode);
912 seq_printf(s, " [fwnode] dev=%s, node=%pfw\n",
913 devnode->dev ? dev_name(devnode->dev) : "nil",
916 fwnode_handle_put(devnode);
923 v4l2_async_nf_name(struct v4l2_async_notifier *notifier)
925 if (notifier->v4l2_dev)
926 return notifier->v4l2_dev->name;
927 else if (notifier->sd)
928 return notifier->sd->name;
933 static int pending_subdevs_show(struct seq_file *s, void *data)
935 struct v4l2_async_notifier *notif;
936 struct v4l2_async_connection *asc;
938 mutex_lock(&list_lock);
940 list_for_each_entry(notif, ¬ifier_list, notifier_entry) {
941 seq_printf(s, "%s:\n", v4l2_async_nf_name(notif));
942 list_for_each_entry(asc, ¬if->waiting_list, asc_entry)
943 print_waiting_match(s, &asc->match);
946 mutex_unlock(&list_lock);
950 DEFINE_SHOW_ATTRIBUTE(pending_subdevs);
952 static struct dentry *v4l2_async_debugfs_dir;
954 static int __init v4l2_async_init(void)
956 v4l2_async_debugfs_dir = debugfs_create_dir("v4l2-async", NULL);
957 debugfs_create_file("pending_async_subdevices", 0444,
958 v4l2_async_debugfs_dir, NULL,
959 &pending_subdevs_fops);
964 static void __exit v4l2_async_exit(void)
966 debugfs_remove_recursive(v4l2_async_debugfs_dir);
969 subsys_initcall(v4l2_async_init);
970 module_exit(v4l2_async_exit);
975 MODULE_DESCRIPTION("V4L2 asynchronous subdevice registration API");
976 MODULE_LICENSE("GPL");