Skip to content

Commit aef69d5

Browse files
Sakari Ailusmchehab
authored andcommitted
media: v4l: fwnode: Add a convenience function for registering sensors
Add a convenience function for parsing firmware for information on related devices using v4l2_async_notifier_parse_fwnode_sensor_common() registering the notifier and finally the async sub-device itself. This should be useful for sensor drivers that do not have device specific requirements related to firmware information parsing or the async framework. Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Acked-by: Hans Verkuil <hans.verkuil@cisco.com> Reviewed-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se> Reviewed-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk> Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
1 parent 7a9ec80 commit aef69d5

4 files changed

Lines changed: 81 additions & 4 deletions

File tree

‎drivers/media/v4l2-core/v4l2-async.c‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -474,19 +474,25 @@ int v4l2_async_subdev_notifier_register(struct v4l2_subdev *sd,
474474
}
475475
EXPORT_SYMBOL(v4l2_async_subdev_notifier_register);
476476

477-
void v4l2_async_notifier_unregister(struct v4l2_async_notifier *notifier)
477+
static void __v4l2_async_notifier_unregister(
478+
struct v4l2_async_notifier *notifier)
478479
{
479-
if (!notifier->v4l2_dev && !notifier->sd)
480+
if (!notifier || (!notifier->v4l2_dev && !notifier->sd))
480481
return;
481482

482-
mutex_lock(&list_lock);
483-
484483
v4l2_async_notifier_unbind_all_subdevs(notifier);
485484

486485
notifier->sd = NULL;
487486
notifier->v4l2_dev = NULL;
488487

489488
list_del(&notifier->list);
489+
}
490+
491+
void v4l2_async_notifier_unregister(struct v4l2_async_notifier *notifier)
492+
{
493+
mutex_lock(&list_lock);
494+
495+
__v4l2_async_notifier_unregister(notifier);
490496

491497
mutex_unlock(&list_lock);
492498
}
@@ -596,6 +602,11 @@ void v4l2_async_unregister_subdev(struct v4l2_subdev *sd)
596602
{
597603
mutex_lock(&list_lock);
598604

605+
__v4l2_async_notifier_unregister(sd->subdev_notifier);
606+
v4l2_async_notifier_cleanup(sd->subdev_notifier);
607+
kfree(sd->subdev_notifier);
608+
sd->subdev_notifier = NULL;
609+
599610
if (sd->asd) {
600611
struct v4l2_async_notifier *notifier = sd->notifier;
601612

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
#include <media/v4l2-async.h>
3131
#include <media/v4l2-fwnode.h>
32+
#include <media/v4l2-subdev.h>
3233

3334
enum v4l2_fwnode_bus_type {
3435
V4L2_FWNODE_BUS_TYPE_GUESS = 0,
@@ -900,6 +901,46 @@ int v4l2_async_notifier_parse_fwnode_sensor_common(
900901
}
901902
EXPORT_SYMBOL_GPL(v4l2_async_notifier_parse_fwnode_sensor_common);
902903

904+
int v4l2_async_register_subdev_sensor_common(struct v4l2_subdev *sd)
905+
{
906+
struct v4l2_async_notifier *notifier;
907+
int ret;
908+
909+
if (WARN_ON(!sd->dev))
910+
return -ENODEV;
911+
912+
notifier = kzalloc(sizeof(*notifier), GFP_KERNEL);
913+
if (!notifier)
914+
return -ENOMEM;
915+
916+
ret = v4l2_async_notifier_parse_fwnode_sensor_common(sd->dev,
917+
notifier);
918+
if (ret < 0)
919+
goto out_cleanup;
920+
921+
ret = v4l2_async_subdev_notifier_register(sd, notifier);
922+
if (ret < 0)
923+
goto out_cleanup;
924+
925+
ret = v4l2_async_register_subdev(sd);
926+
if (ret < 0)
927+
goto out_unregister;
928+
929+
sd->subdev_notifier = notifier;
930+
931+
return 0;
932+
933+
out_unregister:
934+
v4l2_async_notifier_unregister(notifier);
935+
936+
out_cleanup:
937+
v4l2_async_notifier_cleanup(notifier);
938+
kfree(notifier);
939+
940+
return ret;
941+
}
942+
EXPORT_SYMBOL_GPL(v4l2_async_register_subdev_sensor_common);
943+
903944
MODULE_LICENSE("GPL");
904945
MODULE_AUTHOR("Sakari Ailus <sakari.ailus@linux.intel.com>");
905946
MODULE_AUTHOR("Sylwester Nawrocki <s.nawrocki@samsung.com>");

‎include/media/v4l2-async.h‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,28 @@ void v4l2_async_notifier_cleanup(struct v4l2_async_notifier *notifier);
173173
*/
174174
int v4l2_async_register_subdev(struct v4l2_subdev *sd);
175175

176+
/**
177+
* v4l2_async_register_subdev_sensor_common - registers a sensor sub-device to
178+
* the asynchronous sub-device
179+
* framework and parse set up common
180+
* sensor related devices
181+
*
182+
* @sd: pointer to struct &v4l2_subdev
183+
*
184+
* This function is just like v4l2_async_register_subdev() with the exception
185+
* that calling it will also parse firmware interfaces for remote references
186+
* using v4l2_async_notifier_parse_fwnode_sensor_common() and registers the
187+
* async sub-devices. The sub-device is similarly unregistered by calling
188+
* v4l2_async_unregister_subdev().
189+
*
190+
* While registered, the subdev module is marked as in-use.
191+
*
192+
* An error is returned if the module is no longer loaded on any attempts
193+
* to register it.
194+
*/
195+
int __must_check v4l2_async_register_subdev_sensor_common(
196+
struct v4l2_subdev *sd);
197+
176198
/**
177199
* v4l2_async_unregister_subdev - unregisters a sub-device to the asynchronous
178200
* subdevice framework

‎include/media/v4l2-subdev.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,8 @@ struct v4l2_subdev_platform_data {
793793
* list.
794794
* @asd: Pointer to respective &struct v4l2_async_subdev.
795795
* @notifier: Pointer to the managing notifier.
796+
* @subdev_notifier: A sub-device notifier implicitly registered for the sub-
797+
* device using v4l2_device_register_sensor_subdev().
796798
* @pdata: common part of subdevice platform data
797799
*
798800
* Each instance of a subdev driver should create this struct, either
@@ -823,6 +825,7 @@ struct v4l2_subdev {
823825
struct list_head async_list;
824826
struct v4l2_async_subdev *asd;
825827
struct v4l2_async_notifier *notifier;
828+
struct v4l2_async_notifier *subdev_notifier;
826829
struct v4l2_subdev_platform_data *pdata;
827830
};
828831

0 commit comments

Comments
 (0)