aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2010-03-07 13:04:59 -0500
committerMauro Carvalho Chehab <mchehab@redhat.com>2011-03-22 03:53:12 -0400
commit503c3d829eaf48837dd5bff5d97ad66369bb955a (patch)
tree9c14ed9561c5ffca07909e53d5ae0e52cdf5f99e /drivers/media
parenta5ccc48a7c48610e7f92fa599406738d69195d51 (diff)
[media] media: Entity use count
Due to the wide differences between drivers regarding power management needs, the media controller does not implement power management. However, the media_entity structure includes a use_count field that media drivers can use to track the number of users of every entity for power management needs. The use_count field is owned by media drivers and must not be touched by entity drivers. Access to the field must be protected by the media device graph_mutex lock. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Acked-by: Hans Verkuil <hverkuil@xs4all.nl> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media')
-rw-r--r--drivers/media/media-device.c1
-rw-r--r--drivers/media/media-entity.c46
2 files changed, 47 insertions, 0 deletions
diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index a36509a1df09..d2bc809d7a2a 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -73,6 +73,7 @@ int __must_check media_device_register(struct media_device *mdev)
73 mdev->entity_id = 1; 73 mdev->entity_id = 1;
74 INIT_LIST_HEAD(&mdev->entities); 74 INIT_LIST_HEAD(&mdev->entities);
75 spin_lock_init(&mdev->lock); 75 spin_lock_init(&mdev->lock);
76 mutex_init(&mdev->graph_mutex);
76 77
77 /* Register the device node. */ 78 /* Register the device node. */
78 mdev->devnode.fops = &media_device_fops; 79 mdev->devnode.fops = &media_device_fops;
diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index 166f2b5505ce..3e7e2d569cec 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -23,6 +23,7 @@
23#include <linux/module.h> 23#include <linux/module.h>
24#include <linux/slab.h> 24#include <linux/slab.h>
25#include <media/media-entity.h> 25#include <media/media-entity.h>
26#include <media/media-device.h>
26 27
27/** 28/**
28 * media_entity_init - Initialize a media entity 29 * media_entity_init - Initialize a media entity
@@ -196,6 +197,51 @@ media_entity_graph_walk_next(struct media_entity_graph *graph)
196EXPORT_SYMBOL_GPL(media_entity_graph_walk_next); 197EXPORT_SYMBOL_GPL(media_entity_graph_walk_next);
197 198
198/* ----------------------------------------------------------------------------- 199/* -----------------------------------------------------------------------------
200 * Module use count
201 */
202
203/*
204 * media_entity_get - Get a reference to the parent module
205 * @entity: The entity
206 *
207 * Get a reference to the parent media device module.
208 *
209 * The function will return immediately if @entity is NULL.
210 *
211 * Return a pointer to the entity on success or NULL on failure.
212 */
213struct media_entity *media_entity_get(struct media_entity *entity)
214{
215 if (entity == NULL)
216 return NULL;
217
218 if (entity->parent->dev &&
219 !try_module_get(entity->parent->dev->driver->owner))
220 return NULL;
221
222 return entity;
223}
224EXPORT_SYMBOL_GPL(media_entity_get);
225
226/*
227 * media_entity_put - Release the reference to the parent module
228 * @entity: The entity
229 *
230 * Release the reference count acquired by media_entity_get().
231 *
232 * The function will return immediately if @entity is NULL.
233 */
234void media_entity_put(struct media_entity *entity)
235{
236 if (entity == NULL)
237 return;
238
239 if (entity->parent->dev)
240 module_put(entity->parent->dev->driver->owner);
241}
242EXPORT_SYMBOL_GPL(media_entity_put);
243
244/* -----------------------------------------------------------------------------
199 * Links management 245 * Links management
200 */ 246 */
201 247