diff options
author | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2011-05-10 17:33:48 -0400 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2011-05-11 09:56:03 -0400 |
commit | 6e28f976ec73aec688bf89a63ac719ba765e9360 (patch) | |
tree | 577b6bc78be727a4c6843cbe7e1e9778028e782a | |
parent | 063b7cc43fb2413238095b81f9b4a2ee2c52056b (diff) |
ASoC: Use spi_write() for SPI writes
do_spi_write() is just an open coded copy of do_spi_write() so we can
delete it and just call spi_write() directly. Indeed, as a result of
recent refactoring all the SPI write functions are just very long
wrappers around spi_write() which don't add anything except for some
pointless copies so we can just use spi_write() as the hw_write
operation directly. It should be as type safe to do this as it is to do
the same thing with I2C and it saves us a bunch of code.
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Acked-by: Liam Girdwood <lrg@ti.com>
-rw-r--r-- | sound/soc/soc-cache.c | 132 |
1 files changed, 4 insertions, 128 deletions
diff --git a/sound/soc/soc-cache.c b/sound/soc/soc-cache.c index 73907e5f078f..01e5b9846436 100644 --- a/sound/soc/soc-cache.c +++ b/sound/soc/soc-cache.c | |||
@@ -20,30 +20,6 @@ | |||
20 | 20 | ||
21 | #include <trace/events/asoc.h> | 21 | #include <trace/events/asoc.h> |
22 | 22 | ||
23 | #if defined(CONFIG_SPI_MASTER) | ||
24 | static 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 | |||
47 | static int do_hw_write(struct snd_soc_codec *codec, unsigned int reg, | 23 | static int do_hw_write(struct snd_soc_codec *codec, unsigned int reg, |
48 | unsigned int value, const void *data, int len) | 24 | unsigned int value, const void *data, int len) |
49 | { | 25 | { |
@@ -108,21 +84,6 @@ static int snd_soc_4_12_write(struct snd_soc_codec *codec, unsigned int reg, | |||
108 | return do_hw_write(codec, reg, value, &data, 2); | 84 | return do_hw_write(codec, reg, value, &data, 2); |
109 | } | 85 | } |
110 | 86 | ||
111 | #if defined(CONFIG_SPI_MASTER) | ||
112 | static int snd_soc_4_12_spi_write(void *control_data, const char *data, | ||
113 | int len) | ||
114 | { | ||
115 | u8 msg[2]; | ||
116 | |||
117 | msg[0] = data[0]; | ||
118 | msg[1] = data[1]; | ||
119 | |||
120 | return do_spi_write(control_data, msg, len); | ||
121 | } | ||
122 | #else | ||
123 | #define snd_soc_4_12_spi_write NULL | ||
124 | #endif | ||
125 | |||
126 | static unsigned int snd_soc_7_9_read(struct snd_soc_codec *codec, | 87 | static unsigned int snd_soc_7_9_read(struct snd_soc_codec *codec, |
127 | unsigned int reg) | 88 | unsigned int reg) |
128 | { | 89 | { |
@@ -140,21 +101,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); | 101 | return do_hw_write(codec, reg, value, data, 2); |
141 | } | 102 | } |
142 | 103 | ||
143 | #if defined(CONFIG_SPI_MASTER) | ||
144 | static 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 | |||
158 | static int snd_soc_8_8_write(struct snd_soc_codec *codec, unsigned int reg, | 104 | static int snd_soc_8_8_write(struct snd_soc_codec *codec, unsigned int reg, |
159 | unsigned int value) | 105 | unsigned int value) |
160 | { | 106 | { |
@@ -173,21 +119,6 @@ static unsigned int snd_soc_8_8_read(struct snd_soc_codec *codec, | |||
173 | return do_hw_read(codec, reg); | 119 | return do_hw_read(codec, reg); |
174 | } | 120 | } |
175 | 121 | ||
176 | #if defined(CONFIG_SPI_MASTER) | ||
177 | static 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 | |||
191 | static int snd_soc_8_16_write(struct snd_soc_codec *codec, unsigned int reg, | 122 | static int snd_soc_8_16_write(struct snd_soc_codec *codec, unsigned int reg, |
192 | unsigned int value) | 123 | unsigned int value) |
193 | { | 124 | { |
@@ -206,22 +137,6 @@ static unsigned int snd_soc_8_16_read(struct snd_soc_codec *codec, | |||
206 | return do_hw_read(codec, reg); | 137 | return do_hw_read(codec, reg); |
207 | } | 138 | } |
208 | 139 | ||
209 | #if defined(CONFIG_SPI_MASTER) | ||
210 | static 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)) | 140 | #if defined(CONFIG_I2C) || (defined(CONFIG_I2C_MODULE) && defined(MODULE)) |
226 | static unsigned int do_i2c_read(struct snd_soc_codec *codec, | 141 | static unsigned int do_i2c_read(struct snd_soc_codec *codec, |
227 | void *reg, int reglen, | 142 | void *reg, int reglen, |
@@ -322,22 +237,6 @@ static int snd_soc_16_8_write(struct snd_soc_codec *codec, unsigned int reg, | |||
322 | return do_hw_write(codec, reg, value, data, 3); | 237 | return do_hw_write(codec, reg, value, data, 3); |
323 | } | 238 | } |
324 | 239 | ||
325 | #if defined(CONFIG_SPI_MASTER) | ||
326 | static int snd_soc_16_8_spi_write(void *control_data, const char *data, | ||
327 | int len) | ||
328 | { | ||
329 | u8 msg[3]; | ||
330 | |||
331 | msg[0] = data[0]; | ||
332 | msg[1] = data[1]; | ||
333 | msg[2] = data[2]; | ||
334 | |||
335 | return do_spi_write(control_data, msg, len); | ||
336 | } | ||
337 | #else | ||
338 | #define snd_soc_16_8_spi_write NULL | ||
339 | #endif | ||
340 | |||
341 | #if defined(CONFIG_I2C) || (defined(CONFIG_I2C_MODULE) && defined(MODULE)) | 240 | #if defined(CONFIG_I2C) || (defined(CONFIG_I2C_MODULE) && defined(MODULE)) |
342 | static unsigned int snd_soc_16_16_read_i2c(struct snd_soc_codec *codec, | 241 | static unsigned int snd_soc_16_16_read_i2c(struct snd_soc_codec *codec, |
343 | unsigned int r) | 242 | unsigned int r) |
@@ -374,23 +273,6 @@ static int snd_soc_16_16_write(struct snd_soc_codec *codec, unsigned int reg, | |||
374 | return do_hw_write(codec, reg, value, data, 4); | 273 | return do_hw_write(codec, reg, value, data, 4); |
375 | } | 274 | } |
376 | 275 | ||
377 | #if defined(CONFIG_SPI_MASTER) | ||
378 | static int snd_soc_16_16_spi_write(void *control_data, const char *data, | ||
379 | int len) | ||
380 | { | ||
381 | u8 msg[4]; | ||
382 | |||
383 | msg[0] = data[0]; | ||
384 | msg[1] = data[1]; | ||
385 | msg[2] = data[2]; | ||
386 | msg[3] = data[3]; | ||
387 | |||
388 | return do_spi_write(control_data, msg, len); | ||
389 | } | ||
390 | #else | ||
391 | #define snd_soc_16_16_spi_write NULL | ||
392 | #endif | ||
393 | |||
394 | /* Primitive bulk write support for soc-cache. The data pointed to by | 276 | /* Primitive bulk write support for soc-cache. The data pointed to by |
395 | * `data' needs to already be in the form the hardware expects | 277 | * `data' needs to already be in the form the hardware expects |
396 | * including any leading register specific data. Any data written | 278 | * including any leading register specific data. Any data written |
@@ -420,7 +302,7 @@ static int snd_soc_hw_bulk_write_raw(struct snd_soc_codec *codec, unsigned int r | |||
420 | #endif | 302 | #endif |
421 | #if defined(CONFIG_SPI_MASTER) | 303 | #if defined(CONFIG_SPI_MASTER) |
422 | case SND_SOC_SPI: | 304 | case SND_SOC_SPI: |
423 | ret = do_spi_write(codec->control_data, data, len); | 305 | ret = spi_write(codec->control_data, data, len); |
424 | break; | 306 | break; |
425 | #endif | 307 | #endif |
426 | default: | 308 | default: |
@@ -439,43 +321,36 @@ static struct { | |||
439 | int addr_bits; | 321 | int addr_bits; |
440 | int data_bits; | 322 | int data_bits; |
441 | int (*write)(struct snd_soc_codec *codec, unsigned int, unsigned int); | 323 | int (*write)(struct snd_soc_codec *codec, unsigned int, unsigned int); |
442 | int (*spi_write)(void *, const char *, int); | ||
443 | unsigned int (*read)(struct snd_soc_codec *, unsigned int); | 324 | unsigned int (*read)(struct snd_soc_codec *, unsigned int); |
444 | unsigned int (*i2c_read)(struct snd_soc_codec *, unsigned int); | 325 | unsigned int (*i2c_read)(struct snd_soc_codec *, unsigned int); |
445 | } io_types[] = { | 326 | } io_types[] = { |
446 | { | 327 | { |
447 | .addr_bits = 4, .data_bits = 12, | 328 | .addr_bits = 4, .data_bits = 12, |
448 | .write = snd_soc_4_12_write, .read = snd_soc_4_12_read, | 329 | .write = snd_soc_4_12_write, .read = snd_soc_4_12_read, |
449 | .spi_write = snd_soc_4_12_spi_write, | ||
450 | }, | 330 | }, |
451 | { | 331 | { |
452 | .addr_bits = 7, .data_bits = 9, | 332 | .addr_bits = 7, .data_bits = 9, |
453 | .write = snd_soc_7_9_write, .read = snd_soc_7_9_read, | 333 | .write = snd_soc_7_9_write, .read = snd_soc_7_9_read, |
454 | .spi_write = snd_soc_7_9_spi_write, | ||
455 | }, | 334 | }, |
456 | { | 335 | { |
457 | .addr_bits = 8, .data_bits = 8, | 336 | .addr_bits = 8, .data_bits = 8, |
458 | .write = snd_soc_8_8_write, .read = snd_soc_8_8_read, | 337 | .write = snd_soc_8_8_write, .read = snd_soc_8_8_read, |
459 | .i2c_read = snd_soc_8_8_read_i2c, | 338 | .i2c_read = snd_soc_8_8_read_i2c, |
460 | .spi_write = snd_soc_8_8_spi_write, | ||
461 | }, | 339 | }, |
462 | { | 340 | { |
463 | .addr_bits = 8, .data_bits = 16, | 341 | .addr_bits = 8, .data_bits = 16, |
464 | .write = snd_soc_8_16_write, .read = snd_soc_8_16_read, | 342 | .write = snd_soc_8_16_write, .read = snd_soc_8_16_read, |
465 | .i2c_read = snd_soc_8_16_read_i2c, | 343 | .i2c_read = snd_soc_8_16_read_i2c, |
466 | .spi_write = snd_soc_8_16_spi_write, | ||
467 | }, | 344 | }, |
468 | { | 345 | { |
469 | .addr_bits = 16, .data_bits = 8, | 346 | .addr_bits = 16, .data_bits = 8, |
470 | .write = snd_soc_16_8_write, .read = snd_soc_16_8_read, | 347 | .write = snd_soc_16_8_write, .read = snd_soc_16_8_read, |
471 | .i2c_read = snd_soc_16_8_read_i2c, | 348 | .i2c_read = snd_soc_16_8_read_i2c, |
472 | .spi_write = snd_soc_16_8_spi_write, | ||
473 | }, | 349 | }, |
474 | { | 350 | { |
475 | .addr_bits = 16, .data_bits = 16, | 351 | .addr_bits = 16, .data_bits = 16, |
476 | .write = snd_soc_16_16_write, .read = snd_soc_16_16_read, | 352 | .write = snd_soc_16_16_write, .read = snd_soc_16_16_read, |
477 | .i2c_read = snd_soc_16_16_read_i2c, | 353 | .i2c_read = snd_soc_16_16_read_i2c, |
478 | .spi_write = snd_soc_16_16_spi_write, | ||
479 | }, | 354 | }, |
480 | }; | 355 | }; |
481 | 356 | ||
@@ -536,8 +411,9 @@ int snd_soc_codec_set_cache_io(struct snd_soc_codec *codec, | |||
536 | break; | 411 | break; |
537 | 412 | ||
538 | case SND_SOC_SPI: | 413 | case SND_SOC_SPI: |
539 | if (io_types[i].spi_write) | 414 | #ifdef CONFIG_SPI_MASTER |
540 | codec->hw_write = io_types[i].spi_write; | 415 | codec->hw_write = (hw_write_t)spi_write; |
416 | #endif | ||
541 | 417 | ||
542 | codec->control_data = container_of(codec->dev, | 418 | codec->control_data = container_of(codec->dev, |
543 | struct spi_device, | 419 | struct spi_device, |