#include "khaje-pm7250b.dtsi"
#include "khaje-thermal-pm7250b-overlay.dtsi"
#include <dt-bindings/iio/qti_power_supply_iio.h>

&soc {
	qrd_batterydata: qcom,battery-data {
		qcom,batt-id-range-pct = <15>;
		#include "qg-batterydata-atl466271_3300mAh.dtsi"
	};
};

&tlmm {
	smb_int_default: smb_int_default {
		mux {
			pins = "gpio105";
			function = "gpio";
		};

		config {
			pins = "gpio105";
			bias-pull-up;
			input-enable;
		};
	};
};

&qupv3_se1_i2c {
	status = "ok";
	#include "smb1394.dtsi"
};

&smb1394 {
	pinctrl-names = "default";
	pinctrl-0 = <&smb_int_default>;
	interrupt-parent = <&tlmm>;
	interrupt-names = "smb1394";
	interrupts = <105 IRQ_TYPE_LEVEL_LOW>;
	status = "ok";
};

&smb1394_div2_cp_primary {
	io-channels = <&pm7250b_vadc ADC5_AMUX_THM2>;
	io-channel-names = "die_temp";
	qcom,parallel-input-mode = <1>;
	qcom,parallel-output-mode = <2>;
	status = "ok";
};

&pm7250b_vadc {
	smb1390_therm@e {
		qcom,scale-fn-type = <ADC_SCALE_HW_CALIB_PM5_SMB1398_TEMP>;
	};
};

&pm7250b_charger {
	status = "ok";
	#io-channel-cells = <1>;
	io-channels = <&pm7250b_vadc ADC5_USB_IN_V_16>,
		      <&pm7250b_vadc ADC5_USB_IN_I>,
		      <&pm7250b_vadc ADC5_CHG_TEMP>,
		      <&pm7250b_vadc ADC5_DIE_TEMP>,
		      <&pm7250b_vadc ADC5_AMUX_THM3_100K_PU>,
		      <&pm7250b_vadc ADC5_SBUx>,
		      <&pm7250b_vadc ADC5_VPH_PWR>,
		      <&pm7250b_vadc ADC5_AMUX_THM1_100K_PU>,
		      <&pm7250b_qg PSY_IIO_RESISTANCE_ID>,
		      <&pm7250b_qg PSY_IIO_VOLTAGE_NOW>,
		      <&pm7250b_qg PSY_IIO_TEMP>,
		      <&pm7250b_qg PSY_IIO_CAPACITY>,
		      <&pm7250b_qg PSY_IIO_VOLTAGE_OCV>,
		      <&pm7250b_qg PSY_IIO_VOLTAGE_AVG>,
		      <&pm7250b_qg PSY_IIO_DEBUG_BATTERY>,
		      <&pm7250b_qg PSY_IIO_REAL_CAPACITY>,
		      <&pm7250b_qg PSY_IIO_CC_SOC>,
		      <&pm7250b_qg PSY_IIO_CURRENT_NOW>,
		      <&pm7250b_qg PSY_IIO_VOLTAGE_MAX>,
		      <&pm7250b_qg PSY_IIO_CHARGE_FULL>,
		      <&pm7250b_qg PSY_IIO_CHARGE_COUNTER>,
		      <&pm7250b_qg PSY_IIO_CYCLE_COUNT>,
		      <&pm7250b_qg PSY_IIO_CHARGE_FULL_DESIGN>,
		      <&pm7250b_qg PSY_IIO_TIME_TO_FULL_NOW>;
	io-channel-names = "usb_in_voltage",
			   "usb_in_current",
			   "chg_temp",
			   "die_temp",
			   "conn_temp",
			   "sbux_res",
			   "vph_voltage",
			   "skin_temp",
			   "resistance_id",
			   "voltage_now",
			   "temp",
			   "capacity",
			   "voltage_ocv",
			   "voltage_avg",
			   "debug_battery",
			   "real_capacity",
			   "cc_soc",
			   "current_now",
			   "voltage_max",
			   "charge_full",
			   "charge_counter",
			   "cycle_count",
			   "charge_full_design",
			   "time_to_full_now";
	qcom,battery-data = <&qrd_batterydata>;
	qcom,sec-charger-config = <1>;
	qcom,auto-recharge-soc = <98>;
	qcom,step-charging-enable;
	qcom,sw-jeita-enable;
	qcom,charger-temp-max = <800>;
	qcom,smb-temp-max = <800>;
	qcom,suspend-input-on-debug-batt;
	qcom,fcc-stepping-enable;
	qcom,fcc-step-delay-ms = <100>;
	qcom,fcc-step-size-ua = <100000>;
	qcom,smb-internal-pull-kohm = <0>;
	qcom,thermal-mitigation = <8000000 7500000 7000000 6500000 6000000 5500000
			5000000 4500000 4000000 3500000 3000000 2500000 2000000 1500000
			1000000 500000>;
};

&pm7250b_qg {
	status = "ok";
	#io-channel-cells = <1>;
	io-channels = <&pm7250b_vadc ADC5_BAT_THERM_100K_PU>,
		      <&pm7250b_vadc ADC5_BAT_ID_100K_PU>,
		      <&pm7250b_charger PSY_IIO_INPUT_CURRENT_LIMITED>,
		      <&pm7250b_charger PSY_IIO_RECHARGE_SOC>,
		      <&pm7250b_charger PSY_IIO_FORCE_RECHARGE>,
		      <&pm7250b_charger PSY_IIO_CHARGE_DONE>;
	io-channel-names = "batt-therm",
			   "batt-id",
			   "input_current_limited",
			   "recharge_soc",
			   "force_recharge",
			   "charge_done";
	qcom,qg-iterm-ma = <150>;
	qcom,hold-soc-while-full;
	qcom,linearize-soc;
	qcom,cl-feedback-on;
	qcom,tcss-enable;
	qcom,fvss-enable;
	qcom,fvss-vbatt-mv = <3500>;
	qcom,bass-enable;
	qcom,vbatt-cutoff-mv = <3400>;
	qcom,vbatt-low-mv = <3500>;
	qcom,vbatt-low-cold-mv = <3800>;
	qcom,vbatt-empty-mv = <3200>;
	qcom,vbatt-empty-cold-mv = <3100>;
	qcom,use-cp-iin-sns;
};

&pm7250b_charger {
	dpdm-supply = <&usb2_phy0>;

	smb5_vbus: qcom,smb5-vbus {
		regulator-name = "smb5-vbus";
	};

	smb5_vconn: qcom,smb5-vconn {
		regulator-name = "smb5-vconn";
	};
};

&pm7250b_pdphy {
	vdd-pdphy-supply = <&L15A>;
	vbus-supply = <&smb5_vbus>;
	vconn-supply = <&smb5_vconn>;

		#io-channel-cells = <1>;
		io-channels = <&pm7250b_charger PSY_IIO_PD_ACTIVE>,
					  <&pm7250b_charger PSY_IIO_TYPEC_CC_ORIENTATION>,
					  <&pm7250b_charger PSY_IIO_CONNECTOR_TYPE>,
					  <&pm7250b_charger PSY_IIO_TYPEC_POWER_ROLE>,
					  <&pm7250b_charger PSY_IIO_PD_USB_SUSPEND_SUPPORTED>,
					  <&pm7250b_charger PSY_IIO_TYPEC_SRC_RP>,
					  <&pm7250b_charger PSY_IIO_PD_IN_HARD_RESET>,
					  <&pm7250b_charger PSY_IIO_PD_CURRENT_MAX>,
					  <&pm7250b_charger PSY_IIO_PR_SWAP>,
					  <&pm7250b_charger PSY_IIO_PD_VOLTAGE_MIN>,
					  <&pm7250b_charger PSY_IIO_PD_VOLTAGE_MAX>,
					  <&pm7250b_charger PSY_IIO_USB_REAL_TYPE>,
					  <&pm7250b_charger PSY_IIO_TYPEC_MODE>,
					  <&pm7250b_charger PSY_IIO_PE_START>;
		io-channel-names = "pd_active",
					  "typec_cc_orientation",
					  "connector_type",
					  "typec_power_role",
					  "pd_usb_suspend_supported",
					  "typec_src_rp",
					  "pd_in_hard_reset",
					  "pr_current_max",
					  "pr_swap",
					  "pd_voltage_min",
					  "pd_voltage_max",
					  "real_type",
					  "typec_mode",
					  "pe_start";
};

&usb0 {
	extcon = <&pm7250b_pdphy>, <&pm7250b_charger>, <&eud>;
};

&thermal_zones {
	quiet-therm {
		cooling-maps {
			quiet_batt_cdev1 {
				trip = <&quiet_batt_trip0>;
				cooling-device = <&pm7250b_charger 8 8>;
			};

			quiet_batt_cdev2 {
				trip = <&quiet_batt_trip1>;
				cooling-device = <&pm7250b_charger 12 12>;
			};

			quiet_batt_cdev3 {
				trip = <&quiet_batt_trip2>;
				cooling-device = <&pm7250b_charger 14 14>;
			};

			quiet_batt_cdev4 {
				trip = <&quiet_batt_trip3>;
				cooling-device = <&pm7250b_charger 16 16>;
			};
		};
	};

	pm7250b-tz {
		cooling-maps {
			trip0_bat {
				cooling-device = <&pm7250b_charger 15 15>;
			};

			trip1_bat {
				cooling-device = <&pm7250b_charger 16 16>;
			};
		};
	};
};
