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

Commit 2246f88e 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: skip usb psy input current unless SDP"

parents 5f6931d1 1df95494
Loading
Loading
Loading
Loading
+45 −12
Original line number Diff line number Diff line
@@ -1166,6 +1166,7 @@ static void smbchg_usb_update_online_work(struct work_struct *work)

	mutex_lock(&chip->usb_set_online_lock);
	if (chip->usb_online != online) {
		pr_smb(PR_MISC, "setting usb psy online = %d\n", online);
		power_supply_set_online(chip->usb_psy, online);
		chip->usb_online = online;
	}
@@ -1494,8 +1495,8 @@ static int smbchg_set_usb_current_max(struct smbchg_chip *chip,
	}

out:
	pr_smb(PR_STATUS, "usb current set to %d mA\n",
			chip->usb_max_current_ma);
	pr_smb(PR_STATUS, "usb type = %s current set to %d mA\n",
			usb_type_name, chip->usb_max_current_ma);
	return rc;
}

@@ -3090,6 +3091,8 @@ static void smbchg_external_power_changed(struct power_supply *psy)
				struct smbchg_chip, batt_psy);
	union power_supply_propval prop = {0,};
	int rc, current_limit = 0, soc;
	enum power_supply_type usb_supply_type;
	char *usb_type_name = "null";

	if (chip->bms_psy_name)
		chip->bms_psy =
@@ -3113,21 +3116,20 @@ static void smbchg_external_power_changed(struct power_supply *psy)

	rc = chip->usb_psy->get_property(chip->usb_psy,
				POWER_SUPPLY_PROP_CHARGING_ENABLED, &prop);
	if (rc < 0)
		pr_smb(PR_MISC, "could not read USB charge_en, rc=%d\n",
				rc);
	else
	if (rc == 0)
		smbchg_usb_en(chip, prop.intval, REASON_POWER_SUPPLY);

	rc = chip->usb_psy->get_property(chip->usb_psy,
				POWER_SUPPLY_PROP_CURRENT_MAX, &prop);
	if (rc < 0)
		dev_err(chip->dev,
			"could not read USB current_max property, rc=%d\n", rc);
	else
	if (rc != 0)
		current_limit = prop.intval / 1000;

	pr_smb(PR_MISC, "current_limit = %d\n", current_limit);
	read_usb_type(chip, &usb_type_name, &usb_supply_type);
	if (usb_supply_type != POWER_SUPPLY_TYPE_USB)
		goto  skip_current_for_non_sdp;

	pr_smb(PR_MISC, "usb type = %s current_limit = %d\n",
			usb_type_name, current_limit);
	mutex_lock(&chip->current_change_lock);
	if (current_limit != chip->usb_target_current_ma) {
		pr_smb(PR_STATUS, "changed current_limit = %d\n",
@@ -3141,6 +3143,7 @@ static void smbchg_external_power_changed(struct power_supply *psy)
	}
	mutex_unlock(&chip->current_change_lock);

skip_current_for_non_sdp:
	smbchg_vfloat_adjust_check(chip);

	power_supply_changed(&chip->batt_psy);
@@ -3850,6 +3853,7 @@ static void handle_usb_removal(struct smbchg_chip *chip)
		power_supply_set_dp_dm(chip->usb_psy,
				POWER_SUPPLY_DP_DM_DPR_DMR);
		schedule_work(&chip->usb_set_online_work);
		pr_smb(PR_MISC, "setting usb psy health UNKNOWN\n");
		rc = power_supply_set_health_state(chip->usb_psy,
				POWER_SUPPLY_HEALTH_UNKNOWN);
		if (rc)
@@ -3886,6 +3890,9 @@ static bool is_src_detect_high(struct smbchg_chip *chip)
}

#define HVDCP_NOTIFY_MS		2500
#define DEFAULT_WALL_CHG_MA	1800
#define DEFAULT_SDP_MA		100
#define DEFAULT_CDP_MA		1500
static void handle_usb_insertion(struct smbchg_chip *chip)
{
	struct power_supply *parallel_psy = get_parallel_psy(chip);
@@ -3914,6 +3921,9 @@ static void handle_usb_insertion(struct smbchg_chip *chip)
			 * if the handle_usb_insertion was triggered from
			 * the falling edge of an USBIN_OV interrupt
			 */
			pr_smb(PR_MISC, "setting usb psy health %s\n",
					chip->very_weak_charger
					? "UNSPEC_FAILURE" : "GOOD");
			rc = power_supply_set_health_state(chip->usb_psy,
					chip->very_weak_charger
					? POWER_SUPPLY_HEALTH_UNSPEC_FAILURE
@@ -3929,6 +3939,21 @@ static void handle_usb_insertion(struct smbchg_chip *chip)
	if (usb_supply_type == POWER_SUPPLY_TYPE_USB_DCP)
		schedule_delayed_work(&chip->hvdcp_det_work,
					msecs_to_jiffies(HVDCP_NOTIFY_MS));

	mutex_lock(&chip->current_change_lock);
	if (usb_supply_type == POWER_SUPPLY_TYPE_USB)
		chip->usb_target_current_ma = DEFAULT_SDP_MA;
	else if (usb_supply_type == POWER_SUPPLY_TYPE_USB_CDP)
		chip->usb_target_current_ma = DEFAULT_CDP_MA;
	else
		chip->usb_target_current_ma = DEFAULT_WALL_CHG_MA;

	pr_smb(PR_STATUS, "%s detected setting mA = %d\n",
		usb_type_name, chip->usb_target_current_ma);
	rc = smbchg_set_thermal_limited_usb_current_max(chip,
				chip->usb_target_current_ma);
	mutex_unlock(&chip->current_change_lock);

	if (parallel_psy) {
		rc = power_supply_set_present(parallel_psy, true);
		chip->parallel_charger_detected = rc ? false : true;
@@ -4081,6 +4106,8 @@ static void increment_aicl_count(struct smbchg_chip *chip)
			bad_charger = true;
		}
		if (bad_charger) {
			pr_smb(PR_MISC,
				"setting usb psy health UNSPEC_FAILURE\n");
			rc = power_supply_set_health_state(chip->usb_psy,
					POWER_SUPPLY_HEALTH_UNSPEC_FAILURE);
			if (rc)
@@ -4598,6 +4625,7 @@ static irqreturn_t usbin_ov_handler(int irq, void *_chip)
	if (reg & USBIN_OV_BIT) {
		chip->usb_ov_det = true;
		if (chip->usb_psy) {
			pr_smb(PR_MISC, "setting usb psy health OV\n");
			rc = power_supply_set_health_state(chip->usb_psy,
					POWER_SUPPLY_HEALTH_OVERVOLTAGE);
			if (rc)
@@ -4677,6 +4705,7 @@ static irqreturn_t usbin_uv_handler(int irq, void *_chip)
			if (rc)
				pr_err("could not enable aicl reruns: %d", rc);
		}
		pr_smb(PR_MISC, "setting usb psy health UNSPEC_FAILURE\n");
		rc = power_supply_set_health_state(chip->usb_psy,
				POWER_SUPPLY_HEALTH_UNSPEC_FAILURE);
		if (rc)
@@ -4822,8 +4851,11 @@ static irqreturn_t usbid_change_handler(int irq, void *_chip)
	pr_smb(PR_INTERRUPT, "triggered\n");

	otg_present = is_otg_present(chip);
	if (chip->usb_psy)
	if (chip->usb_psy) {
		pr_smb(PR_MISC, "setting usb psy OTG = %d\n",
				otg_present ? 1 : 0);
		power_supply_set_usb_otg(chip->usb_psy, otg_present ? 1 : 0);
	}
	if (otg_present)
		pr_smb(PR_STATUS, "OTG detected\n");

@@ -6121,6 +6153,7 @@ static int smbchg_probe(struct spmi_device *spmi)
		goto unregister_led_class;
	}

	pr_smb(PR_MISC, "setting usb psy present = %d\n", chip->usb_present);
	power_supply_set_present(chip->usb_psy, chip->usb_present);

	dump_regs(chip);