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

Commit f0af46d2 authored by Abhijeet Dharmapurikar's avatar Abhijeet Dharmapurikar Committed by Matt Wagantall
Browse files

power-supply: Add charging and fuel gauging drivers



Add PMIC charging and fuel gauge drivers on msm-3.18.

This snapshot is taken as of msm-3.14 commit 3bc54cf86b (Merge "msm:
camera: Add dummy sub module in sensor pipeline")

Signed-off-by: default avatarAbhijeet Dharmapurikar <adharmap@codeaurora.org>
parent 4ac34f63
Loading
Loading
Loading
Loading
+195 −0
Original line number Diff line number Diff line
Battery Profile Data

Battery Data is a collection of battery profile data made available to
the QPNP Charger and BMS drivers via device tree.

qcom,battery-data node required properties:
- qcom,rpull-up-kohm : The vadc pullup resistor's resistance value in kOhms.
- qcom,vref-batt-therm-uv : The vadc voltage used to make readings.
			For Qualcomm VADCs this should be 1800000uV.

qcom,battery-data node optional properties:
- qcom,batt-id-range-pct : The area of variation between upper and lower bound
			for which a given battery ID resistance is valid. This
			value is expressed as a percentage of the specified kohm
			resistance provided by qcom,batt-id-kohm.

qcom,battery-data can also include any number of children nodes. These children
nodes will be treated as battery profile data nodes.

Profile data node required properties:
- qcom,fcc-mah : Full charge count of the battery in milliamp-hours
- qcom,default-rbatt-mohm : The nominal battery resistance value
- qcom,rbatt-capacitive-mohm : The capacitive resistance of the battery.
- qcom,flat-ocv-threshold-uv : The threshold under which the battery can be
			considered to be in the flat portion of the discharge
			curve.
- qcom,max-voltage-uv : The maximum rated voltage of the battery
- qcom,v-cutoff-uv : The cutoff voltage of the battery at which the device
			should shutdown gracefully.
- qcom,chg-term-ua : The termination charging current of the battery.
- qcom,batt-id-kohm : The battery id resistance of the battery. It can be
			used as an array which could support multiple IDs for one battery
			module when the ID resistance of some battery modules goes across
			several ranges.
- qcom,battery-type : A string indicating the type of battery.
- qcom,fg-profile-data : An array of hexadecimal values used to configure more
			complex fuel gauge peripherals which have a large amount
			of coefficients used in hardware state machines and thus
			influencing the final output of the state of charge read
			by software.

Profile data node required subnodes:
- qcom,fcc-temp-lut : An 1-dimensional lookup table node that encodes
			temperature to fcc lookup. The units for this lookup
			table should be degrees celsius to milliamp-hours.
- qcom,pc-temp-ocv-lut : A 2-dimensional lookup table node that encodes
			temperature and percent charge to open circuit voltage
			lookup. The units for this lookup table should be
			degrees celsius and percent to millivolts.
- qcom,rbatt-sf-lut : A 2-dimentional lookup table node that encodes
			temperature and percent charge to battery internal
			resistance lookup. The units for this lookup table
			should be degrees celsius and percent to milliohms.

Profile data node optional subnodes:
- qcom,ibat-acc-luit: A 2-dimentional lookup table that encodes temperature
			and battery current to battery ACC (apparent charge
			capacity). The units for this lookup table should be
			temperature in degrees celsius, ibat in milli-amps
			and ACC in milli-ampere-hour.

Lookup table required properties:
- qcom,lut-col-legend : An array that encodes the legend of the lookup table's
			columns. The length of this array will determine the
			lookup table's width.
- qcom,lut-data : An array that encodes the lookup table's data. The size of this
			array should be equal to the size of qcom,lut-col-legend
			multiplied by 1 if it's a 1-dimensional table, or
			the size of qcom,lut-row-legend if it's a 2-dimensional
			table. The data should be in a flattened row-major
			representation.

Lookup table optional properties:
- qcom,lut-row-legend : An array that encodes the legend of the lookup table's rows.
			If this property exists, then it is assumed that the
			lookup table is a 2-dimensional table.

Example:

In msm8974-mtp.dtsi:

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

	/include/ "batterydata-palladium.dtsi"
	/include/ "batterydata-mtp-3000mah.dtsi"
};

&pm8941_bms {
	qcom,battery-data = <&mtp_batterydata>;
};

In batterydata-palladium.dtsi:

qcom,palladium-batterydata {
	qcom,fcc-mah = <1500>;
	qcom,default-rbatt-mohm = <236>;
	qcom,rbatt-capacitive-mohm = <50>;
	qcom,flat-ocv-threshold-uv = <3800000>;
	qcom,max-voltage-uv = <4200000>;
	qcom,v-cutoff-uv = <3400000>;
	qcom,chg-term-ua = <100000>;
	qcom,batt-id-kohm = <75>;
	qcom,battery-type = "palladium_1500mah";

	qcom,fcc-temp-lut {
		qcom,lut-col-legend = <(-20) 0 25 40 65>;
		qcom,lut-data = <1492 1492 1493 1483 1502>;
	};

	qcom,pc-temp-ocv-lut {
		qcom,lut-col-legend = <(-20) 0 25 40 65>;
		qcom,lut-row-legend = <100 95 90 85 80 75 70>,
				<65 60 55 50 45 40 35>,
				<30 25 20 15 10 9 8>,
				<7 6 5 4 3 2 1 0>;
		qcom,lut-data = <4173 4167 4163 4156 4154>,
			<4104 4107 4108 4102 4104>,
			<4057 4072 4069 4061 4060>,
			<3973 4009 4019 4016 4020>,
			<3932 3959 3981 3982 3983>,
			<3899 3928 3954 3950 3950>,
			<3868 3895 3925 3921 3920>,
			<3837 3866 3898 3894 3892>,
			<3812 3841 3853 3856 3862>,
			<3794 3818 3825 3823 3822>,
			<3780 3799 3804 3804 3803>,
			<3768 3787 3790 3788 3788>,
			<3757 3779 3778 3775 3776>,
			<3747 3772 3771 3766 3765>,
			<3736 3763 3766 3760 3746>,
			<3725 3749 3756 3747 3729>,
			<3714 3718 3734 3724 3706>,
			<3701 3703 3696 3689 3668>,
			<3675 3695 3682 3675 3662>,
			<3670 3691 3680 3673 3661>,
			<3661 3686 3679 3672 3656>,
			<3649 3680 3676 3669 3641>,
			<3633 3669 3667 3655 3606>,
			<3610 3647 3640 3620 3560>,
			<3580 3607 3596 3572 3501>,
			<3533 3548 3537 3512 3425>,
			<3457 3468 3459 3429 3324>,
			<3328 3348 3340 3297 3172>,
			<3000 3000 3000 3000 3000>;
	};

	qcom,rbatt-sf-lut {
		qcom,lut-col-legend = <(-20) 0 25 40 65>;
		qcom,lut-row-legend = <100 95 90 85 80 75 70>,
				<65 60 55 50 45 40 35>,
				<30 25 20 15 10 9 8>,
				<7 6 5 4 3 2 1 0>;
		qcom,lut-data = <357 187 100 91 91>,
			<400 208 105 94 94>,
			<390 204 106 95 96>,
			<391 201 108 98 98>,
			<391 202 110 98 100>,
			<390 200 110 99 102>,
			<389 200 110 99 102>,
			<393 202 101 93 100>,
			<407 205 99 89 94>,
			<428 208 100 91 96>,
			<455 212 102 92 98>,
			<495 220 104 93 101>,
			<561 232 107 95 102>,
			<634 245 112 98 98>,
			<714 258 114 98 98>,
			<791 266 114 97 100>,
			<871 289 108 95 97>,
			<973 340 124 108 105>,
			<489 241 109 96 99>,
			<511 246 110 96 99>,
			<534 252 111 95 98>,
			<579 263 112 96 96>,
			<636 276 111 95 97>,
			<730 294 109 96 99>,
			<868 328 112 98 104>,
			<1089 374 119 101 115>,
			<1559 457 128 105 213>,
			<12886 1026 637 422 3269>,
			<170899 127211 98968 88907 77102>;
	};

	qcom,ibat-acc-lut {
		qcom,lut-col-legend = <(-20) 0 25>;
		qcom,lut-row-legend = <0 250 500 1000>;
		qcom,lut-data = <1470 1470 1473>,
				<1406 1406 1430>,
				<1247 1247 1414>,
				<764 764 1338>;
	};
};
+352 −0
Original line number Diff line number Diff line
Qualcomm QPNP Charger

The charger supports the switch mode battery charger and boost (SMBB)
peripherals on Qualcomm PMIC chips.

There are seven different peripherals adding the following functionality.
Each of these peripherals are implemented as subnodes in the example at the
end of this file.

- qcom,chgr:		Supports charging control and status
			reporting.
- qcom,bat-if:		Battery status reporting such as presence,
			temperature reporting and voltage collapse
			protection.
- qcom,buck:		Charger buck configuration and status
			reporting with regards to several regulation
			loops such as vdd, ibat etc.
- qcom,usb-chgpth:	USB charge path detection and input current
			limiting configuration.
- qcom,dc-chgpth:	DC charge path detection and input current
			limiting configuration.
- qcom,chg-misc:	Miscellaneous features such as buck frequency
			settings, comparator override features etc.

Parent node required properties:
- qcom,vddmax-mv:			Target voltage of battery in mV.
- qcom,vddsafe-mv:			Maximum Vdd voltage in mV.
- qcom,vinmin-mv:			Minimum input voltage in mV.
- qcom,ibatmax-ma:			Maximum battery charge current in mA
- qcom,ibatsafe-ma:			Safety battery current setting
- qcom,thermal-mitigation:		Array of ibatmax values for different
					system thermal mitigation level.

Parent node optional properties:
- qcom,ibatterm-ma:			Current at which charging is terminated when
					the analog end of charge option is selected.
- qcom,maxinput-usb-ma:			Maximum input current USB.
- qcom,maxinput-dc-ma:			Maximum input current DC.
- qcom,vbatdet-delta-mv:		Battery charging resume delta.
- qcom,vbatweak-mv:			Weak battery voltage threshold in mV, above which
					fast charging can start. The supported voltage range is
					from 2100mV to 3600mV with a step size of 100mV.
- qcom,charging-disabled:		Set this property to disable charging
					by default. This can then be overriden
					writing the the module parameter
					"charging_disabled".
- qcom,duty-cycle-100p:			Set this property to enable the 100% duty
					cycle feature.
- qcom,use-default-batt-values:		Set this flag to force reporting of
					battery temperature of 250 decidegree
					Celsius, state of charge to be 50%
					and disable charging.
- qcom,warm-bat-decidegc:		Warm battery temperature in decidegC.
- qcom,cool-bat-decidegc:		Cool battery temperature in decidegC.
					Note that if both warm and cool battery
					temperatures are set, the corresponding
					ibatmax and bat-mv properties are
					required to be set.
- qcom,ibatmax-cool-ma:			Maximum cool battery charge current.
- qcom,ibatmax-warm-ma:			Maximum warm battery charge current.
- qcom,warm-bat-mv:			Warm temperature battery target voltage.
- qcom,cool-bat-mv:			Cool temperature battery target voltage.
- qcom,tchg-mins:			Maximum total software initialized charge time.
- qcom,bpd-detection:			Select a battery presence detection scheme by
					specifying either "bpd_thm", "bpd_id" or
					"bpd_thm_id". "bpd_thm" selects the temperature
					pin, "bpd_id" uses the id pin for battery presence
					detection, "bpd_thm_id" selects both.
					If the property is not set, the temperatue pin will
					be used.
- qcom,btc-disabled:			If flag is set battery hot and cold monitoring is
					disabled in hardware. This monitoring is turned on
					by default.
- qcom,batt-hot-percent:		Specify a supported hot threshold percentage.
					Supported thresholds: 25% and 35%. If none is specified
					hardware defaults will be used.
- qcom,batt-cold-percent:		Specify a supported cold threshold percentage.
					Supported thresholds: 70% and 80%. If none is specified
					hardware defaults will be used.
- otg-parent-supply			Specify a phandle to a parent supply regulator
					for the OTG regulator.
- boost-parent-supply			Specify a phandle to a parent supply regulator
					for the boost regulator.
- qcom,resume-soc			Capacity in percent at which charging should resume
					when a fully charged battery drops below this level.
- qcom,chg-vadc				Corresponding VADC device's phandle.
- qcom,pmic-revid			The phandle to the revid node of the pmic on which charger
					peripheral is present. This property is a must on PMIC chips
					that exhibit inaccuracies in battery current readings. This
					phandle is used to check the version of the PMIC and apply
					necessary software workarounds.
- qcom,ext-ovp-present			Indicates if an external OVP exists which reduces the
					overall input resistance of the charge path.
- qcom,ovp-monitor-en			The ovp is enabled on hw by default. If this flag is
					set, the charger ovp status is monitored in software.
- qcom,ibat-calibration-enabled		Indicates if ibat calibration is enabled. This is
					required for devices which have a ibat trim error
					causing ibatmax to go out of spec.
- qcom,power-stage-reduced		Indicates if power stage workaround is enabled. This work
					around reduces the power stage segments while charging
					under high load during low battery voltages. It's for
					improving IADC accuracy while board has a bad layout.
- qcom,use-external-rsense		A boolean that controls whether BMS will use
					an external sensor resistor instead of the default
					RDS of the batfet.
- qcom,vbatdet-maxerr-mv		This property in mV is a hystersis value for the charge
					resume voltage property qcom,vbatdet-delta-mv. If this
					property is not defined it defaults to 50 mV.
- qcom,parallel-ovp-mode		When this option is enabled, it allows charging through both
					DC and USB OVP FETs. Please note that this should only
					be enabled in board designs with PM8941 which have DC_IN
					and USB_IN connected via a short.
 - qcom,ext-ovp-isns-enable-gpio	External OVP enable GPIO.
 - qcom,ext-ovp-isns-r-ohm			External ISNS OVP resistance in ohm.

Sub node required structure:
- A qcom,chg node must be a child of an SPMI node that has specified
	the spmi-dev-container property. Each subnode reflects
	a hardware peripheral which adds a unique set of features
	to the collective charging device. For example USB detection
	and the battery interface are each seperate peripherals and
	each should be their own subnode.
- qcom,chg-adc_tm			Corresponding ADC TM device's phandle to set recurring
					measurements and receive notification for batt_therm.

Sub node required properties:
- compatible:		Must be "qcom,qpnp-charger".
- reg:			Specifies the SPMI address and size for this peripheral.
- interrupts:		Specifies the interrupt associated with the peripheral.
- interrupt-names:	Specifies the interrupt names for the peripheral. Every
			available interrupt needs to have an associated name
			with it to indentify its purpose.

			The following lists each subnode and their corresponding
			required interrupt names:

			qcom,usb-chgpth:
			 - usbin-valid
			 - usb-ocp (only for SMBBP and SMBCL)

			qcom,chgr:
			 - chg-done
			 - chg-failed

			The following interrupts are available:

			qcom,chgr:
			 - chg-done:		Triggers on charge completion.
			 - chg-failed:		Notifies of charge failures.
			 - fast-chg-on:		Notifies of fast charging state.
			 - trkl-chg-on:		Indicates trickle charging.
			 - state-change:	Notifies of a state change in
						the charger state machine.
			 - chgwdog:		Charger watchdog interrupt.
			 - vbat-det-hi:		Triggers on vbat-det-hi voltage
						setting,can be used as
						battery alarm.
			 - vbat-det-hi:		Triggers on vbat-det-low voltage
						setting, can be used as
						battery alarm.

			qcom,buck:
			 - vdd-loop:		VDD loop change interrupt.
			 - ibat-loop:		Ibat loop change interrupt.
			 - ichg-loop:		Charge current loop change.
			 - vchg-loop:		Charge voltage loop change.
			 - overtemp:		Overtemperature interrupt.
			 - vref-ov:		Reference overvoltage interrupt.
			 - vbat-ov:		Battery overvoltage interrupt.

			qcom,bat-if:
			 - psi:			PMIC serial interface interrupt.
			 - vcp-on:		Voltage collapse protection
						status interrupt.
			 - bat-fet-on:		BATFET status interrupt.
			 - bat-temp-ok:		Battery temperature status
						interrupt.
			 - batt-pres:		Battery presence status
						interrupt.

			qcom,usb-chgpth:
			 - usbin-valid:		Indicates valid USB connection.
			 - coarse-det-usb:	Coarse detect interrupt triggers
						at low voltage on USB_IN.
			 - chg-gone:		Triggers on VCHG line.
			 - usb-ocp		Triggers on over current conditions when
						reverse boosting. (Only available on
						SMBCL and SMBBP devices).

			qcom,dc-chgpth:
			 - dcin-valid:		Indicates a valid DC charger
						connection.
			 - coarse-det-dc:	Coarse detect interrupt triggers
						at low voltage on DC_IN.

			qcom,boost:
			 - limit-error:		Limiting error on SMBB boost.
			 - boost-pwr-ok:	Status of boost power.

Sub node optional properties:
			qcom,usb-chgpth:
			 - regulator-name:	A string used as a descriptive name
						for the OTG regulator.
			qcom,boost:
			 - regulator-min-microvolt:	Minimum boost voltage setting.
			 - regulator-max-microvolt:	Maximum boost voltage setting.
			 - regulator-name:	A string used as a descriptive name
						for the boost regulator.

			qcom,batfet:
			 - regulator-name:	A string used as a descriptive name
						for the batfet regulator.

			qcom,chgr:
			 - regulator-name:	A string used as a descriptive name
						for the flash workarounds regulator.
Example:
	pm8941-chg {
		spmi-dev-container;
		compatible = "qcom,qpnp-charger";
		#address-cells = <1>;
		#size-cells = <1>;

		otg-parent-supply = <&pm8941_boost>;
		boost-parent-supply = <&foo_parent_reg>;

		qcom,vddmax-mv = <4200>;
		qcom,vddsafe-mv = <4200>;
		qcom,vinmin-mv = <4200>;
		qcom,ibatmax-ma = <1500>;
		qcom,ibatterm-ma = <200>;
		qcom,ibatsafe-ma = <1500>;
		qcom,vbatweak-mv = <3200>;
		qcom,thermal-mitigation = <1500 700 600 325>;
		qcom,cool-bat-degc = <10>;
		qcom,cool-bat-mv = <4100>;
		qcom,ibatmax-warm-ma = <350>;
		qcom,warm-bat-degc = <45>;
		qcom,warm-bat-mv = <4100>;
		qcom,ibatmax-cool-ma = <350>;
		qcom,vbatdet-delta-mv = <60>;
		qcom,batt-hot-percent = <25>;
		qcom,batt-cold-percent = <85>;
		qcom,btc-disabled = <0>;
		qcom,chg-vadc = <&pm8941_vadc>;
		qcom,chg-adc_tm = <&pm8941_adc_tm>;
		qcom,pmic-revid = <&pm8941_revid>;

		qcom,chgr@1000 {
			reg = <0x1000 0x100>;
			interrupts =	<0x0 0x10 0x0>,
				<0x0 0x10 0x1>,
					<0x0 0x10 0x2>,
					<0x0 0x10 0x3>,
					<0x0 0x10 0x4>,
					<0x0 0x10 0x5>,
					<0x0 0x10 0x6>,
					<0x0 0x10 0x7>;

			interrupt-names =	"chg-done",
						"chg-failed",
						"fast-chg-on",
						"trkl-chg-on",
						"state-change",
						"chgwdog",
						"vbat-det-hi",
						"vbat-det-lo";
		};

		qcom,buck@1100 {
			reg = <0x1100 0x100>;
			interrupts =	<0x0 0x11 0x0>,
					<0x0 0x11 0x1>,
					<0x0 0x11 0x2>,
					<0x0 0x11 0x3>,
					<0x0 0x11 0x4>,
					<0x0 0x11 0x5>,
					<0x0 0x11 0x6>;

			interrupt-names =	"vdd-loop",
						"ibat-loop",
						"ichg-loop",
						"vchg-loop",
						"overtemp",
						"vref-ov",
						"vbat-ov";
		};

		qcom,bat-if@1200 {
			reg = <0x1200 0x100>;
			interrupts =	<0x0 0x12 0x0>,
					<0x0 0x12 0x1>,
					<0x0 0x12 0x2>,
					<0x0 0x12 0x3>,
					<0x0 0x12 0x4>;

			interrupt-names =	"psi",
						"vcp-on",
						"bat-fet-on",
						"bat-temp-ok",
						"batt-pres";
		};

		pm8941_chg_otg: qcom,usb-chgpth@1300 {
			reg = <0x1300 0x100>;
			interrupts =	<0 0x13 0x0>,
					<0 0x13 0x1>,
					<0x0 0x13 0x2>;

			interrupt-names =	"usbin-valid",
						"coarse-det-usb",
						"chg-gone";
		};

		qcom,dc-chgpth@1400 {
			reg = <0x1400 0x100>;
			interrupts =	<0x0 0x14 0x0>,
					<0x0 0x14 0x1>;

			interrupt-names =	"dcin-valid",
						"coarse-det-dc";
		};

		pm8941_chg_boost: qcom,boost@1500 {
			reg = <0x1500 0x100>;
			interrupts =	<0x0 0x15 0x0>,
					<0x0 0x15 0x1>;

			interrupt-names =	"limit-error",
						"boost-pwr-ok";
		};

		qcom,misc@1600 {
			reg = <0x1600 0x100>;
		};
	};

In regulator specific device tree file:

	&pm8941_chg_boost {
		regulator-min-microvolt = <5000000>;
		regulator-max-microvolt = <5000000>;
		regulator-name = "8941_smbb_boost";
	};

	&pm8941_chg_batif  {
		regulator-name = "batfet";
	};

	&pm8941_chg_otg {
		regulator-name = "8941_smbb_otg";
	};
+250 −0

File added.

Preview size limit exceeded, changes collapsed.

+211 −0

File added.

Preview size limit exceeded, changes collapsed.

+363 −0

File added.

Preview size limit exceeded, changes collapsed.

Loading