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

/dts-v1/;

#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/leds/common.h>
#include <dt-bindings/pinctrl/rockchip.h>
#include <dt-bindings/pwm/pwm.h>
#include "rk3566.dtsi"

/ {
	model = "OneThing Edge Cube (OEC)/OEC Turbo";
	compatible = "onething,edge-cube", "rockchip,rk3566";

	aliases {
		ethernet0 = &gmac1;
		mmc0 = &sdhci;
	};

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

	gmac1_clkin: external-gmac1-clock {
		compatible = "fixed-clock";
		clock-frequency = <125000000>;
		clock-output-names = "gmac1_clkin";
		#clock-cells = <0>;
	};

	leds {
		compatible = "gpio-leds";

		rgb_led_b: led-0 {
			color = <LED_COLOR_ID_BLUE>;
			default-state = "off";
			function = LED_FUNCTION_STATUS;
			gpios = <&gpio3 RK_PB3 GPIO_ACTIVE_LOW>;
			pinctrl-names = "default";
			pinctrl-0 = <&rgb_led_b_enable_l>;
		};

		rgb_led_g: led-1 {
			color = <LED_COLOR_ID_GREEN>;
			default-state = "on";
			function = LED_FUNCTION_STATUS;
			gpios = <&gpio3 RK_PB4 GPIO_ACTIVE_LOW>;
			pinctrl-names = "default";
			pinctrl-0 = <&rgb_led_g_enable_l>;
		};

		rgb_led_r: led-2 {
			color = <LED_COLOR_ID_RED>;
			default-state = "off";
			function = LED_FUNCTION_STATUS;
			gpios = <&gpio0 RK_PC3 GPIO_ACTIVE_LOW>;
			pinctrl-names = "default";
			pinctrl-0 = <&rgb_led_r_enable_l>;
		};
	};

	vcc_1v8: regulator-vcc-1v8 {
		compatible = "regulator-fixed";
		regulator-name = "vcc_1v8";
		regulator-always-on;
		regulator-boot-on;
		regulator-min-microvolt = <1800000>;
		regulator-max-microvolt = <1800000>;
		vin-supply = <&vcc5v0_sys>;
	};

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

	vcc12v0_dcin: regulator-vcc12v0-dcin {
		compatible = "regulator-fixed";
		regulator-name = "vcc12v0_dcin";
		regulator-always-on;
		regulator-boot-on;
		regulator-min-microvolt = <12000000>;
		regulator-max-microvolt = <12000000>;
	};

	vcc3v3_sys: regulator-vcc3v3-sys {
		compatible = "regulator-fixed";
		regulator-name = "vcc3v3_sys";
		regulator-always-on;
		regulator-boot-on;
		regulator-min-microvolt = <3300000>;
		regulator-max-microvolt = <3300000>;
		vin-supply = <&vcc12v0_dcin>;
	};

	vcc5v0_sys: regulator-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 = <&vcc12v0_dcin>;
	};

	vcc5v0_usb_host: regulator-vcc5v0-usb-host {
		compatible = "regulator-fixed";
		enable-active-high;
		gpios = <&gpio0 RK_PC6 GPIO_ACTIVE_HIGH>;
		pinctrl-names = "default";
		pinctrl-0 = <&vcc5v0_usb_host_en>;
		regulator-name = "vcc5v0_usb_host";
		regulator-min-microvolt = <5000000>;
		regulator-max-microvolt = <5000000>;
		vin-supply = <&vcc5v0_sys>;
	};

	vdd_cpu: regulator-vdd-cpu {
		compatible = "pwm-regulator";
		pwms = <&pwm0 0 5000 PWM_POLARITY_INVERTED>;
		regulator-always-on;
		regulator-boot-on;
		regulator-name = "vdd_cpu";
		regulator-min-microvolt = <800000>;
		regulator-max-microvolt = <1200000>;
		regulator-settling-time-up-us = <250>;
		pwm-supply = <&vcc5v0_sys>;
	};

	vdd_fixed: regulator-vdd-fixed {
		compatible = "regulator-fixed";
		regulator-always-on;
		regulator-boot-on;
		regulator-name = "vdd_fixed";
		regulator-min-microvolt = <950000>;
		regulator-max-microvolt = <950000>;
		vin-supply = <&vcc5v0_sys>;
	};

	vdd_logic: regulator-vdd-logic {
		compatible = "pwm-regulator";
		pwms = <&pwm1 0 5000 PWM_POLARITY_INVERTED>;
		regulator-name = "vdd_logic";
		regulator-always-on;
		regulator-boot-on;
		regulator-min-microvolt = <800000>;
		regulator-max-microvolt = <1100000>;
		regulator-settling-time-up-us = <250>;
		pwm-supply = <&vcc5v0_sys>;
	};
};


/* No hardware video output port */
&display_subsystem {
	status = "disabled";
};

&combphy1 {
	status = "okay";
};

&combphy2 {
	status = "okay";
};

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

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

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

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

&gmac1 {
	assigned-clocks = <&cru SCLK_GMAC1_RX_TX>, <&cru SCLK_GMAC1>;
	assigned-clock-parents = <&cru SCLK_GMAC1_RGMII_SPEED>, <&gmac1_clkin>;
	clock_in_out = "input";
	phy-handle = <&rgmii_phy1>;
	phy-mode = "rgmii-id";
	pinctrl-names = "default";
	pinctrl-0 = <&gmac1m1_miim
		    &gmac1m1_tx_bus2
		    &gmac1m1_rx_bus2
		    &gmac1m1_rgmii_clk
		    &gmac1m1_rgmii_bus
		    &gmac1m1_clkinout>;
	status = "okay";
};

&gpu {
	status = "okay";
};

&mdio1 {
	rgmii_phy1: ethernet-phy@1 {
		compatible = "ethernet-phy-ieee802.3-c22";
		reg = <0x1>;
		reset-assert-us = <20000>;
		reset-deassert-us = <100000>;
		reset-gpios = <&gpio4 RK_PC2 GPIO_ACTIVE_LOW>;
	};
};

&pinctrl {
	gmac {
		eth_phy_reset_pin: eth-phy-reset-pin {
			rockchip,pins = <4 RK_PC2 RK_FUNC_GPIO &pcfg_pull_up>;
		};
	};

	leds {
		rgb_led_b_enable_l: rgb-led-b-enable-l {
			rockchip,pins = <3 RK_PB3 RK_FUNC_GPIO &pcfg_pull_none>;
		};

		rgb_led_g_enable_l: rgb-led-g-enable-l {
			rockchip,pins = <3 RK_PB4 RK_FUNC_GPIO &pcfg_pull_none>;
		};

		rgb_led_r_enable_l: rgb-led-r-enable-l {
			rockchip,pins = <0 RK_PC3 RK_FUNC_GPIO &pcfg_pull_none>;
		};
	};

	usb {
		vcc5v0_usb_host_en: vcc5v0-usb-host-en {
			rockchip,pins = <0 RK_PC6 RK_FUNC_GPIO &pcfg_pull_none>;
		};
	};
};

&pmu_io_domains {
	pmuio1-supply = <&vcc_3v3>;
	pmuio2-supply = <&vcc_3v3>;
	vccio1-supply = <&vcc_1v8>;
	vccio3-supply = <&vcc_3v3>;
	vccio4-supply = <&vcc_1v8>;
	vccio5-supply = <&vcc_3v3>;
	vccio6-supply = <&vcc_1v8>;
	vccio7-supply = <&vcc_3v3>;
	status = "okay";
};

&pwm0 {
	status = "okay";
};

&pwm1 {
	status = "okay";
};

&saradc {
	vref-supply = <&vcc_1v8>;
	status = "okay";
};

&sata2 {
	status = "okay";
};

&sdhci {
	bus-width = <8>;
	cap-mmc-highspeed;
	mmc-hs200-1_8v;
	no-sd;
	no-sdio;
	non-removable;
	pinctrl-names = "default";
	pinctrl-0 = <&emmc_bus8 &emmc_clk &emmc_cmd &emmc_datastrobe>;
	status = "okay";
};

&tsadc {
	rockchip,hw-tshut-mode = <1>;
	rockchip,hw-tshut-polarity = <0>;
	status = "okay";
};

&uart2 {
	status = "okay";
};

&usb_host0_ehci {
	status = "okay";
};

&usb_host0_ohci {
	status = "okay";
};

&usb_host1_ehci {
	status = "okay";
};

&usb_host1_ohci {
	status = "okay";
};

&usb_host1_xhci {
	status = "okay";
};

&usb2phy0 {
	status = "okay";
};

&usb2phy0_host {
	phy-supply = <&vcc5v0_usb_host>;
	status = "okay";
};

&usb2phy0_otg {
	status = "okay";
};

&usb2phy1 {
	status = "okay";
};

&usb2phy1_host {
	phy-supply = <&vcc5v0_usb_host>;
	status = "okay";
};

&usb2phy1_otg {
	phy-supply = <&vcc5v0_usb_host>;
	status = "okay";
};