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

Commit 7a33dc6c authored by Vatsal Bucha's avatar Vatsal Bucha
Browse files

ASoC: codecs: Add count check for swr haptics device up/down



Add count check before enabling/disabling regulator for swr
haptics. This is to ensure that count dosent get mismatched.

Change-Id: I73bb9f8ef459eea4327b9db09c430e8c2ec87adb
Signed-off-by: default avatarVatsal Bucha <vbucha@codeaurora.org>
parent 59298aad
Loading
Loading
Loading
Loading
+14 −5
Original line number Diff line number Diff line
@@ -77,6 +77,7 @@ struct swr_haptics_dev {
	struct regmap			*regmap;
	struct swr_port			port;
	struct regulator		*vdd;
	u32 enable_cnt;
};

static bool swr_hap_volatile_register(struct device *dev, unsigned int reg)
@@ -324,6 +325,7 @@ 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) {
@@ -427,6 +429,8 @@ static int swr_haptics_device_up(struct swr_device *sdev)
		dev_err(swr_hap->dev, "%s: enable swr-slave failed, rc=%d\n",
				__func__, rc);
		return rc;
	} else {
		swr_hap->enable_cnt++;
	}

	return 0;
@@ -443,13 +447,18 @@ static int swr_haptics_device_down(struct swr_device *sdev)
	}

	/* 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;
	}

	return 0;
}