From patchwork Fri Nov 16 14:59:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phil Edworthy X-Patchwork-Id: 10686427 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B070917DE for ; Fri, 16 Nov 2018 15:00:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9E46A2BB97 for ; Fri, 16 Nov 2018 15:00:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 912D02C617; Fri, 16 Nov 2018 15:00:28 +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=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0DC652BB97 for ; Fri, 16 Nov 2018 15:00:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=svd57QWBMvkBCkGLcMwcIK/bAxQgONNjlVo1WWv/wW8=; b=sIYy3auel6EjiRMyewc2ZZBJvY zLMrAY3OAvi9viY9CKv72Dx/9Aqb2Oc5NlaDLyXlFcrrASqFDfKwyMgFlpuLi16uJEEJCJTMVsu7u cZhULXJEvp2X3ucEwRs+Uz930G9waTCKclQRhdPZv0GyhrEZTgbI0UQDktVBvywZG+Kxj3puRa3N9 wl4j3Bxn6VZiPEE2OsARQMQJoBHUYWkR9mynkw/7+upxiL5EMls0Dl8DolcyPvPcWRxGqI8Vf2b75 TJgeDjK1rDjDzdNHcMt/59go6eBT8BVksmYrSBIIgnVdhKabzhFaeGYVn7+UrzLBQyN32bgGQ2ZsZ VEKf+uaA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gNfbe-0006ms-QT; Fri, 16 Nov 2018 15:00:26 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gNfbc-0006kl-Et for linux-arm-kernel@bombadil.infradead.org; Fri, 16 Nov 2018 15:00:24 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=lnFdV8Djs6011dnF8m7VMhTn8Evln339qwEft6Pvong=; b=QBrYZJpTv1277yLIPCdckDSMv Dy9GcvEkH/IqQTn1nyPNiSNdVNMn6uzQwaAFeE3LL1rG2kHfrNXkXt0Gr/PjUD39hLJRZXJpCyUeq yiNVT7nX195NQLPd2KpNTjZTcAlYt3aP69ckOKZTZKd5bqDlu36XPqAr9WV22UWz7tf+NwSEUh8/F noxyG6K5NfCu4dB6CopGD5PZ7Lj2aVy/NN2A8VMNfjJDoZlcKeBOsElprTopoffUjNxwqclV0Dd+8 VEwjlqUbJe2iMgas/77V9CBYjFFYW92iZmtavsUs/5J0HaLtglvXnhV4kTRfoFcofge3vBdwUSiAw 2lZjX1y3w==; Received: from relmlor1.renesas.com ([210.160.252.171] helo=relmlie5.idc.renesas.com) by merlin.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gNfbY-0001AL-4o for linux-arm-kernel@lists.infradead.org; Fri, 16 Nov 2018 15:00:22 +0000 Received: from unknown (HELO relmlir4.idc.renesas.com) ([10.200.68.154]) by relmlie5.idc.renesas.com with ESMTP; 17 Nov 2018 00:00:03 +0900 Received: from relmlii2.idc.renesas.com (relmlii2.idc.renesas.com [10.200.68.66]) by relmlir4.idc.renesas.com (Postfix) with ESMTP id B0E8FE3A6D; Sat, 17 Nov 2018 00:00:03 +0900 (JST) X-IronPort-AV: E=Sophos;i="5.56,240,1539615600"; d="scan'208";a="297674437" Received: from unknown (HELO vbox.ree.adwin.renesas.com) ([10.226.37.67]) by relmlii2.idc.renesas.com with ESMTP; 17 Nov 2018 00:00:00 +0900 From: Phil Edworthy To: Stephen Boyd , Michael Turquette , Andy Shevchenko , Russell King Subject: [PATCH v6 1/6] clk: Add of_clk_get_by_name_optional() function Date: Fri, 16 Nov 2018 14:59:32 +0000 Message-Id: <20181116145937.27660-2-phil.edworthy@renesas.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181116145937.27660-1-phil.edworthy@renesas.com> References: <20181116145937.27660-1-phil.edworthy@renesas.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181116_100020_524034_D5CC0077 X-CRM114-Status: GOOD ( 30.63 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Phil Edworthy , linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Geert Uytterhoeven , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 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 Quite a few drivers get an optional clock, e.g. a clock required to access a peripheral's registers that is always enabled on some devices. This adds the of_clk_get_by_name_optional() function for this purpose. This function behaves the same as of_clk_get_by_name() except that it will return NULL instead of -ENOENT. This allows for simpler error handling in the callers. Signed-off-by: Phil Edworthy --- *Warning* This changes the return values for of_clk_get_by_name() in some cases. If the name arg is non-NULL, and the "clock-names" OF property can't be found or the name is not in that prop, the code used to return -EINVAL, but will now return -ENOENT. Note that before and after this patch, if name=NULL and no "clocks" OF property has been found, of_clk_get_by_name() returns -ENOENT. I believe the new behaviour is correct. I cannot find any callers to of_clk_get_by_name() that explicitly check for -EINVAL or -ENOENT, but there is the possibility that something will break at runtime with this change. v6: - Rework the __of_clk_get_by_name() logic so as to avoid duplicate tests. v5: - Simplified the code by handling all the error conditions on exit v4: - For optional named clocks of_property_match_string() will return -EINVAL if the "clock-names" property is missing, or -ENODATA if the specified clock name in the "clock-names" property is missing. If we then call __of_clk_get() with these errors as the index, we get clk = -EINVAL. This is then filtered later on so users don't see it. However, if the clock is not named, __of_clk_get() will return -ENOENT is the clock provide is not there. So for optional named clocks, use index to determine if the clock provider is there or not, and for unnamed clocks, simply check if __of_clk_get() returns -ENOENT. v3: - Fix check for clock not present. __of_clk_get() returns -EINVAL if it's not there. Cover case of when there is no clock name. - of_clk_get_by_name_optional() should return NULL if !np. - Add dummy version of of_clk_get_by_name_optional() for the !OF || !COMMON_CLK case. --- drivers/clk/clkdev.c | 76 ++++++++++++++++++++++++++++++++++++-------- include/linux/clk.h | 6 ++++ 2 files changed, 69 insertions(+), 13 deletions(-) diff --git a/drivers/clk/clkdev.c b/drivers/clk/clkdev.c index 9ab3db8b3988..0c655d1ba1d9 100644 --- a/drivers/clk/clkdev.c +++ b/drivers/clk/clkdev.c @@ -52,9 +52,19 @@ struct clk *of_clk_get(struct device_node *np, int index) } EXPORT_SYMBOL(of_clk_get); +/* + * This function tries to find a clock provider. + * If a name is provided, the function looks for a clock with that name in the + * OF node's "clock-names" property. If not found, the function will try the + * parent node and so on until a matching property is found or we reach the + * top of the tree. + * When no clock provider is found, if optional is true, the function will + * return NULL, otherwise return -ENOENT. + */ static struct clk *__of_clk_get_by_name(struct device_node *np, const char *dev_id, - const char *name) + const char *name, + bool optional) { struct clk *clk = ERR_PTR(-ENOENT); @@ -65,18 +75,33 @@ static struct clk *__of_clk_get_by_name(struct device_node *np, /* * For named clocks, first look up the name in the * "clock-names" property. If it cannot be found, then - * index will be an error code, and of_clk_get() will fail. + * index will be an error code. */ if (name) index = of_property_match_string(np, "clock-names", name); - clk = __of_clk_get(np, index, dev_id, name); - if (!IS_ERR(clk)) { - break; - } else if (name && index >= 0) { - if (PTR_ERR(clk) != -EPROBE_DEFER) - pr_err("ERROR: could not get clock %pOF:%s(%i)\n", - np, name ? name : "", index); - return clk; + + /* + * If we are looking for an unnamed clock, or we have found the + * named clock in the node, try to get the clock provider. + */ + if (index >= 0) { + clk = __of_clk_get(np, index, dev_id, name); + if (!IS_ERR(clk)) + return clk; + + /* + * If the node specifies the clock name, do not walk up + * the tree looking in parent nodes. + */ + if (name) { + /* Optional clock that's not there? */ + if (optional && PTR_ERR(clk) == -ENOENT) + clk = NULL; + else if (PTR_ERR(clk) != -EPROBE_DEFER) + pr_err("ERROR: could not get clock %pOF:%s(%i)\n", + np, name, index); + return clk; + } } /* @@ -89,6 +114,9 @@ static struct clk *__of_clk_get_by_name(struct device_node *np, break; } + if (optional && PTR_ERR(clk) == -ENOENT) + clk = NULL; + return clk; } @@ -106,15 +134,37 @@ struct clk *of_clk_get_by_name(struct device_node *np, const char *name) if (!np) return ERR_PTR(-ENOENT); - return __of_clk_get_by_name(np, np->full_name, name); + return __of_clk_get_by_name(np, np->full_name, name, false); } EXPORT_SYMBOL(of_clk_get_by_name); +/** + * of_clk_get_by_name_optional() - Parse and lookup an optional 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. + * It behaves the same as of_clk_get_by_name(), except when np is NULL or no + * clock provider is found, when it then returns NULL. + */ +struct clk *of_clk_get_by_name_optional(struct device_node *np, + const char *name) +{ + if (!np) + return NULL; + + return __of_clk_get_by_name(np, np->full_name, name, true); +} +EXPORT_SYMBOL(of_clk_get_by_name_optional); + #else /* defined(CONFIG_OF) && defined(CONFIG_COMMON_CLK) */ static struct clk *__of_clk_get_by_name(struct device_node *np, const char *dev_id, - const char *name) + const char *name, + bool optional) { return ERR_PTR(-ENOENT); } @@ -197,7 +247,7 @@ struct clk *clk_get(struct device *dev, const char *con_id) struct clk *clk; if (dev && dev->of_node) { - clk = __of_clk_get_by_name(dev->of_node, dev_id, con_id); + clk = __of_clk_get_by_name(dev->of_node, dev_id, con_id, false); if (!IS_ERR(clk) || PTR_ERR(clk) == -EPROBE_DEFER) return clk; } diff --git a/include/linux/clk.h b/include/linux/clk.h index a7773b5c0b9f..84512b3ecf5c 100644 --- a/include/linux/clk.h +++ b/include/linux/clk.h @@ -865,6 +865,7 @@ static inline void clk_bulk_disable_unprepare(int num_clks, #if defined(CONFIG_OF) && defined(CONFIG_COMMON_CLK) struct clk *of_clk_get(struct device_node *np, int index); struct clk *of_clk_get_by_name(struct device_node *np, const char *name); +struct clk *of_clk_get_by_name_optional(struct device_node *np, const char *name); struct clk *of_clk_get_from_provider(struct of_phandle_args *clkspec); #else static inline struct clk *of_clk_get(struct device_node *np, int index) @@ -876,6 +877,11 @@ static inline struct clk *of_clk_get_by_name(struct device_node *np, { return ERR_PTR(-ENOENT); } +static inline struct clk *of_clk_get_by_name_optional(struct device_node *np, + const char *name) +{ + return NULL; +} static inline struct clk *of_clk_get_from_provider(struct of_phandle_args *clkspec) { return ERR_PTR(-ENOENT); From patchwork Fri Nov 16 14:59:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phil Edworthy X-Patchwork-Id: 10686433 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E1C6314BD for ; Fri, 16 Nov 2018 15:00:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CE9202C3B9 for ; Fri, 16 Nov 2018 15:00:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C21922C623; Fri, 16 Nov 2018 15:00:42 +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=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 57EC62C3B9 for ; Fri, 16 Nov 2018 15:00:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=Nsrb+5aezt1DsS8ZturIuDUJpFDQWwT0mDzl0tJuywA=; b=aQBCykB+kdf3X7O2gmbjp28fFm 868jKc4q/pWI1jLz8Ij+KJ6JjCEH7+pAVGcFpAXaabBi4JlVLFBKM2F4CLx3Rnc0xagFeET9LmrQ6 1wVAIQnjkH7MMw+LgFmvuUSvbfD8uOHXFJAK2L+nmhABjTaN3EQUNjn7P7qnRr40QZFPBBIQ5+fix GufjK0O27xnXM7e/xfJYyjh1tek9vRO+KF6j0gs6RLI6RsrVP1S9gPmOJbS7Ii8lqFvJJeFGVjZFi oaf/YHVXQxxVvSKkP6+LrnMD6NRi1f90gqds2Fbp/PPZYzak5wnHaU3giK3hq7ECbybNhlpcija7p FNTEvC2w==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gNfbr-00072S-2e; Fri, 16 Nov 2018 15:00:39 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gNfbk-0006sM-Dz for linux-arm-kernel@bombadil.infradead.org; Fri, 16 Nov 2018 15:00:32 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=I9i0S6aJ5MvCxMJJLYcN9UYM7Y8OxpPk2OuMEkocTfk=; b=TLr7bfjzlVdDnibxc3F0pzBOf kGYIFiW0HjTC80/Fz5xeg3p5Z6zWuHJqQdGZio0a0o9/DXxAG+sgoBcQ7jnsRTIm9FkcYJrsBlJ9o L9JzBBu0mX1IK4Mm50IaZ/uaF6X7Amdkg+b+AE4m9mBQosdU15uMDsmpW78WAtWDh4JGwbfUHy2VT Nc8ti5Ma3RPblDUl9CeuQVKwo3Q0DWU0Tx8fPhd/0hZlHrSNnmFjFwd3FBi7dwlxrBvHEZ7WhdW2w gAt/Ah2OF3a717d+jgSS9B85FFCuPvvw23kan0IcQEVMXdlYfIhk19B36mMJOlajJGOPPBc6NVQCx xzQ1qvq+g==; Received: from relmlor1.renesas.com ([210.160.252.171] helo=relmlie5.idc.renesas.com) by casper.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gNfbg-0006sM-JH for linux-arm-kernel@lists.infradead.org; Fri, 16 Nov 2018 15:00:31 +0000 Received: from unknown (HELO relmlir4.idc.renesas.com) ([10.200.68.154]) by relmlie5.idc.renesas.com with ESMTP; 17 Nov 2018 00:00:15 +0900 Received: from relmlii2.idc.renesas.com (relmlii2.idc.renesas.com [10.200.68.66]) by relmlir4.idc.renesas.com (Postfix) with ESMTP id CBFB3E3B06; Sat, 17 Nov 2018 00:00:15 +0900 (JST) X-IronPort-AV: E=Sophos;i="5.56,240,1539615600"; d="scan'208";a="297674531" Received: from unknown (HELO vbox.ree.adwin.renesas.com) ([10.226.37.67]) by relmlii2.idc.renesas.com with ESMTP; 17 Nov 2018 00:00:12 +0900 From: Phil Edworthy To: Stephen Boyd , Michael Turquette , Andy Shevchenko , Russell King Subject: [PATCH v6 2/6] clk: Add (devm_)clk_get_optional() functions Date: Fri, 16 Nov 2018 14:59:33 +0000 Message-Id: <20181116145937.27660-3-phil.edworthy@renesas.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181116145937.27660-1-phil.edworthy@renesas.com> References: <20181116145937.27660-1-phil.edworthy@renesas.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181116_150029_312787_1D1EA450 X-CRM114-Status: GOOD ( 13.33 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Phil Edworthy , linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Geert Uytterhoeven , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 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 This adds clk_get_optional() and devm_clk_get_optional() functions to get optional clocks. They behave the same as (devm_)clk_get except where there is no clock producer. In this case, instead of returning -ENOENT, the function returns NULL. This makes error checking simpler and allows clk_prepare_enable, etc to be called on the returned reference without additional checks. Signed-off-by: Phil Edworthy --- v6: - Add doxygen style comment for devm_clk_get_optional() args v5: - No changes. v4: - No changes. v3: - No changes. --- drivers/clk/clk-devres.c | 18 ++++++++++++++++-- drivers/clk/clkdev.c | 17 +++++++++++++++-- include/linux/clk.h | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 4 deletions(-) diff --git a/drivers/clk/clk-devres.c b/drivers/clk/clk-devres.c index 12c87457eca1..be07536725a2 100644 --- a/drivers/clk/clk-devres.c +++ b/drivers/clk/clk-devres.c @@ -14,7 +14,7 @@ static void devm_clk_release(struct device *dev, void *res) clk_put(*(struct clk **)res); } -struct clk *devm_clk_get(struct device *dev, const char *id) +static struct clk *__devm_clk_get(struct device *dev, const char *id, bool optional) { struct clk **ptr, *clk; @@ -22,7 +22,10 @@ struct clk *devm_clk_get(struct device *dev, const char *id) if (!ptr) return ERR_PTR(-ENOMEM); - clk = clk_get(dev, id); + if (!optional) + clk = clk_get(dev, id); + else + clk = clk_get_optional(dev, id); if (!IS_ERR(clk)) { *ptr = clk; devres_add(dev, ptr); @@ -32,8 +35,19 @@ struct clk *devm_clk_get(struct device *dev, const char *id) return clk; } + +struct clk *devm_clk_get(struct device *dev, const char *id) +{ + return __devm_clk_get(dev, id, false); +} EXPORT_SYMBOL(devm_clk_get); +struct clk *devm_clk_get_optional(struct device *dev, const char *id) +{ + return __devm_clk_get(dev, id, true); +} +EXPORT_SYMBOL(devm_clk_get_optional); + struct clk_bulk_devres { struct clk_bulk_data *clks; int num_clks; diff --git a/drivers/clk/clkdev.c b/drivers/clk/clkdev.c index 0c655d1ba1d9..ebf3afef4371 100644 --- a/drivers/clk/clkdev.c +++ b/drivers/clk/clkdev.c @@ -241,21 +241,34 @@ struct clk *clk_get_sys(const char *dev_id, const char *con_id) } EXPORT_SYMBOL(clk_get_sys); -struct clk *clk_get(struct device *dev, const char *con_id) +static struct clk *internal_clk_get(struct device *dev, const char *con_id, + bool optional) { const char *dev_id = dev ? dev_name(dev) : NULL; struct clk *clk; if (dev && dev->of_node) { - clk = __of_clk_get_by_name(dev->of_node, dev_id, con_id, false); + clk = __of_clk_get_by_name(dev->of_node, dev_id, con_id, + optional); if (!IS_ERR(clk) || PTR_ERR(clk) == -EPROBE_DEFER) return clk; } return clk_get_sys(dev_id, con_id); } + +struct clk *clk_get(struct device *dev, const char *con_id) +{ + return internal_clk_get(dev, con_id, false); +} EXPORT_SYMBOL(clk_get); +struct clk *clk_get_optional(struct device *dev, const char *con_id) +{ + return internal_clk_get(dev, con_id, true); +} +EXPORT_SYMBOL(clk_get_optional); + void clk_put(struct clk *clk) { __clk_put(clk); diff --git a/include/linux/clk.h b/include/linux/clk.h index 84512b3ecf5c..58bebc32133e 100644 --- a/include/linux/clk.h +++ b/include/linux/clk.h @@ -290,6 +290,16 @@ static inline void clk_bulk_unprepare(int num_clks, struct clk_bulk_data *clks) */ struct clk *clk_get(struct device *dev, const char *id); +/** + * clk_get_optional - lookup and obtain a reference to optional clock producer. + * @dev: device for clock "consumer" + * @id: clock consumer ID + * + * Behaves the same as clk_get except where there is no clock producer. In this + * case, instead of returning -ENOENT, the function returns NULL. + */ +struct clk *clk_get_optional(struct device *dev, const char *id); + /** * clk_bulk_get - lookup and obtain a number of references to clock producer. * @dev: device for clock "consumer" @@ -383,6 +393,17 @@ int __must_check devm_clk_bulk_get_all(struct device *dev, */ struct clk *devm_clk_get(struct device *dev, const char *id); +/** + * devm_clk_get_optional - lookup and obtain a managed reference to an optional + * clock producer. + * @dev: device for clock "consumer" + * @id: clock consumer ID + * + * Behaves the same as devm_clk_get except where there is no clock producer. In + * this case, instead of returning -ENOENT, the function returns NULL. + */ +struct clk *devm_clk_get_optional(struct device *dev, const char *id); + /** * devm_get_clk_from_child - lookup and obtain a managed reference to a * clock producer from child node. @@ -701,6 +722,11 @@ static inline struct clk *clk_get(struct device *dev, const char *id) return NULL; } +static inline struct clk *clk_get_optional(struct device *dev, const char *id) +{ + return NULL; +} + static inline int __must_check clk_bulk_get(struct device *dev, int num_clks, struct clk_bulk_data *clks) { @@ -718,6 +744,12 @@ static inline struct clk *devm_clk_get(struct device *dev, const char *id) return NULL; } +static inline struct clk *devm_clk_get_optional(struct device *dev, + const char *id) +{ + return NULL; +} + static inline int __must_check devm_clk_bulk_get(struct device *dev, int num_clks, struct clk_bulk_data *clks) {