Skip to content

Commit bfc4e86

Browse files
Timur Tabiperexg
authored andcommitted
[ALSA] Fix CS4270 volume control and optimize I2C operations
The volume control for the CS4270 ASoC driver was inverted - raising the volume level with alsamixer would decrease the actual volume. This patch also improves the performance of the I2C code (used to change register settings) by only performing an I2C write if the new value is different from the value that's in the register cache. Signed-off-by: Timur Tabi <timur@freescale.com> Signed-off-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Jaroslav Kysela <perex@suse.cz>
1 parent 23d4635 commit bfc4e86

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

‎sound/soc/codecs/cs4270.c‎

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -294,19 +294,24 @@ static unsigned int cs4270_read_reg_cache(struct snd_soc_codec *codec,
294294
static int cs4270_i2c_write(struct snd_soc_codec *codec, unsigned int reg,
295295
unsigned int value)
296296
{
297+
u8 *cache = codec->reg_cache;
298+
297299
if ((reg < CS4270_FIRSTREG) || (reg > CS4270_LASTREG))
298300
return -EIO;
299301

300-
if (i2c_smbus_write_byte_data(codec->control_data, reg, value) == 0) {
302+
/* Only perform an I2C operation if the new value is different */
303+
if (cache[reg - CS4270_FIRSTREG] != value) {
304+
struct i2c_client *client = codec->control_data;
305+
if (i2c_smbus_write_byte_data(client, reg, value)) {
306+
printk(KERN_ERR "cs4270: I2C write failed\n");
307+
return -EIO;
308+
}
309+
301310
/* We've written to the hardware, so update the cache */
302-
u8 *cache = codec->reg_cache;
303311
cache[reg - CS4270_FIRSTREG] = value;
304-
return 0;
305-
} else {
306-
printk(KERN_ERR "cs4270: I2C write of register %u failed\n",
307-
reg);
308-
return -EIO;
309312
}
313+
314+
return 0;
310315
}
311316

312317
/*
@@ -521,7 +526,7 @@ static int cs4270_i2c_detach(struct i2c_client *client)
521526
/* A list of non-DAPM controls that the CS4270 supports */
522527
static const struct snd_kcontrol_new cs4270_snd_controls[] = {
523528
SOC_DOUBLE_R("Master Playback Volume",
524-
CS4270_VOLA, CS4270_VOLB, 0, 0xFF, 0)
529+
CS4270_VOLA, CS4270_VOLB, 0, 0xFF, 1)
525530
};
526531

527532
static struct i2c_driver cs4270_i2c_driver = {

0 commit comments

Comments
 (0)