Alsa-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Scott Jiang <scott.jiang.linux@gmail.com>
To: Mark Brown <broonie@opensource.wolfsonmicro.com>
Cc: uclinux-dist-devel@blackfin.uclinux.org,
	alsa-devel@alsa-project.org,
	Scott Jiang <scott.jiang.linux@gmail.com>
Subject: [PATCH v2 4/5] ASoC: add spi hw read function for 16 addr 8 data mode
Date: Fri, 12 Aug 2011 18:04:13 -0400	[thread overview]
Message-ID: <1313186654-22520-4-git-send-email-scott.jiang.linux@gmail.com> (raw)
In-Reply-To: <1313186654-22520-1-git-send-email-scott.jiang.linux@gmail.com>

some spi registers are 7bits global address + 1 bit r/w + 8 bits
register address. soc cache layer can't support this kind well.
so let codec driver read registers directly.

Signed-off-by: Scott Jiang <scott.jiang.linux@gmail.com>
---
 sound/soc/soc-io.c |   23 +++++++++++++++++++++++
 1 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/sound/soc/soc-io.c b/sound/soc/soc-io.c
index cca490c..a62f7dd 100644
--- a/sound/soc/soc-io.c
+++ b/sound/soc/soc-io.c
@@ -205,6 +205,25 @@ static unsigned int snd_soc_16_8_read_i2c(struct snd_soc_codec *codec,
 #define snd_soc_16_8_read_i2c NULL
 #endif
 
+#if defined(CONFIG_SPI_MASTER)
+static unsigned int snd_soc_16_8_read_spi(struct snd_soc_codec *codec,
+		                          unsigned int r)
+{
+	struct spi_device *spi = codec->control_data;
+
+	const u16 reg = cpu_to_be16(r | 0x100);
+	u8 data;
+	int ret;
+
+	ret = spi_write_then_read(spi, &reg, 2, &data, 1);
+	if (ret < 0)
+		return 0;
+	return data;
+}
+#else
+#define snd_soc_16_8_read_spi NULL
+#endif
+
 static int snd_soc_16_8_write(struct snd_soc_codec *codec, unsigned int reg,
 			      unsigned int value)
 {
@@ -295,6 +314,7 @@ static struct {
 	int (*write)(struct snd_soc_codec *codec, unsigned int, unsigned int);
 	unsigned int (*read)(struct snd_soc_codec *, unsigned int);
 	unsigned int (*i2c_read)(struct snd_soc_codec *, unsigned int);
+	unsigned int (*spi_read)(struct snd_soc_codec *, unsigned int);
 } io_types[] = {
 	{
 		.addr_bits = 4, .data_bits = 12,
@@ -318,6 +338,7 @@ static struct {
 		.addr_bits = 16, .data_bits = 8,
 		.write = snd_soc_16_8_write,
 		.i2c_read = snd_soc_16_8_read_i2c,
+		.spi_read = snd_soc_16_8_read_spi,
 	},
 	{
 		.addr_bits = 16, .data_bits = 16,
@@ -383,6 +404,8 @@ int snd_soc_codec_set_cache_io(struct snd_soc_codec *codec,
 #ifdef CONFIG_SPI_MASTER
 		codec->hw_write = do_spi_write;
 #endif
+		if (io_types[i].spi_read)
+			codec->hw_read = io_types[i].spi_read;
 
 		codec->control_data = container_of(codec->dev,
 						   struct spi_device,
-- 
1.7.0.4

  parent reply	other threads:[~2011-08-12  8:57 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-12 22:04 [PATCH v2 1/5] ASoC: ad193x: fix registers definition Scott Jiang
2011-08-12 21:05 ` Paul Menzel
2011-08-12 22:04 ` [PATCH v2 2/5] ASoC: ad193x: fix dac word len setting Scott Jiang
2011-08-15  2:42   ` Barry Song
2011-08-15 13:29   ` Mark Brown
2011-08-12 22:04 ` [PATCH v2 3/5] ASoC: ad193x: fix system clock Scott Jiang
2011-08-15 13:35   ` Mark Brown
2011-08-12 22:04 ` Scott Jiang [this message]
2011-08-15  2:46   ` [PATCH v2 4/5] ASoC: add spi hw read function for 16 addr 8 data mode Barry Song
2011-08-15  7:03     ` Scott Jiang
2011-08-15 13:37   ` Mark Brown
2011-08-12 22:04 ` [PATCH v2 5/5] ASoC: ad193x: remove cache support Scott Jiang
2011-08-15 13:43   ` Mark Brown
2011-08-15 13:29 ` [PATCH v2 1/5] ASoC: ad193x: fix registers definition 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=1313186654-22520-4-git-send-email-scott.jiang.linux@gmail.com \
    --to=scott.jiang.linux@gmail.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@opensource.wolfsonmicro.com \
    --cc=uclinux-dist-devel@blackfin.uclinux.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox