From 446c921ecedc6a354b8069f5a0b258e562a6efaf Mon Sep 17 00:00:00 2001 From: Janusz Krzysztofik Date: Tue, 12 May 2026 00:47:43 +0000 Subject: [PATCH 1/2] ASoC: ti: ams-delta: Stop (ab)using card->pop_time A flag is needed that tells the card driver if the codec has been initialized successfully over the modem's line discipline. Initially, codec->hw_write was used as the flag, but it was then dropped and the flag function associated with card->pop_time, already managed by the codec driver for diagnostic purposes. Since now the card->pop_time is going to be killed, stop abusing foreign fields in favor of an own one. Signed-off-by: Janusz Krzysztofik Signed-off-by: Kuninori Morimoto Link: https://patch.msgid.link/87v7ctwj0w.wl-kuninori.morimoto.gx@renesas.com Signed-off-by: Mark Brown --- sound/soc/codecs/cx20442.c | 8 ++++++-- sound/soc/codecs/cx20442.h | 5 +++++ sound/soc/ti/ams-delta.c | 21 ++++++++++++--------- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/sound/soc/codecs/cx20442.c b/sound/soc/codecs/cx20442.c index c0dc69ce4d0e..3a1455b79cd3 100644 --- a/sound/soc/codecs/cx20442.c +++ b/sound/soc/codecs/cx20442.c @@ -236,7 +236,8 @@ static int v253_open(struct tty_struct *tty) /* Line discipline .close() */ static void v253_close(struct tty_struct *tty) { - struct snd_soc_component *component = tty->disc_data; + struct cx20442_codec *codec = tty->disc_data; + struct snd_soc_component *component = codec->component; struct cx20442_priv *cx20442; tty->disc_data = NULL; @@ -248,6 +249,7 @@ static void v253_close(struct tty_struct *tty) /* Prevent the codec driver from further accessing the modem */ cx20442->tty = NULL; + codec->ready = false; component->card->pop_time = 0; } @@ -261,7 +263,8 @@ static void v253_hangup(struct tty_struct *tty) static void v253_receive(struct tty_struct *tty, const u8 *cp, const u8 *fp, size_t count) { - struct snd_soc_component *component = tty->disc_data; + struct cx20442_codec *codec = tty->disc_data; + struct snd_soc_component *component = codec->component; struct cx20442_priv *cx20442; if (!component) @@ -274,6 +277,7 @@ static void v253_receive(struct tty_struct *tty, const u8 *cp, const u8 *fp, /* Set up codec driver access to modem controls */ cx20442->tty = tty; + codec->ready = true; component->card->pop_time = 1; } } diff --git a/sound/soc/codecs/cx20442.h b/sound/soc/codecs/cx20442.h index bb897bcb2486..78ab1eab083e 100644 --- a/sound/soc/codecs/cx20442.h +++ b/sound/soc/codecs/cx20442.h @@ -8,6 +8,11 @@ #ifndef _CX20442_CODEC_H #define _CX20442_CODEC_H +struct cx20442_codec { + struct snd_soc_component *component; + bool ready; +}; + extern struct tty_ldisc_ops v253_ops; #endif diff --git a/sound/soc/ti/ams-delta.c b/sound/soc/ti/ams-delta.c index ba173d9fcba9..1775997f86d0 100644 --- a/sound/soc/ti/ams-delta.c +++ b/sound/soc/ti/ams-delta.c @@ -93,7 +93,7 @@ static unsigned short ams_delta_audio_agc; * Used for passing a codec structure pointer * from the board initialization code to the tty line discipline. */ -static struct snd_soc_component *cx20442_codec; +static struct cx20442_codec cx20442_codec; static int ams_delta_set_audio_mode(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) @@ -105,7 +105,7 @@ static int ams_delta_set_audio_mode(struct snd_kcontrol *kcontrol, int pin, changed = 0; /* Refuse any mode changes if we are not able to control the codec. */ - if (!cx20442_codec->card->pop_time) + if (!cx20442_codec.ready) return -EUNATCH; if (ucontrol->value.enumerated.item[0] >= control->items) @@ -280,14 +280,14 @@ static int cx81801_open(struct tty_struct *tty) { int ret; - if (!cx20442_codec) + if (!cx20442_codec.component) return -ENODEV; /* * Pass the codec structure pointer for use by other ldisc callbacks, * both the card and the codec specific parts. */ - tty->disc_data = cx20442_codec; + tty->disc_data = &cx20442_codec; ret = v253_ops.open(tty); @@ -300,9 +300,12 @@ static int cx81801_open(struct tty_struct *tty) /* Line discipline .close() */ static void cx81801_close(struct tty_struct *tty) { - struct snd_soc_component *component = tty->disc_data; + struct snd_soc_component *component = cx20442_codec.component; struct snd_soc_dapm_context *dapm; + if (WARN_ON(tty->disc_data != &cx20442_codec)) + return; + timer_delete_sync(&cx81801_timer); /* Prevent the hook switch from further changing the DAPM pins */ @@ -339,14 +342,14 @@ static void cx81801_hangup(struct tty_struct *tty) static void cx81801_receive(struct tty_struct *tty, const u8 *cp, const u8 *fp, size_t count) { - struct snd_soc_component *component = tty->disc_data; + struct snd_soc_component *component = cx20442_codec.component; const unsigned char *c; int apply, ret; - if (!component) + if (WARN_ON(tty->disc_data != &cx20442_codec)) return; - if (!component->card->pop_time) { + if (!cx20442_codec.ready) { /* First modem response, complete setup procedure */ /* Initialize timer used for config pulse generation */ @@ -467,7 +470,7 @@ static int ams_delta_cx20442_init(struct snd_soc_pcm_runtime *rtd) /* Codec is ready, now add/activate board specific controls */ /* Store a pointer to the codec structure for tty ldisc use */ - cx20442_codec = snd_soc_rtd_to_codec(rtd, 0)->component; + cx20442_codec.component = snd_soc_rtd_to_codec(rtd, 0)->component; /* Add hook switch - can be used to control the codec from userspace * even if line discipline fails */ From 9639a6875ea9926ab021484ee46c432a1df7c209 Mon Sep 17 00:00:00 2001 From: Kuninori Morimoto Date: Tue, 12 May 2026 00:47:50 +0000 Subject: [PATCH 2/2] ASoC: soc-dapm: move card->pop_time to soc-dapm.c Card has pop_time which have used only from TI, and it is now stop using it. This pop_time is used for debug, and can be access from debugfs. Let's move it from Card to soc-dapm.c local. This patch renames it as asoc/${card}/pop_time to asoc/dapm_pop_time. This patch moves it from Card to soc-dapm.c, tidyup soc-dapm.c accordingly, and remove card->pop_time from cx20442.c which is no longer needed. Signed-off-by: Kuninori Morimoto Link: https://patch.msgid.link/87tssdwj0p.wl-kuninori.morimoto.gx@renesas.com Signed-off-by: Mark Brown --- include/sound/soc-dapm.h | 1 + include/sound/soc.h | 2 -- sound/soc/codecs/cx20442.c | 3 --- sound/soc/soc-core.c | 5 ++--- sound/soc/soc-dapm.c | 30 ++++++++++++++++++------------ 5 files changed, 21 insertions(+), 20 deletions(-) diff --git a/include/sound/soc-dapm.h b/include/sound/soc-dapm.h index 4f8fb7622a13..f24eafefbdff 100644 --- a/include/sound/soc-dapm.h +++ b/include/sound/soc-dapm.h @@ -673,6 +673,7 @@ int snd_soc_dapm_mux_update_power(struct snd_soc_dapm_context *dapm, /* dapm sys fs - used by the core */ extern struct attribute *snd_soc_dapm_dev_attrs[]; void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm, struct dentry *parent); +void snd_soc_dapm_debugfs_pop_time(struct dentry *parent); /* dapm audio pin control and status */ int snd_soc_dapm_enable_pin(struct snd_soc_dapm_context *dapm, const char *pin); diff --git a/include/sound/soc.h b/include/sound/soc.h index 5e3eb617d832..453548988d38 100644 --- a/include/sound/soc.h +++ b/include/sound/soc.h @@ -1081,8 +1081,6 @@ struct snd_soc_card { #ifdef CONFIG_PM_SLEEP struct work_struct deferred_resume_work; #endif - u32 pop_time; - /* bit field */ unsigned int instantiated:1; unsigned int topology_shortname_created:1; diff --git a/sound/soc/codecs/cx20442.c b/sound/soc/codecs/cx20442.c index 3a1455b79cd3..0dea84cd8ef2 100644 --- a/sound/soc/codecs/cx20442.c +++ b/sound/soc/codecs/cx20442.c @@ -250,7 +250,6 @@ static void v253_close(struct tty_struct *tty) /* Prevent the codec driver from further accessing the modem */ cx20442->tty = NULL; codec->ready = false; - component->card->pop_time = 0; } /* Line discipline .hangup() */ @@ -278,7 +277,6 @@ static void v253_receive(struct tty_struct *tty, const u8 *cp, const u8 *fp, /* Set up codec driver access to modem controls */ cx20442->tty = tty; codec->ready = true; - component->card->pop_time = 1; } } @@ -379,7 +377,6 @@ static int cx20442_component_probe(struct snd_soc_component *component) cx20442->tty = NULL; snd_soc_component_set_drvdata(component, cx20442); - component->card->pop_time = 0; return 0; } diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 3fecf9fc903c..033121911b08 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -194,9 +194,6 @@ static void soc_init_card_debugfs(struct snd_soc_card *card) card->debugfs_card_root = debugfs_create_dir(card->name, snd_soc_debugfs_root); - debugfs_create_u32("dapm_pop_time", 0644, card->debugfs_card_root, - &card->pop_time); - snd_soc_dapm_debugfs_init(snd_soc_card_to_dapm(card), card->debugfs_card_root); } @@ -215,6 +212,8 @@ static void snd_soc_debugfs_init(void) debugfs_create_file("components", 0444, snd_soc_debugfs_root, NULL, &component_list_fops); + + snd_soc_dapm_debugfs_pop_time(snd_soc_debugfs_root); } static void snd_soc_debugfs_exit(void) diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c index d6192204e613..10f5fb771e30 100644 --- a/sound/soc/soc-dapm.c +++ b/sound/soc/soc-dapm.c @@ -40,6 +40,8 @@ #include +static u32 pop_time; + /* DAPM context */ struct snd_soc_dapm_context { enum snd_soc_bias_level bias_level; @@ -161,14 +163,14 @@ static void dapm_assert_locked(struct snd_soc_dapm_context *dapm) snd_soc_dapm_mutex_assert_held(dapm); } -static void dapm_pop_wait(u32 pop_time) +static void dapm_pop_wait(void) { if (pop_time) schedule_timeout_uninterruptible(msecs_to_jiffies(pop_time)); } -__printf(3, 4) -static void dapm_pop_dbg(struct device *dev, u32 pop_time, const char *fmt, ...) +__printf(2, 3) +static void dapm_pop_dbg(struct device *dev, const char *fmt, ...) { va_list args; char *buf; @@ -1872,8 +1874,7 @@ static void dapm_seq_check_event(struct snd_soc_card *card, if (w->event && (w->event_flags & event)) { int ret; - dapm_pop_dbg(dev, card->pop_time, "pop test : %s %s\n", - w->name, ev_name); + dapm_pop_dbg(dev, "pop test : %s %s\n", w->name, ev_name); dapm_async_complete(w->dapm); trace_snd_soc_dapm_widget_event_start(w, event); ret = w->event(w, NULL, event); @@ -1909,7 +1910,7 @@ static void dapm_seq_run_coalesced(struct snd_soc_card *card, else value |= w->off_val << w->shift; - dapm_pop_dbg(dev, card->pop_time, + dapm_pop_dbg(dev, "pop test : Queue %s: reg=0x%x, 0x%x/0x%x\n", w->name, reg, value, mask); @@ -1923,10 +1924,10 @@ static void dapm_seq_run_coalesced(struct snd_soc_card *card, * same register. */ - dapm_pop_dbg(dev, card->pop_time, + dapm_pop_dbg(dev, "pop test : Applying 0x%x/0x%x to %x in %dms\n", - value, mask, reg, card->pop_time); - dapm_pop_wait(card->pop_time); + value, mask, reg, pop_time); + dapm_pop_wait(); dapm_update_bits(dapm, reg, mask, value); } @@ -2392,9 +2393,9 @@ static int dapm_power_widgets(struct snd_soc_card *card, int event, return ret; } - dapm_pop_dbg(card->dev, card->pop_time, - "DAPM sequencing finished, waiting %dms\n", card->pop_time); - dapm_pop_wait(card->pop_time); + dapm_pop_dbg(card->dev, + "DAPM sequencing finished, waiting %dms\n", pop_time); + dapm_pop_wait(); trace_snd_soc_dapm_done(card, event); @@ -2561,6 +2562,11 @@ static const struct file_operations dapm_bias_fops = { .llseek = default_llseek, }; +void snd_soc_dapm_debugfs_pop_time(struct dentry *parent) +{ + debugfs_create_u32("dapm_pop_time", 0644, parent, &pop_time); +} + void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm, struct dentry *parent) {