From patchwork Thu Dec 19 11:23:32 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tero Kristo X-Patchwork-Id: 3377011 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 CD92BC0D4A for ; Thu, 19 Dec 2013 11:26:42 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 13E1320627 for ; Thu, 19 Dec 2013 11:26:38 +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 308EA20619 for ; Thu, 19 Dec 2013 11:26:33 +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 1Vtbje-0007NL-2f; Thu, 19 Dec 2013 11:25:46 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VtbjS-0004CH-HZ; Thu, 19 Dec 2013 11:25:34 +0000 Received: from devils.ext.ti.com ([198.47.26.153]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Vtbiv-00044o-HO for linux-arm-kernel@lists.infradead.org; Thu, 19 Dec 2013 11:25:04 +0000 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by devils.ext.ti.com (8.13.7/8.13.7) with ESMTP id rBJBOcJW009912; Thu, 19 Dec 2013 05:24:38 -0600 Received: from DFLE73.ent.ti.com (dfle73.ent.ti.com [128.247.5.110]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id rBJBOcNJ014810; Thu, 19 Dec 2013 05:24:38 -0600 Received: from dflp33.itg.ti.com (10.64.6.16) by DFLE73.ent.ti.com (128.247.5.110) with Microsoft SMTP Server id 14.2.342.3; Thu, 19 Dec 2013 05:24:37 -0600 Received: from localhost.localdomain (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp33.itg.ti.com (8.14.3/8.13.8) with ESMTP id rBJBOUgt009888; Thu, 19 Dec 2013 05:24:35 -0600 From: Tero Kristo To: , , , , , , Subject: [PATCHv11 01/49] clk: add support for registering clocks from description Date: Thu, 19 Dec 2013 13:23:32 +0200 Message-ID: <1387452260-23276-2-git-send-email-t-kristo@ti.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1387452260-23276-1-git-send-email-t-kristo@ti.com> References: <1387452260-23276-1-git-send-email-t-kristo@ti.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20131219_062501_726118_B0BEB147 X-CRM114-Status: GOOD ( 13.69 ) X-Spam-Score: -7.4 (-------) Cc: devicetree@vger.kernel.org, Mike Turquette , 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, 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 From: Mike Turquette clk_register_desc is the primary interface for populating the clock tree with new clock nodes. In time, this will replace the various hardware-specific registration functions (e.g. clk_register_gate). Signed-off-by: Mike Turquette Signed-off-by: Tero Kristo --- drivers/clk/clk.c | 71 ++++++++++++++++++++++++++++++++++++++++++ include/linux/clk-provider.h | 23 ++++++++++++++ 2 files changed, 94 insertions(+) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 2cf2ea6..29281f6 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -1905,6 +1905,77 @@ fail_out: EXPORT_SYMBOL_GPL(clk_register); /** + * clk_register_desc - register a new clock from its description + * @dev: device that is registering this clock + * @desc: description of the clock, may be __initdata or otherwise discarded + * + * clk_register_desc is the primary interface for populating the clock tree + * with new clock nodes. In time it will replace the various hardware-specific + * registration functions (e.g. clk_register_gate). clk_register_desc returns a + * pointer to the newly allocated struct clk which is an opaque cookie. Drivers + * must not dereference it except to check with IS_ERR. + */ +struct clk *clk_register_desc(struct device *dev, struct clk_desc *desc) +{ + int ret, i; + struct clk *clk; + + clk = kzalloc(sizeof(*clk), GFP_KERNEL); + + if (!clk) + return ERR_PTR(-ENOMEM); + + clk->hw = desc->register_func(dev, desc); + clk->hw->clk = clk; + + /* _clk_register */ + clk->name = kstrdup(desc->name, GFP_KERNEL); + if (!clk->name) { + ret = -ENOMEM; + goto fail_name; + } + + clk->ops = desc->ops; + clk->flags = desc->flags; + clk->num_parents = desc->num_parents; + + /* allocate local copy in case parent_names is __initdata */ + clk->parent_names = kcalloc(clk->num_parents, sizeof(char *), + GFP_KERNEL); + + if (!clk->parent_names) { + ret = -ENOMEM; + goto fail_parent_names; + } + + /* copy each string name in case parent_names is __initdata */ + for (i = 0; i < clk->num_parents; i++) { + clk->parent_names[i] = kstrdup(desc->parent_names[i], + GFP_KERNEL); + + if (!clk->parent_names[i]) { + ret = -ENOMEM; + goto fail_parent_names_copy; + } + } + + ret = __clk_init(dev, clk); + + if (!ret) + return clk; + +fail_parent_names_copy: + while (--i >= 0) + kfree(clk->parent_names[i]); + kfree(clk->parent_names); +fail_parent_names: + kfree(clk->name); +fail_name: + kfree(clk); + return ERR_PTR(ret); +} + +/** * clk_unregister - unregister a currently registered clock * @clk: clock to unregister * diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h index 7e59253..7fddcb3 100644 --- a/include/linux/clk-provider.h +++ b/include/linux/clk-provider.h @@ -161,6 +161,28 @@ struct clk_init_data { }; /** + * struct clk_desc - clock init descriptor for providing init time parameters + * for a clock. + * + * @name: clock name + * @ops: clock ops + * @parent_names: array of string names for all possible parents + * @num_parents: number of possible parents + * @flags: framework-level hints and quirks + * @register_func: function for parsing the clock descriptor and providing + * ready-to-register clk_hw + */ +struct clk_desc { + const char *name; + const struct clk_ops *ops; + const char **parent_names; + u8 num_parents; + unsigned long flags; + struct clk_hw *(*register_func)(struct device *dev, + struct clk_desc *desc); +}; + +/** * struct clk_hw - handle for traversing from a struct clk to its corresponding * hardware-specific structure. struct clk_hw should be declared within struct * clk_foo and then referenced by the struct clk instance that uses struct @@ -419,6 +441,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name, * error code; drivers must test for an error code after calling clk_register. */ struct clk *clk_register(struct device *dev, struct clk_hw *hw); +struct clk *clk_register_desc(struct device *dev, struct clk_desc *desc); struct clk *devm_clk_register(struct device *dev, struct clk_hw *hw); void clk_unregister(struct clk *clk);