#include <dt-bindings/clock/qcom,rpmh.h>
#include <dt-bindings/pinctrl/qcom,pmic-gpio.h>
#include <dt-bindings/iio/qcom,spmi-adc7-pm6450.h>

#define PMR735A_SID	6

#include "pmk8350.dtsi"
#include "pm6450.dtsi"
#include "pm6150l.dtsi"
#include "pmr735a.dtsi"

&soc {
	reboot_reason {
		compatible = "qcom,reboot-reason";
		nvmem-cells = <&restart_reason>;
		nvmem-cell-names = "restart_reason";
	};

	pmic-pon-log {
		compatible = "qcom,pmic-pon-log";
		nvmem = <&pmk8350_sdam_5>;
		nvmem-names = "pon_log";
	};
};

&pmk8350 {
	/delete-node/ pon_pbs@800;
	/delete-node/ pon_hlos@1300;

	pon_hlos@1300 {
		compatible = "qcom,pm8998-pon";
		reg = <0x1300>, <0x800>;
		reg-names = "pon_hlos", "pon_pbs";
		qcom,log-kpd-event;

		pwrkey {
			compatible = "qcom,pmk8350-pwrkey";
			interrupts = <0x0 0x13 0x7 IRQ_TYPE_EDGE_BOTH>;
			linux,code = <KEY_POWER>;
		};

		resin {
			compatible = "qcom,pmk8350-resin";
			interrupts = <0x0 0x13 0x6 IRQ_TYPE_EDGE_BOTH>;
			linux,code = <KEY_VOLUMEDOWN>;
		};
	};
};

&pmk8350_vadc {
	pinctrl-names = "default";
	pinctrl-0 = <&quiet_therm_default>;

	/delete-node/ pm8350_ref_gnd;
	/delete-node/ pm8350_vref_1p25;
	/delete-node/ pm8350_die_temp;
	/delete-node/ pm8350_vph_pwr;

	/delete-node/ pm8350b_ref_gnd;
	/delete-node/ pm8350b_vref_1p25;
	/delete-node/ pm8350b_die_temp;
	/delete-node/ pm8350b_vph_pwr;
	/delete-node/ pm8350b_vbat_sns;

	/delete-node/ pmr735b_ref_gnd;
	/delete-node/ pmr735b_vref_1p25;
	/delete-node/ pmr735b_die_temp;

	/* PM6450 Channel nodes */
	pm6450_ref_gnd {
		reg = <PM6450_ADC7_REF_GND>;
		label = "pm6450_ref_gnd";
		qcom,pre-scaling = <1 1>;
	};

	pm6450_vref_1p25 {
		reg = <PM6450_ADC7_1P25VREF>;
		label = "pm6450_vref_1p25";
		qcom,pre-scaling = <1 1>;
	};

	pm6450_die_temp {
		reg = <PM6450_ADC7_DIE_TEMP>;
		label = "pm6450_die_temp";
		qcom,pre-scaling = <1 1>;
	};

	pm6450_quiet_therm {
		reg = <PM6450_ADC7_AMUX1_GPIO2_100K_PU>;
		label = "pm6450_quiet_therm";
		qcom,ratiometric;
		qcom,hw-settle-time = <200>;
		qcom,pre-scaling = <1 1>;
	};
};

&pmk8350_adc_tm {
	io-channels = <&pmk8350_vadc PMK8350_ADC7_AMUX_THM1_100K_PU>,
			<&pmk8350_vadc PM6450_ADC7_AMUX1_GPIO2_100K_PU>;

	pmk8350_xo_therm {
		reg = <PMK8350_ADC7_AMUX_THM1_100K_PU>;
		qcom,ratiometric;
		qcom,hw-settle-time = <200>;
	};

	pm6450_quiet_therm {
		reg = <PM6450_ADC7_AMUX1_GPIO2_100K_PU>;
		qcom,ratiometric;
		qcom,hw-settle-time = <200>;
	};
};

&pmk8350_sdam_23 {
	adc_scaling: scaling@bf {
		reg = <0xbf 0x1>;
		bits = <0 2>;
	};
};

&pmk8350_sdam_1 {
	ufs_dev: ufs_dev@94 {
		reg = <0x94 0x1>;
		bits = <0 0>;
	};
};

&pm6450_gpios {
	key_vol_up {
		key_vol_up_default: key_vol_up_default {
			pins = "gpio1";
			function = "normal";
			input-enable;
			bias-pull-up;
			power-source = <0>;
		};
	};

	quiet_therm {
		quiet_therm_default: quiet_therm_default {
			pins = "gpio2";
			bias-high-impedance;
		};
	};

	pm8010i_reset {
		pm8010i_active: pm8010i_active {
			pins = "gpio3";
			function = "normal";
			bias-disable;
			output-high;
			power-source = <0>;
		};
	};

	pm8010j_reset {
		pm8010j_active: pm8010j_active {
			pins = "gpio4";
			function = "normal";
			bias-disable;
			output-high;
			power-source = <0>;
		};
	};
};

&pm6150l_revid {
	status = "disabled";
};

&pm6150l_4 {
	qcom,power-on@800 {
		status = "disabled";
	};
};

&pm6150l_clkdiv {
	clocks = <&rpmhcc RPMH_CXO_CLK>;
};

&pm6150l_vadc {
	pinctrl-names = "default";
	pinctrl-0 = <&ufs_therm_default &wide_rfc_therm_default>;

	pa_therm2 {
		reg = <ADC5_AMUX_THM1_100K_PU>;
		label = "pa_therm2";
		qcom,ratiometric;
		qcom,hw-settle-time = <200>;
		qcom,pre-scaling = <1 1>;
	};

	pa_therm1 {
		reg = <ADC5_AMUX_THM3_100K_PU>;
		label = "pa_therm1";
		qcom,ratiometric;
		qcom,hw-settle-time = <200>;
		qcom,pre-scaling = <1 1>;
	};

	ufs_therm {
		reg = <ADC5_GPIO1_100K_PU>;
		label = "ufs_therm";
		qcom,ratiometric;
		qcom,hw-settle-time = <200>;
		qcom,pre-scaling = <1 1>;
	};

	wide_rfc_therm {
		reg = <ADC5_GPIO3_100K_PU>;
		label = "wide_rfc_therm";
		qcom,ratiometric;
		qcom,hw-settle-time = <200>;
		qcom,pre-scaling = <1 1>;
	};
};

&pm6150l_gpios {
	ufs_therm {
		ufs_therm_default: ufs_therm_default {
			pins = "gpio5";
			bias-high-impedance;
		};
	};

	wide_rfc_therm {
		wide_rfc_therm_default: wide_rfc_therm_default {
			pins = "gpio7";
			bias-high-impedance;
		};
	};
};

&pm6150l_adc_tm {
	io-channels = <&pm6150l_vadc ADC5_AMUX_THM1_100K_PU>,
			<&pm6150l_vadc ADC5_AMUX_THM3_100K_PU>,
			<&pm6150l_vadc ADC5_GPIO1_100K_PU>,
			<&pm6150l_vadc ADC5_GPIO3_100K_PU>;

	/* Channel nodes */
	pa_therm2 {
		reg = <ADC5_AMUX_THM1_100K_PU>;
		qcom,ratiometric;
		qcom,hw-settle-time = <200>;
	};

	pa_therm1 {
		reg = <ADC5_AMUX_THM3_100K_PU>;
		qcom,ratiometric;
		qcom,hw-settle-time = <200>;
	};

	ufs_therm {
		reg = <ADC5_GPIO1_100K_PU>;
		qcom,ratiometric;
		qcom,hw-settle-time = <200>;
	};

	wide_rfc_therm {
		reg = <ADC5_GPIO3_100K_PU>;
		qcom,ratiometric;
		qcom,hw-settle-time = <200>;
	};
};

&flash_led {
	status = "ok";
	qcom,use-qti-battery-interface;
};

&pmr735a_spmi {
	reg = <6 SPMI_USID>;
};

&pmr735a_tz {
	interrupts = <0x6 0xa 0x0 IRQ_TYPE_EDGE_BOTH>;
	io-channels = <&pmk8350_vadc PMR735A_ADC7_DIE_TEMP>;
	io-channel-names = "thermal";
};

&thermal_zones {
	xo-therm {
		polling-delay-passive = <0>;
		polling-delay = <0>;
		thermal-sensors = <&pmk8350_adc_tm PMK8350_ADC7_AMUX_THM1_100K_PU>;
		trips {
			active-config0 {
				temperature = <125000>;
				hysteresis = <1000>;
				type = "passive";
			};

			active-config1 {
				temperature = <125000>;
				hysteresis = <1000>;
				type = "passive";
			};
		};
	};

	sys-therm-1 {
		polling-delay-passive = <0>;
		polling-delay = <0>;
		thermal-sensors = <&pm6150l_adc_tm ADC5_GPIO1_100K_PU>;
		trips {
			active-config0 {
				temperature = <125000>;
				hysteresis = <1000>;
				type = "passive";
			};

			active-config1 {
				temperature = <125000>;
				hysteresis = <1000>;
				type = "passive";
			};
		};
	};

	sys-therm-2 {
		polling-delay-passive = <0>;
		polling-delay = <0>;
		thermal-sensors = <&pm6150l_adc_tm ADC5_GPIO3_100K_PU>;
		trips {
			active-config0 {
				temperature = <125000>;
				hysteresis = <1000>;
				type = "passive";
			};

			active-config1 {
				temperature = <125000>;
				hysteresis = <1000>;
				type = "passive";
			};
		};
	};

	sys-therm-3 {
		polling-delay-passive = <0>;
		polling-delay = <0>;
		thermal-sensors = <&pmk8350_adc_tm PM6450_ADC7_AMUX1_GPIO2_100K_PU>;
		trips {
			active-config0 {
				temperature = <125000>;
				hysteresis = <1000>;
				type = "passive";
			};

			active-config1 {
				temperature = <125000>;
				hysteresis = <1000>;
				type = "passive";
			};
		};
	};

	sys-therm-4 {
		polling-delay-passive = <0>;
		polling-delay = <0>;
		thermal-sensors = <&pm6150l_adc_tm ADC5_AMUX_THM1_100K_PU>;
		trips {
			active-config0 {
				temperature = <125000>;
				hysteresis = <1000>;
				type = "passive";
			};

			active-config1 {
				temperature = <125000>;
				hysteresis = <1000>;
				type = "passive";
			};
		};
	};

	sys-therm-5 {
		polling-delay-passive = <0>;
		polling-delay = <0>;
		thermal-sensors = <&pm6150l_adc_tm ADC5_AMUX_THM3_100K_PU>;
		trips {
			active-config0 {
				temperature = <125000>;
				hysteresis = <1000>;
				type = "passive";
			};

			active-config1 {
				temperature = <125000>;
				hysteresis = <1000>;
				type = "passive";
			};
		};
	};
};

/*
 * Each QUP device that's a parent to PMIC must be listed as a critical device
 * to GCC
 */
&gcc {
	qcom,critical-devices = <&qupv3_se2_i2c>;
};

&qupv3_se2_i2c {
	#address-cells = <1>;
	#size-cells = <0>;
	status = "ok";

	pm8010i@8 {
		compatible = "qcom,i2c-pmic";
		reg = <0x8>;
		#address-cells = <1>;
		#size-cells = <0>;

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

		pm8010-chip@900 {
			compatible = "qcom,pm8008-chip";
			reg = <0x900>;

			PM8010I_EN: qcom,pm8008-chip-en {
				regulator-name = "pm8010i-chip-en";
			};
		};

		qcom,revid@100 {
			compatible = "qcom,qpnp-revid";
			reg = <0x100>;
		};
	};

	pm8010i@9 {
		compatible = "qcom,i2c-pmic";
		reg = <0x9>;
		#address-cells = <1>;
		#size-cells = <0>;

		qcom,pm8010i-regulator {
			compatible = "qcom,pm8010-regulator";
			#address-cells = <1>;
			#size-cells = <0>;

			pm8008_en-supply = <&PM8010I_EN>;
			vdd_l1_l2-supply = <&S8B>;
			vdd_l3_l4-supply = <&BOB>;
			vdd_l5-supply = <&BOB>;
			vdd_l6-supply = <&BOB>;
			vdd_l7-supply = <&BOB>;

			L1I: pm8010i_l1: regulator@4000 {
				reg = <0x4000>;
				regulator-name = "pm8010i_l1";
				regulator-min-microvolt = <1000000>;
				regulator-max-microvolt = <1200000>;
				qcom,min-dropout-voltage = <88000>;
				qcom,hpm-min-load = <30000>;
			};

			L2I: pm8010i_l2: regulator@4100 {
				reg = <0x4100>;
				regulator-name = "pm8010i_l2";
				regulator-min-microvolt = <950000>;
				regulator-max-microvolt = <1150000>;
				qcom,min-dropout-voltage = <64000>;
				qcom,hpm-min-load = <30000>;
			};

			L3I: pm8010i_l3: regulator@4200 {
				reg = <0x4200>;
				regulator-name = "pm8010i_l3";
				regulator-min-microvolt = <1328000>;
				regulator-max-microvolt = <3000000>;
				qcom,min-dropout-voltage = <176000>;
				qcom,hpm-min-load = <0>;
			};

			L4I: pm8010i_l4: regulator@4300 {
				reg = <0x4300>;
				regulator-name = "pm8010i_l4";
				regulator-min-microvolt = <1376000>;
				regulator-max-microvolt = <2900000>;
				qcom,min-dropout-voltage = <128000>;
				qcom,hpm-min-load = <0>;
			};

			L6I: pm8010i_l6: regulator@4500 {
				reg = <0x4500>;
				regulator-name = "pm8010i_l6";
				regulator-min-microvolt = <1376000>;
				regulator-max-microvolt = <2900000>;
				qcom,min-dropout-voltage = <128000>;
				qcom,hpm-min-load = <0>;
			};

			L7I: pm8010i_l7: regulator@4600 {
				reg = <0x4600>;
				regulator-name = "pm8010i_l7";
				regulator-min-microvolt = <1248000>;
				regulator-max-microvolt = <3000000>;
				qcom,min-dropout-voltage = <256000>;
				qcom,hpm-min-load = <0>;
			};
		};
	};

	pm8010j@c {
		compatible = "qcom,i2c-pmic";
		reg = <0xc>;
		#address-cells = <1>;
		#size-cells = <0>;

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

		pm8010-chip@900 {
			compatible = "qcom,pm8008-chip";
			reg = <0x900>;

			PM8010J_EN: qcom,pm8008-chip-en {
				regulator-name = "pm8010j-chip-en";
			};
		};

		qcom,revid@100 {
			compatible = "qcom,qpnp-revid";
			reg = <0x100>;
		};
	};

	pm8010j@d {
		compatible = "qcom,i2c-pmic";
		reg = <0xd>;
		#address-cells = <1>;
		#size-cells = <0>;

		qcom,pm8010j-regulator {
			compatible = "qcom,pm8010-regulator";
			#address-cells = <1>;
			#size-cells = <0>;

			pm8008_en-supply = <&PM8010J_EN>;
			vdd_l1_l2-supply = <&S8B>;
			vdd_l3_l4-supply = <&S8E>;
			vdd_l5-supply = <&BOB>;
			vdd_l6-supply = <&BOB>;
			vdd_l7-supply = <&BOB>;

			L1J: pm8010j_l1: regulator@4000 {
				reg = <0x4000>;
				regulator-name = "pm8010j_l1";
				regulator-min-microvolt = <950000>;
				regulator-max-microvolt = <1150000>;
				qcom,min-dropout-voltage = <48000>;
				qcom,hpm-min-load = <30000>;
			};

			L3J: pm8010j_l3: regulator@4200 {
				reg = <0x4200>;
				regulator-name = "pm8010j_l3";
				regulator-min-microvolt = <1744000>;
				regulator-max-microvolt = <1900000>;
				qcom,min-dropout-voltage = <72000>;
				qcom,hpm-min-load = <0>;
			};

			L4J: pm8010j_l4: regulator@4300 {
				reg = <0x4300>;
				regulator-name = "pm8010j_l4";
				regulator-min-microvolt = <1664000>;
				regulator-max-microvolt = <1888000>;
				qcom,min-dropout-voltage = <152000>;
				qcom,hpm-min-load = <0>;
			};

			L6J: pm8010j_l6: regulator@4500 {
				reg = <0x4500>;
				regulator-name = "pm8010j_l6";
				regulator-min-microvolt = <1376000>;
				regulator-max-microvolt = <2900000>;
				qcom,min-dropout-voltage = <128000>;
				qcom,hpm-min-load = <0>;
			};
		};
	};
};

&soc {
	display_panel_vddio: display_gpio_regulator@1 {
		compatible = "qti-regulator-fixed";
		regulator-name = "display_panel_vddio";
		regulator-min-microvolt = <1800000>;
		regulator-max-microvolt = <1800000>;
		regulator-enable-ramp-delay = <233>;
		gpio = <&pm6150l_gpios 9 0>;
		enable-active-high;
		regulator-boot-on;
		proxy-supply = <&display_panel_vddio>;
		qcom,proxy-consumer-enable;
		pinctrl-names = "default";
		pinctrl-0 = <&display_panel_vddio_default>;
	};

	display_panel_avdd: display_gpio_regulator@2 {
		compatible = "qti-regulator-fixed";
		regulator-name = "display_panel_avdd";
		regulator-min-microvolt = <5500000>;
		regulator-max-microvolt = <5500000>;
		regulator-enable-ramp-delay = <233>;
		gpio = <&pm6150l_gpios 4 0>;
		enable-active-high;
		regulator-boot-on;
		proxy-supply = <&display_panel_avdd>;
		qcom,proxy-consumer-enable;
		pinctrl-names = "default";
		pinctrl-0 = <&display_panel_avdd_default>;
	};

	display_panel_extvdd: display_gpio_regulator@3 {
		compatible = "qti-regulator-fixed";
		regulator-name = "display_panel_extvdd";
		regulator-min-microvolt = <1200000>;
		regulator-max-microvolt = <1200000>;
		regulator-enable-ramp-delay = <233>;
		gpio = <&pm6150l_gpios 3 0>;
		enable-active-high;
		regulator-boot-on;
		proxy-supply = <&display_panel_extvdd>;
		qcom,proxy-consumer-enable;
		pinctrl-names = "default";
		pinctrl-0 = <&display_panel_extvdd_default>;
	};

	display_panel_ibb: display_panel_ibb_stub {
		compatible = "qcom,stub-regulator";
		regulator-name = "display_panel_ibb";
		regulator-min-microvolt = <4600000>;
		regulator-max-microvolt = <6000000>;
	};
};

&pm6150l_gpios {
	display_panel_supply_ctrl {
		display_panel_vddio_default: display_panel_vddio_default {
			pins = "gpio9";
			function = "normal";
			input-disable;
			output-enable;
			bias-disable;
			power-source = <0>;
			qcom,drive-strength = <2>;
		};

		display_panel_avdd_default: display_panel_avdd_default {
			pins = "gpio4";
			function = "normal";
			input-disable;
			output-enable;
			bias-disable;
			power-source = <0>;
			qcom,drive-strength = <2>;
		};

		display_panel_extvdd_default: display_panel_extvdd_default {
			pins = "gpio3";
			function = "normal";
			input-disable;
			output-enable;
			bias-disable;
			power-source = <0>;
			qcom,drive-strength = <2>;
		};
	};

	lcd_backlight_ctrl {
		lcd_backlight_en_default: lcd_backlight_en_default {
			pins = "gpio10";
			function = "normal";
			input-disable;
			output-enable;
			bias-disable;
			power-source = <0>;
			qcom,drive-strength = <2>;
		};
	};
};

&pm6450_gpios {
	lcd_backlight_ctrl {
		lcd_backlight_pwm_default: lcd_backlight_pwm_default {
			pins = "gpio7";
			function = "func1";
			input-disable;
			output-enable;
			bias-disable;
			power-source = <1>;       /* 1.8V */
			qcom,drive-strength = <2>;
		};
	};
};
