From patchwork Mon Jul 11 02:53:56 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 963292 Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p6B3hlZn010480 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Mon, 11 Jul 2011 03:44:08 GMT Received: from canuck.infradead.org ([2001:4978:20e::1]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1Qg7PA-00016D-It; Mon, 11 Jul 2011 03:43:33 +0000 Received: from localhost ([127.0.0.1] helo=canuck.infradead.org) by canuck.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1Qg7P8-0004Vv-Lc; Mon, 11 Jul 2011 03:43:30 +0000 Received: from opensource.wolfsonmicro.com ([80.75.67.52] helo=opensource2.wolfsonmicro.com) by canuck.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1Qg7OR-0004ML-Uz for linux-arm-kernel@lists.infradead.org; Mon, 11 Jul 2011 03:42:49 +0000 Received: from finisterre.wolfsonmicro.main (unknown [203.226.206.138]) by opensource2.wolfsonmicro.com (Postfix) with ESMTPSA id A2E98114A23; Mon, 11 Jul 2011 04:42:45 +0100 (BST) Received: from broonie by finisterre.wolfsonmicro.main with local (Exim 4.76) (envelope-from ) id 1Qg6dF-00018E-Fu; Mon, 11 Jul 2011 11:54:01 +0900 From: Mark Brown To: Jeremy Kerr Subject: [PATCH 5/6] clk: Support multiple instances of the same clock provider Date: Mon, 11 Jul 2011 11:53:56 +0900 Message-Id: <1310352837-4277-5-git-send-email-broonie@opensource.wolfsonmicro.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1310352837-4277-1-git-send-email-broonie@opensource.wolfsonmicro.com> References: <20110711025344.GA27497@opensource.wolfsonmicro.com> <1310352837-4277-1-git-send-email-broonie@opensource.wolfsonmicro.com> X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20110710_234248_350402_5F73D24A X-CRM114-Status: GOOD ( 23.14 ) X-Spam-Score: -0.0 (/) X-Spam-Report: SpamAssassin version 3.3.1 on canuck.infradead.org summary: Content analysis details: (-0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay domain Cc: Grant Likely , Mark Brown , linux-sh@vger.kernel.org, patches@opensource.wolfsonmicro.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Mon, 11 Jul 2011 03:44:08 +0000 (UTC) Currently the generic clk API identifies clocks internally using the name of the clock. This is OK for on-SoC clocks where we have enough control to disambiguate but doesn't work well for clocks provided on external chips where a system design may include more than one instance of the same chip (the Wolfson Speyside system is an example of this) or may have namespace collisions. Address this by allowing the clock provider to supply a struct device for the clock for use in disambiguation. As a first pass if it is provided we prefix the clock name with the dev_name() of the device. With a device tree binding for clocks it should be possible to remove this mangling and instead use the struct device to provide access to the binding information. In order to avoid needless noise in names and memory usage it is strongly recommended that on-SoC clocks do not provide a struct device until the implementation is improved. Signed-off-by: Mark Brown --- drivers/clk/clk.c | 36 ++++++++++++++++++++++++++++++++---- include/linux/clk.h | 14 ++++++++++---- 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 1df6e23..f36f637 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -13,6 +13,7 @@ #include #include #include +#include struct clk { const char *name; @@ -252,20 +253,44 @@ int clk_set_parent(struct clk *clk, struct clk *parent) } EXPORT_SYMBOL_GPL(clk_set_parent); -struct clk *clk_register(const struct clk_hw_ops *ops, struct clk_hw *hw, - const char *name) +struct clk *clk_register(struct device *dev, const struct clk_hw_ops *ops, + struct clk_hw *hw, const char *name) { struct clk *clk; + char *new_name; + size_t name_len; clk = kzalloc(sizeof(*clk), GFP_KERNEL); if (!clk) return NULL; - clk->name = name; clk->ops = ops; clk->hw = hw; hw->clk = clk; + /* Since we currently match clock providers on a purely string + * based method add a prefix based on the device name if a + * device is provided. When we have support for device tree + * based clock matching it should be possible to avoid this + * mangling and instead use the struct device to hook into + * the bindings. + * + * As we don't currently support unregistering clocks we don't + * need to worry about cleanup as yet. + */ + if (dev) { + name_len = strlen(name) + strlen(dev_name(dev)) + 2; + new_name = kzalloc(name_len, GFP_KERNEL); + if (!new_name) + goto err; + + snprintf(new_name, name_len, "%s-%s", dev_name(dev), name); + + clk->name = new_name; + } else { + clk->name = name; + } + /* Query the hardware for parent and initial rate. We may alter * the clock topology, making this clock available from the parent's * children list. So, we need to protect against concurrent @@ -285,7 +310,10 @@ struct clk *clk_register(const struct clk_hw_ops *ops, struct clk_hw *hw, mutex_unlock(&prepare_lock); - return clk; + +err: + kfree(clk); + return NULL; } EXPORT_SYMBOL_GPL(clk_register); diff --git a/include/linux/clk.h b/include/linux/clk.h index fb5e435..cb1879b 100644 --- a/include/linux/clk.h +++ b/include/linux/clk.h @@ -139,15 +139,21 @@ extern struct clk_hw_ops clk_gate_ops; /** * clk_register - register and initialize a new clock * + * @dev: device providing the clock or NULL * @ops: ops for the new clock * @hw: struct clk_hw to be passed to the ops of the new clock * @name: name to use for the new clock * - * Register a new clock with the clk subsytem. Returns either a - * struct clk for the new clock or a NULL pointer. + * Register a new clock with the clk subsytem. If dev is provided + * then it will be used to disambiguate between multiple instances of + * the same device in the system, typically this should only be done + * for devices that are not part of the core SoC unless device tree is + * in use. + * + * Returns either a struct clk for the new clock or a NULL pointer. */ -struct clk *clk_register(const struct clk_hw_ops *ops, struct clk_hw *hw, - const char *name); +struct clk *clk_register(struct device *dev, const struct clk_hw_ops *ops, + struct clk_hw *hw, const char *name); /** * clk_unregister - remove a clock