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

Commit 3dfe2eeb authored by Xiaozhe Shi's avatar Xiaozhe Shi Committed by Gerrit - the friendly Code Review server
Browse files

power: qpnp-smbcharger: qpnp-fg: change how fg status works



Currently the charger only reports charge full to the fuel gauge.
However, for other algorithms and workarounds, the fuel gauge needs to
know the full range of charging status from the charger driver.

Fix this by reporting all the status changes from the charger to the
fuel gauge.

CRs-Fixed: 771998
Change-Id: I69c80de8b30b9e332ea1b541f9a5e6f7daa45816
Signed-off-by: default avatarXiaozhe Shi <xiaozhes@codeaurora.org>
parent 36b1f2a9
Loading
Loading
Loading
Loading
+19 −2
Original line number Diff line number Diff line
@@ -283,6 +283,7 @@ struct fg_chip {
	struct mutex		rw_lock;
	struct work_struct	batt_profile_init;
	struct work_struct	dump_sram;
	struct work_struct	status_change_work;
	struct power_supply	*batt_psy;
	struct fg_wakeup_source	memif_wakeup_source;
	struct fg_wakeup_source	profile_wakeup_source;
@@ -305,6 +306,7 @@ struct fg_chip {
	const char		*batt_type;
	unsigned long		last_sram_update_time;
	unsigned long		last_temp_update_time;
	int			status;
};

/* FG_MEMIF DEBUGFS structures */
@@ -1449,6 +1451,18 @@ static int fg_power_get_property(struct power_supply *psy,
	return 0;
}

static void status_change_work(struct work_struct *work)
{
	struct fg_chip *chip = container_of(work,
				struct fg_chip,
				status_change_work);

	if ((chip->status == POWER_SUPPLY_STATUS_FULL ||
			chip->status == POWER_SUPPLY_STATUS_CHARGING)
			&& get_prop_capacity(chip) == 100)
		fg_configure_soc(chip);
}

static int fg_power_set_property(struct power_supply *psy,
				  enum power_supply_property psp,
				  const union power_supply_propval *val)
@@ -1468,8 +1482,8 @@ static int fg_power_set_property(struct power_supply *psy,
			update_sram_data(chip, &unused);
		break;
	case POWER_SUPPLY_PROP_STATUS:
		if (val->intval == POWER_SUPPLY_STATUS_FULL)
			rc = fg_configure_soc(chip);
		chip->status = val->intval;
		schedule_work(&chip->status_change_work);
		break;
	default:
		return -EINVAL;
@@ -2242,6 +2256,7 @@ static int fg_remove(struct spmi_device *spmi)
	cancel_delayed_work_sync(&chip->update_jeita_setting);
	cancel_work_sync(&chip->batt_profile_init);
	cancel_work_sync(&chip->dump_sram);
	cancel_work_sync(&chip->status_change_work);
	power_supply_unregister(&chip->bms_psy);
	mutex_destroy(&chip->rw_lock);
	wakeup_source_trash(&chip->memif_wakeup_source.source);
@@ -2849,6 +2864,7 @@ static int fg_probe(struct spmi_device *spmi)
	INIT_DELAYED_WORK(&chip->update_temp_work, update_temp_data);
	INIT_WORK(&chip->batt_profile_init, batt_profile_init);
	INIT_WORK(&chip->dump_sram, dump_sram);
	INIT_WORK(&chip->status_change_work, status_change_work);
	init_completion(&chip->sram_access_granted);
	init_completion(&chip->sram_access_revoked);
	init_completion(&chip->batt_id_avail);
@@ -2990,6 +3006,7 @@ cancel_work:
	cancel_delayed_work_sync(&chip->update_temp_work);
	cancel_work_sync(&chip->batt_profile_init);
	cancel_work_sync(&chip->dump_sram);
	cancel_work_sync(&chip->status_change_work);
of_init_fail:
	mutex_destroy(&chip->rw_lock);
	wakeup_source_trash(&chip->memif_wakeup_source.source);
+14 −41
Original line number Diff line number Diff line
@@ -203,7 +203,6 @@ struct smbchg_chip {
	struct smbchg_regulator		otg_vreg;
	struct smbchg_regulator		ext_otg_vreg;
	struct work_struct		usb_set_online_work;
	struct work_struct		batt_soc_work;
	struct delayed_work		vfloat_adjust_work;
	struct delayed_work		hvdcp_det_work;
	spinlock_t			sec_access_lock;
@@ -766,22 +765,6 @@ static int set_property_on_fg(struct smbchg_chip *chip,
	return rc;
}

static void smbchg_check_and_notify_fg_soc(struct smbchg_chip *chip)
{
	bool charger_present, charger_suspended;

	charger_present = is_usb_present(chip) | is_dc_present(chip);
	charger_suspended = chip->usb_suspended & chip->dc_suspended;

	if (charger_present && !charger_suspended
		&& get_prop_batt_status(chip)
			== POWER_SUPPLY_STATUS_CHARGING) {
		pr_smb(PR_STATUS, "Adjusting battery soc in FG\n");
		set_property_on_fg(chip, POWER_SUPPLY_PROP_STATUS,
				POWER_SUPPLY_STATUS_FULL);
	}
}

static int get_property_from_fg(struct smbchg_chip *chip,
		enum power_supply_property prop, int *val)
{
@@ -821,11 +804,6 @@ static int get_prop_batt_capacity(struct smbchg_chip *chip)
		pr_smb(PR_STATUS, "Couldn't get capacity rc = %d\n", rc);
		capacity = DEFAULT_BATT_CAPACITY;
	}
	if ((capacity == 100) && (get_prop_charge_type(chip)
					== POWER_SUPPLY_CHARGE_TYPE_TAPER
				|| get_prop_batt_status(chip)
					== POWER_SUPPLY_STATUS_FULL))
		smbchg_check_and_notify_fg_soc(chip);
	return capacity;
}

@@ -3301,19 +3279,11 @@ static int smbchg_charging_status_change(struct smbchg_chip *chip)
{
	smbchg_low_icl_wa_check(chip);
	smbchg_vfloat_adjust_check(chip);
	set_property_on_fg(chip, POWER_SUPPLY_PROP_STATUS,
			get_prop_batt_status(chip));
	return 0;
}

static void smbchg_adjust_batt_soc_work(struct work_struct *work)
{
	struct smbchg_chip *chip = container_of(work,
				struct smbchg_chip,
				batt_soc_work);

	if (get_prop_batt_capacity(chip) == 100)
		smbchg_check_and_notify_fg_soc(chip);
}

#define HOT_BAT_HARD_BIT	BIT(0)
#define HOT_BAT_SOFT_BIT	BIT(1)
#define COLD_BAT_HARD_BIT	BIT(2)
@@ -3330,10 +3300,10 @@ static irqreturn_t batt_hot_handler(int irq, void *_chip)
	smbchg_read(chip, &reg, chip->bat_if_base + RT_STS, 1);
	chip->batt_hot = !!(reg & HOT_BAT_HARD_BIT);
	pr_smb(PR_INTERRUPT, "triggered: 0x%02x\n", reg);
	smbchg_charging_status_change(chip);
	smbchg_parallel_usb_check_ok(chip);
	if (chip->psy_registered)
		power_supply_changed(&chip->batt_psy);
	smbchg_charging_status_change(chip);
	smbchg_wipower_check(chip);
	return IRQ_HANDLED;
}
@@ -3346,10 +3316,10 @@ static irqreturn_t batt_cold_handler(int irq, void *_chip)
	smbchg_read(chip, &reg, chip->bat_if_base + RT_STS, 1);
	chip->batt_cold = !!(reg & COLD_BAT_HARD_BIT);
	pr_smb(PR_INTERRUPT, "triggered: 0x%02x\n", reg);
	smbchg_charging_status_change(chip);
	smbchg_parallel_usb_check_ok(chip);
	if (chip->psy_registered)
		power_supply_changed(&chip->batt_psy);
	smbchg_charging_status_change(chip);
	smbchg_wipower_check(chip);
	return IRQ_HANDLED;
}
@@ -3392,6 +3362,7 @@ static irqreturn_t batt_pres_handler(int irq, void *_chip)
	pr_smb(PR_INTERRUPT, "triggered: 0x%02x\n", reg);
	if (chip->psy_registered)
		power_supply_changed(&chip->batt_psy);
	smbchg_charging_status_change(chip);
	return IRQ_HANDLED;
}

@@ -3406,11 +3377,10 @@ static irqreturn_t chg_error_handler(int irq, void *_chip)
	struct smbchg_chip *chip = _chip;

	pr_smb(PR_INTERRUPT, "chg-error triggered\n");
	smbchg_charging_status_change(chip);
	smbchg_parallel_usb_check_ok(chip);
	if (chip->psy_registered)
		power_supply_changed(&chip->batt_psy);

	smbchg_charging_status_change(chip);
	smbchg_wipower_check(chip);
	return IRQ_HANDLED;
}
@@ -3420,11 +3390,10 @@ static irqreturn_t fastchg_handler(int irq, void *_chip)
	struct smbchg_chip *chip = _chip;

	pr_smb(PR_INTERRUPT, "p2f triggered\n");
	smbchg_charging_status_change(chip);
	smbchg_parallel_usb_check_ok(chip);
	if (chip->psy_registered)
		power_supply_changed(&chip->batt_psy);

	smbchg_charging_status_change(chip);
	smbchg_wipower_check(chip);
	return IRQ_HANDLED;
}
@@ -3515,9 +3484,8 @@ static irqreturn_t chg_term_handler(int irq, void *_chip)
	smbchg_parallel_usb_check_ok(chip);
	if (chip->psy_registered)
		power_supply_changed(&chip->batt_psy);
	if (reg & BAT_TCC_REACHED_BIT)
		schedule_work(&chip->batt_soc_work);
	smbchg_aicl_deglitch_wa_check(chip);
	smbchg_charging_status_change(chip);
	return IRQ_HANDLED;
}

@@ -3531,6 +3499,9 @@ static irqreturn_t taper_handler(int irq, void *_chip)
	pr_smb(PR_INTERRUPT, "triggered: 0x%02x\n", reg);
	smbchg_aicl_deglitch_wa_check(chip);
	smbchg_parallel_usb_taper(chip);
	if (chip->psy_registered)
		power_supply_changed(&chip->batt_psy);
	smbchg_charging_status_change(chip);
	smbchg_wipower_check(chip);
	return IRQ_HANDLED;
}
@@ -3546,6 +3517,7 @@ static irqreturn_t recharge_handler(int irq, void *_chip)
	smbchg_parallel_usb_check_ok(chip);
	if (chip->psy_registered)
		power_supply_changed(&chip->batt_psy);
	smbchg_charging_status_change(chip);
	return IRQ_HANDLED;
}

@@ -3558,6 +3530,7 @@ static irqreturn_t safety_timeout_handler(int irq, void *_chip)
	pr_warn_ratelimited("safety timeout rt_stat = 0x%02x\n", reg);
	if (chip->psy_registered)
		power_supply_changed(&chip->batt_psy);
	smbchg_charging_status_change(chip);
	return IRQ_HANDLED;
}

@@ -3595,6 +3568,7 @@ static irqreturn_t dcin_uv_handler(int irq, void *_chip)
		chip->dc_present = dc_present;
		if (chip->psy_registered)
			power_supply_changed(&chip->dc_psy);
		smbchg_charging_status_change(chip);
	}

	smbchg_wipower_check(chip);
@@ -4930,7 +4904,6 @@ static int smbchg_probe(struct spmi_device *spmi)
	}

	INIT_WORK(&chip->usb_set_online_work, smbchg_usb_update_online_work);
	INIT_WORK(&chip->batt_soc_work, smbchg_adjust_batt_soc_work);
	INIT_DELAYED_WORK(&chip->parallel_en_work,
			smbchg_parallel_usb_en_work);
	INIT_DELAYED_WORK(&chip->vfloat_adjust_work, smbchg_vfloat_adjust_work);