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

Commit 9694891e authored by Abhijeet Dharmapurikar's avatar Abhijeet Dharmapurikar Committed by Ram Chandrasekar
Browse files

power: battery_current_limit: Support btm based current measurement



On some hardware configurations battery current can be
read from adc. Update the code to configure the adc to
periodically read the battery current and setup
notifications when the thresholds are crossed. Reduce max
frequency for all cpus when in high current mode.

Configuring battery current monitoring:
=> The bcl "type" sysfs node should read out "btm" and NOT
"bcl" for battery current monitor mode operation.
 cat /sys/devices/qcom,bcl.29/type

=> Use the "mode" sysfs node to determine whether the
BCL driver is enabled or disabled. Configuring the BCL
operational parameters require the users to,
    * disable the BCL driver.
    * configure one or more BCL operational parameters.
    * re-enable the BCL driver.
 cat /sys/devices/qcom,bcl.29/mode

=> The sysfs node "high_threshold_ua" can be used to
configure the current threshold, ABOVE which the max
cpu frequency is restricted.
 echo "disable" > /sys/devices/qcom,bcl.29/mode
 echo 2000000 > /sys/devices/qcom,bcl.29/high_threshold_ua
 echo "enable" > /sys/devices/qcom,bcl.29/mode
 cat /sys/devices/qcom,bcl.29/high_threshold_ua
In the above commands, the BCL driver is disabled before
configuring the high threshold. The high threshold is
configured to 2A and then the driver is re-enabled.

=> The sysfs node "low_threshold_ua" can be used to
configure the current threshold, BELOW which the max
cpu frequency restriction is removed.
 echo "disable" > /sys/devices/qcom,bcl.29/mode
 echo 1000000 > /sys/devices/qcom,bcl.29/low_threshold_ua
 echo "enable" > /sys/devices/qcom,bcl.29/mode
 cat /sys/devices/qcom,bcl.29/low_threshold_ua
In the above commands, the BCL driver is disabled before
configuring the low threshold. The low threshold is
configured to 1A and then the driver is re-enabled.

=> The sysfs node "freq_max", can be used to configure
the BCL max frequency mitigation value. The BCL s/w by
default is configured to restrict the cpu max frequency
to 1.9Ghz. BCL driver doesn't mitigate the max cpu
frequency below 1.9GHz. Any request to the max frequency
value below 1.9Ghz, will be considered as a request for
1.9Ghz by BCL driver.
 echo "disable" > /sys/devices/qcom,bcl.29/mode
 echo 2265600 > /sys/devices/qcom,bcl.29/freq_max
 echo "enable" > /sys/devices/qcom,bcl.29/mode
 cat /sys/devices/qcom,bcl.29/freq_max
This command echo 2265600 > /sys/devices/qcom,bcl.29/freq_max,
will set the max cpu frequency restriction to 2.2Ghz. But
the command echo 300000 > /sys/devices/qcom,bcl.29/freq_max,
will restrict the max frequency restriction to 1.9Ghz.

=> The "adc_interval_us" sysfs node can be queried for
the ADC polling timer interval.
 cat /sys/devices/qcom,bcl.29/adc_interval_us

=> The "high_load_state" sysfs nodes can be queried to see
whether the BCL driver has sensed a high load state or not.
 cat /sys/devices/qcom,bcl.29/high_load_state
For the above command if a value 1 is returned, then it
implies that BCL has sensed a high load state and has
restricted the CPU max frequencies.

Change-Id: Ib3981c46f4fd44d90806a84276c98b8608ee8957
Signed-off-by: default avatarRam Chandrasekar <rkumbako@codeaurora.org>
parent 01f3b4c6
Loading
Loading
Loading
Loading
+66 −1
Original line number Diff line number Diff line
* Battery Current Limit

This Battery Current Limit device, provides an interface to detect and notify
This Battery Current Limit(BCL) device, provides an interface to detect and notify
interested applications when the SOC is drawing current in excess of the limits
specified.
The BCL driver has another operation mode, where it monitors the battery
current sensor via ADC TM hardware called BTM. The newer devices support
a BTM hardware configuration, which can measure the battery current and voltage.
This ADC hardware is capable of sampling the sensor every 1 msec and interrupts
the BCL driver, which in turn mitigates the CPU frequency based on the
current load thresholds. The BCL drivers operation mode is decided based
on the parameters given in the device tree. In this BTM operation mode, BCL
driver provides sysfs entries to configure the thresholds, ADC polling
timer interval and other operational parameters.

The device tree parameters for bcl are:

Required parameters:
- compatible: Must be "qcom,bcl"

Optional parameters:
- qcom,bcl-enable : If this property is defined, BCL functionality will
		be enabled from boot. The mode of operation, will be based
		on the properties defined in the device tree.
- qcom,ibat-vadc = <&vadc_phandle>: A phandle to the VADC device. The BTM mode
		of operation requires this property to be defined if and only
		if qcom,ibat-threshold-adc_tm and qcom,ibat-monitor are defined.
		Error in any of these properties will disable BTM mode of operation
		and will fall back to the available current monitor mode.
- qcom,ibat-threshold-adc_tm = <&vadc_tm_phandle>: A phandle to the ADC TM
		device. BCL registers with the hardware monitor for this TM
		device to be able to set thresholds and get threshold
		notifications. The BTM mode of operation requires this property
		to be defined if and only if qcom,ibat-vadc and qcom,ibat-monitor
		are defined. Error in any of these properties will disable BTM
		mode of operation and will fall back to the available current
		monitor mode.

Optional nodes:
- qcom,ibat-monitor: This optional node defines all the parameters for the
		battery current monitoring. The BTM mode of operation requires
		all the below properties to be defined with valid values. Also,
		this node should be defined if and only if qcom,ibat-vadc and
		qcom,ibat-threshold-adc_tm are defined. Error in any of these
		properties will disable BTM mode of operation and will fall
		back to the available current monitor mode.
	* high-threshold-uamp: The battery current, in microampere, after which
		the BCL driver should cap the maximum frequency.
	* low-threshold-uamp: The battery current, in microampere, below which
		the BCL driver should clear the CPU frequency mitigation.
	* mitigation-freq-khz: The maximum frequency value the BCL driver
		should mitigate the CPUS's with. This frequency shouldn't be
		less than the minimum frequency request that the kernel thermal
		monitor driver places during vdd restriction.
	* ibat-channel: The ADC hardware's channel number.
	* uv-to-ua-numerator: The conversion parameter required for converting
		the voltage measure from ADC hardware to current value.
	* uv-to-ua-denominator: The conversion parameter required for
		converting the voltage measure from ADC hardware to current.
		The microvolt to microampere (or vice-versa) conversion uses
		the below conversion formulae.
		ua = (uv * uv-to-ua-numerator) / uv-to-ua-denominator
	* adc-interval-usec: The polling interval, in microseconds, for the ADC
		hardware.

Example:
	qcom,bcl {
		compatible = "qcom,bcl";
		qcom,ibat-vadc = <&pma8084_vadc>;
		qcom,ibat-threshold-adc_tm = <&pma8084_adc_tm>;
		qcom,ibat-monitor {
			high-threshold-uamp = <1500>;
			low-threshold-uamp = <500>;
			mitigation-freq-khz = <1958400>;
			ibat-channel = <0x15>;
			adc-interval-usec = <3900>;
			uv-to-ua-numerator = <2>;
			uv-to-ua-denominator = <1>;
		};
	};
+582 −75

File changed.

Preview size limit exceeded, changes collapsed.