From patchwork Mon Jun 16 13:40:04 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 4359311 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 19436BEEAA for ; Mon, 16 Jun 2014 13:52:32 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 293442017D for ; Mon, 16 Jun 2014 13:52:31 +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 2497D20179 for ; Mon, 16 Jun 2014 13:52:30 +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 1WwX9i-0004Co-NL; Mon, 16 Jun 2014 13:41:02 +0000 Received: from mail-ig0-f176.google.com ([209.85.213.176]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WwX8y-0002WN-7p for linux-arm-kernel@lists.infradead.org; Mon, 16 Jun 2014 13:40:17 +0000 Received: by mail-ig0-f176.google.com with SMTP id a13so2908188igq.9 for ; Mon, 16 Jun 2014 06:39:54 -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=/fOCxyJVfTasN/KzSmZGHcU4qlIS9Loe1hRAc02immU=; b=P3r0mrpVmbbQTuaKEkkfIv08Xxf1EDveADJvbmeVgsm+//CXXP4kzUKmdjgLBtrnJG GaEIYvsT7jk/BkLW/S+n7F+6Kpvt+TiG8JvW+TNFjV1ob8SxfRVZa+e+tHjuSm3FmSYg flItE5HT9quVJurG3yIYnMasBvJSUKJZwDe8ZW2hdZOlBwnoDxxD0SKs8ouX57M97F8s 4aDFiiFh+0QZq8ZpVCRp/g5Ry7RCXQEN8CRMJr8PCbhvZ8R3htvBljmtIIfMRh2udwAO cWIDNe5xAJDkjPS0MnPqa7Y3aa6jtBLIGqGL010RahAVag1Vl5wxYBTrgUJJCllwVkxU 9+8g== X-Gm-Message-State: ALoCoQkGYH1lQkWpDLP9/h7bnvaIu0JCRY4iXNEy9Yq4OT51Xs3VsPtcTVwOqXLN/3RETNWWLHVB X-Received: by 10.42.137.70 with SMTP id x6mr2658637ict.79.1402925993665; Mon, 16 Jun 2014 06:39:53 -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 k20sm20775727igf.5.2014.06.16.06.39.52 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 16 Jun 2014 06:39:53 -0700 (PDT) From: Alex Elder To: mturquette@linaro.org, mporter@linaro.org, bcm@fixthebug.org Subject: [PATCH v6 4/7] clk: bcm281xx: implement prerequisite clocks Date: Mon, 16 Jun 2014 08:40:04 -0500 Message-Id: <1402926007-4436-5-git-send-email-elder@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1402926007-4436-1-git-send-email-elder@linaro.org> References: <1402926007-4436-1-git-send-email-elder@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140616_064016_387359_E561D214 X-CRM114-Status: GOOD ( 20.44 ) X-Spam-Score: -0.8 (/) 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.18-1 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.9 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.c | 70 ++++++++++++++++++++++++++++++++++++++++++++-- drivers/clk/bcm/clk-kona.h | 20 +++++++++++-- 2 files changed, 85 insertions(+), 5 deletions(-) diff --git a/drivers/clk/bcm/clk-kona.c b/drivers/clk/bcm/clk-kona.c index 2e27924..51b4edb 100644 --- a/drivers/clk/bcm/clk-kona.c +++ b/drivers/clk/bcm/clk-kona.c @@ -1037,6 +1037,42 @@ 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 (WARN_ON_ONCE(!prereq_clk)) + return -ENOENT; + bcm_clk->prereq.clk = prereq_clk; + } + + /* Dependent clock already holds the prepare lock */ + 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); @@ -1044,6 +1080,13 @@ static int kona_clk_prepare(struct clk_hw *hw) unsigned long flags; int ret = 0; + /* Prepare the prerequisite clock first */ + if (bcm_clk->prereq.name) { + ret = kona_prereq_prepare_enable(bcm_clk); + if (ret) + goto out; + } + if (clk_is_initialized(bcm_clk)) return 0; @@ -1062,19 +1105,42 @@ static int kona_clk_prepare(struct clk_hw *hw) __ccu_write_disable(ccu); ccu_unlock(ccu, flags); - +out: if (!ret) clk_set_initialized(bcm_clk); 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); + + clk_disable(prereq_clk); + __clk_unprepare(prereq_clk); +} + static void kona_clk_unprepare(struct clk_hw *hw) { struct kona_clk *bcm_clk = to_kona_clk(hw); WARN_ON(!clk_is_initialized(bcm_clk)); - /* Nothing to do. */ + + /* + * 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; + + kona_prereq_disable_unprepare(bcm_clk); } 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 ea77ec1..98b6fa1 100644 --- a/drivers/clk/bcm/clk-kona.h +++ b/drivers/clk/bcm/clk-kona.h @@ -407,6 +407,10 @@ struct kona_clk { struct ccu_data *ccu; /* ccu this clock is associated with */ enum bcm_clk_type type; u32 flags; /* BCM_CLK_KONA_FLAGS_* below */ + struct { + const char *name; + struct clk *clk; + } prereq; union { void *data; struct peri_clk_data *peri; @@ -422,16 +426,26 @@ struct kona_clk { #define BCM_CLK_KONA_FLAGS_INITIALIZED ((u32)1 << 0) /* Clock initialized */ /* 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 } /*