// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
/*
 * Copyright (c) 2026 Mizuno Miotsuki <founder@crepuse.com>
 */

/dts-v1/;

#include <dt-bindings/input/input.h>
#include "rk3308.dtsi"

/ {
	model = "DFRobot UNIHIKER M10 V1.2";
	compatible = "dfrobot,unihiker-m10-v1.2", "rockchip,rk3308";

	aliases {
		mmc0 = &emmc;
		mmc1 = &sdmmc;
		mmc2 = &sdio;
	};

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

	keys {
		compatible = "gpio-keys";

		key-a {
			debounce-interval = <20>;
			gpios = <&gpio0 RK_PC1 GPIO_ACTIVE_LOW>;
			label = "A";
			linux,code = <KEY_A>;
		};

		key-b {
			debounce-interval = <20>;
			gpios = <&gpio0 RK_PC2 GPIO_ACTIVE_LOW>;
			label = "B";
			linux,code = <KEY_B>;
		};

		key-home {
			debounce-interval = <20>;
			gpios = <&gpio1 RK_PA0 GPIO_ACTIVE_LOW>;
			label = "Home";
			linux,code = <KEY_HOME>;
		};
	};

	sdio_pwrseq: sdio-pwrseq {
		compatible = "mmc-pwrseq-simple";
		pinctrl-names = "default";
		pinctrl-0 = <&wifi_enable_h>;
		reset-gpios = <&gpio0 RK_PA2 GPIO_ACTIVE_LOW>;
	};

	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 = <&vcc_io>;
	};

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

	vcc_sd: regulator-vcc-sd {
		compatible = "regulator-fixed";
		gpios = <&gpio4 RK_PD6 GPIO_ACTIVE_LOW>;
		pinctrl-names = "default";
		pinctrl-0 = <&sd_vcc_en>;
		regulator-name = "vcc_sd";
		regulator-min-microvolt = <3300000>;
		regulator-max-microvolt = <3300000>;
	};

	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>;
	};

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

	vdd_core: regulator-vdd-core {
		compatible = "pwm-regulator";
		pwms = <&pwm0 0 5000 1>;
		regulator-name = "vdd_core";
		regulator-always-on;
		regulator-boot-on;
		regulator-min-microvolt = <827000>;
		regulator-max-microvolt = <1340000>;
		regulator-settling-time-up-us = <250>;
	};
};

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

&emmc {
	cap-mmc-highspeed;
	no-1-8-v;
	non-removable;
	pinctrl-names = "default";
	pinctrl-0 = <&emmc_bus8 &emmc_clk &emmc_cmd>;
	vmmc-supply = <&vcc_io>;
	status = "okay";
};

&io_domains {
	vccio0-supply = <&vcc_io>;
	vccio1-supply = <&vcc_io>;
	vccio2-supply = <&vcc_io>;
	vccio3-supply = <&vcc_io>;
	vccio4-supply = <&vcc_1v8>;
	vccio5-supply = <&vcc_io>;
	status = "okay";
};

&otp {
	status = "disabled";
};

&pinctrl {
	pinctrl-names = "default";
	pinctrl-0 = <&rtc_32k>;

	sdmmc {
		sd_vcc_en: sd-vcc-en {
			rockchip,pins = <4 RK_PD6 RK_FUNC_GPIO &pcfg_pull_none>;
		};
	};

	usb {
		usb_host_vbus_en: usb-host-vbus-en {
			rockchip,pins = <0 RK_PC5 RK_FUNC_GPIO &pcfg_pull_none>;
		};
	};

	wifi {
		wifi_enable_h: wifi-enable-h {
			rockchip,pins = <0 RK_PA2 RK_FUNC_GPIO &pcfg_pull_none>;
		};

		wifi_host_wake: wifi-host-wake {
			rockchip,pins = <0 RK_PA0 RK_FUNC_GPIO &pcfg_pull_down>;
		};
	};
};

&pwm0 {
	pinctrl-names = "default";
	pinctrl-0 = <&pwm0_pin_pull_down>;
	status = "okay";
};

&sdio {
	#address-cells = <1>;
	#size-cells = <0>;
	cap-sd-highspeed;
	cap-sdio-irq;
	keep-power-in-suspend;
	mmc-pwrseq = <&sdio_pwrseq>;
	no-mmc;
	no-sd;
	non-removable;
	vmmc-supply = <&vcc_io>;
	vqmmc-supply = <&vcc_1v8>;
	status = "okay";

	wifi@1 {
		reg = <1>;
		interrupt-parent = <&gpio0>;
		interrupts = <RK_PA0 IRQ_TYPE_LEVEL_HIGH>;
		interrupt-names = "host-wake";
		pinctrl-names = "default";
		pinctrl-0 = <&wifi_host_wake>;
	};
};

&sdmmc {
	cap-sd-highspeed;
	disable-wp;
	no-1-8-v;
	vmmc-supply = <&vcc_sd>;
	vqmmc-supply = <&vcc_io>;
	status = "okay";
};

&u2phy {
	status = "okay";
};

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

&u2phy_otg {
	status = "okay";
};

&uart0 {
	pinctrl-names = "default";
	pinctrl-0 = <&uart0_xfer>;
	status = "okay";
};

&usb20_otg {
	dr_mode = "peripheral";
	status = "okay";
};

&usb_host_ehci {
	status = "okay";
};

&usb_host_ohci {
	status = "okay";
};

&wdt {
	status = "okay";
};