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

/dts-v1/;
#include "rk3368.dtsi"
#include "rk3368-android.dtsi"
#include <dt-bindings/pwm/pwm.h>
#include <dt-bindings/clock/rk618-cru.h>

/ {
	model = "Rockchip rk3368 Sziauto board";
	compatible = "rockchip,sziauto", "rockchip,rk3368";

	panel {
		compatible = "simple-panel";
		backlight = <&backlight>;
		enable-gpios = <&gpio3 13 GPIO_ACTIVE_LOW>;
		prepare-delay-ms = <20>;
		enable-delay-ms = <20>;
		disable-delay-ms = <20>;
		unprepare-delay-ms = <20>;
		bus-format = <MEDIA_BUS_FMT_RGB888_1X7X4_SPWG>;

		display-timings {
			native-mode = <&timing0>;

			timing0: timing0 {
				clock-frequency = <136000000>;
				hactive = <1920>;
				vactive = <1080>;
				hback-porch = <60>;
				hfront-porch = <60>;
				hsync-len = <40>;
				vback-porch = <4>;
				vfront-porch = <4>;
				vsync-len = <3>;
				hsync-active = <0>;
				vsync-active = <0>;
				de-active = <0>;
				pixelclk-active = <0>;
			};
		};

		port {
			panel_in_lvds: endpoint {
				remote-endpoint = <&lvds_out_panel>;
			};
		};
	};

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

	backlight: backlight {
		compatible = "pwm-backlight";
		pwms = <&pwm0 0 50000 0>;
		brightness-levels = <
			 32  32  34  34  36  36  38  38  40  40
			 42  42  44  44  46  46  48  48  50  50
			 52  52  54  54  56  56  58  58  60  60
			 62  62  64  64  66  66  68  68  70  70
			 72  72  74  74  76  76  78  78  80  80
			 82  82  84  84  86  86  88  88  90  90
			 92  92  94  94  96  96  98  98 100 100
			102 102 104 104 106 106 108 108 110 110
			112 112 114 114 116 116 118 118 120 120
			122 122 124 124 126 126 128 128 130 130
			132 132 134 134 136 136 138 138 140 140
			142 142 144 144 146 146 148 148 150 150
			152 152 154 154 156 156 158 158 160 160
			162 162 164 164 166 166 168 168 170 170
			172 172 174 174 176 176 178 178 180 180
			182 182 184 184 186 186 188 188 190 190
			192 192 194 194 196 196 198 198 200 200
			202 202 204 204 206 206 208 208 210 210
			212 212 214 214 216 216 218 218 220 220
			222 222 224 224 225 225 226 226 227 227
			228 228 229 229 230 230 231 231 232 232
			233 233 234 234 235 235 236 236 237 237
			238 238 239 239 240 240 241 241 242 242
			243 243 244 244 245 245 246 246 247 247
			248 248 249 249 250 250 251 251 252 252
			253 253 254 254 255 255>;
		default-brightness-level = <120>;
		enable-gpios = <&gpio3 28 GPIO_ACTIVE_HIGH>;
	};

	rockchip-key {
		compatible = "rockchip,key";
		io-channels = <&saradc 1>;
		status = "okay";

		vol-up-key {
			linux,code = <115>;
			label = "volume up";
			rockchip,adc_value = <1>;
		};

		vol-down-key {
			linux,code = <114>;
			label = "volume down";
			rockchip,adc_value = <170>;
		};

		power-key {
			gpios = <&gpio0 2 GPIO_ACTIVE_LOW>;
			linux,code = <116>;
			label = "power";
			gpio-key,wakeup;
		};

		menu-key {
			linux,code = <59>;
			label = "menu";
			rockchip,adc_value = <355>;
		};

		home-key {
			linux,code = <102>;
			label = "home";
			rockchip,adc_value = <746>;
		};

		back-key {
			linux,code = <158>;
			label = "back";
			rockchip,adc_value = <560>;
		};

		camera-key {
			linux,code = <212>;
			label = "camera";
			rockchip,adc_value = <450>;
		};
	};

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

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

	xin32k: xin32k {
		compatible = "fixed-clock";
		clock-frequency = <32768>;
		clock-output-names = "xin32k";
		#clock-cells = <0>;
	};
};

&firmware_android {
	compatible = "android,firmware";
	fstab {
		compatible = "android,fstab";
		system {
			compatible = "android,system";
			dev = "/dev/block/by-name/system";
			type = "ext4";
			mnt_flags = "ro,barrier=1,inode_readahead_blks=8";
			fsmgr_flags = "wait,verify";
		};
		vendor {
			compatible = "android,vendor";
			dev = "/dev/block/by-name/vendor";
			type = "ext4";
			mnt_flags = "ro,barrier=1,inode_readahead_blks=8";
			fsmgr_flags = "wait,verify";
		};
	};
};

&i2c5 {
	status = "okay";

	rk618@50 {
		compatible = "rockchip,rk618";
		reg = <0x50>;
		pinctrl-names = "default";
		pinctrl-0 = <&i2s_8ch_mclk>;
		clocks = <&cru SCLK_I2S_8CH_OUT>;
		clock-names = "clkin";
		assigned-clocks = <&cru SCLK_I2S_8CH_OUT>;
		assigned-clock-rates = <11289600>;
		reset-gpios = <&gpio3 14 GPIO_ACTIVE_LOW>;
		status = "okay";

		clock: cru {
			compatible = "rockchip,rk618-cru";
			clocks = <&cru SCLK_I2S_8CH_OUT>, <&cru DCLK_VOP>;
			clock-names = "clkin", "lcdc0_dclkp";
			assigned-clocks = <&clock SCALER_PLLIN_CLK>, <&clock VIF_PLLIN_CLK>,
					  <&clock SCALER_CLK>, <&clock VIF0_PRE_CLK>,
					  <&clock CODEC_CLK>, <&clock DITHER_CLK>;
			assigned-clock-parents = <&cru SCLK_I2S_8CH_OUT>, <&clock LCDC0_CLK>,
						 <&clock SCALER_PLL_CLK>, <&clock VIF_PLL_CLK>,
						 <&cru SCLK_I2S_8CH_OUT>, <&clock VIF0_CLK>;
			#clock-cells = <1>;
			status = "okay";
		};

		hdmi {
			compatible = "rockchip,rk618-hdmi";
			clocks = <&clock HDMI_CLK>;
			clock-names = "hdmi";
			assigned-clocks = <&clock HDMI_CLK>;
			assigned-clock-parents = <&clock VIF0_CLK>;
			interrupt-parent = <&gpio3>;
			interrupts = <23 IRQ_TYPE_LEVEL_HIGH>;
			status = "okay";

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

				port@0 {
					reg = <0>;

					hdmi_in_vif: endpoint {
						remote-endpoint = <&vif_out_hdmi>;
					};
				};

				port@1 {
					reg = <1>;

					hdmi_out_scaler: endpoint {
						remote-endpoint = <&scaler_in_hdmi>;
					};
				};
			};
		};

		lvds {
			compatible = "rockchip,rk618-lvds";
			clocks = <&clock LVDS_CLK>;
			clock-names = "lvds";
			dual-channel;
			status = "okay";

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

				port@0 {
					reg = <0>;

					lvds_in_scaler: endpoint {
						remote-endpoint = <&scaler_out_lvds>;
					};
				};

				port@1 {
					reg = <1>;

					lvds_out_panel: endpoint {
						remote-endpoint = <&panel_in_lvds>;
					};
				};
			};
		};

		scaler {
			compatible = "rockchip,rk618-scaler";
			clocks = <&clock SCALER_CLK>, <&clock VIF0_CLK>,
				 <&clock DITHER_CLK>;
			clock-names = "scaler", "vif", "dither";
			status = "okay";

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

				port@0 {
					reg = <0>;

					scaler_in_hdmi: endpoint {
						remote-endpoint = <&hdmi_out_scaler>;
					};
				};

				port@1 {
					reg = <1>;

					scaler_out_lvds: endpoint {
						remote-endpoint = <&lvds_in_scaler>;
					};
				};
			};
		};

		vif {
			compatible = "rockchip,rk618-vif";
			clocks = <&clock VIF0_CLK>, <&clock VIF0_PRE_CLK>;
			clock-names = "vif", "vif_pre";
			status = "okay";

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

				port@0 {
					reg = <0>;

					vif_in_rgb: endpoint {
						remote-endpoint = <&rgb_out_vif>;
					};
				};

				port@1 {
					reg = <1>;

					vif_out_hdmi: endpoint {
						remote-endpoint = <&hdmi_in_vif>;
					};
				};
			};
		};
	};
};

&rgb {
	status = "okay";

	ports {
		port@1 {
			reg = <1>;

			rgb_out_vif: endpoint {
				remote-endpoint = <&vif_in_rgb>;
			};
		};
	};
};

&route_rgb {
	status = "okay";
};

&emmc {
	status = "okay";
	bus-width = <8>;
	cap-mmc-highspeed;
	mmc-hs200-1_8v;
	no-sdio;
	no-sd;
	disable-wp;
	non-removable;
	num-slots = <1>;
	pinctrl-names = "default";
	pinctrl-0 = <&emmc_clk &emmc_cmd &emmc_bus8>;
};

&sdmmc {
	status = "disabled";
	clock-frequency = <37500000>;
	clock-freq-min-max = <400000 37500000>;
	no-sdio;
	no-mmc;
	cap-mmc-highspeed;
	cap-sd-highspeed;
	card-detect-delay = <200>;
	disable-wp;
	num-slots = <1>;
	pinctrl-names = "default";
	pinctrl-0 = <&sdmmc_clk &sdmmc_cmd &sdmmc_cd &sdmmc_bus4>;
};

&sdio0 {
	clock-frequency = <50000000>;
	clock-freq-min-max = <200000 50000000>;
	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;
	num-slots = <1>;
	pinctrl-names = "default";
	pinctrl-0 = <&sdio0_bus4 &sdio0_cmd &sdio0_clk>;
	sd-uhs-sdr104;
	status = "okay";
};

&i2c0 {
	status = "okay";

	syr827: syr827@40 {
		compatible = "silergy,syr827";
		reg = <0x40>;
		fcs,suspend-voltage-selector = <1>;

		regulator-compatible = "fan53555-reg";
		regulator-name = "vdd_arm";
		regulator-min-microvolt = <712500>;
		regulator-max-microvolt = <1500000>;
		regulator-ramp-delay = <1000>;
		regulator-always-on;
		regulator-boot-on;
		regulator-initial-state = <3>;

		regulator-state-mem {
			regulator-off-in-suspend;
			regulator-suspend-microvolt = <900000>;
		};
	};

	rk818: pmic@1c {
		compatible = "rockchip,rk818";
		reg = <0x1c>;
		clock-output-names = "rk818-clkout1", "wifibt_32kin";
		interrupt-parent = <&gpio0>;
		interrupts = <1 IRQ_TYPE_LEVEL_LOW>;
		pinctrl-names = "default";
		pinctrl-0 = <&pmic_int_l>;
		rockchip,system-power-controller;
		wakeup-source;
		#clock-cells = <1>;

		vcc1-supply = <&vcc_sys>;
		vcc2-supply = <&vcc_sys>;
		vcc3-supply = <&vcc_sys>;
		vcc4-supply = <&vcc_sys>;
		vcc6-supply = <&vcc_sys>;
		vcc7-supply = <&vcc_sys>;
		vcc8-supply = <&vcc_sys>;
		vcc9-supply = <&vcc_io>;

		regulators {
			vdd_logic: DCDC_REG1 {
				regulator-name = "vdd_logic";
				regulator-always-on;
				regulator-boot-on;
				regulator-min-microvolt = <750000>;
				regulator-max-microvolt = <1450000>;
				regulator-ramp-delay = <6001>;

				regulator-state-mem {
					regulator-on-in-suspend;
					regulator-suspend-microvolt = <1000000>;
				};
			};

			vdd_gpu: DCDC_REG2 {
				regulator-name = "vdd_gpu";
				regulator-always-on;
				regulator-boot-on;
				regulator-min-microvolt = <800000>;
				regulator-max-microvolt = <1250000>;
				regulator-ramp-delay = <6001>;

				regulator-state-mem {
					regulator-on-in-suspend;
					regulator-suspend-microvolt = <1000000>;
				};
			};

			vcc_ddr: DCDC_REG3 {
				regulator-always-on;
				regulator-boot-on;
				regulator-name = "vcc_ddr";

				regulator-state-mem {
					regulator-on-in-suspend;
				};
			};

			vcc_io: DCDC_REG4 {
				regulator-always-on;
				regulator-boot-on;
				regulator-min-microvolt = <3300000>;
				regulator-max-microvolt = <3300000>;
				regulator-name = "vcc_io";

				regulator-state-mem {
					regulator-on-in-suspend;
					regulator-suspend-microvolt = <3300000>;
				};
			};

			vcca_codec: LDO_REG1 {
				regulator-always-on;
				regulator-boot-on;
				regulator-min-microvolt = <3300000>;
				regulator-max-microvolt = <3300000>;
				regulator-name = "vcca_codec";

				regulator-state-mem {
					regulator-on-in-suspend;
					regulator-suspend-microvolt = <3300000>;
				};
			};

			vcc_tp: LDO_REG2 {
				regulator-always-on;
				regulator-boot-on;
				regulator-min-microvolt = <3000000>;
				regulator-max-microvolt = <3000000>;
				regulator-name = "vcc_tp";

				regulator-state-mem {
					regulator-off-in-suspend;
				};
			};

			vdd_10: LDO_REG3 {
				regulator-always-on;
				regulator-boot-on;
				regulator-min-microvolt = <1000000>;
				regulator-max-microvolt = <1000000>;
				regulator-name = "vdd_10";

				regulator-state-mem {
					regulator-on-in-suspend;
					regulator-suspend-microvolt = <1000000>;
				};
			};

			vcc18_lcd: LDO_REG4 {
				regulator-always-on;
				regulator-boot-on;
				regulator-min-microvolt = <1800000>;
				regulator-max-microvolt = <1800000>;
				regulator-name = "vcc18_lcd";

				regulator-state-mem {
					regulator-on-in-suspend;
					regulator-suspend-microvolt = <1800000>;
				};
			};

			vccio_pmu: LDO_REG5 {
				regulator-always-on;
				regulator-boot-on;
				regulator-min-microvolt = <1800000>;
				regulator-max-microvolt = <1800000>;
				regulator-name = "vccio_pmu";

				regulator-state-mem {
					regulator-on-in-suspend;
					regulator-suspend-microvolt = <1800000>;
				};
			};

			vdd10_lcd: LDO_REG6 {
				regulator-always-on;
				regulator-boot-on;
				regulator-min-microvolt = <1000000>;
				regulator-max-microvolt = <1000000>;
				regulator-name = "vdd10_lcd";

				regulator-state-mem {
					regulator-on-in-suspend;
					regulator-suspend-microvolt = <1000000>;
				};
			};

			vcc_18: LDO_REG7 {
				regulator-always-on;
				regulator-boot-on;
				regulator-min-microvolt = <1800000>;
				regulator-max-microvolt = <1800000>;
				regulator-name = "vcc_18";

				regulator-state-mem {
					regulator-on-in-suspend;
					regulator-suspend-microvolt = <1800000>;
				};
			};

			vccio_wl: LDO_REG8 {
				regulator-always-on;
				regulator-boot-on;
				regulator-min-microvolt = <1800000>;
				regulator-max-microvolt = <3300000>;
				regulator-name = "vccio_wl";

				regulator-state-mem {
					regulator-on-in-suspend;
					regulator-suspend-microvolt = <3300000>;
				};
			};

			vccio_sd: LDO_REG9 {
				regulator-always-on;
				regulator-boot-on;
				regulator-min-microvolt = <1800000>;
				regulator-max-microvolt = <3300000>;
				regulator-name = "vccio_sd";

				regulator-state-mem {
					regulator-on-in-suspend;
					regulator-suspend-microvolt = <3300000>;
				};
			};

			vcc_sd: SWITCH_REG {
				regulator-always-on;
				regulator-boot-on;
				regulator-name = "vcc_sd";

				regulator-state-mem {
					regulator-on-in-suspend;
				};
			};

			boost_otg: DCDC_BOOST {
				regulator-name = "boost_otg";
				regulator-always-on;
				regulator-boot-on;
				regulator-min-microvolt = <5000000>;
				regulator-max-microvolt = <5000000>;

				regulator-state-mem {
					regulator-on-in-suspend;
					regulator-suspend-microvolt = <5000000>;
				};
			};
		};
	};
};

&cpu_l0 {
	cpu-supply = <&syr827>;
};

&cpu_l1 {
	cpu-supply = <&syr827>;
};

&cpu_l2 {
	cpu-supply = <&syr827>;
};

&cpu_l3 {
	cpu-supply = <&syr827>;
};

&cpu_b0 {
	cpu-supply = <&syr827>;
};

&cpu_b1 {
	cpu-supply = <&syr827>;
};

&cpu_b2 {
	cpu-supply = <&syr827>;
};

&cpu_b3 {
	cpu-supply = <&syr827>;
};

&gpu {
	logic-supply = <&vdd_logic>;
};

&io_domains {
	dvp-supply = <&vcc_18>;
	audio-supply = <&vcc_io>;
	gpio30-supply = <&vcc_io>;
	gpio1830-supply = <&vcc_io>;
	sdcard-supply = <&vccio_sd>;
	wifi-supply = <&vccio_wl>;
	status = "okay";
};

&pmu_io_domains {
	pmu-supply = <&vcc_io>;
	vop-supply = <&vcc_io>;
	status = "okay";
};

&pwm0 {
	status = "okay";
};

&pwm1 {
	status = "okay";
};

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

&u2phy {
	status = "okay";

	u2phy_host: host-port {
		phy-supply = <&vcc_host>;
		status = "okay";
	};
};

&usb_host0_ehci {
	status = "okay";
};

&usb_host0_ohci {
	status = "okay";
};

&mailbox {
	status = "okay";
};

&mailbox_scpi {
	status = "okay";
};

&saradc {
	status = "okay";
};

&tsadc {
	tsadc-supply = <&syr827>;
	status = "okay";
};

&pinctrl {
	pmic {
		pmic_int_l: pmic-int-l {
			rockchip,pins = <0 RK_PA1 RK_FUNC_GPIO &pcfg_pull_up>;
		};
	};

	usb2 {
		host_vbus_drv: host-vbus-drv {
			rockchip,pins = <0 RK_PA4 RK_FUNC_GPIO &pcfg_pull_none>;
		};
	};

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