From patchwork Thu Jun 12 16:53:42 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grygorii Strashko X-Patchwork-Id: 4343161 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id E17FEBEEAA for ; Thu, 12 Jun 2014 16:08:32 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1C4A1202DD for ; Thu, 12 Jun 2014 16:08:32 +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 44DE9201C7 for ; Thu, 12 Jun 2014 16:08:31 +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 1Wv7W8-0002Q7-SO; Thu, 12 Jun 2014 16:06:20 +0000 Received: from comal.ext.ti.com ([198.47.26.152]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Wv7W2-0002JW-IT for linux-arm-kernel@lists.infradead.org; Thu, 12 Jun 2014 16:06:15 +0000 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by comal.ext.ti.com (8.13.7/8.13.7) with ESMTP id s5CG5kME000813; Thu, 12 Jun 2014 11:05:46 -0500 Received: from DLEE70.ent.ti.com (dlee70.ent.ti.com [157.170.170.113]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id s5CG5kV0007695; Thu, 12 Jun 2014 11:05:46 -0500 Received: from dlep32.itg.ti.com (157.170.170.100) by DLEE70.ent.ti.com (157.170.170.113) with Microsoft SMTP Server id 14.3.174.1; Thu, 12 Jun 2014 11:05:46 -0500 Received: from localhost (dlep60.itg.ti.com [157.170.170.21]) by dlep32.itg.ti.com (8.14.3/8.13.8) with ESMTP id s5CG5gFT002062; Thu, 12 Jun 2014 11:05:44 -0500 From: Grygorii Strashko To: Subject: [RFC PATCH 1/2] clk: of: introduce of_clk_get_from_set() Date: Thu, 12 Jun 2014 19:53:42 +0300 Message-ID: <1402592023-13416-2-git-send-email-grygorii.strashko@ti.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1402592023-13416-1-git-send-email-grygorii.strashko@ti.com> References: <1398334403-26181-1-git-send-email-geert+renesas@glider.be> <1402592023-13416-1-git-send-email-grygorii.strashko@ti.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140612_090614_710206_81D1388C X-CRM114-Status: GOOD ( 12.30 ) X-Spam-Score: -5.7 (-----) Cc: devicetree@vger.kernel.org, ulf.hansson@linaro.org, khilman@linaro.org, mturquette@linaro.org, horms@verge.net.au, linux-sh@vger.kernel.org, rjw@rjwysocki.net, linux-pm@vger.kernel.org, magnus.damm@gmail.com, tomasz.figa@gmail.com, linux-kernel@vger.kernel.org, grant.likely@secretlab.ca, ben.dooks@codethink.co.uk, laurent.pinchart@ideasonboard.com, Grygorii Strashko , linux-omap@vger.kernel.org, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , 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.5 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD, 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 In many case it's useful to divide device's clocks into few sets according to their designation. - some clocks can be optional for the device - some clocks can be managed by PM frameworks (like clock_ops for example) while some need to be managed by driver directly. This patch introduces new API of_clk_get_from_set() which allows the callers to specify additional prefix to be used together with generic DT clocks list property name "clocks". In the example bellow, the caller asks CLK framework to retrieve clock from the clocks list "clkops-clocks" and not from "clocks": DT: usb: usb@2680000 { compatible = "ti,keystone-dwc3"; [...] clkops-clocks = <&clkusb>; Code: clk = of_clk_get_from_set(np, "clkops", 0); This changes will not affect on already existed code. Signed-off-by: Grygorii Strashko --- drivers/clk/clkdev.c | 24 ++++++++++++++++++++++-- include/linux/clk.h | 7 +++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/drivers/clk/clkdev.c b/drivers/clk/clkdev.c index f890b90..2308518 100644 --- a/drivers/clk/clkdev.c +++ b/drivers/clk/clkdev.c @@ -53,7 +53,8 @@ struct clk *of_clk_get_by_clkspec(struct of_phandle_args *clkspec) return clk; } -struct clk *of_clk_get(struct device_node *np, int index) +static struct clk *of_clk_get_named(struct device_node *np, + const char *propname, int index) { struct of_phandle_args clkspec; struct clk *clk; @@ -62,7 +63,7 @@ struct clk *of_clk_get(struct device_node *np, int index) if (index < 0) return ERR_PTR(-EINVAL); - rc = of_parse_phandle_with_args(np, "clocks", "#clock-cells", index, + rc = of_parse_phandle_with_args(np, propname, "#clock-cells", index, &clkspec); if (rc) return ERR_PTR(rc); @@ -71,8 +72,27 @@ struct clk *of_clk_get(struct device_node *np, int index) of_node_put(clkspec.np); return clk; } + +struct clk *of_clk_get(struct device_node *np, int index) +{ + return of_clk_get_named(np, "clocks", index); +} EXPORT_SYMBOL(of_clk_get); +struct clk *of_clk_get_from_set(struct device_node *np, + const char *set_id, int index) +{ + char prop_name[32]; /* 32 is max size of property name */ + + if (set_id) + snprintf(prop_name, 32, "%s-clocks", set_id); + else + snprintf(prop_name, 32, "clocks"); + + return of_clk_get_named(np, prop_name, index); +} +EXPORT_SYMBOL(of_clk_get_from_set); + /** * of_clk_get_by_name() - Parse and lookup a clock referenced by a device node * @np: pointer to clock consumer node diff --git a/include/linux/clk.h b/include/linux/clk.h index fb5e097..fc8865a 100644 --- a/include/linux/clk.h +++ b/include/linux/clk.h @@ -397,6 +397,8 @@ struct of_phandle_args; #if defined(CONFIG_OF) && defined(CONFIG_COMMON_CLK) struct clk *of_clk_get(struct device_node *np, int index); +struct clk *of_clk_get_from_set(struct device_node *np, + const char *set_id, int index); struct clk *of_clk_get_by_name(struct device_node *np, const char *name); struct clk *of_clk_get_from_provider(struct of_phandle_args *clkspec); #else @@ -409,6 +411,11 @@ static inline struct clk *of_clk_get_by_name(struct device_node *np, { return ERR_PTR(-ENOENT); } +static inline struct clk *of_clk_get_from_set(struct device_node *np, + const char *set_id, int index) +{ + return ERR_PTR(-ENOENT); +} #endif #endif