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

Commit 8e4bdbc6 authored by Ashay Jaiswal's avatar Ashay Jaiswal
Browse files

power: smb135x-charger: Add support to disable charger-inhibit feature



The charger inhibit option prevents battery charging upon insertion of
charger when battery voltage is above the programmed inhibit threshold.

Disable charger-inhibit based on device-tree flag to always enable
charging on charger insertion.

CRs-Fixed: 703710
Change-Id: Ib09b5afbdc3f538c3d4c51db75ad6d2ce6dbaa86
Signed-off-by: default avatarAshay Jaiswal <ashayj@codeaurora.org>
parent d5fc7ff6
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -55,6 +55,7 @@ Optional Properties:
					charging. In this case the input current from USB is split
					between a main charger and smb135x for reducing thermal impact
					of high current charging from USB path.
- qcom,inhibit-disabled:	Disables the charger-inhibit function.

Example:
	i2c@f9967000 {
+47 −26
Original line number Diff line number Diff line
@@ -326,6 +326,7 @@ struct smb135x_chg {
	int				*usb_current_table;
	int				dc_current_arr_size;
	int				*dc_current_table;
	bool				inhibit_disabled;
	u8				irq_cfg_mask[3];
	int				otg_oc_count;

@@ -1461,6 +1462,7 @@ static int smb135x_set_resume_threshold(struct smb135x_chg *chip,
	int rc;
	u8 reg;

	if (!chip->inhibit_disabled) {
		if (resume_delta_mv < 100)
			reg = CHG_INHIBIT_50MV_VAL;
		else if (resume_delta_mv < 200)
@@ -1470,11 +1472,14 @@ static int smb135x_set_resume_threshold(struct smb135x_chg *chip,
		else
			reg = CHG_INHIBIT_300MV_VAL;

	rc = smb135x_masked_write(chip, CFG_4_REG, CHG_INHIBIT_MASK, reg);
		rc = smb135x_masked_write(chip, CFG_4_REG, CHG_INHIBIT_MASK,
						reg);
		if (rc < 0) {
		dev_err(chip->dev, "Couldn't set inhibit val rc = %d\n", rc);
			dev_err(chip->dev, "Couldn't set inhibit val rc = %d\n",
						rc);
			return rc;
		}
	}

	if (resume_delta_mv < 200)
		reg = 0;
@@ -2834,7 +2839,7 @@ DEFINE_SIMPLE_ATTRIBUTE(force_irq_ops, NULL, force_irq_set, "0x%02llx\n");

static int force_rechg_set(void *data, u64 val)
{
	int rc;
	int rc = 0;
	struct smb135x_chg *chip = data;

	if (!chip->chg_enabled) {
@@ -2842,19 +2847,27 @@ static int force_rechg_set(void *data, u64 val)
		return -EINVAL;
	}

	rc = smb135x_masked_write(chip, CFG_14_REG, EN_CHG_INHIBIT_BIT, 0);
	if (!chip->inhibit_disabled) {
		rc = smb135x_masked_write(chip, CFG_14_REG, EN_CHG_INHIBIT_BIT,
					0);
		if (rc)
			dev_err(chip->dev,
				"Couldn't disable charge-inhibit rc=%d\n", rc);

		/* delay for charge-inhibit to take affect */
		msleep(500);
	}

	rc |= smb135x_charging(chip, false);
	rc |= smb135x_charging(chip, true);
	rc |= smb135x_masked_write(chip, CFG_14_REG, EN_CHG_INHIBIT_BIT,
						EN_CHG_INHIBIT_BIT);

	if (!chip->inhibit_disabled) {
		rc |= smb135x_masked_write(chip, CFG_14_REG,
				EN_CHG_INHIBIT_BIT, EN_CHG_INHIBIT_BIT);
		if (rc)
			dev_err(chip->dev,
				"Couldn't enable charge-inhibit rc=%d\n", rc);
	}

	return rc;
}
@@ -3039,12 +3052,17 @@ static int smb135x_hw_init(struct smb135x_chg *chip)
	/*
	 * set chg en by cmd register, set chg en by writing bit 1,
	 * enable auto pre to fast, enable current termination, enable
	 * auto recharge, enable chg inhibition
	 * auto recharge, enable chg inhibition based on the dt flag
	 */
	if (chip->inhibit_disabled)
		reg = 0;
	else
		reg = EN_CHG_INHIBIT_BIT;

	rc = smb135x_masked_write(chip, CFG_14_REG,
			CHG_EN_BY_PIN_BIT | CHG_EN_ACTIVE_LOW_BIT
			| PRE_TO_FAST_REQ_CMD_BIT | DISABLE_AUTO_RECHARGE_BIT
			| EN_CHG_INHIBIT_BIT, EN_CHG_INHIBIT_BIT);
			| EN_CHG_INHIBIT_BIT, reg);
	if (rc < 0) {
		dev_err(chip->dev, "Couldn't set cfg 14 rc=%d\n", rc);
		return rc;
@@ -3338,6 +3356,9 @@ static int smb_parse_dt(struct smb135x_chg *chip)
						"qcom,charging-disabled"));
	chip->chg_enabled = !chip->chg_disabled_permanently;

	chip->inhibit_disabled  = of_property_read_bool(node,
						"qcom,inhibit-disabled");

	rc = of_property_read_string(node, "qcom,bms-psy-name",
						&chip->bms_psy_name);
	if (rc)