diff options
author | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2011-05-30 10:54:18 +0800 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2011-05-30 10:54:18 +0800 |
commit | d21685ec258f803d3badae5eae821383a34815a9 (patch) | |
tree | 7ab60a2a5d557a4f345b01a79ca2f877c06d9b92 /sound/soc/soc-cache.c | |
parent | 74ab24af4fe165de5af01d0507250dd099f096b0 (diff) | |
parent | ea02c63d57d7ec099f66ddb2942b4022e865cd5f (diff) |
Merge branch 'for-2.6.40' into for-2.6.41
Diffstat (limited to 'sound/soc/soc-cache.c')
-rw-r--r-- | sound/soc/soc-cache.c | 140 |
1 files changed, 14 insertions, 126 deletions
diff --git a/sound/soc/soc-cache.c b/sound/soc/soc-cache.c index d1d4059be04e..d8ce34c83d8b 100644 --- a/sound/soc/soc-cache.c +++ b/sound/soc/soc-cache.c @@ -20,25 +20,15 @@ #include <trace/events/asoc.h> -#if defined(CONFIG_SPI_MASTER) -static int do_spi_write(void *control_data, const void *msg, - int len) +#ifdef CONFIG_SPI_MASTER +static int do_spi_write(void *control, const char *data, int len) { - struct spi_device *spi = control_data; - struct spi_transfer t; - struct spi_message m; - - if (len <= 0) - return 0; - - spi_message_init(&m); - memset(&t, 0, sizeof t); - - t.tx_buf = msg; - t.len = len; + struct spi_device *spi = control; + int ret; - spi_message_add_tail(&t, &m); - spi_sync(spi, &m); + ret = spi_write(spi, data, len); + if (ret < 0) + return ret; return len; } @@ -101,28 +91,12 @@ static unsigned int snd_soc_4_12_read(struct snd_soc_codec *codec, static int snd_soc_4_12_write(struct snd_soc_codec *codec, unsigned int reg, unsigned int value) { - u8 data[2]; - - data[0] = (reg << 4) | ((value >> 8) & 0x000f); - data[1] = value & 0x00ff; - - return do_hw_write(codec, reg, value, data, 2); -} - -#if defined(CONFIG_SPI_MASTER) -static int snd_soc_4_12_spi_write(void *control_data, const char *data, - int len) -{ - u8 msg[2]; + u16 data; - msg[0] = data[1]; - msg[1] = data[0]; + data = cpu_to_be16((reg << 12) | (value & 0xffffff)); - return do_spi_write(control_data, msg, len); + return do_hw_write(codec, reg, value, &data, 2); } -#else -#define snd_soc_4_12_spi_write NULL -#endif static unsigned int snd_soc_7_9_read(struct snd_soc_codec *codec, unsigned int reg) @@ -140,21 +114,6 @@ static int snd_soc_7_9_write(struct snd_soc_codec *codec, unsigned int reg, return do_hw_write(codec, reg, value, &data, 2); } -#if defined(CONFIG_SPI_MASTER) -static int snd_soc_7_9_spi_write(void *control_data, const char *data, - int len) -{ - u8 msg[2]; - - msg[0] = data[0]; - msg[1] = data[1]; - - return do_spi_write(control_data, msg, len); -} -#else -#define snd_soc_7_9_spi_write NULL -#endif - static int snd_soc_8_8_write(struct snd_soc_codec *codec, unsigned int reg, unsigned int value) { @@ -173,21 +132,6 @@ static unsigned int snd_soc_8_8_read(struct snd_soc_codec *codec, return do_hw_read(codec, reg); } -#if defined(CONFIG_SPI_MASTER) -static int snd_soc_8_8_spi_write(void *control_data, const char *data, - int len) -{ - u8 msg[2]; - - msg[0] = data[0]; - msg[1] = data[1]; - - return do_spi_write(control_data, msg, len); -} -#else -#define snd_soc_8_8_spi_write NULL -#endif - static int snd_soc_8_16_write(struct snd_soc_codec *codec, unsigned int reg, unsigned int value) { @@ -206,22 +150,6 @@ static unsigned int snd_soc_8_16_read(struct snd_soc_codec *codec, return do_hw_read(codec, reg); } -#if defined(CONFIG_SPI_MASTER) -static int snd_soc_8_16_spi_write(void *control_data, const char *data, - int len) -{ - u8 msg[3]; - - msg[0] = data[0]; - msg[1] = data[1]; - msg[2] = data[2]; - - return do_spi_write(control_data, msg, len); -} -#else -#define snd_soc_8_16_spi_write NULL -#endif - #if defined(CONFIG_I2C) || (defined(CONFIG_I2C_MODULE) && defined(MODULE)) static unsigned int do_i2c_read(struct snd_soc_codec *codec, void *reg, int reglen, @@ -318,27 +246,10 @@ static int snd_soc_16_8_write(struct snd_soc_codec *codec, unsigned int reg, memcpy(data, &rval, sizeof(rval)); data[2] = value; - reg &= 0xff; return do_hw_write(codec, reg, value, data, 3); } -#if defined(CONFIG_SPI_MASTER) -static int snd_soc_16_8_spi_write(void *control_data, const char *data, - int len) -{ - u8 msg[3]; - - msg[0] = data[0]; - msg[1] = data[1]; - msg[2] = data[2]; - - return do_spi_write(control_data, msg, len); -} -#else -#define snd_soc_16_8_spi_write NULL -#endif - #if defined(CONFIG_I2C) || (defined(CONFIG_I2C_MODULE) && defined(MODULE)) static unsigned int snd_soc_16_16_read_i2c(struct snd_soc_codec *codec, unsigned int r) @@ -373,23 +284,6 @@ static int snd_soc_16_16_write(struct snd_soc_codec *codec, unsigned int reg, return do_hw_write(codec, reg, value, data, sizeof(data)); } -#if defined(CONFIG_SPI_MASTER) -static int snd_soc_16_16_spi_write(void *control_data, const char *data, - int len) -{ - u8 msg[4]; - - msg[0] = data[0]; - msg[1] = data[1]; - msg[2] = data[2]; - msg[3] = data[3]; - - return do_spi_write(control_data, msg, len); -} -#else -#define snd_soc_16_16_spi_write NULL -#endif - /* Primitive bulk write support for soc-cache. The data pointed to by * `data' needs to already be in the form the hardware expects * including any leading register specific data. Any data written @@ -419,7 +313,7 @@ static int snd_soc_hw_bulk_write_raw(struct snd_soc_codec *codec, unsigned int r #endif #if defined(CONFIG_SPI_MASTER) case SND_SOC_SPI: - ret = do_spi_write(codec->control_data, data, len); + ret = spi_write(codec->control_data, data, len); break; #endif default: @@ -438,43 +332,36 @@ static struct { int addr_bits; int data_bits; int (*write)(struct snd_soc_codec *codec, unsigned int, unsigned int); - int (*spi_write)(void *, const char *, int); unsigned int (*read)(struct snd_soc_codec *, unsigned int); unsigned int (*i2c_read)(struct snd_soc_codec *, unsigned int); } io_types[] = { { .addr_bits = 4, .data_bits = 12, .write = snd_soc_4_12_write, .read = snd_soc_4_12_read, - .spi_write = snd_soc_4_12_spi_write, }, { .addr_bits = 7, .data_bits = 9, .write = snd_soc_7_9_write, .read = snd_soc_7_9_read, - .spi_write = snd_soc_7_9_spi_write, }, { .addr_bits = 8, .data_bits = 8, .write = snd_soc_8_8_write, .read = snd_soc_8_8_read, .i2c_read = snd_soc_8_8_read_i2c, - .spi_write = snd_soc_8_8_spi_write, }, { .addr_bits = 8, .data_bits = 16, .write = snd_soc_8_16_write, .read = snd_soc_8_16_read, .i2c_read = snd_soc_8_16_read_i2c, - .spi_write = snd_soc_8_16_spi_write, }, { .addr_bits = 16, .data_bits = 8, .write = snd_soc_16_8_write, .read = snd_soc_16_8_read, .i2c_read = snd_soc_16_8_read_i2c, - .spi_write = snd_soc_16_8_spi_write, }, { .addr_bits = 16, .data_bits = 16, .write = snd_soc_16_16_write, .read = snd_soc_16_16_read, .i2c_read = snd_soc_16_16_read_i2c, - .spi_write = snd_soc_16_16_spi_write, }, }; @@ -535,8 +422,9 @@ int snd_soc_codec_set_cache_io(struct snd_soc_codec *codec, break; case SND_SOC_SPI: - if (io_types[i].spi_write) - codec->hw_write = io_types[i].spi_write; +#ifdef CONFIG_SPI_MASTER + codec->hw_write = do_spi_write; +#endif codec->control_data = container_of(codec->dev, struct spi_device, |