]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ASoC: ti: ams-delta: Stop (ab)using card->pop_time
authorJanusz Krzysztofik <jmkrzyszt@gmail.com>
Tue, 12 May 2026 00:47:43 +0000 (00:47 +0000)
committerMark Brown <broonie@kernel.org>
Wed, 20 May 2026 12:36:49 +0000 (13:36 +0100)
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 <jmkrzyszt@gmail.com>
Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Link: https://patch.msgid.link/87v7ctwj0w.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/codecs/cx20442.c
sound/soc/codecs/cx20442.h
sound/soc/ti/ams-delta.c

index c0dc69ce4d0e7034c9d7dcfaec4c5513d456c5b8..3a1455b79cd32b7231f80ef8b242577fc4636a5d 100644 (file)
@@ -236,7 +236,8 @@ err:
 /* 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;
        }
 }
index bb897bcb2486917dd543880337991d76efd0e766..78ab1eab083e78f071665a4347b03f153e9a3457 100644 (file)
@@ -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
index ba173d9fcba91d310bc758d404ea0a597c999aab..1775997f86d046dfa83523b185ffdc7b41d91a90 100644 (file)
@@ -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 */