All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: alsa-devel@alsa-project.org, Sonic Zhang <sonic.zhang@analog.com>
Subject: [PATCH 4/6] ASoC: ad1980: make usage of register cache optional
Date: Tue, 24 Aug 2010 15:09:42 +0200	[thread overview]
Message-ID: <1282655384-13357-4-git-send-email-u.kleine-koenig@pengutronix.de> (raw)
In-Reply-To: <1282655384-13357-1-git-send-email-u.kleine-koenig@pengutronix.de>

I'm hunting some problems where reading and writing to the codec doesn't
work.  In this case caching is in the way.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 sound/soc/codecs/ad1980.c |   36 +++++++++++++++++++++++++++++-------
 1 files changed, 29 insertions(+), 7 deletions(-)

diff --git a/sound/soc/codecs/ad1980.c b/sound/soc/codecs/ad1980.c
index 82267e5..864e65d 100644
--- a/sound/soc/codecs/ad1980.c
+++ b/sound/soc/codecs/ad1980.c
@@ -33,6 +33,8 @@
 
 #include "ad1980.h"
 
+#define AC97_USE_CACHE 1
+#if AC97_USE_CACHE
 /*
  * AD1980 register cache
  */
@@ -54,6 +56,7 @@ static const u16 ad1980_reg[] = {
 	0x0000, 0x0000, 0x1001, 0x0000, /* 70 - 76 */
 	0x0000, 0x0000, 0x4144, 0x5370  /* 78 - 7e */
 };
+#endif
 
 static const char *ad1980_rec_sel[] = {"Mic", "CD", "NC", "AUX", "Line",
 		"Stereo Mix", "Mono Mix", "Phone"};
@@ -101,7 +104,9 @@ static unsigned int ac97_read(struct snd_soc_codec *codec,
 	unsigned int reg)
 {
 	u16 *cache = codec->reg_cache;
+	int ret;
 
+#if AC97_USE_CACHE
 	switch (reg) {
 	case AC97_RESET:
 	case AC97_INT_PAGING:
@@ -109,27 +114,38 @@ static unsigned int ac97_read(struct snd_soc_codec *codec,
 	case AC97_EXTENDED_STATUS:
 	case AC97_VENDOR_ID1:
 	case AC97_VENDOR_ID2:
-		return soc_ac97_ops.read(codec->ac97, reg);
+#endif
+		ret = soc_ac97_ops.read(codec->ac97, reg);
+#if AC97_USE_CACHE
 	default:
 		reg = reg >> 1;
 
 		if (reg >= ARRAY_SIZE(ad1980_reg))
-			return -EINVAL;
-
-		return cache[reg];
+			ret = -EINVAL;
+		else
+			ret = cache[reg];
 	}
+#endif
+
+	pr_debug("%s: reg=0x%02x, val=0x%04x\n", __func__, reg, ret);
+
+	return ret;
 }
 
 static int ac97_write(struct snd_soc_codec *codec, unsigned int reg,
 	unsigned int val)
 {
-	u16 *cache = codec->reg_cache;
+	pr_debug("%s: reg=0x%02x, val=0x%04x\n", __func__, reg, val);
 
 	soc_ac97_ops.write(codec->ac97, reg, val);
+
+#if AC97_USE_CACHE
 	reg = reg >> 1;
-	if (reg < ARRAY_SIZE(ad1980_reg))
+	if (reg < ARRAY_SIZE(ad1980_reg)) {
+		u16 *cache = codec->reg_cache;
 		cache[reg] = val;
-
+	}
+#endif
 	return 0;
 }
 
@@ -204,6 +220,7 @@ static int ad1980_soc_probe(struct platform_device *pdev)
 	codec = socdev->card->codec;
 	mutex_init(&codec->mutex);
 
+#if AC97_USE_CACHE
 	codec->reg_cache =
 		kzalloc(sizeof(u16) * ARRAY_SIZE(ad1980_reg), GFP_KERNEL);
 	if (codec->reg_cache == NULL) {
@@ -214,6 +231,7 @@ static int ad1980_soc_probe(struct platform_device *pdev)
 			ARRAY_SIZE(ad1980_reg));
 	codec->reg_cache_size = sizeof(u16) * ARRAY_SIZE(ad1980_reg);
 	codec->reg_cache_step = 2;
+#endif
 	codec->name = "AD1980";
 	codec->owner = THIS_MODULE;
 	codec->dai = &ad1980_dai;
@@ -279,9 +297,11 @@ pcm_err:
 	snd_soc_free_ac97_codec(codec);
 
 codec_err:
+#if AC97_USE_CACHE
 	kfree(codec->reg_cache);
 
 cache_err:
+#endif
 	kfree(socdev->card->codec);
 	socdev->card->codec = NULL;
 	return ret;
@@ -298,7 +318,9 @@ static int ad1980_soc_remove(struct platform_device *pdev)
 	snd_soc_dapm_free(socdev);
 	snd_soc_free_pcms(socdev);
 	snd_soc_free_ac97_codec(codec);
+#if AC97_USE_CACHE
 	kfree(codec->reg_cache);
+#endif
 	kfree(codec);
 	return 0;
 }
-- 
1.7.1

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

  parent reply	other threads:[~2010-08-24 13:09 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-24 13:09 [PATCH 1/6] ASoC: ad1980: Stay in 20bit mode for architectures other than blackfin Uwe Kleine-König
2010-08-24 13:09 ` [PATCH 2/6] ASoC: ad1980: fix names of a few kcontrols Uwe Kleine-König
2010-08-27 18:11   ` Mark Brown
2010-08-24 13:09 ` [PATCH 3/6] ASoC: ad1980: remove unneeded function declaration Uwe Kleine-König
2010-08-27 18:12   ` Mark Brown
2010-08-28  8:14     ` Liam Girdwood
2010-08-29 13:53       ` Mark Brown
2010-08-24 13:09 ` Uwe Kleine-König [this message]
2010-08-27 18:20   ` [PATCH 4/6] ASoC: ad1980: make usage of register cache optional Mark Brown
2010-08-24 13:09 ` [PATCH 5/6] ASoC: ad1980: verify cache at probe time Uwe Kleine-König
2010-08-27 18:23   ` Mark Brown
2010-08-24 13:09 ` [PATCH 6/6] ASoC: ad1980: verify writes Uwe Kleine-König
2010-08-27 18:25   ` Mark Brown
2010-08-25  3:28 ` [PATCH 1/6] ASoC: ad1980: Stay in 20bit mode for architectures other than blackfin Zhang, Sonic
2010-08-25  5:03   ` Uwe Kleine-König
2010-08-27 18:06 ` Mark Brown

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=1282655384-13357-4-git-send-email-u.kleine-koenig@pengutronix.de \
    --to=u.kleine-koenig@pengutronix.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=sonic.zhang@analog.com \
    /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.