2 * V4L2 fwnode binding parsing library
4 * The origins of the V4L2 fwnode library are in V4L2 OF library that
5 * formerly was located in v4l2-of.c.
7 * Copyright (c) 2016 Intel Corporation.
8 * Author: Sakari Ailus <sakari.ailus@linux.intel.com>
10 * Copyright (C) 2012 - 2013 Samsung Electronics Co., Ltd.
11 * Author: Sylwester Nawrocki <s.nawrocki@samsung.com>
13 * Copyright (C) 2012 Renesas Electronics Corp.
14 * Author: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of version 2 of the GNU General Public License as
18 * published by the Free Software Foundation.
20 #include <linux/acpi.h>
21 #include <linux/kernel.h>
23 #include <linux/module.h>
25 #include <linux/property.h>
26 #include <linux/slab.h>
27 #include <linux/string.h>
28 #include <linux/types.h>
30 #include <media/v4l2-async.h>
31 #include <media/v4l2-fwnode.h>
32 #include <media/v4l2-subdev.h>
34 enum v4l2_fwnode_bus_type
{
35 V4L2_FWNODE_BUS_TYPE_GUESS
= 0,
36 V4L2_FWNODE_BUS_TYPE_CSI2_CPHY
,
37 V4L2_FWNODE_BUS_TYPE_CSI1
,
38 V4L2_FWNODE_BUS_TYPE_CCP2
,
39 NR_OF_V4L2_FWNODE_BUS_TYPE
,
42 static int v4l2_fwnode_endpoint_parse_csi2_bus(struct fwnode_handle
*fwnode
,
43 struct v4l2_fwnode_endpoint
*vep
)
45 struct v4l2_fwnode_bus_mipi_csi2
*bus
= &vep
->bus
.mipi_csi2
;
46 bool have_clk_lane
= false;
47 unsigned int flags
= 0, lanes_used
= 0;
52 rval
= fwnode_property_read_u32_array(fwnode
, "data-lanes", NULL
, 0);
54 u32 array
[1 + V4L2_FWNODE_CSI2_MAX_DATA_LANES
];
57 min_t(int, V4L2_FWNODE_CSI2_MAX_DATA_LANES
, rval
);
59 fwnode_property_read_u32_array(fwnode
, "data-lanes", array
,
62 for (i
= 0; i
< bus
->num_data_lanes
; i
++) {
63 if (lanes_used
& BIT(array
[i
]))
64 pr_warn("duplicated lane %u in data-lanes\n",
66 lanes_used
|= BIT(array
[i
]);
68 bus
->data_lanes
[i
] = array
[i
];
71 rval
= fwnode_property_read_u32_array(fwnode
,
72 "lane-polarities", NULL
,
75 if (rval
!= 1 + bus
->num_data_lanes
/* clock+data */) {
76 pr_warn("invalid number of lane-polarities entries (need %u, got %u)\n",
77 1 + bus
->num_data_lanes
, rval
);
81 fwnode_property_read_u32_array(fwnode
,
82 "lane-polarities", array
,
83 1 + bus
->num_data_lanes
);
85 for (i
= 0; i
< 1 + bus
->num_data_lanes
; i
++)
86 bus
->lane_polarities
[i
] = array
[i
];
91 if (!fwnode_property_read_u32(fwnode
, "clock-lanes", &v
)) {
92 if (lanes_used
& BIT(v
))
93 pr_warn("duplicated lane %u in clock-lanes\n", v
);
100 if (fwnode_property_present(fwnode
, "clock-noncontinuous"))
101 flags
|= V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK
;
102 else if (have_clk_lane
|| bus
->num_data_lanes
> 0)
103 flags
|= V4L2_MBUS_CSI2_CONTINUOUS_CLOCK
;
106 vep
->bus_type
= V4L2_MBUS_CSI2
;
111 static void v4l2_fwnode_endpoint_parse_parallel_bus(
112 struct fwnode_handle
*fwnode
, struct v4l2_fwnode_endpoint
*vep
)
114 struct v4l2_fwnode_bus_parallel
*bus
= &vep
->bus
.parallel
;
115 unsigned int flags
= 0;
118 if (!fwnode_property_read_u32(fwnode
, "hsync-active", &v
))
119 flags
|= v
? V4L2_MBUS_HSYNC_ACTIVE_HIGH
:
120 V4L2_MBUS_HSYNC_ACTIVE_LOW
;
122 if (!fwnode_property_read_u32(fwnode
, "vsync-active", &v
))
123 flags
|= v
? V4L2_MBUS_VSYNC_ACTIVE_HIGH
:
124 V4L2_MBUS_VSYNC_ACTIVE_LOW
;
126 if (!fwnode_property_read_u32(fwnode
, "field-even-active", &v
))
127 flags
|= v
? V4L2_MBUS_FIELD_EVEN_HIGH
:
128 V4L2_MBUS_FIELD_EVEN_LOW
;
130 vep
->bus_type
= V4L2_MBUS_PARALLEL
;
132 vep
->bus_type
= V4L2_MBUS_BT656
;
134 if (!fwnode_property_read_u32(fwnode
, "pclk-sample", &v
))
135 flags
|= v
? V4L2_MBUS_PCLK_SAMPLE_RISING
:
136 V4L2_MBUS_PCLK_SAMPLE_FALLING
;
138 if (!fwnode_property_read_u32(fwnode
, "data-active", &v
))
139 flags
|= v
? V4L2_MBUS_DATA_ACTIVE_HIGH
:
140 V4L2_MBUS_DATA_ACTIVE_LOW
;
142 if (fwnode_property_present(fwnode
, "slave-mode"))
143 flags
|= V4L2_MBUS_SLAVE
;
145 flags
|= V4L2_MBUS_MASTER
;
147 if (!fwnode_property_read_u32(fwnode
, "bus-width", &v
))
150 if (!fwnode_property_read_u32(fwnode
, "data-shift", &v
))
153 if (!fwnode_property_read_u32(fwnode
, "sync-on-green-active", &v
))
154 flags
|= v
? V4L2_MBUS_VIDEO_SOG_ACTIVE_HIGH
:
155 V4L2_MBUS_VIDEO_SOG_ACTIVE_LOW
;
157 if (!fwnode_property_read_u32(fwnode
, "data-enable-active", &v
))
158 flags
|= v
? V4L2_MBUS_DATA_ENABLE_HIGH
:
159 V4L2_MBUS_DATA_ENABLE_LOW
;
166 v4l2_fwnode_endpoint_parse_csi1_bus(struct fwnode_handle
*fwnode
,
167 struct v4l2_fwnode_endpoint
*vep
,
170 struct v4l2_fwnode_bus_mipi_csi1
*bus
= &vep
->bus
.mipi_csi1
;
173 if (!fwnode_property_read_u32(fwnode
, "clock-inv", &v
))
176 if (!fwnode_property_read_u32(fwnode
, "strobe", &v
))
179 if (!fwnode_property_read_u32(fwnode
, "data-lanes", &v
))
182 if (!fwnode_property_read_u32(fwnode
, "clock-lanes", &v
))
185 if (bus_type
== V4L2_FWNODE_BUS_TYPE_CCP2
)
186 vep
->bus_type
= V4L2_MBUS_CCP2
;
188 vep
->bus_type
= V4L2_MBUS_CSI1
;
191 int v4l2_fwnode_endpoint_parse(struct fwnode_handle
*fwnode
,
192 struct v4l2_fwnode_endpoint
*vep
)
197 fwnode_graph_parse_endpoint(fwnode
, &vep
->base
);
199 /* Zero fields from bus_type to until the end */
200 memset(&vep
->bus_type
, 0, sizeof(*vep
) -
201 offsetof(typeof(*vep
), bus_type
));
203 fwnode_property_read_u32(fwnode
, "bus-type", &bus_type
);
206 case V4L2_FWNODE_BUS_TYPE_GUESS
:
207 rval
= v4l2_fwnode_endpoint_parse_csi2_bus(fwnode
, vep
);
211 * Parse the parallel video bus properties only if none
212 * of the MIPI CSI-2 specific properties were found.
214 if (vep
->bus
.mipi_csi2
.flags
== 0)
215 v4l2_fwnode_endpoint_parse_parallel_bus(fwnode
, vep
);
218 case V4L2_FWNODE_BUS_TYPE_CCP2
:
219 case V4L2_FWNODE_BUS_TYPE_CSI1
:
220 v4l2_fwnode_endpoint_parse_csi1_bus(fwnode
, vep
, bus_type
);
224 pr_warn("unsupported bus type %u\n", bus_type
);
228 EXPORT_SYMBOL_GPL(v4l2_fwnode_endpoint_parse
);
230 void v4l2_fwnode_endpoint_free(struct v4l2_fwnode_endpoint
*vep
)
232 if (IS_ERR_OR_NULL(vep
))
235 kfree(vep
->link_frequencies
);
238 EXPORT_SYMBOL_GPL(v4l2_fwnode_endpoint_free
);
240 struct v4l2_fwnode_endpoint
*v4l2_fwnode_endpoint_alloc_parse(
241 struct fwnode_handle
*fwnode
)
243 struct v4l2_fwnode_endpoint
*vep
;
246 vep
= kzalloc(sizeof(*vep
), GFP_KERNEL
);
248 return ERR_PTR(-ENOMEM
);
250 rval
= v4l2_fwnode_endpoint_parse(fwnode
, vep
);
254 rval
= fwnode_property_read_u64_array(fwnode
, "link-frequencies",
257 vep
->link_frequencies
=
258 kmalloc_array(rval
, sizeof(*vep
->link_frequencies
),
260 if (!vep
->link_frequencies
) {
265 vep
->nr_of_link_frequencies
= rval
;
267 rval
= fwnode_property_read_u64_array(
268 fwnode
, "link-frequencies", vep
->link_frequencies
,
269 vep
->nr_of_link_frequencies
);
277 v4l2_fwnode_endpoint_free(vep
);
278 return ERR_PTR(rval
);
280 EXPORT_SYMBOL_GPL(v4l2_fwnode_endpoint_alloc_parse
);
282 int v4l2_fwnode_parse_link(struct fwnode_handle
*__fwnode
,
283 struct v4l2_fwnode_link
*link
)
285 const char *port_prop
= is_of_node(__fwnode
) ? "reg" : "port";
286 struct fwnode_handle
*fwnode
;
288 memset(link
, 0, sizeof(*link
));
290 fwnode
= fwnode_get_parent(__fwnode
);
291 fwnode_property_read_u32(fwnode
, port_prop
, &link
->local_port
);
292 fwnode
= fwnode_get_next_parent(fwnode
);
293 if (is_of_node(fwnode
) &&
294 of_node_cmp(to_of_node(fwnode
)->name
, "ports") == 0)
295 fwnode
= fwnode_get_next_parent(fwnode
);
296 link
->local_node
= fwnode
;
298 fwnode
= fwnode_graph_get_remote_endpoint(__fwnode
);
300 fwnode_handle_put(fwnode
);
304 fwnode
= fwnode_get_parent(fwnode
);
305 fwnode_property_read_u32(fwnode
, port_prop
, &link
->remote_port
);
306 fwnode
= fwnode_get_next_parent(fwnode
);
307 if (is_of_node(fwnode
) &&
308 of_node_cmp(to_of_node(fwnode
)->name
, "ports") == 0)
309 fwnode
= fwnode_get_next_parent(fwnode
);
310 link
->remote_node
= fwnode
;
314 EXPORT_SYMBOL_GPL(v4l2_fwnode_parse_link
);
316 void v4l2_fwnode_put_link(struct v4l2_fwnode_link
*link
)
318 fwnode_handle_put(link
->local_node
);
319 fwnode_handle_put(link
->remote_node
);
321 EXPORT_SYMBOL_GPL(v4l2_fwnode_put_link
);
323 static int v4l2_async_notifier_realloc(struct v4l2_async_notifier
*notifier
,
324 unsigned int max_subdevs
)
326 struct v4l2_async_subdev
**subdevs
;
328 if (max_subdevs
<= notifier
->max_subdevs
)
331 subdevs
= kvmalloc_array(
332 max_subdevs
, sizeof(*notifier
->subdevs
),
333 GFP_KERNEL
| __GFP_ZERO
);
337 if (notifier
->subdevs
) {
338 memcpy(subdevs
, notifier
->subdevs
,
339 sizeof(*subdevs
) * notifier
->num_subdevs
);
341 kvfree(notifier
->subdevs
);
344 notifier
->subdevs
= subdevs
;
345 notifier
->max_subdevs
= max_subdevs
;
350 static int v4l2_async_notifier_fwnode_parse_endpoint(
351 struct device
*dev
, struct v4l2_async_notifier
*notifier
,
352 struct fwnode_handle
*endpoint
, unsigned int asd_struct_size
,
353 int (*parse_endpoint
)(struct device
*dev
,
354 struct v4l2_fwnode_endpoint
*vep
,
355 struct v4l2_async_subdev
*asd
))
357 struct v4l2_async_subdev
*asd
;
358 struct v4l2_fwnode_endpoint
*vep
;
361 asd
= kzalloc(asd_struct_size
, GFP_KERNEL
);
365 asd
->match_type
= V4L2_ASYNC_MATCH_FWNODE
;
367 fwnode_graph_get_remote_port_parent(endpoint
);
368 if (!asd
->match
.fwnode
) {
369 dev_warn(dev
, "bad remote port parent\n");
374 vep
= v4l2_fwnode_endpoint_alloc_parse(endpoint
);
377 dev_warn(dev
, "unable to parse V4L2 fwnode endpoint (%d)\n",
382 ret
= parse_endpoint
? parse_endpoint(dev
, vep
, asd
) : 0;
383 if (ret
== -ENOTCONN
)
384 dev_dbg(dev
, "ignoring port@%u/endpoint@%u\n", vep
->base
.port
,
388 "driver could not parse port@%u/endpoint@%u (%d)\n",
389 vep
->base
.port
, vep
->base
.id
, ret
);
390 v4l2_fwnode_endpoint_free(vep
);
394 notifier
->subdevs
[notifier
->num_subdevs
] = asd
;
395 notifier
->num_subdevs
++;
400 fwnode_handle_put(asd
->match
.fwnode
);
403 return ret
== -ENOTCONN
? 0 : ret
;
406 static int __v4l2_async_notifier_parse_fwnode_endpoints(
407 struct device
*dev
, struct v4l2_async_notifier
*notifier
,
408 size_t asd_struct_size
, unsigned int port
, bool has_port
,
409 int (*parse_endpoint
)(struct device
*dev
,
410 struct v4l2_fwnode_endpoint
*vep
,
411 struct v4l2_async_subdev
*asd
))
413 struct fwnode_handle
*fwnode
;
414 unsigned int max_subdevs
= notifier
->max_subdevs
;
417 if (WARN_ON(asd_struct_size
< sizeof(struct v4l2_async_subdev
)))
420 for (fwnode
= NULL
; (fwnode
= fwnode_graph_get_next_endpoint(
421 dev_fwnode(dev
), fwnode
)); ) {
422 struct fwnode_handle
*dev_fwnode
;
425 dev_fwnode
= fwnode_graph_get_port_parent(fwnode
);
426 is_available
= fwnode_device_is_available(dev_fwnode
);
427 fwnode_handle_put(dev_fwnode
);
432 struct fwnode_endpoint ep
;
434 ret
= fwnode_graph_parse_endpoint(fwnode
, &ep
);
436 fwnode_handle_put(fwnode
);
446 /* No subdevs to add? Return here. */
447 if (max_subdevs
== notifier
->max_subdevs
)
450 ret
= v4l2_async_notifier_realloc(notifier
, max_subdevs
);
454 for (fwnode
= NULL
; (fwnode
= fwnode_graph_get_next_endpoint(
455 dev_fwnode(dev
), fwnode
)); ) {
456 struct fwnode_handle
*dev_fwnode
;
459 dev_fwnode
= fwnode_graph_get_port_parent(fwnode
);
460 is_available
= fwnode_device_is_available(dev_fwnode
);
461 fwnode_handle_put(dev_fwnode
);
466 struct fwnode_endpoint ep
;
468 ret
= fwnode_graph_parse_endpoint(fwnode
, &ep
);
476 if (WARN_ON(notifier
->num_subdevs
>= notifier
->max_subdevs
)) {
481 ret
= v4l2_async_notifier_fwnode_parse_endpoint(
482 dev
, notifier
, fwnode
, asd_struct_size
, parse_endpoint
);
487 fwnode_handle_put(fwnode
);
492 int v4l2_async_notifier_parse_fwnode_endpoints(
493 struct device
*dev
, struct v4l2_async_notifier
*notifier
,
494 size_t asd_struct_size
,
495 int (*parse_endpoint
)(struct device
*dev
,
496 struct v4l2_fwnode_endpoint
*vep
,
497 struct v4l2_async_subdev
*asd
))
499 return __v4l2_async_notifier_parse_fwnode_endpoints(
500 dev
, notifier
, asd_struct_size
, 0, false, parse_endpoint
);
502 EXPORT_SYMBOL_GPL(v4l2_async_notifier_parse_fwnode_endpoints
);
504 int v4l2_async_notifier_parse_fwnode_endpoints_by_port(
505 struct device
*dev
, struct v4l2_async_notifier
*notifier
,
506 size_t asd_struct_size
, unsigned int port
,
507 int (*parse_endpoint
)(struct device
*dev
,
508 struct v4l2_fwnode_endpoint
*vep
,
509 struct v4l2_async_subdev
*asd
))
511 return __v4l2_async_notifier_parse_fwnode_endpoints(
512 dev
, notifier
, asd_struct_size
, port
, true, parse_endpoint
);
514 EXPORT_SYMBOL_GPL(v4l2_async_notifier_parse_fwnode_endpoints_by_port
);
517 * v4l2_fwnode_reference_parse - parse references for async sub-devices
518 * @dev: the device node the properties of which are parsed for references
519 * @notifier: the async notifier where the async subdevs will be added
520 * @prop: the name of the property
522 * Return: 0 on success
523 * -ENOENT if no entries were found
524 * -ENOMEM if memory allocation failed
525 * -EINVAL if property parsing failed
527 static int v4l2_fwnode_reference_parse(
528 struct device
*dev
, struct v4l2_async_notifier
*notifier
,
531 struct fwnode_reference_args args
;
536 !(ret
= fwnode_property_get_reference_args(
537 dev_fwnode(dev
), prop
, NULL
, 0, index
, &args
));
539 fwnode_handle_put(args
.fwnode
);
545 * Note that right now both -ENODATA and -ENOENT may signal
546 * out-of-bounds access. Return the error in cases other than that.
548 if (ret
!= -ENOENT
&& ret
!= -ENODATA
)
551 ret
= v4l2_async_notifier_realloc(notifier
,
552 notifier
->num_subdevs
+ index
);
556 for (index
= 0; !fwnode_property_get_reference_args(
557 dev_fwnode(dev
), prop
, NULL
, 0, index
, &args
);
559 struct v4l2_async_subdev
*asd
;
561 if (WARN_ON(notifier
->num_subdevs
>= notifier
->max_subdevs
)) {
566 asd
= kzalloc(sizeof(*asd
), GFP_KERNEL
);
572 notifier
->subdevs
[notifier
->num_subdevs
] = asd
;
573 asd
->match
.fwnode
= args
.fwnode
;
574 asd
->match_type
= V4L2_ASYNC_MATCH_FWNODE
;
575 notifier
->num_subdevs
++;
581 fwnode_handle_put(args
.fwnode
);
586 * v4l2_fwnode_reference_get_int_prop - parse a reference with integer
588 * @fwnode: fwnode to read @prop from
589 * @notifier: notifier for @dev
590 * @prop: the name of the property
591 * @index: the index of the reference to get
592 * @props: the array of integer property names
593 * @nprops: the number of integer property names in @nprops
595 * First find an fwnode referred to by the reference at @index in @prop.
597 * Then under that fwnode, @nprops times, for each property in @props,
598 * iteratively follow child nodes starting from fwnode such that they have the
599 * property in @props array at the index of the child node distance from the
600 * root node and the value of that property matching with the integer argument
601 * of the reference, at the same index.
603 * The child fwnode reched at the end of the iteration is then returned to the
606 * The core reason for this is that you cannot refer to just any node in ACPI.
607 * So to refer to an endpoint (easy in DT) you need to refer to a device, then
608 * provide a list of (property name, property value) tuples where each tuple
609 * uniquely identifies a child node. The first tuple identifies a child directly
610 * underneath the device fwnode, the next tuple identifies a child node
611 * underneath the fwnode identified by the previous tuple, etc. until you
612 * reached the fwnode you need.
614 * An example with a graph, as defined in Documentation/acpi/dsd/graph.txt:
616 * Scope (\_SB.PCI0.I2C2)
620 * Name (_DSD, Package () {
621 * ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
625 * Package () { "nokia,smia" }
628 * ToUUID("dbb8e3e6-5886-4ba6-8795-1319f52a966b"),
630 * Package () { "port0", "PRT0" },
633 * Name (PRT0, Package() {
634 * ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
636 * Package () { "port", 0 },
638 * ToUUID("dbb8e3e6-5886-4ba6-8795-1319f52a966b"),
640 * Package () { "endpoint0", "EP00" },
643 * Name (EP00, Package() {
644 * ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
646 * Package () { "endpoint", 0 },
650 * \_SB.PCI0.ISP, 4, 0
662 * Name (_DSD, Package () {
663 * ToUUID("dbb8e3e6-5886-4ba6-8795-1319f52a966b"),
665 * Package () { "port4", "PRT4" },
669 * Name (PRT4, Package() {
670 * ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
672 * Package () { "port", 4 },
674 * ToUUID("dbb8e3e6-5886-4ba6-8795-1319f52a966b"),
676 * Package () { "endpoint0", "EP40" },
680 * Name (EP40, Package() {
681 * ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
683 * Package () { "endpoint", 0 },
687 * \_SB.PCI0.I2C2.CAM0,
696 * From the EP40 node under ISP device, you could parse the graph remote
697 * endpoint using v4l2_fwnode_reference_get_int_prop with these arguments:
699 * @fwnode: fwnode referring to EP40 under ISP.
700 * @prop: "remote-endpoint"
702 * @props: "port", "endpoint"
705 * And you'd get back fwnode referring to EP00 under CAM0.
707 * The same works the other way around: if you use EP00 under CAM0 as the
708 * fwnode, you'll get fwnode referring to EP40 under ISP.
710 * The same example in DT syntax would look like this:
713 * compatible = "nokia,smia";
719 * remote-endpoint = <&isp 4 0>;
730 * remote-endpoint = <&cam 0 0>;
736 * Return: 0 on success
737 * -ENOENT if no entries (or the property itself) were found
738 * -EINVAL if property parsing otherwise failed
739 * -ENOMEM if memory allocation failed
741 static struct fwnode_handle
*v4l2_fwnode_reference_get_int_prop(
742 struct fwnode_handle
*fwnode
, const char *prop
, unsigned int index
,
743 const char * const *props
, unsigned int nprops
)
745 struct fwnode_reference_args fwnode_args
;
746 u64
*args
= fwnode_args
.args
;
747 struct fwnode_handle
*child
;
751 * Obtain remote fwnode as well as the integer arguments.
753 * Note that right now both -ENODATA and -ENOENT may signal
754 * out-of-bounds access. Return -ENOENT in that case.
756 ret
= fwnode_property_get_reference_args(fwnode
, prop
, NULL
, nprops
,
757 index
, &fwnode_args
);
759 return ERR_PTR(ret
== -ENODATA
? -ENOENT
: ret
);
762 * Find a node in the tree under the referred fwnode corresponding to
763 * the integer arguments.
765 fwnode
= fwnode_args
.fwnode
;
769 /* Loop over all child nodes under fwnode. */
770 fwnode_for_each_child_node(fwnode
, child
) {
771 if (fwnode_property_read_u32(child
, *props
, &val
))
774 /* Found property, see if its value matches. */
779 fwnode_handle_put(fwnode
);
781 /* No property found; return an error here. */
783 fwnode
= ERR_PTR(-ENOENT
);
796 * v4l2_fwnode_reference_parse_int_props - parse references for async
798 * @dev: struct device pointer
799 * @notifier: notifier for @dev
800 * @prop: the name of the property
801 * @props: the array of integer property names
802 * @nprops: the number of integer properties
804 * Use v4l2_fwnode_reference_get_int_prop to find fwnodes through reference in
805 * property @prop with integer arguments with child nodes matching in properties
806 * @props. Then, set up V4L2 async sub-devices for those fwnodes in the notifier
809 * While it is technically possible to use this function on DT, it is only
810 * meaningful on ACPI. On Device tree you can refer to any node in the tree but
811 * on ACPI the references are limited to devices.
813 * Return: 0 on success
814 * -ENOENT if no entries (or the property itself) were found
815 * -EINVAL if property parsing otherwisefailed
816 * -ENOMEM if memory allocation failed
818 static int v4l2_fwnode_reference_parse_int_props(
819 struct device
*dev
, struct v4l2_async_notifier
*notifier
,
820 const char *prop
, const char * const *props
, unsigned int nprops
)
822 struct fwnode_handle
*fwnode
;
828 fwnode
= v4l2_fwnode_reference_get_int_prop(dev_fwnode(dev
),
831 if (IS_ERR(fwnode
)) {
833 * Note that right now both -ENODATA and -ENOENT may
834 * signal out-of-bounds access. Return the error in
835 * cases other than that.
837 if (PTR_ERR(fwnode
) != -ENOENT
&&
838 PTR_ERR(fwnode
) != -ENODATA
)
839 return PTR_ERR(fwnode
);
842 fwnode_handle_put(fwnode
);
846 ret
= v4l2_async_notifier_realloc(notifier
,
847 notifier
->num_subdevs
+ index
);
851 for (index
= 0; !IS_ERR((fwnode
= v4l2_fwnode_reference_get_int_prop(
852 dev_fwnode(dev
), prop
, index
, props
,
853 nprops
))); index
++) {
854 struct v4l2_async_subdev
*asd
;
856 if (WARN_ON(notifier
->num_subdevs
>= notifier
->max_subdevs
)) {
861 asd
= kzalloc(sizeof(struct v4l2_async_subdev
), GFP_KERNEL
);
867 notifier
->subdevs
[notifier
->num_subdevs
] = asd
;
868 asd
->match
.fwnode
= fwnode
;
869 asd
->match_type
= V4L2_ASYNC_MATCH_FWNODE
;
870 notifier
->num_subdevs
++;
873 return PTR_ERR(fwnode
) == -ENOENT
? 0 : PTR_ERR(fwnode
);
876 fwnode_handle_put(fwnode
);
880 int v4l2_async_notifier_parse_fwnode_sensor_common(
881 struct device
*dev
, struct v4l2_async_notifier
*notifier
)
883 static const char * const led_props
[] = { "led" };
884 static const struct {
886 const char * const *props
;
889 { "flash-leds", led_props
, ARRAY_SIZE(led_props
) },
890 { "lens-focus", NULL
, 0 },
894 for (i
= 0; i
< ARRAY_SIZE(props
); i
++) {
897 if (props
[i
].props
&& is_acpi_node(dev_fwnode(dev
)))
898 ret
= v4l2_fwnode_reference_parse_int_props(
899 dev
, notifier
, props
[i
].name
,
900 props
[i
].props
, props
[i
].nprops
);
902 ret
= v4l2_fwnode_reference_parse(
903 dev
, notifier
, props
[i
].name
);
904 if (ret
&& ret
!= -ENOENT
) {
905 dev_warn(dev
, "parsing property \"%s\" failed (%d)\n",
913 EXPORT_SYMBOL_GPL(v4l2_async_notifier_parse_fwnode_sensor_common
);
915 int v4l2_async_register_subdev_sensor_common(struct v4l2_subdev
*sd
)
917 struct v4l2_async_notifier
*notifier
;
920 if (WARN_ON(!sd
->dev
))
923 notifier
= kzalloc(sizeof(*notifier
), GFP_KERNEL
);
927 ret
= v4l2_async_notifier_parse_fwnode_sensor_common(sd
->dev
,
932 ret
= v4l2_async_subdev_notifier_register(sd
, notifier
);
936 ret
= v4l2_async_register_subdev(sd
);
940 sd
->subdev_notifier
= notifier
;
945 v4l2_async_notifier_unregister(notifier
);
948 v4l2_async_notifier_cleanup(notifier
);
953 EXPORT_SYMBOL_GPL(v4l2_async_register_subdev_sensor_common
);
955 MODULE_LICENSE("GPL");
956 MODULE_AUTHOR("Sakari Ailus <sakari.ailus@linux.intel.com>");
957 MODULE_AUTHOR("Sylwester Nawrocki <s.nawrocki@samsung.com>");
958 MODULE_AUTHOR("Guennadi Liakhovetski <g.liakhovetski@gmx.de>");