bcm27xx: add support for linux v5.15
[openwrt/staging/chunkeey.git] / target / linux / bcm27xx / patches-5.15 / 950-0771-media-v4l2-async-Create-links-during-v4l2_async_matc.patch
1 From 3f32e8b803061cf04a1fe31a3070e46fd0d379e8 Mon Sep 17 00:00:00 2001
2 From: Daniel Scally <djrscally@gmail.com>
3 Date: Wed, 2 Mar 2022 22:03:04 +0000
4 Subject: [PATCH] media: v4l2-async: Create links during
5 v4l2_async_match_notify()
6
7 Upon an async fwnode match, there's some typical behaviour that the
8 notifier and matching subdev will want to do. For example, a notifier
9 representing a sensor matching to an async subdev representing its
10 VCM will want to create an ancillary link to expose that relationship
11 to userspace.
12
13 To avoid lots of code in individual drivers, try to build these links
14 within v4l2 core.
15
16 Signed-off-by: Daniel Scally <djrscally@gmail.com>
17 ---
18 drivers/media/v4l2-core/v4l2-async.c | 31 ++++++++++++++++++++++++++++
19 1 file changed, 31 insertions(+)
20
21 --- a/drivers/media/v4l2-core/v4l2-async.c
22 +++ b/drivers/media/v4l2-core/v4l2-async.c
23 @@ -275,6 +275,24 @@ v4l2_async_notifier_try_complete(struct
24 static int
25 v4l2_async_notifier_try_all_subdevs(struct v4l2_async_notifier *notifier);
26
27 +static int v4l2_async_create_ancillary_links(struct v4l2_async_notifier *n,
28 + struct v4l2_subdev *sd)
29 +{
30 + struct media_link *link = NULL;
31 +
32 +#if IS_ENABLED(CONFIG_MEDIA_CONTROLLER)
33 +
34 + if (sd->entity.function != MEDIA_ENT_F_LENS &&
35 + sd->entity.function != MEDIA_ENT_F_FLASH)
36 + return 0;
37 +
38 + link = media_create_ancillary_link(&n->sd->entity, &sd->entity);
39 +
40 +#endif
41 +
42 + return IS_ERR(link) ? PTR_ERR(link) : 0;
43 +}
44 +
45 static int v4l2_async_match_notify(struct v4l2_async_notifier *notifier,
46 struct v4l2_device *v4l2_dev,
47 struct v4l2_subdev *sd,
48 @@ -292,6 +310,19 @@ static int v4l2_async_match_notify(struc
49 v4l2_device_unregister_subdev(sd);
50 return ret;
51 }
52 +
53 + /*
54 + * Depending of the function of the entities involved, we may want to
55 + * create links between them (for example between a sensor and its lens
56 + * or between a sensor's source pad and the connected device's sink
57 + * pad).
58 + */
59 + ret = v4l2_async_create_ancillary_links(notifier, sd);
60 + if (ret) {
61 + v4l2_async_notifier_call_unbind(notifier, sd, asd);
62 + v4l2_device_unregister_subdev(sd);
63 + return ret;
64 + }
65
66 /* Remove from the waiting list */
67 list_del(&asd->list);