// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
/*
 * Copyright (c) 2026 Yanan He <grumpycat921013@gmail.com>
 */

/dts-v1/;
#include <dt-bindings/input/input.h>
#include "rv1126-alientek-clrv1126f.dtsi"

/ {
	model = "Alientek ATK-DLRV1126";
	compatible = "alientek,dlrv1126", "alientek,clrv1126f", "rockchip,rv1126";

	aliases {
		ethernet0 = &gmac;
		mmc1 = &sdio;
		mmc2 = &sdmmc;
	};

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

	adc-keys {
		compatible = "adc-keys";
		io-channels = <&saradc 0>;
		io-channel-names = "buttons";
		keyup-threshold-microvolt = <1800000>;
		poll-interval = <100>;

		button-esc {
			label = "esc";
			linux,code = <KEY_ESC>;
			press-threshold-microvolt = <0>;
		};

		button-left {
			label = "left";
			linux,code = <KEY_LEFT>;
			press-threshold-microvolt = <801562>;
		};

		button-menu {
			label = "menu";
			linux,code = <KEY_MENU>;
			press-threshold-microvolt = <1198828>;
		};

		button-right {
			label = "right";
			linux,code = <KEY_RIGHT>;
			press-threshold-microvolt = <400781>;
		};
	};

	leds {
		compatible = "gpio-leds";

		led-0 {
			label = "sys-led";
			gpios = <&gpio3 RK_PD4 GPIO_ACTIVE_HIGH>;
			linux,default-trigger = "heartbeat";
			default-state = "on";
		};

		led-1 {
			label = "user-led";
			gpios = <&gpio3 RK_PD6 GPIO_ACTIVE_HIGH>;
			linux,default-trigger = "none";
			default-state = "on";
		};
	};

	sound {
		compatible = "simple-audio-card";
		simple-audio-card,format = "i2s";
		simple-audio-card,name = "Analog RK809";
		simple-audio-card,mclk-fs = <256>;
		simple-audio-card,widgets =
			"Speaker", "Speaker",
			"Headphone", "Headphones",
			"Microphone", "Mic Jack";
		simple-audio-card,routing =
			"Speaker", "SPKO",
			"Headphones", "HPOL",
			"Headphones", "HPOR",
			"MICL", "Mic Jack";

		simple-audio-card,cpu {
			sound-dai = <&i2s0>;
		};

		simple-audio-card,codec {
			sound-dai = <&rk809>;
		};
	};

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

	sdio_pwrseq: pwrseq-sdio {
		compatible = "mmc-pwrseq-simple";
		pinctrl-names = "default";
		pinctrl-0 = <&wifi_enable_h>;
		reset-gpios = <&gpio0 RK_PA6 GPIO_ACTIVE_LOW>;
		post-power-on-delay-ms = <200>;
		power-off-delay-us = <20000>;
	};
};

&gmac {
	assigned-clocks = <&cru CLK_GMAC_SRC>, <&cru CLK_GMAC_TX_RX>,
			  <&cru CLK_GMAC_ETHERNET_OUT>;
	assigned-clock-parents = <&cru CLK_GMAC_SRC_M1>,
				 <&cru RGMII_MODE_CLK>;
	assigned-clock-rates = <125000000>, <0>, <25000000>;
	clock_in_out = "input";
	phy-handle = <&phy>;
	phy-mode = "rgmii-id";
	pinctrl-names = "default";
	pinctrl-0 = <&rgmiim1_miim &rgmiim1_bus2 &rgmiim1_bus4
		     &clk_out_ethernetm1_pins>;
	status = "okay";
};

&i2c5 {
	status = "okay";
	clock-frequency = <400000>;

	pcf8563: rtc@51 {
		compatible = "nxp,pcf8563";
		reg = <0x51>;
		#clock-cells = <0>;
		clock-output-names = "xin32k";
		interrupt-parent = <&gpio1>;
		interrupts = <RK_PD0 IRQ_TYPE_LEVEL_LOW>;
	};
};

&i2s0 {
	pinctrl-names = "default";
	pinctrl-0 = <&i2s0m0_sclk_tx>,
		    <&i2s0m0_mclk>,
		    <&i2s0m0_lrck_tx>,
		    <&i2s0m0_sdo0>,
		    <&i2s0m0_sdo1_sdi3>;
	rockchip,trcm-sync-tx-only;
	rockchip,i2s-rx-route = <3 1 2 0>;
	rockchip,i2s-tx-route = <0 1 2 3>;
	status = "okay";
};

&mdio {
	phy: ethernet-phy@1 {
		compatible = "ethernet-phy-ieee802.3-c22";
		reg = <0x1>;
		clocks = <&cru CLK_GMAC_ETHERNET_OUT>;
		pinctrl-names = "default";
		pinctrl-0 = <&eth_phy_rst>;
		reset-gpios = <&gpio3 RK_PA0 GPIO_ACTIVE_LOW>;
		reset-assert-us = <20000>;
		reset-deassert-us = <100000>;
	};
};

&pinctrl {
	bt {
		bt_enable: bt-enable {
			rockchip,pins = <0 RK_PA7 RK_FUNC_GPIO &pcfg_pull_none>;
		};

		bt_wake_dev: bt-wake-dev {
			rockchip,pins = <1 RK_PD1 RK_FUNC_GPIO &pcfg_pull_none>;
		};

		bt_wake_host: bt-wake-host {
			rockchip,pins = <0 RK_PA5 RK_FUNC_GPIO &pcfg_pull_none>;
		};
	};

	ethernet {
		eth_phy_rst: eth-phy-rst {
			rockchip,pins = <3 RK_PA0 RK_FUNC_GPIO &pcfg_pull_down>;
		};
	};

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

&sdio {
	bus-width = <4>;
	cap-sdio-irq;
	keep-power-in-suspend;
	max-frequency = <25000000>;
	mmc-pwrseq = <&sdio_pwrseq>;
	non-removable;
	pinctrl-names = "default";
	pinctrl-0 = <&sdmmc1_clk &sdmmc1_cmd &sdmmc1_bus4>;
	rockchip,default-sample-phase = <90>;
	vmmc-supply = <&vcc3v3_sd>;
	vqmmc-supply = <&vcc_1v8>;
	status = "okay";
};

&sdmmc {
	bus-width = <4>;
	cap-mmc-highspeed;
	cap-sd-highspeed;
	card-detect-delay = <200>;
	pinctrl-names = "default";
	pinctrl-0 = <&sdmmc0_clk &sdmmc0_cmd &sdmmc0_bus4 &sdmmc0_det>;
	rockchip,default-sample-phase = <90>;
	sd-uhs-sdr12;
	sd-uhs-sdr25;
	sd-uhs-sdr104;
	vmmc-supply = <&vcc3v3_sd>;
	vqmmc-supply = <&vccio_sd>;
	status = "okay";
};

&uart0 {
	pinctrl-names = "default";
	pinctrl-0 = <&uart0_xfer &uart0_ctsn &uart0_rtsn>;
	uart-has-rtscts;
	status = "okay";

	bluetooth {
		compatible = "brcm,bcm43430a1-bt";
		clocks = <&rk809 1>;
		clock-names = "lpo";
		device-wakeup-gpios = <&gpio1 RK_PD1 GPIO_ACTIVE_HIGH>;
		interrupt-parent = <&gpio0>;
		interrupts = <RK_PA5 IRQ_TYPE_EDGE_RISING>;
		interrupt-names = "host-wakeup";
		max-speed = <115200>;
		pinctrl-names = "default";
		pinctrl-0 = <&bt_enable>, <&bt_wake_dev>, <&bt_wake_host>;
		shutdown-gpios = <&gpio0 RK_PA7 GPIO_ACTIVE_HIGH>;
		vbat-supply = <&vcc_3v3>;
		vddio-supply = <&vcc_1v8>;
	};
};

&uart2 {
	status = "okay";
};