From patchwork Tue Jun 24 23:57:29 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuah Khan X-Patchwork-Id: 4414901 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 7851A9F1D6 for ; Tue, 24 Jun 2014 23:58:00 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8643720120 for ; Tue, 24 Jun 2014 23:57:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6BFF420379 for ; Tue, 24 Jun 2014 23:57:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753835AbaFXX54 (ORCPT ); Tue, 24 Jun 2014 19:57:56 -0400 Received: from qmta02.emeryville.ca.mail.comcast.net ([76.96.30.24]:38566 "EHLO qmta02.emeryville.ca.mail.comcast.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753775AbaFXX5y (ORCPT ); Tue, 24 Jun 2014 19:57:54 -0400 Received: from omta08.emeryville.ca.mail.comcast.net ([76.96.30.12]) by qmta02.emeryville.ca.mail.comcast.net with comcast id JPbH1o0030FhH24A2Pxupb; Tue, 24 Jun 2014 23:57:54 +0000 Received: from mail.gonehiking.org ([50.134.149.16]) by omta08.emeryville.ca.mail.comcast.net with comcast id JPxr1o00c0MU7Qa8UPxsAl; Tue, 24 Jun 2014 23:57:53 +0000 Received: from lorien.sisa.samsung.com (lorien-wl.internal [192.168.1.40]) by mail.gonehiking.org (Postfix) with ESMTP id 47B214064C; Tue, 24 Jun 2014 17:57:51 -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 2/4] media: dvb-fe changes to use tuner token Date: Tue, 24 Jun 2014 17:57:29 -0600 Message-Id: <610ef2cd4bbb8a6ccbf16d78f2a0088b5b2d8b23.1403652043.git.shuah.kh@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=1403654274; bh=XhAzwZSz2S9fLBEgniC8FR6enqJllE0ulEcNW4HYcIw=; h=Received:Received:Received:From:To:Subject:Date:Message-Id; b=eHmvaBzIsEZkb58039mX1egbwZ5d3eVmMIF41RF46PoqfMvTxBIG3g9HrO6/5Ly64 R63pswwbCUraZ5M6L6K+KiBXgsroIVTd1PfObm54Myb7fiMxj3RLy+M4r8cBsTZkDb BNcGBR4iUUSbjSlyJMUKtVkD1eWNgaGY0itksB6zj05MoqBHRfd1njwwpt1CA69GBf LBO7Vc18XSHj6W2QsaMSeciqbeJa49bT6PeZ6ziIbq0Y9weoyrRRnwtomd+0gybwO6 uskR4A/QlgYjgHKexXniOcHfOWgxJ4EQe9Ztr9Eipy0xcr5ZUC9EDLqHxp6EoGR/3N ft3Kb4QQkN6ig== 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 dvb_frontend. 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 dvb_frontend to lock tuner token for exclusive access to tuner function for digital TV function use. When Tuner token is present, dvb_frontend_start() calls devm_token_lock() to lock the token. If token is busy, -EBUSY is returned to the user-space. Tuner token is unlocked if kdvb adapter fe kthread fails to start. This token is held in use as long as the kdvb adapter fe kthread is running. Tuner token is unlocked in dvb_frontend_thread() when kdvb adapter fe thread exits. Signed-off-by: Shuah Khan --- drivers/media/dvb-core/dvb_frontend.c | 21 +++++++++++++++++++++ drivers/media/dvb-core/dvb_frontend.h | 1 + 2 files changed, 22 insertions(+) diff --git a/drivers/media/dvb-core/dvb_frontend.c b/drivers/media/dvb-core/dvb_frontend.c index 6cc2631..37d3a4e 100644 --- a/drivers/media/dvb-core/dvb_frontend.c +++ b/drivers/media/dvb-core/dvb_frontend.c @@ -41,6 +41,7 @@ #include #include #include +#include #include "dvb_frontend.h" #include "dvbdev.h" @@ -747,6 +748,11 @@ restart: if (semheld) up(&fepriv->sem); dvb_frontend_wakeup(fe); + + if (fe->tuner_tkn) { + devm_token_unlock(fe->dvb->device, fe->tuner_tkn); + dev_info(fe->dvb->device, "dvb: Tuner is unlocked\n"); + } return 0; } @@ -840,6 +846,17 @@ static int dvb_frontend_start(struct dvb_frontend *fe) fepriv->state = FESTATE_IDLE; fepriv->exit = DVB_FE_NO_EXIT; fepriv->thread = NULL; + + if (fe->tuner_tkn) { + ret = devm_token_lock(fe->dvb->device, fe->tuner_tkn); + if (ret) { + dev_info(fe->dvb->device, + "dvb: Tuner is busy %d\n", ret); + return ret; + } + dev_info(fe->dvb->device, "dvb: Tuner is locked\n"); + } + mb(); fe_thread = kthread_run(dvb_frontend_thread, fe, @@ -850,6 +867,10 @@ static int dvb_frontend_start(struct dvb_frontend *fe) "dvb_frontend_start: failed to start kthread (%d)\n", ret); up(&fepriv->sem); + if (fe->tuner_tkn) { + devm_token_unlock(fe->dvb->device, fe->tuner_tkn); + dev_info(fe->dvb->device, "dvb: Tuner is unlocked\n"); + } return ret; } fepriv->thread = fe_thread; diff --git a/drivers/media/dvb-core/dvb_frontend.h b/drivers/media/dvb-core/dvb_frontend.h index 371b6ca..c9ba5fd 100644 --- a/drivers/media/dvb-core/dvb_frontend.h +++ b/drivers/media/dvb-core/dvb_frontend.h @@ -418,6 +418,7 @@ struct dvb_frontend { #define DVB_FRONTEND_COMPONENT_DEMOD 1 int (*callback)(void *adapter_priv, int component, int cmd, int arg); int id; + char *tuner_tkn; }; extern int dvb_register_frontend(struct dvb_adapter *dvb,