From patchwork Wed Feb 19 05:21:25 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mike Turquette X-Patchwork-Id: 3677991 Return-Path: X-Original-To: patchwork-linux-arm@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 2AE8F9F35F for ; Wed, 19 Feb 2014 05:22:03 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E460F2016C for ; Wed, 19 Feb 2014 05:22:01 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7020B20158 for ; Wed, 19 Feb 2014 05:22:00 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WFzbX-0005Yu-KY; Wed, 19 Feb 2014 05:21:55 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WFzbV-0003Ur-3i; Wed, 19 Feb 2014 05:21:53 +0000 Received: from mail-ig0-f180.google.com ([209.85.213.180]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WFzbS-0003UC-Gk for linux-arm-kernel@lists.infradead.org; Wed, 19 Feb 2014 05:21:51 +0000 Received: by mail-ig0-f180.google.com with SMTP id m12so526464iga.1 for ; Tue, 18 Feb 2014 21:21:28 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:content-type:mime-version :content-transfer-encoding:to:from:in-reply-to:cc:references :message-id:user-agent:subject:date; bh=laUW5XqdLOQhYRlyCBWhtVuPrQQoEa+ST5hnWe5v1Ds=; b=jp/JoTBjgQGM0iGbQ/wpun6LGOdFS8eyyy7Uh9o0LGKt7OzyTlNGW6Oi1gxyF4KyYG aQrRiKlgPCygXYMXliC8AVdKmxZ0DN6neah0eqD6iiF8U0ZzOxAssY2InwlzQOPxQbbD UeaciTGGp1ZOEWvCTAUK6mxEAjN2Qzm4d3o9927NcblLQuV+RR7BSnr3TXhIzDiQuzWb QWVRvoK/uhUSmqBDK9pAX7MFUQXlmaY4lHHIJZg9nTl7z3q8fkDJQRrYruKEiIfINJsy xIEAT0nN98bHPi+AtSaBAzNdUlMMoeFGqwefs/hna1sKIJWfLXJ4ckmqznywxrPEzYlV Q00g== X-Gm-Message-State: ALoCoQmvPKDb4rhmXY1gKzWuECvpeBcA34k3ApI/md4uPxEyAWhcd8UKKYYHIY95U0Crdnm1/xAB X-Received: by 10.50.79.193 with SMTP id l1mr26227195igx.36.1392787288157; Tue, 18 Feb 2014 21:21:28 -0800 (PST) Received: from localhost ([2601:9:5900:1fe:ca60:ff:fe0a:8a36]) by mx.google.com with ESMTPSA id u1sm47111675igm.8.2014.02.18.21.21.26 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 18 Feb 2014 21:21:27 -0800 (PST) MIME-Version: 1.0 To: Maxime Ripard , =?utf-8?q?David_Lanzend=C3=B6rfer?= From: Mike Turquette In-Reply-To: <20140218141532.GH3142@lukather> References: <20140217095907.15040.81893.stgit@pagira.o2s.ch> <20140217100221.15040.47203.stgit@pagira.o2s.ch> <20140218141532.GH3142@lukather> Message-ID: <20140219052125.8345.70717@quantum> User-Agent: alot/0.3.5 Subject: Re: [PATCH v7 2/8] clk: sunxi: Implement MMC phase control Date: Tue, 18 Feb 2014 21:21:25 -0800 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140219_002150_617709_ABC4046C X-CRM114-Status: GOOD ( 26.22 ) X-Spam-Score: 0.3 (/) Cc: devicetree@vger.kernel.org, dinguyen@altera.com, "Ulf Hansson , Laurent Pinchart , Simon Baatz , Hans de Goede , =?utf-8?q?Emilio_L=C3=B3pez?= , linux-mmc@vger.kernel.org, Chris Ball , linux-kernel@vger.kernel.org, H Hartley Sweeten , linux-sunxi@googlegroups.com, Tejun Heo , Guennadi Liakhovetski" , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,KHOP_BIG_TO_CC, RCVD_IN_DNSWL_MED,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 Quoting Maxime Ripard (2014-02-18 06:15:32) > Hi, > > On Mon, Feb 17, 2014 at 11:02:21AM +0100, David Lanzendörfer wrote: > > From: Emilio López > > > > Signed-off-by: Emilio López > > You're missing your Signed-off-by here too. Remember, for every patch > you send, your Signed-off-by must be there, regardless wether you're > the author or not. > > A commit log would be very much welcome too. > > Now, down to the patch itself, I remember Mike saying that he would > prefer adding a function in the framework instead of hardcoding > it. Mike, what's your feeling on this? Would merging this seem > reasonnable to you as is, or do you want to take this to the > framework? Hi Maxime & Emilio, Maybe something like the following RFC? If it seems sufficient for this case then I will post to the wider list with an eye towards merging it for 3.15. I've Cc'd Dinh since this came up on the socfpga thread as well. Regards, Mike From 56fa297591be5c5e22df6d2ca43fccf285a45636 Mon Sep 17 00:00:00 2001 From: Mike Turquette Date: Tue, 18 Feb 2014 20:33:50 -0800 Subject: [PATCH] clk: introduce clk_set_phase function & callback A common operation for a clock signal generator is to shift the phase of that signal. This patch introduces a new function to the clk.h API to dynamically adjust the phase of a clock signal. Additionally this patch introduces support for the new function in the common clock framework via the .set_phase call back in struct clk_ops. Signed-off-by: Mike Turquette --- This patch is totally untested. It may make your board burst into flames. drivers/clk/clk.c | 84 +++++++++++++++++++++++++++++++++++++++++--- include/linux/clk-private.h | 1 + include/linux/clk-provider.h | 5 +++ include/linux/clk.h | 29 +++++++++++++++ 4 files changed, 115 insertions(+), 4 deletions(-) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index ea2ca9f..635170a 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -106,11 +106,11 @@ static void clk_summary_show_one(struct seq_file *s, struct clk *c, int level) if (!c) return; - seq_printf(s, "%*s%-*s %-11d %-12d %-10lu %-11lu", + seq_printf(s, "%*s%-*s %-11d %-12d %-10lu %-11lu %-3d", level * 3 + 1, "", 30 - level * 3, c->name, c->enable_count, c->prepare_count, clk_get_rate(c), - clk_get_accuracy(c)); + clk_get_accuracy(c), clk_get_phase(c)); seq_printf(s, "\n"); } @@ -132,8 +132,8 @@ static int clk_summary_show(struct seq_file *s, void *data) { struct clk *c; - seq_printf(s, " clock enable_cnt prepare_cnt rate accuracy\n"); - seq_printf(s, "---------------------------------------------------------------------------------\n"); + seq_printf(s, " clock enable_cnt prepare_cnt rate accuracy phase\n"); + seq_printf(s, "-----------------------------------------------------------------------------------------\n"); clk_prepare_lock(); @@ -171,6 +171,7 @@ static void clk_dump_one(struct seq_file *s, struct clk *c, int level) seq_printf(s, "\"prepare_count\": %d,", c->prepare_count); seq_printf(s, "\"rate\": %lu", clk_get_rate(c)); seq_printf(s, "\"accuracy\": %lu", clk_get_accuracy(c)); + seq_printf(s, "\"phase\": %d", clk_get_phase(c)); } static void clk_dump_subtree(struct seq_file *s, struct clk *c, int level) @@ -257,6 +258,11 @@ static int clk_debug_create_one(struct clk *clk, struct dentry *pdentry) if (!d) goto err_out; + d = debugfs_create_u32("clk_phase", S_IRUGO, clk->dentry, + (u32 *)&clk->phase); + if (!d) + goto err_out; + d = debugfs_create_x32("clk_flags", S_IRUGO, clk->dentry, (u32 *)&clk->flags); if (!d) @@ -1766,6 +1772,76 @@ out: EXPORT_SYMBOL_GPL(clk_set_parent); /** + * clk_set_phase - adjust the phase shift of a clock signal + * @clk: clock signal source + * @degrees: number of degrees the signal is shifted + * + * Shifts the phase of a clock signal by the specified degrees. Returns 0 on + * success, -EERROR otherwise. + * + * This function makes no distiction about the input or reference signal that + * we adjust the clock signal phase against. For example phase locked-loop + * clock signal generators we may shift phase with respect to feedback clock + * signal input, but for other cases the clock phase may be shifted with + * respect to some other, unspecified signal. + * + * Additionally the concept of phase shift does not propagate through the clock + * tree hierarchy, which sets it appart from clock rates and clock accuracy. A + * parent clock phase attribute does not have an impact on the phase attribute + * of a child clock. + */ +int clk_set_phase(struct clk *clk, int degrees) +{ + int ret = 0; + + if (!clk) + goto out; + + /* sanity check degrees */ + degrees %= 360; + if (degrees < 0) + degrees += 360; + + clk_prepare_lock(); + + if (!clk->ops->set_phase) + goto out_unlock; + + ret = clk->ops->set_phase(clk->hw, degrees); + + if (!ret) + clk->phase = degrees; + +out_unlock: + clk_prepare_unlock(); + +out: + return ret; +} + +/** + * clk_get_phase - return the phase shift of a clock signal + * @clk: clock signal source + * + * Returns the phase shift of a clock node in degrees, otherwise returns + * -EERROR. + */ +int clk_get_phase(struct clk *clk) +{ + int ret = 0; + + if (!clk) + goto out; + + clk_prepare_lock(); + ret = clk->phase; + clk_prepare_unlock(); + +out: + return ret; +} + +/** * __clk_init - initialize the data structures in a struct clk * @dev: device initializing this clk, placeholder for now * @clk: clk being initialized diff --git a/include/linux/clk-private.h b/include/linux/clk-private.h index efbf70b..845be30 100644 --- a/include/linux/clk-private.h +++ b/include/linux/clk-private.h @@ -46,6 +46,7 @@ struct clk { unsigned int enable_count; unsigned int prepare_count; unsigned long accuracy; + int phase; struct hlist_head children; struct hlist_node child_node; unsigned int notifier_count; diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h index 939533d..cc49fb8 100644 --- a/include/linux/clk-provider.h +++ b/include/linux/clk-provider.h @@ -127,6 +127,10 @@ struct clk_hw; * separately via calls to .set_parent and .set_rate. * Returns 0 on success, -EERROR otherwise. * + * @set_phase: Shift the phase this clock signal in degrees specified + * by the second argument. Valid values for degrees are + * 0-359. Return 0 on success, otherwise -EERROR. + * * * The clk_enable/clk_disable and clk_prepare/clk_unprepare pairs allow * implementations to split any work between atomic (enable) and sleepable @@ -164,6 +168,7 @@ struct clk_ops { unsigned long parent_rate, u8 index); unsigned long (*recalc_accuracy)(struct clk_hw *hw, unsigned long parent_accuracy); + int (*set_phase)(struct clk_hw *hw, int degrees); void (*init)(struct clk_hw *hw); }; diff --git a/include/linux/clk.h b/include/linux/clk.h index 0dd9114..ae2b2f4 100644 --- a/include/linux/clk.h +++ b/include/linux/clk.h @@ -92,6 +92,25 @@ int clk_notifier_unregister(struct clk *clk, struct notifier_block *nb); */ long clk_get_accuracy(struct clk *clk); +/** + * clk_set_phase - adjust the phase shift of a clock signal + * @clk: clock signal source + * @degrees: number of degrees the signal is shifted + * + * Shifts the phase of a clock signal by the specified degrees. Returns 0 on + * success, -EERROR otherwise. + */ +int clk_set_phase(struct clk *clk, int degrees); + +/** + * clk_get_phase - return the phase shift of a clock signal + * @clk: clock signal source + * + * Returns the phase shift of a clock node in degrees, otherwise returns + * -EERROR. + */ +int clk_get_phase(struct clk *clk); + #else static inline long clk_get_accuracy(struct clk *clk) @@ -99,6 +118,16 @@ static inline long clk_get_accuracy(struct clk *clk) return -ENOTSUPP; } +static inline long clk_set_phase(struct clk *clk, int phase) +{ + return -ENOTSUPP; +} + +static inline long clk_get_phase(struct clk *clk) +{ + return -ENOTSUPP; +} + #endif /**