From patchwork Wed Feb 26 00:15:49 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 3719631 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 3D7EA9F2ED for ; Wed, 26 Feb 2014 00:20:12 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2D187201EF for ; Wed, 26 Feb 2014 00:20:11 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (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 EDA7820166 for ; Wed, 26 Feb 2014 00:20:09 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WISCP-0004jA-9g; Wed, 26 Feb 2014 00:18:10 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WISBm-0004N2-8I; Wed, 26 Feb 2014 00:17:30 +0000 Received: from mail-ie0-f173.google.com ([209.85.223.173]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WISAi-0004Dl-IJ for linux-arm-kernel@lists.infradead.org; Wed, 26 Feb 2014 00:16:34 +0000 Received: by mail-ie0-f173.google.com with SMTP id lx4so62983iec.18 for ; Tue, 25 Feb 2014 16:16:03 -0800 (PST) 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=jhefB39Vh7eVom8unHRhnLIRwgG4G/+vmRCyLgIdib0=; b=CKrWAwoTj/Emx5RhS7XUQpHKZSBIXvmUNCgxPpytgfomJIdz5VcVThl2/s2avynpT8 /fVZ6VoZvlhe+zGJ1ec+goKdZXGhYcW4GF5vN/H2zKmVa2SamrpDf7XNS8sGZYSbvJYi l2MtroPbUpSZ398rq46oWAIQA2zHYc5ebgRxpSXjinEpeJiOMJR+zvFfxe4nmYd1RfYb p44nfnmTStrsjXFE7ZqmRFU7VtWL1KbIkFRHyGu2ok3VKm9XCLwtXSWrLu14Vbvrn4IP PLhsocArfubsoNmTvdrlVU04VLQS8YKZdMzBSp8AEbuD5jBi6a/f71IaZ5Sv+eR95yLj 4JaA== X-Gm-Message-State: ALoCoQnrlWRs3RhLr8Qy+wilSuZE4duqS6JB/eGZt3PKNFVbWCcGMyYCL7n5ixY/xN2MZcQTiwpl X-Received: by 10.42.226.8 with SMTP id iu8mr2698773icb.7.1393373763616; Tue, 25 Feb 2014 16:16:03 -0800 (PST) Received: from localhost.localdomain (c-71-195-31-37.hsd1.mn.comcast.net. [71.195.31.37]) by mx.google.com with ESMTPSA id om7sm91459igb.10.2014.02.25.16.16.01 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 25 Feb 2014 16:16:02 -0800 (PST) From: Alex Elder To: mturquette@linaro.org, mporter@linaro.org, bcm@fixthebug.org, galak@codeaurora.org, ijc+devicetree@hellion.org.uk, mark.rutland@arm.com, pawel.moll@arm.com, robh+dt@kernel.org Subject: [PATCH v2 09/12] clk: bcm281xx: implement prerequisite clocks Date: Tue, 25 Feb 2014 18:15:49 -0600 Message-Id: <1393373752-30875-10-git-send-email-elder@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1393373752-30875-1-git-send-email-elder@linaro.org> References: <1393373752-30875-1-git-send-email-elder@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140225_191624_760408_AF1F5B58 X-CRM114-Status: GOOD ( 19.04 ) X-Spam-Score: 0.5 (/) Cc: devicetree@vger.kernel.org, bcm-kernel-feedback-list@broadcom.com, 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=-1.1 required=5.0 tests=BAYES_00,KHOP_BIG_TO_CC, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=no 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. The prerequisite clock must be initialized before the clock that depends on it. A prerequisite clock is defined initially by its name; as that clock gets initialized the name gets replaced with a pointer to its clock structure pointer. In order to allow getting a reference to a clock by its name we call clkdev_add() for each clock as it gets set up. A new clk_lookup structure is added to the kona_clk type for this purpose. Rework the KONA_CLK() macro, and define a new KONA_CLK_PREREQ() variant that allows a prerequisite clock to be specified. There exist clocks that could specify more than one prequisite, but almost all clocks only ever use one. We can add support for more than one if we find we need it at some point. Signed-off-by: Alex Elder --- drivers/clk/bcm/clk-kona-setup.c | 16 ++++++++++---- drivers/clk/bcm/clk-kona.c | 45 ++++++++++++++++++++++++++++++++++++++ drivers/clk/bcm/clk-kona.h | 20 ++++++++++++++--- 3 files changed, 74 insertions(+), 7 deletions(-) diff --git a/drivers/clk/bcm/clk-kona-setup.c b/drivers/clk/bcm/clk-kona-setup.c index 757de19..973053b 100644 --- a/drivers/clk/bcm/clk-kona-setup.c +++ b/drivers/clk/bcm/clk-kona-setup.c @@ -685,6 +685,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) { + /* There is no function defined for this (yet) */ + /* clkdev_remove(&bcm_clk->cl); */ + switch (bcm_clk->type) { case bcm_clk_peri: peri_clk_teardown(bcm_clk->data, &bcm_clk->init_data); @@ -718,6 +721,7 @@ static void kona_clk_teardown(struct clk *clk) struct clk *kona_clk_setup(struct kona_clk *bcm_clk) { struct clk_init_data *init_data = &bcm_clk->init_data; + const char *name = init_data->name; struct clk *clk = NULL; switch (bcm_clk->type) { @@ -727,14 +731,13 @@ struct clk *kona_clk_setup(struct kona_clk *bcm_clk) break; default: pr_err("%s: clock type %d invalid for %s\n", __func__, - (int)bcm_clk->type, init_data->name); + (int)bcm_clk->type, name); return NULL; } /* Make sure everything makes sense before we set it up */ if (!kona_clk_valid(bcm_clk)) { - pr_err("%s: clock data invalid for %s\n", __func__, - init_data->name); + pr_err("%s: clock data invalid for %s\n", __func__, name); goto out_teardown; } @@ -742,11 +745,16 @@ struct clk *kona_clk_setup(struct kona_clk *bcm_clk) clk = clk_register(NULL, &bcm_clk->hw); if (IS_ERR(clk)) { pr_err("%s: error registering clock %s (%ld)\n", __func__, - init_data->name, PTR_ERR(clk)); + name, PTR_ERR(clk)); goto out_teardown; } BUG_ON(!clk); + /* Make it so we can look the clock up using clk_find() */ + bcm_clk->cl.con_id = name; + bcm_clk->cl.clk = clk; + clkdev_add(&bcm_clk->cl); + return clk; out_teardown: bcm_clk_teardown(bcm_clk); diff --git a/drivers/clk/bcm/clk-kona.c b/drivers/clk/bcm/clk-kona.c index 6caed3b..37f7861 100644 --- a/drivers/clk/bcm/clk-kona.c +++ b/drivers/clk/bcm/clk-kona.c @@ -1193,6 +1193,48 @@ static bool __peri_clk_init(struct kona_clk *bcm_clk) return true; } +static bool __kona_clk_init(struct kona_clk *bcm_clk); +static bool __kona_prereq_init(struct kona_clk *bcm_clk) +{ + struct clk *clk; + struct clk_hw *hw; + struct kona_clk *prereq; + + BUG_ON(clk_is_initialized(bcm_clk)); + + if (!bcm_clk->prereq) + return true; + + clk = clk_get(NULL, bcm_clk->prereq); + if (IS_ERR(clk)) { + pr_err("%s: unable to get prereq clock %s for %s\n", + __func__, bcm_clk->prereq, bcm_clk->init_data.name); + return false; + } + hw = __clk_get_hw(clk); + if (!hw) { + pr_err("%s: null hw pointer for clock %s\n", __func__, + bcm_clk->init_data.name); + return false; + } + prereq = to_kona_clk(hw); + if (prereq->ccu != bcm_clk->ccu) { + pr_err("%s: prereq clock %s CCU different for clock %s\n", + __func__, bcm_clk->prereq, bcm_clk->init_data.name); + return false; + } + + /* Initialize the prerequisite clock first */ + if (!__kona_clk_init(prereq)) { + pr_err("%s: failed to init prereq %s for clock %s\n", + __func__, bcm_clk->prereq, bcm_clk->init_data.name); + return false; + } + bcm_clk->prereq_clk = clk; + + return true; +} + static bool __kona_clk_init(struct kona_clk *bcm_clk) { bool ret = false; @@ -1200,6 +1242,9 @@ static bool __kona_clk_init(struct kona_clk *bcm_clk) if (clk_is_initialized(bcm_clk)) return true; + if (!__kona_prereq_init(bcm_clk)) + return false; + switch (bcm_clk->type) { case bcm_clk_peri: ret = __peri_clk_init(bcm_clk); diff --git a/drivers/clk/bcm/clk-kona.h b/drivers/clk/bcm/clk-kona.h index 01fa776..27e0913 100644 --- a/drivers/clk/bcm/clk-kona.h +++ b/drivers/clk/bcm/clk-kona.h @@ -22,6 +22,8 @@ #include #include #include +#include +#include #define BILLION 1000000000 @@ -407,6 +409,11 @@ 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 clk_lookup cl; + union { + const char *prereq; + struct clk *prereq_clk; + }; union { void *data; struct peri_clk_data *peri; @@ -422,15 +429,22 @@ 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, \ - .data = &_clk_name ## _data, \ + .data = &_clk_name ## _data +#define KONA_CLK_PREREQ(_ccu_name, _clk_name, _type, _prereq) \ + { \ + .prereq = #_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 }