// 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 "pm4125.dtsi"
#include "pm8005.dtsi"

/ {
	aliases {
		serial1 = &uart8;
	};

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

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

	msm_therm_bridge: msm-therm-bridge {
		compatible = "generic-adc-thermal";
		io-channels = <&pm4125_adc ADC5_AMUX_THM3_100K_PU>;
		io-channel-names = "sensor-channel";
		#thermal-sensor-cells = <0>;
	};

	pa_therm_bridge: pa-therm-bridge {
		compatible = "generic-adc-thermal";
		io-channels = <&pm4125_adc ADC5_AMUX_THM1_100K_PU>;
		io-channel-names = "sensor-channel";
		#thermal-sensor-cells = <0>;
	};

	quiet_therm_bridge: quiet-therm-bridge {
		compatible = "generic-adc-thermal";
		io-channels = <&pm4125_adc ADC5_AMUX_THM2_100K_PU>;
		io-channel-names = "sensor-channel";
		#thermal-sensor-cells = <0>;
	};

	thermal-zones {
		sys-1-thermal {
			polling-delay-passive = <2000>;
			thermal-sensors = <&pa_therm_bridge>;

			trips {
				active-config0 {
					temperature = <80000>;
					hysteresis = <2000>;
					type = "hot";
				};
			};
		};

		sys-2-thermal {
			polling-delay-passive = <2000>;
			thermal-sensors = <&quiet_therm_bridge>;

			trips {
				active-config0 {
					temperature = <80000>;
					hysteresis = <2000>;
					type = "hot";
				};
			};
		};

		sys-3-thermal {
			polling-delay-passive = <2000>;
			thermal-sensors = <&msm_therm_bridge>;

			trips {
				active-config0 {
					temperature = <80000>;
					hysteresis = <2000>;
					type = "hot";
				};
			};
		};
	};

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

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

		swctrl-gpios = <&tlmm 88 GPIO_ACTIVE_HIGH>;

		vddio-supply = <&pm4125_l7>;
		vddxo-supply = <&pm4125_l13>;
		vddrf-supply = <&pm4125_l10>;
		vddch0-supply = <&pm4125_l22>;

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

&pm4125_adc {
	pinctrl-0 = <&pm4125_adc_gpio5_default>, <&pm4125_adc_gpio6_default>;
	pinctrl-names = "default";

	channel@4d {
		reg = <ADC5_AMUX_THM1_100K_PU>;
		label = "pa_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@4f {
		reg = <ADC5_AMUX_THM3_100K_PU>;
		label = "msm_therm";
		qcom,ratiometric;
		qcom,hw-settle-time = <200>;
		qcom,pre-scaling = <1 1>;
	};

	channel@54 {
		reg = <ADC5_GPIO3_100K_PU>;
		label = "chgr_skin";
		qcom,ratiometric;
		qcom,hw-settle-time = <200>;
		qcom,pre-scaling = <1 1>;
	};

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

&pm4125_gpios {
	pm4125_adc_gpio5_default: pm4125-adc-gpio5-state {
		pins = "gpio5";
		function = PMIC_GPIO_FUNC_NORMAL;
		bias-high-impedance;
	};

	pm4125_adc_gpio6_default: pm4125-adc-gpio6-state {
		pins = "gpio6";
		function = PMIC_GPIO_FUNC_NORMAL;
		bias-high-impedance;
	};

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

&pm4125_resin {
	linux,code = <KEY_VOLUMEDOWN>;

	status = "okay";
};

&pm8005_regulators {
	status = "disabled";
};

&pm4125_typec {
	status = "okay";

	connector {
		compatible = "usb-c-connector";

		power-role = "dual";
		data-role = "dual";
		self-powered;

		vbus-supply = <&pm4125_vbus>;

		typec-power-opmode = "default";
		pd-disable;

		ports {
			#address-cells = <1>;
			#size-cells = <0>;

			port@0 {
				reg = <0>;
				pm4125_hs_in: endpoint {
				};
			};

			port@1 {
				reg = <1>;
				pm4125_ss_in: endpoint {
				};
			};
		};
	};
};

&pm4125_vbus {
	regulator-min-microvolt = <5000000>;
	regulator-max-microvolt = <5000000>;

	status = "okay";
};

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

		pm4125_s2: s2 {
			regulator-min-microvolt = <1000000>;
			regulator-max-microvolt = <1200000>;
		};

		pm4125_l3: l3 {
			regulator-min-microvolt = <624000>;
			regulator-max-microvolt = <650000>;
		};

		pm4125_l4: l4 {
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <2960000>;
		};

		pm4125_l5: l5 {
			regulator-min-microvolt = <1232000>;
			regulator-max-microvolt = <1304000>;
		};

		pm4125_l6: l6 {
			regulator-min-microvolt = <788000>;
			regulator-max-microvolt = <1050000>;
		};

		pm4125_l7: l7 {
			regulator-min-microvolt = <664000>;
			regulator-max-microvolt = <664000>;
		};

		pm4125_l8: l8 {
			regulator-min-microvolt = <928000>;
			regulator-max-microvolt = <1000000>;
		};

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

		pm4125_l10: l10 {
			regulator-min-microvolt = <1304000>;
			regulator-max-microvolt = <1304000>;
		};

		pm4125_l12: l12 {
			regulator-min-microvolt = <928000>;
			regulator-max-microvolt = <975000>;
		};

		pm4125_l13: l13 {
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1800000>;
		};

		pm4125_l14: l14 {
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1800000>;
		};

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

		pm4125_l16: l16 {
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1800000>;
		};

		pm4125_l17: l17 {
			regulator-min-microvolt = <3000000>;
			regulator-max-microvolt = <3544000>;
		};

		pm4125_l18: l18 {
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <2960000>;
		};

		pm4125_l19: l19 {
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <2960000>;
		};

		pm4125_l20: l20 {
			regulator-min-microvolt = <2952000>;
			regulator-max-microvolt = <2952000>;
		};

		pm4125_l21: l21 {
			regulator-min-microvolt = <3000000>;
			regulator-max-microvolt = <3056000>;
		};

		pm4125_l22: l22 {
			regulator-min-microvolt = <3304000>;
			regulator-max-microvolt = <3304000>;
		};
	};
};

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