[v4,23/29] video: stm32: ltdc: select the pixel clock source on STM32MP25

Message ID 20261203171852.62649-24-dario.binacchi@amarulasolutions.com
State New
Headers
Series Add Engicam MicroGEA-STM32MP257D-RMM board support |

Commit Message

Dario Binacchi Dec. 3, 2026, 5:18 p.m. UTC
On STM32MP25 the LTDC pixel clock is selected by the SYSCFG DISPLAYCLKCR
mux, referenced by the "ref" clock of the LTDC, whose reset value is the
LVDS PHY clock. As nothing programs it, a panel connected directly to
the LTDC gets no pixel clock.

Select the LVDS PHY clock when the LTDC feeds the LVDS bridge, and the
LTDC kernel clock otherwise.

Co-developed-by: Yannick Fertre <yannick.fertre@foss.st.com>
Signed-off-by: Yannick Fertre <yannick.fertre@foss.st.com>
Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>

---

Changes in v4:
- Select the LTDC kernel clock by default, as it is also needed by
  the DSI bridge
- Add Co-developed-by tag

Changes in v3:
- Select the pixel clock source only on st,stm32mp255-ltdc

 drivers/video/stm32/stm32_ltdc.c | 52 ++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)
  

Patch

diff --git a/drivers/video/stm32/stm32_ltdc.c b/drivers/video/stm32/stm32_ltdc.c
index da580a78a5db..0351cd98bc4d 100644
--- a/drivers/video/stm32/stm32_ltdc.c
+++ b/drivers/video/stm32/stm32_ltdc.c
@@ -12,7 +12,9 @@ 
 #include <dm.h>
 #include <log.h>
 #include <panel.h>
+#include <regmap.h>
 #include <reset.h>
+#include <syscon.h>
 #include <video.h>
 #include <video_bridge.h>
 #include <asm/io.h>
@@ -275,6 +277,12 @@  static const u32 layer_regs_a2[] = {
 #define HWVER_40100 0x040100
 #define HWVER_40101 0x040101
 
+/* STM32MP25 SYSCFG pixel clock mux, described by the "ref" clock */
+#define SYSCFG_DISPLAYCLKCR		0x5000
+#define DISPLAYCLKCR_DPIVSLVDS		GENMASK(1, 0)
+#define DISPLAYCLKCR_LVDS		1
+#define DISPLAYCLKCR_DPI		2
+
 enum stm32_ltdc_pix_fmt {
 	PF_ARGB8888 = 0,	/* ARGB [32 bits] */
 	PF_ABGR8888,		/* ABGR [32 bits] */
@@ -709,6 +717,41 @@  static int stm32_ltdc_of_to_plat(struct udevice *dev)
 	return ret;
 }
 
+/*
+ * On STM32MP25 the LTDC pixel clock is selected in SYSCFG_DISPLAYCLKCR
+ * among the DSI byte lane clock, the LVDS PHY pixel clock (reset value)
+ * and the LTDC kernel clock. Select the LVDS PHY pixel clock when the
+ * LTDC feeds the LVDS bridge, the LTDC kernel clock otherwise.
+ */
+static int stm32_ltdc_set_pixel_clock_source(struct udevice *dev)
+{
+	struct stm32_ltdc_plat *plat = dev_get_plat(dev);
+	struct ofnode_phandle_args args;
+	struct regmap *regmap;
+	u32 src = DISPLAYCLKCR_DPI;
+	int index, ret;
+
+	index = dev_read_stringlist_search(dev, "clock-names", "ref");
+	if (index < 0)
+		return 0;
+
+	if (plat->bridge &&
+	    device_is_compatible(plat->bridge, "st,stm32mp25-lvds"))
+		src = DISPLAYCLKCR_LVDS;
+
+	ret = dev_read_phandle_with_args(dev, "clocks", "#clock-cells", 0,
+					 index, &args);
+	if (ret)
+		return ret;
+
+	regmap = syscon_node_to_regmap(args.node);
+	if (IS_ERR(regmap))
+		return PTR_ERR(regmap);
+
+	return regmap_update_bits(regmap, SYSCFG_DISPLAYCLKCR,
+				  DISPLAYCLKCR_DPIVSLVDS, src);
+}
+
 static int stm32_ltdc_probe(struct udevice *dev)
 {
 	struct video_uc_plat *uc_plat = dev_get_uclass_plat(dev);
@@ -719,6 +762,15 @@  static int stm32_ltdc_probe(struct udevice *dev)
 	ulong rate;
 	int ret;
 
+	if (device_is_compatible(dev, "st,stm32mp255-ltdc")) {
+		ret = stm32_ltdc_set_pixel_clock_source(dev);
+		if (ret) {
+			dev_err(dev, "pixel clock source selection error %d\n",
+				ret);
+			return ret;
+		}
+	}
+
 	ret = clk_enable(&plat->bclk);
 	if (ret) {
 		dev_err(dev, "bus clock enable error %d\n", ret);