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

Commit 2b1e1d83 authored by Xiaozhe Shi's avatar Xiaozhe Shi
Browse files

power: qpnp-smbcharger: fix charging enable



Currently, the charger driver does not check whether or not the
charge_enable command bit is set during its initialization. If charging
was disabled in the bootloader, then charging may not start at all
after it boots into Linux.

Fix this by always enabling charging during smbchg_hw_init().

Furthermore, change the confusing CHG_EN_COMMAND_BIT define to
CHG_EN_POLARITY_BIT so that it accurately reflects that the bit controls
the charge enable polarity.

Finally, remove an old workaround that makes smbchg_hw_init() sleep for
20ms when waiting for charging to start/stop.

CRs-Fixed: 867782
Change-Id: Iee555dc1e8af3a6e00681e81f2398ebd820cbc40
Signed-off-by: default avatarXiaozhe Shi <xiaozhes@codeaurora.org>
parent 630fdcc6
Loading
Loading
Loading
Loading
+14 −10
Original line number Diff line number Diff line
@@ -733,7 +733,6 @@ static void read_usb_type(struct smbchg_chip *chip, char **usb_type_name,
#define BATT_PRE_CHG_VAL		0x1
#define BATT_FAST_CHG_VAL		0x2
#define BATT_TAPER_CHG_VAL		0x3
#define CHG_EN_BIT			BIT(0)
#define CHG_INHIBIT_BIT			BIT(1)
#define BAT_TCC_REACHED_BIT		BIT(7)
static int get_prop_batt_status(struct smbchg_chip *chip)
@@ -5556,7 +5555,7 @@ static inline int get_bpd(const char *name)
#define CHG_INHIBIT_MASK		0x03
#define USE_REGISTER_FOR_CURRENT	BIT(2)
#define CHG_EN_SRC_BIT			BIT(7)
#define CHG_EN_COMMAND_BIT		BIT(6)
#define CHG_EN_POLARITY_BIT		BIT(6)
#define P2F_CHG_TRAN			BIT(5)
#define I_TERM_BIT			BIT(3)
#define AUTO_RECHG_BIT			BIT(2)
@@ -5686,15 +5685,25 @@ static int smbchg_hw_init(struct smbchg_chip *chip)
	 * the device tree configuration.
	 */
	rc = smbchg_sec_masked_write(chip, chip->chgr_base + CHGR_CFG2,
			CHG_EN_SRC_BIT | CHG_EN_COMMAND_BIT | P2F_CHG_TRAN
			CHG_EN_SRC_BIT | CHG_EN_POLARITY_BIT | P2F_CHG_TRAN
			| I_TERM_BIT | AUTO_RECHG_BIT | CHARGER_INHIBIT_BIT,
			CHG_EN_COMMAND_BIT
			CHG_EN_POLARITY_BIT
			| (chip->chg_inhibit_en ? CHARGER_INHIBIT_BIT : 0)
			| (chip->iterm_disabled ? I_TERM_BIT : 0));
	if (rc < 0) {
		dev_err(chip->dev, "Couldn't set chgr_cfg2 rc=%d\n", rc);
		return rc;
	}

	/*
	 * enable battery charging to make sure it hasn't been changed earlier
	 * by the bootloader.
	 */
	rc = smbchg_charging_en(chip, true);
	if (rc < 0) {
		dev_err(chip->dev, "Couldn't enable battery charging=%d\n", rc);
		return rc;
	}
	chip->battchg_disabled = 0;

	/*
@@ -5882,11 +5891,6 @@ static int smbchg_hw_init(struct smbchg_chip *chip)

	smbchg_charging_status_change(chip);

	/*
	 * The charger needs 20 milliseconds to go into battery supplementary
	 * mode. Sleep here until we are sure it takes into effect.
	 */
	msleep(20);
	smbchg_usb_en(chip, chip->chg_enabled, REASON_USER);
	smbchg_dc_en(chip, chip->chg_enabled, REASON_USER);
	/* resume threshold */