// SPDX-License-Identifier: BSD-3-Clause
/*
 * Copyright (c) 2023, Luca Weiss <luca.weiss@fairphone.com>
 */

/dts-v1/;

/* PM7250B is configured to use SID8/9 */
#define PM7250B_SID 8
#define PM7250B_SID1 9

#include <dt-bindings/iio/qcom,spmi-adc7-pm7325.h>
#include <dt-bindings/iio/qcom,spmi-adc7-pmk8350.h>
#include <dt-bindings/leds/common.h>
#include <dt-bindings/media/video-interfaces.h>
#include <dt-bindings/media/video-interface-devices.h>
#include <dt-bindings/pinctrl/qcom,pmic-gpio.h>
#include <dt-bindings/regulator/qcom,rpmh-regulator.h>
#include <dt-bindings/sound/qcom,q6asm.h>
#include <dt-bindings/sound/qcom,q6dsp-lpass-ports.h>
#include "kodiak.dtsi"
#include "pm7250b.dtsi"
#include "pm7325.dtsi"
#include "pm8350c.dtsi" /* PM7350C */
#include "pmk8350.dtsi" /* PMK7325 */

/delete-node/ &rmtfs_mem;

/ {
	model = "Fairphone 5";
	compatible = "fairphone,fp5", "qcom,qcm6490";
	chassis-type = "handset";

	aliases {
		serial0 = &uart5;
		serial1 = &uart7;
	};

	chosen {
		#address-cells = <2>;
		#size-cells = <2>;
		ranges;

		framebuffer {
			compatible = "simple-framebuffer";
			memory-region = <&cont_splash_mem>;
			width = <1224>;
			height = <2700>;
			stride = <(1224 * 4)>;
			format = "a8r8g8b8";
			clocks = <&gcc GCC_DISP_HF_AXI_CLK>;
			vci-supply = <&vreg_oled_vci>;
			dvdd-supply = <&vreg_oled_dvdd>;
		};
	};

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

		pinctrl-0 = <&volume_down_default>, <&hall_sensor_default>;
		pinctrl-names = "default";

		key-volume-up {
			label = "Volume up";
			gpios = <&pm7325_gpios 6 GPIO_ACTIVE_LOW>;
			linux,code = <KEY_VOLUMEUP>;
		};

		/* Powered by the always-on vreg_l8c */
		event-hall-sensor {
			label = "Hall Effect Sensor";
			gpios = <&tlmm 155 GPIO_ACTIVE_LOW>;
			linux,input-type = <EV_SW>;
			linux,code = <SW_LID>;
			linux,can-disable;
			wakeup-source;
		};
	};

	pmic-glink {
		compatible = "qcom,qcm6490-pmic-glink", "qcom,pmic-glink";

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

		orientation-gpios = <&tlmm 140 GPIO_ACTIVE_HIGH>;

		connector@0 {
			compatible = "usb-c-connector";
			reg = <0>;
			power-role = "dual";
			data-role = "dual";

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

				port@0 {
					reg = <0>;

					pmic_glink_hs_in: endpoint {
						remote-endpoint = <&usb_1_dwc3_hs>;
					};
				};

				port@1 {
					reg = <1>;

					pmic_glink_ss_in: endpoint {
						remote-endpoint = <&redriver_ss_out>;
					};
				};

				port@2 {
					reg = <2>;

					pmic_glink_sbu: endpoint {
						remote-endpoint = <&ocp96011_sbu_mux>;
					};
				};
			};
		};
	};

	vreg_afvdd_2p8: regulator-afvdd-2p8 {
		compatible = "regulator-fixed";
		regulator-name = "AFVDD_2P8";
		regulator-min-microvolt = <2800000>;
		regulator-max-microvolt = <2800000>;
		gpio = <&tlmm 68 GPIO_ACTIVE_HIGH>;
		enable-active-high;
		vin-supply = <&vreg_bob>;
	};

	vreg_ois_avdd0_1p8: regulator-ois-avdd0-1p8 {
		compatible = "regulator-fixed";
		regulator-name = "OIS_AVDD0_1P8";
		regulator-min-microvolt = <1800000>;
		regulator-max-microvolt = <1800000>;
		gpio = <&tlmm 157 GPIO_ACTIVE_HIGH>;
		enable-active-high;
		vin-supply = <&vreg_bob>;
	};

	vreg_ois_dvdd_1p1: regulator-ois-dvdd-1p1 {
		compatible = "regulator-fixed";
		regulator-name = "OIS_DVDD_1P1";
		regulator-min-microvolt = <1100000>;
		regulator-max-microvolt = <1100000>;
		gpio = <&tlmm 97 GPIO_ACTIVE_HIGH>;
		enable-active-high;
		vin-supply = <&vreg_s8b>;
	};

	vreg_oled_dvdd: regulator-oled-dvdd {
		compatible = "regulator-fixed";
		regulator-name = "oled_dvdd";
		regulator-min-microvolt = <1200000>;
		regulator-max-microvolt = <1200000>;

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

		vin-supply = <&vreg_s1b>;

		regulator-boot-on;
	};

	vreg_oled_vci: regulator-oled-vci {
		compatible = "regulator-fixed";
		regulator-name = "oled_vci";
		regulator-min-microvolt = <3000000>;
		regulator-max-microvolt = <3000000>;

		gpio = <&pm8350c_gpios 7 GPIO_ACTIVE_HIGH>;
		enable-active-high;

		vin-supply = <&vreg_l13c>;

		regulator-boot-on;
	};

	vreg_usb_redrive_1v8: regulator-usb-redrive-1v8 {
		compatible = "regulator-fixed";
		regulator-name = "USB_REDRIVE_1V8";
		regulator-min-microvolt = <1800000>;
		regulator-max-microvolt = <1800000>;

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

		vin-supply = <&vreg_bob>;

		regulator-boot-on;

		pinctrl-0 = <&usb_redrive_1v8_en_default>;
		pinctrl-names = "default";
	};

	vph_pwr: regulator-vph-pwr {
		compatible = "regulator-fixed";

		regulator-name = "vph_pwr";
		regulator-min-microvolt = <3700000>;
		regulator-max-microvolt = <3700000>;

		regulator-always-on;
		regulator-boot-on;
	};

	vreg_vtof_ldo_2p8: regulator-vtof-ldo-2p8 {
		compatible = "regulator-fixed";
		regulator-name = "VTOF_LDO_2P8";
		regulator-min-microvolt = <2800000>;
		regulator-max-microvolt = <2800000>;
		regulator-enable-ramp-delay = <233>;

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

		vin-supply = <&vreg_bob>;
	};

	reserved-memory {
		cont_splash_mem: cont-splash@e1000000 {
			reg = <0x0 0xe1000000 0x0 0x2300000>;
			no-map;
		};

		cdsp_mem: cdsp@88f00000 {
			reg = <0x0 0x88f00000 0x0 0x1e00000>;
			no-map;
		};

		removed_mem: removed@c0000000 {
			reg = <0x0 0xc0000000 0x0 0x5100000>;
			no-map;
		};

		rmtfs_mem: memory@f8500000 {
			compatible = "qcom,rmtfs-mem";
			reg = <0x0 0xf8500000 0x0 0x600000>;
			no-map;

			qcom,client-id = <1>;
			qcom,vmid = <QCOM_SCM_VMID_MSS_MSA>, <QCOM_SCM_VMID_NAV>;
		};
	};

	thermal-zones {
		camera-thermal {
			polling-delay-passive = <0>;

			thermal-sensors = <&pmk8350_adc_tm 2>;

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

		chg-skin-thermal {
			polling-delay-passive = <0>;

			thermal-sensors = <&pm7250b_adc_tm 0>;

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

		conn-thermal {
			polling-delay-passive = <0>;

			thermal-sensors = <&pm7250b_adc_tm 1>;

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

		mem-thermal {
			polling-delay-passive = <0>;

			thermal-sensors = <&pm7250b_adc_tm 2>;

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

		pm8008-thermal {
			polling-delay-passive = <100>;
			thermal-sensors = <&pm8008>;

			trips {
				trip0 {
					temperature = <95000>;
					hysteresis = <0>;
					type = "passive";
				};

				trip1 {
					temperature = <115000>;
					hysteresis = <0>;
					type = "critical";
				};
			};
		};

		quiet-thermal {
			polling-delay-passive = <0>;

			thermal-sensors = <&pmk8350_adc_tm 1>;

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

		rear-cam-thermal {
			polling-delay-passive = <0>;

			thermal-sensors = <&pmk8350_adc_tm 4>;

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

		sdm-skin-thermal {
			polling-delay-passive = <0>;

			thermal-sensors = <&pmk8350_adc_tm 3>;

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

		xo-thermal {
			polling-delay-passive = <0>;

			thermal-sensors = <&pmk8350_adc_tm 0>;

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

&apps_rsc {
	regulators-0 {
		compatible = "qcom,pm7325-rpmh-regulators";

		vdd-l1-l4-l12-l15-supply = <&vreg_s7b>;
		vdd-l2-l7-supply = <&vreg_bob>;
		vdd-l6-l9-l10-supply = <&vreg_s8b>;
		vdd-l8-supply = <&vreg_s7b>;
		vdd-l11-l17-l18-l19-supply = <&vreg_s1b>;
		vdd-l13-supply = <&vreg_s7b>;
		vdd-l14-l16-supply = <&vreg_s8b>;
		vdd-s1-supply = <&vph_pwr>;
		vdd-s7-supply = <&vph_pwr>;
		vdd-s8-supply = <&vph_pwr>;

		qcom,pmic-id = "b";

		vreg_s1b: smps1 {
			regulator-name = "vreg_s1b";
			regulator-min-microvolt = <1840000>;
			regulator-max-microvolt = <2040000>;
		};

		/*
		 * s2b (smps2) is ebi.lvl
		 * s3b-s4b-s5b (smps3-smps4-smps5) is VDD_APC1
		 * s6b (smps6) is VDD_APC0
		 */

		vreg_s7b: smps7 {
			regulator-name = "vreg_s7b";
			regulator-min-microvolt = <535000>;
			regulator-max-microvolt = <1120000>;
		};

		vreg_s8b: smps8 {
			regulator-name = "vreg_s8b";
			regulator-min-microvolt = <1200000>;
			regulator-max-microvolt = <1500000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_RET>;
		};

		vreg_l1b: ldo1 {
			regulator-name = "vreg_l1b";
			regulator-min-microvolt = <825000>;
			regulator-max-microvolt = <925000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l2b: ldo2 {
			regulator-name = "vreg_l2b";
			regulator-min-microvolt = <2700000>;
			regulator-max-microvolt = <3544000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l3b: ldo3 {
			regulator-name = "vreg_l3b";
			regulator-min-microvolt = <312000>;
			regulator-max-microvolt = <910000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		/*
		 * l4b (ldo4) is lmx.lvl
		 * l5b (ldo5) is lcx.lvl
		 */

		vreg_l6b: ldo6 {
			regulator-name = "vreg_l6b";
			regulator-min-microvolt = <1140000>;
			regulator-max-microvolt = <1260000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l7b: ldo7 {
			regulator-name = "vreg_l7b";
			/* Constrained for UFS VCC, at least until UFS driver scales voltage */
			regulator-min-microvolt = <2952000>;
			regulator-max-microvolt = <2952000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l8b: ldo8 {
			regulator-name = "vreg_l8b";
			regulator-min-microvolt = <870000>;
			regulator-max-microvolt = <970000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l9b: ldo9 {
			regulator-name = "vreg_l9b";
			regulator-min-microvolt = <1200000>;
			regulator-max-microvolt = <1304000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		/* l10b (ldo10) is PMK7325 VDD_ACTIVE */

		vreg_l11b: ldo11 {
			regulator-name = "vreg_l11b";
			regulator-min-microvolt = <1504000>;
			regulator-max-microvolt = <2000000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l12b: ldo12 {
			regulator-name = "vreg_l12b";
			regulator-min-microvolt = <751000>;
			regulator-max-microvolt = <824000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l13b: ldo13 {
			regulator-name = "vreg_l13b";
			regulator-min-microvolt = <530000>;
			regulator-max-microvolt = <824000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l14b: ldo14 {
			regulator-name = "vreg_l14b";
			regulator-min-microvolt = <1080000>;
			regulator-max-microvolt = <1304000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l15b: ldo15 {
			regulator-name = "vreg_l15b";
			regulator-min-microvolt = <765000>;
			regulator-max-microvolt = <1020000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l16b: ldo16 {
			regulator-name = "vreg_l16b";
			regulator-min-microvolt = <1100000>;
			regulator-max-microvolt = <1300000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l17b: ldo17 {
			regulator-name = "vreg_l17b";
			regulator-min-microvolt = <1700000>;
			regulator-max-microvolt = <1900000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l18b: ldo18 {
			regulator-name = "vreg_l18b";
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <2000000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l19b: ldo19 {
			regulator-name = "vreg_l19b";
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <2000000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};
	};

	regulators-1 {
		compatible = "qcom,pm8350c-rpmh-regulators";

		vdd-bob-supply = <&vph_pwr>;
		vdd-l1-l12-supply = <&vreg_s1b>;
		vdd-l2-l8-supply = <&vreg_s1b>;
		vdd-l3-l4-l5-l7-l13-supply = <&vreg_bob>;
		vdd-l6-l9-l11-supply = <&vreg_bob>;
		vdd-l10-supply = <&vreg_s7b>;
		vdd-s1-supply = <&vph_pwr>;
		vdd-s9-supply = <&vph_pwr>;

		qcom,pmic-id = "c";

		vreg_s1c: smps1 {
			regulator-name = "vreg_s1c";
			regulator-min-microvolt = <2190000>;
			regulator-max-microvolt = <2210000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		/*
		 * s2c-s3c-s4c (smps2-smps3-smps4) is cx.lvl
		 * s5c-s6c (smps5-smps6) is mss.lvl
		 * s7c-s8c (smps7-smps8) is gfx.lvl
		 */

		vreg_s9c: smps9 {
			regulator-name = "vreg_s9c";
			regulator-min-microvolt = <1010000>;
			regulator-max-microvolt = <1170000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		/* s10c (smps10) is mx.lvl */

		vreg_l1c: ldo1 {
			regulator-name = "vreg_l1c";
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1980000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l2c: ldo2 {
			regulator-name = "vreg_l2c";
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1950000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l3c: ldo3 {
			regulator-name = "vreg_l3c";
			regulator-min-microvolt = <3000000>;
			regulator-max-microvolt = <3400000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l4c: ldo4 {
			regulator-name = "vreg_l4c";
			regulator-min-microvolt = <1620000>;
			regulator-max-microvolt = <3300000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l5c: ldo5 {
			regulator-name = "vreg_l5c";
			regulator-min-microvolt = <1620000>;
			regulator-max-microvolt = <3300000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l6c: ldo6 {
			regulator-name = "vreg_l6c";
			regulator-min-microvolt = <1650000>;
			regulator-max-microvolt = <3544000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l7c: ldo7 {
			regulator-name = "vreg_l7c";
			regulator-min-microvolt = <3000000>;
			regulator-max-microvolt = <3544000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l8c: ldo8 {
			regulator-name = "vreg_l8c";
			regulator-min-microvolt = <1620000>;
			regulator-max-microvolt = <2000000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
			/* Hall sensor VDD */
			regulator-always-on;
		};

		vreg_l9c: ldo9 {
			regulator-name = "vreg_l9c";
			regulator-min-microvolt = <2700000>;
			regulator-max-microvolt = <3544000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l10c: ldo10 {
			regulator-name = "vreg_l10c";
			regulator-min-microvolt = <720000>;
			regulator-max-microvolt = <1050000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l11c: ldo11 {
			regulator-name = "vreg_l11c";
			regulator-min-microvolt = <2800000>;
			regulator-max-microvolt = <3544000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l12c: ldo12 {
			regulator-name = "vreg_l12c";
			regulator-min-microvolt = <1650000>;
			regulator-max-microvolt = <2000000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l13c: ldo13 {
			regulator-name = "vreg_l13c";
			regulator-min-microvolt = <2700000>;
			regulator-max-microvolt = <3544000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_bob: bob {
			regulator-name = "vreg_bob";
			regulator-min-microvolt = <3008000>;
			regulator-max-microvolt = <3960000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_AUTO>;
		};
	};
};

&camss {
	vdda-phy-supply = <&vreg_l10c>;
	vdda-pll-supply = <&vreg_l6b>;

	status = "okay";

	ports {
		port@3 {
			csiphy3_ep: endpoint {
				data-lanes = <0 1 2 3>;
				bus-type = <MEDIA_BUS_TYPE_CSI2_DPHY>;
				remote-endpoint = <&camera_s5kjn1_ep>;
			};
		};
	};
};

&cci0 {
	status = "okay";
};

&cci0_i2c0 {
	/* IMX800 @ 1a */

	eeprom@50 {
		compatible = "puya,p24c256c", "atmel,24c256";
		reg = <0x50>;
		vcc-supply = <&vreg_l6p>;
		read-only;
	};
};

&cci0_i2c1 {
	camera_imx858_dw9800k: actuator@e {
		compatible = "dongwoon,dw9800k";
		reg = <0x0e>;
		vdd-supply = <&vreg_afvdd_2p8>;

		dongwoon,sac-mode = <1>;
		dongwoon,vcm-prescale = <16>;
	};

	/* IMX858 @ 29 */

	eeprom@54 {
		compatible = "giantec,gt24p128f", "atmel,24c128";
		reg = <0x54>;
		vcc-supply = <&vreg_l6p>;
		read-only;
	};
};

&cci1 {
	status = "okay";
};

&cci1_i2c1 {
	camera@10 {
		compatible = "samsung,s5kjn1";
		reg = <0x10>;

		vdda-supply = <&vreg_l3p>;
		vddd-supply = <&vreg_l2p>;
		vddio-supply = <&vreg_l6p>;

		clocks = <&camcc CAM_CC_MCLK3_CLK>;
		assigned-clocks = <&camcc CAM_CC_MCLK3_CLK>;
		assigned-clock-rates = <24000000>;

		reset-gpios = <&tlmm 78 GPIO_ACTIVE_LOW>;

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

		orientation = <MEDIA_ORIENTATION_FRONT>;
		rotation = <270>;

		port {
			camera_s5kjn1_ep: endpoint {
				data-lanes = <1 2 3 4>;
				link-frequencies = /bits/ 64 <700000000>;
				remote-endpoint = <&csiphy3_ep>;
			};
		};
	};

	eeprom@51 {
		compatible = "giantec,gt24p128f", "atmel,24c128";
		reg = <0x51>;
		vcc-supply = <&vreg_l6p>;
		read-only;
	};
};

&gcc {
	protected-clocks = <GCC_CFG_NOC_LPASS_CLK>,
			   <GCC_EDP_CLKREF_EN>,
			   <GCC_MSS_CFG_AHB_CLK>,
			   <GCC_MSS_GPLL0_MAIN_DIV_CLK_SRC>,
			   <GCC_MSS_OFFLINE_AXI_CLK>,
			   <GCC_MSS_Q6SS_BOOT_CLK_SRC>,
			   <GCC_MSS_Q6_MEMNOC_AXI_CLK>,
			   <GCC_MSS_SNOC_AXI_CLK>,
			   <GCC_QSPI_CNOC_PERIPH_AHB_CLK>,
			   <GCC_QSPI_CORE_CLK>,
			   <GCC_QSPI_CORE_CLK_SRC>,
			   <GCC_SEC_CTRL_CLK_SRC>,
			   <GCC_WPSS_AHB_BDG_MST_CLK>,
			   <GCC_WPSS_AHB_CLK>,
			   <GCC_WPSS_RSCP_CLK>;
};

&gpi_dma0 {
	status = "okay";
};

&gpi_dma1 {
	status = "okay";
};

&gpu {
	status = "okay";
};

&gpu_zap_shader {
	firmware-name = "qcom/qcm6490/fairphone5/a660_zap.mbn";
};

&i2c1 {
	status = "okay";

	pm8008: pmic@8 {
		compatible = "qcom,pm8008";
		reg = <0x8>;

		interrupts-extended = <&tlmm 25 IRQ_TYPE_EDGE_RISING>;
		reset-gpios = <&pm8350c_gpios 3 GPIO_ACTIVE_LOW>;

		vdd-l1-l2-supply = <&vreg_s8b>;
		vdd-l3-l4-supply = <&vreg_bob>;
		vdd-l5-supply = <&vreg_bob>;
		vdd-l6-supply = <&vreg_s1b>;
		vdd-l7-supply = <&vreg_bob>;

		pinctrl-names = "default";
		pinctrl-0 = <&pm8008_int_default>, <&pm8008_reset_n_default>;

		gpio-controller;
		#gpio-cells = <2>;
		gpio-ranges = <&pm8008 0 0 2>;

		interrupt-controller;
		#interrupt-cells = <2>;

		#thermal-sensor-cells = <0>;

		regulators {
			vreg_l1p: ldo1 {
				regulator-name = "vreg_l1p";
				regulator-min-microvolt = <1000000>;
				regulator-max-microvolt = <1200000>;
			};

			vreg_l2p: ldo2 {
				regulator-name = "vreg_l2p";
				regulator-min-microvolt = <950000>;
				regulator-max-microvolt = <1152000>;
			};

			vreg_l3p: ldo3 {
				regulator-name = "vreg_l3p";
				regulator-min-microvolt = <2700000>;
				regulator-max-microvolt = <3000000>;
			};

			vreg_l4p: ldo4 {
				regulator-name = "vreg_l4p";
				regulator-min-microvolt = <2700000>;
				regulator-max-microvolt = <2900000>;
			};

			vreg_l5p: ldo5 {
				regulator-name = "vreg_l5p";
				regulator-min-microvolt = <2704000>;
				regulator-max-microvolt = <2900000>;
			};

			vreg_l6p: ldo6 {
				regulator-name = "vreg_l6p";
				regulator-min-microvolt = <1700000>;
				regulator-max-microvolt = <1904000>;
				/* Pull-up for CCI I2C busses */
				regulator-always-on;
			};

			vreg_l7p: ldo7 {
				regulator-name = "vreg_l7p";
				regulator-min-microvolt = <2700000>;
				regulator-max-microvolt = <3000000>;
			};
		};
	};

	/* Pixelworks @ 26 */

	typec-mux@42 {
		compatible = "ocs,ocp96011", "fcs,fsa4480";
		reg = <0x42>;

		interrupts-extended = <&tlmm 7 IRQ_TYPE_LEVEL_LOW>;

		vcc-supply = <&vreg_bob>;

		mode-switch;
		orientation-switch;

		port {
			ocp96011_sbu_mux: endpoint {
				remote-endpoint = <&pmic_glink_sbu>;
				data-lanes = <1 0>;
			};
		};
	};

	vibrator@5a {
		compatible = "awinic,aw86927";
		reg = <0x5a>;

		interrupts-extended = <&tlmm 101 IRQ_TYPE_EDGE_FALLING>;
		reset-gpios = <&tlmm 100 GPIO_ACTIVE_LOW>;

		pinctrl-0 = <&aw86927_int_default>;
		pinctrl-names = "default";
	};
};

&i2c2 {
	status = "okay";

	/* Top speaker / ear speaker */
	aw88261_l: audio-codec@34 {
		compatible = "awinic,aw88261";
		reg = <0x34>;

		dvdd-supply = <&vreg_l18b>;
		sound-name-prefix = "Amplifier L";
		firmware-name = "qcom/qcm6490/fairphone5/aw88261_acf.bin";

		awinic,audio-channel = <0>;

		#sound-dai-cells = <0>;
	};

	/* Bottom speaker */
	aw88261_r: audio-codec@35 {
		compatible = "awinic,aw88261";
		reg = <0x35>;

		dvdd-supply = <&vreg_l18b>;
		sound-name-prefix = "Amplifier R";
		firmware-name = "qcom/qcm6490/fairphone5/aw88261_acf.bin";

		awinic,audio-channel = <1>;

		#sound-dai-cells = <0>;
	};
};

&i2c4 {
	status = "okay";

	typec-mux@1a {
		compatible = "nxp,ptn36502";
		reg = <0x1a>;

		vdd18-supply = <&vreg_usb_redrive_1v8>;

		retimer-switch;
		orientation-switch;

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

			port@0 {
				reg = <0>;

				redriver_ss_out: endpoint {
					remote-endpoint = <&pmic_glink_ss_in>;
				};
			};

			port@1 {
				reg = <1>;

				redriver_ss_in: endpoint {
					remote-endpoint = <&usb_dp_qmpphy_out>;
				};
			};
		};
	};
};

&i2c9 {
	status = "okay";

	/* ST21NFC NFC @ 28 */
	/* VL53L3 ToF @ 29 */
};

&ipa {
	firmware-name = "qcom/qcm6490/fairphone5/ipa_fws.mbn";

	status = "okay";
};

&lpass_audiocc {
	compatible = "qcom,qcm6490-lpassaudiocc";
	/delete-property/ power-domains;
};

&mdss {
	status = "okay";
};

&mdss_dp {
	status = "okay";
};

&mdss_dp_out {
	data-lanes = <0 1>;
};

&mdss_dsi {
	vdda-supply = <&vreg_l6b>;
	status = "okay";

	panel@0 {
		compatible = "fairphone,fp5-rm692e5-boe", "raydium,rm692e5";
		reg = <0>;

		reset-gpios = <&tlmm 44 GPIO_ACTIVE_LOW>;

		vci-supply = <&vreg_oled_vci>;
		vddio-supply = <&vreg_l12c>;
		dvdd-supply = <&vreg_oled_dvdd>;

		pinctrl-0 = <&disp_reset_n_active>, <&mdp_vsync>;
		pinctrl-1 = <&disp_reset_n_suspend>, <&mdp_vsync>;
		pinctrl-names = "default", "sleep";

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

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

&mdss_dsi_phy {
	vdds-supply = <&vreg_l10c>;
	status = "okay";
};

&pm7250b_adc {
	pinctrl-0 = <&pm7250b_adc_default>;
	pinctrl-names = "default";

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

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

	channel@53 {
		reg = <ADC5_GPIO2_100K_PU>;
		qcom,ratiometric;
		qcom,hw-settle-time = <200>;
		qcom,pre-scaling = <1 1>;
		label = "mem_therm";
	};
};

&pm7250b_adc_tm {
	status = "okay";

	charger-skin-therm@0 {
		reg = <0>;
		io-channels = <&pm7250b_adc ADC5_AMUX_THM1_100K_PU>;
		qcom,ratiometric;
		qcom,hw-settle-time-us = <200>;
	};

	conn-therm@1 {
		reg = <1>;
		io-channels = <&pm7250b_adc ADC5_AMUX_THM3_100K_PU>;
		qcom,ratiometric;
		qcom,hw-settle-time-us = <200>;
	};

	mem-therm@2 {
		reg = <2>;
		io-channels = <&pm7250b_adc ADC5_GPIO2_100K_PU>;
		qcom,ratiometric;
		qcom,hw-settle-time-us = <200>;
	};
};

&pm7250b_gpios {
	pm7250b_adc_default: adc-default-state {
		pins = "gpio12";
		function = PMIC_GPIO_FUNC_NORMAL;
		bias-high-impedance;
	};
};

&pm7325_gpios {
	volume_down_default: volume-down-default-state {
		pins = "gpio6";
		function = PMIC_GPIO_FUNC_NORMAL;
		power-source = <1>;
		bias-pull-up;
		input-enable;
	};
};

&pm8350c_flash {
	status = "okay";

	led-0 {
		function = LED_FUNCTION_FLASH;
		color = <LED_COLOR_ID_WHITE>;
		led-sources = <1>, <4>;
		led-max-microamp = <500000>;
		flash-max-microamp = <1500000>;
		flash-max-timeout-us = <1280000>;
	};
};

&pmk8350_adc_tm {
	status = "okay";

	xo-therm@0 {
		reg = <0>;
		io-channels = <&pmk8350_vadc PMK8350_ADC7_AMUX_THM1_100K_PU>;
		qcom,ratiometric;
		qcom,hw-settle-time-us = <200>;
	};

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

	cam-flash-therm@2 {
		reg = <2>;
		io-channels = <&pmk8350_vadc PM7325_ADC7_AMUX_THM2_100K_PU>;
		qcom,ratiometric;
		qcom,hw-settle-time-us = <200>;
	};

	sdm-skin-therm@3 {
		reg = <3>;
		io-channels = <&pmk8350_vadc PM7325_ADC7_AMUX_THM3_100K_PU>;
		qcom,ratiometric;
		qcom,hw-settle-time-us = <200>;
	};

	wide-rfc-therm@4 {
		reg = <4>;
		io-channels = <&pmk8350_vadc PM7325_ADC7_AMUX_THM4_100K_PU>;
		qcom,ratiometric;
		qcom,hw-settle-time-us = <200>;
	};
};

&pm8350c_gpios {
	pm8008_reset_n_default: pm8008-reset-n-default-state {
		pins = "gpio3";
		function = PMIC_GPIO_FUNC_NORMAL;
		bias-pull-down;
	};
};

&pmk8350_rtc {
	status = "okay";
};

&pmk8350_vadc {
	status = "okay";

	channel@44 {
		reg = <PMK8350_ADC7_AMUX_THM1_100K_PU>;
		qcom,ratiometric;
		qcom,hw-settle-time = <200>;
		qcom,pre-scaling = <1 1>;
		label = "pmk8350_xo_therm";
	};

	channel@144 {
		reg = <PM7325_ADC7_AMUX_THM1_100K_PU>;
		qcom,ratiometric;
		qcom,hw-settle-time = <200>;
		qcom,pre-scaling = <1 1>;
		label = "pm7325_quiet_therm";
	};

	channel@145 {
		reg = <PM7325_ADC7_AMUX_THM2_100K_PU>;
		qcom,ratiometric;
		qcom,hw-settle-time = <200>;
		qcom,pre-scaling = <1 1>;
		label = "pm7325_cam_flash_therm";
	};

	channel@146 {
		reg = <PM7325_ADC7_AMUX_THM3_100K_PU>;
		qcom,ratiometric;
		qcom,hw-settle-time = <200>;
		qcom,pre-scaling = <1 1>;
		label = "pm7325_sdm_skin_therm";
	};

	channel@147 {
		reg = <PM7325_ADC7_AMUX_THM4_100K_PU>;
		qcom,ratiometric;
		qcom,hw-settle-time = <200>;
		qcom,pre-scaling = <1 1>;
		label = "pm7325_wide_rfc_therm";
	};
};

&pon_pwrkey {
	status = "okay";
};

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

&q6afedai {
	dai@127 {
		reg = <QUINARY_MI2S_RX>;
		qcom,sd-lines = <0>;
	};
};

&qup_spi13_cs {
	drive-strength = <6>;
	bias-disable;
};

&qup_spi13_data_clk {
	drive-strength = <6>;
	bias-disable;
};

&qup_uart5_rx {
	drive-strength = <2>;
	bias-disable;
};

&qup_uart5_tx {
	drive-strength = <2>;
	bias-disable;
};

&qupv3_id_0 {
	status = "okay";
};

&qupv3_id_1 {
	status = "okay";
};

&remoteproc_adsp {
	firmware-name = "qcom/qcm6490/fairphone5/adsp.mbn";
	status = "okay";
};

&remoteproc_cdsp {
	firmware-name = "qcom/qcm6490/fairphone5/cdsp.mbn";
	status = "okay";
};

&remoteproc_mpss {
	firmware-name = "qcom/qcm6490/fairphone5/modem.mbn";
	status = "okay";
};

&remoteproc_wpss {
	firmware-name = "qcom/qcm6490/fairphone5/wpss.mbn";
	status = "okay";
};

&sdc2_clk {
	drive-strength = <16>;
	bias-disable;
};

&sdc2_cmd {
	drive-strength = <10>;
	bias-pull-up;
};

&sdc2_data {
	drive-strength = <10>;
	bias-pull-up;
};

&sdhc_2 {
	vmmc-supply = <&vreg_l9c>;
	vqmmc-supply = <&vreg_l6c>;

	pinctrl-0 = <&sdc2_clk>, <&sdc2_cmd>, <&sdc2_data>;
	pinctrl-1 = <&sdc2_clk_sleep>, <&sdc2_cmd_sleep>, <&sdc2_data_sleep>;

	status = "okay";
};

&sound {
	compatible = "fairphone,fp5-sndcard";
	model = "Fairphone 5";

	pinctrl-0 = <&lpass_i2s1_active>;
	pinctrl-1 = <&lpass_i2s1_sleep>;
	pinctrl-names = "default",
			"sleep";

	mm1-dai-link {
		link-name = "MultiMedia1";

		cpu {
			sound-dai = <&q6asmdai MSM_FRONTEND_DAI_MULTIMEDIA1>;
		};
	};

	i2s-dai-link {
		link-name = "Quinary MI2S Playback";

		codec {
			sound-dai = <&aw88261_l>, <&aw88261_r>;
		};

		cpu {
			sound-dai = <&q6afedai QUINARY_MI2S_RX>;
		};

		platform {
			sound-dai = <&q6routing>;
		};
	};

	displayport-rx-dai-link {
		link-name = "DisplayPort Playback";

		codec {
			sound-dai = <&mdss_dp>;
		};

		cpu {
			sound-dai = <&q6afedai DISPLAY_PORT_RX>;
		};

		platform {
			sound-dai = <&q6routing>;
		};
	};

	usb-dai-link {
		link-name = "USB Playback";

		codec {
			sound-dai = <&q6usbdai USB_RX>;
		};

		cpu {
			sound-dai = <&q6afedai USB_RX>;
		};

		platform {
			sound-dai = <&q6routing>;
		};
	};
};

&spi13 {
	status = "okay";

	touchscreen@0 {
		compatible = "goodix,gt9897";
		reg = <0>;
		interrupts-extended = <&tlmm 81 IRQ_TYPE_LEVEL_LOW>;
		reset-gpios = <&tlmm 105 GPIO_ACTIVE_LOW>;
		avdd-supply = <&vreg_l3c>;
		vddio-supply = <&vreg_l2c>;
		spi-max-frequency = <1000000>;
		touchscreen-size-x = <1224>;
		touchscreen-size-y = <2700>;
	};
};

&tlmm {
	/*
	 * 32-33: SMB1394 (SPMI)
	 * 56-59: fingerprint reader (SPI)
	 */
	gpio-reserved-ranges = <32 2>, <56 4>;

	pm8008_int_default: pm8008-int-default-state {
		pins = "gpio25";
		function = "gpio";
		drive-strength = <2>;
		bias-disable;
	};

	qup_uart7_sleep_cts: qup-uart7-sleep-cts-state {
		pins = "gpio28";
		function = "gpio";
		/*
		 * Configure a bias-bus-hold on CTS to lower power
		 * usage when Bluetooth is turned off. Bus hold will
		 * maintain a low power state regardless of whether
		 * the Bluetooth module drives the pin in either
		 * direction or leaves the pin fully unpowered.
		 */
		bias-bus-hold;
	};

	qup_uart7_sleep_rts: qup-uart7-sleep-rts-state {
		pins = "gpio29";
		function = "gpio";
		/*
		 * Configure pull-down on RTS. As RTS is active low
		 * signal, pull it low to indicate the BT SoC that it
		 * can wakeup the system anytime from suspend state by
		 * pulling RX low (by sending wakeup bytes).
		 */
		bias-pull-down;
	};

	qup_uart7_sleep_tx: qup-uart7-sleep-tx-state {
		pins = "gpio30";
		function = "gpio";
		/*
		 * Configure pull-up on TX when it isn't actively driven
		 * to prevent BT SoC from receiving garbage during sleep.
		 */
		bias-pull-up;
	};

	qup_uart7_sleep_rx: qup-uart7-sleep-rx-state {
		pins = "gpio31";
		function = "gpio";
		/*
		 * Configure a pull-up on RX. This is needed to avoid
		 * garbage data when the TX pin of the Bluetooth module
		 * is floating which may cause spurious wakeups.
		 */
		bias-pull-up;
	};

	disp_reset_n_active: disp-reset-n-active-state {
		pins = "gpio44";
		function = "gpio";
		drive-strength = <8>;
		bias-disable;
	};

	disp_reset_n_suspend: disp-reset-n-suspend-state {
		pins = "gpio44";
		function = "gpio";
		drive-strength = <2>;
		bias-pull-down;
	};

	usb_redrive_1v8_en_default: usb-redrive-1v8-en-default-state {
		pins = "gpio61";
		function = "gpio";
		drive-strength = <2>;
		bias-disable;
		output-high;
	};

	mdp_vsync: mdp-vsync-state {
		pins = "gpio80";
		function = "mdp_vsync";
		drive-strength = <2>;
		bias-pull-down;
	};

	bluetooth_enable_default: bluetooth-enable-default-state {
		pins = "gpio85";
		function = "gpio";
		output-low;
		bias-disable;
	};

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

	aw86927_int_default: aw86927-int-default-state {
		pins = "gpio101";
		function = "gpio";
		drive-strength = <2>;
		bias-pull-up;
	};

	hall_sensor_default: hall-sensor-default-state {
		pins = "gpio155";
		function = "gpio";
		drive-strength = <2>;
		bias-pull-up;
	};
};

&uart5 {
	status = "okay";
};

&uart7 {
	/delete-property/interrupts;
	interrupts-extended = <&intc GIC_SPI 608 IRQ_TYPE_LEVEL_HIGH>,
			      <&tlmm 31 IRQ_TYPE_EDGE_FALLING>;

	pinctrl-1 = <&qup_uart7_sleep_cts>, <&qup_uart7_sleep_rts>, <&qup_uart7_sleep_tx>, <&qup_uart7_sleep_rx>;
	pinctrl-names = "default", "sleep";

	status = "okay";

	bluetooth: bluetooth {
		compatible = "qcom,wcn6750-bt";

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

		enable-gpios = <&tlmm 85 GPIO_ACTIVE_HIGH>;
		swctrl-gpios = <&tlmm 86 GPIO_ACTIVE_HIGH>;

		vddio-supply = <&vreg_l19b>;
		vddaon-supply = <&vreg_s7b>;
		vddbtcxmx-supply = <&vreg_s7b>;
		vddrfacmn-supply = <&vreg_s7b>;
		vddrfa0p8-supply = <&vreg_s7b>;
		vddrfa1p7-supply = <&vreg_s1b>;
		vddrfa1p2-supply = <&vreg_s8b>;
		vddrfa2p2-supply = <&vreg_s1c>;
		vddasd-supply = <&vreg_l11c>;

		max-speed = <3200000>;
	};
};

&ufs_mem_hc {
	reset-gpios = <&tlmm 175 GPIO_ACTIVE_LOW>;

	vcc-supply = <&vreg_l7b>;
	vcc-max-microamp = <800000>;
	/*
	 * Technically l9b enables an eLDO (supplied by s1b) which then powers
	 * VCCQ2 of the UFS.
	 */
	vccq-supply = <&vreg_l9b>;
	vccq-max-microamp = <900000>;

	status = "okay";
};

&ufs_mem_phy {
	vdda-phy-supply = <&vreg_l10c>;
	vdda-pll-supply = <&vreg_l6b>;

	status = "okay";
};

&usb_1 {
	dr_mode = "otg";
	usb-role-switch;

	status = "okay";
};

&usb_1_dwc3_hs {
	remote-endpoint = <&pmic_glink_hs_in>;
};

&usb_1_hsphy {
	vdda-pll-supply = <&vreg_l10c>;
	vdda18-supply = <&vreg_l1c>;
	vdda33-supply = <&vreg_l2b>;

	qcom,hs-crossover-voltage-microvolt = <28000>;
	qcom,hs-output-impedance-micro-ohms = <2600000>;
	qcom,hs-rise-fall-time-bp = <5430>;
	qcom,hs-disconnect-bp = <1743>;
	qcom,hs-amplitude-bp = <2430>;

	qcom,pre-emphasis-amplitude-bp = <20000>;
	qcom,pre-emphasis-duration-bp = <20000>;

	qcom,squelch-detector-bp = <(-2090)>;

	status = "okay";
};

&usb_1_qmpphy {
	vdda-phy-supply = <&vreg_l1b>;
	vdda-pll-supply = <&vreg_l6b>;

	status = "okay";
};

&usb_dp_qmpphy_out {
	remote-endpoint = <&redriver_ss_in>;
};

&venus {
	firmware-name = "qcom/qcm6490/fairphone5/venus.mbn";
	status = "okay";
};

&wifi {
	qcom,calibration-variant = "Fairphone_5";
	status = "okay";
};