// SPDX-License-Identifier: (GPL-2.0+ OR MIT)


/{
	ext_cam_24m_clk: external-camera-24m-clock {
		compatible = "fixed-clock";
		#clock-cells = <0>;
		clock-frequency = <24000000>;
		clock-output-names = "ext_cam_24m_clk";
	}; 

	ext_cam_37m_clk: external-camera-37m-clock {
		compatible = "fixed-clock";
		clock-frequency = <37125000>;
		clock-output-names = "ext_cam_37m_clk";
		#clock-cells = <0>;
	};

	vdd_cam_5v: vdd-cam-5v-regulator {
		compatible = "regulator-fixed";
		regulator-name = "vdd_cam_5v";
		regulator-always-on;
		regulator-boot-on;
		regulator-min-microvolt = <3300000>;
		regulator-max-microvolt = <3300000>;
	};

	cam_dovdd: cam-dovdd {
		compatible = "regulator-fixed";
		regulator-name = "cam_dovdd";
		regulator-always-on;
		regulator-boot-on;
		regulator-min-microvolt = <1800000>;
		regulator-max-microvolt = <1800000>;
		vin-supply = <&vdd_cam_5v>;
	};

	cam_avdd: cam-avdd {
		compatible = "regulator-fixed";
		regulator-name = "cam_avdd";
		regulator-always-on;
		regulator-boot-on;
		regulator-min-microvolt = <2800000>;
		regulator-max-microvolt = <2800000>;
		vin-supply = <&vdd_cam_5v>;
	};

	cam_dvdd: cam-dvdd {
		compatible = "regulator-fixed";
		regulator-name = "cam_dvdd";
		regulator-always-on;
		regulator-boot-on;
		regulator-min-microvolt = <1200000>;
		regulator-max-microvolt = <1200000>;
		vin-supply = <&vdd_cam_5v>;
	};
};


&csi2_dphy_hw {
	status = "okay";
};

&csi2_dphy1 {
	status = "okay";

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

		port@0 {
			reg = <0>;
			#address-cells = <1>;
			#size-cells = <0>;

			csi_dphy1_input0: endpoint@0 {
				reg = <0>;
				remote-endpoint = <&ov8858_cam0_out>;
				data-lanes = <1 2>;
			};

			csi_dphy1_input1: endpoint@1 {
				reg = <1>;
				remote-endpoint = <&imx415_cam0_out>;
				data-lanes = <1 2>;
			};

			csi_dphy1_input2: endpoint@2 {
				reg = <2>;
				remote-endpoint = <&gc4653_cam0_out>;
				data-lanes = <1 2>;
			};

			csi_dphy1_input3: endpoint@3 {
				reg = <3>;
				remote-endpoint = <&gc2053_cam0_out>;
				data-lanes = <1 2>;
			};

			csi_dphy1_input4: endpoint@4 {
				reg = <4>;
				remote-endpoint = <&gc2093_cam0_out>;
				data-lanes = <1 2>;
			};
		};

		port@1 {
			reg = <1>;
			#address-cells = <1>;
			#size-cells = <0>;

			csi_dphy1_output: endpoint@0 {
				reg = <0>;
				remote-endpoint = <&mipi0_csi2_input>;
			};
		};
	};
};

&csi2_dphy2 {
	status = "okay";

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

		port@0 {
			reg = <0>;
			#address-cells = <1>;
			#size-cells = <0>;

			csi_dphy2_input0: endpoint@0 {
				reg = <0>;
				remote-endpoint = <&ov8858_cam1_out>;
				data-lanes = <1 2>;
			};

			csi_dphy2_input1: endpoint@1 {
				reg = <1>;
				remote-endpoint = <&imx415_cam1_out>;
				data-lanes = <1 2>;
			};
	
			csi_dphy2_input2: endpoint@2 {
				reg = <2>;
				remote-endpoint = <&gc4653_cam1_out>;
				data-lanes = <1 2>;
			};

			csi_dphy2_input3: endpoint@3 {
				reg = <3>;
				remote-endpoint = <&gc2053_cam1_out>;
				data-lanes = <1 2>;
			};

			csi_dphy2_input4: endpoint@4 {
				reg = <4>;
				remote-endpoint = <&gc2093_cam1_out>;
				data-lanes = <1 2>;
			};

		};

		port@1 {
			reg = <1>;
			#address-cells = <1>;
			#size-cells = <0>;

			csi_dphy2_output: endpoint@0 {
				reg = <0>;
				remote-endpoint = <&mipi1_csi2_input>;
			};
		};
	};
};

&i2c4 {
	status = "okay";
	clock-frequency = <400000>;
	pinctrl-names = "default";
	pinctrl-0 = <&i2c4m2_xfer>;

	dw9714_cam0: dw9714-cam0@c {
		status = "okay";
		compatible = "dongwoon,dw9714";
		reg = <0xc>;
		rockchip,camera-module-index = <0>;
		rockchip,vcm-max-current = <100>;
		rockchip,vcm-start-current = <0>;
		rockchip,vcm-rated-current = <100>;
		rockchip,vcm-step-mode = <0xd>;
		rockchip,vcm-dlc-enable = <0>;
		rockchip,vcm-mclk = <0>;	
		rockchip,vcm-t-src = <0>;
		rockchip,camera-module-facing = "back";
	};

	ov8858_cam0: ov8858-cam0@36 {
		compatible = "ovti,ov8858";
		status = "okay";
		reg = <0x36>;
		clocks = <&ext_cam_24m_clk>;
		clock-names = "xvclk";
		pwdn-gpios = <&gpio5 0 GPIO_ACTIVE_HIGH>;
		reset-gpios = <&gpio5 1 GPIO_ACTIVE_HIGH>;

		dovdd-supply= <&cam_dovdd>; /* 1.8v */
		avdd-supply = <&cam_avdd>;  /* 2.8v */
		dvdd-supply = <&cam_dvdd>;  /* 1.2v */

		rockchip,camera-module-index = <0>;
		rockchip,camera-module-facing = "back";
		rockchip,camera-module-name = "HS5885-BNSM1018-V01";
		rockchip,camera-module-lens-name = "default";
		lens-focus = <&dw9714_cam0>;

		port {
			/* MIPI CSI-2 bus endpoint */
			ov8858_cam0_out: endpoint {
				remote-endpoint = <&csi_dphy1_input0>;
				data-lanes = <1 2>;
			};
		};
	};

	imx415_cam0: imx415-cam0@1a {
		compatible = "sony,imx415";
		status = "okay";
		reg = <0x1a>;
		clocks = <&ext_cam_37m_clk>;
		clock-names = "xvclk";
		power-gpios = <&gpio5 0 GPIO_ACTIVE_HIGH>;
		reset-gpios = <&gpio5 1 GPIO_ACTIVE_LOW>;

		dovdd-supply= <&cam_dovdd>; /* 1.8v */
		avdd-supply = <&cam_avdd>;  /* 2.8v */
		dvdd-supply = <&cam_dvdd>;  /* 1.2v */

		rockchip,camera-module-index = <0>;
		rockchip,camera-module-facing = "back";
		rockchip,camera-module-name = "CMK-OT2022-PX1";
		rockchip,camera-module-lens-name = "IR0147-50IRC-8M-F20";
		rockchip,imx415-capture-mode=<1>; /* 1920x1080 */
		port {
			imx415_cam0_out: endpoint {
				remote-endpoint = <&csi_dphy1_input1>;
				data-lanes = <1 2>;
			};
		};
	};

	gc4653_cam0: gc4653-cam0@29 {
		compatible = "galaxycore,gc4653";
		status = "okay";
		reg = <0x29>;
		clocks = <&ext_cam_24m_clk>;
		clock-names = "xvclk";

		avdd-supply = <&cam_avdd>;
		dovdd-supply = <&cam_dovdd>;
		dvdd-supply = <&cam_dvdd>;
		pwdn-gpios = <&gpio5 0 GPIO_ACTIVE_HIGH>;
		reset-gpios = <&gpio5 1 GPIO_ACTIVE_HIGH>;

		rockchip,camera-module-index = <0>;
		rockchip,camera-module-facing = "front";
		rockchip,camera-module-name = "YT10120";
		rockchip,camera-module-lens-name = "30IRC-4M-F20";

		// NO_HDR:0 HDR_X2:5 HDR_X3:6
		// rockchip,camera-hdr-mode = <0>;
		port {
			gc4653_cam0_out: endpoint {
				remote-endpoint = <&csi_dphy1_input2>;
				data-lanes = <1 2>;
			};
		};
	};

	gc2053_cam0: gc2053-cam0@37 {
		compatible = "galaxycore,gc2053";
		status = "okay";
		reg = <0x37>;
		clocks = <&ext_cam_24m_clk>;
		clock-names = "xvclk";

		avdd-supply = <&cam_avdd>;
		dovdd-supply = <&cam_dovdd>;
		dvdd-supply = <&cam_dvdd>;

		pwdn-gpios = <&gpio5 0 GPIO_ACTIVE_LOW>;
		reset-gpios = <&gpio5 1 GPIO_ACTIVE_LOW>;

		rockchip,camera-module-index = <0>;
		rockchip,camera-module-facing = "back";
		rockchip,camera-module-name = "CMK-OT2274-V10";
		rockchip,camera-module-lens-name = "28IRC-F20";
		port {
			gc2053_cam0_out: endpoint {
				remote-endpoint = <&csi_dphy1_input3>;
				data-lanes = <1 2>;
			};
		};
	};

	gc2093_cam0: gc2093-cam0@37 {
		compatible = "galaxycore,gc2093";
		status = "okay";
		reg = <0x37>;
		clocks = <&ext_cam_24m_clk>;
		clock-names = "xvclk";

		avdd-supply = <&cam_avdd>;
		dovdd-supply = <&cam_dovdd>;
		dvdd-supply = <&cam_dvdd>;

		pwdn-gpios = <&gpio5 0 GPIO_ACTIVE_HIGH>;
		reset-gpios = <&gpio5 1 GPIO_ACTIVE_LOW>;

		rockchip,camera-module-index = <0>;
		rockchip,camera-module-facing = "back";
		rockchip,camera-module-name = "SIDA209300461";
		rockchip,camera-module-lens-name = "60IRC_F20";

		port {
			gc2093_cam0_out: endpoint {
				remote-endpoint = <&csi_dphy1_input4>;
				data-lanes = <1 2>;
			};
		};
	};
};

&i2c3 {
    status = "okay";
    clock-frequency = <400000>;
    pinctrl-names = "default";
    pinctrl-0 = <&i2c3m2_xfer>;

	dw9714_cam1: dw9714-cam1@c {
		status = "okay";
		compatible = "dongwoon,dw9714";
		reg = <0xc>;
		rockchip,camera-module-index = <0>;
		rockchip,vcm-max-current = <100>;
		rockchip,vcm-start-current = <0>;
		rockchip,vcm-rated-current = <100>;
		rockchip,vcm-step-mode = <0xd>;
		rockchip,vcm-dlc-enable = <0>;
		rockchip,vcm-mclk = <0>;	
		rockchip,vcm-t-src = <0>;
		rockchip,camera-module-facing = "back";
	};

	ov8858_cam1: ov8858-cam1@36 {
		compatible = "ovti,ov8858";
		status = "okay";
		reg = <0x36>;
		clocks = <&ext_cam_24m_clk>;
		clock-names = "xvclk";
		pwdn-gpios = <&gpio5 2 GPIO_ACTIVE_HIGH>;
		reset-gpios = <&gpio5 3 GPIO_ACTIVE_HIGH>;

		dovdd-supply= <&cam_dovdd>; /* 1.8v */
		avdd-supply = <&cam_avdd>;  /* 2.8v */
		dvdd-supply = <&cam_dvdd>;  /* 1.2v */

		rockchip,camera-module-index = <1>;
		rockchip,camera-module-facing = "back";
		rockchip,camera-module-name = "HS5885-BNSM1018-V01";
		rockchip,camera-module-lens-name = "default";
		lens-focus = <&dw9714_cam0>;

		port {
			/* MIPI CSI-2 bus endpoint */
			ov8858_cam1_out: endpoint {
				remote-endpoint = <&csi_dphy2_input0>;
				data-lanes = <1 2>;
			};
		};
	};

	imx415_cam1: imx415-cam1@1a {
		compatible = "sony,imx415";
		status = "okay";
		reg = <0x1a>;
		clocks = <&ext_cam_37m_clk>;
		clock-names = "xvclk";
		power-gpios = <&gpio5 2 GPIO_ACTIVE_HIGH>;
		reset-gpios = <&gpio5 3 GPIO_ACTIVE_LOW>;

		dovdd-supply= <&cam_dovdd>; /* 1.8v */
		avdd-supply = <&cam_avdd>;  /* 2.8v */
		dvdd-supply = <&cam_dvdd>;  /* 1.2v */

		rockchip,camera-module-index = <1>;
		rockchip,camera-module-facing = "back";
		rockchip,camera-module-name = "CMK-OT2022-PX1";
		rockchip,camera-module-lens-name = "IR0147-50IRC-8M-F20";
		rockchip,imx415-capture-mode=<1>; /* 1920x1080 */
		port {
			imx415_cam1_out: endpoint {
				remote-endpoint = <&csi_dphy2_input1>;
				data-lanes = <1 2>;
			};
		};
	};

	gc4653_cam1: gc4653-cam1@29 {
		compatible = "galaxycore,gc4653";
		status = "okay";
		reg = <0x29>;
		clocks = <&ext_cam_24m_clk>;
		clock-names = "xvclk";

		avdd-supply = <&cam_avdd>;
		dovdd-supply = <&cam_dovdd>;
		dvdd-supply = <&cam_dvdd>;
		pwdn-gpios = <&gpio5 2 GPIO_ACTIVE_HIGH>;
		reset-gpios = <&gpio5 3 GPIO_ACTIVE_HIGH>;

		rockchip,camera-module-index = <1>;
		rockchip,camera-module-facing = "front";
		rockchip,camera-module-name = "YT10120";
		rockchip,camera-module-lens-name = "30IRC-4M-F20";

		// NO_HDR:0 HDR_X2:5 HDR_X3:6
		// rockchip,camera-hdr-mode = <0>;
		port {
			gc4653_cam1_out: endpoint {
				remote-endpoint = <&csi_dphy2_input2>;
				data-lanes = <1 2>;
			};
		};
	};

	gc2053_cam1: gc2053-cam1@37 {
		compatible = "galaxycore,gc2053";
		status = "okay";
		reg = <0x37>;
		clocks = <&ext_cam_24m_clk>;
		clock-names = "xvclk";

		avdd-supply = <&cam_avdd>;
		dovdd-supply = <&cam_dovdd>;
		dvdd-supply = <&cam_dvdd>;

		pwdn-gpios = <&gpio5 2 GPIO_ACTIVE_LOW>;
		reset-gpios = <&gpio5 3 GPIO_ACTIVE_LOW>;

		rockchip,camera-module-index = <1>;
		rockchip,camera-module-facing = "back";
		rockchip,camera-module-name = "CMK-OT2274-V10";
		rockchip,camera-module-lens-name = "28IRC-F20";
		port {
			gc2053_cam1_out: endpoint {
				remote-endpoint = <&csi_dphy2_input3>;
				data-lanes = <1 2>;
			};
		};
	};

	gc2093_cam1: gc2093-cam1@37 {
		compatible = "galaxycore,gc2093";
		status = "okay";
		reg = <0x37>;
		clocks = <&ext_cam_24m_clk>;
		clock-names = "xvclk";

		avdd-supply = <&cam_avdd>;
		dovdd-supply = <&cam_dovdd>;
		dvdd-supply = <&cam_dvdd>;

		pwdn-gpios = <&gpio5 2 GPIO_ACTIVE_HIGH>;
		reset-gpios = <&gpio5 3 GPIO_ACTIVE_LOW>;

		rockchip,camera-module-index = <1>;
		rockchip,camera-module-facing = "back";
		rockchip,camera-module-name = "SIDA209300461";
		rockchip,camera-module-lens-name = "60IRC_F20";

		port {
			gc2093_cam1_out: endpoint {
				remote-endpoint = <&csi_dphy2_input4>;
				data-lanes = <1 2>;
			};
		};
	};

};

&mipi0_csi2 {
	status = "okay";

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

		port@0 {
			reg = <0>;
			#address-cells = <1>;
			#size-cells = <0>;

			mipi0_csi2_input: endpoint@1 {
				reg = <1>;
				remote-endpoint = <&csi_dphy1_output>;
			};
		};

		port@1 {
			reg = <1>;
			#address-cells = <1>;
			#size-cells = <0>;

			mipi0_csi2_output: endpoint@0 {
				reg = <0>;
				remote-endpoint = <&cif_mipi_in0>;
			};
		};
	};
};

&mipi1_csi2 {
	status = "okay";

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

		port@0 {
			reg = <0>;
			#address-cells = <1>;
			#size-cells = <0>;

			mipi1_csi2_input: endpoint@1 {
				reg = <1>;
				remote-endpoint = <&csi_dphy2_output>;
			};
		};

		port@1 {
			reg = <1>;
			#address-cells = <1>;
			#size-cells = <0>;

			mipi1_csi2_output: endpoint@0 {
				reg = <0>;
				remote-endpoint = <&cif_mipi_in1>;
			};
		};
	};
};

&rkcif {
	status = "okay";
	pinctrl-names = "default";
	pinctrl-0 = <&mipi_pins>;
};

&rkcif_mipi_lvds {
	status = "okay";

	port {
		/* MIPI CSI-2 endpoint */
		cif_mipi_in0: endpoint {
			remote-endpoint = <&mipi0_csi2_output>;
		};
	};
};

&rkcif_mipi_lvds_sditf {
	status = "okay";

	port {
		/* MIPI CSI-2 endpoint */
		mipi_lvds0_sditf: endpoint {
			remote-endpoint = <&isp_in0>;
		};
	};
};

&rkcif_mipi_lvds1 {
	status = "okay";

	port {
		/* MIPI CSI-2 endpoint */
		cif_mipi_in1: endpoint {
			remote-endpoint = <&mipi1_csi2_output>;
		};
	};
};

&rkcif_mipi_lvds1_sditf {
	status = "okay";

	port {
		/* MIPI CSI-2 endpoint */
		mipi_lvds1_sditf: endpoint {
			remote-endpoint = <&isp_in1>;
		};
	};
};

&rkisp {
	status = "okay";
};

&rkisp_vir0 {
	status = "okay";

	port@0 {
		isp_in0: endpoint {
			remote-endpoint = <&mipi_lvds0_sditf>;
		};
	};
};

&rkisp_vir1 {
	status = "okay";

	port@0 {
		isp_in1: endpoint {
			remote-endpoint = <&mipi_lvds1_sditf>;
		};
	};
};
