From patchwork Thu May 29 14:05:59 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 31126 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f199.google.com (mail-ob0-f199.google.com [209.85.214.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 31E12203E6 for ; Thu, 29 May 2014 14:06:59 +0000 (UTC) Received: by mail-ob0-f199.google.com with SMTP id wm4sf1677512obc.2 for ; Thu, 29 May 2014 07:06:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=xXNhoBqfEsq07FAZu52np2LGfyTIZyJl7TDsT8r0EoY=; b=l0iCcmApNJYJsLA0CWA9OGcvz8zel3rY9vCLIJdu3c2hjhUDB30ob74ey70hNMSga7 ckAwpI1becsmuKibJ7vJTx+1UNqq2erWlxCTcoFKILgZSf+WlEmi1KQ0HfQUbhj23f+e IhV0jIiBO5ffmooqVGMpmaibuhZv69x+Wzx5c5z1l8876MOI+N3Czy3Vy9KfVJvYw4wq YiPPq/xJUXPi/4GFmITVL/ojpBYVbhqhBDjb/rs661n9/NJaPPcPeyb59jZMuB9Nr4QB YQAQmsHmpVjLvBsT+S+edhRBQnLGCoVYiovITIqNEHb7WD9M9zkSd6WxuyHLpVO/6ePk jirA== X-Gm-Message-State: ALoCoQnkNX1TY3xAbXGvvzX3p1Mlksr6plaJ3n8+etCgV6OnYntCL4/EzA288xjAgKGur8YlQzKo X-Received: by 10.43.92.195 with SMTP id br3mr2659152icc.1.1401372418646; Thu, 29 May 2014 07:06:58 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.103.118 with SMTP id x109ls572770qge.74.gmail; Thu, 29 May 2014 07:06:58 -0700 (PDT) X-Received: by 10.221.50.70 with SMTP id vd6mr1298061vcb.51.1401372418437; Thu, 29 May 2014 07:06:58 -0700 (PDT) Received: from mail-ve0-f176.google.com (mail-ve0-f176.google.com [209.85.128.176]) by mx.google.com with ESMTPS id kp5si550695veb.19.2014.05.29.07.06.58 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 29 May 2014 07:06:58 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.176 as permitted sender) client-ip=209.85.128.176; Received: by mail-ve0-f176.google.com with SMTP id jz11so420405veb.21 for ; Thu, 29 May 2014 07:06:58 -0700 (PDT) X-Received: by 10.58.34.72 with SMTP id x8mr1053477vei.61.1401372418340; Thu, 29 May 2014 07:06:58 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.221.72 with SMTP id ib8csp31248vcb; Thu, 29 May 2014 07:06:57 -0700 (PDT) X-Received: by 10.68.231.7 with SMTP id tc7mr9330107pbc.32.1401372416966; Thu, 29 May 2014 07:06:56 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id xg6si1144563pab.9.2014.05.29.07.06.56 for ; Thu, 29 May 2014 07:06:56 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757495AbaE2OGs (ORCPT + 27 others); Thu, 29 May 2014 10:06:48 -0400 Received: from mail-ig0-f169.google.com ([209.85.213.169]:60455 "EHLO mail-ig0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965132AbaE2OGH (ORCPT ); Thu, 29 May 2014 10:06:07 -0400 Received: by mail-ig0-f169.google.com with SMTP id hl10so3556312igb.0 for ; Thu, 29 May 2014 07:06:06 -0700 (PDT) X-Received: by 10.50.137.67 with SMTP id qg3mr52084725igb.33.1401372366762; Thu, 29 May 2014 07:06:06 -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 ng17sm2510130igb.13.2014.05.29.07.06.05 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 29 May 2014 07:06:06 -0700 (PDT) From: Alex Elder To: mturquette@linaro.org, mporter@linaro.org, bcm@fixthebug.org Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 3/5] clk: bcm281xx: add bus clock support Date: Thu, 29 May 2014 09:05:59 -0500 Message-Id: <1401372361-18842-4-git-send-email-elder@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1401372361-18842-1-git-send-email-elder@linaro.org> References: <1401372361-18842-1-git-send-email-elder@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: elder@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.176 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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 | 58 ++++++++++++++++++++++++ drivers/clk/bcm/clk-kona.h | 8 ++++ 3 files changed, 159 insertions(+), 3 deletions(-) diff --git a/drivers/clk/bcm/clk-kona-setup.c b/drivers/clk/bcm/clk-kona-setup.c index e5aeded..c2d83cf 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 d08b3e9..cd040aa 100644 --- a/drivers/clk/bcm/clk-kona.c +++ b/drivers/clk/bcm/clk-kona.c @@ -986,6 +986,36 @@ static int selector_write(struct ccu_data *ccu, struct bcm_clk_gate *gate, /* Clock operations */ +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 = { + .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); @@ -1196,6 +1226,31 @@ struct clk_ops kona_peri_clk_ops = { .set_rate = kona_peri_clk_set_rate, }; +/* 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) { @@ -1300,6 +1355,9 @@ static bool __kona_clk_init(struct kona_clk *bcm_clk) return false; switch (bcm_clk->type) { + case bcm_clk_bus: + ret = __bus_clk_init(bcm_clk); + break; case bcm_clk_peri: ret = __peri_clk_init(bcm_clk); break; diff --git a/drivers/clk/bcm/clk-kona.h b/drivers/clk/bcm/clk-kona.h index be00767..02041d2 100644 --- a/drivers/clk/bcm/clk-kona.h +++ b/drivers/clk/bcm/clk-kona.h @@ -389,6 +389,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; @@ -415,6 +421,7 @@ struct kona_clk { } p; union { void *data; + struct bus_clk_data *bus; struct peri_clk_data *peri; } u; }; @@ -519,6 +526,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 */