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

Commit 6ca8f059 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: Update the dpdm usage"

parents 028f34a7 6c1e9ab5
Loading
Loading
Loading
Loading
+50 −24
Original line number Diff line number Diff line
@@ -1520,6 +1520,47 @@ static struct power_supply *get_parallel_psy(struct smbchg_chip *chip)
	return chip->parallel.psy;
}

static int smbchg_request_dpdm(struct smbchg_chip *chip, bool enable)
{
	int rc = 0;

	/* fetch the DPDM regulator */
	if (!chip->dpdm_reg && of_get_property(chip->dev->of_node,
				"dpdm-supply", NULL)) {
		chip->dpdm_reg = devm_regulator_get(chip->dev, "dpdm");
		if (IS_ERR(chip->dpdm_reg)) {
			rc = PTR_ERR(chip->dpdm_reg);
			dev_err(chip->dev, "Couldn't get dpdm regulator rc=%d\n",
					rc);
			chip->dpdm_reg = NULL;
			return rc;
		}
	}

	if (!chip->dpdm_reg)
		return -ENODEV;

	if (enable) {
		if (!regulator_is_enabled(chip->dpdm_reg)) {
			pr_smb(PR_STATUS, "enabling DPDM regulator\n");
			rc = regulator_enable(chip->dpdm_reg);
			if (rc < 0)
				dev_err(chip->dev, "Couldn't enable dpdm regulator rc=%d\n",
					rc);
		}
	} else {
		if (regulator_is_enabled(chip->dpdm_reg)) {
			pr_smb(PR_STATUS, "disabling DPDM regulator\n");
			rc = regulator_disable(chip->dpdm_reg);
			if (rc < 0)
				dev_err(chip->dev, "Couldn't disable dpdm regulator rc=%d\n",
					rc);
		}
	}

	return rc;
}

static void smbchg_usb_update_online_work(struct work_struct *work)
{
	struct smbchg_chip *chip = container_of(work,
@@ -4590,8 +4631,11 @@ static int set_usb_psy_dp_dm(struct smbchg_chip *chip, int state)
	if (!rc && !(reg & USBIN_UV_BIT) && !(reg & USBIN_SRC_DET_BIT)) {
		pr_smb(PR_MISC, "overwriting state = %d with %d\n",
				state, POWER_SUPPLY_DP_DM_DPF_DMF);
		if (chip->dpdm_reg && !regulator_is_enabled(chip->dpdm_reg))
			return regulator_enable(chip->dpdm_reg);
		rc = smbchg_request_dpdm(chip, true);
		if (rc < 0) {
			pr_err("Couldn't enable DP/DM for pulsing rc=%d\n", rc);
			return rc;
		}
	}
	pr_smb(PR_MISC, "setting usb psy dp dm = %d\n", state);
	pval.intval = state;
@@ -4697,8 +4741,7 @@ static void handle_usb_removal(struct smbchg_chip *chip)
	smbchg_relax(chip, PM_DETECT_HVDCP);
	smbchg_change_usb_supply_type(chip, POWER_SUPPLY_TYPE_UNKNOWN);
	extcon_set_cable_state_(chip->extcon, EXTCON_USB, chip->usb_present);
	if (chip->dpdm_reg)
		regulator_disable(chip->dpdm_reg);
	smbchg_request_dpdm(chip, false);
	schedule_work(&chip->usb_set_online_work);

	pr_smb(PR_MISC, "setting usb psy health UNKNOWN\n");
@@ -5248,8 +5291,7 @@ static int smbchg_unprepare_for_pulsing(struct smbchg_chip *chip)
{
	int rc = 0;

	if (chip->dpdm_reg && !regulator_is_enabled(chip->dpdm_reg))
		rc = regulator_enable(chip->dpdm_reg);
	rc = smbchg_request_dpdm(chip, true);
	if (rc < 0) {
		pr_err("Couldn't enable DP/DM for pulsing rc=%d\n", rc);
		return rc;
@@ -6481,8 +6523,7 @@ static irqreturn_t usbin_uv_handler(int irq, void *_chip)
	 */
	if (!(reg & USBIN_UV_BIT) && !(reg & USBIN_SRC_DET_BIT)) {
		pr_smb(PR_MISC, "setting usb dp=f dm=f\n");
		if (chip->dpdm_reg && !regulator_is_enabled(chip->dpdm_reg))
			rc = regulator_enable(chip->dpdm_reg);
		rc = smbchg_request_dpdm(chip, true);
		if (rc < 0) {
			pr_err("Couldn't enable DP/DM for pulsing rc=%d\n", rc);
			return rc;
@@ -6731,15 +6772,8 @@ static int determine_initial_status(struct smbchg_chip *chip)
	chip->dc_present = is_dc_present(chip);

	if (chip->usb_present) {
		int rc = 0;

		pr_smb(PR_MISC, "setting usb dp=f dm=f\n");
		if (chip->dpdm_reg && !regulator_is_enabled(chip->dpdm_reg))
			rc = regulator_enable(chip->dpdm_reg);
		if (rc < 0) {
			pr_err("Couldn't enable DP/DM for pulsing rc=%d\n", rc);
			return rc;
		}
		smbchg_request_dpdm(chip, true);
		handle_usb_insertion(chip);
	} else {
		handle_usb_removal(chip);
@@ -8372,14 +8406,6 @@ static int smbchg_probe(struct platform_device *pdev)
		goto votables_cleanup;
	}

	if (of_find_property(chip->dev->of_node, "dpdm-supply", NULL)) {
		chip->dpdm_reg = devm_regulator_get(chip->dev, "dpdm");
		if (IS_ERR(chip->dpdm_reg)) {
			rc = PTR_ERR(chip->dpdm_reg);
			goto votables_cleanup;
		}
	}

	rc = smbchg_hw_init(chip);
	if (rc < 0) {
		dev_err(&pdev->dev,
+11 −14
Original line number Diff line number Diff line
@@ -1835,9 +1835,12 @@ static int get_psy_type(struct msm_otg *motg)
	union power_supply_propval pval = {0};

	if (!psy) {
		dev_err(motg->phy.dev, "no usb power supply registered\n");
		psy = power_supply_get_by_name("usb");
		if (!psy) {
			dev_err(motg->phy.dev, "Could not get usb power_supply\n");
			return -ENODEV;
		}
	}

	power_supply_get_property(psy, POWER_SUPPLY_PROP_REAL_TYPE, &pval);

@@ -1868,11 +1871,6 @@ static int msm_otg_notify_chg_type(struct msm_otg *motg)
	else
		charger_type = POWER_SUPPLY_TYPE_UNKNOWN;

	if (!psy) {
		dev_err(motg->phy.dev, "no usb power supply registered\n");
		return -ENODEV;
	}

	pr_debug("Trying to set usb power supply type %d\n", charger_type);

	propval.intval = charger_type;
@@ -1897,6 +1895,10 @@ static void msm_otg_notify_charger(struct msm_otg *motg, unsigned int mA)

	dev_dbg(motg->phy.dev, "Requested curr from USB = %u\n", mA);

	psy_type = get_psy_type(motg);
	if (psy_type == -ENODEV)
		return;

	if (msm_otg_notify_chg_type(motg))
		dev_dbg(motg->phy.dev, "Failed notifying %d charger type to PMIC\n",
							motg->chg_type);
@@ -4473,12 +4475,8 @@ static int msm_otg_probe(struct platform_device *pdev)
	}

	psy = power_supply_get_by_name("usb");
	if (!psy) {
		dev_dbg(&pdev->dev, "Could not get usb power_supply\n");
		ret = -EPROBE_DEFER;
		goto otg_remove_devices;
	}

	if (!psy)
		dev_warn(&pdev->dev, "Could not get usb power_supply\n");

	ret = msm_otg_extcon_register(motg);
	if (ret)
@@ -4533,7 +4531,6 @@ static int msm_otg_probe(struct platform_device *pdev)
put_psy:
	if (psy)
		power_supply_put(psy);
otg_remove_devices:
	if (pdev->dev.of_node)
		msm_otg_setup_devices(pdev, motg->pdata->mode, false);
remove_cdev: