mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH v2 1/2] clk: implement clk_get_optional helper
@ 2023-09-06 13:39 Bastian Krause
  2023-09-06 13:39 ` [PATCH v2 2/2] pwm: imx: enable clocks during PWM register accesses Bastian Krause
  2023-09-06 14:09 ` [PATCH v2 1/2] clk: implement clk_get_optional helper Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Bastian Krause @ 2023-09-06 13:39 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum, Uwe Kleine-König, Marco Felsch

From: Ahmad Fatoum <a.fatoum@pengutronix.de>

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>
Reviewed-by: Marco Felsch <m.felsch@pengutronix.de>
---
No changes since (implicit) v1.
---
 include/linux/clk.h | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/include/linux/clk.h b/include/linux/clk.h
index 8509d5ece9d..82022e78e39 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




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-09-06 14:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-06 13:39 [PATCH v2 1/2] clk: implement clk_get_optional helper Bastian Krause
2023-09-06 13:39 ` [PATCH v2 2/2] pwm: imx: enable clocks during PWM register accesses Bastian Krause
2023-09-06 14:09 ` [PATCH v2 1/2] clk: implement clk_get_optional helper Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox