From patchwork Fri Oct 2 22:07:30 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuah Khan X-Patchwork-Id: 7320251 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id B9EA59F32B for ; Sat, 3 Oct 2015 07:31:59 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id ACC0220851 for ; Sat, 3 Oct 2015 07:31:58 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 40AB9207D9 for ; Sat, 3 Oct 2015 07:31:57 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 66707266CDE; Sat, 3 Oct 2015 09:31:56 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_LOW, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id E71E6266A2B; Sat, 3 Oct 2015 09:23:12 +0200 (CEST) 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 34E462669FE; Sat, 3 Oct 2015 00:08:26 +0200 (CEST) Received: from resqmta-po-10v.sys.comcast.net (resqmta-po-10v.sys.comcast.net [96.114.154.169]) by alsa0.perex.cz (Postfix) with ESMTP id 5166B2669B9 for ; Sat, 3 Oct 2015 00:07:46 +0200 (CEST) Received: from resomta-po-05v.sys.comcast.net ([96.114.154.229]) by resqmta-po-10v.sys.comcast.net with comcast id QN7g1r00M4xDoy801N7msi; Fri, 02 Oct 2015 22:07:46 +0000 Received: from mail.gonehiking.org ([73.181.52.62]) by resomta-po-05v.sys.comcast.net with comcast id QN7f1r0081LXgTt01N7lGs; Fri, 02 Oct 2015 22:07:45 +0000 Received: from lorien.internal (lorien-wl.internal [192.168.1.40]) by mail.gonehiking.org (Postfix) with ESMTP id D1963A153D; Fri, 2 Oct 2015 16:07:44 -0600 (MDT) From: Shuah Khan To: mchehab@osg.samsung.com, hans.verkuil@cisco.com, laurent.pinchart@ideasonboard.com, sakari.ailus@linux.intel.com, tiwai@suse.de, pawel@osciak.com, m.szyprowski@samsung.com, kyungmin.park@samsung.com, perex@perex.cz, dan.carpenter@oracle.com, tskd08@gmail.com, arnd@arndb.de, ruchandani.tina@gmail.com, corbet@lwn.net, k.kozlowski@samsung.com, chehabrafael@gmail.com, prabhakar.csengg@gmail.com, elfring@users.sourceforge.net, Julia.Lawall@lip6.fr, p.zabel@pengutronix.de, ricardo.ribalda@gmail.com, labbott@fedoraproject.org, chris.j.arges@canonical.com, pierre-louis.bossart@linux.intel.com, johan@oljud.se, wsa@the-dreams.de, jcragg@gmail.com, clemens@ladisch.de, daniel@zonque.org, gtmkramer@xs4all.nl, misterpib@gmail.com, takamichiho@gmail.com, pmatilai@laiskiainen.org, vladcatoi@gmail.com, damien@zamaudio.com, normalperson@yhbt.net, joe@oampo.co.uk, jussi@sonarnerd.net, calcprogrammer1@gmail.com Date: Fri, 2 Oct 2015 16:07:30 -0600 Message-Id: <5f3004783b21f44d93ae0f12ff7f53f1f0c61107.1443822799.git.shuahkh@osg.samsung.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: References: In-Reply-To: References: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcast.net; s=q20140121; t=1443823666; bh=bZN5fss7QMmMdzzBts2Xz2tBMSTUHgnFuH/Jiw/OVTs=; h=Received:Received:Received:From:To:Subject:Date:Message-Id; b=rcHwafDGB8uSN5iUdf8gtNKQ5Ybo+DaPJ8tvdh/es/4yWgMiwgiET2BhM/AqIz2fo spfs9yrOnHfMSzklOB5D+eUv+1JFjCDvtCP/FYeJGUQpHnUNhkzfkJehUgVNrk1JL6 G9FHa7y9dMs1VpMSkY3nnSbOUk0tQ/TKysWdr0aYHmOPC/h+3trUJ+h+GiaxxG99ks L9xjW7GbE+plyzvtRn/aFitLP6YHtt+emdFAzRfFH75q2E9I9FPlmdtZv9X+6mS9Qv V8NGXy5wWhSdBQE4Q6JmOYhjXDZXdKttCx149C6pWKOnZaad3UkUfN+6oDwOAoTqQk pHWH9+nMrN/YQ== X-Mailman-Approved-At: Sat, 03 Oct 2015 09:23:02 +0200 Cc: alsa-devel@alsa-project.org, Shuah Khan , linux-media@vger.kernel.org Subject: [alsa-devel] [PATCH MC Next Gen 18/20] media: au0828 implement enable_source and disable_source handlers 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: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP Implements enable_source and disable_source handlers for other drivers (v4l2-core, dvb-core, and ALSA) to use to check for tuner connected to the decoder and activate the link if tuner is free, and deactivate and free the tuner when it is no longer needed. Signed-off-by: Shuah Khan --- drivers/media/usb/au0828/au0828-core.c | 149 ++++++++++++++++++++++++++++++++- drivers/media/usb/au0828/au0828.h | 2 + 2 files changed, 149 insertions(+), 2 deletions(-) diff --git a/drivers/media/usb/au0828/au0828-core.c b/drivers/media/usb/au0828/au0828-core.c index ade89d9..7af5d0d 100644 --- a/drivers/media/usb/au0828/au0828-core.c +++ b/drivers/media/usb/au0828/au0828-core.c @@ -256,9 +256,9 @@ void au0828_create_media_graph(struct media_entity *new, void *notify_data) if (tuner && !dev->tuner_linked) { dev->tuner = tuner; + /* create tuner to decoder link in deactivated state */ ret = media_create_pad_link(tuner, TUNER_PAD_IF_OUTPUT, - decoder, 0, - MEDIA_LNK_FL_ENABLED); + decoder, 0, 0); if (ret == 0) dev->tuner_linked = 1; } @@ -319,6 +319,146 @@ void au0828_create_media_graph(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; + 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; + + /* for Audio and Video entities, source is the decoder */ + mutex_lock(&mdev->graph_mutex); + + dev = mdev->source_priv; + if (!dev->tuner || !dev->decoder) { + ret = -ENODEV; + goto end; + } + + /* + * For Audio and V4L2 entity, find the link to which decoder + * is the sink. Look for an active link between decoder and + * tuner, if one exists, nothing to do. If not, look for any + * active links between tuner and any other entity. If one + * exists, tuner is busy. If tuner is free, setup link and + * start pipeline from source (tuner). + * 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 = dev->decoder; + else + sink = entity; + + /* Is an active link between sink and tuner */ + if (dev->active_link) { + if (dev->active_link->sink->entity == sink && + dev->active_link->source->entity == dev->tuner) { + 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 == dev->tuner) { + 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("Deactive 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; +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 + struct media_entity *sink; + 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->tuner || !dev->decoder || !dev->active_link) { + ret = -ENODEV; + goto end; + } + + if (entity->function != MEDIA_ENT_F_DTV_DEMOD) + sink = dev->decoder; + else + sink = entity; + + /* link is active - stop pipeline from source (tuner) */ + if (dev->active_link && dev->active_link->sink->entity == sink && + dev->active_link->source->entity == dev->tuner) { + /* 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("Deactive link Error %d\n", ret); + dev->active_link = NULL; + dev->active_link_owner = NULL; + } + +end: + mutex_unlock(&mdev->graph_mutex); +#endif +} + static void au0828_media_device_register(struct au0828_dev *dev, struct usb_device *udev) { @@ -355,6 +495,11 @@ static void au0828_media_device_register(struct au0828_dev *dev, dev->entity_notify.notify = au0828_create_media_graph; media_device_register_entity_notify(mdev, &dev->entity_notify); + /* set enable_source */ + mdev->source_priv = (void *) dev; + mdev->enable_source = au0828_enable_source; + mdev->disable_source = au0828_disable_source; + dev->media_dev = mdev; #endif } diff --git a/drivers/media/usb/au0828/au0828.h b/drivers/media/usb/au0828/au0828.h index 3874906f..2f4d597 100644 --- a/drivers/media/usb/au0828/au0828.h +++ b/drivers/media/usb/au0828/au0828.h @@ -288,6 +288,8 @@ struct au0828_dev { bool vdev_linked; bool vbi_linked; bool audio_capture_linked; + struct media_link *active_link; + struct media_entity *active_link_owner; #endif };