// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
/*
 * Copyright (c) 2025 Radxa Computer (Shenzhen) Co., Ltd.
 */

/dts-v1/;

#include <dt-bindings/leds/common.h>
#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/pinctrl/rockchip.h>
#include "rk3568-radxa-cm3j.dtsi"

/ {
	model = "Radxa CM3J on RPi CM4 IO Board";
	compatible = "radxa,cm3j-rpi-cm4", "radxa,cm3j", "rockchip,rk3568";

	aliases {
		ethernet0 = &gmac1;
		mmc1 = &sdmmc0;
		rtc0 = &pcf85063;
	};

	chosen {
		stdout-path = "serial2:1500000n8";
	};

	hdmi-con {
		compatible = "hdmi-connector";
		type = "a";

		port {
			hdmi_con_in: endpoint {
				remote-endpoint = <&hdmi_out_con>;
			};
		};
	};

	leds-1 {
		compatible = "gpio-leds";

		led-1 {
			color = <LED_COLOR_ID_RED>;
			default-state = "on";
			function = LED_FUNCTION_POWER;
			gpios = <&gpio3 RK_PC4 GPIO_ACTIVE_LOW>;
			pinctrl-names = "default";
			pinctrl-0 = <&npwr_led>;
		};

		led-2 {
			color = <LED_COLOR_ID_GREEN>;
			default-state = "on";
			function = LED_FUNCTION_STATUS;
			gpios = <&gpio4 RK_PC6 GPIO_ACTIVE_LOW>;
			linux,default-trigger = "heartbeat";
			pinctrl-names = "default";
			pinctrl-0 = <&pi_nled_activity>;
		};
	};

	dc12v: regulator-12v0 {
		compatible = "regulator-fixed";
		regulator-name = "dc12v";
		regulator-always-on;
		regulator-boot-on;
		regulator-min-microvolt = <12000000>;
		regulator-max-microvolt = <12000000>;
	};

	dc3v3_pcie: regulator-3v3-2 {
		compatible = "regulator-fixed";
		regulator-name = "dc3v3_pcie";
		regulator-always-on;
		regulator-boot-on;
		regulator-min-microvolt = <3300000>;
		regulator-max-microvolt = <3300000>;
		vin-supply = <&dc12v>;
	};

	gpio_vref: regulator-3v3-3 {
		compatible = "regulator-fixed";
		regulator-name = "gpio_vref";
		regulator-always-on;
		regulator-boot-on;
		regulator-min-microvolt = <3300000>;
		regulator-max-microvolt = <3300000>;
		vin-supply = <&dc3v3>;
	};

	dc5v: regulator-5v0 {
		compatible = "regulator-fixed";
		regulator-name = "dc5v";
		regulator-always-on;
		regulator-boot-on;
		regulator-min-microvolt = <5000000>;
		regulator-max-microvolt = <5000000>;
		vin-supply = <&dc12v>;
	};
};

&combphy0 {
	status = "okay";
};

&combphy2 {
	status = "okay";
};

&gmac1 {
	status = "okay";
};

&gpio0 {
	nextrst-hog {
		gpio-hog;
		/*
		 * GPIO_ACTIVE_LOW + output-low here means that the pin is set
		 * to high, because output-low decides the value pre-inversion.
		 */
		gpios = <RK_PC0 GPIO_ACTIVE_LOW>;
		line-name = "nEXTRST";
		output-low;
	};
};

&hdmi {
	status = "okay";
};

&hdmi_sound {
	status = "okay";
};

&i2c0 {
	emc2301: fan-controller@2f {
		compatible = "microchip,emc2301", "microchip,emc2305";
		reg = <0x2f>;
		#address-cells = <1>;
		#size-cells = <0>;
		#pwm-cells = <3>;

		fan@0 {
			reg = <0x0>;
			pwms = <&emc2301 26000 0 1>;
			#cooling-cells = <2>;
		};
	};

	pcf85063: rtc@51 {
		compatible = "nxp,pcf85063a";
		reg = <0x51>;
		wakeup-source;
	};
};

&i2s0_8ch {
	status = "okay";
};

&pinctrl {
	leds {
		npwr_led: npwr-led {
			rockchip,pins = <3 RK_PC4 RK_FUNC_GPIO &pcfg_pull_none>;
		};

		pi_nled_activity: pi-nled-activity {
			rockchip,pins = <4 RK_PC6 RK_FUNC_GPIO &pcfg_pull_none>;
		};
	};
};

&pcie2x1 {
	vpcie3v3-supply = <&dc3v3_pcie>;
	status = "okay";
};

&sdmmc0 {
	bus-width = <4>;
	cap-sd-highspeed;
	broken-cd;
	disable-wp;
	no-mmc;
	no-sdio;
	pinctrl-names = "default";
	pinctrl-0 = <&sdmmc0_bus4 &sdmmc0_clk &sdmmc0_cmd>;
	vmmc-supply = <&dc3v3>;
	status = "okay";
};

&uart2 {
	status = "okay";
};

&usb2phy0 {
	status = "okay";
};

&usb2phy0_otg {
	status = "okay";
};

&usb_host0_xhci {
	status = "okay";
};