Skip to content

Commit

Permalink
ASoC: soc-cache: Add spi_write support for all I/O types
Browse files Browse the repository at this point in the history
Ensure that all drivers that use SPI and I2C will work properly
by providing SPI write functions for all different I/O types.

Signed-off-by: Dimitris Papastamos <dp@opensource.wolfsonmicro.com>
Acked-by: Liam Girdwood <lrg@slimlogic.co.uk>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
  • Loading branch information
Dimitris Papastamos authored and Mark Brown committed Oct 5, 2010
1 parent bb5a027 commit f479fd9
Showing 1 changed file with 96 additions and 0 deletions.
96 changes: 96 additions & 0 deletions sound/soc/soc-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,36 @@ static unsigned int snd_soc_8_8_read(struct snd_soc_codec *codec,
return cache[reg];
}

#if defined(CONFIG_SPI_MASTER)
static int snd_soc_8_8_spi_write(void *control_data, const char *data,
int len)
{
struct spi_device *spi = control_data;
struct spi_transfer t;
struct spi_message m;
u8 msg[2];

if (len <= 0)
return 0;

msg[0] = data[0];
msg[1] = data[1];

spi_message_init(&m);
memset(&t, 0, (sizeof t));

t.tx_buf = &msg[0];
t.len = len;

spi_message_add_tail(&t, &m);
spi_sync(spi, &m);

return 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)
{
Expand Down Expand Up @@ -254,6 +284,37 @@ static unsigned int snd_soc_8_16_read(struct snd_soc_codec *codec,
}
}

#if defined(CONFIG_SPI_MASTER)
static int snd_soc_8_16_spi_write(void *control_data, const char *data,
int len)
{
struct spi_device *spi = control_data;
struct spi_transfer t;
struct spi_message m;
u8 msg[3];

if (len <= 0)
return 0;

msg[0] = data[0];
msg[1] = data[1];
msg[2] = data[2];

spi_message_init(&m);
memset(&t, 0, (sizeof t));

t.tx_buf = &msg[0];
t.len = len;

spi_message_add_tail(&t, &m);
spi_sync(spi, &m);

return len;
}
#else
#define snd_soc_8_16_spi_write NULL
#endif

#if defined(CONFIG_I2C) || (defined(CONFIG_I2C_MODULE) && defined(MODULE))
static unsigned int snd_soc_8_8_read_i2c(struct snd_soc_codec *codec,
unsigned int r)
Expand Down Expand Up @@ -518,6 +579,38 @@ static int snd_soc_16_16_write(struct snd_soc_codec *codec, unsigned int reg,
return -EIO;
}

#if defined(CONFIG_SPI_MASTER)
static int snd_soc_16_16_spi_write(void *control_data, const char *data,
int len)
{
struct spi_device *spi = control_data;
struct spi_transfer t;
struct spi_message m;
u8 msg[4];

if (len <= 0)
return 0;

msg[0] = data[0];
msg[1] = data[1];
msg[2] = data[2];
msg[3] = data[3];

spi_message_init(&m);
memset(&t, 0, (sizeof t));

t.tx_buf = &msg[0];
t.len = len;

spi_message_add_tail(&t, &m);
spi_sync(spi, &m);

return len;
}
#else
#define snd_soc_16_16_spi_write NULL
#endif

static struct {
int addr_bits;
int data_bits;
Expand All @@ -540,11 +633,13 @@ static struct {
.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,
Expand All @@ -556,6 +651,7 @@ static struct {
.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,
},
};

Expand Down

0 comments on commit f479fd9

Please sign in to comment.