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

/dts-v1/;
/plugin/;

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

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

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

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

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

&main_pmx0 {
	cam1_reset_pins_default: cam1-default-reset-pins {
		pinctrl-single,pins = <
			J722S_IOPAD(0x01d8, PIN_OUTPUT, 7) /* (D22) MCAN0_TX.GPIO1_24 */
		>;
	};
};

&dsi_csi_mux {
	idle-state = <1>;
};

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

	status = "okay";

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

		clocks = <&clk_imx219_csi1>;

		VANA-supply = <&reg_2p8v_csi1>;
		VDIG-supply = <&reg_1p8v_csi1>;
		VDDL-supply = <&reg_1p2v_csi1>;

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

		reset-gpios = <&main_gpio1 24 GPIO_ACTIVE_HIGH>;

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

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

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

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

&ti_csi2rx1 {
	status = "okay";
};

&dphy1 {
	status = "okay";
};