linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 00/22] Sharing media resources across ALSA and au0828 drivers
@ 2016-02-11 23:41 Shuah Khan
  2016-02-11 23:41 ` [PATCH v3 01/22] [media] Docbook: media-types.xml: Add ALSA Media Controller Intf types Shuah Khan
                   ` (21 more replies)
  0 siblings, 22 replies; 49+ messages in thread
From: Shuah Khan @ 2016-02-11 23:41 UTC (permalink / raw)
  To: mchehab, tiwai, clemens, hans.verkuil, laurent.pinchart,
	sakari.ailus, javier
  Cc: Shuah Khan, pawel, m.szyprowski, kyungmin.park, perex, arnd,
	dan.carpenter, tvboxspy, crope, ruchandani.tina, corbet,
	chehabrafael, k.kozlowski, stefanr, inki.dae, jh1009.sung,
	elfring, prabhakar.csengg, sw0312.kim, p.zabel, ricardo.ribalda,
	labbott, pierre-louis.bossart, ricard.wanderlof, julian,
	takamichiho, dominic.sacre, misterpib, daniel, gtmkramer,
	normalperson, joe, linuxbugs, johan, klock.android, nenggun.kim,
	j.anaszewski, geliangtang, albert, linux-kernel, linux-media,
	alsa-devel

This patch series updates ALSA driver, and au0828 core
driver to use Managed Media controller API and Media
Controller API to share media resource (tuner).

This Patch v3 series is based on linux_media master.
This work addresses Mauro and Takashi's comments on
Patch v2 series.

Changes since Patch v2 series:
- Added documentation for uapi and new MC interfaces
  1. Ran make for documentation and Mauro's doc script.
     Thanks for sharing the script.
- Updated commit logs as needed for clarity.
- media: v4l-core add enable/disable source common interfaces
  Addressed comments - added static inlines in header file
- media: dvb-frontend invoke enable/disable_source handlers
  Moved the patch after enable/disable handlers and left
  pipe in dvb_frontend_private
- media: au0828 video remove au0828_enable_analog_tuner() and
  media: au0828 video change to use v4l_enable_media_source()
  1. Collapsed these two patches - it doesn't make sense to keep
     them separate. Also added FIXME as per Mauro's suggestion.
- media: au0828 change to use Managed Media Controller API
  1. Added comment explaining the need for using udev->product
     instead of dev->board.name
- media: au0828 add enable, disable source handlers
  1. Changed to handle S-Video and Composite inputs.
  2. Fixed a bug that lets Video in when ALSA holds the
     source.
  3. Added comments to one FIXME for s_input changes.
     Fix is in progress and will send it in a day or two
     combined with other issues found in au0828 video in
     the way it handles input. Doesn't impact this routine,
     changes are all in au0828-video.
- sound/usb: Use Media Controller API to share media resources
  1. Addressed comments from Mauro and Takashi about void pointer
     use.
  2. Fixed kbuildbot error when MEDIA_SUPPORT=m
- Dropped media: Ensure media device unregister is done only once
  Device removal worked without any changes to media unregister
  path. This work isn't necessary.

Shuah Khan (22):
  [media] Docbook: media-types.xml: Add ALSA Media Controller Intf types
  uapi/media.h: Declare interface types for ALSA
  [media] Docbook: media-types.xml: Add Audio Function Entities
  media: Add ALSA Media Controller function entities
  media: Media Controller register/unregister entity_notify API
  media: Media Controller enable/disable source handler API
  media: Media Controller export non locking __media_entity_setup_link()
  edia: Media Controller non-locking
    __media_entity_pipeline_start/stop()
  media: v4l-core add enable/disable source common interfaces
  media: Move au8522_media_pads enum to au8522.h from au8522_priv.h
  media: au8522 change to create MC pad for ALSA Audio Out
  media: au0828 Use au8522_media_pads enum for pad defines
  media: Change v4l-core to check if source is free
  media: au0828 change to use Managed Media Controller API
  media: au0828 handle media_init and media_register window
  media: au0828 create tuner to decoder link in disabled state
  media: au0828 disable tuner to demod link
  media: au0828-core register entity_notify hook
  media: au0828 add enable, disable source handlers
  media: dvb-frontend invoke enable/disable_source handlers
  media: au0828 video change to use v4l_enable_media_source()
  sound/usb: Use Media Controller API to share media resources

 Documentation/DocBook/media/v4l/media-types.xml |  52 ++++
 drivers/media/dvb-core/dvb_frontend.c           | 135 ++--------
 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                    |  42 +++
 drivers/media/media-entity.c                    |  51 +++-
 drivers/media/usb/au0828/au0828-core.c          | 325 ++++++++++++++++++++++--
 drivers/media/usb/au0828/au0828-video.c         | 102 +++-----
 drivers/media/usb/au0828/au0828.h               |   6 +
 drivers/media/v4l2-core/Makefile                |   1 +
 drivers/media/v4l2-core/v4l2-fh.c               |   2 +
 drivers/media/v4l2-core/v4l2-ioctl.c            |  30 +++
 drivers/media/v4l2-core/v4l2-mc.c               |  52 ++++
 drivers/media/v4l2-core/videobuf2-core.c        |   4 +
 include/media/media-device.h                    |  86 +++++++
 include/media/media-entity.h                    |  19 ++
 include/media/v4l2-dev.h                        |   1 +
 include/media/v4l2-mc.h                         |  65 +++++
 include/uapi/linux/media.h                      |  17 ++
 sound/usb/Kconfig                               |   4 +
 sound/usb/Makefile                              |   2 +
 sound/usb/card.c                                |  14 +
 sound/usb/card.h                                |   3 +
 sound/usb/media.c                               | 318 +++++++++++++++++++++++
 sound/usb/media.h                               |  72 ++++++
 sound/usb/mixer.h                               |   3 +
 sound/usb/pcm.c                                 |  28 +-
 sound/usb/quirks-table.h                        |   1 +
 sound/usb/stream.c                              |   2 +
 sound/usb/usbaudio.h                            |   6 +
 31 files changed, 1240 insertions(+), 220 deletions(-)
 create mode 100644 drivers/media/v4l2-core/v4l2-mc.c
 create mode 100644 sound/usb/media.c
 create mode 100644 sound/usb/media.h

-- 
2.5.0

^ permalink raw reply	[flat|nested] 49+ messages in thread

* [PATCH v3 01/22] [media] Docbook: media-types.xml: Add ALSA Media Controller Intf types
  2016-02-11 23:41 [PATCH v3 00/22] Sharing media resources across ALSA and au0828 drivers Shuah Khan
@ 2016-02-11 23:41 ` Shuah Khan
  2016-02-17 12:19   ` Mauro Carvalho Chehab
  2016-02-11 23:41 ` [PATCH v3 02/22] uapi/media.h: Declare interface types for ALSA Shuah Khan
                   ` (20 subsequent siblings)
  21 siblings, 1 reply; 49+ messages in thread
From: Shuah Khan @ 2016-02-11 23:41 UTC (permalink / raw)
  To: mchehab, tiwai, clemens, hans.verkuil, laurent.pinchart,
	sakari.ailus, javier
  Cc: Shuah Khan, pawel, m.szyprowski, kyungmin.park, perex, arnd,
	dan.carpenter, tvboxspy, crope, ruchandani.tina, corbet,
	chehabrafael, k.kozlowski, stefanr, inki.dae, jh1009.sung,
	elfring, prabhakar.csengg, sw0312.kim, p.zabel, ricardo.ribalda,
	labbott, pierre-louis.bossart, ricard.wanderlof, julian,
	takamichiho, dominic.sacre, misterpib, daniel, gtmkramer,
	normalperson, joe, linuxbugs, johan, klock.android, nenggun.kim,
	j.anaszewski, geliangtang, albert, linux-kernel, linux-media,
	alsa-devel

Add ALSA Media Controller Intf types

Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
---
 Documentation/DocBook/media/v4l/media-types.xml | 40 +++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/Documentation/DocBook/media/v4l/media-types.xml b/Documentation/DocBook/media/v4l/media-types.xml
index 751c3d0..3730967 100644
--- a/Documentation/DocBook/media/v4l/media-types.xml
+++ b/Documentation/DocBook/media/v4l/media-types.xml
@@ -193,6 +193,46 @@
 	    <entry>Device node interface for Software Defined Radio (V4L)</entry>
 	    <entry>typically, /dev/swradio?</entry>
 	  </row>
+	  <row>
+	    <entry><constant>MEDIA_INTF_T_ALSA_PCM_CAPTURE</constant></entry>
+	    <entry>Device node interface for ASLA PCM Capture</entry>
+	    <entry>typically, /dev/snd/pcmC?D?c</entry>
+	  </row>
+	  <row>
+	    <entry><constant>MEDIA_INTF_T_ALSA_PCM_PLAYBACK</constant></entry>
+	    <entry>Device node interface for ASLA PCM Playback</entry>
+	    <entry>typically, /dev/snd/pcmC?D?p</entry>
+	  </row>
+	  <row>
+	    <entry><constant>MEDIA_INTF_T_ALSA_CONTROL</constant></entry>
+	    <entry>Device node interface for ASLA Control</entry>
+	    <entry>typically, /dev/snd/controlC?</entry>
+	  </row>
+	  <row>
+	    <entry><constant>MEDIA_INTF_T_ALSA_COMPRESS</constant></entry>
+	    <entry>Device node interface for ASLA Compress</entry>
+	    <entry>typically, /dev/snd/compr?</entry>
+	  </row>
+	  <row>
+	    <entry><constant>MEDIA_INTF_T_ALSA_RAWMIDI</constant></entry>
+	    <entry>Device node interface for ASLA Raw MIDI</entry>
+	    <entry>typically, /dev/snd/midi?</entry>
+	  </row>
+	  <row>
+	    <entry><constant>MEDIA_INTF_T_ALSA_HWDEP</constant></entry>
+	    <entry>Device node interface for ASLA Hardware Dependent</entry>
+	    <entry>typically, /dev/snd/hwC?D?</entry>
+	  </row>
+	  <row>
+	    <entry><constant>MEDIA_INTF_T_ALSA_SEQUENCER</constant></entry>
+	    <entry>Device node interface for ASLA Sequencer</entry>
+	    <entry>typically, /dev/snd/seq</entry>
+	  </row>
+	  <row>
+	    <entry><constant>MEDIA_INTF_T_ALSA_TIMER</constant></entry>
+	    <entry>Device node interface for ASLA Timer</entry>
+	    <entry>typically, /dev/snd/timer</entry>
+	  </row>
 	</tbody>
       </tgroup>
     </table>
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH v3 02/22] uapi/media.h: Declare interface types for ALSA
  2016-02-11 23:41 [PATCH v3 00/22] Sharing media resources across ALSA and au0828 drivers Shuah Khan
  2016-02-11 23:41 ` [PATCH v3 01/22] [media] Docbook: media-types.xml: Add ALSA Media Controller Intf types Shuah Khan
@ 2016-02-11 23:41 ` Shuah Khan
  2016-02-17 12:21   ` Mauro Carvalho Chehab
  2016-03-03 14:59   ` Hans Verkuil
  2016-02-11 23:41 ` [PATCH v3 03/22] [media] Docbook: media-types.xml: Add Audio Function Entities Shuah Khan
                   ` (19 subsequent siblings)
  21 siblings, 2 replies; 49+ messages in thread
From: Shuah Khan @ 2016-02-11 23:41 UTC (permalink / raw)
  To: mchehab, tiwai, clemens, hans.verkuil, laurent.pinchart,
	sakari.ailus, javier
  Cc: Shuah Khan, pawel, m.szyprowski, kyungmin.park, perex, arnd,
	dan.carpenter, tvboxspy, crope, ruchandani.tina, corbet,
	chehabrafael, k.kozlowski, stefanr, inki.dae, jh1009.sung,
	elfring, prabhakar.csengg, sw0312.kim, p.zabel, ricardo.ribalda,
	labbott, pierre-louis.bossart, ricard.wanderlof, julian,
	takamichiho, dominic.sacre, misterpib, daniel, gtmkramer,
	normalperson, joe, linuxbugs, johan, klock.android, nenggun.kim,
	j.anaszewski, geliangtang, albert, linux-kernel, linux-media,
	alsa-devel

Declare the interface types to be used on alsa for
the new G_TOPOLOGY ioctl.

Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
---
 drivers/media/media-entity.c | 16 ++++++++++++++++
 include/uapi/linux/media.h   | 10 ++++++++++
 2 files changed, 26 insertions(+)

diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index f2e4360..6179543 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -65,6 +65,22 @@ static inline const char *intf_type(struct media_interface *intf)
 		return "v4l2-subdev";
 	case MEDIA_INTF_T_V4L_SWRADIO:
 		return "swradio";
+	case MEDIA_INTF_T_ALSA_PCM_CAPTURE:
+		return "pcm-capture";
+	case MEDIA_INTF_T_ALSA_PCM_PLAYBACK:
+		return "pcm-playback";
+	case MEDIA_INTF_T_ALSA_CONTROL:
+		return "alsa-control";
+	case MEDIA_INTF_T_ALSA_COMPRESS:
+		return "compress";
+	case MEDIA_INTF_T_ALSA_RAWMIDI:
+		return "rawmidi";
+	case MEDIA_INTF_T_ALSA_HWDEP:
+		return "hwdep";
+	case MEDIA_INTF_T_ALSA_SEQUENCER:
+		return "sequencer";
+	case MEDIA_INTF_T_ALSA_TIMER:
+		return "timer";
 	default:
 		return "unknown-intf";
 	}
diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
index c9eb42a..3cc0366 100644
--- a/include/uapi/linux/media.h
+++ b/include/uapi/linux/media.h
@@ -265,6 +265,7 @@ struct media_links_enum {
 
 #define MEDIA_INTF_T_DVB_BASE	0x00000100
 #define MEDIA_INTF_T_V4L_BASE	0x00000200
+#define MEDIA_INTF_T_ALSA_BASE	0x00000300
 
 /* Interface types */
 
@@ -280,6 +281,15 @@ struct media_links_enum {
 #define MEDIA_INTF_T_V4L_SUBDEV (MEDIA_INTF_T_V4L_BASE + 3)
 #define MEDIA_INTF_T_V4L_SWRADIO (MEDIA_INTF_T_V4L_BASE + 4)
 
+#define MEDIA_INTF_T_ALSA_PCM_CAPTURE   (MEDIA_INTF_T_ALSA_BASE)
+#define MEDIA_INTF_T_ALSA_PCM_PLAYBACK  (MEDIA_INTF_T_ALSA_BASE + 1)
+#define MEDIA_INTF_T_ALSA_CONTROL       (MEDIA_INTF_T_ALSA_BASE + 2)
+#define MEDIA_INTF_T_ALSA_COMPRESS      (MEDIA_INTF_T_ALSA_BASE + 3)
+#define MEDIA_INTF_T_ALSA_RAWMIDI       (MEDIA_INTF_T_ALSA_BASE + 4)
+#define MEDIA_INTF_T_ALSA_HWDEP         (MEDIA_INTF_T_ALSA_BASE + 5)
+#define MEDIA_INTF_T_ALSA_SEQUENCER     (MEDIA_INTF_T_ALSA_BASE + 6)
+#define MEDIA_INTF_T_ALSA_TIMER         (MEDIA_INTF_T_ALSA_BASE + 7)
+
 /*
  * MC next gen API definitions
  *
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH v3 03/22] [media] Docbook: media-types.xml: Add Audio Function Entities
  2016-02-11 23:41 [PATCH v3 00/22] Sharing media resources across ALSA and au0828 drivers Shuah Khan
  2016-02-11 23:41 ` [PATCH v3 01/22] [media] Docbook: media-types.xml: Add ALSA Media Controller Intf types Shuah Khan
  2016-02-11 23:41 ` [PATCH v3 02/22] uapi/media.h: Declare interface types for ALSA Shuah Khan
@ 2016-02-11 23:41 ` Shuah Khan
  2016-02-17 12:23   ` Mauro Carvalho Chehab
       [not found]   ` <1886674.Y0SDWvK9bd@avalon>
  2016-02-11 23:41 ` [PATCH v3 04/22] media: Add ALSA Media Controller function entities Shuah Khan
                   ` (18 subsequent siblings)
  21 siblings, 2 replies; 49+ messages in thread
From: Shuah Khan @ 2016-02-11 23:41 UTC (permalink / raw)
  To: mchehab, tiwai, clemens, hans.verkuil, laurent.pinchart,
	sakari.ailus, javier
  Cc: Shuah Khan, pawel, m.szyprowski, kyungmin.park, perex, arnd,
	dan.carpenter, tvboxspy, crope, ruchandani.tina, corbet,
	chehabrafael, k.kozlowski, stefanr, inki.dae, jh1009.sung,
	elfring, prabhakar.csengg, sw0312.kim, p.zabel, ricardo.ribalda,
	labbott, pierre-louis.bossart, ricard.wanderlof, julian,
	takamichiho, dominic.sacre, misterpib, daniel, gtmkramer,
	normalperson, joe, linuxbugs, johan, klock.android, nenggun.kim,
	j.anaszewski, geliangtang, albert, linux-kernel, linux-media,
	alsa-devel

Add Audio Function Entities

Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
---
 Documentation/DocBook/media/v4l/media-types.xml | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/Documentation/DocBook/media/v4l/media-types.xml b/Documentation/DocBook/media/v4l/media-types.xml
index 3730967..924a604 100644
--- a/Documentation/DocBook/media/v4l/media-types.xml
+++ b/Documentation/DocBook/media/v4l/media-types.xml
@@ -113,6 +113,18 @@
 		   decoder.
 	    </entry>
 	  </row>
+	  <row>
+	    <entry><constant>MEDIA_ENT_F_AUDIO_CAPTURE</constant></entry>
+	    <entry>Audio Capture Function Entity.</entry>
+	  </row>
+	  <row>
+	    <entry><constant>MEDIA_ENT_F_AUDIO_PLAYBACK</constant></entry>
+	    <entry>Audio Playback Function Entity.</entry>
+	  </row>
+	  <row>
+	    <entry><constant>MEDIA_ENT_F_AUDIO_MIXER</constant></entry>
+	    <entry>Audio Mixer Function Entity.</entry>
+	  </row>
 	</tbody>
       </tgroup>
     </table>
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH v3 04/22] media: Add ALSA Media Controller function entities
  2016-02-11 23:41 [PATCH v3 00/22] Sharing media resources across ALSA and au0828 drivers Shuah Khan
                   ` (2 preceding siblings ...)
  2016-02-11 23:41 ` [PATCH v3 03/22] [media] Docbook: media-types.xml: Add Audio Function Entities Shuah Khan
@ 2016-02-11 23:41 ` Shuah Khan
  2016-02-17 12:25   ` Mauro Carvalho Chehab
  2016-02-11 23:41 ` [PATCH v3 05/22] media: Media Controller register/unregister entity_notify API Shuah Khan
                   ` (17 subsequent siblings)
  21 siblings, 1 reply; 49+ messages in thread
From: Shuah Khan @ 2016-02-11 23:41 UTC (permalink / raw)
  To: mchehab, tiwai, clemens, hans.verkuil, laurent.pinchart,
	sakari.ailus, javier
  Cc: Shuah Khan, pawel, m.szyprowski, kyungmin.park, perex, arnd,
	dan.carpenter, tvboxspy, crope, ruchandani.tina, corbet,
	chehabrafael, k.kozlowski, stefanr, inki.dae, jh1009.sung,
	elfring, prabhakar.csengg, sw0312.kim, p.zabel, ricardo.ribalda,
	labbott, pierre-louis.bossart, ricard.wanderlof, julian,
	takamichiho, dominic.sacre, misterpib, daniel, gtmkramer,
	normalperson, joe, linuxbugs, johan, klock.android, nenggun.kim,
	j.anaszewski, geliangtang, albert, linux-kernel, linux-media,
	alsa-devel

Add ALSA Media Controller capture, playback, and mixer
function entity defines.

Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
---
 include/uapi/linux/media.h | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
index 3cc0366..449462e 100644
--- a/include/uapi/linux/media.h
+++ b/include/uapi/linux/media.h
@@ -98,6 +98,13 @@ struct media_device_info {
 #define MEDIA_ENT_F_IF_AUD_DECODER	(MEDIA_ENT_F_BASE + 42)
 
 /*
+ * Audio Entity Functions
+ */
+#define MEDIA_ENT_F_AUDIO_CAPTURE	(MEDIA_ENT_F_BASE + 200)
+#define MEDIA_ENT_F_AUDIO_PLAYBACK	(MEDIA_ENT_F_BASE + 201)
+#define MEDIA_ENT_F_AUDIO_MIXER		(MEDIA_ENT_F_BASE + 202)
+
+/*
  * Don't touch on those. The ranges MEDIA_ENT_F_OLD_BASE and
  * MEDIA_ENT_F_OLD_SUBDEV_BASE are kept to keep backward compatibility
  * with the legacy v1 API.The number range is out of range by purpose:
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH v3 05/22] media: Media Controller register/unregister entity_notify API
  2016-02-11 23:41 [PATCH v3 00/22] Sharing media resources across ALSA and au0828 drivers Shuah Khan
                   ` (3 preceding siblings ...)
  2016-02-11 23:41 ` [PATCH v3 04/22] media: Add ALSA Media Controller function entities Shuah Khan
@ 2016-02-11 23:41 ` Shuah Khan
  2016-02-11 23:41 ` [PATCH v3 06/22] media: Media Controller enable/disable source handler API Shuah Khan
                   ` (16 subsequent siblings)
  21 siblings, 0 replies; 49+ messages in thread
From: Shuah Khan @ 2016-02-11 23:41 UTC (permalink / raw)
  To: mchehab, tiwai, clemens, hans.verkuil, laurent.pinchart,
	sakari.ailus, javier
  Cc: Shuah Khan, pawel, m.szyprowski, kyungmin.park, perex, arnd,
	dan.carpenter, tvboxspy, crope, ruchandani.tina, corbet,
	chehabrafael, k.kozlowski, stefanr, inki.dae, jh1009.sung,
	elfring, prabhakar.csengg, sw0312.kim, p.zabel, ricardo.ribalda,
	labbott, pierre-louis.bossart, ricard.wanderlof, julian,
	takamichiho, dominic.sacre, misterpib, daniel, gtmkramer,
	normalperson, joe, linuxbugs, johan, klock.android, nenggun.kim,
	j.anaszewski, geliangtang, albert, linux-kernel, linux-media,
	alsa-devel

Add new interfaces to register and unregister entity_notify
hook to media device. These interfaces allow drivers to add
hooks to take appropriate actions when new entities get added
to a shared media device. For example, au0828 bridge driver
registers an entity_notify hook to create links as needed
between media graph nodes.

Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
---
 drivers/media/media-device.c | 42 +++++++++++++++++++++++++++++++++
 include/media/media-device.h | 56 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 98 insertions(+)

diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index 4d1c13d..9c1cf70 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -536,6 +536,7 @@ static void media_device_release(struct media_devnode *mdev)
 int __must_check media_device_register_entity(struct media_device *mdev,
 					      struct media_entity *entity)
 {
+	struct media_entity_notify *notify, *next;
 	unsigned int i;
 	int ret;
 
@@ -575,6 +576,11 @@ int __must_check media_device_register_entity(struct media_device *mdev,
 		media_gobj_create(mdev, MEDIA_GRAPH_PAD,
 			       &entity->pads[i].graph_obj);
 
+	/* invoke entity_notify callbacks */
+	list_for_each_entry_safe(notify, next, &mdev->entity_notify, list) {
+		(notify)->notify(entity, notify->notify_data);
+	}
+
 	spin_unlock(&mdev->lock);
 
 	return 0;
@@ -608,6 +614,8 @@ static void __media_device_unregister_entity(struct media_entity *entity)
 	/* Remove the entity */
 	media_gobj_destroy(&entity->graph_obj);
 
+	/* invoke entity_notify callbacks to handle entity removal?? */
+
 	entity->graph_obj.mdev = NULL;
 }
 
@@ -640,6 +648,7 @@ void media_device_init(struct media_device *mdev)
 	INIT_LIST_HEAD(&mdev->interfaces);
 	INIT_LIST_HEAD(&mdev->pads);
 	INIT_LIST_HEAD(&mdev->links);
+	INIT_LIST_HEAD(&mdev->entity_notify);
 	spin_lock_init(&mdev->lock);
 	mutex_init(&mdev->graph_mutex);
 	ida_init(&mdev->entity_internal_idx);
@@ -685,11 +694,40 @@ int __must_check __media_device_register(struct media_device *mdev,
 }
 EXPORT_SYMBOL_GPL(__media_device_register);
 
+int __must_check media_device_register_entity_notify(struct media_device *mdev,
+					struct media_entity_notify *nptr)
+{
+	spin_lock(&mdev->lock);
+	list_add_tail(&nptr->list, &mdev->entity_notify);
+	spin_unlock(&mdev->lock);
+	return 0;
+}
+EXPORT_SYMBOL_GPL(media_device_register_entity_notify);
+
+/**
+ * Note: Should be called with mdev->lock held.
+ */
+static void __media_device_unregister_entity_notify(struct media_device *mdev,
+					struct media_entity_notify *nptr)
+{
+	list_del(&nptr->list);
+}
+
+void media_device_unregister_entity_notify(struct media_device *mdev,
+					struct media_entity_notify *nptr)
+{
+	spin_lock(&mdev->lock);
+	__media_device_unregister_entity_notify(mdev, nptr);
+	spin_unlock(&mdev->lock);
+}
+EXPORT_SYMBOL_GPL(media_device_unregister_entity_notify);
+
 void media_device_unregister(struct media_device *mdev)
 {
 	struct media_entity *entity;
 	struct media_entity *next;
 	struct media_interface *intf, *tmp_intf;
+	struct media_entity_notify *notify, *nextp;
 
 	if (mdev == NULL)
 		return;
@@ -706,6 +744,10 @@ void media_device_unregister(struct media_device *mdev)
 	list_for_each_entry_safe(entity, next, &mdev->entities, graph_obj.list)
 		__media_device_unregister_entity(entity);
 
+	/* Remove all entity_notify callbacks from the media device */
+	list_for_each_entry_safe(notify, nextp, &mdev->entity_notify, list)
+		__media_device_unregister_entity_notify(mdev, notify);
+
 	/* Remove all interfaces from the media device */
 	list_for_each_entry_safe(intf, tmp_intf, &mdev->interfaces,
 				 graph_obj.list) {
diff --git a/include/media/media-device.h b/include/media/media-device.h
index d385589..075a482 100644
--- a/include/media/media-device.h
+++ b/include/media/media-device.h
@@ -265,6 +265,22 @@ struct ida;
 struct device;
 
 /**
+ * struct media_entity_notify - Media Entity Notify
+ *
+ * @list: List head
+ * @notify_data: Input data to invoke the callback
+ * @notify: Callback function pointer
+ *
+ * Drivers may register a callback to take action when
+ * new entities get registered with the media device.
+ */
+struct media_entity_notify {
+	struct list_head list;
+	void *notify_data;
+	void (*notify)(struct media_entity *entity, void *notify_data);
+};
+
+/**
  * struct media_device - Media device
  * @dev:	Parent device
  * @devnode:	Media device node
@@ -283,6 +299,7 @@ struct device;
  * @interfaces:	List of registered interfaces
  * @pads:	List of registered pads
  * @links:	List of registered links
+ * @entity_notify: List of registered entity_notify callbacks
  * @lock:	Entities list lock
  * @graph_mutex: Entities graph operation lock
  * @link_notify: Link state change notification callback
@@ -319,6 +336,9 @@ struct media_device {
 	struct list_head pads;
 	struct list_head links;
 
+	/* notify callback list invoked when a new entity is registered */
+	struct list_head entity_notify;
+
 	/* Protects the graph objects creation/removal */
 	spinlock_t lock;
 	/* Serializes graph operations. */
@@ -498,6 +518,31 @@ int __must_check media_device_register_entity(struct media_device *mdev,
 void media_device_unregister_entity(struct media_entity *entity);
 
 /**
+ * media_device_register_entity_notify() - Registers a media entity_notify
+ *					   callback
+ *
+ * @mdev:      The media device
+ * @nptr:      The media_entity_notify
+ *
+ * Note: When a new entity is registered, all the registered
+ * media_entity_notify callbacks are invoked.
+ */
+
+int __must_check media_device_register_entity_notify(struct media_device *mdev,
+					struct media_entity_notify *nptr);
+
+/**
+ * media_device_unregister_entity_notify() - Unregister a media entity notify
+ *					     callback
+ *
+ * @mdev:      The media device
+ * @nptr:      The media_entity_notify
+ *
+ */
+void media_device_unregister_entity_notify(struct media_device *mdev,
+					struct media_entity_notify *nptr);
+
+/**
  * media_device_get_devres() -	get media device as device resource
  *				creates if one doesn't exist
  *
@@ -552,6 +597,17 @@ static inline int media_device_register_entity(struct media_device *mdev,
 static inline void media_device_unregister_entity(struct media_entity *entity)
 {
 }
+static inline int media_device_register_entity_notify(
+					struct media_device *mdev,
+					struct media_entity_notify *nptr)
+{
+	return 0;
+}
+static inline void media_device_unregister_entity_notify(
+					struct media_device *mdev,
+					struct media_entity_notify *nptr)
+{
+}
 static inline struct media_device *media_device_get_devres(struct device *dev)
 {
 	return NULL;
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH v3 06/22] media: Media Controller enable/disable source handler API
  2016-02-11 23:41 [PATCH v3 00/22] Sharing media resources across ALSA and au0828 drivers Shuah Khan
                   ` (4 preceding siblings ...)
  2016-02-11 23:41 ` [PATCH v3 05/22] media: Media Controller register/unregister entity_notify API Shuah Khan
@ 2016-02-11 23:41 ` Shuah Khan
  2016-03-10  7:35   ` Sakari Ailus
  2016-02-11 23:41 ` [PATCH v3 07/22] media: Media Controller export non locking __media_entity_setup_link() Shuah Khan
                   ` (15 subsequent siblings)
  21 siblings, 1 reply; 49+ messages in thread
From: Shuah Khan @ 2016-02-11 23:41 UTC (permalink / raw)
  To: mchehab, tiwai, clemens, hans.verkuil, laurent.pinchart,
	sakari.ailus, javier
  Cc: Shuah Khan, pawel, m.szyprowski, kyungmin.park, perex, arnd,
	dan.carpenter, tvboxspy, crope, ruchandani.tina, corbet,
	chehabrafael, k.kozlowski, stefanr, inki.dae, jh1009.sung,
	elfring, prabhakar.csengg, sw0312.kim, p.zabel, ricardo.ribalda,
	labbott, pierre-louis.bossart, ricard.wanderlof, julian,
	takamichiho, dominic.sacre, misterpib, daniel, gtmkramer,
	normalperson, joe, linuxbugs, johan, klock.android, nenggun.kim,
	j.anaszewski, geliangtang, albert, linux-kernel, linux-media,
	alsa-devel

Add new fields to struct media_device to add enable_source, and
disable_source handlers, and source_priv to stash driver private
data that is used to run these handlers. The enable_source handler
finds source entity for the passed in entity and checks if it is
available. When link is found, it activates it. Disable source
handler deactivates the link.

Bridge driver is expected to implement and set these handlers.

Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
---
 include/media/media-device.h | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/include/media/media-device.h b/include/media/media-device.h
index 075a482..1a04644 100644
--- a/include/media/media-device.h
+++ b/include/media/media-device.h
@@ -302,6 +302,11 @@ struct media_entity_notify {
  * @entity_notify: List of registered entity_notify callbacks
  * @lock:	Entities list lock
  * @graph_mutex: Entities graph operation lock
+ *
+ * @source_priv: Driver Private data for enable/disable source handlers
+ * @enable_source: Enable Source Handler function pointer
+ * @disable_source: Disable Source Handler function pointer
+ *
  * @link_notify: Link state change notification callback
  *
  * This structure represents an abstract high-level media device. It allows easy
@@ -313,6 +318,26 @@ struct media_entity_notify {
  *
  * @model is a descriptive model name exported through sysfs. It doesn't have to
  * be unique.
+ *
+ * @enable_source is a handler to find source entity for the
+ * sink entity  and activate the link between them if source
+ * entity is free. Drivers should call this handler before
+ * accessing the source.
+ *
+ * @disable_source is a handler to find source entity for the
+ * sink entity  and deactivate the link between them. Drivers
+ * should call this handler to release the source.
+ *
+ * Note: Bridge driver is expected to implement and set the
+ * handler when media_device is registered or when
+ * bridge driver finds the media_device during probe.
+ * Bridge driver sets source_priv with information
+ * necessary to run enable/disable source handlers.
+ *
+ * Use-case: find tuner entity connected to the decoder
+ * entity and check if it is available, and activate the
+ * the link between them from enable_source and deactivate
+ * from disable_source.
  */
 struct media_device {
 	/* dev->driver_data points to this struct. */
@@ -344,6 +369,11 @@ struct media_device {
 	/* Serializes graph operations. */
 	struct mutex graph_mutex;
 
+	void *source_priv;
+	int (*enable_source)(struct media_entity *entity,
+			     struct media_pipeline *pipe);
+	void (*disable_source)(struct media_entity *entity);
+
 	int (*link_notify)(struct media_link *link, u32 flags,
 			   unsigned int notification);
 };
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH v3 07/22] media: Media Controller export non locking __media_entity_setup_link()
  2016-02-11 23:41 [PATCH v3 00/22] Sharing media resources across ALSA and au0828 drivers Shuah Khan
                   ` (5 preceding siblings ...)
  2016-02-11 23:41 ` [PATCH v3 06/22] media: Media Controller enable/disable source handler API Shuah Khan
@ 2016-02-11 23:41 ` Shuah Khan
  2016-02-11 23:41 ` [PATCH v3 08/22] media: Media Controller non-locking __media_entity_pipeline_start/stop() Shuah Khan
                   ` (14 subsequent siblings)
  21 siblings, 0 replies; 49+ messages in thread
From: Shuah Khan @ 2016-02-11 23:41 UTC (permalink / raw)
  To: mchehab, tiwai, clemens, hans.verkuil, laurent.pinchart,
	sakari.ailus, javier
  Cc: Shuah Khan, pawel, m.szyprowski, kyungmin.park, perex, arnd,
	dan.carpenter, tvboxspy, crope, ruchandani.tina, corbet,
	chehabrafael, k.kozlowski, stefanr, inki.dae, jh1009.sung,
	elfring, prabhakar.csengg, sw0312.kim, p.zabel, ricardo.ribalda,
	labbott, pierre-louis.bossart, ricard.wanderlof, julian,
	takamichiho, dominic.sacre, misterpib, daniel, gtmkramer,
	normalperson, joe, linuxbugs, johan, klock.android, nenggun.kim,
	j.anaszewski, geliangtang, albert, linux-kernel, linux-media,
	alsa-devel

Export __media_entity_setup_link() to be used from code paths
that hold the graph_mutex.

Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
---
 drivers/media/media-entity.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index 6179543..9b4d712 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -805,6 +805,7 @@ int __media_entity_setup_link(struct media_link *link, u32 flags)
 
 	return ret;
 }
+EXPORT_SYMBOL_GPL(__media_entity_setup_link);
 
 int media_entity_setup_link(struct media_link *link, u32 flags)
 {
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH v3 08/22] media: Media Controller non-locking __media_entity_pipeline_start/stop()
  2016-02-11 23:41 [PATCH v3 00/22] Sharing media resources across ALSA and au0828 drivers Shuah Khan
                   ` (6 preceding siblings ...)
  2016-02-11 23:41 ` [PATCH v3 07/22] media: Media Controller export non locking __media_entity_setup_link() Shuah Khan
@ 2016-02-11 23:41 ` Shuah Khan
  2016-02-11 23:41 ` [PATCH v3 09/22] media: v4l-core add enable/disable source common interfaces Shuah Khan
                   ` (13 subsequent siblings)
  21 siblings, 0 replies; 49+ messages in thread
From: Shuah Khan @ 2016-02-11 23:41 UTC (permalink / raw)
  To: mchehab, tiwai, clemens, hans.verkuil, laurent.pinchart,
	sakari.ailus, javier
  Cc: Shuah Khan, pawel, m.szyprowski, kyungmin.park, perex, arnd,
	dan.carpenter, tvboxspy, crope, ruchandani.tina, corbet,
	chehabrafael, k.kozlowski, stefanr, inki.dae, jh1009.sung,
	elfring, prabhakar.csengg, sw0312.kim, p.zabel, ricardo.ribalda,
	labbott, pierre-louis.bossart, ricard.wanderlof, julian,
	takamichiho, dominic.sacre, misterpib, daniel, gtmkramer,
	normalperson, joe, linuxbugs, johan, klock.android, nenggun.kim,
	j.anaszewski, geliangtang, albert, linux-kernel, linux-media,
	alsa-devel

Add non-locking __media_entity_pipeline_start/stop()
interfaces to be called from code paths that hold the
graph_mutex.

Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
---
 drivers/media/media-entity.c | 34 ++++++++++++++++++++++++----------
 include/media/media-entity.h | 19 +++++++++++++++++++
 2 files changed, 43 insertions(+), 10 deletions(-)

diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index 9b4d712..b78e4c2 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -365,8 +365,8 @@ EXPORT_SYMBOL_GPL(media_entity_graph_walk_next);
  * Pipeline management
  */
 
-__must_check int media_entity_pipeline_start(struct media_entity *entity,
-					     struct media_pipeline *pipe)
+__must_check int __media_entity_pipeline_start(struct media_entity *entity,
+					       struct media_pipeline *pipe)
 {
 	struct media_device *mdev = entity->graph_obj.mdev;
 	struct media_entity_graph *graph = &pipe->graph;
@@ -374,8 +374,6 @@ __must_check int media_entity_pipeline_start(struct media_entity *entity,
 	struct media_link *link;
 	int ret;
 
-	mutex_lock(&mdev->graph_mutex);
-
 	if (!pipe->streaming_count++) {
 		ret = media_entity_graph_walk_init(&pipe->graph, mdev);
 		if (ret)
@@ -456,8 +454,6 @@ __must_check int media_entity_pipeline_start(struct media_entity *entity,
 		}
 	}
 
-	mutex_unlock(&mdev->graph_mutex);
-
 	return 0;
 
 error:
@@ -487,19 +483,28 @@ error_graph_walk_start:
 	if (!--pipe->streaming_count)
 		media_entity_graph_walk_cleanup(graph);
 
-	mutex_unlock(&mdev->graph_mutex);
+	return ret;
+}
+EXPORT_SYMBOL_GPL(__media_entity_pipeline_start);
 
+__must_check int media_entity_pipeline_start(struct media_entity *entity,
+					     struct media_pipeline *pipe)
+{
+	struct media_device *mdev = entity->graph_obj.mdev;
+	int ret;
+
+	mutex_lock(&mdev->graph_mutex);
+	ret = __media_entity_pipeline_start(entity, pipe);
+	mutex_unlock(&mdev->graph_mutex);
 	return ret;
 }
 EXPORT_SYMBOL_GPL(media_entity_pipeline_start);
 
-void media_entity_pipeline_stop(struct media_entity *entity)
+void __media_entity_pipeline_stop(struct media_entity *entity)
 {
-	struct media_device *mdev = entity->graph_obj.mdev;
 	struct media_entity_graph *graph = &entity->pipe->graph;
 	struct media_pipeline *pipe = entity->pipe;
 
-	mutex_lock(&mdev->graph_mutex);
 
 	WARN_ON(!pipe->streaming_count);
 	media_entity_graph_walk_start(graph, entity);
@@ -516,6 +521,15 @@ void media_entity_pipeline_stop(struct media_entity *entity)
 	if (!--pipe->streaming_count)
 		media_entity_graph_walk_cleanup(graph);
 
+}
+EXPORT_SYMBOL_GPL(__media_entity_pipeline_stop);
+
+void media_entity_pipeline_stop(struct media_entity *entity)
+{
+	struct media_device *mdev = entity->graph_obj.mdev;
+
+	mutex_lock(&mdev->graph_mutex);
+	__media_entity_pipeline_stop(entity);
 	mutex_unlock(&mdev->graph_mutex);
 }
 EXPORT_SYMBOL_GPL(media_entity_pipeline_stop);
diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index fe485d3..d58e29d 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -832,6 +832,16 @@ media_entity_graph_walk_next(struct media_entity_graph *graph);
  */
 __must_check int media_entity_pipeline_start(struct media_entity *entity,
 					     struct media_pipeline *pipe);
+/**
+ * __media_entity_pipeline_start - Mark a pipeline as streaming
+ *
+ * @entity: Starting entity
+ * @pipe: Media pipeline to be assigned to all entities in the pipeline.
+ *
+ * Note: This is the non-locking version of media_entity_pipeline_start()
+ */
+__must_check int __media_entity_pipeline_start(struct media_entity *entity,
+					       struct media_pipeline *pipe);
 
 /**
  * media_entity_pipeline_stop - Mark a pipeline as not streaming
@@ -848,6 +858,15 @@ __must_check int media_entity_pipeline_start(struct media_entity *entity,
 void media_entity_pipeline_stop(struct media_entity *entity);
 
 /**
+ * __media_entity_pipeline_stop - Mark a pipeline as not streaming
+ *
+ * @entity: Starting entity
+ *
+ * Note: This is the non-locking version of media_entity_pipeline_stop()
+ */
+void __media_entity_pipeline_stop(struct media_entity *entity);
+
+/**
  * media_devnode_create() - creates and initializes a device node interface
  *
  * @mdev:	pointer to struct &media_device
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH v3 09/22] media: v4l-core add enable/disable source common interfaces
  2016-02-11 23:41 [PATCH v3 00/22] Sharing media resources across ALSA and au0828 drivers Shuah Khan
                   ` (7 preceding siblings ...)
  2016-02-11 23:41 ` [PATCH v3 08/22] media: Media Controller non-locking __media_entity_pipeline_start/stop() Shuah Khan
@ 2016-02-11 23:41 ` Shuah Khan
  2016-02-11 23:41 ` [PATCH v3 10/22] media: Move au8522_media_pads enum to au8522.h from au8522_priv.h Shuah Khan
                   ` (12 subsequent siblings)
  21 siblings, 0 replies; 49+ messages in thread
From: Shuah Khan @ 2016-02-11 23:41 UTC (permalink / raw)
  To: mchehab, tiwai, clemens, hans.verkuil, laurent.pinchart,
	sakari.ailus, javier
  Cc: Shuah Khan, pawel, m.szyprowski, kyungmin.park, perex, arnd,
	dan.carpenter, tvboxspy, crope, ruchandani.tina, corbet,
	chehabrafael, k.kozlowski, stefanr, inki.dae, jh1009.sung,
	elfring, prabhakar.csengg, sw0312.kim, p.zabel, ricardo.ribalda,
	labbott, pierre-louis.bossart, ricard.wanderlof, julian,
	takamichiho, dominic.sacre, misterpib, daniel, gtmkramer,
	normalperson, joe, linuxbugs, johan, klock.android, nenggun.kim,
	j.anaszewski, geliangtang, albert, linux-kernel, linux-media,
	alsa-devel

Add a new interfaces to be used by v4l-core to invoke enable
source and disable_source handlers in the media_device. The
enable_source helper function invokes the enable_source handler
to find media source entity connected to the entity and check
is it is available or busy. If source is available, link is
activated and pipeline is started. The disable_source helper
function invokes the disable_source handler to deactivate and
stop the pipeline.

Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
---
 drivers/media/v4l2-core/Makefile  |  1 +
 drivers/media/v4l2-core/v4l2-mc.c | 52 +++++++++++++++++++++++++++++++
 include/media/v4l2-dev.h          |  1 +
 include/media/v4l2-mc.h           | 65 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 119 insertions(+)
 create mode 100644 drivers/media/v4l2-core/v4l2-mc.c

diff --git a/drivers/media/v4l2-core/Makefile b/drivers/media/v4l2-core/Makefile
index 1dc8bba..795a535 100644
--- a/drivers/media/v4l2-core/Makefile
+++ b/drivers/media/v4l2-core/Makefile
@@ -16,6 +16,7 @@ endif
 ifeq ($(CONFIG_TRACEPOINTS),y)
   videodev-objs += vb2-trace.o v4l2-trace.o
 endif
+videodev-$(CONFIG_MEDIA_CONTROLLER) += v4l2-mc.o
 
 obj-$(CONFIG_VIDEO_V4L2) += videodev.o
 obj-$(CONFIG_VIDEO_V4L2) += v4l2-common.o
diff --git a/drivers/media/v4l2-core/v4l2-mc.c b/drivers/media/v4l2-core/v4l2-mc.c
new file mode 100644
index 0000000..3a8addf
--- /dev/null
+++ b/drivers/media/v4l2-core/v4l2-mc.c
@@ -0,0 +1,52 @@
+/*
+ * v4l2-mc.c - Media Controller V4L2 Common Interfaces
+ *
+ * Copyright (C) 2016 Shuah Khan <shuahkh@osg.samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <media/v4l2-mc.h>
+#include <media/media-device.h>
+#include <media/videobuf2-core.h>
+#include <media/v4l2-fh.h>
+
+int v4l_enable_media_source(struct video_device *vdev)
+{
+	struct media_device *mdev = vdev->entity.graph_obj.mdev;
+	int ret;
+
+	if (!mdev || !mdev->enable_source)
+		return 0;
+	ret = mdev->enable_source(&vdev->entity, &vdev->pipe);
+	if (ret)
+		return -EBUSY;
+	return 0;
+}
+EXPORT_SYMBOL_GPL(v4l_enable_media_source);
+
+void v4l_disable_media_source(struct video_device *vdev)
+{
+	struct media_device *mdev = vdev->entity.graph_obj.mdev;
+
+	if (mdev && mdev->disable_source)
+		mdev->disable_source(&vdev->entity);
+}
+EXPORT_SYMBOL_GPL(v4l_disable_media_source);
+
+int v4l_vb2q_enable_media_source(struct vb2_queue *q)
+{
+	struct v4l2_fh *fh = q->owner;
+
+	return v4l_enable_media_source(fh->vdev);
+}
+EXPORT_SYMBOL_GPL(v4l_vb2q_enable_media_source);
+
diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
index eeabf20..76056ab 100644
--- a/include/media/v4l2-dev.h
+++ b/include/media/v4l2-dev.h
@@ -87,6 +87,7 @@ struct video_device
 #if defined(CONFIG_MEDIA_CONTROLLER)
 	struct media_entity entity;
 	struct media_intf_devnode *intf_devnode;
+	struct media_pipeline pipe;
 #endif
 	/* device ops */
 	const struct v4l2_file_operations *fops;
diff --git a/include/media/v4l2-mc.h b/include/media/v4l2-mc.h
index df11519..c31b537 100644
--- a/include/media/v4l2-mc.h
+++ b/include/media/v4l2-mc.h
@@ -14,6 +14,11 @@
  * GNU General Public License for more details.
  */
 
+#ifndef _V4L2_MC_H
+#define _V4L2_MC_H
+
+#include <media/v4l2-dev.h>
+
 /**
  * enum tuner_pad_index - tuner pad index for MEDIA_ENT_F_TUNER
  *
@@ -89,3 +94,63 @@ enum demod_pad_index {
 	DEMOD_PAD_VBI_OUT,
 	DEMOD_NUM_PADS
 };
+
+/**
+ * v4l_enable_media_source() -	Hold media source for exclusive use
+ *				if free
+ *
+ * @vdev - poniter to struct video_device
+ *
+ * This interface calls enable_source handler to determine if
+ * media source is free for use. The enable_source handler is
+ * responsible for checking is the media source is free and
+ * start a pipeline between the media source and the media
+ * entity associated with the video device. This interface
+ * should be called from v4l2-core and dvb-core interfaces
+ * that change the source configuration.
+ *
+ * Return: returns zero on success or a negative error code.
+ */
+#ifdef CONFIG_MEDIA_CONTROLLER
+int v4l_enable_media_source(struct video_device *vdev);
+#else
+static int v4l_enable_media_source(struct video_device *vdev) { return 0; }
+#endif
+
+/**
+ * v4l_disable_media_source() -	Release media source
+ *
+ * @vdev - poniter to struct video_device
+ *
+ * This interface calls disable_source handler to release
+ * the media source. The disable_source handler stops the
+ * active media pipeline between the media source and the
+ * media entity associated with the video device.
+ *
+ * Return: returns zero on success or a negative error code.
+ */
+#ifdef CONFIG_MEDIA_CONTROLLER
+void v4l_disable_media_source(struct video_device *vdev);
+#else
+static void v4l_disable_media_source(struct video_device *vdev) { return; }
+#endif
+
+/*
+ * v4l_vb2q_enable_media_tuner -  Hold media source for exclusive use
+ *				  if free.
+ * @q - pointer to struct vb2_queue
+ *
+ * Wrapper for v4l_enable_media_source(). This function should
+ * be called from v4l2-core to enable the media source with
+ * pointer to struct vb2_queue as the input argument. Some
+ * v4l2-core interfaces don't have access to video device and
+ * this interface finds the struct video_device for the q and
+ * calls v4l_enable_media_source().
+ */
+#ifdef CONFIG_MEDIA_CONTROLLER
+int v4l_vb2q_enable_media_source(struct vb2_queue *q);
+#else
+static int v4l_vb2q_enable_media_source(struct vb2_queue *q) { return 0; }
+#endif
+
+#endif /* _V4L2_MC_H */
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH v3 10/22] media: Move au8522_media_pads enum to au8522.h from au8522_priv.h
  2016-02-11 23:41 [PATCH v3 00/22] Sharing media resources across ALSA and au0828 drivers Shuah Khan
                   ` (8 preceding siblings ...)
  2016-02-11 23:41 ` [PATCH v3 09/22] media: v4l-core add enable/disable source common interfaces Shuah Khan
@ 2016-02-11 23:41 ` Shuah Khan
  2016-02-11 23:41 ` [PATCH v3 11/22] media: au8522 change to create MC pad for ALSA Audio Out Shuah Khan
                   ` (11 subsequent siblings)
  21 siblings, 0 replies; 49+ messages in thread
From: Shuah Khan @ 2016-02-11 23:41 UTC (permalink / raw)
  To: mchehab, tiwai, clemens, hans.verkuil, laurent.pinchart,
	sakari.ailus, javier
  Cc: Shuah Khan, pawel, m.szyprowski, kyungmin.park, perex, arnd,
	dan.carpenter, tvboxspy, crope, ruchandani.tina, corbet,
	chehabrafael, k.kozlowski, stefanr, inki.dae, jh1009.sung,
	elfring, prabhakar.csengg, sw0312.kim, p.zabel, ricardo.ribalda,
	labbott, pierre-louis.bossart, ricard.wanderlof, julian,
	takamichiho, dominic.sacre, misterpib, daniel, gtmkramer,
	normalperson, joe, linuxbugs, johan, klock.android, nenggun.kim,
	j.anaszewski, geliangtang, albert, linux-kernel, linux-media,
	alsa-devel

Move the au8522_media_pads enum to au8522.h
from au8522_priv.h to export them. This will
allow au0828-core to use these defines instead
of hard-coding them them.

Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
---
 drivers/media/dvb-frontends/au8522.h      | 7 +++++++
 drivers/media/dvb-frontends/au8522_priv.h | 8 --------
 2 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/drivers/media/dvb-frontends/au8522.h b/drivers/media/dvb-frontends/au8522.h
index dde6158..3c72f40 100644
--- a/drivers/media/dvb-frontends/au8522.h
+++ b/drivers/media/dvb-frontends/au8522.h
@@ -90,4 +90,11 @@ enum au8522_audio_input {
 	AU8522_AUDIO_SIF,
 };
 
+enum au8522_media_pads {
+	AU8522_PAD_INPUT,
+	AU8522_PAD_VID_OUT,
+	AU8522_PAD_VBI_OUT,
+
+	AU8522_NUM_PADS
+};
 #endif /* __AU8522_H__ */
diff --git a/drivers/media/dvb-frontends/au8522_priv.h b/drivers/media/dvb-frontends/au8522_priv.h
index 404a0cb..505215a 100644
--- a/drivers/media/dvb-frontends/au8522_priv.h
+++ b/drivers/media/dvb-frontends/au8522_priv.h
@@ -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;
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH v3 11/22] media: au8522 change to create MC pad for ALSA Audio Out
  2016-02-11 23:41 [PATCH v3 00/22] Sharing media resources across ALSA and au0828 drivers Shuah Khan
                   ` (9 preceding siblings ...)
  2016-02-11 23:41 ` [PATCH v3 10/22] media: Move au8522_media_pads enum to au8522.h from au8522_priv.h Shuah Khan
@ 2016-02-11 23:41 ` Shuah Khan
  2016-02-11 23:41 ` [PATCH v3 12/22] media: au0828 Use au8522_media_pads enum for pad defines Shuah Khan
                   ` (10 subsequent siblings)
  21 siblings, 0 replies; 49+ messages in thread
From: Shuah Khan @ 2016-02-11 23:41 UTC (permalink / raw)
  To: mchehab, tiwai, clemens, hans.verkuil, laurent.pinchart,
	sakari.ailus, javier
  Cc: Shuah Khan, pawel, m.szyprowski, kyungmin.park, perex, arnd,
	dan.carpenter, tvboxspy, crope, ruchandani.tina, corbet,
	chehabrafael, k.kozlowski, stefanr, inki.dae, jh1009.sung,
	elfring, prabhakar.csengg, sw0312.kim, p.zabel, ricardo.ribalda,
	labbott, pierre-louis.bossart, ricard.wanderlof, julian,
	takamichiho, dominic.sacre, misterpib, daniel, gtmkramer,
	normalperson, joe, linuxbugs, johan, klock.android, nenggun.kim,
	j.anaszewski, geliangtang, albert, linux-kernel, linux-media,
	alsa-devel

Add new pad for ALSA Audio Out to au8522_media_pads.

Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
---
 drivers/media/dvb-frontends/au8522.h         | 1 +
 drivers/media/dvb-frontends/au8522_decoder.c | 1 +
 2 files changed, 2 insertions(+)

diff --git a/drivers/media/dvb-frontends/au8522.h b/drivers/media/dvb-frontends/au8522.h
index 3c72f40..d7a997f 100644
--- a/drivers/media/dvb-frontends/au8522.h
+++ b/drivers/media/dvb-frontends/au8522.h
@@ -94,6 +94,7 @@ enum au8522_media_pads {
 	AU8522_PAD_INPUT,
 	AU8522_PAD_VID_OUT,
 	AU8522_PAD_VBI_OUT,
+	AU8522_PAD_AUDIO_OUT,
 
 	AU8522_NUM_PADS
 };
diff --git a/drivers/media/dvb-frontends/au8522_decoder.c b/drivers/media/dvb-frontends/au8522_decoder.c
index 73612c5..0ab9f1e 100644
--- a/drivers/media/dvb-frontends/au8522_decoder.c
+++ b/drivers/media/dvb-frontends/au8522_decoder.c
@@ -766,6 +766,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_SOURCE;
 	sd->entity.function = MEDIA_ENT_F_ATV_DECODER;
 
 	ret = media_entity_pads_init(&sd->entity, ARRAY_SIZE(state->pads),
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH v3 12/22] media: au0828 Use au8522_media_pads enum for pad defines
  2016-02-11 23:41 [PATCH v3 00/22] Sharing media resources across ALSA and au0828 drivers Shuah Khan
                   ` (10 preceding siblings ...)
  2016-02-11 23:41 ` [PATCH v3 11/22] media: au8522 change to create MC pad for ALSA Audio Out Shuah Khan
@ 2016-02-11 23:41 ` Shuah Khan
  2016-02-11 23:41 ` [PATCH v3 13/22] media: Change v4l-core to check if source is free Shuah Khan
                   ` (9 subsequent siblings)
  21 siblings, 0 replies; 49+ messages in thread
From: Shuah Khan @ 2016-02-11 23:41 UTC (permalink / raw)
  To: mchehab, tiwai, clemens, hans.verkuil, laurent.pinchart,
	sakari.ailus, javier
  Cc: Shuah Khan, pawel, m.szyprowski, kyungmin.park, perex, arnd,
	dan.carpenter, tvboxspy, crope, ruchandani.tina, corbet,
	chehabrafael, k.kozlowski, stefanr, inki.dae, jh1009.sung,
	elfring, prabhakar.csengg, sw0312.kim, p.zabel, ricardo.ribalda,
	labbott, pierre-louis.bossart, ricard.wanderlof, julian,
	takamichiho, dominic.sacre, misterpib, daniel, gtmkramer,
	normalperson, joe, linuxbugs, johan, klock.android, nenggun.kim,
	j.anaszewski, geliangtang, albert, linux-kernel, linux-media,
	alsa-devel

Change au0828-core to use au8522_media_pads enum defines
instead of hard-coding the pad values.

Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
---
 drivers/media/usb/au0828/au0828-core.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/media/usb/au0828/au0828-core.c b/drivers/media/usb/au0828/au0828-core.c
index df2bc3f..ce5afea 100644
--- a/drivers/media/usb/au0828/au0828-core.c
+++ b/drivers/media/usb/au0828/au0828-core.c
@@ -20,6 +20,7 @@
  */
 
 #include "au0828.h"
+#include "au8522.h"
 
 #include <linux/module.h>
 #include <linux/slab.h>
@@ -282,11 +283,13 @@ static int au0828_create_media_graph(struct au0828_dev *dev)
 		if (ret)
 			return ret;
 	}
-	ret = media_create_pad_link(decoder, 1, &dev->vdev.entity, 0,
+	ret = media_create_pad_link(decoder, AU8522_PAD_VID_OUT,
+				    &dev->vdev.entity, 0,
 				    MEDIA_LNK_FL_ENABLED);
 	if (ret)
 		return ret;
-	ret = media_create_pad_link(decoder, 2, &dev->vbi_dev.entity, 0,
+	ret = media_create_pad_link(decoder, AU8522_PAD_VBI_OUT,
+				    &dev->vbi_dev.entity, 0,
 				    MEDIA_LNK_FL_ENABLED);
 	if (ret)
 		return ret;
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH v3 13/22] media: Change v4l-core to check if source is free
  2016-02-11 23:41 [PATCH v3 00/22] Sharing media resources across ALSA and au0828 drivers Shuah Khan
                   ` (11 preceding siblings ...)
  2016-02-11 23:41 ` [PATCH v3 12/22] media: au0828 Use au8522_media_pads enum for pad defines Shuah Khan
@ 2016-02-11 23:41 ` Shuah Khan
  2016-02-11 23:41 ` [PATCH v3 14/22] media: au0828 change to use Managed Media Controller API Shuah Khan
                   ` (8 subsequent siblings)
  21 siblings, 0 replies; 49+ messages in thread
From: Shuah Khan @ 2016-02-11 23:41 UTC (permalink / raw)
  To: mchehab, tiwai, clemens, hans.verkuil, laurent.pinchart,
	sakari.ailus, javier
  Cc: Shuah Khan, pawel, m.szyprowski, kyungmin.park, perex, arnd,
	dan.carpenter, tvboxspy, crope, ruchandani.tina, corbet,
	chehabrafael, k.kozlowski, stefanr, inki.dae, jh1009.sung,
	elfring, prabhakar.csengg, sw0312.kim, p.zabel, ricardo.ribalda,
	labbott, pierre-louis.bossart, ricard.wanderlof, julian,
	takamichiho, dominic.sacre, misterpib, daniel, gtmkramer,
	normalperson, joe, linuxbugs, johan, klock.android, nenggun.kim,
	j.anaszewski, geliangtang, albert, linux-kernel, linux-media,
	alsa-devel

Change s_input, s_fmt, s_tuner, s_frequency, querystd,
s_hw_freq_seek, and vb2_core_streamon interfaces that
alter the tuner configuration to check if it is free,
by calling v4l_enable_media_source(). If source isn't
free, return -EBUSY. v4l_disable_media_source() is
called from v4l2_fh_exit() to release tuner (source).
vb2_core_streamon() uses v4l_vb2q_enable_media_source().

Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
---
 drivers/media/v4l2-core/v4l2-fh.c        |  2 ++
 drivers/media/v4l2-core/v4l2-ioctl.c     | 30 ++++++++++++++++++++++++++++++
 drivers/media/v4l2-core/videobuf2-core.c |  4 ++++
 3 files changed, 36 insertions(+)

diff --git a/drivers/media/v4l2-core/v4l2-fh.c b/drivers/media/v4l2-core/v4l2-fh.c
index c97067a..c183f09 100644
--- a/drivers/media/v4l2-core/v4l2-fh.c
+++ b/drivers/media/v4l2-core/v4l2-fh.c
@@ -29,6 +29,7 @@
 #include <media/v4l2-fh.h>
 #include <media/v4l2-event.h>
 #include <media/v4l2-ioctl.h>
+#include <media/v4l2-mc.h>
 
 void v4l2_fh_init(struct v4l2_fh *fh, struct video_device *vdev)
 {
@@ -92,6 +93,7 @@ void v4l2_fh_exit(struct v4l2_fh *fh)
 {
 	if (fh->vdev == NULL)
 		return;
+	v4l_disable_media_source(fh->vdev);
 	v4l2_event_unsubscribe_all(fh);
 	fh->vdev = NULL;
 }
diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
index 8a018c6..ceaa44a 100644
--- a/drivers/media/v4l2-core/v4l2-ioctl.c
+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
@@ -27,6 +27,7 @@
 #include <media/v4l2-event.h>
 #include <media/v4l2-device.h>
 #include <media/videobuf2-v4l2.h>
+#include <media/v4l2-mc.h>
 
 #include <trace/events/v4l2.h>
 
@@ -1041,6 +1042,12 @@ static int v4l_querycap(const struct v4l2_ioctl_ops *ops,
 static int v4l_s_input(const struct v4l2_ioctl_ops *ops,
 				struct file *file, void *fh, void *arg)
 {
+	struct video_device *vfd = video_devdata(file);
+	int ret;
+
+	ret = v4l_enable_media_source(vfd);
+	if (ret)
+		return ret;
 	return ops->vidioc_s_input(file, fh, *(unsigned int *)arg);
 }
 
@@ -1448,6 +1455,9 @@ static int v4l_s_fmt(const struct v4l2_ioctl_ops *ops,
 	bool is_tx = vfd->vfl_dir != VFL_DIR_RX;
 	int ret;
 
+	ret = v4l_enable_media_source(vfd);
+	if (ret)
+		return ret;
 	v4l_sanitize_format(p);
 
 	switch (p->type) {
@@ -1637,7 +1647,11 @@ static int v4l_s_tuner(const struct v4l2_ioctl_ops *ops,
 {
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_tuner *p = arg;
+	int ret;
 
+	ret = v4l_enable_media_source(vfd);
+	if (ret)
+		return ret;
 	p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
 			V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
 	return ops->vidioc_s_tuner(file, fh, p);
@@ -1691,7 +1705,11 @@ static int v4l_s_frequency(const struct v4l2_ioctl_ops *ops,
 	struct video_device *vfd = video_devdata(file);
 	const struct v4l2_frequency *p = arg;
 	enum v4l2_tuner_type type;
+	int ret;
 
+	ret = v4l_enable_media_source(vfd);
+	if (ret)
+		return ret;
 	if (vfd->vfl_type == VFL_TYPE_SDR) {
 		if (p->type != V4L2_TUNER_SDR && p->type != V4L2_TUNER_RF)
 			return -EINVAL;
@@ -1746,7 +1764,11 @@ static int v4l_s_std(const struct v4l2_ioctl_ops *ops,
 {
 	struct video_device *vfd = video_devdata(file);
 	v4l2_std_id id = *(v4l2_std_id *)arg, norm;
+	int ret;
 
+	ret = v4l_enable_media_source(vfd);
+	if (ret)
+		return ret;
 	norm = id & vfd->tvnorms;
 	if (vfd->tvnorms && !norm)	/* Check if std is supported */
 		return -EINVAL;
@@ -1760,7 +1782,11 @@ static int v4l_querystd(const struct v4l2_ioctl_ops *ops,
 {
 	struct video_device *vfd = video_devdata(file);
 	v4l2_std_id *p = arg;
+	int ret;
 
+	ret = v4l_enable_media_source(vfd);
+	if (ret)
+		return ret;
 	/*
 	 * If no signal is detected, then the driver should return
 	 * V4L2_STD_UNKNOWN. Otherwise it should return tvnorms with
@@ -1779,7 +1805,11 @@ static int v4l_s_hw_freq_seek(const struct v4l2_ioctl_ops *ops,
 	struct video_device *vfd = video_devdata(file);
 	struct v4l2_hw_freq_seek *p = arg;
 	enum v4l2_tuner_type type;
+	int ret;
 
+	ret = v4l_enable_media_source(vfd);
+	if (ret)
+		return ret;
 	/* s_hw_freq_seek is not supported for SDR for now */
 	if (vfd->vfl_type == VFL_TYPE_SDR)
 		return -EINVAL;
diff --git a/drivers/media/v4l2-core/videobuf2-core.c b/drivers/media/v4l2-core/videobuf2-core.c
index ec5b78e..d381478 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -25,6 +25,7 @@
 #include <linux/kthread.h>
 
 #include <media/videobuf2-core.h>
+#include <media/v4l2-mc.h>
 
 #include <trace/events/vb2.h>
 
@@ -1873,6 +1874,9 @@ int vb2_core_streamon(struct vb2_queue *q, unsigned int type)
 	 * are available.
 	 */
 	if (q->queued_count >= q->min_buffers_needed) {
+		ret = v4l_vb2q_enable_media_source(q);
+		if (ret)
+			return ret;
 		ret = vb2_start_streaming(q);
 		if (ret) {
 			__vb2_queue_cancel(q);
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH v3 14/22] media: au0828 change to use Managed Media Controller API
  2016-02-11 23:41 [PATCH v3 00/22] Sharing media resources across ALSA and au0828 drivers Shuah Khan
                   ` (12 preceding siblings ...)
  2016-02-11 23:41 ` [PATCH v3 13/22] media: Change v4l-core to check if source is free Shuah Khan
@ 2016-02-11 23:41 ` Shuah Khan
  2016-02-11 23:41 ` [PATCH v3 15/22] media: au0828 handle media_init and media_register window Shuah Khan
                   ` (7 subsequent siblings)
  21 siblings, 0 replies; 49+ messages in thread
From: Shuah Khan @ 2016-02-11 23:41 UTC (permalink / raw)
  To: mchehab, tiwai, clemens, hans.verkuil, laurent.pinchart,
	sakari.ailus, javier
  Cc: Shuah Khan, pawel, m.szyprowski, kyungmin.park, perex, arnd,
	dan.carpenter, tvboxspy, crope, ruchandani.tina, corbet,
	chehabrafael, k.kozlowski, stefanr, inki.dae, jh1009.sung,
	elfring, prabhakar.csengg, sw0312.kim, p.zabel, ricardo.ribalda,
	labbott, pierre-louis.bossart, ricard.wanderlof, julian,
	takamichiho, dominic.sacre, misterpib, daniel, gtmkramer,
	normalperson, joe, linuxbugs, johan, klock.android, nenggun.kim,
	j.anaszewski, geliangtang, albert, linux-kernel, linux-media,
	alsa-devel

Change au0828 to use Managed Media Controller API to
share media device and coordinate creating/deleting
the shared media device with the snd-usb-audio driver.
The shared media device is created as device resource
of the parent usb device of the two drivers.

Populate media device model with USB Device product
name instead of au0828 device board name. This change
is necessary because, if the media device is registered
by the snd-usb-audio driver first, and it doesn't know
the au0828 board name.

Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
---
 drivers/media/usb/au0828/au0828-core.c | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)

diff --git a/drivers/media/usb/au0828/au0828-core.c b/drivers/media/usb/au0828/au0828-core.c
index ce5afea..a740bea 100644
--- a/drivers/media/usb/au0828/au0828-core.c
+++ b/drivers/media/usb/au0828/au0828-core.c
@@ -135,10 +135,10 @@ static void au0828_unregister_media_device(struct au0828_dev *dev)
 {
 
 #ifdef CONFIG_MEDIA_CONTROLLER
-	if (dev->media_dev) {
+	if (dev->media_dev &&
+		media_devnode_is_registered(&dev->media_dev->devnode)) {
 		media_device_unregister(dev->media_dev);
 		media_device_cleanup(dev->media_dev);
-		kfree(dev->media_dev);
 		dev->media_dev = NULL;
 	}
 #endif
@@ -224,23 +224,24 @@ static int au0828_media_device_init(struct au0828_dev *dev,
 #ifdef CONFIG_MEDIA_CONTROLLER
 	struct media_device *mdev;
 
-	mdev = kzalloc(sizeof(*mdev), GFP_KERNEL);
+	mdev = media_device_get_devres(&udev->dev);
 	if (!mdev)
 		return -ENOMEM;
 
-	mdev->dev = &udev->dev;
+	if (!media_devnode_is_registered(&mdev->devnode)) {
+		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;
+		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);
 
-	media_device_init(mdev);
+		media_device_init(mdev);
+	}
 
 	dev->media_dev = mdev;
 #endif
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH v3 15/22] media: au0828 handle media_init and media_register window
  2016-02-11 23:41 [PATCH v3 00/22] Sharing media resources across ALSA and au0828 drivers Shuah Khan
                   ` (13 preceding siblings ...)
  2016-02-11 23:41 ` [PATCH v3 14/22] media: au0828 change to use Managed Media Controller API Shuah Khan
@ 2016-02-11 23:41 ` Shuah Khan
  2016-02-11 23:41 ` [PATCH v3 16/22] media: au0828 create tuner to decoder link in disabled state Shuah Khan
                   ` (6 subsequent siblings)
  21 siblings, 0 replies; 49+ messages in thread
From: Shuah Khan @ 2016-02-11 23:41 UTC (permalink / raw)
  To: mchehab, tiwai, clemens, hans.verkuil, laurent.pinchart,
	sakari.ailus, javier
  Cc: Shuah Khan, pawel, m.szyprowski, kyungmin.park, perex, arnd,
	dan.carpenter, tvboxspy, crope, ruchandani.tina, corbet,
	chehabrafael, k.kozlowski, stefanr, inki.dae, jh1009.sung,
	elfring, prabhakar.csengg, sw0312.kim, p.zabel, ricardo.ribalda,
	labbott, pierre-louis.bossart, ricard.wanderlof, julian,
	takamichiho, dominic.sacre, misterpib, daniel, gtmkramer,
	normalperson, joe, linuxbugs, johan, klock.android, nenggun.kim,
	j.anaszewski, geliangtang, albert, linux-kernel, linux-media,
	alsa-devel

Media device initialization and registration
steps are split. There is a window between
media device init and media device register
during usb probe.

au0828 bridge driver and snd-usb-audio could
try to initialize the media device, if they
simply checked, whether the device has been
registered. They also need to check whether
the device has been initialized.

Change the au0828-core to check if media device
is already initialized during initialization step
and check if media device is already registered
during the registration step.

Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
---
 drivers/media/usb/au0828/au0828-core.c | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)

diff --git a/drivers/media/usb/au0828/au0828-core.c b/drivers/media/usb/au0828/au0828-core.c
index a740bea..99f8022 100644
--- a/drivers/media/usb/au0828/au0828-core.c
+++ b/drivers/media/usb/au0828/au0828-core.c
@@ -228,7 +228,8 @@ static int au0828_media_device_init(struct au0828_dev *dev,
 	if (!mdev)
 		return -ENOMEM;
 
-	if (!media_devnode_is_registered(&mdev->devnode)) {
+	/* check if media device is already initialized */
+	if (!mdev->dev) {
 		mdev->dev = &udev->dev;
 
 		if (udev->product)
@@ -328,6 +329,27 @@ static int au0828_create_media_graph(struct au0828_dev *dev)
 	return 0;
 }
 
+static int au0828_media_device_register(struct au0828_dev *dev,
+					struct usb_device *udev)
+{
+#ifdef CONFIG_MEDIA_CONTROLLER
+	int ret;
+
+	if (dev->media_dev &&
+		!media_devnode_is_registered(&dev->media_dev->devnode)) {
+
+		/* register media device */
+		ret = media_device_register(dev->media_dev);
+		if (ret) {
+			dev_err(&udev->dev,
+				"Media Device Register Error: %d\n", ret);
+			return ret;
+		}
+	}
+#endif
+	return 0;
+}
+
 static int au0828_usb_probe(struct usb_interface *interface,
 	const struct usb_device_id *id)
 {
@@ -455,7 +477,7 @@ static int au0828_usb_probe(struct usb_interface *interface,
 	}
 
 #ifdef CONFIG_MEDIA_CONTROLLER
-	retval = media_device_register(dev->media_dev);
+	retval = au0828_media_device_register(dev, usbdev);
 #endif
 
 done:
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH v3 16/22] media: au0828 create tuner to decoder link in disabled state
  2016-02-11 23:41 [PATCH v3 00/22] Sharing media resources across ALSA and au0828 drivers Shuah Khan
                   ` (14 preceding siblings ...)
  2016-02-11 23:41 ` [PATCH v3 15/22] media: au0828 handle media_init and media_register window Shuah Khan
@ 2016-02-11 23:41 ` Shuah Khan
  2016-02-11 23:41 ` [PATCH v3 17/22] media: au0828 disable tuner to demod link Shuah Khan
                   ` (5 subsequent siblings)
  21 siblings, 0 replies; 49+ messages in thread
From: Shuah Khan @ 2016-02-11 23:41 UTC (permalink / raw)
  To: mchehab, tiwai, clemens, hans.verkuil, laurent.pinchart,
	sakari.ailus, javier
  Cc: Shuah Khan, pawel, m.szyprowski, kyungmin.park, perex, arnd,
	dan.carpenter, tvboxspy, crope, ruchandani.tina, corbet,
	chehabrafael, k.kozlowski, stefanr, inki.dae, jh1009.sung,
	elfring, prabhakar.csengg, sw0312.kim, p.zabel, ricardo.ribalda,
	labbott, pierre-louis.bossart, ricard.wanderlof, julian,
	takamichiho, dominic.sacre, misterpib, daniel, gtmkramer,
	normalperson, joe, linuxbugs, johan, klock.android, nenggun.kim,
	j.anaszewski, geliangtang, albert, linux-kernel, linux-media,
	alsa-devel

Create tuner to demod pad link in disabled state to
avoid disable step when tuner resource is requested
by dvb.

Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
---
 drivers/media/usb/au0828/au0828-core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/usb/au0828/au0828-core.c b/drivers/media/usb/au0828/au0828-core.c
index 99f8022..66b44c9 100644
--- a/drivers/media/usb/au0828/au0828-core.c
+++ b/drivers/media/usb/au0828/au0828-core.c
@@ -279,9 +279,9 @@ static int au0828_create_media_graph(struct au0828_dev *dev)
 		return -EINVAL;
 
 	if (tuner) {
+		/* create tuner to decoder link in deactivated state */
 		ret = media_create_pad_link(tuner, TUNER_PAD_OUTPUT,
-					    decoder, 0,
-					    MEDIA_LNK_FL_ENABLED);
+					    decoder, 0, 0);
 		if (ret)
 			return ret;
 	}
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH v3 17/22] media: au0828 disable tuner to demod link
  2016-02-11 23:41 [PATCH v3 00/22] Sharing media resources across ALSA and au0828 drivers Shuah Khan
                   ` (15 preceding siblings ...)
  2016-02-11 23:41 ` [PATCH v3 16/22] media: au0828 create tuner to decoder link in disabled state Shuah Khan
@ 2016-02-11 23:41 ` Shuah Khan
  2016-02-11 23:41 ` [PATCH v3 18/22] media: au0828-core register entity_notify hook Shuah Khan
                   ` (4 subsequent siblings)
  21 siblings, 0 replies; 49+ messages in thread
From: Shuah Khan @ 2016-02-11 23:41 UTC (permalink / raw)
  To: mchehab, tiwai, clemens, hans.verkuil, laurent.pinchart,
	sakari.ailus, javier
  Cc: Shuah Khan, pawel, m.szyprowski, kyungmin.park, perex, arnd,
	dan.carpenter, tvboxspy, crope, ruchandani.tina, corbet,
	chehabrafael, k.kozlowski, stefanr, inki.dae, jh1009.sung,
	elfring, prabhakar.csengg, sw0312.kim, p.zabel, ricardo.ribalda,
	labbott, pierre-louis.bossart, ricard.wanderlof, julian,
	takamichiho, dominic.sacre, misterpib, daniel, gtmkramer,
	normalperson, joe, linuxbugs, johan, klock.android, nenggun.kim,
	j.anaszewski, geliangtang, albert, linux-kernel, linux-media,
	alsa-devel

Change au0828_create_media_graph() to find and disable
tuner and demod link. This helps avoid an additional
disable step when tuner is requested by video or audio.

Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
---
 drivers/media/usb/au0828/au0828-core.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/drivers/media/usb/au0828/au0828-core.c b/drivers/media/usb/au0828/au0828-core.c
index 66b44c9..92d22ed 100644
--- a/drivers/media/usb/au0828/au0828-core.c
+++ b/drivers/media/usb/au0828/au0828-core.c
@@ -255,7 +255,7 @@ static int au0828_create_media_graph(struct au0828_dev *dev)
 #ifdef CONFIG_MEDIA_CONTROLLER
 	struct media_device *mdev = dev->media_dev;
 	struct media_entity *entity;
-	struct media_entity *tuner = NULL, *decoder = NULL;
+	struct media_entity *tuner = NULL, *decoder = NULL, *demod = NULL;
 	int i, ret;
 
 	if (!mdev)
@@ -269,6 +269,9 @@ static int au0828_create_media_graph(struct au0828_dev *dev)
 		case MEDIA_ENT_F_ATV_DECODER:
 			decoder = entity;
 			break;
+		case MEDIA_ENT_F_DTV_DEMOD:
+			demod = entity;
+			break;
 		}
 	}
 
@@ -325,6 +328,21 @@ static int au0828_create_media_graph(struct au0828_dev *dev)
 			break;
 		}
 	}
+
+	/*
+	 * Disable tuner to demod link to avoid disable step
+	 * when tuner is requested by video or audio
+	*/
+	if (tuner && demod) {
+		struct media_link *link;
+
+		list_for_each_entry(link, &demod->links, list) {
+			if (link->sink->entity == demod &&
+			    link->source->entity == tuner) {
+				media_entity_setup_link(link, 0);
+			}
+		}
+	}
 #endif
 	return 0;
 }
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH v3 18/22] media: au0828-core register entity_notify hook
  2016-02-11 23:41 [PATCH v3 00/22] Sharing media resources across ALSA and au0828 drivers Shuah Khan
                   ` (16 preceding siblings ...)
  2016-02-11 23:41 ` [PATCH v3 17/22] media: au0828 disable tuner to demod link Shuah Khan
@ 2016-02-11 23:41 ` Shuah Khan
  2016-02-11 23:41 ` [PATCH v3 19/22] media: au0828 add enable, disable source handlers Shuah Khan
                   ` (3 subsequent siblings)
  21 siblings, 0 replies; 49+ messages in thread
From: Shuah Khan @ 2016-02-11 23:41 UTC (permalink / raw)
  To: mchehab, tiwai, clemens, hans.verkuil, laurent.pinchart,
	sakari.ailus, javier
  Cc: Shuah Khan, pawel, m.szyprowski, kyungmin.park, perex, arnd,
	dan.carpenter, tvboxspy, crope, ruchandani.tina, corbet,
	chehabrafael, k.kozlowski, stefanr, inki.dae, jh1009.sung,
	elfring, prabhakar.csengg, sw0312.kim, p.zabel, ricardo.ribalda,
	labbott, pierre-louis.bossart, ricard.wanderlof, julian,
	takamichiho, dominic.sacre, misterpib, daniel, gtmkramer,
	normalperson, joe, linuxbugs, johan, klock.android, nenggun.kim,
	j.anaszewski, geliangtang, albert, linux-kernel, linux-media,
	alsa-devel

Register entity_notify async hook to create links
between existing bridge driver entities and a newly
added non-bridge driver entities. For example, this
handler creates link between V4L decoder entity and
ALSA mixer entity.

Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
---
 drivers/media/usb/au0828/au0828-core.c | 43 ++++++++++++++++++++++++++++++++--
 drivers/media/usb/au0828/au0828.h      |  1 +
 2 files changed, 42 insertions(+), 2 deletions(-)

diff --git a/drivers/media/usb/au0828/au0828-core.c b/drivers/media/usb/au0828/au0828-core.c
index 92d22ed..4c90f28 100644
--- a/drivers/media/usb/au0828/au0828-core.c
+++ b/drivers/media/usb/au0828/au0828-core.c
@@ -347,14 +347,42 @@ static int au0828_create_media_graph(struct au0828_dev *dev)
 	return 0;
 }
 
+void au0828_media_graph_notify(struct media_entity *new, void *notify_data)
+{
+#ifdef CONFIG_MEDIA_CONTROLLER
+	struct au0828_dev *dev = (struct au0828_dev *) notify_data;
+	int ret;
+
+	if (!dev->decoder)
+		return;
+
+	switch (new->function) {
+	case MEDIA_ENT_F_AUDIO_MIXER:
+		ret = media_create_pad_link(dev->decoder,
+					    AU8522_PAD_AUDIO_OUT,
+					    new, 0,
+					    MEDIA_LNK_FL_ENABLED);
+		if (ret)
+			dev_err(&dev->usbdev->dev,
+				"Mixer Pad Link Create Error: %d\n",
+				ret);
+		break;
+	default:
+		break;
+	}
+#endif
+}
+
 static int au0828_media_device_register(struct au0828_dev *dev,
 					struct usb_device *udev)
 {
 #ifdef CONFIG_MEDIA_CONTROLLER
 	int ret;
 
-	if (dev->media_dev &&
-		!media_devnode_is_registered(&dev->media_dev->devnode)) {
+	if (!dev->media_dev)
+		return 0;
+
+	if (!media_devnode_is_registered(&dev->media_dev->devnode)) {
 
 		/* register media device */
 		ret = media_device_register(dev->media_dev);
@@ -364,6 +392,17 @@ static int au0828_media_device_register(struct au0828_dev *dev,
 			return ret;
 		}
 	}
+	/* register entity_notify callback */
+	dev->entity_notify.notify_data = (void *) dev;
+	dev->entity_notify.notify = (void *) au0828_media_graph_notify;
+	ret = media_device_register_entity_notify(dev->media_dev,
+						  &dev->entity_notify);
+	if (ret) {
+		dev_err(&udev->dev,
+			"Media Device register entity_notify Error: %d\n",
+			ret);
+		return ret;
+	}
 #endif
 	return 0;
 }
diff --git a/drivers/media/usb/au0828/au0828.h b/drivers/media/usb/au0828/au0828.h
index 8276072..54379ec 100644
--- a/drivers/media/usb/au0828/au0828.h
+++ b/drivers/media/usb/au0828/au0828.h
@@ -283,6 +283,7 @@ struct au0828_dev {
 	struct media_entity *decoder;
 	struct media_entity input_ent[AU0828_MAX_INPUT];
 	struct media_pad input_pad[AU0828_MAX_INPUT];
+	struct media_entity_notify entity_notify;
 #endif
 };
 
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH v3 19/22] media: au0828 add enable, disable source handlers
  2016-02-11 23:41 [PATCH v3 00/22] Sharing media resources across ALSA and au0828 drivers Shuah Khan
                   ` (17 preceding siblings ...)
  2016-02-11 23:41 ` [PATCH v3 18/22] media: au0828-core register entity_notify hook Shuah Khan
@ 2016-02-11 23:41 ` Shuah Khan
  2016-02-11 23:41 ` [PATCH v3 20/22] media: dvb-frontend invoke enable/disable_source handlers Shuah Khan
                   ` (2 subsequent siblings)
  21 siblings, 0 replies; 49+ messages in thread
From: Shuah Khan @ 2016-02-11 23:41 UTC (permalink / raw)
  To: mchehab, tiwai, clemens, hans.verkuil, laurent.pinchart,
	sakari.ailus, javier
  Cc: Shuah Khan, pawel, m.szyprowski, kyungmin.park, perex, arnd,
	dan.carpenter, tvboxspy, crope, ruchandani.tina, corbet,
	chehabrafael, k.kozlowski, stefanr, inki.dae, jh1009.sung,
	elfring, prabhakar.csengg, sw0312.kim, p.zabel, ricardo.ribalda,
	labbott, pierre-louis.bossart, ricard.wanderlof, julian,
	takamichiho, dominic.sacre, misterpib, daniel, gtmkramer,
	normalperson, joe, linuxbugs, johan, klock.android, nenggun.kim,
	j.anaszewski, geliangtang, albert, linux-kernel, linux-media,
	alsa-devel

Add enable_source and disable_source handlers.
The enable source handler is called from
v4l2-core, dvb-core, and ALSA drivers to check
if the shared media source is free. The disable
source handler is called to release the shared
media source.

Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
---
 drivers/media/usb/au0828/au0828-core.c | 202 +++++++++++++++++++++++++++++++++
 drivers/media/usb/au0828/au0828.h      |   5 +
 2 files changed, 207 insertions(+)

diff --git a/drivers/media/usb/au0828/au0828-core.c b/drivers/media/usb/au0828/au0828-core.c
index 4c90f28..bcae077 100644
--- a/drivers/media/usb/au0828/au0828-core.c
+++ b/drivers/media/usb/au0828/au0828-core.c
@@ -282,6 +282,7 @@ static int au0828_create_media_graph(struct au0828_dev *dev)
 		return -EINVAL;
 
 	if (tuner) {
+		dev->tuner = tuner;
 		/* create tuner to decoder link in deactivated state */
 		ret = media_create_pad_link(tuner, TUNER_PAD_OUTPUT,
 					    decoder, 0, 0);
@@ -373,6 +374,203 @@ void au0828_media_graph_notify(struct media_entity *new, void *notify_data)
 #endif
 }
 
+static int au0828_enable_source(struct media_entity *entity,
+				struct media_pipeline *pipe)
+{
+#ifdef CONFIG_MEDIA_CONTROLLER
+	struct media_entity  *source, *find_source;
+	struct media_entity *sink;
+	struct media_link *link, *found_link = NULL;
+	int ret = 0;
+	struct media_device *mdev = entity->graph_obj.mdev;
+	struct au0828_dev *dev;
+
+	if (!mdev)
+		return -ENODEV;
+
+	mutex_lock(&mdev->graph_mutex);
+
+	dev = mdev->source_priv;
+
+	/*
+	 * For Audio and V4L2 entity, find the link to which decoder
+	 * is the sink. Look for an active link between decoder and
+	 * source (tuner/s-video/Composite), if one exists, nothing
+	 * to do. If not, look for any  active links between source
+	 * and any other entity. If one exists, source is busy. If
+	 * source is free, setup link and start pipeline from source.
+	 * For DVB FE entity, the source for the link is the tuner.
+	 * Check if tuner is available and setup link and start
+	 * pipeline.
+	*/
+	if (entity->function == MEDIA_ENT_F_DTV_DEMOD) {
+		sink = entity;
+		find_source = dev->tuner;
+	} else {
+		/* Analog isn't configured or register failed */
+		if (!dev->decoder) {
+			ret = -ENODEV;
+			goto end;
+		}
+
+		sink = dev->decoder;
+
+		/*
+		 * Default input is tuner and default input_type
+		 * is AU0828_VMUX_TELEVISION.
+		 * FIXME:
+		 * There is a problem when s_input is called to
+		 * change the default input. s_input will try to
+		 * enable_source before attempting to change the
+		 * input on the device, and will end up enabling
+		 * default source which is tuner.
+		 *
+		 * Additional logic is necessary in au0828
+		 * to detect that the input has changed and
+		 * enable the right source.
+		*/
+
+		if (dev->input_type == AU0828_VMUX_TELEVISION)
+			find_source = dev->tuner;
+		else if (dev->input_type == AU0828_VMUX_SVIDEO ||
+			 dev->input_type == AU0828_VMUX_COMPOSITE)
+			find_source = &dev->input_ent[dev->input_type];
+		else {
+			/* unknown input - let user select input */
+			ret = 0;
+			goto end;
+		}
+	}
+
+	/* Is an active link between sink and source */
+	if (dev->active_link) {
+		/*
+		 * If DVB is using the tuner and calling entity is
+		 * audio/video, the following check will be false,
+		 * since sink is different. Result is Busy.
+		 */
+		if (dev->active_link->sink->entity == sink &&
+		    dev->active_link->source->entity == find_source) {
+			/*
+			 * Either ALSA or Video own tuner. sink is
+			 * the same for both. Prevent Video stepping
+			 * on ALSA when ALSA owns the source.
+			*/
+			if (dev->active_link_owner != entity &&
+			    dev->active_link_owner->function ==
+						MEDIA_ENT_F_AUDIO_CAPTURE) {
+				pr_debug("ALSA has the tuner\n");
+				ret = -EBUSY;
+				goto end;
+			}
+			ret = 0;
+			goto end;
+		} else {
+			ret = -EBUSY;
+			goto end;
+		}
+	}
+
+	list_for_each_entry(link, &sink->links, list) {
+		/* Check sink, and source */
+		if (link->sink->entity == sink &&
+		    link->source->entity == find_source) {
+			found_link = link;
+			break;
+		}
+	}
+
+	if (!found_link) {
+		ret = -ENODEV;
+		goto end;
+	}
+
+	/* activate link between source and sink and start pipeline */
+	source = found_link->source->entity;
+	ret = __media_entity_setup_link(found_link, MEDIA_LNK_FL_ENABLED);
+	if (ret) {
+		pr_err("Activate tuner link %s->%s. Error %d\n",
+			source->name, sink->name, ret);
+		goto end;
+	}
+
+	ret = __media_entity_pipeline_start(entity, pipe);
+	if (ret) {
+		pr_err("Start Pipeline: %s->%s Error %d\n",
+			source->name, entity->name, ret);
+		ret = __media_entity_setup_link(found_link, 0);
+		pr_err("Deactivate link Error %d\n", ret);
+		goto end;
+	}
+	/*
+	 * save active link and active link owner to avoid audio
+	 * deactivating video owned link from disable_source and
+	 * vice versa
+	*/
+	dev->active_link = found_link;
+	dev->active_link_owner = entity;
+	dev->active_source = source;
+	dev->active_sink = sink;
+
+	pr_debug("Enabled Source: %s->%s->%s Ret %d\n",
+		 dev->active_source->name, dev->active_sink->name,
+		 dev->active_link_owner->name, ret);
+end:
+	mutex_unlock(&mdev->graph_mutex);
+	pr_debug("au0828_enable_source() end %s %d %d\n",
+		 entity->name, entity->function, ret);
+	return ret;
+#endif
+	return 0;
+}
+
+static void au0828_disable_source(struct media_entity *entity)
+{
+#ifdef CONFIG_MEDIA_CONTROLLER
+	int ret = 0;
+	struct media_device *mdev = entity->graph_obj.mdev;
+	struct au0828_dev *dev;
+
+	if (!mdev)
+		return;
+
+	mutex_lock(&mdev->graph_mutex);
+	dev = mdev->source_priv;
+
+	if (!dev->active_link) {
+		ret = -ENODEV;
+		goto end;
+	}
+
+	/* link is active - stop pipeline from source (tuner) */
+	if (dev->active_link->sink->entity == dev->active_sink &&
+	    dev->active_link->source->entity == dev->active_source) {
+		/*
+		 * prevent video from deactivating link when audio
+		 * has active pipeline
+		*/
+		if (dev->active_link_owner != entity)
+			goto end;
+		__media_entity_pipeline_stop(entity);
+		ret = __media_entity_setup_link(dev->active_link, 0);
+		if (ret)
+			pr_err("Deactivate link Error %d\n", ret);
+
+		pr_debug("Disabled Source: %s->%s->%s Ret %d\n",
+			 dev->active_source->name, dev->active_sink->name,
+			 dev->active_link_owner->name, ret);
+
+		dev->active_link = NULL;
+		dev->active_link_owner = NULL;
+		dev->active_source = NULL;
+		dev->active_sink = NULL;
+	}
+
+end:
+	mutex_unlock(&mdev->graph_mutex);
+#endif
+}
+
 static int au0828_media_device_register(struct au0828_dev *dev,
 					struct usb_device *udev)
 {
@@ -403,6 +601,10 @@ static int au0828_media_device_register(struct au0828_dev *dev,
 			ret);
 		return ret;
 	}
+	/* set enable_source */
+	dev->media_dev->source_priv = (void *) dev;
+	dev->media_dev->enable_source = au0828_enable_source;
+	dev->media_dev->disable_source = au0828_disable_source;
 #endif
 	return 0;
 }
diff --git a/drivers/media/usb/au0828/au0828.h b/drivers/media/usb/au0828/au0828.h
index 54379ec..66f2ec3 100644
--- a/drivers/media/usb/au0828/au0828.h
+++ b/drivers/media/usb/au0828/au0828.h
@@ -284,6 +284,11 @@ struct au0828_dev {
 	struct media_entity input_ent[AU0828_MAX_INPUT];
 	struct media_pad input_pad[AU0828_MAX_INPUT];
 	struct media_entity_notify entity_notify;
+	struct media_entity *tuner;
+	struct media_link *active_link;
+	struct media_entity *active_link_owner;
+	struct media_entity *active_source;
+	struct media_entity *active_sink;
 #endif
 };
 
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH v3 20/22] media: dvb-frontend invoke enable/disable_source handlers
  2016-02-11 23:41 [PATCH v3 00/22] Sharing media resources across ALSA and au0828 drivers Shuah Khan
                   ` (18 preceding siblings ...)
  2016-02-11 23:41 ` [PATCH v3 19/22] media: au0828 add enable, disable source handlers Shuah Khan
@ 2016-02-11 23:41 ` Shuah Khan
  2016-02-11 23:41 ` [PATCH v3 21/22] media: au0828 video change to use v4l_enable_media_source() Shuah Khan
  2016-02-11 23:41 ` [PATCH v3 22/22] sound/usb: Use Media Controller API to share media resources Shuah Khan
  21 siblings, 0 replies; 49+ messages in thread
From: Shuah Khan @ 2016-02-11 23:41 UTC (permalink / raw)
  To: mchehab, tiwai, clemens, hans.verkuil, laurent.pinchart,
	sakari.ailus, javier
  Cc: Shuah Khan, pawel, m.szyprowski, kyungmin.park, perex, arnd,
	dan.carpenter, tvboxspy, crope, ruchandani.tina, corbet,
	chehabrafael, k.kozlowski, stefanr, inki.dae, jh1009.sung,
	elfring, prabhakar.csengg, sw0312.kim, p.zabel, ricardo.ribalda,
	labbott, pierre-louis.bossart, ricard.wanderlof, julian,
	takamichiho, dominic.sacre, misterpib, daniel, gtmkramer,
	normalperson, joe, linuxbugs, johan, klock.android, nenggun.kim,
	j.anaszewski, geliangtang, albert, linux-kernel, linux-media,
	alsa-devel

Change dvb frontend to check if tuner is free when
device opened in RW mode. Call to enable_source
handler either returns with an active pipeline to
tuner or error if tuner is busy. Tuner is released
when frontend is released calling the disable_source
handler.

Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
---
 drivers/media/dvb-core/dvb_frontend.c | 135 ++++++----------------------------
 1 file changed, 21 insertions(+), 114 deletions(-)

diff --git a/drivers/media/dvb-core/dvb_frontend.c b/drivers/media/dvb-core/dvb_frontend.c
index 03cc508..8221fa6 100644
--- a/drivers/media/dvb-core/dvb_frontend.c
+++ b/drivers/media/dvb-core/dvb_frontend.c
@@ -134,7 +134,6 @@ struct dvb_frontend_private {
 
 #if defined(CONFIG_MEDIA_CONTROLLER_DVB)
 	struct media_pipeline pipe;
-	struct media_entity *pipe_start_entity;
 #endif
 };
 
@@ -596,104 +595,12 @@ static void dvb_frontend_wakeup(struct dvb_frontend *fe)
 	wake_up_interruptible(&fepriv->wait_queue);
 }
 
-/**
- * dvb_enable_media_tuner() - tries to enable the DVB tuner
- *
- * @fe:		struct dvb_frontend pointer
- *
- * This function ensures that just one media tuner is enabled for a given
- * frontend. It has two different behaviors:
- * - For trivial devices with just one tuner:
- *   it just enables the existing tuner->fe link
- * - For devices with more than one tuner:
- *   It is up to the driver to implement the logic that will enable one tuner
- *   and disable the other ones. However, if more than one tuner is enabled for
- *   the same frontend, it will print an error message and return -EINVAL.
- *
- * At return, it will return the error code returned by media_entity_setup_link,
- * or 0 if everything is OK, if no tuner is linked to the frontend or if the
- * mdev is NULL.
- */
-#ifdef CONFIG_MEDIA_CONTROLLER_DVB
-static int dvb_enable_media_tuner(struct dvb_frontend *fe)
-{
-	struct dvb_frontend_private *fepriv = fe->frontend_priv;
-	struct dvb_adapter *adapter = fe->dvb;
-	struct media_device *mdev = adapter->mdev;
-	struct media_entity  *entity, *source;
-	struct media_link *link, *found_link = NULL;
-	int ret, n_links = 0, active_links = 0;
-
-	fepriv->pipe_start_entity = NULL;
-
-	if (!mdev)
-		return 0;
-
-	entity = fepriv->dvbdev->entity;
-	fepriv->pipe_start_entity = entity;
-
-	list_for_each_entry(link, &entity->links, list) {
-		if (link->sink->entity == entity) {
-			found_link = link;
-			n_links++;
-			if (link->flags & MEDIA_LNK_FL_ENABLED)
-				active_links++;
-		}
-	}
-
-	if (!n_links || active_links == 1 || !found_link)
-		return 0;
-
-	/*
-	 * If a frontend has more than one tuner linked, it is up to the driver
-	 * to select with one will be the active one, as the frontend core can't
-	 * guess. If the driver doesn't do that, it is a bug.
-	 */
-	if (n_links > 1 && active_links != 1) {
-		dev_err(fe->dvb->device,
-			"WARNING: there are %d active links among %d tuners. This is a driver's bug!\n",
-			active_links, n_links);
-		return -EINVAL;
-	}
-
-	source = found_link->source->entity;
-	fepriv->pipe_start_entity = source;
-	list_for_each_entry(link, &source->links, list) {
-		struct media_entity *sink;
-		int flags = 0;
-
-		sink = link->sink->entity;
-		if (sink == entity)
-			flags = MEDIA_LNK_FL_ENABLED;
-
-		ret = media_entity_setup_link(link, flags);
-		if (ret) {
-			dev_err(fe->dvb->device,
-				"Couldn't change link %s->%s to %s. Error %d\n",
-				source->name, sink->name,
-				flags ? "enabled" : "disabled",
-				ret);
-			return ret;
-		} else
-			dev_dbg(fe->dvb->device,
-				"link %s->%s was %s\n",
-				source->name, sink->name,
-				flags ? "ENABLED" : "disabled");
-	}
-	return 0;
-}
-#endif
-
 static int dvb_frontend_thread(void *data)
 {
 	struct dvb_frontend *fe = data;
 	struct dvb_frontend_private *fepriv = fe->frontend_priv;
 	enum fe_status s;
 	enum dvbfe_algo algo;
-#ifdef CONFIG_MEDIA_CONTROLLER_DVB
-	int ret;
-#endif
-
 	bool re_tune = false;
 	bool semheld = false;
 
@@ -706,20 +613,6 @@ static int dvb_frontend_thread(void *data)
 	fepriv->wakeup = 0;
 	fepriv->reinitialise = 0;
 
-#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");
-	} else if (fepriv->pipe_start_entity) {
-		ret = media_entity_pipeline_start(fepriv->pipe_start_entity,
-						  &fepriv->pipe);
-		if (ret)
-			return ret;
-	}
-#endif
-
 	dvb_frontend_init(fe);
 
 	set_freezable();
@@ -829,12 +722,6 @@ restart:
 		}
 	}
 
-#ifdef CONFIG_MEDIA_CONTROLLER_DVB
-	if (fepriv->pipe_start_entity)
-		media_entity_pipeline_stop(fepriv->pipe_start_entity);
-	fepriv->pipe_start_entity = NULL;
-#endif
-
 	if (dvb_powerdown_on_sleep) {
 		if (fe->ops.set_voltage)
 			fe->ops.set_voltage(fe, SEC_VOLTAGE_OFF);
@@ -2612,9 +2499,20 @@ static int dvb_frontend_open(struct inode *inode, struct file *file)
 		fepriv->tone = -1;
 		fepriv->voltage = -1;
 
+#ifdef CONFIG_MEDIA_CONTROLLER_DVB
+		if (fe->dvb->mdev && fe->dvb->mdev->enable_source) {
+			ret = fe->dvb->mdev->enable_source(dvbdev->entity,
+							   &fepriv->pipe);
+			if (ret) {
+				dev_err(fe->dvb->device,
+					"Tuner is busy. Error %d\n", ret);
+				goto err2;
+			}
+		}
+#endif
 		ret = dvb_frontend_start (fe);
 		if (ret)
-			goto err2;
+			goto err3;
 
 		/*  empty event queue */
 		fepriv->events.eventr = fepriv->events.eventw = 0;
@@ -2624,7 +2522,12 @@ static int dvb_frontend_open(struct inode *inode, struct file *file)
 		mutex_unlock (&adapter->mfe_lock);
 	return ret;
 
+err3:
+#ifdef CONFIG_MEDIA_CONTROLLER_DVB
+	if (fe->dvb->mdev && fe->dvb->mdev->disable_source)
+		fe->dvb->mdev->disable_source(dvbdev->entity);
 err2:
+#endif
 	dvb_generic_release(inode, file);
 err1:
 	if (dvbdev->users == -1 && fe->ops.ts_bus_ctrl)
@@ -2653,6 +2556,10 @@ static int dvb_frontend_release(struct inode *inode, struct file *file)
 
 	if (dvbdev->users == -1) {
 		wake_up(&fepriv->wait_queue);
+#ifdef CONFIG_MEDIA_CONTROLLER_DVB
+		if (fe->dvb->mdev && fe->dvb->mdev->disable_source)
+			fe->dvb->mdev->disable_source(dvbdev->entity);
+#endif
 		if (fe->exit != DVB_FE_NO_EXIT)
 			wake_up(&dvbdev->wait_queue);
 		if (fe->ops.ts_bus_ctrl)
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH v3 21/22] media: au0828 video change to use v4l_enable_media_source()
  2016-02-11 23:41 [PATCH v3 00/22] Sharing media resources across ALSA and au0828 drivers Shuah Khan
                   ` (19 preceding siblings ...)
  2016-02-11 23:41 ` [PATCH v3 20/22] media: dvb-frontend invoke enable/disable_source handlers Shuah Khan
@ 2016-02-11 23:41 ` Shuah Khan
  2016-02-11 23:41 ` [PATCH v3 22/22] sound/usb: Use Media Controller API to share media resources Shuah Khan
  21 siblings, 0 replies; 49+ messages in thread
From: Shuah Khan @ 2016-02-11 23:41 UTC (permalink / raw)
  To: mchehab, tiwai, clemens, hans.verkuil, laurent.pinchart,
	sakari.ailus, javier
  Cc: Shuah Khan, pawel, m.szyprowski, kyungmin.park, perex, arnd,
	dan.carpenter, tvboxspy, crope, ruchandani.tina, corbet,
	chehabrafael, k.kozlowski, stefanr, inki.dae, jh1009.sung,
	elfring, prabhakar.csengg, sw0312.kim, p.zabel, ricardo.ribalda,
	labbott, pierre-louis.bossart, ricard.wanderlof, julian,
	takamichiho, dominic.sacre, misterpib, daniel, gtmkramer,
	normalperson, joe, linuxbugs, johan, klock.android, nenggun.kim,
	j.anaszewski, geliangtang, albert, linux-kernel, linux-media,
	alsa-devel

Change au0828 to check if tuner is free or not
before changing tuner configuration.

vidioc_g_tuner(), and au0828_v4l2_close() now call
v4l-core interface v4l_enable_media_source() before
changing tuner configuration.

Remove au0828_enable_analog_tuner() as it is
no longer needed because v4l2-core implements
common interfaces to check for media source
availability.

In addition, queue_setup() no longer needs the
tuner availability check since v4l2-core does it.

Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
---
 drivers/media/usb/au0828/au0828-video.c | 102 ++++++++++++--------------------
 1 file changed, 39 insertions(+), 63 deletions(-)

diff --git a/drivers/media/usb/au0828/au0828-video.c b/drivers/media/usb/au0828/au0828-video.c
index 8c54fd2..9304f96 100644
--- a/drivers/media/usb/au0828/au0828-video.c
+++ b/drivers/media/usb/au0828/au0828-video.c
@@ -638,64 +638,6 @@ static inline int au0828_isoc_copy(struct au0828_dev *dev, struct urb *urb)
 	return rc;
 }
 
-static int au0828_enable_analog_tuner(struct au0828_dev *dev)
-{
-#ifdef CONFIG_MEDIA_CONTROLLER
-	struct media_device *mdev = dev->media_dev;
-	struct media_entity *source;
-	struct media_link *link, *found_link = NULL;
-	int ret, active_links = 0;
-
-	if (!mdev || !dev->decoder)
-		return 0;
-
-	/*
-	 * This will find the tuner that is connected into the decoder.
-	 * Technically, this is not 100% correct, as the device may be
-	 * using an analog input instead of the tuner. However, as we can't
-	 * do DVB streaming while the DMA engine is being used for V4L2,
-	 * this should be enough for the actual needs.
-	 */
-	list_for_each_entry(link, &dev->decoder->links, list) {
-		if (link->sink->entity == dev->decoder) {
-			found_link = link;
-			if (link->flags & MEDIA_LNK_FL_ENABLED)
-				active_links++;
-			break;
-		}
-	}
-
-	if (active_links == 1 || !found_link)
-		return 0;
-
-	source = found_link->source->entity;
-	list_for_each_entry(link, &source->links, list) {
-		struct media_entity *sink;
-		int flags = 0;
-
-		sink = link->sink->entity;
-
-		if (sink == dev->decoder)
-			flags = MEDIA_LNK_FL_ENABLED;
-
-		ret = media_entity_setup_link(link, flags);
-		if (ret) {
-			pr_err(
-				"Couldn't change link %s->%s to %s. Error %d\n",
-				source->name, sink->name,
-				flags ? "enabled" : "disabled",
-				ret);
-			return ret;
-		} else
-			au0828_isocdbg(
-				"link %s->%s was %s\n",
-				source->name, sink->name,
-				flags ? "ENABLED" : "disabled");
-	}
-#endif
-	return 0;
-}
-
 static int queue_setup(struct vb2_queue *vq,
 		       unsigned int *nbuffers, unsigned int *nplanes,
 		       unsigned int sizes[], void *alloc_ctxs[])
@@ -707,9 +649,6 @@ static int queue_setup(struct vb2_queue *vq,
 		return sizes[0] < size ? -EINVAL : 0;
 	*nplanes = 1;
 	sizes[0] = size;
-
-	au0828_enable_analog_tuner(dev);
-
 	return 0;
 }
 
@@ -1067,8 +1006,39 @@ static int au0828_v4l2_close(struct file *filp)
 		goto end;
 
 	if (dev->users == 1) {
-		/* Save some power by putting tuner to sleep */
-		v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_power, 0);
+		/*
+		 * Avoid putting tuner in sleep if DVB or ALSA are
+		 * streaming.
+		 *
+		 * On most USB devices  like au0828 the tuner can
+		 * be safely put in sleep stare here if ALSA isn't
+		 * streaming. Exceptions are some very old USB tuner
+		 * models such as em28xx-based WinTV USB2 which have
+		 * a separate audio output jack. The devices that have
+		 * a separate audio output jack have analog tuners,
+		 * like Philips FM1236. Those devices are always on,
+		 * so the s_power callback are silently ignored.
+		 * So, the current logic here does the following:
+		 * Disable (put tuner to sleep) when
+		 * - ALSA and DVB aren't not streaming;
+		 * - the last V4L2 file handler is closed.
+		 *
+		 * FIXME:
+		 *
+		 * Additionally, this logic could be improved to
+		 * disable the media source if the above conditions
+		 * are met and if the device:
+		 * - doesn't have a separate audio out plug (or
+		 * - doesn't use a silicon tuner like xc2028/3028/4000/5000).
+		 *
+		 * Once this additional logic is in place, a callback
+		 * is needed to enable the media source and power on
+		 * the tuner, for radio to work.
+		*/
+		ret = v4l_enable_media_source(vdev);
+		if (ret == 0)
+			v4l2_device_call_all(&dev->v4l2_dev, 0, core,
+					     s_power, 0);
 		dev->std_set_in_tuner_core = 0;
 
 		/* When close the device, set the usb intf0 into alt0 to free
@@ -1469,10 +1439,16 @@ static int vidioc_s_audio(struct file *file, void *priv, const struct v4l2_audio
 static int vidioc_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t)
 {
 	struct au0828_dev *dev = video_drvdata(file);
+	struct video_device *vfd = video_devdata(file);
+	int ret;
 
 	if (t->index != 0)
 		return -EINVAL;
 
+	ret = v4l_enable_media_source(vfd);
+	if (ret)
+		return ret;
+
 	dprintk(1, "%s called std_set %d dev_state %d\n", __func__,
 		dev->std_set_in_tuner_core, dev->dev_state);
 
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH v3 22/22] sound/usb: Use Media Controller API to share media resources
  2016-02-11 23:41 [PATCH v3 00/22] Sharing media resources across ALSA and au0828 drivers Shuah Khan
                   ` (20 preceding siblings ...)
  2016-02-11 23:41 ` [PATCH v3 21/22] media: au0828 video change to use v4l_enable_media_source() Shuah Khan
@ 2016-02-11 23:41 ` Shuah Khan
  2016-02-26 19:33   ` Shuah Khan
  2016-02-26 19:55   ` Takashi Iwai
  21 siblings, 2 replies; 49+ messages in thread
From: Shuah Khan @ 2016-02-11 23:41 UTC (permalink / raw)
  To: mchehab, tiwai, clemens, hans.verkuil, laurent.pinchart,
	sakari.ailus, javier
  Cc: Shuah Khan, pawel, m.szyprowski, kyungmin.park, perex, arnd,
	dan.carpenter, tvboxspy, crope, ruchandani.tina, corbet,
	chehabrafael, k.kozlowski, stefanr, inki.dae, jh1009.sung,
	elfring, prabhakar.csengg, sw0312.kim, p.zabel, ricardo.ribalda,
	labbott, pierre-louis.bossart, ricard.wanderlof, julian,
	takamichiho, dominic.sacre, misterpib, daniel, gtmkramer,
	normalperson, joe, linuxbugs, johan, klock.android, nenggun.kim,
	j.anaszewski, geliangtang, albert, linux-kernel, linux-media,
	alsa-devel

Change ALSA driver to use Media Controller API to
share media resources with DVB and V4L2 drivers
on a AU0828 media device. Media Controller specific
initialization is done after sound card is registered.
ALSA creates Media interface and entity function graph
nodes for Control, Mixer, PCM Playback, and PCM Capture
devices.

snd_usb_hw_params() will call Media Controller enable
source handler interface to request the media resource.
If resource request is granted, it will release it from
snd_usb_hw_free(). If resource is busy, -EBUSY is returned.

Media specific cleanup is done in usb_audio_disconnect().

Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
---
 sound/usb/Kconfig        |   4 +
 sound/usb/Makefile       |   2 +
 sound/usb/card.c         |  14 +++
 sound/usb/card.h         |   3 +
 sound/usb/media.c        | 318 +++++++++++++++++++++++++++++++++++++++++++++++
 sound/usb/media.h        |  72 +++++++++++
 sound/usb/mixer.h        |   3 +
 sound/usb/pcm.c          |  28 ++++-
 sound/usb/quirks-table.h |   1 +
 sound/usb/stream.c       |   2 +
 sound/usb/usbaudio.h     |   6 +
 11 files changed, 448 insertions(+), 5 deletions(-)
 create mode 100644 sound/usb/media.c
 create mode 100644 sound/usb/media.h

diff --git a/sound/usb/Kconfig b/sound/usb/Kconfig
index a452ad7..ba117f5 100644
--- a/sound/usb/Kconfig
+++ b/sound/usb/Kconfig
@@ -15,6 +15,7 @@ config SND_USB_AUDIO
 	select SND_RAWMIDI
 	select SND_PCM
 	select BITREVERSE
+	select SND_USB_AUDIO_USE_MEDIA_CONTROLLER if MEDIA_CONTROLLER && MEDIA_SUPPORT
 	help
 	  Say Y here to include support for USB audio and USB MIDI
 	  devices.
@@ -22,6 +23,9 @@ config SND_USB_AUDIO
 	  To compile this driver as a module, choose M here: the module
 	  will be called snd-usb-audio.
 
+config SND_USB_AUDIO_USE_MEDIA_CONTROLLER
+	bool
+
 config SND_USB_UA101
 	tristate "Edirol UA-101/UA-1000 driver"
 	select SND_PCM
diff --git a/sound/usb/Makefile b/sound/usb/Makefile
index 2d2d122..8dca3c4 100644
--- a/sound/usb/Makefile
+++ b/sound/usb/Makefile
@@ -15,6 +15,8 @@ snd-usb-audio-objs := 	card.o \
 			quirks.o \
 			stream.o
 
+snd-usb-audio-$(CONFIG_SND_USB_AUDIO_USE_MEDIA_CONTROLLER) += media.o
+
 snd-usbmidi-lib-objs := midi.o
 
 # Toplevel Module Dependency
diff --git a/sound/usb/card.c b/sound/usb/card.c
index 1f09d95..35fe256 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");
@@ -561,6 +562,11 @@ static int usb_audio_probe(struct usb_interface *intf,
 	if (err < 0)
 		goto __error;
 
+	if (quirk->media_device) {
+		/* don't want to fail when media_device_create() fails */
+		media_device_create(chip, intf);
+	}
+
 	usb_chip[chip->index] = chip;
 	chip->num_interfaces++;
 	usb_set_intfdata(intf, chip);
@@ -617,6 +623,14 @@ static void usb_audio_disconnect(struct usb_interface *intf)
 		list_for_each(p, &chip->midi_list) {
 			snd_usbmidi_disconnect(p);
 		}
+		/*
+		 * Nice to check quirk && quirk->media_device
+		 * need some special handlings. Doesn't look like
+		 * we have access to quirk here
+		 * Acceses mixer_list
+		*/
+		media_device_delete(chip);
+
 		/* release mixer resources */
 		list_for_each_entry(mixer, &chip->mixer_list, list) {
 			snd_usb_mixer_disconnect(mixer);
diff --git a/sound/usb/card.h b/sound/usb/card.h
index 71778ca..34a0898 100644
--- a/sound/usb/card.h
+++ b/sound/usb/card.h
@@ -105,6 +105,8 @@ struct snd_usb_endpoint {
 	struct list_head list;
 };
 
+struct media_ctl;
+
 struct snd_usb_substream {
 	struct snd_usb_stream *stream;
 	struct usb_device *dev;
@@ -156,6 +158,7 @@ struct snd_usb_substream {
 	} dsd_dop;
 
 	bool trigger_tstamp_pending_update; /* trigger timestamp being updated from initial estimate */
+	struct media_ctl *media_ctl;
 };
 
 struct snd_usb_stream {
diff --git a/sound/usb/media.c b/sound/usb/media.c
new file mode 100644
index 0000000..cff1459
--- /dev/null
+++ b/sound/usb/media.c
@@ -0,0 +1,318 @@
+/*
+ * media.c - Media Controller specific ALSA driver code
+ *
+ * Copyright (c) 2016 Shuah Khan <shuahkh@osg.samsung.com>
+ * Copyright (c) 2016 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.
+*/
+
+#include <linux/init.h>
+#include <linux/list.h>
+#include <linux/mutex.h>
+#include <linux/slab.h>
+#include <linux/usb.h>
+
+#include <sound/pcm.h>
+#include <sound/core.h>
+
+#include "usbaudio.h"
+#include "card.h"
+#include "mixer.h"
+#include "media.h"
+
+static int media_enable_source(struct media_ctl *mctl)
+{
+	if (mctl && mctl->media_dev->enable_source)
+		return mctl->media_dev->enable_source(&mctl->media_entity,
+						      &mctl->media_pipe);
+	return 0;
+}
+
+static void media_disable_source(struct media_ctl *mctl)
+{
+	if (mctl && mctl->media_dev->disable_source)
+		mctl->media_dev->disable_source(&mctl->media_entity);
+}
+
+int media_stream_init(struct snd_usb_substream *subs, struct snd_pcm *pcm,
+			int stream)
+{
+	struct media_device *mdev;
+	struct media_ctl *mctl;
+	struct device *pcm_dev = &pcm->streams[stream].dev;
+	u32 intf_type;
+	int ret = 0;
+	u16 mixer_pad;
+	struct media_entity *entity;
+
+	mdev = subs->stream->chip->media_dev;
+	if (!mdev)
+		return -ENODEV;
+
+	if (subs->media_ctl)
+		return 0;
+
+	/* allocate media_ctl */
+	mctl = kzalloc(sizeof(*mctl), GFP_KERNEL);
+	if (!mctl)
+		return -ENOMEM;
+
+	mctl->media_dev = mdev;
+	if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
+		intf_type = MEDIA_INTF_T_ALSA_PCM_PLAYBACK;
+		mctl->media_entity.function = MEDIA_ENT_F_AUDIO_PLAYBACK;
+		mctl->media_pad.flags = MEDIA_PAD_FL_SOURCE;
+		mixer_pad = 1;
+	} else {
+		intf_type = MEDIA_INTF_T_ALSA_PCM_CAPTURE;
+		mctl->media_entity.function = MEDIA_ENT_F_AUDIO_CAPTURE;
+		mctl->media_pad.flags = MEDIA_PAD_FL_SINK;
+		mixer_pad = 2;
+	}
+	mctl->media_entity.name = pcm->name;
+	media_entity_pads_init(&mctl->media_entity, 1, &mctl->media_pad);
+	ret =  media_device_register_entity(mctl->media_dev,
+					    &mctl->media_entity);
+	if (ret)
+		goto err1;
+
+	mctl->intf_devnode = media_devnode_create(mdev, intf_type, 0,
+						  MAJOR(pcm_dev->devt),
+						  MINOR(pcm_dev->devt));
+	if (!mctl->intf_devnode) {
+		ret = -ENOMEM;
+		goto err2;
+	}
+	mctl->intf_link = media_create_intf_link(&mctl->media_entity,
+						 &mctl->intf_devnode->intf,
+						 MEDIA_LNK_FL_ENABLED);
+	if (!mctl->intf_link) {
+		ret = -ENOMEM;
+		goto err3;
+	}
+
+	/* create link between mixer and audio */
+	media_device_for_each_entity(entity, mdev) {
+		switch (entity->function) {
+		case MEDIA_ENT_F_AUDIO_MIXER:
+			ret = media_create_pad_link(entity, mixer_pad,
+						    &mctl->media_entity, 0,
+						    MEDIA_LNK_FL_ENABLED);
+			if (ret)
+				goto err4;
+			break;
+		}
+	}
+
+	subs->media_ctl = mctl;
+	return 0;
+
+err4:
+	media_remove_intf_link(mctl->intf_link);
+err3:
+	media_devnode_remove(mctl->intf_devnode);
+err2:
+	media_device_unregister_entity(&mctl->media_entity);
+err1:
+	kfree(mctl);
+	return ret;
+}
+
+void media_stream_delete(struct snd_usb_substream *subs)
+{
+	struct media_ctl *mctl = subs->media_ctl;
+
+	if (mctl && mctl->media_dev) {
+		struct media_device *mdev;
+
+		mdev = subs->stream->chip->media_dev;
+		if (mdev && media_devnode_is_registered(&mdev->devnode)) {
+			media_devnode_remove(mctl->intf_devnode);
+			media_device_unregister_entity(&mctl->media_entity);
+			media_entity_cleanup(&mctl->media_entity);
+		}
+		kfree(mctl);
+		subs->media_ctl = NULL;
+	}
+}
+
+int media_start_pipeline(struct snd_usb_substream *subs)
+{
+	struct media_ctl *mctl = subs->media_ctl;
+
+	if (mctl)
+		return media_enable_source(mctl);
+	return 0;
+}
+
+void media_stop_pipeline(struct snd_usb_substream *subs)
+{
+	struct media_ctl *mctl = subs->media_ctl;
+
+	if (mctl)
+		media_disable_source(mctl);
+}
+
+int media_mixer_init(struct snd_usb_audio *chip)
+{
+	struct device *ctl_dev = &chip->card->ctl_dev;
+	struct media_intf_devnode *ctl_intf;
+	struct usb_mixer_interface *mixer;
+	struct media_device *mdev = chip->media_dev;
+	struct media_mixer_ctl *mctl;
+	u32 intf_type = MEDIA_INTF_T_ALSA_CONTROL;
+	int ret;
+
+	if (!mdev)
+		return -ENODEV;
+
+	ctl_intf = chip->ctl_intf_media_devnode;
+	if (!ctl_intf) {
+		ctl_intf = media_devnode_create(mdev, intf_type, 0,
+						MAJOR(ctl_dev->devt),
+						MINOR(ctl_dev->devt));
+		if (!ctl_intf)
+			return -ENOMEM;
+		chip->ctl_intf_media_devnode = ctl_intf;
+	}
+
+	list_for_each_entry(mixer, &chip->mixer_list, list) {
+
+		if (mixer->media_mixer_ctl)
+			continue;
+
+		/* allocate media_mixer_ctl */
+		mctl = kzalloc(sizeof(*mctl), GFP_KERNEL);
+		if (!mctl)
+			return -ENOMEM;
+
+		mctl->media_dev = mdev;
+		mctl->media_entity.function = MEDIA_ENT_F_AUDIO_MIXER;
+		mctl->media_entity.name = chip->card->mixername;
+		mctl->media_pad[0].flags = MEDIA_PAD_FL_SINK;
+		mctl->media_pad[1].flags = MEDIA_PAD_FL_SOURCE;
+		mctl->media_pad[2].flags = MEDIA_PAD_FL_SOURCE;
+		media_entity_pads_init(&mctl->media_entity, MEDIA_MIXER_PAD_MAX,
+				  mctl->media_pad);
+		ret =  media_device_register_entity(mctl->media_dev,
+						    &mctl->media_entity);
+		if (ret) {
+			kfree(mctl);
+			return ret;
+		}
+
+		mctl->intf_link = media_create_intf_link(&mctl->media_entity,
+							 &ctl_intf->intf,
+							 MEDIA_LNK_FL_ENABLED);
+		if (!mctl->intf_link) {
+			media_device_unregister_entity(&mctl->media_entity);
+			media_entity_cleanup(&mctl->media_entity);
+			kfree(mctl);
+			return -ENOMEM;
+		}
+		mctl->intf_devnode = ctl_intf;
+		mixer->media_mixer_ctl = mctl;
+	}
+	return 0;
+}
+
+static void media_mixer_delete(struct snd_usb_audio *chip)
+{
+	struct usb_mixer_interface *mixer;
+	struct media_device *mdev = chip->media_dev;
+
+	if (!mdev)
+		return;
+
+	list_for_each_entry(mixer, &chip->mixer_list, list) {
+		struct media_mixer_ctl *mctl;
+
+		mctl = mixer->media_mixer_ctl;
+		if (!mixer->media_mixer_ctl)
+			continue;
+
+		if (media_devnode_is_registered(&mdev->devnode)) {
+			media_device_unregister_entity(&mctl->media_entity);
+			media_entity_cleanup(&mctl->media_entity);
+		}
+		kfree(mctl);
+		mixer->media_mixer_ctl = NULL;
+	}
+	if (media_devnode_is_registered(&mdev->devnode))
+		media_devnode_remove(chip->ctl_intf_media_devnode);
+	chip->ctl_intf_media_devnode = NULL;
+}
+
+int media_device_create(struct snd_usb_audio *chip,
+			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 (!mdev->dev) {
+		/* 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);
+		media_device_init(mdev);
+	}
+	if (!media_devnode_is_registered(&mdev->devnode)) {
+		ret = media_device_register(mdev);
+		if (ret) {
+			dev_err(&usbdev->dev,
+				"Couldn't register media device. Error: %d\n",
+				ret);
+			return ret;
+		}
+	}
+
+	/* save media device - avoid lookups */
+	chip->media_dev = mdev;
+
+	/* Create media entities for mixer and control dev */
+	ret = media_mixer_init(chip);
+	if (ret) {
+		dev_err(&usbdev->dev,
+			"Couldn't create media mixer entities. Error: %d\n",
+			ret);
+
+		/* clear saved media_dev */
+		chip->media_dev = NULL;
+
+		return ret;
+	}
+	return 0;
+}
+
+void media_device_delete(struct snd_usb_audio *chip)
+{
+	struct media_device *mdev = chip->media_dev;
+
+	media_mixer_delete(chip);
+
+	if (mdev) {
+		if (media_devnode_is_registered(&mdev->devnode))
+			media_device_unregister(mdev);
+		chip->media_dev = NULL;
+	}
+}
diff --git a/sound/usb/media.h b/sound/usb/media.h
new file mode 100644
index 0000000..f66b4d7
--- /dev/null
+++ b/sound/usb/media.h
@@ -0,0 +1,72 @@
+/*
+ * media.h - Media Controller specific ALSA driver code
+ *
+ * Copyright (c) 2016 Shuah Khan <shuahkh@osg.samsung.com>
+ * Copyright (c) 2016 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 CONFIG_SND_USB_AUDIO_USE_MEDIA_CONTROLLER
+
+#include <media/media-device.h>
+#include <media/media-entity.h>
+#include <sound/asound.h>
+
+struct media_ctl {
+	struct media_device *media_dev;
+	struct media_entity media_entity;
+	struct media_intf_devnode *intf_devnode;
+	struct media_link *intf_link;
+	struct media_pad media_pad;
+	struct media_pipeline media_pipe;
+};
+
+/*
+ * One source pad each for SNDRV_PCM_STREAM_CAPTURE and
+ * SNDRV_PCM_STREAM_PLAYBACK. One for sink pad to link
+ * to AUDIO Source
+*/
+#define MEDIA_MIXER_PAD_MAX    (SNDRV_PCM_STREAM_LAST + 2)
+
+struct media_mixer_ctl {
+	struct media_device *media_dev;
+	struct media_entity media_entity;
+	struct media_intf_devnode *intf_devnode;
+	struct media_link *intf_link;
+	struct media_pad media_pad[MEDIA_MIXER_PAD_MAX];
+	struct media_pipeline media_pipe;
+};
+
+int media_device_create(struct snd_usb_audio *chip,
+			struct usb_interface *iface);
+void media_device_delete(struct snd_usb_audio *chip);
+int media_stream_init(struct snd_usb_substream *subs, struct snd_pcm *pcm,
+			int stream);
+void media_stream_delete(struct snd_usb_substream *subs);
+int media_start_pipeline(struct snd_usb_substream *subs);
+void media_stop_pipeline(struct snd_usb_substream *subs);
+#else
+static inline int media_device_create(struct snd_usb_audio *chip,
+				      struct usb_interface *iface)
+						{ return 0; }
+static inline void media_device_delete(struct snd_usb_audio *chip) { }
+static inline int media_stream_init(struct snd_usb_substream *subs,
+					struct snd_pcm *pcm, int stream)
+						{ return 0; }
+static inline void media_stream_delete(struct snd_usb_substream *subs) { }
+static inline int media_start_pipeline(struct snd_usb_substream *subs)
+					{ return 0; }
+static inline void media_stop_pipeline(struct snd_usb_substream *subs) { }
+#endif
+#endif /* __MEDIA_H */
diff --git a/sound/usb/mixer.h b/sound/usb/mixer.h
index 3417ef3..f378944 100644
--- a/sound/usb/mixer.h
+++ b/sound/usb/mixer.h
@@ -3,6 +3,8 @@
 
 #include <sound/info.h>
 
+struct media_mixer_ctl;
+
 struct usb_mixer_interface {
 	struct snd_usb_audio *chip;
 	struct usb_host_interface *hostif;
@@ -22,6 +24,7 @@ struct usb_mixer_interface {
 	struct urb *rc_urb;
 	struct usb_ctrlrequest *rc_setup_packet;
 	u8 rc_buffer[6];
+	struct media_mixer_ctl *media_mixer_ctl;
 };
 
 #define MAX_CHANNELS	16	/* max logical channels */
diff --git a/sound/usb/pcm.c b/sound/usb/pcm.c
index 9245f52..c3b8486 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
@@ -715,10 +716,14 @@ static int snd_usb_hw_params(struct snd_pcm_substream *substream,
 	struct audioformat *fmt;
 	int ret;
 
+	ret = media_start_pipeline(subs);
+	if (ret)
+		return ret;
+
 	ret = snd_pcm_lib_alloc_vmalloc_buffer(substream,
 					       params_buffer_bytes(hw_params));
 	if (ret < 0)
-		return ret;
+		goto err_ret;
 
 	subs->pcm_format = params_format(hw_params);
 	subs->period_bytes = params_period_bytes(hw_params);
@@ -732,22 +737,27 @@ static int snd_usb_hw_params(struct snd_pcm_substream *substream,
 		dev_dbg(&subs->dev->dev,
 			"cannot set format: format = %#x, rate = %d, channels = %d\n",
 			   subs->pcm_format, subs->cur_rate, subs->channels);
-		return -EINVAL;
+		ret = -EINVAL;
+		goto err_ret;
 	}
 
 	ret = snd_usb_lock_shutdown(subs->stream->chip);
 	if (ret < 0)
-		return ret;
+		goto err_ret;
 	ret = set_format(subs, fmt);
 	snd_usb_unlock_shutdown(subs->stream->chip);
 	if (ret < 0)
-		return ret;
+		goto err_ret;
 
 	subs->interface = fmt->iface;
 	subs->altset_idx = fmt->altset_idx;
 	subs->need_setup_ep = true;
 
 	return 0;
+
+err_ret:
+	media_stop_pipeline(subs);
+	return ret;
 }
 
 /*
@@ -759,6 +769,7 @@ static int snd_usb_hw_free(struct snd_pcm_substream *substream)
 {
 	struct snd_usb_substream *subs = substream->runtime->private_data;
 
+	media_stop_pipeline(subs);
 	subs->cur_audiofmt = NULL;
 	subs->cur_rate = 0;
 	subs->period_bytes = 0;
@@ -1219,6 +1230,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;
@@ -1232,7 +1244,12 @@ 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)
+		ret = media_stream_init(subs, as->pcm, direction);
+	if (ret)
+		snd_usb_autosuspend(subs->stream->chip);
+	return ret;
 }
 
 static int snd_usb_pcm_close(struct snd_pcm_substream *substream, int direction)
@@ -1241,6 +1258,7 @@ static int snd_usb_pcm_close(struct snd_pcm_substream *substream, int direction)
 	struct snd_usb_substream *subs = &as->substream[direction];
 
 	stop_endpoints(subs, true);
+	media_stop_pipeline(subs);
 
 	if (subs->interface >= 0 &&
 	    !snd_usb_lock_shutdown(subs->stream->chip)) {
diff --git a/sound/usb/quirks-table.h b/sound/usb/quirks-table.h
index c60a776..9d087b1 100644
--- a/sound/usb/quirks-table.h
+++ b/sound/usb/quirks-table.h
@@ -2886,6 +2886,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/stream.c b/sound/usb/stream.c
index c4dc577..6c7f5c1 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);
 }
 
 
diff --git a/sound/usb/usbaudio.h b/sound/usb/usbaudio.h
index b665d85..a161c7c 100644
--- a/sound/usb/usbaudio.h
+++ b/sound/usb/usbaudio.h
@@ -30,6 +30,9 @@
  *
  */
 
+struct media_device;
+struct media_intf_devnode;
+
 struct snd_usb_audio {
 	int index;
 	struct usb_device *dev;
@@ -60,6 +63,8 @@ struct snd_usb_audio {
 	bool autoclock;			/* from the 'autoclock' module param */
 
 	struct usb_host_interface *ctrl_intf;	/* the audio control interface */
+	struct media_device *media_dev;
+	struct media_intf_devnode *ctl_intf_media_devnode;
 };
 
 #define usb_audio_err(chip, fmt, args...) \
@@ -110,6 +115,7 @@ struct snd_usb_audio_quirk {
 	const char *product_name;
 	int16_t ifnum;
 	uint16_t type;
+	bool media_device;
 	const void *data;
 };
 
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* Re: [PATCH v3 01/22] [media] Docbook: media-types.xml: Add ALSA Media Controller Intf types
  2016-02-11 23:41 ` [PATCH v3 01/22] [media] Docbook: media-types.xml: Add ALSA Media Controller Intf types Shuah Khan
@ 2016-02-17 12:19   ` Mauro Carvalho Chehab
  2016-02-17 14:59     ` Shuah Khan
  2016-02-26 19:28     ` Shuah Khan
  0 siblings, 2 replies; 49+ messages in thread
From: Mauro Carvalho Chehab @ 2016-02-17 12:19 UTC (permalink / raw)
  To: Shuah Khan, tiwai
  Cc: clemens, hans.verkuil, laurent.pinchart, sakari.ailus, javier,
	pawel, m.szyprowski, kyungmin.park, perex, arnd, dan.carpenter,
	tvboxspy, crope, ruchandani.tina, corbet, chehabrafael,
	k.kozlowski, stefanr, inki.dae, jh1009.sung, elfring,
	prabhakar.csengg, sw0312.kim, p.zabel, ricardo.ribalda, labbott,
	pierre-louis.bossart, ricard.wanderlof, julian, takamichiho,
	dominic.sacre, misterpib, daniel, gtmkramer, normalperson, joe,
	linuxbugs, johan, klock.android, nenggun.kim, j.anaszewski,
	geliangtang, albert, linux-kernel, linux-media, alsa-devel

Em Thu, 11 Feb 2016 16:41:17 -0700
Shuah Khan <shuahkh@osg.samsung.com> escreveu:

> Add ALSA Media Controller Intf types
> 
> Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
> ---
>  Documentation/DocBook/media/v4l/media-types.xml | 40 +++++++++++++++++++++++++
>  1 file changed, 40 insertions(+)
> 
> diff --git a/Documentation/DocBook/media/v4l/media-types.xml b/Documentation/DocBook/media/v4l/media-types.xml
> index 751c3d0..3730967 100644
> --- a/Documentation/DocBook/media/v4l/media-types.xml
> +++ b/Documentation/DocBook/media/v4l/media-types.xml
> @@ -193,6 +193,46 @@
>  	    <entry>Device node interface for Software Defined Radio (V4L)</entry>
>  	    <entry>typically, /dev/swradio?</entry>
>  	  </row>
> +	  <row>
> +	    <entry><constant>MEDIA_INTF_T_ALSA_PCM_CAPTURE</constant></entry>
> +	    <entry>Device node interface for ASLA PCM Capture</entry>
> +	    <entry>typically, /dev/snd/pcmC?D?c</entry>
> +	  </row>
> +	  <row>
> +	    <entry><constant>MEDIA_INTF_T_ALSA_PCM_PLAYBACK</constant></entry>
> +	    <entry>Device node interface for ASLA PCM Playback</entry>
> +	    <entry>typically, /dev/snd/pcmC?D?p</entry>
> +	  </row>
> +	  <row>
> +	    <entry><constant>MEDIA_INTF_T_ALSA_CONTROL</constant></entry>
> +	    <entry>Device node interface for ASLA Control</entry>
> +	    <entry>typically, /dev/snd/controlC?</entry>
> +	  </row>
> +	  <row>
> +	    <entry><constant>MEDIA_INTF_T_ALSA_COMPRESS</constant></entry>
> +	    <entry>Device node interface for ASLA Compress</entry>
> +	    <entry>typically, /dev/snd/compr?</entry>
> +	  </row>
> +	  <row>
> +	    <entry><constant>MEDIA_INTF_T_ALSA_RAWMIDI</constant></entry>
> +	    <entry>Device node interface for ASLA Raw MIDI</entry>
> +	    <entry>typically, /dev/snd/midi?</entry>
> +	  </row>
> +	  <row>
> +	    <entry><constant>MEDIA_INTF_T_ALSA_HWDEP</constant></entry>
> +	    <entry>Device node interface for ASLA Hardware Dependent</entry>
> +	    <entry>typically, /dev/snd/hwC?D?</entry>
> +	  </row>
> +	  <row>
> +	    <entry><constant>MEDIA_INTF_T_ALSA_SEQUENCER</constant></entry>
> +	    <entry>Device node interface for ASLA Sequencer</entry>
> +	    <entry>typically, /dev/snd/seq</entry>
> +	  </row>
> +	  <row>
> +	    <entry><constant>MEDIA_INTF_T_ALSA_TIMER</constant></entry>
> +	    <entry>Device node interface for ASLA Timer</entry>
> +	    <entry>typically, /dev/snd/timer</entry>

On all the above:
	s,ASLA,ALSA,

Except for that, patch looks OK for me.

Takashi,

If this is OK for you too, could you please ack?

Thanks,
Mauro

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v3 02/22] uapi/media.h: Declare interface types for ALSA
  2016-02-11 23:41 ` [PATCH v3 02/22] uapi/media.h: Declare interface types for ALSA Shuah Khan
@ 2016-02-17 12:21   ` Mauro Carvalho Chehab
  2016-02-26 19:30     ` Shuah Khan
  2016-03-03 14:59   ` Hans Verkuil
  1 sibling, 1 reply; 49+ messages in thread
From: Mauro Carvalho Chehab @ 2016-02-17 12:21 UTC (permalink / raw)
  To: Shuah Khan, tiwai
  Cc: clemens, hans.verkuil, laurent.pinchart, sakari.ailus, javier,
	pawel, m.szyprowski, kyungmin.park, perex, arnd, dan.carpenter,
	tvboxspy, crope, ruchandani.tina, corbet, chehabrafael,
	k.kozlowski, stefanr, inki.dae, jh1009.sung, elfring,
	prabhakar.csengg, sw0312.kim, p.zabel, ricardo.ribalda, labbott,
	pierre-louis.bossart, ricard.wanderlof, julian, takamichiho,
	dominic.sacre, misterpib, daniel, gtmkramer, normalperson, joe,
	linuxbugs, johan, klock.android, nenggun.kim, j.anaszewski,
	geliangtang, albert, linux-kernel, linux-media, alsa-devel

Em Thu, 11 Feb 2016 16:41:18 -0700
Shuah Khan <shuahkh@osg.samsung.com> escreveu:

> Declare the interface types to be used on alsa for
> the new G_TOPOLOGY ioctl.
> 
> Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
> ---
>  drivers/media/media-entity.c | 16 ++++++++++++++++
>  include/uapi/linux/media.h   | 10 ++++++++++
>  2 files changed, 26 insertions(+)
> 
> diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
> index f2e4360..6179543 100644
> --- a/drivers/media/media-entity.c
> +++ b/drivers/media/media-entity.c
> @@ -65,6 +65,22 @@ static inline const char *intf_type(struct media_interface *intf)
>  		return "v4l2-subdev";
>  	case MEDIA_INTF_T_V4L_SWRADIO:
>  		return "swradio";
> +	case MEDIA_INTF_T_ALSA_PCM_CAPTURE:
> +		return "pcm-capture";
> +	case MEDIA_INTF_T_ALSA_PCM_PLAYBACK:
> +		return "pcm-playback";
> +	case MEDIA_INTF_T_ALSA_CONTROL:
> +		return "alsa-control";
> +	case MEDIA_INTF_T_ALSA_COMPRESS:
> +		return "compress";
> +	case MEDIA_INTF_T_ALSA_RAWMIDI:
> +		return "rawmidi";
> +	case MEDIA_INTF_T_ALSA_HWDEP:
> +		return "hwdep";
> +	case MEDIA_INTF_T_ALSA_SEQUENCER:
> +		return "sequencer";
> +	case MEDIA_INTF_T_ALSA_TIMER:
> +		return "timer";
>  	default:
>  		return "unknown-intf";
>  	}
> diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
> index c9eb42a..3cc0366 100644
> --- a/include/uapi/linux/media.h
> +++ b/include/uapi/linux/media.h
> @@ -265,6 +265,7 @@ struct media_links_enum {
>  
>  #define MEDIA_INTF_T_DVB_BASE	0x00000100
>  #define MEDIA_INTF_T_V4L_BASE	0x00000200
> +#define MEDIA_INTF_T_ALSA_BASE	0x00000300
>  
>  /* Interface types */
>  
> @@ -280,6 +281,15 @@ struct media_links_enum {
>  #define MEDIA_INTF_T_V4L_SUBDEV (MEDIA_INTF_T_V4L_BASE + 3)
>  #define MEDIA_INTF_T_V4L_SWRADIO (MEDIA_INTF_T_V4L_BASE + 4)
>  
> +#define MEDIA_INTF_T_ALSA_PCM_CAPTURE   (MEDIA_INTF_T_ALSA_BASE)
> +#define MEDIA_INTF_T_ALSA_PCM_PLAYBACK  (MEDIA_INTF_T_ALSA_BASE + 1)
> +#define MEDIA_INTF_T_ALSA_CONTROL       (MEDIA_INTF_T_ALSA_BASE + 2)
> +#define MEDIA_INTF_T_ALSA_COMPRESS      (MEDIA_INTF_T_ALSA_BASE + 3)
> +#define MEDIA_INTF_T_ALSA_RAWMIDI       (MEDIA_INTF_T_ALSA_BASE + 4)
> +#define MEDIA_INTF_T_ALSA_HWDEP         (MEDIA_INTF_T_ALSA_BASE + 5)
> +#define MEDIA_INTF_T_ALSA_SEQUENCER     (MEDIA_INTF_T_ALSA_BASE + 6)
> +#define MEDIA_INTF_T_ALSA_TIMER         (MEDIA_INTF_T_ALSA_BASE + 7)
> +
>  /*
>   * MC next gen API definitions
>   *

Looks OK to me.

Takashi,

If this is OK for you too, would you mind acking it?

Thanks,
Mauro

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v3 03/22] [media] Docbook: media-types.xml: Add Audio Function Entities
  2016-02-11 23:41 ` [PATCH v3 03/22] [media] Docbook: media-types.xml: Add Audio Function Entities Shuah Khan
@ 2016-02-17 12:23   ` Mauro Carvalho Chehab
  2016-02-26 19:40     ` Takashi Iwai
       [not found]   ` <1886674.Y0SDWvK9bd@avalon>
  1 sibling, 1 reply; 49+ messages in thread
From: Mauro Carvalho Chehab @ 2016-02-17 12:23 UTC (permalink / raw)
  To: Shuah Khan, tiwai
  Cc: clemens, hans.verkuil, laurent.pinchart, sakari.ailus, javier,
	pawel, m.szyprowski, kyungmin.park, perex, arnd, dan.carpenter,
	tvboxspy, crope, ruchandani.tina, corbet, chehabrafael,
	k.kozlowski, stefanr, inki.dae, jh1009.sung, elfring,
	prabhakar.csengg, sw0312.kim, p.zabel, ricardo.ribalda, labbott,
	pierre-louis.bossart, ricard.wanderlof, julian, takamichiho,
	dominic.sacre, misterpib, daniel, gtmkramer, normalperson, joe,
	linuxbugs, johan, klock.android, nenggun.kim, j.anaszewski,
	geliangtang, albert, linux-kernel, linux-media, alsa-devel

Em Thu, 11 Feb 2016 16:41:19 -0700
Shuah Khan <shuahkh@osg.samsung.com> escreveu:

> Add Audio Function Entities
> 
> Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
> ---
>  Documentation/DocBook/media/v4l/media-types.xml | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
> 
> diff --git a/Documentation/DocBook/media/v4l/media-types.xml b/Documentation/DocBook/media/v4l/media-types.xml
> index 3730967..924a604 100644
> --- a/Documentation/DocBook/media/v4l/media-types.xml
> +++ b/Documentation/DocBook/media/v4l/media-types.xml
> @@ -113,6 +113,18 @@
>  		   decoder.
>  	    </entry>
>  	  </row>
> +	  <row>
> +	    <entry><constant>MEDIA_ENT_F_AUDIO_CAPTURE</constant></entry>
> +	    <entry>Audio Capture Function Entity.</entry>
> +	  </row>
> +	  <row>
> +	    <entry><constant>MEDIA_ENT_F_AUDIO_PLAYBACK</constant></entry>
> +	    <entry>Audio Playback Function Entity.</entry>
> +	  </row>
> +	  <row>
> +	    <entry><constant>MEDIA_ENT_F_AUDIO_MIXER</constant></entry>
> +	    <entry>Audio Mixer Function Entity.</entry>
> +	  </row>
>  	</tbody>
>        </tgroup>
>      </table>

Looks OK to me.

Takashi,

Could you ack if ok for you?


-- 
Thanks,
Mauro

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v3 04/22] media: Add ALSA Media Controller function entities
  2016-02-11 23:41 ` [PATCH v3 04/22] media: Add ALSA Media Controller function entities Shuah Khan
@ 2016-02-17 12:25   ` Mauro Carvalho Chehab
  2016-02-26 19:40     ` Takashi Iwai
  0 siblings, 1 reply; 49+ messages in thread
From: Mauro Carvalho Chehab @ 2016-02-17 12:25 UTC (permalink / raw)
  To: Shuah Khan, tiwai
  Cc: clemens, hans.verkuil, laurent.pinchart, sakari.ailus, javier,
	pawel, m.szyprowski, kyungmin.park, perex, arnd, dan.carpenter,
	tvboxspy, crope, ruchandani.tina, corbet, chehabrafael,
	k.kozlowski, stefanr, inki.dae, jh1009.sung, elfring,
	prabhakar.csengg, sw0312.kim, p.zabel, ricardo.ribalda, labbott,
	pierre-louis.bossart, ricard.wanderlof, julian, takamichiho,
	dominic.sacre, misterpib, daniel, gtmkramer, normalperson, joe,
	linuxbugs, johan, klock.android, nenggun.kim, j.anaszewski,
	geliangtang, albert, linux-kernel, linux-media, alsa-devel

Em Thu, 11 Feb 2016 16:41:20 -0700
Shuah Khan <shuahkh@osg.samsung.com> escreveu:

> Add ALSA Media Controller capture, playback, and mixer
> function entity defines.
> 
> Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
> ---
>  include/uapi/linux/media.h | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
> index 3cc0366..449462e 100644
> --- a/include/uapi/linux/media.h
> +++ b/include/uapi/linux/media.h
> @@ -98,6 +98,13 @@ struct media_device_info {
>  #define MEDIA_ENT_F_IF_AUD_DECODER	(MEDIA_ENT_F_BASE + 42)
>  
>  /*
> + * Audio Entity Functions
> + */
> +#define MEDIA_ENT_F_AUDIO_CAPTURE	(MEDIA_ENT_F_BASE + 200)
> +#define MEDIA_ENT_F_AUDIO_PLAYBACK	(MEDIA_ENT_F_BASE + 201)
> +#define MEDIA_ENT_F_AUDIO_MIXER		(MEDIA_ENT_F_BASE + 202)
> +
> +/*
>   * Don't touch on those. The ranges MEDIA_ENT_F_OLD_BASE and
>   * MEDIA_ENT_F_OLD_SUBDEV_BASE are kept to keep backward compatibility
>   * with the legacy v1 API.The number range is out of range by purpose:

Looks OK to me. 

This won't apply anymore on master, because we changed the numberspace, 
but it is a trivial conflict. No need to rebase.

Takashi,

If OK for you, please ack.


-- 
Thanks,
Mauro

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v3 01/22] [media] Docbook: media-types.xml: Add ALSA Media Controller Intf types
  2016-02-17 12:19   ` Mauro Carvalho Chehab
@ 2016-02-17 14:59     ` Shuah Khan
  2016-02-26 19:28     ` Shuah Khan
  1 sibling, 0 replies; 49+ messages in thread
From: Shuah Khan @ 2016-02-17 14:59 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, tiwai
  Cc: clemens, hans.verkuil, laurent.pinchart, sakari.ailus, javier,
	pawel, m.szyprowski, kyungmin.park, perex, arnd, dan.carpenter,
	tvboxspy, crope, ruchandani.tina, corbet, chehabrafael,
	k.kozlowski, stefanr, inki.dae, jh1009.sung, elfring,
	prabhakar.csengg, sw0312.kim, p.zabel, ricardo.ribalda, labbott,
	pierre-louis.bossart, ricard.wanderlof, julian, takamichiho,
	dominic.sacre, misterpib, daniel, gtmkramer, normalperson, joe,
	linuxbugs, johan, klock.android, nenggun.kim, j.anaszewski,
	geliangtang, albert, linux-kernel, linux-media, alsa-devel,
	Shuah Khan

On 02/17/2016 05:19 AM, Mauro Carvalho Chehab wrote:
> Em Thu, 11 Feb 2016 16:41:17 -0700
> Shuah Khan <shuahkh@osg.samsung.com> escreveu:
> 
>> Add ALSA Media Controller Intf types
>>
>> Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
>> ---
>>  Documentation/DocBook/media/v4l/media-types.xml | 40 +++++++++++++++++++++++++
>>  1 file changed, 40 insertions(+)
>>
>> diff --git a/Documentation/DocBook/media/v4l/media-types.xml b/Documentation/DocBook/media/v4l/media-types.xml
>> index 751c3d0..3730967 100644
>> --- a/Documentation/DocBook/media/v4l/media-types.xml
>> +++ b/Documentation/DocBook/media/v4l/media-types.xml
>> @@ -193,6 +193,46 @@
>>  	    <entry>Device node interface for Software Defined Radio (V4L)</entry>
>>  	    <entry>typically, /dev/swradio?</entry>
>>  	  </row>
>> +	  <row>
>> +	    <entry><constant>MEDIA_INTF_T_ALSA_PCM_CAPTURE</constant></entry>
>> +	    <entry>Device node interface for ASLA PCM Capture</entry>
>> +	    <entry>typically, /dev/snd/pcmC?D?c</entry>
>> +	  </row>
>> +	  <row>
>> +	    <entry><constant>MEDIA_INTF_T_ALSA_PCM_PLAYBACK</constant></entry>
>> +	    <entry>Device node interface for ASLA PCM Playback</entry>
>> +	    <entry>typically, /dev/snd/pcmC?D?p</entry>
>> +	  </row>
>> +	  <row>
>> +	    <entry><constant>MEDIA_INTF_T_ALSA_CONTROL</constant></entry>
>> +	    <entry>Device node interface for ASLA Control</entry>
>> +	    <entry>typically, /dev/snd/controlC?</entry>
>> +	  </row>
>> +	  <row>
>> +	    <entry><constant>MEDIA_INTF_T_ALSA_COMPRESS</constant></entry>
>> +	    <entry>Device node interface for ASLA Compress</entry>
>> +	    <entry>typically, /dev/snd/compr?</entry>
>> +	  </row>
>> +	  <row>
>> +	    <entry><constant>MEDIA_INTF_T_ALSA_RAWMIDI</constant></entry>
>> +	    <entry>Device node interface for ASLA Raw MIDI</entry>
>> +	    <entry>typically, /dev/snd/midi?</entry>
>> +	  </row>
>> +	  <row>
>> +	    <entry><constant>MEDIA_INTF_T_ALSA_HWDEP</constant></entry>
>> +	    <entry>Device node interface for ASLA Hardware Dependent</entry>
>> +	    <entry>typically, /dev/snd/hwC?D?</entry>
>> +	  </row>
>> +	  <row>
>> +	    <entry><constant>MEDIA_INTF_T_ALSA_SEQUENCER</constant></entry>
>> +	    <entry>Device node interface for ASLA Sequencer</entry>
>> +	    <entry>typically, /dev/snd/seq</entry>
>> +	  </row>
>> +	  <row>
>> +	    <entry><constant>MEDIA_INTF_T_ALSA_TIMER</constant></entry>
>> +	    <entry>Device node interface for ASLA Timer</entry>
>> +	    <entry>typically, /dev/snd/timer</entry>
> 
> On all the above:
> 	s,ASLA,ALSA,

Sorry for the typo. Sent v4 with the fix.

> 
> Except for that, patch looks OK for me.
> 
> Takashi,
> 
> If this is OK for you too, could you please ack?
> 
> Thanks,
> Mauro
> 

-- Shuah

-- 
Shuah Khan
Sr. Linux Kernel Developer
Open Source Innovation Group
Samsung Research America (Silicon Valley)
shuahkh@osg.samsung.com | (970) 217-8978

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v3 01/22] [media] Docbook: media-types.xml: Add ALSA Media Controller Intf types
  2016-02-17 12:19   ` Mauro Carvalho Chehab
  2016-02-17 14:59     ` Shuah Khan
@ 2016-02-26 19:28     ` Shuah Khan
  1 sibling, 0 replies; 49+ messages in thread
From: Shuah Khan @ 2016-02-26 19:28 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, tiwai
  Cc: clemens, hans.verkuil, laurent.pinchart, sakari.ailus, javier,
	pawel, m.szyprowski, kyungmin.park, perex, arnd, dan.carpenter,
	tvboxspy, crope, ruchandani.tina, corbet, chehabrafael,
	k.kozlowski, stefanr, inki.dae, jh1009.sung, elfring,
	prabhakar.csengg, sw0312.kim, p.zabel, ricardo.ribalda, labbott,
	pierre-louis.bossart, ricard.wanderlof, julian, takamichiho,
	dominic.sacre, misterpib, daniel, gtmkramer, normalperson, joe,
	linuxbugs, johan, klock.android, nenggun.kim, j.anaszewski,
	geliangtang, albert, linux-kernel, linux-media, alsa-devel,
	Shuah Khan

On 02/17/2016 05:19 AM, Mauro Carvalho Chehab wrote:
> Em Thu, 11 Feb 2016 16:41:17 -0700
> Shuah Khan <shuahkh@osg.samsung.com> escreveu:
> 
>> Add ALSA Media Controller Intf types
>>
>> Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
>> ---
>>  Documentation/DocBook/media/v4l/media-types.xml | 40 +++++++++++++++++++++++++
>>  1 file changed, 40 insertions(+)
>>
>> diff --git a/Documentation/DocBook/media/v4l/media-types.xml b/Documentation/DocBook/media/v4l/media-types.xml
>> index 751c3d0..3730967 100644
>> --- a/Documentation/DocBook/media/v4l/media-types.xml
>> +++ b/Documentation/DocBook/media/v4l/media-types.xml
>> @@ -193,6 +193,46 @@
>>  	    <entry>Device node interface for Software Defined Radio (V4L)</entry>
>>  	    <entry>typically, /dev/swradio?</entry>
>>  	  </row>
>> +	  <row>
>> +	    <entry><constant>MEDIA_INTF_T_ALSA_PCM_CAPTURE</constant></entry>
>> +	    <entry>Device node interface for ASLA PCM Capture</entry>
>> +	    <entry>typically, /dev/snd/pcmC?D?c</entry>
>> +	  </row>
>> +	  <row>
>> +	    <entry><constant>MEDIA_INTF_T_ALSA_PCM_PLAYBACK</constant></entry>
>> +	    <entry>Device node interface for ASLA PCM Playback</entry>
>> +	    <entry>typically, /dev/snd/pcmC?D?p</entry>
>> +	  </row>
>> +	  <row>
>> +	    <entry><constant>MEDIA_INTF_T_ALSA_CONTROL</constant></entry>
>> +	    <entry>Device node interface for ASLA Control</entry>
>> +	    <entry>typically, /dev/snd/controlC?</entry>
>> +	  </row>
>> +	  <row>
>> +	    <entry><constant>MEDIA_INTF_T_ALSA_COMPRESS</constant></entry>
>> +	    <entry>Device node interface for ASLA Compress</entry>
>> +	    <entry>typically, /dev/snd/compr?</entry>
>> +	  </row>
>> +	  <row>
>> +	    <entry><constant>MEDIA_INTF_T_ALSA_RAWMIDI</constant></entry>
>> +	    <entry>Device node interface for ASLA Raw MIDI</entry>
>> +	    <entry>typically, /dev/snd/midi?</entry>
>> +	  </row>
>> +	  <row>
>> +	    <entry><constant>MEDIA_INTF_T_ALSA_HWDEP</constant></entry>
>> +	    <entry>Device node interface for ASLA Hardware Dependent</entry>
>> +	    <entry>typically, /dev/snd/hwC?D?</entry>
>> +	  </row>
>> +	  <row>
>> +	    <entry><constant>MEDIA_INTF_T_ALSA_SEQUENCER</constant></entry>
>> +	    <entry>Device node interface for ASLA Sequencer</entry>
>> +	    <entry>typically, /dev/snd/seq</entry>
>> +	  </row>
>> +	  <row>
>> +	    <entry><constant>MEDIA_INTF_T_ALSA_TIMER</constant></entry>
>> +	    <entry>Device node interface for ASLA Timer</entry>
>> +	    <entry>typically, /dev/snd/timer</entry>
> 
> On all the above:
> 	s,ASLA,ALSA,
> 
> Except for that, patch looks OK for me.
> 
> Takashi,
> 
> If this is OK for you too, could you please ack?
> 

Hi Takashi/Mauro,

I send Patch v4 for just this patch to fix the above.

Takashi,

Could you please Ack if you are okay with this.

thanks,
-- Shuah




-- 
Shuah Khan
Sr. Linux Kernel Developer
Open Source Innovation Group
Samsung Research America (Silicon Valley)
shuahkh@osg.samsung.com | (970) 217-8978

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v3 02/22] uapi/media.h: Declare interface types for ALSA
  2016-02-17 12:21   ` Mauro Carvalho Chehab
@ 2016-02-26 19:30     ` Shuah Khan
  2016-02-26 19:38       ` Takashi Iwai
  0 siblings, 1 reply; 49+ messages in thread
From: Shuah Khan @ 2016-02-26 19:30 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, tiwai
  Cc: clemens, hans.verkuil, laurent.pinchart, sakari.ailus, javier,
	pawel, m.szyprowski, kyungmin.park, perex, arnd, dan.carpenter,
	tvboxspy, crope, ruchandani.tina, corbet, chehabrafael,
	k.kozlowski, stefanr, inki.dae, jh1009.sung, elfring,
	prabhakar.csengg, sw0312.kim, p.zabel, ricardo.ribalda, labbott,
	pierre-louis.bossart, ricard.wanderlof, julian, takamichiho,
	dominic.sacre, misterpib, daniel, gtmkramer, normalperson, joe,
	linuxbugs, johan, klock.android, nenggun.kim, j.anaszewski,
	geliangtang, albert, linux-kernel, linux-media, alsa-devel,
	Shuah Khan

On 02/17/2016 05:21 AM, Mauro Carvalho Chehab wrote:
> Em Thu, 11 Feb 2016 16:41:18 -0700
> Shuah Khan <shuahkh@osg.samsung.com> escreveu:
> 
>> Declare the interface types to be used on alsa for
>> the new G_TOPOLOGY ioctl.
>>
>> Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
>> ---
>>  drivers/media/media-entity.c | 16 ++++++++++++++++
>>  include/uapi/linux/media.h   | 10 ++++++++++
>>  2 files changed, 26 insertions(+)
>>
>> diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
>> index f2e4360..6179543 100644
>> --- a/drivers/media/media-entity.c
>> +++ b/drivers/media/media-entity.c
>> @@ -65,6 +65,22 @@ static inline const char *intf_type(struct media_interface *intf)
>>  		return "v4l2-subdev";
>>  	case MEDIA_INTF_T_V4L_SWRADIO:
>>  		return "swradio";
>> +	case MEDIA_INTF_T_ALSA_PCM_CAPTURE:
>> +		return "pcm-capture";
>> +	case MEDIA_INTF_T_ALSA_PCM_PLAYBACK:
>> +		return "pcm-playback";
>> +	case MEDIA_INTF_T_ALSA_CONTROL:
>> +		return "alsa-control";
>> +	case MEDIA_INTF_T_ALSA_COMPRESS:
>> +		return "compress";
>> +	case MEDIA_INTF_T_ALSA_RAWMIDI:
>> +		return "rawmidi";
>> +	case MEDIA_INTF_T_ALSA_HWDEP:
>> +		return "hwdep";
>> +	case MEDIA_INTF_T_ALSA_SEQUENCER:
>> +		return "sequencer";
>> +	case MEDIA_INTF_T_ALSA_TIMER:
>> +		return "timer";
>>  	default:
>>  		return "unknown-intf";
>>  	}
>> diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
>> index c9eb42a..3cc0366 100644
>> --- a/include/uapi/linux/media.h
>> +++ b/include/uapi/linux/media.h
>> @@ -265,6 +265,7 @@ struct media_links_enum {
>>  
>>  #define MEDIA_INTF_T_DVB_BASE	0x00000100
>>  #define MEDIA_INTF_T_V4L_BASE	0x00000200
>> +#define MEDIA_INTF_T_ALSA_BASE	0x00000300
>>  
>>  /* Interface types */
>>  
>> @@ -280,6 +281,15 @@ struct media_links_enum {
>>  #define MEDIA_INTF_T_V4L_SUBDEV (MEDIA_INTF_T_V4L_BASE + 3)
>>  #define MEDIA_INTF_T_V4L_SWRADIO (MEDIA_INTF_T_V4L_BASE + 4)
>>  
>> +#define MEDIA_INTF_T_ALSA_PCM_CAPTURE   (MEDIA_INTF_T_ALSA_BASE)
>> +#define MEDIA_INTF_T_ALSA_PCM_PLAYBACK  (MEDIA_INTF_T_ALSA_BASE + 1)
>> +#define MEDIA_INTF_T_ALSA_CONTROL       (MEDIA_INTF_T_ALSA_BASE + 2)
>> +#define MEDIA_INTF_T_ALSA_COMPRESS      (MEDIA_INTF_T_ALSA_BASE + 3)
>> +#define MEDIA_INTF_T_ALSA_RAWMIDI       (MEDIA_INTF_T_ALSA_BASE + 4)
>> +#define MEDIA_INTF_T_ALSA_HWDEP         (MEDIA_INTF_T_ALSA_BASE + 5)
>> +#define MEDIA_INTF_T_ALSA_SEQUENCER     (MEDIA_INTF_T_ALSA_BASE + 6)
>> +#define MEDIA_INTF_T_ALSA_TIMER         (MEDIA_INTF_T_ALSA_BASE + 7)
>> +
>>  /*
>>   * MC next gen API definitions
>>   *
> 
> Looks OK to me.
> 
> Takashi,
> 
> If this is OK for you too, would you mind acking it?
> 

Hi Takashi,

Are you okay with this patch? Could you please
Ack it.

thanks,
-- Shuah


-- 
Shuah Khan
Sr. Linux Kernel Developer
Open Source Innovation Group
Samsung Research America (Silicon Valley)
shuahkh@osg.samsung.com | (970) 217-8978

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v3 22/22] sound/usb: Use Media Controller API to share media resources
  2016-02-11 23:41 ` [PATCH v3 22/22] sound/usb: Use Media Controller API to share media resources Shuah Khan
@ 2016-02-26 19:33   ` Shuah Khan
  2016-02-26 19:55   ` Takashi Iwai
  1 sibling, 0 replies; 49+ messages in thread
From: Shuah Khan @ 2016-02-26 19:33 UTC (permalink / raw)
  To: mchehab, tiwai
  Cc: clemens, hans.verkuil, laurent.pinchart, sakari.ailus, javier,
	pawel, m.szyprowski, kyungmin.park, perex, arnd, dan.carpenter,
	tvboxspy, crope, ruchandani.tina, corbet, chehabrafael,
	k.kozlowski, stefanr, inki.dae, jh1009.sung, elfring,
	prabhakar.csengg, sw0312.kim, p.zabel, ricardo.ribalda, labbott,
	pierre-louis.bossart, ricard.wanderlof, julian, takamichiho,
	dominic.sacre, misterpib, daniel, gtmkramer, normalperson, joe,
	linuxbugs, johan, klock.android, nenggun.kim, j.anaszewski,
	geliangtang, albert, linux-kernel, linux-media, alsa-devel,
	Shuah Khan

On 02/11/2016 04:41 PM, Shuah Khan wrote:
> Change ALSA driver to use Media Controller API to
> share media resources with DVB and V4L2 drivers
> on a AU0828 media device. Media Controller specific
> initialization is done after sound card is registered.
> ALSA creates Media interface and entity function graph
> nodes for Control, Mixer, PCM Playback, and PCM Capture
> devices.
> 
> snd_usb_hw_params() will call Media Controller enable
> source handler interface to request the media resource.
> If resource request is granted, it will release it from
> snd_usb_hw_free(). If resource is busy, -EBUSY is returned.
> 
> Media specific cleanup is done in usb_audio_disconnect().
> 
> Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>

Hi Takashi,

Hope you are okay with this version. I addressed all
your comments. Could you please Ack it or let me know
if there is something I still need to address.

thanks,
-- Shuah

> ---
>  sound/usb/Kconfig        |   4 +
>  sound/usb/Makefile       |   2 +
>  sound/usb/card.c         |  14 +++
>  sound/usb/card.h         |   3 +
>  sound/usb/media.c        | 318 +++++++++++++++++++++++++++++++++++++++++++++++
>  sound/usb/media.h        |  72 +++++++++++
>  sound/usb/mixer.h        |   3 +
>  sound/usb/pcm.c          |  28 ++++-
>  sound/usb/quirks-table.h |   1 +
>  sound/usb/stream.c       |   2 +
>  sound/usb/usbaudio.h     |   6 +
>  11 files changed, 448 insertions(+), 5 deletions(-)
>  create mode 100644 sound/usb/media.c
>  create mode 100644 sound/usb/media.h
> 
> diff --git a/sound/usb/Kconfig b/sound/usb/Kconfig
> index a452ad7..ba117f5 100644
> --- a/sound/usb/Kconfig
> +++ b/sound/usb/Kconfig
> @@ -15,6 +15,7 @@ config SND_USB_AUDIO
>  	select SND_RAWMIDI
>  	select SND_PCM
>  	select BITREVERSE
> +	select SND_USB_AUDIO_USE_MEDIA_CONTROLLER if MEDIA_CONTROLLER && MEDIA_SUPPORT
>  	help
>  	  Say Y here to include support for USB audio and USB MIDI
>  	  devices.
> @@ -22,6 +23,9 @@ config SND_USB_AUDIO
>  	  To compile this driver as a module, choose M here: the module
>  	  will be called snd-usb-audio.
>  
> +config SND_USB_AUDIO_USE_MEDIA_CONTROLLER
> +	bool
> +
>  config SND_USB_UA101
>  	tristate "Edirol UA-101/UA-1000 driver"
>  	select SND_PCM
> diff --git a/sound/usb/Makefile b/sound/usb/Makefile
> index 2d2d122..8dca3c4 100644
> --- a/sound/usb/Makefile
> +++ b/sound/usb/Makefile
> @@ -15,6 +15,8 @@ snd-usb-audio-objs := 	card.o \
>  			quirks.o \
>  			stream.o
>  
> +snd-usb-audio-$(CONFIG_SND_USB_AUDIO_USE_MEDIA_CONTROLLER) += media.o
> +
>  snd-usbmidi-lib-objs := midi.o
>  
>  # Toplevel Module Dependency
> diff --git a/sound/usb/card.c b/sound/usb/card.c
> index 1f09d95..35fe256 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");
> @@ -561,6 +562,11 @@ static int usb_audio_probe(struct usb_interface *intf,
>  	if (err < 0)
>  		goto __error;
>  
> +	if (quirk->media_device) {
> +		/* don't want to fail when media_device_create() fails */
> +		media_device_create(chip, intf);
> +	}
> +
>  	usb_chip[chip->index] = chip;
>  	chip->num_interfaces++;
>  	usb_set_intfdata(intf, chip);
> @@ -617,6 +623,14 @@ static void usb_audio_disconnect(struct usb_interface *intf)
>  		list_for_each(p, &chip->midi_list) {
>  			snd_usbmidi_disconnect(p);
>  		}
> +		/*
> +		 * Nice to check quirk && quirk->media_device
> +		 * need some special handlings. Doesn't look like
> +		 * we have access to quirk here
> +		 * Acceses mixer_list
> +		*/
> +		media_device_delete(chip);
> +
>  		/* release mixer resources */
>  		list_for_each_entry(mixer, &chip->mixer_list, list) {
>  			snd_usb_mixer_disconnect(mixer);
> diff --git a/sound/usb/card.h b/sound/usb/card.h
> index 71778ca..34a0898 100644
> --- a/sound/usb/card.h
> +++ b/sound/usb/card.h
> @@ -105,6 +105,8 @@ struct snd_usb_endpoint {
>  	struct list_head list;
>  };
>  
> +struct media_ctl;
> +
>  struct snd_usb_substream {
>  	struct snd_usb_stream *stream;
>  	struct usb_device *dev;
> @@ -156,6 +158,7 @@ struct snd_usb_substream {
>  	} dsd_dop;
>  
>  	bool trigger_tstamp_pending_update; /* trigger timestamp being updated from initial estimate */
> +	struct media_ctl *media_ctl;
>  };
>  
>  struct snd_usb_stream {
> diff --git a/sound/usb/media.c b/sound/usb/media.c
> new file mode 100644
> index 0000000..cff1459
> --- /dev/null
> +++ b/sound/usb/media.c
> @@ -0,0 +1,318 @@
> +/*
> + * media.c - Media Controller specific ALSA driver code
> + *
> + * Copyright (c) 2016 Shuah Khan <shuahkh@osg.samsung.com>
> + * Copyright (c) 2016 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.
> +*/
> +
> +#include <linux/init.h>
> +#include <linux/list.h>
> +#include <linux/mutex.h>
> +#include <linux/slab.h>
> +#include <linux/usb.h>
> +
> +#include <sound/pcm.h>
> +#include <sound/core.h>
> +
> +#include "usbaudio.h"
> +#include "card.h"
> +#include "mixer.h"
> +#include "media.h"
> +
> +static int media_enable_source(struct media_ctl *mctl)
> +{
> +	if (mctl && mctl->media_dev->enable_source)
> +		return mctl->media_dev->enable_source(&mctl->media_entity,
> +						      &mctl->media_pipe);
> +	return 0;
> +}
> +
> +static void media_disable_source(struct media_ctl *mctl)
> +{
> +	if (mctl && mctl->media_dev->disable_source)
> +		mctl->media_dev->disable_source(&mctl->media_entity);
> +}
> +
> +int media_stream_init(struct snd_usb_substream *subs, struct snd_pcm *pcm,
> +			int stream)
> +{
> +	struct media_device *mdev;
> +	struct media_ctl *mctl;
> +	struct device *pcm_dev = &pcm->streams[stream].dev;
> +	u32 intf_type;
> +	int ret = 0;
> +	u16 mixer_pad;
> +	struct media_entity *entity;
> +
> +	mdev = subs->stream->chip->media_dev;
> +	if (!mdev)
> +		return -ENODEV;
> +
> +	if (subs->media_ctl)
> +		return 0;
> +
> +	/* allocate media_ctl */
> +	mctl = kzalloc(sizeof(*mctl), GFP_KERNEL);
> +	if (!mctl)
> +		return -ENOMEM;
> +
> +	mctl->media_dev = mdev;
> +	if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
> +		intf_type = MEDIA_INTF_T_ALSA_PCM_PLAYBACK;
> +		mctl->media_entity.function = MEDIA_ENT_F_AUDIO_PLAYBACK;
> +		mctl->media_pad.flags = MEDIA_PAD_FL_SOURCE;
> +		mixer_pad = 1;
> +	} else {
> +		intf_type = MEDIA_INTF_T_ALSA_PCM_CAPTURE;
> +		mctl->media_entity.function = MEDIA_ENT_F_AUDIO_CAPTURE;
> +		mctl->media_pad.flags = MEDIA_PAD_FL_SINK;
> +		mixer_pad = 2;
> +	}
> +	mctl->media_entity.name = pcm->name;
> +	media_entity_pads_init(&mctl->media_entity, 1, &mctl->media_pad);
> +	ret =  media_device_register_entity(mctl->media_dev,
> +					    &mctl->media_entity);
> +	if (ret)
> +		goto err1;
> +
> +	mctl->intf_devnode = media_devnode_create(mdev, intf_type, 0,
> +						  MAJOR(pcm_dev->devt),
> +						  MINOR(pcm_dev->devt));
> +	if (!mctl->intf_devnode) {
> +		ret = -ENOMEM;
> +		goto err2;
> +	}
> +	mctl->intf_link = media_create_intf_link(&mctl->media_entity,
> +						 &mctl->intf_devnode->intf,
> +						 MEDIA_LNK_FL_ENABLED);
> +	if (!mctl->intf_link) {
> +		ret = -ENOMEM;
> +		goto err3;
> +	}
> +
> +	/* create link between mixer and audio */
> +	media_device_for_each_entity(entity, mdev) {
> +		switch (entity->function) {
> +		case MEDIA_ENT_F_AUDIO_MIXER:
> +			ret = media_create_pad_link(entity, mixer_pad,
> +						    &mctl->media_entity, 0,
> +						    MEDIA_LNK_FL_ENABLED);
> +			if (ret)
> +				goto err4;
> +			break;
> +		}
> +	}
> +
> +	subs->media_ctl = mctl;
> +	return 0;
> +
> +err4:
> +	media_remove_intf_link(mctl->intf_link);
> +err3:
> +	media_devnode_remove(mctl->intf_devnode);
> +err2:
> +	media_device_unregister_entity(&mctl->media_entity);
> +err1:
> +	kfree(mctl);
> +	return ret;
> +}
> +
> +void media_stream_delete(struct snd_usb_substream *subs)
> +{
> +	struct media_ctl *mctl = subs->media_ctl;
> +
> +	if (mctl && mctl->media_dev) {
> +		struct media_device *mdev;
> +
> +		mdev = subs->stream->chip->media_dev;
> +		if (mdev && media_devnode_is_registered(&mdev->devnode)) {
> +			media_devnode_remove(mctl->intf_devnode);
> +			media_device_unregister_entity(&mctl->media_entity);
> +			media_entity_cleanup(&mctl->media_entity);
> +		}
> +		kfree(mctl);
> +		subs->media_ctl = NULL;
> +	}
> +}
> +
> +int media_start_pipeline(struct snd_usb_substream *subs)
> +{
> +	struct media_ctl *mctl = subs->media_ctl;
> +
> +	if (mctl)
> +		return media_enable_source(mctl);
> +	return 0;
> +}
> +
> +void media_stop_pipeline(struct snd_usb_substream *subs)
> +{
> +	struct media_ctl *mctl = subs->media_ctl;
> +
> +	if (mctl)
> +		media_disable_source(mctl);
> +}
> +
> +int media_mixer_init(struct snd_usb_audio *chip)
> +{
> +	struct device *ctl_dev = &chip->card->ctl_dev;
> +	struct media_intf_devnode *ctl_intf;
> +	struct usb_mixer_interface *mixer;
> +	struct media_device *mdev = chip->media_dev;
> +	struct media_mixer_ctl *mctl;
> +	u32 intf_type = MEDIA_INTF_T_ALSA_CONTROL;
> +	int ret;
> +
> +	if (!mdev)
> +		return -ENODEV;
> +
> +	ctl_intf = chip->ctl_intf_media_devnode;
> +	if (!ctl_intf) {
> +		ctl_intf = media_devnode_create(mdev, intf_type, 0,
> +						MAJOR(ctl_dev->devt),
> +						MINOR(ctl_dev->devt));
> +		if (!ctl_intf)
> +			return -ENOMEM;
> +		chip->ctl_intf_media_devnode = ctl_intf;
> +	}
> +
> +	list_for_each_entry(mixer, &chip->mixer_list, list) {
> +
> +		if (mixer->media_mixer_ctl)
> +			continue;
> +
> +		/* allocate media_mixer_ctl */
> +		mctl = kzalloc(sizeof(*mctl), GFP_KERNEL);
> +		if (!mctl)
> +			return -ENOMEM;
> +
> +		mctl->media_dev = mdev;
> +		mctl->media_entity.function = MEDIA_ENT_F_AUDIO_MIXER;
> +		mctl->media_entity.name = chip->card->mixername;
> +		mctl->media_pad[0].flags = MEDIA_PAD_FL_SINK;
> +		mctl->media_pad[1].flags = MEDIA_PAD_FL_SOURCE;
> +		mctl->media_pad[2].flags = MEDIA_PAD_FL_SOURCE;
> +		media_entity_pads_init(&mctl->media_entity, MEDIA_MIXER_PAD_MAX,
> +				  mctl->media_pad);
> +		ret =  media_device_register_entity(mctl->media_dev,
> +						    &mctl->media_entity);
> +		if (ret) {
> +			kfree(mctl);
> +			return ret;
> +		}
> +
> +		mctl->intf_link = media_create_intf_link(&mctl->media_entity,
> +							 &ctl_intf->intf,
> +							 MEDIA_LNK_FL_ENABLED);
> +		if (!mctl->intf_link) {
> +			media_device_unregister_entity(&mctl->media_entity);
> +			media_entity_cleanup(&mctl->media_entity);
> +			kfree(mctl);
> +			return -ENOMEM;
> +		}
> +		mctl->intf_devnode = ctl_intf;
> +		mixer->media_mixer_ctl = mctl;
> +	}
> +	return 0;
> +}
> +
> +static void media_mixer_delete(struct snd_usb_audio *chip)
> +{
> +	struct usb_mixer_interface *mixer;
> +	struct media_device *mdev = chip->media_dev;
> +
> +	if (!mdev)
> +		return;
> +
> +	list_for_each_entry(mixer, &chip->mixer_list, list) {
> +		struct media_mixer_ctl *mctl;
> +
> +		mctl = mixer->media_mixer_ctl;
> +		if (!mixer->media_mixer_ctl)
> +			continue;
> +
> +		if (media_devnode_is_registered(&mdev->devnode)) {
> +			media_device_unregister_entity(&mctl->media_entity);
> +			media_entity_cleanup(&mctl->media_entity);
> +		}
> +		kfree(mctl);
> +		mixer->media_mixer_ctl = NULL;
> +	}
> +	if (media_devnode_is_registered(&mdev->devnode))
> +		media_devnode_remove(chip->ctl_intf_media_devnode);
> +	chip->ctl_intf_media_devnode = NULL;
> +}
> +
> +int media_device_create(struct snd_usb_audio *chip,
> +			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 (!mdev->dev) {
> +		/* 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);
> +		media_device_init(mdev);
> +	}
> +	if (!media_devnode_is_registered(&mdev->devnode)) {
> +		ret = media_device_register(mdev);
> +		if (ret) {
> +			dev_err(&usbdev->dev,
> +				"Couldn't register media device. Error: %d\n",
> +				ret);
> +			return ret;
> +		}
> +	}
> +
> +	/* save media device - avoid lookups */
> +	chip->media_dev = mdev;
> +
> +	/* Create media entities for mixer and control dev */
> +	ret = media_mixer_init(chip);
> +	if (ret) {
> +		dev_err(&usbdev->dev,
> +			"Couldn't create media mixer entities. Error: %d\n",
> +			ret);
> +
> +		/* clear saved media_dev */
> +		chip->media_dev = NULL;
> +
> +		return ret;
> +	}
> +	return 0;
> +}
> +
> +void media_device_delete(struct snd_usb_audio *chip)
> +{
> +	struct media_device *mdev = chip->media_dev;
> +
> +	media_mixer_delete(chip);
> +
> +	if (mdev) {
> +		if (media_devnode_is_registered(&mdev->devnode))
> +			media_device_unregister(mdev);
> +		chip->media_dev = NULL;
> +	}
> +}
> diff --git a/sound/usb/media.h b/sound/usb/media.h
> new file mode 100644
> index 0000000..f66b4d7
> --- /dev/null
> +++ b/sound/usb/media.h
> @@ -0,0 +1,72 @@
> +/*
> + * media.h - Media Controller specific ALSA driver code
> + *
> + * Copyright (c) 2016 Shuah Khan <shuahkh@osg.samsung.com>
> + * Copyright (c) 2016 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 CONFIG_SND_USB_AUDIO_USE_MEDIA_CONTROLLER
> +
> +#include <media/media-device.h>
> +#include <media/media-entity.h>
> +#include <sound/asound.h>
> +
> +struct media_ctl {
> +	struct media_device *media_dev;
> +	struct media_entity media_entity;
> +	struct media_intf_devnode *intf_devnode;
> +	struct media_link *intf_link;
> +	struct media_pad media_pad;
> +	struct media_pipeline media_pipe;
> +};
> +
> +/*
> + * One source pad each for SNDRV_PCM_STREAM_CAPTURE and
> + * SNDRV_PCM_STREAM_PLAYBACK. One for sink pad to link
> + * to AUDIO Source
> +*/
> +#define MEDIA_MIXER_PAD_MAX    (SNDRV_PCM_STREAM_LAST + 2)
> +
> +struct media_mixer_ctl {
> +	struct media_device *media_dev;
> +	struct media_entity media_entity;
> +	struct media_intf_devnode *intf_devnode;
> +	struct media_link *intf_link;
> +	struct media_pad media_pad[MEDIA_MIXER_PAD_MAX];
> +	struct media_pipeline media_pipe;
> +};
> +
> +int media_device_create(struct snd_usb_audio *chip,
> +			struct usb_interface *iface);
> +void media_device_delete(struct snd_usb_audio *chip);
> +int media_stream_init(struct snd_usb_substream *subs, struct snd_pcm *pcm,
> +			int stream);
> +void media_stream_delete(struct snd_usb_substream *subs);
> +int media_start_pipeline(struct snd_usb_substream *subs);
> +void media_stop_pipeline(struct snd_usb_substream *subs);
> +#else
> +static inline int media_device_create(struct snd_usb_audio *chip,
> +				      struct usb_interface *iface)
> +						{ return 0; }
> +static inline void media_device_delete(struct snd_usb_audio *chip) { }
> +static inline int media_stream_init(struct snd_usb_substream *subs,
> +					struct snd_pcm *pcm, int stream)
> +						{ return 0; }
> +static inline void media_stream_delete(struct snd_usb_substream *subs) { }
> +static inline int media_start_pipeline(struct snd_usb_substream *subs)
> +					{ return 0; }
> +static inline void media_stop_pipeline(struct snd_usb_substream *subs) { }
> +#endif
> +#endif /* __MEDIA_H */
> diff --git a/sound/usb/mixer.h b/sound/usb/mixer.h
> index 3417ef3..f378944 100644
> --- a/sound/usb/mixer.h
> +++ b/sound/usb/mixer.h
> @@ -3,6 +3,8 @@
>  
>  #include <sound/info.h>
>  
> +struct media_mixer_ctl;
> +
>  struct usb_mixer_interface {
>  	struct snd_usb_audio *chip;
>  	struct usb_host_interface *hostif;
> @@ -22,6 +24,7 @@ struct usb_mixer_interface {
>  	struct urb *rc_urb;
>  	struct usb_ctrlrequest *rc_setup_packet;
>  	u8 rc_buffer[6];
> +	struct media_mixer_ctl *media_mixer_ctl;
>  };
>  
>  #define MAX_CHANNELS	16	/* max logical channels */
> diff --git a/sound/usb/pcm.c b/sound/usb/pcm.c
> index 9245f52..c3b8486 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
> @@ -715,10 +716,14 @@ static int snd_usb_hw_params(struct snd_pcm_substream *substream,
>  	struct audioformat *fmt;
>  	int ret;
>  
> +	ret = media_start_pipeline(subs);
> +	if (ret)
> +		return ret;
> +
>  	ret = snd_pcm_lib_alloc_vmalloc_buffer(substream,
>  					       params_buffer_bytes(hw_params));
>  	if (ret < 0)
> -		return ret;
> +		goto err_ret;
>  
>  	subs->pcm_format = params_format(hw_params);
>  	subs->period_bytes = params_period_bytes(hw_params);
> @@ -732,22 +737,27 @@ static int snd_usb_hw_params(struct snd_pcm_substream *substream,
>  		dev_dbg(&subs->dev->dev,
>  			"cannot set format: format = %#x, rate = %d, channels = %d\n",
>  			   subs->pcm_format, subs->cur_rate, subs->channels);
> -		return -EINVAL;
> +		ret = -EINVAL;
> +		goto err_ret;
>  	}
>  
>  	ret = snd_usb_lock_shutdown(subs->stream->chip);
>  	if (ret < 0)
> -		return ret;
> +		goto err_ret;
>  	ret = set_format(subs, fmt);
>  	snd_usb_unlock_shutdown(subs->stream->chip);
>  	if (ret < 0)
> -		return ret;
> +		goto err_ret;
>  
>  	subs->interface = fmt->iface;
>  	subs->altset_idx = fmt->altset_idx;
>  	subs->need_setup_ep = true;
>  
>  	return 0;
> +
> +err_ret:
> +	media_stop_pipeline(subs);
> +	return ret;
>  }
>  
>  /*
> @@ -759,6 +769,7 @@ static int snd_usb_hw_free(struct snd_pcm_substream *substream)
>  {
>  	struct snd_usb_substream *subs = substream->runtime->private_data;
>  
> +	media_stop_pipeline(subs);
>  	subs->cur_audiofmt = NULL;
>  	subs->cur_rate = 0;
>  	subs->period_bytes = 0;
> @@ -1219,6 +1230,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;
> @@ -1232,7 +1244,12 @@ 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)
> +		ret = media_stream_init(subs, as->pcm, direction);
> +	if (ret)
> +		snd_usb_autosuspend(subs->stream->chip);
> +	return ret;
>  }
>  
>  static int snd_usb_pcm_close(struct snd_pcm_substream *substream, int direction)
> @@ -1241,6 +1258,7 @@ static int snd_usb_pcm_close(struct snd_pcm_substream *substream, int direction)
>  	struct snd_usb_substream *subs = &as->substream[direction];
>  
>  	stop_endpoints(subs, true);
> +	media_stop_pipeline(subs);
>  
>  	if (subs->interface >= 0 &&
>  	    !snd_usb_lock_shutdown(subs->stream->chip)) {
> diff --git a/sound/usb/quirks-table.h b/sound/usb/quirks-table.h
> index c60a776..9d087b1 100644
> --- a/sound/usb/quirks-table.h
> +++ b/sound/usb/quirks-table.h
> @@ -2886,6 +2886,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/stream.c b/sound/usb/stream.c
> index c4dc577..6c7f5c1 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);
>  }
>  
>  
> diff --git a/sound/usb/usbaudio.h b/sound/usb/usbaudio.h
> index b665d85..a161c7c 100644
> --- a/sound/usb/usbaudio.h
> +++ b/sound/usb/usbaudio.h
> @@ -30,6 +30,9 @@
>   *
>   */
>  
> +struct media_device;
> +struct media_intf_devnode;
> +
>  struct snd_usb_audio {
>  	int index;
>  	struct usb_device *dev;
> @@ -60,6 +63,8 @@ struct snd_usb_audio {
>  	bool autoclock;			/* from the 'autoclock' module param */
>  
>  	struct usb_host_interface *ctrl_intf;	/* the audio control interface */
> +	struct media_device *media_dev;
> +	struct media_intf_devnode *ctl_intf_media_devnode;
>  };
>  
>  #define usb_audio_err(chip, fmt, args...) \
> @@ -110,6 +115,7 @@ struct snd_usb_audio_quirk {
>  	const char *product_name;
>  	int16_t ifnum;
>  	uint16_t type;
> +	bool media_device;
>  	const void *data;
>  };
>  
> 


-- 
Shuah Khan
Sr. Linux Kernel Developer
Open Source Innovation Group
Samsung Research America (Silicon Valley)
shuahkh@osg.samsung.com | (970) 217-8978

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v3 02/22] uapi/media.h: Declare interface types for ALSA
  2016-02-26 19:30     ` Shuah Khan
@ 2016-02-26 19:38       ` Takashi Iwai
  0 siblings, 0 replies; 49+ messages in thread
From: Takashi Iwai @ 2016-02-26 19:38 UTC (permalink / raw)
  To: Shuah Khan
  Cc: Mauro Carvalho Chehab, geliangtang, alsa-devel, arnd,
	ricard.wanderlof, hans.verkuil, labbott, chehabrafael,
	klock.android, misterpib, prabhakar.csengg, ricardo.ribalda,
	ruchandani.tina, takamichiho, tvboxspy, dominic.sacre, albert,
	laurent.pinchart, crope, julian, clemens, pierre-louis.bossart,
	sakari.ailus, corbet, joe, johan, dan.carpenter, pawel, javier,
	p.zabel, perex, stefanr, inki.dae, j.anaszewski, jh1009.sung,
	k.kozlowski, kyungmin.park, m.szyprowski, nenggun.kim,
	sw0312.kim, elfring, linux-kernel, linux-media, linuxbugs,
	gtmkramer, normalperson, daniel

On Fri, 26 Feb 2016 20:30:03 +0100,
Shuah Khan wrote:
> 
> On 02/17/2016 05:21 AM, Mauro Carvalho Chehab wrote:
> > Em Thu, 11 Feb 2016 16:41:18 -0700
> > Shuah Khan <shuahkh@osg.samsung.com> escreveu:
> > 
> >> Declare the interface types to be used on alsa for
> >> the new G_TOPOLOGY ioctl.
> >>
> >> Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
> >> ---
> >>  drivers/media/media-entity.c | 16 ++++++++++++++++
> >>  include/uapi/linux/media.h   | 10 ++++++++++
> >>  2 files changed, 26 insertions(+)
> >>
> >> diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
> >> index f2e4360..6179543 100644
> >> --- a/drivers/media/media-entity.c
> >> +++ b/drivers/media/media-entity.c
> >> @@ -65,6 +65,22 @@ static inline const char *intf_type(struct media_interface *intf)
> >>  		return "v4l2-subdev";
> >>  	case MEDIA_INTF_T_V4L_SWRADIO:
> >>  		return "swradio";
> >> +	case MEDIA_INTF_T_ALSA_PCM_CAPTURE:
> >> +		return "pcm-capture";
> >> +	case MEDIA_INTF_T_ALSA_PCM_PLAYBACK:
> >> +		return "pcm-playback";
> >> +	case MEDIA_INTF_T_ALSA_CONTROL:
> >> +		return "alsa-control";
> >> +	case MEDIA_INTF_T_ALSA_COMPRESS:
> >> +		return "compress";
> >> +	case MEDIA_INTF_T_ALSA_RAWMIDI:
> >> +		return "rawmidi";
> >> +	case MEDIA_INTF_T_ALSA_HWDEP:
> >> +		return "hwdep";
> >> +	case MEDIA_INTF_T_ALSA_SEQUENCER:
> >> +		return "sequencer";
> >> +	case MEDIA_INTF_T_ALSA_TIMER:
> >> +		return "timer";
> >>  	default:
> >>  		return "unknown-intf";
> >>  	}
> >> diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
> >> index c9eb42a..3cc0366 100644
> >> --- a/include/uapi/linux/media.h
> >> +++ b/include/uapi/linux/media.h
> >> @@ -265,6 +265,7 @@ struct media_links_enum {
> >>  
> >>  #define MEDIA_INTF_T_DVB_BASE	0x00000100
> >>  #define MEDIA_INTF_T_V4L_BASE	0x00000200
> >> +#define MEDIA_INTF_T_ALSA_BASE	0x00000300
> >>  
> >>  /* Interface types */
> >>  
> >> @@ -280,6 +281,15 @@ struct media_links_enum {
> >>  #define MEDIA_INTF_T_V4L_SUBDEV (MEDIA_INTF_T_V4L_BASE + 3)
> >>  #define MEDIA_INTF_T_V4L_SWRADIO (MEDIA_INTF_T_V4L_BASE + 4)
> >>  
> >> +#define MEDIA_INTF_T_ALSA_PCM_CAPTURE   (MEDIA_INTF_T_ALSA_BASE)
> >> +#define MEDIA_INTF_T_ALSA_PCM_PLAYBACK  (MEDIA_INTF_T_ALSA_BASE + 1)
> >> +#define MEDIA_INTF_T_ALSA_CONTROL       (MEDIA_INTF_T_ALSA_BASE + 2)
> >> +#define MEDIA_INTF_T_ALSA_COMPRESS      (MEDIA_INTF_T_ALSA_BASE + 3)
> >> +#define MEDIA_INTF_T_ALSA_RAWMIDI       (MEDIA_INTF_T_ALSA_BASE + 4)
> >> +#define MEDIA_INTF_T_ALSA_HWDEP         (MEDIA_INTF_T_ALSA_BASE + 5)
> >> +#define MEDIA_INTF_T_ALSA_SEQUENCER     (MEDIA_INTF_T_ALSA_BASE + 6)
> >> +#define MEDIA_INTF_T_ALSA_TIMER         (MEDIA_INTF_T_ALSA_BASE + 7)
> >> +
> >>  /*
> >>   * MC next gen API definitions
> >>   *
> > 
> > Looks OK to me.
> > 
> > Takashi,
> > 
> > If this is OK for you too, would you mind acking it?
> > 
> 
> Hi Takashi,
> 
> Are you okay with this patch? Could you please
> Ack it.

Sorry for the late response.
Yes, this definition looks OK to me.

Acked-by: Takashi Iwai <tiwai@suse.de>


thanks,

Takashi

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v3 03/22] [media] Docbook: media-types.xml: Add Audio Function Entities
  2016-02-17 12:23   ` Mauro Carvalho Chehab
@ 2016-02-26 19:40     ` Takashi Iwai
  0 siblings, 0 replies; 49+ messages in thread
From: Takashi Iwai @ 2016-02-26 19:40 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Shuah Khan, geliangtang, alsa-devel, arnd, ricard.wanderlof,
	hans.verkuil, labbott, chehabrafael, klock.android, misterpib,
	prabhakar.csengg, ricardo.ribalda, ruchandani.tina, takamichiho,
	tvboxspy, dominic.sacre, albert, laurent.pinchart, crope, julian,
	clemens, pierre-louis.bossart, sakari.ailus, corbet, joe, johan,
	dan.carpenter, pawel, javier, p.zabel, perex, stefanr, inki.dae,
	j.anaszewski, jh1009.sung, k.kozlowski, kyungmin.park,
	m.szyprowski, nenggun.kim, sw0312.kim, elfring, linux-kernel,
	linux-media, linuxbugs, gtmkramer, normalperson, daniel

On Wed, 17 Feb 2016 13:23:09 +0100,
Mauro Carvalho Chehab wrote:
> 
> Em Thu, 11 Feb 2016 16:41:19 -0700
> Shuah Khan <shuahkh@osg.samsung.com> escreveu:
> 
> > Add Audio Function Entities
> > 
> > Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
> > ---
> >  Documentation/DocBook/media/v4l/media-types.xml | 12 ++++++++++++
> >  1 file changed, 12 insertions(+)
> > 
> > diff --git a/Documentation/DocBook/media/v4l/media-types.xml b/Documentation/DocBook/media/v4l/media-types.xml
> > index 3730967..924a604 100644
> > --- a/Documentation/DocBook/media/v4l/media-types.xml
> > +++ b/Documentation/DocBook/media/v4l/media-types.xml
> > @@ -113,6 +113,18 @@
> >  		   decoder.
> >  	    </entry>
> >  	  </row>
> > +	  <row>
> > +	    <entry><constant>MEDIA_ENT_F_AUDIO_CAPTURE</constant></entry>
> > +	    <entry>Audio Capture Function Entity.</entry>
> > +	  </row>
> > +	  <row>
> > +	    <entry><constant>MEDIA_ENT_F_AUDIO_PLAYBACK</constant></entry>
> > +	    <entry>Audio Playback Function Entity.</entry>
> > +	  </row>
> > +	  <row>
> > +	    <entry><constant>MEDIA_ENT_F_AUDIO_MIXER</constant></entry>
> > +	    <entry>Audio Mixer Function Entity.</entry>
> > +	  </row>
> >  	</tbody>
> >        </tgroup>
> >      </table>
> 
> Looks OK to me.
> 
> Takashi,
> 
> Could you ack if ok for you?

Yeah, nothing looks wrong, as it's pretty straightforward :)

Acked-by: Takashi Iwai <tiwai@suse.de>


thanks,

Takashi

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v3 04/22] media: Add ALSA Media Controller function entities
  2016-02-17 12:25   ` Mauro Carvalho Chehab
@ 2016-02-26 19:40     ` Takashi Iwai
  0 siblings, 0 replies; 49+ messages in thread
From: Takashi Iwai @ 2016-02-26 19:40 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Shuah Khan, geliangtang, alsa-devel, arnd, ricard.wanderlof,
	hans.verkuil, labbott, chehabrafael, klock.android, misterpib,
	prabhakar.csengg, ricardo.ribalda, ruchandani.tina, takamichiho,
	tvboxspy, dominic.sacre, albert, laurent.pinchart, crope, julian,
	clemens, pierre-louis.bossart, sakari.ailus, corbet, joe, johan,
	dan.carpenter, pawel, javier, p.zabel, perex, stefanr, inki.dae,
	j.anaszewski, jh1009.sung, k.kozlowski, kyungmin.park,
	m.szyprowski, nenggun.kim, sw0312.kim, elfring, linux-kernel,
	linux-media, linuxbugs, gtmkramer, normalperson, daniel

On Wed, 17 Feb 2016 13:25:05 +0100,
Mauro Carvalho Chehab wrote:
> 
> Em Thu, 11 Feb 2016 16:41:20 -0700
> Shuah Khan <shuahkh@osg.samsung.com> escreveu:
> 
> > Add ALSA Media Controller capture, playback, and mixer
> > function entity defines.
> > 
> > Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
> > ---
> >  include/uapi/linux/media.h | 7 +++++++
> >  1 file changed, 7 insertions(+)
> > 
> > diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
> > index 3cc0366..449462e 100644
> > --- a/include/uapi/linux/media.h
> > +++ b/include/uapi/linux/media.h
> > @@ -98,6 +98,13 @@ struct media_device_info {
> >  #define MEDIA_ENT_F_IF_AUD_DECODER	(MEDIA_ENT_F_BASE + 42)
> >  
> >  /*
> > + * Audio Entity Functions
> > + */
> > +#define MEDIA_ENT_F_AUDIO_CAPTURE	(MEDIA_ENT_F_BASE + 200)
> > +#define MEDIA_ENT_F_AUDIO_PLAYBACK	(MEDIA_ENT_F_BASE + 201)
> > +#define MEDIA_ENT_F_AUDIO_MIXER		(MEDIA_ENT_F_BASE + 202)
> > +
> > +/*
> >   * Don't touch on those. The ranges MEDIA_ENT_F_OLD_BASE and
> >   * MEDIA_ENT_F_OLD_SUBDEV_BASE are kept to keep backward compatibility
> >   * with the legacy v1 API.The number range is out of range by purpose:
> 
> Looks OK to me. 
> 
> This won't apply anymore on master, because we changed the numberspace, 
> but it is a trivial conflict. No need to rebase.
> 
> Takashi,
> 
> If OK for you, please ack.

Acked-by: Takashi Iwai <tiwai@suse.de>


Takashi

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v3 22/22] sound/usb: Use Media Controller API to share media resources
  2016-02-11 23:41 ` [PATCH v3 22/22] sound/usb: Use Media Controller API to share media resources Shuah Khan
  2016-02-26 19:33   ` Shuah Khan
@ 2016-02-26 19:55   ` Takashi Iwai
  2016-02-26 20:08     ` Shuah Khan
  1 sibling, 1 reply; 49+ messages in thread
From: Takashi Iwai @ 2016-02-26 19:55 UTC (permalink / raw)
  To: Shuah Khan
  Cc: hans.verkuil, laurent.pinchart, clemens, sakari.ailus, javier,
	mchehab, geliangtang, alsa-devel, arnd, ricard.wanderlof,
	labbott, chehabrafael, klock.android, misterpib,
	prabhakar.csengg, ricardo.ribalda, ruchandani.tina, takamichiho,
	tvboxspy, dominic.sacre, albert, crope, julian,
	pierre-louis.bossart, corbet, joe, johan, dan.carpenter, pawel,
	p.zabel, perex, stefanr, inki.dae, j.anaszewski, jh1009.sung,
	k.kozlowski, kyungmin.park, m.szyprowski, nenggun.kim,
	sw0312.kim, elfring, linux-kernel, linux-media, linuxbugs,
	gtmkramer, normalperson, daniel

On Fri, 12 Feb 2016 00:41:38 +0100,
Shuah Khan wrote:
> 
> Change ALSA driver to use Media Controller API to
> share media resources with DVB and V4L2 drivers
> on a AU0828 media device. Media Controller specific
> initialization is done after sound card is registered.
> ALSA creates Media interface and entity function graph
> nodes for Control, Mixer, PCM Playback, and PCM Capture
> devices.
> 
> snd_usb_hw_params() will call Media Controller enable
> source handler interface to request the media resource.
> If resource request is granted, it will release it from
> snd_usb_hw_free(). If resource is busy, -EBUSY is returned.
> 
> Media specific cleanup is done in usb_audio_disconnect().
> 
> Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
> ---
>  sound/usb/Kconfig        |   4 +
>  sound/usb/Makefile       |   2 +
>  sound/usb/card.c         |  14 +++
>  sound/usb/card.h         |   3 +
>  sound/usb/media.c        | 318 +++++++++++++++++++++++++++++++++++++++++++++++
>  sound/usb/media.h        |  72 +++++++++++
>  sound/usb/mixer.h        |   3 +
>  sound/usb/pcm.c          |  28 ++++-
>  sound/usb/quirks-table.h |   1 +
>  sound/usb/stream.c       |   2 +
>  sound/usb/usbaudio.h     |   6 +
>  11 files changed, 448 insertions(+), 5 deletions(-)
>  create mode 100644 sound/usb/media.c
>  create mode 100644 sound/usb/media.h
> 
> diff --git a/sound/usb/Kconfig b/sound/usb/Kconfig
> index a452ad7..ba117f5 100644
> --- a/sound/usb/Kconfig
> +++ b/sound/usb/Kconfig
> @@ -15,6 +15,7 @@ config SND_USB_AUDIO
>  	select SND_RAWMIDI
>  	select SND_PCM
>  	select BITREVERSE
> +	select SND_USB_AUDIO_USE_MEDIA_CONTROLLER if MEDIA_CONTROLLER && MEDIA_SUPPORT

Looking at the media Kconfig again, this would be broken if
MEDIA_SUPPORT=m and SND_USB_AUDIO=y.  The ugly workaround is something
like:
	select SND_USB_AUDIO_USE_MEDIA_CONTROLLER \
		if MEDIA_CONTROLLER && (MEDIA_SUPPORT=y || MEDIA_SUPPORT=SND)

Other than that, it looks more or less OK to me.
The way how media_stream_init() gets called is a bit worrisome, but it
should work practically.  Another concern is about the disconnection.
Can all function calls in media_device_delete() be safe even if it's
called while the application still opens the MC device?

In anyway, such a thing can be improved later once after we get this
merged, too.  So, feel fee to take my ack.

 Acked-by: Takashi Iwai <tiwai@suse.de>


thanks,

Takashi

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v3 22/22] sound/usb: Use Media Controller API to share media resources
  2016-02-26 19:55   ` Takashi Iwai
@ 2016-02-26 20:08     ` Shuah Khan
  2016-02-26 20:50       ` Takashi Iwai
  0 siblings, 1 reply; 49+ messages in thread
From: Shuah Khan @ 2016-02-26 20:08 UTC (permalink / raw)
  To: Takashi Iwai
  Cc: hans.verkuil, laurent.pinchart, clemens, sakari.ailus, javier,
	mchehab, geliangtang, alsa-devel, arnd, ricard.wanderlof,
	labbott, chehabrafael, klock.android, misterpib,
	prabhakar.csengg, ricardo.ribalda, ruchandani.tina, takamichiho,
	tvboxspy, dominic.sacre, albert, crope, julian,
	pierre-louis.bossart, corbet, joe, johan, dan.carpenter, pawel,
	p.zabel, perex, stefanr, inki.dae, j.anaszewski, jh1009.sung,
	k.kozlowski, kyungmin.park, m.szyprowski, nenggun.kim,
	sw0312.kim, elfring, linux-kernel, linux-media, linuxbugs,
	gtmkramer, normalperson, daniel

On 02/26/2016 12:55 PM, Takashi Iwai wrote:
> On Fri, 12 Feb 2016 00:41:38 +0100,
> Shuah Khan wrote:
>>
>> Change ALSA driver to use Media Controller API to
>> share media resources with DVB and V4L2 drivers
>> on a AU0828 media device. Media Controller specific
>> initialization is done after sound card is registered.
>> ALSA creates Media interface and entity function graph
>> nodes for Control, Mixer, PCM Playback, and PCM Capture
>> devices.
>>
>> snd_usb_hw_params() will call Media Controller enable
>> source handler interface to request the media resource.
>> If resource request is granted, it will release it from
>> snd_usb_hw_free(). If resource is busy, -EBUSY is returned.
>>
>> Media specific cleanup is done in usb_audio_disconnect().
>>
>> Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
>> ---
>>  sound/usb/Kconfig        |   4 +
>>  sound/usb/Makefile       |   2 +
>>  sound/usb/card.c         |  14 +++
>>  sound/usb/card.h         |   3 +
>>  sound/usb/media.c        | 318 +++++++++++++++++++++++++++++++++++++++++++++++
>>  sound/usb/media.h        |  72 +++++++++++
>>  sound/usb/mixer.h        |   3 +
>>  sound/usb/pcm.c          |  28 ++++-
>>  sound/usb/quirks-table.h |   1 +
>>  sound/usb/stream.c       |   2 +
>>  sound/usb/usbaudio.h     |   6 +
>>  11 files changed, 448 insertions(+), 5 deletions(-)
>>  create mode 100644 sound/usb/media.c
>>  create mode 100644 sound/usb/media.h
>>
>> diff --git a/sound/usb/Kconfig b/sound/usb/Kconfig
>> index a452ad7..ba117f5 100644
>> --- a/sound/usb/Kconfig
>> +++ b/sound/usb/Kconfig
>> @@ -15,6 +15,7 @@ config SND_USB_AUDIO
>>  	select SND_RAWMIDI
>>  	select SND_PCM
>>  	select BITREVERSE
>> +	select SND_USB_AUDIO_USE_MEDIA_CONTROLLER if MEDIA_CONTROLLER && MEDIA_SUPPORT
> 
> Looking at the media Kconfig again, this would be broken if
> MEDIA_SUPPORT=m and SND_USB_AUDIO=y.  The ugly workaround is something
> like:
> 	select SND_USB_AUDIO_USE_MEDIA_CONTROLLER \
> 		if MEDIA_CONTROLLER && (MEDIA_SUPPORT=y || MEDIA_SUPPORT=SND)

My current config is MEDIA_SUPPORT=m and SND_USB_AUDIO=y
It is working and I didn't see any issues so far. Maybe
the current change is good. I am hoping kbuild-bot can
find issues (if any) once it gets merged.

> 
> Other than that, it looks more or less OK to me.
> The way how media_stream_init() gets called is a bit worrisome, but it
> should work practically.  Another concern is about the disconnection.
> Can all function calls in media_device_delete() be safe even if it's
> called while the application still opens the MC device?

Right. I have been looking into device removal path when
ioctls are active and I can resolve any issues that might
surface while an audio app is active when device is removed.

> 
> In anyway, such a thing can be improved later once after we get this
> merged, too.  So, feel fee to take my ack.
> 
>  Acked-by: Takashi Iwai <tiwai@suse.de>

thanks for the Ack
-- Shuah

> 
> 
> thanks,
> 
> Takashi
> 


-- 
Shuah Khan
Sr. Linux Kernel Developer
Open Source Innovation Group
Samsung Research America (Silicon Valley)
shuahkh@osg.samsung.com | (970) 217-8978

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v3 22/22] sound/usb: Use Media Controller API to share media resources
  2016-02-26 20:08     ` Shuah Khan
@ 2016-02-26 20:50       ` Takashi Iwai
  2016-02-27  2:55         ` Shuah Khan
  0 siblings, 1 reply; 49+ messages in thread
From: Takashi Iwai @ 2016-02-26 20:50 UTC (permalink / raw)
  To: Shuah Khan
  Cc: hans.verkuil, laurent.pinchart, clemens, sakari.ailus, javier,
	mchehab, geliangtang, alsa-devel, arnd, ricard.wanderlof,
	labbott, chehabrafael, klock.android, misterpib,
	prabhakar.csengg, ricardo.ribalda, ruchandani.tina, takamichiho,
	tvboxspy, dominic.sacre, albert, crope, julian,
	pierre-louis.bossart, corbet, joe, johan, dan.carpenter, pawel,
	p.zabel, perex, stefanr, inki.dae, j.anaszewski, jh1009.sung,
	k.kozlowski, kyungmin.park, m.szyprowski, nenggun.kim,
	sw0312.kim, elfring, linux-kernel, linux-media, linuxbugs,
	gtmkramer, normalperson, daniel

On Fri, 26 Feb 2016 21:08:43 +0100,
Shuah Khan wrote:
> 
> On 02/26/2016 12:55 PM, Takashi Iwai wrote:
> > On Fri, 12 Feb 2016 00:41:38 +0100,
> > Shuah Khan wrote:
> >>
> >> Change ALSA driver to use Media Controller API to
> >> share media resources with DVB and V4L2 drivers
> >> on a AU0828 media device. Media Controller specific
> >> initialization is done after sound card is registered.
> >> ALSA creates Media interface and entity function graph
> >> nodes for Control, Mixer, PCM Playback, and PCM Capture
> >> devices.
> >>
> >> snd_usb_hw_params() will call Media Controller enable
> >> source handler interface to request the media resource.
> >> If resource request is granted, it will release it from
> >> snd_usb_hw_free(). If resource is busy, -EBUSY is returned.
> >>
> >> Media specific cleanup is done in usb_audio_disconnect().
> >>
> >> Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
> >> ---
> >>  sound/usb/Kconfig        |   4 +
> >>  sound/usb/Makefile       |   2 +
> >>  sound/usb/card.c         |  14 +++
> >>  sound/usb/card.h         |   3 +
> >>  sound/usb/media.c        | 318 +++++++++++++++++++++++++++++++++++++++++++++++
> >>  sound/usb/media.h        |  72 +++++++++++
> >>  sound/usb/mixer.h        |   3 +
> >>  sound/usb/pcm.c          |  28 ++++-
> >>  sound/usb/quirks-table.h |   1 +
> >>  sound/usb/stream.c       |   2 +
> >>  sound/usb/usbaudio.h     |   6 +
> >>  11 files changed, 448 insertions(+), 5 deletions(-)
> >>  create mode 100644 sound/usb/media.c
> >>  create mode 100644 sound/usb/media.h
> >>
> >> diff --git a/sound/usb/Kconfig b/sound/usb/Kconfig
> >> index a452ad7..ba117f5 100644
> >> --- a/sound/usb/Kconfig
> >> +++ b/sound/usb/Kconfig
> >> @@ -15,6 +15,7 @@ config SND_USB_AUDIO
> >>  	select SND_RAWMIDI
> >>  	select SND_PCM
> >>  	select BITREVERSE
> >> +	select SND_USB_AUDIO_USE_MEDIA_CONTROLLER if MEDIA_CONTROLLER && MEDIA_SUPPORT
> > 
> > Looking at the media Kconfig again, this would be broken if
> > MEDIA_SUPPORT=m and SND_USB_AUDIO=y.  The ugly workaround is something
> > like:
> > 	select SND_USB_AUDIO_USE_MEDIA_CONTROLLER \
> > 		if MEDIA_CONTROLLER && (MEDIA_SUPPORT=y || MEDIA_SUPPORT=SND)
> 
> My current config is MEDIA_SUPPORT=m and SND_USB_AUDIO=y
> It is working and I didn't see any issues so far.

Hmm, how does it be?  In drivers/media/Makefile:

ifeq ($(CONFIG_MEDIA_CONTROLLER),y)
  obj-$(CONFIG_MEDIA_SUPPORT) += media.o
endif

So it's a module.  Meanwhile you have reference from usb-audio driver
that is built-in kernel.  How is the symbol resolved?

> Maybe
> the current change is good. I am hoping kbuild-bot can
> find issues (if any) once it gets merged.
> 
> > 
> > Other than that, it looks more or less OK to me.
> > The way how media_stream_init() gets called is a bit worrisome, but it
> > should work practically.  Another concern is about the disconnection.
> > Can all function calls in media_device_delete() be safe even if it's
> > called while the application still opens the MC device?
> 
> Right. I have been looking into device removal path when
> ioctls are active and I can resolve any issues that might
> surface while an audio app is active when device is removed.

So, it's 100% safe to call all these media_*() functions while the
device is being accessed before closing?


Takashi

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v3 22/22] sound/usb: Use Media Controller API to share media resources
  2016-02-26 20:50       ` Takashi Iwai
@ 2016-02-27  2:55         ` Shuah Khan
  2016-02-27  7:48           ` Takashi Iwai
  0 siblings, 1 reply; 49+ messages in thread
From: Shuah Khan @ 2016-02-27  2:55 UTC (permalink / raw)
  To: Takashi Iwai
  Cc: hans.verkuil, laurent.pinchart, clemens, sakari.ailus, javier,
	mchehab, geliangtang, alsa-devel, arnd, ricard.wanderlof,
	labbott, chehabrafael, klock.android, misterpib,
	prabhakar.csengg, ricardo.ribalda, ruchandani.tina, takamichiho,
	tvboxspy, dominic.sacre, albert, crope, julian,
	pierre-louis.bossart, corbet, joe, johan, dan.carpenter, pawel,
	p.zabel, perex, stefanr, inki.dae, j.anaszewski, jh1009.sung,
	k.kozlowski, kyungmin.park, m.szyprowski, nenggun.kim,
	sw0312.kim, elfring, linux-kernel, linux-media, linuxbugs,
	gtmkramer, normalperson, daniel, Shuah Khan

On 02/26/2016 01:50 PM, Takashi Iwai wrote:
> On Fri, 26 Feb 2016 21:08:43 +0100,
> Shuah Khan wrote:
>>
>> On 02/26/2016 12:55 PM, Takashi Iwai wrote:
>>> On Fri, 12 Feb 2016 00:41:38 +0100,
>>> Shuah Khan wrote:
>>>>
>>>> Change ALSA driver to use Media Controller API to
>>>> share media resources with DVB and V4L2 drivers
>>>> on a AU0828 media device. Media Controller specific
>>>> initialization is done after sound card is registered.
>>>> ALSA creates Media interface and entity function graph
>>>> nodes for Control, Mixer, PCM Playback, and PCM Capture
>>>> devices.
>>>>
>>>> snd_usb_hw_params() will call Media Controller enable
>>>> source handler interface to request the media resource.
>>>> If resource request is granted, it will release it from
>>>> snd_usb_hw_free(). If resource is busy, -EBUSY is returned.
>>>>
>>>> Media specific cleanup is done in usb_audio_disconnect().
>>>>
>>>> Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
>>>> ---
>>>>  sound/usb/Kconfig        |   4 +
>>>>  sound/usb/Makefile       |   2 +
>>>>  sound/usb/card.c         |  14 +++
>>>>  sound/usb/card.h         |   3 +
>>>>  sound/usb/media.c        | 318 +++++++++++++++++++++++++++++++++++++++++++++++
>>>>  sound/usb/media.h        |  72 +++++++++++
>>>>  sound/usb/mixer.h        |   3 +
>>>>  sound/usb/pcm.c          |  28 ++++-
>>>>  sound/usb/quirks-table.h |   1 +
>>>>  sound/usb/stream.c       |   2 +
>>>>  sound/usb/usbaudio.h     |   6 +
>>>>  11 files changed, 448 insertions(+), 5 deletions(-)
>>>>  create mode 100644 sound/usb/media.c
>>>>  create mode 100644 sound/usb/media.h
>>>>
>>>> diff --git a/sound/usb/Kconfig b/sound/usb/Kconfig
>>>> index a452ad7..ba117f5 100644
>>>> --- a/sound/usb/Kconfig
>>>> +++ b/sound/usb/Kconfig
>>>> @@ -15,6 +15,7 @@ config SND_USB_AUDIO
>>>>  	select SND_RAWMIDI
>>>>  	select SND_PCM
>>>>  	select BITREVERSE
>>>> +	select SND_USB_AUDIO_USE_MEDIA_CONTROLLER if MEDIA_CONTROLLER && MEDIA_SUPPORT
>>>
>>> Looking at the media Kconfig again, this would be broken if
>>> MEDIA_SUPPORT=m and SND_USB_AUDIO=y.  The ugly workaround is something
>>> like:
>>> 	select SND_USB_AUDIO_USE_MEDIA_CONTROLLER \
>>> 		if MEDIA_CONTROLLER && (MEDIA_SUPPORT=y || MEDIA_SUPPORT=SND)
>>
>> My current config is MEDIA_SUPPORT=m and SND_USB_AUDIO=y
>> It is working and I didn't see any issues so far.
> 
> Hmm, how does it be?  In drivers/media/Makefile:
> 
> ifeq ($(CONFIG_MEDIA_CONTROLLER),y)
>   obj-$(CONFIG_MEDIA_SUPPORT) += media.o
> endif
> 
> So it's a module.  Meanwhile you have reference from usb-audio driver
> that is built-in kernel.  How is the symbol resolved?

Sorry my mistake. I misspoke. My config had:
CONFIG_MEDIA_SUPPORT=m
CONFIG_MEDIA_CONTROLLER=y
CONFIG_SND_USB_AUDIO=m

The following doesn't work as you pointed out.

CONFIG_MEDIA_SUPPORT=m
CONFIG_MEDIA_CONTROLLER=y
CONFIG_SND_USB_AUDIO=y

okay here is what will work for all of the possible
combinations of CONFIG_MEDIA_SUPPORT and CONFIG_SND_USB_AUDIO

select SND_USB_AUDIO_USE_MEDIA_CONTROLLER \
       if MEDIA_CONTROLLER && ((MEDIA_SUPPORT=y) || (MEDIA_SUPPORT=m && SND_USB_AUDIO=m))

The above will cover the cases when

1. CONFIG_MEDIA_SUPPORT and CONFIG_SND_USB_AUDIO are
   both modules
   CONFIG_SND_USB_AUDIO_USE_MEDIA_CONTROLLER is selected

2. CONFIG_MEDIA_SUPPORT=y and CONFIG_SND_USB_AUDIO=m
   CONFIG_SND_USB_AUDIO_USE_MEDIA_CONTROLLER is selected

3. CONFIG_MEDIA_SUPPORT=y and CONFIG_SND_USB_AUDIO=y
   CONFIG_SND_USB_AUDIO_USE_MEDIA_CONTROLLER is selected

4. CONFIG_MEDIA_SUPPORT=m and CONFIG_SND_USB_AUDIO=y
   This is when we don't want
   CONFIG_SND_USB_AUDIO_USE_MEDIA_CONTROLLER selected

I verified all of the above combinations to make sure
the logic works.

If you think of a better way to do this please let me
know. I will go ahead and send patch v4 with the above
change and you can decide if that is acceptable.

>>>
>>> Other than that, it looks more or less OK to me.
>>> The way how media_stream_init() gets called is a bit worrisome, but it
>>> should work practically.  Another concern is about the disconnection.
>>> Can all function calls in media_device_delete() be safe even if it's
>>> called while the application still opens the MC device?
>>
>> Right. I have been looking into device removal path when
>> ioctls are active and I can resolve any issues that might
>> surface while an audio app is active when device is removed.
> 
> So, it's 100% safe to call all these media_*() functions while the
> device is being accessed before closing?
> 

There is a known problem with device removal when
media device file is open and ioctl is in progress.
This isn't specific to this patch series, a general
problem that is related to media device removal in
general.

I am working on a fix for this problem. As you said,
earlier, I can work on fixing issues after the merge.

thanks,
-- Shuah


-- 
Shuah Khan
Sr. Linux Kernel Developer
Open Source Innovation Group
Samsung Research America (Silicon Valley)
shuahkh@osg.samsung.com | (970) 217-8978

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v3 22/22] sound/usb: Use Media Controller API to share media resources
  2016-02-27  2:55         ` Shuah Khan
@ 2016-02-27  7:48           ` Takashi Iwai
  2016-02-27 12:41             ` Mauro Carvalho Chehab
  2016-02-29  6:01             ` Shuah Khan
  0 siblings, 2 replies; 49+ messages in thread
From: Takashi Iwai @ 2016-02-27  7:48 UTC (permalink / raw)
  To: Shuah Khan
  Cc: hans.verkuil, laurent.pinchart, clemens, sakari.ailus, javier,
	mchehab, geliangtang, alsa-devel, arnd, ricard.wanderlof,
	labbott, chehabrafael, klock.android, misterpib,
	prabhakar.csengg, ricardo.ribalda, ruchandani.tina, takamichiho,
	tvboxspy, dominic.sacre, albert, crope, julian,
	pierre-louis.bossart, corbet, joe, johan, dan.carpenter, pawel,
	p.zabel, perex, stefanr, inki.dae, j.anaszewski, jh1009.sung,
	k.kozlowski, kyungmin.park, m.szyprowski, nenggun.kim,
	sw0312.kim, elfring, linux-kernel, linux-media, linuxbugs,
	gtmkramer, normalperson, daniel

On Sat, 27 Feb 2016 03:55:39 +0100,
Shuah Khan wrote:
> 
> On 02/26/2016 01:50 PM, Takashi Iwai wrote:
> > On Fri, 26 Feb 2016 21:08:43 +0100,
> > Shuah Khan wrote:
> >>
> >> On 02/26/2016 12:55 PM, Takashi Iwai wrote:
> >>> On Fri, 12 Feb 2016 00:41:38 +0100,
> >>> Shuah Khan wrote:
> >>>>
> >>>> Change ALSA driver to use Media Controller API to
> >>>> share media resources with DVB and V4L2 drivers
> >>>> on a AU0828 media device. Media Controller specific
> >>>> initialization is done after sound card is registered.
> >>>> ALSA creates Media interface and entity function graph
> >>>> nodes for Control, Mixer, PCM Playback, and PCM Capture
> >>>> devices.
> >>>>
> >>>> snd_usb_hw_params() will call Media Controller enable
> >>>> source handler interface to request the media resource.
> >>>> If resource request is granted, it will release it from
> >>>> snd_usb_hw_free(). If resource is busy, -EBUSY is returned.
> >>>>
> >>>> Media specific cleanup is done in usb_audio_disconnect().
> >>>>
> >>>> Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
> >>>> ---
> >>>>  sound/usb/Kconfig        |   4 +
> >>>>  sound/usb/Makefile       |   2 +
> >>>>  sound/usb/card.c         |  14 +++
> >>>>  sound/usb/card.h         |   3 +
> >>>>  sound/usb/media.c        | 318 +++++++++++++++++++++++++++++++++++++++++++++++
> >>>>  sound/usb/media.h        |  72 +++++++++++
> >>>>  sound/usb/mixer.h        |   3 +
> >>>>  sound/usb/pcm.c          |  28 ++++-
> >>>>  sound/usb/quirks-table.h |   1 +
> >>>>  sound/usb/stream.c       |   2 +
> >>>>  sound/usb/usbaudio.h     |   6 +
> >>>>  11 files changed, 448 insertions(+), 5 deletions(-)
> >>>>  create mode 100644 sound/usb/media.c
> >>>>  create mode 100644 sound/usb/media.h
> >>>>
> >>>> diff --git a/sound/usb/Kconfig b/sound/usb/Kconfig
> >>>> index a452ad7..ba117f5 100644
> >>>> --- a/sound/usb/Kconfig
> >>>> +++ b/sound/usb/Kconfig
> >>>> @@ -15,6 +15,7 @@ config SND_USB_AUDIO
> >>>>  	select SND_RAWMIDI
> >>>>  	select SND_PCM
> >>>>  	select BITREVERSE
> >>>> +	select SND_USB_AUDIO_USE_MEDIA_CONTROLLER if MEDIA_CONTROLLER && MEDIA_SUPPORT
> >>>
> >>> Looking at the media Kconfig again, this would be broken if
> >>> MEDIA_SUPPORT=m and SND_USB_AUDIO=y.  The ugly workaround is something
> >>> like:
> >>> 	select SND_USB_AUDIO_USE_MEDIA_CONTROLLER \
> >>> 		if MEDIA_CONTROLLER && (MEDIA_SUPPORT=y || MEDIA_SUPPORT=SND)
> >>
> >> My current config is MEDIA_SUPPORT=m and SND_USB_AUDIO=y
> >> It is working and I didn't see any issues so far.
> > 
> > Hmm, how does it be?  In drivers/media/Makefile:
> > 
> > ifeq ($(CONFIG_MEDIA_CONTROLLER),y)
> >   obj-$(CONFIG_MEDIA_SUPPORT) += media.o
> > endif
> > 
> > So it's a module.  Meanwhile you have reference from usb-audio driver
> > that is built-in kernel.  How is the symbol resolved?
> 
> Sorry my mistake. I misspoke. My config had:
> CONFIG_MEDIA_SUPPORT=m
> CONFIG_MEDIA_CONTROLLER=y
> CONFIG_SND_USB_AUDIO=m
> 
> The following doesn't work as you pointed out.
> 
> CONFIG_MEDIA_SUPPORT=m
> CONFIG_MEDIA_CONTROLLER=y
> CONFIG_SND_USB_AUDIO=y
> 
> okay here is what will work for all of the possible
> combinations of CONFIG_MEDIA_SUPPORT and CONFIG_SND_USB_AUDIO
> 
> select SND_USB_AUDIO_USE_MEDIA_CONTROLLER \
>        if MEDIA_CONTROLLER && ((MEDIA_SUPPORT=y) || (MEDIA_SUPPORT=m && SND_USB_AUDIO=m))
> 
> The above will cover the cases when
> 
> 1. CONFIG_MEDIA_SUPPORT and CONFIG_SND_USB_AUDIO are
>    both modules
>    CONFIG_SND_USB_AUDIO_USE_MEDIA_CONTROLLER is selected
> 
> 2. CONFIG_MEDIA_SUPPORT=y and CONFIG_SND_USB_AUDIO=m
>    CONFIG_SND_USB_AUDIO_USE_MEDIA_CONTROLLER is selected
> 
> 3. CONFIG_MEDIA_SUPPORT=y and CONFIG_SND_USB_AUDIO=y
>    CONFIG_SND_USB_AUDIO_USE_MEDIA_CONTROLLER is selected
> 
> 4. CONFIG_MEDIA_SUPPORT=m and CONFIG_SND_USB_AUDIO=y
>    This is when we don't want
>    CONFIG_SND_USB_AUDIO_USE_MEDIA_CONTROLLER selected
> 
> I verified all of the above combinations to make sure
> the logic works.
> 
> If you think of a better way to do this please let me
> know. I will go ahead and send patch v4 with the above
> change and you can decide if that is acceptable.

I'm not 100% sure whether CONFIG_SND_USB_AUDIO=m can be put there as
conditional inside CONFIG_SND_USB_AUDIO definition.  Maybe a safer
form would be like:

config SND_USB_AUDIO_USE_MEDIA_CONTROLLER
	bool
	default y
	depends on SND_USB_AUDIO
	depends on MEDIA_CONTROLLER
	depends on (MEDIA_SUPPORT=y || MEDIA_SUPPORT=SND_USB_AUDIO)

and drop select from SND_USB_AUDIO.


> >>> Other than that, it looks more or less OK to me.
> >>> The way how media_stream_init() gets called is a bit worrisome, but it
> >>> should work practically.  Another concern is about the disconnection.
> >>> Can all function calls in media_device_delete() be safe even if it's
> >>> called while the application still opens the MC device?
> >>
> >> Right. I have been looking into device removal path when
> >> ioctls are active and I can resolve any issues that might
> >> surface while an audio app is active when device is removed.
> > 
> > So, it's 100% safe to call all these media_*() functions while the
> > device is being accessed before closing?
> > 
> 
> There is a known problem with device removal when
> media device file is open and ioctl is in progress.
> This isn't specific to this patch series, a general
> problem that is related to media device removal in
> general.
> 
> I am working on a fix for this problem. As you said,
> earlier, I can work on fixing issues after the merge.

OK, understood.


Takashi

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v3 22/22] sound/usb: Use Media Controller API to share media resources
  2016-02-27  7:48           ` Takashi Iwai
@ 2016-02-27 12:41             ` Mauro Carvalho Chehab
  2016-02-29  6:01             ` Shuah Khan
  1 sibling, 0 replies; 49+ messages in thread
From: Mauro Carvalho Chehab @ 2016-02-27 12:41 UTC (permalink / raw)
  To: Takashi Iwai
  Cc: Shuah Khan, hans.verkuil, laurent.pinchart, clemens,
	sakari.ailus, javier, geliangtang, alsa-devel, arnd,
	ricard.wanderlof, labbott, chehabrafael, klock.android,
	misterpib, prabhakar.csengg, ricardo.ribalda, ruchandani.tina,
	takamichiho, tvboxspy, dominic.sacre, albert, crope, julian,
	pierre-louis.bossart, corbet, joe, johan, dan.carpenter, pawel,
	p.zabel, perex, stefanr, inki.dae, j.anaszewski, jh1009.sung,
	k.kozlowski, kyungmin.park, m.szyprowski, nenggun.kim,
	sw0312.kim, elfring, linux-kernel, linux-media, linuxbugs,
	gtmkramer, normalperson, daniel

Em Sat, 27 Feb 2016 08:48:05 +0100
Takashi Iwai <tiwai@suse.de> escreveu:

> On Sat, 27 Feb 2016 03:55:39 +0100,
> Shuah Khan wrote:
> > 
> > On 02/26/2016 01:50 PM, Takashi Iwai wrote:  
> > > On Fri, 26 Feb 2016 21:08:43 +0100,
> > > Shuah Khan wrote:  
> > >>
> > >> On 02/26/2016 12:55 PM, Takashi Iwai wrote:  
> > >>> On Fri, 12 Feb 2016 00:41:38 +0100,
> > >>> Shuah Khan wrote:  
> > >>>>
> > >>>> Change ALSA driver to use Media Controller API to
> > >>>> share media resources with DVB and V4L2 drivers
> > >>>> on a AU0828 media device. Media Controller specific
> > >>>> initialization is done after sound card is registered.
> > >>>> ALSA creates Media interface and entity function graph
> > >>>> nodes for Control, Mixer, PCM Playback, and PCM Capture
> > >>>> devices.
> > >>>>
> > >>>> snd_usb_hw_params() will call Media Controller enable
> > >>>> source handler interface to request the media resource.
> > >>>> If resource request is granted, it will release it from
> > >>>> snd_usb_hw_free(). If resource is busy, -EBUSY is returned.
> > >>>>
> > >>>> Media specific cleanup is done in usb_audio_disconnect().
> > >>>>
> > >>>> Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
> > >>>> ---
> > >>>>  sound/usb/Kconfig        |   4 +
> > >>>>  sound/usb/Makefile       |   2 +
> > >>>>  sound/usb/card.c         |  14 +++
> > >>>>  sound/usb/card.h         |   3 +
> > >>>>  sound/usb/media.c        | 318 +++++++++++++++++++++++++++++++++++++++++++++++
> > >>>>  sound/usb/media.h        |  72 +++++++++++
> > >>>>  sound/usb/mixer.h        |   3 +
> > >>>>  sound/usb/pcm.c          |  28 ++++-
> > >>>>  sound/usb/quirks-table.h |   1 +
> > >>>>  sound/usb/stream.c       |   2 +
> > >>>>  sound/usb/usbaudio.h     |   6 +
> > >>>>  11 files changed, 448 insertions(+), 5 deletions(-)
> > >>>>  create mode 100644 sound/usb/media.c
> > >>>>  create mode 100644 sound/usb/media.h
> > >>>>
> > >>>> diff --git a/sound/usb/Kconfig b/sound/usb/Kconfig
> > >>>> index a452ad7..ba117f5 100644
> > >>>> --- a/sound/usb/Kconfig
> > >>>> +++ b/sound/usb/Kconfig
> > >>>> @@ -15,6 +15,7 @@ config SND_USB_AUDIO
> > >>>>  	select SND_RAWMIDI
> > >>>>  	select SND_PCM
> > >>>>  	select BITREVERSE
> > >>>> +	select SND_USB_AUDIO_USE_MEDIA_CONTROLLER if MEDIA_CONTROLLER && MEDIA_SUPPORT  
> > >>>
> > >>> Looking at the media Kconfig again, this would be broken if
> > >>> MEDIA_SUPPORT=m and SND_USB_AUDIO=y.  The ugly workaround is something
> > >>> like:
> > >>> 	select SND_USB_AUDIO_USE_MEDIA_CONTROLLER \
> > >>> 		if MEDIA_CONTROLLER && (MEDIA_SUPPORT=y || MEDIA_SUPPORT=SND)  
> > >>
> > >> My current config is MEDIA_SUPPORT=m and SND_USB_AUDIO=y
> > >> It is working and I didn't see any issues so far.  
> > > 
> > > Hmm, how does it be?  In drivers/media/Makefile:
> > > 
> > > ifeq ($(CONFIG_MEDIA_CONTROLLER),y)
> > >   obj-$(CONFIG_MEDIA_SUPPORT) += media.o
> > > endif
> > > 
> > > So it's a module.  Meanwhile you have reference from usb-audio driver
> > > that is built-in kernel.  How is the symbol resolved?  
> > 
> > Sorry my mistake. I misspoke. My config had:
> > CONFIG_MEDIA_SUPPORT=m
> > CONFIG_MEDIA_CONTROLLER=y
> > CONFIG_SND_USB_AUDIO=m
> > 
> > The following doesn't work as you pointed out.
> > 
> > CONFIG_MEDIA_SUPPORT=m
> > CONFIG_MEDIA_CONTROLLER=y
> > CONFIG_SND_USB_AUDIO=y
> > 
> > okay here is what will work for all of the possible
> > combinations of CONFIG_MEDIA_SUPPORT and CONFIG_SND_USB_AUDIO
> > 
> > select SND_USB_AUDIO_USE_MEDIA_CONTROLLER \
> >        if MEDIA_CONTROLLER && ((MEDIA_SUPPORT=y) || (MEDIA_SUPPORT=m && SND_USB_AUDIO=m))
> > 
> > The above will cover the cases when
> > 
> > 1. CONFIG_MEDIA_SUPPORT and CONFIG_SND_USB_AUDIO are
> >    both modules
> >    CONFIG_SND_USB_AUDIO_USE_MEDIA_CONTROLLER is selected
> > 
> > 2. CONFIG_MEDIA_SUPPORT=y and CONFIG_SND_USB_AUDIO=m
> >    CONFIG_SND_USB_AUDIO_USE_MEDIA_CONTROLLER is selected
> > 
> > 3. CONFIG_MEDIA_SUPPORT=y and CONFIG_SND_USB_AUDIO=y
> >    CONFIG_SND_USB_AUDIO_USE_MEDIA_CONTROLLER is selected
> > 
> > 4. CONFIG_MEDIA_SUPPORT=m and CONFIG_SND_USB_AUDIO=y
> >    This is when we don't want
> >    CONFIG_SND_USB_AUDIO_USE_MEDIA_CONTROLLER selected
> > 
> > I verified all of the above combinations to make sure
> > the logic works.
> > 
> > If you think of a better way to do this please let me
> > know. I will go ahead and send patch v4 with the above
> > change and you can decide if that is acceptable.  
> 
> I'm not 100% sure whether CONFIG_SND_USB_AUDIO=m can be put there as
> conditional inside CONFIG_SND_USB_AUDIO definition.  Maybe a safer
> form would be like:
> 
> config SND_USB_AUDIO_USE_MEDIA_CONTROLLER
> 	bool
> 	default y
> 	depends on SND_USB_AUDIO
> 	depends on MEDIA_CONTROLLER
> 	depends on (MEDIA_SUPPORT=y || MEDIA_SUPPORT=SND_USB_AUDIO)
> 
> and drop select from SND_USB_AUDIO.
> 
> 
> > >>> Other than that, it looks more or less OK to me.
> > >>> The way how media_stream_init() gets called is a bit worrisome, but it
> > >>> should work practically.  Another concern is about the disconnection.
> > >>> Can all function calls in media_device_delete() be safe even if it's
> > >>> called while the application still opens the MC device?  
> > >>
> > >> Right. I have been looking into device removal path when
> > >> ioctls are active and I can resolve any issues that might
> > >> surface while an audio app is active when device is removed.  
> > > 
> > > So, it's 100% safe to call all these media_*() functions while the
> > > device is being accessed before closing?
> > >   
> > 
> > There is a known problem with device removal when
> > media device file is open and ioctl is in progress.
> > This isn't specific to this patch series, a general
> > problem that is related to media device removal in
> > general.
> > 
> > I am working on a fix for this problem. As you said,
> > earlier, I can work on fixing issues after the merge.  
> 
> OK, understood.
> 
> 
> Takashi


As there are still some issues here, I decided to apply all but
this one, in order to avoid having compilation issues with random
configs.

Shuah,

As there were several conflicts when I applied the initial 21 patches
from this series, please apply this one on the top of the latest
tree. 

As this patch touches only at sound, it is independent, so
you won't need to rebase it. However, I might have solved some
conflicts badly, a final test wouldn't hurt ;)

Regards,
Mauro

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v3 22/22] sound/usb: Use Media Controller API to share media resources
  2016-02-27  7:48           ` Takashi Iwai
  2016-02-27 12:41             ` Mauro Carvalho Chehab
@ 2016-02-29  6:01             ` Shuah Khan
  1 sibling, 0 replies; 49+ messages in thread
From: Shuah Khan @ 2016-02-29  6:01 UTC (permalink / raw)
  To: Takashi Iwai, mchehab
  Cc: hans.verkuil, laurent.pinchart, clemens, sakari.ailus, javier,
	geliangtang, alsa-devel, arnd, ricard.wanderlof, labbott,
	chehabrafael, klock.android, misterpib, prabhakar.csengg,
	ricardo.ribalda, ruchandani.tina, takamichiho, tvboxspy,
	dominic.sacre, albert, crope, julian, pierre-louis.bossart,
	corbet, joe, johan, dan.carpenter, pawel, p.zabel, perex,
	stefanr, inki.dae, j.anaszewski, jh1009.sung, k.kozlowski,
	kyungmin.park, m.szyprowski, nenggun.kim, sw0312.kim, elfring,
	linux-kernel, linux-media, linuxbugs, gtmkramer, normalperson,
	daniel

On 02/27/2016 12:48 AM, Takashi Iwai wrote:
> On Sat, 27 Feb 2016 03:55:39 +0100,
> Shuah Khan wrote:
>>
>> On 02/26/2016 01:50 PM, Takashi Iwai wrote:
>>> On Fri, 26 Feb 2016 21:08:43 +0100,
>>> Shuah Khan wrote:
>>>>
>>>> On 02/26/2016 12:55 PM, Takashi Iwai wrote:
>>>>> On Fri, 12 Feb 2016 00:41:38 +0100,
>>>>> Shuah Khan wrote:
>>>>>>
>>>>>> Change ALSA driver to use Media Controller API to
>>>>>> share media resources with DVB and V4L2 drivers
>>>>>> on a AU0828 media device. Media Controller specific
>>>>>> initialization is done after sound card is registered.
>>>>>> ALSA creates Media interface and entity function graph
>>>>>> nodes for Control, Mixer, PCM Playback, and PCM Capture
>>>>>> devices.
>>>>>>
>>>>>> snd_usb_hw_params() will call Media Controller enable
>>>>>> source handler interface to request the media resource.
>>>>>> If resource request is granted, it will release it from
>>>>>> snd_usb_hw_free(). If resource is busy, -EBUSY is returned.
>>>>>>
>>>>>> Media specific cleanup is done in usb_audio_disconnect().
>>>>>>
>>>>>> Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
>>>>>> ---
>>>>>>  sound/usb/Kconfig        |   4 +
>>>>>>  sound/usb/Makefile       |   2 +
>>>>>>  sound/usb/card.c         |  14 +++
>>>>>>  sound/usb/card.h         |   3 +
>>>>>>  sound/usb/media.c        | 318 +++++++++++++++++++++++++++++++++++++++++++++++
>>>>>>  sound/usb/media.h        |  72 +++++++++++
>>>>>>  sound/usb/mixer.h        |   3 +
>>>>>>  sound/usb/pcm.c          |  28 ++++-
>>>>>>  sound/usb/quirks-table.h |   1 +
>>>>>>  sound/usb/stream.c       |   2 +
>>>>>>  sound/usb/usbaudio.h     |   6 +
>>>>>>  11 files changed, 448 insertions(+), 5 deletions(-)
>>>>>>  create mode 100644 sound/usb/media.c
>>>>>>  create mode 100644 sound/usb/media.h
>>>>>>
>>>>>> diff --git a/sound/usb/Kconfig b/sound/usb/Kconfig
>>>>>> index a452ad7..ba117f5 100644
>>>>>> --- a/sound/usb/Kconfig
>>>>>> +++ b/sound/usb/Kconfig
>>>>>> @@ -15,6 +15,7 @@ config SND_USB_AUDIO
>>>>>>  	select SND_RAWMIDI
>>>>>>  	select SND_PCM
>>>>>>  	select BITREVERSE
>>>>>> +	select SND_USB_AUDIO_USE_MEDIA_CONTROLLER if MEDIA_CONTROLLER && MEDIA_SUPPORT
>>>>>
>>>>> Looking at the media Kconfig again, this would be broken if
>>>>> MEDIA_SUPPORT=m and SND_USB_AUDIO=y.  The ugly workaround is something
>>>>> like:
>>>>> 	select SND_USB_AUDIO_USE_MEDIA_CONTROLLER \
>>>>> 		if MEDIA_CONTROLLER && (MEDIA_SUPPORT=y || MEDIA_SUPPORT=SND)
>>>>
>>>> My current config is MEDIA_SUPPORT=m and SND_USB_AUDIO=y
>>>> It is working and I didn't see any issues so far.
>>>
>>> Hmm, how does it be?  In drivers/media/Makefile:
>>>
>>> ifeq ($(CONFIG_MEDIA_CONTROLLER),y)
>>>   obj-$(CONFIG_MEDIA_SUPPORT) += media.o
>>> endif
>>>
>>> So it's a module.  Meanwhile you have reference from usb-audio driver
>>> that is built-in kernel.  How is the symbol resolved?
>>
>> Sorry my mistake. I misspoke. My config had:
>> CONFIG_MEDIA_SUPPORT=m
>> CONFIG_MEDIA_CONTROLLER=y
>> CONFIG_SND_USB_AUDIO=m
>>
>> The following doesn't work as you pointed out.
>>
>> CONFIG_MEDIA_SUPPORT=m
>> CONFIG_MEDIA_CONTROLLER=y
>> CONFIG_SND_USB_AUDIO=y
>>
>> okay here is what will work for all of the possible
>> combinations of CONFIG_MEDIA_SUPPORT and CONFIG_SND_USB_AUDIO
>>
>> select SND_USB_AUDIO_USE_MEDIA_CONTROLLER \
>>        if MEDIA_CONTROLLER && ((MEDIA_SUPPORT=y) || (MEDIA_SUPPORT=m && SND_USB_AUDIO=m))
>>
>> The above will cover the cases when
>>
>> 1. CONFIG_MEDIA_SUPPORT and CONFIG_SND_USB_AUDIO are
>>    both modules
>>    CONFIG_SND_USB_AUDIO_USE_MEDIA_CONTROLLER is selected
>>
>> 2. CONFIG_MEDIA_SUPPORT=y and CONFIG_SND_USB_AUDIO=m
>>    CONFIG_SND_USB_AUDIO_USE_MEDIA_CONTROLLER is selected
>>
>> 3. CONFIG_MEDIA_SUPPORT=y and CONFIG_SND_USB_AUDIO=y
>>    CONFIG_SND_USB_AUDIO_USE_MEDIA_CONTROLLER is selected
>>
>> 4. CONFIG_MEDIA_SUPPORT=m and CONFIG_SND_USB_AUDIO=y
>>    This is when we don't want
>>    CONFIG_SND_USB_AUDIO_USE_MEDIA_CONTROLLER selected
>>
>> I verified all of the above combinations to make sure
>> the logic works.
>>
>> If you think of a better way to do this please let me
>> know. I will go ahead and send patch v4 with the above
>> change and you can decide if that is acceptable.
> 
> I'm not 100% sure whether CONFIG_SND_USB_AUDIO=m can be put there as
> conditional inside CONFIG_SND_USB_AUDIO definition.  Maybe a safer
> form would be like:
> 
> config SND_USB_AUDIO_USE_MEDIA_CONTROLLER
> 	bool
> 	default y
> 	depends on SND_USB_AUDIO
> 	depends on MEDIA_CONTROLLER
> 	depends on (MEDIA_SUPPORT=y || MEDIA_SUPPORT=SND_USB_AUDIO)
> 
> and drop select from SND_USB_AUDIO.
> 
> 
>>>>> Other than that, it looks more or less OK to me.
>>>>> The way how media_stream_init() gets called is a bit worrisome, but it
>>>>> should work practically.  Another concern is about the disconnection.
>>>>> Can all function calls in media_device_delete() be safe even if it's
>>>>> called while the application still opens the MC device?
>>>>
>>>> Right. I have been looking into device removal path when
>>>> ioctls are active and I can resolve any issues that might
>>>> surface while an audio app is active when device is removed.
>>>
>>> So, it's 100% safe to call all these media_*() functions while the
>>> device is being accessed before closing?
>>>
>>
>> There is a known problem with device removal when
>> media device file is open and ioctl is in progress.
>> This isn't specific to this patch series, a general
>> problem that is related to media device removal in
>> general.
>>
>> I am working on a fix for this problem. As you said,
>> earlier, I can work on fixing issues after the merge.
> 
> OK, understood.
> 
> 

Hi Takashi,

I sent patch v4 that works for all combinations
of MEDIA_SUPPORT and SND_USB_AUDIO.

Please review and Ack if you are okay with this
version. Thanks for your help with the Kconfig
file changes.

-- Shuah

-- 
Shuah Khan
Sr. Linux Kernel Developer
Open Source Innovation Group
Samsung Research America (Silicon Valley)
shuahkh@osg.samsung.com | (970) 217-8978

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v3 02/22] uapi/media.h: Declare interface types for ALSA
  2016-02-11 23:41 ` [PATCH v3 02/22] uapi/media.h: Declare interface types for ALSA Shuah Khan
  2016-02-17 12:21   ` Mauro Carvalho Chehab
@ 2016-03-03 14:59   ` Hans Verkuil
  2016-03-03 15:57     ` Shuah Khan
  1 sibling, 1 reply; 49+ messages in thread
From: Hans Verkuil @ 2016-03-03 14:59 UTC (permalink / raw)
  To: Shuah Khan, mchehab, tiwai, clemens, hans.verkuil,
	laurent.pinchart, sakari.ailus, javier
  Cc: pawel, m.szyprowski, kyungmin.park, perex, arnd, dan.carpenter,
	tvboxspy, crope, ruchandani.tina, corbet, chehabrafael,
	k.kozlowski, stefanr, inki.dae, jh1009.sung, elfring,
	prabhakar.csengg, sw0312.kim, p.zabel, ricardo.ribalda, labbott,
	pierre-louis.bossart, ricard.wanderlof, julian, takamichiho,
	dominic.sacre, misterpib, daniel, gtmkramer, normalperson, joe,
	linuxbugs, johan, klock.android, nenggun.kim, j.anaszewski,
	geliangtang, albert, linux-kernel, linux-media, alsa-devel

On 02/12/16 00:41, Shuah Khan wrote:
> Declare the interface types to be used on alsa for
> the new G_TOPOLOGY ioctl.
> 
> Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
> ---
>  drivers/media/media-entity.c | 16 ++++++++++++++++
>  include/uapi/linux/media.h   | 10 ++++++++++
>  2 files changed, 26 insertions(+)
> 
> diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
> index f2e4360..6179543 100644
> --- a/drivers/media/media-entity.c
> +++ b/drivers/media/media-entity.c
> @@ -65,6 +65,22 @@ static inline const char *intf_type(struct media_interface *intf)
>  		return "v4l2-subdev";
>  	case MEDIA_INTF_T_V4L_SWRADIO:
>  		return "swradio";
> +	case MEDIA_INTF_T_ALSA_PCM_CAPTURE:
> +		return "pcm-capture";
> +	case MEDIA_INTF_T_ALSA_PCM_PLAYBACK:
> +		return "pcm-playback";
> +	case MEDIA_INTF_T_ALSA_CONTROL:
> +		return "alsa-control";
> +	case MEDIA_INTF_T_ALSA_COMPRESS:
> +		return "compress";
> +	case MEDIA_INTF_T_ALSA_RAWMIDI:
> +		return "rawmidi";
> +	case MEDIA_INTF_T_ALSA_HWDEP:
> +		return "hwdep";
> +	case MEDIA_INTF_T_ALSA_SEQUENCER:
> +		return "sequencer";
> +	case MEDIA_INTF_T_ALSA_TIMER:
> +		return "timer";

Wouldn't it be better to add an 'alsa' prefix for all of these?

And 'dvb-' or 'v4l2-' (or v4l-) for the others as well.

Names like 'timer' are very generic. I think it would be a good idea to
make the naming more regular and have it include the subsystem name just
as the define does.

Regards,

	Hans

>  	default:
>  		return "unknown-intf";
>  	}
> diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
> index c9eb42a..3cc0366 100644
> --- a/include/uapi/linux/media.h
> +++ b/include/uapi/linux/media.h
> @@ -265,6 +265,7 @@ struct media_links_enum {
>  
>  #define MEDIA_INTF_T_DVB_BASE	0x00000100
>  #define MEDIA_INTF_T_V4L_BASE	0x00000200
> +#define MEDIA_INTF_T_ALSA_BASE	0x00000300
>  
>  /* Interface types */
>  
> @@ -280,6 +281,15 @@ struct media_links_enum {
>  #define MEDIA_INTF_T_V4L_SUBDEV (MEDIA_INTF_T_V4L_BASE + 3)
>  #define MEDIA_INTF_T_V4L_SWRADIO (MEDIA_INTF_T_V4L_BASE + 4)
>  
> +#define MEDIA_INTF_T_ALSA_PCM_CAPTURE   (MEDIA_INTF_T_ALSA_BASE)
> +#define MEDIA_INTF_T_ALSA_PCM_PLAYBACK  (MEDIA_INTF_T_ALSA_BASE + 1)
> +#define MEDIA_INTF_T_ALSA_CONTROL       (MEDIA_INTF_T_ALSA_BASE + 2)
> +#define MEDIA_INTF_T_ALSA_COMPRESS      (MEDIA_INTF_T_ALSA_BASE + 3)
> +#define MEDIA_INTF_T_ALSA_RAWMIDI       (MEDIA_INTF_T_ALSA_BASE + 4)
> +#define MEDIA_INTF_T_ALSA_HWDEP         (MEDIA_INTF_T_ALSA_BASE + 5)
> +#define MEDIA_INTF_T_ALSA_SEQUENCER     (MEDIA_INTF_T_ALSA_BASE + 6)
> +#define MEDIA_INTF_T_ALSA_TIMER         (MEDIA_INTF_T_ALSA_BASE + 7)
> +
>  /*
>   * MC next gen API definitions
>   *
> 

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v3 02/22] uapi/media.h: Declare interface types for ALSA
  2016-03-03 14:59   ` Hans Verkuil
@ 2016-03-03 15:57     ` Shuah Khan
  0 siblings, 0 replies; 49+ messages in thread
From: Shuah Khan @ 2016-03-03 15:57 UTC (permalink / raw)
  To: Hans Verkuil, mchehab, tiwai, clemens, hans.verkuil,
	laurent.pinchart, sakari.ailus, javier
  Cc: pawel, m.szyprowski, kyungmin.park, perex, arnd, dan.carpenter,
	tvboxspy, crope, ruchandani.tina, corbet, chehabrafael,
	k.kozlowski, stefanr, inki.dae, jh1009.sung, elfring,
	prabhakar.csengg, sw0312.kim, p.zabel, ricardo.ribalda, labbott,
	pierre-louis.bossart, ricard.wanderlof, julian, takamichiho,
	dominic.sacre, misterpib, daniel, gtmkramer, normalperson, joe,
	linuxbugs, johan, klock.android, nenggun.kim, j.anaszewski,
	geliangtang, albert, linux-kernel, linux-media, alsa-devel,
	Shuah Khan

On 03/03/2016 07:59 AM, Hans Verkuil wrote:
> On 02/12/16 00:41, Shuah Khan wrote:
>> Declare the interface types to be used on alsa for
>> the new G_TOPOLOGY ioctl.
>>
>> Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
>> ---
>>  drivers/media/media-entity.c | 16 ++++++++++++++++
>>  include/uapi/linux/media.h   | 10 ++++++++++
>>  2 files changed, 26 insertions(+)
>>
>> diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
>> index f2e4360..6179543 100644
>> --- a/drivers/media/media-entity.c
>> +++ b/drivers/media/media-entity.c
>> @@ -65,6 +65,22 @@ static inline const char *intf_type(struct media_interface *intf)
>>  		return "v4l2-subdev";
>>  	case MEDIA_INTF_T_V4L_SWRADIO:
>>  		return "swradio";
>> +	case MEDIA_INTF_T_ALSA_PCM_CAPTURE:
>> +		return "pcm-capture";
>> +	case MEDIA_INTF_T_ALSA_PCM_PLAYBACK:
>> +		return "pcm-playback";
>> +	case MEDIA_INTF_T_ALSA_CONTROL:
>> +		return "alsa-control";
>> +	case MEDIA_INTF_T_ALSA_COMPRESS:
>> +		return "compress";
>> +	case MEDIA_INTF_T_ALSA_RAWMIDI:
>> +		return "rawmidi";
>> +	case MEDIA_INTF_T_ALSA_HWDEP:
>> +		return "hwdep";
>> +	case MEDIA_INTF_T_ALSA_SEQUENCER:
>> +		return "sequencer";
>> +	case MEDIA_INTF_T_ALSA_TIMER:
>> +		return "timer";
> 
> Wouldn't it be better to add an 'alsa' prefix for all of these?
> 
> And 'dvb-' or 'v4l2-' (or v4l-) for the others as well.
> 
> Names like 'timer' are very generic. I think it would be a good idea to
> make the naming more regular and have it include the subsystem name just
> as the define does.
> 
> Regards,
> 
> 	Hans
> 

Yes adding more information 'dvb-' or 'v4l2-' (or v4l-), alsa
to strings would help. I can fix all of them in a separate
patch if that is okay with you.

thanks,
-- Shuah


-- 
Shuah Khan
Sr. Linux Kernel Developer
Open Source Innovation Group
Samsung Research America (Silicon Valley)
shuahkh@osg.samsung.com | (970) 217-8978

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v3 03/22] [media] Docbook: media-types.xml: Add Audio Function Entities
       [not found]   ` <1886674.Y0SDWvK9bd@avalon>
@ 2016-03-03 22:50     ` Shuah Khan
  0 siblings, 0 replies; 49+ messages in thread
From: Shuah Khan @ 2016-03-03 22:50 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: mchehab, tiwai, clemens, hans.verkuil, sakari.ailus, javier,
	pawel, m.szyprowski, kyungmin.park, perex, arnd, dan.carpenter,
	tvboxspy, crope, ruchandani.tina, corbet, chehabrafael,
	k.kozlowski, stefanr, inki.dae, jh1009.sung, elfring,
	prabhakar.csengg, sw0312.kim, p.zabel, ricardo.ribalda, labbott,
	pierre-louis.bossart, ricard.wanderlof, julian, takamichiho,
	dominic.sacre, misterpib, daniel, gtmkramer, normalperson, joe,
	linuxbugs, johan, klock.android, nenggun.kim, j.anaszewski,
	geliangtang, al bert, linux-kernel, linux-media, alsa-devel,
	Shuah Khan

On 02/28/2016 07:46 PM, Laurent Pinchart wrote:
> Hi Shuah,
> 
> Thank you for the patch.
> 
> On Thursday 11 February 2016 16:41:19 Shuah Khan wrote:
>> Add Audio Function Entities
>>
>> Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
>> ---
>>  Documentation/DocBook/media/v4l/media-types.xml | 12 ++++++++++++
>>  1 file changed, 12 insertions(+)
>>
>> diff --git a/Documentation/DocBook/media/v4l/media-types.xml
>> b/Documentation/DocBook/media/v4l/media-types.xml index 3730967..924a604
>> 100644
>> --- a/Documentation/DocBook/media/v4l/media-types.xml
>> +++ b/Documentation/DocBook/media/v4l/media-types.xml
>> @@ -113,6 +113,18 @@
>>  		   decoder.
>>  	    </entry>
>>  	  </row>
>> +	  <row>
>> +	    <entry><constant>MEDIA_ENT_F_AUDIO_CAPTURE</constant></entry>
>> +	    <entry>Audio Capture Function Entity.</entry>
>> +	  </row>
>> +	  <row>
>> +	    <entry><constant>MEDIA_ENT_F_AUDIO_PLAYBACK</constant></entry>
>> +	    <entry>Audio Playback Function Entity.</entry>
>> +	  </row>
> 
> I think this deserves a longer description. From the name and short 
> description I'm not sure what the capture and playback functions are.
> 
>> +	  <row>
>> +	    <entry><constant>MEDIA_ENT_F_AUDIO_MIXER</constant></entry>
>> +	    <entry>Audio Mixer Function Entity.</entry>
>> +	  </row>
> 
> Entities can implement multiple functions, so function descriptions shouldn't 
> refer to entity this way. MEDIA_ENT_F_AUDIO_MIXER doesn't mean that the entity 
> is an audio mixer, it means that the entity implements the audio mixer 
> function. If you want to keep the description short you could just write 
> "Audio mixer". A longer description could be "The entity can mix multiple 
> input audio streams to produce an output audio stream.".
> 
>>  	</tbody>
>>        </tgroup>
>>      </table>
> 

Thanks for the review. I will send a followup patch
for this.

thanks,
-- Shuah

-- 
Shuah Khan
Sr. Linux Kernel Developer
Open Source Innovation Group
Samsung Research America (Silicon Valley)
shuahkh@osg.samsung.com | (970) 217-8978

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v3 06/22] media: Media Controller enable/disable source handler API
  2016-02-11 23:41 ` [PATCH v3 06/22] media: Media Controller enable/disable source handler API Shuah Khan
@ 2016-03-10  7:35   ` Sakari Ailus
  2016-03-10 14:29     ` Shuah Khan
  0 siblings, 1 reply; 49+ messages in thread
From: Sakari Ailus @ 2016-03-10  7:35 UTC (permalink / raw)
  To: Shuah Khan
  Cc: mchehab, tiwai, clemens, hans.verkuil, laurent.pinchart,
	sakari.ailus, javier, pawel, m.szyprowski, kyungmin.park, perex,
	arnd, dan.carpenter, tvboxspy, crope, ruchandani.tina, corbet,
	chehabrafael, k.kozlowski, stefanr, inki.dae, jh1009.sung,
	elfring, prabhakar.csengg, sw0312.kim, p.zabel, ricardo.ribalda,
	labbott, pierre-louis.bossart, ricard.wanderlof, julian,
	takamichiho, dominic.sacre, misterpib, daniel, gtmkramer,
	normalperson, joe, linuxbugs, johan, klock.android, nenggun.kim,
	j.anaszewski, geliangtang, albert, linux-kernel, linux-media,
	alsa-devel

Hi Shuah,

On Thu, Feb 11, 2016 at 04:41:22PM -0700, Shuah Khan wrote:
> Add new fields to struct media_device to add enable_source, and
> disable_source handlers, and source_priv to stash driver private
> data that is used to run these handlers. The enable_source handler
> finds source entity for the passed in entity and checks if it is
> available. When link is found, it activates it. Disable source
> handler deactivates the link.
> 
> Bridge driver is expected to implement and set these handlers.
> 
> Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
> ---
>  include/media/media-device.h | 30 ++++++++++++++++++++++++++++++
>  1 file changed, 30 insertions(+)
> 
> diff --git a/include/media/media-device.h b/include/media/media-device.h
> index 075a482..1a04644 100644
> --- a/include/media/media-device.h
> +++ b/include/media/media-device.h
> @@ -302,6 +302,11 @@ struct media_entity_notify {
>   * @entity_notify: List of registered entity_notify callbacks
>   * @lock:	Entities list lock
>   * @graph_mutex: Entities graph operation lock
> + *
> + * @source_priv: Driver Private data for enable/disable source handlers
> + * @enable_source: Enable Source Handler function pointer
> + * @disable_source: Disable Source Handler function pointer
> + *
>   * @link_notify: Link state change notification callback
>   *
>   * This structure represents an abstract high-level media device. It allows easy
> @@ -313,6 +318,26 @@ struct media_entity_notify {
>   *
>   * @model is a descriptive model name exported through sysfs. It doesn't have to
>   * be unique.
> + *
> + * @enable_source is a handler to find source entity for the
> + * sink entity  and activate the link between them if source
> + * entity is free. Drivers should call this handler before
> + * accessing the source.
> + *
> + * @disable_source is a handler to find source entity for the
> + * sink entity  and deactivate the link between them. Drivers
> + * should call this handler to release the source.
> + *

Is there a particular reason you're not simply (de)activating the link, but
instead add a new callback?

> + * Note: Bridge driver is expected to implement and set the
> + * handler when media_device is registered or when
> + * bridge driver finds the media_device during probe.
> + * Bridge driver sets source_priv with information
> + * necessary to run enable/disable source handlers.
> + *
> + * Use-case: find tuner entity connected to the decoder
> + * entity and check if it is available, and activate the
> + * the link between them from enable_source and deactivate
> + * from disable_source.
>   */
>  struct media_device {
>  	/* dev->driver_data points to this struct. */
> @@ -344,6 +369,11 @@ struct media_device {
>  	/* Serializes graph operations. */
>  	struct mutex graph_mutex;
>  
> +	void *source_priv;
> +	int (*enable_source)(struct media_entity *entity,
> +			     struct media_pipeline *pipe);
> +	void (*disable_source)(struct media_entity *entity);
> +
>  	int (*link_notify)(struct media_link *link, u32 flags,
>  			   unsigned int notification);
>  };

-- 
Kind regards,

Sakari Ailus
e-mail: sakari.ailus@iki.fi	XMPP: sailus@retiisi.org.uk

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v3 06/22] media: Media Controller enable/disable source handler API
  2016-03-10  7:35   ` Sakari Ailus
@ 2016-03-10 14:29     ` Shuah Khan
  2016-03-13 20:11       ` Sakari Ailus
  0 siblings, 1 reply; 49+ messages in thread
From: Shuah Khan @ 2016-03-10 14:29 UTC (permalink / raw)
  To: Sakari Ailus
  Cc: mchehab, tiwai, clemens, hans.verkuil, laurent.pinchart,
	sakari.ailus, javier, pawel, m.szyprowski, kyungmin.park, perex,
	arnd, dan.carpenter, tvboxspy, crope, ruchandani.tina, corbet,
	chehabrafael, k.kozlowski, stefanr, inki.dae, jh1009.sung,
	elfring, prabhakar.csengg, sw0312.kim, p.zabel, ricardo.ribalda,
	labbott, pierre-louis.bossart, ricard.wanderlof, julian,
	takamichiho, dominic.sacre, misterpib, daniel, gtmkramer,
	normalperson, joe, linuxbugs, johan, klock.android, nenggun.kim,
	j.anaszewski, geliangtang, albert, linux-kernel, linux-media,
	alsa-devel, Shuah Khan

On 03/10/2016 12:35 AM, Sakari Ailus wrote:
> Hi Shuah,
> 
> On Thu, Feb 11, 2016 at 04:41:22PM -0700, Shuah Khan wrote:
>> Add new fields to struct media_device to add enable_source, and
>> disable_source handlers, and source_priv to stash driver private
>> data that is used to run these handlers. The enable_source handler
>> finds source entity for the passed in entity and checks if it is
>> available. When link is found, it activates it. Disable source
>> handler deactivates the link.
>>
>> Bridge driver is expected to implement and set these handlers.
>>
>> Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
>> ---
>>  include/media/media-device.h | 30 ++++++++++++++++++++++++++++++
>>  1 file changed, 30 insertions(+)
>>
>> diff --git a/include/media/media-device.h b/include/media/media-device.h
>> index 075a482..1a04644 100644
>> --- a/include/media/media-device.h
>> +++ b/include/media/media-device.h
>> @@ -302,6 +302,11 @@ struct media_entity_notify {
>>   * @entity_notify: List of registered entity_notify callbacks
>>   * @lock:	Entities list lock
>>   * @graph_mutex: Entities graph operation lock
>> + *
>> + * @source_priv: Driver Private data for enable/disable source handlers
>> + * @enable_source: Enable Source Handler function pointer
>> + * @disable_source: Disable Source Handler function pointer
>> + *
>>   * @link_notify: Link state change notification callback
>>   *
>>   * This structure represents an abstract high-level media device. It allows easy
>> @@ -313,6 +318,26 @@ struct media_entity_notify {
>>   *
>>   * @model is a descriptive model name exported through sysfs. It doesn't have to
>>   * be unique.
>> + *
>> + * @enable_source is a handler to find source entity for the
>> + * sink entity  and activate the link between them if source
>> + * entity is free. Drivers should call this handler before
>> + * accessing the source.
>> + *
>> + * @disable_source is a handler to find source entity for the
>> + * sink entity  and deactivate the link between them. Drivers
>> + * should call this handler to release the source.
>> + *
> 
> Is there a particular reason you're not simply (de)activating the link, but
> instead add a new callback?

These two handlers are separate for a couple of reasons:

1. Explicit and symmetric API is easier to use and maintain.
   Similar what we do in other cases, register/unregister
   get/put etc.
2. This is more important. Disable handler makes sure the
   owner is releasing the resource. Otherwise, when some
   other application does enable, the owner could loose
   the resource, if enable and disable are the same.

   e.g: Video app is holding the resource, DVB app does
   enable. Disable handler makes sure Video/owner  is the one
   that is asking to do the release.

thanks,
-- Shuah

> 
>> + * Note: Bridge driver is expected to implement and set the
>> + * handler when media_device is registered or when
>> + * bridge driver finds the media_device during probe.
>> + * Bridge driver sets source_priv with information
>> + * necessary to run enable/disable source handlers.
>> + *
>> + * Use-case: find tuner entity connected to the decoder
>> + * entity and check if it is available, and activate the
>> + * the link between them from enable_source and deactivate
>> + * from disable_source.
>>   */
>>  struct media_device {
>>  	/* dev->driver_data points to this struct. */
>> @@ -344,6 +369,11 @@ struct media_device {
>>  	/* Serializes graph operations. */
>>  	struct mutex graph_mutex;
>>  
>> +	void *source_priv;
>> +	int (*enable_source)(struct media_entity *entity,
>> +			     struct media_pipeline *pipe);
>> +	void (*disable_source)(struct media_entity *entity);
>> +
>>  	int (*link_notify)(struct media_link *link, u32 flags,
>>  			   unsigned int notification);
>>  };
> 


-- 
Shuah Khan
Sr. Linux Kernel Developer
Open Source Innovation Group
Samsung Research America (Silicon Valley)
shuahkh@osg.samsung.com | (970) 217-8978

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v3 06/22] media: Media Controller enable/disable source handler API
  2016-03-10 14:29     ` Shuah Khan
@ 2016-03-13 20:11       ` Sakari Ailus
  2016-03-14 15:22         ` Shuah Khan
  0 siblings, 1 reply; 49+ messages in thread
From: Sakari Ailus @ 2016-03-13 20:11 UTC (permalink / raw)
  To: Shuah Khan
  Cc: mchehab, tiwai, clemens, hans.verkuil, laurent.pinchart,
	sakari.ailus, javier, pawel, m.szyprowski, kyungmin.park, perex,
	arnd, dan.carpenter, tvboxspy, crope, ruchandani.tina, corbet,
	chehabrafael, k.kozlowski, stefanr, inki.dae, jh1009.sung,
	elfring, prabhakar.csengg, sw0312.kim, p.zabel, ricardo.ribalda,
	labbott, pierre-louis.bossart, ricard.wanderlof, julian,
	takamichiho, dominic.sacre, misterpib, daniel, gtmkramer,
	normalperson, joe, linuxbugs, johan, klock.android, nenggun.kim,
	j.anaszewski, geliangtang, albert, linux-kernel, linux-media,
	alsa-devel

Hi Shuah,

On Thu, Mar 10, 2016 at 07:29:59AM -0700, Shuah Khan wrote:
> On 03/10/2016 12:35 AM, Sakari Ailus wrote:
> > Hi Shuah,
> > 
> > On Thu, Feb 11, 2016 at 04:41:22PM -0700, Shuah Khan wrote:
> >> Add new fields to struct media_device to add enable_source, and
> >> disable_source handlers, and source_priv to stash driver private
> >> data that is used to run these handlers. The enable_source handler
> >> finds source entity for the passed in entity and checks if it is
> >> available. When link is found, it activates it. Disable source
> >> handler deactivates the link.
> >>
> >> Bridge driver is expected to implement and set these handlers.
> >>
> >> Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
> >> ---
> >>  include/media/media-device.h | 30 ++++++++++++++++++++++++++++++
> >>  1 file changed, 30 insertions(+)
> >>
> >> diff --git a/include/media/media-device.h b/include/media/media-device.h
> >> index 075a482..1a04644 100644
> >> --- a/include/media/media-device.h
> >> +++ b/include/media/media-device.h
> >> @@ -302,6 +302,11 @@ struct media_entity_notify {
> >>   * @entity_notify: List of registered entity_notify callbacks
> >>   * @lock:	Entities list lock
> >>   * @graph_mutex: Entities graph operation lock
> >> + *
> >> + * @source_priv: Driver Private data for enable/disable source handlers
> >> + * @enable_source: Enable Source Handler function pointer
> >> + * @disable_source: Disable Source Handler function pointer
> >> + *
> >>   * @link_notify: Link state change notification callback
> >>   *
> >>   * This structure represents an abstract high-level media device. It allows easy
> >> @@ -313,6 +318,26 @@ struct media_entity_notify {
> >>   *
> >>   * @model is a descriptive model name exported through sysfs. It doesn't have to
> >>   * be unique.
> >> + *
> >> + * @enable_source is a handler to find source entity for the
> >> + * sink entity  and activate the link between them if source
> >> + * entity is free. Drivers should call this handler before
> >> + * accessing the source.
> >> + *
> >> + * @disable_source is a handler to find source entity for the
> >> + * sink entity  and deactivate the link between them. Drivers
> >> + * should call this handler to release the source.
> >> + *
> > 
> > Is there a particular reason you're not simply (de)activating the link, but
> > instead add a new callback?
> 
> These two handlers are separate for a couple of reasons:
> 
> 1. Explicit and symmetric API is easier to use and maintain.
>    Similar what we do in other cases, register/unregister
>    get/put etc.

Link state is set explicitly (enabled or disabled). This is certainly not a
reason to create a redundant API for link setup.

> 2. This is more important. Disable handler makes sure the
>    owner is releasing the resource. Otherwise, when some
>    other application does enable, the owner could loose
>    the resource, if enable and disable are the same.
> 
>    e.g: Video app is holding the resource, DVB app does
>    enable. Disable handler makes sure Video/owner  is the one
>    that is asking to do the release.

Based on the later patches in this set, the enable_source() callback of the 
au0828 driver performs three things:

- Find the source entity,
- Enable the link from some au0828 entity to the source and
- Start the pipeline that begins from the I/O device node. The pipe object
  is embedded in struct video_device.

disable_source() undoes this in reverse order.

That's in the au0828 driver and rightly so.

Then it gets murkier. enable_source() and disable_source() callbacks
(through a few turns) will get called from v4l2-ioctl.c functions
v4l_querycap, v4l_s_fmt, v4l_s_frequency, v4l_s_std and v4l_querystd. This
is also performed in VB2 core vb2_core_streamon() function.

I certainly have no objections when it comes to blocking other processes
from setting the format when a process holding a file handle to a device has
e.g. set the format. The implementation is another matter.

What particularly does concern me in this patchset is:

- struct media_pipe is intended to be allocated by drivers embedded in
  another struct holding information the driver needs related to the
  pipeline. Moving this struct to struct video_device prevents this, which
  translates to v4l_enable_media_source() and v4l_disable_media_source()
  functions the patchset adds being specific to the au0828 driver. They
  should be part of that driver, and may not be part of the V4L2 core.
  struct media_pipe may not be added to struct video_device for the same
  reason.

- The IOCTL handlers in v4l2-ioctl.c already call driver-settable callbacks
  before this set. It looks like redundant callbacks are added there as
  ell. The same appears to be true for the VB2 callback. Could you use the
  existing callbacks instead of creating new ones?

As a short term solution, I propose moving the code to the au0828 driver.
Once it is there, we can see whether it could be made more generic if there
is a need for it elsewhere. I believe so. Support atomic pipeline
configuration and startup is a generic problem that requires a generic
solution: we should have a way to construct a pipeline and prevent other
users from messing with it before it's started. But as currently implemented
by this patchset, it is very specific to the au0828 driver and as such may
not be added to the V4L2 or the MC frameworks.

-- 
Best regards,

Sakari Ailus
e-mail: sakari.ailus@iki.fi	XMPP: sailus@retiisi.org.uk

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v3 06/22] media: Media Controller enable/disable source handler API
  2016-03-13 20:11       ` Sakari Ailus
@ 2016-03-14 15:22         ` Shuah Khan
  2016-03-17  9:30           ` Sakari Ailus
  0 siblings, 1 reply; 49+ messages in thread
From: Shuah Khan @ 2016-03-14 15:22 UTC (permalink / raw)
  To: Sakari Ailus
  Cc: mchehab, tiwai, clemens, hans.verkuil, laurent.pinchart,
	sakari.ailus, javier, pawel, m.szyprowski, kyungmin.park, perex,
	arnd, dan.carpenter, tvboxspy, crope, ruchandani.tina, corbet,
	chehabrafael, k.kozlowski, stefanr, inki.dae, jh1009.sung,
	elfring, prabhakar.csengg, sw0312.kim, p.zabel, ricardo.ribalda,
	labbott, pierre-louis.bossart, ricard.wanderlof, julian,
	takamichiho, dominic.sacre, misterpib, daniel, gtmkramer,
	normalperson, joe, linuxbugs, johan, klock.android, nenggun.kim,
	j.anaszewski, geliangtang, albert, linux-kernel, linux-media,
	alsa-devel, Shuah Khan

On 03/13/2016 02:11 PM, Sakari Ailus wrote:
> Hi Shuah,
> 
> On Thu, Mar 10, 2016 at 07:29:59AM -0700, Shuah Khan wrote:
>> On 03/10/2016 12:35 AM, Sakari Ailus wrote:
>>> Hi Shuah,
>>>
>>> On Thu, Feb 11, 2016 at 04:41:22PM -0700, Shuah Khan wrote:
>>>> Add new fields to struct media_device to add enable_source, and
>>>> disable_source handlers, and source_priv to stash driver private
>>>> data that is used to run these handlers. The enable_source handler
>>>> finds source entity for the passed in entity and checks if it is
>>>> available. When link is found, it activates it. Disable source
>>>> handler deactivates the link.
>>>>
>>>> Bridge driver is expected to implement and set these handlers.
>>>>
>>>> Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
>>>> ---
>>>>  include/media/media-device.h | 30 ++++++++++++++++++++++++++++++
>>>>  1 file changed, 30 insertions(+)
>>>>
>>>> diff --git a/include/media/media-device.h b/include/media/media-device.h
>>>> index 075a482..1a04644 100644
>>>> --- a/include/media/media-device.h
>>>> +++ b/include/media/media-device.h
>>>> @@ -302,6 +302,11 @@ struct media_entity_notify {
>>>>   * @entity_notify: List of registered entity_notify callbacks
>>>>   * @lock:	Entities list lock
>>>>   * @graph_mutex: Entities graph operation lock
>>>> + *
>>>> + * @source_priv: Driver Private data for enable/disable source handlers
>>>> + * @enable_source: Enable Source Handler function pointer
>>>> + * @disable_source: Disable Source Handler function pointer
>>>> + *
>>>>   * @link_notify: Link state change notification callback
>>>>   *
>>>>   * This structure represents an abstract high-level media device. It allows easy
>>>> @@ -313,6 +318,26 @@ struct media_entity_notify {
>>>>   *
>>>>   * @model is a descriptive model name exported through sysfs. It doesn't have to
>>>>   * be unique.
>>>> + *
>>>> + * @enable_source is a handler to find source entity for the
>>>> + * sink entity  and activate the link between them if source
>>>> + * entity is free. Drivers should call this handler before
>>>> + * accessing the source.
>>>> + *
>>>> + * @disable_source is a handler to find source entity for the
>>>> + * sink entity  and deactivate the link between them. Drivers
>>>> + * should call this handler to release the source.
>>>> + *
>>>
>>> Is there a particular reason you're not simply (de)activating the link, but
>>> instead add a new callback?
>>
>> These two handlers are separate for a couple of reasons:
>>
>> 1. Explicit and symmetric API is easier to use and maintain.
>>    Similar what we do in other cases, register/unregister
>>    get/put etc.
> 
> Link state is set explicitly (enabled or disabled). This is certainly not a
> reason to create a redundant API for link setup.
> 
>> 2. This is more important. Disable handler makes sure the
>>    owner is releasing the resource. Otherwise, when some
>>    other application does enable, the owner could loose
>>    the resource, if enable and disable are the same.
>>
>>    e.g: Video app is holding the resource, DVB app does
>>    enable. Disable handler makes sure Video/owner  is the one
>>    that is asking to do the release.
> 
> Based on the later patches in this set, the enable_source() callback of the 
> au0828 driver performs three things:
> 
> - Find the source entity,
> - Enable the link from some au0828 entity to the source and
> - Start the pipeline that begins from the I/O device node. The pipe object
>   is embedded in struct video_device.
> 
> disable_source() undoes this in reverse order.
> 
> That's in the au0828 driver and rightly so.
> 
> Then it gets murkier. enable_source() and disable_source() callbacks
> (through a few turns) will get called from v4l2-ioctl.c functions
> v4l_querycap, v4l_s_fmt, v4l_s_frequency, v4l_s_std and v4l_querystd. This
> is also performed in VB2 core vb2_core_streamon() function.
> 
> I certainly have no objections when it comes to blocking other processes
> from setting the format when a process holding a file handle to a device has
> e.g. set the format. The implementation is another matter.
> 
> What particularly does concern me in this patchset is:
> 
> - struct media_pipe is intended to be allocated by drivers embedded in
>   another struct holding information the driver needs related to the
>   pipeline. Moving this struct to struct video_device prevents this, which
>   translates to v4l_enable_media_source() and v4l_disable_media_source()
>   functions the patchset adds being specific to the au0828 driver. They
>   should be part of that driver, and may not be part of the V4L2 core.
>   struct media_pipe may not be added to struct video_device for the same
>   reason.

This media_pipe is associated with struct video_device though. I don't
understand your concern. I am viewing this media_pipe as part of the
registered video_device. video_device struct is in the au0828 device
and gets registered as a whole including the media_pipe 

> 
> - The IOCTL handlers in v4l2-ioctl.c already call driver-settable callbacks
>   before this set. It looks like redundant callbacks are added there as
>   ell. The same appears to be true for the VB2 callback. Could you use the
>   existing callbacks instead of creating new ones?

If I understand correctly, you are suggesting that the calls to enable
and disable source should be made from the au0828 hooks. e.g vidioc_s_std()

Calling them from v4l2-core makes it generic and works on all drivers
without driver changes. That is the rationale for making adding v4l2
common interfaces v4l_enable_media_source() and v4l_disable_media_source()

> 
> As a short term solution, I propose moving the code to the au0828 driver.
> Once it is there, we can see whether it could be made more generic if there
> is a need for it elsewhere. I believe so. Support atomic pipeline
> configuration and startup is a generic problem that requires a generic
> solution: we should have a way to construct a pipeline and prevent other
> users from messing with it before it's started. But as currently implemented
> by this patchset, it is very specific to the au0828 driver and as such may
> not be added to the V4L2 or the MC frameworks.
> 

The enable and disable handlers themselves are for a good reason. These are
handlers that get called from dvb-core, v4l2-core via the common interfaces.
These also get called from sound driver from the media_device. All of this is
generic. Could you please elaborate on which part is au0828 driver specific
other than the media_pipe in struct video_device?

thanks,
-- Shuah

-- 
Shuah Khan
Sr. Linux Kernel Developer
Open Source Innovation Group
Samsung Research America (Silicon Valley)
shuahkh@osg.samsung.com | (970) 217-8978

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v3 06/22] media: Media Controller enable/disable source handler API
  2016-03-14 15:22         ` Shuah Khan
@ 2016-03-17  9:30           ` Sakari Ailus
  0 siblings, 0 replies; 49+ messages in thread
From: Sakari Ailus @ 2016-03-17  9:30 UTC (permalink / raw)
  To: Shuah Khan
  Cc: mchehab, tiwai, clemens, hans.verkuil, laurent.pinchart,
	sakari.ailus, javier, pawel, m.szyprowski, kyungmin.park, perex,
	arnd, dan.carpenter, tvboxspy, crope, ruchandani.tina, corbet,
	chehabrafael, k.kozlowski, stefanr, inki.dae, jh1009.sung,
	elfring, prabhakar.csengg, sw0312.kim, p.zabel, ricardo.ribalda,
	labbott, pierre-louis.bossart, ricard.wanderlof, julian,
	takamichiho, dominic.sacre, misterpib, daniel, gtmkramer,
	normalperson, joe, linuxbugs, johan, klock.android, nenggun.kim,
	j.anaszewski, geliangtang, albert, linux-kernel, linux-media,
	alsa-devel

Hi Shuah,

I see that the patches have been merged to media-tree.git master and
subsequently a pull request has been sent to Linus including them, but the
remaining issues still need to be fixed. Some matters should be discussed
further on the list.

On Mon, Mar 14, 2016 at 09:22:12AM -0600, Shuah Khan wrote:
> On 03/13/2016 02:11 PM, Sakari Ailus wrote:
> > Hi Shuah,
> > 
> > On Thu, Mar 10, 2016 at 07:29:59AM -0700, Shuah Khan wrote:
> >> On 03/10/2016 12:35 AM, Sakari Ailus wrote:
> >>> Hi Shuah,
> >>>
> >>> On Thu, Feb 11, 2016 at 04:41:22PM -0700, Shuah Khan wrote:
> >>>> Add new fields to struct media_device to add enable_source, and
> >>>> disable_source handlers, and source_priv to stash driver private
> >>>> data that is used to run these handlers. The enable_source handler
> >>>> finds source entity for the passed in entity and checks if it is
> >>>> available. When link is found, it activates it. Disable source
> >>>> handler deactivates the link.
> >>>>
> >>>> Bridge driver is expected to implement and set these handlers.
> >>>>
> >>>> Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
> >>>> ---
> >>>>  include/media/media-device.h | 30 ++++++++++++++++++++++++++++++
> >>>>  1 file changed, 30 insertions(+)
> >>>>
> >>>> diff --git a/include/media/media-device.h b/include/media/media-device.h
> >>>> index 075a482..1a04644 100644
> >>>> --- a/include/media/media-device.h
> >>>> +++ b/include/media/media-device.h
> >>>> @@ -302,6 +302,11 @@ struct media_entity_notify {
> >>>>   * @entity_notify: List of registered entity_notify callbacks
> >>>>   * @lock:	Entities list lock
> >>>>   * @graph_mutex: Entities graph operation lock
> >>>> + *
> >>>> + * @source_priv: Driver Private data for enable/disable source handlers
> >>>> + * @enable_source: Enable Source Handler function pointer
> >>>> + * @disable_source: Disable Source Handler function pointer
> >>>> + *
> >>>>   * @link_notify: Link state change notification callback
> >>>>   *
> >>>>   * This structure represents an abstract high-level media device. It allows easy
> >>>> @@ -313,6 +318,26 @@ struct media_entity_notify {
> >>>>   *
> >>>>   * @model is a descriptive model name exported through sysfs. It doesn't have to
> >>>>   * be unique.
> >>>> + *
> >>>> + * @enable_source is a handler to find source entity for the
> >>>> + * sink entity  and activate the link between them if source
> >>>> + * entity is free. Drivers should call this handler before
> >>>> + * accessing the source.
> >>>> + *
> >>>> + * @disable_source is a handler to find source entity for the
> >>>> + * sink entity  and deactivate the link between them. Drivers
> >>>> + * should call this handler to release the source.
> >>>> + *
> >>>
> >>> Is there a particular reason you're not simply (de)activating the link, but
> >>> instead add a new callback?
> >>
> >> These two handlers are separate for a couple of reasons:
> >>
> >> 1. Explicit and symmetric API is easier to use and maintain.
> >>    Similar what we do in other cases, register/unregister
> >>    get/put etc.
> > 
> > Link state is set explicitly (enabled or disabled). This is certainly not a
> > reason to create a redundant API for link setup.
> > 
> >> 2. This is more important. Disable handler makes sure the
> >>    owner is releasing the resource. Otherwise, when some
> >>    other application does enable, the owner could loose
> >>    the resource, if enable and disable are the same.
> >>
> >>    e.g: Video app is holding the resource, DVB app does
> >>    enable. Disable handler makes sure Video/owner  is the one
> >>    that is asking to do the release.
> > 
> > Based on the later patches in this set, the enable_source() callback of the 
> > au0828 driver performs three things:
> > 
> > - Find the source entity,
> > - Enable the link from some au0828 entity to the source and
> > - Start the pipeline that begins from the I/O device node. The pipe object
> >   is embedded in struct video_device.
> > 
> > disable_source() undoes this in reverse order.
> > 
> > That's in the au0828 driver and rightly so.
> > 
> > Then it gets murkier. enable_source() and disable_source() callbacks
> > (through a few turns) will get called from v4l2-ioctl.c functions
> > v4l_querycap, v4l_s_fmt, v4l_s_frequency, v4l_s_std and v4l_querystd. This
> > is also performed in VB2 core vb2_core_streamon() function.
> > 
> > I certainly have no objections when it comes to blocking other processes
> > from setting the format when a process holding a file handle to a device has
> > e.g. set the format. The implementation is another matter.
> > 
> > What particularly does concern me in this patchset is:
> > 
> > - struct media_pipe is intended to be allocated by drivers embedded in
> >   another struct holding information the driver needs related to the
> >   pipeline. Moving this struct to struct video_device prevents this, which
> >   translates to v4l_enable_media_source() and v4l_disable_media_source()
> >   functions the patchset adds being specific to the au0828 driver. They
> >   should be part of that driver, and may not be part of the V4L2 core.
> >   struct media_pipe may not be added to struct video_device for the same
> >   reason.
> 
> This media_pipe is associated with struct video_device though. I don't
> understand your concern. I am viewing this media_pipe as part of the
> registered video_device. video_device struct is in the au0828 device

That is another problem --- this approach excludes pipelines with multiple
video nodes in them. It's not uncommon to have more than one video device in
a pipeline nowadays, e.g. omap3isp driver has that in memory-to-memory
processing.

Other ISPs also have more than one memory output in a single pipeline, that
omap3isp driver could technically support as well.

If you look at the struct media_pipeline, it was an empty struct until a
month or so ago. Drivers embed this struct in their own data structures.

> and gets registered as a whole including the media_pipe 
> 
> > 
> > - The IOCTL handlers in v4l2-ioctl.c already call driver-settable callbacks
> >   before this set. It looks like redundant callbacks are added there as
> >   ell. The same appears to be true for the VB2 callback. Could you use the
> >   existing callbacks instead of creating new ones?
> 
> If I understand correctly, you are suggesting that the calls to enable
> and disable source should be made from the au0828 hooks. e.g vidioc_s_std()
> 
> Calling them from v4l2-core makes it generic and works on all drivers
> without driver changes. That is the rationale for making adding v4l2
> common interfaces v4l_enable_media_source() and v4l_disable_media_source()
> 
> > 
> > As a short term solution, I propose moving the code to the au0828 driver.
> > Once it is there, we can see whether it could be made more generic if there
> > is a need for it elsewhere. I believe so. Support atomic pipeline
> > configuration and startup is a generic problem that requires a generic
> > solution: we should have a way to construct a pipeline and prevent other
> > users from messing with it before it's started. But as currently implemented
> > by this patchset, it is very specific to the au0828 driver and as such may
> > not be added to the V4L2 or the MC frameworks.
> > 
> 
> The enable and disable handlers themselves are for a good reason. These are
> handlers that get called from dvb-core, v4l2-core via the common interfaces.
> These also get called from sound driver from the media_device. All of this is
> generic. Could you please elaborate on which part is au0828 driver specific
> other than the media_pipe in struct video_device?

As far as I understand, you intend to prevent changing e.g. format or input
after a user holding e.g. a file handle to a video node open by other
processes. The au0828 driver does this by configuring the links and starting
the pipeline from the driver itself.

That solution does solve the problem in some special cases (I presume au0828
driver at least), but how about drivers that support the V4L2 sub-device
API? If you start the pipeline based on VIDIOC_S_FMT, for instance, that
also prevents changing the V4L2 sub-device formats along that pipeline.
There is no requirement that the V4L2 sub-device formats in a pipeline must
be set before the V4L2 formats.

Should VIDIOC_S_FMT, for example, have that kind of behaviour? The question
is closely related to the more generic question of how do you prevent other
processes from changing a pipeline (links, V4L2 sub-device formats,
selections or V4L2 formats etc.) while it's being configured. So far that
hasn't been done elsewhere than on video nodes, and not all drivers
implemeted that. I'd like to have at least Hans's and Laurent's opinion on
that. I think the idea is good in principle.

This should be considered together with existing mechanisms. The V4L2 spec
says that:

	Application Priority
	
	When multiple applications share a device it may be desirable to
	assign them different priorities. Contrary to the traditional "rm
	-rf /" school of thought a video recording application could for
	example block other applications from changing video controls or
	switching the current TV channel. Another objective is to permit
	low priority applications working in background, which can be
	preempted by user controlled applications and automatically regain
	control of the device at a later time.
	
	Since these features cannot be implemented entirely in user space
	V4L2 defines the VIDIOC_G_PRIORITY and VIDIOC_S_PRIORITY ioctls to
	request and query the access priority associate with a file
	descriptor. Opening a device assigns a medium priority, compatible
	with earlier versions of V4L2 and drivers not supporting these
	ioctls. Applications requiring a different priority will usually
	call VIDIOC_S_PRIORITY after verifying the device with the
	VIDIOC_QUERYCAP ioctl.
	
	Ioctls changing driver properties, such as VIDIOC_S_INPUT, return an
	EBUSY error code after another application obtained higher priority.

	<URL:http://hverkuil.home.xs4all.nl/spec/media.html#app-pri>

Setting the input should thus be possible unless another application (file
handle) has a higher priority.

It would be good to write an RFC on the topic so that it's easier for
everyone to understand the underlying technical problems and the intended
way to resolve those issues (once there is one).

In order to make your solution generic, it should also

1. Support pipelines with multiple video nodes in them.

2. Assuming people find extending (and implementing them where
implementation is missing) the current priority mechanisms, provide a way to
prevent other processes from changing configuration of V4L2/MC/V4L2
sub-device nodes (links, V4L2 sub-device formats, selections or V4L2 formats
etc.). The au0828 implementation should be in line with this.

-- 
Kind regards,

Sakari Ailus
e-mail: sakari.ailus@iki.fi	XMPP: sailus@retiisi.org.uk

^ permalink raw reply	[flat|nested] 49+ messages in thread

end of thread, other threads:[~2016-03-17  9:30 UTC | newest]

Thread overview: 49+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-11 23:41 [PATCH v3 00/22] Sharing media resources across ALSA and au0828 drivers Shuah Khan
2016-02-11 23:41 ` [PATCH v3 01/22] [media] Docbook: media-types.xml: Add ALSA Media Controller Intf types Shuah Khan
2016-02-17 12:19   ` Mauro Carvalho Chehab
2016-02-17 14:59     ` Shuah Khan
2016-02-26 19:28     ` Shuah Khan
2016-02-11 23:41 ` [PATCH v3 02/22] uapi/media.h: Declare interface types for ALSA Shuah Khan
2016-02-17 12:21   ` Mauro Carvalho Chehab
2016-02-26 19:30     ` Shuah Khan
2016-02-26 19:38       ` Takashi Iwai
2016-03-03 14:59   ` Hans Verkuil
2016-03-03 15:57     ` Shuah Khan
2016-02-11 23:41 ` [PATCH v3 03/22] [media] Docbook: media-types.xml: Add Audio Function Entities Shuah Khan
2016-02-17 12:23   ` Mauro Carvalho Chehab
2016-02-26 19:40     ` Takashi Iwai
     [not found]   ` <1886674.Y0SDWvK9bd@avalon>
2016-03-03 22:50     ` Shuah Khan
2016-02-11 23:41 ` [PATCH v3 04/22] media: Add ALSA Media Controller function entities Shuah Khan
2016-02-17 12:25   ` Mauro Carvalho Chehab
2016-02-26 19:40     ` Takashi Iwai
2016-02-11 23:41 ` [PATCH v3 05/22] media: Media Controller register/unregister entity_notify API Shuah Khan
2016-02-11 23:41 ` [PATCH v3 06/22] media: Media Controller enable/disable source handler API Shuah Khan
2016-03-10  7:35   ` Sakari Ailus
2016-03-10 14:29     ` Shuah Khan
2016-03-13 20:11       ` Sakari Ailus
2016-03-14 15:22         ` Shuah Khan
2016-03-17  9:30           ` Sakari Ailus
2016-02-11 23:41 ` [PATCH v3 07/22] media: Media Controller export non locking __media_entity_setup_link() Shuah Khan
2016-02-11 23:41 ` [PATCH v3 08/22] media: Media Controller non-locking __media_entity_pipeline_start/stop() Shuah Khan
2016-02-11 23:41 ` [PATCH v3 09/22] media: v4l-core add enable/disable source common interfaces Shuah Khan
2016-02-11 23:41 ` [PATCH v3 10/22] media: Move au8522_media_pads enum to au8522.h from au8522_priv.h Shuah Khan
2016-02-11 23:41 ` [PATCH v3 11/22] media: au8522 change to create MC pad for ALSA Audio Out Shuah Khan
2016-02-11 23:41 ` [PATCH v3 12/22] media: au0828 Use au8522_media_pads enum for pad defines Shuah Khan
2016-02-11 23:41 ` [PATCH v3 13/22] media: Change v4l-core to check if source is free Shuah Khan
2016-02-11 23:41 ` [PATCH v3 14/22] media: au0828 change to use Managed Media Controller API Shuah Khan
2016-02-11 23:41 ` [PATCH v3 15/22] media: au0828 handle media_init and media_register window Shuah Khan
2016-02-11 23:41 ` [PATCH v3 16/22] media: au0828 create tuner to decoder link in disabled state Shuah Khan
2016-02-11 23:41 ` [PATCH v3 17/22] media: au0828 disable tuner to demod link Shuah Khan
2016-02-11 23:41 ` [PATCH v3 18/22] media: au0828-core register entity_notify hook Shuah Khan
2016-02-11 23:41 ` [PATCH v3 19/22] media: au0828 add enable, disable source handlers Shuah Khan
2016-02-11 23:41 ` [PATCH v3 20/22] media: dvb-frontend invoke enable/disable_source handlers Shuah Khan
2016-02-11 23:41 ` [PATCH v3 21/22] media: au0828 video change to use v4l_enable_media_source() Shuah Khan
2016-02-11 23:41 ` [PATCH v3 22/22] sound/usb: Use Media Controller API to share media resources Shuah Khan
2016-02-26 19:33   ` Shuah Khan
2016-02-26 19:55   ` Takashi Iwai
2016-02-26 20:08     ` Shuah Khan
2016-02-26 20:50       ` Takashi Iwai
2016-02-27  2:55         ` Shuah Khan
2016-02-27  7:48           ` Takashi Iwai
2016-02-27 12:41             ` Mauro Carvalho Chehab
2016-02-29  6:01             ` Shuah Khan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).