From patchwork Tue Jun 24 23:57:30 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuah Khan X-Patchwork-Id: 4414911 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 69227BEEAA for ; Tue, 24 Jun 2014 23:58:02 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 79A79202D1 for ; Tue, 24 Jun 2014 23:58:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 97D2520120 for ; Tue, 24 Jun 2014 23:58:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753775AbaFXX56 (ORCPT ); Tue, 24 Jun 2014 19:57:58 -0400 Received: from qmta04.emeryville.ca.mail.comcast.net ([76.96.30.40]:58100 "EHLO qmta04.emeryville.ca.mail.comcast.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753807AbaFXX54 (ORCPT ); Tue, 24 Jun 2014 19:57:56 -0400 Received: from omta05.emeryville.ca.mail.comcast.net ([76.96.30.43]) by qmta04.emeryville.ca.mail.comcast.net with comcast id JPui1o0070vp7WLA4PxvHT; Tue, 24 Jun 2014 23:57:55 +0000 Received: from mail.gonehiking.org ([50.134.149.16]) by omta05.emeryville.ca.mail.comcast.net with comcast id JPxt1o00d0MU7Qa8RPxuiC; Tue, 24 Jun 2014 23:57:55 +0000 Received: from lorien.sisa.samsung.com (lorien-wl.internal [192.168.1.40]) by mail.gonehiking.org (Postfix) with ESMTP id E6A5D40885; Tue, 24 Jun 2014 17:57:52 -0600 (MDT) From: Shuah Khan To: gregkh@linuxfoundation.org, m.chehab@samsung.com, olebowle@gmx.com, ttmesterr@gmail.com, dheitmueller@kernellabs.com, cb.xiong@samsung.com, yongjun_wei@trendmicro.com.cn, hans.verkuil@cisco.com, prabhakar.csengg@gmail.com, laurent.pinchart@ideasonboard.com, sakari.ailus@linux.intel.com, crope@iki.fi, wade_farnsworth@mentor.com, ricardo.ribalda@gmail.com Cc: Shuah Khan , linux-media@vger.kernel.org Subject: [PATCH 3/4] media: v4l2-core changes to use tuner token Date: Tue, 24 Jun 2014 17:57:30 -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=1403654275; bh=aCmXPq1YPLLThXqjukOK+UZCesN5aEyL1a0lXgf++GE=; h=Received:Received:Received:From:To:Subject:Date:Message-Id; b=KwmDc11FciCK87i1g85Ow6ZO4m9GngDmCun8WZDtaFhfMSta3x8jK1ujy3qMKpmy+ 4n/gX7JPIa7RO6kHqziJq/wOB1CAlsi+/mnTh5miFZcc7xMUC+0GAcfvvS1GclbEsT U2sYbDJ74Z0SqW5TM4eNDtTFMOQ2nQIz0UWbHHFaBa7B+3MVZ57Vjr67wq4JZpyGHK FF3wsZCJc3kf/P4lfWn1y+DoMkRyfv59ZS3ewFxC8GOrC95CKM/9y62/SFo3AkpnA7 JmdKyXsH+Ofi5E7C/z4LMXreNibw8JQtGBT4jy46/nrKU6/kLc7fOonq99a0ojtrPb nxMoQjAF0sNRA== 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=ham 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 Add a new field tuner_tkn to struct video_device. Drivers can create tuner token using devm_token_create() and initialize the tuner_tkn when frontend is registered with the dvb-core. This change enables drivers to provide a token devres for tuner access control. Change v4l2-core to lock tuner token for exclusive access to tuner function for analog TV function use. When Tuner token is present, v4l2_open() calls devm_token_lock() to lock the token. If token is busy, -EBUSY is returned to the user-space. Tuner token is unlocked in error paths in v4l2_open(). This token is held as long as the v4l2 device is open and unlocked from v4l2_release(). Signed-off-by: Shuah Khan --- drivers/media/v4l2-core/v4l2-dev.c | 23 ++++++++++++++++++++++- include/media/v4l2-dev.h | 1 + 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/drivers/media/v4l2-core/v4l2-dev.c b/drivers/media/v4l2-core/v4l2-dev.c index 634d863..8dff809 100644 --- a/drivers/media/v4l2-core/v4l2-dev.c +++ b/drivers/media/v4l2-core/v4l2-dev.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -445,6 +446,17 @@ static int v4l2_open(struct inode *inode, struct file *filp) mutex_unlock(&videodev_lock); return -ENODEV; } + /* check if tuner is busy first */ + if (vdev->tuner_tkn && vdev->dev_parent) { + ret = devm_token_lock(vdev->dev_parent, vdev->tuner_tkn); + if (ret) { + mutex_unlock(&videodev_lock); + dev_info(vdev->dev_parent, "v4l2: Tuner is busy\n"); + return ret; + } + dev_info(vdev->dev_parent, "v4l2: Tuner is locked\n"); + } + /* and increase the device refcount */ video_get(vdev); mutex_unlock(&videodev_lock); @@ -459,8 +471,13 @@ static int v4l2_open(struct inode *inode, struct file *filp) printk(KERN_DEBUG "%s: open (%d)\n", video_device_node_name(vdev), ret); /* decrease the refcount in case of an error */ - if (ret) + if (ret) { video_put(vdev); + if (vdev->tuner_tkn && vdev->dev_parent) { + devm_token_unlock(vdev->dev_parent, vdev->tuner_tkn); + dev_info(vdev->dev_parent, "v4l2: Tuner is unlocked\n"); + } + } return ret; } @@ -479,6 +496,10 @@ static int v4l2_release(struct inode *inode, struct file *filp) /* decrease the refcount unconditionally since the release() return value is ignored. */ video_put(vdev); + if (vdev->tuner_tkn && vdev->dev_parent) { + devm_token_unlock(vdev->dev_parent, vdev->tuner_tkn); + dev_info(vdev->dev_parent, "v4l2: Tuner is unlocked\n"); + } return ret; } diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h index eec6e46..1676349 100644 --- a/include/media/v4l2-dev.h +++ b/include/media/v4l2-dev.h @@ -141,6 +141,7 @@ struct video_device /* serialization lock */ DECLARE_BITMAP(disable_locking, BASE_VIDIOC_PRIVATE); struct mutex *lock; + char *tuner_tkn; }; #define media_entity_to_video_device(__e) \