// SPDX-License-Identifier: GPL-2.0
#include "qcom-msm8974pro.dtsi"
#include "qcom-pm8841.dtsi"
#include "qcom-pm8941.dtsi"
#include <dt-bindings/input/input.h>
#include <dt-bindings/leds/common.h>
#include <dt-bindings/pinctrl/qcom,pmic-gpio.h>

/ {
	model = "Fairphone 2";
	compatible = "fairphone,fp2", "qcom,msm8974pro", "qcom,msm8974";
	chassis-type = "handset";

	aliases {
		mmc0 = &sdhc_1;
		mmc1 = &sdhc_2;
		serial0 = &blsp1_uart2;
	};

	chosen {
		stdout-path = "serial0:115200n8";
	};

	gpio-keys {
		compatible = "gpio-keys";

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

		key-camera-snapshot {
			label = "camera_snapshot";
			gpios = <&pm8941_gpios 1 GPIO_ACTIVE_LOW>;
			linux,code = <KEY_CAMERA>;
			wakeup-source;
			debounce-interval = <15>;
		};

		key-volume-down {
			label = "volume_down";
			gpios = <&pm8941_gpios 2 GPIO_ACTIVE_LOW>;
			linux,code = <KEY_VOLUMEDOWN>;
			wakeup-source;
			debounce-interval = <15>;
		};

		key-volume-up {
			label = "volume_up";
			gpios = <&pm8941_gpios 5 GPIO_ACTIVE_LOW>;
			linux,code = <KEY_VOLUMEUP>;
			wakeup-source;
			debounce-interval = <15>;
		};
	};

	vibrator {
		compatible = "gpio-vibrator";
		enable-gpios = <&tlmm 86 GPIO_ACTIVE_HIGH>;
		vcc-supply = <&pm8941_l18>;
	};
};

&blsp1_i2c2 {
	status = "okay";

	touchscreen@41 {
		compatible = "ilitek,ili2120";
		reg = <0x41>;
		interrupt-parent = <&tlmm>;
		interrupts = <28 IRQ_TYPE_EDGE_FALLING>;
		reset-gpios = <&tlmm 55 GPIO_ACTIVE_LOW>;

		touchscreen-size-x = <1080>;
		touchscreen-size-y = <1920>;
	};
};

&blsp1_uart2 {
	status = "okay";
};

&imem {
	reboot-mode {
		mode-normal = <0x77665501>;
		mode-bootloader = <0x77665500>;
		mode-recovery = <0x77665502>;
	};
};

&pm8941_gpios {
	gpio_keys_pin_a: gpio-keys-active-state {
		pins = "gpio1", "gpio2", "gpio5";
		function = "normal";

		bias-pull-up;
		power-source = <PM8941_GPIO_S3>;
	};
};

&pm8941_lpg {
	status = "okay";

	qcom,power-source = <1>;

	multi-led {
		color = <LED_COLOR_ID_RGB>;
		function = LED_FUNCTION_STATUS;

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

		led@7 {
			reg = <7>;
			color = <LED_COLOR_ID_RED>;
		};

		led@6 {
			reg = <6>;
			color = <LED_COLOR_ID_GREEN>;
		};

		led@5 {
			reg = <5>;
			color = <LED_COLOR_ID_BLUE>;
		};
	};
};

&pronto {
	status = "okay";

	vddmx-supply = <&pm8841_s1>;
	vddcx-supply = <&pm8841_s2>;
	vddpx-supply = <&pm8941_s3>;

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

	iris {
		vddxo-supply = <&pm8941_l6>;
		vddrfa-supply = <&pm8941_l11>;
		vddpa-supply = <&pm8941_l19>;
		vdddig-supply = <&pm8941_s3>;
	};

	smd-edge {
		qcom,remote-pid = <4>;
		label = "pronto";

		wcnss {
			status = "okay";
		};
	};
};

&remoteproc_adsp {
	status = "okay";
	cx-supply = <&pm8841_s2>;
};

&remoteproc_mss {
	status = "okay";
	cx-supply = <&pm8841_s2>;
	mss-supply = <&pm8841_s3>;
	mx-supply = <&pm8841_s1>;
	pll-supply = <&pm8941_l12>;
};

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

		pm8841_s1: s1 {
			regulator-min-microvolt = <675000>;
			regulator-max-microvolt = <1050000>;
		};

		pm8841_s2: s2 {
			regulator-min-microvolt = <500000>;
			regulator-max-microvolt = <1050000>;
		};

		pm8841_s3: s3 {
			regulator-min-microvolt = <1050000>;
			regulator-max-microvolt = <1050000>;
		};
	};

	regulators-1 {
		compatible = "qcom,rpm-pm8941-regulators";

		vdd_l1_l3-supply = <&pm8941_s1>;
		vdd_l2_lvs1_2_3-supply = <&pm8941_s3>;
		vdd_l4_l11-supply = <&pm8941_s1>;
		vdd_l5_l7-supply = <&pm8941_s2>;
		vdd_l6_l12_l14_l15-supply = <&pm8941_s2>;
		vdd_l9_l10_l17_l22-supply = <&vreg_boost>;
		vdd_l13_l20_l23_l24-supply = <&vreg_boost>;
		vdd_l21-supply = <&vreg_boost>;

		pm8941_s1: s1 {
			regulator-min-microvolt = <1300000>;
			regulator-max-microvolt = <1300000>;
			regulator-always-on;
			regulator-boot-on;
		};

		pm8941_s2: s2 {
			regulator-min-microvolt = <2150000>;
			regulator-max-microvolt = <2150000>;
			regulator-boot-on;
		};

		pm8941_s3: s3 {
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1800000>;
			regulator-always-on;
			regulator-boot-on;
		};

		pm8941_l1: l1 {
			regulator-min-microvolt = <1225000>;
			regulator-max-microvolt = <1225000>;
			regulator-always-on;
			regulator-boot-on;
		};

		pm8941_l2: l2 {
			regulator-min-microvolt = <1200000>;
			regulator-max-microvolt = <1200000>;
		};

		pm8941_l3: l3 {
			regulator-min-microvolt = <1225000>;
			regulator-max-microvolt = <1225000>;
		};

		pm8941_l4: l4 {
			regulator-min-microvolt = <1225000>;
			regulator-max-microvolt = <1225000>;
		};

		pm8941_l5: l5 {
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1800000>;
		};

		pm8941_l6: l6 {
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1800000>;
			regulator-boot-on;
		};

		pm8941_l7: l7 {
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1800000>;
			regulator-boot-on;
		};

		pm8941_l8: l8 {
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1800000>;
		};

		pm8941_l9: l9 {
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <2950000>;
		};

		pm8941_l10: l10 {
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <2950000>;
		};

		pm8941_l11: l11 {
			regulator-min-microvolt = <1225000>;
			regulator-max-microvolt = <1350000>;
		};

		pm8941_l12: l12 {
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1800000>;
			regulator-always-on;
			regulator-boot-on;
		};

		pm8941_l13: l13 {
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <2950000>;
			regulator-boot-on;
		};

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

		pm8941_l15: l15 {
			regulator-min-microvolt = <2050000>;
			regulator-max-microvolt = <2050000>;
		};

		pm8941_l16: l16 {
			regulator-min-microvolt = <2700000>;
			regulator-max-microvolt = <2700000>;
		};

		pm8941_l17: l17 {
			regulator-min-microvolt = <2850000>;
			regulator-max-microvolt = <2850000>;
		};

		pm8941_l18: l18 {
			regulator-min-microvolt = <2850000>;
			regulator-max-microvolt = <2850000>;
		};

		pm8941_l19: l19 {
			regulator-min-microvolt = <2900000>;
			regulator-max-microvolt = <3350000>;
		};

		pm8941_l20: l20 {
			regulator-min-microvolt = <2950000>;
			regulator-max-microvolt = <2950000>;
			regulator-system-load = <200000>;
			regulator-allow-set-load;
			regulator-boot-on;
		};

		pm8941_l21: l21 {
			regulator-min-microvolt = <2950000>;
			regulator-max-microvolt = <2950000>;
			regulator-boot-on;
		};

		pm8941_l22: l22 {
			regulator-min-microvolt = <3000000>;
			regulator-max-microvolt = <3300000>;
		};

		pm8941_l23: l23 {
			regulator-min-microvolt = <3000000>;
			regulator-max-microvolt = <3000000>;
		};

		pm8941_l24: l24 {
			regulator-min-microvolt = <3075000>;
			regulator-max-microvolt = <3075000>;
			regulator-boot-on;
		};
	};
};

&sdhc_1 {
	status = "okay";

	vmmc-supply = <&pm8941_l20>;
	vqmmc-supply = <&pm8941_s3>;

	pinctrl-names = "default", "sleep";
	pinctrl-0 = <&sdc1_on>;
	pinctrl-1 = <&sdc1_off>;
};

&sdhc_2 {
	status = "okay";

	vmmc-supply = <&pm8941_l21>;
	vqmmc-supply = <&pm8941_l13>;

	pinctrl-names = "default", "sleep";
	pinctrl-0 = <&sdc2_on>;
	pinctrl-1 = <&sdc2_off>;
};

&smbb {
	usb-charge-current-limit = <1500000>;
	qcom,fast-charge-safe-current = <1500000>;
	qcom,fast-charge-current-limit = <1500000>;
	qcom,fast-charge-safe-voltage = <4380000>;
	qcom,fast-charge-high-threshold-voltage = <4350000>;
	qcom,auto-recharge-threshold-voltage = <4240000>;
	qcom,minimum-input-voltage = <4450000>;
};

&tlmm {
	sdc1_on: sdc1-on-state {
		clk-pins {
			pins = "sdc1_clk";
			drive-strength = <16>;
			bias-disable;
		};

		cmd-data-pins {
			pins = "sdc1_cmd", "sdc1_data";
			drive-strength = <10>;
			bias-pull-up;
		};
	};

	sdc2_on: sdc2-on-state {
		clk-pins {
			pins = "sdc2_clk";
			drive-strength = <10>;
			bias-disable;
		};

		cmd-data-pins {
			pins = "sdc2_cmd", "sdc2_data";
			drive-strength = <6>;
			bias-pull-up;
		};
	};

	wcnss_pin_a: wcnss-pin-active-state {
		wlan-pins {
			pins = "gpio36", "gpio37", "gpio38", "gpio39", "gpio40";
			function = "wlan";

			drive-strength = <6>;
			bias-pull-down;
		};

		bt-pins {
			pins = "gpio35", "gpio43", "gpio44";
			function = "bt";

			drive-strength = <2>;
			bias-pull-down;
		};

		fm-pins {
			pins = "gpio41", "gpio42";
			function = "fm";

			drive-strength = <2>;
			bias-pull-down;
		};
	};
};

&usb {
	status = "okay";

	phys = <&usb_hs1_phy>;
	phy-select = <&tcsr 0xb000 0>;
	extcon = <&smbb>, <&usb_id>;
	vbus-supply = <&chg_otg>;

	hnp-disable;
	srp-disable;
	adp-disable;
};

&usb_hs1_phy {
	status = "okay";

	v1p8-supply = <&pm8941_l6>;
	v3p3-supply = <&pm8941_l24>;

	extcon = <&smbb>;
	qcom,init-seq = /bits/ 8 <0x1 0x64>;
};