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

Commit 7bb9de33 authored by Chunmei Cai's avatar Chunmei Cai
Browse files

power: qpnp-smbcharger/fg: Keep BCL above LPM when CHG_LED is on



If charger going to sleep mode, the CHG_LED will be turned off. Keeping
BCL above LPM when CHG_LED is on to keep the charger in standby mode to
avoid messing up the CHG_LED behavior.

CRs-Fixed:951801
Change-Id: Ib9566f69d4cf70181f6ec8f3861be7d2f8e0cf00
Signed-off-by: default avatarChunmei Cai <ccai@codeaurora.org>
parent d70d0441
Loading
Loading
Loading
Loading
+60 −1
Original line number Diff line number Diff line
@@ -111,7 +111,8 @@ enum pmic_subtype {
enum wa_flags {
	IADC_GAIN_COMP_WA = BIT(0),
	USE_CC_SOC_REG = BIT(1),
	PULSE_REQUEST_WA = BIT(2)
	PULSE_REQUEST_WA = BIT(2),
	BCL_HI_POWER_FOR_CHGLED_WA = BIT(3)
};

enum current_sense_type {
@@ -429,6 +430,7 @@ struct fg_chip {
	struct work_struct	init_work;
	struct work_struct	charge_full_work;
	struct work_struct	gain_comp_work;
	struct work_struct	bcl_hi_power_work;
	struct power_supply	*batt_psy;
	struct power_supply	*usb_psy;
	struct power_supply	*dc_psy;
@@ -459,6 +461,7 @@ struct fg_chip {
	bool			otg_present;
	bool			safety_timer_expired;
	bool			bad_batt_detection_en;
	bool			bcl_lpm_disabled;
	struct delayed_work	update_jeita_setting;
	struct delayed_work	update_sram_data;
	struct delayed_work	update_temp_work;
@@ -2617,6 +2620,7 @@ static enum power_supply_property fg_power_props[] = {
	POWER_SUPPLY_PROP_VOLTAGE_MIN,
	POWER_SUPPLY_PROP_CYCLE_COUNT,
	POWER_SUPPLY_PROP_CYCLE_COUNT_ID,
	POWER_SUPPLY_PROP_HI_POWER,
};

static int fg_power_get_property(struct power_supply *psy,
@@ -3567,6 +3571,12 @@ static int fg_power_set_property(struct power_supply *psy,
		chip->safety_timer_expired = val->intval;
		schedule_work(&chip->status_change_work);
		break;
	case POWER_SUPPLY_PROP_HI_POWER:
		if (chip->wa_flag & BCL_HI_POWER_FOR_CHGLED_WA) {
			chip->bcl_lpm_disabled = !!val->intval;
			schedule_work(&chip->bcl_hi_power_work);
		}
		break;
	default:
		return -EINVAL;
	};
@@ -4937,6 +4947,52 @@ static void update_bcl_thresholds(struct fg_chip *chip)
			data[lm_offset], data[mh_offset]);
}

static int disable_bcl_lpm(struct fg_chip *chip)
{
	u8 data[4];
	u8 lm_offset = 0;
	u16 address = 0;
	int rc = 0;

	address = settings[FG_MEM_BCL_LM_THRESHOLD].address;
	lm_offset = settings[FG_MEM_BCL_LM_THRESHOLD].offset;
	rc = fg_mem_read(chip, data, address, 4, 0, 1);
	if (rc) {
		pr_err("Error reading BCL LM & MH threshold rc:%d\n", rc);
		return rc;
	}
	pr_debug("Old BCL LM threshold:%x\n", data[lm_offset]);

	/* Put BCL always above LPM */
	BCL_MA_TO_ADC(0, data[lm_offset]);

	rc = fg_mem_write(chip, data, address, 4, 0, 0);
	if (rc)
		pr_err("spmi write failed. addr:%03x, rc:%d\n",
			address, rc);
	else
		pr_debug("New BCL LM threshold:%x\n", data[lm_offset]);

	return rc;
}

static void bcl_hi_power_work(struct work_struct *work)
{
	struct fg_chip *chip = container_of(work,
			struct fg_chip,
			bcl_hi_power_work);
	int rc;

	if (chip->bcl_lpm_disabled) {
		rc = disable_bcl_lpm(chip);
		if (rc)
			pr_err("failed to disable bcl low mode %d\n",
					rc);
	} else {
		update_bcl_thresholds(chip);
	}
}

#define VOLT_UV_TO_VOLTCMP8(volt_uv)	\
			((volt_uv - 2500000) / 9766)
static int update_irq_volt_empty(struct fg_chip *chip)
@@ -6050,6 +6106,7 @@ static int fg_hw_init(struct fg_chip *chip)
	case PMI8937:
		rc = fg_8950_hw_init(chip);
		/* Setup workaround flag based on PMIC type */
		chip->wa_flag |= BCL_HI_POWER_FOR_CHGLED_WA;
		if (fg_sense_type == INTERNAL_CURRENT_SENSE)
			chip->wa_flag |= IADC_GAIN_COMP_WA;
		if (chip->pmic_revision[REVID_DIG_MAJOR] > 1)
@@ -6317,6 +6374,7 @@ static int fg_probe(struct spmi_device *spmi)
	INIT_WORK(&chip->init_work, delayed_init_work);
	INIT_WORK(&chip->charge_full_work, charge_full_work);
	INIT_WORK(&chip->gain_comp_work, iadc_gain_comp_work);
	INIT_WORK(&chip->bcl_hi_power_work, bcl_hi_power_work);
	alarm_init(&chip->fg_cap_learning_alarm, ALARM_BOOTTIME,
			fg_cap_learning_alarm_cb);
	init_completion(&chip->sram_access_granted);
@@ -6484,6 +6542,7 @@ cancel_work:
	cancel_work_sync(&chip->gain_comp_work);
	cancel_work_sync(&chip->init_work);
	cancel_work_sync(&chip->charge_full_work);
	cancel_work_sync(&chip->bcl_hi_power_work);
of_init_fail:
	mutex_destroy(&chip->rslow_comp.lock);
	mutex_destroy(&chip->rw_lock);
+16 −7
Original line number Diff line number Diff line
@@ -3811,6 +3811,11 @@ static void smbchg_chg_led_brightness_set(struct led_classdev *cdev,
	reg = (value > LED_OFF) ? CHG_LED_ON << CHG_LED_SHIFT :
		CHG_LED_OFF << CHG_LED_SHIFT;

	if (value > LED_OFF)
		power_supply_set_hi_power_state(chip->bms_psy, 1);
	else
		power_supply_set_hi_power_state(chip->bms_psy, 0);

	pr_smb(PR_STATUS,
			"set the charger led brightness to value=%d\n",
			value);
@@ -3852,14 +3857,18 @@ static void smbchg_chg_led_blink_set(struct smbchg_chip *chip,
	u8 reg;
	int rc;

	if (blinking == 0)
	if (blinking == 0) {
		reg = CHG_LED_OFF << CHG_LED_SHIFT;
	else if (blinking == 1)
		power_supply_set_hi_power_state(chip->bms_psy, 0);
	} else {
		power_supply_set_hi_power_state(chip->bms_psy, 1);
		if (blinking == 1)
			reg = LED_BLINKING_PATTERN1 << CHG_LED_SHIFT;
		else if (blinking == 2)
			reg = LED_BLINKING_PATTERN2 << CHG_LED_SHIFT;
		else
			reg = LED_BLINKING_PATTERN1 << CHG_LED_SHIFT;
	}

	rc = smbchg_sec_masked_write(chip,
			chip->bat_if_base + CMD_CHG_LED_REG,