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

/dts-v1/;

#include "rk3562.dtsi"
#include "rk3562-evb.dtsi"
#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/pinctrl/rockchip.h>

/ {
	model = "Rockchip RK3562 TEST1 DDR3 V10 Board";
	compatible = "rockchip,rk3562-test1-ddr3-v10", "rockchip,rk3562";

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

	rk809_sound: rk809-sound {
		status = "okay";
		compatible = "rockchip,multicodecs-card";
		rockchip,card-name = "rockchip-rk809";
		hp-det-gpio = <&gpio3 RK_PC6 GPIO_ACTIVE_LOW>;
		rockchip,format = "i2s";
		rockchip,mclk-fs = <256>;
		rockchip,cpu = <&sai2>;
		rockchip,codec = <&rk809_codec>;
		pinctrl-names = "default";
		pinctrl-0 = <&hp_det>;
	};

	sdio_pwrseq: sdio-pwrseq {
		compatible = "mmc-pwrseq-simple";
		clocks = <&rk809 1>;
		clock-names = "ext_clock";
		pinctrl-names = "default";
		pinctrl-0 = <&wifi_enable_h>;

		/*
		 * On the module itself this is one of these (depending
		 * on the actual card populated):
		 * - SDIO_RESET_L_WL_REG_ON
		 * - PDN (power down when low)
		 */
		post-power-on-delay-ms = <200>;
		reset-gpios = <&gpio0 RK_PB3 GPIO_ACTIVE_LOW>;
	};

	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_usb: vcc5v0-usb {
		compatible = "regulator-fixed";
		regulator-name = "vcc5v0_usb";
		regulator-always-on;
		regulator-boot-on;
		regulator-min-microvolt = <5000000>;
		regulator-max-microvolt = <5000000>;
		vin-supply = <&dc_12v>;
	};

	vcc5v0_usb_host: vcc5v0-usb-host {
		compatible = "regulator-fixed";
		regulator-name = "vcc5v0_usb_host";
		regulator-boot-on;
		regulator-always-on;
		regulator-min-microvolt = <5000000>;
		regulator-max-microvolt = <5000000>;
		enable-active-high;
		gpio = <&gpio0 RK_PB7 GPIO_ACTIVE_HIGH>;
		vin-supply = <&vcc5v0_usb>;
		pinctrl-names = "default";
		pinctrl-0 = <&usb_host_pwren>;
	};

	vcc5v0_usb_otg: vcc5v0-usb-otg {
		compatible = "regulator-fixed";
		regulator-name = "vcc5v0_usb_otg";
		regulator-min-microvolt = <5000000>;
		regulator-max-microvolt = <5000000>;
		enable-active-high;
		gpio = <&gpio0 RK_PC0 GPIO_ACTIVE_HIGH>;
		vin-supply = <&vcc5v0_usb>;
		pinctrl-names = "default";
		pinctrl-0 = <&usb_otg_pwren>;
	};

	vcc3v3_clk: vcc3v3-clk {
		compatible = "regulator-fixed";
		regulator-name = "vcc3v3_clk";
		regulator-min-microvolt = <3300000>;
		regulator-max-microvolt = <3300000>;
		vin-supply = <&vcc5v0_sys>;
	};

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

	vcc25_ddr: vcc25-ddr {
		compatible = "regulator-fixed";
		regulator-name = "vcc25_ddr";
		regulator-always-on;
		regulator-boot-on;
		regulator-min-microvolt = <2500000>;
		regulator-max-microvolt = <2500000>;
		vin-supply = <&vcc3v3_sys>;
	};

	vdd_npu: vdd-npu {
		compatible = "pwm-regulator";
		pwms = <&pwm6 0 5000 1>;
		regulator-name = "vdd_npu";
		regulator-min-microvolt = <800000>;
		regulator-max-microvolt = <1100000>;
		regulator-init-microvolt = <900000>;
		regulator-always-on;
		regulator-boot-on;
		regulator-settling-time-up-us = <250>;
		pwm-supply = <&vcc5v0_sys>;
		status = "okay";
	};

	wireless-wlan {
		compatible = "wlan-platdata";
		rockchip,grf = <&sys_grf>;
		wifi_chip_type = "ap6275s";
		pinctrl-names = "default";
		pinctrl-0 = <&wifi_host_wake_irq>;
		WIFI,host_wake_irq = <&gpio0 RK_PB4 GPIO_ACTIVE_HIGH>;
		WIFI,poweren_gpio = <&gpio0 RK_PB3 GPIO_ACTIVE_HIGH>;
		status = "okay";
	};

	wireless-bluetooth {
		compatible = "bluetooth-platdata";
		clocks = <&rk809 1>;
		clock-names = "ext_clock";
		//wifi-bt-power-toggle;
		uart_rts_gpios = <&gpio1 RK_PD2 GPIO_ACTIVE_LOW>;
		pinctrl-names = "default", "rts_gpio";
		pinctrl-0 = <&uart1m0_rtsn>;
		pinctrl-1 = <&uart1_gpios>;
		BT,reset_gpio    = <&gpio0 RK_PC5 GPIO_ACTIVE_HIGH>;
		BT,wake_gpio     = <&gpio0 RK_PC7 GPIO_ACTIVE_HIGH>;
		BT,wake_host_irq = <&gpio0 RK_PC6 GPIO_ACTIVE_HIGH>;
		status = "okay";
	};
};

&combphy_pu {
	status = "okay";
};

&dsi {
	status = "okay";
};

&dsi_in_vp0 {
	status = "okay";
};

&dsi_panel {
	power-supply = <&vcc3v3_lcd_n>;
	reset-gpios = <&gpio0 RK_PC4 GPIO_ACTIVE_LOW>;
	pinctrl-names = "default";
	pinctrl-0 = <&lcd_rst_gpio>;
};

&gmac0 {
	/* Use rgmii-rxid mode to disable rx delay inside Soc */
	phy-mode = "rgmii-rxid";
	clock_in_out = "output";

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

	tx_delay = <0x3f>;
	/* rx_delay = <0x3f>; */

	pinctrl-names = "default";
	pinctrl-0 = <&rgmiim1_miim
		     &rgmiim1_tx_bus2
		     &rgmiim1_rx_bus2
		     &rgmiim1_rgmii_clk
		     &rgmiim1_rgmii_bus
		     &ethm1_pins>;

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

&gt1x {
	compatible = "goodix,gt1x";
	reg = <0x14>;
	pinctrl-names = "default";
	pinctrl-0 = <&touch_gpio>;
	goodix,rst-gpio = <&gpio0 RK_PA0 GPIO_ACTIVE_HIGH>;
	goodix,irq-gpio = <&gpio0 RK_PA4 GPIO_ACTIVE_LOW>;
	/*
	 * power-supply should switche to vcc3v3_lcd1_n
	 * when mipi panel is connected to dsi1.
	 */
	power-supply = <&vcc3v3_lcd_n>;
};

&mdio0 {
	rgmii_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 {
	headphone {
		hp_det: hp-det {
			rockchip,pins = <3 RK_PC6 RK_FUNC_GPIO &pcfg_pull_none>;
		};
	};

	lcd {
		lcd_rst_gpio: lcd-rst-gpio {
			rockchip,pins = <0 RK_PC4 RK_FUNC_GPIO &pcfg_pull_none>;
		};
	};

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

	touch {
		touch_gpio: touch-gpio {
			rockchip,pins =
				<0 RK_PA4 RK_FUNC_GPIO &pcfg_pull_up>,
				<0 RK_PA0 RK_FUNC_GPIO &pcfg_pull_none>;
		};
	};

	usb {
		usb_host_pwren: usb-host-pwren {
			rockchip,pins = <0 RK_PB7 RK_FUNC_GPIO &pcfg_pull_none>;
		};

		usb_otg_pwren: usb-otg-pwren {
			rockchip,pins = <0 RK_PC0 RK_FUNC_GPIO &pcfg_pull_none>;
		};
	};

	wireless-wlan {
		wifi_host_wake_irq: wifi-host-wake-irq {
			rockchip,pins = <0 RK_PB4 RK_FUNC_GPIO &pcfg_pull_down>;
		};
	};

	wireless-bluetooth {
		uart1_gpios: uart1-gpios {
			rockchip,pins = <1 RK_PD2 RK_FUNC_GPIO &pcfg_pull_none>;
		};
	};
};

&route_dsi {
	status = "okay";
};

&sai2 {
	status = "okay";
	pinctrl-names = "default";
	pinctrl-0 = <&i2s2m1_lrck
		     &i2s2m1_sclk
		     &i2s2m1_sdi
		     &i2s2m1_sdo>;
};

&sdmmc0 {
	no-sd;
	no-mmc;
	bus-width = <4>;
	disable-wp;
	cap-sd-highspeed;
	cap-sdio-irq;
	keep-power-in-suspend;
	mmc-pwrseq = <&sdio_pwrseq>;
	non-removable;
	pinctrl-names = "default";
	pinctrl-0 = <&sdmmc0_bus4 &sdmmc0_clk &sdmmc0_cmd>;
	sd-uhs-sdr104;
	status = "okay";
};

&sdmmc1 {
	no-sdio;
	no-mmc;
	bus-width = <4>;
	cap-mmc-highspeed;
	cap-sd-highspeed;
	disable-wp;
	sd-uhs-sdr104;
	vmmc-supply = <&vcc3v3_sd>;
	vqmmc-supply = <&vccio_sd>;
	pinctrl-names = "default";
	pinctrl-0 = <&sdmmc1_bus4 &sdmmc1_clk &sdmmc1_cmd &sdmmc1_det>;
	/* Should disable gmac0 and fix hardware if enabling sdmmc1 */
	status = "disabled";
};

&pwm6 {
	status = "okay";
};

&u2phy {
	status = "okay";
};

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

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

&uart1 {
	status = "okay";
	pinctrl-names = "default";
	pinctrl-0 = <&uart1m0_xfer &uart1m0_ctsn>;
};

&usb_host0_ehci {
	status = "okay";
};

&usb_host0_ohci {
	status = "okay";
};

&usbdrd30 {
	status = "okay";
};

&usbdrd_dwc3 {
	status = "okay";
	dr_mode = "otg";
	extcon = <&u2phy>;
};

&vcc3v3_lcd_n {
	gpio = <&gpio0 RK_PC3 GPIO_ACTIVE_HIGH>;
	enable-active-high;
};

&video_phy {
	status = "okay";
};
