[media] media: Media Controller register/unregister entity_notify API
Add new interfaces to register and unregister entity_notify hook to media device. These interfaces allow drivers to add hooks to take appropriate actions when new entities get added to a shared media device. For example, au0828 bridge driver registers an entity_notify hook to create links as needed between media graph nodes. [mchehab@osg.samsung.com: simple comments should be /* and not /**] Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
This commit is contained in:
parent
7a2eba12ff
commit
afcbdb5589
|
@ -542,6 +542,7 @@ static void media_device_release(struct media_devnode *mdev)
|
||||||
int __must_check media_device_register_entity(struct media_device *mdev,
|
int __must_check media_device_register_entity(struct media_device *mdev,
|
||||||
struct media_entity *entity)
|
struct media_entity *entity)
|
||||||
{
|
{
|
||||||
|
struct media_entity_notify *notify, *next;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
@ -581,6 +582,11 @@ int __must_check media_device_register_entity(struct media_device *mdev,
|
||||||
media_gobj_create(mdev, MEDIA_GRAPH_PAD,
|
media_gobj_create(mdev, MEDIA_GRAPH_PAD,
|
||||||
&entity->pads[i].graph_obj);
|
&entity->pads[i].graph_obj);
|
||||||
|
|
||||||
|
/* invoke entity_notify callbacks */
|
||||||
|
list_for_each_entry_safe(notify, next, &mdev->entity_notify, list) {
|
||||||
|
(notify)->notify(entity, notify->notify_data);
|
||||||
|
}
|
||||||
|
|
||||||
spin_unlock(&mdev->lock);
|
spin_unlock(&mdev->lock);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -614,6 +620,8 @@ static void __media_device_unregister_entity(struct media_entity *entity)
|
||||||
/* Remove the entity */
|
/* Remove the entity */
|
||||||
media_gobj_destroy(&entity->graph_obj);
|
media_gobj_destroy(&entity->graph_obj);
|
||||||
|
|
||||||
|
/* invoke entity_notify callbacks to handle entity removal?? */
|
||||||
|
|
||||||
entity->graph_obj.mdev = NULL;
|
entity->graph_obj.mdev = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -646,6 +654,7 @@ void media_device_init(struct media_device *mdev)
|
||||||
INIT_LIST_HEAD(&mdev->interfaces);
|
INIT_LIST_HEAD(&mdev->interfaces);
|
||||||
INIT_LIST_HEAD(&mdev->pads);
|
INIT_LIST_HEAD(&mdev->pads);
|
||||||
INIT_LIST_HEAD(&mdev->links);
|
INIT_LIST_HEAD(&mdev->links);
|
||||||
|
INIT_LIST_HEAD(&mdev->entity_notify);
|
||||||
spin_lock_init(&mdev->lock);
|
spin_lock_init(&mdev->lock);
|
||||||
mutex_init(&mdev->graph_mutex);
|
mutex_init(&mdev->graph_mutex);
|
||||||
ida_init(&mdev->entity_internal_idx);
|
ida_init(&mdev->entity_internal_idx);
|
||||||
|
@ -691,11 +700,40 @@ int __must_check __media_device_register(struct media_device *mdev,
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(__media_device_register);
|
EXPORT_SYMBOL_GPL(__media_device_register);
|
||||||
|
|
||||||
|
int __must_check media_device_register_entity_notify(struct media_device *mdev,
|
||||||
|
struct media_entity_notify *nptr)
|
||||||
|
{
|
||||||
|
spin_lock(&mdev->lock);
|
||||||
|
list_add_tail(&nptr->list, &mdev->entity_notify);
|
||||||
|
spin_unlock(&mdev->lock);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL_GPL(media_device_register_entity_notify);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Note: Should be called with mdev->lock held.
|
||||||
|
*/
|
||||||
|
static void __media_device_unregister_entity_notify(struct media_device *mdev,
|
||||||
|
struct media_entity_notify *nptr)
|
||||||
|
{
|
||||||
|
list_del(&nptr->list);
|
||||||
|
}
|
||||||
|
|
||||||
|
void media_device_unregister_entity_notify(struct media_device *mdev,
|
||||||
|
struct media_entity_notify *nptr)
|
||||||
|
{
|
||||||
|
spin_lock(&mdev->lock);
|
||||||
|
__media_device_unregister_entity_notify(mdev, nptr);
|
||||||
|
spin_unlock(&mdev->lock);
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL_GPL(media_device_unregister_entity_notify);
|
||||||
|
|
||||||
void media_device_unregister(struct media_device *mdev)
|
void media_device_unregister(struct media_device *mdev)
|
||||||
{
|
{
|
||||||
struct media_entity *entity;
|
struct media_entity *entity;
|
||||||
struct media_entity *next;
|
struct media_entity *next;
|
||||||
struct media_interface *intf, *tmp_intf;
|
struct media_interface *intf, *tmp_intf;
|
||||||
|
struct media_entity_notify *notify, *nextp;
|
||||||
|
|
||||||
if (mdev == NULL)
|
if (mdev == NULL)
|
||||||
return;
|
return;
|
||||||
|
@ -712,6 +750,10 @@ void media_device_unregister(struct media_device *mdev)
|
||||||
list_for_each_entry_safe(entity, next, &mdev->entities, graph_obj.list)
|
list_for_each_entry_safe(entity, next, &mdev->entities, graph_obj.list)
|
||||||
__media_device_unregister_entity(entity);
|
__media_device_unregister_entity(entity);
|
||||||
|
|
||||||
|
/* Remove all entity_notify callbacks from the media device */
|
||||||
|
list_for_each_entry_safe(notify, nextp, &mdev->entity_notify, list)
|
||||||
|
__media_device_unregister_entity_notify(mdev, notify);
|
||||||
|
|
||||||
/* Remove all interfaces from the media device */
|
/* Remove all interfaces from the media device */
|
||||||
list_for_each_entry_safe(intf, tmp_intf, &mdev->interfaces,
|
list_for_each_entry_safe(intf, tmp_intf, &mdev->interfaces,
|
||||||
graph_obj.list) {
|
graph_obj.list) {
|
||||||
|
|
|
@ -264,6 +264,22 @@
|
||||||
struct ida;
|
struct ida;
|
||||||
struct device;
|
struct device;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* struct media_entity_notify - Media Entity Notify
|
||||||
|
*
|
||||||
|
* @list: List head
|
||||||
|
* @notify_data: Input data to invoke the callback
|
||||||
|
* @notify: Callback function pointer
|
||||||
|
*
|
||||||
|
* Drivers may register a callback to take action when
|
||||||
|
* new entities get registered with the media device.
|
||||||
|
*/
|
||||||
|
struct media_entity_notify {
|
||||||
|
struct list_head list;
|
||||||
|
void *notify_data;
|
||||||
|
void (*notify)(struct media_entity *entity, void *notify_data);
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* struct media_device - Media device
|
* struct media_device - Media device
|
||||||
* @dev: Parent device
|
* @dev: Parent device
|
||||||
|
@ -287,6 +303,7 @@ struct device;
|
||||||
* @interfaces: List of registered interfaces
|
* @interfaces: List of registered interfaces
|
||||||
* @pads: List of registered pads
|
* @pads: List of registered pads
|
||||||
* @links: List of registered links
|
* @links: List of registered links
|
||||||
|
* @entity_notify: List of registered entity_notify callbacks
|
||||||
* @lock: Entities list lock
|
* @lock: Entities list lock
|
||||||
* @graph_mutex: Entities graph operation lock
|
* @graph_mutex: Entities graph operation lock
|
||||||
* @link_notify: Link state change notification callback
|
* @link_notify: Link state change notification callback
|
||||||
|
@ -324,6 +341,9 @@ struct media_device {
|
||||||
struct list_head pads;
|
struct list_head pads;
|
||||||
struct list_head links;
|
struct list_head links;
|
||||||
|
|
||||||
|
/* notify callback list invoked when a new entity is registered */
|
||||||
|
struct list_head entity_notify;
|
||||||
|
|
||||||
/* Protects the graph objects creation/removal */
|
/* Protects the graph objects creation/removal */
|
||||||
spinlock_t lock;
|
spinlock_t lock;
|
||||||
/* Serializes graph operations. */
|
/* Serializes graph operations. */
|
||||||
|
@ -506,6 +526,31 @@ int __must_check media_device_register_entity(struct media_device *mdev,
|
||||||
*/
|
*/
|
||||||
void media_device_unregister_entity(struct media_entity *entity);
|
void media_device_unregister_entity(struct media_entity *entity);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* media_device_register_entity_notify() - Registers a media entity_notify
|
||||||
|
* callback
|
||||||
|
*
|
||||||
|
* @mdev: The media device
|
||||||
|
* @nptr: The media_entity_notify
|
||||||
|
*
|
||||||
|
* Note: When a new entity is registered, all the registered
|
||||||
|
* media_entity_notify callbacks are invoked.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int __must_check media_device_register_entity_notify(struct media_device *mdev,
|
||||||
|
struct media_entity_notify *nptr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* media_device_unregister_entity_notify() - Unregister a media entity notify
|
||||||
|
* callback
|
||||||
|
*
|
||||||
|
* @mdev: The media device
|
||||||
|
* @nptr: The media_entity_notify
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void media_device_unregister_entity_notify(struct media_device *mdev,
|
||||||
|
struct media_entity_notify *nptr);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* media_device_get_devres() - get media device as device resource
|
* media_device_get_devres() - get media device as device resource
|
||||||
* creates if one doesn't exist
|
* creates if one doesn't exist
|
||||||
|
@ -594,6 +639,17 @@ static inline int media_device_register_entity(struct media_device *mdev,
|
||||||
static inline void media_device_unregister_entity(struct media_entity *entity)
|
static inline void media_device_unregister_entity(struct media_entity *entity)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
static inline int media_device_register_entity_notify(
|
||||||
|
struct media_device *mdev,
|
||||||
|
struct media_entity_notify *nptr)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
static inline void media_device_unregister_entity_notify(
|
||||||
|
struct media_device *mdev,
|
||||||
|
struct media_entity_notify *nptr)
|
||||||
|
{
|
||||||
|
}
|
||||||
static inline struct media_device *media_device_get_devres(struct device *dev)
|
static inline struct media_device *media_device_get_devres(struct device *dev)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
Loading…
Reference in New Issue