// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
/*
 * Copyright (c) 2023 Rockchip Electronics Co., Ltd.
 *
 */

/dts-v1/;

#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/pinctrl/rockchip.h>
#include "rk3562j-electric.dtsi"

/ {
	model = "Rockchip RK3562J CORE DDR4 V10 Board";
	compatible = "rockchip,rk3562j-core-ddr4-v10", "rockchip,rk3562";

	chosen: chosen {
		bootargs = "earlycon=uart8250,mmio32,0xff210000 console=ttyFIQ0 root=PARTUUID=614e0000-0000 rw rootwait";
	};

	fiq-debugger {
		compatible = "rockchip,fiq-debugger";
		rockchip,serial-id = <0>;
		rockchip,wake-irq = <0>;
		/* If enable uart uses irq instead of fiq */
		rockchip,irq-mode-enable = <1>;
		rockchip,baudrate = <1500000>;  /* Only 115200 and 1500000 */
		interrupts = <GIC_SPI 242 IRQ_TYPE_LEVEL_HIGH>;
		pinctrl-names = "default";
		pinctrl-0 = <&uart0m0_xfer>;
		status = "okay";
	};

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

	vcc5v0_sys: vcc5v0-sys {
		compatible = "regulator-fixed";
		regulator-name = "vcc5v0_sys";
		regulator-always-on;
		regulator-boot-on;
		regulator-min-microvolt = <5000000>;
		regulator-max-microvolt = <5000000>;
		vin-supply = <&dc_12v>;
	};

	vcc5v0_host: vcc5v0-host-regulator {
		compatible = "regulator-fixed";
		regulator-name = "vcc5v0_host";
		regulator-boot-on;
		regulator-always-on;
		regulator-min-microvolt = <5000000>;
		regulator-max-microvolt = <5000000>;
		enable-active-high;
		gpio = <&gpio3 RK_PB7 GPIO_ACTIVE_HIGH>;
		vin-supply = <&vcc5v0_sys>;
		pinctrl-names = "default";
		pinctrl-0 = <&vcc5v0_host_en>;
	};

	vcc5v0_otg: vcc5v0-otg-regulator {
		compatible = "regulator-fixed";
		regulator-name = "vcc5v0_otg";
		regulator-min-microvolt = <5000000>;
		regulator-max-microvolt = <5000000>;
		enable-active-high;
		gpio = <&expander0 11 GPIO_ACTIVE_HIGH>;
		vin-supply = <&vcc5v0_sys>;
	};
};

&combphy_pu {
	status = "disabled";
};

&cpu0 {
	cpu-supply = <&vdd_cpu>;
};

&gmac0 {
	phy-mode = "rmii";
	clock_in_out = "input";

	snps,reset-gpio = <&gpio4 RK_PA0 GPIO_ACTIVE_LOW>;
	snps,reset-active-low;
	/* Reset time is 20ms, 100ms for rtl8211f */
	snps,reset-delays-us = <0 20000 100000>;

	pinctrl-names = "default";
	pinctrl-0 = <&rgmiim0_miim
		     &rgmiim0_tx_bus2
		     &rgmiim0_rx_bus2
		     &rgmiim0_clk>;

	phy-handle = <&rmii_phy>;
	status = "okay";
};

&i2c0 {
	status = "okay";

	expander0: pca953x@26 {
		vcc-supply = <&vcc_3v3>;
		compatible = "nxp,pca9555";
		reg = <0x26>;
		gpio-controller;
		#gpio-cells = <2>;
		status = "okay";
	};

	rk809: pmic@20 {
		compatible = "rockchip,rk809";
		reg = <0x20>;
		interrupt-parent = <&gpio0>;
		interrupts = <3 IRQ_TYPE_LEVEL_LOW>;

		pinctrl-names = "default", "pmic-sleep",
				"pmic-power-off", "pmic-reset";
		pinctrl-0 = <&pmic_int>;
		pinctrl-1 = <&soc_slppin_slp>, <&rk817_slppin_slp>;
		pinctrl-2 = <&soc_slppin_gpio>, <&rk817_slppin_pwrdn>;
		pinctrl-3 = <&soc_slppin_gpio>, <&rk817_slppin_rst>;
		rockchip,system-power-controller;
		wakeup-source;
		#clock-cells = <1>;
		clock-output-names = "rk808-clkout1", "rk808-clkout2";
		/* 1: rst regs (default in codes), 0: rst the pmic */
		pmic-reset-func = <0>;
		/* not save the PMIC_POWER_EN register in uboot */
		not-save-power-en = <1>;

		vcc1-supply = <&vcc5v0_sys>;
		vcc2-supply = <&vcc5v0_sys>;
		vcc3-supply = <&vcc5v0_sys>;
		vcc4-supply = <&vcc5v0_sys>;
		vcc5-supply = <&vcc3v3_sys>;
		vcc6-supply = <&vcc3v3_sys>;
		vcc7-supply = <&vcc3v3_sys>;
		vcc8-supply = <&vcc3v3_sys>;
		vcc9-supply = <&vcc5v0_sys>;

		pwrkey {
			status = "okay";
		};

		pinctrl_rk8xx: pinctrl_rk8xx {
			gpio-controller;
			#gpio-cells = <2>;

			rk817_slppin_null: rk817_slppin_null {
				pins = "gpio_slp";
				function = "pin_fun0";
			};

			rk817_slppin_slp: rk817_slppin_slp {
				pins = "gpio_slp";
				function = "pin_fun1";
			};

			rk817_slppin_pwrdn: rk817_slppin_pwrdn {
				pins = "gpio_slp";
				function = "pin_fun2";
			};

			rk817_slppin_rst: rk817_slppin_rst {
				pins = "gpio_slp";
				function = "pin_fun3";
			};
		};

		regulators {
			vdd_logic: DCDC_REG1 {
				regulator-always-on;
				regulator-boot-on;
				regulator-min-microvolt = <500000>;
				regulator-max-microvolt = <1350000>;
				regulator-init-microvolt = <900000>;
				regulator-ramp-delay = <6001>;
				regulator-initial-mode = <0x2>;
				regulator-name = "vdd_logic";
				regulator-state-mem {
					regulator-off-in-suspend;
				};
			};

			vdd_cpu: DCDC_REG2 {
				regulator-always-on;
				regulator-boot-on;
				regulator-min-microvolt = <500000>;
				regulator-max-microvolt = <1350000>;
				regulator-init-microvolt = <900000>;
				regulator-ramp-delay = <6001>;
				regulator-initial-mode = <0x2>;
				regulator-name = "vdd_cpu";
				regulator-state-mem {
					regulator-off-in-suspend;
				};
			};

			vcc_ddr: DCDC_REG3 {
				regulator-always-on;
				regulator-boot-on;
				regulator-initial-mode = <0x2>;
				regulator-name = "vcc_ddr";
				regulator-state-mem {
					regulator-on-in-suspend;
				};
			};

			vdd_buck4: DCDC_REG4 {
				regulator-ramp-delay = <6001>;
				regulator-initial-mode = <0x2>;
				regulator-name = "vdd_buck4";
				regulator-state-mem {
					regulator-off-in-suspend;
				};
			};

			vdda_0v9: LDO_REG1 {
				regulator-boot-on;
				regulator-always-on;
				regulator-min-microvolt = <900000>;
				regulator-max-microvolt = <900000>;
				regulator-name = "vdda_0v9";
				regulator-state-mem {
					regulator-off-in-suspend;
				};
			};

			vcca_1v8: LDO_REG2 {
				regulator-always-on;
				regulator-boot-on;
				regulator-min-microvolt = <1800000>;
				regulator-max-microvolt = <1800000>;
				regulator-name = "vcca_1v8";
				regulator-state-mem {
					regulator-off-in-suspend;
				};
			};

			vcc_ldo3: LDO_REG3 {
				regulator-name = "vcc_ldo3";
				regulator-state-mem {
					regulator-off-in-suspend;
				};
			};

			vcc_1v8: LDO_REG4 {
				regulator-always-on;
				regulator-boot-on;
				regulator-min-microvolt = <1800000>;
				regulator-max-microvolt = <1800000>;
				regulator-name = "vcc_1v8";
				regulator-state-mem {
					regulator-off-in-suspend;
				};
			};

			vcc_ldo5: LDO_REG5 {
				regulator-name = "vcc_ldo5";
				regulator-state-mem {
					regulator-off-in-suspend;
				};
			};

			vcc_ldo6: LDO_REG6 {
				regulator-name = "vcc_ldo6";
				regulator-state-mem {
					regulator-off-in-suspend;
				};
			};

			vcc_ldo7: LDO_REG7 {
				regulator-name = "vcc_ldo7";
				regulator-state-mem {
					regulator-off-in-suspend;
				};
			};

			vcc_ldo8: LDO_REG8 {
				regulator-name = "vcc_ldo8";
				regulator-state-mem {
					regulator-off-in-suspend;
				};
			};

			vcc_ldo9: LDO_REG9 {
				regulator-name = "vcc_ldo9";
				regulator-state-mem {
					regulator-off-in-suspend;
				};
			};

			vcc3v3_sys: DCDC_REG5 {
				regulator-always-on;
				regulator-boot-on;
				regulator-min-microvolt = <3300000>;
				regulator-max-microvolt = <3300000>;
				regulator-name = "vcc3v3_sys";
				regulator-state-mem {
					regulator-off-in-suspend;
				};
			};

			vcc_sw1: SWITCH_REG1 {
				regulator-name = "vcc_sw1";
				regulator-state-mem {
					regulator-off-in-suspend;
				};
			};

			vcc_3v3: SWITCH_REG2 {
				regulator-always-on;
				regulator-boot-on;
				regulator-name = "vcc_3v3";
				regulator-state-mem {
					regulator-off-in-suspend;
				};
			};
		};
	};
};

&i2c1 {
	status = "okay";
	pinctrl-0 = <&i2c1m0_xfer>;
};

&i2c2 {
	status = "okay";
	pinctrl-0 = <&i2c2m0_xfer>;
};

&i2c4 {
	status = "okay";
	pinctrl-0 = <&i2c4m1_xfer>;
};

&mdio0 {
	rmii_phy: phy@1 {
		compatible = "ethernet-phy-ieee802.3-c22";
		reg = <0x1>;
		clocks = <&cru CLK_GMAC_ETH_OUT2IO>;
		assigned-clocks = <&cru CLK_GMAC_ETH_OUT2IO>;
		assigned-clock-rates = <25000000>;
	};
};

&pinctrl {
	usb {
		vcc5v0_host_en: vcc5v0-host-en {
			rockchip,pins = <3 RK_PB7 RK_FUNC_GPIO &pcfg_pull_none>;
		};
	};
};

&pwm0 {
	status = "okay";
	pinctrl-0 = <&pwm0m1_pins>;
};

&pwm3 {
	status = "okay";
	pinctrl-0 = <&pwm3m0_pins>;
};

&pwm4 {
	status = "okay";
	pinctrl-0 = <&pwm4m0_pins>;
};

&pwm7 {
	status = "okay";
	pinctrl-0 = <&pwm7m0_pins>;
};

&pwm8 {
	status = "okay";
	pinctrl-0 = <&pwm8m0_pins>;
};

&pwm9 {
	status = "okay";
	pinctrl-0 = <&pwm9m0_pins>;
};

&rng {
	status = "okay";
};

&saradc0 {
	status = "okay";
	vref-supply = <&vcca_1v8>;
};

&sdhci {
	status = "okay";
};

&spi1 {
	status = "okay";
	pinctrl-0 = <&spi1m1_csn0 &spi1m1_pins>;
};

&spi2 {
	status = "okay";
	pinctrl-0 = <&spi2m1_csn0 &spi2m1_pins>;
};

&tsadc {
	status = "okay";
};

&u2phy {
	status = "okay";
};

&u2phy_host {
	phy-supply = <&vcc5v0_host>;
	status = "okay";
};

&u2phy_otg {
	vbus-supply = <&vcc5v0_otg>;
	status = "okay";
};

&uart2 {
	status = "okay";
	pinctrl-0 = <&uart2m1_xfer &uart2m1_ctsn &uart2m1_rtsn>;
};

&uart4 {
	status = "okay";
	pinctrl-0 = <&uart4m0_xfer &uart4m0_ctsn &uart4m0_rtsn>;
};

&uart5 {
	status = "okay";
	pinctrl-0 = <&uart5m1_xfer>;
};

&uart6 {
	status = "okay";
	pinctrl-0 = <&uart6m0_xfer>;
};

&uart7 {
	status = "okay";
	pinctrl-0 = <&uart7m0_xfer>;
};

&uart8 {
	status = "okay";
	pinctrl-0 = <&uart8m0_xfer>;
};

&uart9 {
	status = "okay";
	pinctrl-0 = <&uart9m1_xfer>;
};

&usb_host0_ehci {
	status = "okay";
};

&usb_host0_ohci {
	status = "okay";
};

&usbdrd30 {
	status = "okay";
};

&usbdrd_dwc3 {
	status = "okay";
	dr_mode = "otg";
	extcon = <&u2phy>;
	maximum-speed = "high-speed";
	phys = <&u2phy_otg>;
	phy-names = "usb2-phy";
	snps,dis_u2_susphy_quirk;
	snps,usb2-lpm-disable;
};
