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

Commit 88ca25aa authored by Linux Build Service Account's avatar Linux Build Service Account Committed by Gerrit - the friendly Code Review server
Browse files

Merge "power: qpnp-qg: add support for capacity learning and cycle counter" into msm-4.9

parents f35937a4 a791d522
Loading
Loading
Loading
Loading
+71 −0
Original line number Diff line number Diff line
@@ -191,6 +191,77 @@ First Level Node - QGAUGE device
		    temperature specific configuration as applied. If not
		    specified, the default value is 0 degree centigrade.

- qcom,cl-disable
	Usage:      optional
	Value type: <empty>
	Definition: A boolean property to disable the battery capacity
		    learning when charging.

- qcom,cl-feedback-on
	Usage:      optional
	Value type: <empty>
	Definition: A boolean property to feedback the learned capacity into
		    the capacity lerning algorithm. This has to be used only if the
		    property "qcom,cl-disable" is not specified.

- qcom,cl-max-start-soc
	Usage:      optional
	Value type: <u32>
	Definition: Battery SOC has to be below or equal to this value at the
		    start of a charge cycle to start the capacity learning.
		    If this is not specified, then the default value used
		    will be 15. Unit is in percentage.

- qcom,cl-min-start-soc
	Usage:      optional
	Value type: <u32>
	Definition: Battery SOC has to be above or equal to this value at the
		    start of a charge cycle to start the capacity learning.
		    If this is not specified, then the default value used
		    will be 10. Unit is in percentage.

- qcom,cl-min-temp
	Usage:      optional
	Value type: <u32>
	Definition: Lower limit of battery temperature to start the capacity
		    learning. If this is not specified, then the default value
		    used will be 150 (15 C). Unit is in decidegC.

- qcom,cl-max-temp
	Usage:      optional
	Value type: <u32>
	Definition: Upper limit of battery temperature to start the capacity
		    learning. If this is not specified, then the default value
		    used will be 500 (50 C). Unit is in decidegC.

- qcom,cl-max-increment
	Usage:      optional
	Value type: <u32>
	Definition: Maximum capacity increment allowed per capacity learning
		    cycle. If this is not specified, then the default value
		    used will be 5 (0.5%). Unit is in decipercentage.

- qcom,cl-max-decrement
	Usage:      optional
	Value type: <u32>
	Definition: Maximum capacity decrement allowed per capacity learning
		    cycle. If this is not specified, then the default value
		    used will be 100 (10%). Unit is in decipercentage.

- qcom,cl-min-limit
	Usage:      optional
	Value type: <u32>
	Definition: Minimum limit that the capacity cannot go below in a
		    capacity learning cycle. If this is not specified, then
		    the default value is 0. Unit is in decipercentage.

- qcom,cl-max-limit
	Usage:      optional
	Value type: <u32>
	Definition: Maximum limit that the capacity cannot go above in a
		    capacity learning cycle. If this is not specified, then
		    the default value is 0. Unit is in decipercentage.

==========================================================
Second Level Nodes - Peripherals managed by QGAUGE driver
==========================================================
+1 −1
Original line number Diff line number Diff line
@@ -7,7 +7,7 @@ obj-$(CONFIG_SMB1355_SLAVE_CHARGER) += smb1355-charger.o pmic-voter.o
obj-$(CONFIG_SMB1351_USB_CHARGER) += smb1351-charger.o pmic-voter.o battery.o
obj-$(CONFIG_QPNP_SMB2)		+= step-chg-jeita.o battery.o qpnp-smb2.o smb-lib.o pmic-voter.o storm-watch.o
obj-$(CONFIG_SMB138X_CHARGER)	+= step-chg-jeita.o smb138x-charger.o smb-lib.o pmic-voter.o storm-watch.o battery.o
obj-$(CONFIG_QPNP_QG)		+= qpnp-qg.o pmic-voter.o qg-util.o qg-soc.o qg-sdam.o qg-battery-profile.o qg-profile-lib.o
obj-$(CONFIG_QPNP_QG)		+= qpnp-qg.o pmic-voter.o qg-util.o qg-soc.o qg-sdam.o qg-battery-profile.o qg-profile-lib.o fg-alg.o
obj-$(CONFIG_QPNP_QNOVO)	+= qpnp-qnovo.o battery.o
obj-$(CONFIG_QPNP_TYPEC)	+= qpnp-typec.o
obj-$(CONFIG_QPNP_SMB5)		+= step-chg-jeita.o battery.o qpnp-smb5.o smb5-lib.o pmic-voter.o storm-watch.o schgm-flash.o
+21 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@
#include <linux/slab.h>
#include <linux/uaccess.h>
#include <uapi/linux/qg-profile.h>
#include "qg-battery-profile.h"
#include "qg-profile-lib.h"
#include "qg-defs.h"

@@ -410,6 +411,26 @@ int lookup_soc_ocv(u32 *soc, u32 ocv_uv, int batt_temp, bool charging)
	return 0;
}

int qg_get_nominal_capacity(u32 *nom_cap_uah, int batt_temp, bool charging)
{
	u8 table_index = charging ? TABLE_FCC1 : TABLE_FCC2;
	u32 fcc_mah;

	if (!the_battery || !the_battery->profile) {
		pr_err("Battery profile not loaded\n");
		return -ENODEV;
	}

	fcc_mah = interpolate_single_row_lut(
				&the_battery->profile[table_index],
					batt_temp, DEGC_SCALE);
	fcc_mah = CAP(QG_MIN_FCC_MAH, QG_MAX_FCC_MAH, fcc_mah);

	*nom_cap_uah = fcc_mah * 1000;

	return 0;
}

int qg_batterydata_init(struct device_node *profile_node)
{
	int rc = 0;
+1 −0
Original line number Diff line number Diff line
@@ -15,5 +15,6 @@
int qg_batterydata_init(struct device_node *node);
void qg_batterydata_exit(void);
int lookup_soc_ocv(u32 *soc, u32 ocv_uv, int batt_temp, bool charging);
int qg_get_nominal_capacity(u32 *nom_cap_uah, int batt_temp, bool charging);

#endif /* __QG_BATTERY_PROFILE_H__ */
+13 −0
Original line number Diff line number Diff line
@@ -12,6 +12,9 @@
#ifndef __QG_CORE_H__
#define __QG_CORE_H__

#include <linux/kernel.h>
#include "fg-alg.h"

struct qg_batt_props {
	const char		*batt_type_str;
	int			float_volt_uv;
@@ -49,6 +52,8 @@ struct qg_dt {
	int			cold_temp_threshold;
	bool			hold_soc_while_full;
	bool			linearize_soc;
	bool			cl_disable;
	bool			cl_feedback_on;
};

struct qpnp_qg {
@@ -109,12 +114,19 @@ struct qpnp_qg {
	int			maint_soc;
	int			msoc;
	int			pon_soc;
	int			batt_soc;
	int			cc_soc;
	struct alarm		alarm_timer;
	u32			sdam_data[SDAM_MAX];

	/* DT */
	struct qg_dt		dt;
	struct qg_batt_props	bp;
	/* capacity learning */
	struct cap_learning	*cl;
	/* charge counter */
	struct cycle_counter	*counter;
	char			counter_buf[BUCKET_COUNT * 8];
};

enum ocv_type {
@@ -135,6 +147,7 @@ enum debug_mask {
	QG_DEBUG_PM		= BIT(7),
	QG_DEBUG_BUS_READ	= BIT(8),
	QG_DEBUG_BUS_WRITE	= BIT(9),
	QG_DEBUG_ALG_CL		= BIT(10),
};

enum qg_irq {
Loading