aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/soc-cache.c
diff options
context:
space:
mode:
authorMark Brown <broonie@opensource.wolfsonmicro.com>2011-05-29 22:54:18 -0400
committerMark Brown <broonie@opensource.wolfsonmicro.com>2011-05-29 22:54:18 -0400
commitd21685ec258f803d3badae5eae821383a34815a9 (patch)
tree7ab60a2a5d557a4f345b01a79ca2f877c06d9b92 /sound/soc/soc-cache.c
parent74ab24af4fe165de5af01d0507250dd099f096b0 (diff)
parentea02c63d57d7ec099f66ddb2942b4022e865cd5f (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.c140
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 @@
20 20
21#include <trace/events/asoc.h> 21#include <trace/events/asoc.h>
22 22
23#if defined(CONFIG_SPI_MASTER) 23#ifdef CONFIG_SPI_MASTER
24static int do_spi_write(void *control_data, const void *msg, 24static int do_spi_write(void *control, const char *data, int len)
25 int len)
26{ 25{
27 struct spi_device *spi = control_data; 26 struct spi_device *spi = control;
28 struct spi_transfer t; 27 int ret;
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 28
40 spi_message_add_tail(&t, &m); 29 ret = spi_write(spi, data, len);
41 spi_sync(spi, &m); 30 if (ret < 0)
31 return ret;
42 32
43 return len; 33 return len;
44} 34}
@@ -101,28 +91,12 @@ static unsigned int snd_soc_4_12_read(struct snd_soc_codec *codec,
101static int snd_soc_4_12_write(struct snd_soc_codec *codec, unsigned int reg, 91static int snd_soc_4_12_write(struct snd_soc_codec *codec, unsigned int reg,
102 unsigned int value) 92 unsigned int value)
103{ 93{
104 u8 data[2]; 94 u16 data;
105
106 data[0] = (reg << 4) | ((value >> 8) & 0x000f);
107 data[1] = value & 0x00ff;
108
109 return do_hw_write(codec, reg, value, data, 2);
110}
111
112#if defined(CONFIG_SPI_MASTER)
113static int snd_soc_4_12_spi_write(void *control_data, const char *data,
114 int len)
115{
116 u8 msg[2];
117 95
118 msg[0] = data[1]; 96 data = cpu_to_be16((reg << 12) | (value & 0xffffff));
119 msg[1] = data[0];
120 97
121 return do_spi_write(control_data, msg, len); 98 return do_hw_write(codec, reg, value, &data, 2);
122} 99}
123#else
124#define snd_soc_4_12_spi_write NULL
125#endif
126 100
127static unsigned int snd_soc_7_9_read(struct snd_soc_codec *codec, 101static unsigned int snd_soc_7_9_read(struct snd_soc_codec *codec,
128 unsigned int reg) 102 unsigned int reg)
@@ -140,21 +114,6 @@ static int snd_soc_7_9_write(struct snd_soc_codec *codec, unsigned int reg,
140 return do_hw_write(codec, reg, value, &data, 2); 114 return do_hw_write(codec, reg, value, &data, 2);
141} 115}
142 116
143#if defined(CONFIG_SPI_MASTER)
144static int snd_soc_7_9_spi_write(void *control_data, const char *data,
145 int len)
146{
147 u8 msg[2];
148
149 msg[0] = data[0];
150 msg[1] = data[1];
151
152 return do_spi_write(control_data, msg, len);
153}
154#else
155#define snd_soc_7_9_spi_write NULL
156#endif
157
158static int snd_soc_8_8_write(struct snd_soc_codec *codec, unsigned int reg, 117static int snd_soc_8_8_write(struct snd_soc_codec *codec, unsigned int reg,
159 unsigned int value) 118 unsigned int value)
160{ 119{
@@ -173,21 +132,6 @@ static unsigned int snd_soc_8_8_read(struct snd_soc_codec *codec,
173 return do_hw_read(codec, reg); 132 return do_hw_read(codec, reg);
174} 133}
175 134
176#if defined(CONFIG_SPI_MASTER)
177static int snd_soc_8_8_spi_write(void *control_data, const char *data,
178 int len)
179{
180 u8 msg[2];
181
182 msg[0] = data[0];
183 msg[1] = data[1];
184
185 return do_spi_write(control_data, msg, len);
186}
187#else
188#define snd_soc_8_8_spi_write NULL
189#endif
190
191static int snd_soc_8_16_write(struct snd_soc_codec *codec, unsigned int reg, 135static int snd_soc_8_16_write(struct snd_soc_codec *codec, unsigned int reg,
192 unsigned int value) 136 unsigned int value)
193{ 137{
@@ -206,22 +150,6 @@ static unsigned int snd_soc_8_16_read(struct snd_soc_codec *codec,
206 return do_hw_read(codec, reg); 150 return do_hw_read(codec, reg);
207} 151}
208 152
209#if defined(CONFIG_SPI_MASTER)
210static int snd_soc_8_16_spi_write(void *control_data, const char *data,
211 int len)
212{
213 u8 msg[3];
214
215 msg[0] = data[0];
216 msg[1] = data[1];
217 msg[2] = data[2];
218
219 return do_spi_write(control_data, msg, len);
220}
221#else
222#define snd_soc_8_16_spi_write NULL
223#endif
224
225#if defined(CONFIG_I2C) || (defined(CONFIG_I2C_MODULE) && defined(MODULE)) 153#if defined(CONFIG_I2C) || (defined(CONFIG_I2C_MODULE) && defined(MODULE))
226static unsigned int do_i2c_read(struct snd_soc_codec *codec, 154static unsigned int do_i2c_read(struct snd_soc_codec *codec,
227 void *reg, int reglen, 155 void *reg, int reglen,
@@ -318,27 +246,10 @@ static int snd_soc_16_8_write(struct snd_soc_codec *codec, unsigned int reg,
318 246
319 memcpy(data, &rval, sizeof(rval)); 247 memcpy(data, &rval, sizeof(rval));
320 data[2] = value; 248 data[2] = value;
321 reg &= 0xff;
322 249
323 return do_hw_write(codec, reg, value, data, 3); 250 return do_hw_write(codec, reg, value, data, 3);
324} 251}
325 252
326#if defined(CONFIG_SPI_MASTER)
327static int snd_soc_16_8_spi_write(void *control_data, const char *data,
328 int len)
329{
330 u8 msg[3];
331
332 msg[0] = data[0];
333 msg[1] = data[1];
334 msg[2] = data[2];
335
336 return do_spi_write(control_data, msg, len);
337}
338#else
339#define snd_soc_16_8_spi_write NULL
340#endif
341
342#if defined(CONFIG_I2C) || (defined(CONFIG_I2C_MODULE) && defined(MODULE)) 253#if defined(CONFIG_I2C) || (defined(CONFIG_I2C_MODULE) && defined(MODULE))
343static unsigned int snd_soc_16_16_read_i2c(struct snd_soc_codec *codec, 254static unsigned int snd_soc_16_16_read_i2c(struct snd_soc_codec *codec,
344 unsigned int r) 255 unsigned int r)
@@ -373,23 +284,6 @@ static int snd_soc_16_16_write(struct snd_soc_codec *codec, unsigned int reg,
373 return do_hw_write(codec, reg, value, data, sizeof(data)); 284 return do_hw_write(codec, reg, value, data, sizeof(data));
374} 285}
375 286
376#if defined(CONFIG_SPI_MASTER)
377static int snd_soc_16_16_spi_write(void *control_data, const char *data,
378 int len)
379{
380 u8 msg[4];
381
382 msg[0] = data[0];
383 msg[1] = data[1];
384 msg[2] = data[2];
385 msg[3] = data[3];
386
387 return do_spi_write(control_data, msg, len);
388}
389#else
390#define snd_soc_16_16_spi_write NULL
391#endif
392
393/* Primitive bulk write support for soc-cache. The data pointed to by 287/* Primitive bulk write support for soc-cache. The data pointed to by
394 * `data' needs to already be in the form the hardware expects 288 * `data' needs to already be in the form the hardware expects
395 * including any leading register specific data. Any data written 289 * 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
419#endif 313#endif
420#if defined(CONFIG_SPI_MASTER) 314#if defined(CONFIG_SPI_MASTER)
421 case SND_SOC_SPI: 315 case SND_SOC_SPI:
422 ret = do_spi_write(codec->control_data, data, len); 316 ret = spi_write(codec->control_data, data, len);
423 break; 317 break;
424#endif 318#endif
425 default: 319 default:
@@ -438,43 +332,36 @@ static struct {
438 int addr_bits; 332 int addr_bits;
439 int data_bits; 333 int data_bits;
440 int (*write)(struct snd_soc_codec *codec, unsigned int, unsigned int); 334 int (*write)(struct snd_soc_codec *codec, unsigned int, unsigned int);
441 int (*spi_write)(void *, const char *, int);
442 unsigned int (*read)(struct snd_soc_codec *, unsigned int); 335 unsigned int (*read)(struct snd_soc_codec *, unsigned int);
443 unsigned int (*i2c_read)(struct snd_soc_codec *, unsigned int); 336 unsigned int (*i2c_read)(struct snd_soc_codec *, unsigned int);
444} io_types[] = { 337} io_types[] = {
445 { 338 {
446 .addr_bits = 4, .data_bits = 12, 339 .addr_bits = 4, .data_bits = 12,
447 .write = snd_soc_4_12_write, .read = snd_soc_4_12_read, 340 .write = snd_soc_4_12_write, .read = snd_soc_4_12_read,
448 .spi_write = snd_soc_4_12_spi_write,
449 }, 341 },
450 { 342 {
451 .addr_bits = 7, .data_bits = 9, 343 .addr_bits = 7, .data_bits = 9,
452 .write = snd_soc_7_9_write, .read = snd_soc_7_9_read, 344 .write = snd_soc_7_9_write, .read = snd_soc_7_9_read,
453 .spi_write = snd_soc_7_9_spi_write,
454 }, 345 },
455 { 346 {
456 .addr_bits = 8, .data_bits = 8, 347 .addr_bits = 8, .data_bits = 8,
457 .write = snd_soc_8_8_write, .read = snd_soc_8_8_read, 348 .write = snd_soc_8_8_write, .read = snd_soc_8_8_read,
458 .i2c_read = snd_soc_8_8_read_i2c, 349 .i2c_read = snd_soc_8_8_read_i2c,
459 .spi_write = snd_soc_8_8_spi_write,
460 }, 350 },
461 { 351 {
462 .addr_bits = 8, .data_bits = 16, 352 .addr_bits = 8, .data_bits = 16,
463 .write = snd_soc_8_16_write, .read = snd_soc_8_16_read, 353 .write = snd_soc_8_16_write, .read = snd_soc_8_16_read,
464 .i2c_read = snd_soc_8_16_read_i2c, 354 .i2c_read = snd_soc_8_16_read_i2c,
465 .spi_write = snd_soc_8_16_spi_write,
466 }, 355 },
467 { 356 {
468 .addr_bits = 16, .data_bits = 8, 357 .addr_bits = 16, .data_bits = 8,
469 .write = snd_soc_16_8_write, .read = snd_soc_16_8_read, 358 .write = snd_soc_16_8_write, .read = snd_soc_16_8_read,
470 .i2c_read = snd_soc_16_8_read_i2c, 359 .i2c_read = snd_soc_16_8_read_i2c,
471 .spi_write = snd_soc_16_8_spi_write,
472 }, 360 },
473 { 361 {
474 .addr_bits = 16, .data_bits = 16, 362 .addr_bits = 16, .data_bits = 16,
475 .write = snd_soc_16_16_write, .read = snd_soc_16_16_read, 363 .write = snd_soc_16_16_write, .read = snd_soc_16_16_read,
476 .i2c_read = snd_soc_16_16_read_i2c, 364 .i2c_read = snd_soc_16_16_read_i2c,
477 .spi_write = snd_soc_16_16_spi_write,
478 }, 365 },
479}; 366};
480 367
@@ -535,8 +422,9 @@ int snd_soc_codec_set_cache_io(struct snd_soc_codec *codec,
535 break; 422 break;
536 423
537 case SND_SOC_SPI: 424 case SND_SOC_SPI:
538 if (io_types[i].spi_write) 425#ifdef CONFIG_SPI_MASTER
539 codec->hw_write = io_types[i].spi_write; 426 codec->hw_write = do_spi_write;
427#endif
540 428
541 codec->control_data = container_of(codec->dev, 429 codec->control_data = container_of(codec->dev,
542 struct spi_device, 430 struct spi_device,