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

/dts-v1/;

#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/pinctrl/rockchip.h>
#include <dt-bindings/input/rk-input.h>
#include <dt-bindings/sensor-dev.h>
#include <dt-bindings/display/drm_mipi_dsi.h>
#include "dt-bindings/usb/pd.h"
#include "../rk3562.dtsi"

/ {
	rpdzkj:rpdzkj_config {
		compatible = "rp_config";
		user_version = "rpdzkj";
		system_rotate = "0";
		csi_camera_rotate = "0"; //all csi camera rotation //0 90 180 270 //no effect
		csi_camera_facing = "0"; //0:auto  1:all front   2:all back //no effect
		usb_camera_rotate = "0"; //all usb camera rotation //0 90 180 270 
		usb_camera_facing = "0"; //0:auto  1:all front   2:all back
		lcd_density = "160";
		language = "zh-CN";   //zh-CN //en-US
		time_zone = "Asia/Shanghai"; //Asia/Shanghai = +8   //Europe/London  = +1       //Africa/Casablanca     = +0;
		not_navigation_bar = "false";
		not_status_bar = "false";
		default_launcher = "true";
		has_root = "true";
		usb_not_permission = "true";
		gps_use = "false";
		gps_serial_port = "/dev/ttyS4";
		primary_device = "DSI";
		extend_device = "HDMI-A";
		extend_rotate = "0";
		rotation_efull = "false";
		extend_rotate_2 = "0";//0 0//1 90 //2 180 //3 270
		rotation_efull_2 = "true";
		extend_rotate_3 = "0";//0 0//1 90 //2 180 //3 270
		rotation_efull_3 = "true";
		home_apk = "null";
		status = "okay";
  	};

	lvds_panel: panel@0 {
		status = "disabled";
	};	

	charge-animation {
		compatible = "rockchip,uboot-charge";
		rockchip,uboot-charge-on = <0>;
		rockchip,android-charge-on = <0>;
		rockchip,uboot-low-power-voltage = <3250>;
		rockchip,screen-on-voltage = <3300>;
		status = "okay";
	};

	rk817_sound: rk817-sound {
		status = "okay";
		compatible = "rockchip,multicodecs-card";
		rockchip,card-name = "rockchip-rk817";
	//	hp-det-gpio = <&gpio3 RK_PA0 GPIO_ACTIVE_LOW>;
		rockchip,format = "i2s";
		rockchip,mclk-fs = <256>;
		rockchip,cpu = <&sai0>;
		rockchip,codec = <&rk817_codec>;
	//	pinctrl-names = "default";
	//	pinctrl-0 = <&hp_det>;
	};
	rk_headset: rk-headset {
		compatible = "rockchip_headset";
	};
	
//	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>;
//	};
	
	vcc_sd: vcc-sd {
		compatible = "regulator-gpio";
		enable-active-low;
		regulator-boot-on;
		enable-gpio = <&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";
	};
	
	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>;
     	};

	vcc5v_midu: vcc5v-midu {
                compatible = "regulator-fixed";
                regulator-name = "vcc5v_midu";
                regulator-always-on;
                regulator-boot-on;
                regulator-min-microvolt = <5000000>;
                regulator-max-microvolt = <5000000>;
                vin-supply = <&dc_12v>;
        };

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

	vcc3v3_lcd_n: vcc3v3-lcd-n {
         	compatible = "regulator-fixed";
         	regulator-name = "vcc3v3_lcd_n";
         	regulator-boot-on;
         	regulator-min-microvolt = <3300000>;
         	regulator-max-microvolt = <3300000>;
         	enable-active-high;
         	vin-supply = <&vcc3v3_sys>;
         	regulator-state-mem {
			regulator-off-in-suspend;
         	};
     	};	
	/*
	wireless-wlan {
		compatible = "wlan-platdata";
		rockchip,grf = <&sys_grf>;
		wifi_chip_type = "ap6255";
		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>;
		WIFI,vbat_gpio = <&gpio0 RK_PA0 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";
	};
	*/
};

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

//&bus_soc {
//	rockchip,soc-bus-table = <0 0x00a000a8 0x7001>,
//				 <1 0x00a000a8 0x7c39>,
//				 <2 0x00a000a8 0x7c39>,
//				 <3 0x00a000a8 0x7c39>,
//				 <4 0x00a000a5 0xb007>,
//				 <5 0x00a000a8 0x7034>,
//				 <6 0x00a000a8 0x7034>,
//				 <7 0x00a000a8 0x7034>,
//				 <8 0x00a000a8 0x7001>;
//};

&display_subsystem {
	status = "okay";
};

&dsi {
 dsi_panel: panel@0 {
            status = "disabled";
        };
};

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

&i2c0 {
	status = "okay";

	rk817: pmic@20 {
		compatible = "rockchip,rk817";
		reg = <0x20>;
		interrupt-parent = <&gpio0>;
		interrupts = <3 IRQ_TYPE_LEVEL_LOW>;

		pinctrl-names = "default", "pmic-sleep",
			"pmic-power-off", "pmic-reset";
		pinctrl-0 = <&pmic_int>;
		pinctrl-1 = <&soc_slppin_slp>, <&rk817_slppin_slp>;
		pinctrl-2 = <&soc_slppin_gpio>, <&rk817_slppin_pwrdn>;
		pinctrl-3 = <&soc_slppin_gpio>, <&rk817_slppin_rst>;
		rockchip,system-power-controller;
		wakeup-source;
		#clock-cells = <1>;
		clock-output-names = "rk808-clkout1", "rk808-clkout2";
		/* 1: rst regs (default in codes), 0: rst the pmic */
		pmic-reset-func = <0>;
		vcc1-supply = <&vcc_sys>;
		vcc2-supply = <&vcc_sys>;
		vcc3-supply = <&vcc_sys>;
		vcc4-supply = <&vcc_sys>;
		vcc5-supply = <&vcc_sys>;
		vcc6-supply = <&vcc_sys>;
		vcc7-supply = <&vcc_sys>;
		vcc8-supply = <&vcc_sys>;
		vcc9-supply = <&dcdc_boost>;
		pwrkey {
			status = "okay";
		};

		pinctrl_rk8xx: pinctrl_rk8xx {
			gpio-controller;
			#gpio-cells = <2>;

			rk817_slppin_null: rk817_slppin_null {
				pins = "gpio_slp";
				function = "pin_fun0";
			};

			rk817_slppin_slp: rk817_slppin_slp {
				pins = "gpio_slp";
				function = "pin_fun1";
			};

			rk817_slppin_pwrdn: rk817_slppin_pwrdn {
				pins = "gpio_slp";
				function = "pin_fun2";
			};

			rk817_slppin_rst: rk817_slppin_rst {
				pins = "gpio_slp";
				function = "pin_fun3";
			};
		};

		regulators {
			vdd_logic: DCDC_REG1 {
				regulator-always-on;
				regulator-boot-on;
				regulator-min-microvolt = <500000>;
				regulator-max-microvolt = <1350000>;
				regulator-init-microvolt = <900000>;
				regulator-ramp-delay = <6001>;
				regulator-initial-mode = <0x2>;
				regulator-name = "vdd_logic";
				regulator-state-mem {
					regulator-off-in-suspend;
					regulator-suspend-microvolt = <900000>;
				};
			};

			vdd_cpu: DCDC_REG2 {
				regulator-always-on;
				regulator-boot-on;
				regulator-min-microvolt = <500000>;
				regulator-max-microvolt = <1350000>;
				regulator-init-microvolt = <900000>;
				regulator-ramp-delay = <6001>;
				regulator-initial-mode = <0x2>;
				regulator-name = "vdd_cpu";
				regulator-state-mem {
					regulator-off-in-suspend;
				};
			};

			vcc_ddr: DCDC_REG3 {
				regulator-always-on;
				regulator-boot-on;
				regulator-initial-mode = <0x2>;
				regulator-name = "vcc_ddr";
				regulator-state-mem {
					regulator-on-in-suspend;
				};
			};

			vcc3v3_sys: DCDC_REG4 {
				regulator-always-on;
				regulator-boot-on;
				regulator-min-microvolt = <3300000>;
				regulator-max-microvolt = <3300000>;
				regulator-initial-mode = <0x2>;
				regulator-name = "vcc3v3_sys";
				regulator-state-mem {
					regulator-on-in-suspend;
					regulator-suspend-microvolt = <3300000>;
				};
			};

			vcca1v8_pmu: LDO_REG1 {
				regulator-always-on;
				regulator-boot-on;
				regulator-min-microvolt = <1800000>;
				regulator-max-microvolt = <1800000>;
				regulator-name = "vcca1v8_pmu";
				regulator-state-mem {
					regulator-on-in-suspend;
					regulator-suspend-microvolt = <1800000>;
				};
			};

			vdda_0v9: LDO_REG2 {
				regulator-always-on;
				regulator-boot-on;
				regulator-min-microvolt = <900000>;
				regulator-max-microvolt = <900000>;
				regulator-name = "vdda_0v9";
				regulator-state-mem {
					regulator-off-in-suspend;
				};
			};

			vdda0v9_pmu: LDO_REG3 {
				regulator-always-on;
				regulator-boot-on;
				regulator-min-microvolt = <900000>;
				regulator-max-microvolt = <900000>;
				regulator-name = "vdda0v9_pmu";
				regulator-state-mem {
					regulator-on-in-suspend;
					regulator-suspend-microvolt = <900000>;
				};
			};

			vccio_acodec: LDO_REG4 {
				regulator-always-on;
				regulator-boot-on;
				regulator-min-microvolt = <3000000>;
				regulator-max-microvolt = <3000000>;
				regulator-name = "vccio_acodec";
				regulator-state-mem {
					regulator-off-in-suspend;
				};
			};

			vccio_sd: LDO_REG5 {
				regulator-always-on;
				regulator-boot-on;
				regulator-min-microvolt = <1800000>;
				regulator-max-microvolt = <3300000>;
				regulator-name = "vccio_sd";
				regulator-state-mem {
					regulator-off-in-suspend;
				};
			};

			vcc3v3_pmu: LDO_REG6 {
				regulator-always-on;
				regulator-boot-on;
				regulator-min-microvolt = <3300000>;
				regulator-max-microvolt = <3300000>;
				regulator-name = "vcc3v3_pmu";
				regulator-state-mem {
					regulator-on-in-suspend;
					regulator-suspend-microvolt = <3000000>;
				};
			};

			vcc_1v8: LDO_REG7 {
				regulator-always-on;
				regulator-boot-on;
				regulator-min-microvolt = <1800000>;
				regulator-max-microvolt = <1800000>;
				regulator-name = "vcc_1v8";
				regulator-state-mem {
					regulator-off-in-suspend;
				};
			};

			vcc1v8_dvp: LDO_REG8 {
				regulator-always-on;
				regulator-boot-on;
				regulator-min-microvolt = <1800000>;
				regulator-max-microvolt = <1800000>;
				regulator-name = "vcc1v8_dvp";
				regulator-state-mem {
					regulator-off-in-suspend;
				};
			};

			vcc2v8_dvp: LDO_REG9 {
				regulator-always-on;
				regulator-boot-on;
				regulator-min-microvolt = <2800000>;
				regulator-max-microvolt = <2800000>;
				regulator-name = "vcc2v8_dvp";
				regulator-state-mem {
					regulator-off-in-suspend;
				};
			};

			dcdc_boost: BOOST {
				regulator-always-on;
				regulator-boot-on;
				regulator-min-microvolt = <4700000>;
				regulator-max-microvolt = <5400000>;
				regulator-name = "boost";
				regulator-state-mem {
					regulator-off-in-suspend;
				};
			};

			otg_switch: OTG_SWITCH {
				regulator-name = "otg_switch";
				regulator-state-mem {
					regulator-off-in-suspend;
				};
			};
		};
		
		/*
		battery {
			compatible = "rk817,battery";
			ocv_table = <3400 3671 3686 3712 3738 3756 3773
				     3787 3802 3819 3840 3868 3916 3959
				     3998 4041 4087 4138 4191 4247 4313>;
			design_capacity = <5780>;
			design_qmax = <6358>;
			bat_res = <100>;
			sleep_enter_current = <150>;
			sleep_exit_current = <180>;
			sleep_filter_current = <100>;
			power_off_thresd = <3400>;
			zero_algorithm_vol = <3950>;
			max_soc_offset = <60>;
			monitor_sec = <5>;
			sample_res = <10>;
			virtual_power = <0>;
		};

		charger {
			compatible = "rk817,charger";
			min_input_voltage = <4500>;
			max_input_current = <1500>;
			max_chrg_current = <2000>;
			max_chrg_voltage = <4350>;
			chrg_term_mode = <0>;
			chrg_finish_cur = <300>;
			virtual_power = <0>;
			dc_det_adc = <0>;
			extcon = <&u2phy>;
			gate_function_disable = <1>;
		};
		*/
		rk817_codec: codec {
			#sound-dai-cells = <0>;
			compatible = "rockchip,rk817-codec";
			clocks = <&mclkout_sai0>;
			clock-names = "mclk";
			assigned-clocks = <&mclkout_sai0>;
			assigned-clock-rates = <12288000>;
			pinctrl-names = "default";
			pinctrl-0 = <&i2s0m0_mclk>;
			hp-volume = <20>;
			spk-volume = <55>;
			status = "okay";
		};
	};
};

&jpegd {
	status = "okay";
};

&jpegd_mmu {
	status = "okay";
};

&mpp_srv {
	status = "okay";
};

&pinctrl {
	/*
	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>;
		};
	};
	/*
	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>;
		};
	};
	*/
};

&pwm6 {
	status = "okay";
};

&pwm7 {
	status = "okay";
};

&rga2 {
	status = "okay";
};

&rga2_mmu {
	status = "okay";
};

&rknpu {
 	rknpu-supply = <&vdd_npu>;
 	status = "okay";
};

&rknpu_mmu {
	status = "okay";
};

&rkvdec {
	status = "okay";
};

&rkvdec_mmu {
	status = "okay";
};

&rkvenc {
	status = "okay";
};

&rkvenc_mmu {
	status = "okay";
};


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

&saradc0 {
	status = "okay";
	vref-supply = <&vcc_1v8>;
};

&saradc1 {
        status = "okay";
        vref-supply = <&vcc_1v8>;
};

&sdhci {
	bus-width = <8>;
	no-sdio;
	no-sd;
	supports-emmc;
	non-removable;
	max-frequency = <200000000>;
	mmc-hs400-1_8v;
	mmc-hs400-enhanced-strobe;
	full-pwr-cycle-in-suspend;
	status = "okay";
};

&sdmmc0 {
	max-frequency = <200000000>;
	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 {
	max-frequency = <200000000>;
	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";
};
*/
&tsadc {
	status = "okay";
};

&vop {
	status = "okay";
};

&vop_mmu {
	status = "okay";
};
