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

/dts-v1/;

#include "dt-bindings/usb/pd.h"
#include "rk3562.dtsi"
#include "rk3562-evb.dtsi"
#include "rk3562-evb1-cam.dtsi"
#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/pinctrl/rockchip.h>
#include <dt-bindings/sensor-dev.h>

/ {
	model = "Rockchip RK3562 EVB1 LP4X V10 Board";
	compatible = "rockchip,rk3562-evb1-lp4x-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>;
	};

	rk817_sound: rk817-sound {
		status = "okay";
		compatible = "rockchip,multicodecs-card";
		rockchip,card-name = "rockchip-rk817";
		hp-det-gpio = <&gpio1 RK_PD0 GPIO_ACTIVE_LOW>;
		rockchip,format = "i2s";
		rockchip,mclk-fs = <256>;
		rockchip,cpu = <&sai0>;
		rockchip,codec = <&rk817_codec>;
		pinctrl-names = "default";
		pinctrl-0 = <&hp_det>;
	};

	sdio_pwrseq: sdio-pwrseq {
		compatible = "mmc-pwrseq-simple";
		clocks = <&rk817 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>;
	};

	vcc3v3_pcie20: vcc3v3-pcie20 {
		compatible = "regulator-fixed";
		regulator-name = "vcc3v3_pcie20";
		regulator-min-microvolt = <3300000>;
		regulator-max-microvolt = <3300000>;
		enable-active-high;
		gpios = <&gpio0 RK_PB7 GPIO_ACTIVE_HIGH>;
		startup-delay-us = <5000>;
		vin-supply = <&dc_12v>;
	};

	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_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 = <&gpio4 RK_PB0 GPIO_ACTIVE_HIGH>;
		vin-supply = <&dcdc_boost>;
		pinctrl-names = "default";
		pinctrl-0 = <&usb_host_pwren>;
	};

	vbat_3v8: vbat-3v8 {
		compatible = "regulator-fixed";
		regulator-name = "vbat_3v8";
		regulator-always-on;
		regulator-boot-on;
		regulator-min-microvolt = <3800000>;
		regulator-max-microvolt = <3800000>;
	};

	vcc_sd: vcc-sd {
		compatible = "regulator-gpio";
		enable-active-low;
		regulator-boot-on;
		gpios = <&gpio0 RK_PA5 GPIO_ACTIVE_LOW>;
		regulator-min-microvolt = <3300000>;
		regulator-max-microvolt = <3300000>;
		pinctrl-names = "default";
		pinctrl-0 = <&vcc_sd_h>;
		regulator-name = "vcc_sd";
		states = <0 0x0
			  3300000 0x1>;
	};

	vcc_sys: vcc-sys {
		compatible = "regulator-fixed";
		regulator-name = "vcc_sys";
		regulator-always-on;
		regulator-boot-on;
		regulator-min-microvolt = <3800000>;
		regulator-max-microvolt = <3800000>;
	};

	vdd_gpu: vdd-gpu {
		compatible = "pwm-regulator";
		pwms = <&pwm7 0 5000 1>;
		regulator-name = "vdd_gpu";
		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 = <&vcc_sys>;
		status = "okay";
	};

	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 = <&vcc_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 = <&rk817 1>;
		clock-names = "ext_clock";
		//wifi-bt-power-toggle;
		uart_rts_gpios = <&gpio1 RK_PD3 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";
	};
};

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

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

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

	pinctrl-names = "default";
	pinctrl-0 = <&rgmiim0_miim
		     &rgmiim0_tx_bus2
		     &rgmiim0_rx_bus2
		     &rgmiim0_rgmii_clk
		     &rgmiim0_rgmii_bus
		     &ethm0_pins>;

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

&i2c0 {
	status = "okay";

	usbc0: fusb302@22 {
		compatible = "fcs,fusb302";
		reg = <0x22>;
		interrupt-parent = <&gpio1>;
		interrupts = <RK_PC7 IRQ_TYPE_LEVEL_LOW>;
		pinctrl-names = "default";
		pinctrl-0 = <&usbc0_int>;
		vbus-supply = <&otg_switch>;
		status = "okay";

		ports {
			#address-cells = <1>;
			#size-cells = <0>;

			port@0 {
				reg = <0>;
				usbc0_role_sw: endpoint@0 {
					remote-endpoint = <&dwc3_role_switch>;
				};
			};
		};

		usb_con: connector {
			compatible = "usb-c-connector";
			label = "USB-C";
			data-role = "dual";
			power-role = "dual";
			try-power-role = "sink";
			op-sink-microwatt = <1000000>;
			sink-pdos =
				<PDO_FIXED(5000, 1000, PDO_FIXED_USB_COMM)>;
			source-pdos =
				<PDO_FIXED(5000, 3000, PDO_FIXED_USB_COMM)>;
		};
	};
};

&i2c5 {
	status = "okay";

	mpu6500_acc: mpu_acc@68 {
		compatible = "mpu6500_acc";
		reg = <0x68>;
		irq-gpio = <&gpio0 RK_PA7 IRQ_TYPE_EDGE_RISING>;
		irq_enable = <0>;
		poll_delay_ms = <30>;
		type = <SENSOR_TYPE_ACCEL>;
		layout = <3>;
	};

	mpu6500_gyro: mpu_gyro@68 {
		compatible = "mpu6500_gyro";
		reg = <0x68>;
		poll_delay_ms = <30>;
		type = <SENSOR_TYPE_GYROSCOPE>;
		layout = <3>;
	};
};

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

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

&pwm3 {
	status = "okay";

	compatible = "rockchip,remotectl-pwm";
	pinctrl-names = "default";
	pinctrl-0 = <&pwm3m0_pins>;
	assigned-clocks = <&cru CLK_PMU1_PWM0>;
	assigned-clock-rates = <24000000>;
	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_VOLUMEDOWN>,
			<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>,
			<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>;
	};
};

&pwm6 {
	status = "okay";
};

&pwm7 {
	status = "okay";
};

&route_dsi {
	status = "okay";
};

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

&video_phy {
	status = "okay";
};

&pcie2x1 {
	reset-gpios = <&gpio3 RK_PB0 GPIO_ACTIVE_HIGH>;
	vpcie3v3-supply = <&vcc3v3_pcie20>;
	status = "okay";
};

&pinctrl {
	headphone {
		hp_det: hp-det {
			rockchip,pins = <1 RK_PD0 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>;
		};
	};

	vcc_sd {
		vcc_sd_h: vcc-sd-h {
			rockchip,pins = <0 RK_PA5 RK_FUNC_GPIO &pcfg_pull_down>;
		};
	};

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

		usbc0_int: usbc0-int {
			rockchip,pins = <1 RK_PC7 RK_FUNC_GPIO &pcfg_pull_up>;
		};
	};

	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_PD3 RK_FUNC_GPIO &pcfg_pull_none>;
		};
	};
};

&sai0 {
	status = "okay";
	pinctrl-names = "default";
	pinctrl-0 = <&i2s0m0_lrck
		     &i2s0m0_sclk
		     &i2s0m0_sdi0
		     &i2s0m0_sdo0>;
};

&sdmmc0 {
	no-sdio;
	no-mmc;
	bus-width = <4>;
	cap-mmc-highspeed;
	cap-sd-highspeed;
	disable-wp;
	sd-uhs-sdr104;
	vmmc-supply = <&vcc_sd>;
	vqmmc-supply = <&vccio_sd>;
	pinctrl-names = "default";
	pinctrl-0 = <&sdmmc0_bus4 &sdmmc0_clk &sdmmc0_cmd &sdmmc0_det>;
	status = "okay";
};

&sdmmc1 {
	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 = <&sdmmc1_bus4 &sdmmc1_cmd &sdmmc1_clk>;
	sd-uhs-sdr104;
	status = "okay";
};

&u2phy {
	status = "okay";
};

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

&u2phy_otg {
	status = "okay";
};

&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";
	maximum-speed = "high-speed";
	phys = <&u2phy_otg>;
	phy-names = "usb2-phy";
	snps,dis_u2_susphy_quirk;
	snps,usb2-lpm-disable;
	usb-role-switch;
	port {
		#address-cells = <1>;
		#size-cells = <0>;
		dwc3_role_switch: endpoint@0 {
			reg = <0>;
			remote-endpoint = <&usbc0_role_sw>;
		};
	};
};
