Skip to content

Commit 164b7dd

Browse files
mstrozekbroonie
authored andcommitted
ASoC: cs42l43: Add jack delay debounce after suspend
Hardware reports jack absent after reset/suspension regardless of jack state, so introduce an additional delay only in suspension case to allow proper detection to take place after a short delay. Signed-off-by: Maciej Strozek <[email protected]> Reviewed-by: Charles Keepax <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 3d6c9dd commit 164b7dd

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

sound/soc/codecs/cs42l43-jack.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,15 +167,15 @@ int cs42l43_set_jack(struct snd_soc_component *component,
167167
autocontrol |= 0x3 << CS42L43_JACKDET_MODE_SHIFT;
168168

169169
ret = cs42l43_find_index(priv, "cirrus,tip-fall-db-ms", 500,
170-
NULL, cs42l43_accdet_db_ms,
170+
&priv->tip_fall_db_ms, cs42l43_accdet_db_ms,
171171
ARRAY_SIZE(cs42l43_accdet_db_ms));
172172
if (ret < 0)
173173
goto error;
174174

175175
tip_deb |= ret << CS42L43_TIPSENSE_FALLING_DB_TIME_SHIFT;
176176

177177
ret = cs42l43_find_index(priv, "cirrus,tip-rise-db-ms", 500,
178-
NULL, cs42l43_accdet_db_ms,
178+
&priv->tip_rise_db_ms, cs42l43_accdet_db_ms,
179179
ARRAY_SIZE(cs42l43_accdet_db_ms));
180180
if (ret < 0)
181181
goto error;
@@ -764,21 +764,28 @@ void cs42l43_tip_sense_work(struct work_struct *work)
764764
error:
765765
mutex_unlock(&priv->jack_lock);
766766

767+
priv->suspend_jack_debounce = false;
768+
767769
pm_runtime_mark_last_busy(priv->dev);
768770
pm_runtime_put_autosuspend(priv->dev);
769771
}
770772

771773
irqreturn_t cs42l43_tip_sense(int irq, void *data)
772774
{
773775
struct cs42l43_codec *priv = data;
776+
unsigned int db_delay = priv->tip_debounce_ms;
774777

775778
cancel_delayed_work(&priv->bias_sense_timeout);
776779
cancel_delayed_work(&priv->tip_sense_work);
777780
cancel_delayed_work(&priv->button_press_work);
778781
cancel_work(&priv->button_release_work);
779782

783+
// Ensure delay after suspend is long enough to avoid false detection
784+
if (priv->suspend_jack_debounce)
785+
db_delay += priv->tip_fall_db_ms + priv->tip_rise_db_ms;
786+
780787
queue_delayed_work(system_long_wq, &priv->tip_sense_work,
781-
msecs_to_jiffies(priv->tip_debounce_ms));
788+
msecs_to_jiffies(db_delay));
782789

783790
return IRQ_HANDLED;
784791
}

sound/soc/codecs/cs42l43.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2402,9 +2402,22 @@ static int cs42l43_codec_runtime_resume(struct device *dev)
24022402
return 0;
24032403
}
24042404

2405+
static int cs42l43_codec_runtime_force_suspend(struct device *dev)
2406+
{
2407+
struct cs42l43_codec *priv = dev_get_drvdata(dev);
2408+
2409+
dev_dbg(priv->dev, "Runtime suspend\n");
2410+
2411+
priv->suspend_jack_debounce = true;
2412+
2413+
pm_runtime_force_suspend(dev);
2414+
2415+
return 0;
2416+
}
2417+
24052418
static const struct dev_pm_ops cs42l43_codec_pm_ops = {
24062419
RUNTIME_PM_OPS(NULL, cs42l43_codec_runtime_resume, NULL)
2407-
SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, pm_runtime_force_resume)
2420+
SET_SYSTEM_SLEEP_PM_OPS(cs42l43_codec_runtime_force_suspend, pm_runtime_force_resume)
24082421
};
24092422

24102423
static const struct platform_device_id cs42l43_codec_id_table[] = {

sound/soc/codecs/cs42l43.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ struct cs42l43_codec {
7878

7979
bool use_ring_sense;
8080
unsigned int tip_debounce_ms;
81+
unsigned int tip_fall_db_ms;
82+
unsigned int tip_rise_db_ms;
8183
unsigned int bias_low;
8284
unsigned int bias_sense_ua;
8385
unsigned int bias_ramp_ms;
@@ -95,6 +97,7 @@ struct cs42l43_codec {
9597
bool button_detect_running;
9698
bool jack_present;
9799
int jack_override;
100+
bool suspend_jack_debounce;
98101

99102
struct work_struct hp_ilimit_work;
100103
struct delayed_work hp_ilimit_clear_work;

0 commit comments

Comments
 (0)