// SPDX-License-Identifier: BSD-3-Clause
/*
 * Copyright (c) 2020, Konrad Dybcio
 */

#include <dt-bindings/input/qcom,spmi-haptics.h>
#include <dt-bindings/iio/qcom,spmi-vadc.h>
#include <dt-bindings/input/linux-event-codes.h>
#include <dt-bindings/interrupt-controller/irq.h>
#include <dt-bindings/spmi/spmi.h>
#include <dt-bindings/thermal/thermal.h>

/ {
	thermal-zones {
		pm660-thermal {
			polling-delay-passive = <250>;

			thermal-sensors = <&pm660_temp>;

			trips {
				pm660_alert0: pm660-alert0 {
					temperature = <95000>;
					hysteresis = <2000>;
					type = "passive";
				};
				pm660_crit: pm660-crit {
					temperature = <125000>;
					hysteresis = <2000>;
					type = "critical";
				};
			};
		};
	};
};

&spmi_bus {
	pmic@0 {
		compatible = "qcom,pm660", "qcom,spmi-pmic";
		reg = <0x0 SPMI_USID>;
		#address-cells = <1>;
		#size-cells = <0>;

		rtc@6000 {
			compatible = "qcom,pm8941-rtc";
			reg = <0x6000>, <0x6100>;
			reg-names = "rtc", "alarm";
			interrupts = <0x0 0x61 0x1 IRQ_TYPE_EDGE_RISING>;
		};

		pon: pon@800 {
			compatible = "qcom,pm8998-pon";
			reg = <0x800>;
			mode-bootloader = <0x2>;
			mode-recovery = <0x1>;

			pon_pwrkey: pwrkey {
				compatible = "qcom,pm8941-pwrkey";
				interrupts = <0x0 0x8 0 IRQ_TYPE_EDGE_BOTH>;
				debounce = <15625>;
				bias-pull-up;
				linux,code = <KEY_POWER>;

				status = "disabled";
			};

			pon_resin: resin {
				compatible = "qcom,pm8941-resin";
				interrupts = <0x0 0x8 1 IRQ_TYPE_EDGE_BOTH>;
				debounce = <15625>;
				bias-pull-up;

				status = "disabled";
			};
		};

		pm660_charger: charger@1000 {
			compatible = "qcom,pm660-charger";
			reg = <0x1000>;

			interrupts = <0x0 0x13 0x4 IRQ_TYPE_EDGE_BOTH>,
				     <0x0 0x12 0x2 IRQ_TYPE_EDGE_BOTH>,
				     <0x0 0x16 0x1 IRQ_TYPE_EDGE_RISING>,
				     <0x0 0x13 0x6 IRQ_TYPE_EDGE_RISING>;
			interrupt-names = "usb-plugin", "bat-ov", "wdog-bark", "usbin-icl-change";

			io-channels = <&pm660_rradc 3>,
				      <&pm660_rradc 4>;
			io-channel-names = "usbin_i", "usbin_v";

			#cooling-cells = <2>;

			status = "disabled";
		};

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

		pm660_adc: adc@3100 {
			compatible = "qcom,spmi-adc-rev2";
			reg = <0x3100>;
			interrupts = <0x0 0x31 0x0 IRQ_TYPE_EDGE_RISING>;
			#address-cells = <1>;
			#size-cells = <0>;
			#io-channel-cells = <1>;

			channel@0 {
				reg = <ADC5_REF_GND>;
				qcom,decimation = <1024>;
				qcom,pre-scaling = <1 1>;
				label = "ref_gnd";
			};

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

			channel@6 {
				reg = <ADC5_DIE_TEMP>;
				qcom,decimation = <1024>;
				qcom,pre-scaling = <1 1>;
				label = "die_temp";
			};

			channel@4c {
				reg = <ADC5_XO_THERM_100K_PU>;
				qcom,pre-scaling = <1 1>;
				qcom,decimation = <1024>;
				qcom,hw-settle-time = <200>;
				qcom,ratiometric;
				label = "xo_therm";
			};

			channel@4d {
				reg = <ADC5_AMUX_THM1_100K_PU>;
				qcom,pre-scaling = <1 1>;
				qcom,decimation = <1024>;
				qcom,hw-settle-time = <200>;
				qcom,ratiometric;
				label = "msm_therm";
			};

			channel@4e {
				reg = <ADC5_AMUX_THM2_100K_PU>;
				qcom,pre-scaling = <1 1>;
				qcom,decimation = <1024>;
				qcom,hw-settle-time = <200>;
				qcom,ratiometric;
				label = "emmc_therm";
			};

			channel@4f {
				reg = <ADC5_AMUX_THM3_100K_PU>;
				qcom,pre-scaling = <1 1>;
				qcom,decimation = <1024>;
				qcom,hw-settle-time = <200>;
				qcom,ratiometric;
				label = "pa_therm0";
			};

			channel@50 {
				reg = <ADC5_AMUX_THM4_100K_PU>;
				qcom,pre-scaling = <1 1>;
				qcom,decimation = <1024>;
				qcom,hw-settle-time = <200>;
				qcom,ratiometric;
				label = "pa_therm1";
			};

			channel@51 {
				reg = <ADC5_AMUX_THM5_100K_PU>;
				qcom,pre-scaling = <1 1>;
				qcom,decimation = <1024>;
				qcom,hw-settle-time = <200>;
				qcom,ratiometric;
				label = "quiet_therm";
			};

			channel@83 {
				reg = <ADC5_VPH_PWR>;
				qcom,decimation = <1024>;
				qcom,pre-scaling = <1 3>;
				label = "vph_pwr";
			};

			channel@85 {
				reg = <ADC5_VCOIN>;
				qcom,decimation = <1024>;
				qcom,pre-scaling = <1 3>;
				label = "vcoin";
			};
		};

		pm660_adc_tm: adc-tm@3400 {
			compatible = "qcom,spmi-adc-tm-hc";
			reg = <0x3400>;
			interrupts = <0x0 0x34 0x0 IRQ_TYPE_EDGE_RISING>;
			#thermal-sensor-cells = <1>;
			#address-cells = <1>;
			#size-cells = <0>;
			status = "disabled";
		};

		pm660_fg: fuel-gauge@4000 {
		        compatible = "qcom,pmi8998-fg";
		        reg = <0x4000>;
		        interrupts = <0x0 0x40 0x3 IRQ_TYPE_EDGE_RISING>;
		        interrupt-names = "soc-delta";
		        status = "disabled";
		};

		pm660_rradc: adc@4500 {
			compatible = "qcom,pm660-rradc";
			reg = <0x4500>;
			#io-channel-cells = <1>;

			status = "disabled";
		};

		pm660_gpios: gpio@c000 {
			compatible = "qcom,pm660-gpio", "qcom,spmi-gpio";
			reg = <0xc000>;
			gpio-controller;
			gpio-ranges = <&pm660_gpios 0 0 13>;
			#gpio-cells = <2>;
			interrupt-controller;
			#interrupt-cells = <2>;
		};
	};

	pmic@1 {
		compatible = "qcom,pm660", "qcom,spmi-pmic";
		reg = <0x1 SPMI_USID>;
		#address-cells = <1>;
		#size-cells = <0>;

		pm660_spmi_regulators: regulators {
			compatible = "qcom,pm660-regulators";
		};

		pm660_haptics: haptics@c000 {
			compatible = "qcom,pm660-haptics", "qcom,spmi-haptics";
			reg = <0xc000>;

			interrupts = <0x1 0xc0 0x0 IRQ_TYPE_EDGE_BOTH>,
				     <0x1 0xc0 0x1 IRQ_TYPE_EDGE_BOTH>;
			interrupt-names = "short", "play";

			qcom,vmax = <3200>;
			qcom,wave-play-rate-us = <10000>;
			qcom,wave-shape = <HAP_WAVE_SQUARE>;
			qcom,play-mode = <HAP_PLAY_BUFFER>;
			qcom,brake-pattern = <0x3 0x3 0x2 0x1>;

			status = "disabled";
		};
	};
};
