From patchwork Mon Sep 22 15:00:47 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuah Khan X-Patchwork-Id: 4948361 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 31B869F2BB for ; Mon, 22 Sep 2014 15:08:18 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C8E9920172 for ; Mon, 22 Sep 2014 15:08:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F35A92010E for ; Mon, 22 Sep 2014 15:08:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754159AbaIVPHR (ORCPT ); Mon, 22 Sep 2014 11:07:17 -0400 Received: from resqmta-po-11v.sys.comcast.net ([96.114.154.170]:59081 "EHLO resqmta-po-11v.sys.comcast.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754144AbaIVPHO (ORCPT ); Mon, 22 Sep 2014 11:07:14 -0400 Received: from resomta-po-04v.sys.comcast.net ([96.114.154.228]) by resqmta-po-11v.sys.comcast.net with comcast id uF171o0034vw8ds01F18uv; Mon, 22 Sep 2014 15:01:08 +0000 Received: from mail.gonehiking.org ([50.134.149.16]) by resomta-po-04v.sys.comcast.net with comcast id uF151o00T0MU7Qa01F16bu; Mon, 22 Sep 2014 15:01:08 +0000 Received: from lorien.internal (lorien-wl.internal [192.168.1.40]) by mail.gonehiking.org (Postfix) with ESMTP id B0B2A3FF0F; Mon, 22 Sep 2014 09:01:05 -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.co, hverkuil@xs4all.nl, ramakrmu@cisco.com, sakari.ailus@linux.intel.com, laurent.pinchart@ideasonboard.com Cc: Shuah Khan , linux-kernel@vger.kernel.org, linux-media@vger.kernel.org Subject: [PATCH 3/5] media: au0828-video changes to use media tuner token api Date: Mon, 22 Sep 2014 09:00:47 -0600 Message-Id: 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=1411398068; bh=FrNhCrmgnMr8pHzdjKpnP7FZE5lcpaUQg+VbCkkbcIc=; h=Received:Received:Received:From:To:Subject:Date:Message-Id; b=Y+5GsXVl0LooI2fBqXT4s8f5R3uLJ8Ld6/UsecS7DFRw3Rp5AdqoWesGF81tC8dhl MCGlt5PqLLUD0QwEi5n3PpFJXoyMW2uzvtf1wA6tUjGVEDeqYhJU5HrUEH1lHq2g0V qkZ2BZKtua5p4gfN/dT4aAlNLUzFissPM2LiFd0FY5mytopZUckDIP09+lvEIQpIOr rnrtql9W7xdsZ/6UbAu9tZY9RADF1upJeIcUG7s3n/syBePBqWjs7hnsgaFej0FNDm acDthZCzuBLGwXObJiiGdTmWPIa287Vx/IG2TW2VyG5MmYXoK86PYbZ/lYn/TPkUrp XHuzpaNG6hzTg== Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,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 token 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 in shared analog mode - return leaving tuner in shared mode vb1 streamon: - hold tuner in shared analog mode - return leaving tuner in shared mode release v4l2_file_operations: - hold tuner in exclusive analog mode to power down. Don't call s_power when tuner is busy. 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 | 43 ++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/drivers/media/usb/au0828/au0828-video.c b/drivers/media/usb/au0828/au0828-video.c index 5f337b1..52a3644 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, MEDIA_MODE_ANALOG); + if (ret) { + dev_info(&dev->usbdev->dev, + "%s: Tuner is busy\n", __func__); + /* don't touch tuner and usb device interface */ + 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, MEDIA_MODE_ANALOG); +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_shared_tuner_tkn(&dev->usbdev->dev, MEDIA_MODE_ANALOG); + 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_shared_tuner_tkn(&dev->usbdev->dev, MEDIA_MODE_ANALOG); + 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,16 +1572,24 @@ 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_shared_tuner_tkn(&dev->usbdev->dev, MEDIA_MODE_ANALOG); + if (ret) { + dev_info(&dev->usbdev->dev, "%s: Tuner is busy\n", __func__); + return -EBUSY; + } + strcpy(t->name, "Auvitek tuner"); au0828_init_tuner(dev); i2c_gate_ctrl(dev, 1); v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, g_tuner, t); i2c_gate_ctrl(dev, 0); + media_put_tuner_tkn(&dev->usbdev->dev, MEDIA_MODE_ANALOG); return 0; } @@ -1682,6 +1714,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_shared_tuner_tkn(&dev->usbdev->dev, MEDIA_MODE_ANALOG); + 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 +2121,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);