#include <dt-bindings/interrupt-controller/irq.h>
#include <dt-bindings/spmi/spmi.h>
#include <dt-bindings/iio/qcom,spmi-vadc.h>

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

	pmi632_2: qcom,pmi632@2 {
		compatible = "qcom,spmi-pmic";
		reg = <2 SPMI_USID>;
		#address-cells = <1>;
		#size-cells = <0>;

		pmi632_pon: qcom,power-on@800 {
			compatible = "qcom,qpnp-power-on";
			reg = <0x800>;
		};

		pmi632_vadc: vadc@3100 {
			compatible = "qcom,spmi-adc5-lite";
			reg = <0x3100>;
			#address-cells = <1>;
			#size-cells = <0>;
			interrupts = <0x2 0x31 0x0 IRQ_TYPE_EDGE_RISING>;
			interrupt-names = "eoc-int-en-set";
			#io-channel-cells = <1>;
			io-channel-ranges;

			/* Channel nodes */
			ref_gnd {
				reg = <ADC5_REF_GND>;
				label = "ref_gnd";
				qcom,pre-scaling = <1 1>;
			};

			vref_1p25 {
				reg = <ADC5_1P25VREF>;
				label = "vref_1p25";
				qcom,pre-scaling = <1 1>;
			};

			die_temp {
				reg = <ADC5_DIE_TEMP>;
				label = "die_temp";
				qcom,pre-scaling = <1 1>;
			};

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

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

			usb_in_i_uv {
				reg = <ADC5_USB_IN_I>;
				label = "usb_in_i_uv";
				qcom,pre-scaling = <1 1>;
			};

			chg_temp {
				reg = <ADC5_CHG_TEMP>;
				label = "chg_temp";
				qcom,pre-scaling = <1 1>;
			};

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

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

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

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

			i_parallel {
				reg = <ADC5_PARALLEL_ISENSE>;
				label = "i_parallel";
				qcom,pre-scaling = <1 1>;
			};
		};

		pmi632_adc_tm: adc_tm@3500 {
			compatible = "qcom,adc-tm5";
			reg = <0x3500>;
			interrupts = <0x2 0x35 0x0 IRQ_TYPE_EDGE_RISING>;
			interrupt-names = "threshold";
			#address-cells = <1>;
			#size-cells = <0>;
			#thermal-sensor-cells = <1>;
		};

		pmi632_tz: qcom,temp-alarm@2400 {
			compatible = "qcom,spmi-temp-alarm";
			reg = <0x2400>;
			interrupts = <0x2 0x24 0x0 IRQ_TYPE_EDGE_BOTH>;
			io-channels = <&pmi632_vadc ADC5_DIE_TEMP>;
			io-channel-names = "thermal";
			#thermal-sensor-cells = <0>;
		};

		qcom,schgm-flash@a600 {
			compatible = "qcom,schgm-flash";
			reg = <0xa600>;
			interrupts = <0x2 0xa6 0x2 IRQ_TYPE_EDGE_RISING>,
				     <0x2 0xa6 0x6 IRQ_TYPE_EDGE_RISING>;
			interrupt-names = "flash-state-change",
				     "ilim2-s2";
			qcom,flash-disable-soc = <10>;
		};

		pmi632_gpios: pinctrl@c000 {
			compatible = "qcom,pmi632-gpio";
			reg = <0xc000>;
			gpio-controller;
			#gpio-cells = <2>;
			interrupt-controller;
			#interrupt-cells = <2>;
		};

		pmi632_pbs_client3: qcom,pbs@7400 {
			compatible = "qcom,qpnp-pbs";
			reg = <0x7400>;
		};

		pmi632_sdam7: qcom,sdam@b600 {
			compatible = "qcom,spmi-sdam";
			reg = <0xb600>;
		};

		pmi632_bcl: bcl@3d00 {
			compatible = "qcom,bcl-v5";
			reg = <0x3d00>;
			interrupts = <0x2 0x3d 0x0 IRQ_TYPE_NONE>,
					<0x2 0x3d 0x1 IRQ_TYPE_NONE>,
					<0x2 0x3d 0x2 IRQ_TYPE_NONE>;
			interrupt-names = "bcl-lvl0",
						"bcl-lvl1",
						"bcl-lvl2";
			qcom,ibat-use-qg-adc-5a;
			#thermal-sensor-cells = <1>;
		};

		bcl_soc: bcl-soc {
			compatible = "qcom,msm-bcl-soc";
			#thermal-sensor-cells = <0>;
		};
	};

	pmi632_3: qcom,pmi632@3 {
		compatible ="qcom,spmi-pmic";
		reg = <3 SPMI_USID>;
		#address-cells = <1>;
		#size-cells = <0>;

		pmi632_vib: qcom,vibrator@5700 {
			compatible = "qcom,qpnp-vibrator-ldo";
			reg = <0x5700>;
			qcom,vib-ldo-volt-uv = <3000000>;
			qcom,disable-overdrive;
		};

		pmi632_pwm: qcom,pwms@b300 {
			compatible = "qcom,pwm-lpg";
			reg = <0xb300>;
			reg-names = "lpg-base";
			#pwm-cells = <2>;
			qcom,num-lpg-channels = <5>;
			nvmem-names = "ppg_sdam";
			nvmem = <&pmi632_sdam7>;
			qcom,pbs-client = <&pmi632_pbs_client3>;
			qcom,lut-sdam-base = <0x80>;
			qcom,lut-patterns = <0 0 0 14 28 42 56 70 84 100
						100 84 70 56 42 28 14 0 0 0>;
			lpg@1 {
				qcom,lpg-chan-id = <1>;
				qcom,ramp-step-ms = <200>;
				qcom,ramp-low-index = <0>;
				qcom,ramp-high-index = <19>;
				qcom,ramp-pattern-repeat;
				qcom,lpg-sdam-base = <0x48>;
			};

			lpg@2 {
				qcom,lpg-chan-id = <2>;
				qcom,ramp-step-ms = <200>;
				qcom,ramp-low-index = <0>;
				qcom,ramp-high-index = <19>;
				qcom,ramp-pattern-repeat;
				qcom,lpg-sdam-base = <0x56>;
			};

			lpg@3 {
				qcom,lpg-chan-id = <3>;
				qcom,ramp-step-ms = <200>;
				qcom,ramp-low-index = <0>;
				qcom,ramp-high-index = <19>;
				qcom,ramp-pattern-repeat;
				qcom,lpg-sdam-base = <0x64>;
			};
		};

		pmi632_rgb: qcom,leds@d000 {
			compatible = "qcom,tri-led";
			reg = <0xd000>;
			red {
				label = "red";
				pwms = <&pmi632_pwm 0 1000000>;
				led-sources = <0>;
				linux,default-trigger = "timer";
			};

			green {
				label = "green";
				pwms = <&pmi632_pwm 1 1000000>;
				led-sources = <1>;
				linux,default-trigger = "timer";
			};

			blue {
				label = "blue";
				pwms = <&pmi632_pwm 2 1000000>;
				led-sources = <2>;
				linux,default-trigger = "timer";
			};
		};

		pmi632_lcdb: qpnp-lcdb@ec00 {
			status = "disabled";
			compatible = "qcom,lcdb-pmi632";
			#address-cells = <1>;
			#size-cells = <0>;
			reg = <0xec00>;
			interrupts = <0x3 0xec 0x1 IRQ_TYPE_EDGE_RISING>;
			interrupt-names = "sc-irq";

			qcom,voltage-step-ramp;

			lcdb_ldo_vreg: ldo {
				label = "ldo";
				regulator-name = "lcdb_ldo";
				regulator-min-microvolt = <4000000>;
				regulator-max-microvolt = <6000000>;
			};

			lcdb_ncp_vreg: ncp {
				label = "ncp";
				regulator-name = "lcdb_ncp";
				regulator-min-microvolt = <4000000>;
				regulator-max-microvolt = <6000000>;
			};

			lcdb_bst_vreg: bst {
				label = "bst";
				regulator-name = "lcdb_bst";
				regulator-min-microvolt = <4700000>;
				regulator-max-microvolt = <6275000>;
			};
		};

		flash_led: qcom,leds@d300 {
			compatible = "qcom,pmi632-flash-led-v2";
			reg = <0xd300>;
			label = "flash";
			interrupts = <0x3 0xd3 0x0 IRQ_TYPE_EDGE_RISING>,
				     <0x3 0xd3 0x3 IRQ_TYPE_EDGE_RISING>,
				     <0x3 0xd3 0x4 IRQ_TYPE_EDGE_RISING>;
			interrupt-names = "led-fault-irq",
					  "all-ramp-down-done-irq",
					  "all-ramp-up-done-irq";
			qcom,short-circuit-det;
			qcom,open-circuit-det;
			qcom,vph-droop-det;
			qcom,thermal-derate-en;
			qcom,thermal-derate-current = <200 500 1000>;
			qcom,isc-delay = <192>;

			pmi632_flash0: qcom,flash_0 {
				label = "flash";
				qcom,led-name = "led:flash_0";
				qcom,max-current = <1500>;
				qcom,default-led-trigger = "flash0_trigger";
				qcom,id = <0>;
				qcom,current-ma = <1000>;
				qcom,duration-ms = <1280>;
				qcom,ires-ua = <12500>;
				qcom,hdrm-voltage-mv = <400>;
				qcom,hdrm-vol-hi-lo-win-mv = <100>;
			};

			pmi632_flash1: qcom,flash_1 {
				label = "flash";
				qcom,led-name = "led:flash_1";
				qcom,max-current = <1500>;
				qcom,default-led-trigger = "flash1_trigger";
				qcom,id = <1>;
				qcom,current-ma = <1000>;
				qcom,duration-ms = <1280>;
				qcom,ires-ua = <12500>;
				qcom,hdrm-voltage-mv = <400>;
				qcom,hdrm-vol-hi-lo-win-mv = <100>;
			};

			pmi632_torch0: qcom,torch_0 {
				label = "torch";
				qcom,led-name = "led:torch_0";
				qcom,max-current = <500>;
				qcom,default-led-trigger = "torch0_trigger";
				qcom,id = <0>;
				qcom,current-ma = <300>;
				qcom,ires-ua = <12500>;
				qcom,hdrm-voltage-mv = <400>;
				qcom,hdrm-vol-hi-lo-win-mv = <100>;
			};

			pmi632_torch1: qcom,torch_1 {
				label = "torch";
				qcom,led-name = "led:torch_1";
				qcom,max-current = <500>;
				qcom,default-led-trigger = "torch1_trigger";
				qcom,id = <1>;
				qcom,current-ma = <300>;
				qcom,ires-ua = <12500>;
				qcom,hdrm-voltage-mv = <400>;
				qcom,hdrm-vol-hi-lo-win-mv = <100>;
			};

			pmi632_switch0: qcom,led_switch_0 {
				label = "switch";
				qcom,led-name = "led:switch_0";
				qcom,led-mask = <3>;
				qcom,default-led-trigger = "switch0_trigger";
			};

			pmi632_switch1: qcom,led_switch_1 {
				label = "switch";
				qcom,led-name = "led:switch_1";
				qcom,led-mask = <2>;
				qcom,default-led-trigger = "switch1_trigger";
			};

		};

	};
};

&thermal_zones {
	pmi632-tz {
		polling-delay-passive = <100>;
		polling-delay = <0>;
		thermal-sensors = <&pmi632_tz>;

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

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

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

	pmi632-ibat-lvl0 {
		polling-delay-passive = <0>;
		polling-delay = <0>;
		thermal-sensors = <&pmi632_bcl 0>;

		trips {
				ibat_lvl0: ibat-lvl0 {
				temperature = <4000>;
				hysteresis = <200>;
				type = "passive";
			};
		};
	};

	pmi632-ibat-lvl1 {
		polling-delay-passive = <0>;
		polling-delay = <0>;
		thermal-sensors = <&pmi632_bcl 1>;

		trips {
				ibat_lvl1: ibat-lvl1 {
				temperature = <5000>;
				hysteresis = <200>;
				type = "passive";
			};
		};
	};

	pmi632-bcl-lvl0 {
		polling-delay-passive = <100>;
		polling-delay = <0>;
		thermal-sensors = <&pmi632_bcl 5>;

		trips {
			thermal-engine-trip {
				temperature = <100>;
				hysteresis = <0>;
				type = "passive";
			};

			thermal-hal-trip {
				temperature = <100>;
				hysteresis = <0>;
				type = "passive";
			};

			b_bcl_lvl0: b-bcl-lvl0 {
				temperature = <1>;
				hysteresis = <1>;
				type = "passive";
			};
		};
	};

	pmi632-bcl-lvl1 {
		polling-delay-passive = <100>;
		polling-delay = <0>;
		thermal-sensors = <&pmi632_bcl 6>;

		trips {
			thermal-engine-trip {
				temperature = <100>;
				hysteresis = <0>;
				type = "passive";
			};

			thermal-hal-trip {
				temperature = <100>;
				hysteresis = <0>;
				type = "passive";
			};

			b_bcl_lvl1: b-bcl-lvl1 {
				temperature = <1>;
				hysteresis = <1>;
				type = "passive";
			};
		};
	};

	pmi632-bcl-lvl2 {
		polling-delay-passive = <100>;
		polling-delay = <0>;
		thermal-sensors = <&pmi632_bcl 7>;

		trips {
			thermal-engine-trip {
				temperature = <100>;
				hysteresis = <0>;
				type = "passive";
			};

			thermal-hal-trip {
				temperature = <100>;
				hysteresis = <0>;
				type = "passive";
			};

			b_bcl_lvl2: b-bcl-lvl2 {
				temperature = <1>;
				hysteresis = <1>;
				type = "passive";
			};
		};
	};

	socd {
		polling-delay-passive = <100>;
		polling-delay = <0>;
		thermal-sensors = <&bcl_soc>;

		trips {
			thermal-engine-trip {
				temperature = <100>;
				hysteresis = <0>;
				type = "passive";
			};

			thermal-hal-trip {
				temperature = <100>;
				hysteresis = <0>;
				type = "passive";
			};

			socd_trip:socd-trip {
				temperature = <90>;
				hysteresis = <1>;
				type = "passive";
			};
		};
	};
};
