[RFC 2/3] serial: mxc: Enable getting and enabling clocks with CCF Composite

Adam Ford aford173 at gmail.com
Sat Apr 30 18:14:21 CEST 2022


Certain platforms have the UART clocks exposed through the CCF.
When they are, it's possible to enable and query the clock(s)
for a given UART. Add support getting, enabling, and querying
the clocks.

Signed-off-by: Adam Ford <aford173 at gmail.com>

diff --git a/drivers/serial/serial_mxc.c b/drivers/serial/serial_mxc.c
index e4970a169b..c68040ba74 100644
--- a/drivers/serial/serial_mxc.c
+++ b/drivers/serial/serial_mxc.c
@@ -10,6 +10,7 @@
 #include <asm/arch/imx-regs.h>
 #include <asm/arch/clock.h>
 #include <asm/global_data.h>
+#include <clk.h>
 #include <dm/platform_data/serial_mxc.h>
 #include <serial.h>
 #include <linux/compiler.h>
@@ -266,8 +267,13 @@ __weak struct serial_device *default_serial_console(void)
 int mxc_serial_setbrg(struct udevice *dev, int baudrate)
 {
 	struct mxc_serial_plat *plat = dev_get_plat(dev);
-	u32 clk = imx_get_uartclk();
+	u32 clk;
 
+#if CONFIG_IS_ENABLED(CLK_COMPOSITE_CCF)
+	 clk = clk_get_rate(&plat->ipg_clk);
+#else
+	clk = imx_get_uartclk;
+#endif
 	_mxc_serial_setbrg(plat->reg, clk, baudrate, plat->use_dte);
 
 	return 0;
@@ -277,6 +283,22 @@ static int mxc_serial_probe(struct udevice *dev)
 {
 	struct mxc_serial_plat *plat = dev_get_plat(dev);
 
+#if CONFIG_IS_ENABLED(CLK_COMPOSITE_CCF)
+	int ret = 0;
+
+	ret = clk_enable(&plat->per_clk);
+	if (ret) {
+		printf("Failed to enable per_clk\n");
+		return ret;
+	}
+
+	ret = clk_enable(&plat->per_clk);
+	if (ret) {
+		printf("Failed to enable ipg_clk\n");
+		return ret;
+	}
+
+#endif
 	_mxc_serial_init(plat->reg, plat->use_dte);
 
 	return 0;
@@ -339,6 +361,21 @@ static int mxc_serial_of_to_plat(struct udevice *dev)
 
 	plat->use_dte = fdtdec_get_bool(gd->fdt_blob, dev_of_offset(dev),
 					"fsl,dte-mode");
+#if CONFIG_IS_ENABLED(CLK_COMPOSITE_CCF)
+	int ret = 0;
+
+	ret = clk_get_by_name(dev, "per", &plat->per_clk);
+	if (ret) {
+		printf("Failed to get per_clk\n");
+		return ret;
+	}
+
+	ret = clk_get_by_name(dev, "ipg", &plat->ipg_clk);
+	if (ret) {
+		printf("Failed to get per_clk\n");
+		return ret;
+	}
+#endif
 	return 0;
 }
 
diff --git a/include/dm/platform_data/serial_mxc.h b/include/dm/platform_data/serial_mxc.h
index cc59eeb1dd..9a8c8498bf 100644
--- a/include/dm/platform_data/serial_mxc.h
+++ b/include/dm/platform_data/serial_mxc.h
@@ -10,6 +10,8 @@
 struct mxc_serial_plat {
 	struct mxc_uart *reg;  /* address of registers in physical memory */
 	bool use_dte;
+	struct clk per_clk;
+	struct clk ipg_clk;
 };
 
 #endif
-- 
2.34.1



More information about the U-Boot mailing list