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) {