Skip to content

Commit 7c4d65f

Browse files
Sakari Ailusrkhuangtao
authored andcommitted
FROMLIST: v4l: fwnode: Add convenience function for parsing common external refs
Add v4l2_fwnode_parse_reference_sensor_common for parsing common sensor properties that refer to adjacent devices such as flash or lens driver chips. As this is an association only, there's little a regular driver needs to know about these devices as such. Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Acked-by: Hans Verkuil <hans.verkuil@cisco.com> Acked-by: Pavel Machek <pavel@ucw.cz> (cherry picked from commit 547be5f2082a4b5d148f8f4ddd8672c91ef52da9) 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: I3440987cb1ed89819dc54c9d47f7bd4e27ef3203 Reviewed-on: https://chromium-review.googlesource.com/693699 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 4cea477 commit 7c4d65f

3 files changed

Lines changed: 58 additions & 1 deletion

File tree

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,41 @@ static int v4l2_fwnode_reference_parse_int_props(
730730
return ret;
731731
}
732732

733+
int v4l2_async_notifier_parse_fwnode_sensor_common(
734+
struct device *dev, struct v4l2_async_notifier *notifier)
735+
{
736+
static const char *led_props[] = { "led" };
737+
static const struct {
738+
const char *name;
739+
const char **props;
740+
unsigned int nprops;
741+
} props[] = {
742+
{ "flash-leds", led_props, ARRAY_SIZE(led_props) },
743+
{ "lens-focus", NULL, 0 },
744+
};
745+
unsigned int i;
746+
747+
for (i = 0; i < ARRAY_SIZE(props); i++) {
748+
int ret;
749+
750+
if (props[i].props && is_acpi_node(dev_fwnode(dev)))
751+
ret = v4l2_fwnode_reference_parse_int_props(
752+
dev, notifier, props[i].name,
753+
props[i].props, props[i].nprops);
754+
else
755+
ret = v4l2_fwnode_reference_parse(
756+
dev, notifier, props[i].name);
757+
if (ret && ret != -ENOENT) {
758+
dev_warn(dev, "parsing property \"%s\" failed (%d)\n",
759+
props[i].name, ret);
760+
return ret;
761+
}
762+
}
763+
764+
return 0;
765+
}
766+
EXPORT_SYMBOL_GPL(v4l2_async_notifier_parse_fwnode_sensor_common);
767+
733768
MODULE_LICENSE("GPL");
734769
MODULE_AUTHOR("Sakari Ailus <sakari.ailus@linux.intel.com>");
735770
MODULE_AUTHOR("Sylwester Nawrocki <s.nawrocki@samsung.com>");

include/media/v4l2-async.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ void v4l2_async_notifier_unregister(struct v4l2_async_notifier *notifier);
155155
* Release memory resources related to a notifier, including the async
156156
* sub-devices allocated for the purposes of the notifier but not the notifier
157157
* itself. The user is responsible for calling this function to clean up the
158-
* notifier after calling @v4l2_async_notifier_parse_fwnode_endpoints.
158+
* notifier after calling @v4l2_async_notifier_parse_fwnode_endpoints or
159+
* @v4l2_fwnode_reference_parse_sensor_common.
159160
*
160161
* There is no harm from calling v4l2_async_notifier_cleanup in other
161162
* cases as long as its memory has been zeroed after it has been

include/media/v4l2-fwnode.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,4 +298,25 @@ int v4l2_async_notifier_parse_fwnode_endpoints_by_port(
298298
struct v4l2_fwnode_endpoint *vep,
299299
struct v4l2_async_subdev *asd));
300300

301+
/**
302+
* v4l2_fwnode_reference_parse_sensor_common - parse common references on
303+
* sensors for async sub-devices
304+
* @dev: the device node the properties of which are parsed for references
305+
* @notifier: the async notifier where the async subdevs will be added
306+
*
307+
* Parse common sensor properties for remote devices related to the
308+
* sensor and set up async sub-devices for them.
309+
*
310+
* Any notifier populated using this function must be released with a call to
311+
* v4l2_async_notifier_release() after it has been unregistered and the async
312+
* sub-devices are no longer in use, even in the case the function returned an
313+
* error.
314+
*
315+
* Return: 0 on success
316+
* -ENOMEM if memory allocation failed
317+
* -EINVAL if property parsing failed
318+
*/
319+
int v4l2_async_notifier_parse_fwnode_sensor_common(
320+
struct device *dev, struct v4l2_async_notifier *notifier);
321+
301322
#endif /* _V4L2_FWNODE_H */

0 commit comments

Comments
 (0)