From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 1/3] serial: introduce clk_get_enabled_for_console()
Date: Wed, 25 Mar 2026 12:42:46 +0100 [thread overview]
Message-ID: <20260325114753.2249763-2-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20260325114753.2249763-1-a.fatoum@pengutronix.de>
For all serial drivers that call clk_get_for_console() followed
by clk_enable(), while checking both for errors, switch over to
a new clk_get_enabled_for_console().
This makes code more concise and allows ignoring a specific clk_enable
error code in the next commit.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
drivers/serial/serial_lpuart.c | 12 +++---------
drivers/serial/serial_lpuart32.c | 12 +++---------
drivers/serial/serial_ns16550.c | 9 +++------
drivers/serial/serial_stm32.c | 10 ++--------
include/console.h | 15 +++++++++++++++
include/linux/clk.h | 28 ++++++++++++++++++++++++++++
6 files changed, 54 insertions(+), 32 deletions(-)
diff --git a/drivers/serial/serial_lpuart.c b/drivers/serial/serial_lpuart.c
index 8bbef08309f9..d9416d538cc5 100644
--- a/drivers/serial/serial_lpuart.c
+++ b/drivers/serial/serial_lpuart.c
@@ -131,16 +131,10 @@ static int lpuart_serial_probe(struct device *dev)
}
lpuart->base = IOMEM(lpuart->io->start);
- lpuart->clk = clk_get_for_console(dev, NULL);
+ lpuart->clk = clk_get_enabled_for_console(dev, NULL);
if (IS_ERR(lpuart->clk)) {
- ret = PTR_ERR(lpuart->clk);
- dev_err(dev, "Failed to get UART clock %d\n", ret);
- goto io_release;
- }
-
- ret = clk_enable(lpuart->clk);
- if (ret) {
- dev_err(dev, "Failed to enable UART clock %d\n", ret);
+ ret = dev_errp_probe(dev, lpuart->clk,
+ "Failed to get/enable UART clock\n");
goto io_release;
}
diff --git a/drivers/serial/serial_lpuart32.c b/drivers/serial/serial_lpuart32.c
index 25f0782e026e..e1ba872849ac 100644
--- a/drivers/serial/serial_lpuart32.c
+++ b/drivers/serial/serial_lpuart32.c
@@ -119,16 +119,10 @@ static int lpuart32_serial_probe(struct device *dev)
}
lpuart32->base = IOMEM(lpuart32->io->start) + devtype->reg_offs;
- lpuart32->clk = clk_get_for_console(dev, NULL);
+ lpuart32->clk = clk_get_enabled_for_console(dev, NULL);
if (IS_ERR(lpuart32->clk)) {
- ret = PTR_ERR(lpuart32->clk);
- dev_err(dev, "Failed to get UART clock %d\n", ret);
- goto io_release;
- }
-
- ret = clk_enable(lpuart32->clk);
- if (ret) {
- dev_err(dev, "Failed to enable UART clock %d\n", ret);
+ ret = dev_errp_probe(dev, lpuart32->clk,
+ "Failed to get/enable UART clock\n");
goto io_release;
}
diff --git a/drivers/serial/serial_ns16550.c b/drivers/serial/serial_ns16550.c
index 61e294a38c4c..b220982450dd 100644
--- a/drivers/serial/serial_ns16550.c
+++ b/drivers/serial/serial_ns16550.c
@@ -529,15 +529,12 @@ static int ns16550_probe(struct device *dev)
priv->plat.clock = devtype->clk_default;
if (!priv->plat.clock) {
- priv->clk = clk_get_for_console(dev, NULL);
+ priv->clk = clk_get_enabled_for_console(dev, NULL);
if (IS_ERR(priv->clk)) {
- ret = PTR_ERR(priv->clk);
- dev_err(dev, "failed to get clk (%d)\n", ret);
+ ret = dev_errp_probe(dev, priv->clk,
+ "failed to get/enable clk\n");
goto release_region;
}
- ret = clk_enable(priv->clk);
- if (ret)
- goto clk_put;
priv->plat.clock = clk_get_rate(priv->clk);
}
diff --git a/drivers/serial/serial_stm32.c b/drivers/serial/serial_stm32.c
index f61d04aed440..1cf58be09e2f 100644
--- a/drivers/serial/serial_stm32.c
+++ b/drivers/serial/serial_stm32.c
@@ -165,16 +165,10 @@ static int stm32_serial_probe(struct device *dev)
stm32->stm32f4 = info->stm32f4;
stm32->uart_enable_bit = info->uart_enable_bit;
- stm32->clk = clk_get_for_console(dev, NULL);
+ stm32->clk = clk_get_enabled_for_console(dev, NULL);
if (IS_ERR(stm32->clk)) {
ret = dev_err_probe(dev, PTR_ERR(stm32->clk),
- "Failed to get UART clock\n");
- goto io_release;
- }
-
- ret = clk_enable(stm32->clk);
- if (ret) {
- dev_err_probe(dev, ret, "Failed to enable UART clock\n");
+ "Failed to get/enable UART clock\n");
goto io_release;
}
diff --git a/include/console.h b/include/console.h
index b163c6684ee1..d5e18bde61c8 100644
--- a/include/console.h
+++ b/include/console.h
@@ -282,4 +282,19 @@ static inline struct clk *clk_get_for_console(struct device *dev, const char *id
return clk;
}
+static inline struct clk *clk_get_enabled_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_enabled(dev, id);
+
+ clk = clk_get_enabled_if_available(dev, id);
+ if (clk == NULL)
+ dev_warn(dev, "couldn't get/enable clock (ignoring)\n");
+
+ return clk;
+}
+
#endif
diff --git a/include/linux/clk.h b/include/linux/clk.h
index 655e7a52e9b9..1cb8a1898e10 100644
--- a/include/linux/clk.h
+++ b/include/linux/clk.h
@@ -1270,4 +1270,32 @@ static inline struct clk *clk_get_if_available(struct device *dev, const char *i
return clk;
}
+/**
+ * clk_get_enabled_if_available - get & enable clock, ignoring known unavailable clock controller
+ * @dev: device for clock "consumer"
+ * @id: clock consumer ID
+ *
+ * Return: a struct clk corresponding to the clock producer after enabling it, 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_enabled_if_available(struct device *dev,
+ const char *id)
+{
+ struct clk *clk = clk_get_if_available(dev, id);
+ int ret;
+
+ if (IS_ERR_OR_NULL(clk))
+ return clk;
+
+ ret = clk_enable(clk);
+ if (ret) {
+ clk_put(clk);
+ return ERR_PTR(ret);
+ }
+
+ return clk;
+}
+
#endif
--
2.47.3
next prev parent reply other threads:[~2026-03-25 11:48 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-25 11:42 [PATCH 0/3] firmware: arm_scmi: clock: make more robust Ahmad Fatoum
2026-03-25 11:42 ` Ahmad Fatoum [this message]
2026-03-25 11:42 ` [PATCH 2/3] clk: ignore -EPROTO in clk_get_enabled_if_available Ahmad Fatoum
2026-03-25 11:42 ` [PATCH 3/3] firmware: arm_scmi: clock: sync with Linux v7.0 Ahmad Fatoum
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=20260325114753.2249763-2-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