#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/pinctrl/qcom,pmic-gpio.h>
#include <dt-bindings/iio/qcom,spmi-vadc.h>
#include <dt-bindings/interrupt-controller/irq.h>

#include "pm8150.dtsi"

&soc {
	reboot_reason {
		compatible = "qcom,reboot-reason";
		nvmem-cells = <&restart_reason>;
		nvmem-cell-names = "restart_reason";
	};

	gpio_keys {
		compatible = "gpio-keys";
		label = "gpio-keys";
		pinctrl-names = "default";
		pinctrl-0 = <&gpio_vol_up>;

		vol_up {
			label = "vol_up";
			gpios = <&tlmm 122 GPIO_ACTIVE_LOW>;
			linux,input-type = <1>;
			linux,code = <KEY_VOLUMEUP>;
			debounce-interval = <15>;
			linux,can-disable;
		};
	};
};

&pm8150_vadc {
	pm8150_skin_therm {
		reg = <ADC5_AMUX_THM1_100K_PU>;
		label = "pm8150_skin_temp";
		qcom,hw-settle-time = <200>;
		qcom,ratiometric;
		qcom,pre-scaling = <1 1>;
	};

	/*
	 * This thermistor has 100k pullup already connected,
	 * modify config following HW recommendation, for all
	 * platforms other than SG.
	 */
	pm8150_wlan_therm {
		reg = <ADC5_AMUX_THM2>;
		label = "pm8150_wlan_temp";
		qcom,hw-settle-time = <200>;
		qcom,pre-scaling = <1 1>;
		qcom,scale-fn-type = <ADC_SCALE_HW_CALIB_THERM_100K_PULLUP>;
	};

	pm8150_xo_therm {
		reg = <ADC5_XO_THERM_100K_PU>;
		label = "pm8150_xo_therm";
		qcom,hw-settle-time = <600>;
		qcom,ratiometric;
		qcom,pre-scaling = <1 1>;
	};
};

&pm8150_adc_tm {
	io-channels = <&pm8150_vadc ADC5_AMUX_THM1_100K_PU>,
			<&pm8150_vadc ADC5_AMUX_THM2>,
			<&pm8150_vadc ADC5_XO_THERM_100K_PU>;

	pm8150_skin_therm {
		reg = <ADC5_AMUX_THM1_100K_PU>;
		qcom,hw-settle-time = <200>;
		qcom,ratiometric;
	};

	/*
	 * This thermistor has 100k pullup already connected,
	 * modify config following HW recommendation, for all
	 * platforms other than SG.
	 */
	pm8150_wlan_therm {
		reg = <ADC5_AMUX_THM2>;
		qcom,hw-settle-time = <200>;
	};

	pm8150_xo_therm {
		reg = <ADC5_XO_THERM_100K_PU>;
		qcom,hw-settle-time = <600>;
		qcom,ratiometric;
	};
};

&thermal_zones {
	sys-therm-0 {
		polling-delay-passive = <0>;
		polling-delay = <0>;
		thermal-sensors = <&pm8150_adc_tm ADC5_AMUX_THM1_100K_PU>;
		trips {
			active-config0 {
				temperature = <125000>;
				hysteresis = <1000>;
				type = "passive";
			};

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

	sys-therm-1 {
		polling-delay-passive = <0>;
		polling-delay = <0>;
		thermal-sensors = <&pm8150_adc_tm ADC5_AMUX_THM2>;
		trips {
			active-config0 {
				temperature = <125000>;
				hysteresis = <1000>;
				type = "passive";
			};

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

	xo-therm {
		polling-delay-passive = <0>;
		polling-delay = <0>;
		thermal-sensors = <&pm8150_adc_tm ADC5_XO_THERM_100K_PU>;
		trips {
			active-config0 {
				temperature = <125000>;
				hysteresis = <1000>;
				type = "passive";
			};

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

&qupv3_se10_i2c {
	clock-frequency = <400000>;

	#address-cells = <1>;
	#size-cells = <0>;
	status = "ok";

	battery: battery {
		compatible = "simple-battery";
		voltage-min-design-microvolt = <3100000>;
		energy-full-design-microwatt-hours = <2520000>;
		charge-full-design-microamp-hours = <645000>;
		over-voltage-threshold-microvolt = <4500000>;
		re-charge-voltage-microvolt = <250000>;
		/* bq256xx's termination current setting has a min limit of 60mA */
		charge-term-current-microamp = <60000>;
		constant-charge-current-max-microamp = <500000>;
		constant-charge-voltage-max-microvolt = <4480000>;
		voltage-max-design-microvolt = <4480000>;
		precharge-current-microamp = <128000>;
		factory-internal-resistance-micro-ohms = <120000>;
	};

	charger: charger@6b {
		compatible = "ti,bq25600";
		reg = <0x6b>;

		interrupt-parent = <&tlmm>;
		interrupts = <6 IRQ_TYPE_EDGE_FALLING>;
		debugboard-detect-gpio = <&tlmm 54 GPIO_ACTIVE_HIGH>;
		ti,watchdog-timeout-ms = <0>;
		pinctrl-names =  "default";
		pinctrl-0 = <&bq256xx_intr_default>;

		input-voltage-limit-microvolt = <4480000>;
		input-current-limit-microamp = <500000>;
		monitored-battery = <&battery>;
		status = "ok";
	};

	battery_645mAh: battery_645mAh {
		qmax-cell0 = <15546>;
		resist-table = <8 8 8 10 12 9 13 18 23 29 34 47 60 87 131>;
	};

	battery_630mAh: battery_630mAh {
		qmax-cell0 = <15656>;
		resist-table = <16 16 17 20 22 13 17 18 18 18 17 23 28 44 62>;
	};

	bq27421: fuel-gauge@55 {
		compatible = "ti,bq27421";
		reg = <0x55>;

		interrupt-parent = <&tlmm>;
		interrupts = <7 IRQ_TYPE_EDGE_FALLING>;
		pinctrl-names =  "default";
		pinctrl-0 = <&bq27421_intr_default>;

		bat-resist-table = <&battery_645mAh>;
		monitored-battery = <&battery>;
		status = "ok";
	};
};

&usb0 {
	extcon = <&charger>, <&eud>;
};

&pm8150_pon {
	qcom,log-kpd-event;
};
