Skip to content

Commit d2209eb

Browse files
Sakari Ailusrkhuangtao
authored andcommitted
FROMLIST: v4l: fwnode: Add a helper function for parsing generic references
Add function v4l2_fwnode_reference_parse() for parsing them as async sub-devices. This can be done on e.g. flash or lens async sub-devices that are not part of but are associated with a sensor. Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Acked-by: Hans Verkuil <hans.verkuil@cisco.com> (cherry picked from commit ba63cd710bba4c3d9f2379d4af62412b2e4bd4c7) https://git.linuxtv.org/sailus/media_tree.git/log/?h=010f7f4393fd http://www.spinics.net/lists/linux-media/msg122688.html Signed-off-by: Marc Herbert <marc.herbert@intel.com> BUG=b:64133998 TEST=media device topology shows subdevs registered successfully TEST=no camera regression Change-Id: I9f84287faf59c8215d010f83671985fb66e02181 Reviewed-on: https://chromium-review.googlesource.com/693697 Commit-Ready: Tomasz Figa <tfiga@chromium.org> Tested-by: Hyungwoo Yang <hyungwoo.yang@intel.com> Reviewed-by: Tomasz Figa <tfiga@chromium.org> Signed-off-by: Jacob Chen <jacob2.chen@rock-chips.com>
1 parent ffa51fe commit d2209eb

1 file changed

Lines changed: 69 additions & 0 deletions

File tree

drivers/media/v4l2-core/v4l2-fwnode.c

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,75 @@ int v4l2_async_notifier_parse_fwnode_endpoints_by_port(
460460
}
461461
EXPORT_SYMBOL_GPL(v4l2_async_notifier_parse_fwnode_endpoints_by_port);
462462

463+
/*
464+
* v4l2_fwnode_reference_parse - parse references for async sub-devices
465+
* @dev: the device node the properties of which are parsed for references
466+
* @notifier: the async notifier where the async subdevs will be added
467+
* @prop: the name of the property
468+
*
469+
* Return: 0 on success
470+
* -ENOENT if no entries were found
471+
* -ENOMEM if memory allocation failed
472+
* -EINVAL if property parsing failed
473+
*/
474+
static int v4l2_fwnode_reference_parse(
475+
struct device *dev, struct v4l2_async_notifier *notifier,
476+
const char *prop)
477+
{
478+
struct fwnode_reference_args args;
479+
unsigned int index;
480+
int ret;
481+
482+
for (index = 0;
483+
!(ret = fwnode_property_get_reference_args(
484+
dev_fwnode(dev), prop, NULL, 0, index, &args));
485+
index++)
486+
fwnode_handle_put(args.fwnode);
487+
488+
if (!index)
489+
return -ENOENT;
490+
491+
/*
492+
* Note that right now both -ENODATA and -ENOENT may signal
493+
* out-of-bounds access. Return the error in cases other than that.
494+
*/
495+
if (ret != -ENOENT && ret != -ENODATA)
496+
return ret;
497+
498+
ret = v4l2_async_notifier_realloc(notifier,
499+
notifier->num_subdevs + index);
500+
if (ret)
501+
return ret;
502+
503+
for (index = 0; !fwnode_property_get_reference_args(
504+
dev_fwnode(dev), prop, NULL, 0, index, &args);
505+
index++) {
506+
struct v4l2_async_subdev *asd;
507+
508+
if (WARN_ON(notifier->num_subdevs >= notifier->max_subdevs)) {
509+
ret = -EINVAL;
510+
goto error;
511+
}
512+
513+
asd = kzalloc(sizeof(*asd), GFP_KERNEL);
514+
if (!asd) {
515+
ret = -ENOMEM;
516+
goto error;
517+
}
518+
519+
notifier->subdevs[notifier->num_subdevs] = asd;
520+
asd->match.fwnode.fwnode = args.fwnode;
521+
asd->match_type = V4L2_ASYNC_MATCH_FWNODE;
522+
notifier->num_subdevs++;
523+
}
524+
525+
return 0;
526+
527+
error:
528+
fwnode_handle_put(args.fwnode);
529+
return ret;
530+
}
531+
463532
MODULE_LICENSE("GPL");
464533
MODULE_AUTHOR("Sakari Ailus <sakari.ailus@linux.intel.com>");
465534
MODULE_AUTHOR("Sylwester Nawrocki <s.nawrocki@samsung.com>");

0 commit comments

Comments
 (0)