[alsa-devel] [PATCH v2 0/2] Update ALSA driver to use media controller API
This patch series updates ALSA driver to use media controller API to share tuner with DVB and V4L2 drivers that control AU0828 media device. Two new interfaces are added to media controller API to enable creating media device as a device resource. This allows creating media device as a device resource on the main struct device that is common to all drivers that control a single media hardware and share resources on it. Drivers then can find the common media device to register entities and manage links, and pipelines.
Tested with and without CONFIG_MEDIA_CONTROLLER enabled. Tested tuner entity doesn't exist case as au0828 v4l2 driver is the one that will create the tuner when it gets updated to use media controller API.
Please note that au0828 updates media controller are necessary before the resource sharing can work across ALSA and au0828 dvb and v4l2 drivers. This work is in progress and another developer is working on it.
Changes since v1: - Moved media specific code into new header and source file - Created a new structure for media controller specific fields - Added a new define USE_MEDIA_CONTROLLER to add media specific code. This new define is defined only when Media Controller support is enabled. New media specific code is active only when this define is defined. - Moved media_deviced_delete() check under !was_shutdown block - Removed return check for media_device_init() - Changed new Media Controller interface names for clarity. Now they are named media_device_get_devres() and media_device_find_devres(). - Calling media_entity_pipeline_stop() on a pipe that isn't active appears to be safe. This needs further testing once AU0828 media controller patches are ready.
Shuah Khan (2): media: new media controller API for device resource support sound/usb: Update ALSA driver to use media controller API
drivers/media/media-device.c | 33 ++++++++ include/media/media-device.h | 2 + sound/usb/Makefile | 3 +- sound/usb/card.c | 5 ++ sound/usb/card.h | 1 + sound/usb/media.c | 181 +++++++++++++++++++++++++++++++++++++++++++ sound/usb/media.h | 40 ++++++++++ sound/usb/pcm.c | 10 ++- sound/usb/quirks-table.h | 1 + sound/usb/quirks.c | 9 ++- sound/usb/stream.c | 3 + sound/usb/usbaudio.h | 1 + 12 files changed, 286 insertions(+), 3 deletions(-) create mode 100644 sound/usb/media.c create mode 100644 sound/usb/media.h
Add new media controller API to allocate media device as a device resource. When a media device is created on the main struct device which is the parent device for the interface device, it will be available to all drivers associated with that interface. For example, if a usb media device driver creates the media device on the main struct device which is common for all the drivers that control the media device, including the non-media ALSA driver, media controller API can be used to share access to the resources on the media device. This new interface provides the above described feature. A second interface that finds and returns the media device is added to allow drivers to find the media device created by any of the drivers associated with the device.
Signed-off-by: Shuah Khan shuahkh@osg.samsung.com --- drivers/media/media-device.c | 33 +++++++++++++++++++++++++++++++++ include/media/media-device.h | 2 ++ 2 files changed, 35 insertions(+)
diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c index 7b39440..a4d5b24 100644 --- a/drivers/media/media-device.c +++ b/drivers/media/media-device.c @@ -462,3 +462,36 @@ void media_device_unregister_entity(struct media_entity *entity) entity->parent = NULL; } EXPORT_SYMBOL_GPL(media_device_unregister_entity); + +static void media_device_release_devres(struct device *dev, void *res) +{ +} + +/* + * media_device_get_devres() - get media device as device resource + * creates if one doesn't exist +*/ +struct media_device *media_device_get_devres(struct device *dev) +{ + struct media_device *mdev; + + mdev = devres_find(dev, media_device_release_devres, NULL, NULL); + if (mdev) + return mdev; + + mdev = devres_alloc(media_device_release_devres, + sizeof(struct media_device), GFP_KERNEL); + if (!mdev) + return NULL; + return devres_get(dev, mdev, NULL, NULL); +} +EXPORT_SYMBOL_GPL(media_device_get_devres); + +/* + * media_device_find_devres() - find media device as device resource +*/ +struct media_device *media_device_find_devres(struct device *dev) +{ + return devres_find(dev, media_device_release_devres, NULL, NULL); +} +EXPORT_SYMBOL_GPL(media_device_find_devres); diff --git a/include/media/media-device.h b/include/media/media-device.h index 6e6db78..22792cd 100644 --- a/include/media/media-device.h +++ b/include/media/media-device.h @@ -95,6 +95,8 @@ void media_device_unregister(struct media_device *mdev); int __must_check media_device_register_entity(struct media_device *mdev, struct media_entity *entity); void media_device_unregister_entity(struct media_entity *entity); +struct media_device *media_device_get_devres(struct device *dev); +struct media_device *media_device_find_devres(struct device *dev);
/* Iterate over all entities. */ #define media_device_for_each_entity(entity, mdev) \
Em Wed, 03 Jun 2015 09:12:53 -0600 Shuah Khan shuahkh@osg.samsung.com escreveu:
Add new media controller API to allocate media device as a device resource. When a media device is created on the main struct device which is the parent device for the interface device, it will be available to all drivers associated with that interface. For example, if a usb media device driver creates the media device on the main struct device which is common for all the drivers that control the media device, including the non-media ALSA driver, media controller API can be used to share access to the resources on the media device. This new interface provides the above described feature. A second interface that finds and returns the media device is added to allow drivers to find the media device created by any of the drivers associated with the device.
Signed-off-by: Shuah Khan shuahkh@osg.samsung.com
drivers/media/media-device.c | 33 +++++++++++++++++++++++++++++++++ include/media/media-device.h | 2 ++ 2 files changed, 35 insertions(+)
diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c index 7b39440..a4d5b24 100644 --- a/drivers/media/media-device.c +++ b/drivers/media/media-device.c @@ -462,3 +462,36 @@ void media_device_unregister_entity(struct media_entity *entity) entity->parent = NULL; } EXPORT_SYMBOL_GPL(media_device_unregister_entity);
+static void media_device_release_devres(struct device *dev, void *res) +{ +}
+/*
- media_device_get_devres() - get media device as device resource
creates if one doesn't exist
+*/ +struct media_device *media_device_get_devres(struct device *dev) +{
- struct media_device *mdev;
- mdev = devres_find(dev, media_device_release_devres, NULL, NULL);
- if (mdev)
return mdev;
- mdev = devres_alloc(media_device_release_devres,
sizeof(struct media_device), GFP_KERNEL);
- if (!mdev)
return NULL;
- return devres_get(dev, mdev, NULL, NULL);
+} +EXPORT_SYMBOL_GPL(media_device_get_devres);
+/*
- media_device_find_devres() - find media device as device resource
+*/ +struct media_device *media_device_find_devres(struct device *dev) +{
- return devres_find(dev, media_device_release_devres, NULL, NULL);
+} +EXPORT_SYMBOL_GPL(media_device_find_devres); diff --git a/include/media/media-device.h b/include/media/media-device.h index 6e6db78..22792cd 100644 --- a/include/media/media-device.h +++ b/include/media/media-device.h @@ -95,6 +95,8 @@ void media_device_unregister(struct media_device *mdev); int __must_check media_device_register_entity(struct media_device *mdev, struct media_entity *entity); void media_device_unregister_entity(struct media_entity *entity); +struct media_device *media_device_get_devres(struct device *dev); +struct media_device *media_device_find_devres(struct device *dev);
Hmm... what happens if the Kernel is compiled without MC controller support?
I think that the best would be to add a #ifdef at the header file and provide an alternate dummy method to avoid the need of testing for it everywhere.
/* Iterate over all entities. */ #define media_device_for_each_entity(entity, mdev) \
On 06/03/2015 11:42 AM, Mauro Carvalho Chehab wrote:
Em Wed, 03 Jun 2015 09:12:53 -0600 Shuah Khan shuahkh@osg.samsung.com escreveu:
Add new media controller API to allocate media device as a device resource. When a media device is created on the main struct device which is the parent device for the interface device, it will be available to all drivers associated with that interface. For example, if a usb media device driver creates the media device on the main struct device which is common for all the drivers that control the media device, including the non-media ALSA driver, media controller API can be used to share access to the resources on the media device. This new interface provides the above described feature. A second interface that finds and returns the media device is added to allow drivers to find the media device created by any of the drivers associated with the device.
Signed-off-by: Shuah Khan shuahkh@osg.samsung.com
drivers/media/media-device.c | 33 +++++++++++++++++++++++++++++++++ include/media/media-device.h | 2 ++ 2 files changed, 35 insertions(+)
diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c index 7b39440..a4d5b24 100644 --- a/drivers/media/media-device.c +++ b/drivers/media/media-device.c @@ -462,3 +462,36 @@ void media_device_unregister_entity(struct media_entity *entity) entity->parent = NULL; } EXPORT_SYMBOL_GPL(media_device_unregister_entity);
+static void media_device_release_devres(struct device *dev, void *res) +{ +}
+/*
- media_device_get_devres() - get media device as device resource
creates if one doesn't exist
+*/ +struct media_device *media_device_get_devres(struct device *dev) +{
- struct media_device *mdev;
- mdev = devres_find(dev, media_device_release_devres, NULL, NULL);
- if (mdev)
return mdev;
- mdev = devres_alloc(media_device_release_devres,
sizeof(struct media_device), GFP_KERNEL);
- if (!mdev)
return NULL;
- return devres_get(dev, mdev, NULL, NULL);
+} +EXPORT_SYMBOL_GPL(media_device_get_devres);
+/*
- media_device_find_devres() - find media device as device resource
+*/ +struct media_device *media_device_find_devres(struct device *dev) +{
- return devres_find(dev, media_device_release_devres, NULL, NULL);
+} +EXPORT_SYMBOL_GPL(media_device_find_devres); diff --git a/include/media/media-device.h b/include/media/media-device.h index 6e6db78..22792cd 100644 --- a/include/media/media-device.h +++ b/include/media/media-device.h @@ -95,6 +95,8 @@ void media_device_unregister(struct media_device *mdev); int __must_check media_device_register_entity(struct media_device *mdev, struct media_entity *entity); void media_device_unregister_entity(struct media_entity *entity); +struct media_device *media_device_get_devres(struct device *dev); +struct media_device *media_device_find_devres(struct device *dev);
Hmm... what happens if the Kernel is compiled without MC controller support?
Yeah. I noticed media controller api users have the code in ifdef CONFIG_MEDIA_CONTROLLER.
I think that the best would be to add a #ifdef at the header file and provide an alternate dummy method to avoid the need of testing for it everywhere.
I agree with you that a better way to do it would be defining media controller api in ifdef CONFIG_MEDIA_CONTROLLER and provide stubs for else case, similar to what I did in sound/usb/media.c
I followed the existing code to add new interfaces. Do you want to see all media controller interfaces in ifdef clause with stubs or just the two new interfaces I added? Or is this something that should be done as a separate change to catch all media controller interfaces?
thanks, -- Shuah
Em Wed, 03 Jun 2015 12:14:09 -0600 Shuah Khan shuahkh@osg.samsung.com escreveu:
On 06/03/2015 11:42 AM, Mauro Carvalho Chehab wrote:
Em Wed, 03 Jun 2015 09:12:53 -0600 Shuah Khan shuahkh@osg.samsung.com escreveu:
Add new media controller API to allocate media device as a device resource. When a media device is created on the main struct device which is the parent device for the interface device, it will be available to all drivers associated with that interface. For example, if a usb media device driver creates the media device on the main struct device which is common for all the drivers that control the media device, including the non-media ALSA driver, media controller API can be used to share access to the resources on the media device. This new interface provides the above described feature. A second interface that finds and returns the media device is added to allow drivers to find the media device created by any of the drivers associated with the device.
Signed-off-by: Shuah Khan shuahkh@osg.samsung.com
drivers/media/media-device.c | 33 +++++++++++++++++++++++++++++++++ include/media/media-device.h | 2 ++ 2 files changed, 35 insertions(+)
diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c index 7b39440..a4d5b24 100644 --- a/drivers/media/media-device.c +++ b/drivers/media/media-device.c @@ -462,3 +462,36 @@ void media_device_unregister_entity(struct media_entity *entity) entity->parent = NULL; } EXPORT_SYMBOL_GPL(media_device_unregister_entity);
+static void media_device_release_devres(struct device *dev, void *res) +{ +}
+/*
- media_device_get_devres() - get media device as device resource
creates if one doesn't exist
+*/ +struct media_device *media_device_get_devres(struct device *dev) +{
- struct media_device *mdev;
- mdev = devres_find(dev, media_device_release_devres, NULL, NULL);
- if (mdev)
return mdev;
- mdev = devres_alloc(media_device_release_devres,
sizeof(struct media_device), GFP_KERNEL);
- if (!mdev)
return NULL;
- return devres_get(dev, mdev, NULL, NULL);
+} +EXPORT_SYMBOL_GPL(media_device_get_devres);
+/*
- media_device_find_devres() - find media device as device resource
+*/ +struct media_device *media_device_find_devres(struct device *dev) +{
- return devres_find(dev, media_device_release_devres, NULL, NULL);
+} +EXPORT_SYMBOL_GPL(media_device_find_devres); diff --git a/include/media/media-device.h b/include/media/media-device.h index 6e6db78..22792cd 100644 --- a/include/media/media-device.h +++ b/include/media/media-device.h @@ -95,6 +95,8 @@ void media_device_unregister(struct media_device *mdev); int __must_check media_device_register_entity(struct media_device *mdev, struct media_entity *entity); void media_device_unregister_entity(struct media_entity *entity); +struct media_device *media_device_get_devres(struct device *dev); +struct media_device *media_device_find_devres(struct device *dev);
Hmm... what happens if the Kernel is compiled without MC controller support?
Yeah. I noticed media controller api users have the code in ifdef CONFIG_MEDIA_CONTROLLER.
I think that the best would be to add a #ifdef at the header file and provide an alternate dummy method to avoid the need of testing for it everywhere.
I agree with you that a better way to do it would be defining media controller api in ifdef CONFIG_MEDIA_CONTROLLER and provide stubs for else case, similar to what I did in sound/usb/media.c
I followed the existing code to add new interfaces. Do you want to see all media controller interfaces in ifdef clause with stubs or just the two new interfaces I added? Or is this something that should be done as a separate change to catch all media controller interfaces?
It could be on a separate patch. IMHO, the best is to put all defines on stubs.
thanks, -- Shuah
Change ALSA driver to use media 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().
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 media entity for ALSA and a link from tuner entity to the newly registered ALSA entity are created from snd_usb_init_substream() and removed from free_substream(). The state is kept to indicate if tuner is linked. This is to account for case when tuner entity doesn't exist. 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 tuner_linked is set.
Tested with and without CONFIG_MEDIA_CONTROLLER enabled. Tested tuner entity doesn't exist case as au0828 v4l2 driver is the one that will create the tuner when it gets updated to use media controller API.
Signed-off-by: Shuah Khan shuahkh@osg.samsung.com --- sound/usb/Makefile | 3 +- sound/usb/card.c | 5 ++ sound/usb/card.h | 1 + sound/usb/media.c | 181 +++++++++++++++++++++++++++++++++++++++++++++++ sound/usb/media.h | 40 +++++++++++ sound/usb/pcm.c | 10 ++- sound/usb/quirks-table.h | 1 + sound/usb/quirks.c | 9 ++- sound/usb/stream.c | 3 + sound/usb/usbaudio.h | 1 + 10 files changed, 251 insertions(+), 3 deletions(-) create mode 100644 sound/usb/media.c create mode 100644 sound/usb/media.h
diff --git a/sound/usb/Makefile b/sound/usb/Makefile index 2d2d122..7fe4fdd 100644 --- a/sound/usb/Makefile +++ b/sound/usb/Makefile @@ -13,7 +13,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
diff --git a/sound/usb/card.c b/sound/usb/card.c index 1fab977..469d2bf 100644 --- a/sound/usb/card.c +++ b/sound/usb/card.c @@ -66,6 +66,7 @@ #include "format.h" #include "power.h" #include "stream.h" +#include "media.h"
MODULE_AUTHOR("Takashi Iwai tiwai@suse.de"); 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--; diff --git a/sound/usb/card.h b/sound/usb/card.h index ef580b4..235a85f 100644 --- a/sound/usb/card.h +++ b/sound/usb/card.h @@ -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 { diff --git a/sound/usb/media.c b/sound/usb/media.c new file mode 100644 index 0000000..8e8a0b3 --- /dev/null +++ b/sound/usb/media.c @@ -0,0 +1,181 @@ +/* + * media.c - managed media token resource + * + * Copyright (c) 2015 Shuah Khan shuahkh@osg.samsung.com + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * This file is released under the GPLv2. + */ + +/* + * This file adds Media Controller support to ALSA driver + * to use the Media Controller API to share tuner with DVB + * and V4L2 drivers that control media device. Media device + * is created based on existing quirks framework. Using this + * approach, the media controller API usage can be added for + * a specific device. +*/ + +#ifdef CONFIG_MEDIA_CONTROLLER +#if defined(CONFIG_MEDIA_SUPPORT) || \ + (defined(CONFIG_MEDIA_SUPPORT_MODULE) && defined(MODULE)) +#define USE_MEDIA_CONTROLLER +#endif +#endif + +#include <linux/init.h> +#include <linux/list.h> +#include <linux/slab.h> +#include <linux/string.h> +#include <linux/ctype.h> +#include <linux/usb.h> +#include <linux/moduleparam.h> +#include <linux/mutex.h> +#include <linux/usb/audio.h> +#include <linux/usb/audio-v2.h> +#include <linux/module.h> + +#include <sound/control.h> +#include <sound/core.h> +#include <sound/info.h> +#include <sound/pcm.h> +#include <sound/pcm_params.h> +#include <sound/initval.h> + +#include "usbaudio.h" +#include "card.h" +#include "midi.h" +#include "mixer.h" +#include "proc.h" +#include "quirks.h" +#include "endpoint.h" +#include "helper.h" +#include "debug.h" +#include "pcm.h" +#include "format.h" +#include "power.h" +#include "stream.h" +#include "media.h" + +#ifdef USE_MEDIA_CONTROLLER +int media_device_init(struct usb_interface *iface) +{ + struct media_device *mdev; + struct usb_device *usbdev = interface_to_usbdev(iface); + int ret; + + mdev = media_device_get_devres(&usbdev->dev); + if (!mdev) + return -ENOMEM; + if (!media_devnode_is_registered(&mdev->devnode)) { + /* register media device */ + mdev->dev = &usbdev->dev; + if (usbdev->product) + strlcpy(mdev->model, usbdev->product, + sizeof(mdev->model)); + if (usbdev->serial) + strlcpy(mdev->serial, usbdev->serial, + sizeof(mdev->serial)); + strcpy(mdev->bus_info, usbdev->devpath); + mdev->hw_revision = le16_to_cpu(usbdev->descriptor.bcdDevice); + ret = media_device_register(mdev); + if (ret) { + dev_err(&usbdev->dev, + "Couldn't create a media device. Error: %d\n", + ret); + return ret; + } + } + dev_info(&usbdev->dev, "Created media device.\n"); + return 0; +} + +void media_device_delete(struct usb_interface *iface) +{ + struct media_device *mdev; + struct usb_device *usbdev = interface_to_usbdev(iface); + + mdev = media_device_find_devres(&usbdev->dev); + if (mdev && media_devnode_is_registered(&mdev->devnode)) + media_device_unregister(mdev); + dev_info(&usbdev->dev, "Deleted media device.\n"); +} + +void media_stream_init(struct snd_usb_substream *subs) +{ + struct media_device *mdev; + struct media_ctl *mctl; + struct media_entity *entity; + int ret; + + mdev = media_device_find_devres(&subs->dev->dev); + if (!mdev) + return; + + /* allocate media_ctl */ + mctl = kzalloc(sizeof(struct media_ctl), GFP_KERNEL); + if (!mctl) + return; + + mctl->media_dev = mdev; + mctl->media_entity.type = MEDIA_ENT_T_DEVNODE_ALSA; + media_entity_init(&mctl->media_entity, 1, &mctl->media_pads, 0); + media_device_register_entity(mctl->media_dev, &mctl->media_entity); + media_device_for_each_entity(entity, mctl->media_dev) { + switch (entity->type) { + case MEDIA_ENT_T_V4L2_SUBDEV_TUNER: + ret = media_entity_create_link(entity, 0, + &mctl->media_entity, 0, + MEDIA_LNK_FL_ENABLED); + if (ret == 0) + mctl->tuner_linked = 1; + break; + } + } + subs->media_ctl = (void *) mctl; +} + +void media_stream_delete(struct snd_usb_substream *subs) +{ + struct media_ctl *mctl = (struct media_ctl *) subs->media_ctl; + + if (mctl && mctl->media_dev) { + mctl->media_dev = NULL; + mctl->tuner_linked = 0; + media_entity_remove_links(&mctl->media_entity); + media_device_unregister_entity(&mctl->media_entity); + media_entity_cleanup(&mctl->media_entity); + } +} + +int media_start_pipeline(struct snd_usb_substream *subs) +{ + struct media_ctl *mctl = (struct media_ctl *) subs->media_ctl; + int ret = 0; + + if (mctl && mctl->tuner_linked) + ret = media_entity_pipeline_start(&mctl->media_entity, + &mctl->media_pipe); + return ret; +} + +void media_stop_pipeline(struct snd_usb_substream *subs) +{ + struct media_ctl *mctl = (struct media_ctl *) subs->media_ctl; + + if (mctl && mctl->tuner_linked) + media_entity_pipeline_stop(&mctl->media_entity); +} +#else +int media_device_init(struct usb_interface *iface) { return 0; } + +void media_device_delete(struct usb_interface *iface) { } + +void media_stream_init(struct snd_usb_substream *subs) { } + +void media_stream_delete(struct snd_usb_substream *subs) { } + +int media_start_pipeline(struct snd_usb_substream *subs) { return 0; } + +void media_stop_pipeline(struct snd_usb_substream *subs) { } +#endif diff --git a/sound/usb/media.h b/sound/usb/media.h new file mode 100644 index 0000000..cddc05c --- /dev/null +++ b/sound/usb/media.h @@ -0,0 +1,40 @@ +/* + * media.h - managed media token resource + * + * Copyright (c) 2015 Shuah Khan shuahkh@osg.samsung.com + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * This file is released under the GPLv2. + */ + +/* + * This file adds Media Controller support to ALSA driver + * to use the Media Controller API to share tuner with DVB + * and V4L2 drivers that control media device. Media device + * is created based on existing quirks framework. Using this + * approach, the media controller API usage can be added for + * a specific device. +*/ +#ifndef __MEDIA_H + +#ifdef USE_MEDIA_CONTROLLER +#include <media/media-device.h> +#include <media/media-entity.h> + +struct media_ctl { + struct media_device *media_dev; + struct media_entity media_entity; + struct media_pad media_pads; + struct media_pipeline media_pipe; + bool tuner_linked; +}; +#endif + +extern int media_device_init(struct usb_interface *iface); +extern void media_device_delete(struct usb_interface *iface); +extern void media_stream_init(struct snd_usb_substream *subs); +extern void media_stream_delete(struct snd_usb_substream *subs); +extern int media_start_pipeline(struct snd_usb_substream *subs); +extern void media_stop_pipeline(struct snd_usb_substream *subs); + +#endif /* __MEDIA_H */ diff --git a/sound/usb/pcm.c b/sound/usb/pcm.c index b4ef410..bb83da5 100644 --- a/sound/usb/pcm.c +++ b/sound/usb/pcm.c @@ -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 @@ -1225,6 +1226,7 @@ static int snd_usb_pcm_close(struct snd_pcm_substream *substream, int direction)
subs->pcm_substream = NULL; snd_usb_autosuspend(subs->stream->chip); + media_stop_pipeline(subs);
return 0; } @@ -1587,9 +1589,14 @@ static int snd_usb_substream_capture_trigger(struct snd_pcm_substream *substream
switch (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 +1604,7 @@ static int snd_usb_substream_capture_trigger(struct snd_pcm_substream *substream case 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; diff --git a/sound/usb/quirks-table.h b/sound/usb/quirks-table.h index 2f6d3e9..51c544f 100644 --- a/sound/usb/quirks-table.h +++ b/sound/usb/quirks-table.h @@ -2798,6 +2798,7 @@ YAMAHA_DEVICE(0x7010, "UB99"), .product_name = pname, \ .ifnum = QUIRK_ANY_INTERFACE, \ .type = QUIRK_AUDIO_ALIGN_TRANSFER, \ + .media_device = 1, \ } \ }
diff --git a/sound/usb/quirks.c b/sound/usb/quirks.c index 46facfc..ea2a9f0 100644 --- a/sound/usb/quirks.c +++ b/sound/usb/quirks.c @@ -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; }
/* diff --git a/sound/usb/stream.c b/sound/usb/stream.c index 310a382..ab15d9a 100644 --- a/sound/usb/stream.c +++ b/sound/usb/stream.c @@ -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); }
@@ -104,6 +106,7 @@ static void snd_usb_init_substream(struct snd_usb_stream *as, subs->ep_num = fp->endpoint; if (fp->channels > subs->channels_max) subs->channels_max = fp->channels; + media_stream_init(subs); }
/* kctl callbacks for usb-audio channel maps */ diff --git a/sound/usb/usbaudio.h b/sound/usb/usbaudio.h index 91d0380..c2dbf1d 100644 --- a/sound/usb/usbaudio.h +++ b/sound/usb/usbaudio.h @@ -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; };
Em Wed, 03 Jun 2015 09:12:54 -0600 Shuah Khan shuahkh@osg.samsung.com escreveu:
Change ALSA driver to use media 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().
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 media entity for ALSA and a link from tuner entity to the newly registered ALSA entity are created from snd_usb_init_substream() and removed from free_substream(). The state is kept to indicate if tuner is linked. This is to account for case when tuner entity doesn't exist. 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 tuner_linked is set.
Tested with and without CONFIG_MEDIA_CONTROLLER enabled. Tested tuner entity doesn't exist case as au0828 v4l2 driver is the one that will create the tuner when it gets updated to use media controller API.
Signed-off-by: Shuah Khan shuahkh@osg.samsung.com
sound/usb/Makefile | 3 +- sound/usb/card.c | 5 ++ sound/usb/card.h | 1 + sound/usb/media.c | 181 +++++++++++++++++++++++++++++++++++++++++++++++ sound/usb/media.h | 40 +++++++++++ sound/usb/pcm.c | 10 ++- sound/usb/quirks-table.h | 1 + sound/usb/quirks.c | 9 ++- sound/usb/stream.c | 3 + sound/usb/usbaudio.h | 1 + 10 files changed, 251 insertions(+), 3 deletions(-) create mode 100644 sound/usb/media.c create mode 100644 sound/usb/media.h
diff --git a/sound/usb/Makefile b/sound/usb/Makefile index 2d2d122..7fe4fdd 100644 --- a/sound/usb/Makefile +++ b/sound/usb/Makefile @@ -13,7 +13,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
diff --git a/sound/usb/card.c b/sound/usb/card.c index 1fab977..469d2bf 100644 --- a/sound/usb/card.c +++ b/sound/usb/card.c @@ -66,6 +66,7 @@ #include "format.h" #include "power.h" #include "stream.h" +#include "media.h"
MODULE_AUTHOR("Takashi Iwai tiwai@suse.de"); 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--;
diff --git a/sound/usb/card.h b/sound/usb/card.h index ef580b4..235a85f 100644 --- a/sound/usb/card.h +++ b/sound/usb/card.h @@ -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 { diff --git a/sound/usb/media.c b/sound/usb/media.c new file mode 100644 index 0000000..8e8a0b3 --- /dev/null +++ b/sound/usb/media.c @@ -0,0 +1,181 @@ +/*
- media.c - managed media token resource
- Copyright (c) 2015 Shuah Khan shuahkh@osg.samsung.com
- Copyright (c) 2015 Samsung Electronics Co., Ltd.
- This file is released under the GPLv2.
- */
+/*
- This file adds Media Controller support to ALSA driver
- to use the Media Controller API to share tuner with DVB
- and V4L2 drivers that control media device. Media device
- is created based on existing quirks framework. Using this
- approach, the media controller API usage can be added for
- a specific device.
+*/
+#ifdef CONFIG_MEDIA_CONTROLLER +#if defined(CONFIG_MEDIA_SUPPORT) || \
- (defined(CONFIG_MEDIA_SUPPORT_MODULE) && defined(MODULE))
+#define USE_MEDIA_CONTROLLER +#endif +#endif
+#include <linux/init.h> +#include <linux/list.h> +#include <linux/slab.h> +#include <linux/string.h> +#include <linux/ctype.h> +#include <linux/usb.h> +#include <linux/moduleparam.h> +#include <linux/mutex.h> +#include <linux/usb/audio.h> +#include <linux/usb/audio-v2.h> +#include <linux/module.h>
+#include <sound/control.h> +#include <sound/core.h> +#include <sound/info.h> +#include <sound/pcm.h> +#include <sound/pcm_params.h> +#include <sound/initval.h>
+#include "usbaudio.h" +#include "card.h" +#include "midi.h" +#include "mixer.h" +#include "proc.h" +#include "quirks.h" +#include "endpoint.h" +#include "helper.h" +#include "debug.h" +#include "pcm.h" +#include "format.h" +#include "power.h" +#include "stream.h" +#include "media.h"
+#ifdef USE_MEDIA_CONTROLLER
Nah. Please move this test to Makefile and add the stubs to media.h header.
+int media_device_init(struct usb_interface *iface) +{
- struct media_device *mdev;
- struct usb_device *usbdev = interface_to_usbdev(iface);
- int ret;
- mdev = media_device_get_devres(&usbdev->dev);
- if (!mdev)
return -ENOMEM;
- if (!media_devnode_is_registered(&mdev->devnode)) {
/* register media device */
mdev->dev = &usbdev->dev;
if (usbdev->product)
strlcpy(mdev->model, usbdev->product,
sizeof(mdev->model));
if (usbdev->serial)
strlcpy(mdev->serial, usbdev->serial,
sizeof(mdev->serial));
strcpy(mdev->bus_info, usbdev->devpath);
mdev->hw_revision = le16_to_cpu(usbdev->descriptor.bcdDevice);
ret = media_device_register(mdev);
if (ret) {
dev_err(&usbdev->dev,
"Couldn't create a media device. Error: %d\n",
ret);
return ret;
}
- }
- dev_info(&usbdev->dev, "Created media device.\n");
- return 0;
+}
+void media_device_delete(struct usb_interface *iface) +{
- struct media_device *mdev;
- struct usb_device *usbdev = interface_to_usbdev(iface);
- mdev = media_device_find_devres(&usbdev->dev);
- if (mdev && media_devnode_is_registered(&mdev->devnode))
media_device_unregister(mdev);
- dev_info(&usbdev->dev, "Deleted media device.\n");
+}
+void media_stream_init(struct snd_usb_substream *subs) +{
- struct media_device *mdev;
- struct media_ctl *mctl;
- struct media_entity *entity;
- int ret;
- mdev = media_device_find_devres(&subs->dev->dev);
- if (!mdev)
return;
- /* allocate media_ctl */
- mctl = kzalloc(sizeof(struct media_ctl), GFP_KERNEL);
- if (!mctl)
return;
- mctl->media_dev = mdev;
- mctl->media_entity.type = MEDIA_ENT_T_DEVNODE_ALSA;
- media_entity_init(&mctl->media_entity, 1, &mctl->media_pads, 0);
- media_device_register_entity(mctl->media_dev, &mctl->media_entity);
Looks ok, but we'll likely need to change from DEVNODE_ALSA to something else to reflect what alsa components (sub-devices?) will be actually being registered: mixer, pcm playback, pcm capture, etc;
- media_device_for_each_entity(entity, mctl->media_dev) {
switch (entity->type) {
case MEDIA_ENT_T_V4L2_SUBDEV_TUNER:
ret = media_entity_create_link(entity, 0,
&mctl->media_entity, 0,
MEDIA_LNK_FL_ENABLED);
I don't think that this code belongs here.
The proper thing to do seems to add a hook that would be called every time that media_entity_create() is called.
Inside the hook code, if both alsa mixer and tuner are registered, it will create the above link.
Such hook would be registered by some function call. At the time such function would be called, the hook code will also run.
This way, it won't matter if snd-usb-audio is probed before or after au0828.
As the above knowledge is au0828-specifics, the best is to add the hook function caller code inside au0828 driver.
if (ret == 0)
mctl->tuner_linked = 1;
break;
}
- }
- subs->media_ctl = (void *) mctl;
+}
+void media_stream_delete(struct snd_usb_substream *subs) +{
- struct media_ctl *mctl = (struct media_ctl *) subs->media_ctl;
- if (mctl && mctl->media_dev) {
mctl->media_dev = NULL;
mctl->tuner_linked = 0;
media_entity_remove_links(&mctl->media_entity);
Hmm... will this work? What happens if just snd-usb-audio is removed, but au0828 keeps loaded?
Laurent knows better than me, but I think this will cause troubles.
media_device_unregister_entity(&mctl->media_entity);
media_entity_cleanup(&mctl->media_entity);
- }
+}
+int media_start_pipeline(struct snd_usb_substream *subs) +{
- struct media_ctl *mctl = (struct media_ctl *) subs->media_ctl;
- int ret = 0;
- if (mctl && mctl->tuner_linked)
ret = media_entity_pipeline_start(&mctl->media_entity,
&mctl->media_pipe);
I think that pipeline start/stop functions need to be modified, as it should start/stop here just the alsa part of the pipeline, not touching at the V4L2 one.
- return ret;
+}
+void media_stop_pipeline(struct snd_usb_substream *subs) +{
- struct media_ctl *mctl = (struct media_ctl *) subs->media_ctl;
- if (mctl && mctl->tuner_linked)
media_entity_pipeline_stop(&mctl->media_entity);
+} +#else +int media_device_init(struct usb_interface *iface) { return 0; }
+void media_device_delete(struct usb_interface *iface) { }
+void media_stream_init(struct snd_usb_substream *subs) { }
+void media_stream_delete(struct snd_usb_substream *subs) { }
+int media_start_pipeline(struct snd_usb_substream *subs) { return 0; }
+void media_stop_pipeline(struct snd_usb_substream *subs) { }
Please put the stubs at the header file.
+#endif diff --git a/sound/usb/media.h b/sound/usb/media.h new file mode 100644 index 0000000..cddc05c --- /dev/null +++ b/sound/usb/media.h @@ -0,0 +1,40 @@ +/*
- media.h - managed media token resource
- Copyright (c) 2015 Shuah Khan shuahkh@osg.samsung.com
- Copyright (c) 2015 Samsung Electronics Co., Ltd.
- This file is released under the GPLv2.
- */
+/*
- This file adds Media Controller support to ALSA driver
- to use the Media Controller API to share tuner with DVB
- and V4L2 drivers that control media device. Media device
- is created based on existing quirks framework. Using this
- approach, the media controller API usage can be added for
- a specific device.
+*/ +#ifndef __MEDIA_H
+#ifdef USE_MEDIA_CONTROLLER +#include <media/media-device.h> +#include <media/media-entity.h>
+struct media_ctl {
- struct media_device *media_dev;
- struct media_entity media_entity;
- struct media_pad media_pads;
- struct media_pipeline media_pipe;
- bool tuner_linked;
+}; +#endif
+extern int media_device_init(struct usb_interface *iface); +extern void media_device_delete(struct usb_interface *iface); +extern void media_stream_init(struct snd_usb_substream *subs); +extern void media_stream_delete(struct snd_usb_substream *subs); +extern int media_start_pipeline(struct snd_usb_substream *subs); +extern void media_stop_pipeline(struct snd_usb_substream *subs);
+#endif /* __MEDIA_H */ diff --git a/sound/usb/pcm.c b/sound/usb/pcm.c index b4ef410..bb83da5 100644 --- a/sound/usb/pcm.c +++ b/sound/usb/pcm.c @@ -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 @@ -1225,6 +1226,7 @@ static int snd_usb_pcm_close(struct snd_pcm_substream *substream, int direction)
subs->pcm_substream = NULL; snd_usb_autosuspend(subs->stream->chip);
media_stop_pipeline(subs);
return 0;
} @@ -1587,9 +1589,14 @@ static int snd_usb_substream_capture_trigger(struct snd_pcm_substream *substream
switch (cmd) { case SNDRV_PCM_TRIGGER_START:
err = media_start_pipeline(subs);
if (err)
err = start_endpoints(subs, false);return err;
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 +1604,7 @@ static int snd_usb_substream_capture_trigger(struct snd_pcm_substream *substream case SNDRV_PCM_TRIGGER_STOP: stop_endpoints(subs, false); subs->running = 0;
return 0; case SNDRV_PCM_TRIGGER_PAUSE_PUSH: subs->data_endpoint->retire_data_urb = NULL;media_stop_pipeline(subs);
diff --git a/sound/usb/quirks-table.h b/sound/usb/quirks-table.h index 2f6d3e9..51c544f 100644 --- a/sound/usb/quirks-table.h +++ b/sound/usb/quirks-table.h @@ -2798,6 +2798,7 @@ YAMAHA_DEVICE(0x7010, "UB99"), .product_name = pname, \ .ifnum = QUIRK_ANY_INTERFACE, \ .type = QUIRK_AUDIO_ALIGN_TRANSFER, \
} \.media_device = 1, \
}
diff --git a/sound/usb/quirks.c b/sound/usb/quirks.c index 46facfc..ea2a9f0 100644 --- a/sound/usb/quirks.c +++ b/sound/usb/quirks.c @@ -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);
} else { usb_audio_err(chip, "invalid quirk type %d\n", quirk->type); return -ENXIO; }ret = quirk_funcs[quirk->type](chip, iface, driver, quirk);
- return ret;
}
/* diff --git a/sound/usb/stream.c b/sound/usb/stream.c index 310a382..ab15d9a 100644 --- a/sound/usb/stream.c +++ b/sound/usb/stream.c @@ -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);
}
@@ -104,6 +106,7 @@ static void snd_usb_init_substream(struct snd_usb_stream *as, subs->ep_num = fp->endpoint; if (fp->channels > subs->channels_max) subs->channels_max = fp->channels;
- media_stream_init(subs);
}
/* kctl callbacks for usb-audio channel maps */ diff --git a/sound/usb/usbaudio.h b/sound/usb/usbaudio.h index 91d0380..c2dbf1d 100644 --- a/sound/usb/usbaudio.h +++ b/sound/usb/usbaudio.h @@ -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;
};
On 06/03/2015 01:14 PM, Mauro Carvalho Chehab wrote:
Em Wed, 03 Jun 2015 09:12:54 -0600 Shuah Khan shuahkh@osg.samsung.com escreveu:
Change ALSA driver to use media 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().
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 media entity for ALSA and a link from tuner entity to the newly registered ALSA entity are created from snd_usb_init_substream() and removed from free_substream(). The state is kept to indicate if tuner is linked. This is to account for case when tuner entity doesn't exist. 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 tuner_linked is set.
Tested with and without CONFIG_MEDIA_CONTROLLER enabled. Tested tuner entity doesn't exist case as au0828 v4l2 driver is the one that will create the tuner when it gets updated to use media controller API.
Signed-off-by: Shuah Khan shuahkh@osg.samsung.com
sound/usb/Makefile | 3 +- sound/usb/card.c | 5 ++ sound/usb/card.h | 1 + sound/usb/media.c | 181 +++++++++++++++++++++++++++++++++++++++++++++++ sound/usb/media.h | 40 +++++++++++ sound/usb/pcm.c | 10 ++- sound/usb/quirks-table.h | 1 + sound/usb/quirks.c | 9 ++- sound/usb/stream.c | 3 + sound/usb/usbaudio.h | 1 + 10 files changed, 251 insertions(+), 3 deletions(-) create mode 100644 sound/usb/media.c create mode 100644 sound/usb/media.h
diff --git a/sound/usb/Makefile b/sound/usb/Makefile index 2d2d122..7fe4fdd 100644 --- a/sound/usb/Makefile +++ b/sound/usb/Makefile @@ -13,7 +13,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
diff --git a/sound/usb/card.c b/sound/usb/card.c index 1fab977..469d2bf 100644 --- a/sound/usb/card.c +++ b/sound/usb/card.c @@ -66,6 +66,7 @@ #include "format.h" #include "power.h" #include "stream.h" +#include "media.h"
MODULE_AUTHOR("Takashi Iwai tiwai@suse.de"); 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--;
diff --git a/sound/usb/card.h b/sound/usb/card.h index ef580b4..235a85f 100644 --- a/sound/usb/card.h +++ b/sound/usb/card.h @@ -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 { diff --git a/sound/usb/media.c b/sound/usb/media.c new file mode 100644 index 0000000..8e8a0b3 --- /dev/null +++ b/sound/usb/media.c @@ -0,0 +1,181 @@ +/*
- media.c - managed media token resource
- Copyright (c) 2015 Shuah Khan shuahkh@osg.samsung.com
- Copyright (c) 2015 Samsung Electronics Co., Ltd.
- This file is released under the GPLv2.
- */
+/*
- This file adds Media Controller support to ALSA driver
- to use the Media Controller API to share tuner with DVB
- and V4L2 drivers that control media device. Media device
- is created based on existing quirks framework. Using this
- approach, the media controller API usage can be added for
- a specific device.
+*/
+#ifdef CONFIG_MEDIA_CONTROLLER +#if defined(CONFIG_MEDIA_SUPPORT) || \
- (defined(CONFIG_MEDIA_SUPPORT_MODULE) && defined(MODULE))
+#define USE_MEDIA_CONTROLLER +#endif +#endif
+#include <linux/init.h> +#include <linux/list.h> +#include <linux/slab.h> +#include <linux/string.h> +#include <linux/ctype.h> +#include <linux/usb.h> +#include <linux/moduleparam.h> +#include <linux/mutex.h> +#include <linux/usb/audio.h> +#include <linux/usb/audio-v2.h> +#include <linux/module.h>
+#include <sound/control.h> +#include <sound/core.h> +#include <sound/info.h> +#include <sound/pcm.h> +#include <sound/pcm_params.h> +#include <sound/initval.h>
+#include "usbaudio.h" +#include "card.h" +#include "midi.h" +#include "mixer.h" +#include "proc.h" +#include "quirks.h" +#include "endpoint.h" +#include "helper.h" +#include "debug.h" +#include "pcm.h" +#include "format.h" +#include "power.h" +#include "stream.h" +#include "media.h"
+#ifdef USE_MEDIA_CONTROLLER
Nah. Please move this test to Makefile and add the stubs to media.h header.
Yes that is a good way to go.
+int media_device_init(struct usb_interface *iface) +{
- struct media_device *mdev;
- struct usb_device *usbdev = interface_to_usbdev(iface);
- int ret;
- mdev = media_device_get_devres(&usbdev->dev);
- if (!mdev)
return -ENOMEM;
- if (!media_devnode_is_registered(&mdev->devnode)) {
/* register media device */
mdev->dev = &usbdev->dev;
if (usbdev->product)
strlcpy(mdev->model, usbdev->product,
sizeof(mdev->model));
if (usbdev->serial)
strlcpy(mdev->serial, usbdev->serial,
sizeof(mdev->serial));
strcpy(mdev->bus_info, usbdev->devpath);
mdev->hw_revision = le16_to_cpu(usbdev->descriptor.bcdDevice);
ret = media_device_register(mdev);
if (ret) {
dev_err(&usbdev->dev,
"Couldn't create a media device. Error: %d\n",
ret);
return ret;
}
- }
- dev_info(&usbdev->dev, "Created media device.\n");
- return 0;
+}
+void media_device_delete(struct usb_interface *iface) +{
- struct media_device *mdev;
- struct usb_device *usbdev = interface_to_usbdev(iface);
- mdev = media_device_find_devres(&usbdev->dev);
- if (mdev && media_devnode_is_registered(&mdev->devnode))
media_device_unregister(mdev);
- dev_info(&usbdev->dev, "Deleted media device.\n");
+}
+void media_stream_init(struct snd_usb_substream *subs) +{
- struct media_device *mdev;
- struct media_ctl *mctl;
- struct media_entity *entity;
- int ret;
- mdev = media_device_find_devres(&subs->dev->dev);
- if (!mdev)
return;
- /* allocate media_ctl */
- mctl = kzalloc(sizeof(struct media_ctl), GFP_KERNEL);
- if (!mctl)
return;
- mctl->media_dev = mdev;
- mctl->media_entity.type = MEDIA_ENT_T_DEVNODE_ALSA;
- media_entity_init(&mctl->media_entity, 1, &mctl->media_pads, 0);
- media_device_register_entity(mctl->media_dev, &mctl->media_entity);
Looks ok, but we'll likely need to change from DEVNODE_ALSA to something else to reflect what alsa components (sub-devices?) will be actually being registered: mixer, pcm playback, pcm capture, etc;
Yes. This might need changes to reflect the full media graph.
- media_device_for_each_entity(entity, mctl->media_dev) {
switch (entity->type) {
case MEDIA_ENT_T_V4L2_SUBDEV_TUNER:
ret = media_entity_create_link(entity, 0,
&mctl->media_entity, 0,
MEDIA_LNK_FL_ENABLED);
I don't think that this code belongs here.
The proper thing to do seems to add a hook that would be called every time that media_entity_create() is called.
Inside the hook code, if both alsa mixer and tuner are registered, it will create the above link.
Such hook would be registered by some function call. At the time such function would be called, the hook code will also run.
One way we can do this in a generic way would be as follows. This might help other media driver interactions in creating entities as well.
Add a new ops to struct media_entity_operations to be called when a new entity id registered so existing entities can take necessary action in response to new entity registration. This hook could be invoked for all existing entities as well as the new one, so the new entity can create necessary links.
If snd-usb-audio is the the first one to create entity, when au0828 comes along and registers its entity, snd-usb-audio's media_entity_operations hook can be called and in that hook it can create links. If au0828 comes along first, then when snd-usb-audio registers its entity and when its new hook is called, it can create the necessary links.
How does this sound? I could make the changes and see if it works.
thanks, -- Shuah
participants (2)
-
Mauro Carvalho Chehab
-
Shuah Khan