aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/soc-cache.c
diff options
context:
space:
mode:
authorDimitris Papastamos <dp@opensource.wolfsonmicro.com>2011-03-22 06:37:00 -0400
committerMark Brown <broonie@opensource.wolfsonmicro.com>2011-03-26 13:44:56 -0400
commit30539a18d366cff6b21f66a81e4d9dccc4a90c89 (patch)
treeb09d68bd592f85ac05d617d5ce40ec623c36c9c0 /sound/soc/soc-cache.c
parentb8cbc195202d05efcda6af81c669577e3cb793e5 (diff)
ASoC: soc-cache: Factor-out the SPI write code
The handling of all snd_soc_x_y_spi_write() functions is similar. Create a separate function and update all callers to use it. Signed-off-by: Dimitris Papastamos <dp@opensource.wolfsonmicro.com> Acked-by: Liam Girdwood <lrg@ti.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'sound/soc/soc-cache.c')
-rw-r--r--sound/soc/soc-cache.c126
1 files changed, 30 insertions, 96 deletions
diff --git a/sound/soc/soc-cache.c b/sound/soc/soc-cache.c
index abb0243f3adf..d7bffdd033b0 100644
--- a/sound/soc/soc-cache.c
+++ b/sound/soc/soc-cache.c
@@ -20,6 +20,30 @@
20 20
21#include <trace/events/asoc.h> 21#include <trace/events/asoc.h>
22 22
23#if defined(CONFIG_SPI_MASTER)
24static int do_spi_write(void *control_data, const void *msg,
25 int len)
26{
27 struct spi_device *spi = control_data;
28 struct spi_transfer t;
29 struct spi_message m;
30
31 if (len <= 0)
32 return 0;
33
34 spi_message_init(&m);
35 memset(&t, 0, sizeof t);
36
37 t.tx_buf = msg;
38 t.len = len;
39
40 spi_message_add_tail(&t, &m);
41 spi_sync(spi, &m);
42
43 return len;
44}
45#endif
46
23static int do_hw_write(struct snd_soc_codec *codec, unsigned int reg, 47static int do_hw_write(struct snd_soc_codec *codec, unsigned int reg,
24 unsigned int value, const void *data, int len) 48 unsigned int value, const void *data, int len)
25{ 49{
@@ -89,27 +113,12 @@ static int snd_soc_4_12_write(struct snd_soc_codec *codec, unsigned int reg,
89static int snd_soc_4_12_spi_write(void *control_data, const char *data, 113static int snd_soc_4_12_spi_write(void *control_data, const char *data,
90 int len) 114 int len)
91{ 115{
92 struct spi_device *spi = control_data;
93 struct spi_transfer t;
94 struct spi_message m;
95 u8 msg[2]; 116 u8 msg[2];
96 117
97 if (len <= 0)
98 return 0;
99
100 msg[0] = data[1]; 118 msg[0] = data[1];
101 msg[1] = data[0]; 119 msg[1] = data[0];
102 120
103 spi_message_init(&m); 121 return do_spi_write(control_data, msg, len);
104 memset(&t, 0, sizeof t);
105
106 t.tx_buf = &msg[0];
107 t.len = len;
108
109 spi_message_add_tail(&t, &m);
110 spi_sync(spi, &m);
111
112 return len;
113} 122}
114#else 123#else
115#define snd_soc_4_12_spi_write NULL 124#define snd_soc_4_12_spi_write NULL
@@ -136,27 +145,12 @@ static int snd_soc_7_9_write(struct snd_soc_codec *codec, unsigned int reg,
136static int snd_soc_7_9_spi_write(void *control_data, const char *data, 145static int snd_soc_7_9_spi_write(void *control_data, const char *data,
137 int len) 146 int len)
138{ 147{
139 struct spi_device *spi = control_data;
140 struct spi_transfer t;
141 struct spi_message m;
142 u8 msg[2]; 148 u8 msg[2];
143 149
144 if (len <= 0)
145 return 0;
146
147 msg[0] = data[0]; 150 msg[0] = data[0];
148 msg[1] = data[1]; 151 msg[1] = data[1];
149 152
150 spi_message_init(&m); 153 return do_spi_write(control_data, msg, len);
151 memset(&t, 0, sizeof t);
152
153 t.tx_buf = &msg[0];
154 t.len = len;
155
156 spi_message_add_tail(&t, &m);
157 spi_sync(spi, &m);
158
159 return len;
160} 154}
161#else 155#else
162#define snd_soc_7_9_spi_write NULL 156#define snd_soc_7_9_spi_write NULL
@@ -184,27 +178,12 @@ static unsigned int snd_soc_8_8_read(struct snd_soc_codec *codec,
184static int snd_soc_8_8_spi_write(void *control_data, const char *data, 178static int snd_soc_8_8_spi_write(void *control_data, const char *data,
185 int len) 179 int len)
186{ 180{
187 struct spi_device *spi = control_data;
188 struct spi_transfer t;
189 struct spi_message m;
190 u8 msg[2]; 181 u8 msg[2];
191 182
192 if (len <= 0)
193 return 0;
194
195 msg[0] = data[0]; 183 msg[0] = data[0];
196 msg[1] = data[1]; 184 msg[1] = data[1];
197 185
198 spi_message_init(&m); 186 return do_spi_write(control_data, msg, len);
199 memset(&t, 0, sizeof t);
200
201 t.tx_buf = &msg[0];
202 t.len = len;
203
204 spi_message_add_tail(&t, &m);
205 spi_sync(spi, &m);
206
207 return len;
208} 187}
209#else 188#else
210#define snd_soc_8_8_spi_write NULL 189#define snd_soc_8_8_spi_write NULL
@@ -232,28 +211,13 @@ static unsigned int snd_soc_8_16_read(struct snd_soc_codec *codec,
232static int snd_soc_8_16_spi_write(void *control_data, const char *data, 211static int snd_soc_8_16_spi_write(void *control_data, const char *data,
233 int len) 212 int len)
234{ 213{
235 struct spi_device *spi = control_data;
236 struct spi_transfer t;
237 struct spi_message m;
238 u8 msg[3]; 214 u8 msg[3];
239 215
240 if (len <= 0)
241 return 0;
242
243 msg[0] = data[0]; 216 msg[0] = data[0];
244 msg[1] = data[1]; 217 msg[1] = data[1];
245 msg[2] = data[2]; 218 msg[2] = data[2];
246 219
247 spi_message_init(&m); 220 return do_spi_write(control_data, msg, len);
248 memset(&t, 0, sizeof t);
249
250 t.tx_buf = &msg[0];
251 t.len = len;
252
253 spi_message_add_tail(&t, &m);
254 spi_sync(spi, &m);
255
256 return len;
257} 221}
258#else 222#else
259#define snd_soc_8_16_spi_write NULL 223#define snd_soc_8_16_spi_write NULL
@@ -365,28 +329,13 @@ static int snd_soc_16_8_write(struct snd_soc_codec *codec, unsigned int reg,
365static int snd_soc_16_8_spi_write(void *control_data, const char *data, 329static int snd_soc_16_8_spi_write(void *control_data, const char *data,
366 int len) 330 int len)
367{ 331{
368 struct spi_device *spi = control_data;
369 struct spi_transfer t;
370 struct spi_message m;
371 u8 msg[3]; 332 u8 msg[3];
372 333
373 if (len <= 0)
374 return 0;
375
376 msg[0] = data[0]; 334 msg[0] = data[0];
377 msg[1] = data[1]; 335 msg[1] = data[1];
378 msg[2] = data[2]; 336 msg[2] = data[2];
379 337
380 spi_message_init(&m); 338 return do_spi_write(control_data, msg, len);
381 memset(&t, 0, sizeof t);
382
383 t.tx_buf = &msg[0];
384 t.len = len;
385
386 spi_message_add_tail(&t, &m);
387 spi_sync(spi, &m);
388
389 return len;
390} 339}
391#else 340#else
392#define snd_soc_16_8_spi_write NULL 341#define snd_soc_16_8_spi_write NULL
@@ -432,29 +381,14 @@ static int snd_soc_16_16_write(struct snd_soc_codec *codec, unsigned int reg,
432static int snd_soc_16_16_spi_write(void *control_data, const char *data, 381static int snd_soc_16_16_spi_write(void *control_data, const char *data,
433 int len) 382 int len)
434{ 383{
435 struct spi_device *spi = control_data;
436 struct spi_transfer t;
437 struct spi_message m;
438 u8 msg[4]; 384 u8 msg[4];
439 385
440 if (len <= 0)
441 return 0;
442
443 msg[0] = data[0]; 386 msg[0] = data[0];
444 msg[1] = data[1]; 387 msg[1] = data[1];
445 msg[2] = data[2]; 388 msg[2] = data[2];
446 msg[3] = data[3]; 389 msg[3] = data[3];
447 390
448 spi_message_init(&m); 391 return do_spi_write(control_data, msg, len);
449 memset(&t, 0, sizeof t);
450
451 t.tx_buf = &msg[0];
452 t.len = len;
453
454 spi_message_add_tail(&t, &m);
455 spi_sync(spi, &m);
456
457 return len;
458} 392}
459#else 393#else
460#define snd_soc_16_16_spi_write NULL 394#define snd_soc_16_16_spi_write NULL