* [PATCH 1/5] ASoC: rt5651: Fix workqueue cancel vs irq free race on remove
@ 2018-07-04 22:59 Hans de Goede
2018-07-04 22:59 ` [PATCH 2/5] ASoC: rt5651: Allow disabling jack-detect by calling set_jack(NULL) Hans de Goede
` (4 more replies)
0 siblings, 5 replies; 12+ messages in thread
From: Hans de Goede @ 2018-07-04 22:59 UTC (permalink / raw)
To: Liam Girdwood, Mark Brown, Bard Liao, Oder Chiou
Cc: Hans de Goede, alsa-devel, Pierre-Louis Bossart, Carlo Caione
On removal we must free the IRQ *before* cancelling the jack-detect work,
so that the jack-detect work cannot be rescheduled by the IRQ.
Before this commit we were cancelling the jack-detect work from the
driver remove callback, while relying on devm to free the IRQ, which
happens after the remove callback.
This is the wrong order. This commit uses a devm-action to register
a devm callback which cancels the work, before requesting the IRQ
(devm tears things down in reverse order). This also allows us to
remove the now empty remove driver callback.
Cc: Carlo Caione <carlo@endlessm.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
sound/soc/codecs/rt5651.c | 22 ++++++++++++----------
1 file changed, 12 insertions(+), 10 deletions(-)
diff --git a/sound/soc/codecs/rt5651.c b/sound/soc/codecs/rt5651.c
index 6b5669f3e85d..39d2c67cd064 100644
--- a/sound/soc/codecs/rt5651.c
+++ b/sound/soc/codecs/rt5651.c
@@ -1696,6 +1696,13 @@ static irqreturn_t rt5651_irq(int irq, void *data)
return IRQ_HANDLED;
}
+static void rt5651_cancel_work(void *data)
+{
+ struct rt5651_priv *rt5651 = data;
+
+ cancel_work_sync(&rt5651->jack_detect_work);
+}
+
static int rt5651_set_jack(struct snd_soc_component *component,
struct snd_soc_jack *hp_jack, void *data)
{
@@ -2036,6 +2043,11 @@ static int rt5651_i2c_probe(struct i2c_client *i2c,
INIT_WORK(&rt5651->jack_detect_work, rt5651_jack_detect_work);
+ /* Make sure work is stopped on probe-error / remove */
+ ret = devm_add_action_or_reset(&i2c->dev, rt5651_cancel_work, rt5651);
+ if (ret)
+ return ret;
+
ret = devm_snd_soc_register_component(&i2c->dev,
&soc_component_dev_rt5651,
rt5651_dai, ARRAY_SIZE(rt5651_dai));
@@ -2043,15 +2055,6 @@ static int rt5651_i2c_probe(struct i2c_client *i2c,
return ret;
}
-static int rt5651_i2c_remove(struct i2c_client *i2c)
-{
- struct rt5651_priv *rt5651 = i2c_get_clientdata(i2c);
-
- cancel_work_sync(&rt5651->jack_detect_work);
-
- return 0;
-}
-
static struct i2c_driver rt5651_i2c_driver = {
.driver = {
.name = "rt5651",
@@ -2059,7 +2062,6 @@ static struct i2c_driver rt5651_i2c_driver = {
.of_match_table = of_match_ptr(rt5651_of_match),
},
.probe = rt5651_i2c_probe,
- .remove = rt5651_i2c_remove,
.id_table = rt5651_i2c_id,
};
module_i2c_driver(rt5651_i2c_driver);
--
2.17.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 2/5] ASoC: rt5651: Allow disabling jack-detect by calling set_jack(NULL)
2018-07-04 22:59 [PATCH 1/5] ASoC: rt5651: Fix workqueue cancel vs irq free race on remove Hans de Goede
@ 2018-07-04 22:59 ` Hans de Goede
2018-07-10 18:16 ` Applied "ASoC: rt5651: Allow disabling jack-detect by calling set_jack(NULL)" to the asoc tree Mark Brown
2018-07-04 22:59 ` [PATCH 3/5] ASoC: rt5651: Add button press support Hans de Goede
` (3 subsequent siblings)
4 siblings, 1 reply; 12+ messages in thread
From: Hans de Goede @ 2018-07-04 22:59 UTC (permalink / raw)
To: Liam Girdwood, Mark Brown, Bard Liao, Oder Chiou
Cc: Hans de Goede, alsa-devel, Pierre-Louis Bossart, Carlo Caione
Allow the machine driver to disable jack-detect over a suspend/resume by
calling snd_soc_component_set_jack(NULL).
Note this renames rt5651_set_jack, where all the jack-enable work was done
to rt5651_enable_jack_detect. This function can now no longer fail as it
does not request the IRQ anymore. It can still be passed an invalid jack
source, but that should never happen, so this is now logged and treated as
no jack source.
Cc: Carlo Caione <carlo@endlessm.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
sound/soc/codecs/rt5651.c | 55 +++++++++++++++++++++++++--------------
1 file changed, 36 insertions(+), 19 deletions(-)
diff --git a/sound/soc/codecs/rt5651.c b/sound/soc/codecs/rt5651.c
index 39d2c67cd064..40bd1e70fee7 100644
--- a/sound/soc/codecs/rt5651.c
+++ b/sound/soc/codecs/rt5651.c
@@ -1703,14 +1703,10 @@ static void rt5651_cancel_work(void *data)
cancel_work_sync(&rt5651->jack_detect_work);
}
-static int rt5651_set_jack(struct snd_soc_component *component,
- struct snd_soc_jack *hp_jack, void *data)
+static void rt5651_enable_jack_detect(struct snd_soc_component *component,
+ struct snd_soc_jack *hp_jack)
{
struct rt5651_priv *rt5651 = snd_soc_component_get_drvdata(component);
- int ret;
-
- if (!rt5651->irq)
- return -EINVAL;
/* IRQ output on GPIO1 */
snd_soc_component_update_bits(component, RT5651_GPIO_CTRL1,
@@ -1737,10 +1733,10 @@ static int rt5651_set_jack(struct snd_soc_component *component,
RT5651_JD2_IRQ_EN, RT5651_JD2_IRQ_EN);
break;
case RT5651_JD_NULL:
- return 0;
+ return;
default:
dev_err(component->dev, "Currently only JD1_1 / JD1_2 / JD2 are supported\n");
- return -EINVAL;
+ return;
}
/* Enable jack detect power */
@@ -1774,19 +1770,28 @@ static int rt5651_set_jack(struct snd_soc_component *component,
RT5651_MB1_OC_STKY_MASK, RT5651_MB1_OC_STKY_EN);
rt5651->hp_jack = hp_jack;
-
- ret = devm_request_threaded_irq(component->dev, rt5651->irq, NULL,
- rt5651_irq,
- IRQF_TRIGGER_RISING |
- IRQF_TRIGGER_FALLING |
- IRQF_ONESHOT, "rt5651", rt5651);
- if (ret) {
- dev_err(component->dev, "Failed to reguest IRQ: %d\n", ret);
- return ret;
- }
-
+ enable_irq(rt5651->irq);
/* sync initial jack state */
queue_work(system_power_efficient_wq, &rt5651->jack_detect_work);
+}
+
+static void rt5651_disable_jack_detect(struct snd_soc_component *component)
+{
+ struct rt5651_priv *rt5651 = snd_soc_component_get_drvdata(component);
+
+ disable_irq(rt5651->irq);
+ rt5651_cancel_work(rt5651);
+
+ rt5651->hp_jack = NULL;
+}
+
+static int rt5651_set_jack(struct snd_soc_component *component,
+ struct snd_soc_jack *jack, void *data)
+{
+ if (jack)
+ rt5651_enable_jack_detect(component, jack);
+ else
+ rt5651_disable_jack_detect(component);
return 0;
}
@@ -2048,6 +2053,18 @@ static int rt5651_i2c_probe(struct i2c_client *i2c,
if (ret)
return ret;
+ ret = devm_request_irq(&i2c->dev, rt5651->irq, rt5651_irq,
+ IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING
+ | IRQF_ONESHOT, "rt5651", rt5651);
+ if (ret == 0) {
+ /* Gets re-enabled by rt5651_set_jack() */
+ disable_irq(rt5651->irq);
+ } else {
+ dev_warn(&i2c->dev, "Failed to reguest IRQ %d: %d\n",
+ rt5651->irq, ret);
+ rt5651->irq = -ENXIO;
+ }
+
ret = devm_snd_soc_register_component(&i2c->dev,
&soc_component_dev_rt5651,
rt5651_dai, ARRAY_SIZE(rt5651_dai));
--
2.17.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 3/5] ASoC: rt5651: Add button press support
2018-07-04 22:59 [PATCH 1/5] ASoC: rt5651: Fix workqueue cancel vs irq free race on remove Hans de Goede
2018-07-04 22:59 ` [PATCH 2/5] ASoC: rt5651: Allow disabling jack-detect by calling set_jack(NULL) Hans de Goede
@ 2018-07-04 22:59 ` Hans de Goede
2018-07-10 18:16 ` Applied "ASoC: rt5651: Add button press support" to the asoc tree Mark Brown
2018-07-04 22:59 ` [PATCH 4/5] ASoC: Intel: bytcr_rt5651: Disable jack-detect over suspend/resume Hans de Goede
` (2 subsequent siblings)
4 siblings, 1 reply; 12+ messages in thread
From: Hans de Goede @ 2018-07-04 22:59 UTC (permalink / raw)
To: Liam Girdwood, Mark Brown, Bard Liao, Oder Chiou
Cc: Hans de Goede, alsa-devel, Pierre-Louis Bossart, Carlo Caione
Enable button press detection for headsets by using the ovcd IRQ to get
notified of button presses.
This is modelled after (almost exactly copied from) the button press code
for the rt5640 which has identical ovcd hardware.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
sound/soc/codecs/rt5651.c | 158 ++++++++++++++++++++++++++++++++++++--
sound/soc/codecs/rt5651.h | 8 ++
2 files changed, 159 insertions(+), 7 deletions(-)
diff --git a/sound/soc/codecs/rt5651.c b/sound/soc/codecs/rt5651.c
index 40bd1e70fee7..0462049e739c 100644
--- a/sound/soc/codecs/rt5651.c
+++ b/sound/soc/codecs/rt5651.c
@@ -1581,6 +1581,24 @@ static void rt5651_disable_micbias1_for_ovcd(struct snd_soc_component *component
snd_soc_dapm_mutex_unlock(dapm);
}
+static void rt5651_enable_micbias1_ovcd_irq(struct snd_soc_component *component)
+{
+ struct rt5651_priv *rt5651 = snd_soc_component_get_drvdata(component);
+
+ snd_soc_component_update_bits(component, RT5651_IRQ_CTRL2,
+ RT5651_IRQ_MB1_OC_MASK, RT5651_IRQ_MB1_OC_NOR);
+ rt5651->ovcd_irq_enabled = true;
+}
+
+static void rt5651_disable_micbias1_ovcd_irq(struct snd_soc_component *component)
+{
+ struct rt5651_priv *rt5651 = snd_soc_component_get_drvdata(component);
+
+ snd_soc_component_update_bits(component, RT5651_IRQ_CTRL2,
+ RT5651_IRQ_MB1_OC_MASK, RT5651_IRQ_MB1_OC_BP);
+ rt5651->ovcd_irq_enabled = false;
+}
+
static void rt5651_clear_micbias1_ovcd(struct snd_soc_component *component)
{
snd_soc_component_update_bits(component, RT5651_IRQ_CTRL2,
@@ -1622,10 +1640,80 @@ static bool rt5651_jack_inserted(struct snd_soc_component *component)
return val == 0;
}
-/* Jack detect timings */
+/* Jack detect and button-press timings */
#define JACK_SETTLE_TIME 100 /* milli seconds */
#define JACK_DETECT_COUNT 5
#define JACK_DETECT_MAXCOUNT 20 /* Aprox. 2 seconds worth of tries */
+#define JACK_UNPLUG_TIME 80 /* milli seconds */
+#define BP_POLL_TIME 10 /* milli seconds */
+#define BP_POLL_MAXCOUNT 200 /* assume something is wrong after this */
+#define BP_THRESHOLD 3
+
+static void rt5651_start_button_press_work(struct snd_soc_component *component)
+{
+ struct rt5651_priv *rt5651 = snd_soc_component_get_drvdata(component);
+
+ rt5651->poll_count = 0;
+ rt5651->press_count = 0;
+ rt5651->release_count = 0;
+ rt5651->pressed = false;
+ rt5651->press_reported = false;
+ rt5651_clear_micbias1_ovcd(component);
+ schedule_delayed_work(&rt5651->bp_work, msecs_to_jiffies(BP_POLL_TIME));
+}
+
+static void rt5651_button_press_work(struct work_struct *work)
+{
+ struct rt5651_priv *rt5651 =
+ container_of(work, struct rt5651_priv, bp_work.work);
+ struct snd_soc_component *component = rt5651->component;
+
+ /* Check the jack was not removed underneath us */
+ if (!rt5651_jack_inserted(component))
+ return;
+
+ if (rt5651_micbias1_ovcd(component)) {
+ rt5651->release_count = 0;
+ rt5651->press_count++;
+ /* Remember till after JACK_UNPLUG_TIME wait */
+ if (rt5651->press_count >= BP_THRESHOLD)
+ rt5651->pressed = true;
+ rt5651_clear_micbias1_ovcd(component);
+ } else {
+ rt5651->press_count = 0;
+ rt5651->release_count++;
+ }
+
+ /*
+ * The pins get temporarily shorted on jack unplug, so we poll for
+ * at least JACK_UNPLUG_TIME milli-seconds before reporting a press.
+ */
+ rt5651->poll_count++;
+ if (rt5651->poll_count < (JACK_UNPLUG_TIME / BP_POLL_TIME)) {
+ schedule_delayed_work(&rt5651->bp_work,
+ msecs_to_jiffies(BP_POLL_TIME));
+ return;
+ }
+
+ if (rt5651->pressed && !rt5651->press_reported) {
+ dev_dbg(component->dev, "headset button press\n");
+ snd_soc_jack_report(rt5651->hp_jack, SND_JACK_BTN_0,
+ SND_JACK_BTN_0);
+ rt5651->press_reported = true;
+ }
+
+ if (rt5651->release_count >= BP_THRESHOLD) {
+ if (rt5651->press_reported) {
+ dev_dbg(component->dev, "headset button release\n");
+ snd_soc_jack_report(rt5651->hp_jack, 0, SND_JACK_BTN_0);
+ }
+ /* Re-enable OVCD IRQ to detect next press */
+ rt5651_enable_micbias1_ovcd_irq(component);
+ return; /* Stop polling */
+ }
+
+ schedule_delayed_work(&rt5651->bp_work, msecs_to_jiffies(BP_POLL_TIME));
+}
static int rt5651_detect_headset(struct snd_soc_component *component)
{
@@ -1676,15 +1764,58 @@ static void rt5651_jack_detect_work(struct work_struct *work)
{
struct rt5651_priv *rt5651 =
container_of(work, struct rt5651_priv, jack_detect_work);
+ struct snd_soc_component *component = rt5651->component;
int report = 0;
- if (rt5651_jack_inserted(rt5651->component)) {
- rt5651_enable_micbias1_for_ovcd(rt5651->component);
- report = rt5651_detect_headset(rt5651->component);
- rt5651_disable_micbias1_for_ovcd(rt5651->component);
+ if (!rt5651_jack_inserted(component)) {
+ /* Jack removed, or spurious IRQ? */
+ if (rt5651->hp_jack->status & SND_JACK_HEADPHONE) {
+ if (rt5651->hp_jack->status & SND_JACK_MICROPHONE) {
+ cancel_delayed_work_sync(&rt5651->bp_work);
+ rt5651_disable_micbias1_ovcd_irq(component);
+ rt5651_disable_micbias1_for_ovcd(component);
+ }
+ snd_soc_jack_report(rt5651->hp_jack, 0,
+ SND_JACK_HEADSET | SND_JACK_BTN_0);
+ dev_dbg(component->dev, "jack unplugged\n");
+ }
+ } else if (!(rt5651->hp_jack->status & SND_JACK_HEADPHONE)) {
+ /* Jack inserted */
+ WARN_ON(rt5651->ovcd_irq_enabled);
+ rt5651_enable_micbias1_for_ovcd(component);
+ report = rt5651_detect_headset(component);
+ if (report == SND_JACK_HEADSET) {
+ /* Enable ovcd IRQ for button press detect. */
+ rt5651_enable_micbias1_ovcd_irq(component);
+ } else {
+ /* No more need for overcurrent detect. */
+ rt5651_disable_micbias1_for_ovcd(component);
+ }
+ dev_dbg(component->dev, "detect report %#02x\n", report);
+ snd_soc_jack_report(rt5651->hp_jack, report, SND_JACK_HEADSET);
+ } else if (rt5651->ovcd_irq_enabled && rt5651_micbias1_ovcd(component)) {
+ dev_dbg(component->dev, "OVCD IRQ\n");
+
+ /*
+ * The ovcd IRQ keeps firing while the button is pressed, so
+ * we disable it and start polling the button until released.
+ *
+ * The disable will make the IRQ pin 0 again and since we get
+ * IRQs on both edges (so as to detect both jack plugin and
+ * unplug) this means we will immediately get another IRQ.
+ * The ovcd_irq_enabled check above makes the 2ND IRQ a NOP.
+ */
+ rt5651_disable_micbias1_ovcd_irq(component);
+ rt5651_start_button_press_work(component);
+
+ /*
+ * If the jack-detect IRQ flag goes high (unplug) after our
+ * above rt5651_jack_inserted() check and before we have
+ * disabled the OVCD IRQ, the IRQ pin will stay high and as
+ * we react to edges, we miss the unplug event -> recheck.
+ */
+ queue_work(system_long_wq, &rt5651->jack_detect_work);
}
-
- snd_soc_jack_report(rt5651->hp_jack, report, SND_JACK_HEADSET);
}
static irqreturn_t rt5651_irq(int irq, void *data)
@@ -1701,6 +1832,7 @@ static void rt5651_cancel_work(void *data)
struct rt5651_priv *rt5651 = data;
cancel_work_sync(&rt5651->jack_detect_work);
+ cancel_delayed_work_sync(&rt5651->bp_work);
}
static void rt5651_enable_jack_detect(struct snd_soc_component *component,
@@ -1770,6 +1902,11 @@ static void rt5651_enable_jack_detect(struct snd_soc_component *component,
RT5651_MB1_OC_STKY_MASK, RT5651_MB1_OC_STKY_EN);
rt5651->hp_jack = hp_jack;
+ if (rt5651->hp_jack->status & SND_JACK_MICROPHONE) {
+ rt5651_enable_micbias1_for_ovcd(component);
+ rt5651_enable_micbias1_ovcd_irq(component);
+ }
+
enable_irq(rt5651->irq);
/* sync initial jack state */
queue_work(system_power_efficient_wq, &rt5651->jack_detect_work);
@@ -1782,6 +1919,12 @@ static void rt5651_disable_jack_detect(struct snd_soc_component *component)
disable_irq(rt5651->irq);
rt5651_cancel_work(rt5651);
+ if (rt5651->hp_jack->status & SND_JACK_MICROPHONE) {
+ rt5651_disable_micbias1_ovcd_irq(component);
+ rt5651_disable_micbias1_for_ovcd(component);
+ snd_soc_jack_report(rt5651->hp_jack, 0, SND_JACK_BTN_0);
+ }
+
rt5651->hp_jack = NULL;
}
@@ -2046,6 +2189,7 @@ static int rt5651_i2c_probe(struct i2c_client *i2c,
rt5651->irq = i2c->irq;
rt5651->hp_mute = 1;
+ INIT_DELAYED_WORK(&rt5651->bp_work, rt5651_button_press_work);
INIT_WORK(&rt5651->jack_detect_work, rt5651_jack_detect_work);
/* Make sure work is stopped on probe-error / remove */
diff --git a/sound/soc/codecs/rt5651.h b/sound/soc/codecs/rt5651.h
index 3a0968c53fde..ac6de6fb5414 100644
--- a/sound/soc/codecs/rt5651.h
+++ b/sound/soc/codecs/rt5651.h
@@ -2071,8 +2071,16 @@ struct rt5651_pll_code {
struct rt5651_priv {
struct snd_soc_component *component;
struct regmap *regmap;
+ /* Jack and button detect data */
struct snd_soc_jack *hp_jack;
struct work_struct jack_detect_work;
+ struct delayed_work bp_work;
+ bool ovcd_irq_enabled;
+ bool pressed;
+ bool press_reported;
+ int press_count;
+ int release_count;
+ int poll_count;
unsigned int jd_src;
unsigned int ovcd_th;
unsigned int ovcd_sf;
--
2.17.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 4/5] ASoC: Intel: bytcr_rt5651: Disable jack-detect over suspend/resume
2018-07-04 22:59 [PATCH 1/5] ASoC: rt5651: Fix workqueue cancel vs irq free race on remove Hans de Goede
2018-07-04 22:59 ` [PATCH 2/5] ASoC: rt5651: Allow disabling jack-detect by calling set_jack(NULL) Hans de Goede
2018-07-04 22:59 ` [PATCH 3/5] ASoC: rt5651: Add button press support Hans de Goede
@ 2018-07-04 22:59 ` Hans de Goede
2018-07-09 22:57 ` Pierre-Louis Bossart
2018-07-10 18:16 ` Applied "ASoC: Intel: bytcr_rt5651: Disable jack-detect over suspend/resume" to the asoc tree Mark Brown
2018-07-04 22:59 ` [PATCH 5/5] ASoC: Intel: bytcr_rt5651: Reporting button presses Hans de Goede
2018-07-10 18:16 ` Applied "ASoC: rt5651: Fix workqueue cancel vs irq free race on remove" " Mark Brown
4 siblings, 2 replies; 12+ messages in thread
From: Hans de Goede @ 2018-07-04 22:59 UTC (permalink / raw)
To: Liam Girdwood, Mark Brown, Bard Liao, Oder Chiou
Cc: Hans de Goede, alsa-devel, Pierre-Louis Bossart, Carlo Caione
Disable jack-detection and thus the codec IRQ over suspend/resume.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
sound/soc/intel/boards/bytcr_rt5651.c | 49 ++++++++++++++++++++++++---
1 file changed, 44 insertions(+), 5 deletions(-)
diff --git a/sound/soc/intel/boards/bytcr_rt5651.c b/sound/soc/intel/boards/bytcr_rt5651.c
index 5301205496be..2a8f86dfe4cb 100644
--- a/sound/soc/intel/boards/bytcr_rt5651.c
+++ b/sound/soc/intel/boards/bytcr_rt5651.c
@@ -676,6 +676,48 @@ static struct snd_soc_dai_link byt_rt5651_dais[] = {
};
/* SoC card */
+static char byt_rt5651_codec_name[SND_ACPI_I2C_ID_LEN];
+static char byt_rt5651_codec_aif_name[12]; /* = "rt5651-aif[1|2]" */
+static char byt_rt5651_cpu_dai_name[10]; /* = "ssp[0|2]-port" */
+static char byt_rt5651_long_name[40]; /* = "bytcr-rt5651-*-mic[-swapped-hp]" */
+
+static int byt_rt5651_suspend(struct snd_soc_card *card)
+{
+ struct snd_soc_component *component;
+
+ if (!BYT_RT5651_JDSRC(byt_rt5651_quirk))
+ return 0;
+
+ list_for_each_entry(component, &card->component_dev_list, card_list) {
+ if (!strcmp(component->name, byt_rt5651_codec_name)) {
+ dev_dbg(component->dev, "disabling jack detect before suspend\n");
+ snd_soc_component_set_jack(component, NULL, NULL);
+ break;
+ }
+ }
+
+ return 0;
+}
+
+static int byt_rt5651_resume(struct snd_soc_card *card)
+{
+ struct byt_rt5651_private *priv = snd_soc_card_get_drvdata(card);
+ struct snd_soc_component *component;
+
+ if (!BYT_RT5651_JDSRC(byt_rt5651_quirk))
+ return 0;
+
+ list_for_each_entry(component, &card->component_dev_list, card_list) {
+ if (!strcmp(component->name, byt_rt5651_codec_name)) {
+ dev_dbg(component->dev, "re-enabling jack detect after resume\n");
+ snd_soc_component_set_jack(component, &priv->jack, NULL);
+ break;
+ }
+ }
+
+ return 0;
+}
+
static struct snd_soc_card byt_rt5651_card = {
.name = "bytcr-rt5651",
.owner = THIS_MODULE,
@@ -686,13 +728,10 @@ static struct snd_soc_card byt_rt5651_card = {
.dapm_routes = byt_rt5651_audio_map,
.num_dapm_routes = ARRAY_SIZE(byt_rt5651_audio_map),
.fully_routed = true,
+ .suspend_pre = byt_rt5651_suspend,
+ .resume_post = byt_rt5651_resume,
};
-static char byt_rt5651_codec_name[SND_ACPI_I2C_ID_LEN];
-static char byt_rt5651_codec_aif_name[12]; /* = "rt5651-aif[1|2]" */
-static char byt_rt5651_cpu_dai_name[10]; /* = "ssp[0|2]-port" */
-static char byt_rt5651_long_name[40]; /* = "bytcr-rt5651-*-mic[-swapped-hp]" */
-
static const struct x86_cpu_id baytrail_cpu_ids[] = {
{ X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_SILVERMONT1 }, /* Valleyview */
{}
--
2.17.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 5/5] ASoC: Intel: bytcr_rt5651: Reporting button presses
2018-07-04 22:59 [PATCH 1/5] ASoC: rt5651: Fix workqueue cancel vs irq free race on remove Hans de Goede
` (2 preceding siblings ...)
2018-07-04 22:59 ` [PATCH 4/5] ASoC: Intel: bytcr_rt5651: Disable jack-detect over suspend/resume Hans de Goede
@ 2018-07-04 22:59 ` Hans de Goede
2018-07-09 22:58 ` Pierre-Louis Bossart
2018-07-10 18:16 ` Applied "ASoC: Intel: bytcr_rt5651: Reporting button presses" to the asoc tree Mark Brown
2018-07-10 18:16 ` Applied "ASoC: rt5651: Fix workqueue cancel vs irq free race on remove" " Mark Brown
4 siblings, 2 replies; 12+ messages in thread
From: Hans de Goede @ 2018-07-04 22:59 UTC (permalink / raw)
To: Liam Girdwood, Mark Brown, Bard Liao, Oder Chiou
Cc: Hans de Goede, alsa-devel, Pierre-Louis Bossart, Carlo Caione
Enable reporting of button presses now that the codec driver recently has
gotten support for this.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
sound/soc/intel/boards/bytcr_rt5651.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/sound/soc/intel/boards/bytcr_rt5651.c b/sound/soc/intel/boards/bytcr_rt5651.c
index 2a8f86dfe4cb..b687043c8425 100644
--- a/sound/soc/intel/boards/bytcr_rt5651.c
+++ b/sound/soc/intel/boards/bytcr_rt5651.c
@@ -26,6 +26,7 @@
#include <linux/clk.h>
#include <linux/device.h>
#include <linux/dmi.h>
+#include <linux/input.h>
#include <linux/gpio/consumer.h>
#include <linux/gpio/machine.h>
#include <linux/slab.h>
@@ -531,13 +532,17 @@ static int byt_rt5651_init(struct snd_soc_pcm_runtime *runtime)
if (BYT_RT5651_JDSRC(byt_rt5651_quirk)) {
ret = snd_soc_card_jack_new(runtime->card, "Headset",
- SND_JACK_HEADSET, &priv->jack,
- bytcr_jack_pins, ARRAY_SIZE(bytcr_jack_pins));
+ SND_JACK_HEADSET | SND_JACK_BTN_0,
+ &priv->jack, bytcr_jack_pins,
+ ARRAY_SIZE(bytcr_jack_pins));
if (ret) {
dev_err(runtime->dev, "jack creation failed %d\n", ret);
return ret;
}
+ snd_jack_set_key(priv->jack.jack, SND_JACK_BTN_0,
+ KEY_PLAYPAUSE);
+
ret = snd_soc_component_set_jack(codec, &priv->jack, NULL);
if (ret)
return ret;
--
2.17.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH 4/5] ASoC: Intel: bytcr_rt5651: Disable jack-detect over suspend/resume
2018-07-04 22:59 ` [PATCH 4/5] ASoC: Intel: bytcr_rt5651: Disable jack-detect over suspend/resume Hans de Goede
@ 2018-07-09 22:57 ` Pierre-Louis Bossart
2018-07-10 18:16 ` Applied "ASoC: Intel: bytcr_rt5651: Disable jack-detect over suspend/resume" to the asoc tree Mark Brown
1 sibling, 0 replies; 12+ messages in thread
From: Pierre-Louis Bossart @ 2018-07-09 22:57 UTC (permalink / raw)
To: Hans de Goede, Liam Girdwood, Mark Brown, Bard Liao, Oder Chiou
Cc: alsa-devel, Carlo Caione
On 07/04/2018 05:59 PM, Hans de Goede wrote:
> Disable jack-detection and thus the codec IRQ over suspend/resume.
>
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Acked-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
> ---
> sound/soc/intel/boards/bytcr_rt5651.c | 49 ++++++++++++++++++++++++---
> 1 file changed, 44 insertions(+), 5 deletions(-)
>
> diff --git a/sound/soc/intel/boards/bytcr_rt5651.c b/sound/soc/intel/boards/bytcr_rt5651.c
> index 5301205496be..2a8f86dfe4cb 100644
> --- a/sound/soc/intel/boards/bytcr_rt5651.c
> +++ b/sound/soc/intel/boards/bytcr_rt5651.c
> @@ -676,6 +676,48 @@ static struct snd_soc_dai_link byt_rt5651_dais[] = {
> };
>
> /* SoC card */
> +static char byt_rt5651_codec_name[SND_ACPI_I2C_ID_LEN];
> +static char byt_rt5651_codec_aif_name[12]; /* = "rt5651-aif[1|2]" */
> +static char byt_rt5651_cpu_dai_name[10]; /* = "ssp[0|2]-port" */
> +static char byt_rt5651_long_name[40]; /* = "bytcr-rt5651-*-mic[-swapped-hp]" */
> +
> +static int byt_rt5651_suspend(struct snd_soc_card *card)
> +{
> + struct snd_soc_component *component;
> +
> + if (!BYT_RT5651_JDSRC(byt_rt5651_quirk))
> + return 0;
> +
> + list_for_each_entry(component, &card->component_dev_list, card_list) {
> + if (!strcmp(component->name, byt_rt5651_codec_name)) {
> + dev_dbg(component->dev, "disabling jack detect before suspend\n");
> + snd_soc_component_set_jack(component, NULL, NULL);
> + break;
> + }
> + }
> +
> + return 0;
> +}
> +
> +static int byt_rt5651_resume(struct snd_soc_card *card)
> +{
> + struct byt_rt5651_private *priv = snd_soc_card_get_drvdata(card);
> + struct snd_soc_component *component;
> +
> + if (!BYT_RT5651_JDSRC(byt_rt5651_quirk))
> + return 0;
> +
> + list_for_each_entry(component, &card->component_dev_list, card_list) {
> + if (!strcmp(component->name, byt_rt5651_codec_name)) {
> + dev_dbg(component->dev, "re-enabling jack detect after resume\n");
> + snd_soc_component_set_jack(component, &priv->jack, NULL);
> + break;
> + }
> + }
> +
> + return 0;
> +}
> +
> static struct snd_soc_card byt_rt5651_card = {
> .name = "bytcr-rt5651",
> .owner = THIS_MODULE,
> @@ -686,13 +728,10 @@ static struct snd_soc_card byt_rt5651_card = {
> .dapm_routes = byt_rt5651_audio_map,
> .num_dapm_routes = ARRAY_SIZE(byt_rt5651_audio_map),
> .fully_routed = true,
> + .suspend_pre = byt_rt5651_suspend,
> + .resume_post = byt_rt5651_resume,
> };
>
> -static char byt_rt5651_codec_name[SND_ACPI_I2C_ID_LEN];
> -static char byt_rt5651_codec_aif_name[12]; /* = "rt5651-aif[1|2]" */
> -static char byt_rt5651_cpu_dai_name[10]; /* = "ssp[0|2]-port" */
> -static char byt_rt5651_long_name[40]; /* = "bytcr-rt5651-*-mic[-swapped-hp]" */
> -
> static const struct x86_cpu_id baytrail_cpu_ids[] = {
> { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_SILVERMONT1 }, /* Valleyview */
> {}
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 5/5] ASoC: Intel: bytcr_rt5651: Reporting button presses
2018-07-04 22:59 ` [PATCH 5/5] ASoC: Intel: bytcr_rt5651: Reporting button presses Hans de Goede
@ 2018-07-09 22:58 ` Pierre-Louis Bossart
2018-07-10 18:16 ` Applied "ASoC: Intel: bytcr_rt5651: Reporting button presses" to the asoc tree Mark Brown
1 sibling, 0 replies; 12+ messages in thread
From: Pierre-Louis Bossart @ 2018-07-09 22:58 UTC (permalink / raw)
To: Hans de Goede, Liam Girdwood, Mark Brown, Bard Liao, Oder Chiou
Cc: alsa-devel, Carlo Caione
On 07/04/2018 05:59 PM, Hans de Goede wrote:
> Enable reporting of button presses now that the codec driver recently has
> gotten support for this.
>
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Acked-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
> ---
> sound/soc/intel/boards/bytcr_rt5651.c | 9 +++++++--
> 1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/sound/soc/intel/boards/bytcr_rt5651.c b/sound/soc/intel/boards/bytcr_rt5651.c
> index 2a8f86dfe4cb..b687043c8425 100644
> --- a/sound/soc/intel/boards/bytcr_rt5651.c
> +++ b/sound/soc/intel/boards/bytcr_rt5651.c
> @@ -26,6 +26,7 @@
> #include <linux/clk.h>
> #include <linux/device.h>
> #include <linux/dmi.h>
> +#include <linux/input.h>
> #include <linux/gpio/consumer.h>
> #include <linux/gpio/machine.h>
> #include <linux/slab.h>
> @@ -531,13 +532,17 @@ static int byt_rt5651_init(struct snd_soc_pcm_runtime *runtime)
>
> if (BYT_RT5651_JDSRC(byt_rt5651_quirk)) {
> ret = snd_soc_card_jack_new(runtime->card, "Headset",
> - SND_JACK_HEADSET, &priv->jack,
> - bytcr_jack_pins, ARRAY_SIZE(bytcr_jack_pins));
> + SND_JACK_HEADSET | SND_JACK_BTN_0,
> + &priv->jack, bytcr_jack_pins,
> + ARRAY_SIZE(bytcr_jack_pins));
> if (ret) {
> dev_err(runtime->dev, "jack creation failed %d\n", ret);
> return ret;
> }
>
> + snd_jack_set_key(priv->jack.jack, SND_JACK_BTN_0,
> + KEY_PLAYPAUSE);
> +
> ret = snd_soc_component_set_jack(codec, &priv->jack, NULL);
> if (ret)
> return ret;
^ permalink raw reply [flat|nested] 12+ messages in thread
* Applied "ASoC: Intel: bytcr_rt5651: Reporting button presses" to the asoc tree
2018-07-04 22:59 ` [PATCH 5/5] ASoC: Intel: bytcr_rt5651: Reporting button presses Hans de Goede
2018-07-09 22:58 ` Pierre-Louis Bossart
@ 2018-07-10 18:16 ` Mark Brown
1 sibling, 0 replies; 12+ messages in thread
From: Mark Brown @ 2018-07-10 18:16 UTC (permalink / raw)
To: Hans de Goede
Cc: Oder Chiou, alsa-devel, Pierre-Louis Bossart, Liam Girdwood,
Mark Brown, Carlo Caione, Bard Liao
The patch
ASoC: Intel: bytcr_rt5651: Reporting button presses
has been applied to the asoc tree at
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git
All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying
to this mail.
Thanks,
Mark
>From caed9d636e857997e923dfe473b9310de645d916 Mon Sep 17 00:00:00 2001
From: Hans de Goede <hdegoede@redhat.com>
Date: Thu, 5 Jul 2018 00:59:35 +0200
Subject: [PATCH] ASoC: Intel: bytcr_rt5651: Reporting button presses
Enable reporting of button presses now that the codec driver recently has
gotten support for this.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Acked-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
---
sound/soc/intel/boards/bytcr_rt5651.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/sound/soc/intel/boards/bytcr_rt5651.c b/sound/soc/intel/boards/bytcr_rt5651.c
index 2a8f86dfe4cb..b687043c8425 100644
--- a/sound/soc/intel/boards/bytcr_rt5651.c
+++ b/sound/soc/intel/boards/bytcr_rt5651.c
@@ -26,6 +26,7 @@
#include <linux/clk.h>
#include <linux/device.h>
#include <linux/dmi.h>
+#include <linux/input.h>
#include <linux/gpio/consumer.h>
#include <linux/gpio/machine.h>
#include <linux/slab.h>
@@ -531,13 +532,17 @@ static int byt_rt5651_init(struct snd_soc_pcm_runtime *runtime)
if (BYT_RT5651_JDSRC(byt_rt5651_quirk)) {
ret = snd_soc_card_jack_new(runtime->card, "Headset",
- SND_JACK_HEADSET, &priv->jack,
- bytcr_jack_pins, ARRAY_SIZE(bytcr_jack_pins));
+ SND_JACK_HEADSET | SND_JACK_BTN_0,
+ &priv->jack, bytcr_jack_pins,
+ ARRAY_SIZE(bytcr_jack_pins));
if (ret) {
dev_err(runtime->dev, "jack creation failed %d\n", ret);
return ret;
}
+ snd_jack_set_key(priv->jack.jack, SND_JACK_BTN_0,
+ KEY_PLAYPAUSE);
+
ret = snd_soc_component_set_jack(codec, &priv->jack, NULL);
if (ret)
return ret;
--
2.18.0.rc2
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Applied "ASoC: Intel: bytcr_rt5651: Disable jack-detect over suspend/resume" to the asoc tree
2018-07-04 22:59 ` [PATCH 4/5] ASoC: Intel: bytcr_rt5651: Disable jack-detect over suspend/resume Hans de Goede
2018-07-09 22:57 ` Pierre-Louis Bossart
@ 2018-07-10 18:16 ` Mark Brown
1 sibling, 0 replies; 12+ messages in thread
From: Mark Brown @ 2018-07-10 18:16 UTC (permalink / raw)
To: Hans de Goede
Cc: Oder Chiou, alsa-devel, Pierre-Louis Bossart, Liam Girdwood,
Mark Brown, Carlo Caione, Bard Liao
The patch
ASoC: Intel: bytcr_rt5651: Disable jack-detect over suspend/resume
has been applied to the asoc tree at
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git
All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying
to this mail.
Thanks,
Mark
>From b91f432cbc3326f715b8c3f02ff4066ab398833f Mon Sep 17 00:00:00 2001
From: Hans de Goede <hdegoede@redhat.com>
Date: Thu, 5 Jul 2018 00:59:34 +0200
Subject: [PATCH] ASoC: Intel: bytcr_rt5651: Disable jack-detect over
suspend/resume
Disable jack-detection and thus the codec IRQ over suspend/resume.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Acked-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
---
sound/soc/intel/boards/bytcr_rt5651.c | 49 ++++++++++++++++++++++++---
1 file changed, 44 insertions(+), 5 deletions(-)
diff --git a/sound/soc/intel/boards/bytcr_rt5651.c b/sound/soc/intel/boards/bytcr_rt5651.c
index 5301205496be..2a8f86dfe4cb 100644
--- a/sound/soc/intel/boards/bytcr_rt5651.c
+++ b/sound/soc/intel/boards/bytcr_rt5651.c
@@ -676,6 +676,48 @@ static struct snd_soc_dai_link byt_rt5651_dais[] = {
};
/* SoC card */
+static char byt_rt5651_codec_name[SND_ACPI_I2C_ID_LEN];
+static char byt_rt5651_codec_aif_name[12]; /* = "rt5651-aif[1|2]" */
+static char byt_rt5651_cpu_dai_name[10]; /* = "ssp[0|2]-port" */
+static char byt_rt5651_long_name[40]; /* = "bytcr-rt5651-*-mic[-swapped-hp]" */
+
+static int byt_rt5651_suspend(struct snd_soc_card *card)
+{
+ struct snd_soc_component *component;
+
+ if (!BYT_RT5651_JDSRC(byt_rt5651_quirk))
+ return 0;
+
+ list_for_each_entry(component, &card->component_dev_list, card_list) {
+ if (!strcmp(component->name, byt_rt5651_codec_name)) {
+ dev_dbg(component->dev, "disabling jack detect before suspend\n");
+ snd_soc_component_set_jack(component, NULL, NULL);
+ break;
+ }
+ }
+
+ return 0;
+}
+
+static int byt_rt5651_resume(struct snd_soc_card *card)
+{
+ struct byt_rt5651_private *priv = snd_soc_card_get_drvdata(card);
+ struct snd_soc_component *component;
+
+ if (!BYT_RT5651_JDSRC(byt_rt5651_quirk))
+ return 0;
+
+ list_for_each_entry(component, &card->component_dev_list, card_list) {
+ if (!strcmp(component->name, byt_rt5651_codec_name)) {
+ dev_dbg(component->dev, "re-enabling jack detect after resume\n");
+ snd_soc_component_set_jack(component, &priv->jack, NULL);
+ break;
+ }
+ }
+
+ return 0;
+}
+
static struct snd_soc_card byt_rt5651_card = {
.name = "bytcr-rt5651",
.owner = THIS_MODULE,
@@ -686,13 +728,10 @@ static struct snd_soc_card byt_rt5651_card = {
.dapm_routes = byt_rt5651_audio_map,
.num_dapm_routes = ARRAY_SIZE(byt_rt5651_audio_map),
.fully_routed = true,
+ .suspend_pre = byt_rt5651_suspend,
+ .resume_post = byt_rt5651_resume,
};
-static char byt_rt5651_codec_name[SND_ACPI_I2C_ID_LEN];
-static char byt_rt5651_codec_aif_name[12]; /* = "rt5651-aif[1|2]" */
-static char byt_rt5651_cpu_dai_name[10]; /* = "ssp[0|2]-port" */
-static char byt_rt5651_long_name[40]; /* = "bytcr-rt5651-*-mic[-swapped-hp]" */
-
static const struct x86_cpu_id baytrail_cpu_ids[] = {
{ X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_SILVERMONT1 }, /* Valleyview */
{}
--
2.18.0.rc2
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Applied "ASoC: rt5651: Add button press support" to the asoc tree
2018-07-04 22:59 ` [PATCH 3/5] ASoC: rt5651: Add button press support Hans de Goede
@ 2018-07-10 18:16 ` Mark Brown
0 siblings, 0 replies; 12+ messages in thread
From: Mark Brown @ 2018-07-10 18:16 UTC (permalink / raw)
To: Hans de Goede
Cc: Oder Chiou, alsa-devel, Pierre-Louis Bossart, Liam Girdwood,
Mark Brown, Carlo Caione, Bard Liao
The patch
ASoC: rt5651: Add button press support
has been applied to the asoc tree at
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git
All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying
to this mail.
Thanks,
Mark
>From df1569f2006b157caa944367d0d431eb4ea08624 Mon Sep 17 00:00:00 2001
From: Hans de Goede <hdegoede@redhat.com>
Date: Thu, 5 Jul 2018 00:59:33 +0200
Subject: [PATCH] ASoC: rt5651: Add button press support
Enable button press detection for headsets by using the ovcd IRQ to get
notified of button presses.
This is modelled after (almost exactly copied from) the button press code
for the rt5640 which has identical ovcd hardware.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
---
sound/soc/codecs/rt5651.c | 158 ++++++++++++++++++++++++++++++++++++--
sound/soc/codecs/rt5651.h | 8 ++
2 files changed, 159 insertions(+), 7 deletions(-)
diff --git a/sound/soc/codecs/rt5651.c b/sound/soc/codecs/rt5651.c
index 40bd1e70fee7..0462049e739c 100644
--- a/sound/soc/codecs/rt5651.c
+++ b/sound/soc/codecs/rt5651.c
@@ -1581,6 +1581,24 @@ static void rt5651_disable_micbias1_for_ovcd(struct snd_soc_component *component
snd_soc_dapm_mutex_unlock(dapm);
}
+static void rt5651_enable_micbias1_ovcd_irq(struct snd_soc_component *component)
+{
+ struct rt5651_priv *rt5651 = snd_soc_component_get_drvdata(component);
+
+ snd_soc_component_update_bits(component, RT5651_IRQ_CTRL2,
+ RT5651_IRQ_MB1_OC_MASK, RT5651_IRQ_MB1_OC_NOR);
+ rt5651->ovcd_irq_enabled = true;
+}
+
+static void rt5651_disable_micbias1_ovcd_irq(struct snd_soc_component *component)
+{
+ struct rt5651_priv *rt5651 = snd_soc_component_get_drvdata(component);
+
+ snd_soc_component_update_bits(component, RT5651_IRQ_CTRL2,
+ RT5651_IRQ_MB1_OC_MASK, RT5651_IRQ_MB1_OC_BP);
+ rt5651->ovcd_irq_enabled = false;
+}
+
static void rt5651_clear_micbias1_ovcd(struct snd_soc_component *component)
{
snd_soc_component_update_bits(component, RT5651_IRQ_CTRL2,
@@ -1622,10 +1640,80 @@ static bool rt5651_jack_inserted(struct snd_soc_component *component)
return val == 0;
}
-/* Jack detect timings */
+/* Jack detect and button-press timings */
#define JACK_SETTLE_TIME 100 /* milli seconds */
#define JACK_DETECT_COUNT 5
#define JACK_DETECT_MAXCOUNT 20 /* Aprox. 2 seconds worth of tries */
+#define JACK_UNPLUG_TIME 80 /* milli seconds */
+#define BP_POLL_TIME 10 /* milli seconds */
+#define BP_POLL_MAXCOUNT 200 /* assume something is wrong after this */
+#define BP_THRESHOLD 3
+
+static void rt5651_start_button_press_work(struct snd_soc_component *component)
+{
+ struct rt5651_priv *rt5651 = snd_soc_component_get_drvdata(component);
+
+ rt5651->poll_count = 0;
+ rt5651->press_count = 0;
+ rt5651->release_count = 0;
+ rt5651->pressed = false;
+ rt5651->press_reported = false;
+ rt5651_clear_micbias1_ovcd(component);
+ schedule_delayed_work(&rt5651->bp_work, msecs_to_jiffies(BP_POLL_TIME));
+}
+
+static void rt5651_button_press_work(struct work_struct *work)
+{
+ struct rt5651_priv *rt5651 =
+ container_of(work, struct rt5651_priv, bp_work.work);
+ struct snd_soc_component *component = rt5651->component;
+
+ /* Check the jack was not removed underneath us */
+ if (!rt5651_jack_inserted(component))
+ return;
+
+ if (rt5651_micbias1_ovcd(component)) {
+ rt5651->release_count = 0;
+ rt5651->press_count++;
+ /* Remember till after JACK_UNPLUG_TIME wait */
+ if (rt5651->press_count >= BP_THRESHOLD)
+ rt5651->pressed = true;
+ rt5651_clear_micbias1_ovcd(component);
+ } else {
+ rt5651->press_count = 0;
+ rt5651->release_count++;
+ }
+
+ /*
+ * The pins get temporarily shorted on jack unplug, so we poll for
+ * at least JACK_UNPLUG_TIME milli-seconds before reporting a press.
+ */
+ rt5651->poll_count++;
+ if (rt5651->poll_count < (JACK_UNPLUG_TIME / BP_POLL_TIME)) {
+ schedule_delayed_work(&rt5651->bp_work,
+ msecs_to_jiffies(BP_POLL_TIME));
+ return;
+ }
+
+ if (rt5651->pressed && !rt5651->press_reported) {
+ dev_dbg(component->dev, "headset button press\n");
+ snd_soc_jack_report(rt5651->hp_jack, SND_JACK_BTN_0,
+ SND_JACK_BTN_0);
+ rt5651->press_reported = true;
+ }
+
+ if (rt5651->release_count >= BP_THRESHOLD) {
+ if (rt5651->press_reported) {
+ dev_dbg(component->dev, "headset button release\n");
+ snd_soc_jack_report(rt5651->hp_jack, 0, SND_JACK_BTN_0);
+ }
+ /* Re-enable OVCD IRQ to detect next press */
+ rt5651_enable_micbias1_ovcd_irq(component);
+ return; /* Stop polling */
+ }
+
+ schedule_delayed_work(&rt5651->bp_work, msecs_to_jiffies(BP_POLL_TIME));
+}
static int rt5651_detect_headset(struct snd_soc_component *component)
{
@@ -1676,15 +1764,58 @@ static void rt5651_jack_detect_work(struct work_struct *work)
{
struct rt5651_priv *rt5651 =
container_of(work, struct rt5651_priv, jack_detect_work);
+ struct snd_soc_component *component = rt5651->component;
int report = 0;
- if (rt5651_jack_inserted(rt5651->component)) {
- rt5651_enable_micbias1_for_ovcd(rt5651->component);
- report = rt5651_detect_headset(rt5651->component);
- rt5651_disable_micbias1_for_ovcd(rt5651->component);
+ if (!rt5651_jack_inserted(component)) {
+ /* Jack removed, or spurious IRQ? */
+ if (rt5651->hp_jack->status & SND_JACK_HEADPHONE) {
+ if (rt5651->hp_jack->status & SND_JACK_MICROPHONE) {
+ cancel_delayed_work_sync(&rt5651->bp_work);
+ rt5651_disable_micbias1_ovcd_irq(component);
+ rt5651_disable_micbias1_for_ovcd(component);
+ }
+ snd_soc_jack_report(rt5651->hp_jack, 0,
+ SND_JACK_HEADSET | SND_JACK_BTN_0);
+ dev_dbg(component->dev, "jack unplugged\n");
+ }
+ } else if (!(rt5651->hp_jack->status & SND_JACK_HEADPHONE)) {
+ /* Jack inserted */
+ WARN_ON(rt5651->ovcd_irq_enabled);
+ rt5651_enable_micbias1_for_ovcd(component);
+ report = rt5651_detect_headset(component);
+ if (report == SND_JACK_HEADSET) {
+ /* Enable ovcd IRQ for button press detect. */
+ rt5651_enable_micbias1_ovcd_irq(component);
+ } else {
+ /* No more need for overcurrent detect. */
+ rt5651_disable_micbias1_for_ovcd(component);
+ }
+ dev_dbg(component->dev, "detect report %#02x\n", report);
+ snd_soc_jack_report(rt5651->hp_jack, report, SND_JACK_HEADSET);
+ } else if (rt5651->ovcd_irq_enabled && rt5651_micbias1_ovcd(component)) {
+ dev_dbg(component->dev, "OVCD IRQ\n");
+
+ /*
+ * The ovcd IRQ keeps firing while the button is pressed, so
+ * we disable it and start polling the button until released.
+ *
+ * The disable will make the IRQ pin 0 again and since we get
+ * IRQs on both edges (so as to detect both jack plugin and
+ * unplug) this means we will immediately get another IRQ.
+ * The ovcd_irq_enabled check above makes the 2ND IRQ a NOP.
+ */
+ rt5651_disable_micbias1_ovcd_irq(component);
+ rt5651_start_button_press_work(component);
+
+ /*
+ * If the jack-detect IRQ flag goes high (unplug) after our
+ * above rt5651_jack_inserted() check and before we have
+ * disabled the OVCD IRQ, the IRQ pin will stay high and as
+ * we react to edges, we miss the unplug event -> recheck.
+ */
+ queue_work(system_long_wq, &rt5651->jack_detect_work);
}
-
- snd_soc_jack_report(rt5651->hp_jack, report, SND_JACK_HEADSET);
}
static irqreturn_t rt5651_irq(int irq, void *data)
@@ -1701,6 +1832,7 @@ static void rt5651_cancel_work(void *data)
struct rt5651_priv *rt5651 = data;
cancel_work_sync(&rt5651->jack_detect_work);
+ cancel_delayed_work_sync(&rt5651->bp_work);
}
static void rt5651_enable_jack_detect(struct snd_soc_component *component,
@@ -1770,6 +1902,11 @@ static void rt5651_enable_jack_detect(struct snd_soc_component *component,
RT5651_MB1_OC_STKY_MASK, RT5651_MB1_OC_STKY_EN);
rt5651->hp_jack = hp_jack;
+ if (rt5651->hp_jack->status & SND_JACK_MICROPHONE) {
+ rt5651_enable_micbias1_for_ovcd(component);
+ rt5651_enable_micbias1_ovcd_irq(component);
+ }
+
enable_irq(rt5651->irq);
/* sync initial jack state */
queue_work(system_power_efficient_wq, &rt5651->jack_detect_work);
@@ -1782,6 +1919,12 @@ static void rt5651_disable_jack_detect(struct snd_soc_component *component)
disable_irq(rt5651->irq);
rt5651_cancel_work(rt5651);
+ if (rt5651->hp_jack->status & SND_JACK_MICROPHONE) {
+ rt5651_disable_micbias1_ovcd_irq(component);
+ rt5651_disable_micbias1_for_ovcd(component);
+ snd_soc_jack_report(rt5651->hp_jack, 0, SND_JACK_BTN_0);
+ }
+
rt5651->hp_jack = NULL;
}
@@ -2046,6 +2189,7 @@ static int rt5651_i2c_probe(struct i2c_client *i2c,
rt5651->irq = i2c->irq;
rt5651->hp_mute = 1;
+ INIT_DELAYED_WORK(&rt5651->bp_work, rt5651_button_press_work);
INIT_WORK(&rt5651->jack_detect_work, rt5651_jack_detect_work);
/* Make sure work is stopped on probe-error / remove */
diff --git a/sound/soc/codecs/rt5651.h b/sound/soc/codecs/rt5651.h
index 3a0968c53fde..ac6de6fb5414 100644
--- a/sound/soc/codecs/rt5651.h
+++ b/sound/soc/codecs/rt5651.h
@@ -2071,8 +2071,16 @@ struct rt5651_pll_code {
struct rt5651_priv {
struct snd_soc_component *component;
struct regmap *regmap;
+ /* Jack and button detect data */
struct snd_soc_jack *hp_jack;
struct work_struct jack_detect_work;
+ struct delayed_work bp_work;
+ bool ovcd_irq_enabled;
+ bool pressed;
+ bool press_reported;
+ int press_count;
+ int release_count;
+ int poll_count;
unsigned int jd_src;
unsigned int ovcd_th;
unsigned int ovcd_sf;
--
2.18.0.rc2
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Applied "ASoC: rt5651: Allow disabling jack-detect by calling set_jack(NULL)" to the asoc tree
2018-07-04 22:59 ` [PATCH 2/5] ASoC: rt5651: Allow disabling jack-detect by calling set_jack(NULL) Hans de Goede
@ 2018-07-10 18:16 ` Mark Brown
0 siblings, 0 replies; 12+ messages in thread
From: Mark Brown @ 2018-07-10 18:16 UTC (permalink / raw)
To: Hans de Goede
Cc: Oder Chiou, alsa-devel, Pierre-Louis Bossart, Liam Girdwood,
Mark Brown, Carlo Caione, Bard Liao
The patch
ASoC: rt5651: Allow disabling jack-detect by calling set_jack(NULL)
has been applied to the asoc tree at
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git
All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying
to this mail.
Thanks,
Mark
>From 34c906ddacd237511808fb2bbd941e6b91e9095a Mon Sep 17 00:00:00 2001
From: Hans de Goede <hdegoede@redhat.com>
Date: Thu, 5 Jul 2018 00:59:32 +0200
Subject: [PATCH] ASoC: rt5651: Allow disabling jack-detect by calling
set_jack(NULL)
Allow the machine driver to disable jack-detect over a suspend/resume by
calling snd_soc_component_set_jack(NULL).
Note this renames rt5651_set_jack, where all the jack-enable work was done
to rt5651_enable_jack_detect. This function can now no longer fail as it
does not request the IRQ anymore. It can still be passed an invalid jack
source, but that should never happen, so this is now logged and treated as
no jack source.
Cc: Carlo Caione <carlo@endlessm.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
---
sound/soc/codecs/rt5651.c | 55 +++++++++++++++++++++++++--------------
1 file changed, 36 insertions(+), 19 deletions(-)
diff --git a/sound/soc/codecs/rt5651.c b/sound/soc/codecs/rt5651.c
index 39d2c67cd064..40bd1e70fee7 100644
--- a/sound/soc/codecs/rt5651.c
+++ b/sound/soc/codecs/rt5651.c
@@ -1703,14 +1703,10 @@ static void rt5651_cancel_work(void *data)
cancel_work_sync(&rt5651->jack_detect_work);
}
-static int rt5651_set_jack(struct snd_soc_component *component,
- struct snd_soc_jack *hp_jack, void *data)
+static void rt5651_enable_jack_detect(struct snd_soc_component *component,
+ struct snd_soc_jack *hp_jack)
{
struct rt5651_priv *rt5651 = snd_soc_component_get_drvdata(component);
- int ret;
-
- if (!rt5651->irq)
- return -EINVAL;
/* IRQ output on GPIO1 */
snd_soc_component_update_bits(component, RT5651_GPIO_CTRL1,
@@ -1737,10 +1733,10 @@ static int rt5651_set_jack(struct snd_soc_component *component,
RT5651_JD2_IRQ_EN, RT5651_JD2_IRQ_EN);
break;
case RT5651_JD_NULL:
- return 0;
+ return;
default:
dev_err(component->dev, "Currently only JD1_1 / JD1_2 / JD2 are supported\n");
- return -EINVAL;
+ return;
}
/* Enable jack detect power */
@@ -1774,19 +1770,28 @@ static int rt5651_set_jack(struct snd_soc_component *component,
RT5651_MB1_OC_STKY_MASK, RT5651_MB1_OC_STKY_EN);
rt5651->hp_jack = hp_jack;
-
- ret = devm_request_threaded_irq(component->dev, rt5651->irq, NULL,
- rt5651_irq,
- IRQF_TRIGGER_RISING |
- IRQF_TRIGGER_FALLING |
- IRQF_ONESHOT, "rt5651", rt5651);
- if (ret) {
- dev_err(component->dev, "Failed to reguest IRQ: %d\n", ret);
- return ret;
- }
-
+ enable_irq(rt5651->irq);
/* sync initial jack state */
queue_work(system_power_efficient_wq, &rt5651->jack_detect_work);
+}
+
+static void rt5651_disable_jack_detect(struct snd_soc_component *component)
+{
+ struct rt5651_priv *rt5651 = snd_soc_component_get_drvdata(component);
+
+ disable_irq(rt5651->irq);
+ rt5651_cancel_work(rt5651);
+
+ rt5651->hp_jack = NULL;
+}
+
+static int rt5651_set_jack(struct snd_soc_component *component,
+ struct snd_soc_jack *jack, void *data)
+{
+ if (jack)
+ rt5651_enable_jack_detect(component, jack);
+ else
+ rt5651_disable_jack_detect(component);
return 0;
}
@@ -2048,6 +2053,18 @@ static int rt5651_i2c_probe(struct i2c_client *i2c,
if (ret)
return ret;
+ ret = devm_request_irq(&i2c->dev, rt5651->irq, rt5651_irq,
+ IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING
+ | IRQF_ONESHOT, "rt5651", rt5651);
+ if (ret == 0) {
+ /* Gets re-enabled by rt5651_set_jack() */
+ disable_irq(rt5651->irq);
+ } else {
+ dev_warn(&i2c->dev, "Failed to reguest IRQ %d: %d\n",
+ rt5651->irq, ret);
+ rt5651->irq = -ENXIO;
+ }
+
ret = devm_snd_soc_register_component(&i2c->dev,
&soc_component_dev_rt5651,
rt5651_dai, ARRAY_SIZE(rt5651_dai));
--
2.18.0.rc2
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Applied "ASoC: rt5651: Fix workqueue cancel vs irq free race on remove" to the asoc tree
2018-07-04 22:59 [PATCH 1/5] ASoC: rt5651: Fix workqueue cancel vs irq free race on remove Hans de Goede
` (3 preceding siblings ...)
2018-07-04 22:59 ` [PATCH 5/5] ASoC: Intel: bytcr_rt5651: Reporting button presses Hans de Goede
@ 2018-07-10 18:16 ` Mark Brown
4 siblings, 0 replies; 12+ messages in thread
From: Mark Brown @ 2018-07-10 18:16 UTC (permalink / raw)
To: Hans de Goede
Cc: Oder Chiou, alsa-devel, Pierre-Louis Bossart, Liam Girdwood,
Mark Brown, Carlo Caione, Bard Liao
The patch
ASoC: rt5651: Fix workqueue cancel vs irq free race on remove
has been applied to the asoc tree at
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git
All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying
to this mail.
Thanks,
Mark
>From 8d2d7bcdc1645dc243f7735278675b083c0e506c Mon Sep 17 00:00:00 2001
From: Hans de Goede <hdegoede@redhat.com>
Date: Thu, 5 Jul 2018 00:59:31 +0200
Subject: [PATCH] ASoC: rt5651: Fix workqueue cancel vs irq free race on remove
On removal we must free the IRQ *before* cancelling the jack-detect work,
so that the jack-detect work cannot be rescheduled by the IRQ.
Before this commit we were cancelling the jack-detect work from the
driver remove callback, while relying on devm to free the IRQ, which
happens after the remove callback.
This is the wrong order. This commit uses a devm-action to register
a devm callback which cancels the work, before requesting the IRQ
(devm tears things down in reverse order). This also allows us to
remove the now empty remove driver callback.
Cc: Carlo Caione <carlo@endlessm.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
---
sound/soc/codecs/rt5651.c | 22 ++++++++++++----------
1 file changed, 12 insertions(+), 10 deletions(-)
diff --git a/sound/soc/codecs/rt5651.c b/sound/soc/codecs/rt5651.c
index 6b5669f3e85d..39d2c67cd064 100644
--- a/sound/soc/codecs/rt5651.c
+++ b/sound/soc/codecs/rt5651.c
@@ -1696,6 +1696,13 @@ static irqreturn_t rt5651_irq(int irq, void *data)
return IRQ_HANDLED;
}
+static void rt5651_cancel_work(void *data)
+{
+ struct rt5651_priv *rt5651 = data;
+
+ cancel_work_sync(&rt5651->jack_detect_work);
+}
+
static int rt5651_set_jack(struct snd_soc_component *component,
struct snd_soc_jack *hp_jack, void *data)
{
@@ -2036,6 +2043,11 @@ static int rt5651_i2c_probe(struct i2c_client *i2c,
INIT_WORK(&rt5651->jack_detect_work, rt5651_jack_detect_work);
+ /* Make sure work is stopped on probe-error / remove */
+ ret = devm_add_action_or_reset(&i2c->dev, rt5651_cancel_work, rt5651);
+ if (ret)
+ return ret;
+
ret = devm_snd_soc_register_component(&i2c->dev,
&soc_component_dev_rt5651,
rt5651_dai, ARRAY_SIZE(rt5651_dai));
@@ -2043,15 +2055,6 @@ static int rt5651_i2c_probe(struct i2c_client *i2c,
return ret;
}
-static int rt5651_i2c_remove(struct i2c_client *i2c)
-{
- struct rt5651_priv *rt5651 = i2c_get_clientdata(i2c);
-
- cancel_work_sync(&rt5651->jack_detect_work);
-
- return 0;
-}
-
static struct i2c_driver rt5651_i2c_driver = {
.driver = {
.name = "rt5651",
@@ -2059,7 +2062,6 @@ static struct i2c_driver rt5651_i2c_driver = {
.of_match_table = of_match_ptr(rt5651_of_match),
},
.probe = rt5651_i2c_probe,
- .remove = rt5651_i2c_remove,
.id_table = rt5651_i2c_id,
};
module_i2c_driver(rt5651_i2c_driver);
--
2.18.0.rc2
^ permalink raw reply related [flat|nested] 12+ messages in thread
end of thread, other threads:[~2018-07-10 18:16 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-07-04 22:59 [PATCH 1/5] ASoC: rt5651: Fix workqueue cancel vs irq free race on remove Hans de Goede
2018-07-04 22:59 ` [PATCH 2/5] ASoC: rt5651: Allow disabling jack-detect by calling set_jack(NULL) Hans de Goede
2018-07-10 18:16 ` Applied "ASoC: rt5651: Allow disabling jack-detect by calling set_jack(NULL)" to the asoc tree Mark Brown
2018-07-04 22:59 ` [PATCH 3/5] ASoC: rt5651: Add button press support Hans de Goede
2018-07-10 18:16 ` Applied "ASoC: rt5651: Add button press support" to the asoc tree Mark Brown
2018-07-04 22:59 ` [PATCH 4/5] ASoC: Intel: bytcr_rt5651: Disable jack-detect over suspend/resume Hans de Goede
2018-07-09 22:57 ` Pierre-Louis Bossart
2018-07-10 18:16 ` Applied "ASoC: Intel: bytcr_rt5651: Disable jack-detect over suspend/resume" to the asoc tree Mark Brown
2018-07-04 22:59 ` [PATCH 5/5] ASoC: Intel: bytcr_rt5651: Reporting button presses Hans de Goede
2018-07-09 22:58 ` Pierre-Louis Bossart
2018-07-10 18:16 ` Applied "ASoC: Intel: bytcr_rt5651: Reporting button presses" to the asoc tree Mark Brown
2018-07-10 18:16 ` Applied "ASoC: rt5651: Fix workqueue cancel vs irq free race on remove" " Mark Brown
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).