Update ALSA, and au0828 drivers to use Managed Media Controller API
Subsystems (3)
cover Update ALSA, and au0828 drivers to use Managed Media Controller API
s patch series updates ALSA driver, and au0828 core driver to use Managed Media controller API to share tuner. Please note that Managed Media Controller API and DVB and V4L2 drivers updates to use Media Controller API have been added in a prior patch series.
Media Controller API is enhanced with two new interfaces to register and unregister entity_notify hooks to allow drivers to take appropriate actions when as new entities get added to the shared media device.
Tested exclusion between digital, analog, and audio to ensure when tuner has an active link to DVB FE, analog, and audio will detect and honor the tuner busy conditions and vice versa.
This patch series has been updated to address comments from 3 previous versions of this series. Link to v3 below for reference.
https://www.mail-archive.com/linux-media%40vger.kernel.org/msg89491.html
https://www.mail-archive.com/[email protected]/msg89492.html
https://www.mail-archive.com/linux-media%40vger.kernel.org/msg89493.html
Open Issues:
ALSA has makes media_entity_pipeline_start() call in irq path. I am seeing warnings that the graph_mutex is unsafe irq lock. Media Controller API updates to start/stop pipeline to be irq safe might be necessary. Maybe there are other MC interfaces that need to be irq safe, but I haven't seen any problems with my testing.
So as per options, graph_mutex could be changed to a spinlock. It looks like drivers hold this lock and it isn't abstracted to MC API. Unfortunate, this would require changes to drivers that directly hold the lock for graph walks if this mutex is changed to spinlock. This issue needs to be resolved.
Note: This series includes a revert to a patch that added media controller entity framework enhancements that implemented entity ops for entity_notify functionality. Entity ops for entity_notify doesn't handle and cover entity create ordering variations that could occur during boot. entity_notify list has been moved to media device level which makes the entity_notify calls to work correctly.
Shuah Khan (7):
Revert "[media] media: media controller entity framework enhancements
for ALSA"
media: Media Controller register/unregister entity_notify API
media: Add ALSA Media Controller devnodes
media: change dvb-frontend to honor MC tuner enable error
media: au8522 change to create MC pad for ALSA Audio Out
media: au0828 change to use Managed Media Controller API sound/usb: Update ALSA driver to use Managed Media Controller API
drivers/media/dvb-core/dvb_frontend.c | 5 +- drivers/media/dvb-frontends/au8522.h | 8 + drivers/media/dvb-frontends/au8522_decoder.c | 1 + drivers/media/dvb-frontends/au8522_priv.h | 8 - drivers/media/media-device.c | 46 ++++- drivers/media/usb/au0828/au0828-core.c | 132 ++++++++------ drivers/media/usb/au0828/au0828.h | 5 + include/media/media-device.h | 23 +++ include/media/media-entity.h | 4 - include/uapi/linux/media.h | 5 + sound/usb/Makefile | 15 +- sound/usb/card.c | 5 + sound/usb/card.h | 1 + sound/usb/media.c | 260 +++++++++++++++++++++++++++ sound/usb/media.h | 52 ++++++ sound/usb/pcm.c | 15 +- sound/usb/quirks-table.h | 1 + sound/usb/quirks.c | 9 +- sound/usb/stream.c | 2 + sound/usb/usbaudio.h | 1 + 20 files changed, 523 insertions(+), 75 deletions(-) create mode 100644 sound/usb/media.c create mode 100644 sound/usb/media.h
Signature · 1 line
2.1.4
PATCH 1/7 Revert "[media] media: media controller entity framework enhancements for ALSA"
This reverts commit ed64cf1e182fb30fe67652386c0880fcf3302f97. This patch is no longer necessary as the entity register callback is implemented at media_device level.
--- drivers/media/media-device.c | 7 ------- include/media/media-entity.h | 4 ---- 2 files changed, 11 deletions(-)
drivers/media/media-device.c +0 -7
@@ -428,8 +428,6 @@ EXPORT_SYMBOL_GPL(media_device_unregister);int __must_check media_device_register_entity (struct media_device *mdev,struct media_entity *entity) { -struct media_entity *eptr; -/* Warn if we apparently re-register an entity */ WARN_ON (entity->parent !=NULL ); entity->parent = mdev;
@@ -442,11 +440,6 @@ int __must_check media_device_register_entity(struct media_device *mdev,list_add_tail (&entity->list, &mdev->entities);spin_unlock (&mdev->lock); -media_device_for_each_entity (eptr, mdev) { -if (eptr != entity) -media_entity_call (eptr, register_notify); - } -return 0 ; }EXPORT_SYMBOL_GPL (media_device_register_entity);
include/media/media-entity.h +0 -4
@@ -46,7 +46,6 @@ struct media_pad {/** * struct media_entity_operations - Media entity operations -* @register_notify Notify entity of newly registered entity * @link_setup: Notify the entity of link changes. The operation can * return an error, in which case link setup will be * cancelled. Optional.
@@ -55,7 +54,6 @@ struct media_pad {* validates all links by calling this operation. Optional. */ struct media_entity_operations { -int (*register_notify)(struct media_entity *entity);int (*link_setup)(struct media_entity *entity,const struct media_pad *local,const struct media_pad *remote,u32 flags);
@@ -103,8 +101,6 @@ struct media_entity {/* Sub-device specifications */ /* Nothing needed yet */ } info; - -void *private;/* private data for the entity */ };static inline u32 media_entity_type (struct media_entity *entity)
Signature · 1 line
2.1.4
PATCH 2/7 media: Media Controller register/unregister entity_notify API
In reply to Shuah KhanAdd 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.
--- drivers/media/media-device.c | 45 ++++++++++++++++++++++++++++++++++++++++++++ include/media/media-device.h | 23 ++++++++++++++++++++++ 2 files changed, 68 insertions(+)
drivers/media/media-device.c +45 -0
@@ -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);
include/media/media-device.h +23 -0
@@ -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) {
Signature · 1 line
2.1.4
PATCH 3/7 media: Add ALSA Media Controller devnodes
In reply to Shuah KhanAdd ALSA Media Controller capture, playback, and mixer devnode defines.
--- include/uapi/linux/media.h | 5 +++++ 1 file changed, 5 insertions(+)
include/uapi/linux/media.h +5 -0
@@ -49,12 +49,17 @@ struct media_device_info {#define MEDIA_ENT_T_DEVNODE (1 << MEDIA_ENT_TYPE_SHIFT)#define MEDIA_ENT_T_DEVNODE_V4L (MEDIA_ENT_T_DEVNODE + 1)#define MEDIA_ENT_T_DEVNODE_FB (MEDIA_ENT_T_DEVNODE + 2) +/* Legacy ALSA symbol. Keep it to avoid userspace compilation breakages */ #define MEDIA_ENT_T_DEVNODE_ALSA (MEDIA_ENT_T_DEVNODE + 3)#define MEDIA_ENT_T_DEVNODE_DVB_FE (MEDIA_ENT_T_DEVNODE + 4)#define MEDIA_ENT_T_DEVNODE_DVB_DEMUX (MEDIA_ENT_T_DEVNODE + 5)#define MEDIA_ENT_T_DEVNODE_DVB_DVR (MEDIA_ENT_T_DEVNODE + 6)#define MEDIA_ENT_T_DEVNODE_DVB_CA (MEDIA_ENT_T_DEVNODE + 7)#define MEDIA_ENT_T_DEVNODE_DVB_NET (MEDIA_ENT_T_DEVNODE + 8) +/* ALSA devnodes */ +#define MEDIA_ENT_T_DEVNODE_ALSA_CAPTURE (MEDIA_ENT_T_DEVNODE + 9) +#define MEDIA_ENT_T_DEVNODE_ALSA_PLAYBACK (MEDIA_ENT_T_DEVNODE + 10) +#define MEDIA_ENT_T_DEVNODE_ALSA_MIXER (MEDIA_ENT_T_DEVNODE + 11)/* Legacy symbol. Use it to avoid userspace compilation breakages */ #define MEDIA_ENT_T_DEVNODE_DVB MEDIA_ENT_T_DEVNODE_DVB_FE
Signature · 1 line
2.1.4
PATCH 4/7 media: change dvb-frontend to honor MC tuner enable error
In reply to Shuah KhanChange dvb_frontend_thread() to honor MC tuner enable error and return as opposed to ignoring the error and continuing to use it.
--- drivers/media/dvb-core/dvb_frontend.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/media/dvb-core/dvb_frontend.c +2 -3
@@ -713,9 +713,8 @@ static int dvb_frontend_thread(void *data)#ifdef CONFIG_MEDIA_CONTROLLER_DVB ret =dvb_enable_media_tuner (fe);if (ret) { -/* FIXME: return an error if it fails */ -dev_info (fe->dvb->device, -"proceeding with FE task\n" ); +dev_err (fe->dvb->device,"Tuner is busy. Error %d\n" , ret); +return ret; }else if (fepriv->pipe_start_entity) { ret =media_entity_pipeline_start (fepriv->pipe_start_entity, &fepriv->pipe);
Signature · 1 line
2.1.4
PATCH 5/7 media: au8522 change to create MC pad for ALSA Audio Out
In reply to Shuah KhanAdd new pad for ALSA Audio Out to au8522_media_pads. Move the au8522_media_pads enum to au8522.h from au8522_priv.h. This will allow au0828-core to use these defines instead of hard-coding the pad values when it creates media graph linking decode pads to other entities.
--- drivers/media/dvb-frontends/au8522.h | 8 ++++++++ drivers/media/dvb-frontends/au8522_decoder.c | 1 + drivers/media/dvb-frontends/au8522_priv.h | 8 -------- 3 files changed, 9 insertions(+), 8 deletions(-)
drivers/media/dvb-frontends/au8522.h +8 -0
@@ -90,4 +90,12 @@ enum au8522_audio_input { AU8522_AUDIO_SIF, }; +enum au8522_media_pads { +AU8522_PAD_INPUT , +AU8522_PAD_VID_OUT , +AU8522_PAD_VBI_OUT , +AU8522_PAD_AUDIO_OUT , + +AU8522_NUM_PADS +};#endif /* __AU8522_H__ */
drivers/media/dvb-frontends/au8522_decoder.c +1 -0
@@ -775,6 +775,7 @@ static int au8522_probe(struct i2c_client *client, state->pads[AU8522_PAD_INPUT ].flags =MEDIA_PAD_FL_SINK ; state->pads[AU8522_PAD_VID_OUT ].flags =MEDIA_PAD_FL_SOURCE ; state->pads[AU8522_PAD_VBI_OUT ].flags =MEDIA_PAD_FL_SOURCE ; + state->pads[AU8522_PAD_AUDIO_OUT ].flags =MEDIA_PAD_FL_SINK ; sd->entity.type =MEDIA_ENT_T_V4L2_SUBDEV_DECODER ; ret = media_entity_init(&sd->entity, ARRAY_SIZE(state->pads),
drivers/media/dvb-frontends/au8522_priv.h +0 -8
@@ -39,14 +39,6 @@#define AU8522_DIGITAL_MODE 1#define AU8522_SUSPEND_MODE 2 -enum au8522_media_pads { -AU8522_PAD_INPUT , -AU8522_PAD_VID_OUT , -AU8522_PAD_VBI_OUT , - -AU8522_NUM_PADS -}; -struct au8522_state {struct i2c_client *c;struct i2c_adapter *i2c;
Signature · 1 line
2.1.4
PATCH 6/7 media: au0828 change to use Managed Media Controller API
In reply to Shuah KhanChange au0828 to use Managed Media Controller API to coordinate creating/deleting media device on parent usb device it shares with the snd-usb-audio driver. With this change, au0828 uses media_device_get_devres() to allocate a new media device devres or return an existing one, if it finds one.
In addition, au0828 registers entity_notify hook to create media graph for the device. It creates necessary links from video, vbi, and ALSA entities to decoder and links tuner and decoder entities.
--- drivers/media/usb/au0828/au0828-core.c | 132 ++++++++++++++++++++------------- drivers/media/usb/au0828/au0828.h | 5 ++ 2 files changed, 85 insertions(+), 52 deletions(-)
drivers/media/usb/au0828/au0828-core.c +80 -52
@@ -20,6 +20,7 @@*/ #include "au0828.h" +#include "au8522.h" #include <linux/module.h> #include <linux/slab.h>
@@ -131,10 +132,12 @@ static void au0828_unregister_media_device(struct au0828_dev *dev) {#ifdef CONFIG_MEDIA_CONTROLLER -if (dev->media_dev) { -media_device_unregister (dev->media_dev); -kfree (dev->media_dev); - dev->media_dev =NULL ; +if (dev->media_dev && +media_devnode_is_registered (&dev->media_dev->devnode)) { +media_device_unregister_entity_notify (dev->media_dev, + &dev->entity_notify); +media_device_unregister (dev->media_dev); + dev->media_dev =NULL ; }#endif }
@@ -196,53 +199,23 @@ static void au0828_usb_disconnect(struct usb_interface *interface)au0828_usb_release (dev); } -static void au0828_media_device_register (struct au0828_dev *dev, -struct usb_device *udev) -{ -#ifdef CONFIG_MEDIA_CONTROLLER -struct media_device *mdev; -int ret; - - mdev =kzalloc (sizeof (*mdev),GFP_KERNEL ); -if (!mdev) -return ; - - mdev->dev = &udev->dev; - -if (!dev->board.name) -strlcpy (mdev->model,"unknown au0828" ,sizeof (mdev->model)); -else -strlcpy (mdev->model, dev->board.name,sizeof (mdev->model)); -if (udev->serial) -strlcpy (mdev->serial, udev->serial,sizeof (mdev->serial)); -strcpy (mdev->bus_info, udev->devpath); - mdev->hw_revision =le16_to_cpu (udev->descriptor.bcdDevice); - mdev->driver_version =LINUX_VERSION_CODE ; - - ret =media_device_register (mdev); -if (ret) { -pr_err ( -"Couldn't create a media device. Error: %d\n" , - ret); -kfree (mdev); -return ; - } - - dev->media_dev = mdev; -#endif -} - - -static void au0828_create_media_graph (struct au0828_dev *dev) +void au0828_create_media_graph (struct media_entity *new,void *notify_data) {#ifdef CONFIG_MEDIA_CONTROLLER +struct au0828_dev *dev = (struct au0828_dev *) notify_data;struct media_device *mdev = dev->media_dev;struct media_entity *entity;struct media_entity *tuner =NULL , *decoder =NULL ; +struct media_entity *alsa_capture =NULL ; +int ret =0 ;if (!mdev)return ; +if (dev->tuner_linked && dev->vdev_linked && dev->vbi_linked && + dev->alsa_capture_linked) +return ; +media_device_for_each_entity (entity, mdev) {switch (entity->type) {case MEDIA_ENT_T_V4L2_SUBDEV_TUNER :
@@ -251,6 +224,9 @@ static void au0828_create_media_graph(struct au0828_dev *dev)case MEDIA_ENT_T_V4L2_SUBDEV_DECODER : decoder = entity;break ; +case MEDIA_ENT_T_DEVNODE_ALSA_CAPTURE : + alsa_capture = entity; +break ; } }
@@ -259,15 +235,69 @@ static void au0828_create_media_graph(struct au0828_dev *dev)if (!decoder)return ; -if (tuner) -media_entity_create_link (tuner,0 , decoder,0 , +if (tuner && !dev->tuner_linked) { + ret =media_entity_create_link (tuner,0 , decoder,0 ,MEDIA_LNK_FL_ENABLED ); -if (dev->vdev.entity.links) -media_entity_create_link (decoder,1 , &dev->vdev.entity,0 , -MEDIA_LNK_FL_ENABLED ); -if (dev->vbi_dev.entity.links) -media_entity_create_link (decoder,2 , &dev->vbi_dev.entity,0 , -MEDIA_LNK_FL_ENABLED ); +if (ret ==0 ) + dev->tuner_linked =1 ; + } +if (dev->vdev.entity.links && !dev->vdev_linked) { + ret =media_entity_create_link (decoder,AU8522_PAD_VID_OUT , + &dev->vdev.entity,0 ,MEDIA_LNK_FL_ENABLED ); +if (ret ==0 ) + dev->vdev_linked =1 ; + } +if (dev->vbi_dev.entity.links && !dev->vbi_linked) { + ret =media_entity_create_link (decoder,AU8522_PAD_VBI_OUT , + &dev->vbi_dev.entity,0 ,MEDIA_LNK_FL_ENABLED ); +if (ret ==0 ) + dev->vbi_linked =1 ; + } +if (alsa_capture && !dev->alsa_capture_linked) { + ret =media_entity_create_link (decoder,AU8522_PAD_AUDIO_OUT , + alsa_capture,0 , +MEDIA_LNK_FL_ENABLED ); +if (ret ==0 ) + dev->alsa_capture_linked =1 ; + } +#endif +} + +static void au0828_media_device_register (struct au0828_dev *dev, +struct usb_device *udev) +{ +#ifdef CONFIG_MEDIA_CONTROLLER +struct media_device *mdev; +int ret; + + mdev =media_device_get_devres (&udev->dev); +if (!mdev) +return ; + +if (!media_devnode_is_registered (&mdev->devnode)) { +/* register media device */ + mdev->dev = &udev->dev; +if (udev->product) +strlcpy (mdev->model, udev->product, +sizeof (mdev->model)); +if (udev->serial) +strlcpy (mdev->serial, udev->serial, +sizeof (mdev->serial)); +strcpy (mdev->bus_info, udev->devpath); + mdev->hw_revision =le16_to_cpu (udev->descriptor.bcdDevice); + ret =media_device_register (mdev); +if (ret) { +dev_err (&udev->dev, +"Couldn't create a media device. Error: %d\n" , + ret); +return ; + } +/* register entity_notify callback */ + dev->entity_notify.notify_data = (void *) dev; + dev->entity_notify.notify = au0828_create_media_graph; +media_device_register_entity_notify (mdev, &dev->entity_notify); + } + dev->media_dev = mdev;#endif }
@@ -383,8 +413,6 @@ static int au0828_usb_probe(struct usb_interface *interface,mutex_unlock (&dev->lock); -au0828_create_media_graph (dev); -return retval; }
drivers/media/usb/au0828/au0828.h +5 -0
@@ -281,6 +281,11 @@ struct au0828_dev {struct media_device *media_dev;struct media_pad video_pad, vbi_pad;struct media_entity *decoder; +struct media_entity_notify entity_notify; +bool tuner_linked; +bool vdev_linked; +bool vbi_linked; +bool alsa_capture_linked;#endif };
Signature · 1 line
2.1.4
Re: [PATCH 6/7] media: au0828 change to use Managed Media Controller API
Sorry for this nit-pick and some time after you sent this patch. It's not a redo the patch" complaint, it's something that could be fixed later.
Quoted 4 lines · Shuah Khan
drivers/media/usb/au0828/au0828-core.c +0
-0@@ -131,10 +132,12 @@ static void au0828_unregister_media_device(struct au0828_dev *dev) {#ifdef CONFIG_MEDIA_CONTROLLER
drivers/media/usb/au0828/au0828-core.c static void au0828_unregister_media_device(struct au0828_dev *dev) · line 140
Quoted 10 lines
drivers/media/usb/au0828/au0828-core.c +6
-4-if (dev->media_dev) { -media_device_unregister (dev->media_dev); -kfree (dev->media_dev); - dev->media_dev =NULL ; +if (dev->media_dev && +media_devnode_is_registered (&dev->media_dev->devnode)) { +media_device_unregister_entity_notify (dev->media_dev, + &dev->entity_notify); +media_device_unregister (dev->media_dev); + dev->media_dev =NULL ;
The indenting is slightly off here. It should be:
if (dev->media_dev &&
media_devnode_is_registered(&dev->media_dev->devnode)) {
media_device_unregister_entity_notify(dev->media_dev,
&dev->entity_notify);
media_device_unregister(dev->media_dev);
dev->media_dev = NULL;
}Aligning if statements using spaces like that is nicer and checkpatch.pl won't complain.
regards,
dan carpenter
Re: [PATCH 6/7] media: au0828 change to use Managed Media Controller API
Quoted 31 lines · Dan Carpenter
Sorry for this nit-pick and some time after you sent this patch. It's not a redo the patch" complaint, it's something that could be fixed later.
Quoted 4 lines · Shuah Khan
drivers/media/usb/au0828/au0828-core.c +0
-0@@ -131,10 +132,12 @@ static void au0828_unregister_media_device(struct au0828_dev *dev) {#ifdef CONFIG_MEDIA_CONTROLLER drivers/media/usb/au0828/au0828-core.c static void au0828_unregister_media_device(struct au0828_dev *dev) · line 140
Quoted 10 lines
drivers/media/usb/au0828/au0828-core.c +6
-4-if (dev->media_dev) { -media_device_unregister (dev->media_dev); -kfree (dev->media_dev); - dev->media_dev =NULL ; +if (dev->media_dev && +media_devnode_is_registered (&dev->media_dev->devnode)) { +media_device_unregister_entity_notify (dev->media_dev, + &dev->entity_notify); +media_device_unregister (dev->media_dev); + dev->media_dev =NULL ;The indenting is slightly off here. It should be:
if (dev->media_dev && media_devnode_is_registered(&dev->media_dev->devnode)) { media_device_unregister_entity_notify(dev->media_dev, &dev->entity_notify); media_device_unregister(dev->media_dev); dev->media_dev = NULL; }
Quoted 3 lines
Aligning if statements using spaces like that is nicer and checkpatch.pl won't complain.
Yeah. I try to do that whenever. In this case, if I align, the line becomes longer than 80 chars adding more things to worry about. In such cases, I tend to not worry about aligning.
thanks,
-- Shuah
Signature · 5 lines
Shuah Khan Sr. Linux Kernel Developer Open Source Innovation Group Samsung Research America (Silicon Valley) [email protected] | (970) 217-8978
Re: [PATCH 6/7] media: au0828 change to use Managed Media Controller API
Quoted 23 lines · Shuah Khan
Quoted 23 lines
drivers/media/usb/au0828/au0828-core.c static void au0828_unregister_media_device(struct au0828_dev *dev) · line 140
Quoted 11 lines
#ifdef
CONFIG_MEDIA_CONTROLLERdrivers/media/usb/au0828/au0828-core.c +6
-4-if (dev->media_dev) { -media_device_unregister (dev->media_dev); -kfree (dev->media_dev); - dev->media_dev =NULL ; +if (dev->media_dev && +media_devnode_is_registered (&dev->media_dev->devnode)) { +media_device_unregister_entity_notify (dev->media_dev, + &dev->entity_notify); +media_device_unregister (dev->media_dev); + dev->media_dev =NULL ;The indenting is slightly off here. It should be:
if (dev->media_dev && media_devnode_is_registered(&dev->media_dev->devnode)) { media_device_unregister_entity_notify(dev->media_dev, &dev->entity_notify); media_device_unregister(dev->media_dev); dev->media_dev = NULL; }
Quoted 7 lines
Quoted 3 lines
Aligning if statements using spaces like that is nicer and checkpatch.pl won't complain.
Yeah. I try to do that whenever. In this case, if I align, the line becomes longer than 80 chars adding more things to worry about. In such cases, I tend to not worry about aligning.
The main thing is that the body of the if statement is intended 16 spaces instead of 8. Otherwise I wouldn't have commented.
regards,
dan carpenter
Re: [PATCH 6/7] media: au0828 change to use Managed Media Controller API
Quoted 28 lines · Dan Carpenter
Quoted 27 lines · Shuah Khan
Quoted 26 lines
drivers/media/usb/au0828/au0828-core.c static void au0828_unregister_media_device(struct au0828_dev *dev) · line 140
Quoted 11 lines
#ifdef
CONFIG_MEDIA_CONTROLLERdrivers/media/usb/au0828/au0828-core.c +6
-4-if (dev->media_dev) { -media_device_unregister (dev->media_dev); -kfree (dev->media_dev); - dev->media_dev =NULL ; +if (dev->media_dev && +media_devnode_is_registered (&dev->media_dev->devnode)) { +media_device_unregister_entity_notify (dev->media_dev, + &dev->entity_notify); +media_device_unregister (dev->media_dev); + dev->media_dev =NULL ;The indenting is slightly off here. It should be:
if (dev->media_dev && media_devnode_is_registered(&dev->media_dev->devnode)) { media_device_unregister_entity_notify(dev->media_dev, &dev->entity_notify); media_device_unregister(dev->media_dev); dev->media_dev = NULL; }Aligning if statements using spaces like that is nicer and checkpatch.pl won't complain.
Quoted 7 lines
Quoted 3 lines
Yeah. I try to do that whenever. In this case, if I align, the line becomes longer than 80 chars adding more things to worry about. In such cases, I tend to not worry about aligning.
The main thing is that the body of the if statement is intended 16 spaces instead of 8. Otherwise I wouldn't have commented.
Yes. I see what you are saying. I will fix it in v2 series.
thanks,
-- Shuah
Signature · 5 lines
Shuah Khan Sr. Linux Kernel Developer Open Source Innovation Group Samsung Research America (Silicon Valley) [email protected] | (970) 217-8978
PATCH 7/7 sound/usb: Update ALSA driver to use Managed Media Controller API
In reply to Shuah KhanChange ALSA driver to use Managed ~media Managed Controller API to share tuner with DVB and V4L2 drivers that control AU0828 media device. Media device is created based on a newly added field value in the struct snd_usb_audio_quirk. Using this approach, the media controller API usage can be added for a specific device. In this patch, Media Controller API is enabled for AU0828 hw. snd_usb_create_quirk() will check this new field, if set will create a media device using media_device_get_devres() interface.
media_device_get_devres() will allocate a new media device devres or return an existing one, if it finds one.
During probe, media usb driver could have created the media device devres. It will then register the media device if it isn't already registered. Media device unregister is done from usb_audio_disconnect().
During probe, media usb driver could have created the media device devres. It will then register the media device if it isn't already registered. Media device unregister is done from usb_audio_disconnect().
New structure media_ctl is added to group the new fields to support media entity and links. This new structure is added to struct snd_usb_substream.
A new entity_notify hook and a new ALSA capture media entity are registered from snd_usb_pcm_open() after setting up hardware information for the PCM device.
When a new entity is registered, Media Controller API interface media_device_register_entity() invokes all registered entity_notify hooks for the media device. ALSA entity_notify hook parses all the entity list to find a link from decoder it ALSA entity. This indicates that the bridge driver created a link from decoder to ALSA capture entity. At this time, ALSA will attempt to enable the tuner to link the tuner to the decoder calling media_entity_setup_link(). media_entity_setup_link() will either return success activating tuner to decoder link or error if it tuner is busy.
Media pipeline gets started to mark the tuner busy from snd_usb_substream_capture_trigger() in response to SNDRV_PCM_TRIGGER_START and pipeline is stopped in response to SNDRV_PCM_TRIGGER_STOP. snd_usb_pcm_close() stops pipeline to cover the case when SNDRV_PCM_TRIGGER_STOP isn't issued. Pipeline start and stop are done only when decoder_linked is set. Tuner enable step could be done from snd_usb_substream_capture_trigger(). The reason it is done from snd_usb_pcm_open() is that it reduces the work that is needed from snd_usb_substream_capture_trigger().
There is an open issue with graph_mutex hold in Media Controller media_entity_pipeline_start() and media_entity_pipeline_stop() API. snd-us-audio calls these from snd_usb_substream_capture_trigger() which could be called in irq path. This issue needs to be resolved before this patch can go in.
--- sound/usb/Makefile | 15 ++- sound/usb/card.c | 5 + sound/usb/card.h | 1 + sound/usb/media.c | 260 +++++++++++++++++++++++++++++++++++++++++++++++ sound/usb/media.h | 52 ++++++++++ sound/usb/pcm.c | 15 ++- sound/usb/quirks-table.h | 1 + sound/usb/quirks.c | 9 +- sound/usb/stream.c | 2 + sound/usb/usbaudio.h | 1 + 10 files changed, 357 insertions(+), 4 deletions(-) create mode 100644 sound/usb/media.c create mode 100644 sound/usb/media.h
sound/usb/Makefile +14 -1
@@ -2,6 +2,18 @@ # Makefile for ALSA # +# Media Controller +ifeq ($(CONFIG_MEDIA_CONTROLLER),y) + ifeq ($(CONFIG_MEDIA_SUPPORT),y) + KBUILD_CFLAGS += -DUSE_MEDIA_CONTROLLER + endif + ifeq ($(CONFIG_MEDIA_SUPPORT_MODULE),y) + ifeq ($(MODULE),y) + KBUILD_CFLAGS += -DUSE_MEDIA_CONTROLLER + endif + endif +endif + snd-usb-audio-objs := card.o \ clock.o \ endpoint.o \
@@ -13,7 +25,8 @@ snd-usb-audio-objs := card.o \ pcm.o \ proc.o \ quirks.o \ - stream.o + stream.o \ + media.o snd-usbmidi-lib-objs := midi.o
sound/usb/card.c +5 -0
@@ -66,6 +66,7 @@#include "format.h" #include "power.h" #include "stream.h" +#include "media.h" MODULE_AUTHOR ("Takashi Iwai <[email protected]>" );MODULE_DESCRIPTION ("USB Audio" );
@@ -619,6 +620,10 @@ static void usb_audio_disconnect(struct usb_interface *intf)list_for_each_entry (mixer, &chip->mixer_list, list) {snd_usb_mixer_disconnect (mixer); } +/* Nice to check quirk && quirk->media_device +* need some special handlings. Doesn't look like +* we have access to quirk here */ +media_device_delete (intf); } chip->num_interfaces--;
sound/usb/card.h +1 -0
@@ -155,6 +155,7 @@ struct snd_usb_substream { } dsd_dop;bool trigger_tstamp_pending_update;/* trigger timestamp being updated from initial estimate */ +void *media_ctl; };struct snd_usb_stream {
sound/usb/media.c new file +260 -0
260 lines not on this page · raw message
sound/usb/media.h new file +52 -0
52 lines not on this page · raw message
sound/usb/pcm.c +13 -2
@@ -35,6 +35,7 @@#include "pcm.h" #include "clock.h" #include "power.h" +#include "media.h" #define SUBSTREAM_FLAG_DATA_EP_STARTED 0#define SUBSTREAM_FLAG_SYNC_EP_STARTED 1
@@ -1195,6 +1196,7 @@ static int snd_usb_pcm_open(struct snd_pcm_substream *substream, int direction)struct snd_usb_stream *as =snd_pcm_substream_chip (substream);struct snd_pcm_runtime *runtime = substream->runtime;struct snd_usb_substream *subs = &as->substream[direction]; +int ret; subs->interface =-1 ; subs->altset_idx =0 ;
@@ -1208,7 +1210,10 @@ static int snd_usb_pcm_open(struct snd_pcm_substream *substream, int direction) subs->dsd_dop.channel =0 ; subs->dsd_dop.marker =1 ; -return setup_hw_info (runtime, subs); + ret =setup_hw_info (runtime, subs); +if (ret ==0 ) +media_stream_init (subs, as->pcm, direction); +return ret; }static int snd_usb_pcm_close (struct snd_pcm_substream *substream,int direction)
@@ -1587,9 +1592,14 @@ static int snd_usb_substream_capture_trigger(struct snd_pcm_substream *substreamswitch (cmd) {case SNDRV_PCM_TRIGGER_START : + err =media_start_pipeline (subs); +if (err) +return err; err =start_endpoints (subs, false); -if (err <0 ) +if (err <0 ) { +media_stop_pipeline (subs);return err; + } subs->data_endpoint->retire_data_urb = retire_capture_urb; subs->running =1 ;
@@ -1597,6 +1607,7 @@ static int snd_usb_substream_capture_trigger(struct snd_pcm_substream *substreamcase SNDRV_PCM_TRIGGER_STOP :stop_endpoints (subs, false); subs->running =0 ; +media_stop_pipeline (subs);return 0 ;case SNDRV_PCM_TRIGGER_PAUSE_PUSH : subs->data_endpoint->retire_data_urb =NULL ;
sound/usb/quirks-table.h +1 -0
@@ -2798,6 +2798,7 @@ YAMAHA_DEVICE(0x7010, "UB99"), .product_name = pname, \ .ifnum = QUIRK_ANY_INTERFACE, \ .type = QUIRK_AUDIO_ALIGN_TRANSFER, \ + .media_device = 1, \ } \ }
sound/usb/quirks.c +8 -1
@@ -36,6 +36,7 @@#include "pcm.h" #include "clock.h" #include "stream.h" +#include "media.h" /* * handle the quirks for the contained interfaces
@@ -541,13 +542,19 @@ int snd_usb_create_quirk(struct snd_usb_audio *chip, [QUIRK_AUDIO_ALIGN_TRANSFER] = create_align_transfer_quirk, [QUIRK_AUDIO_STANDARD_MIXER] = create_standard_mixer_quirk, }; +int ret; +if (quirk->media_device) { +/* don't want to fail when media_device_init() doesn't work */ +media_device_init (iface); + }if (quirk->type <QUIRK_TYPE_COUNT ) { -return quirk_funcs[quirk->type](chip, iface, driver, quirk); + ret = quirk_funcs[quirk->type](chip, iface, driver, quirk); }else {usb_audio_err (chip,"invalid quirk type %d\n" , quirk->type);return -ENXIO ; } +return ret; }/*
sound/usb/stream.c +2 -0
@@ -36,6 +36,7 @@#include "format.h" #include "clock.h" #include "stream.h" +#include "media.h" /* * free a substream
@@ -52,6 +53,7 @@ static void free_substream(struct snd_usb_substream *subs)kfree (fp); }kfree (subs->rate_list.list); +media_stream_delete (subs); }
sound/usb/usbaudio.h +1 -0
@@ -108,6 +108,7 @@ struct snd_usb_audio_quirk {const char *product_name;int16_t ifnum;uint16_t type; +bool media_device;const void *data; };
Signature · 1 line
2.1.4
Re: [PATCH 7/7] sound/usb: Update ALSA driver to use Managed Media Controller API
sound/usb/media.c line 165
Quoted 5 lines · Shuah Khan
sound/usb/media.c new file +5
-0+ ret =media_entity_setup_link (link, flags); +if (ret) { + dev_err(mctl->media_dev->dev, + "Couldn't change tuner link", + "%s->%s to %s. Error %d\n",
Add a space after "link".
"Couldn't change tuner link ", "%s->%s to %s. Error %d\n",
regards,
dan carpenter
Re: [PATCH 7/7] sound/usb: Update ALSA driver to use Managed Media Controller API
Quoted 10 lines · Dan Carpenter
sound/usb/media.c line 165
Quoted 5 lines · Shuah Khan
sound/usb/media.c new file +5
-0+ ret =media_entity_setup_link (link, flags); +if (ret) { + dev_err(mctl->media_dev->dev, + "Couldn't change tuner link", + "%s->%s to %s. Error %d\n",Add a space after "link".
Quoted 2 lines
"Couldn't change tuner link ", "%s->%s to %s. Error %d\n",
Such a message string would be better to be in a single line even if it's over 80 chars. Otherwise it becomes hard to grep.
thanks,
Takashi
Re: [PATCH 7/7] sound/usb: Update ALSA driver to use Managed Media Controller API
Quoted 12 lines · Takashi Iwai
Quoted 10 lines · Dan Carpenter
sound/usb/media.c line 165
Quoted 5 lines · Shuah Khan
sound/usb/media.c new file +5
-0+ ret =media_entity_setup_link (link, flags); +if (ret) { + dev_err(mctl->media_dev->dev, + "Couldn't change tuner link", + "%s->%s to %s. Error %d\n",Add a space after "link".
Quoted 6 lines
Quoted 2 lines
"Couldn't change tuner link ", "%s->%s to %s. Error %d\n",Such a message string would be better to be in a single line even if it's over 80 chars. Otherwise it becomes hard to grep.
Right. The above generates a warning and I found it after I sent the patch. I will have to re-do this patch to fix this. I prefer not splitting the message, but checkpatch compains if I don't.
thanks,
-- Shuah
Signature · 5 lines
Shuah Khan Sr. Linux Kernel Developer Open Source Innovation Group Samsung Research America (Silicon Valley) [email protected] | (970) 217-8978
PATCH 1/1 media-ctl: Update to add support for ALSA devices
In reply to Shuah KhanAdd support to recognize ALSA media nodes and generate media graph that includes ALSA pcm and mixer devices. This patch depends on kernel Media Controller changes to support ALSA.
--- utils/media-ctl/libmediactl.c | 18 ++++++++++++------ utils/media-ctl/media-ctl.c | 3 +++ utils/media-ctl/mediactl.h | 4 +++- 3 files changed, 18 insertions(+), 7 deletions(-)
utils/media-ctl/libmediactl.c +12 -6
@@ -153,7 +153,9 @@ struct media_entity *media_get_default_entity(struct media_device *media,return media->def.v4l;case MEDIA_ENT_T_DEVNODE_FB :return media->def.fb; -case MEDIA_ENT_T_DEVNODE_ALSA : +case MEDIA_ENT_T_DEVNODE_ALSA_CAPTURE : +case MEDIA_ENT_T_DEVNODE_ALSA_PLAYBACK : +case MEDIA_ENT_T_DEVNODE_ALSA_MIXER :return media->def.alsa;case MEDIA_ENT_T_DEVNODE_DVB_FE :case MEDIA_ENT_T_DEVNODE_DVB_DEMUX :
@@ -481,7 +483,6 @@ static int media_get_devname_sysfs(struct media_entity *entity)if (p ==NULL )return -EINVAL ; -sprintf (devname,"/dev/%s" , p +1 );if (strstr (p +1 ,"dvb" )) {char *s = p +1 ;
@@ -493,6 +494,8 @@ static int media_get_devname_sysfs(struct media_entity *entity)return -EINVAL ; *p ='/' ;sprintf (devname,"/dev/dvb/adapter%s" , s); + }else if (strstr (p +1 ,"pcm" ) ||strstr (p +1 ,"control" )) { +sprintf (devname,"/dev/snd/%s" , p +1 ); }else {sprintf (devname,"/dev/%s" , p +1 ); }
@@ -562,7 +565,9 @@ static int media_enum_entities(struct media_device *media)case MEDIA_ENT_T_DEVNODE_FB : media->def.fb = entity;break ; -case MEDIA_ENT_T_DEVNODE_ALSA : +case MEDIA_ENT_T_DEVNODE_ALSA_CAPTURE : +case MEDIA_ENT_T_DEVNODE_ALSA_PLAYBACK : +case MEDIA_ENT_T_DEVNODE_ALSA_MIXER : media->def.alsa = entity;break ;case MEDIA_ENT_T_DEVNODE_DVB_FE :
@@ -577,8 +582,7 @@ static int media_enum_entities(struct media_device *media)/* Find the corresponding device name. */ if (media_entity_type (entity) !=MEDIA_ENT_T_DEVNODE && -media_entity_type (entity) !=MEDIA_ENT_T_V4L2_SUBDEV && - entity->info.type ==MEDIA_ENT_T_DEVNODE_ALSA ) +media_entity_type (entity) !=MEDIA_ENT_T_V4L2_SUBDEV )continue ;/* Try to get the device name via udev */
@@ -774,7 +778,9 @@ int media_device_add_entity(struct media_device *media, defent = &media->def.fb; entity->info.fb = desc->fb;break ; -case MEDIA_ENT_T_DEVNODE_ALSA : +case MEDIA_ENT_T_DEVNODE_ALSA_CAPTURE : +case MEDIA_ENT_T_DEVNODE_ALSA_PLAYBACK : +case MEDIA_ENT_T_DEVNODE_ALSA_MIXER : defent = &media->def.alsa; entity->info.alsa = desc->alsa;break ;
utils/media-ctl/media-ctl.c +3 -0
@@ -290,6 +290,9 @@ static const char *media_entity_subtype_to_string(unsigned type)"DVB DVR" ,"DVB CA" ,"DVB NET" , +"ALSA CAPTURE" , +"ALSA PLAYBACK" , + "ALSA MIXER", };static const char *subdev_types[] = { "Unknown",
utils/media-ctl/mediactl.h +3 -1
@@ -305,7 +305,9 @@ struct media_entity *media_get_entity(struct media_device *media, unsigned int i* * MEDIA_ENT_T_DEVNODE_V4L * MEDIA_ENT_T_DEVNODE_FB -* MEDIA_ENT_T_DEVNODE_ALSA +* MEDIA_ENT_T_DEVNODE_ALSA_CAPTURE +* MEDIA_ENT_T_DEVNODE_ALSA_PLAYBACK +* MEDIA_ENT_T_DEVNODE_ALSA_MIXER * MEDIA_ENT_T_DEVNODE_DVB_FE * MEDIA_ENT_T_DEVNODE_DVB_DEMUX * MEDIA_ENT_T_DEVNODE_DVB_DVR
Signature · 1 line
2.1.4