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

Commit 685351ad authored by Anirudh Ghayal's avatar Anirudh Ghayal Committed by Gerrit - the friendly Code Review server
Browse files

power: qpnp-qg: Update the QPNP QG driver from 4.9 kernel



This implementation is based on snapshot of msm-4.9
commit 42e1de365776 ("ARM: dts: msm: Enable the
dpdm-supply node for MSM8917/37").

Change-Id: I61c6a21f8e5a47b02387a1dfbeeed4bb821da139
Signed-off-by: default avatarAnirudh Ghayal <aghayal@codeaurora.org>
parent a7d75039
Loading
Loading
Loading
Loading
+39 −0
Original line number Diff line number Diff line
@@ -262,6 +262,45 @@ First Level Node - QGAUGE device
		    capacity learning cycle. If this is not specified, then
		    the default value is 0. Unit is in decipercentage.

- qcom,esr-disable
	Usage:      optional
	Value type: <bool>
	Definition: Boolean property to disable ESR estimation. If not defined
		    ESR estimation stays enabled for charge-cycles.

- qcom,esr-discharge-enable
	Usage:      optional
	Value type: <bool>
	Definition: Boolean property to enable ESR estimation during discharge.
		    Only valid if 'qcom,esr-disable' is not defined.

- qcom,esr-qual-current-ua
	Usage:      optional
	Value type: <u32>
	Definition: Minimum current differential in uA to qualify an ESR
		    reading as valid. If not defined the value defaults
		    to 130mA.

- qcom,esr-qual-vbatt-uv
	Usage:      optional
	Value type: <u32>
	Definition: Minimum vbatt differential in uV to qualify an ESR
		    reading as valid. If not defined the value defaults
		    to 7mV.

- qcom,esr-disable-soc
	Usage:      optional
	Value type: <u32>
	Definition: Minimum battery SOC below which ESR will not be
		    attempted by QG. If not defined the value defaults
		    to 10%.

- qcom,qg-ext-sns
	Usage:      optional
	Value type: <bool>
	Definition: Boolean property to support external-rsense based
		    configuration.

==========================================================
Second Level Nodes - Peripherals managed by QGAUGE driver
==========================================================
+2 −6
Original line number Diff line number Diff line
@@ -398,10 +398,8 @@ int lookup_soc_ocv(u32 *soc, u32 ocv_uv, int batt_temp, bool charging)
{
	u8 table_index = charging ? TABLE_SOC_OCV1 : TABLE_SOC_OCV2;

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

	*soc = interpolate_soc(&the_battery->profile[table_index],
				batt_temp, UV_TO_DECIUV(ocv_uv));
@@ -416,10 +414,8 @@ 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_node) {
		pr_err("Battery profile not loaded\n");
	if (!the_battery || !the_battery->profile_node)
		return -ENODEV;
	}

	fcc_mah = interpolate_single_row_lut(
				&the_battery->profile[table_index],
+36 −0
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@

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

struct qg_batt_props {
	const char		*batt_type_str;
@@ -50,10 +51,25 @@ struct qg_dt {
	int			rbat_conn_mohm;
	int			ignore_shutdown_soc_secs;
	int			cold_temp_threshold;
	int			esr_qual_i_ua;
	int			esr_qual_v_uv;
	int			esr_disable_soc;
	bool			hold_soc_while_full;
	bool			linearize_soc;
	bool			cl_disable;
	bool			cl_feedback_on;
	bool			esr_disable;
	bool			esr_discharge_enable;
	bool			qg_ext_sense;
};

struct qg_esr_data {
	u32			pre_esr_v;
	u32			pre_esr_i;
	u32			post_esr_v;
	u32			post_esr_i;
	u32			esr;
	bool			valid;
};

struct qpnp_qg {
@@ -87,6 +103,7 @@ struct qpnp_qg {
	struct power_supply	*batt_psy;
	struct power_supply	*usb_psy;
	struct power_supply	*parallel_psy;
	struct qg_esr_data	esr_data[QG_MAX_ESR_COUNT];

	/* status variable */
	u32			*debug_mask;
@@ -102,10 +119,18 @@ struct qpnp_qg {
	bool			charge_full;
	int			charge_status;
	int			charge_type;
	int			chg_iterm_ma;
	int			next_wakeup_ms;
	int			esr_actual;
	int			esr_nominal;
	int			soh;
	int			soc_reporting_ready;
	u32			fifo_done_count;
	u32			wa_flags;
	u32			seq_no;
	u32			charge_counter_uah;
	u32			esr_avg;
	u32			esr_last;
	ktime_t			last_user_update_time;
	ktime_t			last_fifo_update_time;
	struct iio_channel	*batt_therm_chan;
@@ -118,6 +143,7 @@ struct qpnp_qg {
	int			pon_soc;
	int			batt_soc;
	int			cc_soc;
	int			full_soc;
	struct alarm		alarm_timer;
	u32			sdam_data[SDAM_MAX];

@@ -128,6 +154,14 @@ struct qpnp_qg {
	struct cap_learning	*cl;
	/* charge counter */
	struct cycle_counter	*counter;
	/* ttf */
	struct ttf		*ttf;
};

struct ocv_all {
	u32 ocv_uv;
	u32 ocv_raw;
	char ocv_type[20];
};

enum ocv_type {
@@ -135,6 +169,7 @@ enum ocv_type {
	S3_GOOD_OCV,
	S3_LAST_OCV,
	SDAM_PON_OCV,
	PON_OCV_MAX,
};

enum debug_mask {
@@ -149,6 +184,7 @@ enum debug_mask {
	QG_DEBUG_BUS_READ	= BIT(8),
	QG_DEBUG_BUS_WRITE	= BIT(9),
	QG_DEBUG_ALG_CL		= BIT(10),
	QG_DEBUG_ESR		= BIT(11),
};

enum qg_irq {
+4 −0
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@
#define GOOD_OCV_VOTER			"GOOD_OCV_VOTER"
#define PROFILE_IRQ_DISABLE		"NO_PROFILE_IRQ_DISABLE"
#define QG_INIT_STATE_IRQ_DISABLE	"QG_INIT_STATE_IRQ_DISABLE"
#define TTF_AWAKE_VOTER			"TTF_AWAKE_VOTER"

#define V_RAW_TO_UV(V_RAW)		div_u64(194637ULL * (u64)V_RAW, 1000)
#define I_RAW_TO_UA(I_RAW)		div_s64(152588LL * (s64)I_RAW, 1000)
@@ -44,6 +45,9 @@
#define UV_TO_DECIUV(a)			(a / 100)
#define DECIUV_TO_UV(a)			(a * 100)

#define QG_MAX_ESR_COUNT		10
#define QG_MIN_ESR_COUNT		2

#define CAP(min, max, value)			\
		((min > value) ? min : ((value > max) ? max : value))

+37 −10
Original line number Diff line number Diff line
@@ -17,7 +17,9 @@
#define QG_TYPE					0x0D

#define QG_STATUS1_REG				0x08
#define QG_OK_BIT				BIT(7)
#define BATTERY_PRESENT_BIT			BIT(0)
#define ESR_MEAS_DONE_BIT			BIT(4)

#define QG_STATUS2_REG				0x09
#define GOOD_OCV_BIT				BIT(1)
@@ -25,9 +27,13 @@
#define QG_STATUS3_REG				0x0A
#define COUNT_FIFO_RT_MASK			GENMASK(3, 0)

#define QG_STATUS4_REG				0x0B
#define ESR_MEAS_IN_PROGRESS_BIT		BIT(4)

#define QG_INT_RT_STS_REG			0x10
#define FIFO_UPDATE_DONE_RT_STS_BIT		BIT(3)
#define VBAT_LOW_INT_RT_STS_BIT			BIT(1)
#define BATTERY_MISSING_INT_RT_STS_BIT		BIT(0)

#define QG_INT_LATCHED_STS_REG			0x18
#define FIFO_UPDATE_DONE_INT_LAT_STS_BIT	BIT(3)
@@ -60,11 +66,25 @@
#define QG_S3_ENTRY_IBAT_THRESHOLD_REG		0x5E
#define QG_S3_EXIT_IBAT_THRESHOLD_REG		0x5F

#define QG_S5_OCV_VALIDATE_MEAS_CTL1_REG	0x60
#define ALLOW_S5_BIT				BIT(7)

#define QG_S7_PON_OCV_MEAS_CTL1_REG		0x64
#define ADC_CONV_DLY_MASK			GENMASK(3, 0)

#define QG_ESR_MEAS_TRIG_REG			0x68
#define HW_ESR_MEAS_START_BIT			BIT(0)

#define QG_S7_PON_OCV_V_DATA0_REG		0x70
#define QG_S7_PON_OCV_I_DATA0_REG		0x72
#define QG_S3_GOOD_OCV_V_DATA0_REG		0x74
#define QG_S3_GOOD_OCV_I_DATA0_REG		0x76

#define QG_PRE_ESR_V_DATA0_REG			0x78
#define QG_PRE_ESR_I_DATA0_REG			0x7A
#define QG_POST_ESR_V_DATA0_REG			0x7C
#define QG_POST_ESR_I_DATA0_REG			0x7E

#define QG_V_ACCUM_DATA0_RT_REG			0x88
#define QG_I_ACCUM_DATA0_RT_REG			0x8B
#define QG_ACCUM_CNT_RT_REG			0x8E
@@ -80,15 +100,22 @@
#define QG_LAST_S3_SLEEP_V_DATA0_REG		0xCC

/* SDAM offsets */
#define QG_SDAM_VALID_OFFSET			0x46
#define QG_SDAM_SOC_OFFSET			0x47
#define QG_SDAM_TEMP_OFFSET			0x48
#define QG_SDAM_RBAT_OFFSET			0x4A
#define QG_SDAM_OCV_OFFSET			0x4C
#define QG_SDAM_IBAT_OFFSET			0x50
#define QG_SDAM_TIME_OFFSET			0x54
#define QG_SDAM_CYCLE_COUNT_OFFSET		0x58
#define QG_SDAM_LEARNED_CAPACITY_OFFSET		0x68
#define QG_SDAM_PON_OCV_OFFSET			0x7C
#define QG_SDAM_VALID_OFFSET			0x46 /* 1-byte 0x46 */
#define QG_SDAM_SOC_OFFSET			0x47 /* 1-byte 0x47 */
#define QG_SDAM_TEMP_OFFSET			0x48 /* 2-byte 0x48-0x49 */
#define QG_SDAM_RBAT_OFFSET			0x4A /* 2-byte 0x4A-0x4B */
#define QG_SDAM_OCV_OFFSET			0x4C /* 4-byte 0x4C-0x4F */
#define QG_SDAM_IBAT_OFFSET			0x50 /* 4-byte 0x50-0x53 */
#define QG_SDAM_TIME_OFFSET			0x54 /* 4-byte 0x54-0x57 */
#define QG_SDAM_CYCLE_COUNT_OFFSET		0x58 /* 16-byte 0x58-0x67 */
#define QG_SDAM_LEARNED_CAPACITY_OFFSET		0x68 /* 2-byte 0x68-0x69 */
#define QG_SDAM_ESR_CHARGE_DELTA_OFFSET		0x6A /* 4-byte 0x6A-0x6D */
#define QG_SDAM_ESR_DISCHARGE_DELTA_OFFSET	0x6E /* 4-byte 0x6E-0x71 */
#define QG_SDAM_ESR_CHARGE_SF_OFFSET		0x72 /* 2-byte 0x72-0x73 */
#define QG_SDAM_ESR_DISCHARGE_SF_OFFSET		0x74 /* 2-byte 0x74-0x75 */
#define QG_SDAM_MAX_OFFSET			0xA4

/* Below offset is used by PBS */
#define QG_SDAM_PON_OCV_OFFSET			0xBC /* 2-byte 0xBC-0xBD */

#endif
Loading