From 249a4775ccf296529acf20e52fa32ca41717ef4a Mon Sep 17 00:00:00 2001
From: Benjamin Mugnier <benjamin.mugnier@foss.st.com>
Date: Wed, 7 Jan 2026 13:23:13 +0100
Subject: [PATCH] overlays: Add vd55g1 and vd65g4 camera sensors overlays

Provide two device trees : vd55g1 is monochrome, while vd65g4 is RGB.

Factorize most of the definitions in vd55g1_vd65g4-overlay.dtsi and
describe the overlays in README.

Support both cam0 and cam1 interfaces with raspberry pi __overrides__
mechanism.

Signed-off-by: Benjamin Mugnier <benjamin.mugnier@foss.st.com>
---
 arch/arm/boot/dts/overlays/Makefile           |   2 +
 arch/arm/boot/dts/overlays/README             |  30 +++++
 arch/arm/boot/dts/overlays/vd55g1-overlay.dts |  22 ++++
 .../dts/overlays/vd55g1_vd65g4-overlay.dtsi   | 108 ++++++++++++++++++
 arch/arm/boot/dts/overlays/vd65g4-overlay.dts |  22 ++++
 5 files changed, 184 insertions(+)
 create mode 100644 arch/arm/boot/dts/overlays/vd55g1-overlay.dts
 create mode 100644 arch/arm/boot/dts/overlays/vd55g1_vd65g4-overlay.dtsi
 create mode 100644 arch/arm/boot/dts/overlays/vd65g4-overlay.dts

--- a/arch/arm/boot/dts/overlays/Makefile
+++ b/arch/arm/boot/dts/overlays/Makefile
@@ -346,7 +346,9 @@ dtbo-$(CONFIG_ARCH_BCM2835) += \
 	vc4-kms-v3d-pi4.dtbo \
 	vc4-kms-v3d-pi5.dtbo \
 	vc4-kms-vga666.dtbo \
+	vd55g1.dtbo \
 	vd56g3.dtbo \
+	vd65g4.dtbo \
 	vd66gy.dtbo \
 	vec-gpio-pi5.dtbo \
 	vga666.dtbo \
--- a/arch/arm/boot/dts/overlays/README
+++ b/arch/arm/boot/dts/overlays/README
@@ -5866,6 +5866,21 @@ Params: ddc                     Enables
                                 GPIOs, therefore level shifters are required.
 
 
+Name:   vd55g1
+Info:   ST VD55G1 camera module.
+        Uses Unicam 1, which is the standard camera connector on most Pi
+        variants.
+Load:   dtoverlay=vd55g1,<param>=<val>
+Params: rotation                Mounting rotation of the camera sensor (0 or
+                                180, default 0)
+        orientation             Sensor orientation (0 = front, 1 = rear,
+                                2 = external, default external)
+        media-controller        Configure use of Media Controller API for
+                                configuring the sensor (default on)
+        cam0                    Adopt the default configuration for CAM0 on a
+                                Compute Module (CSI0, i2c_vc, and cam0_reg).
+
+
 Name:   vd56g3
 Info:   ST VD56G3 camera module.
         Uses Unicam 1, which is the standard camera connector on most Pi
@@ -5874,6 +5889,21 @@ Load:   dtoverlay=vd56g3,<param>=<val>
 Params: rotation                Mounting rotation of the camera sensor (0 or
                                 180, default 0)
         orientation             Sensor orientation (0 = front, 1 = rear,
+                                2 = external, default external)
+        media-controller        Configure use of Media Controller API for
+                                configuring the sensor (default on)
+        cam0                    Adopt the default configuration for CAM0 on a
+                                Compute Module (CSI0, i2c_vc, and cam0_reg).
+
+
+Name:   vd65g4
+Info:   ST VD65G4 camera module.
+        Uses Unicam 1, which is the standard camera connector on most Pi
+        variants.
+Load:   dtoverlay=vd65g4,<param>=<val>
+Params: rotation                Mounting rotation of the camera sensor (0 or
+                                180, default 0)
+        orientation             Sensor orientation (0 = front, 1 = rear,
                                 2 = external, default external)
         media-controller        Configure use of Media Controller API for
                                 configuring the sensor (default on)
--- /dev/null
+++ b/arch/arm/boot/dts/overlays/vd55g1-overlay.dts
@@ -0,0 +1,22 @@
+// SPDX-License-Identifier: GPL-2.0-only
+// Definitions for VD55G1 camera module on VC I2C bus
+
+/dts-v1/;
+/plugin/;
+
+#include <dt-bindings/gpio/gpio.h>
+#include "vd55g1_vd65g4-overlay.dtsi"
+
+/{
+	compatible = "brcm,bcm2835";
+
+	// Fragment numbers deliberately high to avoid conflicts with the
+	// included vd55g1_vd65g4 overlay file.
+
+	fragment@101 {
+		target = <&cam_node>;
+		__overlay__ {
+			compatible = "st,vd55g1";
+		};
+	};
+};
--- /dev/null
+++ b/arch/arm/boot/dts/overlays/vd55g1_vd65g4-overlay.dtsi
@@ -0,0 +1,108 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/dts-v1/;
+/plugin/;
+
+/{
+	compatible = "brcm,bcm2835";
+
+	fragment@0 {
+		target = <&i2c0if>;
+		__overlay__ {
+			status = "okay";
+		};
+	};
+
+	clk_frag: fragment@1 {
+		target = <&cam1_clk>;
+		__overlay__ {
+			status = "okay";
+			clock-frequency = <12000000>;
+		};
+	};
+
+	fragment@2 {
+		target = <&i2c0mux>;
+		__overlay__ {
+			status = "okay";
+		};
+	};
+
+	i2c_frag: fragment@3 {
+		target = <&i2c_csi_dsi>;
+		__overlay__ {
+			#address-cells = <1>;
+			#size-cells = <0>;
+			status = "okay";
+
+			cam_node: cam@10 {
+				reg = <0x10>;
+				status = "disabled";
+
+				clocks = <&cam1_clk>;
+				clock-names = "xclk";
+
+				vana-supply = <&cam1_reg>;	/* 2.8v */
+				vddio-supply = <&cam_dummy_reg>;	/* 1.8v */
+				vcore-supply = <&cam_dummy_reg>;	/* 1.2v */
+
+				rotation = <0>;
+				orientation = <2>;
+
+				st,leds = <2>;
+
+				port {
+					cam_endpoint: endpoint {
+						clock-lanes = <0>;
+						data-lanes = <1>;
+						clock-noncontinuous;
+						link-frequencies =
+							/bits/ 64 <600000000>;
+						lane-polarities = <1 1>;
+					};
+				};
+			};
+		};
+	};
+
+	csi_frag: fragment@4 {
+		target = <&csi1>;
+		csi: __overlay__ {
+			status = "okay";
+
+			port {
+				csi_ep: endpoint {
+					remote-endpoint = <&cam_endpoint>;
+					clock-lanes = <0>;
+					data-lanes = <1>;
+					clock-noncontinuous;
+				};
+			};
+		};
+	};
+
+	fragment@5 {
+		target = <&csi1>;
+		__dormant__ {
+			compatible = "brcm,bcm2835-unicam-legacy";
+		};
+	};
+
+	__overrides__ {
+		rotation = <&cam_node>,"rotation:0";
+		orientation = <&cam_node>,"orientation:0";
+		media-controller = <0>,"!5";
+		cam0 = <&i2c_frag>, "target:0=",<&i2c_csi_dsi0>,
+		       <&csi_frag>, "target:0=",<&csi0>,
+		       <&clk_frag>, "target:0=",<&cam0_clk>,
+		       <&cam_node>, "clocks:0=",<&cam0_clk>,
+		       <&cam_node>, "vana-supply:0=",<&cam0_reg>;
+	};
+};
+
+&cam_node {
+	status = "okay";
+};
+
+&cam_endpoint {
+	remote-endpoint = <&csi_ep>;
+};
--- /dev/null
+++ b/arch/arm/boot/dts/overlays/vd65g4-overlay.dts
@@ -0,0 +1,22 @@
+// SPDX-License-Identifier: GPL-2.0-only
+// Definitions for VD65G4 camera module on VC I2C bus
+
+/dts-v1/;
+/plugin/;
+
+#include <dt-bindings/gpio/gpio.h>
+#include "vd55g1_vd65g4-overlay.dtsi"
+
+/{
+	compatible = "brcm,bcm2835";
+
+	// Fragment numbers deliberately high to avoid conflicts with the
+	// included vd55g1_vd65g4 overlay file.
+
+	fragment@101 {
+		target = <&cam_node>;
+		__overlay__ {
+			compatible = "st,vd65g4";
+		};
+	};
+};
