All of lore.kernel.org
 help / color / mirror / Atom feed
From: Timur Tabi <timur@freescale.com>
To: alsa-devel@alsa-project.org
Cc: Timur Tabi <timur@freescale.com>
Subject: [PATCH] [ALSA] Fix CS4270 volume control and optimize I2C operations
Date: Mon, 10 Sep 2007 17:19:02 -0500	[thread overview]
Message-ID: <11894627422900-git-send-email-timur@freescale.com> (raw)

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>
---

This patch applies to the 'mm' branch of perex/alsa.git.  I would like this
patch to be part of ALSA 1.0.15.

 sound/soc/codecs/cs4270.c |   21 +++++++++++++--------
 1 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/sound/soc/codecs/cs4270.c b/sound/soc/codecs/cs4270.c
index 43d50a4..5d601ad 100644
--- a/sound/soc/codecs/cs4270.c
+++ b/sound/soc/codecs/cs4270.c
@@ -294,19 +294,24 @@ static unsigned int cs4270_read_reg_cache(struct snd_soc_codec *codec,
 static int cs4270_i2c_write(struct snd_soc_codec *codec, unsigned int reg,
 			    unsigned int value)
 {
+	u8 *cache = codec->reg_cache;
+
 	if ((reg < CS4270_FIRSTREG) || (reg > CS4270_LASTREG))
 		return -EIO;
 
-	if (i2c_smbus_write_byte_data(codec->control_data, reg, value) == 0) {
+	/* Only perform an I2C operation if the new value is different */
+	if (cache[reg - CS4270_FIRSTREG] != value) {
+		struct i2c_client *client = codec->control_data;
+		if (i2c_smbus_write_byte_data(client, reg, value)) {
+			printk(KERN_ERR "cs4270: I2C write failed\n");
+			return -EIO;
+		}
+
 		/* We've written to the hardware, so update the cache */
-		u8 *cache = codec->reg_cache;
 		cache[reg - CS4270_FIRSTREG] = value;
-		return 0;
-	} else {
-		printk(KERN_ERR "cs4270: I2C write of register %u failed\n",
-			reg);
-		return -EIO;
 	}
+
+	return 0;
 }
 
 /*
@@ -521,7 +526,7 @@ static int cs4270_i2c_detach(struct i2c_client *client)
 /* A list of non-DAPM controls that the CS4270 supports */
 static const struct snd_kcontrol_new cs4270_snd_controls[] = {
 	SOC_DOUBLE_R("Master Playback Volume",
-		CS4270_VOLA, CS4270_VOLB, 0, 0xFF, 0)
+		CS4270_VOLA, CS4270_VOLB, 0, 0xFF, 1)
 };
 
 static struct i2c_driver cs4270_i2c_driver = {
-- 
1.5.2.4

             reply	other threads:[~2007-09-10 22:19 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-10 22:19 Timur Tabi [this message]
2007-09-10 22:46 ` [PATCH] [ALSA] Fix CS4270 volume control and optimize I2C operations Takashi Iwai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=11894627422900-git-send-email-timur@freescale.com \
    --to=timur@freescale.com \
    --cc=alsa-devel@alsa-project.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.