// SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
/*
 * Device Tree Overlay for an IMX462 camera sensor on connector J2 on R-Car V4H
 * ES3.0 Sparrow Hawk board.
 *
 * Copyright 2025 Renesas Electronics Corp.
 * Copyright 2025 Niklas Söderlund <niklas.soderlund@ragnatech.se>
 */

/dts-v1/;
/plugin/;

#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/media/video-interfaces.h>
#include <dt-bindings/media/video-interface-devices.h>

&{/} {
	clk_cam_j2: clk-cam-j2 {
		compatible = "fixed-clock";
		#clock-cells = <0>;
		clock-frequency = <37125000>;
	};

	/* Page 29 / CSI_IF_CN / J2 */
	reg_cam_j2: reg-cam-j2 {
		compatible = "regulator-fixed";
		regulator-name = "cam-J2";
		enable-active-high;
		gpios = <&gpio0 2 GPIO_ACTIVE_HIGH>;
	};
};

&i2c2 {
	#address-cells = <1>;
	#size-cells = <0>;
	status = "okay";

	cam@1a {
		compatible = "sony,imx462lqr";
		reg = <0x1a>;

		clocks = <&clk_cam_j2>;
		clock-names = "xclk";
		clock-frequency = <37125000>;

		vdddo-supply = <&reg_cam_j2>;
		vdda-supply = <&reg_cam_j2>;
		vddd-supply = <&reg_cam_j2>;

		orientation = <MEDIA_ORIENTATION_EXTERNAL>;
		rotation = <0>;

		port {
			imx462_j2_out: endpoint {
				link-frequencies = /bits/ 64 <222750000 148500000>;
				data-lanes = <1 2 3 4>;
				remote-endpoint = <&csi41_in>;
			};
		};
	};
};

/* Page 29 / CSI_IF_CN */
&csi41 {
	status = "okay";

	ports {
		#address-cells = <1>;
		#size-cells = <0>;

		port@0 {
			reg = <0>;

			csi41_in: endpoint {
				bus-type = <MEDIA_BUS_TYPE_CSI2_DPHY>;
				clock-lanes = <0>;
				data-lanes = <1 2 3 4>;
				remote-endpoint = <&imx462_j2_out>;
			};
		};
	};
};

&isp1 {
	status = "okay";
};

&vin08 {
	status = "okay";
};

&vin09 {
	status = "okay";
};

&vin10 {
	status = "okay";
};

&vin11 {
	status = "okay";
};

&vin12 {
	status = "okay";
};

&vin13 {
	status = "okay";
};

&vin14 {
	status = "okay";
};

&vin15 {
	status = "okay";
};