Re: [PATCH v2 2/2] sound/usb: Update ALSA driver to use media controller API

2015-06-05 Thread Shuah Khan
On 06/03/2015 01:14 PM, Mauro Carvalho Chehab wrote:
 Em Wed, 03 Jun 2015 09:12:54 -0600
 Shuah Khan shua...@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 shua...@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 ti...@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 000..8e8a0b3
 --- /dev/null
 +++ b/sound/usb/media.c
 @@ -0,0 +1,181 @@
 +/*
 + * media.c - managed media token resource
 + *
 + * Copyright (c) 2015 Shuah Khan shua...@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))
 

Re: [PATCH v2 2/2] sound/usb: Update ALSA driver to use media controller API

2015-06-03 Thread Mauro Carvalho Chehab
Em Wed, 03 Jun 2015 09:12:54 -0600
Shuah Khan shua...@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 shua...@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 ti...@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 000..8e8a0b3
 --- /dev/null
 +++ b/sound/usb/media.c
 @@ -0,0 +1,181 @@
 +/*
 + * media.c - managed media token resource
 + *
 + * Copyright (c) 2015 Shuah Khan shua...@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
 

[PATCH v2 2/2] sound/usb: Update ALSA driver to use media controller API

2015-06-03 Thread Shuah Khan
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 shua...@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 ti...@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 000..8e8a0b3
--- /dev/null
+++ b/sound/usb/media.c
@@ -0,0 +1,181 @@
+/*
+ * media.c - managed media token resource
+ *
+ * Copyright (c) 2015 Shuah Khan shua...@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