#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/input/input.h>

#include "anorak-pmic-overlay.dtsi"
#include "anorak-thermal-overlay.dtsi"

&sdhc_2 {
	status = "ok";

	vdd-supply = <&L12B>;
	qcom,vdd-voltage-level = <2960000 2960000>;
	qcom,vdd-current-level = <0 800000>;

	vdd-io-supply = <&L18B>;
	qcom,vdd-io-voltage-level = <1800000 2960000>;
	qcom,vdd-io-current-level = <0 22000>;

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

	cd-gpios = <&tlmm 175 GPIO_ACTIVE_LOW>;
};

&ufsphy_mem {
	compatible = "qcom,ufs-phy-qmp-v4-anarok";

	vdda-phy-supply = <&L2F>;
	vdda-pll-supply = <&L2C>;
	vdda-phy-max-microamp = <138000>;
	vdda-pll-max-microamp = <18300>;

	status = "ok";
};

&ufshc_mem {
	vdd-hba-supply = <&gcc_ufs_phy_gdsc>;

	vcc-supply = <&L13B>;
	vcc-max-microamp = <1300000>;

	vccq-supply = <&L3B>;
	vccq-max-microamp = <1200000>;

	qcom,vddp-ref-clk-supply = <&L3B>;
	qcom,vddp-ref-clk-max-microamp = <100>;

	status = "ok";
};

&tlmm {
	nordic_gpio6_suspend: nordic_gpio6_suspend {
		mux {
			pins = "gpio135";
			function = "gpio";
		};

		config {
			pins = "gpio135";
			drive-strength = <8>;
			bias-disable = <0>;
			output-high;
		};
	};

	/* active low due to hmd nordic */
	nordic_gpio6_active: nordic_gpio6_active {
		mux {
			pins = "gpio135";
			function = "gpio";
		};

		config {
			pins = "gpio135";
			bias-pull-down; /* PULL DOWN */
			drive-strength = <2>; /* 2 MA */
			output-low;
		};
	};

	nordic_gpio10_active: nordic_gpio10_active {
		mux {
			pins = "gpio98";
			function = "gpio";
		};

		config {
			pins = "gpio98";
			drive-strength = <8>;
			bias-disable = <0>;
			output-high;
		};
	};

	nordic_gpio10_suspend: nordic_gpio10_suspend {
		mux {
			pins = "gpio98";
			function = "gpio";
		};

		config {
			pins = "gpio98";
			bias-pull-down; /* PULL DOWN */
			drive-strength = <2>; /* 2 MA */
		};
	};

	nordic_gpio11_active: nordic_gpio11_active {
		mux {
			pins = "gpio99";
			function = "gpio";
		};

		config {
			pins = "gpio99";
			drive-strength = <8>;
			bias-disable = <0>;
			output-high;
		};
	};

	nordic_gpio11_suspend: nordic_gpio11_suspend {
		mux {
			pins = "gpio99";
			function = "gpio";
		};

		config {
			pins = "gpio99";
			bias-pull-down; /* PULL DOWN */
			drive-strength = <2>; /* 2 MA */
		};
	};

	nordic_ctrl_suspend: nordic_ctrl_suspend {
		mux {
			pins = "gpio134";
			function = "gpio";
		};

		config {
			pins = "gpio134";
			drive-strength = <8>;
			bias-disable = <0>;
			output-high;
		};
	};

	/* active low due to hmd nordic */
	nordic_ctrl_active: nordic_ctrl_active {
		mux {
			pins = "gpio134";
			function = "gpio";
		};

		config {
			pins = "gpio134";
			bias-pull-down; /* PULL DOWN */
			drive-strength = <2>; /* 2 MA */
			output-low;
		};
	};

	nordic_int_active: nordic_int_active {
		mux {
			pins = "gpio97";
			function = "gpio";
		};

		config {
			pins = "gpio97";
			drive-strength = <8>;
			bias-disable = <0>;
			output-high;
		};
	};

	nordic_int_suspend: nordic_int_suspend {
		mux {
			pins = "gpio97";
			function = "gpio";
		};

		config {
			pins = "gpio97";
			bias-pull-down; /* PULL DOWN */
			drive-strength = <2>; /* 2 MA */
		};
	};

	ipd_int_active: ipd_int_active {
		mux {
			pins = "gpio207";
			function = "gpio";
		};

		config {
			pins = "gpio207";
			drive-strength = <2>;   /* 2 mA */
			bias-pull-up;           /* PULL UP */
			input-enable;
		};
	};

	ipd_int_sleep: ipd_int_sleep {
		mux {
			pins = "gpio207";
			function = "gpio";
		};

		config {
			pins = "gpio207";
			drive-strength = <2>;   /* 2 mA */
			bias-pull-down;         /* PULL DOWN */
			input-enable;
		};
	};

};

&soc {
	gpio_keys {
		compatible = "gpio-keys";
		label = "gpio-keys";

		pinctrl-names = "default";
		pinctrl-0 = <&key_vol_up_default
			     &key_confirm_default
			     &key_back_default>;

		confirm_key {
			label = "confirm_key";
			gpios = <&pm8550b_gpios 2 GPIO_ACTIVE_LOW>;
			linux,input-type = <1>;
			linux,code = <KEY_OK>;
			gpio-key,wakeup;
			debounce-interval = <15>;
			linux,can-disable;
		};

		back_key {
			label = "back_key";
			gpios = <&pm8550b_gpios 6 GPIO_ACTIVE_LOW>;
			linux,input-type = <1>;
			linux,code = <KEY_BACK>;
			gpio-key,wakeup;
			debounce-interval = <15>;
			linux,can-disable;
		};

		vol_up {
			label = "volume_up";
			gpios = <&pm8550b_gpios 10 GPIO_ACTIVE_LOW>;
			linux,input-type = <1>;
			linux,code = <KEY_VOLUMEUP>;
			gpio-key,wakeup;
			debounce-interval = <15>;
			linux,can-disable;
		};
	};
};

&pm8550b_haptics {
	qcom,vmax-mv = <1300>;
	qcom,lra-period-us = <5880>;
	status = "ok";

	effect_0 {
		/* CLICK */
		qcom,wf-vmax-mv = <1800>;
		qcom,wf-pattern-period-us = <5880>;
	};

	effect_1 {
		/* DOUBLE_CLICK */
		qcom,wf-vmax-mv = <1800>;
		qcom,wf-pattern-period-us = <5880>;
	};

	effect_2 {
		/* TICK */
		qcom,wf-vmax-mv = <1800>;
		qcom,wf-pattern-period-us = <5880>;
	};

	effect_3 {
		/* THUD */
		qcom,wf-vmax-mv = <1800>;
		qcom,wf-pattern-period-us = <5880>;
	};

	effect_4 {
		/* POP */
		qcom,wf-vmax-mv = <1800>;
		qcom,wf-pattern-period-us = <5880>;
	};

	effect_5 {
		/* HEAVY CLICK */
		qcom,wf-vmax-mv = <1800>;
		qcom,wf-pattern-period-us = <5880>;
	};
};

&battery_charger {
	qcom,thermal-mitigation-step = <500000>;
	qcom,wireless-charging-not-supported;
};

&msm_sdexpress {
	vdd1-supply = <&L12B>;
	qcom,vdd1-voltage-level = <2960000 2960000>;
	qcom,vdd1-current-level = <0 600000>;

	vdd2-supply = <&L4B>;
	qcom,vdd2-voltage-level = <1800000 1800000>;
	qcom,vdd2-current-level = <0 600000>;

	sdexpress-gpios = <&tlmm 172 0>;
	clkreq-gpios = <&tlmm 171 GPIO_ACTIVE_LOW>;

	status = "ok";
};

&pmxr2230_l11 {
	regulator-min-microvolt = <1800000>;
	qcom,init-voltage = <1800000>;
};

&qupv3_se4_spi {
	status = "okay";

	nordic@0 {
		compatible = "nordic,spicontroller";
		reg = <0>;

		v1p8-supply = <&L11B>;
		spi-max-frequency = <8000000>;
		pinctrl-names = "nordic_default", "nordic_sleep";
		pinctrl-0 = <&nordic_gpio6_active &nordic_ctrl_active>;
		pinctrl-1 = <&nordic_gpio6_suspend &nordic_ctrl_suspend>;

		nordic,ledl-gpio = <&tlmm 134 0>;
		nordic,ledr-gpio = <&tlmm 135 0>;

		interrupt-parent = <&tlmm>;
		interrupt-names = "nordicspi_irq";
		nordic,irq-gpio = <&tlmm 97 0>;
		nordic,irq_pin = <&tlmm 97 0x00>;
		interrupts = <64 1>;
	};
};

&qupv3_se2_i2c {
	status = "ok";
};

&itof_level {
	enable-gpio = <&tlmm 87 GPIO_ACTIVE_HIGH>;
	regulator-min-microvolt = <4300000>;
	regulator-max-microvolt = <4300000>;
	status = "ok";
};

&qupv3_se2_i2c {
	status = "okay";

	#address-cells = <1>;
	#size-cells = <0>;
	redriver: redriver@1c {
		compatible = "onnn,redriver";
		reg = <0x1c>;

		vdd-supply = <&L9B>;

		lane-channel-swap;

		pinctrl-names = "default";
		pinctrl-0 = <&usb3phy_portselect_gpio>;
		gpios = <&tlmm 160 0>;

		eq = /bits/ 8 <
				/* Parameters for USB */
				0x4 0x4 0x4 0x4
				/* Parameters for DP */
				0x4 0x6 0x6 0x4>;
		flat-gain = /bits/ 8 <
				/* Parameters for USB */
				0x0 0x1 0x1 0x2
				/* Parameters for DP */
				0x0 0x3 0x3 0x0>;
		output-comp = /bits/ 8 <
				/* Parameters for USB */
				0x3 0x3 0x3 0x3
				/* Parameters for DP */
				0x3 0x3 0x3 0x3>;
		loss-match = /bits/ 8 <
				/* Parameters for USB */
				0x1 0x3 0x3 0x1
				/* Parameters for DP */
				0x3 0x3 0x3 0x3>;
	};
};

&usb_qmp_dp_phy {
	pinctrl-names = "unused";
};

&usb0 {
	ssusb_redriver = <&redriver>;
};

&usb2_phy0 {
	qcom,param-override-seq = <
			/* override x0 */
			0x86 0x6c
			/* override x1 */
			0x8a 0x70
			/* override x2 */
			0x1e 0x74
			/* override x3 */
			0x03 0x78>;
};

&pcie2 {
	qcom,phy-sequence = <0x1240 0x03 0x0
		0x1010 0x01 0x0
		0x101c 0x31 0x0
		0x1020 0x01 0x0
		0x1024 0xde 0x0
		0x1028 0x07 0x0
		0x1030 0x97 0x0
		0x1034 0x0c 0x0
		0x1044 0x14 0x0
		0x1048 0x90 0x0
		0x1058 0x0f 0x0
		0x1074 0x06 0x0
		0x1078 0x06 0x0
		0x107c 0x16 0x0
		0x1080 0x16 0x0
		0x1084 0x36 0x0
		0x1088 0x36 0x0
		0x1094 0x08 0x0
		0x10a4 0x46 0x0
		0x10a8 0x04 0x0
		0x10ac 0x0a 0x0
		0x10b0 0x1a 0x0
		0x10b4 0x14 0x0
		0x10b8 0x34 0x0
		0x10bc 0x82 0x0
		0x10c4 0xd0 0x0
		0x10cc 0x55 0x0
		0x10d0 0x55 0x0
		0x10d4 0x03 0x0
		0x10d8 0x55 0x0
		0x10dc 0x55 0x0
		0x10e0 0x05 0x0
		0x110c 0x02 0x0
		0x1154 0x34 0x0
		0x1158 0x12 0x0
		0x115c 0x00 0x0
		0x1168 0x0a 0x0
		0x116c 0x04 0x0
		0x119c 0x88 0x0
		0x1174 0x60 0x0
		0x117c 0x06 0x0
		0x11a0 0x14 0x0
		0x11a8 0x0f 0x0
		0x0220 0x16 0x0
		0x03c0 0x38 0x0
		0x0a20 0x16 0x0
		0x0bc0 0x38 0x0
		0x0360 0x9a 0x0
		0x0364 0xb0 0x0
		0x0368 0x92 0x0
		0x036c 0xf0 0x0
		0x0370 0x42 0x0
		0x0374 0x99 0x0
		0x0378 0x29 0x0
		0x037c 0x9a 0x0
		0x0380 0xfb 0x0
		0x0384 0x92 0x0
		0x0388 0xec 0x0
		0x038c 0x43 0x0
		0x0390 0xdd 0x0
		0x0394 0x0d 0x0
		0x0398 0xf3 0x0
		0x039c 0xf8 0x0
		0x03a0 0xec 0x0
		0x03a4 0xd6 0x0
		0x03a8 0x83 0x0
		0x03ac 0xf5 0x0
		0x03b0 0x5e 0x0
		0x0b60 0x9a 0x0
		0x0b64 0xb0 0x0
		0x0b68 0x92 0x0
		0x0b6c 0xf0 0x0
		0x0b70 0x42 0x0
		0x0b74 0x99 0x0
		0x0b78 0x29 0x0
		0x0b7c 0x9a 0x0
		0x0b80 0xfb 0x0
		0x0b84 0x92 0x0
		0x0b88 0xec 0x0
		0x0b8c 0x43 0x0
		0x0b90 0xdd 0x0
		0x0b94 0x0d 0x0
		0x0b98 0xf3 0x0
		0x0b9c 0xf8 0x0
		0x0ba0 0xec 0x0
		0x0ba4 0xd6 0x0
		0x0ba8 0x83 0x0
		0x0bac 0xf5 0x0
		0x0bb0 0x5e 0x0
		0x03b4 0x20 0x0
		0x022c 0x3f 0x0
		0x0230 0x37 0x0
		0x0bb4 0x20 0x0
		0x0a2c 0x3f 0x0
		0x0a30 0x37 0x0
		0x0078 0x05 0x0
		0x007c 0xf6 0x0
		0x0080 0x0f 0x0
		0x0878 0x05 0x0
		0x087c 0xf6 0x0
		0x0880 0x0f 0x0
		0x0290 0x00 0x0
		0x0a90 0x00 0x0
		0x03f8 0x1f 0x0
		0x0400 0x1f 0x0
		0x0408 0x1f 0x0
		0x0410 0x1f 0x0
		0x0418 0x1f 0x0
		0x0420 0x1f 0x0
		0x03f4 0x1f 0x0
		0x03fc 0x1f 0x0
		0x0404 0x1f 0x0
		0x0bf8 0x1f 0x0
		0x0c00 0x1f 0x0
		0x0c08 0x1f 0x0
		0x0c10 0x1f 0x0
		0x0c18 0x1f 0x0
		0x0c20 0x1f 0x0
		0x0bf4 0x1f 0x0
		0x0bfc 0x1f 0x0
		0x0c04 0x1f 0x0
		0x0438 0x09 0x0
		0x0c38 0x09 0x0
		0x0208 0x0c 0x0
		0x0a08 0x0c 0x0
		0x020c 0x08 0x0
		0x0a0c 0x08 0x0
		0x021c 0x04 0x0
		0x0a1c 0x04 0x0
		0x02d4 0x04 0x0
		0x0ad4 0x04 0x0
		0x02dc 0x08 0x0
		0x0adc 0x08 0x0
		0x0308 0x0b 0x0
		0x0b08 0x0b 0x0
		0x0318 0x7c 0x0
		0x0b18 0x7c 0x0
		0x027c 0x10 0x0
		0x0a7c 0x10 0x0
		0x02b4 0x00 0x0
		0x0ab4 0x00 0x0
		0x02ec 0x05 0x0
		0x0aec 0x05 0x0
		0x02c4 0x00 0x0
		0x02c8 0x1f 0x0
		0x0ac4 0x00 0x0
		0x0ac8 0x1f 0x0
		0x0030 0x1f 0x0
		0x0034 0x07 0x0
		0x0830 0x1f 0x0
		0x0834 0x07 0x0
		0x141c 0xc1 0x0
		0x1490 0x00 0x0
		0x13e0 0x16 0x0
		0x13e4 0x22 0x0
		0x1508 0x02 0x0
		0x14a0 0x16 0x0
		0x1584 0x28 0x0
		0x1370 0x2e 0x0
		0x155c 0x2e 0x0
		0x140c 0x1d 0x0
		0x1388 0x66 0x0
		0x1e24 0x00 0x0
		0x1e28 0x00 0x0
		0x1828 0x00 0x0
		0x1c28 0x00 0x0
		0x127c 0x08 0x0
		0x1260 0x90 0x0 /* Set preset 7 for long channel */
		0x1200 0x00 0x0
		0x1244 0x03 0x0>;
};

&regulator_ocp_notifier {
	periph-1c1-supply = <&L1B>;
	periph-1c3-supply = <&L3B>;
	periph-1c4-supply = <&L4B>;
	periph-1c5-supply = <&L5B>;
	periph-1c6-supply = <&L6B>;
	periph-1c7-supply = <&L7B>;
	periph-1c8-supply = <&L8B>;
	periph-1c9-supply = <&L9B>;
	periph-1ca-supply = <&L10B>;
	periph-1cb-supply = <&L11B>;
	periph-1cc-supply = <&L12B>;
	periph-1cd-supply = <&L13B>;
	periph-1ce-supply = <&L14B>;
	periph-1cf-supply = <&L15B>;
	periph-1d2-supply = <&L18B>;
	periph-1d4-supply = <&L20B>;
	periph-1d5-supply = <&L21B>;
	periph-1d6-supply = <&L22B>;
	periph-1d7-supply = <&L23B>;
	periph-2c1-supply = <&L1C_LEVEL>;
	periph-2c2-supply = <&L2C>;
	periph-3c1-supply = <&L1D>;
	periph-3c2-supply = <&L2D>;
	periph-5c1-supply = <&L1F_LEVEL>;
	periph-5c2-supply = <&L2F>;
	periph-5c3-supply = <&L3F>;
	periph-c40-supply = <&L1M>;
	periph-c41-supply = <&L2M>;
	periph-c42-supply = <&L3M>;
	periph-c43-supply = <&L4M>;
	periph-c44-supply = <&L5M>;
	periph-c45-supply = <&L6M>;
	periph-d40-supply = <&L1N>;
	periph-d41-supply = <&L2N>;
	periph-d42-supply = <&L3N>;
	periph-d43-supply = <&L4N>;
	periph-d44-supply = <&L5N>;
	periph-d46-supply = <&L7N>;
};

&qupv3_se2_i2c {
	k09973: k09973@10 {
		compatible = "qcom,ipd";
		reg = <0x10>;
		interrupt-parent = <&tlmm>;
		interrupts = <207 0x2008>;
		pinctrl-names = "ipd_int_active","ipd_int_sleep";

		pinctrl-0 = <&ipd_int_active>;
		pinctrl-1 = <&ipd_int_sleep>;


		gpios = <&tlmm 207 GPIO_ACTIVE_HIGH>;
		ipd,measurment_number = <4>;
		ipd,DRDY_event = <0>;
		ipd,SW_event = <1 1 1 0>;
		ipd,ERR_event = <0>;
		ipd,POL_setting = <0 0 0 0 >;
		ipd,SDR_setting = <0>;
		ipd,SMR_setting = <1>;
		ipd,Mode = <4>;
		ipd,Device_type = <1>;
		ipd,near_ipd = <58>;
		ipd,far_ipd = <68>;
		ipd,near_res = <1350>;
		ipd,far_res = <7945>;
		ipd,threshold_X = <1500 500>;
		ipd,threshold_Y = <0 1000>;
		ipd,threshold_Z = <13000 12000>;
		ipd,threshold_V = <0 1000>;
		#io-channel-cells = <1>;
		io-channel-ranges;
		io-channels = <&pmk8550_vadc PMXR2230_ADC5_GEN3_AMUX_THM5_100K_PU>;
		io-channel-names = "ipd";
	};
};
