From patchwork Mon Jun 2 22:44:55 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 31311 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f198.google.com (mail-ie0-f198.google.com [209.85.223.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 4F8B320AE6 for ; Mon, 2 Jun 2014 22:46:35 +0000 (UTC) Received: by mail-ie0-f198.google.com with SMTP id tp5sf30620519ieb.5 for ; Mon, 02 Jun 2014 15:46:35 -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=9WJgNMnfUHQovyr8YNhc+Bn79084eEj6jJqll9vhZ9Q=; b=IEg76Sr/VRRqjF1zJBqUjDynCCq45IkIhpmL5an3Pi1hjLEdEbgnDQAARv1t2/D85o nfbfk3/v9vtufVVmiRUK3zvQIVqYd75NNFqqLPz7WO2ycIIUPaCEjBahD5P1I1Nj+i8s V80rcrLizUtJt+Qn/xpSXKHxCITCt6n+iApSs0/0w+m5Haoe8r7N5yZabnwMwqyJB6wk Z9yOtLHds528QahSDspYUEy4Xxi9aYpq4ylhnJyGKOhDuMiJwpFpGgr5rxGLJPF+vtfd DBJvsonCHkdIuDhnlRaNBRvpqUFbmiL3GgkxmAdZpIXYTEl3Q/CBUuR7YAEenbMRZEAy AGUQ== X-Gm-Message-State: ALoCoQmxWvgA3G+KqwbPgQANhC3/xzKaA7LWxhZIkO6z6b3dJM4Kh20LRpBwq6mvmNEBmgq5M/3I X-Received: by 10.182.24.104 with SMTP id t8mr16025362obf.34.1401749195519; Mon, 02 Jun 2014 15:46:35 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.108.229 with SMTP id j92ls2176143qgf.14.gmail; Mon, 02 Jun 2014 15:46:35 -0700 (PDT) X-Received: by 10.52.125.198 with SMTP id ms6mr26899270vdb.28.1401749195360; Mon, 02 Jun 2014 15:46:35 -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 fe3si8833883vec.43.2014.06.02.15.46.35 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 02 Jun 2014 15:46:35 -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 jz11so5948753veb.21 for ; Mon, 02 Jun 2014 15:46:35 -0700 (PDT) X-Received: by 10.221.9.72 with SMTP id ov8mr8790503vcb.27.1401749195264; Mon, 02 Jun 2014 15:46:35 -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 ib8csp132167vcb; Mon, 2 Jun 2014 15:46:34 -0700 (PDT) X-Received: by 10.68.143.65 with SMTP id sc1mr44322136pbb.93.1401749194331; Mon, 02 Jun 2014 15:46:34 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id dy1si13504412pab.91.2014.06.02.15.46.33; Mon, 02 Jun 2014 15:46:33 -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 S932228AbaFBWqT (ORCPT + 27 others); Mon, 2 Jun 2014 18:46:19 -0400 Received: from mail-ig0-f179.google.com ([209.85.213.179]:37698 "EHLO mail-ig0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752981AbaFBWpA (ORCPT ); Mon, 2 Jun 2014 18:45:00 -0400 Received: by mail-ig0-f179.google.com with SMTP id hn18so4039867igb.6 for ; Mon, 02 Jun 2014 15:44:59 -0700 (PDT) X-Received: by 10.50.62.104 with SMTP id x8mr23041235igr.37.1401749099787; Mon, 02 Jun 2014 15:44:59 -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.58 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 02 Jun 2014 15:44:59 -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 v5 4/7] clk: bcm281xx: implement prerequisite clocks Date: Mon, 2 Jun 2014 17:44:55 -0500 Message-Id: <1401749098-10185-5-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> 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: , 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 } /*