From patchwork Fri May 30 20:53:05 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 4274051 Return-Path: X-Original-To: patchwork-linux-arm@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 9EE79BEEA7 for ; Fri, 30 May 2014 20:56:04 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9E84320265 for ; Fri, 30 May 2014 20:56:03 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (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 8DE55202E5 for ; Fri, 30 May 2014 20:56:02 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WqToi-0003fv-Oe; Fri, 30 May 2014 20:54:20 +0000 Received: from mail-ig0-f182.google.com ([209.85.213.182]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WqTo0-0002yU-MQ for linux-arm-kernel@lists.infradead.org; Fri, 30 May 2014 20:53:37 +0000 Received: by mail-ig0-f182.google.com with SMTP id uy17so1326299igb.15 for ; Fri, 30 May 2014 13:53:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=DxgZpt6qSrO+JwcB3rNuL0nz9/z2Zs1snKvqgCZM2y0=; b=h0KS+oKzww1w+9uFPaBLTKLfn20JDpKDGSylMLETO9cFuZWje1RpvtxKllU8JHT4rq MEtEm6cbhzlUT7BnJA+hNlmNRAUs1pSQy4LePipa2gnMVtZMpkf80YsuMcgiN1QxgWmm b/daYSpfZLikUUlULTUnGUicgVcVq7xAH92WaM3uuBo4ffEZrPIMV8Ti7MPTEKJFJPyj VXXV0tav3mAo+KX1YMSqFiX1fxHDnsFvCgv/AKwR4LvVJr9GiuZsiBqFNaWBVjyPXpDN CaHGw6dnEeTgDxiDSITHmNachPl1LbuaXBrATC5xFT0LYfLLWcmfrfxVhOeCU49hy/7k JZBQ== X-Gm-Message-State: ALoCoQmbKjoUPlTuITY9djLYG8tBaSiyyMcdHpIAHzhBXqJKYbX9Xfo/bhZZNTITyfDJb1oi7XfB X-Received: by 10.50.143.9 with SMTP id sa9mr158020igb.2.1401483195157; Fri, 30 May 2014 13:53:15 -0700 (PDT) Received: from localhost.localdomain (c-71-195-31-37.hsd1.mn.comcast.net. [71.195.31.37]) by mx.google.com with ESMTPSA id b8sm8057705igx.3.2014.05.30.13.53.14 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 30 May 2014 13:53:14 -0700 (PDT) From: Alex Elder To: mturquette@linaro.org, mporter@linaro.org, bcm@fixthebug.org Subject: [PATCH v4 4/7] clk: bcm281xx: implement prerequisite clocks Date: Fri, 30 May 2014 15:53:05 -0500 Message-Id: <1401483188-5395-5-git-send-email-elder@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1401483188-5395-1-git-send-email-elder@linaro.org> References: <1401483188-5395-1-git-send-email-elder@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140530_135336_833904_16201DEB X-CRM114-Status: GOOD ( 23.89 ) X-Spam-Score: -0.7 (/) Cc: linux-kernel@vger.kernel.org, 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: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,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 Allow a clock to specify a "prerequisite" clock, identified by its name. The prerequisite clock must be prepared and enabled before a clock that depends on it is used. In order to simplify locking, we require a clock and its prerequisite to be associated with the same CCU. (We'll just trust--but not verify--that nobody defines a cycle of prerequisite clocks.) Rework the KONA_CLK() macro, and define a new KONA_CLK_PREREQ() variant that allows a prerequisite clock to be specified. Signed-off-by: Alex Elder --- drivers/clk/bcm/clk-kona-setup.c | 24 ++++++++++++ drivers/clk/bcm/clk-kona.c | 84 +++++++++++++++++++++++++++++++++++++++- drivers/clk/bcm/clk-kona.h | 20 ++++++++-- 3 files changed, 123 insertions(+), 5 deletions(-) diff --git a/drivers/clk/bcm/clk-kona-setup.c b/drivers/clk/bcm/clk-kona-setup.c index 317f7dd..36a99b9 100644 --- a/drivers/clk/bcm/clk-kona-setup.c +++ b/drivers/clk/bcm/clk-kona-setup.c @@ -796,6 +796,28 @@ static bool ccu_data_valid(struct ccu_data *ccu) } /* + * If a clock specifies a prerequisite clock, they must both be on + * the same CCU. Check if the named prerequisite clock matches one + * of the ones provided by CCU. A null name means no prerequisite. + */ +static bool kona_prereq_valid(struct ccu_data *ccu, const char *prereq_name) +{ + unsigned int i; + + if (!prereq_name) + return true; + + for (i = 0; i < ccu->clk_data.clk_num; i++) + if (!strcmp(prereq_name, ccu->kona_clks[i].init_data.name)) + return true; + + pr_err("%s: prereq clock %s not defined for ccu %s\n", __func__, + prereq_name, ccu->name); + + return false; +} + +/* * Set up a CCU. Call the provided ccu_clks_setup callback to * initialize the array of clocks provided by the CCU. */ @@ -857,6 +879,8 @@ void __init kona_dt_ccu_setup(struct ccu_data *ccu, for (i = 0; i < ccu->clk_data.clk_num; i++) { if (!ccu->kona_clks[i].ccu) continue; + if (!kona_prereq_valid(ccu, ccu->kona_clks[i].prereq.name)) + continue; ccu->clk_data.clks[i] = kona_clk_setup(&ccu->kona_clks[i]); } diff --git a/drivers/clk/bcm/clk-kona.c b/drivers/clk/bcm/clk-kona.c index 9a69a01..a6a45cd 100644 --- a/drivers/clk/bcm/clk-kona.c +++ b/drivers/clk/bcm/clk-kona.c @@ -1028,6 +1028,44 @@ static bool __peri_clk_init(struct kona_clk *bcm_clk) /* Clock operations */ +static int __kona_prereq_prepare_enable(struct kona_clk *bcm_clk) +{ + const char *clk_name = bcm_clk->init_data.name; + const char *prereq_name = bcm_clk->prereq.name; + struct clk *prereq_clk = bcm_clk->prereq.clk; + int ret; + + BUG_ON(!clk_name); + + /* Look up the prerequisite clock if we haven't already */ + if (!prereq_clk) { + prereq_clk = __clk_lookup(prereq_name); + if (!prereq_clk) { + pr_err("%s: prereq clock %s for %s not found\n", + __func__, prereq_name, clk_name); + return -ENOENT; + } + bcm_clk->prereq.clk = prereq_clk; + } + + ret = __clk_prepare(prereq_clk); + if (ret) { + pr_err("%s: unable to prepare prereq clock %s for %s\n", + __func__, prereq_name, clk_name); + return ret; + } + + ret = clk_enable(prereq_clk); + if (ret) { + __clk_unprepare(prereq_clk); + pr_err("%s: unable to enable prereq clock %s for %s\n", + __func__, prereq_name, clk_name); + return ret; + } + + return 0; +} + static int kona_clk_prepare(struct clk_hw *hw) { struct kona_clk *bcm_clk = to_kona_clk(hw); @@ -1038,6 +1076,13 @@ static int kona_clk_prepare(struct clk_hw *hw) flags = ccu_lock(ccu); __ccu_write_enable(ccu); + /* Prepare the prerequisite clock first */ + if (bcm_clk->prereq.name) { + ret = __kona_prereq_prepare_enable(bcm_clk); + if (ret) + goto out; + } + switch (bcm_clk->type) { case bcm_clk_peri: if (!__peri_clk_init(bcm_clk)) @@ -1046,16 +1091,51 @@ static int kona_clk_prepare(struct clk_hw *hw) default: BUG(); } - +out: __ccu_write_disable(ccu); ccu_unlock(ccu, flags); return ret; } +/* + * Disable and unprepare a prerequisite clock, and drop our + * reference to it. + */ +static void __kona_prereq_disable_unprepare(struct kona_clk *bcm_clk) +{ + struct clk *prereq_clk = bcm_clk->prereq.clk; + + BUG_ON(!bcm_clk->prereq.name); + WARN_ON_ONCE(!prereq_clk); + + bcm_clk->prereq.clk = NULL; + + clk_disable(prereq_clk); + __clk_unprepare(prereq_clk); +} + static void kona_clk_unprepare(struct clk_hw *hw) { - /* Nothing to do. */ + struct kona_clk *bcm_clk = to_kona_clk(hw); + struct ccu_data *ccu; + unsigned long flags; + + /* + * We don't do anything to unprepare Kona clocks themselves, + * but if there's a prerequisite we'll need to unprepare it. + */ + if (!bcm_clk->prereq.name) + return; + + ccu = bcm_clk->ccu; + flags = ccu_lock(ccu); + __ccu_write_enable(ccu); + + __kona_prereq_disable_unprepare(bcm_clk); + + __ccu_write_disable(ccu); + ccu_unlock(ccu, flags); } static int kona_peri_clk_enable(struct clk_hw *hw) diff --git a/drivers/clk/bcm/clk-kona.h b/drivers/clk/bcm/clk-kona.h index 3409111..0a845a0 100644 --- a/drivers/clk/bcm/clk-kona.h +++ b/drivers/clk/bcm/clk-kona.h @@ -406,6 +406,10 @@ struct kona_clk { struct clk_init_data init_data; /* includes name of this clock */ struct ccu_data *ccu; /* ccu this clock is associated with */ enum bcm_clk_type type; + struct { + const char *name; + struct clk *clk; + } prereq; union { void *data; struct peri_clk_data *peri; @@ -415,16 +419,26 @@ struct kona_clk { container_of(_hw, struct kona_clk, hw) /* Initialization macro for an entry in a CCU's kona_clks[] array. */ -#define KONA_CLK(_ccu_name, _clk_name, _type) \ - { \ +#define ___KONA_CLK_COMMON(_ccu_name, _clk_name, _type) \ .init_data = { \ .name = #_clk_name, \ .ops = &kona_ ## _type ## _clk_ops, \ }, \ .ccu = &_ccu_name ## _ccu_data, \ .type = bcm_clk_ ## _type, \ - .u.data = &_clk_name ## _data, \ + .u.data = &_clk_name ## _data + +#define KONA_CLK_PREREQ(_ccu_name, _clk_name, _type, _prereq) \ + { \ + .prereq.name = #_prereq, \ + ___KONA_CLK_COMMON(_ccu_name, _clk_name, _type), \ } + +#define KONA_CLK(_ccu_name, _clk_name, _type) \ + { \ + ___KONA_CLK_COMMON(_ccu_name, _clk_name, _type), \ + } + #define LAST_KONA_CLK { .type = bcm_clk_none } /*