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

#include "rk322x.dtsi"
#include "rk3229-cpu-opp.dtsi"
#include "rk322x-android.dtsi"
#include <dt-bindings/input/input.h>

/ {
	gpio_keys {
		compatible = "gpio-keys";
		#address-cells = <1>;
		#size-cells = <0>;
		autorepeat;

		pinctrl-names = "default";
		pinctrl-0 = <&pwr_key>;

		power_key: power-key {
			label = "GPIO Key Power";
			gpios = <&gpio3 23 GPIO_ACTIVE_LOW>;
			linux,code = <KEY_POWER>;
			debounce-interval = <100>;
			wakeup-source;
		};
	};

	sound {
		compatible = "simple-audio-card";
		simple-audio-card,format = "i2s";
		simple-audio-card,mclk-fs = <256>;
		simple-audio-card,name = "rockchip,rk3229";
		simple-audio-card,cpu {
			sound-dai = <&i2s1>;
		};
		simple-audio-card,codec {
			sound-dai = <&codec>;
		};
	};

	hdmi_sound: hdmi-sound {
		status = "okay";
		compatible = "simple-audio-card";
		simple-audio-card,format = "i2s";
		simple-audio-card,mclk-fs = <128>;
		simple-audio-card,name = "rockchip,hdmi";
		simple-audio-card,cpu {
			sound-dai = <&i2s0>;
		};
		simple-audio-card,codec {
			sound-dai = <&hdmi>;
		};
	};

	regulators {
		compatible = "simple-bus";
		#address-cells = <1>;
		#size-cells = <0>;

		vccio_1v8_reg: regulator@0 {
			compatible = "regulator-fixed";
			regulator-name = "vccio_1v8";
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1800000>;
			regulator-always-on;
		};

		vccio_3v3_reg: regulator@1 {
			compatible = "regulator-fixed";
			regulator-name = "vccio_3v3";
			regulator-min-microvolt = <3300000>;
			regulator-max-microvolt = <3300000>;
			regulator-always-on;
		};
	};

	sdio_pwrseq: sdio-pwrseq {
		compatible = "mmc-pwrseq-simple";
		clocks = <&hym8563>;
		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)
		 */
		reset-gpios = <&gpio2 26 GPIO_ACTIVE_LOW>; /* GPIO2_D2 */
	};

	spdif_out: spdif-out {
		status = "okay";
		compatible = "linux,spdif-dit";
		#sound-dai-cells = <0>;
	};

	spdif-sound {
		status = "okay";
		compatible = "simple-audio-card";
		simple-audio-card,name = "ROCKCHIP,SPDIF";
		simple-audio-card,mclk-fs = <128>;
		simple-audio-card,cpu {
			sound-dai = <&spdif>;
		};
		simple-audio-card,codec {
			sound-dai = <&spdif_out>;
		};
	};

	vcc_host: vcc-host-regulator {
		compatible = "regulator-fixed";
		enable-active-high;
		gpio = <&gpio3 20 GPIO_ACTIVE_HIGH>;
		pinctrl-names = "default";
		pinctrl-0 = <&host_vbus_drv>;
		regulator-name = "vcc_host";
		regulator-always-on;
		regulator-boot-on;
	};

	vcc_otg_vbus: otg-vbus-regulator {
		compatible = "regulator-fixed";
		gpio = <&gpio3 RK_PC6 GPIO_ACTIVE_HIGH>;
		pinctrl-names = "default";
		pinctrl-0 = <&otg_vbus_drv>;
		regulator-name = "vcc_otg_vbus";
		regulator-min-microvolt = <5000000>;
		regulator-max-microvolt = <5000000>;
		enable-active-high;
	};

	vcc_phy: vcc-phy-regulator {
		compatible = "regulator-fixed";
		enable-active-high;
		regulator-name = "vcc_phy";
		regulator-min-microvolt = <1800000>;
		regulator-max-microvolt = <1800000>;
		regulator-always-on;
		regulator-boot-on;
	};

	vdd_arm: vdd-arm-regulator {
		compatible = "pwm-regulator";
		rockchip,pwm_id = <1>;
		rockchip,pwm_voltage = <1100000>;
		pwms = <&pwm1 0 5000 1>;
		regulator-name = "vdd_arm";
		regulator-min-microvolt = <950000>;
		regulator-max-microvolt = <1400000>;
		regulator-settling-time-up-us = <250>;
		regulator-always-on;
		regulator-boot-on;
	};

	vdd_log: vdd-log-regulator {
		compatible = "pwm-regulator";
		rockchip,pwm_id = <2>;
		rockchip,pwm_voltage = <1200000>;
		pwms = <&pwm2 0 5000 1>;
		regulator-name = "vdd_log";
		regulator-min-microvolt = <1000000>;
		regulator-max-microvolt = <1300000>;
		regulator-settling-time-up-us = <250>;
		regulator-always-on;
		regulator-boot-on;
	};

	wireless-bluetooth {
		compatible = "bluetooth-platdata";
		clocks = <&hym8563>;
		clock-names = "ext_clock";
		uart_rts_gpios = <&gpio3 6 GPIO_ACTIVE_LOW>;
		pinctrl-names = "default", "rts_gpio";
		pinctrl-0 = <&uart11_rts>;
		pinctrl-1 = <&uart11_rts_gpio>;
		BT,power_gpio = <&gpio2 29 GPIO_ACTIVE_HIGH>;
		BT,wake_host_irq = <&gpio3 26 GPIO_ACTIVE_HIGH>;
		status = "okay";
	};

	wireless-wlan {
		compatible = "wlan-platdata";
		rockchip,grf = <&grf>;
		wifi_chip_type = "ap6335";
		sdio_vref = <1800>;
		WIFI,host_wake_irq = <&gpio0 28 GPIO_ACTIVE_HIGH>;
		status = "okay";
	};
};

&codec {
	#sound-dai-cells = <0>;
	status = "okay";
};

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

&display_subsystem {
	logo-memory-region = <&drm_logo>;
	status = "okay";
	secure-memory-region = <&secure_memory>;
	route {
		route_hdmi: route-hdmi {
			status = "okay";
			logo,uboot = "logo.bmp";
			logo,kernel = "logo_kernel.bmp";
			logo,mode = "center";
			charge_logo,mode = "center";
			connect = <&vop_out_hdmi>;
		};

		route_tve: route-tve {
			status = "okay";
			logo,uboot = "logo.bmp";
			logo,kernel = "logo_kernel.bmp";
			logo,mode = "center";
			charge_logo,mode = "center";
			connect = <&vop_out_tve>;
		};
	};
};

&dmc {
	center-supply = <&vdd_log>;
	status = "okay";
};

&gmac {
	assigned-clocks = <&cru SCLK_MAC_SRC>;
	assigned-clock-rates = <50000000>;
	clock_in_out = "output";
	phy-supply = <&vcc_phy>;
	phy-mode = "rmii";
	phy-handle = <&phy>;
	status = "okay";

	mdio {
		compatible = "snps,dwmac-mdio";
		#address-cells = <1>;
		#size-cells = <0>;

		phy: phy@0 {
			compatible = "ethernet-phy-id1234.d400", "ethernet-phy-ieee802.3-c22";
			reg = <0>;
			clocks = <&cru SCLK_MAC_PHY>;
			resets = <&cru SRST_MACPHY>;
			phy-is-integrated;
		};
	};
};

&gpu {
	status = "okay";
	mali-supply = <&vdd_log>;
};

&hdmi {
	status = "okay";
	#sound-dai-cells = <0>;
	ddc-i2c-scl-high-time-ns = <9625>;
	ddc-i2c-scl-low-time-ns = <10000>;
};

&io_domains {
	status = "okay";

	vccio1-supply = <&vccio_3v3_reg>;
	vccio2-supply = <&vccio_1v8_reg>;
	vccio4-supply = <&vccio_3v3_reg>;
};

&secure_memory {
	/*
	 * enable like this:
	 * reg = <0x80000000 0x10000000>;
	 */
	reg = <0x80000000 0x0>;
};

&i2c0 {
	status = "okay";

	hym8563: hym8563@51 {
		compatible = "haoyu,hym8563";
		reg = <0x51>;
		#clock-cells = <0>;
		clock-frequency = <32768>;
		clock-output-names = "xin32k";
	};
};

&i2s0 {
	status = "okay";
	rockchip,bclk-fs = <128>;
	#sound-dai-cells = <0>;
};

&i2s1 {
	#sound-dai-cells = <0>;
	status = "okay";
};

&iep {
	status = "okay";
};

&iep_mmu {
	status = "okay";
};

&mpp_srv {
	status = "okay";
};

&nandc {
	status = "okay";
};

&pinctrl {
	keys {
		pwr_key: pwr-key {
			rockchip,pins = <3 RK_PC7 RK_FUNC_GPIO &pcfg_pull_up>;
		};
	};

	sdmmc {
		sdmmc_pwr: sdmmc-pwr {
			rockchip,pins = <1 RK_PB6 RK_FUNC_GPIO &pcfg_pull_none>;
		};
	};

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

	usb {
		host_vbus_drv: host-vbus-drv {
			rockchip,pins = <3 RK_PC4 RK_FUNC_GPIO &pcfg_pull_none>;
		};

		otg_vbus_drv: otg-vbus-drv {
			rockchip,pins = <3 RK_PC6 RK_FUNC_GPIO &pcfg_pull_none>;
		};
	};
};

&pwm1 {
	status = "okay";
	pinctrl-names = "active";
	pinctrl-0 = <&pwm1_pin_pull_down>;
};

&pwm2 {
	status = "okay";
	pinctrl-names = "active";
	pinctrl-0 = <&pwm2_pin_pull_up>;
};

&pwm3 {
	status = "okay";
	pinctrl-names = "default";
	pinctrl-0 = <&pwm3_pin>;
	compatible = "rockchip,remotectl-pwm";
	remote_pwm_id = <3>;
	handle_cpu_id = <1>;
	remote_support_psci = <1>;

	ir_key1 {
		rockchip,usercode = <0x4040>;
		rockchip,key_table =
			<0xf2	KEY_REPLY>,
			<0xba	KEY_BACK>,
			<0xf4	KEY_UP>,
			<0xf1	KEY_DOWN>,
			<0xef	KEY_LEFT>,
			<0xee	KEY_RIGHT>,
			<0xbd	KEY_HOME>,
			<0xea	KEY_VOLUMEUP>,
			<0xe3	KEY_VOLUMEDOWN>,
			<0xe2	KEY_SEARCH>,
			<0xb2	KEY_POWER>,
			<0xbc	KEY_MUTE>,
			<0xec	KEY_MENU>,
			<0xbf	0x190>,
			<0xe0	0x191>,
			<0xe1	0x192>,
			<0xe9	183>,
			<0xe6	248>,
			<0xe8	185>,
			<0xe7	186>,
			<0xf0	388>,
			<0xbe	0x175>;
	};

	ir_key2 {
		rockchip,usercode = <0xff00>;
		rockchip,key_table =
			<0xf9	KEY_HOME>,
			<0xbf	KEY_BACK>,
			<0xfb	KEY_MENU>,
			<0xaa	KEY_REPLY>,
			<0xb9	KEY_UP>,
			<0xe9	KEY_DOWN>,
			<0xb8	KEY_LEFT>,
			<0xea	KEY_RIGHT>,
			<0xeb	KEY_VOLUMEDOWN>,
			<0xef	KEY_VOLUMEUP>,
			<0xf7	KEY_MUTE>,
			<0xe7	KEY_POWER>,
			<0xfc	KEY_POWER>,
			<0xa9	KEY_VOLUMEDOWN>,
			<0xa8	KEY_PLAYPAUSE>,
			<0xe0	KEY_VOLUMEDOWN>,
			<0xa5	KEY_VOLUMEDOWN>,
			<0xab	183>,
			<0xb7	388>,
			<0xe8	388>,
			<0xf8	184>,
			<0xaf	185>,
			<0xed	KEY_VOLUMEDOWN>,
			<0xee	186>,
			<0xb3	KEY_VOLUMEDOWN>,
			<0xf1	KEY_VOLUMEDOWN>,
			<0xf2	KEY_VOLUMEDOWN>,
			<0xf3	KEY_SEARCH>,
			<0xb4	KEY_VOLUMEDOWN>,
			<0xa4	KEY_SETUP>,
			<0xbe	KEY_SEARCH>;
	};

	ir_key3 {
		rockchip,usercode = <0x1dcc>;
		rockchip,key_table =
			<0xee	KEY_REPLY>,
			<0xf0	KEY_BACK>,
			<0xf8	KEY_UP>,
			<0xbb	KEY_DOWN>,
			<0xef	KEY_LEFT>,
			<0xed	KEY_RIGHT>,
			<0xfc	KEY_HOME>,
			<0xf1	KEY_VOLUMEUP>,
			<0xfd	KEY_VOLUMEDOWN>,
			<0xb7	KEY_SEARCH>,
			<0xff	KEY_POWER>,
			<0xf3	KEY_MUTE>,
			<0xbf	KEY_MENU>,
			<0xf9	0x191>,
			<0xf5	0x192>,
			<0xb3	388>,
			<0xbe	KEY_1>,
			<0xba	KEY_2>,
			<0xb2	KEY_3>,
			<0xbd	KEY_4>,
			<0xf9	KEY_5>,
			<0xb1	KEY_6>,
			<0xfc	KEY_7>,
			<0xf8	KEY_8>,
			<0xb0	KEY_9>,
			<0xb6	KEY_0>,
			<0xb5	KEY_BACKSPACE>;
	};
};

&rockchip_suspend {
	status = "okay";
	rockchip,virtual-poweroff = <1>;
	rockchip,sleep-mode-config = <
		(0
		|RKPM_CTR_GTCLKS
		|RKPM_CTR_IDLESRAM_MD
		|RKPM_CTR_PMIC
		)
	>;
};

&sdio {
	status = "okay";
	mmc-pwrseq = <&sdio_pwrseq>;
};

&sdmmc {
	status = "okay";
	pinctrl-names = "default";
	pinctrl-0 = <&sdmmc_pwr &sdmmc_clk &sdmmc_cmd &sdmmc_bus4>;
};

&spdif {
	status = "okay";
	#sound-dai-cells = <0>;
};

&threshold {
	temperature = <90000>; /* millicelsius */
};

&target {
	temperature = <105000>; /* millicelsius */
};

&soc_crit {
	temperature = <115000>; /* millicelsius */
};

&tsadc {
	rockchip,hw-tshut-temp = <120000>;
	status = "okay";
};

&tve {
	status = "okay";
};

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

&u2phy0_host {
	phy-supply = <&vcc_host>;
};

&u2phy1_host {
	phy-supply = <&vcc_host>;
};

&u2phy0_otg {
	vbus-supply = <&vcc_otg_vbus>;
};

&usb_host0_ehci {
	status = "okay";
};

&usb_host0_ohci {
	status = "okay";
};

&usb_host1_ehci {
	status = "okay";
};

&usb_host1_ohci {
	status = "okay";
};

&usb_host2_ehci {
	status = "okay";
};

&usb_host2_ohci {
	status = "okay";
};

&vdpu {
	status = "okay";
};

&vepu {
	status = "okay";
};

&vpu_mmu {
	status = "okay";
};

&rkvdec {
	vcodec-supply = <&vdd_log>;
	status = "okay";
};

&rkvdec_mmu {
	status = "okay";
};

&rk_rga {
	status = "okay";
};
