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

Commit 90f05606 authored by Fenglin Wu's avatar Fenglin Wu
Browse files

asoc: codec: swr-haptics: update slave-vdd regulator control logic



Update the slave-vdd regulator control logic to avoid unbalanced
regulator_enable() regulator_disable() calls. Meanwhile, correct
the jump label when bailing out from soundwire enumeration failure.
This helps to avoid the regulator_put() call in the device remove
process throwing a warning for a dangling regulator enable status.

Change-Id: I89157f5f9177db69bbbf6aedcc8e605c43a7584e
Signed-off-by: default avatarFenglin Wu <fenglinw@codeaurora.org>
parent 0f28ed9d
Loading
Loading
Loading
Loading
+50 −36
Original line number Diff line number Diff line
@@ -76,10 +76,10 @@ struct swr_haptics_dev {
	struct snd_soc_component	*component;
	struct regmap			*regmap;
	struct swr_port			port;
	struct regulator		*vdd;
	u32 enable_cnt;
	struct regulator		*slave_vdd;
	struct regulator		*hpwr_vreg;
	u32				hpwr_voltage_mv;
	bool				slave_enabled;
	bool				hpwr_vreg_enabled;
	u8				vmax;
};
@@ -168,6 +168,44 @@ static int swr_hap_enable_hpwr_vreg(struct swr_haptics_dev *swr_hap, bool en)
	return 0;
}

static int swr_haptics_slave_enable(struct swr_haptics_dev *swr_hap)
{
	int rc;

	if (swr_hap->slave_enabled)
		return 0;

	rc = regulator_enable(swr_hap->slave_vdd);
	if (rc < 0) {
		dev_err(swr_hap->dev, "%s: enable swr-slave-vdd failed, rc=%d\n",
				__func__, rc);
		return rc;
	}

	dev_dbg(swr_hap->dev, "%s: enable swr-slave-vdd success\n", __func__);
	swr_hap->slave_enabled = true;
	return 0;
}

static int swr_haptics_slave_disable(struct swr_haptics_dev *swr_hap)
{
	int rc;

	if (!swr_hap->slave_enabled)
		return 0;

	rc = regulator_disable(swr_hap->slave_vdd);
	if (rc < 0) {
		dev_err(swr_hap->dev, "%s: disable swr-slave-vdd failed, rc=%d\n",
				__func__, rc);
		return rc;
	}

	dev_dbg(swr_hap->dev, "%s: disable swr-slave-vdd success\n", __func__);
	swr_hap->slave_enabled = false;
	return 0;
}

struct regmap_config swr_hap_regmap_config = {
	.reg_bits		= 16,
	.val_bits		= 8,
@@ -438,7 +476,6 @@ static int swr_haptics_probe(struct swr_device *sdev)
	swr_hap->swr_slave = sdev;
	swr_hap->dev = &sdev->dev;
	swr_set_dev_data(sdev, swr_hap);
	swr_hap->enable_cnt = 0;

	rc = swr_haptics_parse_port_mapping(sdev);
	if (rc < 0) {
@@ -447,9 +484,9 @@ static int swr_haptics_probe(struct swr_device *sdev)
		goto clean;
	}

	swr_hap->vdd = devm_regulator_get(swr_hap->dev, "swr-slave");
	if (IS_ERR(swr_hap->vdd)) {
		rc = PTR_ERR(swr_hap->vdd);
	swr_hap->slave_vdd = devm_regulator_get(swr_hap->dev, "swr-slave");
	if (IS_ERR(swr_hap->slave_vdd)) {
		rc = PTR_ERR(swr_hap->slave_vdd);
		if (rc != -EPROBE_DEFER)
			dev_err(swr_hap->dev, "%s: get swr-slave-supply failed, rc=%d\n",
					__func__, rc);
@@ -476,7 +513,7 @@ static int swr_haptics_probe(struct swr_device *sdev)
		}
	}

	rc = regulator_enable(swr_hap->vdd);
	rc = swr_haptics_slave_enable(swr_hap);
	if (rc < 0) {
		dev_err(swr_hap->dev, "%s: enable swr-slave-vdd failed, rc=%d\n",
				__func__, rc);
@@ -492,7 +529,7 @@ static int swr_haptics_probe(struct swr_device *sdev)
		dev_err(swr_hap->dev, "%s: failed to get devnum for swr-haptics, rc=%d\n",
				__func__, rc);
		rc = -EPROBE_DEFER;
		goto clean;
		goto dev_err;
	}

	sdev->dev_num = devnum;
@@ -514,7 +551,7 @@ static int swr_haptics_probe(struct swr_device *sdev)

	return 0;
dev_err:
	regulator_disable(swr_hap->vdd);
	swr_haptics_slave_disable(swr_hap);
	swr_remove_device(sdev);
clean:
	swr_set_dev_data(sdev, NULL);
@@ -533,7 +570,7 @@ static int swr_haptics_remove(struct swr_device *sdev)
		goto clean;
	}

	rc = regulator_disable(swr_hap->vdd);
	rc = swr_haptics_slave_disable(swr_hap);
	if (rc < 0) {
		dev_err(swr_hap->dev, "%s: disable swr-slave failed, rc=%d\n",
				__func__, rc);
@@ -548,7 +585,6 @@ static int swr_haptics_remove(struct swr_device *sdev)
static int swr_haptics_device_up(struct swr_device *sdev)
{
	struct swr_haptics_dev *swr_hap;
	int rc;

	swr_hap = swr_get_dev_data(sdev);
	if (!swr_hap) {
@@ -557,16 +593,7 @@ static int swr_haptics_device_up(struct swr_device *sdev)
	}

	/* Take SWR slave out of reset */
	rc = regulator_enable(swr_hap->vdd);
	if (rc < 0) {
		dev_err(swr_hap->dev, "%s: enable swr-slave failed, rc=%d\n",
				__func__, rc);
		return rc;
	} else {
		swr_hap->enable_cnt++;
	}

	return 0;
	return swr_haptics_slave_enable(swr_hap);
}

static int swr_haptics_device_down(struct swr_device *sdev)
@@ -579,20 +606,6 @@ static int swr_haptics_device_down(struct swr_device *sdev)
		return -ENODEV;
	}

	/* Put SWR slave into reset */
	if (swr_hap->enable_cnt > 0) {
		rc = regulator_disable(swr_hap->vdd);
		if (rc < 0) {
			dev_err(swr_hap->dev, "%s: disable swr-slave failed, rc=%d\n",
				__func__, rc);
			return rc;
		} else {
			swr_hap->enable_cnt--;
		}
	} else {
		swr_hap->enable_cnt = 0;
	}

	/* Disable HAP_PWR regulator */
	rc = swr_hap_enable_hpwr_vreg(swr_hap, false);
	if (rc < 0) {
@@ -601,7 +614,8 @@ static int swr_haptics_device_down(struct swr_device *sdev)
		return rc;
	}

	return 0;
	/* Put SWR slave into reset */
	return swr_haptics_slave_disable(swr_hap);
}

static int swr_haptics_suspend(struct device *dev)