Skip to content

Commit f479fd9

Browse files
Dimitris Papastamosbroonie
authored andcommitted
ASoC: soc-cache: Add spi_write support for all I/O types
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 <[email protected]> Acked-by: Liam Girdwood <[email protected]> Signed-off-by: Mark Brown <[email protected]>
1 parent bb5a027 commit f479fd9

File tree

1 file changed

+96
-0
lines changed

1 file changed

+96
-0
lines changed

sound/soc/soc-cache.c

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,36 @@ static unsigned int snd_soc_8_8_read(struct snd_soc_codec *codec,
211211
return cache[reg];
212212
}
213213

214+
#if defined(CONFIG_SPI_MASTER)
215+
static int snd_soc_8_8_spi_write(void *control_data, const char *data,
216+
int len)
217+
{
218+
struct spi_device *spi = control_data;
219+
struct spi_transfer t;
220+
struct spi_message m;
221+
u8 msg[2];
222+
223+
if (len <= 0)
224+
return 0;
225+
226+
msg[0] = data[0];
227+
msg[1] = data[1];
228+
229+
spi_message_init(&m);
230+
memset(&t, 0, (sizeof t));
231+
232+
t.tx_buf = &msg[0];
233+
t.len = len;
234+
235+
spi_message_add_tail(&t, &m);
236+
spi_sync(spi, &m);
237+
238+
return len;
239+
}
240+
#else
241+
#define snd_soc_8_8_spi_write NULL
242+
#endif
243+
214244
static int snd_soc_8_16_write(struct snd_soc_codec *codec, unsigned int reg,
215245
unsigned int value)
216246
{
@@ -254,6 +284,37 @@ static unsigned int snd_soc_8_16_read(struct snd_soc_codec *codec,
254284
}
255285
}
256286

287+
#if defined(CONFIG_SPI_MASTER)
288+
static int snd_soc_8_16_spi_write(void *control_data, const char *data,
289+
int len)
290+
{
291+
struct spi_device *spi = control_data;
292+
struct spi_transfer t;
293+
struct spi_message m;
294+
u8 msg[3];
295+
296+
if (len <= 0)
297+
return 0;
298+
299+
msg[0] = data[0];
300+
msg[1] = data[1];
301+
msg[2] = data[2];
302+
303+
spi_message_init(&m);
304+
memset(&t, 0, (sizeof t));
305+
306+
t.tx_buf = &msg[0];
307+
t.len = len;
308+
309+
spi_message_add_tail(&t, &m);
310+
spi_sync(spi, &m);
311+
312+
return len;
313+
}
314+
#else
315+
#define snd_soc_8_16_spi_write NULL
316+
#endif
317+
257318
#if defined(CONFIG_I2C) || (defined(CONFIG_I2C_MODULE) && defined(MODULE))
258319
static unsigned int snd_soc_8_8_read_i2c(struct snd_soc_codec *codec,
259320
unsigned int r)
@@ -518,6 +579,38 @@ static int snd_soc_16_16_write(struct snd_soc_codec *codec, unsigned int reg,
518579
return -EIO;
519580
}
520581

582+
#if defined(CONFIG_SPI_MASTER)
583+
static int snd_soc_16_16_spi_write(void *control_data, const char *data,
584+
int len)
585+
{
586+
struct spi_device *spi = control_data;
587+
struct spi_transfer t;
588+
struct spi_message m;
589+
u8 msg[4];
590+
591+
if (len <= 0)
592+
return 0;
593+
594+
msg[0] = data[0];
595+
msg[1] = data[1];
596+
msg[2] = data[2];
597+
msg[3] = data[3];
598+
599+
spi_message_init(&m);
600+
memset(&t, 0, (sizeof t));
601+
602+
t.tx_buf = &msg[0];
603+
t.len = len;
604+
605+
spi_message_add_tail(&t, &m);
606+
spi_sync(spi, &m);
607+
608+
return len;
609+
}
610+
#else
611+
#define snd_soc_16_16_spi_write NULL
612+
#endif
613+
521614
static struct {
522615
int addr_bits;
523616
int data_bits;
@@ -540,11 +633,13 @@ static struct {
540633
.addr_bits = 8, .data_bits = 8,
541634
.write = snd_soc_8_8_write, .read = snd_soc_8_8_read,
542635
.i2c_read = snd_soc_8_8_read_i2c,
636+
.spi_write = snd_soc_8_8_spi_write,
543637
},
544638
{
545639
.addr_bits = 8, .data_bits = 16,
546640
.write = snd_soc_8_16_write, .read = snd_soc_8_16_read,
547641
.i2c_read = snd_soc_8_16_read_i2c,
642+
.spi_write = snd_soc_8_16_spi_write,
548643
},
549644
{
550645
.addr_bits = 16, .data_bits = 8,
@@ -556,6 +651,7 @@ static struct {
556651
.addr_bits = 16, .data_bits = 16,
557652
.write = snd_soc_16_16_write, .read = snd_soc_16_16_read,
558653
.i2c_read = snd_soc_16_16_read_i2c,
654+
.spi_write = snd_soc_16_16_spi_write,
559655
},
560656
};
561657

0 commit comments

Comments
 (0)