From patchwork Tue Mar 21 06:15:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rajendra Nayak X-Patchwork-Id: 9636061 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 2B82A601E9 for ; Tue, 21 Mar 2017 06:16:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1D873279E0 for ; Tue, 21 Mar 2017 06:16:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 126FC27CAF; Tue, 21 Mar 2017 06:16:44 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AAEBD27CEA for ; Tue, 21 Mar 2017 06:16:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756506AbdCUGQn (ORCPT ); Tue, 21 Mar 2017 02:16:43 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:42416 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756426AbdCUGQi (ORCPT ); Tue, 21 Mar 2017 02:16:38 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id ED3E260CF1; Tue, 21 Mar 2017 06:15:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1490076942; bh=Jajnst0Dm6KEQa63Wwoefr4xwyMvZ/idCIPzGoZdbLk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZKfRXDT9jPit40skByKJq8ZUVlJUGvo6dONlUEPstjPQAzeThU1VmcPkSKx9NyvXU CfsERZ8fEuSCmh2lOOGdBdlbC4SnkpQgmi+ld7eUn9juURsNpYMYy9+8VkVPROSgNp CjqYuDtN4GlWGcS2Eymp+RYeWAUBkvjfMvH811iQ= Received: from blr-ubuntu-173.qualcomm.com (unknown [202.46.23.61]) (using TLSv1.1 with cipher ECDHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: rnayak@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 3B33660CDE; Tue, 21 Mar 2017 06:15:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1490076942; bh=Jajnst0Dm6KEQa63Wwoefr4xwyMvZ/idCIPzGoZdbLk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZKfRXDT9jPit40skByKJq8ZUVlJUGvo6dONlUEPstjPQAzeThU1VmcPkSKx9NyvXU CfsERZ8fEuSCmh2lOOGdBdlbC4SnkpQgmi+ld7eUn9juURsNpYMYy9+8VkVPROSgNp CjqYuDtN4GlWGcS2Eymp+RYeWAUBkvjfMvH811iQ= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 3B33660CDE Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=rnayak@codeaurora.org From: Rajendra Nayak To: sboyd@codeaurora.org, mturquette@baylibre.com Cc: linux-clk@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Rajendra Nayak Subject: [PATCH 2/5] clk: Add clk_hw_get_clk() helper API to be used by clk providers Date: Tue, 21 Mar 2017 11:45:20 +0530 Message-Id: <1490076923-20194-3-git-send-email-rnayak@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1490076923-20194-1-git-send-email-rnayak@codeaurora.org> References: <1490076923-20194-1-git-send-email-rnayak@codeaurora.org> Sender: linux-clk-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP As we move towards a cleaner split to have clock providers use clk_hw for all clock operations, while consumers operate on the (per-user) struct clk handles, we still have cases where in a clock provider might want to call into high level clk apis which only operate on a struct clk handle. To facilitate such needs, have a clk_hw_get_clk() api which can be used from within clock providers to get access to struct clk handles. Signed-off-by: Rajendra Nayak --- drivers/clk/clk.c | 39 +++++++++++++++++++++++++++++++++++++++ include/linux/clk-provider.h | 5 +++++ 2 files changed, 44 insertions(+) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 0fb39fe..a6ba77c 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -186,6 +186,45 @@ const char *clk_hw_get_name(const struct clk_hw *hw) } EXPORT_SYMBOL_GPL(clk_hw_get_name); +struct clk *clk_hw_get_clk(struct clk_hw *hw, const char *dev_id, + const char *con_id) +{ + return __clk_create_clk(hw, dev_id, con_id); +} +EXPORT_SYMBOL_GPL(clk_hw_get_clk); + +void clk_hw_put_clk(struct clk *clk) +{ + __clk_free_clk(clk); +} +EXPORT_SYMBOL_GPL(clk_hw_put_clk); + +static void devm_clk_hw_put(struct device *dev, void *res) +{ + clk_hw_put_clk(*(struct clk **)res); +} + +struct clk *devm_clk_hw_get_clk(struct device *dev, struct clk_hw *hw, + const char *con_id) +{ + struct clk **ptr, *clk; + + ptr = devres_alloc(devm_clk_hw_put, sizeof(*ptr), GFP_KERNEL); + if (!ptr) + return ERR_PTR(-ENOMEM); + + clk = clk_hw_get_clk(hw, dev_name(dev), con_id); + if (!IS_ERR(clk)) { + *ptr = clk; + devres_add(dev, ptr); + } else { + devres_free(ptr); + } + + return clk; +} +EXPORT_SYMBOL_GPL(devm_clk_hw_get_clk); + struct clk_hw *__clk_get_hw(struct clk *clk) { return !clk ? NULL : clk->core->hw; diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h index a428aec..feddf95 100644 --- a/include/linux/clk-provider.h +++ b/include/linux/clk-provider.h @@ -729,6 +729,11 @@ struct clk_hw *clk_hw_register_gpio_mux(struct device *dev, const char *name, /* helper functions */ const char *__clk_get_name(const struct clk *clk); const char *clk_hw_get_name(const struct clk_hw *hw); +struct clk *clk_hw_get_clk(struct clk_hw *hw, const char *dev_id, + const char *con_id); +void clk_hw_put_clk(struct clk *clk); +struct clk *devm_clk_hw_get_clk(struct device *dev, struct clk_hw *hw, + const char *con_id); struct clk_hw *__clk_get_hw(struct clk *clk); unsigned int clk_hw_get_num_parents(const struct clk_hw *hw); struct clk_hw *clk_hw_get_parent(const struct clk_hw *hw);