#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/pinctrl/qcom,pmic-gpio.h>
#include <dt-bindings/iio/qcom,spmi-adc5-gen3-pmxr2230.h>
#include <dt-bindings/iio/qcom,spmi-adc5-gen3-smb139x.h>

#define PMR735A_SID 0x5

#include "pmk8550.dtsi"
#include "pmxr2230.dtsi"
#include "pm8550vs.dtsi"
#include "pmr735d.dtsi"
#include "pmr735a.dtsi"
#include "pm8010.dtsi"

/* Set SID from 0xa to 0x4 for pmr735d */
&pmr735d_k {
	reg = <0x4 SPMI_USID>;
};

&pmr735d_k_tz {
	interrupts = <0x4 0xa 0x0 IRQ_TYPE_EDGE_BOTH>;
};


/* Disable the second instance */
&pmr735d_l {
	status  = "disabled";
};

&pmr735d_l_temp_alarm {
	status  = "disabled";
};

/* Set SID from 0x4 to 0x5 for pmr735d */
&pmr735a {
	reg = <0x5 SPMI_USID>;
};

&pmr735a_tz {
	interrupts = <0x5 0xa 0x0 IRQ_TYPE_EDGE_BOTH>;
};

&pm8550vs_d {
	status = "ok";
};

&pm8550vs_d_temp_alarm {
	status = "ok";
};

&pmxr2230_gpios {
	key_vol_up {
		key_vol_up_default: key_vol_up_default {
			pins = "gpio6";
			function = "normal";
			input-enable;
			bias-pull-up;
			power-source = <1>;
		};
	};

	sys_therm_2_gpio7 {
		sys_therm_2_gpio7_default: sys_therm_2_gpio7_default {
			pins = "gpio7";
			bias-high-impedance;
		};
	};
};

&pmk8550_gpios {
	pinctrl-0 = <&alt_sleep_clk_default>;
	pinctrl-names = "default";

	alt_sleep_clk {
		alt_sleep_clk_default: alt_sleep_clk_default {
			pins = "gpio3";
			function = "func1";
			input-disable;
			output-enable;
			bias-disable;
			power-source = <0>;
		};
	};
};

&pm8550vs_c_tz {
	io-channels = <&pmk8550_vadc PM8550VS_C_ADC5_GEN3_DIE_TEMP>;
	io-channel-names = "thermal";
};

&pm8550vs_d_tz {
	io-channels = <&pmk8550_vadc PM8550VS_D_ADC5_GEN3_DIE_TEMP>;
	io-channel-names = "thermal";
};

&pmk8550_vadc {
	pinctrl-names = "default";
	pinctrl-0 = <&sys_therm_2_gpio7_default>;

	/delete-node/ pm8550_offset_ref;
	/delete-node/ pm8550_vref_1p25;
	/delete-node/ pm8550_die_temp;
	/delete-node/ pm8550_vph_pwr;

	/delete-node/ pm8550vs_e_die_temp;
	/delete-node/ pm8550vs_g_die_temp;

	/delete-node/ pm8550ve_die_temp;

	/* PMXR2230 Channel nodes */
	pmxr2230_offset_ref {
		reg = <PMXR2230_ADC5_GEN3_OFFSET_REF>;
		label = "pmxr2230_offset_ref";
		qcom,pre-scaling = <1 1>;
	};

	pmxr2230_vref_1p25 {
		reg = <PMXR2230_ADC5_GEN3_1P25VREF>;
		label = "pmxr2230_vref_1p25";
		qcom,pre-scaling = <1 1>;
	};

	pmxr2230_die_temp {
		reg = <PMXR2230_ADC5_GEN3_DIE_TEMP>;
		label = "pmxr2230_die_temp";
		qcom,pre-scaling = <1 1>;
	};

	pmxr2230_vph_pwr {
		reg = <PMXR2230_ADC5_GEN3_VPH_PWR>;
		label = "pmxr2230_vph_pwr";
		qcom,pre-scaling = <1 3>;
	};

	pmxr2230_sys_therm_1 {
		reg = <PMXR2230_ADC5_GEN3_AMUX_THM2_100K_PU>;
		label = "pmxr2230_sys_therm_1";
		qcom,ratiometric;
		qcom,hw-settle-time = <200>;
		qcom,pre-scaling = <1 1>;
		qcom,adc-tm-type = <1>;
	};

	pmxr2230_sys_therm_2 {
		reg = <PMXR2230_ADC5_GEN3_AMUX3_GPIO7_100K_PU>;
		label = "pmxr2230_sys_therm_2";
		qcom,ratiometric;
		qcom,hw-settle-time = <200>;
		qcom,pre-scaling = <1 1>;
		qcom,adc-tm-type = <1>;
	};

	pmxr2230_sys_therm_3 {
		reg = <PMXR2230_ADC5_GEN3_AMUX_THM4_100K_PU>;
		label = "pmxr2230_sys_therm_3";
		qcom,ratiometric;
		qcom,hw-settle-time = <200>;
		qcom,pre-scaling = <1 1>;
		qcom,adc-tm-type = <1>;
	};

	pmxr2230_sys_therm_4 {
		reg = <PMXR2230_ADC5_GEN3_AMUX_THM3_100K_PU>;
		label = "pmxr2230_sys_therm_4";
		qcom,ratiometric;
		qcom,hw-settle-time = <200>;
		qcom,pre-scaling = <1 1>;
		qcom,adc-tm-type = <1>;
	};

	pmxr2230_sys_therm_5 {
		reg = <PMXR2230_ADC5_GEN3_AMUX_THM1_100K_PU>;
		label = "pmxr2230_sys_therm_5";
		qcom,ratiometric;
		qcom,hw-settle-time = <200>;
		qcom,pre-scaling = <1 1>;
		qcom,adc-tm-type = <1>;
	};

	smb139x_1_smb_temp {
		reg = <SMB1394_1_ADC5_GEN3_SMB_TEMP>;
		label = "smb139x_1_smb_temp";
	};

	smb139x_1_iin_smb {
		reg = <SMB1394_1_ADC5_GEN3_IIN_SMB>;
		label = "smb139x_1_iin_smb";
	};

	smb139x_1_ichg_smb {
		reg = <SMB1394_1_ADC5_GEN3_ICHG_SMB>;
		label = "smb139x_1_ichg_smb";
	};

	smb139x_2_smb_temp {
		reg = <SMB1394_2_ADC5_GEN3_SMB_TEMP>;
		label = "smb139x_2_smb_temp";
	};

	smb139x_2_iin_smb {
		reg = <SMB1394_2_ADC5_GEN3_IIN_SMB>;
		label = "smb139x_2_iin_smb";
	};

	smb139x_2_ichg_smb {
		reg = <SMB1394_2_ADC5_GEN3_ICHG_SMB>;
		label = "smb139x_2_ichg_smb";
	};
};

&thermal_zones {

	sys-therm-1 {

		polling-delay-passive = <0>;
		polling-delay = <0>;
		thermal-sensors = <&pmk8550_vadc PMXR2230_ADC5_GEN3_AMUX_THM2_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 = <&pmk8550_vadc PMXR2230_ADC5_GEN3_AMUX3_GPIO7_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 = <&pmk8550_vadc PMXR2230_ADC5_GEN3_AMUX_THM4_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 = <&pmk8550_vadc PMXR2230_ADC5_GEN3_AMUX_THM3_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 = <&pmk8550_vadc PMXR2230_ADC5_GEN3_AMUX_THM1_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 = <&pmk8550_vadc PMK8550_ADC5_GEN3_AMUX_THM1_XO_THERM_100K_PU>;
		trips {
			active-config0 {
				temperature = <125000>;
				hysteresis = <1000>;
				type = "passive";
			};

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

			display_test_config1: display-test-config1 {
				temperature = <125000>;
				hysteresis = <1000>;
				type = "passive";
			};

			display_test_config2: display-test-config2 {
				temperature = <125000>;
				hysteresis = <1000>;
				type = "passive";
			};

			display_test_config3: display-test-config3 {
				temperature = <125000>;
				hysteresis = <1000>;
				type = "passive";
			};
		};
	};
};

&pmk8550_sdam_1 {
	ufs_dev: ufs_dev@ad {
		reg = <0xad 0x1>;
		bits = <0 0>;
	};
};

&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 = <&pmk8550_sdam_5>, <&pmk8550_sdam_6>;
		nvmem-names = "pon_log0", "pon_log1";
	};

	regulator_ocp_notifier: regulator-ocp-notifier {
		compatible = "qcom,regulator-ocp-notifier";
		interrupt-parent = <&spmi_bus>;
		interrupts = <0x0 0x71 0x1 IRQ_TYPE_EDGE_RISING>;
		nvmem-cells = <&ocp_log>;
		nvmem-cell-names = "ocp_log";
	};
};
