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

#include "pmxr2230.dtsi"
#include "pm8550b.dtsi"
#include "pm8550ve.dtsi"
#include "pm8550vs.dtsi"
#include "pmk8550.dtsi"

&pm8550vs_c {
	status = "ok";
};

&pm8550vs_d {
	status = "ok";
};

&pm8550vs_c_temp_alarm {
	status = "ok";
};

&pm8550vs_d_temp_alarm {
	status = "ok";
};

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

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

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

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

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

&pm8550b_gpios {
	key_confirm {
		key_confirm_default: key_confirm_default {
			pins = "gpio2";
			function = "normal";
			input-enable;
			bias-pull-up;
			power-source = <1>;
		};
	};

	key_back {
		key_back_default: key_back_default {
			pins = "gpio6";
			function = "normal";
			input-enable;
			bias-pull-up;
			power-source = <1>;
		};
	};

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

&pm8550ve_f_gpios {
	pwr_en_gpio {
		pwr_en_gpio_default: pwr_en_gpio_default {
			pins = "gpio6";
			function = "normal";
			power-source = <0>;
			output-low;
			input-disable;
		};
	};

	driver_en_gpio {
		driver_en_gpio_default: driver_en_gpio_default {
			pins = "gpio5";
			function = "normal";
			power-source = <0>;
			output-low;
			input-disable;
		};
	};
};

&pmk8550_sdam_1 {
	ufs_dev: ufs_dev@af {
		reg = <0xaf 0x1>;
		bits = <4 4>;
	};
};

&pmxr2230_tz {
	io-channels = <&pmk8550_vadc PMXR2230_ADC5_GEN3_DIE_TEMP>;
	io-channel-names = "thermal";
};

&pm8550b_tz {
	io-channels = <&pmk8550_vadc PM8550B_ADC5_GEN3_DIE_TEMP>;
	io-channel-names = "thermal";
};

&pm8550b_lite_tz {
	io-channels = <&pmk8550_vadc PM8550B_ADC5_GEN3_TEMP_ALARM_LITE>;
	io-channel-names = "thermal";
};

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

&pm8550ve_f_tz {
	io-channels = <&pmk8550_vadc PM8550VE_ADC5_GEN3_DIE_TEMP>;
	io-channel-names = "thermal";
};

&pmxr2230_flash {
	qcom,external-led;
	pinctrl-names = "default";
	pinctrl-0 = <&ext_flash_default>;
};

&pmxr2230_gpios {
	flash_default {
		ext_flash_default: ext_flash_default {
			pins = "gpio2";
			function = "normal";
			input-enable;
			output-disable;
			bias-disable;
			power-source = <1>;
		};
	};

	pmxr2230_sd_card_therm {
		pmxr2230_sd_card_therm_default: pmxr2230_sd_card_therm_default {
			pins = "gpio3";
			bias-high-impedance;
		};
	};

	pmxr2230_optics_therm {
		pmxr2230_optics_therm_default: pmxr2230_optics_therm_default {
			pins = "gpio4";
			bias-high-impedance;
		};
	};
};

&pmk8550_vadc {
	pinctrl-names = "default";
	pinctrl-0 = <&pmxr2230_sd_card_therm_default &pmxr2230_optics_therm_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;

	/* 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_soc_therm {
		reg = <PMXR2230_ADC5_GEN3_AMUX_THM1_100K_PU>;
		label = "pmxr2230_soc_therm";
		qcom,ratiometric;
		qcom,hw-settle-time = <200>;
		qcom,pre-scaling = <1 1>;
		qcom,adc-tm-type = <1>;
	};

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

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

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

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

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

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

	pm8550b_chg_temp {
		reg = <PM8550B_ADC5_GEN3_CHG_TEMP>;
		label = "pm8550b_chg_temp";
	};

	pm8550b_iin_fb {
		reg = <PM8550B_ADC5_GEN3_IIN_FB>;
		label = "pm8550b_iin_fb";
	};

	pm8550b_ichg_fb {
		reg = <PM8550B_ADC5_GEN3_ICHG_FB>;
		label = "pm8550b_ichg_fb";
	};

	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 {
	pm8010m_tz {
		polling-delay-passive = <100>;
		polling-delay = <0>;
		thermal-governor = "step_wise";
		thermal-sensors = <&pm8010m_tz>;

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

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

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

	pm8010n_tz {
		polling-delay-passive = <100>;
		polling-delay = <0>;
		thermal-governor = "step_wise";
		thermal-sensors = <&pm8010n_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-0 {
		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";
			};
		};
	};

	sys-therm-1 {
		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";
			};

			fan_config0: fan-config0 {
				temperature = <70000>;
				hysteresis = <1000>;
				type = "passive";
			};
		};
	};

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

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

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

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

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

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

&pm8550b_haptics {
	nvmem-names = "hap_cfg_sdam";
	nvmem = <&pmk8550_sdam_46>;
};

&pmk8550_pwrkey {
	qcom,log-kpd-event;
};

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

&qupv3_se2_i2c {
	status = "ok";

	fancontroller: max31760@50 {
		compatible = "maxim,max31760";
		#cooling-cells = <2>;
		reg = <0x50>;
		maxim,fan-num = <2>;
		pinctrl-names = "default";
		pinctrl-0 = <&pwr_en_gpio_default
			&driver_en_gpio_default>;
		maxim,driver-en-gpio = <&pm8550ve_f_gpios 5 GPIO_ACTIVE_LOW>;
		maxim,pwr-en-gpio = <&pm8550ve_f_gpios 6 GPIO_ACTIVE_LOW>;
		status = "ok";
	};
};

&pmk8550_gpios {
	imu_clk {
		imu_clkin_default: imu_clkin_default {
			pins = "gpio3";
			function = "func1";
			input-disable;
			output-enable;
			power-source = <0>;
			qcom,drive-strength = <3>;
		};
	};
};
