From patchwork Thu Jan 24 20:32:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuah X-Patchwork-Id: 10780101 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id ACB3391E for ; Thu, 24 Jan 2019 20:32:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9A14F26B39 for ; Thu, 24 Jan 2019 20:32:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8E1A12E4C8; Thu, 24 Jan 2019 20:32:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8B19526B39 for ; Thu, 24 Jan 2019 20:32:53 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 5BF14267590; Thu, 24 Jan 2019 21:32:51 +0100 (CET) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 8034726785F; Thu, 24 Jan 2019 21:32:49 +0100 (CET) Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by alsa0.perex.cz (Postfix) with ESMTP id F06542674A9 for ; Thu, 24 Jan 2019 21:32:46 +0100 (CET) Received: from shuah-t480s.internal (c-24-9-64-241.hsd1.co.comcast.net [24.9.64.241]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 51D012184C; Thu, 24 Jan 2019 20:32:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548361965; bh=bepO7BCIsiNzv741MrCe8Mnu11JyA/lw4/zL++3auRM=; h=From:To:Cc:Subject:Date:From; b=lYYv0gnYM6njVxpEF46cCPb/1t3zl64kgXBu0WxoyG+q4Dr7FHTpbNoRcMHVWNdnN h8tjUdJTWaM5YYXkvXASHVlRjc2oljyeEkOyUN+3B03Iw1O2Ww9LGD5tSWhCKGg91f Rw0TTzPmNX1E9VrtH4SafA3G6fXyuveG9duVD3Cc= From: Shuah Khan To: mchehab@kernel.org, perex@perex.cz, tiwai@suse.com, hverkuil@xs4all.nl Date: Thu, 24 Jan 2019 13:32:37 -0700 Message-Id: X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 Cc: alsa-devel@alsa-project.org, Shuah Khan , linux-kernel@vger.kernel.org, linux-media@vger.kernel.org Subject: [alsa-devel] [PATCH v10 0/4] Media Device Allocator API X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP Media Device Allocator API to allows multiple drivers share a media device. This API solves a very common use-case for media devices where one physical device (an USB stick) provides both audio and video. When such media device exposes a standard USB Audio class, a proprietary Video class, two or more independent drivers will share a single physical USB bridge. In such cases, it is necessary to coordinate access to the shared resource. Using this API, drivers can allocate a media device with the shared struct device as the key. Once the media device is allocated by a driver, other drivers can get a reference to it. The media device is released when all the references are released. - This patch series is tested on 5.0-rc3 and addresses comments on v9 series from Hans Verkuil. - v9 was tested on 4.20-rc6. - Tested sharing resources with kaffeine, vlc, xawtv, tvtime, and arecord. When analog is streaming, digital and audio user-space applications detect that the tuner is busy and exit. When digital is streaming, analog and audio applications detect that the tuner is busy and exit. When arecord is owns the tuner, digital and analog detect that the tuner is busy and exit. - Tested media device allocator API with bind/unbind testing on snd-usb-audio and au0828 drivers to make sure /dev/mediaX is released only when the last driver is unbound. - Addressed review comments from Hans on the RFC v8 (rebased on 4.19) - Updated change log to describe the use-case more clearly. - No changes to 0001,0002 code since the v7 referenced below. - 0003 is a new patch to enable ALSA defines that have been disabled for kernel between 4.9 and 4.19. - Minor merge conflict resolution in 0004. - Added SPDX to new files. Changes since v9: - Patch 1: Fix mutex assert warning from find_module() calls. This code was written before the change to find_module() that requires callers to hold module_mutex. I missed this during my testing on 4.20-rc6. Hans Verkuil reported the problem. - Patch 4: sound/usb: Initializes all the entities it can before registering the device based on comments from Hans Verkuil - Carried Reviewed-by tag from Takashi Iwai for the sound from v9. - No changes to Patches 2 and 3. References: https://lkml.org/lkml/2018/11/2/169 https://www.mail-archive.com/linux-media@vger.kernel.org/msg105854.html Shuah Khan (4): media: Media Device Allocator API media: change au0828 to use Media Device Allocator API media: media.h: Enable ALSA MEDIA_INTF_T* interface types sound/usb: Use Media Controller API to share media resources Documentation/media/kapi/mc-core.rst | 41 ++++ drivers/media/Makefile | 4 + drivers/media/media-dev-allocator.c | 144 +++++++++++ drivers/media/usb/au0828/au0828-core.c | 12 +- drivers/media/usb/au0828/au0828.h | 1 + include/media/media-dev-allocator.h | 53 ++++ include/uapi/linux/media.h | 25 +- sound/usb/Kconfig | 4 + sound/usb/Makefile | 2 + sound/usb/card.c | 14 ++ sound/usb/card.h | 3 + sound/usb/media.c | 327 +++++++++++++++++++++++++ sound/usb/media.h | 74 ++++++ sound/usb/mixer.h | 3 + sound/usb/pcm.c | 29 ++- sound/usb/quirks-table.h | 1 + sound/usb/stream.c | 2 + sound/usb/usbaudio.h | 6 + 18 files changed, 723 insertions(+), 22 deletions(-) create mode 100644 drivers/media/media-dev-allocator.c create mode 100644 include/media/media-dev-allocator.h create mode 100644 sound/usb/media.c create mode 100644 sound/usb/media.h