// SPDX-License-Identifier: BSD-3-Clause
/*
 * Copyright (c) 2022, Luca Weiss <luca@z3ntu.xyz>
 */
/dts-v1/;

#include <dt-bindings/leds/common.h>
#include "sdm632.dtsi"
#include "pm8953.dtsi"
#include "pmi632.dtsi"

/ {
	model = "Fairphone 3";
	compatible = "fairphone,fp3", "qcom,sdm632";
	chassis-type = "handset";
	qcom,msm-id = <349 0>;
	qcom,board-id = <8 0x10000>;

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

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

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

		key-volume-up {
			label = "volume_up";
			linux,code = <KEY_VOLUMEUP>;
			gpios = <&tlmm 85 GPIO_ACTIVE_LOW>;
		};
	};

	vreg_cam_af_2p85: regulator-cam-af-2p85 {
		compatible = "regulator-fixed";
		regulator-name = "cam_af_2p85";
		regulator-min-microvolt = <2850000>;
		regulator-max-microvolt = <2850000>;

		gpio = <&tlmm 128 GPIO_ACTIVE_HIGH>;
		enable-active-high;

		vin-supply = <&vph_pwr>;
	};

	vreg_cam_io_1p8: regulator-cam-io-1p8 {
		compatible = "regulator-fixed";
		regulator-name = "cam_io_1p8";
		regulator-min-microvolt = <1800000>;
		regulator-max-microvolt = <1800000>;

		gpio = <&tlmm 130 GPIO_ACTIVE_HIGH>;
		enable-active-high;

		vin-supply = <&vph_pwr>;
	};

	vreg_cam2_dig_1p2: regulator-cam2-dig-1p2 {
		compatible = "regulator-fixed";
		regulator-name = "cam2_dig_1p2";
		regulator-min-microvolt = <1200000>;
		regulator-max-microvolt = <1200000>;

		gpio = <&tlmm 46 GPIO_ACTIVE_HIGH>;
		enable-active-high;

		vin-supply = <&vph_pwr>;
	};

	/* Dummy regulator until PMI632 has LCDB VSP/VSN support */
	lcdb_dummy: regulator-lcdb-dummy {
		compatible = "regulator-fixed";
		regulator-name = "lcdb_dummy";
		regulator-min-microvolt = <5500000>;
		regulator-max-microvolt = <5500000>;
	};

	vph_pwr: vph-pwr-regulator {
		compatible = "regulator-fixed";
		regulator-name = "vph_pwr";
		regulator-always-on;
		regulator-boot-on;
	};
};

&cci {
	status = "okay";
};

&cci_i2c0 {
	/* Sony IMX363 (rear) @ 0x10 */

	eeprom@50 {
		compatible = "belling,bl24s64", "atmel,24c64";
		reg = <0x50>;
		vcc-supply = <&vreg_cam_io_1p8>;
		read-only;
	};

	/* ON Semi LC898217 VCM @ 0x72 */
};

&cci_i2c1 {
	/* Samsung S5K4H7YX (front) @ 0x10 */
};

&gpu {
	status = "okay";
};

&gpu_zap_shader {
	firmware-name = "qcom/msm8953/fairphone/fp3/a506_zap.mbn";
};

&hsusb_phy {
	vdd-supply = <&pm8953_l3>;
	vdda-pll-supply = <&pm8953_l7>;
	vdda-phy-dpdm-supply = <&pm8953_l13>;

	status = "okay";
};

&i2c_3 {
	status = "okay";

	touchscreen@48 {
		compatible = "himax,hx83112b";
		reg = <0x48>;
		interrupt-parent = <&tlmm>;
		interrupts = <65 IRQ_TYPE_LEVEL_LOW>;
		touchscreen-size-x = <1080>;
		touchscreen-size-y = <2160>;
		reset-gpios = <&tlmm 64 GPIO_ACTIVE_LOW>;
	};
};

&i2c_5 {
	status = "okay";

	nfc@28 {
		compatible = "nxp,nq310", "nxp,nxp-nci-i2c";
		reg = <0x28>;

		interrupt-parent = <&tlmm>;
		interrupts = <17 IRQ_TYPE_LEVEL_HIGH>;

		enable-gpios = <&tlmm 16 GPIO_ACTIVE_HIGH>;
		firmware-gpios = <&tlmm 62 GPIO_ACTIVE_HIGH>;
	};
};

&lpass {
	firmware-name = "qcom/msm8953/fairphone/fp3/adsp.mbn";

	status = "okay";
};

&mdss {
	status = "okay";
};

&mdss_dsi0 {
	vdda-supply = <&pm8953_s3>;
	status = "okay";

	panel@0 {
		compatible = "djn,98-03057-6598b-i";
		reg = <0>;

		reset-gpios = <&tlmm 61 GPIO_ACTIVE_LOW>;

		iovcc-supply = <&pm8953_l6>;
		vsn-supply = <&lcdb_dummy>;
		vsp-supply = <&lcdb_dummy>;

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

		port {
			panel_in: endpoint {
				remote-endpoint = <&mdss_dsi0_out>;
			};
		};
	};
};

&mdss_dsi0_out {
	data-lanes = <0 1 2 3>;
	remote-endpoint = <&panel_in>;
};

&mdss_dsi0_phy {
	vcca-supply = <&pm8953_l3>;
	status = "okay";
};

&mpss {
	firmware-name = "qcom/msm8953/fairphone/fp3/mba.mbn",
			"qcom/msm8953/fairphone/fp3/modem.mbn";
	pll-supply = <&pm8953_l7>;

	status = "okay";
};

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

&pmi632_lpg {
	status = "okay";

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

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

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

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

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

&pmi632_typec {
	status = "okay";

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

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

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

		vbus-supply = <&pmi632_vbus>;

		port {
			pmi632_hs_in: endpoint {
				remote-endpoint = <&usb_dwc3_hs>;
			};
		};
	};
};

&pmi632_vbus {
	regulator-min-microamp = <500000>;
	regulator-max-microamp = <1000000>;
	status = "okay";
};

&pmi632_vib {
	status = "okay";
};

&sdhc_1 {
	vmmc-supply = <&pm8953_l8>;
	vqmmc-supply = <&pm8953_l5>;

	status = "okay";
};

&sdhc_2 {
	vmmc-supply = <&pm8953_l11>;
	vqmmc-supply = <&pm8953_l12>;

	cd-gpios = <&tlmm 133 GPIO_ACTIVE_LOW>;

	status = "okay";
};

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

		vdd_l1-supply = <&pm8953_s3>;
		vdd_l2_l3-supply = <&pm8953_s3>;
		vdd_l4_l5_l6_l7_l16_l19-supply = <&pm8953_s4>;
		vdd_l8_l11_l12_l13_l14_l15-supply = <&vph_pwr>;
		vdd_l9_l10_l17_l18_l22-supply = <&vph_pwr>;

		pm8953_s3: s3 {
			regulator-min-microvolt = <984000>;
			regulator-max-microvolt = <1240000>;
		};

		pm8953_s4: s4 {
			regulator-min-microvolt = <1036000>;
			regulator-max-microvolt = <2040000>;
		};

		pm8953_s5: s5 {
			regulator-min-microvolt = <1036000>;
			regulator-max-microvolt = <2040000>;
		};

		pm8953_l1: l1 {
			regulator-min-microvolt = <975000>;
			regulator-max-microvolt = <1050000>;
		};

		pm8953_l2: l2 {
			regulator-min-microvolt = <975000>;
			regulator-max-microvolt = <1175000>;
		};

		pm8953_l3: l3 {
			regulator-min-microvolt = <925000>;
			regulator-max-microvolt = <925000>;
		};

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

		pm8953_l6: l6 {
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1800000>;
		};

		pm8953_l7: l7 {
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1900000>;
		};

		pm8953_l8: l8 {
			regulator-min-microvolt = <2900000>;
			regulator-max-microvolt = <2900000>;
		};

		pm8953_l9: l9 {
			regulator-min-microvolt = <3000000>;
			regulator-max-microvolt = <3300000>;
		};

		pm8953_l10: l10 {
			regulator-min-microvolt = <2800000>;
			regulator-max-microvolt = <3000000>;
		};

		pm8953_l11: l11 {
			regulator-min-microvolt = <2950000>;
			regulator-max-microvolt = <2950000>;
		};

		pm8953_l12: l12 {
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <2950000>;
		};

		pm8953_l13: l13 {
			regulator-min-microvolt = <3125000>;
			regulator-max-microvolt = <3125000>;
		};

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

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

		pm8953_l19: l19 {
			regulator-min-microvolt = <1200000>;
			regulator-max-microvolt = <1350000>;
		};

		pm8953_l22: l22 {
			regulator-min-microvolt = <2800000>;
			regulator-max-microvolt = <2800000>;
		};

		pm8953_l23: l23 {
			regulator-min-microvolt = <975000>;
			regulator-max-microvolt = <1225000>;
		};
	};
};

&tlmm {
	/*
	 * 0-3: unused but protected by TZ
	 * 135-138: fingerprint reader (SPI)
	 */
	gpio-reserved-ranges = <0 4>, <135 4>;

	mdss_te_default: mdss-te-default-state {
		pins = "gpio24";
		function = "mdp_vsync";
		drive-strength = <2>;
		bias-pull-down;
	};
};

&uart_0 {
	status = "okay";
};

&usb3 {
	status = "okay";
};

&usb_dwc3_hs {
	remote-endpoint = <&pmi632_hs_in>;
};

&wcnss {
	firmware-name = "qcom/msm8953/fairphone/fp3/wcnss.mbn";
	vddpx-supply = <&pm8953_l5>;

	status = "okay";
};

&wcnss_ctrl {
	firmware-name = "qcom/msm8953/fairphone/fp3/WCNSS_qcom_wlan_nv.bin";
};

&wcnss_iris {
	compatible = "qcom,wcn3680";

	vddxo-supply = <&pm8953_l7>;
	vddrfa-supply = <&pm8953_l19>;
	vddpa-supply = <&pm8953_l9>;
	vdddig-supply = <&pm8953_l5>;
};