From patchwork Mon Jun 2 22:44:56 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 4284421 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 3862FBEEA7 for ; Mon, 2 Jun 2014 22:48:22 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 066942024D for ; Mon, 2 Jun 2014 22:48:21 +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 E0B85200D7 for ; Mon, 2 Jun 2014 22:48:19 +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 1WrazH-0004ZR-Re; Mon, 02 Jun 2014 22:45:51 +0000 Received: from mail-ig0-f173.google.com ([209.85.213.173]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Wrayn-0003OG-A4 for linux-arm-kernel@lists.infradead.org; Mon, 02 Jun 2014 22:45:23 +0000 Received: by mail-ig0-f173.google.com with SMTP id hn18so3995583igb.6 for ; Mon, 02 Jun 2014 15:45:00 -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=IOv1UsTzVEYGLwxj9peyxcwGXa3cuQeOlfKCDeVNnGY=; b=VhJtU5h58Vac7RK1UrPR6IOdGU5ZccczrNE6om4eQZLg1QVpapN3qV247JfzGgsD0o U8fWBF4bkUO/b1t0NqlSeBbIldgSJHvH8fEKtjtDEPEMGnUft2lMfF/q32KXnrT5b2mK UsC9d8LqKP74XjLWenoKruIcWHDwL7yFM/BsnwrwZKUu77Ww0C5Y56eLcLAb2kMSoJvF T3j4RocEu5c/tAuPrSG65RiOGUZFcpHoovKyLVD8uw+1yMG0bfmcCZQh+23bgdaKetVM nEoD/PzZ/QeEjsnkuqyIDPeqUbA3akqGsBdwNatDdKvJJSH9sFa5p/pSNInnd/4FYU+q 1cNg== X-Gm-Message-State: ALoCoQmqwF9JFJdJUW69aLaJU3A4aw1OmiFZvObUTx+0DknNa699bahowMtygsG3eMuW0mjKSdFl X-Received: by 10.42.27.147 with SMTP id j19mr5618320icc.81.1401749100802; Mon, 02 Jun 2014 15:45:00 -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 o19sm3523192igi.20.2014.06.02.15.44.59 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 02 Jun 2014 15:45:00 -0700 (PDT) From: Alex Elder To: mturquette@linaro.org, mporter@linaro.org, bcm@fixthebug.org Subject: [PATCH v5 5/7] clk: bcm281xx: add bus clock support Date: Mon, 2 Jun 2014 17:44:56 -0500 Message-Id: <1401749098-10185-6-git-send-email-elder@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1401749098-10185-1-git-send-email-elder@linaro.org> References: <1401749098-10185-1-git-send-email-elder@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140602_154521_450060_B5CC98C6 X-CRM114-Status: GOOD ( 19.85 ) 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 Add bus clock support. A bus clock has a subset of the components present in a peripheral clock (again, all optional): a gate; CCU policy management bits; and if needed, bits to control hysteresis. Signed-off-by: Alex Elder --- drivers/clk/bcm/clk-kona-setup.c | 96 ++++++++++++++++++++++++++++++++++++++-- drivers/clk/bcm/clk-kona.c | 61 +++++++++++++++++++++++++ drivers/clk/bcm/clk-kona.h | 8 ++++ 3 files changed, 162 insertions(+), 3 deletions(-) diff --git a/drivers/clk/bcm/clk-kona-setup.c b/drivers/clk/bcm/clk-kona-setup.c index 317f7dd..1dae591 100644 --- a/drivers/clk/bcm/clk-kona-setup.c +++ b/drivers/clk/bcm/clk-kona-setup.c @@ -76,6 +76,56 @@ static bool clk_requires_trigger(struct kona_clk *bcm_clk) return divider_exists(div) && !divider_is_fixed(div); } +static bool bus_clk_data_offsets_valid(struct kona_clk *bcm_clk) +{ + struct bus_clk_data *bus; + struct bcm_clk_policy *policy; + struct bcm_clk_gate *gate; + struct bcm_clk_hyst *hyst; + const char *name; + u32 limit; + + BUG_ON(bcm_clk->type != bcm_clk_bus); + bus = bcm_clk->u.bus; + name = bcm_clk->init_data.name; + + limit = bcm_clk->ccu->range - sizeof(u32); + limit = round_down(limit, sizeof(u32)); + + policy = &bus->policy; + if (policy_exists(policy)) { + if (policy->offset > limit) { + pr_err("%s: bad policy offset for %s (%u > %u)\n", + __func__, name, policy->offset, limit); + return false; + } + } + + gate = &bus->gate; + hyst = &bus->hyst; + if (gate_exists(gate)) { + if (gate->offset > limit) { + pr_err("%s: bad gate offset for %s (%u > %u)\n", + __func__, name, gate->offset, limit); + return false; + } + if (hyst_exists(hyst)) { + if (hyst->offset > limit) { + pr_err("%s: bad hysteresis offset for %s " + "(%u > %u)\n", __func__, + name, hyst->offset, limit); + return false; + } + } + } else if (hyst_exists(hyst)) { + pr_err("%s: hysteresis but no gate for %s\n", __func__, name); + return false; + } + + + return true; +} + static bool peri_clk_data_offsets_valid(struct kona_clk *bcm_clk) { struct peri_clk_data *peri; @@ -86,15 +136,13 @@ static bool peri_clk_data_offsets_valid(struct kona_clk *bcm_clk) struct bcm_clk_sel *sel; struct bcm_clk_trig *trig; const char *name; - u32 range; u32 limit; BUG_ON(bcm_clk->type != bcm_clk_peri); peri = bcm_clk->u.peri; name = bcm_clk->init_data.name; - range = bcm_clk->ccu->range; - limit = range - sizeof(u32); + limit = bcm_clk->ccu->range - sizeof(u32); limit = round_down(limit, sizeof(u32)); policy = &peri->policy; @@ -397,6 +445,23 @@ static bool trig_valid(struct bcm_clk_trig *trig, const char *field_name, return bit_posn_valid(trig->bit, field_name, clock_name); } +/* Determine whether the set of bus clock registers are valid. */ +static bool +bus_clk_data_valid(struct kona_clk *bcm_clk) +{ + struct bcm_clk_gate *gate; + + BUG_ON(bcm_clk->type != bcm_clk_bus); + if (!bus_clk_data_offsets_valid(bcm_clk)) + return false; + + gate = &bcm_clk->u.bus->gate; + if (!gate_exists(gate)) + return true; + + return gate_valid(gate, "gate", bcm_clk->init_data.name); +} + /* Determine whether the set of peripheral clock registers are valid. */ static bool peri_clk_data_valid(struct kona_clk *bcm_clk) @@ -494,6 +559,10 @@ peri_clk_data_valid(struct kona_clk *bcm_clk) static bool kona_clk_valid(struct kona_clk *bcm_clk) { switch (bcm_clk->type) { + case bcm_clk_bus: + if (!bus_clk_data_valid(bcm_clk)) + return false; + break; case bcm_clk_peri: if (!peri_clk_data_valid(bcm_clk)) return false; @@ -664,6 +733,20 @@ static void clk_sel_teardown(struct bcm_clk_sel *sel, init_data->parent_names = NULL; } +static void bus_clk_teardown(struct bus_clk_data *data, + struct clk_init_data *init_data) +{ + /* Nothing to do */ +} + +static int +bus_clk_setup(struct bus_clk_data *data, struct clk_init_data *init_data) +{ + init_data->flags = CLK_IGNORE_UNUSED; + + return 0; +} + static void peri_clk_teardown(struct peri_clk_data *data, struct clk_init_data *init_data) { @@ -687,6 +770,9 @@ peri_clk_setup(struct peri_clk_data *data, struct clk_init_data *init_data) static void bcm_clk_teardown(struct kona_clk *bcm_clk) { switch (bcm_clk->type) { + case bcm_clk_bus: + bus_clk_teardown(bcm_clk->u.data, &bcm_clk->init_data); + break; case bcm_clk_peri: peri_clk_teardown(bcm_clk->u.data, &bcm_clk->init_data); break; @@ -722,6 +808,10 @@ struct clk *kona_clk_setup(struct kona_clk *bcm_clk) struct clk *clk = NULL; switch (bcm_clk->type) { + case bcm_clk_bus: + if (bus_clk_setup(bcm_clk->u.data, init_data)) + return NULL; + break; case bcm_clk_peri: if (peri_clk_setup(bcm_clk->u.data, init_data)) return NULL; diff --git a/drivers/clk/bcm/clk-kona.c b/drivers/clk/bcm/clk-kona.c index 51b4edb..a938b15 100644 --- a/drivers/clk/bcm/clk-kona.c +++ b/drivers/clk/bcm/clk-kona.c @@ -984,6 +984,31 @@ static int selector_write(struct ccu_data *ccu, struct bcm_clk_gate *gate, return ret; } +/* Put a bus clock into its initial state */ +static bool __bus_clk_init(struct kona_clk *bcm_clk) +{ + struct ccu_data *ccu = bcm_clk->ccu; + struct bus_clk_data *bus = bcm_clk->u.bus; + const char *name = bcm_clk->init_data.name; + + BUG_ON(bcm_clk->type != bcm_clk_bus); + + if (!policy_init(ccu, &bus->policy)) { + pr_err("%s: error initializing policy for %s\n", + __func__, name); + return false; + } + if (!gate_init(ccu, &bus->gate)) { + pr_err("%s: error initializing gate for %s\n", __func__, name); + return false; + } + if (!hyst_init(ccu, &bus->hyst)) { + pr_err("%s: error initializing hyst for %s\n", __func__, name); + return false; + } + return true; +} + /* Put a peripheral clock into its initial state */ static bool __peri_clk_init(struct kona_clk *bcm_clk) { @@ -1095,6 +1120,10 @@ static int kona_clk_prepare(struct clk_hw *hw) __ccu_write_enable(ccu); switch (bcm_clk->type) { + case bcm_clk_bus: + if (!__bus_clk_init(bcm_clk)) + ret = -EINVAL; + break; case bcm_clk_peri: if (!__peri_clk_init(bcm_clk)) ret = -EINVAL; @@ -1143,6 +1172,38 @@ static void kona_clk_unprepare(struct clk_hw *hw) kona_prereq_disable_unprepare(bcm_clk); } +static int kona_bus_clk_enable(struct clk_hw *hw) +{ + struct kona_clk *bcm_clk = to_kona_clk(hw); + struct bcm_clk_gate *gate = &bcm_clk->u.bus->gate; + + return clk_gate(bcm_clk->ccu, bcm_clk->init_data.name, gate, true); +} + +static void kona_bus_clk_disable(struct clk_hw *hw) +{ + struct kona_clk *bcm_clk = to_kona_clk(hw); + struct bcm_clk_gate *gate = &bcm_clk->u.bus->gate; + + (void)clk_gate(bcm_clk->ccu, bcm_clk->init_data.name, gate, false); +} + +static int kona_bus_clk_is_enabled(struct clk_hw *hw) +{ + struct kona_clk *bcm_clk = to_kona_clk(hw); + struct bcm_clk_gate *gate = &bcm_clk->u.bus->gate; + + return is_clk_gate_enabled(bcm_clk->ccu, gate) ? 1 : 0; +} + +struct clk_ops kona_bus_clk_ops = { + .prepare = kona_clk_prepare, + .unprepare = kona_clk_unprepare, + .enable = kona_bus_clk_enable, + .disable = kona_bus_clk_disable, + .is_enabled = kona_bus_clk_is_enabled, +}; + static int kona_peri_clk_enable(struct clk_hw *hw) { struct kona_clk *bcm_clk = to_kona_clk(hw); diff --git a/drivers/clk/bcm/clk-kona.h b/drivers/clk/bcm/clk-kona.h index 98b6fa1..46ea11f 100644 --- a/drivers/clk/bcm/clk-kona.h +++ b/drivers/clk/bcm/clk-kona.h @@ -387,6 +387,12 @@ struct bcm_clk_trig { .flags = FLAG(TRIG, EXISTS), \ } +struct bus_clk_data { + struct bcm_clk_policy policy; + struct bcm_clk_gate gate; + struct bcm_clk_hyst hyst; +}; + struct peri_clk_data { struct bcm_clk_policy policy; struct bcm_clk_gate gate; @@ -413,6 +419,7 @@ struct kona_clk { } prereq; union { void *data; + struct bus_clk_data *bus; struct peri_clk_data *peri; } u; }; @@ -520,6 +527,7 @@ struct ccu_data { /* Exported globals */ +extern struct clk_ops kona_bus_clk_ops; extern struct clk_ops kona_peri_clk_ops; /* Externally visible functions */