From patchwork Thu Jul 20 04:48:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rajendra Nayak X-Patchwork-Id: 9853757 X-Patchwork-Delegate: sboyd@codeaurora.org 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 89D0260392 for ; Thu, 20 Jul 2017 04:48:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7589228737 for ; Thu, 20 Jul 2017 04:48:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6A70B28748; Thu, 20 Jul 2017 04:48:52 +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 0C5FE28737 for ; Thu, 20 Jul 2017 04:48:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932981AbdGTEsv (ORCPT ); Thu, 20 Jul 2017 00:48:51 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:49818 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932745AbdGTEsv (ORCPT ); Thu, 20 Jul 2017 00:48:51 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 79DE261201; Thu, 20 Jul 2017 04:48:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1500526130; bh=K5fO9/dzDZMl5j580o4Kcnci4G3TEJt+JFnRZPW6s9o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hLRe/CgnPl124XMiCp4h0v1AQJXyCJz77pcFAHyz5sI9r2uy6Njxsv3YPmNSw9OiM ZAvhgJnh5dWy4bZBS+l8EP9dyDqGCc3K3e3Mw+LpEQMM9GEAg/eAc8WaI7GiVQxJrO du38FWMbAAj0Sovwo5NPOb8UrHmrR9I2qLRtTTXQ= Received: from blr-ubuntu-173.qualcomm.com (blr-bdr-fw-01_globalnat_allzones-outside.qualcomm.com [103.229.18.19]) (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 4205D611C5; Thu, 20 Jul 2017 04:48:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1500526129; bh=K5fO9/dzDZMl5j580o4Kcnci4G3TEJt+JFnRZPW6s9o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q2036d+Ci7O6DUdj1InY5JoDSXiQAW3LNkuyYKK2CGkmF2PcmZi9IFzVLTAS/Tdrx WDNWUwYoLvOewQXTCCmQfAtY5a5eW57hbdg0zrO/DM0pvj/+FjaRK+bvVp1bLa+isX xbGS+RDFbogYVTPc9P6p40VN3XnirEscQ7+tm0pk= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 4205D611C5 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-arm-msm@vger.kernel.org, linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, stanimir.varbanov@linaro.org, vivek.gautam@codeaurora.org, Rajendra Nayak Subject: [PATCH v2 2/5] clk: Add clk_hw_get_clk() helper API to be used by clk providers Date: Thu, 20 Jul 2017 10:18:16 +0530 Message-Id: <1500526099-9935-3-git-send-email-rnayak@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1500526099-9935-1-git-send-email-rnayak@codeaurora.org> References: <1500526099-9935-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 fc58c52..c9bbfb3 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 c59c625..c85bfed 100644 --- a/include/linux/clk-provider.h +++ b/include/linux/clk-provider.h @@ -730,6 +730,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);