ALSA: hda/cs8409: Use timeout rather than retries for I2C transaction waits
authorStefan Binding <sbinding@opensource.cirrus.com>
Wed, 11 Aug 2021 18:56:51 +0000 (19:56 +0100)
committerTakashi Iwai <tiwai@suse.de>
Thu, 12 Aug 2021 11:41:58 +0000 (13:41 +0200)
Signed-off-by: Stefan Binding <sbinding@opensource.cirrus.com>
Signed-off-by: Vitaly Rodionov <vitalyr@opensource.cirrus.com>
Link: https://lore.kernel.org/r/20210811185654.6837-25-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 897c48140d8bc86419ab4364dba6df9496fb7978..9f6c51a5835a009a180c9ec8177b43aa6d91cd3e 100644 (file)
@@ -140,24 +140,14 @@ static void cs8409_enable_i2c_clock(struct hda_codec *codec)
  * @codec: the codec instance
  *
  * Wait for I2C transaction to complete.
- * Return -1 if transaction wait times out.
+ * Return -ETIMEDOUT if transaction wait times out.
  */
 static int cs8409_i2c_wait_complete(struct hda_codec *codec)
 {
-       int repeat = 5;
        unsigned int retval;
 
-       do {
-               retval = cs8409_vendor_coef_get(codec, CS8409_I2C_STS);
-               if ((retval & 0x18) != 0x18) {
-                       usleep_range(2000, 4000);
-                       --repeat;
-               } else
-                       return 0;
-
-       } while (repeat);
-
-       return -1;
+       return read_poll_timeout(cs8409_vendor_coef_get, retval, retval & 0x18,
+               CS42L42_I2C_SLEEP_US, CS42L42_I2C_TIMEOUT_US, false, codec, CS8409_I2C_STS);
 }
 
 /**
index 2208be2ffad133a26c2129e9242ad6fd5e02a303..71dbbd8e2f3b849bfeab81288574545ed28a6a46 100644 (file)
@@ -231,6 +231,8 @@ enum cs8409_coefficient_index_registers {
 #define CS42L42_HSTYPE_MASK                    (0x03)
 #define CS42L42_JACK_INSERTED                  (0x0C)
 #define CS42L42_JACK_REMOVED                   (0x00)
+#define CS42L42_I2C_TIMEOUT_US                 (20000)
+#define CS42L42_I2C_SLEEP_US                   (2000)
 
 /* Dell BULLSEYE / WARLOCK / CYBORG Specific Definitions */