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

#include "pmk8350.dtsi"
#include "pm6450.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 &wide_rfc_therm_default
			&rear_cam_flash_therm_default &pa_therm2_default &pa_therm1_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;

	/delete-node/ pmr735a_ref_gnd;
	/delete-node/ pmr735a_vref_1p25;
	/delete-node/ pmr735a_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_wide_rfc_therm {
		reg = <PMK8350_ADC7_AMUX_THM2_100K_PU>;
		label = "pmk8350_wide_rfc_therm";
		qcom,ratiometric;
		qcom,hw-settle-time = <200>;
		qcom,pre-scaling = <1 1>;
	};

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

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

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

&spmi_bus {
	#address-cells = <2>;
	#size-cells = <0>;
	interrupt-controller;
	#interrupt-cells = <4>;

	pm8010_e: qcom,pm8010@4 {
		compatible = "qcom,spmi-pmic";
		reg = <4 SPMI_USID>;
		#address-cells = <1>;
		#size-cells = <0>;

		pm8010e_tz: pm8010-e-temp-alarm@2400 {
			compatible = "qcom,spmi-temp-alarm";
			reg = <0x2400>;
			interrupts = <0x4 0x24 0x0 IRQ_TYPE_EDGE_BOTH>;
			#thermal-sensor-cells = <0>;
		};
	};
};

&pmk8350_adc_tm {
	io-channels = <&pmk8350_vadc PMK8350_ADC7_AMUX_THM1_100K_PU>,
			<&pmk8350_vadc PM6450_ADC7_AMUX1_GPIO2_100K_PU>,
			<&pmk8350_vadc PMK8350_ADC7_AMUX_THM2_100K_PU>,
			<&pmk8350_vadc PM6450_ADC7_AMUX4_GPIO5_100K_PU>,
			<&pmk8350_vadc PM6450_ADC7_AMUX3_GPIO4_100K_PU>,
			<&pmk8350_vadc PMK8350_ADC7_AMUX_THM3_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_wide_rfc_therm {
		reg = <PMK8350_ADC7_AMUX_THM2_100K_PU>;
		qcom,ratiometric;
		qcom,hw-settle-time = <200>;
	};

	pm6450_rear_cam_flash_therm {
		reg = <PM6450_ADC7_AMUX4_GPIO5_100K_PU>;
		qcom,ratiometric;
		qcom,hw-settle-time = <200>;
	};

	pm6450_pa2_therm {
		reg = <PM6450_ADC7_AMUX3_GPIO4_100K_PU>;
		qcom,ratiometric;
		qcom,hw-settle-time = <200>;
	};

	pmk8350_pa1_therm {
		reg = <PMK8350_ADC7_AMUX_THM3_100K_PU>;
		qcom,ratiometric;
		qcom,hw-settle-time = <200>;
	};
};

&pmk8350_gpios {
	wide_rfc_therm {
		wide_rfc_therm_default: wide_rfc_therm_default {
			pins = "gpio1";
			bias-high-impedance;
		};
	};

	 pa_therm1 {
		pa_therm1_default: pa_therm1_default {
			pins = "gpio2";
			bias-high-impedance;
		};
	};
};

&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 {
	quiet_therm {
		quiet_therm_default: quiet_therm_default {
			pins = "gpio2";
			bias-high-impedance;
		};
	};

	rear_cam_flash_therm {
		rear_cam_flash_therm_default: rear_cam_flash_therm_default {
			pins = "gpio5";
			bias-high-impedance;
		};
	};

	pa_therm2 {
		pa_therm2_default: pa_therm2_default {
			pins = "gpio4";
			bias-high-impedance;
		};
	};

};

&thermal_zones {
	pm8010e_tz {
		polling-delay-passive = <100>;
		polling-delay = <0>;
		thermal-governor = "step_wise";
		thermal-sensors = <&pm8010e_tz>;

		trips {
			trip0 {
				temperature = <95000>;
				hysteresis = <0>;
				type = "passive";
			};

			trip1 {
				temperature = <115000>;
				hysteresis = <0>;
				type = "passive";
			};

			trip2 {
				temperature = <145000>;
				hysteresis = <0>;
				type = "critical";
			};
		};
	};

	sys-therm-6 {
		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-4 {
		polling-delay-passive = <0>;
		polling-delay = <0>;
		thermal-sensors = <&pmk8350_adc_tm PMK8350_ADC7_AMUX_THM2_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 = <&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-3 {
		polling-delay-passive = <0>;
		polling-delay = <0>;
		thermal-sensors = <&pmk8350_adc_tm PM6450_ADC7_AMUX4_GPIO5_100K_PU>;
		trips {
			active-config0 {
				temperature = <125000>;
				hysteresis = <1000>;
				type = "passive";
			};

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

	sys-therm-11 {
		polling-delay-passive = <0>;
		polling-delay = <0>;
		thermal-sensors = <&pmk8350_adc_tm PM6450_ADC7_AMUX3_GPIO4_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 = <&pmk8350_adc_tm PMK8350_ADC7_AMUX_THM3_100K_PU>;
		trips {
			active-config0 {
				temperature = <125000>;
				hysteresis = <1000>;
				type = "passive";
			};

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

&tlmm {
	key_vol_up_default: key_vol_up_default {
		mux {
			pins = "gpio53";
			function = "gpio";
		};

		config {
			pins = "gpio53";
			drive-strength = <2>;
			bias-pull-up;
			input-enable;
		};
	};

	pm8010m_active: pm8010m-active {
		mux {
			pins = "gpio29";
			function = "gpio";
		};

		config {
			pins = "gpio29";
			bias-pull-up;
			output-high;
			drive-strength = <2>;
		};
	};

	pm8010n_active: pm8010n-active {
		mux {
			pins = "gpio30";
			function = "gpio";
		};

		config {
			pins = "gpio30";
			bias-pull-up;
			output-high;
			drive-strength = <2>;
		};
	};
};

&soc {
	 gpio_keys {
		compatible = "gpio-keys";
		label = "gpio-keys";

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

		vol_up {
			label = "volume_up";
			gpios = <&tlmm 53 GPIO_ACTIVE_LOW>;
			linux,input-type = <1>;
			linux,code = <KEY_VOLUMEUP>;
			gpio-key,wakeup;
			debounce-interval = <15>;
			linux,can-disable;
		};
	};
};

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

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

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

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

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

			PM8010M_EN: qcom,pm8008-chip-en {
				regulator-name = "pm8010m-chip-en";
			};
		};

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

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

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

			pm8008_en-supply = <&PM8010M_EN>;
			vdd_l1_l2-supply = <&S8B>;

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

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

			L3M: pm8010m_l3: regulator@4200 {
				reg = <0x4200>;
				regulator-name = "pm8010m_l3";
				regulator-min-microvolt = <2800000>;
				regulator-max-microvolt = <3000000>;
				qcom,hpm-min-load = <0>;
			};

			L4M: pm8010m_l4: regulator@4300 {
				reg = <0x4300>;
				regulator-name = "pm8010m_l4";
				regulator-min-microvolt = <2700000>;
				regulator-max-microvolt = <2900000>;
				qcom,hpm-min-load = <0>;
			};

			L6M: pm8010m_l6: regulator@4500 {
				reg = <0x4500>;
				regulator-name = "pm8010m_l6";
				regulator-min-microvolt = <2700000>;
				regulator-max-microvolt = <3000000>;
				qcom,hpm-min-load = <0>;
			};

			L7M: pm8010m_l7: regulator@4600 {
				reg = <0x4600>;
				regulator-name = "pm8010m_l7";
				regulator-min-microvolt = <2650000>;
				regulator-max-microvolt = <2950000>;
				qcom,hpm-min-load = <0>;
			};
		};
	};

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

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

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

			PM8010N_EN: qcom,pm8008-chip-en {
				regulator-name = "pm8010n-chip-en";
			};
		};

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

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

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

			pm8008_en-supply = <&PM8010N_EN>;
			vdd_l1_l2-supply = <&S8B>;
			vdd_l3_l4-supply = <&S9B>;

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

			L3N: pm8010n_l3: regulator@4200 {
				reg = <0x4200>;
				regulator-name = "pm8010n_l3";
				regulator-min-microvolt = <1736000>;
				regulator-max-microvolt = <3312000>;
				qcom,hpm-min-load = <0>;
				qcom,min-dropout-voltage = <120000>;
			};

			L4N: pm8010n_l4: regulator@4300 {
				reg = <0x4300>;
				regulator-name = "pm8010N_l4";
				regulator-min-microvolt = <1704000>;
				regulator-max-microvolt = <1900000>;
				qcom,hpm-min-load = <0>;
				qcom,min-dropout-voltage = <152000>;
			};

			L6N: pm8010n_l6: regulator@4500 {
				reg = <0x4500>;
				regulator-name = "pm8010n_l6";
				regulator-min-microvolt = <2700000>;
				regulator-max-microvolt = <3000000>;
				qcom,hpm-min-load = <0>;
			};
		};
	};
};

&pm6450_pwm_1 {
	status = "ok";
};

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

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