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

Commit 49fdb1ee 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-smbcharger: Add support to configure FCC and FV compensation"

parents d6d08f3a b7000bd4
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -112,6 +112,12 @@ Optional Properties:
- qcom,float-voltage-mv		Float Voltage in mV - the maximum voltage up
				to which the battery is charged. Supported
				range 3600mV to 4500mV
- qcom,float-voltage-comp	Specifies the JEITA float voltage compensation.
				Value ranges from 0 to 63.
- qcom,fastchg-current-ma	Specifies the fast charge current in mA. Supported
				range is from 300mA to 3000mA.
- qcom,fastchg-current-comp	Specifies the fast charge current compensation in
				mA. Supported values are 250, 700, 900 and 1200mA.
- qcom,charging-timeout-mins	Maximum duration in minutes that a single
				charge cycle may last.  Supported values are:
				0, 192, 384, 768, and 1536.  A value of 0
+85 −3
Original line number Diff line number Diff line
@@ -95,6 +95,8 @@ struct smbchg_chip {
	int				target_fastchg_current_ma;
	int				fastchg_current_ma;
	int				vfloat_mv;
	int				fastchg_current_comp;
	int				float_voltage_comp;
	int				resume_delta_mv;
	int				safety_time;
	int				prechg_safety_time;
@@ -882,7 +884,7 @@ static int get_prop_batt_health(struct smbchg_chip *chip)
		return POWER_SUPPLY_HEALTH_GOOD;
}

int usb_current_table[] = {
static const int usb_current_table[] = {
	300,
	400,
	450,
@@ -917,7 +919,7 @@ int usb_current_table[] = {
	3000
};

int dc_current_table[] = {
static const int dc_current_table[] = {
	300,
	400,
	450,
@@ -946,6 +948,13 @@ int dc_current_table[] = {
	2000,
};

static const int fcc_comp_table[] = {
	250,
	700,
	900,
	1200,
};

static int calc_thermal_limited_current(struct smbchg_chip *chip,
						int current_ma)
{
@@ -2174,6 +2183,49 @@ static int smbchg_calc_max_flash_current(struct smbchg_chip *chip)
	return (int)total_flash_ua;
}

#define FCC_CMP_CFG	0xF3
#define FCC_COMP_MASK	SMB_MASK(1, 0)
static int smbchg_fastchg_current_comp_set(struct smbchg_chip *chip,
					int comp_current)
{
	int rc;
	u8 i;

	for (i = 0; i < ARRAY_SIZE(fcc_comp_table); i++)
		if (comp_current == fcc_comp_table[i])
			break;

	if (i >= ARRAY_SIZE(fcc_comp_table))
		return -EINVAL;

	rc = smbchg_sec_masked_write(chip, chip->chgr_base + FCC_CMP_CFG,
			FCC_COMP_MASK, i);

	if (rc)
		dev_err(chip->dev, "Couldn't set fastchg current comp rc = %d\n",
			rc);

	return rc;
}

#define FV_CMP_CFG	0xF5
#define FV_COMP_MASK	SMB_MASK(5, 0)
static int smbchg_float_voltage_comp_set(struct smbchg_chip *chip, int code)
{
	int rc;
	u8 val;

	val = code & FV_COMP_MASK;
	rc = smbchg_sec_masked_write(chip, chip->chgr_base + FV_CMP_CFG,
			FV_COMP_MASK, val);

	if (rc)
		dev_err(chip->dev, "Couldn't set float voltage comp rc = %d\n",
			rc);

	return rc;
}

#define VFLOAT_CFG_REG			0xF4
#define MIN_FLOAT_MV			3600
#define MAX_FLOAT_MV			4500
@@ -3698,7 +3750,7 @@ static inline int get_bpd(const char *name)
#define PIN_SRC_SHIFT			0
#define CHGR_CFG			0xFF
#define RCHG_LVL_BIT			BIT(0)
#define CFG_AFVC			0xF5
#define CFG_AFVC			0xF6
#define VFLOAT_COMP_ENABLE_MASK		SMB_MASK(2, 0)
#define TR_RID_REG			0xFA
#define FG_INPUT_FET_DELAY_BIT		BIT(3)
@@ -3820,6 +3872,32 @@ static int smbchg_hw_init(struct smbchg_chip *chip)
		pr_smb(PR_STATUS, "set vfloat to %d\n", chip->vfloat_mv);
	}

	/* set the fast charge current compensation */
	if (chip->fastchg_current_comp != -EINVAL) {
		rc = smbchg_fastchg_current_comp_set(chip,
			chip->fastchg_current_comp);
		if (rc < 0) {
			dev_err(chip->dev, "Couldn't set fastchg current comp rc = %d\n",
				rc);
			return rc;
		}
		pr_smb(PR_STATUS, "set fastchg current comp to %d\n",
			chip->fastchg_current_comp);
	}

	/* set the float voltage compensation */
	if (chip->float_voltage_comp != -EINVAL) {
		rc = smbchg_float_voltage_comp_set(chip,
			chip->float_voltage_comp);
		if (rc < 0) {
			dev_err(chip->dev, "Couldn't set float voltage comp rc = %d\n",
				rc);
			return rc;
		}
		pr_smb(PR_STATUS, "set float voltage comp to %d\n",
			chip->float_voltage_comp);
	}

	/* set iterm */
	if (chip->iterm_ma != -EINVAL) {
		if (chip->iterm_disabled) {
@@ -4154,6 +4232,10 @@ static int smb_parse_dt(struct smbchg_chip *chip)
	OF_PROP_READ(chip, chip->rpara_uohm, "rparasitic-uohm", rc, 1);
	OF_PROP_READ(chip, chip->prechg_safety_time, "precharging-timeout-mins",
			rc, 1);
	OF_PROP_READ(chip, chip->fastchg_current_comp, "fastchg-current-comp",
			rc, 1);
	OF_PROP_READ(chip, chip->float_voltage_comp, "float-voltage-comp",
			rc, 1);
	if (chip->safety_time != -EINVAL &&
		(chip->safety_time > chg_time[ARRAY_SIZE(chg_time) - 1])) {
		dev_err(chip->dev, "Bad charging-timeout-mins %d\n",