From patchwork Fri Jan 2 11:48:43 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guennadi Liakhovetski X-Patchwork-Id: 5558861 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.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 33F2E9F2ED for ; Fri, 2 Jan 2015 11:48:56 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3309120256 for ; Fri, 2 Jan 2015 11:48:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2887E2024D for ; Fri, 2 Jan 2015 11:48:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752064AbbABLsw (ORCPT ); Fri, 2 Jan 2015 06:48:52 -0500 Received: from mout.gmx.net ([212.227.17.20]:49547 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751947AbbABLsv (ORCPT ); Fri, 2 Jan 2015 06:48:51 -0500 Received: from axis700.grange ([87.79.96.210]) by mail.gmx.com (mrgmx103) with ESMTPSA (Nemesis) id 0Lx8ZJ-1XnTdM00b3-016fcA; Fri, 02 Jan 2015 12:48:45 +0100 Received: by axis700.grange (Postfix, from userid 1000) id D02A440BDB; Fri, 2 Jan 2015 12:48:43 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by axis700.grange (Postfix) with ESMTP id CD5E540BD9; Fri, 2 Jan 2015 12:48:43 +0100 (CET) Date: Fri, 2 Jan 2015 12:48:43 +0100 (CET) From: Guennadi Liakhovetski X-X-Sender: lyakh@axis700.grange To: Linux Media Mailing List cc: Josh Wu , Laurent Pinchart Subject: [PATCH 2/2] V4L2: add CCF support to the v4l2_clk API In-Reply-To: Message-ID: References: MIME-Version: 1.0 X-Provags-ID: V03:K0:gVywC4l8jsvyuwnyZ54kvuPdo29Y3+DfmcxI/7iqkxPEYJXRhEb 9GTXK/I+/lc8DIk8O14i4deQlKmuAze43ntBwz0SV4gU8nJiJ7kEj+iNO93LkZUK4GMKnbn zCkHVJw6aj9Rpo9CKNKimokvE9ikBc74wBuyldEPWk10Y5qcNwVuaujZ8RSq3trSmnItcPR m8QrugtBxF50p7CT9h9xw== X-UI-Out-Filterresults: notjunk:1; Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00,FREEMAIL_FROM, MALFORMED_FREEMAIL, RCVD_IN_DNSWL_HI, 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 V4L2 clocks, e.g. used by camera sensors for their master clock, do not have to be supplied by a different V4L2 driver, they can also be supplied by an independent source. In this case the standart kernel clock API should be used to handle such clocks. This patch adds support for such cases. Signed-off-by: Guennadi Liakhovetski --- drivers/media/v4l2-core/v4l2-clk.c | 76 +++++++++++++++++++++++++++++++++----- include/media/v4l2-clk.h | 2 + 2 files changed, 68 insertions(+), 10 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-clk.c b/drivers/media/v4l2-core/v4l2-clk.c index c210906..693e5a0 100644 --- a/drivers/media/v4l2-core/v4l2-clk.c +++ b/drivers/media/v4l2-core/v4l2-clk.c @@ -9,6 +9,7 @@ */ #include +#include #include #include #include @@ -39,9 +40,24 @@ static struct v4l2_clk *v4l2_clk_find(const char *dev_id, const char *id) return ERR_PTR(-ENODEV); } +static int v4l2_clk_add(struct v4l2_clk *clk, const char *dev_id, + const char *id) +{ + mutex_lock(&clk_lock); + if (!IS_ERR(v4l2_clk_find(dev_id, id))) { + mutex_unlock(&clk_lock); + return -EEXIST; + } + list_add_tail(&clk->list, &clk_list); + mutex_unlock(&clk_lock); + + return 0; +} + struct v4l2_clk *v4l2_clk_get(struct device *dev, const char *id) { struct v4l2_clk *clk; + struct clk *ccf_clk = clk_get(dev, id); mutex_lock(&clk_lock); clk = v4l2_clk_find(dev_name(dev), id); @@ -50,6 +66,22 @@ struct v4l2_clk *v4l2_clk_get(struct device *dev, const char *id) atomic_inc(&clk->use_count); mutex_unlock(&clk_lock); + if (!IS_ERR(ccf_clk) && IS_ERR(clk)) { + /* not yet on the list */ + clk = kzalloc(sizeof(struct v4l2_clk), GFP_KERNEL); + if (clk) + clk->id = kstrdup(id, GFP_KERNEL); + if (!clk || !clk->id) { + kfree(clk); + clk_put(ccf_clk); + return ERR_PTR(-ENOMEM); + } + clk->clk = ccf_clk; + atomic_set(&clk->use_count, 1); + + v4l2_clk_add(clk, dev_name(dev), id); + } + return clk; } EXPORT_SYMBOL(v4l2_clk_get); @@ -67,6 +99,15 @@ void v4l2_clk_put(struct v4l2_clk *clk) if (tmp == clk) atomic_dec(&clk->use_count); + if (clk->clk) { + clk_put(clk->clk); + if (!atomic_read(&clk->use_count)) { + list_del(&clk->list); + kfree(clk->id); + kfree(clk); + } + } + mutex_unlock(&clk_lock); } EXPORT_SYMBOL(v4l2_clk_put); @@ -98,8 +139,12 @@ static void v4l2_clk_unlock_driver(struct v4l2_clk *clk) int v4l2_clk_enable(struct v4l2_clk *clk) { - int ret = v4l2_clk_lock_driver(clk); + int ret; + + if (clk->clk) + return clk_enable(clk->clk); + ret = v4l2_clk_lock_driver(clk); if (ret < 0) return ret; @@ -125,6 +170,9 @@ void v4l2_clk_disable(struct v4l2_clk *clk) { int enable; + if (clk->clk) + return clk_disable(clk->clk); + mutex_lock(&clk->lock); enable = --clk->enable; @@ -142,8 +190,12 @@ EXPORT_SYMBOL(v4l2_clk_disable); unsigned long v4l2_clk_get_rate(struct v4l2_clk *clk) { - int ret = v4l2_clk_lock_driver(clk); + int ret; + if (clk->clk) + return clk_get_rate(clk->clk); + + ret = v4l2_clk_lock_driver(clk); if (ret < 0) return ret; @@ -162,7 +214,16 @@ EXPORT_SYMBOL(v4l2_clk_get_rate); int v4l2_clk_set_rate(struct v4l2_clk *clk, unsigned long rate) { - int ret = v4l2_clk_lock_driver(clk); + int ret; + + if (clk->clk) { + long r = clk_round_rate(clk->clk, rate); + if (r < 0) + return r; + return clk_set_rate(clk->clk, r); + } + + ret = v4l2_clk_lock_driver(clk); if (ret < 0) return ret; @@ -204,14 +265,9 @@ struct v4l2_clk *v4l2_clk_register(const struct v4l2_clk_ops *ops, atomic_set(&clk->use_count, 0); mutex_init(&clk->lock); - mutex_lock(&clk_lock); - if (!IS_ERR(v4l2_clk_find(dev_id, NULL))) { - mutex_unlock(&clk_lock); - ret = -EEXIST; + ret = v4l2_clk_add(clk, dev_id, NULL); + if (ret < 0) goto eexist; - } - list_add_tail(&clk->list, &clk_list); - mutex_unlock(&clk_lock); return clk; diff --git a/include/media/v4l2-clk.h b/include/media/v4l2-clk.h index 8f06967..4402b2d 100644 --- a/include/media/v4l2-clk.h +++ b/include/media/v4l2-clk.h @@ -22,6 +22,7 @@ struct module; struct device; +struct clk; struct v4l2_clk { struct list_head list; const struct v4l2_clk_ops *ops; @@ -30,6 +31,7 @@ struct v4l2_clk { int enable; struct mutex lock; /* Protect the enable count */ atomic_t use_count; + struct clk *clk; void *priv; };