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: 31224 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oa0-f69.google.com (mail-oa0-f69.google.com [209.85.219.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id CDEE520671 for ; Fri, 30 May 2014 20:53:41 +0000 (UTC) Received: by mail-oa0-f69.google.com with SMTP id i7sf11404059oag.0 for ; Fri, 30 May 2014 13:53:41 -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=eK8Q6WqQVrmXLVWPVUdcs8W3PKAgG71+zhzmmk4yO2s=; b=FuJNGgSi4Dl0+Q/8DaqfM6WpzlF7xtU0jIJm5Srt8kZcFhMoNO/MVzXHXuNzbz4Ynr W53JQIe2JbCNZv5CbKmflbHFTHWxKpIl5pNS1jXvA2ba59YeWQyehxGkCPVAOcaKmzgS sjyjNXqQoI/ILTRLqXspmaEYiFE8eAa50jof7uG4xWCgECWdQ65O7DwAvjtNxiMS37fv YZT4x8HrgRmmtsPw2/bmNCC2dzQbFgFCnSY3gwqH2GgYyt00TCEEwERCtWrtDHuxI+4Z JXPJZYjslrSvpRl0w1Xd5wbeu1Ab6SN7XLlJs//WWBc/lwCcJg2VnDeE+qnSEffnC2B2 OvZg== X-Gm-Message-State: ALoCoQmtSR/3NdijNQbQ1Rjxw13NvscCO/qDm+ki3VDbdOBN9reaf3S3K2CNC2Trs7gHHazDVwyX X-Received: by 10.42.19.73 with SMTP id a9mr6191934icb.31.1401483221324; Fri, 30 May 2014 13:53:41 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.21.85 with SMTP id 79ls1338588qgk.41.gmail; Fri, 30 May 2014 13:53:41 -0700 (PDT) X-Received: by 10.58.195.130 with SMTP id ie2mr16469100vec.3.1401483221111; Fri, 30 May 2014 13:53:41 -0700 (PDT) Received: from mail-vc0-f170.google.com (mail-vc0-f170.google.com [209.85.220.170]) by mx.google.com with ESMTPS id e8si4074749vdv.65.2014.05.30.13.53.41 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 30 May 2014 13:53:41 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.170 as permitted sender) client-ip=209.85.220.170; Received: by mail-vc0-f170.google.com with SMTP id la4so2717881vcb.15 for ; Fri, 30 May 2014 13:53:41 -0700 (PDT) X-Received: by 10.58.185.165 with SMTP id fd5mr4560427vec.41.1401483221010; Fri, 30 May 2014 13:53:41 -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 ib8csp140946vcb; Fri, 30 May 2014 13:53:40 -0700 (PDT) X-Received: by 10.67.2.34 with SMTP id bl2mr21372450pad.58.1401483219930; Fri, 30 May 2014 13:53:39 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bu1si7051218pbc.136.2014.05.30.13.53.39; Fri, 30 May 2014 13:53:39 -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 S934515AbaE3UxR (ORCPT + 28 others); Fri, 30 May 2014 16:53:17 -0400 Received: from mail-ie0-f182.google.com ([209.85.223.182]:59509 "EHLO mail-ie0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754460AbaE3UxP (ORCPT ); Fri, 30 May 2014 16:53:15 -0400 Received: by mail-ie0-f182.google.com with SMTP id x19so2322837ier.13 for ; Fri, 30 May 2014 13:53:15 -0700 (PDT) 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 Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.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> 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.220.170 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: , 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 } /*