From patchwork Tue Oct 14 14:58:39 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuah Khan X-Patchwork-Id: 5080761 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 78AC5C11AC for ; Tue, 14 Oct 2014 15:01:18 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3CBDC20158 for ; Tue, 14 Oct 2014 15:01:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E07F120148 for ; Tue, 14 Oct 2014 15:01:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932276AbaJNPBJ (ORCPT ); Tue, 14 Oct 2014 11:01:09 -0400 Received: from resqmta-po-07v.sys.comcast.net ([96.114.154.166]:33748 "EHLO resqmta-po-07v.sys.comcast.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932354AbaJNO72 (ORCPT ); Tue, 14 Oct 2014 10:59:28 -0400 Received: from resomta-po-17v.sys.comcast.net ([96.114.154.241]) by resqmta-po-07v.sys.comcast.net with comcast id 32zD1p0045Clt1L012zTG7; Tue, 14 Oct 2014 14:59:27 +0000 Received: from mail.gonehiking.org ([50.134.149.16]) by resomta-po-17v.sys.comcast.net with comcast id 32zS1p00d0MU7Qa012zTjc; Tue, 14 Oct 2014 14:59:27 +0000 Received: from lorien.sisa.samsung.com (lorien-wl.internal [192.168.1.40]) by mail.gonehiking.org (Postfix) with ESMTP id 900BA40A47; Tue, 14 Oct 2014 08:59:26 -0600 (MDT) From: Shuah Khan To: m.chehab@samsung.com, akpm@linux-foundation.org, gregkh@linuxfoundation.org, crope@iki.fi, olebowle@gmx.com, dheitmueller@kernellabs.com, hverkuil@xs4all.nl, ramakrmu@cisco.com, sakari.ailus@linux.intel.com, laurent.pinchart@ideasonboard.com, perex@perex.cz, tiwai@suse.de, prabhakar.csengg@gmail.com, tim.gardner@canonical.com, linux@eikelenboom.it Cc: Shuah Khan , linux-media@vger.kernel.org, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/6] media: au0828-video changes to use media token api Date: Tue, 14 Oct 2014 08:58:39 -0600 Message-Id: <297d2639063811813ba259d873ee722441d0fa41.1413246372.git.shuahkh@osg.samsung.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: References: In-Reply-To: References: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcast.net; s=q20140121; t=1413298767; bh=gyNCqbl5BP3FtVPsLftM7seME0+lSSBVmyaND8HngCY=; h=Received:Received:Received:From:To:Subject:Date:Message-Id; b=cCB2EPThb5RBcU9qmJ389HCsPZb0gzdkq3lrZAMPeqLWpoxJY2LLMXNglukmciY+B vwY4mbKy25AbWETwwERE18iv2TrFcifCsZhB4eQRRLJyESumMXHH0TBAso7m2JmpXL izujHehRAYZDyyk5wiMjDNhKzhVV8V4eYhgKnCCcY7DRDvJBjrpr8FbNX0fnX2OBrd nGQH/gF5km78tVQP70+zkRUZXkQIZibZI8a3BRrRjejHRT41tiyGRxijVasUcHleQh 7RLEapTv0DgDCdrz+GijRms9pKlMou14E87wrqY8zhPW3qJaot11ndmJ036z3J7CJW BIasZPbvbVb6A== Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID,T_RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP au0828-video driver uses vb1 api and needs changes to vb1 v4l2 interfaces that change the tuner status. In addition to that this driver initializes the tuner from a some ioctls that are query (read) tuner status. These ioctls are changed to hold the tuner and audio tokens to avoid disrupting digital stream if active. Further more, release v4l2_file_operations powers down the tuner. The following changes are made: read, poll v4l2_file_operations: - hold tuner and audio tokens - return leaving tuner and audio tokens locked vb1 streamon: - hold tuner and audio tokens - return leaving tuner and audio tokens locked release v4l2_file_operations: - hold tuner and audio tokens before power down Don't call s_power when tuner is busy Note that media_get_tuner_tkn() will do a get on audio token and return with both tuner and audio tokens locked. When tuner token released using media_put_tuner_tkn() , audio token is released. Initialize dev_parent field struct video_device to enable media tuner token lookup from v4l2-core. Signed-off-by: Shuah Khan --- drivers/media/usb/au0828/au0828-video.c | 42 ++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/drivers/media/usb/au0828/au0828-video.c b/drivers/media/usb/au0828/au0828-video.c index 5f337b1..931e736 100644 --- a/drivers/media/usb/au0828/au0828-video.c +++ b/drivers/media/usb/au0828/au0828-video.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -1085,10 +1086,21 @@ static int au0828_v4l2_close(struct file *filp) au0828_uninit_isoc(dev); + ret = media_get_tuner_tkn(&dev->usbdev->dev); + if (ret) { + dev_info(&dev->usbdev->dev, + "%s: Tuner is busy\n", __func__); + /* don't touch tuner - avoid putting to sleep step */ + goto skip_s_power; + } + dev_info(&dev->usbdev->dev, "%s: Putting tuner to sleep\n", + __func__); /* Save some power by putting tuner to sleep */ v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_power, 0); - dev->std_set_in_tuner_core = 0; + media_put_tuner_tkn(&dev->usbdev->dev); +skip_s_power: + dev->std_set_in_tuner_core = 0; /* When close the device, set the usb intf0 into alt0 to free USB bandwidth */ ret = usb_set_interface(dev->usbdev, 0, 0); @@ -1136,6 +1148,12 @@ static ssize_t au0828_v4l2_read(struct file *filp, char __user *buf, if (rc < 0) return rc; + /* don't put the tuner token - this case is same as STREAMON */ + rc = media_get_tuner_tkn(&dev->usbdev->dev); + if (rc) { + dev_info(&dev->usbdev->dev, "%s: Tuner is busy\n", __func__); + return -EBUSY; + } if (mutex_lock_interruptible(&dev->lock)) return -ERESTARTSYS; au0828_init_tuner(dev); @@ -1177,6 +1195,12 @@ static unsigned int au0828_v4l2_poll(struct file *filp, poll_table *wait) if (check_dev(dev) < 0) return POLLERR; + /* don't put the tuner token - this case is same as STREAMON */ + res = media_get_tuner_tkn(&dev->usbdev->dev); + if (res) { + dev_info(&dev->usbdev->dev, "%s: Tuner is busy\n", __func__); + return -EBUSY; + } res = v4l2_ctrl_poll(filp, wait); if (!(req_events & (POLLIN | POLLRDNORM))) return res; @@ -1548,10 +1572,17 @@ static int vidioc_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t) { struct au0828_fh *fh = priv; struct au0828_dev *dev = fh->dev; + int ret; if (t->index != 0) return -EINVAL; + ret = media_get_tuner_tkn(&dev->usbdev->dev); + if (ret) { + dev_info(&dev->usbdev->dev, "%s: Tuner is busy\n", __func__); + return -EBUSY; + } + strcpy(t->name, "Auvitek tuner"); au0828_init_tuner(dev); @@ -1682,6 +1713,12 @@ static int vidioc_streamon(struct file *file, void *priv, dprintk(1, "vidioc_streamon fh=%p t=%d fh->res=%d dev->res=%d\n", fh, type, fh->resources, dev->resources); + rc = media_get_tuner_tkn(&dev->usbdev->dev); + if (rc) { + dev_info(&dev->usbdev->dev, "%s: Tuner is busy\n", __func__); + return -EBUSY; + } + if (unlikely(!res_get(fh, get_ressource(fh)))) return -EBUSY; @@ -2083,12 +2120,15 @@ int au0828_analog_register(struct au0828_dev *dev, dev->vdev->v4l2_dev = &dev->v4l2_dev; dev->vdev->lock = &dev->lock; strcpy(dev->vdev->name, "au0828a video"); + /* there is no way to deduce parent from v4l2_dev */ + dev->vdev->dev_parent = &dev->usbdev->dev; /* Setup the VBI device */ *dev->vbi_dev = au0828_video_template; dev->vbi_dev->v4l2_dev = &dev->v4l2_dev; dev->vbi_dev->lock = &dev->lock; strcpy(dev->vbi_dev->name, "au0828a vbi"); + dev->vbi_dev->dev_parent = &dev->usbdev->dev; /* Register the v4l2 device */ video_set_drvdata(dev->vdev, dev);