/* Copyright (c) 2014-2017, The Linux Foundation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
 * only version 2 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

#include "msm8909.dtsi"
#include "msm8909-pinctrl.dtsi"
#include "msm8909-regulator.dtsi"
#include "msm8909-camera-sensor-mtp.dtsi"


&soc {
	/*
	 * DT node to add support for SMB135x charger and integrate
	 * with VM-BMS.
	 */
	i2c@78b8000 {
		smb1357_otg_vreg: smb1357-charger@57 {
			compatible = "qcom,smb1357-charger";
			reg = <0x57>;
			interrupt-parent = <&msm_gpio>;
			interrupts = <58 8>;
			pinctrl-names = "default";
			pinctrl-0 = <&smb_int_default>;

			qcom,bmd-algo-disabled;
			qcom,float-voltage-mv = <4200>;
			qcom,charging-timeout = <1536>;
			qcom,recharge-thresh-mv = <100>;
			regulator-name = "smb1357_otg_vreg";
			qcom,soft-vfloat-comp-disabled;
			qcom,thermal-mitigation = <1500 700 600 0>;

			qcom,bms-psy-name = "bms";

			/*
			 * Disable SMB1357 based charging termination as BMS
			 * controls charging.
			 */
			qcom,iterm-disabled;

			/*
			 * Disable charge inhibit feature to start chargin on
			 * charger insertion independent of battery voltage.
			 */
			qcom,inhibit-disabled;

			/* BMS is controlling charging/re-charge */
			qcom,bms-controlled-charging;

			/*
			 * To enable charger node:
			 * set status = "ok" and
			 * add 'qcom,use-external-charger' to pm8909_chg node
			 */
			status = "disabled";
		};
	};

	/*
	 * DT node to add support for SMB358 charger and integrate
	 * with VM-BMS.
	 */
	i2c@78b8000 {
		smb358_otg_vreg: smb358-charger@57 {
			compatible = "qcom,smb358-charger";
			reg = <0x57>;
			interrupt-parent = <&msm_gpio>;
			interrupts = <58 8>;
			pinctrl-names = "default";
			pinctrl-0 = <&smb_int_default>;

			qcom,float-voltage-mv = <4200>;
			qcom,recharge-mv = <100>;
			regulator-name = "smb358_otg_vreg";
			qcom,thermal-mitigation = <1500 700 600 0>;
			qcom,fastchg-current-max-ma = <1500>;

			qcom,disable-apsd;
			qcom,bms-psy-name = "bms";
			qcom,bms-controlled-charging;
			qcom,iterm-disabled;
			qcom,chg-inhibit-disabled;
			/*
			 * In some of designs, the battery thermistor
			 * is only connected to the PMIC THERM pin.
			 * In this condition, we should define 'qcom,using-pmic-therm'.
			 */
			qcom,using-pmic-therm;
			qcom,hot-bat-decidegc = <550>;
			qcom,cold-bat-decidegc = <0>;
			qcom,bat-present-decidegc = <200>;
			/*
			 * Below preperties are used for enable JEITA
			 */
			qcom,warm-bat-decidegc = <450>;
			qcom,cool-bat-decidegc = <100>;
			qcom,warm-bat-ma = <350>;
			qcom,cool-bat-ma = <350>;
			qcom,warm-bat-mv = <4100>;
			qcom,cool-bat-mv = <4100>;

			/*
			 * To enable charger node:
			 * set status = "ok" and
			 * add 'qcom,use-external-charger' to pm8909_chg node
			 */
			status = "disabled";
		};
	};

	gen-vkeys {
		compatible = "qcom,gen-vkeys";
		label = "synaptics_dsx";
		qcom,disp-maxx = <719>;
		qcom,disp-maxy = <1279>;
		qcom,panel-maxx = <719>;
		qcom,panel-maxy = <1405>;
		qcom,key-codes = <158 139 172 217>;
	};

	gpio_keys {
		compatible = "gpio-keys";
		input-name = "gpio-keys";
		pinctrl-names = "tlmm_gpio_key_active","tlmm_gpio_key_suspend";
		pinctrl-0 = <&gpio_key_active>;
		pinctrl-1 = <&gpio_key_suspend>;

		camera_focus {
			label = "camera_focus";
			gpios = <&msm_gpio 91 0x1>;
			linux,input-type = <1>;
			linux,code = <0x210>;
			gpio-key,wakeup;
			debounce-interval = <15>;
		};

		camera_snapshot {
			label = "camera_snapshot";
			gpios = <&msm_gpio 92 0x1>;
			linux,input-type = <1>;
			linux,code = <0x2fe>;
			gpio-key,wakeup;
			debounce-interval = <15>;
		};

		vol_up {
			label = "volume_up";
			gpios = <&msm_gpio 90 0x1>;
			linux,input-type = <1>;
			linux,code = <115>;
			gpio-key,wakeup;
			debounce-interval = <15>;
		};
	};

	audio_codec_mtp: sound {
		compatible = "qcom,msm8952-audio-codec";
		qcom,model = "msm8909-snd-card";
		reg = <0x7702000 0x4>,
		      <0x7702004 0x4>,
		      <0x7702008 0x4>;
		reg-names = "csr_gp_io_mux_mic_ctl",
			    "csr_gp_io_mux_spkr_ctl",
			    "csr_gp_io_lpaif_pri_pcm_pri_mode_muxsel";

		qcom,msm-snd-card-id = <0>;
		qcom,msm-codec-type = "internal";
		qcom,msm-ext-pa = "primary";
		qcom,msm-mclk-freq = <9600000>;
		qcom,msm-mbhc-hphl-swh = <0>;
		qcom,msm-mbhc-gnd-swh = <0>;
		qcom,msm-hs-micbias-type = "internal";
		qcom,msm-micbias1-ext-cap;
		qcom,split-a2dp;
		qcom,audio-routing =
			"RX_BIAS", "MCLK",
			"SPK_RX_BIAS", "MCLK",
			"INT_LDO_H", "MCLK",
			"MIC BIAS External", "Handset Mic",
			"MIC BIAS Internal2", "Headset Mic",
			"MIC BIAS External", "Secondary Mic",
			"AMIC1", "MIC BIAS External",
			"AMIC2", "MIC BIAS Internal2",
			"AMIC3", "MIC BIAS External";
		qcom,msm-gpios =
			"pri_i2s",
			"us_eu_gpio";
		qcom,pinctrl-names =
			"all_off",
			"pri_i2s_act",
			"us_eu_gpio_act",
			"pri_i2s_us_eu_gpio_act";
		pinctrl-names =
			"all_off",
			"pri_i2s_act",
			"us_eu_gpio_act",
			"pri_i2s_us_eu_gpio_act";
		pinctrl-0 = <&cdc_pdm_lines_sus &cross_conn_det_sus
							&vdd_spkdrv_sus>;
		pinctrl-1 = <&cdc_pdm_lines_act &cross_conn_det_sus
							&vdd_spkdrv_act>;
		pinctrl-2 = <&cdc_pdm_lines_sus &cross_conn_det_act
							&vdd_spkdrv_sus>;
		pinctrl-3 = <&cdc_pdm_lines_act &cross_conn_det_act
							&vdd_spkdrv_act>;
		qcom,cdc-us-euro-gpios = <&msm_gpio 97 0>;
		asoc-platform = <&pcm0>, <&pcm1>, <&pcm2>, <&voip>, <&voice>,
				<&loopback>, <&compress>, <&hostless>,
				<&afe>, <&lsm>, <&routing>, <&lpa>,
				<&voice_svc>;
		asoc-platform-names = "msm-pcm-dsp.0", "msm-pcm-dsp.1",
				"msm-pcm-dsp.2", "msm-voip-dsp",
				"msm-pcm-voice", "msm-pcm-loopback",
				"msm-compress-dsp", "msm-pcm-hostless",
				"msm-pcm-afe", "msm-lsm-client",
				"msm-pcm-routing", "msm-pcm-lpa",
				"msm-voice-svc";
		asoc-cpu = <&dai_pri_auxpcm>,
				<&dai_mi2s0>, <&dai_mi2s1>, <&dai_mi2s2>,
				<&dai_mi2s3>, <&dai_mi2s5>, <&dai_mi2s6>,
				<&bt_sco_rx>, <&bt_sco_tx>, <&bt_a2dp_rx>,
				<&int_fm_rx>, <&int_fm_tx>, <&afe_pcm_rx>,
				<&afe_pcm_tx>, <&afe_proxy_rx>, <&afe_proxy_tx>,
				<&incall_record_rx>, <&incall_record_tx>,
				<&incall_music_rx>, <&incall_music_2_rx>;
		asoc-cpu-names = "msm-dai-q6-auxpcm.1",
				"msm-dai-q6-mi2s.0", "msm-dai-q6-mi2s.1",
				"msm-dai-q6-mi2s.2", "msm-dai-q6-mi2s.3",
				"msm-dai-q6-mi2s.5", "msm-dai-q6-mi2s.6",
				"msm-dai-q6-dev.12288", "msm-dai-q6-dev.12289",
				"msm-dai-q6-dev.12290", "msm-dai-q6-dev.12292",
				"msm-dai-q6-dev.12293", "msm-dai-q6-dev.224",
				"msm-dai-q6-dev.225", "msm-dai-q6-dev.241",
				"msm-dai-q6-dev.240", "msm-dai-q6-dev.32771",
				"msm-dai-q6-dev.32772", "msm-dai-q6-dev.32773",
				"msm-dai-q6-dev.32770";
		asoc-codec = <&stub_codec>, <&pm8909_conga_dig>;
		asoc-codec-names = "msm-stub-codec.1", "cajon_codec";
	};
};

&blsp1_uart1 {
	status = "ok";
	pinctrl-names = "default";
	pinctrl-0 = <&uart_console_sleep>;
};
&blsp1_uart2 { // NDM
	status = "okay";
	pinctrl-0 = <&hsuart_sleep>;
	pinctrl-1 = <&hsuart_active>;
};

/ {
	mtp_batterydata: qcom,battery-data {
		qcom,rpull-up-kohm = <100>;
		qcom,vref-batt-therm = <1800000>;

		#include "batterydata-palladium.dtsi"
	};
};

&qcom_rng {
	status = "okay";
};

&qcom_crypto {
	status = "okay";
};

&qcom_cedev {
	status = "okay";
};

&qcom_seecom {
	status = "okay";
};

&qcom_tzlog {
	status = "okay";
};

&qnand_1 {
	status = "ok";
};

&sdhc_1 {
	vdd-supply = <&pm8909_l8>;
	qcom,vdd-voltage-level = <2900000 2900000>;
	qcom,vdd-current-level = <200 400000>;

	vdd-io-supply = <&pm8909_l5>;
	qcom,vdd-io-always-on;
	qcom,vdd-io-lpm-sup;
	qcom,vdd-io-voltage-level = <1800000 1800000>;
	qcom,vdd-io-current-level = <200 60000>;

	pinctrl-names = "active", "sleep";
	pinctrl-0 = <&sdc1_clk_on &sdc1_cmd_on &sdc1_data_on>;
	pinctrl-1 = <&sdc1_clk_off &sdc1_cmd_off &sdc1_data_off>;

	qcom,bus-speed-mode = "HS200_1p8v", "DDR_1p8v";
	qcom,nonremovable;

	status = "ok";
};

&sdhc_2 {
	 #address-cells = <0>;
	interrupt-parent = <&sdhc_2>;
	interrupts = <0 1 2>;
	#interrupt-cells = <1>;
	interrupt-map-mask = <0xffffffff>;
	interrupt-map = <0 &intc 0 125 0
			1 &intc 0 221 0
			2 &msm_gpio 38 0>;
	interrupt-names = "hc_irq", "pwr_irq", "status_irq";
	cd-gpios = <&msm_gpio 38 0x1>;

	vdd-supply = <&pm8909_l11>;
	qcom,vdd-voltage-level = <1800000 2950000>;
	qcom,vdd-current-level = <15000 400000>;

	vdd-io-supply = <&pm8909_l12>;
	qcom,vdd-io-voltage-level = <1800000 2950000>;
	qcom,vdd-io-current-level = <200 50000>;

	pinctrl-names = "active", "sleep";
	pinctrl-0 = <&sdc2_clk_on &sdc2_cmd_on &sdc2_data_on &sdc2_cd_on>;
	pinctrl-1 = <&sdc2_clk_off &sdc2_cmd_off &sdc2_data_off &sdc2_cd_off>;

	status = "disabled";
};

&i2c_1 { /* BLSP1 QUP1 */
	mpu6050@68 { /* Gyroscope and accelerometer sensor combo */
		compatible = "invn,mpu6050";
		reg = <0x68>;
		pinctrl-names = "mpu_default","mpu_sleep";
		pinctrl-0 = <&mpu6050_default>;
		pinctrl-1 = <&mpu6050_sleep>;
		interrupt-parent = <&msm_gpio>;
		interrupts = <96 0x1>;
		vdd-supply = <&pm8909_l17>;
		vlogic-supply = <&pm8909_l6>;
		invn,gpio-int = <&msm_gpio 96 0x1>;
		invn,place = "Portrait Down Back Side";
	};

	avago@39 { /* Ambient light and proximity sensor */
		compatible = "avago,apds9900";
		reg = <0x39>;
		pinctrl-names = "default","sleep";
		pinctrl-0 = <&apds99xx_default>;
		pinctrl-1 = <&apds99xx_sleep>;
		interrupt-parent = <&msm_gpio>;
		interrupts = <94 0x2002>;
		vdd-supply = <&pm8909_l17>;
		vio-supply = <&pm8909_l6>;
		avago,irq-gpio = <&msm_gpio 94 0x2002>;
		avago,ps-threshold = <600>;
		avago,ps-hysteresis-threshold = <500>;
		avago,ps-pulse = <8>;
		avago,ps-pgain = <0>;
		avago,als-B = <186>;
		avago,als-C = <75>;
		avago,als-D = <129>;
		avago,ga-value = <256>;
	};

	akm@c { /* Magnetic field sensor */
		compatible = "ak,ak8963";
		reg = <0x0c>;
		pinctrl-names = "ak8963_default", "ak8963_sleep";
		pinctrl-0 = <&ak8963_default>;
		pinctrl-1 = <&ak8963_sleep>;
		interrupt-parent = <&msm_gpio>;
		interrupts = <65 0x2>;
		vdd-supply = <&pm8909_l17>;
		vio-supply = <&pm8909_l6>;
		ak,layout = <0x6>;
		ak,auto-report;
	};
};

&dsi_auo_cx_qvga_cmd {
	qcom,mdss-dsi-bl-pmic-control-type = "bl_ctrl_dcs";
	qcom,mdss-dsi-bl-pmic-pwm-frequency = <100>;
	qcom,mdss-dsi-bl-pmic-bank-select = <0>;
	qcom,mdss-dsi-pwm-gpio = <&pm8909_mpps 2 0>;
	qcom,panel-supply-entries = <&dsi_panel_pwr_supply>;
};

&dsi_auo_qvga_cmd {
	qcom,mdss-dsi-bl-pmic-control-type = "bl_ctrl_dcs";
	qcom,mdss-dsi-bl-pmic-pwm-frequency = <100>;
	qcom,mdss-dsi-bl-pmic-bank-select = <0>;
	qcom,mdss-dsi-pwm-gpio = <&pm8909_mpps 2 0>;
	qcom,panel-supply-entries = <&dsi_panel_pwr_supply>;
};

&dsi_hx8394d_480_vid {
	qcom,mdss-dsi-bl-pmic-control-type = "bl_ctrl_pwm";
	qcom,mdss-dsi-bl-pmic-pwm-frequency = <100>;
	qcom,mdss-dsi-bl-pmic-bank-select = <0>;
	qcom,mdss-dsi-pwm-gpio = <&pm8909_mpps 2 0>;
	qcom,panel-supply-entries = <&dsi_panel_pwr_supply>;
};

&dsi_hx8394d_720_vid {
	qcom,mdss-dsi-bl-pmic-control-type = "bl_ctrl_pwm";
	qcom,mdss-dsi-bl-pmic-pwm-frequency = <100>;
	qcom,mdss-dsi-bl-pmic-bank-select = <0>;
	qcom,mdss-dsi-pwm-gpio = <&pm8909_mpps 2 0>;
	qcom,panel-supply-entries = <&dsi_panel_pwr_supply>;
};

&dsi_hx8394d_qhd_vid {
	qcom,mdss-dsi-bl-pmic-control-type = "bl_ctrl_pwm";
	qcom,mdss-dsi-bl-pmic-pwm-frequency = <100>;
	qcom,mdss-dsi-bl-pmic-bank-select = <0>;
	qcom,mdss-dsi-pwm-gpio = <&pm8909_mpps 2 0>;
	qcom,panel-supply-entries = <&dsi_panel_pwr_supply>;
};

&msm_gpio {
	pmx_mdss {
		mdss_dsi_active: mdss_dsi_active {
			mux {
				pins = "gpio25", "gpio37";
			};
			config {
				pins = "gpio25", "gpio37";
			};
		};
		mdss_dsi_suspend: mdss_dsi_suspend {
			mux {
				pins = "gpio25", "gpio37";
			};
			config {
				pins = "gpio25", "gpio37";
			};
		};
	};
	pmx_mdss_te {
		mdss_te_active: mdss_te_active {
			mux {
				pins = "gpio24";
			};
			config {
				pins = "gpio24";
			};
		};
		mdss_te_suspend: mdss_te_suspend {
			mux {
				pins = "gpio24";
			};
			config {
				pins = "gpio24";
			};
		};
	};
	mpu6050_int_pin {
		mpu6050_default: mpu6050_default {
			mux {
				pins = "gpio96";
				function = "gpio";
			};
			config {
				pins = "gpio96";
				drive-dtrength = <6>;
				bias-pull-down;
			};
		};
		mpu6050_sleep: mpu6050_sleep {
			mux {
				pins = "gpio96";
				function = "gpio";
			};
			config {
				pins = "gpio96";
				drive-dtrength = <2>;
				bias-pull-down;
			};
		};
	};
	apds99xx_int_pin {
		apds99xx_default: apds99xx_default {
			mux {
				pins = "gpio94";
				function = "gpio";
			};
			config {
				pins = "gpio94";
				drive-strength = <6>;
				bias-pull-up;
			};
		};
		apds99xx_sleep: apds99xx_sleep {
			mux {
				pins = "gpio94";
				function = "gpio";
			};
			config {
				pins = "gpio94";
				drive-strength = <2>;
				bias-pull-down;
			};
		};
	};
	ak8963_int_pin {
		ak8963_default: ak8963_default {
			mux {
				pins = "gpio65";
				function = "gpio";
			};
			config {
				pins = "gpio65";
				drive-strength = <6>;
				bias-pull-up;
			};
		};
		ak8963_sleep: ak8963_sleep {
			mux {
				pins = "gpio65";
				function = "gpio";
			};
			config {
				pins = "gpio65";
				drive-strength = <2>;
				bias-pull-down;
			};
		};
	};
};

&mdss_dsi0 {
	qcom,dsi-pref-prim-pan = <&dsi_hx8394d_720_vid>;
	pinctrl-names = "mdss_default", "mdss_sleep";
	pinctrl-0 = <&mdss_dsi_active &mdss_te_active>;
	pinctrl-1 = <&mdss_dsi_suspend &mdss_te_suspend>;

	qcom,platform-reset-gpio = <&msm_gpio 25 0>;
	qcom,platform-bklight-en-gpio = <&msm_gpio 37 0>;
};

/* CoreSight */
&tpiu {
	pinctrl-names = "sdcard", "trace", "swduart",
			"swdtrc", "jtag", "spmi";
	/* NIDnT */
	pinctrl-0 = <&qdsd_clk_sdcard &qdsd_cmd_sdcard
		     &qdsd_data0_sdcard &qdsd_data1_sdcard
		     &qdsd_data2_sdcard &qdsd_data3_sdcard>;
	pinctrl-1 = <&qdsd_clk_trace &qdsd_cmd_trace
		     &qdsd_data0_trace &qdsd_data1_trace
		     &qdsd_data2_trace &qdsd_data3_trace>;
	pinctrl-2 = <&qdsd_cmd_swduart &qdsd_data0_swduart
		     &qdsd_data1_swduart &qdsd_data2_swduart
		     &qdsd_data3_swduart>;
	pinctrl-3 = <&qdsd_clk_swdtrc &qdsd_cmd_swdtrc
		     &qdsd_data0_swdtrc &qdsd_data1_swdtrc
		     &qdsd_data2_swdtrc &qdsd_data3_swdtrc>;
	pinctrl-4 = <&qdsd_cmd_jtag &qdsd_data0_jtag
		     &qdsd_data1_jtag &qdsd_data2_jtag
		     &qdsd_data3_jtag>;
	pinctrl-5 = <&qdsd_clk_spmi &qdsd_cmd_spmi
		     &qdsd_data0_spmi &qdsd_data3_spmi>;
};
