ALSA: hda/cs8409: Prevent I2C access during suspend time
authorLucas Tanure <tanureal@opensource.cirrus.com>
Wed, 11 Aug 2021 18:56:38 +0000 (19:56 +0100)
committerTakashi Iwai <tiwai@suse.de>
Thu, 12 Aug 2021 11:41:46 +0000 (13:41 +0200)
Signed-off-by: Lucas Tanure <tanureal@opensource.cirrus.com>
Signed-off-by: Vitaly Rodionov <vitalyr@opensource.cirrus.com>
Link: https://lore.kernel.org/r/20210811185654.6837-12-vitalyr@opensource.cirrus.com
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/pci/hda/patch_cs8409.c
sound/pci/hda/patch_cs8409.h

index 4ad832f..0b13bce 100644 (file)
@@ -127,9 +127,13 @@ static int cs8409_i2c_wait_complete(struct hda_codec *codec)
 static int cs8409_i2c_read(struct hda_codec *codec, unsigned int i2c_address, unsigned int i2c_reg,
                           unsigned int paged)
 {
+       struct cs8409_spec *spec = codec->spec;
        unsigned int i2c_reg_data;
        unsigned int read_data;
 
+       if (spec->cs42l42_suspended)
+               return -EPERM;
+
        cs8409_enable_i2c_clock(codec, 1);
        cs8409_vendor_coef_set(codec, CS8409_I2C_ADDR, i2c_address);
 
@@ -172,8 +176,12 @@ static int cs8409_i2c_read(struct hda_codec *codec, unsigned int i2c_address, un
 static int cs8409_i2c_write(struct hda_codec *codec, unsigned int i2c_address, unsigned int i2c_reg,
                            unsigned int i2c_data, unsigned int paged)
 {
+       struct cs8409_spec *spec = codec->spec;
        unsigned int i2c_reg_data;
 
+       if (spec->cs42l42_suspended)
+               return -EPERM;
+
        cs8409_enable_i2c_clock(codec, 1);
        cs8409_vendor_coef_set(codec, CS8409_I2C_ADDR, i2c_address);
 
@@ -371,6 +379,8 @@ static void cs8409_cs42l42_reset(struct hda_codec *codec)
        /* wait ~10ms */
        usleep_range(10000, 15000);
 
+       spec->cs42l42_suspended = 0;
+
        mutex_lock(&spec->cs8409_i2c_mux);
 
        /* Clear interrupts, by reading interrupt status registers */
@@ -594,6 +604,9 @@ static int cs8409_suspend(struct hda_codec *codec)
        /* Power down CS42L42 ASP/EQ/MIX/HP */
        cs8409_i2c_write(codec, CS42L42_I2C_ADDR, 0x1101, 0xfe, 1);
        mutex_unlock(&spec->cs8409_i2c_mux);
+
+       spec->cs42l42_suspended = 1;
+
        /* Assert CS42L42 RTS# line */
        snd_hda_codec_write(codec, CS8409_PIN_AFG, 0, AC_VERB_SET_GPIO_DATA, 0);
 
@@ -759,6 +772,7 @@ void cs8409_cs42l42_fixups(struct hda_codec *codec, const struct hda_fixup *fix,
 
                spec->cs42l42_hp_jack_in = 0;
                spec->cs42l42_mic_jack_in = 0;
+               spec->cs42l42_suspended = 1;
 
                /* Basic initial sequence for specific hw configuration */
                snd_hda_sequence_write(codec, cs8409_cs42l42_init_verbs);
index 1d3ce28..0f2084b 100644 (file)
@@ -269,6 +269,7 @@ struct cs8409_spec {
        unsigned int cs42l42_hp_jack_in:1;
        unsigned int cs42l42_mic_jack_in:1;
        unsigned int cs42l42_volume_init:1;
+       unsigned int cs42l42_suspended:1;
        char cs42l42_hp_volume[CS42L42_HP_CH];
        char cs42l42_hs_mic_volume[CS42L42_HS_MIC_CH];