Skip to content

Commit 255a3eb

Browse files
Sakari Ailusrkhuangtao
authored andcommitted
FROMLIST: v4l: async: 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> (cherry picked from commit dd202f9d5346cacd785a482952f54b205eafcc64) 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> Conflicts: include/media/v4l2-subdev.h (convert to older documentation style) BUG=b:64133998 TEST=media device topology shows subdevs registered successfully TEST=no camera regression Change-Id: Ia4af50d7204173d17d04faf9575f6605a1400e46 Reviewed-on: https://chromium-review.googlesource.com/693700 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 7c4d65f commit 255a3eb

4 files changed

Lines changed: 71 additions & 0 deletions

File tree

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,11 @@ void v4l2_async_unregister_subdev(struct v4l2_subdev *sd)
584584
{
585585
struct v4l2_async_notifier *notifier = sd->notifier;
586586

587+
if (sd->subdev_notifier)
588+
v4l2_async_notifier_unregister(sd->subdev_notifier);
589+
v4l2_async_notifier_cleanup(sd->subdev_notifier);
590+
kfree(sd->subdev_notifier);
591+
587592
if (!sd->asd) {
588593
if (!list_empty(&sd->async_list))
589594
v4l2_async_cleanup(sd);

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
static int v4l2_fwnode_endpoint_parse_csi_bus(struct fwnode_handle *fwnode,
3435
struct v4l2_fwnode_endpoint *vep)
@@ -765,6 +766,46 @@ int v4l2_async_notifier_parse_fwnode_sensor_common(
765766
}
766767
EXPORT_SYMBOL_GPL(v4l2_async_notifier_parse_fwnode_sensor_common);
767768

769+
int v4l2_async_register_subdev_sensor_common(struct v4l2_subdev *sd)
770+
{
771+
struct v4l2_async_notifier *notifier;
772+
int ret;
773+
774+
if (WARN_ON(!sd->dev))
775+
return -ENODEV;
776+
777+
notifier = kzalloc(sizeof(*notifier), GFP_KERNEL);
778+
if (!notifier)
779+
return -ENOMEM;
780+
781+
ret = v4l2_async_notifier_parse_fwnode_sensor_common(sd->dev,
782+
notifier);
783+
if (ret < 0)
784+
goto out_cleanup;
785+
786+
ret = v4l2_async_subdev_notifier_register(sd, notifier);
787+
if (ret < 0)
788+
goto out_cleanup;
789+
790+
ret = v4l2_async_register_subdev(sd);
791+
if (ret < 0)
792+
goto out_unregister;
793+
794+
sd->subdev_notifier = notifier;
795+
796+
return 0;
797+
798+
out_unregister:
799+
v4l2_async_notifier_unregister(notifier);
800+
801+
out_cleanup:
802+
v4l2_async_notifier_cleanup(notifier);
803+
kfree(notifier);
804+
805+
return ret;
806+
}
807+
EXPORT_SYMBOL_GPL(v4l2_async_register_subdev_sensor_common);
808+
768809
MODULE_LICENSE("GPL");
769810
MODULE_AUTHOR("Sakari Ailus <sakari.ailus@linux.intel.com>");
770811
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
@@ -172,6 +172,28 @@ void v4l2_async_notifier_cleanup(struct v4l2_async_notifier *notifier);
172172
*/
173173
int v4l2_async_register_subdev(struct v4l2_subdev *sd);
174174

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

include/media/v4l2-subdev.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,9 @@ struct v4l2_subdev {
750750
/* Pointer to the managing notifier. */
751751
struct v4l2_async_notifier *notifier;
752752
/* common part of subdevice platform data */
753+
struct v4l2_async_notifier *subdev_notifier;
754+
/* A sub-device notifier implicitly registered for the sub-device
755+
using v4l2_device_register_sensor_subdev(). */
753756
struct v4l2_subdev_platform_data *pdata;
754757
};
755758

0 commit comments

Comments
 (0)