From 7a33dc6cc1af852e6aa9ace58b66c7f3ae3e37b7 Mon Sep 17 00:00:00 2001 From: Vatsal Bucha Date: Mon, 9 Nov 2020 10:37:14 +0530 Subject: [PATCH] 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: Vatsal Bucha --- asoc/codecs/swr-haptics.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/asoc/codecs/swr-haptics.c b/asoc/codecs/swr-haptics.c index dcfeb39dd05d..20657d57200a 100644 --- a/asoc/codecs/swr-haptics.c +++ b/asoc/codecs/swr-haptics.c @@ -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 */ - rc = regulator_disable(swr_hap->vdd); - if (rc < 0) { - dev_err(swr_hap->dev, "%s: disable swr-slave failed, rc=%d\n", + 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; + return rc; + } else { + swr_hap->enable_cnt--; + } + } else { + swr_hap->enable_cnt = 0; } - return 0; }