From ef71b9482d9759b8efcafd1b7be84273a4b71b33 Mon Sep 17 00:00:00 2001 From: Shuming Fan Date: Mon, 9 Dec 2019 14:45:27 +0800 Subject: [PATCH 1/2] ASoC: rt700: Add pin sense check during jack type detection To avoid IO error, the codec driver needs to check the pin sense during jack type detection. Due to the jack type detection will take some times in the loop, in case the jack is removed during this time, then the driver goes into suspend mode. The IO error will occur in the rest of process. Signed-off-by: Shuming Fan --- sound/soc/codecs/rt700.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/sound/soc/codecs/rt700.c b/sound/soc/codecs/rt700.c index fbb3f5b3b29b0c..257686c936cfff 100644 --- a/sound/soc/codecs/rt700.c +++ b/sound/soc/codecs/rt700.c @@ -115,6 +115,7 @@ static int rt700_headset_detect(struct rt700_priv *rt700) { unsigned int buf, loop = 0; int ret; + unsigned int jack_status = 0, reg; ret = rt700_index_read(rt700->regmap, RT700_COMBO_JACK_AUTO_CTL2, &buf); @@ -130,6 +131,11 @@ static int rt700_headset_detect(struct rt700_priv *rt700) RT700_COMBO_JACK_AUTO_CTL2, &buf); if (ret < 0) goto io_error; + + reg = RT700_VERB_GET_PIN_SENSE | RT700_HP_OUT; + ret = regmap_read(rt700->regmap, reg, &jack_status); + if ((jack_status & (1 << 31)) == 0) + goto remove_error; } if (loop >= 500) @@ -150,6 +156,9 @@ static int rt700_headset_detect(struct rt700_priv *rt700) io_error: pr_err_ratelimited("IO error in %s, ret %d\n", __func__, ret); return ret; +remove_error: + pr_err_ratelimited("Jack removal in %s\n", __func__); + return -ENODEV; } static void rt700_jack_detect_handler(struct work_struct *work) From a9617eeeb1e31e071d74982e6a769f06ebda546d Mon Sep 17 00:00:00 2001 From: Shuming Fan Date: Mon, 9 Dec 2019 14:45:46 +0800 Subject: [PATCH 2/2] ASoC: rt711: Add pin sense check during jack type detection To avoid IO error, the codec driver needs to check the pin sense during jack type detection. Due to the jack type detection will take some times in the loop, in case the jack is removed during this time, then the driver goes into suspend mode. The IO error will occur in the rest of process. Signed-off-by: Shuming Fan --- sound/soc/codecs/rt711.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/sound/soc/codecs/rt711.c b/sound/soc/codecs/rt711.c index 688fe05b0ee961..0d05f331c18315 100644 --- a/sound/soc/codecs/rt711.c +++ b/sound/soc/codecs/rt711.c @@ -193,6 +193,7 @@ static int rt711_headset_detect(struct rt711_priv *rt711) { unsigned int buf, loop = 0; int ret; + unsigned int jack_status = 0, reg; ret = rt711_index_read(rt711->regmap, RT711_VENDOR_REG, RT711_COMBO_JACK_AUTO_CTL2, &buf); @@ -208,6 +209,13 @@ static int rt711_headset_detect(struct rt711_priv *rt711) RT711_COMBO_JACK_AUTO_CTL2, &buf); if (ret < 0) goto io_error; + + reg = RT711_VERB_GET_PIN_SENSE | RT711_HP_OUT; + ret = regmap_read(rt711->regmap, reg, &jack_status); + if (ret < 0) + goto io_error; + if ((jack_status & (1 << 31)) == 0) + goto remove_error; } if (loop >= 500) @@ -228,6 +236,9 @@ static int rt711_headset_detect(struct rt711_priv *rt711) io_error: pr_err_ratelimited("IO error in %s, ret %d\n", __func__, ret); return ret; +remove_error: + pr_err_ratelimited("Jack removal in %s\n", __func__); + return -ENODEV; } static void rt711_jack_detect_handler(struct work_struct *work)