@@ -211,6 +211,36 @@ static unsigned int snd_soc_8_8_read(struct snd_soc_codec *codec,
211
211
return cache [reg ];
212
212
}
213
213
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
+
214
244
static int snd_soc_8_16_write (struct snd_soc_codec * codec , unsigned int reg ,
215
245
unsigned int value )
216
246
{
@@ -254,6 +284,37 @@ static unsigned int snd_soc_8_16_read(struct snd_soc_codec *codec,
254
284
}
255
285
}
256
286
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
+
257
318
#if defined(CONFIG_I2C ) || (defined(CONFIG_I2C_MODULE ) && defined(MODULE ))
258
319
static unsigned int snd_soc_8_8_read_i2c (struct snd_soc_codec * codec ,
259
320
unsigned int r )
@@ -518,6 +579,38 @@ static int snd_soc_16_16_write(struct snd_soc_codec *codec, unsigned int reg,
518
579
return - EIO ;
519
580
}
520
581
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
+
521
614
static struct {
522
615
int addr_bits ;
523
616
int data_bits ;
@@ -540,11 +633,13 @@ static struct {
540
633
.addr_bits = 8 , .data_bits = 8 ,
541
634
.write = snd_soc_8_8_write , .read = snd_soc_8_8_read ,
542
635
.i2c_read = snd_soc_8_8_read_i2c ,
636
+ .spi_write = snd_soc_8_8_spi_write ,
543
637
},
544
638
{
545
639
.addr_bits = 8 , .data_bits = 16 ,
546
640
.write = snd_soc_8_16_write , .read = snd_soc_8_16_read ,
547
641
.i2c_read = snd_soc_8_16_read_i2c ,
642
+ .spi_write = snd_soc_8_16_spi_write ,
548
643
},
549
644
{
550
645
.addr_bits = 16 , .data_bits = 8 ,
@@ -556,6 +651,7 @@ static struct {
556
651
.addr_bits = 16 , .data_bits = 16 ,
557
652
.write = snd_soc_16_16_write , .read = snd_soc_16_16_read ,
558
653
.i2c_read = snd_soc_16_16_read_i2c ,
654
+ .spi_write = snd_soc_16_16_spi_write ,
559
655
},
560
656
};
561
657
0 commit comments