From patchwork Thu Jun 30 14:13:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tero Kristo X-Patchwork-Id: 9208069 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D6E626075A for ; Thu, 30 Jun 2016 14:18:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C717A2867E for ; Thu, 30 Jun 2016 14:18:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BBEE828681; Thu, 30 Jun 2016 14:18:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A9E082867E for ; Thu, 30 Jun 2016 14:18:28 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bIclr-000763-35; Thu, 30 Jun 2016 14:16:47 +0000 Received: from devils.ext.ti.com ([198.47.26.153]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bIcjf-0003ig-I6 for linux-arm-kernel@lists.infradead.org; Thu, 30 Jun 2016 14:14:32 +0000 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by devils.ext.ti.com (8.13.7/8.13.7) with ESMTP id u5UECihI007038; Thu, 30 Jun 2016 09:12:44 -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 u5UEDt4f004418; Thu, 30 Jun 2016 09:13:55 -0500 Received: from dlep33.itg.ti.com (157.170.170.75) by DLEE70.ent.ti.com (157.170.170.113) with Microsoft SMTP Server id 14.3.294.0; Thu, 30 Jun 2016 09:13:55 -0500 Received: from gomoku.home (ileax41-snat.itg.ti.com [10.172.224.153]) by dlep33.itg.ti.com (8.14.3/8.13.8) with ESMTP id u5UEDnVV002253; Thu, 30 Jun 2016 09:13:53 -0500 From: Tero Kristo To: , , , , , Subject: [PATCHv3 1/7] clkdev: add helper registration API Date: Thu, 30 Jun 2016 17:13:32 +0300 Message-ID: <1467296018-25086-2-git-send-email-t-kristo@ti.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1467296018-25086-1-git-send-email-t-kristo@ti.com> References: <1467296018-25086-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-20160630_071431_796246_E359D155 X-CRM114-Status: GOOD ( 11.85 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Russell King , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP In certain cases, it is desirable to extend the implementation of the clkdev lookup, to avoid registering massive amounts of clkdev aliases. A simple helper implementation can instead be used to search and automatically create the clkdev entries. A sample of this is the TI clock implementation, which currently registers a large number of clkdev entries with a very simple mapping strategy. This patch adds an API to register a helper function that gets called during clk_get(), in case everything else fails to look up the clock. Individual clock drivers are then free to register the helper and implement it the way they want. Signed-off-by: Tero Kristo Cc: Russell King --- drivers/clk/clkdev.c | 22 +++++++++++++++++++++- include/linux/clkdev.h | 1 + 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/drivers/clk/clkdev.c b/drivers/clk/clkdev.c index 89cc700..788c0b2 100644 --- a/drivers/clk/clkdev.c +++ b/drivers/clk/clkdev.c @@ -26,6 +26,8 @@ static LIST_HEAD(clocks); static DEFINE_MUTEX(clocks_mutex); +static struct clk * (*clkdev_get_helper)(const char *dev_id, + const char *con_id); #if defined(CONFIG_OF) && defined(CONFIG_COMMON_CLK) static struct clk *__of_clk_get(struct device_node *np, int index, @@ -190,7 +192,13 @@ struct clk *clk_get_sys(const char *dev_id, const char *con_id) out: mutex_unlock(&clocks_mutex); - return cl ? clk : ERR_PTR(-ENOENT); + if (cl) + return clk; + + if (clkdev_get_helper) + return clkdev_get_helper(dev_id, con_id); + + return ERR_PTR(-ENOENT); } EXPORT_SYMBOL(clk_get_sys); @@ -209,6 +217,18 @@ struct clk *clk_get(struct device *dev, const char *con_id) } EXPORT_SYMBOL(clk_get); +int clkdev_helper_register(struct clk * (*helper)(const char *, + const char *)) +{ + if (clkdev_get_helper) + return -EBUSY; + + clkdev_get_helper = helper; + + return 0; +} +EXPORT_SYMBOL(clkdev_helper_register); + void clk_put(struct clk *clk) { __clk_put(clk); diff --git a/include/linux/clkdev.h b/include/linux/clkdev.h index 2eabc86..173e2fa 100644 --- a/include/linux/clkdev.h +++ b/include/linux/clkdev.h @@ -51,6 +51,7 @@ int clk_add_alias(const char *, const char *, const char *, struct device *); int clk_register_clkdev(struct clk *, const char *, const char *); int clk_hw_register_clkdev(struct clk_hw *, const char *, const char *); +int clkdev_helper_register(struct clk * (*)(const char *, const char *)); #ifdef CONFIG_COMMON_CLK int __clk_get(struct clk *clk);