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: 3376801 Return-Path: X-Original-To: patchwork-linux-omap@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 0F6F4C0D4B for ; Thu, 19 Dec 2013 11:25:13 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B2F972063F for ; Thu, 19 Dec 2013 11:25:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 757F62063D for ; Thu, 19 Dec 2013 11:25:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752944Ab3LSLZJ (ORCPT ); Thu, 19 Dec 2013 06:25:09 -0500 Received: from devils.ext.ti.com ([198.47.26.153]:38882 "EHLO devils.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752852Ab3LSLZF (ORCPT ); Thu, 19 Dec 2013 06:25:05 -0500 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: , , , , , , CC: , , Mike Turquette 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 Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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);