From patchwork Sun May 11 20:24:34 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Hesselbarth X-Patchwork-Id: 4152411 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 E99DA9F170 for ; Sun, 11 May 2014 20:28:41 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 108BD20165 for ; Sun, 11 May 2014 20:28:41 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (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 38B8F20131 for ; Sun, 11 May 2014 20:28:40 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WjaJK-0003hk-2U; Sun, 11 May 2014 20:25:26 +0000 Received: from mail-ee0-x235.google.com ([2a00:1450:4013:c00::235]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WjaJ6-0002W7-1v for linux-arm-kernel@lists.infradead.org; Sun, 11 May 2014 20:25:13 +0000 Received: by mail-ee0-f53.google.com with SMTP id c13so4048148eek.26 for ; Sun, 11 May 2014 13:24:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=VctKUBxnVACBaZNptK9giFMAZEmLnV9UVHpplOiUlqo=; b=AeLlTtjm4b4WKfT4VMT1e740xqQc7lL8tXE2xvW99Wh3ni0jjl6ujglTh/bGYne/Gy i1q/fs7AKEpixZ5wEAoBslglH0nxMHz6ipKkDtngiIpJLf5RbB8jpgnfZq3ocXc2/qQx HfXi/qtl0nHbGqS9IBTxMAsqXtNTzrMnUOb65W67xBBoNlicU3f9JuyZoNEIPToAZN2A 3e7JptiKjSQIbAVNO4cEyhE85QpXEG+PMol0iVargEuo0kiAdi7NoFfUF1lEsVo0o5CU Kwkjk94TWkdzgeFgxwhJXH9XRQXjbRx+E2eYn9UG6WGKCqzIoWjjTuGF2ZFm9r3kc6Hr Jk2Q== X-Received: by 10.14.53.66 with SMTP id f42mr12085086eec.70.1399839889630; Sun, 11 May 2014 13:24:49 -0700 (PDT) Received: from topkick.lan (dslc-082-083-214-144.pools.arcor-ip.net. [82.83.214.144]) by mx.google.com with ESMTPSA id w48sm27790600eel.9.2014.05.11.13.24.47 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 11 May 2014 13:24:48 -0700 (PDT) From: Sebastian Hesselbarth To: Sebastian Hesselbarth Subject: [PATCH 1/8] clk: add helper for unique DT clock names Date: Sun, 11 May 2014 22:24:34 +0200 Message-Id: <1399839881-29895-2-git-send-email-sebastian.hesselbarth@gmail.com> In-Reply-To: <1399839881-29895-1-git-send-email-sebastian.hesselbarth@gmail.com> References: <1399839881-29895-1-git-send-email-sebastian.hesselbarth@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140511_132512_293278_F137EE47 X-CRM114-Status: GOOD ( 13.44 ) X-Spam-Score: -0.1 (/) Cc: devicetree@vger.kernel.org, Mike Turquette , Antoine Tenart , linux-kernel@vger.kernel.org, Rob Herring , Alexandre Belloni , Grant Likely , 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=-2.4 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable 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 Currently, most DT clock drivers pick a unique node name to allow unique clock names. As ePAPR recommends node names to be generic, we therefore provide a helper to generate a unique clock name from the DT node name plus reg property or a magic number instead. This is basically the same we already do for proper devices and may vanish as soon as there is some (early) device support for clocks available. Signed-off-by: Sebastian Hesselbarth --- Cc: Mike Turquette Cc: Grant Likely Cc: Rob Herring Cc: Alexandre Belloni Cc: Antoine Tenart Cc: devicetree@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org --- drivers/clk/clk.c | 29 +++++++++++++++++++++++++++++ include/linux/clk-provider.h | 5 +++++ 2 files changed, 34 insertions(+) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index dff0373f53c1..b449a635dbfa 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -2543,6 +2544,34 @@ const char *of_clk_get_parent_name(struct device_node *np, int index) } EXPORT_SYMBOL_GPL(of_clk_get_parent_name); +/** + * of_clk_create_name() - Allocate and create a unique clock name + * @np: Device node pointer of the clock node + * + * This will allocate and create a unique clock name based on the + * reg property value. As a last resort, it will use the node name + * followed by a unique number. The caller has to deallocate the + * buffer. + */ +char *of_clk_create_name(struct device_node *np) +{ + static atomic_t clk_no_reg_magic; + const __be32 *reg; + u64 addr; + int magic; + + reg = of_get_property(np, "reg", NULL); + if (reg) { + addr = of_translate_address(np, reg); + return kasprintf(GFP_KERNEL, "%llx.%s", + (unsigned long long)addr, np->name); + } + + magic = atomic_add_return(1, &clk_no_reg_magic); + return kasprintf(GFP_KERNEL, "%s.%d", np->name, magic); +} +EXPORT_SYMBOL_GPL(of_clk_create_name); + struct clock_provider { of_clk_init_cb_t clk_init_cb; struct device_node *np; diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h index 511917416fb0..c6f3ca1cd81c 100644 --- a/include/linux/clk-provider.h +++ b/include/linux/clk-provider.h @@ -514,6 +514,7 @@ 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); +char *of_clk_create_name(struct device_node *np); void of_clk_init(const struct of_device_id *matches); @@ -543,6 +544,10 @@ static inline const char *of_clk_get_parent_name(struct device_node *np, { return NULL; } +static inline char *of_clk_create_name(struct device_node *np) +{ + return NULL; +} #define of_clk_init(matches) \ { while (0); } #endif /* CONFIG_OF */