ALSA: hda/cs8409: Avoid setting the same I2C address for every access
authorLucas Tanure <tanureal@opensource.cirrus.com>
Wed, 11 Aug 2021 18:56:41 +0000 (19:56 +0100)
committerTakashi Iwai <tiwai@suse.de>
Thu, 12 Aug 2021 11:41:48 +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-15-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 420f3a612fc4dc6064e42f3407826adb423ca821..e683349ebd50ad0bc87ca11dba95d7a55f06ee91 100644 (file)
@@ -155,6 +155,21 @@ static int cs8409_i2c_wait_complete(struct hda_codec *codec)
        return -1;
 }
 
+/**
+ * cs8409_set_i2c_dev_addr - Set i2c address for transaction
+ * @codec: the codec instance
+ * @addr: I2C Address
+ */
+static void cs8409_set_i2c_dev_addr(struct hda_codec *codec, unsigned int addr)
+{
+       struct cs8409_spec *spec = codec->spec;
+
+       if (spec->dev_addr != addr) {
+               cs8409_vendor_coef_set(codec, CS8409_I2C_ADDR, addr);
+               spec->dev_addr = addr;
+       }
+}
+
 /**
  * cs8409_i2c_read - CS8409 I2C Read.
  * @codec: the codec instance
@@ -176,7 +191,7 @@ static int cs8409_i2c_read(struct hda_codec *codec, unsigned int i2c_address, un
                return -EPERM;
 
        cs8409_enable_i2c_clock(codec);
-       cs8409_vendor_coef_set(codec, CS8409_I2C_ADDR, i2c_address);
+       cs8409_set_i2c_dev_addr(codec, i2c_address);
 
        if (paged) {
                cs8409_vendor_coef_set(codec, CS8409_I2C_QWRITE, i2c_reg >> 8);
@@ -222,7 +237,7 @@ static int cs8409_i2c_write(struct hda_codec *codec, unsigned int i2c_address, u
                return -EPERM;
 
        cs8409_enable_i2c_clock(codec);
-       cs8409_vendor_coef_set(codec, CS8409_I2C_ADDR, i2c_address);
+       cs8409_set_i2c_dev_addr(codec, i2c_address);
 
        if (paged) {
                cs8409_vendor_coef_set(codec, CS8409_I2C_QWRITE, i2c_reg >> 8);
index 542582c213d285b36ee8be12236457325392d967..c2c208218e34c4c95aa07c158b848a50645d290b 100644 (file)
@@ -281,6 +281,7 @@ struct cs8409_spec {
 
        struct mutex cs8409_i2c_mux;
        unsigned int i2c_clck_enabled;
+       unsigned int dev_addr;
        struct delayed_work i2c_clk_work;
 
        /* verb exec op override */