mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: bst@pengutronix.de, Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH master 1/2] clk: implement clk_get_optional helper
Date: Mon,  4 Sep 2023 17:49:52 +0200	[thread overview]
Message-ID: <20230904154953.2367158-1-a.fatoum@pengutronix.de> (raw)

Lack of clock can be ok at times and thus the clk API accepts NULL
arguments and treats them as no-op.

Linux provides a clk_get_optional function to simplify code with such
optional code, so let's provide an equivalent for barebox.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 include/linux/clk.h | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/include/linux/clk.h b/include/linux/clk.h
index 8509d5ece9d5..82022e78e39d 100644
--- a/include/linux/clk.h
+++ b/include/linux/clk.h
@@ -932,4 +932,23 @@ static inline void clk_bulk_disable(int num_clks,
 
 #endif
 
+/**
+ * clk_get_optional - lookup and obtain a reference to an 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.
+ */
+static inline struct clk *clk_get_optional(struct device *dev, const char *id)
+{
+	struct clk *clk = clk_get(dev, id);
+
+	if (clk == ERR_PTR(-ENOENT))
+		return NULL;
+
+	return clk;
+}
+
 #endif
-- 
2.39.2




             reply	other threads:[~2023-09-04 15:51 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-04 15:49 Ahmad Fatoum [this message]
2023-09-04 15:49 ` [PATCH master 2/2] pwm: imx: enable clocks during PWM register accesses Ahmad Fatoum
2023-09-05 11:02   ` Marco Felsch
2023-09-06 12:42   ` Bastian Krause
2023-09-05 11:03 ` [PATCH master 1/2] clk: implement clk_get_optional helper Marco Felsch

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230904154953.2367158-1-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=bst@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox