/* Copyright (c) 2017-2018, 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 <dt-bindings/gpio/gpio.h>
#include <dt-bindings/interrupt-controller/irq.h>
#include "mdm9650-v1.1.dtsi"
#include "mdm9650-pinctrl.dtsi"

/ {
	aliases {
		serial0 = &blsp1_uart3;
	};

	gpio-leds {
		compatible = "gpio-leds";

		status {
			gpios = <&tlmm_pinmux 14 0>;
			default-state = "on";
		};
	};
};

&soc {
	sound {
		status = "disabled";
	};

	usb_detect {
		compatible = "qcom,gpio-usbdetect";
		interrupt-parent = <&spmi_bus>;
		interrupts = <0x0 0x0d 0x0>; /* PMD9655 VBUS DETECT */
		interrupt-names = "vbus_det_irq";
	};

	can_vreg: regulator-can-tps65051 {
		compatible = "regulator-fixed";
		regulator-name = "can_vreg";
		regulator-min-microvolt = <1800000>;
		regulator-max-microvolt = <1800000>;
		startup-delay-us = <920>;
		gpio = <&tlmm_pinmux 69 0>;
		enable-active-high;
		regulator-always-on;
	};

	pps {
		use-system-time-ts;
	};

	qcom,ipc_router_external_ap_xprt {
		compatible = "qcom,ipc-router-mhi-dev-xprt";
		qcom,out-chan-id = <20>;
		qcom,in-chan-id = <21>;
		qcom,xprt-remote = "external-ap";
		qcom,xprt-linkid = <2>;
		qcom,xprt-version = <1>;
	};
};

&cnss_pcie {
	status = "disabled";
};

&blsp1_uart3 {
	status = "ok";
	pinctrl-names = "default";
	pinctrl-0 = <&uart3_console_active>;
};

&i2c_3 {
	status = "ok";

	wcd9xxx_codec@d {
		status = "disabled";
	};

	bmi160@68 {
		compatible = "bosch-sensortec,bmi160";
		reg = <0x68>;
		pinctrl-names = "default";
		pinctrl-0 = <&bmi160_int1_default &bmi160_int2_default>;
		interrupt-parent = <&tlmm_pinmux>;
		interrupts = <81 0x2002>;
		bmi,init-interval = <200>;
		bmi,place = <1>;
		bmi,gpio_irq = <&tlmm_pinmux 81 0x2002>;
	};
};

&spi_1 {
	status = "ok";
	/delete-property/ qcom,use-bam;

	can-controller@0 {
		compatible = "fsl,k61";
		spi-max-frequency = <4800000>;
		reg = <0>;
		interrupt-parent = <&tlmm_pinmux>;
		interrupts = <68 IRQ_TYPE_EDGE_RISING>;
		reset-gpio = <&tlmm_pinmux 89 GPIO_ACTIVE_LOW>;
		pinctrl-names = "active", "sleep";
		pinctrl-0 = <&can_rst_on>;
		pinctrl-1 = <&can_rst_off>;
	};
};

&spi_2 {
	status = "ok";
};

&qnand_1 {
	status = "ok";
};

&usb3 {
	qcom,charging-disabled;
};

&pcie_ep {
	status = "ok";
	perst-gpio = <&tlmm_pinmux 60 0>;
	wake-gpio = <&tlmm_pinmux 61 0>;
	clkreq-gpio = <&tlmm_pinmux 64 0>;
	mdm2apstatus-gpio = <&tlmm_pinmux 20 0>;
	/delete-property/ qcom,pcie-perst-enum;
};

&pcie0 {
	status = "disabled";
};

&cnss_pcie {
	status = "disabled";
};

&mhi_device {
	status = "ok";
};

/* pinctrl redefinitions */
&bmi160_int1_default {
	mux {
		pins = "gpio81";
	};
	config {
		pins = "gpio81";
	};
};

&bmi160_int2_default {
	mux {
		pins = "gpio94";
	};
	config {
		pins = "gpio94";
	};
};

&can_rst_on {
	mux {
		pins = "gpio89";
	};
	config {
		pins = "gpio89";
	};
};

&can_rst_off {
	mux {
		pins = "gpio89";
	};
	config {
		pins = "gpio89";
	};
};

&pcie_ep_perst_default {
	mux {
		pins = "gpio60";
	};
	config {
		pins = "gpio60";
	};
};

&pcie0_mdm2apstatus_default {
	mux {
		pins = "gpio20";
	};
	config {
		pins = "gpio20";
		bias-disable;
		/delete-property/ bias-pull-down;
	};
};

/* Needed by spi_1 */
&pmd9650_l13 {
	regulator-always-on;
};

&pmd9650_gpios {
	gpio@c000 { /* GPIO 1 - MDM2AP_VDD_MIN */
		status = "ok";
		qcom,mode = <1>;         /* Digital output*/
		qcom,pull = <4>;         /* Pulldown 10uA */
		qcom,vin-sel = <0>;      /* VPH_PWR */
		qcom,src-sel = <0>;      /* GPIO */
		qcom,invert = <0>;       /* Invert */
		qcom,master-en = <1>;    /* Enable GPIO */
	};

	gpio@c100 { /* GPIO 2 - VADC */
		/* GPIO should be left off, and in the high
		 * impedance state when the pin is used with the VADC
		 */
		status = "ok";
		qcom,master-en = <0>;		/* DISABLE GPIO */
	};

	gpio@c200 { /* GPIO 3 - MDM2AP_VDD_WAKEUP */
		status = "ok";
		qcom,mode = <1>;         /* Digital output*/
		qcom,pull = <4>;         /* Pulldown 10uA */
		qcom,vin-sel = <0>;      /* VPH_PWR */
		qcom,src-sel = <0>;      /* GPIO */
		qcom,invert = <0>;       /* Invert */
		qcom,master-en = <1>;    /* Enable GPIO */
	};

	gpio@c400 { /* GPIO 5 - USB_ID */
		status = "ok";
		qcom,mode = <0>;		/* Digital input */
		qcom,pull = <1>;		/* Pull up 1.5 uA */
		qcom,vin-sel = <1>;		/* 1.8 V */
		qcom,master-en = <1>;		/* Enable GPIO */
	};

	gpio@c800 { /* GPIO 9 - CAN_EN - not used */
		/* Set as input since CAN_EN is being set
		 * from MDM GPIO, same line goes to this pin
		 */
		status = "ok";
		qcom,mode = <0>;		/* Digital input */
		qcom,pull = <5>;		/* No pull */
		qcom,vin-sel = <1>;		/* 1.8 V */
		qcom,master-en = <1>;		/* Enable GPIO */
	};
};

&pmd9650_vadc {
	chan@83 {
		label = "vph_pwr";
		reg = <0x83>;
		qcom,decimation = <2>;
		qcom,pre-div-channel-scaling = <1>;
		qcom,calibration-type = "absolute";
		qcom,scale-function = <0>;
		qcom,hw-settle-time = <0>;
		qcom,fast-avg-setup = <0>;
	};

	chan@4c {
		label = "xo_therm_buf";
		reg = <0x4c>;
		qcom,decimation = <2>;
		qcom,pre-div-channel-scaling = <0>;
		qcom,calibration-type = "ratiometric";
		qcom,scale-function = <4>;
		qcom,hw-settle-time = <2>;
		qcom,fast-avg-setup = <0>;
		qcom,vadc-thermal-node;
	};

	chan@53 {
		label = "ambient_therm";
		reg = <0x53>;
		qcom,decimation = <2>;
		qcom,pre-div-channel-scaling = <0>;
		qcom,calibration-type = "ratiometric";
		qcom,scale-function = <2>;
		qcom,hw-settle-time = <2>;
		qcom,fast-avg-setup = <0>;
		qcom,vadc-thermal-node;
	};

	chan@4d {
		label = "mdm_case_therm";
		reg = <0x4d>;
		qcom,decimation = <2>;
		qcom,pre-div-channel-scaling = <0>;
		qcom,calibration-type = "ratiometric";
		qcom,scale-function = <2>;
		qcom,hw-settle-time = <2>;
		qcom,fast-avg-setup = <0>;
		qcom,vadc-thermal-node;
	};

	chan@4e {
		label = "pa_therm1";
		reg = <0x4e>;
		qcom,decimation = <2>;
		qcom,pre-div-channel-scaling = <0>;
		qcom,calibration-type = "ratiometric";
		qcom,scale-function = <2>;
		qcom,hw-settle-time = <2>;
		qcom,fast-avg-setup = <0>;
		qcom,vadc-thermal-node;
	};

	chan@4f {
		label = "pa_therm2";
		reg = <0x4f>;
		qcom,decimation = <2>;
		qcom,pre-div-channel-scaling = <0>;
		qcom,calibration-type = "ratiometric";
		qcom,scale-function = <2>;
		qcom,hw-settle-time = <2>;
		qcom,fast-avg-setup = <0>;
		qcom,vadc-thermal-node;
	};
};

&pmd9650_pon {
	interrupts = <0x0 0x8 0x0>, <0x0 0x8 0x1>;
	interrupt-names = "kpdpwr", "resin";
	qcom,s3-src = "resin";

	qcom,pon_2 {
		qcom,pon-type = <1>;
		qcom,support-reset = <1>;
		qcom,s1-timer = <0>;
		qcom,s2-timer = <2000>;
		qcom,s2-type = <7>;
		qcom,pull-up = <1>;
	};
};
