Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9fdc6d08 authored by Anirudh Ghayal's avatar Anirudh Ghayal
Browse files

power: qpnp-vm-bms: Add QPNP voltage mode(VM) BMS driver



The voltage-mode BMS driver uses periodic VBATT readings
to calculate the state of charge(SOC) of the battery.
The final SOC is calculated by an userspace application
after post-processing the VBATT readings.

Change-Id: I3c19e8dc7f1952c4e8274209d55aad176d90a180
Signed-off-by: default avatarAnirudh Ghayal <aghayal@codeaurora.org>
parent 2e385636
Loading
Loading
Loading
Loading
+151 −0
Original line number Diff line number Diff line
Qualcomm's QPNP Voltage-Mode(VM) PMIC Battery Management System

QPNP PMIC VM BMS provides interface to clients to read properties related
to the battery. Its main function is to calculate the SOC (state of charge)
of the battery based on periodic sampling of the VBAT (battery voltage).

Parent node required properties:
- compatible	: Must be  "qcom,qpnp-vm-bms" for the BM driver.
- reg		: Offset and length of the PMIC peripheral register map.
- interrupts	: The interrupt mappings.
		  The format should be
		  <slave-id peripheral-id interrupt-number>.
- interrupt-names : names for the mapped bms interrupt
		The following interrupts are required:
		0 : leave CV state
		1 : enter CV state
		2 : good ocv generated
		3 : ocv_thr
		4 : fifo update
		5 : fsm state chnaged

Additionally, optional subnodes may be included:
- qcom,batt-pres-status : A subnode with a register address for the SMBB
		battery interface's BATT_PRES_STATUS register. If this node is
		added, then the BMS will try to detect offmode battery removal
		via the battery interface's offmode battery removal circuit.
- qcom,battery-data : A phandle to a node containing the available batterydata
		profiles. See the batterydata bindings documentation for more
		details.

Parent node required properties:
- qcom,v-cutoff-uv : cutoff voltage where the battery is considered dead in
			micro-volts.
- qcom,max-voltage-uv : maximum voltage for the battery in micro-volts.
- qcom,r-conn-mohm : connector resistance in milli-ohms.
- qcom,shutdown-soc-valid-limit : If the ocv upon restart is within this
			distance of the shutdown ocv, the BMS will try to force
			the new SoC to the old one to provide charge continuity.
			That is to say,
				if (abs(shutdown-soc - current-soc) < limit)
				then use old SoC.
- qcom,low-soc-calculate-soc-threshold : The SoC threshold for when
			the periodic calculate_soc work speeds up. This ensures
			SoC is updated in userspace constantly when we are near
			shutdown.
- qcom,low-voltage-threshold : The battery voltage threshold in micro-volts for
			when the BMS tries to wake up and hold a wakelock to
			ensure a clean shutdown.
- qcom,low-voltage-calculate-soc-ms : The time period between subsequent
			SoC recalculations when the current voltage is below
			qcom,low-voltage threshold. This takes precedence over
			qcom,low-soc-calculate-soc-ms.
- qcom,low-soc-calculate-soc-ms : The time period between subsequent
			SoC recalculations when the current SoC is below
			qcom,low-soc-calculate-soc-threshold. This takes
			precedence over qcom,calculate-soc-ms.
- qcom,calculate-soc-ms : The time period between subsequent SoC
			recalculations when the current SoC is above or equal
			qcom,low-soc-calculate-soc-threshold.
- qcom,volatge-soc-timeout-ms : The timeout period after which the module starts
			reporting volage based SOC and does not use the VMBMS
			algorithm for SOC calculation.
- qcom,bms-vadc: Corresponding VADC device's phandle.

Parent node Optional properties
- qcom,s1-sample-interval-ms: The sampling rate in ms of the accumulator in state
			S1. (i.e) the rate at which the accumulator is being
			filled with vbat samples. Minimum value = 0 and
			Maximum value = 2550ms.
- qcom,s2-sample-interval-ms: The sampling rate in ms of the accumulator in state
			S2. (i.e) the rate at which the accumulator is being
			filled with vbat samples. Minimum value = 0 and
			Maximum value = 2550ms.
- qcom,s1-sample-count: The number of samples to be accululated for one FIFO in
			state S1. Possible values are - 0, 4, 8, 16, 32, 64, 128,
			256.
- qcom,s2-sample-count: The number of samples to be accululated for one FIFO in
			state S2. Possible values are - 0, 4, 8, 16, 32, 64, 128,
			256.
- qcom,s1-fifo-legth:	Number of FIFO's to be filled in state S1, to generate
			the fifo_update_done interrupt. Possile values - 0 to 8
- qcom,s2-fifo-legth:	Number of FIFO's to be filled in state S2, to generate
			the fifo_update_done interrupt. Possible values- 0 to 8
- qcom,force-s2-in-charging: Bool property to force the BMS into S2 (CV) state
			during charging
- qcom,force-s3-on-suspend : Bool property to force the BMS into S3 (sleep) state
			while entering into system suspend.
- qcom,report-charger-eoc : Bool property to indicate if BMS needs to indicate
			EOC to charger.
- qcom,ignore-shutdown-soc: A boolean that controls whether BMS will
			try to force the startup SoC to be the same as the
			shutdown SoC. Defining it will make BMS ignore the
			shutdown SoC.
- qcom,use-voltage-soc : A boolean that controls whether BMS will use
			voltage-based SoC instead of a coulomb counter based
			one. Voltage-based SoC will not guarantee linearity.

qcom,batt-pres-status node required properties:
- reg : offset and length of the PMIC LBC battery interface BATT_PRES_STATUS
		register.

qcom,qpnp-chg-pres required properties:
- reg : offset and length of the PMIC LBC charger interafce CHARGER_OPTION
		register.

Example:
pm8916_bms: qcom,qpnp-vm-bms {
	spmi-dev-container;
	compatible = "qcom,qpnp-vm-bms";
	#address-cells = <1>;
	#size-cells = <1>;
	status = "disabled";

	qcom,v-cutoff-uv = <3400000>;
	qcom,max-voltage-uv = <4200000>;
	qcom,r-conn-mohm = <18>;
	qcom,shutdown-soc-valid-limit = <20>;
	qcom,low-soc-calculate-soc-threshold = <15>;
	qcom,low-voltage-threshold = <3420000>;
	qcom,low-voltage-calculate-soc-ms = <1000>;
	qcom,low-soc-calculate-soc-ms = <5000>;
	qcom,calculate-soc-ms = <20000>;
	qcom,volatge-soc-timeout-ms = <60000>;
	qcom,battery-data = <&mtp_batterydata>;
	qcom,bms-vadc = <&pm8916_vadc>;

	qcom,batt-pres-status@1208 {
		reg = <0x1208 0x1>;
	}

	qcom,qpnp-chg-pres@1208 {
		reg = <0x1108 0x1>;
	}

	qcom,bms-bms@4000 {
		reg = <0x4000 0x100>;
		interrupts =	<0x0 0x40 0x0>,
				<0x0 0x40 0x1>,
				<0x0 0x40 0x2>,
				<0x0 0x40 0x3>,
				<0x0 0x40 0x4>,
				<0x0 0x40 0x5>,

		interrupt-names = "leave_cv",
				  "enter_cv",
				  "good_ocv",
				  "ocv_thr",
				  "fifo_updtaed",
				  "fsm_state_change";
	};
};
+10 −0
Original line number Diff line number Diff line
@@ -466,6 +466,16 @@ config BATTERY_GOLDFISH
	  Say Y to enable support for the battery and AC power in the
	  Goldfish emulator.

config QPNP_VM_BMS
	tristate "QPNP Voltage-Mode Battery Monitoring System driver"
	depends on SPMI
	depends on MSM_QPNP_INT
	help
	  Say Y here to enable support for QPNP chip vm-bms device.
	  The voltage-mode (vm) BMS driver uses periodic VBATT
	  readings from the battery to calculate the State of
	  Charge.

config QPNP_BMS
	tristate "QPNP Battery Monitoring System driver"
	depends on SPMI
+1 −0
Original line number Diff line number Diff line
@@ -58,6 +58,7 @@ obj-$(CONFIG_SMB135X_CHARGER) += smb135x-charger.o
obj-$(CONFIG_BATTERY_BQ28400)	+= bq28400_battery.o
obj-$(CONFIG_SMB137C_CHARGER)	+= smb137c-charger.o
obj-$(CONFIG_QPNP_BMS)		+= qpnp-bms.o batterydata-lib.o
obj-$(CONFIG_QPNP_VM_BMS)	+= qpnp-vm-bms.o batterydata-lib.o batterydata-interface.o
obj-$(CONFIG_QPNP_CHARGER)	+= qpnp-charger.o
obj-$(CONFIG_CHARGER_SMB347)	+= smb347-charger.o
obj-$(CONFIG_CHARGER_TPS65090)	+= tps65090-charger.o
+2957 −0

File added.

Preview size limit exceeded, changes collapsed.

+2 −1
Original line number Diff line number Diff line
@@ -130,7 +130,8 @@ struct bms_battery_data {

#if defined(CONFIG_PM8921_BMS) || \
	defined(CONFIG_PM8921_BMS_MODULE) || \
	defined(CONFIG_QPNP_BMS)
	defined(CONFIG_QPNP_BMS) || \
	defined(CONFIG_QPNP_VM_BMS)
extern struct bms_battery_data  palladium_1500_data;
extern struct bms_battery_data  desay_5200_data;
extern struct bms_battery_data  oem_batt_data;
Loading