From patchwork Thu Feb 13 09:00:46 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tero Kristo X-Patchwork-Id: 24577 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f198.google.com (mail-ob0-f198.google.com [209.85.214.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 5CE8D202B2 for ; Thu, 13 Feb 2014 09:01:36 +0000 (UTC) Received: by mail-ob0-f198.google.com with SMTP id wp4sf39305305obc.9 for ; Thu, 13 Feb 2014 01:01:35 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe:content-type; bh=zuj7Tn7XNFlSScfc1aUGnpAUnwCiZ4iex+L77RUWdH0=; b=QFqAD2UiEbTLydZtmOCZ5WBGwAUoAavyAp157yj+NdyYrZLaQ/4g08vqwHbgL8hMHd g3GiaUyAQwBGLT6KEBI12Fk8w2QyFERvfcXKVgbXGOq+yV0DMRQ9Fj0p7ecQ+KCoXM3k 2PSne/Sam2tAI8H5E2l8TeXUcXC1wGZ120J/iH7M6u0bCdD8o5zXZUQdJG9vYnt1VAry BBKhq2qch5AV9ET2azWCLjg4hvAKxxmRcbJ1eQ/1RqZh1bdH0JQdKMDZouLzjzxnyiSA vEWS2AcOwQGrf0Sa9fIQAtrD2LXDiFmEmiruTIDKVRXduZrvwaD/9Zgc/HdNgOMhl1vk k1Lw== X-Gm-Message-State: ALoCoQnXXvek768BjrNkpCAEL9Ix4+dyUtNnDihQ/O7qAPkBBafZSvrzjOIlsqL+vLD3KGSJ8pUY X-Received: by 10.182.111.227 with SMTP id il3mr94791obb.41.1392282095446; Thu, 13 Feb 2014 01:01:35 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.51.130 with SMTP id u2ls2049936qga.34.gmail; Thu, 13 Feb 2014 01:01:35 -0800 (PST) X-Received: by 10.52.179.198 with SMTP id di6mr107130vdc.7.1392282095326; Thu, 13 Feb 2014 01:01:35 -0800 (PST) Received: from mail-vc0-f174.google.com (mail-vc0-f174.google.com [209.85.220.174]) by mx.google.com with ESMTPS id h13si424269vct.143.2014.02.13.01.01.35 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 13 Feb 2014 01:01:35 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.174 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.174; Received: by mail-vc0-f174.google.com with SMTP id im17so8015085vcb.33 for ; Thu, 13 Feb 2014 01:01:35 -0800 (PST) X-Received: by 10.58.155.162 with SMTP id vx2mr143768veb.46.1392282095232; Thu, 13 Feb 2014 01:01:35 -0800 (PST) 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.174.196 with SMTP id u4csp10093vcz; Thu, 13 Feb 2014 01:01:34 -0800 (PST) X-Received: by 10.68.43.2 with SMTP id s2mr493754pbl.60.1392282093834; Thu, 13 Feb 2014 01:01:33 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id gz8si1352577pac.56.2014.02.13.01.01.33; Thu, 13 Feb 2014 01:01:33 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-omap-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753460AbaBMJBc (ORCPT + 5 others); Thu, 13 Feb 2014 04:01:32 -0500 Received: from arroyo.ext.ti.com ([192.94.94.40]:55186 "EHLO arroyo.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753423AbaBMJBb (ORCPT ); Thu, 13 Feb 2014 04:01:31 -0500 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by arroyo.ext.ti.com (8.13.7/8.13.7) with ESMTP id s1D9169r013704; Thu, 13 Feb 2014 03:01:06 -0600 Received: from DFLE72.ent.ti.com (dfle72.ent.ti.com [128.247.5.109]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id s1D9162N012591; Thu, 13 Feb 2014 03:01:06 -0600 Received: from dlep33.itg.ti.com (157.170.170.75) by DFLE72.ent.ti.com (128.247.5.109) with Microsoft SMTP Server id 14.3.174.1; Thu, 13 Feb 2014 03:01:06 -0600 Received: from localhost.localdomain (ileax41-snat.itg.ti.com [10.172.224.153]) by dlep33.itg.ti.com (8.14.3/8.13.8) with ESMTP id s1D911bk021319; Thu, 13 Feb 2014 03:01:05 -0600 From: Tero Kristo To: , CC: , Subject: [PATCH 2/4] clk: add support for default-rate Date: Thu, 13 Feb 2014 11:00:46 +0200 Message-ID: <1392282048-6284-3-git-send-email-t-kristo@ti.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1392282048-6284-1-git-send-email-t-kristo@ti.com> References: <1392282048-6284-1-git-send-email-t-kristo@ti.com> MIME-Version: 1.0 Sender: linux-omap-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: t-kristo@ti.com X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.174 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) 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: , default-rate property can now be used to set initial rates for clocks. This is added by default for all clocks which get initialized through of_clk_init(). Signed-off-by: Tero Kristo --- .../devicetree/bindings/clock/clock-bindings.txt | 9 ++ drivers/clk/clk.c | 86 ++++++++++++++++++++ include/linux/clk-provider.h | 2 + 3 files changed, 97 insertions(+) diff --git a/Documentation/devicetree/bindings/clock/clock-bindings.txt b/Documentation/devicetree/bindings/clock/clock-bindings.txt index 7c52c29..d676112 100644 --- a/Documentation/devicetree/bindings/clock/clock-bindings.txt +++ b/Documentation/devicetree/bindings/clock/clock-bindings.txt @@ -44,6 +44,15 @@ For example: clocks by index. The names should reflect the clock output signal names for the device. +default-rate: Sets the rate of the clock during boot to the provided + rate. + +For example: + + clk-divider { + default-rate = <1000000>; + }; + ==Clock consumers== Required properties: diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 5517944..cb144e4 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -2526,6 +2526,89 @@ const char *of_clk_get_parent_name(struct device_node *np, int index) } EXPORT_SYMBOL_GPL(of_clk_get_parent_name); +static LIST_HEAD(clk_init_info_list); + +struct clk_init_info { + struct device_node *node; + struct clk *clk; + u32 rate; + struct list_head link; + struct list_head sort_link; +}; + +int __init of_clk_parse_init_rate(struct device_node *node, struct clk *clk) +{ + u32 rate; + struct clk_init_info *cinfo; + + if (of_property_read_u32(node, "default-rate", &rate)) + return 0; + + cinfo = kzalloc(sizeof(*cinfo), GFP_KERNEL); + if (!cinfo) + return -ENOMEM; + + cinfo->node = node; + cinfo->clk = clk; + cinfo->rate = rate; + list_add(&cinfo->link, &clk_init_info_list); + INIT_LIST_HEAD(&cinfo->sort_link); + + return 0; +} + +int __init of_clk_set_init_rates(void) +{ + struct clk_init_info *cinfo, *tmp; + struct of_phandle_args clkspec; + int ret = 0; + struct list_head sorted_list; + struct clk *clk; + + INIT_LIST_HEAD(&sorted_list); + + list_for_each_entry(cinfo, &clk_init_info_list, link) { + /* Get missing clk pointers */ + if (!cinfo->clk) { + clkspec.np = cinfo->node; + cinfo->clk = of_clk_get_from_provider(&clkspec); + } + + /* Check if we are the parent of any of the sorted clocks */ + list_for_each_entry(tmp, &sorted_list, sort_link) { + clk = tmp->clk; + while (clk && clk != cinfo->clk) + clk = clk->parent; + + if (clk == cinfo->clk) { + /* Add us before this node in the list */ + list_add_tail(&cinfo->sort_link, + &tmp->sort_link); + break; + } + } + + if (list_empty(&cinfo->sort_link)) + list_add_tail(&cinfo->sort_link, &sorted_list); + } + + /* Process sorted list and set clk rates */ + list_for_each_entry_safe(cinfo, tmp, &sorted_list, sort_link) { + int r = clk_set_rate(cinfo->clk, cinfo->rate); + if (r) { + pr_err("%s: clk_set_rate for %s failed: %d\n", __func__, + cinfo->node->name, ret); + ret = r; + } + + /* Clean up the static list */ + list_del(&cinfo->link); + kfree(cinfo); + } + + return ret; +} + /** * of_clk_init() - Scan and init clock providers from the DT * @matches: array of compatible values and init functions for providers. @@ -2544,6 +2627,9 @@ void __init of_clk_init(const struct of_device_id *matches) for_each_matching_node_and_match(np, matches, &match) { of_clk_init_cb_t clk_init_cb = match->data; clk_init_cb(np); + of_clk_parse_init_rate(np, NULL); } + + of_clk_set_init_rates(); } #endif diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h index 939533d..1bbd194 100644 --- a/include/linux/clk-provider.h +++ b/include/linux/clk-provider.h @@ -506,6 +506,8 @@ struct clk *of_clk_src_simple_get(struct of_phandle_args *clkspec, struct clk *of_clk_src_onecell_get(struct of_phandle_args *clkspec, void *data); int of_clk_get_parent_count(struct device_node *np); const char *of_clk_get_parent_name(struct device_node *np, int index); +int of_clk_parse_init_rate(struct device_node *node, struct clk *clk); +int of_clk_set_init_rates(void); void of_clk_init(const struct of_device_id *matches);