Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4295395imu; Mon, 28 Jan 2019 22:11:04 -0800 (PST) X-Google-Smtp-Source: ALg8bN4axFFm3O6tvknjSPjfqVrXyfklUYYNcggs1+9FmAxUTximoUoGNnl0uNoZV/L0fd9BFfgh X-Received: by 2002:a17:902:4681:: with SMTP id p1mr25368626pld.184.1548742263949; Mon, 28 Jan 2019 22:11:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548742263; cv=none; d=google.com; s=arc-20160816; b=vKLWJ8ooKXt4DT/Qu0FsZ5709leS/YJ/LiqnVXsOsV8oGkD+8sNJzJNJNtWr/KQ3Jp rA5xn8o3oSwIykeYpfWnpmFJBg36qsi47cHRHWRmTsXDgD/AHUJORapOJNk84WuCm26n EqefewmmXxx96iSVnwaLZd0YwbkOdNbyRlkKUvPNT7EP2bdpged3evSyXlQtBUUhivuB AnrsZy8MbbgXAfdVllzrWx6vfzMSPBoJNTsMbOpG7PFMVIt/8lhVa5bb0lyYjJlNucd6 tVw0d/fyei3SmRuwThRGiOsgLEDVxJYwzBxMvDuDRLFXx6rcl122dKQQFOP3kmC9vq47 L/Yw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=K/r/Sz9To4Yy2GXLMQiiPHmSjhFZki2xcTtZ8EdZnEI=; b=Zzk5RhDkHt2h4Gmg9mxPtFkkj72j4kgA8u7/iPy28+s7l8Wk0i4HWUbXIsu2btopPO RwIVFRRvlfvkIov7flj6vJJUzxjRzF8PHCKvdNhmgE9XUr+1Ieum5k0X5WHgPHxEoZWX O+WRHgfIbKn/zBqmBD13e1HOFcy+IQWc6mDKmIISZwcnZAZHKmogFBSE+R2ZShhLzuPv WtyeUPJeyfKQwi7iTEhUUiVqK61fmuPio56/fEf5c8WgMnJKnTSAmQUoSKellnZyAb6q NqxYyUHQf4qrnZd/ssdxDvvVSBTmesvjeNp/250C4hZ+4ZWKu3xZzNFFasTVGIJmPT3c EYcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=chkEP6cp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v6si35253817pfv.181.2019.01.28.22.10.47; Mon, 28 Jan 2019 22:11:03 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=chkEP6cp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727589AbfA2GK2 (ORCPT + 99 others); Tue, 29 Jan 2019 01:10:28 -0500 Received: from mail.kernel.org ([198.145.29.99]:33466 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727366AbfA2GK0 (ORCPT ); Tue, 29 Jan 2019 01:10:26 -0500 Received: from mail.kernel.org (unknown [104.132.0.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A847921852; Tue, 29 Jan 2019 06:10:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548742224; bh=lqLBOdLs/K2ek01660gtvK/N+IUXOeXI9jrcvENBlWY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=chkEP6cppO4jcoYJRpIBRwEPEaqQfaGd2idjH2On/oB7oxgRCVcbTMnfSWQVbsNA6 z8p+0MM6Km1b2dwN2svWuMhXWQvGTGUwcC2bHP/ZhJcPBABJEwV2gMybJ6/08aMYAt /sMBeBBtCvU2vQZtlpaVNKQPK7islN9FscGSRh9Y= From: Stephen Boyd To: Michael Turquette , Stephen Boyd Cc: linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, Miquel Raynal , Jerome Brunet , Russell King Subject: [PATCH 6/9] clk: Move of_clk_*() APIs into clk.c from clkdev.c Date: Mon, 28 Jan 2019 22:10:18 -0800 Message-Id: <20190129061021.94775-7-sboyd@kernel.org> X-Mailer: git-send-email 2.20.1.495.gaa96b0ce6b-goog In-Reply-To: <20190129061021.94775-1-sboyd@kernel.org> References: <20190129061021.94775-1-sboyd@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The API between clk.c and clkdev.c is purely getting the clk_hw structure (or the struct clk if it's not CCF) and then turning that struct clk_hw pointer into a struct clk pointer via clk_hw_create_clk(). There's no need to complicate clkdev.c with these DT parsing details that are only relevant to the common clk framework. Move the DT parsing logic into the core framework and just expose the APIs to get a clk_hw pointer and convert it. Cc: Miquel Raynal Cc: Jerome Brunet Cc: Russell King Cc: Michael Turquette Signed-off-by: Stephen Boyd --- drivers/clk/clk.c | 57 ++++++++++++++++++++++++++++++++++++++--- drivers/clk/clk.h | 11 +++++--- drivers/clk/clkdev.c | 60 -------------------------------------------- 3 files changed, 62 insertions(+), 66 deletions(-) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 73f8a287bf42..202902e64799 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -4080,8 +4080,8 @@ void devm_of_clk_del_provider(struct device *dev) } EXPORT_SYMBOL(devm_of_clk_del_provider); -int of_parse_clkspec(const struct device_node *np, int index, const char *name, - struct of_phandle_args *out_args) +static int of_parse_clkspec(const struct device_node *np, int index, + const char *name, struct of_phandle_args *out_args) { int ret = -ENOENT; @@ -4131,7 +4131,8 @@ __of_clk_get_hw_from_provider(struct of_clk_provider *provider, return __clk_get_hw(clk); } -struct clk_hw *of_clk_get_hw_from_clkspec(struct of_phandle_args *clkspec) +static struct clk_hw * +of_clk_get_hw_from_clkspec(struct of_phandle_args *clkspec) { struct of_clk_provider *provider; struct clk_hw *hw = ERR_PTR(-EPROBE_DEFER); @@ -4168,6 +4169,56 @@ struct clk *of_clk_get_from_provider(struct of_phandle_args *clkspec) } EXPORT_SYMBOL_GPL(of_clk_get_from_provider); +struct clk_hw *of_clk_get_hw(struct device_node *np, int index, + const char *con_id) +{ + int ret; + struct clk_hw *hw; + struct of_phandle_args clkspec; + + ret = of_parse_clkspec(np, index, con_id, &clkspec); + if (ret) + return ERR_PTR(ret); + + hw = of_clk_get_hw_from_clkspec(&clkspec); + of_node_put(clkspec.np); + + return hw; +} + +static struct clk *__of_clk_get(struct device_node *np, + int index, const char *dev_id, + const char *con_id) +{ + struct clk_hw *hw = of_clk_get_hw(np, index, con_id); + + return clk_hw_create_clk(NULL, hw, dev_id, con_id); +} + +struct clk *of_clk_get(struct device_node *np, int index) +{ + return __of_clk_get(np, index, np->full_name, NULL); +} +EXPORT_SYMBOL(of_clk_get); + +/** + * of_clk_get_by_name() - Parse and lookup a clock referenced by a device node + * @np: pointer to clock consumer node + * @name: name of consumer's clock input, or NULL for the first clock reference + * + * This function parses the clocks and clock-names properties, + * and uses them to look up the struct clk from the registered list of clock + * providers. + */ +struct clk *of_clk_get_by_name(struct device_node *np, const char *name) +{ + if (!np) + return ERR_PTR(-ENOENT); + + return __of_clk_get(np, -1, np->full_name, name); +} +EXPORT_SYMBOL(of_clk_get_by_name); + /** * of_clk_get_parent_count() - Count the number of clocks a device node has * @np: device node to count diff --git a/drivers/clk/clk.h b/drivers/clk/clk.h index fda0ad483416..46e668d64da8 100644 --- a/drivers/clk/clk.h +++ b/drivers/clk/clk.h @@ -14,9 +14,14 @@ struct device; struct of_phandle_args; #if defined(CONFIG_OF) && defined(CONFIG_COMMON_CLK) -int of_parse_clkspec(const struct device_node *np, int index, const char *name, - struct of_phandle_args *out_args); -struct clk_hw *of_clk_get_hw_from_clkspec(struct of_phandle_args *clkspec); +struct clk_hw *of_clk_get_hw(struct device_node *np, + int index, const char *con_id); +#else /* !CONFIG_COMMON_CLK || !CONFIG_OF */ +static inline struct clk_hw *of_clk_get_hw(struct device_node *np, + int index, const char *con_id) +{ + return ERR_PTR(-ENOENT); +} #endif #ifdef CONFIG_COMMON_CLK diff --git a/drivers/clk/clkdev.c b/drivers/clk/clkdev.c index f2f4f2afd28c..d3758bf4305c 100644 --- a/drivers/clk/clkdev.c +++ b/drivers/clk/clkdev.c @@ -27,66 +27,6 @@ static LIST_HEAD(clocks); static DEFINE_MUTEX(clocks_mutex); -#if defined(CONFIG_OF) && defined(CONFIG_COMMON_CLK) -static struct clk_hw *of_clk_get_hw(struct device_node *np, - int index, const char *con_id) -{ - int ret; - struct clk_hw *hw; - struct of_phandle_args clkspec; - - ret = of_parse_clkspec(np, index, con_id, &clkspec); - if (ret) - return ERR_PTR(ret); - - hw = of_clk_get_hw_from_clkspec(&clkspec); - of_node_put(clkspec.np); - - return hw; -} - -static struct clk *__of_clk_get(struct device_node *np, - int index, const char *dev_id, - const char *con_id) -{ - struct clk_hw *hw = of_clk_get_hw(np, index, con_id); - - return clk_hw_create_clk(NULL, hw, dev_id, con_id); -} - -struct clk *of_clk_get(struct device_node *np, int index) -{ - return __of_clk_get(np, index, np->full_name, NULL); -} -EXPORT_SYMBOL(of_clk_get); - -/** - * of_clk_get_by_name() - Parse and lookup a clock referenced by a device node - * @np: pointer to clock consumer node - * @name: name of consumer's clock input, or NULL for the first clock reference - * - * This function parses the clocks and clock-names properties, - * and uses them to look up the struct clk from the registered list of clock - * providers. - */ -struct clk *of_clk_get_by_name(struct device_node *np, const char *name) -{ - if (!np) - return ERR_PTR(-ENOENT); - - return __of_clk_get(np, -1, np->full_name, name); -} -EXPORT_SYMBOL(of_clk_get_by_name); - -#else /* defined(CONFIG_OF) && defined(CONFIG_COMMON_CLK) */ - -static struct clk_hw *of_clk_get_hw(struct device_node *np, - int index, const char *con_id) -{ - return ERR_PTR(-ENOENT); -} -#endif - /* * Find the correct struct clk for the device and connection ID. * We do slightly fuzzy matching here: -- Sent by a computer through tubes