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
;
162 v4l2_fwnode_endpoint_parse_csi1_bus(struct fwnode_handle
*fwnode
,
163 struct v4l2_fwnode_endpoint
*vep
,
166 struct v4l2_fwnode_bus_mipi_csi1
*bus
= &vep
->bus
.mipi_csi1
;
169 if (!fwnode_property_read_u32(fwnode
, "clock-inv", &v
))
172 if (!fwnode_property_read_u32(fwnode
, "strobe", &v
))
175 if (!fwnode_property_read_u32(fwnode
, "data-lanes", &v
))
178 if (!fwnode_property_read_u32(fwnode
, "clock-lanes", &v
))
181 if (bus_type
== V4L2_FWNODE_BUS_TYPE_CCP2
)
182 vep
->bus_type
= V4L2_MBUS_CCP2
;
184 vep
->bus_type
= V4L2_MBUS_CSI1
;
187 int v4l2_fwnode_endpoint_parse(struct fwnode_handle
*fwnode
,
188 struct v4l2_fwnode_endpoint
*vep
)
193 fwnode_graph_parse_endpoint(fwnode
, &vep
->base
);
195 /* Zero fields from bus_type to until the end */
196 memset(&vep
->bus_type
, 0, sizeof(*vep
) -
197 offsetof(typeof(*vep
), bus_type
));
199 fwnode_property_read_u32(fwnode
, "bus-type", &bus_type
);
202 case V4L2_FWNODE_BUS_TYPE_GUESS
:
203 rval
= v4l2_fwnode_endpoint_parse_csi2_bus(fwnode
, vep
);
207 * Parse the parallel video bus properties only if none
208 * of the MIPI CSI-2 specific properties were found.
210 if (vep
->bus
.mipi_csi2
.flags
== 0)
211 v4l2_fwnode_endpoint_parse_parallel_bus(fwnode
, vep
);
214 case V4L2_FWNODE_BUS_TYPE_CCP2
:
215 case V4L2_FWNODE_BUS_TYPE_CSI1
:
216 v4l2_fwnode_endpoint_parse_csi1_bus(fwnode
, vep
, bus_type
);
220 pr_warn("unsupported bus type %u\n", bus_type
);
224 EXPORT_SYMBOL_GPL(v4l2_fwnode_endpoint_parse
);
226 void v4l2_fwnode_endpoint_free(struct v4l2_fwnode_endpoint
*vep
)
228 if (IS_ERR_OR_NULL(vep
))
231 kfree(vep
->link_frequencies
);
234 EXPORT_SYMBOL_GPL(v4l2_fwnode_endpoint_free
);
236 struct v4l2_fwnode_endpoint
*v4l2_fwnode_endpoint_alloc_parse(
237 struct fwnode_handle
*fwnode
)
239 struct v4l2_fwnode_endpoint
*vep
;
242 vep
= kzalloc(sizeof(*vep
), GFP_KERNEL
);
244 return ERR_PTR(-ENOMEM
);
246 rval
= v4l2_fwnode_endpoint_parse(fwnode
, vep
);
250 rval
= fwnode_property_read_u64_array(fwnode
, "link-frequencies",
253 vep
->link_frequencies
=
254 kmalloc_array(rval
, sizeof(*vep
->link_frequencies
),
256 if (!vep
->link_frequencies
) {
261 vep
->nr_of_link_frequencies
= rval
;
263 rval
= fwnode_property_read_u64_array(
264 fwnode
, "link-frequencies", vep
->link_frequencies
,
265 vep
->nr_of_link_frequencies
);
273 v4l2_fwnode_endpoint_free(vep
);
274 return ERR_PTR(rval
);
276 EXPORT_SYMBOL_GPL(v4l2_fwnode_endpoint_alloc_parse
);
278 int v4l2_fwnode_parse_link(struct fwnode_handle
*__fwnode
,
279 struct v4l2_fwnode_link
*link
)
281 const char *port_prop
= is_of_node(__fwnode
) ? "reg" : "port";
282 struct fwnode_handle
*fwnode
;
284 memset(link
, 0, sizeof(*link
));
286 fwnode
= fwnode_get_parent(__fwnode
);
287 fwnode_property_read_u32(fwnode
, port_prop
, &link
->local_port
);
288 fwnode
= fwnode_get_next_parent(fwnode
);
289 if (is_of_node(fwnode
) &&
290 of_node_cmp(to_of_node(fwnode
)->name
, "ports") == 0)
291 fwnode
= fwnode_get_next_parent(fwnode
);
292 link
->local_node
= fwnode
;
294 fwnode
= fwnode_graph_get_remote_endpoint(__fwnode
);
296 fwnode_handle_put(fwnode
);
300 fwnode
= fwnode_get_parent(fwnode
);
301 fwnode_property_read_u32(fwnode
, port_prop
, &link
->remote_port
);
302 fwnode
= fwnode_get_next_parent(fwnode
);
303 if (is_of_node(fwnode
) &&
304 of_node_cmp(to_of_node(fwnode
)->name
, "ports") == 0)
305 fwnode
= fwnode_get_next_parent(fwnode
);
306 link
->remote_node
= fwnode
;
310 EXPORT_SYMBOL_GPL(v4l2_fwnode_parse_link
);
312 void v4l2_fwnode_put_link(struct v4l2_fwnode_link
*link
)
314 fwnode_handle_put(link
->local_node
);
315 fwnode_handle_put(link
->remote_node
);
317 EXPORT_SYMBOL_GPL(v4l2_fwnode_put_link
);
319 static int v4l2_async_notifier_realloc(struct v4l2_async_notifier
*notifier
,
320 unsigned int max_subdevs
)
322 struct v4l2_async_subdev
**subdevs
;
324 if (max_subdevs
<= notifier
->max_subdevs
)
327 subdevs
= kvmalloc_array(
328 max_subdevs
, sizeof(*notifier
->subdevs
),
329 GFP_KERNEL
| __GFP_ZERO
);
333 if (notifier
->subdevs
) {
334 memcpy(subdevs
, notifier
->subdevs
,
335 sizeof(*subdevs
) * notifier
->num_subdevs
);
337 kvfree(notifier
->subdevs
);
340 notifier
->subdevs
= subdevs
;
341 notifier
->max_subdevs
= max_subdevs
;
346 static int v4l2_async_notifier_fwnode_parse_endpoint(
347 struct device
*dev
, struct v4l2_async_notifier
*notifier
,
348 struct fwnode_handle
*endpoint
, unsigned int asd_struct_size
,
349 int (*parse_endpoint
)(struct device
*dev
,
350 struct v4l2_fwnode_endpoint
*vep
,
351 struct v4l2_async_subdev
*asd
))
353 struct v4l2_async_subdev
*asd
;
354 struct v4l2_fwnode_endpoint
*vep
;
357 asd
= kzalloc(asd_struct_size
, GFP_KERNEL
);
361 asd
->match_type
= V4L2_ASYNC_MATCH_FWNODE
;
363 fwnode_graph_get_remote_port_parent(endpoint
);
364 if (!asd
->match
.fwnode
) {
365 dev_warn(dev
, "bad remote port parent\n");
370 vep
= v4l2_fwnode_endpoint_alloc_parse(endpoint
);
373 dev_warn(dev
, "unable to parse V4L2 fwnode endpoint (%d)\n",
378 ret
= parse_endpoint
? parse_endpoint(dev
, vep
, asd
) : 0;
379 if (ret
== -ENOTCONN
)
380 dev_dbg(dev
, "ignoring port@%u/endpoint@%u\n", vep
->base
.port
,
384 "driver could not parse port@%u/endpoint@%u (%d)\n",
385 vep
->base
.port
, vep
->base
.id
, ret
);
386 v4l2_fwnode_endpoint_free(vep
);
390 notifier
->subdevs
[notifier
->num_subdevs
] = asd
;
391 notifier
->num_subdevs
++;
396 fwnode_handle_put(asd
->match
.fwnode
);
399 return ret
== -ENOTCONN
? 0 : ret
;
402 static int __v4l2_async_notifier_parse_fwnode_endpoints(
403 struct device
*dev
, struct v4l2_async_notifier
*notifier
,
404 size_t asd_struct_size
, unsigned int port
, bool has_port
,
405 int (*parse_endpoint
)(struct device
*dev
,
406 struct v4l2_fwnode_endpoint
*vep
,
407 struct v4l2_async_subdev
*asd
))
409 struct fwnode_handle
*fwnode
;
410 unsigned int max_subdevs
= notifier
->max_subdevs
;
413 if (WARN_ON(asd_struct_size
< sizeof(struct v4l2_async_subdev
)))
416 for (fwnode
= NULL
; (fwnode
= fwnode_graph_get_next_endpoint(
417 dev_fwnode(dev
), fwnode
)); ) {
418 struct fwnode_handle
*dev_fwnode
;
421 dev_fwnode
= fwnode_graph_get_port_parent(fwnode
);
422 is_available
= fwnode_device_is_available(dev_fwnode
);
423 fwnode_handle_put(dev_fwnode
);
428 struct fwnode_endpoint ep
;
430 ret
= fwnode_graph_parse_endpoint(fwnode
, &ep
);
432 fwnode_handle_put(fwnode
);
442 /* No subdevs to add? Return here. */
443 if (max_subdevs
== notifier
->max_subdevs
)
446 ret
= v4l2_async_notifier_realloc(notifier
, max_subdevs
);
450 for (fwnode
= NULL
; (fwnode
= fwnode_graph_get_next_endpoint(
451 dev_fwnode(dev
), fwnode
)); ) {
452 struct fwnode_handle
*dev_fwnode
;
455 dev_fwnode
= fwnode_graph_get_port_parent(fwnode
);
456 is_available
= fwnode_device_is_available(dev_fwnode
);
457 fwnode_handle_put(dev_fwnode
);
462 struct fwnode_endpoint ep
;
464 ret
= fwnode_graph_parse_endpoint(fwnode
, &ep
);
472 if (WARN_ON(notifier
->num_subdevs
>= notifier
->max_subdevs
)) {
477 ret
= v4l2_async_notifier_fwnode_parse_endpoint(
478 dev
, notifier
, fwnode
, asd_struct_size
, parse_endpoint
);
483 fwnode_handle_put(fwnode
);
488 int v4l2_async_notifier_parse_fwnode_endpoints(
489 struct device
*dev
, struct v4l2_async_notifier
*notifier
,
490 size_t asd_struct_size
,
491 int (*parse_endpoint
)(struct device
*dev
,
492 struct v4l2_fwnode_endpoint
*vep
,
493 struct v4l2_async_subdev
*asd
))
495 return __v4l2_async_notifier_parse_fwnode_endpoints(
496 dev
, notifier
, asd_struct_size
, 0, false, parse_endpoint
);
498 EXPORT_SYMBOL_GPL(v4l2_async_notifier_parse_fwnode_endpoints
);
500 int v4l2_async_notifier_parse_fwnode_endpoints_by_port(
501 struct device
*dev
, struct v4l2_async_notifier
*notifier
,
502 size_t asd_struct_size
, unsigned int port
,
503 int (*parse_endpoint
)(struct device
*dev
,
504 struct v4l2_fwnode_endpoint
*vep
,
505 struct v4l2_async_subdev
*asd
))
507 return __v4l2_async_notifier_parse_fwnode_endpoints(
508 dev
, notifier
, asd_struct_size
, port
, true, parse_endpoint
);
510 EXPORT_SYMBOL_GPL(v4l2_async_notifier_parse_fwnode_endpoints_by_port
);
513 * v4l2_fwnode_reference_parse - parse references for async sub-devices
514 * @dev: the device node the properties of which are parsed for references
515 * @notifier: the async notifier where the async subdevs will be added
516 * @prop: the name of the property
518 * Return: 0 on success
519 * -ENOENT if no entries were found
520 * -ENOMEM if memory allocation failed
521 * -EINVAL if property parsing failed
523 static int v4l2_fwnode_reference_parse(
524 struct device
*dev
, struct v4l2_async_notifier
*notifier
,
527 struct fwnode_reference_args args
;
532 !(ret
= fwnode_property_get_reference_args(
533 dev_fwnode(dev
), prop
, NULL
, 0, index
, &args
));
535 fwnode_handle_put(args
.fwnode
);
541 * Note that right now both -ENODATA and -ENOENT may signal
542 * out-of-bounds access. Return the error in cases other than that.
544 if (ret
!= -ENOENT
&& ret
!= -ENODATA
)
547 ret
= v4l2_async_notifier_realloc(notifier
,
548 notifier
->num_subdevs
+ index
);
552 for (index
= 0; !fwnode_property_get_reference_args(
553 dev_fwnode(dev
), prop
, NULL
, 0, index
, &args
);
555 struct v4l2_async_subdev
*asd
;
557 if (WARN_ON(notifier
->num_subdevs
>= notifier
->max_subdevs
)) {
562 asd
= kzalloc(sizeof(*asd
), GFP_KERNEL
);
568 notifier
->subdevs
[notifier
->num_subdevs
] = asd
;
569 asd
->match
.fwnode
= args
.fwnode
;
570 asd
->match_type
= V4L2_ASYNC_MATCH_FWNODE
;
571 notifier
->num_subdevs
++;
577 fwnode_handle_put(args
.fwnode
);
582 * v4l2_fwnode_reference_get_int_prop - parse a reference with integer
584 * @fwnode: fwnode to read @prop from
585 * @notifier: notifier for @dev
586 * @prop: the name of the property
587 * @index: the index of the reference to get
588 * @props: the array of integer property names
589 * @nprops: the number of integer property names in @nprops
591 * First find an fwnode referred to by the reference at @index in @prop.
593 * Then under that fwnode, @nprops times, for each property in @props,
594 * iteratively follow child nodes starting from fwnode such that they have the
595 * property in @props array at the index of the child node distance from the
596 * root node and the value of that property matching with the integer argument
597 * of the reference, at the same index.
599 * The child fwnode reched at the end of the iteration is then returned to the
602 * The core reason for this is that you cannot refer to just any node in ACPI.
603 * So to refer to an endpoint (easy in DT) you need to refer to a device, then
604 * provide a list of (property name, property value) tuples where each tuple
605 * uniquely identifies a child node. The first tuple identifies a child directly
606 * underneath the device fwnode, the next tuple identifies a child node
607 * underneath the fwnode identified by the previous tuple, etc. until you
608 * reached the fwnode you need.
610 * An example with a graph, as defined in Documentation/acpi/dsd/graph.txt:
612 * Scope (\_SB.PCI0.I2C2)
616 * Name (_DSD, Package () {
617 * ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
621 * Package () { "nokia,smia" }
624 * ToUUID("dbb8e3e6-5886-4ba6-8795-1319f52a966b"),
626 * Package () { "port0", "PRT0" },
629 * Name (PRT0, Package() {
630 * ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
632 * Package () { "port", 0 },
634 * ToUUID("dbb8e3e6-5886-4ba6-8795-1319f52a966b"),
636 * Package () { "endpoint0", "EP00" },
639 * Name (EP00, Package() {
640 * ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
642 * Package () { "endpoint", 0 },
646 * \_SB.PCI0.ISP, 4, 0
658 * Name (_DSD, Package () {
659 * ToUUID("dbb8e3e6-5886-4ba6-8795-1319f52a966b"),
661 * Package () { "port4", "PRT4" },
665 * Name (PRT4, Package() {
666 * ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
668 * Package () { "port", 4 },
670 * ToUUID("dbb8e3e6-5886-4ba6-8795-1319f52a966b"),
672 * Package () { "endpoint0", "EP40" },
676 * Name (EP40, Package() {
677 * ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
679 * Package () { "endpoint", 0 },
683 * \_SB.PCI0.I2C2.CAM0,
692 * From the EP40 node under ISP device, you could parse the graph remote
693 * endpoint using v4l2_fwnode_reference_get_int_prop with these arguments:
695 * @fwnode: fwnode referring to EP40 under ISP.
696 * @prop: "remote-endpoint"
698 * @props: "port", "endpoint"
701 * And you'd get back fwnode referring to EP00 under CAM0.
703 * The same works the other way around: if you use EP00 under CAM0 as the
704 * fwnode, you'll get fwnode referring to EP40 under ISP.
706 * The same example in DT syntax would look like this:
709 * compatible = "nokia,smia";
715 * remote-endpoint = <&isp 4 0>;
726 * remote-endpoint = <&cam 0 0>;
732 * Return: 0 on success
733 * -ENOENT if no entries (or the property itself) were found
734 * -EINVAL if property parsing otherwise failed
735 * -ENOMEM if memory allocation failed
737 static struct fwnode_handle
*v4l2_fwnode_reference_get_int_prop(
738 struct fwnode_handle
*fwnode
, const char *prop
, unsigned int index
,
739 const char * const *props
, unsigned int nprops
)
741 struct fwnode_reference_args fwnode_args
;
742 unsigned int *args
= fwnode_args
.args
;
743 struct fwnode_handle
*child
;
747 * Obtain remote fwnode as well as the integer arguments.
749 * Note that right now both -ENODATA and -ENOENT may signal
750 * out-of-bounds access. Return -ENOENT in that case.
752 ret
= fwnode_property_get_reference_args(fwnode
, prop
, NULL
, nprops
,
753 index
, &fwnode_args
);
755 return ERR_PTR(ret
== -ENODATA
? -ENOENT
: ret
);
758 * Find a node in the tree under the referred fwnode corresponding to
759 * the integer arguments.
761 fwnode
= fwnode_args
.fwnode
;
765 /* Loop over all child nodes under fwnode. */
766 fwnode_for_each_child_node(fwnode
, child
) {
767 if (fwnode_property_read_u32(child
, *props
, &val
))
770 /* Found property, see if its value matches. */
775 fwnode_handle_put(fwnode
);
777 /* No property found; return an error here. */
779 fwnode
= ERR_PTR(-ENOENT
);
792 * v4l2_fwnode_reference_parse_int_props - parse references for async
794 * @dev: struct device pointer
795 * @notifier: notifier for @dev
796 * @prop: the name of the property
797 * @props: the array of integer property names
798 * @nprops: the number of integer properties
800 * Use v4l2_fwnode_reference_get_int_prop to find fwnodes through reference in
801 * property @prop with integer arguments with child nodes matching in properties
802 * @props. Then, set up V4L2 async sub-devices for those fwnodes in the notifier
805 * While it is technically possible to use this function on DT, it is only
806 * meaningful on ACPI. On Device tree you can refer to any node in the tree but
807 * on ACPI the references are limited to devices.
809 * Return: 0 on success
810 * -ENOENT if no entries (or the property itself) were found
811 * -EINVAL if property parsing otherwisefailed
812 * -ENOMEM if memory allocation failed
814 static int v4l2_fwnode_reference_parse_int_props(
815 struct device
*dev
, struct v4l2_async_notifier
*notifier
,
816 const char *prop
, const char * const *props
, unsigned int nprops
)
818 struct fwnode_handle
*fwnode
;
822 for (index
= 0; !IS_ERR((fwnode
= v4l2_fwnode_reference_get_int_prop(
823 dev_fwnode(dev
), prop
, index
, props
,
825 fwnode_handle_put(fwnode
);
828 * Note that right now both -ENODATA and -ENOENT may signal
829 * out-of-bounds access. Return the error in cases other than that.
831 if (PTR_ERR(fwnode
) != -ENOENT
&& PTR_ERR(fwnode
) != -ENODATA
)
832 return PTR_ERR(fwnode
);
834 ret
= v4l2_async_notifier_realloc(notifier
,
835 notifier
->num_subdevs
+ index
);
839 for (index
= 0; !IS_ERR((fwnode
= v4l2_fwnode_reference_get_int_prop(
840 dev_fwnode(dev
), prop
, index
, props
,
841 nprops
))); index
++) {
842 struct v4l2_async_subdev
*asd
;
844 if (WARN_ON(notifier
->num_subdevs
>= notifier
->max_subdevs
)) {
849 asd
= kzalloc(sizeof(struct v4l2_async_subdev
), GFP_KERNEL
);
855 notifier
->subdevs
[notifier
->num_subdevs
] = asd
;
856 asd
->match
.fwnode
= fwnode
;
857 asd
->match_type
= V4L2_ASYNC_MATCH_FWNODE
;
858 notifier
->num_subdevs
++;
861 return PTR_ERR(fwnode
) == -ENOENT
? 0 : PTR_ERR(fwnode
);
864 fwnode_handle_put(fwnode
);
868 int v4l2_async_notifier_parse_fwnode_sensor_common(
869 struct device
*dev
, struct v4l2_async_notifier
*notifier
)
871 static const char * const led_props
[] = { "led" };
872 static const struct {
874 const char * const *props
;
877 { "flash-leds", led_props
, ARRAY_SIZE(led_props
) },
878 { "lens-focus", NULL
, 0 },
882 for (i
= 0; i
< ARRAY_SIZE(props
); i
++) {
885 if (props
[i
].props
&& is_acpi_node(dev_fwnode(dev
)))
886 ret
= v4l2_fwnode_reference_parse_int_props(
887 dev
, notifier
, props
[i
].name
,
888 props
[i
].props
, props
[i
].nprops
);
890 ret
= v4l2_fwnode_reference_parse(
891 dev
, notifier
, props
[i
].name
);
892 if (ret
&& ret
!= -ENOENT
) {
893 dev_warn(dev
, "parsing property \"%s\" failed (%d)\n",
901 EXPORT_SYMBOL_GPL(v4l2_async_notifier_parse_fwnode_sensor_common
);
903 int v4l2_async_register_subdev_sensor_common(struct v4l2_subdev
*sd
)
905 struct v4l2_async_notifier
*notifier
;
908 if (WARN_ON(!sd
->dev
))
911 notifier
= kzalloc(sizeof(*notifier
), GFP_KERNEL
);
915 ret
= v4l2_async_notifier_parse_fwnode_sensor_common(sd
->dev
,
920 ret
= v4l2_async_subdev_notifier_register(sd
, notifier
);
924 ret
= v4l2_async_register_subdev(sd
);
928 sd
->subdev_notifier
= notifier
;
933 v4l2_async_notifier_unregister(notifier
);
936 v4l2_async_notifier_cleanup(notifier
);
941 EXPORT_SYMBOL_GPL(v4l2_async_register_subdev_sensor_common
);
943 MODULE_LICENSE("GPL");
944 MODULE_AUTHOR("Sakari Ailus <sakari.ailus@linux.intel.com>");
945 MODULE_AUTHOR("Sylwester Nawrocki <s.nawrocki@samsung.com>");
946 MODULE_AUTHOR("Guennadi Liakhovetski <g.liakhovetski@gmx.de>");