// SPDX-License-Identifier: BSD-3-Clause
/*
 * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
 */

#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/iio/qcom,spmi-vadc.h>
#include <dt-bindings/pinctrl/qcom,pmic-gpio.h>

#include "shikra.dtsi"
#include "pm8150.dtsi"

/ {
	aliases {
		serial1 = &uart8;
	};

	gpio-key {
		compatible = "gpio-keys";
		label = "gpio-keys";
		pinctrl-names = "default";
		pinctrl-0 = <&vol_up_n>;

		key-volume-up {
			label = "Volume Up";
			gpios = <&pm8150_gpios 6 GPIO_ACTIVE_LOW>;
			linux,input-type = <1>;
			linux,code = <KEY_VOLUMEUP>;
			wakeup-source;
			debounce-interval = <15>;
			linux,can-disable;
		};
	};

	thermal-zones {
		sys-1-thermal {
			thermal-sensors = <&pm8150_adc_tm 0>;

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

		sys-2-thermal {
			thermal-sensors = <&pm8150_adc_tm 1>;

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

		sys-3-thermal {
			thermal-sensors = <&pm8150_adc_tm 2>;

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

	vreg_wcn_3p3: regulator-wcn-3p3 {
		compatible = "regulator-fixed";
		regulator-name = "wcn_3p3";
		regulator-min-microvolt = <3300000>;
		regulator-max-microvolt = <3300000>;
		regulator-always-on;
	};

	wcn3988-pmu {
		compatible = "qcom,wcn3988-pmu";

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

		swctrl-gpios = <&tlmm 88 GPIO_ACTIVE_HIGH>;

		vddio-supply = <&pm8150_s4>;
		vddxo-supply = <&pm8150_l12>;
		vddrf-supply = <&pm8150_l8>;
		vddch0-supply = <&vreg_wcn_3p3>;

		regulators {
			vreg_pmu_io: ldo0 {
				regulator-name = "vreg_pmu_io";
			};

			vreg_pmu_xo: ldo1 {
				regulator-name = "vreg_pmu_xo";
			};

			vreg_pmu_rf: ldo2 {
				regulator-name = "vreg_pmu_rf";
			};

			vreg_pmu_ch0: ldo3 {
				regulator-name = "vreg_pmu_ch0";
			};

			vreg_pmu_ch1: ldo4 {
				regulator-name = "vreg_pmu_ch1";
			};
		};
	};
};

&pm8150_adc {
	pinctrl-0 = <&pm8150_adc_gpio2_default>, <&pm8150_adc_gpio3_default>;
	pinctrl-names = "default";

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

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

	channel@52 {
		reg = <ADC5_GPIO1_100K_PU>;
		label = "gnss_therm";
		qcom,ratiometric;
		qcom,hw-settle-time = <200>;
		qcom,pre-scaling = <1 1>;
	};

	channel@55 {
		reg = <ADC5_GPIO4_100K_PU>;
		label = "pa_therm";
		qcom,ratiometric;
		qcom,hw-settle-time = <200>;
		qcom,pre-scaling = <1 1>;
	};
};

&pm8150_adc_tm {
	status = "okay";

	pa-therm@0 {
		reg = <0>;
		io-channels = <&pm8150_adc ADC5_GPIO4_100K_PU>;
		qcom,ratiometric;
		qcom,hw-settle-time-us = <200>;
	};

	quiet-therm@1 {
		reg = <1>;
		io-channels = <&pm8150_adc ADC5_AMUX_THM2_100K_PU>;
		qcom,ratiometric;
		qcom,hw-settle-time-us = <200>;
	};

	msm-therm@2 {
		reg = <2>;
		io-channels = <&pm8150_adc ADC5_AMUX_THM1_100K_PU>;
		qcom,ratiometric;
		qcom,hw-settle-time-us = <200>;
	};
};

&pm8150_gpios {
	pm8150_adc_gpio2_default: pm8150-adc-gpio2-state {
		pins = "gpio2";
		function = PMIC_GPIO_FUNC_NORMAL;
		bias-high-impedance;
	};

	pm8150_adc_gpio3_default: pm8150-adc-gpio3-state {
		pins = "gpio3";
		function = PMIC_GPIO_FUNC_NORMAL;
		bias-high-impedance;
	};

	vol_up_n: vol-up-n-state {
		pins = "gpio6";
		function = PMIC_GPIO_FUNC_NORMAL;
		input-enable;
		bias-pull-up;
		power-source = <0>;
	};

};

&pon_pwrkey {
	status = "okay";
};

&pon_resin {
	linux,code = <KEY_VOLUMEDOWN>;
	status = "okay";
};

&rpm_requests {
	regulators {
		compatible = "qcom,rpm-pm8150-regulators";

		pm8150_s4: s4 {
			regulator-min-microvolt = <1080000>;
			regulator-max-microvolt = <2040000>;
		};

		pm8150_s5: s5 {
			regulator-min-microvolt = <1574000>;
			regulator-max-microvolt = <2040000>;
		};

		pm8150_s6: s6 {
			regulator-min-microvolt = <382000>;
			regulator-max-microvolt = <1352000>;
		};

		pm8150_s7: s7 {
			regulator-min-microvolt = <1000000>;
			regulator-max-microvolt = <1200000>;
		};

		pm8150_s8: s8 {
			regulator-min-microvolt = <570000>;
			regulator-max-microvolt = <650000>;
		};

		pm8150_l1: l1 {
			regulator-min-microvolt = <312000>;
			regulator-max-microvolt = <1304000>;
		};

		pm8150_l2: l2 {
			regulator-min-microvolt = <1650000>;
			regulator-max-microvolt = <3300000>;
		};

		pm8150_l3: l3 {
			regulator-min-microvolt = <312000>;
			regulator-max-microvolt = <1304000>;
		};

		pm8150_l4: l4 {
			regulator-min-microvolt = <875000>;
			regulator-max-microvolt = <975000>;
		};

		pm8150_l5: l5 {
			regulator-min-microvolt = <788000>;
			regulator-max-microvolt = <1050000>;
		};

		pm8150_l6: l6 {
			regulator-min-microvolt = <875000>;
			regulator-max-microvolt = <1000000>;
		};

		pm8150_l7: l7 {
			regulator-min-microvolt = <1504000>;
			regulator-max-microvolt = <2000000>;
		};

		pm8150_l8: l8 {
			regulator-min-microvolt = <1150000>;
			regulator-max-microvolt = <1304000>;
		};

		pm8150_l9: l9 {
			regulator-min-microvolt = <875000>;
			regulator-max-microvolt = <1000000>;
		};

		pm8150_l10: l10 {
			regulator-min-microvolt = <2700000>;
			regulator-max-microvolt = <3544000>;
		};

		pm8150_l11: l11 {
			regulator-min-microvolt = <1100000>;
			regulator-max-microvolt = <1304000>;
		};

		pm8150_l12: l12 {
			regulator-min-microvolt = <1650000>;
			regulator-max-microvolt = <1950000>;
		};

		pm8150_l13: l13 {
			regulator-min-microvolt = <2921000>;
			regulator-max-microvolt = <3230000>;
		};

		pm8150_l14: l14 {
			regulator-min-microvolt = <1700000>;
			regulator-max-microvolt = <1910000>;
		};

		pm8150_l15: l15 {
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1900000>;
		};

		pm8150_l16: l16 {
			regulator-min-microvolt = <1504000>;
			regulator-max-microvolt = <3544000>;
		};

		pm8150_l17: l17 {
			regulator-min-microvolt = <2700000>;
			regulator-max-microvolt = <3544000>;
		};

		pm8150_l18: l18 {
			regulator-min-microvolt = <400000>;
			regulator-max-microvolt = <728000>;
		};
	};
};

&tlmm {
	gpio-reserved-ranges = <6 4>, /* Fingerprint SPI */
			       <30 2>, /* NFC SPI */
			       <138 1>, /* NFC Secure IO */
			       <155 11>; /* eMMC Boot */

	sw_ctrl_default: sw-ctrl-default-state {
		pins = "gpio88";
		function = "gpio";
		bias-pull-down;
	};
};

&uart8 {
	status = "okay";

	bluetooth {
		compatible = "qcom,wcn3988-bt";
		max-speed = <3200000>;

		vddio-supply = <&vreg_pmu_io>;
		vddxo-supply = <&vreg_pmu_xo>;
		vddrf-supply = <&vreg_pmu_rf>;
		vddch0-supply = <&vreg_pmu_ch0>;
	};
};

&wifi {
	vdd-0.8-cx-mx-supply = <&pm8150_s4>;
	vdd-1.8-xo-supply = <&vreg_pmu_xo>;
	vdd-1.3-rfa-supply = <&vreg_pmu_rf>;
	vdd-3.3-ch0-supply = <&vreg_pmu_ch0>;

	qcom,calibration-variant = "Shikra_EVK";
	firmware-name = "shikra";

	status = "okay";
};