From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH v2 1/2] console: provide best-effort clk_get_for_console helper
Date: Wed, 22 Nov 2023 18:13:19 +0100 [thread overview]
Message-ID: <20231122171320.1714868-1-a.fatoum@pengutronix.de> (raw)
From: Ahmad Fatoum <ahmad@a3f.at>
clk_get will return -EPROBE_DEFER if clock provider hasn't yet been
probed. In a system with deep probe enabled, dependencies are probed
on demand, so a -EPROBE_DEFER return is final and the console probe
will never succeed.
CONFIG_DEBUG_LL is often used to debug this, but because the low-level
console is not interactive, it's a bit cumbersome. Improve upon this a
bit, by providing a clk_get_for_console helper that returns NULL if and
only if we are sure that a clock provider will not be probed.
In that case, the driver can skip code paths initialization code and
baud rate setting dependent on having access to the clock and still
register a console that reuses what was set up by CONFIG_DEBUG_LL.
Signed-off-by: Ahmad Fatoum <ahmad@a3f.at>
---
v1 -> v2:
- restrict new mechanism to stdout console (Sascha)
---
include/console.h | 27 +++++++++++++++++++++++++++
include/linux/clk.h | 21 +++++++++++++++++++++
2 files changed, 48 insertions(+)
diff --git a/include/console.h b/include/console.h
index d7cbdfa99207..69c0ec144b31 100644
--- a/include/console.h
+++ b/include/console.h
@@ -8,6 +8,7 @@
#define _CONSOLE_H_
#include <param.h>
+#include <linux/clk.h>
#include <linux/list.h>
#include <driver.h>
#include <serdev.h>
@@ -228,4 +229,30 @@ static inline void console_ctrlc_allow(void) { }
static inline void console_ctrlc_forbid(void) { }
#endif
+/**
+ * clk_get_for_console - get clock, ignoring known unavailable clock controller
+ * @dev: device for clock "consumer"
+ * @id: clock consumer ID
+ *
+ * Return: a struct clk corresponding to the clock producer, a
+ * valid IS_ERR() condition containing errno or NULL if it could
+ * be determined that the clock producer will never be probed in
+ * absence of modules. The NULL return allows serial drivers to
+ * skip clock handling for the stdout console and rely on CONFIG_DEBUG_LL.
+ */
+static inline struct clk *clk_get_for_console(struct device *dev, const char *id)
+{
+ __always_unused unsigned baudrate;
+ struct clk *clk;
+
+ if (!IS_ENABLED(CONFIG_DEBUG_LL) || !of_device_is_stdout_path(dev, &baudrate))
+ return clk_get(dev, id);
+
+ clk = clk_get_if_available(dev, id);
+ if (clk == NULL)
+ dev_warn(dev, "couldn't get clock (ignoring)\n");
+
+ return clk;
+}
+
#endif
diff --git a/include/linux/clk.h b/include/linux/clk.h
index 61b4ff3127cf..f505f18a75c0 100644
--- a/include/linux/clk.h
+++ b/include/linux/clk.h
@@ -14,6 +14,7 @@
#include <linux/spinlock.h>
#include <linux/stringify.h>
#include <linux/container_of.h>
+#include <deep-probe.h>
#include <xfuncs.h>
struct device;
@@ -982,4 +983,24 @@ static inline struct clk *clk_get_enabled(struct device *dev, const char *id)
return clk;
}
+/**
+ * clk_get_if_available - get clock, ignoring known unavailable clock controller
+ * @dev: device for clock "consumer"
+ * @id: clock consumer ID
+ *
+ * Return: a struct clk corresponding to the clock producer, a
+ * valid IS_ERR() condition containing errno or NULL if it could
+ * be determined that the clock producer will never be probed in
+ * absence of modules.
+ */
+static inline struct clk *clk_get_if_available(struct device *dev, const char *id)
+{
+ struct clk *clk = clk_get(dev, id);
+
+ if (clk == ERR_PTR(-EPROBE_DEFER) && deep_probe_is_supported())
+ return NULL;
+
+ return clk;
+}
+
#endif
--
2.39.2
next reply other threads:[~2023-11-22 17:14 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-22 17:13 Ahmad Fatoum [this message]
2023-11-22 17:13 ` [PATCH v2 2/2] serial: stm32: support probing with missing clock provider Ahmad Fatoum
2023-11-23 7:22 ` [PATCH v2 1/2] console: provide best-effort clk_get_for_console helper Sascha Hauer
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=20231122171320.1714868-1-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
/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