Message ID | Pine.LNX.4.64.1502011211160.9534@axis700.grange (mailing list archive) |
---|---|
State | Superseded, archived |
Delegated to: | Guennadi Liakhovetski |
Headers |
Received: from mail.tu-berlin.de ([130.149.7.33]) by www.linuxtv.org with esmtp (Exim 4.72) (envelope-from <linux-media-owner@vger.kernel.org>) id 1YHsSI-0006VI-RP; Sun, 01 Feb 2015 12:12:42 +0100 X-tubIT-Incoming-IP: 209.132.180.67 Received: from vger.kernel.org ([209.132.180.67]) by mail.tu-berlin.de (exim-4.72/mailfrontend-5) with esmtp id 1YHsSG-0003gu-8C; Sun, 01 Feb 2015 12:12:42 +0100 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752800AbbBALMi (ORCPT <rfc822;mkrufky@linuxtv.org> + 1 other); Sun, 1 Feb 2015 06:12:38 -0500 Received: from mout.gmx.net ([212.227.15.19]:56407 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752605AbbBALMh (ORCPT <rfc822;linux-media@vger.kernel.org>); Sun, 1 Feb 2015 06:12:37 -0500 Received: from axis700.grange ([87.79.47.147]) by mail.gmx.com (mrgmx001) with ESMTPSA (Nemesis) id 0M5Lqx-1XS7mn2vKp-00zXnF; Sun, 01 Feb 2015 12:12:34 +0100 Received: by axis700.grange (Postfix, from userid 1000) id 57F1240BDB; Sun, 1 Feb 2015 12:12:33 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by axis700.grange (Postfix) with ESMTP id 50D9140BD9; Sun, 1 Feb 2015 12:12:33 +0100 (CET) Date: Sun, 1 Feb 2015 12:12:33 +0100 (CET) From: Guennadi Liakhovetski <g.liakhovetski@gmx.de> X-X-Sender: lyakh@axis700.grange To: Laurent Pinchart <laurent.pinchart@ideasonboard.com> cc: Linux Media Mailing List <linux-media@vger.kernel.org>, Josh Wu <josh.wu@atmel.com> Subject: [PATCH v4 2/2] V4L: add CCF support to the v4l2_clk API In-Reply-To: <8420980.1Z1tGTCX4O@avalon> Message-ID: <Pine.LNX.4.64.1502011211160.9534@axis700.grange> References: <Pine.LNX.4.64.1502010007180.26661@axis700.grange> <Pine.LNX.4.64.1502010019380.26661@axis700.grange> <8420980.1Z1tGTCX4O@avalon> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Provags-ID: V03:K0:/+9b4mTTZugdl5CaUUNwxJu2ndxTDfmPKLxNxb44hxqFhD8BLcb 4aQO91e+5BLwO032YlGNvg06VYfPL9fP5gpXenvKba80SEP/s8ahcoP3rMXLSV7lYdZcHtA wAzBRFm46A0Azx3+CBpXAWNjEGHBMhuQX1zTsG9f/cZfPJFWuIcfPy8OAp/6yRG7+hi51Wi qoMjjwDJQZMLt5LGYZP2g== X-UI-Out-Filterresults: notjunk:1; Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: <linux-media.vger.kernel.org> X-Mailing-List: linux-media@vger.kernel.org X-PMX-Version: 6.0.0.2142326, Antispam-Engine: 2.7.2.2107409, Antispam-Data: 2015.2.1.110023 X-PMX-Spam: Gauge=IIIIIIIII, Probability=9%, Report=' MULTIPLE_RCPTS 0.1, HTML_00_01 0.05, HTML_00_10 0.05, MSGID_ADDED_BY_MTA 0.05, BODY_SIZE_3000_3999 0, BODY_SIZE_5000_LESS 0, BODY_SIZE_7000_LESS 0, REFERENCES 0, URI_ENDS_IN_HTML 0, __ANY_URI 0, __CP_URI_IN_BODY 0, __CT 0, __CT_TEXT_PLAIN 0, __FRAUD_BODY_WEBMAIL 0, __FRAUD_WEBMAIL 0, __FRAUD_WEBMAIL_FROM 0, __HAS_FROM 0, __HAS_MSGID 0, __HAS_X_MAILING_LIST 0, __IN_REP_TO 0, __MIME_TEXT_ONLY 0, __MIME_VERSION 0, __MULTIPLE_RCPTS_CC_X2 0, __PHISH_SPEAR_STRUCTURE_1 0, __REFERENCES 0, __SANE_MSGID 0, __SUBJ_ALPHA_END 0, __TO_MALFORMED_2 0, __URI_NO_WWW 0, __URI_NS ' |
Commit Message
Guennadi Liakhovetski
Feb. 1, 2015, 11:12 a.m. UTC
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 <g.liakhovetski@gmx.de> Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> --- v4: sizeof(*clk) :) drivers/media/v4l2-core/v4l2-clk.c | 48 +++++++++++++++++++++++++++++++++++--- include/media/v4l2-clk.h | 2 ++ 2 files changed, 47 insertions(+), 3 deletions(-)
Comments
Hi, Guennadi On 2/1/2015 7:12 PM, Guennadi Liakhovetski wrote: > 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 <g.liakhovetski@gmx.de> > Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Thanks for the patch. Tested-by: Josh Wu <josh.wu@atmel.com> Best Regards, Josh Wu > --- > > v4: sizeof(*clk) :) > > drivers/media/v4l2-core/v4l2-clk.c | 48 +++++++++++++++++++++++++++++++++++--- > include/media/v4l2-clk.h | 2 ++ > 2 files changed, 47 insertions(+), 3 deletions(-) > > diff --git a/drivers/media/v4l2-core/v4l2-clk.c b/drivers/media/v4l2-core/v4l2-clk.c > index 3ff0b00..9f8cb20 100644 > --- a/drivers/media/v4l2-core/v4l2-clk.c > +++ b/drivers/media/v4l2-core/v4l2-clk.c > @@ -9,6 +9,7 @@ > */ > > #include <linux/atomic.h> > +#include <linux/clk.h> > #include <linux/device.h> > #include <linux/errno.h> > #include <linux/list.h> > @@ -37,6 +38,21 @@ static struct v4l2_clk *v4l2_clk_find(const char *dev_id) > struct v4l2_clk *v4l2_clk_get(struct device *dev, const char *id) > { > struct v4l2_clk *clk; > + struct clk *ccf_clk = clk_get(dev, id); > + > + if (PTR_ERR(ccf_clk) == -EPROBE_DEFER) > + return ERR_PTR(-EPROBE_DEFER); > + > + if (!IS_ERR_OR_NULL(ccf_clk)) { > + clk = kzalloc(sizeof(*clk), GFP_KERNEL); > + if (!clk) { > + clk_put(ccf_clk); > + return ERR_PTR(-ENOMEM); > + } > + clk->clk = ccf_clk; > + > + return clk; > + } > > mutex_lock(&clk_lock); > clk = v4l2_clk_find(dev_name(dev)); > @@ -56,6 +72,12 @@ void v4l2_clk_put(struct v4l2_clk *clk) > if (IS_ERR(clk)) > return; > > + if (clk->clk) { > + clk_put(clk->clk); > + kfree(clk); > + return; > + } > + > mutex_lock(&clk_lock); > > list_for_each_entry(tmp, &clk_list, list) > @@ -93,8 +115,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_prepare_enable(clk->clk); > + > + ret = v4l2_clk_lock_driver(clk); > if (ret < 0) > return ret; > > @@ -120,6 +146,9 @@ void v4l2_clk_disable(struct v4l2_clk *clk) > { > int enable; > > + if (clk->clk) > + return clk_disable_unprepare(clk->clk); > + > mutex_lock(&clk->lock); > > enable = --clk->enable; > @@ -137,8 +166,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; > > @@ -157,7 +190,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; > diff --git a/include/media/v4l2-clk.h b/include/media/v4l2-clk.h > index 928045f..3ef6e3d 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; > @@ -29,6 +30,7 @@ struct v4l2_clk { > int enable; > struct mutex lock; /* Protect the enable count */ > atomic_t use_count; > + struct clk *clk; > void *priv; > }; > -- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Em Sun, 1 Feb 2015 12:12:33 +0100 (CET) Guennadi Liakhovetski <g.liakhovetski@gmx.de> escreveu: > 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 <g.liakhovetski@gmx.de> > Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> > --- > > v4: sizeof(*clk) :) > > drivers/media/v4l2-core/v4l2-clk.c | 48 +++++++++++++++++++++++++++++++++++--- > include/media/v4l2-clk.h | 2 ++ > 2 files changed, 47 insertions(+), 3 deletions(-) > > diff --git a/drivers/media/v4l2-core/v4l2-clk.c b/drivers/media/v4l2-core/v4l2-clk.c > index 3ff0b00..9f8cb20 100644 > --- a/drivers/media/v4l2-core/v4l2-clk.c > +++ b/drivers/media/v4l2-core/v4l2-clk.c > @@ -9,6 +9,7 @@ > */ > > #include <linux/atomic.h> > +#include <linux/clk.h> > #include <linux/device.h> > #include <linux/errno.h> > #include <linux/list.h> > @@ -37,6 +38,21 @@ static struct v4l2_clk *v4l2_clk_find(const char *dev_id) > struct v4l2_clk *v4l2_clk_get(struct device *dev, const char *id) > { > struct v4l2_clk *clk; > + struct clk *ccf_clk = clk_get(dev, id); > + > + if (PTR_ERR(ccf_clk) == -EPROBE_DEFER) > + return ERR_PTR(-EPROBE_DEFER); Why not do just: return ccf_clk; > + > + if (!IS_ERR_OR_NULL(ccf_clk)) { > + clk = kzalloc(sizeof(*clk), GFP_KERNEL); > + if (!clk) { > + clk_put(ccf_clk); > + return ERR_PTR(-ENOMEM); > + } > + clk->clk = ccf_clk; > + > + return clk; > + } The error condition here looks a little weird to me. I mean, if the CCF clock returns an error, shouldn't it fail instead of silently run some logic to find another clock source? Isn't it risky on getting a wrong value? If the above code is right, please add a comment there explaining why it is safe to discard the CCF clock error. > > mutex_lock(&clk_lock); > clk = v4l2_clk_find(dev_name(dev)); > @@ -56,6 +72,12 @@ void v4l2_clk_put(struct v4l2_clk *clk) > if (IS_ERR(clk)) > return; > > + if (clk->clk) { > + clk_put(clk->clk); > + kfree(clk); > + return; > + } > + > mutex_lock(&clk_lock); > > list_for_each_entry(tmp, &clk_list, list) > @@ -93,8 +115,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_prepare_enable(clk->clk); > + > + ret = v4l2_clk_lock_driver(clk); > if (ret < 0) > return ret; > > @@ -120,6 +146,9 @@ void v4l2_clk_disable(struct v4l2_clk *clk) > { > int enable; > > + if (clk->clk) > + return clk_disable_unprepare(clk->clk); > + > mutex_lock(&clk->lock); > > enable = --clk->enable; > @@ -137,8 +166,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; > > @@ -157,7 +190,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; > diff --git a/include/media/v4l2-clk.h b/include/media/v4l2-clk.h > index 928045f..3ef6e3d 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; > @@ -29,6 +30,7 @@ struct v4l2_clk { > int enable; > struct mutex lock; /* Protect the enable count */ > atomic_t use_count; > + struct clk *clk; > void *priv; > }; > -- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Hi Mauro, On Mon Mar 02 2015 18:55:23 GMT+0200 (EET), Mauro Carvalho Chehab wrote: > Em Sun, 1 Feb 2015 12:12:33 +0100 (CET) > Guennadi Liakhovetski <g.liakhovetski@gmx.de> escreveu: > > > 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 <g.liakhovetski@gmx.de> > > Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> > > --- > > > > v4: sizeof(*clk) :) > > > > drivers/media/v4l2-core/v4l2-clk.c | 48 +++++++++++++++++++++++++++++++++++--- > > include/media/v4l2-clk.h | 2 ++ > > 2 files changed, 47 insertions(+), 3 deletions(-) > > > > diff --git a/drivers/media/v4l2-core/v4l2-clk.c b/drivers/media/v4l2-core/v4l2-clk.c > > index 3ff0b00..9f8cb20 100644 > > --- a/drivers/media/v4l2-core/v4l2-clk.c > > +++ b/drivers/media/v4l2-core/v4l2-clk.c > > @@ -9,6 +9,7 @@ > > */ > > > > #include <linux/atomic.h> > > +#include <linux/clk.h> > > #include <linux/device.h> > > #include <linux/errno.h> > > #include <linux/list.h> > > @@ -37,6 +38,21 @@ static struct v4l2_clk *v4l2_clk_find(const char *dev_id) > > struct v4l2_clk *v4l2_clk_get(struct device *dev, const char *id) > > { > > struct v4l2_clk *clk; > > + struct clk *ccf_clk = clk_get(dev, id); > > + > > + if (PTR_ERR(ccf_clk) == -EPROBE_DEFER) > > + return ERR_PTR(-EPROBE_DEFER); > > Why not do just: > return ccf_clk; I find the explicit error slightly more readable, but that's a matter of taste. > > + > > + if (!IS_ERR_OR_NULL(ccf_clk)) { > > + clk = kzalloc(sizeof(*clk), GFP_KERNEL); > > + if (!clk) { > > + clk_put(ccf_clk); > > + return ERR_PTR(-ENOMEM); > > + } > > + clk->clk = ccf_clk; > > + > > + return clk; > > + } > > The error condition here looks a little weird to me. I mean, if the > CCF clock returns an error, shouldn't it fail instead of silently > run some logic to find another clock source? Isn't it risky on getting > a wrong value? The idea is that, in the long term, everything should use CCF directly. However, we have clock providers on platforms where CCF isn't avalaible. V4L2 clock has been introduced as a single API usable by V4L2 clock users allowing them to retrieve and use clocks regardless of whether the provider uses CCF or not. Internally it first tries CCF, and then falls back to the non-CCF implementation in case of failure. > If the above code is right, please add a comment there explaining > why it is safe to discard the CCF clock error. > > > > > mutex_lock(&clk_lock); > > clk = v4l2_clk_find(dev_name(dev)); > > @@ -56,6 +72,12 @@ void v4l2_clk_put(struct v4l2_clk *clk) > > if (IS_ERR(clk)) > > return; > > > > + if (clk->clk) { > > + clk_put(clk->clk); > > + kfree(clk); > > + return; > > + } > > + > > mutex_lock(&clk_lock); > > > > list_for_each_entry(tmp, &clk_list, list) > > @@ -93,8 +115,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_prepare_enable(clk->clk); > > + > > + ret = v4l2_clk_lock_driver(clk); > > if (ret < 0) > > return ret; > > > > @@ -120,6 +146,9 @@ void v4l2_clk_disable(struct v4l2_clk *clk) > > { > > int enable; > > > > + if (clk->clk) > > + return clk_disable_unprepare(clk->clk); > > + > > mutex_lock(&clk->lock); > > > > enable = --clk->enable; > > @@ -137,8 +166,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; > > > > @@ -157,7 +190,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; > > diff --git a/include/media/v4l2-clk.h b/include/media/v4l2-clk.h > > index 928045f..3ef6e3d 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; > > @@ -29,6 +30,7 @@ struct v4l2_clk { > > int enable; > > struct mutex lock; /* Protect the enable count */ > > atomic_t use_count; > > + struct clk *clk; > > void *priv; > > }; > > >
Em Mon, 02 Mar 2015 20:52:41 +0000 laurent.pinchart@ideasonboard.com escreveu: > Hi Mauro, > > On Mon Mar 02 2015 18:55:23 GMT+0200 (EET), Mauro Carvalho Chehab wrote: > > Em Sun, 1 Feb 2015 12:12:33 +0100 (CET) > > Guennadi Liakhovetski <g.liakhovetski@gmx.de> escreveu: > > > > > 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 <g.liakhovetski@gmx.de> > > > Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> > > > --- > > > > > > v4: sizeof(*clk) :) > > > > > > drivers/media/v4l2-core/v4l2-clk.c | 48 +++++++++++++++++++++++++++++++++++--- > > > include/media/v4l2-clk.h | 2 ++ > > > 2 files changed, 47 insertions(+), 3 deletions(-) > > > > > > diff --git a/drivers/media/v4l2-core/v4l2-clk.c b/drivers/media/v4l2-core/v4l2-clk.c > > > index 3ff0b00..9f8cb20 100644 > > > --- a/drivers/media/v4l2-core/v4l2-clk.c > > > +++ b/drivers/media/v4l2-core/v4l2-clk.c > > > @@ -9,6 +9,7 @@ > > > */ > > > > > > #include <linux/atomic.h> > > > +#include <linux/clk.h> > > > #include <linux/device.h> > > > #include <linux/errno.h> > > > #include <linux/list.h> > > > @@ -37,6 +38,21 @@ static struct v4l2_clk *v4l2_clk_find(const char *dev_id) > > > struct v4l2_clk *v4l2_clk_get(struct device *dev, const char *id) > > > { > > > struct v4l2_clk *clk; > > > + struct clk *ccf_clk = clk_get(dev, id); > > > + > > > + if (PTR_ERR(ccf_clk) == -EPROBE_DEFER) > > > + return ERR_PTR(-EPROBE_DEFER); > > > > Why not do just: > > return ccf_clk; > > I find the explicit error slightly more readable, but that's a matter of taste. Well, return(ccf_clk) will likely produce a smaller instruction code than return (long). > > > > + > > > + if (!IS_ERR_OR_NULL(ccf_clk)) { > > > + clk = kzalloc(sizeof(*clk), GFP_KERNEL); > > > + if (!clk) { > > > + clk_put(ccf_clk); > > > + return ERR_PTR(-ENOMEM); > > > + } > > > + clk->clk = ccf_clk; > > > + > > > + return clk; > > > + } > > > > The error condition here looks a little weird to me. I mean, if the > > CCF clock returns an error, shouldn't it fail instead of silently > > run some logic to find another clock source? Isn't it risky on getting > > a wrong value? > > The idea is that, in the long term, everything should use CCF directly. However, we have clock providers on platforms where CCF isn't avalaible. V4L2 clock has been introduced as a single API usable by V4L2 clock users allowing them to retrieve and use clocks regardless of whether the provider uses CCF or not. Internally it first tries CCF, and then falls back to the non-CCF implementation in case of failure. Yeah, I got that the non-CCF is a fallback code, to be used on platforms that CCF isn't available. However, the above code doesn't seem to look if CCF is available or not. Instead, it assumes that *all* error codes, or even NULL, means that CCF isn't available. Shouldn't it be, instead, either waiting for NULL or for some specific error code, in order to: - return the error code, if CCF is available but getting the clock failed; - run the backward-compat code when CCF is not available. Regards, Mauro -- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Hi Mauro, On Tuesday 03 March 2015 13:40:50 Mauro Carvalho Chehab wrote: > Em Mon, 02 Mar 2015 20:52:41 +0000 Laurent Pinchart escreveu: > > On Mon Mar 02 2015 18:55:23 GMT+0200 (EET), Mauro Carvalho Chehab wrote: > >> Em Sun, 1 Feb 2015 12:12:33 +0100 (CET) Guennadi Liakhovetski escreveu: > >>> 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 <g.liakhovetski@gmx.de> > >>> Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> > >>> --- > >>> > >>> v4: sizeof(*clk) :) > >>> > >>> drivers/media/v4l2-core/v4l2-clk.c | 48 ++++++++++++++++++++++++++--- > >>> include/media/v4l2-clk.h | 2 ++ > >>> 2 files changed, 47 insertions(+), 3 deletions(-) > >>> > >>> diff --git a/drivers/media/v4l2-core/v4l2-clk.c > >>> b/drivers/media/v4l2-core/v4l2-clk.c index 3ff0b00..9f8cb20 100644 > >>> --- a/drivers/media/v4l2-core/v4l2-clk.c > >>> +++ b/drivers/media/v4l2-core/v4l2-clk.c [snip] > >>> @@ -37,6 +38,21 @@ static struct v4l2_clk *v4l2_clk_find(const char > >>> *dev_id) > >>> struct v4l2_clk *v4l2_clk_get(struct device *dev, const char *id) > >>> { > >>> struct v4l2_clk *clk; > >>> > >>> + struct clk *ccf_clk = clk_get(dev, id); > >>> + > >>> + if (PTR_ERR(ccf_clk) == -EPROBE_DEFER) > >>> + return ERR_PTR(-EPROBE_DEFER); > >> > >> Why not do just: > >> return ccf_clk; > > > > I find the explicit error slightly more readable, but that's a matter of > > taste. > > Well, return(ccf_clk) will likely produce a smaller instruction code > than return (long). Not if the compiler is smart :-) > >>> + > >>> + if (!IS_ERR_OR_NULL(ccf_clk)) { > >>> + clk = kzalloc(sizeof(*clk), GFP_KERNEL); > >>> + if (!clk) { > >>> + clk_put(ccf_clk); > >>> + return ERR_PTR(-ENOMEM); > >>> + } > >>> + clk->clk = ccf_clk; > >>> + > >>> + return clk; > >>> + } > >> > >> The error condition here looks a little weird to me. I mean, if the > >> CCF clock returns an error, shouldn't it fail instead of silently > >> run some logic to find another clock source? Isn't it risky on getting > >> a wrong value? > > > > The idea is that, in the long term, everything should use CCF directly. > > However, we have clock providers on platforms where CCF isn't avalaible. > > V4L2 clock has been introduced as a single API usable by V4L2 clock > > users allowing them to retrieve and use clocks regardless of whether the > > provider uses CCF or not. Internally it first tries CCF, and then falls > > back to the non-CCF implementation in case of failure. > > Yeah, I got that the non-CCF is a fallback code, to be used on > platforms that CCF isn't available. > > However, the above code doesn't seem to look if CCF is available > or not. Instead, it assumes that *all* error codes, or even NULL, > means that CCF isn't available. > > Shouldn't it be, instead, either waiting for NULL or for some > specific error code, in order to: > - return the error code, if CCF is available but getting > the clock failed; > - run the backward-compat code when CCF is not available. Isn't that pretty much what the code is doing ? If we get a -EPROBE_DEFER error from CCF meaning that the clock is known but not registered yet we return it. Otherwise, if the clock is unknown to CCF, or if CCF is disabled, we fall back.
Em Wed, 04 Mar 2015 00:56:18 +0200 Laurent Pinchart <laurent.pinchart@ideasonboard.com> escreveu: > Hi Mauro, > > On Tuesday 03 March 2015 13:40:50 Mauro Carvalho Chehab wrote: > > Em Mon, 02 Mar 2015 20:52:41 +0000 Laurent Pinchart escreveu: > > > On Mon Mar 02 2015 18:55:23 GMT+0200 (EET), Mauro Carvalho Chehab wrote: > > >> Em Sun, 1 Feb 2015 12:12:33 +0100 (CET) Guennadi Liakhovetski escreveu: > > >>> 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 <g.liakhovetski@gmx.de> > > >>> Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> > > >>> --- > > >>> > > >>> v4: sizeof(*clk) :) > > >>> > > >>> drivers/media/v4l2-core/v4l2-clk.c | 48 ++++++++++++++++++++++++++--- > > >>> include/media/v4l2-clk.h | 2 ++ > > >>> 2 files changed, 47 insertions(+), 3 deletions(-) > > >>> > > >>> diff --git a/drivers/media/v4l2-core/v4l2-clk.c > > >>> b/drivers/media/v4l2-core/v4l2-clk.c index 3ff0b00..9f8cb20 100644 > > >>> --- a/drivers/media/v4l2-core/v4l2-clk.c > > >>> +++ b/drivers/media/v4l2-core/v4l2-clk.c > > [snip] > > > >>> @@ -37,6 +38,21 @@ static struct v4l2_clk *v4l2_clk_find(const char > > >>> *dev_id) > > >>> struct v4l2_clk *v4l2_clk_get(struct device *dev, const char *id) > > >>> { > > >>> struct v4l2_clk *clk; > > >>> > > >>> + struct clk *ccf_clk = clk_get(dev, id); > > >>> + > > >>> + if (PTR_ERR(ccf_clk) == -EPROBE_DEFER) > > >>> + return ERR_PTR(-EPROBE_DEFER); > > >> > > >> Why not do just: > > >> return ccf_clk; > > > > > > I find the explicit error slightly more readable, but that's a matter of > > > taste. > > > > Well, return(ccf_clk) will likely produce a smaller instruction code > > than return (long). > > Not if the compiler is smart :-) > > > >>> + > > >>> + if (!IS_ERR_OR_NULL(ccf_clk)) { > > >>> + clk = kzalloc(sizeof(*clk), GFP_KERNEL); > > >>> + if (!clk) { > > >>> + clk_put(ccf_clk); > > >>> + return ERR_PTR(-ENOMEM); > > >>> + } > > >>> + clk->clk = ccf_clk; > > >>> + > > >>> + return clk; > > >>> + } > > >> > > >> The error condition here looks a little weird to me. I mean, if the > > >> CCF clock returns an error, shouldn't it fail instead of silently > > >> run some logic to find another clock source? Isn't it risky on getting > > >> a wrong value? > > > > > > The idea is that, in the long term, everything should use CCF directly. > > > However, we have clock providers on platforms where CCF isn't avalaible. > > > V4L2 clock has been introduced as a single API usable by V4L2 clock > > > users allowing them to retrieve and use clocks regardless of whether the > > > provider uses CCF or not. Internally it first tries CCF, and then falls > > > back to the non-CCF implementation in case of failure. > > > > Yeah, I got that the non-CCF is a fallback code, to be used on > > platforms that CCF isn't available. > > > > However, the above code doesn't seem to look if CCF is available > > or not. Instead, it assumes that *all* error codes, or even NULL, > > means that CCF isn't available. > > > > Shouldn't it be, instead, either waiting for NULL or for some > > specific error code, in order to: > > - return the error code, if CCF is available but getting > > the clock failed; > > - run the backward-compat code when CCF is not available. > > Isn't that pretty much what the code is doing ? If we get a -EPROBE_DEFER > error from CCF meaning that the clock is known but not registered yet we > return it. Otherwise, if the clock is unknown to CCF, or if CCF is disabled, > we fall back. I didn't check the CCF code, but couldn't it return error codes like ENOMEM? What are all the error codes it can return ATM? What, among them, can happen when CCF is available? Also, as the CCF code can be changed, if the intent behavior is to only allow EPROBE_DEFER or NULL, if the there is support for CCF, then you need to have an explicit comment there to avoid that any newer patches to add different error codes. IMHO, it seems a way better to define a single error code to be returned when the platform doesn't support CCF (like -ENOTSUPP), and calling the fallback code only in this case. Something like: if (PTR_ERR(ccf_clk) != -ENOTSUPP) return ccf_clk; /* CCF is not supported. Fall back to the old way */ k = kzalloc(sizeof(*clk), GFP_KERNEL); if (!clk) { clk_put(ccf_clk); return ERR_PTR(-ENOMEM); } clk->clk = ccf_clk; return clk; Regards, Mauro -- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Hi Mauro, On Tuesday 03 March 2015 20:21:29 Mauro Carvalho Chehab wrote: > Em Wed, 04 Mar 2015 00:56:18 +0200 Laurent Pinchart escreveu: > > On Tuesday 03 March 2015 13:40:50 Mauro Carvalho Chehab wrote: > >> Em Mon, 02 Mar 2015 20:52:41 +0000 Laurent Pinchart escreveu: > >>> On Mon Mar 02 2015 18:55:23 GMT+0200 (EET), Mauro Carvalho Chehab wrote: > >>>> Em Sun, 1 Feb 2015 12:12:33 +0100 (CET) Guennadi Liakhovetski escreveu: > >>>>> 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 <g.liakhovetski@gmx.de> > >>>>> Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> > >>>>> --- > >>>>> > >>>>> v4: sizeof(*clk) :) > >>>>> > >>>>> drivers/media/v4l2-core/v4l2-clk.c | 48 ++++++++++++++++++++++++--- > >>>>> include/media/v4l2-clk.h | 2 ++ > >>>>> 2 files changed, 47 insertions(+), 3 deletions(-) > >>>>> > >>>>> diff --git a/drivers/media/v4l2-core/v4l2-clk.c > >>>>> b/drivers/media/v4l2-core/v4l2-clk.c index 3ff0b00..9f8cb20 100644 > >>>>> --- a/drivers/media/v4l2-core/v4l2-clk.c > >>>>> +++ b/drivers/media/v4l2-core/v4l2-clk.c > > > > [snip] > > > >>>>> @@ -37,6 +38,21 @@ static struct v4l2_clk *v4l2_clk_find(const char > >>>>> *dev_id) > >>>>> struct v4l2_clk *v4l2_clk_get(struct device *dev, const char *id) > >>>>> { > >>>>> struct v4l2_clk *clk; > >>>>> + struct clk *ccf_clk = clk_get(dev, id); > >>>>> + > >>>>> + if (PTR_ERR(ccf_clk) == -EPROBE_DEFER) > >>>>> + return ERR_PTR(-EPROBE_DEFER); > >>>> > >>>> Why not do just: > >>>> return ccf_clk; > >>> > >>> I find the explicit error slightly more readable, but that's a matter > >>> of taste. > >> > >> Well, return(ccf_clk) will likely produce a smaller instruction code > >> than return (long). > > > > Not if the compiler is smart :-) > > > >>>>> + > >>>>> + if (!IS_ERR_OR_NULL(ccf_clk)) { > >>>>> + clk = kzalloc(sizeof(*clk), GFP_KERNEL); > >>>>> + if (!clk) { > >>>>> + clk_put(ccf_clk); > >>>>> + return ERR_PTR(-ENOMEM); > >>>>> + } > >>>>> + clk->clk = ccf_clk; > >>>>> + > >>>>> + return clk; > >>>>> + } > >>>> > >>>> The error condition here looks a little weird to me. I mean, if the > >>>> CCF clock returns an error, shouldn't it fail instead of silently > >>>> run some logic to find another clock source? Isn't it risky on > >>>> getting a wrong value? > >>> > >>> The idea is that, in the long term, everything should use CCF > >>> directly. However, we have clock providers on platforms where CCF > >>> isn't avalaible. V4L2 clock has been introduced as a single API > >>> usable by V4L2 clock users allowing them to retrieve and use clocks > >>> regardless of whether the provider uses CCF or not. Internally it > >>> first tries CCF, and then falls back to the non-CCF implementation in > >>> case of failure. > >> > >> Yeah, I got that the non-CCF is a fallback code, to be used on > >> platforms that CCF isn't available. > >> > >> However, the above code doesn't seem to look if CCF is available > >> or not. Instead, it assumes that *all* error codes, or even NULL, > >> means that CCF isn't available. > >> > >> Shouldn't it be, instead, either waiting for NULL or for some > >> specific error code, in order to: > >> > >> - return the error code, if CCF is available but getting > >> the clock failed; > >> > >> - run the backward-compat code when CCF is not available. > > > > Isn't that pretty much what the code is doing ? If we get a -EPROBE_DEFER > > error from CCF meaning that the clock is known but not registered yet we > > return it. Otherwise, if the clock is unknown to CCF, or if CCF is > > disabled, we fall back. > > I didn't check the CCF code, but couldn't it return error codes like > ENOMEM? What are all the error codes it can return ATM? What, among > them, can happen when CCF is available? > > Also, as the CCF code can be changed, if the intent behavior is to only > allow EPROBE_DEFER or NULL, if the there is support for CCF, then you > need to have an explicit comment there to avoid that any newer patches > to add different error codes. > > IMHO, it seems a way better to define a single error code to be > returned when the platform doesn't support CCF (like -ENOTSUPP), But that's not how CCF works :-) Regardless of that, note that the clk_get() call is part of the Linux clock API, of which CCF is one implementation. clk_get() is implemented by custom architecture code on platforms where CCF isn't used. The idea of this patch is to - return the platform clock if available (clk_get() returns a non-NULL, non- error pointer) - defer probing if the platform clock requests so - fall back to the internal clocks list I don't see a need for something else. > and calling the fallback code only in this case. Something like: > > if (PTR_ERR(ccf_clk) != -ENOTSUPP) > return ccf_clk; > > /* CCF is not supported. Fall back to the old way */ > k = kzalloc(sizeof(*clk), GFP_KERNEL); > if (!clk) { > clk_put(ccf_clk); > return ERR_PTR(-ENOMEM); > } > clk->clk = ccf_clk; > return clk;
Hi Mauro, On Mon, 2 Mar 2015, Mauro Carvalho Chehab wrote: > Em Sun, 1 Feb 2015 12:12:33 +0100 (CET) > Guennadi Liakhovetski <g.liakhovetski@gmx.de> escreveu: > > > 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 <g.liakhovetski@gmx.de> > > Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> > > --- > > > > v4: sizeof(*clk) :) > > > > drivers/media/v4l2-core/v4l2-clk.c | 48 +++++++++++++++++++++++++++++++++++--- > > include/media/v4l2-clk.h | 2 ++ > > 2 files changed, 47 insertions(+), 3 deletions(-) > > > > diff --git a/drivers/media/v4l2-core/v4l2-clk.c b/drivers/media/v4l2-core/v4l2-clk.c > > index 3ff0b00..9f8cb20 100644 > > --- a/drivers/media/v4l2-core/v4l2-clk.c > > +++ b/drivers/media/v4l2-core/v4l2-clk.c > > @@ -9,6 +9,7 @@ > > */ > > > > #include <linux/atomic.h> > > +#include <linux/clk.h> > > #include <linux/device.h> > > #include <linux/errno.h> > > #include <linux/list.h> > > @@ -37,6 +38,21 @@ static struct v4l2_clk *v4l2_clk_find(const char *dev_id) > > struct v4l2_clk *v4l2_clk_get(struct device *dev, const char *id) > > { > > struct v4l2_clk *clk; > > + struct clk *ccf_clk = clk_get(dev, id); > > + > > + if (PTR_ERR(ccf_clk) == -EPROBE_DEFER) > > + return ERR_PTR(-EPROBE_DEFER); > > Why not do just: > return ccf_clk; I would prefer that shorter form too, but the function returns "struct v4l2_clk *" and ccf_clk is "struct clk *" Thanks Guennadi -- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/drivers/media/v4l2-core/v4l2-clk.c b/drivers/media/v4l2-core/v4l2-clk.c index 3ff0b00..9f8cb20 100644 --- a/drivers/media/v4l2-core/v4l2-clk.c +++ b/drivers/media/v4l2-core/v4l2-clk.c @@ -9,6 +9,7 @@ */ #include <linux/atomic.h> +#include <linux/clk.h> #include <linux/device.h> #include <linux/errno.h> #include <linux/list.h> @@ -37,6 +38,21 @@ static struct v4l2_clk *v4l2_clk_find(const char *dev_id) struct v4l2_clk *v4l2_clk_get(struct device *dev, const char *id) { struct v4l2_clk *clk; + struct clk *ccf_clk = clk_get(dev, id); + + if (PTR_ERR(ccf_clk) == -EPROBE_DEFER) + return ERR_PTR(-EPROBE_DEFER); + + if (!IS_ERR_OR_NULL(ccf_clk)) { + clk = kzalloc(sizeof(*clk), GFP_KERNEL); + if (!clk) { + clk_put(ccf_clk); + return ERR_PTR(-ENOMEM); + } + clk->clk = ccf_clk; + + return clk; + } mutex_lock(&clk_lock); clk = v4l2_clk_find(dev_name(dev)); @@ -56,6 +72,12 @@ void v4l2_clk_put(struct v4l2_clk *clk) if (IS_ERR(clk)) return; + if (clk->clk) { + clk_put(clk->clk); + kfree(clk); + return; + } + mutex_lock(&clk_lock); list_for_each_entry(tmp, &clk_list, list) @@ -93,8 +115,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_prepare_enable(clk->clk); + + ret = v4l2_clk_lock_driver(clk); if (ret < 0) return ret; @@ -120,6 +146,9 @@ void v4l2_clk_disable(struct v4l2_clk *clk) { int enable; + if (clk->clk) + return clk_disable_unprepare(clk->clk); + mutex_lock(&clk->lock); enable = --clk->enable; @@ -137,8 +166,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; @@ -157,7 +190,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; diff --git a/include/media/v4l2-clk.h b/include/media/v4l2-clk.h index 928045f..3ef6e3d 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; @@ -29,6 +30,7 @@ struct v4l2_clk { int enable; struct mutex lock; /* Protect the enable count */ atomic_t use_count; + struct clk *clk; void *priv; };