// SPDX-License-Identifier: GPL-2.0-only OR MIT
/*
 * RPi Camera V2.1 on BeagleY AI CSI0 port
 *
 * Copyright (C) 2026 Ideas On Board Oy
 */

/dts-v1/;
/plugin/;

#include <dt-bindings/gpio/gpio.h>
#include "k3-pinctrl.h"

&{/} {
	clk_imx219_csi0: imx219-csi0-xclk {
		compatible = "fixed-clock";
		#clock-cells = <0>;
		clock-frequency = <24000000>;
	};

	reg_2p8v_csi0: regulator-2p8v-csi0 {
		compatible = "regulator-fixed";
		regulator-name = "2P8V_CSI0";
		regulator-min-microvolt = <2800000>;
		regulator-max-microvolt = <2800000>;
		vin-supply = <&vdd_3v3>;
		regulator-always-on;
	};

	reg_1p8v_csi0: regulator-1p8v-csi0 {
		compatible = "regulator-fixed";
		regulator-name = "1P8V_CSI0";
		regulator-min-microvolt = <1800000>;
		regulator-max-microvolt = <1800000>;
		vin-supply = <&vdd_3v3>;
		regulator-always-on;
	};

	reg_1p2v_csi0: regulator-1p2v-csi0 {
		compatible = "regulator-fixed";
		regulator-name = "1P2V_CSI0";
		regulator-min-microvolt = <1200000>;
		regulator-max-microvolt = <1200000>;
		vin-supply = <&vdd_3v3>;
		regulator-always-on;
	};
};

&mcu_pmx0 {
	cam0_reset_pins_default: cam0-default-reset-pins {
		pinctrl-single,pins = <
			J722S_MCU_IOPAD(0x003c, PIN_OUTPUT, 7) /* (C1) MCU_MCAN1_TX.MCU_GPIO0_15 */
		>;
	};
};

&mcu_gpio0 {
	status = "okay";
};

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

	status = "okay";

	imx219_0: sensor@10 {
		compatible = "sony,imx219";
		reg = <0x10>;

		clocks = <&clk_imx219_csi0>;

		VANA-supply = <&reg_2p8v_csi0>;
		VDIG-supply = <&reg_1p8v_csi0>;
		VDDL-supply = <&reg_1p2v_csi0>;

		pinctrl-names = "default";
		pinctrl-0 = <&cam0_reset_pins_default>;

		reset-gpios = <&mcu_gpio0 15 GPIO_ACTIVE_HIGH>;

		port {
			csi2_cam0: endpoint {
				remote-endpoint = <&csi2rx0_in_sensor>;
				link-frequencies = /bits/ 64 <456000000>;
				clock-lanes = <0>;
				data-lanes = <1 2>;
			};
		};
	};
};

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

		csi0_port0: port@0 {
			reg = <0>;
			status = "okay";

			csi2rx0_in_sensor: endpoint {
				remote-endpoint = <&csi2_cam0>;
				bus-type = <4>; /* CSI2 DPHY. */
				clock-lanes = <0>;
				data-lanes = <1 2>;
			};
		};
	};
};

&ti_csi2rx0 {
	status = "okay";
};

&dphy0 {
	status = "okay";
};