diff options
author | Hans Verkuil <hverkuil@xs4all.nl> | 2011-01-08 05:15:53 -0500 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2011-01-19 08:45:31 -0500 |
commit | 45f6f84af3ae9db19f39bc5d0976d626b0ef626e (patch) | |
tree | f3ef2f5bb782f5d7180c5cc2a8ab58fd855a4ccf | |
parent | 3c7c9370fb645f4713e0fbbe69425d8db9b47a13 (diff) |
[media] v4l2-subdev: add (un)register internal ops
Some subdevs need to call into the board code after they are registered
and have a valid struct v4l2_device pointer. The s_config op was abused
for this, but now that it is removed we need a cleaner way of solving this.
So this patch adds a struct with internal ops that the v4l2 core can call.
Currently only two ops exist: register and unregister. Subdevs can implement
these to call the board code and pass it the v4l2_device pointer, which the
board code can then use to get access to the struct that embeds the
v4l2_device.
It is expected that in the future open and close ops will also be added.
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
-rw-r--r-- | drivers/media/video/v4l2-device.c | 14 | ||||
-rw-r--r-- | include/media/v4l2-subdev.h | 17 |
2 files changed, 29 insertions, 2 deletions
diff --git a/drivers/media/video/v4l2-device.c b/drivers/media/video/v4l2-device.c index 7fe6f92af480..b24f002ffa67 100644 --- a/drivers/media/video/v4l2-device.c +++ b/drivers/media/video/v4l2-device.c | |||
@@ -126,11 +126,19 @@ int v4l2_device_register_subdev(struct v4l2_device *v4l2_dev, | |||
126 | WARN_ON(sd->v4l2_dev != NULL); | 126 | WARN_ON(sd->v4l2_dev != NULL); |
127 | if (!try_module_get(sd->owner)) | 127 | if (!try_module_get(sd->owner)) |
128 | return -ENODEV; | 128 | return -ENODEV; |
129 | sd->v4l2_dev = v4l2_dev; | ||
130 | if (sd->internal_ops && sd->internal_ops->registered) { | ||
131 | err = sd->internal_ops->registered(sd); | ||
132 | if (err) | ||
133 | return err; | ||
134 | } | ||
129 | /* This just returns 0 if either of the two args is NULL */ | 135 | /* This just returns 0 if either of the two args is NULL */ |
130 | err = v4l2_ctrl_add_handler(v4l2_dev->ctrl_handler, sd->ctrl_handler); | 136 | err = v4l2_ctrl_add_handler(v4l2_dev->ctrl_handler, sd->ctrl_handler); |
131 | if (err) | 137 | if (err) { |
138 | if (sd->internal_ops && sd->internal_ops->unregistered) | ||
139 | sd->internal_ops->unregistered(sd); | ||
132 | return err; | 140 | return err; |
133 | sd->v4l2_dev = v4l2_dev; | 141 | } |
134 | spin_lock(&v4l2_dev->lock); | 142 | spin_lock(&v4l2_dev->lock); |
135 | list_add_tail(&sd->list, &v4l2_dev->subdevs); | 143 | list_add_tail(&sd->list, &v4l2_dev->subdevs); |
136 | spin_unlock(&v4l2_dev->lock); | 144 | spin_unlock(&v4l2_dev->lock); |
@@ -146,6 +154,8 @@ void v4l2_device_unregister_subdev(struct v4l2_subdev *sd) | |||
146 | spin_lock(&sd->v4l2_dev->lock); | 154 | spin_lock(&sd->v4l2_dev->lock); |
147 | list_del(&sd->list); | 155 | list_del(&sd->list); |
148 | spin_unlock(&sd->v4l2_dev->lock); | 156 | spin_unlock(&sd->v4l2_dev->lock); |
157 | if (sd->internal_ops && sd->internal_ops->unregistered) | ||
158 | sd->internal_ops->unregistered(sd); | ||
149 | sd->v4l2_dev = NULL; | 159 | sd->v4l2_dev = NULL; |
150 | module_put(sd->owner); | 160 | module_put(sd->owner); |
151 | } | 161 | } |
diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h index 42fbe462031d..daf1e57d9b26 100644 --- a/include/media/v4l2-subdev.h +++ b/include/media/v4l2-subdev.h | |||
@@ -411,6 +411,21 @@ struct v4l2_subdev_ops { | |||
411 | const struct v4l2_subdev_sensor_ops *sensor; | 411 | const struct v4l2_subdev_sensor_ops *sensor; |
412 | }; | 412 | }; |
413 | 413 | ||
414 | /* | ||
415 | * Internal ops. Never call this from drivers, only the v4l2 framework can call | ||
416 | * these ops. | ||
417 | * | ||
418 | * registered: called when this subdev is registered. When called the v4l2_dev | ||
419 | * field is set to the correct v4l2_device. | ||
420 | * | ||
421 | * unregistered: called when this subdev is unregistered. When called the | ||
422 | * v4l2_dev field is still set to the correct v4l2_device. | ||
423 | */ | ||
424 | struct v4l2_subdev_internal_ops { | ||
425 | int (*registered)(struct v4l2_subdev *sd); | ||
426 | void (*unregistered)(struct v4l2_subdev *sd); | ||
427 | }; | ||
428 | |||
414 | #define V4L2_SUBDEV_NAME_SIZE 32 | 429 | #define V4L2_SUBDEV_NAME_SIZE 32 |
415 | 430 | ||
416 | /* Set this flag if this subdev is a i2c device. */ | 431 | /* Set this flag if this subdev is a i2c device. */ |
@@ -427,6 +442,8 @@ struct v4l2_subdev { | |||
427 | u32 flags; | 442 | u32 flags; |
428 | struct v4l2_device *v4l2_dev; | 443 | struct v4l2_device *v4l2_dev; |
429 | const struct v4l2_subdev_ops *ops; | 444 | const struct v4l2_subdev_ops *ops; |
445 | /* Never call these internal ops from within a driver! */ | ||
446 | const struct v4l2_subdev_internal_ops *internal_ops; | ||
430 | /* The control handler of this subdev. May be NULL. */ | 447 | /* The control handler of this subdev. May be NULL. */ |
431 | struct v4l2_ctrl_handler *ctrl_handler; | 448 | struct v4l2_ctrl_handler *ctrl_handler; |
432 | /* name must be unique */ | 449 | /* name must be unique */ |