From patchwork Wed Jul 22 22:42:03 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuah Khan X-Patchwork-Id: 6851241 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 51D999F1D4 for ; Thu, 23 Jul 2015 06:13:44 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5091B20768 for ; Thu, 23 Jul 2015 06:13:43 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id F34C120694 for ; Thu, 23 Jul 2015 06:13:41 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 2098D265C96; Thu, 23 Jul 2015 08:13:41 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_NONE, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=no version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id 84B0F264F40; Thu, 23 Jul 2015 08:08:44 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 162182614E2; Thu, 23 Jul 2015 00:42:46 +0200 (CEST) Received: from resqmta-po-03v.sys.comcast.net (resqmta-po-03v.sys.comcast.net [96.114.154.162]) by alsa0.perex.cz (Postfix) with ESMTP id 6E11E26070F for ; Thu, 23 Jul 2015 00:42:36 +0200 (CEST) Received: from resomta-po-14v.sys.comcast.net ([96.114.154.238]) by resqmta-po-03v.sys.comcast.net with comcast id vaib1q00B58ss0Y01aibWb; Wed, 22 Jul 2015 22:42:35 +0000 Received: from mail.gonehiking.org ([73.181.52.62]) by resomta-po-14v.sys.comcast.net with comcast id vaiZ1q0011LXgTt01aiZ1B; Wed, 22 Jul 2015 22:42:35 +0000 Received: from lorien.internal (lorien-wl.internal [192.168.1.40]) by mail.gonehiking.org (Postfix) with ESMTP id 784F1120446; Wed, 22 Jul 2015 16:42:32 -0600 (MDT) From: Shuah Khan To: mchehab@osg.samsung.com, hans.verkuil@cisco.com, laurent.pinchart@ideasonboard.com, tiwai@suse.de, sakari.ailus@linux.intel.com, perex@perex.cz, crope@iki.fi, arnd@arndb.de, stefanr@s5r6.in-berlin.de, ruchandani.tina@gmail.com, chehabrafael@gmail.com, dan.carpenter@oracle.com, prabhakar.csengg@gmail.com, chris.j.arges@canonical.com, agoode@google.com, pierre-louis.bossart@linux.intel.com, gtmkramer@xs4all.nl, clemens@ladisch.de, daniel@zonque.org, vladcatoi@gmail.com, misterpib@gmail.com, damien@zamaudio.com, pmatilai@laiskiainen.org, takamichiho@gmail.com, normalperson@yhbt.net, bugzilla.frnkcg@spamgourmet.com, joe@oampo.co.uk, calcprogrammer1@gmail.com, jussi@sonarnerd.net, kyungmin.park@samsung.com, s.nawrocki@samsung.com, kgene@kernel.org, hyun.kwon@xilinx.com, michal.simek@xilinx.com, soren.brinkmann@xilinx.com, pawel@osciak.com, m.szyprowski@samsung.com, gregkh@linuxfoundation.org, skd08@gmail.com, nsekhar@ti.com, boris.brezillon@free-electrons.com, Julia.Lawall@lip6.fr, elfring@users.sourceforge.net, p.zabel@pengutronix.de, ricardo.ribalda@gmail.com Date: Wed, 22 Jul 2015 16:42:03 -0600 Message-Id: <21da4006a0f95ec7aad81539e58df5ef04a173cb.1437599281.git.shuahkh@osg.samsung.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: References: In-Reply-To: References: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcast.net; s=q20140121; t=1437604955; bh=4xJ2GWZE1fYoHwQ15aEU71+zOi8wfbi1XzO4+Kf4fA0=; h=Received:Received:Received:From:To:Subject:Date:Message-Id; b=iXJlJkLD3SCLYil7YoI89uzk1wvvOI5HZ0o/HNK8QmKKH/WP/+i8Jo01i29fZ1gRR LTSHrVU0NTsfH7yTQ1CrFn8X4Cirpfl1qFO0CHlaX5fvV4965P3R5mATfl3KQrfWtU DYIPMWnryn3j3ey1+P4sxG9jMIT3ceuWTaReqMFS7Po0lTH98PxukjhICc3rcdZ/+R tG8A2IUwkRtefwcSTidEjKa5iy6Y+p7ntahoh9WhrXz1pIh9ZBvX8uGzUpmdgpj5J8 RaZnf3HKwETzET1ainmPH0TlYChLSmCc8TgYEJr/4bgBCXjkQI14PijO+nC+y4xYL2 WqLeQmDqq8Abg== X-Mailman-Approved-At: Thu, 23 Jul 2015 08:08:33 +0200 Cc: devel@driverdev.osuosl.org, alsa-devel@alsa-project.org, linux-samsung-soc@vger.kernel.org, Shuah Khan , linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org Subject: [alsa-devel] [PATCH v2 02/19] media: Media Controller register/unregister entity_notify API X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP Add new interfaces to register and unregister entity_notify hook to media device to allow drivers to take appropriate actions when as new entities get added to the shared media device.When a new entity is registered, all registered entity_notify hooks are invoked to allow drivers or modules that registered hook to take appropriate action. For example, ALSA driver registers an entity_notify hook to parse the list of registered entities to determine if decoder has been linked to ALSA entity. au0828 bridge driver registers an entity_notify hook to create media graph for the device. Signed-off-by: Shuah Khan --- drivers/media/media-device.c | 45 ++++++++++++++++++++++++++++++++++++++++++++ include/media/media-device.h | 23 ++++++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c index c55ab50..22565a8 100644 --- a/drivers/media/media-device.c +++ b/drivers/media/media-device.c @@ -381,6 +381,7 @@ int __must_check __media_device_register(struct media_device *mdev, mdev->entity_id = 1; INIT_LIST_HEAD(&mdev->entities); + INIT_LIST_HEAD(&mdev->entity_notify); spin_lock_init(&mdev->lock); mutex_init(&mdev->graph_mutex); @@ -411,9 +412,12 @@ void media_device_unregister(struct media_device *mdev) { struct media_entity *entity; struct media_entity *next; + struct media_entity_notify *notify, *nextp; list_for_each_entry_safe(entity, next, &mdev->entities, list) media_device_unregister_entity(entity); + list_for_each_entry_safe(notify, nextp, &mdev->entity_notify, list) + media_device_unregister_entity_notify(mdev, notify); device_remove_file(&mdev->devnode.dev, &dev_attr_model); media_devnode_unregister(&mdev->devnode); @@ -421,6 +425,39 @@ void media_device_unregister(struct media_device *mdev) EXPORT_SYMBOL_GPL(media_device_unregister); /** + * media_device_register_entity_notify - Register a media entity notify + * callback with a media device. When a new entity is registered, all + * the registered media_entity_notify callbacks are invoked. + * @mdev: The media device + * @nptr: The media_entity_notify + */ +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); + +/** + * media_device_unregister_entity_notify - Unregister a media entity notify + * callback with a media device. When a new entity is registered, all + * the registered media_entity_notify callbacks are invoked. + * @mdev: The media device + * @nptr: The media_entity_notify + */ +void media_device_unregister_entity_notify(struct media_device *mdev, + struct media_entity_notify *nptr) +{ + spin_lock(&mdev->lock); + list_del(&nptr->list); + spin_unlock(&mdev->lock); +} +EXPORT_SYMBOL_GPL(media_device_unregister_entity_notify); + +/** * media_device_register_entity - Register an entity with a media device * @mdev: The media device * @entity: The entity @@ -428,6 +465,8 @@ EXPORT_SYMBOL_GPL(media_device_unregister); int __must_check media_device_register_entity(struct media_device *mdev, struct media_entity *entity) { + struct media_entity_notify *notify, *next; + /* Warn if we apparently re-register an entity */ WARN_ON(entity->parent != NULL); entity->parent = mdev; @@ -440,6 +479,11 @@ int __must_check media_device_register_entity(struct media_device *mdev, list_add_tail(&entity->list, &mdev->entities); spin_unlock(&mdev->lock); + /* invoke entity_notify callbacks */ + list_for_each_entry_safe(notify, next, &mdev->entity_notify, list) { + (notify)->notify(entity, notify->notify_data); + } + return 0; } EXPORT_SYMBOL_GPL(media_device_register_entity); @@ -462,6 +506,7 @@ void media_device_unregister_entity(struct media_entity *entity) list_del(&entity->list); spin_unlock(&mdev->lock); entity->parent = NULL; + /* invoke entity_notify callbacks to handle entity removal?? */ } EXPORT_SYMBOL_GPL(media_device_unregister_entity); diff --git a/include/media/media-device.h b/include/media/media-device.h index a44f18f..a3854f6 100644 --- a/include/media/media-device.h +++ b/include/media/media-device.h @@ -32,6 +32,12 @@ struct 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 * @dev: Parent device @@ -70,6 +76,8 @@ struct media_device { u32 entity_id; struct list_head entities; + /* notify callback list invoked when a new entity is registered */ + struct list_head entity_notify; /* Protects the entities list */ spinlock_t lock; @@ -94,6 +102,10 @@ int __must_check __media_device_register(struct media_device *mdev, #define media_device_register(mdev) __media_device_register(mdev, THIS_MODULE) void media_device_unregister(struct media_device *mdev); +int __must_check media_device_register_entity_notify(struct media_device *mdev, + struct media_entity_notify *nptr); +void media_device_unregister_entity_notify(struct media_device *mdev, + struct media_entity_notify *nptr); int __must_check media_device_register_entity(struct media_device *mdev, struct media_entity *entity); void media_device_unregister_entity(struct media_entity *entity); @@ -112,6 +124,17 @@ static inline int media_device_register(struct media_device *mdev) static inline void media_device_unregister(struct media_device *mdev) { } +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 int media_device_register_entity(struct media_device *mdev, struct media_entity *entity) {