diff options
Diffstat (limited to 'sound')
251 files changed, 21166 insertions, 7963 deletions
diff --git a/sound/atmel/ac97c.c b/sound/atmel/ac97c.c index 115313ef54d6..f5ded640b395 100644 --- a/sound/atmel/ac97c.c +++ b/sound/atmel/ac97c.c | |||
@@ -991,6 +991,8 @@ static int __devinit atmel_ac97c_probe(struct platform_device *pdev) | |||
991 | gpio_direction_output(pdata->reset_pin, 1); | 991 | gpio_direction_output(pdata->reset_pin, 1); |
992 | chip->reset_pin = pdata->reset_pin; | 992 | chip->reset_pin = pdata->reset_pin; |
993 | } | 993 | } |
994 | } else { | ||
995 | chip->reset_pin = -EINVAL; | ||
994 | } | 996 | } |
995 | 997 | ||
996 | snd_card_set_dev(card, &pdev->dev); | 998 | snd_card_set_dev(card, &pdev->dev); |
diff --git a/sound/core/jack.c b/sound/core/jack.c index 471e1e3b0a99..a06b1651fcba 100644 --- a/sound/core/jack.c +++ b/sound/core/jack.c | |||
@@ -155,7 +155,7 @@ EXPORT_SYMBOL(snd_jack_new); | |||
155 | * @jack: The jack to configure | 155 | * @jack: The jack to configure |
156 | * @parent: The device to set as parent for the jack. | 156 | * @parent: The device to set as parent for the jack. |
157 | * | 157 | * |
158 | * Set the parent for the jack input device in the device tree. This | 158 | * Set the parent for the jack devices in the device tree. This |
159 | * function is only valid prior to registration of the jack. If no | 159 | * function is only valid prior to registration of the jack. If no |
160 | * parent is configured then the parent device will be the sound card. | 160 | * parent is configured then the parent device will be the sound card. |
161 | */ | 161 | */ |
@@ -179,6 +179,9 @@ EXPORT_SYMBOL(snd_jack_set_parent); | |||
179 | * mapping is provided but keys are enabled in the jack type then | 179 | * mapping is provided but keys are enabled in the jack type then |
180 | * BTN_n numeric buttons will be reported. | 180 | * BTN_n numeric buttons will be reported. |
181 | * | 181 | * |
182 | * If jacks are not reporting via the input API this call will have no | ||
183 | * effect. | ||
184 | * | ||
182 | * Note that this is intended to be use by simple devices with small | 185 | * Note that this is intended to be use by simple devices with small |
183 | * numbers of keys that can be reported. It is also possible to | 186 | * numbers of keys that can be reported. It is also possible to |
184 | * access the input device directly - devices with complex input | 187 | * access the input device directly - devices with complex input |
diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c index 4d18941178e6..faedb1481b24 100644 --- a/sound/core/pcm_lib.c +++ b/sound/core/pcm_lib.c | |||
@@ -1894,6 +1894,7 @@ static snd_pcm_sframes_t snd_pcm_lib_write1(struct snd_pcm_substream *substream, | |||
1894 | struct snd_pcm_runtime *runtime = substream->runtime; | 1894 | struct snd_pcm_runtime *runtime = substream->runtime; |
1895 | snd_pcm_uframes_t xfer = 0; | 1895 | snd_pcm_uframes_t xfer = 0; |
1896 | snd_pcm_uframes_t offset = 0; | 1896 | snd_pcm_uframes_t offset = 0; |
1897 | snd_pcm_uframes_t avail; | ||
1897 | int err = 0; | 1898 | int err = 0; |
1898 | 1899 | ||
1899 | if (size == 0) | 1900 | if (size == 0) |
@@ -1917,13 +1918,12 @@ static snd_pcm_sframes_t snd_pcm_lib_write1(struct snd_pcm_substream *substream, | |||
1917 | } | 1918 | } |
1918 | 1919 | ||
1919 | runtime->twake = runtime->control->avail_min ? : 1; | 1920 | runtime->twake = runtime->control->avail_min ? : 1; |
1921 | if (runtime->status->state == SNDRV_PCM_STATE_RUNNING) | ||
1922 | snd_pcm_update_hw_ptr(substream); | ||
1923 | avail = snd_pcm_playback_avail(runtime); | ||
1920 | while (size > 0) { | 1924 | while (size > 0) { |
1921 | snd_pcm_uframes_t frames, appl_ptr, appl_ofs; | 1925 | snd_pcm_uframes_t frames, appl_ptr, appl_ofs; |
1922 | snd_pcm_uframes_t avail; | ||
1923 | snd_pcm_uframes_t cont; | 1926 | snd_pcm_uframes_t cont; |
1924 | if (runtime->status->state == SNDRV_PCM_STATE_RUNNING) | ||
1925 | snd_pcm_update_hw_ptr(substream); | ||
1926 | avail = snd_pcm_playback_avail(runtime); | ||
1927 | if (!avail) { | 1927 | if (!avail) { |
1928 | if (nonblock) { | 1928 | if (nonblock) { |
1929 | err = -EAGAIN; | 1929 | err = -EAGAIN; |
@@ -1971,6 +1971,7 @@ static snd_pcm_sframes_t snd_pcm_lib_write1(struct snd_pcm_substream *substream, | |||
1971 | offset += frames; | 1971 | offset += frames; |
1972 | size -= frames; | 1972 | size -= frames; |
1973 | xfer += frames; | 1973 | xfer += frames; |
1974 | avail -= frames; | ||
1974 | if (runtime->status->state == SNDRV_PCM_STATE_PREPARED && | 1975 | if (runtime->status->state == SNDRV_PCM_STATE_PREPARED && |
1975 | snd_pcm_playback_hw_avail(runtime) >= (snd_pcm_sframes_t)runtime->start_threshold) { | 1976 | snd_pcm_playback_hw_avail(runtime) >= (snd_pcm_sframes_t)runtime->start_threshold) { |
1976 | err = snd_pcm_start(substream); | 1977 | err = snd_pcm_start(substream); |
@@ -2111,6 +2112,7 @@ static snd_pcm_sframes_t snd_pcm_lib_read1(struct snd_pcm_substream *substream, | |||
2111 | struct snd_pcm_runtime *runtime = substream->runtime; | 2112 | struct snd_pcm_runtime *runtime = substream->runtime; |
2112 | snd_pcm_uframes_t xfer = 0; | 2113 | snd_pcm_uframes_t xfer = 0; |
2113 | snd_pcm_uframes_t offset = 0; | 2114 | snd_pcm_uframes_t offset = 0; |
2115 | snd_pcm_uframes_t avail; | ||
2114 | int err = 0; | 2116 | int err = 0; |
2115 | 2117 | ||
2116 | if (size == 0) | 2118 | if (size == 0) |
@@ -2141,13 +2143,12 @@ static snd_pcm_sframes_t snd_pcm_lib_read1(struct snd_pcm_substream *substream, | |||
2141 | } | 2143 | } |
2142 | 2144 | ||
2143 | runtime->twake = runtime->control->avail_min ? : 1; | 2145 | runtime->twake = runtime->control->avail_min ? : 1; |
2146 | if (runtime->status->state == SNDRV_PCM_STATE_RUNNING) | ||
2147 | snd_pcm_update_hw_ptr(substream); | ||
2148 | avail = snd_pcm_capture_avail(runtime); | ||
2144 | while (size > 0) { | 2149 | while (size > 0) { |
2145 | snd_pcm_uframes_t frames, appl_ptr, appl_ofs; | 2150 | snd_pcm_uframes_t frames, appl_ptr, appl_ofs; |
2146 | snd_pcm_uframes_t avail; | ||
2147 | snd_pcm_uframes_t cont; | 2151 | snd_pcm_uframes_t cont; |
2148 | if (runtime->status->state == SNDRV_PCM_STATE_RUNNING) | ||
2149 | snd_pcm_update_hw_ptr(substream); | ||
2150 | avail = snd_pcm_capture_avail(runtime); | ||
2151 | if (!avail) { | 2152 | if (!avail) { |
2152 | if (runtime->status->state == | 2153 | if (runtime->status->state == |
2153 | SNDRV_PCM_STATE_DRAINING) { | 2154 | SNDRV_PCM_STATE_DRAINING) { |
@@ -2202,6 +2203,7 @@ static snd_pcm_sframes_t snd_pcm_lib_read1(struct snd_pcm_substream *substream, | |||
2202 | offset += frames; | 2203 | offset += frames; |
2203 | size -= frames; | 2204 | size -= frames; |
2204 | xfer += frames; | 2205 | xfer += frames; |
2206 | avail -= frames; | ||
2205 | } | 2207 | } |
2206 | _end_unlock: | 2208 | _end_unlock: |
2207 | runtime->twake = 0; | 2209 | runtime->twake = 0; |
diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c index 3fe99e644eb8..53b5ada8f7c3 100644 --- a/sound/core/pcm_native.c +++ b/sound/core/pcm_native.c | |||
@@ -1360,7 +1360,14 @@ static int snd_pcm_prepare(struct snd_pcm_substream *substream, | |||
1360 | 1360 | ||
1361 | static int snd_pcm_pre_drain_init(struct snd_pcm_substream *substream, int state) | 1361 | static int snd_pcm_pre_drain_init(struct snd_pcm_substream *substream, int state) |
1362 | { | 1362 | { |
1363 | substream->runtime->trigger_master = substream; | 1363 | struct snd_pcm_runtime *runtime = substream->runtime; |
1364 | switch (runtime->status->state) { | ||
1365 | case SNDRV_PCM_STATE_OPEN: | ||
1366 | case SNDRV_PCM_STATE_DISCONNECTED: | ||
1367 | case SNDRV_PCM_STATE_SUSPENDED: | ||
1368 | return -EBADFD; | ||
1369 | } | ||
1370 | runtime->trigger_master = substream; | ||
1364 | return 0; | 1371 | return 0; |
1365 | } | 1372 | } |
1366 | 1373 | ||
@@ -1379,6 +1386,9 @@ static int snd_pcm_do_drain_init(struct snd_pcm_substream *substream, int state) | |||
1379 | case SNDRV_PCM_STATE_RUNNING: | 1386 | case SNDRV_PCM_STATE_RUNNING: |
1380 | runtime->status->state = SNDRV_PCM_STATE_DRAINING; | 1387 | runtime->status->state = SNDRV_PCM_STATE_DRAINING; |
1381 | break; | 1388 | break; |
1389 | case SNDRV_PCM_STATE_XRUN: | ||
1390 | runtime->status->state = SNDRV_PCM_STATE_SETUP; | ||
1391 | break; | ||
1382 | default: | 1392 | default: |
1383 | break; | 1393 | break; |
1384 | } | 1394 | } |
diff --git a/sound/core/sound_oss.c b/sound/core/sound_oss.c index c70092043061..e9528333e36d 100644 --- a/sound/core/sound_oss.c +++ b/sound/core/sound_oss.c | |||
@@ -35,7 +35,7 @@ | |||
35 | #include <linux/sound.h> | 35 | #include <linux/sound.h> |
36 | #include <linux/mutex.h> | 36 | #include <linux/mutex.h> |
37 | 37 | ||
38 | #define SNDRV_OSS_MINORS 128 | 38 | #define SNDRV_OSS_MINORS 256 |
39 | 39 | ||
40 | static struct snd_minor *snd_oss_minors[SNDRV_OSS_MINORS]; | 40 | static struct snd_minor *snd_oss_minors[SNDRV_OSS_MINORS]; |
41 | static DEFINE_MUTEX(sound_oss_mutex); | 41 | static DEFINE_MUTEX(sound_oss_mutex); |
@@ -111,7 +111,7 @@ int snd_register_oss_device(int type, struct snd_card *card, int dev, | |||
111 | int register1 = -1, register2 = -1; | 111 | int register1 = -1, register2 = -1; |
112 | struct device *carddev = snd_card_get_device_link(card); | 112 | struct device *carddev = snd_card_get_device_link(card); |
113 | 113 | ||
114 | if (card && card->number >= 8) | 114 | if (card && card->number >= SNDRV_MINOR_OSS_DEVICES) |
115 | return 0; /* ignore silently */ | 115 | return 0; /* ignore silently */ |
116 | if (minor < 0) | 116 | if (minor < 0) |
117 | return minor; | 117 | return minor; |
@@ -170,7 +170,7 @@ int snd_unregister_oss_device(int type, struct snd_card *card, int dev) | |||
170 | int track2 = -1; | 170 | int track2 = -1; |
171 | struct snd_minor *mptr; | 171 | struct snd_minor *mptr; |
172 | 172 | ||
173 | if (card && card->number >= 8) | 173 | if (card && card->number >= SNDRV_MINOR_OSS_DEVICES) |
174 | return 0; | 174 | return 0; |
175 | if (minor < 0) | 175 | if (minor < 0) |
176 | return minor; | 176 | return minor; |
diff --git a/sound/drivers/aloop.c b/sound/drivers/aloop.c index ad079b63b8ba..8b5c36f4d303 100644 --- a/sound/drivers/aloop.c +++ b/sound/drivers/aloop.c | |||
@@ -117,6 +117,7 @@ struct loopback_pcm { | |||
117 | /* timer stuff */ | 117 | /* timer stuff */ |
118 | unsigned int irq_pos; /* fractional IRQ position */ | 118 | unsigned int irq_pos; /* fractional IRQ position */ |
119 | unsigned int period_size_frac; | 119 | unsigned int period_size_frac; |
120 | unsigned int last_drift; | ||
120 | unsigned long last_jiffies; | 121 | unsigned long last_jiffies; |
121 | struct timer_list timer; | 122 | struct timer_list timer; |
122 | }; | 123 | }; |
@@ -264,6 +265,7 @@ static int loopback_trigger(struct snd_pcm_substream *substream, int cmd) | |||
264 | return err; | 265 | return err; |
265 | dpcm->last_jiffies = jiffies; | 266 | dpcm->last_jiffies = jiffies; |
266 | dpcm->pcm_rate_shift = 0; | 267 | dpcm->pcm_rate_shift = 0; |
268 | dpcm->last_drift = 0; | ||
267 | spin_lock(&cable->lock); | 269 | spin_lock(&cable->lock); |
268 | cable->running |= stream; | 270 | cable->running |= stream; |
269 | cable->pause &= ~stream; | 271 | cable->pause &= ~stream; |
@@ -444,34 +446,30 @@ static void copy_play_buf(struct loopback_pcm *play, | |||
444 | } | 446 | } |
445 | } | 447 | } |
446 | 448 | ||
447 | #define BYTEPOS_UPDATE_POSONLY 0 | 449 | static inline unsigned int bytepos_delta(struct loopback_pcm *dpcm, |
448 | #define BYTEPOS_UPDATE_CLEAR 1 | 450 | unsigned int jiffies_delta) |
449 | #define BYTEPOS_UPDATE_COPY 2 | ||
450 | |||
451 | static void loopback_bytepos_update(struct loopback_pcm *dpcm, | ||
452 | unsigned int delta, | ||
453 | unsigned int cmd) | ||
454 | { | 451 | { |
455 | unsigned int count; | ||
456 | unsigned long last_pos; | 452 | unsigned long last_pos; |
453 | unsigned int delta; | ||
457 | 454 | ||
458 | last_pos = byte_pos(dpcm, dpcm->irq_pos); | 455 | last_pos = byte_pos(dpcm, dpcm->irq_pos); |
459 | dpcm->irq_pos += delta * dpcm->pcm_bps; | 456 | dpcm->irq_pos += jiffies_delta * dpcm->pcm_bps; |
460 | count = byte_pos(dpcm, dpcm->irq_pos) - last_pos; | 457 | delta = byte_pos(dpcm, dpcm->irq_pos) - last_pos; |
461 | if (!count) | 458 | if (delta >= dpcm->last_drift) |
462 | return; | 459 | delta -= dpcm->last_drift; |
463 | if (cmd == BYTEPOS_UPDATE_CLEAR) | 460 | dpcm->last_drift = 0; |
464 | clear_capture_buf(dpcm, count); | ||
465 | else if (cmd == BYTEPOS_UPDATE_COPY) | ||
466 | copy_play_buf(dpcm->cable->streams[SNDRV_PCM_STREAM_PLAYBACK], | ||
467 | dpcm->cable->streams[SNDRV_PCM_STREAM_CAPTURE], | ||
468 | count); | ||
469 | dpcm->buf_pos += count; | ||
470 | dpcm->buf_pos %= dpcm->pcm_buffer_size; | ||
471 | if (dpcm->irq_pos >= dpcm->period_size_frac) { | 461 | if (dpcm->irq_pos >= dpcm->period_size_frac) { |
472 | dpcm->irq_pos %= dpcm->period_size_frac; | 462 | dpcm->irq_pos %= dpcm->period_size_frac; |
473 | dpcm->period_update_pending = 1; | 463 | dpcm->period_update_pending = 1; |
474 | } | 464 | } |
465 | return delta; | ||
466 | } | ||
467 | |||
468 | static inline void bytepos_finish(struct loopback_pcm *dpcm, | ||
469 | unsigned int delta) | ||
470 | { | ||
471 | dpcm->buf_pos += delta; | ||
472 | dpcm->buf_pos %= dpcm->pcm_buffer_size; | ||
475 | } | 473 | } |
476 | 474 | ||
477 | static unsigned int loopback_pos_update(struct loopback_cable *cable) | 475 | static unsigned int loopback_pos_update(struct loopback_cable *cable) |
@@ -481,7 +479,7 @@ static unsigned int loopback_pos_update(struct loopback_cable *cable) | |||
481 | struct loopback_pcm *dpcm_capt = | 479 | struct loopback_pcm *dpcm_capt = |
482 | cable->streams[SNDRV_PCM_STREAM_CAPTURE]; | 480 | cable->streams[SNDRV_PCM_STREAM_CAPTURE]; |
483 | unsigned long delta_play = 0, delta_capt = 0; | 481 | unsigned long delta_play = 0, delta_capt = 0; |
484 | unsigned int running; | 482 | unsigned int running, count1, count2; |
485 | unsigned long flags; | 483 | unsigned long flags; |
486 | 484 | ||
487 | spin_lock_irqsave(&cable->lock, flags); | 485 | spin_lock_irqsave(&cable->lock, flags); |
@@ -500,12 +498,13 @@ static unsigned int loopback_pos_update(struct loopback_cable *cable) | |||
500 | goto unlock; | 498 | goto unlock; |
501 | 499 | ||
502 | if (delta_play > delta_capt) { | 500 | if (delta_play > delta_capt) { |
503 | loopback_bytepos_update(dpcm_play, delta_play - delta_capt, | 501 | count1 = bytepos_delta(dpcm_play, delta_play - delta_capt); |
504 | BYTEPOS_UPDATE_POSONLY); | 502 | bytepos_finish(dpcm_play, count1); |
505 | delta_play = delta_capt; | 503 | delta_play = delta_capt; |
506 | } else if (delta_play < delta_capt) { | 504 | } else if (delta_play < delta_capt) { |
507 | loopback_bytepos_update(dpcm_capt, delta_capt - delta_play, | 505 | count1 = bytepos_delta(dpcm_capt, delta_capt - delta_play); |
508 | BYTEPOS_UPDATE_CLEAR); | 506 | clear_capture_buf(dpcm_capt, count1); |
507 | bytepos_finish(dpcm_capt, count1); | ||
509 | delta_capt = delta_play; | 508 | delta_capt = delta_play; |
510 | } | 509 | } |
511 | 510 | ||
@@ -513,8 +512,17 @@ static unsigned int loopback_pos_update(struct loopback_cable *cable) | |||
513 | goto unlock; | 512 | goto unlock; |
514 | 513 | ||
515 | /* note delta_capt == delta_play at this moment */ | 514 | /* note delta_capt == delta_play at this moment */ |
516 | loopback_bytepos_update(dpcm_capt, delta_capt, BYTEPOS_UPDATE_COPY); | 515 | count1 = bytepos_delta(dpcm_play, delta_play); |
517 | loopback_bytepos_update(dpcm_play, delta_play, BYTEPOS_UPDATE_POSONLY); | 516 | count2 = bytepos_delta(dpcm_capt, delta_capt); |
517 | if (count1 < count2) { | ||
518 | dpcm_capt->last_drift = count2 - count1; | ||
519 | count1 = count2; | ||
520 | } else if (count1 > count2) { | ||
521 | dpcm_play->last_drift = count1 - count2; | ||
522 | } | ||
523 | copy_play_buf(dpcm_play, dpcm_capt, count1); | ||
524 | bytepos_finish(dpcm_play, count1); | ||
525 | bytepos_finish(dpcm_capt, count1); | ||
518 | unlock: | 526 | unlock: |
519 | spin_unlock_irqrestore(&cable->lock, flags); | 527 | spin_unlock_irqrestore(&cable->lock, flags); |
520 | return running; | 528 | return running; |
diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c index 87657dd7714c..ea995af6d049 100644 --- a/sound/firewire/amdtp.c +++ b/sound/firewire/amdtp.c | |||
@@ -31,6 +31,8 @@ | |||
31 | #define INTERRUPT_INTERVAL 16 | 31 | #define INTERRUPT_INTERVAL 16 |
32 | #define QUEUE_LENGTH 48 | 32 | #define QUEUE_LENGTH 48 |
33 | 33 | ||
34 | static void pcm_period_tasklet(unsigned long data); | ||
35 | |||
34 | /** | 36 | /** |
35 | * amdtp_out_stream_init - initialize an AMDTP output stream structure | 37 | * amdtp_out_stream_init - initialize an AMDTP output stream structure |
36 | * @s: the AMDTP output stream to initialize | 38 | * @s: the AMDTP output stream to initialize |
@@ -47,6 +49,7 @@ int amdtp_out_stream_init(struct amdtp_out_stream *s, struct fw_unit *unit, | |||
47 | s->flags = flags; | 49 | s->flags = flags; |
48 | s->context = ERR_PTR(-1); | 50 | s->context = ERR_PTR(-1); |
49 | mutex_init(&s->mutex); | 51 | mutex_init(&s->mutex); |
52 | tasklet_init(&s->period_tasklet, pcm_period_tasklet, (unsigned long)s); | ||
50 | s->packet_index = 0; | 53 | s->packet_index = 0; |
51 | 54 | ||
52 | return 0; | 55 | return 0; |
@@ -164,6 +167,21 @@ void amdtp_out_stream_set_pcm_format(struct amdtp_out_stream *s, | |||
164 | } | 167 | } |
165 | EXPORT_SYMBOL(amdtp_out_stream_set_pcm_format); | 168 | EXPORT_SYMBOL(amdtp_out_stream_set_pcm_format); |
166 | 169 | ||
170 | /** | ||
171 | * amdtp_out_stream_pcm_prepare - prepare PCM device for running | ||
172 | * @s: the AMDTP output stream | ||
173 | * | ||
174 | * This function should be called from the PCM device's .prepare callback. | ||
175 | */ | ||
176 | void amdtp_out_stream_pcm_prepare(struct amdtp_out_stream *s) | ||
177 | { | ||
178 | tasklet_kill(&s->period_tasklet); | ||
179 | s->pcm_buffer_pointer = 0; | ||
180 | s->pcm_period_pointer = 0; | ||
181 | s->pointer_flush = true; | ||
182 | } | ||
183 | EXPORT_SYMBOL(amdtp_out_stream_pcm_prepare); | ||
184 | |||
167 | static unsigned int calculate_data_blocks(struct amdtp_out_stream *s) | 185 | static unsigned int calculate_data_blocks(struct amdtp_out_stream *s) |
168 | { | 186 | { |
169 | unsigned int phase, data_blocks; | 187 | unsigned int phase, data_blocks; |
@@ -376,11 +394,21 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle) | |||
376 | s->pcm_period_pointer += data_blocks; | 394 | s->pcm_period_pointer += data_blocks; |
377 | if (s->pcm_period_pointer >= pcm->runtime->period_size) { | 395 | if (s->pcm_period_pointer >= pcm->runtime->period_size) { |
378 | s->pcm_period_pointer -= pcm->runtime->period_size; | 396 | s->pcm_period_pointer -= pcm->runtime->period_size; |
379 | snd_pcm_period_elapsed(pcm); | 397 | s->pointer_flush = false; |
398 | tasklet_hi_schedule(&s->period_tasklet); | ||
380 | } | 399 | } |
381 | } | 400 | } |
382 | } | 401 | } |
383 | 402 | ||
403 | static void pcm_period_tasklet(unsigned long data) | ||
404 | { | ||
405 | struct amdtp_out_stream *s = (void *)data; | ||
406 | struct snd_pcm_substream *pcm = ACCESS_ONCE(s->pcm); | ||
407 | |||
408 | if (pcm) | ||
409 | snd_pcm_period_elapsed(pcm); | ||
410 | } | ||
411 | |||
384 | static void out_packet_callback(struct fw_iso_context *context, u32 cycle, | 412 | static void out_packet_callback(struct fw_iso_context *context, u32 cycle, |
385 | size_t header_length, void *header, void *data) | 413 | size_t header_length, void *header, void *data) |
386 | { | 414 | { |
@@ -506,6 +534,24 @@ err_unlock: | |||
506 | EXPORT_SYMBOL(amdtp_out_stream_start); | 534 | EXPORT_SYMBOL(amdtp_out_stream_start); |
507 | 535 | ||
508 | /** | 536 | /** |
537 | * amdtp_out_stream_pcm_pointer - get the PCM buffer position | ||
538 | * @s: the AMDTP output stream that transports the PCM data | ||
539 | * | ||
540 | * Returns the current buffer position, in frames. | ||
541 | */ | ||
542 | unsigned long amdtp_out_stream_pcm_pointer(struct amdtp_out_stream *s) | ||
543 | { | ||
544 | /* this optimization is allowed to be racy */ | ||
545 | if (s->pointer_flush) | ||
546 | fw_iso_context_flush_completions(s->context); | ||
547 | else | ||
548 | s->pointer_flush = true; | ||
549 | |||
550 | return ACCESS_ONCE(s->pcm_buffer_pointer); | ||
551 | } | ||
552 | EXPORT_SYMBOL(amdtp_out_stream_pcm_pointer); | ||
553 | |||
554 | /** | ||
509 | * amdtp_out_stream_update - update the stream after a bus reset | 555 | * amdtp_out_stream_update - update the stream after a bus reset |
510 | * @s: the AMDTP output stream | 556 | * @s: the AMDTP output stream |
511 | */ | 557 | */ |
@@ -532,6 +578,7 @@ void amdtp_out_stream_stop(struct amdtp_out_stream *s) | |||
532 | return; | 578 | return; |
533 | } | 579 | } |
534 | 580 | ||
581 | tasklet_kill(&s->period_tasklet); | ||
535 | fw_iso_context_stop(s->context); | 582 | fw_iso_context_stop(s->context); |
536 | fw_iso_context_destroy(s->context); | 583 | fw_iso_context_destroy(s->context); |
537 | s->context = ERR_PTR(-1); | 584 | s->context = ERR_PTR(-1); |
diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h index 537a9cb83581..b680c5ef01d6 100644 --- a/sound/firewire/amdtp.h +++ b/sound/firewire/amdtp.h | |||
@@ -1,6 +1,7 @@ | |||
1 | #ifndef SOUND_FIREWIRE_AMDTP_H_INCLUDED | 1 | #ifndef SOUND_FIREWIRE_AMDTP_H_INCLUDED |
2 | #define SOUND_FIREWIRE_AMDTP_H_INCLUDED | 2 | #define SOUND_FIREWIRE_AMDTP_H_INCLUDED |
3 | 3 | ||
4 | #include <linux/interrupt.h> | ||
4 | #include <linux/mutex.h> | 5 | #include <linux/mutex.h> |
5 | #include <linux/spinlock.h> | 6 | #include <linux/spinlock.h> |
6 | #include "packets-buffer.h" | 7 | #include "packets-buffer.h" |
@@ -55,6 +56,7 @@ struct amdtp_out_stream { | |||
55 | struct iso_packets_buffer buffer; | 56 | struct iso_packets_buffer buffer; |
56 | 57 | ||
57 | struct snd_pcm_substream *pcm; | 58 | struct snd_pcm_substream *pcm; |
59 | struct tasklet_struct period_tasklet; | ||
58 | 60 | ||
59 | int packet_index; | 61 | int packet_index; |
60 | unsigned int data_block_counter; | 62 | unsigned int data_block_counter; |
@@ -66,6 +68,7 @@ struct amdtp_out_stream { | |||
66 | 68 | ||
67 | unsigned int pcm_buffer_pointer; | 69 | unsigned int pcm_buffer_pointer; |
68 | unsigned int pcm_period_pointer; | 70 | unsigned int pcm_period_pointer; |
71 | bool pointer_flush; | ||
69 | }; | 72 | }; |
70 | 73 | ||
71 | int amdtp_out_stream_init(struct amdtp_out_stream *s, struct fw_unit *unit, | 74 | int amdtp_out_stream_init(struct amdtp_out_stream *s, struct fw_unit *unit, |
@@ -81,6 +84,8 @@ void amdtp_out_stream_stop(struct amdtp_out_stream *s); | |||
81 | 84 | ||
82 | void amdtp_out_stream_set_pcm_format(struct amdtp_out_stream *s, | 85 | void amdtp_out_stream_set_pcm_format(struct amdtp_out_stream *s, |
83 | snd_pcm_format_t format); | 86 | snd_pcm_format_t format); |
87 | void amdtp_out_stream_pcm_prepare(struct amdtp_out_stream *s); | ||
88 | unsigned long amdtp_out_stream_pcm_pointer(struct amdtp_out_stream *s); | ||
84 | void amdtp_out_stream_pcm_abort(struct amdtp_out_stream *s); | 89 | void amdtp_out_stream_pcm_abort(struct amdtp_out_stream *s); |
85 | 90 | ||
86 | /** | 91 | /** |
@@ -123,18 +128,6 @@ static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s) | |||
123 | } | 128 | } |
124 | 129 | ||
125 | /** | 130 | /** |
126 | * amdtp_out_stream_pcm_prepare - prepare PCM device for running | ||
127 | * @s: the AMDTP output stream | ||
128 | * | ||
129 | * This function should be called from the PCM device's .prepare callback. | ||
130 | */ | ||
131 | static inline void amdtp_out_stream_pcm_prepare(struct amdtp_out_stream *s) | ||
132 | { | ||
133 | s->pcm_buffer_pointer = 0; | ||
134 | s->pcm_period_pointer = 0; | ||
135 | } | ||
136 | |||
137 | /** | ||
138 | * amdtp_out_stream_pcm_trigger - start/stop playback from a PCM device | 131 | * amdtp_out_stream_pcm_trigger - start/stop playback from a PCM device |
139 | * @s: the AMDTP output stream | 132 | * @s: the AMDTP output stream |
140 | * @pcm: the PCM device to be started, or %NULL to stop the current device | 133 | * @pcm: the PCM device to be started, or %NULL to stop the current device |
@@ -149,18 +142,6 @@ static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s, | |||
149 | ACCESS_ONCE(s->pcm) = pcm; | 142 | ACCESS_ONCE(s->pcm) = pcm; |
150 | } | 143 | } |
151 | 144 | ||
152 | /** | ||
153 | * amdtp_out_stream_pcm_pointer - get the PCM buffer position | ||
154 | * @s: the AMDTP output stream that transports the PCM data | ||
155 | * | ||
156 | * Returns the current buffer position, in frames. | ||
157 | */ | ||
158 | static inline unsigned long | ||
159 | amdtp_out_stream_pcm_pointer(struct amdtp_out_stream *s) | ||
160 | { | ||
161 | return ACCESS_ONCE(s->pcm_buffer_pointer); | ||
162 | } | ||
163 | |||
164 | static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc) | 145 | static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc) |
165 | { | 146 | { |
166 | return sfc & 1; | 147 | return sfc & 1; |
diff --git a/sound/pci/Kconfig b/sound/pci/Kconfig index 5ca0939e4223..ff3af6e77d61 100644 --- a/sound/pci/Kconfig +++ b/sound/pci/Kconfig | |||
@@ -228,7 +228,7 @@ config SND_OXYGEN | |||
228 | Say Y here to include support for sound cards based on the | 228 | Say Y here to include support for sound cards based on the |
229 | C-Media CMI8788 (Oxygen HD Audio) chip: | 229 | C-Media CMI8788 (Oxygen HD Audio) chip: |
230 | * Asound A-8788 | 230 | * Asound A-8788 |
231 | * Asus Xonar DG | 231 | * Asus Xonar DG/DGX |
232 | * AuzenTech X-Meridian | 232 | * AuzenTech X-Meridian |
233 | * AuzenTech X-Meridian 2G | 233 | * AuzenTech X-Meridian 2G |
234 | * Bgears b-Enspirer | 234 | * Bgears b-Enspirer |
diff --git a/sound/pci/ad1889.c b/sound/pci/ad1889.c index 9d91d61902b4..e672ff4df2da 100644 --- a/sound/pci/ad1889.c +++ b/sound/pci/ad1889.c | |||
@@ -1062,17 +1062,4 @@ static struct pci_driver ad1889_pci_driver = { | |||
1062 | .remove = __devexit_p(snd_ad1889_remove), | 1062 | .remove = __devexit_p(snd_ad1889_remove), |
1063 | }; | 1063 | }; |
1064 | 1064 | ||
1065 | static int __init | 1065 | module_pci_driver(ad1889_pci_driver); |
1066 | alsa_ad1889_init(void) | ||
1067 | { | ||
1068 | return pci_register_driver(&ad1889_pci_driver); | ||
1069 | } | ||
1070 | |||
1071 | static void __exit | ||
1072 | alsa_ad1889_fini(void) | ||
1073 | { | ||
1074 | pci_unregister_driver(&ad1889_pci_driver); | ||
1075 | } | ||
1076 | |||
1077 | module_init(alsa_ad1889_init); | ||
1078 | module_exit(alsa_ad1889_fini); | ||
diff --git a/sound/pci/ali5451/ali5451.c b/sound/pci/ali5451/ali5451.c index bdd6164e9c7e..9dfc27bf6cc6 100644 --- a/sound/pci/ali5451/ali5451.c +++ b/sound/pci/ali5451/ali5451.c | |||
@@ -2294,7 +2294,7 @@ static void __devexit snd_ali_remove(struct pci_dev *pci) | |||
2294 | pci_set_drvdata(pci, NULL); | 2294 | pci_set_drvdata(pci, NULL); |
2295 | } | 2295 | } |
2296 | 2296 | ||
2297 | static struct pci_driver driver = { | 2297 | static struct pci_driver ali5451_driver = { |
2298 | .name = KBUILD_MODNAME, | 2298 | .name = KBUILD_MODNAME, |
2299 | .id_table = snd_ali_ids, | 2299 | .id_table = snd_ali_ids, |
2300 | .probe = snd_ali_probe, | 2300 | .probe = snd_ali_probe, |
@@ -2305,15 +2305,4 @@ static struct pci_driver driver = { | |||
2305 | #endif | 2305 | #endif |
2306 | }; | 2306 | }; |
2307 | 2307 | ||
2308 | static int __init alsa_card_ali_init(void) | 2308 | module_pci_driver(ali5451_driver); |
2309 | { | ||
2310 | return pci_register_driver(&driver); | ||
2311 | } | ||
2312 | |||
2313 | static void __exit alsa_card_ali_exit(void) | ||
2314 | { | ||
2315 | pci_unregister_driver(&driver); | ||
2316 | } | ||
2317 | |||
2318 | module_init(alsa_card_ali_init) | ||
2319 | module_exit(alsa_card_ali_exit) | ||
diff --git a/sound/pci/als300.c b/sound/pci/als300.c index 8196e229b2df..59d65388faf5 100644 --- a/sound/pci/als300.c +++ b/sound/pci/als300.c | |||
@@ -852,7 +852,7 @@ static int __devinit snd_als300_probe(struct pci_dev *pci, | |||
852 | return 0; | 852 | return 0; |
853 | } | 853 | } |
854 | 854 | ||
855 | static struct pci_driver driver = { | 855 | static struct pci_driver als300_driver = { |
856 | .name = KBUILD_MODNAME, | 856 | .name = KBUILD_MODNAME, |
857 | .id_table = snd_als300_ids, | 857 | .id_table = snd_als300_ids, |
858 | .probe = snd_als300_probe, | 858 | .probe = snd_als300_probe, |
@@ -863,15 +863,4 @@ static struct pci_driver driver = { | |||
863 | #endif | 863 | #endif |
864 | }; | 864 | }; |
865 | 865 | ||
866 | static int __init alsa_card_als300_init(void) | 866 | module_pci_driver(als300_driver); |
867 | { | ||
868 | return pci_register_driver(&driver); | ||
869 | } | ||
870 | |||
871 | static void __exit alsa_card_als300_exit(void) | ||
872 | { | ||
873 | pci_unregister_driver(&driver); | ||
874 | } | ||
875 | |||
876 | module_init(alsa_card_als300_init) | ||
877 | module_exit(alsa_card_als300_exit) | ||
diff --git a/sound/pci/als4000.c b/sound/pci/als4000.c index 3269b8011ea9..7d7f2598c748 100644 --- a/sound/pci/als4000.c +++ b/sound/pci/als4000.c | |||
@@ -1036,7 +1036,7 @@ static int snd_als4000_resume(struct pci_dev *pci) | |||
1036 | #endif /* CONFIG_PM */ | 1036 | #endif /* CONFIG_PM */ |
1037 | 1037 | ||
1038 | 1038 | ||
1039 | static struct pci_driver driver = { | 1039 | static struct pci_driver als4000_driver = { |
1040 | .name = KBUILD_MODNAME, | 1040 | .name = KBUILD_MODNAME, |
1041 | .id_table = snd_als4000_ids, | 1041 | .id_table = snd_als4000_ids, |
1042 | .probe = snd_card_als4000_probe, | 1042 | .probe = snd_card_als4000_probe, |
@@ -1047,15 +1047,4 @@ static struct pci_driver driver = { | |||
1047 | #endif | 1047 | #endif |
1048 | }; | 1048 | }; |
1049 | 1049 | ||
1050 | static int __init alsa_card_als4000_init(void) | 1050 | module_pci_driver(als4000_driver); |
1051 | { | ||
1052 | return pci_register_driver(&driver); | ||
1053 | } | ||
1054 | |||
1055 | static void __exit alsa_card_als4000_exit(void) | ||
1056 | { | ||
1057 | pci_unregister_driver(&driver); | ||
1058 | } | ||
1059 | |||
1060 | module_init(alsa_card_als4000_init) | ||
1061 | module_exit(alsa_card_als4000_exit) | ||
diff --git a/sound/pci/atiixp.c b/sound/pci/atiixp.c index 590682f115ef..156a94f8a123 100644 --- a/sound/pci/atiixp.c +++ b/sound/pci/atiixp.c | |||
@@ -1700,7 +1700,7 @@ static void __devexit snd_atiixp_remove(struct pci_dev *pci) | |||
1700 | pci_set_drvdata(pci, NULL); | 1700 | pci_set_drvdata(pci, NULL); |
1701 | } | 1701 | } |
1702 | 1702 | ||
1703 | static struct pci_driver driver = { | 1703 | static struct pci_driver atiixp_driver = { |
1704 | .name = KBUILD_MODNAME, | 1704 | .name = KBUILD_MODNAME, |
1705 | .id_table = snd_atiixp_ids, | 1705 | .id_table = snd_atiixp_ids, |
1706 | .probe = snd_atiixp_probe, | 1706 | .probe = snd_atiixp_probe, |
@@ -1711,16 +1711,4 @@ static struct pci_driver driver = { | |||
1711 | #endif | 1711 | #endif |
1712 | }; | 1712 | }; |
1713 | 1713 | ||
1714 | 1714 | module_pci_driver(atiixp_driver); | |
1715 | static int __init alsa_card_atiixp_init(void) | ||
1716 | { | ||
1717 | return pci_register_driver(&driver); | ||
1718 | } | ||
1719 | |||
1720 | static void __exit alsa_card_atiixp_exit(void) | ||
1721 | { | ||
1722 | pci_unregister_driver(&driver); | ||
1723 | } | ||
1724 | |||
1725 | module_init(alsa_card_atiixp_init) | ||
1726 | module_exit(alsa_card_atiixp_exit) | ||
diff --git a/sound/pci/atiixp_modem.c b/sound/pci/atiixp_modem.c index 524d35f31232..30a4fd96ce73 100644 --- a/sound/pci/atiixp_modem.c +++ b/sound/pci/atiixp_modem.c | |||
@@ -1331,7 +1331,7 @@ static void __devexit snd_atiixp_remove(struct pci_dev *pci) | |||
1331 | pci_set_drvdata(pci, NULL); | 1331 | pci_set_drvdata(pci, NULL); |
1332 | } | 1332 | } |
1333 | 1333 | ||
1334 | static struct pci_driver driver = { | 1334 | static struct pci_driver atiixp_modem_driver = { |
1335 | .name = KBUILD_MODNAME, | 1335 | .name = KBUILD_MODNAME, |
1336 | .id_table = snd_atiixp_ids, | 1336 | .id_table = snd_atiixp_ids, |
1337 | .probe = snd_atiixp_probe, | 1337 | .probe = snd_atiixp_probe, |
@@ -1342,16 +1342,4 @@ static struct pci_driver driver = { | |||
1342 | #endif | 1342 | #endif |
1343 | }; | 1343 | }; |
1344 | 1344 | ||
1345 | 1345 | module_pci_driver(atiixp_modem_driver); | |
1346 | static int __init alsa_card_atiixp_init(void) | ||
1347 | { | ||
1348 | return pci_register_driver(&driver); | ||
1349 | } | ||
1350 | |||
1351 | static void __exit alsa_card_atiixp_exit(void) | ||
1352 | { | ||
1353 | pci_unregister_driver(&driver); | ||
1354 | } | ||
1355 | |||
1356 | module_init(alsa_card_atiixp_init) | ||
1357 | module_exit(alsa_card_atiixp_exit) | ||
diff --git a/sound/pci/au88x0/au88x0.c b/sound/pci/au88x0/au88x0.c index f13ad536b2d5..ffc376f9f4e4 100644 --- a/sound/pci/au88x0/au88x0.c +++ b/sound/pci/au88x0/au88x0.c | |||
@@ -375,24 +375,11 @@ static void __devexit snd_vortex_remove(struct pci_dev *pci) | |||
375 | } | 375 | } |
376 | 376 | ||
377 | // pci_driver definition | 377 | // pci_driver definition |
378 | static struct pci_driver driver = { | 378 | static struct pci_driver vortex_driver = { |
379 | .name = KBUILD_MODNAME, | 379 | .name = KBUILD_MODNAME, |
380 | .id_table = snd_vortex_ids, | 380 | .id_table = snd_vortex_ids, |
381 | .probe = snd_vortex_probe, | 381 | .probe = snd_vortex_probe, |
382 | .remove = __devexit_p(snd_vortex_remove), | 382 | .remove = __devexit_p(snd_vortex_remove), |
383 | }; | 383 | }; |
384 | 384 | ||
385 | // initialization of the module | 385 | module_pci_driver(vortex_driver); |
386 | static int __init alsa_card_vortex_init(void) | ||
387 | { | ||
388 | return pci_register_driver(&driver); | ||
389 | } | ||
390 | |||
391 | // clean up the module | ||
392 | static void __exit alsa_card_vortex_exit(void) | ||
393 | { | ||
394 | pci_unregister_driver(&driver); | ||
395 | } | ||
396 | |||
397 | module_init(alsa_card_vortex_init) | ||
398 | module_exit(alsa_card_vortex_exit) | ||
diff --git a/sound/pci/aw2/aw2-alsa.c b/sound/pci/aw2/aw2-alsa.c index 1c5231931462..0f804741825f 100644 --- a/sound/pci/aw2/aw2-alsa.c +++ b/sound/pci/aw2/aw2-alsa.c | |||
@@ -112,8 +112,6 @@ struct aw2 { | |||
112 | /********************************* | 112 | /********************************* |
113 | * FUNCTION DECLARATIONS | 113 | * FUNCTION DECLARATIONS |
114 | ********************************/ | 114 | ********************************/ |
115 | static int __init alsa_card_aw2_init(void); | ||
116 | static void __exit alsa_card_aw2_exit(void); | ||
117 | static int snd_aw2_dev_free(struct snd_device *device); | 115 | static int snd_aw2_dev_free(struct snd_device *device); |
118 | static int __devinit snd_aw2_create(struct snd_card *card, | 116 | static int __devinit snd_aw2_create(struct snd_card *card, |
119 | struct pci_dev *pci, struct aw2 **rchip); | 117 | struct pci_dev *pci, struct aw2 **rchip); |
@@ -171,13 +169,15 @@ static DEFINE_PCI_DEVICE_TABLE(snd_aw2_ids) = { | |||
171 | MODULE_DEVICE_TABLE(pci, snd_aw2_ids); | 169 | MODULE_DEVICE_TABLE(pci, snd_aw2_ids); |
172 | 170 | ||
173 | /* pci_driver definition */ | 171 | /* pci_driver definition */ |
174 | static struct pci_driver driver = { | 172 | static struct pci_driver aw2_driver = { |
175 | .name = KBUILD_MODNAME, | 173 | .name = KBUILD_MODNAME, |
176 | .id_table = snd_aw2_ids, | 174 | .id_table = snd_aw2_ids, |
177 | .probe = snd_aw2_probe, | 175 | .probe = snd_aw2_probe, |
178 | .remove = __devexit_p(snd_aw2_remove), | 176 | .remove = __devexit_p(snd_aw2_remove), |
179 | }; | 177 | }; |
180 | 178 | ||
179 | module_pci_driver(aw2_driver); | ||
180 | |||
181 | /* operators for playback PCM alsa interface */ | 181 | /* operators for playback PCM alsa interface */ |
182 | static struct snd_pcm_ops snd_aw2_playback_ops = { | 182 | static struct snd_pcm_ops snd_aw2_playback_ops = { |
183 | .open = snd_aw2_pcm_playback_open, | 183 | .open = snd_aw2_pcm_playback_open, |
@@ -217,23 +217,6 @@ static struct snd_kcontrol_new aw2_control __devinitdata = { | |||
217 | * FUNCTION IMPLEMENTATIONS | 217 | * FUNCTION IMPLEMENTATIONS |
218 | ********************************/ | 218 | ********************************/ |
219 | 219 | ||
220 | /* initialization of the module */ | ||
221 | static int __init alsa_card_aw2_init(void) | ||
222 | { | ||
223 | snd_printdd(KERN_DEBUG "aw2: Load aw2 module\n"); | ||
224 | return pci_register_driver(&driver); | ||
225 | } | ||
226 | |||
227 | /* clean up the module */ | ||
228 | static void __exit alsa_card_aw2_exit(void) | ||
229 | { | ||
230 | snd_printdd(KERN_DEBUG "aw2: Unload aw2 module\n"); | ||
231 | pci_unregister_driver(&driver); | ||
232 | } | ||
233 | |||
234 | module_init(alsa_card_aw2_init); | ||
235 | module_exit(alsa_card_aw2_exit); | ||
236 | |||
237 | /* component-destructor */ | 220 | /* component-destructor */ |
238 | static int snd_aw2_dev_free(struct snd_device *device) | 221 | static int snd_aw2_dev_free(struct snd_device *device) |
239 | { | 222 | { |
diff --git a/sound/pci/azt3328.c b/sound/pci/azt3328.c index 496f14c1a731..f0b4d7493af5 100644 --- a/sound/pci/azt3328.c +++ b/sound/pci/azt3328.c | |||
@@ -2862,7 +2862,7 @@ snd_azf3328_resume(struct pci_dev *pci) | |||
2862 | #endif /* CONFIG_PM */ | 2862 | #endif /* CONFIG_PM */ |
2863 | 2863 | ||
2864 | 2864 | ||
2865 | static struct pci_driver driver = { | 2865 | static struct pci_driver azf3328_driver = { |
2866 | .name = KBUILD_MODNAME, | 2866 | .name = KBUILD_MODNAME, |
2867 | .id_table = snd_azf3328_ids, | 2867 | .id_table = snd_azf3328_ids, |
2868 | .probe = snd_azf3328_probe, | 2868 | .probe = snd_azf3328_probe, |
@@ -2873,23 +2873,4 @@ static struct pci_driver driver = { | |||
2873 | #endif | 2873 | #endif |
2874 | }; | 2874 | }; |
2875 | 2875 | ||
2876 | static int __init | 2876 | module_pci_driver(azf3328_driver); |
2877 | alsa_card_azf3328_init(void) | ||
2878 | { | ||
2879 | int err; | ||
2880 | snd_azf3328_dbgcallenter(); | ||
2881 | err = pci_register_driver(&driver); | ||
2882 | snd_azf3328_dbgcallleave(); | ||
2883 | return err; | ||
2884 | } | ||
2885 | |||
2886 | static void __exit | ||
2887 | alsa_card_azf3328_exit(void) | ||
2888 | { | ||
2889 | snd_azf3328_dbgcallenter(); | ||
2890 | pci_unregister_driver(&driver); | ||
2891 | snd_azf3328_dbgcallleave(); | ||
2892 | } | ||
2893 | |||
2894 | module_init(alsa_card_azf3328_init) | ||
2895 | module_exit(alsa_card_azf3328_exit) | ||
diff --git a/sound/pci/bt87x.c b/sound/pci/bt87x.c index 62d6163fc9d9..b6a95eeca095 100644 --- a/sound/pci/bt87x.c +++ b/sound/pci/bt87x.c | |||
@@ -836,8 +836,6 @@ static struct { | |||
836 | {0x7063, 0x2000}, /* pcHDTV HD-2000 TV */ | 836 | {0x7063, 0x2000}, /* pcHDTV HD-2000 TV */ |
837 | }; | 837 | }; |
838 | 838 | ||
839 | static struct pci_driver driver; | ||
840 | |||
841 | /* return the id of the card, or a negative value if it's blacklisted */ | 839 | /* return the id of the card, or a negative value if it's blacklisted */ |
842 | static int __devinit snd_bt87x_detect_card(struct pci_dev *pci) | 840 | static int __devinit snd_bt87x_detect_card(struct pci_dev *pci) |
843 | { | 841 | { |
@@ -964,24 +962,11 @@ static DEFINE_PCI_DEVICE_TABLE(snd_bt87x_default_ids) = { | |||
964 | { } | 962 | { } |
965 | }; | 963 | }; |
966 | 964 | ||
967 | static struct pci_driver driver = { | 965 | static struct pci_driver bt87x_driver = { |
968 | .name = KBUILD_MODNAME, | 966 | .name = KBUILD_MODNAME, |
969 | .id_table = snd_bt87x_ids, | 967 | .id_table = snd_bt87x_ids, |
970 | .probe = snd_bt87x_probe, | 968 | .probe = snd_bt87x_probe, |
971 | .remove = __devexit_p(snd_bt87x_remove), | 969 | .remove = __devexit_p(snd_bt87x_remove), |
972 | }; | 970 | }; |
973 | 971 | ||
974 | static int __init alsa_card_bt87x_init(void) | 972 | module_pci_driver(bt87x_driver); |
975 | { | ||
976 | if (load_all) | ||
977 | driver.id_table = snd_bt87x_default_ids; | ||
978 | return pci_register_driver(&driver); | ||
979 | } | ||
980 | |||
981 | static void __exit alsa_card_bt87x_exit(void) | ||
982 | { | ||
983 | pci_unregister_driver(&driver); | ||
984 | } | ||
985 | |||
986 | module_init(alsa_card_bt87x_init) | ||
987 | module_exit(alsa_card_bt87x_exit) | ||
diff --git a/sound/pci/ca0106/ca0106_main.c b/sound/pci/ca0106/ca0106_main.c index 08d6ebfe5a61..e76d68a7081f 100644 --- a/sound/pci/ca0106/ca0106_main.c +++ b/sound/pci/ca0106/ca0106_main.c | |||
@@ -1932,7 +1932,7 @@ static DEFINE_PCI_DEVICE_TABLE(snd_ca0106_ids) = { | |||
1932 | MODULE_DEVICE_TABLE(pci, snd_ca0106_ids); | 1932 | MODULE_DEVICE_TABLE(pci, snd_ca0106_ids); |
1933 | 1933 | ||
1934 | // pci_driver definition | 1934 | // pci_driver definition |
1935 | static struct pci_driver driver = { | 1935 | static struct pci_driver ca0106_driver = { |
1936 | .name = KBUILD_MODNAME, | 1936 | .name = KBUILD_MODNAME, |
1937 | .id_table = snd_ca0106_ids, | 1937 | .id_table = snd_ca0106_ids, |
1938 | .probe = snd_ca0106_probe, | 1938 | .probe = snd_ca0106_probe, |
@@ -1943,17 +1943,4 @@ static struct pci_driver driver = { | |||
1943 | #endif | 1943 | #endif |
1944 | }; | 1944 | }; |
1945 | 1945 | ||
1946 | // initialization of the module | 1946 | module_pci_driver(ca0106_driver); |
1947 | static int __init alsa_card_ca0106_init(void) | ||
1948 | { | ||
1949 | return pci_register_driver(&driver); | ||
1950 | } | ||
1951 | |||
1952 | // clean up the module | ||
1953 | static void __exit alsa_card_ca0106_exit(void) | ||
1954 | { | ||
1955 | pci_unregister_driver(&driver); | ||
1956 | } | ||
1957 | |||
1958 | module_init(alsa_card_ca0106_init) | ||
1959 | module_exit(alsa_card_ca0106_exit) | ||
diff --git a/sound/pci/cmipci.c b/sound/pci/cmipci.c index 19b06269adc2..3815bd4c6779 100644 --- a/sound/pci/cmipci.c +++ b/sound/pci/cmipci.c | |||
@@ -3398,7 +3398,7 @@ static int snd_cmipci_resume(struct pci_dev *pci) | |||
3398 | } | 3398 | } |
3399 | #endif /* CONFIG_PM */ | 3399 | #endif /* CONFIG_PM */ |
3400 | 3400 | ||
3401 | static struct pci_driver driver = { | 3401 | static struct pci_driver cmipci_driver = { |
3402 | .name = KBUILD_MODNAME, | 3402 | .name = KBUILD_MODNAME, |
3403 | .id_table = snd_cmipci_ids, | 3403 | .id_table = snd_cmipci_ids, |
3404 | .probe = snd_cmipci_probe, | 3404 | .probe = snd_cmipci_probe, |
@@ -3409,15 +3409,4 @@ static struct pci_driver driver = { | |||
3409 | #endif | 3409 | #endif |
3410 | }; | 3410 | }; |
3411 | 3411 | ||
3412 | static int __init alsa_card_cmipci_init(void) | 3412 | module_pci_driver(cmipci_driver); |
3413 | { | ||
3414 | return pci_register_driver(&driver); | ||
3415 | } | ||
3416 | |||
3417 | static void __exit alsa_card_cmipci_exit(void) | ||
3418 | { | ||
3419 | pci_unregister_driver(&driver); | ||
3420 | } | ||
3421 | |||
3422 | module_init(alsa_card_cmipci_init) | ||
3423 | module_exit(alsa_card_cmipci_exit) | ||
diff --git a/sound/pci/cs4281.c b/sound/pci/cs4281.c index a9f368f60df6..33506ee569bd 100644 --- a/sound/pci/cs4281.c +++ b/sound/pci/cs4281.c | |||
@@ -2084,7 +2084,7 @@ static int cs4281_resume(struct pci_dev *pci) | |||
2084 | } | 2084 | } |
2085 | #endif /* CONFIG_PM */ | 2085 | #endif /* CONFIG_PM */ |
2086 | 2086 | ||
2087 | static struct pci_driver driver = { | 2087 | static struct pci_driver cs4281_driver = { |
2088 | .name = KBUILD_MODNAME, | 2088 | .name = KBUILD_MODNAME, |
2089 | .id_table = snd_cs4281_ids, | 2089 | .id_table = snd_cs4281_ids, |
2090 | .probe = snd_cs4281_probe, | 2090 | .probe = snd_cs4281_probe, |
@@ -2095,15 +2095,4 @@ static struct pci_driver driver = { | |||
2095 | #endif | 2095 | #endif |
2096 | }; | 2096 | }; |
2097 | 2097 | ||
2098 | static int __init alsa_card_cs4281_init(void) | 2098 | module_pci_driver(cs4281_driver); |
2099 | { | ||
2100 | return pci_register_driver(&driver); | ||
2101 | } | ||
2102 | |||
2103 | static void __exit alsa_card_cs4281_exit(void) | ||
2104 | { | ||
2105 | pci_unregister_driver(&driver); | ||
2106 | } | ||
2107 | |||
2108 | module_init(alsa_card_cs4281_init) | ||
2109 | module_exit(alsa_card_cs4281_exit) | ||
diff --git a/sound/pci/cs46xx/cs46xx.c b/sound/pci/cs46xx/cs46xx.c index 819d79d0586d..6cc7404e0e8f 100644 --- a/sound/pci/cs46xx/cs46xx.c +++ b/sound/pci/cs46xx/cs46xx.c | |||
@@ -161,7 +161,7 @@ static void __devexit snd_card_cs46xx_remove(struct pci_dev *pci) | |||
161 | pci_set_drvdata(pci, NULL); | 161 | pci_set_drvdata(pci, NULL); |
162 | } | 162 | } |
163 | 163 | ||
164 | static struct pci_driver driver = { | 164 | static struct pci_driver cs46xx_driver = { |
165 | .name = KBUILD_MODNAME, | 165 | .name = KBUILD_MODNAME, |
166 | .id_table = snd_cs46xx_ids, | 166 | .id_table = snd_cs46xx_ids, |
167 | .probe = snd_card_cs46xx_probe, | 167 | .probe = snd_card_cs46xx_probe, |
@@ -172,15 +172,4 @@ static struct pci_driver driver = { | |||
172 | #endif | 172 | #endif |
173 | }; | 173 | }; |
174 | 174 | ||
175 | static int __init alsa_card_cs46xx_init(void) | 175 | module_pci_driver(cs46xx_driver); |
176 | { | ||
177 | return pci_register_driver(&driver); | ||
178 | } | ||
179 | |||
180 | static void __exit alsa_card_cs46xx_exit(void) | ||
181 | { | ||
182 | pci_unregister_driver(&driver); | ||
183 | } | ||
184 | |||
185 | module_init(alsa_card_cs46xx_init) | ||
186 | module_exit(alsa_card_cs46xx_exit) | ||
diff --git a/sound/pci/cs5530.c b/sound/pci/cs5530.c index c47cabff2bfa..f1e4229993af 100644 --- a/sound/pci/cs5530.c +++ b/sound/pci/cs5530.c | |||
@@ -291,23 +291,11 @@ static int __devinit snd_cs5530_probe(struct pci_dev *pci, | |||
291 | return 0; | 291 | return 0; |
292 | } | 292 | } |
293 | 293 | ||
294 | static struct pci_driver driver = { | 294 | static struct pci_driver cs5530_driver = { |
295 | .name = KBUILD_MODNAME, | 295 | .name = KBUILD_MODNAME, |
296 | .id_table = snd_cs5530_ids, | 296 | .id_table = snd_cs5530_ids, |
297 | .probe = snd_cs5530_probe, | 297 | .probe = snd_cs5530_probe, |
298 | .remove = __devexit_p(snd_cs5530_remove), | 298 | .remove = __devexit_p(snd_cs5530_remove), |
299 | }; | 299 | }; |
300 | 300 | ||
301 | static int __init alsa_card_cs5530_init(void) | 301 | module_pci_driver(cs5530_driver); |
302 | { | ||
303 | return pci_register_driver(&driver); | ||
304 | } | ||
305 | |||
306 | static void __exit alsa_card_cs5530_exit(void) | ||
307 | { | ||
308 | pci_unregister_driver(&driver); | ||
309 | } | ||
310 | |||
311 | module_init(alsa_card_cs5530_init) | ||
312 | module_exit(alsa_card_cs5530_exit) | ||
313 | |||
diff --git a/sound/pci/cs5535audio/cs5535audio.c b/sound/pci/cs5535audio/cs5535audio.c index a2fb2173e980..2c9697cf0a1a 100644 --- a/sound/pci/cs5535audio/cs5535audio.c +++ b/sound/pci/cs5535audio/cs5535audio.c | |||
@@ -394,7 +394,7 @@ static void __devexit snd_cs5535audio_remove(struct pci_dev *pci) | |||
394 | pci_set_drvdata(pci, NULL); | 394 | pci_set_drvdata(pci, NULL); |
395 | } | 395 | } |
396 | 396 | ||
397 | static struct pci_driver driver = { | 397 | static struct pci_driver cs5535audio_driver = { |
398 | .name = KBUILD_MODNAME, | 398 | .name = KBUILD_MODNAME, |
399 | .id_table = snd_cs5535audio_ids, | 399 | .id_table = snd_cs5535audio_ids, |
400 | .probe = snd_cs5535audio_probe, | 400 | .probe = snd_cs5535audio_probe, |
@@ -405,18 +405,7 @@ static struct pci_driver driver = { | |||
405 | #endif | 405 | #endif |
406 | }; | 406 | }; |
407 | 407 | ||
408 | static int __init alsa_card_cs5535audio_init(void) | 408 | module_pci_driver(cs5535audio_driver); |
409 | { | ||
410 | return pci_register_driver(&driver); | ||
411 | } | ||
412 | |||
413 | static void __exit alsa_card_cs5535audio_exit(void) | ||
414 | { | ||
415 | pci_unregister_driver(&driver); | ||
416 | } | ||
417 | |||
418 | module_init(alsa_card_cs5535audio_init) | ||
419 | module_exit(alsa_card_cs5535audio_exit) | ||
420 | 409 | ||
421 | MODULE_AUTHOR("Jaya Kumar"); | 410 | MODULE_AUTHOR("Jaya Kumar"); |
422 | MODULE_LICENSE("GPL"); | 411 | MODULE_LICENSE("GPL"); |
diff --git a/sound/pci/ctxfi/xfi.c b/sound/pci/ctxfi/xfi.c index 15d95d2bacee..75aa2c338410 100644 --- a/sound/pci/ctxfi/xfi.c +++ b/sound/pci/ctxfi/xfi.c | |||
@@ -154,15 +154,4 @@ static struct pci_driver ct_driver = { | |||
154 | #endif | 154 | #endif |
155 | }; | 155 | }; |
156 | 156 | ||
157 | static int __init ct_card_init(void) | 157 | module_pci_driver(ct_driver); |
158 | { | ||
159 | return pci_register_driver(&ct_driver); | ||
160 | } | ||
161 | |||
162 | static void __exit ct_card_exit(void) | ||
163 | { | ||
164 | pci_unregister_driver(&ct_driver); | ||
165 | } | ||
166 | |||
167 | module_init(ct_card_init) | ||
168 | module_exit(ct_card_exit) | ||
diff --git a/sound/pci/echoaudio/echoaudio.c b/sound/pci/echoaudio/echoaudio.c index 595c11f904bb..0f8eda1dafdb 100644 --- a/sound/pci/echoaudio/echoaudio.c +++ b/sound/pci/echoaudio/echoaudio.c | |||
@@ -2328,7 +2328,7 @@ static void __devexit snd_echo_remove(struct pci_dev *pci) | |||
2328 | ******************************************************************************/ | 2328 | ******************************************************************************/ |
2329 | 2329 | ||
2330 | /* pci_driver definition */ | 2330 | /* pci_driver definition */ |
2331 | static struct pci_driver driver = { | 2331 | static struct pci_driver echo_driver = { |
2332 | .name = KBUILD_MODNAME, | 2332 | .name = KBUILD_MODNAME, |
2333 | .id_table = snd_echo_ids, | 2333 | .id_table = snd_echo_ids, |
2334 | .probe = snd_echo_probe, | 2334 | .probe = snd_echo_probe, |
@@ -2339,22 +2339,4 @@ static struct pci_driver driver = { | |||
2339 | #endif /* CONFIG_PM */ | 2339 | #endif /* CONFIG_PM */ |
2340 | }; | 2340 | }; |
2341 | 2341 | ||
2342 | 2342 | module_pci_driver(echo_driver); | |
2343 | |||
2344 | /* initialization of the module */ | ||
2345 | static int __init alsa_card_echo_init(void) | ||
2346 | { | ||
2347 | return pci_register_driver(&driver); | ||
2348 | } | ||
2349 | |||
2350 | |||
2351 | |||
2352 | /* clean up the module */ | ||
2353 | static void __exit alsa_card_echo_exit(void) | ||
2354 | { | ||
2355 | pci_unregister_driver(&driver); | ||
2356 | } | ||
2357 | |||
2358 | |||
2359 | module_init(alsa_card_echo_init) | ||
2360 | module_exit(alsa_card_echo_exit) | ||
diff --git a/sound/pci/emu10k1/emu10k1.c b/sound/pci/emu10k1/emu10k1.c index 790c65d980c8..7fdbbe4d9965 100644 --- a/sound/pci/emu10k1/emu10k1.c +++ b/sound/pci/emu10k1/emu10k1.c | |||
@@ -263,7 +263,7 @@ static int snd_emu10k1_resume(struct pci_dev *pci) | |||
263 | } | 263 | } |
264 | #endif | 264 | #endif |
265 | 265 | ||
266 | static struct pci_driver driver = { | 266 | static struct pci_driver emu10k1_driver = { |
267 | .name = KBUILD_MODNAME, | 267 | .name = KBUILD_MODNAME, |
268 | .id_table = snd_emu10k1_ids, | 268 | .id_table = snd_emu10k1_ids, |
269 | .probe = snd_card_emu10k1_probe, | 269 | .probe = snd_card_emu10k1_probe, |
@@ -274,15 +274,4 @@ static struct pci_driver driver = { | |||
274 | #endif | 274 | #endif |
275 | }; | 275 | }; |
276 | 276 | ||
277 | static int __init alsa_card_emu10k1_init(void) | 277 | module_pci_driver(emu10k1_driver); |
278 | { | ||
279 | return pci_register_driver(&driver); | ||
280 | } | ||
281 | |||
282 | static void __exit alsa_card_emu10k1_exit(void) | ||
283 | { | ||
284 | pci_unregister_driver(&driver); | ||
285 | } | ||
286 | |||
287 | module_init(alsa_card_emu10k1_init) | ||
288 | module_exit(alsa_card_emu10k1_exit) | ||
diff --git a/sound/pci/emu10k1/emu10k1x.c b/sound/pci/emu10k1/emu10k1x.c index 47a651cb6e84..5c8978b2c4d9 100644 --- a/sound/pci/emu10k1/emu10k1x.c +++ b/sound/pci/emu10k1/emu10k1x.c | |||
@@ -1612,24 +1612,11 @@ static DEFINE_PCI_DEVICE_TABLE(snd_emu10k1x_ids) = { | |||
1612 | MODULE_DEVICE_TABLE(pci, snd_emu10k1x_ids); | 1612 | MODULE_DEVICE_TABLE(pci, snd_emu10k1x_ids); |
1613 | 1613 | ||
1614 | // pci_driver definition | 1614 | // pci_driver definition |
1615 | static struct pci_driver driver = { | 1615 | static struct pci_driver emu10k1x_driver = { |
1616 | .name = KBUILD_MODNAME, | 1616 | .name = KBUILD_MODNAME, |
1617 | .id_table = snd_emu10k1x_ids, | 1617 | .id_table = snd_emu10k1x_ids, |
1618 | .probe = snd_emu10k1x_probe, | 1618 | .probe = snd_emu10k1x_probe, |
1619 | .remove = __devexit_p(snd_emu10k1x_remove), | 1619 | .remove = __devexit_p(snd_emu10k1x_remove), |
1620 | }; | 1620 | }; |
1621 | 1621 | ||
1622 | // initialization of the module | 1622 | module_pci_driver(emu10k1x_driver); |
1623 | static int __init alsa_card_emu10k1x_init(void) | ||
1624 | { | ||
1625 | return pci_register_driver(&driver); | ||
1626 | } | ||
1627 | |||
1628 | // clean up the module | ||
1629 | static void __exit alsa_card_emu10k1x_exit(void) | ||
1630 | { | ||
1631 | pci_unregister_driver(&driver); | ||
1632 | } | ||
1633 | |||
1634 | module_init(alsa_card_emu10k1x_init) | ||
1635 | module_exit(alsa_card_emu10k1x_exit) | ||
diff --git a/sound/pci/ens1370.c b/sound/pci/ens1370.c index 47a245e84190..3821c81d1c99 100644 --- a/sound/pci/ens1370.c +++ b/sound/pci/ens1370.c | |||
@@ -2488,7 +2488,7 @@ static void __devexit snd_audiopci_remove(struct pci_dev *pci) | |||
2488 | pci_set_drvdata(pci, NULL); | 2488 | pci_set_drvdata(pci, NULL); |
2489 | } | 2489 | } |
2490 | 2490 | ||
2491 | static struct pci_driver driver = { | 2491 | static struct pci_driver ens137x_driver = { |
2492 | .name = KBUILD_MODNAME, | 2492 | .name = KBUILD_MODNAME, |
2493 | .id_table = snd_audiopci_ids, | 2493 | .id_table = snd_audiopci_ids, |
2494 | .probe = snd_audiopci_probe, | 2494 | .probe = snd_audiopci_probe, |
@@ -2499,15 +2499,4 @@ static struct pci_driver driver = { | |||
2499 | #endif | 2499 | #endif |
2500 | }; | 2500 | }; |
2501 | 2501 | ||
2502 | static int __init alsa_card_ens137x_init(void) | 2502 | module_pci_driver(ens137x_driver); |
2503 | { | ||
2504 | return pci_register_driver(&driver); | ||
2505 | } | ||
2506 | |||
2507 | static void __exit alsa_card_ens137x_exit(void) | ||
2508 | { | ||
2509 | pci_unregister_driver(&driver); | ||
2510 | } | ||
2511 | |||
2512 | module_init(alsa_card_ens137x_init) | ||
2513 | module_exit(alsa_card_ens137x_exit) | ||
diff --git a/sound/pci/es1938.c b/sound/pci/es1938.c index 53eb76b41108..82c8d8c5c52a 100644 --- a/sound/pci/es1938.c +++ b/sound/pci/es1938.c | |||
@@ -1882,7 +1882,7 @@ static void __devexit snd_es1938_remove(struct pci_dev *pci) | |||
1882 | pci_set_drvdata(pci, NULL); | 1882 | pci_set_drvdata(pci, NULL); |
1883 | } | 1883 | } |
1884 | 1884 | ||
1885 | static struct pci_driver driver = { | 1885 | static struct pci_driver es1938_driver = { |
1886 | .name = KBUILD_MODNAME, | 1886 | .name = KBUILD_MODNAME, |
1887 | .id_table = snd_es1938_ids, | 1887 | .id_table = snd_es1938_ids, |
1888 | .probe = snd_es1938_probe, | 1888 | .probe = snd_es1938_probe, |
@@ -1893,15 +1893,4 @@ static struct pci_driver driver = { | |||
1893 | #endif | 1893 | #endif |
1894 | }; | 1894 | }; |
1895 | 1895 | ||
1896 | static int __init alsa_card_es1938_init(void) | 1896 | module_pci_driver(es1938_driver); |
1897 | { | ||
1898 | return pci_register_driver(&driver); | ||
1899 | } | ||
1900 | |||
1901 | static void __exit alsa_card_es1938_exit(void) | ||
1902 | { | ||
1903 | pci_unregister_driver(&driver); | ||
1904 | } | ||
1905 | |||
1906 | module_init(alsa_card_es1938_init) | ||
1907 | module_exit(alsa_card_es1938_exit) | ||
diff --git a/sound/pci/es1968.c b/sound/pci/es1968.c index a8faae1c85e4..67f47d891959 100644 --- a/sound/pci/es1968.c +++ b/sound/pci/es1968.c | |||
@@ -2898,7 +2898,7 @@ static void __devexit snd_es1968_remove(struct pci_dev *pci) | |||
2898 | pci_set_drvdata(pci, NULL); | 2898 | pci_set_drvdata(pci, NULL); |
2899 | } | 2899 | } |
2900 | 2900 | ||
2901 | static struct pci_driver driver = { | 2901 | static struct pci_driver es1968_driver = { |
2902 | .name = KBUILD_MODNAME, | 2902 | .name = KBUILD_MODNAME, |
2903 | .id_table = snd_es1968_ids, | 2903 | .id_table = snd_es1968_ids, |
2904 | .probe = snd_es1968_probe, | 2904 | .probe = snd_es1968_probe, |
@@ -2909,15 +2909,4 @@ static struct pci_driver driver = { | |||
2909 | #endif | 2909 | #endif |
2910 | }; | 2910 | }; |
2911 | 2911 | ||
2912 | static int __init alsa_card_es1968_init(void) | 2912 | module_pci_driver(es1968_driver); |
2913 | { | ||
2914 | return pci_register_driver(&driver); | ||
2915 | } | ||
2916 | |||
2917 | static void __exit alsa_card_es1968_exit(void) | ||
2918 | { | ||
2919 | pci_unregister_driver(&driver); | ||
2920 | } | ||
2921 | |||
2922 | module_init(alsa_card_es1968_init) | ||
2923 | module_exit(alsa_card_es1968_exit) | ||
diff --git a/sound/pci/fm801.c b/sound/pci/fm801.c index a416ea8af3e9..f69662322750 100644 --- a/sound/pci/fm801.c +++ b/sound/pci/fm801.c | |||
@@ -1416,7 +1416,7 @@ static int snd_fm801_resume(struct pci_dev *pci) | |||
1416 | } | 1416 | } |
1417 | #endif | 1417 | #endif |
1418 | 1418 | ||
1419 | static struct pci_driver driver = { | 1419 | static struct pci_driver fm801_driver = { |
1420 | .name = KBUILD_MODNAME, | 1420 | .name = KBUILD_MODNAME, |
1421 | .id_table = snd_fm801_ids, | 1421 | .id_table = snd_fm801_ids, |
1422 | .probe = snd_card_fm801_probe, | 1422 | .probe = snd_card_fm801_probe, |
@@ -1427,15 +1427,4 @@ static struct pci_driver driver = { | |||
1427 | #endif | 1427 | #endif |
1428 | }; | 1428 | }; |
1429 | 1429 | ||
1430 | static int __init alsa_card_fm801_init(void) | 1430 | module_pci_driver(fm801_driver); |
1431 | { | ||
1432 | return pci_register_driver(&driver); | ||
1433 | } | ||
1434 | |||
1435 | static void __exit alsa_card_fm801_exit(void) | ||
1436 | { | ||
1437 | pci_unregister_driver(&driver); | ||
1438 | } | ||
1439 | |||
1440 | module_init(alsa_card_fm801_init) | ||
1441 | module_exit(alsa_card_fm801_exit) | ||
diff --git a/sound/pci/hda/Makefile b/sound/pci/hda/Makefile index ace157cc3d15..bd4149f1aaf4 100644 --- a/sound/pci/hda/Makefile +++ b/sound/pci/hda/Makefile | |||
@@ -1,6 +1,6 @@ | |||
1 | snd-hda-intel-objs := hda_intel.o | 1 | snd-hda-intel-objs := hda_intel.o |
2 | 2 | ||
3 | snd-hda-codec-y := hda_codec.o hda_jack.o | 3 | snd-hda-codec-y := hda_codec.o hda_jack.o hda_auto_parser.o |
4 | snd-hda-codec-$(CONFIG_SND_HDA_GENERIC) += hda_generic.o | 4 | snd-hda-codec-$(CONFIG_SND_HDA_GENERIC) += hda_generic.o |
5 | snd-hda-codec-$(CONFIG_PROC_FS) += hda_proc.o | 5 | snd-hda-codec-$(CONFIG_PROC_FS) += hda_proc.o |
6 | snd-hda-codec-$(CONFIG_SND_HDA_HWDEP) += hda_hwdep.o | 6 | snd-hda-codec-$(CONFIG_SND_HDA_HWDEP) += hda_hwdep.o |
diff --git a/sound/pci/hda/hda_auto_parser.c b/sound/pci/hda/hda_auto_parser.c new file mode 100644 index 000000000000..6e9ef3e25093 --- /dev/null +++ b/sound/pci/hda/hda_auto_parser.c | |||
@@ -0,0 +1,760 @@ | |||
1 | /* | ||
2 | * BIOS auto-parser helper functions for HD-audio | ||
3 | * | ||
4 | * Copyright (c) 2012 Takashi Iwai <tiwai@suse.de> | ||
5 | * | ||
6 | * This driver is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; either version 2 of the License, or | ||
9 | * (at your option) any later version. | ||
10 | */ | ||
11 | |||
12 | #include <linux/slab.h> | ||
13 | #include <linux/export.h> | ||
14 | #include <sound/core.h> | ||
15 | #include "hda_codec.h" | ||
16 | #include "hda_local.h" | ||
17 | #include "hda_auto_parser.h" | ||
18 | |||
19 | #define SFX "hda_codec: " | ||
20 | |||
21 | /* | ||
22 | * Helper for automatic pin configuration | ||
23 | */ | ||
24 | |||
25 | static int is_in_nid_list(hda_nid_t nid, const hda_nid_t *list) | ||
26 | { | ||
27 | for (; *list; list++) | ||
28 | if (*list == nid) | ||
29 | return 1; | ||
30 | return 0; | ||
31 | } | ||
32 | |||
33 | |||
34 | /* | ||
35 | * Sort an associated group of pins according to their sequence numbers. | ||
36 | */ | ||
37 | static void sort_pins_by_sequence(hda_nid_t *pins, short *sequences, | ||
38 | int num_pins) | ||
39 | { | ||
40 | int i, j; | ||
41 | short seq; | ||
42 | hda_nid_t nid; | ||
43 | |||
44 | for (i = 0; i < num_pins; i++) { | ||
45 | for (j = i + 1; j < num_pins; j++) { | ||
46 | if (sequences[i] > sequences[j]) { | ||
47 | seq = sequences[i]; | ||
48 | sequences[i] = sequences[j]; | ||
49 | sequences[j] = seq; | ||
50 | nid = pins[i]; | ||
51 | pins[i] = pins[j]; | ||
52 | pins[j] = nid; | ||
53 | } | ||
54 | } | ||
55 | } | ||
56 | } | ||
57 | |||
58 | |||
59 | /* add the found input-pin to the cfg->inputs[] table */ | ||
60 | static void add_auto_cfg_input_pin(struct auto_pin_cfg *cfg, hda_nid_t nid, | ||
61 | int type) | ||
62 | { | ||
63 | if (cfg->num_inputs < AUTO_CFG_MAX_INS) { | ||
64 | cfg->inputs[cfg->num_inputs].pin = nid; | ||
65 | cfg->inputs[cfg->num_inputs].type = type; | ||
66 | cfg->num_inputs++; | ||
67 | } | ||
68 | } | ||
69 | |||
70 | /* sort inputs in the order of AUTO_PIN_* type */ | ||
71 | static void sort_autocfg_input_pins(struct auto_pin_cfg *cfg) | ||
72 | { | ||
73 | int i, j; | ||
74 | |||
75 | for (i = 0; i < cfg->num_inputs; i++) { | ||
76 | for (j = i + 1; j < cfg->num_inputs; j++) { | ||
77 | if (cfg->inputs[i].type > cfg->inputs[j].type) { | ||
78 | struct auto_pin_cfg_item tmp; | ||
79 | tmp = cfg->inputs[i]; | ||
80 | cfg->inputs[i] = cfg->inputs[j]; | ||
81 | cfg->inputs[j] = tmp; | ||
82 | } | ||
83 | } | ||
84 | } | ||
85 | } | ||
86 | |||
87 | /* Reorder the surround channels | ||
88 | * ALSA sequence is front/surr/clfe/side | ||
89 | * HDA sequence is: | ||
90 | * 4-ch: front/surr => OK as it is | ||
91 | * 6-ch: front/clfe/surr | ||
92 | * 8-ch: front/clfe/rear/side|fc | ||
93 | */ | ||
94 | static void reorder_outputs(unsigned int nums, hda_nid_t *pins) | ||
95 | { | ||
96 | hda_nid_t nid; | ||
97 | |||
98 | switch (nums) { | ||
99 | case 3: | ||
100 | case 4: | ||
101 | nid = pins[1]; | ||
102 | pins[1] = pins[2]; | ||
103 | pins[2] = nid; | ||
104 | break; | ||
105 | } | ||
106 | } | ||
107 | |||
108 | /* | ||
109 | * Parse all pin widgets and store the useful pin nids to cfg | ||
110 | * | ||
111 | * The number of line-outs or any primary output is stored in line_outs, | ||
112 | * and the corresponding output pins are assigned to line_out_pins[], | ||
113 | * in the order of front, rear, CLFE, side, ... | ||
114 | * | ||
115 | * If more extra outputs (speaker and headphone) are found, the pins are | ||
116 | * assisnged to hp_pins[] and speaker_pins[], respectively. If no line-out jack | ||
117 | * is detected, one of speaker of HP pins is assigned as the primary | ||
118 | * output, i.e. to line_out_pins[0]. So, line_outs is always positive | ||
119 | * if any analog output exists. | ||
120 | * | ||
121 | * The analog input pins are assigned to inputs array. | ||
122 | * The digital input/output pins are assigned to dig_in_pin and dig_out_pin, | ||
123 | * respectively. | ||
124 | */ | ||
125 | int snd_hda_parse_pin_defcfg(struct hda_codec *codec, | ||
126 | struct auto_pin_cfg *cfg, | ||
127 | const hda_nid_t *ignore_nids, | ||
128 | unsigned int cond_flags) | ||
129 | { | ||
130 | hda_nid_t nid, end_nid; | ||
131 | short seq, assoc_line_out; | ||
132 | short sequences_line_out[ARRAY_SIZE(cfg->line_out_pins)]; | ||
133 | short sequences_speaker[ARRAY_SIZE(cfg->speaker_pins)]; | ||
134 | short sequences_hp[ARRAY_SIZE(cfg->hp_pins)]; | ||
135 | int i; | ||
136 | |||
137 | memset(cfg, 0, sizeof(*cfg)); | ||
138 | |||
139 | memset(sequences_line_out, 0, sizeof(sequences_line_out)); | ||
140 | memset(sequences_speaker, 0, sizeof(sequences_speaker)); | ||
141 | memset(sequences_hp, 0, sizeof(sequences_hp)); | ||
142 | assoc_line_out = 0; | ||
143 | |||
144 | codec->ignore_misc_bit = true; | ||
145 | end_nid = codec->start_nid + codec->num_nodes; | ||
146 | for (nid = codec->start_nid; nid < end_nid; nid++) { | ||
147 | unsigned int wid_caps = get_wcaps(codec, nid); | ||
148 | unsigned int wid_type = get_wcaps_type(wid_caps); | ||
149 | unsigned int def_conf; | ||
150 | short assoc, loc, conn, dev; | ||
151 | |||
152 | /* read all default configuration for pin complex */ | ||
153 | if (wid_type != AC_WID_PIN) | ||
154 | continue; | ||
155 | /* ignore the given nids (e.g. pc-beep returns error) */ | ||
156 | if (ignore_nids && is_in_nid_list(nid, ignore_nids)) | ||
157 | continue; | ||
158 | |||
159 | def_conf = snd_hda_codec_get_pincfg(codec, nid); | ||
160 | if (!(get_defcfg_misc(snd_hda_codec_get_pincfg(codec, nid)) & | ||
161 | AC_DEFCFG_MISC_NO_PRESENCE)) | ||
162 | codec->ignore_misc_bit = false; | ||
163 | conn = get_defcfg_connect(def_conf); | ||
164 | if (conn == AC_JACK_PORT_NONE) | ||
165 | continue; | ||
166 | loc = get_defcfg_location(def_conf); | ||
167 | dev = get_defcfg_device(def_conf); | ||
168 | |||
169 | /* workaround for buggy BIOS setups */ | ||
170 | if (dev == AC_JACK_LINE_OUT) { | ||
171 | if (conn == AC_JACK_PORT_FIXED) | ||
172 | dev = AC_JACK_SPEAKER; | ||
173 | } | ||
174 | |||
175 | switch (dev) { | ||
176 | case AC_JACK_LINE_OUT: | ||
177 | seq = get_defcfg_sequence(def_conf); | ||
178 | assoc = get_defcfg_association(def_conf); | ||
179 | |||
180 | if (!(wid_caps & AC_WCAP_STEREO)) | ||
181 | if (!cfg->mono_out_pin) | ||
182 | cfg->mono_out_pin = nid; | ||
183 | if (!assoc) | ||
184 | continue; | ||
185 | if (!assoc_line_out) | ||
186 | assoc_line_out = assoc; | ||
187 | else if (assoc_line_out != assoc) | ||
188 | continue; | ||
189 | if (cfg->line_outs >= ARRAY_SIZE(cfg->line_out_pins)) | ||
190 | continue; | ||
191 | cfg->line_out_pins[cfg->line_outs] = nid; | ||
192 | sequences_line_out[cfg->line_outs] = seq; | ||
193 | cfg->line_outs++; | ||
194 | break; | ||
195 | case AC_JACK_SPEAKER: | ||
196 | seq = get_defcfg_sequence(def_conf); | ||
197 | assoc = get_defcfg_association(def_conf); | ||
198 | if (cfg->speaker_outs >= ARRAY_SIZE(cfg->speaker_pins)) | ||
199 | continue; | ||
200 | cfg->speaker_pins[cfg->speaker_outs] = nid; | ||
201 | sequences_speaker[cfg->speaker_outs] = (assoc << 4) | seq; | ||
202 | cfg->speaker_outs++; | ||
203 | break; | ||
204 | case AC_JACK_HP_OUT: | ||
205 | seq = get_defcfg_sequence(def_conf); | ||
206 | assoc = get_defcfg_association(def_conf); | ||
207 | if (cfg->hp_outs >= ARRAY_SIZE(cfg->hp_pins)) | ||
208 | continue; | ||
209 | cfg->hp_pins[cfg->hp_outs] = nid; | ||
210 | sequences_hp[cfg->hp_outs] = (assoc << 4) | seq; | ||
211 | cfg->hp_outs++; | ||
212 | break; | ||
213 | case AC_JACK_MIC_IN: | ||
214 | add_auto_cfg_input_pin(cfg, nid, AUTO_PIN_MIC); | ||
215 | break; | ||
216 | case AC_JACK_LINE_IN: | ||
217 | add_auto_cfg_input_pin(cfg, nid, AUTO_PIN_LINE_IN); | ||
218 | break; | ||
219 | case AC_JACK_CD: | ||
220 | add_auto_cfg_input_pin(cfg, nid, AUTO_PIN_CD); | ||
221 | break; | ||
222 | case AC_JACK_AUX: | ||
223 | add_auto_cfg_input_pin(cfg, nid, AUTO_PIN_AUX); | ||
224 | break; | ||
225 | case AC_JACK_SPDIF_OUT: | ||
226 | case AC_JACK_DIG_OTHER_OUT: | ||
227 | if (cfg->dig_outs >= ARRAY_SIZE(cfg->dig_out_pins)) | ||
228 | continue; | ||
229 | cfg->dig_out_pins[cfg->dig_outs] = nid; | ||
230 | cfg->dig_out_type[cfg->dig_outs] = | ||
231 | (loc == AC_JACK_LOC_HDMI) ? | ||
232 | HDA_PCM_TYPE_HDMI : HDA_PCM_TYPE_SPDIF; | ||
233 | cfg->dig_outs++; | ||
234 | break; | ||
235 | case AC_JACK_SPDIF_IN: | ||
236 | case AC_JACK_DIG_OTHER_IN: | ||
237 | cfg->dig_in_pin = nid; | ||
238 | if (loc == AC_JACK_LOC_HDMI) | ||
239 | cfg->dig_in_type = HDA_PCM_TYPE_HDMI; | ||
240 | else | ||
241 | cfg->dig_in_type = HDA_PCM_TYPE_SPDIF; | ||
242 | break; | ||
243 | } | ||
244 | } | ||
245 | |||
246 | /* FIX-UP: | ||
247 | * If no line-out is defined but multiple HPs are found, | ||
248 | * some of them might be the real line-outs. | ||
249 | */ | ||
250 | if (!cfg->line_outs && cfg->hp_outs > 1 && | ||
251 | !(cond_flags & HDA_PINCFG_NO_HP_FIXUP)) { | ||
252 | int i = 0; | ||
253 | while (i < cfg->hp_outs) { | ||
254 | /* The real HPs should have the sequence 0x0f */ | ||
255 | if ((sequences_hp[i] & 0x0f) == 0x0f) { | ||
256 | i++; | ||
257 | continue; | ||
258 | } | ||
259 | /* Move it to the line-out table */ | ||
260 | cfg->line_out_pins[cfg->line_outs] = cfg->hp_pins[i]; | ||
261 | sequences_line_out[cfg->line_outs] = sequences_hp[i]; | ||
262 | cfg->line_outs++; | ||
263 | cfg->hp_outs--; | ||
264 | memmove(cfg->hp_pins + i, cfg->hp_pins + i + 1, | ||
265 | sizeof(cfg->hp_pins[0]) * (cfg->hp_outs - i)); | ||
266 | memmove(sequences_hp + i, sequences_hp + i + 1, | ||
267 | sizeof(sequences_hp[0]) * (cfg->hp_outs - i)); | ||
268 | } | ||
269 | memset(cfg->hp_pins + cfg->hp_outs, 0, | ||
270 | sizeof(hda_nid_t) * (AUTO_CFG_MAX_OUTS - cfg->hp_outs)); | ||
271 | if (!cfg->hp_outs) | ||
272 | cfg->line_out_type = AUTO_PIN_HP_OUT; | ||
273 | |||
274 | } | ||
275 | |||
276 | /* sort by sequence */ | ||
277 | sort_pins_by_sequence(cfg->line_out_pins, sequences_line_out, | ||
278 | cfg->line_outs); | ||
279 | sort_pins_by_sequence(cfg->speaker_pins, sequences_speaker, | ||
280 | cfg->speaker_outs); | ||
281 | sort_pins_by_sequence(cfg->hp_pins, sequences_hp, | ||
282 | cfg->hp_outs); | ||
283 | |||
284 | /* | ||
285 | * FIX-UP: if no line-outs are detected, try to use speaker or HP pin | ||
286 | * as a primary output | ||
287 | */ | ||
288 | if (!cfg->line_outs && | ||
289 | !(cond_flags & HDA_PINCFG_NO_LO_FIXUP)) { | ||
290 | if (cfg->speaker_outs) { | ||
291 | cfg->line_outs = cfg->speaker_outs; | ||
292 | memcpy(cfg->line_out_pins, cfg->speaker_pins, | ||
293 | sizeof(cfg->speaker_pins)); | ||
294 | cfg->speaker_outs = 0; | ||
295 | memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins)); | ||
296 | cfg->line_out_type = AUTO_PIN_SPEAKER_OUT; | ||
297 | } else if (cfg->hp_outs) { | ||
298 | cfg->line_outs = cfg->hp_outs; | ||
299 | memcpy(cfg->line_out_pins, cfg->hp_pins, | ||
300 | sizeof(cfg->hp_pins)); | ||
301 | cfg->hp_outs = 0; | ||
302 | memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins)); | ||
303 | cfg->line_out_type = AUTO_PIN_HP_OUT; | ||
304 | } | ||
305 | } | ||
306 | |||
307 | reorder_outputs(cfg->line_outs, cfg->line_out_pins); | ||
308 | reorder_outputs(cfg->hp_outs, cfg->hp_pins); | ||
309 | reorder_outputs(cfg->speaker_outs, cfg->speaker_pins); | ||
310 | |||
311 | sort_autocfg_input_pins(cfg); | ||
312 | |||
313 | /* | ||
314 | * debug prints of the parsed results | ||
315 | */ | ||
316 | snd_printd("autoconfig: line_outs=%d (0x%x/0x%x/0x%x/0x%x/0x%x) type:%s\n", | ||
317 | cfg->line_outs, cfg->line_out_pins[0], cfg->line_out_pins[1], | ||
318 | cfg->line_out_pins[2], cfg->line_out_pins[3], | ||
319 | cfg->line_out_pins[4], | ||
320 | cfg->line_out_type == AUTO_PIN_HP_OUT ? "hp" : | ||
321 | (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT ? | ||
322 | "speaker" : "line")); | ||
323 | snd_printd(" speaker_outs=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n", | ||
324 | cfg->speaker_outs, cfg->speaker_pins[0], | ||
325 | cfg->speaker_pins[1], cfg->speaker_pins[2], | ||
326 | cfg->speaker_pins[3], cfg->speaker_pins[4]); | ||
327 | snd_printd(" hp_outs=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n", | ||
328 | cfg->hp_outs, cfg->hp_pins[0], | ||
329 | cfg->hp_pins[1], cfg->hp_pins[2], | ||
330 | cfg->hp_pins[3], cfg->hp_pins[4]); | ||
331 | snd_printd(" mono: mono_out=0x%x\n", cfg->mono_out_pin); | ||
332 | if (cfg->dig_outs) | ||
333 | snd_printd(" dig-out=0x%x/0x%x\n", | ||
334 | cfg->dig_out_pins[0], cfg->dig_out_pins[1]); | ||
335 | snd_printd(" inputs:"); | ||
336 | for (i = 0; i < cfg->num_inputs; i++) { | ||
337 | snd_printd(" %s=0x%x", | ||
338 | hda_get_autocfg_input_label(codec, cfg, i), | ||
339 | cfg->inputs[i].pin); | ||
340 | } | ||
341 | snd_printd("\n"); | ||
342 | if (cfg->dig_in_pin) | ||
343 | snd_printd(" dig-in=0x%x\n", cfg->dig_in_pin); | ||
344 | |||
345 | return 0; | ||
346 | } | ||
347 | EXPORT_SYMBOL_HDA(snd_hda_parse_pin_defcfg); | ||
348 | |||
349 | int snd_hda_get_input_pin_attr(unsigned int def_conf) | ||
350 | { | ||
351 | unsigned int loc = get_defcfg_location(def_conf); | ||
352 | unsigned int conn = get_defcfg_connect(def_conf); | ||
353 | if (conn == AC_JACK_PORT_NONE) | ||
354 | return INPUT_PIN_ATTR_UNUSED; | ||
355 | /* Windows may claim the internal mic to be BOTH, too */ | ||
356 | if (conn == AC_JACK_PORT_FIXED || conn == AC_JACK_PORT_BOTH) | ||
357 | return INPUT_PIN_ATTR_INT; | ||
358 | if ((loc & 0x30) == AC_JACK_LOC_INTERNAL) | ||
359 | return INPUT_PIN_ATTR_INT; | ||
360 | if ((loc & 0x30) == AC_JACK_LOC_SEPARATE) | ||
361 | return INPUT_PIN_ATTR_DOCK; | ||
362 | if (loc == AC_JACK_LOC_REAR) | ||
363 | return INPUT_PIN_ATTR_REAR; | ||
364 | if (loc == AC_JACK_LOC_FRONT) | ||
365 | return INPUT_PIN_ATTR_FRONT; | ||
366 | return INPUT_PIN_ATTR_NORMAL; | ||
367 | } | ||
368 | EXPORT_SYMBOL_HDA(snd_hda_get_input_pin_attr); | ||
369 | |||
370 | /** | ||
371 | * hda_get_input_pin_label - Give a label for the given input pin | ||
372 | * | ||
373 | * When check_location is true, the function checks the pin location | ||
374 | * for mic and line-in pins, and set an appropriate prefix like "Front", | ||
375 | * "Rear", "Internal". | ||
376 | */ | ||
377 | |||
378 | static const char *hda_get_input_pin_label(struct hda_codec *codec, | ||
379 | hda_nid_t pin, bool check_location) | ||
380 | { | ||
381 | unsigned int def_conf; | ||
382 | static const char * const mic_names[] = { | ||
383 | "Internal Mic", "Dock Mic", "Mic", "Front Mic", "Rear Mic", | ||
384 | }; | ||
385 | int attr; | ||
386 | |||
387 | def_conf = snd_hda_codec_get_pincfg(codec, pin); | ||
388 | |||
389 | switch (get_defcfg_device(def_conf)) { | ||
390 | case AC_JACK_MIC_IN: | ||
391 | if (!check_location) | ||
392 | return "Mic"; | ||
393 | attr = snd_hda_get_input_pin_attr(def_conf); | ||
394 | if (!attr) | ||
395 | return "None"; | ||
396 | return mic_names[attr - 1]; | ||
397 | case AC_JACK_LINE_IN: | ||
398 | if (!check_location) | ||
399 | return "Line"; | ||
400 | attr = snd_hda_get_input_pin_attr(def_conf); | ||
401 | if (!attr) | ||
402 | return "None"; | ||
403 | if (attr == INPUT_PIN_ATTR_DOCK) | ||
404 | return "Dock Line"; | ||
405 | return "Line"; | ||
406 | case AC_JACK_AUX: | ||
407 | return "Aux"; | ||
408 | case AC_JACK_CD: | ||
409 | return "CD"; | ||
410 | case AC_JACK_SPDIF_IN: | ||
411 | return "SPDIF In"; | ||
412 | case AC_JACK_DIG_OTHER_IN: | ||
413 | return "Digital In"; | ||
414 | default: | ||
415 | return "Misc"; | ||
416 | } | ||
417 | } | ||
418 | |||
419 | /* Check whether the location prefix needs to be added to the label. | ||
420 | * If all mic-jacks are in the same location (e.g. rear panel), we don't | ||
421 | * have to put "Front" prefix to each label. In such a case, returns false. | ||
422 | */ | ||
423 | static int check_mic_location_need(struct hda_codec *codec, | ||
424 | const struct auto_pin_cfg *cfg, | ||
425 | int input) | ||
426 | { | ||
427 | unsigned int defc; | ||
428 | int i, attr, attr2; | ||
429 | |||
430 | defc = snd_hda_codec_get_pincfg(codec, cfg->inputs[input].pin); | ||
431 | attr = snd_hda_get_input_pin_attr(defc); | ||
432 | /* for internal or docking mics, we need locations */ | ||
433 | if (attr <= INPUT_PIN_ATTR_NORMAL) | ||
434 | return 1; | ||
435 | |||
436 | attr = 0; | ||
437 | for (i = 0; i < cfg->num_inputs; i++) { | ||
438 | defc = snd_hda_codec_get_pincfg(codec, cfg->inputs[i].pin); | ||
439 | attr2 = snd_hda_get_input_pin_attr(defc); | ||
440 | if (attr2 >= INPUT_PIN_ATTR_NORMAL) { | ||
441 | if (attr && attr != attr2) | ||
442 | return 1; /* different locations found */ | ||
443 | attr = attr2; | ||
444 | } | ||
445 | } | ||
446 | return 0; | ||
447 | } | ||
448 | |||
449 | /** | ||
450 | * hda_get_autocfg_input_label - Get a label for the given input | ||
451 | * | ||
452 | * Get a label for the given input pin defined by the autocfg item. | ||
453 | * Unlike hda_get_input_pin_label(), this function checks all inputs | ||
454 | * defined in autocfg and avoids the redundant mic/line prefix as much as | ||
455 | * possible. | ||
456 | */ | ||
457 | const char *hda_get_autocfg_input_label(struct hda_codec *codec, | ||
458 | const struct auto_pin_cfg *cfg, | ||
459 | int input) | ||
460 | { | ||
461 | int type = cfg->inputs[input].type; | ||
462 | int has_multiple_pins = 0; | ||
463 | |||
464 | if ((input > 0 && cfg->inputs[input - 1].type == type) || | ||
465 | (input < cfg->num_inputs - 1 && cfg->inputs[input + 1].type == type)) | ||
466 | has_multiple_pins = 1; | ||
467 | if (has_multiple_pins && type == AUTO_PIN_MIC) | ||
468 | has_multiple_pins &= check_mic_location_need(codec, cfg, input); | ||
469 | return hda_get_input_pin_label(codec, cfg->inputs[input].pin, | ||
470 | has_multiple_pins); | ||
471 | } | ||
472 | EXPORT_SYMBOL_HDA(hda_get_autocfg_input_label); | ||
473 | |||
474 | /* return the position of NID in the list, or -1 if not found */ | ||
475 | static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums) | ||
476 | { | ||
477 | int i; | ||
478 | for (i = 0; i < nums; i++) | ||
479 | if (list[i] == nid) | ||
480 | return i; | ||
481 | return -1; | ||
482 | } | ||
483 | |||
484 | /* get a unique suffix or an index number */ | ||
485 | static const char *check_output_sfx(hda_nid_t nid, const hda_nid_t *pins, | ||
486 | int num_pins, int *indexp) | ||
487 | { | ||
488 | static const char * const channel_sfx[] = { | ||
489 | " Front", " Surround", " CLFE", " Side" | ||
490 | }; | ||
491 | int i; | ||
492 | |||
493 | i = find_idx_in_nid_list(nid, pins, num_pins); | ||
494 | if (i < 0) | ||
495 | return NULL; | ||
496 | if (num_pins == 1) | ||
497 | return ""; | ||
498 | if (num_pins > ARRAY_SIZE(channel_sfx)) { | ||
499 | if (indexp) | ||
500 | *indexp = i; | ||
501 | return ""; | ||
502 | } | ||
503 | return channel_sfx[i]; | ||
504 | } | ||
505 | |||
506 | static int fill_audio_out_name(struct hda_codec *codec, hda_nid_t nid, | ||
507 | const struct auto_pin_cfg *cfg, | ||
508 | const char *name, char *label, int maxlen, | ||
509 | int *indexp) | ||
510 | { | ||
511 | unsigned int def_conf = snd_hda_codec_get_pincfg(codec, nid); | ||
512 | int attr = snd_hda_get_input_pin_attr(def_conf); | ||
513 | const char *pfx = "", *sfx = ""; | ||
514 | |||
515 | /* handle as a speaker if it's a fixed line-out */ | ||
516 | if (!strcmp(name, "Line Out") && attr == INPUT_PIN_ATTR_INT) | ||
517 | name = "Speaker"; | ||
518 | /* check the location */ | ||
519 | switch (attr) { | ||
520 | case INPUT_PIN_ATTR_DOCK: | ||
521 | pfx = "Dock "; | ||
522 | break; | ||
523 | case INPUT_PIN_ATTR_FRONT: | ||
524 | pfx = "Front "; | ||
525 | break; | ||
526 | } | ||
527 | if (cfg) { | ||
528 | /* try to give a unique suffix if needed */ | ||
529 | sfx = check_output_sfx(nid, cfg->line_out_pins, cfg->line_outs, | ||
530 | indexp); | ||
531 | if (!sfx) | ||
532 | sfx = check_output_sfx(nid, cfg->speaker_pins, cfg->speaker_outs, | ||
533 | indexp); | ||
534 | if (!sfx) { | ||
535 | /* don't add channel suffix for Headphone controls */ | ||
536 | int idx = find_idx_in_nid_list(nid, cfg->hp_pins, | ||
537 | cfg->hp_outs); | ||
538 | if (idx >= 0) | ||
539 | *indexp = idx; | ||
540 | sfx = ""; | ||
541 | } | ||
542 | } | ||
543 | snprintf(label, maxlen, "%s%s%s", pfx, name, sfx); | ||
544 | return 1; | ||
545 | } | ||
546 | |||
547 | /** | ||
548 | * snd_hda_get_pin_label - Get a label for the given I/O pin | ||
549 | * | ||
550 | * Get a label for the given pin. This function works for both input and | ||
551 | * output pins. When @cfg is given as non-NULL, the function tries to get | ||
552 | * an optimized label using hda_get_autocfg_input_label(). | ||
553 | * | ||
554 | * This function tries to give a unique label string for the pin as much as | ||
555 | * possible. For example, when the multiple line-outs are present, it adds | ||
556 | * the channel suffix like "Front", "Surround", etc (only when @cfg is given). | ||
557 | * If no unique name with a suffix is available and @indexp is non-NULL, the | ||
558 | * index number is stored in the pointer. | ||
559 | */ | ||
560 | int snd_hda_get_pin_label(struct hda_codec *codec, hda_nid_t nid, | ||
561 | const struct auto_pin_cfg *cfg, | ||
562 | char *label, int maxlen, int *indexp) | ||
563 | { | ||
564 | unsigned int def_conf = snd_hda_codec_get_pincfg(codec, nid); | ||
565 | const char *name = NULL; | ||
566 | int i; | ||
567 | |||
568 | if (indexp) | ||
569 | *indexp = 0; | ||
570 | if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE) | ||
571 | return 0; | ||
572 | |||
573 | switch (get_defcfg_device(def_conf)) { | ||
574 | case AC_JACK_LINE_OUT: | ||
575 | return fill_audio_out_name(codec, nid, cfg, "Line Out", | ||
576 | label, maxlen, indexp); | ||
577 | case AC_JACK_SPEAKER: | ||
578 | return fill_audio_out_name(codec, nid, cfg, "Speaker", | ||
579 | label, maxlen, indexp); | ||
580 | case AC_JACK_HP_OUT: | ||
581 | return fill_audio_out_name(codec, nid, cfg, "Headphone", | ||
582 | label, maxlen, indexp); | ||
583 | case AC_JACK_SPDIF_OUT: | ||
584 | case AC_JACK_DIG_OTHER_OUT: | ||
585 | if (get_defcfg_location(def_conf) == AC_JACK_LOC_HDMI) | ||
586 | name = "HDMI"; | ||
587 | else | ||
588 | name = "SPDIF"; | ||
589 | if (cfg && indexp) { | ||
590 | i = find_idx_in_nid_list(nid, cfg->dig_out_pins, | ||
591 | cfg->dig_outs); | ||
592 | if (i >= 0) | ||
593 | *indexp = i; | ||
594 | } | ||
595 | break; | ||
596 | default: | ||
597 | if (cfg) { | ||
598 | for (i = 0; i < cfg->num_inputs; i++) { | ||
599 | if (cfg->inputs[i].pin != nid) | ||
600 | continue; | ||
601 | name = hda_get_autocfg_input_label(codec, cfg, i); | ||
602 | if (name) | ||
603 | break; | ||
604 | } | ||
605 | } | ||
606 | if (!name) | ||
607 | name = hda_get_input_pin_label(codec, nid, true); | ||
608 | break; | ||
609 | } | ||
610 | if (!name) | ||
611 | return 0; | ||
612 | strlcpy(label, name, maxlen); | ||
613 | return 1; | ||
614 | } | ||
615 | EXPORT_SYMBOL_HDA(snd_hda_get_pin_label); | ||
616 | |||
617 | int snd_hda_gen_add_verbs(struct hda_gen_spec *spec, | ||
618 | const struct hda_verb *list) | ||
619 | { | ||
620 | const struct hda_verb **v; | ||
621 | snd_array_init(&spec->verbs, sizeof(struct hda_verb *), 8); | ||
622 | v = snd_array_new(&spec->verbs); | ||
623 | if (!v) | ||
624 | return -ENOMEM; | ||
625 | *v = list; | ||
626 | return 0; | ||
627 | } | ||
628 | EXPORT_SYMBOL_HDA(snd_hda_gen_add_verbs); | ||
629 | |||
630 | void snd_hda_gen_apply_verbs(struct hda_codec *codec) | ||
631 | { | ||
632 | struct hda_gen_spec *spec = codec->spec; | ||
633 | int i; | ||
634 | for (i = 0; i < spec->verbs.used; i++) { | ||
635 | struct hda_verb **v = snd_array_elem(&spec->verbs, i); | ||
636 | snd_hda_sequence_write(codec, *v); | ||
637 | } | ||
638 | } | ||
639 | EXPORT_SYMBOL_HDA(snd_hda_gen_apply_verbs); | ||
640 | |||
641 | void snd_hda_apply_pincfgs(struct hda_codec *codec, | ||
642 | const struct hda_pintbl *cfg) | ||
643 | { | ||
644 | for (; cfg->nid; cfg++) | ||
645 | snd_hda_codec_set_pincfg(codec, cfg->nid, cfg->val); | ||
646 | } | ||
647 | EXPORT_SYMBOL_HDA(snd_hda_apply_pincfgs); | ||
648 | |||
649 | void snd_hda_apply_fixup(struct hda_codec *codec, int action) | ||
650 | { | ||
651 | struct hda_gen_spec *spec = codec->spec; | ||
652 | int id = spec->fixup_id; | ||
653 | #ifdef CONFIG_SND_DEBUG_VERBOSE | ||
654 | const char *modelname = spec->fixup_name; | ||
655 | #endif | ||
656 | int depth = 0; | ||
657 | |||
658 | if (!spec->fixup_list) | ||
659 | return; | ||
660 | |||
661 | while (id >= 0) { | ||
662 | const struct hda_fixup *fix = spec->fixup_list + id; | ||
663 | |||
664 | switch (fix->type) { | ||
665 | case HDA_FIXUP_PINS: | ||
666 | if (action != HDA_FIXUP_ACT_PRE_PROBE || !fix->v.pins) | ||
667 | break; | ||
668 | snd_printdd(KERN_INFO SFX | ||
669 | "%s: Apply pincfg for %s\n", | ||
670 | codec->chip_name, modelname); | ||
671 | snd_hda_apply_pincfgs(codec, fix->v.pins); | ||
672 | break; | ||
673 | case HDA_FIXUP_VERBS: | ||
674 | if (action != HDA_FIXUP_ACT_PROBE || !fix->v.verbs) | ||
675 | break; | ||
676 | snd_printdd(KERN_INFO SFX | ||
677 | "%s: Apply fix-verbs for %s\n", | ||
678 | codec->chip_name, modelname); | ||
679 | snd_hda_gen_add_verbs(codec->spec, fix->v.verbs); | ||
680 | break; | ||
681 | case HDA_FIXUP_FUNC: | ||
682 | if (!fix->v.func) | ||
683 | break; | ||
684 | snd_printdd(KERN_INFO SFX | ||
685 | "%s: Apply fix-func for %s\n", | ||
686 | codec->chip_name, modelname); | ||
687 | fix->v.func(codec, fix, action); | ||
688 | break; | ||
689 | default: | ||
690 | snd_printk(KERN_ERR SFX | ||
691 | "%s: Invalid fixup type %d\n", | ||
692 | codec->chip_name, fix->type); | ||
693 | break; | ||
694 | } | ||
695 | if (!fix->chained) | ||
696 | break; | ||
697 | if (++depth > 10) | ||
698 | break; | ||
699 | id = fix->chain_id; | ||
700 | } | ||
701 | } | ||
702 | EXPORT_SYMBOL_HDA(snd_hda_apply_fixup); | ||
703 | |||
704 | void snd_hda_pick_fixup(struct hda_codec *codec, | ||
705 | const struct hda_model_fixup *models, | ||
706 | const struct snd_pci_quirk *quirk, | ||
707 | const struct hda_fixup *fixlist) | ||
708 | { | ||
709 | struct hda_gen_spec *spec = codec->spec; | ||
710 | const struct snd_pci_quirk *q; | ||
711 | int id = -1; | ||
712 | const char *name = NULL; | ||
713 | |||
714 | /* when model=nofixup is given, don't pick up any fixups */ | ||
715 | if (codec->modelname && !strcmp(codec->modelname, "nofixup")) { | ||
716 | spec->fixup_list = NULL; | ||
717 | spec->fixup_id = -1; | ||
718 | return; | ||
719 | } | ||
720 | |||
721 | if (codec->modelname && models) { | ||
722 | while (models->name) { | ||
723 | if (!strcmp(codec->modelname, models->name)) { | ||
724 | id = models->id; | ||
725 | name = models->name; | ||
726 | break; | ||
727 | } | ||
728 | models++; | ||
729 | } | ||
730 | } | ||
731 | if (id < 0) { | ||
732 | q = snd_pci_quirk_lookup(codec->bus->pci, quirk); | ||
733 | if (q) { | ||
734 | id = q->value; | ||
735 | #ifdef CONFIG_SND_DEBUG_VERBOSE | ||
736 | name = q->name; | ||
737 | #endif | ||
738 | } | ||
739 | } | ||
740 | if (id < 0) { | ||
741 | for (q = quirk; q->subvendor; q++) { | ||
742 | unsigned int vendorid = | ||
743 | q->subdevice | (q->subvendor << 16); | ||
744 | if (vendorid == codec->subsystem_id) { | ||
745 | id = q->value; | ||
746 | #ifdef CONFIG_SND_DEBUG_VERBOSE | ||
747 | name = q->name; | ||
748 | #endif | ||
749 | break; | ||
750 | } | ||
751 | } | ||
752 | } | ||
753 | |||
754 | spec->fixup_id = id; | ||
755 | if (id >= 0) { | ||
756 | spec->fixup_list = fixlist; | ||
757 | spec->fixup_name = name; | ||
758 | } | ||
759 | } | ||
760 | EXPORT_SYMBOL_HDA(snd_hda_pick_fixup); | ||
diff --git a/sound/pci/hda/hda_auto_parser.h b/sound/pci/hda/hda_auto_parser.h new file mode 100644 index 000000000000..2a7889dfbd1b --- /dev/null +++ b/sound/pci/hda/hda_auto_parser.h | |||
@@ -0,0 +1,160 @@ | |||
1 | /* | ||
2 | * BIOS auto-parser helper functions for HD-audio | ||
3 | * | ||
4 | * Copyright (c) 2012 Takashi Iwai <tiwai@suse.de> | ||
5 | * | ||
6 | * This driver is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; either version 2 of the License, or | ||
9 | * (at your option) any later version. | ||
10 | */ | ||
11 | |||
12 | #ifndef __SOUND_HDA_AUTO_PARSER_H | ||
13 | #define __SOUND_HDA_AUTO_PARSER_H | ||
14 | |||
15 | /* | ||
16 | * Helper for automatic pin configuration | ||
17 | */ | ||
18 | |||
19 | enum { | ||
20 | AUTO_PIN_MIC, | ||
21 | AUTO_PIN_LINE_IN, | ||
22 | AUTO_PIN_CD, | ||
23 | AUTO_PIN_AUX, | ||
24 | AUTO_PIN_LAST | ||
25 | }; | ||
26 | |||
27 | enum { | ||
28 | AUTO_PIN_LINE_OUT, | ||
29 | AUTO_PIN_SPEAKER_OUT, | ||
30 | AUTO_PIN_HP_OUT | ||
31 | }; | ||
32 | |||
33 | #define AUTO_CFG_MAX_OUTS HDA_MAX_OUTS | ||
34 | #define AUTO_CFG_MAX_INS 8 | ||
35 | |||
36 | struct auto_pin_cfg_item { | ||
37 | hda_nid_t pin; | ||
38 | int type; | ||
39 | }; | ||
40 | |||
41 | struct auto_pin_cfg; | ||
42 | const char *hda_get_autocfg_input_label(struct hda_codec *codec, | ||
43 | const struct auto_pin_cfg *cfg, | ||
44 | int input); | ||
45 | int snd_hda_get_pin_label(struct hda_codec *codec, hda_nid_t nid, | ||
46 | const struct auto_pin_cfg *cfg, | ||
47 | char *label, int maxlen, int *indexp); | ||
48 | |||
49 | enum { | ||
50 | INPUT_PIN_ATTR_UNUSED, /* pin not connected */ | ||
51 | INPUT_PIN_ATTR_INT, /* internal mic/line-in */ | ||
52 | INPUT_PIN_ATTR_DOCK, /* docking mic/line-in */ | ||
53 | INPUT_PIN_ATTR_NORMAL, /* mic/line-in jack */ | ||
54 | INPUT_PIN_ATTR_FRONT, /* mic/line-in jack in front */ | ||
55 | INPUT_PIN_ATTR_REAR, /* mic/line-in jack in rear */ | ||
56 | }; | ||
57 | |||
58 | int snd_hda_get_input_pin_attr(unsigned int def_conf); | ||
59 | |||
60 | struct auto_pin_cfg { | ||
61 | int line_outs; | ||
62 | /* sorted in the order of Front/Surr/CLFE/Side */ | ||
63 | hda_nid_t line_out_pins[AUTO_CFG_MAX_OUTS]; | ||
64 | int speaker_outs; | ||
65 | hda_nid_t speaker_pins[AUTO_CFG_MAX_OUTS]; | ||
66 | int hp_outs; | ||
67 | int line_out_type; /* AUTO_PIN_XXX_OUT */ | ||
68 | hda_nid_t hp_pins[AUTO_CFG_MAX_OUTS]; | ||
69 | int num_inputs; | ||
70 | struct auto_pin_cfg_item inputs[AUTO_CFG_MAX_INS]; | ||
71 | int dig_outs; | ||
72 | hda_nid_t dig_out_pins[2]; | ||
73 | hda_nid_t dig_in_pin; | ||
74 | hda_nid_t mono_out_pin; | ||
75 | int dig_out_type[2]; /* HDA_PCM_TYPE_XXX */ | ||
76 | int dig_in_type; /* HDA_PCM_TYPE_XXX */ | ||
77 | }; | ||
78 | |||
79 | /* bit-flags for snd_hda_parse_pin_def_config() behavior */ | ||
80 | #define HDA_PINCFG_NO_HP_FIXUP (1 << 0) /* no HP-split */ | ||
81 | #define HDA_PINCFG_NO_LO_FIXUP (1 << 1) /* don't take other outs as LO */ | ||
82 | |||
83 | int snd_hda_parse_pin_defcfg(struct hda_codec *codec, | ||
84 | struct auto_pin_cfg *cfg, | ||
85 | const hda_nid_t *ignore_nids, | ||
86 | unsigned int cond_flags); | ||
87 | |||
88 | /* older function */ | ||
89 | #define snd_hda_parse_pin_def_config(codec, cfg, ignore) \ | ||
90 | snd_hda_parse_pin_defcfg(codec, cfg, ignore, 0) | ||
91 | |||
92 | /* | ||
93 | */ | ||
94 | |||
95 | struct hda_gen_spec { | ||
96 | /* fix-up list */ | ||
97 | int fixup_id; | ||
98 | const struct hda_fixup *fixup_list; | ||
99 | const char *fixup_name; | ||
100 | |||
101 | /* additional init verbs */ | ||
102 | struct snd_array verbs; | ||
103 | }; | ||
104 | |||
105 | |||
106 | /* | ||
107 | * Fix-up pin default configurations and add default verbs | ||
108 | */ | ||
109 | |||
110 | struct hda_pintbl { | ||
111 | hda_nid_t nid; | ||
112 | u32 val; | ||
113 | }; | ||
114 | |||
115 | struct hda_model_fixup { | ||
116 | const int id; | ||
117 | const char *name; | ||
118 | }; | ||
119 | |||
120 | struct hda_fixup { | ||
121 | int type; | ||
122 | bool chained; | ||
123 | int chain_id; | ||
124 | union { | ||
125 | const struct hda_pintbl *pins; | ||
126 | const struct hda_verb *verbs; | ||
127 | void (*func)(struct hda_codec *codec, | ||
128 | const struct hda_fixup *fix, | ||
129 | int action); | ||
130 | } v; | ||
131 | }; | ||
132 | |||
133 | /* fixup types */ | ||
134 | enum { | ||
135 | HDA_FIXUP_INVALID, | ||
136 | HDA_FIXUP_PINS, | ||
137 | HDA_FIXUP_VERBS, | ||
138 | HDA_FIXUP_FUNC, | ||
139 | }; | ||
140 | |||
141 | /* fixup action definitions */ | ||
142 | enum { | ||
143 | HDA_FIXUP_ACT_PRE_PROBE, | ||
144 | HDA_FIXUP_ACT_PROBE, | ||
145 | HDA_FIXUP_ACT_INIT, | ||
146 | HDA_FIXUP_ACT_BUILD, | ||
147 | }; | ||
148 | |||
149 | int snd_hda_gen_add_verbs(struct hda_gen_spec *spec, | ||
150 | const struct hda_verb *list); | ||
151 | void snd_hda_gen_apply_verbs(struct hda_codec *codec); | ||
152 | void snd_hda_apply_pincfgs(struct hda_codec *codec, | ||
153 | const struct hda_pintbl *cfg); | ||
154 | void snd_hda_apply_fixup(struct hda_codec *codec, int action); | ||
155 | void snd_hda_pick_fixup(struct hda_codec *codec, | ||
156 | const struct hda_model_fixup *models, | ||
157 | const struct snd_pci_quirk *quirk, | ||
158 | const struct hda_fixup *fixlist); | ||
159 | |||
160 | #endif /* __SOUND_HDA_AUTO_PARSER_H */ | ||
diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c index 841475cc13b6..eb09a3348325 100644 --- a/sound/pci/hda/hda_codec.c +++ b/sound/pci/hda/hda_codec.c | |||
@@ -334,78 +334,67 @@ static hda_nid_t *lookup_conn_list(struct snd_array *array, hda_nid_t nid) | |||
334 | return NULL; | 334 | return NULL; |
335 | } | 335 | } |
336 | 336 | ||
337 | /* read the connection and add to the cache */ | ||
338 | static int read_and_add_raw_conns(struct hda_codec *codec, hda_nid_t nid) | ||
339 | { | ||
340 | hda_nid_t list[HDA_MAX_CONNECTIONS]; | ||
341 | int len; | ||
342 | |||
343 | len = snd_hda_get_raw_connections(codec, nid, list, ARRAY_SIZE(list)); | ||
344 | if (len < 0) | ||
345 | return len; | ||
346 | return snd_hda_override_conn_list(codec, nid, len, list); | ||
347 | } | ||
348 | |||
337 | /** | 349 | /** |
338 | * snd_hda_get_conn_list - get connection list | 350 | * snd_hda_get_connections - copy connection list |
339 | * @codec: the HDA codec | 351 | * @codec: the HDA codec |
340 | * @nid: NID to parse | 352 | * @nid: NID to parse |
341 | * @listp: the pointer to store NID list | 353 | * @conn_list: connection list array; when NULL, checks only the size |
354 | * @max_conns: max. number of connections to store | ||
342 | * | 355 | * |
343 | * Parses the connection list of the given widget and stores the list | 356 | * Parses the connection list of the given widget and stores the list |
344 | * of NIDs. | 357 | * of NIDs. |
345 | * | 358 | * |
346 | * Returns the number of connections, or a negative error code. | 359 | * Returns the number of connections, or a negative error code. |
347 | */ | 360 | */ |
348 | int snd_hda_get_conn_list(struct hda_codec *codec, hda_nid_t nid, | 361 | int snd_hda_get_connections(struct hda_codec *codec, hda_nid_t nid, |
349 | const hda_nid_t **listp) | 362 | hda_nid_t *conn_list, int max_conns) |
350 | { | 363 | { |
351 | struct snd_array *array = &codec->conn_lists; | 364 | struct snd_array *array = &codec->conn_lists; |
352 | int len, err; | 365 | int len; |
353 | hda_nid_t list[HDA_MAX_CONNECTIONS]; | ||
354 | hda_nid_t *p; | 366 | hda_nid_t *p; |
355 | bool added = false; | 367 | bool added = false; |
356 | 368 | ||
357 | again: | 369 | again: |
370 | mutex_lock(&codec->hash_mutex); | ||
371 | len = -1; | ||
358 | /* if the connection-list is already cached, read it */ | 372 | /* if the connection-list is already cached, read it */ |
359 | p = lookup_conn_list(array, nid); | 373 | p = lookup_conn_list(array, nid); |
360 | if (p) { | 374 | if (p) { |
361 | if (listp) | 375 | len = p[1]; |
362 | *listp = p + 2; | 376 | if (conn_list && len > max_conns) { |
363 | return p[1]; | 377 | snd_printk(KERN_ERR "hda_codec: " |
378 | "Too many connections %d for NID 0x%x\n", | ||
379 | len, nid); | ||
380 | mutex_unlock(&codec->hash_mutex); | ||
381 | return -EINVAL; | ||
382 | } | ||
383 | if (conn_list && len) | ||
384 | memcpy(conn_list, p + 2, len * sizeof(hda_nid_t)); | ||
364 | } | 385 | } |
386 | mutex_unlock(&codec->hash_mutex); | ||
387 | if (len >= 0) | ||
388 | return len; | ||
365 | if (snd_BUG_ON(added)) | 389 | if (snd_BUG_ON(added)) |
366 | return -EINVAL; | 390 | return -EINVAL; |
367 | 391 | ||
368 | /* read the connection and add to the cache */ | 392 | len = read_and_add_raw_conns(codec, nid); |
369 | len = snd_hda_get_raw_connections(codec, nid, list, HDA_MAX_CONNECTIONS); | ||
370 | if (len < 0) | 393 | if (len < 0) |
371 | return len; | 394 | return len; |
372 | err = snd_hda_override_conn_list(codec, nid, len, list); | ||
373 | if (err < 0) | ||
374 | return err; | ||
375 | added = true; | 395 | added = true; |
376 | goto again; | 396 | goto again; |
377 | } | 397 | } |
378 | EXPORT_SYMBOL_HDA(snd_hda_get_conn_list); | ||
379 | |||
380 | /** | ||
381 | * snd_hda_get_connections - copy connection list | ||
382 | * @codec: the HDA codec | ||
383 | * @nid: NID to parse | ||
384 | * @conn_list: connection list array | ||
385 | * @max_conns: max. number of connections to store | ||
386 | * | ||
387 | * Parses the connection list of the given widget and stores the list | ||
388 | * of NIDs. | ||
389 | * | ||
390 | * Returns the number of connections, or a negative error code. | ||
391 | */ | ||
392 | int snd_hda_get_connections(struct hda_codec *codec, hda_nid_t nid, | ||
393 | hda_nid_t *conn_list, int max_conns) | ||
394 | { | ||
395 | const hda_nid_t *list; | ||
396 | int len = snd_hda_get_conn_list(codec, nid, &list); | ||
397 | |||
398 | if (len <= 0) | ||
399 | return len; | ||
400 | if (len > max_conns) { | ||
401 | snd_printk(KERN_ERR "hda_codec: " | ||
402 | "Too many connections %d for NID 0x%x\n", | ||
403 | len, nid); | ||
404 | return -EINVAL; | ||
405 | } | ||
406 | memcpy(conn_list, list, len * sizeof(hda_nid_t)); | ||
407 | return len; | ||
408 | } | ||
409 | EXPORT_SYMBOL_HDA(snd_hda_get_connections); | 398 | EXPORT_SYMBOL_HDA(snd_hda_get_connections); |
410 | 399 | ||
411 | /** | 400 | /** |
@@ -543,6 +532,7 @@ int snd_hda_override_conn_list(struct hda_codec *codec, hda_nid_t nid, int len, | |||
543 | hda_nid_t *p; | 532 | hda_nid_t *p; |
544 | int i, old_used; | 533 | int i, old_used; |
545 | 534 | ||
535 | mutex_lock(&codec->hash_mutex); | ||
546 | p = lookup_conn_list(array, nid); | 536 | p = lookup_conn_list(array, nid); |
547 | if (p) | 537 | if (p) |
548 | *p = -1; /* invalidate the old entry */ | 538 | *p = -1; /* invalidate the old entry */ |
@@ -553,10 +543,12 @@ int snd_hda_override_conn_list(struct hda_codec *codec, hda_nid_t nid, int len, | |||
553 | for (i = 0; i < len; i++) | 543 | for (i = 0; i < len; i++) |
554 | if (!add_conn_list(array, list[i])) | 544 | if (!add_conn_list(array, list[i])) |
555 | goto error_add; | 545 | goto error_add; |
546 | mutex_unlock(&codec->hash_mutex); | ||
556 | return 0; | 547 | return 0; |
557 | 548 | ||
558 | error_add: | 549 | error_add: |
559 | array->used = old_used; | 550 | array->used = old_used; |
551 | mutex_unlock(&codec->hash_mutex); | ||
560 | return -ENOMEM; | 552 | return -ENOMEM; |
561 | } | 553 | } |
562 | EXPORT_SYMBOL_HDA(snd_hda_override_conn_list); | 554 | EXPORT_SYMBOL_HDA(snd_hda_override_conn_list); |
@@ -1255,6 +1247,7 @@ int /*__devinit*/ snd_hda_codec_new(struct hda_bus *bus, | |||
1255 | codec->addr = codec_addr; | 1247 | codec->addr = codec_addr; |
1256 | mutex_init(&codec->spdif_mutex); | 1248 | mutex_init(&codec->spdif_mutex); |
1257 | mutex_init(&codec->control_mutex); | 1249 | mutex_init(&codec->control_mutex); |
1250 | mutex_init(&codec->hash_mutex); | ||
1258 | init_hda_cache(&codec->amp_cache, sizeof(struct hda_amp_info)); | 1251 | init_hda_cache(&codec->amp_cache, sizeof(struct hda_amp_info)); |
1259 | init_hda_cache(&codec->cmd_cache, sizeof(struct hda_cache_head)); | 1252 | init_hda_cache(&codec->cmd_cache, sizeof(struct hda_cache_head)); |
1260 | snd_array_init(&codec->mixers, sizeof(struct hda_nid_item), 32); | 1253 | snd_array_init(&codec->mixers, sizeof(struct hda_nid_item), 32); |
@@ -1264,15 +1257,9 @@ int /*__devinit*/ snd_hda_codec_new(struct hda_bus *bus, | |||
1264 | snd_array_init(&codec->cvt_setups, sizeof(struct hda_cvt_setup), 8); | 1257 | snd_array_init(&codec->cvt_setups, sizeof(struct hda_cvt_setup), 8); |
1265 | snd_array_init(&codec->conn_lists, sizeof(hda_nid_t), 64); | 1258 | snd_array_init(&codec->conn_lists, sizeof(hda_nid_t), 64); |
1266 | snd_array_init(&codec->spdif_out, sizeof(struct hda_spdif_out), 16); | 1259 | snd_array_init(&codec->spdif_out, sizeof(struct hda_spdif_out), 16); |
1267 | if (codec->bus->modelname) { | ||
1268 | codec->modelname = kstrdup(codec->bus->modelname, GFP_KERNEL); | ||
1269 | if (!codec->modelname) { | ||
1270 | snd_hda_codec_free(codec); | ||
1271 | return -ENODEV; | ||
1272 | } | ||
1273 | } | ||
1274 | 1260 | ||
1275 | #ifdef CONFIG_SND_HDA_POWER_SAVE | 1261 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
1262 | spin_lock_init(&codec->power_lock); | ||
1276 | INIT_DELAYED_WORK(&codec->power_work, hda_power_work); | 1263 | INIT_DELAYED_WORK(&codec->power_work, hda_power_work); |
1277 | /* snd_hda_codec_new() marks the codec as power-up, and leave it as is. | 1264 | /* snd_hda_codec_new() marks the codec as power-up, and leave it as is. |
1278 | * the caller has to power down appropriatley after initialization | 1265 | * the caller has to power down appropriatley after initialization |
@@ -1281,6 +1268,14 @@ int /*__devinit*/ snd_hda_codec_new(struct hda_bus *bus, | |||
1281 | hda_keep_power_on(codec); | 1268 | hda_keep_power_on(codec); |
1282 | #endif | 1269 | #endif |
1283 | 1270 | ||
1271 | if (codec->bus->modelname) { | ||
1272 | codec->modelname = kstrdup(codec->bus->modelname, GFP_KERNEL); | ||
1273 | if (!codec->modelname) { | ||
1274 | snd_hda_codec_free(codec); | ||
1275 | return -ENODEV; | ||
1276 | } | ||
1277 | } | ||
1278 | |||
1284 | list_add_tail(&codec->list, &bus->codec_list); | 1279 | list_add_tail(&codec->list, &bus->codec_list); |
1285 | bus->caddr_tbl[codec_addr] = codec; | 1280 | bus->caddr_tbl[codec_addr] = codec; |
1286 | 1281 | ||
@@ -1603,6 +1598,60 @@ get_alloc_amp_hash(struct hda_codec *codec, u32 key) | |||
1603 | return (struct hda_amp_info *)get_alloc_hash(&codec->amp_cache, key); | 1598 | return (struct hda_amp_info *)get_alloc_hash(&codec->amp_cache, key); |
1604 | } | 1599 | } |
1605 | 1600 | ||
1601 | /* overwrite the value with the key in the caps hash */ | ||
1602 | static int write_caps_hash(struct hda_codec *codec, u32 key, unsigned int val) | ||
1603 | { | ||
1604 | struct hda_amp_info *info; | ||
1605 | |||
1606 | mutex_lock(&codec->hash_mutex); | ||
1607 | info = get_alloc_amp_hash(codec, key); | ||
1608 | if (!info) { | ||
1609 | mutex_unlock(&codec->hash_mutex); | ||
1610 | return -EINVAL; | ||
1611 | } | ||
1612 | info->amp_caps = val; | ||
1613 | info->head.val |= INFO_AMP_CAPS; | ||
1614 | mutex_unlock(&codec->hash_mutex); | ||
1615 | return 0; | ||
1616 | } | ||
1617 | |||
1618 | /* query the value from the caps hash; if not found, fetch the current | ||
1619 | * value from the given function and store in the hash | ||
1620 | */ | ||
1621 | static unsigned int | ||
1622 | query_caps_hash(struct hda_codec *codec, hda_nid_t nid, int dir, u32 key, | ||
1623 | unsigned int (*func)(struct hda_codec *, hda_nid_t, int)) | ||
1624 | { | ||
1625 | struct hda_amp_info *info; | ||
1626 | unsigned int val; | ||
1627 | |||
1628 | mutex_lock(&codec->hash_mutex); | ||
1629 | info = get_alloc_amp_hash(codec, key); | ||
1630 | if (!info) { | ||
1631 | mutex_unlock(&codec->hash_mutex); | ||
1632 | return 0; | ||
1633 | } | ||
1634 | if (!(info->head.val & INFO_AMP_CAPS)) { | ||
1635 | mutex_unlock(&codec->hash_mutex); /* for reentrance */ | ||
1636 | val = func(codec, nid, dir); | ||
1637 | write_caps_hash(codec, key, val); | ||
1638 | } else { | ||
1639 | val = info->amp_caps; | ||
1640 | mutex_unlock(&codec->hash_mutex); | ||
1641 | } | ||
1642 | return val; | ||
1643 | } | ||
1644 | |||
1645 | static unsigned int read_amp_cap(struct hda_codec *codec, hda_nid_t nid, | ||
1646 | int direction) | ||
1647 | { | ||
1648 | if (!(get_wcaps(codec, nid) & AC_WCAP_AMP_OVRD)) | ||
1649 | nid = codec->afg; | ||
1650 | return snd_hda_param_read(codec, nid, | ||
1651 | direction == HDA_OUTPUT ? | ||
1652 | AC_PAR_AMP_OUT_CAP : AC_PAR_AMP_IN_CAP); | ||
1653 | } | ||
1654 | |||
1606 | /** | 1655 | /** |
1607 | * query_amp_caps - query AMP capabilities | 1656 | * query_amp_caps - query AMP capabilities |
1608 | * @codec: the HD-auio codec | 1657 | * @codec: the HD-auio codec |
@@ -1617,22 +1666,9 @@ get_alloc_amp_hash(struct hda_codec *codec, u32 key) | |||
1617 | */ | 1666 | */ |
1618 | u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction) | 1667 | u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction) |
1619 | { | 1668 | { |
1620 | struct hda_amp_info *info; | 1669 | return query_caps_hash(codec, nid, direction, |
1621 | 1670 | HDA_HASH_KEY(nid, direction, 0), | |
1622 | info = get_alloc_amp_hash(codec, HDA_HASH_KEY(nid, direction, 0)); | 1671 | read_amp_cap); |
1623 | if (!info) | ||
1624 | return 0; | ||
1625 | if (!(info->head.val & INFO_AMP_CAPS)) { | ||
1626 | if (!(get_wcaps(codec, nid) & AC_WCAP_AMP_OVRD)) | ||
1627 | nid = codec->afg; | ||
1628 | info->amp_caps = snd_hda_param_read(codec, nid, | ||
1629 | direction == HDA_OUTPUT ? | ||
1630 | AC_PAR_AMP_OUT_CAP : | ||
1631 | AC_PAR_AMP_IN_CAP); | ||
1632 | if (info->amp_caps) | ||
1633 | info->head.val |= INFO_AMP_CAPS; | ||
1634 | } | ||
1635 | return info->amp_caps; | ||
1636 | } | 1672 | } |
1637 | EXPORT_SYMBOL_HDA(query_amp_caps); | 1673 | EXPORT_SYMBOL_HDA(query_amp_caps); |
1638 | 1674 | ||
@@ -1652,34 +1688,12 @@ EXPORT_SYMBOL_HDA(query_amp_caps); | |||
1652 | int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir, | 1688 | int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir, |
1653 | unsigned int caps) | 1689 | unsigned int caps) |
1654 | { | 1690 | { |
1655 | struct hda_amp_info *info; | 1691 | return write_caps_hash(codec, HDA_HASH_KEY(nid, dir, 0), caps); |
1656 | |||
1657 | info = get_alloc_amp_hash(codec, HDA_HASH_KEY(nid, dir, 0)); | ||
1658 | if (!info) | ||
1659 | return -EINVAL; | ||
1660 | info->amp_caps = caps; | ||
1661 | info->head.val |= INFO_AMP_CAPS; | ||
1662 | return 0; | ||
1663 | } | 1692 | } |
1664 | EXPORT_SYMBOL_HDA(snd_hda_override_amp_caps); | 1693 | EXPORT_SYMBOL_HDA(snd_hda_override_amp_caps); |
1665 | 1694 | ||
1666 | static unsigned int | 1695 | static unsigned int read_pin_cap(struct hda_codec *codec, hda_nid_t nid, |
1667 | query_caps_hash(struct hda_codec *codec, hda_nid_t nid, u32 key, | 1696 | int dir) |
1668 | unsigned int (*func)(struct hda_codec *, hda_nid_t)) | ||
1669 | { | ||
1670 | struct hda_amp_info *info; | ||
1671 | |||
1672 | info = get_alloc_amp_hash(codec, key); | ||
1673 | if (!info) | ||
1674 | return 0; | ||
1675 | if (!info->head.val) { | ||
1676 | info->head.val |= INFO_AMP_CAPS; | ||
1677 | info->amp_caps = func(codec, nid); | ||
1678 | } | ||
1679 | return info->amp_caps; | ||
1680 | } | ||
1681 | |||
1682 | static unsigned int read_pin_cap(struct hda_codec *codec, hda_nid_t nid) | ||
1683 | { | 1697 | { |
1684 | return snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP); | 1698 | return snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP); |
1685 | } | 1699 | } |
@@ -1697,7 +1711,7 @@ static unsigned int read_pin_cap(struct hda_codec *codec, hda_nid_t nid) | |||
1697 | */ | 1711 | */ |
1698 | u32 snd_hda_query_pin_caps(struct hda_codec *codec, hda_nid_t nid) | 1712 | u32 snd_hda_query_pin_caps(struct hda_codec *codec, hda_nid_t nid) |
1699 | { | 1713 | { |
1700 | return query_caps_hash(codec, nid, HDA_HASH_PINCAP_KEY(nid), | 1714 | return query_caps_hash(codec, nid, 0, HDA_HASH_PINCAP_KEY(nid), |
1701 | read_pin_cap); | 1715 | read_pin_cap); |
1702 | } | 1716 | } |
1703 | EXPORT_SYMBOL_HDA(snd_hda_query_pin_caps); | 1717 | EXPORT_SYMBOL_HDA(snd_hda_query_pin_caps); |
@@ -1715,41 +1729,47 @@ EXPORT_SYMBOL_HDA(snd_hda_query_pin_caps); | |||
1715 | int snd_hda_override_pin_caps(struct hda_codec *codec, hda_nid_t nid, | 1729 | int snd_hda_override_pin_caps(struct hda_codec *codec, hda_nid_t nid, |
1716 | unsigned int caps) | 1730 | unsigned int caps) |
1717 | { | 1731 | { |
1718 | struct hda_amp_info *info; | 1732 | return write_caps_hash(codec, HDA_HASH_PINCAP_KEY(nid), caps); |
1719 | info = get_alloc_amp_hash(codec, HDA_HASH_PINCAP_KEY(nid)); | ||
1720 | if (!info) | ||
1721 | return -ENOMEM; | ||
1722 | info->amp_caps = caps; | ||
1723 | info->head.val |= INFO_AMP_CAPS; | ||
1724 | return 0; | ||
1725 | } | 1733 | } |
1726 | EXPORT_SYMBOL_HDA(snd_hda_override_pin_caps); | 1734 | EXPORT_SYMBOL_HDA(snd_hda_override_pin_caps); |
1727 | 1735 | ||
1728 | /* | 1736 | /* read or sync the hash value with the current value; |
1729 | * read the current volume to info | 1737 | * call within hash_mutex |
1730 | * if the cache exists, read the cache value. | ||
1731 | */ | 1738 | */ |
1732 | static unsigned int get_vol_mute(struct hda_codec *codec, | 1739 | static struct hda_amp_info * |
1733 | struct hda_amp_info *info, hda_nid_t nid, | 1740 | update_amp_hash(struct hda_codec *codec, hda_nid_t nid, int ch, |
1734 | int ch, int direction, int index) | 1741 | int direction, int index) |
1735 | { | 1742 | { |
1736 | u32 val, parm; | 1743 | struct hda_amp_info *info; |
1737 | 1744 | unsigned int parm, val = 0; | |
1738 | if (info->head.val & INFO_AMP_VOL(ch)) | 1745 | bool val_read = false; |
1739 | return info->vol[ch]; | ||
1740 | 1746 | ||
1741 | parm = ch ? AC_AMP_GET_RIGHT : AC_AMP_GET_LEFT; | 1747 | retry: |
1742 | parm |= direction == HDA_OUTPUT ? AC_AMP_GET_OUTPUT : AC_AMP_GET_INPUT; | 1748 | info = get_alloc_amp_hash(codec, HDA_HASH_KEY(nid, direction, index)); |
1743 | parm |= index; | 1749 | if (!info) |
1744 | val = snd_hda_codec_read(codec, nid, 0, | 1750 | return NULL; |
1751 | if (!(info->head.val & INFO_AMP_VOL(ch))) { | ||
1752 | if (!val_read) { | ||
1753 | mutex_unlock(&codec->hash_mutex); | ||
1754 | parm = ch ? AC_AMP_GET_RIGHT : AC_AMP_GET_LEFT; | ||
1755 | parm |= direction == HDA_OUTPUT ? | ||
1756 | AC_AMP_GET_OUTPUT : AC_AMP_GET_INPUT; | ||
1757 | parm |= index; | ||
1758 | val = snd_hda_codec_read(codec, nid, 0, | ||
1745 | AC_VERB_GET_AMP_GAIN_MUTE, parm); | 1759 | AC_VERB_GET_AMP_GAIN_MUTE, parm); |
1746 | info->vol[ch] = val & 0xff; | 1760 | val &= 0xff; |
1747 | info->head.val |= INFO_AMP_VOL(ch); | 1761 | val_read = true; |
1748 | return info->vol[ch]; | 1762 | mutex_lock(&codec->hash_mutex); |
1763 | goto retry; | ||
1764 | } | ||
1765 | info->vol[ch] = val; | ||
1766 | info->head.val |= INFO_AMP_VOL(ch); | ||
1767 | } | ||
1768 | return info; | ||
1749 | } | 1769 | } |
1750 | 1770 | ||
1751 | /* | 1771 | /* |
1752 | * write the current volume in info to the h/w and update the cache | 1772 | * write the current volume in info to the h/w |
1753 | */ | 1773 | */ |
1754 | static void put_vol_mute(struct hda_codec *codec, struct hda_amp_info *info, | 1774 | static void put_vol_mute(struct hda_codec *codec, struct hda_amp_info *info, |
1755 | hda_nid_t nid, int ch, int direction, int index, | 1775 | hda_nid_t nid, int ch, int direction, int index, |
@@ -1766,7 +1786,6 @@ static void put_vol_mute(struct hda_codec *codec, struct hda_amp_info *info, | |||
1766 | else | 1786 | else |
1767 | parm |= val; | 1787 | parm |= val; |
1768 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, parm); | 1788 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, parm); |
1769 | info->vol[ch] = val; | ||
1770 | } | 1789 | } |
1771 | 1790 | ||
1772 | /** | 1791 | /** |
@@ -1783,10 +1802,14 @@ int snd_hda_codec_amp_read(struct hda_codec *codec, hda_nid_t nid, int ch, | |||
1783 | int direction, int index) | 1802 | int direction, int index) |
1784 | { | 1803 | { |
1785 | struct hda_amp_info *info; | 1804 | struct hda_amp_info *info; |
1786 | info = get_alloc_amp_hash(codec, HDA_HASH_KEY(nid, direction, index)); | 1805 | unsigned int val = 0; |
1787 | if (!info) | 1806 | |
1788 | return 0; | 1807 | mutex_lock(&codec->hash_mutex); |
1789 | return get_vol_mute(codec, info, nid, ch, direction, index); | 1808 | info = update_amp_hash(codec, nid, ch, direction, index); |
1809 | if (info) | ||
1810 | val = info->vol[ch]; | ||
1811 | mutex_unlock(&codec->hash_mutex); | ||
1812 | return val; | ||
1790 | } | 1813 | } |
1791 | EXPORT_SYMBOL_HDA(snd_hda_codec_amp_read); | 1814 | EXPORT_SYMBOL_HDA(snd_hda_codec_amp_read); |
1792 | 1815 | ||
@@ -1808,15 +1831,23 @@ int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch, | |||
1808 | { | 1831 | { |
1809 | struct hda_amp_info *info; | 1832 | struct hda_amp_info *info; |
1810 | 1833 | ||
1811 | info = get_alloc_amp_hash(codec, HDA_HASH_KEY(nid, direction, idx)); | ||
1812 | if (!info) | ||
1813 | return 0; | ||
1814 | if (snd_BUG_ON(mask & ~0xff)) | 1834 | if (snd_BUG_ON(mask & ~0xff)) |
1815 | mask &= 0xff; | 1835 | mask &= 0xff; |
1816 | val &= mask; | 1836 | val &= mask; |
1817 | val |= get_vol_mute(codec, info, nid, ch, direction, idx) & ~mask; | 1837 | |
1818 | if (info->vol[ch] == val) | 1838 | mutex_lock(&codec->hash_mutex); |
1839 | info = update_amp_hash(codec, nid, ch, direction, idx); | ||
1840 | if (!info) { | ||
1841 | mutex_unlock(&codec->hash_mutex); | ||
1842 | return 0; | ||
1843 | } | ||
1844 | val |= info->vol[ch] & ~mask; | ||
1845 | if (info->vol[ch] == val) { | ||
1846 | mutex_unlock(&codec->hash_mutex); | ||
1819 | return 0; | 1847 | return 0; |
1848 | } | ||
1849 | info->vol[ch] = val; | ||
1850 | mutex_unlock(&codec->hash_mutex); | ||
1820 | put_vol_mute(codec, info, nid, ch, direction, idx, val); | 1851 | put_vol_mute(codec, info, nid, ch, direction, idx, val); |
1821 | return 1; | 1852 | return 1; |
1822 | } | 1853 | } |
@@ -2263,7 +2294,10 @@ int snd_hda_codec_reset(struct hda_codec *codec) | |||
2263 | /* OK, let it free */ | 2294 | /* OK, let it free */ |
2264 | 2295 | ||
2265 | #ifdef CONFIG_SND_HDA_POWER_SAVE | 2296 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
2266 | cancel_delayed_work(&codec->power_work); | 2297 | cancel_delayed_work_sync(&codec->power_work); |
2298 | codec->power_on = 0; | ||
2299 | codec->power_transition = 0; | ||
2300 | codec->power_jiffies = jiffies; | ||
2267 | flush_workqueue(codec->bus->workq); | 2301 | flush_workqueue(codec->bus->workq); |
2268 | #endif | 2302 | #endif |
2269 | snd_hda_ctls_clear(codec); | 2303 | snd_hda_ctls_clear(codec); |
@@ -2859,12 +2893,15 @@ static int snd_hda_spdif_default_get(struct snd_kcontrol *kcontrol, | |||
2859 | { | 2893 | { |
2860 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | 2894 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
2861 | int idx = kcontrol->private_value; | 2895 | int idx = kcontrol->private_value; |
2862 | struct hda_spdif_out *spdif = snd_array_elem(&codec->spdif_out, idx); | 2896 | struct hda_spdif_out *spdif; |
2863 | 2897 | ||
2898 | mutex_lock(&codec->spdif_mutex); | ||
2899 | spdif = snd_array_elem(&codec->spdif_out, idx); | ||
2864 | ucontrol->value.iec958.status[0] = spdif->status & 0xff; | 2900 | ucontrol->value.iec958.status[0] = spdif->status & 0xff; |
2865 | ucontrol->value.iec958.status[1] = (spdif->status >> 8) & 0xff; | 2901 | ucontrol->value.iec958.status[1] = (spdif->status >> 8) & 0xff; |
2866 | ucontrol->value.iec958.status[2] = (spdif->status >> 16) & 0xff; | 2902 | ucontrol->value.iec958.status[2] = (spdif->status >> 16) & 0xff; |
2867 | ucontrol->value.iec958.status[3] = (spdif->status >> 24) & 0xff; | 2903 | ucontrol->value.iec958.status[3] = (spdif->status >> 24) & 0xff; |
2904 | mutex_unlock(&codec->spdif_mutex); | ||
2868 | 2905 | ||
2869 | return 0; | 2906 | return 0; |
2870 | } | 2907 | } |
@@ -2950,12 +2987,14 @@ static int snd_hda_spdif_default_put(struct snd_kcontrol *kcontrol, | |||
2950 | { | 2987 | { |
2951 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | 2988 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
2952 | int idx = kcontrol->private_value; | 2989 | int idx = kcontrol->private_value; |
2953 | struct hda_spdif_out *spdif = snd_array_elem(&codec->spdif_out, idx); | 2990 | struct hda_spdif_out *spdif; |
2954 | hda_nid_t nid = spdif->nid; | 2991 | hda_nid_t nid; |
2955 | unsigned short val; | 2992 | unsigned short val; |
2956 | int change; | 2993 | int change; |
2957 | 2994 | ||
2958 | mutex_lock(&codec->spdif_mutex); | 2995 | mutex_lock(&codec->spdif_mutex); |
2996 | spdif = snd_array_elem(&codec->spdif_out, idx); | ||
2997 | nid = spdif->nid; | ||
2959 | spdif->status = ucontrol->value.iec958.status[0] | | 2998 | spdif->status = ucontrol->value.iec958.status[0] | |
2960 | ((unsigned int)ucontrol->value.iec958.status[1] << 8) | | 2999 | ((unsigned int)ucontrol->value.iec958.status[1] << 8) | |
2961 | ((unsigned int)ucontrol->value.iec958.status[2] << 16) | | 3000 | ((unsigned int)ucontrol->value.iec958.status[2] << 16) | |
@@ -2977,9 +3016,12 @@ static int snd_hda_spdif_out_switch_get(struct snd_kcontrol *kcontrol, | |||
2977 | { | 3016 | { |
2978 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | 3017 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
2979 | int idx = kcontrol->private_value; | 3018 | int idx = kcontrol->private_value; |
2980 | struct hda_spdif_out *spdif = snd_array_elem(&codec->spdif_out, idx); | 3019 | struct hda_spdif_out *spdif; |
2981 | 3020 | ||
3021 | mutex_lock(&codec->spdif_mutex); | ||
3022 | spdif = snd_array_elem(&codec->spdif_out, idx); | ||
2982 | ucontrol->value.integer.value[0] = spdif->ctls & AC_DIG1_ENABLE; | 3023 | ucontrol->value.integer.value[0] = spdif->ctls & AC_DIG1_ENABLE; |
3024 | mutex_unlock(&codec->spdif_mutex); | ||
2983 | return 0; | 3025 | return 0; |
2984 | } | 3026 | } |
2985 | 3027 | ||
@@ -2999,12 +3041,14 @@ static int snd_hda_spdif_out_switch_put(struct snd_kcontrol *kcontrol, | |||
2999 | { | 3041 | { |
3000 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | 3042 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
3001 | int idx = kcontrol->private_value; | 3043 | int idx = kcontrol->private_value; |
3002 | struct hda_spdif_out *spdif = snd_array_elem(&codec->spdif_out, idx); | 3044 | struct hda_spdif_out *spdif; |
3003 | hda_nid_t nid = spdif->nid; | 3045 | hda_nid_t nid; |
3004 | unsigned short val; | 3046 | unsigned short val; |
3005 | int change; | 3047 | int change; |
3006 | 3048 | ||
3007 | mutex_lock(&codec->spdif_mutex); | 3049 | mutex_lock(&codec->spdif_mutex); |
3050 | spdif = snd_array_elem(&codec->spdif_out, idx); | ||
3051 | nid = spdif->nid; | ||
3008 | val = spdif->ctls & ~AC_DIG1_ENABLE; | 3052 | val = spdif->ctls & ~AC_DIG1_ENABLE; |
3009 | if (ucontrol->value.integer.value[0]) | 3053 | if (ucontrol->value.integer.value[0]) |
3010 | val |= AC_DIG1_ENABLE; | 3054 | val |= AC_DIG1_ENABLE; |
@@ -3092,6 +3136,9 @@ int snd_hda_create_spdif_out_ctls(struct hda_codec *codec, | |||
3092 | } | 3136 | } |
3093 | EXPORT_SYMBOL_HDA(snd_hda_create_spdif_out_ctls); | 3137 | EXPORT_SYMBOL_HDA(snd_hda_create_spdif_out_ctls); |
3094 | 3138 | ||
3139 | /* get the hda_spdif_out entry from the given NID | ||
3140 | * call within spdif_mutex lock | ||
3141 | */ | ||
3095 | struct hda_spdif_out *snd_hda_spdif_out_of_nid(struct hda_codec *codec, | 3142 | struct hda_spdif_out *snd_hda_spdif_out_of_nid(struct hda_codec *codec, |
3096 | hda_nid_t nid) | 3143 | hda_nid_t nid) |
3097 | { | 3144 | { |
@@ -3108,9 +3155,10 @@ EXPORT_SYMBOL_HDA(snd_hda_spdif_out_of_nid); | |||
3108 | 3155 | ||
3109 | void snd_hda_spdif_ctls_unassign(struct hda_codec *codec, int idx) | 3156 | void snd_hda_spdif_ctls_unassign(struct hda_codec *codec, int idx) |
3110 | { | 3157 | { |
3111 | struct hda_spdif_out *spdif = snd_array_elem(&codec->spdif_out, idx); | 3158 | struct hda_spdif_out *spdif; |
3112 | 3159 | ||
3113 | mutex_lock(&codec->spdif_mutex); | 3160 | mutex_lock(&codec->spdif_mutex); |
3161 | spdif = snd_array_elem(&codec->spdif_out, idx); | ||
3114 | spdif->nid = (u16)-1; | 3162 | spdif->nid = (u16)-1; |
3115 | mutex_unlock(&codec->spdif_mutex); | 3163 | mutex_unlock(&codec->spdif_mutex); |
3116 | } | 3164 | } |
@@ -3118,10 +3166,11 @@ EXPORT_SYMBOL_HDA(snd_hda_spdif_ctls_unassign); | |||
3118 | 3166 | ||
3119 | void snd_hda_spdif_ctls_assign(struct hda_codec *codec, int idx, hda_nid_t nid) | 3167 | void snd_hda_spdif_ctls_assign(struct hda_codec *codec, int idx, hda_nid_t nid) |
3120 | { | 3168 | { |
3121 | struct hda_spdif_out *spdif = snd_array_elem(&codec->spdif_out, idx); | 3169 | struct hda_spdif_out *spdif; |
3122 | unsigned short val; | 3170 | unsigned short val; |
3123 | 3171 | ||
3124 | mutex_lock(&codec->spdif_mutex); | 3172 | mutex_lock(&codec->spdif_mutex); |
3173 | spdif = snd_array_elem(&codec->spdif_out, idx); | ||
3125 | if (spdif->nid != nid) { | 3174 | if (spdif->nid != nid) { |
3126 | spdif->nid = nid; | 3175 | spdif->nid = nid; |
3127 | val = spdif->ctls; | 3176 | val = spdif->ctls; |
@@ -3486,11 +3535,14 @@ static void hda_call_codec_suspend(struct hda_codec *codec) | |||
3486 | codec->afg ? codec->afg : codec->mfg, | 3535 | codec->afg ? codec->afg : codec->mfg, |
3487 | AC_PWRST_D3); | 3536 | AC_PWRST_D3); |
3488 | #ifdef CONFIG_SND_HDA_POWER_SAVE | 3537 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
3489 | snd_hda_update_power_acct(codec); | ||
3490 | cancel_delayed_work(&codec->power_work); | 3538 | cancel_delayed_work(&codec->power_work); |
3539 | spin_lock(&codec->power_lock); | ||
3540 | snd_hda_update_power_acct(codec); | ||
3541 | trace_hda_power_down(codec); | ||
3491 | codec->power_on = 0; | 3542 | codec->power_on = 0; |
3492 | codec->power_transition = 0; | 3543 | codec->power_transition = 0; |
3493 | codec->power_jiffies = jiffies; | 3544 | codec->power_jiffies = jiffies; |
3545 | spin_unlock(&codec->power_lock); | ||
3494 | #endif | 3546 | #endif |
3495 | } | 3547 | } |
3496 | 3548 | ||
@@ -3499,6 +3551,10 @@ static void hda_call_codec_suspend(struct hda_codec *codec) | |||
3499 | */ | 3551 | */ |
3500 | static void hda_call_codec_resume(struct hda_codec *codec) | 3552 | static void hda_call_codec_resume(struct hda_codec *codec) |
3501 | { | 3553 | { |
3554 | /* set as if powered on for avoiding re-entering the resume | ||
3555 | * in the resume / power-save sequence | ||
3556 | */ | ||
3557 | hda_keep_power_on(codec); | ||
3502 | hda_set_power_state(codec, | 3558 | hda_set_power_state(codec, |
3503 | codec->afg ? codec->afg : codec->mfg, | 3559 | codec->afg ? codec->afg : codec->mfg, |
3504 | AC_PWRST_D0); | 3560 | AC_PWRST_D0); |
@@ -3514,6 +3570,7 @@ static void hda_call_codec_resume(struct hda_codec *codec) | |||
3514 | snd_hda_codec_resume_amp(codec); | 3570 | snd_hda_codec_resume_amp(codec); |
3515 | snd_hda_codec_resume_cache(codec); | 3571 | snd_hda_codec_resume_cache(codec); |
3516 | } | 3572 | } |
3573 | snd_hda_power_down(codec); /* flag down before returning */ | ||
3517 | } | 3574 | } |
3518 | #endif /* CONFIG_PM */ | 3575 | #endif /* CONFIG_PM */ |
3519 | 3576 | ||
@@ -3665,7 +3722,8 @@ unsigned int snd_hda_calc_stream_format(unsigned int rate, | |||
3665 | } | 3722 | } |
3666 | EXPORT_SYMBOL_HDA(snd_hda_calc_stream_format); | 3723 | EXPORT_SYMBOL_HDA(snd_hda_calc_stream_format); |
3667 | 3724 | ||
3668 | static unsigned int get_pcm_param(struct hda_codec *codec, hda_nid_t nid) | 3725 | static unsigned int get_pcm_param(struct hda_codec *codec, hda_nid_t nid, |
3726 | int dir) | ||
3669 | { | 3727 | { |
3670 | unsigned int val = 0; | 3728 | unsigned int val = 0; |
3671 | if (nid != codec->afg && | 3729 | if (nid != codec->afg && |
@@ -3680,11 +3738,12 @@ static unsigned int get_pcm_param(struct hda_codec *codec, hda_nid_t nid) | |||
3680 | 3738 | ||
3681 | static unsigned int query_pcm_param(struct hda_codec *codec, hda_nid_t nid) | 3739 | static unsigned int query_pcm_param(struct hda_codec *codec, hda_nid_t nid) |
3682 | { | 3740 | { |
3683 | return query_caps_hash(codec, nid, HDA_HASH_PARPCM_KEY(nid), | 3741 | return query_caps_hash(codec, nid, 0, HDA_HASH_PARPCM_KEY(nid), |
3684 | get_pcm_param); | 3742 | get_pcm_param); |
3685 | } | 3743 | } |
3686 | 3744 | ||
3687 | static unsigned int get_stream_param(struct hda_codec *codec, hda_nid_t nid) | 3745 | static unsigned int get_stream_param(struct hda_codec *codec, hda_nid_t nid, |
3746 | int dir) | ||
3688 | { | 3747 | { |
3689 | unsigned int streams = snd_hda_param_read(codec, nid, AC_PAR_STREAM); | 3748 | unsigned int streams = snd_hda_param_read(codec, nid, AC_PAR_STREAM); |
3690 | if (!streams || streams == -1) | 3749 | if (!streams || streams == -1) |
@@ -3696,7 +3755,7 @@ static unsigned int get_stream_param(struct hda_codec *codec, hda_nid_t nid) | |||
3696 | 3755 | ||
3697 | static unsigned int query_stream_param(struct hda_codec *codec, hda_nid_t nid) | 3756 | static unsigned int query_stream_param(struct hda_codec *codec, hda_nid_t nid) |
3698 | { | 3757 | { |
3699 | return query_caps_hash(codec, nid, HDA_HASH_PARSTR_KEY(nid), | 3758 | return query_caps_hash(codec, nid, 0, HDA_HASH_PARSTR_KEY(nid), |
3700 | get_stream_param); | 3759 | get_stream_param); |
3701 | } | 3760 | } |
3702 | 3761 | ||
@@ -3775,11 +3834,13 @@ int snd_hda_query_supported_pcm(struct hda_codec *codec, hda_nid_t nid, | |||
3775 | bps = 20; | 3834 | bps = 20; |
3776 | } | 3835 | } |
3777 | } | 3836 | } |
3837 | #if 0 /* FIXME: CS4206 doesn't work, which is the only codec supporting float */ | ||
3778 | if (streams & AC_SUPFMT_FLOAT32) { | 3838 | if (streams & AC_SUPFMT_FLOAT32) { |
3779 | formats |= SNDRV_PCM_FMTBIT_FLOAT_LE; | 3839 | formats |= SNDRV_PCM_FMTBIT_FLOAT_LE; |
3780 | if (!bps) | 3840 | if (!bps) |
3781 | bps = 32; | 3841 | bps = 32; |
3782 | } | 3842 | } |
3843 | #endif | ||
3783 | if (streams == AC_SUPFMT_AC3) { | 3844 | if (streams == AC_SUPFMT_AC3) { |
3784 | /* should be exclusive */ | 3845 | /* should be exclusive */ |
3785 | /* temporary hack: we have still no proper support | 3846 | /* temporary hack: we have still no proper support |
@@ -4283,12 +4344,18 @@ static void hda_power_work(struct work_struct *work) | |||
4283 | container_of(work, struct hda_codec, power_work.work); | 4344 | container_of(work, struct hda_codec, power_work.work); |
4284 | struct hda_bus *bus = codec->bus; | 4345 | struct hda_bus *bus = codec->bus; |
4285 | 4346 | ||
4347 | spin_lock(&codec->power_lock); | ||
4348 | if (codec->power_transition > 0) { /* during power-up sequence? */ | ||
4349 | spin_unlock(&codec->power_lock); | ||
4350 | return; | ||
4351 | } | ||
4286 | if (!codec->power_on || codec->power_count) { | 4352 | if (!codec->power_on || codec->power_count) { |
4287 | codec->power_transition = 0; | 4353 | codec->power_transition = 0; |
4354 | spin_unlock(&codec->power_lock); | ||
4288 | return; | 4355 | return; |
4289 | } | 4356 | } |
4357 | spin_unlock(&codec->power_lock); | ||
4290 | 4358 | ||
4291 | trace_hda_power_down(codec); | ||
4292 | hda_call_codec_suspend(codec); | 4359 | hda_call_codec_suspend(codec); |
4293 | if (bus->ops.pm_notify) | 4360 | if (bus->ops.pm_notify) |
4294 | bus->ops.pm_notify(bus); | 4361 | bus->ops.pm_notify(bus); |
@@ -4296,9 +4363,11 @@ static void hda_power_work(struct work_struct *work) | |||
4296 | 4363 | ||
4297 | static void hda_keep_power_on(struct hda_codec *codec) | 4364 | static void hda_keep_power_on(struct hda_codec *codec) |
4298 | { | 4365 | { |
4366 | spin_lock(&codec->power_lock); | ||
4299 | codec->power_count++; | 4367 | codec->power_count++; |
4300 | codec->power_on = 1; | 4368 | codec->power_on = 1; |
4301 | codec->power_jiffies = jiffies; | 4369 | codec->power_jiffies = jiffies; |
4370 | spin_unlock(&codec->power_lock); | ||
4302 | } | 4371 | } |
4303 | 4372 | ||
4304 | /* update the power on/off account with the current jiffies */ | 4373 | /* update the power on/off account with the current jiffies */ |
@@ -4323,19 +4392,31 @@ void snd_hda_power_up(struct hda_codec *codec) | |||
4323 | { | 4392 | { |
4324 | struct hda_bus *bus = codec->bus; | 4393 | struct hda_bus *bus = codec->bus; |
4325 | 4394 | ||
4395 | spin_lock(&codec->power_lock); | ||
4326 | codec->power_count++; | 4396 | codec->power_count++; |
4327 | if (codec->power_on || codec->power_transition) | 4397 | if (codec->power_on || codec->power_transition > 0) { |
4398 | spin_unlock(&codec->power_lock); | ||
4328 | return; | 4399 | return; |
4400 | } | ||
4401 | spin_unlock(&codec->power_lock); | ||
4329 | 4402 | ||
4403 | cancel_delayed_work_sync(&codec->power_work); | ||
4404 | |||
4405 | spin_lock(&codec->power_lock); | ||
4330 | trace_hda_power_up(codec); | 4406 | trace_hda_power_up(codec); |
4331 | snd_hda_update_power_acct(codec); | 4407 | snd_hda_update_power_acct(codec); |
4332 | codec->power_on = 1; | 4408 | codec->power_on = 1; |
4333 | codec->power_jiffies = jiffies; | 4409 | codec->power_jiffies = jiffies; |
4410 | codec->power_transition = 1; /* avoid reentrance */ | ||
4411 | spin_unlock(&codec->power_lock); | ||
4412 | |||
4334 | if (bus->ops.pm_notify) | 4413 | if (bus->ops.pm_notify) |
4335 | bus->ops.pm_notify(bus); | 4414 | bus->ops.pm_notify(bus); |
4336 | hda_call_codec_resume(codec); | 4415 | hda_call_codec_resume(codec); |
4337 | cancel_delayed_work(&codec->power_work); | 4416 | |
4417 | spin_lock(&codec->power_lock); | ||
4338 | codec->power_transition = 0; | 4418 | codec->power_transition = 0; |
4419 | spin_unlock(&codec->power_lock); | ||
4339 | } | 4420 | } |
4340 | EXPORT_SYMBOL_HDA(snd_hda_power_up); | 4421 | EXPORT_SYMBOL_HDA(snd_hda_power_up); |
4341 | 4422 | ||
@@ -4351,14 +4432,18 @@ EXPORT_SYMBOL_HDA(snd_hda_power_up); | |||
4351 | */ | 4432 | */ |
4352 | void snd_hda_power_down(struct hda_codec *codec) | 4433 | void snd_hda_power_down(struct hda_codec *codec) |
4353 | { | 4434 | { |
4435 | spin_lock(&codec->power_lock); | ||
4354 | --codec->power_count; | 4436 | --codec->power_count; |
4355 | if (!codec->power_on || codec->power_count || codec->power_transition) | 4437 | if (!codec->power_on || codec->power_count || codec->power_transition) { |
4438 | spin_unlock(&codec->power_lock); | ||
4356 | return; | 4439 | return; |
4440 | } | ||
4357 | if (power_save(codec)) { | 4441 | if (power_save(codec)) { |
4358 | codec->power_transition = 1; /* avoid reentrance */ | 4442 | codec->power_transition = -1; /* avoid reentrance */ |
4359 | queue_delayed_work(codec->bus->workq, &codec->power_work, | 4443 | queue_delayed_work(codec->bus->workq, &codec->power_work, |
4360 | msecs_to_jiffies(power_save(codec) * 1000)); | 4444 | msecs_to_jiffies(power_save(codec) * 1000)); |
4361 | } | 4445 | } |
4446 | spin_unlock(&codec->power_lock); | ||
4362 | } | 4447 | } |
4363 | EXPORT_SYMBOL_HDA(snd_hda_power_down); | 4448 | EXPORT_SYMBOL_HDA(snd_hda_power_down); |
4364 | 4449 | ||
@@ -4710,11 +4795,11 @@ int snd_hda_multi_out_analog_prepare(struct hda_codec *codec, | |||
4710 | { | 4795 | { |
4711 | const hda_nid_t *nids = mout->dac_nids; | 4796 | const hda_nid_t *nids = mout->dac_nids; |
4712 | int chs = substream->runtime->channels; | 4797 | int chs = substream->runtime->channels; |
4713 | struct hda_spdif_out *spdif = | 4798 | struct hda_spdif_out *spdif; |
4714 | snd_hda_spdif_out_of_nid(codec, mout->dig_out_nid); | ||
4715 | int i; | 4799 | int i; |
4716 | 4800 | ||
4717 | mutex_lock(&codec->spdif_mutex); | 4801 | mutex_lock(&codec->spdif_mutex); |
4802 | spdif = snd_hda_spdif_out_of_nid(codec, mout->dig_out_nid); | ||
4718 | if (mout->dig_out_nid && mout->share_spdif && | 4803 | if (mout->dig_out_nid && mout->share_spdif && |
4719 | mout->dig_out_used != HDA_DIG_EXCLUSIVE) { | 4804 | mout->dig_out_used != HDA_DIG_EXCLUSIVE) { |
4720 | if (chs == 2 && | 4805 | if (chs == 2 && |
@@ -4795,601 +4880,58 @@ int snd_hda_multi_out_analog_cleanup(struct hda_codec *codec, | |||
4795 | } | 4880 | } |
4796 | EXPORT_SYMBOL_HDA(snd_hda_multi_out_analog_cleanup); | 4881 | EXPORT_SYMBOL_HDA(snd_hda_multi_out_analog_cleanup); |
4797 | 4882 | ||
4798 | /* | ||
4799 | * Helper for automatic pin configuration | ||
4800 | */ | ||
4801 | |||
4802 | static int is_in_nid_list(hda_nid_t nid, const hda_nid_t *list) | ||
4803 | { | ||
4804 | for (; *list; list++) | ||
4805 | if (*list == nid) | ||
4806 | return 1; | ||
4807 | return 0; | ||
4808 | } | ||
4809 | |||
4810 | |||
4811 | /* | ||
4812 | * Sort an associated group of pins according to their sequence numbers. | ||
4813 | */ | ||
4814 | static void sort_pins_by_sequence(hda_nid_t *pins, short *sequences, | ||
4815 | int num_pins) | ||
4816 | { | ||
4817 | int i, j; | ||
4818 | short seq; | ||
4819 | hda_nid_t nid; | ||
4820 | |||
4821 | for (i = 0; i < num_pins; i++) { | ||
4822 | for (j = i + 1; j < num_pins; j++) { | ||
4823 | if (sequences[i] > sequences[j]) { | ||
4824 | seq = sequences[i]; | ||
4825 | sequences[i] = sequences[j]; | ||
4826 | sequences[j] = seq; | ||
4827 | nid = pins[i]; | ||
4828 | pins[i] = pins[j]; | ||
4829 | pins[j] = nid; | ||
4830 | } | ||
4831 | } | ||
4832 | } | ||
4833 | } | ||
4834 | |||
4835 | |||
4836 | /* add the found input-pin to the cfg->inputs[] table */ | ||
4837 | static void add_auto_cfg_input_pin(struct auto_pin_cfg *cfg, hda_nid_t nid, | ||
4838 | int type) | ||
4839 | { | ||
4840 | if (cfg->num_inputs < AUTO_CFG_MAX_INS) { | ||
4841 | cfg->inputs[cfg->num_inputs].pin = nid; | ||
4842 | cfg->inputs[cfg->num_inputs].type = type; | ||
4843 | cfg->num_inputs++; | ||
4844 | } | ||
4845 | } | ||
4846 | |||
4847 | /* sort inputs in the order of AUTO_PIN_* type */ | ||
4848 | static void sort_autocfg_input_pins(struct auto_pin_cfg *cfg) | ||
4849 | { | ||
4850 | int i, j; | ||
4851 | |||
4852 | for (i = 0; i < cfg->num_inputs; i++) { | ||
4853 | for (j = i + 1; j < cfg->num_inputs; j++) { | ||
4854 | if (cfg->inputs[i].type > cfg->inputs[j].type) { | ||
4855 | struct auto_pin_cfg_item tmp; | ||
4856 | tmp = cfg->inputs[i]; | ||
4857 | cfg->inputs[i] = cfg->inputs[j]; | ||
4858 | cfg->inputs[j] = tmp; | ||
4859 | } | ||
4860 | } | ||
4861 | } | ||
4862 | } | ||
4863 | |||
4864 | /* Reorder the surround channels | ||
4865 | * ALSA sequence is front/surr/clfe/side | ||
4866 | * HDA sequence is: | ||
4867 | * 4-ch: front/surr => OK as it is | ||
4868 | * 6-ch: front/clfe/surr | ||
4869 | * 8-ch: front/clfe/rear/side|fc | ||
4870 | */ | ||
4871 | static void reorder_outputs(unsigned int nums, hda_nid_t *pins) | ||
4872 | { | ||
4873 | hda_nid_t nid; | ||
4874 | |||
4875 | switch (nums) { | ||
4876 | case 3: | ||
4877 | case 4: | ||
4878 | nid = pins[1]; | ||
4879 | pins[1] = pins[2]; | ||
4880 | pins[2] = nid; | ||
4881 | break; | ||
4882 | } | ||
4883 | } | ||
4884 | |||
4885 | /* | ||
4886 | * Parse all pin widgets and store the useful pin nids to cfg | ||
4887 | * | ||
4888 | * The number of line-outs or any primary output is stored in line_outs, | ||
4889 | * and the corresponding output pins are assigned to line_out_pins[], | ||
4890 | * in the order of front, rear, CLFE, side, ... | ||
4891 | * | ||
4892 | * If more extra outputs (speaker and headphone) are found, the pins are | ||
4893 | * assisnged to hp_pins[] and speaker_pins[], respectively. If no line-out jack | ||
4894 | * is detected, one of speaker of HP pins is assigned as the primary | ||
4895 | * output, i.e. to line_out_pins[0]. So, line_outs is always positive | ||
4896 | * if any analog output exists. | ||
4897 | * | ||
4898 | * The analog input pins are assigned to inputs array. | ||
4899 | * The digital input/output pins are assigned to dig_in_pin and dig_out_pin, | ||
4900 | * respectively. | ||
4901 | */ | ||
4902 | int snd_hda_parse_pin_defcfg(struct hda_codec *codec, | ||
4903 | struct auto_pin_cfg *cfg, | ||
4904 | const hda_nid_t *ignore_nids, | ||
4905 | unsigned int cond_flags) | ||
4906 | { | ||
4907 | hda_nid_t nid, end_nid; | ||
4908 | short seq, assoc_line_out; | ||
4909 | short sequences_line_out[ARRAY_SIZE(cfg->line_out_pins)]; | ||
4910 | short sequences_speaker[ARRAY_SIZE(cfg->speaker_pins)]; | ||
4911 | short sequences_hp[ARRAY_SIZE(cfg->hp_pins)]; | ||
4912 | int i; | ||
4913 | |||
4914 | memset(cfg, 0, sizeof(*cfg)); | ||
4915 | |||
4916 | memset(sequences_line_out, 0, sizeof(sequences_line_out)); | ||
4917 | memset(sequences_speaker, 0, sizeof(sequences_speaker)); | ||
4918 | memset(sequences_hp, 0, sizeof(sequences_hp)); | ||
4919 | assoc_line_out = 0; | ||
4920 | |||
4921 | codec->ignore_misc_bit = true; | ||
4922 | end_nid = codec->start_nid + codec->num_nodes; | ||
4923 | for (nid = codec->start_nid; nid < end_nid; nid++) { | ||
4924 | unsigned int wid_caps = get_wcaps(codec, nid); | ||
4925 | unsigned int wid_type = get_wcaps_type(wid_caps); | ||
4926 | unsigned int def_conf; | ||
4927 | short assoc, loc, conn, dev; | ||
4928 | |||
4929 | /* read all default configuration for pin complex */ | ||
4930 | if (wid_type != AC_WID_PIN) | ||
4931 | continue; | ||
4932 | /* ignore the given nids (e.g. pc-beep returns error) */ | ||
4933 | if (ignore_nids && is_in_nid_list(nid, ignore_nids)) | ||
4934 | continue; | ||
4935 | |||
4936 | def_conf = snd_hda_codec_get_pincfg(codec, nid); | ||
4937 | if (!(get_defcfg_misc(snd_hda_codec_get_pincfg(codec, nid)) & | ||
4938 | AC_DEFCFG_MISC_NO_PRESENCE)) | ||
4939 | codec->ignore_misc_bit = false; | ||
4940 | conn = get_defcfg_connect(def_conf); | ||
4941 | if (conn == AC_JACK_PORT_NONE) | ||
4942 | continue; | ||
4943 | loc = get_defcfg_location(def_conf); | ||
4944 | dev = get_defcfg_device(def_conf); | ||
4945 | |||
4946 | /* workaround for buggy BIOS setups */ | ||
4947 | if (dev == AC_JACK_LINE_OUT) { | ||
4948 | if (conn == AC_JACK_PORT_FIXED) | ||
4949 | dev = AC_JACK_SPEAKER; | ||
4950 | } | ||
4951 | |||
4952 | switch (dev) { | ||
4953 | case AC_JACK_LINE_OUT: | ||
4954 | seq = get_defcfg_sequence(def_conf); | ||
4955 | assoc = get_defcfg_association(def_conf); | ||
4956 | |||
4957 | if (!(wid_caps & AC_WCAP_STEREO)) | ||
4958 | if (!cfg->mono_out_pin) | ||
4959 | cfg->mono_out_pin = nid; | ||
4960 | if (!assoc) | ||
4961 | continue; | ||
4962 | if (!assoc_line_out) | ||
4963 | assoc_line_out = assoc; | ||
4964 | else if (assoc_line_out != assoc) | ||
4965 | continue; | ||
4966 | if (cfg->line_outs >= ARRAY_SIZE(cfg->line_out_pins)) | ||
4967 | continue; | ||
4968 | cfg->line_out_pins[cfg->line_outs] = nid; | ||
4969 | sequences_line_out[cfg->line_outs] = seq; | ||
4970 | cfg->line_outs++; | ||
4971 | break; | ||
4972 | case AC_JACK_SPEAKER: | ||
4973 | seq = get_defcfg_sequence(def_conf); | ||
4974 | assoc = get_defcfg_association(def_conf); | ||
4975 | if (cfg->speaker_outs >= ARRAY_SIZE(cfg->speaker_pins)) | ||
4976 | continue; | ||
4977 | cfg->speaker_pins[cfg->speaker_outs] = nid; | ||
4978 | sequences_speaker[cfg->speaker_outs] = (assoc << 4) | seq; | ||
4979 | cfg->speaker_outs++; | ||
4980 | break; | ||
4981 | case AC_JACK_HP_OUT: | ||
4982 | seq = get_defcfg_sequence(def_conf); | ||
4983 | assoc = get_defcfg_association(def_conf); | ||
4984 | if (cfg->hp_outs >= ARRAY_SIZE(cfg->hp_pins)) | ||
4985 | continue; | ||
4986 | cfg->hp_pins[cfg->hp_outs] = nid; | ||
4987 | sequences_hp[cfg->hp_outs] = (assoc << 4) | seq; | ||
4988 | cfg->hp_outs++; | ||
4989 | break; | ||
4990 | case AC_JACK_MIC_IN: | ||
4991 | add_auto_cfg_input_pin(cfg, nid, AUTO_PIN_MIC); | ||
4992 | break; | ||
4993 | case AC_JACK_LINE_IN: | ||
4994 | add_auto_cfg_input_pin(cfg, nid, AUTO_PIN_LINE_IN); | ||
4995 | break; | ||
4996 | case AC_JACK_CD: | ||
4997 | add_auto_cfg_input_pin(cfg, nid, AUTO_PIN_CD); | ||
4998 | break; | ||
4999 | case AC_JACK_AUX: | ||
5000 | add_auto_cfg_input_pin(cfg, nid, AUTO_PIN_AUX); | ||
5001 | break; | ||
5002 | case AC_JACK_SPDIF_OUT: | ||
5003 | case AC_JACK_DIG_OTHER_OUT: | ||
5004 | if (cfg->dig_outs >= ARRAY_SIZE(cfg->dig_out_pins)) | ||
5005 | continue; | ||
5006 | cfg->dig_out_pins[cfg->dig_outs] = nid; | ||
5007 | cfg->dig_out_type[cfg->dig_outs] = | ||
5008 | (loc == AC_JACK_LOC_HDMI) ? | ||
5009 | HDA_PCM_TYPE_HDMI : HDA_PCM_TYPE_SPDIF; | ||
5010 | cfg->dig_outs++; | ||
5011 | break; | ||
5012 | case AC_JACK_SPDIF_IN: | ||
5013 | case AC_JACK_DIG_OTHER_IN: | ||
5014 | cfg->dig_in_pin = nid; | ||
5015 | if (loc == AC_JACK_LOC_HDMI) | ||
5016 | cfg->dig_in_type = HDA_PCM_TYPE_HDMI; | ||
5017 | else | ||
5018 | cfg->dig_in_type = HDA_PCM_TYPE_SPDIF; | ||
5019 | break; | ||
5020 | } | ||
5021 | } | ||
5022 | |||
5023 | /* FIX-UP: | ||
5024 | * If no line-out is defined but multiple HPs are found, | ||
5025 | * some of them might be the real line-outs. | ||
5026 | */ | ||
5027 | if (!cfg->line_outs && cfg->hp_outs > 1 && | ||
5028 | !(cond_flags & HDA_PINCFG_NO_HP_FIXUP)) { | ||
5029 | int i = 0; | ||
5030 | while (i < cfg->hp_outs) { | ||
5031 | /* The real HPs should have the sequence 0x0f */ | ||
5032 | if ((sequences_hp[i] & 0x0f) == 0x0f) { | ||
5033 | i++; | ||
5034 | continue; | ||
5035 | } | ||
5036 | /* Move it to the line-out table */ | ||
5037 | cfg->line_out_pins[cfg->line_outs] = cfg->hp_pins[i]; | ||
5038 | sequences_line_out[cfg->line_outs] = sequences_hp[i]; | ||
5039 | cfg->line_outs++; | ||
5040 | cfg->hp_outs--; | ||
5041 | memmove(cfg->hp_pins + i, cfg->hp_pins + i + 1, | ||
5042 | sizeof(cfg->hp_pins[0]) * (cfg->hp_outs - i)); | ||
5043 | memmove(sequences_hp + i, sequences_hp + i + 1, | ||
5044 | sizeof(sequences_hp[0]) * (cfg->hp_outs - i)); | ||
5045 | } | ||
5046 | memset(cfg->hp_pins + cfg->hp_outs, 0, | ||
5047 | sizeof(hda_nid_t) * (AUTO_CFG_MAX_OUTS - cfg->hp_outs)); | ||
5048 | if (!cfg->hp_outs) | ||
5049 | cfg->line_out_type = AUTO_PIN_HP_OUT; | ||
5050 | |||
5051 | } | ||
5052 | |||
5053 | /* sort by sequence */ | ||
5054 | sort_pins_by_sequence(cfg->line_out_pins, sequences_line_out, | ||
5055 | cfg->line_outs); | ||
5056 | sort_pins_by_sequence(cfg->speaker_pins, sequences_speaker, | ||
5057 | cfg->speaker_outs); | ||
5058 | sort_pins_by_sequence(cfg->hp_pins, sequences_hp, | ||
5059 | cfg->hp_outs); | ||
5060 | |||
5061 | /* | ||
5062 | * FIX-UP: if no line-outs are detected, try to use speaker or HP pin | ||
5063 | * as a primary output | ||
5064 | */ | ||
5065 | if (!cfg->line_outs && | ||
5066 | !(cond_flags & HDA_PINCFG_NO_LO_FIXUP)) { | ||
5067 | if (cfg->speaker_outs) { | ||
5068 | cfg->line_outs = cfg->speaker_outs; | ||
5069 | memcpy(cfg->line_out_pins, cfg->speaker_pins, | ||
5070 | sizeof(cfg->speaker_pins)); | ||
5071 | cfg->speaker_outs = 0; | ||
5072 | memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins)); | ||
5073 | cfg->line_out_type = AUTO_PIN_SPEAKER_OUT; | ||
5074 | } else if (cfg->hp_outs) { | ||
5075 | cfg->line_outs = cfg->hp_outs; | ||
5076 | memcpy(cfg->line_out_pins, cfg->hp_pins, | ||
5077 | sizeof(cfg->hp_pins)); | ||
5078 | cfg->hp_outs = 0; | ||
5079 | memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins)); | ||
5080 | cfg->line_out_type = AUTO_PIN_HP_OUT; | ||
5081 | } | ||
5082 | } | ||
5083 | |||
5084 | reorder_outputs(cfg->line_outs, cfg->line_out_pins); | ||
5085 | reorder_outputs(cfg->hp_outs, cfg->hp_pins); | ||
5086 | reorder_outputs(cfg->speaker_outs, cfg->speaker_pins); | ||
5087 | |||
5088 | sort_autocfg_input_pins(cfg); | ||
5089 | |||
5090 | /* | ||
5091 | * debug prints of the parsed results | ||
5092 | */ | ||
5093 | snd_printd("autoconfig: line_outs=%d (0x%x/0x%x/0x%x/0x%x/0x%x) type:%s\n", | ||
5094 | cfg->line_outs, cfg->line_out_pins[0], cfg->line_out_pins[1], | ||
5095 | cfg->line_out_pins[2], cfg->line_out_pins[3], | ||
5096 | cfg->line_out_pins[4], | ||
5097 | cfg->line_out_type == AUTO_PIN_HP_OUT ? "hp" : | ||
5098 | (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT ? | ||
5099 | "speaker" : "line")); | ||
5100 | snd_printd(" speaker_outs=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n", | ||
5101 | cfg->speaker_outs, cfg->speaker_pins[0], | ||
5102 | cfg->speaker_pins[1], cfg->speaker_pins[2], | ||
5103 | cfg->speaker_pins[3], cfg->speaker_pins[4]); | ||
5104 | snd_printd(" hp_outs=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n", | ||
5105 | cfg->hp_outs, cfg->hp_pins[0], | ||
5106 | cfg->hp_pins[1], cfg->hp_pins[2], | ||
5107 | cfg->hp_pins[3], cfg->hp_pins[4]); | ||
5108 | snd_printd(" mono: mono_out=0x%x\n", cfg->mono_out_pin); | ||
5109 | if (cfg->dig_outs) | ||
5110 | snd_printd(" dig-out=0x%x/0x%x\n", | ||
5111 | cfg->dig_out_pins[0], cfg->dig_out_pins[1]); | ||
5112 | snd_printd(" inputs:"); | ||
5113 | for (i = 0; i < cfg->num_inputs; i++) { | ||
5114 | snd_printd(" %s=0x%x", | ||
5115 | hda_get_autocfg_input_label(codec, cfg, i), | ||
5116 | cfg->inputs[i].pin); | ||
5117 | } | ||
5118 | snd_printd("\n"); | ||
5119 | if (cfg->dig_in_pin) | ||
5120 | snd_printd(" dig-in=0x%x\n", cfg->dig_in_pin); | ||
5121 | |||
5122 | return 0; | ||
5123 | } | ||
5124 | EXPORT_SYMBOL_HDA(snd_hda_parse_pin_defcfg); | ||
5125 | |||
5126 | int snd_hda_get_input_pin_attr(unsigned int def_conf) | ||
5127 | { | ||
5128 | unsigned int loc = get_defcfg_location(def_conf); | ||
5129 | unsigned int conn = get_defcfg_connect(def_conf); | ||
5130 | if (conn == AC_JACK_PORT_NONE) | ||
5131 | return INPUT_PIN_ATTR_UNUSED; | ||
5132 | /* Windows may claim the internal mic to be BOTH, too */ | ||
5133 | if (conn == AC_JACK_PORT_FIXED || conn == AC_JACK_PORT_BOTH) | ||
5134 | return INPUT_PIN_ATTR_INT; | ||
5135 | if ((loc & 0x30) == AC_JACK_LOC_INTERNAL) | ||
5136 | return INPUT_PIN_ATTR_INT; | ||
5137 | if ((loc & 0x30) == AC_JACK_LOC_SEPARATE) | ||
5138 | return INPUT_PIN_ATTR_DOCK; | ||
5139 | if (loc == AC_JACK_LOC_REAR) | ||
5140 | return INPUT_PIN_ATTR_REAR; | ||
5141 | if (loc == AC_JACK_LOC_FRONT) | ||
5142 | return INPUT_PIN_ATTR_FRONT; | ||
5143 | return INPUT_PIN_ATTR_NORMAL; | ||
5144 | } | ||
5145 | EXPORT_SYMBOL_HDA(snd_hda_get_input_pin_attr); | ||
5146 | |||
5147 | /** | ||
5148 | * hda_get_input_pin_label - Give a label for the given input pin | ||
5149 | * | ||
5150 | * When check_location is true, the function checks the pin location | ||
5151 | * for mic and line-in pins, and set an appropriate prefix like "Front", | ||
5152 | * "Rear", "Internal". | ||
5153 | */ | ||
5154 | |||
5155 | static const char *hda_get_input_pin_label(struct hda_codec *codec, | ||
5156 | hda_nid_t pin, bool check_location) | ||
5157 | { | ||
5158 | unsigned int def_conf; | ||
5159 | static const char * const mic_names[] = { | ||
5160 | "Internal Mic", "Dock Mic", "Mic", "Front Mic", "Rear Mic", | ||
5161 | }; | ||
5162 | int attr; | ||
5163 | |||
5164 | def_conf = snd_hda_codec_get_pincfg(codec, pin); | ||
5165 | |||
5166 | switch (get_defcfg_device(def_conf)) { | ||
5167 | case AC_JACK_MIC_IN: | ||
5168 | if (!check_location) | ||
5169 | return "Mic"; | ||
5170 | attr = snd_hda_get_input_pin_attr(def_conf); | ||
5171 | if (!attr) | ||
5172 | return "None"; | ||
5173 | return mic_names[attr - 1]; | ||
5174 | case AC_JACK_LINE_IN: | ||
5175 | if (!check_location) | ||
5176 | return "Line"; | ||
5177 | attr = snd_hda_get_input_pin_attr(def_conf); | ||
5178 | if (!attr) | ||
5179 | return "None"; | ||
5180 | if (attr == INPUT_PIN_ATTR_DOCK) | ||
5181 | return "Dock Line"; | ||
5182 | return "Line"; | ||
5183 | case AC_JACK_AUX: | ||
5184 | return "Aux"; | ||
5185 | case AC_JACK_CD: | ||
5186 | return "CD"; | ||
5187 | case AC_JACK_SPDIF_IN: | ||
5188 | return "SPDIF In"; | ||
5189 | case AC_JACK_DIG_OTHER_IN: | ||
5190 | return "Digital In"; | ||
5191 | default: | ||
5192 | return "Misc"; | ||
5193 | } | ||
5194 | } | ||
5195 | |||
5196 | /* Check whether the location prefix needs to be added to the label. | ||
5197 | * If all mic-jacks are in the same location (e.g. rear panel), we don't | ||
5198 | * have to put "Front" prefix to each label. In such a case, returns false. | ||
5199 | */ | ||
5200 | static int check_mic_location_need(struct hda_codec *codec, | ||
5201 | const struct auto_pin_cfg *cfg, | ||
5202 | int input) | ||
5203 | { | ||
5204 | unsigned int defc; | ||
5205 | int i, attr, attr2; | ||
5206 | |||
5207 | defc = snd_hda_codec_get_pincfg(codec, cfg->inputs[input].pin); | ||
5208 | attr = snd_hda_get_input_pin_attr(defc); | ||
5209 | /* for internal or docking mics, we need locations */ | ||
5210 | if (attr <= INPUT_PIN_ATTR_NORMAL) | ||
5211 | return 1; | ||
5212 | |||
5213 | attr = 0; | ||
5214 | for (i = 0; i < cfg->num_inputs; i++) { | ||
5215 | defc = snd_hda_codec_get_pincfg(codec, cfg->inputs[i].pin); | ||
5216 | attr2 = snd_hda_get_input_pin_attr(defc); | ||
5217 | if (attr2 >= INPUT_PIN_ATTR_NORMAL) { | ||
5218 | if (attr && attr != attr2) | ||
5219 | return 1; /* different locations found */ | ||
5220 | attr = attr2; | ||
5221 | } | ||
5222 | } | ||
5223 | return 0; | ||
5224 | } | ||
5225 | |||
5226 | /** | 4883 | /** |
5227 | * hda_get_autocfg_input_label - Get a label for the given input | 4884 | * snd_hda_get_default_vref - Get the default (mic) VREF pin bits |
5228 | * | 4885 | * |
5229 | * Get a label for the given input pin defined by the autocfg item. | 4886 | * Guess the suitable VREF pin bits to be set as the pin-control value. |
5230 | * Unlike hda_get_input_pin_label(), this function checks all inputs | 4887 | * Note: the function doesn't set the AC_PINCTL_IN_EN bit. |
5231 | * defined in autocfg and avoids the redundant mic/line prefix as much as | 4888 | */ |
5232 | * possible. | 4889 | unsigned int snd_hda_get_default_vref(struct hda_codec *codec, hda_nid_t pin) |
5233 | */ | 4890 | { |
5234 | const char *hda_get_autocfg_input_label(struct hda_codec *codec, | 4891 | unsigned int pincap; |
5235 | const struct auto_pin_cfg *cfg, | 4892 | unsigned int oldval; |
5236 | int input) | 4893 | oldval = snd_hda_codec_read(codec, pin, 0, |
5237 | { | 4894 | AC_VERB_GET_PIN_WIDGET_CONTROL, 0); |
5238 | int type = cfg->inputs[input].type; | 4895 | pincap = snd_hda_query_pin_caps(codec, pin); |
5239 | int has_multiple_pins = 0; | 4896 | pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT; |
5240 | 4897 | /* Exception: if the default pin setup is vref50, we give it priority */ | |
5241 | if ((input > 0 && cfg->inputs[input - 1].type == type) || | 4898 | if ((pincap & AC_PINCAP_VREF_80) && oldval != PIN_VREF50) |
5242 | (input < cfg->num_inputs - 1 && cfg->inputs[input + 1].type == type)) | 4899 | return AC_PINCTL_VREF_80; |
5243 | has_multiple_pins = 1; | 4900 | else if (pincap & AC_PINCAP_VREF_50) |
5244 | if (has_multiple_pins && type == AUTO_PIN_MIC) | 4901 | return AC_PINCTL_VREF_50; |
5245 | has_multiple_pins &= check_mic_location_need(codec, cfg, input); | 4902 | else if (pincap & AC_PINCAP_VREF_100) |
5246 | return hda_get_input_pin_label(codec, cfg->inputs[input].pin, | 4903 | return AC_PINCTL_VREF_100; |
5247 | has_multiple_pins); | 4904 | else if (pincap & AC_PINCAP_VREF_GRD) |
5248 | } | 4905 | return AC_PINCTL_VREF_GRD; |
5249 | EXPORT_SYMBOL_HDA(hda_get_autocfg_input_label); | 4906 | return AC_PINCTL_VREF_HIZ; |
5250 | 4907 | } | |
5251 | /* return the position of NID in the list, or -1 if not found */ | 4908 | EXPORT_SYMBOL_HDA(snd_hda_get_default_vref); |
5252 | static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums) | 4909 | |
5253 | { | 4910 | int _snd_hda_set_pin_ctl(struct hda_codec *codec, hda_nid_t pin, |
5254 | int i; | 4911 | unsigned int val, bool cached) |
5255 | for (i = 0; i < nums; i++) | 4912 | { |
5256 | if (list[i] == nid) | 4913 | if (val) { |
5257 | return i; | 4914 | unsigned int cap = snd_hda_query_pin_caps(codec, pin); |
5258 | return -1; | 4915 | if (cap && (val & AC_PINCTL_OUT_EN)) { |
5259 | } | 4916 | if (!(cap & AC_PINCAP_OUT)) |
5260 | 4917 | val &= ~(AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN); | |
5261 | /* get a unique suffix or an index number */ | 4918 | else if ((val & AC_PINCTL_HP_EN) && |
5262 | static const char *check_output_sfx(hda_nid_t nid, const hda_nid_t *pins, | 4919 | !(cap & AC_PINCAP_HP_DRV)) |
5263 | int num_pins, int *indexp) | 4920 | val &= ~AC_PINCTL_HP_EN; |
5264 | { | ||
5265 | static const char * const channel_sfx[] = { | ||
5266 | " Front", " Surround", " CLFE", " Side" | ||
5267 | }; | ||
5268 | int i; | ||
5269 | |||
5270 | i = find_idx_in_nid_list(nid, pins, num_pins); | ||
5271 | if (i < 0) | ||
5272 | return NULL; | ||
5273 | if (num_pins == 1) | ||
5274 | return ""; | ||
5275 | if (num_pins > ARRAY_SIZE(channel_sfx)) { | ||
5276 | if (indexp) | ||
5277 | *indexp = i; | ||
5278 | return ""; | ||
5279 | } | ||
5280 | return channel_sfx[i]; | ||
5281 | } | ||
5282 | |||
5283 | static int fill_audio_out_name(struct hda_codec *codec, hda_nid_t nid, | ||
5284 | const struct auto_pin_cfg *cfg, | ||
5285 | const char *name, char *label, int maxlen, | ||
5286 | int *indexp) | ||
5287 | { | ||
5288 | unsigned int def_conf = snd_hda_codec_get_pincfg(codec, nid); | ||
5289 | int attr = snd_hda_get_input_pin_attr(def_conf); | ||
5290 | const char *pfx = "", *sfx = ""; | ||
5291 | |||
5292 | /* handle as a speaker if it's a fixed line-out */ | ||
5293 | if (!strcmp(name, "Line Out") && attr == INPUT_PIN_ATTR_INT) | ||
5294 | name = "Speaker"; | ||
5295 | /* check the location */ | ||
5296 | switch (attr) { | ||
5297 | case INPUT_PIN_ATTR_DOCK: | ||
5298 | pfx = "Dock "; | ||
5299 | break; | ||
5300 | case INPUT_PIN_ATTR_FRONT: | ||
5301 | pfx = "Front "; | ||
5302 | break; | ||
5303 | } | ||
5304 | if (cfg) { | ||
5305 | /* try to give a unique suffix if needed */ | ||
5306 | sfx = check_output_sfx(nid, cfg->line_out_pins, cfg->line_outs, | ||
5307 | indexp); | ||
5308 | if (!sfx) | ||
5309 | sfx = check_output_sfx(nid, cfg->speaker_pins, cfg->speaker_outs, | ||
5310 | indexp); | ||
5311 | if (!sfx) { | ||
5312 | /* don't add channel suffix for Headphone controls */ | ||
5313 | int idx = find_idx_in_nid_list(nid, cfg->hp_pins, | ||
5314 | cfg->hp_outs); | ||
5315 | if (idx >= 0) | ||
5316 | *indexp = idx; | ||
5317 | sfx = ""; | ||
5318 | } | 4921 | } |
5319 | } | 4922 | if (cap && (val & AC_PINCTL_IN_EN)) { |
5320 | snprintf(label, maxlen, "%s%s%s", pfx, name, sfx); | 4923 | if (!(cap & AC_PINCAP_IN)) |
5321 | return 1; | 4924 | val &= ~(AC_PINCTL_IN_EN | AC_PINCTL_VREFEN); |
5322 | } | ||
5323 | |||
5324 | /** | ||
5325 | * snd_hda_get_pin_label - Get a label for the given I/O pin | ||
5326 | * | ||
5327 | * Get a label for the given pin. This function works for both input and | ||
5328 | * output pins. When @cfg is given as non-NULL, the function tries to get | ||
5329 | * an optimized label using hda_get_autocfg_input_label(). | ||
5330 | * | ||
5331 | * This function tries to give a unique label string for the pin as much as | ||
5332 | * possible. For example, when the multiple line-outs are present, it adds | ||
5333 | * the channel suffix like "Front", "Surround", etc (only when @cfg is given). | ||
5334 | * If no unique name with a suffix is available and @indexp is non-NULL, the | ||
5335 | * index number is stored in the pointer. | ||
5336 | */ | ||
5337 | int snd_hda_get_pin_label(struct hda_codec *codec, hda_nid_t nid, | ||
5338 | const struct auto_pin_cfg *cfg, | ||
5339 | char *label, int maxlen, int *indexp) | ||
5340 | { | ||
5341 | unsigned int def_conf = snd_hda_codec_get_pincfg(codec, nid); | ||
5342 | const char *name = NULL; | ||
5343 | int i; | ||
5344 | |||
5345 | if (indexp) | ||
5346 | *indexp = 0; | ||
5347 | if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE) | ||
5348 | return 0; | ||
5349 | |||
5350 | switch (get_defcfg_device(def_conf)) { | ||
5351 | case AC_JACK_LINE_OUT: | ||
5352 | return fill_audio_out_name(codec, nid, cfg, "Line Out", | ||
5353 | label, maxlen, indexp); | ||
5354 | case AC_JACK_SPEAKER: | ||
5355 | return fill_audio_out_name(codec, nid, cfg, "Speaker", | ||
5356 | label, maxlen, indexp); | ||
5357 | case AC_JACK_HP_OUT: | ||
5358 | return fill_audio_out_name(codec, nid, cfg, "Headphone", | ||
5359 | label, maxlen, indexp); | ||
5360 | case AC_JACK_SPDIF_OUT: | ||
5361 | case AC_JACK_DIG_OTHER_OUT: | ||
5362 | if (get_defcfg_location(def_conf) == AC_JACK_LOC_HDMI) | ||
5363 | name = "HDMI"; | ||
5364 | else | ||
5365 | name = "SPDIF"; | ||
5366 | if (cfg && indexp) { | ||
5367 | i = find_idx_in_nid_list(nid, cfg->dig_out_pins, | ||
5368 | cfg->dig_outs); | ||
5369 | if (i >= 0) | ||
5370 | *indexp = i; | ||
5371 | } | ||
5372 | break; | ||
5373 | default: | ||
5374 | if (cfg) { | ||
5375 | for (i = 0; i < cfg->num_inputs; i++) { | ||
5376 | if (cfg->inputs[i].pin != nid) | ||
5377 | continue; | ||
5378 | name = hda_get_autocfg_input_label(codec, cfg, i); | ||
5379 | if (name) | ||
5380 | break; | ||
5381 | } | ||
5382 | } | 4925 | } |
5383 | if (!name) | ||
5384 | name = hda_get_input_pin_label(codec, nid, true); | ||
5385 | break; | ||
5386 | } | 4926 | } |
5387 | if (!name) | 4927 | if (cached) |
5388 | return 0; | 4928 | return snd_hda_codec_update_cache(codec, pin, 0, |
5389 | strlcpy(label, name, maxlen); | 4929 | AC_VERB_SET_PIN_WIDGET_CONTROL, val); |
5390 | return 1; | 4930 | else |
4931 | return snd_hda_codec_write(codec, pin, 0, | ||
4932 | AC_VERB_SET_PIN_WIDGET_CONTROL, val); | ||
5391 | } | 4933 | } |
5392 | EXPORT_SYMBOL_HDA(snd_hda_get_pin_label); | 4934 | EXPORT_SYMBOL_HDA(_snd_hda_set_pin_ctl); |
5393 | 4935 | ||
5394 | /** | 4936 | /** |
5395 | * snd_hda_add_imux_item - Add an item to input_mux | 4937 | * snd_hda_add_imux_item - Add an item to input_mux |
@@ -5444,8 +4986,6 @@ int snd_hda_suspend(struct hda_bus *bus) | |||
5444 | list_for_each_entry(codec, &bus->codec_list, list) { | 4986 | list_for_each_entry(codec, &bus->codec_list, list) { |
5445 | if (hda_codec_is_power_on(codec)) | 4987 | if (hda_codec_is_power_on(codec)) |
5446 | hda_call_codec_suspend(codec); | 4988 | hda_call_codec_suspend(codec); |
5447 | if (codec->patch_ops.post_suspend) | ||
5448 | codec->patch_ops.post_suspend(codec); | ||
5449 | } | 4989 | } |
5450 | return 0; | 4990 | return 0; |
5451 | } | 4991 | } |
@@ -5465,10 +5005,7 @@ int snd_hda_resume(struct hda_bus *bus) | |||
5465 | struct hda_codec *codec; | 5005 | struct hda_codec *codec; |
5466 | 5006 | ||
5467 | list_for_each_entry(codec, &bus->codec_list, list) { | 5007 | list_for_each_entry(codec, &bus->codec_list, list) { |
5468 | if (codec->patch_ops.pre_resume) | 5008 | hda_call_codec_resume(codec); |
5469 | codec->patch_ops.pre_resume(codec); | ||
5470 | if (snd_hda_codec_needs_resume(codec)) | ||
5471 | hda_call_codec_resume(codec); | ||
5472 | } | 5009 | } |
5473 | return 0; | 5010 | return 0; |
5474 | } | 5011 | } |
diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h index 56b4f74c0b13..54b52819fb47 100644 --- a/sound/pci/hda/hda_codec.h +++ b/sound/pci/hda/hda_codec.h | |||
@@ -704,8 +704,6 @@ struct hda_codec_ops { | |||
704 | unsigned int power_state); | 704 | unsigned int power_state); |
705 | #ifdef CONFIG_PM | 705 | #ifdef CONFIG_PM |
706 | int (*suspend)(struct hda_codec *codec, pm_message_t state); | 706 | int (*suspend)(struct hda_codec *codec, pm_message_t state); |
707 | int (*post_suspend)(struct hda_codec *codec); | ||
708 | int (*pre_resume)(struct hda_codec *codec); | ||
709 | int (*resume)(struct hda_codec *codec); | 707 | int (*resume)(struct hda_codec *codec); |
710 | #endif | 708 | #endif |
711 | #ifdef CONFIG_SND_HDA_POWER_SAVE | 709 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
@@ -829,6 +827,7 @@ struct hda_codec { | |||
829 | 827 | ||
830 | struct mutex spdif_mutex; | 828 | struct mutex spdif_mutex; |
831 | struct mutex control_mutex; | 829 | struct mutex control_mutex; |
830 | struct mutex hash_mutex; | ||
832 | struct snd_array spdif_out; | 831 | struct snd_array spdif_out; |
833 | unsigned int spdif_in_enable; /* SPDIF input enable? */ | 832 | unsigned int spdif_in_enable; /* SPDIF input enable? */ |
834 | const hda_nid_t *slave_dig_outs; /* optional digital out slave widgets */ | 833 | const hda_nid_t *slave_dig_outs; /* optional digital out slave widgets */ |
@@ -861,12 +860,13 @@ struct hda_codec { | |||
861 | unsigned int no_jack_detect:1; /* Machine has no jack-detection */ | 860 | unsigned int no_jack_detect:1; /* Machine has no jack-detection */ |
862 | #ifdef CONFIG_SND_HDA_POWER_SAVE | 861 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
863 | unsigned int power_on :1; /* current (global) power-state */ | 862 | unsigned int power_on :1; /* current (global) power-state */ |
864 | unsigned int power_transition :1; /* power-state in transition */ | 863 | int power_transition; /* power-state in transition */ |
865 | int power_count; /* current (global) power refcount */ | 864 | int power_count; /* current (global) power refcount */ |
866 | struct delayed_work power_work; /* delayed task for powerdown */ | 865 | struct delayed_work power_work; /* delayed task for powerdown */ |
867 | unsigned long power_on_acct; | 866 | unsigned long power_on_acct; |
868 | unsigned long power_off_acct; | 867 | unsigned long power_off_acct; |
869 | unsigned long power_jiffies; | 868 | unsigned long power_jiffies; |
869 | spinlock_t power_lock; | ||
870 | #endif | 870 | #endif |
871 | 871 | ||
872 | /* codec-specific additional proc output */ | 872 | /* codec-specific additional proc output */ |
@@ -911,10 +911,13 @@ int snd_hda_get_sub_nodes(struct hda_codec *codec, hda_nid_t nid, | |||
911 | hda_nid_t *start_id); | 911 | hda_nid_t *start_id); |
912 | int snd_hda_get_connections(struct hda_codec *codec, hda_nid_t nid, | 912 | int snd_hda_get_connections(struct hda_codec *codec, hda_nid_t nid, |
913 | hda_nid_t *conn_list, int max_conns); | 913 | hda_nid_t *conn_list, int max_conns); |
914 | static inline int | ||
915 | snd_hda_get_num_conns(struct hda_codec *codec, hda_nid_t nid) | ||
916 | { | ||
917 | return snd_hda_get_connections(codec, nid, NULL, 0); | ||
918 | } | ||
914 | int snd_hda_get_raw_connections(struct hda_codec *codec, hda_nid_t nid, | 919 | int snd_hda_get_raw_connections(struct hda_codec *codec, hda_nid_t nid, |
915 | hda_nid_t *conn_list, int max_conns); | 920 | hda_nid_t *conn_list, int max_conns); |
916 | int snd_hda_get_conn_list(struct hda_codec *codec, hda_nid_t nid, | ||
917 | const hda_nid_t **listp); | ||
918 | int snd_hda_override_conn_list(struct hda_codec *codec, hda_nid_t nid, int nums, | 921 | int snd_hda_override_conn_list(struct hda_codec *codec, hda_nid_t nid, int nums, |
919 | const hda_nid_t *list); | 922 | const hda_nid_t *list); |
920 | int snd_hda_get_conn_index(struct hda_codec *codec, hda_nid_t mux, | 923 | int snd_hda_get_conn_index(struct hda_codec *codec, hda_nid_t mux, |
@@ -1051,12 +1054,10 @@ const char *snd_hda_get_jack_location(u32 cfg); | |||
1051 | #ifdef CONFIG_SND_HDA_POWER_SAVE | 1054 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
1052 | void snd_hda_power_up(struct hda_codec *codec); | 1055 | void snd_hda_power_up(struct hda_codec *codec); |
1053 | void snd_hda_power_down(struct hda_codec *codec); | 1056 | void snd_hda_power_down(struct hda_codec *codec); |
1054 | #define snd_hda_codec_needs_resume(codec) codec->power_count | ||
1055 | void snd_hda_update_power_acct(struct hda_codec *codec); | 1057 | void snd_hda_update_power_acct(struct hda_codec *codec); |
1056 | #else | 1058 | #else |
1057 | static inline void snd_hda_power_up(struct hda_codec *codec) {} | 1059 | static inline void snd_hda_power_up(struct hda_codec *codec) {} |
1058 | static inline void snd_hda_power_down(struct hda_codec *codec) {} | 1060 | static inline void snd_hda_power_down(struct hda_codec *codec) {} |
1059 | #define snd_hda_codec_needs_resume(codec) 1 | ||
1060 | #endif | 1061 | #endif |
1061 | 1062 | ||
1062 | #ifdef CONFIG_SND_HDA_PATCH_LOADER | 1063 | #ifdef CONFIG_SND_HDA_PATCH_LOADER |
diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c index 1f350522bed4..4ab8102f87ea 100644 --- a/sound/pci/hda/hda_intel.c +++ b/sound/pci/hda/hda_intel.c | |||
@@ -497,6 +497,7 @@ enum { | |||
497 | AZX_DRIVER_NVIDIA, | 497 | AZX_DRIVER_NVIDIA, |
498 | AZX_DRIVER_TERA, | 498 | AZX_DRIVER_TERA, |
499 | AZX_DRIVER_CTX, | 499 | AZX_DRIVER_CTX, |
500 | AZX_DRIVER_CTHDA, | ||
500 | AZX_DRIVER_GENERIC, | 501 | AZX_DRIVER_GENERIC, |
501 | AZX_NUM_DRIVERS, /* keep this as last entry */ | 502 | AZX_NUM_DRIVERS, /* keep this as last entry */ |
502 | }; | 503 | }; |
@@ -518,6 +519,7 @@ enum { | |||
518 | #define AZX_DCAPS_OLD_SSYNC (1 << 20) /* Old SSYNC reg for ICH */ | 519 | #define AZX_DCAPS_OLD_SSYNC (1 << 20) /* Old SSYNC reg for ICH */ |
519 | #define AZX_DCAPS_BUFSIZE (1 << 21) /* no buffer size alignment */ | 520 | #define AZX_DCAPS_BUFSIZE (1 << 21) /* no buffer size alignment */ |
520 | #define AZX_DCAPS_ALIGN_BUFSIZE (1 << 22) /* buffer size alignment */ | 521 | #define AZX_DCAPS_ALIGN_BUFSIZE (1 << 22) /* buffer size alignment */ |
522 | #define AZX_DCAPS_4K_BDLE_BOUNDARY (1 << 23) /* BDLE in 4k boundary */ | ||
521 | 523 | ||
522 | /* quirks for ATI SB / AMD Hudson */ | 524 | /* quirks for ATI SB / AMD Hudson */ |
523 | #define AZX_DCAPS_PRESET_ATI_SB \ | 525 | #define AZX_DCAPS_PRESET_ATI_SB \ |
@@ -533,6 +535,9 @@ enum { | |||
533 | (AZX_DCAPS_NVIDIA_SNOOP | AZX_DCAPS_RIRB_DELAY | AZX_DCAPS_NO_MSI |\ | 535 | (AZX_DCAPS_NVIDIA_SNOOP | AZX_DCAPS_RIRB_DELAY | AZX_DCAPS_NO_MSI |\ |
534 | AZX_DCAPS_ALIGN_BUFSIZE) | 536 | AZX_DCAPS_ALIGN_BUFSIZE) |
535 | 537 | ||
538 | #define AZX_DCAPS_PRESET_CTHDA \ | ||
539 | (AZX_DCAPS_NO_MSI | AZX_DCAPS_POSFIX_LPIB | AZX_DCAPS_4K_BDLE_BOUNDARY) | ||
540 | |||
536 | static char *driver_short_names[] __devinitdata = { | 541 | static char *driver_short_names[] __devinitdata = { |
537 | [AZX_DRIVER_ICH] = "HDA Intel", | 542 | [AZX_DRIVER_ICH] = "HDA Intel", |
538 | [AZX_DRIVER_PCH] = "HDA Intel PCH", | 543 | [AZX_DRIVER_PCH] = "HDA Intel PCH", |
@@ -546,6 +551,7 @@ static char *driver_short_names[] __devinitdata = { | |||
546 | [AZX_DRIVER_NVIDIA] = "HDA NVidia", | 551 | [AZX_DRIVER_NVIDIA] = "HDA NVidia", |
547 | [AZX_DRIVER_TERA] = "HDA Teradici", | 552 | [AZX_DRIVER_TERA] = "HDA Teradici", |
548 | [AZX_DRIVER_CTX] = "HDA Creative", | 553 | [AZX_DRIVER_CTX] = "HDA Creative", |
554 | [AZX_DRIVER_CTHDA] = "HDA Creative", | ||
549 | [AZX_DRIVER_GENERIC] = "HD-Audio Generic", | 555 | [AZX_DRIVER_GENERIC] = "HD-Audio Generic", |
550 | }; | 556 | }; |
551 | 557 | ||
@@ -1285,7 +1291,8 @@ static irqreturn_t azx_interrupt(int irq, void *dev_id) | |||
1285 | /* | 1291 | /* |
1286 | * set up a BDL entry | 1292 | * set up a BDL entry |
1287 | */ | 1293 | */ |
1288 | static int setup_bdle(struct snd_pcm_substream *substream, | 1294 | static int setup_bdle(struct azx *chip, |
1295 | struct snd_pcm_substream *substream, | ||
1289 | struct azx_dev *azx_dev, u32 **bdlp, | 1296 | struct azx_dev *azx_dev, u32 **bdlp, |
1290 | int ofs, int size, int with_ioc) | 1297 | int ofs, int size, int with_ioc) |
1291 | { | 1298 | { |
@@ -1304,6 +1311,12 @@ static int setup_bdle(struct snd_pcm_substream *substream, | |||
1304 | bdl[1] = cpu_to_le32(upper_32_bits(addr)); | 1311 | bdl[1] = cpu_to_le32(upper_32_bits(addr)); |
1305 | /* program the size field of the BDL entry */ | 1312 | /* program the size field of the BDL entry */ |
1306 | chunk = snd_pcm_sgbuf_get_chunk_size(substream, ofs, size); | 1313 | chunk = snd_pcm_sgbuf_get_chunk_size(substream, ofs, size); |
1314 | /* one BDLE cannot cross 4K boundary on CTHDA chips */ | ||
1315 | if (chip->driver_caps & AZX_DCAPS_4K_BDLE_BOUNDARY) { | ||
1316 | u32 remain = 0x1000 - (ofs & 0xfff); | ||
1317 | if (chunk > remain) | ||
1318 | chunk = remain; | ||
1319 | } | ||
1307 | bdl[2] = cpu_to_le32(chunk); | 1320 | bdl[2] = cpu_to_le32(chunk); |
1308 | /* program the IOC to enable interrupt | 1321 | /* program the IOC to enable interrupt |
1309 | * only when the whole fragment is processed | 1322 | * only when the whole fragment is processed |
@@ -1356,7 +1369,7 @@ static int azx_setup_periods(struct azx *chip, | |||
1356 | bdl_pos_adj[chip->dev_index]); | 1369 | bdl_pos_adj[chip->dev_index]); |
1357 | pos_adj = 0; | 1370 | pos_adj = 0; |
1358 | } else { | 1371 | } else { |
1359 | ofs = setup_bdle(substream, azx_dev, | 1372 | ofs = setup_bdle(chip, substream, azx_dev, |
1360 | &bdl, ofs, pos_adj, | 1373 | &bdl, ofs, pos_adj, |
1361 | !substream->runtime->no_period_wakeup); | 1374 | !substream->runtime->no_period_wakeup); |
1362 | if (ofs < 0) | 1375 | if (ofs < 0) |
@@ -1366,10 +1379,10 @@ static int azx_setup_periods(struct azx *chip, | |||
1366 | pos_adj = 0; | 1379 | pos_adj = 0; |
1367 | for (i = 0; i < periods; i++) { | 1380 | for (i = 0; i < periods; i++) { |
1368 | if (i == periods - 1 && pos_adj) | 1381 | if (i == periods - 1 && pos_adj) |
1369 | ofs = setup_bdle(substream, azx_dev, &bdl, ofs, | 1382 | ofs = setup_bdle(chip, substream, azx_dev, &bdl, ofs, |
1370 | period_bytes - pos_adj, 0); | 1383 | period_bytes - pos_adj, 0); |
1371 | else | 1384 | else |
1372 | ofs = setup_bdle(substream, azx_dev, &bdl, ofs, | 1385 | ofs = setup_bdle(chip, substream, azx_dev, &bdl, ofs, |
1373 | period_bytes, | 1386 | period_bytes, |
1374 | !substream->runtime->no_period_wakeup); | 1387 | !substream->runtime->no_period_wakeup); |
1375 | if (ofs < 0) | 1388 | if (ofs < 0) |
@@ -2353,17 +2366,6 @@ static void azx_power_notify(struct hda_bus *bus) | |||
2353 | * power management | 2366 | * power management |
2354 | */ | 2367 | */ |
2355 | 2368 | ||
2356 | static int snd_hda_codecs_inuse(struct hda_bus *bus) | ||
2357 | { | ||
2358 | struct hda_codec *codec; | ||
2359 | |||
2360 | list_for_each_entry(codec, &bus->codec_list, list) { | ||
2361 | if (snd_hda_codec_needs_resume(codec)) | ||
2362 | return 1; | ||
2363 | } | ||
2364 | return 0; | ||
2365 | } | ||
2366 | |||
2367 | static int azx_suspend(struct pci_dev *pci, pm_message_t state) | 2369 | static int azx_suspend(struct pci_dev *pci, pm_message_t state) |
2368 | { | 2370 | { |
2369 | struct snd_card *card = pci_get_drvdata(pci); | 2371 | struct snd_card *card = pci_get_drvdata(pci); |
@@ -2410,8 +2412,7 @@ static int azx_resume(struct pci_dev *pci) | |||
2410 | return -EIO; | 2412 | return -EIO; |
2411 | azx_init_pci(chip); | 2413 | azx_init_pci(chip); |
2412 | 2414 | ||
2413 | if (snd_hda_codecs_inuse(chip->bus)) | 2415 | azx_init_chip(chip, 1); |
2414 | azx_init_chip(chip, 1); | ||
2415 | 2416 | ||
2416 | snd_hda_resume(chip->bus); | 2417 | snd_hda_resume(chip->bus); |
2417 | snd_power_change_state(card, SNDRV_CTL_POWER_D0); | 2418 | snd_power_change_state(card, SNDRV_CTL_POWER_D0); |
@@ -2565,6 +2566,8 @@ static struct snd_pci_quirk probe_mask_list[] __devinitdata = { | |||
2565 | /* forced codec slots */ | 2566 | /* forced codec slots */ |
2566 | SND_PCI_QUIRK(0x1043, 0x1262, "ASUS W5Fm", 0x103), | 2567 | SND_PCI_QUIRK(0x1043, 0x1262, "ASUS W5Fm", 0x103), |
2567 | SND_PCI_QUIRK(0x1046, 0x1262, "ASUS W5F", 0x103), | 2568 | SND_PCI_QUIRK(0x1046, 0x1262, "ASUS W5F", 0x103), |
2569 | /* WinFast VP200 H (Teradici) user reported broken communication */ | ||
2570 | SND_PCI_QUIRK(0x3a21, 0x040d, "WinFast VP200 H", 0x101), | ||
2568 | {} | 2571 | {} |
2569 | }; | 2572 | }; |
2570 | 2573 | ||
@@ -3130,6 +3133,11 @@ static DEFINE_PCI_DEVICE_TABLE(azx_ids) = { | |||
3130 | .driver_data = AZX_DRIVER_CTX | AZX_DCAPS_CTX_WORKAROUND | | 3133 | .driver_data = AZX_DRIVER_CTX | AZX_DCAPS_CTX_WORKAROUND | |
3131 | AZX_DCAPS_RIRB_PRE_DELAY | AZX_DCAPS_POSFIX_LPIB }, | 3134 | AZX_DCAPS_RIRB_PRE_DELAY | AZX_DCAPS_POSFIX_LPIB }, |
3132 | #endif | 3135 | #endif |
3136 | /* CTHDA chips */ | ||
3137 | { PCI_DEVICE(0x1102, 0x0010), | ||
3138 | .driver_data = AZX_DRIVER_CTHDA | AZX_DCAPS_PRESET_CTHDA }, | ||
3139 | { PCI_DEVICE(0x1102, 0x0012), | ||
3140 | .driver_data = AZX_DRIVER_CTHDA | AZX_DCAPS_PRESET_CTHDA }, | ||
3133 | /* Vortex86MX */ | 3141 | /* Vortex86MX */ |
3134 | { PCI_DEVICE(0x17f3, 0x3010), .driver_data = AZX_DRIVER_GENERIC }, | 3142 | { PCI_DEVICE(0x17f3, 0x3010), .driver_data = AZX_DRIVER_GENERIC }, |
3135 | /* VMware HDAudio */ | 3143 | /* VMware HDAudio */ |
@@ -3148,7 +3156,7 @@ static DEFINE_PCI_DEVICE_TABLE(azx_ids) = { | |||
3148 | MODULE_DEVICE_TABLE(pci, azx_ids); | 3156 | MODULE_DEVICE_TABLE(pci, azx_ids); |
3149 | 3157 | ||
3150 | /* pci_driver definition */ | 3158 | /* pci_driver definition */ |
3151 | static struct pci_driver driver = { | 3159 | static struct pci_driver azx_driver = { |
3152 | .name = KBUILD_MODNAME, | 3160 | .name = KBUILD_MODNAME, |
3153 | .id_table = azx_ids, | 3161 | .id_table = azx_ids, |
3154 | .probe = azx_probe, | 3162 | .probe = azx_probe, |
@@ -3159,15 +3167,4 @@ static struct pci_driver driver = { | |||
3159 | #endif | 3167 | #endif |
3160 | }; | 3168 | }; |
3161 | 3169 | ||
3162 | static int __init alsa_card_azx_init(void) | 3170 | module_pci_driver(azx_driver); |
3163 | { | ||
3164 | return pci_register_driver(&driver); | ||
3165 | } | ||
3166 | |||
3167 | static void __exit alsa_card_azx_exit(void) | ||
3168 | { | ||
3169 | pci_unregister_driver(&driver); | ||
3170 | } | ||
3171 | |||
3172 | module_init(alsa_card_azx_init) | ||
3173 | module_exit(alsa_card_azx_exit) | ||
diff --git a/sound/pci/hda/hda_jack.c b/sound/pci/hda/hda_jack.c index d68948499fbc..2dd1c113a4c1 100644 --- a/sound/pci/hda/hda_jack.c +++ b/sound/pci/hda/hda_jack.c | |||
@@ -17,6 +17,7 @@ | |||
17 | #include <sound/jack.h> | 17 | #include <sound/jack.h> |
18 | #include "hda_codec.h" | 18 | #include "hda_codec.h" |
19 | #include "hda_local.h" | 19 | #include "hda_local.h" |
20 | #include "hda_auto_parser.h" | ||
20 | #include "hda_jack.h" | 21 | #include "hda_jack.h" |
21 | 22 | ||
22 | bool is_jack_detectable(struct hda_codec *codec, hda_nid_t nid) | 23 | bool is_jack_detectable(struct hda_codec *codec, hda_nid_t nid) |
diff --git a/sound/pci/hda/hda_jack.h b/sound/pci/hda/hda_jack.h index c66655cf413a..8ae52465ec5d 100644 --- a/sound/pci/hda/hda_jack.h +++ b/sound/pci/hda/hda_jack.h | |||
@@ -12,6 +12,8 @@ | |||
12 | #ifndef __SOUND_HDA_JACK_H | 12 | #ifndef __SOUND_HDA_JACK_H |
13 | #define __SOUND_HDA_JACK_H | 13 | #define __SOUND_HDA_JACK_H |
14 | 14 | ||
15 | struct auto_pin_cfg; | ||
16 | |||
15 | struct hda_jack_tbl { | 17 | struct hda_jack_tbl { |
16 | hda_nid_t nid; | 18 | hda_nid_t nid; |
17 | unsigned char action; /* event action (0 = none) */ | 19 | unsigned char action; /* event action (0 = none) */ |
diff --git a/sound/pci/hda/hda_local.h b/sound/pci/hda/hda_local.h index 0ec9248165bc..9a096a8e0fc5 100644 --- a/sound/pci/hda/hda_local.h +++ b/sound/pci/hda/hda_local.h | |||
@@ -262,6 +262,8 @@ int snd_hda_input_mux_put(struct hda_codec *codec, | |||
262 | const struct hda_input_mux *imux, | 262 | const struct hda_input_mux *imux, |
263 | struct snd_ctl_elem_value *ucontrol, hda_nid_t nid, | 263 | struct snd_ctl_elem_value *ucontrol, hda_nid_t nid, |
264 | unsigned int *cur_val); | 264 | unsigned int *cur_val); |
265 | int snd_hda_add_imux_item(struct hda_input_mux *imux, const char *label, | ||
266 | int index, int *type_index_ret); | ||
265 | 267 | ||
266 | /* | 268 | /* |
267 | * Channel mode helper | 269 | * Channel mode helper |
@@ -393,72 +395,7 @@ struct hda_bus_unsolicited { | |||
393 | struct hda_bus *bus; | 395 | struct hda_bus *bus; |
394 | }; | 396 | }; |
395 | 397 | ||
396 | /* | 398 | /* helper macros to retrieve pin default-config values */ |
397 | * Helper for automatic pin configuration | ||
398 | */ | ||
399 | |||
400 | enum { | ||
401 | AUTO_PIN_MIC, | ||
402 | AUTO_PIN_LINE_IN, | ||
403 | AUTO_PIN_CD, | ||
404 | AUTO_PIN_AUX, | ||
405 | AUTO_PIN_LAST | ||
406 | }; | ||
407 | |||
408 | enum { | ||
409 | AUTO_PIN_LINE_OUT, | ||
410 | AUTO_PIN_SPEAKER_OUT, | ||
411 | AUTO_PIN_HP_OUT | ||
412 | }; | ||
413 | |||
414 | #define AUTO_CFG_MAX_OUTS HDA_MAX_OUTS | ||
415 | #define AUTO_CFG_MAX_INS 8 | ||
416 | |||
417 | struct auto_pin_cfg_item { | ||
418 | hda_nid_t pin; | ||
419 | int type; | ||
420 | }; | ||
421 | |||
422 | struct auto_pin_cfg; | ||
423 | const char *hda_get_autocfg_input_label(struct hda_codec *codec, | ||
424 | const struct auto_pin_cfg *cfg, | ||
425 | int input); | ||
426 | int snd_hda_get_pin_label(struct hda_codec *codec, hda_nid_t nid, | ||
427 | const struct auto_pin_cfg *cfg, | ||
428 | char *label, int maxlen, int *indexp); | ||
429 | int snd_hda_add_imux_item(struct hda_input_mux *imux, const char *label, | ||
430 | int index, int *type_index_ret); | ||
431 | |||
432 | enum { | ||
433 | INPUT_PIN_ATTR_UNUSED, /* pin not connected */ | ||
434 | INPUT_PIN_ATTR_INT, /* internal mic/line-in */ | ||
435 | INPUT_PIN_ATTR_DOCK, /* docking mic/line-in */ | ||
436 | INPUT_PIN_ATTR_NORMAL, /* mic/line-in jack */ | ||
437 | INPUT_PIN_ATTR_FRONT, /* mic/line-in jack in front */ | ||
438 | INPUT_PIN_ATTR_REAR, /* mic/line-in jack in rear */ | ||
439 | }; | ||
440 | |||
441 | int snd_hda_get_input_pin_attr(unsigned int def_conf); | ||
442 | |||
443 | struct auto_pin_cfg { | ||
444 | int line_outs; | ||
445 | /* sorted in the order of Front/Surr/CLFE/Side */ | ||
446 | hda_nid_t line_out_pins[AUTO_CFG_MAX_OUTS]; | ||
447 | int speaker_outs; | ||
448 | hda_nid_t speaker_pins[AUTO_CFG_MAX_OUTS]; | ||
449 | int hp_outs; | ||
450 | int line_out_type; /* AUTO_PIN_XXX_OUT */ | ||
451 | hda_nid_t hp_pins[AUTO_CFG_MAX_OUTS]; | ||
452 | int num_inputs; | ||
453 | struct auto_pin_cfg_item inputs[AUTO_CFG_MAX_INS]; | ||
454 | int dig_outs; | ||
455 | hda_nid_t dig_out_pins[2]; | ||
456 | hda_nid_t dig_in_pin; | ||
457 | hda_nid_t mono_out_pin; | ||
458 | int dig_out_type[2]; /* HDA_PCM_TYPE_XXX */ | ||
459 | int dig_in_type; /* HDA_PCM_TYPE_XXX */ | ||
460 | }; | ||
461 | |||
462 | #define get_defcfg_connect(cfg) \ | 399 | #define get_defcfg_connect(cfg) \ |
463 | ((cfg & AC_DEFCFG_PORT_CONN) >> AC_DEFCFG_PORT_CONN_SHIFT) | 400 | ((cfg & AC_DEFCFG_PORT_CONN) >> AC_DEFCFG_PORT_CONN_SHIFT) |
464 | #define get_defcfg_association(cfg) \ | 401 | #define get_defcfg_association(cfg) \ |
@@ -472,19 +409,6 @@ struct auto_pin_cfg { | |||
472 | #define get_defcfg_misc(cfg) \ | 409 | #define get_defcfg_misc(cfg) \ |
473 | ((cfg & AC_DEFCFG_MISC) >> AC_DEFCFG_MISC_SHIFT) | 410 | ((cfg & AC_DEFCFG_MISC) >> AC_DEFCFG_MISC_SHIFT) |
474 | 411 | ||
475 | /* bit-flags for snd_hda_parse_pin_def_config() behavior */ | ||
476 | #define HDA_PINCFG_NO_HP_FIXUP (1 << 0) /* no HP-split */ | ||
477 | #define HDA_PINCFG_NO_LO_FIXUP (1 << 1) /* don't take other outs as LO */ | ||
478 | |||
479 | int snd_hda_parse_pin_defcfg(struct hda_codec *codec, | ||
480 | struct auto_pin_cfg *cfg, | ||
481 | const hda_nid_t *ignore_nids, | ||
482 | unsigned int cond_flags); | ||
483 | |||
484 | /* older function */ | ||
485 | #define snd_hda_parse_pin_def_config(codec, cfg, ignore) \ | ||
486 | snd_hda_parse_pin_defcfg(codec, cfg, ignore, 0) | ||
487 | |||
488 | /* amp values */ | 412 | /* amp values */ |
489 | #define AMP_IN_MUTE(idx) (0x7080 | ((idx)<<8)) | 413 | #define AMP_IN_MUTE(idx) (0x7080 | ((idx)<<8)) |
490 | #define AMP_IN_UNMUTE(idx) (0x7000 | ((idx)<<8)) | 414 | #define AMP_IN_UNMUTE(idx) (0x7000 | ((idx)<<8)) |
@@ -502,6 +426,46 @@ int snd_hda_parse_pin_defcfg(struct hda_codec *codec, | |||
502 | #define PIN_HP (AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN) | 426 | #define PIN_HP (AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN) |
503 | #define PIN_HP_AMP (AC_PINCTL_HP_EN) | 427 | #define PIN_HP_AMP (AC_PINCTL_HP_EN) |
504 | 428 | ||
429 | unsigned int snd_hda_get_default_vref(struct hda_codec *codec, hda_nid_t pin); | ||
430 | int _snd_hda_set_pin_ctl(struct hda_codec *codec, hda_nid_t pin, | ||
431 | unsigned int val, bool cached); | ||
432 | |||
433 | /** | ||
434 | * _snd_hda_set_pin_ctl - Set a pin-control value safely | ||
435 | * @codec: the codec instance | ||
436 | * @pin: the pin NID to set the control | ||
437 | * @val: the pin-control value (AC_PINCTL_* bits) | ||
438 | * | ||
439 | * This function sets the pin-control value to the given pin, but | ||
440 | * filters out the invalid pin-control bits when the pin has no such | ||
441 | * capabilities. For example, when PIN_HP is passed but the pin has no | ||
442 | * HP-drive capability, the HP bit is omitted. | ||
443 | * | ||
444 | * The function doesn't check the input VREF capability bits, though. | ||
445 | * Use snd_hda_get_default_vref() to guess the right value. | ||
446 | * Also, this function is only for analog pins, not for HDMI pins. | ||
447 | */ | ||
448 | static inline int | ||
449 | snd_hda_set_pin_ctl(struct hda_codec *codec, hda_nid_t pin, unsigned int val) | ||
450 | { | ||
451 | return _snd_hda_set_pin_ctl(codec, pin, val, false); | ||
452 | } | ||
453 | |||
454 | /** | ||
455 | * snd_hda_set_pin_ctl_cache - Set a pin-control value safely | ||
456 | * @codec: the codec instance | ||
457 | * @pin: the pin NID to set the control | ||
458 | * @val: the pin-control value (AC_PINCTL_* bits) | ||
459 | * | ||
460 | * Just like snd_hda_set_pin_ctl() but write to cache as well. | ||
461 | */ | ||
462 | static inline int | ||
463 | snd_hda_set_pin_ctl_cache(struct hda_codec *codec, hda_nid_t pin, | ||
464 | unsigned int val) | ||
465 | { | ||
466 | return _snd_hda_set_pin_ctl(codec, pin, val, true); | ||
467 | } | ||
468 | |||
505 | /* | 469 | /* |
506 | * get widget capabilities | 470 | * get widget capabilities |
507 | */ | 471 | */ |
diff --git a/sound/pci/hda/patch_analog.c b/sound/pci/hda/patch_analog.c index 7143393927da..d8b2d6dee986 100644 --- a/sound/pci/hda/patch_analog.c +++ b/sound/pci/hda/patch_analog.c | |||
@@ -28,6 +28,7 @@ | |||
28 | #include <sound/core.h> | 28 | #include <sound/core.h> |
29 | #include "hda_codec.h" | 29 | #include "hda_codec.h" |
30 | #include "hda_local.h" | 30 | #include "hda_local.h" |
31 | #include "hda_auto_parser.h" | ||
31 | #include "hda_beep.h" | 32 | #include "hda_beep.h" |
32 | #include "hda_jack.h" | 33 | #include "hda_jack.h" |
33 | 34 | ||
@@ -1742,9 +1743,7 @@ static int ad1981_hp_master_sw_put(struct snd_kcontrol *kcontrol, | |||
1742 | if (! ad198x_eapd_put(kcontrol, ucontrol)) | 1743 | if (! ad198x_eapd_put(kcontrol, ucontrol)) |
1743 | return 0; | 1744 | return 0; |
1744 | /* change speaker pin appropriately */ | 1745 | /* change speaker pin appropriately */ |
1745 | snd_hda_codec_write(codec, 0x05, 0, | 1746 | snd_hda_set_pin_ctl(codec, 0x05, spec->cur_eapd ? PIN_OUT : 0); |
1746 | AC_VERB_SET_PIN_WIDGET_CONTROL, | ||
1747 | spec->cur_eapd ? PIN_OUT : 0); | ||
1748 | /* toggle HP mute appropriately */ | 1747 | /* toggle HP mute appropriately */ |
1749 | snd_hda_codec_amp_stereo(codec, 0x06, HDA_OUTPUT, 0, | 1748 | snd_hda_codec_amp_stereo(codec, 0x06, HDA_OUTPUT, 0, |
1750 | HDA_AMP_MUTE, | 1749 | HDA_AMP_MUTE, |
@@ -3103,7 +3102,7 @@ static void ad1988_auto_set_output_and_unmute(struct hda_codec *codec, | |||
3103 | int dac_idx) | 3102 | int dac_idx) |
3104 | { | 3103 | { |
3105 | /* set as output */ | 3104 | /* set as output */ |
3106 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type); | 3105 | snd_hda_set_pin_ctl(codec, nid, pin_type); |
3107 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE); | 3106 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE); |
3108 | switch (nid) { | 3107 | switch (nid) { |
3109 | case 0x11: /* port-A - DAC 03 */ | 3108 | case 0x11: /* port-A - DAC 03 */ |
@@ -3157,6 +3156,7 @@ static void ad1988_auto_init_analog_input(struct hda_codec *codec) | |||
3157 | for (i = 0; i < cfg->num_inputs; i++) { | 3156 | for (i = 0; i < cfg->num_inputs; i++) { |
3158 | hda_nid_t nid = cfg->inputs[i].pin; | 3157 | hda_nid_t nid = cfg->inputs[i].pin; |
3159 | int type = cfg->inputs[i].type; | 3158 | int type = cfg->inputs[i].type; |
3159 | int val; | ||
3160 | switch (nid) { | 3160 | switch (nid) { |
3161 | case 0x15: /* port-C */ | 3161 | case 0x15: /* port-C */ |
3162 | snd_hda_codec_write(codec, 0x33, 0, AC_VERB_SET_CONNECT_SEL, 0x0); | 3162 | snd_hda_codec_write(codec, 0x33, 0, AC_VERB_SET_CONNECT_SEL, 0x0); |
@@ -3165,8 +3165,10 @@ static void ad1988_auto_init_analog_input(struct hda_codec *codec) | |||
3165 | snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_CONNECT_SEL, 0x0); | 3165 | snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_CONNECT_SEL, 0x0); |
3166 | break; | 3166 | break; |
3167 | } | 3167 | } |
3168 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, | 3168 | val = PIN_IN; |
3169 | type == AUTO_PIN_MIC ? PIN_VREF80 : PIN_IN); | 3169 | if (type == AUTO_PIN_MIC) |
3170 | val |= snd_hda_get_default_vref(codec, nid); | ||
3171 | snd_hda_set_pin_ctl(codec, nid, val); | ||
3170 | if (nid != AD1988_PIN_CD_NID) | 3172 | if (nid != AD1988_PIN_CD_NID) |
3171 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, | 3173 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, |
3172 | AMP_OUT_MUTE); | 3174 | AMP_OUT_MUTE); |
diff --git a/sound/pci/hda/patch_ca0110.c b/sound/pci/hda/patch_ca0110.c index 09ccfabb4a17..19ae14f739cb 100644 --- a/sound/pci/hda/patch_ca0110.c +++ b/sound/pci/hda/patch_ca0110.c | |||
@@ -26,6 +26,7 @@ | |||
26 | #include <sound/core.h> | 26 | #include <sound/core.h> |
27 | #include "hda_codec.h" | 27 | #include "hda_codec.h" |
28 | #include "hda_local.h" | 28 | #include "hda_local.h" |
29 | #include "hda_auto_parser.h" | ||
29 | 30 | ||
30 | /* | 31 | /* |
31 | */ | 32 | */ |
@@ -341,8 +342,7 @@ static int ca0110_build_pcms(struct hda_codec *codec) | |||
341 | static void init_output(struct hda_codec *codec, hda_nid_t pin, hda_nid_t dac) | 342 | static void init_output(struct hda_codec *codec, hda_nid_t pin, hda_nid_t dac) |
342 | { | 343 | { |
343 | if (pin) { | 344 | if (pin) { |
344 | snd_hda_codec_write(codec, pin, 0, | 345 | snd_hda_set_pin_ctl(codec, pin, PIN_HP); |
345 | AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP); | ||
346 | if (get_wcaps(codec, pin) & AC_WCAP_OUT_AMP) | 346 | if (get_wcaps(codec, pin) & AC_WCAP_OUT_AMP) |
347 | snd_hda_codec_write(codec, pin, 0, | 347 | snd_hda_codec_write(codec, pin, 0, |
348 | AC_VERB_SET_AMP_GAIN_MUTE, | 348 | AC_VERB_SET_AMP_GAIN_MUTE, |
@@ -356,8 +356,8 @@ static void init_output(struct hda_codec *codec, hda_nid_t pin, hda_nid_t dac) | |||
356 | static void init_input(struct hda_codec *codec, hda_nid_t pin, hda_nid_t adc) | 356 | static void init_input(struct hda_codec *codec, hda_nid_t pin, hda_nid_t adc) |
357 | { | 357 | { |
358 | if (pin) { | 358 | if (pin) { |
359 | snd_hda_codec_write(codec, pin, 0, | 359 | snd_hda_set_pin_ctl(codec, pin, PIN_IN | |
360 | AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80); | 360 | snd_hda_get_default_vref(codec, pin)); |
361 | if (get_wcaps(codec, pin) & AC_WCAP_IN_AMP) | 361 | if (get_wcaps(codec, pin) & AC_WCAP_IN_AMP) |
362 | snd_hda_codec_write(codec, pin, 0, | 362 | snd_hda_codec_write(codec, pin, 0, |
363 | AC_VERB_SET_AMP_GAIN_MUTE, | 363 | AC_VERB_SET_AMP_GAIN_MUTE, |
diff --git a/sound/pci/hda/patch_ca0132.c b/sound/pci/hda/patch_ca0132.c index 21d91d580da8..d0d3540e39e7 100644 --- a/sound/pci/hda/patch_ca0132.c +++ b/sound/pci/hda/patch_ca0132.c | |||
@@ -30,6 +30,7 @@ | |||
30 | #include <sound/core.h> | 30 | #include <sound/core.h> |
31 | #include "hda_codec.h" | 31 | #include "hda_codec.h" |
32 | #include "hda_local.h" | 32 | #include "hda_local.h" |
33 | #include "hda_auto_parser.h" | ||
33 | 34 | ||
34 | #define WIDGET_CHIP_CTRL 0x15 | 35 | #define WIDGET_CHIP_CTRL 0x15 |
35 | #define WIDGET_DSP_CTRL 0x16 | 36 | #define WIDGET_DSP_CTRL 0x16 |
@@ -239,8 +240,7 @@ enum get_set { | |||
239 | static void init_output(struct hda_codec *codec, hda_nid_t pin, hda_nid_t dac) | 240 | static void init_output(struct hda_codec *codec, hda_nid_t pin, hda_nid_t dac) |
240 | { | 241 | { |
241 | if (pin) { | 242 | if (pin) { |
242 | snd_hda_codec_write(codec, pin, 0, | 243 | snd_hda_set_pin_ctl(codec, pin, PIN_HP); |
243 | AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP); | ||
244 | if (get_wcaps(codec, pin) & AC_WCAP_OUT_AMP) | 244 | if (get_wcaps(codec, pin) & AC_WCAP_OUT_AMP) |
245 | snd_hda_codec_write(codec, pin, 0, | 245 | snd_hda_codec_write(codec, pin, 0, |
246 | AC_VERB_SET_AMP_GAIN_MUTE, | 246 | AC_VERB_SET_AMP_GAIN_MUTE, |
@@ -254,9 +254,8 @@ static void init_output(struct hda_codec *codec, hda_nid_t pin, hda_nid_t dac) | |||
254 | static void init_input(struct hda_codec *codec, hda_nid_t pin, hda_nid_t adc) | 254 | static void init_input(struct hda_codec *codec, hda_nid_t pin, hda_nid_t adc) |
255 | { | 255 | { |
256 | if (pin) { | 256 | if (pin) { |
257 | snd_hda_codec_write(codec, pin, 0, | 257 | snd_hda_set_pin_ctl(codec, pin, PIN_IN | |
258 | AC_VERB_SET_PIN_WIDGET_CONTROL, | 258 | snd_hda_get_default_vref(codec, pin)); |
259 | PIN_VREF80); | ||
260 | if (get_wcaps(codec, pin) & AC_WCAP_IN_AMP) | 259 | if (get_wcaps(codec, pin) & AC_WCAP_IN_AMP) |
261 | snd_hda_codec_write(codec, pin, 0, | 260 | snd_hda_codec_write(codec, pin, 0, |
262 | AC_VERB_SET_AMP_GAIN_MUTE, | 261 | AC_VERB_SET_AMP_GAIN_MUTE, |
diff --git a/sound/pci/hda/patch_cirrus.c b/sound/pci/hda/patch_cirrus.c index c83ccdba1e5a..9647ed4d7929 100644 --- a/sound/pci/hda/patch_cirrus.c +++ b/sound/pci/hda/patch_cirrus.c | |||
@@ -26,6 +26,7 @@ | |||
26 | #include <sound/core.h> | 26 | #include <sound/core.h> |
27 | #include "hda_codec.h" | 27 | #include "hda_codec.h" |
28 | #include "hda_local.h" | 28 | #include "hda_local.h" |
29 | #include "hda_auto_parser.h" | ||
29 | #include "hda_jack.h" | 30 | #include "hda_jack.h" |
30 | #include <sound/tlv.h> | 31 | #include <sound/tlv.h> |
31 | 32 | ||
@@ -933,8 +934,7 @@ static void cs_automute(struct hda_codec *codec) | |||
933 | pin_ctl = 0; | 934 | pin_ctl = 0; |
934 | 935 | ||
935 | nid = cfg->speaker_pins[i]; | 936 | nid = cfg->speaker_pins[i]; |
936 | snd_hda_codec_write(codec, nid, 0, | 937 | snd_hda_set_pin_ctl(codec, nid, pin_ctl); |
937 | AC_VERB_SET_PIN_WIDGET_CONTROL, pin_ctl); | ||
938 | } | 938 | } |
939 | if (spec->gpio_eapd_hp) { | 939 | if (spec->gpio_eapd_hp) { |
940 | unsigned int gpio = hp_present ? | 940 | unsigned int gpio = hp_present ? |
@@ -948,16 +948,14 @@ static void cs_automute(struct hda_codec *codec) | |||
948 | /* mute HPs if spdif jack (SENSE_B) is present */ | 948 | /* mute HPs if spdif jack (SENSE_B) is present */ |
949 | for (i = 0; i < cfg->hp_outs; i++) { | 949 | for (i = 0; i < cfg->hp_outs; i++) { |
950 | nid = cfg->hp_pins[i]; | 950 | nid = cfg->hp_pins[i]; |
951 | snd_hda_codec_write(codec, nid, 0, | 951 | snd_hda_set_pin_ctl(codec, nid, |
952 | AC_VERB_SET_PIN_WIDGET_CONTROL, | ||
953 | (spdif_present && spec->sense_b) ? 0 : PIN_HP); | 952 | (spdif_present && spec->sense_b) ? 0 : PIN_HP); |
954 | } | 953 | } |
955 | 954 | ||
956 | /* SPDIF TX on/off */ | 955 | /* SPDIF TX on/off */ |
957 | if (cfg->dig_outs) { | 956 | if (cfg->dig_outs) { |
958 | nid = cfg->dig_out_pins[0]; | 957 | nid = cfg->dig_out_pins[0]; |
959 | snd_hda_codec_write(codec, nid, 0, | 958 | snd_hda_set_pin_ctl(codec, nid, |
960 | AC_VERB_SET_PIN_WIDGET_CONTROL, | ||
961 | spdif_present ? PIN_OUT : 0); | 959 | spdif_present ? PIN_OUT : 0); |
962 | 960 | ||
963 | } | 961 | } |
@@ -1024,13 +1022,11 @@ static void init_output(struct hda_codec *codec) | |||
1024 | 1022 | ||
1025 | /* set appropriate pin controls */ | 1023 | /* set appropriate pin controls */ |
1026 | for (i = 0; i < cfg->line_outs; i++) | 1024 | for (i = 0; i < cfg->line_outs; i++) |
1027 | snd_hda_codec_write(codec, cfg->line_out_pins[i], 0, | 1025 | snd_hda_set_pin_ctl(codec, cfg->line_out_pins[i], PIN_OUT); |
1028 | AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT); | ||
1029 | /* HP */ | 1026 | /* HP */ |
1030 | for (i = 0; i < cfg->hp_outs; i++) { | 1027 | for (i = 0; i < cfg->hp_outs; i++) { |
1031 | hda_nid_t nid = cfg->hp_pins[i]; | 1028 | hda_nid_t nid = cfg->hp_pins[i]; |
1032 | snd_hda_codec_write(codec, nid, 0, | 1029 | snd_hda_set_pin_ctl(codec, nid, PIN_HP); |
1033 | AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP); | ||
1034 | if (!cfg->speaker_outs) | 1030 | if (!cfg->speaker_outs) |
1035 | continue; | 1031 | continue; |
1036 | if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP) { | 1032 | if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP) { |
@@ -1041,8 +1037,7 @@ static void init_output(struct hda_codec *codec) | |||
1041 | 1037 | ||
1042 | /* Speaker */ | 1038 | /* Speaker */ |
1043 | for (i = 0; i < cfg->speaker_outs; i++) | 1039 | for (i = 0; i < cfg->speaker_outs; i++) |
1044 | snd_hda_codec_write(codec, cfg->speaker_pins[i], 0, | 1040 | snd_hda_set_pin_ctl(codec, cfg->speaker_pins[i], PIN_OUT); |
1045 | AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT); | ||
1046 | 1041 | ||
1047 | /* SPDIF is enabled on presence detect for CS421x */ | 1042 | /* SPDIF is enabled on presence detect for CS421x */ |
1048 | if (spec->hp_detect || spec->spdif_detect) | 1043 | if (spec->hp_detect || spec->spdif_detect) |
@@ -1063,14 +1058,9 @@ static void init_input(struct hda_codec *codec) | |||
1063 | continue; | 1058 | continue; |
1064 | /* set appropriate pin control and mute first */ | 1059 | /* set appropriate pin control and mute first */ |
1065 | ctl = PIN_IN; | 1060 | ctl = PIN_IN; |
1066 | if (cfg->inputs[i].type == AUTO_PIN_MIC) { | 1061 | if (cfg->inputs[i].type == AUTO_PIN_MIC) |
1067 | unsigned int caps = snd_hda_query_pin_caps(codec, pin); | 1062 | ctl |= snd_hda_get_default_vref(codec, pin); |
1068 | caps >>= AC_PINCAP_VREF_SHIFT; | 1063 | snd_hda_set_pin_ctl(codec, pin, ctl); |
1069 | if (caps & AC_PINCAP_VREF_80) | ||
1070 | ctl = PIN_VREF80; | ||
1071 | } | ||
1072 | snd_hda_codec_write(codec, pin, 0, | ||
1073 | AC_VERB_SET_PIN_WIDGET_CONTROL, ctl); | ||
1074 | snd_hda_codec_write(codec, spec->adc_nid[i], 0, | 1064 | snd_hda_codec_write(codec, spec->adc_nid[i], 0, |
1075 | AC_VERB_SET_AMP_GAIN_MUTE, | 1065 | AC_VERB_SET_AMP_GAIN_MUTE, |
1076 | AMP_IN_MUTE(spec->adc_idx[i])); | 1066 | AMP_IN_MUTE(spec->adc_idx[i])); |
diff --git a/sound/pci/hda/patch_cmedia.c b/sound/pci/hda/patch_cmedia.c index b6767b4ced44..c8fdaaefe702 100644 --- a/sound/pci/hda/patch_cmedia.c +++ b/sound/pci/hda/patch_cmedia.c | |||
@@ -29,6 +29,7 @@ | |||
29 | #include <sound/core.h> | 29 | #include <sound/core.h> |
30 | #include "hda_codec.h" | 30 | #include "hda_codec.h" |
31 | #include "hda_local.h" | 31 | #include "hda_local.h" |
32 | #include "hda_auto_parser.h" | ||
32 | #define NUM_PINS 11 | 33 | #define NUM_PINS 11 |
33 | 34 | ||
34 | 35 | ||
diff --git a/sound/pci/hda/patch_conexant.c b/sound/pci/hda/patch_conexant.c index d906c5b74cf0..3acb5824ad39 100644 --- a/sound/pci/hda/patch_conexant.c +++ b/sound/pci/hda/patch_conexant.c | |||
@@ -30,6 +30,7 @@ | |||
30 | 30 | ||
31 | #include "hda_codec.h" | 31 | #include "hda_codec.h" |
32 | #include "hda_local.h" | 32 | #include "hda_local.h" |
33 | #include "hda_auto_parser.h" | ||
33 | #include "hda_beep.h" | 34 | #include "hda_beep.h" |
34 | #include "hda_jack.h" | 35 | #include "hda_jack.h" |
35 | 36 | ||
@@ -66,6 +67,7 @@ struct imux_info { | |||
66 | }; | 67 | }; |
67 | 68 | ||
68 | struct conexant_spec { | 69 | struct conexant_spec { |
70 | struct hda_gen_spec gen; | ||
69 | 71 | ||
70 | const struct snd_kcontrol_new *mixers[5]; | 72 | const struct snd_kcontrol_new *mixers[5]; |
71 | int num_mixers; | 73 | int num_mixers; |
@@ -141,6 +143,7 @@ struct conexant_spec { | |||
141 | unsigned int hp_laptop:1; | 143 | unsigned int hp_laptop:1; |
142 | unsigned int asus:1; | 144 | unsigned int asus:1; |
143 | unsigned int pin_eapd_ctrls:1; | 145 | unsigned int pin_eapd_ctrls:1; |
146 | unsigned int fixup_stereo_dmic:1; | ||
144 | 147 | ||
145 | unsigned int adc_switching:1; | 148 | unsigned int adc_switching:1; |
146 | 149 | ||
@@ -1601,17 +1604,13 @@ static void cxt5051_update_speaker(struct hda_codec *codec) | |||
1601 | unsigned int pinctl; | 1604 | unsigned int pinctl; |
1602 | /* headphone pin */ | 1605 | /* headphone pin */ |
1603 | pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0; | 1606 | pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0; |
1604 | snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, | 1607 | snd_hda_set_pin_ctl(codec, 0x16, pinctl); |
1605 | pinctl); | ||
1606 | /* speaker pin */ | 1608 | /* speaker pin */ |
1607 | pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0; | 1609 | pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0; |
1608 | snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, | 1610 | snd_hda_set_pin_ctl(codec, 0x1a, pinctl); |
1609 | pinctl); | ||
1610 | /* on ideapad there is an additional speaker (subwoofer) to mute */ | 1611 | /* on ideapad there is an additional speaker (subwoofer) to mute */ |
1611 | if (spec->ideapad) | 1612 | if (spec->ideapad) |
1612 | snd_hda_codec_write(codec, 0x1b, 0, | 1613 | snd_hda_set_pin_ctl(codec, 0x1b, pinctl); |
1613 | AC_VERB_SET_PIN_WIDGET_CONTROL, | ||
1614 | pinctl); | ||
1615 | } | 1614 | } |
1616 | 1615 | ||
1617 | /* turn on/off EAPD (+ mute HP) as a master switch */ | 1616 | /* turn on/off EAPD (+ mute HP) as a master switch */ |
@@ -1996,8 +1995,7 @@ static void cxt5066_update_speaker(struct hda_codec *codec) | |||
1996 | 1995 | ||
1997 | /* Port A (HP) */ | 1996 | /* Port A (HP) */ |
1998 | pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0; | 1997 | pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0; |
1999 | snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, | 1998 | snd_hda_set_pin_ctl(codec, 0x19, pinctl); |
2000 | pinctl); | ||
2001 | 1999 | ||
2002 | /* Port D (HP/LO) */ | 2000 | /* Port D (HP/LO) */ |
2003 | pinctl = spec->cur_eapd ? spec->port_d_mode : 0; | 2001 | pinctl = spec->cur_eapd ? spec->port_d_mode : 0; |
@@ -2010,13 +2008,11 @@ static void cxt5066_update_speaker(struct hda_codec *codec) | |||
2010 | if (!hp_port_d_present(spec)) | 2008 | if (!hp_port_d_present(spec)) |
2011 | pinctl = 0; | 2009 | pinctl = 0; |
2012 | } | 2010 | } |
2013 | snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, | 2011 | snd_hda_set_pin_ctl(codec, 0x1c, pinctl); |
2014 | pinctl); | ||
2015 | 2012 | ||
2016 | /* CLASS_D AMP */ | 2013 | /* CLASS_D AMP */ |
2017 | pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0; | 2014 | pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0; |
2018 | snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, | 2015 | snd_hda_set_pin_ctl(codec, 0x1f, pinctl); |
2019 | pinctl); | ||
2020 | } | 2016 | } |
2021 | 2017 | ||
2022 | /* turn on/off EAPD (+ mute HP) as a master switch */ | 2018 | /* turn on/off EAPD (+ mute HP) as a master switch */ |
@@ -2047,8 +2043,7 @@ static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec) | |||
2047 | /* Even though port F is the DC input, the bias is controlled on port B. | 2043 | /* Even though port F is the DC input, the bias is controlled on port B. |
2048 | * we also leave that port as an active input (but unselected) in DC mode | 2044 | * we also leave that port as an active input (but unselected) in DC mode |
2049 | * just in case that is necessary to make the bias setting take effect. */ | 2045 | * just in case that is necessary to make the bias setting take effect. */ |
2050 | return snd_hda_codec_write_cache(codec, 0x1a, 0, | 2046 | return snd_hda_set_pin_ctl_cache(codec, 0x1a, |
2051 | AC_VERB_SET_PIN_WIDGET_CONTROL, | ||
2052 | cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index); | 2047 | cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index); |
2053 | } | 2048 | } |
2054 | 2049 | ||
@@ -2081,14 +2076,14 @@ static void cxt5066_olpc_select_mic(struct hda_codec *codec) | |||
2081 | } | 2076 | } |
2082 | 2077 | ||
2083 | /* disable DC (port F) */ | 2078 | /* disable DC (port F) */ |
2084 | snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0); | 2079 | snd_hda_set_pin_ctl(codec, 0x1e, 0); |
2085 | 2080 | ||
2086 | /* external mic, port B */ | 2081 | /* external mic, port B */ |
2087 | snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, | 2082 | snd_hda_set_pin_ctl(codec, 0x1a, |
2088 | spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0); | 2083 | spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0); |
2089 | 2084 | ||
2090 | /* internal mic, port C */ | 2085 | /* internal mic, port C */ |
2091 | snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, | 2086 | snd_hda_set_pin_ctl(codec, 0x1b, |
2092 | spec->ext_mic_present ? 0 : PIN_VREF80); | 2087 | spec->ext_mic_present ? 0 : PIN_VREF80); |
2093 | } | 2088 | } |
2094 | 2089 | ||
@@ -3357,9 +3352,7 @@ static void do_automute(struct hda_codec *codec, int num_pins, | |||
3357 | struct conexant_spec *spec = codec->spec; | 3352 | struct conexant_spec *spec = codec->spec; |
3358 | int i; | 3353 | int i; |
3359 | for (i = 0; i < num_pins; i++) | 3354 | for (i = 0; i < num_pins; i++) |
3360 | snd_hda_codec_write(codec, pins[i], 0, | 3355 | snd_hda_set_pin_ctl(codec, pins[i], on ? PIN_OUT : 0); |
3361 | AC_VERB_SET_PIN_WIDGET_CONTROL, | ||
3362 | on ? PIN_OUT : 0); | ||
3363 | if (spec->pin_eapd_ctrls) | 3356 | if (spec->pin_eapd_ctrls) |
3364 | cx_auto_turn_eapd(codec, num_pins, pins, on); | 3357 | cx_auto_turn_eapd(codec, num_pins, pins, on); |
3365 | } | 3358 | } |
@@ -3976,8 +3969,7 @@ static void cx_auto_init_output(struct hda_codec *codec) | |||
3976 | if (snd_hda_query_pin_caps(codec, cfg->hp_pins[i]) & | 3969 | if (snd_hda_query_pin_caps(codec, cfg->hp_pins[i]) & |
3977 | AC_PINCAP_HP_DRV) | 3970 | AC_PINCAP_HP_DRV) |
3978 | val |= AC_PINCTL_HP_EN; | 3971 | val |= AC_PINCTL_HP_EN; |
3979 | snd_hda_codec_write(codec, cfg->hp_pins[i], 0, | 3972 | snd_hda_set_pin_ctl(codec, cfg->hp_pins[i], val); |
3980 | AC_VERB_SET_PIN_WIDGET_CONTROL, val); | ||
3981 | } | 3973 | } |
3982 | mute_outputs(codec, cfg->hp_outs, cfg->hp_pins); | 3974 | mute_outputs(codec, cfg->hp_outs, cfg->hp_pins); |
3983 | mute_outputs(codec, cfg->line_outs, cfg->line_out_pins); | 3975 | mute_outputs(codec, cfg->line_outs, cfg->line_out_pins); |
@@ -4030,13 +4022,11 @@ static void cx_auto_init_input(struct hda_codec *codec) | |||
4030 | } | 4022 | } |
4031 | 4023 | ||
4032 | for (i = 0; i < cfg->num_inputs; i++) { | 4024 | for (i = 0; i < cfg->num_inputs; i++) { |
4033 | unsigned int type; | 4025 | hda_nid_t pin = cfg->inputs[i].pin; |
4026 | unsigned int type = PIN_IN; | ||
4034 | if (cfg->inputs[i].type == AUTO_PIN_MIC) | 4027 | if (cfg->inputs[i].type == AUTO_PIN_MIC) |
4035 | type = PIN_VREF80; | 4028 | type |= snd_hda_get_default_vref(codec, pin); |
4036 | else | 4029 | snd_hda_set_pin_ctl(codec, pin, type); |
4037 | type = PIN_IN; | ||
4038 | snd_hda_codec_write(codec, cfg->inputs[i].pin, 0, | ||
4039 | AC_VERB_SET_PIN_WIDGET_CONTROL, type); | ||
4040 | } | 4030 | } |
4041 | 4031 | ||
4042 | if (spec->auto_mic) { | 4032 | if (spec->auto_mic) { |
@@ -4063,11 +4053,9 @@ static void cx_auto_init_digital(struct hda_codec *codec) | |||
4063 | struct auto_pin_cfg *cfg = &spec->autocfg; | 4053 | struct auto_pin_cfg *cfg = &spec->autocfg; |
4064 | 4054 | ||
4065 | if (spec->multiout.dig_out_nid) | 4055 | if (spec->multiout.dig_out_nid) |
4066 | snd_hda_codec_write(codec, cfg->dig_out_pins[0], 0, | 4056 | snd_hda_set_pin_ctl(codec, cfg->dig_out_pins[0], PIN_OUT); |
4067 | AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT); | ||
4068 | if (spec->dig_in_nid) | 4057 | if (spec->dig_in_nid) |
4069 | snd_hda_codec_write(codec, cfg->dig_in_pin, 0, | 4058 | snd_hda_set_pin_ctl(codec, cfg->dig_in_pin, PIN_IN); |
4070 | AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN); | ||
4071 | } | 4059 | } |
4072 | 4060 | ||
4073 | static int cx_auto_init(struct hda_codec *codec) | 4061 | static int cx_auto_init(struct hda_codec *codec) |
@@ -4084,9 +4072,9 @@ static int cx_auto_init(struct hda_codec *codec) | |||
4084 | 4072 | ||
4085 | static int cx_auto_add_volume_idx(struct hda_codec *codec, const char *basename, | 4073 | static int cx_auto_add_volume_idx(struct hda_codec *codec, const char *basename, |
4086 | const char *dir, int cidx, | 4074 | const char *dir, int cidx, |
4087 | hda_nid_t nid, int hda_dir, int amp_idx) | 4075 | hda_nid_t nid, int hda_dir, int amp_idx, int chs) |
4088 | { | 4076 | { |
4089 | static char name[32]; | 4077 | static char name[44]; |
4090 | static struct snd_kcontrol_new knew[] = { | 4078 | static struct snd_kcontrol_new knew[] = { |
4091 | HDA_CODEC_VOLUME(name, 0, 0, 0), | 4079 | HDA_CODEC_VOLUME(name, 0, 0, 0), |
4092 | HDA_CODEC_MUTE(name, 0, 0, 0), | 4080 | HDA_CODEC_MUTE(name, 0, 0, 0), |
@@ -4096,7 +4084,7 @@ static int cx_auto_add_volume_idx(struct hda_codec *codec, const char *basename, | |||
4096 | 4084 | ||
4097 | for (i = 0; i < 2; i++) { | 4085 | for (i = 0; i < 2; i++) { |
4098 | struct snd_kcontrol *kctl; | 4086 | struct snd_kcontrol *kctl; |
4099 | knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, 3, amp_idx, | 4087 | knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, chs, amp_idx, |
4100 | hda_dir); | 4088 | hda_dir); |
4101 | knew[i].subdevice = HDA_SUBDEV_AMP_FLAG; | 4089 | knew[i].subdevice = HDA_SUBDEV_AMP_FLAG; |
4102 | knew[i].index = cidx; | 4090 | knew[i].index = cidx; |
@@ -4115,7 +4103,7 @@ static int cx_auto_add_volume_idx(struct hda_codec *codec, const char *basename, | |||
4115 | } | 4103 | } |
4116 | 4104 | ||
4117 | #define cx_auto_add_volume(codec, str, dir, cidx, nid, hda_dir) \ | 4105 | #define cx_auto_add_volume(codec, str, dir, cidx, nid, hda_dir) \ |
4118 | cx_auto_add_volume_idx(codec, str, dir, cidx, nid, hda_dir, 0) | 4106 | cx_auto_add_volume_idx(codec, str, dir, cidx, nid, hda_dir, 0, 3) |
4119 | 4107 | ||
4120 | #define cx_auto_add_pb_volume(codec, nid, str, idx) \ | 4108 | #define cx_auto_add_pb_volume(codec, nid, str, idx) \ |
4121 | cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT) | 4109 | cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT) |
@@ -4185,6 +4173,36 @@ static int cx_auto_build_output_controls(struct hda_codec *codec) | |||
4185 | return 0; | 4173 | return 0; |
4186 | } | 4174 | } |
4187 | 4175 | ||
4176 | /* Returns zero if this is a normal stereo channel, and non-zero if it should | ||
4177 | be split in two independent channels. | ||
4178 | dest_label must be at least 44 characters. */ | ||
4179 | static int cx_auto_get_rightch_label(struct hda_codec *codec, const char *label, | ||
4180 | char *dest_label, int nid) | ||
4181 | { | ||
4182 | struct conexant_spec *spec = codec->spec; | ||
4183 | int i; | ||
4184 | |||
4185 | if (!spec->fixup_stereo_dmic) | ||
4186 | return 0; | ||
4187 | |||
4188 | for (i = 0; i < AUTO_CFG_MAX_INS; i++) { | ||
4189 | int def_conf; | ||
4190 | if (spec->autocfg.inputs[i].pin != nid) | ||
4191 | continue; | ||
4192 | |||
4193 | if (spec->autocfg.inputs[i].type != AUTO_PIN_MIC) | ||
4194 | return 0; | ||
4195 | def_conf = snd_hda_codec_get_pincfg(codec, nid); | ||
4196 | if (snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT) | ||
4197 | return 0; | ||
4198 | |||
4199 | /* Finally found the inverted internal mic! */ | ||
4200 | snprintf(dest_label, 44, "Inverted %s", label); | ||
4201 | return 1; | ||
4202 | } | ||
4203 | return 0; | ||
4204 | } | ||
4205 | |||
4188 | static int cx_auto_add_capture_volume(struct hda_codec *codec, hda_nid_t nid, | 4206 | static int cx_auto_add_capture_volume(struct hda_codec *codec, hda_nid_t nid, |
4189 | const char *label, const char *pfx, | 4207 | const char *label, const char *pfx, |
4190 | int cidx) | 4208 | int cidx) |
@@ -4193,14 +4211,25 @@ static int cx_auto_add_capture_volume(struct hda_codec *codec, hda_nid_t nid, | |||
4193 | int i; | 4211 | int i; |
4194 | 4212 | ||
4195 | for (i = 0; i < spec->num_adc_nids; i++) { | 4213 | for (i = 0; i < spec->num_adc_nids; i++) { |
4214 | char rightch_label[44]; | ||
4196 | hda_nid_t adc_nid = spec->adc_nids[i]; | 4215 | hda_nid_t adc_nid = spec->adc_nids[i]; |
4197 | int idx = get_input_connection(codec, adc_nid, nid); | 4216 | int idx = get_input_connection(codec, adc_nid, nid); |
4198 | if (idx < 0) | 4217 | if (idx < 0) |
4199 | continue; | 4218 | continue; |
4200 | if (codec->single_adc_amp) | 4219 | if (codec->single_adc_amp) |
4201 | idx = 0; | 4220 | idx = 0; |
4221 | |||
4222 | if (cx_auto_get_rightch_label(codec, label, rightch_label, nid)) { | ||
4223 | /* Make two independent kcontrols for left and right */ | ||
4224 | int err = cx_auto_add_volume_idx(codec, label, pfx, | ||
4225 | cidx, adc_nid, HDA_INPUT, idx, 1); | ||
4226 | if (err < 0) | ||
4227 | return err; | ||
4228 | return cx_auto_add_volume_idx(codec, rightch_label, pfx, | ||
4229 | cidx, adc_nid, HDA_INPUT, idx, 2); | ||
4230 | } | ||
4202 | return cx_auto_add_volume_idx(codec, label, pfx, | 4231 | return cx_auto_add_volume_idx(codec, label, pfx, |
4203 | cidx, adc_nid, HDA_INPUT, idx); | 4232 | cidx, adc_nid, HDA_INPUT, idx, 3); |
4204 | } | 4233 | } |
4205 | return 0; | 4234 | return 0; |
4206 | } | 4235 | } |
@@ -4213,9 +4242,19 @@ static int cx_auto_add_boost_volume(struct hda_codec *codec, int idx, | |||
4213 | int i, con; | 4242 | int i, con; |
4214 | 4243 | ||
4215 | nid = spec->imux_info[idx].pin; | 4244 | nid = spec->imux_info[idx].pin; |
4216 | if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) | 4245 | if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) { |
4246 | char rightch_label[44]; | ||
4247 | if (cx_auto_get_rightch_label(codec, label, rightch_label, nid)) { | ||
4248 | int err = cx_auto_add_volume_idx(codec, label, " Boost", | ||
4249 | cidx, nid, HDA_INPUT, 0, 1); | ||
4250 | if (err < 0) | ||
4251 | return err; | ||
4252 | return cx_auto_add_volume_idx(codec, rightch_label, " Boost", | ||
4253 | cidx, nid, HDA_INPUT, 0, 2); | ||
4254 | } | ||
4217 | return cx_auto_add_volume(codec, label, " Boost", cidx, | 4255 | return cx_auto_add_volume(codec, label, " Boost", cidx, |
4218 | nid, HDA_INPUT); | 4256 | nid, HDA_INPUT); |
4257 | } | ||
4219 | con = __select_input_connection(codec, spec->imux_info[idx].adc, nid, | 4258 | con = __select_input_connection(codec, spec->imux_info[idx].adc, nid, |
4220 | &mux, false, 0); | 4259 | &mux, false, 0); |
4221 | if (con < 0) | 4260 | if (con < 0) |
@@ -4370,37 +4409,21 @@ static const struct hda_codec_ops cx_auto_patch_ops = { | |||
4370 | /* | 4409 | /* |
4371 | * pin fix-up | 4410 | * pin fix-up |
4372 | */ | 4411 | */ |
4373 | struct cxt_pincfg { | ||
4374 | hda_nid_t nid; | ||
4375 | u32 val; | ||
4376 | }; | ||
4377 | |||
4378 | static void apply_pincfg(struct hda_codec *codec, const struct cxt_pincfg *cfg) | ||
4379 | { | ||
4380 | for (; cfg->nid; cfg++) | ||
4381 | snd_hda_codec_set_pincfg(codec, cfg->nid, cfg->val); | ||
4382 | |||
4383 | } | ||
4384 | |||
4385 | static void apply_pin_fixup(struct hda_codec *codec, | ||
4386 | const struct snd_pci_quirk *quirk, | ||
4387 | const struct cxt_pincfg **table) | ||
4388 | { | ||
4389 | quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk); | ||
4390 | if (quirk) { | ||
4391 | snd_printdd(KERN_INFO "hda_codec: applying pincfg for %s\n", | ||
4392 | quirk->name); | ||
4393 | apply_pincfg(codec, table[quirk->value]); | ||
4394 | } | ||
4395 | } | ||
4396 | |||
4397 | enum { | 4412 | enum { |
4398 | CXT_PINCFG_LENOVO_X200, | 4413 | CXT_PINCFG_LENOVO_X200, |
4399 | CXT_PINCFG_LENOVO_TP410, | 4414 | CXT_PINCFG_LENOVO_TP410, |
4415 | CXT_FIXUP_STEREO_DMIC, | ||
4400 | }; | 4416 | }; |
4401 | 4417 | ||
4418 | static void cxt_fixup_stereo_dmic(struct hda_codec *codec, | ||
4419 | const struct hda_fixup *fix, int action) | ||
4420 | { | ||
4421 | struct conexant_spec *spec = codec->spec; | ||
4422 | spec->fixup_stereo_dmic = 1; | ||
4423 | } | ||
4424 | |||
4402 | /* ThinkPad X200 & co with cxt5051 */ | 4425 | /* ThinkPad X200 & co with cxt5051 */ |
4403 | static const struct cxt_pincfg cxt_pincfg_lenovo_x200[] = { | 4426 | static const struct hda_pintbl cxt_pincfg_lenovo_x200[] = { |
4404 | { 0x16, 0x042140ff }, /* HP (seq# overridden) */ | 4427 | { 0x16, 0x042140ff }, /* HP (seq# overridden) */ |
4405 | { 0x17, 0x21a11000 }, /* dock-mic */ | 4428 | { 0x17, 0x21a11000 }, /* dock-mic */ |
4406 | { 0x19, 0x2121103f }, /* dock-HP */ | 4429 | { 0x19, 0x2121103f }, /* dock-HP */ |
@@ -4409,16 +4432,26 @@ static const struct cxt_pincfg cxt_pincfg_lenovo_x200[] = { | |||
4409 | }; | 4432 | }; |
4410 | 4433 | ||
4411 | /* ThinkPad 410/420/510/520, X201 & co with cxt5066 */ | 4434 | /* ThinkPad 410/420/510/520, X201 & co with cxt5066 */ |
4412 | static const struct cxt_pincfg cxt_pincfg_lenovo_tp410[] = { | 4435 | static const struct hda_pintbl cxt_pincfg_lenovo_tp410[] = { |
4413 | { 0x19, 0x042110ff }, /* HP (seq# overridden) */ | 4436 | { 0x19, 0x042110ff }, /* HP (seq# overridden) */ |
4414 | { 0x1a, 0x21a190f0 }, /* dock-mic */ | 4437 | { 0x1a, 0x21a190f0 }, /* dock-mic */ |
4415 | { 0x1c, 0x212140ff }, /* dock-HP */ | 4438 | { 0x1c, 0x212140ff }, /* dock-HP */ |
4416 | {} | 4439 | {} |
4417 | }; | 4440 | }; |
4418 | 4441 | ||
4419 | static const struct cxt_pincfg *cxt_pincfg_tbl[] = { | 4442 | static const struct hda_fixup cxt_fixups[] = { |
4420 | [CXT_PINCFG_LENOVO_X200] = cxt_pincfg_lenovo_x200, | 4443 | [CXT_PINCFG_LENOVO_X200] = { |
4421 | [CXT_PINCFG_LENOVO_TP410] = cxt_pincfg_lenovo_tp410, | 4444 | .type = HDA_FIXUP_PINS, |
4445 | .v.pins = cxt_pincfg_lenovo_x200, | ||
4446 | }, | ||
4447 | [CXT_PINCFG_LENOVO_TP410] = { | ||
4448 | .type = HDA_FIXUP_PINS, | ||
4449 | .v.pins = cxt_pincfg_lenovo_tp410, | ||
4450 | }, | ||
4451 | [CXT_FIXUP_STEREO_DMIC] = { | ||
4452 | .type = HDA_FIXUP_FUNC, | ||
4453 | .v.func = cxt_fixup_stereo_dmic, | ||
4454 | }, | ||
4422 | }; | 4455 | }; |
4423 | 4456 | ||
4424 | static const struct snd_pci_quirk cxt5051_fixups[] = { | 4457 | static const struct snd_pci_quirk cxt5051_fixups[] = { |
@@ -4432,6 +4465,7 @@ static const struct snd_pci_quirk cxt5066_fixups[] = { | |||
4432 | SND_PCI_QUIRK(0x17aa, 0x215f, "Lenovo T510", CXT_PINCFG_LENOVO_TP410), | 4465 | SND_PCI_QUIRK(0x17aa, 0x215f, "Lenovo T510", CXT_PINCFG_LENOVO_TP410), |
4433 | SND_PCI_QUIRK(0x17aa, 0x21ce, "Lenovo T420", CXT_PINCFG_LENOVO_TP410), | 4466 | SND_PCI_QUIRK(0x17aa, 0x21ce, "Lenovo T420", CXT_PINCFG_LENOVO_TP410), |
4434 | SND_PCI_QUIRK(0x17aa, 0x21cf, "Lenovo T520", CXT_PINCFG_LENOVO_TP410), | 4467 | SND_PCI_QUIRK(0x17aa, 0x21cf, "Lenovo T520", CXT_PINCFG_LENOVO_TP410), |
4468 | SND_PCI_QUIRK(0x17aa, 0x3975, "Lenovo U300s", CXT_FIXUP_STEREO_DMIC), | ||
4435 | {} | 4469 | {} |
4436 | }; | 4470 | }; |
4437 | 4471 | ||
@@ -4471,13 +4505,16 @@ static int patch_conexant_auto(struct hda_codec *codec) | |||
4471 | case 0x14f15051: | 4505 | case 0x14f15051: |
4472 | add_cx5051_fake_mutes(codec); | 4506 | add_cx5051_fake_mutes(codec); |
4473 | codec->pin_amp_workaround = 1; | 4507 | codec->pin_amp_workaround = 1; |
4474 | apply_pin_fixup(codec, cxt5051_fixups, cxt_pincfg_tbl); | 4508 | snd_hda_pick_fixup(codec, NULL, cxt5051_fixups, cxt_fixups); |
4475 | break; | 4509 | break; |
4476 | default: | 4510 | default: |
4477 | codec->pin_amp_workaround = 1; | 4511 | codec->pin_amp_workaround = 1; |
4478 | apply_pin_fixup(codec, cxt5066_fixups, cxt_pincfg_tbl); | 4512 | snd_hda_pick_fixup(codec, NULL, cxt5066_fixups, cxt_fixups); |
4513 | break; | ||
4479 | } | 4514 | } |
4480 | 4515 | ||
4516 | snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE); | ||
4517 | |||
4481 | /* Show mute-led control only on HP laptops | 4518 | /* Show mute-led control only on HP laptops |
4482 | * This is a sort of white-list: on HP laptops, EAPD corresponds | 4519 | * This is a sort of white-list: on HP laptops, EAPD corresponds |
4483 | * only to the mute-LED without actualy amp function. Meanwhile, | 4520 | * only to the mute-LED without actualy amp function. Meanwhile, |
@@ -4556,6 +4593,12 @@ static const struct hda_codec_preset snd_hda_preset_conexant[] = { | |||
4556 | .patch = patch_conexant_auto }, | 4593 | .patch = patch_conexant_auto }, |
4557 | { .id = 0x14f150b9, .name = "CX20665", | 4594 | { .id = 0x14f150b9, .name = "CX20665", |
4558 | .patch = patch_conexant_auto }, | 4595 | .patch = patch_conexant_auto }, |
4596 | { .id = 0x14f1510f, .name = "CX20751/2", | ||
4597 | .patch = patch_conexant_auto }, | ||
4598 | { .id = 0x14f15110, .name = "CX20751/2", | ||
4599 | .patch = patch_conexant_auto }, | ||
4600 | { .id = 0x14f15111, .name = "CX20753/4", | ||
4601 | .patch = patch_conexant_auto }, | ||
4559 | {} /* terminator */ | 4602 | {} /* terminator */ |
4560 | }; | 4603 | }; |
4561 | 4604 | ||
@@ -4576,6 +4619,9 @@ MODULE_ALIAS("snd-hda-codec-id:14f150ab"); | |||
4576 | MODULE_ALIAS("snd-hda-codec-id:14f150ac"); | 4619 | MODULE_ALIAS("snd-hda-codec-id:14f150ac"); |
4577 | MODULE_ALIAS("snd-hda-codec-id:14f150b8"); | 4620 | MODULE_ALIAS("snd-hda-codec-id:14f150b8"); |
4578 | MODULE_ALIAS("snd-hda-codec-id:14f150b9"); | 4621 | MODULE_ALIAS("snd-hda-codec-id:14f150b9"); |
4622 | MODULE_ALIAS("snd-hda-codec-id:14f1510f"); | ||
4623 | MODULE_ALIAS("snd-hda-codec-id:14f15110"); | ||
4624 | MODULE_ALIAS("snd-hda-codec-id:14f15111"); | ||
4579 | 4625 | ||
4580 | MODULE_LICENSE("GPL"); | 4626 | MODULE_LICENSE("GPL"); |
4581 | MODULE_DESCRIPTION("Conexant HD-audio codec"); | 4627 | MODULE_DESCRIPTION("Conexant HD-audio codec"); |
diff --git a/sound/pci/hda/patch_hdmi.c b/sound/pci/hda/patch_hdmi.c index 83f345f3c961..ad319d4dc32f 100644 --- a/sound/pci/hda/patch_hdmi.c +++ b/sound/pci/hda/patch_hdmi.c | |||
@@ -1592,10 +1592,10 @@ static int nvhdmi_8ch_7x_pcm_prepare(struct hda_pcm_stream *hinfo, | |||
1592 | unsigned int dataDCC2, channel_id; | 1592 | unsigned int dataDCC2, channel_id; |
1593 | int i; | 1593 | int i; |
1594 | struct hdmi_spec *spec = codec->spec; | 1594 | struct hdmi_spec *spec = codec->spec; |
1595 | struct hda_spdif_out *spdif = | 1595 | struct hda_spdif_out *spdif; |
1596 | snd_hda_spdif_out_of_nid(codec, spec->cvts[0].cvt_nid); | ||
1597 | 1596 | ||
1598 | mutex_lock(&codec->spdif_mutex); | 1597 | mutex_lock(&codec->spdif_mutex); |
1598 | spdif = snd_hda_spdif_out_of_nid(codec, spec->cvts[0].cvt_nid); | ||
1599 | 1599 | ||
1600 | chs = substream->runtime->channels; | 1600 | chs = substream->runtime->channels; |
1601 | 1601 | ||
diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c index 708d47c294ee..ff71dcef08ef 100644 --- a/sound/pci/hda/patch_realtek.c +++ b/sound/pci/hda/patch_realtek.c | |||
@@ -32,6 +32,7 @@ | |||
32 | #include <sound/jack.h> | 32 | #include <sound/jack.h> |
33 | #include "hda_codec.h" | 33 | #include "hda_codec.h" |
34 | #include "hda_local.h" | 34 | #include "hda_local.h" |
35 | #include "hda_auto_parser.h" | ||
35 | #include "hda_beep.h" | 36 | #include "hda_beep.h" |
36 | #include "hda_jack.h" | 37 | #include "hda_jack.h" |
37 | 38 | ||
@@ -66,8 +67,6 @@ struct alc_customize_define { | |||
66 | unsigned int fixup:1; /* Means that this sku is set by driver, not read from hw */ | 67 | unsigned int fixup:1; /* Means that this sku is set by driver, not read from hw */ |
67 | }; | 68 | }; |
68 | 69 | ||
69 | struct alc_fixup; | ||
70 | |||
71 | struct alc_multi_io { | 70 | struct alc_multi_io { |
72 | hda_nid_t pin; /* multi-io widget pin NID */ | 71 | hda_nid_t pin; /* multi-io widget pin NID */ |
73 | hda_nid_t dac; /* DAC to be connected */ | 72 | hda_nid_t dac; /* DAC to be connected */ |
@@ -82,19 +81,33 @@ enum { | |||
82 | 81 | ||
83 | #define MAX_VOL_NIDS 0x40 | 82 | #define MAX_VOL_NIDS 0x40 |
84 | 83 | ||
84 | /* make compatible with old code */ | ||
85 | #define alc_apply_pincfgs snd_hda_apply_pincfgs | ||
86 | #define alc_apply_fixup snd_hda_apply_fixup | ||
87 | #define alc_pick_fixup snd_hda_pick_fixup | ||
88 | #define alc_fixup hda_fixup | ||
89 | #define alc_pincfg hda_pintbl | ||
90 | #define alc_model_fixup hda_model_fixup | ||
91 | |||
92 | #define ALC_FIXUP_PINS HDA_FIXUP_PINS | ||
93 | #define ALC_FIXUP_VERBS HDA_FIXUP_VERBS | ||
94 | #define ALC_FIXUP_FUNC HDA_FIXUP_FUNC | ||
95 | |||
96 | #define ALC_FIXUP_ACT_PRE_PROBE HDA_FIXUP_ACT_PRE_PROBE | ||
97 | #define ALC_FIXUP_ACT_PROBE HDA_FIXUP_ACT_PROBE | ||
98 | #define ALC_FIXUP_ACT_INIT HDA_FIXUP_ACT_INIT | ||
99 | #define ALC_FIXUP_ACT_BUILD HDA_FIXUP_ACT_BUILD | ||
100 | |||
101 | |||
85 | struct alc_spec { | 102 | struct alc_spec { |
103 | struct hda_gen_spec gen; | ||
104 | |||
86 | /* codec parameterization */ | 105 | /* codec parameterization */ |
87 | const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */ | 106 | const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */ |
88 | unsigned int num_mixers; | 107 | unsigned int num_mixers; |
89 | const struct snd_kcontrol_new *cap_mixer; /* capture mixer */ | 108 | const struct snd_kcontrol_new *cap_mixer; /* capture mixer */ |
90 | unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */ | 109 | unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */ |
91 | 110 | ||
92 | const struct hda_verb *init_verbs[10]; /* initialization verbs | ||
93 | * don't forget NULL | ||
94 | * termination! | ||
95 | */ | ||
96 | unsigned int num_init_verbs; | ||
97 | |||
98 | char stream_name_analog[32]; /* analog PCM stream */ | 111 | char stream_name_analog[32]; /* analog PCM stream */ |
99 | const struct hda_pcm_stream *stream_analog_playback; | 112 | const struct hda_pcm_stream *stream_analog_playback; |
100 | const struct hda_pcm_stream *stream_analog_capture; | 113 | const struct hda_pcm_stream *stream_analog_capture; |
@@ -210,11 +223,6 @@ struct alc_spec { | |||
210 | unsigned int pll_coef_idx, pll_coef_bit; | 223 | unsigned int pll_coef_idx, pll_coef_bit; |
211 | unsigned int coef0; | 224 | unsigned int coef0; |
212 | 225 | ||
213 | /* fix-up list */ | ||
214 | int fixup_id; | ||
215 | const struct alc_fixup *fixup_list; | ||
216 | const char *fixup_name; | ||
217 | |||
218 | /* multi-io */ | 226 | /* multi-io */ |
219 | int multi_ios; | 227 | int multi_ios; |
220 | struct alc_multi_io multi_io[4]; | 228 | struct alc_multi_io multi_io[4]; |
@@ -319,13 +327,16 @@ static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx, | |||
319 | 327 | ||
320 | /* for shared I/O, change the pin-control accordingly */ | 328 | /* for shared I/O, change the pin-control accordingly */ |
321 | if (spec->shared_mic_hp) { | 329 | if (spec->shared_mic_hp) { |
330 | unsigned int val; | ||
331 | hda_nid_t pin = spec->autocfg.inputs[1].pin; | ||
322 | /* NOTE: this assumes that there are only two inputs, the | 332 | /* NOTE: this assumes that there are only two inputs, the |
323 | * first is the real internal mic and the second is HP jack. | 333 | * first is the real internal mic and the second is HP jack. |
324 | */ | 334 | */ |
325 | snd_hda_codec_write(codec, spec->autocfg.inputs[1].pin, 0, | 335 | if (spec->cur_mux[adc_idx]) |
326 | AC_VERB_SET_PIN_WIDGET_CONTROL, | 336 | val = snd_hda_get_default_vref(codec, pin) | PIN_IN; |
327 | spec->cur_mux[adc_idx] ? | 337 | else |
328 | PIN_VREF80 : PIN_HP); | 338 | val = PIN_HP; |
339 | snd_hda_set_pin_ctl(codec, pin, val); | ||
329 | spec->automute_speaker = !spec->cur_mux[adc_idx]; | 340 | spec->automute_speaker = !spec->cur_mux[adc_idx]; |
330 | call_update_outputs(codec); | 341 | call_update_outputs(codec); |
331 | } | 342 | } |
@@ -338,7 +349,7 @@ static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx, | |||
338 | nid = get_capsrc(spec, adc_idx); | 349 | nid = get_capsrc(spec, adc_idx); |
339 | 350 | ||
340 | /* no selection? */ | 351 | /* no selection? */ |
341 | num_conns = snd_hda_get_conn_list(codec, nid, NULL); | 352 | num_conns = snd_hda_get_num_conns(codec, nid); |
342 | if (num_conns <= 1) | 353 | if (num_conns <= 1) |
343 | return 1; | 354 | return 1; |
344 | 355 | ||
@@ -376,25 +387,9 @@ static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid, | |||
376 | int auto_pin_type) | 387 | int auto_pin_type) |
377 | { | 388 | { |
378 | unsigned int val = PIN_IN; | 389 | unsigned int val = PIN_IN; |
379 | 390 | if (auto_pin_type == AUTO_PIN_MIC) | |
380 | if (auto_pin_type == AUTO_PIN_MIC) { | 391 | val |= snd_hda_get_default_vref(codec, nid); |
381 | unsigned int pincap; | 392 | snd_hda_set_pin_ctl(codec, nid, val); |
382 | unsigned int oldval; | ||
383 | oldval = snd_hda_codec_read(codec, nid, 0, | ||
384 | AC_VERB_GET_PIN_WIDGET_CONTROL, 0); | ||
385 | pincap = snd_hda_query_pin_caps(codec, nid); | ||
386 | pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT; | ||
387 | /* if the default pin setup is vref50, we give it priority */ | ||
388 | if ((pincap & AC_PINCAP_VREF_80) && oldval != PIN_VREF50) | ||
389 | val = PIN_VREF80; | ||
390 | else if (pincap & AC_PINCAP_VREF_50) | ||
391 | val = PIN_VREF50; | ||
392 | else if (pincap & AC_PINCAP_VREF_100) | ||
393 | val = PIN_VREF100; | ||
394 | else if (pincap & AC_PINCAP_VREF_GRD) | ||
395 | val = PIN_VREFGRD; | ||
396 | } | ||
397 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, val); | ||
398 | } | 393 | } |
399 | 394 | ||
400 | /* | 395 | /* |
@@ -409,13 +404,6 @@ static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix) | |||
409 | spec->mixers[spec->num_mixers++] = mix; | 404 | spec->mixers[spec->num_mixers++] = mix; |
410 | } | 405 | } |
411 | 406 | ||
412 | static void add_verb(struct alc_spec *spec, const struct hda_verb *verb) | ||
413 | { | ||
414 | if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs))) | ||
415 | return; | ||
416 | spec->init_verbs[spec->num_init_verbs++] = verb; | ||
417 | } | ||
418 | |||
419 | /* | 407 | /* |
420 | * GPIO setup tables, used in initialization | 408 | * GPIO setup tables, used in initialization |
421 | */ | 409 | */ |
@@ -517,9 +505,7 @@ static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins, | |||
517 | } else | 505 | } else |
518 | val = 0; | 506 | val = 0; |
519 | val |= pin_bits; | 507 | val |= pin_bits; |
520 | snd_hda_codec_write(codec, nid, 0, | 508 | snd_hda_set_pin_ctl(codec, nid, val); |
521 | AC_VERB_SET_PIN_WIDGET_CONTROL, | ||
522 | val); | ||
523 | break; | 509 | break; |
524 | case ALC_AUTOMUTE_AMP: | 510 | case ALC_AUTOMUTE_AMP: |
525 | snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0, | 511 | snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0, |
@@ -1200,6 +1186,16 @@ static void alc_auto_check_switches(struct hda_codec *codec) | |||
1200 | */ | 1186 | */ |
1201 | #define ALC_FIXUP_SKU_IGNORE (2) | 1187 | #define ALC_FIXUP_SKU_IGNORE (2) |
1202 | 1188 | ||
1189 | static void alc_fixup_sku_ignore(struct hda_codec *codec, | ||
1190 | const struct hda_fixup *fix, int action) | ||
1191 | { | ||
1192 | struct alc_spec *spec = codec->spec; | ||
1193 | if (action == HDA_FIXUP_ACT_PRE_PROBE) { | ||
1194 | spec->cdefine.fixup = 1; | ||
1195 | spec->cdefine.sku_cfg = ALC_FIXUP_SKU_IGNORE; | ||
1196 | } | ||
1197 | } | ||
1198 | |||
1203 | static int alc_auto_parse_customize_define(struct hda_codec *codec) | 1199 | static int alc_auto_parse_customize_define(struct hda_codec *codec) |
1204 | { | 1200 | { |
1205 | unsigned int ass, tmp, i; | 1201 | unsigned int ass, tmp, i; |
@@ -1403,178 +1399,6 @@ static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports) | |||
1403 | } | 1399 | } |
1404 | 1400 | ||
1405 | /* | 1401 | /* |
1406 | * Fix-up pin default configurations and add default verbs | ||
1407 | */ | ||
1408 | |||
1409 | struct alc_pincfg { | ||
1410 | hda_nid_t nid; | ||
1411 | u32 val; | ||
1412 | }; | ||
1413 | |||
1414 | struct alc_model_fixup { | ||
1415 | const int id; | ||
1416 | const char *name; | ||
1417 | }; | ||
1418 | |||
1419 | struct alc_fixup { | ||
1420 | int type; | ||
1421 | bool chained; | ||
1422 | int chain_id; | ||
1423 | union { | ||
1424 | unsigned int sku; | ||
1425 | const struct alc_pincfg *pins; | ||
1426 | const struct hda_verb *verbs; | ||
1427 | void (*func)(struct hda_codec *codec, | ||
1428 | const struct alc_fixup *fix, | ||
1429 | int action); | ||
1430 | } v; | ||
1431 | }; | ||
1432 | |||
1433 | enum { | ||
1434 | ALC_FIXUP_INVALID, | ||
1435 | ALC_FIXUP_SKU, | ||
1436 | ALC_FIXUP_PINS, | ||
1437 | ALC_FIXUP_VERBS, | ||
1438 | ALC_FIXUP_FUNC, | ||
1439 | }; | ||
1440 | |||
1441 | enum { | ||
1442 | ALC_FIXUP_ACT_PRE_PROBE, | ||
1443 | ALC_FIXUP_ACT_PROBE, | ||
1444 | ALC_FIXUP_ACT_INIT, | ||
1445 | ALC_FIXUP_ACT_BUILD, | ||
1446 | }; | ||
1447 | |||
1448 | static void alc_apply_pincfgs(struct hda_codec *codec, | ||
1449 | const struct alc_pincfg *cfg) | ||
1450 | { | ||
1451 | for (; cfg->nid; cfg++) | ||
1452 | snd_hda_codec_set_pincfg(codec, cfg->nid, cfg->val); | ||
1453 | } | ||
1454 | |||
1455 | static void alc_apply_fixup(struct hda_codec *codec, int action) | ||
1456 | { | ||
1457 | struct alc_spec *spec = codec->spec; | ||
1458 | int id = spec->fixup_id; | ||
1459 | #ifdef CONFIG_SND_DEBUG_VERBOSE | ||
1460 | const char *modelname = spec->fixup_name; | ||
1461 | #endif | ||
1462 | int depth = 0; | ||
1463 | |||
1464 | if (!spec->fixup_list) | ||
1465 | return; | ||
1466 | |||
1467 | while (id >= 0) { | ||
1468 | const struct alc_fixup *fix = spec->fixup_list + id; | ||
1469 | const struct alc_pincfg *cfg; | ||
1470 | |||
1471 | switch (fix->type) { | ||
1472 | case ALC_FIXUP_SKU: | ||
1473 | if (action != ALC_FIXUP_ACT_PRE_PROBE || !fix->v.sku) | ||
1474 | break; | ||
1475 | snd_printdd(KERN_INFO "hda_codec: %s: " | ||
1476 | "Apply sku override for %s\n", | ||
1477 | codec->chip_name, modelname); | ||
1478 | spec->cdefine.sku_cfg = fix->v.sku; | ||
1479 | spec->cdefine.fixup = 1; | ||
1480 | break; | ||
1481 | case ALC_FIXUP_PINS: | ||
1482 | cfg = fix->v.pins; | ||
1483 | if (action != ALC_FIXUP_ACT_PRE_PROBE || !cfg) | ||
1484 | break; | ||
1485 | snd_printdd(KERN_INFO "hda_codec: %s: " | ||
1486 | "Apply pincfg for %s\n", | ||
1487 | codec->chip_name, modelname); | ||
1488 | alc_apply_pincfgs(codec, cfg); | ||
1489 | break; | ||
1490 | case ALC_FIXUP_VERBS: | ||
1491 | if (action != ALC_FIXUP_ACT_PROBE || !fix->v.verbs) | ||
1492 | break; | ||
1493 | snd_printdd(KERN_INFO "hda_codec: %s: " | ||
1494 | "Apply fix-verbs for %s\n", | ||
1495 | codec->chip_name, modelname); | ||
1496 | add_verb(codec->spec, fix->v.verbs); | ||
1497 | break; | ||
1498 | case ALC_FIXUP_FUNC: | ||
1499 | if (!fix->v.func) | ||
1500 | break; | ||
1501 | snd_printdd(KERN_INFO "hda_codec: %s: " | ||
1502 | "Apply fix-func for %s\n", | ||
1503 | codec->chip_name, modelname); | ||
1504 | fix->v.func(codec, fix, action); | ||
1505 | break; | ||
1506 | default: | ||
1507 | snd_printk(KERN_ERR "hda_codec: %s: " | ||
1508 | "Invalid fixup type %d\n", | ||
1509 | codec->chip_name, fix->type); | ||
1510 | break; | ||
1511 | } | ||
1512 | if (!fix->chained) | ||
1513 | break; | ||
1514 | if (++depth > 10) | ||
1515 | break; | ||
1516 | id = fix->chain_id; | ||
1517 | } | ||
1518 | } | ||
1519 | |||
1520 | static void alc_pick_fixup(struct hda_codec *codec, | ||
1521 | const struct alc_model_fixup *models, | ||
1522 | const struct snd_pci_quirk *quirk, | ||
1523 | const struct alc_fixup *fixlist) | ||
1524 | { | ||
1525 | struct alc_spec *spec = codec->spec; | ||
1526 | const struct snd_pci_quirk *q; | ||
1527 | int id = -1; | ||
1528 | const char *name = NULL; | ||
1529 | |||
1530 | /* when model=nofixup is given, don't pick up any fixups */ | ||
1531 | if (codec->modelname && !strcmp(codec->modelname, "nofixup")) { | ||
1532 | spec->fixup_list = NULL; | ||
1533 | spec->fixup_id = -1; | ||
1534 | return; | ||
1535 | } | ||
1536 | |||
1537 | if (codec->modelname && models) { | ||
1538 | while (models->name) { | ||
1539 | if (!strcmp(codec->modelname, models->name)) { | ||
1540 | id = models->id; | ||
1541 | name = models->name; | ||
1542 | break; | ||
1543 | } | ||
1544 | models++; | ||
1545 | } | ||
1546 | } | ||
1547 | if (id < 0) { | ||
1548 | q = snd_pci_quirk_lookup(codec->bus->pci, quirk); | ||
1549 | if (q) { | ||
1550 | id = q->value; | ||
1551 | #ifdef CONFIG_SND_DEBUG_VERBOSE | ||
1552 | name = q->name; | ||
1553 | #endif | ||
1554 | } | ||
1555 | } | ||
1556 | if (id < 0) { | ||
1557 | for (q = quirk; q->subvendor; q++) { | ||
1558 | unsigned int vendorid = | ||
1559 | q->subdevice | (q->subvendor << 16); | ||
1560 | if (vendorid == codec->subsystem_id) { | ||
1561 | id = q->value; | ||
1562 | #ifdef CONFIG_SND_DEBUG_VERBOSE | ||
1563 | name = q->name; | ||
1564 | #endif | ||
1565 | break; | ||
1566 | } | ||
1567 | } | ||
1568 | } | ||
1569 | |||
1570 | spec->fixup_id = id; | ||
1571 | if (id >= 0) { | ||
1572 | spec->fixup_list = fixlist; | ||
1573 | spec->fixup_name = name; | ||
1574 | } | ||
1575 | } | ||
1576 | |||
1577 | /* | ||
1578 | * COEF access helper functions | 1402 | * COEF access helper functions |
1579 | */ | 1403 | */ |
1580 | static int alc_read_coef_idx(struct hda_codec *codec, | 1404 | static int alc_read_coef_idx(struct hda_codec *codec, |
@@ -1621,8 +1445,7 @@ static void alc_auto_init_digital(struct hda_codec *codec) | |||
1621 | pin = spec->autocfg.dig_out_pins[i]; | 1445 | pin = spec->autocfg.dig_out_pins[i]; |
1622 | if (!pin) | 1446 | if (!pin) |
1623 | continue; | 1447 | continue; |
1624 | snd_hda_codec_write(codec, pin, 0, | 1448 | snd_hda_set_pin_ctl(codec, pin, PIN_OUT); |
1625 | AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT); | ||
1626 | if (!i) | 1449 | if (!i) |
1627 | dac = spec->multiout.dig_out_nid; | 1450 | dac = spec->multiout.dig_out_nid; |
1628 | else | 1451 | else |
@@ -1635,9 +1458,7 @@ static void alc_auto_init_digital(struct hda_codec *codec) | |||
1635 | } | 1458 | } |
1636 | pin = spec->autocfg.dig_in_pin; | 1459 | pin = spec->autocfg.dig_in_pin; |
1637 | if (pin) | 1460 | if (pin) |
1638 | snd_hda_codec_write(codec, pin, 0, | 1461 | snd_hda_set_pin_ctl(codec, pin, PIN_IN); |
1639 | AC_VERB_SET_PIN_WIDGET_CONTROL, | ||
1640 | PIN_IN); | ||
1641 | } | 1462 | } |
1642 | 1463 | ||
1643 | /* parse digital I/Os and set up NIDs in BIOS auto-parse mode */ | 1464 | /* parse digital I/Os and set up NIDs in BIOS auto-parse mode */ |
@@ -2068,7 +1889,6 @@ static void alc_auto_init_std(struct hda_codec *codec); | |||
2068 | static int alc_init(struct hda_codec *codec) | 1889 | static int alc_init(struct hda_codec *codec) |
2069 | { | 1890 | { |
2070 | struct alc_spec *spec = codec->spec; | 1891 | struct alc_spec *spec = codec->spec; |
2071 | unsigned int i; | ||
2072 | 1892 | ||
2073 | if (spec->init_hook) | 1893 | if (spec->init_hook) |
2074 | spec->init_hook(codec); | 1894 | spec->init_hook(codec); |
@@ -2076,8 +1896,6 @@ static int alc_init(struct hda_codec *codec) | |||
2076 | alc_fix_pll(codec); | 1896 | alc_fix_pll(codec); |
2077 | alc_auto_init_amp(codec, spec->init_amp); | 1897 | alc_auto_init_amp(codec, spec->init_amp); |
2078 | 1898 | ||
2079 | for (i = 0; i < spec->num_init_verbs; i++) | ||
2080 | snd_hda_sequence_write(codec, spec->init_verbs[i]); | ||
2081 | alc_init_special_input_src(codec); | 1899 | alc_init_special_input_src(codec); |
2082 | alc_auto_init_std(codec); | 1900 | alc_auto_init_std(codec); |
2083 | 1901 | ||
@@ -2725,7 +2543,6 @@ static int alc_auto_fill_adc_caps(struct hda_codec *codec) | |||
2725 | nid = codec->start_nid; | 2543 | nid = codec->start_nid; |
2726 | for (i = 0; i < codec->num_nodes; i++, nid++) { | 2544 | for (i = 0; i < codec->num_nodes; i++, nid++) { |
2727 | hda_nid_t src; | 2545 | hda_nid_t src; |
2728 | const hda_nid_t *list; | ||
2729 | unsigned int caps = get_wcaps(codec, nid); | 2546 | unsigned int caps = get_wcaps(codec, nid); |
2730 | int type = get_wcaps_type(caps); | 2547 | int type = get_wcaps_type(caps); |
2731 | 2548 | ||
@@ -2743,13 +2560,14 @@ static int alc_auto_fill_adc_caps(struct hda_codec *codec) | |||
2743 | cap_nids[nums] = src; | 2560 | cap_nids[nums] = src; |
2744 | break; | 2561 | break; |
2745 | } | 2562 | } |
2746 | n = snd_hda_get_conn_list(codec, src, &list); | 2563 | n = snd_hda_get_num_conns(codec, src); |
2747 | if (n > 1) { | 2564 | if (n > 1) { |
2748 | cap_nids[nums] = src; | 2565 | cap_nids[nums] = src; |
2749 | break; | 2566 | break; |
2750 | } else if (n != 1) | 2567 | } else if (n != 1) |
2751 | break; | 2568 | break; |
2752 | src = *list; | 2569 | if (snd_hda_get_connections(codec, src, &src, 1) != 1) |
2570 | break; | ||
2753 | } | 2571 | } |
2754 | if (++nums >= max_nums) | 2572 | if (++nums >= max_nums) |
2755 | break; | 2573 | break; |
@@ -2856,8 +2674,7 @@ static int alc_auto_create_shared_input(struct hda_codec *codec) | |||
2856 | static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid, | 2674 | static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid, |
2857 | unsigned int pin_type) | 2675 | unsigned int pin_type) |
2858 | { | 2676 | { |
2859 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, | 2677 | snd_hda_set_pin_ctl(codec, nid, pin_type); |
2860 | pin_type); | ||
2861 | /* unmute pin */ | 2678 | /* unmute pin */ |
2862 | if (nid_has_mute(codec, nid, HDA_OUTPUT)) | 2679 | if (nid_has_mute(codec, nid, HDA_OUTPUT)) |
2863 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, | 2680 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, |
@@ -2891,7 +2708,7 @@ static void alc_auto_init_analog_input(struct hda_codec *codec) | |||
2891 | 2708 | ||
2892 | /* mute all loopback inputs */ | 2709 | /* mute all loopback inputs */ |
2893 | if (spec->mixer_nid) { | 2710 | if (spec->mixer_nid) { |
2894 | int nums = snd_hda_get_conn_list(codec, spec->mixer_nid, NULL); | 2711 | int nums = snd_hda_get_num_conns(codec, spec->mixer_nid); |
2895 | for (i = 0; i < nums; i++) | 2712 | for (i = 0; i < nums; i++) |
2896 | snd_hda_codec_write(codec, spec->mixer_nid, 0, | 2713 | snd_hda_codec_write(codec, spec->mixer_nid, 0, |
2897 | AC_VERB_SET_AMP_GAIN_MUTE, | 2714 | AC_VERB_SET_AMP_GAIN_MUTE, |
@@ -3521,7 +3338,7 @@ static int alc_auto_add_sw_ctl(struct hda_codec *codec, | |||
3521 | if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) { | 3338 | if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) { |
3522 | type = ALC_CTL_WIDGET_MUTE; | 3339 | type = ALC_CTL_WIDGET_MUTE; |
3523 | val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT); | 3340 | val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT); |
3524 | } else if (snd_hda_get_conn_list(codec, nid, NULL) == 1) { | 3341 | } else if (snd_hda_get_num_conns(codec, nid) == 1) { |
3525 | type = ALC_CTL_WIDGET_MUTE; | 3342 | type = ALC_CTL_WIDGET_MUTE; |
3526 | val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT); | 3343 | val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT); |
3527 | } else { | 3344 | } else { |
@@ -3998,9 +3815,7 @@ static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output) | |||
3998 | snd_hda_codec_read(codec, nid, 0, | 3815 | snd_hda_codec_read(codec, nid, 0, |
3999 | AC_VERB_GET_PIN_WIDGET_CONTROL, 0); | 3816 | AC_VERB_GET_PIN_WIDGET_CONTROL, 0); |
4000 | if (output) { | 3817 | if (output) { |
4001 | snd_hda_codec_update_cache(codec, nid, 0, | 3818 | snd_hda_set_pin_ctl_cache(codec, nid, PIN_OUT); |
4002 | AC_VERB_SET_PIN_WIDGET_CONTROL, | ||
4003 | PIN_OUT); | ||
4004 | if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP) | 3819 | if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP) |
4005 | snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0, | 3820 | snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0, |
4006 | HDA_AMP_MUTE, 0); | 3821 | HDA_AMP_MUTE, 0); |
@@ -4009,9 +3824,8 @@ static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output) | |||
4009 | if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP) | 3824 | if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP) |
4010 | snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0, | 3825 | snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0, |
4011 | HDA_AMP_MUTE, HDA_AMP_MUTE); | 3826 | HDA_AMP_MUTE, HDA_AMP_MUTE); |
4012 | snd_hda_codec_update_cache(codec, nid, 0, | 3827 | snd_hda_set_pin_ctl_cache(codec, nid, |
4013 | AC_VERB_SET_PIN_WIDGET_CONTROL, | 3828 | spec->multi_io[idx].ctl_in); |
4014 | spec->multi_io[idx].ctl_in); | ||
4015 | } | 3829 | } |
4016 | return 0; | 3830 | return 0; |
4017 | } | 3831 | } |
@@ -4084,7 +3898,7 @@ static void alc_remove_invalid_adc_nids(struct hda_codec *codec) | |||
4084 | nums = 0; | 3898 | nums = 0; |
4085 | for (n = 0; n < spec->num_adc_nids; n++) { | 3899 | for (n = 0; n < spec->num_adc_nids; n++) { |
4086 | hda_nid_t cap = spec->private_capsrc_nids[n]; | 3900 | hda_nid_t cap = spec->private_capsrc_nids[n]; |
4087 | int num_conns = snd_hda_get_conn_list(codec, cap, NULL); | 3901 | int num_conns = snd_hda_get_num_conns(codec, cap); |
4088 | for (i = 0; i < imux->num_items; i++) { | 3902 | for (i = 0; i < imux->num_items; i++) { |
4089 | hda_nid_t pin = spec->imux_pins[i]; | 3903 | hda_nid_t pin = spec->imux_pins[i]; |
4090 | if (pin) { | 3904 | if (pin) { |
@@ -4213,7 +4027,7 @@ static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap, | |||
4213 | if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) { | 4027 | if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) { |
4214 | snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx, | 4028 | snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx, |
4215 | HDA_AMP_MUTE, 0); | 4029 | HDA_AMP_MUTE, 0); |
4216 | } else if (snd_hda_get_conn_list(codec, cap, NULL) > 1) { | 4030 | } else if (snd_hda_get_num_conns(codec, cap) > 1) { |
4217 | snd_hda_codec_write_cache(codec, cap, 0, | 4031 | snd_hda_codec_write_cache(codec, cap, 0, |
4218 | AC_VERB_SET_CONNECT_SEL, idx); | 4032 | AC_VERB_SET_CONNECT_SEL, idx); |
4219 | } | 4033 | } |
@@ -4427,6 +4241,25 @@ static int alc_parse_auto_config(struct hda_codec *codec, | |||
4427 | return 1; | 4241 | return 1; |
4428 | } | 4242 | } |
4429 | 4243 | ||
4244 | /* common preparation job for alc_spec */ | ||
4245 | static int alc_alloc_spec(struct hda_codec *codec, hda_nid_t mixer_nid) | ||
4246 | { | ||
4247 | struct alc_spec *spec = kzalloc(sizeof(*spec), GFP_KERNEL); | ||
4248 | int err; | ||
4249 | |||
4250 | if (!spec) | ||
4251 | return -ENOMEM; | ||
4252 | codec->spec = spec; | ||
4253 | spec->mixer_nid = mixer_nid; | ||
4254 | |||
4255 | err = alc_codec_rename_from_preset(codec); | ||
4256 | if (err < 0) { | ||
4257 | kfree(spec); | ||
4258 | return err; | ||
4259 | } | ||
4260 | return 0; | ||
4261 | } | ||
4262 | |||
4430 | static int alc880_parse_auto_config(struct hda_codec *codec) | 4263 | static int alc880_parse_auto_config(struct hda_codec *codec) |
4431 | { | 4264 | { |
4432 | static const hda_nid_t alc880_ignore[] = { 0x1d, 0 }; | 4265 | static const hda_nid_t alc880_ignore[] = { 0x1d, 0 }; |
@@ -4808,13 +4641,11 @@ static int patch_alc880(struct hda_codec *codec) | |||
4808 | struct alc_spec *spec; | 4641 | struct alc_spec *spec; |
4809 | int err; | 4642 | int err; |
4810 | 4643 | ||
4811 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); | 4644 | err = alc_alloc_spec(codec, 0x0b); |
4812 | if (spec == NULL) | 4645 | if (err < 0) |
4813 | return -ENOMEM; | 4646 | return err; |
4814 | |||
4815 | codec->spec = spec; | ||
4816 | 4647 | ||
4817 | spec->mixer_nid = 0x0b; | 4648 | spec = codec->spec; |
4818 | spec->need_dac_fix = 1; | 4649 | spec->need_dac_fix = 1; |
4819 | 4650 | ||
4820 | alc_pick_fixup(codec, alc880_fixup_models, alc880_fixup_tbl, | 4651 | alc_pick_fixup(codec, alc880_fixup_models, alc880_fixup_tbl, |
@@ -4890,7 +4721,7 @@ static void alc260_fixup_gpio1_toggle(struct hda_codec *codec, | |||
4890 | spec->autocfg.hp_pins[0] = 0x0f; /* copy it for automute */ | 4721 | spec->autocfg.hp_pins[0] = 0x0f; /* copy it for automute */ |
4891 | snd_hda_jack_detect_enable(codec, 0x0f, ALC_HP_EVENT); | 4722 | snd_hda_jack_detect_enable(codec, 0x0f, ALC_HP_EVENT); |
4892 | spec->unsol_event = alc_sku_unsol_event; | 4723 | spec->unsol_event = alc_sku_unsol_event; |
4893 | add_verb(codec->spec, alc_gpio1_init_verbs); | 4724 | snd_hda_gen_add_verbs(&spec->gen, alc_gpio1_init_verbs); |
4894 | } | 4725 | } |
4895 | } | 4726 | } |
4896 | 4727 | ||
@@ -5001,13 +4832,11 @@ static int patch_alc260(struct hda_codec *codec) | |||
5001 | struct alc_spec *spec; | 4832 | struct alc_spec *spec; |
5002 | int err; | 4833 | int err; |
5003 | 4834 | ||
5004 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); | 4835 | err = alc_alloc_spec(codec, 0x07); |
5005 | if (spec == NULL) | 4836 | if (err < 0) |
5006 | return -ENOMEM; | 4837 | return err; |
5007 | |||
5008 | codec->spec = spec; | ||
5009 | 4838 | ||
5010 | spec->mixer_nid = 0x07; | 4839 | spec = codec->spec; |
5011 | 4840 | ||
5012 | alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups); | 4841 | alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups); |
5013 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); | 4842 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); |
@@ -5171,8 +5000,7 @@ static void alc889_fixup_mbp_vref(struct hda_codec *codec, | |||
5171 | val = snd_hda_codec_read(codec, nids[i], 0, | 5000 | val = snd_hda_codec_read(codec, nids[i], 0, |
5172 | AC_VERB_GET_PIN_WIDGET_CONTROL, 0); | 5001 | AC_VERB_GET_PIN_WIDGET_CONTROL, 0); |
5173 | val |= AC_PINCTL_VREF_80; | 5002 | val |= AC_PINCTL_VREF_80; |
5174 | snd_hda_codec_write(codec, nids[i], 0, | 5003 | snd_hda_set_pin_ctl(codec, nids[i], val); |
5175 | AC_VERB_SET_PIN_WIDGET_CONTROL, val); | ||
5176 | spec->keep_vref_in_automute = 1; | 5004 | spec->keep_vref_in_automute = 1; |
5177 | break; | 5005 | break; |
5178 | } | 5006 | } |
@@ -5193,8 +5021,7 @@ static void alc889_fixup_imac91_vref(struct hda_codec *codec, | |||
5193 | val = snd_hda_codec_read(codec, nids[i], 0, | 5021 | val = snd_hda_codec_read(codec, nids[i], 0, |
5194 | AC_VERB_GET_PIN_WIDGET_CONTROL, 0); | 5022 | AC_VERB_GET_PIN_WIDGET_CONTROL, 0); |
5195 | val |= AC_PINCTL_VREF_50; | 5023 | val |= AC_PINCTL_VREF_50; |
5196 | snd_hda_codec_write(codec, nids[i], 0, | 5024 | snd_hda_set_pin_ctl(codec, nids[i], val); |
5197 | AC_VERB_SET_PIN_WIDGET_CONTROL, val); | ||
5198 | } | 5025 | } |
5199 | spec->keep_vref_in_automute = 1; | 5026 | spec->keep_vref_in_automute = 1; |
5200 | } | 5027 | } |
@@ -5225,8 +5052,8 @@ static const struct alc_fixup alc882_fixups[] = { | |||
5225 | } | 5052 | } |
5226 | }, | 5053 | }, |
5227 | [ALC882_FIXUP_ACER_ASPIRE_7736] = { | 5054 | [ALC882_FIXUP_ACER_ASPIRE_7736] = { |
5228 | .type = ALC_FIXUP_SKU, | 5055 | .type = ALC_FIXUP_FUNC, |
5229 | .v.sku = ALC_FIXUP_SKU_IGNORE, | 5056 | .v.func = alc_fixup_sku_ignore, |
5230 | }, | 5057 | }, |
5231 | [ALC882_FIXUP_ASUS_W90V] = { | 5058 | [ALC882_FIXUP_ASUS_W90V] = { |
5232 | .type = ALC_FIXUP_PINS, | 5059 | .type = ALC_FIXUP_PINS, |
@@ -5476,13 +5303,11 @@ static int patch_alc882(struct hda_codec *codec) | |||
5476 | struct alc_spec *spec; | 5303 | struct alc_spec *spec; |
5477 | int err; | 5304 | int err; |
5478 | 5305 | ||
5479 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); | 5306 | err = alc_alloc_spec(codec, 0x0b); |
5480 | if (spec == NULL) | 5307 | if (err < 0) |
5481 | return -ENOMEM; | 5308 | return err; |
5482 | |||
5483 | codec->spec = spec; | ||
5484 | 5309 | ||
5485 | spec->mixer_nid = 0x0b; | 5310 | spec = codec->spec; |
5486 | 5311 | ||
5487 | switch (codec->vendor_id) { | 5312 | switch (codec->vendor_id) { |
5488 | case 0x10ec0882: | 5313 | case 0x10ec0882: |
@@ -5494,10 +5319,6 @@ static int patch_alc882(struct hda_codec *codec) | |||
5494 | break; | 5319 | break; |
5495 | } | 5320 | } |
5496 | 5321 | ||
5497 | err = alc_codec_rename_from_preset(codec); | ||
5498 | if (err < 0) | ||
5499 | goto error; | ||
5500 | |||
5501 | alc_pick_fixup(codec, alc882_fixup_models, alc882_fixup_tbl, | 5322 | alc_pick_fixup(codec, alc882_fixup_models, alc882_fixup_tbl, |
5502 | alc882_fixups); | 5323 | alc882_fixups); |
5503 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); | 5324 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); |
@@ -5621,13 +5442,11 @@ static int patch_alc262(struct hda_codec *codec) | |||
5621 | struct alc_spec *spec; | 5442 | struct alc_spec *spec; |
5622 | int err; | 5443 | int err; |
5623 | 5444 | ||
5624 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); | 5445 | err = alc_alloc_spec(codec, 0x0b); |
5625 | if (spec == NULL) | 5446 | if (err < 0) |
5626 | return -ENOMEM; | 5447 | return err; |
5627 | |||
5628 | codec->spec = spec; | ||
5629 | 5448 | ||
5630 | spec->mixer_nid = 0x0b; | 5449 | spec = codec->spec; |
5631 | 5450 | ||
5632 | #if 0 | 5451 | #if 0 |
5633 | /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is | 5452 | /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is |
@@ -5710,7 +5529,7 @@ static int alc268_parse_auto_config(struct hda_codec *codec) | |||
5710 | if (err > 0) { | 5529 | if (err > 0) { |
5711 | if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) { | 5530 | if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) { |
5712 | add_mixer(spec, alc268_beep_mixer); | 5531 | add_mixer(spec, alc268_beep_mixer); |
5713 | add_verb(spec, alc268_beep_init_verbs); | 5532 | snd_hda_gen_add_verbs(&spec->gen, alc268_beep_init_verbs); |
5714 | } | 5533 | } |
5715 | } | 5534 | } |
5716 | return err; | 5535 | return err; |
@@ -5723,13 +5542,12 @@ static int patch_alc268(struct hda_codec *codec) | |||
5723 | struct alc_spec *spec; | 5542 | struct alc_spec *spec; |
5724 | int i, has_beep, err; | 5543 | int i, has_beep, err; |
5725 | 5544 | ||
5726 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); | ||
5727 | if (spec == NULL) | ||
5728 | return -ENOMEM; | ||
5729 | |||
5730 | codec->spec = spec; | ||
5731 | |||
5732 | /* ALC268 has no aa-loopback mixer */ | 5545 | /* ALC268 has no aa-loopback mixer */ |
5546 | err = alc_alloc_spec(codec, 0); | ||
5547 | if (err < 0) | ||
5548 | return err; | ||
5549 | |||
5550 | spec = codec->spec; | ||
5733 | 5551 | ||
5734 | /* automatic parse from the BIOS config */ | 5552 | /* automatic parse from the BIOS config */ |
5735 | err = alc268_parse_auto_config(codec); | 5553 | err = alc268_parse_auto_config(codec); |
@@ -5946,9 +5764,7 @@ static void alc269_fixup_mic2_mute_hook(void *private_data, int enabled) | |||
5946 | { | 5764 | { |
5947 | struct hda_codec *codec = private_data; | 5765 | struct hda_codec *codec = private_data; |
5948 | unsigned int pinval = enabled ? 0x20 : 0x24; | 5766 | unsigned int pinval = enabled ? 0x20 : 0x24; |
5949 | snd_hda_codec_update_cache(codec, 0x19, 0, | 5767 | snd_hda_set_pin_ctl_cache(codec, 0x19, pinval); |
5950 | AC_VERB_SET_PIN_WIDGET_CONTROL, | ||
5951 | pinval); | ||
5952 | } | 5768 | } |
5953 | 5769 | ||
5954 | static void alc269_fixup_mic2_mute(struct hda_codec *codec, | 5770 | static void alc269_fixup_mic2_mute(struct hda_codec *codec, |
@@ -6015,8 +5831,8 @@ static const struct alc_fixup alc269_fixups[] = { | |||
6015 | } | 5831 | } |
6016 | }, | 5832 | }, |
6017 | [ALC269_FIXUP_SKU_IGNORE] = { | 5833 | [ALC269_FIXUP_SKU_IGNORE] = { |
6018 | .type = ALC_FIXUP_SKU, | 5834 | .type = ALC_FIXUP_FUNC, |
6019 | .v.sku = ALC_FIXUP_SKU_IGNORE, | 5835 | .v.func = alc_fixup_sku_ignore, |
6020 | }, | 5836 | }, |
6021 | [ALC269_FIXUP_ASUS_G73JW] = { | 5837 | [ALC269_FIXUP_ASUS_G73JW] = { |
6022 | .type = ALC_FIXUP_PINS, | 5838 | .type = ALC_FIXUP_PINS, |
@@ -6242,19 +6058,13 @@ static void alc269_fill_coef(struct hda_codec *codec) | |||
6242 | static int patch_alc269(struct hda_codec *codec) | 6058 | static int patch_alc269(struct hda_codec *codec) |
6243 | { | 6059 | { |
6244 | struct alc_spec *spec; | 6060 | struct alc_spec *spec; |
6245 | int err = 0; | 6061 | int err; |
6246 | |||
6247 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); | ||
6248 | if (spec == NULL) | ||
6249 | return -ENOMEM; | ||
6250 | |||
6251 | codec->spec = spec; | ||
6252 | |||
6253 | spec->mixer_nid = 0x0b; | ||
6254 | 6062 | ||
6255 | err = alc_codec_rename_from_preset(codec); | 6063 | err = alc_alloc_spec(codec, 0x0b); |
6256 | if (err < 0) | 6064 | if (err < 0) |
6257 | goto error; | 6065 | return err; |
6066 | |||
6067 | spec = codec->spec; | ||
6258 | 6068 | ||
6259 | if (codec->vendor_id == 0x10ec0269) { | 6069 | if (codec->vendor_id == 0x10ec0269) { |
6260 | spec->codec_variant = ALC269_TYPE_ALC269VA; | 6070 | spec->codec_variant = ALC269_TYPE_ALC269VA; |
@@ -6346,8 +6156,7 @@ static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec, | |||
6346 | if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))) | 6156 | if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))) |
6347 | val |= AC_PINCTL_IN_EN; | 6157 | val |= AC_PINCTL_IN_EN; |
6348 | val |= AC_PINCTL_VREF_50; | 6158 | val |= AC_PINCTL_VREF_50; |
6349 | snd_hda_codec_write(codec, 0x0f, 0, | 6159 | snd_hda_set_pin_ctl(codec, 0x0f, val); |
6350 | AC_VERB_SET_PIN_WIDGET_CONTROL, val); | ||
6351 | spec->keep_vref_in_automute = 1; | 6160 | spec->keep_vref_in_automute = 1; |
6352 | } | 6161 | } |
6353 | 6162 | ||
@@ -6401,13 +6210,11 @@ static int patch_alc861(struct hda_codec *codec) | |||
6401 | struct alc_spec *spec; | 6210 | struct alc_spec *spec; |
6402 | int err; | 6211 | int err; |
6403 | 6212 | ||
6404 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); | 6213 | err = alc_alloc_spec(codec, 0x15); |
6405 | if (spec == NULL) | 6214 | if (err < 0) |
6406 | return -ENOMEM; | 6215 | return err; |
6407 | |||
6408 | codec->spec = spec; | ||
6409 | 6216 | ||
6410 | spec->mixer_nid = 0x15; | 6217 | spec = codec->spec; |
6411 | 6218 | ||
6412 | alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups); | 6219 | alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups); |
6413 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); | 6220 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); |
@@ -6504,13 +6311,11 @@ static int patch_alc861vd(struct hda_codec *codec) | |||
6504 | struct alc_spec *spec; | 6311 | struct alc_spec *spec; |
6505 | int err; | 6312 | int err; |
6506 | 6313 | ||
6507 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); | 6314 | err = alc_alloc_spec(codec, 0x0b); |
6508 | if (spec == NULL) | 6315 | if (err < 0) |
6509 | return -ENOMEM; | 6316 | return err; |
6510 | |||
6511 | codec->spec = spec; | ||
6512 | 6317 | ||
6513 | spec->mixer_nid = 0x0b; | 6318 | spec = codec->spec; |
6514 | 6319 | ||
6515 | alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups); | 6320 | alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups); |
6516 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); | 6321 | alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); |
@@ -6522,7 +6327,7 @@ static int patch_alc861vd(struct hda_codec *codec) | |||
6522 | 6327 | ||
6523 | if (codec->vendor_id == 0x10ec0660) { | 6328 | if (codec->vendor_id == 0x10ec0660) { |
6524 | /* always turn on EAPD */ | 6329 | /* always turn on EAPD */ |
6525 | add_verb(spec, alc660vd_eapd_verbs); | 6330 | snd_hda_gen_add_verbs(&spec->gen, alc660vd_eapd_verbs); |
6526 | } | 6331 | } |
6527 | 6332 | ||
6528 | if (!spec->no_analog) { | 6333 | if (!spec->no_analog) { |
@@ -6635,8 +6440,8 @@ static const struct alc_fixup alc662_fixups[] = { | |||
6635 | } | 6440 | } |
6636 | }, | 6441 | }, |
6637 | [ALC662_FIXUP_SKU_IGNORE] = { | 6442 | [ALC662_FIXUP_SKU_IGNORE] = { |
6638 | .type = ALC_FIXUP_SKU, | 6443 | .type = ALC_FIXUP_FUNC, |
6639 | .v.sku = ALC_FIXUP_SKU_IGNORE, | 6444 | .v.func = alc_fixup_sku_ignore, |
6640 | }, | 6445 | }, |
6641 | [ALC662_FIXUP_HP_RP5800] = { | 6446 | [ALC662_FIXUP_HP_RP5800] = { |
6642 | .type = ALC_FIXUP_PINS, | 6447 | .type = ALC_FIXUP_PINS, |
@@ -6849,25 +6654,19 @@ static const struct alc_model_fixup alc662_fixup_models[] = { | |||
6849 | static int patch_alc662(struct hda_codec *codec) | 6654 | static int patch_alc662(struct hda_codec *codec) |
6850 | { | 6655 | { |
6851 | struct alc_spec *spec; | 6656 | struct alc_spec *spec; |
6852 | int err = 0; | 6657 | int err; |
6853 | |||
6854 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); | ||
6855 | if (!spec) | ||
6856 | return -ENOMEM; | ||
6857 | 6658 | ||
6858 | codec->spec = spec; | 6659 | err = alc_alloc_spec(codec, 0x0b); |
6660 | if (err < 0) | ||
6661 | return err; | ||
6859 | 6662 | ||
6860 | spec->mixer_nid = 0x0b; | 6663 | spec = codec->spec; |
6861 | 6664 | ||
6862 | /* handle multiple HPs as is */ | 6665 | /* handle multiple HPs as is */ |
6863 | spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP; | 6666 | spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP; |
6864 | 6667 | ||
6865 | alc_fix_pll_init(codec, 0x20, 0x04, 15); | 6668 | alc_fix_pll_init(codec, 0x20, 0x04, 15); |
6866 | 6669 | ||
6867 | err = alc_codec_rename_from_preset(codec); | ||
6868 | if (err < 0) | ||
6869 | goto error; | ||
6870 | |||
6871 | if ((alc_get_coef0(codec) & (1 << 14)) && | 6670 | if ((alc_get_coef0(codec) & (1 << 14)) && |
6872 | codec->bus->pci->subsystem_vendor == 0x1025 && | 6671 | codec->bus->pci->subsystem_vendor == 0x1025 && |
6873 | spec->cdefine.platform_type == 1) { | 6672 | spec->cdefine.platform_type == 1) { |
@@ -6930,16 +6729,12 @@ static int alc680_parse_auto_config(struct hda_codec *codec) | |||
6930 | */ | 6729 | */ |
6931 | static int patch_alc680(struct hda_codec *codec) | 6730 | static int patch_alc680(struct hda_codec *codec) |
6932 | { | 6731 | { |
6933 | struct alc_spec *spec; | ||
6934 | int err; | 6732 | int err; |
6935 | 6733 | ||
6936 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); | ||
6937 | if (spec == NULL) | ||
6938 | return -ENOMEM; | ||
6939 | |||
6940 | codec->spec = spec; | ||
6941 | |||
6942 | /* ALC680 has no aa-loopback mixer */ | 6734 | /* ALC680 has no aa-loopback mixer */ |
6735 | err = alc_alloc_spec(codec, 0); | ||
6736 | if (err < 0) | ||
6737 | return err; | ||
6943 | 6738 | ||
6944 | /* automatic parse from the BIOS config */ | 6739 | /* automatic parse from the BIOS config */ |
6945 | err = alc680_parse_auto_config(codec); | 6740 | err = alc680_parse_auto_config(codec); |
diff --git a/sound/pci/hda/patch_sigmatel.c b/sound/pci/hda/patch_sigmatel.c index 2cb1e08f962a..7db8228f1b88 100644 --- a/sound/pci/hda/patch_sigmatel.c +++ b/sound/pci/hda/patch_sigmatel.c | |||
@@ -36,6 +36,7 @@ | |||
36 | #include <sound/tlv.h> | 36 | #include <sound/tlv.h> |
37 | #include "hda_codec.h" | 37 | #include "hda_codec.h" |
38 | #include "hda_local.h" | 38 | #include "hda_local.h" |
39 | #include "hda_auto_parser.h" | ||
39 | #include "hda_beep.h" | 40 | #include "hda_beep.h" |
40 | #include "hda_jack.h" | 41 | #include "hda_jack.h" |
41 | 42 | ||
@@ -221,6 +222,7 @@ struct sigmatel_spec { | |||
221 | unsigned char aloopback_shift; | 222 | unsigned char aloopback_shift; |
222 | 223 | ||
223 | /* power management */ | 224 | /* power management */ |
225 | unsigned int power_map_bits; | ||
224 | unsigned int num_pwrs; | 226 | unsigned int num_pwrs; |
225 | const hda_nid_t *pwr_nids; | 227 | const hda_nid_t *pwr_nids; |
226 | const hda_nid_t *dac_list; | 228 | const hda_nid_t *dac_list; |
@@ -314,6 +316,9 @@ struct sigmatel_spec { | |||
314 | struct hda_vmaster_mute_hook vmaster_mute; | 316 | struct hda_vmaster_mute_hook vmaster_mute; |
315 | }; | 317 | }; |
316 | 318 | ||
319 | #define AC_VERB_IDT_SET_POWER_MAP 0x7ec | ||
320 | #define AC_VERB_IDT_GET_POWER_MAP 0xfec | ||
321 | |||
317 | static const hda_nid_t stac9200_adc_nids[1] = { | 322 | static const hda_nid_t stac9200_adc_nids[1] = { |
318 | 0x03, | 323 | 0x03, |
319 | }; | 324 | }; |
@@ -681,8 +686,7 @@ static int stac_vrefout_set(struct hda_codec *codec, | |||
681 | pinctl &= ~AC_PINCTL_VREFEN; | 686 | pinctl &= ~AC_PINCTL_VREFEN; |
682 | pinctl |= (new_vref & AC_PINCTL_VREFEN); | 687 | pinctl |= (new_vref & AC_PINCTL_VREFEN); |
683 | 688 | ||
684 | error = snd_hda_codec_write_cache(codec, nid, 0, | 689 | error = snd_hda_set_pin_ctl_cache(codec, nid, pinctl); |
685 | AC_VERB_SET_PIN_WIDGET_CONTROL, pinctl); | ||
686 | if (error < 0) | 690 | if (error < 0) |
687 | return error; | 691 | return error; |
688 | 692 | ||
@@ -706,8 +710,7 @@ static unsigned int stac92xx_vref_set(struct hda_codec *codec, | |||
706 | else | 710 | else |
707 | pincfg |= AC_PINCTL_IN_EN; | 711 | pincfg |= AC_PINCTL_IN_EN; |
708 | 712 | ||
709 | error = snd_hda_codec_write_cache(codec, nid, 0, | 713 | error = snd_hda_set_pin_ctl_cache(codec, nid, pincfg); |
710 | AC_VERB_SET_PIN_WIDGET_CONTROL, pincfg); | ||
711 | if (error < 0) | 714 | if (error < 0) |
712 | return error; | 715 | return error; |
713 | else | 716 | else |
@@ -2505,27 +2508,10 @@ static int stac92xx_build_pcms(struct hda_codec *codec) | |||
2505 | return 0; | 2508 | return 0; |
2506 | } | 2509 | } |
2507 | 2510 | ||
2508 | static unsigned int stac92xx_get_default_vref(struct hda_codec *codec, | ||
2509 | hda_nid_t nid) | ||
2510 | { | ||
2511 | unsigned int pincap = snd_hda_query_pin_caps(codec, nid); | ||
2512 | pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT; | ||
2513 | if (pincap & AC_PINCAP_VREF_100) | ||
2514 | return AC_PINCTL_VREF_100; | ||
2515 | if (pincap & AC_PINCAP_VREF_80) | ||
2516 | return AC_PINCTL_VREF_80; | ||
2517 | if (pincap & AC_PINCAP_VREF_50) | ||
2518 | return AC_PINCTL_VREF_50; | ||
2519 | if (pincap & AC_PINCAP_VREF_GRD) | ||
2520 | return AC_PINCTL_VREF_GRD; | ||
2521 | return 0; | ||
2522 | } | ||
2523 | |||
2524 | static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type) | 2511 | static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type) |
2525 | 2512 | ||
2526 | { | 2513 | { |
2527 | snd_hda_codec_write_cache(codec, nid, 0, | 2514 | snd_hda_set_pin_ctl_cache(codec, nid, pin_type); |
2528 | AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type); | ||
2529 | } | 2515 | } |
2530 | 2516 | ||
2531 | #define stac92xx_hp_switch_info snd_ctl_boolean_mono_info | 2517 | #define stac92xx_hp_switch_info snd_ctl_boolean_mono_info |
@@ -2594,7 +2580,7 @@ static int stac92xx_dc_bias_get(struct snd_kcontrol *kcontrol, | |||
2594 | hda_nid_t nid = kcontrol->private_value; | 2580 | hda_nid_t nid = kcontrol->private_value; |
2595 | unsigned int vref = stac92xx_vref_get(codec, nid); | 2581 | unsigned int vref = stac92xx_vref_get(codec, nid); |
2596 | 2582 | ||
2597 | if (vref == stac92xx_get_default_vref(codec, nid)) | 2583 | if (vref == snd_hda_get_default_vref(codec, nid)) |
2598 | ucontrol->value.enumerated.item[0] = 0; | 2584 | ucontrol->value.enumerated.item[0] = 0; |
2599 | else if (vref == AC_PINCTL_VREF_GRD) | 2585 | else if (vref == AC_PINCTL_VREF_GRD) |
2600 | ucontrol->value.enumerated.item[0] = 1; | 2586 | ucontrol->value.enumerated.item[0] = 1; |
@@ -2613,7 +2599,7 @@ static int stac92xx_dc_bias_put(struct snd_kcontrol *kcontrol, | |||
2613 | hda_nid_t nid = kcontrol->private_value; | 2599 | hda_nid_t nid = kcontrol->private_value; |
2614 | 2600 | ||
2615 | if (ucontrol->value.enumerated.item[0] == 0) | 2601 | if (ucontrol->value.enumerated.item[0] == 0) |
2616 | new_vref = stac92xx_get_default_vref(codec, nid); | 2602 | new_vref = snd_hda_get_default_vref(codec, nid); |
2617 | else if (ucontrol->value.enumerated.item[0] == 1) | 2603 | else if (ucontrol->value.enumerated.item[0] == 1) |
2618 | new_vref = AC_PINCTL_VREF_GRD; | 2604 | new_vref = AC_PINCTL_VREF_GRD; |
2619 | else if (ucontrol->value.enumerated.item[0] == 2) | 2605 | else if (ucontrol->value.enumerated.item[0] == 2) |
@@ -2679,7 +2665,7 @@ static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_ | |||
2679 | else { | 2665 | else { |
2680 | unsigned int pinctl = AC_PINCTL_IN_EN; | 2666 | unsigned int pinctl = AC_PINCTL_IN_EN; |
2681 | if (io_idx) /* set VREF for mic */ | 2667 | if (io_idx) /* set VREF for mic */ |
2682 | pinctl |= stac92xx_get_default_vref(codec, nid); | 2668 | pinctl |= snd_hda_get_default_vref(codec, nid); |
2683 | stac92xx_auto_set_pinctl(codec, nid, pinctl); | 2669 | stac92xx_auto_set_pinctl(codec, nid, pinctl); |
2684 | } | 2670 | } |
2685 | 2671 | ||
@@ -2847,7 +2833,7 @@ static inline int stac92xx_add_jack_mode_control(struct hda_codec *codec, | |||
2847 | char name[22]; | 2833 | char name[22]; |
2848 | 2834 | ||
2849 | if (snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT) { | 2835 | if (snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT) { |
2850 | if (stac92xx_get_default_vref(codec, nid) == AC_PINCTL_VREF_GRD | 2836 | if (snd_hda_get_default_vref(codec, nid) == AC_PINCTL_VREF_GRD |
2851 | && nid == spec->line_switch) | 2837 | && nid == spec->line_switch) |
2852 | control = STAC_CTL_WIDGET_IO_SWITCH; | 2838 | control = STAC_CTL_WIDGET_IO_SWITCH; |
2853 | else if (snd_hda_query_pin_caps(codec, nid) | 2839 | else if (snd_hda_query_pin_caps(codec, nid) |
@@ -4250,13 +4236,6 @@ static void stac_store_hints(struct hda_codec *codec) | |||
4250 | val = snd_hda_get_bool_hint(codec, "eapd_switch"); | 4236 | val = snd_hda_get_bool_hint(codec, "eapd_switch"); |
4251 | if (val >= 0) | 4237 | if (val >= 0) |
4252 | spec->eapd_switch = val; | 4238 | spec->eapd_switch = val; |
4253 | get_int_hint(codec, "gpio_led_polarity", &spec->gpio_led_polarity); | ||
4254 | if (get_int_hint(codec, "gpio_led", &spec->gpio_led)) { | ||
4255 | spec->gpio_mask |= spec->gpio_led; | ||
4256 | spec->gpio_dir |= spec->gpio_led; | ||
4257 | if (spec->gpio_led_polarity) | ||
4258 | spec->gpio_data |= spec->gpio_led; | ||
4259 | } | ||
4260 | } | 4239 | } |
4261 | 4240 | ||
4262 | static void stac_issue_unsol_events(struct hda_codec *codec, int num_pins, | 4241 | static void stac_issue_unsol_events(struct hda_codec *codec, int num_pins, |
@@ -4354,7 +4333,7 @@ static int stac92xx_init(struct hda_codec *codec) | |||
4354 | unsigned int pinctl, conf; | 4333 | unsigned int pinctl, conf; |
4355 | if (type == AUTO_PIN_MIC) { | 4334 | if (type == AUTO_PIN_MIC) { |
4356 | /* for mic pins, force to initialize */ | 4335 | /* for mic pins, force to initialize */ |
4357 | pinctl = stac92xx_get_default_vref(codec, nid); | 4336 | pinctl = snd_hda_get_default_vref(codec, nid); |
4358 | pinctl |= AC_PINCTL_IN_EN; | 4337 | pinctl |= AC_PINCTL_IN_EN; |
4359 | stac92xx_auto_set_pinctl(codec, nid, pinctl); | 4338 | stac92xx_auto_set_pinctl(codec, nid, pinctl); |
4360 | } else { | 4339 | } else { |
@@ -4390,10 +4369,18 @@ static int stac92xx_init(struct hda_codec *codec) | |||
4390 | hda_nid_t nid = spec->pwr_nids[i]; | 4369 | hda_nid_t nid = spec->pwr_nids[i]; |
4391 | int pinctl, def_conf; | 4370 | int pinctl, def_conf; |
4392 | 4371 | ||
4372 | def_conf = snd_hda_codec_get_pincfg(codec, nid); | ||
4373 | def_conf = get_defcfg_connect(def_conf); | ||
4374 | if (def_conf == AC_JACK_PORT_NONE) { | ||
4375 | /* power off unused ports */ | ||
4376 | stac_toggle_power_map(codec, nid, 0); | ||
4377 | continue; | ||
4378 | } | ||
4393 | /* power on when no jack detection is available */ | 4379 | /* power on when no jack detection is available */ |
4394 | /* or when the VREF is used for controlling LED */ | 4380 | /* or when the VREF is used for controlling LED */ |
4395 | if (!spec->hp_detect || | 4381 | if (!spec->hp_detect || |
4396 | spec->vref_mute_led_nid == nid) { | 4382 | spec->vref_mute_led_nid == nid || |
4383 | !is_jack_detectable(codec, nid)) { | ||
4397 | stac_toggle_power_map(codec, nid, 1); | 4384 | stac_toggle_power_map(codec, nid, 1); |
4398 | continue; | 4385 | continue; |
4399 | } | 4386 | } |
@@ -4411,15 +4398,6 @@ static int stac92xx_init(struct hda_codec *codec) | |||
4411 | stac_toggle_power_map(codec, nid, 1); | 4398 | stac_toggle_power_map(codec, nid, 1); |
4412 | continue; | 4399 | continue; |
4413 | } | 4400 | } |
4414 | def_conf = snd_hda_codec_get_pincfg(codec, nid); | ||
4415 | def_conf = get_defcfg_connect(def_conf); | ||
4416 | /* skip any ports that don't have jacks since presence | ||
4417 | * detection is useless */ | ||
4418 | if (def_conf != AC_JACK_PORT_NONE && | ||
4419 | !is_jack_detectable(codec, nid)) { | ||
4420 | stac_toggle_power_map(codec, nid, 1); | ||
4421 | continue; | ||
4422 | } | ||
4423 | if (enable_pin_detect(codec, nid, STAC_PWR_EVENT)) { | 4401 | if (enable_pin_detect(codec, nid, STAC_PWR_EVENT)) { |
4424 | stac_issue_unsol_event(codec, nid); | 4402 | stac_issue_unsol_event(codec, nid); |
4425 | continue; | 4403 | continue; |
@@ -4432,6 +4410,12 @@ static int stac92xx_init(struct hda_codec *codec) | |||
4432 | 4410 | ||
4433 | /* sync mute LED */ | 4411 | /* sync mute LED */ |
4434 | snd_hda_sync_vmaster_hook(&spec->vmaster_mute); | 4412 | snd_hda_sync_vmaster_hook(&spec->vmaster_mute); |
4413 | |||
4414 | /* sync the power-map */ | ||
4415 | if (spec->num_pwrs) | ||
4416 | snd_hda_codec_write(codec, codec->afg, 0, | ||
4417 | AC_VERB_IDT_SET_POWER_MAP, | ||
4418 | spec->power_map_bits); | ||
4435 | if (spec->dac_list) | 4419 | if (spec->dac_list) |
4436 | stac92xx_power_down(codec); | 4420 | stac92xx_power_down(codec); |
4437 | return 0; | 4421 | return 0; |
@@ -4460,8 +4444,7 @@ static void stac92xx_shutup_pins(struct hda_codec *codec) | |||
4460 | struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i); | 4444 | struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i); |
4461 | def_conf = snd_hda_codec_get_pincfg(codec, pin->nid); | 4445 | def_conf = snd_hda_codec_get_pincfg(codec, pin->nid); |
4462 | if (get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE) | 4446 | if (get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE) |
4463 | snd_hda_codec_write(codec, pin->nid, 0, | 4447 | snd_hda_set_pin_ctl(codec, pin->nid, 0); |
4464 | AC_VERB_SET_PIN_WIDGET_CONTROL, 0); | ||
4465 | } | 4448 | } |
4466 | } | 4449 | } |
4467 | 4450 | ||
@@ -4517,9 +4500,7 @@ static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid, | |||
4517 | 4500 | ||
4518 | pin_ctl |= flag; | 4501 | pin_ctl |= flag; |
4519 | if (old_ctl != pin_ctl) | 4502 | if (old_ctl != pin_ctl) |
4520 | snd_hda_codec_write_cache(codec, nid, 0, | 4503 | snd_hda_set_pin_ctl_cache(codec, nid, pin_ctl); |
4521 | AC_VERB_SET_PIN_WIDGET_CONTROL, | ||
4522 | pin_ctl); | ||
4523 | } | 4504 | } |
4524 | 4505 | ||
4525 | static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid, | 4506 | static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid, |
@@ -4528,9 +4509,7 @@ static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid, | |||
4528 | unsigned int pin_ctl = snd_hda_codec_read(codec, nid, | 4509 | unsigned int pin_ctl = snd_hda_codec_read(codec, nid, |
4529 | 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00); | 4510 | 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00); |
4530 | if (pin_ctl & flag) | 4511 | if (pin_ctl & flag) |
4531 | snd_hda_codec_write_cache(codec, nid, 0, | 4512 | snd_hda_set_pin_ctl_cache(codec, nid, pin_ctl & ~flag); |
4532 | AC_VERB_SET_PIN_WIDGET_CONTROL, | ||
4533 | pin_ctl & ~flag); | ||
4534 | } | 4513 | } |
4535 | 4514 | ||
4536 | static inline int get_pin_presence(struct hda_codec *codec, hda_nid_t nid) | 4515 | static inline int get_pin_presence(struct hda_codec *codec, hda_nid_t nid) |
@@ -4682,14 +4661,18 @@ static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid, | |||
4682 | 4661 | ||
4683 | idx = 1 << idx; | 4662 | idx = 1 << idx; |
4684 | 4663 | ||
4685 | val = snd_hda_codec_read(codec, codec->afg, 0, 0x0fec, 0x0) & 0xff; | 4664 | val = spec->power_map_bits; |
4686 | if (enable) | 4665 | if (enable) |
4687 | val &= ~idx; | 4666 | val &= ~idx; |
4688 | else | 4667 | else |
4689 | val |= idx; | 4668 | val |= idx; |
4690 | 4669 | ||
4691 | /* power down unused output ports */ | 4670 | /* power down unused output ports */ |
4692 | snd_hda_codec_write(codec, codec->afg, 0, 0x7ec, val); | 4671 | if (val != spec->power_map_bits) { |
4672 | spec->power_map_bits = val; | ||
4673 | snd_hda_codec_write(codec, codec->afg, 0, | ||
4674 | AC_VERB_IDT_SET_POWER_MAP, val); | ||
4675 | } | ||
4693 | } | 4676 | } |
4694 | 4677 | ||
4695 | static void stac92xx_pin_sense(struct hda_codec *codec, hda_nid_t nid) | 4678 | static void stac92xx_pin_sense(struct hda_codec *codec, hda_nid_t nid) |
@@ -4866,6 +4849,11 @@ static int find_mute_led_cfg(struct hda_codec *codec, int default_polarity) | |||
4866 | struct sigmatel_spec *spec = codec->spec; | 4849 | struct sigmatel_spec *spec = codec->spec; |
4867 | const struct dmi_device *dev = NULL; | 4850 | const struct dmi_device *dev = NULL; |
4868 | 4851 | ||
4852 | if (get_int_hint(codec, "gpio_led", &spec->gpio_led)) { | ||
4853 | get_int_hint(codec, "gpio_led_polarity", | ||
4854 | &spec->gpio_led_polarity); | ||
4855 | return 1; | ||
4856 | } | ||
4869 | if ((codec->subsystem_id >> 16) == PCI_VENDOR_ID_HP) { | 4857 | if ((codec->subsystem_id >> 16) == PCI_VENDOR_ID_HP) { |
4870 | while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING, | 4858 | while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING, |
4871 | NULL, dev))) { | 4859 | NULL, dev))) { |
@@ -4952,7 +4940,8 @@ static void stac92hd_proc_hook(struct snd_info_buffer *buffer, | |||
4952 | { | 4940 | { |
4953 | if (nid == codec->afg) | 4941 | if (nid == codec->afg) |
4954 | snd_iprintf(buffer, "Power-Map: 0x%02x\n", | 4942 | snd_iprintf(buffer, "Power-Map: 0x%02x\n", |
4955 | snd_hda_codec_read(codec, nid, 0, 0x0fec, 0x0)); | 4943 | snd_hda_codec_read(codec, nid, 0, |
4944 | AC_VERB_IDT_GET_POWER_MAP, 0)); | ||
4956 | } | 4945 | } |
4957 | 4946 | ||
4958 | static void analog_loop_proc_hook(struct snd_info_buffer *buffer, | 4947 | static void analog_loop_proc_hook(struct snd_info_buffer *buffer, |
@@ -5009,20 +4998,6 @@ static int stac92xx_suspend(struct hda_codec *codec, pm_message_t state) | |||
5009 | return 0; | 4998 | return 0; |
5010 | } | 4999 | } |
5011 | 5000 | ||
5012 | static int stac92xx_pre_resume(struct hda_codec *codec) | ||
5013 | { | ||
5014 | struct sigmatel_spec *spec = codec->spec; | ||
5015 | |||
5016 | /* sync mute LED */ | ||
5017 | if (spec->vref_mute_led_nid) | ||
5018 | stac_vrefout_set(codec, spec->vref_mute_led_nid, | ||
5019 | spec->vref_led); | ||
5020 | else if (spec->gpio_led) | ||
5021 | stac_gpio_set(codec, spec->gpio_mask, | ||
5022 | spec->gpio_dir, spec->gpio_data); | ||
5023 | return 0; | ||
5024 | } | ||
5025 | |||
5026 | static void stac92xx_set_power_state(struct hda_codec *codec, hda_nid_t fg, | 5001 | static void stac92xx_set_power_state(struct hda_codec *codec, hda_nid_t fg, |
5027 | unsigned int power_state) | 5002 | unsigned int power_state) |
5028 | { | 5003 | { |
@@ -5046,7 +5021,6 @@ static void stac92xx_set_power_state(struct hda_codec *codec, hda_nid_t fg, | |||
5046 | #else | 5021 | #else |
5047 | #define stac92xx_suspend NULL | 5022 | #define stac92xx_suspend NULL |
5048 | #define stac92xx_resume NULL | 5023 | #define stac92xx_resume NULL |
5049 | #define stac92xx_pre_resume NULL | ||
5050 | #define stac92xx_set_power_state NULL | 5024 | #define stac92xx_set_power_state NULL |
5051 | #endif /* CONFIG_PM */ | 5025 | #endif /* CONFIG_PM */ |
5052 | 5026 | ||
@@ -5592,9 +5566,6 @@ again: | |||
5592 | codec->patch_ops.set_power_state = | 5566 | codec->patch_ops.set_power_state = |
5593 | stac92xx_set_power_state; | 5567 | stac92xx_set_power_state; |
5594 | } | 5568 | } |
5595 | #ifdef CONFIG_PM | ||
5596 | codec->patch_ops.pre_resume = stac92xx_pre_resume; | ||
5597 | #endif | ||
5598 | } | 5569 | } |
5599 | 5570 | ||
5600 | err = stac92xx_parse_auto_config(codec); | 5571 | err = stac92xx_parse_auto_config(codec); |
@@ -5901,9 +5872,6 @@ again: | |||
5901 | codec->patch_ops.set_power_state = | 5872 | codec->patch_ops.set_power_state = |
5902 | stac92xx_set_power_state; | 5873 | stac92xx_set_power_state; |
5903 | } | 5874 | } |
5904 | #ifdef CONFIG_PM | ||
5905 | codec->patch_ops.pre_resume = stac92xx_pre_resume; | ||
5906 | #endif | ||
5907 | } | 5875 | } |
5908 | 5876 | ||
5909 | spec->multiout.dac_nids = spec->dac_nids; | 5877 | spec->multiout.dac_nids = spec->dac_nids; |
diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c index 06214fdc9486..82b368068e08 100644 --- a/sound/pci/hda/patch_via.c +++ b/sound/pci/hda/patch_via.c | |||
@@ -54,6 +54,7 @@ | |||
54 | #include <sound/asoundef.h> | 54 | #include <sound/asoundef.h> |
55 | #include "hda_codec.h" | 55 | #include "hda_codec.h" |
56 | #include "hda_local.h" | 56 | #include "hda_local.h" |
57 | #include "hda_auto_parser.h" | ||
57 | #include "hda_jack.h" | 58 | #include "hda_jack.h" |
58 | 59 | ||
59 | /* Pin Widget NID */ | 60 | /* Pin Widget NID */ |
@@ -484,7 +485,7 @@ static void activate_output_mix(struct hda_codec *codec, struct nid_path *path, | |||
484 | 485 | ||
485 | if (!path) | 486 | if (!path) |
486 | return; | 487 | return; |
487 | num = snd_hda_get_conn_list(codec, mix_nid, NULL); | 488 | num = snd_hda_get_num_conns(codec, mix_nid); |
488 | for (i = 0; i < num; i++) { | 489 | for (i = 0; i < num; i++) { |
489 | if (i == idx) | 490 | if (i == idx) |
490 | val = AMP_IN_UNMUTE(i); | 491 | val = AMP_IN_UNMUTE(i); |
@@ -532,8 +533,7 @@ static void init_output_pin(struct hda_codec *codec, hda_nid_t pin, | |||
532 | { | 533 | { |
533 | if (!pin) | 534 | if (!pin) |
534 | return; | 535 | return; |
535 | snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, | 536 | snd_hda_set_pin_ctl(codec, pin, pin_type); |
536 | pin_type); | ||
537 | if (snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_EAPD) | 537 | if (snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_EAPD) |
538 | snd_hda_codec_write(codec, pin, 0, | 538 | snd_hda_codec_write(codec, pin, 0, |
539 | AC_VERB_SET_EAPD_BTLENABLE, 0x02); | 539 | AC_VERB_SET_EAPD_BTLENABLE, 0x02); |
@@ -662,12 +662,12 @@ static void via_auto_init_analog_input(struct hda_codec *codec) | |||
662 | hda_nid_t nid = cfg->inputs[i].pin; | 662 | hda_nid_t nid = cfg->inputs[i].pin; |
663 | if (spec->smart51_enabled && is_smart51_pins(codec, nid)) | 663 | if (spec->smart51_enabled && is_smart51_pins(codec, nid)) |
664 | ctl = PIN_OUT; | 664 | ctl = PIN_OUT; |
665 | else if (cfg->inputs[i].type == AUTO_PIN_MIC) | 665 | else { |
666 | ctl = PIN_VREF50; | ||
667 | else | ||
668 | ctl = PIN_IN; | 666 | ctl = PIN_IN; |
669 | snd_hda_codec_write(codec, nid, 0, | 667 | if (cfg->inputs[i].type == AUTO_PIN_MIC) |
670 | AC_VERB_SET_PIN_WIDGET_CONTROL, ctl); | 668 | ctl |= snd_hda_get_default_vref(codec, nid); |
669 | } | ||
670 | snd_hda_set_pin_ctl(codec, nid, ctl); | ||
671 | } | 671 | } |
672 | 672 | ||
673 | /* init input-src */ | 673 | /* init input-src */ |
@@ -1006,9 +1006,7 @@ static int via_smart51_put(struct snd_kcontrol *kcontrol, | |||
1006 | AC_VERB_GET_PIN_WIDGET_CONTROL, 0); | 1006 | AC_VERB_GET_PIN_WIDGET_CONTROL, 0); |
1007 | parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN); | 1007 | parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN); |
1008 | parm |= out_in; | 1008 | parm |= out_in; |
1009 | snd_hda_codec_write(codec, nid, 0, | 1009 | snd_hda_set_pin_ctl(codec, nid, parm); |
1010 | AC_VERB_SET_PIN_WIDGET_CONTROL, | ||
1011 | parm); | ||
1012 | if (out_in == AC_PINCTL_OUT_EN) { | 1010 | if (out_in == AC_PINCTL_OUT_EN) { |
1013 | mute_aa_path(codec, 1); | 1011 | mute_aa_path(codec, 1); |
1014 | notify_aa_path_ctls(codec); | 1012 | notify_aa_path_ctls(codec); |
@@ -1647,8 +1645,7 @@ static void toggle_output_mutes(struct hda_codec *codec, int num_pins, | |||
1647 | parm &= ~AC_PINCTL_OUT_EN; | 1645 | parm &= ~AC_PINCTL_OUT_EN; |
1648 | else | 1646 | else |
1649 | parm |= AC_PINCTL_OUT_EN; | 1647 | parm |= AC_PINCTL_OUT_EN; |
1650 | snd_hda_codec_write(codec, pins[i], 0, | 1648 | snd_hda_set_pin_ctl(codec, pins[i], parm); |
1651 | AC_VERB_SET_PIN_WIDGET_CONTROL, parm); | ||
1652 | } | 1649 | } |
1653 | } | 1650 | } |
1654 | 1651 | ||
@@ -1709,8 +1706,7 @@ static void via_gpio_control(struct hda_codec *codec) | |||
1709 | 1706 | ||
1710 | if (gpio_data == 0x02) { | 1707 | if (gpio_data == 0x02) { |
1711 | /* unmute line out */ | 1708 | /* unmute line out */ |
1712 | snd_hda_codec_write(codec, spec->autocfg.line_out_pins[0], 0, | 1709 | snd_hda_set_pin_ctl(codec, spec->autocfg.line_out_pins[0], |
1713 | AC_VERB_SET_PIN_WIDGET_CONTROL, | ||
1714 | PIN_OUT); | 1710 | PIN_OUT); |
1715 | if (vol_counter & 0x20) { | 1711 | if (vol_counter & 0x20) { |
1716 | /* decrease volume */ | 1712 | /* decrease volume */ |
@@ -1728,9 +1724,7 @@ static void via_gpio_control(struct hda_codec *codec) | |||
1728 | } | 1724 | } |
1729 | } else if (!(gpio_data & 0x02)) { | 1725 | } else if (!(gpio_data & 0x02)) { |
1730 | /* mute line out */ | 1726 | /* mute line out */ |
1731 | snd_hda_codec_write(codec, spec->autocfg.line_out_pins[0], 0, | 1727 | snd_hda_set_pin_ctl(codec, spec->autocfg.line_out_pins[0], 0); |
1732 | AC_VERB_SET_PIN_WIDGET_CONTROL, | ||
1733 | 0); | ||
1734 | } | 1728 | } |
1735 | } | 1729 | } |
1736 | 1730 | ||
@@ -2757,8 +2751,7 @@ static void via_auto_init_dig_in(struct hda_codec *codec) | |||
2757 | struct via_spec *spec = codec->spec; | 2751 | struct via_spec *spec = codec->spec; |
2758 | if (!spec->dig_in_nid) | 2752 | if (!spec->dig_in_nid) |
2759 | return; | 2753 | return; |
2760 | snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0, | 2754 | snd_hda_set_pin_ctl(codec, spec->autocfg.dig_in_pin, PIN_IN); |
2761 | AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN); | ||
2762 | } | 2755 | } |
2763 | 2756 | ||
2764 | /* initialize the unsolicited events */ | 2757 | /* initialize the unsolicited events */ |
diff --git a/sound/pci/ice1712/ice1712.c b/sound/pci/ice1712/ice1712.c index 132a86e09d07..5be2e120a14e 100644 --- a/sound/pci/ice1712/ice1712.c +++ b/sound/pci/ice1712/ice1712.c | |||
@@ -2803,22 +2803,11 @@ static void __devexit snd_ice1712_remove(struct pci_dev *pci) | |||
2803 | pci_set_drvdata(pci, NULL); | 2803 | pci_set_drvdata(pci, NULL); |
2804 | } | 2804 | } |
2805 | 2805 | ||
2806 | static struct pci_driver driver = { | 2806 | static struct pci_driver ice1712_driver = { |
2807 | .name = KBUILD_MODNAME, | 2807 | .name = KBUILD_MODNAME, |
2808 | .id_table = snd_ice1712_ids, | 2808 | .id_table = snd_ice1712_ids, |
2809 | .probe = snd_ice1712_probe, | 2809 | .probe = snd_ice1712_probe, |
2810 | .remove = __devexit_p(snd_ice1712_remove), | 2810 | .remove = __devexit_p(snd_ice1712_remove), |
2811 | }; | 2811 | }; |
2812 | 2812 | ||
2813 | static int __init alsa_card_ice1712_init(void) | 2813 | module_pci_driver(ice1712_driver); |
2814 | { | ||
2815 | return pci_register_driver(&driver); | ||
2816 | } | ||
2817 | |||
2818 | static void __exit alsa_card_ice1712_exit(void) | ||
2819 | { | ||
2820 | pci_unregister_driver(&driver); | ||
2821 | } | ||
2822 | |||
2823 | module_init(alsa_card_ice1712_init) | ||
2824 | module_exit(alsa_card_ice1712_exit) | ||
diff --git a/sound/pci/ice1712/ice1724.c b/sound/pci/ice1712/ice1724.c index 812d10e43ae0..a01a00d1cf4d 100644 --- a/sound/pci/ice1712/ice1724.c +++ b/sound/pci/ice1712/ice1724.c | |||
@@ -2873,7 +2873,7 @@ static int snd_vt1724_resume(struct pci_dev *pci) | |||
2873 | } | 2873 | } |
2874 | #endif | 2874 | #endif |
2875 | 2875 | ||
2876 | static struct pci_driver driver = { | 2876 | static struct pci_driver vt1724_driver = { |
2877 | .name = KBUILD_MODNAME, | 2877 | .name = KBUILD_MODNAME, |
2878 | .id_table = snd_vt1724_ids, | 2878 | .id_table = snd_vt1724_ids, |
2879 | .probe = snd_vt1724_probe, | 2879 | .probe = snd_vt1724_probe, |
@@ -2884,15 +2884,4 @@ static struct pci_driver driver = { | |||
2884 | #endif | 2884 | #endif |
2885 | }; | 2885 | }; |
2886 | 2886 | ||
2887 | static int __init alsa_card_ice1724_init(void) | 2887 | module_pci_driver(vt1724_driver); |
2888 | { | ||
2889 | return pci_register_driver(&driver); | ||
2890 | } | ||
2891 | |||
2892 | static void __exit alsa_card_ice1724_exit(void) | ||
2893 | { | ||
2894 | pci_unregister_driver(&driver); | ||
2895 | } | ||
2896 | |||
2897 | module_init(alsa_card_ice1724_init) | ||
2898 | module_exit(alsa_card_ice1724_exit) | ||
diff --git a/sound/pci/intel8x0.c b/sound/pci/intel8x0.c index e0a4263baa20..f4e2dd4da8cf 100644 --- a/sound/pci/intel8x0.c +++ b/sound/pci/intel8x0.c | |||
@@ -3338,7 +3338,7 @@ static void __devexit snd_intel8x0_remove(struct pci_dev *pci) | |||
3338 | pci_set_drvdata(pci, NULL); | 3338 | pci_set_drvdata(pci, NULL); |
3339 | } | 3339 | } |
3340 | 3340 | ||
3341 | static struct pci_driver driver = { | 3341 | static struct pci_driver intel8x0_driver = { |
3342 | .name = KBUILD_MODNAME, | 3342 | .name = KBUILD_MODNAME, |
3343 | .id_table = snd_intel8x0_ids, | 3343 | .id_table = snd_intel8x0_ids, |
3344 | .probe = snd_intel8x0_probe, | 3344 | .probe = snd_intel8x0_probe, |
@@ -3349,16 +3349,4 @@ static struct pci_driver driver = { | |||
3349 | #endif | 3349 | #endif |
3350 | }; | 3350 | }; |
3351 | 3351 | ||
3352 | 3352 | module_pci_driver(intel8x0_driver); | |
3353 | static int __init alsa_card_intel8x0_init(void) | ||
3354 | { | ||
3355 | return pci_register_driver(&driver); | ||
3356 | } | ||
3357 | |||
3358 | static void __exit alsa_card_intel8x0_exit(void) | ||
3359 | { | ||
3360 | pci_unregister_driver(&driver); | ||
3361 | } | ||
3362 | |||
3363 | module_init(alsa_card_intel8x0_init) | ||
3364 | module_exit(alsa_card_intel8x0_exit) | ||
diff --git a/sound/pci/intel8x0m.c b/sound/pci/intel8x0m.c index d689913a61be..fc27a6a69e77 100644 --- a/sound/pci/intel8x0m.c +++ b/sound/pci/intel8x0m.c | |||
@@ -1324,7 +1324,7 @@ static void __devexit snd_intel8x0m_remove(struct pci_dev *pci) | |||
1324 | pci_set_drvdata(pci, NULL); | 1324 | pci_set_drvdata(pci, NULL); |
1325 | } | 1325 | } |
1326 | 1326 | ||
1327 | static struct pci_driver driver = { | 1327 | static struct pci_driver intel8x0m_driver = { |
1328 | .name = KBUILD_MODNAME, | 1328 | .name = KBUILD_MODNAME, |
1329 | .id_table = snd_intel8x0m_ids, | 1329 | .id_table = snd_intel8x0m_ids, |
1330 | .probe = snd_intel8x0m_probe, | 1330 | .probe = snd_intel8x0m_probe, |
@@ -1335,16 +1335,4 @@ static struct pci_driver driver = { | |||
1335 | #endif | 1335 | #endif |
1336 | }; | 1336 | }; |
1337 | 1337 | ||
1338 | 1338 | module_pci_driver(intel8x0m_driver); | |
1339 | static int __init alsa_card_intel8x0m_init(void) | ||
1340 | { | ||
1341 | return pci_register_driver(&driver); | ||
1342 | } | ||
1343 | |||
1344 | static void __exit alsa_card_intel8x0m_exit(void) | ||
1345 | { | ||
1346 | pci_unregister_driver(&driver); | ||
1347 | } | ||
1348 | |||
1349 | module_init(alsa_card_intel8x0m_init) | ||
1350 | module_exit(alsa_card_intel8x0m_exit) | ||
diff --git a/sound/pci/korg1212/korg1212.c b/sound/pci/korg1212/korg1212.c index 8fea45ab5882..e69ce5f9c31e 100644 --- a/sound/pci/korg1212/korg1212.c +++ b/sound/pci/korg1212/korg1212.c | |||
@@ -2476,22 +2476,11 @@ static void __devexit snd_korg1212_remove(struct pci_dev *pci) | |||
2476 | pci_set_drvdata(pci, NULL); | 2476 | pci_set_drvdata(pci, NULL); |
2477 | } | 2477 | } |
2478 | 2478 | ||
2479 | static struct pci_driver driver = { | 2479 | static struct pci_driver korg1212_driver = { |
2480 | .name = KBUILD_MODNAME, | 2480 | .name = KBUILD_MODNAME, |
2481 | .id_table = snd_korg1212_ids, | 2481 | .id_table = snd_korg1212_ids, |
2482 | .probe = snd_korg1212_probe, | 2482 | .probe = snd_korg1212_probe, |
2483 | .remove = __devexit_p(snd_korg1212_remove), | 2483 | .remove = __devexit_p(snd_korg1212_remove), |
2484 | }; | 2484 | }; |
2485 | 2485 | ||
2486 | static int __init alsa_card_korg1212_init(void) | 2486 | module_pci_driver(korg1212_driver); |
2487 | { | ||
2488 | return pci_register_driver(&driver); | ||
2489 | } | ||
2490 | |||
2491 | static void __exit alsa_card_korg1212_exit(void) | ||
2492 | { | ||
2493 | pci_unregister_driver(&driver); | ||
2494 | } | ||
2495 | |||
2496 | module_init(alsa_card_korg1212_init) | ||
2497 | module_exit(alsa_card_korg1212_exit) | ||
diff --git a/sound/pci/lola/lola.c b/sound/pci/lola/lola.c index 375982736858..ac15166bee68 100644 --- a/sound/pci/lola/lola.c +++ b/sound/pci/lola/lola.c | |||
@@ -770,22 +770,11 @@ static DEFINE_PCI_DEVICE_TABLE(lola_ids) = { | |||
770 | MODULE_DEVICE_TABLE(pci, lola_ids); | 770 | MODULE_DEVICE_TABLE(pci, lola_ids); |
771 | 771 | ||
772 | /* pci_driver definition */ | 772 | /* pci_driver definition */ |
773 | static struct pci_driver driver = { | 773 | static struct pci_driver lola_driver = { |
774 | .name = KBUILD_MODNAME, | 774 | .name = KBUILD_MODNAME, |
775 | .id_table = lola_ids, | 775 | .id_table = lola_ids, |
776 | .probe = lola_probe, | 776 | .probe = lola_probe, |
777 | .remove = __devexit_p(lola_remove), | 777 | .remove = __devexit_p(lola_remove), |
778 | }; | 778 | }; |
779 | 779 | ||
780 | static int __init alsa_card_lola_init(void) | 780 | module_pci_driver(lola_driver); |
781 | { | ||
782 | return pci_register_driver(&driver); | ||
783 | } | ||
784 | |||
785 | static void __exit alsa_card_lola_exit(void) | ||
786 | { | ||
787 | pci_unregister_driver(&driver); | ||
788 | } | ||
789 | |||
790 | module_init(alsa_card_lola_init) | ||
791 | module_exit(alsa_card_lola_exit) | ||
diff --git a/sound/pci/lx6464es/lx6464es.c b/sound/pci/lx6464es/lx6464es.c index d94c0c292bd0..d1ab43706735 100644 --- a/sound/pci/lx6464es/lx6464es.c +++ b/sound/pci/lx6464es/lx6464es.c | |||
@@ -1141,24 +1141,11 @@ static void __devexit snd_lx6464es_remove(struct pci_dev *pci) | |||
1141 | } | 1141 | } |
1142 | 1142 | ||
1143 | 1143 | ||
1144 | static struct pci_driver driver = { | 1144 | static struct pci_driver lx6464es_driver = { |
1145 | .name = KBUILD_MODNAME, | 1145 | .name = KBUILD_MODNAME, |
1146 | .id_table = snd_lx6464es_ids, | 1146 | .id_table = snd_lx6464es_ids, |
1147 | .probe = snd_lx6464es_probe, | 1147 | .probe = snd_lx6464es_probe, |
1148 | .remove = __devexit_p(snd_lx6464es_remove), | 1148 | .remove = __devexit_p(snd_lx6464es_remove), |
1149 | }; | 1149 | }; |
1150 | 1150 | ||
1151 | 1151 | module_pci_driver(lx6464es_driver); | |
1152 | /* module initialization */ | ||
1153 | static int __init mod_init(void) | ||
1154 | { | ||
1155 | return pci_register_driver(&driver); | ||
1156 | } | ||
1157 | |||
1158 | static void __exit mod_exit(void) | ||
1159 | { | ||
1160 | pci_unregister_driver(&driver); | ||
1161 | } | ||
1162 | |||
1163 | module_init(mod_init); | ||
1164 | module_exit(mod_exit); | ||
diff --git a/sound/pci/maestro3.c b/sound/pci/maestro3.c index 78229b0dad2b..deef21399586 100644 --- a/sound/pci/maestro3.c +++ b/sound/pci/maestro3.c | |||
@@ -2837,7 +2837,7 @@ static void __devexit snd_m3_remove(struct pci_dev *pci) | |||
2837 | pci_set_drvdata(pci, NULL); | 2837 | pci_set_drvdata(pci, NULL); |
2838 | } | 2838 | } |
2839 | 2839 | ||
2840 | static struct pci_driver driver = { | 2840 | static struct pci_driver m3_driver = { |
2841 | .name = KBUILD_MODNAME, | 2841 | .name = KBUILD_MODNAME, |
2842 | .id_table = snd_m3_ids, | 2842 | .id_table = snd_m3_ids, |
2843 | .probe = snd_m3_probe, | 2843 | .probe = snd_m3_probe, |
@@ -2848,15 +2848,4 @@ static struct pci_driver driver = { | |||
2848 | #endif | 2848 | #endif |
2849 | }; | 2849 | }; |
2850 | 2850 | ||
2851 | static int __init alsa_card_m3_init(void) | 2851 | module_pci_driver(m3_driver); |
2852 | { | ||
2853 | return pci_register_driver(&driver); | ||
2854 | } | ||
2855 | |||
2856 | static void __exit alsa_card_m3_exit(void) | ||
2857 | { | ||
2858 | pci_unregister_driver(&driver); | ||
2859 | } | ||
2860 | |||
2861 | module_init(alsa_card_m3_init) | ||
2862 | module_exit(alsa_card_m3_exit) | ||
diff --git a/sound/pci/mixart/mixart.c b/sound/pci/mixart/mixart.c index 487837c01c9f..0762610c99c0 100644 --- a/sound/pci/mixart/mixart.c +++ b/sound/pci/mixart/mixart.c | |||
@@ -1380,22 +1380,11 @@ static void __devexit snd_mixart_remove(struct pci_dev *pci) | |||
1380 | pci_set_drvdata(pci, NULL); | 1380 | pci_set_drvdata(pci, NULL); |
1381 | } | 1381 | } |
1382 | 1382 | ||
1383 | static struct pci_driver driver = { | 1383 | static struct pci_driver mixart_driver = { |
1384 | .name = KBUILD_MODNAME, | 1384 | .name = KBUILD_MODNAME, |
1385 | .id_table = snd_mixart_ids, | 1385 | .id_table = snd_mixart_ids, |
1386 | .probe = snd_mixart_probe, | 1386 | .probe = snd_mixart_probe, |
1387 | .remove = __devexit_p(snd_mixart_remove), | 1387 | .remove = __devexit_p(snd_mixart_remove), |
1388 | }; | 1388 | }; |
1389 | 1389 | ||
1390 | static int __init alsa_card_mixart_init(void) | 1390 | module_pci_driver(mixart_driver); |
1391 | { | ||
1392 | return pci_register_driver(&driver); | ||
1393 | } | ||
1394 | |||
1395 | static void __exit alsa_card_mixart_exit(void) | ||
1396 | { | ||
1397 | pci_unregister_driver(&driver); | ||
1398 | } | ||
1399 | |||
1400 | module_init(alsa_card_mixart_init) | ||
1401 | module_exit(alsa_card_mixart_exit) | ||
diff --git a/sound/pci/nm256/nm256.c b/sound/pci/nm256/nm256.c index ade2c64bd606..8159b05ee94d 100644 --- a/sound/pci/nm256/nm256.c +++ b/sound/pci/nm256/nm256.c | |||
@@ -1742,7 +1742,7 @@ static void __devexit snd_nm256_remove(struct pci_dev *pci) | |||
1742 | } | 1742 | } |
1743 | 1743 | ||
1744 | 1744 | ||
1745 | static struct pci_driver driver = { | 1745 | static struct pci_driver nm256_driver = { |
1746 | .name = KBUILD_MODNAME, | 1746 | .name = KBUILD_MODNAME, |
1747 | .id_table = snd_nm256_ids, | 1747 | .id_table = snd_nm256_ids, |
1748 | .probe = snd_nm256_probe, | 1748 | .probe = snd_nm256_probe, |
@@ -1753,16 +1753,4 @@ static struct pci_driver driver = { | |||
1753 | #endif | 1753 | #endif |
1754 | }; | 1754 | }; |
1755 | 1755 | ||
1756 | 1756 | module_pci_driver(nm256_driver); | |
1757 | static int __init alsa_card_nm256_init(void) | ||
1758 | { | ||
1759 | return pci_register_driver(&driver); | ||
1760 | } | ||
1761 | |||
1762 | static void __exit alsa_card_nm256_exit(void) | ||
1763 | { | ||
1764 | pci_unregister_driver(&driver); | ||
1765 | } | ||
1766 | |||
1767 | module_init(alsa_card_nm256_init) | ||
1768 | module_exit(alsa_card_nm256_exit) | ||
diff --git a/sound/pci/oxygen/oxygen.c b/sound/pci/oxygen/oxygen.c index eab663eef117..610275bfbaeb 100644 --- a/sound/pci/oxygen/oxygen.c +++ b/sound/pci/oxygen/oxygen.c | |||
@@ -94,6 +94,7 @@ enum { | |||
94 | MODEL_2CH_OUTPUT, | 94 | MODEL_2CH_OUTPUT, |
95 | MODEL_HG2PCI, | 95 | MODEL_HG2PCI, |
96 | MODEL_XONAR_DG, | 96 | MODEL_XONAR_DG, |
97 | MODEL_XONAR_DGX, | ||
97 | }; | 98 | }; |
98 | 99 | ||
99 | static DEFINE_PCI_DEVICE_TABLE(oxygen_ids) = { | 100 | static DEFINE_PCI_DEVICE_TABLE(oxygen_ids) = { |
@@ -109,6 +110,8 @@ static DEFINE_PCI_DEVICE_TABLE(oxygen_ids) = { | |||
109 | { OXYGEN_PCI_SUBID(0x1a58, 0x0910), .driver_data = MODEL_CMEDIA_REF }, | 110 | { OXYGEN_PCI_SUBID(0x1a58, 0x0910), .driver_data = MODEL_CMEDIA_REF }, |
110 | /* Asus Xonar DG */ | 111 | /* Asus Xonar DG */ |
111 | { OXYGEN_PCI_SUBID(0x1043, 0x8467), .driver_data = MODEL_XONAR_DG }, | 112 | { OXYGEN_PCI_SUBID(0x1043, 0x8467), .driver_data = MODEL_XONAR_DG }, |
113 | /* Asus Xonar DGX */ | ||
114 | { OXYGEN_PCI_SUBID(0x1043, 0x8521), .driver_data = MODEL_XONAR_DGX }, | ||
112 | /* PCI 2.0 HD Audio */ | 115 | /* PCI 2.0 HD Audio */ |
113 | { OXYGEN_PCI_SUBID(0x13f6, 0x8782), .driver_data = MODEL_2CH_OUTPUT }, | 116 | { OXYGEN_PCI_SUBID(0x13f6, 0x8782), .driver_data = MODEL_2CH_OUTPUT }, |
114 | /* Kuroutoshikou CMI8787-HG2PCI */ | 117 | /* Kuroutoshikou CMI8787-HG2PCI */ |
@@ -827,6 +830,11 @@ static int __devinit get_oxygen_model(struct oxygen *chip, | |||
827 | break; | 830 | break; |
828 | case MODEL_XONAR_DG: | 831 | case MODEL_XONAR_DG: |
829 | chip->model = model_xonar_dg; | 832 | chip->model = model_xonar_dg; |
833 | chip->model.shortname = "Xonar DG"; | ||
834 | break; | ||
835 | case MODEL_XONAR_DGX: | ||
836 | chip->model = model_xonar_dg; | ||
837 | chip->model.shortname = "Xonar DGX"; | ||
830 | break; | 838 | break; |
831 | } | 839 | } |
832 | if (id->driver_data == MODEL_MERIDIAN || | 840 | if (id->driver_data == MODEL_MERIDIAN || |
@@ -870,15 +878,4 @@ static struct pci_driver oxygen_driver = { | |||
870 | #endif | 878 | #endif |
871 | }; | 879 | }; |
872 | 880 | ||
873 | static int __init alsa_card_oxygen_init(void) | 881 | module_pci_driver(oxygen_driver); |
874 | { | ||
875 | return pci_register_driver(&oxygen_driver); | ||
876 | } | ||
877 | |||
878 | static void __exit alsa_card_oxygen_exit(void) | ||
879 | { | ||
880 | pci_unregister_driver(&oxygen_driver); | ||
881 | } | ||
882 | |||
883 | module_init(alsa_card_oxygen_init) | ||
884 | module_exit(alsa_card_oxygen_exit) | ||
diff --git a/sound/pci/oxygen/virtuoso.c b/sound/pci/oxygen/virtuoso.c index 3fdee4950174..19962c6d38c3 100644 --- a/sound/pci/oxygen/virtuoso.c +++ b/sound/pci/oxygen/virtuoso.c | |||
@@ -100,15 +100,4 @@ static struct pci_driver xonar_driver = { | |||
100 | .shutdown = oxygen_pci_shutdown, | 100 | .shutdown = oxygen_pci_shutdown, |
101 | }; | 101 | }; |
102 | 102 | ||
103 | static int __init alsa_card_xonar_init(void) | 103 | module_pci_driver(xonar_driver); |
104 | { | ||
105 | return pci_register_driver(&xonar_driver); | ||
106 | } | ||
107 | |||
108 | static void __exit alsa_card_xonar_exit(void) | ||
109 | { | ||
110 | pci_unregister_driver(&xonar_driver); | ||
111 | } | ||
112 | |||
113 | module_init(alsa_card_xonar_init) | ||
114 | module_exit(alsa_card_xonar_exit) | ||
diff --git a/sound/pci/oxygen/xonar_dg.c b/sound/pci/oxygen/xonar_dg.c index 793bdf03d7e0..77acd790ea47 100644 --- a/sound/pci/oxygen/xonar_dg.c +++ b/sound/pci/oxygen/xonar_dg.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * card driver for the Xonar DG | 2 | * card driver for the Xonar DG/DGX |
3 | * | 3 | * |
4 | * Copyright (c) Clemens Ladisch <clemens@ladisch.de> | 4 | * Copyright (c) Clemens Ladisch <clemens@ladisch.de> |
5 | * | 5 | * |
@@ -17,8 +17,8 @@ | |||
17 | */ | 17 | */ |
18 | 18 | ||
19 | /* | 19 | /* |
20 | * Xonar DG | 20 | * Xonar DG/DGX |
21 | * -------- | 21 | * ------------ |
22 | * | 22 | * |
23 | * CMI8788: | 23 | * CMI8788: |
24 | * | 24 | * |
@@ -581,7 +581,6 @@ static void dump_cs4245_registers(struct oxygen *chip, | |||
581 | } | 581 | } |
582 | 582 | ||
583 | struct oxygen_model model_xonar_dg = { | 583 | struct oxygen_model model_xonar_dg = { |
584 | .shortname = "Xonar DG", | ||
585 | .longname = "C-Media Oxygen HD Audio", | 584 | .longname = "C-Media Oxygen HD Audio", |
586 | .chip = "CMI8786", | 585 | .chip = "CMI8786", |
587 | .init = dg_init, | 586 | .init = dg_init, |
diff --git a/sound/pci/pcxhr/pcxhr.c b/sound/pci/pcxhr/pcxhr.c index fd1809ab73b4..0435f45e9513 100644 --- a/sound/pci/pcxhr/pcxhr.c +++ b/sound/pci/pcxhr/pcxhr.c | |||
@@ -1607,22 +1607,11 @@ static void __devexit pcxhr_remove(struct pci_dev *pci) | |||
1607 | pci_set_drvdata(pci, NULL); | 1607 | pci_set_drvdata(pci, NULL); |
1608 | } | 1608 | } |
1609 | 1609 | ||
1610 | static struct pci_driver driver = { | 1610 | static struct pci_driver pcxhr_driver = { |
1611 | .name = KBUILD_MODNAME, | 1611 | .name = KBUILD_MODNAME, |
1612 | .id_table = pcxhr_ids, | 1612 | .id_table = pcxhr_ids, |
1613 | .probe = pcxhr_probe, | 1613 | .probe = pcxhr_probe, |
1614 | .remove = __devexit_p(pcxhr_remove), | 1614 | .remove = __devexit_p(pcxhr_remove), |
1615 | }; | 1615 | }; |
1616 | 1616 | ||
1617 | static int __init pcxhr_module_init(void) | 1617 | module_pci_driver(pcxhr_driver); |
1618 | { | ||
1619 | return pci_register_driver(&driver); | ||
1620 | } | ||
1621 | |||
1622 | static void __exit pcxhr_module_exit(void) | ||
1623 | { | ||
1624 | pci_unregister_driver(&driver); | ||
1625 | } | ||
1626 | |||
1627 | module_init(pcxhr_module_init) | ||
1628 | module_exit(pcxhr_module_exit) | ||
diff --git a/sound/pci/riptide/riptide.c b/sound/pci/riptide/riptide.c index 0481d94aac9b..cbeb3f77350c 100644 --- a/sound/pci/riptide/riptide.c +++ b/sound/pci/riptide/riptide.c | |||
@@ -1837,8 +1837,7 @@ static int snd_riptide_free(struct snd_riptide *chip) | |||
1837 | } | 1837 | } |
1838 | if (chip->irq >= 0) | 1838 | if (chip->irq >= 0) |
1839 | free_irq(chip->irq, chip); | 1839 | free_irq(chip->irq, chip); |
1840 | if (chip->fw_entry) | 1840 | release_firmware(chip->fw_entry); |
1841 | release_firmware(chip->fw_entry); | ||
1842 | release_and_free_resource(chip->res_port); | 1841 | release_and_free_resource(chip->res_port); |
1843 | kfree(chip); | 1842 | kfree(chip); |
1844 | return 0; | 1843 | return 0; |
diff --git a/sound/pci/rme32.c b/sound/pci/rme32.c index b4819d5e41db..46b3629dda22 100644 --- a/sound/pci/rme32.c +++ b/sound/pci/rme32.c | |||
@@ -1984,22 +1984,11 @@ static void __devexit snd_rme32_remove(struct pci_dev *pci) | |||
1984 | pci_set_drvdata(pci, NULL); | 1984 | pci_set_drvdata(pci, NULL); |
1985 | } | 1985 | } |
1986 | 1986 | ||
1987 | static struct pci_driver driver = { | 1987 | static struct pci_driver rme32_driver = { |
1988 | .name = KBUILD_MODNAME, | 1988 | .name = KBUILD_MODNAME, |
1989 | .id_table = snd_rme32_ids, | 1989 | .id_table = snd_rme32_ids, |
1990 | .probe = snd_rme32_probe, | 1990 | .probe = snd_rme32_probe, |
1991 | .remove = __devexit_p(snd_rme32_remove), | 1991 | .remove = __devexit_p(snd_rme32_remove), |
1992 | }; | 1992 | }; |
1993 | 1993 | ||
1994 | static int __init alsa_card_rme32_init(void) | 1994 | module_pci_driver(rme32_driver); |
1995 | { | ||
1996 | return pci_register_driver(&driver); | ||
1997 | } | ||
1998 | |||
1999 | static void __exit alsa_card_rme32_exit(void) | ||
2000 | { | ||
2001 | pci_unregister_driver(&driver); | ||
2002 | } | ||
2003 | |||
2004 | module_init(alsa_card_rme32_init) | ||
2005 | module_exit(alsa_card_rme32_exit) | ||
diff --git a/sound/pci/rme96.c b/sound/pci/rme96.c index ba894158e76c..9b98dc406988 100644 --- a/sound/pci/rme96.c +++ b/sound/pci/rme96.c | |||
@@ -2395,22 +2395,11 @@ static void __devexit snd_rme96_remove(struct pci_dev *pci) | |||
2395 | pci_set_drvdata(pci, NULL); | 2395 | pci_set_drvdata(pci, NULL); |
2396 | } | 2396 | } |
2397 | 2397 | ||
2398 | static struct pci_driver driver = { | 2398 | static struct pci_driver rme96_driver = { |
2399 | .name = KBUILD_MODNAME, | 2399 | .name = KBUILD_MODNAME, |
2400 | .id_table = snd_rme96_ids, | 2400 | .id_table = snd_rme96_ids, |
2401 | .probe = snd_rme96_probe, | 2401 | .probe = snd_rme96_probe, |
2402 | .remove = __devexit_p(snd_rme96_remove), | 2402 | .remove = __devexit_p(snd_rme96_remove), |
2403 | }; | 2403 | }; |
2404 | 2404 | ||
2405 | static int __init alsa_card_rme96_init(void) | 2405 | module_pci_driver(rme96_driver); |
2406 | { | ||
2407 | return pci_register_driver(&driver); | ||
2408 | } | ||
2409 | |||
2410 | static void __exit alsa_card_rme96_exit(void) | ||
2411 | { | ||
2412 | pci_unregister_driver(&driver); | ||
2413 | } | ||
2414 | |||
2415 | module_init(alsa_card_rme96_init) | ||
2416 | module_exit(alsa_card_rme96_exit) | ||
diff --git a/sound/pci/rme9652/hdsp.c b/sound/pci/rme9652/hdsp.c index 0b2aea2ce172..0d6930c4f4b7 100644 --- a/sound/pci/rme9652/hdsp.c +++ b/sound/pci/rme9652/hdsp.c | |||
@@ -5636,22 +5636,11 @@ static void __devexit snd_hdsp_remove(struct pci_dev *pci) | |||
5636 | pci_set_drvdata(pci, NULL); | 5636 | pci_set_drvdata(pci, NULL); |
5637 | } | 5637 | } |
5638 | 5638 | ||
5639 | static struct pci_driver driver = { | 5639 | static struct pci_driver hdsp_driver = { |
5640 | .name = KBUILD_MODNAME, | 5640 | .name = KBUILD_MODNAME, |
5641 | .id_table = snd_hdsp_ids, | 5641 | .id_table = snd_hdsp_ids, |
5642 | .probe = snd_hdsp_probe, | 5642 | .probe = snd_hdsp_probe, |
5643 | .remove = __devexit_p(snd_hdsp_remove), | 5643 | .remove = __devexit_p(snd_hdsp_remove), |
5644 | }; | 5644 | }; |
5645 | 5645 | ||
5646 | static int __init alsa_card_hdsp_init(void) | 5646 | module_pci_driver(hdsp_driver); |
5647 | { | ||
5648 | return pci_register_driver(&driver); | ||
5649 | } | ||
5650 | |||
5651 | static void __exit alsa_card_hdsp_exit(void) | ||
5652 | { | ||
5653 | pci_unregister_driver(&driver); | ||
5654 | } | ||
5655 | |||
5656 | module_init(alsa_card_hdsp_init) | ||
5657 | module_exit(alsa_card_hdsp_exit) | ||
diff --git a/sound/pci/rme9652/hdspm.c b/sound/pci/rme9652/hdspm.c index bc030a2088da..0a5027b94714 100644 --- a/sound/pci/rme9652/hdspm.c +++ b/sound/pci/rme9652/hdspm.c | |||
@@ -6918,23 +6918,11 @@ static void __devexit snd_hdspm_remove(struct pci_dev *pci) | |||
6918 | pci_set_drvdata(pci, NULL); | 6918 | pci_set_drvdata(pci, NULL); |
6919 | } | 6919 | } |
6920 | 6920 | ||
6921 | static struct pci_driver driver = { | 6921 | static struct pci_driver hdspm_driver = { |
6922 | .name = KBUILD_MODNAME, | 6922 | .name = KBUILD_MODNAME, |
6923 | .id_table = snd_hdspm_ids, | 6923 | .id_table = snd_hdspm_ids, |
6924 | .probe = snd_hdspm_probe, | 6924 | .probe = snd_hdspm_probe, |
6925 | .remove = __devexit_p(snd_hdspm_remove), | 6925 | .remove = __devexit_p(snd_hdspm_remove), |
6926 | }; | 6926 | }; |
6927 | 6927 | ||
6928 | 6928 | module_pci_driver(hdspm_driver); | |
6929 | static int __init alsa_card_hdspm_init(void) | ||
6930 | { | ||
6931 | return pci_register_driver(&driver); | ||
6932 | } | ||
6933 | |||
6934 | static void __exit alsa_card_hdspm_exit(void) | ||
6935 | { | ||
6936 | pci_unregister_driver(&driver); | ||
6937 | } | ||
6938 | |||
6939 | module_init(alsa_card_hdspm_init) | ||
6940 | module_exit(alsa_card_hdspm_exit) | ||
diff --git a/sound/pci/rme9652/rme9652.c b/sound/pci/rme9652/rme9652.c index b737d1619cc7..a15fc100ab0c 100644 --- a/sound/pci/rme9652/rme9652.c +++ b/sound/pci/rme9652/rme9652.c | |||
@@ -2631,22 +2631,11 @@ static void __devexit snd_rme9652_remove(struct pci_dev *pci) | |||
2631 | pci_set_drvdata(pci, NULL); | 2631 | pci_set_drvdata(pci, NULL); |
2632 | } | 2632 | } |
2633 | 2633 | ||
2634 | static struct pci_driver driver = { | 2634 | static struct pci_driver rme9652_driver = { |
2635 | .name = KBUILD_MODNAME, | 2635 | .name = KBUILD_MODNAME, |
2636 | .id_table = snd_rme9652_ids, | 2636 | .id_table = snd_rme9652_ids, |
2637 | .probe = snd_rme9652_probe, | 2637 | .probe = snd_rme9652_probe, |
2638 | .remove = __devexit_p(snd_rme9652_remove), | 2638 | .remove = __devexit_p(snd_rme9652_remove), |
2639 | }; | 2639 | }; |
2640 | 2640 | ||
2641 | static int __init alsa_card_hammerfall_init(void) | 2641 | module_pci_driver(rme9652_driver); |
2642 | { | ||
2643 | return pci_register_driver(&driver); | ||
2644 | } | ||
2645 | |||
2646 | static void __exit alsa_card_hammerfall_exit(void) | ||
2647 | { | ||
2648 | pci_unregister_driver(&driver); | ||
2649 | } | ||
2650 | |||
2651 | module_init(alsa_card_hammerfall_init) | ||
2652 | module_exit(alsa_card_hammerfall_exit) | ||
diff --git a/sound/pci/sis7019.c b/sound/pci/sis7019.c index ff500a87f769..1552642765d6 100644 --- a/sound/pci/sis7019.c +++ b/sound/pci/sis7019.c | |||
@@ -1488,15 +1488,4 @@ static struct pci_driver sis7019_driver = { | |||
1488 | #endif | 1488 | #endif |
1489 | }; | 1489 | }; |
1490 | 1490 | ||
1491 | static int __init sis7019_init(void) | 1491 | module_pci_driver(sis7019_driver); |
1492 | { | ||
1493 | return pci_register_driver(&sis7019_driver); | ||
1494 | } | ||
1495 | |||
1496 | static void __exit sis7019_exit(void) | ||
1497 | { | ||
1498 | pci_unregister_driver(&sis7019_driver); | ||
1499 | } | ||
1500 | |||
1501 | module_init(sis7019_init); | ||
1502 | module_exit(sis7019_exit); | ||
diff --git a/sound/pci/sonicvibes.c b/sound/pci/sonicvibes.c index 54cc802050f7..baa9946bedf0 100644 --- a/sound/pci/sonicvibes.c +++ b/sound/pci/sonicvibes.c | |||
@@ -1530,22 +1530,11 @@ static void __devexit snd_sonic_remove(struct pci_dev *pci) | |||
1530 | pci_set_drvdata(pci, NULL); | 1530 | pci_set_drvdata(pci, NULL); |
1531 | } | 1531 | } |
1532 | 1532 | ||
1533 | static struct pci_driver driver = { | 1533 | static struct pci_driver sonicvibes_driver = { |
1534 | .name = KBUILD_MODNAME, | 1534 | .name = KBUILD_MODNAME, |
1535 | .id_table = snd_sonic_ids, | 1535 | .id_table = snd_sonic_ids, |
1536 | .probe = snd_sonic_probe, | 1536 | .probe = snd_sonic_probe, |
1537 | .remove = __devexit_p(snd_sonic_remove), | 1537 | .remove = __devexit_p(snd_sonic_remove), |
1538 | }; | 1538 | }; |
1539 | 1539 | ||
1540 | static int __init alsa_card_sonicvibes_init(void) | 1540 | module_pci_driver(sonicvibes_driver); |
1541 | { | ||
1542 | return pci_register_driver(&driver); | ||
1543 | } | ||
1544 | |||
1545 | static void __exit alsa_card_sonicvibes_exit(void) | ||
1546 | { | ||
1547 | pci_unregister_driver(&driver); | ||
1548 | } | ||
1549 | |||
1550 | module_init(alsa_card_sonicvibes_init) | ||
1551 | module_exit(alsa_card_sonicvibes_exit) | ||
diff --git a/sound/pci/trident/trident.c b/sound/pci/trident/trident.c index 5f1def7f45e5..611983ec7321 100644 --- a/sound/pci/trident/trident.c +++ b/sound/pci/trident/trident.c | |||
@@ -172,7 +172,7 @@ static void __devexit snd_trident_remove(struct pci_dev *pci) | |||
172 | pci_set_drvdata(pci, NULL); | 172 | pci_set_drvdata(pci, NULL); |
173 | } | 173 | } |
174 | 174 | ||
175 | static struct pci_driver driver = { | 175 | static struct pci_driver trident_driver = { |
176 | .name = KBUILD_MODNAME, | 176 | .name = KBUILD_MODNAME, |
177 | .id_table = snd_trident_ids, | 177 | .id_table = snd_trident_ids, |
178 | .probe = snd_trident_probe, | 178 | .probe = snd_trident_probe, |
@@ -183,15 +183,4 @@ static struct pci_driver driver = { | |||
183 | #endif | 183 | #endif |
184 | }; | 184 | }; |
185 | 185 | ||
186 | static int __init alsa_card_trident_init(void) | 186 | module_pci_driver(trident_driver); |
187 | { | ||
188 | return pci_register_driver(&driver); | ||
189 | } | ||
190 | |||
191 | static void __exit alsa_card_trident_exit(void) | ||
192 | { | ||
193 | pci_unregister_driver(&driver); | ||
194 | } | ||
195 | |||
196 | module_init(alsa_card_trident_init) | ||
197 | module_exit(alsa_card_trident_exit) | ||
diff --git a/sound/pci/via82xx.c b/sound/pci/via82xx.c index 75630408c6db..b5afab48943e 100644 --- a/sound/pci/via82xx.c +++ b/sound/pci/via82xx.c | |||
@@ -2619,7 +2619,7 @@ static void __devexit snd_via82xx_remove(struct pci_dev *pci) | |||
2619 | pci_set_drvdata(pci, NULL); | 2619 | pci_set_drvdata(pci, NULL); |
2620 | } | 2620 | } |
2621 | 2621 | ||
2622 | static struct pci_driver driver = { | 2622 | static struct pci_driver via82xx_driver = { |
2623 | .name = KBUILD_MODNAME, | 2623 | .name = KBUILD_MODNAME, |
2624 | .id_table = snd_via82xx_ids, | 2624 | .id_table = snd_via82xx_ids, |
2625 | .probe = snd_via82xx_probe, | 2625 | .probe = snd_via82xx_probe, |
@@ -2630,15 +2630,4 @@ static struct pci_driver driver = { | |||
2630 | #endif | 2630 | #endif |
2631 | }; | 2631 | }; |
2632 | 2632 | ||
2633 | static int __init alsa_card_via82xx_init(void) | 2633 | module_pci_driver(via82xx_driver); |
2634 | { | ||
2635 | return pci_register_driver(&driver); | ||
2636 | } | ||
2637 | |||
2638 | static void __exit alsa_card_via82xx_exit(void) | ||
2639 | { | ||
2640 | pci_unregister_driver(&driver); | ||
2641 | } | ||
2642 | |||
2643 | module_init(alsa_card_via82xx_init) | ||
2644 | module_exit(alsa_card_via82xx_exit) | ||
diff --git a/sound/pci/via82xx_modem.c b/sound/pci/via82xx_modem.c index 5efcbcac506a..59fd47ed0a31 100644 --- a/sound/pci/via82xx_modem.c +++ b/sound/pci/via82xx_modem.c | |||
@@ -1223,7 +1223,7 @@ static void __devexit snd_via82xx_remove(struct pci_dev *pci) | |||
1223 | pci_set_drvdata(pci, NULL); | 1223 | pci_set_drvdata(pci, NULL); |
1224 | } | 1224 | } |
1225 | 1225 | ||
1226 | static struct pci_driver driver = { | 1226 | static struct pci_driver via82xx_modem_driver = { |
1227 | .name = KBUILD_MODNAME, | 1227 | .name = KBUILD_MODNAME, |
1228 | .id_table = snd_via82xx_modem_ids, | 1228 | .id_table = snd_via82xx_modem_ids, |
1229 | .probe = snd_via82xx_probe, | 1229 | .probe = snd_via82xx_probe, |
@@ -1234,15 +1234,4 @@ static struct pci_driver driver = { | |||
1234 | #endif | 1234 | #endif |
1235 | }; | 1235 | }; |
1236 | 1236 | ||
1237 | static int __init alsa_card_via82xx_init(void) | 1237 | module_pci_driver(via82xx_modem_driver); |
1238 | { | ||
1239 | return pci_register_driver(&driver); | ||
1240 | } | ||
1241 | |||
1242 | static void __exit alsa_card_via82xx_exit(void) | ||
1243 | { | ||
1244 | pci_unregister_driver(&driver); | ||
1245 | } | ||
1246 | |||
1247 | module_init(alsa_card_via82xx_init) | ||
1248 | module_exit(alsa_card_via82xx_exit) | ||
diff --git a/sound/pci/vx222/vx222.c b/sound/pci/vx222/vx222.c index 6a534bfe1274..1ea1f656a5dc 100644 --- a/sound/pci/vx222/vx222.c +++ b/sound/pci/vx222/vx222.c | |||
@@ -289,7 +289,7 @@ static int snd_vx222_resume(struct pci_dev *pci) | |||
289 | } | 289 | } |
290 | #endif | 290 | #endif |
291 | 291 | ||
292 | static struct pci_driver driver = { | 292 | static struct pci_driver vx222_driver = { |
293 | .name = KBUILD_MODNAME, | 293 | .name = KBUILD_MODNAME, |
294 | .id_table = snd_vx222_ids, | 294 | .id_table = snd_vx222_ids, |
295 | .probe = snd_vx222_probe, | 295 | .probe = snd_vx222_probe, |
@@ -300,15 +300,4 @@ static struct pci_driver driver = { | |||
300 | #endif | 300 | #endif |
301 | }; | 301 | }; |
302 | 302 | ||
303 | static int __init alsa_card_vx222_init(void) | 303 | module_pci_driver(vx222_driver); |
304 | { | ||
305 | return pci_register_driver(&driver); | ||
306 | } | ||
307 | |||
308 | static void __exit alsa_card_vx222_exit(void) | ||
309 | { | ||
310 | pci_unregister_driver(&driver); | ||
311 | } | ||
312 | |||
313 | module_init(alsa_card_vx222_init) | ||
314 | module_exit(alsa_card_vx222_exit) | ||
diff --git a/sound/pci/ymfpci/ymfpci.c b/sound/pci/ymfpci/ymfpci.c index 94ab728f5ca8..9a1d01d653a7 100644 --- a/sound/pci/ymfpci/ymfpci.c +++ b/sound/pci/ymfpci/ymfpci.c | |||
@@ -350,7 +350,7 @@ static void __devexit snd_card_ymfpci_remove(struct pci_dev *pci) | |||
350 | pci_set_drvdata(pci, NULL); | 350 | pci_set_drvdata(pci, NULL); |
351 | } | 351 | } |
352 | 352 | ||
353 | static struct pci_driver driver = { | 353 | static struct pci_driver ymfpci_driver = { |
354 | .name = KBUILD_MODNAME, | 354 | .name = KBUILD_MODNAME, |
355 | .id_table = snd_ymfpci_ids, | 355 | .id_table = snd_ymfpci_ids, |
356 | .probe = snd_card_ymfpci_probe, | 356 | .probe = snd_card_ymfpci_probe, |
@@ -361,15 +361,4 @@ static struct pci_driver driver = { | |||
361 | #endif | 361 | #endif |
362 | }; | 362 | }; |
363 | 363 | ||
364 | static int __init alsa_card_ymfpci_init(void) | 364 | module_pci_driver(ymfpci_driver); |
365 | { | ||
366 | return pci_register_driver(&driver); | ||
367 | } | ||
368 | |||
369 | static void __exit alsa_card_ymfpci_exit(void) | ||
370 | { | ||
371 | pci_unregister_driver(&driver); | ||
372 | } | ||
373 | |||
374 | module_init(alsa_card_ymfpci_init) | ||
375 | module_exit(alsa_card_ymfpci_exit) | ||
diff --git a/sound/sh/sh_dac_audio.c b/sound/sh/sh_dac_audio.c index b11f82b5718f..f8b01c77b298 100644 --- a/sound/sh/sh_dac_audio.c +++ b/sound/sh/sh_dac_audio.c | |||
@@ -433,7 +433,7 @@ probe_error: | |||
433 | /* | 433 | /* |
434 | * "driver" definition | 434 | * "driver" definition |
435 | */ | 435 | */ |
436 | static struct platform_driver driver = { | 436 | static struct platform_driver sh_dac_driver = { |
437 | .probe = snd_sh_dac_probe, | 437 | .probe = snd_sh_dac_probe, |
438 | .remove = snd_sh_dac_remove, | 438 | .remove = snd_sh_dac_remove, |
439 | .driver = { | 439 | .driver = { |
@@ -441,4 +441,4 @@ static struct platform_driver driver = { | |||
441 | }, | 441 | }, |
442 | }; | 442 | }; |
443 | 443 | ||
444 | module_platform_driver(driver); | 444 | module_platform_driver(sh_dac_driver); |
diff --git a/sound/soc/Kconfig b/sound/soc/Kconfig index 91c985599d32..40b2ad1bb1cd 100644 --- a/sound/soc/Kconfig +++ b/sound/soc/Kconfig | |||
@@ -35,7 +35,6 @@ source "sound/soc/blackfin/Kconfig" | |||
35 | source "sound/soc/davinci/Kconfig" | 35 | source "sound/soc/davinci/Kconfig" |
36 | source "sound/soc/ep93xx/Kconfig" | 36 | source "sound/soc/ep93xx/Kconfig" |
37 | source "sound/soc/fsl/Kconfig" | 37 | source "sound/soc/fsl/Kconfig" |
38 | source "sound/soc/imx/Kconfig" | ||
39 | source "sound/soc/jz4740/Kconfig" | 38 | source "sound/soc/jz4740/Kconfig" |
40 | source "sound/soc/nuc900/Kconfig" | 39 | source "sound/soc/nuc900/Kconfig" |
41 | source "sound/soc/omap/Kconfig" | 40 | source "sound/soc/omap/Kconfig" |
@@ -48,9 +47,13 @@ source "sound/soc/s6000/Kconfig" | |||
48 | source "sound/soc/sh/Kconfig" | 47 | source "sound/soc/sh/Kconfig" |
49 | source "sound/soc/tegra/Kconfig" | 48 | source "sound/soc/tegra/Kconfig" |
50 | source "sound/soc/txx9/Kconfig" | 49 | source "sound/soc/txx9/Kconfig" |
50 | source "sound/soc/ux500/Kconfig" | ||
51 | 51 | ||
52 | # Supported codecs | 52 | # Supported codecs |
53 | source "sound/soc/codecs/Kconfig" | 53 | source "sound/soc/codecs/Kconfig" |
54 | 54 | ||
55 | # generic frame-work | ||
56 | source "sound/soc/generic/Kconfig" | ||
57 | |||
55 | endif # SND_SOC | 58 | endif # SND_SOC |
56 | 59 | ||
diff --git a/sound/soc/Makefile b/sound/soc/Makefile index 2feaf376e94b..70990f4017f4 100644 --- a/sound/soc/Makefile +++ b/sound/soc/Makefile | |||
@@ -6,13 +6,13 @@ obj-$(CONFIG_SND_SOC_DMAENGINE_PCM) += snd-soc-dmaengine-pcm.o | |||
6 | 6 | ||
7 | obj-$(CONFIG_SND_SOC) += snd-soc-core.o | 7 | obj-$(CONFIG_SND_SOC) += snd-soc-core.o |
8 | obj-$(CONFIG_SND_SOC) += codecs/ | 8 | obj-$(CONFIG_SND_SOC) += codecs/ |
9 | obj-$(CONFIG_SND_SOC) += generic/ | ||
9 | obj-$(CONFIG_SND_SOC) += atmel/ | 10 | obj-$(CONFIG_SND_SOC) += atmel/ |
10 | obj-$(CONFIG_SND_SOC) += au1x/ | 11 | obj-$(CONFIG_SND_SOC) += au1x/ |
11 | obj-$(CONFIG_SND_SOC) += blackfin/ | 12 | obj-$(CONFIG_SND_SOC) += blackfin/ |
12 | obj-$(CONFIG_SND_SOC) += davinci/ | 13 | obj-$(CONFIG_SND_SOC) += davinci/ |
13 | obj-$(CONFIG_SND_SOC) += ep93xx/ | 14 | obj-$(CONFIG_SND_SOC) += ep93xx/ |
14 | obj-$(CONFIG_SND_SOC) += fsl/ | 15 | obj-$(CONFIG_SND_SOC) += fsl/ |
15 | obj-$(CONFIG_SND_SOC) += imx/ | ||
16 | obj-$(CONFIG_SND_SOC) += jz4740/ | 16 | obj-$(CONFIG_SND_SOC) += jz4740/ |
17 | obj-$(CONFIG_SND_SOC) += mid-x86/ | 17 | obj-$(CONFIG_SND_SOC) += mid-x86/ |
18 | obj-$(CONFIG_SND_SOC) += mxs/ | 18 | obj-$(CONFIG_SND_SOC) += mxs/ |
@@ -25,3 +25,4 @@ obj-$(CONFIG_SND_SOC) += s6000/ | |||
25 | obj-$(CONFIG_SND_SOC) += sh/ | 25 | obj-$(CONFIG_SND_SOC) += sh/ |
26 | obj-$(CONFIG_SND_SOC) += tegra/ | 26 | obj-$(CONFIG_SND_SOC) += tegra/ |
27 | obj-$(CONFIG_SND_SOC) += txx9/ | 27 | obj-$(CONFIG_SND_SOC) += txx9/ |
28 | obj-$(CONFIG_SND_SOC) += ux500/ | ||
diff --git a/sound/soc/blackfin/bf5xx-ssm2602.c b/sound/soc/blackfin/bf5xx-ssm2602.c index b39ad356b92b..7dbeef1099b4 100644 --- a/sound/soc/blackfin/bf5xx-ssm2602.c +++ b/sound/soc/blackfin/bf5xx-ssm2602.c | |||
@@ -44,16 +44,8 @@ | |||
44 | 44 | ||
45 | static struct snd_soc_card bf5xx_ssm2602; | 45 | static struct snd_soc_card bf5xx_ssm2602; |
46 | 46 | ||
47 | static int bf5xx_ssm2602_hw_params(struct snd_pcm_substream *substream, | 47 | static int bf5xx_ssm2602_dai_init(struct snd_soc_pcm_runtime *rtd) |
48 | struct snd_pcm_hw_params *params) | ||
49 | { | 48 | { |
50 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
51 | struct snd_soc_dai *codec_dai = rtd->codec_dai; | ||
52 | unsigned int clk = 0; | ||
53 | int ret = 0; | ||
54 | |||
55 | pr_debug("%s rate %d format %x\n", __func__, params_rate(params), | ||
56 | params_format(params)); | ||
57 | /* | 49 | /* |
58 | * If you are using a crystal source which frequency is not 12MHz | 50 | * If you are using a crystal source which frequency is not 12MHz |
59 | * then modify the below case statement with frequency of the crystal. | 51 | * then modify the below case statement with frequency of the crystal. |
@@ -61,31 +53,10 @@ static int bf5xx_ssm2602_hw_params(struct snd_pcm_substream *substream, | |||
61 | * If you are using the SPORT to generate clocking then this is | 53 | * If you are using the SPORT to generate clocking then this is |
62 | * where to do it. | 54 | * where to do it. |
63 | */ | 55 | */ |
64 | 56 | return snd_soc_dai_set_sysclk(rtd->codec_dai, SSM2602_SYSCLK, 12000000, | |
65 | switch (params_rate(params)) { | ||
66 | case 8000: | ||
67 | case 16000: | ||
68 | case 48000: | ||
69 | case 96000: | ||
70 | case 11025: | ||
71 | case 22050: | ||
72 | case 44100: | ||
73 | clk = 12000000; | ||
74 | break; | ||
75 | } | ||
76 | |||
77 | ret = snd_soc_dai_set_sysclk(codec_dai, SSM2602_SYSCLK, clk, | ||
78 | SND_SOC_CLOCK_IN); | 57 | SND_SOC_CLOCK_IN); |
79 | if (ret < 0) | ||
80 | return ret; | ||
81 | |||
82 | return 0; | ||
83 | } | 58 | } |
84 | 59 | ||
85 | static struct snd_soc_ops bf5xx_ssm2602_ops = { | ||
86 | .hw_params = bf5xx_ssm2602_hw_params, | ||
87 | }; | ||
88 | |||
89 | /* CODEC is master for BCLK and LRC in this configuration. */ | 60 | /* CODEC is master for BCLK and LRC in this configuration. */ |
90 | #define BF5XX_SSM2602_DAIFMT (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | \ | 61 | #define BF5XX_SSM2602_DAIFMT (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | \ |
91 | SND_SOC_DAIFMT_CBM_CFM) | 62 | SND_SOC_DAIFMT_CBM_CFM) |
@@ -98,7 +69,7 @@ static struct snd_soc_dai_link bf5xx_ssm2602_dai[] = { | |||
98 | .codec_dai_name = "ssm2602-hifi", | 69 | .codec_dai_name = "ssm2602-hifi", |
99 | .platform_name = "bfin-i2s-pcm-audio", | 70 | .platform_name = "bfin-i2s-pcm-audio", |
100 | .codec_name = "ssm2602.0-001b", | 71 | .codec_name = "ssm2602.0-001b", |
101 | .ops = &bf5xx_ssm2602_ops, | 72 | .init = bf5xx_ssm2602_dai_init, |
102 | .dai_fmt = BF5XX_SSM2602_DAIFMT, | 73 | .dai_fmt = BF5XX_SSM2602_DAIFMT, |
103 | }, | 74 | }, |
104 | { | 75 | { |
@@ -108,7 +79,7 @@ static struct snd_soc_dai_link bf5xx_ssm2602_dai[] = { | |||
108 | .codec_dai_name = "ssm2602-hifi", | 79 | .codec_dai_name = "ssm2602-hifi", |
109 | .platform_name = "bfin-i2s-pcm-audio", | 80 | .platform_name = "bfin-i2s-pcm-audio", |
110 | .codec_name = "ssm2602.0-001b", | 81 | .codec_name = "ssm2602.0-001b", |
111 | .ops = &bf5xx_ssm2602_ops, | 82 | .init = bf5xx_ssm2602_dai_init, |
112 | .dai_fmt = BF5XX_SSM2602_DAIFMT, | 83 | .dai_fmt = BF5XX_SSM2602_DAIFMT, |
113 | }, | 84 | }, |
114 | }; | 85 | }; |
diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig index 59d8efaa17e9..1e1613a438dd 100644 --- a/sound/soc/codecs/Kconfig +++ b/sound/soc/codecs/Kconfig | |||
@@ -29,6 +29,7 @@ config SND_SOC_ALL_CODECS | |||
29 | select SND_SOC_ALC5632 if I2C | 29 | select SND_SOC_ALC5632 if I2C |
30 | select SND_SOC_CQ0093VC if MFD_DAVINCI_VOICECODEC | 30 | select SND_SOC_CQ0093VC if MFD_DAVINCI_VOICECODEC |
31 | select SND_SOC_CS42L51 if I2C | 31 | select SND_SOC_CS42L51 if I2C |
32 | select SND_SOC_CS42L52 if I2C | ||
32 | select SND_SOC_CS42L73 if I2C | 33 | select SND_SOC_CS42L73 if I2C |
33 | select SND_SOC_CS4270 if I2C | 34 | select SND_SOC_CS4270 if I2C |
34 | select SND_SOC_CS4271 if SND_SOC_I2C_AND_SPI | 35 | select SND_SOC_CS4271 if SND_SOC_I2C_AND_SPI |
@@ -37,11 +38,15 @@ config SND_SOC_ALL_CODECS | |||
37 | select SND_SOC_DFBMCS320 | 38 | select SND_SOC_DFBMCS320 |
38 | select SND_SOC_JZ4740_CODEC | 39 | select SND_SOC_JZ4740_CODEC |
39 | select SND_SOC_LM4857 if I2C | 40 | select SND_SOC_LM4857 if I2C |
41 | select SND_SOC_LM49453 if I2C | ||
40 | select SND_SOC_MAX98088 if I2C | 42 | select SND_SOC_MAX98088 if I2C |
41 | select SND_SOC_MAX98095 if I2C | 43 | select SND_SOC_MAX98095 if I2C |
42 | select SND_SOC_MAX9850 if I2C | 44 | select SND_SOC_MAX9850 if I2C |
43 | select SND_SOC_MAX9768 if I2C | 45 | select SND_SOC_MAX9768 if I2C |
44 | select SND_SOC_MAX9877 if I2C | 46 | select SND_SOC_MAX9877 if I2C |
47 | select SND_SOC_MC13783 if MFD_MC13XXX | ||
48 | select SND_SOC_ML26124 if I2C | ||
49 | select SND_SOC_OMAP_HDMI_CODEC if OMAP4_DSS_HDMI | ||
45 | select SND_SOC_PCM3008 | 50 | select SND_SOC_PCM3008 |
46 | select SND_SOC_RT5631 if I2C | 51 | select SND_SOC_RT5631 if I2C |
47 | select SND_SOC_SGTL5000 if I2C | 52 | select SND_SOC_SGTL5000 if I2C |
@@ -181,6 +186,9 @@ config SND_SOC_CQ0093VC | |||
181 | config SND_SOC_CS42L51 | 186 | config SND_SOC_CS42L51 |
182 | tristate | 187 | tristate |
183 | 188 | ||
189 | config SND_SOC_CS42L52 | ||
190 | tristate | ||
191 | |||
184 | config SND_SOC_CS42L73 | 192 | config SND_SOC_CS42L73 |
185 | tristate | 193 | tristate |
186 | 194 | ||
@@ -217,6 +225,9 @@ config SND_SOC_DFBMCS320 | |||
217 | config SND_SOC_DMIC | 225 | config SND_SOC_DMIC |
218 | tristate | 226 | tristate |
219 | 227 | ||
228 | config SND_SOC_LM49453 | ||
229 | tristate | ||
230 | |||
220 | config SND_SOC_MAX98088 | 231 | config SND_SOC_MAX98088 |
221 | tristate | 232 | tristate |
222 | 233 | ||
@@ -226,6 +237,9 @@ config SND_SOC_MAX98095 | |||
226 | config SND_SOC_MAX9850 | 237 | config SND_SOC_MAX9850 |
227 | tristate | 238 | tristate |
228 | 239 | ||
240 | config SND_SOC_OMAP_HDMI_CODEC | ||
241 | tristate | ||
242 | |||
229 | config SND_SOC_PCM3008 | 243 | config SND_SOC_PCM3008 |
230 | tristate | 244 | tristate |
231 | 245 | ||
@@ -435,5 +449,11 @@ config SND_SOC_MAX9768 | |||
435 | config SND_SOC_MAX9877 | 449 | config SND_SOC_MAX9877 |
436 | tristate | 450 | tristate |
437 | 451 | ||
452 | config SND_SOC_MC13783 | ||
453 | tristate | ||
454 | |||
455 | config SND_SOC_ML26124 | ||
456 | tristate | ||
457 | |||
438 | config SND_SOC_TPA6130A2 | 458 | config SND_SOC_TPA6130A2 |
439 | tristate | 459 | tristate |
diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile index 6662eb0cdcc0..fc27fec39487 100644 --- a/sound/soc/codecs/Makefile +++ b/sound/soc/codecs/Makefile | |||
@@ -15,6 +15,7 @@ snd-soc-ak4642-objs := ak4642.o | |||
15 | snd-soc-ak4671-objs := ak4671.o | 15 | snd-soc-ak4671-objs := ak4671.o |
16 | snd-soc-cq93vc-objs := cq93vc.o | 16 | snd-soc-cq93vc-objs := cq93vc.o |
17 | snd-soc-cs42l51-objs := cs42l51.o | 17 | snd-soc-cs42l51-objs := cs42l51.o |
18 | snd-soc-cs42l52-objs := cs42l52.o | ||
18 | snd-soc-cs42l73-objs := cs42l73.o | 19 | snd-soc-cs42l73-objs := cs42l73.o |
19 | snd-soc-cs4270-objs := cs4270.o | 20 | snd-soc-cs4270-objs := cs4270.o |
20 | snd-soc-cs4271-objs := cs4271.o | 21 | snd-soc-cs4271-objs := cs4271.o |
@@ -25,10 +26,14 @@ snd-soc-dmic-objs := dmic.o | |||
25 | snd-soc-jz4740-codec-objs := jz4740.o | 26 | snd-soc-jz4740-codec-objs := jz4740.o |
26 | snd-soc-l3-objs := l3.o | 27 | snd-soc-l3-objs := l3.o |
27 | snd-soc-lm4857-objs := lm4857.o | 28 | snd-soc-lm4857-objs := lm4857.o |
29 | snd-soc-lm49453-objs := lm49453.o | ||
28 | snd-soc-max9768-objs := max9768.o | 30 | snd-soc-max9768-objs := max9768.o |
29 | snd-soc-max98088-objs := max98088.o | 31 | snd-soc-max98088-objs := max98088.o |
30 | snd-soc-max98095-objs := max98095.o | 32 | snd-soc-max98095-objs := max98095.o |
31 | snd-soc-max9850-objs := max9850.o | 33 | snd-soc-max9850-objs := max9850.o |
34 | snd-soc-mc13783-objs := mc13783.o | ||
35 | snd-soc-ml26124-objs := ml26124.o | ||
36 | snd-soc-omap-hdmi-codec-objs := omap-hdmi.o | ||
32 | snd-soc-pcm3008-objs := pcm3008.o | 37 | snd-soc-pcm3008-objs := pcm3008.o |
33 | snd-soc-rt5631-objs := rt5631.o | 38 | snd-soc-rt5631-objs := rt5631.o |
34 | snd-soc-sgtl5000-objs := sgtl5000.o | 39 | snd-soc-sgtl5000-objs := sgtl5000.o |
@@ -121,6 +126,7 @@ obj-$(CONFIG_SND_SOC_ALC5623) += snd-soc-alc5623.o | |||
121 | obj-$(CONFIG_SND_SOC_ALC5632) += snd-soc-alc5632.o | 126 | obj-$(CONFIG_SND_SOC_ALC5632) += snd-soc-alc5632.o |
122 | obj-$(CONFIG_SND_SOC_CQ0093VC) += snd-soc-cq93vc.o | 127 | obj-$(CONFIG_SND_SOC_CQ0093VC) += snd-soc-cq93vc.o |
123 | obj-$(CONFIG_SND_SOC_CS42L51) += snd-soc-cs42l51.o | 128 | obj-$(CONFIG_SND_SOC_CS42L51) += snd-soc-cs42l51.o |
129 | obj-$(CONFIG_SND_SOC_CS42L52) += snd-soc-cs42l52.o | ||
124 | obj-$(CONFIG_SND_SOC_CS42L73) += snd-soc-cs42l73.o | 130 | obj-$(CONFIG_SND_SOC_CS42L73) += snd-soc-cs42l73.o |
125 | obj-$(CONFIG_SND_SOC_CS4270) += snd-soc-cs4270.o | 131 | obj-$(CONFIG_SND_SOC_CS4270) += snd-soc-cs4270.o |
126 | obj-$(CONFIG_SND_SOC_CS4271) += snd-soc-cs4271.o | 132 | obj-$(CONFIG_SND_SOC_CS4271) += snd-soc-cs4271.o |
@@ -128,13 +134,17 @@ obj-$(CONFIG_SND_SOC_CX20442) += snd-soc-cx20442.o | |||
128 | obj-$(CONFIG_SND_SOC_DA7210) += snd-soc-da7210.o | 134 | obj-$(CONFIG_SND_SOC_DA7210) += snd-soc-da7210.o |
129 | obj-$(CONFIG_SND_SOC_DFBMCS320) += snd-soc-dfbmcs320.o | 135 | obj-$(CONFIG_SND_SOC_DFBMCS320) += snd-soc-dfbmcs320.o |
130 | obj-$(CONFIG_SND_SOC_DMIC) += snd-soc-dmic.o | 136 | obj-$(CONFIG_SND_SOC_DMIC) += snd-soc-dmic.o |
137 | obj-$(CONFIG_SND_SOC_JZ4740_CODEC) += snd-soc-jz4740-codec.o | ||
131 | obj-$(CONFIG_SND_SOC_L3) += snd-soc-l3.o | 138 | obj-$(CONFIG_SND_SOC_L3) += snd-soc-l3.o |
132 | obj-$(CONFIG_SND_SOC_LM4857) += snd-soc-lm4857.o | 139 | obj-$(CONFIG_SND_SOC_LM4857) += snd-soc-lm4857.o |
133 | obj-$(CONFIG_SND_SOC_JZ4740_CODEC) += snd-soc-jz4740-codec.o | 140 | obj-$(CONFIG_SND_SOC_LM49453) += snd-soc-lm49453.o |
134 | obj-$(CONFIG_SND_SOC_MAX9768) += snd-soc-max9768.o | 141 | obj-$(CONFIG_SND_SOC_MAX9768) += snd-soc-max9768.o |
135 | obj-$(CONFIG_SND_SOC_MAX98088) += snd-soc-max98088.o | 142 | obj-$(CONFIG_SND_SOC_MAX98088) += snd-soc-max98088.o |
136 | obj-$(CONFIG_SND_SOC_MAX98095) += snd-soc-max98095.o | 143 | obj-$(CONFIG_SND_SOC_MAX98095) += snd-soc-max98095.o |
137 | obj-$(CONFIG_SND_SOC_MAX9850) += snd-soc-max9850.o | 144 | obj-$(CONFIG_SND_SOC_MAX9850) += snd-soc-max9850.o |
145 | obj-$(CONFIG_SND_SOC_MC13783) += snd-soc-mc13783.o | ||
146 | obj-$(CONFIG_SND_SOC_ML26124) += snd-soc-ml26124.o | ||
147 | obj-$(CONFIG_SND_SOC_OMAP_HDMI_CODEC) += snd-soc-omap-hdmi-codec.o | ||
138 | obj-$(CONFIG_SND_SOC_PCM3008) += snd-soc-pcm3008.o | 148 | obj-$(CONFIG_SND_SOC_PCM3008) += snd-soc-pcm3008.o |
139 | obj-$(CONFIG_SND_SOC_RT5631) += snd-soc-rt5631.o | 149 | obj-$(CONFIG_SND_SOC_RT5631) += snd-soc-rt5631.o |
140 | obj-$(CONFIG_SND_SOC_SGTL5000) += snd-soc-sgtl5000.o | 150 | obj-$(CONFIG_SND_SOC_SGTL5000) += snd-soc-sgtl5000.o |
diff --git a/sound/soc/codecs/ac97.c b/sound/soc/codecs/ac97.c index 1bbad4c16d28..2023c749f232 100644 --- a/sound/soc/codecs/ac97.c +++ b/sound/soc/codecs/ac97.c | |||
@@ -26,13 +26,11 @@ | |||
26 | static int ac97_prepare(struct snd_pcm_substream *substream, | 26 | static int ac97_prepare(struct snd_pcm_substream *substream, |
27 | struct snd_soc_dai *dai) | 27 | struct snd_soc_dai *dai) |
28 | { | 28 | { |
29 | struct snd_pcm_runtime *runtime = substream->runtime; | 29 | struct snd_soc_codec *codec = dai->codec; |
30 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
31 | struct snd_soc_codec *codec = rtd->codec; | ||
32 | 30 | ||
33 | int reg = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ? | 31 | int reg = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ? |
34 | AC97_PCM_FRONT_DAC_RATE : AC97_PCM_LR_ADC_RATE; | 32 | AC97_PCM_FRONT_DAC_RATE : AC97_PCM_LR_ADC_RATE; |
35 | return snd_ac97_set_rate(codec->ac97, reg, runtime->rate); | 33 | return snd_ac97_set_rate(codec->ac97, reg, substream->runtime->rate); |
36 | } | 34 | } |
37 | 35 | ||
38 | #define STD_AC97_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\ | 36 | #define STD_AC97_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\ |
diff --git a/sound/soc/codecs/ad1836.c b/sound/soc/codecs/ad1836.c index 12e3b4118557..c67b50d8b317 100644 --- a/sound/soc/codecs/ad1836.c +++ b/sound/soc/codecs/ad1836.c | |||
@@ -162,9 +162,7 @@ static int ad1836_hw_params(struct snd_pcm_substream *substream, | |||
162 | struct snd_soc_dai *dai) | 162 | struct snd_soc_dai *dai) |
163 | { | 163 | { |
164 | int word_len = 0; | 164 | int word_len = 0; |
165 | 165 | struct snd_soc_codec *codec = dai->codec; | |
166 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
167 | struct snd_soc_codec *codec = rtd->codec; | ||
168 | 166 | ||
169 | /* bit size */ | 167 | /* bit size */ |
170 | switch (params_format(params)) { | 168 | switch (params_format(params)) { |
diff --git a/sound/soc/codecs/ad193x.c b/sound/soc/codecs/ad193x.c index a4a6bef2c0bb..13e62be4f990 100644 --- a/sound/soc/codecs/ad193x.c +++ b/sound/soc/codecs/ad193x.c | |||
@@ -245,9 +245,7 @@ static int ad193x_hw_params(struct snd_pcm_substream *substream, | |||
245 | struct snd_soc_dai *dai) | 245 | struct snd_soc_dai *dai) |
246 | { | 246 | { |
247 | int word_len = 0, master_rate = 0; | 247 | int word_len = 0, master_rate = 0; |
248 | 248 | struct snd_soc_codec *codec = dai->codec; | |
249 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
250 | struct snd_soc_codec *codec = rtd->codec; | ||
251 | struct ad193x_priv *ad193x = snd_soc_codec_get_drvdata(codec); | 249 | struct ad193x_priv *ad193x = snd_soc_codec_get_drvdata(codec); |
252 | 250 | ||
253 | /* bit size */ | 251 | /* bit size */ |
diff --git a/sound/soc/codecs/adau1701.c b/sound/soc/codecs/adau1701.c index 78e9ce48bb99..3d50fc8646b6 100644 --- a/sound/soc/codecs/adau1701.c +++ b/sound/soc/codecs/adau1701.c | |||
@@ -258,8 +258,7 @@ static int adau1701_set_playback_pcm_format(struct snd_soc_codec *codec, | |||
258 | static int adau1701_hw_params(struct snd_pcm_substream *substream, | 258 | static int adau1701_hw_params(struct snd_pcm_substream *substream, |
259 | struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) | 259 | struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) |
260 | { | 260 | { |
261 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 261 | struct snd_soc_codec *codec = dai->codec; |
262 | struct snd_soc_codec *codec = rtd->codec; | ||
263 | snd_pcm_format_t format; | 262 | snd_pcm_format_t format; |
264 | unsigned int val; | 263 | unsigned int val; |
265 | 264 | ||
diff --git a/sound/soc/codecs/ak4104.c b/sound/soc/codecs/ak4104.c index ceb96ecf5588..31d4483245d0 100644 --- a/sound/soc/codecs/ak4104.c +++ b/sound/soc/codecs/ak4104.c | |||
@@ -88,8 +88,7 @@ static int ak4104_hw_params(struct snd_pcm_substream *substream, | |||
88 | struct snd_pcm_hw_params *params, | 88 | struct snd_pcm_hw_params *params, |
89 | struct snd_soc_dai *dai) | 89 | struct snd_soc_dai *dai) |
90 | { | 90 | { |
91 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 91 | struct snd_soc_codec *codec = dai->codec; |
92 | struct snd_soc_codec *codec = rtd->codec; | ||
93 | int val = 0; | 92 | int val = 0; |
94 | 93 | ||
95 | /* set the IEC958 bits: consumer mode, no copyright bit */ | 94 | /* set the IEC958 bits: consumer mode, no copyright bit */ |
diff --git a/sound/soc/codecs/ak4535.c b/sound/soc/codecs/ak4535.c index 838ae8b22b50..618fdc30f73e 100644 --- a/sound/soc/codecs/ak4535.c +++ b/sound/soc/codecs/ak4535.c | |||
@@ -262,8 +262,7 @@ static int ak4535_hw_params(struct snd_pcm_substream *substream, | |||
262 | struct snd_pcm_hw_params *params, | 262 | struct snd_pcm_hw_params *params, |
263 | struct snd_soc_dai *dai) | 263 | struct snd_soc_dai *dai) |
264 | { | 264 | { |
265 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 265 | struct snd_soc_codec *codec = dai->codec; |
266 | struct snd_soc_codec *codec = rtd->codec; | ||
267 | struct ak4535_priv *ak4535 = snd_soc_codec_get_drvdata(codec); | 266 | struct ak4535_priv *ak4535 = snd_soc_codec_get_drvdata(codec); |
268 | u8 mode2 = snd_soc_read(codec, AK4535_MODE2) & ~(0x3 << 5); | 267 | u8 mode2 = snd_soc_read(codec, AK4535_MODE2) & ~(0x3 << 5); |
269 | int rate = params_rate(params), fs = 256; | 268 | int rate = params_rate(params), fs = 256; |
diff --git a/sound/soc/codecs/ak4641.c b/sound/soc/codecs/ak4641.c index c4d165a4bddf..543a12f471be 100644 --- a/sound/soc/codecs/ak4641.c +++ b/sound/soc/codecs/ak4641.c | |||
@@ -296,8 +296,7 @@ static int ak4641_i2s_hw_params(struct snd_pcm_substream *substream, | |||
296 | struct snd_pcm_hw_params *params, | 296 | struct snd_pcm_hw_params *params, |
297 | struct snd_soc_dai *dai) | 297 | struct snd_soc_dai *dai) |
298 | { | 298 | { |
299 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 299 | struct snd_soc_codec *codec = dai->codec; |
300 | struct snd_soc_codec *codec = rtd->codec; | ||
301 | struct ak4641_priv *ak4641 = snd_soc_codec_get_drvdata(codec); | 300 | struct ak4641_priv *ak4641 = snd_soc_codec_get_drvdata(codec); |
302 | int rate = params_rate(params), fs = 256; | 301 | int rate = params_rate(params), fs = 256; |
303 | u8 mode2; | 302 | u8 mode2; |
@@ -517,67 +516,24 @@ static int ak4641_resume(struct snd_soc_codec *codec) | |||
517 | 516 | ||
518 | static int ak4641_probe(struct snd_soc_codec *codec) | 517 | static int ak4641_probe(struct snd_soc_codec *codec) |
519 | { | 518 | { |
520 | struct ak4641_platform_data *pdata = codec->dev->platform_data; | ||
521 | int ret; | 519 | int ret; |
522 | 520 | ||
523 | |||
524 | if (pdata) { | ||
525 | if (gpio_is_valid(pdata->gpio_power)) { | ||
526 | ret = gpio_request_one(pdata->gpio_power, | ||
527 | GPIOF_OUT_INIT_LOW, "ak4641 power"); | ||
528 | if (ret) | ||
529 | goto err_out; | ||
530 | } | ||
531 | if (gpio_is_valid(pdata->gpio_npdn)) { | ||
532 | ret = gpio_request_one(pdata->gpio_npdn, | ||
533 | GPIOF_OUT_INIT_LOW, "ak4641 npdn"); | ||
534 | if (ret) | ||
535 | goto err_gpio; | ||
536 | |||
537 | udelay(1); /* > 150 ns */ | ||
538 | gpio_set_value(pdata->gpio_npdn, 1); | ||
539 | } | ||
540 | } | ||
541 | |||
542 | ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_I2C); | 521 | ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_I2C); |
543 | if (ret != 0) { | 522 | if (ret != 0) { |
544 | dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); | 523 | dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); |
545 | goto err_register; | 524 | return ret; |
546 | } | 525 | } |
547 | 526 | ||
548 | /* power on device */ | 527 | /* power on device */ |
549 | ak4641_set_bias_level(codec, SND_SOC_BIAS_STANDBY); | 528 | ak4641_set_bias_level(codec, SND_SOC_BIAS_STANDBY); |
550 | 529 | ||
551 | return 0; | 530 | return 0; |
552 | |||
553 | err_register: | ||
554 | if (pdata) { | ||
555 | if (gpio_is_valid(pdata->gpio_power)) | ||
556 | gpio_set_value(pdata->gpio_power, 0); | ||
557 | if (gpio_is_valid(pdata->gpio_npdn)) | ||
558 | gpio_free(pdata->gpio_npdn); | ||
559 | } | ||
560 | err_gpio: | ||
561 | if (pdata && gpio_is_valid(pdata->gpio_power)) | ||
562 | gpio_free(pdata->gpio_power); | ||
563 | err_out: | ||
564 | return ret; | ||
565 | } | 531 | } |
566 | 532 | ||
567 | static int ak4641_remove(struct snd_soc_codec *codec) | 533 | static int ak4641_remove(struct snd_soc_codec *codec) |
568 | { | 534 | { |
569 | struct ak4641_platform_data *pdata = codec->dev->platform_data; | ||
570 | |||
571 | ak4641_set_bias_level(codec, SND_SOC_BIAS_OFF); | 535 | ak4641_set_bias_level(codec, SND_SOC_BIAS_OFF); |
572 | 536 | ||
573 | if (pdata) { | ||
574 | if (gpio_is_valid(pdata->gpio_power)) { | ||
575 | gpio_set_value(pdata->gpio_power, 0); | ||
576 | gpio_free(pdata->gpio_power); | ||
577 | } | ||
578 | if (gpio_is_valid(pdata->gpio_npdn)) | ||
579 | gpio_free(pdata->gpio_npdn); | ||
580 | } | ||
581 | return 0; | 537 | return 0; |
582 | } | 538 | } |
583 | 539 | ||
@@ -604,6 +560,7 @@ static struct snd_soc_codec_driver soc_codec_dev_ak4641 = { | |||
604 | static int __devinit ak4641_i2c_probe(struct i2c_client *i2c, | 560 | static int __devinit ak4641_i2c_probe(struct i2c_client *i2c, |
605 | const struct i2c_device_id *id) | 561 | const struct i2c_device_id *id) |
606 | { | 562 | { |
563 | struct ak4641_platform_data *pdata = i2c->dev.platform_data; | ||
607 | struct ak4641_priv *ak4641; | 564 | struct ak4641_priv *ak4641; |
608 | int ret; | 565 | int ret; |
609 | 566 | ||
@@ -612,16 +569,62 @@ static int __devinit ak4641_i2c_probe(struct i2c_client *i2c, | |||
612 | if (!ak4641) | 569 | if (!ak4641) |
613 | return -ENOMEM; | 570 | return -ENOMEM; |
614 | 571 | ||
572 | if (pdata) { | ||
573 | if (gpio_is_valid(pdata->gpio_power)) { | ||
574 | ret = gpio_request_one(pdata->gpio_power, | ||
575 | GPIOF_OUT_INIT_LOW, "ak4641 power"); | ||
576 | if (ret) | ||
577 | goto err_out; | ||
578 | } | ||
579 | if (gpio_is_valid(pdata->gpio_npdn)) { | ||
580 | ret = gpio_request_one(pdata->gpio_npdn, | ||
581 | GPIOF_OUT_INIT_LOW, "ak4641 npdn"); | ||
582 | if (ret) | ||
583 | goto err_gpio; | ||
584 | |||
585 | udelay(1); /* > 150 ns */ | ||
586 | gpio_set_value(pdata->gpio_npdn, 1); | ||
587 | } | ||
588 | } | ||
589 | |||
615 | i2c_set_clientdata(i2c, ak4641); | 590 | i2c_set_clientdata(i2c, ak4641); |
616 | 591 | ||
617 | ret = snd_soc_register_codec(&i2c->dev, &soc_codec_dev_ak4641, | 592 | ret = snd_soc_register_codec(&i2c->dev, &soc_codec_dev_ak4641, |
618 | ak4641_dai, ARRAY_SIZE(ak4641_dai)); | 593 | ak4641_dai, ARRAY_SIZE(ak4641_dai)); |
594 | if (ret != 0) | ||
595 | goto err_gpio2; | ||
596 | |||
597 | return 0; | ||
598 | |||
599 | err_gpio2: | ||
600 | if (pdata) { | ||
601 | if (gpio_is_valid(pdata->gpio_power)) | ||
602 | gpio_set_value(pdata->gpio_power, 0); | ||
603 | if (gpio_is_valid(pdata->gpio_npdn)) | ||
604 | gpio_free(pdata->gpio_npdn); | ||
605 | } | ||
606 | err_gpio: | ||
607 | if (pdata && gpio_is_valid(pdata->gpio_power)) | ||
608 | gpio_free(pdata->gpio_power); | ||
609 | err_out: | ||
619 | return ret; | 610 | return ret; |
620 | } | 611 | } |
621 | 612 | ||
622 | static int __devexit ak4641_i2c_remove(struct i2c_client *i2c) | 613 | static int __devexit ak4641_i2c_remove(struct i2c_client *i2c) |
623 | { | 614 | { |
615 | struct ak4641_platform_data *pdata = i2c->dev.platform_data; | ||
616 | |||
624 | snd_soc_unregister_codec(&i2c->dev); | 617 | snd_soc_unregister_codec(&i2c->dev); |
618 | |||
619 | if (pdata) { | ||
620 | if (gpio_is_valid(pdata->gpio_power)) { | ||
621 | gpio_set_value(pdata->gpio_power, 0); | ||
622 | gpio_free(pdata->gpio_power); | ||
623 | } | ||
624 | if (gpio_is_valid(pdata->gpio_npdn)) | ||
625 | gpio_free(pdata->gpio_npdn); | ||
626 | } | ||
627 | |||
625 | return 0; | 628 | return 0; |
626 | } | 629 | } |
627 | 630 | ||
@@ -641,23 +644,7 @@ static struct i2c_driver ak4641_i2c_driver = { | |||
641 | .id_table = ak4641_i2c_id, | 644 | .id_table = ak4641_i2c_id, |
642 | }; | 645 | }; |
643 | 646 | ||
644 | static int __init ak4641_modinit(void) | 647 | module_i2c_driver(ak4641_i2c_driver); |
645 | { | ||
646 | int ret; | ||
647 | |||
648 | ret = i2c_add_driver(&ak4641_i2c_driver); | ||
649 | if (ret != 0) | ||
650 | pr_err("Failed to register AK4641 I2C driver: %d\n", ret); | ||
651 | |||
652 | return ret; | ||
653 | } | ||
654 | module_init(ak4641_modinit); | ||
655 | |||
656 | static void __exit ak4641_exit(void) | ||
657 | { | ||
658 | i2c_del_driver(&ak4641_i2c_driver); | ||
659 | } | ||
660 | module_exit(ak4641_exit); | ||
661 | 648 | ||
662 | MODULE_DESCRIPTION("SoC AK4641 driver"); | 649 | MODULE_DESCRIPTION("SoC AK4641 driver"); |
663 | MODULE_AUTHOR("Harald Welte <laforge@gnufiish.org>"); | 650 | MODULE_AUTHOR("Harald Welte <laforge@gnufiish.org>"); |
diff --git a/sound/soc/codecs/alc5623.c b/sound/soc/codecs/alc5623.c index d47b62ddb210..1960478ce6bb 100644 --- a/sound/soc/codecs/alc5623.c +++ b/sound/soc/codecs/alc5623.c | |||
@@ -705,8 +705,7 @@ static int alc5623_set_dai_fmt(struct snd_soc_dai *codec_dai, | |||
705 | static int alc5623_pcm_hw_params(struct snd_pcm_substream *substream, | 705 | static int alc5623_pcm_hw_params(struct snd_pcm_substream *substream, |
706 | struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) | 706 | struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) |
707 | { | 707 | { |
708 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 708 | struct snd_soc_codec *codec = dai->codec; |
709 | struct snd_soc_codec *codec = rtd->codec; | ||
710 | struct alc5623_priv *alc5623 = snd_soc_codec_get_drvdata(codec); | 709 | struct alc5623_priv *alc5623 = snd_soc_codec_get_drvdata(codec); |
711 | int coeff, rate; | 710 | int coeff, rate; |
712 | u16 iface; | 711 | u16 iface; |
@@ -1084,25 +1083,7 @@ static struct i2c_driver alc5623_i2c_driver = { | |||
1084 | .id_table = alc5623_i2c_table, | 1083 | .id_table = alc5623_i2c_table, |
1085 | }; | 1084 | }; |
1086 | 1085 | ||
1087 | static int __init alc5623_modinit(void) | 1086 | module_i2c_driver(alc5623_i2c_driver); |
1088 | { | ||
1089 | int ret; | ||
1090 | |||
1091 | ret = i2c_add_driver(&alc5623_i2c_driver); | ||
1092 | if (ret != 0) { | ||
1093 | printk(KERN_ERR "%s: can't add i2c driver", __func__); | ||
1094 | return ret; | ||
1095 | } | ||
1096 | |||
1097 | return ret; | ||
1098 | } | ||
1099 | module_init(alc5623_modinit); | ||
1100 | |||
1101 | static void __exit alc5623_modexit(void) | ||
1102 | { | ||
1103 | i2c_del_driver(&alc5623_i2c_driver); | ||
1104 | } | ||
1105 | module_exit(alc5623_modexit); | ||
1106 | 1087 | ||
1107 | MODULE_DESCRIPTION("ASoC alc5621/2/3 driver"); | 1088 | MODULE_DESCRIPTION("ASoC alc5621/2/3 driver"); |
1108 | MODULE_AUTHOR("Arnaud Patard <arnaud.patard@rtp-net.org>"); | 1089 | MODULE_AUTHOR("Arnaud Patard <arnaud.patard@rtp-net.org>"); |
diff --git a/sound/soc/codecs/alc5632.c b/sound/soc/codecs/alc5632.c index e2111e0ccad7..7dd02420b36d 100644 --- a/sound/soc/codecs/alc5632.c +++ b/sound/soc/codecs/alc5632.c | |||
@@ -861,8 +861,7 @@ static int alc5632_set_dai_fmt(struct snd_soc_dai *codec_dai, | |||
861 | static int alc5632_pcm_hw_params(struct snd_pcm_substream *substream, | 861 | static int alc5632_pcm_hw_params(struct snd_pcm_substream *substream, |
862 | struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) | 862 | struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) |
863 | { | 863 | { |
864 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 864 | struct snd_soc_codec *codec = dai->codec; |
865 | struct snd_soc_codec *codec = rtd->codec; | ||
866 | int coeff, rate; | 865 | int coeff, rate; |
867 | u16 iface; | 866 | u16 iface; |
868 | 867 | ||
@@ -1131,7 +1130,7 @@ static __devinit int alc5632_i2c_probe(struct i2c_client *client, | |||
1131 | 1130 | ||
1132 | i2c_set_clientdata(client, alc5632); | 1131 | i2c_set_clientdata(client, alc5632); |
1133 | 1132 | ||
1134 | alc5632->regmap = regmap_init_i2c(client, &alc5632_regmap); | 1133 | alc5632->regmap = devm_regmap_init_i2c(client, &alc5632_regmap); |
1135 | if (IS_ERR(alc5632->regmap)) { | 1134 | if (IS_ERR(alc5632->regmap)) { |
1136 | ret = PTR_ERR(alc5632->regmap); | 1135 | ret = PTR_ERR(alc5632->regmap); |
1137 | dev_err(&client->dev, "regmap_init() failed: %d\n", ret); | 1136 | dev_err(&client->dev, "regmap_init() failed: %d\n", ret); |
@@ -1143,7 +1142,6 @@ static __devinit int alc5632_i2c_probe(struct i2c_client *client, | |||
1143 | if (ret1 != 0 || ret2 != 0) { | 1142 | if (ret1 != 0 || ret2 != 0) { |
1144 | dev_err(&client->dev, | 1143 | dev_err(&client->dev, |
1145 | "Failed to read chip ID: ret1=%d, ret2=%d\n", ret1, ret2); | 1144 | "Failed to read chip ID: ret1=%d, ret2=%d\n", ret1, ret2); |
1146 | regmap_exit(alc5632->regmap); | ||
1147 | return -EIO; | 1145 | return -EIO; |
1148 | } | 1146 | } |
1149 | 1147 | ||
@@ -1152,14 +1150,12 @@ static __devinit int alc5632_i2c_probe(struct i2c_client *client, | |||
1152 | if ((vid1 != 0x10EC) || (vid2 != id->driver_data)) { | 1150 | if ((vid1 != 0x10EC) || (vid2 != id->driver_data)) { |
1153 | dev_err(&client->dev, | 1151 | dev_err(&client->dev, |
1154 | "Device is not a ALC5632: VID1=0x%x, VID2=0x%x\n", vid1, vid2); | 1152 | "Device is not a ALC5632: VID1=0x%x, VID2=0x%x\n", vid1, vid2); |
1155 | regmap_exit(alc5632->regmap); | ||
1156 | return -EINVAL; | 1153 | return -EINVAL; |
1157 | } | 1154 | } |
1158 | 1155 | ||
1159 | ret = alc5632_reset(alc5632->regmap); | 1156 | ret = alc5632_reset(alc5632->regmap); |
1160 | if (ret < 0) { | 1157 | if (ret < 0) { |
1161 | dev_err(&client->dev, "Failed to issue reset\n"); | 1158 | dev_err(&client->dev, "Failed to issue reset\n"); |
1162 | regmap_exit(alc5632->regmap); | ||
1163 | return ret; | 1159 | return ret; |
1164 | } | 1160 | } |
1165 | 1161 | ||
@@ -1177,7 +1173,6 @@ static __devinit int alc5632_i2c_probe(struct i2c_client *client, | |||
1177 | 1173 | ||
1178 | if (ret < 0) { | 1174 | if (ret < 0) { |
1179 | dev_err(&client->dev, "Failed to register codec: %d\n", ret); | 1175 | dev_err(&client->dev, "Failed to register codec: %d\n", ret); |
1180 | regmap_exit(alc5632->regmap); | ||
1181 | return ret; | 1176 | return ret; |
1182 | } | 1177 | } |
1183 | 1178 | ||
@@ -1186,9 +1181,7 @@ static __devinit int alc5632_i2c_probe(struct i2c_client *client, | |||
1186 | 1181 | ||
1187 | static __devexit int alc5632_i2c_remove(struct i2c_client *client) | 1182 | static __devexit int alc5632_i2c_remove(struct i2c_client *client) |
1188 | { | 1183 | { |
1189 | struct alc5632_priv *alc5632 = i2c_get_clientdata(client); | ||
1190 | snd_soc_unregister_codec(&client->dev); | 1184 | snd_soc_unregister_codec(&client->dev); |
1191 | regmap_exit(alc5632->regmap); | ||
1192 | return 0; | 1185 | return 0; |
1193 | } | 1186 | } |
1194 | 1187 | ||
@@ -1209,25 +1202,7 @@ static struct i2c_driver alc5632_i2c_driver = { | |||
1209 | .id_table = alc5632_i2c_table, | 1202 | .id_table = alc5632_i2c_table, |
1210 | }; | 1203 | }; |
1211 | 1204 | ||
1212 | static int __init alc5632_modinit(void) | 1205 | module_i2c_driver(alc5632_i2c_driver); |
1213 | { | ||
1214 | int ret; | ||
1215 | |||
1216 | ret = i2c_add_driver(&alc5632_i2c_driver); | ||
1217 | if (ret != 0) { | ||
1218 | printk(KERN_ERR "%s: can't add i2c driver", __func__); | ||
1219 | return ret; | ||
1220 | } | ||
1221 | |||
1222 | return ret; | ||
1223 | } | ||
1224 | module_init(alc5632_modinit); | ||
1225 | |||
1226 | static void __exit alc5632_modexit(void) | ||
1227 | { | ||
1228 | i2c_del_driver(&alc5632_i2c_driver); | ||
1229 | } | ||
1230 | module_exit(alc5632_modexit); | ||
1231 | 1206 | ||
1232 | MODULE_DESCRIPTION("ASoC ALC5632 driver"); | 1207 | MODULE_DESCRIPTION("ASoC ALC5632 driver"); |
1233 | MODULE_AUTHOR("Leon Romanovsky <leon@leon.nu>"); | 1208 | MODULE_AUTHOR("Leon Romanovsky <leon@leon.nu>"); |
diff --git a/sound/soc/codecs/cs4270.c b/sound/soc/codecs/cs4270.c index 1d672f528662..047917f0b8ae 100644 --- a/sound/soc/codecs/cs4270.c +++ b/sound/soc/codecs/cs4270.c | |||
@@ -307,8 +307,7 @@ static int cs4270_hw_params(struct snd_pcm_substream *substream, | |||
307 | struct snd_pcm_hw_params *params, | 307 | struct snd_pcm_hw_params *params, |
308 | struct snd_soc_dai *dai) | 308 | struct snd_soc_dai *dai) |
309 | { | 309 | { |
310 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 310 | struct snd_soc_codec *codec = dai->codec; |
311 | struct snd_soc_codec *codec = rtd->codec; | ||
312 | struct cs4270_private *cs4270 = snd_soc_codec_get_drvdata(codec); | 311 | struct cs4270_private *cs4270 = snd_soc_codec_get_drvdata(codec); |
313 | int ret; | 312 | int ret; |
314 | unsigned int i; | 313 | unsigned int i; |
@@ -600,10 +599,12 @@ static int cs4270_soc_suspend(struct snd_soc_codec *codec) | |||
600 | static int cs4270_soc_resume(struct snd_soc_codec *codec) | 599 | static int cs4270_soc_resume(struct snd_soc_codec *codec) |
601 | { | 600 | { |
602 | struct cs4270_private *cs4270 = snd_soc_codec_get_drvdata(codec); | 601 | struct cs4270_private *cs4270 = snd_soc_codec_get_drvdata(codec); |
603 | int reg; | 602 | int reg, ret; |
604 | 603 | ||
605 | regulator_bulk_enable(ARRAY_SIZE(cs4270->supplies), | 604 | ret = regulator_bulk_enable(ARRAY_SIZE(cs4270->supplies), |
606 | cs4270->supplies); | 605 | cs4270->supplies); |
606 | if (ret != 0) | ||
607 | return ret; | ||
607 | 608 | ||
608 | /* In case the device was put to hard reset during sleep, we need to | 609 | /* In case the device was put to hard reset during sleep, we need to |
609 | * wait 500ns here before any I2C communication. */ | 610 | * wait 500ns here before any I2C communication. */ |
diff --git a/sound/soc/codecs/cs4271.c b/sound/soc/codecs/cs4271.c index bf7141280a74..9eb01d7d58a3 100644 --- a/sound/soc/codecs/cs4271.c +++ b/sound/soc/codecs/cs4271.c | |||
@@ -318,8 +318,7 @@ static int cs4271_hw_params(struct snd_pcm_substream *substream, | |||
318 | struct snd_pcm_hw_params *params, | 318 | struct snd_pcm_hw_params *params, |
319 | struct snd_soc_dai *dai) | 319 | struct snd_soc_dai *dai) |
320 | { | 320 | { |
321 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 321 | struct snd_soc_codec *codec = dai->codec; |
322 | struct snd_soc_codec *codec = rtd->codec; | ||
323 | struct cs4271_private *cs4271 = snd_soc_codec_get_drvdata(codec); | 322 | struct cs4271_private *cs4271 = snd_soc_codec_get_drvdata(codec); |
324 | int i, ret; | 323 | int i, ret; |
325 | unsigned int ratio, val; | 324 | unsigned int ratio, val; |
diff --git a/sound/soc/codecs/cs42l51.c b/sound/soc/codecs/cs42l51.c index a8bf588e8740..091d0193f507 100644 --- a/sound/soc/codecs/cs42l51.c +++ b/sound/soc/codecs/cs42l51.c | |||
@@ -141,15 +141,15 @@ static const struct soc_enum cs42l51_chan_mix = | |||
141 | static const struct snd_kcontrol_new cs42l51_snd_controls[] = { | 141 | static const struct snd_kcontrol_new cs42l51_snd_controls[] = { |
142 | SOC_DOUBLE_R_SX_TLV("PCM Playback Volume", | 142 | SOC_DOUBLE_R_SX_TLV("PCM Playback Volume", |
143 | CS42L51_PCMA_VOL, CS42L51_PCMB_VOL, | 143 | CS42L51_PCMA_VOL, CS42L51_PCMB_VOL, |
144 | 7, 0xffffff99, 0x18, adc_pcm_tlv), | 144 | 6, 0x19, 0x7F, adc_pcm_tlv), |
145 | SOC_DOUBLE_R("PCM Playback Switch", | 145 | SOC_DOUBLE_R("PCM Playback Switch", |
146 | CS42L51_PCMA_VOL, CS42L51_PCMB_VOL, 7, 1, 1), | 146 | CS42L51_PCMA_VOL, CS42L51_PCMB_VOL, 7, 1, 1), |
147 | SOC_DOUBLE_R_SX_TLV("Analog Playback Volume", | 147 | SOC_DOUBLE_R_SX_TLV("Analog Playback Volume", |
148 | CS42L51_AOUTA_VOL, CS42L51_AOUTB_VOL, | 148 | CS42L51_AOUTA_VOL, CS42L51_AOUTB_VOL, |
149 | 8, 0xffffff19, 0x18, aout_tlv), | 149 | 0, 0x34, 0xE4, aout_tlv), |
150 | SOC_DOUBLE_R_SX_TLV("ADC Mixer Volume", | 150 | SOC_DOUBLE_R_SX_TLV("ADC Mixer Volume", |
151 | CS42L51_ADCA_VOL, CS42L51_ADCB_VOL, | 151 | CS42L51_ADCA_VOL, CS42L51_ADCB_VOL, |
152 | 7, 0xffffff99, 0x18, adc_pcm_tlv), | 152 | 6, 0x19, 0x7F, adc_pcm_tlv), |
153 | SOC_DOUBLE_R("ADC Mixer Switch", | 153 | SOC_DOUBLE_R("ADC Mixer Switch", |
154 | CS42L51_ADCA_VOL, CS42L51_ADCB_VOL, 7, 1, 1), | 154 | CS42L51_ADCA_VOL, CS42L51_ADCB_VOL, 7, 1, 1), |
155 | SOC_SINGLE("Playback Deemphasis Switch", CS42L51_DAC_CTL, 3, 1, 0), | 155 | SOC_SINGLE("Playback Deemphasis Switch", CS42L51_DAC_CTL, 3, 1, 0), |
@@ -356,8 +356,7 @@ static int cs42l51_hw_params(struct snd_pcm_substream *substream, | |||
356 | struct snd_pcm_hw_params *params, | 356 | struct snd_pcm_hw_params *params, |
357 | struct snd_soc_dai *dai) | 357 | struct snd_soc_dai *dai) |
358 | { | 358 | { |
359 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 359 | struct snd_soc_codec *codec = dai->codec; |
360 | struct snd_soc_codec *codec = rtd->codec; | ||
361 | struct cs42l51_private *cs42l51 = snd_soc_codec_get_drvdata(codec); | 360 | struct cs42l51_private *cs42l51 = snd_soc_codec_get_drvdata(codec); |
362 | int ret; | 361 | int ret; |
363 | unsigned int i; | 362 | unsigned int i; |
diff --git a/sound/soc/codecs/cs42l52.c b/sound/soc/codecs/cs42l52.c new file mode 100644 index 000000000000..a7109413aef1 --- /dev/null +++ b/sound/soc/codecs/cs42l52.c | |||
@@ -0,0 +1,1295 @@ | |||
1 | /* | ||
2 | * cs42l52.c -- CS42L52 ALSA SoC audio driver | ||
3 | * | ||
4 | * Copyright 2012 CirrusLogic, Inc. | ||
5 | * | ||
6 | * Author: Georgi Vlaev <joe@nucleusys.com> | ||
7 | * Author: Brian Austin <brian.austin@cirrus.com> | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or modify | ||
10 | * it under the terms of the GNU General Public License version 2 as | ||
11 | * published by the Free Software Foundation. | ||
12 | * | ||
13 | */ | ||
14 | |||
15 | #include <linux/module.h> | ||
16 | #include <linux/moduleparam.h> | ||
17 | #include <linux/version.h> | ||
18 | #include <linux/kernel.h> | ||
19 | #include <linux/init.h> | ||
20 | #include <linux/delay.h> | ||
21 | #include <linux/pm.h> | ||
22 | #include <linux/i2c.h> | ||
23 | #include <linux/input.h> | ||
24 | #include <linux/regmap.h> | ||
25 | #include <linux/slab.h> | ||
26 | #include <linux/workqueue.h> | ||
27 | #include <linux/platform_device.h> | ||
28 | #include <linux/slab.h> | ||
29 | #include <sound/core.h> | ||
30 | #include <sound/pcm.h> | ||
31 | #include <sound/pcm_params.h> | ||
32 | #include <sound/soc.h> | ||
33 | #include <sound/soc-dapm.h> | ||
34 | #include <sound/initval.h> | ||
35 | #include <sound/tlv.h> | ||
36 | #include <sound/cs42l52.h> | ||
37 | #include "cs42l52.h" | ||
38 | |||
39 | struct sp_config { | ||
40 | u8 spc, format, spfs; | ||
41 | u32 srate; | ||
42 | }; | ||
43 | |||
44 | struct cs42l52_private { | ||
45 | struct regmap *regmap; | ||
46 | struct snd_soc_codec *codec; | ||
47 | struct device *dev; | ||
48 | struct sp_config config; | ||
49 | struct cs42l52_platform_data pdata; | ||
50 | u32 sysclk; | ||
51 | u8 mclksel; | ||
52 | u32 mclk; | ||
53 | u8 flags; | ||
54 | #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) | ||
55 | struct input_dev *beep; | ||
56 | struct work_struct beep_work; | ||
57 | int beep_rate; | ||
58 | #endif | ||
59 | }; | ||
60 | |||
61 | static const struct reg_default cs42l52_reg_defaults[] = { | ||
62 | { CS42L52_PWRCTL1, 0x9F }, /* r02 PWRCTL 1 */ | ||
63 | { CS42L52_PWRCTL2, 0x07 }, /* r03 PWRCTL 2 */ | ||
64 | { CS42L52_PWRCTL3, 0xFF }, /* r04 PWRCTL 3 */ | ||
65 | { CS42L52_CLK_CTL, 0xA0 }, /* r05 Clocking Ctl */ | ||
66 | { CS42L52_IFACE_CTL1, 0x00 }, /* r06 Interface Ctl 1 */ | ||
67 | { CS42L52_ADC_PGA_A, 0x80 }, /* r08 Input A Select */ | ||
68 | { CS42L52_ADC_PGA_B, 0x80 }, /* r09 Input B Select */ | ||
69 | { CS42L52_ANALOG_HPF_CTL, 0xA5 }, /* r0A Analog HPF Ctl */ | ||
70 | { CS42L52_ADC_HPF_FREQ, 0x00 }, /* r0B ADC HPF Corner Freq */ | ||
71 | { CS42L52_ADC_MISC_CTL, 0x00 }, /* r0C Misc. ADC Ctl */ | ||
72 | { CS42L52_PB_CTL1, 0x60 }, /* r0D Playback Ctl 1 */ | ||
73 | { CS42L52_MISC_CTL, 0x02 }, /* r0E Misc. Ctl */ | ||
74 | { CS42L52_PB_CTL2, 0x00 }, /* r0F Playback Ctl 2 */ | ||
75 | { CS42L52_MICA_CTL, 0x00 }, /* r10 MICA Amp Ctl */ | ||
76 | { CS42L52_MICB_CTL, 0x00 }, /* r11 MICB Amp Ctl */ | ||
77 | { CS42L52_PGAA_CTL, 0x00 }, /* r12 PGAA Vol, Misc. */ | ||
78 | { CS42L52_PGAB_CTL, 0x00 }, /* r13 PGAB Vol, Misc. */ | ||
79 | { CS42L52_PASSTHRUA_VOL, 0x00 }, /* r14 Bypass A Vol */ | ||
80 | { CS42L52_PASSTHRUB_VOL, 0x00 }, /* r15 Bypass B Vol */ | ||
81 | { CS42L52_ADCA_VOL, 0x00 }, /* r16 ADCA Volume */ | ||
82 | { CS42L52_ADCB_VOL, 0x00 }, /* r17 ADCB Volume */ | ||
83 | { CS42L52_ADCA_MIXER_VOL, 0x80 }, /* r18 ADCA Mixer Volume */ | ||
84 | { CS42L52_ADCB_MIXER_VOL, 0x80 }, /* r19 ADCB Mixer Volume */ | ||
85 | { CS42L52_PCMA_MIXER_VOL, 0x00 }, /* r1A PCMA Mixer Volume */ | ||
86 | { CS42L52_PCMB_MIXER_VOL, 0x00 }, /* r1B PCMB Mixer Volume */ | ||
87 | { CS42L52_BEEP_FREQ, 0x00 }, /* r1C Beep Freq on Time */ | ||
88 | { CS42L52_BEEP_VOL, 0x00 }, /* r1D Beep Volume off Time */ | ||
89 | { CS42L52_BEEP_TONE_CTL, 0x00 }, /* r1E Beep Tone Cfg. */ | ||
90 | { CS42L52_TONE_CTL, 0x00 }, /* r1F Tone Ctl */ | ||
91 | { CS42L52_MASTERA_VOL, 0x88 }, /* r20 Master A Volume */ | ||
92 | { CS42L52_MASTERB_VOL, 0x00 }, /* r21 Master B Volume */ | ||
93 | { CS42L52_HPA_VOL, 0x00 }, /* r22 Headphone A Volume */ | ||
94 | { CS42L52_HPB_VOL, 0x00 }, /* r23 Headphone B Volume */ | ||
95 | { CS42L52_SPKA_VOL, 0x00 }, /* r24 Speaker A Volume */ | ||
96 | { CS42L52_SPKB_VOL, 0x00 }, /* r25 Speaker B Volume */ | ||
97 | { CS42L52_ADC_PCM_MIXER, 0x00 }, /* r26 Channel Mixer and Swap */ | ||
98 | { CS42L52_LIMITER_CTL1, 0x00 }, /* r27 Limit Ctl 1 Thresholds */ | ||
99 | { CS42L52_LIMITER_CTL2, 0x7F }, /* r28 Limit Ctl 2 Release Rate */ | ||
100 | { CS42L52_LIMITER_AT_RATE, 0xC0 }, /* r29 Limiter Attack Rate */ | ||
101 | { CS42L52_ALC_CTL, 0x00 }, /* r2A ALC Ctl 1 Attack Rate */ | ||
102 | { CS42L52_ALC_RATE, 0x3F }, /* r2B ALC Release Rate */ | ||
103 | { CS42L52_ALC_THRESHOLD, 0x3f }, /* r2C ALC Thresholds */ | ||
104 | { CS42L52_NOISE_GATE_CTL, 0x00 }, /* r2D Noise Gate Ctl */ | ||
105 | { CS42L52_CLK_STATUS, 0x00 }, /* r2E Overflow and Clock Status */ | ||
106 | { CS42L52_BATT_COMPEN, 0x00 }, /* r2F battery Compensation */ | ||
107 | { CS42L52_BATT_LEVEL, 0x00 }, /* r30 VP Battery Level */ | ||
108 | { CS42L52_SPK_STATUS, 0x00 }, /* r31 Speaker Status */ | ||
109 | { CS42L52_TEM_CTL, 0x3B }, /* r32 Temp Ctl */ | ||
110 | { CS42L52_THE_FOLDBACK, 0x00 }, /* r33 Foldback */ | ||
111 | }; | ||
112 | |||
113 | static bool cs42l52_readable_register(struct device *dev, unsigned int reg) | ||
114 | { | ||
115 | switch (reg) { | ||
116 | case CS42L52_CHIP: | ||
117 | case CS42L52_PWRCTL1: | ||
118 | case CS42L52_PWRCTL2: | ||
119 | case CS42L52_PWRCTL3: | ||
120 | case CS42L52_CLK_CTL: | ||
121 | case CS42L52_IFACE_CTL1: | ||
122 | case CS42L52_IFACE_CTL2: | ||
123 | case CS42L52_ADC_PGA_A: | ||
124 | case CS42L52_ADC_PGA_B: | ||
125 | case CS42L52_ANALOG_HPF_CTL: | ||
126 | case CS42L52_ADC_HPF_FREQ: | ||
127 | case CS42L52_ADC_MISC_CTL: | ||
128 | case CS42L52_PB_CTL1: | ||
129 | case CS42L52_MISC_CTL: | ||
130 | case CS42L52_PB_CTL2: | ||
131 | case CS42L52_MICA_CTL: | ||
132 | case CS42L52_MICB_CTL: | ||
133 | case CS42L52_PGAA_CTL: | ||
134 | case CS42L52_PGAB_CTL: | ||
135 | case CS42L52_PASSTHRUA_VOL: | ||
136 | case CS42L52_PASSTHRUB_VOL: | ||
137 | case CS42L52_ADCA_VOL: | ||
138 | case CS42L52_ADCB_VOL: | ||
139 | case CS42L52_ADCA_MIXER_VOL: | ||
140 | case CS42L52_ADCB_MIXER_VOL: | ||
141 | case CS42L52_PCMA_MIXER_VOL: | ||
142 | case CS42L52_PCMB_MIXER_VOL: | ||
143 | case CS42L52_BEEP_FREQ: | ||
144 | case CS42L52_BEEP_VOL: | ||
145 | case CS42L52_BEEP_TONE_CTL: | ||
146 | case CS42L52_TONE_CTL: | ||
147 | case CS42L52_MASTERA_VOL: | ||
148 | case CS42L52_MASTERB_VOL: | ||
149 | case CS42L52_HPA_VOL: | ||
150 | case CS42L52_HPB_VOL: | ||
151 | case CS42L52_SPKA_VOL: | ||
152 | case CS42L52_SPKB_VOL: | ||
153 | case CS42L52_ADC_PCM_MIXER: | ||
154 | case CS42L52_LIMITER_CTL1: | ||
155 | case CS42L52_LIMITER_CTL2: | ||
156 | case CS42L52_LIMITER_AT_RATE: | ||
157 | case CS42L52_ALC_CTL: | ||
158 | case CS42L52_ALC_RATE: | ||
159 | case CS42L52_ALC_THRESHOLD: | ||
160 | case CS42L52_NOISE_GATE_CTL: | ||
161 | case CS42L52_CLK_STATUS: | ||
162 | case CS42L52_BATT_COMPEN: | ||
163 | case CS42L52_BATT_LEVEL: | ||
164 | case CS42L52_SPK_STATUS: | ||
165 | case CS42L52_TEM_CTL: | ||
166 | case CS42L52_THE_FOLDBACK: | ||
167 | case CS42L52_CHARGE_PUMP: | ||
168 | return true; | ||
169 | default: | ||
170 | return false; | ||
171 | } | ||
172 | } | ||
173 | |||
174 | static bool cs42l52_volatile_register(struct device *dev, unsigned int reg) | ||
175 | { | ||
176 | switch (reg) { | ||
177 | case CS42L52_IFACE_CTL2: | ||
178 | case CS42L52_CLK_STATUS: | ||
179 | case CS42L52_BATT_LEVEL: | ||
180 | case CS42L52_SPK_STATUS: | ||
181 | case CS42L52_CHARGE_PUMP: | ||
182 | return 1; | ||
183 | default: | ||
184 | return 0; | ||
185 | } | ||
186 | } | ||
187 | |||
188 | static DECLARE_TLV_DB_SCALE(hl_tlv, -10200, 50, 0); | ||
189 | |||
190 | static DECLARE_TLV_DB_SCALE(hpd_tlv, -9600, 50, 1); | ||
191 | |||
192 | static DECLARE_TLV_DB_SCALE(ipd_tlv, -9600, 100, 0); | ||
193 | |||
194 | static DECLARE_TLV_DB_SCALE(mic_tlv, 1600, 100, 0); | ||
195 | |||
196 | static DECLARE_TLV_DB_SCALE(pga_tlv, -600, 50, 0); | ||
197 | |||
198 | static const unsigned int limiter_tlv[] = { | ||
199 | TLV_DB_RANGE_HEAD(2), | ||
200 | 0, 2, TLV_DB_SCALE_ITEM(-3000, 600, 0), | ||
201 | 3, 7, TLV_DB_SCALE_ITEM(-1200, 300, 0), | ||
202 | }; | ||
203 | |||
204 | static const char * const cs42l52_adca_text[] = { | ||
205 | "Input1A", "Input2A", "Input3A", "Input4A", "PGA Input Left"}; | ||
206 | |||
207 | static const char * const cs42l52_adcb_text[] = { | ||
208 | "Input1B", "Input2B", "Input3B", "Input4B", "PGA Input Right"}; | ||
209 | |||
210 | static const struct soc_enum adca_enum = | ||
211 | SOC_ENUM_SINGLE(CS42L52_ADC_PGA_A, 5, | ||
212 | ARRAY_SIZE(cs42l52_adca_text), cs42l52_adca_text); | ||
213 | |||
214 | static const struct soc_enum adcb_enum = | ||
215 | SOC_ENUM_SINGLE(CS42L52_ADC_PGA_B, 5, | ||
216 | ARRAY_SIZE(cs42l52_adcb_text), cs42l52_adcb_text); | ||
217 | |||
218 | static const struct snd_kcontrol_new adca_mux = | ||
219 | SOC_DAPM_ENUM("Left ADC Input Capture Mux", adca_enum); | ||
220 | |||
221 | static const struct snd_kcontrol_new adcb_mux = | ||
222 | SOC_DAPM_ENUM("Right ADC Input Capture Mux", adcb_enum); | ||
223 | |||
224 | static const char * const mic_bias_level_text[] = { | ||
225 | "0.5 +VA", "0.6 +VA", "0.7 +VA", | ||
226 | "0.8 +VA", "0.83 +VA", "0.91 +VA" | ||
227 | }; | ||
228 | |||
229 | static const struct soc_enum mic_bias_level_enum = | ||
230 | SOC_ENUM_SINGLE(CS42L52_IFACE_CTL1, 0, | ||
231 | ARRAY_SIZE(mic_bias_level_text), mic_bias_level_text); | ||
232 | |||
233 | static const char * const cs42l52_mic_text[] = { "Single", "Differential" }; | ||
234 | |||
235 | static const struct soc_enum mica_enum = | ||
236 | SOC_ENUM_SINGLE(CS42L52_MICA_CTL, 5, | ||
237 | ARRAY_SIZE(cs42l52_mic_text), cs42l52_mic_text); | ||
238 | |||
239 | static const struct soc_enum micb_enum = | ||
240 | SOC_ENUM_SINGLE(CS42L52_MICB_CTL, 5, | ||
241 | ARRAY_SIZE(cs42l52_mic_text), cs42l52_mic_text); | ||
242 | |||
243 | static const struct snd_kcontrol_new mica_mux = | ||
244 | SOC_DAPM_ENUM("Left Mic Input Capture Mux", mica_enum); | ||
245 | |||
246 | static const struct snd_kcontrol_new micb_mux = | ||
247 | SOC_DAPM_ENUM("Right Mic Input Capture Mux", micb_enum); | ||
248 | |||
249 | static const char * const digital_output_mux_text[] = {"ADC", "DSP"}; | ||
250 | |||
251 | static const struct soc_enum digital_output_mux_enum = | ||
252 | SOC_ENUM_SINGLE(CS42L52_ADC_MISC_CTL, 6, | ||
253 | ARRAY_SIZE(digital_output_mux_text), | ||
254 | digital_output_mux_text); | ||
255 | |||
256 | static const struct snd_kcontrol_new digital_output_mux = | ||
257 | SOC_DAPM_ENUM("Digital Output Mux", digital_output_mux_enum); | ||
258 | |||
259 | static const char * const hp_gain_num_text[] = { | ||
260 | "0.3959", "0.4571", "0.5111", "0.6047", | ||
261 | "0.7099", "0.8399", "1.000", "1.1430" | ||
262 | }; | ||
263 | |||
264 | static const struct soc_enum hp_gain_enum = | ||
265 | SOC_ENUM_SINGLE(CS42L52_PB_CTL1, 4, | ||
266 | ARRAY_SIZE(hp_gain_num_text), hp_gain_num_text); | ||
267 | |||
268 | static const char * const beep_pitch_text[] = { | ||
269 | "C4", "C5", "D5", "E5", "F5", "G5", "A5", "B5", | ||
270 | "C6", "D6", "E6", "F6", "G6", "A6", "B6", "C7" | ||
271 | }; | ||
272 | |||
273 | static const struct soc_enum beep_pitch_enum = | ||
274 | SOC_ENUM_SINGLE(CS42L52_BEEP_FREQ, 4, | ||
275 | ARRAY_SIZE(beep_pitch_text), beep_pitch_text); | ||
276 | |||
277 | static const char * const beep_ontime_text[] = { | ||
278 | "86 ms", "430 ms", "780 ms", "1.20 s", "1.50 s", | ||
279 | "1.80 s", "2.20 s", "2.50 s", "2.80 s", "3.20 s", | ||
280 | "3.50 s", "3.80 s", "4.20 s", "4.50 s", "4.80 s", "5.20 s" | ||
281 | }; | ||
282 | |||
283 | static const struct soc_enum beep_ontime_enum = | ||
284 | SOC_ENUM_SINGLE(CS42L52_BEEP_FREQ, 0, | ||
285 | ARRAY_SIZE(beep_ontime_text), beep_ontime_text); | ||
286 | |||
287 | static const char * const beep_offtime_text[] = { | ||
288 | "1.23 s", "2.58 s", "3.90 s", "5.20 s", | ||
289 | "6.60 s", "8.05 s", "9.35 s", "10.80 s" | ||
290 | }; | ||
291 | |||
292 | static const struct soc_enum beep_offtime_enum = | ||
293 | SOC_ENUM_SINGLE(CS42L52_BEEP_VOL, 5, | ||
294 | ARRAY_SIZE(beep_offtime_text), beep_offtime_text); | ||
295 | |||
296 | static const char * const beep_config_text[] = { | ||
297 | "Off", "Single", "Multiple", "Continuous" | ||
298 | }; | ||
299 | |||
300 | static const struct soc_enum beep_config_enum = | ||
301 | SOC_ENUM_SINGLE(CS42L52_BEEP_TONE_CTL, 6, | ||
302 | ARRAY_SIZE(beep_config_text), beep_config_text); | ||
303 | |||
304 | static const char * const beep_bass_text[] = { | ||
305 | "50 Hz", "100 Hz", "200 Hz", "250 Hz" | ||
306 | }; | ||
307 | |||
308 | static const struct soc_enum beep_bass_enum = | ||
309 | SOC_ENUM_SINGLE(CS42L52_BEEP_TONE_CTL, 1, | ||
310 | ARRAY_SIZE(beep_bass_text), beep_bass_text); | ||
311 | |||
312 | static const char * const beep_treble_text[] = { | ||
313 | "5 kHz", "7 kHz", "10 kHz", " 15 kHz" | ||
314 | }; | ||
315 | |||
316 | static const struct soc_enum beep_treble_enum = | ||
317 | SOC_ENUM_SINGLE(CS42L52_BEEP_TONE_CTL, 3, | ||
318 | ARRAY_SIZE(beep_treble_text), beep_treble_text); | ||
319 | |||
320 | static const char * const ng_threshold_text[] = { | ||
321 | "-34dB", "-37dB", "-40dB", "-43dB", | ||
322 | "-46dB", "-52dB", "-58dB", "-64dB" | ||
323 | }; | ||
324 | |||
325 | static const struct soc_enum ng_threshold_enum = | ||
326 | SOC_ENUM_SINGLE(CS42L52_NOISE_GATE_CTL, 2, | ||
327 | ARRAY_SIZE(ng_threshold_text), ng_threshold_text); | ||
328 | |||
329 | static const char * const cs42l52_ng_delay_text[] = { | ||
330 | "50ms", "100ms", "150ms", "200ms"}; | ||
331 | |||
332 | static const struct soc_enum ng_delay_enum = | ||
333 | SOC_ENUM_SINGLE(CS42L52_NOISE_GATE_CTL, 0, | ||
334 | ARRAY_SIZE(cs42l52_ng_delay_text), cs42l52_ng_delay_text); | ||
335 | |||
336 | static const char * const cs42l52_ng_type_text[] = { | ||
337 | "Apply Specific", "Apply All" | ||
338 | }; | ||
339 | |||
340 | static const struct soc_enum ng_type_enum = | ||
341 | SOC_ENUM_SINGLE(CS42L52_NOISE_GATE_CTL, 6, | ||
342 | ARRAY_SIZE(cs42l52_ng_type_text), cs42l52_ng_type_text); | ||
343 | |||
344 | static const char * const left_swap_text[] = { | ||
345 | "Left", "LR 2", "Right"}; | ||
346 | |||
347 | static const char * const right_swap_text[] = { | ||
348 | "Right", "LR 2", "Left"}; | ||
349 | |||
350 | static const unsigned int swap_values[] = { 0, 1, 3 }; | ||
351 | |||
352 | static const struct soc_enum adca_swap_enum = | ||
353 | SOC_VALUE_ENUM_SINGLE(CS42L52_ADC_PCM_MIXER, 2, 1, | ||
354 | ARRAY_SIZE(left_swap_text), | ||
355 | left_swap_text, | ||
356 | swap_values); | ||
357 | |||
358 | static const struct snd_kcontrol_new adca_mixer = | ||
359 | SOC_DAPM_ENUM("Route", adca_swap_enum); | ||
360 | |||
361 | static const struct soc_enum pcma_swap_enum = | ||
362 | SOC_VALUE_ENUM_SINGLE(CS42L52_ADC_PCM_MIXER, 6, 1, | ||
363 | ARRAY_SIZE(left_swap_text), | ||
364 | left_swap_text, | ||
365 | swap_values); | ||
366 | |||
367 | static const struct snd_kcontrol_new pcma_mixer = | ||
368 | SOC_DAPM_ENUM("Route", pcma_swap_enum); | ||
369 | |||
370 | static const struct soc_enum adcb_swap_enum = | ||
371 | SOC_VALUE_ENUM_SINGLE(CS42L52_ADC_PCM_MIXER, 0, 1, | ||
372 | ARRAY_SIZE(right_swap_text), | ||
373 | right_swap_text, | ||
374 | swap_values); | ||
375 | |||
376 | static const struct snd_kcontrol_new adcb_mixer = | ||
377 | SOC_DAPM_ENUM("Route", adcb_swap_enum); | ||
378 | |||
379 | static const struct soc_enum pcmb_swap_enum = | ||
380 | SOC_VALUE_ENUM_SINGLE(CS42L52_ADC_PCM_MIXER, 4, 1, | ||
381 | ARRAY_SIZE(right_swap_text), | ||
382 | right_swap_text, | ||
383 | swap_values); | ||
384 | |||
385 | static const struct snd_kcontrol_new pcmb_mixer = | ||
386 | SOC_DAPM_ENUM("Route", pcmb_swap_enum); | ||
387 | |||
388 | |||
389 | static const struct snd_kcontrol_new passthrul_ctl = | ||
390 | SOC_DAPM_SINGLE("Switch", CS42L52_MISC_CTL, 6, 1, 0); | ||
391 | |||
392 | static const struct snd_kcontrol_new passthrur_ctl = | ||
393 | SOC_DAPM_SINGLE("Switch", CS42L52_MISC_CTL, 7, 1, 0); | ||
394 | |||
395 | static const struct snd_kcontrol_new spkl_ctl = | ||
396 | SOC_DAPM_SINGLE("Switch", CS42L52_PWRCTL3, 0, 1, 1); | ||
397 | |||
398 | static const struct snd_kcontrol_new spkr_ctl = | ||
399 | SOC_DAPM_SINGLE("Switch", CS42L52_PWRCTL3, 2, 1, 1); | ||
400 | |||
401 | static const struct snd_kcontrol_new hpl_ctl = | ||
402 | SOC_DAPM_SINGLE("Switch", CS42L52_PWRCTL3, 4, 1, 1); | ||
403 | |||
404 | static const struct snd_kcontrol_new hpr_ctl = | ||
405 | SOC_DAPM_SINGLE("Switch", CS42L52_PWRCTL3, 6, 1, 1); | ||
406 | |||
407 | static const struct snd_kcontrol_new cs42l52_snd_controls[] = { | ||
408 | |||
409 | SOC_DOUBLE_R_SX_TLV("Master Volume", CS42L52_MASTERA_VOL, | ||
410 | CS42L52_MASTERB_VOL, 0, 0x34, 0xE4, hl_tlv), | ||
411 | |||
412 | SOC_DOUBLE_R_SX_TLV("Headphone Volume", CS42L52_HPA_VOL, | ||
413 | CS42L52_HPB_VOL, 0, 0x34, 0xCC, hpd_tlv), | ||
414 | |||
415 | SOC_ENUM("Headphone Analog Gain", hp_gain_enum), | ||
416 | |||
417 | SOC_DOUBLE_R_SX_TLV("Speaker Volume", CS42L52_SPKA_VOL, | ||
418 | CS42L52_SPKB_VOL, 7, 0x1, 0xff, hl_tlv), | ||
419 | |||
420 | SOC_DOUBLE_R_SX_TLV("Bypass Volume", CS42L52_PASSTHRUA_VOL, | ||
421 | CS42L52_PASSTHRUB_VOL, 6, 0x18, 0x90, pga_tlv), | ||
422 | |||
423 | SOC_DOUBLE("Bypass Mute", CS42L52_MISC_CTL, 4, 5, 1, 0), | ||
424 | |||
425 | SOC_DOUBLE_R_TLV("MIC Gain Volume", CS42L52_MICA_CTL, | ||
426 | CS42L52_MICB_CTL, 0, 0x10, 0, mic_tlv), | ||
427 | |||
428 | SOC_ENUM("MIC Bias Level", mic_bias_level_enum), | ||
429 | |||
430 | SOC_DOUBLE_R_SX_TLV("ADC Volume", CS42L52_ADCA_VOL, | ||
431 | CS42L52_ADCB_VOL, 7, 0x80, 0xA0, ipd_tlv), | ||
432 | SOC_DOUBLE_R_SX_TLV("ADC Mixer Volume", | ||
433 | CS42L52_ADCA_MIXER_VOL, CS42L52_ADCB_MIXER_VOL, | ||
434 | 6, 0x7f, 0x19, ipd_tlv), | ||
435 | |||
436 | SOC_DOUBLE("ADC Switch", CS42L52_ADC_MISC_CTL, 0, 1, 1, 0), | ||
437 | |||
438 | SOC_DOUBLE_R("ADC Mixer Switch", CS42L52_ADCA_MIXER_VOL, | ||
439 | CS42L52_ADCB_MIXER_VOL, 7, 1, 1), | ||
440 | |||
441 | SOC_DOUBLE_R_SX_TLV("PGA Volume", CS42L52_PGAA_CTL, | ||
442 | CS42L52_PGAB_CTL, 0, 0x28, 0x30, pga_tlv), | ||
443 | |||
444 | SOC_DOUBLE_R_SX_TLV("PCM Mixer Volume", | ||
445 | CS42L52_PCMA_MIXER_VOL, CS42L52_PCMB_MIXER_VOL, | ||
446 | 6, 0x7f, 0x19, hl_tlv), | ||
447 | SOC_DOUBLE_R("PCM Mixer Switch", | ||
448 | CS42L52_PCMA_MIXER_VOL, CS42L52_PCMB_MIXER_VOL, 7, 1, 1), | ||
449 | |||
450 | SOC_ENUM("Beep Config", beep_config_enum), | ||
451 | SOC_ENUM("Beep Pitch", beep_pitch_enum), | ||
452 | SOC_ENUM("Beep on Time", beep_ontime_enum), | ||
453 | SOC_ENUM("Beep off Time", beep_offtime_enum), | ||
454 | SOC_SINGLE_TLV("Beep Volume", CS42L52_BEEP_VOL, 0, 0x1f, 0x07, hl_tlv), | ||
455 | SOC_SINGLE("Beep Mixer Switch", CS42L52_BEEP_TONE_CTL, 5, 1, 1), | ||
456 | SOC_ENUM("Beep Treble Corner Freq", beep_treble_enum), | ||
457 | SOC_ENUM("Beep Bass Corner Freq", beep_bass_enum), | ||
458 | |||
459 | SOC_SINGLE("Tone Control Switch", CS42L52_BEEP_TONE_CTL, 0, 1, 1), | ||
460 | SOC_SINGLE_TLV("Treble Gain Volume", | ||
461 | CS42L52_TONE_CTL, 4, 15, 1, hl_tlv), | ||
462 | SOC_SINGLE_TLV("Bass Gain Volume", | ||
463 | CS42L52_TONE_CTL, 0, 15, 1, hl_tlv), | ||
464 | |||
465 | /* Limiter */ | ||
466 | SOC_SINGLE_TLV("Limiter Max Threshold Volume", | ||
467 | CS42L52_LIMITER_CTL1, 5, 7, 0, limiter_tlv), | ||
468 | SOC_SINGLE_TLV("Limiter Cushion Threshold Volume", | ||
469 | CS42L52_LIMITER_CTL1, 2, 7, 0, limiter_tlv), | ||
470 | SOC_SINGLE_TLV("Limiter Release Rate Volume", | ||
471 | CS42L52_LIMITER_CTL2, 0, 63, 0, limiter_tlv), | ||
472 | SOC_SINGLE_TLV("Limiter Attack Rate Volume", | ||
473 | CS42L52_LIMITER_AT_RATE, 0, 63, 0, limiter_tlv), | ||
474 | |||
475 | SOC_SINGLE("Limiter SR Switch", CS42L52_LIMITER_CTL1, 1, 1, 0), | ||
476 | SOC_SINGLE("Limiter ZC Switch", CS42L52_LIMITER_CTL1, 0, 1, 0), | ||
477 | SOC_SINGLE("Limiter Switch", CS42L52_LIMITER_CTL2, 7, 1, 0), | ||
478 | |||
479 | /* ALC */ | ||
480 | SOC_SINGLE_TLV("ALC Attack Rate Volume", CS42L52_ALC_CTL, | ||
481 | 0, 63, 0, limiter_tlv), | ||
482 | SOC_SINGLE_TLV("ALC Release Rate Volume", CS42L52_ALC_RATE, | ||
483 | 0, 63, 0, limiter_tlv), | ||
484 | SOC_SINGLE_TLV("ALC Max Threshold Volume", CS42L52_ALC_THRESHOLD, | ||
485 | 5, 7, 0, limiter_tlv), | ||
486 | SOC_SINGLE_TLV("ALC Min Threshold Volume", CS42L52_ALC_THRESHOLD, | ||
487 | 2, 7, 0, limiter_tlv), | ||
488 | |||
489 | SOC_DOUBLE_R("ALC SR Capture Switch", CS42L52_PGAA_CTL, | ||
490 | CS42L52_PGAB_CTL, 7, 1, 1), | ||
491 | SOC_DOUBLE_R("ALC ZC Capture Switch", CS42L52_PGAA_CTL, | ||
492 | CS42L52_PGAB_CTL, 6, 1, 1), | ||
493 | SOC_DOUBLE("ALC Capture Switch", CS42L52_ALC_CTL, 6, 7, 1, 0), | ||
494 | |||
495 | /* Noise gate */ | ||
496 | SOC_ENUM("NG Type Switch", ng_type_enum), | ||
497 | SOC_SINGLE("NG Enable Switch", CS42L52_NOISE_GATE_CTL, 6, 1, 0), | ||
498 | SOC_SINGLE("NG Boost Switch", CS42L52_NOISE_GATE_CTL, 5, 1, 1), | ||
499 | SOC_ENUM("NG Threshold", ng_threshold_enum), | ||
500 | SOC_ENUM("NG Delay", ng_delay_enum), | ||
501 | |||
502 | SOC_DOUBLE("HPF Switch", CS42L52_ANALOG_HPF_CTL, 5, 7, 1, 0), | ||
503 | |||
504 | SOC_DOUBLE("Analog SR Switch", CS42L52_ANALOG_HPF_CTL, 1, 3, 1, 1), | ||
505 | SOC_DOUBLE("Analog ZC Switch", CS42L52_ANALOG_HPF_CTL, 0, 2, 1, 1), | ||
506 | SOC_SINGLE("Digital SR Switch", CS42L52_MISC_CTL, 1, 1, 0), | ||
507 | SOC_SINGLE("Digital ZC Switch", CS42L52_MISC_CTL, 0, 1, 0), | ||
508 | SOC_SINGLE("Deemphasis Switch", CS42L52_MISC_CTL, 2, 1, 0), | ||
509 | |||
510 | SOC_SINGLE("Batt Compensation Switch", CS42L52_BATT_COMPEN, 7, 1, 0), | ||
511 | SOC_SINGLE("Batt VP Monitor Switch", CS42L52_BATT_COMPEN, 6, 1, 0), | ||
512 | SOC_SINGLE("Batt VP ref", CS42L52_BATT_COMPEN, 0, 0x0f, 0), | ||
513 | |||
514 | SOC_SINGLE("PGA AIN1L Switch", CS42L52_ADC_PGA_A, 0, 1, 0), | ||
515 | SOC_SINGLE("PGA AIN1R Switch", CS42L52_ADC_PGA_B, 0, 1, 0), | ||
516 | SOC_SINGLE("PGA AIN2L Switch", CS42L52_ADC_PGA_A, 1, 1, 0), | ||
517 | SOC_SINGLE("PGA AIN2R Switch", CS42L52_ADC_PGA_B, 1, 1, 0), | ||
518 | |||
519 | SOC_SINGLE("PGA AIN3L Switch", CS42L52_ADC_PGA_A, 2, 1, 0), | ||
520 | SOC_SINGLE("PGA AIN3R Switch", CS42L52_ADC_PGA_B, 2, 1, 0), | ||
521 | |||
522 | SOC_SINGLE("PGA AIN4L Switch", CS42L52_ADC_PGA_A, 3, 1, 0), | ||
523 | SOC_SINGLE("PGA AIN4R Switch", CS42L52_ADC_PGA_B, 3, 1, 0), | ||
524 | |||
525 | SOC_SINGLE("PGA MICA Switch", CS42L52_ADC_PGA_A, 4, 1, 0), | ||
526 | SOC_SINGLE("PGA MICB Switch", CS42L52_ADC_PGA_B, 4, 1, 0), | ||
527 | |||
528 | }; | ||
529 | |||
530 | static const struct snd_soc_dapm_widget cs42l52_dapm_widgets[] = { | ||
531 | |||
532 | SND_SOC_DAPM_INPUT("AIN1L"), | ||
533 | SND_SOC_DAPM_INPUT("AIN1R"), | ||
534 | SND_SOC_DAPM_INPUT("AIN2L"), | ||
535 | SND_SOC_DAPM_INPUT("AIN2R"), | ||
536 | SND_SOC_DAPM_INPUT("AIN3L"), | ||
537 | SND_SOC_DAPM_INPUT("AIN3R"), | ||
538 | SND_SOC_DAPM_INPUT("AIN4L"), | ||
539 | SND_SOC_DAPM_INPUT("AIN4R"), | ||
540 | SND_SOC_DAPM_INPUT("MICA"), | ||
541 | SND_SOC_DAPM_INPUT("MICB"), | ||
542 | SND_SOC_DAPM_SIGGEN("Beep"), | ||
543 | |||
544 | SND_SOC_DAPM_AIF_OUT("AIFOUTL", NULL, 0, | ||
545 | SND_SOC_NOPM, 0, 0), | ||
546 | SND_SOC_DAPM_AIF_OUT("AIFOUTR", NULL, 0, | ||
547 | SND_SOC_NOPM, 0, 0), | ||
548 | |||
549 | SND_SOC_DAPM_MUX("MICA Mux", SND_SOC_NOPM, 0, 0, &mica_mux), | ||
550 | SND_SOC_DAPM_MUX("MICB Mux", SND_SOC_NOPM, 0, 0, &micb_mux), | ||
551 | |||
552 | SND_SOC_DAPM_ADC("ADC Left", NULL, CS42L52_PWRCTL1, 1, 1), | ||
553 | SND_SOC_DAPM_ADC("ADC Right", NULL, CS42L52_PWRCTL1, 2, 1), | ||
554 | SND_SOC_DAPM_PGA("PGA Left", CS42L52_PWRCTL1, 3, 1, NULL, 0), | ||
555 | SND_SOC_DAPM_PGA("PGA Right", CS42L52_PWRCTL1, 4, 1, NULL, 0), | ||
556 | |||
557 | SND_SOC_DAPM_MUX("ADC Left Mux", SND_SOC_NOPM, 0, 0, &adca_mux), | ||
558 | SND_SOC_DAPM_MUX("ADC Right Mux", SND_SOC_NOPM, 0, 0, &adcb_mux), | ||
559 | |||
560 | SND_SOC_DAPM_MUX("ADC Left Swap", SND_SOC_NOPM, | ||
561 | 0, 0, &adca_mixer), | ||
562 | SND_SOC_DAPM_MUX("ADC Right Swap", SND_SOC_NOPM, | ||
563 | 0, 0, &adcb_mixer), | ||
564 | |||
565 | SND_SOC_DAPM_MUX("Output Mux", SND_SOC_NOPM, | ||
566 | 0, 0, &digital_output_mux), | ||
567 | |||
568 | SND_SOC_DAPM_PGA("PGA MICA", CS42L52_PWRCTL2, 1, 1, NULL, 0), | ||
569 | SND_SOC_DAPM_PGA("PGA MICB", CS42L52_PWRCTL2, 2, 1, NULL, 0), | ||
570 | |||
571 | SND_SOC_DAPM_SUPPLY("Mic Bias", CS42L52_PWRCTL2, 0, 1, NULL, 0), | ||
572 | SND_SOC_DAPM_SUPPLY("Charge Pump", CS42L52_PWRCTL1, 7, 1, NULL, 0), | ||
573 | |||
574 | SND_SOC_DAPM_AIF_IN("AIFINL", NULL, 0, | ||
575 | SND_SOC_NOPM, 0, 0), | ||
576 | SND_SOC_DAPM_AIF_IN("AIFINR", NULL, 0, | ||
577 | SND_SOC_NOPM, 0, 0), | ||
578 | |||
579 | SND_SOC_DAPM_DAC("DAC Left", NULL, SND_SOC_NOPM, 0, 0), | ||
580 | SND_SOC_DAPM_DAC("DAC Right", NULL, SND_SOC_NOPM, 0, 0), | ||
581 | |||
582 | SND_SOC_DAPM_SWITCH("Bypass Left", CS42L52_MISC_CTL, | ||
583 | 6, 0, &passthrul_ctl), | ||
584 | SND_SOC_DAPM_SWITCH("Bypass Right", CS42L52_MISC_CTL, | ||
585 | 7, 0, &passthrur_ctl), | ||
586 | |||
587 | SND_SOC_DAPM_MUX("PCM Left Swap", SND_SOC_NOPM, | ||
588 | 0, 0, &pcma_mixer), | ||
589 | SND_SOC_DAPM_MUX("PCM Right Swap", SND_SOC_NOPM, | ||
590 | 0, 0, &pcmb_mixer), | ||
591 | |||
592 | SND_SOC_DAPM_SWITCH("HP Left Amp", SND_SOC_NOPM, 0, 0, &hpl_ctl), | ||
593 | SND_SOC_DAPM_SWITCH("HP Right Amp", SND_SOC_NOPM, 0, 0, &hpr_ctl), | ||
594 | |||
595 | SND_SOC_DAPM_SWITCH("SPK Left Amp", SND_SOC_NOPM, 0, 0, &spkl_ctl), | ||
596 | SND_SOC_DAPM_SWITCH("SPK Right Amp", SND_SOC_NOPM, 0, 0, &spkr_ctl), | ||
597 | |||
598 | SND_SOC_DAPM_OUTPUT("HPOUTA"), | ||
599 | SND_SOC_DAPM_OUTPUT("HPOUTB"), | ||
600 | SND_SOC_DAPM_OUTPUT("SPKOUTA"), | ||
601 | SND_SOC_DAPM_OUTPUT("SPKOUTB"), | ||
602 | |||
603 | }; | ||
604 | |||
605 | static const struct snd_soc_dapm_route cs42l52_audio_map[] = { | ||
606 | |||
607 | {"Capture", NULL, "AIFOUTL"}, | ||
608 | {"Capture", NULL, "AIFOUTL"}, | ||
609 | |||
610 | {"AIFOUTL", NULL, "Output Mux"}, | ||
611 | {"AIFOUTR", NULL, "Output Mux"}, | ||
612 | |||
613 | {"Output Mux", "ADC", "ADC Left"}, | ||
614 | {"Output Mux", "ADC", "ADC Right"}, | ||
615 | |||
616 | {"ADC Left", NULL, "Charge Pump"}, | ||
617 | {"ADC Right", NULL, "Charge Pump"}, | ||
618 | |||
619 | {"Charge Pump", NULL, "ADC Left Mux"}, | ||
620 | {"Charge Pump", NULL, "ADC Right Mux"}, | ||
621 | |||
622 | {"ADC Left Mux", "Input1A", "AIN1L"}, | ||
623 | {"ADC Right Mux", "Input1B", "AIN1R"}, | ||
624 | {"ADC Left Mux", "Input2A", "AIN2L"}, | ||
625 | {"ADC Right Mux", "Input2B", "AIN2R"}, | ||
626 | {"ADC Left Mux", "Input3A", "AIN3L"}, | ||
627 | {"ADC Right Mux", "Input3B", "AIN3R"}, | ||
628 | {"ADC Left Mux", "Input4A", "AIN4L"}, | ||
629 | {"ADC Right Mux", "Input4B", "AIN4R"}, | ||
630 | {"ADC Left Mux", "PGA Input Left", "PGA Left"}, | ||
631 | {"ADC Right Mux", "PGA Input Right" , "PGA Right"}, | ||
632 | |||
633 | {"PGA Left", "Switch", "AIN1L"}, | ||
634 | {"PGA Right", "Switch", "AIN1R"}, | ||
635 | {"PGA Left", "Switch", "AIN2L"}, | ||
636 | {"PGA Right", "Switch", "AIN2R"}, | ||
637 | {"PGA Left", "Switch", "AIN3L"}, | ||
638 | {"PGA Right", "Switch", "AIN3R"}, | ||
639 | {"PGA Left", "Switch", "AIN4L"}, | ||
640 | {"PGA Right", "Switch", "AIN4R"}, | ||
641 | |||
642 | {"PGA Left", "Switch", "PGA MICA"}, | ||
643 | {"PGA MICA", NULL, "MICA"}, | ||
644 | |||
645 | {"PGA Right", "Switch", "PGA MICB"}, | ||
646 | {"PGA MICB", NULL, "MICB"}, | ||
647 | |||
648 | {"HPOUTA", NULL, "HP Left Amp"}, | ||
649 | {"HPOUTB", NULL, "HP Right Amp"}, | ||
650 | {"HP Left Amp", NULL, "Bypass Left"}, | ||
651 | {"HP Right Amp", NULL, "Bypass Right"}, | ||
652 | {"Bypass Left", "Switch", "PGA Left"}, | ||
653 | {"Bypass Right", "Switch", "PGA Right"}, | ||
654 | {"HP Left Amp", "Switch", "DAC Left"}, | ||
655 | {"HP Right Amp", "Switch", "DAC Right"}, | ||
656 | |||
657 | {"SPKOUTA", NULL, "SPK Left Amp"}, | ||
658 | {"SPKOUTB", NULL, "SPK Right Amp"}, | ||
659 | |||
660 | {"SPK Left Amp", NULL, "Beep"}, | ||
661 | {"SPK Right Amp", NULL, "Beep"}, | ||
662 | {"SPK Left Amp", "Switch", "Playback"}, | ||
663 | {"SPK Right Amp", "Switch", "Playback"}, | ||
664 | |||
665 | {"DAC Left", NULL, "Beep"}, | ||
666 | {"DAC Right", NULL, "Beep"}, | ||
667 | {"DAC Left", NULL, "Playback"}, | ||
668 | {"DAC Right", NULL, "Playback"}, | ||
669 | |||
670 | {"Output Mux", "DSP", "Playback"}, | ||
671 | {"Output Mux", "DSP", "Playback"}, | ||
672 | |||
673 | {"AIFINL", NULL, "Playback"}, | ||
674 | {"AIFINR", NULL, "Playback"}, | ||
675 | |||
676 | }; | ||
677 | |||
678 | struct cs42l52_clk_para { | ||
679 | u32 mclk; | ||
680 | u32 rate; | ||
681 | u8 speed; | ||
682 | u8 group; | ||
683 | u8 videoclk; | ||
684 | u8 ratio; | ||
685 | u8 mclkdiv2; | ||
686 | }; | ||
687 | |||
688 | static const struct cs42l52_clk_para clk_map_table[] = { | ||
689 | /*8k*/ | ||
690 | {12288000, 8000, CLK_QS_MODE, CLK_32K, CLK_NO_27M, CLK_R_128, 0}, | ||
691 | {18432000, 8000, CLK_QS_MODE, CLK_32K, CLK_NO_27M, CLK_R_128, 0}, | ||
692 | {12000000, 8000, CLK_QS_MODE, CLK_32K, CLK_NO_27M, CLK_R_125, 0}, | ||
693 | {24000000, 8000, CLK_QS_MODE, CLK_32K, CLK_NO_27M, CLK_R_125, 1}, | ||
694 | {27000000, 8000, CLK_QS_MODE, CLK_32K, CLK_27M_MCLK, CLK_R_125, 0}, | ||
695 | |||
696 | /*11.025k*/ | ||
697 | {11289600, 11025, CLK_QS_MODE, CLK_NO_32K, CLK_NO_27M, CLK_R_128, 0}, | ||
698 | {16934400, 11025, CLK_QS_MODE, CLK_NO_32K, CLK_NO_27M, CLK_R_128, 0}, | ||
699 | |||
700 | /*16k*/ | ||
701 | {12288000, 16000, CLK_HS_MODE, CLK_32K, CLK_NO_27M, CLK_R_128, 0}, | ||
702 | {18432000, 16000, CLK_HS_MODE, CLK_32K, CLK_NO_27M, CLK_R_128, 0}, | ||
703 | {12000000, 16000, CLK_HS_MODE, CLK_32K, CLK_NO_27M, CLK_R_125, 0}, | ||
704 | {24000000, 16000, CLK_HS_MODE, CLK_32K, CLK_NO_27M, CLK_R_125, 1}, | ||
705 | {27000000, 16000, CLK_HS_MODE, CLK_32K, CLK_27M_MCLK, CLK_R_125, 1}, | ||
706 | |||
707 | /*22.05k*/ | ||
708 | {11289600, 22050, CLK_HS_MODE, CLK_NO_32K, CLK_NO_27M, CLK_R_128, 0}, | ||
709 | {16934400, 22050, CLK_HS_MODE, CLK_NO_32K, CLK_NO_27M, CLK_R_128, 0}, | ||
710 | |||
711 | /* 32k */ | ||
712 | {12288000, 32000, CLK_SS_MODE, CLK_32K, CLK_NO_27M, CLK_R_128, 0}, | ||
713 | {18432000, 32000, CLK_SS_MODE, CLK_32K, CLK_NO_27M, CLK_R_128, 0}, | ||
714 | {12000000, 32000, CLK_SS_MODE, CLK_32K, CLK_NO_27M, CLK_R_125, 0}, | ||
715 | {24000000, 32000, CLK_SS_MODE, CLK_32K, CLK_NO_27M, CLK_R_125, 1}, | ||
716 | {27000000, 32000, CLK_SS_MODE, CLK_32K, CLK_27M_MCLK, CLK_R_125, 0}, | ||
717 | |||
718 | /* 44.1k */ | ||
719 | {11289600, 44100, CLK_SS_MODE, CLK_NO_32K, CLK_NO_27M, CLK_R_128, 0}, | ||
720 | {16934400, 44100, CLK_SS_MODE, CLK_NO_32K, CLK_NO_27M, CLK_R_128, 0}, | ||
721 | |||
722 | /* 48k */ | ||
723 | {12288000, 48000, CLK_SS_MODE, CLK_NO_32K, CLK_NO_27M, CLK_R_128, 0}, | ||
724 | {18432000, 48000, CLK_SS_MODE, CLK_NO_32K, CLK_NO_27M, CLK_R_128, 0}, | ||
725 | {12000000, 48000, CLK_SS_MODE, CLK_NO_32K, CLK_NO_27M, CLK_R_125, 0}, | ||
726 | {24000000, 48000, CLK_SS_MODE, CLK_NO_32K, CLK_NO_27M, CLK_R_125, 1}, | ||
727 | {27000000, 48000, CLK_SS_MODE, CLK_NO_32K, CLK_27M_MCLK, CLK_R_125, 1}, | ||
728 | |||
729 | /* 88.2k */ | ||
730 | {11289600, 88200, CLK_DS_MODE, CLK_NO_32K, CLK_NO_27M, CLK_R_128, 0}, | ||
731 | {16934400, 88200, CLK_DS_MODE, CLK_NO_32K, CLK_NO_27M, CLK_R_128, 0}, | ||
732 | |||
733 | /* 96k */ | ||
734 | {12288000, 96000, CLK_DS_MODE, CLK_NO_32K, CLK_NO_27M, CLK_R_128, 0}, | ||
735 | {18432000, 96000, CLK_DS_MODE, CLK_NO_32K, CLK_NO_27M, CLK_R_128, 0}, | ||
736 | {12000000, 96000, CLK_DS_MODE, CLK_NO_32K, CLK_NO_27M, CLK_R_125, 0}, | ||
737 | {24000000, 96000, CLK_DS_MODE, CLK_NO_32K, CLK_NO_27M, CLK_R_125, 1}, | ||
738 | }; | ||
739 | |||
740 | static int cs42l52_get_clk(int mclk, int rate) | ||
741 | { | ||
742 | int i, ret = 0; | ||
743 | u_int mclk1, mclk2 = 0; | ||
744 | |||
745 | for (i = 0; i < ARRAY_SIZE(clk_map_table); i++) { | ||
746 | if (clk_map_table[i].rate == rate) { | ||
747 | mclk1 = clk_map_table[i].mclk; | ||
748 | if (abs(mclk - mclk1) < abs(mclk - mclk2)) { | ||
749 | mclk2 = mclk1; | ||
750 | ret = i; | ||
751 | } | ||
752 | } | ||
753 | } | ||
754 | if (ret > ARRAY_SIZE(clk_map_table)) | ||
755 | return -EINVAL; | ||
756 | return ret; | ||
757 | } | ||
758 | |||
759 | static int cs42l52_set_sysclk(struct snd_soc_dai *codec_dai, | ||
760 | int clk_id, unsigned int freq, int dir) | ||
761 | { | ||
762 | struct snd_soc_codec *codec = codec_dai->codec; | ||
763 | struct cs42l52_private *cs42l52 = snd_soc_codec_get_drvdata(codec); | ||
764 | |||
765 | if ((freq >= CS42L52_MIN_CLK) && (freq <= CS42L52_MAX_CLK)) { | ||
766 | cs42l52->sysclk = freq; | ||
767 | } else { | ||
768 | dev_err(codec->dev, "Invalid freq paramter\n"); | ||
769 | return -EINVAL; | ||
770 | } | ||
771 | return 0; | ||
772 | } | ||
773 | |||
774 | static int cs42l52_set_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt) | ||
775 | { | ||
776 | struct snd_soc_codec *codec = codec_dai->codec; | ||
777 | struct cs42l52_private *cs42l52 = snd_soc_codec_get_drvdata(codec); | ||
778 | int ret = 0; | ||
779 | u8 iface = 0; | ||
780 | |||
781 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { | ||
782 | case SND_SOC_DAIFMT_CBM_CFM: | ||
783 | iface = CS42L52_IFACE_CTL1_MASTER; | ||
784 | break; | ||
785 | case SND_SOC_DAIFMT_CBS_CFS: | ||
786 | iface = CS42L52_IFACE_CTL1_SLAVE; | ||
787 | break; | ||
788 | default: | ||
789 | return -EINVAL; | ||
790 | } | ||
791 | |||
792 | /* interface format */ | ||
793 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { | ||
794 | case SND_SOC_DAIFMT_I2S: | ||
795 | iface |= CS42L52_IFACE_CTL1_ADC_FMT_I2S | | ||
796 | CS42L52_IFACE_CTL1_DAC_FMT_I2S; | ||
797 | break; | ||
798 | case SND_SOC_DAIFMT_RIGHT_J: | ||
799 | iface |= CS42L52_IFACE_CTL1_DAC_FMT_RIGHT_J; | ||
800 | break; | ||
801 | case SND_SOC_DAIFMT_LEFT_J: | ||
802 | iface |= CS42L52_IFACE_CTL1_ADC_FMT_LEFT_J | | ||
803 | CS42L52_IFACE_CTL1_DAC_FMT_LEFT_J; | ||
804 | break; | ||
805 | case SND_SOC_DAIFMT_DSP_A: | ||
806 | iface |= CS42L52_IFACE_CTL1_DSP_MODE_EN; | ||
807 | break; | ||
808 | case SND_SOC_DAIFMT_DSP_B: | ||
809 | break; | ||
810 | default: | ||
811 | return -EINVAL; | ||
812 | } | ||
813 | |||
814 | /* clock inversion */ | ||
815 | switch (fmt & SND_SOC_DAIFMT_INV_MASK) { | ||
816 | case SND_SOC_DAIFMT_NB_NF: | ||
817 | break; | ||
818 | case SND_SOC_DAIFMT_IB_IF: | ||
819 | iface |= CS42L52_IFACE_CTL1_INV_SCLK; | ||
820 | break; | ||
821 | case SND_SOC_DAIFMT_IB_NF: | ||
822 | iface |= CS42L52_IFACE_CTL1_INV_SCLK; | ||
823 | break; | ||
824 | case SND_SOC_DAIFMT_NB_IF: | ||
825 | break; | ||
826 | default: | ||
827 | ret = -EINVAL; | ||
828 | } | ||
829 | cs42l52->config.format = iface; | ||
830 | snd_soc_write(codec, CS42L52_IFACE_CTL1, cs42l52->config.format); | ||
831 | |||
832 | return 0; | ||
833 | } | ||
834 | |||
835 | static int cs42l52_digital_mute(struct snd_soc_dai *dai, int mute) | ||
836 | { | ||
837 | struct snd_soc_codec *codec = dai->codec; | ||
838 | |||
839 | if (mute) | ||
840 | snd_soc_update_bits(codec, CS42L52_PB_CTL1, | ||
841 | CS42L52_PB_CTL1_MUTE_MASK, | ||
842 | CS42L52_PB_CTL1_MUTE); | ||
843 | else | ||
844 | snd_soc_update_bits(codec, CS42L52_PB_CTL1, | ||
845 | CS42L52_PB_CTL1_MUTE_MASK, | ||
846 | CS42L52_PB_CTL1_UNMUTE); | ||
847 | |||
848 | return 0; | ||
849 | } | ||
850 | |||
851 | static int cs42l52_pcm_hw_params(struct snd_pcm_substream *substream, | ||
852 | struct snd_pcm_hw_params *params, | ||
853 | struct snd_soc_dai *dai) | ||
854 | { | ||
855 | struct snd_soc_codec *codec = dai->codec; | ||
856 | struct cs42l52_private *cs42l52 = snd_soc_codec_get_drvdata(codec); | ||
857 | u32 clk = 0; | ||
858 | int index; | ||
859 | |||
860 | index = cs42l52_get_clk(cs42l52->sysclk, params_rate(params)); | ||
861 | if (index >= 0) { | ||
862 | cs42l52->sysclk = clk_map_table[index].mclk; | ||
863 | |||
864 | clk |= (clk_map_table[index].speed << CLK_SPEED_SHIFT) | | ||
865 | (clk_map_table[index].group << CLK_32K_SR_SHIFT) | | ||
866 | (clk_map_table[index].videoclk << CLK_27M_MCLK_SHIFT) | | ||
867 | (clk_map_table[index].ratio << CLK_RATIO_SHIFT) | | ||
868 | clk_map_table[index].mclkdiv2; | ||
869 | |||
870 | snd_soc_write(codec, CS42L52_CLK_CTL, clk); | ||
871 | } else { | ||
872 | dev_err(codec->dev, "can't get correct mclk\n"); | ||
873 | return -EINVAL; | ||
874 | } | ||
875 | |||
876 | return 0; | ||
877 | } | ||
878 | |||
879 | static int cs42l52_set_bias_level(struct snd_soc_codec *codec, | ||
880 | enum snd_soc_bias_level level) | ||
881 | { | ||
882 | struct cs42l52_private *cs42l52 = snd_soc_codec_get_drvdata(codec); | ||
883 | |||
884 | switch (level) { | ||
885 | case SND_SOC_BIAS_ON: | ||
886 | break; | ||
887 | case SND_SOC_BIAS_PREPARE: | ||
888 | snd_soc_update_bits(codec, CS42L52_PWRCTL1, | ||
889 | CS42L52_PWRCTL1_PDN_CODEC, 0); | ||
890 | break; | ||
891 | case SND_SOC_BIAS_STANDBY: | ||
892 | if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { | ||
893 | regcache_cache_only(cs42l52->regmap, false); | ||
894 | regcache_sync(cs42l52->regmap); | ||
895 | } | ||
896 | snd_soc_write(codec, CS42L52_PWRCTL1, CS42L52_PWRCTL1_PDN_ALL); | ||
897 | break; | ||
898 | case SND_SOC_BIAS_OFF: | ||
899 | snd_soc_write(codec, CS42L52_PWRCTL1, CS42L52_PWRCTL1_PDN_ALL); | ||
900 | regcache_cache_only(cs42l52->regmap, true); | ||
901 | break; | ||
902 | } | ||
903 | codec->dapm.bias_level = level; | ||
904 | |||
905 | return 0; | ||
906 | } | ||
907 | |||
908 | #define CS42L52_RATES (SNDRV_PCM_RATE_8000_96000) | ||
909 | |||
910 | #define CS42L52_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_U16_LE | \ | ||
911 | SNDRV_PCM_FMTBIT_S18_3LE | SNDRV_PCM_FMTBIT_U18_3LE | \ | ||
912 | SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_U20_3LE | \ | ||
913 | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_U24_LE) | ||
914 | |||
915 | static struct snd_soc_dai_ops cs42l52_ops = { | ||
916 | .hw_params = cs42l52_pcm_hw_params, | ||
917 | .digital_mute = cs42l52_digital_mute, | ||
918 | .set_fmt = cs42l52_set_fmt, | ||
919 | .set_sysclk = cs42l52_set_sysclk, | ||
920 | }; | ||
921 | |||
922 | static struct snd_soc_dai_driver cs42l52_dai = { | ||
923 | .name = "cs42l52", | ||
924 | .playback = { | ||
925 | .stream_name = "Playback", | ||
926 | .channels_min = 1, | ||
927 | .channels_max = 2, | ||
928 | .rates = CS42L52_RATES, | ||
929 | .formats = CS42L52_FORMATS, | ||
930 | }, | ||
931 | .capture = { | ||
932 | .stream_name = "Capture", | ||
933 | .channels_min = 1, | ||
934 | .channels_max = 2, | ||
935 | .rates = CS42L52_RATES, | ||
936 | .formats = CS42L52_FORMATS, | ||
937 | }, | ||
938 | .ops = &cs42l52_ops, | ||
939 | }; | ||
940 | |||
941 | static int cs42l52_suspend(struct snd_soc_codec *codec) | ||
942 | { | ||
943 | cs42l52_set_bias_level(codec, SND_SOC_BIAS_OFF); | ||
944 | |||
945 | return 0; | ||
946 | } | ||
947 | |||
948 | static int cs42l52_resume(struct snd_soc_codec *codec) | ||
949 | { | ||
950 | cs42l52_set_bias_level(codec, SND_SOC_BIAS_STANDBY); | ||
951 | |||
952 | return 0; | ||
953 | } | ||
954 | |||
955 | #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) | ||
956 | static int beep_rates[] = { | ||
957 | 261, 522, 585, 667, 706, 774, 889, 1000, | ||
958 | 1043, 1200, 1333, 1412, 1600, 1714, 2000, 2182 | ||
959 | }; | ||
960 | |||
961 | static void cs42l52_beep_work(struct work_struct *work) | ||
962 | { | ||
963 | struct cs42l52_private *cs42l52 = | ||
964 | container_of(work, struct cs42l52_private, beep_work); | ||
965 | struct snd_soc_codec *codec = cs42l52->codec; | ||
966 | struct snd_soc_dapm_context *dapm = &codec->dapm; | ||
967 | int i; | ||
968 | int val = 0; | ||
969 | int best = 0; | ||
970 | |||
971 | if (cs42l52->beep_rate) { | ||
972 | for (i = 0; i < ARRAY_SIZE(beep_rates); i++) { | ||
973 | if (abs(cs42l52->beep_rate - beep_rates[i]) < | ||
974 | abs(cs42l52->beep_rate - beep_rates[best])) | ||
975 | best = i; | ||
976 | } | ||
977 | |||
978 | dev_dbg(codec->dev, "Set beep rate %dHz for requested %dHz\n", | ||
979 | beep_rates[best], cs42l52->beep_rate); | ||
980 | |||
981 | val = (best << CS42L52_BEEP_RATE_SHIFT); | ||
982 | |||
983 | snd_soc_dapm_enable_pin(dapm, "Beep"); | ||
984 | } else { | ||
985 | dev_dbg(codec->dev, "Disabling beep\n"); | ||
986 | snd_soc_dapm_disable_pin(dapm, "Beep"); | ||
987 | } | ||
988 | |||
989 | snd_soc_update_bits(codec, CS42L52_BEEP_FREQ, | ||
990 | CS42L52_BEEP_RATE_MASK, val); | ||
991 | |||
992 | snd_soc_dapm_sync(dapm); | ||
993 | } | ||
994 | |||
995 | /* For usability define a way of injecting beep events for the device - | ||
996 | * many systems will not have a keyboard. | ||
997 | */ | ||
998 | static int cs42l52_beep_event(struct input_dev *dev, unsigned int type, | ||
999 | unsigned int code, int hz) | ||
1000 | { | ||
1001 | struct snd_soc_codec *codec = input_get_drvdata(dev); | ||
1002 | struct cs42l52_private *cs42l52 = snd_soc_codec_get_drvdata(codec); | ||
1003 | |||
1004 | dev_dbg(codec->dev, "Beep event %x %x\n", code, hz); | ||
1005 | |||
1006 | switch (code) { | ||
1007 | case SND_BELL: | ||
1008 | if (hz) | ||
1009 | hz = 261; | ||
1010 | case SND_TONE: | ||
1011 | break; | ||
1012 | default: | ||
1013 | return -1; | ||
1014 | } | ||
1015 | |||
1016 | /* Kick the beep from a workqueue */ | ||
1017 | cs42l52->beep_rate = hz; | ||
1018 | schedule_work(&cs42l52->beep_work); | ||
1019 | return 0; | ||
1020 | } | ||
1021 | |||
1022 | static ssize_t cs42l52_beep_set(struct device *dev, | ||
1023 | struct device_attribute *attr, | ||
1024 | const char *buf, size_t count) | ||
1025 | { | ||
1026 | struct cs42l52_private *cs42l52 = dev_get_drvdata(dev); | ||
1027 | long int time; | ||
1028 | int ret; | ||
1029 | |||
1030 | ret = kstrtol(buf, 10, &time); | ||
1031 | if (ret != 0) | ||
1032 | return ret; | ||
1033 | |||
1034 | input_event(cs42l52->beep, EV_SND, SND_TONE, time); | ||
1035 | |||
1036 | return count; | ||
1037 | } | ||
1038 | |||
1039 | static DEVICE_ATTR(beep, 0200, NULL, cs42l52_beep_set); | ||
1040 | |||
1041 | static void cs42l52_init_beep(struct snd_soc_codec *codec) | ||
1042 | { | ||
1043 | struct cs42l52_private *cs42l52 = snd_soc_codec_get_drvdata(codec); | ||
1044 | int ret; | ||
1045 | |||
1046 | cs42l52->beep = input_allocate_device(); | ||
1047 | if (!cs42l52->beep) { | ||
1048 | dev_err(codec->dev, "Failed to allocate beep device\n"); | ||
1049 | return; | ||
1050 | } | ||
1051 | |||
1052 | INIT_WORK(&cs42l52->beep_work, cs42l52_beep_work); | ||
1053 | cs42l52->beep_rate = 0; | ||
1054 | |||
1055 | cs42l52->beep->name = "CS42L52 Beep Generator"; | ||
1056 | cs42l52->beep->phys = dev_name(codec->dev); | ||
1057 | cs42l52->beep->id.bustype = BUS_I2C; | ||
1058 | |||
1059 | cs42l52->beep->evbit[0] = BIT_MASK(EV_SND); | ||
1060 | cs42l52->beep->sndbit[0] = BIT_MASK(SND_BELL) | BIT_MASK(SND_TONE); | ||
1061 | cs42l52->beep->event = cs42l52_beep_event; | ||
1062 | cs42l52->beep->dev.parent = codec->dev; | ||
1063 | input_set_drvdata(cs42l52->beep, codec); | ||
1064 | |||
1065 | ret = input_register_device(cs42l52->beep); | ||
1066 | if (ret != 0) { | ||
1067 | input_free_device(cs42l52->beep); | ||
1068 | cs42l52->beep = NULL; | ||
1069 | dev_err(codec->dev, "Failed to register beep device\n"); | ||
1070 | } | ||
1071 | |||
1072 | ret = device_create_file(codec->dev, &dev_attr_beep); | ||
1073 | if (ret != 0) { | ||
1074 | dev_err(codec->dev, "Failed to create keyclick file: %d\n", | ||
1075 | ret); | ||
1076 | } | ||
1077 | } | ||
1078 | |||
1079 | static void cs42l52_free_beep(struct snd_soc_codec *codec) | ||
1080 | { | ||
1081 | struct cs42l52_private *cs42l52 = snd_soc_codec_get_drvdata(codec); | ||
1082 | |||
1083 | device_remove_file(codec->dev, &dev_attr_beep); | ||
1084 | input_unregister_device(cs42l52->beep); | ||
1085 | cancel_work_sync(&cs42l52->beep_work); | ||
1086 | cs42l52->beep = NULL; | ||
1087 | |||
1088 | snd_soc_update_bits(codec, CS42L52_BEEP_TONE_CTL, | ||
1089 | CS42L52_BEEP_EN_MASK, 0); | ||
1090 | } | ||
1091 | #else | ||
1092 | static void cs42l52_init_beep(struct snd_soc_codec *codec) | ||
1093 | { | ||
1094 | } | ||
1095 | |||
1096 | static void cs42l52_free_beep(struct snd_soc_codec *codec) | ||
1097 | { | ||
1098 | } | ||
1099 | #endif | ||
1100 | |||
1101 | static int cs42l52_probe(struct snd_soc_codec *codec) | ||
1102 | { | ||
1103 | struct cs42l52_private *cs42l52 = snd_soc_codec_get_drvdata(codec); | ||
1104 | int ret; | ||
1105 | |||
1106 | codec->control_data = cs42l52->regmap; | ||
1107 | ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_REGMAP); | ||
1108 | if (ret < 0) { | ||
1109 | dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); | ||
1110 | return ret; | ||
1111 | } | ||
1112 | regcache_cache_only(cs42l52->regmap, true); | ||
1113 | |||
1114 | cs42l52_init_beep(codec); | ||
1115 | |||
1116 | cs42l52_set_bias_level(codec, SND_SOC_BIAS_STANDBY); | ||
1117 | |||
1118 | cs42l52->sysclk = CS42L52_DEFAULT_CLK; | ||
1119 | cs42l52->config.format = CS42L52_DEFAULT_FORMAT; | ||
1120 | |||
1121 | /* Set Platform MICx CFG */ | ||
1122 | snd_soc_update_bits(codec, CS42L52_MICA_CTL, | ||
1123 | CS42L52_MIC_CTL_TYPE_MASK, | ||
1124 | cs42l52->pdata.mica_cfg << | ||
1125 | CS42L52_MIC_CTL_TYPE_SHIFT); | ||
1126 | |||
1127 | snd_soc_update_bits(codec, CS42L52_MICB_CTL, | ||
1128 | CS42L52_MIC_CTL_TYPE_MASK, | ||
1129 | cs42l52->pdata.micb_cfg << | ||
1130 | CS42L52_MIC_CTL_TYPE_SHIFT); | ||
1131 | |||
1132 | /* if Single Ended, Get Mic_Select */ | ||
1133 | if (cs42l52->pdata.mica_cfg) | ||
1134 | snd_soc_update_bits(codec, CS42L52_MICA_CTL, | ||
1135 | CS42L52_MIC_CTL_MIC_SEL_MASK, | ||
1136 | cs42l52->pdata.mica_sel << | ||
1137 | CS42L52_MIC_CTL_MIC_SEL_SHIFT); | ||
1138 | if (cs42l52->pdata.micb_cfg) | ||
1139 | snd_soc_update_bits(codec, CS42L52_MICB_CTL, | ||
1140 | CS42L52_MIC_CTL_MIC_SEL_MASK, | ||
1141 | cs42l52->pdata.micb_sel << | ||
1142 | CS42L52_MIC_CTL_MIC_SEL_SHIFT); | ||
1143 | |||
1144 | /* Set Platform Charge Pump Freq */ | ||
1145 | snd_soc_update_bits(codec, CS42L52_CHARGE_PUMP, | ||
1146 | CS42L52_CHARGE_PUMP_MASK, | ||
1147 | cs42l52->pdata.chgfreq << | ||
1148 | CS42L52_CHARGE_PUMP_SHIFT); | ||
1149 | |||
1150 | /* Set Platform Bias Level */ | ||
1151 | snd_soc_update_bits(codec, CS42L52_IFACE_CTL2, | ||
1152 | CS42L52_IFACE_CTL2_BIAS_LVL, | ||
1153 | cs42l52->pdata.micbias_lvl); | ||
1154 | |||
1155 | return ret; | ||
1156 | } | ||
1157 | |||
1158 | static int cs42l52_remove(struct snd_soc_codec *codec) | ||
1159 | { | ||
1160 | cs42l52_free_beep(codec); | ||
1161 | cs42l52_set_bias_level(codec, SND_SOC_BIAS_OFF); | ||
1162 | |||
1163 | return 0; | ||
1164 | } | ||
1165 | |||
1166 | static struct snd_soc_codec_driver soc_codec_dev_cs42l52 = { | ||
1167 | .probe = cs42l52_probe, | ||
1168 | .remove = cs42l52_remove, | ||
1169 | .suspend = cs42l52_suspend, | ||
1170 | .resume = cs42l52_resume, | ||
1171 | .set_bias_level = cs42l52_set_bias_level, | ||
1172 | |||
1173 | .dapm_widgets = cs42l52_dapm_widgets, | ||
1174 | .num_dapm_widgets = ARRAY_SIZE(cs42l52_dapm_widgets), | ||
1175 | .dapm_routes = cs42l52_audio_map, | ||
1176 | .num_dapm_routes = ARRAY_SIZE(cs42l52_audio_map), | ||
1177 | |||
1178 | .controls = cs42l52_snd_controls, | ||
1179 | .num_controls = ARRAY_SIZE(cs42l52_snd_controls), | ||
1180 | }; | ||
1181 | |||
1182 | /* Current and threshold powerup sequence Pg37 */ | ||
1183 | static const struct reg_default cs42l52_threshold_patch[] = { | ||
1184 | |||
1185 | { 0x00, 0x99 }, | ||
1186 | { 0x3E, 0xBA }, | ||
1187 | { 0x47, 0x80 }, | ||
1188 | { 0x32, 0xBB }, | ||
1189 | { 0x32, 0x3B }, | ||
1190 | { 0x00, 0x00 }, | ||
1191 | |||
1192 | }; | ||
1193 | |||
1194 | static struct regmap_config cs42l52_regmap = { | ||
1195 | .reg_bits = 8, | ||
1196 | .val_bits = 8, | ||
1197 | |||
1198 | .max_register = CS42L52_MAX_REGISTER, | ||
1199 | .reg_defaults = cs42l52_reg_defaults, | ||
1200 | .num_reg_defaults = ARRAY_SIZE(cs42l52_reg_defaults), | ||
1201 | .readable_reg = cs42l52_readable_register, | ||
1202 | .volatile_reg = cs42l52_volatile_register, | ||
1203 | .cache_type = REGCACHE_RBTREE, | ||
1204 | }; | ||
1205 | |||
1206 | static int cs42l52_i2c_probe(struct i2c_client *i2c_client, | ||
1207 | const struct i2c_device_id *id) | ||
1208 | { | ||
1209 | struct cs42l52_private *cs42l52; | ||
1210 | int ret; | ||
1211 | unsigned int devid = 0; | ||
1212 | unsigned int reg; | ||
1213 | |||
1214 | cs42l52 = devm_kzalloc(&i2c_client->dev, sizeof(struct cs42l52_private), | ||
1215 | GFP_KERNEL); | ||
1216 | if (cs42l52 == NULL) | ||
1217 | return -ENOMEM; | ||
1218 | cs42l52->dev = &i2c_client->dev; | ||
1219 | |||
1220 | cs42l52->regmap = regmap_init_i2c(i2c_client, &cs42l52_regmap); | ||
1221 | if (IS_ERR(cs42l52->regmap)) { | ||
1222 | ret = PTR_ERR(cs42l52->regmap); | ||
1223 | dev_err(&i2c_client->dev, "regmap_init() failed: %d\n", ret); | ||
1224 | goto err; | ||
1225 | } | ||
1226 | |||
1227 | i2c_set_clientdata(i2c_client, cs42l52); | ||
1228 | |||
1229 | if (dev_get_platdata(&i2c_client->dev)) | ||
1230 | memcpy(&cs42l52->pdata, dev_get_platdata(&i2c_client->dev), | ||
1231 | sizeof(cs42l52->pdata)); | ||
1232 | |||
1233 | ret = regmap_register_patch(cs42l52->regmap, cs42l52_threshold_patch, | ||
1234 | ARRAY_SIZE(cs42l52_threshold_patch)); | ||
1235 | if (ret != 0) | ||
1236 | dev_warn(cs42l52->dev, "Failed to apply regmap patch: %d\n", | ||
1237 | ret); | ||
1238 | |||
1239 | ret = regmap_read(cs42l52->regmap, CS42L52_CHIP, ®); | ||
1240 | devid = reg & CS42L52_CHIP_ID_MASK; | ||
1241 | if (devid != CS42L52_CHIP_ID) { | ||
1242 | ret = -ENODEV; | ||
1243 | dev_err(&i2c_client->dev, | ||
1244 | "CS42L52 Device ID (%X). Expected %X\n", | ||
1245 | devid, CS42L52_CHIP_ID); | ||
1246 | goto err_regmap; | ||
1247 | } | ||
1248 | |||
1249 | regcache_cache_only(cs42l52->regmap, true); | ||
1250 | |||
1251 | ret = snd_soc_register_codec(&i2c_client->dev, | ||
1252 | &soc_codec_dev_cs42l52, &cs42l52_dai, 1); | ||
1253 | if (ret < 0) | ||
1254 | goto err_regmap; | ||
1255 | return 0; | ||
1256 | |||
1257 | err_regmap: | ||
1258 | regmap_exit(cs42l52->regmap); | ||
1259 | |||
1260 | err: | ||
1261 | return ret; | ||
1262 | } | ||
1263 | |||
1264 | static int cs42l52_i2c_remove(struct i2c_client *client) | ||
1265 | { | ||
1266 | struct cs42l52_private *cs42l52 = i2c_get_clientdata(client); | ||
1267 | |||
1268 | snd_soc_unregister_codec(&client->dev); | ||
1269 | regmap_exit(cs42l52->regmap); | ||
1270 | |||
1271 | return 0; | ||
1272 | } | ||
1273 | |||
1274 | static const struct i2c_device_id cs42l52_id[] = { | ||
1275 | { "cs42l52", 0 }, | ||
1276 | { } | ||
1277 | }; | ||
1278 | MODULE_DEVICE_TABLE(i2c, cs42l52_id); | ||
1279 | |||
1280 | static struct i2c_driver cs42l52_i2c_driver = { | ||
1281 | .driver = { | ||
1282 | .name = "cs42l52", | ||
1283 | .owner = THIS_MODULE, | ||
1284 | }, | ||
1285 | .id_table = cs42l52_id, | ||
1286 | .probe = cs42l52_i2c_probe, | ||
1287 | .remove = __devexit_p(cs42l52_i2c_remove), | ||
1288 | }; | ||
1289 | |||
1290 | module_i2c_driver(cs42l52_i2c_driver); | ||
1291 | |||
1292 | MODULE_DESCRIPTION("ASoC CS42L52 driver"); | ||
1293 | MODULE_AUTHOR("Georgi Vlaev, Nucleus Systems Ltd, <joe@nucleusys.com>"); | ||
1294 | MODULE_AUTHOR("Brian Austin, Cirrus Logic Inc, <brian.austin@cirrus.com>"); | ||
1295 | MODULE_LICENSE("GPL"); | ||
diff --git a/sound/soc/codecs/cs42l52.h b/sound/soc/codecs/cs42l52.h new file mode 100644 index 000000000000..60985c059071 --- /dev/null +++ b/sound/soc/codecs/cs42l52.h | |||
@@ -0,0 +1,274 @@ | |||
1 | /* | ||
2 | * cs42l52.h -- CS42L52 ALSA SoC audio driver | ||
3 | * | ||
4 | * Copyright 2012 CirrusLogic, Inc. | ||
5 | * | ||
6 | * Author: Georgi Vlaev <joe@nucleusys.com> | ||
7 | * Author: Brian Austin <brian.austin@cirrus.com> | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or modify | ||
10 | * it under the terms of the GNU General Public License version 2 as | ||
11 | * published by the Free Software Foundation. | ||
12 | * | ||
13 | */ | ||
14 | |||
15 | #ifndef __CS42L52_H__ | ||
16 | #define __CS42L52_H__ | ||
17 | |||
18 | #define CS42L52_NAME "CS42L52" | ||
19 | #define CS42L52_DEFAULT_CLK 12000000 | ||
20 | #define CS42L52_MIN_CLK 11000000 | ||
21 | #define CS42L52_MAX_CLK 27000000 | ||
22 | #define CS42L52_DEFAULT_FORMAT SNDRV_PCM_FMTBIT_S16_LE | ||
23 | #define CS42L52_DEFAULT_MAX_CHANS 2 | ||
24 | #define CS42L52_SYSCLK 1 | ||
25 | |||
26 | #define CS42L52_CHIP_SWICTH (1 << 17) | ||
27 | #define CS42L52_ALL_IN_ONE (1 << 16) | ||
28 | #define CS42L52_CHIP_ONE 0x00 | ||
29 | #define CS42L52_CHIP_TWO 0x01 | ||
30 | #define CS42L52_CHIP_THR 0x02 | ||
31 | #define CS42L52_CHIP_MASK 0x0f | ||
32 | |||
33 | #define CS42L52_FIX_BITS_CTL 0x00 | ||
34 | #define CS42L52_CHIP 0x01 | ||
35 | #define CS42L52_CHIP_ID 0xE0 | ||
36 | #define CS42L52_CHIP_ID_MASK 0xF8 | ||
37 | #define CS42L52_CHIP_REV_A0 0x00 | ||
38 | #define CS42L52_CHIP_REV_A1 0x01 | ||
39 | #define CS42L52_CHIP_REV_B0 0x02 | ||
40 | #define CS42L52_CHIP_REV_MASK 0x03 | ||
41 | |||
42 | #define CS42L52_PWRCTL1 0x02 | ||
43 | #define CS42L52_PWRCTL1_PDN_ALL 0x9F | ||
44 | #define CS42L52_PWRCTL1_PDN_CHRG 0x80 | ||
45 | #define CS42L52_PWRCTL1_PDN_PGAB 0x10 | ||
46 | #define CS42L52_PWRCTL1_PDN_PGAA 0x08 | ||
47 | #define CS42L52_PWRCTL1_PDN_ADCB 0x04 | ||
48 | #define CS42L52_PWRCTL1_PDN_ADCA 0x02 | ||
49 | #define CS42L52_PWRCTL1_PDN_CODEC 0x01 | ||
50 | |||
51 | #define CS42L52_PWRCTL2 0x03 | ||
52 | #define CS42L52_PWRCTL2_OVRDB (1 << 4) | ||
53 | #define CS42L52_PWRCTL2_OVRDA (1 << 3) | ||
54 | #define CS42L52_PWRCTL2_PDN_MICB (1 << 2) | ||
55 | #define CS42L52_PWRCTL2_PDN_MICB_SHIFT 2 | ||
56 | #define CS42L52_PWRCTL2_PDN_MICA (1 << 1) | ||
57 | #define CS42L52_PWRCTL2_PDN_MICA_SHIFT 1 | ||
58 | #define CS42L52_PWRCTL2_PDN_MICBIAS (1 << 0) | ||
59 | #define CS42L52_PWRCTL2_PDN_MICBIAS_SHIFT 0 | ||
60 | |||
61 | #define CS42L52_PWRCTL3 0x04 | ||
62 | #define CS42L52_PWRCTL3_HPB_PDN_SHIFT 6 | ||
63 | #define CS42L52_PWRCTL3_HPB_ON_LOW 0x00 | ||
64 | #define CS42L52_PWRCTL3_HPB_ON_HIGH 0x01 | ||
65 | #define CS42L52_PWRCTL3_HPB_ALWAYS_ON 0x02 | ||
66 | #define CS42L52_PWRCTL3_HPB_ALWAYS_OFF 0x03 | ||
67 | #define CS42L52_PWRCTL3_HPA_PDN_SHIFT 4 | ||
68 | #define CS42L52_PWRCTL3_HPA_ON_LOW 0x00 | ||
69 | #define CS42L52_PWRCTL3_HPA_ON_HIGH 0x01 | ||
70 | #define CS42L52_PWRCTL3_HPA_ALWAYS_ON 0x02 | ||
71 | #define CS42L52_PWRCTL3_HPA_ALWAYS_OFF 0x03 | ||
72 | #define CS42L52_PWRCTL3_SPKB_PDN_SHIFT 2 | ||
73 | #define CS42L52_PWRCTL3_SPKB_ON_LOW 0x00 | ||
74 | #define CS42L52_PWRCTL3_SPKB_ON_HIGH 0x01 | ||
75 | #define CS42L52_PWRCTL3_SPKB_ALWAYS_ON 0x02 | ||
76 | #define CS42L52_PWRCTL3_PDN_SPKB (1 << 2) | ||
77 | #define CS42L52_PWRCTL3_PDN_SPKA (1 << 0) | ||
78 | #define CS42L52_PWRCTL3_SPKA_PDN_SHIFT 0 | ||
79 | #define CS42L52_PWRCTL3_SPKA_ON_LOW 0x00 | ||
80 | #define CS42L52_PWRCTL3_SPKA_ON_HIGH 0x01 | ||
81 | #define CS42L52_PWRCTL3_SPKA_ALWAYS_ON 0x02 | ||
82 | |||
83 | #define CS42L52_DEFAULT_OUTPUT_STATE 0x05 | ||
84 | #define CS42L52_PWRCTL3_CONF_MASK 0x03 | ||
85 | |||
86 | #define CS42L52_CLK_CTL 0x05 | ||
87 | #define CLK_AUTODECT_ENABLE (1 << 7) | ||
88 | #define CLK_SPEED_SHIFT 5 | ||
89 | #define CLK_DS_MODE 0x00 | ||
90 | #define CLK_SS_MODE 0x01 | ||
91 | #define CLK_HS_MODE 0x02 | ||
92 | #define CLK_QS_MODE 0x03 | ||
93 | #define CLK_32K_SR_SHIFT 4 | ||
94 | #define CLK_32K 0x01 | ||
95 | #define CLK_NO_32K 0x00 | ||
96 | #define CLK_27M_MCLK_SHIFT 3 | ||
97 | #define CLK_27M_MCLK 0x01 | ||
98 | #define CLK_NO_27M 0x00 | ||
99 | #define CLK_RATIO_SHIFT 1 | ||
100 | #define CLK_R_128 0x00 | ||
101 | #define CLK_R_125 0x01 | ||
102 | #define CLK_R_132 0x02 | ||
103 | #define CLK_R_136 0x03 | ||
104 | |||
105 | #define CS42L52_IFACE_CTL1 0x06 | ||
106 | #define CS42L52_IFACE_CTL1_MASTER (1 << 7) | ||
107 | #define CS42L52_IFACE_CTL1_SLAVE (0 << 7) | ||
108 | #define CS42L52_IFACE_CTL1_INV_SCLK (1 << 6) | ||
109 | #define CS42L52_IFACE_CTL1_ADC_FMT_I2S (1 << 5) | ||
110 | #define CS42L52_IFACE_CTL1_ADC_FMT_LEFT_J (0 << 5) | ||
111 | #define CS42L52_IFACE_CTL1_DSP_MODE_EN (1 << 4) | ||
112 | #define CS42L52_IFACE_CTL1_DAC_FMT_LEFT_J (0 << 2) | ||
113 | #define CS42L52_IFACE_CTL1_DAC_FMT_I2S (1 << 2) | ||
114 | #define CS42L52_IFACE_CTL1_DAC_FMT_RIGHT_J (2 << 2) | ||
115 | #define CS42L52_IFACE_CTL1_WL_32BIT (0x00) | ||
116 | #define CS42L52_IFACE_CTL1_WL_24BIT (0x01) | ||
117 | #define CS42L52_IFACE_CTL1_WL_20BIT (0x02) | ||
118 | #define CS42L52_IFACE_CTL1_WL_16BIT (0x03) | ||
119 | #define CS42L52_IFACE_CTL1_WL_MASK 0xFFFF | ||
120 | |||
121 | #define CS42L52_IFACE_CTL2 0x07 | ||
122 | #define CS42L52_IFACE_CTL2_SC_MC_EQ (1 << 6) | ||
123 | #define CS42L52_IFACE_CTL2_LOOPBACK (1 << 5) | ||
124 | #define CS42L52_IFACE_CTL2_S_MODE_OUTPUT_EN (0 << 4) | ||
125 | #define CS42L52_IFACE_CTL2_S_MODE_OUTPUT_HIZ (1 << 4) | ||
126 | #define CS42L52_IFACE_CTL2_HP_SW_INV (1 << 3) | ||
127 | #define CS42L52_IFACE_CTL2_BIAS_LVL 0x07 | ||
128 | |||
129 | #define CS42L52_ADC_PGA_A 0x08 | ||
130 | #define CS42L52_ADC_PGA_B 0x09 | ||
131 | #define CS42L52_ADC_SEL_SHIFT 5 | ||
132 | #define CS42L52_ADC_SEL_AIN1 0x00 | ||
133 | #define CS42L52_ADC_SEL_AIN2 0x01 | ||
134 | #define CS42L52_ADC_SEL_AIN3 0x02 | ||
135 | #define CS42L52_ADC_SEL_AIN4 0x03 | ||
136 | #define CS42L52_ADC_SEL_PGA 0x04 | ||
137 | |||
138 | #define CS42L52_ANALOG_HPF_CTL 0x0A | ||
139 | #define CS42L52_HPF_CTL_ANLGSFTB (1 << 3) | ||
140 | #define CS42L52_HPF_CTL_ANLGSFTA (1 << 0) | ||
141 | |||
142 | #define CS42L52_ADC_HPF_FREQ 0x0B | ||
143 | #define CS42L52_ADC_MISC_CTL 0x0C | ||
144 | #define CS42L52_ADC_MISC_CTL_SOURCE_DSP (1 << 6) | ||
145 | |||
146 | #define CS42L52_PB_CTL1 0x0D | ||
147 | #define CS42L52_PB_CTL1_HP_GAIN_SHIFT 5 | ||
148 | #define CS42L52_PB_CTL1_HP_GAIN_03959 0x00 | ||
149 | #define CS42L52_PB_CTL1_HP_GAIN_04571 0x01 | ||
150 | #define CS42L52_PB_CTL1_HP_GAIN_05111 0x02 | ||
151 | #define CS42L52_PB_CTL1_HP_GAIN_06047 0x03 | ||
152 | #define CS42L52_PB_CTL1_HP_GAIN_07099 0x04 | ||
153 | #define CS42L52_PB_CTL1_HP_GAIN_08399 0x05 | ||
154 | #define CS42L52_PB_CTL1_HP_GAIN_10000 0x06 | ||
155 | #define CS42L52_PB_CTL1_HP_GAIN_11430 0x07 | ||
156 | #define CS42L52_PB_CTL1_INV_PCMB (1 << 3) | ||
157 | #define CS42L52_PB_CTL1_INV_PCMA (1 << 2) | ||
158 | #define CS42L52_PB_CTL1_MSTB_MUTE (1 << 1) | ||
159 | #define CS42L52_PB_CTL1_MSTA_MUTE (1 << 0) | ||
160 | #define CS42L52_PB_CTL1_MUTE_MASK 0xFFFD | ||
161 | #define CS42L52_PB_CTL1_MUTE 3 | ||
162 | #define CS42L52_PB_CTL1_UNMUTE 0 | ||
163 | |||
164 | #define CS42L52_MISC_CTL 0x0E | ||
165 | #define CS42L52_MISC_CTL_DEEMPH (1 << 2) | ||
166 | #define CS42L52_MISC_CTL_DIGSFT (1 << 1) | ||
167 | #define CS42L52_MISC_CTL_DIGZC (1 << 0) | ||
168 | |||
169 | #define CS42L52_PB_CTL2 0x0F | ||
170 | #define CS42L52_PB_CTL2_HPB_MUTE (1 << 7) | ||
171 | #define CS42L52_PB_CTL2_HPA_MUTE (1 << 6) | ||
172 | #define CS42L52_PB_CTL2_SPKB_MUTE (1 << 5) | ||
173 | #define CS42L52_PB_CTL2_SPKA_MUTE (1 << 4) | ||
174 | #define CS42L52_PB_CTL2_SPK_SWAP (1 << 2) | ||
175 | #define CS42L52_PB_CTL2_SPK_MONO (1 << 1) | ||
176 | #define CS42L52_PB_CTL2_SPK_MUTE50 (1 << 0) | ||
177 | |||
178 | #define CS42L52_MICA_CTL 0x10 | ||
179 | #define CS42L52_MICB_CTL 0x11 | ||
180 | #define CS42L52_MIC_CTL_MIC_SEL_MASK 0xBF | ||
181 | #define CS42L52_MIC_CTL_MIC_SEL_SHIFT 6 | ||
182 | #define CS42L52_MIC_CTL_TYPE_MASK 0xDF | ||
183 | #define CS42L52_MIC_CTL_TYPE_SHIFT 5 | ||
184 | |||
185 | |||
186 | #define CS42L52_PGAA_CTL 0x12 | ||
187 | #define CS42L52_PGAB_CTL 0x13 | ||
188 | #define CS42L52_PGAX_CTL_VOL_12DB 24 | ||
189 | #define CS42L52_PGAX_CTL_VOL_6DB 12 /*step size 0.5db*/ | ||
190 | |||
191 | #define CS42L52_PASSTHRUA_VOL 0x14 | ||
192 | #define CS42L52_PASSTHRUB_VOL 0x15 | ||
193 | |||
194 | #define CS42L52_ADCA_VOL 0x16 | ||
195 | #define CS42L52_ADCB_VOL 0x17 | ||
196 | #define CS42L52_ADCX_VOL_24DB 24 /*step size 1db*/ | ||
197 | #define CS42L52_ADCX_VOL_12DB 12 | ||
198 | #define CS42L52_ADCX_VOL_6DB 6 | ||
199 | |||
200 | #define CS42L52_ADCA_MIXER_VOL 0x18 | ||
201 | #define CS42L52_ADCB_MIXER_VOL 0x19 | ||
202 | #define CS42L52_ADC_MIXER_VOL_12DB 0x18 | ||
203 | |||
204 | #define CS42L52_PCMA_MIXER_VOL 0x1A | ||
205 | #define CS42L52_PCMB_MIXER_VOL 0x1B | ||
206 | |||
207 | #define CS42L52_BEEP_FREQ 0x1C | ||
208 | #define CS42L52_BEEP_VOL 0x1D | ||
209 | #define CS42L52_BEEP_TONE_CTL 0x1E | ||
210 | #define CS42L52_BEEP_RATE_SHIFT 4 | ||
211 | #define CS42L52_BEEP_RATE_MASK 0x0F | ||
212 | |||
213 | #define CS42L52_TONE_CTL 0x1F | ||
214 | #define CS42L52_BEEP_EN_MASK 0x3F | ||
215 | |||
216 | #define CS42L52_MASTERA_VOL 0x20 | ||
217 | #define CS42L52_MASTERB_VOL 0x21 | ||
218 | |||
219 | #define CS42L52_HPA_VOL 0x22 | ||
220 | #define CS42L52_HPB_VOL 0x23 | ||
221 | #define CS42L52_DEFAULT_HP_VOL 0xF0 | ||
222 | |||
223 | #define CS42L52_SPKA_VOL 0x24 | ||
224 | #define CS42L52_SPKB_VOL 0x25 | ||
225 | #define CS42L52_DEFAULT_SPK_VOL 0xF0 | ||
226 | |||
227 | #define CS42L52_ADC_PCM_MIXER 0x26 | ||
228 | |||
229 | #define CS42L52_LIMITER_CTL1 0x27 | ||
230 | #define CS42L52_LIMITER_CTL2 0x28 | ||
231 | #define CS42L52_LIMITER_AT_RATE 0x29 | ||
232 | |||
233 | #define CS42L52_ALC_CTL 0x2A | ||
234 | #define CS42L52_ALC_CTL_ALCB_ENABLE_SHIFT 7 | ||
235 | #define CS42L52_ALC_CTL_ALCA_ENABLE_SHIFT 6 | ||
236 | #define CS42L52_ALC_CTL_FASTEST_ATTACK 0 | ||
237 | |||
238 | #define CS42L52_ALC_RATE 0x2B | ||
239 | #define CS42L52_ALC_SLOWEST_RELEASE 0x3F | ||
240 | |||
241 | #define CS42L52_ALC_THRESHOLD 0x2C | ||
242 | #define CS42L52_ALC_MAX_RATE_SHIFT 5 | ||
243 | #define CS42L52_ALC_MIN_RATE_SHIFT 2 | ||
244 | #define CS42L52_ALC_RATE_0DB 0 | ||
245 | #define CS42L52_ALC_RATE_3DB 1 | ||
246 | #define CS42L52_ALC_RATE_6DB 2 | ||
247 | |||
248 | #define CS42L52_NOISE_GATE_CTL 0x2D | ||
249 | #define CS42L52_NG_ENABLE_SHIFT 6 | ||
250 | #define CS42L52_NG_THRESHOLD_SHIFT 2 | ||
251 | #define CS42L52_NG_MIN_70DB 2 | ||
252 | #define CS42L52_NG_DELAY_SHIFT 0 | ||
253 | #define CS42L52_NG_DELAY_100MS 1 | ||
254 | |||
255 | #define CS42L52_CLK_STATUS 0x2E | ||
256 | #define CS42L52_BATT_COMPEN 0x2F | ||
257 | |||
258 | #define CS42L52_BATT_LEVEL 0x30 | ||
259 | #define CS42L52_SPK_STATUS 0x31 | ||
260 | #define CS42L52_SPK_STATUS_PIN_SHIFT 3 | ||
261 | #define CS42L52_SPK_STATUS_PIN_HIGH 1 | ||
262 | |||
263 | #define CS42L52_TEM_CTL 0x32 | ||
264 | #define CS42L52_TEM_CTL_SET 0x80 | ||
265 | #define CS42L52_THE_FOLDBACK 0x33 | ||
266 | #define CS42L52_CHARGE_PUMP 0x34 | ||
267 | #define CS42L52_CHARGE_PUMP_MASK 0xF0 | ||
268 | #define CS42L52_CHARGE_PUMP_SHIFT 4 | ||
269 | #define CS42L52_FIX_BITS1 0x3E | ||
270 | #define CS42L52_FIX_BITS2 0x47 | ||
271 | |||
272 | #define CS42L52_MAX_REGISTER 0x34 | ||
273 | |||
274 | #endif | ||
diff --git a/sound/soc/codecs/cs42l73.c b/sound/soc/codecs/cs42l73.c index 3686417f5ea5..e0d45fdaa750 100644 --- a/sound/soc/codecs/cs42l73.c +++ b/sound/soc/codecs/cs42l73.c | |||
@@ -43,9 +43,6 @@ struct cs42l73_private { | |||
43 | }; | 43 | }; |
44 | 44 | ||
45 | static const struct reg_default cs42l73_reg_defaults[] = { | 45 | static const struct reg_default cs42l73_reg_defaults[] = { |
46 | { 1, 0x42 }, /* r01 - Device ID A&B */ | ||
47 | { 2, 0xA7 }, /* r02 - Device ID C&D */ | ||
48 | { 3, 0x30 }, /* r03 - Device ID E */ | ||
49 | { 6, 0xF1 }, /* r06 - Power Ctl 1 */ | 46 | { 6, 0xF1 }, /* r06 - Power Ctl 1 */ |
50 | { 7, 0xDF }, /* r07 - Power Ctl 2 */ | 47 | { 7, 0xDF }, /* r07 - Power Ctl 2 */ |
51 | { 8, 0x3F }, /* r08 - Power Ctl 3 */ | 48 | { 8, 0x3F }, /* r08 - Power Ctl 3 */ |
@@ -402,37 +399,37 @@ static const struct snd_kcontrol_new ear_amp_ctl = | |||
402 | 399 | ||
403 | static const struct snd_kcontrol_new cs42l73_snd_controls[] = { | 400 | static const struct snd_kcontrol_new cs42l73_snd_controls[] = { |
404 | SOC_DOUBLE_R_SX_TLV("Headphone Analog Playback Volume", | 401 | SOC_DOUBLE_R_SX_TLV("Headphone Analog Playback Volume", |
405 | CS42L73_HPAAVOL, CS42L73_HPBAVOL, 7, | 402 | CS42L73_HPAAVOL, CS42L73_HPBAVOL, 0, |
406 | 0xffffffC1, 0x0C, hpaloa_tlv), | 403 | 0x41, 0x4B, hpaloa_tlv), |
407 | 404 | ||
408 | SOC_DOUBLE_R_SX_TLV("LineOut Analog Playback Volume", CS42L73_LOAAVOL, | 405 | SOC_DOUBLE_R_SX_TLV("LineOut Analog Playback Volume", CS42L73_LOAAVOL, |
409 | CS42L73_LOBAVOL, 7, 0xffffffC1, 0x0C, hpaloa_tlv), | 406 | CS42L73_LOBAVOL, 0, 0x41, 0x4B, hpaloa_tlv), |
410 | 407 | ||
411 | SOC_DOUBLE_R_SX_TLV("Input PGA Analog Volume", CS42L73_MICAPREPGAAVOL, | 408 | SOC_DOUBLE_R_SX_TLV("Input PGA Analog Volume", CS42L73_MICAPREPGAAVOL, |
412 | CS42L73_MICBPREPGABVOL, 5, 0xffffff35, | 409 | CS42L73_MICBPREPGABVOL, 5, 0x34, |
413 | 0x34, micpga_tlv), | 410 | 0x24, micpga_tlv), |
414 | 411 | ||
415 | SOC_DOUBLE_R("MIC Preamp Switch", CS42L73_MICAPREPGAAVOL, | 412 | SOC_DOUBLE_R("MIC Preamp Switch", CS42L73_MICAPREPGAAVOL, |
416 | CS42L73_MICBPREPGABVOL, 6, 1, 1), | 413 | CS42L73_MICBPREPGABVOL, 6, 1, 1), |
417 | 414 | ||
418 | SOC_DOUBLE_R_SX_TLV("Input Path Digital Volume", CS42L73_IPADVOL, | 415 | SOC_DOUBLE_R_SX_TLV("Input Path Digital Volume", CS42L73_IPADVOL, |
419 | CS42L73_IPBDVOL, 7, 0xffffffA0, 0xA0, ipd_tlv), | 416 | CS42L73_IPBDVOL, 0, 0xA0, 0x6C, ipd_tlv), |
420 | 417 | ||
421 | SOC_DOUBLE_R_SX_TLV("HL Digital Playback Volume", | 418 | SOC_DOUBLE_R_SX_TLV("HL Digital Playback Volume", |
422 | CS42L73_HLADVOL, CS42L73_HLBDVOL, 7, 0xffffffE5, | 419 | CS42L73_HLADVOL, CS42L73_HLBDVOL, |
423 | 0xE4, hl_tlv), | 420 | 0, 0x34, 0xE4, hl_tlv), |
424 | 421 | ||
425 | SOC_SINGLE_TLV("ADC A Boost Volume", | 422 | SOC_SINGLE_TLV("ADC A Boost Volume", |
426 | CS42L73_ADCIPC, 2, 0x01, 1, adc_boost_tlv), | 423 | CS42L73_ADCIPC, 2, 0x01, 1, adc_boost_tlv), |
427 | 424 | ||
428 | SOC_SINGLE_TLV("ADC B Boost Volume", | 425 | SOC_SINGLE_TLV("ADC B Boost Volume", |
429 | CS42L73_ADCIPC, 6, 0x01, 1, adc_boost_tlv), | 426 | CS42L73_ADCIPC, 6, 0x01, 1, adc_boost_tlv), |
430 | 427 | ||
431 | SOC_SINGLE_TLV("Speakerphone Digital Playback Volume", | 428 | SOC_SINGLE_SX_TLV("Speakerphone Digital Volume", |
432 | CS42L73_SPKDVOL, 0, 0xE4, 1, hl_tlv), | 429 | CS42L73_SPKDVOL, 0, 0x34, 0xE4, hl_tlv), |
433 | 430 | ||
434 | SOC_SINGLE_TLV("Ear Speaker Digital Playback Volume", | 431 | SOC_SINGLE_SX_TLV("Ear Speaker Digital Volume", |
435 | CS42L73_ESLDVOL, 0, 0xE4, 1, hl_tlv), | 432 | CS42L73_ESLDVOL, 0, 0x34, 0xE4, hl_tlv), |
436 | 433 | ||
437 | SOC_DOUBLE_R("Headphone Analog Playback Switch", CS42L73_HPAAVOL, | 434 | SOC_DOUBLE_R("Headphone Analog Playback Switch", CS42L73_HPAAVOL, |
438 | CS42L73_HPBAVOL, 7, 1, 1), | 435 | CS42L73_HPBAVOL, 7, 1, 1), |
@@ -599,17 +596,17 @@ static const struct snd_soc_dapm_widget cs42l73_dapm_widgets[] = { | |||
599 | SND_SOC_DAPM_INPUT("MIC2"), | 596 | SND_SOC_DAPM_INPUT("MIC2"), |
600 | SND_SOC_DAPM_SUPPLY("MIC2 Bias", CS42L73_PWRCTL2, 7, 1, NULL, 0), | 597 | SND_SOC_DAPM_SUPPLY("MIC2 Bias", CS42L73_PWRCTL2, 7, 1, NULL, 0), |
601 | 598 | ||
602 | SND_SOC_DAPM_AIF_OUT("XSPOUTL", "XSP Capture", 0, | 599 | SND_SOC_DAPM_AIF_OUT("XSPOUTL", NULL, 0, |
603 | CS42L73_PWRCTL2, 1, 1), | 600 | CS42L73_PWRCTL2, 1, 1), |
604 | SND_SOC_DAPM_AIF_OUT("XSPOUTR", "XSP Capture", 0, | 601 | SND_SOC_DAPM_AIF_OUT("XSPOUTR", NULL, 0, |
605 | CS42L73_PWRCTL2, 1, 1), | 602 | CS42L73_PWRCTL2, 1, 1), |
606 | SND_SOC_DAPM_AIF_OUT("ASPOUTL", "ASP Capture", 0, | 603 | SND_SOC_DAPM_AIF_OUT("ASPOUTL", NULL, 0, |
607 | CS42L73_PWRCTL2, 3, 1), | 604 | CS42L73_PWRCTL2, 3, 1), |
608 | SND_SOC_DAPM_AIF_OUT("ASPOUTR", "ASP Capture", 0, | 605 | SND_SOC_DAPM_AIF_OUT("ASPOUTR", NULL, 0, |
609 | CS42L73_PWRCTL2, 3, 1), | 606 | CS42L73_PWRCTL2, 3, 1), |
610 | SND_SOC_DAPM_AIF_OUT("VSPOUTL", "VSP Capture", 0, | 607 | SND_SOC_DAPM_AIF_OUT("VSPOUTL", NULL, 0, |
611 | CS42L73_PWRCTL2, 4, 1), | 608 | CS42L73_PWRCTL2, 4, 1), |
612 | SND_SOC_DAPM_AIF_OUT("VSPOUTR", "VSP Capture", 0, | 609 | SND_SOC_DAPM_AIF_OUT("VSPOUTR", NULL, 0, |
613 | CS42L73_PWRCTL2, 4, 1), | 610 | CS42L73_PWRCTL2, 4, 1), |
614 | 611 | ||
615 | SND_SOC_DAPM_PGA("PGA Left", SND_SOC_NOPM, 0, 0, NULL, 0), | 612 | SND_SOC_DAPM_PGA("PGA Left", SND_SOC_NOPM, 0, 0, NULL, 0), |
@@ -638,21 +635,21 @@ static const struct snd_soc_dapm_widget cs42l73_dapm_widgets[] = { | |||
638 | SND_SOC_DAPM_MIXER("VSPL Output Mixer", SND_SOC_NOPM, 0, 0, NULL, 0), | 635 | SND_SOC_DAPM_MIXER("VSPL Output Mixer", SND_SOC_NOPM, 0, 0, NULL, 0), |
639 | SND_SOC_DAPM_MIXER("VSPR Output Mixer", SND_SOC_NOPM, 0, 0, NULL, 0), | 636 | SND_SOC_DAPM_MIXER("VSPR Output Mixer", SND_SOC_NOPM, 0, 0, NULL, 0), |
640 | 637 | ||
641 | SND_SOC_DAPM_AIF_IN("XSPINL", "XSP Playback", 0, | 638 | SND_SOC_DAPM_AIF_IN("XSPINL", NULL, 0, |
642 | CS42L73_PWRCTL2, 0, 1), | 639 | CS42L73_PWRCTL2, 0, 1), |
643 | SND_SOC_DAPM_AIF_IN("XSPINR", "XSP Playback", 0, | 640 | SND_SOC_DAPM_AIF_IN("XSPINR", NULL, 0, |
644 | CS42L73_PWRCTL2, 0, 1), | 641 | CS42L73_PWRCTL2, 0, 1), |
645 | SND_SOC_DAPM_AIF_IN("XSPINM", "XSP Playback", 0, | 642 | SND_SOC_DAPM_AIF_IN("XSPINM", NULL, 0, |
646 | CS42L73_PWRCTL2, 0, 1), | 643 | CS42L73_PWRCTL2, 0, 1), |
647 | 644 | ||
648 | SND_SOC_DAPM_AIF_IN("ASPINL", "ASP Playback", 0, | 645 | SND_SOC_DAPM_AIF_IN("ASPINL", NULL, 0, |
649 | CS42L73_PWRCTL2, 2, 1), | 646 | CS42L73_PWRCTL2, 2, 1), |
650 | SND_SOC_DAPM_AIF_IN("ASPINR", "ASP Playback", 0, | 647 | SND_SOC_DAPM_AIF_IN("ASPINR", NULL, 0, |
651 | CS42L73_PWRCTL2, 2, 1), | 648 | CS42L73_PWRCTL2, 2, 1), |
652 | SND_SOC_DAPM_AIF_IN("ASPINM", "ASP Playback", 0, | 649 | SND_SOC_DAPM_AIF_IN("ASPINM", NULL, 0, |
653 | CS42L73_PWRCTL2, 2, 1), | 650 | CS42L73_PWRCTL2, 2, 1), |
654 | 651 | ||
655 | SND_SOC_DAPM_AIF_IN("VSPIN", "VSP Playback", 0, | 652 | SND_SOC_DAPM_AIF_IN("VSPIN", NULL, 0, |
656 | CS42L73_PWRCTL2, 4, 1), | 653 | CS42L73_PWRCTL2, 4, 1), |
657 | 654 | ||
658 | SND_SOC_DAPM_MIXER("HL Left Mixer", SND_SOC_NOPM, 0, 0, NULL, 0), | 655 | SND_SOC_DAPM_MIXER("HL Left Mixer", SND_SOC_NOPM, 0, 0, NULL, 0), |
@@ -776,6 +773,14 @@ static const struct snd_soc_dapm_route cs42l73_audio_map[] = { | |||
776 | {"HL Left Mixer", NULL, "VSPIN"}, | 773 | {"HL Left Mixer", NULL, "VSPIN"}, |
777 | {"HL Right Mixer", NULL, "VSPIN"}, | 774 | {"HL Right Mixer", NULL, "VSPIN"}, |
778 | 775 | ||
776 | {"ASPINL", NULL, "ASP Playback"}, | ||
777 | {"ASPINM", NULL, "ASP Playback"}, | ||
778 | {"ASPINR", NULL, "ASP Playback"}, | ||
779 | {"XSPINL", NULL, "XSP Playback"}, | ||
780 | {"XSPINM", NULL, "XSP Playback"}, | ||
781 | {"XSPINR", NULL, "XSP Playback"}, | ||
782 | {"VSPIN", NULL, "VSP Playback"}, | ||
783 | |||
779 | /* Capture Paths */ | 784 | /* Capture Paths */ |
780 | {"MIC1", NULL, "MIC1 Bias"}, | 785 | {"MIC1", NULL, "MIC1 Bias"}, |
781 | {"PGA Left Mux", "Mic 1", "MIC1"}, | 786 | {"PGA Left Mux", "Mic 1", "MIC1"}, |
@@ -822,6 +827,13 @@ static const struct snd_soc_dapm_route cs42l73_audio_map[] = { | |||
822 | 827 | ||
823 | {"VSPOUTL", NULL, "VSPL Output Mixer"}, | 828 | {"VSPOUTL", NULL, "VSPL Output Mixer"}, |
824 | {"VSPOUTR", NULL, "VSPR Output Mixer"}, | 829 | {"VSPOUTR", NULL, "VSPR Output Mixer"}, |
830 | |||
831 | {"ASP Capture", NULL, "ASPOUTL"}, | ||
832 | {"ASP Capture", NULL, "ASPOUTR"}, | ||
833 | {"XSP Capture", NULL, "XSPOUTL"}, | ||
834 | {"XSP Capture", NULL, "XSPOUTR"}, | ||
835 | {"VSP Capture", NULL, "VSPOUTL"}, | ||
836 | {"VSP Capture", NULL, "VSPOUTR"}, | ||
825 | }; | 837 | }; |
826 | 838 | ||
827 | struct cs42l73_mclk_div { | 839 | struct cs42l73_mclk_div { |
@@ -1091,8 +1103,7 @@ static int cs42l73_pcm_hw_params(struct snd_pcm_substream *substream, | |||
1091 | struct snd_pcm_hw_params *params, | 1103 | struct snd_pcm_hw_params *params, |
1092 | struct snd_soc_dai *dai) | 1104 | struct snd_soc_dai *dai) |
1093 | { | 1105 | { |
1094 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 1106 | struct snd_soc_codec *codec = dai->codec; |
1095 | struct snd_soc_codec *codec = rtd->codec; | ||
1096 | struct cs42l73_private *priv = snd_soc_codec_get_drvdata(codec); | 1107 | struct cs42l73_private *priv = snd_soc_codec_get_drvdata(codec); |
1097 | int id = dai->id; | 1108 | int id = dai->id; |
1098 | int mclk_coeff; | 1109 | int mclk_coeff; |
@@ -1429,25 +1440,7 @@ static struct i2c_driver cs42l73_i2c_driver = { | |||
1429 | 1440 | ||
1430 | }; | 1441 | }; |
1431 | 1442 | ||
1432 | static int __init cs42l73_modinit(void) | 1443 | module_i2c_driver(cs42l73_i2c_driver); |
1433 | { | ||
1434 | int ret; | ||
1435 | ret = i2c_add_driver(&cs42l73_i2c_driver); | ||
1436 | if (ret != 0) { | ||
1437 | pr_err("Failed to register CS42L73 I2C driver: %d\n", ret); | ||
1438 | return ret; | ||
1439 | } | ||
1440 | return 0; | ||
1441 | } | ||
1442 | |||
1443 | module_init(cs42l73_modinit); | ||
1444 | |||
1445 | static void __exit cs42l73_exit(void) | ||
1446 | { | ||
1447 | i2c_del_driver(&cs42l73_i2c_driver); | ||
1448 | } | ||
1449 | |||
1450 | module_exit(cs42l73_exit); | ||
1451 | 1444 | ||
1452 | MODULE_DESCRIPTION("ASoC CS42L73 driver"); | 1445 | MODULE_DESCRIPTION("ASoC CS42L73 driver"); |
1453 | MODULE_AUTHOR("Georgi Vlaev, Nucleus Systems Ltd, <joe@nucleusys.com>"); | 1446 | MODULE_AUTHOR("Georgi Vlaev, Nucleus Systems Ltd, <joe@nucleusys.com>"); |
diff --git a/sound/soc/codecs/da7210.c b/sound/soc/codecs/da7210.c index 7843711729bc..af5db7080519 100644 --- a/sound/soc/codecs/da7210.c +++ b/sound/soc/codecs/da7210.c | |||
@@ -17,6 +17,7 @@ | |||
17 | 17 | ||
18 | #include <linux/delay.h> | 18 | #include <linux/delay.h> |
19 | #include <linux/i2c.h> | 19 | #include <linux/i2c.h> |
20 | #include <linux/spi/spi.h> | ||
20 | #include <linux/regmap.h> | 21 | #include <linux/regmap.h> |
21 | #include <linux/slab.h> | 22 | #include <linux/slab.h> |
22 | #include <linux/module.h> | 23 | #include <linux/module.h> |
@@ -27,6 +28,7 @@ | |||
27 | #include <sound/tlv.h> | 28 | #include <sound/tlv.h> |
28 | 29 | ||
29 | /* DA7210 register space */ | 30 | /* DA7210 register space */ |
31 | #define DA7210_PAGE_CONTROL 0x00 | ||
30 | #define DA7210_CONTROL 0x01 | 32 | #define DA7210_CONTROL 0x01 |
31 | #define DA7210_STATUS 0x02 | 33 | #define DA7210_STATUS 0x02 |
32 | #define DA7210_STARTUP1 0x03 | 34 | #define DA7210_STARTUP1 0x03 |
@@ -146,6 +148,7 @@ | |||
146 | #define DA7210_DAI_EN (1 << 7) | 148 | #define DA7210_DAI_EN (1 << 7) |
147 | 149 | ||
148 | /*PLL_DIV3 bit fields */ | 150 | /*PLL_DIV3 bit fields */ |
151 | #define DA7210_PLL_DIV_L_MASK (0xF << 0) | ||
149 | #define DA7210_MCLK_RANGE_10_20_MHZ (1 << 4) | 152 | #define DA7210_MCLK_RANGE_10_20_MHZ (1 << 4) |
150 | #define DA7210_PLL_BYP (1 << 6) | 153 | #define DA7210_PLL_BYP (1 << 6) |
151 | 154 | ||
@@ -162,12 +165,16 @@ | |||
162 | #define DA7210_PLL_FS_48000 (0xB << 0) | 165 | #define DA7210_PLL_FS_48000 (0xB << 0) |
163 | #define DA7210_PLL_FS_88200 (0xE << 0) | 166 | #define DA7210_PLL_FS_88200 (0xE << 0) |
164 | #define DA7210_PLL_FS_96000 (0xF << 0) | 167 | #define DA7210_PLL_FS_96000 (0xF << 0) |
168 | #define DA7210_MCLK_DET_EN (0x1 << 5) | ||
169 | #define DA7210_MCLK_SRM_EN (0x1 << 6) | ||
165 | #define DA7210_PLL_EN (0x1 << 7) | 170 | #define DA7210_PLL_EN (0x1 << 7) |
166 | 171 | ||
167 | /* SOFTMUTE bit fields */ | 172 | /* SOFTMUTE bit fields */ |
168 | #define DA7210_RAMP_EN (1 << 6) | 173 | #define DA7210_RAMP_EN (1 << 6) |
169 | 174 | ||
170 | /* CONTROL bit fields */ | 175 | /* CONTROL bit fields */ |
176 | #define DA7210_REG_EN (1 << 0) | ||
177 | #define DA7210_BIAS_EN (1 << 2) | ||
171 | #define DA7210_NOISE_SUP_EN (1 << 3) | 178 | #define DA7210_NOISE_SUP_EN (1 << 3) |
172 | 179 | ||
173 | /* IN_GAIN bit fields */ | 180 | /* IN_GAIN bit fields */ |
@@ -206,6 +213,47 @@ | |||
206 | #define DA7210_OUT2_OUTMIX_L (1 << 6) | 213 | #define DA7210_OUT2_OUTMIX_L (1 << 6) |
207 | #define DA7210_OUT2_EN (1 << 7) | 214 | #define DA7210_OUT2_EN (1 << 7) |
208 | 215 | ||
216 | struct pll_div { | ||
217 | int fref; | ||
218 | int fout; | ||
219 | u8 div1; | ||
220 | u8 div2; | ||
221 | u8 div3; | ||
222 | u8 mode; /* 0 = slave, 1 = master */ | ||
223 | }; | ||
224 | |||
225 | /* PLL dividers table */ | ||
226 | static const struct pll_div da7210_pll_div[] = { | ||
227 | /* for MASTER mode, fs = 44.1Khz */ | ||
228 | { 12000000, 2822400, 0xE8, 0x6C, 0x2, 1}, /* MCLK=12Mhz */ | ||
229 | { 13000000, 2822400, 0xDF, 0x28, 0xC, 1}, /* MCLK=13Mhz */ | ||
230 | { 13500000, 2822400, 0xDB, 0x0A, 0xD, 1}, /* MCLK=13.5Mhz */ | ||
231 | { 14400000, 2822400, 0xD4, 0x5A, 0x2, 1}, /* MCLK=14.4Mhz */ | ||
232 | { 19200000, 2822400, 0xBB, 0x43, 0x9, 1}, /* MCLK=19.2Mhz */ | ||
233 | { 19680000, 2822400, 0xB9, 0x6D, 0xA, 1}, /* MCLK=19.68Mhz */ | ||
234 | { 19800000, 2822400, 0xB8, 0xFB, 0xB, 1}, /* MCLK=19.8Mhz */ | ||
235 | /* for MASTER mode, fs = 48Khz */ | ||
236 | { 12000000, 3072000, 0xF3, 0x12, 0x7, 1}, /* MCLK=12Mhz */ | ||
237 | { 13000000, 3072000, 0xE8, 0xFD, 0x5, 1}, /* MCLK=13Mhz */ | ||
238 | { 13500000, 3072000, 0xE4, 0x82, 0x3, 1}, /* MCLK=13.5Mhz */ | ||
239 | { 14400000, 3072000, 0xDD, 0x3A, 0x0, 1}, /* MCLK=14.4Mhz */ | ||
240 | { 19200000, 3072000, 0xC1, 0xEB, 0x8, 1}, /* MCLK=19.2Mhz */ | ||
241 | { 19680000, 3072000, 0xBF, 0xEC, 0x0, 1}, /* MCLK=19.68Mhz */ | ||
242 | { 19800000, 3072000, 0xBF, 0x70, 0x0, 1}, /* MCLK=19.8Mhz */ | ||
243 | /* for SLAVE mode with SRM */ | ||
244 | { 12000000, 2822400, 0xED, 0xBF, 0x5, 0}, /* MCLK=12Mhz */ | ||
245 | { 13000000, 2822400, 0xE4, 0x13, 0x0, 0}, /* MCLK=13Mhz */ | ||
246 | { 13500000, 2822400, 0xDF, 0xC6, 0x8, 0}, /* MCLK=13.5Mhz */ | ||
247 | { 14400000, 2822400, 0xD8, 0xCA, 0x1, 0}, /* MCLK=14.4Mhz */ | ||
248 | { 19200000, 2822400, 0xBE, 0x97, 0x9, 0}, /* MCLK=19.2Mhz */ | ||
249 | { 19680000, 2822400, 0xBC, 0xAC, 0xD, 0}, /* MCLK=19.68Mhz */ | ||
250 | { 19800000, 2822400, 0xBC, 0x35, 0xE, 0}, /* MCLK=19.8Mhz */ | ||
251 | }; | ||
252 | |||
253 | enum clk_src { | ||
254 | DA7210_CLKSRC_MCLK | ||
255 | }; | ||
256 | |||
209 | #define DA7210_VERSION "0.0.1" | 257 | #define DA7210_VERSION "0.0.1" |
210 | 258 | ||
211 | /* | 259 | /* |
@@ -628,9 +676,12 @@ static const struct snd_soc_dapm_route da7210_audio_map[] = { | |||
628 | /* Codec private data */ | 676 | /* Codec private data */ |
629 | struct da7210_priv { | 677 | struct da7210_priv { |
630 | struct regmap *regmap; | 678 | struct regmap *regmap; |
679 | unsigned int mclk_rate; | ||
680 | int master; | ||
631 | }; | 681 | }; |
632 | 682 | ||
633 | static struct reg_default da7210_reg_defaults[] = { | 683 | static struct reg_default da7210_reg_defaults[] = { |
684 | { 0x00, 0x00 }, | ||
634 | { 0x01, 0x11 }, | 685 | { 0x01, 0x11 }, |
635 | { 0x03, 0x00 }, | 686 | { 0x03, 0x00 }, |
636 | { 0x04, 0x00 }, | 687 | { 0x04, 0x00 }, |
@@ -713,10 +764,10 @@ static int da7210_hw_params(struct snd_pcm_substream *substream, | |||
713 | struct snd_pcm_hw_params *params, | 764 | struct snd_pcm_hw_params *params, |
714 | struct snd_soc_dai *dai) | 765 | struct snd_soc_dai *dai) |
715 | { | 766 | { |
716 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 767 | struct snd_soc_codec *codec = dai->codec; |
717 | struct snd_soc_codec *codec = rtd->codec; | 768 | struct da7210_priv *da7210 = snd_soc_codec_get_drvdata(codec); |
718 | u32 dai_cfg1; | 769 | u32 dai_cfg1; |
719 | u32 fs, bypass; | 770 | u32 fs, sysclk; |
720 | 771 | ||
721 | /* set DAI source to Left and Right ADC */ | 772 | /* set DAI source to Left and Right ADC */ |
722 | snd_soc_write(codec, DA7210_DAI_SRC_SEL, | 773 | snd_soc_write(codec, DA7210_DAI_SRC_SEL, |
@@ -749,43 +800,43 @@ static int da7210_hw_params(struct snd_pcm_substream *substream, | |||
749 | switch (params_rate(params)) { | 800 | switch (params_rate(params)) { |
750 | case 8000: | 801 | case 8000: |
751 | fs = DA7210_PLL_FS_8000; | 802 | fs = DA7210_PLL_FS_8000; |
752 | bypass = DA7210_PLL_BYP; | 803 | sysclk = 3072000; |
753 | break; | 804 | break; |
754 | case 11025: | 805 | case 11025: |
755 | fs = DA7210_PLL_FS_11025; | 806 | fs = DA7210_PLL_FS_11025; |
756 | bypass = 0; | 807 | sysclk = 2822400; |
757 | break; | 808 | break; |
758 | case 12000: | 809 | case 12000: |
759 | fs = DA7210_PLL_FS_12000; | 810 | fs = DA7210_PLL_FS_12000; |
760 | bypass = DA7210_PLL_BYP; | 811 | sysclk = 3072000; |
761 | break; | 812 | break; |
762 | case 16000: | 813 | case 16000: |
763 | fs = DA7210_PLL_FS_16000; | 814 | fs = DA7210_PLL_FS_16000; |
764 | bypass = DA7210_PLL_BYP; | 815 | sysclk = 3072000; |
765 | break; | 816 | break; |
766 | case 22050: | 817 | case 22050: |
767 | fs = DA7210_PLL_FS_22050; | 818 | fs = DA7210_PLL_FS_22050; |
768 | bypass = 0; | 819 | sysclk = 2822400; |
769 | break; | 820 | break; |
770 | case 32000: | 821 | case 32000: |
771 | fs = DA7210_PLL_FS_32000; | 822 | fs = DA7210_PLL_FS_32000; |
772 | bypass = DA7210_PLL_BYP; | 823 | sysclk = 3072000; |
773 | break; | 824 | break; |
774 | case 44100: | 825 | case 44100: |
775 | fs = DA7210_PLL_FS_44100; | 826 | fs = DA7210_PLL_FS_44100; |
776 | bypass = 0; | 827 | sysclk = 2822400; |
777 | break; | 828 | break; |
778 | case 48000: | 829 | case 48000: |
779 | fs = DA7210_PLL_FS_48000; | 830 | fs = DA7210_PLL_FS_48000; |
780 | bypass = DA7210_PLL_BYP; | 831 | sysclk = 3072000; |
781 | break; | 832 | break; |
782 | case 88200: | 833 | case 88200: |
783 | fs = DA7210_PLL_FS_88200; | 834 | fs = DA7210_PLL_FS_88200; |
784 | bypass = 0; | 835 | sysclk = 2822400; |
785 | break; | 836 | break; |
786 | case 96000: | 837 | case 96000: |
787 | fs = DA7210_PLL_FS_96000; | 838 | fs = DA7210_PLL_FS_96000; |
788 | bypass = DA7210_PLL_BYP; | 839 | sysclk = 3072000; |
789 | break; | 840 | break; |
790 | default: | 841 | default: |
791 | return -EINVAL; | 842 | return -EINVAL; |
@@ -795,8 +846,26 @@ static int da7210_hw_params(struct snd_pcm_substream *substream, | |||
795 | snd_soc_update_bits(codec, DA7210_STARTUP1, DA7210_SC_MST_EN, 0); | 846 | snd_soc_update_bits(codec, DA7210_STARTUP1, DA7210_SC_MST_EN, 0); |
796 | 847 | ||
797 | snd_soc_update_bits(codec, DA7210_PLL, DA7210_PLL_FS_MASK, fs); | 848 | snd_soc_update_bits(codec, DA7210_PLL, DA7210_PLL_FS_MASK, fs); |
798 | snd_soc_update_bits(codec, DA7210_PLL_DIV3, DA7210_PLL_BYP, bypass); | ||
799 | 849 | ||
850 | if (da7210->mclk_rate && (da7210->mclk_rate != sysclk)) { | ||
851 | /* PLL mode, disable PLL bypass */ | ||
852 | snd_soc_update_bits(codec, DA7210_PLL_DIV3, DA7210_PLL_BYP, 0); | ||
853 | |||
854 | if (!da7210->master) { | ||
855 | /* PLL slave mode, also enable SRM */ | ||
856 | snd_soc_update_bits(codec, DA7210_PLL, | ||
857 | (DA7210_MCLK_SRM_EN | | ||
858 | DA7210_MCLK_DET_EN), | ||
859 | (DA7210_MCLK_SRM_EN | | ||
860 | DA7210_MCLK_DET_EN)); | ||
861 | } | ||
862 | } else { | ||
863 | /* PLL bypass mode, enable PLL bypass and Auto Detection */ | ||
864 | snd_soc_update_bits(codec, DA7210_PLL, DA7210_MCLK_DET_EN, | ||
865 | DA7210_MCLK_DET_EN); | ||
866 | snd_soc_update_bits(codec, DA7210_PLL_DIV3, DA7210_PLL_BYP, | ||
867 | DA7210_PLL_BYP); | ||
868 | } | ||
800 | /* Enable active mode */ | 869 | /* Enable active mode */ |
801 | snd_soc_update_bits(codec, DA7210_STARTUP1, | 870 | snd_soc_update_bits(codec, DA7210_STARTUP1, |
802 | DA7210_SC_MST_EN, DA7210_SC_MST_EN); | 871 | DA7210_SC_MST_EN, DA7210_SC_MST_EN); |
@@ -810,17 +879,24 @@ static int da7210_hw_params(struct snd_pcm_substream *substream, | |||
810 | static int da7210_set_dai_fmt(struct snd_soc_dai *codec_dai, u32 fmt) | 879 | static int da7210_set_dai_fmt(struct snd_soc_dai *codec_dai, u32 fmt) |
811 | { | 880 | { |
812 | struct snd_soc_codec *codec = codec_dai->codec; | 881 | struct snd_soc_codec *codec = codec_dai->codec; |
882 | struct da7210_priv *da7210 = snd_soc_codec_get_drvdata(codec); | ||
813 | u32 dai_cfg1; | 883 | u32 dai_cfg1; |
814 | u32 dai_cfg3; | 884 | u32 dai_cfg3; |
815 | 885 | ||
816 | dai_cfg1 = 0x7f & snd_soc_read(codec, DA7210_DAI_CFG1); | 886 | dai_cfg1 = 0x7f & snd_soc_read(codec, DA7210_DAI_CFG1); |
817 | dai_cfg3 = 0xfc & snd_soc_read(codec, DA7210_DAI_CFG3); | 887 | dai_cfg3 = 0xfc & snd_soc_read(codec, DA7210_DAI_CFG3); |
818 | 888 | ||
889 | if ((snd_soc_read(codec, DA7210_PLL) & DA7210_PLL_EN) && | ||
890 | (!(snd_soc_read(codec, DA7210_PLL_DIV3) & DA7210_PLL_BYP))) | ||
891 | return -EINVAL; | ||
892 | |||
819 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { | 893 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
820 | case SND_SOC_DAIFMT_CBM_CFM: | 894 | case SND_SOC_DAIFMT_CBM_CFM: |
895 | da7210->master = 1; | ||
821 | dai_cfg1 |= DA7210_DAI_MODE_MASTER; | 896 | dai_cfg1 |= DA7210_DAI_MODE_MASTER; |
822 | break; | 897 | break; |
823 | case SND_SOC_DAIFMT_CBS_CFS: | 898 | case SND_SOC_DAIFMT_CBS_CFS: |
899 | da7210->master = 0; | ||
824 | dai_cfg1 |= DA7210_DAI_MODE_SLAVE; | 900 | dai_cfg1 |= DA7210_DAI_MODE_SLAVE; |
825 | break; | 901 | break; |
826 | default: | 902 | default: |
@@ -872,10 +948,101 @@ static int da7210_mute(struct snd_soc_dai *dai, int mute) | |||
872 | #define DA7210_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ | 948 | #define DA7210_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ |
873 | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE) | 949 | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE) |
874 | 950 | ||
951 | static int da7210_set_dai_sysclk(struct snd_soc_dai *codec_dai, | ||
952 | int clk_id, unsigned int freq, int dir) | ||
953 | { | ||
954 | struct snd_soc_codec *codec = codec_dai->codec; | ||
955 | struct da7210_priv *da7210 = snd_soc_codec_get_drvdata(codec); | ||
956 | |||
957 | switch (clk_id) { | ||
958 | case DA7210_CLKSRC_MCLK: | ||
959 | switch (freq) { | ||
960 | case 12000000: | ||
961 | case 13000000: | ||
962 | case 13500000: | ||
963 | case 14400000: | ||
964 | case 19200000: | ||
965 | case 19680000: | ||
966 | case 19800000: | ||
967 | da7210->mclk_rate = freq; | ||
968 | return 0; | ||
969 | default: | ||
970 | dev_err(codec_dai->dev, "Unsupported MCLK value %d\n", | ||
971 | freq); | ||
972 | return -EINVAL; | ||
973 | } | ||
974 | break; | ||
975 | default: | ||
976 | dev_err(codec_dai->dev, "Unknown clock source %d\n", clk_id); | ||
977 | return -EINVAL; | ||
978 | } | ||
979 | } | ||
980 | |||
981 | /** | ||
982 | * da7210_set_dai_pll :Configure the codec PLL | ||
983 | * @param codec_dai : pointer to codec DAI | ||
984 | * @param pll_id : da7210 has only one pll, so pll_id is always zero | ||
985 | * @param fref : MCLK frequency, should be < 20MHz | ||
986 | * @param fout : FsDM value, Refer page 44 & 45 of datasheet | ||
987 | * @return int : Zero for success, negative error code for error | ||
988 | * | ||
989 | * Note: Supported PLL input frequencies are 12MHz, 13MHz, 13.5MHz, 14.4MHz, | ||
990 | * 19.2MHz, 19.6MHz and 19.8MHz | ||
991 | */ | ||
992 | static int da7210_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id, | ||
993 | int source, unsigned int fref, unsigned int fout) | ||
994 | { | ||
995 | struct snd_soc_codec *codec = codec_dai->codec; | ||
996 | struct da7210_priv *da7210 = snd_soc_codec_get_drvdata(codec); | ||
997 | |||
998 | u8 pll_div1, pll_div2, pll_div3, cnt; | ||
999 | |||
1000 | /* In slave mode, there is only one set of divisors */ | ||
1001 | if (!da7210->master) | ||
1002 | fout = 2822400; | ||
1003 | |||
1004 | /* Search pll div array for correct divisors */ | ||
1005 | for (cnt = 0; cnt < ARRAY_SIZE(da7210_pll_div); cnt++) { | ||
1006 | /* check fref, mode and fout */ | ||
1007 | if ((fref == da7210_pll_div[cnt].fref) && | ||
1008 | (da7210->master == da7210_pll_div[cnt].mode) && | ||
1009 | (fout == da7210_pll_div[cnt].fout)) { | ||
1010 | /* all match, pick up divisors */ | ||
1011 | pll_div1 = da7210_pll_div[cnt].div1; | ||
1012 | pll_div2 = da7210_pll_div[cnt].div2; | ||
1013 | pll_div3 = da7210_pll_div[cnt].div3; | ||
1014 | break; | ||
1015 | } | ||
1016 | } | ||
1017 | if (cnt >= ARRAY_SIZE(da7210_pll_div)) | ||
1018 | goto err; | ||
1019 | |||
1020 | /* Disable active mode */ | ||
1021 | snd_soc_update_bits(codec, DA7210_STARTUP1, DA7210_SC_MST_EN, 0); | ||
1022 | /* Write PLL dividers */ | ||
1023 | snd_soc_write(codec, DA7210_PLL_DIV1, pll_div1); | ||
1024 | snd_soc_write(codec, DA7210_PLL_DIV2, pll_div2); | ||
1025 | snd_soc_update_bits(codec, DA7210_PLL_DIV3, | ||
1026 | DA7210_PLL_DIV_L_MASK, pll_div3); | ||
1027 | |||
1028 | /* Enable PLL */ | ||
1029 | snd_soc_update_bits(codec, DA7210_PLL, DA7210_PLL_EN, DA7210_PLL_EN); | ||
1030 | |||
1031 | /* Enable active mode */ | ||
1032 | snd_soc_update_bits(codec, DA7210_STARTUP1, DA7210_SC_MST_EN, | ||
1033 | DA7210_SC_MST_EN); | ||
1034 | return 0; | ||
1035 | err: | ||
1036 | dev_err(codec_dai->dev, "Unsupported PLL input frequency %d\n", fref); | ||
1037 | return -EINVAL; | ||
1038 | } | ||
1039 | |||
875 | /* DAI operations */ | 1040 | /* DAI operations */ |
876 | static const struct snd_soc_dai_ops da7210_dai_ops = { | 1041 | static const struct snd_soc_dai_ops da7210_dai_ops = { |
877 | .hw_params = da7210_hw_params, | 1042 | .hw_params = da7210_hw_params, |
878 | .set_fmt = da7210_set_dai_fmt, | 1043 | .set_fmt = da7210_set_dai_fmt, |
1044 | .set_sysclk = da7210_set_dai_sysclk, | ||
1045 | .set_pll = da7210_set_dai_pll, | ||
879 | .digital_mute = da7210_mute, | 1046 | .digital_mute = da7210_mute, |
880 | }; | 1047 | }; |
881 | 1048 | ||
@@ -915,24 +1082,11 @@ static int da7210_probe(struct snd_soc_codec *codec) | |||
915 | return ret; | 1082 | return ret; |
916 | } | 1083 | } |
917 | 1084 | ||
918 | /* FIXME | 1085 | da7210->mclk_rate = 0; /* This will be set from set_sysclk() */ |
919 | * | 1086 | da7210->master = 0; /* This will be set from set_fmt() */ |
920 | * This driver use fixed value here | ||
921 | * And below settings expects MCLK = 12.288MHz | ||
922 | * | ||
923 | * When you select different MCLK, please check... | ||
924 | * DA7210_PLL_DIV1 val | ||
925 | * DA7210_PLL_DIV2 val | ||
926 | * DA7210_PLL_DIV3 val | ||
927 | * DA7210_PLL_DIV3 :: DA7210_MCLK_RANGExxx | ||
928 | */ | ||
929 | 1087 | ||
930 | /* | 1088 | /* Enable internal regulator & bias current */ |
931 | * make sure that DA7210 use bypass mode before start up | 1089 | snd_soc_write(codec, DA7210_CONTROL, DA7210_REG_EN | DA7210_BIAS_EN); |
932 | */ | ||
933 | snd_soc_write(codec, DA7210_STARTUP1, 0); | ||
934 | snd_soc_write(codec, DA7210_PLL_DIV3, | ||
935 | DA7210_MCLK_RANGE_10_20_MHZ | DA7210_PLL_BYP); | ||
936 | 1090 | ||
937 | /* | 1091 | /* |
938 | * ADC settings | 1092 | * ADC settings |
@@ -1007,34 +1161,13 @@ static int da7210_probe(struct snd_soc_codec *codec) | |||
1007 | /* Enable Aux2 */ | 1161 | /* Enable Aux2 */ |
1008 | snd_soc_write(codec, DA7210_AUX2, DA7210_AUX2_EN); | 1162 | snd_soc_write(codec, DA7210_AUX2, DA7210_AUX2_EN); |
1009 | 1163 | ||
1164 | /* Set PLL Master clock range 10-20 MHz, enable PLL bypass */ | ||
1165 | snd_soc_write(codec, DA7210_PLL_DIV3, DA7210_MCLK_RANGE_10_20_MHZ | | ||
1166 | DA7210_PLL_BYP); | ||
1167 | |||
1010 | /* Diable PLL and bypass it */ | 1168 | /* Diable PLL and bypass it */ |
1011 | snd_soc_write(codec, DA7210_PLL, DA7210_PLL_FS_48000); | 1169 | snd_soc_write(codec, DA7210_PLL, DA7210_PLL_FS_48000); |
1012 | 1170 | ||
1013 | /* | ||
1014 | * If 48kHz sound came, it use bypass mode, | ||
1015 | * and when it is 44.1kHz, it use PLL. | ||
1016 | * | ||
1017 | * This time, this driver sets PLL always ON | ||
1018 | * and controls bypass/PLL mode by switching | ||
1019 | * DA7210_PLL_DIV3 :: DA7210_PLL_BYP bit. | ||
1020 | * see da7210_hw_params | ||
1021 | */ | ||
1022 | snd_soc_write(codec, DA7210_PLL_DIV1, 0xE5); /* MCLK = 12.288MHz */ | ||
1023 | snd_soc_write(codec, DA7210_PLL_DIV2, 0x99); | ||
1024 | snd_soc_write(codec, DA7210_PLL_DIV3, 0x0A | | ||
1025 | DA7210_MCLK_RANGE_10_20_MHZ | DA7210_PLL_BYP); | ||
1026 | snd_soc_update_bits(codec, DA7210_PLL, DA7210_PLL_EN, DA7210_PLL_EN); | ||
1027 | |||
1028 | /* As suggested by Dialog */ | ||
1029 | /* unlock */ | ||
1030 | regmap_write(da7210->regmap, DA7210_A_HID_UNLOCK, 0x8B); | ||
1031 | regmap_write(da7210->regmap, DA7210_A_TEST_UNLOCK, 0xB4); | ||
1032 | regmap_write(da7210->regmap, DA7210_A_PLL1, 0x01); | ||
1033 | regmap_write(da7210->regmap, DA7210_A_CP_MODE, 0x7C); | ||
1034 | /* re-lock */ | ||
1035 | regmap_write(da7210->regmap, DA7210_A_HID_UNLOCK, 0x00); | ||
1036 | regmap_write(da7210->regmap, DA7210_A_TEST_UNLOCK, 0x00); | ||
1037 | |||
1038 | /* Activate all enabled subsystem */ | 1171 | /* Activate all enabled subsystem */ |
1039 | snd_soc_write(codec, DA7210_STARTUP1, DA7210_SC_MST_EN); | 1172 | snd_soc_write(codec, DA7210_STARTUP1, DA7210_SC_MST_EN); |
1040 | 1173 | ||
@@ -1055,7 +1188,26 @@ static struct snd_soc_codec_driver soc_codec_dev_da7210 = { | |||
1055 | .num_dapm_routes = ARRAY_SIZE(da7210_audio_map), | 1188 | .num_dapm_routes = ARRAY_SIZE(da7210_audio_map), |
1056 | }; | 1189 | }; |
1057 | 1190 | ||
1058 | static struct regmap_config da7210_regmap = { | 1191 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) |
1192 | |||
1193 | static struct reg_default da7210_regmap_i2c_patch[] = { | ||
1194 | |||
1195 | /* System controller master disable */ | ||
1196 | { DA7210_STARTUP1, 0x00 }, | ||
1197 | /* Set PLL Master clock range 10-20 MHz */ | ||
1198 | { DA7210_PLL_DIV3, DA7210_MCLK_RANGE_10_20_MHZ }, | ||
1199 | |||
1200 | /* to unlock */ | ||
1201 | { DA7210_A_HID_UNLOCK, 0x8B}, | ||
1202 | { DA7210_A_TEST_UNLOCK, 0xB4}, | ||
1203 | { DA7210_A_PLL1, 0x01}, | ||
1204 | { DA7210_A_CP_MODE, 0x7C}, | ||
1205 | /* to re-lock */ | ||
1206 | { DA7210_A_HID_UNLOCK, 0x00}, | ||
1207 | { DA7210_A_TEST_UNLOCK, 0x00}, | ||
1208 | }; | ||
1209 | |||
1210 | static const struct regmap_config da7210_regmap_config_i2c = { | ||
1059 | .reg_bits = 8, | 1211 | .reg_bits = 8, |
1060 | .val_bits = 8, | 1212 | .val_bits = 8, |
1061 | 1213 | ||
@@ -1066,7 +1218,6 @@ static struct regmap_config da7210_regmap = { | |||
1066 | .cache_type = REGCACHE_RBTREE, | 1218 | .cache_type = REGCACHE_RBTREE, |
1067 | }; | 1219 | }; |
1068 | 1220 | ||
1069 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) | ||
1070 | static int __devinit da7210_i2c_probe(struct i2c_client *i2c, | 1221 | static int __devinit da7210_i2c_probe(struct i2c_client *i2c, |
1071 | const struct i2c_device_id *id) | 1222 | const struct i2c_device_id *id) |
1072 | { | 1223 | { |
@@ -1080,13 +1231,18 @@ static int __devinit da7210_i2c_probe(struct i2c_client *i2c, | |||
1080 | 1231 | ||
1081 | i2c_set_clientdata(i2c, da7210); | 1232 | i2c_set_clientdata(i2c, da7210); |
1082 | 1233 | ||
1083 | da7210->regmap = regmap_init_i2c(i2c, &da7210_regmap); | 1234 | da7210->regmap = regmap_init_i2c(i2c, &da7210_regmap_config_i2c); |
1084 | if (IS_ERR(da7210->regmap)) { | 1235 | if (IS_ERR(da7210->regmap)) { |
1085 | ret = PTR_ERR(da7210->regmap); | 1236 | ret = PTR_ERR(da7210->regmap); |
1086 | dev_err(&i2c->dev, "regmap_init() failed: %d\n", ret); | 1237 | dev_err(&i2c->dev, "regmap_init() failed: %d\n", ret); |
1087 | return ret; | 1238 | return ret; |
1088 | } | 1239 | } |
1089 | 1240 | ||
1241 | ret = regmap_register_patch(da7210->regmap, da7210_regmap_i2c_patch, | ||
1242 | ARRAY_SIZE(da7210_regmap_i2c_patch)); | ||
1243 | if (ret != 0) | ||
1244 | dev_warn(&i2c->dev, "Failed to apply regmap patch: %d\n", ret); | ||
1245 | |||
1090 | ret = snd_soc_register_codec(&i2c->dev, | 1246 | ret = snd_soc_register_codec(&i2c->dev, |
1091 | &soc_codec_dev_da7210, &da7210_dai, 1); | 1247 | &soc_codec_dev_da7210, &da7210_dai, 1); |
1092 | if (ret < 0) { | 1248 | if (ret < 0) { |
@@ -1119,7 +1275,7 @@ MODULE_DEVICE_TABLE(i2c, da7210_i2c_id); | |||
1119 | /* I2C codec control layer */ | 1275 | /* I2C codec control layer */ |
1120 | static struct i2c_driver da7210_i2c_driver = { | 1276 | static struct i2c_driver da7210_i2c_driver = { |
1121 | .driver = { | 1277 | .driver = { |
1122 | .name = "da7210-codec", | 1278 | .name = "da7210", |
1123 | .owner = THIS_MODULE, | 1279 | .owner = THIS_MODULE, |
1124 | }, | 1280 | }, |
1125 | .probe = da7210_i2c_probe, | 1281 | .probe = da7210_i2c_probe, |
@@ -1128,12 +1284,112 @@ static struct i2c_driver da7210_i2c_driver = { | |||
1128 | }; | 1284 | }; |
1129 | #endif | 1285 | #endif |
1130 | 1286 | ||
1287 | #if defined(CONFIG_SPI_MASTER) | ||
1288 | |||
1289 | static struct reg_default da7210_regmap_spi_patch[] = { | ||
1290 | /* Dummy read to give two pulses over nCS for SPI */ | ||
1291 | { DA7210_AUX2, 0x00 }, | ||
1292 | { DA7210_AUX2, 0x00 }, | ||
1293 | |||
1294 | /* System controller master disable */ | ||
1295 | { DA7210_STARTUP1, 0x00 }, | ||
1296 | /* Set PLL Master clock range 10-20 MHz */ | ||
1297 | { DA7210_PLL_DIV3, DA7210_MCLK_RANGE_10_20_MHZ }, | ||
1298 | |||
1299 | /* to set PAGE1 of SPI register space */ | ||
1300 | { DA7210_PAGE_CONTROL, 0x80 }, | ||
1301 | /* to unlock */ | ||
1302 | { DA7210_A_HID_UNLOCK, 0x8B}, | ||
1303 | { DA7210_A_TEST_UNLOCK, 0xB4}, | ||
1304 | { DA7210_A_PLL1, 0x01}, | ||
1305 | { DA7210_A_CP_MODE, 0x7C}, | ||
1306 | /* to re-lock */ | ||
1307 | { DA7210_A_HID_UNLOCK, 0x00}, | ||
1308 | { DA7210_A_TEST_UNLOCK, 0x00}, | ||
1309 | /* to set back PAGE0 of SPI register space */ | ||
1310 | { DA7210_PAGE_CONTROL, 0x00 }, | ||
1311 | }; | ||
1312 | |||
1313 | static const struct regmap_config da7210_regmap_config_spi = { | ||
1314 | .reg_bits = 8, | ||
1315 | .val_bits = 8, | ||
1316 | .read_flag_mask = 0x01, | ||
1317 | .write_flag_mask = 0x00, | ||
1318 | |||
1319 | .reg_defaults = da7210_reg_defaults, | ||
1320 | .num_reg_defaults = ARRAY_SIZE(da7210_reg_defaults), | ||
1321 | .volatile_reg = da7210_volatile_register, | ||
1322 | .readable_reg = da7210_readable_register, | ||
1323 | .cache_type = REGCACHE_RBTREE, | ||
1324 | }; | ||
1325 | |||
1326 | static int __devinit da7210_spi_probe(struct spi_device *spi) | ||
1327 | { | ||
1328 | struct da7210_priv *da7210; | ||
1329 | int ret; | ||
1330 | |||
1331 | da7210 = devm_kzalloc(&spi->dev, sizeof(struct da7210_priv), | ||
1332 | GFP_KERNEL); | ||
1333 | if (!da7210) | ||
1334 | return -ENOMEM; | ||
1335 | |||
1336 | spi_set_drvdata(spi, da7210); | ||
1337 | da7210->regmap = devm_regmap_init_spi(spi, &da7210_regmap_config_spi); | ||
1338 | if (IS_ERR(da7210->regmap)) { | ||
1339 | ret = PTR_ERR(da7210->regmap); | ||
1340 | dev_err(&spi->dev, "Failed to register regmap: %d\n", ret); | ||
1341 | return ret; | ||
1342 | } | ||
1343 | |||
1344 | ret = regmap_register_patch(da7210->regmap, da7210_regmap_spi_patch, | ||
1345 | ARRAY_SIZE(da7210_regmap_spi_patch)); | ||
1346 | if (ret != 0) | ||
1347 | dev_warn(&spi->dev, "Failed to apply regmap patch: %d\n", ret); | ||
1348 | |||
1349 | ret = snd_soc_register_codec(&spi->dev, | ||
1350 | &soc_codec_dev_da7210, &da7210_dai, 1); | ||
1351 | if (ret < 0) | ||
1352 | goto err_regmap; | ||
1353 | |||
1354 | return ret; | ||
1355 | |||
1356 | err_regmap: | ||
1357 | regmap_exit(da7210->regmap); | ||
1358 | |||
1359 | return ret; | ||
1360 | } | ||
1361 | |||
1362 | static int __devexit da7210_spi_remove(struct spi_device *spi) | ||
1363 | { | ||
1364 | struct da7210_priv *da7210 = spi_get_drvdata(spi); | ||
1365 | snd_soc_unregister_codec(&spi->dev); | ||
1366 | regmap_exit(da7210->regmap); | ||
1367 | return 0; | ||
1368 | } | ||
1369 | |||
1370 | static struct spi_driver da7210_spi_driver = { | ||
1371 | .driver = { | ||
1372 | .name = "da7210", | ||
1373 | .owner = THIS_MODULE, | ||
1374 | }, | ||
1375 | .probe = da7210_spi_probe, | ||
1376 | .remove = __devexit_p(da7210_spi_remove) | ||
1377 | }; | ||
1378 | #endif | ||
1379 | |||
1131 | static int __init da7210_modinit(void) | 1380 | static int __init da7210_modinit(void) |
1132 | { | 1381 | { |
1133 | int ret = 0; | 1382 | int ret = 0; |
1134 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) | 1383 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) |
1135 | ret = i2c_add_driver(&da7210_i2c_driver); | 1384 | ret = i2c_add_driver(&da7210_i2c_driver); |
1136 | #endif | 1385 | #endif |
1386 | #if defined(CONFIG_SPI_MASTER) | ||
1387 | ret = spi_register_driver(&da7210_spi_driver); | ||
1388 | if (ret) { | ||
1389 | printk(KERN_ERR "Failed to register da7210 SPI driver: %d\n", | ||
1390 | ret); | ||
1391 | } | ||
1392 | #endif | ||
1137 | return ret; | 1393 | return ret; |
1138 | } | 1394 | } |
1139 | module_init(da7210_modinit); | 1395 | module_init(da7210_modinit); |
@@ -1143,6 +1399,9 @@ static void __exit da7210_exit(void) | |||
1143 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) | 1399 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) |
1144 | i2c_del_driver(&da7210_i2c_driver); | 1400 | i2c_del_driver(&da7210_i2c_driver); |
1145 | #endif | 1401 | #endif |
1402 | #if defined(CONFIG_SPI_MASTER) | ||
1403 | spi_unregister_driver(&da7210_spi_driver); | ||
1404 | #endif | ||
1146 | } | 1405 | } |
1147 | module_exit(da7210_exit); | 1406 | module_exit(da7210_exit); |
1148 | 1407 | ||
diff --git a/sound/soc/codecs/jz4740.c b/sound/soc/codecs/jz4740.c index 4624e752a188..85d9cabe6d55 100644 --- a/sound/soc/codecs/jz4740.c +++ b/sound/soc/codecs/jz4740.c | |||
@@ -164,8 +164,7 @@ static int jz4740_codec_hw_params(struct snd_pcm_substream *substream, | |||
164 | struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) | 164 | struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) |
165 | { | 165 | { |
166 | uint32_t val; | 166 | uint32_t val; |
167 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 167 | struct snd_soc_codec *codec = dai->codec; |
168 | struct snd_soc_codec *codec =rtd->codec; | ||
169 | 168 | ||
170 | switch (params_rate(params)) { | 169 | switch (params_rate(params)) { |
171 | case 8000: | 170 | case 8000: |
diff --git a/sound/soc/codecs/lm49453.c b/sound/soc/codecs/lm49453.c new file mode 100644 index 000000000000..802b9f176b16 --- /dev/null +++ b/sound/soc/codecs/lm49453.c | |||
@@ -0,0 +1,1550 @@ | |||
1 | /* | ||
2 | * lm49453.c - LM49453 ALSA Soc Audio driver | ||
3 | * | ||
4 | * Copyright (c) 2012 Texas Instruments, Inc | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; version 2 of the License. | ||
9 | * | ||
10 | * Initially based on sound/soc/codecs/wm8350.c | ||
11 | */ | ||
12 | |||
13 | #include <linux/module.h> | ||
14 | #include <linux/moduleparam.h> | ||
15 | #include <linux/version.h> | ||
16 | #include <linux/kernel.h> | ||
17 | #include <linux/init.h> | ||
18 | #include <linux/delay.h> | ||
19 | #include <linux/pm.h> | ||
20 | #include <linux/i2c.h> | ||
21 | #include <linux/regmap.h> | ||
22 | #include <linux/slab.h> | ||
23 | #include <sound/core.h> | ||
24 | #include <sound/pcm.h> | ||
25 | #include <sound/pcm_params.h> | ||
26 | #include <sound/soc.h> | ||
27 | #include <sound/soc-dapm.h> | ||
28 | #include <sound/tlv.h> | ||
29 | #include <sound/jack.h> | ||
30 | #include <sound/initval.h> | ||
31 | #include <asm/div64.h> | ||
32 | #include "lm49453.h" | ||
33 | |||
34 | static struct reg_default lm49453_reg_defs[] = { | ||
35 | { 0, 0x00 }, | ||
36 | { 1, 0x00 }, | ||
37 | { 2, 0x00 }, | ||
38 | { 3, 0x00 }, | ||
39 | { 4, 0x00 }, | ||
40 | { 5, 0x00 }, | ||
41 | { 6, 0x00 }, | ||
42 | { 7, 0x00 }, | ||
43 | { 8, 0x00 }, | ||
44 | { 9, 0x00 }, | ||
45 | { 10, 0x00 }, | ||
46 | { 11, 0x00 }, | ||
47 | { 12, 0x00 }, | ||
48 | { 13, 0x00 }, | ||
49 | { 14, 0x00 }, | ||
50 | { 15, 0x00 }, | ||
51 | { 16, 0x00 }, | ||
52 | { 17, 0x00 }, | ||
53 | { 18, 0x00 }, | ||
54 | { 19, 0x00 }, | ||
55 | { 20, 0x00 }, | ||
56 | { 21, 0x00 }, | ||
57 | { 22, 0x00 }, | ||
58 | { 23, 0x00 }, | ||
59 | { 32, 0x00 }, | ||
60 | { 33, 0x00 }, | ||
61 | { 35, 0x00 }, | ||
62 | { 36, 0x00 }, | ||
63 | { 37, 0x00 }, | ||
64 | { 46, 0x00 }, | ||
65 | { 48, 0x00 }, | ||
66 | { 49, 0x00 }, | ||
67 | { 51, 0x00 }, | ||
68 | { 56, 0x00 }, | ||
69 | { 58, 0x00 }, | ||
70 | { 59, 0x00 }, | ||
71 | { 60, 0x00 }, | ||
72 | { 61, 0x00 }, | ||
73 | { 62, 0x00 }, | ||
74 | { 63, 0x00 }, | ||
75 | { 64, 0x00 }, | ||
76 | { 65, 0x00 }, | ||
77 | { 66, 0x00 }, | ||
78 | { 67, 0x00 }, | ||
79 | { 68, 0x00 }, | ||
80 | { 69, 0x00 }, | ||
81 | { 70, 0x00 }, | ||
82 | { 71, 0x00 }, | ||
83 | { 72, 0x00 }, | ||
84 | { 73, 0x00 }, | ||
85 | { 74, 0x00 }, | ||
86 | { 75, 0x00 }, | ||
87 | { 76, 0x00 }, | ||
88 | { 77, 0x00 }, | ||
89 | { 78, 0x00 }, | ||
90 | { 79, 0x00 }, | ||
91 | { 80, 0x00 }, | ||
92 | { 81, 0x00 }, | ||
93 | { 82, 0x00 }, | ||
94 | { 83, 0x00 }, | ||
95 | { 85, 0x00 }, | ||
96 | { 85, 0x00 }, | ||
97 | { 86, 0x00 }, | ||
98 | { 87, 0x00 }, | ||
99 | { 88, 0x00 }, | ||
100 | { 89, 0x00 }, | ||
101 | { 90, 0x00 }, | ||
102 | { 91, 0x00 }, | ||
103 | { 92, 0x00 }, | ||
104 | { 93, 0x00 }, | ||
105 | { 94, 0x00 }, | ||
106 | { 95, 0x00 }, | ||
107 | { 96, 0x01 }, | ||
108 | { 97, 0x00 }, | ||
109 | { 98, 0x00 }, | ||
110 | { 99, 0x00 }, | ||
111 | { 100, 0x00 }, | ||
112 | { 101, 0x00 }, | ||
113 | { 102, 0x00 }, | ||
114 | { 103, 0x01 }, | ||
115 | { 105, 0x01 }, | ||
116 | { 106, 0x00 }, | ||
117 | { 107, 0x01 }, | ||
118 | { 107, 0x00 }, | ||
119 | { 108, 0x00 }, | ||
120 | { 109, 0x00 }, | ||
121 | { 110, 0x00 }, | ||
122 | { 111, 0x02 }, | ||
123 | { 112, 0x02 }, | ||
124 | { 113, 0x00 }, | ||
125 | { 121, 0x80 }, | ||
126 | { 122, 0xBB }, | ||
127 | { 123, 0x80 }, | ||
128 | { 124, 0xBB }, | ||
129 | { 128, 0x00 }, | ||
130 | { 130, 0x00 }, | ||
131 | { 131, 0x00 }, | ||
132 | { 132, 0x00 }, | ||
133 | { 133, 0x0A }, | ||
134 | { 134, 0x0A }, | ||
135 | { 135, 0x0A }, | ||
136 | { 136, 0x0F }, | ||
137 | { 137, 0x00 }, | ||
138 | { 138, 0x73 }, | ||
139 | { 139, 0x33 }, | ||
140 | { 140, 0x73 }, | ||
141 | { 141, 0x33 }, | ||
142 | { 142, 0x73 }, | ||
143 | { 143, 0x33 }, | ||
144 | { 144, 0x73 }, | ||
145 | { 145, 0x33 }, | ||
146 | { 146, 0x73 }, | ||
147 | { 147, 0x33 }, | ||
148 | { 148, 0x73 }, | ||
149 | { 149, 0x33 }, | ||
150 | { 150, 0x73 }, | ||
151 | { 151, 0x33 }, | ||
152 | { 152, 0x00 }, | ||
153 | { 153, 0x00 }, | ||
154 | { 154, 0x00 }, | ||
155 | { 155, 0x00 }, | ||
156 | { 176, 0x00 }, | ||
157 | { 177, 0x00 }, | ||
158 | { 178, 0x00 }, | ||
159 | { 179, 0x00 }, | ||
160 | { 180, 0x00 }, | ||
161 | { 181, 0x00 }, | ||
162 | { 182, 0x00 }, | ||
163 | { 183, 0x00 }, | ||
164 | { 184, 0x00 }, | ||
165 | { 185, 0x00 }, | ||
166 | { 186, 0x00 }, | ||
167 | { 189, 0x00 }, | ||
168 | { 188, 0x00 }, | ||
169 | { 194, 0x00 }, | ||
170 | { 195, 0x00 }, | ||
171 | { 196, 0x00 }, | ||
172 | { 197, 0x00 }, | ||
173 | { 200, 0x00 }, | ||
174 | { 201, 0x00 }, | ||
175 | { 202, 0x00 }, | ||
176 | { 203, 0x00 }, | ||
177 | { 204, 0x00 }, | ||
178 | { 205, 0x00 }, | ||
179 | { 208, 0x00 }, | ||
180 | { 209, 0x00 }, | ||
181 | { 210, 0x00 }, | ||
182 | { 211, 0x00 }, | ||
183 | { 213, 0x00 }, | ||
184 | { 214, 0x00 }, | ||
185 | { 215, 0x00 }, | ||
186 | { 216, 0x00 }, | ||
187 | { 217, 0x00 }, | ||
188 | { 218, 0x00 }, | ||
189 | { 219, 0x00 }, | ||
190 | { 221, 0x00 }, | ||
191 | { 222, 0x00 }, | ||
192 | { 224, 0x00 }, | ||
193 | { 225, 0x00 }, | ||
194 | { 226, 0x00 }, | ||
195 | { 227, 0x00 }, | ||
196 | { 228, 0x00 }, | ||
197 | { 229, 0x00 }, | ||
198 | { 230, 0x13 }, | ||
199 | { 231, 0x00 }, | ||
200 | { 232, 0x80 }, | ||
201 | { 233, 0x0C }, | ||
202 | { 234, 0xDD }, | ||
203 | { 235, 0x00 }, | ||
204 | { 236, 0x04 }, | ||
205 | { 237, 0x00 }, | ||
206 | { 238, 0x00 }, | ||
207 | { 239, 0x00 }, | ||
208 | { 240, 0x00 }, | ||
209 | { 241, 0x00 }, | ||
210 | { 242, 0x00 }, | ||
211 | { 243, 0x00 }, | ||
212 | { 244, 0x00 }, | ||
213 | { 245, 0x00 }, | ||
214 | { 248, 0x00 }, | ||
215 | { 249, 0x00 }, | ||
216 | { 254, 0x00 }, | ||
217 | { 255, 0x00 }, | ||
218 | }; | ||
219 | |||
220 | /* codec private data */ | ||
221 | struct lm49453_priv { | ||
222 | struct regmap *regmap; | ||
223 | int fs_rate; | ||
224 | }; | ||
225 | |||
226 | /* capture path controls */ | ||
227 | |||
228 | static const char *lm49453_mic2mode_text[] = {"Single Ended", "Differential"}; | ||
229 | |||
230 | static const SOC_ENUM_SINGLE_DECL(lm49453_mic2mode_enum, LM49453_P0_MICR_REG, 5, | ||
231 | lm49453_mic2mode_text); | ||
232 | |||
233 | static const char *lm49453_dmic_cfg_text[] = {"DMICDAT1", "DMICDAT2"}; | ||
234 | |||
235 | static const SOC_ENUM_SINGLE_DECL(lm49453_dmic12_cfg_enum, | ||
236 | LM49453_P0_DIGITAL_MIC1_CONFIG_REG, | ||
237 | 7, lm49453_dmic_cfg_text); | ||
238 | |||
239 | static const SOC_ENUM_SINGLE_DECL(lm49453_dmic34_cfg_enum, | ||
240 | LM49453_P0_DIGITAL_MIC2_CONFIG_REG, | ||
241 | 7, lm49453_dmic_cfg_text); | ||
242 | |||
243 | /* MUX Controls */ | ||
244 | static const char *lm49453_adcl_mux_text[] = { "MIC1", "Aux_L" }; | ||
245 | |||
246 | static const char *lm49453_adcr_mux_text[] = { "MIC2", "Aux_R" }; | ||
247 | |||
248 | static const struct soc_enum lm49453_adcl_enum = | ||
249 | SOC_ENUM_SINGLE(LM49453_P0_ANALOG_MIXER_ADC_REG, 0, | ||
250 | ARRAY_SIZE(lm49453_adcl_mux_text), | ||
251 | lm49453_adcl_mux_text); | ||
252 | |||
253 | static const struct soc_enum lm49453_adcr_enum = | ||
254 | SOC_ENUM_SINGLE(LM49453_P0_ANALOG_MIXER_ADC_REG, 1, | ||
255 | ARRAY_SIZE(lm49453_adcr_mux_text), | ||
256 | lm49453_adcr_mux_text); | ||
257 | |||
258 | static const struct snd_kcontrol_new lm49453_adcl_mux_control = | ||
259 | SOC_DAPM_ENUM("ADC Left Mux", lm49453_adcl_enum); | ||
260 | |||
261 | static const struct snd_kcontrol_new lm49453_adcr_mux_control = | ||
262 | SOC_DAPM_ENUM("ADC Right Mux", lm49453_adcr_enum); | ||
263 | |||
264 | static const struct snd_kcontrol_new lm49453_headset_left_mixer[] = { | ||
265 | SOC_DAPM_SINGLE("Port1_1 Switch", LM49453_P0_DACHPL1_REG, 0, 1, 0), | ||
266 | SOC_DAPM_SINGLE("Port1_2 Switch", LM49453_P0_DACHPL1_REG, 1, 1, 0), | ||
267 | SOC_DAPM_SINGLE("Port1_3 Switch", LM49453_P0_DACHPL1_REG, 2, 1, 0), | ||
268 | SOC_DAPM_SINGLE("Port1_4 Switch", LM49453_P0_DACHPL1_REG, 3, 1, 0), | ||
269 | SOC_DAPM_SINGLE("Port1_5 Switch", LM49453_P0_DACHPL1_REG, 4, 1, 0), | ||
270 | SOC_DAPM_SINGLE("Port1_6 Switch", LM49453_P0_DACHPL1_REG, 5, 1, 0), | ||
271 | SOC_DAPM_SINGLE("Port1_7 Switch", LM49453_P0_DACHPL1_REG, 6, 1, 0), | ||
272 | SOC_DAPM_SINGLE("Port1_8 Switch", LM49453_P0_DACHPL1_REG, 7, 1, 0), | ||
273 | SOC_DAPM_SINGLE("DMIC1L Switch", LM49453_P0_DACHPL2_REG, 0, 1, 0), | ||
274 | SOC_DAPM_SINGLE("DMIC1R Switch", LM49453_P0_DACHPL2_REG, 1, 1, 0), | ||
275 | SOC_DAPM_SINGLE("DMIC2L Switch", LM49453_P0_DACHPL2_REG, 2, 1, 0), | ||
276 | SOC_DAPM_SINGLE("DMIC2R Switch", LM49453_P0_DACHPL2_REG, 3, 1, 0), | ||
277 | SOC_DAPM_SINGLE("ADCL Switch", LM49453_P0_DACHPL2_REG, 4, 1, 0), | ||
278 | SOC_DAPM_SINGLE("ADCR Switch", LM49453_P0_DACHPL2_REG, 5, 1, 0), | ||
279 | SOC_DAPM_SINGLE("Port2_1 Switch", LM49453_P0_DACHPL2_REG, 6, 1, 0), | ||
280 | SOC_DAPM_SINGLE("Port2_2 Switch", LM49453_P0_DACHPL2_REG, 7, 1, 0), | ||
281 | SOC_DAPM_SINGLE("Sidetone Switch", LM49453_P0_STN_SEL_REG, 0, 0, 0), | ||
282 | }; | ||
283 | |||
284 | static const struct snd_kcontrol_new lm49453_headset_right_mixer[] = { | ||
285 | SOC_DAPM_SINGLE("Port1_1 Switch", LM49453_P0_DACHPR1_REG, 0, 1, 0), | ||
286 | SOC_DAPM_SINGLE("Port1_2 Switch", LM49453_P0_DACHPR1_REG, 1, 1, 0), | ||
287 | SOC_DAPM_SINGLE("Port1_3 Switch", LM49453_P0_DACHPR1_REG, 2, 1, 0), | ||
288 | SOC_DAPM_SINGLE("Port1_4 Switch", LM49453_P0_DACHPR1_REG, 3, 1, 0), | ||
289 | SOC_DAPM_SINGLE("Port1_5 Switch", LM49453_P0_DACHPR1_REG, 4, 1, 0), | ||
290 | SOC_DAPM_SINGLE("Port1_6 Switch", LM49453_P0_DACHPR1_REG, 5, 1, 0), | ||
291 | SOC_DAPM_SINGLE("Port1_7 Switch", LM49453_P0_DACHPR1_REG, 6, 1, 0), | ||
292 | SOC_DAPM_SINGLE("Port1_8 Switch", LM49453_P0_DACHPR1_REG, 7, 1, 0), | ||
293 | SOC_DAPM_SINGLE("DMIC1L Switch", LM49453_P0_DACHPR2_REG, 0, 1, 0), | ||
294 | SOC_DAPM_SINGLE("DMIC1R Switch", LM49453_P0_DACHPR2_REG, 1, 1, 0), | ||
295 | SOC_DAPM_SINGLE("DMIC2L Switch", LM49453_P0_DACHPR2_REG, 2, 1, 0), | ||
296 | SOC_DAPM_SINGLE("DMIC2R Switch", LM49453_P0_DACHPR2_REG, 3, 1, 0), | ||
297 | SOC_DAPM_SINGLE("ADCL Switch", LM49453_P0_DACHPR2_REG, 4, 1, 0), | ||
298 | SOC_DAPM_SINGLE("ADCR Switch", LM49453_P0_DACHPR2_REG, 5, 1, 0), | ||
299 | SOC_DAPM_SINGLE("Port2_1 Switch", LM49453_P0_DACHPR2_REG, 6, 1, 0), | ||
300 | SOC_DAPM_SINGLE("Port2_2 Switch", LM49453_P0_DACHPR2_REG, 7, 1, 0), | ||
301 | SOC_DAPM_SINGLE("Sidetone Switch", LM49453_P0_STN_SEL_REG, 1, 0, 0), | ||
302 | }; | ||
303 | |||
304 | static const struct snd_kcontrol_new lm49453_speaker_left_mixer[] = { | ||
305 | SOC_DAPM_SINGLE("Port1_1 Switch", LM49453_P0_DACLSL1_REG, 0, 1, 0), | ||
306 | SOC_DAPM_SINGLE("Port1_2 Switch", LM49453_P0_DACLSL1_REG, 1, 1, 0), | ||
307 | SOC_DAPM_SINGLE("Port1_3 Switch", LM49453_P0_DACLSL1_REG, 2, 1, 0), | ||
308 | SOC_DAPM_SINGLE("Port1_4 Switch", LM49453_P0_DACLSL1_REG, 3, 1, 0), | ||
309 | SOC_DAPM_SINGLE("Port1_5 Switch", LM49453_P0_DACLSL1_REG, 4, 1, 0), | ||
310 | SOC_DAPM_SINGLE("Port1_6 Switch", LM49453_P0_DACLSL1_REG, 5, 1, 0), | ||
311 | SOC_DAPM_SINGLE("Port1_7 Switch", LM49453_P0_DACLSL1_REG, 6, 1, 0), | ||
312 | SOC_DAPM_SINGLE("Port1_8 Switch", LM49453_P0_DACLSL1_REG, 7, 1, 0), | ||
313 | SOC_DAPM_SINGLE("DMIC1L Switch", LM49453_P0_DACLSL2_REG, 0, 1, 0), | ||
314 | SOC_DAPM_SINGLE("DMIC1R Switch", LM49453_P0_DACLSL2_REG, 1, 1, 0), | ||
315 | SOC_DAPM_SINGLE("DMIC2L Switch", LM49453_P0_DACLSL2_REG, 2, 1, 0), | ||
316 | SOC_DAPM_SINGLE("DMIC2R Switch", LM49453_P0_DACLSL2_REG, 3, 1, 0), | ||
317 | SOC_DAPM_SINGLE("ADCL Switch", LM49453_P0_DACLSL2_REG, 4, 1, 0), | ||
318 | SOC_DAPM_SINGLE("ADCR Switch", LM49453_P0_DACLSL2_REG, 5, 1, 0), | ||
319 | SOC_DAPM_SINGLE("Port2_1 Switch", LM49453_P0_DACLSL2_REG, 6, 1, 0), | ||
320 | SOC_DAPM_SINGLE("Port2_2 Switch", LM49453_P0_DACLSL2_REG, 7, 1, 0), | ||
321 | SOC_DAPM_SINGLE("Sidetone Switch", LM49453_P0_STN_SEL_REG, 2, 0, 0), | ||
322 | }; | ||
323 | |||
324 | static const struct snd_kcontrol_new lm49453_speaker_right_mixer[] = { | ||
325 | SOC_DAPM_SINGLE("Port1_1 Switch", LM49453_P0_DACLSR1_REG, 0, 1, 0), | ||
326 | SOC_DAPM_SINGLE("Port1_2 Switch", LM49453_P0_DACLSR1_REG, 1, 1, 0), | ||
327 | SOC_DAPM_SINGLE("Port1_3 Switch", LM49453_P0_DACLSR1_REG, 2, 1, 0), | ||
328 | SOC_DAPM_SINGLE("Port1_4 Switch", LM49453_P0_DACLSR1_REG, 3, 1, 0), | ||
329 | SOC_DAPM_SINGLE("Port1_5 Switch", LM49453_P0_DACLSR1_REG, 4, 1, 0), | ||
330 | SOC_DAPM_SINGLE("Port1_6 Switch", LM49453_P0_DACLSR1_REG, 5, 1, 0), | ||
331 | SOC_DAPM_SINGLE("Port1_7 Switch", LM49453_P0_DACLSR1_REG, 6, 1, 0), | ||
332 | SOC_DAPM_SINGLE("Port1_8 Switch", LM49453_P0_DACLSR1_REG, 7, 1, 0), | ||
333 | SOC_DAPM_SINGLE("DMIC1L Switch", LM49453_P0_DACLSR2_REG, 0, 1, 0), | ||
334 | SOC_DAPM_SINGLE("DMIC1R Switch", LM49453_P0_DACLSR2_REG, 1, 1, 0), | ||
335 | SOC_DAPM_SINGLE("DMIC2L Switch", LM49453_P0_DACLSR2_REG, 2, 1, 0), | ||
336 | SOC_DAPM_SINGLE("DMIC2R Switch", LM49453_P0_DACLSR2_REG, 3, 1, 0), | ||
337 | SOC_DAPM_SINGLE("ADCL Switch", LM49453_P0_DACLSR2_REG, 4, 1, 0), | ||
338 | SOC_DAPM_SINGLE("ADCR Switch", LM49453_P0_DACLSR2_REG, 5, 1, 0), | ||
339 | SOC_DAPM_SINGLE("Port2_1 Switch", LM49453_P0_DACLSR2_REG, 6, 1, 0), | ||
340 | SOC_DAPM_SINGLE("Port2_2 Switch", LM49453_P0_DACLSR2_REG, 7, 1, 0), | ||
341 | SOC_DAPM_SINGLE("Sidetone Switch", LM49453_P0_STN_SEL_REG, 3, 0, 0), | ||
342 | }; | ||
343 | |||
344 | static const struct snd_kcontrol_new lm49453_haptic_left_mixer[] = { | ||
345 | SOC_DAPM_SINGLE("Port1_1 Switch", LM49453_P0_DACHAL1_REG, 0, 1, 0), | ||
346 | SOC_DAPM_SINGLE("Port1_2 Switch", LM49453_P0_DACHAL1_REG, 1, 1, 0), | ||
347 | SOC_DAPM_SINGLE("Port1_3 Switch", LM49453_P0_DACHAL1_REG, 2, 1, 0), | ||
348 | SOC_DAPM_SINGLE("Port1_4 Switch", LM49453_P0_DACHAL1_REG, 3, 1, 0), | ||
349 | SOC_DAPM_SINGLE("Port1_5 Switch", LM49453_P0_DACHAL1_REG, 4, 1, 0), | ||
350 | SOC_DAPM_SINGLE("Port1_6 Switch", LM49453_P0_DACHAL1_REG, 5, 1, 0), | ||
351 | SOC_DAPM_SINGLE("Port1_7 Switch", LM49453_P0_DACHAL1_REG, 6, 1, 0), | ||
352 | SOC_DAPM_SINGLE("Port1_8 Switch", LM49453_P0_DACHAL1_REG, 7, 1, 0), | ||
353 | SOC_DAPM_SINGLE("DMIC1L Switch", LM49453_P0_DACHAL2_REG, 0, 1, 0), | ||
354 | SOC_DAPM_SINGLE("DMIC1R Switch", LM49453_P0_DACHAL2_REG, 1, 1, 0), | ||
355 | SOC_DAPM_SINGLE("DMIC2L Switch", LM49453_P0_DACHAL2_REG, 2, 1, 0), | ||
356 | SOC_DAPM_SINGLE("DMIC2R Switch", LM49453_P0_DACHAL2_REG, 3, 1, 0), | ||
357 | SOC_DAPM_SINGLE("ADCL Switch", LM49453_P0_DACHAL2_REG, 4, 1, 0), | ||
358 | SOC_DAPM_SINGLE("ADCR Switch", LM49453_P0_DACHAL2_REG, 5, 1, 0), | ||
359 | SOC_DAPM_SINGLE("Port2_1 Switch", LM49453_P0_DACHAL2_REG, 6, 1, 0), | ||
360 | SOC_DAPM_SINGLE("Port2_2 Switch", LM49453_P0_DACHAL2_REG, 7, 1, 0), | ||
361 | SOC_DAPM_SINGLE("Sidetone Switch", LM49453_P0_STN_SEL_REG, 4, 0, 0), | ||
362 | }; | ||
363 | |||
364 | static const struct snd_kcontrol_new lm49453_haptic_right_mixer[] = { | ||
365 | SOC_DAPM_SINGLE("Port1_1 Switch", LM49453_P0_DACHAR1_REG, 0, 1, 0), | ||
366 | SOC_DAPM_SINGLE("Port1_2 Switch", LM49453_P0_DACHAR1_REG, 1, 1, 0), | ||
367 | SOC_DAPM_SINGLE("Port1_3 Switch", LM49453_P0_DACHAR1_REG, 2, 1, 0), | ||
368 | SOC_DAPM_SINGLE("Port1_4 Switch", LM49453_P0_DACHAR1_REG, 3, 1, 0), | ||
369 | SOC_DAPM_SINGLE("Port1_5 Switch", LM49453_P0_DACHAR1_REG, 4, 1, 0), | ||
370 | SOC_DAPM_SINGLE("Port1_6 Switch", LM49453_P0_DACHAR1_REG, 5, 1, 0), | ||
371 | SOC_DAPM_SINGLE("Port1_7 Switch", LM49453_P0_DACHAR1_REG, 6, 1, 0), | ||
372 | SOC_DAPM_SINGLE("Port1_8 Switch", LM49453_P0_DACHAR1_REG, 7, 1, 0), | ||
373 | SOC_DAPM_SINGLE("DMIC1L Switch", LM49453_P0_DACHAR2_REG, 0, 1, 0), | ||
374 | SOC_DAPM_SINGLE("DMIC1R Switch", LM49453_P0_DACHAR2_REG, 1, 1, 0), | ||
375 | SOC_DAPM_SINGLE("DMIC2L Switch", LM49453_P0_DACHAR2_REG, 2, 1, 0), | ||
376 | SOC_DAPM_SINGLE("DMIC2R Switch", LM49453_P0_DACHAR2_REG, 3, 1, 0), | ||
377 | SOC_DAPM_SINGLE("ADCL Switch", LM49453_P0_DACHAR2_REG, 4, 1, 0), | ||
378 | SOC_DAPM_SINGLE("ADCR Switch", LM49453_P0_DACHAR2_REG, 5, 1, 0), | ||
379 | SOC_DAPM_SINGLE("Port2_1 Switch", LM49453_P0_DACHAR2_REG, 6, 1, 0), | ||
380 | SOC_DAPM_SINGLE("Port2_2 Switch", LM49453_P0_DACHAR2_REG, 7, 1, 0), | ||
381 | SOC_DAPM_SINGLE("Sidetone Switch", LM49453_P0_STN_SEL_REG, 5, 0, 0), | ||
382 | }; | ||
383 | |||
384 | static const struct snd_kcontrol_new lm49453_lineout_left_mixer[] = { | ||
385 | SOC_DAPM_SINGLE("Port1_1 Switch", LM49453_P0_DACLOL1_REG, 0, 1, 0), | ||
386 | SOC_DAPM_SINGLE("Port1_2 Switch", LM49453_P0_DACLOL1_REG, 1, 1, 0), | ||
387 | SOC_DAPM_SINGLE("Port1_3 Switch", LM49453_P0_DACLOL1_REG, 2, 1, 0), | ||
388 | SOC_DAPM_SINGLE("Port1_4 Switch", LM49453_P0_DACLOL1_REG, 3, 1, 0), | ||
389 | SOC_DAPM_SINGLE("Port1_5 Switch", LM49453_P0_DACLOL1_REG, 4, 1, 0), | ||
390 | SOC_DAPM_SINGLE("Port1_6 Switch", LM49453_P0_DACLOL1_REG, 5, 1, 0), | ||
391 | SOC_DAPM_SINGLE("Port1_7 Switch", LM49453_P0_DACLOL1_REG, 6, 1, 0), | ||
392 | SOC_DAPM_SINGLE("Port1_8 Switch", LM49453_P0_DACLOL1_REG, 7, 1, 0), | ||
393 | SOC_DAPM_SINGLE("DMIC1L Switch", LM49453_P0_DACLOL2_REG, 0, 1, 0), | ||
394 | SOC_DAPM_SINGLE("DMIC1R Switch", LM49453_P0_DACLOL2_REG, 1, 1, 0), | ||
395 | SOC_DAPM_SINGLE("DMIC2L Switch", LM49453_P0_DACLOL2_REG, 2, 1, 0), | ||
396 | SOC_DAPM_SINGLE("DMIC2R Switch", LM49453_P0_DACLOL2_REG, 3, 1, 0), | ||
397 | SOC_DAPM_SINGLE("ADCL Switch", LM49453_P0_DACLOL2_REG, 4, 1, 0), | ||
398 | SOC_DAPM_SINGLE("ADCR Switch", LM49453_P0_DACLOL2_REG, 5, 1, 0), | ||
399 | SOC_DAPM_SINGLE("Port2_1 Switch", LM49453_P0_DACLOL2_REG, 6, 1, 0), | ||
400 | SOC_DAPM_SINGLE("Port2_2 Switch", LM49453_P0_DACLOL2_REG, 7, 1, 0), | ||
401 | SOC_DAPM_SINGLE("Sidetone Switch", LM49453_P0_STN_SEL_REG, 6, 0, 0), | ||
402 | }; | ||
403 | |||
404 | static const struct snd_kcontrol_new lm49453_lineout_right_mixer[] = { | ||
405 | SOC_DAPM_SINGLE("Port1_1 Switch", LM49453_P0_DACLOR1_REG, 0, 1, 0), | ||
406 | SOC_DAPM_SINGLE("Port1_2 Switch", LM49453_P0_DACLOR1_REG, 1, 1, 0), | ||
407 | SOC_DAPM_SINGLE("Port1_3 Switch", LM49453_P0_DACLOR1_REG, 2, 1, 0), | ||
408 | SOC_DAPM_SINGLE("Port1_4 Switch", LM49453_P0_DACLOR1_REG, 3, 1, 0), | ||
409 | SOC_DAPM_SINGLE("Port1_5 Switch", LM49453_P0_DACLOR1_REG, 4, 1, 0), | ||
410 | SOC_DAPM_SINGLE("Port1_6 Switch", LM49453_P0_DACLOR1_REG, 5, 1, 0), | ||
411 | SOC_DAPM_SINGLE("Port1_7 Switch", LM49453_P0_DACLOR1_REG, 6, 1, 0), | ||
412 | SOC_DAPM_SINGLE("Port1_8 Switch", LM49453_P0_DACLOR1_REG, 7, 1, 0), | ||
413 | SOC_DAPM_SINGLE("DMIC1L Switch", LM49453_P0_DACLOR2_REG, 0, 1, 0), | ||
414 | SOC_DAPM_SINGLE("DMIC1R Switch", LM49453_P0_DACLOR2_REG, 1, 1, 0), | ||
415 | SOC_DAPM_SINGLE("DMIC2L Switch", LM49453_P0_DACLOR2_REG, 2, 1, 0), | ||
416 | SOC_DAPM_SINGLE("DMIC2R Switch", LM49453_P0_DACLOR2_REG, 3, 1, 0), | ||
417 | SOC_DAPM_SINGLE("ADCL Switch", LM49453_P0_DACLOR2_REG, 4, 1, 0), | ||
418 | SOC_DAPM_SINGLE("ADCR Switch", LM49453_P0_DACLOR2_REG, 5, 1, 0), | ||
419 | SOC_DAPM_SINGLE("Port2_1 Switch", LM49453_P0_DACLOR2_REG, 6, 1, 0), | ||
420 | SOC_DAPM_SINGLE("Port2_2 Switch", LM49453_P0_DACLOR2_REG, 7, 1, 0), | ||
421 | SOC_DAPM_SINGLE("Sidetone Switch", LM49453_P0_STN_SEL_REG, 7, 0, 0), | ||
422 | }; | ||
423 | |||
424 | static const struct snd_kcontrol_new lm49453_port1_tx1_mixer[] = { | ||
425 | SOC_DAPM_SINGLE("DMIC1L Switch", LM49453_P0_PORT1_TX1_REG, 0, 1, 0), | ||
426 | SOC_DAPM_SINGLE("DMIC1R Switch", LM49453_P0_PORT1_TX1_REG, 1, 1, 0), | ||
427 | SOC_DAPM_SINGLE("DMIC2L Switch", LM49453_P0_PORT1_TX1_REG, 2, 1, 0), | ||
428 | SOC_DAPM_SINGLE("DMIC2R Switch", LM49453_P0_PORT1_TX1_REG, 3, 1, 0), | ||
429 | SOC_DAPM_SINGLE("ADCL Switch", LM49453_P0_PORT1_TX1_REG, 4, 1, 0), | ||
430 | SOC_DAPM_SINGLE("ADCR Switch", LM49453_P0_PORT1_TX1_REG, 5, 1, 0), | ||
431 | SOC_DAPM_SINGLE("Port1_1 Switch", LM49453_P0_PORT1_TX1_REG, 6, 1, 0), | ||
432 | SOC_DAPM_SINGLE("Port2_1 Switch", LM49453_P0_PORT1_TX1_REG, 7, 1, 0), | ||
433 | }; | ||
434 | |||
435 | static const struct snd_kcontrol_new lm49453_port1_tx2_mixer[] = { | ||
436 | SOC_DAPM_SINGLE("DMIC1L Switch", LM49453_P0_PORT1_TX2_REG, 0, 1, 0), | ||
437 | SOC_DAPM_SINGLE("DMIC1R Switch", LM49453_P0_PORT1_TX2_REG, 1, 1, 0), | ||
438 | SOC_DAPM_SINGLE("DMIC2L Switch", LM49453_P0_PORT1_TX2_REG, 2, 1, 0), | ||
439 | SOC_DAPM_SINGLE("DMIC2R Switch", LM49453_P0_PORT1_TX2_REG, 3, 1, 0), | ||
440 | SOC_DAPM_SINGLE("ADCL Switch", LM49453_P0_PORT1_TX2_REG, 4, 1, 0), | ||
441 | SOC_DAPM_SINGLE("ADCR Switch", LM49453_P0_PORT1_TX2_REG, 5, 1, 0), | ||
442 | SOC_DAPM_SINGLE("Port1_2 Switch", LM49453_P0_PORT1_TX2_REG, 6, 1, 0), | ||
443 | SOC_DAPM_SINGLE("Port2_2 Switch", LM49453_P0_PORT1_TX2_REG, 7, 1, 0), | ||
444 | }; | ||
445 | |||
446 | static const struct snd_kcontrol_new lm49453_port1_tx3_mixer[] = { | ||
447 | SOC_DAPM_SINGLE("DMIC1L Switch", LM49453_P0_PORT1_TX3_REG, 0, 1, 0), | ||
448 | SOC_DAPM_SINGLE("DMIC1R Switch", LM49453_P0_PORT1_TX3_REG, 1, 1, 0), | ||
449 | SOC_DAPM_SINGLE("DMIC2L Switch", LM49453_P0_PORT1_TX3_REG, 2, 1, 0), | ||
450 | SOC_DAPM_SINGLE("DMIC2R Switch", LM49453_P0_PORT1_TX3_REG, 3, 1, 0), | ||
451 | SOC_DAPM_SINGLE("ADCL Switch", LM49453_P0_PORT1_TX3_REG, 4, 1, 0), | ||
452 | SOC_DAPM_SINGLE("ADCR Switch", LM49453_P0_PORT1_TX3_REG, 5, 1, 0), | ||
453 | SOC_DAPM_SINGLE("Port1_3 Switch", LM49453_P0_PORT1_TX3_REG, 6, 1, 0), | ||
454 | }; | ||
455 | |||
456 | static const struct snd_kcontrol_new lm49453_port1_tx4_mixer[] = { | ||
457 | SOC_DAPM_SINGLE("DMIC1L Switch", LM49453_P0_PORT1_TX4_REG, 0, 1, 0), | ||
458 | SOC_DAPM_SINGLE("DMIC1R Switch", LM49453_P0_PORT1_TX4_REG, 1, 1, 0), | ||
459 | SOC_DAPM_SINGLE("DMIC2L Switch", LM49453_P0_PORT1_TX4_REG, 2, 1, 0), | ||
460 | SOC_DAPM_SINGLE("DMIC2R Switch", LM49453_P0_PORT1_TX4_REG, 3, 1, 0), | ||
461 | SOC_DAPM_SINGLE("ADCL Switch", LM49453_P0_PORT1_TX4_REG, 4, 1, 0), | ||
462 | SOC_DAPM_SINGLE("ADCR Switch", LM49453_P0_PORT1_TX4_REG, 5, 1, 0), | ||
463 | SOC_DAPM_SINGLE("Port1_4 Switch", LM49453_P0_PORT1_TX4_REG, 6, 1, 0), | ||
464 | }; | ||
465 | |||
466 | static const struct snd_kcontrol_new lm49453_port1_tx5_mixer[] = { | ||
467 | SOC_DAPM_SINGLE("DMIC1L Switch", LM49453_P0_PORT1_TX5_REG, 0, 1, 0), | ||
468 | SOC_DAPM_SINGLE("DMIC1R Switch", LM49453_P0_PORT1_TX5_REG, 1, 1, 0), | ||
469 | SOC_DAPM_SINGLE("DMIC2L Switch", LM49453_P0_PORT1_TX5_REG, 2, 1, 0), | ||
470 | SOC_DAPM_SINGLE("DMIC2R Switch", LM49453_P0_PORT1_TX5_REG, 3, 1, 0), | ||
471 | SOC_DAPM_SINGLE("ADCL Switch", LM49453_P0_PORT1_TX5_REG, 4, 1, 0), | ||
472 | SOC_DAPM_SINGLE("ADCR Switch", LM49453_P0_PORT1_TX5_REG, 5, 1, 0), | ||
473 | SOC_DAPM_SINGLE("Port1_5 Switch", LM49453_P0_PORT1_TX5_REG, 6, 1, 0), | ||
474 | }; | ||
475 | |||
476 | static const struct snd_kcontrol_new lm49453_port1_tx6_mixer[] = { | ||
477 | SOC_DAPM_SINGLE("DMIC1L Switch", LM49453_P0_PORT1_TX6_REG, 0, 1, 0), | ||
478 | SOC_DAPM_SINGLE("DMIC1R Switch", LM49453_P0_PORT1_TX6_REG, 1, 1, 0), | ||
479 | SOC_DAPM_SINGLE("DMIC2L Switch", LM49453_P0_PORT1_TX6_REG, 2, 1, 0), | ||
480 | SOC_DAPM_SINGLE("DMIC2R Switch", LM49453_P0_PORT1_TX6_REG, 3, 1, 0), | ||
481 | SOC_DAPM_SINGLE("ADCL Switch", LM49453_P0_PORT1_TX6_REG, 4, 1, 0), | ||
482 | SOC_DAPM_SINGLE("ADCR Switch", LM49453_P0_PORT1_TX6_REG, 5, 1, 0), | ||
483 | SOC_DAPM_SINGLE("Port1_6 Switch", LM49453_P0_PORT1_TX6_REG, 6, 1, 0), | ||
484 | }; | ||
485 | |||
486 | static const struct snd_kcontrol_new lm49453_port1_tx7_mixer[] = { | ||
487 | SOC_DAPM_SINGLE("DMIC1L Switch", LM49453_P0_PORT1_TX7_REG, 0, 1, 0), | ||
488 | SOC_DAPM_SINGLE("DMIC1R Switch", LM49453_P0_PORT1_TX7_REG, 1, 1, 0), | ||
489 | SOC_DAPM_SINGLE("DMIC2L Switch", LM49453_P0_PORT1_TX7_REG, 2, 1, 0), | ||
490 | SOC_DAPM_SINGLE("DMIC2R Switch", LM49453_P0_PORT1_TX7_REG, 3, 1, 0), | ||
491 | SOC_DAPM_SINGLE("ADCL Switch", LM49453_P0_PORT1_TX7_REG, 4, 1, 0), | ||
492 | SOC_DAPM_SINGLE("ADCR Switch", LM49453_P0_PORT1_TX7_REG, 5, 1, 0), | ||
493 | SOC_DAPM_SINGLE("Port1_7 Switch", LM49453_P0_PORT1_TX7_REG, 6, 1, 0), | ||
494 | }; | ||
495 | |||
496 | static const struct snd_kcontrol_new lm49453_port1_tx8_mixer[] = { | ||
497 | SOC_DAPM_SINGLE("DMIC1L Switch", LM49453_P0_PORT1_TX8_REG, 0, 1, 0), | ||
498 | SOC_DAPM_SINGLE("DMIC1R Switch", LM49453_P0_PORT1_TX8_REG, 1, 1, 0), | ||
499 | SOC_DAPM_SINGLE("DMIC2L Switch", LM49453_P0_PORT1_TX8_REG, 2, 1, 0), | ||
500 | SOC_DAPM_SINGLE("DMIC2R Switch", LM49453_P0_PORT1_TX8_REG, 3, 1, 0), | ||
501 | SOC_DAPM_SINGLE("ADCL Switch", LM49453_P0_PORT1_TX8_REG, 4, 1, 0), | ||
502 | SOC_DAPM_SINGLE("ADCR Switch", LM49453_P0_PORT1_TX8_REG, 5, 1, 0), | ||
503 | SOC_DAPM_SINGLE("Port1_8 Switch", LM49453_P0_PORT1_TX8_REG, 6, 1, 0), | ||
504 | }; | ||
505 | |||
506 | static const struct snd_kcontrol_new lm49453_port2_tx1_mixer[] = { | ||
507 | SOC_DAPM_SINGLE("DMIC1L Switch", LM49453_P0_PORT2_TX1_REG, 0, 1, 0), | ||
508 | SOC_DAPM_SINGLE("DMIC1R Switch", LM49453_P0_PORT2_TX1_REG, 1, 1, 0), | ||
509 | SOC_DAPM_SINGLE("DMIC2L Switch", LM49453_P0_PORT2_TX1_REG, 2, 1, 0), | ||
510 | SOC_DAPM_SINGLE("DMIC2R Switch", LM49453_P0_PORT2_TX1_REG, 3, 1, 0), | ||
511 | SOC_DAPM_SINGLE("ADCL Switch", LM49453_P0_PORT2_TX1_REG, 4, 1, 0), | ||
512 | SOC_DAPM_SINGLE("ADCR Switch", LM49453_P0_PORT2_TX1_REG, 5, 1, 0), | ||
513 | SOC_DAPM_SINGLE("Port1_1 Switch", LM49453_P0_PORT2_TX1_REG, 6, 1, 0), | ||
514 | SOC_DAPM_SINGLE("Port2_1 Switch", LM49453_P0_PORT2_TX1_REG, 7, 1, 0), | ||
515 | }; | ||
516 | |||
517 | static const struct snd_kcontrol_new lm49453_port2_tx2_mixer[] = { | ||
518 | SOC_DAPM_SINGLE("DMIC1L Switch", LM49453_P0_PORT2_TX2_REG, 0, 1, 0), | ||
519 | SOC_DAPM_SINGLE("DMIC1R Switch", LM49453_P0_PORT2_TX2_REG, 1, 1, 0), | ||
520 | SOC_DAPM_SINGLE("DMIC2L Switch", LM49453_P0_PORT2_TX2_REG, 2, 1, 0), | ||
521 | SOC_DAPM_SINGLE("DMIC2R Switch", LM49453_P0_PORT2_TX2_REG, 3, 1, 0), | ||
522 | SOC_DAPM_SINGLE("ADCL Switch", LM49453_P0_PORT2_TX2_REG, 4, 1, 0), | ||
523 | SOC_DAPM_SINGLE("ADCR Switch", LM49453_P0_PORT2_TX2_REG, 5, 1, 0), | ||
524 | SOC_DAPM_SINGLE("Port1_2 Switch", LM49453_P0_PORT2_TX2_REG, 6, 1, 0), | ||
525 | SOC_DAPM_SINGLE("Port2_2 Switch", LM49453_P0_PORT2_TX2_REG, 7, 1, 0), | ||
526 | }; | ||
527 | |||
528 | /* TLV Declarations */ | ||
529 | static const DECLARE_TLV_DB_SCALE(digital_tlv, -7650, 150, 1); | ||
530 | static const DECLARE_TLV_DB_SCALE(port_tlv, 0, 600, 0); | ||
531 | |||
532 | static const struct snd_kcontrol_new lm49453_sidetone_mixer_controls[] = { | ||
533 | /* Sidetone supports mono only */ | ||
534 | SOC_DAPM_SINGLE_TLV("Sidetone ADCL Volume", LM49453_P0_STN_VOL_ADCL_REG, | ||
535 | 0, 0x3F, 0, digital_tlv), | ||
536 | SOC_DAPM_SINGLE_TLV("Sidetone ADCR Volume", LM49453_P0_STN_VOL_ADCR_REG, | ||
537 | 0, 0x3F, 0, digital_tlv), | ||
538 | SOC_DAPM_SINGLE_TLV("Sidetone DMIC1L Volume", LM49453_P0_STN_VOL_DMIC1L_REG, | ||
539 | 0, 0x3F, 0, digital_tlv), | ||
540 | SOC_DAPM_SINGLE_TLV("Sidetone DMIC1R Volume", LM49453_P0_STN_VOL_DMIC1R_REG, | ||
541 | 0, 0x3F, 0, digital_tlv), | ||
542 | SOC_DAPM_SINGLE_TLV("Sidetone DMIC2L Volume", LM49453_P0_STN_VOL_DMIC2L_REG, | ||
543 | 0, 0x3F, 0, digital_tlv), | ||
544 | SOC_DAPM_SINGLE_TLV("Sidetone DMIC2R Volume", LM49453_P0_STN_VOL_DMIC2R_REG, | ||
545 | 0, 0x3F, 0, digital_tlv), | ||
546 | }; | ||
547 | |||
548 | static const struct snd_kcontrol_new lm49453_snd_controls[] = { | ||
549 | /* mic1 and mic2 supports mono only */ | ||
550 | SOC_SINGLE_TLV("Mic1 Volume", LM49453_P0_ADC_LEVELL_REG, 0, 6, | ||
551 | 0, digital_tlv), | ||
552 | SOC_SINGLE_TLV("Mic2 Volume", LM49453_P0_ADC_LEVELR_REG, 0, 6, | ||
553 | 0, digital_tlv), | ||
554 | |||
555 | SOC_DOUBLE_R_TLV("DMIC1 Volume", LM49453_P0_DMIC1_LEVELL_REG, | ||
556 | LM49453_P0_DMIC1_LEVELR_REG, 0, 6, 0, digital_tlv), | ||
557 | SOC_DOUBLE_R_TLV("DMIC2 Volume", LM49453_P0_DMIC2_LEVELL_REG, | ||
558 | LM49453_P0_DMIC2_LEVELR_REG, 0, 6, 0, digital_tlv), | ||
559 | |||
560 | SOC_DAPM_ENUM("Mic2Mode", lm49453_mic2mode_enum), | ||
561 | SOC_DAPM_ENUM("DMIC12 SRC", lm49453_dmic12_cfg_enum), | ||
562 | SOC_DAPM_ENUM("DMIC34 SRC", lm49453_dmic34_cfg_enum), | ||
563 | |||
564 | /* Capture path filter enable */ | ||
565 | SOC_SINGLE("DMIC1 HPFilter Switch", LM49453_P0_ADC_FX_ENABLES_REG, | ||
566 | 0, 1, 0), | ||
567 | SOC_SINGLE("DMIC2 HPFilter Switch", LM49453_P0_ADC_FX_ENABLES_REG, | ||
568 | 1, 1, 0), | ||
569 | SOC_SINGLE("ADC HPFilter Switch", LM49453_P0_ADC_FX_ENABLES_REG, | ||
570 | 2, 1, 0), | ||
571 | |||
572 | SOC_DOUBLE_R_TLV("DAC HP Volume", LM49453_P0_DAC_HP_LEVELL_REG, | ||
573 | LM49453_P0_DAC_HP_LEVELR_REG, 0, 6, 0, digital_tlv), | ||
574 | SOC_DOUBLE_R_TLV("DAC LO Volume", LM49453_P0_DAC_LO_LEVELL_REG, | ||
575 | LM49453_P0_DAC_LO_LEVELR_REG, 0, 6, 0, digital_tlv), | ||
576 | SOC_DOUBLE_R_TLV("DAC LS Volume", LM49453_P0_DAC_LS_LEVELL_REG, | ||
577 | LM49453_P0_DAC_LS_LEVELR_REG, 0, 6, 0, digital_tlv), | ||
578 | SOC_DOUBLE_R_TLV("DAC HA Volume", LM49453_P0_DAC_HA_LEVELL_REG, | ||
579 | LM49453_P0_DAC_HA_LEVELR_REG, 0, 6, 0, digital_tlv), | ||
580 | |||
581 | SOC_SINGLE_TLV("EP Volume", LM49453_P0_DAC_LS_LEVELL_REG, | ||
582 | 0, 6, 0, digital_tlv), | ||
583 | |||
584 | SOC_SINGLE_TLV("PORT1_1_RX_LVL Volume", LM49453_P0_PORT1_RX_LVL1_REG, | ||
585 | 0, 3, 0, port_tlv), | ||
586 | SOC_SINGLE_TLV("PORT1_2_RX_LVL Volume", LM49453_P0_PORT1_RX_LVL1_REG, | ||
587 | 2, 3, 0, port_tlv), | ||
588 | SOC_SINGLE_TLV("PORT1_3_RX_LVL Volume", LM49453_P0_PORT1_RX_LVL1_REG, | ||
589 | 4, 3, 0, port_tlv), | ||
590 | SOC_SINGLE_TLV("PORT1_4_RX_LVL Volume", LM49453_P0_PORT1_RX_LVL1_REG, | ||
591 | 6, 3, 0, port_tlv), | ||
592 | SOC_SINGLE_TLV("PORT1_5_RX_LVL Volume", LM49453_P0_PORT1_RX_LVL2_REG, | ||
593 | 0, 3, 0, port_tlv), | ||
594 | SOC_SINGLE_TLV("PORT1_6_RX_LVL Volume", LM49453_P0_PORT1_RX_LVL2_REG, | ||
595 | 2, 3, 0, port_tlv), | ||
596 | SOC_SINGLE_TLV("PORT1_7_RX_LVL Volume", LM49453_P0_PORT1_RX_LVL2_REG, | ||
597 | 4, 3, 0, port_tlv), | ||
598 | SOC_SINGLE_TLV("PORT1_8_RX_LVL Volume", LM49453_P0_PORT1_RX_LVL2_REG, | ||
599 | 6, 3, 0, port_tlv), | ||
600 | |||
601 | SOC_SINGLE_TLV("PORT2_1_RX_LVL Volume", LM49453_P0_PORT2_RX_LVL_REG, | ||
602 | 0, 3, 0, port_tlv), | ||
603 | SOC_SINGLE_TLV("PORT2_2_RX_LVL Volume", LM49453_P0_PORT2_RX_LVL_REG, | ||
604 | 2, 3, 0, port_tlv), | ||
605 | |||
606 | SOC_SINGLE("Port1 Playback Switch", LM49453_P0_AUDIO_PORT1_BASIC_REG, | ||
607 | 1, 1, 0), | ||
608 | SOC_SINGLE("Port2 Playback Switch", LM49453_P0_AUDIO_PORT2_BASIC_REG, | ||
609 | 1, 1, 0), | ||
610 | SOC_SINGLE("Port1 Capture Switch", LM49453_P0_AUDIO_PORT1_BASIC_REG, | ||
611 | 2, 1, 0), | ||
612 | SOC_SINGLE("Port2 Capture Switch", LM49453_P0_AUDIO_PORT2_BASIC_REG, | ||
613 | 2, 1, 0) | ||
614 | |||
615 | }; | ||
616 | |||
617 | /* DAPM widgets */ | ||
618 | static const struct snd_soc_dapm_widget lm49453_dapm_widgets[] = { | ||
619 | |||
620 | /* All end points HP,EP, LS, Lineout and Haptic */ | ||
621 | SND_SOC_DAPM_OUTPUT("HPOUTL"), | ||
622 | SND_SOC_DAPM_OUTPUT("HPOUTR"), | ||
623 | SND_SOC_DAPM_OUTPUT("EPOUT"), | ||
624 | SND_SOC_DAPM_OUTPUT("LSOUTL"), | ||
625 | SND_SOC_DAPM_OUTPUT("LSOUTR"), | ||
626 | SND_SOC_DAPM_OUTPUT("LOOUTR"), | ||
627 | SND_SOC_DAPM_OUTPUT("LOOUTL"), | ||
628 | SND_SOC_DAPM_OUTPUT("HAOUTL"), | ||
629 | SND_SOC_DAPM_OUTPUT("HAOUTR"), | ||
630 | |||
631 | SND_SOC_DAPM_INPUT("AMIC1"), | ||
632 | SND_SOC_DAPM_INPUT("AMIC2"), | ||
633 | SND_SOC_DAPM_INPUT("DMIC1DAT"), | ||
634 | SND_SOC_DAPM_INPUT("DMIC2DAT"), | ||
635 | SND_SOC_DAPM_INPUT("AUXL"), | ||
636 | SND_SOC_DAPM_INPUT("AUXR"), | ||
637 | |||
638 | SND_SOC_DAPM_PGA("PORT1_1_RX", SND_SOC_NOPM, 0, 0, NULL, 0), | ||
639 | SND_SOC_DAPM_PGA("PORT1_2_RX", SND_SOC_NOPM, 0, 0, NULL, 0), | ||
640 | SND_SOC_DAPM_PGA("PORT1_3_RX", SND_SOC_NOPM, 0, 0, NULL, 0), | ||
641 | SND_SOC_DAPM_PGA("PORT1_4_RX", SND_SOC_NOPM, 0, 0, NULL, 0), | ||
642 | SND_SOC_DAPM_PGA("PORT1_5_RX", SND_SOC_NOPM, 0, 0, NULL, 0), | ||
643 | SND_SOC_DAPM_PGA("PORT1_6_RX", SND_SOC_NOPM, 0, 0, NULL, 0), | ||
644 | SND_SOC_DAPM_PGA("PORT1_7_RX", SND_SOC_NOPM, 0, 0, NULL, 0), | ||
645 | SND_SOC_DAPM_PGA("PORT1_8_RX", SND_SOC_NOPM, 0, 0, NULL, 0), | ||
646 | SND_SOC_DAPM_PGA("PORT2_1_RX", SND_SOC_NOPM, 0, 0, NULL, 0), | ||
647 | SND_SOC_DAPM_PGA("PORT2_2_RX", SND_SOC_NOPM, 0, 0, NULL, 0), | ||
648 | |||
649 | SND_SOC_DAPM_SUPPLY("AMIC1Bias", LM49453_P0_MICL_REG, 6, 0, NULL, 0), | ||
650 | SND_SOC_DAPM_SUPPLY("AMIC2Bias", LM49453_P0_MICR_REG, 6, 0, NULL, 0), | ||
651 | |||
652 | /* playback path driver enables */ | ||
653 | SND_SOC_DAPM_OUT_DRV("Headset Switch", | ||
654 | LM49453_P0_PMC_SETUP_REG, 0, 0, NULL, 0), | ||
655 | SND_SOC_DAPM_OUT_DRV("Earpiece Switch", | ||
656 | LM49453_P0_EP_REG, 0, 0, NULL, 0), | ||
657 | SND_SOC_DAPM_OUT_DRV("Speaker Left Switch", | ||
658 | LM49453_P0_DIS_PKVL_FB_REG, 0, 1, NULL, 0), | ||
659 | SND_SOC_DAPM_OUT_DRV("Speaker Right Switch", | ||
660 | LM49453_P0_DIS_PKVL_FB_REG, 1, 1, NULL, 0), | ||
661 | SND_SOC_DAPM_OUT_DRV("Haptic Left Switch", | ||
662 | LM49453_P0_DIS_PKVL_FB_REG, 2, 1, NULL, 0), | ||
663 | SND_SOC_DAPM_OUT_DRV("Haptic Right Switch", | ||
664 | LM49453_P0_DIS_PKVL_FB_REG, 3, 1, NULL, 0), | ||
665 | |||
666 | /* DAC */ | ||
667 | SND_SOC_DAPM_DAC("HPL DAC", "Headset", SND_SOC_NOPM, 0, 0), | ||
668 | SND_SOC_DAPM_DAC("HPR DAC", "Headset", SND_SOC_NOPM, 0, 0), | ||
669 | SND_SOC_DAPM_DAC("LSL DAC", "Speaker", SND_SOC_NOPM, 0, 0), | ||
670 | SND_SOC_DAPM_DAC("LSR DAC", "Speaker", SND_SOC_NOPM, 0, 0), | ||
671 | SND_SOC_DAPM_DAC("HAL DAC", "Haptic", SND_SOC_NOPM, 0, 0), | ||
672 | SND_SOC_DAPM_DAC("HAR DAC", "Haptic", SND_SOC_NOPM, 0, 0), | ||
673 | SND_SOC_DAPM_DAC("LOL DAC", "Lineout", SND_SOC_NOPM, 0, 0), | ||
674 | SND_SOC_DAPM_DAC("LOR DAC", "Lineout", SND_SOC_NOPM, 0, 0), | ||
675 | |||
676 | |||
677 | SND_SOC_DAPM_PGA("AUXL Input", | ||
678 | LM49453_P0_ANALOG_MIXER_ADC_REG, 2, 0, NULL, 0), | ||
679 | SND_SOC_DAPM_PGA("AUXR Input", | ||
680 | LM49453_P0_ANALOG_MIXER_ADC_REG, 3, 0, NULL, 0), | ||
681 | |||
682 | SND_SOC_DAPM_PGA("Sidetone", SND_SOC_NOPM, 0, 0, NULL, 0), | ||
683 | |||
684 | /* ADC */ | ||
685 | SND_SOC_DAPM_ADC("DMIC1 Left", "Capture", SND_SOC_NOPM, 1, 0), | ||
686 | SND_SOC_DAPM_ADC("DMIC1 Right", "Capture", SND_SOC_NOPM, 1, 0), | ||
687 | SND_SOC_DAPM_ADC("DMIC2 Left", "Capture", SND_SOC_NOPM, 1, 0), | ||
688 | SND_SOC_DAPM_ADC("DMIC2 Right", "Capture", SND_SOC_NOPM, 1, 0), | ||
689 | |||
690 | SND_SOC_DAPM_ADC("ADC Left", "Capture", SND_SOC_NOPM, 1, 0), | ||
691 | SND_SOC_DAPM_ADC("ADC Right", "Capture", SND_SOC_NOPM, 0, 0), | ||
692 | |||
693 | SND_SOC_DAPM_MUX("ADCL Mux", SND_SOC_NOPM, 0, 0, | ||
694 | &lm49453_adcl_mux_control), | ||
695 | SND_SOC_DAPM_MUX("ADCR Mux", SND_SOC_NOPM, 0, 0, | ||
696 | &lm49453_adcr_mux_control), | ||
697 | |||
698 | SND_SOC_DAPM_MUX("Mic1 Input", | ||
699 | SND_SOC_NOPM, 0, 0, &lm49453_adcl_mux_control), | ||
700 | |||
701 | SND_SOC_DAPM_MUX("Mic2 Input", | ||
702 | SND_SOC_NOPM, 0, 0, &lm49453_adcr_mux_control), | ||
703 | |||
704 | /* AIF */ | ||
705 | SND_SOC_DAPM_AIF_IN("PORT1_SDI", NULL, 0, | ||
706 | LM49453_P0_PULL_CONFIG1_REG, 2, 0), | ||
707 | SND_SOC_DAPM_AIF_IN("PORT2_SDI", NULL, 0, | ||
708 | LM49453_P0_PULL_CONFIG1_REG, 6, 0), | ||
709 | |||
710 | SND_SOC_DAPM_AIF_OUT("PORT1_SDO", NULL, 0, | ||
711 | LM49453_P0_PULL_CONFIG1_REG, 3, 0), | ||
712 | SND_SOC_DAPM_AIF_OUT("PORT2_SDO", NULL, 0, | ||
713 | LM49453_P0_PULL_CONFIG1_REG, 7, 0), | ||
714 | |||
715 | /* Port1 TX controls */ | ||
716 | SND_SOC_DAPM_OUT_DRV("P1_1_TX", SND_SOC_NOPM, 0, 0, NULL, 0), | ||
717 | SND_SOC_DAPM_OUT_DRV("P1_2_TX", SND_SOC_NOPM, 0, 0, NULL, 0), | ||
718 | SND_SOC_DAPM_OUT_DRV("P1_3_TX", SND_SOC_NOPM, 0, 0, NULL, 0), | ||
719 | SND_SOC_DAPM_OUT_DRV("P1_4_TX", SND_SOC_NOPM, 0, 0, NULL, 0), | ||
720 | SND_SOC_DAPM_OUT_DRV("P1_5_TX", SND_SOC_NOPM, 0, 0, NULL, 0), | ||
721 | SND_SOC_DAPM_OUT_DRV("P1_6_TX", SND_SOC_NOPM, 0, 0, NULL, 0), | ||
722 | SND_SOC_DAPM_OUT_DRV("P1_7_TX", SND_SOC_NOPM, 0, 0, NULL, 0), | ||
723 | SND_SOC_DAPM_OUT_DRV("P1_8_TX", SND_SOC_NOPM, 0, 0, NULL, 0), | ||
724 | |||
725 | /* Port2 TX controls */ | ||
726 | SND_SOC_DAPM_OUT_DRV("P2_1_TX", SND_SOC_NOPM, 0, 0, NULL, 0), | ||
727 | SND_SOC_DAPM_OUT_DRV("P2_2_TX", SND_SOC_NOPM, 0, 0, NULL, 0), | ||
728 | |||
729 | /* Sidetone Mixer */ | ||
730 | SND_SOC_DAPM_MIXER("Sidetone Mixer", SND_SOC_NOPM, 0, 0, | ||
731 | lm49453_sidetone_mixer_controls, | ||
732 | ARRAY_SIZE(lm49453_sidetone_mixer_controls)), | ||
733 | |||
734 | /* DAC MIXERS */ | ||
735 | SND_SOC_DAPM_MIXER("HPL Mixer", SND_SOC_NOPM, 0, 0, | ||
736 | lm49453_headset_left_mixer, | ||
737 | ARRAY_SIZE(lm49453_headset_left_mixer)), | ||
738 | SND_SOC_DAPM_MIXER("HPR Mixer", SND_SOC_NOPM, 0, 0, | ||
739 | lm49453_headset_right_mixer, | ||
740 | ARRAY_SIZE(lm49453_headset_right_mixer)), | ||
741 | SND_SOC_DAPM_MIXER("LOL Mixer", SND_SOC_NOPM, 0, 0, | ||
742 | lm49453_lineout_left_mixer, | ||
743 | ARRAY_SIZE(lm49453_lineout_left_mixer)), | ||
744 | SND_SOC_DAPM_MIXER("LOR Mixer", SND_SOC_NOPM, 0, 0, | ||
745 | lm49453_lineout_right_mixer, | ||
746 | ARRAY_SIZE(lm49453_lineout_right_mixer)), | ||
747 | SND_SOC_DAPM_MIXER("LSL Mixer", SND_SOC_NOPM, 0, 0, | ||
748 | lm49453_speaker_left_mixer, | ||
749 | ARRAY_SIZE(lm49453_speaker_left_mixer)), | ||
750 | SND_SOC_DAPM_MIXER("LSR Mixer", SND_SOC_NOPM, 0, 0, | ||
751 | lm49453_speaker_right_mixer, | ||
752 | ARRAY_SIZE(lm49453_speaker_right_mixer)), | ||
753 | SND_SOC_DAPM_MIXER("HAL Mixer", SND_SOC_NOPM, 0, 0, | ||
754 | lm49453_haptic_left_mixer, | ||
755 | ARRAY_SIZE(lm49453_haptic_left_mixer)), | ||
756 | SND_SOC_DAPM_MIXER("HAR Mixer", SND_SOC_NOPM, 0, 0, | ||
757 | lm49453_haptic_right_mixer, | ||
758 | ARRAY_SIZE(lm49453_haptic_right_mixer)), | ||
759 | |||
760 | /* Capture Mixer */ | ||
761 | SND_SOC_DAPM_MIXER("Port1_1 Mixer", SND_SOC_NOPM, 0, 0, | ||
762 | lm49453_port1_tx1_mixer, | ||
763 | ARRAY_SIZE(lm49453_port1_tx1_mixer)), | ||
764 | SND_SOC_DAPM_MIXER("Port1_2 Mixer", SND_SOC_NOPM, 0, 0, | ||
765 | lm49453_port1_tx2_mixer, | ||
766 | ARRAY_SIZE(lm49453_port1_tx2_mixer)), | ||
767 | SND_SOC_DAPM_MIXER("Port1_3 Mixer", SND_SOC_NOPM, 0, 0, | ||
768 | lm49453_port1_tx3_mixer, | ||
769 | ARRAY_SIZE(lm49453_port1_tx3_mixer)), | ||
770 | SND_SOC_DAPM_MIXER("Port1_4 Mixer", SND_SOC_NOPM, 0, 0, | ||
771 | lm49453_port1_tx4_mixer, | ||
772 | ARRAY_SIZE(lm49453_port1_tx4_mixer)), | ||
773 | SND_SOC_DAPM_MIXER("Port1_5 Mixer", SND_SOC_NOPM, 0, 0, | ||
774 | lm49453_port1_tx5_mixer, | ||
775 | ARRAY_SIZE(lm49453_port1_tx5_mixer)), | ||
776 | SND_SOC_DAPM_MIXER("Port1_6 Mixer", SND_SOC_NOPM, 0, 0, | ||
777 | lm49453_port1_tx6_mixer, | ||
778 | ARRAY_SIZE(lm49453_port1_tx6_mixer)), | ||
779 | SND_SOC_DAPM_MIXER("Port1_7 Mixer", SND_SOC_NOPM, 0, 0, | ||
780 | lm49453_port1_tx7_mixer, | ||
781 | ARRAY_SIZE(lm49453_port1_tx7_mixer)), | ||
782 | SND_SOC_DAPM_MIXER("Port1_8 Mixer", SND_SOC_NOPM, 0, 0, | ||
783 | lm49453_port1_tx8_mixer, | ||
784 | ARRAY_SIZE(lm49453_port1_tx8_mixer)), | ||
785 | |||
786 | SND_SOC_DAPM_MIXER("Port2_1 Mixer", SND_SOC_NOPM, 0, 0, | ||
787 | lm49453_port2_tx1_mixer, | ||
788 | ARRAY_SIZE(lm49453_port2_tx1_mixer)), | ||
789 | SND_SOC_DAPM_MIXER("Port2_2 Mixer", SND_SOC_NOPM, 0, 0, | ||
790 | lm49453_port2_tx2_mixer, | ||
791 | ARRAY_SIZE(lm49453_port2_tx2_mixer)), | ||
792 | }; | ||
793 | |||
794 | static const struct snd_soc_dapm_route lm49453_audio_map[] = { | ||
795 | /* Port SDI mapping */ | ||
796 | { "PORT1_1_RX", "Port1 Playback Switch", "PORT1_SDI" }, | ||
797 | { "PORT1_2_RX", "Port1 Playback Switch", "PORT1_SDI" }, | ||
798 | { "PORT1_3_RX", "Port1 Playback Switch", "PORT1_SDI" }, | ||
799 | { "PORT1_4_RX", "Port1 Playback Switch", "PORT1_SDI" }, | ||
800 | { "PORT1_5_RX", "Port1 Playback Switch", "PORT1_SDI" }, | ||
801 | { "PORT1_6_RX", "Port1 Playback Switch", "PORT1_SDI" }, | ||
802 | { "PORT1_7_RX", "Port1 Playback Switch", "PORT1_SDI" }, | ||
803 | { "PORT1_8_RX", "Port1 Playback Switch", "PORT1_SDI" }, | ||
804 | |||
805 | { "PORT2_1_RX", "Port2 Playback Switch", "PORT2_SDI" }, | ||
806 | { "PORT2_2_RX", "Port2 Playback Switch", "PORT2_SDI" }, | ||
807 | |||
808 | /* HP mapping */ | ||
809 | { "HPL Mixer", "Port1_1 Switch", "PORT1_1_RX" }, | ||
810 | { "HPL Mixer", "Port1_2 Switch", "PORT1_2_RX" }, | ||
811 | { "HPL Mixer", "Port1_3 Switch", "PORT1_3_RX" }, | ||
812 | { "HPL Mixer", "Port1_4 Switch", "PORT1_4_RX" }, | ||
813 | { "HPL Mixer", "Port1_5 Switch", "PORT1_5_RX" }, | ||
814 | { "HPL Mixer", "Port1_6 Switch", "PORT1_6_RX" }, | ||
815 | { "HPL Mixer", "Port1_7 Switch", "PORT1_7_RX" }, | ||
816 | { "HPL Mixer", "Port1_8 Switch", "PORT1_8_RX" }, | ||
817 | |||
818 | { "HPL Mixer", "Port2_1 Switch", "PORT2_1_RX" }, | ||
819 | { "HPL Mixer", "Port2_2 Switch", "PORT2_2_RX" }, | ||
820 | |||
821 | { "HPL Mixer", "ADCL Switch", "ADC Left" }, | ||
822 | { "HPL Mixer", "ADCR Switch", "ADC Right" }, | ||
823 | { "HPL Mixer", "DMIC1L Switch", "DMIC1 Left" }, | ||
824 | { "HPL Mixer", "DMIC1R Switch", "DMIC1 Right" }, | ||
825 | { "HPL Mixer", "DMIC2L Switch", "DMIC2 Left" }, | ||
826 | { "HPL Mixer", "DMIC2R Switch", "DMIC2 Right" }, | ||
827 | { "HPL Mixer", "Sidetone Switch", "Sidetone" }, | ||
828 | |||
829 | { "HPL DAC", NULL, "HPL Mixer" }, | ||
830 | |||
831 | { "HPR Mixer", "Port1_1 Switch", "PORT1_1_RX" }, | ||
832 | { "HPR Mixer", "Port1_2 Switch", "PORT1_2_RX" }, | ||
833 | { "HPR Mixer", "Port1_3 Switch", "PORT1_3_RX" }, | ||
834 | { "HPR Mixer", "Port1_4 Switch", "PORT1_4_RX" }, | ||
835 | { "HPR Mixer", "Port1_5 Switch", "PORT1_5_RX" }, | ||
836 | { "HPR Mixer", "Port1_6 Switch", "PORT1_6_RX" }, | ||
837 | { "HPR Mixer", "Port1_7 Switch", "PORT1_7_RX" }, | ||
838 | { "HPR Mixer", "Port1_8 Switch", "PORT1_8_RX" }, | ||
839 | |||
840 | /* Port 2 */ | ||
841 | { "HPR Mixer", "Port2_1 Switch", "PORT2_1_RX" }, | ||
842 | { "HPR Mixer", "Port2_2 Switch", "PORT2_2_RX" }, | ||
843 | |||
844 | { "HPR Mixer", "ADCL Switch", "ADC Left" }, | ||
845 | { "HPR Mixer", "ADCR Switch", "ADC Right" }, | ||
846 | { "HPR Mixer", "DMIC1L Switch", "DMIC1 Left" }, | ||
847 | { "HPR Mixer", "DMIC1R Switch", "DMIC1 Right" }, | ||
848 | { "HPR Mixer", "DMIC2L Switch", "DMIC2 Left" }, | ||
849 | { "HPR Mixer", "DMIC2L Switch", "DMIC2 Right" }, | ||
850 | { "HPR Mixer", "Sidetone Switch", "Sidetone" }, | ||
851 | |||
852 | { "HPR DAC", NULL, "HPR Mixer" }, | ||
853 | |||
854 | { "HPOUTL", "Headset Switch", "HPL DAC"}, | ||
855 | { "HPOUTR", "Headset Switch", "HPR DAC"}, | ||
856 | |||
857 | /* EP map */ | ||
858 | { "EPOUT", "Earpiece Switch", "HPL DAC" }, | ||
859 | |||
860 | /* Speaker map */ | ||
861 | { "LSL Mixer", "Port1_1 Switch", "PORT1_1_RX" }, | ||
862 | { "LSL Mixer", "Port1_2 Switch", "PORT1_2_RX" }, | ||
863 | { "LSL Mixer", "Port1_3 Switch", "PORT1_3_RX" }, | ||
864 | { "LSL Mixer", "Port1_4 Switch", "PORT1_4_RX" }, | ||
865 | { "LSL Mixer", "Port1_5 Switch", "PORT1_5_RX" }, | ||
866 | { "LSL Mixer", "Port1_6 Switch", "PORT1_6_RX" }, | ||
867 | { "LSL Mixer", "Port1_7 Switch", "PORT1_7_RX" }, | ||
868 | { "LSL Mixer", "Port1_8 Switch", "PORT1_8_RX" }, | ||
869 | |||
870 | /* Port 2 */ | ||
871 | { "LSL Mixer", "Port2_1 Switch", "PORT2_1_RX" }, | ||
872 | { "LSL Mixer", "Port2_2 Switch", "PORT2_2_RX" }, | ||
873 | |||
874 | { "LSL Mixer", "ADCL Switch", "ADC Left" }, | ||
875 | { "LSL Mixer", "ADCR Switch", "ADC Right" }, | ||
876 | { "LSL Mixer", "DMIC1L Switch", "DMIC1 Left" }, | ||
877 | { "LSL Mixer", "DMIC1R Switch", "DMIC1 Right" }, | ||
878 | { "LSL Mixer", "DMIC2L Switch", "DMIC2 Left" }, | ||
879 | { "LSL Mixer", "DMIC2R Switch", "DMIC2 Right" }, | ||
880 | { "LSL Mixer", "Sidetone Switch", "Sidetone" }, | ||
881 | |||
882 | { "LSL DAC", NULL, "LSL Mixer" }, | ||
883 | |||
884 | { "LSR Mixer", "Port1_1 Switch", "PORT1_1_RX" }, | ||
885 | { "LSR Mixer", "Port1_2 Switch", "PORT1_2_RX" }, | ||
886 | { "LSR Mixer", "Port1_3 Switch", "PORT1_3_RX" }, | ||
887 | { "LSR Mixer", "Port1_4 Switch", "PORT1_4_RX" }, | ||
888 | { "LSR Mixer", "Port1_5 Switch", "PORT1_5_RX" }, | ||
889 | { "LSR Mixer", "Port1_6 Switch", "PORT1_6_RX" }, | ||
890 | { "LSR Mixer", "Port1_7 Switch", "PORT1_7_RX" }, | ||
891 | { "LSR Mixer", "Port1_8 Switch", "PORT1_8_RX" }, | ||
892 | |||
893 | /* Port 2 */ | ||
894 | { "LSR Mixer", "Port2_1 Switch", "PORT2_1_RX" }, | ||
895 | { "LSR Mixer", "Port2_2 Switch", "PORT2_2_RX" }, | ||
896 | |||
897 | { "LSR Mixer", "ADCL Switch", "ADC Left" }, | ||
898 | { "LSR Mixer", "ADCR Switch", "ADC Right" }, | ||
899 | { "LSR Mixer", "DMIC1L Switch", "DMIC1 Left" }, | ||
900 | { "LSR Mixer", "DMIC1R Switch", "DMIC1 Right" }, | ||
901 | { "LSR Mixer", "DMIC2L Switch", "DMIC2 Left" }, | ||
902 | { "LSR Mixer", "DMIC2R Switch", "DMIC2 Right" }, | ||
903 | { "LSR Mixer", "Sidetone Switch", "Sidetone" }, | ||
904 | |||
905 | { "LSR DAC", NULL, "LSR Mixer" }, | ||
906 | |||
907 | { "LSOUTL", "Speaker Left Switch", "LSL DAC"}, | ||
908 | { "LSOUTR", "Speaker Left Switch", "LSR DAC"}, | ||
909 | |||
910 | /* Haptic map */ | ||
911 | { "HAL Mixer", "Port1_1 Switch", "PORT1_1_RX" }, | ||
912 | { "HAL Mixer", "Port1_2 Switch", "PORT1_2_RX" }, | ||
913 | { "HAL Mixer", "Port1_3 Switch", "PORT1_3_RX" }, | ||
914 | { "HAL Mixer", "Port1_4 Switch", "PORT1_4_RX" }, | ||
915 | { "HAL Mixer", "Port1_5 Switch", "PORT1_5_RX" }, | ||
916 | { "HAL Mixer", "Port1_6 Switch", "PORT1_6_RX" }, | ||
917 | { "HAL Mixer", "Port1_7 Switch", "PORT1_7_RX" }, | ||
918 | { "HAL Mixer", "Port1_8 Switch", "PORT1_8_RX" }, | ||
919 | |||
920 | /* Port 2 */ | ||
921 | { "HAL Mixer", "Port2_1 Switch", "PORT2_1_RX" }, | ||
922 | { "HAL Mixer", "Port2_2 Switch", "PORT2_2_RX" }, | ||
923 | |||
924 | { "HAL Mixer", "ADCL Switch", "ADC Left" }, | ||
925 | { "HAL Mixer", "ADCR Switch", "ADC Right" }, | ||
926 | { "HAL Mixer", "DMIC1L Switch", "DMIC1 Left" }, | ||
927 | { "HAL Mixer", "DMIC1R Switch", "DMIC1 Right" }, | ||
928 | { "HAL Mixer", "DMIC2L Switch", "DMIC2 Left" }, | ||
929 | { "HAL Mixer", "DMIC2R Switch", "DMIC2 Right" }, | ||
930 | { "HAL Mixer", "Sidetone Switch", "Sidetone" }, | ||
931 | |||
932 | { "HAL DAC", NULL, "HAL Mixer" }, | ||
933 | |||
934 | { "HAR Mixer", "Port1_1 Switch", "PORT1_1_RX" }, | ||
935 | { "HAR Mixer", "Port1_2 Switch", "PORT1_2_RX" }, | ||
936 | { "HAR Mixer", "Port1_3 Switch", "PORT1_3_RX" }, | ||
937 | { "HAR Mixer", "Port1_4 Switch", "PORT1_4_RX" }, | ||
938 | { "HAR Mixer", "Port1_5 Switch", "PORT1_5_RX" }, | ||
939 | { "HAR Mixer", "Port1_6 Switch", "PORT1_6_RX" }, | ||
940 | { "HAR Mixer", "Port1_7 Switch", "PORT1_7_RX" }, | ||
941 | { "HAR Mixer", "Port1_8 Switch", "PORT1_8_RX" }, | ||
942 | |||
943 | /* Port 2 */ | ||
944 | { "HAR Mixer", "Port2_1 Switch", "PORT2_1_RX" }, | ||
945 | { "HAR Mixer", "Port2_2 Switch", "PORT2_2_RX" }, | ||
946 | |||
947 | { "HAR Mixer", "ADCL Switch", "ADC Left" }, | ||
948 | { "HAR Mixer", "ADCR Switch", "ADC Right" }, | ||
949 | { "HAR Mixer", "DMIC1L Switch", "DMIC1 Left" }, | ||
950 | { "HAR Mixer", "DMIC1R Switch", "DMIC1 Right" }, | ||
951 | { "HAR Mixer", "DMIC2L Switch", "DMIC2 Left" }, | ||
952 | { "HAR Mixer", "DMIC2R Switch", "DMIC2 Right" }, | ||
953 | { "HAR Mixer", "Sideton Switch", "Sidetone" }, | ||
954 | |||
955 | { "HAR DAC", NULL, "HAR Mixer" }, | ||
956 | |||
957 | { "HAOUTL", "Haptic Left Switch", "HAL DAC" }, | ||
958 | { "HAOUTR", "Haptic Right Switch", "HAR DAC" }, | ||
959 | |||
960 | /* Lineout map */ | ||
961 | { "LOL Mixer", "Port1_1 Switch", "PORT1_1_RX" }, | ||
962 | { "LOL Mixer", "Port1_2 Switch", "PORT1_2_RX" }, | ||
963 | { "LOL Mixer", "Port1_3 Switch", "PORT1_3_RX" }, | ||
964 | { "LOL Mixer", "Port1_4 Switch", "PORT1_4_RX" }, | ||
965 | { "LOL Mixer", "Port1_5 Switch", "PORT1_5_RX" }, | ||
966 | { "LOL Mixer", "Port1_6 Switch", "PORT1_6_RX" }, | ||
967 | { "LOL Mixer", "Port1_7 Switch", "PORT1_7_RX" }, | ||
968 | { "LOL Mixer", "Port1_8 Switch", "PORT1_8_RX" }, | ||
969 | |||
970 | /* Port 2 */ | ||
971 | { "LOL Mixer", "Port2_1 Switch", "PORT2_1_RX" }, | ||
972 | { "LOL Mixer", "Port2_2 Switch", "PORT2_2_RX" }, | ||
973 | |||
974 | { "LOL Mixer", "ADCL Switch", "ADC Left" }, | ||
975 | { "LOL Mixer", "ADCR Switch", "ADC Right" }, | ||
976 | { "LOL Mixer", "DMIC1L Switch", "DMIC1 Left" }, | ||
977 | { "LOL Mixer", "DMIC1R Switch", "DMIC1 Right" }, | ||
978 | { "LOL Mixer", "DMIC2L Switch", "DMIC2 Left" }, | ||
979 | { "LOL Mixer", "DMIC2R Switch", "DMIC2 Right" }, | ||
980 | { "LOL Mixer", "Sidetone Switch", "Sidetone" }, | ||
981 | |||
982 | { "LOL DAC", NULL, "LOL Mixer" }, | ||
983 | |||
984 | { "LOR Mixer", "Port1_1 Switch", "PORT1_1_RX" }, | ||
985 | { "LOR Mixer", "Port1_2 Switch", "PORT1_2_RX" }, | ||
986 | { "LOR Mixer", "Port1_3 Switch", "PORT1_3_RX" }, | ||
987 | { "LOR Mixer", "Port1_4 Switch", "PORT1_4_RX" }, | ||
988 | { "LOR Mixer", "Port1_5 Switch", "PORT1_5_RX" }, | ||
989 | { "LOR Mixer", "Port1_6 Switch", "PORT1_6_RX" }, | ||
990 | { "LOR Mixer", "Port1_7 Switch", "PORT1_7_RX" }, | ||
991 | { "LOR Mixer", "Port1_8 Switch", "PORT1_8_RX" }, | ||
992 | |||
993 | /* Port 2 */ | ||
994 | { "LOR Mixer", "Port2_1 Switch", "PORT2_1_RX" }, | ||
995 | { "LOR Mixer", "Port2_2 Switch", "PORT2_2_RX" }, | ||
996 | |||
997 | { "LOR Mixer", "ADCL Switch", "ADC Left" }, | ||
998 | { "LOR Mixer", "ADCR Switch", "ADC Right" }, | ||
999 | { "LOR Mixer", "DMIC1L Switch", "DMIC1 Left" }, | ||
1000 | { "LOR Mixer", "DMIC1R Switch", "DMIC1 Right" }, | ||
1001 | { "LOR Mixer", "DMIC2L Switch", "DMIC2 Left" }, | ||
1002 | { "LOR Mixer", "DMIC2R Switch", "DMIC2 Right" }, | ||
1003 | { "LOR Mixer", "Sidetone Switch", "Sidetone" }, | ||
1004 | |||
1005 | { "LOR DAC", NULL, "LOR Mixer" }, | ||
1006 | |||
1007 | { "LOOUTL", NULL, "LOL DAC" }, | ||
1008 | { "LOOUTR", NULL, "LOR DAC" }, | ||
1009 | |||
1010 | /* TX map */ | ||
1011 | /* Port1 mappings */ | ||
1012 | { "Port1_1 Mixer", "ADCL Switch", "ADC Left" }, | ||
1013 | { "Port1_1 Mixer", "ADCR Switch", "ADC Right" }, | ||
1014 | { "Port1_1 Mixer", "DMIC1L Switch", "DMIC1 Left" }, | ||
1015 | { "Port1_1 Mixer", "DMIC1R Switch", "DMIC1 Right" }, | ||
1016 | { "Port1_1 Mixer", "DMIC2L Switch", "DMIC2 Left" }, | ||
1017 | { "Port1_1 Mixer", "DMIC2R Switch", "DMIC2 Right" }, | ||
1018 | |||
1019 | { "Port1_2 Mixer", "ADCL Switch", "ADC Left" }, | ||
1020 | { "Port1_2 Mixer", "ADCR Switch", "ADC Right" }, | ||
1021 | { "Port1_2 Mixer", "DMIC1L Switch", "DMIC1 Left" }, | ||
1022 | { "Port1_2 Mixer", "DMIC1R Switch", "DMIC1 Right" }, | ||
1023 | { "Port1_2 Mixer", "DMIC2L Switch", "DMIC2 Left" }, | ||
1024 | { "Port1_2 Mixer", "DMIC2R Switch", "DMIC2 Right" }, | ||
1025 | |||
1026 | { "Port1_3 Mixer", "ADCL Switch", "ADC Left" }, | ||
1027 | { "Port1_3 Mixer", "ADCR Switch", "ADC Right" }, | ||
1028 | { "Port1_3 Mixer", "DMIC1L Switch", "DMIC1 Left" }, | ||
1029 | { "Port1_3 Mixer", "DMIC1R Switch", "DMIC1 Right" }, | ||
1030 | { "Port1_3 Mixer", "DMIC2L Switch", "DMIC2 Left" }, | ||
1031 | { "Port1_3 Mixer", "DMIC2R Switch", "DMIC2 Right" }, | ||
1032 | |||
1033 | { "Port1_4 Mixer", "ADCL Switch", "ADC Left" }, | ||
1034 | { "Port1_4 Mixer", "ADCR Switch", "ADC Right" }, | ||
1035 | { "Port1_4 Mixer", "DMIC1L Switch", "DMIC1 Left" }, | ||
1036 | { "Port1_4 Mixer", "DMIC1R Switch", "DMIC1 Right" }, | ||
1037 | { "Port1_4 Mixer", "DMIC2L Switch", "DMIC2 Left" }, | ||
1038 | { "Port1_4 Mixer", "DMIC2R Switch", "DMIC2 Right" }, | ||
1039 | |||
1040 | { "Port1_5 Mixer", "ADCL Switch", "ADC Left" }, | ||
1041 | { "Port1_5 Mixer", "ADCR Switch", "ADC Right" }, | ||
1042 | { "Port1_5 Mixer", "DMIC1L Switch", "DMIC1 Left" }, | ||
1043 | { "Port1_5 Mixer", "DMIC1R Switch", "DMIC1 Right" }, | ||
1044 | { "Port1_5 Mixer", "DMIC2L Switch", "DMIC2 Left" }, | ||
1045 | { "Port1_5 Mixer", "DMIC2R Switch", "DMIC2 Right" }, | ||
1046 | |||
1047 | { "Port1_6 Mixer", "ADCL Switch", "ADC Left" }, | ||
1048 | { "Port1_6 Mixer", "ADCR Switch", "ADC Right" }, | ||
1049 | { "Port1_6 Mixer", "DMIC1L Switch", "DMIC1 Left" }, | ||
1050 | { "Port1_6 Mixer", "DMIC1R Switch", "DMIC1 Right" }, | ||
1051 | { "Port1_6 Mixer", "DMIC2L Switch", "DMIC2 Left" }, | ||
1052 | { "Port1_6 Mixer", "DMIC2R Switch", "DMIC2 Right" }, | ||
1053 | |||
1054 | { "Port1_7 Mixer", "ADCL Switch", "ADC Left" }, | ||
1055 | { "Port1_7 Mixer", "ADCR Switch", "ADC Right" }, | ||
1056 | { "Port1_7 Mixer", "DMIC1L Switch", "DMIC1 Left" }, | ||
1057 | { "Port1_7 Mixer", "DMIC1R Switch", "DMIC1 Right" }, | ||
1058 | { "Port1_7 Mixer", "DMIC2L Switch", "DMIC2 Left" }, | ||
1059 | { "Port1_7 Mixer", "DMIC2R Switch", "DMIC2 Right" }, | ||
1060 | |||
1061 | { "Port1_8 Mixer", "ADCL Switch", "ADC Left" }, | ||
1062 | { "Port1_8 Mixer", "ADCR Switch", "ADC Right" }, | ||
1063 | { "Port1_8 Mixer", "DMIC1L Switch", "DMIC1 Left" }, | ||
1064 | { "Port1_8 Mixer", "DMIC1R Switch", "DMIC1 Right" }, | ||
1065 | { "Port1_8 Mixer", "DMIC2L Switch", "DMIC2 Left" }, | ||
1066 | { "Port1_8 Mixer", "DMIC2R Switch", "DMIC2 Right" }, | ||
1067 | |||
1068 | { "Port2_1 Mixer", "ADCL Switch", "ADC Left" }, | ||
1069 | { "Port2_1 Mixer", "ADCR Switch", "ADC Right" }, | ||
1070 | { "Port2_1 Mixer", "DMIC1L Switch", "DMIC1 Left" }, | ||
1071 | { "Port2_1 Mixer", "DMIC1R Switch", "DMIC1 Right" }, | ||
1072 | { "Port2_1 Mixer", "DMIC2L Switch", "DMIC2 Left" }, | ||
1073 | { "Port2_1 Mixer", "DMIC2R Switch", "DMIC2 Right" }, | ||
1074 | |||
1075 | { "Port2_2 Mixer", "ADCL Switch", "ADC Left" }, | ||
1076 | { "Port2_2 Mixer", "ADCR Switch", "ADC Right" }, | ||
1077 | { "Port2_2 Mixer", "DMIC1L Switch", "DMIC1 Left" }, | ||
1078 | { "Port2_2 Mixer", "DMIC1R Switch", "DMIC1 Right" }, | ||
1079 | { "Port2_2 Mixer", "DMIC2L Switch", "DMIC2 Left" }, | ||
1080 | { "Port2_2 Mixer", "DMIC2R Switch", "DMIC2 Right" }, | ||
1081 | |||
1082 | { "P1_1_TX", NULL, "Port1_1 Mixer" }, | ||
1083 | { "P1_2_TX", NULL, "Port1_2 Mixer" }, | ||
1084 | { "P1_3_TX", NULL, "Port1_3 Mixer" }, | ||
1085 | { "P1_4_TX", NULL, "Port1_4 Mixer" }, | ||
1086 | { "P1_5_TX", NULL, "Port1_5 Mixer" }, | ||
1087 | { "P1_6_TX", NULL, "Port1_6 Mixer" }, | ||
1088 | { "P1_7_TX", NULL, "Port1_7 Mixer" }, | ||
1089 | { "P1_8_TX", NULL, "Port1_8 Mixer" }, | ||
1090 | |||
1091 | { "P2_1_TX", NULL, "Port2_1 Mixer" }, | ||
1092 | { "P2_2_TX", NULL, "Port2_2 Mixer" }, | ||
1093 | |||
1094 | { "PORT1_SDO", "Port1 Capture Switch", "P1_1_TX"}, | ||
1095 | { "PORT1_SDO", "Port1 Capture Switch", "P1_2_TX"}, | ||
1096 | { "PORT1_SDO", "Port1 Capture Switch", "P1_3_TX"}, | ||
1097 | { "PORT1_SDO", "Port1 Capture Switch", "P1_4_TX"}, | ||
1098 | { "PORT1_SDO", "Port1 Capture Switch", "P1_5_TX"}, | ||
1099 | { "PORT1_SDO", "Port1 Capture Switch", "P1_6_TX"}, | ||
1100 | { "PORT1_SDO", "Port1 Capture Switch", "P1_7_TX"}, | ||
1101 | { "PORT1_SDO", "Port1 Capture Switch", "P1_8_TX"}, | ||
1102 | |||
1103 | { "PORT2_SDO", "Port2 Capture Switch", "P2_1_TX"}, | ||
1104 | { "PORT2_SDO", "Port2 Capture Switch", "P2_2_TX"}, | ||
1105 | |||
1106 | { "Mic1 Input", NULL, "AMIC1" }, | ||
1107 | { "Mic2 Input", NULL, "AMIC2" }, | ||
1108 | |||
1109 | { "AUXL Input", NULL, "AUXL" }, | ||
1110 | { "AUXR Input", NULL, "AUXR" }, | ||
1111 | |||
1112 | /* AUX connections */ | ||
1113 | { "ADCL Mux", "Aux_L", "AUXL Input" }, | ||
1114 | { "ADCL Mux", "MIC1", "Mic1 Input" }, | ||
1115 | |||
1116 | { "ADCR Mux", "Aux_R", "AUXR Input" }, | ||
1117 | { "ADCR Mux", "MIC2", "Mic2 Input" }, | ||
1118 | |||
1119 | /* ADC connection */ | ||
1120 | { "ADC Left", NULL, "ADCL Mux"}, | ||
1121 | { "ADC Right", NULL, "ADCR Mux"}, | ||
1122 | |||
1123 | { "DMIC1 Left", NULL, "DMIC1DAT"}, | ||
1124 | { "DMIC1 Right", NULL, "DMIC1DAT"}, | ||
1125 | { "DMIC2 Left", NULL, "DMIC2DAT"}, | ||
1126 | { "DMIC2 Right", NULL, "DMIC2DAT"}, | ||
1127 | |||
1128 | /* Sidetone map */ | ||
1129 | { "Sidetone Mixer", NULL, "ADC Left" }, | ||
1130 | { "Sidetone Mixer", NULL, "ADC Right" }, | ||
1131 | { "Sidetone Mixer", NULL, "DMIC1 Left" }, | ||
1132 | { "Sidetone Mixer", NULL, "DMIC1 Right" }, | ||
1133 | { "Sidetone Mixer", NULL, "DMIC2 Left" }, | ||
1134 | { "Sidetone Mixer", NULL, "DMIC2 Right" }, | ||
1135 | |||
1136 | { "Sidetone", "Sidetone Switch", "Sidetone Mixer" }, | ||
1137 | }; | ||
1138 | |||
1139 | static int lm49453_hw_params(struct snd_pcm_substream *substream, | ||
1140 | struct snd_pcm_hw_params *params, | ||
1141 | struct snd_soc_dai *dai) | ||
1142 | { | ||
1143 | struct snd_soc_codec *codec = dai->codec; | ||
1144 | struct lm49453_priv *lm49453 = snd_soc_codec_get_drvdata(codec); | ||
1145 | u16 clk_div = 0; | ||
1146 | |||
1147 | lm49453->fs_rate = params_rate(params); | ||
1148 | |||
1149 | /* Setting DAC clock dividers based on substream sample rate. */ | ||
1150 | switch (lm49453->fs_rate) { | ||
1151 | case 8000: | ||
1152 | case 16000: | ||
1153 | case 32000: | ||
1154 | case 24000: | ||
1155 | case 48000: | ||
1156 | clk_div = 256; | ||
1157 | break; | ||
1158 | case 11025: | ||
1159 | case 22050: | ||
1160 | case 44100: | ||
1161 | clk_div = 216; | ||
1162 | break; | ||
1163 | case 96000: | ||
1164 | clk_div = 127; | ||
1165 | break; | ||
1166 | default: | ||
1167 | return -EINVAL; | ||
1168 | } | ||
1169 | |||
1170 | snd_soc_write(codec, LM49453_P0_ADC_CLK_DIV_REG, clk_div); | ||
1171 | snd_soc_write(codec, LM49453_P0_DAC_HP_CLK_DIV_REG, clk_div); | ||
1172 | |||
1173 | return 0; | ||
1174 | } | ||
1175 | |||
1176 | static int lm49453_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt) | ||
1177 | { | ||
1178 | struct snd_soc_codec *codec = codec_dai->codec; | ||
1179 | |||
1180 | u16 aif_val; | ||
1181 | int mode = 0; | ||
1182 | int clk_phase = 0; | ||
1183 | int clk_shift = 0; | ||
1184 | |||
1185 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { | ||
1186 | case SND_SOC_DAIFMT_CBS_CFS: | ||
1187 | aif_val = 0; | ||
1188 | break; | ||
1189 | case SND_SOC_DAIFMT_CBS_CFM: | ||
1190 | aif_val = LM49453_AUDIO_PORT1_BASIC_SYNC_MS; | ||
1191 | break; | ||
1192 | case SND_SOC_DAIFMT_CBM_CFS: | ||
1193 | aif_val = LM49453_AUDIO_PORT1_BASIC_CLK_MS; | ||
1194 | break; | ||
1195 | case SND_SOC_DAIFMT_CBM_CFM: | ||
1196 | aif_val = LM49453_AUDIO_PORT1_BASIC_CLK_MS | | ||
1197 | LM49453_AUDIO_PORT1_BASIC_SYNC_MS; | ||
1198 | break; | ||
1199 | default: | ||
1200 | return -EINVAL; | ||
1201 | } | ||
1202 | |||
1203 | |||
1204 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { | ||
1205 | case SND_SOC_DAIFMT_I2S: | ||
1206 | break; | ||
1207 | case SND_SOC_DAIFMT_DSP_A: | ||
1208 | mode = 1; | ||
1209 | clk_phase = (1 << 5); | ||
1210 | clk_shift = 1; | ||
1211 | break; | ||
1212 | case SND_SOC_DAIFMT_DSP_B: | ||
1213 | mode = 1; | ||
1214 | clk_phase = (1 << 5); | ||
1215 | clk_shift = 0; | ||
1216 | break; | ||
1217 | default: | ||
1218 | return -EINVAL; | ||
1219 | } | ||
1220 | |||
1221 | snd_soc_update_bits(codec, LM49453_P0_AUDIO_PORT1_BASIC_REG, | ||
1222 | LM49453_AUDIO_PORT1_BASIC_FMT_MASK|BIT(1)|BIT(5), | ||
1223 | (aif_val | mode | clk_phase)); | ||
1224 | |||
1225 | snd_soc_write(codec, LM49453_P0_AUDIO_PORT1_RX_MSB_REG, clk_shift); | ||
1226 | |||
1227 | return 0; | ||
1228 | } | ||
1229 | |||
1230 | static int lm49453_set_dai_sysclk(struct snd_soc_dai *dai, int clk_id, | ||
1231 | unsigned int freq, int dir) | ||
1232 | { | ||
1233 | struct snd_soc_codec *codec = dai->codec; | ||
1234 | u16 pll_clk = 0; | ||
1235 | |||
1236 | switch (freq) { | ||
1237 | case 12288000: | ||
1238 | case 26000000: | ||
1239 | case 19200000: | ||
1240 | /* pll clk slection */ | ||
1241 | pll_clk = 0; | ||
1242 | break; | ||
1243 | case 48000: | ||
1244 | case 32576: | ||
1245 | /* fll clk slection */ | ||
1246 | pll_clk = BIT(4); | ||
1247 | return 0; | ||
1248 | default: | ||
1249 | return -EINVAL; | ||
1250 | } | ||
1251 | |||
1252 | snd_soc_update_bits(codec, LM49453_P0_PMC_SETUP_REG, BIT(4), pll_clk); | ||
1253 | |||
1254 | return 0; | ||
1255 | } | ||
1256 | |||
1257 | static int lm49453_hp_mute(struct snd_soc_dai *dai, int mute) | ||
1258 | { | ||
1259 | snd_soc_update_bits(dai->codec, LM49453_P0_DAC_DSP_REG, BIT(1)|BIT(0), | ||
1260 | (mute ? (BIT(1)|BIT(0)) : 0)); | ||
1261 | return 0; | ||
1262 | } | ||
1263 | |||
1264 | static int lm49453_lo_mute(struct snd_soc_dai *dai, int mute) | ||
1265 | { | ||
1266 | snd_soc_update_bits(dai->codec, LM49453_P0_DAC_DSP_REG, BIT(3)|BIT(2), | ||
1267 | (mute ? (BIT(3)|BIT(2)) : 0)); | ||
1268 | return 0; | ||
1269 | } | ||
1270 | |||
1271 | static int lm49453_ls_mute(struct snd_soc_dai *dai, int mute) | ||
1272 | { | ||
1273 | snd_soc_update_bits(dai->codec, LM49453_P0_DAC_DSP_REG, BIT(5)|BIT(4), | ||
1274 | (mute ? (BIT(5)|BIT(4)) : 0)); | ||
1275 | return 0; | ||
1276 | } | ||
1277 | |||
1278 | static int lm49453_ep_mute(struct snd_soc_dai *dai, int mute) | ||
1279 | { | ||
1280 | snd_soc_update_bits(dai->codec, LM49453_P0_DAC_DSP_REG, BIT(4), | ||
1281 | (mute ? BIT(4) : 0)); | ||
1282 | return 0; | ||
1283 | } | ||
1284 | |||
1285 | static int lm49453_ha_mute(struct snd_soc_dai *dai, int mute) | ||
1286 | { | ||
1287 | snd_soc_update_bits(dai->codec, LM49453_P0_DAC_DSP_REG, BIT(7)|BIT(6), | ||
1288 | (mute ? (BIT(7)|BIT(6)) : 0)); | ||
1289 | return 0; | ||
1290 | } | ||
1291 | |||
1292 | static int lm49453_set_bias_level(struct snd_soc_codec *codec, | ||
1293 | enum snd_soc_bias_level level) | ||
1294 | { | ||
1295 | struct lm49453_priv *lm49453 = snd_soc_codec_get_drvdata(codec); | ||
1296 | |||
1297 | switch (level) { | ||
1298 | case SND_SOC_BIAS_ON: | ||
1299 | case SND_SOC_BIAS_PREPARE: | ||
1300 | break; | ||
1301 | |||
1302 | case SND_SOC_BIAS_STANDBY: | ||
1303 | if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) | ||
1304 | regcache_sync(lm49453->regmap); | ||
1305 | |||
1306 | snd_soc_update_bits(codec, LM49453_P0_PMC_SETUP_REG, | ||
1307 | LM49453_PMC_SETUP_CHIP_EN, LM49453_CHIP_EN); | ||
1308 | break; | ||
1309 | |||
1310 | case SND_SOC_BIAS_OFF: | ||
1311 | snd_soc_update_bits(codec, LM49453_P0_PMC_SETUP_REG, | ||
1312 | LM49453_PMC_SETUP_CHIP_EN, 0); | ||
1313 | break; | ||
1314 | } | ||
1315 | |||
1316 | codec->dapm.bias_level = level; | ||
1317 | |||
1318 | return 0; | ||
1319 | } | ||
1320 | |||
1321 | /* Formates supported by LM49453 driver. */ | ||
1322 | #define LM49453_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ | ||
1323 | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE) | ||
1324 | |||
1325 | static struct snd_soc_dai_ops lm49453_headset_dai_ops = { | ||
1326 | .hw_params = lm49453_hw_params, | ||
1327 | .set_sysclk = lm49453_set_dai_sysclk, | ||
1328 | .set_fmt = lm49453_set_dai_fmt, | ||
1329 | .digital_mute = lm49453_hp_mute, | ||
1330 | }; | ||
1331 | |||
1332 | static struct snd_soc_dai_ops lm49453_speaker_dai_ops = { | ||
1333 | .hw_params = lm49453_hw_params, | ||
1334 | .set_sysclk = lm49453_set_dai_sysclk, | ||
1335 | .set_fmt = lm49453_set_dai_fmt, | ||
1336 | .digital_mute = lm49453_ls_mute, | ||
1337 | }; | ||
1338 | |||
1339 | static struct snd_soc_dai_ops lm49453_haptic_dai_ops = { | ||
1340 | .hw_params = lm49453_hw_params, | ||
1341 | .set_sysclk = lm49453_set_dai_sysclk, | ||
1342 | .set_fmt = lm49453_set_dai_fmt, | ||
1343 | .digital_mute = lm49453_ha_mute, | ||
1344 | }; | ||
1345 | |||
1346 | static struct snd_soc_dai_ops lm49453_ep_dai_ops = { | ||
1347 | .hw_params = lm49453_hw_params, | ||
1348 | .set_sysclk = lm49453_set_dai_sysclk, | ||
1349 | .set_fmt = lm49453_set_dai_fmt, | ||
1350 | .digital_mute = lm49453_ep_mute, | ||
1351 | }; | ||
1352 | |||
1353 | static struct snd_soc_dai_ops lm49453_lineout_dai_ops = { | ||
1354 | .hw_params = lm49453_hw_params, | ||
1355 | .set_sysclk = lm49453_set_dai_sysclk, | ||
1356 | .set_fmt = lm49453_set_dai_fmt, | ||
1357 | .digital_mute = lm49453_lo_mute, | ||
1358 | }; | ||
1359 | |||
1360 | /* LM49453 dai structure. */ | ||
1361 | static const struct snd_soc_dai_driver lm49453_dai[] = { | ||
1362 | { | ||
1363 | .name = "LM49453 Headset", | ||
1364 | .playback = { | ||
1365 | .stream_name = "Headset", | ||
1366 | .channels_min = 2, | ||
1367 | .channels_max = 2, | ||
1368 | .rates = SNDRV_PCM_RATE_8000_192000, | ||
1369 | .formats = LM49453_FORMATS, | ||
1370 | }, | ||
1371 | .capture = { | ||
1372 | .stream_name = "Capture", | ||
1373 | .channels_min = 1, | ||
1374 | .channels_max = 5, | ||
1375 | .rates = SNDRV_PCM_RATE_8000_192000, | ||
1376 | .formats = LM49453_FORMATS, | ||
1377 | }, | ||
1378 | .ops = &lm49453_headset_dai_ops, | ||
1379 | .symmetric_rates = 1, | ||
1380 | }, | ||
1381 | { | ||
1382 | .name = "LM49453 Speaker", | ||
1383 | .playback = { | ||
1384 | .stream_name = "Speaker", | ||
1385 | .channels_min = 2, | ||
1386 | .channels_max = 2, | ||
1387 | .rates = SNDRV_PCM_RATE_8000_192000, | ||
1388 | .formats = LM49453_FORMATS, | ||
1389 | }, | ||
1390 | .ops = &lm49453_speaker_dai_ops, | ||
1391 | }, | ||
1392 | { | ||
1393 | .name = "LM49453 Haptic", | ||
1394 | .playback = { | ||
1395 | .stream_name = "Haptic", | ||
1396 | .channels_min = 2, | ||
1397 | .channels_max = 2, | ||
1398 | .rates = SNDRV_PCM_RATE_8000_192000, | ||
1399 | .formats = LM49453_FORMATS, | ||
1400 | }, | ||
1401 | .ops = &lm49453_haptic_dai_ops, | ||
1402 | }, | ||
1403 | { | ||
1404 | .name = "LM49453 Earpiece", | ||
1405 | .playback = { | ||
1406 | .stream_name = "Earpiece", | ||
1407 | .channels_min = 1, | ||
1408 | .channels_max = 1, | ||
1409 | .rates = SNDRV_PCM_RATE_8000_192000, | ||
1410 | .formats = LM49453_FORMATS, | ||
1411 | }, | ||
1412 | .ops = &lm49453_ep_dai_ops, | ||
1413 | }, | ||
1414 | { | ||
1415 | .name = "LM49453 line out", | ||
1416 | .playback = { | ||
1417 | .stream_name = "Lineout", | ||
1418 | .channels_min = 2, | ||
1419 | .channels_max = 2, | ||
1420 | .rates = SNDRV_PCM_RATE_8000_192000, | ||
1421 | .formats = LM49453_FORMATS, | ||
1422 | }, | ||
1423 | .ops = &lm49453_lineout_dai_ops, | ||
1424 | }, | ||
1425 | }; | ||
1426 | |||
1427 | static int lm49453_suspend(struct snd_soc_codec *codec) | ||
1428 | { | ||
1429 | lm49453_set_bias_level(codec, SND_SOC_BIAS_OFF); | ||
1430 | return 0; | ||
1431 | } | ||
1432 | |||
1433 | static int lm49453_resume(struct snd_soc_codec *codec) | ||
1434 | { | ||
1435 | lm49453_set_bias_level(codec, SND_SOC_BIAS_STANDBY); | ||
1436 | return 0; | ||
1437 | } | ||
1438 | |||
1439 | static int lm49453_probe(struct snd_soc_codec *codec) | ||
1440 | { | ||
1441 | struct lm49453_priv *lm49453 = snd_soc_codec_get_drvdata(codec); | ||
1442 | int ret = 0; | ||
1443 | |||
1444 | codec->control_data = lm49453->regmap; | ||
1445 | |||
1446 | ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_REGMAP); | ||
1447 | if (ret < 0) { | ||
1448 | dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); | ||
1449 | return ret; | ||
1450 | } | ||
1451 | |||
1452 | return 0; | ||
1453 | } | ||
1454 | |||
1455 | /* power down chip */ | ||
1456 | static int lm49453_remove(struct snd_soc_codec *codec) | ||
1457 | { | ||
1458 | lm49453_set_bias_level(codec, SND_SOC_BIAS_OFF); | ||
1459 | return 0; | ||
1460 | } | ||
1461 | |||
1462 | static struct snd_soc_codec_driver soc_codec_dev_lm49453 = { | ||
1463 | .probe = lm49453_probe, | ||
1464 | .remove = lm49453_remove, | ||
1465 | .suspend = lm49453_suspend, | ||
1466 | .resume = lm49453_resume, | ||
1467 | .set_bias_level = lm49453_set_bias_level, | ||
1468 | .controls = lm49453_snd_controls, | ||
1469 | .num_controls = ARRAY_SIZE(lm49453_snd_controls), | ||
1470 | .dapm_widgets = lm49453_dapm_widgets, | ||
1471 | .num_dapm_widgets = ARRAY_SIZE(lm49453_dapm_widgets), | ||
1472 | .dapm_routes = lm49453_audio_map, | ||
1473 | .num_dapm_routes = ARRAY_SIZE(lm49453_audio_map), | ||
1474 | .idle_bias_off = true, | ||
1475 | }; | ||
1476 | |||
1477 | static const struct regmap_config lm49453_regmap_config = { | ||
1478 | .reg_bits = 8, | ||
1479 | .val_bits = 8, | ||
1480 | |||
1481 | .max_register = LM49453_MAX_REGISTER, | ||
1482 | .reg_defaults = lm49453_reg_defs, | ||
1483 | .num_reg_defaults = ARRAY_SIZE(lm49453_reg_defs), | ||
1484 | .cache_type = REGCACHE_RBTREE, | ||
1485 | }; | ||
1486 | |||
1487 | static __devinit int lm49453_i2c_probe(struct i2c_client *i2c, | ||
1488 | const struct i2c_device_id *id) | ||
1489 | { | ||
1490 | struct lm49453_priv *lm49453; | ||
1491 | int ret = 0; | ||
1492 | |||
1493 | lm49453 = devm_kzalloc(&i2c->dev, sizeof(struct lm49453_priv), | ||
1494 | GFP_KERNEL); | ||
1495 | |||
1496 | if (lm49453 == NULL) | ||
1497 | return -ENOMEM; | ||
1498 | |||
1499 | i2c_set_clientdata(i2c, lm49453); | ||
1500 | |||
1501 | lm49453->regmap = regmap_init_i2c(i2c, &lm49453_regmap_config); | ||
1502 | if (IS_ERR(lm49453->regmap)) { | ||
1503 | ret = PTR_ERR(lm49453->regmap); | ||
1504 | dev_err(&i2c->dev, "Failed to allocate register map: %d\n", | ||
1505 | ret); | ||
1506 | return ret; | ||
1507 | } | ||
1508 | |||
1509 | ret = snd_soc_register_codec(&i2c->dev, | ||
1510 | &soc_codec_dev_lm49453, | ||
1511 | lm49453_dai, ARRAY_SIZE(lm49453_dai)); | ||
1512 | if (ret < 0) { | ||
1513 | dev_err(&i2c->dev, "Failed to register codec: %d\n", ret); | ||
1514 | regmap_exit(lm49453->regmap); | ||
1515 | return ret; | ||
1516 | } | ||
1517 | |||
1518 | return ret; | ||
1519 | } | ||
1520 | |||
1521 | static int __devexit lm49453_i2c_remove(struct i2c_client *client) | ||
1522 | { | ||
1523 | struct lm49453_priv *lm49453 = i2c_get_clientdata(client); | ||
1524 | |||
1525 | snd_soc_unregister_codec(&client->dev); | ||
1526 | regmap_exit(lm49453->regmap); | ||
1527 | return 0; | ||
1528 | } | ||
1529 | |||
1530 | static const struct i2c_device_id lm49453_i2c_id[] = { | ||
1531 | { "lm49453", 0 }, | ||
1532 | { } | ||
1533 | }; | ||
1534 | MODULE_DEVICE_TABLE(i2c, lm49453_i2c_id); | ||
1535 | |||
1536 | static struct i2c_driver lm49453_i2c_driver = { | ||
1537 | .driver = { | ||
1538 | .name = "lm49453", | ||
1539 | .owner = THIS_MODULE, | ||
1540 | }, | ||
1541 | .probe = lm49453_i2c_probe, | ||
1542 | .remove = __devexit_p(lm49453_i2c_remove), | ||
1543 | .id_table = lm49453_i2c_id, | ||
1544 | }; | ||
1545 | |||
1546 | module_i2c_driver(lm49453_i2c_driver); | ||
1547 | |||
1548 | MODULE_DESCRIPTION("ASoC LM49453 driver"); | ||
1549 | MODULE_AUTHOR("M R Swami Reddy <MR.Swami.Reddy@ti.com>"); | ||
1550 | MODULE_LICENSE("GPL v2"); | ||
diff --git a/sound/soc/codecs/lm49453.h b/sound/soc/codecs/lm49453.h new file mode 100644 index 000000000000..a63cfa5c0883 --- /dev/null +++ b/sound/soc/codecs/lm49453.h | |||
@@ -0,0 +1,380 @@ | |||
1 | /* | ||
2 | * lm49453.h - LM49453 ALSA Soc Audio drive | ||
3 | * | ||
4 | * Copyright (c) 2012 Texas Instruments, Inc | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; version 2 of the License. | ||
9 | * | ||
10 | */ | ||
11 | |||
12 | #ifndef _LM49453_H | ||
13 | #define _LM49453_H | ||
14 | |||
15 | #include <linux/bitops.h> | ||
16 | |||
17 | /* LM49453_P0 register space for page0 */ | ||
18 | #define LM49453_P0_PMC_SETUP_REG 0x00 | ||
19 | #define LM49453_P0_PLL_CLK_SEL1_REG 0x01 | ||
20 | #define LM49453_P0_PLL_CLK_SEL2_REG 0x02 | ||
21 | #define LM49453_P0_PMC_CLK_DIV_REG 0x03 | ||
22 | #define LM49453_P0_HSDET_CLK_DIV_REG 0x04 | ||
23 | #define LM49453_P0_DMIC_CLK_DIV_REG 0x05 | ||
24 | #define LM49453_P0_ADC_CLK_DIV_REG 0x06 | ||
25 | #define LM49453_P0_DAC_OT_CLK_DIV_REG 0x07 | ||
26 | #define LM49453_P0_PLL_HF_M_REG 0x08 | ||
27 | #define LM49453_P0_PLL_LF_M_REG 0x09 | ||
28 | #define LM49453_P0_PLL_NL_REG 0x0A | ||
29 | #define LM49453_P0_PLL_N_MODL_REG 0x0B | ||
30 | #define LM49453_P0_PLL_N_MODH_REG 0x0C | ||
31 | #define LM49453_P0_PLL_P1_REG 0x0D | ||
32 | #define LM49453_P0_PLL_P2_REG 0x0E | ||
33 | #define LM49453_P0_FLL_REF_FREQL_REG 0x0F | ||
34 | #define LM49453_P0_FLL_REF_FREQH_REG 0x10 | ||
35 | #define LM49453_P0_VCO_TARGETLL_REG 0x11 | ||
36 | #define LM49453_P0_VCO_TARGETLH_REG 0x12 | ||
37 | #define LM49453_P0_VCO_TARGETHL_REG 0x13 | ||
38 | #define LM49453_P0_VCO_TARGETHH_REG 0x14 | ||
39 | #define LM49453_P0_PLL_CONFIG_REG 0x15 | ||
40 | #define LM49453_P0_DAC_CLK_SEL_REG 0x16 | ||
41 | #define LM49453_P0_DAC_HP_CLK_DIV_REG 0x17 | ||
42 | |||
43 | /* Analog Mixer Input Stages */ | ||
44 | #define LM49453_P0_MICL_REG 0x20 | ||
45 | #define LM49453_P0_MICR_REG 0x21 | ||
46 | #define LM49453_P0_EP_REG 0x24 | ||
47 | #define LM49453_P0_DIS_PKVL_FB_REG 0x25 | ||
48 | |||
49 | /* Analog Mixer Output Stages */ | ||
50 | #define LM49453_P0_ANALOG_MIXER_ADC_REG 0x2E | ||
51 | |||
52 | /*ADC or DAC */ | ||
53 | #define LM49453_P0_ADC_DSP_REG 0x30 | ||
54 | #define LM49453_P0_DAC_DSP_REG 0x31 | ||
55 | |||
56 | /* EFFECTS ENABLES */ | ||
57 | #define LM49453_P0_ADC_FX_ENABLES_REG 0x33 | ||
58 | |||
59 | /* GPIO */ | ||
60 | #define LM49453_P0_GPIO1_REG 0x38 | ||
61 | #define LM49453_P0_GPIO2_REG 0x39 | ||
62 | #define LM49453_P0_GPIO3_REG 0x3A | ||
63 | #define LM49453_P0_HAP_CTL_REG 0x3B | ||
64 | #define LM49453_P0_HAP_FREQ_PROG_LEFTL_REG 0x3C | ||
65 | #define LM49453_P0_HAP_FREQ_PROG_LEFTH_REG 0x3D | ||
66 | #define LM49453_P0_HAP_FREQ_PROG_RIGHTL_REG 0x3E | ||
67 | #define LM49453_P0_HAP_FREQ_PROG_RIGHTH_REG 0x3F | ||
68 | |||
69 | /* DIGITAL MIXER */ | ||
70 | #define LM49453_P0_DMIX_CLK_SEL_REG 0x40 | ||
71 | #define LM49453_P0_PORT1_RX_LVL1_REG 0x41 | ||
72 | #define LM49453_P0_PORT1_RX_LVL2_REG 0x42 | ||
73 | #define LM49453_P0_PORT2_RX_LVL_REG 0x43 | ||
74 | #define LM49453_P0_PORT1_TX1_REG 0x44 | ||
75 | #define LM49453_P0_PORT1_TX2_REG 0x45 | ||
76 | #define LM49453_P0_PORT1_TX3_REG 0x46 | ||
77 | #define LM49453_P0_PORT1_TX4_REG 0x47 | ||
78 | #define LM49453_P0_PORT1_TX5_REG 0x48 | ||
79 | #define LM49453_P0_PORT1_TX6_REG 0x49 | ||
80 | #define LM49453_P0_PORT1_TX7_REG 0x4A | ||
81 | #define LM49453_P0_PORT1_TX8_REG 0x4B | ||
82 | #define LM49453_P0_PORT2_TX1_REG 0x4C | ||
83 | #define LM49453_P0_PORT2_TX2_REG 0x4D | ||
84 | #define LM49453_P0_STN_SEL_REG 0x4F | ||
85 | #define LM49453_P0_DACHPL1_REG 0x50 | ||
86 | #define LM49453_P0_DACHPL2_REG 0x51 | ||
87 | #define LM49453_P0_DACHPR1_REG 0x52 | ||
88 | #define LM49453_P0_DACHPR2_REG 0x53 | ||
89 | #define LM49453_P0_DACLOL1_REG 0x54 | ||
90 | #define LM49453_P0_DACLOL2_REG 0x55 | ||
91 | #define LM49453_P0_DACLOR1_REG 0x56 | ||
92 | #define LM49453_P0_DACLOR2_REG 0x57 | ||
93 | #define LM49453_P0_DACLSL1_REG 0x58 | ||
94 | #define LM49453_P0_DACLSL2_REG 0x59 | ||
95 | #define LM49453_P0_DACLSR1_REG 0x5A | ||
96 | #define LM49453_P0_DACLSR2_REG 0x5B | ||
97 | #define LM49453_P0_DACHAL1_REG 0x5C | ||
98 | #define LM49453_P0_DACHAL2_REG 0x5D | ||
99 | #define LM49453_P0_DACHAR1_REG 0x5E | ||
100 | #define LM49453_P0_DACHAR2_REG 0x5F | ||
101 | |||
102 | /* AUDIO PORT 1 (TDM) */ | ||
103 | #define LM49453_P0_AUDIO_PORT1_BASIC_REG 0x60 | ||
104 | #define LM49453_P0_AUDIO_PORT1_CLK_GEN1_REG 0x61 | ||
105 | #define LM49453_P0_AUDIO_PORT1_CLK_GEN2_REG 0x62 | ||
106 | #define LM49453_P0_AUDIO_PORT1_CLK_GEN3_REG 0x63 | ||
107 | #define LM49453_P0_AUDIO_PORT1_SYNC_RATE_REG 0x64 | ||
108 | #define LM49453_P0_AUDIO_PORT1_SYNC_SDO_SETUP_REG 0x65 | ||
109 | #define LM49453_P0_AUDIO_PORT1_DATA_WIDTH_REG 0x66 | ||
110 | #define LM49453_P0_AUDIO_PORT1_RX_MSB_REG 0x67 | ||
111 | #define LM49453_P0_AUDIO_PORT1_TX_MSB_REG 0x68 | ||
112 | #define LM49453_P0_AUDIO_PORT1_TDM_CHANNELS_REG 0x69 | ||
113 | |||
114 | /* AUDIO PORT 2 */ | ||
115 | #define LM49453_P0_AUDIO_PORT2_BASIC_REG 0x6A | ||
116 | #define LM49453_P0_AUDIO_PORT2_CLK_GEN1_REG 0x6B | ||
117 | #define LM49453_P0_AUDIO_PORT2_CLK_GEN2_REG 0x6C | ||
118 | #define LM49453_P0_AUDIO_PORT2_SYNC_GEN_REG 0x6D | ||
119 | #define LM49453_P0_AUDIO_PORT2_DATA_WIDTH_REG 0x6E | ||
120 | #define LM49453_P0_AUDIO_PORT2_RX_MODE_REG 0x6F | ||
121 | #define LM49453_P0_AUDIO_PORT2_TX_MODE_REG 0x70 | ||
122 | |||
123 | /* SAMPLE RATE */ | ||
124 | #define LM49453_P0_PORT1_SR_LSB_REG 0x79 | ||
125 | #define LM49453_P0_PORT1_SR_MSB_REG 0x7A | ||
126 | #define LM49453_P0_PORT2_SR_LSB_REG 0x7B | ||
127 | #define LM49453_P0_PORT2_SR_MSB_REG 0x7C | ||
128 | |||
129 | /* EFFECTS - HPFs */ | ||
130 | #define LM49453_P0_HPF_REG 0x80 | ||
131 | |||
132 | /* EFFECTS ADC ALC */ | ||
133 | #define LM49453_P0_ADC_ALC1_REG 0x82 | ||
134 | #define LM49453_P0_ADC_ALC2_REG 0x83 | ||
135 | #define LM49453_P0_ADC_ALC3_REG 0x84 | ||
136 | #define LM49453_P0_ADC_ALC4_REG 0x85 | ||
137 | #define LM49453_P0_ADC_ALC5_REG 0x86 | ||
138 | #define LM49453_P0_ADC_ALC6_REG 0x87 | ||
139 | #define LM49453_P0_ADC_ALC7_REG 0x88 | ||
140 | #define LM49453_P0_ADC_ALC8_REG 0x89 | ||
141 | #define LM49453_P0_DMIC1_LEVELL_REG 0x8A | ||
142 | #define LM49453_P0_DMIC1_LEVELR_REG 0x8B | ||
143 | #define LM49453_P0_DMIC2_LEVELL_REG 0x8C | ||
144 | #define LM49453_P0_DMIC2_LEVELR_REG 0x8D | ||
145 | #define LM49453_P0_ADC_LEVELL_REG 0x8E | ||
146 | #define LM49453_P0_ADC_LEVELR_REG 0x8F | ||
147 | #define LM49453_P0_DAC_HP_LEVELL_REG 0x90 | ||
148 | #define LM49453_P0_DAC_HP_LEVELR_REG 0x91 | ||
149 | #define LM49453_P0_DAC_LO_LEVELL_REG 0x92 | ||
150 | #define LM49453_P0_DAC_LO_LEVELR_REG 0x93 | ||
151 | #define LM49453_P0_DAC_LS_LEVELL_REG 0x94 | ||
152 | #define LM49453_P0_DAC_LS_LEVELR_REG 0x95 | ||
153 | #define LM49453_P0_DAC_HA_LEVELL_REG 0x96 | ||
154 | #define LM49453_P0_DAC_HA_LEVELR_REG 0x97 | ||
155 | #define LM49453_P0_SOFT_MUTE_REG 0x98 | ||
156 | #define LM49453_P0_DMIC_MUTE_CFG_REG 0x99 | ||
157 | #define LM49453_P0_ADC_MUTE_CFG_REG 0x9A | ||
158 | #define LM49453_P0_DAC_MUTE_CFG_REG 0x9B | ||
159 | |||
160 | /*DIGITAL MIC1 */ | ||
161 | #define LM49453_P0_DIGITAL_MIC1_CONFIG_REG 0xB0 | ||
162 | #define LM49453_P0_DIGITAL_MIC1_DATA_DELAYL_REG 0xB1 | ||
163 | #define LM49453_P0_DIGITAL_MIC1_DATA_DELAYR_REG 0xB2 | ||
164 | |||
165 | /*DIGITAL MIC2 */ | ||
166 | #define LM49453_P0_DIGITAL_MIC2_CONFIG_REG 0xB3 | ||
167 | #define LM49453_P0_DIGITAL_MIC2_DATA_DELAYL_REG 0xB4 | ||
168 | #define LM49453_P0_DIGITAL_MIC2_DATA_DELAYR_REG 0xB5 | ||
169 | |||
170 | /* ADC DECIMATOR */ | ||
171 | #define LM49453_P0_ADC_DECIMATOR_REG 0xB6 | ||
172 | |||
173 | /* DAC CONFIGURE */ | ||
174 | #define LM49453_P0_DAC_CONFIG_REG 0xB7 | ||
175 | |||
176 | /* SIDETONE */ | ||
177 | #define LM49453_P0_STN_VOL_ADCL_REG 0xB8 | ||
178 | #define LM49453_P0_STN_VOL_ADCR_REG 0xB9 | ||
179 | #define LM49453_P0_STN_VOL_DMIC1L_REG 0xBA | ||
180 | #define LM49453_P0_STN_VOL_DMIC1R_REG 0xBB | ||
181 | #define LM49453_P0_STN_VOL_DMIC2L_REG 0xBC | ||
182 | #define LM49453_P0_STN_VOL_DMIC2R_REG 0xBD | ||
183 | |||
184 | /* ADC/DAC CLIPPING MONITORS (Read Only/Write to Clear) */ | ||
185 | #define LM49453_P0_ADC_DEC_CLIP_REG 0xC2 | ||
186 | #define LM49453_P0_ADC_HPF_CLIP_REG 0xC3 | ||
187 | #define LM49453_P0_ADC_LVL_CLIP_REG 0xC4 | ||
188 | #define LM49453_P0_DAC_LVL_CLIP_REG 0xC5 | ||
189 | |||
190 | /* ADC ALC EFFECT MONITORS (Read Only) */ | ||
191 | #define LM49453_P0_ADC_LVLMONL_REG 0xC8 | ||
192 | #define LM49453_P0_ADC_LVLMONR_REG 0xC9 | ||
193 | #define LM49453_P0_ADC_ALCMONL_REG 0xCA | ||
194 | #define LM49453_P0_ADC_ALCMONR_REG 0xCB | ||
195 | #define LM49453_P0_ADC_MUTED_REG 0xCC | ||
196 | #define LM49453_P0_DAC_MUTED_REG 0xCD | ||
197 | |||
198 | /* HEADSET DETECT */ | ||
199 | #define LM49453_P0_HSD_PPB_LONG_CNT_LIMITL_REG 0xD0 | ||
200 | #define LM49453_P0_HSD_PPB_LONG_CNT_LIMITR_REG 0xD1 | ||
201 | #define LM49453_P0_HSD_PIN3_4_EX_LOOP_CNT_LIMITL_REG 0xD2 | ||
202 | #define LM49453_P0_HSD_PIN3_4_EX_LOOP_CNT_LIMITH_REG 0xD3 | ||
203 | #define LM49453_P0_HSD_TIMEOUT1_REG 0xD4 | ||
204 | #define LM49453_P0_HSD_TIMEOUT2_REG 0xD5 | ||
205 | #define LM49453_P0_HSD_TIMEOUT3_REG 0xD6 | ||
206 | #define LM49453_P0_HSD_PIN3_4_CFG_REG 0xD7 | ||
207 | #define LM49453_P0_HSD_IRQ1_REG 0xD8 | ||
208 | #define LM49453_P0_HSD_IRQ2_REG 0xD9 | ||
209 | #define LM49453_P0_HSD_IRQ3_REG 0xDA | ||
210 | #define LM49453_P0_HSD_IRQ4_REG 0xDB | ||
211 | #define LM49453_P0_HSD_IRQ_MASK1_REG 0xDC | ||
212 | #define LM49453_P0_HSD_IRQ_MASK2_REG 0xDD | ||
213 | #define LM49453_P0_HSD_IRQ_MASK3_REG 0xDE | ||
214 | #define LM49453_P0_HSD_R_HPLL_REG 0xE0 | ||
215 | #define LM49453_P0_HSD_R_HPLH_REG 0xE1 | ||
216 | #define LM49453_P0_HSD_R_HPLU_REG 0xE2 | ||
217 | #define LM49453_P0_HSD_R_HPRL_REG 0xE3 | ||
218 | #define LM49453_P0_HSD_R_HPRH_REG 0xE4 | ||
219 | #define LM49453_P0_HSD_R_HPRU_REG 0xE5 | ||
220 | #define LM49453_P0_HSD_VEL_L_FINALL_REG 0xE6 | ||
221 | #define LM49453_P0_HSD_VEL_L_FINALH_REG 0xE7 | ||
222 | #define LM49453_P0_HSD_VEL_L_FINALU_REG 0xE8 | ||
223 | #define LM49453_P0_HSD_RO_FINALL_REG 0xE9 | ||
224 | #define LM49453_P0_HSD_RO_FINALH_REG 0xEA | ||
225 | #define LM49453_P0_HSD_RO_FINALU_REG 0xEB | ||
226 | #define LM49453_P0_HSD_VMIC_BIAS_FINALL_REG 0xEC | ||
227 | #define LM49453_P0_HSD_VMIC_BIAS_FINALH_REG 0xED | ||
228 | #define LM49453_P0_HSD_VMIC_BIAS_FINALU_REG 0xEE | ||
229 | #define LM49453_P0_HSD_PIN_CONFIG_REG 0xEF | ||
230 | #define LM49453_P0_HSD_PLUG_DETECT_BB_IRQ_STATUS1_REG 0xF1 | ||
231 | #define LM49453_P0_HSD_PLUG_DETECT_BB_IRQ_STATUS2_REG 0xF2 | ||
232 | #define LM49453_P0_HSD_PLUG_DETECT_BB_IRQ_STATUS3_REG 0xF3 | ||
233 | #define LM49453_P0_HSD_PLUG_DETECT_BB_IRQ_STATEL_REG 0xF4 | ||
234 | #define LM49453_P0_HSD_PLUG_DETECT_BB_IRQ_STATEH_REG 0xF5 | ||
235 | |||
236 | /* I/O PULLDOWN CONFIG */ | ||
237 | #define LM49453_P0_PULL_CONFIG1_REG 0xF8 | ||
238 | #define LM49453_P0_PULL_CONFIG2_REG 0xF9 | ||
239 | #define LM49453_P0_PULL_CONFIG3_REG 0xFA | ||
240 | |||
241 | /* RESET */ | ||
242 | #define LM49453_P0_RESET_REG 0xFE | ||
243 | |||
244 | /* PAGE */ | ||
245 | #define LM49453_PAGE_REG 0xFF | ||
246 | |||
247 | #define LM49453_MAX_REGISTER (0xFF+1) | ||
248 | |||
249 | /* LM49453_P0_PMC_SETUP_REG (0x00h) */ | ||
250 | #define LM49453_PMC_SETUP_CHIP_EN (BIT(1)|BIT(0)) | ||
251 | #define LM49453_PMC_SETUP_PLL_EN BIT(2) | ||
252 | #define LM49453_PMC_SETUP_PLL_P2_EN BIT(3) | ||
253 | #define LM49453_PMC_SETUP_PLL_FLL BIT(4) | ||
254 | #define LM49453_PMC_SETUP_MCLK_OVER BIT(5) | ||
255 | #define LM49453_PMC_SETUP_RTC_CLK_OVER BIT(6) | ||
256 | #define LM49453_PMC_SETUP_CHIP_ACTIVE BIT(7) | ||
257 | |||
258 | /* Chip Enable bits */ | ||
259 | #define LM49453_CHIP_EN_SHUTDOWN 0x00 | ||
260 | #define LM49453_CHIP_EN 0x01 | ||
261 | #define LM49453_CHIP_EN_HSD_DETECT 0x02 | ||
262 | #define LM49453_CHIP_EN_INVALID_HSD 0x03 | ||
263 | |||
264 | /* LM49453_P0_PLL_CLK_SEL1_REG (0x01h) */ | ||
265 | #define LM49453_CLK_SEL1_MCLK_SEL 0x11 | ||
266 | #define LM49453_CLK_SEL1_RTC_SEL 0x11 | ||
267 | #define LM49453_CLK_SEL1_PORT1_SEL 0x10 | ||
268 | #define LM49453_CLK_SEL1_PORT2_SEL 0x11 | ||
269 | |||
270 | /* LM49453_P0_PLL_CLK_SEL2_REG (0x02h) */ | ||
271 | #define LM49453_CLK_SEL2_ADC_CLK_SEL 0x38 | ||
272 | |||
273 | /* LM49453_P0_FLL_REF_FREQL_REG (0x0F) */ | ||
274 | #define LM49453_FLL_REF_FREQ_VAL 0x8ca0001 | ||
275 | |||
276 | /* LM49453_P0_VCO_TARGETLL_REG (0x11) */ | ||
277 | #define LM49453_VCO_TARGET_VAL 0x8ca0001 | ||
278 | |||
279 | /* LM49453_P0_ADC_DSP_REG (0x30h) */ | ||
280 | #define LM49453_ADC_DSP_ADC_MUTEL BIT(0) | ||
281 | #define LM49453_ADC_DSP_ADC_MUTER BIT(1) | ||
282 | #define LM49453_ADC_DSP_DMIC1_MUTEL BIT(2) | ||
283 | #define LM49453_ADC_DSP_DMIC1_MUTER BIT(3) | ||
284 | #define LM49453_ADC_DSP_DMIC2_MUTEL BIT(4) | ||
285 | #define LM49453_ADC_DSP_DMIC2_MUTER BIT(5) | ||
286 | #define LM49453_ADC_DSP_MUTE_ALL 0x3F | ||
287 | |||
288 | /* LM49453_P0_DAC_DSP_REG (0x31h) */ | ||
289 | #define LM49453_DAC_DSP_MUTE_ALL 0xFF | ||
290 | |||
291 | /* LM49453_P0_AUDIO_PORT1_BASIC_REG (0x60h) */ | ||
292 | #define LM49453_AUDIO_PORT1_BASIC_FMT_MASK (BIT(4)|BIT(3)) | ||
293 | #define LM49453_AUDIO_PORT1_BASIC_CLK_MS BIT(3) | ||
294 | #define LM49453_AUDIO_PORT1_BASIC_SYNC_MS BIT(4) | ||
295 | |||
296 | /* LM49453_P0_RESET_REG (0xFEh) */ | ||
297 | #define LM49453_RESET_REG_RST BIT(0) | ||
298 | |||
299 | /* Page select register bits (0xFF) */ | ||
300 | #define LM49453_PAGE0_SELECT 0x0 | ||
301 | #define LM49453_PAGE1_SELECT 0x1 | ||
302 | |||
303 | /* LM49453_P0_HSD_PIN3_4_CFG_REG (Jack Pin config - 0xD7) */ | ||
304 | #define LM49453_JACK_DISABLE 0x00 | ||
305 | #define LM49453_JACK_CONFIG1 0x01 | ||
306 | #define LM49453_JACK_CONFIG2 0x02 | ||
307 | #define LM49453_JACK_CONFIG3 0x03 | ||
308 | #define LM49453_JACK_CONFIG4 0x04 | ||
309 | #define LM49453_JACK_CONFIG5 0x05 | ||
310 | |||
311 | /* Page 1 REGISTERS */ | ||
312 | |||
313 | /* SIDETONE */ | ||
314 | #define LM49453_P1_SIDETONE_SA0L_REG 0x80 | ||
315 | #define LM49453_P1_SIDETONE_SA0H_REG 0x81 | ||
316 | #define LM49453_P1_SIDETONE_SAB0U_REG 0x82 | ||
317 | #define LM49453_P1_SIDETONE_SB0L_REG 0x83 | ||
318 | #define LM49453_P1_SIDETONE_SB0H_REG 0x84 | ||
319 | #define LM49453_P1_SIDETONE_SH0L_REG 0x85 | ||
320 | #define LM49453_P1_SIDETONE_SH0H_REG 0x86 | ||
321 | #define LM49453_P1_SIDETONE_SH0U_REG 0x87 | ||
322 | #define LM49453_P1_SIDETONE_SA1L_REG 0x88 | ||
323 | #define LM49453_P1_SIDETONE_SA1H_REG 0x89 | ||
324 | #define LM49453_P1_SIDETONE_SAB1U_REG 0x8A | ||
325 | #define LM49453_P1_SIDETONE_SB1L_REG 0x8B | ||
326 | #define LM49453_P1_SIDETONE_SB1H_REG 0x8C | ||
327 | #define LM49453_P1_SIDETONE_SH1L_REG 0x8D | ||
328 | #define LM49453_P1_SIDETONE_SH1H_REG 0x8E | ||
329 | #define LM49453_P1_SIDETONE_SH1U_REG 0x8F | ||
330 | #define LM49453_P1_SIDETONE_SA2L_REG 0x90 | ||
331 | #define LM49453_P1_SIDETONE_SA2H_REG 0x91 | ||
332 | #define LM49453_P1_SIDETONE_SAB2U_REG 0x92 | ||
333 | #define LM49453_P1_SIDETONE_SB2L_REG 0x93 | ||
334 | #define LM49453_P1_SIDETONE_SB2H_REG 0x94 | ||
335 | #define LM49453_P1_SIDETONE_SH2L_REG 0x95 | ||
336 | #define LM49453_P1_SIDETONE_SH2H_REG 0x96 | ||
337 | #define LM49453_P1_SIDETONE_SH2U_REG 0x97 | ||
338 | #define LM49453_P1_SIDETONE_SA3L_REG 0x98 | ||
339 | #define LM49453_P1_SIDETONE_SA3H_REG 0x99 | ||
340 | #define LM49453_P1_SIDETONE_SAB3U_REG 0x9A | ||
341 | #define LM49453_P1_SIDETONE_SB3L_REG 0x9B | ||
342 | #define LM49453_P1_SIDETONE_SB3H_REG 0x9C | ||
343 | #define LM49453_P1_SIDETONE_SH3L_REG 0x9D | ||
344 | #define LM49453_P1_SIDETONE_SH3H_REG 0x9E | ||
345 | #define LM49453_P1_SIDETONE_SH3U_REG 0x9F | ||
346 | #define LM49453_P1_SIDETONE_SA4L_REG 0xA0 | ||
347 | #define LM49453_P1_SIDETONE_SA4H_REG 0xA1 | ||
348 | #define LM49453_P1_SIDETONE_SAB4U_REG 0xA2 | ||
349 | #define LM49453_P1_SIDETONE_SB4L_REG 0xA3 | ||
350 | #define LM49453_P1_SIDETONE_SB4H_REG 0xA4 | ||
351 | #define LM49453_P1_SIDETONE_SH4L_REG 0xA5 | ||
352 | #define LM49453_P1_SIDETONE_SH4H_REG 0xA6 | ||
353 | #define LM49453_P1_SIDETONE_SH4U_REG 0xA7 | ||
354 | #define LM49453_P1_SIDETONE_SA5L_REG 0xA8 | ||
355 | #define LM49453_P1_SIDETONE_SA5H_REG 0xA9 | ||
356 | #define LM49453_P1_SIDETONE_SAB5U_REG 0xAA | ||
357 | #define LM49453_P1_SIDETONE_SB5L_REG 0xAB | ||
358 | #define LM49453_P1_SIDETONE_SB5H_REG 0xAC | ||
359 | #define LM49453_P1_SIDETONE_SH5L_REG 0xAD | ||
360 | #define LM49453_P1_SIDETONE_SH5H_REG 0xAE | ||
361 | #define LM49453_P1_SIDETONE_SH5U_REG 0xAF | ||
362 | |||
363 | /* CHARGE PUMP CONFIG */ | ||
364 | #define LM49453_P1_CP_CONFIG1_REG 0xB0 | ||
365 | #define LM49453_P1_CP_CONFIG2_REG 0xB1 | ||
366 | #define LM49453_P1_CP_CONFIG3_REG 0xB2 | ||
367 | #define LM49453_P1_CP_CONFIG4_REG 0xB3 | ||
368 | #define LM49453_P1_CP_LA_VTH1L_REG 0xB4 | ||
369 | #define LM49453_P1_CP_LA_VTH1M_REG 0xB5 | ||
370 | #define LM49453_P1_CP_LA_VTH2L_REG 0xB6 | ||
371 | #define LM49453_P1_CP_LA_VTH2M_REG 0xB7 | ||
372 | #define LM49453_P1_CP_LA_VTH3L_REG 0xB8 | ||
373 | #define LM49453_P1_CP_LA_VTH3H_REG 0xB9 | ||
374 | #define LM49453_P1_CP_CLK_DIV_REG 0xBA | ||
375 | |||
376 | /* DAC */ | ||
377 | #define LM49453_P1_DAC_CHOP_REG 0xC0 | ||
378 | |||
379 | #define LM49453_CLK_SRC_MCLK 1 | ||
380 | #endif | ||
diff --git a/sound/soc/codecs/max98095.c b/sound/soc/codecs/max98095.c index 0bb511a0388d..35179e2c23c9 100644 --- a/sound/soc/codecs/max98095.c +++ b/sound/soc/codecs/max98095.c | |||
@@ -24,6 +24,7 @@ | |||
24 | #include <linux/slab.h> | 24 | #include <linux/slab.h> |
25 | #include <asm/div64.h> | 25 | #include <asm/div64.h> |
26 | #include <sound/max98095.h> | 26 | #include <sound/max98095.h> |
27 | #include <sound/jack.h> | ||
27 | #include "max98095.h" | 28 | #include "max98095.h" |
28 | 29 | ||
29 | enum max98095_type { | 30 | enum max98095_type { |
@@ -51,6 +52,8 @@ struct max98095_priv { | |||
51 | u8 lin_state; | 52 | u8 lin_state; |
52 | unsigned int mic1pre; | 53 | unsigned int mic1pre; |
53 | unsigned int mic2pre; | 54 | unsigned int mic2pre; |
55 | struct snd_soc_jack *headphone_jack; | ||
56 | struct snd_soc_jack *mic_jack; | ||
54 | }; | 57 | }; |
55 | 58 | ||
56 | static const u8 max98095_reg_def[M98095_REG_CNT] = { | 59 | static const u8 max98095_reg_def[M98095_REG_CNT] = { |
@@ -2173,9 +2176,125 @@ static void max98095_handle_pdata(struct snd_soc_codec *codec) | |||
2173 | max98095_handle_bq_pdata(codec); | 2176 | max98095_handle_bq_pdata(codec); |
2174 | } | 2177 | } |
2175 | 2178 | ||
2179 | static irqreturn_t max98095_report_jack(int irq, void *data) | ||
2180 | { | ||
2181 | struct snd_soc_codec *codec = data; | ||
2182 | struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec); | ||
2183 | unsigned int value; | ||
2184 | int hp_report = 0; | ||
2185 | int mic_report = 0; | ||
2186 | |||
2187 | /* Read the Jack Status Register */ | ||
2188 | value = snd_soc_read(codec, M98095_007_JACK_AUTO_STS); | ||
2189 | |||
2190 | /* If ddone is not set, then detection isn't finished yet */ | ||
2191 | if ((value & M98095_DDONE) == 0) | ||
2192 | return IRQ_NONE; | ||
2193 | |||
2194 | /* if hp, check its bit, and if set, clear it */ | ||
2195 | if ((value & M98095_HP_IN || value & M98095_LO_IN) && | ||
2196 | max98095->headphone_jack) | ||
2197 | hp_report |= SND_JACK_HEADPHONE; | ||
2198 | |||
2199 | /* if mic, check its bit, and if set, clear it */ | ||
2200 | if ((value & M98095_MIC_IN) && max98095->mic_jack) | ||
2201 | mic_report |= SND_JACK_MICROPHONE; | ||
2202 | |||
2203 | if (max98095->headphone_jack == max98095->mic_jack) { | ||
2204 | snd_soc_jack_report(max98095->headphone_jack, | ||
2205 | hp_report | mic_report, | ||
2206 | SND_JACK_HEADSET); | ||
2207 | } else { | ||
2208 | if (max98095->headphone_jack) | ||
2209 | snd_soc_jack_report(max98095->headphone_jack, | ||
2210 | hp_report, SND_JACK_HEADPHONE); | ||
2211 | if (max98095->mic_jack) | ||
2212 | snd_soc_jack_report(max98095->mic_jack, | ||
2213 | mic_report, SND_JACK_MICROPHONE); | ||
2214 | } | ||
2215 | |||
2216 | return IRQ_HANDLED; | ||
2217 | } | ||
2218 | |||
2219 | int max98095_jack_detect_enable(struct snd_soc_codec *codec) | ||
2220 | { | ||
2221 | struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec); | ||
2222 | int ret = 0; | ||
2223 | int detect_enable = M98095_JDEN; | ||
2224 | unsigned int slew = M98095_DEFAULT_SLEW_DELAY; | ||
2225 | |||
2226 | if (max98095->pdata->jack_detect_pin5en) | ||
2227 | detect_enable |= M98095_PIN5EN; | ||
2228 | |||
2229 | if (max98095->pdata->jack_detect_delay) | ||
2230 | slew = max98095->pdata->jack_detect_delay; | ||
2231 | |||
2232 | ret = snd_soc_write(codec, M98095_08E_JACK_DC_SLEW, slew); | ||
2233 | if (ret < 0) { | ||
2234 | dev_err(codec->dev, "Failed to cfg auto detect %d\n", ret); | ||
2235 | return ret; | ||
2236 | } | ||
2237 | |||
2238 | /* configure auto detection to be enabled */ | ||
2239 | ret = snd_soc_write(codec, M98095_089_JACK_DET_AUTO, detect_enable); | ||
2240 | if (ret < 0) { | ||
2241 | dev_err(codec->dev, "Failed to cfg auto detect %d\n", ret); | ||
2242 | return ret; | ||
2243 | } | ||
2244 | |||
2245 | return ret; | ||
2246 | } | ||
2247 | |||
2248 | int max98095_jack_detect_disable(struct snd_soc_codec *codec) | ||
2249 | { | ||
2250 | int ret = 0; | ||
2251 | |||
2252 | /* configure auto detection to be disabled */ | ||
2253 | ret = snd_soc_write(codec, M98095_089_JACK_DET_AUTO, 0x0); | ||
2254 | if (ret < 0) { | ||
2255 | dev_err(codec->dev, "Failed to cfg auto detect %d\n", ret); | ||
2256 | return ret; | ||
2257 | } | ||
2258 | |||
2259 | return ret; | ||
2260 | } | ||
2261 | |||
2262 | int max98095_jack_detect(struct snd_soc_codec *codec, | ||
2263 | struct snd_soc_jack *hp_jack, struct snd_soc_jack *mic_jack) | ||
2264 | { | ||
2265 | struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec); | ||
2266 | struct i2c_client *client = to_i2c_client(codec->dev); | ||
2267 | int ret = 0; | ||
2268 | |||
2269 | max98095->headphone_jack = hp_jack; | ||
2270 | max98095->mic_jack = mic_jack; | ||
2271 | |||
2272 | /* only progress if we have at least 1 jack pointer */ | ||
2273 | if (!hp_jack && !mic_jack) | ||
2274 | return -EINVAL; | ||
2275 | |||
2276 | max98095_jack_detect_enable(codec); | ||
2277 | |||
2278 | /* enable interrupts for headphone jack detection */ | ||
2279 | ret = snd_soc_update_bits(codec, M98095_013_JACK_INT_EN, | ||
2280 | M98095_IDDONE, M98095_IDDONE); | ||
2281 | if (ret < 0) { | ||
2282 | dev_err(codec->dev, "Failed to cfg jack irqs %d\n", ret); | ||
2283 | return ret; | ||
2284 | } | ||
2285 | |||
2286 | max98095_report_jack(client->irq, codec); | ||
2287 | return 0; | ||
2288 | } | ||
2289 | |||
2176 | #ifdef CONFIG_PM | 2290 | #ifdef CONFIG_PM |
2177 | static int max98095_suspend(struct snd_soc_codec *codec) | 2291 | static int max98095_suspend(struct snd_soc_codec *codec) |
2178 | { | 2292 | { |
2293 | struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec); | ||
2294 | |||
2295 | if (max98095->headphone_jack || max98095->mic_jack) | ||
2296 | max98095_jack_detect_disable(codec); | ||
2297 | |||
2179 | max98095_set_bias_level(codec, SND_SOC_BIAS_OFF); | 2298 | max98095_set_bias_level(codec, SND_SOC_BIAS_OFF); |
2180 | 2299 | ||
2181 | return 0; | 2300 | return 0; |
@@ -2183,8 +2302,16 @@ static int max98095_suspend(struct snd_soc_codec *codec) | |||
2183 | 2302 | ||
2184 | static int max98095_resume(struct snd_soc_codec *codec) | 2303 | static int max98095_resume(struct snd_soc_codec *codec) |
2185 | { | 2304 | { |
2305 | struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec); | ||
2306 | struct i2c_client *client = to_i2c_client(codec->dev); | ||
2307 | |||
2186 | max98095_set_bias_level(codec, SND_SOC_BIAS_STANDBY); | 2308 | max98095_set_bias_level(codec, SND_SOC_BIAS_STANDBY); |
2187 | 2309 | ||
2310 | if (max98095->headphone_jack || max98095->mic_jack) { | ||
2311 | max98095_jack_detect_enable(codec); | ||
2312 | max98095_report_jack(client->irq, codec); | ||
2313 | } | ||
2314 | |||
2188 | return 0; | 2315 | return 0; |
2189 | } | 2316 | } |
2190 | #else | 2317 | #else |
@@ -2227,6 +2354,7 @@ static int max98095_probe(struct snd_soc_codec *codec) | |||
2227 | { | 2354 | { |
2228 | struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec); | 2355 | struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec); |
2229 | struct max98095_cdata *cdata; | 2356 | struct max98095_cdata *cdata; |
2357 | struct i2c_client *client; | ||
2230 | int ret = 0; | 2358 | int ret = 0; |
2231 | 2359 | ||
2232 | ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_I2C); | 2360 | ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_I2C); |
@@ -2238,6 +2366,8 @@ static int max98095_probe(struct snd_soc_codec *codec) | |||
2238 | /* reset the codec, the DSP core, and disable all interrupts */ | 2366 | /* reset the codec, the DSP core, and disable all interrupts */ |
2239 | max98095_reset(codec); | 2367 | max98095_reset(codec); |
2240 | 2368 | ||
2369 | client = to_i2c_client(codec->dev); | ||
2370 | |||
2241 | /* initialize private data */ | 2371 | /* initialize private data */ |
2242 | 2372 | ||
2243 | max98095->sysclk = (unsigned)-1; | 2373 | max98095->sysclk = (unsigned)-1; |
@@ -2266,11 +2396,23 @@ static int max98095_probe(struct snd_soc_codec *codec) | |||
2266 | max98095->mic1pre = 0; | 2396 | max98095->mic1pre = 0; |
2267 | max98095->mic2pre = 0; | 2397 | max98095->mic2pre = 0; |
2268 | 2398 | ||
2399 | if (client->irq) { | ||
2400 | /* register an audio interrupt */ | ||
2401 | ret = request_threaded_irq(client->irq, NULL, | ||
2402 | max98095_report_jack, | ||
2403 | IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING, | ||
2404 | "max98095", codec); | ||
2405 | if (ret) { | ||
2406 | dev_err(codec->dev, "Failed to request IRQ: %d\n", ret); | ||
2407 | goto err_access; | ||
2408 | } | ||
2409 | } | ||
2410 | |||
2269 | ret = snd_soc_read(codec, M98095_0FF_REV_ID); | 2411 | ret = snd_soc_read(codec, M98095_0FF_REV_ID); |
2270 | if (ret < 0) { | 2412 | if (ret < 0) { |
2271 | dev_err(codec->dev, "Failure reading hardware revision: %d\n", | 2413 | dev_err(codec->dev, "Failure reading hardware revision: %d\n", |
2272 | ret); | 2414 | ret); |
2273 | goto err_access; | 2415 | goto err_irq; |
2274 | } | 2416 | } |
2275 | dev_info(codec->dev, "Hardware revision: %c\n", ret - 0x40 + 'A'); | 2417 | dev_info(codec->dev, "Hardware revision: %c\n", ret - 0x40 + 'A'); |
2276 | 2418 | ||
@@ -2306,14 +2448,28 @@ static int max98095_probe(struct snd_soc_codec *codec) | |||
2306 | 2448 | ||
2307 | max98095_add_widgets(codec); | 2449 | max98095_add_widgets(codec); |
2308 | 2450 | ||
2451 | return 0; | ||
2452 | |||
2453 | err_irq: | ||
2454 | if (client->irq) | ||
2455 | free_irq(client->irq, codec); | ||
2309 | err_access: | 2456 | err_access: |
2310 | return ret; | 2457 | return ret; |
2311 | } | 2458 | } |
2312 | 2459 | ||
2313 | static int max98095_remove(struct snd_soc_codec *codec) | 2460 | static int max98095_remove(struct snd_soc_codec *codec) |
2314 | { | 2461 | { |
2462 | struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec); | ||
2463 | struct i2c_client *client = to_i2c_client(codec->dev); | ||
2464 | |||
2315 | max98095_set_bias_level(codec, SND_SOC_BIAS_OFF); | 2465 | max98095_set_bias_level(codec, SND_SOC_BIAS_OFF); |
2316 | 2466 | ||
2467 | if (max98095->headphone_jack || max98095->mic_jack) | ||
2468 | max98095_jack_detect_disable(codec); | ||
2469 | |||
2470 | if (client->irq) | ||
2471 | free_irq(client->irq, codec); | ||
2472 | |||
2317 | return 0; | 2473 | return 0; |
2318 | } | 2474 | } |
2319 | 2475 | ||
diff --git a/sound/soc/codecs/max98095.h b/sound/soc/codecs/max98095.h index 891584a0eb03..2ebbe4e894bf 100644 --- a/sound/soc/codecs/max98095.h +++ b/sound/soc/codecs/max98095.h | |||
@@ -175,11 +175,23 @@ | |||
175 | 175 | ||
176 | /* MAX98095 Registers Bit Fields */ | 176 | /* MAX98095 Registers Bit Fields */ |
177 | 177 | ||
178 | /* M98095_007_JACK_AUTO_STS */ | ||
179 | #define M98095_MIC_IN (1<<3) | ||
180 | #define M98095_LO_IN (1<<5) | ||
181 | #define M98095_HP_IN (1<<6) | ||
182 | #define M98095_DDONE (1<<7) | ||
183 | |||
178 | /* M98095_00F_HOST_CFG */ | 184 | /* M98095_00F_HOST_CFG */ |
179 | #define M98095_SEG (1<<0) | 185 | #define M98095_SEG (1<<0) |
180 | #define M98095_XTEN (1<<1) | 186 | #define M98095_XTEN (1<<1) |
181 | #define M98095_MDLLEN (1<<2) | 187 | #define M98095_MDLLEN (1<<2) |
182 | 188 | ||
189 | /* M98095_013_JACK_INT_EN */ | ||
190 | #define M98095_IMIC_IN (1<<3) | ||
191 | #define M98095_ILO_IN (1<<5) | ||
192 | #define M98095_IHP_IN (1<<6) | ||
193 | #define M98095_IDDONE (1<<7) | ||
194 | |||
183 | /* M98095_027_DAI1_CLKMODE, M98095_031_DAI2_CLKMODE, M98095_03B_DAI3_CLKMODE */ | 195 | /* M98095_027_DAI1_CLKMODE, M98095_031_DAI2_CLKMODE, M98095_03B_DAI3_CLKMODE */ |
184 | #define M98095_CLKMODE_MASK 0xFF | 196 | #define M98095_CLKMODE_MASK 0xFF |
185 | 197 | ||
@@ -255,6 +267,10 @@ | |||
255 | #define M98095_EQ2EN (1<<1) | 267 | #define M98095_EQ2EN (1<<1) |
256 | #define M98095_EQ1EN (1<<0) | 268 | #define M98095_EQ1EN (1<<0) |
257 | 269 | ||
270 | /* M98095_089_JACK_DET_AUTO */ | ||
271 | #define M98095_PIN5EN (1<<2) | ||
272 | #define M98095_JDEN (1<<7) | ||
273 | |||
258 | /* M98095_090_PWR_EN_IN */ | 274 | /* M98095_090_PWR_EN_IN */ |
259 | #define M98095_INEN (1<<7) | 275 | #define M98095_INEN (1<<7) |
260 | #define M98095_MB2EN (1<<3) | 276 | #define M98095_MB2EN (1<<3) |
@@ -296,4 +312,10 @@ | |||
296 | #define M98095_174_DAI1_BQ_BASE 0x74 | 312 | #define M98095_174_DAI1_BQ_BASE 0x74 |
297 | #define M98095_17E_DAI2_BQ_BASE 0x7E | 313 | #define M98095_17E_DAI2_BQ_BASE 0x7E |
298 | 314 | ||
315 | /* Default Delay used in Slew Rate Calculation for Jack detection */ | ||
316 | #define M98095_DEFAULT_SLEW_DELAY 0x18 | ||
317 | |||
318 | extern int max98095_jack_detect(struct snd_soc_codec *codec, | ||
319 | struct snd_soc_jack *hp_jack, struct snd_soc_jack *mic_jack); | ||
320 | |||
299 | #endif | 321 | #endif |
diff --git a/sound/soc/codecs/mc13783.c b/sound/soc/codecs/mc13783.c new file mode 100644 index 000000000000..6276e352125f --- /dev/null +++ b/sound/soc/codecs/mc13783.c | |||
@@ -0,0 +1,786 @@ | |||
1 | /* | ||
2 | * Copyright 2008 Juergen Beisert, kernel@pengutronix.de | ||
3 | * Copyright 2009 Sascha Hauer, s.hauer@pengutronix.de | ||
4 | * Copyright 2012 Philippe Retornaz, philippe.retornaz@epfl.ch | ||
5 | * | ||
6 | * Initial development of this code was funded by | ||
7 | * Phytec Messtechnik GmbH, http://www.phytec.de | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or | ||
10 | * modify it under the terms of the GNU General Public License | ||
11 | * as published by the Free Software Foundation; either version 2 | ||
12 | * of the License, or (at your option) any later version. | ||
13 | * This program is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | * GNU General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU General Public License | ||
19 | * along with this program; if not, write to the Free Software | ||
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | ||
21 | * MA 02110-1301, USA. | ||
22 | */ | ||
23 | #include <linux/module.h> | ||
24 | #include <linux/device.h> | ||
25 | #include <linux/mfd/mc13xxx.h> | ||
26 | #include <linux/slab.h> | ||
27 | #include <sound/core.h> | ||
28 | #include <sound/control.h> | ||
29 | #include <sound/pcm.h> | ||
30 | #include <sound/soc.h> | ||
31 | #include <sound/initval.h> | ||
32 | #include <sound/soc-dapm.h> | ||
33 | |||
34 | #include "mc13783.h" | ||
35 | |||
36 | #define MC13783_AUDIO_RX0 36 | ||
37 | #define MC13783_AUDIO_RX1 37 | ||
38 | #define MC13783_AUDIO_TX 38 | ||
39 | #define MC13783_SSI_NETWORK 39 | ||
40 | #define MC13783_AUDIO_CODEC 40 | ||
41 | #define MC13783_AUDIO_DAC 41 | ||
42 | |||
43 | #define AUDIO_RX0_ALSPEN (1 << 5) | ||
44 | #define AUDIO_RX0_ALSPSEL (1 << 7) | ||
45 | #define AUDIO_RX0_ADDCDC (1 << 21) | ||
46 | #define AUDIO_RX0_ADDSTDC (1 << 22) | ||
47 | #define AUDIO_RX0_ADDRXIN (1 << 23) | ||
48 | |||
49 | #define AUDIO_RX1_PGARXEN (1 << 0); | ||
50 | #define AUDIO_RX1_PGASTEN (1 << 5) | ||
51 | #define AUDIO_RX1_ARXINEN (1 << 10) | ||
52 | |||
53 | #define AUDIO_TX_AMC1REN (1 << 5) | ||
54 | #define AUDIO_TX_AMC1LEN (1 << 7) | ||
55 | #define AUDIO_TX_AMC2EN (1 << 9) | ||
56 | #define AUDIO_TX_ATXINEN (1 << 11) | ||
57 | #define AUDIO_TX_RXINREC (1 << 13) | ||
58 | |||
59 | #define SSI_NETWORK_CDCTXRXSLOT(x) (((x) & 0x3) << 2) | ||
60 | #define SSI_NETWORK_CDCTXSECSLOT(x) (((x) & 0x3) << 4) | ||
61 | #define SSI_NETWORK_CDCRXSECSLOT(x) (((x) & 0x3) << 6) | ||
62 | #define SSI_NETWORK_CDCRXSECGAIN(x) (((x) & 0x3) << 8) | ||
63 | #define SSI_NETWORK_CDCSUMGAIN(x) (1 << 10) | ||
64 | #define SSI_NETWORK_CDCFSDLY(x) (1 << 11) | ||
65 | #define SSI_NETWORK_DAC_SLOTS_8 (1 << 12) | ||
66 | #define SSI_NETWORK_DAC_SLOTS_4 (2 << 12) | ||
67 | #define SSI_NETWORK_DAC_SLOTS_2 (3 << 12) | ||
68 | #define SSI_NETWORK_DAC_SLOT_MASK (3 << 12) | ||
69 | #define SSI_NETWORK_DAC_RXSLOT_0_1 (0 << 14) | ||
70 | #define SSI_NETWORK_DAC_RXSLOT_2_3 (1 << 14) | ||
71 | #define SSI_NETWORK_DAC_RXSLOT_4_5 (2 << 14) | ||
72 | #define SSI_NETWORK_DAC_RXSLOT_6_7 (3 << 14) | ||
73 | #define SSI_NETWORK_DAC_RXSLOT_MASK (3 << 14) | ||
74 | #define SSI_NETWORK_STDCRXSECSLOT(x) (((x) & 0x3) << 16) | ||
75 | #define SSI_NETWORK_STDCRXSECGAIN(x) (((x) & 0x3) << 18) | ||
76 | #define SSI_NETWORK_STDCSUMGAIN (1 << 20) | ||
77 | |||
78 | /* | ||
79 | * MC13783_AUDIO_CODEC and MC13783_AUDIO_DAC mostly share the same | ||
80 | * register layout | ||
81 | */ | ||
82 | #define AUDIO_SSI_SEL (1 << 0) | ||
83 | #define AUDIO_CLK_SEL (1 << 1) | ||
84 | #define AUDIO_CSM (1 << 2) | ||
85 | #define AUDIO_BCL_INV (1 << 3) | ||
86 | #define AUDIO_CFS_INV (1 << 4) | ||
87 | #define AUDIO_CFS(x) (((x) & 0x3) << 5) | ||
88 | #define AUDIO_CLK(x) (((x) & 0x7) << 7) | ||
89 | #define AUDIO_C_EN (1 << 11) | ||
90 | #define AUDIO_C_CLK_EN (1 << 12) | ||
91 | #define AUDIO_C_RESET (1 << 15) | ||
92 | |||
93 | #define AUDIO_CODEC_CDCFS8K16K (1 << 10) | ||
94 | #define AUDIO_DAC_CFS_DLY_B (1 << 10) | ||
95 | |||
96 | struct mc13783_priv { | ||
97 | struct snd_soc_codec codec; | ||
98 | struct mc13xxx *mc13xxx; | ||
99 | |||
100 | enum mc13783_ssi_port adc_ssi_port; | ||
101 | enum mc13783_ssi_port dac_ssi_port; | ||
102 | }; | ||
103 | |||
104 | static unsigned int mc13783_read(struct snd_soc_codec *codec, | ||
105 | unsigned int reg) | ||
106 | { | ||
107 | struct mc13783_priv *priv = snd_soc_codec_get_drvdata(codec); | ||
108 | unsigned int value = 0; | ||
109 | |||
110 | mc13xxx_lock(priv->mc13xxx); | ||
111 | |||
112 | mc13xxx_reg_read(priv->mc13xxx, reg, &value); | ||
113 | |||
114 | mc13xxx_unlock(priv->mc13xxx); | ||
115 | |||
116 | return value; | ||
117 | } | ||
118 | |||
119 | static int mc13783_write(struct snd_soc_codec *codec, | ||
120 | unsigned int reg, unsigned int value) | ||
121 | { | ||
122 | struct mc13783_priv *priv = snd_soc_codec_get_drvdata(codec); | ||
123 | int ret; | ||
124 | |||
125 | mc13xxx_lock(priv->mc13xxx); | ||
126 | |||
127 | ret = mc13xxx_reg_write(priv->mc13xxx, reg, value); | ||
128 | |||
129 | mc13xxx_unlock(priv->mc13xxx); | ||
130 | |||
131 | return ret; | ||
132 | } | ||
133 | |||
134 | /* Mapping between sample rates and register value */ | ||
135 | static unsigned int mc13783_rates[] = { | ||
136 | 8000, 11025, 12000, 16000, | ||
137 | 22050, 24000, 32000, 44100, | ||
138 | 48000, 64000, 96000 | ||
139 | }; | ||
140 | |||
141 | static int mc13783_pcm_hw_params_dac(struct snd_pcm_substream *substream, | ||
142 | struct snd_pcm_hw_params *params, | ||
143 | struct snd_soc_dai *dai) | ||
144 | { | ||
145 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
146 | struct snd_soc_codec *codec = rtd->codec; | ||
147 | unsigned int rate = params_rate(params); | ||
148 | int i; | ||
149 | |||
150 | for (i = 0; i < ARRAY_SIZE(mc13783_rates); i++) { | ||
151 | if (rate == mc13783_rates[i]) { | ||
152 | snd_soc_update_bits(codec, MC13783_AUDIO_DAC, | ||
153 | 0xf << 17, i << 17); | ||
154 | return 0; | ||
155 | } | ||
156 | } | ||
157 | |||
158 | return -EINVAL; | ||
159 | } | ||
160 | |||
161 | static int mc13783_pcm_hw_params_codec(struct snd_pcm_substream *substream, | ||
162 | struct snd_pcm_hw_params *params, | ||
163 | struct snd_soc_dai *dai) | ||
164 | { | ||
165 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
166 | struct snd_soc_codec *codec = rtd->codec; | ||
167 | unsigned int rate = params_rate(params); | ||
168 | unsigned int val; | ||
169 | |||
170 | switch (rate) { | ||
171 | case 8000: | ||
172 | val = 0; | ||
173 | break; | ||
174 | case 16000: | ||
175 | val = AUDIO_CODEC_CDCFS8K16K; | ||
176 | break; | ||
177 | default: | ||
178 | return -EINVAL; | ||
179 | } | ||
180 | |||
181 | snd_soc_update_bits(codec, MC13783_AUDIO_CODEC, AUDIO_CODEC_CDCFS8K16K, | ||
182 | val); | ||
183 | |||
184 | return 0; | ||
185 | } | ||
186 | |||
187 | static int mc13783_pcm_hw_params_sync(struct snd_pcm_substream *substream, | ||
188 | struct snd_pcm_hw_params *params, | ||
189 | struct snd_soc_dai *dai) | ||
190 | { | ||
191 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) | ||
192 | return mc13783_pcm_hw_params_dac(substream, params, dai); | ||
193 | else | ||
194 | return mc13783_pcm_hw_params_codec(substream, params, dai); | ||
195 | } | ||
196 | |||
197 | static int mc13783_set_fmt(struct snd_soc_dai *dai, unsigned int fmt, | ||
198 | unsigned int reg) | ||
199 | { | ||
200 | struct snd_soc_codec *codec = dai->codec; | ||
201 | unsigned int val = 0; | ||
202 | unsigned int mask = AUDIO_CFS(3) | AUDIO_BCL_INV | AUDIO_CFS_INV | | ||
203 | AUDIO_CSM | AUDIO_C_CLK_EN | AUDIO_C_RESET; | ||
204 | |||
205 | |||
206 | /* DAI mode */ | ||
207 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { | ||
208 | case SND_SOC_DAIFMT_I2S: | ||
209 | val |= AUDIO_CFS(2); | ||
210 | break; | ||
211 | case SND_SOC_DAIFMT_DSP_A: | ||
212 | val |= AUDIO_CFS(1); | ||
213 | break; | ||
214 | default: | ||
215 | return -EINVAL; | ||
216 | } | ||
217 | |||
218 | /* DAI clock inversion */ | ||
219 | switch (fmt & SND_SOC_DAIFMT_INV_MASK) { | ||
220 | case SND_SOC_DAIFMT_NB_NF: | ||
221 | val |= AUDIO_BCL_INV; | ||
222 | break; | ||
223 | case SND_SOC_DAIFMT_NB_IF: | ||
224 | val |= AUDIO_BCL_INV | AUDIO_CFS_INV; | ||
225 | break; | ||
226 | case SND_SOC_DAIFMT_IB_NF: | ||
227 | break; | ||
228 | case SND_SOC_DAIFMT_IB_IF: | ||
229 | val |= AUDIO_CFS_INV; | ||
230 | break; | ||
231 | } | ||
232 | |||
233 | /* DAI clock master masks */ | ||
234 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { | ||
235 | case SND_SOC_DAIFMT_CBM_CFM: | ||
236 | val |= AUDIO_C_CLK_EN; | ||
237 | break; | ||
238 | case SND_SOC_DAIFMT_CBS_CFS: | ||
239 | val |= AUDIO_CSM; | ||
240 | break; | ||
241 | case SND_SOC_DAIFMT_CBM_CFS: | ||
242 | case SND_SOC_DAIFMT_CBS_CFM: | ||
243 | return -EINVAL; | ||
244 | } | ||
245 | |||
246 | val |= AUDIO_C_RESET; | ||
247 | |||
248 | snd_soc_update_bits(codec, reg, mask, val); | ||
249 | |||
250 | return 0; | ||
251 | } | ||
252 | |||
253 | static int mc13783_set_fmt_async(struct snd_soc_dai *dai, unsigned int fmt) | ||
254 | { | ||
255 | if (dai->id == MC13783_ID_STEREO_DAC) | ||
256 | return mc13783_set_fmt(dai, fmt, MC13783_AUDIO_DAC); | ||
257 | else | ||
258 | return mc13783_set_fmt(dai, fmt, MC13783_AUDIO_CODEC); | ||
259 | } | ||
260 | |||
261 | static int mc13783_set_fmt_sync(struct snd_soc_dai *dai, unsigned int fmt) | ||
262 | { | ||
263 | int ret; | ||
264 | |||
265 | ret = mc13783_set_fmt(dai, fmt, MC13783_AUDIO_DAC); | ||
266 | if (ret) | ||
267 | return ret; | ||
268 | |||
269 | /* | ||
270 | * In synchronous mode force the voice codec into slave mode | ||
271 | * so that the clock / framesync from the stereo DAC is used | ||
272 | */ | ||
273 | fmt &= ~SND_SOC_DAIFMT_MASTER_MASK; | ||
274 | fmt |= SND_SOC_DAIFMT_CBS_CFS; | ||
275 | ret = mc13783_set_fmt(dai, fmt, MC13783_AUDIO_CODEC); | ||
276 | |||
277 | return ret; | ||
278 | } | ||
279 | |||
280 | static int mc13783_sysclk[] = { | ||
281 | 13000000, | ||
282 | 15360000, | ||
283 | 16800000, | ||
284 | -1, | ||
285 | 26000000, | ||
286 | -1, /* 12000000, invalid for voice codec */ | ||
287 | -1, /* 3686400, invalid for voice codec */ | ||
288 | 33600000, | ||
289 | }; | ||
290 | |||
291 | static int mc13783_set_sysclk(struct snd_soc_dai *dai, | ||
292 | int clk_id, unsigned int freq, int dir, | ||
293 | unsigned int reg) | ||
294 | { | ||
295 | struct snd_soc_codec *codec = dai->codec; | ||
296 | int clk; | ||
297 | unsigned int val = 0; | ||
298 | unsigned int mask = AUDIO_CLK(0x7) | AUDIO_CLK_SEL; | ||
299 | |||
300 | for (clk = 0; clk < ARRAY_SIZE(mc13783_sysclk); clk++) { | ||
301 | if (mc13783_sysclk[clk] < 0) | ||
302 | continue; | ||
303 | if (mc13783_sysclk[clk] == freq) | ||
304 | break; | ||
305 | } | ||
306 | |||
307 | if (clk == ARRAY_SIZE(mc13783_sysclk)) | ||
308 | return -EINVAL; | ||
309 | |||
310 | if (clk_id == MC13783_CLK_CLIB) | ||
311 | val |= AUDIO_CLK_SEL; | ||
312 | |||
313 | val |= AUDIO_CLK(clk); | ||
314 | |||
315 | snd_soc_update_bits(codec, reg, mask, val); | ||
316 | |||
317 | return 0; | ||
318 | } | ||
319 | |||
320 | static int mc13783_set_sysclk_dac(struct snd_soc_dai *dai, | ||
321 | int clk_id, unsigned int freq, int dir) | ||
322 | { | ||
323 | return mc13783_set_sysclk(dai, clk_id, freq, dir, MC13783_AUDIO_DAC); | ||
324 | } | ||
325 | |||
326 | static int mc13783_set_sysclk_codec(struct snd_soc_dai *dai, | ||
327 | int clk_id, unsigned int freq, int dir) | ||
328 | { | ||
329 | return mc13783_set_sysclk(dai, clk_id, freq, dir, MC13783_AUDIO_CODEC); | ||
330 | } | ||
331 | |||
332 | static int mc13783_set_sysclk_sync(struct snd_soc_dai *dai, | ||
333 | int clk_id, unsigned int freq, int dir) | ||
334 | { | ||
335 | int ret; | ||
336 | |||
337 | ret = mc13783_set_sysclk(dai, clk_id, freq, dir, MC13783_AUDIO_DAC); | ||
338 | if (ret) | ||
339 | return ret; | ||
340 | |||
341 | return mc13783_set_sysclk(dai, clk_id, freq, dir, MC13783_AUDIO_CODEC); | ||
342 | } | ||
343 | |||
344 | static int mc13783_set_tdm_slot_dac(struct snd_soc_dai *dai, | ||
345 | unsigned int tx_mask, unsigned int rx_mask, int slots, | ||
346 | int slot_width) | ||
347 | { | ||
348 | struct snd_soc_codec *codec = dai->codec; | ||
349 | unsigned int val = 0; | ||
350 | unsigned int mask = SSI_NETWORK_DAC_SLOT_MASK | | ||
351 | SSI_NETWORK_DAC_RXSLOT_MASK; | ||
352 | |||
353 | switch (slots) { | ||
354 | case 2: | ||
355 | val |= SSI_NETWORK_DAC_SLOTS_2; | ||
356 | break; | ||
357 | case 4: | ||
358 | val |= SSI_NETWORK_DAC_SLOTS_4; | ||
359 | break; | ||
360 | case 8: | ||
361 | val |= SSI_NETWORK_DAC_SLOTS_8; | ||
362 | break; | ||
363 | default: | ||
364 | return -EINVAL; | ||
365 | } | ||
366 | |||
367 | switch (rx_mask) { | ||
368 | case 0xfffffffc: | ||
369 | val |= SSI_NETWORK_DAC_RXSLOT_0_1; | ||
370 | break; | ||
371 | case 0xfffffff3: | ||
372 | val |= SSI_NETWORK_DAC_RXSLOT_2_3; | ||
373 | break; | ||
374 | case 0xffffffcf: | ||
375 | val |= SSI_NETWORK_DAC_RXSLOT_4_5; | ||
376 | break; | ||
377 | case 0xffffff3f: | ||
378 | val |= SSI_NETWORK_DAC_RXSLOT_6_7; | ||
379 | break; | ||
380 | default: | ||
381 | return -EINVAL; | ||
382 | }; | ||
383 | |||
384 | snd_soc_update_bits(codec, MC13783_SSI_NETWORK, mask, val); | ||
385 | |||
386 | return 0; | ||
387 | } | ||
388 | |||
389 | static int mc13783_set_tdm_slot_codec(struct snd_soc_dai *dai, | ||
390 | unsigned int tx_mask, unsigned int rx_mask, int slots, | ||
391 | int slot_width) | ||
392 | { | ||
393 | struct snd_soc_codec *codec = dai->codec; | ||
394 | unsigned int val = 0; | ||
395 | unsigned int mask = 0x3f; | ||
396 | |||
397 | if (slots != 4) | ||
398 | return -EINVAL; | ||
399 | |||
400 | if (tx_mask != 0xfffffffc) | ||
401 | return -EINVAL; | ||
402 | |||
403 | val |= (0x00 << 2); /* primary timeslot RX/TX(?) is 0 */ | ||
404 | val |= (0x01 << 4); /* secondary timeslot TX is 1 */ | ||
405 | |||
406 | snd_soc_update_bits(codec, MC13783_SSI_NETWORK, mask, val); | ||
407 | |||
408 | return 0; | ||
409 | } | ||
410 | |||
411 | static int mc13783_set_tdm_slot_sync(struct snd_soc_dai *dai, | ||
412 | unsigned int tx_mask, unsigned int rx_mask, int slots, | ||
413 | int slot_width) | ||
414 | { | ||
415 | int ret; | ||
416 | |||
417 | ret = mc13783_set_tdm_slot_dac(dai, tx_mask, rx_mask, slots, | ||
418 | slot_width); | ||
419 | if (ret) | ||
420 | return ret; | ||
421 | |||
422 | ret = mc13783_set_tdm_slot_codec(dai, tx_mask, rx_mask, slots, | ||
423 | slot_width); | ||
424 | |||
425 | return ret; | ||
426 | } | ||
427 | |||
428 | static const struct snd_kcontrol_new mc1l_amp_ctl = | ||
429 | SOC_DAPM_SINGLE("Switch", 38, 7, 1, 0); | ||
430 | |||
431 | static const struct snd_kcontrol_new mc1r_amp_ctl = | ||
432 | SOC_DAPM_SINGLE("Switch", 38, 5, 1, 0); | ||
433 | |||
434 | static const struct snd_kcontrol_new mc2_amp_ctl = | ||
435 | SOC_DAPM_SINGLE("Switch", 38, 9, 1, 0); | ||
436 | |||
437 | static const struct snd_kcontrol_new atx_amp_ctl = | ||
438 | SOC_DAPM_SINGLE("Switch", 38, 11, 1, 0); | ||
439 | |||
440 | |||
441 | /* Virtual mux. The chip does the input selection automatically | ||
442 | * as soon as we enable one input. */ | ||
443 | static const char * const adcl_enum_text[] = { | ||
444 | "MC1L", "RXINL", | ||
445 | }; | ||
446 | |||
447 | static const struct soc_enum adcl_enum = | ||
448 | SOC_ENUM_SINGLE(0, 0, ARRAY_SIZE(adcl_enum_text), adcl_enum_text); | ||
449 | |||
450 | static const struct snd_kcontrol_new left_input_mux = | ||
451 | SOC_DAPM_ENUM_VIRT("Route", adcl_enum); | ||
452 | |||
453 | static const char * const adcr_enum_text[] = { | ||
454 | "MC1R", "MC2", "RXINR", "TXIN", | ||
455 | }; | ||
456 | |||
457 | static const struct soc_enum adcr_enum = | ||
458 | SOC_ENUM_SINGLE(0, 0, ARRAY_SIZE(adcr_enum_text), adcr_enum_text); | ||
459 | |||
460 | static const struct snd_kcontrol_new right_input_mux = | ||
461 | SOC_DAPM_ENUM_VIRT("Route", adcr_enum); | ||
462 | |||
463 | static const struct snd_kcontrol_new samp_ctl = | ||
464 | SOC_DAPM_SINGLE("Switch", 36, 3, 1, 0); | ||
465 | |||
466 | static const struct snd_kcontrol_new lamp_ctl = | ||
467 | SOC_DAPM_SINGLE("Switch", 36, 5, 1, 0); | ||
468 | |||
469 | static const struct snd_kcontrol_new hlamp_ctl = | ||
470 | SOC_DAPM_SINGLE("Switch", 36, 10, 1, 0); | ||
471 | |||
472 | static const struct snd_kcontrol_new hramp_ctl = | ||
473 | SOC_DAPM_SINGLE("Switch", 36, 9, 1, 0); | ||
474 | |||
475 | static const struct snd_kcontrol_new llamp_ctl = | ||
476 | SOC_DAPM_SINGLE("Switch", 36, 16, 1, 0); | ||
477 | |||
478 | static const struct snd_kcontrol_new lramp_ctl = | ||
479 | SOC_DAPM_SINGLE("Switch", 36, 15, 1, 0); | ||
480 | |||
481 | static const struct snd_soc_dapm_widget mc13783_dapm_widgets[] = { | ||
482 | /* Input */ | ||
483 | SND_SOC_DAPM_INPUT("MC1LIN"), | ||
484 | SND_SOC_DAPM_INPUT("MC1RIN"), | ||
485 | SND_SOC_DAPM_INPUT("MC2IN"), | ||
486 | SND_SOC_DAPM_INPUT("RXINR"), | ||
487 | SND_SOC_DAPM_INPUT("RXINL"), | ||
488 | SND_SOC_DAPM_INPUT("TXIN"), | ||
489 | |||
490 | SND_SOC_DAPM_SUPPLY("MC1 Bias", 38, 0, 0, NULL, 0), | ||
491 | SND_SOC_DAPM_SUPPLY("MC2 Bias", 38, 1, 0, NULL, 0), | ||
492 | |||
493 | SND_SOC_DAPM_SWITCH("MC1L Amp", 38, 7, 0, &mc1l_amp_ctl), | ||
494 | SND_SOC_DAPM_SWITCH("MC1R Amp", 38, 5, 0, &mc1r_amp_ctl), | ||
495 | SND_SOC_DAPM_SWITCH("MC2 Amp", 38, 9, 0, &mc2_amp_ctl), | ||
496 | SND_SOC_DAPM_SWITCH("TXIN Amp", 38, 11, 0, &atx_amp_ctl), | ||
497 | |||
498 | SND_SOC_DAPM_VIRT_MUX("PGA Left Input Mux", SND_SOC_NOPM, 0, 0, | ||
499 | &left_input_mux), | ||
500 | SND_SOC_DAPM_VIRT_MUX("PGA Right Input Mux", SND_SOC_NOPM, 0, 0, | ||
501 | &right_input_mux), | ||
502 | |||
503 | SND_SOC_DAPM_PGA("PGA Left Input", SND_SOC_NOPM, 0, 0, NULL, 0), | ||
504 | SND_SOC_DAPM_PGA("PGA Right Input", SND_SOC_NOPM, 0, 0, NULL, 0), | ||
505 | |||
506 | SND_SOC_DAPM_ADC("ADC", "Capture", 40, 11, 0), | ||
507 | SND_SOC_DAPM_SUPPLY("ADC_Reset", 40, 15, 0, NULL, 0), | ||
508 | |||
509 | /* Output */ | ||
510 | SND_SOC_DAPM_SUPPLY("DAC_E", 41, 11, 0, NULL, 0), | ||
511 | SND_SOC_DAPM_SUPPLY("DAC_Reset", 41, 15, 0, NULL, 0), | ||
512 | SND_SOC_DAPM_OUTPUT("RXOUTL"), | ||
513 | SND_SOC_DAPM_OUTPUT("RXOUTR"), | ||
514 | SND_SOC_DAPM_OUTPUT("HSL"), | ||
515 | SND_SOC_DAPM_OUTPUT("HSR"), | ||
516 | SND_SOC_DAPM_OUTPUT("LSP"), | ||
517 | SND_SOC_DAPM_OUTPUT("SP"), | ||
518 | |||
519 | SND_SOC_DAPM_SWITCH("Speaker Amp", 36, 3, 0, &samp_ctl), | ||
520 | SND_SOC_DAPM_SWITCH("Loudspeaker Amp", SND_SOC_NOPM, 0, 0, &lamp_ctl), | ||
521 | SND_SOC_DAPM_SWITCH("Headset Amp Left", 36, 10, 0, &hlamp_ctl), | ||
522 | SND_SOC_DAPM_SWITCH("Headset Amp Right", 36, 9, 0, &hramp_ctl), | ||
523 | SND_SOC_DAPM_SWITCH("Line out Amp Left", 36, 16, 0, &llamp_ctl), | ||
524 | SND_SOC_DAPM_SWITCH("Line out Amp Right", 36, 15, 0, &lramp_ctl), | ||
525 | SND_SOC_DAPM_DAC("DAC", "Playback", 36, 22, 0), | ||
526 | SND_SOC_DAPM_PGA("DAC PGA", 37, 5, 0, NULL, 0), | ||
527 | }; | ||
528 | |||
529 | static struct snd_soc_dapm_route mc13783_routes[] = { | ||
530 | /* Input */ | ||
531 | { "MC1L Amp", NULL, "MC1LIN"}, | ||
532 | { "MC1R Amp", NULL, "MC1RIN" }, | ||
533 | { "MC2 Amp", NULL, "MC2IN" }, | ||
534 | { "TXIN Amp", NULL, "TXIN"}, | ||
535 | |||
536 | { "PGA Left Input Mux", "MC1L", "MC1L Amp" }, | ||
537 | { "PGA Left Input Mux", "RXINL", "RXINL"}, | ||
538 | { "PGA Right Input Mux", "MC1R", "MC1R Amp" }, | ||
539 | { "PGA Right Input Mux", "MC2", "MC2 Amp"}, | ||
540 | { "PGA Right Input Mux", "TXIN", "TXIN Amp"}, | ||
541 | { "PGA Right Input Mux", "RXINR", "RXINR"}, | ||
542 | |||
543 | { "PGA Left Input", NULL, "PGA Left Input Mux"}, | ||
544 | { "PGA Right Input", NULL, "PGA Right Input Mux"}, | ||
545 | |||
546 | { "ADC", NULL, "PGA Left Input"}, | ||
547 | { "ADC", NULL, "PGA Right Input"}, | ||
548 | { "ADC", NULL, "ADC_Reset"}, | ||
549 | |||
550 | /* Output */ | ||
551 | { "HSL", NULL, "Headset Amp Left" }, | ||
552 | { "HSR", NULL, "Headset Amp Right"}, | ||
553 | { "RXOUTL", NULL, "Line out Amp Left"}, | ||
554 | { "RXOUTR", NULL, "Line out Amp Right"}, | ||
555 | { "SP", NULL, "Speaker Amp"}, | ||
556 | { "Speaker Amp", NULL, "DAC PGA"}, | ||
557 | { "LSP", NULL, "DAC PGA"}, | ||
558 | { "Headset Amp Left", NULL, "DAC PGA"}, | ||
559 | { "Headset Amp Right", NULL, "DAC PGA"}, | ||
560 | { "Line out Amp Left", NULL, "DAC PGA"}, | ||
561 | { "Line out Amp Right", NULL, "DAC PGA"}, | ||
562 | { "DAC PGA", NULL, "DAC"}, | ||
563 | { "DAC", NULL, "DAC_E"}, | ||
564 | }; | ||
565 | |||
566 | static const char * const mc13783_3d_mixer[] = {"Stereo", "Phase Mix", | ||
567 | "Mono", "Mono Mix"}; | ||
568 | |||
569 | static const struct soc_enum mc13783_enum_3d_mixer = | ||
570 | SOC_ENUM_SINGLE(MC13783_AUDIO_RX1, 16, ARRAY_SIZE(mc13783_3d_mixer), | ||
571 | mc13783_3d_mixer); | ||
572 | |||
573 | static struct snd_kcontrol_new mc13783_control_list[] = { | ||
574 | SOC_SINGLE("Loudspeaker enable", MC13783_AUDIO_RX0, 5, 1, 0), | ||
575 | SOC_SINGLE("PCM Playback Volume", MC13783_AUDIO_RX1, 6, 15, 0), | ||
576 | SOC_DOUBLE("PCM Capture Volume", MC13783_AUDIO_TX, 19, 14, 31, 0), | ||
577 | SOC_ENUM("3D Control", mc13783_enum_3d_mixer), | ||
578 | }; | ||
579 | |||
580 | static int mc13783_probe(struct snd_soc_codec *codec) | ||
581 | { | ||
582 | struct mc13783_priv *priv = snd_soc_codec_get_drvdata(codec); | ||
583 | |||
584 | mc13xxx_lock(priv->mc13xxx); | ||
585 | |||
586 | /* these are the reset values */ | ||
587 | mc13xxx_reg_write(priv->mc13xxx, MC13783_AUDIO_RX0, 0x25893); | ||
588 | mc13xxx_reg_write(priv->mc13xxx, MC13783_AUDIO_RX1, 0x00d35A); | ||
589 | mc13xxx_reg_write(priv->mc13xxx, MC13783_AUDIO_TX, 0x420000); | ||
590 | mc13xxx_reg_write(priv->mc13xxx, MC13783_SSI_NETWORK, 0x013060); | ||
591 | mc13xxx_reg_write(priv->mc13xxx, MC13783_AUDIO_CODEC, 0x180027); | ||
592 | mc13xxx_reg_write(priv->mc13xxx, MC13783_AUDIO_DAC, 0x0e0004); | ||
593 | |||
594 | if (priv->adc_ssi_port == MC13783_SSI1_PORT) | ||
595 | mc13xxx_reg_rmw(priv->mc13xxx, MC13783_AUDIO_CODEC, | ||
596 | AUDIO_SSI_SEL, 0); | ||
597 | else | ||
598 | mc13xxx_reg_rmw(priv->mc13xxx, MC13783_AUDIO_CODEC, | ||
599 | 0, AUDIO_SSI_SEL); | ||
600 | |||
601 | if (priv->dac_ssi_port == MC13783_SSI1_PORT) | ||
602 | mc13xxx_reg_rmw(priv->mc13xxx, MC13783_AUDIO_DAC, | ||
603 | AUDIO_SSI_SEL, 0); | ||
604 | else | ||
605 | mc13xxx_reg_rmw(priv->mc13xxx, MC13783_AUDIO_DAC, | ||
606 | 0, AUDIO_SSI_SEL); | ||
607 | |||
608 | mc13xxx_unlock(priv->mc13xxx); | ||
609 | |||
610 | return 0; | ||
611 | } | ||
612 | |||
613 | static int mc13783_remove(struct snd_soc_codec *codec) | ||
614 | { | ||
615 | struct mc13783_priv *priv = snd_soc_codec_get_drvdata(codec); | ||
616 | |||
617 | mc13xxx_lock(priv->mc13xxx); | ||
618 | |||
619 | /* Make sure VAUDIOON is off */ | ||
620 | mc13xxx_reg_rmw(priv->mc13xxx, MC13783_AUDIO_RX0, 0x3, 0); | ||
621 | |||
622 | mc13xxx_unlock(priv->mc13xxx); | ||
623 | |||
624 | return 0; | ||
625 | } | ||
626 | |||
627 | #define MC13783_RATES_RECORD (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000) | ||
628 | |||
629 | #define MC13783_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ | ||
630 | SNDRV_PCM_FMTBIT_S24_LE) | ||
631 | |||
632 | static struct snd_soc_dai_ops mc13783_ops_dac = { | ||
633 | .hw_params = mc13783_pcm_hw_params_dac, | ||
634 | .set_fmt = mc13783_set_fmt_async, | ||
635 | .set_sysclk = mc13783_set_sysclk_dac, | ||
636 | .set_tdm_slot = mc13783_set_tdm_slot_dac, | ||
637 | }; | ||
638 | |||
639 | static struct snd_soc_dai_ops mc13783_ops_codec = { | ||
640 | .hw_params = mc13783_pcm_hw_params_codec, | ||
641 | .set_fmt = mc13783_set_fmt_async, | ||
642 | .set_sysclk = mc13783_set_sysclk_codec, | ||
643 | .set_tdm_slot = mc13783_set_tdm_slot_codec, | ||
644 | }; | ||
645 | |||
646 | /* | ||
647 | * The mc13783 has two SSI ports, both of them can be routed either | ||
648 | * to the voice codec or the stereo DAC. When two different SSI ports | ||
649 | * are used for the voice codec and the stereo DAC we can do different | ||
650 | * formats and sysclock settings for playback and capture | ||
651 | * (mc13783-hifi-playback and mc13783-hifi-capture). Using the same port | ||
652 | * forces us to use symmetric rates (mc13783-hifi). | ||
653 | */ | ||
654 | static struct snd_soc_dai_driver mc13783_dai_async[] = { | ||
655 | { | ||
656 | .name = "mc13783-hifi-playback", | ||
657 | .id = MC13783_ID_STEREO_DAC, | ||
658 | .playback = { | ||
659 | .stream_name = "Playback", | ||
660 | .channels_min = 1, | ||
661 | .channels_max = 2, | ||
662 | .rates = SNDRV_PCM_RATE_8000_96000, | ||
663 | .formats = MC13783_FORMATS, | ||
664 | }, | ||
665 | .ops = &mc13783_ops_dac, | ||
666 | }, { | ||
667 | .name = "mc13783-hifi-capture", | ||
668 | .id = MC13783_ID_STEREO_CODEC, | ||
669 | .capture = { | ||
670 | .stream_name = "Capture", | ||
671 | .channels_min = 1, | ||
672 | .channels_max = 2, | ||
673 | .rates = MC13783_RATES_RECORD, | ||
674 | .formats = MC13783_FORMATS, | ||
675 | }, | ||
676 | .ops = &mc13783_ops_codec, | ||
677 | }, | ||
678 | }; | ||
679 | |||
680 | static struct snd_soc_dai_ops mc13783_ops_sync = { | ||
681 | .hw_params = mc13783_pcm_hw_params_sync, | ||
682 | .set_fmt = mc13783_set_fmt_sync, | ||
683 | .set_sysclk = mc13783_set_sysclk_sync, | ||
684 | .set_tdm_slot = mc13783_set_tdm_slot_sync, | ||
685 | }; | ||
686 | |||
687 | static struct snd_soc_dai_driver mc13783_dai_sync[] = { | ||
688 | { | ||
689 | .name = "mc13783-hifi", | ||
690 | .id = MC13783_ID_SYNC, | ||
691 | .playback = { | ||
692 | .stream_name = "Playback", | ||
693 | .channels_min = 1, | ||
694 | .channels_max = 2, | ||
695 | .rates = SNDRV_PCM_RATE_8000_96000, | ||
696 | .formats = MC13783_FORMATS, | ||
697 | }, | ||
698 | .capture = { | ||
699 | .stream_name = "Capture", | ||
700 | .channels_min = 1, | ||
701 | .channels_max = 2, | ||
702 | .rates = MC13783_RATES_RECORD, | ||
703 | .formats = MC13783_FORMATS, | ||
704 | }, | ||
705 | .ops = &mc13783_ops_sync, | ||
706 | .symmetric_rates = 1, | ||
707 | } | ||
708 | }; | ||
709 | |||
710 | static struct snd_soc_codec_driver soc_codec_dev_mc13783 = { | ||
711 | .probe = mc13783_probe, | ||
712 | .remove = mc13783_remove, | ||
713 | .read = mc13783_read, | ||
714 | .write = mc13783_write, | ||
715 | .controls = mc13783_control_list, | ||
716 | .num_controls = ARRAY_SIZE(mc13783_control_list), | ||
717 | .dapm_widgets = mc13783_dapm_widgets, | ||
718 | .num_dapm_widgets = ARRAY_SIZE(mc13783_dapm_widgets), | ||
719 | .dapm_routes = mc13783_routes, | ||
720 | .num_dapm_routes = ARRAY_SIZE(mc13783_routes), | ||
721 | }; | ||
722 | |||
723 | static int mc13783_codec_probe(struct platform_device *pdev) | ||
724 | { | ||
725 | struct mc13xxx *mc13xxx; | ||
726 | struct mc13783_priv *priv; | ||
727 | struct mc13xxx_codec_platform_data *pdata = pdev->dev.platform_data; | ||
728 | int ret; | ||
729 | |||
730 | mc13xxx = dev_get_drvdata(pdev->dev.parent); | ||
731 | |||
732 | |||
733 | priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); | ||
734 | if (priv == NULL) | ||
735 | return -ENOMEM; | ||
736 | |||
737 | dev_set_drvdata(&pdev->dev, priv); | ||
738 | priv->mc13xxx = mc13xxx; | ||
739 | if (pdata) { | ||
740 | priv->adc_ssi_port = pdata->adc_ssi_port; | ||
741 | priv->dac_ssi_port = pdata->dac_ssi_port; | ||
742 | } else { | ||
743 | priv->adc_ssi_port = MC13783_SSI1_PORT; | ||
744 | priv->dac_ssi_port = MC13783_SSI2_PORT; | ||
745 | } | ||
746 | |||
747 | if (priv->adc_ssi_port == priv->dac_ssi_port) | ||
748 | ret = snd_soc_register_codec(&pdev->dev, &soc_codec_dev_mc13783, | ||
749 | mc13783_dai_sync, ARRAY_SIZE(mc13783_dai_sync)); | ||
750 | else | ||
751 | ret = snd_soc_register_codec(&pdev->dev, &soc_codec_dev_mc13783, | ||
752 | mc13783_dai_async, ARRAY_SIZE(mc13783_dai_async)); | ||
753 | |||
754 | if (ret) | ||
755 | goto err_register_codec; | ||
756 | |||
757 | return 0; | ||
758 | |||
759 | err_register_codec: | ||
760 | dev_err(&pdev->dev, "register codec failed with %d\n", ret); | ||
761 | |||
762 | return ret; | ||
763 | } | ||
764 | |||
765 | static int mc13783_codec_remove(struct platform_device *pdev) | ||
766 | { | ||
767 | snd_soc_unregister_codec(&pdev->dev); | ||
768 | |||
769 | return 0; | ||
770 | } | ||
771 | |||
772 | static struct platform_driver mc13783_codec_driver = { | ||
773 | .driver = { | ||
774 | .name = "mc13783-codec", | ||
775 | .owner = THIS_MODULE, | ||
776 | }, | ||
777 | .probe = mc13783_codec_probe, | ||
778 | .remove = __devexit_p(mc13783_codec_remove), | ||
779 | }; | ||
780 | |||
781 | module_platform_driver(mc13783_codec_driver); | ||
782 | |||
783 | MODULE_DESCRIPTION("ASoC MC13783 driver"); | ||
784 | MODULE_AUTHOR("Sascha Hauer, Pengutronix <s.hauer@pengutronix.de>"); | ||
785 | MODULE_AUTHOR("Philippe Retornaz <philippe.retornaz@epfl.ch>"); | ||
786 | MODULE_LICENSE("GPL"); | ||
diff --git a/sound/soc/codecs/mc13783.h b/sound/soc/codecs/mc13783.h new file mode 100644 index 000000000000..3a6d1993a217 --- /dev/null +++ b/sound/soc/codecs/mc13783.h | |||
@@ -0,0 +1,28 @@ | |||
1 | /* | ||
2 | * Copyright 2008 Juergen Beisert, kernel@pengutronix.de | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or | ||
5 | * modify it under the terms of the GNU General Public License | ||
6 | * as published by the Free Software Foundation; either version 2 | ||
7 | * of the License, or (at your option) any later version. | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program; if not, write to the Free Software Foundation, Inc. | ||
15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
16 | */ | ||
17 | |||
18 | #ifndef MC13783_MIXER_H | ||
19 | #define MC13783_MIXER_H | ||
20 | |||
21 | #define MC13783_CLK_CLIA 1 | ||
22 | #define MC13783_CLK_CLIB 2 | ||
23 | |||
24 | #define MC13783_ID_STEREO_DAC 1 | ||
25 | #define MC13783_ID_STEREO_CODEC 2 | ||
26 | #define MC13783_ID_SYNC 3 | ||
27 | |||
28 | #endif /* MC13783_MIXER_H */ | ||
diff --git a/sound/soc/codecs/ml26124.c b/sound/soc/codecs/ml26124.c new file mode 100644 index 000000000000..22cb5bf59273 --- /dev/null +++ b/sound/soc/codecs/ml26124.c | |||
@@ -0,0 +1,681 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2011 LAPIS Semiconductor Co., Ltd. | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License as published by | ||
6 | * the Free Software Foundation; version 2 of the License. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program; if not, write to the Free Software | ||
15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. | ||
16 | */ | ||
17 | |||
18 | #include <linux/module.h> | ||
19 | #include <linux/moduleparam.h> | ||
20 | #include <linux/init.h> | ||
21 | #include <linux/delay.h> | ||
22 | #include <linux/pm.h> | ||
23 | #include <linux/i2c.h> | ||
24 | #include <linux/slab.h> | ||
25 | #include <linux/platform_device.h> | ||
26 | #include <linux/regmap.h> | ||
27 | #include <sound/core.h> | ||
28 | #include <sound/pcm.h> | ||
29 | #include <sound/pcm_params.h> | ||
30 | #include <sound/soc.h> | ||
31 | #include <sound/tlv.h> | ||
32 | #include "ml26124.h" | ||
33 | |||
34 | #define DVOL_CTL_DVMUTE_ON BIT(4) /* Digital volume MUTE On */ | ||
35 | #define DVOL_CTL_DVMUTE_OFF 0 /* Digital volume MUTE Off */ | ||
36 | #define ML26124_SAI_NO_DELAY BIT(1) | ||
37 | #define ML26124_SAI_FRAME_SYNC (BIT(5) | BIT(0)) /* For mono (Telecodec) */ | ||
38 | #define ML26134_CACHESIZE 212 | ||
39 | #define ML26124_VMID BIT(1) | ||
40 | #define ML26124_RATES (SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_32000 |\ | ||
41 | SNDRV_PCM_RATE_48000) | ||
42 | #define ML26124_FORMATS (SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE |\ | ||
43 | SNDRV_PCM_FMTBIT_S32_LE) | ||
44 | #define ML26124_NUM_REGISTER ML26134_CACHESIZE | ||
45 | |||
46 | struct ml26124_priv { | ||
47 | u32 mclk; | ||
48 | u32 rate; | ||
49 | struct regmap *regmap; | ||
50 | int clk_in; | ||
51 | struct snd_pcm_substream *substream; | ||
52 | }; | ||
53 | |||
54 | struct clk_coeff { | ||
55 | u32 mclk; | ||
56 | u32 rate; | ||
57 | u8 pllnl; | ||
58 | u8 pllnh; | ||
59 | u8 pllml; | ||
60 | u8 pllmh; | ||
61 | u8 plldiv; | ||
62 | }; | ||
63 | |||
64 | /* ML26124 configuration */ | ||
65 | static const DECLARE_TLV_DB_SCALE(digital_tlv, -7150, 50, 0); | ||
66 | |||
67 | static const DECLARE_TLV_DB_SCALE(alclvl, -2250, 150, 0); | ||
68 | static const DECLARE_TLV_DB_SCALE(mingain, -1200, 600, 0); | ||
69 | static const DECLARE_TLV_DB_SCALE(maxgain, -675, 600, 0); | ||
70 | static const DECLARE_TLV_DB_SCALE(boost_vol, -1200, 75, 0); | ||
71 | static const DECLARE_TLV_DB_SCALE(ngth, -7650, 150, 0); | ||
72 | |||
73 | static const char * const ml26124_companding[] = {"16bit PCM", "u-law", | ||
74 | "A-law"}; | ||
75 | |||
76 | static const struct soc_enum ml26124_adc_companding_enum | ||
77 | = SOC_ENUM_SINGLE(ML26124_SAI_TRANS_CTL, 6, 3, ml26124_companding); | ||
78 | |||
79 | static const struct soc_enum ml26124_dac_companding_enum | ||
80 | = SOC_ENUM_SINGLE(ML26124_SAI_RCV_CTL, 6, 3, ml26124_companding); | ||
81 | |||
82 | static const struct snd_kcontrol_new ml26124_snd_controls[] = { | ||
83 | SOC_SINGLE_TLV("Capture Digital Volume", ML26124_RECORD_DIG_VOL, 0, | ||
84 | 0xff, 1, digital_tlv), | ||
85 | SOC_SINGLE_TLV("Playback Digital Volume", ML26124_PLBAK_DIG_VOL, 0, | ||
86 | 0xff, 1, digital_tlv), | ||
87 | SOC_SINGLE_TLV("Digital Boost Volume", ML26124_DIGI_BOOST_VOL, 0, | ||
88 | 0x3f, 0, boost_vol), | ||
89 | SOC_SINGLE_TLV("EQ Band0 Volume", ML26124_EQ_GAIN_BRAND0, 0, | ||
90 | 0xff, 1, digital_tlv), | ||
91 | SOC_SINGLE_TLV("EQ Band1 Volume", ML26124_EQ_GAIN_BRAND1, 0, | ||
92 | 0xff, 1, digital_tlv), | ||
93 | SOC_SINGLE_TLV("EQ Band2 Volume", ML26124_EQ_GAIN_BRAND2, 0, | ||
94 | 0xff, 1, digital_tlv), | ||
95 | SOC_SINGLE_TLV("EQ Band3 Volume", ML26124_EQ_GAIN_BRAND3, 0, | ||
96 | 0xff, 1, digital_tlv), | ||
97 | SOC_SINGLE_TLV("EQ Band4 Volume", ML26124_EQ_GAIN_BRAND4, 0, | ||
98 | 0xff, 1, digital_tlv), | ||
99 | SOC_SINGLE_TLV("ALC Target Level", ML26124_ALC_TARGET_LEV, 0, | ||
100 | 0xf, 1, alclvl), | ||
101 | SOC_SINGLE_TLV("ALC Min Input Volume", ML26124_ALC_MAXMIN_GAIN, 0, | ||
102 | 7, 0, mingain), | ||
103 | SOC_SINGLE_TLV("ALC Max Input Volume", ML26124_ALC_MAXMIN_GAIN, 4, | ||
104 | 7, 1, maxgain), | ||
105 | SOC_SINGLE_TLV("Playback Limiter Min Input Volume", | ||
106 | ML26124_PL_MAXMIN_GAIN, 0, 7, 0, mingain), | ||
107 | SOC_SINGLE_TLV("Playback Limiter Max Input Volume", | ||
108 | ML26124_PL_MAXMIN_GAIN, 4, 7, 1, maxgain), | ||
109 | SOC_SINGLE_TLV("Playback Boost Volume", ML26124_PLYBAK_BOST_VOL, 0, | ||
110 | 0x3f, 0, boost_vol), | ||
111 | SOC_SINGLE("DC High Pass Filter Switch", ML26124_FILTER_EN, 0, 1, 0), | ||
112 | SOC_SINGLE("Noise High Pass Filter Switch", ML26124_FILTER_EN, 1, 1, 0), | ||
113 | SOC_SINGLE("ZC Switch", ML26124_PW_ZCCMP_PW_MNG, 1, | ||
114 | 1, 0), | ||
115 | SOC_SINGLE("EQ Band0 Switch", ML26124_FILTER_EN, 2, 1, 0), | ||
116 | SOC_SINGLE("EQ Band1 Switch", ML26124_FILTER_EN, 3, 1, 0), | ||
117 | SOC_SINGLE("EQ Band2 Switch", ML26124_FILTER_EN, 4, 1, 0), | ||
118 | SOC_SINGLE("EQ Band3 Switch", ML26124_FILTER_EN, 5, 1, 0), | ||
119 | SOC_SINGLE("EQ Band4 Switch", ML26124_FILTER_EN, 6, 1, 0), | ||
120 | SOC_SINGLE("Play Limiter", ML26124_DVOL_CTL, 0, 1, 0), | ||
121 | SOC_SINGLE("Capture Limiter", ML26124_DVOL_CTL, 1, 1, 0), | ||
122 | SOC_SINGLE("Digital Volume Fade Switch", ML26124_DVOL_CTL, 3, 1, 0), | ||
123 | SOC_SINGLE("Digital Switch", ML26124_DVOL_CTL, 4, 1, 0), | ||
124 | SOC_ENUM("DAC Companding", ml26124_dac_companding_enum), | ||
125 | SOC_ENUM("ADC Companding", ml26124_adc_companding_enum), | ||
126 | }; | ||
127 | |||
128 | static const struct snd_kcontrol_new ml26124_output_mixer_controls[] = { | ||
129 | SOC_DAPM_SINGLE("DAC Switch", ML26124_SPK_AMP_OUT, 1, 1, 0), | ||
130 | SOC_DAPM_SINGLE("Line in loopback Switch", ML26124_SPK_AMP_OUT, 3, 1, | ||
131 | 0), | ||
132 | SOC_DAPM_SINGLE("PGA Switch", ML26124_SPK_AMP_OUT, 5, 1, 0), | ||
133 | }; | ||
134 | |||
135 | /* Input mux */ | ||
136 | static const char * const ml26124_input_select[] = {"Analog MIC SingleEnded in", | ||
137 | "Digital MIC in", "Analog MIC Differential in"}; | ||
138 | |||
139 | static const struct soc_enum ml26124_insel_enum = | ||
140 | SOC_ENUM_SINGLE(ML26124_MIC_IF_CTL, 0, 3, ml26124_input_select); | ||
141 | |||
142 | static const struct snd_kcontrol_new ml26124_input_mux_controls = | ||
143 | SOC_DAPM_ENUM("Input Select", ml26124_insel_enum); | ||
144 | |||
145 | static const struct snd_kcontrol_new ml26124_line_control = | ||
146 | SOC_DAPM_SINGLE("Switch", ML26124_PW_LOUT_PW_MNG, 1, 1, 0); | ||
147 | |||
148 | static const struct snd_soc_dapm_widget ml26124_dapm_widgets[] = { | ||
149 | SND_SOC_DAPM_SUPPLY("MCLKEN", ML26124_CLK_EN, 0, 0, NULL, 0), | ||
150 | SND_SOC_DAPM_SUPPLY("PLLEN", ML26124_CLK_EN, 1, 0, NULL, 0), | ||
151 | SND_SOC_DAPM_SUPPLY("PLLOE", ML26124_CLK_EN, 2, 0, NULL, 0), | ||
152 | SND_SOC_DAPM_SUPPLY("MICBIAS", ML26124_PW_REF_PW_MNG, 2, 0, NULL, 0), | ||
153 | SND_SOC_DAPM_MIXER("Output Mixer", SND_SOC_NOPM, 0, 0, | ||
154 | &ml26124_output_mixer_controls[0], | ||
155 | ARRAY_SIZE(ml26124_output_mixer_controls)), | ||
156 | SND_SOC_DAPM_DAC("DAC", "Playback", ML26124_PW_DAC_PW_MNG, 1, 0), | ||
157 | SND_SOC_DAPM_ADC("ADC", "Capture", ML26124_PW_IN_PW_MNG, 1, 0), | ||
158 | SND_SOC_DAPM_PGA("PGA", ML26124_PW_IN_PW_MNG, 3, 0, NULL, 0), | ||
159 | SND_SOC_DAPM_MUX("Input Mux", SND_SOC_NOPM, 0, 0, | ||
160 | &ml26124_input_mux_controls), | ||
161 | SND_SOC_DAPM_SWITCH("Line Out Enable", SND_SOC_NOPM, 0, 0, | ||
162 | &ml26124_line_control), | ||
163 | SND_SOC_DAPM_INPUT("MDIN"), | ||
164 | SND_SOC_DAPM_INPUT("MIN"), | ||
165 | SND_SOC_DAPM_INPUT("LIN"), | ||
166 | SND_SOC_DAPM_OUTPUT("SPOUT"), | ||
167 | SND_SOC_DAPM_OUTPUT("LOUT"), | ||
168 | }; | ||
169 | |||
170 | static const struct snd_soc_dapm_route ml26124_intercon[] = { | ||
171 | /* Supply */ | ||
172 | {"DAC", NULL, "MCLKEN"}, | ||
173 | {"ADC", NULL, "MCLKEN"}, | ||
174 | {"DAC", NULL, "PLLEN"}, | ||
175 | {"ADC", NULL, "PLLEN"}, | ||
176 | {"DAC", NULL, "PLLOE"}, | ||
177 | {"ADC", NULL, "PLLOE"}, | ||
178 | |||
179 | /* output mixer */ | ||
180 | {"Output Mixer", "DAC Switch", "DAC"}, | ||
181 | {"Output Mixer", "Line in loopback Switch", "LIN"}, | ||
182 | |||
183 | /* outputs */ | ||
184 | {"LOUT", NULL, "Output Mixer"}, | ||
185 | {"SPOUT", NULL, "Output Mixer"}, | ||
186 | {"Line Out Enable", NULL, "LOUT"}, | ||
187 | |||
188 | /* input */ | ||
189 | {"ADC", NULL, "Input Mux"}, | ||
190 | {"Input Mux", "Analog MIC SingleEnded in", "PGA"}, | ||
191 | {"Input Mux", "Analog MIC Differential in", "PGA"}, | ||
192 | {"PGA", NULL, "MIN"}, | ||
193 | }; | ||
194 | |||
195 | /* PLLOutputFreq(Hz) = InputMclkFreq(Hz) * PLLM / (PLLN * PLLDIV) */ | ||
196 | static const struct clk_coeff coeff_div[] = { | ||
197 | {12288000, 16000, 0xc, 0x0, 0x20, 0x0, 0x4}, | ||
198 | {12288000, 32000, 0xc, 0x0, 0x20, 0x0, 0x4}, | ||
199 | {12288000, 48000, 0xc, 0x0, 0x30, 0x0, 0x4}, | ||
200 | }; | ||
201 | |||
202 | static struct reg_default ml26124_reg[] = { | ||
203 | /* CLOCK control Register */ | ||
204 | {0x00, 0x00 }, /* Sampling Rate */ | ||
205 | {0x02, 0x00}, /* PLL NL */ | ||
206 | {0x04, 0x00}, /* PLLNH */ | ||
207 | {0x06, 0x00}, /* PLLML */ | ||
208 | {0x08, 0x00}, /* MLLMH */ | ||
209 | {0x0a, 0x00}, /* PLLDIV */ | ||
210 | {0x0c, 0x00}, /* Clock Enable */ | ||
211 | {0x0e, 0x00}, /* CLK Input/Output Control */ | ||
212 | |||
213 | /* System Control Register */ | ||
214 | {0x10, 0x00}, /* Software RESET */ | ||
215 | {0x12, 0x00}, /* Record/Playback Run */ | ||
216 | {0x14, 0x00}, /* Mic Input/Output control */ | ||
217 | |||
218 | /* Power Management Register */ | ||
219 | {0x20, 0x00}, /* Reference Power Management */ | ||
220 | {0x22, 0x00}, /* Input Power Management */ | ||
221 | {0x24, 0x00}, /* DAC Power Management */ | ||
222 | {0x26, 0x00}, /* SP-AMP Power Management */ | ||
223 | {0x28, 0x00}, /* LINEOUT Power Management */ | ||
224 | {0x2a, 0x00}, /* VIDEO Power Management */ | ||
225 | {0x2e, 0x00}, /* AC-CMP Power Management */ | ||
226 | |||
227 | /* Analog reference Control Register */ | ||
228 | {0x30, 0x04}, /* MICBIAS Voltage Control */ | ||
229 | |||
230 | /* Input/Output Amplifier Control Register */ | ||
231 | {0x32, 0x10}, /* MIC Input Volume */ | ||
232 | {0x38, 0x00}, /* Mic Boost Volume */ | ||
233 | {0x3a, 0x33}, /* Speaker AMP Volume */ | ||
234 | {0x48, 0x00}, /* AMP Volume Control Function Enable */ | ||
235 | {0x4a, 0x00}, /* Amplifier Volume Fader Control */ | ||
236 | |||
237 | /* Analog Path Control Register */ | ||
238 | {0x54, 0x00}, /* Speaker AMP Output Control */ | ||
239 | {0x5a, 0x00}, /* Mic IF Control */ | ||
240 | {0xe8, 0x01}, /* Mic Select Control */ | ||
241 | |||
242 | /* Audio Interface Control Register */ | ||
243 | {0x60, 0x00}, /* SAI-Trans Control */ | ||
244 | {0x62, 0x00}, /* SAI-Receive Control */ | ||
245 | {0x64, 0x00}, /* SAI Mode select */ | ||
246 | |||
247 | /* DSP Control Register */ | ||
248 | {0x66, 0x01}, /* Filter Func Enable */ | ||
249 | {0x68, 0x00}, /* Volume Control Func Enable */ | ||
250 | {0x6A, 0x00}, /* Mixer & Volume Control*/ | ||
251 | {0x6C, 0xff}, /* Record Digital Volume */ | ||
252 | {0x70, 0xff}, /* Playback Digital Volume */ | ||
253 | {0x72, 0x10}, /* Digital Boost Volume */ | ||
254 | {0x74, 0xe7}, /* EQ gain Band0 */ | ||
255 | {0x76, 0xe7}, /* EQ gain Band1 */ | ||
256 | {0x78, 0xe7}, /* EQ gain Band2 */ | ||
257 | {0x7A, 0xe7}, /* EQ gain Band3 */ | ||
258 | {0x7C, 0xe7}, /* EQ gain Band4 */ | ||
259 | {0x7E, 0x00}, /* HPF2 CutOff*/ | ||
260 | {0x80, 0x00}, /* EQ Band0 Coef0L */ | ||
261 | {0x82, 0x00}, /* EQ Band0 Coef0H */ | ||
262 | {0x84, 0x00}, /* EQ Band0 Coef0L */ | ||
263 | {0x86, 0x00}, /* EQ Band0 Coef0H */ | ||
264 | {0x88, 0x00}, /* EQ Band1 Coef0L */ | ||
265 | {0x8A, 0x00}, /* EQ Band1 Coef0H */ | ||
266 | {0x8C, 0x00}, /* EQ Band1 Coef0L */ | ||
267 | {0x8E, 0x00}, /* EQ Band1 Coef0H */ | ||
268 | {0x90, 0x00}, /* EQ Band2 Coef0L */ | ||
269 | {0x92, 0x00}, /* EQ Band2 Coef0H */ | ||
270 | {0x94, 0x00}, /* EQ Band2 Coef0L */ | ||
271 | {0x96, 0x00}, /* EQ Band2 Coef0H */ | ||
272 | {0x98, 0x00}, /* EQ Band3 Coef0L */ | ||
273 | {0x9A, 0x00}, /* EQ Band3 Coef0H */ | ||
274 | {0x9C, 0x00}, /* EQ Band3 Coef0L */ | ||
275 | {0x9E, 0x00}, /* EQ Band3 Coef0H */ | ||
276 | {0xA0, 0x00}, /* EQ Band4 Coef0L */ | ||
277 | {0xA2, 0x00}, /* EQ Band4 Coef0H */ | ||
278 | {0xA4, 0x00}, /* EQ Band4 Coef0L */ | ||
279 | {0xA6, 0x00}, /* EQ Band4 Coef0H */ | ||
280 | |||
281 | /* ALC Control Register */ | ||
282 | {0xb0, 0x00}, /* ALC Mode */ | ||
283 | {0xb2, 0x02}, /* ALC Attack Time */ | ||
284 | {0xb4, 0x03}, /* ALC Decay Time */ | ||
285 | {0xb6, 0x00}, /* ALC Hold Time */ | ||
286 | {0xb8, 0x0b}, /* ALC Target Level */ | ||
287 | {0xba, 0x70}, /* ALC Max/Min Gain */ | ||
288 | {0xbc, 0x00}, /* Noise Gate Threshold */ | ||
289 | {0xbe, 0x00}, /* ALC ZeroCross TimeOut */ | ||
290 | |||
291 | /* Playback Limiter Control Register */ | ||
292 | {0xc0, 0x04}, /* PL Attack Time */ | ||
293 | {0xc2, 0x05}, /* PL Decay Time */ | ||
294 | {0xc4, 0x0d}, /* PL Target Level */ | ||
295 | {0xc6, 0x70}, /* PL Max/Min Gain */ | ||
296 | {0xc8, 0x10}, /* Playback Boost Volume */ | ||
297 | {0xca, 0x00}, /* PL ZeroCross TimeOut */ | ||
298 | |||
299 | /* Video Amplifier Control Register */ | ||
300 | {0xd0, 0x01}, /* VIDEO AMP Gain Control */ | ||
301 | {0xd2, 0x01}, /* VIDEO AMP Setup 1 */ | ||
302 | {0xd4, 0x01}, /* VIDEO AMP Control2 */ | ||
303 | }; | ||
304 | |||
305 | /* Get sampling rate value of sampling rate setting register (0x0) */ | ||
306 | static inline int get_srate(int rate) | ||
307 | { | ||
308 | int srate; | ||
309 | |||
310 | switch (rate) { | ||
311 | case 16000: | ||
312 | srate = 3; | ||
313 | break; | ||
314 | case 32000: | ||
315 | srate = 6; | ||
316 | break; | ||
317 | case 48000: | ||
318 | srate = 8; | ||
319 | break; | ||
320 | default: | ||
321 | return -EINVAL; | ||
322 | } | ||
323 | return srate; | ||
324 | } | ||
325 | |||
326 | static inline int get_coeff(int mclk, int rate) | ||
327 | { | ||
328 | int i; | ||
329 | |||
330 | for (i = 0; i < ARRAY_SIZE(coeff_div); i++) { | ||
331 | if (coeff_div[i].rate == rate && coeff_div[i].mclk == mclk) | ||
332 | return i; | ||
333 | } | ||
334 | return -EINVAL; | ||
335 | } | ||
336 | |||
337 | static int ml26124_hw_params(struct snd_pcm_substream *substream, | ||
338 | struct snd_pcm_hw_params *hw_params, | ||
339 | struct snd_soc_dai *dai) | ||
340 | { | ||
341 | struct snd_soc_codec *codec = dai->codec; | ||
342 | struct ml26124_priv *priv = snd_soc_codec_get_drvdata(codec); | ||
343 | int i = get_coeff(priv->mclk, params_rate(hw_params)); | ||
344 | |||
345 | priv->substream = substream; | ||
346 | priv->rate = params_rate(hw_params); | ||
347 | |||
348 | if (priv->clk_in) { | ||
349 | switch (priv->mclk / params_rate(hw_params)) { | ||
350 | case 256: | ||
351 | snd_soc_update_bits(codec, ML26124_CLK_CTL, | ||
352 | BIT(0) | BIT(1), 1); | ||
353 | break; | ||
354 | case 512: | ||
355 | snd_soc_update_bits(codec, ML26124_CLK_CTL, | ||
356 | BIT(0) | BIT(1), 2); | ||
357 | break; | ||
358 | case 1024: | ||
359 | snd_soc_update_bits(codec, ML26124_CLK_CTL, | ||
360 | BIT(0) | BIT(1), 3); | ||
361 | break; | ||
362 | default: | ||
363 | dev_err(codec->dev, "Unsupported MCLKI\n"); | ||
364 | break; | ||
365 | } | ||
366 | } else { | ||
367 | snd_soc_update_bits(codec, ML26124_CLK_CTL, | ||
368 | BIT(0) | BIT(1), 0); | ||
369 | } | ||
370 | |||
371 | switch (params_rate(hw_params)) { | ||
372 | case 16000: | ||
373 | snd_soc_update_bits(codec, ML26124_SMPLING_RATE, 0xf, | ||
374 | get_srate(params_rate(hw_params))); | ||
375 | snd_soc_update_bits(codec, ML26124_PLLNL, 0xff, | ||
376 | coeff_div[i].pllnl); | ||
377 | snd_soc_update_bits(codec, ML26124_PLLNH, 0x1, | ||
378 | coeff_div[i].pllnh); | ||
379 | snd_soc_update_bits(codec, ML26124_PLLML, 0xff, | ||
380 | coeff_div[i].pllml); | ||
381 | snd_soc_update_bits(codec, ML26124_PLLMH, 0x3f, | ||
382 | coeff_div[i].pllmh); | ||
383 | snd_soc_update_bits(codec, ML26124_PLLDIV, 0x1f, | ||
384 | coeff_div[i].plldiv); | ||
385 | break; | ||
386 | case 32000: | ||
387 | snd_soc_update_bits(codec, ML26124_SMPLING_RATE, 0xf, | ||
388 | get_srate(params_rate(hw_params))); | ||
389 | snd_soc_update_bits(codec, ML26124_PLLNL, 0xff, | ||
390 | coeff_div[i].pllnl); | ||
391 | snd_soc_update_bits(codec, ML26124_PLLNH, 0x1, | ||
392 | coeff_div[i].pllnh); | ||
393 | snd_soc_update_bits(codec, ML26124_PLLML, 0xff, | ||
394 | coeff_div[i].pllml); | ||
395 | snd_soc_update_bits(codec, ML26124_PLLMH, 0x3f, | ||
396 | coeff_div[i].pllmh); | ||
397 | snd_soc_update_bits(codec, ML26124_PLLDIV, 0x1f, | ||
398 | coeff_div[i].plldiv); | ||
399 | break; | ||
400 | case 48000: | ||
401 | snd_soc_update_bits(codec, ML26124_SMPLING_RATE, 0xf, | ||
402 | get_srate(params_rate(hw_params))); | ||
403 | snd_soc_update_bits(codec, ML26124_PLLNL, 0xff, | ||
404 | coeff_div[i].pllnl); | ||
405 | snd_soc_update_bits(codec, ML26124_PLLNH, 0x1, | ||
406 | coeff_div[i].pllnh); | ||
407 | snd_soc_update_bits(codec, ML26124_PLLML, 0xff, | ||
408 | coeff_div[i].pllml); | ||
409 | snd_soc_update_bits(codec, ML26124_PLLMH, 0x3f, | ||
410 | coeff_div[i].pllmh); | ||
411 | snd_soc_update_bits(codec, ML26124_PLLDIV, 0x1f, | ||
412 | coeff_div[i].plldiv); | ||
413 | break; | ||
414 | default: | ||
415 | pr_err("%s:this rate is no support for ml26124\n", __func__); | ||
416 | return -EINVAL; | ||
417 | } | ||
418 | |||
419 | return 0; | ||
420 | } | ||
421 | |||
422 | static int ml26124_mute(struct snd_soc_dai *dai, int mute) | ||
423 | { | ||
424 | struct snd_soc_codec *codec = dai->codec; | ||
425 | struct ml26124_priv *priv = snd_soc_codec_get_drvdata(codec); | ||
426 | |||
427 | switch (priv->substream->stream) { | ||
428 | case SNDRV_PCM_STREAM_CAPTURE: | ||
429 | snd_soc_update_bits(codec, ML26124_REC_PLYBAK_RUN, BIT(0), 1); | ||
430 | break; | ||
431 | case SNDRV_PCM_STREAM_PLAYBACK: | ||
432 | snd_soc_update_bits(codec, ML26124_REC_PLYBAK_RUN, BIT(1), 2); | ||
433 | break; | ||
434 | } | ||
435 | |||
436 | if (mute) | ||
437 | snd_soc_update_bits(codec, ML26124_DVOL_CTL, BIT(4), | ||
438 | DVOL_CTL_DVMUTE_ON); | ||
439 | else | ||
440 | snd_soc_update_bits(codec, ML26124_DVOL_CTL, BIT(4), | ||
441 | DVOL_CTL_DVMUTE_OFF); | ||
442 | |||
443 | return 0; | ||
444 | } | ||
445 | |||
446 | static int ml26124_set_dai_fmt(struct snd_soc_dai *codec_dai, | ||
447 | unsigned int fmt) | ||
448 | { | ||
449 | unsigned char mode; | ||
450 | struct snd_soc_codec *codec = codec_dai->codec; | ||
451 | |||
452 | /* set master/slave audio interface */ | ||
453 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { | ||
454 | case SND_SOC_DAIFMT_CBM_CFM: | ||
455 | mode = 1; | ||
456 | break; | ||
457 | case SND_SOC_DAIFMT_CBS_CFS: | ||
458 | mode = 0; | ||
459 | break; | ||
460 | default: | ||
461 | return -EINVAL; | ||
462 | } | ||
463 | snd_soc_update_bits(codec, ML26124_SAI_MODE_SEL, BIT(0), mode); | ||
464 | |||
465 | /* interface format */ | ||
466 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { | ||
467 | case SND_SOC_DAIFMT_I2S: | ||
468 | break; | ||
469 | default: | ||
470 | return -EINVAL; | ||
471 | } | ||
472 | |||
473 | /* clock inversion */ | ||
474 | switch (fmt & SND_SOC_DAIFMT_INV_MASK) { | ||
475 | case SND_SOC_DAIFMT_NB_NF: | ||
476 | break; | ||
477 | default: | ||
478 | return -EINVAL; | ||
479 | } | ||
480 | |||
481 | return 0; | ||
482 | } | ||
483 | |||
484 | static int ml26124_set_dai_sysclk(struct snd_soc_dai *codec_dai, | ||
485 | int clk_id, unsigned int freq, int dir) | ||
486 | { | ||
487 | struct snd_soc_codec *codec = codec_dai->codec; | ||
488 | struct ml26124_priv *priv = snd_soc_codec_get_drvdata(codec); | ||
489 | |||
490 | switch (clk_id) { | ||
491 | case ML26124_USE_PLLOUT: | ||
492 | priv->clk_in = ML26124_USE_PLLOUT; | ||
493 | break; | ||
494 | case ML26124_USE_MCLKI: | ||
495 | priv->clk_in = ML26124_USE_MCLKI; | ||
496 | break; | ||
497 | default: | ||
498 | return -EINVAL; | ||
499 | } | ||
500 | |||
501 | priv->mclk = freq; | ||
502 | |||
503 | return 0; | ||
504 | } | ||
505 | |||
506 | static int ml26124_set_bias_level(struct snd_soc_codec *codec, | ||
507 | enum snd_soc_bias_level level) | ||
508 | { | ||
509 | struct ml26124_priv *priv = snd_soc_codec_get_drvdata(codec); | ||
510 | |||
511 | switch (level) { | ||
512 | case SND_SOC_BIAS_ON: | ||
513 | snd_soc_update_bits(codec, ML26124_PW_SPAMP_PW_MNG, | ||
514 | ML26124_R26_MASK, ML26124_BLT_PREAMP_ON); | ||
515 | msleep(100); | ||
516 | snd_soc_update_bits(codec, ML26124_PW_SPAMP_PW_MNG, | ||
517 | ML26124_R26_MASK, | ||
518 | ML26124_MICBEN_ON | ML26124_BLT_ALL_ON); | ||
519 | break; | ||
520 | case SND_SOC_BIAS_PREPARE: | ||
521 | break; | ||
522 | case SND_SOC_BIAS_STANDBY: | ||
523 | /* VMID ON */ | ||
524 | if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { | ||
525 | snd_soc_update_bits(codec, ML26124_PW_REF_PW_MNG, | ||
526 | ML26124_VMID, ML26124_VMID); | ||
527 | msleep(500); | ||
528 | regcache_sync(priv->regmap); | ||
529 | } | ||
530 | break; | ||
531 | case SND_SOC_BIAS_OFF: | ||
532 | /* VMID OFF */ | ||
533 | snd_soc_update_bits(codec, ML26124_PW_REF_PW_MNG, | ||
534 | ML26124_VMID, 0); | ||
535 | break; | ||
536 | } | ||
537 | codec->dapm.bias_level = level; | ||
538 | return 0; | ||
539 | } | ||
540 | |||
541 | static const struct snd_soc_dai_ops ml26124_dai_ops = { | ||
542 | .hw_params = ml26124_hw_params, | ||
543 | .digital_mute = ml26124_mute, | ||
544 | .set_fmt = ml26124_set_dai_fmt, | ||
545 | .set_sysclk = ml26124_set_dai_sysclk, | ||
546 | }; | ||
547 | |||
548 | static struct snd_soc_dai_driver ml26124_dai = { | ||
549 | .name = "ml26124-hifi", | ||
550 | .playback = { | ||
551 | .stream_name = "Playback", | ||
552 | .channels_min = 1, | ||
553 | .channels_max = 2, | ||
554 | .rates = ML26124_RATES, | ||
555 | .formats = ML26124_FORMATS,}, | ||
556 | .capture = { | ||
557 | .stream_name = "Capture", | ||
558 | .channels_min = 1, | ||
559 | .channels_max = 2, | ||
560 | .rates = ML26124_RATES, | ||
561 | .formats = ML26124_FORMATS,}, | ||
562 | .ops = &ml26124_dai_ops, | ||
563 | .symmetric_rates = 1, | ||
564 | }; | ||
565 | |||
566 | #ifdef CONFIG_PM | ||
567 | static int ml26124_suspend(struct snd_soc_codec *codec) | ||
568 | { | ||
569 | ml26124_set_bias_level(codec, SND_SOC_BIAS_OFF); | ||
570 | |||
571 | return 0; | ||
572 | } | ||
573 | |||
574 | static int ml26124_resume(struct snd_soc_codec *codec) | ||
575 | { | ||
576 | ml26124_set_bias_level(codec, SND_SOC_BIAS_STANDBY); | ||
577 | |||
578 | return 0; | ||
579 | } | ||
580 | #else | ||
581 | #define ml26124_suspend NULL | ||
582 | #define ml26124_resume NULL | ||
583 | #endif | ||
584 | |||
585 | static int ml26124_probe(struct snd_soc_codec *codec) | ||
586 | { | ||
587 | int ret; | ||
588 | struct ml26124_priv *priv = snd_soc_codec_get_drvdata(codec); | ||
589 | codec->control_data = priv->regmap; | ||
590 | |||
591 | ret = snd_soc_codec_set_cache_io(codec, 7, 9, SND_SOC_REGMAP); | ||
592 | if (ret < 0) { | ||
593 | dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); | ||
594 | return ret; | ||
595 | } | ||
596 | |||
597 | /* Software Reset */ | ||
598 | snd_soc_update_bits(codec, ML26124_SW_RST, 0x01, 1); | ||
599 | snd_soc_update_bits(codec, ML26124_SW_RST, 0x01, 0); | ||
600 | |||
601 | ml26124_set_bias_level(codec, SND_SOC_BIAS_STANDBY); | ||
602 | |||
603 | return 0; | ||
604 | } | ||
605 | |||
606 | static struct snd_soc_codec_driver soc_codec_dev_ml26124 = { | ||
607 | .probe = ml26124_probe, | ||
608 | .suspend = ml26124_suspend, | ||
609 | .resume = ml26124_resume, | ||
610 | .set_bias_level = ml26124_set_bias_level, | ||
611 | .dapm_widgets = ml26124_dapm_widgets, | ||
612 | .num_dapm_widgets = ARRAY_SIZE(ml26124_dapm_widgets), | ||
613 | .dapm_routes = ml26124_intercon, | ||
614 | .num_dapm_routes = ARRAY_SIZE(ml26124_intercon), | ||
615 | .controls = ml26124_snd_controls, | ||
616 | .num_controls = ARRAY_SIZE(ml26124_snd_controls), | ||
617 | }; | ||
618 | |||
619 | static const struct regmap_config ml26124_i2c_regmap = { | ||
620 | .val_bits = 8, | ||
621 | .reg_bits = 8, | ||
622 | .max_register = ML26124_NUM_REGISTER, | ||
623 | .reg_defaults = ml26124_reg, | ||
624 | .num_reg_defaults = ARRAY_SIZE(ml26124_reg), | ||
625 | .cache_type = REGCACHE_RBTREE, | ||
626 | .write_flag_mask = 0x01, | ||
627 | }; | ||
628 | |||
629 | static __devinit int ml26124_i2c_probe(struct i2c_client *i2c, | ||
630 | const struct i2c_device_id *id) | ||
631 | { | ||
632 | struct ml26124_priv *priv; | ||
633 | int ret; | ||
634 | |||
635 | priv = devm_kzalloc(&i2c->dev, sizeof(*priv), GFP_KERNEL); | ||
636 | if (!priv) | ||
637 | return -ENOMEM; | ||
638 | |||
639 | i2c_set_clientdata(i2c, priv); | ||
640 | |||
641 | priv->regmap = regmap_init_i2c(i2c, &ml26124_i2c_regmap); | ||
642 | if (IS_ERR(priv->regmap)) { | ||
643 | ret = PTR_ERR(priv->regmap); | ||
644 | dev_err(&i2c->dev, "regmap_init_i2c() failed: %d\n", ret); | ||
645 | return ret; | ||
646 | } | ||
647 | |||
648 | return snd_soc_register_codec(&i2c->dev, | ||
649 | &soc_codec_dev_ml26124, &ml26124_dai, 1); | ||
650 | } | ||
651 | |||
652 | static __devexit int ml26124_i2c_remove(struct i2c_client *client) | ||
653 | { | ||
654 | struct ml26124_priv *priv = i2c_get_clientdata(client); | ||
655 | |||
656 | snd_soc_unregister_codec(&client->dev); | ||
657 | regmap_exit(priv->regmap); | ||
658 | return 0; | ||
659 | } | ||
660 | |||
661 | static const struct i2c_device_id ml26124_i2c_id[] = { | ||
662 | { "ml26124", 0 }, | ||
663 | { } | ||
664 | }; | ||
665 | MODULE_DEVICE_TABLE(i2c, ml26124_i2c_id); | ||
666 | |||
667 | static struct i2c_driver ml26124_i2c_driver = { | ||
668 | .driver = { | ||
669 | .name = "ml26124", | ||
670 | .owner = THIS_MODULE, | ||
671 | }, | ||
672 | .probe = ml26124_i2c_probe, | ||
673 | .remove = __devexit_p(ml26124_i2c_remove), | ||
674 | .id_table = ml26124_i2c_id, | ||
675 | }; | ||
676 | |||
677 | module_i2c_driver(ml26124_i2c_driver); | ||
678 | |||
679 | MODULE_AUTHOR("Tomoya MORINAGA <tomoya.rohm@gmail.com>"); | ||
680 | MODULE_DESCRIPTION("LAPIS Semiconductor ML26124 ALSA SoC codec driver"); | ||
681 | MODULE_LICENSE("GPL"); | ||
diff --git a/sound/soc/codecs/ml26124.h b/sound/soc/codecs/ml26124.h new file mode 100644 index 000000000000..5ea0cbb8c46c --- /dev/null +++ b/sound/soc/codecs/ml26124.h | |||
@@ -0,0 +1,184 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2011 LAPIS Semiconductor Co., Ltd. | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License as published by | ||
6 | * the Free Software Foundation; version 2 of the License. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program; if not, write to the Free Software | ||
15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. | ||
16 | */ | ||
17 | |||
18 | #ifndef ML26124_H | ||
19 | #define ML26124_H | ||
20 | |||
21 | /* Clock Control Register */ | ||
22 | #define ML26124_SMPLING_RATE 0x00 | ||
23 | #define ML26124_PLLNL 0x02 | ||
24 | #define ML26124_PLLNH 0x04 | ||
25 | #define ML26124_PLLML 0x06 | ||
26 | #define ML26124_PLLMH 0x08 | ||
27 | #define ML26124_PLLDIV 0x0a | ||
28 | #define ML26124_CLK_EN 0x0c | ||
29 | #define ML26124_CLK_CTL 0x0e | ||
30 | |||
31 | /* System Control Register */ | ||
32 | #define ML26124_SW_RST 0x10 | ||
33 | #define ML26124_REC_PLYBAK_RUN 0x12 | ||
34 | #define ML26124_MIC_TIM 0x14 | ||
35 | |||
36 | /* Power Mnagement Register */ | ||
37 | #define ML26124_PW_REF_PW_MNG 0x20 | ||
38 | #define ML26124_PW_IN_PW_MNG 0x22 | ||
39 | #define ML26124_PW_DAC_PW_MNG 0x24 | ||
40 | #define ML26124_PW_SPAMP_PW_MNG 0x26 | ||
41 | #define ML26124_PW_LOUT_PW_MNG 0x28 | ||
42 | #define ML26124_PW_VOUT_PW_MNG 0x2a | ||
43 | #define ML26124_PW_ZCCMP_PW_MNG 0x2e | ||
44 | |||
45 | /* Analog Reference Control Register */ | ||
46 | #define ML26124_PW_MICBIAS_VOL 0x30 | ||
47 | |||
48 | /* Input/Output Amplifier Control Register */ | ||
49 | #define ML26124_PW_MIC_IN_VOL 0x32 | ||
50 | #define ML26124_PW_MIC_BOST_VOL 0x38 | ||
51 | #define ML26124_PW_SPK_AMP_VOL 0x3a | ||
52 | #define ML26124_PW_AMP_VOL_FUNC 0x48 | ||
53 | #define ML26124_PW_AMP_VOL_FADE 0x4a | ||
54 | |||
55 | /* Analog Path Control Register */ | ||
56 | #define ML26124_SPK_AMP_OUT 0x54 | ||
57 | #define ML26124_MIC_IF_CTL 0x5a | ||
58 | #define ML26124_MIC_SELECT 0xe8 | ||
59 | |||
60 | /* Audio Interface Control Register */ | ||
61 | #define ML26124_SAI_TRANS_CTL 0x60 | ||
62 | #define ML26124_SAI_RCV_CTL 0x62 | ||
63 | #define ML26124_SAI_MODE_SEL 0x64 | ||
64 | |||
65 | /* DSP Control Register */ | ||
66 | #define ML26124_FILTER_EN 0x66 | ||
67 | #define ML26124_DVOL_CTL 0x68 | ||
68 | #define ML26124_MIXER_VOL_CTL 0x6a | ||
69 | #define ML26124_RECORD_DIG_VOL 0x6c | ||
70 | #define ML26124_PLBAK_DIG_VOL 0x70 | ||
71 | #define ML26124_DIGI_BOOST_VOL 0x72 | ||
72 | #define ML26124_EQ_GAIN_BRAND0 0x74 | ||
73 | #define ML26124_EQ_GAIN_BRAND1 0x76 | ||
74 | #define ML26124_EQ_GAIN_BRAND2 0x78 | ||
75 | #define ML26124_EQ_GAIN_BRAND3 0x7a | ||
76 | #define ML26124_EQ_GAIN_BRAND4 0x7c | ||
77 | #define ML26124_HPF2_CUTOFF 0x7e | ||
78 | #define ML26124_EQBRAND0_F0L 0x80 | ||
79 | #define ML26124_EQBRAND0_F0H 0x82 | ||
80 | #define ML26124_EQBRAND0_F1L 0x84 | ||
81 | #define ML26124_EQBRAND0_F1H 0x86 | ||
82 | #define ML26124_EQBRAND1_F0L 0x88 | ||
83 | #define ML26124_EQBRAND1_F0H 0x8a | ||
84 | #define ML26124_EQBRAND1_F1L 0x8c | ||
85 | #define ML26124_EQBRAND1_F1H 0x8e | ||
86 | #define ML26124_EQBRAND2_F0L 0x90 | ||
87 | #define ML26124_EQBRAND2_F0H 0x92 | ||
88 | #define ML26124_EQBRAND2_F1L 0x94 | ||
89 | #define ML26124_EQBRAND2_F1H 0x96 | ||
90 | #define ML26124_EQBRAND3_F0L 0x98 | ||
91 | #define ML26124_EQBRAND3_F0H 0x9a | ||
92 | #define ML26124_EQBRAND3_F1L 0x9c | ||
93 | #define ML26124_EQBRAND3_F1H 0x9e | ||
94 | #define ML26124_EQBRAND4_F0L 0xa0 | ||
95 | #define ML26124_EQBRAND4_F0H 0xa2 | ||
96 | #define ML26124_EQBRAND4_F1L 0xa4 | ||
97 | #define ML26124_EQBRAND4_F1H 0xa6 | ||
98 | |||
99 | /* ALC Control Register */ | ||
100 | #define ML26124_ALC_MODE 0xb0 | ||
101 | #define ML26124_ALC_ATTACK_TIM 0xb2 | ||
102 | #define ML26124_ALC_DECAY_TIM 0xb4 | ||
103 | #define ML26124_ALC_HOLD_TIM 0xb6 | ||
104 | #define ML26124_ALC_TARGET_LEV 0xb8 | ||
105 | #define ML26124_ALC_MAXMIN_GAIN 0xba | ||
106 | #define ML26124_NOIS_GATE_THRSH 0xbc | ||
107 | #define ML26124_ALC_ZERO_TIMOUT 0xbe | ||
108 | |||
109 | /* Playback Limiter Control Register */ | ||
110 | #define ML26124_PL_ATTACKTIME 0xc0 | ||
111 | #define ML26124_PL_DECAYTIME 0xc2 | ||
112 | #define ML26124_PL_TARGETTIME 0xc4 | ||
113 | #define ML26124_PL_MAXMIN_GAIN 0xc6 | ||
114 | #define ML26124_PLYBAK_BOST_VOL 0xc8 | ||
115 | #define ML26124_PL_0CROSS_TIMOUT 0xca | ||
116 | |||
117 | /* Video Amplifer Control Register */ | ||
118 | #define ML26124_VIDEO_AMP_GAIN_CTL 0xd0 | ||
119 | #define ML26124_VIDEO_AMP_SETUP1 0xd2 | ||
120 | #define ML26124_VIDEO_AMP_CTL2 0xd4 | ||
121 | |||
122 | /* Clock select for machine driver */ | ||
123 | #define ML26124_USE_PLL 0 | ||
124 | #define ML26124_USE_MCLKI_256FS 1 | ||
125 | #define ML26124_USE_MCLKI_512FS 2 | ||
126 | #define ML26124_USE_MCLKI_1024FS 3 | ||
127 | |||
128 | /* Register Mask */ | ||
129 | #define ML26124_R0_MASK 0xf | ||
130 | #define ML26124_R2_MASK 0xff | ||
131 | #define ML26124_R4_MASK 0x1 | ||
132 | #define ML26124_R6_MASK 0xf | ||
133 | #define ML26124_R8_MASK 0x3f | ||
134 | #define ML26124_Ra_MASK 0x1f | ||
135 | #define ML26124_Rc_MASK 0x1f | ||
136 | #define ML26124_Re_MASK 0x7 | ||
137 | #define ML26124_R10_MASK 0x1 | ||
138 | #define ML26124_R12_MASK 0x17 | ||
139 | #define ML26124_R14_MASK 0x3f | ||
140 | #define ML26124_R20_MASK 0x47 | ||
141 | #define ML26124_R22_MASK 0xa | ||
142 | #define ML26124_R24_MASK 0x2 | ||
143 | #define ML26124_R26_MASK 0x1f | ||
144 | #define ML26124_R28_MASK 0x2 | ||
145 | #define ML26124_R2a_MASK 0x2 | ||
146 | #define ML26124_R2e_MASK 0x2 | ||
147 | #define ML26124_R30_MASK 0x7 | ||
148 | #define ML26124_R32_MASK 0x3f | ||
149 | #define ML26124_R38_MASK 0x38 | ||
150 | #define ML26124_R3a_MASK 0x3f | ||
151 | #define ML26124_R48_MASK 0x3 | ||
152 | #define ML26124_R4a_MASK 0x7 | ||
153 | #define ML26124_R54_MASK 0x2a | ||
154 | #define ML26124_R5a_MASK 0x3 | ||
155 | #define ML26124_Re8_MASK 0x3 | ||
156 | #define ML26124_R60_MASK 0xff | ||
157 | #define ML26124_R62_MASK 0xff | ||
158 | #define ML26124_R64_MASK 0x1 | ||
159 | #define ML26124_R66_MASK 0xff | ||
160 | #define ML26124_R68_MASK 0x3b | ||
161 | #define ML26124_R6a_MASK 0xf3 | ||
162 | #define ML26124_R6c_MASK 0xff | ||
163 | #define ML26124_R70_MASK 0xff | ||
164 | |||
165 | #define ML26124_MCLKEN BIT(0) | ||
166 | #define ML26124_PLLEN BIT(1) | ||
167 | #define ML26124_PLLOE BIT(2) | ||
168 | #define ML26124_MCLKOE BIT(3) | ||
169 | |||
170 | #define ML26124_BLT_ALL_ON 0x1f | ||
171 | #define ML26124_BLT_PREAMP_ON 0x13 | ||
172 | |||
173 | #define ML26124_MICBEN_ON BIT(2) | ||
174 | |||
175 | enum ml26124_regs { | ||
176 | ML26124_MCLK = 0, | ||
177 | }; | ||
178 | |||
179 | enum ml26124_clk_in { | ||
180 | ML26124_USE_PLLOUT = 0, | ||
181 | ML26124_USE_MCLKI, | ||
182 | }; | ||
183 | |||
184 | #endif | ||
diff --git a/sound/soc/codecs/omap-hdmi.c b/sound/soc/codecs/omap-hdmi.c new file mode 100644 index 000000000000..1bf5c74f5f96 --- /dev/null +++ b/sound/soc/codecs/omap-hdmi.c | |||
@@ -0,0 +1,69 @@ | |||
1 | /* | ||
2 | * ALSA SoC codec driver for HDMI audio on OMAP processors. | ||
3 | * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/ | ||
4 | * Author: Ricardo Neri <ricardo.neri@ti.com> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU General Public License | ||
8 | * version 2 as published by the Free Software Foundation. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, but | ||
11 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | * General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, write to the Free Software | ||
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
18 | * 02110-1301 USA | ||
19 | * | ||
20 | */ | ||
21 | #include <linux/module.h> | ||
22 | #include <sound/soc.h> | ||
23 | |||
24 | #define DRV_NAME "hdmi-audio-codec" | ||
25 | |||
26 | static struct snd_soc_codec_driver omap_hdmi_codec; | ||
27 | |||
28 | static struct snd_soc_dai_driver omap_hdmi_codec_dai = { | ||
29 | .name = "omap-hdmi-hifi", | ||
30 | .playback = { | ||
31 | .channels_min = 2, | ||
32 | .channels_max = 8, | ||
33 | .rates = SNDRV_PCM_RATE_32000 | | ||
34 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 | | ||
35 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 | | ||
36 | SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_192000, | ||
37 | .formats = SNDRV_PCM_FMTBIT_S16_LE | | ||
38 | SNDRV_PCM_FMTBIT_S24_LE, | ||
39 | }, | ||
40 | }; | ||
41 | |||
42 | static __devinit int omap_hdmi_codec_probe(struct platform_device *pdev) | ||
43 | { | ||
44 | return snd_soc_register_codec(&pdev->dev, &omap_hdmi_codec, | ||
45 | &omap_hdmi_codec_dai, 1); | ||
46 | } | ||
47 | |||
48 | static __devexit int omap_hdmi_codec_remove(struct platform_device *pdev) | ||
49 | { | ||
50 | snd_soc_unregister_codec(&pdev->dev); | ||
51 | return 0; | ||
52 | } | ||
53 | |||
54 | static struct platform_driver omap_hdmi_codec_driver = { | ||
55 | .driver = { | ||
56 | .name = DRV_NAME, | ||
57 | .owner = THIS_MODULE, | ||
58 | }, | ||
59 | |||
60 | .probe = omap_hdmi_codec_probe, | ||
61 | .remove = __devexit_p(omap_hdmi_codec_remove), | ||
62 | }; | ||
63 | |||
64 | module_platform_driver(omap_hdmi_codec_driver); | ||
65 | |||
66 | MODULE_AUTHOR("Ricardo Neri <ricardo.neri@ti.com>"); | ||
67 | MODULE_DESCRIPTION("ASoC OMAP HDMI codec driver"); | ||
68 | MODULE_LICENSE("GPL"); | ||
69 | MODULE_ALIAS("platform:" DRV_NAME); | ||
diff --git a/sound/soc/codecs/rt5631.c b/sound/soc/codecs/rt5631.c index 20c324c7c349..960d0e93cce9 100644 --- a/sound/soc/codecs/rt5631.c +++ b/sound/soc/codecs/rt5631.c | |||
@@ -18,7 +18,7 @@ | |||
18 | #include <linux/delay.h> | 18 | #include <linux/delay.h> |
19 | #include <linux/pm.h> | 19 | #include <linux/pm.h> |
20 | #include <linux/i2c.h> | 20 | #include <linux/i2c.h> |
21 | #include <linux/spi/spi.h> | 21 | #include <linux/regmap.h> |
22 | #include <sound/core.h> | 22 | #include <sound/core.h> |
23 | #include <sound/pcm.h> | 23 | #include <sound/pcm.h> |
24 | #include <sound/pcm_params.h> | 24 | #include <sound/pcm_params.h> |
@@ -30,6 +30,7 @@ | |||
30 | #include "rt5631.h" | 30 | #include "rt5631.h" |
31 | 31 | ||
32 | struct rt5631_priv { | 32 | struct rt5631_priv { |
33 | struct regmap *regmap; | ||
33 | int codec_version; | 34 | int codec_version; |
34 | int master; | 35 | int master; |
35 | int sysclk; | 36 | int sysclk; |
@@ -38,33 +39,33 @@ struct rt5631_priv { | |||
38 | int dmic_used_flag; | 39 | int dmic_used_flag; |
39 | }; | 40 | }; |
40 | 41 | ||
41 | static const u16 rt5631_reg[RT5631_VENDOR_ID2 + 1] = { | 42 | static const struct reg_default rt5631_reg[] = { |
42 | [RT5631_SPK_OUT_VOL] = 0x8888, | 43 | { RT5631_SPK_OUT_VOL, 0x8888 }, |
43 | [RT5631_HP_OUT_VOL] = 0x8080, | 44 | { RT5631_HP_OUT_VOL, 0x8080 }, |
44 | [RT5631_MONO_AXO_1_2_VOL] = 0xa080, | 45 | { RT5631_MONO_AXO_1_2_VOL, 0xa080 }, |
45 | [RT5631_AUX_IN_VOL] = 0x0808, | 46 | { RT5631_AUX_IN_VOL, 0x0808 }, |
46 | [RT5631_ADC_REC_MIXER] = 0xf0f0, | 47 | { RT5631_ADC_REC_MIXER, 0xf0f0 }, |
47 | [RT5631_VDAC_DIG_VOL] = 0x0010, | 48 | { RT5631_VDAC_DIG_VOL, 0x0010 }, |
48 | [RT5631_OUTMIXER_L_CTRL] = 0xffc0, | 49 | { RT5631_OUTMIXER_L_CTRL, 0xffc0 }, |
49 | [RT5631_OUTMIXER_R_CTRL] = 0xffc0, | 50 | { RT5631_OUTMIXER_R_CTRL, 0xffc0 }, |
50 | [RT5631_AXO1MIXER_CTRL] = 0x88c0, | 51 | { RT5631_AXO1MIXER_CTRL, 0x88c0 }, |
51 | [RT5631_AXO2MIXER_CTRL] = 0x88c0, | 52 | { RT5631_AXO2MIXER_CTRL, 0x88c0 }, |
52 | [RT5631_DIG_MIC_CTRL] = 0x3000, | 53 | { RT5631_DIG_MIC_CTRL, 0x3000 }, |
53 | [RT5631_MONO_INPUT_VOL] = 0x8808, | 54 | { RT5631_MONO_INPUT_VOL, 0x8808 }, |
54 | [RT5631_SPK_MIXER_CTRL] = 0xf8f8, | 55 | { RT5631_SPK_MIXER_CTRL, 0xf8f8 }, |
55 | [RT5631_SPK_MONO_OUT_CTRL] = 0xfc00, | 56 | { RT5631_SPK_MONO_OUT_CTRL, 0xfc00 }, |
56 | [RT5631_SPK_MONO_HP_OUT_CTRL] = 0x4440, | 57 | { RT5631_SPK_MONO_HP_OUT_CTRL, 0x4440 }, |
57 | [RT5631_SDP_CTRL] = 0x8000, | 58 | { RT5631_SDP_CTRL, 0x8000 }, |
58 | [RT5631_MONO_SDP_CTRL] = 0x8000, | 59 | { RT5631_MONO_SDP_CTRL, 0x8000 }, |
59 | [RT5631_STEREO_AD_DA_CLK_CTRL] = 0x2010, | 60 | { RT5631_STEREO_AD_DA_CLK_CTRL, 0x2010 }, |
60 | [RT5631_GEN_PUR_CTRL_REG] = 0x0e00, | 61 | { RT5631_GEN_PUR_CTRL_REG, 0x0e00 }, |
61 | [RT5631_INT_ST_IRQ_CTRL_2] = 0x071a, | 62 | { RT5631_INT_ST_IRQ_CTRL_2, 0x071a }, |
62 | [RT5631_MISC_CTRL] = 0x2040, | 63 | { RT5631_MISC_CTRL, 0x2040 }, |
63 | [RT5631_DEPOP_FUN_CTRL_2] = 0x8000, | 64 | { RT5631_DEPOP_FUN_CTRL_2, 0x8000 }, |
64 | [RT5631_SOFT_VOL_CTRL] = 0x07e0, | 65 | { RT5631_SOFT_VOL_CTRL, 0x07e0 }, |
65 | [RT5631_ALC_CTRL_1] = 0x0206, | 66 | { RT5631_ALC_CTRL_1, 0x0206 }, |
66 | [RT5631_ALC_CTRL_3] = 0x2000, | 67 | { RT5631_ALC_CTRL_3, 0x2000 }, |
67 | [RT5631_PSEUDO_SPATL_CTRL] = 0x0553, | 68 | { RT5631_PSEUDO_SPATL_CTRL, 0x0553 }, |
68 | }; | 69 | }; |
69 | 70 | ||
70 | /** | 71 | /** |
@@ -96,8 +97,7 @@ static int rt5631_reset(struct snd_soc_codec *codec) | |||
96 | return snd_soc_write(codec, RT5631_RESET, 0); | 97 | return snd_soc_write(codec, RT5631_RESET, 0); |
97 | } | 98 | } |
98 | 99 | ||
99 | static int rt5631_volatile_register(struct snd_soc_codec *codec, | 100 | static bool rt5631_volatile_register(struct device *dev, unsigned int reg) |
100 | unsigned int reg) | ||
101 | { | 101 | { |
102 | switch (reg) { | 102 | switch (reg) { |
103 | case RT5631_RESET: | 103 | case RT5631_RESET: |
@@ -111,8 +111,7 @@ static int rt5631_volatile_register(struct snd_soc_codec *codec, | |||
111 | } | 111 | } |
112 | } | 112 | } |
113 | 113 | ||
114 | static int rt5631_readable_register(struct snd_soc_codec *codec, | 114 | static bool rt5631_readable_register(struct device *dev, unsigned int reg) |
115 | unsigned int reg) | ||
116 | { | 115 | { |
117 | switch (reg) { | 116 | switch (reg) { |
118 | case RT5631_RESET: | 117 | case RT5631_RESET: |
@@ -1361,8 +1360,7 @@ static int get_coeff(int mclk, int rate, int timesofbclk) | |||
1361 | static int rt5631_hifi_pcm_params(struct snd_pcm_substream *substream, | 1360 | static int rt5631_hifi_pcm_params(struct snd_pcm_substream *substream, |
1362 | struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) | 1361 | struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) |
1363 | { | 1362 | { |
1364 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 1363 | struct snd_soc_codec *codec = dai->codec; |
1365 | struct snd_soc_codec *codec = rtd->codec; | ||
1366 | struct rt5631_priv *rt5631 = snd_soc_codec_get_drvdata(codec); | 1364 | struct rt5631_priv *rt5631 = snd_soc_codec_get_drvdata(codec); |
1367 | int timesofbclk = 32, coeff; | 1365 | int timesofbclk = 32, coeff; |
1368 | unsigned int iface = 0; | 1366 | unsigned int iface = 0; |
@@ -1544,6 +1542,8 @@ static int rt5631_codec_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id, | |||
1544 | static int rt5631_set_bias_level(struct snd_soc_codec *codec, | 1542 | static int rt5631_set_bias_level(struct snd_soc_codec *codec, |
1545 | enum snd_soc_bias_level level) | 1543 | enum snd_soc_bias_level level) |
1546 | { | 1544 | { |
1545 | struct rt5631_priv *rt5631 = snd_soc_codec_get_drvdata(codec); | ||
1546 | |||
1547 | switch (level) { | 1547 | switch (level) { |
1548 | case SND_SOC_BIAS_ON: | 1548 | case SND_SOC_BIAS_ON: |
1549 | case SND_SOC_BIAS_PREPARE: | 1549 | case SND_SOC_BIAS_PREPARE: |
@@ -1561,8 +1561,8 @@ static int rt5631_set_bias_level(struct snd_soc_codec *codec, | |||
1561 | snd_soc_update_bits(codec, RT5631_PWR_MANAG_ADD3, | 1561 | snd_soc_update_bits(codec, RT5631_PWR_MANAG_ADD3, |
1562 | RT5631_PWR_FAST_VREF_CTRL, | 1562 | RT5631_PWR_FAST_VREF_CTRL, |
1563 | RT5631_PWR_FAST_VREF_CTRL); | 1563 | RT5631_PWR_FAST_VREF_CTRL); |
1564 | codec->cache_only = false; | 1564 | regcache_cache_only(rt5631->regmap, false); |
1565 | snd_soc_cache_sync(codec); | 1565 | regcache_sync(rt5631->regmap); |
1566 | } | 1566 | } |
1567 | break; | 1567 | break; |
1568 | 1568 | ||
@@ -1587,7 +1587,9 @@ static int rt5631_probe(struct snd_soc_codec *codec) | |||
1587 | unsigned int val; | 1587 | unsigned int val; |
1588 | int ret; | 1588 | int ret; |
1589 | 1589 | ||
1590 | ret = snd_soc_codec_set_cache_io(codec, 8, 16, SND_SOC_I2C); | 1590 | codec->control_data = rt5631->regmap; |
1591 | |||
1592 | ret = snd_soc_codec_set_cache_io(codec, 8, 16, SND_SOC_REGMAP); | ||
1591 | if (ret != 0) { | 1593 | if (ret != 0) { |
1592 | dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); | 1594 | dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); |
1593 | return ret; | 1595 | return ret; |
@@ -1698,12 +1700,6 @@ static struct snd_soc_codec_driver soc_codec_dev_rt5631 = { | |||
1698 | .suspend = rt5631_suspend, | 1700 | .suspend = rt5631_suspend, |
1699 | .resume = rt5631_resume, | 1701 | .resume = rt5631_resume, |
1700 | .set_bias_level = rt5631_set_bias_level, | 1702 | .set_bias_level = rt5631_set_bias_level, |
1701 | .reg_cache_size = RT5631_VENDOR_ID2 + 1, | ||
1702 | .reg_word_size = sizeof(u16), | ||
1703 | .reg_cache_default = rt5631_reg, | ||
1704 | .volatile_register = rt5631_volatile_register, | ||
1705 | .readable_register = rt5631_readable_register, | ||
1706 | .reg_cache_step = 1, | ||
1707 | .controls = rt5631_snd_controls, | 1703 | .controls = rt5631_snd_controls, |
1708 | .num_controls = ARRAY_SIZE(rt5631_snd_controls), | 1704 | .num_controls = ARRAY_SIZE(rt5631_snd_controls), |
1709 | .dapm_widgets = rt5631_dapm_widgets, | 1705 | .dapm_widgets = rt5631_dapm_widgets, |
@@ -1718,6 +1714,18 @@ static const struct i2c_device_id rt5631_i2c_id[] = { | |||
1718 | }; | 1714 | }; |
1719 | MODULE_DEVICE_TABLE(i2c, rt5631_i2c_id); | 1715 | MODULE_DEVICE_TABLE(i2c, rt5631_i2c_id); |
1720 | 1716 | ||
1717 | static const struct regmap_config rt5631_regmap_config = { | ||
1718 | .reg_bits = 8, | ||
1719 | .val_bits = 16, | ||
1720 | |||
1721 | .readable_reg = rt5631_readable_register, | ||
1722 | .volatile_reg = rt5631_volatile_register, | ||
1723 | .max_register = RT5631_VENDOR_ID2, | ||
1724 | .reg_defaults = rt5631_reg, | ||
1725 | .num_reg_defaults = ARRAY_SIZE(rt5631_reg), | ||
1726 | .cache_type = REGCACHE_RBTREE, | ||
1727 | }; | ||
1728 | |||
1721 | static int rt5631_i2c_probe(struct i2c_client *i2c, | 1729 | static int rt5631_i2c_probe(struct i2c_client *i2c, |
1722 | const struct i2c_device_id *id) | 1730 | const struct i2c_device_id *id) |
1723 | { | 1731 | { |
@@ -1731,6 +1739,10 @@ static int rt5631_i2c_probe(struct i2c_client *i2c, | |||
1731 | 1739 | ||
1732 | i2c_set_clientdata(i2c, rt5631); | 1740 | i2c_set_clientdata(i2c, rt5631); |
1733 | 1741 | ||
1742 | rt5631->regmap = devm_regmap_init_i2c(i2c, &rt5631_regmap_config); | ||
1743 | if (IS_ERR(rt5631->regmap)) | ||
1744 | return PTR_ERR(rt5631->regmap); | ||
1745 | |||
1734 | ret = snd_soc_register_codec(&i2c->dev, &soc_codec_dev_rt5631, | 1746 | ret = snd_soc_register_codec(&i2c->dev, &soc_codec_dev_rt5631, |
1735 | rt5631_dai, ARRAY_SIZE(rt5631_dai)); | 1747 | rt5631_dai, ARRAY_SIZE(rt5631_dai)); |
1736 | return ret; | 1748 | return ret; |
@@ -1752,17 +1764,7 @@ static struct i2c_driver rt5631_i2c_driver = { | |||
1752 | .id_table = rt5631_i2c_id, | 1764 | .id_table = rt5631_i2c_id, |
1753 | }; | 1765 | }; |
1754 | 1766 | ||
1755 | static int __init rt5631_modinit(void) | 1767 | module_i2c_driver(rt5631_i2c_driver); |
1756 | { | ||
1757 | return i2c_add_driver(&rt5631_i2c_driver); | ||
1758 | } | ||
1759 | module_init(rt5631_modinit); | ||
1760 | |||
1761 | static void __exit rt5631_modexit(void) | ||
1762 | { | ||
1763 | i2c_del_driver(&rt5631_i2c_driver); | ||
1764 | } | ||
1765 | module_exit(rt5631_modexit); | ||
1766 | 1768 | ||
1767 | MODULE_DESCRIPTION("ASoC RT5631 driver"); | 1769 | MODULE_DESCRIPTION("ASoC RT5631 driver"); |
1768 | MODULE_AUTHOR("flove <flove@realtek.com>"); | 1770 | MODULE_AUTHOR("flove <flove@realtek.com>"); |
diff --git a/sound/soc/codecs/sgtl5000.c b/sound/soc/codecs/sgtl5000.c index c395ec370445..8af6a5245b18 100644 --- a/sound/soc/codecs/sgtl5000.c +++ b/sound/soc/codecs/sgtl5000.c | |||
@@ -84,8 +84,8 @@ static struct regulator_consumer_supply ldo_consumer[] = { | |||
84 | 84 | ||
85 | static struct regulator_init_data ldo_init_data = { | 85 | static struct regulator_init_data ldo_init_data = { |
86 | .constraints = { | 86 | .constraints = { |
87 | .min_uV = 850000, | 87 | .min_uV = 1200000, |
88 | .max_uV = 1600000, | 88 | .max_uV = 1200000, |
89 | .valid_modes_mask = REGULATOR_MODE_NORMAL, | 89 | .valid_modes_mask = REGULATOR_MODE_NORMAL, |
90 | .valid_ops_mask = REGULATOR_CHANGE_STATUS, | 90 | .valid_ops_mask = REGULATOR_CHANGE_STATUS, |
91 | }, | 91 | }, |
@@ -197,9 +197,9 @@ static const struct snd_soc_dapm_widget sgtl5000_dapm_widgets[] = { | |||
197 | SND_SOC_DAPM_OUTPUT("HP_OUT"), | 197 | SND_SOC_DAPM_OUTPUT("HP_OUT"), |
198 | SND_SOC_DAPM_OUTPUT("LINE_OUT"), | 198 | SND_SOC_DAPM_OUTPUT("LINE_OUT"), |
199 | 199 | ||
200 | SND_SOC_DAPM_MICBIAS_E("Mic Bias", SGTL5000_CHIP_MIC_CTRL, 8, 0, | 200 | SND_SOC_DAPM_SUPPLY("Mic Bias", SGTL5000_CHIP_MIC_CTRL, 8, 0, |
201 | mic_bias_event, | 201 | mic_bias_event, |
202 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), | 202 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), |
203 | 203 | ||
204 | SND_SOC_DAPM_PGA("HP", SGTL5000_CHIP_ANA_POWER, 4, 0, NULL, 0), | 204 | SND_SOC_DAPM_PGA("HP", SGTL5000_CHIP_ANA_POWER, 4, 0, NULL, 0), |
205 | SND_SOC_DAPM_PGA("LO", SGTL5000_CHIP_ANA_POWER, 0, 0, NULL, 0), | 205 | SND_SOC_DAPM_PGA("LO", SGTL5000_CHIP_ANA_POWER, 0, 0, NULL, 0), |
@@ -665,8 +665,7 @@ static int sgtl5000_pcm_hw_params(struct snd_pcm_substream *substream, | |||
665 | struct snd_pcm_hw_params *params, | 665 | struct snd_pcm_hw_params *params, |
666 | struct snd_soc_dai *dai) | 666 | struct snd_soc_dai *dai) |
667 | { | 667 | { |
668 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 668 | struct snd_soc_codec *codec = dai->codec; |
669 | struct snd_soc_codec *codec = rtd->codec; | ||
670 | struct sgtl5000_priv *sgtl5000 = snd_soc_codec_get_drvdata(codec); | 669 | struct sgtl5000_priv *sgtl5000 = snd_soc_codec_get_drvdata(codec); |
671 | int channels = params_channels(params); | 670 | int channels = params_channels(params); |
672 | int i2s_ctl = 0; | 671 | int i2s_ctl = 0; |
@@ -1455,17 +1454,7 @@ static struct i2c_driver sgtl5000_i2c_driver = { | |||
1455 | .id_table = sgtl5000_id, | 1454 | .id_table = sgtl5000_id, |
1456 | }; | 1455 | }; |
1457 | 1456 | ||
1458 | static int __init sgtl5000_modinit(void) | 1457 | module_i2c_driver(sgtl5000_i2c_driver); |
1459 | { | ||
1460 | return i2c_add_driver(&sgtl5000_i2c_driver); | ||
1461 | } | ||
1462 | module_init(sgtl5000_modinit); | ||
1463 | |||
1464 | static void __exit sgtl5000_exit(void) | ||
1465 | { | ||
1466 | i2c_del_driver(&sgtl5000_i2c_driver); | ||
1467 | } | ||
1468 | module_exit(sgtl5000_exit); | ||
1469 | 1458 | ||
1470 | MODULE_DESCRIPTION("Freescale SGTL5000 ALSA SoC Codec Driver"); | 1459 | MODULE_DESCRIPTION("Freescale SGTL5000 ALSA SoC Codec Driver"); |
1471 | MODULE_AUTHOR("Zeng Zhaoming <zengzm.kernel@gmail.com>"); | 1460 | MODULE_AUTHOR("Zeng Zhaoming <zengzm.kernel@gmail.com>"); |
diff --git a/sound/soc/codecs/ssm2602.c b/sound/soc/codecs/ssm2602.c index de2b20544ceb..079066fef425 100644 --- a/sound/soc/codecs/ssm2602.c +++ b/sound/soc/codecs/ssm2602.c | |||
@@ -33,6 +33,7 @@ | |||
33 | #include <linux/pm.h> | 33 | #include <linux/pm.h> |
34 | #include <linux/i2c.h> | 34 | #include <linux/i2c.h> |
35 | #include <linux/spi/spi.h> | 35 | #include <linux/spi/spi.h> |
36 | #include <linux/regmap.h> | ||
36 | #include <linux/slab.h> | 37 | #include <linux/slab.h> |
37 | #include <sound/core.h> | 38 | #include <sound/core.h> |
38 | #include <sound/pcm.h> | 39 | #include <sound/pcm.h> |
@@ -43,8 +44,6 @@ | |||
43 | 44 | ||
44 | #include "ssm2602.h" | 45 | #include "ssm2602.h" |
45 | 46 | ||
46 | #define SSM2602_VERSION "0.1" | ||
47 | |||
48 | enum ssm2602_type { | 47 | enum ssm2602_type { |
49 | SSM2602, | 48 | SSM2602, |
50 | SSM2604, | 49 | SSM2604, |
@@ -53,10 +52,12 @@ enum ssm2602_type { | |||
53 | /* codec private data */ | 52 | /* codec private data */ |
54 | struct ssm2602_priv { | 53 | struct ssm2602_priv { |
55 | unsigned int sysclk; | 54 | unsigned int sysclk; |
56 | enum snd_soc_control_type control_type; | 55 | struct snd_pcm_hw_constraint_list *sysclk_constraints; |
57 | struct snd_pcm_substream *master_substream; | 56 | struct snd_pcm_substream *master_substream; |
58 | struct snd_pcm_substream *slave_substream; | 57 | struct snd_pcm_substream *slave_substream; |
59 | 58 | ||
59 | struct regmap *regmap; | ||
60 | |||
60 | enum ssm2602_type type; | 61 | enum ssm2602_type type; |
61 | unsigned int clk_out_pwr; | 62 | unsigned int clk_out_pwr; |
62 | }; | 63 | }; |
@@ -73,7 +74,6 @@ static const u16 ssm2602_reg[SSM2602_CACHEREGNUM] = { | |||
73 | 0x0000, 0x0000 | 74 | 0x0000, 0x0000 |
74 | }; | 75 | }; |
75 | 76 | ||
76 | #define ssm2602_reset(c) snd_soc_write(c, SSM2602_RESET, 0) | ||
77 | 77 | ||
78 | /*Appending several "None"s just for OSS mixer use*/ | 78 | /*Appending several "None"s just for OSS mixer use*/ |
79 | static const char *ssm2602_input_select[] = { | 79 | static const char *ssm2602_input_select[] = { |
@@ -195,6 +195,24 @@ static const struct snd_soc_dapm_route ssm2604_routes[] = { | |||
195 | {"ADC", NULL, "Line Input"}, | 195 | {"ADC", NULL, "Line Input"}, |
196 | }; | 196 | }; |
197 | 197 | ||
198 | static const unsigned int ssm2602_rates_12288000[] = { | ||
199 | 8000, 32000, 48000, 96000, | ||
200 | }; | ||
201 | |||
202 | static struct snd_pcm_hw_constraint_list ssm2602_constraints_12288000 = { | ||
203 | .list = ssm2602_rates_12288000, | ||
204 | .count = ARRAY_SIZE(ssm2602_rates_12288000), | ||
205 | }; | ||
206 | |||
207 | static const unsigned int ssm2602_rates_11289600[] = { | ||
208 | 8000, 44100, 88200, | ||
209 | }; | ||
210 | |||
211 | static struct snd_pcm_hw_constraint_list ssm2602_constraints_11289600 = { | ||
212 | .list = ssm2602_rates_11289600, | ||
213 | .count = ARRAY_SIZE(ssm2602_rates_11289600), | ||
214 | }; | ||
215 | |||
198 | struct ssm2602_coeff { | 216 | struct ssm2602_coeff { |
199 | u32 mclk; | 217 | u32 mclk; |
200 | u32 rate; | 218 | u32 rate; |
@@ -254,11 +272,10 @@ static int ssm2602_hw_params(struct snd_pcm_substream *substream, | |||
254 | struct snd_pcm_hw_params *params, | 272 | struct snd_pcm_hw_params *params, |
255 | struct snd_soc_dai *dai) | 273 | struct snd_soc_dai *dai) |
256 | { | 274 | { |
257 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 275 | struct snd_soc_codec *codec = dai->codec; |
258 | struct snd_soc_codec *codec = rtd->codec; | ||
259 | struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec); | 276 | struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec); |
260 | u16 iface = snd_soc_read(codec, SSM2602_IFACE) & 0xfff3; | ||
261 | int srate = ssm2602_get_coeff(ssm2602->sysclk, params_rate(params)); | 277 | int srate = ssm2602_get_coeff(ssm2602->sysclk, params_rate(params)); |
278 | unsigned int iface; | ||
262 | 279 | ||
263 | if (substream == ssm2602->slave_substream) { | 280 | if (substream == ssm2602->slave_substream) { |
264 | dev_dbg(codec->dev, "Ignoring hw_params for slave substream\n"); | 281 | dev_dbg(codec->dev, "Ignoring hw_params for slave substream\n"); |
@@ -268,31 +285,34 @@ static int ssm2602_hw_params(struct snd_pcm_substream *substream, | |||
268 | if (srate < 0) | 285 | if (srate < 0) |
269 | return srate; | 286 | return srate; |
270 | 287 | ||
271 | snd_soc_write(codec, SSM2602_SRATE, srate); | 288 | regmap_write(ssm2602->regmap, SSM2602_SRATE, srate); |
272 | 289 | ||
273 | /* bit size */ | 290 | /* bit size */ |
274 | switch (params_format(params)) { | 291 | switch (params_format(params)) { |
275 | case SNDRV_PCM_FORMAT_S16_LE: | 292 | case SNDRV_PCM_FORMAT_S16_LE: |
293 | iface = 0x0; | ||
276 | break; | 294 | break; |
277 | case SNDRV_PCM_FORMAT_S20_3LE: | 295 | case SNDRV_PCM_FORMAT_S20_3LE: |
278 | iface |= 0x0004; | 296 | iface = 0x4; |
279 | break; | 297 | break; |
280 | case SNDRV_PCM_FORMAT_S24_LE: | 298 | case SNDRV_PCM_FORMAT_S24_LE: |
281 | iface |= 0x0008; | 299 | iface = 0x8; |
282 | break; | 300 | break; |
283 | case SNDRV_PCM_FORMAT_S32_LE: | 301 | case SNDRV_PCM_FORMAT_S32_LE: |
284 | iface |= 0x000c; | 302 | iface = 0xc; |
285 | break; | 303 | break; |
304 | default: | ||
305 | return -EINVAL; | ||
286 | } | 306 | } |
287 | snd_soc_write(codec, SSM2602_IFACE, iface); | 307 | regmap_update_bits(ssm2602->regmap, SSM2602_IFACE, |
308 | IFACE_AUDIO_DATA_LEN, iface); | ||
288 | return 0; | 309 | return 0; |
289 | } | 310 | } |
290 | 311 | ||
291 | static int ssm2602_startup(struct snd_pcm_substream *substream, | 312 | static int ssm2602_startup(struct snd_pcm_substream *substream, |
292 | struct snd_soc_dai *dai) | 313 | struct snd_soc_dai *dai) |
293 | { | 314 | { |
294 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 315 | struct snd_soc_codec *codec = dai->codec; |
295 | struct snd_soc_codec *codec = rtd->codec; | ||
296 | struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec); | 316 | struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec); |
297 | struct snd_pcm_runtime *master_runtime; | 317 | struct snd_pcm_runtime *master_runtime; |
298 | 318 | ||
@@ -322,14 +342,19 @@ static int ssm2602_startup(struct snd_pcm_substream *substream, | |||
322 | } else | 342 | } else |
323 | ssm2602->master_substream = substream; | 343 | ssm2602->master_substream = substream; |
324 | 344 | ||
345 | if (ssm2602->sysclk_constraints) { | ||
346 | snd_pcm_hw_constraint_list(substream->runtime, 0, | ||
347 | SNDRV_PCM_HW_PARAM_RATE, | ||
348 | ssm2602->sysclk_constraints); | ||
349 | } | ||
350 | |||
325 | return 0; | 351 | return 0; |
326 | } | 352 | } |
327 | 353 | ||
328 | static void ssm2602_shutdown(struct snd_pcm_substream *substream, | 354 | static void ssm2602_shutdown(struct snd_pcm_substream *substream, |
329 | struct snd_soc_dai *dai) | 355 | struct snd_soc_dai *dai) |
330 | { | 356 | { |
331 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 357 | struct snd_soc_codec *codec = dai->codec; |
332 | struct snd_soc_codec *codec = rtd->codec; | ||
333 | struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec); | 358 | struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec); |
334 | 359 | ||
335 | if (ssm2602->master_substream == substream) | 360 | if (ssm2602->master_substream == substream) |
@@ -341,14 +366,14 @@ static void ssm2602_shutdown(struct snd_pcm_substream *substream, | |||
341 | 366 | ||
342 | static int ssm2602_mute(struct snd_soc_dai *dai, int mute) | 367 | static int ssm2602_mute(struct snd_soc_dai *dai, int mute) |
343 | { | 368 | { |
344 | struct snd_soc_codec *codec = dai->codec; | 369 | struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(dai->codec); |
345 | 370 | ||
346 | if (mute) | 371 | if (mute) |
347 | snd_soc_update_bits(codec, SSM2602_APDIGI, | 372 | regmap_update_bits(ssm2602->regmap, SSM2602_APDIGI, |
348 | APDIGI_ENABLE_DAC_MUTE, | 373 | APDIGI_ENABLE_DAC_MUTE, |
349 | APDIGI_ENABLE_DAC_MUTE); | 374 | APDIGI_ENABLE_DAC_MUTE); |
350 | else | 375 | else |
351 | snd_soc_update_bits(codec, SSM2602_APDIGI, | 376 | regmap_update_bits(ssm2602->regmap, SSM2602_APDIGI, |
352 | APDIGI_ENABLE_DAC_MUTE, 0); | 377 | APDIGI_ENABLE_DAC_MUTE, 0); |
353 | return 0; | 378 | return 0; |
354 | } | 379 | } |
@@ -364,16 +389,21 @@ static int ssm2602_set_dai_sysclk(struct snd_soc_dai *codec_dai, | |||
364 | return -EINVAL; | 389 | return -EINVAL; |
365 | 390 | ||
366 | switch (freq) { | 391 | switch (freq) { |
367 | case 11289600: | ||
368 | case 12000000: | ||
369 | case 12288000: | 392 | case 12288000: |
370 | case 16934400: | ||
371 | case 18432000: | 393 | case 18432000: |
372 | ssm2602->sysclk = freq; | 394 | ssm2602->sysclk_constraints = &ssm2602_constraints_12288000; |
395 | break; | ||
396 | case 11289600: | ||
397 | case 16934400: | ||
398 | ssm2602->sysclk_constraints = &ssm2602_constraints_11289600; | ||
399 | break; | ||
400 | case 12000000: | ||
401 | ssm2602->sysclk_constraints = NULL; | ||
373 | break; | 402 | break; |
374 | default: | 403 | default: |
375 | return -EINVAL; | 404 | return -EINVAL; |
376 | } | 405 | } |
406 | ssm2602->sysclk = freq; | ||
377 | } else { | 407 | } else { |
378 | unsigned int mask; | 408 | unsigned int mask; |
379 | 409 | ||
@@ -393,7 +423,7 @@ static int ssm2602_set_dai_sysclk(struct snd_soc_dai *codec_dai, | |||
393 | else | 423 | else |
394 | ssm2602->clk_out_pwr &= ~mask; | 424 | ssm2602->clk_out_pwr &= ~mask; |
395 | 425 | ||
396 | snd_soc_update_bits(codec, SSM2602_PWR, | 426 | regmap_update_bits(ssm2602->regmap, SSM2602_PWR, |
397 | PWR_CLK_OUT_PDN | PWR_OSC_PDN, ssm2602->clk_out_pwr); | 427 | PWR_CLK_OUT_PDN | PWR_OSC_PDN, ssm2602->clk_out_pwr); |
398 | } | 428 | } |
399 | 429 | ||
@@ -403,8 +433,8 @@ static int ssm2602_set_dai_sysclk(struct snd_soc_dai *codec_dai, | |||
403 | static int ssm2602_set_dai_fmt(struct snd_soc_dai *codec_dai, | 433 | static int ssm2602_set_dai_fmt(struct snd_soc_dai *codec_dai, |
404 | unsigned int fmt) | 434 | unsigned int fmt) |
405 | { | 435 | { |
406 | struct snd_soc_codec *codec = codec_dai->codec; | 436 | struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec_dai->codec); |
407 | u16 iface = 0; | 437 | unsigned int iface = 0; |
408 | 438 | ||
409 | /* set master/slave audio interface */ | 439 | /* set master/slave audio interface */ |
410 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { | 440 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
@@ -455,7 +485,7 @@ static int ssm2602_set_dai_fmt(struct snd_soc_dai *codec_dai, | |||
455 | } | 485 | } |
456 | 486 | ||
457 | /* set iface */ | 487 | /* set iface */ |
458 | snd_soc_write(codec, SSM2602_IFACE, iface); | 488 | regmap_write(ssm2602->regmap, SSM2602_IFACE, iface); |
459 | return 0; | 489 | return 0; |
460 | } | 490 | } |
461 | 491 | ||
@@ -467,7 +497,7 @@ static int ssm2602_set_bias_level(struct snd_soc_codec *codec, | |||
467 | switch (level) { | 497 | switch (level) { |
468 | case SND_SOC_BIAS_ON: | 498 | case SND_SOC_BIAS_ON: |
469 | /* vref/mid on, osc and clkout on if enabled */ | 499 | /* vref/mid on, osc and clkout on if enabled */ |
470 | snd_soc_update_bits(codec, SSM2602_PWR, | 500 | regmap_update_bits(ssm2602->regmap, SSM2602_PWR, |
471 | PWR_POWER_OFF | PWR_CLK_OUT_PDN | PWR_OSC_PDN, | 501 | PWR_POWER_OFF | PWR_CLK_OUT_PDN | PWR_OSC_PDN, |
472 | ssm2602->clk_out_pwr); | 502 | ssm2602->clk_out_pwr); |
473 | break; | 503 | break; |
@@ -475,13 +505,13 @@ static int ssm2602_set_bias_level(struct snd_soc_codec *codec, | |||
475 | break; | 505 | break; |
476 | case SND_SOC_BIAS_STANDBY: | 506 | case SND_SOC_BIAS_STANDBY: |
477 | /* everything off except vref/vmid, */ | 507 | /* everything off except vref/vmid, */ |
478 | snd_soc_update_bits(codec, SSM2602_PWR, | 508 | regmap_update_bits(ssm2602->regmap, SSM2602_PWR, |
479 | PWR_POWER_OFF | PWR_CLK_OUT_PDN | PWR_OSC_PDN, | 509 | PWR_POWER_OFF | PWR_CLK_OUT_PDN | PWR_OSC_PDN, |
480 | PWR_CLK_OUT_PDN | PWR_OSC_PDN); | 510 | PWR_CLK_OUT_PDN | PWR_OSC_PDN); |
481 | break; | 511 | break; |
482 | case SND_SOC_BIAS_OFF: | 512 | case SND_SOC_BIAS_OFF: |
483 | /* everything off */ | 513 | /* everything off */ |
484 | snd_soc_update_bits(codec, SSM2602_PWR, | 514 | regmap_update_bits(ssm2602->regmap, SSM2602_PWR, |
485 | PWR_POWER_OFF, PWR_POWER_OFF); | 515 | PWR_POWER_OFF, PWR_POWER_OFF); |
486 | break; | 516 | break; |
487 | 517 | ||
@@ -540,12 +570,13 @@ static int ssm2602_resume(struct snd_soc_codec *codec) | |||
540 | 570 | ||
541 | static int ssm2602_probe(struct snd_soc_codec *codec) | 571 | static int ssm2602_probe(struct snd_soc_codec *codec) |
542 | { | 572 | { |
573 | struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec); | ||
543 | struct snd_soc_dapm_context *dapm = &codec->dapm; | 574 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
544 | int ret; | 575 | int ret; |
545 | 576 | ||
546 | snd_soc_update_bits(codec, SSM2602_LOUT1V, | 577 | regmap_update_bits(ssm2602->regmap, SSM2602_LOUT1V, |
547 | LOUT1V_LRHP_BOTH, LOUT1V_LRHP_BOTH); | 578 | LOUT1V_LRHP_BOTH, LOUT1V_LRHP_BOTH); |
548 | snd_soc_update_bits(codec, SSM2602_ROUT1V, | 579 | regmap_update_bits(ssm2602->regmap, SSM2602_ROUT1V, |
549 | ROUT1V_RLHP_BOTH, ROUT1V_RLHP_BOTH); | 580 | ROUT1V_RLHP_BOTH, ROUT1V_RLHP_BOTH); |
550 | 581 | ||
551 | ret = snd_soc_add_codec_controls(codec, ssm2602_snd_controls, | 582 | ret = snd_soc_add_codec_controls(codec, ssm2602_snd_controls, |
@@ -581,27 +612,26 @@ static int ssm260x_probe(struct snd_soc_codec *codec) | |||
581 | struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec); | 612 | struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec); |
582 | int ret; | 613 | int ret; |
583 | 614 | ||
584 | pr_info("ssm2602 Audio Codec %s", SSM2602_VERSION); | 615 | codec->control_data = ssm2602->regmap; |
585 | 616 | ret = snd_soc_codec_set_cache_io(codec, 0, 0, SND_SOC_REGMAP); | |
586 | ret = snd_soc_codec_set_cache_io(codec, 7, 9, ssm2602->control_type); | ||
587 | if (ret < 0) { | 617 | if (ret < 0) { |
588 | dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); | 618 | dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); |
589 | return ret; | 619 | return ret; |
590 | } | 620 | } |
591 | 621 | ||
592 | ret = ssm2602_reset(codec); | 622 | ret = regmap_write(ssm2602->regmap, SSM2602_RESET, 0); |
593 | if (ret < 0) { | 623 | if (ret < 0) { |
594 | dev_err(codec->dev, "Failed to issue reset: %d\n", ret); | 624 | dev_err(codec->dev, "Failed to issue reset: %d\n", ret); |
595 | return ret; | 625 | return ret; |
596 | } | 626 | } |
597 | 627 | ||
598 | /* set the update bits */ | 628 | /* set the update bits */ |
599 | snd_soc_update_bits(codec, SSM2602_LINVOL, | 629 | regmap_update_bits(ssm2602->regmap, SSM2602_LINVOL, |
600 | LINVOL_LRIN_BOTH, LINVOL_LRIN_BOTH); | 630 | LINVOL_LRIN_BOTH, LINVOL_LRIN_BOTH); |
601 | snd_soc_update_bits(codec, SSM2602_RINVOL, | 631 | regmap_update_bits(ssm2602->regmap, SSM2602_RINVOL, |
602 | RINVOL_RLIN_BOTH, RINVOL_RLIN_BOTH); | 632 | RINVOL_RLIN_BOTH, RINVOL_RLIN_BOTH); |
603 | /*select Line in as default input*/ | 633 | /*select Line in as default input*/ |
604 | snd_soc_write(codec, SSM2602_APANA, APANA_SELECT_DAC | | 634 | regmap_write(ssm2602->regmap, SSM2602_APANA, APANA_SELECT_DAC | |
605 | APANA_ENABLE_MIC_BOOST); | 635 | APANA_ENABLE_MIC_BOOST); |
606 | 636 | ||
607 | switch (ssm2602->type) { | 637 | switch (ssm2602->type) { |
@@ -634,9 +664,6 @@ static struct snd_soc_codec_driver soc_codec_dev_ssm2602 = { | |||
634 | .suspend = ssm2602_suspend, | 664 | .suspend = ssm2602_suspend, |
635 | .resume = ssm2602_resume, | 665 | .resume = ssm2602_resume, |
636 | .set_bias_level = ssm2602_set_bias_level, | 666 | .set_bias_level = ssm2602_set_bias_level, |
637 | .reg_cache_size = ARRAY_SIZE(ssm2602_reg), | ||
638 | .reg_word_size = sizeof(u16), | ||
639 | .reg_cache_default = ssm2602_reg, | ||
640 | 667 | ||
641 | .controls = ssm260x_snd_controls, | 668 | .controls = ssm260x_snd_controls, |
642 | .num_controls = ARRAY_SIZE(ssm260x_snd_controls), | 669 | .num_controls = ARRAY_SIZE(ssm260x_snd_controls), |
@@ -646,6 +673,23 @@ static struct snd_soc_codec_driver soc_codec_dev_ssm2602 = { | |||
646 | .num_dapm_routes = ARRAY_SIZE(ssm260x_routes), | 673 | .num_dapm_routes = ARRAY_SIZE(ssm260x_routes), |
647 | }; | 674 | }; |
648 | 675 | ||
676 | static bool ssm2602_register_volatile(struct device *dev, unsigned int reg) | ||
677 | { | ||
678 | return reg == SSM2602_RESET; | ||
679 | } | ||
680 | |||
681 | static const struct regmap_config ssm2602_regmap_config = { | ||
682 | .val_bits = 9, | ||
683 | .reg_bits = 7, | ||
684 | |||
685 | .max_register = SSM2602_RESET, | ||
686 | .volatile_reg = ssm2602_register_volatile, | ||
687 | |||
688 | .cache_type = REGCACHE_RBTREE, | ||
689 | .reg_defaults_raw = ssm2602_reg, | ||
690 | .num_reg_defaults_raw = ARRAY_SIZE(ssm2602_reg), | ||
691 | }; | ||
692 | |||
649 | #if defined(CONFIG_SPI_MASTER) | 693 | #if defined(CONFIG_SPI_MASTER) |
650 | static int __devinit ssm2602_spi_probe(struct spi_device *spi) | 694 | static int __devinit ssm2602_spi_probe(struct spi_device *spi) |
651 | { | 695 | { |
@@ -658,9 +702,12 @@ static int __devinit ssm2602_spi_probe(struct spi_device *spi) | |||
658 | return -ENOMEM; | 702 | return -ENOMEM; |
659 | 703 | ||
660 | spi_set_drvdata(spi, ssm2602); | 704 | spi_set_drvdata(spi, ssm2602); |
661 | ssm2602->control_type = SND_SOC_SPI; | ||
662 | ssm2602->type = SSM2602; | 705 | ssm2602->type = SSM2602; |
663 | 706 | ||
707 | ssm2602->regmap = devm_regmap_init_spi(spi, &ssm2602_regmap_config); | ||
708 | if (IS_ERR(ssm2602->regmap)) | ||
709 | return PTR_ERR(ssm2602->regmap); | ||
710 | |||
664 | ret = snd_soc_register_codec(&spi->dev, | 711 | ret = snd_soc_register_codec(&spi->dev, |
665 | &soc_codec_dev_ssm2602, &ssm2602_dai, 1); | 712 | &soc_codec_dev_ssm2602, &ssm2602_dai, 1); |
666 | return ret; | 713 | return ret; |
@@ -701,9 +748,12 @@ static int __devinit ssm2602_i2c_probe(struct i2c_client *i2c, | |||
701 | return -ENOMEM; | 748 | return -ENOMEM; |
702 | 749 | ||
703 | i2c_set_clientdata(i2c, ssm2602); | 750 | i2c_set_clientdata(i2c, ssm2602); |
704 | ssm2602->control_type = SND_SOC_I2C; | ||
705 | ssm2602->type = id->driver_data; | 751 | ssm2602->type = id->driver_data; |
706 | 752 | ||
753 | ssm2602->regmap = devm_regmap_init_i2c(i2c, &ssm2602_regmap_config); | ||
754 | if (IS_ERR(ssm2602->regmap)) | ||
755 | return PTR_ERR(ssm2602->regmap); | ||
756 | |||
707 | ret = snd_soc_register_codec(&i2c->dev, | 757 | ret = snd_soc_register_codec(&i2c->dev, |
708 | &soc_codec_dev_ssm2602, &ssm2602_dai, 1); | 758 | &soc_codec_dev_ssm2602, &ssm2602_dai, 1); |
709 | return ret; | 759 | return ret; |
diff --git a/sound/soc/codecs/sta32x.c b/sound/soc/codecs/sta32x.c index 7db6fa515028..8d717f4b5a87 100644 --- a/sound/soc/codecs/sta32x.c +++ b/sound/soc/codecs/sta32x.c | |||
@@ -609,8 +609,7 @@ static int sta32x_hw_params(struct snd_pcm_substream *substream, | |||
609 | struct snd_pcm_hw_params *params, | 609 | struct snd_pcm_hw_params *params, |
610 | struct snd_soc_dai *dai) | 610 | struct snd_soc_dai *dai) |
611 | { | 611 | { |
612 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 612 | struct snd_soc_codec *codec = dai->codec; |
613 | struct snd_soc_codec *codec = rtd->codec; | ||
614 | struct sta32x_priv *sta32x = snd_soc_codec_get_drvdata(codec); | 613 | struct sta32x_priv *sta32x = snd_soc_codec_get_drvdata(codec); |
615 | unsigned int rate; | 614 | unsigned int rate; |
616 | int i, mcs = -1, ir = -1; | 615 | int i, mcs = -1, ir = -1; |
diff --git a/sound/soc/codecs/tlv320aic23.c b/sound/soc/codecs/tlv320aic23.c index df1e07ffac32..31762ebdd774 100644 --- a/sound/soc/codecs/tlv320aic23.c +++ b/sound/soc/codecs/tlv320aic23.c | |||
@@ -34,8 +34,6 @@ | |||
34 | 34 | ||
35 | #include "tlv320aic23.h" | 35 | #include "tlv320aic23.h" |
36 | 36 | ||
37 | #define AIC23_VERSION "0.1" | ||
38 | |||
39 | /* | 37 | /* |
40 | * AIC23 register cache | 38 | * AIC23 register cache |
41 | */ | 39 | */ |
@@ -325,8 +323,7 @@ static int tlv320aic23_hw_params(struct snd_pcm_substream *substream, | |||
325 | struct snd_pcm_hw_params *params, | 323 | struct snd_pcm_hw_params *params, |
326 | struct snd_soc_dai *dai) | 324 | struct snd_soc_dai *dai) |
327 | { | 325 | { |
328 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 326 | struct snd_soc_codec *codec = dai->codec; |
329 | struct snd_soc_codec *codec = rtd->codec; | ||
330 | u16 iface_reg; | 327 | u16 iface_reg; |
331 | int ret; | 328 | int ret; |
332 | struct aic23 *aic23 = snd_soc_codec_get_drvdata(codec); | 329 | struct aic23 *aic23 = snd_soc_codec_get_drvdata(codec); |
@@ -371,8 +368,7 @@ static int tlv320aic23_hw_params(struct snd_pcm_substream *substream, | |||
371 | static int tlv320aic23_pcm_prepare(struct snd_pcm_substream *substream, | 368 | static int tlv320aic23_pcm_prepare(struct snd_pcm_substream *substream, |
372 | struct snd_soc_dai *dai) | 369 | struct snd_soc_dai *dai) |
373 | { | 370 | { |
374 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 371 | struct snd_soc_codec *codec = dai->codec; |
375 | struct snd_soc_codec *codec = rtd->codec; | ||
376 | 372 | ||
377 | /* set active */ | 373 | /* set active */ |
378 | snd_soc_write(codec, TLV320AIC23_ACTIVE, 0x0001); | 374 | snd_soc_write(codec, TLV320AIC23_ACTIVE, 0x0001); |
@@ -383,8 +379,7 @@ static int tlv320aic23_pcm_prepare(struct snd_pcm_substream *substream, | |||
383 | static void tlv320aic23_shutdown(struct snd_pcm_substream *substream, | 379 | static void tlv320aic23_shutdown(struct snd_pcm_substream *substream, |
384 | struct snd_soc_dai *dai) | 380 | struct snd_soc_dai *dai) |
385 | { | 381 | { |
386 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 382 | struct snd_soc_codec *codec = dai->codec; |
387 | struct snd_soc_codec *codec = rtd->codec; | ||
388 | struct aic23 *aic23 = snd_soc_codec_get_drvdata(codec); | 383 | struct aic23 *aic23 = snd_soc_codec_get_drvdata(codec); |
389 | 384 | ||
390 | /* deactivate */ | 385 | /* deactivate */ |
@@ -548,8 +543,6 @@ static int tlv320aic23_probe(struct snd_soc_codec *codec) | |||
548 | struct aic23 *aic23 = snd_soc_codec_get_drvdata(codec); | 543 | struct aic23 *aic23 = snd_soc_codec_get_drvdata(codec); |
549 | int ret; | 544 | int ret; |
550 | 545 | ||
551 | printk(KERN_INFO "AIC23 Audio Codec %s\n", AIC23_VERSION); | ||
552 | |||
553 | ret = snd_soc_codec_set_cache_io(codec, 7, 9, aic23->control_type); | 546 | ret = snd_soc_codec_set_cache_io(codec, 7, 9, aic23->control_type); |
554 | if (ret < 0) { | 547 | if (ret < 0) { |
555 | dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); | 548 | dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); |
diff --git a/sound/soc/codecs/tlv320aic26.c b/sound/soc/codecs/tlv320aic26.c index 802064b5030d..85944e953578 100644 --- a/sound/soc/codecs/tlv320aic26.c +++ b/sound/soc/codecs/tlv320aic26.c | |||
@@ -126,8 +126,7 @@ static int aic26_hw_params(struct snd_pcm_substream *substream, | |||
126 | struct snd_pcm_hw_params *params, | 126 | struct snd_pcm_hw_params *params, |
127 | struct snd_soc_dai *dai) | 127 | struct snd_soc_dai *dai) |
128 | { | 128 | { |
129 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 129 | struct snd_soc_codec *codec = dai->codec; |
130 | struct snd_soc_codec *codec = rtd->codec; | ||
131 | struct aic26 *aic26 = snd_soc_codec_get_drvdata(codec); | 130 | struct aic26 *aic26 = snd_soc_codec_get_drvdata(codec); |
132 | int fsref, divisor, wlen, pval, jval, dval, qval; | 131 | int fsref, divisor, wlen, pval, jval, dval, qval; |
133 | u16 reg; | 132 | u16 reg; |
diff --git a/sound/soc/codecs/tlv320aic3x.c b/sound/soc/codecs/tlv320aic3x.c index 8d20f6ec20f3..64d2a4fa34b2 100644 --- a/sound/soc/codecs/tlv320aic3x.c +++ b/sound/soc/codecs/tlv320aic3x.c | |||
@@ -802,8 +802,7 @@ static int aic3x_hw_params(struct snd_pcm_substream *substream, | |||
802 | struct snd_pcm_hw_params *params, | 802 | struct snd_pcm_hw_params *params, |
803 | struct snd_soc_dai *dai) | 803 | struct snd_soc_dai *dai) |
804 | { | 804 | { |
805 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 805 | struct snd_soc_codec *codec = dai->codec; |
806 | struct snd_soc_codec *codec =rtd->codec; | ||
807 | struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec); | 806 | struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec); |
808 | int codec_clk = 0, bypass_pll = 0, fsref, last_clk = 0; | 807 | int codec_clk = 0, bypass_pll = 0, fsref, last_clk = 0; |
809 | u8 data, j, r, p, pll_q, pll_p = 1, pll_r = 1, pll_j = 1; | 808 | u8 data, j, r, p, pll_q, pll_p = 1, pll_r = 1, pll_j = 1; |
@@ -1161,24 +1160,6 @@ static int aic3x_set_bias_level(struct snd_soc_codec *codec, | |||
1161 | return 0; | 1160 | return 0; |
1162 | } | 1161 | } |
1163 | 1162 | ||
1164 | void aic3x_set_headset_detection(struct snd_soc_codec *codec, int detect, | ||
1165 | int headset_debounce, int button_debounce) | ||
1166 | { | ||
1167 | u8 val; | ||
1168 | |||
1169 | val = ((detect & AIC3X_HEADSET_DETECT_MASK) | ||
1170 | << AIC3X_HEADSET_DETECT_SHIFT) | | ||
1171 | ((headset_debounce & AIC3X_HEADSET_DEBOUNCE_MASK) | ||
1172 | << AIC3X_HEADSET_DEBOUNCE_SHIFT) | | ||
1173 | ((button_debounce & AIC3X_BUTTON_DEBOUNCE_MASK) | ||
1174 | << AIC3X_BUTTON_DEBOUNCE_SHIFT); | ||
1175 | |||
1176 | if (detect & AIC3X_HEADSET_DETECT_MASK) | ||
1177 | val |= AIC3X_HEADSET_DETECT_ENABLED; | ||
1178 | |||
1179 | snd_soc_write(codec, AIC3X_HEADSET_DETECT_CTRL_A, val); | ||
1180 | } | ||
1181 | |||
1182 | #define AIC3X_RATES SNDRV_PCM_RATE_8000_96000 | 1163 | #define AIC3X_RATES SNDRV_PCM_RATE_8000_96000 |
1183 | #define AIC3X_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \ | 1164 | #define AIC3X_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \ |
1184 | SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S32_LE) | 1165 | SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S32_LE) |
diff --git a/sound/soc/codecs/tlv320dac33.c b/sound/soc/codecs/tlv320dac33.c index 4587ddd0fbf8..0dd41077ab79 100644 --- a/sound/soc/codecs/tlv320dac33.c +++ b/sound/soc/codecs/tlv320dac33.c | |||
@@ -62,8 +62,10 @@ | |||
62 | #define UTHR_FROM_PERIOD_SIZE(samples, playrate, burstrate) \ | 62 | #define UTHR_FROM_PERIOD_SIZE(samples, playrate, burstrate) \ |
63 | (((samples)*5000) / (((burstrate)*5000) / ((burstrate) - (playrate)))) | 63 | (((samples)*5000) / (((burstrate)*5000) / ((burstrate) - (playrate)))) |
64 | 64 | ||
65 | static void dac33_calculate_times(struct snd_pcm_substream *substream); | 65 | static void dac33_calculate_times(struct snd_pcm_substream *substream, |
66 | static int dac33_prepare_chip(struct snd_pcm_substream *substream); | 66 | struct snd_soc_codec *codec); |
67 | static int dac33_prepare_chip(struct snd_pcm_substream *substream, | ||
68 | struct snd_soc_codec *codec); | ||
67 | 69 | ||
68 | enum dac33_state { | 70 | enum dac33_state { |
69 | DAC33_IDLE = 0, | 71 | DAC33_IDLE = 0, |
@@ -427,8 +429,8 @@ static int dac33_playback_event(struct snd_soc_dapm_widget *w, | |||
427 | switch (event) { | 429 | switch (event) { |
428 | case SND_SOC_DAPM_PRE_PMU: | 430 | case SND_SOC_DAPM_PRE_PMU: |
429 | if (likely(dac33->substream)) { | 431 | if (likely(dac33->substream)) { |
430 | dac33_calculate_times(dac33->substream); | 432 | dac33_calculate_times(dac33->substream, w->codec); |
431 | dac33_prepare_chip(dac33->substream); | 433 | dac33_prepare_chip(dac33->substream, w->codec); |
432 | } | 434 | } |
433 | break; | 435 | break; |
434 | case SND_SOC_DAPM_POST_PMD: | 436 | case SND_SOC_DAPM_POST_PMD: |
@@ -799,8 +801,7 @@ static void dac33_oscwait(struct snd_soc_codec *codec) | |||
799 | static int dac33_startup(struct snd_pcm_substream *substream, | 801 | static int dac33_startup(struct snd_pcm_substream *substream, |
800 | struct snd_soc_dai *dai) | 802 | struct snd_soc_dai *dai) |
801 | { | 803 | { |
802 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 804 | struct snd_soc_codec *codec = dai->codec; |
803 | struct snd_soc_codec *codec = rtd->codec; | ||
804 | struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec); | 805 | struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec); |
805 | 806 | ||
806 | /* Stream started, save the substream pointer */ | 807 | /* Stream started, save the substream pointer */ |
@@ -812,8 +813,7 @@ static int dac33_startup(struct snd_pcm_substream *substream, | |||
812 | static void dac33_shutdown(struct snd_pcm_substream *substream, | 813 | static void dac33_shutdown(struct snd_pcm_substream *substream, |
813 | struct snd_soc_dai *dai) | 814 | struct snd_soc_dai *dai) |
814 | { | 815 | { |
815 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 816 | struct snd_soc_codec *codec = dai->codec; |
816 | struct snd_soc_codec *codec = rtd->codec; | ||
817 | struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec); | 817 | struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec); |
818 | 818 | ||
819 | dac33->substream = NULL; | 819 | dac33->substream = NULL; |
@@ -825,8 +825,7 @@ static int dac33_hw_params(struct snd_pcm_substream *substream, | |||
825 | struct snd_pcm_hw_params *params, | 825 | struct snd_pcm_hw_params *params, |
826 | struct snd_soc_dai *dai) | 826 | struct snd_soc_dai *dai) |
827 | { | 827 | { |
828 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 828 | struct snd_soc_codec *codec = dai->codec; |
829 | struct snd_soc_codec *codec = rtd->codec; | ||
830 | struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec); | 829 | struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec); |
831 | 830 | ||
832 | /* Check parameters for validity */ | 831 | /* Check parameters for validity */ |
@@ -868,10 +867,9 @@ static int dac33_hw_params(struct snd_pcm_substream *substream, | |||
868 | * writes happens in different order, than dac33 might end up in unknown state. | 867 | * writes happens in different order, than dac33 might end up in unknown state. |
869 | * Use the known, working sequence of register writes to initialize the dac33. | 868 | * Use the known, working sequence of register writes to initialize the dac33. |
870 | */ | 869 | */ |
871 | static int dac33_prepare_chip(struct snd_pcm_substream *substream) | 870 | static int dac33_prepare_chip(struct snd_pcm_substream *substream, |
871 | struct snd_soc_codec *codec) | ||
872 | { | 872 | { |
873 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
874 | struct snd_soc_codec *codec = rtd->codec; | ||
875 | struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec); | 873 | struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec); |
876 | unsigned int oscset, ratioset, pwr_ctrl, reg_tmp; | 874 | unsigned int oscset, ratioset, pwr_ctrl, reg_tmp; |
877 | u8 aictrl_a, aictrl_b, fifoctrl_a; | 875 | u8 aictrl_a, aictrl_b, fifoctrl_a; |
@@ -1067,10 +1065,9 @@ static int dac33_prepare_chip(struct snd_pcm_substream *substream) | |||
1067 | return 0; | 1065 | return 0; |
1068 | } | 1066 | } |
1069 | 1067 | ||
1070 | static void dac33_calculate_times(struct snd_pcm_substream *substream) | 1068 | static void dac33_calculate_times(struct snd_pcm_substream *substream, |
1069 | struct snd_soc_codec *codec) | ||
1071 | { | 1070 | { |
1072 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
1073 | struct snd_soc_codec *codec = rtd->codec; | ||
1074 | struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec); | 1071 | struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec); |
1075 | unsigned int period_size = substream->runtime->period_size; | 1072 | unsigned int period_size = substream->runtime->period_size; |
1076 | unsigned int rate = substream->runtime->rate; | 1073 | unsigned int rate = substream->runtime->rate; |
@@ -1128,8 +1125,7 @@ static void dac33_calculate_times(struct snd_pcm_substream *substream) | |||
1128 | static int dac33_pcm_trigger(struct snd_pcm_substream *substream, int cmd, | 1125 | static int dac33_pcm_trigger(struct snd_pcm_substream *substream, int cmd, |
1129 | struct snd_soc_dai *dai) | 1126 | struct snd_soc_dai *dai) |
1130 | { | 1127 | { |
1131 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 1128 | struct snd_soc_codec *codec = dai->codec; |
1132 | struct snd_soc_codec *codec = rtd->codec; | ||
1133 | struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec); | 1129 | struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec); |
1134 | int ret = 0; | 1130 | int ret = 0; |
1135 | 1131 | ||
@@ -1161,8 +1157,7 @@ static snd_pcm_sframes_t dac33_dai_delay( | |||
1161 | struct snd_pcm_substream *substream, | 1157 | struct snd_pcm_substream *substream, |
1162 | struct snd_soc_dai *dai) | 1158 | struct snd_soc_dai *dai) |
1163 | { | 1159 | { |
1164 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 1160 | struct snd_soc_codec *codec = dai->codec; |
1165 | struct snd_soc_codec *codec = rtd->codec; | ||
1166 | struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec); | 1161 | struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec); |
1167 | unsigned long long t0, t1, t_now; | 1162 | unsigned long long t0, t1, t_now; |
1168 | unsigned int time_delta, uthr; | 1163 | unsigned int time_delta, uthr; |
diff --git a/sound/soc/codecs/twl4030.c b/sound/soc/codecs/twl4030.c index 170cf9a8fc79..391fcfc7b63b 100644 --- a/sound/soc/codecs/twl4030.c +++ b/sound/soc/codecs/twl4030.c | |||
@@ -1685,8 +1685,7 @@ static void twl4030_tdm_enable(struct snd_soc_codec *codec, int direction, | |||
1685 | static int twl4030_startup(struct snd_pcm_substream *substream, | 1685 | static int twl4030_startup(struct snd_pcm_substream *substream, |
1686 | struct snd_soc_dai *dai) | 1686 | struct snd_soc_dai *dai) |
1687 | { | 1687 | { |
1688 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 1688 | struct snd_soc_codec *codec = dai->codec; |
1689 | struct snd_soc_codec *codec = rtd->codec; | ||
1690 | struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec); | 1689 | struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec); |
1691 | 1690 | ||
1692 | if (twl4030->master_substream) { | 1691 | if (twl4030->master_substream) { |
@@ -1715,8 +1714,7 @@ static int twl4030_startup(struct snd_pcm_substream *substream, | |||
1715 | static void twl4030_shutdown(struct snd_pcm_substream *substream, | 1714 | static void twl4030_shutdown(struct snd_pcm_substream *substream, |
1716 | struct snd_soc_dai *dai) | 1715 | struct snd_soc_dai *dai) |
1717 | { | 1716 | { |
1718 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 1717 | struct snd_soc_codec *codec = dai->codec; |
1719 | struct snd_soc_codec *codec = rtd->codec; | ||
1720 | struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec); | 1718 | struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec); |
1721 | 1719 | ||
1722 | if (twl4030->master_substream == substream) | 1720 | if (twl4030->master_substream == substream) |
@@ -1740,8 +1738,7 @@ static int twl4030_hw_params(struct snd_pcm_substream *substream, | |||
1740 | struct snd_pcm_hw_params *params, | 1738 | struct snd_pcm_hw_params *params, |
1741 | struct snd_soc_dai *dai) | 1739 | struct snd_soc_dai *dai) |
1742 | { | 1740 | { |
1743 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 1741 | struct snd_soc_codec *codec = dai->codec; |
1744 | struct snd_soc_codec *codec = rtd->codec; | ||
1745 | struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec); | 1742 | struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec); |
1746 | u8 mode, old_mode, format, old_format; | 1743 | u8 mode, old_mode, format, old_format; |
1747 | 1744 | ||
@@ -1974,8 +1971,7 @@ static void twl4030_voice_enable(struct snd_soc_codec *codec, int direction, | |||
1974 | static int twl4030_voice_startup(struct snd_pcm_substream *substream, | 1971 | static int twl4030_voice_startup(struct snd_pcm_substream *substream, |
1975 | struct snd_soc_dai *dai) | 1972 | struct snd_soc_dai *dai) |
1976 | { | 1973 | { |
1977 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 1974 | struct snd_soc_codec *codec = dai->codec; |
1978 | struct snd_soc_codec *codec = rtd->codec; | ||
1979 | struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec); | 1975 | struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec); |
1980 | u8 mode; | 1976 | u8 mode; |
1981 | 1977 | ||
@@ -2007,8 +2003,7 @@ static int twl4030_voice_startup(struct snd_pcm_substream *substream, | |||
2007 | static void twl4030_voice_shutdown(struct snd_pcm_substream *substream, | 2003 | static void twl4030_voice_shutdown(struct snd_pcm_substream *substream, |
2008 | struct snd_soc_dai *dai) | 2004 | struct snd_soc_dai *dai) |
2009 | { | 2005 | { |
2010 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 2006 | struct snd_soc_codec *codec = dai->codec; |
2011 | struct snd_soc_codec *codec = rtd->codec; | ||
2012 | 2007 | ||
2013 | /* Enable voice digital filters */ | 2008 | /* Enable voice digital filters */ |
2014 | twl4030_voice_enable(codec, substream->stream, 0); | 2009 | twl4030_voice_enable(codec, substream->stream, 0); |
@@ -2017,8 +2012,7 @@ static void twl4030_voice_shutdown(struct snd_pcm_substream *substream, | |||
2017 | static int twl4030_voice_hw_params(struct snd_pcm_substream *substream, | 2012 | static int twl4030_voice_hw_params(struct snd_pcm_substream *substream, |
2018 | struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) | 2013 | struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) |
2019 | { | 2014 | { |
2020 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 2015 | struct snd_soc_codec *codec = dai->codec; |
2021 | struct snd_soc_codec *codec = rtd->codec; | ||
2022 | struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec); | 2016 | struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec); |
2023 | u8 old_mode, mode; | 2017 | u8 old_mode, mode; |
2024 | 2018 | ||
diff --git a/sound/soc/codecs/twl6040.c b/sound/soc/codecs/twl6040.c index dc7509b9d53a..a36e9fcdf184 100644 --- a/sound/soc/codecs/twl6040.c +++ b/sound/soc/codecs/twl6040.c | |||
@@ -46,17 +46,6 @@ | |||
46 | #define TWL6040_OUTHF_0dB 0x03 | 46 | #define TWL6040_OUTHF_0dB 0x03 |
47 | #define TWL6040_OUTHF_M52dB 0x1D | 47 | #define TWL6040_OUTHF_M52dB 0x1D |
48 | 48 | ||
49 | #define TWL6040_RAMP_NONE 0 | ||
50 | #define TWL6040_RAMP_UP 1 | ||
51 | #define TWL6040_RAMP_DOWN 2 | ||
52 | |||
53 | #define TWL6040_HSL_VOL_MASK 0x0F | ||
54 | #define TWL6040_HSL_VOL_SHIFT 0 | ||
55 | #define TWL6040_HSR_VOL_MASK 0xF0 | ||
56 | #define TWL6040_HSR_VOL_SHIFT 4 | ||
57 | #define TWL6040_HF_VOL_MASK 0x1F | ||
58 | #define TWL6040_HF_VOL_SHIFT 0 | ||
59 | |||
60 | /* Shadow register used by the driver */ | 49 | /* Shadow register used by the driver */ |
61 | #define TWL6040_REG_SW_SHADOW 0x2F | 50 | #define TWL6040_REG_SW_SHADOW 0x2F |
62 | #define TWL6040_CACHEREGNUM (TWL6040_REG_SW_SHADOW + 1) | 51 | #define TWL6040_CACHEREGNUM (TWL6040_REG_SW_SHADOW + 1) |
@@ -64,18 +53,6 @@ | |||
64 | /* TWL6040_REG_SW_SHADOW (0x2F) fields */ | 53 | /* TWL6040_REG_SW_SHADOW (0x2F) fields */ |
65 | #define TWL6040_EAR_PATH_ENABLE 0x01 | 54 | #define TWL6040_EAR_PATH_ENABLE 0x01 |
66 | 55 | ||
67 | struct twl6040_output { | ||
68 | u16 active; | ||
69 | u16 left_vol; | ||
70 | u16 right_vol; | ||
71 | u16 left_step; | ||
72 | u16 right_step; | ||
73 | unsigned int step_delay; | ||
74 | u16 ramp; | ||
75 | struct delayed_work work; | ||
76 | struct completion ramp_done; | ||
77 | }; | ||
78 | |||
79 | struct twl6040_jack_data { | 56 | struct twl6040_jack_data { |
80 | struct snd_soc_jack *jack; | 57 | struct snd_soc_jack *jack; |
81 | struct delayed_work work; | 58 | struct delayed_work work; |
@@ -100,8 +77,6 @@ struct twl6040_data { | |||
100 | struct snd_soc_codec *codec; | 77 | struct snd_soc_codec *codec; |
101 | struct workqueue_struct *workqueue; | 78 | struct workqueue_struct *workqueue; |
102 | struct mutex mutex; | 79 | struct mutex mutex; |
103 | struct twl6040_output headset; | ||
104 | struct twl6040_output handsfree; | ||
105 | }; | 80 | }; |
106 | 81 | ||
107 | /* | 82 | /* |
@@ -311,318 +286,6 @@ static void twl6040_restore_regs(struct snd_soc_codec *codec) | |||
311 | } | 286 | } |
312 | } | 287 | } |
313 | 288 | ||
314 | /* | ||
315 | * Ramp HS PGA volume to minimise pops at stream startup and shutdown. | ||
316 | */ | ||
317 | static inline int twl6040_hs_ramp_step(struct snd_soc_codec *codec, | ||
318 | unsigned int left_step, unsigned int right_step) | ||
319 | { | ||
320 | |||
321 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); | ||
322 | struct twl6040_output *headset = &priv->headset; | ||
323 | int left_complete = 0, right_complete = 0; | ||
324 | u8 reg, val; | ||
325 | |||
326 | /* left channel */ | ||
327 | left_step = (left_step > 0xF) ? 0xF : left_step; | ||
328 | reg = twl6040_read_reg_cache(codec, TWL6040_REG_HSGAIN); | ||
329 | val = (~reg & TWL6040_HSL_VOL_MASK); | ||
330 | |||
331 | if (headset->ramp == TWL6040_RAMP_UP) { | ||
332 | /* ramp step up */ | ||
333 | if (val < headset->left_vol) { | ||
334 | if (val + left_step > headset->left_vol) | ||
335 | val = headset->left_vol; | ||
336 | else | ||
337 | val += left_step; | ||
338 | |||
339 | reg &= ~TWL6040_HSL_VOL_MASK; | ||
340 | twl6040_write(codec, TWL6040_REG_HSGAIN, | ||
341 | (reg | (~val & TWL6040_HSL_VOL_MASK))); | ||
342 | } else { | ||
343 | left_complete = 1; | ||
344 | } | ||
345 | } else if (headset->ramp == TWL6040_RAMP_DOWN) { | ||
346 | /* ramp step down */ | ||
347 | if (val > 0x0) { | ||
348 | if ((int)val - (int)left_step < 0) | ||
349 | val = 0; | ||
350 | else | ||
351 | val -= left_step; | ||
352 | |||
353 | reg &= ~TWL6040_HSL_VOL_MASK; | ||
354 | twl6040_write(codec, TWL6040_REG_HSGAIN, reg | | ||
355 | (~val & TWL6040_HSL_VOL_MASK)); | ||
356 | } else { | ||
357 | left_complete = 1; | ||
358 | } | ||
359 | } | ||
360 | |||
361 | /* right channel */ | ||
362 | right_step = (right_step > 0xF) ? 0xF : right_step; | ||
363 | reg = twl6040_read_reg_cache(codec, TWL6040_REG_HSGAIN); | ||
364 | val = (~reg & TWL6040_HSR_VOL_MASK) >> TWL6040_HSR_VOL_SHIFT; | ||
365 | |||
366 | if (headset->ramp == TWL6040_RAMP_UP) { | ||
367 | /* ramp step up */ | ||
368 | if (val < headset->right_vol) { | ||
369 | if (val + right_step > headset->right_vol) | ||
370 | val = headset->right_vol; | ||
371 | else | ||
372 | val += right_step; | ||
373 | |||
374 | reg &= ~TWL6040_HSR_VOL_MASK; | ||
375 | twl6040_write(codec, TWL6040_REG_HSGAIN, | ||
376 | (reg | (~val << TWL6040_HSR_VOL_SHIFT))); | ||
377 | } else { | ||
378 | right_complete = 1; | ||
379 | } | ||
380 | } else if (headset->ramp == TWL6040_RAMP_DOWN) { | ||
381 | /* ramp step down */ | ||
382 | if (val > 0x0) { | ||
383 | if ((int)val - (int)right_step < 0) | ||
384 | val = 0; | ||
385 | else | ||
386 | val -= right_step; | ||
387 | |||
388 | reg &= ~TWL6040_HSR_VOL_MASK; | ||
389 | twl6040_write(codec, TWL6040_REG_HSGAIN, | ||
390 | reg | (~val << TWL6040_HSR_VOL_SHIFT)); | ||
391 | } else { | ||
392 | right_complete = 1; | ||
393 | } | ||
394 | } | ||
395 | |||
396 | return left_complete & right_complete; | ||
397 | } | ||
398 | |||
399 | /* | ||
400 | * Ramp HF PGA volume to minimise pops at stream startup and shutdown. | ||
401 | */ | ||
402 | static inline int twl6040_hf_ramp_step(struct snd_soc_codec *codec, | ||
403 | unsigned int left_step, unsigned int right_step) | ||
404 | { | ||
405 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); | ||
406 | struct twl6040_output *handsfree = &priv->handsfree; | ||
407 | int left_complete = 0, right_complete = 0; | ||
408 | u16 reg, val; | ||
409 | |||
410 | /* left channel */ | ||
411 | left_step = (left_step > 0x1D) ? 0x1D : left_step; | ||
412 | reg = twl6040_read_reg_cache(codec, TWL6040_REG_HFLGAIN); | ||
413 | reg = 0x1D - reg; | ||
414 | val = (reg & TWL6040_HF_VOL_MASK); | ||
415 | if (handsfree->ramp == TWL6040_RAMP_UP) { | ||
416 | /* ramp step up */ | ||
417 | if (val < handsfree->left_vol) { | ||
418 | if (val + left_step > handsfree->left_vol) | ||
419 | val = handsfree->left_vol; | ||
420 | else | ||
421 | val += left_step; | ||
422 | |||
423 | reg &= ~TWL6040_HF_VOL_MASK; | ||
424 | twl6040_write(codec, TWL6040_REG_HFLGAIN, | ||
425 | reg | (0x1D - val)); | ||
426 | } else { | ||
427 | left_complete = 1; | ||
428 | } | ||
429 | } else if (handsfree->ramp == TWL6040_RAMP_DOWN) { | ||
430 | /* ramp step down */ | ||
431 | if (val > 0) { | ||
432 | if ((int)val - (int)left_step < 0) | ||
433 | val = 0; | ||
434 | else | ||
435 | val -= left_step; | ||
436 | |||
437 | reg &= ~TWL6040_HF_VOL_MASK; | ||
438 | twl6040_write(codec, TWL6040_REG_HFLGAIN, | ||
439 | reg | (0x1D - val)); | ||
440 | } else { | ||
441 | left_complete = 1; | ||
442 | } | ||
443 | } | ||
444 | |||
445 | /* right channel */ | ||
446 | right_step = (right_step > 0x1D) ? 0x1D : right_step; | ||
447 | reg = twl6040_read_reg_cache(codec, TWL6040_REG_HFRGAIN); | ||
448 | reg = 0x1D - reg; | ||
449 | val = (reg & TWL6040_HF_VOL_MASK); | ||
450 | if (handsfree->ramp == TWL6040_RAMP_UP) { | ||
451 | /* ramp step up */ | ||
452 | if (val < handsfree->right_vol) { | ||
453 | if (val + right_step > handsfree->right_vol) | ||
454 | val = handsfree->right_vol; | ||
455 | else | ||
456 | val += right_step; | ||
457 | |||
458 | reg &= ~TWL6040_HF_VOL_MASK; | ||
459 | twl6040_write(codec, TWL6040_REG_HFRGAIN, | ||
460 | reg | (0x1D - val)); | ||
461 | } else { | ||
462 | right_complete = 1; | ||
463 | } | ||
464 | } else if (handsfree->ramp == TWL6040_RAMP_DOWN) { | ||
465 | /* ramp step down */ | ||
466 | if (val > 0) { | ||
467 | if ((int)val - (int)right_step < 0) | ||
468 | val = 0; | ||
469 | else | ||
470 | val -= right_step; | ||
471 | |||
472 | reg &= ~TWL6040_HF_VOL_MASK; | ||
473 | twl6040_write(codec, TWL6040_REG_HFRGAIN, | ||
474 | reg | (0x1D - val)); | ||
475 | } | ||
476 | } | ||
477 | |||
478 | return left_complete & right_complete; | ||
479 | } | ||
480 | |||
481 | /* | ||
482 | * This work ramps both output PGAs at stream start/stop time to | ||
483 | * minimise pop associated with DAPM power switching. | ||
484 | */ | ||
485 | static void twl6040_pga_hs_work(struct work_struct *work) | ||
486 | { | ||
487 | struct twl6040_data *priv = | ||
488 | container_of(work, struct twl6040_data, headset.work.work); | ||
489 | struct snd_soc_codec *codec = priv->codec; | ||
490 | struct twl6040_output *headset = &priv->headset; | ||
491 | int i, headset_complete; | ||
492 | |||
493 | /* do we need to ramp at all ? */ | ||
494 | if (headset->ramp == TWL6040_RAMP_NONE) | ||
495 | return; | ||
496 | |||
497 | /* HS PGA gain range: 0x0 - 0xf (0 - 15) */ | ||
498 | for (i = 0; i < 16; i++) { | ||
499 | headset_complete = twl6040_hs_ramp_step(codec, | ||
500 | headset->left_step, | ||
501 | headset->right_step); | ||
502 | |||
503 | /* ramp finished ? */ | ||
504 | if (headset_complete) | ||
505 | break; | ||
506 | |||
507 | schedule_timeout_interruptible( | ||
508 | msecs_to_jiffies(headset->step_delay)); | ||
509 | } | ||
510 | |||
511 | if (headset->ramp == TWL6040_RAMP_DOWN) { | ||
512 | headset->active = 0; | ||
513 | complete(&headset->ramp_done); | ||
514 | } else { | ||
515 | headset->active = 1; | ||
516 | } | ||
517 | headset->ramp = TWL6040_RAMP_NONE; | ||
518 | } | ||
519 | |||
520 | static void twl6040_pga_hf_work(struct work_struct *work) | ||
521 | { | ||
522 | struct twl6040_data *priv = | ||
523 | container_of(work, struct twl6040_data, handsfree.work.work); | ||
524 | struct snd_soc_codec *codec = priv->codec; | ||
525 | struct twl6040_output *handsfree = &priv->handsfree; | ||
526 | int i, handsfree_complete; | ||
527 | |||
528 | /* do we need to ramp at all ? */ | ||
529 | if (handsfree->ramp == TWL6040_RAMP_NONE) | ||
530 | return; | ||
531 | |||
532 | /* | ||
533 | * HF PGA gain range: 0x00 - 0x1d (0 - 29) */ | ||
534 | for (i = 0; i < 30; i++) { | ||
535 | handsfree_complete = twl6040_hf_ramp_step(codec, | ||
536 | handsfree->left_step, | ||
537 | handsfree->right_step); | ||
538 | |||
539 | /* ramp finished ? */ | ||
540 | if (handsfree_complete) | ||
541 | break; | ||
542 | |||
543 | schedule_timeout_interruptible( | ||
544 | msecs_to_jiffies(handsfree->step_delay)); | ||
545 | } | ||
546 | |||
547 | |||
548 | if (handsfree->ramp == TWL6040_RAMP_DOWN) { | ||
549 | handsfree->active = 0; | ||
550 | complete(&handsfree->ramp_done); | ||
551 | } else | ||
552 | handsfree->active = 1; | ||
553 | handsfree->ramp = TWL6040_RAMP_NONE; | ||
554 | } | ||
555 | |||
556 | static int out_drv_event(struct snd_soc_dapm_widget *w, | ||
557 | struct snd_kcontrol *kcontrol, int event) | ||
558 | { | ||
559 | struct snd_soc_codec *codec = w->codec; | ||
560 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); | ||
561 | struct twl6040_output *out; | ||
562 | struct delayed_work *work; | ||
563 | |||
564 | switch (w->shift) { | ||
565 | case 2: /* Headset output driver */ | ||
566 | out = &priv->headset; | ||
567 | work = &out->work; | ||
568 | /* | ||
569 | * Make sure, that we do not mess up variables for already | ||
570 | * executing work. | ||
571 | */ | ||
572 | cancel_delayed_work_sync(work); | ||
573 | |||
574 | out->left_step = priv->hs_left_step; | ||
575 | out->right_step = priv->hs_right_step; | ||
576 | out->step_delay = 5; /* 5 ms between volume ramp steps */ | ||
577 | break; | ||
578 | case 4: /* Handsfree output driver */ | ||
579 | out = &priv->handsfree; | ||
580 | work = &out->work; | ||
581 | /* | ||
582 | * Make sure, that we do not mess up variables for already | ||
583 | * executing work. | ||
584 | */ | ||
585 | cancel_delayed_work_sync(work); | ||
586 | |||
587 | out->left_step = priv->hf_left_step; | ||
588 | out->right_step = priv->hf_right_step; | ||
589 | out->step_delay = 5; /* 5 ms between volume ramp steps */ | ||
590 | break; | ||
591 | default: | ||
592 | return -1; | ||
593 | } | ||
594 | |||
595 | switch (event) { | ||
596 | case SND_SOC_DAPM_POST_PMU: | ||
597 | if (out->active) | ||
598 | break; | ||
599 | |||
600 | /* don't use volume ramp for power-up */ | ||
601 | out->ramp = TWL6040_RAMP_UP; | ||
602 | out->left_step = out->left_vol; | ||
603 | out->right_step = out->right_vol; | ||
604 | |||
605 | queue_delayed_work(priv->workqueue, work, msecs_to_jiffies(1)); | ||
606 | break; | ||
607 | |||
608 | case SND_SOC_DAPM_PRE_PMD: | ||
609 | if (!out->active) | ||
610 | break; | ||
611 | |||
612 | /* use volume ramp for power-down */ | ||
613 | out->ramp = TWL6040_RAMP_DOWN; | ||
614 | INIT_COMPLETION(out->ramp_done); | ||
615 | |||
616 | queue_delayed_work(priv->workqueue, work, msecs_to_jiffies(1)); | ||
617 | |||
618 | wait_for_completion_timeout(&out->ramp_done, | ||
619 | msecs_to_jiffies(2000)); | ||
620 | break; | ||
621 | } | ||
622 | |||
623 | return 0; | ||
624 | } | ||
625 | |||
626 | /* set headset dac and driver power mode */ | 289 | /* set headset dac and driver power mode */ |
627 | static int headset_power_mode(struct snd_soc_codec *codec, int high_perf) | 290 | static int headset_power_mode(struct snd_soc_codec *codec, int high_perf) |
628 | { | 291 | { |
@@ -747,71 +410,6 @@ static irqreturn_t twl6040_audio_handler(int irq, void *data) | |||
747 | return IRQ_HANDLED; | 410 | return IRQ_HANDLED; |
748 | } | 411 | } |
749 | 412 | ||
750 | static int twl6040_put_volsw(struct snd_kcontrol *kcontrol, | ||
751 | struct snd_ctl_elem_value *ucontrol) | ||
752 | { | ||
753 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); | ||
754 | struct twl6040_data *twl6040_priv = snd_soc_codec_get_drvdata(codec); | ||
755 | struct twl6040_output *out = NULL; | ||
756 | struct soc_mixer_control *mc = | ||
757 | (struct soc_mixer_control *)kcontrol->private_value; | ||
758 | int ret; | ||
759 | |||
760 | /* For HS and HF we shadow the values and only actually write | ||
761 | * them out when active in order to ensure the amplifier comes on | ||
762 | * as quietly as possible. */ | ||
763 | switch (mc->reg) { | ||
764 | case TWL6040_REG_HSGAIN: | ||
765 | out = &twl6040_priv->headset; | ||
766 | break; | ||
767 | case TWL6040_REG_HFLGAIN: | ||
768 | out = &twl6040_priv->handsfree; | ||
769 | break; | ||
770 | default: | ||
771 | dev_warn(codec->dev, "%s: Unexpected register: 0x%02x\n", | ||
772 | __func__, mc->reg); | ||
773 | return -EINVAL; | ||
774 | } | ||
775 | |||
776 | out->left_vol = ucontrol->value.integer.value[0]; | ||
777 | out->right_vol = ucontrol->value.integer.value[1]; | ||
778 | if (!out->active) | ||
779 | return 1; | ||
780 | |||
781 | ret = snd_soc_put_volsw(kcontrol, ucontrol); | ||
782 | if (ret < 0) | ||
783 | return ret; | ||
784 | |||
785 | return 1; | ||
786 | } | ||
787 | |||
788 | static int twl6040_get_volsw(struct snd_kcontrol *kcontrol, | ||
789 | struct snd_ctl_elem_value *ucontrol) | ||
790 | { | ||
791 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); | ||
792 | struct twl6040_data *twl6040_priv = snd_soc_codec_get_drvdata(codec); | ||
793 | struct twl6040_output *out = &twl6040_priv->headset; | ||
794 | struct soc_mixer_control *mc = | ||
795 | (struct soc_mixer_control *)kcontrol->private_value; | ||
796 | |||
797 | switch (mc->reg) { | ||
798 | case TWL6040_REG_HSGAIN: | ||
799 | out = &twl6040_priv->headset; | ||
800 | break; | ||
801 | case TWL6040_REG_HFLGAIN: | ||
802 | out = &twl6040_priv->handsfree; | ||
803 | break; | ||
804 | default: | ||
805 | dev_warn(codec->dev, "%s: Unexpected register: 0x%02x\n", | ||
806 | __func__, mc->reg); | ||
807 | return -EINVAL; | ||
808 | } | ||
809 | |||
810 | ucontrol->value.integer.value[0] = out->left_vol; | ||
811 | ucontrol->value.integer.value[1] = out->right_vol; | ||
812 | return 0; | ||
813 | } | ||
814 | |||
815 | static int twl6040_soc_dapm_put_vibra_enum(struct snd_kcontrol *kcontrol, | 413 | static int twl6040_soc_dapm_put_vibra_enum(struct snd_kcontrol *kcontrol, |
816 | struct snd_ctl_elem_value *ucontrol) | 414 | struct snd_ctl_elem_value *ucontrol) |
817 | { | 415 | { |
@@ -1076,12 +674,10 @@ static const struct snd_kcontrol_new twl6040_snd_controls[] = { | |||
1076 | TWL6040_REG_LINEGAIN, 0, 3, 7, 0, afm_amp_tlv), | 674 | TWL6040_REG_LINEGAIN, 0, 3, 7, 0, afm_amp_tlv), |
1077 | 675 | ||
1078 | /* Playback gains */ | 676 | /* Playback gains */ |
1079 | SOC_DOUBLE_EXT_TLV("Headset Playback Volume", | 677 | SOC_DOUBLE_TLV("Headset Playback Volume", |
1080 | TWL6040_REG_HSGAIN, 0, 4, 0xF, 1, twl6040_get_volsw, | 678 | TWL6040_REG_HSGAIN, 0, 4, 0xF, 1, hs_tlv), |
1081 | twl6040_put_volsw, hs_tlv), | 679 | SOC_DOUBLE_R_TLV("Handsfree Playback Volume", |
1082 | SOC_DOUBLE_R_EXT_TLV("Handsfree Playback Volume", | 680 | TWL6040_REG_HFLGAIN, TWL6040_REG_HFRGAIN, 0, 0x1D, 1, hf_tlv), |
1083 | TWL6040_REG_HFLGAIN, TWL6040_REG_HFRGAIN, 0, 0x1D, 1, | ||
1084 | twl6040_get_volsw, twl6040_put_volsw, hf_tlv), | ||
1085 | SOC_SINGLE_TLV("Earphone Playback Volume", | 681 | SOC_SINGLE_TLV("Earphone Playback Volume", |
1086 | TWL6040_REG_EARCTL, 1, 0xF, 1, ep_tlv), | 682 | TWL6040_REG_EARCTL, 1, 0xF, 1, ep_tlv), |
1087 | 683 | ||
@@ -1180,22 +776,14 @@ static const struct snd_soc_dapm_widget twl6040_dapm_widgets[] = { | |||
1180 | &auxr_switch_control), | 776 | &auxr_switch_control), |
1181 | 777 | ||
1182 | /* Analog playback drivers */ | 778 | /* Analog playback drivers */ |
1183 | SND_SOC_DAPM_OUT_DRV_E("HF Left Driver", | 779 | SND_SOC_DAPM_OUT_DRV("HF Left Driver", |
1184 | TWL6040_REG_HFLCTL, 4, 0, NULL, 0, | 780 | TWL6040_REG_HFLCTL, 4, 0, NULL, 0), |
1185 | out_drv_event, | 781 | SND_SOC_DAPM_OUT_DRV("HF Right Driver", |
1186 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), | 782 | TWL6040_REG_HFRCTL, 4, 0, NULL, 0), |
1187 | SND_SOC_DAPM_OUT_DRV_E("HF Right Driver", | 783 | SND_SOC_DAPM_OUT_DRV("HS Left Driver", |
1188 | TWL6040_REG_HFRCTL, 4, 0, NULL, 0, | 784 | TWL6040_REG_HSLCTL, 2, 0, NULL, 0), |
1189 | out_drv_event, | 785 | SND_SOC_DAPM_OUT_DRV("HS Right Driver", |
1190 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), | 786 | TWL6040_REG_HSRCTL, 2, 0, NULL, 0), |
1191 | SND_SOC_DAPM_OUT_DRV_E("HS Left Driver", | ||
1192 | TWL6040_REG_HSLCTL, 2, 0, NULL, 0, | ||
1193 | out_drv_event, | ||
1194 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), | ||
1195 | SND_SOC_DAPM_OUT_DRV_E("HS Right Driver", | ||
1196 | TWL6040_REG_HSRCTL, 2, 0, NULL, 0, | ||
1197 | out_drv_event, | ||
1198 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), | ||
1199 | SND_SOC_DAPM_OUT_DRV_E("Earphone Driver", | 787 | SND_SOC_DAPM_OUT_DRV_E("Earphone Driver", |
1200 | TWL6040_REG_EARCTL, 0, 0, NULL, 0, | 788 | TWL6040_REG_EARCTL, 0, 0, NULL, 0, |
1201 | twl6040_ep_drv_event, | 789 | twl6040_ep_drv_event, |
@@ -1339,8 +927,7 @@ static int twl6040_set_bias_level(struct snd_soc_codec *codec, | |||
1339 | static int twl6040_startup(struct snd_pcm_substream *substream, | 927 | static int twl6040_startup(struct snd_pcm_substream *substream, |
1340 | struct snd_soc_dai *dai) | 928 | struct snd_soc_dai *dai) |
1341 | { | 929 | { |
1342 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 930 | struct snd_soc_codec *codec = dai->codec; |
1343 | struct snd_soc_codec *codec = rtd->codec; | ||
1344 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); | 931 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
1345 | 932 | ||
1346 | snd_pcm_hw_constraint_list(substream->runtime, 0, | 933 | snd_pcm_hw_constraint_list(substream->runtime, 0, |
@@ -1354,8 +941,7 @@ static int twl6040_hw_params(struct snd_pcm_substream *substream, | |||
1354 | struct snd_pcm_hw_params *params, | 941 | struct snd_pcm_hw_params *params, |
1355 | struct snd_soc_dai *dai) | 942 | struct snd_soc_dai *dai) |
1356 | { | 943 | { |
1357 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 944 | struct snd_soc_codec *codec = dai->codec; |
1358 | struct snd_soc_codec *codec = rtd->codec; | ||
1359 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); | 945 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
1360 | int rate; | 946 | int rate; |
1361 | 947 | ||
@@ -1391,8 +977,7 @@ static int twl6040_hw_params(struct snd_pcm_substream *substream, | |||
1391 | static int twl6040_prepare(struct snd_pcm_substream *substream, | 977 | static int twl6040_prepare(struct snd_pcm_substream *substream, |
1392 | struct snd_soc_dai *dai) | 978 | struct snd_soc_dai *dai) |
1393 | { | 979 | { |
1394 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 980 | struct snd_soc_codec *codec = dai->codec; |
1395 | struct snd_soc_codec *codec = rtd->codec; | ||
1396 | struct twl6040 *twl6040 = codec->control_data; | 981 | struct twl6040 *twl6040 = codec->control_data; |
1397 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); | 982 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
1398 | int ret; | 983 | int ret; |
@@ -1570,14 +1155,9 @@ static int twl6040_probe(struct snd_soc_codec *codec) | |||
1570 | } | 1155 | } |
1571 | 1156 | ||
1572 | INIT_DELAYED_WORK(&priv->hs_jack.work, twl6040_accessory_work); | 1157 | INIT_DELAYED_WORK(&priv->hs_jack.work, twl6040_accessory_work); |
1573 | INIT_DELAYED_WORK(&priv->headset.work, twl6040_pga_hs_work); | ||
1574 | INIT_DELAYED_WORK(&priv->handsfree.work, twl6040_pga_hf_work); | ||
1575 | 1158 | ||
1576 | mutex_init(&priv->mutex); | 1159 | mutex_init(&priv->mutex); |
1577 | 1160 | ||
1578 | init_completion(&priv->headset.ramp_done); | ||
1579 | init_completion(&priv->handsfree.ramp_done); | ||
1580 | |||
1581 | ret = request_threaded_irq(priv->plug_irq, NULL, twl6040_audio_handler, | 1161 | ret = request_threaded_irq(priv->plug_irq, NULL, twl6040_audio_handler, |
1582 | 0, "twl6040_irq_plug", codec); | 1162 | 0, "twl6040_irq_plug", codec); |
1583 | if (ret) { | 1163 | if (ret) { |
diff --git a/sound/soc/codecs/uda134x.c b/sound/soc/codecs/uda134x.c index 797b0dde2c68..6c3d43b8ee85 100644 --- a/sound/soc/codecs/uda134x.c +++ b/sound/soc/codecs/uda134x.c | |||
@@ -159,8 +159,7 @@ static int uda134x_mute(struct snd_soc_dai *dai, int mute) | |||
159 | static int uda134x_startup(struct snd_pcm_substream *substream, | 159 | static int uda134x_startup(struct snd_pcm_substream *substream, |
160 | struct snd_soc_dai *dai) | 160 | struct snd_soc_dai *dai) |
161 | { | 161 | { |
162 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 162 | struct snd_soc_codec *codec = dai->codec; |
163 | struct snd_soc_codec *codec =rtd->codec; | ||
164 | struct uda134x_priv *uda134x = snd_soc_codec_get_drvdata(codec); | 163 | struct uda134x_priv *uda134x = snd_soc_codec_get_drvdata(codec); |
165 | struct snd_pcm_runtime *master_runtime; | 164 | struct snd_pcm_runtime *master_runtime; |
166 | 165 | ||
@@ -191,8 +190,7 @@ static int uda134x_startup(struct snd_pcm_substream *substream, | |||
191 | static void uda134x_shutdown(struct snd_pcm_substream *substream, | 190 | static void uda134x_shutdown(struct snd_pcm_substream *substream, |
192 | struct snd_soc_dai *dai) | 191 | struct snd_soc_dai *dai) |
193 | { | 192 | { |
194 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 193 | struct snd_soc_codec *codec = dai->codec; |
195 | struct snd_soc_codec *codec = rtd->codec; | ||
196 | struct uda134x_priv *uda134x = snd_soc_codec_get_drvdata(codec); | 194 | struct uda134x_priv *uda134x = snd_soc_codec_get_drvdata(codec); |
197 | 195 | ||
198 | if (uda134x->master_substream == substream) | 196 | if (uda134x->master_substream == substream) |
diff --git a/sound/soc/codecs/uda1380.c b/sound/soc/codecs/uda1380.c index 4f1b23d7e404..2502214b84ab 100644 --- a/sound/soc/codecs/uda1380.c +++ b/sound/soc/codecs/uda1380.c | |||
@@ -502,8 +502,7 @@ static int uda1380_set_dai_fmt_capture(struct snd_soc_dai *codec_dai, | |||
502 | static int uda1380_trigger(struct snd_pcm_substream *substream, int cmd, | 502 | static int uda1380_trigger(struct snd_pcm_substream *substream, int cmd, |
503 | struct snd_soc_dai *dai) | 503 | struct snd_soc_dai *dai) |
504 | { | 504 | { |
505 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 505 | struct snd_soc_codec *codec = dai->codec; |
506 | struct snd_soc_codec *codec = rtd->codec; | ||
507 | struct uda1380_priv *uda1380 = snd_soc_codec_get_drvdata(codec); | 506 | struct uda1380_priv *uda1380 = snd_soc_codec_get_drvdata(codec); |
508 | int mixer = uda1380_read_reg_cache(codec, UDA1380_MIXER); | 507 | int mixer = uda1380_read_reg_cache(codec, UDA1380_MIXER); |
509 | 508 | ||
@@ -528,8 +527,7 @@ static int uda1380_pcm_hw_params(struct snd_pcm_substream *substream, | |||
528 | struct snd_pcm_hw_params *params, | 527 | struct snd_pcm_hw_params *params, |
529 | struct snd_soc_dai *dai) | 528 | struct snd_soc_dai *dai) |
530 | { | 529 | { |
531 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 530 | struct snd_soc_codec *codec = dai->codec; |
532 | struct snd_soc_codec *codec = rtd->codec; | ||
533 | u16 clk = uda1380_read_reg_cache(codec, UDA1380_CLK); | 531 | u16 clk = uda1380_read_reg_cache(codec, UDA1380_CLK); |
534 | 532 | ||
535 | /* set WSPLL power and divider if running from this clock */ | 533 | /* set WSPLL power and divider if running from this clock */ |
diff --git a/sound/soc/codecs/wl1273.c b/sound/soc/codecs/wl1273.c index 3d868dc40092..7b24d6d192e1 100644 --- a/sound/soc/codecs/wl1273.c +++ b/sound/soc/codecs/wl1273.c | |||
@@ -293,8 +293,7 @@ static const struct snd_kcontrol_new wl1273_controls[] = { | |||
293 | static int wl1273_startup(struct snd_pcm_substream *substream, | 293 | static int wl1273_startup(struct snd_pcm_substream *substream, |
294 | struct snd_soc_dai *dai) | 294 | struct snd_soc_dai *dai) |
295 | { | 295 | { |
296 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 296 | struct snd_soc_codec *codec = dai->codec; |
297 | struct snd_soc_codec *codec = rtd->codec; | ||
298 | struct wl1273_priv *wl1273 = snd_soc_codec_get_drvdata(codec); | 297 | struct wl1273_priv *wl1273 = snd_soc_codec_get_drvdata(codec); |
299 | 298 | ||
300 | switch (wl1273->mode) { | 299 | switch (wl1273->mode) { |
@@ -329,8 +328,7 @@ static int wl1273_hw_params(struct snd_pcm_substream *substream, | |||
329 | struct snd_pcm_hw_params *params, | 328 | struct snd_pcm_hw_params *params, |
330 | struct snd_soc_dai *dai) | 329 | struct snd_soc_dai *dai) |
331 | { | 330 | { |
332 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 331 | struct wl1273_priv *wl1273 = snd_soc_codec_get_drvdata(dai->codec); |
333 | struct wl1273_priv *wl1273 = snd_soc_codec_get_drvdata(rtd->codec); | ||
334 | struct wl1273_core *core = wl1273->core; | 332 | struct wl1273_core *core = wl1273->core; |
335 | unsigned int rate, width, r; | 333 | unsigned int rate, width, r; |
336 | 334 | ||
diff --git a/sound/soc/codecs/wm1250-ev1.c b/sound/soc/codecs/wm1250-ev1.c index aefb4f89be0e..e0b51e9f8b12 100644 --- a/sound/soc/codecs/wm1250-ev1.c +++ b/sound/soc/codecs/wm1250-ev1.c | |||
@@ -79,22 +79,65 @@ static const struct snd_soc_dapm_route wm1250_ev1_dapm_routes[] = { | |||
79 | { "WM1250 Output", NULL, "DAC" }, | 79 | { "WM1250 Output", NULL, "DAC" }, |
80 | }; | 80 | }; |
81 | 81 | ||
82 | static int wm1250_ev1_hw_params(struct snd_pcm_substream *substream, | ||
83 | struct snd_pcm_hw_params *params, | ||
84 | struct snd_soc_dai *dai) | ||
85 | { | ||
86 | struct wm1250_priv *wm1250 = snd_soc_codec_get_drvdata(dai->codec); | ||
87 | |||
88 | switch (params_rate(params)) { | ||
89 | case 8000: | ||
90 | gpio_set_value(wm1250->gpios[WM1250_EV1_GPIO_CLK_SEL0].gpio, | ||
91 | 1); | ||
92 | gpio_set_value(wm1250->gpios[WM1250_EV1_GPIO_CLK_SEL1].gpio, | ||
93 | 1); | ||
94 | break; | ||
95 | case 16000: | ||
96 | gpio_set_value(wm1250->gpios[WM1250_EV1_GPIO_CLK_SEL0].gpio, | ||
97 | 0); | ||
98 | gpio_set_value(wm1250->gpios[WM1250_EV1_GPIO_CLK_SEL1].gpio, | ||
99 | 1); | ||
100 | break; | ||
101 | case 32000: | ||
102 | gpio_set_value(wm1250->gpios[WM1250_EV1_GPIO_CLK_SEL0].gpio, | ||
103 | 1); | ||
104 | gpio_set_value(wm1250->gpios[WM1250_EV1_GPIO_CLK_SEL1].gpio, | ||
105 | 0); | ||
106 | break; | ||
107 | case 64000: | ||
108 | gpio_set_value(wm1250->gpios[WM1250_EV1_GPIO_CLK_SEL0].gpio, | ||
109 | 0); | ||
110 | gpio_set_value(wm1250->gpios[WM1250_EV1_GPIO_CLK_SEL1].gpio, | ||
111 | 0); | ||
112 | break; | ||
113 | default: | ||
114 | return -EINVAL; | ||
115 | } | ||
116 | |||
117 | return 0; | ||
118 | } | ||
119 | |||
120 | static const struct snd_soc_dai_ops wm1250_ev1_ops = { | ||
121 | .hw_params = wm1250_ev1_hw_params, | ||
122 | }; | ||
123 | |||
82 | static struct snd_soc_dai_driver wm1250_ev1_dai = { | 124 | static struct snd_soc_dai_driver wm1250_ev1_dai = { |
83 | .name = "wm1250-ev1", | 125 | .name = "wm1250-ev1", |
84 | .playback = { | 126 | .playback = { |
85 | .stream_name = "Playback", | 127 | .stream_name = "Playback", |
86 | .channels_min = 1, | 128 | .channels_min = 1, |
87 | .channels_max = 1, | 129 | .channels_max = 2, |
88 | .rates = SNDRV_PCM_RATE_8000, | 130 | .rates = SNDRV_PCM_RATE_8000, |
89 | .formats = SNDRV_PCM_FMTBIT_S16_LE, | 131 | .formats = SNDRV_PCM_FMTBIT_S16_LE, |
90 | }, | 132 | }, |
91 | .capture = { | 133 | .capture = { |
92 | .stream_name = "Capture", | 134 | .stream_name = "Capture", |
93 | .channels_min = 1, | 135 | .channels_min = 1, |
94 | .channels_max = 1, | 136 | .channels_max = 2, |
95 | .rates = SNDRV_PCM_RATE_8000, | 137 | .rates = SNDRV_PCM_RATE_8000, |
96 | .formats = SNDRV_PCM_FMTBIT_S16_LE, | 138 | .formats = SNDRV_PCM_FMTBIT_S16_LE, |
97 | }, | 139 | }, |
140 | .ops = &wm1250_ev1_ops, | ||
98 | }; | 141 | }; |
99 | 142 | ||
100 | static struct snd_soc_codec_driver soc_codec_dev_wm1250_ev1 = { | 143 | static struct snd_soc_codec_driver soc_codec_dev_wm1250_ev1 = { |
@@ -215,23 +258,7 @@ static struct i2c_driver wm1250_ev1_i2c_driver = { | |||
215 | .id_table = wm1250_ev1_i2c_id, | 258 | .id_table = wm1250_ev1_i2c_id, |
216 | }; | 259 | }; |
217 | 260 | ||
218 | static int __init wm1250_ev1_modinit(void) | 261 | module_i2c_driver(wm1250_ev1_i2c_driver); |
219 | { | ||
220 | int ret = 0; | ||
221 | |||
222 | ret = i2c_add_driver(&wm1250_ev1_i2c_driver); | ||
223 | if (ret != 0) | ||
224 | pr_err("Failed to register WM1250-EV1 I2C driver: %d\n", ret); | ||
225 | |||
226 | return ret; | ||
227 | } | ||
228 | module_init(wm1250_ev1_modinit); | ||
229 | |||
230 | static void __exit wm1250_ev1_exit(void) | ||
231 | { | ||
232 | i2c_del_driver(&wm1250_ev1_i2c_driver); | ||
233 | } | ||
234 | module_exit(wm1250_ev1_exit); | ||
235 | 262 | ||
236 | MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); | 263 | MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); |
237 | MODULE_DESCRIPTION("WM1250-EV1 audio I/O module driver"); | 264 | MODULE_DESCRIPTION("WM1250-EV1 audio I/O module driver"); |
diff --git a/sound/soc/codecs/wm5100-tables.c b/sound/soc/codecs/wm5100-tables.c index 9a18fae68204..e167207a19cc 100644 --- a/sound/soc/codecs/wm5100-tables.c +++ b/sound/soc/codecs/wm5100-tables.c | |||
@@ -32,7 +32,18 @@ bool wm5100_volatile_register(struct device *dev, unsigned int reg) | |||
32 | case WM5100_MIC_DETECT_3: | 32 | case WM5100_MIC_DETECT_3: |
33 | return 1; | 33 | return 1; |
34 | default: | 34 | default: |
35 | return 0; | 35 | if ((reg >= WM5100_DSP1_PM_0 && reg <= WM5100_DSP1_PM_1535) || |
36 | (reg >= WM5100_DSP1_ZM_0 && reg <= WM5100_DSP1_ZM_2047) || | ||
37 | (reg >= WM5100_DSP1_DM_0 && reg <= WM5100_DSP1_DM_511) || | ||
38 | (reg >= WM5100_DSP2_PM_0 && reg <= WM5100_DSP2_PM_1535) || | ||
39 | (reg >= WM5100_DSP2_ZM_0 && reg <= WM5100_DSP2_ZM_2047) || | ||
40 | (reg >= WM5100_DSP2_DM_0 && reg <= WM5100_DSP2_DM_511) || | ||
41 | (reg >= WM5100_DSP3_PM_0 && reg <= WM5100_DSP3_PM_1535) || | ||
42 | (reg >= WM5100_DSP3_ZM_0 && reg <= WM5100_DSP3_ZM_2047) || | ||
43 | (reg >= WM5100_DSP3_DM_0 && reg <= WM5100_DSP3_DM_511)) | ||
44 | return 1; | ||
45 | else | ||
46 | return 0; | ||
36 | } | 47 | } |
37 | } | 48 | } |
38 | 49 | ||
@@ -697,9 +708,110 @@ bool wm5100_readable_register(struct device *dev, unsigned int reg) | |||
697 | case WM5100_HPLPF3_2: | 708 | case WM5100_HPLPF3_2: |
698 | case WM5100_HPLPF4_1: | 709 | case WM5100_HPLPF4_1: |
699 | case WM5100_HPLPF4_2: | 710 | case WM5100_HPLPF4_2: |
711 | case WM5100_DSP1_CONTROL_1: | ||
712 | case WM5100_DSP1_CONTROL_2: | ||
713 | case WM5100_DSP1_CONTROL_3: | ||
714 | case WM5100_DSP1_CONTROL_4: | ||
715 | case WM5100_DSP1_CONTROL_5: | ||
716 | case WM5100_DSP1_CONTROL_6: | ||
717 | case WM5100_DSP1_CONTROL_7: | ||
718 | case WM5100_DSP1_CONTROL_8: | ||
719 | case WM5100_DSP1_CONTROL_9: | ||
720 | case WM5100_DSP1_CONTROL_10: | ||
721 | case WM5100_DSP1_CONTROL_11: | ||
722 | case WM5100_DSP1_CONTROL_12: | ||
723 | case WM5100_DSP1_CONTROL_13: | ||
724 | case WM5100_DSP1_CONTROL_14: | ||
725 | case WM5100_DSP1_CONTROL_15: | ||
726 | case WM5100_DSP1_CONTROL_16: | ||
727 | case WM5100_DSP1_CONTROL_17: | ||
728 | case WM5100_DSP1_CONTROL_18: | ||
729 | case WM5100_DSP1_CONTROL_19: | ||
730 | case WM5100_DSP1_CONTROL_20: | ||
731 | case WM5100_DSP1_CONTROL_21: | ||
732 | case WM5100_DSP1_CONTROL_22: | ||
733 | case WM5100_DSP1_CONTROL_23: | ||
734 | case WM5100_DSP1_CONTROL_24: | ||
735 | case WM5100_DSP1_CONTROL_25: | ||
736 | case WM5100_DSP1_CONTROL_26: | ||
737 | case WM5100_DSP1_CONTROL_27: | ||
738 | case WM5100_DSP1_CONTROL_28: | ||
739 | case WM5100_DSP1_CONTROL_29: | ||
740 | case WM5100_DSP1_CONTROL_30: | ||
741 | case WM5100_DSP2_CONTROL_1: | ||
742 | case WM5100_DSP2_CONTROL_2: | ||
743 | case WM5100_DSP2_CONTROL_3: | ||
744 | case WM5100_DSP2_CONTROL_4: | ||
745 | case WM5100_DSP2_CONTROL_5: | ||
746 | case WM5100_DSP2_CONTROL_6: | ||
747 | case WM5100_DSP2_CONTROL_7: | ||
748 | case WM5100_DSP2_CONTROL_8: | ||
749 | case WM5100_DSP2_CONTROL_9: | ||
750 | case WM5100_DSP2_CONTROL_10: | ||
751 | case WM5100_DSP2_CONTROL_11: | ||
752 | case WM5100_DSP2_CONTROL_12: | ||
753 | case WM5100_DSP2_CONTROL_13: | ||
754 | case WM5100_DSP2_CONTROL_14: | ||
755 | case WM5100_DSP2_CONTROL_15: | ||
756 | case WM5100_DSP2_CONTROL_16: | ||
757 | case WM5100_DSP2_CONTROL_17: | ||
758 | case WM5100_DSP2_CONTROL_18: | ||
759 | case WM5100_DSP2_CONTROL_19: | ||
760 | case WM5100_DSP2_CONTROL_20: | ||
761 | case WM5100_DSP2_CONTROL_21: | ||
762 | case WM5100_DSP2_CONTROL_22: | ||
763 | case WM5100_DSP2_CONTROL_23: | ||
764 | case WM5100_DSP2_CONTROL_24: | ||
765 | case WM5100_DSP2_CONTROL_25: | ||
766 | case WM5100_DSP2_CONTROL_26: | ||
767 | case WM5100_DSP2_CONTROL_27: | ||
768 | case WM5100_DSP2_CONTROL_28: | ||
769 | case WM5100_DSP2_CONTROL_29: | ||
770 | case WM5100_DSP2_CONTROL_30: | ||
771 | case WM5100_DSP3_CONTROL_1: | ||
772 | case WM5100_DSP3_CONTROL_2: | ||
773 | case WM5100_DSP3_CONTROL_3: | ||
774 | case WM5100_DSP3_CONTROL_4: | ||
775 | case WM5100_DSP3_CONTROL_5: | ||
776 | case WM5100_DSP3_CONTROL_6: | ||
777 | case WM5100_DSP3_CONTROL_7: | ||
778 | case WM5100_DSP3_CONTROL_8: | ||
779 | case WM5100_DSP3_CONTROL_9: | ||
780 | case WM5100_DSP3_CONTROL_10: | ||
781 | case WM5100_DSP3_CONTROL_11: | ||
782 | case WM5100_DSP3_CONTROL_12: | ||
783 | case WM5100_DSP3_CONTROL_13: | ||
784 | case WM5100_DSP3_CONTROL_14: | ||
785 | case WM5100_DSP3_CONTROL_15: | ||
786 | case WM5100_DSP3_CONTROL_16: | ||
787 | case WM5100_DSP3_CONTROL_17: | ||
788 | case WM5100_DSP3_CONTROL_18: | ||
789 | case WM5100_DSP3_CONTROL_19: | ||
790 | case WM5100_DSP3_CONTROL_20: | ||
791 | case WM5100_DSP3_CONTROL_21: | ||
792 | case WM5100_DSP3_CONTROL_22: | ||
793 | case WM5100_DSP3_CONTROL_23: | ||
794 | case WM5100_DSP3_CONTROL_24: | ||
795 | case WM5100_DSP3_CONTROL_25: | ||
796 | case WM5100_DSP3_CONTROL_26: | ||
797 | case WM5100_DSP3_CONTROL_27: | ||
798 | case WM5100_DSP3_CONTROL_28: | ||
799 | case WM5100_DSP3_CONTROL_29: | ||
800 | case WM5100_DSP3_CONTROL_30: | ||
700 | return 1; | 801 | return 1; |
701 | default: | 802 | default: |
702 | return 0; | 803 | if ((reg >= WM5100_DSP1_PM_0 && reg <= WM5100_DSP1_PM_1535) || |
804 | (reg >= WM5100_DSP1_ZM_0 && reg <= WM5100_DSP1_ZM_2047) || | ||
805 | (reg >= WM5100_DSP1_DM_0 && reg <= WM5100_DSP1_DM_511) || | ||
806 | (reg >= WM5100_DSP2_PM_0 && reg <= WM5100_DSP2_PM_1535) || | ||
807 | (reg >= WM5100_DSP2_ZM_0 && reg <= WM5100_DSP2_ZM_2047) || | ||
808 | (reg >= WM5100_DSP2_DM_0 && reg <= WM5100_DSP2_DM_511) || | ||
809 | (reg >= WM5100_DSP3_PM_0 && reg <= WM5100_DSP3_PM_1535) || | ||
810 | (reg >= WM5100_DSP3_ZM_0 && reg <= WM5100_DSP3_ZM_2047) || | ||
811 | (reg >= WM5100_DSP3_DM_0 && reg <= WM5100_DSP3_DM_511)) | ||
812 | return 1; | ||
813 | else | ||
814 | return 0; | ||
703 | } | 815 | } |
704 | } | 816 | } |
705 | 817 | ||
@@ -1361,4 +1473,13 @@ struct reg_default wm5100_reg_defaults[WM5100_REGISTER_COUNT] = { | |||
1361 | { 0x0EC9, 0x0000 }, /* R3785 - HPLPF3_2 */ | 1473 | { 0x0EC9, 0x0000 }, /* R3785 - HPLPF3_2 */ |
1362 | { 0x0ECC, 0x0000 }, /* R3788 - HPLPF4_1 */ | 1474 | { 0x0ECC, 0x0000 }, /* R3788 - HPLPF4_1 */ |
1363 | { 0x0ECD, 0x0000 }, /* R3789 - HPLPF4_2 */ | 1475 | { 0x0ECD, 0x0000 }, /* R3789 - HPLPF4_2 */ |
1476 | { 0x0F02, 0x0000 }, /* R3842 - DSP1 Control 2 */ | ||
1477 | { 0x0F03, 0x0000 }, /* R3843 - DSP1 Control 3 */ | ||
1478 | { 0x0F04, 0x0000 }, /* R3844 - DSP1 Control 4 */ | ||
1479 | { 0x1002, 0x0000 }, /* R4098 - DSP2 Control 2 */ | ||
1480 | { 0x1003, 0x0000 }, /* R4099 - DSP2 Control 3 */ | ||
1481 | { 0x1004, 0x0000 }, /* R4100 - DSP2 Control 4 */ | ||
1482 | { 0x1102, 0x0000 }, /* R4354 - DSP3 Control 2 */ | ||
1483 | { 0x1103, 0x0000 }, /* R4355 - DSP3 Control 3 */ | ||
1484 | { 0x1104, 0x0000 }, /* R4356 - DSP3 Control 4 */ | ||
1364 | }; | 1485 | }; |
diff --git a/sound/soc/codecs/wm5100.c b/sound/soc/codecs/wm5100.c index b9c185ce64e4..cb6d5372103a 100644 --- a/sound/soc/codecs/wm5100.c +++ b/sound/soc/codecs/wm5100.c | |||
@@ -1265,29 +1265,12 @@ static const __devinitdata struct reg_default wm5100_reva_patches[] = { | |||
1265 | { WM5100_AUDIO_IF_3_19, 1 }, | 1265 | { WM5100_AUDIO_IF_3_19, 1 }, |
1266 | }; | 1266 | }; |
1267 | 1267 | ||
1268 | static int wm5100_dai_to_base(struct snd_soc_dai *dai) | ||
1269 | { | ||
1270 | switch (dai->id) { | ||
1271 | case 0: | ||
1272 | return WM5100_AUDIO_IF_1_1 - 1; | ||
1273 | case 1: | ||
1274 | return WM5100_AUDIO_IF_2_1 - 1; | ||
1275 | case 2: | ||
1276 | return WM5100_AUDIO_IF_3_1 - 1; | ||
1277 | default: | ||
1278 | BUG(); | ||
1279 | return -EINVAL; | ||
1280 | } | ||
1281 | } | ||
1282 | |||
1283 | static int wm5100_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) | 1268 | static int wm5100_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) |
1284 | { | 1269 | { |
1285 | struct snd_soc_codec *codec = dai->codec; | 1270 | struct snd_soc_codec *codec = dai->codec; |
1286 | int lrclk, bclk, mask, base; | 1271 | int lrclk, bclk, mask, base; |
1287 | 1272 | ||
1288 | base = wm5100_dai_to_base(dai); | 1273 | base = dai->driver->base; |
1289 | if (base < 0) | ||
1290 | return base; | ||
1291 | 1274 | ||
1292 | lrclk = 0; | 1275 | lrclk = 0; |
1293 | bclk = 0; | 1276 | bclk = 0; |
@@ -1414,9 +1397,7 @@ static int wm5100_hw_params(struct snd_pcm_substream *substream, | |||
1414 | int i, base, bclk, aif_rate, lrclk, wl, fl, sr; | 1397 | int i, base, bclk, aif_rate, lrclk, wl, fl, sr; |
1415 | int *bclk_rates; | 1398 | int *bclk_rates; |
1416 | 1399 | ||
1417 | base = wm5100_dai_to_base(dai); | 1400 | base = dai->driver->base; |
1418 | if (base < 0) | ||
1419 | return base; | ||
1420 | 1401 | ||
1421 | /* Data sizes if not using TDM */ | 1402 | /* Data sizes if not using TDM */ |
1422 | wl = snd_pcm_format_width(params_format(params)); | 1403 | wl = snd_pcm_format_width(params_format(params)); |
@@ -1897,6 +1878,7 @@ static int wm5100_set_fll(struct snd_soc_codec *codec, int fll_id, int source, | |||
1897 | static struct snd_soc_dai_driver wm5100_dai[] = { | 1878 | static struct snd_soc_dai_driver wm5100_dai[] = { |
1898 | { | 1879 | { |
1899 | .name = "wm5100-aif1", | 1880 | .name = "wm5100-aif1", |
1881 | .base = WM5100_AUDIO_IF_1_1 - 1, | ||
1900 | .playback = { | 1882 | .playback = { |
1901 | .stream_name = "AIF1 Playback", | 1883 | .stream_name = "AIF1 Playback", |
1902 | .channels_min = 2, | 1884 | .channels_min = 2, |
@@ -1916,6 +1898,7 @@ static struct snd_soc_dai_driver wm5100_dai[] = { | |||
1916 | { | 1898 | { |
1917 | .name = "wm5100-aif2", | 1899 | .name = "wm5100-aif2", |
1918 | .id = 1, | 1900 | .id = 1, |
1901 | .base = WM5100_AUDIO_IF_2_1 - 1, | ||
1919 | .playback = { | 1902 | .playback = { |
1920 | .stream_name = "AIF2 Playback", | 1903 | .stream_name = "AIF2 Playback", |
1921 | .channels_min = 2, | 1904 | .channels_min = 2, |
@@ -1935,6 +1918,7 @@ static struct snd_soc_dai_driver wm5100_dai[] = { | |||
1935 | { | 1918 | { |
1936 | .name = "wm5100-aif3", | 1919 | .name = "wm5100-aif3", |
1937 | .id = 2, | 1920 | .id = 2, |
1921 | .base = WM5100_AUDIO_IF_3_1 - 1, | ||
1938 | .playback = { | 1922 | .playback = { |
1939 | .stream_name = "AIF3 Playback", | 1923 | .stream_name = "AIF3 Playback", |
1940 | .channels_min = 2, | 1924 | .channels_min = 2, |
@@ -2454,7 +2438,7 @@ static __devinit int wm5100_i2c_probe(struct i2c_client *i2c, | |||
2454 | 2438 | ||
2455 | wm5100->dev = &i2c->dev; | 2439 | wm5100->dev = &i2c->dev; |
2456 | 2440 | ||
2457 | wm5100->regmap = regmap_init_i2c(i2c, &wm5100_regmap); | 2441 | wm5100->regmap = devm_regmap_init_i2c(i2c, &wm5100_regmap); |
2458 | if (IS_ERR(wm5100->regmap)) { | 2442 | if (IS_ERR(wm5100->regmap)) { |
2459 | ret = PTR_ERR(wm5100->regmap); | 2443 | ret = PTR_ERR(wm5100->regmap); |
2460 | dev_err(&i2c->dev, "Failed to allocate register map: %d\n", | 2444 | dev_err(&i2c->dev, "Failed to allocate register map: %d\n", |
@@ -2479,7 +2463,7 @@ static __devinit int wm5100_i2c_probe(struct i2c_client *i2c, | |||
2479 | if (ret != 0) { | 2463 | if (ret != 0) { |
2480 | dev_err(&i2c->dev, "Failed to request core supplies: %d\n", | 2464 | dev_err(&i2c->dev, "Failed to request core supplies: %d\n", |
2481 | ret); | 2465 | ret); |
2482 | goto err_regmap; | 2466 | goto err; |
2483 | } | 2467 | } |
2484 | 2468 | ||
2485 | ret = regulator_bulk_enable(ARRAY_SIZE(wm5100->core_supplies), | 2469 | ret = regulator_bulk_enable(ARRAY_SIZE(wm5100->core_supplies), |
@@ -2487,7 +2471,7 @@ static __devinit int wm5100_i2c_probe(struct i2c_client *i2c, | |||
2487 | if (ret != 0) { | 2471 | if (ret != 0) { |
2488 | dev_err(&i2c->dev, "Failed to enable core supplies: %d\n", | 2472 | dev_err(&i2c->dev, "Failed to enable core supplies: %d\n", |
2489 | ret); | 2473 | ret); |
2490 | goto err_regmap; | 2474 | goto err; |
2491 | } | 2475 | } |
2492 | 2476 | ||
2493 | if (wm5100->pdata.ldo_ena) { | 2477 | if (wm5100->pdata.ldo_ena) { |
@@ -2660,8 +2644,6 @@ err_ldo: | |||
2660 | err_enable: | 2644 | err_enable: |
2661 | regulator_bulk_disable(ARRAY_SIZE(wm5100->core_supplies), | 2645 | regulator_bulk_disable(ARRAY_SIZE(wm5100->core_supplies), |
2662 | wm5100->core_supplies); | 2646 | wm5100->core_supplies); |
2663 | err_regmap: | ||
2664 | regmap_exit(wm5100->regmap); | ||
2665 | err: | 2647 | err: |
2666 | return ret; | 2648 | return ret; |
2667 | } | 2649 | } |
@@ -2682,7 +2664,6 @@ static __devexit int wm5100_i2c_remove(struct i2c_client *i2c) | |||
2682 | gpio_set_value_cansleep(wm5100->pdata.ldo_ena, 0); | 2664 | gpio_set_value_cansleep(wm5100->pdata.ldo_ena, 0); |
2683 | gpio_free(wm5100->pdata.ldo_ena); | 2665 | gpio_free(wm5100->pdata.ldo_ena); |
2684 | } | 2666 | } |
2685 | regmap_exit(wm5100->regmap); | ||
2686 | 2667 | ||
2687 | return 0; | 2668 | return 0; |
2688 | } | 2669 | } |
@@ -2749,17 +2730,7 @@ static struct i2c_driver wm5100_i2c_driver = { | |||
2749 | .id_table = wm5100_i2c_id, | 2730 | .id_table = wm5100_i2c_id, |
2750 | }; | 2731 | }; |
2751 | 2732 | ||
2752 | static int __init wm5100_modinit(void) | 2733 | module_i2c_driver(wm5100_i2c_driver); |
2753 | { | ||
2754 | return i2c_add_driver(&wm5100_i2c_driver); | ||
2755 | } | ||
2756 | module_init(wm5100_modinit); | ||
2757 | |||
2758 | static void __exit wm5100_exit(void) | ||
2759 | { | ||
2760 | i2c_del_driver(&wm5100_i2c_driver); | ||
2761 | } | ||
2762 | module_exit(wm5100_exit); | ||
2763 | 2734 | ||
2764 | MODULE_DESCRIPTION("ASoC WM5100 driver"); | 2735 | MODULE_DESCRIPTION("ASoC WM5100 driver"); |
2765 | MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); | 2736 | MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); |
diff --git a/sound/soc/codecs/wm5100.h b/sound/soc/codecs/wm5100.h index 25cb6016f9d7..935a9b7fb274 100644 --- a/sound/soc/codecs/wm5100.h +++ b/sound/soc/codecs/wm5100.h | |||
@@ -709,6 +709,96 @@ int wm5100_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack); | |||
709 | #define WM5100_HPLPF3_2 0xEC9 | 709 | #define WM5100_HPLPF3_2 0xEC9 |
710 | #define WM5100_HPLPF4_1 0xECC | 710 | #define WM5100_HPLPF4_1 0xECC |
711 | #define WM5100_HPLPF4_2 0xECD | 711 | #define WM5100_HPLPF4_2 0xECD |
712 | #define WM5100_DSP1_CONTROL_1 0xF00 | ||
713 | #define WM5100_DSP1_CONTROL_2 0xF02 | ||
714 | #define WM5100_DSP1_CONTROL_3 0xF03 | ||
715 | #define WM5100_DSP1_CONTROL_4 0xF04 | ||
716 | #define WM5100_DSP1_CONTROL_5 0xF06 | ||
717 | #define WM5100_DSP1_CONTROL_6 0xF07 | ||
718 | #define WM5100_DSP1_CONTROL_7 0xF08 | ||
719 | #define WM5100_DSP1_CONTROL_8 0xF09 | ||
720 | #define WM5100_DSP1_CONTROL_9 0xF0A | ||
721 | #define WM5100_DSP1_CONTROL_10 0xF0B | ||
722 | #define WM5100_DSP1_CONTROL_11 0xF0C | ||
723 | #define WM5100_DSP1_CONTROL_12 0xF0D | ||
724 | #define WM5100_DSP1_CONTROL_13 0xF0F | ||
725 | #define WM5100_DSP1_CONTROL_14 0xF10 | ||
726 | #define WM5100_DSP1_CONTROL_15 0xF11 | ||
727 | #define WM5100_DSP1_CONTROL_16 0xF12 | ||
728 | #define WM5100_DSP1_CONTROL_17 0xF13 | ||
729 | #define WM5100_DSP1_CONTROL_18 0xF14 | ||
730 | #define WM5100_DSP1_CONTROL_19 0xF16 | ||
731 | #define WM5100_DSP1_CONTROL_20 0xF17 | ||
732 | #define WM5100_DSP1_CONTROL_21 0xF18 | ||
733 | #define WM5100_DSP1_CONTROL_22 0xF1A | ||
734 | #define WM5100_DSP1_CONTROL_23 0xF1B | ||
735 | #define WM5100_DSP1_CONTROL_24 0xF1C | ||
736 | #define WM5100_DSP1_CONTROL_25 0xF1E | ||
737 | #define WM5100_DSP1_CONTROL_26 0xF20 | ||
738 | #define WM5100_DSP1_CONTROL_27 0xF21 | ||
739 | #define WM5100_DSP1_CONTROL_28 0xF22 | ||
740 | #define WM5100_DSP1_CONTROL_29 0xF23 | ||
741 | #define WM5100_DSP1_CONTROL_30 0xF24 | ||
742 | #define WM5100_DSP2_CONTROL_1 0x1000 | ||
743 | #define WM5100_DSP2_CONTROL_2 0x1002 | ||
744 | #define WM5100_DSP2_CONTROL_3 0x1003 | ||
745 | #define WM5100_DSP2_CONTROL_4 0x1004 | ||
746 | #define WM5100_DSP2_CONTROL_5 0x1006 | ||
747 | #define WM5100_DSP2_CONTROL_6 0x1007 | ||
748 | #define WM5100_DSP2_CONTROL_7 0x1008 | ||
749 | #define WM5100_DSP2_CONTROL_8 0x1009 | ||
750 | #define WM5100_DSP2_CONTROL_9 0x100A | ||
751 | #define WM5100_DSP2_CONTROL_10 0x100B | ||
752 | #define WM5100_DSP2_CONTROL_11 0x100C | ||
753 | #define WM5100_DSP2_CONTROL_12 0x100D | ||
754 | #define WM5100_DSP2_CONTROL_13 0x100F | ||
755 | #define WM5100_DSP2_CONTROL_14 0x1010 | ||
756 | #define WM5100_DSP2_CONTROL_15 0x1011 | ||
757 | #define WM5100_DSP2_CONTROL_16 0x1012 | ||
758 | #define WM5100_DSP2_CONTROL_17 0x1013 | ||
759 | #define WM5100_DSP2_CONTROL_18 0x1014 | ||
760 | #define WM5100_DSP2_CONTROL_19 0x1016 | ||
761 | #define WM5100_DSP2_CONTROL_20 0x1017 | ||
762 | #define WM5100_DSP2_CONTROL_21 0x1018 | ||
763 | #define WM5100_DSP2_CONTROL_22 0x101A | ||
764 | #define WM5100_DSP2_CONTROL_23 0x101B | ||
765 | #define WM5100_DSP2_CONTROL_24 0x101C | ||
766 | #define WM5100_DSP2_CONTROL_25 0x101E | ||
767 | #define WM5100_DSP2_CONTROL_26 0x1020 | ||
768 | #define WM5100_DSP2_CONTROL_27 0x1021 | ||
769 | #define WM5100_DSP2_CONTROL_28 0x1022 | ||
770 | #define WM5100_DSP2_CONTROL_29 0x1023 | ||
771 | #define WM5100_DSP2_CONTROL_30 0x1024 | ||
772 | #define WM5100_DSP3_CONTROL_1 0x1100 | ||
773 | #define WM5100_DSP3_CONTROL_2 0x1102 | ||
774 | #define WM5100_DSP3_CONTROL_3 0x1103 | ||
775 | #define WM5100_DSP3_CONTROL_4 0x1104 | ||
776 | #define WM5100_DSP3_CONTROL_5 0x1106 | ||
777 | #define WM5100_DSP3_CONTROL_6 0x1107 | ||
778 | #define WM5100_DSP3_CONTROL_7 0x1108 | ||
779 | #define WM5100_DSP3_CONTROL_8 0x1109 | ||
780 | #define WM5100_DSP3_CONTROL_9 0x110A | ||
781 | #define WM5100_DSP3_CONTROL_10 0x110B | ||
782 | #define WM5100_DSP3_CONTROL_11 0x110C | ||
783 | #define WM5100_DSP3_CONTROL_12 0x110D | ||
784 | #define WM5100_DSP3_CONTROL_13 0x110F | ||
785 | #define WM5100_DSP3_CONTROL_14 0x1110 | ||
786 | #define WM5100_DSP3_CONTROL_15 0x1111 | ||
787 | #define WM5100_DSP3_CONTROL_16 0x1112 | ||
788 | #define WM5100_DSP3_CONTROL_17 0x1113 | ||
789 | #define WM5100_DSP3_CONTROL_18 0x1114 | ||
790 | #define WM5100_DSP3_CONTROL_19 0x1116 | ||
791 | #define WM5100_DSP3_CONTROL_20 0x1117 | ||
792 | #define WM5100_DSP3_CONTROL_21 0x1118 | ||
793 | #define WM5100_DSP3_CONTROL_22 0x111A | ||
794 | #define WM5100_DSP3_CONTROL_23 0x111B | ||
795 | #define WM5100_DSP3_CONTROL_24 0x111C | ||
796 | #define WM5100_DSP3_CONTROL_25 0x111E | ||
797 | #define WM5100_DSP3_CONTROL_26 0x1120 | ||
798 | #define WM5100_DSP3_CONTROL_27 0x1121 | ||
799 | #define WM5100_DSP3_CONTROL_28 0x1122 | ||
800 | #define WM5100_DSP3_CONTROL_29 0x1123 | ||
801 | #define WM5100_DSP3_CONTROL_30 0x1124 | ||
712 | #define WM5100_DSP1_DM_0 0x4000 | 802 | #define WM5100_DSP1_DM_0 0x4000 |
713 | #define WM5100_DSP1_DM_1 0x4001 | 803 | #define WM5100_DSP1_DM_1 0x4001 |
714 | #define WM5100_DSP1_DM_2 0x4002 | 804 | #define WM5100_DSP1_DM_2 0x4002 |
@@ -4561,6 +4651,75 @@ int wm5100_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack); | |||
4561 | #define WM5100_LHPF4_COEFF_WIDTH 16 /* LHPF4_COEFF - [15:0] */ | 4651 | #define WM5100_LHPF4_COEFF_WIDTH 16 /* LHPF4_COEFF - [15:0] */ |
4562 | 4652 | ||
4563 | /* | 4653 | /* |
4654 | * R4132 (0x1024) - DSP2 Control 30 | ||
4655 | */ | ||
4656 | #define WM5100_DSP2_RATE_MASK 0xC000 /* DSP2_RATE - [15:14] */ | ||
4657 | #define WM5100_DSP2_RATE_SHIFT 14 /* DSP2_RATE - [15:14] */ | ||
4658 | #define WM5100_DSP2_RATE_WIDTH 2 /* DSP2_RATE - [15:14] */ | ||
4659 | #define WM5100_DSP2_DBG_CLK_ENA 0x0008 /* DSP2_DBG_CLK_ENA */ | ||
4660 | #define WM5100_DSP2_DBG_CLK_ENA_MASK 0x0008 /* DSP2_DBG_CLK_ENA */ | ||
4661 | #define WM5100_DSP2_DBG_CLK_ENA_SHIFT 3 /* DSP2_DBG_CLK_ENA */ | ||
4662 | #define WM5100_DSP2_DBG_CLK_ENA_WIDTH 1 /* DSP2_DBG_CLK_ENA */ | ||
4663 | #define WM5100_DSP2_SYS_ENA 0x0004 /* DSP2_SYS_ENA */ | ||
4664 | #define WM5100_DSP2_SYS_ENA_MASK 0x0004 /* DSP2_SYS_ENA */ | ||
4665 | #define WM5100_DSP2_SYS_ENA_SHIFT 2 /* DSP2_SYS_ENA */ | ||
4666 | #define WM5100_DSP2_SYS_ENA_WIDTH 1 /* DSP2_SYS_ENA */ | ||
4667 | #define WM5100_DSP2_CORE_ENA 0x0002 /* DSP2_CORE_ENA */ | ||
4668 | #define WM5100_DSP2_CORE_ENA_MASK 0x0002 /* DSP2_CORE_ENA */ | ||
4669 | #define WM5100_DSP2_CORE_ENA_SHIFT 1 /* DSP2_CORE_ENA */ | ||
4670 | #define WM5100_DSP2_CORE_ENA_WIDTH 1 /* DSP2_CORE_ENA */ | ||
4671 | #define WM5100_DSP2_START 0x0001 /* DSP2_START */ | ||
4672 | #define WM5100_DSP2_START_MASK 0x0001 /* DSP2_START */ | ||
4673 | #define WM5100_DSP2_START_SHIFT 0 /* DSP2_START */ | ||
4674 | #define WM5100_DSP2_START_WIDTH 1 /* DSP2_START */ | ||
4675 | |||
4676 | /* | ||
4677 | * R3876 (0xF24) - DSP1 Control 30 | ||
4678 | */ | ||
4679 | #define WM5100_DSP1_RATE_MASK 0xC000 /* DSP1_RATE - [15:14] */ | ||
4680 | #define WM5100_DSP1_RATE_SHIFT 14 /* DSP1_RATE - [15:14] */ | ||
4681 | #define WM5100_DSP1_RATE_WIDTH 2 /* DSP1_RATE - [15:14] */ | ||
4682 | #define WM5100_DSP1_DBG_CLK_ENA 0x0008 /* DSP1_DBG_CLK_ENA */ | ||
4683 | #define WM5100_DSP1_DBG_CLK_ENA_MASK 0x0008 /* DSP1_DBG_CLK_ENA */ | ||
4684 | #define WM5100_DSP1_DBG_CLK_ENA_SHIFT 3 /* DSP1_DBG_CLK_ENA */ | ||
4685 | #define WM5100_DSP1_DBG_CLK_ENA_WIDTH 1 /* DSP1_DBG_CLK_ENA */ | ||
4686 | #define WM5100_DSP1_SYS_ENA 0x0004 /* DSP1_SYS_ENA */ | ||
4687 | #define WM5100_DSP1_SYS_ENA_MASK 0x0004 /* DSP1_SYS_ENA */ | ||
4688 | #define WM5100_DSP1_SYS_ENA_SHIFT 2 /* DSP1_SYS_ENA */ | ||
4689 | #define WM5100_DSP1_SYS_ENA_WIDTH 1 /* DSP1_SYS_ENA */ | ||
4690 | #define WM5100_DSP1_CORE_ENA 0x0002 /* DSP1_CORE_ENA */ | ||
4691 | #define WM5100_DSP1_CORE_ENA_MASK 0x0002 /* DSP1_CORE_ENA */ | ||
4692 | #define WM5100_DSP1_CORE_ENA_SHIFT 1 /* DSP1_CORE_ENA */ | ||
4693 | #define WM5100_DSP1_CORE_ENA_WIDTH 1 /* DSP1_CORE_ENA */ | ||
4694 | #define WM5100_DSP1_START 0x0001 /* DSP1_START */ | ||
4695 | #define WM5100_DSP1_START_MASK 0x0001 /* DSP1_START */ | ||
4696 | #define WM5100_DSP1_START_SHIFT 0 /* DSP1_START */ | ||
4697 | #define WM5100_DSP1_START_WIDTH 1 /* DSP1_START */ | ||
4698 | |||
4699 | /* | ||
4700 | * R4388 (0x1124) - DSP3 Control 30 | ||
4701 | */ | ||
4702 | #define WM5100_DSP3_RATE_MASK 0xC000 /* DSP3_RATE - [15:14] */ | ||
4703 | #define WM5100_DSP3_RATE_SHIFT 14 /* DSP3_RATE - [15:14] */ | ||
4704 | #define WM5100_DSP3_RATE_WIDTH 2 /* DSP3_RATE - [15:14] */ | ||
4705 | #define WM5100_DSP3_DBG_CLK_ENA 0x0008 /* DSP3_DBG_CLK_ENA */ | ||
4706 | #define WM5100_DSP3_DBG_CLK_ENA_MASK 0x0008 /* DSP3_DBG_CLK_ENA */ | ||
4707 | #define WM5100_DSP3_DBG_CLK_ENA_SHIFT 3 /* DSP3_DBG_CLK_ENA */ | ||
4708 | #define WM5100_DSP3_DBG_CLK_ENA_WIDTH 1 /* DSP3_DBG_CLK_ENA */ | ||
4709 | #define WM5100_DSP3_SYS_ENA 0x0004 /* DSP3_SYS_ENA */ | ||
4710 | #define WM5100_DSP3_SYS_ENA_MASK 0x0004 /* DSP3_SYS_ENA */ | ||
4711 | #define WM5100_DSP3_SYS_ENA_SHIFT 2 /* DSP3_SYS_ENA */ | ||
4712 | #define WM5100_DSP3_SYS_ENA_WIDTH 1 /* DSP3_SYS_ENA */ | ||
4713 | #define WM5100_DSP3_CORE_ENA 0x0002 /* DSP3_CORE_ENA */ | ||
4714 | #define WM5100_DSP3_CORE_ENA_MASK 0x0002 /* DSP3_CORE_ENA */ | ||
4715 | #define WM5100_DSP3_CORE_ENA_SHIFT 1 /* DSP3_CORE_ENA */ | ||
4716 | #define WM5100_DSP3_CORE_ENA_WIDTH 1 /* DSP3_CORE_ENA */ | ||
4717 | #define WM5100_DSP3_START 0x0001 /* DSP3_START */ | ||
4718 | #define WM5100_DSP3_START_MASK 0x0001 /* DSP3_START */ | ||
4719 | #define WM5100_DSP3_START_SHIFT 0 /* DSP3_START */ | ||
4720 | #define WM5100_DSP3_START_WIDTH 1 /* DSP3_START */ | ||
4721 | |||
4722 | /* | ||
4564 | * R16384 (0x4000) - DSP1 DM 0 | 4723 | * R16384 (0x4000) - DSP1 DM 0 |
4565 | */ | 4724 | */ |
4566 | #define WM5100_DSP1_DM_START_1_MASK 0x00FF /* DSP1_DM_START - [7:0] */ | 4725 | #define WM5100_DSP1_DM_START_1_MASK 0x00FF /* DSP1_DM_START - [7:0] */ |
diff --git a/sound/soc/codecs/wm8350.c b/sound/soc/codecs/wm8350.c index aa12c6b6beeb..555ee146ae0d 100644 --- a/sound/soc/codecs/wm8350.c +++ b/sound/soc/codecs/wm8350.c | |||
@@ -71,13 +71,6 @@ struct wm8350_data { | |||
71 | int fll_freq_in; | 71 | int fll_freq_in; |
72 | }; | 72 | }; |
73 | 73 | ||
74 | static unsigned int wm8350_codec_cache_read(struct snd_soc_codec *codec, | ||
75 | unsigned int reg) | ||
76 | { | ||
77 | struct wm8350 *wm8350 = codec->control_data; | ||
78 | return wm8350->reg_cache[reg]; | ||
79 | } | ||
80 | |||
81 | static unsigned int wm8350_codec_read(struct snd_soc_codec *codec, | 74 | static unsigned int wm8350_codec_read(struct snd_soc_codec *codec, |
82 | unsigned int reg) | 75 | unsigned int reg) |
83 | { | 76 | { |
@@ -99,7 +92,7 @@ static inline int wm8350_out1_ramp_step(struct snd_soc_codec *codec) | |||
99 | { | 92 | { |
100 | struct wm8350_data *wm8350_data = snd_soc_codec_get_drvdata(codec); | 93 | struct wm8350_data *wm8350_data = snd_soc_codec_get_drvdata(codec); |
101 | struct wm8350_output *out1 = &wm8350_data->out1; | 94 | struct wm8350_output *out1 = &wm8350_data->out1; |
102 | struct wm8350 *wm8350 = codec->control_data; | 95 | struct wm8350 *wm8350 = wm8350_data->wm8350; |
103 | int left_complete = 0, right_complete = 0; | 96 | int left_complete = 0, right_complete = 0; |
104 | u16 reg, val; | 97 | u16 reg, val; |
105 | 98 | ||
@@ -165,7 +158,7 @@ static inline int wm8350_out2_ramp_step(struct snd_soc_codec *codec) | |||
165 | { | 158 | { |
166 | struct wm8350_data *wm8350_data = snd_soc_codec_get_drvdata(codec); | 159 | struct wm8350_data *wm8350_data = snd_soc_codec_get_drvdata(codec); |
167 | struct wm8350_output *out2 = &wm8350_data->out2; | 160 | struct wm8350_output *out2 = &wm8350_data->out2; |
168 | struct wm8350 *wm8350 = codec->control_data; | 161 | struct wm8350 *wm8350 = wm8350_data->wm8350; |
169 | int left_complete = 0, right_complete = 0; | 162 | int left_complete = 0, right_complete = 0; |
170 | u16 reg, val; | 163 | u16 reg, val; |
171 | 164 | ||
@@ -360,8 +353,8 @@ static int wm8350_put_volsw_2r_vu(struct snd_kcontrol *kcontrol, | |||
360 | return ret; | 353 | return ret; |
361 | 354 | ||
362 | /* now hit the volume update bits (always bit 8) */ | 355 | /* now hit the volume update bits (always bit 8) */ |
363 | val = wm8350_codec_read(codec, reg); | 356 | val = snd_soc_read(codec, reg); |
364 | wm8350_codec_write(codec, reg, val | WM8350_OUT1_VU); | 357 | snd_soc_write(codec, reg, val | WM8350_OUT1_VU); |
365 | return 1; | 358 | return 1; |
366 | } | 359 | } |
367 | 360 | ||
@@ -781,7 +774,8 @@ static int wm8350_set_dai_sysclk(struct snd_soc_dai *codec_dai, | |||
781 | int clk_id, unsigned int freq, int dir) | 774 | int clk_id, unsigned int freq, int dir) |
782 | { | 775 | { |
783 | struct snd_soc_codec *codec = codec_dai->codec; | 776 | struct snd_soc_codec *codec = codec_dai->codec; |
784 | struct wm8350 *wm8350 = codec->control_data; | 777 | struct wm8350_data *wm8350_data = snd_soc_codec_get_drvdata(codec); |
778 | struct wm8350 *wm8350 = wm8350_data->wm8350; | ||
785 | u16 fll_4; | 779 | u16 fll_4; |
786 | 780 | ||
787 | switch (clk_id) { | 781 | switch (clk_id) { |
@@ -795,9 +789,9 @@ static int wm8350_set_dai_sysclk(struct snd_soc_dai *codec_dai, | |||
795 | case WM8350_MCLK_SEL_PLL_32K: | 789 | case WM8350_MCLK_SEL_PLL_32K: |
796 | wm8350_set_bits(wm8350, WM8350_CLOCK_CONTROL_1, | 790 | wm8350_set_bits(wm8350, WM8350_CLOCK_CONTROL_1, |
797 | WM8350_MCLK_SEL); | 791 | WM8350_MCLK_SEL); |
798 | fll_4 = wm8350_codec_read(codec, WM8350_FLL_CONTROL_4) & | 792 | fll_4 = snd_soc_read(codec, WM8350_FLL_CONTROL_4) & |
799 | ~WM8350_FLL_CLK_SRC_MASK; | 793 | ~WM8350_FLL_CLK_SRC_MASK; |
800 | wm8350_codec_write(codec, WM8350_FLL_CONTROL_4, fll_4 | clk_id); | 794 | snd_soc_write(codec, WM8350_FLL_CONTROL_4, fll_4 | clk_id); |
801 | break; | 795 | break; |
802 | } | 796 | } |
803 | 797 | ||
@@ -819,39 +813,39 @@ static int wm8350_set_clkdiv(struct snd_soc_dai *codec_dai, int div_id, int div) | |||
819 | 813 | ||
820 | switch (div_id) { | 814 | switch (div_id) { |
821 | case WM8350_ADC_CLKDIV: | 815 | case WM8350_ADC_CLKDIV: |
822 | val = wm8350_codec_read(codec, WM8350_ADC_DIVIDER) & | 816 | val = snd_soc_read(codec, WM8350_ADC_DIVIDER) & |
823 | ~WM8350_ADC_CLKDIV_MASK; | 817 | ~WM8350_ADC_CLKDIV_MASK; |
824 | wm8350_codec_write(codec, WM8350_ADC_DIVIDER, val | div); | 818 | snd_soc_write(codec, WM8350_ADC_DIVIDER, val | div); |
825 | break; | 819 | break; |
826 | case WM8350_DAC_CLKDIV: | 820 | case WM8350_DAC_CLKDIV: |
827 | val = wm8350_codec_read(codec, WM8350_DAC_CLOCK_CONTROL) & | 821 | val = snd_soc_read(codec, WM8350_DAC_CLOCK_CONTROL) & |
828 | ~WM8350_DAC_CLKDIV_MASK; | 822 | ~WM8350_DAC_CLKDIV_MASK; |
829 | wm8350_codec_write(codec, WM8350_DAC_CLOCK_CONTROL, val | div); | 823 | snd_soc_write(codec, WM8350_DAC_CLOCK_CONTROL, val | div); |
830 | break; | 824 | break; |
831 | case WM8350_BCLK_CLKDIV: | 825 | case WM8350_BCLK_CLKDIV: |
832 | val = wm8350_codec_read(codec, WM8350_CLOCK_CONTROL_1) & | 826 | val = snd_soc_read(codec, WM8350_CLOCK_CONTROL_1) & |
833 | ~WM8350_BCLK_DIV_MASK; | 827 | ~WM8350_BCLK_DIV_MASK; |
834 | wm8350_codec_write(codec, WM8350_CLOCK_CONTROL_1, val | div); | 828 | snd_soc_write(codec, WM8350_CLOCK_CONTROL_1, val | div); |
835 | break; | 829 | break; |
836 | case WM8350_OPCLK_CLKDIV: | 830 | case WM8350_OPCLK_CLKDIV: |
837 | val = wm8350_codec_read(codec, WM8350_CLOCK_CONTROL_1) & | 831 | val = snd_soc_read(codec, WM8350_CLOCK_CONTROL_1) & |
838 | ~WM8350_OPCLK_DIV_MASK; | 832 | ~WM8350_OPCLK_DIV_MASK; |
839 | wm8350_codec_write(codec, WM8350_CLOCK_CONTROL_1, val | div); | 833 | snd_soc_write(codec, WM8350_CLOCK_CONTROL_1, val | div); |
840 | break; | 834 | break; |
841 | case WM8350_SYS_CLKDIV: | 835 | case WM8350_SYS_CLKDIV: |
842 | val = wm8350_codec_read(codec, WM8350_CLOCK_CONTROL_1) & | 836 | val = snd_soc_read(codec, WM8350_CLOCK_CONTROL_1) & |
843 | ~WM8350_MCLK_DIV_MASK; | 837 | ~WM8350_MCLK_DIV_MASK; |
844 | wm8350_codec_write(codec, WM8350_CLOCK_CONTROL_1, val | div); | 838 | snd_soc_write(codec, WM8350_CLOCK_CONTROL_1, val | div); |
845 | break; | 839 | break; |
846 | case WM8350_DACLR_CLKDIV: | 840 | case WM8350_DACLR_CLKDIV: |
847 | val = wm8350_codec_read(codec, WM8350_DAC_LR_RATE) & | 841 | val = snd_soc_read(codec, WM8350_DAC_LR_RATE) & |
848 | ~WM8350_DACLRC_RATE_MASK; | 842 | ~WM8350_DACLRC_RATE_MASK; |
849 | wm8350_codec_write(codec, WM8350_DAC_LR_RATE, val | div); | 843 | snd_soc_write(codec, WM8350_DAC_LR_RATE, val | div); |
850 | break; | 844 | break; |
851 | case WM8350_ADCLR_CLKDIV: | 845 | case WM8350_ADCLR_CLKDIV: |
852 | val = wm8350_codec_read(codec, WM8350_ADC_LR_RATE) & | 846 | val = snd_soc_read(codec, WM8350_ADC_LR_RATE) & |
853 | ~WM8350_ADCLRC_RATE_MASK; | 847 | ~WM8350_ADCLRC_RATE_MASK; |
854 | wm8350_codec_write(codec, WM8350_ADC_LR_RATE, val | div); | 848 | snd_soc_write(codec, WM8350_ADC_LR_RATE, val | div); |
855 | break; | 849 | break; |
856 | default: | 850 | default: |
857 | return -EINVAL; | 851 | return -EINVAL; |
@@ -863,13 +857,13 @@ static int wm8350_set_clkdiv(struct snd_soc_dai *codec_dai, int div_id, int div) | |||
863 | static int wm8350_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt) | 857 | static int wm8350_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt) |
864 | { | 858 | { |
865 | struct snd_soc_codec *codec = codec_dai->codec; | 859 | struct snd_soc_codec *codec = codec_dai->codec; |
866 | u16 iface = wm8350_codec_read(codec, WM8350_AI_FORMATING) & | 860 | u16 iface = snd_soc_read(codec, WM8350_AI_FORMATING) & |
867 | ~(WM8350_AIF_BCLK_INV | WM8350_AIF_LRCLK_INV | WM8350_AIF_FMT_MASK); | 861 | ~(WM8350_AIF_BCLK_INV | WM8350_AIF_LRCLK_INV | WM8350_AIF_FMT_MASK); |
868 | u16 master = wm8350_codec_read(codec, WM8350_AI_DAC_CONTROL) & | 862 | u16 master = snd_soc_read(codec, WM8350_AI_DAC_CONTROL) & |
869 | ~WM8350_BCLK_MSTR; | 863 | ~WM8350_BCLK_MSTR; |
870 | u16 dac_lrc = wm8350_codec_read(codec, WM8350_DAC_LR_RATE) & | 864 | u16 dac_lrc = snd_soc_read(codec, WM8350_DAC_LR_RATE) & |
871 | ~WM8350_DACLRC_ENA; | 865 | ~WM8350_DACLRC_ENA; |
872 | u16 adc_lrc = wm8350_codec_read(codec, WM8350_ADC_LR_RATE) & | 866 | u16 adc_lrc = snd_soc_read(codec, WM8350_ADC_LR_RATE) & |
873 | ~WM8350_ADCLRC_ENA; | 867 | ~WM8350_ADCLRC_ENA; |
874 | 868 | ||
875 | /* set master/slave audio interface */ | 869 | /* set master/slave audio interface */ |
@@ -922,42 +916,10 @@ static int wm8350_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt) | |||
922 | return -EINVAL; | 916 | return -EINVAL; |
923 | } | 917 | } |
924 | 918 | ||
925 | wm8350_codec_write(codec, WM8350_AI_FORMATING, iface); | 919 | snd_soc_write(codec, WM8350_AI_FORMATING, iface); |
926 | wm8350_codec_write(codec, WM8350_AI_DAC_CONTROL, master); | 920 | snd_soc_write(codec, WM8350_AI_DAC_CONTROL, master); |
927 | wm8350_codec_write(codec, WM8350_DAC_LR_RATE, dac_lrc); | 921 | snd_soc_write(codec, WM8350_DAC_LR_RATE, dac_lrc); |
928 | wm8350_codec_write(codec, WM8350_ADC_LR_RATE, adc_lrc); | 922 | snd_soc_write(codec, WM8350_ADC_LR_RATE, adc_lrc); |
929 | return 0; | ||
930 | } | ||
931 | |||
932 | static int wm8350_pcm_trigger(struct snd_pcm_substream *substream, | ||
933 | int cmd, struct snd_soc_dai *codec_dai) | ||
934 | { | ||
935 | struct snd_soc_codec *codec = codec_dai->codec; | ||
936 | int master = wm8350_codec_cache_read(codec, WM8350_AI_DAC_CONTROL) & | ||
937 | WM8350_BCLK_MSTR; | ||
938 | int enabled = 0; | ||
939 | |||
940 | /* Check that the DACs or ADCs are enabled since they are | ||
941 | * required for LRC in master mode. The DACs or ADCs need a | ||
942 | * valid audio path i.e. pin -> ADC or DAC -> pin before | ||
943 | * the LRC will be enabled in master mode. */ | ||
944 | if (!master || cmd != SNDRV_PCM_TRIGGER_START) | ||
945 | return 0; | ||
946 | |||
947 | if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) { | ||
948 | enabled = wm8350_codec_cache_read(codec, WM8350_POWER_MGMT_4) & | ||
949 | (WM8350_ADCR_ENA | WM8350_ADCL_ENA); | ||
950 | } else { | ||
951 | enabled = wm8350_codec_cache_read(codec, WM8350_POWER_MGMT_4) & | ||
952 | (WM8350_DACR_ENA | WM8350_DACL_ENA); | ||
953 | } | ||
954 | |||
955 | if (!enabled) { | ||
956 | dev_err(codec->dev, | ||
957 | "%s: invalid audio path - no clocks available\n", | ||
958 | __func__); | ||
959 | return -EINVAL; | ||
960 | } | ||
961 | return 0; | 923 | return 0; |
962 | } | 924 | } |
963 | 925 | ||
@@ -966,8 +928,9 @@ static int wm8350_pcm_hw_params(struct snd_pcm_substream *substream, | |||
966 | struct snd_soc_dai *codec_dai) | 928 | struct snd_soc_dai *codec_dai) |
967 | { | 929 | { |
968 | struct snd_soc_codec *codec = codec_dai->codec; | 930 | struct snd_soc_codec *codec = codec_dai->codec; |
969 | struct wm8350 *wm8350 = codec->control_data; | 931 | struct wm8350_data *wm8350_data = snd_soc_codec_get_drvdata(codec); |
970 | u16 iface = wm8350_codec_read(codec, WM8350_AI_FORMATING) & | 932 | struct wm8350 *wm8350 = wm8350_data->wm8350; |
933 | u16 iface = snd_soc_read(codec, WM8350_AI_FORMATING) & | ||
971 | ~WM8350_AIF_WL_MASK; | 934 | ~WM8350_AIF_WL_MASK; |
972 | 935 | ||
973 | /* bit size */ | 936 | /* bit size */ |
@@ -985,7 +948,7 @@ static int wm8350_pcm_hw_params(struct snd_pcm_substream *substream, | |||
985 | break; | 948 | break; |
986 | } | 949 | } |
987 | 950 | ||
988 | wm8350_codec_write(codec, WM8350_AI_FORMATING, iface); | 951 | snd_soc_write(codec, WM8350_AI_FORMATING, iface); |
989 | 952 | ||
990 | /* The sloping stopband filter is recommended for use with | 953 | /* The sloping stopband filter is recommended for use with |
991 | * lower sample rates to improve performance. | 954 | * lower sample rates to improve performance. |
@@ -1005,12 +968,15 @@ static int wm8350_pcm_hw_params(struct snd_pcm_substream *substream, | |||
1005 | static int wm8350_mute(struct snd_soc_dai *dai, int mute) | 968 | static int wm8350_mute(struct snd_soc_dai *dai, int mute) |
1006 | { | 969 | { |
1007 | struct snd_soc_codec *codec = dai->codec; | 970 | struct snd_soc_codec *codec = dai->codec; |
1008 | struct wm8350 *wm8350 = codec->control_data; | 971 | unsigned int val; |
1009 | 972 | ||
1010 | if (mute) | 973 | if (mute) |
1011 | wm8350_set_bits(wm8350, WM8350_DAC_MUTE, WM8350_DAC_MUTE_ENA); | 974 | val = WM8350_DAC_MUTE_ENA; |
1012 | else | 975 | else |
1013 | wm8350_clear_bits(wm8350, WM8350_DAC_MUTE, WM8350_DAC_MUTE_ENA); | 976 | val = 0; |
977 | |||
978 | snd_soc_update_bits(codec, WM8350_DAC_MUTE, WM8350_DAC_MUTE_ENA, val); | ||
979 | |||
1014 | return 0; | 980 | return 0; |
1015 | } | 981 | } |
1016 | 982 | ||
@@ -1079,8 +1045,8 @@ static int wm8350_set_fll(struct snd_soc_dai *codec_dai, | |||
1079 | unsigned int freq_out) | 1045 | unsigned int freq_out) |
1080 | { | 1046 | { |
1081 | struct snd_soc_codec *codec = codec_dai->codec; | 1047 | struct snd_soc_codec *codec = codec_dai->codec; |
1082 | struct wm8350 *wm8350 = codec->control_data; | ||
1083 | struct wm8350_data *priv = snd_soc_codec_get_drvdata(codec); | 1048 | struct wm8350_data *priv = snd_soc_codec_get_drvdata(codec); |
1049 | struct wm8350 *wm8350 = priv->wm8350; | ||
1084 | struct _fll_div fll_div; | 1050 | struct _fll_div fll_div; |
1085 | int ret = 0; | 1051 | int ret = 0; |
1086 | u16 fll_1, fll_4; | 1052 | u16 fll_1, fll_4; |
@@ -1104,17 +1070,17 @@ static int wm8350_set_fll(struct snd_soc_dai *codec_dai, | |||
1104 | fll_div.ratio); | 1070 | fll_div.ratio); |
1105 | 1071 | ||
1106 | /* set up N.K & dividers */ | 1072 | /* set up N.K & dividers */ |
1107 | fll_1 = wm8350_codec_read(codec, WM8350_FLL_CONTROL_1) & | 1073 | fll_1 = snd_soc_read(codec, WM8350_FLL_CONTROL_1) & |
1108 | ~(WM8350_FLL_OUTDIV_MASK | WM8350_FLL_RSP_RATE_MASK | 0xc000); | 1074 | ~(WM8350_FLL_OUTDIV_MASK | WM8350_FLL_RSP_RATE_MASK | 0xc000); |
1109 | wm8350_codec_write(codec, WM8350_FLL_CONTROL_1, | 1075 | snd_soc_write(codec, WM8350_FLL_CONTROL_1, |
1110 | fll_1 | (fll_div.div << 8) | 0x50); | 1076 | fll_1 | (fll_div.div << 8) | 0x50); |
1111 | wm8350_codec_write(codec, WM8350_FLL_CONTROL_2, | 1077 | snd_soc_write(codec, WM8350_FLL_CONTROL_2, |
1112 | (fll_div.ratio << 11) | (fll_div. | 1078 | (fll_div.ratio << 11) | (fll_div. |
1113 | n & WM8350_FLL_N_MASK)); | 1079 | n & WM8350_FLL_N_MASK)); |
1114 | wm8350_codec_write(codec, WM8350_FLL_CONTROL_3, fll_div.k); | 1080 | snd_soc_write(codec, WM8350_FLL_CONTROL_3, fll_div.k); |
1115 | fll_4 = wm8350_codec_read(codec, WM8350_FLL_CONTROL_4) & | 1081 | fll_4 = snd_soc_read(codec, WM8350_FLL_CONTROL_4) & |
1116 | ~(WM8350_FLL_FRAC | WM8350_FLL_SLOW_LOCK_REF); | 1082 | ~(WM8350_FLL_FRAC | WM8350_FLL_SLOW_LOCK_REF); |
1117 | wm8350_codec_write(codec, WM8350_FLL_CONTROL_4, | 1083 | snd_soc_write(codec, WM8350_FLL_CONTROL_4, |
1118 | fll_4 | (fll_div.k ? WM8350_FLL_FRAC : 0) | | 1084 | fll_4 | (fll_div.k ? WM8350_FLL_FRAC : 0) | |
1119 | (fll_div.ratio == 8 ? WM8350_FLL_SLOW_LOCK_REF : 0)); | 1085 | (fll_div.ratio == 8 ? WM8350_FLL_SLOW_LOCK_REF : 0)); |
1120 | 1086 | ||
@@ -1131,8 +1097,8 @@ static int wm8350_set_fll(struct snd_soc_dai *codec_dai, | |||
1131 | static int wm8350_set_bias_level(struct snd_soc_codec *codec, | 1097 | static int wm8350_set_bias_level(struct snd_soc_codec *codec, |
1132 | enum snd_soc_bias_level level) | 1098 | enum snd_soc_bias_level level) |
1133 | { | 1099 | { |
1134 | struct wm8350 *wm8350 = codec->control_data; | ||
1135 | struct wm8350_data *priv = snd_soc_codec_get_drvdata(codec); | 1100 | struct wm8350_data *priv = snd_soc_codec_get_drvdata(codec); |
1101 | struct wm8350 *wm8350 = priv->wm8350; | ||
1136 | struct wm8350_audio_platform_data *platform = | 1102 | struct wm8350_audio_platform_data *platform = |
1137 | wm8350->codec.platform_data; | 1103 | wm8350->codec.platform_data; |
1138 | u16 pm1; | 1104 | u16 pm1; |
@@ -1339,35 +1305,36 @@ static void wm8350_hpr_work(struct work_struct *work) | |||
1339 | wm8350_hp_work(priv, &priv->hpr, WM8350_JACK_R_LVL); | 1305 | wm8350_hp_work(priv, &priv->hpr, WM8350_JACK_R_LVL); |
1340 | } | 1306 | } |
1341 | 1307 | ||
1342 | static irqreturn_t wm8350_hp_jack_handler(int irq, void *data) | 1308 | static irqreturn_t wm8350_hpl_jack_handler(int irq, void *data) |
1343 | { | 1309 | { |
1344 | struct wm8350_data *priv = data; | 1310 | struct wm8350_data *priv = data; |
1345 | struct wm8350 *wm8350 = priv->wm8350; | 1311 | struct wm8350 *wm8350 = priv->wm8350; |
1346 | struct wm8350_jack_data *jack = NULL; | ||
1347 | 1312 | ||
1348 | switch (irq - wm8350->irq_base) { | ||
1349 | case WM8350_IRQ_CODEC_JCK_DET_L: | ||
1350 | #ifndef CONFIG_SND_SOC_WM8350_MODULE | 1313 | #ifndef CONFIG_SND_SOC_WM8350_MODULE |
1351 | trace_snd_soc_jack_irq("WM8350 HPL"); | 1314 | trace_snd_soc_jack_irq("WM8350 HPL"); |
1352 | #endif | 1315 | #endif |
1353 | jack = &priv->hpl; | ||
1354 | break; | ||
1355 | 1316 | ||
1356 | case WM8350_IRQ_CODEC_JCK_DET_R: | 1317 | if (device_may_wakeup(wm8350->dev)) |
1318 | pm_wakeup_event(wm8350->dev, 250); | ||
1319 | |||
1320 | schedule_delayed_work(&priv->hpl.work, 200); | ||
1321 | |||
1322 | return IRQ_HANDLED; | ||
1323 | } | ||
1324 | |||
1325 | static irqreturn_t wm8350_hpr_jack_handler(int irq, void *data) | ||
1326 | { | ||
1327 | struct wm8350_data *priv = data; | ||
1328 | struct wm8350 *wm8350 = priv->wm8350; | ||
1329 | |||
1357 | #ifndef CONFIG_SND_SOC_WM8350_MODULE | 1330 | #ifndef CONFIG_SND_SOC_WM8350_MODULE |
1358 | trace_snd_soc_jack_irq("WM8350 HPR"); | 1331 | trace_snd_soc_jack_irq("WM8350 HPR"); |
1359 | #endif | 1332 | #endif |
1360 | jack = &priv->hpr; | ||
1361 | break; | ||
1362 | |||
1363 | default: | ||
1364 | BUG(); | ||
1365 | } | ||
1366 | 1333 | ||
1367 | if (device_may_wakeup(wm8350->dev)) | 1334 | if (device_may_wakeup(wm8350->dev)) |
1368 | pm_wakeup_event(wm8350->dev, 250); | 1335 | pm_wakeup_event(wm8350->dev, 250); |
1369 | 1336 | ||
1370 | schedule_delayed_work(&jack->work, 200); | 1337 | schedule_delayed_work(&priv->hpr.work, 200); |
1371 | 1338 | ||
1372 | return IRQ_HANDLED; | 1339 | return IRQ_HANDLED; |
1373 | } | 1340 | } |
@@ -1387,7 +1354,7 @@ int wm8350_hp_jack_detect(struct snd_soc_codec *codec, enum wm8350_jack which, | |||
1387 | struct snd_soc_jack *jack, int report) | 1354 | struct snd_soc_jack *jack, int report) |
1388 | { | 1355 | { |
1389 | struct wm8350_data *priv = snd_soc_codec_get_drvdata(codec); | 1356 | struct wm8350_data *priv = snd_soc_codec_get_drvdata(codec); |
1390 | struct wm8350 *wm8350 = codec->control_data; | 1357 | struct wm8350 *wm8350 = priv->wm8350; |
1391 | int irq; | 1358 | int irq; |
1392 | int ena; | 1359 | int ena; |
1393 | 1360 | ||
@@ -1418,7 +1385,14 @@ int wm8350_hp_jack_detect(struct snd_soc_codec *codec, enum wm8350_jack which, | |||
1418 | } | 1385 | } |
1419 | 1386 | ||
1420 | /* Sync status */ | 1387 | /* Sync status */ |
1421 | wm8350_hp_jack_handler(irq + wm8350->irq_base, priv); | 1388 | switch (which) { |
1389 | case WM8350_JDL: | ||
1390 | wm8350_hpl_jack_handler(0, priv); | ||
1391 | break; | ||
1392 | case WM8350_JDR: | ||
1393 | wm8350_hpr_jack_handler(0, priv); | ||
1394 | break; | ||
1395 | } | ||
1422 | 1396 | ||
1423 | return 0; | 1397 | return 0; |
1424 | } | 1398 | } |
@@ -1463,7 +1437,7 @@ int wm8350_mic_jack_detect(struct snd_soc_codec *codec, | |||
1463 | int detect_report, int short_report) | 1437 | int detect_report, int short_report) |
1464 | { | 1438 | { |
1465 | struct wm8350_data *priv = snd_soc_codec_get_drvdata(codec); | 1439 | struct wm8350_data *priv = snd_soc_codec_get_drvdata(codec); |
1466 | struct wm8350 *wm8350 = codec->control_data; | 1440 | struct wm8350 *wm8350 = priv->wm8350; |
1467 | 1441 | ||
1468 | priv->mic.jack = jack; | 1442 | priv->mic.jack = jack; |
1469 | priv->mic.report = detect_report; | 1443 | priv->mic.report = detect_report; |
@@ -1491,7 +1465,6 @@ EXPORT_SYMBOL_GPL(wm8350_mic_jack_detect); | |||
1491 | static const struct snd_soc_dai_ops wm8350_dai_ops = { | 1465 | static const struct snd_soc_dai_ops wm8350_dai_ops = { |
1492 | .hw_params = wm8350_pcm_hw_params, | 1466 | .hw_params = wm8350_pcm_hw_params, |
1493 | .digital_mute = wm8350_mute, | 1467 | .digital_mute = wm8350_mute, |
1494 | .trigger = wm8350_pcm_trigger, | ||
1495 | .set_fmt = wm8350_set_dai_fmt, | 1468 | .set_fmt = wm8350_set_dai_fmt, |
1496 | .set_sysclk = wm8350_set_dai_sysclk, | 1469 | .set_sysclk = wm8350_set_dai_sysclk, |
1497 | .set_pll = wm8350_set_fll, | 1470 | .set_pll = wm8350_set_fll, |
@@ -1559,9 +1532,9 @@ static int wm8350_codec_probe(struct snd_soc_codec *codec) | |||
1559 | wm8350_set_bits(wm8350, WM8350_POWER_MGMT_5, WM8350_CODEC_ENA); | 1532 | wm8350_set_bits(wm8350, WM8350_POWER_MGMT_5, WM8350_CODEC_ENA); |
1560 | 1533 | ||
1561 | /* Enable robust clocking mode in ADC */ | 1534 | /* Enable robust clocking mode in ADC */ |
1562 | wm8350_codec_write(codec, WM8350_SECURITY, 0xa7); | 1535 | snd_soc_write(codec, WM8350_SECURITY, 0xa7); |
1563 | wm8350_codec_write(codec, 0xde, 0x13); | 1536 | snd_soc_write(codec, 0xde, 0x13); |
1564 | wm8350_codec_write(codec, WM8350_SECURITY, 0); | 1537 | snd_soc_write(codec, WM8350_SECURITY, 0); |
1565 | 1538 | ||
1566 | /* read OUT1 & OUT2 volumes */ | 1539 | /* read OUT1 & OUT2 volumes */ |
1567 | out1 = &priv->out1; | 1540 | out1 = &priv->out1; |
@@ -1601,10 +1574,10 @@ static int wm8350_codec_probe(struct snd_soc_codec *codec) | |||
1601 | WM8350_JDL_ENA | WM8350_JDR_ENA); | 1574 | WM8350_JDL_ENA | WM8350_JDR_ENA); |
1602 | 1575 | ||
1603 | wm8350_register_irq(wm8350, WM8350_IRQ_CODEC_JCK_DET_L, | 1576 | wm8350_register_irq(wm8350, WM8350_IRQ_CODEC_JCK_DET_L, |
1604 | wm8350_hp_jack_handler, 0, "Left jack detect", | 1577 | wm8350_hpl_jack_handler, 0, "Left jack detect", |
1605 | priv); | 1578 | priv); |
1606 | wm8350_register_irq(wm8350, WM8350_IRQ_CODEC_JCK_DET_R, | 1579 | wm8350_register_irq(wm8350, WM8350_IRQ_CODEC_JCK_DET_R, |
1607 | wm8350_hp_jack_handler, 0, "Right jack detect", | 1580 | wm8350_hpr_jack_handler, 0, "Right jack detect", |
1608 | priv); | 1581 | priv); |
1609 | wm8350_register_irq(wm8350, WM8350_IRQ_CODEC_MICSCD, | 1582 | wm8350_register_irq(wm8350, WM8350_IRQ_CODEC_MICSCD, |
1610 | wm8350_mic_handler, 0, "Microphone short", priv); | 1583 | wm8350_mic_handler, 0, "Microphone short", priv); |
diff --git a/sound/soc/codecs/wm8400.c b/sound/soc/codecs/wm8400.c index 898979d23010..5dc31ebcd0e7 100644 --- a/sound/soc/codecs/wm8400.c +++ b/sound/soc/codecs/wm8400.c | |||
@@ -138,8 +138,8 @@ static int wm8400_outpga_put_volsw_vu(struct snd_kcontrol *kcontrol, | |||
138 | return ret; | 138 | return ret; |
139 | 139 | ||
140 | /* now hit the volume update bits (always bit 8) */ | 140 | /* now hit the volume update bits (always bit 8) */ |
141 | val = wm8400_read(codec, reg); | 141 | val = snd_soc_read(codec, reg); |
142 | return wm8400_write(codec, reg, val | 0x0100); | 142 | return snd_soc_write(codec, reg, val | 0x0100); |
143 | } | 143 | } |
144 | 144 | ||
145 | #define WM8400_OUTPGA_SINGLE_R_TLV(xname, reg, shift, max, invert, tlv_array) \ | 145 | #define WM8400_OUTPGA_SINGLE_R_TLV(xname, reg, shift, max, invert, tlv_array) \ |
@@ -362,8 +362,8 @@ static int inmixer_event (struct snd_soc_dapm_widget *w, | |||
362 | { | 362 | { |
363 | u16 reg, fakepower; | 363 | u16 reg, fakepower; |
364 | 364 | ||
365 | reg = wm8400_read(w->codec, WM8400_POWER_MANAGEMENT_2); | 365 | reg = snd_soc_read(w->codec, WM8400_POWER_MANAGEMENT_2); |
366 | fakepower = wm8400_read(w->codec, WM8400_INTDRIVBITS); | 366 | fakepower = snd_soc_read(w->codec, WM8400_INTDRIVBITS); |
367 | 367 | ||
368 | if (fakepower & ((1 << WM8400_INMIXL_PWR) | | 368 | if (fakepower & ((1 << WM8400_INMIXL_PWR) | |
369 | (1 << WM8400_AINLMUX_PWR))) { | 369 | (1 << WM8400_AINLMUX_PWR))) { |
@@ -378,7 +378,7 @@ static int inmixer_event (struct snd_soc_dapm_widget *w, | |||
378 | } else { | 378 | } else { |
379 | reg &= ~WM8400_AINR_ENA; | 379 | reg &= ~WM8400_AINR_ENA; |
380 | } | 380 | } |
381 | wm8400_write(w->codec, WM8400_POWER_MANAGEMENT_2, reg); | 381 | snd_soc_write(w->codec, WM8400_POWER_MANAGEMENT_2, reg); |
382 | 382 | ||
383 | return 0; | 383 | return 0; |
384 | } | 384 | } |
@@ -394,7 +394,7 @@ static int outmixer_event (struct snd_soc_dapm_widget *w, | |||
394 | 394 | ||
395 | switch (reg_shift) { | 395 | switch (reg_shift) { |
396 | case WM8400_SPEAKER_MIXER | (WM8400_LDSPK << 8) : | 396 | case WM8400_SPEAKER_MIXER | (WM8400_LDSPK << 8) : |
397 | reg = wm8400_read(w->codec, WM8400_OUTPUT_MIXER1); | 397 | reg = snd_soc_read(w->codec, WM8400_OUTPUT_MIXER1); |
398 | if (reg & WM8400_LDLO) { | 398 | if (reg & WM8400_LDLO) { |
399 | printk(KERN_WARNING | 399 | printk(KERN_WARNING |
400 | "Cannot set as Output Mixer 1 LDLO Set\n"); | 400 | "Cannot set as Output Mixer 1 LDLO Set\n"); |
@@ -402,7 +402,7 @@ static int outmixer_event (struct snd_soc_dapm_widget *w, | |||
402 | } | 402 | } |
403 | break; | 403 | break; |
404 | case WM8400_SPEAKER_MIXER | (WM8400_RDSPK << 8): | 404 | case WM8400_SPEAKER_MIXER | (WM8400_RDSPK << 8): |
405 | reg = wm8400_read(w->codec, WM8400_OUTPUT_MIXER2); | 405 | reg = snd_soc_read(w->codec, WM8400_OUTPUT_MIXER2); |
406 | if (reg & WM8400_RDRO) { | 406 | if (reg & WM8400_RDRO) { |
407 | printk(KERN_WARNING | 407 | printk(KERN_WARNING |
408 | "Cannot set as Output Mixer 2 RDRO Set\n"); | 408 | "Cannot set as Output Mixer 2 RDRO Set\n"); |
@@ -410,7 +410,7 @@ static int outmixer_event (struct snd_soc_dapm_widget *w, | |||
410 | } | 410 | } |
411 | break; | 411 | break; |
412 | case WM8400_OUTPUT_MIXER1 | (WM8400_LDLO << 8): | 412 | case WM8400_OUTPUT_MIXER1 | (WM8400_LDLO << 8): |
413 | reg = wm8400_read(w->codec, WM8400_SPEAKER_MIXER); | 413 | reg = snd_soc_read(w->codec, WM8400_SPEAKER_MIXER); |
414 | if (reg & WM8400_LDSPK) { | 414 | if (reg & WM8400_LDSPK) { |
415 | printk(KERN_WARNING | 415 | printk(KERN_WARNING |
416 | "Cannot set as Speaker Mixer LDSPK Set\n"); | 416 | "Cannot set as Speaker Mixer LDSPK Set\n"); |
@@ -418,7 +418,7 @@ static int outmixer_event (struct snd_soc_dapm_widget *w, | |||
418 | } | 418 | } |
419 | break; | 419 | break; |
420 | case WM8400_OUTPUT_MIXER2 | (WM8400_RDRO << 8): | 420 | case WM8400_OUTPUT_MIXER2 | (WM8400_RDRO << 8): |
421 | reg = wm8400_read(w->codec, WM8400_SPEAKER_MIXER); | 421 | reg = snd_soc_read(w->codec, WM8400_SPEAKER_MIXER); |
422 | if (reg & WM8400_RDSPK) { | 422 | if (reg & WM8400_RDSPK) { |
423 | printk(KERN_WARNING | 423 | printk(KERN_WARNING |
424 | "Cannot set as Speaker Mixer RDSPK Set\n"); | 424 | "Cannot set as Speaker Mixer RDSPK Set\n"); |
@@ -1021,13 +1021,13 @@ static int wm8400_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id, | |||
1021 | wm8400->fll_in = freq_in; | 1021 | wm8400->fll_in = freq_in; |
1022 | 1022 | ||
1023 | /* We *must* disable the FLL before any changes */ | 1023 | /* We *must* disable the FLL before any changes */ |
1024 | reg = wm8400_read(codec, WM8400_POWER_MANAGEMENT_2); | 1024 | reg = snd_soc_read(codec, WM8400_POWER_MANAGEMENT_2); |
1025 | reg &= ~WM8400_FLL_ENA; | 1025 | reg &= ~WM8400_FLL_ENA; |
1026 | wm8400_write(codec, WM8400_POWER_MANAGEMENT_2, reg); | 1026 | snd_soc_write(codec, WM8400_POWER_MANAGEMENT_2, reg); |
1027 | 1027 | ||
1028 | reg = wm8400_read(codec, WM8400_FLL_CONTROL_1); | 1028 | reg = snd_soc_read(codec, WM8400_FLL_CONTROL_1); |
1029 | reg &= ~WM8400_FLL_OSC_ENA; | 1029 | reg &= ~WM8400_FLL_OSC_ENA; |
1030 | wm8400_write(codec, WM8400_FLL_CONTROL_1, reg); | 1030 | snd_soc_write(codec, WM8400_FLL_CONTROL_1, reg); |
1031 | 1031 | ||
1032 | if (!freq_out) | 1032 | if (!freq_out) |
1033 | return 0; | 1033 | return 0; |
@@ -1035,15 +1035,15 @@ static int wm8400_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id, | |||
1035 | reg &= ~(WM8400_FLL_REF_FREQ | WM8400_FLL_FRATIO_MASK); | 1035 | reg &= ~(WM8400_FLL_REF_FREQ | WM8400_FLL_FRATIO_MASK); |
1036 | reg |= WM8400_FLL_FRAC | factors.fratio; | 1036 | reg |= WM8400_FLL_FRAC | factors.fratio; |
1037 | reg |= factors.freq_ref << WM8400_FLL_REF_FREQ_SHIFT; | 1037 | reg |= factors.freq_ref << WM8400_FLL_REF_FREQ_SHIFT; |
1038 | wm8400_write(codec, WM8400_FLL_CONTROL_1, reg); | 1038 | snd_soc_write(codec, WM8400_FLL_CONTROL_1, reg); |
1039 | 1039 | ||
1040 | wm8400_write(codec, WM8400_FLL_CONTROL_2, factors.k); | 1040 | snd_soc_write(codec, WM8400_FLL_CONTROL_2, factors.k); |
1041 | wm8400_write(codec, WM8400_FLL_CONTROL_3, factors.n); | 1041 | snd_soc_write(codec, WM8400_FLL_CONTROL_3, factors.n); |
1042 | 1042 | ||
1043 | reg = wm8400_read(codec, WM8400_FLL_CONTROL_4); | 1043 | reg = snd_soc_read(codec, WM8400_FLL_CONTROL_4); |
1044 | reg &= ~WM8400_FLL_OUTDIV_MASK; | 1044 | reg &= ~WM8400_FLL_OUTDIV_MASK; |
1045 | reg |= factors.outdiv; | 1045 | reg |= factors.outdiv; |
1046 | wm8400_write(codec, WM8400_FLL_CONTROL_4, reg); | 1046 | snd_soc_write(codec, WM8400_FLL_CONTROL_4, reg); |
1047 | 1047 | ||
1048 | return 0; | 1048 | return 0; |
1049 | } | 1049 | } |
@@ -1057,8 +1057,8 @@ static int wm8400_set_dai_fmt(struct snd_soc_dai *codec_dai, | |||
1057 | struct snd_soc_codec *codec = codec_dai->codec; | 1057 | struct snd_soc_codec *codec = codec_dai->codec; |
1058 | u16 audio1, audio3; | 1058 | u16 audio1, audio3; |
1059 | 1059 | ||
1060 | audio1 = wm8400_read(codec, WM8400_AUDIO_INTERFACE_1); | 1060 | audio1 = snd_soc_read(codec, WM8400_AUDIO_INTERFACE_1); |
1061 | audio3 = wm8400_read(codec, WM8400_AUDIO_INTERFACE_3); | 1061 | audio3 = snd_soc_read(codec, WM8400_AUDIO_INTERFACE_3); |
1062 | 1062 | ||
1063 | /* set master/slave audio interface */ | 1063 | /* set master/slave audio interface */ |
1064 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { | 1064 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
@@ -1099,8 +1099,8 @@ static int wm8400_set_dai_fmt(struct snd_soc_dai *codec_dai, | |||
1099 | return -EINVAL; | 1099 | return -EINVAL; |
1100 | } | 1100 | } |
1101 | 1101 | ||
1102 | wm8400_write(codec, WM8400_AUDIO_INTERFACE_1, audio1); | 1102 | snd_soc_write(codec, WM8400_AUDIO_INTERFACE_1, audio1); |
1103 | wm8400_write(codec, WM8400_AUDIO_INTERFACE_3, audio3); | 1103 | snd_soc_write(codec, WM8400_AUDIO_INTERFACE_3, audio3); |
1104 | return 0; | 1104 | return 0; |
1105 | } | 1105 | } |
1106 | 1106 | ||
@@ -1112,24 +1112,24 @@ static int wm8400_set_dai_clkdiv(struct snd_soc_dai *codec_dai, | |||
1112 | 1112 | ||
1113 | switch (div_id) { | 1113 | switch (div_id) { |
1114 | case WM8400_MCLK_DIV: | 1114 | case WM8400_MCLK_DIV: |
1115 | reg = wm8400_read(codec, WM8400_CLOCKING_2) & | 1115 | reg = snd_soc_read(codec, WM8400_CLOCKING_2) & |
1116 | ~WM8400_MCLK_DIV_MASK; | 1116 | ~WM8400_MCLK_DIV_MASK; |
1117 | wm8400_write(codec, WM8400_CLOCKING_2, reg | div); | 1117 | snd_soc_write(codec, WM8400_CLOCKING_2, reg | div); |
1118 | break; | 1118 | break; |
1119 | case WM8400_DACCLK_DIV: | 1119 | case WM8400_DACCLK_DIV: |
1120 | reg = wm8400_read(codec, WM8400_CLOCKING_2) & | 1120 | reg = snd_soc_read(codec, WM8400_CLOCKING_2) & |
1121 | ~WM8400_DAC_CLKDIV_MASK; | 1121 | ~WM8400_DAC_CLKDIV_MASK; |
1122 | wm8400_write(codec, WM8400_CLOCKING_2, reg | div); | 1122 | snd_soc_write(codec, WM8400_CLOCKING_2, reg | div); |
1123 | break; | 1123 | break; |
1124 | case WM8400_ADCCLK_DIV: | 1124 | case WM8400_ADCCLK_DIV: |
1125 | reg = wm8400_read(codec, WM8400_CLOCKING_2) & | 1125 | reg = snd_soc_read(codec, WM8400_CLOCKING_2) & |
1126 | ~WM8400_ADC_CLKDIV_MASK; | 1126 | ~WM8400_ADC_CLKDIV_MASK; |
1127 | wm8400_write(codec, WM8400_CLOCKING_2, reg | div); | 1127 | snd_soc_write(codec, WM8400_CLOCKING_2, reg | div); |
1128 | break; | 1128 | break; |
1129 | case WM8400_BCLK_DIV: | 1129 | case WM8400_BCLK_DIV: |
1130 | reg = wm8400_read(codec, WM8400_CLOCKING_1) & | 1130 | reg = snd_soc_read(codec, WM8400_CLOCKING_1) & |
1131 | ~WM8400_BCLK_DIV_MASK; | 1131 | ~WM8400_BCLK_DIV_MASK; |
1132 | wm8400_write(codec, WM8400_CLOCKING_1, reg | div); | 1132 | snd_soc_write(codec, WM8400_CLOCKING_1, reg | div); |
1133 | break; | 1133 | break; |
1134 | default: | 1134 | default: |
1135 | return -EINVAL; | 1135 | return -EINVAL; |
@@ -1145,9 +1145,8 @@ static int wm8400_hw_params(struct snd_pcm_substream *substream, | |||
1145 | struct snd_pcm_hw_params *params, | 1145 | struct snd_pcm_hw_params *params, |
1146 | struct snd_soc_dai *dai) | 1146 | struct snd_soc_dai *dai) |
1147 | { | 1147 | { |
1148 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 1148 | struct snd_soc_codec *codec = dai->codec; |
1149 | struct snd_soc_codec *codec = rtd->codec; | 1149 | u16 audio1 = snd_soc_read(codec, WM8400_AUDIO_INTERFACE_1); |
1150 | u16 audio1 = wm8400_read(codec, WM8400_AUDIO_INTERFACE_1); | ||
1151 | 1150 | ||
1152 | audio1 &= ~WM8400_AIF_WL_MASK; | 1151 | audio1 &= ~WM8400_AIF_WL_MASK; |
1153 | /* bit size */ | 1152 | /* bit size */ |
@@ -1165,19 +1164,19 @@ static int wm8400_hw_params(struct snd_pcm_substream *substream, | |||
1165 | break; | 1164 | break; |
1166 | } | 1165 | } |
1167 | 1166 | ||
1168 | wm8400_write(codec, WM8400_AUDIO_INTERFACE_1, audio1); | 1167 | snd_soc_write(codec, WM8400_AUDIO_INTERFACE_1, audio1); |
1169 | return 0; | 1168 | return 0; |
1170 | } | 1169 | } |
1171 | 1170 | ||
1172 | static int wm8400_mute(struct snd_soc_dai *dai, int mute) | 1171 | static int wm8400_mute(struct snd_soc_dai *dai, int mute) |
1173 | { | 1172 | { |
1174 | struct snd_soc_codec *codec = dai->codec; | 1173 | struct snd_soc_codec *codec = dai->codec; |
1175 | u16 val = wm8400_read(codec, WM8400_DAC_CTRL) & ~WM8400_DAC_MUTE; | 1174 | u16 val = snd_soc_read(codec, WM8400_DAC_CTRL) & ~WM8400_DAC_MUTE; |
1176 | 1175 | ||
1177 | if (mute) | 1176 | if (mute) |
1178 | wm8400_write(codec, WM8400_DAC_CTRL, val | WM8400_DAC_MUTE); | 1177 | snd_soc_write(codec, WM8400_DAC_CTRL, val | WM8400_DAC_MUTE); |
1179 | else | 1178 | else |
1180 | wm8400_write(codec, WM8400_DAC_CTRL, val); | 1179 | snd_soc_write(codec, WM8400_DAC_CTRL, val); |
1181 | 1180 | ||
1182 | return 0; | 1181 | return 0; |
1183 | } | 1182 | } |
@@ -1196,9 +1195,9 @@ static int wm8400_set_bias_level(struct snd_soc_codec *codec, | |||
1196 | 1195 | ||
1197 | case SND_SOC_BIAS_PREPARE: | 1196 | case SND_SOC_BIAS_PREPARE: |
1198 | /* VMID=2*50k */ | 1197 | /* VMID=2*50k */ |
1199 | val = wm8400_read(codec, WM8400_POWER_MANAGEMENT_1) & | 1198 | val = snd_soc_read(codec, WM8400_POWER_MANAGEMENT_1) & |
1200 | ~WM8400_VMID_MODE_MASK; | 1199 | ~WM8400_VMID_MODE_MASK; |
1201 | wm8400_write(codec, WM8400_POWER_MANAGEMENT_1, val | 0x2); | 1200 | snd_soc_write(codec, WM8400_POWER_MANAGEMENT_1, val | 0x2); |
1202 | break; | 1201 | break; |
1203 | 1202 | ||
1204 | case SND_SOC_BIAS_STANDBY: | 1203 | case SND_SOC_BIAS_STANDBY: |
@@ -1212,74 +1211,74 @@ static int wm8400_set_bias_level(struct snd_soc_codec *codec, | |||
1212 | return ret; | 1211 | return ret; |
1213 | } | 1212 | } |
1214 | 1213 | ||
1215 | wm8400_write(codec, WM8400_POWER_MANAGEMENT_1, | 1214 | snd_soc_write(codec, WM8400_POWER_MANAGEMENT_1, |
1216 | WM8400_CODEC_ENA | WM8400_SYSCLK_ENA); | 1215 | WM8400_CODEC_ENA | WM8400_SYSCLK_ENA); |
1217 | 1216 | ||
1218 | /* Enable POBCTRL, SOFT_ST, VMIDTOG and BUFDCOPEN */ | 1217 | /* Enable POBCTRL, SOFT_ST, VMIDTOG and BUFDCOPEN */ |
1219 | wm8400_write(codec, WM8400_ANTIPOP2, WM8400_SOFTST | | 1218 | snd_soc_write(codec, WM8400_ANTIPOP2, WM8400_SOFTST | |
1220 | WM8400_BUFDCOPEN | WM8400_POBCTRL); | 1219 | WM8400_BUFDCOPEN | WM8400_POBCTRL); |
1221 | 1220 | ||
1222 | msleep(50); | 1221 | msleep(50); |
1223 | 1222 | ||
1224 | /* Enable VREF & VMID at 2x50k */ | 1223 | /* Enable VREF & VMID at 2x50k */ |
1225 | val = wm8400_read(codec, WM8400_POWER_MANAGEMENT_1); | 1224 | val = snd_soc_read(codec, WM8400_POWER_MANAGEMENT_1); |
1226 | val |= 0x2 | WM8400_VREF_ENA; | 1225 | val |= 0x2 | WM8400_VREF_ENA; |
1227 | wm8400_write(codec, WM8400_POWER_MANAGEMENT_1, val); | 1226 | snd_soc_write(codec, WM8400_POWER_MANAGEMENT_1, val); |
1228 | 1227 | ||
1229 | /* Enable BUFIOEN */ | 1228 | /* Enable BUFIOEN */ |
1230 | wm8400_write(codec, WM8400_ANTIPOP2, WM8400_SOFTST | | 1229 | snd_soc_write(codec, WM8400_ANTIPOP2, WM8400_SOFTST | |
1231 | WM8400_BUFDCOPEN | WM8400_POBCTRL | | 1230 | WM8400_BUFDCOPEN | WM8400_POBCTRL | |
1232 | WM8400_BUFIOEN); | 1231 | WM8400_BUFIOEN); |
1233 | 1232 | ||
1234 | /* disable POBCTRL, SOFT_ST and BUFDCOPEN */ | 1233 | /* disable POBCTRL, SOFT_ST and BUFDCOPEN */ |
1235 | wm8400_write(codec, WM8400_ANTIPOP2, WM8400_BUFIOEN); | 1234 | snd_soc_write(codec, WM8400_ANTIPOP2, WM8400_BUFIOEN); |
1236 | } | 1235 | } |
1237 | 1236 | ||
1238 | /* VMID=2*300k */ | 1237 | /* VMID=2*300k */ |
1239 | val = wm8400_read(codec, WM8400_POWER_MANAGEMENT_1) & | 1238 | val = snd_soc_read(codec, WM8400_POWER_MANAGEMENT_1) & |
1240 | ~WM8400_VMID_MODE_MASK; | 1239 | ~WM8400_VMID_MODE_MASK; |
1241 | wm8400_write(codec, WM8400_POWER_MANAGEMENT_1, val | 0x4); | 1240 | snd_soc_write(codec, WM8400_POWER_MANAGEMENT_1, val | 0x4); |
1242 | break; | 1241 | break; |
1243 | 1242 | ||
1244 | case SND_SOC_BIAS_OFF: | 1243 | case SND_SOC_BIAS_OFF: |
1245 | /* Enable POBCTRL and SOFT_ST */ | 1244 | /* Enable POBCTRL and SOFT_ST */ |
1246 | wm8400_write(codec, WM8400_ANTIPOP2, WM8400_SOFTST | | 1245 | snd_soc_write(codec, WM8400_ANTIPOP2, WM8400_SOFTST | |
1247 | WM8400_POBCTRL | WM8400_BUFIOEN); | 1246 | WM8400_POBCTRL | WM8400_BUFIOEN); |
1248 | 1247 | ||
1249 | /* Enable POBCTRL, SOFT_ST and BUFDCOPEN */ | 1248 | /* Enable POBCTRL, SOFT_ST and BUFDCOPEN */ |
1250 | wm8400_write(codec, WM8400_ANTIPOP2, WM8400_SOFTST | | 1249 | snd_soc_write(codec, WM8400_ANTIPOP2, WM8400_SOFTST | |
1251 | WM8400_BUFDCOPEN | WM8400_POBCTRL | | 1250 | WM8400_BUFDCOPEN | WM8400_POBCTRL | |
1252 | WM8400_BUFIOEN); | 1251 | WM8400_BUFIOEN); |
1253 | 1252 | ||
1254 | /* mute DAC */ | 1253 | /* mute DAC */ |
1255 | val = wm8400_read(codec, WM8400_DAC_CTRL); | 1254 | val = snd_soc_read(codec, WM8400_DAC_CTRL); |
1256 | wm8400_write(codec, WM8400_DAC_CTRL, val | WM8400_DAC_MUTE); | 1255 | snd_soc_write(codec, WM8400_DAC_CTRL, val | WM8400_DAC_MUTE); |
1257 | 1256 | ||
1258 | /* Enable any disabled outputs */ | 1257 | /* Enable any disabled outputs */ |
1259 | val = wm8400_read(codec, WM8400_POWER_MANAGEMENT_1); | 1258 | val = snd_soc_read(codec, WM8400_POWER_MANAGEMENT_1); |
1260 | val |= WM8400_SPK_ENA | WM8400_OUT3_ENA | | 1259 | val |= WM8400_SPK_ENA | WM8400_OUT3_ENA | |
1261 | WM8400_OUT4_ENA | WM8400_LOUT_ENA | | 1260 | WM8400_OUT4_ENA | WM8400_LOUT_ENA | |
1262 | WM8400_ROUT_ENA; | 1261 | WM8400_ROUT_ENA; |
1263 | wm8400_write(codec, WM8400_POWER_MANAGEMENT_1, val); | 1262 | snd_soc_write(codec, WM8400_POWER_MANAGEMENT_1, val); |
1264 | 1263 | ||
1265 | /* Disable VMID */ | 1264 | /* Disable VMID */ |
1266 | val &= ~WM8400_VMID_MODE_MASK; | 1265 | val &= ~WM8400_VMID_MODE_MASK; |
1267 | wm8400_write(codec, WM8400_POWER_MANAGEMENT_1, val); | 1266 | snd_soc_write(codec, WM8400_POWER_MANAGEMENT_1, val); |
1268 | 1267 | ||
1269 | msleep(300); | 1268 | msleep(300); |
1270 | 1269 | ||
1271 | /* Enable all output discharge bits */ | 1270 | /* Enable all output discharge bits */ |
1272 | wm8400_write(codec, WM8400_ANTIPOP1, WM8400_DIS_LLINE | | 1271 | snd_soc_write(codec, WM8400_ANTIPOP1, WM8400_DIS_LLINE | |
1273 | WM8400_DIS_RLINE | WM8400_DIS_OUT3 | | 1272 | WM8400_DIS_RLINE | WM8400_DIS_OUT3 | |
1274 | WM8400_DIS_OUT4 | WM8400_DIS_LOUT | | 1273 | WM8400_DIS_OUT4 | WM8400_DIS_LOUT | |
1275 | WM8400_DIS_ROUT); | 1274 | WM8400_DIS_ROUT); |
1276 | 1275 | ||
1277 | /* Disable VREF */ | 1276 | /* Disable VREF */ |
1278 | val &= ~WM8400_VREF_ENA; | 1277 | val &= ~WM8400_VREF_ENA; |
1279 | wm8400_write(codec, WM8400_POWER_MANAGEMENT_1, val); | 1278 | snd_soc_write(codec, WM8400_POWER_MANAGEMENT_1, val); |
1280 | 1279 | ||
1281 | /* disable POBCTRL, SOFT_ST and BUFDCOPEN */ | 1280 | /* disable POBCTRL, SOFT_ST and BUFDCOPEN */ |
1282 | wm8400_write(codec, WM8400_ANTIPOP2, 0x0); | 1281 | snd_soc_write(codec, WM8400_ANTIPOP2, 0x0); |
1283 | 1282 | ||
1284 | ret = regulator_bulk_disable(ARRAY_SIZE(power), | 1283 | ret = regulator_bulk_disable(ARRAY_SIZE(power), |
1285 | &power[0]); | 1284 | &power[0]); |
@@ -1385,19 +1384,19 @@ static int wm8400_codec_probe(struct snd_soc_codec *codec) | |||
1385 | 1384 | ||
1386 | wm8400_codec_reset(codec); | 1385 | wm8400_codec_reset(codec); |
1387 | 1386 | ||
1388 | reg = wm8400_read(codec, WM8400_POWER_MANAGEMENT_1); | 1387 | reg = snd_soc_read(codec, WM8400_POWER_MANAGEMENT_1); |
1389 | wm8400_write(codec, WM8400_POWER_MANAGEMENT_1, reg | WM8400_CODEC_ENA); | 1388 | snd_soc_write(codec, WM8400_POWER_MANAGEMENT_1, reg | WM8400_CODEC_ENA); |
1390 | 1389 | ||
1391 | /* Latch volume update bits */ | 1390 | /* Latch volume update bits */ |
1392 | reg = wm8400_read(codec, WM8400_LEFT_LINE_INPUT_1_2_VOLUME); | 1391 | reg = snd_soc_read(codec, WM8400_LEFT_LINE_INPUT_1_2_VOLUME); |
1393 | wm8400_write(codec, WM8400_LEFT_LINE_INPUT_1_2_VOLUME, | 1392 | snd_soc_write(codec, WM8400_LEFT_LINE_INPUT_1_2_VOLUME, |
1394 | reg & WM8400_IPVU); | 1393 | reg & WM8400_IPVU); |
1395 | reg = wm8400_read(codec, WM8400_RIGHT_LINE_INPUT_1_2_VOLUME); | 1394 | reg = snd_soc_read(codec, WM8400_RIGHT_LINE_INPUT_1_2_VOLUME); |
1396 | wm8400_write(codec, WM8400_RIGHT_LINE_INPUT_1_2_VOLUME, | 1395 | snd_soc_write(codec, WM8400_RIGHT_LINE_INPUT_1_2_VOLUME, |
1397 | reg & WM8400_IPVU); | 1396 | reg & WM8400_IPVU); |
1398 | 1397 | ||
1399 | wm8400_write(codec, WM8400_LEFT_OUTPUT_VOLUME, 0x50 | (1<<8)); | 1398 | snd_soc_write(codec, WM8400_LEFT_OUTPUT_VOLUME, 0x50 | (1<<8)); |
1400 | wm8400_write(codec, WM8400_RIGHT_OUTPUT_VOLUME, 0x50 | (1<<8)); | 1399 | snd_soc_write(codec, WM8400_RIGHT_OUTPUT_VOLUME, 0x50 | (1<<8)); |
1401 | 1400 | ||
1402 | if (!schedule_work(&priv->work)) { | 1401 | if (!schedule_work(&priv->work)) { |
1403 | ret = -EINVAL; | 1402 | ret = -EINVAL; |
@@ -1414,8 +1413,8 @@ static int wm8400_codec_remove(struct snd_soc_codec *codec) | |||
1414 | { | 1413 | { |
1415 | u16 reg; | 1414 | u16 reg; |
1416 | 1415 | ||
1417 | reg = wm8400_read(codec, WM8400_POWER_MANAGEMENT_1); | 1416 | reg = snd_soc_read(codec, WM8400_POWER_MANAGEMENT_1); |
1418 | wm8400_write(codec, WM8400_POWER_MANAGEMENT_1, | 1417 | snd_soc_write(codec, WM8400_POWER_MANAGEMENT_1, |
1419 | reg & (~WM8400_CODEC_ENA)); | 1418 | reg & (~WM8400_CODEC_ENA)); |
1420 | 1419 | ||
1421 | regulator_bulk_free(ARRAY_SIZE(power), power); | 1420 | regulator_bulk_free(ARRAY_SIZE(power), power); |
@@ -1428,7 +1427,7 @@ static struct snd_soc_codec_driver soc_codec_dev_wm8400 = { | |||
1428 | .remove = wm8400_codec_remove, | 1427 | .remove = wm8400_codec_remove, |
1429 | .suspend = wm8400_suspend, | 1428 | .suspend = wm8400_suspend, |
1430 | .resume = wm8400_resume, | 1429 | .resume = wm8400_resume, |
1431 | .read = wm8400_read, | 1430 | .read = snd_soc_read, |
1432 | .write = wm8400_write, | 1431 | .write = wm8400_write, |
1433 | .set_bias_level = wm8400_set_bias_level, | 1432 | .set_bias_level = wm8400_set_bias_level, |
1434 | 1433 | ||
diff --git a/sound/soc/codecs/wm8510.c b/sound/soc/codecs/wm8510.c index 9166126bd312..56a049555e2c 100644 --- a/sound/soc/codecs/wm8510.c +++ b/sound/soc/codecs/wm8510.c | |||
@@ -392,8 +392,7 @@ static int wm8510_pcm_hw_params(struct snd_pcm_substream *substream, | |||
392 | struct snd_pcm_hw_params *params, | 392 | struct snd_pcm_hw_params *params, |
393 | struct snd_soc_dai *dai) | 393 | struct snd_soc_dai *dai) |
394 | { | 394 | { |
395 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 395 | struct snd_soc_codec *codec = dai->codec; |
396 | struct snd_soc_codec *codec = rtd->codec; | ||
397 | u16 iface = snd_soc_read(codec, WM8510_IFACE) & 0x19f; | 396 | u16 iface = snd_soc_read(codec, WM8510_IFACE) & 0x19f; |
398 | u16 adn = snd_soc_read(codec, WM8510_ADD) & 0x1f1; | 397 | u16 adn = snd_soc_read(codec, WM8510_ADD) & 0x1f1; |
399 | 398 | ||
diff --git a/sound/soc/codecs/wm8523.c b/sound/soc/codecs/wm8523.c index 7fea2c3bf7e7..1c3ffb290cdc 100644 --- a/sound/soc/codecs/wm8523.c +++ b/sound/soc/codecs/wm8523.c | |||
@@ -145,8 +145,7 @@ static int wm8523_hw_params(struct snd_pcm_substream *substream, | |||
145 | struct snd_pcm_hw_params *params, | 145 | struct snd_pcm_hw_params *params, |
146 | struct snd_soc_dai *dai) | 146 | struct snd_soc_dai *dai) |
147 | { | 147 | { |
148 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 148 | struct snd_soc_codec *codec = dai->codec; |
149 | struct snd_soc_codec *codec = rtd->codec; | ||
150 | struct wm8523_priv *wm8523 = snd_soc_codec_get_drvdata(codec); | 149 | struct wm8523_priv *wm8523 = snd_soc_codec_get_drvdata(codec); |
151 | int i; | 150 | int i; |
152 | u16 aifctrl1 = snd_soc_read(codec, WM8523_AIF_CTRL1); | 151 | u16 aifctrl1 = snd_soc_read(codec, WM8523_AIF_CTRL1); |
diff --git a/sound/soc/codecs/wm8728.c b/sound/soc/codecs/wm8728.c index fc3d59e49084..1467f97dce21 100644 --- a/sound/soc/codecs/wm8728.c +++ b/sound/soc/codecs/wm8728.c | |||
@@ -88,8 +88,7 @@ static int wm8728_hw_params(struct snd_pcm_substream *substream, | |||
88 | struct snd_pcm_hw_params *params, | 88 | struct snd_pcm_hw_params *params, |
89 | struct snd_soc_dai *dai) | 89 | struct snd_soc_dai *dai) |
90 | { | 90 | { |
91 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 91 | struct snd_soc_codec *codec = dai->codec; |
92 | struct snd_soc_codec *codec = rtd->codec; | ||
93 | u16 dac = snd_soc_read(codec, WM8728_DACCTL); | 92 | u16 dac = snd_soc_read(codec, WM8728_DACCTL); |
94 | 93 | ||
95 | dac &= ~0x18; | 94 | dac &= ~0x18; |
diff --git a/sound/soc/codecs/wm8731.c b/sound/soc/codecs/wm8731.c index a32caa72bd7d..9d1b9b0271f1 100644 --- a/sound/soc/codecs/wm8731.c +++ b/sound/soc/codecs/wm8731.c | |||
@@ -635,16 +635,17 @@ static int __devinit wm8731_spi_probe(struct spi_device *spi) | |||
635 | struct wm8731_priv *wm8731; | 635 | struct wm8731_priv *wm8731; |
636 | int ret; | 636 | int ret; |
637 | 637 | ||
638 | wm8731 = kzalloc(sizeof(struct wm8731_priv), GFP_KERNEL); | 638 | wm8731 = devm_kzalloc(&spi->dev, sizeof(struct wm8731_priv), |
639 | GFP_KERNEL); | ||
639 | if (wm8731 == NULL) | 640 | if (wm8731 == NULL) |
640 | return -ENOMEM; | 641 | return -ENOMEM; |
641 | 642 | ||
642 | wm8731->regmap = regmap_init_spi(spi, &wm8731_regmap); | 643 | wm8731->regmap = devm_regmap_init_spi(spi, &wm8731_regmap); |
643 | if (IS_ERR(wm8731->regmap)) { | 644 | if (IS_ERR(wm8731->regmap)) { |
644 | ret = PTR_ERR(wm8731->regmap); | 645 | ret = PTR_ERR(wm8731->regmap); |
645 | dev_err(&spi->dev, "Failed to allocate register map: %d\n", | 646 | dev_err(&spi->dev, "Failed to allocate register map: %d\n", |
646 | ret); | 647 | ret); |
647 | goto err; | 648 | return ret; |
648 | } | 649 | } |
649 | 650 | ||
650 | spi_set_drvdata(spi, wm8731); | 651 | spi_set_drvdata(spi, wm8731); |
@@ -653,25 +654,15 @@ static int __devinit wm8731_spi_probe(struct spi_device *spi) | |||
653 | &soc_codec_dev_wm8731, &wm8731_dai, 1); | 654 | &soc_codec_dev_wm8731, &wm8731_dai, 1); |
654 | if (ret != 0) { | 655 | if (ret != 0) { |
655 | dev_err(&spi->dev, "Failed to register CODEC: %d\n", ret); | 656 | dev_err(&spi->dev, "Failed to register CODEC: %d\n", ret); |
656 | goto err_regmap; | 657 | return ret; |
657 | } | 658 | } |
658 | 659 | ||
659 | return 0; | 660 | return 0; |
660 | |||
661 | err_regmap: | ||
662 | regmap_exit(wm8731->regmap); | ||
663 | err: | ||
664 | kfree(wm8731); | ||
665 | return ret; | ||
666 | } | 661 | } |
667 | 662 | ||
668 | static int __devexit wm8731_spi_remove(struct spi_device *spi) | 663 | static int __devexit wm8731_spi_remove(struct spi_device *spi) |
669 | { | 664 | { |
670 | struct wm8731_priv *wm8731 = spi_get_drvdata(spi); | ||
671 | |||
672 | snd_soc_unregister_codec(&spi->dev); | 665 | snd_soc_unregister_codec(&spi->dev); |
673 | regmap_exit(wm8731->regmap); | ||
674 | kfree(wm8731); | ||
675 | return 0; | 666 | return 0; |
676 | } | 667 | } |
677 | 668 | ||
@@ -693,16 +684,17 @@ static __devinit int wm8731_i2c_probe(struct i2c_client *i2c, | |||
693 | struct wm8731_priv *wm8731; | 684 | struct wm8731_priv *wm8731; |
694 | int ret; | 685 | int ret; |
695 | 686 | ||
696 | wm8731 = kzalloc(sizeof(struct wm8731_priv), GFP_KERNEL); | 687 | wm8731 = devm_kzalloc(&i2c->dev, sizeof(struct wm8731_priv), |
688 | GFP_KERNEL); | ||
697 | if (wm8731 == NULL) | 689 | if (wm8731 == NULL) |
698 | return -ENOMEM; | 690 | return -ENOMEM; |
699 | 691 | ||
700 | wm8731->regmap = regmap_init_i2c(i2c, &wm8731_regmap); | 692 | wm8731->regmap = devm_regmap_init_i2c(i2c, &wm8731_regmap); |
701 | if (IS_ERR(wm8731->regmap)) { | 693 | if (IS_ERR(wm8731->regmap)) { |
702 | ret = PTR_ERR(wm8731->regmap); | 694 | ret = PTR_ERR(wm8731->regmap); |
703 | dev_err(&i2c->dev, "Failed to allocate register map: %d\n", | 695 | dev_err(&i2c->dev, "Failed to allocate register map: %d\n", |
704 | ret); | 696 | ret); |
705 | goto err; | 697 | return ret; |
706 | } | 698 | } |
707 | 699 | ||
708 | i2c_set_clientdata(i2c, wm8731); | 700 | i2c_set_clientdata(i2c, wm8731); |
@@ -711,24 +703,15 @@ static __devinit int wm8731_i2c_probe(struct i2c_client *i2c, | |||
711 | &soc_codec_dev_wm8731, &wm8731_dai, 1); | 703 | &soc_codec_dev_wm8731, &wm8731_dai, 1); |
712 | if (ret != 0) { | 704 | if (ret != 0) { |
713 | dev_err(&i2c->dev, "Failed to register CODEC: %d\n", ret); | 705 | dev_err(&i2c->dev, "Failed to register CODEC: %d\n", ret); |
714 | goto err_regmap; | 706 | return ret; |
715 | } | 707 | } |
716 | 708 | ||
717 | return 0; | 709 | return 0; |
718 | |||
719 | err_regmap: | ||
720 | regmap_exit(wm8731->regmap); | ||
721 | err: | ||
722 | kfree(wm8731); | ||
723 | return ret; | ||
724 | } | 710 | } |
725 | 711 | ||
726 | static __devexit int wm8731_i2c_remove(struct i2c_client *client) | 712 | static __devexit int wm8731_i2c_remove(struct i2c_client *client) |
727 | { | 713 | { |
728 | struct wm8731_priv *wm8731 = i2c_get_clientdata(client); | ||
729 | snd_soc_unregister_codec(&client->dev); | 714 | snd_soc_unregister_codec(&client->dev); |
730 | regmap_exit(wm8731->regmap); | ||
731 | kfree(wm8731); | ||
732 | return 0; | 715 | return 0; |
733 | } | 716 | } |
734 | 717 | ||
diff --git a/sound/soc/codecs/wm8737.c b/sound/soc/codecs/wm8737.c index 4fe9d191e277..d0520124616d 100644 --- a/sound/soc/codecs/wm8737.c +++ b/sound/soc/codecs/wm8737.c | |||
@@ -329,8 +329,7 @@ static int wm8737_hw_params(struct snd_pcm_substream *substream, | |||
329 | struct snd_pcm_hw_params *params, | 329 | struct snd_pcm_hw_params *params, |
330 | struct snd_soc_dai *dai) | 330 | struct snd_soc_dai *dai) |
331 | { | 331 | { |
332 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 332 | struct snd_soc_codec *codec = dai->codec; |
333 | struct snd_soc_codec *codec = rtd->codec; | ||
334 | struct wm8737_priv *wm8737 = snd_soc_codec_get_drvdata(codec); | 333 | struct wm8737_priv *wm8737 = snd_soc_codec_get_drvdata(codec); |
335 | int i; | 334 | int i; |
336 | u16 clocking = 0; | 335 | u16 clocking = 0; |
diff --git a/sound/soc/codecs/wm8741.c b/sound/soc/codecs/wm8741.c index 3941f50bf187..6e849cb04243 100644 --- a/sound/soc/codecs/wm8741.c +++ b/sound/soc/codecs/wm8741.c | |||
@@ -203,8 +203,7 @@ static int wm8741_hw_params(struct snd_pcm_substream *substream, | |||
203 | struct snd_pcm_hw_params *params, | 203 | struct snd_pcm_hw_params *params, |
204 | struct snd_soc_dai *dai) | 204 | struct snd_soc_dai *dai) |
205 | { | 205 | { |
206 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 206 | struct snd_soc_codec *codec = dai->codec; |
207 | struct snd_soc_codec *codec = rtd->codec; | ||
208 | struct wm8741_priv *wm8741 = snd_soc_codec_get_drvdata(codec); | 207 | struct wm8741_priv *wm8741 = snd_soc_codec_get_drvdata(codec); |
209 | u16 iface = snd_soc_read(codec, WM8741_FORMAT_CONTROL) & 0x1FC; | 208 | u16 iface = snd_soc_read(codec, WM8741_FORMAT_CONTROL) & 0x1FC; |
210 | int i; | 209 | int i; |
diff --git a/sound/soc/codecs/wm8750.c b/sound/soc/codecs/wm8750.c index e4c50ce7d9c0..89151ca5e776 100644 --- a/sound/soc/codecs/wm8750.c +++ b/sound/soc/codecs/wm8750.c | |||
@@ -547,8 +547,7 @@ static int wm8750_pcm_hw_params(struct snd_pcm_substream *substream, | |||
547 | struct snd_pcm_hw_params *params, | 547 | struct snd_pcm_hw_params *params, |
548 | struct snd_soc_dai *dai) | 548 | struct snd_soc_dai *dai) |
549 | { | 549 | { |
550 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 550 | struct snd_soc_codec *codec = dai->codec; |
551 | struct snd_soc_codec *codec = rtd->codec; | ||
552 | struct wm8750_priv *wm8750 = snd_soc_codec_get_drvdata(codec); | 551 | struct wm8750_priv *wm8750 = snd_soc_codec_get_drvdata(codec); |
553 | u16 iface = snd_soc_read(codec, WM8750_IFACE) & 0x1f3; | 552 | u16 iface = snd_soc_read(codec, WM8750_IFACE) & 0x1f3; |
554 | u16 srate = snd_soc_read(codec, WM8750_SRATE) & 0x1c0; | 553 | u16 srate = snd_soc_read(codec, WM8750_SRATE) & 0x1c0; |
diff --git a/sound/soc/codecs/wm8753.c b/sound/soc/codecs/wm8753.c index e27e7b62b365..a26482cd7654 100644 --- a/sound/soc/codecs/wm8753.c +++ b/sound/soc/codecs/wm8753.c | |||
@@ -931,8 +931,7 @@ static int wm8753_pcm_hw_params(struct snd_pcm_substream *substream, | |||
931 | struct snd_pcm_hw_params *params, | 931 | struct snd_pcm_hw_params *params, |
932 | struct snd_soc_dai *dai) | 932 | struct snd_soc_dai *dai) |
933 | { | 933 | { |
934 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 934 | struct snd_soc_codec *codec = dai->codec; |
935 | struct snd_soc_codec *codec = rtd->codec; | ||
936 | struct wm8753_priv *wm8753 = snd_soc_codec_get_drvdata(codec); | 935 | struct wm8753_priv *wm8753 = snd_soc_codec_get_drvdata(codec); |
937 | u16 voice = snd_soc_read(codec, WM8753_PCM) & 0x01f3; | 936 | u16 voice = snd_soc_read(codec, WM8753_PCM) & 0x01f3; |
938 | u16 srate = snd_soc_read(codec, WM8753_SRATE1) & 0x017f; | 937 | u16 srate = snd_soc_read(codec, WM8753_SRATE1) & 0x017f; |
@@ -1161,8 +1160,7 @@ static int wm8753_i2s_hw_params(struct snd_pcm_substream *substream, | |||
1161 | struct snd_pcm_hw_params *params, | 1160 | struct snd_pcm_hw_params *params, |
1162 | struct snd_soc_dai *dai) | 1161 | struct snd_soc_dai *dai) |
1163 | { | 1162 | { |
1164 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 1163 | struct snd_soc_codec *codec = dai->codec; |
1165 | struct snd_soc_codec *codec = rtd->codec; | ||
1166 | struct wm8753_priv *wm8753 = snd_soc_codec_get_drvdata(codec); | 1164 | struct wm8753_priv *wm8753 = snd_soc_codec_get_drvdata(codec); |
1167 | u16 srate = snd_soc_read(codec, WM8753_SRATE1) & 0x01c0; | 1165 | u16 srate = snd_soc_read(codec, WM8753_SRATE1) & 0x01c0; |
1168 | u16 hifi = snd_soc_read(codec, WM8753_HIFI) & 0x01f3; | 1166 | u16 hifi = snd_soc_read(codec, WM8753_HIFI) & 0x01f3; |
diff --git a/sound/soc/codecs/wm8900.c b/sound/soc/codecs/wm8900.c index f18c554efc98..077c9628c70d 100644 --- a/sound/soc/codecs/wm8900.c +++ b/sound/soc/codecs/wm8900.c | |||
@@ -610,8 +610,7 @@ static int wm8900_hw_params(struct snd_pcm_substream *substream, | |||
610 | struct snd_pcm_hw_params *params, | 610 | struct snd_pcm_hw_params *params, |
611 | struct snd_soc_dai *dai) | 611 | struct snd_soc_dai *dai) |
612 | { | 612 | { |
613 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 613 | struct snd_soc_codec *codec = dai->codec; |
614 | struct snd_soc_codec *codec = rtd->codec; | ||
615 | u16 reg; | 614 | u16 reg; |
616 | 615 | ||
617 | reg = snd_soc_read(codec, WM8900_REG_AUDIO1) & ~0x60; | 616 | reg = snd_soc_read(codec, WM8900_REG_AUDIO1) & ~0x60; |
diff --git a/sound/soc/codecs/wm8903.c b/sound/soc/codecs/wm8903.c index c91fb2f99c13..86b8a2926591 100644 --- a/sound/soc/codecs/wm8903.c +++ b/sound/soc/codecs/wm8903.c | |||
@@ -1432,8 +1432,7 @@ static int wm8903_hw_params(struct snd_pcm_substream *substream, | |||
1432 | struct snd_pcm_hw_params *params, | 1432 | struct snd_pcm_hw_params *params, |
1433 | struct snd_soc_dai *dai) | 1433 | struct snd_soc_dai *dai) |
1434 | { | 1434 | { |
1435 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 1435 | struct snd_soc_codec *codec = dai->codec; |
1436 | struct snd_soc_codec *codec =rtd->codec; | ||
1437 | struct wm8903_priv *wm8903 = snd_soc_codec_get_drvdata(codec); | 1436 | struct wm8903_priv *wm8903 = snd_soc_codec_get_drvdata(codec); |
1438 | int fs = params_rate(params); | 1437 | int fs = params_rate(params); |
1439 | int bclk; | 1438 | int bclk; |
diff --git a/sound/soc/codecs/wm8940.c b/sound/soc/codecs/wm8940.c index d2883affea3b..481a3d9cfe48 100644 --- a/sound/soc/codecs/wm8940.c +++ b/sound/soc/codecs/wm8940.c | |||
@@ -371,8 +371,7 @@ static int wm8940_i2s_hw_params(struct snd_pcm_substream *substream, | |||
371 | struct snd_pcm_hw_params *params, | 371 | struct snd_pcm_hw_params *params, |
372 | struct snd_soc_dai *dai) | 372 | struct snd_soc_dai *dai) |
373 | { | 373 | { |
374 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 374 | struct snd_soc_codec *codec = dai->codec; |
375 | struct snd_soc_codec *codec = rtd->codec; | ||
376 | u16 iface = snd_soc_read(codec, WM8940_IFACE) & 0xFD9F; | 375 | u16 iface = snd_soc_read(codec, WM8940_IFACE) & 0xFD9F; |
377 | u16 addcntrl = snd_soc_read(codec, WM8940_ADDCNTRL) & 0xFFF1; | 376 | u16 addcntrl = snd_soc_read(codec, WM8940_ADDCNTRL) & 0xFFF1; |
378 | u16 companding = snd_soc_read(codec, | 377 | u16 companding = snd_soc_read(codec, |
diff --git a/sound/soc/codecs/wm8960.c b/sound/soc/codecs/wm8960.c index 840d72086d04..8bc659d8dd2e 100644 --- a/sound/soc/codecs/wm8960.c +++ b/sound/soc/codecs/wm8960.c | |||
@@ -505,8 +505,7 @@ static int wm8960_hw_params(struct snd_pcm_substream *substream, | |||
505 | struct snd_pcm_hw_params *params, | 505 | struct snd_pcm_hw_params *params, |
506 | struct snd_soc_dai *dai) | 506 | struct snd_soc_dai *dai) |
507 | { | 507 | { |
508 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 508 | struct snd_soc_codec *codec = dai->codec; |
509 | struct snd_soc_codec *codec = rtd->codec; | ||
510 | struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec); | 509 | struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec); |
511 | u16 iface = snd_soc_read(codec, WM8960_IFACE1) & 0xfff3; | 510 | u16 iface = snd_soc_read(codec, WM8960_IFACE1) & 0xfff3; |
512 | int i; | 511 | int i; |
diff --git a/sound/soc/codecs/wm8962.c b/sound/soc/codecs/wm8962.c index 15d467ff91b4..0cfce9999c89 100644 --- a/sound/soc/codecs/wm8962.c +++ b/sound/soc/codecs/wm8962.c | |||
@@ -1478,7 +1478,8 @@ static const DECLARE_TLV_DB_SCALE(eq_tlv, -1200, 100, 0); | |||
1478 | 1478 | ||
1479 | static int wm8962_dsp2_write_config(struct snd_soc_codec *codec) | 1479 | static int wm8962_dsp2_write_config(struct snd_soc_codec *codec) |
1480 | { | 1480 | { |
1481 | return 0; | 1481 | return regcache_sync_region(codec->control_data, |
1482 | WM8962_HDBASS_AI_1, WM8962_MAX_REGISTER); | ||
1482 | } | 1483 | } |
1483 | 1484 | ||
1484 | static int wm8962_dsp2_set_enable(struct snd_soc_codec *codec, u16 val) | 1485 | static int wm8962_dsp2_set_enable(struct snd_soc_codec *codec, u16 val) |
@@ -1755,10 +1756,22 @@ SOC_DOUBLE_R_TLV("EQ4 Volume", WM8962_EQ3, WM8962_EQ23, | |||
1755 | SOC_DOUBLE_R_TLV("EQ5 Volume", WM8962_EQ3, WM8962_EQ23, | 1756 | SOC_DOUBLE_R_TLV("EQ5 Volume", WM8962_EQ3, WM8962_EQ23, |
1756 | WM8962_EQL_B5_GAIN_SHIFT, 31, 0, eq_tlv), | 1757 | WM8962_EQL_B5_GAIN_SHIFT, 31, 0, eq_tlv), |
1757 | 1758 | ||
1759 | SOC_SINGLE("3D Switch", WM8962_THREED1, 0, 1, 0), | ||
1760 | SND_SOC_BYTES_MASK("3D Coefficients", WM8962_THREED1, 4, WM8962_THREED_ENA), | ||
1761 | |||
1762 | SOC_SINGLE("DF1 Switch", WM8962_DF1, 0, 1, 0), | ||
1763 | SND_SOC_BYTES_MASK("DF1 Coefficients", WM8962_DF1, 7, WM8962_DF1_ENA), | ||
1764 | |||
1765 | SOC_SINGLE("DRC Switch", WM8962_DRC_1, 0, 1, 0), | ||
1766 | SND_SOC_BYTES_MASK("DRC Coefficients", WM8962_DRC_1, 5, WM8962_DRC_ENA), | ||
1767 | |||
1758 | WM8962_DSP2_ENABLE("VSS Switch", WM8962_VSS_ENA_SHIFT), | 1768 | WM8962_DSP2_ENABLE("VSS Switch", WM8962_VSS_ENA_SHIFT), |
1769 | SND_SOC_BYTES("VSS Coefficients", WM8962_VSS_XHD2_1, 148), | ||
1759 | WM8962_DSP2_ENABLE("HPF1 Switch", WM8962_HPF1_ENA_SHIFT), | 1770 | WM8962_DSP2_ENABLE("HPF1 Switch", WM8962_HPF1_ENA_SHIFT), |
1760 | WM8962_DSP2_ENABLE("HPF2 Switch", WM8962_HPF2_ENA_SHIFT), | 1771 | WM8962_DSP2_ENABLE("HPF2 Switch", WM8962_HPF2_ENA_SHIFT), |
1772 | SND_SOC_BYTES("HPF Coefficients", WM8962_LHPF2, 1), | ||
1761 | WM8962_DSP2_ENABLE("HD Bass Switch", WM8962_HDBASS_ENA_SHIFT), | 1773 | WM8962_DSP2_ENABLE("HD Bass Switch", WM8962_HDBASS_ENA_SHIFT), |
1774 | SND_SOC_BYTES("HD Bass Coefficients", WM8962_HDBASS_AI_1, 30), | ||
1762 | }; | 1775 | }; |
1763 | 1776 | ||
1764 | static const struct snd_kcontrol_new wm8962_spk_mono_controls[] = { | 1777 | static const struct snd_kcontrol_new wm8962_spk_mono_controls[] = { |
@@ -2519,8 +2532,7 @@ static int wm8962_hw_params(struct snd_pcm_substream *substream, | |||
2519 | struct snd_pcm_hw_params *params, | 2532 | struct snd_pcm_hw_params *params, |
2520 | struct snd_soc_dai *dai) | 2533 | struct snd_soc_dai *dai) |
2521 | { | 2534 | { |
2522 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 2535 | struct snd_soc_codec *codec = dai->codec; |
2523 | struct snd_soc_codec *codec = rtd->codec; | ||
2524 | struct wm8962_priv *wm8962 = snd_soc_codec_get_drvdata(codec); | 2536 | struct wm8962_priv *wm8962 = snd_soc_codec_get_drvdata(codec); |
2525 | int i; | 2537 | int i; |
2526 | int aif0 = 0; | 2538 | int aif0 = 0; |
diff --git a/sound/soc/codecs/wm8971.c b/sound/soc/codecs/wm8971.c index 28fe59e3ce01..eef783f6b6d6 100644 --- a/sound/soc/codecs/wm8971.c +++ b/sound/soc/codecs/wm8971.c | |||
@@ -478,8 +478,7 @@ static int wm8971_pcm_hw_params(struct snd_pcm_substream *substream, | |||
478 | struct snd_pcm_hw_params *params, | 478 | struct snd_pcm_hw_params *params, |
479 | struct snd_soc_dai *dai) | 479 | struct snd_soc_dai *dai) |
480 | { | 480 | { |
481 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 481 | struct snd_soc_codec *codec = dai->codec; |
482 | struct snd_soc_codec *codec = rtd->codec; | ||
483 | struct wm8971_priv *wm8971 = snd_soc_codec_get_drvdata(codec); | 482 | struct wm8971_priv *wm8971 = snd_soc_codec_get_drvdata(codec); |
484 | u16 iface = snd_soc_read(codec, WM8971_IFACE) & 0x1f3; | 483 | u16 iface = snd_soc_read(codec, WM8971_IFACE) & 0x1f3; |
485 | u16 srate = snd_soc_read(codec, WM8971_SRATE) & 0x1c0; | 484 | u16 srate = snd_soc_read(codec, WM8971_SRATE) & 0x1c0; |
diff --git a/sound/soc/codecs/wm8978.c b/sound/soc/codecs/wm8978.c index 72d5fdcd3cc2..a5be3adecf75 100644 --- a/sound/soc/codecs/wm8978.c +++ b/sound/soc/codecs/wm8978.c | |||
@@ -723,8 +723,7 @@ static int wm8978_hw_params(struct snd_pcm_substream *substream, | |||
723 | struct snd_pcm_hw_params *params, | 723 | struct snd_pcm_hw_params *params, |
724 | struct snd_soc_dai *dai) | 724 | struct snd_soc_dai *dai) |
725 | { | 725 | { |
726 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 726 | struct snd_soc_codec *codec = dai->codec; |
727 | struct snd_soc_codec *codec = rtd->codec; | ||
728 | struct wm8978_priv *wm8978 = snd_soc_codec_get_drvdata(codec); | 727 | struct wm8978_priv *wm8978 = snd_soc_codec_get_drvdata(codec); |
729 | /* Word length mask = 0x60 */ | 728 | /* Word length mask = 0x60 */ |
730 | u16 iface_ctl = snd_soc_read(codec, WM8978_AUDIO_INTERFACE) & ~0x60; | 729 | u16 iface_ctl = snd_soc_read(codec, WM8978_AUDIO_INTERFACE) & ~0x60; |
diff --git a/sound/soc/codecs/wm8988.c b/sound/soc/codecs/wm8988.c index 6cdf6a2bc283..1d4c5cf47b06 100644 --- a/sound/soc/codecs/wm8988.c +++ b/sound/soc/codecs/wm8988.c | |||
@@ -668,8 +668,7 @@ static int wm8988_pcm_hw_params(struct snd_pcm_substream *substream, | |||
668 | struct snd_pcm_hw_params *params, | 668 | struct snd_pcm_hw_params *params, |
669 | struct snd_soc_dai *dai) | 669 | struct snd_soc_dai *dai) |
670 | { | 670 | { |
671 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 671 | struct snd_soc_codec *codec = dai->codec; |
672 | struct snd_soc_codec *codec = rtd->codec; | ||
673 | struct wm8988_priv *wm8988 = snd_soc_codec_get_drvdata(codec); | 672 | struct wm8988_priv *wm8988 = snd_soc_codec_get_drvdata(codec); |
674 | u16 iface = snd_soc_read(codec, WM8988_IFACE) & 0x1f3; | 673 | u16 iface = snd_soc_read(codec, WM8988_IFACE) & 0x1f3; |
675 | u16 srate = snd_soc_read(codec, WM8988_SRATE) & 0x180; | 674 | u16 srate = snd_soc_read(codec, WM8988_SRATE) & 0x180; |
diff --git a/sound/soc/codecs/wm8990.c b/sound/soc/codecs/wm8990.c index 9d242351e6e8..db63c97ddf51 100644 --- a/sound/soc/codecs/wm8990.c +++ b/sound/soc/codecs/wm8990.c | |||
@@ -1112,8 +1112,7 @@ static int wm8990_hw_params(struct snd_pcm_substream *substream, | |||
1112 | struct snd_pcm_hw_params *params, | 1112 | struct snd_pcm_hw_params *params, |
1113 | struct snd_soc_dai *dai) | 1113 | struct snd_soc_dai *dai) |
1114 | { | 1114 | { |
1115 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 1115 | struct snd_soc_codec *codec = dai->codec; |
1116 | struct snd_soc_codec *codec = rtd->codec; | ||
1117 | u16 audio1 = snd_soc_read(codec, WM8990_AUDIO_INTERFACE_1); | 1116 | u16 audio1 = snd_soc_read(codec, WM8990_AUDIO_INTERFACE_1); |
1118 | 1117 | ||
1119 | audio1 &= ~WM8990_AIF_WL_MASK; | 1118 | audio1 &= ~WM8990_AIF_WL_MASK; |
diff --git a/sound/soc/codecs/wm8993.c b/sound/soc/codecs/wm8993.c index d256a9340644..36acfccab999 100644 --- a/sound/soc/codecs/wm8993.c +++ b/sound/soc/codecs/wm8993.c | |||
@@ -218,7 +218,6 @@ struct wm8993_priv { | |||
218 | unsigned int sysclk_rate; | 218 | unsigned int sysclk_rate; |
219 | unsigned int fs; | 219 | unsigned int fs; |
220 | unsigned int bclk; | 220 | unsigned int bclk; |
221 | int class_w_users; | ||
222 | unsigned int fll_fref; | 221 | unsigned int fll_fref; |
223 | unsigned int fll_fout; | 222 | unsigned int fll_fout; |
224 | int fll_src; | 223 | int fll_src; |
@@ -824,84 +823,6 @@ static int clk_sys_event(struct snd_soc_dapm_widget *w, | |||
824 | return 0; | 823 | return 0; |
825 | } | 824 | } |
826 | 825 | ||
827 | /* | ||
828 | * When used with DAC outputs only the WM8993 charge pump supports | ||
829 | * operation in class W mode, providing very low power consumption | ||
830 | * when used with digital sources. Enable and disable this mode | ||
831 | * automatically depending on the mixer configuration. | ||
832 | * | ||
833 | * Currently the only supported paths are the direct DAC->headphone | ||
834 | * paths (which provide minimum power consumption anyway). | ||
835 | */ | ||
836 | static int class_w_put(struct snd_kcontrol *kcontrol, | ||
837 | struct snd_ctl_elem_value *ucontrol) | ||
838 | { | ||
839 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); | ||
840 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; | ||
841 | struct snd_soc_codec *codec = widget->codec; | ||
842 | struct wm8993_priv *wm8993 = snd_soc_codec_get_drvdata(codec); | ||
843 | int ret; | ||
844 | |||
845 | /* Turn it off if we're using the main output mixer */ | ||
846 | if (ucontrol->value.integer.value[0] == 0) { | ||
847 | if (wm8993->class_w_users == 0) { | ||
848 | dev_dbg(codec->dev, "Disabling Class W\n"); | ||
849 | snd_soc_update_bits(codec, WM8993_CLASS_W_0, | ||
850 | WM8993_CP_DYN_FREQ | | ||
851 | WM8993_CP_DYN_V, | ||
852 | 0); | ||
853 | } | ||
854 | wm8993->class_w_users++; | ||
855 | wm8993->hubs_data.class_w = true; | ||
856 | } | ||
857 | |||
858 | /* Implement the change */ | ||
859 | ret = snd_soc_dapm_put_enum_double(kcontrol, ucontrol); | ||
860 | |||
861 | /* Enable it if we're using the direct DAC path */ | ||
862 | if (ucontrol->value.integer.value[0] == 1) { | ||
863 | if (wm8993->class_w_users == 1) { | ||
864 | dev_dbg(codec->dev, "Enabling Class W\n"); | ||
865 | snd_soc_update_bits(codec, WM8993_CLASS_W_0, | ||
866 | WM8993_CP_DYN_FREQ | | ||
867 | WM8993_CP_DYN_V, | ||
868 | WM8993_CP_DYN_FREQ | | ||
869 | WM8993_CP_DYN_V); | ||
870 | } | ||
871 | wm8993->class_w_users--; | ||
872 | wm8993->hubs_data.class_w = false; | ||
873 | } | ||
874 | |||
875 | dev_dbg(codec->dev, "Indirect DAC use count now %d\n", | ||
876 | wm8993->class_w_users); | ||
877 | |||
878 | return ret; | ||
879 | } | ||
880 | |||
881 | #define SOC_DAPM_ENUM_W(xname, xenum) \ | ||
882 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ | ||
883 | .info = snd_soc_info_enum_double, \ | ||
884 | .get = snd_soc_dapm_get_enum_double, \ | ||
885 | .put = class_w_put, \ | ||
886 | .private_value = (unsigned long)&xenum } | ||
887 | |||
888 | static const char *hp_mux_text[] = { | ||
889 | "Mixer", | ||
890 | "DAC", | ||
891 | }; | ||
892 | |||
893 | static const struct soc_enum hpl_enum = | ||
894 | SOC_ENUM_SINGLE(WM8993_OUTPUT_MIXER1, 8, 2, hp_mux_text); | ||
895 | |||
896 | static const struct snd_kcontrol_new hpl_mux = | ||
897 | SOC_DAPM_ENUM_W("Left Headphone Mux", hpl_enum); | ||
898 | |||
899 | static const struct soc_enum hpr_enum = | ||
900 | SOC_ENUM_SINGLE(WM8993_OUTPUT_MIXER2, 8, 2, hp_mux_text); | ||
901 | |||
902 | static const struct snd_kcontrol_new hpr_mux = | ||
903 | SOC_DAPM_ENUM_W("Right Headphone Mux", hpr_enum); | ||
904 | |||
905 | static const struct snd_kcontrol_new left_speaker_mixer[] = { | 826 | static const struct snd_kcontrol_new left_speaker_mixer[] = { |
906 | SOC_DAPM_SINGLE("Input Switch", WM8993_SPEAKER_MIXER, 7, 1, 0), | 827 | SOC_DAPM_SINGLE("Input Switch", WM8993_SPEAKER_MIXER, 7, 1, 0), |
907 | SOC_DAPM_SINGLE("IN1LP Switch", WM8993_SPEAKER_MIXER, 5, 1, 0), | 828 | SOC_DAPM_SINGLE("IN1LP Switch", WM8993_SPEAKER_MIXER, 5, 1, 0), |
@@ -988,8 +909,8 @@ SND_SOC_DAPM_MUX("DACR Sidetone", SND_SOC_NOPM, 0, 0, &sidetoner_mux), | |||
988 | SND_SOC_DAPM_DAC("DACL", NULL, WM8993_POWER_MANAGEMENT_3, 1, 0), | 909 | SND_SOC_DAPM_DAC("DACL", NULL, WM8993_POWER_MANAGEMENT_3, 1, 0), |
989 | SND_SOC_DAPM_DAC("DACR", NULL, WM8993_POWER_MANAGEMENT_3, 0, 0), | 910 | SND_SOC_DAPM_DAC("DACR", NULL, WM8993_POWER_MANAGEMENT_3, 0, 0), |
990 | 911 | ||
991 | SND_SOC_DAPM_MUX("Left Headphone Mux", SND_SOC_NOPM, 0, 0, &hpl_mux), | 912 | SND_SOC_DAPM_MUX("Left Headphone Mux", SND_SOC_NOPM, 0, 0, &wm_hubs_hpl_mux), |
992 | SND_SOC_DAPM_MUX("Right Headphone Mux", SND_SOC_NOPM, 0, 0, &hpr_mux), | 913 | SND_SOC_DAPM_MUX("Right Headphone Mux", SND_SOC_NOPM, 0, 0, &wm_hubs_hpr_mux), |
993 | 914 | ||
994 | SND_SOC_DAPM_MIXER("SPKL", WM8993_POWER_MANAGEMENT_3, 8, 0, | 915 | SND_SOC_DAPM_MIXER("SPKL", WM8993_POWER_MANAGEMENT_3, 8, 0, |
995 | left_speaker_mixer, ARRAY_SIZE(left_speaker_mixer)), | 916 | left_speaker_mixer, ARRAY_SIZE(left_speaker_mixer)), |
@@ -1579,9 +1500,6 @@ static int wm8993_probe(struct snd_soc_codec *codec) | |||
1579 | return ret; | 1500 | return ret; |
1580 | } | 1501 | } |
1581 | 1502 | ||
1582 | /* By default we're using the output mixers */ | ||
1583 | wm8993->class_w_users = 2; | ||
1584 | |||
1585 | /* Latch volume update bits and default ZC on */ | 1503 | /* Latch volume update bits and default ZC on */ |
1586 | snd_soc_update_bits(codec, WM8993_RIGHT_DAC_DIGITAL_VOLUME, | 1504 | snd_soc_update_bits(codec, WM8993_RIGHT_DAC_DIGITAL_VOLUME, |
1587 | WM8993_DAC_VU, WM8993_DAC_VU); | 1505 | WM8993_DAC_VU, WM8993_DAC_VU); |
diff --git a/sound/soc/codecs/wm8994.c b/sound/soc/codecs/wm8994.c index 2de12ebe43b5..993639d694ce 100644 --- a/sound/soc/codecs/wm8994.c +++ b/sound/soc/codecs/wm8994.c | |||
@@ -70,8 +70,8 @@ static const struct wm8958_micd_rate micdet_rates[] = { | |||
70 | static const struct wm8958_micd_rate jackdet_rates[] = { | 70 | static const struct wm8958_micd_rate jackdet_rates[] = { |
71 | { 32768, true, 0, 1 }, | 71 | { 32768, true, 0, 1 }, |
72 | { 32768, false, 0, 1 }, | 72 | { 32768, false, 0, 1 }, |
73 | { 44100 * 256, true, 7, 10 }, | 73 | { 44100 * 256, true, 10, 10 }, |
74 | { 44100 * 256, false, 7, 10 }, | 74 | { 44100 * 256, false, 7, 8 }, |
75 | }; | 75 | }; |
76 | 76 | ||
77 | static void wm8958_micd_set_rate(struct snd_soc_codec *codec) | 77 | static void wm8958_micd_set_rate(struct snd_soc_codec *codec) |
@@ -82,7 +82,8 @@ static void wm8958_micd_set_rate(struct snd_soc_codec *codec) | |||
82 | const struct wm8958_micd_rate *rates; | 82 | const struct wm8958_micd_rate *rates; |
83 | int num_rates; | 83 | int num_rates; |
84 | 84 | ||
85 | if (wm8994->jack_cb != wm8958_default_micdet) | 85 | if (!(wm8994->pdata && wm8994->pdata->micd_rates) && |
86 | wm8994->jack_cb != wm8958_default_micdet) | ||
86 | return; | 87 | return; |
87 | 88 | ||
88 | idle = !wm8994->jack_mic; | 89 | idle = !wm8994->jack_mic; |
@@ -118,6 +119,10 @@ static void wm8958_micd_set_rate(struct snd_soc_codec *codec) | |||
118 | val = rates[best].start << WM8958_MICD_BIAS_STARTTIME_SHIFT | 119 | val = rates[best].start << WM8958_MICD_BIAS_STARTTIME_SHIFT |
119 | | rates[best].rate << WM8958_MICD_RATE_SHIFT; | 120 | | rates[best].rate << WM8958_MICD_RATE_SHIFT; |
120 | 121 | ||
122 | dev_dbg(codec->dev, "MICD rate %d,%d for %dHz %s\n", | ||
123 | rates[best].start, rates[best].rate, sysclk, | ||
124 | idle ? "idle" : "active"); | ||
125 | |||
121 | snd_soc_update_bits(codec, WM8958_MIC_DETECT_1, | 126 | snd_soc_update_bits(codec, WM8958_MIC_DETECT_1, |
122 | WM8958_MICD_BIAS_STARTTIME_MASK | | 127 | WM8958_MICD_BIAS_STARTTIME_MASK | |
123 | WM8958_MICD_RATE_MASK, val); | 128 | WM8958_MICD_RATE_MASK, val); |
@@ -398,7 +403,7 @@ static void wm8994_set_retune_mobile(struct snd_soc_codec *codec, int block) | |||
398 | wm8994->dac_rates[iface]); | 403 | wm8994->dac_rates[iface]); |
399 | 404 | ||
400 | /* The EQ will be disabled while reconfiguring it, remember the | 405 | /* The EQ will be disabled while reconfiguring it, remember the |
401 | * current configuration. | 406 | * current configuration. |
402 | */ | 407 | */ |
403 | save = snd_soc_read(codec, base); | 408 | save = snd_soc_read(codec, base); |
404 | save &= WM8994_AIF1DAC1_EQ_ENA; | 409 | save &= WM8994_AIF1DAC1_EQ_ENA; |
@@ -689,6 +694,9 @@ static void wm1811_jackdet_set_mode(struct snd_soc_codec *codec, u16 mode) | |||
689 | if (!wm8994->jackdet || !wm8994->jack_cb) | 694 | if (!wm8994->jackdet || !wm8994->jack_cb) |
690 | return; | 695 | return; |
691 | 696 | ||
697 | if (!wm8994->jackdet || !wm8994->jack_cb) | ||
698 | return; | ||
699 | |||
692 | if (wm8994->active_refcount) | 700 | if (wm8994->active_refcount) |
693 | mode = WM1811_JACKDET_MODE_AUDIO; | 701 | mode = WM1811_JACKDET_MODE_AUDIO; |
694 | 702 | ||
@@ -784,7 +792,7 @@ static void vmid_reference(struct snd_soc_codec *codec) | |||
784 | 792 | ||
785 | switch (wm8994->vmid_mode) { | 793 | switch (wm8994->vmid_mode) { |
786 | default: | 794 | default: |
787 | WARN_ON(0 == "Invalid VMID mode"); | 795 | WARN_ON(NULL == "Invalid VMID mode"); |
788 | case WM8994_VMID_NORMAL: | 796 | case WM8994_VMID_NORMAL: |
789 | /* Startup bias, VMID ramp & buffer */ | 797 | /* Startup bias, VMID ramp & buffer */ |
790 | snd_soc_update_bits(codec, WM8994_ANTIPOP_2, | 798 | snd_soc_update_bits(codec, WM8994_ANTIPOP_2, |
@@ -937,27 +945,12 @@ static int vmid_event(struct snd_soc_dapm_widget *w, | |||
937 | return 0; | 945 | return 0; |
938 | } | 946 | } |
939 | 947 | ||
940 | static void wm8994_update_class_w(struct snd_soc_codec *codec) | 948 | static bool wm8994_check_class_w_digital(struct snd_soc_codec *codec) |
941 | { | 949 | { |
942 | struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec); | ||
943 | int enable = 1; | ||
944 | int source = 0; /* GCC flow analysis can't track enable */ | 950 | int source = 0; /* GCC flow analysis can't track enable */ |
945 | int reg, reg_r; | 951 | int reg, reg_r; |
946 | 952 | ||
947 | /* Only support direct DAC->headphone paths */ | 953 | /* We also need the same AIF source for L/R and only one path */ |
948 | reg = snd_soc_read(codec, WM8994_OUTPUT_MIXER_1); | ||
949 | if (!(reg & WM8994_DAC1L_TO_HPOUT1L)) { | ||
950 | dev_vdbg(codec->dev, "HPL connected to output mixer\n"); | ||
951 | enable = 0; | ||
952 | } | ||
953 | |||
954 | reg = snd_soc_read(codec, WM8994_OUTPUT_MIXER_2); | ||
955 | if (!(reg & WM8994_DAC1R_TO_HPOUT1R)) { | ||
956 | dev_vdbg(codec->dev, "HPR connected to output mixer\n"); | ||
957 | enable = 0; | ||
958 | } | ||
959 | |||
960 | /* We also need the same setting for L/R and only one path */ | ||
961 | reg = snd_soc_read(codec, WM8994_DAC1_LEFT_MIXER_ROUTING); | 954 | reg = snd_soc_read(codec, WM8994_DAC1_LEFT_MIXER_ROUTING); |
962 | switch (reg) { | 955 | switch (reg) { |
963 | case WM8994_AIF2DACL_TO_DAC1L: | 956 | case WM8994_AIF2DACL_TO_DAC1L: |
@@ -974,30 +967,20 @@ static void wm8994_update_class_w(struct snd_soc_codec *codec) | |||
974 | break; | 967 | break; |
975 | default: | 968 | default: |
976 | dev_vdbg(codec->dev, "DAC mixer setting: %x\n", reg); | 969 | dev_vdbg(codec->dev, "DAC mixer setting: %x\n", reg); |
977 | enable = 0; | 970 | return false; |
978 | break; | ||
979 | } | 971 | } |
980 | 972 | ||
981 | reg_r = snd_soc_read(codec, WM8994_DAC1_RIGHT_MIXER_ROUTING); | 973 | reg_r = snd_soc_read(codec, WM8994_DAC1_RIGHT_MIXER_ROUTING); |
982 | if (reg_r != reg) { | 974 | if (reg_r != reg) { |
983 | dev_vdbg(codec->dev, "Left and right DAC mixers different\n"); | 975 | dev_vdbg(codec->dev, "Left and right DAC mixers different\n"); |
984 | enable = 0; | 976 | return false; |
985 | } | 977 | } |
986 | 978 | ||
987 | if (enable) { | 979 | /* Set the source up */ |
988 | dev_dbg(codec->dev, "Class W enabled\n"); | 980 | snd_soc_update_bits(codec, WM8994_CLASS_W_1, |
989 | snd_soc_update_bits(codec, WM8994_CLASS_W_1, | 981 | WM8994_CP_DYN_SRC_SEL_MASK, source); |
990 | WM8994_CP_DYN_PWR | | 982 | |
991 | WM8994_CP_DYN_SRC_SEL_MASK, | 983 | return true; |
992 | source | WM8994_CP_DYN_PWR); | ||
993 | wm8994->hubs.class_w = true; | ||
994 | |||
995 | } else { | ||
996 | dev_dbg(codec->dev, "Class W disabled\n"); | ||
997 | snd_soc_update_bits(codec, WM8994_CLASS_W_1, | ||
998 | WM8994_CP_DYN_PWR, 0); | ||
999 | wm8994->hubs.class_w = false; | ||
1000 | } | ||
1001 | } | 984 | } |
1002 | 985 | ||
1003 | static int aif1clk_ev(struct snd_soc_dapm_widget *w, | 986 | static int aif1clk_ev(struct snd_soc_dapm_widget *w, |
@@ -1280,45 +1263,6 @@ static int dac_ev(struct snd_soc_dapm_widget *w, | |||
1280 | return 0; | 1263 | return 0; |
1281 | } | 1264 | } |
1282 | 1265 | ||
1283 | static const char *hp_mux_text[] = { | ||
1284 | "Mixer", | ||
1285 | "DAC", | ||
1286 | }; | ||
1287 | |||
1288 | #define WM8994_HP_ENUM(xname, xenum) \ | ||
1289 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ | ||
1290 | .info = snd_soc_info_enum_double, \ | ||
1291 | .get = snd_soc_dapm_get_enum_double, \ | ||
1292 | .put = wm8994_put_hp_enum, \ | ||
1293 | .private_value = (unsigned long)&xenum } | ||
1294 | |||
1295 | static int wm8994_put_hp_enum(struct snd_kcontrol *kcontrol, | ||
1296 | struct snd_ctl_elem_value *ucontrol) | ||
1297 | { | ||
1298 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); | ||
1299 | struct snd_soc_dapm_widget *w = wlist->widgets[0]; | ||
1300 | struct snd_soc_codec *codec = w->codec; | ||
1301 | int ret; | ||
1302 | |||
1303 | ret = snd_soc_dapm_put_enum_double(kcontrol, ucontrol); | ||
1304 | |||
1305 | wm8994_update_class_w(codec); | ||
1306 | |||
1307 | return ret; | ||
1308 | } | ||
1309 | |||
1310 | static const struct soc_enum hpl_enum = | ||
1311 | SOC_ENUM_SINGLE(WM8994_OUTPUT_MIXER_1, 8, 2, hp_mux_text); | ||
1312 | |||
1313 | static const struct snd_kcontrol_new hpl_mux = | ||
1314 | WM8994_HP_ENUM("Left Headphone Mux", hpl_enum); | ||
1315 | |||
1316 | static const struct soc_enum hpr_enum = | ||
1317 | SOC_ENUM_SINGLE(WM8994_OUTPUT_MIXER_2, 8, 2, hp_mux_text); | ||
1318 | |||
1319 | static const struct snd_kcontrol_new hpr_mux = | ||
1320 | WM8994_HP_ENUM("Right Headphone Mux", hpr_enum); | ||
1321 | |||
1322 | static const char *adc_mux_text[] = { | 1266 | static const char *adc_mux_text[] = { |
1323 | "ADC", | 1267 | "ADC", |
1324 | "DMIC", | 1268 | "DMIC", |
@@ -1430,7 +1374,7 @@ static int wm8994_put_class_w(struct snd_kcontrol *kcontrol, | |||
1430 | 1374 | ||
1431 | ret = snd_soc_dapm_put_volsw(kcontrol, ucontrol); | 1375 | ret = snd_soc_dapm_put_volsw(kcontrol, ucontrol); |
1432 | 1376 | ||
1433 | wm8994_update_class_w(codec); | 1377 | wm_hubs_update_class_w(codec); |
1434 | 1378 | ||
1435 | return ret; | 1379 | return ret; |
1436 | } | 1380 | } |
@@ -1524,7 +1468,7 @@ static const struct snd_kcontrol_new wm8958_aif3adc_mux = | |||
1524 | SOC_DAPM_ENUM("AIF3ADC Mux", wm8958_aif3adc_enum); | 1468 | SOC_DAPM_ENUM("AIF3ADC Mux", wm8958_aif3adc_enum); |
1525 | 1469 | ||
1526 | static const char *mono_pcm_out_text[] = { | 1470 | static const char *mono_pcm_out_text[] = { |
1527 | "None", "AIF2ADCL", "AIF2ADCR", | 1471 | "None", "AIF2ADCL", "AIF2ADCR", |
1528 | }; | 1472 | }; |
1529 | 1473 | ||
1530 | static const struct soc_enum mono_pcm_out_enum = | 1474 | static const struct soc_enum mono_pcm_out_enum = |
@@ -1573,9 +1517,9 @@ SND_SOC_DAPM_MIXER_E("SPKL", WM8994_POWER_MANAGEMENT_3, 8, 0, | |||
1573 | SND_SOC_DAPM_MIXER_E("SPKR", WM8994_POWER_MANAGEMENT_3, 9, 0, | 1517 | SND_SOC_DAPM_MIXER_E("SPKR", WM8994_POWER_MANAGEMENT_3, 9, 0, |
1574 | right_speaker_mixer, ARRAY_SIZE(right_speaker_mixer), | 1518 | right_speaker_mixer, ARRAY_SIZE(right_speaker_mixer), |
1575 | late_enable_ev, SND_SOC_DAPM_PRE_PMU), | 1519 | late_enable_ev, SND_SOC_DAPM_PRE_PMU), |
1576 | SND_SOC_DAPM_MUX_E("Left Headphone Mux", SND_SOC_NOPM, 0, 0, &hpl_mux, | 1520 | SND_SOC_DAPM_MUX_E("Left Headphone Mux", SND_SOC_NOPM, 0, 0, &wm_hubs_hpl_mux, |
1577 | late_enable_ev, SND_SOC_DAPM_PRE_PMU), | 1521 | late_enable_ev, SND_SOC_DAPM_PRE_PMU), |
1578 | SND_SOC_DAPM_MUX_E("Right Headphone Mux", SND_SOC_NOPM, 0, 0, &hpr_mux, | 1522 | SND_SOC_DAPM_MUX_E("Right Headphone Mux", SND_SOC_NOPM, 0, 0, &wm_hubs_hpr_mux, |
1579 | late_enable_ev, SND_SOC_DAPM_PRE_PMU), | 1523 | late_enable_ev, SND_SOC_DAPM_PRE_PMU), |
1580 | 1524 | ||
1581 | SND_SOC_DAPM_POST("Late Disable PGA", late_disable_ev) | 1525 | SND_SOC_DAPM_POST("Late Disable PGA", late_disable_ev) |
@@ -1591,8 +1535,8 @@ SND_SOC_DAPM_MIXER("SPKL", WM8994_POWER_MANAGEMENT_3, 8, 0, | |||
1591 | left_speaker_mixer, ARRAY_SIZE(left_speaker_mixer)), | 1535 | left_speaker_mixer, ARRAY_SIZE(left_speaker_mixer)), |
1592 | SND_SOC_DAPM_MIXER("SPKR", WM8994_POWER_MANAGEMENT_3, 9, 0, | 1536 | SND_SOC_DAPM_MIXER("SPKR", WM8994_POWER_MANAGEMENT_3, 9, 0, |
1593 | right_speaker_mixer, ARRAY_SIZE(right_speaker_mixer)), | 1537 | right_speaker_mixer, ARRAY_SIZE(right_speaker_mixer)), |
1594 | SND_SOC_DAPM_MUX("Left Headphone Mux", SND_SOC_NOPM, 0, 0, &hpl_mux), | 1538 | SND_SOC_DAPM_MUX("Left Headphone Mux", SND_SOC_NOPM, 0, 0, &wm_hubs_hpl_mux), |
1595 | SND_SOC_DAPM_MUX("Right Headphone Mux", SND_SOC_NOPM, 0, 0, &hpr_mux), | 1539 | SND_SOC_DAPM_MUX("Right Headphone Mux", SND_SOC_NOPM, 0, 0, &wm_hubs_hpr_mux), |
1596 | }; | 1540 | }; |
1597 | 1541 | ||
1598 | static const struct snd_soc_dapm_widget wm8994_dac_revd_widgets[] = { | 1542 | static const struct snd_soc_dapm_widget wm8994_dac_revd_widgets[] = { |
@@ -1732,6 +1676,7 @@ SND_SOC_DAPM_MUX("AIF3ADC Mux", SND_SOC_NOPM, 0, 0, &wm8994_aif3adc_mux), | |||
1732 | }; | 1676 | }; |
1733 | 1677 | ||
1734 | static const struct snd_soc_dapm_widget wm8958_dapm_widgets[] = { | 1678 | static const struct snd_soc_dapm_widget wm8958_dapm_widgets[] = { |
1679 | SND_SOC_DAPM_SUPPLY("AIF3", WM8994_POWER_MANAGEMENT_6, 5, 1, NULL, 0), | ||
1735 | SND_SOC_DAPM_MUX("Mono PCM Out Mux", SND_SOC_NOPM, 0, 0, &mono_pcm_out_mux), | 1680 | SND_SOC_DAPM_MUX("Mono PCM Out Mux", SND_SOC_NOPM, 0, 0, &mono_pcm_out_mux), |
1736 | SND_SOC_DAPM_MUX("AIF2DACL Mux", SND_SOC_NOPM, 0, 0, &aif2dacl_src_mux), | 1681 | SND_SOC_DAPM_MUX("AIF2DACL Mux", SND_SOC_NOPM, 0, 0, &aif2dacl_src_mux), |
1737 | SND_SOC_DAPM_MUX("AIF2DACR Mux", SND_SOC_NOPM, 0, 0, &aif2dacr_src_mux), | 1682 | SND_SOC_DAPM_MUX("AIF2DACR Mux", SND_SOC_NOPM, 0, 0, &aif2dacr_src_mux), |
@@ -1972,6 +1917,9 @@ static const struct snd_soc_dapm_route wm8958_intercon[] = { | |||
1972 | { "AIF2DACR Mux", "AIF2", "AIF2DAC Mux" }, | 1917 | { "AIF2DACR Mux", "AIF2", "AIF2DAC Mux" }, |
1973 | { "AIF2DACR Mux", "AIF3", "AIF3DACDAT" }, | 1918 | { "AIF2DACR Mux", "AIF3", "AIF3DACDAT" }, |
1974 | 1919 | ||
1920 | { "AIF3DACDAT", NULL, "AIF3" }, | ||
1921 | { "AIF3ADCDAT", NULL, "AIF3" }, | ||
1922 | |||
1975 | { "Mono PCM Out Mux", "AIF2ADCL", "AIF2ADCL" }, | 1923 | { "Mono PCM Out Mux", "AIF2ADCL", "AIF2ADCL" }, |
1976 | { "Mono PCM Out Mux", "AIF2ADCR", "AIF2ADCR" }, | 1924 | { "Mono PCM Out Mux", "AIF2ADCR", "AIF2ADCR" }, |
1977 | 1925 | ||
@@ -2068,24 +2016,20 @@ static int _wm8994_set_fll(struct snd_soc_codec *codec, int id, int src, | |||
2068 | struct wm8994 *control = wm8994->wm8994; | 2016 | struct wm8994 *control = wm8994->wm8994; |
2069 | int reg_offset, ret; | 2017 | int reg_offset, ret; |
2070 | struct fll_div fll; | 2018 | struct fll_div fll; |
2071 | u16 reg, aif1, aif2; | 2019 | u16 reg, clk1, aif_reg, aif_src; |
2072 | unsigned long timeout; | 2020 | unsigned long timeout; |
2073 | bool was_enabled; | 2021 | bool was_enabled; |
2074 | 2022 | ||
2075 | aif1 = snd_soc_read(codec, WM8994_AIF1_CLOCKING_1) | ||
2076 | & WM8994_AIF1CLK_ENA; | ||
2077 | |||
2078 | aif2 = snd_soc_read(codec, WM8994_AIF2_CLOCKING_1) | ||
2079 | & WM8994_AIF2CLK_ENA; | ||
2080 | |||
2081 | switch (id) { | 2023 | switch (id) { |
2082 | case WM8994_FLL1: | 2024 | case WM8994_FLL1: |
2083 | reg_offset = 0; | 2025 | reg_offset = 0; |
2084 | id = 0; | 2026 | id = 0; |
2027 | aif_src = 0x10; | ||
2085 | break; | 2028 | break; |
2086 | case WM8994_FLL2: | 2029 | case WM8994_FLL2: |
2087 | reg_offset = 0x20; | 2030 | reg_offset = 0x20; |
2088 | id = 1; | 2031 | id = 1; |
2032 | aif_src = 0x18; | ||
2089 | break; | 2033 | break; |
2090 | default: | 2034 | default: |
2091 | return -EINVAL; | 2035 | return -EINVAL; |
@@ -2127,16 +2071,33 @@ static int _wm8994_set_fll(struct snd_soc_codec *codec, int id, int src, | |||
2127 | if (ret < 0) | 2071 | if (ret < 0) |
2128 | return ret; | 2072 | return ret; |
2129 | 2073 | ||
2130 | /* Gate the AIF clocks while we reclock */ | 2074 | /* Make sure that we're not providing SYSCLK right now */ |
2131 | snd_soc_update_bits(codec, WM8994_AIF1_CLOCKING_1, | 2075 | clk1 = snd_soc_read(codec, WM8994_CLOCKING_1); |
2132 | WM8994_AIF1CLK_ENA, 0); | 2076 | if (clk1 & WM8994_SYSCLK_SRC) |
2133 | snd_soc_update_bits(codec, WM8994_AIF2_CLOCKING_1, | 2077 | aif_reg = WM8994_AIF2_CLOCKING_1; |
2134 | WM8994_AIF2CLK_ENA, 0); | 2078 | else |
2079 | aif_reg = WM8994_AIF1_CLOCKING_1; | ||
2080 | reg = snd_soc_read(codec, aif_reg); | ||
2081 | |||
2082 | if ((reg & WM8994_AIF1CLK_ENA) && | ||
2083 | (reg & WM8994_AIF1CLK_SRC_MASK) == aif_src) { | ||
2084 | dev_err(codec->dev, "FLL%d is currently providing SYSCLK\n", | ||
2085 | id + 1); | ||
2086 | return -EBUSY; | ||
2087 | } | ||
2135 | 2088 | ||
2136 | /* We always need to disable the FLL while reconfiguring */ | 2089 | /* We always need to disable the FLL while reconfiguring */ |
2137 | snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_1 + reg_offset, | 2090 | snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_1 + reg_offset, |
2138 | WM8994_FLL1_ENA, 0); | 2091 | WM8994_FLL1_ENA, 0); |
2139 | 2092 | ||
2093 | if (wm8994->fll_byp && src == WM8994_FLL_SRC_BCLK && | ||
2094 | freq_in == freq_out && freq_out) { | ||
2095 | dev_dbg(codec->dev, "Bypassing FLL%d\n", id + 1); | ||
2096 | snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_5 + reg_offset, | ||
2097 | WM8958_FLL1_BYP, WM8958_FLL1_BYP); | ||
2098 | goto out; | ||
2099 | } | ||
2100 | |||
2140 | reg = (fll.outdiv << WM8994_FLL1_OUTDIV_SHIFT) | | 2101 | reg = (fll.outdiv << WM8994_FLL1_OUTDIV_SHIFT) | |
2141 | (fll.fll_fratio << WM8994_FLL1_FRATIO_SHIFT); | 2102 | (fll.fll_fratio << WM8994_FLL1_FRATIO_SHIFT); |
2142 | snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_2 + reg_offset, | 2103 | snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_2 + reg_offset, |
@@ -2151,6 +2112,7 @@ static int _wm8994_set_fll(struct snd_soc_codec *codec, int id, int src, | |||
2151 | fll.n << WM8994_FLL1_N_SHIFT); | 2112 | fll.n << WM8994_FLL1_N_SHIFT); |
2152 | 2113 | ||
2153 | snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_5 + reg_offset, | 2114 | snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_5 + reg_offset, |
2115 | WM8958_FLL1_BYP | | ||
2154 | WM8994_FLL1_REFCLK_DIV_MASK | | 2116 | WM8994_FLL1_REFCLK_DIV_MASK | |
2155 | WM8994_FLL1_REFCLK_SRC_MASK, | 2117 | WM8994_FLL1_REFCLK_SRC_MASK, |
2156 | (fll.clk_ref_div << WM8994_FLL1_REFCLK_DIV_SHIFT) | | 2118 | (fll.clk_ref_div << WM8994_FLL1_REFCLK_DIV_SHIFT) | |
@@ -2213,16 +2175,11 @@ static int _wm8994_set_fll(struct snd_soc_codec *codec, int id, int src, | |||
2213 | } | 2175 | } |
2214 | } | 2176 | } |
2215 | 2177 | ||
2178 | out: | ||
2216 | wm8994->fll[id].in = freq_in; | 2179 | wm8994->fll[id].in = freq_in; |
2217 | wm8994->fll[id].out = freq_out; | 2180 | wm8994->fll[id].out = freq_out; |
2218 | wm8994->fll[id].src = src; | 2181 | wm8994->fll[id].src = src; |
2219 | 2182 | ||
2220 | /* Enable any gated AIF clocks */ | ||
2221 | snd_soc_update_bits(codec, WM8994_AIF1_CLOCKING_1, | ||
2222 | WM8994_AIF1CLK_ENA, aif1); | ||
2223 | snd_soc_update_bits(codec, WM8994_AIF2_CLOCKING_1, | ||
2224 | WM8994_AIF2CLK_ENA, aif2); | ||
2225 | |||
2226 | configure_clock(codec); | 2183 | configure_clock(codec); |
2227 | 2184 | ||
2228 | return 0; | 2185 | return 0; |
@@ -2290,7 +2247,7 @@ static int wm8994_set_dai_sysclk(struct snd_soc_dai *dai, | |||
2290 | 2247 | ||
2291 | case WM8994_SYSCLK_OPCLK: | 2248 | case WM8994_SYSCLK_OPCLK: |
2292 | /* Special case - a division (times 10) is given and | 2249 | /* Special case - a division (times 10) is given and |
2293 | * no effect on main clocking. | 2250 | * no effect on main clocking. |
2294 | */ | 2251 | */ |
2295 | if (freq) { | 2252 | if (freq) { |
2296 | for (i = 0; i < ARRAY_SIZE(opclk_divs); i++) | 2253 | for (i = 0; i < ARRAY_SIZE(opclk_divs); i++) |
@@ -2792,33 +2749,6 @@ static int wm8994_aif3_hw_params(struct snd_pcm_substream *substream, | |||
2792 | return snd_soc_update_bits(codec, aif1_reg, WM8994_AIF1_WL_MASK, aif1); | 2749 | return snd_soc_update_bits(codec, aif1_reg, WM8994_AIF1_WL_MASK, aif1); |
2793 | } | 2750 | } |
2794 | 2751 | ||
2795 | static void wm8994_aif_shutdown(struct snd_pcm_substream *substream, | ||
2796 | struct snd_soc_dai *dai) | ||
2797 | { | ||
2798 | struct snd_soc_codec *codec = dai->codec; | ||
2799 | int rate_reg = 0; | ||
2800 | |||
2801 | switch (dai->id) { | ||
2802 | case 1: | ||
2803 | rate_reg = WM8994_AIF1_RATE; | ||
2804 | break; | ||
2805 | case 2: | ||
2806 | rate_reg = WM8994_AIF2_RATE; | ||
2807 | break; | ||
2808 | default: | ||
2809 | break; | ||
2810 | } | ||
2811 | |||
2812 | /* If the DAI is idle then configure the divider tree for the | ||
2813 | * lowest output rate to save a little power if the clock is | ||
2814 | * still active (eg, because it is system clock). | ||
2815 | */ | ||
2816 | if (rate_reg && !dai->playback_active && !dai->capture_active) | ||
2817 | snd_soc_update_bits(codec, rate_reg, | ||
2818 | WM8994_AIF1_SR_MASK | | ||
2819 | WM8994_AIF1CLK_RATE_MASK, 0x9); | ||
2820 | } | ||
2821 | |||
2822 | static int wm8994_aif_mute(struct snd_soc_dai *codec_dai, int mute) | 2752 | static int wm8994_aif_mute(struct snd_soc_dai *codec_dai, int mute) |
2823 | { | 2753 | { |
2824 | struct snd_soc_codec *codec = codec_dai->codec; | 2754 | struct snd_soc_codec *codec = codec_dai->codec; |
@@ -2860,10 +2790,6 @@ static int wm8994_set_tristate(struct snd_soc_dai *codec_dai, int tristate) | |||
2860 | reg = WM8994_AIF2_MASTER_SLAVE; | 2790 | reg = WM8994_AIF2_MASTER_SLAVE; |
2861 | mask = WM8994_AIF2_TRI; | 2791 | mask = WM8994_AIF2_TRI; |
2862 | break; | 2792 | break; |
2863 | case 3: | ||
2864 | reg = WM8994_POWER_MANAGEMENT_6; | ||
2865 | mask = WM8994_AIF3_TRI; | ||
2866 | break; | ||
2867 | default: | 2793 | default: |
2868 | return -EINVAL; | 2794 | return -EINVAL; |
2869 | } | 2795 | } |
@@ -2900,7 +2826,6 @@ static const struct snd_soc_dai_ops wm8994_aif1_dai_ops = { | |||
2900 | .set_sysclk = wm8994_set_dai_sysclk, | 2826 | .set_sysclk = wm8994_set_dai_sysclk, |
2901 | .set_fmt = wm8994_set_dai_fmt, | 2827 | .set_fmt = wm8994_set_dai_fmt, |
2902 | .hw_params = wm8994_hw_params, | 2828 | .hw_params = wm8994_hw_params, |
2903 | .shutdown = wm8994_aif_shutdown, | ||
2904 | .digital_mute = wm8994_aif_mute, | 2829 | .digital_mute = wm8994_aif_mute, |
2905 | .set_pll = wm8994_set_fll, | 2830 | .set_pll = wm8994_set_fll, |
2906 | .set_tristate = wm8994_set_tristate, | 2831 | .set_tristate = wm8994_set_tristate, |
@@ -2910,7 +2835,6 @@ static const struct snd_soc_dai_ops wm8994_aif2_dai_ops = { | |||
2910 | .set_sysclk = wm8994_set_dai_sysclk, | 2835 | .set_sysclk = wm8994_set_dai_sysclk, |
2911 | .set_fmt = wm8994_set_dai_fmt, | 2836 | .set_fmt = wm8994_set_dai_fmt, |
2912 | .hw_params = wm8994_hw_params, | 2837 | .hw_params = wm8994_hw_params, |
2913 | .shutdown = wm8994_aif_shutdown, | ||
2914 | .digital_mute = wm8994_aif_mute, | 2838 | .digital_mute = wm8994_aif_mute, |
2915 | .set_pll = wm8994_set_fll, | 2839 | .set_pll = wm8994_set_fll, |
2916 | .set_tristate = wm8994_set_tristate, | 2840 | .set_tristate = wm8994_set_tristate, |
@@ -2918,7 +2842,6 @@ static const struct snd_soc_dai_ops wm8994_aif2_dai_ops = { | |||
2918 | 2842 | ||
2919 | static const struct snd_soc_dai_ops wm8994_aif3_dai_ops = { | 2843 | static const struct snd_soc_dai_ops wm8994_aif3_dai_ops = { |
2920 | .hw_params = wm8994_aif3_hw_params, | 2844 | .hw_params = wm8994_aif3_hw_params, |
2921 | .set_tristate = wm8994_set_tristate, | ||
2922 | }; | 2845 | }; |
2923 | 2846 | ||
2924 | static struct snd_soc_dai_driver wm8994_dai[] = { | 2847 | static struct snd_soc_dai_driver wm8994_dai[] = { |
@@ -3126,14 +3049,14 @@ static void wm8994_handle_retune_mobile_pdata(struct wm8994_priv *wm8994) | |||
3126 | 3049 | ||
3127 | /* Expand the array... */ | 3050 | /* Expand the array... */ |
3128 | t = krealloc(wm8994->retune_mobile_texts, | 3051 | t = krealloc(wm8994->retune_mobile_texts, |
3129 | sizeof(char *) * | 3052 | sizeof(char *) * |
3130 | (wm8994->num_retune_mobile_texts + 1), | 3053 | (wm8994->num_retune_mobile_texts + 1), |
3131 | GFP_KERNEL); | 3054 | GFP_KERNEL); |
3132 | if (t == NULL) | 3055 | if (t == NULL) |
3133 | continue; | 3056 | continue; |
3134 | 3057 | ||
3135 | /* ...store the new entry... */ | 3058 | /* ...store the new entry... */ |
3136 | t[wm8994->num_retune_mobile_texts] = | 3059 | t[wm8994->num_retune_mobile_texts] = |
3137 | pdata->retune_mobile_cfgs[i].name; | 3060 | pdata->retune_mobile_cfgs[i].name; |
3138 | 3061 | ||
3139 | /* ...and remember the new version. */ | 3062 | /* ...and remember the new version. */ |
@@ -3304,25 +3227,25 @@ int wm8994_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack, | |||
3304 | } | 3227 | } |
3305 | EXPORT_SYMBOL_GPL(wm8994_mic_detect); | 3228 | EXPORT_SYMBOL_GPL(wm8994_mic_detect); |
3306 | 3229 | ||
3307 | static irqreturn_t wm8994_mic_irq(int irq, void *data) | 3230 | static void wm8994_mic_work(struct work_struct *work) |
3308 | { | 3231 | { |
3309 | struct wm8994_priv *priv = data; | 3232 | struct wm8994_priv *priv = container_of(work, |
3310 | struct snd_soc_codec *codec = priv->codec; | 3233 | struct wm8994_priv, |
3311 | int reg; | 3234 | mic_work.work); |
3235 | struct regmap *regmap = priv->wm8994->regmap; | ||
3236 | struct device *dev = priv->wm8994->dev; | ||
3237 | unsigned int reg; | ||
3238 | int ret; | ||
3312 | int report; | 3239 | int report; |
3313 | 3240 | ||
3314 | #ifndef CONFIG_SND_SOC_WM8994_MODULE | 3241 | ret = regmap_read(regmap, WM8994_INTERRUPT_RAW_STATUS_2, ®); |
3315 | trace_snd_soc_jack_irq(dev_name(codec->dev)); | 3242 | if (ret < 0) { |
3316 | #endif | 3243 | dev_err(dev, "Failed to read microphone status: %d\n", |
3317 | 3244 | ret); | |
3318 | reg = snd_soc_read(codec, WM8994_INTERRUPT_RAW_STATUS_2); | 3245 | return; |
3319 | if (reg < 0) { | ||
3320 | dev_err(codec->dev, "Failed to read microphone status: %d\n", | ||
3321 | reg); | ||
3322 | return IRQ_HANDLED; | ||
3323 | } | 3246 | } |
3324 | 3247 | ||
3325 | dev_dbg(codec->dev, "Microphone status: %x\n", reg); | 3248 | dev_dbg(dev, "Microphone status: %x\n", reg); |
3326 | 3249 | ||
3327 | report = 0; | 3250 | report = 0; |
3328 | if (reg & WM8994_MIC1_DET_STS) { | 3251 | if (reg & WM8994_MIC1_DET_STS) { |
@@ -3361,6 +3284,20 @@ static irqreturn_t wm8994_mic_irq(int irq, void *data) | |||
3361 | 3284 | ||
3362 | snd_soc_jack_report(priv->micdet[1].jack, report, | 3285 | snd_soc_jack_report(priv->micdet[1].jack, report, |
3363 | SND_JACK_HEADSET | SND_JACK_BTN_0); | 3286 | SND_JACK_HEADSET | SND_JACK_BTN_0); |
3287 | } | ||
3288 | |||
3289 | static irqreturn_t wm8994_mic_irq(int irq, void *data) | ||
3290 | { | ||
3291 | struct wm8994_priv *priv = data; | ||
3292 | struct snd_soc_codec *codec = priv->codec; | ||
3293 | |||
3294 | #ifndef CONFIG_SND_SOC_WM8994_MODULE | ||
3295 | trace_snd_soc_jack_irq(dev_name(codec->dev)); | ||
3296 | #endif | ||
3297 | |||
3298 | pm_wakeup_event(codec->dev, 300); | ||
3299 | |||
3300 | schedule_delayed_work(&priv->mic_work, msecs_to_jiffies(250)); | ||
3364 | 3301 | ||
3365 | return IRQ_HANDLED; | 3302 | return IRQ_HANDLED; |
3366 | } | 3303 | } |
@@ -3415,9 +3352,6 @@ static void wm8958_default_micdet(u16 status, void *data) | |||
3415 | 3352 | ||
3416 | wm8958_micd_set_rate(codec); | 3353 | wm8958_micd_set_rate(codec); |
3417 | 3354 | ||
3418 | snd_soc_jack_report(wm8994->micdet[0].jack, SND_JACK_HEADPHONE, | ||
3419 | SND_JACK_HEADSET); | ||
3420 | |||
3421 | /* If we have jackdet that will detect removal */ | 3355 | /* If we have jackdet that will detect removal */ |
3422 | if (wm8994->jackdet) { | 3356 | if (wm8994->jackdet) { |
3423 | mutex_lock(&wm8994->accdet_lock); | 3357 | mutex_lock(&wm8994->accdet_lock); |
@@ -3430,14 +3364,13 @@ static void wm8958_default_micdet(u16 status, void *data) | |||
3430 | 3364 | ||
3431 | mutex_unlock(&wm8994->accdet_lock); | 3365 | mutex_unlock(&wm8994->accdet_lock); |
3432 | 3366 | ||
3433 | if (wm8994->pdata->jd_ext_cap) { | 3367 | if (wm8994->pdata->jd_ext_cap) |
3434 | mutex_lock(&codec->mutex); | ||
3435 | snd_soc_dapm_disable_pin(&codec->dapm, | 3368 | snd_soc_dapm_disable_pin(&codec->dapm, |
3436 | "MICBIAS2"); | 3369 | "MICBIAS2"); |
3437 | snd_soc_dapm_sync(&codec->dapm); | ||
3438 | mutex_unlock(&codec->mutex); | ||
3439 | } | ||
3440 | } | 3370 | } |
3371 | |||
3372 | snd_soc_jack_report(wm8994->micdet[0].jack, SND_JACK_HEADPHONE, | ||
3373 | SND_JACK_HEADSET); | ||
3441 | } | 3374 | } |
3442 | 3375 | ||
3443 | /* Report short circuit as a button */ | 3376 | /* Report short circuit as a button */ |
@@ -3489,6 +3422,8 @@ static irqreturn_t wm1811_jackdet_irq(int irq, void *data) | |||
3489 | if (present) { | 3422 | if (present) { |
3490 | dev_dbg(codec->dev, "Jack detected\n"); | 3423 | dev_dbg(codec->dev, "Jack detected\n"); |
3491 | 3424 | ||
3425 | wm8958_micd_set_rate(codec); | ||
3426 | |||
3492 | snd_soc_update_bits(codec, WM8958_MICBIAS2, | 3427 | snd_soc_update_bits(codec, WM8958_MICBIAS2, |
3493 | WM8958_MICB2_DISCH, 0); | 3428 | WM8958_MICB2_DISCH, 0); |
3494 | 3429 | ||
@@ -3526,16 +3461,11 @@ static irqreturn_t wm1811_jackdet_irq(int irq, void *data) | |||
3526 | 3461 | ||
3527 | /* If required for an external cap force MICBIAS on */ | 3462 | /* If required for an external cap force MICBIAS on */ |
3528 | if (wm8994->pdata->jd_ext_cap) { | 3463 | if (wm8994->pdata->jd_ext_cap) { |
3529 | mutex_lock(&codec->mutex); | ||
3530 | |||
3531 | if (present) | 3464 | if (present) |
3532 | snd_soc_dapm_force_enable_pin(&codec->dapm, | 3465 | snd_soc_dapm_force_enable_pin(&codec->dapm, |
3533 | "MICBIAS2"); | 3466 | "MICBIAS2"); |
3534 | else | 3467 | else |
3535 | snd_soc_dapm_disable_pin(&codec->dapm, "MICBIAS2"); | 3468 | snd_soc_dapm_disable_pin(&codec->dapm, "MICBIAS2"); |
3536 | |||
3537 | snd_soc_dapm_sync(&codec->dapm); | ||
3538 | mutex_unlock(&codec->mutex); | ||
3539 | } | 3469 | } |
3540 | 3470 | ||
3541 | if (present) | 3471 | if (present) |
@@ -3740,6 +3670,7 @@ static int wm8994_codec_probe(struct snd_soc_codec *codec) | |||
3740 | wm8994->codec = codec; | 3670 | wm8994->codec = codec; |
3741 | 3671 | ||
3742 | mutex_init(&wm8994->accdet_lock); | 3672 | mutex_init(&wm8994->accdet_lock); |
3673 | INIT_DELAYED_WORK(&wm8994->mic_work, wm8994_mic_work); | ||
3743 | 3674 | ||
3744 | for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++) | 3675 | for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++) |
3745 | init_completion(&wm8994->fll_locked[i]); | 3676 | init_completion(&wm8994->fll_locked[i]); |
@@ -3783,13 +3714,22 @@ static int wm8994_codec_probe(struct snd_soc_codec *codec) | |||
3783 | case WM8958: | 3714 | case WM8958: |
3784 | wm8994->hubs.dcs_readback_mode = 1; | 3715 | wm8994->hubs.dcs_readback_mode = 1; |
3785 | wm8994->hubs.hp_startup_mode = 1; | 3716 | wm8994->hubs.hp_startup_mode = 1; |
3717 | |||
3718 | switch (wm8994->revision) { | ||
3719 | case 0: | ||
3720 | break; | ||
3721 | default: | ||
3722 | wm8994->fll_byp = true; | ||
3723 | break; | ||
3724 | } | ||
3786 | break; | 3725 | break; |
3787 | 3726 | ||
3788 | case WM1811: | 3727 | case WM1811: |
3789 | wm8994->hubs.dcs_readback_mode = 2; | 3728 | wm8994->hubs.dcs_readback_mode = 2; |
3790 | wm8994->hubs.no_series_update = 1; | 3729 | wm8994->hubs.no_series_update = 1; |
3791 | wm8994->hubs.hp_startup_mode = 1; | 3730 | wm8994->hubs.hp_startup_mode = 1; |
3792 | wm8994->hubs.no_cache_class_w = true; | 3731 | wm8994->hubs.no_cache_dac_hp_direct = true; |
3732 | wm8994->fll_byp = true; | ||
3793 | 3733 | ||
3794 | switch (wm8994->revision) { | 3734 | switch (wm8994->revision) { |
3795 | case 0: | 3735 | case 0: |
@@ -4010,7 +3950,8 @@ static int wm8994_codec_probe(struct snd_soc_codec *codec) | |||
4010 | break; | 3950 | break; |
4011 | } | 3951 | } |
4012 | 3952 | ||
4013 | wm8994_update_class_w(codec); | 3953 | wm8994->hubs.check_class_w_digital = wm8994_check_class_w_digital; |
3954 | wm_hubs_update_class_w(codec); | ||
4014 | 3955 | ||
4015 | wm8994_handle_pdata(wm8994); | 3956 | wm8994_handle_pdata(wm8994); |
4016 | 3957 | ||
@@ -4075,7 +4016,6 @@ static int wm8994_codec_probe(struct snd_soc_codec *codec) | |||
4075 | ARRAY_SIZE(wm8994_dac_widgets)); | 4016 | ARRAY_SIZE(wm8994_dac_widgets)); |
4076 | break; | 4017 | break; |
4077 | } | 4018 | } |
4078 | |||
4079 | 4019 | ||
4080 | wm_hubs_add_analogue_routes(codec, 0, 0); | 4020 | wm_hubs_add_analogue_routes(codec, 0, 0); |
4081 | snd_soc_dapm_add_routes(dapm, intercon, ARRAY_SIZE(intercon)); | 4021 | snd_soc_dapm_add_routes(dapm, intercon, ARRAY_SIZE(intercon)); |
@@ -4140,7 +4080,7 @@ err_irq: | |||
4140 | return ret; | 4080 | return ret; |
4141 | } | 4081 | } |
4142 | 4082 | ||
4143 | static int wm8994_codec_remove(struct snd_soc_codec *codec) | 4083 | static int wm8994_codec_remove(struct snd_soc_codec *codec) |
4144 | { | 4084 | { |
4145 | struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec); | 4085 | struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec); |
4146 | struct wm8994 *control = wm8994->wm8994; | 4086 | struct wm8994 *control = wm8994->wm8994; |
@@ -4181,14 +4121,10 @@ static int wm8994_codec_remove(struct snd_soc_codec *codec) | |||
4181 | free_irq(wm8994->micdet_irq, wm8994); | 4121 | free_irq(wm8994->micdet_irq, wm8994); |
4182 | break; | 4122 | break; |
4183 | } | 4123 | } |
4184 | if (wm8994->mbc) | 4124 | release_firmware(wm8994->mbc); |
4185 | release_firmware(wm8994->mbc); | 4125 | release_firmware(wm8994->mbc_vss); |
4186 | if (wm8994->mbc_vss) | 4126 | release_firmware(wm8994->enh_eq); |
4187 | release_firmware(wm8994->mbc_vss); | ||
4188 | if (wm8994->enh_eq) | ||
4189 | release_firmware(wm8994->enh_eq); | ||
4190 | kfree(wm8994->retune_mobile_texts); | 4127 | kfree(wm8994->retune_mobile_texts); |
4191 | |||
4192 | return 0; | 4128 | return 0; |
4193 | } | 4129 | } |
4194 | 4130 | ||
diff --git a/sound/soc/codecs/wm8994.h b/sound/soc/codecs/wm8994.h index c724112998d8..d77e06f0a675 100644 --- a/sound/soc/codecs/wm8994.h +++ b/sound/soc/codecs/wm8994.h | |||
@@ -12,6 +12,7 @@ | |||
12 | #include <sound/soc.h> | 12 | #include <sound/soc.h> |
13 | #include <linux/firmware.h> | 13 | #include <linux/firmware.h> |
14 | #include <linux/completion.h> | 14 | #include <linux/completion.h> |
15 | #include <linux/workqueue.h> | ||
15 | 16 | ||
16 | #include "wm_hubs.h" | 17 | #include "wm_hubs.h" |
17 | 18 | ||
@@ -79,6 +80,7 @@ struct wm8994_priv { | |||
79 | struct wm8994_fll_config fll[2], fll_suspend[2]; | 80 | struct wm8994_fll_config fll[2], fll_suspend[2]; |
80 | struct completion fll_locked[2]; | 81 | struct completion fll_locked[2]; |
81 | bool fll_locked_irq; | 82 | bool fll_locked_irq; |
83 | bool fll_byp; | ||
82 | 84 | ||
83 | int vmid_refcount; | 85 | int vmid_refcount; |
84 | int active_refcount; | 86 | int active_refcount; |
@@ -126,6 +128,7 @@ struct wm8994_priv { | |||
126 | 128 | ||
127 | struct mutex accdet_lock; | 129 | struct mutex accdet_lock; |
128 | struct wm8994_micdet micdet[2]; | 130 | struct wm8994_micdet micdet[2]; |
131 | struct delayed_work mic_work; | ||
129 | bool mic_detecting; | 132 | bool mic_detecting; |
130 | bool jack_mic; | 133 | bool jack_mic; |
131 | int btn_mask; | 134 | int btn_mask; |
diff --git a/sound/soc/codecs/wm8996.c b/sound/soc/codecs/wm8996.c index 1fd635494045..8af422e38fd0 100644 --- a/sound/soc/codecs/wm8996.c +++ b/sound/soc/codecs/wm8996.c | |||
@@ -1770,7 +1770,13 @@ static int wm8996_set_bias_level(struct snd_soc_codec *codec, | |||
1770 | 1770 | ||
1771 | switch (level) { | 1771 | switch (level) { |
1772 | case SND_SOC_BIAS_ON: | 1772 | case SND_SOC_BIAS_ON: |
1773 | break; | ||
1773 | case SND_SOC_BIAS_PREPARE: | 1774 | case SND_SOC_BIAS_PREPARE: |
1775 | /* Put the MICBIASes into regulating mode */ | ||
1776 | snd_soc_update_bits(codec, WM8996_MICBIAS_1, | ||
1777 | WM8996_MICB1_MODE, 0); | ||
1778 | snd_soc_update_bits(codec, WM8996_MICBIAS_2, | ||
1779 | WM8996_MICB2_MODE, 0); | ||
1774 | break; | 1780 | break; |
1775 | 1781 | ||
1776 | case SND_SOC_BIAS_STANDBY: | 1782 | case SND_SOC_BIAS_STANDBY: |
@@ -1793,6 +1799,12 @@ static int wm8996_set_bias_level(struct snd_soc_codec *codec, | |||
1793 | regcache_cache_only(codec->control_data, false); | 1799 | regcache_cache_only(codec->control_data, false); |
1794 | regcache_sync(codec->control_data); | 1800 | regcache_sync(codec->control_data); |
1795 | } | 1801 | } |
1802 | |||
1803 | /* Bypass the MICBIASes for lowest power */ | ||
1804 | snd_soc_update_bits(codec, WM8996_MICBIAS_1, | ||
1805 | WM8996_MICB1_MODE, WM8996_MICB1_MODE); | ||
1806 | snd_soc_update_bits(codec, WM8996_MICBIAS_2, | ||
1807 | WM8996_MICB2_MODE, WM8996_MICB2_MODE); | ||
1796 | break; | 1808 | break; |
1797 | 1809 | ||
1798 | case SND_SOC_BIAS_OFF: | 1810 | case SND_SOC_BIAS_OFF: |
diff --git a/sound/soc/codecs/wm9081.c b/sound/soc/codecs/wm9081.c index 076c126ed9b1..9328270df16c 100644 --- a/sound/soc/codecs/wm9081.c +++ b/sound/soc/codecs/wm9081.c | |||
@@ -774,7 +774,7 @@ static const struct snd_soc_dapm_widget wm9081_dapm_widgets[] = { | |||
774 | SND_SOC_DAPM_INPUT("IN1"), | 774 | SND_SOC_DAPM_INPUT("IN1"), |
775 | SND_SOC_DAPM_INPUT("IN2"), | 775 | SND_SOC_DAPM_INPUT("IN2"), |
776 | 776 | ||
777 | SND_SOC_DAPM_DAC("DAC", "HiFi Playback", WM9081_POWER_MANAGEMENT, 0, 0), | 777 | SND_SOC_DAPM_DAC("DAC", NULL, WM9081_POWER_MANAGEMENT, 0, 0), |
778 | 778 | ||
779 | SND_SOC_DAPM_MIXER_NAMED_CTL("Mixer", SND_SOC_NOPM, 0, 0, | 779 | SND_SOC_DAPM_MIXER_NAMED_CTL("Mixer", SND_SOC_NOPM, 0, 0, |
780 | mixer, ARRAY_SIZE(mixer)), | 780 | mixer, ARRAY_SIZE(mixer)), |
@@ -799,6 +799,7 @@ SND_SOC_DAPM_SUPPLY("TSENSE", WM9081_POWER_MANAGEMENT, 7, 0, NULL, 0), | |||
799 | static const struct snd_soc_dapm_route wm9081_audio_paths[] = { | 799 | static const struct snd_soc_dapm_route wm9081_audio_paths[] = { |
800 | { "DAC", NULL, "CLK_SYS" }, | 800 | { "DAC", NULL, "CLK_SYS" }, |
801 | { "DAC", NULL, "CLK_DSP" }, | 801 | { "DAC", NULL, "CLK_DSP" }, |
802 | { "DAC", NULL, "AIF" }, | ||
802 | 803 | ||
803 | { "Mixer", "IN1 Switch", "IN1" }, | 804 | { "Mixer", "IN1 Switch", "IN1" }, |
804 | { "Mixer", "IN2 Switch", "IN2" }, | 805 | { "Mixer", "IN2 Switch", "IN2" }, |
@@ -1252,7 +1253,7 @@ static const struct snd_soc_dai_ops wm9081_dai_ops = { | |||
1252 | static struct snd_soc_dai_driver wm9081_dai = { | 1253 | static struct snd_soc_dai_driver wm9081_dai = { |
1253 | .name = "wm9081-hifi", | 1254 | .name = "wm9081-hifi", |
1254 | .playback = { | 1255 | .playback = { |
1255 | .stream_name = "HiFi Playback", | 1256 | .stream_name = "AIF", |
1256 | .channels_min = 1, | 1257 | .channels_min = 1, |
1257 | .channels_max = 2, | 1258 | .channels_max = 2, |
1258 | .rates = WM9081_RATES, | 1259 | .rates = WM9081_RATES, |
diff --git a/sound/soc/codecs/wm9705.c b/sound/soc/codecs/wm9705.c index cacc6a86b46f..e8e782a0c78d 100644 --- a/sound/soc/codecs/wm9705.c +++ b/sound/soc/codecs/wm9705.c | |||
@@ -236,9 +236,7 @@ static int ac97_write(struct snd_soc_codec *codec, unsigned int reg, | |||
236 | static int ac97_prepare(struct snd_pcm_substream *substream, | 236 | static int ac97_prepare(struct snd_pcm_substream *substream, |
237 | struct snd_soc_dai *dai) | 237 | struct snd_soc_dai *dai) |
238 | { | 238 | { |
239 | struct snd_pcm_runtime *runtime = substream->runtime; | 239 | struct snd_soc_codec *codec = dai->codec; |
240 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
241 | struct snd_soc_codec *codec = rtd->codec; | ||
242 | int reg; | 240 | int reg; |
243 | u16 vra; | 241 | u16 vra; |
244 | 242 | ||
@@ -250,7 +248,7 @@ static int ac97_prepare(struct snd_pcm_substream *substream, | |||
250 | else | 248 | else |
251 | reg = AC97_PCM_LR_ADC_RATE; | 249 | reg = AC97_PCM_LR_ADC_RATE; |
252 | 250 | ||
253 | return ac97_write(codec, reg, runtime->rate); | 251 | return ac97_write(codec, reg, substream->runtime->rate); |
254 | } | 252 | } |
255 | 253 | ||
256 | #define WM9705_AC97_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | \ | 254 | #define WM9705_AC97_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | \ |
diff --git a/sound/soc/codecs/wm9712.c b/sound/soc/codecs/wm9712.c index b342ae50bcd6..a1541414d904 100644 --- a/sound/soc/codecs/wm9712.c +++ b/sound/soc/codecs/wm9712.c | |||
@@ -467,11 +467,10 @@ static int ac97_write(struct snd_soc_codec *codec, unsigned int reg, | |||
467 | static int ac97_prepare(struct snd_pcm_substream *substream, | 467 | static int ac97_prepare(struct snd_pcm_substream *substream, |
468 | struct snd_soc_dai *dai) | 468 | struct snd_soc_dai *dai) |
469 | { | 469 | { |
470 | struct snd_pcm_runtime *runtime = substream->runtime; | 470 | struct snd_soc_codec *codec = dai->codec; |
471 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
472 | struct snd_soc_codec *codec =rtd->codec; | ||
473 | int reg; | 471 | int reg; |
474 | u16 vra; | 472 | u16 vra; |
473 | struct snd_pcm_runtime *runtime = substream->runtime; | ||
475 | 474 | ||
476 | vra = ac97_read(codec, AC97_EXTENDED_STATUS); | 475 | vra = ac97_read(codec, AC97_EXTENDED_STATUS); |
477 | ac97_write(codec, AC97_EXTENDED_STATUS, vra | 0x1); | 476 | ac97_write(codec, AC97_EXTENDED_STATUS, vra | 0x1); |
@@ -487,10 +486,9 @@ static int ac97_prepare(struct snd_pcm_substream *substream, | |||
487 | static int ac97_aux_prepare(struct snd_pcm_substream *substream, | 486 | static int ac97_aux_prepare(struct snd_pcm_substream *substream, |
488 | struct snd_soc_dai *dai) | 487 | struct snd_soc_dai *dai) |
489 | { | 488 | { |
490 | struct snd_pcm_runtime *runtime = substream->runtime; | 489 | struct snd_soc_codec *codec = dai->codec; |
491 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
492 | struct snd_soc_codec *codec = rtd->codec; | ||
493 | u16 vra, xsle; | 490 | u16 vra, xsle; |
491 | struct snd_pcm_runtime *runtime = substream->runtime; | ||
494 | 492 | ||
495 | vra = ac97_read(codec, AC97_EXTENDED_STATUS); | 493 | vra = ac97_read(codec, AC97_EXTENDED_STATUS); |
496 | ac97_write(codec, AC97_EXTENDED_STATUS, vra | 0x1); | 494 | ac97_write(codec, AC97_EXTENDED_STATUS, vra | 0x1); |
diff --git a/sound/soc/codecs/wm_hubs.c b/sound/soc/codecs/wm_hubs.c index 6c028c470601..dfe957a47f29 100644 --- a/sound/soc/codecs/wm_hubs.c +++ b/sound/soc/codecs/wm_hubs.c | |||
@@ -109,12 +109,103 @@ irqreturn_t wm_hubs_dcs_done(int irq, void *data) | |||
109 | } | 109 | } |
110 | EXPORT_SYMBOL_GPL(wm_hubs_dcs_done); | 110 | EXPORT_SYMBOL_GPL(wm_hubs_dcs_done); |
111 | 111 | ||
112 | static bool wm_hubs_dac_hp_direct(struct snd_soc_codec *codec) | ||
113 | { | ||
114 | int reg; | ||
115 | |||
116 | /* If we're going via the mixer we'll need to do additional checks */ | ||
117 | reg = snd_soc_read(codec, WM8993_OUTPUT_MIXER1); | ||
118 | if (!(reg & WM8993_DACL_TO_HPOUT1L)) { | ||
119 | if (reg & ~WM8993_DACL_TO_MIXOUTL) { | ||
120 | dev_vdbg(codec->dev, "Analogue paths connected: %x\n", | ||
121 | reg & ~WM8993_DACL_TO_HPOUT1L); | ||
122 | return false; | ||
123 | } else { | ||
124 | dev_vdbg(codec->dev, "HPL connected to mixer\n"); | ||
125 | } | ||
126 | } else { | ||
127 | dev_vdbg(codec->dev, "HPL connected to DAC\n"); | ||
128 | } | ||
129 | |||
130 | reg = snd_soc_read(codec, WM8993_OUTPUT_MIXER2); | ||
131 | if (!(reg & WM8993_DACR_TO_HPOUT1R)) { | ||
132 | if (reg & ~WM8993_DACR_TO_MIXOUTR) { | ||
133 | dev_vdbg(codec->dev, "Analogue paths connected: %x\n", | ||
134 | reg & ~WM8993_DACR_TO_HPOUT1R); | ||
135 | return false; | ||
136 | } else { | ||
137 | dev_vdbg(codec->dev, "HPR connected to mixer\n"); | ||
138 | } | ||
139 | } else { | ||
140 | dev_vdbg(codec->dev, "HPR connected to DAC\n"); | ||
141 | } | ||
142 | |||
143 | return true; | ||
144 | } | ||
145 | |||
146 | struct wm_hubs_dcs_cache { | ||
147 | struct list_head list; | ||
148 | unsigned int left; | ||
149 | unsigned int right; | ||
150 | u16 dcs_cfg; | ||
151 | }; | ||
152 | |||
153 | static bool wm_hubs_dcs_cache_get(struct snd_soc_codec *codec, | ||
154 | struct wm_hubs_dcs_cache **entry) | ||
155 | { | ||
156 | struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec); | ||
157 | struct wm_hubs_dcs_cache *cache; | ||
158 | unsigned int left, right; | ||
159 | |||
160 | left = snd_soc_read(codec, WM8993_LEFT_OUTPUT_VOLUME); | ||
161 | left &= WM8993_HPOUT1L_VOL_MASK; | ||
162 | |||
163 | right = snd_soc_read(codec, WM8993_RIGHT_OUTPUT_VOLUME); | ||
164 | right &= WM8993_HPOUT1R_VOL_MASK; | ||
165 | |||
166 | list_for_each_entry(cache, &hubs->dcs_cache, list) { | ||
167 | if (cache->left != left || cache->right != right) | ||
168 | continue; | ||
169 | |||
170 | *entry = cache; | ||
171 | return true; | ||
172 | } | ||
173 | |||
174 | return false; | ||
175 | } | ||
176 | |||
177 | static void wm_hubs_dcs_cache_set(struct snd_soc_codec *codec, u16 dcs_cfg) | ||
178 | { | ||
179 | struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec); | ||
180 | struct wm_hubs_dcs_cache *cache; | ||
181 | |||
182 | if (hubs->no_cache_dac_hp_direct) | ||
183 | return; | ||
184 | |||
185 | cache = devm_kzalloc(codec->dev, sizeof(*cache), GFP_KERNEL); | ||
186 | if (!cache) { | ||
187 | dev_err(codec->dev, "Failed to allocate DCS cache entry\n"); | ||
188 | return; | ||
189 | } | ||
190 | |||
191 | cache->left = snd_soc_read(codec, WM8993_LEFT_OUTPUT_VOLUME); | ||
192 | cache->left &= WM8993_HPOUT1L_VOL_MASK; | ||
193 | |||
194 | cache->right = snd_soc_read(codec, WM8993_RIGHT_OUTPUT_VOLUME); | ||
195 | cache->right &= WM8993_HPOUT1R_VOL_MASK; | ||
196 | |||
197 | cache->dcs_cfg = dcs_cfg; | ||
198 | |||
199 | list_add_tail(&cache->list, &hubs->dcs_cache); | ||
200 | } | ||
201 | |||
112 | /* | 202 | /* |
113 | * Startup calibration of the DC servo | 203 | * Startup calibration of the DC servo |
114 | */ | 204 | */ |
115 | static void calibrate_dc_servo(struct snd_soc_codec *codec) | 205 | static void calibrate_dc_servo(struct snd_soc_codec *codec) |
116 | { | 206 | { |
117 | struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec); | 207 | struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec); |
208 | struct wm_hubs_dcs_cache *cache; | ||
118 | s8 offset; | 209 | s8 offset; |
119 | u16 reg, reg_l, reg_r, dcs_cfg, dcs_reg; | 210 | u16 reg, reg_l, reg_r, dcs_cfg, dcs_reg; |
120 | 211 | ||
@@ -129,10 +220,11 @@ static void calibrate_dc_servo(struct snd_soc_codec *codec) | |||
129 | 220 | ||
130 | /* If we're using a digital only path and have a previously | 221 | /* If we're using a digital only path and have a previously |
131 | * callibrated DC servo offset stored then use that. */ | 222 | * callibrated DC servo offset stored then use that. */ |
132 | if (hubs->class_w && hubs->class_w_dcs) { | 223 | if (wm_hubs_dac_hp_direct(codec) && |
133 | dev_dbg(codec->dev, "Using cached DC servo offset %x\n", | 224 | wm_hubs_dcs_cache_get(codec, &cache)) { |
134 | hubs->class_w_dcs); | 225 | dev_dbg(codec->dev, "Using cached DCS offset %x for %d,%d\n", |
135 | snd_soc_write(codec, dcs_reg, hubs->class_w_dcs); | 226 | cache->dcs_cfg, cache->left, cache->right); |
227 | snd_soc_write(codec, dcs_reg, cache->dcs_cfg); | ||
136 | wait_for_dc_servo(codec, | 228 | wait_for_dc_servo(codec, |
137 | WM8993_DCS_TRIG_DAC_WR_0 | | 229 | WM8993_DCS_TRIG_DAC_WR_0 | |
138 | WM8993_DCS_TRIG_DAC_WR_1); | 230 | WM8993_DCS_TRIG_DAC_WR_1); |
@@ -207,8 +299,8 @@ static void calibrate_dc_servo(struct snd_soc_codec *codec) | |||
207 | 299 | ||
208 | /* Save the callibrated offset if we're in class W mode and | 300 | /* Save the callibrated offset if we're in class W mode and |
209 | * therefore don't have any analogue signal mixed in. */ | 301 | * therefore don't have any analogue signal mixed in. */ |
210 | if (hubs->class_w && !hubs->no_cache_class_w) | 302 | if (wm_hubs_dac_hp_direct(codec)) |
211 | hubs->class_w_dcs = dcs_cfg; | 303 | wm_hubs_dcs_cache_set(codec, dcs_cfg); |
212 | } | 304 | } |
213 | 305 | ||
214 | /* | 306 | /* |
@@ -223,9 +315,6 @@ static int wm8993_put_dc_servo(struct snd_kcontrol *kcontrol, | |||
223 | 315 | ||
224 | ret = snd_soc_put_volsw(kcontrol, ucontrol); | 316 | ret = snd_soc_put_volsw(kcontrol, ucontrol); |
225 | 317 | ||
226 | /* Updating the analogue gains invalidates the DC servo cache */ | ||
227 | hubs->class_w_dcs = 0; | ||
228 | |||
229 | /* If we're applying an offset correction then updating the | 318 | /* If we're applying an offset correction then updating the |
230 | * callibration would be likely to introduce further offsets. */ | 319 | * callibration would be likely to introduce further offsets. */ |
231 | if (hubs->dcs_codes_l || hubs->dcs_codes_r || hubs->no_series_update) | 320 | if (hubs->dcs_codes_l || hubs->dcs_codes_r || hubs->no_series_update) |
@@ -530,6 +619,86 @@ static int lineout_event(struct snd_soc_dapm_widget *w, | |||
530 | return 0; | 619 | return 0; |
531 | } | 620 | } |
532 | 621 | ||
622 | void wm_hubs_update_class_w(struct snd_soc_codec *codec) | ||
623 | { | ||
624 | struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec); | ||
625 | int enable = WM8993_CP_DYN_V | WM8993_CP_DYN_FREQ; | ||
626 | |||
627 | if (!wm_hubs_dac_hp_direct(codec)) | ||
628 | enable = false; | ||
629 | |||
630 | if (hubs->check_class_w_digital && !hubs->check_class_w_digital(codec)) | ||
631 | enable = false; | ||
632 | |||
633 | dev_vdbg(codec->dev, "Class W %s\n", enable ? "enabled" : "disabled"); | ||
634 | |||
635 | snd_soc_update_bits(codec, WM8993_CLASS_W_0, | ||
636 | WM8993_CP_DYN_V | WM8993_CP_DYN_FREQ, enable); | ||
637 | } | ||
638 | EXPORT_SYMBOL_GPL(wm_hubs_update_class_w); | ||
639 | |||
640 | #define WM_HUBS_SINGLE_W(xname, reg, shift, max, invert) \ | ||
641 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ | ||
642 | .info = snd_soc_info_volsw, \ | ||
643 | .get = snd_soc_dapm_get_volsw, .put = class_w_put_volsw, \ | ||
644 | .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert) } | ||
645 | |||
646 | static int class_w_put_volsw(struct snd_kcontrol *kcontrol, | ||
647 | struct snd_ctl_elem_value *ucontrol) | ||
648 | { | ||
649 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); | ||
650 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; | ||
651 | struct snd_soc_codec *codec = widget->codec; | ||
652 | int ret; | ||
653 | |||
654 | ret = snd_soc_dapm_put_volsw(kcontrol, ucontrol); | ||
655 | |||
656 | wm_hubs_update_class_w(codec); | ||
657 | |||
658 | return ret; | ||
659 | } | ||
660 | |||
661 | #define WM_HUBS_ENUM_W(xname, xenum) \ | ||
662 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ | ||
663 | .info = snd_soc_info_enum_double, \ | ||
664 | .get = snd_soc_dapm_get_enum_double, \ | ||
665 | .put = class_w_put_double, \ | ||
666 | .private_value = (unsigned long)&xenum } | ||
667 | |||
668 | static int class_w_put_double(struct snd_kcontrol *kcontrol, | ||
669 | struct snd_ctl_elem_value *ucontrol) | ||
670 | { | ||
671 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); | ||
672 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; | ||
673 | struct snd_soc_codec *codec = widget->codec; | ||
674 | int ret; | ||
675 | |||
676 | ret = snd_soc_dapm_put_enum_double(kcontrol, ucontrol); | ||
677 | |||
678 | wm_hubs_update_class_w(codec); | ||
679 | |||
680 | return ret; | ||
681 | } | ||
682 | |||
683 | static const char *hp_mux_text[] = { | ||
684 | "Mixer", | ||
685 | "DAC", | ||
686 | }; | ||
687 | |||
688 | static const struct soc_enum hpl_enum = | ||
689 | SOC_ENUM_SINGLE(WM8993_OUTPUT_MIXER1, 8, 2, hp_mux_text); | ||
690 | |||
691 | const struct snd_kcontrol_new wm_hubs_hpl_mux = | ||
692 | WM_HUBS_ENUM_W("Left Headphone Mux", hpl_enum); | ||
693 | EXPORT_SYMBOL_GPL(wm_hubs_hpl_mux); | ||
694 | |||
695 | static const struct soc_enum hpr_enum = | ||
696 | SOC_ENUM_SINGLE(WM8993_OUTPUT_MIXER2, 8, 2, hp_mux_text); | ||
697 | |||
698 | const struct snd_kcontrol_new wm_hubs_hpr_mux = | ||
699 | WM_HUBS_ENUM_W("Right Headphone Mux", hpr_enum); | ||
700 | EXPORT_SYMBOL_GPL(wm_hubs_hpr_mux); | ||
701 | |||
533 | static const struct snd_kcontrol_new in1l_pga[] = { | 702 | static const struct snd_kcontrol_new in1l_pga[] = { |
534 | SOC_DAPM_SINGLE("IN1LP Switch", WM8993_INPUT_MIXER2, 5, 1, 0), | 703 | SOC_DAPM_SINGLE("IN1LP Switch", WM8993_INPUT_MIXER2, 5, 1, 0), |
535 | SOC_DAPM_SINGLE("IN1LN Switch", WM8993_INPUT_MIXER2, 4, 1, 0), | 704 | SOC_DAPM_SINGLE("IN1LN Switch", WM8993_INPUT_MIXER2, 4, 1, 0), |
@@ -561,25 +730,25 @@ SOC_DAPM_SINGLE("IN1R Switch", WM8993_INPUT_MIXER4, 5, 1, 0), | |||
561 | }; | 730 | }; |
562 | 731 | ||
563 | static const struct snd_kcontrol_new left_output_mixer[] = { | 732 | static const struct snd_kcontrol_new left_output_mixer[] = { |
564 | SOC_DAPM_SINGLE("Right Input Switch", WM8993_OUTPUT_MIXER1, 7, 1, 0), | 733 | WM_HUBS_SINGLE_W("Right Input Switch", WM8993_OUTPUT_MIXER1, 7, 1, 0), |
565 | SOC_DAPM_SINGLE("Left Input Switch", WM8993_OUTPUT_MIXER1, 6, 1, 0), | 734 | WM_HUBS_SINGLE_W("Left Input Switch", WM8993_OUTPUT_MIXER1, 6, 1, 0), |
566 | SOC_DAPM_SINGLE("IN2RN Switch", WM8993_OUTPUT_MIXER1, 5, 1, 0), | 735 | WM_HUBS_SINGLE_W("IN2RN Switch", WM8993_OUTPUT_MIXER1, 5, 1, 0), |
567 | SOC_DAPM_SINGLE("IN2LN Switch", WM8993_OUTPUT_MIXER1, 4, 1, 0), | 736 | WM_HUBS_SINGLE_W("IN2LN Switch", WM8993_OUTPUT_MIXER1, 4, 1, 0), |
568 | SOC_DAPM_SINGLE("IN2LP Switch", WM8993_OUTPUT_MIXER1, 1, 1, 0), | 737 | WM_HUBS_SINGLE_W("IN2LP Switch", WM8993_OUTPUT_MIXER1, 1, 1, 0), |
569 | SOC_DAPM_SINGLE("IN1R Switch", WM8993_OUTPUT_MIXER1, 3, 1, 0), | 738 | WM_HUBS_SINGLE_W("IN1R Switch", WM8993_OUTPUT_MIXER1, 3, 1, 0), |
570 | SOC_DAPM_SINGLE("IN1L Switch", WM8993_OUTPUT_MIXER1, 2, 1, 0), | 739 | WM_HUBS_SINGLE_W("IN1L Switch", WM8993_OUTPUT_MIXER1, 2, 1, 0), |
571 | SOC_DAPM_SINGLE("DAC Switch", WM8993_OUTPUT_MIXER1, 0, 1, 0), | 740 | WM_HUBS_SINGLE_W("DAC Switch", WM8993_OUTPUT_MIXER1, 0, 1, 0), |
572 | }; | 741 | }; |
573 | 742 | ||
574 | static const struct snd_kcontrol_new right_output_mixer[] = { | 743 | static const struct snd_kcontrol_new right_output_mixer[] = { |
575 | SOC_DAPM_SINGLE("Left Input Switch", WM8993_OUTPUT_MIXER2, 7, 1, 0), | 744 | WM_HUBS_SINGLE_W("Left Input Switch", WM8993_OUTPUT_MIXER2, 7, 1, 0), |
576 | SOC_DAPM_SINGLE("Right Input Switch", WM8993_OUTPUT_MIXER2, 6, 1, 0), | 745 | WM_HUBS_SINGLE_W("Right Input Switch", WM8993_OUTPUT_MIXER2, 6, 1, 0), |
577 | SOC_DAPM_SINGLE("IN2LN Switch", WM8993_OUTPUT_MIXER2, 5, 1, 0), | 746 | WM_HUBS_SINGLE_W("IN2LN Switch", WM8993_OUTPUT_MIXER2, 5, 1, 0), |
578 | SOC_DAPM_SINGLE("IN2RN Switch", WM8993_OUTPUT_MIXER2, 4, 1, 0), | 747 | WM_HUBS_SINGLE_W("IN2RN Switch", WM8993_OUTPUT_MIXER2, 4, 1, 0), |
579 | SOC_DAPM_SINGLE("IN1L Switch", WM8993_OUTPUT_MIXER2, 3, 1, 0), | 748 | WM_HUBS_SINGLE_W("IN1L Switch", WM8993_OUTPUT_MIXER2, 3, 1, 0), |
580 | SOC_DAPM_SINGLE("IN1R Switch", WM8993_OUTPUT_MIXER2, 2, 1, 0), | 749 | WM_HUBS_SINGLE_W("IN1R Switch", WM8993_OUTPUT_MIXER2, 2, 1, 0), |
581 | SOC_DAPM_SINGLE("IN2RP Switch", WM8993_OUTPUT_MIXER2, 1, 1, 0), | 750 | WM_HUBS_SINGLE_W("IN2RP Switch", WM8993_OUTPUT_MIXER2, 1, 1, 0), |
582 | SOC_DAPM_SINGLE("DAC Switch", WM8993_OUTPUT_MIXER2, 0, 1, 0), | 751 | WM_HUBS_SINGLE_W("DAC Switch", WM8993_OUTPUT_MIXER2, 0, 1, 0), |
583 | }; | 752 | }; |
584 | 753 | ||
585 | static const struct snd_kcontrol_new earpiece_mixer[] = { | 754 | static const struct snd_kcontrol_new earpiece_mixer[] = { |
@@ -943,6 +1112,7 @@ int wm_hubs_add_analogue_routes(struct snd_soc_codec *codec, | |||
943 | struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec); | 1112 | struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec); |
944 | struct snd_soc_dapm_context *dapm = &codec->dapm; | 1113 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
945 | 1114 | ||
1115 | INIT_LIST_HEAD(&hubs->dcs_cache); | ||
946 | init_completion(&hubs->dcs_done); | 1116 | init_completion(&hubs->dcs_done); |
947 | 1117 | ||
948 | snd_soc_dapm_add_routes(dapm, analogue_routes, | 1118 | snd_soc_dapm_add_routes(dapm, analogue_routes, |
diff --git a/sound/soc/codecs/wm_hubs.h b/sound/soc/codecs/wm_hubs.h index 5705276f4943..da2dc899ce6d 100644 --- a/sound/soc/codecs/wm_hubs.h +++ b/sound/soc/codecs/wm_hubs.h | |||
@@ -16,6 +16,8 @@ | |||
16 | 16 | ||
17 | #include <linux/completion.h> | 17 | #include <linux/completion.h> |
18 | #include <linux/interrupt.h> | 18 | #include <linux/interrupt.h> |
19 | #include <linux/list.h> | ||
20 | #include <sound/control.h> | ||
19 | 21 | ||
20 | struct snd_soc_codec; | 22 | struct snd_soc_codec; |
21 | 23 | ||
@@ -30,9 +32,9 @@ struct wm_hubs_data { | |||
30 | int series_startup; | 32 | int series_startup; |
31 | int no_series_update; | 33 | int no_series_update; |
32 | 34 | ||
33 | bool no_cache_class_w; | 35 | bool no_cache_dac_hp_direct; |
34 | bool class_w; | 36 | struct list_head dcs_cache; |
35 | u16 class_w_dcs; | 37 | bool (*check_class_w_digital)(struct snd_soc_codec *); |
36 | 38 | ||
37 | bool lineout1_se; | 39 | bool lineout1_se; |
38 | bool lineout1n_ena; | 40 | bool lineout1n_ena; |
@@ -58,5 +60,9 @@ extern irqreturn_t wm_hubs_dcs_done(int irq, void *data); | |||
58 | extern void wm_hubs_vmid_ena(struct snd_soc_codec *codec); | 60 | extern void wm_hubs_vmid_ena(struct snd_soc_codec *codec); |
59 | extern void wm_hubs_set_bias_level(struct snd_soc_codec *codec, | 61 | extern void wm_hubs_set_bias_level(struct snd_soc_codec *codec, |
60 | enum snd_soc_bias_level level); | 62 | enum snd_soc_bias_level level); |
63 | extern void wm_hubs_update_class_w(struct snd_soc_codec *codec); | ||
64 | |||
65 | extern const struct snd_kcontrol_new wm_hubs_hpl_mux; | ||
66 | extern const struct snd_kcontrol_new wm_hubs_hpr_mux; | ||
61 | 67 | ||
62 | #endif | 68 | #endif |
diff --git a/sound/soc/ep93xx/ep93xx-ac97.c b/sound/soc/ep93xx/ep93xx-ac97.c index 0678637abd66..bdffab33e160 100644 --- a/sound/soc/ep93xx/ep93xx-ac97.c +++ b/sound/soc/ep93xx/ep93xx-ac97.c | |||
@@ -87,17 +87,13 @@ | |||
87 | * struct ep93xx_ac97_info - EP93xx AC97 controller info structure | 87 | * struct ep93xx_ac97_info - EP93xx AC97 controller info structure |
88 | * @lock: mutex serializing access to the bus (slot 1 & 2 ops) | 88 | * @lock: mutex serializing access to the bus (slot 1 & 2 ops) |
89 | * @dev: pointer to the platform device dev structure | 89 | * @dev: pointer to the platform device dev structure |
90 | * @mem: physical memory resource for the registers | ||
91 | * @regs: mapped AC97 controller registers | 90 | * @regs: mapped AC97 controller registers |
92 | * @irq: AC97 interrupt number | ||
93 | * @done: bus ops wait here for an interrupt | 91 | * @done: bus ops wait here for an interrupt |
94 | */ | 92 | */ |
95 | struct ep93xx_ac97_info { | 93 | struct ep93xx_ac97_info { |
96 | struct mutex lock; | 94 | struct mutex lock; |
97 | struct device *dev; | 95 | struct device *dev; |
98 | struct resource *mem; | ||
99 | void __iomem *regs; | 96 | void __iomem *regs; |
100 | int irq; | ||
101 | struct completion done; | 97 | struct completion done; |
102 | }; | 98 | }; |
103 | 99 | ||
@@ -359,66 +355,50 @@ static struct snd_soc_dai_driver ep93xx_ac97_dai = { | |||
359 | static int __devinit ep93xx_ac97_probe(struct platform_device *pdev) | 355 | static int __devinit ep93xx_ac97_probe(struct platform_device *pdev) |
360 | { | 356 | { |
361 | struct ep93xx_ac97_info *info; | 357 | struct ep93xx_ac97_info *info; |
358 | struct resource *res; | ||
359 | unsigned int irq; | ||
362 | int ret; | 360 | int ret; |
363 | 361 | ||
364 | info = kzalloc(sizeof(struct ep93xx_ac97_info), GFP_KERNEL); | 362 | info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); |
365 | if (!info) | 363 | if (!info) |
366 | return -ENOMEM; | 364 | return -ENOMEM; |
367 | 365 | ||
368 | dev_set_drvdata(&pdev->dev, info); | 366 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
369 | 367 | if (!res) | |
370 | mutex_init(&info->lock); | 368 | return -ENODEV; |
371 | init_completion(&info->done); | ||
372 | info->dev = &pdev->dev; | ||
373 | 369 | ||
374 | info->mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 370 | info->regs = devm_request_and_ioremap(&pdev->dev, res); |
375 | if (!info->mem) { | 371 | if (!info->regs) |
376 | ret = -ENXIO; | 372 | return -ENXIO; |
377 | goto fail_free_info; | ||
378 | } | ||
379 | 373 | ||
380 | info->irq = platform_get_irq(pdev, 0); | 374 | irq = platform_get_irq(pdev, 0); |
381 | if (!info->irq) { | 375 | if (!irq) |
382 | ret = -ENXIO; | 376 | return -ENODEV; |
383 | goto fail_free_info; | ||
384 | } | ||
385 | 377 | ||
386 | if (!request_mem_region(info->mem->start, resource_size(info->mem), | 378 | ret = devm_request_irq(&pdev->dev, irq, ep93xx_ac97_interrupt, |
387 | pdev->name)) { | 379 | IRQF_TRIGGER_HIGH, pdev->name, info); |
388 | ret = -EBUSY; | 380 | if (ret) |
389 | goto fail_free_info; | 381 | goto fail; |
390 | } | ||
391 | 382 | ||
392 | info->regs = ioremap(info->mem->start, resource_size(info->mem)); | 383 | dev_set_drvdata(&pdev->dev, info); |
393 | if (!info->regs) { | ||
394 | ret = -ENOMEM; | ||
395 | goto fail_release_mem; | ||
396 | } | ||
397 | 384 | ||
398 | ret = request_irq(info->irq, ep93xx_ac97_interrupt, IRQF_TRIGGER_HIGH, | 385 | mutex_init(&info->lock); |
399 | pdev->name, info); | 386 | init_completion(&info->done); |
400 | if (ret) | 387 | info->dev = &pdev->dev; |
401 | goto fail_unmap_mem; | ||
402 | 388 | ||
403 | ep93xx_ac97_info = info; | 389 | ep93xx_ac97_info = info; |
404 | platform_set_drvdata(pdev, info); | 390 | platform_set_drvdata(pdev, info); |
405 | 391 | ||
406 | ret = snd_soc_register_dai(&pdev->dev, &ep93xx_ac97_dai); | 392 | ret = snd_soc_register_dai(&pdev->dev, &ep93xx_ac97_dai); |
407 | if (ret) | 393 | if (ret) |
408 | goto fail_free_irq; | 394 | goto fail; |
409 | 395 | ||
410 | return 0; | 396 | return 0; |
411 | 397 | ||
412 | fail_free_irq: | 398 | fail: |
413 | platform_set_drvdata(pdev, NULL); | 399 | platform_set_drvdata(pdev, NULL); |
414 | free_irq(info->irq, info); | 400 | ep93xx_ac97_info = NULL; |
415 | fail_unmap_mem: | 401 | dev_set_drvdata(&pdev->dev, NULL); |
416 | iounmap(info->regs); | ||
417 | fail_release_mem: | ||
418 | release_mem_region(info->mem->start, resource_size(info->mem)); | ||
419 | fail_free_info: | ||
420 | kfree(info); | ||
421 | |||
422 | return ret; | 402 | return ret; |
423 | } | 403 | } |
424 | 404 | ||
@@ -431,11 +411,9 @@ static int __devexit ep93xx_ac97_remove(struct platform_device *pdev) | |||
431 | /* disable the AC97 controller */ | 411 | /* disable the AC97 controller */ |
432 | ep93xx_ac97_write_reg(info, AC97GCR, 0); | 412 | ep93xx_ac97_write_reg(info, AC97GCR, 0); |
433 | 413 | ||
434 | free_irq(info->irq, info); | ||
435 | iounmap(info->regs); | ||
436 | release_mem_region(info->mem->start, resource_size(info->mem)); | ||
437 | platform_set_drvdata(pdev, NULL); | 414 | platform_set_drvdata(pdev, NULL); |
438 | kfree(info); | 415 | ep93xx_ac97_info = NULL; |
416 | dev_set_drvdata(&pdev->dev, NULL); | ||
439 | 417 | ||
440 | return 0; | 418 | return 0; |
441 | } | 419 | } |
diff --git a/sound/soc/ep93xx/ep93xx-i2s.c b/sound/soc/ep93xx/ep93xx-i2s.c index f7a62348e3fe..8df8f6dc474f 100644 --- a/sound/soc/ep93xx/ep93xx-i2s.c +++ b/sound/soc/ep93xx/ep93xx-i2s.c | |||
@@ -63,7 +63,6 @@ struct ep93xx_i2s_info { | |||
63 | struct clk *sclk; | 63 | struct clk *sclk; |
64 | struct clk *lrclk; | 64 | struct clk *lrclk; |
65 | struct ep93xx_pcm_dma_params *dma_params; | 65 | struct ep93xx_pcm_dma_params *dma_params; |
66 | struct resource *mem; | ||
67 | void __iomem *regs; | 66 | void __iomem *regs; |
68 | }; | 67 | }; |
69 | 68 | ||
@@ -373,38 +372,22 @@ static int ep93xx_i2s_probe(struct platform_device *pdev) | |||
373 | struct resource *res; | 372 | struct resource *res; |
374 | int err; | 373 | int err; |
375 | 374 | ||
376 | info = kzalloc(sizeof(struct ep93xx_i2s_info), GFP_KERNEL); | 375 | info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); |
377 | if (!info) { | 376 | if (!info) |
378 | err = -ENOMEM; | 377 | return -ENOMEM; |
379 | goto fail; | ||
380 | } | ||
381 | |||
382 | dev_set_drvdata(&pdev->dev, info); | ||
383 | info->dma_params = ep93xx_i2s_dma_params; | ||
384 | 378 | ||
385 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 379 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
386 | if (!res) { | 380 | if (!res) |
387 | err = -ENODEV; | 381 | return -ENODEV; |
388 | goto fail_free_info; | ||
389 | } | ||
390 | 382 | ||
391 | info->mem = request_mem_region(res->start, resource_size(res), | 383 | info->regs = devm_request_and_ioremap(&pdev->dev, res); |
392 | pdev->name); | 384 | if (!info->regs) |
393 | if (!info->mem) { | 385 | return -ENXIO; |
394 | err = -EBUSY; | ||
395 | goto fail_free_info; | ||
396 | } | ||
397 | |||
398 | info->regs = ioremap(info->mem->start, resource_size(info->mem)); | ||
399 | if (!info->regs) { | ||
400 | err = -ENXIO; | ||
401 | goto fail_release_mem; | ||
402 | } | ||
403 | 386 | ||
404 | info->mclk = clk_get(&pdev->dev, "mclk"); | 387 | info->mclk = clk_get(&pdev->dev, "mclk"); |
405 | if (IS_ERR(info->mclk)) { | 388 | if (IS_ERR(info->mclk)) { |
406 | err = PTR_ERR(info->mclk); | 389 | err = PTR_ERR(info->mclk); |
407 | goto fail_unmap_mem; | 390 | goto fail; |
408 | } | 391 | } |
409 | 392 | ||
410 | info->sclk = clk_get(&pdev->dev, "sclk"); | 393 | info->sclk = clk_get(&pdev->dev, "sclk"); |
@@ -419,6 +402,9 @@ static int ep93xx_i2s_probe(struct platform_device *pdev) | |||
419 | goto fail_put_sclk; | 402 | goto fail_put_sclk; |
420 | } | 403 | } |
421 | 404 | ||
405 | dev_set_drvdata(&pdev->dev, info); | ||
406 | info->dma_params = ep93xx_i2s_dma_params; | ||
407 | |||
422 | err = snd_soc_register_dai(&pdev->dev, &ep93xx_i2s_dai); | 408 | err = snd_soc_register_dai(&pdev->dev, &ep93xx_i2s_dai); |
423 | if (err) | 409 | if (err) |
424 | goto fail_put_lrclk; | 410 | goto fail_put_lrclk; |
@@ -426,17 +412,12 @@ static int ep93xx_i2s_probe(struct platform_device *pdev) | |||
426 | return 0; | 412 | return 0; |
427 | 413 | ||
428 | fail_put_lrclk: | 414 | fail_put_lrclk: |
415 | dev_set_drvdata(&pdev->dev, NULL); | ||
429 | clk_put(info->lrclk); | 416 | clk_put(info->lrclk); |
430 | fail_put_sclk: | 417 | fail_put_sclk: |
431 | clk_put(info->sclk); | 418 | clk_put(info->sclk); |
432 | fail_put_mclk: | 419 | fail_put_mclk: |
433 | clk_put(info->mclk); | 420 | clk_put(info->mclk); |
434 | fail_unmap_mem: | ||
435 | iounmap(info->regs); | ||
436 | fail_release_mem: | ||
437 | release_mem_region(info->mem->start, resource_size(info->mem)); | ||
438 | fail_free_info: | ||
439 | kfree(info); | ||
440 | fail: | 421 | fail: |
441 | return err; | 422 | return err; |
442 | } | 423 | } |
@@ -446,12 +427,10 @@ static int __devexit ep93xx_i2s_remove(struct platform_device *pdev) | |||
446 | struct ep93xx_i2s_info *info = dev_get_drvdata(&pdev->dev); | 427 | struct ep93xx_i2s_info *info = dev_get_drvdata(&pdev->dev); |
447 | 428 | ||
448 | snd_soc_unregister_dai(&pdev->dev); | 429 | snd_soc_unregister_dai(&pdev->dev); |
430 | dev_set_drvdata(&pdev->dev, NULL); | ||
449 | clk_put(info->lrclk); | 431 | clk_put(info->lrclk); |
450 | clk_put(info->sclk); | 432 | clk_put(info->sclk); |
451 | clk_put(info->mclk); | 433 | clk_put(info->mclk); |
452 | iounmap(info->regs); | ||
453 | release_mem_region(info->mem->start, resource_size(info->mem)); | ||
454 | kfree(info); | ||
455 | return 0; | 434 | return 0; |
456 | } | 435 | } |
457 | 436 | ||
diff --git a/sound/soc/fsl/Kconfig b/sound/soc/fsl/Kconfig index d754d34d68a6..d70133086ac3 100644 --- a/sound/soc/fsl/Kconfig +++ b/sound/soc/fsl/Kconfig | |||
@@ -1,18 +1,31 @@ | |||
1 | config SND_MPC52xx_DMA | 1 | config SND_SOC_FSL_SSI |
2 | tristate | 2 | tristate |
3 | 3 | ||
4 | # ASoC platform support for the Freescale PowerPC SOCs that have an SSI and | 4 | config SND_SOC_FSL_UTILS |
5 | # an Elo DMA controller, such as the MPC8610 and P1022. You will still need to | ||
6 | # select a platform driver and a codec driver. | ||
7 | config SND_SOC_POWERPC_SSI | ||
8 | tristate | 5 | tristate |
6 | |||
7 | menuconfig SND_POWERPC_SOC | ||
8 | tristate "SoC Audio for Freescale PowerPC CPUs" | ||
9 | depends on FSL_SOC | 9 | depends on FSL_SOC |
10 | help | ||
11 | Say Y or M if you want to add support for codecs attached to | ||
12 | the PowerPC CPUs. | ||
13 | |||
14 | if SND_POWERPC_SOC | ||
15 | |||
16 | config SND_MPC52xx_DMA | ||
17 | tristate | ||
18 | |||
19 | config SND_SOC_POWERPC_DMA | ||
20 | tristate | ||
10 | 21 | ||
11 | config SND_SOC_MPC8610_HPCD | 22 | config SND_SOC_MPC8610_HPCD |
12 | tristate "ALSA SoC support for the Freescale MPC8610 HPCD board" | 23 | tristate "ALSA SoC support for the Freescale MPC8610 HPCD board" |
13 | # I2C is necessary for the CS4270 driver | 24 | # I2C is necessary for the CS4270 driver |
14 | depends on MPC8610_HPCD && I2C | 25 | depends on MPC8610_HPCD && I2C |
15 | select SND_SOC_POWERPC_SSI | 26 | select SND_SOC_FSL_SSI |
27 | select SND_SOC_FSL_UTILS | ||
28 | select SND_SOC_POWERPC_DMA | ||
16 | select SND_SOC_CS4270 | 29 | select SND_SOC_CS4270 |
17 | select SND_SOC_CS4270_VD33_ERRATA | 30 | select SND_SOC_CS4270_VD33_ERRATA |
18 | default y if MPC8610_HPCD | 31 | default y if MPC8610_HPCD |
@@ -23,7 +36,9 @@ config SND_SOC_P1022_DS | |||
23 | tristate "ALSA SoC support for the Freescale P1022 DS board" | 36 | tristate "ALSA SoC support for the Freescale P1022 DS board" |
24 | # I2C is necessary for the WM8776 driver | 37 | # I2C is necessary for the WM8776 driver |
25 | depends on P1022_DS && I2C | 38 | depends on P1022_DS && I2C |
26 | select SND_SOC_POWERPC_SSI | 39 | select SND_SOC_FSL_SSI |
40 | select SND_SOC_FSL_UTILS | ||
41 | select SND_SOC_POWERPC_DMA | ||
27 | select SND_SOC_WM8776 | 42 | select SND_SOC_WM8776 |
28 | default y if P1022_DS | 43 | default y if P1022_DS |
29 | help | 44 | help |
@@ -65,3 +80,103 @@ config SND_MPC52xx_SOC_EFIKA | |||
65 | help | 80 | help |
66 | Say Y if you want to add support for sound on the Efika. | 81 | Say Y if you want to add support for sound on the Efika. |
67 | 82 | ||
83 | endif # SND_POWERPC_SOC | ||
84 | |||
85 | menuconfig SND_IMX_SOC | ||
86 | tristate "SoC Audio for Freescale i.MX CPUs" | ||
87 | depends on ARCH_MXC | ||
88 | help | ||
89 | Say Y or M if you want to add support for codecs attached to | ||
90 | the i.MX CPUs. | ||
91 | |||
92 | if SND_IMX_SOC | ||
93 | |||
94 | config SND_SOC_IMX_SSI | ||
95 | tristate | ||
96 | |||
97 | config SND_SOC_IMX_PCM | ||
98 | tristate | ||
99 | |||
100 | config SND_SOC_IMX_PCM_FIQ | ||
101 | tristate | ||
102 | select FIQ | ||
103 | select SND_SOC_IMX_PCM | ||
104 | |||
105 | config SND_SOC_IMX_PCM_DMA | ||
106 | tristate | ||
107 | select SND_SOC_DMAENGINE_PCM | ||
108 | select SND_SOC_IMX_PCM | ||
109 | |||
110 | config SND_SOC_IMX_AUDMUX | ||
111 | tristate | ||
112 | |||
113 | config SND_MXC_SOC_WM1133_EV1 | ||
114 | tristate "Audio on the i.MX31ADS with WM1133-EV1 fitted" | ||
115 | depends on MACH_MX31ADS_WM1133_EV1 && EXPERIMENTAL | ||
116 | select SND_SOC_WM8350 | ||
117 | select SND_SOC_IMX_PCM_FIQ | ||
118 | select SND_SOC_IMX_AUDMUX | ||
119 | select SND_SOC_IMX_SSI | ||
120 | help | ||
121 | Enable support for audio on the i.MX31ADS with the WM1133-EV1 | ||
122 | PMIC board with WM8835x fitted. | ||
123 | |||
124 | config SND_SOC_MX27VIS_AIC32X4 | ||
125 | tristate "SoC audio support for Visstrim M10 boards" | ||
126 | depends on MACH_IMX27_VISSTRIM_M10 && I2C | ||
127 | select SND_SOC_TLV320AIC32X4 | ||
128 | select SND_SOC_IMX_PCM_DMA | ||
129 | select SND_SOC_IMX_AUDMUX | ||
130 | select SND_SOC_IMX_SSI | ||
131 | help | ||
132 | Say Y if you want to add support for SoC audio on Visstrim SM10 | ||
133 | board with TLV320AIC32X4 codec. | ||
134 | |||
135 | config SND_SOC_PHYCORE_AC97 | ||
136 | tristate "SoC Audio support for Phytec phyCORE (and phyCARD) boards" | ||
137 | depends on MACH_PCM043 || MACH_PCA100 | ||
138 | select SND_SOC_AC97_BUS | ||
139 | select SND_SOC_WM9712 | ||
140 | select SND_SOC_IMX_PCM_FIQ | ||
141 | select SND_SOC_IMX_AUDMUX | ||
142 | select SND_SOC_IMX_SSI | ||
143 | help | ||
144 | Say Y if you want to add support for SoC audio on Phytec phyCORE | ||
145 | and phyCARD boards in AC97 mode | ||
146 | |||
147 | config SND_SOC_EUKREA_TLV320 | ||
148 | tristate "Eukrea TLV320" | ||
149 | depends on MACH_EUKREA_MBIMX27_BASEBOARD \ | ||
150 | || MACH_EUKREA_MBIMXSD25_BASEBOARD \ | ||
151 | || MACH_EUKREA_MBIMXSD35_BASEBOARD \ | ||
152 | || MACH_EUKREA_MBIMXSD51_BASEBOARD | ||
153 | depends on I2C | ||
154 | select SND_SOC_TLV320AIC23 | ||
155 | select SND_SOC_IMX_PCM_FIQ | ||
156 | select SND_SOC_IMX_AUDMUX | ||
157 | select SND_SOC_IMX_SSI | ||
158 | help | ||
159 | Enable I2S based access to the TLV320AIC23B codec attached | ||
160 | to the SSI interface | ||
161 | |||
162 | config SND_SOC_IMX_SGTL5000 | ||
163 | tristate "SoC Audio support for i.MX boards with sgtl5000" | ||
164 | depends on OF && I2C | ||
165 | select SND_SOC_SGTL5000 | ||
166 | select SND_SOC_IMX_PCM_DMA | ||
167 | select SND_SOC_IMX_AUDMUX | ||
168 | select SND_SOC_FSL_SSI | ||
169 | select SND_SOC_FSL_UTILS | ||
170 | help | ||
171 | Say Y if you want to add support for SoC audio on an i.MX board with | ||
172 | a sgtl5000 codec. | ||
173 | |||
174 | config SND_SOC_IMX_MC13783 | ||
175 | tristate "SoC Audio support for I.MX boards with mc13783" | ||
176 | depends on MFD_MC13783 | ||
177 | select SND_SOC_IMX_SSI | ||
178 | select SND_SOC_IMX_AUDMUX | ||
179 | select SND_SOC_MC13783 | ||
180 | select SND_SOC_IMX_PCM_DMA | ||
181 | |||
182 | endif # SND_IMX_SOC | ||
diff --git a/sound/soc/fsl/Makefile b/sound/soc/fsl/Makefile index b4a38c0ac58c..5f3cf3f52ea0 100644 --- a/sound/soc/fsl/Makefile +++ b/sound/soc/fsl/Makefile | |||
@@ -8,8 +8,11 @@ obj-$(CONFIG_SND_SOC_P1022_DS) += snd-soc-p1022-ds.o | |||
8 | 8 | ||
9 | # Freescale PowerPC SSI/DMA Platform Support | 9 | # Freescale PowerPC SSI/DMA Platform Support |
10 | snd-soc-fsl-ssi-objs := fsl_ssi.o | 10 | snd-soc-fsl-ssi-objs := fsl_ssi.o |
11 | snd-soc-fsl-utils-objs := fsl_utils.o | ||
11 | snd-soc-fsl-dma-objs := fsl_dma.o | 12 | snd-soc-fsl-dma-objs := fsl_dma.o |
12 | obj-$(CONFIG_SND_SOC_POWERPC_SSI) += snd-soc-fsl-ssi.o snd-soc-fsl-dma.o | 13 | obj-$(CONFIG_SND_SOC_FSL_SSI) += snd-soc-fsl-ssi.o |
14 | obj-$(CONFIG_SND_SOC_FSL_UTILS) += snd-soc-fsl-utils.o | ||
15 | obj-$(CONFIG_SND_SOC_POWERPC_DMA) += snd-soc-fsl-dma.o | ||
13 | 16 | ||
14 | # MPC5200 Platform Support | 17 | # MPC5200 Platform Support |
15 | obj-$(CONFIG_SND_MPC52xx_DMA) += mpc5200_dma.o | 18 | obj-$(CONFIG_SND_MPC52xx_DMA) += mpc5200_dma.o |
@@ -20,3 +23,29 @@ obj-$(CONFIG_SND_SOC_MPC5200_AC97) += mpc5200_psc_ac97.o | |||
20 | obj-$(CONFIG_SND_MPC52xx_SOC_PCM030) += pcm030-audio-fabric.o | 23 | obj-$(CONFIG_SND_MPC52xx_SOC_PCM030) += pcm030-audio-fabric.o |
21 | obj-$(CONFIG_SND_MPC52xx_SOC_EFIKA) += efika-audio-fabric.o | 24 | obj-$(CONFIG_SND_MPC52xx_SOC_EFIKA) += efika-audio-fabric.o |
22 | 25 | ||
26 | # i.MX Platform Support | ||
27 | snd-soc-imx-ssi-objs := imx-ssi.o | ||
28 | snd-soc-imx-audmux-objs := imx-audmux.o | ||
29 | |||
30 | obj-$(CONFIG_SND_SOC_IMX_SSI) += snd-soc-imx-ssi.o | ||
31 | obj-$(CONFIG_SND_SOC_IMX_AUDMUX) += snd-soc-imx-audmux.o | ||
32 | |||
33 | obj-$(CONFIG_SND_SOC_IMX_PCM) += snd-soc-imx-pcm.o | ||
34 | snd-soc-imx-pcm-y := imx-pcm.o | ||
35 | snd-soc-imx-pcm-$(CONFIG_SND_SOC_IMX_PCM_FIQ) += imx-pcm-fiq.o | ||
36 | snd-soc-imx-pcm-$(CONFIG_SND_SOC_IMX_PCM_DMA) += imx-pcm-dma.o | ||
37 | |||
38 | # i.MX Machine Support | ||
39 | snd-soc-eukrea-tlv320-objs := eukrea-tlv320.o | ||
40 | snd-soc-phycore-ac97-objs := phycore-ac97.o | ||
41 | snd-soc-mx27vis-aic32x4-objs := mx27vis-aic32x4.o | ||
42 | snd-soc-wm1133-ev1-objs := wm1133-ev1.o | ||
43 | snd-soc-imx-sgtl5000-objs := imx-sgtl5000.o | ||
44 | snd-soc-imx-mc13783-objs := imx-mc13783.o | ||
45 | |||
46 | obj-$(CONFIG_SND_SOC_EUKREA_TLV320) += snd-soc-eukrea-tlv320.o | ||
47 | obj-$(CONFIG_SND_SOC_PHYCORE_AC97) += snd-soc-phycore-ac97.o | ||
48 | obj-$(CONFIG_SND_SOC_MX27VIS_AIC32X4) += snd-soc-mx27vis-aic32x4.o | ||
49 | obj-$(CONFIG_SND_MXC_SOC_WM1133_EV1) += snd-soc-wm1133-ev1.o | ||
50 | obj-$(CONFIG_SND_SOC_IMX_SGTL5000) += snd-soc-imx-sgtl5000.o | ||
51 | obj-$(CONFIG_SND_SOC_IMX_MC13783) += snd-soc-imx-mc13783.o | ||
diff --git a/sound/soc/imx/eukrea-tlv320.c b/sound/soc/fsl/eukrea-tlv320.c index 7d4475cfdb24..efb9ede01208 100644 --- a/sound/soc/imx/eukrea-tlv320.c +++ b/sound/soc/fsl/eukrea-tlv320.c | |||
@@ -7,7 +7,7 @@ | |||
7 | * which is Copyright 2009 Simtec Electronics | 7 | * which is Copyright 2009 Simtec Electronics |
8 | * and on sound/soc/imx/phycore-ac97.c which is | 8 | * and on sound/soc/imx/phycore-ac97.c which is |
9 | * Copyright 2009 Sascha Hauer, Pengutronix <s.hauer@pengutronix.de> | 9 | * Copyright 2009 Sascha Hauer, Pengutronix <s.hauer@pengutronix.de> |
10 | * | 10 | * |
11 | * This program is free software; you can redistribute it and/or modify it | 11 | * This program is free software; you can redistribute it and/or modify it |
12 | * under the terms of the GNU General Public License as published by the | 12 | * under the terms of the GNU General Public License as published by the |
13 | * Free Software Foundation; either version 2 of the License, or (at your | 13 | * Free Software Foundation; either version 2 of the License, or (at your |
diff --git a/sound/soc/fsl/fsl_ssi.c b/sound/soc/fsl/fsl_ssi.c index 2eb407fa3b48..4ed2afd47782 100644 --- a/sound/soc/fsl/fsl_ssi.c +++ b/sound/soc/fsl/fsl_ssi.c | |||
@@ -11,11 +11,15 @@ | |||
11 | */ | 11 | */ |
12 | 12 | ||
13 | #include <linux/init.h> | 13 | #include <linux/init.h> |
14 | #include <linux/io.h> | ||
14 | #include <linux/module.h> | 15 | #include <linux/module.h> |
15 | #include <linux/interrupt.h> | 16 | #include <linux/interrupt.h> |
17 | #include <linux/clk.h> | ||
16 | #include <linux/device.h> | 18 | #include <linux/device.h> |
17 | #include <linux/delay.h> | 19 | #include <linux/delay.h> |
18 | #include <linux/slab.h> | 20 | #include <linux/slab.h> |
21 | #include <linux/of_address.h> | ||
22 | #include <linux/of_irq.h> | ||
19 | #include <linux/of_platform.h> | 23 | #include <linux/of_platform.h> |
20 | 24 | ||
21 | #include <sound/core.h> | 25 | #include <sound/core.h> |
@@ -25,6 +29,26 @@ | |||
25 | #include <sound/soc.h> | 29 | #include <sound/soc.h> |
26 | 30 | ||
27 | #include "fsl_ssi.h" | 31 | #include "fsl_ssi.h" |
32 | #include "imx-pcm.h" | ||
33 | |||
34 | #ifdef PPC | ||
35 | #define read_ssi(addr) in_be32(addr) | ||
36 | #define write_ssi(val, addr) out_be32(addr, val) | ||
37 | #define write_ssi_mask(addr, clear, set) clrsetbits_be32(addr, clear, set) | ||
38 | #elif defined ARM | ||
39 | #define read_ssi(addr) readl(addr) | ||
40 | #define write_ssi(val, addr) writel(val, addr) | ||
41 | /* | ||
42 | * FIXME: Proper locking should be added at write_ssi_mask caller level | ||
43 | * to ensure this register read/modify/write sequence is race free. | ||
44 | */ | ||
45 | static inline void write_ssi_mask(u32 __iomem *addr, u32 clear, u32 set) | ||
46 | { | ||
47 | u32 val = readl(addr); | ||
48 | val = (val & ~clear) | set; | ||
49 | writel(val, addr); | ||
50 | } | ||
51 | #endif | ||
28 | 52 | ||
29 | /** | 53 | /** |
30 | * FSLSSI_I2S_RATES: sample rates supported by the I2S | 54 | * FSLSSI_I2S_RATES: sample rates supported by the I2S |
@@ -94,6 +118,13 @@ struct fsl_ssi_private { | |||
94 | struct device_attribute dev_attr; | 118 | struct device_attribute dev_attr; |
95 | struct platform_device *pdev; | 119 | struct platform_device *pdev; |
96 | 120 | ||
121 | bool new_binding; | ||
122 | bool ssi_on_imx; | ||
123 | struct clk *clk; | ||
124 | struct platform_device *imx_pcm_pdev; | ||
125 | struct imx_pcm_dma_params dma_params_tx; | ||
126 | struct imx_pcm_dma_params dma_params_rx; | ||
127 | |||
97 | struct { | 128 | struct { |
98 | unsigned int rfrc; | 129 | unsigned int rfrc; |
99 | unsigned int tfrc; | 130 | unsigned int tfrc; |
@@ -145,7 +176,7 @@ static irqreturn_t fsl_ssi_isr(int irq, void *dev_id) | |||
145 | were interrupted for. We mask it with the Interrupt Enable register | 176 | were interrupted for. We mask it with the Interrupt Enable register |
146 | so that we only check for events that we're interested in. | 177 | so that we only check for events that we're interested in. |
147 | */ | 178 | */ |
148 | sisr = in_be32(&ssi->sisr) & SIER_FLAGS; | 179 | sisr = read_ssi(&ssi->sisr) & SIER_FLAGS; |
149 | 180 | ||
150 | if (sisr & CCSR_SSI_SISR_RFRC) { | 181 | if (sisr & CCSR_SSI_SISR_RFRC) { |
151 | ssi_private->stats.rfrc++; | 182 | ssi_private->stats.rfrc++; |
@@ -260,7 +291,7 @@ static irqreturn_t fsl_ssi_isr(int irq, void *dev_id) | |||
260 | 291 | ||
261 | /* Clear the bits that we set */ | 292 | /* Clear the bits that we set */ |
262 | if (sisr2) | 293 | if (sisr2) |
263 | out_be32(&ssi->sisr, sisr2); | 294 | write_ssi(sisr2, &ssi->sisr); |
264 | 295 | ||
265 | return ret; | 296 | return ret; |
266 | } | 297 | } |
@@ -295,7 +326,7 @@ static int fsl_ssi_startup(struct snd_pcm_substream *substream, | |||
295 | * SSI needs to be disabled before updating the registers we set | 326 | * SSI needs to be disabled before updating the registers we set |
296 | * here. | 327 | * here. |
297 | */ | 328 | */ |
298 | clrbits32(&ssi->scr, CCSR_SSI_SCR_SSIEN); | 329 | write_ssi_mask(&ssi->scr, CCSR_SSI_SCR_SSIEN, 0); |
299 | 330 | ||
300 | /* | 331 | /* |
301 | * Program the SSI into I2S Slave Non-Network Synchronous mode. | 332 | * Program the SSI into I2S Slave Non-Network Synchronous mode. |
@@ -303,20 +334,18 @@ static int fsl_ssi_startup(struct snd_pcm_substream *substream, | |||
303 | * | 334 | * |
304 | * FIXME: Little-endian samples require a different shift dir | 335 | * FIXME: Little-endian samples require a different shift dir |
305 | */ | 336 | */ |
306 | clrsetbits_be32(&ssi->scr, | 337 | write_ssi_mask(&ssi->scr, |
307 | CCSR_SSI_SCR_I2S_MODE_MASK | CCSR_SSI_SCR_SYN, | 338 | CCSR_SSI_SCR_I2S_MODE_MASK | CCSR_SSI_SCR_SYN, |
308 | CCSR_SSI_SCR_TFR_CLK_DIS | CCSR_SSI_SCR_I2S_MODE_SLAVE | 339 | CCSR_SSI_SCR_TFR_CLK_DIS | CCSR_SSI_SCR_I2S_MODE_SLAVE |
309 | | (synchronous ? CCSR_SSI_SCR_SYN : 0)); | 340 | | (synchronous ? CCSR_SSI_SCR_SYN : 0)); |
310 | 341 | ||
311 | out_be32(&ssi->stcr, | 342 | write_ssi(CCSR_SSI_STCR_TXBIT0 | CCSR_SSI_STCR_TFEN0 | |
312 | CCSR_SSI_STCR_TXBIT0 | CCSR_SSI_STCR_TFEN0 | | ||
313 | CCSR_SSI_STCR_TFSI | CCSR_SSI_STCR_TEFS | | 343 | CCSR_SSI_STCR_TFSI | CCSR_SSI_STCR_TEFS | |
314 | CCSR_SSI_STCR_TSCKP); | 344 | CCSR_SSI_STCR_TSCKP, &ssi->stcr); |
315 | 345 | ||
316 | out_be32(&ssi->srcr, | 346 | write_ssi(CCSR_SSI_SRCR_RXBIT0 | CCSR_SSI_SRCR_RFEN0 | |
317 | CCSR_SSI_SRCR_RXBIT0 | CCSR_SSI_SRCR_RFEN0 | | ||
318 | CCSR_SSI_SRCR_RFSI | CCSR_SSI_SRCR_REFS | | 347 | CCSR_SSI_SRCR_RFSI | CCSR_SSI_SRCR_REFS | |
319 | CCSR_SSI_SRCR_RSCKP); | 348 | CCSR_SSI_SRCR_RSCKP, &ssi->srcr); |
320 | 349 | ||
321 | /* | 350 | /* |
322 | * The DC and PM bits are only used if the SSI is the clock | 351 | * The DC and PM bits are only used if the SSI is the clock |
@@ -324,7 +353,7 @@ static int fsl_ssi_startup(struct snd_pcm_substream *substream, | |||
324 | */ | 353 | */ |
325 | 354 | ||
326 | /* Enable the interrupts and DMA requests */ | 355 | /* Enable the interrupts and DMA requests */ |
327 | out_be32(&ssi->sier, SIER_FLAGS); | 356 | write_ssi(SIER_FLAGS, &ssi->sier); |
328 | 357 | ||
329 | /* | 358 | /* |
330 | * Set the watermark for transmit FIFI 0 and receive FIFO 0. We | 359 | * Set the watermark for transmit FIFI 0 and receive FIFO 0. We |
@@ -339,9 +368,9 @@ static int fsl_ssi_startup(struct snd_pcm_substream *substream, | |||
339 | * make this value larger (and maybe we should), but this way | 368 | * make this value larger (and maybe we should), but this way |
340 | * data will be written to memory as soon as it's available. | 369 | * data will be written to memory as soon as it's available. |
341 | */ | 370 | */ |
342 | out_be32(&ssi->sfcsr, | 371 | write_ssi(CCSR_SSI_SFCSR_TFWM0(ssi_private->fifo_depth - 2) | |
343 | CCSR_SSI_SFCSR_TFWM0(ssi_private->fifo_depth - 2) | | 372 | CCSR_SSI_SFCSR_RFWM0(ssi_private->fifo_depth - 2), |
344 | CCSR_SSI_SFCSR_RFWM0(ssi_private->fifo_depth - 2)); | 373 | &ssi->sfcsr); |
345 | 374 | ||
346 | /* | 375 | /* |
347 | * We keep the SSI disabled because if we enable it, then the | 376 | * We keep the SSI disabled because if we enable it, then the |
@@ -393,6 +422,12 @@ static int fsl_ssi_startup(struct snd_pcm_substream *substream, | |||
393 | ssi_private->second_stream = substream; | 422 | ssi_private->second_stream = substream; |
394 | } | 423 | } |
395 | 424 | ||
425 | if (ssi_private->ssi_on_imx) | ||
426 | snd_soc_dai_set_dma_data(dai, substream, | ||
427 | (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ? | ||
428 | &ssi_private->dma_params_tx : | ||
429 | &ssi_private->dma_params_rx); | ||
430 | |||
396 | return 0; | 431 | return 0; |
397 | } | 432 | } |
398 | 433 | ||
@@ -417,7 +452,7 @@ static int fsl_ssi_hw_params(struct snd_pcm_substream *substream, | |||
417 | unsigned int sample_size = | 452 | unsigned int sample_size = |
418 | snd_pcm_format_width(params_format(hw_params)); | 453 | snd_pcm_format_width(params_format(hw_params)); |
419 | u32 wl = CCSR_SSI_SxCCR_WL(sample_size); | 454 | u32 wl = CCSR_SSI_SxCCR_WL(sample_size); |
420 | int enabled = in_be32(&ssi->scr) & CCSR_SSI_SCR_SSIEN; | 455 | int enabled = read_ssi(&ssi->scr) & CCSR_SSI_SCR_SSIEN; |
421 | 456 | ||
422 | /* | 457 | /* |
423 | * If we're in synchronous mode, and the SSI is already enabled, | 458 | * If we're in synchronous mode, and the SSI is already enabled, |
@@ -439,9 +474,9 @@ static int fsl_ssi_hw_params(struct snd_pcm_substream *substream, | |||
439 | /* In synchronous mode, the SSI uses STCCR for capture */ | 474 | /* In synchronous mode, the SSI uses STCCR for capture */ |
440 | if ((substream->stream == SNDRV_PCM_STREAM_PLAYBACK) || | 475 | if ((substream->stream == SNDRV_PCM_STREAM_PLAYBACK) || |
441 | ssi_private->cpu_dai_drv.symmetric_rates) | 476 | ssi_private->cpu_dai_drv.symmetric_rates) |
442 | clrsetbits_be32(&ssi->stccr, CCSR_SSI_SxCCR_WL_MASK, wl); | 477 | write_ssi_mask(&ssi->stccr, CCSR_SSI_SxCCR_WL_MASK, wl); |
443 | else | 478 | else |
444 | clrsetbits_be32(&ssi->srccr, CCSR_SSI_SxCCR_WL_MASK, wl); | 479 | write_ssi_mask(&ssi->srccr, CCSR_SSI_SxCCR_WL_MASK, wl); |
445 | 480 | ||
446 | return 0; | 481 | return 0; |
447 | } | 482 | } |
@@ -466,19 +501,19 @@ static int fsl_ssi_trigger(struct snd_pcm_substream *substream, int cmd, | |||
466 | case SNDRV_PCM_TRIGGER_START: | 501 | case SNDRV_PCM_TRIGGER_START: |
467 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: | 502 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
468 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) | 503 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
469 | setbits32(&ssi->scr, | 504 | write_ssi_mask(&ssi->scr, 0, |
470 | CCSR_SSI_SCR_SSIEN | CCSR_SSI_SCR_TE); | 505 | CCSR_SSI_SCR_SSIEN | CCSR_SSI_SCR_TE); |
471 | else | 506 | else |
472 | setbits32(&ssi->scr, | 507 | write_ssi_mask(&ssi->scr, 0, |
473 | CCSR_SSI_SCR_SSIEN | CCSR_SSI_SCR_RE); | 508 | CCSR_SSI_SCR_SSIEN | CCSR_SSI_SCR_RE); |
474 | break; | 509 | break; |
475 | 510 | ||
476 | case SNDRV_PCM_TRIGGER_STOP: | 511 | case SNDRV_PCM_TRIGGER_STOP: |
477 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: | 512 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
478 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) | 513 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
479 | clrbits32(&ssi->scr, CCSR_SSI_SCR_TE); | 514 | write_ssi_mask(&ssi->scr, CCSR_SSI_SCR_TE, 0); |
480 | else | 515 | else |
481 | clrbits32(&ssi->scr, CCSR_SSI_SCR_RE); | 516 | write_ssi_mask(&ssi->scr, CCSR_SSI_SCR_RE, 0); |
482 | break; | 517 | break; |
483 | 518 | ||
484 | default: | 519 | default: |
@@ -510,7 +545,7 @@ static void fsl_ssi_shutdown(struct snd_pcm_substream *substream, | |||
510 | if (!ssi_private->first_stream) { | 545 | if (!ssi_private->first_stream) { |
511 | struct ccsr_ssi __iomem *ssi = ssi_private->ssi; | 546 | struct ccsr_ssi __iomem *ssi = ssi_private->ssi; |
512 | 547 | ||
513 | clrbits32(&ssi->scr, CCSR_SSI_SCR_SSIEN); | 548 | write_ssi_mask(&ssi->scr, CCSR_SSI_SCR_SSIEN, 0); |
514 | } | 549 | } |
515 | } | 550 | } |
516 | 551 | ||
@@ -622,12 +657,6 @@ static int __devinit fsl_ssi_probe(struct platform_device *pdev) | |||
622 | if (!of_device_is_available(np)) | 657 | if (!of_device_is_available(np)) |
623 | return -ENODEV; | 658 | return -ENODEV; |
624 | 659 | ||
625 | /* Check for a codec-handle property. */ | ||
626 | if (!of_get_property(np, "codec-handle", NULL)) { | ||
627 | dev_err(&pdev->dev, "missing codec-handle property\n"); | ||
628 | return -ENODEV; | ||
629 | } | ||
630 | |||
631 | /* We only support the SSI in "I2S Slave" mode */ | 660 | /* We only support the SSI in "I2S Slave" mode */ |
632 | sprop = of_get_property(np, "fsl,mode", NULL); | 661 | sprop = of_get_property(np, "fsl,mode", NULL); |
633 | if (!sprop || strcmp(sprop, "i2s-slave")) { | 662 | if (!sprop || strcmp(sprop, "i2s-slave")) { |
@@ -692,6 +721,50 @@ static int __devinit fsl_ssi_probe(struct platform_device *pdev) | |||
692 | /* Older 8610 DTs didn't have the fifo-depth property */ | 721 | /* Older 8610 DTs didn't have the fifo-depth property */ |
693 | ssi_private->fifo_depth = 8; | 722 | ssi_private->fifo_depth = 8; |
694 | 723 | ||
724 | if (of_device_is_compatible(pdev->dev.of_node, "fsl,imx21-ssi")) { | ||
725 | u32 dma_events[2]; | ||
726 | ssi_private->ssi_on_imx = true; | ||
727 | |||
728 | ssi_private->clk = clk_get(&pdev->dev, NULL); | ||
729 | if (IS_ERR(ssi_private->clk)) { | ||
730 | ret = PTR_ERR(ssi_private->clk); | ||
731 | dev_err(&pdev->dev, "could not get clock: %d\n", ret); | ||
732 | goto error_irq; | ||
733 | } | ||
734 | clk_prepare_enable(ssi_private->clk); | ||
735 | |||
736 | /* | ||
737 | * We have burstsize be "fifo_depth - 2" to match the SSI | ||
738 | * watermark setting in fsl_ssi_startup(). | ||
739 | */ | ||
740 | ssi_private->dma_params_tx.burstsize = | ||
741 | ssi_private->fifo_depth - 2; | ||
742 | ssi_private->dma_params_rx.burstsize = | ||
743 | ssi_private->fifo_depth - 2; | ||
744 | ssi_private->dma_params_tx.dma_addr = | ||
745 | ssi_private->ssi_phys + offsetof(struct ccsr_ssi, stx0); | ||
746 | ssi_private->dma_params_rx.dma_addr = | ||
747 | ssi_private->ssi_phys + offsetof(struct ccsr_ssi, srx0); | ||
748 | /* | ||
749 | * TODO: This is a temporary solution and should be changed | ||
750 | * to use generic DMA binding later when the helplers get in. | ||
751 | */ | ||
752 | ret = of_property_read_u32_array(pdev->dev.of_node, | ||
753 | "fsl,ssi-dma-events", dma_events, 2); | ||
754 | if (ret) { | ||
755 | dev_err(&pdev->dev, "could not get dma events\n"); | ||
756 | goto error_clk; | ||
757 | } | ||
758 | ssi_private->dma_params_tx.dma = dma_events[0]; | ||
759 | ssi_private->dma_params_rx.dma = dma_events[1]; | ||
760 | |||
761 | ssi_private->dma_params_tx.shared_peripheral = | ||
762 | of_device_is_compatible(of_get_parent(np), | ||
763 | "fsl,spba-bus"); | ||
764 | ssi_private->dma_params_rx.shared_peripheral = | ||
765 | ssi_private->dma_params_tx.shared_peripheral; | ||
766 | } | ||
767 | |||
695 | /* Initialize the the device_attribute structure */ | 768 | /* Initialize the the device_attribute structure */ |
696 | dev_attr = &ssi_private->dev_attr; | 769 | dev_attr = &ssi_private->dev_attr; |
697 | sysfs_attr_init(&dev_attr->attr); | 770 | sysfs_attr_init(&dev_attr->attr); |
@@ -715,6 +788,26 @@ static int __devinit fsl_ssi_probe(struct platform_device *pdev) | |||
715 | goto error_dev; | 788 | goto error_dev; |
716 | } | 789 | } |
717 | 790 | ||
791 | if (ssi_private->ssi_on_imx) { | ||
792 | ssi_private->imx_pcm_pdev = | ||
793 | platform_device_register_simple("imx-pcm-audio", | ||
794 | -1, NULL, 0); | ||
795 | if (IS_ERR(ssi_private->imx_pcm_pdev)) { | ||
796 | ret = PTR_ERR(ssi_private->imx_pcm_pdev); | ||
797 | goto error_dev; | ||
798 | } | ||
799 | } | ||
800 | |||
801 | /* | ||
802 | * If codec-handle property is missing from SSI node, we assume | ||
803 | * that the machine driver uses new binding which does not require | ||
804 | * SSI driver to trigger machine driver's probe. | ||
805 | */ | ||
806 | if (!of_get_property(np, "codec-handle", NULL)) { | ||
807 | ssi_private->new_binding = true; | ||
808 | goto done; | ||
809 | } | ||
810 | |||
718 | /* Trigger the machine driver's probe function. The platform driver | 811 | /* Trigger the machine driver's probe function. The platform driver |
719 | * name of the machine driver is taken from /compatible property of the | 812 | * name of the machine driver is taken from /compatible property of the |
720 | * device tree. We also pass the address of the CPU DAI driver | 813 | * device tree. We also pass the address of the CPU DAI driver |
@@ -736,15 +829,24 @@ static int __devinit fsl_ssi_probe(struct platform_device *pdev) | |||
736 | goto error_dai; | 829 | goto error_dai; |
737 | } | 830 | } |
738 | 831 | ||
832 | done: | ||
739 | return 0; | 833 | return 0; |
740 | 834 | ||
741 | error_dai: | 835 | error_dai: |
836 | if (ssi_private->ssi_on_imx) | ||
837 | platform_device_unregister(ssi_private->imx_pcm_pdev); | ||
742 | snd_soc_unregister_dai(&pdev->dev); | 838 | snd_soc_unregister_dai(&pdev->dev); |
743 | 839 | ||
744 | error_dev: | 840 | error_dev: |
745 | dev_set_drvdata(&pdev->dev, NULL); | 841 | dev_set_drvdata(&pdev->dev, NULL); |
746 | device_remove_file(&pdev->dev, dev_attr); | 842 | device_remove_file(&pdev->dev, dev_attr); |
747 | 843 | ||
844 | error_clk: | ||
845 | if (ssi_private->ssi_on_imx) { | ||
846 | clk_disable_unprepare(ssi_private->clk); | ||
847 | clk_put(ssi_private->clk); | ||
848 | } | ||
849 | |||
748 | error_irq: | 850 | error_irq: |
749 | free_irq(ssi_private->irq, ssi_private); | 851 | free_irq(ssi_private->irq, ssi_private); |
750 | 852 | ||
@@ -764,7 +866,13 @@ static int fsl_ssi_remove(struct platform_device *pdev) | |||
764 | { | 866 | { |
765 | struct fsl_ssi_private *ssi_private = dev_get_drvdata(&pdev->dev); | 867 | struct fsl_ssi_private *ssi_private = dev_get_drvdata(&pdev->dev); |
766 | 868 | ||
767 | platform_device_unregister(ssi_private->pdev); | 869 | if (!ssi_private->new_binding) |
870 | platform_device_unregister(ssi_private->pdev); | ||
871 | if (ssi_private->ssi_on_imx) { | ||
872 | platform_device_unregister(ssi_private->imx_pcm_pdev); | ||
873 | clk_disable_unprepare(ssi_private->clk); | ||
874 | clk_put(ssi_private->clk); | ||
875 | } | ||
768 | snd_soc_unregister_dai(&pdev->dev); | 876 | snd_soc_unregister_dai(&pdev->dev); |
769 | device_remove_file(&pdev->dev, &ssi_private->dev_attr); | 877 | device_remove_file(&pdev->dev, &ssi_private->dev_attr); |
770 | 878 | ||
@@ -779,6 +887,7 @@ static int fsl_ssi_remove(struct platform_device *pdev) | |||
779 | 887 | ||
780 | static const struct of_device_id fsl_ssi_ids[] = { | 888 | static const struct of_device_id fsl_ssi_ids[] = { |
781 | { .compatible = "fsl,mpc8610-ssi", }, | 889 | { .compatible = "fsl,mpc8610-ssi", }, |
890 | { .compatible = "fsl,imx21-ssi", }, | ||
782 | {} | 891 | {} |
783 | }; | 892 | }; |
784 | MODULE_DEVICE_TABLE(of, fsl_ssi_ids); | 893 | MODULE_DEVICE_TABLE(of, fsl_ssi_ids); |
diff --git a/sound/soc/fsl/fsl_utils.c b/sound/soc/fsl/fsl_utils.c new file mode 100644 index 000000000000..b9e42b503a37 --- /dev/null +++ b/sound/soc/fsl/fsl_utils.c | |||
@@ -0,0 +1,91 @@ | |||
1 | /** | ||
2 | * Freescale ALSA SoC Machine driver utility | ||
3 | * | ||
4 | * Author: Timur Tabi <timur@freescale.com> | ||
5 | * | ||
6 | * Copyright 2010 Freescale Semiconductor, Inc. | ||
7 | * | ||
8 | * This file is licensed under the terms of the GNU General Public License | ||
9 | * version 2. This program is licensed "as is" without any warranty of any | ||
10 | * kind, whether express or implied. | ||
11 | */ | ||
12 | |||
13 | #include <linux/module.h> | ||
14 | #include <linux/of_address.h> | ||
15 | #include <sound/soc.h> | ||
16 | |||
17 | #include "fsl_utils.h" | ||
18 | |||
19 | /** | ||
20 | * fsl_asoc_get_dma_channel - determine the dma channel for a SSI node | ||
21 | * | ||
22 | * @ssi_np: pointer to the SSI device tree node | ||
23 | * @name: name of the phandle pointing to the dma channel | ||
24 | * @dai: ASoC DAI link pointer to be filled with platform_name | ||
25 | * @dma_channel_id: dma channel id to be returned | ||
26 | * @dma_id: dma id to be returned | ||
27 | * | ||
28 | * This function determines the dma and channel id for given SSI node. It | ||
29 | * also discovers the platform_name for the ASoC DAI link. | ||
30 | */ | ||
31 | int fsl_asoc_get_dma_channel(struct device_node *ssi_np, | ||
32 | const char *name, | ||
33 | struct snd_soc_dai_link *dai, | ||
34 | unsigned int *dma_channel_id, | ||
35 | unsigned int *dma_id) | ||
36 | { | ||
37 | struct resource res; | ||
38 | struct device_node *dma_channel_np, *dma_np; | ||
39 | const u32 *iprop; | ||
40 | int ret; | ||
41 | |||
42 | dma_channel_np = of_parse_phandle(ssi_np, name, 0); | ||
43 | if (!dma_channel_np) | ||
44 | return -EINVAL; | ||
45 | |||
46 | if (!of_device_is_compatible(dma_channel_np, "fsl,ssi-dma-channel")) { | ||
47 | of_node_put(dma_channel_np); | ||
48 | return -EINVAL; | ||
49 | } | ||
50 | |||
51 | /* Determine the dev_name for the device_node. This code mimics the | ||
52 | * behavior of of_device_make_bus_id(). We need this because ASoC uses | ||
53 | * the dev_name() of the device to match the platform (DMA) device with | ||
54 | * the CPU (SSI) device. It's all ugly and hackish, but it works (for | ||
55 | * now). | ||
56 | * | ||
57 | * dai->platform name should already point to an allocated buffer. | ||
58 | */ | ||
59 | ret = of_address_to_resource(dma_channel_np, 0, &res); | ||
60 | if (ret) { | ||
61 | of_node_put(dma_channel_np); | ||
62 | return ret; | ||
63 | } | ||
64 | snprintf((char *)dai->platform_name, DAI_NAME_SIZE, "%llx.%s", | ||
65 | (unsigned long long) res.start, dma_channel_np->name); | ||
66 | |||
67 | iprop = of_get_property(dma_channel_np, "cell-index", NULL); | ||
68 | if (!iprop) { | ||
69 | of_node_put(dma_channel_np); | ||
70 | return -EINVAL; | ||
71 | } | ||
72 | *dma_channel_id = be32_to_cpup(iprop); | ||
73 | |||
74 | dma_np = of_get_parent(dma_channel_np); | ||
75 | iprop = of_get_property(dma_np, "cell-index", NULL); | ||
76 | if (!iprop) { | ||
77 | of_node_put(dma_np); | ||
78 | return -EINVAL; | ||
79 | } | ||
80 | *dma_id = be32_to_cpup(iprop); | ||
81 | |||
82 | of_node_put(dma_np); | ||
83 | of_node_put(dma_channel_np); | ||
84 | |||
85 | return 0; | ||
86 | } | ||
87 | EXPORT_SYMBOL(fsl_asoc_get_dma_channel); | ||
88 | |||
89 | MODULE_AUTHOR("Timur Tabi <timur@freescale.com>"); | ||
90 | MODULE_DESCRIPTION("Freescale ASoC utility code"); | ||
91 | MODULE_LICENSE("GPL v2"); | ||
diff --git a/sound/soc/fsl/fsl_utils.h b/sound/soc/fsl/fsl_utils.h new file mode 100644 index 000000000000..b2951126527c --- /dev/null +++ b/sound/soc/fsl/fsl_utils.h | |||
@@ -0,0 +1,26 @@ | |||
1 | /** | ||
2 | * Freescale ALSA SoC Machine driver utility | ||
3 | * | ||
4 | * Author: Timur Tabi <timur@freescale.com> | ||
5 | * | ||
6 | * Copyright 2010 Freescale Semiconductor, Inc. | ||
7 | * | ||
8 | * This file is licensed under the terms of the GNU General Public License | ||
9 | * version 2. This program is licensed "as is" without any warranty of any | ||
10 | * kind, whether express or implied. | ||
11 | */ | ||
12 | |||
13 | #ifndef _FSL_UTILS_H | ||
14 | #define _FSL_UTILS_H | ||
15 | |||
16 | #define DAI_NAME_SIZE 32 | ||
17 | |||
18 | struct snd_soc_dai_link; | ||
19 | struct device_node; | ||
20 | |||
21 | int fsl_asoc_get_dma_channel(struct device_node *ssi_np, const char *name, | ||
22 | struct snd_soc_dai_link *dai, | ||
23 | unsigned int *dma_channel_id, | ||
24 | unsigned int *dma_id); | ||
25 | |||
26 | #endif /* _FSL_UTILS_H */ | ||
diff --git a/sound/soc/imx/imx-audmux.c b/sound/soc/fsl/imx-audmux.c index f23700359c67..f23700359c67 100644 --- a/sound/soc/imx/imx-audmux.c +++ b/sound/soc/fsl/imx-audmux.c | |||
diff --git a/sound/soc/imx/imx-audmux.h b/sound/soc/fsl/imx-audmux.h index 04ebbab8d7b9..04ebbab8d7b9 100644 --- a/sound/soc/imx/imx-audmux.h +++ b/sound/soc/fsl/imx-audmux.h | |||
diff --git a/sound/soc/fsl/imx-mc13783.c b/sound/soc/fsl/imx-mc13783.c new file mode 100644 index 000000000000..f59c34943662 --- /dev/null +++ b/sound/soc/fsl/imx-mc13783.c | |||
@@ -0,0 +1,156 @@ | |||
1 | /* | ||
2 | * imx-mc13783.c -- SoC audio for imx based boards with mc13783 codec | ||
3 | * | ||
4 | * Copyright 2012 Philippe Retornaz, <philippe.retornaz@epfl.ch> | ||
5 | * | ||
6 | * Heavly based on phycore-mc13783: | ||
7 | * Copyright 2009 Sascha Hauer, Pengutronix <s.hauer@pengutronix.de> | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or modify it | ||
10 | * under the terms of the GNU General Public License as published by the | ||
11 | * Free Software Foundation; either version 2 of the License, or (at your | ||
12 | * option) any later version. | ||
13 | * | ||
14 | */ | ||
15 | |||
16 | #include <linux/module.h> | ||
17 | #include <linux/moduleparam.h> | ||
18 | #include <linux/device.h> | ||
19 | #include <sound/core.h> | ||
20 | #include <sound/pcm.h> | ||
21 | #include <sound/soc.h> | ||
22 | #include <sound/soc-dapm.h> | ||
23 | #include <asm/mach-types.h> | ||
24 | |||
25 | #include "../codecs/mc13783.h" | ||
26 | #include "imx-ssi.h" | ||
27 | #include "imx-audmux.h" | ||
28 | |||
29 | #define FMT_SSI (SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_NB_NF | \ | ||
30 | SND_SOC_DAIFMT_CBM_CFM) | ||
31 | |||
32 | static int imx_mc13783_hifi_hw_params(struct snd_pcm_substream *substream, | ||
33 | struct snd_pcm_hw_params *params) | ||
34 | { | ||
35 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
36 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; | ||
37 | struct snd_soc_dai *codec_dai = rtd->codec_dai; | ||
38 | int ret; | ||
39 | |||
40 | ret = snd_soc_dai_set_tdm_slot(codec_dai, 0xfffffffc, 0xfffffffc, | ||
41 | 4, 16); | ||
42 | if (ret) | ||
43 | return ret; | ||
44 | |||
45 | ret = snd_soc_dai_set_sysclk(codec_dai, MC13783_CLK_CLIA, 26000000, 0); | ||
46 | if (ret) | ||
47 | return ret; | ||
48 | |||
49 | ret = snd_soc_dai_set_tdm_slot(cpu_dai, 0x0, 0xfffffffc, 2, 16); | ||
50 | if (ret) | ||
51 | return ret; | ||
52 | |||
53 | return 0; | ||
54 | } | ||
55 | |||
56 | static struct snd_soc_ops imx_mc13783_hifi_ops = { | ||
57 | .hw_params = imx_mc13783_hifi_hw_params, | ||
58 | }; | ||
59 | |||
60 | static struct snd_soc_dai_link imx_mc13783_dai_mc13783[] = { | ||
61 | { | ||
62 | .name = "MC13783", | ||
63 | .stream_name = "Sound", | ||
64 | .codec_dai_name = "mc13783-hifi", | ||
65 | .codec_name = "mc13783-codec", | ||
66 | .cpu_dai_name = "imx-ssi.0", | ||
67 | .platform_name = "imx-pcm-audio.0", | ||
68 | .ops = &imx_mc13783_hifi_ops, | ||
69 | .symmetric_rates = 1, | ||
70 | .dai_fmt = FMT_SSI, | ||
71 | }, | ||
72 | }; | ||
73 | |||
74 | static const struct snd_soc_dapm_widget imx_mc13783_widget[] = { | ||
75 | SND_SOC_DAPM_MIC("Mic", NULL), | ||
76 | SND_SOC_DAPM_HP("Headphone", NULL), | ||
77 | SND_SOC_DAPM_SPK("Speaker", NULL), | ||
78 | }; | ||
79 | |||
80 | static const struct snd_soc_dapm_route imx_mc13783_routes[] = { | ||
81 | {"Speaker", NULL, "LSP"}, | ||
82 | {"Headphone", NULL, "HSL"}, | ||
83 | {"Headphone", NULL, "HSR"}, | ||
84 | |||
85 | {"MC1LIN", NULL, "MC1 Bias"}, | ||
86 | {"MC2IN", NULL, "MC2 Bias"}, | ||
87 | {"MC1 Bias", NULL, "Mic"}, | ||
88 | {"MC2 Bias", NULL, "Mic"}, | ||
89 | }; | ||
90 | |||
91 | static struct snd_soc_card imx_mc13783 = { | ||
92 | .name = "imx_mc13783", | ||
93 | .dai_link = imx_mc13783_dai_mc13783, | ||
94 | .num_links = ARRAY_SIZE(imx_mc13783_dai_mc13783), | ||
95 | .dapm_widgets = imx_mc13783_widget, | ||
96 | .num_dapm_widgets = ARRAY_SIZE(imx_mc13783_widget), | ||
97 | .dapm_routes = imx_mc13783_routes, | ||
98 | .num_dapm_routes = ARRAY_SIZE(imx_mc13783_routes), | ||
99 | }; | ||
100 | |||
101 | static int __devinit imx_mc13783_probe(struct platform_device *pdev) | ||
102 | { | ||
103 | int ret; | ||
104 | |||
105 | imx_mc13783.dev = &pdev->dev; | ||
106 | |||
107 | ret = snd_soc_register_card(&imx_mc13783); | ||
108 | if (ret) { | ||
109 | dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", | ||
110 | ret); | ||
111 | return ret; | ||
112 | } | ||
113 | |||
114 | imx_audmux_v2_configure_port(MX31_AUDMUX_PORT4_SSI_PINS_4, | ||
115 | IMX_AUDMUX_V2_PTCR_SYN, | ||
116 | IMX_AUDMUX_V2_PDCR_RXDSEL(MX31_AUDMUX_PORT1_SSI0) | | ||
117 | IMX_AUDMUX_V2_PDCR_MODE(1) | | ||
118 | IMX_AUDMUX_V2_PDCR_INMMASK(0xfc)); | ||
119 | imx_audmux_v2_configure_port(MX31_AUDMUX_PORT1_SSI0, | ||
120 | IMX_AUDMUX_V2_PTCR_SYN | | ||
121 | IMX_AUDMUX_V2_PTCR_TFSDIR | | ||
122 | IMX_AUDMUX_V2_PTCR_TFSEL(MX31_AUDMUX_PORT4_SSI_PINS_4) | | ||
123 | IMX_AUDMUX_V2_PTCR_TCLKDIR | | ||
124 | IMX_AUDMUX_V2_PTCR_TCSEL(MX31_AUDMUX_PORT4_SSI_PINS_4) | | ||
125 | IMX_AUDMUX_V2_PTCR_RFSDIR | | ||
126 | IMX_AUDMUX_V2_PTCR_RFSEL(MX31_AUDMUX_PORT4_SSI_PINS_4) | | ||
127 | IMX_AUDMUX_V2_PTCR_RCLKDIR | | ||
128 | IMX_AUDMUX_V2_PTCR_RCSEL(MX31_AUDMUX_PORT4_SSI_PINS_4), | ||
129 | IMX_AUDMUX_V2_PDCR_RXDSEL(MX31_AUDMUX_PORT4_SSI_PINS_4)); | ||
130 | |||
131 | return ret; | ||
132 | } | ||
133 | |||
134 | static int __devexit imx_mc13783_remove(struct platform_device *pdev) | ||
135 | { | ||
136 | snd_soc_unregister_card(&imx_mc13783); | ||
137 | |||
138 | return 0; | ||
139 | } | ||
140 | |||
141 | static struct platform_driver imx_mc13783_audio_driver = { | ||
142 | .driver = { | ||
143 | .name = "imx_mc13783", | ||
144 | .owner = THIS_MODULE, | ||
145 | }, | ||
146 | .probe = imx_mc13783_probe, | ||
147 | .remove = __devexit_p(imx_mc13783_remove) | ||
148 | }; | ||
149 | |||
150 | module_platform_driver(imx_mc13783_audio_driver); | ||
151 | |||
152 | MODULE_AUTHOR("Sascha Hauer <s.hauer@pengutronix.de>"); | ||
153 | MODULE_AUTHOR("Philippe Retornaz <philippe.retornaz@epfl.ch"); | ||
154 | MODULE_DESCRIPTION("imx with mc13783 codec ALSA SoC driver"); | ||
155 | MODULE_LICENSE("GPL"); | ||
156 | MODULE_ALIAS("platform:imx_mc13783"); | ||
diff --git a/sound/soc/imx/imx-pcm-dma-mx2.c b/sound/soc/fsl/imx-pcm-dma.c index 6b818de2fc03..f3c0a5ef35c8 100644 --- a/sound/soc/imx/imx-pcm-dma-mx2.c +++ b/sound/soc/fsl/imx-pcm-dma.c | |||
@@ -109,7 +109,8 @@ static int snd_imx_open(struct snd_pcm_substream *substream) | |||
109 | dma_params = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream); | 109 | dma_params = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream); |
110 | 110 | ||
111 | dma_data = kzalloc(sizeof(*dma_data), GFP_KERNEL); | 111 | dma_data = kzalloc(sizeof(*dma_data), GFP_KERNEL); |
112 | dma_data->peripheral_type = IMX_DMATYPE_SSI; | 112 | dma_data->peripheral_type = dma_params->shared_peripheral ? |
113 | IMX_DMATYPE_SSI_SP : IMX_DMATYPE_SSI; | ||
113 | dma_data->priority = DMA_PRIO_HIGH; | 114 | dma_data->priority = DMA_PRIO_HIGH; |
114 | dma_data->dma_request = dma_params->dma; | 115 | dma_data->dma_request = dma_params->dma; |
115 | 116 | ||
diff --git a/sound/soc/imx/imx-pcm-fiq.c b/sound/soc/fsl/imx-pcm-fiq.c index 456b7d723d66..456b7d723d66 100644 --- a/sound/soc/imx/imx-pcm-fiq.c +++ b/sound/soc/fsl/imx-pcm-fiq.c | |||
diff --git a/sound/soc/imx/imx-pcm.c b/sound/soc/fsl/imx-pcm.c index 93dc360b1777..93dc360b1777 100644 --- a/sound/soc/imx/imx-pcm.c +++ b/sound/soc/fsl/imx-pcm.c | |||
diff --git a/sound/soc/imx/imx-pcm.h b/sound/soc/fsl/imx-pcm.h index b5f5c3acf34d..83c0ed7d55c9 100644 --- a/sound/soc/imx/imx-pcm.h +++ b/sound/soc/fsl/imx-pcm.h | |||
@@ -22,6 +22,7 @@ struct imx_pcm_dma_params { | |||
22 | int dma; | 22 | int dma; |
23 | unsigned long dma_addr; | 23 | unsigned long dma_addr; |
24 | int burstsize; | 24 | int burstsize; |
25 | bool shared_peripheral; /* The peripheral is on SPBA bus */ | ||
25 | }; | 26 | }; |
26 | 27 | ||
27 | int snd_imx_pcm_mmap(struct snd_pcm_substream *substream, | 28 | int snd_imx_pcm_mmap(struct snd_pcm_substream *substream, |
diff --git a/sound/soc/fsl/imx-sgtl5000.c b/sound/soc/fsl/imx-sgtl5000.c new file mode 100644 index 000000000000..3a729caeb8c8 --- /dev/null +++ b/sound/soc/fsl/imx-sgtl5000.c | |||
@@ -0,0 +1,221 @@ | |||
1 | /* | ||
2 | * Copyright 2012 Freescale Semiconductor, Inc. | ||
3 | * Copyright 2012 Linaro Ltd. | ||
4 | * | ||
5 | * The code contained herein is licensed under the GNU General Public | ||
6 | * License. You may obtain a copy of the GNU General Public License | ||
7 | * Version 2 or later at the following locations: | ||
8 | * | ||
9 | * http://www.opensource.org/licenses/gpl-license.html | ||
10 | * http://www.gnu.org/copyleft/gpl.html | ||
11 | */ | ||
12 | |||
13 | #include <linux/module.h> | ||
14 | #include <linux/of.h> | ||
15 | #include <linux/of_platform.h> | ||
16 | #include <linux/of_i2c.h> | ||
17 | #include <linux/clk.h> | ||
18 | #include <sound/soc.h> | ||
19 | |||
20 | #include "../codecs/sgtl5000.h" | ||
21 | #include "imx-audmux.h" | ||
22 | |||
23 | #define DAI_NAME_SIZE 32 | ||
24 | |||
25 | struct imx_sgtl5000_data { | ||
26 | struct snd_soc_dai_link dai; | ||
27 | struct snd_soc_card card; | ||
28 | char codec_dai_name[DAI_NAME_SIZE]; | ||
29 | char platform_name[DAI_NAME_SIZE]; | ||
30 | struct clk *codec_clk; | ||
31 | unsigned int clk_frequency; | ||
32 | }; | ||
33 | |||
34 | static int imx_sgtl5000_dai_init(struct snd_soc_pcm_runtime *rtd) | ||
35 | { | ||
36 | struct imx_sgtl5000_data *data = container_of(rtd->card, | ||
37 | struct imx_sgtl5000_data, card); | ||
38 | struct device *dev = rtd->card->dev; | ||
39 | int ret; | ||
40 | |||
41 | ret = snd_soc_dai_set_sysclk(rtd->codec_dai, SGTL5000_SYSCLK, | ||
42 | data->clk_frequency, SND_SOC_CLOCK_IN); | ||
43 | if (ret) { | ||
44 | dev_err(dev, "could not set codec driver clock params\n"); | ||
45 | return ret; | ||
46 | } | ||
47 | |||
48 | return 0; | ||
49 | } | ||
50 | |||
51 | static const struct snd_soc_dapm_widget imx_sgtl5000_dapm_widgets[] = { | ||
52 | SND_SOC_DAPM_MIC("Mic Jack", NULL), | ||
53 | SND_SOC_DAPM_LINE("Line In Jack", NULL), | ||
54 | SND_SOC_DAPM_HP("Headphone Jack", NULL), | ||
55 | SND_SOC_DAPM_SPK("Line Out Jack", NULL), | ||
56 | SND_SOC_DAPM_SPK("Ext Spk", NULL), | ||
57 | }; | ||
58 | |||
59 | static int __devinit imx_sgtl5000_probe(struct platform_device *pdev) | ||
60 | { | ||
61 | struct device_node *np = pdev->dev.of_node; | ||
62 | struct device_node *ssi_np, *codec_np; | ||
63 | struct platform_device *ssi_pdev; | ||
64 | struct i2c_client *codec_dev; | ||
65 | struct imx_sgtl5000_data *data; | ||
66 | int int_port, ext_port; | ||
67 | int ret; | ||
68 | |||
69 | ret = of_property_read_u32(np, "mux-int-port", &int_port); | ||
70 | if (ret) { | ||
71 | dev_err(&pdev->dev, "mux-int-port missing or invalid\n"); | ||
72 | return ret; | ||
73 | } | ||
74 | ret = of_property_read_u32(np, "mux-ext-port", &ext_port); | ||
75 | if (ret) { | ||
76 | dev_err(&pdev->dev, "mux-ext-port missing or invalid\n"); | ||
77 | return ret; | ||
78 | } | ||
79 | |||
80 | /* | ||
81 | * The port numbering in the hardware manual starts at 1, while | ||
82 | * the audmux API expects it starts at 0. | ||
83 | */ | ||
84 | int_port--; | ||
85 | ext_port--; | ||
86 | ret = imx_audmux_v2_configure_port(int_port, | ||
87 | IMX_AUDMUX_V2_PTCR_SYN | | ||
88 | IMX_AUDMUX_V2_PTCR_TFSEL(ext_port) | | ||
89 | IMX_AUDMUX_V2_PTCR_TCSEL(ext_port) | | ||
90 | IMX_AUDMUX_V2_PTCR_TFSDIR | | ||
91 | IMX_AUDMUX_V2_PTCR_TCLKDIR, | ||
92 | IMX_AUDMUX_V2_PDCR_RXDSEL(ext_port)); | ||
93 | if (ret) { | ||
94 | dev_err(&pdev->dev, "audmux internal port setup failed\n"); | ||
95 | return ret; | ||
96 | } | ||
97 | imx_audmux_v2_configure_port(ext_port, | ||
98 | IMX_AUDMUX_V2_PTCR_SYN | | ||
99 | IMX_AUDMUX_V2_PTCR_TCSEL(int_port), | ||
100 | IMX_AUDMUX_V2_PDCR_RXDSEL(int_port)); | ||
101 | if (ret) { | ||
102 | dev_err(&pdev->dev, "audmux external port setup failed\n"); | ||
103 | return ret; | ||
104 | } | ||
105 | |||
106 | ssi_np = of_parse_phandle(pdev->dev.of_node, "ssi-controller", 0); | ||
107 | codec_np = of_parse_phandle(pdev->dev.of_node, "audio-codec", 0); | ||
108 | if (!ssi_np || !codec_np) { | ||
109 | dev_err(&pdev->dev, "phandle missing or invalid\n"); | ||
110 | ret = -EINVAL; | ||
111 | goto fail; | ||
112 | } | ||
113 | |||
114 | ssi_pdev = of_find_device_by_node(ssi_np); | ||
115 | if (!ssi_pdev) { | ||
116 | dev_err(&pdev->dev, "failed to find SSI platform device\n"); | ||
117 | ret = -EINVAL; | ||
118 | goto fail; | ||
119 | } | ||
120 | codec_dev = of_find_i2c_device_by_node(codec_np); | ||
121 | if (!codec_dev) { | ||
122 | dev_err(&pdev->dev, "failed to find codec platform device\n"); | ||
123 | return -EINVAL; | ||
124 | } | ||
125 | |||
126 | data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); | ||
127 | if (!data) { | ||
128 | ret = -ENOMEM; | ||
129 | goto fail; | ||
130 | } | ||
131 | |||
132 | data->codec_clk = clk_get(&codec_dev->dev, NULL); | ||
133 | if (IS_ERR(data->codec_clk)) { | ||
134 | /* assuming clock enabled by default */ | ||
135 | data->codec_clk = NULL; | ||
136 | ret = of_property_read_u32(codec_np, "clock-frequency", | ||
137 | &data->clk_frequency); | ||
138 | if (ret) { | ||
139 | dev_err(&codec_dev->dev, | ||
140 | "clock-frequency missing or invalid\n"); | ||
141 | goto fail; | ||
142 | } | ||
143 | } else { | ||
144 | data->clk_frequency = clk_get_rate(data->codec_clk); | ||
145 | clk_prepare_enable(data->codec_clk); | ||
146 | } | ||
147 | |||
148 | data->dai.name = "HiFi"; | ||
149 | data->dai.stream_name = "HiFi"; | ||
150 | data->dai.codec_dai_name = "sgtl5000"; | ||
151 | data->dai.codec_of_node = codec_np; | ||
152 | data->dai.cpu_dai_name = dev_name(&ssi_pdev->dev); | ||
153 | data->dai.platform_name = "imx-pcm-audio"; | ||
154 | data->dai.init = &imx_sgtl5000_dai_init; | ||
155 | data->dai.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | | ||
156 | SND_SOC_DAIFMT_CBM_CFM; | ||
157 | |||
158 | data->card.dev = &pdev->dev; | ||
159 | ret = snd_soc_of_parse_card_name(&data->card, "model"); | ||
160 | if (ret) | ||
161 | goto clk_fail; | ||
162 | ret = snd_soc_of_parse_audio_routing(&data->card, "audio-routing"); | ||
163 | if (ret) | ||
164 | goto clk_fail; | ||
165 | data->card.num_links = 1; | ||
166 | data->card.dai_link = &data->dai; | ||
167 | data->card.dapm_widgets = imx_sgtl5000_dapm_widgets; | ||
168 | data->card.num_dapm_widgets = ARRAY_SIZE(imx_sgtl5000_dapm_widgets); | ||
169 | |||
170 | ret = snd_soc_register_card(&data->card); | ||
171 | if (ret) { | ||
172 | dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret); | ||
173 | goto clk_fail; | ||
174 | } | ||
175 | |||
176 | platform_set_drvdata(pdev, data); | ||
177 | clk_fail: | ||
178 | clk_put(data->codec_clk); | ||
179 | fail: | ||
180 | if (ssi_np) | ||
181 | of_node_put(ssi_np); | ||
182 | if (codec_np) | ||
183 | of_node_put(codec_np); | ||
184 | |||
185 | return ret; | ||
186 | } | ||
187 | |||
188 | static int __devexit imx_sgtl5000_remove(struct platform_device *pdev) | ||
189 | { | ||
190 | struct imx_sgtl5000_data *data = platform_get_drvdata(pdev); | ||
191 | |||
192 | if (data->codec_clk) { | ||
193 | clk_disable_unprepare(data->codec_clk); | ||
194 | clk_put(data->codec_clk); | ||
195 | } | ||
196 | snd_soc_unregister_card(&data->card); | ||
197 | |||
198 | return 0; | ||
199 | } | ||
200 | |||
201 | static const struct of_device_id imx_sgtl5000_dt_ids[] = { | ||
202 | { .compatible = "fsl,imx-audio-sgtl5000", }, | ||
203 | { /* sentinel */ } | ||
204 | }; | ||
205 | MODULE_DEVICE_TABLE(of, imx_sgtl5000_dt_ids); | ||
206 | |||
207 | static struct platform_driver imx_sgtl5000_driver = { | ||
208 | .driver = { | ||
209 | .name = "imx-sgtl5000", | ||
210 | .owner = THIS_MODULE, | ||
211 | .of_match_table = imx_sgtl5000_dt_ids, | ||
212 | }, | ||
213 | .probe = imx_sgtl5000_probe, | ||
214 | .remove = __devexit_p(imx_sgtl5000_remove), | ||
215 | }; | ||
216 | module_platform_driver(imx_sgtl5000_driver); | ||
217 | |||
218 | MODULE_AUTHOR("Shawn Guo <shawn.guo@linaro.org>"); | ||
219 | MODULE_DESCRIPTION("Freescale i.MX SGTL5000 ASoC machine driver"); | ||
220 | MODULE_LICENSE("GPL v2"); | ||
221 | MODULE_ALIAS("platform:imx-sgtl5000"); | ||
diff --git a/sound/soc/imx/imx-ssi.c b/sound/soc/fsl/imx-ssi.c index 4f81ed456325..cf3ed0362c9c 100644 --- a/sound/soc/imx/imx-ssi.c +++ b/sound/soc/fsl/imx-ssi.c | |||
@@ -28,7 +28,7 @@ | |||
28 | * value. When we read the same register two times (and the register still | 28 | * value. When we read the same register two times (and the register still |
29 | * contains the same value) these status bits are not set. We work | 29 | * contains the same value) these status bits are not set. We work |
30 | * around this by not polling these bits but only wait a fixed delay. | 30 | * around this by not polling these bits but only wait a fixed delay. |
31 | * | 31 | * |
32 | */ | 32 | */ |
33 | 33 | ||
34 | #include <linux/clk.h> | 34 | #include <linux/clk.h> |
diff --git a/sound/soc/imx/imx-ssi.h b/sound/soc/fsl/imx-ssi.h index 5744e86ca878..5744e86ca878 100644 --- a/sound/soc/imx/imx-ssi.h +++ b/sound/soc/fsl/imx-ssi.h | |||
diff --git a/sound/soc/fsl/mpc8610_hpcd.c b/sound/soc/fsl/mpc8610_hpcd.c index 3fea5a15ffe8..60bcba1bc30e 100644 --- a/sound/soc/fsl/mpc8610_hpcd.c +++ b/sound/soc/fsl/mpc8610_hpcd.c | |||
@@ -14,18 +14,16 @@ | |||
14 | #include <linux/interrupt.h> | 14 | #include <linux/interrupt.h> |
15 | #include <linux/of_device.h> | 15 | #include <linux/of_device.h> |
16 | #include <linux/slab.h> | 16 | #include <linux/slab.h> |
17 | #include <linux/of_i2c.h> | ||
18 | #include <sound/soc.h> | 17 | #include <sound/soc.h> |
19 | #include <asm/fsl_guts.h> | 18 | #include <asm/fsl_guts.h> |
20 | 19 | ||
21 | #include "fsl_dma.h" | 20 | #include "fsl_dma.h" |
22 | #include "fsl_ssi.h" | 21 | #include "fsl_ssi.h" |
22 | #include "fsl_utils.h" | ||
23 | 23 | ||
24 | /* There's only one global utilities register */ | 24 | /* There's only one global utilities register */ |
25 | static phys_addr_t guts_phys; | 25 | static phys_addr_t guts_phys; |
26 | 26 | ||
27 | #define DAI_NAME_SIZE 32 | ||
28 | |||
29 | /** | 27 | /** |
30 | * mpc8610_hpcd_data: machine-specific ASoC device data | 28 | * mpc8610_hpcd_data: machine-specific ASoC device data |
31 | * | 29 | * |
@@ -43,7 +41,6 @@ struct mpc8610_hpcd_data { | |||
43 | unsigned int dma_id[2]; /* 0 = DMA1, 1 = DMA2, etc */ | 41 | unsigned int dma_id[2]; /* 0 = DMA1, 1 = DMA2, etc */ |
44 | unsigned int dma_channel_id[2]; /* 0 = ch 0, 1 = ch 1, etc*/ | 42 | unsigned int dma_channel_id[2]; /* 0 = ch 0, 1 = ch 1, etc*/ |
45 | char codec_dai_name[DAI_NAME_SIZE]; | 43 | char codec_dai_name[DAI_NAME_SIZE]; |
46 | char codec_name[DAI_NAME_SIZE]; | ||
47 | char platform_name[2][DAI_NAME_SIZE]; /* One for each DMA channel */ | 44 | char platform_name[2][DAI_NAME_SIZE]; /* One for each DMA channel */ |
48 | }; | 45 | }; |
49 | 46 | ||
@@ -181,141 +178,6 @@ static struct snd_soc_ops mpc8610_hpcd_ops = { | |||
181 | }; | 178 | }; |
182 | 179 | ||
183 | /** | 180 | /** |
184 | * get_node_by_phandle_name - get a node by its phandle name | ||
185 | * | ||
186 | * This function takes a node, the name of a property in that node, and a | ||
187 | * compatible string. Assuming the property is a phandle to another node, | ||
188 | * it returns that node, (optionally) if that node is compatible. | ||
189 | * | ||
190 | * If the property is not a phandle, or the node it points to is not compatible | ||
191 | * with the specific string, then NULL is returned. | ||
192 | */ | ||
193 | static struct device_node *get_node_by_phandle_name(struct device_node *np, | ||
194 | const char *name, | ||
195 | const char *compatible) | ||
196 | { | ||
197 | const phandle *ph; | ||
198 | int len; | ||
199 | |||
200 | ph = of_get_property(np, name, &len); | ||
201 | if (!ph || (len != sizeof(phandle))) | ||
202 | return NULL; | ||
203 | |||
204 | np = of_find_node_by_phandle(*ph); | ||
205 | if (!np) | ||
206 | return NULL; | ||
207 | |||
208 | if (compatible && !of_device_is_compatible(np, compatible)) { | ||
209 | of_node_put(np); | ||
210 | return NULL; | ||
211 | } | ||
212 | |||
213 | return np; | ||
214 | } | ||
215 | |||
216 | /** | ||
217 | * get_parent_cell_index -- return the cell-index of the parent of a node | ||
218 | * | ||
219 | * Return the value of the cell-index property of the parent of the given | ||
220 | * node. This is used for DMA channel nodes that need to know the DMA ID | ||
221 | * of the controller they are on. | ||
222 | */ | ||
223 | static int get_parent_cell_index(struct device_node *np) | ||
224 | { | ||
225 | struct device_node *parent = of_get_parent(np); | ||
226 | const u32 *iprop; | ||
227 | |||
228 | if (!parent) | ||
229 | return -1; | ||
230 | |||
231 | iprop = of_get_property(parent, "cell-index", NULL); | ||
232 | of_node_put(parent); | ||
233 | |||
234 | if (!iprop) | ||
235 | return -1; | ||
236 | |||
237 | return be32_to_cpup(iprop); | ||
238 | } | ||
239 | |||
240 | /** | ||
241 | * codec_node_dev_name - determine the dev_name for a codec node | ||
242 | * | ||
243 | * This function determines the dev_name for an I2C node. This is the name | ||
244 | * that would be returned by dev_name() if this device_node were part of a | ||
245 | * 'struct device' It's ugly and hackish, but it works. | ||
246 | * | ||
247 | * The dev_name for such devices include the bus number and I2C address. For | ||
248 | * example, "cs4270.0-004f". | ||
249 | */ | ||
250 | static int codec_node_dev_name(struct device_node *np, char *buf, size_t len) | ||
251 | { | ||
252 | const u32 *iprop; | ||
253 | int addr; | ||
254 | char temp[DAI_NAME_SIZE]; | ||
255 | struct i2c_client *i2c; | ||
256 | |||
257 | of_modalias_node(np, temp, DAI_NAME_SIZE); | ||
258 | |||
259 | iprop = of_get_property(np, "reg", NULL); | ||
260 | if (!iprop) | ||
261 | return -EINVAL; | ||
262 | |||
263 | addr = be32_to_cpup(iprop); | ||
264 | |||
265 | /* We need the adapter number */ | ||
266 | i2c = of_find_i2c_device_by_node(np); | ||
267 | if (!i2c) | ||
268 | return -ENODEV; | ||
269 | |||
270 | snprintf(buf, len, "%s.%u-%04x", temp, i2c->adapter->nr, addr); | ||
271 | |||
272 | return 0; | ||
273 | } | ||
274 | |||
275 | static int get_dma_channel(struct device_node *ssi_np, | ||
276 | const char *name, | ||
277 | struct snd_soc_dai_link *dai, | ||
278 | unsigned int *dma_channel_id, | ||
279 | unsigned int *dma_id) | ||
280 | { | ||
281 | struct resource res; | ||
282 | struct device_node *dma_channel_np; | ||
283 | const u32 *iprop; | ||
284 | int ret; | ||
285 | |||
286 | dma_channel_np = get_node_by_phandle_name(ssi_np, name, | ||
287 | "fsl,ssi-dma-channel"); | ||
288 | if (!dma_channel_np) | ||
289 | return -EINVAL; | ||
290 | |||
291 | /* Determine the dev_name for the device_node. This code mimics the | ||
292 | * behavior of of_device_make_bus_id(). We need this because ASoC uses | ||
293 | * the dev_name() of the device to match the platform (DMA) device with | ||
294 | * the CPU (SSI) device. It's all ugly and hackish, but it works (for | ||
295 | * now). | ||
296 | * | ||
297 | * dai->platform name should already point to an allocated buffer. | ||
298 | */ | ||
299 | ret = of_address_to_resource(dma_channel_np, 0, &res); | ||
300 | if (ret) | ||
301 | return ret; | ||
302 | snprintf((char *)dai->platform_name, DAI_NAME_SIZE, "%llx.%s", | ||
303 | (unsigned long long) res.start, dma_channel_np->name); | ||
304 | |||
305 | iprop = of_get_property(dma_channel_np, "cell-index", NULL); | ||
306 | if (!iprop) { | ||
307 | of_node_put(dma_channel_np); | ||
308 | return -EINVAL; | ||
309 | } | ||
310 | |||
311 | *dma_channel_id = be32_to_cpup(iprop); | ||
312 | *dma_id = get_parent_cell_index(dma_channel_np); | ||
313 | of_node_put(dma_channel_np); | ||
314 | |||
315 | return 0; | ||
316 | } | ||
317 | |||
318 | /** | ||
319 | * mpc8610_hpcd_probe: platform probe function for the machine driver | 181 | * mpc8610_hpcd_probe: platform probe function for the machine driver |
320 | * | 182 | * |
321 | * Although this is a machine driver, the SSI node is the "master" node with | 183 | * Although this is a machine driver, the SSI node is the "master" node with |
@@ -352,16 +214,8 @@ static int mpc8610_hpcd_probe(struct platform_device *pdev) | |||
352 | machine_data->dai[0].cpu_dai_name = dev_name(&ssi_pdev->dev); | 214 | machine_data->dai[0].cpu_dai_name = dev_name(&ssi_pdev->dev); |
353 | machine_data->dai[0].ops = &mpc8610_hpcd_ops; | 215 | machine_data->dai[0].ops = &mpc8610_hpcd_ops; |
354 | 216 | ||
355 | /* Determine the codec name, it will be used as the codec DAI name */ | 217 | /* ASoC core can match codec with device node */ |
356 | ret = codec_node_dev_name(codec_np, machine_data->codec_name, | 218 | machine_data->dai[0].codec_of_node = codec_np; |
357 | DAI_NAME_SIZE); | ||
358 | if (ret) { | ||
359 | dev_err(&pdev->dev, "invalid codec node %s\n", | ||
360 | codec_np->full_name); | ||
361 | ret = -EINVAL; | ||
362 | goto error; | ||
363 | } | ||
364 | machine_data->dai[0].codec_name = machine_data->codec_name; | ||
365 | 219 | ||
366 | /* The DAI name from the codec (snd_soc_dai_driver.name) */ | 220 | /* The DAI name from the codec (snd_soc_dai_driver.name) */ |
367 | machine_data->dai[0].codec_dai_name = "cs4270-hifi"; | 221 | machine_data->dai[0].codec_dai_name = "cs4270-hifi"; |
@@ -458,9 +312,10 @@ static int mpc8610_hpcd_probe(struct platform_device *pdev) | |||
458 | 312 | ||
459 | /* Find the playback DMA channel to use. */ | 313 | /* Find the playback DMA channel to use. */ |
460 | machine_data->dai[0].platform_name = machine_data->platform_name[0]; | 314 | machine_data->dai[0].platform_name = machine_data->platform_name[0]; |
461 | ret = get_dma_channel(np, "fsl,playback-dma", &machine_data->dai[0], | 315 | ret = fsl_asoc_get_dma_channel(np, "fsl,playback-dma", |
462 | &machine_data->dma_channel_id[0], | 316 | &machine_data->dai[0], |
463 | &machine_data->dma_id[0]); | 317 | &machine_data->dma_channel_id[0], |
318 | &machine_data->dma_id[0]); | ||
464 | if (ret) { | 319 | if (ret) { |
465 | dev_err(&pdev->dev, "missing/invalid playback DMA phandle\n"); | 320 | dev_err(&pdev->dev, "missing/invalid playback DMA phandle\n"); |
466 | goto error; | 321 | goto error; |
@@ -468,9 +323,10 @@ static int mpc8610_hpcd_probe(struct platform_device *pdev) | |||
468 | 323 | ||
469 | /* Find the capture DMA channel to use. */ | 324 | /* Find the capture DMA channel to use. */ |
470 | machine_data->dai[1].platform_name = machine_data->platform_name[1]; | 325 | machine_data->dai[1].platform_name = machine_data->platform_name[1]; |
471 | ret = get_dma_channel(np, "fsl,capture-dma", &machine_data->dai[1], | 326 | ret = fsl_asoc_get_dma_channel(np, "fsl,capture-dma", |
472 | &machine_data->dma_channel_id[1], | 327 | &machine_data->dai[1], |
473 | &machine_data->dma_id[1]); | 328 | &machine_data->dma_channel_id[1], |
329 | &machine_data->dma_id[1]); | ||
474 | if (ret) { | 330 | if (ret) { |
475 | dev_err(&pdev->dev, "missing/invalid capture DMA phandle\n"); | 331 | dev_err(&pdev->dev, "missing/invalid capture DMA phandle\n"); |
476 | goto error; | 332 | goto error; |
diff --git a/sound/soc/imx/mx27vis-aic32x4.c b/sound/soc/fsl/mx27vis-aic32x4.c index f6d04ad4bb39..f6d04ad4bb39 100644 --- a/sound/soc/imx/mx27vis-aic32x4.c +++ b/sound/soc/fsl/mx27vis-aic32x4.c | |||
diff --git a/sound/soc/fsl/p1022_ds.c b/sound/soc/fsl/p1022_ds.c index 982a1c944983..50adf4032bcc 100644 --- a/sound/soc/fsl/p1022_ds.c +++ b/sound/soc/fsl/p1022_ds.c | |||
@@ -14,12 +14,12 @@ | |||
14 | #include <linux/interrupt.h> | 14 | #include <linux/interrupt.h> |
15 | #include <linux/of_device.h> | 15 | #include <linux/of_device.h> |
16 | #include <linux/slab.h> | 16 | #include <linux/slab.h> |
17 | #include <linux/of_i2c.h> | ||
18 | #include <sound/soc.h> | 17 | #include <sound/soc.h> |
19 | #include <asm/fsl_guts.h> | 18 | #include <asm/fsl_guts.h> |
20 | 19 | ||
21 | #include "fsl_dma.h" | 20 | #include "fsl_dma.h" |
22 | #include "fsl_ssi.h" | 21 | #include "fsl_ssi.h" |
22 | #include "fsl_utils.h" | ||
23 | 23 | ||
24 | /* P1022-specific PMUXCR and DMUXCR bit definitions */ | 24 | /* P1022-specific PMUXCR and DMUXCR bit definitions */ |
25 | 25 | ||
@@ -57,8 +57,6 @@ static inline void guts_set_dmuxcr(struct ccsr_guts __iomem *guts, | |||
57 | /* There's only one global utilities register */ | 57 | /* There's only one global utilities register */ |
58 | static phys_addr_t guts_phys; | 58 | static phys_addr_t guts_phys; |
59 | 59 | ||
60 | #define DAI_NAME_SIZE 32 | ||
61 | |||
62 | /** | 60 | /** |
63 | * machine_data: machine-specific ASoC device data | 61 | * machine_data: machine-specific ASoC device data |
64 | * | 62 | * |
@@ -75,7 +73,6 @@ struct machine_data { | |||
75 | unsigned int ssi_id; /* 0 = SSI1, 1 = SSI2, etc */ | 73 | unsigned int ssi_id; /* 0 = SSI1, 1 = SSI2, etc */ |
76 | unsigned int dma_id[2]; /* 0 = DMA1, 1 = DMA2, etc */ | 74 | unsigned int dma_id[2]; /* 0 = DMA1, 1 = DMA2, etc */ |
77 | unsigned int dma_channel_id[2]; /* 0 = ch 0, 1 = ch 1, etc*/ | 75 | unsigned int dma_channel_id[2]; /* 0 = ch 0, 1 = ch 1, etc*/ |
78 | char codec_name[DAI_NAME_SIZE]; | ||
79 | char platform_name[2][DAI_NAME_SIZE]; /* One for each DMA channel */ | 76 | char platform_name[2][DAI_NAME_SIZE]; /* One for each DMA channel */ |
80 | }; | 77 | }; |
81 | 78 | ||
@@ -191,136 +188,6 @@ static struct snd_soc_ops p1022_ds_ops = { | |||
191 | }; | 188 | }; |
192 | 189 | ||
193 | /** | 190 | /** |
194 | * get_node_by_phandle_name - get a node by its phandle name | ||
195 | * | ||
196 | * This function takes a node, the name of a property in that node, and a | ||
197 | * compatible string. Assuming the property is a phandle to another node, | ||
198 | * it returns that node, (optionally) if that node is compatible. | ||
199 | * | ||
200 | * If the property is not a phandle, or the node it points to is not compatible | ||
201 | * with the specific string, then NULL is returned. | ||
202 | */ | ||
203 | static struct device_node *get_node_by_phandle_name(struct device_node *np, | ||
204 | const char *name, const char *compatible) | ||
205 | { | ||
206 | np = of_parse_phandle(np, name, 0); | ||
207 | if (!np) | ||
208 | return NULL; | ||
209 | |||
210 | if (!of_device_is_compatible(np, compatible)) { | ||
211 | of_node_put(np); | ||
212 | return NULL; | ||
213 | } | ||
214 | |||
215 | return np; | ||
216 | } | ||
217 | |||
218 | /** | ||
219 | * get_parent_cell_index -- return the cell-index of the parent of a node | ||
220 | * | ||
221 | * Return the value of the cell-index property of the parent of the given | ||
222 | * node. This is used for DMA channel nodes that need to know the DMA ID | ||
223 | * of the controller they are on. | ||
224 | */ | ||
225 | static int get_parent_cell_index(struct device_node *np) | ||
226 | { | ||
227 | struct device_node *parent = of_get_parent(np); | ||
228 | const u32 *iprop; | ||
229 | int ret = -1; | ||
230 | |||
231 | if (!parent) | ||
232 | return -1; | ||
233 | |||
234 | iprop = of_get_property(parent, "cell-index", NULL); | ||
235 | if (iprop) | ||
236 | ret = be32_to_cpup(iprop); | ||
237 | |||
238 | of_node_put(parent); | ||
239 | |||
240 | return ret; | ||
241 | } | ||
242 | |||
243 | /** | ||
244 | * codec_node_dev_name - determine the dev_name for a codec node | ||
245 | * | ||
246 | * This function determines the dev_name for an I2C node. This is the name | ||
247 | * that would be returned by dev_name() if this device_node were part of a | ||
248 | * 'struct device' It's ugly and hackish, but it works. | ||
249 | * | ||
250 | * The dev_name for such devices include the bus number and I2C address. For | ||
251 | * example, "cs4270-codec.0-004f". | ||
252 | */ | ||
253 | static int codec_node_dev_name(struct device_node *np, char *buf, size_t len) | ||
254 | { | ||
255 | const u32 *iprop; | ||
256 | int addr; | ||
257 | char temp[DAI_NAME_SIZE]; | ||
258 | struct i2c_client *i2c; | ||
259 | |||
260 | of_modalias_node(np, temp, DAI_NAME_SIZE); | ||
261 | |||
262 | iprop = of_get_property(np, "reg", NULL); | ||
263 | if (!iprop) | ||
264 | return -EINVAL; | ||
265 | |||
266 | addr = be32_to_cpup(iprop); | ||
267 | |||
268 | /* We need the adapter number */ | ||
269 | i2c = of_find_i2c_device_by_node(np); | ||
270 | if (!i2c) | ||
271 | return -ENODEV; | ||
272 | |||
273 | snprintf(buf, len, "%s.%u-%04x", temp, i2c->adapter->nr, addr); | ||
274 | |||
275 | return 0; | ||
276 | } | ||
277 | |||
278 | static int get_dma_channel(struct device_node *ssi_np, | ||
279 | const char *name, | ||
280 | struct snd_soc_dai_link *dai, | ||
281 | unsigned int *dma_channel_id, | ||
282 | unsigned int *dma_id) | ||
283 | { | ||
284 | struct resource res; | ||
285 | struct device_node *dma_channel_np; | ||
286 | const u32 *iprop; | ||
287 | int ret; | ||
288 | |||
289 | dma_channel_np = get_node_by_phandle_name(ssi_np, name, | ||
290 | "fsl,ssi-dma-channel"); | ||
291 | if (!dma_channel_np) | ||
292 | return -EINVAL; | ||
293 | |||
294 | /* Determine the dev_name for the device_node. This code mimics the | ||
295 | * behavior of of_device_make_bus_id(). We need this because ASoC uses | ||
296 | * the dev_name() of the device to match the platform (DMA) device with | ||
297 | * the CPU (SSI) device. It's all ugly and hackish, but it works (for | ||
298 | * now). | ||
299 | * | ||
300 | * dai->platform name should already point to an allocated buffer. | ||
301 | */ | ||
302 | ret = of_address_to_resource(dma_channel_np, 0, &res); | ||
303 | if (ret) { | ||
304 | of_node_put(dma_channel_np); | ||
305 | return ret; | ||
306 | } | ||
307 | snprintf((char *)dai->platform_name, DAI_NAME_SIZE, "%llx.%s", | ||
308 | (unsigned long long) res.start, dma_channel_np->name); | ||
309 | |||
310 | iprop = of_get_property(dma_channel_np, "cell-index", NULL); | ||
311 | if (!iprop) { | ||
312 | of_node_put(dma_channel_np); | ||
313 | return -EINVAL; | ||
314 | } | ||
315 | |||
316 | *dma_channel_id = be32_to_cpup(iprop); | ||
317 | *dma_id = get_parent_cell_index(dma_channel_np); | ||
318 | of_node_put(dma_channel_np); | ||
319 | |||
320 | return 0; | ||
321 | } | ||
322 | |||
323 | /** | ||
324 | * p1022_ds_probe: platform probe function for the machine driver | 191 | * p1022_ds_probe: platform probe function for the machine driver |
325 | * | 192 | * |
326 | * Although this is a machine driver, the SSI node is the "master" node with | 193 | * Although this is a machine driver, the SSI node is the "master" node with |
@@ -357,15 +224,8 @@ static int p1022_ds_probe(struct platform_device *pdev) | |||
357 | mdata->dai[0].cpu_dai_name = dev_name(&ssi_pdev->dev); | 224 | mdata->dai[0].cpu_dai_name = dev_name(&ssi_pdev->dev); |
358 | mdata->dai[0].ops = &p1022_ds_ops; | 225 | mdata->dai[0].ops = &p1022_ds_ops; |
359 | 226 | ||
360 | /* Determine the codec name, it will be used as the codec DAI name */ | 227 | /* ASoC core can match codec with device node */ |
361 | ret = codec_node_dev_name(codec_np, mdata->codec_name, DAI_NAME_SIZE); | 228 | mdata->dai[0].codec_of_node = codec_np; |
362 | if (ret) { | ||
363 | dev_err(&pdev->dev, "invalid codec node %s\n", | ||
364 | codec_np->full_name); | ||
365 | ret = -EINVAL; | ||
366 | goto error; | ||
367 | } | ||
368 | mdata->dai[0].codec_name = mdata->codec_name; | ||
369 | 229 | ||
370 | /* We register two DAIs per SSI, one for playback and the other for | 230 | /* We register two DAIs per SSI, one for playback and the other for |
371 | * capture. We support codecs that have separate DAIs for both playback | 231 | * capture. We support codecs that have separate DAIs for both playback |
@@ -462,9 +322,9 @@ static int p1022_ds_probe(struct platform_device *pdev) | |||
462 | 322 | ||
463 | /* Find the playback DMA channel to use. */ | 323 | /* Find the playback DMA channel to use. */ |
464 | mdata->dai[0].platform_name = mdata->platform_name[0]; | 324 | mdata->dai[0].platform_name = mdata->platform_name[0]; |
465 | ret = get_dma_channel(np, "fsl,playback-dma", &mdata->dai[0], | 325 | ret = fsl_asoc_get_dma_channel(np, "fsl,playback-dma", &mdata->dai[0], |
466 | &mdata->dma_channel_id[0], | 326 | &mdata->dma_channel_id[0], |
467 | &mdata->dma_id[0]); | 327 | &mdata->dma_id[0]); |
468 | if (ret) { | 328 | if (ret) { |
469 | dev_err(&pdev->dev, "missing/invalid playback DMA phandle\n"); | 329 | dev_err(&pdev->dev, "missing/invalid playback DMA phandle\n"); |
470 | goto error; | 330 | goto error; |
@@ -472,9 +332,9 @@ static int p1022_ds_probe(struct platform_device *pdev) | |||
472 | 332 | ||
473 | /* Find the capture DMA channel to use. */ | 333 | /* Find the capture DMA channel to use. */ |
474 | mdata->dai[1].platform_name = mdata->platform_name[1]; | 334 | mdata->dai[1].platform_name = mdata->platform_name[1]; |
475 | ret = get_dma_channel(np, "fsl,capture-dma", &mdata->dai[1], | 335 | ret = fsl_asoc_get_dma_channel(np, "fsl,capture-dma", &mdata->dai[1], |
476 | &mdata->dma_channel_id[1], | 336 | &mdata->dma_channel_id[1], |
477 | &mdata->dma_id[1]); | 337 | &mdata->dma_id[1]); |
478 | if (ret) { | 338 | if (ret) { |
479 | dev_err(&pdev->dev, "missing/invalid capture DMA phandle\n"); | 339 | dev_err(&pdev->dev, "missing/invalid capture DMA phandle\n"); |
480 | goto error; | 340 | goto error; |
diff --git a/sound/soc/imx/phycore-ac97.c b/sound/soc/fsl/phycore-ac97.c index f8da6dd115ed..f8da6dd115ed 100644 --- a/sound/soc/imx/phycore-ac97.c +++ b/sound/soc/fsl/phycore-ac97.c | |||
diff --git a/sound/soc/imx/wm1133-ev1.c b/sound/soc/fsl/wm1133-ev1.c index fe54a69073e5..fe54a69073e5 100644 --- a/sound/soc/imx/wm1133-ev1.c +++ b/sound/soc/fsl/wm1133-ev1.c | |||
diff --git a/sound/soc/generic/Kconfig b/sound/soc/generic/Kconfig new file mode 100644 index 000000000000..610f61251640 --- /dev/null +++ b/sound/soc/generic/Kconfig | |||
@@ -0,0 +1,4 @@ | |||
1 | config SND_SIMPLE_CARD | ||
2 | tristate "ASoC Simple sound card support" | ||
3 | help | ||
4 | This option enables generic simple sound card support | ||
diff --git a/sound/soc/generic/Makefile b/sound/soc/generic/Makefile new file mode 100644 index 000000000000..9c3b246792bf --- /dev/null +++ b/sound/soc/generic/Makefile | |||
@@ -0,0 +1,3 @@ | |||
1 | snd-soc-simple-card-objs := simple-card.o | ||
2 | |||
3 | obj-$(CONFIG_SND_SIMPLE_CARD) += snd-soc-simple-card.o | ||
diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c new file mode 100644 index 000000000000..b4b4cab30232 --- /dev/null +++ b/sound/soc/generic/simple-card.c | |||
@@ -0,0 +1,114 @@ | |||
1 | /* | ||
2 | * ASoC simple sound card support | ||
3 | * | ||
4 | * Copyright (C) 2012 Renesas Solutions Corp. | ||
5 | * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License version 2 as | ||
9 | * published by the Free Software Foundation. | ||
10 | */ | ||
11 | |||
12 | #include <linux/platform_device.h> | ||
13 | #include <linux/module.h> | ||
14 | #include <sound/simple_card.h> | ||
15 | |||
16 | #define asoc_simple_get_card_info(p) \ | ||
17 | container_of(p->dai_link, struct asoc_simple_card_info, snd_link) | ||
18 | |||
19 | static int asoc_simple_card_dai_init(struct snd_soc_pcm_runtime *rtd) | ||
20 | { | ||
21 | struct asoc_simple_card_info *cinfo = asoc_simple_get_card_info(rtd); | ||
22 | struct asoc_simple_dai_init_info *iinfo = cinfo->init; | ||
23 | struct snd_soc_dai *codec = rtd->codec_dai; | ||
24 | struct snd_soc_dai *cpu = rtd->cpu_dai; | ||
25 | unsigned int cpu_daifmt = iinfo->fmt | iinfo->cpu_daifmt; | ||
26 | unsigned int codec_daifmt = iinfo->fmt | iinfo->codec_daifmt; | ||
27 | int ret; | ||
28 | |||
29 | if (codec_daifmt) { | ||
30 | ret = snd_soc_dai_set_fmt(codec, codec_daifmt); | ||
31 | if (ret < 0) | ||
32 | return ret; | ||
33 | } | ||
34 | |||
35 | if (iinfo->sysclk) { | ||
36 | ret = snd_soc_dai_set_sysclk(codec, 0, iinfo->sysclk, 0); | ||
37 | if (ret < 0) | ||
38 | return ret; | ||
39 | } | ||
40 | |||
41 | if (cpu_daifmt) { | ||
42 | ret = snd_soc_dai_set_fmt(cpu, cpu_daifmt); | ||
43 | if (ret < 0) | ||
44 | return ret; | ||
45 | } | ||
46 | |||
47 | return 0; | ||
48 | } | ||
49 | |||
50 | static int asoc_simple_card_probe(struct platform_device *pdev) | ||
51 | { | ||
52 | struct asoc_simple_card_info *cinfo = pdev->dev.platform_data; | ||
53 | |||
54 | if (!cinfo) { | ||
55 | dev_err(&pdev->dev, "no info for asoc-simple-card\n"); | ||
56 | return -EINVAL; | ||
57 | } | ||
58 | |||
59 | if (!cinfo->name || | ||
60 | !cinfo->card || | ||
61 | !cinfo->cpu_dai || | ||
62 | !cinfo->codec || | ||
63 | !cinfo->platform || | ||
64 | !cinfo->codec_dai) { | ||
65 | dev_err(&pdev->dev, "insufficient asoc_simple_card_info settings\n"); | ||
66 | return -EINVAL; | ||
67 | } | ||
68 | |||
69 | /* | ||
70 | * init snd_soc_dai_link | ||
71 | */ | ||
72 | cinfo->snd_link.name = cinfo->name; | ||
73 | cinfo->snd_link.stream_name = cinfo->name; | ||
74 | cinfo->snd_link.cpu_dai_name = cinfo->cpu_dai; | ||
75 | cinfo->snd_link.platform_name = cinfo->platform; | ||
76 | cinfo->snd_link.codec_name = cinfo->codec; | ||
77 | cinfo->snd_link.codec_dai_name = cinfo->codec_dai; | ||
78 | |||
79 | /* enable snd_link.init if cinfo has settings */ | ||
80 | if (cinfo->init) | ||
81 | cinfo->snd_link.init = asoc_simple_card_dai_init; | ||
82 | |||
83 | /* | ||
84 | * init snd_soc_card | ||
85 | */ | ||
86 | cinfo->snd_card.name = cinfo->card; | ||
87 | cinfo->snd_card.owner = THIS_MODULE; | ||
88 | cinfo->snd_card.dai_link = &cinfo->snd_link; | ||
89 | cinfo->snd_card.num_links = 1; | ||
90 | cinfo->snd_card.dev = &pdev->dev; | ||
91 | |||
92 | return snd_soc_register_card(&cinfo->snd_card); | ||
93 | } | ||
94 | |||
95 | static int asoc_simple_card_remove(struct platform_device *pdev) | ||
96 | { | ||
97 | struct asoc_simple_card_info *cinfo = pdev->dev.platform_data; | ||
98 | |||
99 | return snd_soc_unregister_card(&cinfo->snd_card); | ||
100 | } | ||
101 | |||
102 | static struct platform_driver asoc_simple_card = { | ||
103 | .driver = { | ||
104 | .name = "asoc-simple-card", | ||
105 | }, | ||
106 | .probe = asoc_simple_card_probe, | ||
107 | .remove = asoc_simple_card_remove, | ||
108 | }; | ||
109 | |||
110 | module_platform_driver(asoc_simple_card); | ||
111 | |||
112 | MODULE_LICENSE("GPL"); | ||
113 | MODULE_DESCRIPTION("ASoC Simple Sound Card"); | ||
114 | MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>"); | ||
diff --git a/sound/soc/imx/Kconfig b/sound/soc/imx/Kconfig deleted file mode 100644 index d83e5d0b5d52..000000000000 --- a/sound/soc/imx/Kconfig +++ /dev/null | |||
@@ -1,79 +0,0 @@ | |||
1 | menuconfig SND_IMX_SOC | ||
2 | tristate "SoC Audio for Freescale i.MX CPUs" | ||
3 | depends on ARCH_MXC | ||
4 | help | ||
5 | Say Y or M if you want to add support for codecs attached to | ||
6 | the i.MX SSI interface. | ||
7 | |||
8 | |||
9 | if SND_IMX_SOC | ||
10 | |||
11 | config SND_SOC_IMX_SSI | ||
12 | tristate | ||
13 | |||
14 | config SND_SOC_IMX_PCM | ||
15 | tristate | ||
16 | |||
17 | config SND_MXC_SOC_FIQ | ||
18 | tristate | ||
19 | select FIQ | ||
20 | select SND_SOC_IMX_PCM | ||
21 | |||
22 | config SND_MXC_SOC_MX2 | ||
23 | select SND_SOC_DMAENGINE_PCM | ||
24 | tristate | ||
25 | select SND_SOC_IMX_PCM | ||
26 | |||
27 | config SND_SOC_IMX_AUDMUX | ||
28 | tristate | ||
29 | |||
30 | config SND_MXC_SOC_WM1133_EV1 | ||
31 | tristate "Audio on the i.MX31ADS with WM1133-EV1 fitted" | ||
32 | depends on MACH_MX31ADS_WM1133_EV1 && EXPERIMENTAL | ||
33 | select SND_SOC_WM8350 | ||
34 | select SND_MXC_SOC_FIQ | ||
35 | select SND_SOC_IMX_AUDMUX | ||
36 | select SND_SOC_IMX_SSI | ||
37 | help | ||
38 | Enable support for audio on the i.MX31ADS with the WM1133-EV1 | ||
39 | PMIC board with WM8835x fitted. | ||
40 | |||
41 | config SND_SOC_MX27VIS_AIC32X4 | ||
42 | tristate "SoC audio support for Visstrim M10 boards" | ||
43 | depends on MACH_IMX27_VISSTRIM_M10 && I2C | ||
44 | select SND_SOC_TLV320AIC32X4 | ||
45 | select SND_MXC_SOC_MX2 | ||
46 | select SND_SOC_IMX_AUDMUX | ||
47 | select SND_SOC_IMX_SSI | ||
48 | help | ||
49 | Say Y if you want to add support for SoC audio on Visstrim SM10 | ||
50 | board with TLV320AIC32X4 codec. | ||
51 | |||
52 | config SND_SOC_PHYCORE_AC97 | ||
53 | tristate "SoC Audio support for Phytec phyCORE (and phyCARD) boards" | ||
54 | depends on MACH_PCM043 || MACH_PCA100 | ||
55 | select SND_SOC_AC97_BUS | ||
56 | select SND_SOC_WM9712 | ||
57 | select SND_MXC_SOC_FIQ | ||
58 | select SND_SOC_IMX_AUDMUX | ||
59 | select SND_SOC_IMX_SSI | ||
60 | help | ||
61 | Say Y if you want to add support for SoC audio on Phytec phyCORE | ||
62 | and phyCARD boards in AC97 mode | ||
63 | |||
64 | config SND_SOC_EUKREA_TLV320 | ||
65 | tristate "Eukrea TLV320" | ||
66 | depends on MACH_EUKREA_MBIMX27_BASEBOARD \ | ||
67 | || MACH_EUKREA_MBIMXSD25_BASEBOARD \ | ||
68 | || MACH_EUKREA_MBIMXSD35_BASEBOARD \ | ||
69 | || MACH_EUKREA_MBIMXSD51_BASEBOARD | ||
70 | depends on I2C | ||
71 | select SND_SOC_TLV320AIC23 | ||
72 | select SND_MXC_SOC_FIQ | ||
73 | select SND_SOC_IMX_AUDMUX | ||
74 | select SND_SOC_IMX_SSI | ||
75 | help | ||
76 | Enable I2S based access to the TLV320AIC23B codec attached | ||
77 | to the SSI interface | ||
78 | |||
79 | endif # SND_IMX_SOC | ||
diff --git a/sound/soc/imx/Makefile b/sound/soc/imx/Makefile deleted file mode 100644 index f5db3e92d0d1..000000000000 --- a/sound/soc/imx/Makefile +++ /dev/null | |||
@@ -1,22 +0,0 @@ | |||
1 | # i.MX Platform Support | ||
2 | snd-soc-imx-ssi-objs := imx-ssi.o | ||
3 | snd-soc-imx-audmux-objs := imx-audmux.o | ||
4 | |||
5 | obj-$(CONFIG_SND_SOC_IMX_SSI) += snd-soc-imx-ssi.o | ||
6 | obj-$(CONFIG_SND_SOC_IMX_AUDMUX) += snd-soc-imx-audmux.o | ||
7 | |||
8 | obj-$(CONFIG_SND_SOC_IMX_PCM) += snd-soc-imx-pcm.o | ||
9 | snd-soc-imx-pcm-y := imx-pcm.o | ||
10 | snd-soc-imx-pcm-$(CONFIG_SND_MXC_SOC_FIQ) += imx-pcm-fiq.o | ||
11 | snd-soc-imx-pcm-$(CONFIG_SND_MXC_SOC_MX2) += imx-pcm-dma-mx2.o | ||
12 | |||
13 | # i.MX Machine Support | ||
14 | snd-soc-eukrea-tlv320-objs := eukrea-tlv320.o | ||
15 | snd-soc-phycore-ac97-objs := phycore-ac97.o | ||
16 | snd-soc-mx27vis-aic32x4-objs := mx27vis-aic32x4.o | ||
17 | snd-soc-wm1133-ev1-objs := wm1133-ev1.o | ||
18 | |||
19 | obj-$(CONFIG_SND_SOC_EUKREA_TLV320) += snd-soc-eukrea-tlv320.o | ||
20 | obj-$(CONFIG_SND_SOC_PHYCORE_AC97) += snd-soc-phycore-ac97.o | ||
21 | obj-$(CONFIG_SND_SOC_MX27VIS_AIC32X4) += snd-soc-mx27vis-aic32x4.o | ||
22 | obj-$(CONFIG_SND_MXC_SOC_WM1133_EV1) += snd-soc-wm1133-ev1.o | ||
diff --git a/sound/soc/jz4740/jz4740-i2s.c b/sound/soc/jz4740/jz4740-i2s.c index a5af7c42e62b..41349670adab 100644 --- a/sound/soc/jz4740/jz4740-i2s.c +++ b/sound/soc/jz4740/jz4740-i2s.c | |||
@@ -346,7 +346,7 @@ static void jz4740_i2c_init_pcm_config(struct jz4740_i2s *i2s) | |||
346 | 346 | ||
347 | /* Playback */ | 347 | /* Playback */ |
348 | dma_config = &i2s->pcm_config_playback.dma_config; | 348 | dma_config = &i2s->pcm_config_playback.dma_config; |
349 | dma_config->src_width = JZ4740_DMA_WIDTH_32BIT, | 349 | dma_config->src_width = JZ4740_DMA_WIDTH_32BIT; |
350 | dma_config->transfer_size = JZ4740_DMA_TRANSFER_SIZE_16BYTE; | 350 | dma_config->transfer_size = JZ4740_DMA_TRANSFER_SIZE_16BYTE; |
351 | dma_config->request_type = JZ4740_DMA_TYPE_AIC_TRANSMIT; | 351 | dma_config->request_type = JZ4740_DMA_TYPE_AIC_TRANSMIT; |
352 | dma_config->flags = JZ4740_DMA_SRC_AUTOINC; | 352 | dma_config->flags = JZ4740_DMA_SRC_AUTOINC; |
@@ -355,7 +355,7 @@ static void jz4740_i2c_init_pcm_config(struct jz4740_i2s *i2s) | |||
355 | 355 | ||
356 | /* Capture */ | 356 | /* Capture */ |
357 | dma_config = &i2s->pcm_config_capture.dma_config; | 357 | dma_config = &i2s->pcm_config_capture.dma_config; |
358 | dma_config->dst_width = JZ4740_DMA_WIDTH_32BIT, | 358 | dma_config->dst_width = JZ4740_DMA_WIDTH_32BIT; |
359 | dma_config->transfer_size = JZ4740_DMA_TRANSFER_SIZE_16BYTE; | 359 | dma_config->transfer_size = JZ4740_DMA_TRANSFER_SIZE_16BYTE; |
360 | dma_config->request_type = JZ4740_DMA_TYPE_AIC_RECEIVE; | 360 | dma_config->request_type = JZ4740_DMA_TYPE_AIC_RECEIVE; |
361 | dma_config->flags = JZ4740_DMA_DST_AUTOINC; | 361 | dma_config->flags = JZ4740_DMA_DST_AUTOINC; |
diff --git a/sound/soc/mxs/mxs-pcm.c b/sound/soc/mxs/mxs-pcm.c index e373fbbc97a0..373dec90579f 100644 --- a/sound/soc/mxs/mxs-pcm.c +++ b/sound/soc/mxs/mxs-pcm.c | |||
@@ -220,28 +220,16 @@ static struct snd_soc_platform_driver mxs_soc_platform = { | |||
220 | .pcm_free = mxs_pcm_free, | 220 | .pcm_free = mxs_pcm_free, |
221 | }; | 221 | }; |
222 | 222 | ||
223 | static int __devinit mxs_soc_platform_probe(struct platform_device *pdev) | 223 | int __devinit mxs_pcm_platform_register(struct device *dev) |
224 | { | 224 | { |
225 | return snd_soc_register_platform(&pdev->dev, &mxs_soc_platform); | 225 | return snd_soc_register_platform(dev, &mxs_soc_platform); |
226 | } | 226 | } |
227 | EXPORT_SYMBOL_GPL(mxs_pcm_platform_register); | ||
227 | 228 | ||
228 | static int __devexit mxs_soc_platform_remove(struct platform_device *pdev) | 229 | void __devexit mxs_pcm_platform_unregister(struct device *dev) |
229 | { | 230 | { |
230 | snd_soc_unregister_platform(&pdev->dev); | 231 | snd_soc_unregister_platform(dev); |
231 | |||
232 | return 0; | ||
233 | } | 232 | } |
234 | 233 | EXPORT_SYMBOL_GPL(mxs_pcm_platform_unregister); | |
235 | static struct platform_driver mxs_pcm_driver = { | ||
236 | .driver = { | ||
237 | .name = "mxs-pcm-audio", | ||
238 | .owner = THIS_MODULE, | ||
239 | }, | ||
240 | .probe = mxs_soc_platform_probe, | ||
241 | .remove = __devexit_p(mxs_soc_platform_remove), | ||
242 | }; | ||
243 | |||
244 | module_platform_driver(mxs_pcm_driver); | ||
245 | 234 | ||
246 | MODULE_LICENSE("GPL"); | 235 | MODULE_LICENSE("GPL"); |
247 | MODULE_ALIAS("platform:mxs-pcm-audio"); | ||
diff --git a/sound/soc/mxs/mxs-pcm.h b/sound/soc/mxs/mxs-pcm.h index 5f01a9124b3d..35ba2ca42384 100644 --- a/sound/soc/mxs/mxs-pcm.h +++ b/sound/soc/mxs/mxs-pcm.h | |||
@@ -24,4 +24,7 @@ struct mxs_pcm_dma_params { | |||
24 | int chan_num; | 24 | int chan_num; |
25 | }; | 25 | }; |
26 | 26 | ||
27 | int mxs_pcm_platform_register(struct device *dev); | ||
28 | void mxs_pcm_platform_unregister(struct device *dev); | ||
29 | |||
27 | #endif | 30 | #endif |
diff --git a/sound/soc/mxs/mxs-saif.c b/sound/soc/mxs/mxs-saif.c index 7fd224bb7324..aba71bfa33b1 100644 --- a/sound/soc/mxs/mxs-saif.c +++ b/sound/soc/mxs/mxs-saif.c | |||
@@ -18,6 +18,8 @@ | |||
18 | 18 | ||
19 | #include <linux/module.h> | 19 | #include <linux/module.h> |
20 | #include <linux/init.h> | 20 | #include <linux/init.h> |
21 | #include <linux/of.h> | ||
22 | #include <linux/of_device.h> | ||
21 | #include <linux/platform_device.h> | 23 | #include <linux/platform_device.h> |
22 | #include <linux/slab.h> | 24 | #include <linux/slab.h> |
23 | #include <linux/dma-mapping.h> | 25 | #include <linux/dma-mapping.h> |
@@ -621,37 +623,57 @@ static irqreturn_t mxs_saif_irq(int irq, void *dev_id) | |||
621 | return IRQ_HANDLED; | 623 | return IRQ_HANDLED; |
622 | } | 624 | } |
623 | 625 | ||
624 | static int mxs_saif_probe(struct platform_device *pdev) | 626 | static int __devinit mxs_saif_probe(struct platform_device *pdev) |
625 | { | 627 | { |
628 | struct device_node *np = pdev->dev.of_node; | ||
626 | struct resource *iores, *dmares; | 629 | struct resource *iores, *dmares; |
627 | struct mxs_saif *saif; | 630 | struct mxs_saif *saif; |
628 | struct mxs_saif_platform_data *pdata; | 631 | struct mxs_saif_platform_data *pdata; |
629 | struct pinctrl *pinctrl; | 632 | struct pinctrl *pinctrl; |
630 | int ret = 0; | 633 | int ret = 0; |
631 | 634 | ||
632 | if (pdev->id >= ARRAY_SIZE(mxs_saif)) | 635 | |
636 | if (!np && pdev->id >= ARRAY_SIZE(mxs_saif)) | ||
633 | return -EINVAL; | 637 | return -EINVAL; |
634 | 638 | ||
635 | saif = devm_kzalloc(&pdev->dev, sizeof(*saif), GFP_KERNEL); | 639 | saif = devm_kzalloc(&pdev->dev, sizeof(*saif), GFP_KERNEL); |
636 | if (!saif) | 640 | if (!saif) |
637 | return -ENOMEM; | 641 | return -ENOMEM; |
638 | 642 | ||
639 | mxs_saif[pdev->id] = saif; | 643 | if (np) { |
640 | saif->id = pdev->id; | 644 | struct device_node *master; |
641 | 645 | saif->id = of_alias_get_id(np, "saif"); | |
642 | pdata = pdev->dev.platform_data; | 646 | if (saif->id < 0) |
643 | if (pdata && !pdata->master_mode) { | 647 | return saif->id; |
644 | saif->master_id = pdata->master_id; | 648 | /* |
645 | if (saif->master_id < 0 || | 649 | * If there is no "fsl,saif-master" phandle, it's a saif |
646 | saif->master_id >= ARRAY_SIZE(mxs_saif) || | 650 | * master. Otherwise, it's a slave and its phandle points |
647 | saif->master_id == saif->id) { | 651 | * to the master. |
648 | dev_err(&pdev->dev, "get wrong master id\n"); | 652 | */ |
649 | return -EINVAL; | 653 | master = of_parse_phandle(np, "fsl,saif-master", 0); |
654 | if (!master) { | ||
655 | saif->master_id = saif->id; | ||
656 | } else { | ||
657 | saif->master_id = of_alias_get_id(master, "saif"); | ||
658 | if (saif->master_id < 0) | ||
659 | return saif->master_id; | ||
650 | } | 660 | } |
651 | } else { | 661 | } else { |
652 | saif->master_id = saif->id; | 662 | saif->id = pdev->id; |
663 | pdata = pdev->dev.platform_data; | ||
664 | if (pdata && !pdata->master_mode) | ||
665 | saif->master_id = pdata->master_id; | ||
666 | else | ||
667 | saif->master_id = saif->id; | ||
668 | } | ||
669 | |||
670 | if (saif->master_id < 0 || saif->master_id >= ARRAY_SIZE(mxs_saif)) { | ||
671 | dev_err(&pdev->dev, "get wrong master id\n"); | ||
672 | return -EINVAL; | ||
653 | } | 673 | } |
654 | 674 | ||
675 | mxs_saif[saif->id] = saif; | ||
676 | |||
655 | pinctrl = devm_pinctrl_get_select_default(&pdev->dev); | 677 | pinctrl = devm_pinctrl_get_select_default(&pdev->dev); |
656 | if (IS_ERR(pinctrl)) { | 678 | if (IS_ERR(pinctrl)) { |
657 | ret = PTR_ERR(pinctrl); | 679 | ret = PTR_ERR(pinctrl); |
@@ -677,12 +699,19 @@ static int mxs_saif_probe(struct platform_device *pdev) | |||
677 | 699 | ||
678 | dmares = platform_get_resource(pdev, IORESOURCE_DMA, 0); | 700 | dmares = platform_get_resource(pdev, IORESOURCE_DMA, 0); |
679 | if (!dmares) { | 701 | if (!dmares) { |
680 | ret = -ENODEV; | 702 | /* |
681 | dev_err(&pdev->dev, "failed to get dma resource: %d\n", | 703 | * TODO: This is a temporary solution and should be changed |
682 | ret); | 704 | * to use generic DMA binding later when the helplers get in. |
683 | goto failed_get_resource; | 705 | */ |
706 | ret = of_property_read_u32(np, "fsl,saif-dma-channel", | ||
707 | &saif->dma_param.chan_num); | ||
708 | if (ret) { | ||
709 | dev_err(&pdev->dev, "failed to get dma channel\n"); | ||
710 | goto failed_get_resource; | ||
711 | } | ||
712 | } else { | ||
713 | saif->dma_param.chan_num = dmares->start; | ||
684 | } | 714 | } |
685 | saif->dma_param.chan_num = dmares->start; | ||
686 | 715 | ||
687 | saif->irq = platform_get_irq(pdev, 0); | 716 | saif->irq = platform_get_irq(pdev, 0); |
688 | if (saif->irq < 0) { | 717 | if (saif->irq < 0) { |
@@ -716,24 +745,14 @@ static int mxs_saif_probe(struct platform_device *pdev) | |||
716 | goto failed_get_resource; | 745 | goto failed_get_resource; |
717 | } | 746 | } |
718 | 747 | ||
719 | saif->soc_platform_pdev = platform_device_alloc( | 748 | ret = mxs_pcm_platform_register(&pdev->dev); |
720 | "mxs-pcm-audio", pdev->id); | ||
721 | if (!saif->soc_platform_pdev) { | ||
722 | ret = -ENOMEM; | ||
723 | goto failed_pdev_alloc; | ||
724 | } | ||
725 | |||
726 | platform_set_drvdata(saif->soc_platform_pdev, saif); | ||
727 | ret = platform_device_add(saif->soc_platform_pdev); | ||
728 | if (ret) { | 749 | if (ret) { |
729 | dev_err(&pdev->dev, "failed to add soc platform device\n"); | 750 | dev_err(&pdev->dev, "register PCM failed: %d\n", ret); |
730 | goto failed_pdev_add; | 751 | goto failed_pdev_alloc; |
731 | } | 752 | } |
732 | 753 | ||
733 | return 0; | 754 | return 0; |
734 | 755 | ||
735 | failed_pdev_add: | ||
736 | platform_device_put(saif->soc_platform_pdev); | ||
737 | failed_pdev_alloc: | 756 | failed_pdev_alloc: |
738 | snd_soc_unregister_dai(&pdev->dev); | 757 | snd_soc_unregister_dai(&pdev->dev); |
739 | failed_get_resource: | 758 | failed_get_resource: |
@@ -746,13 +765,19 @@ static int __devexit mxs_saif_remove(struct platform_device *pdev) | |||
746 | { | 765 | { |
747 | struct mxs_saif *saif = platform_get_drvdata(pdev); | 766 | struct mxs_saif *saif = platform_get_drvdata(pdev); |
748 | 767 | ||
749 | platform_device_unregister(saif->soc_platform_pdev); | 768 | mxs_pcm_platform_unregister(&pdev->dev); |
750 | snd_soc_unregister_dai(&pdev->dev); | 769 | snd_soc_unregister_dai(&pdev->dev); |
751 | clk_put(saif->clk); | 770 | clk_put(saif->clk); |
752 | 771 | ||
753 | return 0; | 772 | return 0; |
754 | } | 773 | } |
755 | 774 | ||
775 | static const struct of_device_id mxs_saif_dt_ids[] = { | ||
776 | { .compatible = "fsl,imx28-saif", }, | ||
777 | { /* sentinel */ } | ||
778 | }; | ||
779 | MODULE_DEVICE_TABLE(of, mxs_saif_dt_ids); | ||
780 | |||
756 | static struct platform_driver mxs_saif_driver = { | 781 | static struct platform_driver mxs_saif_driver = { |
757 | .probe = mxs_saif_probe, | 782 | .probe = mxs_saif_probe, |
758 | .remove = __devexit_p(mxs_saif_remove), | 783 | .remove = __devexit_p(mxs_saif_remove), |
@@ -760,6 +785,7 @@ static struct platform_driver mxs_saif_driver = { | |||
760 | .driver = { | 785 | .driver = { |
761 | .name = "mxs-saif", | 786 | .name = "mxs-saif", |
762 | .owner = THIS_MODULE, | 787 | .owner = THIS_MODULE, |
788 | .of_match_table = mxs_saif_dt_ids, | ||
763 | }, | 789 | }, |
764 | }; | 790 | }; |
765 | 791 | ||
diff --git a/sound/soc/mxs/mxs-saif.h b/sound/soc/mxs/mxs-saif.h index 12c91e4eb941..3cb342e5bc90 100644 --- a/sound/soc/mxs/mxs-saif.h +++ b/sound/soc/mxs/mxs-saif.h | |||
@@ -123,7 +123,6 @@ struct mxs_saif { | |||
123 | unsigned int cur_rate; | 123 | unsigned int cur_rate; |
124 | unsigned int ongoing; | 124 | unsigned int ongoing; |
125 | 125 | ||
126 | struct platform_device *soc_platform_pdev; | ||
127 | u32 fifo_underrun; | 126 | u32 fifo_underrun; |
128 | u32 fifo_overrun; | 127 | u32 fifo_overrun; |
129 | }; | 128 | }; |
diff --git a/sound/soc/mxs/mxs-sgtl5000.c b/sound/soc/mxs/mxs-sgtl5000.c index 60f052b7cf22..3e6e8764b2e6 100644 --- a/sound/soc/mxs/mxs-sgtl5000.c +++ b/sound/soc/mxs/mxs-sgtl5000.c | |||
@@ -18,6 +18,8 @@ | |||
18 | 18 | ||
19 | #include <linux/module.h> | 19 | #include <linux/module.h> |
20 | #include <linux/device.h> | 20 | #include <linux/device.h> |
21 | #include <linux/of.h> | ||
22 | #include <linux/of_device.h> | ||
21 | #include <sound/core.h> | 23 | #include <sound/core.h> |
22 | #include <sound/pcm.h> | 24 | #include <sound/pcm.h> |
23 | #include <sound/soc.h> | 25 | #include <sound/soc.h> |
@@ -90,7 +92,7 @@ static struct snd_soc_dai_link mxs_sgtl5000_dai[] = { | |||
90 | .codec_dai_name = "sgtl5000", | 92 | .codec_dai_name = "sgtl5000", |
91 | .codec_name = "sgtl5000.0-000a", | 93 | .codec_name = "sgtl5000.0-000a", |
92 | .cpu_dai_name = "mxs-saif.0", | 94 | .cpu_dai_name = "mxs-saif.0", |
93 | .platform_name = "mxs-pcm-audio.0", | 95 | .platform_name = "mxs-saif.0", |
94 | .ops = &mxs_sgtl5000_hifi_ops, | 96 | .ops = &mxs_sgtl5000_hifi_ops, |
95 | }, { | 97 | }, { |
96 | .name = "HiFi Rx", | 98 | .name = "HiFi Rx", |
@@ -98,7 +100,7 @@ static struct snd_soc_dai_link mxs_sgtl5000_dai[] = { | |||
98 | .codec_dai_name = "sgtl5000", | 100 | .codec_dai_name = "sgtl5000", |
99 | .codec_name = "sgtl5000.0-000a", | 101 | .codec_name = "sgtl5000.0-000a", |
100 | .cpu_dai_name = "mxs-saif.1", | 102 | .cpu_dai_name = "mxs-saif.1", |
101 | .platform_name = "mxs-pcm-audio.1", | 103 | .platform_name = "mxs-saif.1", |
102 | .ops = &mxs_sgtl5000_hifi_ops, | 104 | .ops = &mxs_sgtl5000_hifi_ops, |
103 | }, | 105 | }, |
104 | }; | 106 | }; |
@@ -110,11 +112,48 @@ static struct snd_soc_card mxs_sgtl5000 = { | |||
110 | .num_links = ARRAY_SIZE(mxs_sgtl5000_dai), | 112 | .num_links = ARRAY_SIZE(mxs_sgtl5000_dai), |
111 | }; | 113 | }; |
112 | 114 | ||
115 | static int __devinit mxs_sgtl5000_probe_dt(struct platform_device *pdev) | ||
116 | { | ||
117 | struct device_node *np = pdev->dev.of_node; | ||
118 | struct device_node *saif_np[2], *codec_np; | ||
119 | int i, ret = 0; | ||
120 | |||
121 | if (!np) | ||
122 | return 1; /* no device tree */ | ||
123 | |||
124 | saif_np[0] = of_parse_phandle(np, "saif-controllers", 0); | ||
125 | saif_np[1] = of_parse_phandle(np, "saif-controllers", 1); | ||
126 | codec_np = of_parse_phandle(np, "audio-codec", 0); | ||
127 | if (!saif_np[0] || !saif_np[1] || !codec_np) { | ||
128 | dev_err(&pdev->dev, "phandle missing or invalid\n"); | ||
129 | return -EINVAL; | ||
130 | } | ||
131 | |||
132 | for (i = 0; i < 2; i++) { | ||
133 | mxs_sgtl5000_dai[i].codec_name = NULL; | ||
134 | mxs_sgtl5000_dai[i].codec_of_node = codec_np; | ||
135 | mxs_sgtl5000_dai[i].cpu_dai_name = NULL; | ||
136 | mxs_sgtl5000_dai[i].cpu_dai_of_node = saif_np[i]; | ||
137 | mxs_sgtl5000_dai[i].platform_name = NULL; | ||
138 | mxs_sgtl5000_dai[i].platform_of_node = saif_np[i]; | ||
139 | } | ||
140 | |||
141 | of_node_put(codec_np); | ||
142 | of_node_put(saif_np[0]); | ||
143 | of_node_put(saif_np[1]); | ||
144 | |||
145 | return ret; | ||
146 | } | ||
147 | |||
113 | static int __devinit mxs_sgtl5000_probe(struct platform_device *pdev) | 148 | static int __devinit mxs_sgtl5000_probe(struct platform_device *pdev) |
114 | { | 149 | { |
115 | struct snd_soc_card *card = &mxs_sgtl5000; | 150 | struct snd_soc_card *card = &mxs_sgtl5000; |
116 | int ret; | 151 | int ret; |
117 | 152 | ||
153 | ret = mxs_sgtl5000_probe_dt(pdev); | ||
154 | if (ret < 0) | ||
155 | return ret; | ||
156 | |||
118 | /* | 157 | /* |
119 | * Set an init clock(11.28Mhz) for sgtl5000 initialization(i2c r/w). | 158 | * Set an init clock(11.28Mhz) for sgtl5000 initialization(i2c r/w). |
120 | * The Sgtl5000 sysclk is derived from saif0 mclk and it's range | 159 | * The Sgtl5000 sysclk is derived from saif0 mclk and it's range |
@@ -148,10 +187,17 @@ static int __devexit mxs_sgtl5000_remove(struct platform_device *pdev) | |||
148 | return 0; | 187 | return 0; |
149 | } | 188 | } |
150 | 189 | ||
190 | static const struct of_device_id mxs_sgtl5000_dt_ids[] = { | ||
191 | { .compatible = "fsl,mxs-audio-sgtl5000", }, | ||
192 | { /* sentinel */ } | ||
193 | }; | ||
194 | MODULE_DEVICE_TABLE(of, mxs_sgtl5000_dt_ids); | ||
195 | |||
151 | static struct platform_driver mxs_sgtl5000_audio_driver = { | 196 | static struct platform_driver mxs_sgtl5000_audio_driver = { |
152 | .driver = { | 197 | .driver = { |
153 | .name = "mxs-sgtl5000", | 198 | .name = "mxs-sgtl5000", |
154 | .owner = THIS_MODULE, | 199 | .owner = THIS_MODULE, |
200 | .of_match_table = mxs_sgtl5000_dt_ids, | ||
155 | }, | 201 | }, |
156 | .probe = mxs_sgtl5000_probe, | 202 | .probe = mxs_sgtl5000_probe, |
157 | .remove = __devexit_p(mxs_sgtl5000_remove), | 203 | .remove = __devexit_p(mxs_sgtl5000_remove), |
diff --git a/sound/soc/omap/Kconfig b/sound/soc/omap/Kconfig index deafbfaacdbf..9ccfa5e1c11b 100644 --- a/sound/soc/omap/Kconfig +++ b/sound/soc/omap/Kconfig | |||
@@ -113,6 +113,7 @@ config SND_OMAP_SOC_OMAP4_HDMI | |||
113 | tristate "SoC Audio support for Texas Instruments OMAP4 HDMI" | 113 | tristate "SoC Audio support for Texas Instruments OMAP4 HDMI" |
114 | depends on SND_OMAP_SOC && OMAP4_DSS_HDMI && OMAP2_DSS && ARCH_OMAP4 | 114 | depends on SND_OMAP_SOC && OMAP4_DSS_HDMI && OMAP2_DSS && ARCH_OMAP4 |
115 | select SND_OMAP_SOC_HDMI | 115 | select SND_OMAP_SOC_HDMI |
116 | select SND_SOC_OMAP_HDMI_CODEC | ||
116 | help | 117 | help |
117 | Say Y if you want to add support for SoC HDMI audio on Texas Instruments | 118 | Say Y if you want to add support for SoC HDMI audio on Texas Instruments |
118 | OMAP4 chips | 119 | OMAP4 chips |
diff --git a/sound/soc/pxa/pxa-ssp.c b/sound/soc/pxa/pxa-ssp.c index fd04ce139031..1c2aa7fab3fd 100644 --- a/sound/soc/pxa/pxa-ssp.c +++ b/sound/soc/pxa/pxa-ssp.c | |||
@@ -85,14 +85,12 @@ struct pxa2xx_pcm_dma_data { | |||
85 | char name[20]; | 85 | char name[20]; |
86 | }; | 86 | }; |
87 | 87 | ||
88 | static struct pxa2xx_pcm_dma_params * | 88 | static void pxa_ssp_set_dma_params(struct ssp_device *ssp, int width4, |
89 | pxa_ssp_get_dma_params(struct ssp_device *ssp, int width4, int out) | 89 | int out, struct pxa2xx_pcm_dma_params *dma_data) |
90 | { | 90 | { |
91 | struct pxa2xx_pcm_dma_data *dma; | 91 | struct pxa2xx_pcm_dma_data *dma; |
92 | 92 | ||
93 | dma = kzalloc(sizeof(struct pxa2xx_pcm_dma_data), GFP_KERNEL); | 93 | dma = container_of(dma_data, struct pxa2xx_pcm_dma_data, params); |
94 | if (dma == NULL) | ||
95 | return NULL; | ||
96 | 94 | ||
97 | snprintf(dma->name, 20, "SSP%d PCM %s %s", ssp->port_id, | 95 | snprintf(dma->name, 20, "SSP%d PCM %s %s", ssp->port_id, |
98 | width4 ? "32-bit" : "16-bit", out ? "out" : "in"); | 96 | width4 ? "32-bit" : "16-bit", out ? "out" : "in"); |
@@ -103,8 +101,6 @@ pxa_ssp_get_dma_params(struct ssp_device *ssp, int width4, int out) | |||
103 | (DCMD_INCTRGADDR | DCMD_FLOWSRC)) | | 101 | (DCMD_INCTRGADDR | DCMD_FLOWSRC)) | |
104 | (width4 ? DCMD_WIDTH4 : DCMD_WIDTH2) | DCMD_BURST16; | 102 | (width4 ? DCMD_WIDTH4 : DCMD_WIDTH2) | DCMD_BURST16; |
105 | dma->params.dev_addr = ssp->phys_base + SSDR; | 103 | dma->params.dev_addr = ssp->phys_base + SSDR; |
106 | |||
107 | return &dma->params; | ||
108 | } | 104 | } |
109 | 105 | ||
110 | static int pxa_ssp_startup(struct snd_pcm_substream *substream, | 106 | static int pxa_ssp_startup(struct snd_pcm_substream *substream, |
@@ -112,6 +108,7 @@ static int pxa_ssp_startup(struct snd_pcm_substream *substream, | |||
112 | { | 108 | { |
113 | struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai); | 109 | struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai); |
114 | struct ssp_device *ssp = priv->ssp; | 110 | struct ssp_device *ssp = priv->ssp; |
111 | struct pxa2xx_pcm_dma_data *dma; | ||
115 | int ret = 0; | 112 | int ret = 0; |
116 | 113 | ||
117 | if (!cpu_dai->active) { | 114 | if (!cpu_dai->active) { |
@@ -119,8 +116,10 @@ static int pxa_ssp_startup(struct snd_pcm_substream *substream, | |||
119 | pxa_ssp_disable(ssp); | 116 | pxa_ssp_disable(ssp); |
120 | } | 117 | } |
121 | 118 | ||
122 | kfree(snd_soc_dai_get_dma_data(cpu_dai, substream)); | 119 | dma = kzalloc(sizeof(struct pxa2xx_pcm_dma_data), GFP_KERNEL); |
123 | snd_soc_dai_set_dma_data(cpu_dai, substream, NULL); | 120 | if (!dma) |
121 | return -ENOMEM; | ||
122 | snd_soc_dai_set_dma_data(cpu_dai, substream, &dma->params); | ||
124 | 123 | ||
125 | return ret; | 124 | return ret; |
126 | } | 125 | } |
@@ -573,18 +572,13 @@ static int pxa_ssp_hw_params(struct snd_pcm_substream *substream, | |||
573 | 572 | ||
574 | dma_data = snd_soc_dai_get_dma_data(cpu_dai, substream); | 573 | dma_data = snd_soc_dai_get_dma_data(cpu_dai, substream); |
575 | 574 | ||
576 | /* generate correct DMA params */ | ||
577 | kfree(dma_data); | ||
578 | |||
579 | /* Network mode with one active slot (ttsa == 1) can be used | 575 | /* Network mode with one active slot (ttsa == 1) can be used |
580 | * to force 16-bit frame width on the wire (for S16_LE), even | 576 | * to force 16-bit frame width on the wire (for S16_LE), even |
581 | * with two channels. Use 16-bit DMA transfers for this case. | 577 | * with two channels. Use 16-bit DMA transfers for this case. |
582 | */ | 578 | */ |
583 | dma_data = pxa_ssp_get_dma_params(ssp, | 579 | pxa_ssp_set_dma_params(ssp, |
584 | ((chn == 2) && (ttsa != 1)) || (width == 32), | 580 | ((chn == 2) && (ttsa != 1)) || (width == 32), |
585 | substream->stream == SNDRV_PCM_STREAM_PLAYBACK); | 581 | substream->stream == SNDRV_PCM_STREAM_PLAYBACK, dma_data); |
586 | |||
587 | snd_soc_dai_set_dma_data(cpu_dai, substream, dma_data); | ||
588 | 582 | ||
589 | /* we can only change the settings if the port is not in use */ | 583 | /* we can only change the settings if the port is not in use */ |
590 | if (pxa_ssp_read_reg(ssp, SSCR0) & SSCR0_SSE) | 584 | if (pxa_ssp_read_reg(ssp, SSCR0) & SSCR0_SSE) |
diff --git a/sound/soc/pxa/pxa2xx-i2s.c b/sound/soc/pxa/pxa2xx-i2s.c index d08583790d23..3075a426124c 100644 --- a/sound/soc/pxa/pxa2xx-i2s.c +++ b/sound/soc/pxa/pxa2xx-i2s.c | |||
@@ -166,7 +166,7 @@ static int pxa2xx_i2s_hw_params(struct snd_pcm_substream *substream, | |||
166 | struct pxa2xx_pcm_dma_params *dma_data; | 166 | struct pxa2xx_pcm_dma_params *dma_data; |
167 | 167 | ||
168 | BUG_ON(IS_ERR(clk_i2s)); | 168 | BUG_ON(IS_ERR(clk_i2s)); |
169 | clk_enable(clk_i2s); | 169 | clk_prepare_enable(clk_i2s); |
170 | clk_ena = 1; | 170 | clk_ena = 1; |
171 | pxa_i2s_wait(); | 171 | pxa_i2s_wait(); |
172 | 172 | ||
@@ -259,7 +259,7 @@ static void pxa2xx_i2s_shutdown(struct snd_pcm_substream *substream, | |||
259 | SACR0 &= ~SACR0_ENB; | 259 | SACR0 &= ~SACR0_ENB; |
260 | pxa_i2s_wait(); | 260 | pxa_i2s_wait(); |
261 | if (clk_ena) { | 261 | if (clk_ena) { |
262 | clk_disable(clk_i2s); | 262 | clk_disable_unprepare(clk_i2s); |
263 | clk_ena = 0; | 263 | clk_ena = 0; |
264 | } | 264 | } |
265 | } | 265 | } |
diff --git a/sound/soc/samsung/littlemill.c b/sound/soc/samsung/littlemill.c index e7416851bf7d..c82c646b8a08 100644 --- a/sound/soc/samsung/littlemill.c +++ b/sound/soc/samsung/littlemill.c | |||
@@ -23,10 +23,10 @@ static int littlemill_set_bias_level(struct snd_soc_card *card, | |||
23 | struct snd_soc_dapm_context *dapm, | 23 | struct snd_soc_dapm_context *dapm, |
24 | enum snd_soc_bias_level level) | 24 | enum snd_soc_bias_level level) |
25 | { | 25 | { |
26 | struct snd_soc_dai *codec_dai = card->rtd[0].codec_dai; | 26 | struct snd_soc_dai *aif1_dai = card->rtd[0].codec_dai; |
27 | int ret; | 27 | int ret; |
28 | 28 | ||
29 | if (dapm->dev != codec_dai->dev) | 29 | if (dapm->dev != aif1_dai->dev) |
30 | return 0; | 30 | return 0; |
31 | 31 | ||
32 | switch (level) { | 32 | switch (level) { |
@@ -36,7 +36,7 @@ static int littlemill_set_bias_level(struct snd_soc_card *card, | |||
36 | * then do so now, otherwise these are noops. | 36 | * then do so now, otherwise these are noops. |
37 | */ | 37 | */ |
38 | if (dapm->bias_level == SND_SOC_BIAS_STANDBY) { | 38 | if (dapm->bias_level == SND_SOC_BIAS_STANDBY) { |
39 | ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL1, | 39 | ret = snd_soc_dai_set_pll(aif1_dai, WM8994_FLL1, |
40 | WM8994_FLL_SRC_MCLK2, 32768, | 40 | WM8994_FLL_SRC_MCLK2, 32768, |
41 | sample_rate * 512); | 41 | sample_rate * 512); |
42 | if (ret < 0) { | 42 | if (ret < 0) { |
@@ -44,7 +44,7 @@ static int littlemill_set_bias_level(struct snd_soc_card *card, | |||
44 | return ret; | 44 | return ret; |
45 | } | 45 | } |
46 | 46 | ||
47 | ret = snd_soc_dai_set_sysclk(codec_dai, | 47 | ret = snd_soc_dai_set_sysclk(aif1_dai, |
48 | WM8994_SYSCLK_FLL1, | 48 | WM8994_SYSCLK_FLL1, |
49 | sample_rate * 512, | 49 | sample_rate * 512, |
50 | SND_SOC_CLOCK_IN); | 50 | SND_SOC_CLOCK_IN); |
@@ -66,25 +66,25 @@ static int littlemill_set_bias_level_post(struct snd_soc_card *card, | |||
66 | struct snd_soc_dapm_context *dapm, | 66 | struct snd_soc_dapm_context *dapm, |
67 | enum snd_soc_bias_level level) | 67 | enum snd_soc_bias_level level) |
68 | { | 68 | { |
69 | struct snd_soc_dai *codec_dai = card->rtd[0].codec_dai; | 69 | struct snd_soc_dai *aif1_dai = card->rtd[0].codec_dai; |
70 | int ret; | 70 | int ret; |
71 | 71 | ||
72 | if (dapm->dev != codec_dai->dev) | 72 | if (dapm->dev != aif1_dai->dev) |
73 | return 0; | 73 | return 0; |
74 | 74 | ||
75 | switch (level) { | 75 | switch (level) { |
76 | case SND_SOC_BIAS_STANDBY: | 76 | case SND_SOC_BIAS_STANDBY: |
77 | ret = snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_MCLK2, | 77 | ret = snd_soc_dai_set_sysclk(aif1_dai, WM8994_SYSCLK_MCLK2, |
78 | 32768, SND_SOC_CLOCK_IN); | 78 | 32768, SND_SOC_CLOCK_IN); |
79 | if (ret < 0) { | 79 | if (ret < 0) { |
80 | pr_err("Failed to switch away from FLL: %d\n", ret); | 80 | pr_err("Failed to switch away from FLL1: %d\n", ret); |
81 | return ret; | 81 | return ret; |
82 | } | 82 | } |
83 | 83 | ||
84 | ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL1, | 84 | ret = snd_soc_dai_set_pll(aif1_dai, WM8994_FLL1, |
85 | 0, 0, 0); | 85 | 0, 0, 0); |
86 | if (ret < 0) { | 86 | if (ret < 0) { |
87 | pr_err("Failed to stop FLL: %d\n", ret); | 87 | pr_err("Failed to stop FLL1: %d\n", ret); |
88 | return ret; | 88 | return ret; |
89 | } | 89 | } |
90 | break; | 90 | break; |
@@ -131,6 +131,14 @@ static struct snd_soc_ops littlemill_ops = { | |||
131 | .hw_params = littlemill_hw_params, | 131 | .hw_params = littlemill_hw_params, |
132 | }; | 132 | }; |
133 | 133 | ||
134 | static const struct snd_soc_pcm_stream baseband_params = { | ||
135 | .formats = SNDRV_PCM_FMTBIT_S32_LE, | ||
136 | .rate_min = 8000, | ||
137 | .rate_max = 8000, | ||
138 | .channels_min = 2, | ||
139 | .channels_max = 2, | ||
140 | }; | ||
141 | |||
134 | static struct snd_soc_dai_link littlemill_dai[] = { | 142 | static struct snd_soc_dai_link littlemill_dai[] = { |
135 | { | 143 | { |
136 | .name = "CPU", | 144 | .name = "CPU", |
@@ -143,13 +151,75 @@ static struct snd_soc_dai_link littlemill_dai[] = { | |||
143 | | SND_SOC_DAIFMT_CBM_CFM, | 151 | | SND_SOC_DAIFMT_CBM_CFM, |
144 | .ops = &littlemill_ops, | 152 | .ops = &littlemill_ops, |
145 | }, | 153 | }, |
154 | { | ||
155 | .name = "Baseband", | ||
156 | .stream_name = "Baseband", | ||
157 | .cpu_dai_name = "wm8994-aif2", | ||
158 | .codec_dai_name = "wm1250-ev1", | ||
159 | .codec_name = "wm1250-ev1.1-0027", | ||
160 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | ||
161 | | SND_SOC_DAIFMT_CBM_CFM, | ||
162 | .ignore_suspend = 1, | ||
163 | .params = &baseband_params, | ||
164 | }, | ||
146 | }; | 165 | }; |
147 | 166 | ||
167 | static int bbclk_ev(struct snd_soc_dapm_widget *w, | ||
168 | struct snd_kcontrol *kcontrol, int event) | ||
169 | { | ||
170 | struct snd_soc_card *card = w->dapm->card; | ||
171 | struct snd_soc_dai *aif2_dai = card->rtd[1].cpu_dai; | ||
172 | int ret; | ||
173 | |||
174 | switch (event) { | ||
175 | case SND_SOC_DAPM_PRE_PMU: | ||
176 | ret = snd_soc_dai_set_pll(aif2_dai, WM8994_FLL2, | ||
177 | WM8994_FLL_SRC_BCLK, 64 * 8000, | ||
178 | 8000 * 256); | ||
179 | if (ret < 0) { | ||
180 | pr_err("Failed to start FLL: %d\n", ret); | ||
181 | return ret; | ||
182 | } | ||
183 | |||
184 | ret = snd_soc_dai_set_sysclk(aif2_dai, WM8994_SYSCLK_FLL2, | ||
185 | 8000 * 256, | ||
186 | SND_SOC_CLOCK_IN); | ||
187 | if (ret < 0) { | ||
188 | pr_err("Failed to set SYSCLK: %d\n", ret); | ||
189 | return ret; | ||
190 | } | ||
191 | break; | ||
192 | case SND_SOC_DAPM_POST_PMD: | ||
193 | ret = snd_soc_dai_set_sysclk(aif2_dai, WM8994_SYSCLK_MCLK2, | ||
194 | 32768, SND_SOC_CLOCK_IN); | ||
195 | if (ret < 0) { | ||
196 | pr_err("Failed to switch away from FLL2: %d\n", ret); | ||
197 | return ret; | ||
198 | } | ||
199 | |||
200 | ret = snd_soc_dai_set_pll(aif2_dai, WM8994_FLL2, | ||
201 | 0, 0, 0); | ||
202 | if (ret < 0) { | ||
203 | pr_err("Failed to stop FLL2: %d\n", ret); | ||
204 | return ret; | ||
205 | } | ||
206 | break; | ||
207 | default: | ||
208 | return -EINVAL; | ||
209 | } | ||
210 | |||
211 | return 0; | ||
212 | } | ||
213 | |||
148 | static struct snd_soc_dapm_widget widgets[] = { | 214 | static struct snd_soc_dapm_widget widgets[] = { |
149 | SND_SOC_DAPM_HP("Headphone", NULL), | 215 | SND_SOC_DAPM_HP("Headphone", NULL), |
150 | 216 | ||
151 | SND_SOC_DAPM_MIC("AMIC", NULL), | 217 | SND_SOC_DAPM_MIC("AMIC", NULL), |
152 | SND_SOC_DAPM_MIC("DMIC", NULL), | 218 | SND_SOC_DAPM_MIC("DMIC", NULL), |
219 | |||
220 | SND_SOC_DAPM_SUPPLY_S("Baseband Clock", -1, SND_SOC_NOPM, 0, 0, | ||
221 | bbclk_ev, | ||
222 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), | ||
153 | }; | 223 | }; |
154 | 224 | ||
155 | static struct snd_soc_dapm_route audio_paths[] = { | 225 | static struct snd_soc_dapm_route audio_paths[] = { |
@@ -162,6 +232,8 @@ static struct snd_soc_dapm_route audio_paths[] = { | |||
162 | { "DMIC", NULL, "MICBIAS2" }, /* Default for DMICBIAS jumper */ | 232 | { "DMIC", NULL, "MICBIAS2" }, /* Default for DMICBIAS jumper */ |
163 | { "DMIC1DAT", NULL, "DMIC" }, | 233 | { "DMIC1DAT", NULL, "DMIC" }, |
164 | { "DMIC2DAT", NULL, "DMIC" }, | 234 | { "DMIC2DAT", NULL, "DMIC" }, |
235 | |||
236 | { "AIF2CLK", NULL, "Baseband Clock" }, | ||
165 | }; | 237 | }; |
166 | 238 | ||
167 | static struct snd_soc_jack littlemill_headset; | 239 | static struct snd_soc_jack littlemill_headset; |
@@ -169,10 +241,16 @@ static struct snd_soc_jack littlemill_headset; | |||
169 | static int littlemill_late_probe(struct snd_soc_card *card) | 241 | static int littlemill_late_probe(struct snd_soc_card *card) |
170 | { | 242 | { |
171 | struct snd_soc_codec *codec = card->rtd[0].codec; | 243 | struct snd_soc_codec *codec = card->rtd[0].codec; |
172 | struct snd_soc_dai *codec_dai = card->rtd[0].codec_dai; | 244 | struct snd_soc_dai *aif1_dai = card->rtd[0].codec_dai; |
245 | struct snd_soc_dai *aif2_dai = card->rtd[1].cpu_dai; | ||
173 | int ret; | 246 | int ret; |
174 | 247 | ||
175 | ret = snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_MCLK2, | 248 | ret = snd_soc_dai_set_sysclk(aif1_dai, WM8994_SYSCLK_MCLK2, |
249 | 32768, SND_SOC_CLOCK_IN); | ||
250 | if (ret < 0) | ||
251 | return ret; | ||
252 | |||
253 | ret = snd_soc_dai_set_sysclk(aif2_dai, WM8994_SYSCLK_MCLK2, | ||
176 | 32768, SND_SOC_CLOCK_IN); | 254 | 32768, SND_SOC_CLOCK_IN); |
177 | if (ret < 0) | 255 | if (ret < 0) |
178 | return ret; | 256 | return ret; |
diff --git a/sound/soc/samsung/lowland.c b/sound/soc/samsung/lowland.c index 4adff934f771..6abf341c4a2a 100644 --- a/sound/soc/samsung/lowland.c +++ b/sound/soc/samsung/lowland.c | |||
@@ -21,33 +21,6 @@ | |||
21 | #define MCLK1_RATE (44100 * 512) | 21 | #define MCLK1_RATE (44100 * 512) |
22 | #define CLKOUT_RATE (44100 * 256) | 22 | #define CLKOUT_RATE (44100 * 256) |
23 | 23 | ||
24 | static int lowland_hw_params(struct snd_pcm_substream *substream, | ||
25 | struct snd_pcm_hw_params *params) | ||
26 | { | ||
27 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
28 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; | ||
29 | struct snd_soc_dai *codec_dai = rtd->codec_dai; | ||
30 | int ret; | ||
31 | |||
32 | ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S | ||
33 | | SND_SOC_DAIFMT_NB_NF | ||
34 | | SND_SOC_DAIFMT_CBM_CFM); | ||
35 | if (ret < 0) | ||
36 | return ret; | ||
37 | |||
38 | ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S | ||
39 | | SND_SOC_DAIFMT_NB_NF | ||
40 | | SND_SOC_DAIFMT_CBM_CFM); | ||
41 | if (ret < 0) | ||
42 | return ret; | ||
43 | |||
44 | return 0; | ||
45 | } | ||
46 | |||
47 | static struct snd_soc_ops lowland_ops = { | ||
48 | .hw_params = lowland_hw_params, | ||
49 | }; | ||
50 | |||
51 | static struct snd_soc_jack lowland_headset; | 24 | static struct snd_soc_jack lowland_headset; |
52 | 25 | ||
53 | /* Headset jack detection DAPM pins */ | 26 | /* Headset jack detection DAPM pins */ |
@@ -101,6 +74,25 @@ static int lowland_wm5100_init(struct snd_soc_pcm_runtime *rtd) | |||
101 | return 0; | 74 | return 0; |
102 | } | 75 | } |
103 | 76 | ||
77 | static int lowland_wm9081_init(struct snd_soc_pcm_runtime *rtd) | ||
78 | { | ||
79 | struct snd_soc_codec *codec = rtd->codec; | ||
80 | |||
81 | snd_soc_dapm_nc_pin(&codec->dapm, "LINEOUT"); | ||
82 | |||
83 | /* At any time the WM9081 is active it will have this clock */ | ||
84 | return snd_soc_codec_set_sysclk(codec, WM9081_SYSCLK_MCLK, 0, | ||
85 | CLKOUT_RATE, 0); | ||
86 | } | ||
87 | |||
88 | static const struct snd_soc_pcm_stream sub_params = { | ||
89 | .formats = SNDRV_PCM_FMTBIT_S32_LE, | ||
90 | .rate_min = 44100, | ||
91 | .rate_max = 44100, | ||
92 | .channels_min = 2, | ||
93 | .channels_max = 2, | ||
94 | }; | ||
95 | |||
104 | static struct snd_soc_dai_link lowland_dai[] = { | 96 | static struct snd_soc_dai_link lowland_dai[] = { |
105 | { | 97 | { |
106 | .name = "CPU", | 98 | .name = "CPU", |
@@ -109,7 +101,8 @@ static struct snd_soc_dai_link lowland_dai[] = { | |||
109 | .codec_dai_name = "wm5100-aif1", | 101 | .codec_dai_name = "wm5100-aif1", |
110 | .platform_name = "samsung-audio", | 102 | .platform_name = "samsung-audio", |
111 | .codec_name = "wm5100.1-001a", | 103 | .codec_name = "wm5100.1-001a", |
112 | .ops = &lowland_ops, | 104 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | |
105 | SND_SOC_DAIFMT_CBM_CFM, | ||
113 | .init = lowland_wm5100_init, | 106 | .init = lowland_wm5100_init, |
114 | }, | 107 | }, |
115 | { | 108 | { |
@@ -118,24 +111,20 @@ static struct snd_soc_dai_link lowland_dai[] = { | |||
118 | .cpu_dai_name = "wm5100-aif2", | 111 | .cpu_dai_name = "wm5100-aif2", |
119 | .codec_dai_name = "wm1250-ev1", | 112 | .codec_dai_name = "wm1250-ev1", |
120 | .codec_name = "wm1250-ev1.1-0027", | 113 | .codec_name = "wm1250-ev1.1-0027", |
121 | .ops = &lowland_ops, | 114 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | |
115 | SND_SOC_DAIFMT_CBM_CFM, | ||
122 | .ignore_suspend = 1, | 116 | .ignore_suspend = 1, |
123 | }, | 117 | }, |
124 | }; | ||
125 | |||
126 | static int lowland_wm9081_init(struct snd_soc_dapm_context *dapm) | ||
127 | { | ||
128 | snd_soc_dapm_nc_pin(dapm, "LINEOUT"); | ||
129 | |||
130 | /* At any time the WM9081 is active it will have this clock */ | ||
131 | return snd_soc_codec_set_sysclk(dapm->codec, WM9081_SYSCLK_MCLK, 0, | ||
132 | CLKOUT_RATE, 0); | ||
133 | } | ||
134 | |||
135 | static struct snd_soc_aux_dev lowland_aux_dev[] = { | ||
136 | { | 118 | { |
137 | .name = "wm9081", | 119 | .name = "Sub Speaker", |
120 | .stream_name = "Sub Speaker", | ||
121 | .cpu_dai_name = "wm5100-aif3", | ||
122 | .codec_dai_name = "wm9081-hifi", | ||
138 | .codec_name = "wm9081.1-006c", | 123 | .codec_name = "wm9081.1-006c", |
124 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | | ||
125 | SND_SOC_DAIFMT_CBM_CFM, | ||
126 | .ignore_suspend = 1, | ||
127 | .params = &sub_params, | ||
139 | .init = lowland_wm9081_init, | 128 | .init = lowland_wm9081_init, |
140 | }, | 129 | }, |
141 | }; | 130 | }; |
@@ -180,8 +169,6 @@ static struct snd_soc_card lowland = { | |||
180 | .owner = THIS_MODULE, | 169 | .owner = THIS_MODULE, |
181 | .dai_link = lowland_dai, | 170 | .dai_link = lowland_dai, |
182 | .num_links = ARRAY_SIZE(lowland_dai), | 171 | .num_links = ARRAY_SIZE(lowland_dai), |
183 | .aux_dev = lowland_aux_dev, | ||
184 | .num_aux_devs = ARRAY_SIZE(lowland_aux_dev), | ||
185 | .codec_conf = lowland_codec_conf, | 172 | .codec_conf = lowland_codec_conf, |
186 | .num_configs = ARRAY_SIZE(lowland_codec_conf), | 173 | .num_configs = ARRAY_SIZE(lowland_codec_conf), |
187 | 174 | ||
diff --git a/sound/soc/samsung/speyside.c b/sound/soc/samsung/speyside.c index f9ab7707a3e4..a4a9fc7e8c76 100644 --- a/sound/soc/samsung/speyside.c +++ b/sound/soc/samsung/speyside.c | |||
@@ -92,33 +92,6 @@ static int speyside_set_bias_level_post(struct snd_soc_card *card, | |||
92 | return 0; | 92 | return 0; |
93 | } | 93 | } |
94 | 94 | ||
95 | static int speyside_hw_params(struct snd_pcm_substream *substream, | ||
96 | struct snd_pcm_hw_params *params) | ||
97 | { | ||
98 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
99 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; | ||
100 | struct snd_soc_dai *codec_dai = rtd->codec_dai; | ||
101 | int ret; | ||
102 | |||
103 | ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S | ||
104 | | SND_SOC_DAIFMT_NB_NF | ||
105 | | SND_SOC_DAIFMT_CBM_CFM); | ||
106 | if (ret < 0) | ||
107 | return ret; | ||
108 | |||
109 | ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S | ||
110 | | SND_SOC_DAIFMT_NB_NF | ||
111 | | SND_SOC_DAIFMT_CBM_CFM); | ||
112 | if (ret < 0) | ||
113 | return ret; | ||
114 | |||
115 | return 0; | ||
116 | } | ||
117 | |||
118 | static struct snd_soc_ops speyside_ops = { | ||
119 | .hw_params = speyside_hw_params, | ||
120 | }; | ||
121 | |||
122 | static struct snd_soc_jack speyside_headset; | 95 | static struct snd_soc_jack speyside_headset; |
123 | 96 | ||
124 | /* Headset jack detection DAPM pins */ | 97 | /* Headset jack detection DAPM pins */ |
@@ -208,7 +181,8 @@ static struct snd_soc_dai_link speyside_dai[] = { | |||
208 | .platform_name = "samsung-audio", | 181 | .platform_name = "samsung-audio", |
209 | .codec_name = "wm8996.1-001a", | 182 | .codec_name = "wm8996.1-001a", |
210 | .init = speyside_wm8996_init, | 183 | .init = speyside_wm8996_init, |
211 | .ops = &speyside_ops, | 184 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
185 | | SND_SOC_DAIFMT_CBM_CFM, | ||
212 | }, | 186 | }, |
213 | { | 187 | { |
214 | .name = "Baseband", | 188 | .name = "Baseband", |
@@ -216,7 +190,8 @@ static struct snd_soc_dai_link speyside_dai[] = { | |||
216 | .cpu_dai_name = "wm8996-aif2", | 190 | .cpu_dai_name = "wm8996-aif2", |
217 | .codec_dai_name = "wm1250-ev1", | 191 | .codec_dai_name = "wm1250-ev1", |
218 | .codec_name = "wm1250-ev1.1-0027", | 192 | .codec_name = "wm1250-ev1.1-0027", |
219 | .ops = &speyside_ops, | 193 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
194 | | SND_SOC_DAIFMT_CBM_CFM, | ||
220 | .ignore_suspend = 1, | 195 | .ignore_suspend = 1, |
221 | }, | 196 | }, |
222 | }; | 197 | }; |
diff --git a/sound/soc/sh/Kconfig b/sound/soc/sh/Kconfig index d8e06a607a22..6bcb1164d599 100644 --- a/sound/soc/sh/Kconfig +++ b/sound/soc/sh/Kconfig | |||
@@ -22,6 +22,7 @@ config SND_SOC_SH4_SSI | |||
22 | 22 | ||
23 | config SND_SOC_SH4_FSI | 23 | config SND_SOC_SH4_FSI |
24 | tristate "SH4 FSI support" | 24 | tristate "SH4 FSI support" |
25 | select SND_SIMPLE_CARD | ||
25 | help | 26 | help |
26 | This option enables FSI sound support | 27 | This option enables FSI sound support |
27 | 28 | ||
@@ -46,29 +47,6 @@ config SND_SH7760_AC97 | |||
46 | This option enables generic sound support for the first | 47 | This option enables generic sound support for the first |
47 | AC97 unit of the SH7760. | 48 | AC97 unit of the SH7760. |
48 | 49 | ||
49 | config SND_FSI_AK4642 | ||
50 | tristate "FSI-AK4642 sound support" | ||
51 | depends on SND_SOC_SH4_FSI && I2C | ||
52 | select SND_SOC_AK4642 | ||
53 | help | ||
54 | This option enables generic sound support for the | ||
55 | FSI - AK4642 unit | ||
56 | |||
57 | config SND_FSI_DA7210 | ||
58 | tristate "FSI-DA7210 sound support" | ||
59 | depends on SND_SOC_SH4_FSI && I2C | ||
60 | select SND_SOC_DA7210 | ||
61 | help | ||
62 | This option enables generic sound support for the | ||
63 | FSI - DA7210 unit | ||
64 | |||
65 | config SND_FSI_HDMI | ||
66 | tristate "FSI-HDMI sound support" | ||
67 | depends on SND_SOC_SH4_FSI && FB_SH_MOBILE_HDMI | ||
68 | help | ||
69 | This option enables generic sound support for the | ||
70 | FSI - HDMI unit | ||
71 | |||
72 | config SND_SIU_MIGOR | 50 | config SND_SIU_MIGOR |
73 | tristate "SIU sound support on Migo-R" | 51 | tristate "SIU sound support on Migo-R" |
74 | depends on SH_MIGOR | 52 | depends on SH_MIGOR |
diff --git a/sound/soc/sh/Makefile b/sound/soc/sh/Makefile index 94476d4c0fd5..849b387d17d9 100644 --- a/sound/soc/sh/Makefile +++ b/sound/soc/sh/Makefile | |||
@@ -14,13 +14,7 @@ obj-$(CONFIG_SND_SOC_SH4_SIU) += snd-soc-siu.o | |||
14 | 14 | ||
15 | ## boards | 15 | ## boards |
16 | snd-soc-sh7760-ac97-objs := sh7760-ac97.o | 16 | snd-soc-sh7760-ac97-objs := sh7760-ac97.o |
17 | snd-soc-fsi-ak4642-objs := fsi-ak4642.o | ||
18 | snd-soc-fsi-da7210-objs := fsi-da7210.o | ||
19 | snd-soc-fsi-hdmi-objs := fsi-hdmi.o | ||
20 | snd-soc-migor-objs := migor.o | 17 | snd-soc-migor-objs := migor.o |
21 | 18 | ||
22 | obj-$(CONFIG_SND_SH7760_AC97) += snd-soc-sh7760-ac97.o | 19 | obj-$(CONFIG_SND_SH7760_AC97) += snd-soc-sh7760-ac97.o |
23 | obj-$(CONFIG_SND_FSI_AK4642) += snd-soc-fsi-ak4642.o | ||
24 | obj-$(CONFIG_SND_FSI_DA7210) += snd-soc-fsi-da7210.o | ||
25 | obj-$(CONFIG_SND_FSI_HDMI) += snd-soc-fsi-hdmi.o | ||
26 | obj-$(CONFIG_SND_SIU_MIGOR) += snd-soc-migor.o | 20 | obj-$(CONFIG_SND_SIU_MIGOR) += snd-soc-migor.o |
diff --git a/sound/soc/sh/fsi-ak4642.c b/sound/soc/sh/fsi-ak4642.c deleted file mode 100644 index 97f540aabbdd..000000000000 --- a/sound/soc/sh/fsi-ak4642.c +++ /dev/null | |||
@@ -1,108 +0,0 @@ | |||
1 | /* | ||
2 | * FSI-AK464x sound support for ms7724se | ||
3 | * | ||
4 | * Copyright (C) 2009 Renesas Solutions Corp. | ||
5 | * Kuninori Morimoto <morimoto.kuninori@renesas.com> | ||
6 | * | ||
7 | * This file is subject to the terms and conditions of the GNU General Public | ||
8 | * License. See the file "COPYING" in the main directory of this archive | ||
9 | * for more details. | ||
10 | */ | ||
11 | |||
12 | #include <linux/platform_device.h> | ||
13 | #include <linux/module.h> | ||
14 | #include <sound/sh_fsi.h> | ||
15 | |||
16 | struct fsi_ak4642_data { | ||
17 | const char *name; | ||
18 | const char *card; | ||
19 | const char *cpu_dai; | ||
20 | const char *codec; | ||
21 | const char *platform; | ||
22 | int id; | ||
23 | }; | ||
24 | |||
25 | static int fsi_ak4642_dai_init(struct snd_soc_pcm_runtime *rtd) | ||
26 | { | ||
27 | struct snd_soc_dai *codec = rtd->codec_dai; | ||
28 | struct snd_soc_dai *cpu = rtd->cpu_dai; | ||
29 | int ret; | ||
30 | |||
31 | ret = snd_soc_dai_set_fmt(codec, SND_SOC_DAIFMT_LEFT_J | | ||
32 | SND_SOC_DAIFMT_CBM_CFM); | ||
33 | if (ret < 0) | ||
34 | return ret; | ||
35 | |||
36 | ret = snd_soc_dai_set_sysclk(codec, 0, 11289600, 0); | ||
37 | if (ret < 0) | ||
38 | return ret; | ||
39 | |||
40 | ret = snd_soc_dai_set_fmt(cpu, SND_SOC_DAIFMT_LEFT_J | | ||
41 | SND_SOC_DAIFMT_CBS_CFS); | ||
42 | |||
43 | return ret; | ||
44 | } | ||
45 | |||
46 | static struct snd_soc_dai_link fsi_dai_link = { | ||
47 | .codec_dai_name = "ak4642-hifi", | ||
48 | .init = fsi_ak4642_dai_init, | ||
49 | }; | ||
50 | |||
51 | static struct snd_soc_card fsi_soc_card = { | ||
52 | .owner = THIS_MODULE, | ||
53 | .dai_link = &fsi_dai_link, | ||
54 | .num_links = 1, | ||
55 | }; | ||
56 | |||
57 | static struct platform_device *fsi_snd_device; | ||
58 | |||
59 | static int fsi_ak4642_probe(struct platform_device *pdev) | ||
60 | { | ||
61 | int ret = -ENOMEM; | ||
62 | struct fsi_ak4642_info *pinfo = pdev->dev.platform_data; | ||
63 | |||
64 | if (!pinfo) { | ||
65 | dev_err(&pdev->dev, "no info for fsi ak4642\n"); | ||
66 | goto out; | ||
67 | } | ||
68 | |||
69 | fsi_snd_device = platform_device_alloc("soc-audio", pinfo->id); | ||
70 | if (!fsi_snd_device) | ||
71 | goto out; | ||
72 | |||
73 | fsi_dai_link.name = pinfo->name; | ||
74 | fsi_dai_link.stream_name = pinfo->name; | ||
75 | fsi_dai_link.cpu_dai_name = pinfo->cpu_dai; | ||
76 | fsi_dai_link.platform_name = pinfo->platform; | ||
77 | fsi_dai_link.codec_name = pinfo->codec; | ||
78 | fsi_soc_card.name = pinfo->card; | ||
79 | |||
80 | platform_set_drvdata(fsi_snd_device, &fsi_soc_card); | ||
81 | ret = platform_device_add(fsi_snd_device); | ||
82 | |||
83 | if (ret) | ||
84 | platform_device_put(fsi_snd_device); | ||
85 | |||
86 | out: | ||
87 | return ret; | ||
88 | } | ||
89 | |||
90 | static int fsi_ak4642_remove(struct platform_device *pdev) | ||
91 | { | ||
92 | platform_device_unregister(fsi_snd_device); | ||
93 | return 0; | ||
94 | } | ||
95 | |||
96 | static struct platform_driver fsi_ak4642 = { | ||
97 | .driver = { | ||
98 | .name = "fsi-ak4642-audio", | ||
99 | }, | ||
100 | .probe = fsi_ak4642_probe, | ||
101 | .remove = fsi_ak4642_remove, | ||
102 | }; | ||
103 | |||
104 | module_platform_driver(fsi_ak4642); | ||
105 | |||
106 | MODULE_LICENSE("GPL"); | ||
107 | MODULE_DESCRIPTION("Generic SH4 FSI-AK4642 sound card"); | ||
108 | MODULE_AUTHOR("Kuninori Morimoto <morimoto.kuninori@renesas.com>"); | ||
diff --git a/sound/soc/sh/fsi-da7210.c b/sound/soc/sh/fsi-da7210.c deleted file mode 100644 index 1dd3354c7411..000000000000 --- a/sound/soc/sh/fsi-da7210.c +++ /dev/null | |||
@@ -1,81 +0,0 @@ | |||
1 | /* | ||
2 | * fsi-da7210.c | ||
3 | * | ||
4 | * Copyright (C) 2009 Renesas Solutions Corp. | ||
5 | * Kuninori Morimoto <morimoto.kuninori@renesas.com> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify it | ||
8 | * under the terms of the GNU General Public License as published by the | ||
9 | * Free Software Foundation; either version 2 of the License, or (at your | ||
10 | * option) any later version. | ||
11 | */ | ||
12 | |||
13 | #include <linux/platform_device.h> | ||
14 | #include <linux/module.h> | ||
15 | #include <sound/sh_fsi.h> | ||
16 | |||
17 | static int fsi_da7210_init(struct snd_soc_pcm_runtime *rtd) | ||
18 | { | ||
19 | struct snd_soc_dai *codec = rtd->codec_dai; | ||
20 | struct snd_soc_dai *cpu = rtd->cpu_dai; | ||
21 | int ret; | ||
22 | |||
23 | ret = snd_soc_dai_set_fmt(codec, | ||
24 | SND_SOC_DAIFMT_I2S | | ||
25 | SND_SOC_DAIFMT_CBM_CFM); | ||
26 | if (ret < 0) | ||
27 | return ret; | ||
28 | |||
29 | ret = snd_soc_dai_set_fmt(cpu, SND_SOC_DAIFMT_I2S | | ||
30 | SND_SOC_DAIFMT_CBS_CFS); | ||
31 | |||
32 | return ret; | ||
33 | } | ||
34 | |||
35 | static struct snd_soc_dai_link fsi_da7210_dai = { | ||
36 | .name = "DA7210", | ||
37 | .stream_name = "DA7210", | ||
38 | .cpu_dai_name = "fsib-dai", /* FSI B */ | ||
39 | .codec_dai_name = "da7210-hifi", | ||
40 | .platform_name = "sh_fsi.0", | ||
41 | .codec_name = "da7210-codec.0-001a", | ||
42 | .init = fsi_da7210_init, | ||
43 | }; | ||
44 | |||
45 | static struct snd_soc_card fsi_soc_card = { | ||
46 | .name = "FSI-DA7210", | ||
47 | .owner = THIS_MODULE, | ||
48 | .dai_link = &fsi_da7210_dai, | ||
49 | .num_links = 1, | ||
50 | }; | ||
51 | |||
52 | static struct platform_device *fsi_da7210_snd_device; | ||
53 | |||
54 | static int __init fsi_da7210_sound_init(void) | ||
55 | { | ||
56 | int ret; | ||
57 | |||
58 | fsi_da7210_snd_device = platform_device_alloc("soc-audio", FSI_PORT_B); | ||
59 | if (!fsi_da7210_snd_device) | ||
60 | return -ENOMEM; | ||
61 | |||
62 | platform_set_drvdata(fsi_da7210_snd_device, &fsi_soc_card); | ||
63 | ret = platform_device_add(fsi_da7210_snd_device); | ||
64 | if (ret) | ||
65 | platform_device_put(fsi_da7210_snd_device); | ||
66 | |||
67 | return ret; | ||
68 | } | ||
69 | |||
70 | static void __exit fsi_da7210_sound_exit(void) | ||
71 | { | ||
72 | platform_device_unregister(fsi_da7210_snd_device); | ||
73 | } | ||
74 | |||
75 | module_init(fsi_da7210_sound_init); | ||
76 | module_exit(fsi_da7210_sound_exit); | ||
77 | |||
78 | /* Module information */ | ||
79 | MODULE_DESCRIPTION("ALSA SoC FSI DA2710"); | ||
80 | MODULE_AUTHOR("Kuninori Morimoto <morimoto.kuninori@renesas.com>"); | ||
81 | MODULE_LICENSE("GPL"); | ||
diff --git a/sound/soc/sh/fsi-hdmi.c b/sound/soc/sh/fsi-hdmi.c deleted file mode 100644 index 6e41908323e8..000000000000 --- a/sound/soc/sh/fsi-hdmi.c +++ /dev/null | |||
@@ -1,118 +0,0 @@ | |||
1 | /* | ||
2 | * FSI - HDMI sound support | ||
3 | * | ||
4 | * Copyright (C) 2010 Renesas Solutions Corp. | ||
5 | * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> | ||
6 | * | ||
7 | * This file is subject to the terms and conditions of the GNU General Public | ||
8 | * License. See the file "COPYING" in the main directory of this archive | ||
9 | * for more details. | ||
10 | */ | ||
11 | |||
12 | #include <linux/platform_device.h> | ||
13 | #include <linux/module.h> | ||
14 | #include <sound/sh_fsi.h> | ||
15 | |||
16 | struct fsi_hdmi_data { | ||
17 | const char *cpu_dai; | ||
18 | const char *card; | ||
19 | int id; | ||
20 | }; | ||
21 | |||
22 | static int fsi_hdmi_dai_init(struct snd_soc_pcm_runtime *rtd) | ||
23 | { | ||
24 | struct snd_soc_dai *cpu = rtd->cpu_dai; | ||
25 | int ret; | ||
26 | |||
27 | ret = snd_soc_dai_set_fmt(cpu, SND_SOC_DAIFMT_CBM_CFM); | ||
28 | |||
29 | return ret; | ||
30 | } | ||
31 | |||
32 | static struct snd_soc_dai_link fsi_dai_link = { | ||
33 | .name = "HDMI", | ||
34 | .stream_name = "HDMI", | ||
35 | .codec_dai_name = "sh_mobile_hdmi-hifi", | ||
36 | .platform_name = "sh_fsi2", | ||
37 | .codec_name = "sh-mobile-hdmi", | ||
38 | .init = fsi_hdmi_dai_init, | ||
39 | }; | ||
40 | |||
41 | static struct snd_soc_card fsi_soc_card = { | ||
42 | .owner = THIS_MODULE, | ||
43 | .dai_link = &fsi_dai_link, | ||
44 | .num_links = 1, | ||
45 | }; | ||
46 | |||
47 | static struct platform_device *fsi_snd_device; | ||
48 | |||
49 | static int fsi_hdmi_probe(struct platform_device *pdev) | ||
50 | { | ||
51 | int ret = -ENOMEM; | ||
52 | const struct platform_device_id *id_entry; | ||
53 | struct fsi_hdmi_data *pdata; | ||
54 | |||
55 | id_entry = pdev->id_entry; | ||
56 | if (!id_entry) { | ||
57 | dev_err(&pdev->dev, "unknown fsi hdmi\n"); | ||
58 | return -ENODEV; | ||
59 | } | ||
60 | |||
61 | pdata = (struct fsi_hdmi_data *)id_entry->driver_data; | ||
62 | |||
63 | fsi_snd_device = platform_device_alloc("soc-audio", pdata->id); | ||
64 | if (!fsi_snd_device) | ||
65 | goto out; | ||
66 | |||
67 | fsi_dai_link.cpu_dai_name = pdata->cpu_dai; | ||
68 | fsi_soc_card.name = pdata->card; | ||
69 | |||
70 | platform_set_drvdata(fsi_snd_device, &fsi_soc_card); | ||
71 | ret = platform_device_add(fsi_snd_device); | ||
72 | |||
73 | if (ret) | ||
74 | platform_device_put(fsi_snd_device); | ||
75 | |||
76 | out: | ||
77 | return ret; | ||
78 | } | ||
79 | |||
80 | static int fsi_hdmi_remove(struct platform_device *pdev) | ||
81 | { | ||
82 | platform_device_unregister(fsi_snd_device); | ||
83 | return 0; | ||
84 | } | ||
85 | |||
86 | static struct fsi_hdmi_data fsi2_a_hdmi = { | ||
87 | .cpu_dai = "fsia-dai", | ||
88 | .card = "FSI2A-HDMI", | ||
89 | .id = FSI_PORT_A, | ||
90 | }; | ||
91 | |||
92 | static struct fsi_hdmi_data fsi2_b_hdmi = { | ||
93 | .cpu_dai = "fsib-dai", | ||
94 | .card = "FSI2B-HDMI", | ||
95 | .id = FSI_PORT_B, | ||
96 | }; | ||
97 | |||
98 | static struct platform_device_id fsi_id_table[] = { | ||
99 | /* FSI 2 */ | ||
100 | { "sh_fsi2_a_hdmi", (kernel_ulong_t)&fsi2_a_hdmi }, | ||
101 | { "sh_fsi2_b_hdmi", (kernel_ulong_t)&fsi2_b_hdmi }, | ||
102 | {}, | ||
103 | }; | ||
104 | |||
105 | static struct platform_driver fsi_hdmi = { | ||
106 | .driver = { | ||
107 | .name = "fsi-hdmi-audio", | ||
108 | }, | ||
109 | .probe = fsi_hdmi_probe, | ||
110 | .remove = fsi_hdmi_remove, | ||
111 | .id_table = fsi_id_table, | ||
112 | }; | ||
113 | |||
114 | module_platform_driver(fsi_hdmi); | ||
115 | |||
116 | MODULE_LICENSE("GPL"); | ||
117 | MODULE_DESCRIPTION("Generic SH4 FSI-HDMI sound card"); | ||
118 | MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>"); | ||
diff --git a/sound/soc/sh/fsi.c b/sound/soc/sh/fsi.c index 74ed2dffbffd..7cee22515d9d 100644 --- a/sound/soc/sh/fsi.c +++ b/sound/soc/sh/fsi.c | |||
@@ -132,6 +132,25 @@ | |||
132 | typedef int (*set_rate_func)(struct device *dev, int rate, int enable); | 132 | typedef int (*set_rate_func)(struct device *dev, int rate, int enable); |
133 | 133 | ||
134 | /* | 134 | /* |
135 | * bus options | ||
136 | * | ||
137 | * 0x000000BA | ||
138 | * | ||
139 | * A : sample widtht 16bit setting | ||
140 | * B : sample widtht 24bit setting | ||
141 | */ | ||
142 | |||
143 | #define SHIFT_16DATA 0 | ||
144 | #define SHIFT_24DATA 4 | ||
145 | |||
146 | #define PACKAGE_24BITBUS_BACK 0 | ||
147 | #define PACKAGE_24BITBUS_FRONT 1 | ||
148 | #define PACKAGE_16BITBUS_STREAM 2 | ||
149 | |||
150 | #define BUSOP_SET(s, a) ((a) << SHIFT_ ## s ## DATA) | ||
151 | #define BUSOP_GET(s, a) (((a) >> SHIFT_ ## s ## DATA) & 0xF) | ||
152 | |||
153 | /* | ||
135 | * FSI driver use below type name for variable | 154 | * FSI driver use below type name for variable |
136 | * | 155 | * |
137 | * xxx_num : number of data | 156 | * xxx_num : number of data |
@@ -189,6 +208,11 @@ struct fsi_stream { | |||
189 | int oerr_num; | 208 | int oerr_num; |
190 | 209 | ||
191 | /* | 210 | /* |
211 | * bus options | ||
212 | */ | ||
213 | u32 bus_option; | ||
214 | |||
215 | /* | ||
192 | * thse are initialized by fsi_handler_init() | 216 | * thse are initialized by fsi_handler_init() |
193 | */ | 217 | */ |
194 | struct fsi_stream_handler *handler; | 218 | struct fsi_stream_handler *handler; |
@@ -211,8 +235,7 @@ struct fsi_priv { | |||
211 | struct fsi_stream playback; | 235 | struct fsi_stream playback; |
212 | struct fsi_stream capture; | 236 | struct fsi_stream capture; |
213 | 237 | ||
214 | u32 do_fmt; | 238 | u32 fmt; |
215 | u32 di_fmt; | ||
216 | 239 | ||
217 | int chan_num:16; | 240 | int chan_num:16; |
218 | int clk_master:1; | 241 | int clk_master:1; |
@@ -321,6 +344,10 @@ static void _fsi_master_mask_set(struct fsi_master *master, | |||
321 | /* | 344 | /* |
322 | * basic function | 345 | * basic function |
323 | */ | 346 | */ |
347 | static int fsi_version(struct fsi_master *master) | ||
348 | { | ||
349 | return master->core->ver; | ||
350 | } | ||
324 | 351 | ||
325 | static struct fsi_master *fsi_get_master(struct fsi_priv *fsi) | 352 | static struct fsi_master *fsi_get_master(struct fsi_priv *fsi) |
326 | { | 353 | { |
@@ -495,6 +522,7 @@ static void fsi_stream_init(struct fsi_priv *fsi, | |||
495 | io->period_samples = fsi_frame2sample(fsi, runtime->period_size); | 522 | io->period_samples = fsi_frame2sample(fsi, runtime->period_size); |
496 | io->period_pos = 0; | 523 | io->period_pos = 0; |
497 | io->sample_width = samples_to_bytes(runtime, 1); | 524 | io->sample_width = samples_to_bytes(runtime, 1); |
525 | io->bus_option = 0; | ||
498 | io->oerr_num = -1; /* ignore 1st err */ | 526 | io->oerr_num = -1; /* ignore 1st err */ |
499 | io->uerr_num = -1; /* ignore 1st err */ | 527 | io->uerr_num = -1; /* ignore 1st err */ |
500 | fsi_stream_handler_call(io, init, fsi, io); | 528 | fsi_stream_handler_call(io, init, fsi, io); |
@@ -522,6 +550,7 @@ static void fsi_stream_quit(struct fsi_priv *fsi, struct fsi_stream *io) | |||
522 | io->period_samples = 0; | 550 | io->period_samples = 0; |
523 | io->period_pos = 0; | 551 | io->period_pos = 0; |
524 | io->sample_width = 0; | 552 | io->sample_width = 0; |
553 | io->bus_option = 0; | ||
525 | io->oerr_num = 0; | 554 | io->oerr_num = 0; |
526 | io->uerr_num = 0; | 555 | io->uerr_num = 0; |
527 | spin_unlock_irqrestore(&master->lock, flags); | 556 | spin_unlock_irqrestore(&master->lock, flags); |
@@ -581,6 +610,53 @@ static int fsi_stream_remove(struct fsi_priv *fsi) | |||
581 | } | 610 | } |
582 | 611 | ||
583 | /* | 612 | /* |
613 | * format/bus/dma setting | ||
614 | */ | ||
615 | static void fsi_format_bus_setup(struct fsi_priv *fsi, struct fsi_stream *io, | ||
616 | u32 bus, struct device *dev) | ||
617 | { | ||
618 | struct fsi_master *master = fsi_get_master(fsi); | ||
619 | int is_play = fsi_stream_is_play(fsi, io); | ||
620 | u32 fmt = fsi->fmt; | ||
621 | |||
622 | if (fsi_version(master) >= 2) { | ||
623 | u32 dma = 0; | ||
624 | |||
625 | /* | ||
626 | * FSI2 needs DMA/Bus setting | ||
627 | */ | ||
628 | switch (bus) { | ||
629 | case PACKAGE_24BITBUS_FRONT: | ||
630 | fmt |= CR_BWS_24; | ||
631 | dma |= VDMD_FRONT; | ||
632 | dev_dbg(dev, "24bit bus / package in front\n"); | ||
633 | break; | ||
634 | case PACKAGE_16BITBUS_STREAM: | ||
635 | fmt |= CR_BWS_16; | ||
636 | dma |= VDMD_STREAM; | ||
637 | dev_dbg(dev, "16bit bus / stream mode\n"); | ||
638 | break; | ||
639 | case PACKAGE_24BITBUS_BACK: | ||
640 | default: | ||
641 | fmt |= CR_BWS_24; | ||
642 | dma |= VDMD_BACK; | ||
643 | dev_dbg(dev, "24bit bus / package in back\n"); | ||
644 | break; | ||
645 | } | ||
646 | |||
647 | if (is_play) | ||
648 | fsi_reg_write(fsi, OUT_DMAC, dma); | ||
649 | else | ||
650 | fsi_reg_write(fsi, IN_DMAC, dma); | ||
651 | } | ||
652 | |||
653 | if (is_play) | ||
654 | fsi_reg_write(fsi, DO_FMT, fmt); | ||
655 | else | ||
656 | fsi_reg_write(fsi, DI_FMT, fmt); | ||
657 | } | ||
658 | |||
659 | /* | ||
584 | * irq function | 660 | * irq function |
585 | */ | 661 | */ |
586 | 662 | ||
@@ -629,11 +705,6 @@ static void fsi_spdif_clk_ctrl(struct fsi_priv *fsi, int enable) | |||
629 | struct fsi_master *master = fsi_get_master(fsi); | 705 | struct fsi_master *master = fsi_get_master(fsi); |
630 | u32 mask, val; | 706 | u32 mask, val; |
631 | 707 | ||
632 | if (master->core->ver < 2) { | ||
633 | pr_err("fsi: register access err (%s)\n", __func__); | ||
634 | return; | ||
635 | } | ||
636 | |||
637 | mask = BP | SE; | 708 | mask = BP | SE; |
638 | val = enable ? mask : 0; | 709 | val = enable ? mask : 0; |
639 | 710 | ||
@@ -648,9 +719,7 @@ static void fsi_spdif_clk_ctrl(struct fsi_priv *fsi, int enable) | |||
648 | static int fsi_set_master_clk(struct device *dev, struct fsi_priv *fsi, | 719 | static int fsi_set_master_clk(struct device *dev, struct fsi_priv *fsi, |
649 | long rate, int enable) | 720 | long rate, int enable) |
650 | { | 721 | { |
651 | struct fsi_master *master = fsi_get_master(fsi); | ||
652 | set_rate_func set_rate = fsi_get_info_set_rate(fsi); | 722 | set_rate_func set_rate = fsi_get_info_set_rate(fsi); |
653 | int fsi_ver = master->core->ver; | ||
654 | int ret; | 723 | int ret; |
655 | 724 | ||
656 | if (!set_rate) | 725 | if (!set_rate) |
@@ -682,10 +751,7 @@ static int fsi_set_master_clk(struct device *dev, struct fsi_priv *fsi, | |||
682 | data |= (0x3 << 12); | 751 | data |= (0x3 << 12); |
683 | break; | 752 | break; |
684 | case SH_FSI_ACKMD_32: | 753 | case SH_FSI_ACKMD_32: |
685 | if (fsi_ver < 2) | 754 | data |= (0x4 << 12); |
686 | dev_err(dev, "unsupported ACKMD\n"); | ||
687 | else | ||
688 | data |= (0x4 << 12); | ||
689 | break; | 755 | break; |
690 | } | 756 | } |
691 | 757 | ||
@@ -708,10 +774,7 @@ static int fsi_set_master_clk(struct device *dev, struct fsi_priv *fsi, | |||
708 | data |= (0x4 << 8); | 774 | data |= (0x4 << 8); |
709 | break; | 775 | break; |
710 | case SH_FSI_BPFMD_16: | 776 | case SH_FSI_BPFMD_16: |
711 | if (fsi_ver < 2) | 777 | data |= (0x7 << 8); |
712 | dev_err(dev, "unsupported ACKMD\n"); | ||
713 | else | ||
714 | data |= (0x7 << 8); | ||
715 | break; | 778 | break; |
716 | } | 779 | } |
717 | 780 | ||
@@ -728,11 +791,26 @@ static int fsi_set_master_clk(struct device *dev, struct fsi_priv *fsi, | |||
728 | */ | 791 | */ |
729 | static void fsi_pio_push16(struct fsi_priv *fsi, u8 *_buf, int samples) | 792 | static void fsi_pio_push16(struct fsi_priv *fsi, u8 *_buf, int samples) |
730 | { | 793 | { |
731 | u16 *buf = (u16 *)_buf; | 794 | u32 enable_stream = fsi_get_info_flags(fsi) & SH_FSI_ENABLE_STREAM_MODE; |
732 | int i; | 795 | int i; |
733 | 796 | ||
734 | for (i = 0; i < samples; i++) | 797 | if (enable_stream) { |
735 | fsi_reg_write(fsi, DODT, ((u32)*(buf + i) << 8)); | 798 | /* |
799 | * stream mode | ||
800 | * see | ||
801 | * fsi_pio_push_init() | ||
802 | */ | ||
803 | u32 *buf = (u32 *)_buf; | ||
804 | |||
805 | for (i = 0; i < samples / 2; i++) | ||
806 | fsi_reg_write(fsi, DODT, buf[i]); | ||
807 | } else { | ||
808 | /* normal mode */ | ||
809 | u16 *buf = (u16 *)_buf; | ||
810 | |||
811 | for (i = 0; i < samples; i++) | ||
812 | fsi_reg_write(fsi, DODT, ((u32)*(buf + i) << 8)); | ||
813 | } | ||
736 | } | 814 | } |
737 | 815 | ||
738 | static void fsi_pio_pop16(struct fsi_priv *fsi, u8 *_buf, int samples) | 816 | static void fsi_pio_pop16(struct fsi_priv *fsi, u8 *_buf, int samples) |
@@ -872,12 +950,44 @@ static void fsi_pio_start_stop(struct fsi_priv *fsi, struct fsi_stream *io, | |||
872 | fsi_master_mask_set(master, CLK_RST, clk, (enable) ? clk : 0); | 950 | fsi_master_mask_set(master, CLK_RST, clk, (enable) ? clk : 0); |
873 | } | 951 | } |
874 | 952 | ||
953 | static int fsi_pio_push_init(struct fsi_priv *fsi, struct fsi_stream *io) | ||
954 | { | ||
955 | u32 enable_stream = fsi_get_info_flags(fsi) & SH_FSI_ENABLE_STREAM_MODE; | ||
956 | |||
957 | /* | ||
958 | * we can use 16bit stream mode | ||
959 | * when "playback" and "16bit data" | ||
960 | * and platform allows "stream mode" | ||
961 | * see | ||
962 | * fsi_pio_push16() | ||
963 | */ | ||
964 | if (enable_stream) | ||
965 | io->bus_option = BUSOP_SET(24, PACKAGE_24BITBUS_BACK) | | ||
966 | BUSOP_SET(16, PACKAGE_16BITBUS_STREAM); | ||
967 | else | ||
968 | io->bus_option = BUSOP_SET(24, PACKAGE_24BITBUS_BACK) | | ||
969 | BUSOP_SET(16, PACKAGE_24BITBUS_BACK); | ||
970 | return 0; | ||
971 | } | ||
972 | |||
973 | static int fsi_pio_pop_init(struct fsi_priv *fsi, struct fsi_stream *io) | ||
974 | { | ||
975 | /* | ||
976 | * always 24bit bus, package back when "capture" | ||
977 | */ | ||
978 | io->bus_option = BUSOP_SET(24, PACKAGE_24BITBUS_BACK) | | ||
979 | BUSOP_SET(16, PACKAGE_24BITBUS_BACK); | ||
980 | return 0; | ||
981 | } | ||
982 | |||
875 | static struct fsi_stream_handler fsi_pio_push_handler = { | 983 | static struct fsi_stream_handler fsi_pio_push_handler = { |
984 | .init = fsi_pio_push_init, | ||
876 | .transfer = fsi_pio_push, | 985 | .transfer = fsi_pio_push, |
877 | .start_stop = fsi_pio_start_stop, | 986 | .start_stop = fsi_pio_start_stop, |
878 | }; | 987 | }; |
879 | 988 | ||
880 | static struct fsi_stream_handler fsi_pio_pop_handler = { | 989 | static struct fsi_stream_handler fsi_pio_pop_handler = { |
990 | .init = fsi_pio_pop_init, | ||
881 | .transfer = fsi_pio_pop, | 991 | .transfer = fsi_pio_pop, |
882 | .start_stop = fsi_pio_start_stop, | 992 | .start_stop = fsi_pio_start_stop, |
883 | }; | 993 | }; |
@@ -919,6 +1029,13 @@ static int fsi_dma_init(struct fsi_priv *fsi, struct fsi_stream *io) | |||
919 | enum dma_data_direction dir = fsi_stream_is_play(fsi, io) ? | 1029 | enum dma_data_direction dir = fsi_stream_is_play(fsi, io) ? |
920 | DMA_TO_DEVICE : DMA_FROM_DEVICE; | 1030 | DMA_TO_DEVICE : DMA_FROM_DEVICE; |
921 | 1031 | ||
1032 | /* | ||
1033 | * 24bit data : 24bit bus / package in back | ||
1034 | * 16bit data : 16bit bus / stream mode | ||
1035 | */ | ||
1036 | io->bus_option = BUSOP_SET(24, PACKAGE_24BITBUS_BACK) | | ||
1037 | BUSOP_SET(16, PACKAGE_16BITBUS_STREAM); | ||
1038 | |||
922 | io->dma = dma_map_single(dai->dev, runtime->dma_area, | 1039 | io->dma = dma_map_single(dai->dev, runtime->dma_area, |
923 | snd_pcm_lib_buffer_bytes(io->substream), dir); | 1040 | snd_pcm_lib_buffer_bytes(io->substream), dir); |
924 | return 0; | 1041 | return 0; |
@@ -1055,25 +1172,9 @@ static int fsi_dma_transfer(struct fsi_priv *fsi, struct fsi_stream *io) | |||
1055 | static void fsi_dma_push_start_stop(struct fsi_priv *fsi, struct fsi_stream *io, | 1172 | static void fsi_dma_push_start_stop(struct fsi_priv *fsi, struct fsi_stream *io, |
1056 | int start) | 1173 | int start) |
1057 | { | 1174 | { |
1058 | u32 bws; | 1175 | u32 enable = start ? DMA_ON : 0; |
1059 | u32 dma; | ||
1060 | 1176 | ||
1061 | switch (io->sample_width * start) { | 1177 | fsi_reg_mask_set(fsi, OUT_DMAC, DMA_ON, enable); |
1062 | case 2: | ||
1063 | bws = CR_BWS_16; | ||
1064 | dma = VDMD_STREAM | DMA_ON; | ||
1065 | break; | ||
1066 | case 4: | ||
1067 | bws = CR_BWS_24; | ||
1068 | dma = VDMD_BACK | DMA_ON; | ||
1069 | break; | ||
1070 | default: | ||
1071 | bws = 0; | ||
1072 | dma = 0; | ||
1073 | } | ||
1074 | |||
1075 | fsi_reg_mask_set(fsi, DO_FMT, CR_BWS_MASK, bws); | ||
1076 | fsi_reg_write(fsi, OUT_DMAC, dma); | ||
1077 | } | 1178 | } |
1078 | 1179 | ||
1079 | static int fsi_dma_probe(struct fsi_priv *fsi, struct fsi_stream *io) | 1180 | static int fsi_dma_probe(struct fsi_priv *fsi, struct fsi_stream *io) |
@@ -1176,8 +1277,6 @@ static int fsi_hw_startup(struct fsi_priv *fsi, | |||
1176 | struct fsi_stream *io, | 1277 | struct fsi_stream *io, |
1177 | struct device *dev) | 1278 | struct device *dev) |
1178 | { | 1279 | { |
1179 | struct fsi_master *master = fsi_get_master(fsi); | ||
1180 | int fsi_ver = master->core->ver; | ||
1181 | u32 flags = fsi_get_info_flags(fsi); | 1280 | u32 flags = fsi_get_info_flags(fsi); |
1182 | u32 data = 0; | 1281 | u32 data = 0; |
1183 | 1282 | ||
@@ -1200,10 +1299,6 @@ static int fsi_hw_startup(struct fsi_priv *fsi, | |||
1200 | 1299 | ||
1201 | fsi_reg_write(fsi, CKG2, data); | 1300 | fsi_reg_write(fsi, CKG2, data); |
1202 | 1301 | ||
1203 | /* set format */ | ||
1204 | fsi_reg_write(fsi, DO_FMT, fsi->do_fmt); | ||
1205 | fsi_reg_write(fsi, DI_FMT, fsi->di_fmt); | ||
1206 | |||
1207 | /* spdif ? */ | 1302 | /* spdif ? */ |
1208 | if (fsi_is_spdif(fsi)) { | 1303 | if (fsi_is_spdif(fsi)) { |
1209 | fsi_spdif_clk_ctrl(fsi, 1); | 1304 | fsi_spdif_clk_ctrl(fsi, 1); |
@@ -1211,15 +1306,18 @@ static int fsi_hw_startup(struct fsi_priv *fsi, | |||
1211 | } | 1306 | } |
1212 | 1307 | ||
1213 | /* | 1308 | /* |
1214 | * FIXME | 1309 | * get bus settings |
1215 | * | ||
1216 | * FSI driver assumed that data package is in-back. | ||
1217 | * FSI2 chip can select it. | ||
1218 | */ | 1310 | */ |
1219 | if (fsi_ver >= 2) { | 1311 | data = 0; |
1220 | fsi_reg_write(fsi, OUT_DMAC, (1 << 4)); | 1312 | switch (io->sample_width) { |
1221 | fsi_reg_write(fsi, IN_DMAC, (1 << 4)); | 1313 | case 2: |
1314 | data = BUSOP_GET(16, io->bus_option); | ||
1315 | break; | ||
1316 | case 4: | ||
1317 | data = BUSOP_GET(24, io->bus_option); | ||
1318 | break; | ||
1222 | } | 1319 | } |
1320 | fsi_format_bus_setup(fsi, io, data, dev); | ||
1223 | 1321 | ||
1224 | /* irq clear */ | 1322 | /* irq clear */ |
1225 | fsi_irq_disable(fsi, io); | 1323 | fsi_irq_disable(fsi, io); |
@@ -1243,7 +1341,9 @@ static int fsi_dai_startup(struct snd_pcm_substream *substream, | |||
1243 | { | 1341 | { |
1244 | struct fsi_priv *fsi = fsi_get_priv(substream); | 1342 | struct fsi_priv *fsi = fsi_get_priv(substream); |
1245 | 1343 | ||
1246 | return fsi_hw_startup(fsi, fsi_stream_get(fsi, substream), dai->dev); | 1344 | fsi->rate = 0; |
1345 | |||
1346 | return 0; | ||
1247 | } | 1347 | } |
1248 | 1348 | ||
1249 | static void fsi_dai_shutdown(struct snd_pcm_substream *substream, | 1349 | static void fsi_dai_shutdown(struct snd_pcm_substream *substream, |
@@ -1251,7 +1351,6 @@ static void fsi_dai_shutdown(struct snd_pcm_substream *substream, | |||
1251 | { | 1351 | { |
1252 | struct fsi_priv *fsi = fsi_get_priv(substream); | 1352 | struct fsi_priv *fsi = fsi_get_priv(substream); |
1253 | 1353 | ||
1254 | fsi_hw_shutdown(fsi, dai->dev); | ||
1255 | fsi->rate = 0; | 1354 | fsi->rate = 0; |
1256 | } | 1355 | } |
1257 | 1356 | ||
@@ -1265,11 +1364,13 @@ static int fsi_dai_trigger(struct snd_pcm_substream *substream, int cmd, | |||
1265 | switch (cmd) { | 1364 | switch (cmd) { |
1266 | case SNDRV_PCM_TRIGGER_START: | 1365 | case SNDRV_PCM_TRIGGER_START: |
1267 | fsi_stream_init(fsi, io, substream); | 1366 | fsi_stream_init(fsi, io, substream); |
1367 | fsi_hw_startup(fsi, io, dai->dev); | ||
1268 | ret = fsi_stream_transfer(io); | 1368 | ret = fsi_stream_transfer(io); |
1269 | if (0 == ret) | 1369 | if (0 == ret) |
1270 | fsi_stream_start(fsi, io); | 1370 | fsi_stream_start(fsi, io); |
1271 | break; | 1371 | break; |
1272 | case SNDRV_PCM_TRIGGER_STOP: | 1372 | case SNDRV_PCM_TRIGGER_STOP: |
1373 | fsi_hw_shutdown(fsi, dai->dev); | ||
1273 | fsi_stream_stop(fsi, io); | 1374 | fsi_stream_stop(fsi, io); |
1274 | fsi_stream_quit(fsi, io); | 1375 | fsi_stream_quit(fsi, io); |
1275 | break; | 1376 | break; |
@@ -1280,42 +1381,33 @@ static int fsi_dai_trigger(struct snd_pcm_substream *substream, int cmd, | |||
1280 | 1381 | ||
1281 | static int fsi_set_fmt_dai(struct fsi_priv *fsi, unsigned int fmt) | 1382 | static int fsi_set_fmt_dai(struct fsi_priv *fsi, unsigned int fmt) |
1282 | { | 1383 | { |
1283 | u32 data = 0; | ||
1284 | |||
1285 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { | 1384 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { |
1286 | case SND_SOC_DAIFMT_I2S: | 1385 | case SND_SOC_DAIFMT_I2S: |
1287 | data = CR_I2S; | 1386 | fsi->fmt = CR_I2S; |
1288 | fsi->chan_num = 2; | 1387 | fsi->chan_num = 2; |
1289 | break; | 1388 | break; |
1290 | case SND_SOC_DAIFMT_LEFT_J: | 1389 | case SND_SOC_DAIFMT_LEFT_J: |
1291 | data = CR_PCM; | 1390 | fsi->fmt = CR_PCM; |
1292 | fsi->chan_num = 2; | 1391 | fsi->chan_num = 2; |
1293 | break; | 1392 | break; |
1294 | default: | 1393 | default: |
1295 | return -EINVAL; | 1394 | return -EINVAL; |
1296 | } | 1395 | } |
1297 | 1396 | ||
1298 | fsi->do_fmt = data; | ||
1299 | fsi->di_fmt = data; | ||
1300 | |||
1301 | return 0; | 1397 | return 0; |
1302 | } | 1398 | } |
1303 | 1399 | ||
1304 | static int fsi_set_fmt_spdif(struct fsi_priv *fsi) | 1400 | static int fsi_set_fmt_spdif(struct fsi_priv *fsi) |
1305 | { | 1401 | { |
1306 | struct fsi_master *master = fsi_get_master(fsi); | 1402 | struct fsi_master *master = fsi_get_master(fsi); |
1307 | u32 data = 0; | ||
1308 | 1403 | ||
1309 | if (master->core->ver < 2) | 1404 | if (fsi_version(master) < 2) |
1310 | return -EINVAL; | 1405 | return -EINVAL; |
1311 | 1406 | ||
1312 | data = CR_BWS_16 | CR_DTMD_SPDIF_PCM | CR_PCM; | 1407 | fsi->fmt = CR_DTMD_SPDIF_PCM | CR_PCM; |
1313 | fsi->chan_num = 2; | 1408 | fsi->chan_num = 2; |
1314 | fsi->spdif = 1; | 1409 | fsi->spdif = 1; |
1315 | 1410 | ||
1316 | fsi->do_fmt = data; | ||
1317 | fsi->di_fmt = data; | ||
1318 | |||
1319 | return 0; | 1411 | return 0; |
1320 | } | 1412 | } |
1321 | 1413 | ||
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index c88d9741b9e7..b37ee8077ed1 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c | |||
@@ -39,6 +39,7 @@ | |||
39 | #include <sound/pcm.h> | 39 | #include <sound/pcm.h> |
40 | #include <sound/pcm_params.h> | 40 | #include <sound/pcm_params.h> |
41 | #include <sound/soc.h> | 41 | #include <sound/soc.h> |
42 | #include <sound/soc-dpcm.h> | ||
42 | #include <sound/initval.h> | 43 | #include <sound/initval.h> |
43 | 44 | ||
44 | #define CREATE_TRACE_POINTS | 45 | #define CREATE_TRACE_POINTS |
@@ -54,7 +55,6 @@ EXPORT_SYMBOL_GPL(snd_soc_debugfs_root); | |||
54 | #endif | 55 | #endif |
55 | 56 | ||
56 | static DEFINE_MUTEX(client_mutex); | 57 | static DEFINE_MUTEX(client_mutex); |
57 | static LIST_HEAD(card_list); | ||
58 | static LIST_HEAD(dai_list); | 58 | static LIST_HEAD(dai_list); |
59 | static LIST_HEAD(platform_list); | 59 | static LIST_HEAD(platform_list); |
60 | static LIST_HEAD(codec_list); | 60 | static LIST_HEAD(codec_list); |
@@ -465,6 +465,35 @@ static inline void soc_cleanup_card_debugfs(struct snd_soc_card *card) | |||
465 | } | 465 | } |
466 | #endif | 466 | #endif |
467 | 467 | ||
468 | struct snd_pcm_substream *snd_soc_get_dai_substream(struct snd_soc_card *card, | ||
469 | const char *dai_link, int stream) | ||
470 | { | ||
471 | int i; | ||
472 | |||
473 | for (i = 0; i < card->num_links; i++) { | ||
474 | if (card->rtd[i].dai_link->no_pcm && | ||
475 | !strcmp(card->rtd[i].dai_link->name, dai_link)) | ||
476 | return card->rtd[i].pcm->streams[stream].substream; | ||
477 | } | ||
478 | dev_dbg(card->dev, "failed to find dai link %s\n", dai_link); | ||
479 | return NULL; | ||
480 | } | ||
481 | EXPORT_SYMBOL_GPL(snd_soc_get_dai_substream); | ||
482 | |||
483 | struct snd_soc_pcm_runtime *snd_soc_get_pcm_runtime(struct snd_soc_card *card, | ||
484 | const char *dai_link) | ||
485 | { | ||
486 | int i; | ||
487 | |||
488 | for (i = 0; i < card->num_links; i++) { | ||
489 | if (!strcmp(card->rtd[i].dai_link->name, dai_link)) | ||
490 | return &card->rtd[i]; | ||
491 | } | ||
492 | dev_dbg(card->dev, "failed to find rtd %s\n", dai_link); | ||
493 | return NULL; | ||
494 | } | ||
495 | EXPORT_SYMBOL_GPL(snd_soc_get_pcm_runtime); | ||
496 | |||
468 | #ifdef CONFIG_SND_SOC_AC97_BUS | 497 | #ifdef CONFIG_SND_SOC_AC97_BUS |
469 | /* unregister ac97 codec */ | 498 | /* unregister ac97 codec */ |
470 | static int soc_ac97_dev_unregister(struct snd_soc_codec *codec) | 499 | static int soc_ac97_dev_unregister(struct snd_soc_codec *codec) |
@@ -567,19 +596,16 @@ int snd_soc_suspend(struct device *dev) | |||
567 | } | 596 | } |
568 | 597 | ||
569 | for (i = 0; i < card->num_rtd; i++) { | 598 | for (i = 0; i < card->num_rtd; i++) { |
570 | struct snd_soc_dai *codec_dai = card->rtd[i].codec_dai; | ||
571 | 599 | ||
572 | if (card->rtd[i].dai_link->ignore_suspend) | 600 | if (card->rtd[i].dai_link->ignore_suspend) |
573 | continue; | 601 | continue; |
574 | 602 | ||
575 | snd_soc_dapm_stream_event(&card->rtd[i], | 603 | snd_soc_dapm_stream_event(&card->rtd[i], |
576 | SNDRV_PCM_STREAM_PLAYBACK, | 604 | SNDRV_PCM_STREAM_PLAYBACK, |
577 | codec_dai, | ||
578 | SND_SOC_DAPM_STREAM_SUSPEND); | 605 | SND_SOC_DAPM_STREAM_SUSPEND); |
579 | 606 | ||
580 | snd_soc_dapm_stream_event(&card->rtd[i], | 607 | snd_soc_dapm_stream_event(&card->rtd[i], |
581 | SNDRV_PCM_STREAM_CAPTURE, | 608 | SNDRV_PCM_STREAM_CAPTURE, |
582 | codec_dai, | ||
583 | SND_SOC_DAPM_STREAM_SUSPEND); | 609 | SND_SOC_DAPM_STREAM_SUSPEND); |
584 | } | 610 | } |
585 | 611 | ||
@@ -683,17 +709,16 @@ static void soc_resume_deferred(struct work_struct *work) | |||
683 | } | 709 | } |
684 | 710 | ||
685 | for (i = 0; i < card->num_rtd; i++) { | 711 | for (i = 0; i < card->num_rtd; i++) { |
686 | struct snd_soc_dai *codec_dai = card->rtd[i].codec_dai; | ||
687 | 712 | ||
688 | if (card->rtd[i].dai_link->ignore_suspend) | 713 | if (card->rtd[i].dai_link->ignore_suspend) |
689 | continue; | 714 | continue; |
690 | 715 | ||
691 | snd_soc_dapm_stream_event(&card->rtd[i], | 716 | snd_soc_dapm_stream_event(&card->rtd[i], |
692 | SNDRV_PCM_STREAM_PLAYBACK, codec_dai, | 717 | SNDRV_PCM_STREAM_PLAYBACK, |
693 | SND_SOC_DAPM_STREAM_RESUME); | 718 | SND_SOC_DAPM_STREAM_RESUME); |
694 | 719 | ||
695 | snd_soc_dapm_stream_event(&card->rtd[i], | 720 | snd_soc_dapm_stream_event(&card->rtd[i], |
696 | SNDRV_PCM_STREAM_CAPTURE, codec_dai, | 721 | SNDRV_PCM_STREAM_CAPTURE, |
697 | SND_SOC_DAPM_STREAM_RESUME); | 722 | SND_SOC_DAPM_STREAM_RESUME); |
698 | } | 723 | } |
699 | 724 | ||
@@ -783,15 +808,9 @@ static int soc_bind_dai_link(struct snd_soc_card *card, int num) | |||
783 | struct snd_soc_dai *codec_dai, *cpu_dai; | 808 | struct snd_soc_dai *codec_dai, *cpu_dai; |
784 | const char *platform_name; | 809 | const char *platform_name; |
785 | 810 | ||
786 | if (rtd->complete) | ||
787 | return 1; | ||
788 | dev_dbg(card->dev, "binding %s at idx %d\n", dai_link->name, num); | 811 | dev_dbg(card->dev, "binding %s at idx %d\n", dai_link->name, num); |
789 | 812 | ||
790 | /* do we already have the CPU DAI for this link ? */ | 813 | /* Find CPU DAI from registered DAIs*/ |
791 | if (rtd->cpu_dai) { | ||
792 | goto find_codec; | ||
793 | } | ||
794 | /* no, then find CPU DAI from registered DAIs*/ | ||
795 | list_for_each_entry(cpu_dai, &dai_list, list) { | 814 | list_for_each_entry(cpu_dai, &dai_list, list) { |
796 | if (dai_link->cpu_dai_of_node) { | 815 | if (dai_link->cpu_dai_of_node) { |
797 | if (cpu_dai->dev->of_node != dai_link->cpu_dai_of_node) | 816 | if (cpu_dai->dev->of_node != dai_link->cpu_dai_of_node) |
@@ -802,18 +821,15 @@ static int soc_bind_dai_link(struct snd_soc_card *card, int num) | |||
802 | } | 821 | } |
803 | 822 | ||
804 | rtd->cpu_dai = cpu_dai; | 823 | rtd->cpu_dai = cpu_dai; |
805 | goto find_codec; | ||
806 | } | 824 | } |
807 | dev_dbg(card->dev, "CPU DAI %s not registered\n", | ||
808 | dai_link->cpu_dai_name); | ||
809 | 825 | ||
810 | find_codec: | 826 | if (!rtd->cpu_dai) { |
811 | /* do we already have the CODEC for this link ? */ | 827 | dev_dbg(card->dev, "CPU DAI %s not registered\n", |
812 | if (rtd->codec) { | 828 | dai_link->cpu_dai_name); |
813 | goto find_platform; | 829 | return -EPROBE_DEFER; |
814 | } | 830 | } |
815 | 831 | ||
816 | /* no, then find CODEC from registered CODECs*/ | 832 | /* Find CODEC from registered CODECs */ |
817 | list_for_each_entry(codec, &codec_list, list) { | 833 | list_for_each_entry(codec, &codec_list, list) { |
818 | if (dai_link->codec_of_node) { | 834 | if (dai_link->codec_of_node) { |
819 | if (codec->dev->of_node != dai_link->codec_of_node) | 835 | if (codec->dev->of_node != dai_link->codec_of_node) |
@@ -835,28 +851,28 @@ find_codec: | |||
835 | dai_link->codec_dai_name)) { | 851 | dai_link->codec_dai_name)) { |
836 | 852 | ||
837 | rtd->codec_dai = codec_dai; | 853 | rtd->codec_dai = codec_dai; |
838 | goto find_platform; | ||
839 | } | 854 | } |
840 | } | 855 | } |
841 | dev_dbg(card->dev, "CODEC DAI %s not registered\n", | ||
842 | dai_link->codec_dai_name); | ||
843 | 856 | ||
844 | goto find_platform; | 857 | if (!rtd->codec_dai) { |
858 | dev_dbg(card->dev, "CODEC DAI %s not registered\n", | ||
859 | dai_link->codec_dai_name); | ||
860 | return -EPROBE_DEFER; | ||
861 | } | ||
845 | } | 862 | } |
846 | dev_dbg(card->dev, "CODEC %s not registered\n", | ||
847 | dai_link->codec_name); | ||
848 | 863 | ||
849 | find_platform: | 864 | if (!rtd->codec) { |
850 | /* do we need a platform? */ | 865 | dev_dbg(card->dev, "CODEC %s not registered\n", |
851 | if (rtd->platform) | 866 | dai_link->codec_name); |
852 | goto out; | 867 | return -EPROBE_DEFER; |
868 | } | ||
853 | 869 | ||
854 | /* if there's no platform we match on the empty platform */ | 870 | /* if there's no platform we match on the empty platform */ |
855 | platform_name = dai_link->platform_name; | 871 | platform_name = dai_link->platform_name; |
856 | if (!platform_name && !dai_link->platform_of_node) | 872 | if (!platform_name && !dai_link->platform_of_node) |
857 | platform_name = "snd-soc-dummy"; | 873 | platform_name = "snd-soc-dummy"; |
858 | 874 | ||
859 | /* no, then find one from the set of registered platforms */ | 875 | /* find one from the set of registered platforms */ |
860 | list_for_each_entry(platform, &platform_list, list) { | 876 | list_for_each_entry(platform, &platform_list, list) { |
861 | if (dai_link->platform_of_node) { | 877 | if (dai_link->platform_of_node) { |
862 | if (platform->dev->of_node != | 878 | if (platform->dev->of_node != |
@@ -868,20 +884,16 @@ find_platform: | |||
868 | } | 884 | } |
869 | 885 | ||
870 | rtd->platform = platform; | 886 | rtd->platform = platform; |
871 | goto out; | ||
872 | } | 887 | } |
873 | 888 | if (!rtd->platform) { | |
874 | dev_dbg(card->dev, "platform %s not registered\n", | 889 | dev_dbg(card->dev, "platform %s not registered\n", |
875 | dai_link->platform_name); | 890 | dai_link->platform_name); |
876 | return 0; | 891 | return -EPROBE_DEFER; |
877 | |||
878 | out: | ||
879 | /* mark rtd as complete if we found all 4 of our client devices */ | ||
880 | if (rtd->codec && rtd->codec_dai && rtd->platform && rtd->cpu_dai) { | ||
881 | rtd->complete = 1; | ||
882 | card->num_rtd++; | ||
883 | } | 892 | } |
884 | return 1; | 893 | |
894 | card->num_rtd++; | ||
895 | |||
896 | return 0; | ||
885 | } | 897 | } |
886 | 898 | ||
887 | static void soc_remove_codec(struct snd_soc_codec *codec) | 899 | static void soc_remove_codec(struct snd_soc_codec *codec) |
@@ -1068,6 +1080,7 @@ static int soc_probe_platform(struct snd_soc_card *card, | |||
1068 | { | 1080 | { |
1069 | int ret = 0; | 1081 | int ret = 0; |
1070 | const struct snd_soc_platform_driver *driver = platform->driver; | 1082 | const struct snd_soc_platform_driver *driver = platform->driver; |
1083 | struct snd_soc_dai *dai; | ||
1071 | 1084 | ||
1072 | platform->card = card; | 1085 | platform->card = card; |
1073 | platform->dapm.card = card; | 1086 | platform->dapm.card = card; |
@@ -1081,6 +1094,14 @@ static int soc_probe_platform(struct snd_soc_card *card, | |||
1081 | snd_soc_dapm_new_controls(&platform->dapm, | 1094 | snd_soc_dapm_new_controls(&platform->dapm, |
1082 | driver->dapm_widgets, driver->num_dapm_widgets); | 1095 | driver->dapm_widgets, driver->num_dapm_widgets); |
1083 | 1096 | ||
1097 | /* Create DAPM widgets for each DAI stream */ | ||
1098 | list_for_each_entry(dai, &dai_list, list) { | ||
1099 | if (dai->dev != platform->dev) | ||
1100 | continue; | ||
1101 | |||
1102 | snd_soc_dapm_new_dai_widgets(&platform->dapm, dai); | ||
1103 | } | ||
1104 | |||
1084 | platform->dapm.idle_bias_off = 1; | 1105 | platform->dapm.idle_bias_off = 1; |
1085 | 1106 | ||
1086 | if (driver->probe) { | 1107 | if (driver->probe) { |
@@ -1170,6 +1191,10 @@ static int soc_post_component_init(struct snd_soc_card *card, | |||
1170 | rtd->dev->init_name = name; | 1191 | rtd->dev->init_name = name; |
1171 | dev_set_drvdata(rtd->dev, rtd); | 1192 | dev_set_drvdata(rtd->dev, rtd); |
1172 | mutex_init(&rtd->pcm_mutex); | 1193 | mutex_init(&rtd->pcm_mutex); |
1194 | INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_PLAYBACK].be_clients); | ||
1195 | INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_CAPTURE].be_clients); | ||
1196 | INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_PLAYBACK].fe_clients); | ||
1197 | INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_CAPTURE].fe_clients); | ||
1173 | ret = device_add(rtd->dev); | 1198 | ret = device_add(rtd->dev); |
1174 | if (ret < 0) { | 1199 | if (ret < 0) { |
1175 | dev_err(card->dev, | 1200 | dev_err(card->dev, |
@@ -1191,6 +1216,17 @@ static int soc_post_component_init(struct snd_soc_card *card, | |||
1191 | dev_err(codec->dev, | 1216 | dev_err(codec->dev, |
1192 | "asoc: failed to add codec sysfs files: %d\n", ret); | 1217 | "asoc: failed to add codec sysfs files: %d\n", ret); |
1193 | 1218 | ||
1219 | #ifdef CONFIG_DEBUG_FS | ||
1220 | /* add DPCM sysfs entries */ | ||
1221 | if (!dailess && !dai_link->dynamic) | ||
1222 | goto out; | ||
1223 | |||
1224 | ret = soc_dpcm_debugfs_add(rtd); | ||
1225 | if (ret < 0) | ||
1226 | dev_err(rtd->dev, "asoc: failed to add dpcm sysfs entries: %d\n", ret); | ||
1227 | |||
1228 | out: | ||
1229 | #endif | ||
1194 | return 0; | 1230 | return 0; |
1195 | } | 1231 | } |
1196 | 1232 | ||
@@ -1200,14 +1236,15 @@ static int soc_probe_dai_link(struct snd_soc_card *card, int num, int order) | |||
1200 | struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; | 1236 | struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; |
1201 | struct snd_soc_codec *codec = rtd->codec; | 1237 | struct snd_soc_codec *codec = rtd->codec; |
1202 | struct snd_soc_platform *platform = rtd->platform; | 1238 | struct snd_soc_platform *platform = rtd->platform; |
1203 | struct snd_soc_dai *codec_dai = rtd->codec_dai, *cpu_dai = rtd->cpu_dai; | 1239 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
1240 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; | ||
1241 | struct snd_soc_dapm_widget *play_w, *capture_w; | ||
1204 | int ret; | 1242 | int ret; |
1205 | 1243 | ||
1206 | dev_dbg(card->dev, "probe %s dai link %d late %d\n", | 1244 | dev_dbg(card->dev, "probe %s dai link %d late %d\n", |
1207 | card->name, num, order); | 1245 | card->name, num, order); |
1208 | 1246 | ||
1209 | /* config components */ | 1247 | /* config components */ |
1210 | codec_dai->codec = codec; | ||
1211 | cpu_dai->platform = platform; | 1248 | cpu_dai->platform = platform; |
1212 | codec_dai->card = card; | 1249 | codec_dai->card = card; |
1213 | cpu_dai->card = card; | 1250 | cpu_dai->card = card; |
@@ -1218,9 +1255,12 @@ static int soc_probe_dai_link(struct snd_soc_card *card, int num, int order) | |||
1218 | /* probe the cpu_dai */ | 1255 | /* probe the cpu_dai */ |
1219 | if (!cpu_dai->probed && | 1256 | if (!cpu_dai->probed && |
1220 | cpu_dai->driver->probe_order == order) { | 1257 | cpu_dai->driver->probe_order == order) { |
1258 | cpu_dai->dapm.card = card; | ||
1221 | if (!try_module_get(cpu_dai->dev->driver->owner)) | 1259 | if (!try_module_get(cpu_dai->dev->driver->owner)) |
1222 | return -ENODEV; | 1260 | return -ENODEV; |
1223 | 1261 | ||
1262 | snd_soc_dapm_new_dai_widgets(&cpu_dai->dapm, cpu_dai); | ||
1263 | |||
1224 | if (cpu_dai->driver->probe) { | 1264 | if (cpu_dai->driver->probe) { |
1225 | ret = cpu_dai->driver->probe(cpu_dai); | 1265 | ret = cpu_dai->driver->probe(cpu_dai); |
1226 | if (ret < 0) { | 1266 | if (ret < 0) { |
@@ -1279,12 +1319,39 @@ static int soc_probe_dai_link(struct snd_soc_card *card, int num, int order) | |||
1279 | if (ret < 0) | 1319 | if (ret < 0) |
1280 | pr_warn("asoc: failed to add pmdown_time sysfs:%d\n", ret); | 1320 | pr_warn("asoc: failed to add pmdown_time sysfs:%d\n", ret); |
1281 | 1321 | ||
1282 | /* create the pcm */ | 1322 | if (!dai_link->params) { |
1283 | ret = soc_new_pcm(rtd, num); | 1323 | /* create the pcm */ |
1284 | if (ret < 0) { | 1324 | ret = soc_new_pcm(rtd, num); |
1285 | pr_err("asoc: can't create pcm %s :%d\n", | 1325 | if (ret < 0) { |
1286 | dai_link->stream_name, ret); | 1326 | pr_err("asoc: can't create pcm %s :%d\n", |
1287 | return ret; | 1327 | dai_link->stream_name, ret); |
1328 | return ret; | ||
1329 | } | ||
1330 | } else { | ||
1331 | /* link the DAI widgets */ | ||
1332 | play_w = codec_dai->playback_widget; | ||
1333 | capture_w = cpu_dai->capture_widget; | ||
1334 | if (play_w && capture_w) { | ||
1335 | ret = snd_soc_dapm_new_pcm(card, dai_link->params, | ||
1336 | capture_w, play_w); | ||
1337 | if (ret != 0) { | ||
1338 | dev_err(card->dev, "Can't link %s to %s: %d\n", | ||
1339 | play_w->name, capture_w->name, ret); | ||
1340 | return ret; | ||
1341 | } | ||
1342 | } | ||
1343 | |||
1344 | play_w = cpu_dai->playback_widget; | ||
1345 | capture_w = codec_dai->capture_widget; | ||
1346 | if (play_w && capture_w) { | ||
1347 | ret = snd_soc_dapm_new_pcm(card, dai_link->params, | ||
1348 | capture_w, play_w); | ||
1349 | if (ret != 0) { | ||
1350 | dev_err(card->dev, "Can't link %s to %s: %d\n", | ||
1351 | play_w->name, capture_w->name, ret); | ||
1352 | return ret; | ||
1353 | } | ||
1354 | } | ||
1288 | } | 1355 | } |
1289 | 1356 | ||
1290 | /* add platform data for AC97 devices */ | 1357 | /* add platform data for AC97 devices */ |
@@ -1334,6 +1401,20 @@ static void soc_unregister_ac97_dai_link(struct snd_soc_codec *codec) | |||
1334 | } | 1401 | } |
1335 | #endif | 1402 | #endif |
1336 | 1403 | ||
1404 | static int soc_check_aux_dev(struct snd_soc_card *card, int num) | ||
1405 | { | ||
1406 | struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num]; | ||
1407 | struct snd_soc_codec *codec; | ||
1408 | |||
1409 | /* find CODEC from registered CODECs*/ | ||
1410 | list_for_each_entry(codec, &codec_list, list) { | ||
1411 | if (!strcmp(codec->name, aux_dev->codec_name)) | ||
1412 | return 0; | ||
1413 | } | ||
1414 | |||
1415 | return -EPROBE_DEFER; | ||
1416 | } | ||
1417 | |||
1337 | static int soc_probe_aux_dev(struct snd_soc_card *card, int num) | 1418 | static int soc_probe_aux_dev(struct snd_soc_card *card, int num) |
1338 | { | 1419 | { |
1339 | struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num]; | 1420 | struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num]; |
@@ -1354,7 +1435,7 @@ static int soc_probe_aux_dev(struct snd_soc_card *card, int num) | |||
1354 | } | 1435 | } |
1355 | /* codec not found */ | 1436 | /* codec not found */ |
1356 | dev_err(card->dev, "asoc: codec %s not found", aux_dev->codec_name); | 1437 | dev_err(card->dev, "asoc: codec %s not found", aux_dev->codec_name); |
1357 | goto out; | 1438 | return -EPROBE_DEFER; |
1358 | 1439 | ||
1359 | found: | 1440 | found: |
1360 | ret = soc_probe_codec(card, codec); | 1441 | ret = soc_probe_codec(card, codec); |
@@ -1404,29 +1485,28 @@ static int snd_soc_init_codec_cache(struct snd_soc_codec *codec, | |||
1404 | return 0; | 1485 | return 0; |
1405 | } | 1486 | } |
1406 | 1487 | ||
1407 | static void snd_soc_instantiate_card(struct snd_soc_card *card) | 1488 | static int snd_soc_instantiate_card(struct snd_soc_card *card) |
1408 | { | 1489 | { |
1409 | struct snd_soc_codec *codec; | 1490 | struct snd_soc_codec *codec; |
1410 | struct snd_soc_codec_conf *codec_conf; | 1491 | struct snd_soc_codec_conf *codec_conf; |
1411 | enum snd_soc_compress_type compress_type; | 1492 | enum snd_soc_compress_type compress_type; |
1412 | struct snd_soc_dai_link *dai_link; | 1493 | struct snd_soc_dai_link *dai_link; |
1413 | int ret, i, order; | 1494 | int ret, i, order, dai_fmt; |
1414 | 1495 | ||
1415 | mutex_lock(&card->mutex); | 1496 | mutex_lock_nested(&card->mutex, SND_SOC_CARD_CLASS_INIT); |
1416 | |||
1417 | if (card->instantiated) { | ||
1418 | mutex_unlock(&card->mutex); | ||
1419 | return; | ||
1420 | } | ||
1421 | 1497 | ||
1422 | /* bind DAIs */ | 1498 | /* bind DAIs */ |
1423 | for (i = 0; i < card->num_links; i++) | 1499 | for (i = 0; i < card->num_links; i++) { |
1424 | soc_bind_dai_link(card, i); | 1500 | ret = soc_bind_dai_link(card, i); |
1501 | if (ret != 0) | ||
1502 | goto base_error; | ||
1503 | } | ||
1425 | 1504 | ||
1426 | /* bind completed ? */ | 1505 | /* check aux_devs too */ |
1427 | if (card->num_rtd != card->num_links) { | 1506 | for (i = 0; i < card->num_aux_devs; i++) { |
1428 | mutex_unlock(&card->mutex); | 1507 | ret = soc_check_aux_dev(card, i); |
1429 | return; | 1508 | if (ret != 0) |
1509 | goto base_error; | ||
1430 | } | 1510 | } |
1431 | 1511 | ||
1432 | /* initialize the register cache for each available codec */ | 1512 | /* initialize the register cache for each available codec */ |
@@ -1446,10 +1526,8 @@ static void snd_soc_instantiate_card(struct snd_soc_card *card) | |||
1446 | } | 1526 | } |
1447 | } | 1527 | } |
1448 | ret = snd_soc_init_codec_cache(codec, compress_type); | 1528 | ret = snd_soc_init_codec_cache(codec, compress_type); |
1449 | if (ret < 0) { | 1529 | if (ret < 0) |
1450 | mutex_unlock(&card->mutex); | 1530 | goto base_error; |
1451 | return; | ||
1452 | } | ||
1453 | } | 1531 | } |
1454 | 1532 | ||
1455 | /* card bind complete so register a sound card */ | 1533 | /* card bind complete so register a sound card */ |
@@ -1458,8 +1536,7 @@ static void snd_soc_instantiate_card(struct snd_soc_card *card) | |||
1458 | if (ret < 0) { | 1536 | if (ret < 0) { |
1459 | pr_err("asoc: can't create sound card for card %s: %d\n", | 1537 | pr_err("asoc: can't create sound card for card %s: %d\n", |
1460 | card->name, ret); | 1538 | card->name, ret); |
1461 | mutex_unlock(&card->mutex); | 1539 | goto base_error; |
1462 | return; | ||
1463 | } | 1540 | } |
1464 | card->snd_card->dev = card->dev; | 1541 | card->snd_card->dev = card->dev; |
1465 | 1542 | ||
@@ -1523,17 +1600,47 @@ static void snd_soc_instantiate_card(struct snd_soc_card *card) | |||
1523 | 1600 | ||
1524 | for (i = 0; i < card->num_links; i++) { | 1601 | for (i = 0; i < card->num_links; i++) { |
1525 | dai_link = &card->dai_link[i]; | 1602 | dai_link = &card->dai_link[i]; |
1603 | dai_fmt = dai_link->dai_fmt; | ||
1526 | 1604 | ||
1527 | if (dai_link->dai_fmt) { | 1605 | if (dai_fmt) { |
1528 | ret = snd_soc_dai_set_fmt(card->rtd[i].codec_dai, | 1606 | ret = snd_soc_dai_set_fmt(card->rtd[i].codec_dai, |
1529 | dai_link->dai_fmt); | 1607 | dai_fmt); |
1530 | if (ret != 0 && ret != -ENOTSUPP) | 1608 | if (ret != 0 && ret != -ENOTSUPP) |
1531 | dev_warn(card->rtd[i].codec_dai->dev, | 1609 | dev_warn(card->rtd[i].codec_dai->dev, |
1532 | "Failed to set DAI format: %d\n", | 1610 | "Failed to set DAI format: %d\n", |
1533 | ret); | 1611 | ret); |
1612 | } | ||
1534 | 1613 | ||
1614 | /* If this is a regular CPU link there will be a platform */ | ||
1615 | if (dai_fmt && | ||
1616 | (dai_link->platform_name || dai_link->platform_of_node)) { | ||
1535 | ret = snd_soc_dai_set_fmt(card->rtd[i].cpu_dai, | 1617 | ret = snd_soc_dai_set_fmt(card->rtd[i].cpu_dai, |
1536 | dai_link->dai_fmt); | 1618 | dai_fmt); |
1619 | if (ret != 0 && ret != -ENOTSUPP) | ||
1620 | dev_warn(card->rtd[i].cpu_dai->dev, | ||
1621 | "Failed to set DAI format: %d\n", | ||
1622 | ret); | ||
1623 | } else if (dai_fmt) { | ||
1624 | /* Flip the polarity for the "CPU" end */ | ||
1625 | dai_fmt &= ~SND_SOC_DAIFMT_MASTER_MASK; | ||
1626 | switch (dai_link->dai_fmt & | ||
1627 | SND_SOC_DAIFMT_MASTER_MASK) { | ||
1628 | case SND_SOC_DAIFMT_CBM_CFM: | ||
1629 | dai_fmt |= SND_SOC_DAIFMT_CBS_CFS; | ||
1630 | break; | ||
1631 | case SND_SOC_DAIFMT_CBM_CFS: | ||
1632 | dai_fmt |= SND_SOC_DAIFMT_CBS_CFM; | ||
1633 | break; | ||
1634 | case SND_SOC_DAIFMT_CBS_CFM: | ||
1635 | dai_fmt |= SND_SOC_DAIFMT_CBM_CFS; | ||
1636 | break; | ||
1637 | case SND_SOC_DAIFMT_CBS_CFS: | ||
1638 | dai_fmt |= SND_SOC_DAIFMT_CBM_CFM; | ||
1639 | break; | ||
1640 | } | ||
1641 | |||
1642 | ret = snd_soc_dai_set_fmt(card->rtd[i].cpu_dai, | ||
1643 | dai_fmt); | ||
1537 | if (ret != 0 && ret != -ENOTSUPP) | 1644 | if (ret != 0 && ret != -ENOTSUPP) |
1538 | dev_warn(card->rtd[i].cpu_dai->dev, | 1645 | dev_warn(card->rtd[i].cpu_dai->dev, |
1539 | "Failed to set DAI format: %d\n", | 1646 | "Failed to set DAI format: %d\n", |
@@ -1599,7 +1706,8 @@ static void snd_soc_instantiate_card(struct snd_soc_card *card) | |||
1599 | card->instantiated = 1; | 1706 | card->instantiated = 1; |
1600 | snd_soc_dapm_sync(&card->dapm); | 1707 | snd_soc_dapm_sync(&card->dapm); |
1601 | mutex_unlock(&card->mutex); | 1708 | mutex_unlock(&card->mutex); |
1602 | return; | 1709 | |
1710 | return 0; | ||
1603 | 1711 | ||
1604 | probe_aux_dev_err: | 1712 | probe_aux_dev_err: |
1605 | for (i = 0; i < card->num_aux_devs; i++) | 1713 | for (i = 0; i < card->num_aux_devs; i++) |
@@ -1614,18 +1722,10 @@ card_probe_error: | |||
1614 | 1722 | ||
1615 | snd_card_free(card->snd_card); | 1723 | snd_card_free(card->snd_card); |
1616 | 1724 | ||
1725 | base_error: | ||
1617 | mutex_unlock(&card->mutex); | 1726 | mutex_unlock(&card->mutex); |
1618 | } | ||
1619 | 1727 | ||
1620 | /* | 1728 | return ret; |
1621 | * Attempt to initialise any uninitialised cards. Must be called with | ||
1622 | * client_mutex. | ||
1623 | */ | ||
1624 | static void snd_soc_instantiate_cards(void) | ||
1625 | { | ||
1626 | struct snd_soc_card *card; | ||
1627 | list_for_each_entry(card, &card_list, list) | ||
1628 | snd_soc_instantiate_card(card); | ||
1629 | } | 1729 | } |
1630 | 1730 | ||
1631 | /* probes a new socdev */ | 1731 | /* probes a new socdev */ |
@@ -2527,6 +2627,87 @@ int snd_soc_put_volsw(struct snd_kcontrol *kcontrol, | |||
2527 | EXPORT_SYMBOL_GPL(snd_soc_put_volsw); | 2627 | EXPORT_SYMBOL_GPL(snd_soc_put_volsw); |
2528 | 2628 | ||
2529 | /** | 2629 | /** |
2630 | * snd_soc_get_volsw_sx - single mixer get callback | ||
2631 | * @kcontrol: mixer control | ||
2632 | * @ucontrol: control element information | ||
2633 | * | ||
2634 | * Callback to get the value of a single mixer control, or a double mixer | ||
2635 | * control that spans 2 registers. | ||
2636 | * | ||
2637 | * Returns 0 for success. | ||
2638 | */ | ||
2639 | int snd_soc_get_volsw_sx(struct snd_kcontrol *kcontrol, | ||
2640 | struct snd_ctl_elem_value *ucontrol) | ||
2641 | { | ||
2642 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); | ||
2643 | struct soc_mixer_control *mc = | ||
2644 | (struct soc_mixer_control *)kcontrol->private_value; | ||
2645 | |||
2646 | unsigned int reg = mc->reg; | ||
2647 | unsigned int reg2 = mc->rreg; | ||
2648 | unsigned int shift = mc->shift; | ||
2649 | unsigned int rshift = mc->rshift; | ||
2650 | int max = mc->max; | ||
2651 | int min = mc->min; | ||
2652 | int mask = (1 << (fls(min + max) - 1)) - 1; | ||
2653 | |||
2654 | ucontrol->value.integer.value[0] = | ||
2655 | ((snd_soc_read(codec, reg) >> shift) - min) & mask; | ||
2656 | |||
2657 | if (snd_soc_volsw_is_stereo(mc)) | ||
2658 | ucontrol->value.integer.value[1] = | ||
2659 | ((snd_soc_read(codec, reg2) >> rshift) - min) & mask; | ||
2660 | |||
2661 | return 0; | ||
2662 | } | ||
2663 | EXPORT_SYMBOL_GPL(snd_soc_get_volsw_sx); | ||
2664 | |||
2665 | /** | ||
2666 | * snd_soc_put_volsw_sx - double mixer set callback | ||
2667 | * @kcontrol: mixer control | ||
2668 | * @uinfo: control element information | ||
2669 | * | ||
2670 | * Callback to set the value of a double mixer control that spans 2 registers. | ||
2671 | * | ||
2672 | * Returns 0 for success. | ||
2673 | */ | ||
2674 | int snd_soc_put_volsw_sx(struct snd_kcontrol *kcontrol, | ||
2675 | struct snd_ctl_elem_value *ucontrol) | ||
2676 | { | ||
2677 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); | ||
2678 | struct soc_mixer_control *mc = | ||
2679 | (struct soc_mixer_control *)kcontrol->private_value; | ||
2680 | |||
2681 | unsigned int reg = mc->reg; | ||
2682 | unsigned int reg2 = mc->rreg; | ||
2683 | unsigned int shift = mc->shift; | ||
2684 | unsigned int rshift = mc->rshift; | ||
2685 | int max = mc->max; | ||
2686 | int min = mc->min; | ||
2687 | int mask = (1 << (fls(min + max) - 1)) - 1; | ||
2688 | int err = 0; | ||
2689 | unsigned short val, val_mask, val2 = 0; | ||
2690 | |||
2691 | val_mask = mask << shift; | ||
2692 | val = (ucontrol->value.integer.value[0] + min) & mask; | ||
2693 | val = val << shift; | ||
2694 | |||
2695 | if (snd_soc_update_bits_locked(codec, reg, val_mask, val)) | ||
2696 | return err; | ||
2697 | |||
2698 | if (snd_soc_volsw_is_stereo(mc)) { | ||
2699 | val_mask = mask << rshift; | ||
2700 | val2 = (ucontrol->value.integer.value[1] + min) & mask; | ||
2701 | val2 = val2 << rshift; | ||
2702 | |||
2703 | if (snd_soc_update_bits_locked(codec, reg2, val_mask, val2)) | ||
2704 | return err; | ||
2705 | } | ||
2706 | return 0; | ||
2707 | } | ||
2708 | EXPORT_SYMBOL_GPL(snd_soc_put_volsw_sx); | ||
2709 | |||
2710 | /** | ||
2530 | * snd_soc_info_volsw_s8 - signed mixer info callback | 2711 | * snd_soc_info_volsw_s8 - signed mixer info callback |
2531 | * @kcontrol: mixer control | 2712 | * @kcontrol: mixer control |
2532 | * @uinfo: control element information | 2713 | * @uinfo: control element information |
@@ -2647,99 +2828,6 @@ int snd_soc_limit_volume(struct snd_soc_codec *codec, | |||
2647 | } | 2828 | } |
2648 | EXPORT_SYMBOL_GPL(snd_soc_limit_volume); | 2829 | EXPORT_SYMBOL_GPL(snd_soc_limit_volume); |
2649 | 2830 | ||
2650 | /** | ||
2651 | * snd_soc_info_volsw_2r_sx - double with tlv and variable data size | ||
2652 | * mixer info callback | ||
2653 | * @kcontrol: mixer control | ||
2654 | * @uinfo: control element information | ||
2655 | * | ||
2656 | * Returns 0 for success. | ||
2657 | */ | ||
2658 | int snd_soc_info_volsw_2r_sx(struct snd_kcontrol *kcontrol, | ||
2659 | struct snd_ctl_elem_info *uinfo) | ||
2660 | { | ||
2661 | struct soc_mixer_control *mc = | ||
2662 | (struct soc_mixer_control *)kcontrol->private_value; | ||
2663 | int max = mc->max; | ||
2664 | int min = mc->min; | ||
2665 | |||
2666 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; | ||
2667 | uinfo->count = 2; | ||
2668 | uinfo->value.integer.min = 0; | ||
2669 | uinfo->value.integer.max = max-min; | ||
2670 | |||
2671 | return 0; | ||
2672 | } | ||
2673 | EXPORT_SYMBOL_GPL(snd_soc_info_volsw_2r_sx); | ||
2674 | |||
2675 | /** | ||
2676 | * snd_soc_get_volsw_2r_sx - double with tlv and variable data size | ||
2677 | * mixer get callback | ||
2678 | * @kcontrol: mixer control | ||
2679 | * @uinfo: control element information | ||
2680 | * | ||
2681 | * Returns 0 for success. | ||
2682 | */ | ||
2683 | int snd_soc_get_volsw_2r_sx(struct snd_kcontrol *kcontrol, | ||
2684 | struct snd_ctl_elem_value *ucontrol) | ||
2685 | { | ||
2686 | struct soc_mixer_control *mc = | ||
2687 | (struct soc_mixer_control *)kcontrol->private_value; | ||
2688 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); | ||
2689 | unsigned int mask = (1<<mc->shift)-1; | ||
2690 | int min = mc->min; | ||
2691 | int val = snd_soc_read(codec, mc->reg) & mask; | ||
2692 | int valr = snd_soc_read(codec, mc->rreg) & mask; | ||
2693 | |||
2694 | ucontrol->value.integer.value[0] = ((val & 0xff)-min) & mask; | ||
2695 | ucontrol->value.integer.value[1] = ((valr & 0xff)-min) & mask; | ||
2696 | return 0; | ||
2697 | } | ||
2698 | EXPORT_SYMBOL_GPL(snd_soc_get_volsw_2r_sx); | ||
2699 | |||
2700 | /** | ||
2701 | * snd_soc_put_volsw_2r_sx - double with tlv and variable data size | ||
2702 | * mixer put callback | ||
2703 | * @kcontrol: mixer control | ||
2704 | * @uinfo: control element information | ||
2705 | * | ||
2706 | * Returns 0 for success. | ||
2707 | */ | ||
2708 | int snd_soc_put_volsw_2r_sx(struct snd_kcontrol *kcontrol, | ||
2709 | struct snd_ctl_elem_value *ucontrol) | ||
2710 | { | ||
2711 | struct soc_mixer_control *mc = | ||
2712 | (struct soc_mixer_control *)kcontrol->private_value; | ||
2713 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); | ||
2714 | unsigned int mask = (1<<mc->shift)-1; | ||
2715 | int min = mc->min; | ||
2716 | int ret; | ||
2717 | unsigned int val, valr, oval, ovalr; | ||
2718 | |||
2719 | val = ((ucontrol->value.integer.value[0]+min) & 0xff); | ||
2720 | val &= mask; | ||
2721 | valr = ((ucontrol->value.integer.value[1]+min) & 0xff); | ||
2722 | valr &= mask; | ||
2723 | |||
2724 | oval = snd_soc_read(codec, mc->reg) & mask; | ||
2725 | ovalr = snd_soc_read(codec, mc->rreg) & mask; | ||
2726 | |||
2727 | ret = 0; | ||
2728 | if (oval != val) { | ||
2729 | ret = snd_soc_write(codec, mc->reg, val); | ||
2730 | if (ret < 0) | ||
2731 | return ret; | ||
2732 | } | ||
2733 | if (ovalr != valr) { | ||
2734 | ret = snd_soc_write(codec, mc->rreg, valr); | ||
2735 | if (ret < 0) | ||
2736 | return ret; | ||
2737 | } | ||
2738 | |||
2739 | return 0; | ||
2740 | } | ||
2741 | EXPORT_SYMBOL_GPL(snd_soc_put_volsw_2r_sx); | ||
2742 | |||
2743 | int snd_soc_bytes_info(struct snd_kcontrol *kcontrol, | 2831 | int snd_soc_bytes_info(struct snd_kcontrol *kcontrol, |
2744 | struct snd_ctl_elem_info *uinfo) | 2832 | struct snd_ctl_elem_info *uinfo) |
2745 | { | 2833 | { |
@@ -2850,6 +2938,186 @@ int snd_soc_bytes_put(struct snd_kcontrol *kcontrol, | |||
2850 | EXPORT_SYMBOL_GPL(snd_soc_bytes_put); | 2938 | EXPORT_SYMBOL_GPL(snd_soc_bytes_put); |
2851 | 2939 | ||
2852 | /** | 2940 | /** |
2941 | * snd_soc_info_xr_sx - signed multi register info callback | ||
2942 | * @kcontrol: mreg control | ||
2943 | * @uinfo: control element information | ||
2944 | * | ||
2945 | * Callback to provide information of a control that can | ||
2946 | * span multiple codec registers which together | ||
2947 | * forms a single signed value in a MSB/LSB manner. | ||
2948 | * | ||
2949 | * Returns 0 for success. | ||
2950 | */ | ||
2951 | int snd_soc_info_xr_sx(struct snd_kcontrol *kcontrol, | ||
2952 | struct snd_ctl_elem_info *uinfo) | ||
2953 | { | ||
2954 | struct soc_mreg_control *mc = | ||
2955 | (struct soc_mreg_control *)kcontrol->private_value; | ||
2956 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; | ||
2957 | uinfo->count = 1; | ||
2958 | uinfo->value.integer.min = mc->min; | ||
2959 | uinfo->value.integer.max = mc->max; | ||
2960 | |||
2961 | return 0; | ||
2962 | } | ||
2963 | EXPORT_SYMBOL_GPL(snd_soc_info_xr_sx); | ||
2964 | |||
2965 | /** | ||
2966 | * snd_soc_get_xr_sx - signed multi register get callback | ||
2967 | * @kcontrol: mreg control | ||
2968 | * @ucontrol: control element information | ||
2969 | * | ||
2970 | * Callback to get the value of a control that can span | ||
2971 | * multiple codec registers which together forms a single | ||
2972 | * signed value in a MSB/LSB manner. The control supports | ||
2973 | * specifying total no of bits used to allow for bitfields | ||
2974 | * across the multiple codec registers. | ||
2975 | * | ||
2976 | * Returns 0 for success. | ||
2977 | */ | ||
2978 | int snd_soc_get_xr_sx(struct snd_kcontrol *kcontrol, | ||
2979 | struct snd_ctl_elem_value *ucontrol) | ||
2980 | { | ||
2981 | struct soc_mreg_control *mc = | ||
2982 | (struct soc_mreg_control *)kcontrol->private_value; | ||
2983 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); | ||
2984 | unsigned int regbase = mc->regbase; | ||
2985 | unsigned int regcount = mc->regcount; | ||
2986 | unsigned int regwshift = codec->driver->reg_word_size * BITS_PER_BYTE; | ||
2987 | unsigned int regwmask = (1<<regwshift)-1; | ||
2988 | unsigned int invert = mc->invert; | ||
2989 | unsigned long mask = (1UL<<mc->nbits)-1; | ||
2990 | long min = mc->min; | ||
2991 | long max = mc->max; | ||
2992 | long val = 0; | ||
2993 | unsigned long regval; | ||
2994 | unsigned int i; | ||
2995 | |||
2996 | for (i = 0; i < regcount; i++) { | ||
2997 | regval = snd_soc_read(codec, regbase+i) & regwmask; | ||
2998 | val |= regval << (regwshift*(regcount-i-1)); | ||
2999 | } | ||
3000 | val &= mask; | ||
3001 | if (min < 0 && val > max) | ||
3002 | val |= ~mask; | ||
3003 | if (invert) | ||
3004 | val = max - val; | ||
3005 | ucontrol->value.integer.value[0] = val; | ||
3006 | |||
3007 | return 0; | ||
3008 | } | ||
3009 | EXPORT_SYMBOL_GPL(snd_soc_get_xr_sx); | ||
3010 | |||
3011 | /** | ||
3012 | * snd_soc_put_xr_sx - signed multi register get callback | ||
3013 | * @kcontrol: mreg control | ||
3014 | * @ucontrol: control element information | ||
3015 | * | ||
3016 | * Callback to set the value of a control that can span | ||
3017 | * multiple codec registers which together forms a single | ||
3018 | * signed value in a MSB/LSB manner. The control supports | ||
3019 | * specifying total no of bits used to allow for bitfields | ||
3020 | * across the multiple codec registers. | ||
3021 | * | ||
3022 | * Returns 0 for success. | ||
3023 | */ | ||
3024 | int snd_soc_put_xr_sx(struct snd_kcontrol *kcontrol, | ||
3025 | struct snd_ctl_elem_value *ucontrol) | ||
3026 | { | ||
3027 | struct soc_mreg_control *mc = | ||
3028 | (struct soc_mreg_control *)kcontrol->private_value; | ||
3029 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); | ||
3030 | unsigned int regbase = mc->regbase; | ||
3031 | unsigned int regcount = mc->regcount; | ||
3032 | unsigned int regwshift = codec->driver->reg_word_size * BITS_PER_BYTE; | ||
3033 | unsigned int regwmask = (1<<regwshift)-1; | ||
3034 | unsigned int invert = mc->invert; | ||
3035 | unsigned long mask = (1UL<<mc->nbits)-1; | ||
3036 | long max = mc->max; | ||
3037 | long val = ucontrol->value.integer.value[0]; | ||
3038 | unsigned int i, regval, regmask; | ||
3039 | int err; | ||
3040 | |||
3041 | if (invert) | ||
3042 | val = max - val; | ||
3043 | val &= mask; | ||
3044 | for (i = 0; i < regcount; i++) { | ||
3045 | regval = (val >> (regwshift*(regcount-i-1))) & regwmask; | ||
3046 | regmask = (mask >> (regwshift*(regcount-i-1))) & regwmask; | ||
3047 | err = snd_soc_update_bits_locked(codec, regbase+i, | ||
3048 | regmask, regval); | ||
3049 | if (err < 0) | ||
3050 | return err; | ||
3051 | } | ||
3052 | |||
3053 | return 0; | ||
3054 | } | ||
3055 | EXPORT_SYMBOL_GPL(snd_soc_put_xr_sx); | ||
3056 | |||
3057 | /** | ||
3058 | * snd_soc_get_strobe - strobe get callback | ||
3059 | * @kcontrol: mixer control | ||
3060 | * @ucontrol: control element information | ||
3061 | * | ||
3062 | * Callback get the value of a strobe mixer control. | ||
3063 | * | ||
3064 | * Returns 0 for success. | ||
3065 | */ | ||
3066 | int snd_soc_get_strobe(struct snd_kcontrol *kcontrol, | ||
3067 | struct snd_ctl_elem_value *ucontrol) | ||
3068 | { | ||
3069 | struct soc_mixer_control *mc = | ||
3070 | (struct soc_mixer_control *)kcontrol->private_value; | ||
3071 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); | ||
3072 | unsigned int reg = mc->reg; | ||
3073 | unsigned int shift = mc->shift; | ||
3074 | unsigned int mask = 1 << shift; | ||
3075 | unsigned int invert = mc->invert != 0; | ||
3076 | unsigned int val = snd_soc_read(codec, reg) & mask; | ||
3077 | |||
3078 | if (shift != 0 && val != 0) | ||
3079 | val = val >> shift; | ||
3080 | ucontrol->value.enumerated.item[0] = val ^ invert; | ||
3081 | |||
3082 | return 0; | ||
3083 | } | ||
3084 | EXPORT_SYMBOL_GPL(snd_soc_get_strobe); | ||
3085 | |||
3086 | /** | ||
3087 | * snd_soc_put_strobe - strobe put callback | ||
3088 | * @kcontrol: mixer control | ||
3089 | * @ucontrol: control element information | ||
3090 | * | ||
3091 | * Callback strobe a register bit to high then low (or the inverse) | ||
3092 | * in one pass of a single mixer enum control. | ||
3093 | * | ||
3094 | * Returns 1 for success. | ||
3095 | */ | ||
3096 | int snd_soc_put_strobe(struct snd_kcontrol *kcontrol, | ||
3097 | struct snd_ctl_elem_value *ucontrol) | ||
3098 | { | ||
3099 | struct soc_mixer_control *mc = | ||
3100 | (struct soc_mixer_control *)kcontrol->private_value; | ||
3101 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); | ||
3102 | unsigned int reg = mc->reg; | ||
3103 | unsigned int shift = mc->shift; | ||
3104 | unsigned int mask = 1 << shift; | ||
3105 | unsigned int invert = mc->invert != 0; | ||
3106 | unsigned int strobe = ucontrol->value.enumerated.item[0] != 0; | ||
3107 | unsigned int val1 = (strobe ^ invert) ? mask : 0; | ||
3108 | unsigned int val2 = (strobe ^ invert) ? 0 : mask; | ||
3109 | int err; | ||
3110 | |||
3111 | err = snd_soc_update_bits_locked(codec, reg, mask, val1); | ||
3112 | if (err < 0) | ||
3113 | return err; | ||
3114 | |||
3115 | err = snd_soc_update_bits_locked(codec, reg, mask, val2); | ||
3116 | return err; | ||
3117 | } | ||
3118 | EXPORT_SYMBOL_GPL(snd_soc_put_strobe); | ||
3119 | |||
3120 | /** | ||
2853 | * snd_soc_dai_set_sysclk - configure DAI system or master clock. | 3121 | * snd_soc_dai_set_sysclk - configure DAI system or master clock. |
2854 | * @dai: DAI | 3122 | * @dai: DAI |
2855 | * @clk_id: DAI specific clock ID | 3123 | * @clk_id: DAI specific clock ID |
@@ -3048,7 +3316,7 @@ int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute) | |||
3048 | if (dai->driver && dai->driver->ops->digital_mute) | 3316 | if (dai->driver && dai->driver->ops->digital_mute) |
3049 | return dai->driver->ops->digital_mute(dai, mute); | 3317 | return dai->driver->ops->digital_mute(dai, mute); |
3050 | else | 3318 | else |
3051 | return -EINVAL; | 3319 | return -ENOTSUPP; |
3052 | } | 3320 | } |
3053 | EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute); | 3321 | EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute); |
3054 | 3322 | ||
@@ -3060,7 +3328,7 @@ EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute); | |||
3060 | */ | 3328 | */ |
3061 | int snd_soc_register_card(struct snd_soc_card *card) | 3329 | int snd_soc_register_card(struct snd_soc_card *card) |
3062 | { | 3330 | { |
3063 | int i; | 3331 | int i, ret; |
3064 | 3332 | ||
3065 | if (!card->name || !card->dev) | 3333 | if (!card->name || !card->dev) |
3066 | return -EINVAL; | 3334 | return -EINVAL; |
@@ -3123,15 +3391,13 @@ int snd_soc_register_card(struct snd_soc_card *card) | |||
3123 | INIT_LIST_HEAD(&card->dapm_dirty); | 3391 | INIT_LIST_HEAD(&card->dapm_dirty); |
3124 | card->instantiated = 0; | 3392 | card->instantiated = 0; |
3125 | mutex_init(&card->mutex); | 3393 | mutex_init(&card->mutex); |
3394 | mutex_init(&card->dapm_mutex); | ||
3126 | 3395 | ||
3127 | mutex_lock(&client_mutex); | 3396 | ret = snd_soc_instantiate_card(card); |
3128 | list_add(&card->list, &card_list); | 3397 | if (ret != 0) |
3129 | snd_soc_instantiate_cards(); | 3398 | soc_cleanup_card_debugfs(card); |
3130 | mutex_unlock(&client_mutex); | ||
3131 | |||
3132 | dev_dbg(card->dev, "Registered card '%s'\n", card->name); | ||
3133 | 3399 | ||
3134 | return 0; | 3400 | return ret; |
3135 | } | 3401 | } |
3136 | EXPORT_SYMBOL_GPL(snd_soc_register_card); | 3402 | EXPORT_SYMBOL_GPL(snd_soc_register_card); |
3137 | 3403 | ||
@@ -3145,9 +3411,6 @@ int snd_soc_unregister_card(struct snd_soc_card *card) | |||
3145 | { | 3411 | { |
3146 | if (card->instantiated) | 3412 | if (card->instantiated) |
3147 | soc_cleanup_card_resources(card); | 3413 | soc_cleanup_card_resources(card); |
3148 | mutex_lock(&client_mutex); | ||
3149 | list_del(&card->list); | ||
3150 | mutex_unlock(&client_mutex); | ||
3151 | dev_dbg(card->dev, "Unregistered card '%s'\n", card->name); | 3414 | dev_dbg(card->dev, "Unregistered card '%s'\n", card->name); |
3152 | 3415 | ||
3153 | return 0; | 3416 | return 0; |
@@ -3221,6 +3484,7 @@ static inline char *fmt_multiple_name(struct device *dev, | |||
3221 | int snd_soc_register_dai(struct device *dev, | 3484 | int snd_soc_register_dai(struct device *dev, |
3222 | struct snd_soc_dai_driver *dai_drv) | 3485 | struct snd_soc_dai_driver *dai_drv) |
3223 | { | 3486 | { |
3487 | struct snd_soc_codec *codec; | ||
3224 | struct snd_soc_dai *dai; | 3488 | struct snd_soc_dai *dai; |
3225 | 3489 | ||
3226 | dev_dbg(dev, "dai register %s\n", dev_name(dev)); | 3490 | dev_dbg(dev, "dai register %s\n", dev_name(dev)); |
@@ -3238,12 +3502,23 @@ int snd_soc_register_dai(struct device *dev, | |||
3238 | 3502 | ||
3239 | dai->dev = dev; | 3503 | dai->dev = dev; |
3240 | dai->driver = dai_drv; | 3504 | dai->driver = dai_drv; |
3505 | dai->dapm.dev = dev; | ||
3241 | if (!dai->driver->ops) | 3506 | if (!dai->driver->ops) |
3242 | dai->driver->ops = &null_dai_ops; | 3507 | dai->driver->ops = &null_dai_ops; |
3243 | 3508 | ||
3244 | mutex_lock(&client_mutex); | 3509 | mutex_lock(&client_mutex); |
3510 | |||
3511 | list_for_each_entry(codec, &codec_list, list) { | ||
3512 | if (codec->dev == dev) { | ||
3513 | dev_dbg(dev, "Mapped DAI %s to CODEC %s\n", | ||
3514 | dai->name, codec->name); | ||
3515 | dai->codec = codec; | ||
3516 | break; | ||
3517 | } | ||
3518 | } | ||
3519 | |||
3245 | list_add(&dai->list, &dai_list); | 3520 | list_add(&dai->list, &dai_list); |
3246 | snd_soc_instantiate_cards(); | 3521 | |
3247 | mutex_unlock(&client_mutex); | 3522 | mutex_unlock(&client_mutex); |
3248 | 3523 | ||
3249 | pr_debug("Registered DAI '%s'\n", dai->name); | 3524 | pr_debug("Registered DAI '%s'\n", dai->name); |
@@ -3287,6 +3562,7 @@ EXPORT_SYMBOL_GPL(snd_soc_unregister_dai); | |||
3287 | int snd_soc_register_dais(struct device *dev, | 3562 | int snd_soc_register_dais(struct device *dev, |
3288 | struct snd_soc_dai_driver *dai_drv, size_t count) | 3563 | struct snd_soc_dai_driver *dai_drv, size_t count) |
3289 | { | 3564 | { |
3565 | struct snd_soc_codec *codec; | ||
3290 | struct snd_soc_dai *dai; | 3566 | struct snd_soc_dai *dai; |
3291 | int i, ret = 0; | 3567 | int i, ret = 0; |
3292 | 3568 | ||
@@ -3314,19 +3590,28 @@ int snd_soc_register_dais(struct device *dev, | |||
3314 | dai->id = dai->driver->id; | 3590 | dai->id = dai->driver->id; |
3315 | else | 3591 | else |
3316 | dai->id = i; | 3592 | dai->id = i; |
3593 | dai->dapm.dev = dev; | ||
3317 | if (!dai->driver->ops) | 3594 | if (!dai->driver->ops) |
3318 | dai->driver->ops = &null_dai_ops; | 3595 | dai->driver->ops = &null_dai_ops; |
3319 | 3596 | ||
3320 | mutex_lock(&client_mutex); | 3597 | mutex_lock(&client_mutex); |
3598 | |||
3599 | list_for_each_entry(codec, &codec_list, list) { | ||
3600 | if (codec->dev == dev) { | ||
3601 | dev_dbg(dev, "Mapped DAI %s to CODEC %s\n", | ||
3602 | dai->name, codec->name); | ||
3603 | dai->codec = codec; | ||
3604 | break; | ||
3605 | } | ||
3606 | } | ||
3607 | |||
3321 | list_add(&dai->list, &dai_list); | 3608 | list_add(&dai->list, &dai_list); |
3609 | |||
3322 | mutex_unlock(&client_mutex); | 3610 | mutex_unlock(&client_mutex); |
3323 | 3611 | ||
3324 | pr_debug("Registered DAI '%s'\n", dai->name); | 3612 | pr_debug("Registered DAI '%s'\n", dai->name); |
3325 | } | 3613 | } |
3326 | 3614 | ||
3327 | mutex_lock(&client_mutex); | ||
3328 | snd_soc_instantiate_cards(); | ||
3329 | mutex_unlock(&client_mutex); | ||
3330 | return 0; | 3615 | return 0; |
3331 | 3616 | ||
3332 | err: | 3617 | err: |
@@ -3384,7 +3669,6 @@ int snd_soc_register_platform(struct device *dev, | |||
3384 | 3669 | ||
3385 | mutex_lock(&client_mutex); | 3670 | mutex_lock(&client_mutex); |
3386 | list_add(&platform->list, &platform_list); | 3671 | list_add(&platform->list, &platform_list); |
3387 | snd_soc_instantiate_cards(); | ||
3388 | mutex_unlock(&client_mutex); | 3672 | mutex_unlock(&client_mutex); |
3389 | 3673 | ||
3390 | pr_debug("Registered platform '%s'\n", platform->name); | 3674 | pr_debug("Registered platform '%s'\n", platform->name); |
@@ -3534,18 +3818,18 @@ int snd_soc_register_codec(struct device *dev, | |||
3534 | fixup_codec_formats(&dai_drv[i].capture); | 3818 | fixup_codec_formats(&dai_drv[i].capture); |
3535 | } | 3819 | } |
3536 | 3820 | ||
3821 | mutex_lock(&client_mutex); | ||
3822 | list_add(&codec->list, &codec_list); | ||
3823 | mutex_unlock(&client_mutex); | ||
3824 | |||
3537 | /* register any DAIs */ | 3825 | /* register any DAIs */ |
3538 | if (num_dai) { | 3826 | if (num_dai) { |
3539 | ret = snd_soc_register_dais(dev, dai_drv, num_dai); | 3827 | ret = snd_soc_register_dais(dev, dai_drv, num_dai); |
3540 | if (ret < 0) | 3828 | if (ret < 0) |
3541 | goto fail; | 3829 | dev_err(codec->dev, "Failed to regster DAIs: %d\n", |
3830 | ret); | ||
3542 | } | 3831 | } |
3543 | 3832 | ||
3544 | mutex_lock(&client_mutex); | ||
3545 | list_add(&codec->list, &codec_list); | ||
3546 | snd_soc_instantiate_cards(); | ||
3547 | mutex_unlock(&client_mutex); | ||
3548 | |||
3549 | pr_debug("Registered codec '%s'\n", codec->name); | 3833 | pr_debug("Registered codec '%s'\n", codec->name); |
3550 | return 0; | 3834 | return 0; |
3551 | 3835 | ||
diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c index 1bb6d4a63cd8..90ee77d2409d 100644 --- a/sound/soc/soc-dapm.c +++ b/sound/soc/soc-dapm.c | |||
@@ -52,6 +52,7 @@ static int dapm_up_seq[] = { | |||
52 | [snd_soc_dapm_supply] = 1, | 52 | [snd_soc_dapm_supply] = 1, |
53 | [snd_soc_dapm_regulator_supply] = 1, | 53 | [snd_soc_dapm_regulator_supply] = 1, |
54 | [snd_soc_dapm_micbias] = 2, | 54 | [snd_soc_dapm_micbias] = 2, |
55 | [snd_soc_dapm_dai_link] = 2, | ||
55 | [snd_soc_dapm_dai] = 3, | 56 | [snd_soc_dapm_dai] = 3, |
56 | [snd_soc_dapm_aif_in] = 3, | 57 | [snd_soc_dapm_aif_in] = 3, |
57 | [snd_soc_dapm_aif_out] = 3, | 58 | [snd_soc_dapm_aif_out] = 3, |
@@ -90,9 +91,10 @@ static int dapm_down_seq[] = { | |||
90 | [snd_soc_dapm_aif_in] = 10, | 91 | [snd_soc_dapm_aif_in] = 10, |
91 | [snd_soc_dapm_aif_out] = 10, | 92 | [snd_soc_dapm_aif_out] = 10, |
92 | [snd_soc_dapm_dai] = 10, | 93 | [snd_soc_dapm_dai] = 10, |
93 | [snd_soc_dapm_regulator_supply] = 11, | 94 | [snd_soc_dapm_dai_link] = 11, |
94 | [snd_soc_dapm_supply] = 11, | 95 | [snd_soc_dapm_regulator_supply] = 12, |
95 | [snd_soc_dapm_post] = 12, | 96 | [snd_soc_dapm_supply] = 12, |
97 | [snd_soc_dapm_post] = 13, | ||
96 | }; | 98 | }; |
97 | 99 | ||
98 | static void pop_wait(u32 pop_time) | 100 | static void pop_wait(u32 pop_time) |
@@ -208,7 +210,23 @@ static int soc_widget_write(struct snd_soc_dapm_widget *w, int reg, int val) | |||
208 | return -1; | 210 | return -1; |
209 | } | 211 | } |
210 | 212 | ||
211 | static int soc_widget_update_bits(struct snd_soc_dapm_widget *w, | 213 | static inline void soc_widget_lock(struct snd_soc_dapm_widget *w) |
214 | { | ||
215 | if (w->codec && !w->codec->using_regmap) | ||
216 | mutex_lock(&w->codec->mutex); | ||
217 | else if (w->platform) | ||
218 | mutex_lock(&w->platform->mutex); | ||
219 | } | ||
220 | |||
221 | static inline void soc_widget_unlock(struct snd_soc_dapm_widget *w) | ||
222 | { | ||
223 | if (w->codec && !w->codec->using_regmap) | ||
224 | mutex_unlock(&w->codec->mutex); | ||
225 | else if (w->platform) | ||
226 | mutex_unlock(&w->platform->mutex); | ||
227 | } | ||
228 | |||
229 | static int soc_widget_update_bits_locked(struct snd_soc_dapm_widget *w, | ||
212 | unsigned short reg, unsigned int mask, unsigned int value) | 230 | unsigned short reg, unsigned int mask, unsigned int value) |
213 | { | 231 | { |
214 | bool change; | 232 | bool change; |
@@ -221,18 +239,24 @@ static int soc_widget_update_bits(struct snd_soc_dapm_widget *w, | |||
221 | if (ret != 0) | 239 | if (ret != 0) |
222 | return ret; | 240 | return ret; |
223 | } else { | 241 | } else { |
242 | soc_widget_lock(w); | ||
224 | ret = soc_widget_read(w, reg); | 243 | ret = soc_widget_read(w, reg); |
225 | if (ret < 0) | 244 | if (ret < 0) { |
245 | soc_widget_unlock(w); | ||
226 | return ret; | 246 | return ret; |
247 | } | ||
227 | 248 | ||
228 | old = ret; | 249 | old = ret; |
229 | new = (old & ~mask) | (value & mask); | 250 | new = (old & ~mask) | (value & mask); |
230 | change = old != new; | 251 | change = old != new; |
231 | if (change) { | 252 | if (change) { |
232 | ret = soc_widget_write(w, reg, new); | 253 | ret = soc_widget_write(w, reg, new); |
233 | if (ret < 0) | 254 | if (ret < 0) { |
255 | soc_widget_unlock(w); | ||
234 | return ret; | 256 | return ret; |
257 | } | ||
235 | } | 258 | } |
259 | soc_widget_unlock(w); | ||
236 | } | 260 | } |
237 | 261 | ||
238 | return change; | 262 | return change; |
@@ -374,6 +398,7 @@ static void dapm_set_path_status(struct snd_soc_dapm_widget *w, | |||
374 | case snd_soc_dapm_mic: | 398 | case snd_soc_dapm_mic: |
375 | case snd_soc_dapm_spk: | 399 | case snd_soc_dapm_spk: |
376 | case snd_soc_dapm_line: | 400 | case snd_soc_dapm_line: |
401 | case snd_soc_dapm_dai_link: | ||
377 | p->connect = 1; | 402 | p->connect = 1; |
378 | break; | 403 | break; |
379 | /* does affect routing - dynamically connected */ | 404 | /* does affect routing - dynamically connected */ |
@@ -682,11 +707,51 @@ static int snd_soc_dapm_suspend_check(struct snd_soc_dapm_widget *widget) | |||
682 | } | 707 | } |
683 | } | 708 | } |
684 | 709 | ||
710 | /* add widget to list if it's not already in the list */ | ||
711 | static int dapm_list_add_widget(struct snd_soc_dapm_widget_list **list, | ||
712 | struct snd_soc_dapm_widget *w) | ||
713 | { | ||
714 | struct snd_soc_dapm_widget_list *wlist; | ||
715 | int wlistsize, wlistentries, i; | ||
716 | |||
717 | if (*list == NULL) | ||
718 | return -EINVAL; | ||
719 | |||
720 | wlist = *list; | ||
721 | |||
722 | /* is this widget already in the list */ | ||
723 | for (i = 0; i < wlist->num_widgets; i++) { | ||
724 | if (wlist->widgets[i] == w) | ||
725 | return 0; | ||
726 | } | ||
727 | |||
728 | /* allocate some new space */ | ||
729 | wlistentries = wlist->num_widgets + 1; | ||
730 | wlistsize = sizeof(struct snd_soc_dapm_widget_list) + | ||
731 | wlistentries * sizeof(struct snd_soc_dapm_widget *); | ||
732 | *list = krealloc(wlist, wlistsize, GFP_KERNEL); | ||
733 | if (*list == NULL) { | ||
734 | dev_err(w->dapm->dev, "can't allocate widget list for %s\n", | ||
735 | w->name); | ||
736 | return -ENOMEM; | ||
737 | } | ||
738 | wlist = *list; | ||
739 | |||
740 | /* insert the widget */ | ||
741 | dev_dbg(w->dapm->dev, "added %s in widget list pos %d\n", | ||
742 | w->name, wlist->num_widgets); | ||
743 | |||
744 | wlist->widgets[wlist->num_widgets] = w; | ||
745 | wlist->num_widgets++; | ||
746 | return 1; | ||
747 | } | ||
748 | |||
685 | /* | 749 | /* |
686 | * Recursively check for a completed path to an active or physically connected | 750 | * Recursively check for a completed path to an active or physically connected |
687 | * output widget. Returns number of complete paths. | 751 | * output widget. Returns number of complete paths. |
688 | */ | 752 | */ |
689 | static int is_connected_output_ep(struct snd_soc_dapm_widget *widget) | 753 | static int is_connected_output_ep(struct snd_soc_dapm_widget *widget, |
754 | struct snd_soc_dapm_widget_list **list) | ||
690 | { | 755 | { |
691 | struct snd_soc_dapm_path *path; | 756 | struct snd_soc_dapm_path *path; |
692 | int con = 0; | 757 | int con = 0; |
@@ -742,9 +807,23 @@ static int is_connected_output_ep(struct snd_soc_dapm_widget *widget) | |||
742 | if (path->walked) | 807 | if (path->walked) |
743 | continue; | 808 | continue; |
744 | 809 | ||
810 | trace_snd_soc_dapm_output_path(widget, path); | ||
811 | |||
745 | if (path->sink && path->connect) { | 812 | if (path->sink && path->connect) { |
746 | path->walked = 1; | 813 | path->walked = 1; |
747 | con += is_connected_output_ep(path->sink); | 814 | |
815 | /* do we need to add this widget to the list ? */ | ||
816 | if (list) { | ||
817 | int err; | ||
818 | err = dapm_list_add_widget(list, path->sink); | ||
819 | if (err < 0) { | ||
820 | dev_err(widget->dapm->dev, "could not add widget %s\n", | ||
821 | widget->name); | ||
822 | return con; | ||
823 | } | ||
824 | } | ||
825 | |||
826 | con += is_connected_output_ep(path->sink, list); | ||
748 | } | 827 | } |
749 | } | 828 | } |
750 | 829 | ||
@@ -757,7 +836,8 @@ static int is_connected_output_ep(struct snd_soc_dapm_widget *widget) | |||
757 | * Recursively check for a completed path to an active or physically connected | 836 | * Recursively check for a completed path to an active or physically connected |
758 | * input widget. Returns number of complete paths. | 837 | * input widget. Returns number of complete paths. |
759 | */ | 838 | */ |
760 | static int is_connected_input_ep(struct snd_soc_dapm_widget *widget) | 839 | static int is_connected_input_ep(struct snd_soc_dapm_widget *widget, |
840 | struct snd_soc_dapm_widget_list **list) | ||
761 | { | 841 | { |
762 | struct snd_soc_dapm_path *path; | 842 | struct snd_soc_dapm_path *path; |
763 | int con = 0; | 843 | int con = 0; |
@@ -825,9 +905,23 @@ static int is_connected_input_ep(struct snd_soc_dapm_widget *widget) | |||
825 | if (path->walked) | 905 | if (path->walked) |
826 | continue; | 906 | continue; |
827 | 907 | ||
908 | trace_snd_soc_dapm_input_path(widget, path); | ||
909 | |||
828 | if (path->source && path->connect) { | 910 | if (path->source && path->connect) { |
829 | path->walked = 1; | 911 | path->walked = 1; |
830 | con += is_connected_input_ep(path->source); | 912 | |
913 | /* do we need to add this widget to the list ? */ | ||
914 | if (list) { | ||
915 | int err; | ||
916 | err = dapm_list_add_widget(list, path->sink); | ||
917 | if (err < 0) { | ||
918 | dev_err(widget->dapm->dev, "could not add widget %s\n", | ||
919 | widget->name); | ||
920 | return con; | ||
921 | } | ||
922 | } | ||
923 | |||
924 | con += is_connected_input_ep(path->source, list); | ||
831 | } | 925 | } |
832 | } | 926 | } |
833 | 927 | ||
@@ -836,6 +930,39 @@ static int is_connected_input_ep(struct snd_soc_dapm_widget *widget) | |||
836 | return con; | 930 | return con; |
837 | } | 931 | } |
838 | 932 | ||
933 | /** | ||
934 | * snd_soc_dapm_get_connected_widgets - query audio path and it's widgets. | ||
935 | * @dai: the soc DAI. | ||
936 | * @stream: stream direction. | ||
937 | * @list: list of active widgets for this stream. | ||
938 | * | ||
939 | * Queries DAPM graph as to whether an valid audio stream path exists for | ||
940 | * the initial stream specified by name. This takes into account | ||
941 | * current mixer and mux kcontrol settings. Creates list of valid widgets. | ||
942 | * | ||
943 | * Returns the number of valid paths or negative error. | ||
944 | */ | ||
945 | int snd_soc_dapm_dai_get_connected_widgets(struct snd_soc_dai *dai, int stream, | ||
946 | struct snd_soc_dapm_widget_list **list) | ||
947 | { | ||
948 | struct snd_soc_card *card = dai->card; | ||
949 | int paths; | ||
950 | |||
951 | mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); | ||
952 | dapm_reset(card); | ||
953 | |||
954 | if (stream == SNDRV_PCM_STREAM_PLAYBACK) | ||
955 | paths = is_connected_output_ep(dai->playback_widget, list); | ||
956 | else | ||
957 | paths = is_connected_input_ep(dai->playback_widget, list); | ||
958 | |||
959 | trace_snd_soc_dapm_connected(paths, stream); | ||
960 | dapm_clear_walk(&card->dapm); | ||
961 | mutex_unlock(&card->dapm_mutex); | ||
962 | |||
963 | return paths; | ||
964 | } | ||
965 | |||
839 | /* | 966 | /* |
840 | * Handler for generic register modifier widget. | 967 | * Handler for generic register modifier widget. |
841 | */ | 968 | */ |
@@ -849,7 +976,7 @@ int dapm_reg_event(struct snd_soc_dapm_widget *w, | |||
849 | else | 976 | else |
850 | val = w->off_val; | 977 | val = w->off_val; |
851 | 978 | ||
852 | soc_widget_update_bits(w, -(w->reg + 1), | 979 | soc_widget_update_bits_locked(w, -(w->reg + 1), |
853 | w->mask << w->shift, val << w->shift); | 980 | w->mask << w->shift, val << w->shift); |
854 | 981 | ||
855 | return 0; | 982 | return 0; |
@@ -863,9 +990,9 @@ int dapm_regulator_event(struct snd_soc_dapm_widget *w, | |||
863 | struct snd_kcontrol *kcontrol, int event) | 990 | struct snd_kcontrol *kcontrol, int event) |
864 | { | 991 | { |
865 | if (SND_SOC_DAPM_EVENT_ON(event)) | 992 | if (SND_SOC_DAPM_EVENT_ON(event)) |
866 | return regulator_enable(w->priv); | 993 | return regulator_enable(w->regulator); |
867 | else | 994 | else |
868 | return regulator_disable_deferred(w->priv, w->shift); | 995 | return regulator_disable_deferred(w->regulator, w->shift); |
869 | } | 996 | } |
870 | EXPORT_SYMBOL_GPL(dapm_regulator_event); | 997 | EXPORT_SYMBOL_GPL(dapm_regulator_event); |
871 | 998 | ||
@@ -892,9 +1019,9 @@ static int dapm_generic_check_power(struct snd_soc_dapm_widget *w) | |||
892 | 1019 | ||
893 | DAPM_UPDATE_STAT(w, power_checks); | 1020 | DAPM_UPDATE_STAT(w, power_checks); |
894 | 1021 | ||
895 | in = is_connected_input_ep(w); | 1022 | in = is_connected_input_ep(w, NULL); |
896 | dapm_clear_walk(w->dapm); | 1023 | dapm_clear_walk(w->dapm); |
897 | out = is_connected_output_ep(w); | 1024 | out = is_connected_output_ep(w, NULL); |
898 | dapm_clear_walk(w->dapm); | 1025 | dapm_clear_walk(w->dapm); |
899 | return out != 0 && in != 0; | 1026 | return out != 0 && in != 0; |
900 | } | 1027 | } |
@@ -903,7 +1030,10 @@ static int dapm_dai_check_power(struct snd_soc_dapm_widget *w) | |||
903 | { | 1030 | { |
904 | DAPM_UPDATE_STAT(w, power_checks); | 1031 | DAPM_UPDATE_STAT(w, power_checks); |
905 | 1032 | ||
906 | return w->active; | 1033 | if (w->active) |
1034 | return w->active; | ||
1035 | |||
1036 | return dapm_generic_check_power(w); | ||
907 | } | 1037 | } |
908 | 1038 | ||
909 | /* Check to see if an ADC has power */ | 1039 | /* Check to see if an ADC has power */ |
@@ -914,7 +1044,7 @@ static int dapm_adc_check_power(struct snd_soc_dapm_widget *w) | |||
914 | DAPM_UPDATE_STAT(w, power_checks); | 1044 | DAPM_UPDATE_STAT(w, power_checks); |
915 | 1045 | ||
916 | if (w->active) { | 1046 | if (w->active) { |
917 | in = is_connected_input_ep(w); | 1047 | in = is_connected_input_ep(w, NULL); |
918 | dapm_clear_walk(w->dapm); | 1048 | dapm_clear_walk(w->dapm); |
919 | return in != 0; | 1049 | return in != 0; |
920 | } else { | 1050 | } else { |
@@ -930,7 +1060,7 @@ static int dapm_dac_check_power(struct snd_soc_dapm_widget *w) | |||
930 | DAPM_UPDATE_STAT(w, power_checks); | 1060 | DAPM_UPDATE_STAT(w, power_checks); |
931 | 1061 | ||
932 | if (w->active) { | 1062 | if (w->active) { |
933 | out = is_connected_output_ep(w); | 1063 | out = is_connected_output_ep(w, NULL); |
934 | dapm_clear_walk(w->dapm); | 1064 | dapm_clear_walk(w->dapm); |
935 | return out != 0; | 1065 | return out != 0; |
936 | } else { | 1066 | } else { |
@@ -1107,7 +1237,7 @@ static void dapm_seq_run_coalesced(struct snd_soc_dapm_context *dapm, | |||
1107 | "pop test : Applying 0x%x/0x%x to %x in %dms\n", | 1237 | "pop test : Applying 0x%x/0x%x to %x in %dms\n", |
1108 | value, mask, reg, card->pop_time); | 1238 | value, mask, reg, card->pop_time); |
1109 | pop_wait(card->pop_time); | 1239 | pop_wait(card->pop_time); |
1110 | soc_widget_update_bits(w, reg, mask, value); | 1240 | soc_widget_update_bits_locked(w, reg, mask, value); |
1111 | } | 1241 | } |
1112 | 1242 | ||
1113 | list_for_each_entry(w, pending, power_list) { | 1243 | list_for_each_entry(w, pending, power_list) { |
@@ -1237,7 +1367,7 @@ static void dapm_widget_update(struct snd_soc_dapm_context *dapm) | |||
1237 | w->name, ret); | 1367 | w->name, ret); |
1238 | } | 1368 | } |
1239 | 1369 | ||
1240 | ret = snd_soc_update_bits(w->codec, update->reg, update->mask, | 1370 | ret = soc_widget_update_bits_locked(w, update->reg, update->mask, |
1241 | update->val); | 1371 | update->val); |
1242 | if (ret < 0) | 1372 | if (ret < 0) |
1243 | pr_err("%s DAPM update failed: %d\n", w->name, ret); | 1373 | pr_err("%s DAPM update failed: %d\n", w->name, ret); |
@@ -1421,12 +1551,10 @@ static int dapm_power_widgets(struct snd_soc_dapm_context *dapm, int event) | |||
1421 | trace_snd_soc_dapm_start(card); | 1551 | trace_snd_soc_dapm_start(card); |
1422 | 1552 | ||
1423 | list_for_each_entry(d, &card->dapm_list, list) { | 1553 | list_for_each_entry(d, &card->dapm_list, list) { |
1424 | if (d->n_widgets || d->codec == NULL) { | 1554 | if (d->idle_bias_off) |
1425 | if (d->idle_bias_off) | 1555 | d->target_bias_level = SND_SOC_BIAS_OFF; |
1426 | d->target_bias_level = SND_SOC_BIAS_OFF; | 1556 | else |
1427 | else | 1557 | d->target_bias_level = SND_SOC_BIAS_STANDBY; |
1428 | d->target_bias_level = SND_SOC_BIAS_STANDBY; | ||
1429 | } | ||
1430 | } | 1558 | } |
1431 | 1559 | ||
1432 | dapm_reset(card); | 1560 | dapm_reset(card); |
@@ -1471,32 +1599,6 @@ static int dapm_power_widgets(struct snd_soc_dapm_context *dapm, int event) | |||
1471 | 1599 | ||
1472 | } | 1600 | } |
1473 | 1601 | ||
1474 | /* If there are no DAPM widgets then try to figure out power from the | ||
1475 | * event type. | ||
1476 | */ | ||
1477 | if (!dapm->n_widgets) { | ||
1478 | switch (event) { | ||
1479 | case SND_SOC_DAPM_STREAM_START: | ||
1480 | case SND_SOC_DAPM_STREAM_RESUME: | ||
1481 | dapm->target_bias_level = SND_SOC_BIAS_ON; | ||
1482 | break; | ||
1483 | case SND_SOC_DAPM_STREAM_STOP: | ||
1484 | if (dapm->codec && dapm->codec->active) | ||
1485 | dapm->target_bias_level = SND_SOC_BIAS_ON; | ||
1486 | else | ||
1487 | dapm->target_bias_level = SND_SOC_BIAS_STANDBY; | ||
1488 | break; | ||
1489 | case SND_SOC_DAPM_STREAM_SUSPEND: | ||
1490 | dapm->target_bias_level = SND_SOC_BIAS_STANDBY; | ||
1491 | break; | ||
1492 | case SND_SOC_DAPM_STREAM_NOP: | ||
1493 | dapm->target_bias_level = dapm->bias_level; | ||
1494 | break; | ||
1495 | default: | ||
1496 | break; | ||
1497 | } | ||
1498 | } | ||
1499 | |||
1500 | /* Force all contexts in the card to the same bias state if | 1602 | /* Force all contexts in the card to the same bias state if |
1501 | * they're not ground referenced. | 1603 | * they're not ground referenced. |
1502 | */ | 1604 | */ |
@@ -1560,9 +1662,9 @@ static ssize_t dapm_widget_power_read_file(struct file *file, | |||
1560 | if (!buf) | 1662 | if (!buf) |
1561 | return -ENOMEM; | 1663 | return -ENOMEM; |
1562 | 1664 | ||
1563 | in = is_connected_input_ep(w); | 1665 | in = is_connected_input_ep(w, NULL); |
1564 | dapm_clear_walk(w->dapm); | 1666 | dapm_clear_walk(w->dapm); |
1565 | out = is_connected_output_ep(w); | 1667 | out = is_connected_output_ep(w, NULL); |
1566 | dapm_clear_walk(w->dapm); | 1668 | dapm_clear_walk(w->dapm); |
1567 | 1669 | ||
1568 | ret = snprintf(buf, PAGE_SIZE, "%s: %s%s in %d out %d", | 1670 | ret = snprintf(buf, PAGE_SIZE, "%s: %s%s in %d out %d", |
@@ -1709,7 +1811,7 @@ static inline void dapm_debugfs_cleanup(struct snd_soc_dapm_context *dapm) | |||
1709 | #endif | 1811 | #endif |
1710 | 1812 | ||
1711 | /* test and update the power status of a mux widget */ | 1813 | /* test and update the power status of a mux widget */ |
1712 | int snd_soc_dapm_mux_update_power(struct snd_soc_dapm_widget *widget, | 1814 | static int soc_dapm_mux_update_power(struct snd_soc_dapm_widget *widget, |
1713 | struct snd_kcontrol *kcontrol, int mux, struct soc_enum *e) | 1815 | struct snd_kcontrol *kcontrol, int mux, struct soc_enum *e) |
1714 | { | 1816 | { |
1715 | struct snd_soc_dapm_path *path; | 1817 | struct snd_soc_dapm_path *path; |
@@ -1746,12 +1848,26 @@ int snd_soc_dapm_mux_update_power(struct snd_soc_dapm_widget *widget, | |||
1746 | dapm_power_widgets(widget->dapm, SND_SOC_DAPM_STREAM_NOP); | 1848 | dapm_power_widgets(widget->dapm, SND_SOC_DAPM_STREAM_NOP); |
1747 | } | 1849 | } |
1748 | 1850 | ||
1749 | return 0; | 1851 | return found; |
1852 | } | ||
1853 | |||
1854 | int snd_soc_dapm_mux_update_power(struct snd_soc_dapm_widget *widget, | ||
1855 | struct snd_kcontrol *kcontrol, int mux, struct soc_enum *e) | ||
1856 | { | ||
1857 | struct snd_soc_card *card = widget->dapm->card; | ||
1858 | int ret; | ||
1859 | |||
1860 | mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); | ||
1861 | ret = soc_dapm_mux_update_power(widget, kcontrol, mux, e); | ||
1862 | mutex_unlock(&card->dapm_mutex); | ||
1863 | if (ret > 0) | ||
1864 | soc_dpcm_runtime_update(widget); | ||
1865 | return ret; | ||
1750 | } | 1866 | } |
1751 | EXPORT_SYMBOL_GPL(snd_soc_dapm_mux_update_power); | 1867 | EXPORT_SYMBOL_GPL(snd_soc_dapm_mux_update_power); |
1752 | 1868 | ||
1753 | /* test and update the power status of a mixer or switch widget */ | 1869 | /* test and update the power status of a mixer or switch widget */ |
1754 | int snd_soc_dapm_mixer_update_power(struct snd_soc_dapm_widget *widget, | 1870 | static int soc_dapm_mixer_update_power(struct snd_soc_dapm_widget *widget, |
1755 | struct snd_kcontrol *kcontrol, int connect) | 1871 | struct snd_kcontrol *kcontrol, int connect) |
1756 | { | 1872 | { |
1757 | struct snd_soc_dapm_path *path; | 1873 | struct snd_soc_dapm_path *path; |
@@ -1778,7 +1894,21 @@ int snd_soc_dapm_mixer_update_power(struct snd_soc_dapm_widget *widget, | |||
1778 | dapm_power_widgets(widget->dapm, SND_SOC_DAPM_STREAM_NOP); | 1894 | dapm_power_widgets(widget->dapm, SND_SOC_DAPM_STREAM_NOP); |
1779 | } | 1895 | } |
1780 | 1896 | ||
1781 | return 0; | 1897 | return found; |
1898 | } | ||
1899 | |||
1900 | int snd_soc_dapm_mixer_update_power(struct snd_soc_dapm_widget *widget, | ||
1901 | struct snd_kcontrol *kcontrol, int connect) | ||
1902 | { | ||
1903 | struct snd_soc_card *card = widget->dapm->card; | ||
1904 | int ret; | ||
1905 | |||
1906 | mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); | ||
1907 | ret = soc_dapm_mixer_update_power(widget, kcontrol, connect); | ||
1908 | mutex_unlock(&card->dapm_mutex); | ||
1909 | if (ret > 0) | ||
1910 | soc_dpcm_runtime_update(widget); | ||
1911 | return ret; | ||
1782 | } | 1912 | } |
1783 | EXPORT_SYMBOL_GPL(snd_soc_dapm_mixer_update_power); | 1913 | EXPORT_SYMBOL_GPL(snd_soc_dapm_mixer_update_power); |
1784 | 1914 | ||
@@ -1939,6 +2069,8 @@ static int snd_soc_dapm_set_pin(struct snd_soc_dapm_context *dapm, | |||
1939 | */ | 2069 | */ |
1940 | int snd_soc_dapm_sync(struct snd_soc_dapm_context *dapm) | 2070 | int snd_soc_dapm_sync(struct snd_soc_dapm_context *dapm) |
1941 | { | 2071 | { |
2072 | int ret; | ||
2073 | |||
1942 | /* | 2074 | /* |
1943 | * Suppress early reports (eg, jacks syncing their state) to avoid | 2075 | * Suppress early reports (eg, jacks syncing their state) to avoid |
1944 | * silly DAPM runs during card startup. | 2076 | * silly DAPM runs during card startup. |
@@ -1946,7 +2078,10 @@ int snd_soc_dapm_sync(struct snd_soc_dapm_context *dapm) | |||
1946 | if (!dapm->card || !dapm->card->instantiated) | 2078 | if (!dapm->card || !dapm->card->instantiated) |
1947 | return 0; | 2079 | return 0; |
1948 | 2080 | ||
1949 | return dapm_power_widgets(dapm, SND_SOC_DAPM_STREAM_NOP); | 2081 | mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); |
2082 | ret = dapm_power_widgets(dapm, SND_SOC_DAPM_STREAM_NOP); | ||
2083 | mutex_unlock(&dapm->card->dapm_mutex); | ||
2084 | return ret; | ||
1950 | } | 2085 | } |
1951 | EXPORT_SYMBOL_GPL(snd_soc_dapm_sync); | 2086 | EXPORT_SYMBOL_GPL(snd_soc_dapm_sync); |
1952 | 2087 | ||
@@ -2055,6 +2190,7 @@ static int snd_soc_dapm_add_route(struct snd_soc_dapm_context *dapm, | |||
2055 | case snd_soc_dapm_aif_in: | 2190 | case snd_soc_dapm_aif_in: |
2056 | case snd_soc_dapm_aif_out: | 2191 | case snd_soc_dapm_aif_out: |
2057 | case snd_soc_dapm_dai: | 2192 | case snd_soc_dapm_dai: |
2193 | case snd_soc_dapm_dai_link: | ||
2058 | list_add(&path->list, &dapm->card->paths); | 2194 | list_add(&path->list, &dapm->card->paths); |
2059 | list_add(&path->list_sink, &wsink->sources); | 2195 | list_add(&path->list_sink, &wsink->sources); |
2060 | list_add(&path->list_source, &wsource->sinks); | 2196 | list_add(&path->list_source, &wsource->sinks); |
@@ -2110,19 +2246,21 @@ err: | |||
2110 | int snd_soc_dapm_add_routes(struct snd_soc_dapm_context *dapm, | 2246 | int snd_soc_dapm_add_routes(struct snd_soc_dapm_context *dapm, |
2111 | const struct snd_soc_dapm_route *route, int num) | 2247 | const struct snd_soc_dapm_route *route, int num) |
2112 | { | 2248 | { |
2113 | int i, ret; | 2249 | int i, ret = 0; |
2114 | 2250 | ||
2251 | mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_INIT); | ||
2115 | for (i = 0; i < num; i++) { | 2252 | for (i = 0; i < num; i++) { |
2116 | ret = snd_soc_dapm_add_route(dapm, route); | 2253 | ret = snd_soc_dapm_add_route(dapm, route); |
2117 | if (ret < 0) { | 2254 | if (ret < 0) { |
2118 | dev_err(dapm->dev, "Failed to add route %s->%s\n", | 2255 | dev_err(dapm->dev, "Failed to add route %s->%s\n", |
2119 | route->source, route->sink); | 2256 | route->source, route->sink); |
2120 | return ret; | 2257 | break; |
2121 | } | 2258 | } |
2122 | route++; | 2259 | route++; |
2123 | } | 2260 | } |
2261 | mutex_unlock(&dapm->card->dapm_mutex); | ||
2124 | 2262 | ||
2125 | return 0; | 2263 | return ret; |
2126 | } | 2264 | } |
2127 | EXPORT_SYMBOL_GPL(snd_soc_dapm_add_routes); | 2265 | EXPORT_SYMBOL_GPL(snd_soc_dapm_add_routes); |
2128 | 2266 | ||
@@ -2193,12 +2331,14 @@ int snd_soc_dapm_weak_routes(struct snd_soc_dapm_context *dapm, | |||
2193 | int i, err; | 2331 | int i, err; |
2194 | int ret = 0; | 2332 | int ret = 0; |
2195 | 2333 | ||
2334 | mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_INIT); | ||
2196 | for (i = 0; i < num; i++) { | 2335 | for (i = 0; i < num; i++) { |
2197 | err = snd_soc_dapm_weak_route(dapm, route); | 2336 | err = snd_soc_dapm_weak_route(dapm, route); |
2198 | if (err) | 2337 | if (err) |
2199 | ret = err; | 2338 | ret = err; |
2200 | route++; | 2339 | route++; |
2201 | } | 2340 | } |
2341 | mutex_unlock(&dapm->card->dapm_mutex); | ||
2202 | 2342 | ||
2203 | return ret; | 2343 | return ret; |
2204 | } | 2344 | } |
@@ -2217,6 +2357,8 @@ int snd_soc_dapm_new_widgets(struct snd_soc_dapm_context *dapm) | |||
2217 | struct snd_soc_dapm_widget *w; | 2357 | struct snd_soc_dapm_widget *w; |
2218 | unsigned int val; | 2358 | unsigned int val; |
2219 | 2359 | ||
2360 | mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_INIT); | ||
2361 | |||
2220 | list_for_each_entry(w, &dapm->card->widgets, list) | 2362 | list_for_each_entry(w, &dapm->card->widgets, list) |
2221 | { | 2363 | { |
2222 | if (w->new) | 2364 | if (w->new) |
@@ -2226,8 +2368,10 @@ int snd_soc_dapm_new_widgets(struct snd_soc_dapm_context *dapm) | |||
2226 | w->kcontrols = kzalloc(w->num_kcontrols * | 2368 | w->kcontrols = kzalloc(w->num_kcontrols * |
2227 | sizeof(struct snd_kcontrol *), | 2369 | sizeof(struct snd_kcontrol *), |
2228 | GFP_KERNEL); | 2370 | GFP_KERNEL); |
2229 | if (!w->kcontrols) | 2371 | if (!w->kcontrols) { |
2372 | mutex_unlock(&dapm->card->dapm_mutex); | ||
2230 | return -ENOMEM; | 2373 | return -ENOMEM; |
2374 | } | ||
2231 | } | 2375 | } |
2232 | 2376 | ||
2233 | switch(w->id) { | 2377 | switch(w->id) { |
@@ -2267,6 +2411,7 @@ int snd_soc_dapm_new_widgets(struct snd_soc_dapm_context *dapm) | |||
2267 | } | 2411 | } |
2268 | 2412 | ||
2269 | dapm_power_widgets(dapm, SND_SOC_DAPM_STREAM_NOP); | 2413 | dapm_power_widgets(dapm, SND_SOC_DAPM_STREAM_NOP); |
2414 | mutex_unlock(&dapm->card->dapm_mutex); | ||
2270 | return 0; | 2415 | return 0; |
2271 | } | 2416 | } |
2272 | EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets); | 2417 | EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets); |
@@ -2326,6 +2471,7 @@ int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol, | |||
2326 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); | 2471 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
2327 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; | 2472 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
2328 | struct snd_soc_codec *codec = widget->codec; | 2473 | struct snd_soc_codec *codec = widget->codec; |
2474 | struct snd_soc_card *card = codec->card; | ||
2329 | struct soc_mixer_control *mc = | 2475 | struct soc_mixer_control *mc = |
2330 | (struct soc_mixer_control *)kcontrol->private_value; | 2476 | (struct soc_mixer_control *)kcontrol->private_value; |
2331 | unsigned int reg = mc->reg; | 2477 | unsigned int reg = mc->reg; |
@@ -2352,7 +2498,7 @@ int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol, | |||
2352 | /* old connection must be powered down */ | 2498 | /* old connection must be powered down */ |
2353 | connect = invert ? 1 : 0; | 2499 | connect = invert ? 1 : 0; |
2354 | 2500 | ||
2355 | mutex_lock(&codec->mutex); | 2501 | mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); |
2356 | 2502 | ||
2357 | change = snd_soc_test_bits(widget->codec, reg, mask, val); | 2503 | change = snd_soc_test_bits(widget->codec, reg, mask, val); |
2358 | if (change) { | 2504 | if (change) { |
@@ -2368,13 +2514,13 @@ int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol, | |||
2368 | update.val = val; | 2514 | update.val = val; |
2369 | widget->dapm->update = &update; | 2515 | widget->dapm->update = &update; |
2370 | 2516 | ||
2371 | snd_soc_dapm_mixer_update_power(widget, kcontrol, connect); | 2517 | soc_dapm_mixer_update_power(widget, kcontrol, connect); |
2372 | 2518 | ||
2373 | widget->dapm->update = NULL; | 2519 | widget->dapm->update = NULL; |
2374 | } | 2520 | } |
2375 | } | 2521 | } |
2376 | 2522 | ||
2377 | mutex_unlock(&codec->mutex); | 2523 | mutex_unlock(&card->dapm_mutex); |
2378 | return 0; | 2524 | return 0; |
2379 | } | 2525 | } |
2380 | EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw); | 2526 | EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw); |
@@ -2423,6 +2569,7 @@ int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol, | |||
2423 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); | 2569 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
2424 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; | 2570 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
2425 | struct snd_soc_codec *codec = widget->codec; | 2571 | struct snd_soc_codec *codec = widget->codec; |
2572 | struct snd_soc_card *card = codec->card; | ||
2426 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; | 2573 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
2427 | unsigned int val, mux, change; | 2574 | unsigned int val, mux, change; |
2428 | unsigned int mask, bitmask; | 2575 | unsigned int mask, bitmask; |
@@ -2443,7 +2590,7 @@ int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol, | |||
2443 | mask |= (bitmask - 1) << e->shift_r; | 2590 | mask |= (bitmask - 1) << e->shift_r; |
2444 | } | 2591 | } |
2445 | 2592 | ||
2446 | mutex_lock(&codec->mutex); | 2593 | mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); |
2447 | 2594 | ||
2448 | change = snd_soc_test_bits(widget->codec, e->reg, mask, val); | 2595 | change = snd_soc_test_bits(widget->codec, e->reg, mask, val); |
2449 | if (change) { | 2596 | if (change) { |
@@ -2459,13 +2606,13 @@ int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol, | |||
2459 | update.val = val; | 2606 | update.val = val; |
2460 | widget->dapm->update = &update; | 2607 | widget->dapm->update = &update; |
2461 | 2608 | ||
2462 | snd_soc_dapm_mux_update_power(widget, kcontrol, mux, e); | 2609 | soc_dapm_mux_update_power(widget, kcontrol, mux, e); |
2463 | 2610 | ||
2464 | widget->dapm->update = NULL; | 2611 | widget->dapm->update = NULL; |
2465 | } | 2612 | } |
2466 | } | 2613 | } |
2467 | 2614 | ||
2468 | mutex_unlock(&codec->mutex); | 2615 | mutex_unlock(&card->dapm_mutex); |
2469 | return change; | 2616 | return change; |
2470 | } | 2617 | } |
2471 | EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double); | 2618 | EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double); |
@@ -2502,6 +2649,7 @@ int snd_soc_dapm_put_enum_virt(struct snd_kcontrol *kcontrol, | |||
2502 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); | 2649 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
2503 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; | 2650 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
2504 | struct snd_soc_codec *codec = widget->codec; | 2651 | struct snd_soc_codec *codec = widget->codec; |
2652 | struct snd_soc_card *card = codec->card; | ||
2505 | struct soc_enum *e = | 2653 | struct soc_enum *e = |
2506 | (struct soc_enum *)kcontrol->private_value; | 2654 | (struct soc_enum *)kcontrol->private_value; |
2507 | int change; | 2655 | int change; |
@@ -2511,7 +2659,7 @@ int snd_soc_dapm_put_enum_virt(struct snd_kcontrol *kcontrol, | |||
2511 | if (ucontrol->value.enumerated.item[0] >= e->max) | 2659 | if (ucontrol->value.enumerated.item[0] >= e->max) |
2512 | return -EINVAL; | 2660 | return -EINVAL; |
2513 | 2661 | ||
2514 | mutex_lock(&codec->mutex); | 2662 | mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); |
2515 | 2663 | ||
2516 | change = widget->value != ucontrol->value.enumerated.item[0]; | 2664 | change = widget->value != ucontrol->value.enumerated.item[0]; |
2517 | if (change) { | 2665 | if (change) { |
@@ -2520,11 +2668,11 @@ int snd_soc_dapm_put_enum_virt(struct snd_kcontrol *kcontrol, | |||
2520 | 2668 | ||
2521 | widget->value = ucontrol->value.enumerated.item[0]; | 2669 | widget->value = ucontrol->value.enumerated.item[0]; |
2522 | 2670 | ||
2523 | snd_soc_dapm_mux_update_power(widget, kcontrol, widget->value, e); | 2671 | soc_dapm_mux_update_power(widget, kcontrol, widget->value, e); |
2524 | } | 2672 | } |
2525 | } | 2673 | } |
2526 | 2674 | ||
2527 | mutex_unlock(&codec->mutex); | 2675 | mutex_unlock(&card->dapm_mutex); |
2528 | return ret; | 2676 | return ret; |
2529 | } | 2677 | } |
2530 | EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_virt); | 2678 | EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_virt); |
@@ -2589,6 +2737,7 @@ int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol *kcontrol, | |||
2589 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); | 2737 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
2590 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; | 2738 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
2591 | struct snd_soc_codec *codec = widget->codec; | 2739 | struct snd_soc_codec *codec = widget->codec; |
2740 | struct snd_soc_card *card = codec->card; | ||
2592 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; | 2741 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
2593 | unsigned int val, mux, change; | 2742 | unsigned int val, mux, change; |
2594 | unsigned int mask; | 2743 | unsigned int mask; |
@@ -2607,7 +2756,7 @@ int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol *kcontrol, | |||
2607 | mask |= e->mask << e->shift_r; | 2756 | mask |= e->mask << e->shift_r; |
2608 | } | 2757 | } |
2609 | 2758 | ||
2610 | mutex_lock(&codec->mutex); | 2759 | mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); |
2611 | 2760 | ||
2612 | change = snd_soc_test_bits(widget->codec, e->reg, mask, val); | 2761 | change = snd_soc_test_bits(widget->codec, e->reg, mask, val); |
2613 | if (change) { | 2762 | if (change) { |
@@ -2623,13 +2772,13 @@ int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol *kcontrol, | |||
2623 | update.val = val; | 2772 | update.val = val; |
2624 | widget->dapm->update = &update; | 2773 | widget->dapm->update = &update; |
2625 | 2774 | ||
2626 | snd_soc_dapm_mux_update_power(widget, kcontrol, mux, e); | 2775 | soc_dapm_mux_update_power(widget, kcontrol, mux, e); |
2627 | 2776 | ||
2628 | widget->dapm->update = NULL; | 2777 | widget->dapm->update = NULL; |
2629 | } | 2778 | } |
2630 | } | 2779 | } |
2631 | 2780 | ||
2632 | mutex_unlock(&codec->mutex); | 2781 | mutex_unlock(&card->dapm_mutex); |
2633 | return change; | 2782 | return change; |
2634 | } | 2783 | } |
2635 | EXPORT_SYMBOL_GPL(snd_soc_dapm_put_value_enum_double); | 2784 | EXPORT_SYMBOL_GPL(snd_soc_dapm_put_value_enum_double); |
@@ -2666,12 +2815,12 @@ int snd_soc_dapm_get_pin_switch(struct snd_kcontrol *kcontrol, | |||
2666 | struct snd_soc_card *card = snd_kcontrol_chip(kcontrol); | 2815 | struct snd_soc_card *card = snd_kcontrol_chip(kcontrol); |
2667 | const char *pin = (const char *)kcontrol->private_value; | 2816 | const char *pin = (const char *)kcontrol->private_value; |
2668 | 2817 | ||
2669 | mutex_lock(&card->mutex); | 2818 | mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); |
2670 | 2819 | ||
2671 | ucontrol->value.integer.value[0] = | 2820 | ucontrol->value.integer.value[0] = |
2672 | snd_soc_dapm_get_pin_status(&card->dapm, pin); | 2821 | snd_soc_dapm_get_pin_status(&card->dapm, pin); |
2673 | 2822 | ||
2674 | mutex_unlock(&card->mutex); | 2823 | mutex_unlock(&card->dapm_mutex); |
2675 | 2824 | ||
2676 | return 0; | 2825 | return 0; |
2677 | } | 2826 | } |
@@ -2689,17 +2838,16 @@ int snd_soc_dapm_put_pin_switch(struct snd_kcontrol *kcontrol, | |||
2689 | struct snd_soc_card *card = snd_kcontrol_chip(kcontrol); | 2838 | struct snd_soc_card *card = snd_kcontrol_chip(kcontrol); |
2690 | const char *pin = (const char *)kcontrol->private_value; | 2839 | const char *pin = (const char *)kcontrol->private_value; |
2691 | 2840 | ||
2692 | mutex_lock(&card->mutex); | 2841 | mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); |
2693 | 2842 | ||
2694 | if (ucontrol->value.integer.value[0]) | 2843 | if (ucontrol->value.integer.value[0]) |
2695 | snd_soc_dapm_enable_pin(&card->dapm, pin); | 2844 | snd_soc_dapm_enable_pin(&card->dapm, pin); |
2696 | else | 2845 | else |
2697 | snd_soc_dapm_disable_pin(&card->dapm, pin); | 2846 | snd_soc_dapm_disable_pin(&card->dapm, pin); |
2698 | 2847 | ||
2699 | snd_soc_dapm_sync(&card->dapm); | 2848 | mutex_unlock(&card->dapm_mutex); |
2700 | |||
2701 | mutex_unlock(&card->mutex); | ||
2702 | 2849 | ||
2850 | snd_soc_dapm_sync(&card->dapm); | ||
2703 | return 0; | 2851 | return 0; |
2704 | } | 2852 | } |
2705 | EXPORT_SYMBOL_GPL(snd_soc_dapm_put_pin_switch); | 2853 | EXPORT_SYMBOL_GPL(snd_soc_dapm_put_pin_switch); |
@@ -2717,9 +2865,9 @@ snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm, | |||
2717 | 2865 | ||
2718 | switch (w->id) { | 2866 | switch (w->id) { |
2719 | case snd_soc_dapm_regulator_supply: | 2867 | case snd_soc_dapm_regulator_supply: |
2720 | w->priv = devm_regulator_get(dapm->dev, w->name); | 2868 | w->regulator = devm_regulator_get(dapm->dev, w->name); |
2721 | if (IS_ERR(w->priv)) { | 2869 | if (IS_ERR(w->regulator)) { |
2722 | ret = PTR_ERR(w->priv); | 2870 | ret = PTR_ERR(w->regulator); |
2723 | dev_err(dapm->dev, "Failed to request %s: %d\n", | 2871 | dev_err(dapm->dev, "Failed to request %s: %d\n", |
2724 | w->name, ret); | 2872 | w->name, ret); |
2725 | return NULL; | 2873 | return NULL; |
@@ -2771,6 +2919,7 @@ snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm, | |||
2771 | case snd_soc_dapm_hp: | 2919 | case snd_soc_dapm_hp: |
2772 | case snd_soc_dapm_mic: | 2920 | case snd_soc_dapm_mic: |
2773 | case snd_soc_dapm_line: | 2921 | case snd_soc_dapm_line: |
2922 | case snd_soc_dapm_dai_link: | ||
2774 | w->power_check = dapm_generic_check_power; | 2923 | w->power_check = dapm_generic_check_power; |
2775 | break; | 2924 | break; |
2776 | case snd_soc_dapm_supply: | 2925 | case snd_soc_dapm_supply: |
@@ -2816,21 +2965,177 @@ int snd_soc_dapm_new_controls(struct snd_soc_dapm_context *dapm, | |||
2816 | { | 2965 | { |
2817 | struct snd_soc_dapm_widget *w; | 2966 | struct snd_soc_dapm_widget *w; |
2818 | int i; | 2967 | int i; |
2968 | int ret = 0; | ||
2819 | 2969 | ||
2970 | mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_INIT); | ||
2820 | for (i = 0; i < num; i++) { | 2971 | for (i = 0; i < num; i++) { |
2821 | w = snd_soc_dapm_new_control(dapm, widget); | 2972 | w = snd_soc_dapm_new_control(dapm, widget); |
2822 | if (!w) { | 2973 | if (!w) { |
2823 | dev_err(dapm->dev, | 2974 | dev_err(dapm->dev, |
2824 | "ASoC: Failed to create DAPM control %s\n", | 2975 | "ASoC: Failed to create DAPM control %s\n", |
2825 | widget->name); | 2976 | widget->name); |
2826 | return -ENOMEM; | 2977 | ret = -ENOMEM; |
2978 | break; | ||
2827 | } | 2979 | } |
2828 | widget++; | 2980 | widget++; |
2829 | } | 2981 | } |
2830 | return 0; | 2982 | mutex_unlock(&dapm->card->dapm_mutex); |
2983 | return ret; | ||
2831 | } | 2984 | } |
2832 | EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls); | 2985 | EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls); |
2833 | 2986 | ||
2987 | static int snd_soc_dai_link_event(struct snd_soc_dapm_widget *w, | ||
2988 | struct snd_kcontrol *kcontrol, int event) | ||
2989 | { | ||
2990 | struct snd_soc_dapm_path *source_p, *sink_p; | ||
2991 | struct snd_soc_dai *source, *sink; | ||
2992 | const struct snd_soc_pcm_stream *config = w->params; | ||
2993 | struct snd_pcm_substream substream; | ||
2994 | struct snd_pcm_hw_params *params = NULL; | ||
2995 | u64 fmt; | ||
2996 | int ret; | ||
2997 | |||
2998 | BUG_ON(!config); | ||
2999 | BUG_ON(list_empty(&w->sources) || list_empty(&w->sinks)); | ||
3000 | |||
3001 | /* We only support a single source and sink, pick the first */ | ||
3002 | source_p = list_first_entry(&w->sources, struct snd_soc_dapm_path, | ||
3003 | list_sink); | ||
3004 | sink_p = list_first_entry(&w->sinks, struct snd_soc_dapm_path, | ||
3005 | list_source); | ||
3006 | |||
3007 | BUG_ON(!source_p || !sink_p); | ||
3008 | BUG_ON(!sink_p->source || !source_p->sink); | ||
3009 | BUG_ON(!source_p->source || !sink_p->sink); | ||
3010 | |||
3011 | source = source_p->source->priv; | ||
3012 | sink = sink_p->sink->priv; | ||
3013 | |||
3014 | /* Be a little careful as we don't want to overflow the mask array */ | ||
3015 | if (config->formats) { | ||
3016 | fmt = ffs(config->formats) - 1; | ||
3017 | } else { | ||
3018 | dev_warn(w->dapm->dev, "Invalid format %llx specified\n", | ||
3019 | config->formats); | ||
3020 | fmt = 0; | ||
3021 | } | ||
3022 | |||
3023 | /* Currently very limited parameter selection */ | ||
3024 | params = kzalloc(sizeof(*params), GFP_KERNEL); | ||
3025 | if (!params) { | ||
3026 | ret = -ENOMEM; | ||
3027 | goto out; | ||
3028 | } | ||
3029 | snd_mask_set(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT), fmt); | ||
3030 | |||
3031 | hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE)->min = | ||
3032 | config->rate_min; | ||
3033 | hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE)->max = | ||
3034 | config->rate_max; | ||
3035 | |||
3036 | hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS)->min | ||
3037 | = config->channels_min; | ||
3038 | hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS)->max | ||
3039 | = config->channels_max; | ||
3040 | |||
3041 | memset(&substream, 0, sizeof(substream)); | ||
3042 | |||
3043 | switch (event) { | ||
3044 | case SND_SOC_DAPM_PRE_PMU: | ||
3045 | if (source->driver->ops && source->driver->ops->hw_params) { | ||
3046 | substream.stream = SNDRV_PCM_STREAM_CAPTURE; | ||
3047 | ret = source->driver->ops->hw_params(&substream, | ||
3048 | params, source); | ||
3049 | if (ret != 0) { | ||
3050 | dev_err(source->dev, | ||
3051 | "hw_params() failed: %d\n", ret); | ||
3052 | goto out; | ||
3053 | } | ||
3054 | } | ||
3055 | |||
3056 | if (sink->driver->ops && sink->driver->ops->hw_params) { | ||
3057 | substream.stream = SNDRV_PCM_STREAM_PLAYBACK; | ||
3058 | ret = sink->driver->ops->hw_params(&substream, params, | ||
3059 | sink); | ||
3060 | if (ret != 0) { | ||
3061 | dev_err(sink->dev, | ||
3062 | "hw_params() failed: %d\n", ret); | ||
3063 | goto out; | ||
3064 | } | ||
3065 | } | ||
3066 | break; | ||
3067 | |||
3068 | case SND_SOC_DAPM_POST_PMU: | ||
3069 | ret = snd_soc_dai_digital_mute(sink, 0); | ||
3070 | if (ret != 0 && ret != -ENOTSUPP) | ||
3071 | dev_warn(sink->dev, "Failed to unmute: %d\n", ret); | ||
3072 | ret = 0; | ||
3073 | break; | ||
3074 | |||
3075 | case SND_SOC_DAPM_PRE_PMD: | ||
3076 | ret = snd_soc_dai_digital_mute(sink, 1); | ||
3077 | if (ret != 0 && ret != -ENOTSUPP) | ||
3078 | dev_warn(sink->dev, "Failed to mute: %d\n", ret); | ||
3079 | ret = 0; | ||
3080 | break; | ||
3081 | |||
3082 | default: | ||
3083 | BUG(); | ||
3084 | return -EINVAL; | ||
3085 | } | ||
3086 | |||
3087 | out: | ||
3088 | kfree(params); | ||
3089 | return ret; | ||
3090 | } | ||
3091 | |||
3092 | int snd_soc_dapm_new_pcm(struct snd_soc_card *card, | ||
3093 | const struct snd_soc_pcm_stream *params, | ||
3094 | struct snd_soc_dapm_widget *source, | ||
3095 | struct snd_soc_dapm_widget *sink) | ||
3096 | { | ||
3097 | struct snd_soc_dapm_route routes[2]; | ||
3098 | struct snd_soc_dapm_widget template; | ||
3099 | struct snd_soc_dapm_widget *w; | ||
3100 | size_t len; | ||
3101 | char *link_name; | ||
3102 | |||
3103 | len = strlen(source->name) + strlen(sink->name) + 2; | ||
3104 | link_name = devm_kzalloc(card->dev, len, GFP_KERNEL); | ||
3105 | if (!link_name) | ||
3106 | return -ENOMEM; | ||
3107 | snprintf(link_name, len, "%s-%s", source->name, sink->name); | ||
3108 | |||
3109 | memset(&template, 0, sizeof(template)); | ||
3110 | template.reg = SND_SOC_NOPM; | ||
3111 | template.id = snd_soc_dapm_dai_link; | ||
3112 | template.name = link_name; | ||
3113 | template.event = snd_soc_dai_link_event; | ||
3114 | template.event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | | ||
3115 | SND_SOC_DAPM_PRE_PMD; | ||
3116 | |||
3117 | dev_dbg(card->dev, "adding %s widget\n", link_name); | ||
3118 | |||
3119 | w = snd_soc_dapm_new_control(&card->dapm, &template); | ||
3120 | if (!w) { | ||
3121 | dev_err(card->dev, "Failed to create %s widget\n", | ||
3122 | link_name); | ||
3123 | return -ENOMEM; | ||
3124 | } | ||
3125 | |||
3126 | w->params = params; | ||
3127 | |||
3128 | memset(&routes, 0, sizeof(routes)); | ||
3129 | |||
3130 | routes[0].source = source->name; | ||
3131 | routes[0].sink = link_name; | ||
3132 | routes[1].source = link_name; | ||
3133 | routes[1].sink = sink->name; | ||
3134 | |||
3135 | return snd_soc_dapm_add_routes(&card->dapm, routes, | ||
3136 | ARRAY_SIZE(routes)); | ||
3137 | } | ||
3138 | |||
2834 | int snd_soc_dapm_new_dai_widgets(struct snd_soc_dapm_context *dapm, | 3139 | int snd_soc_dapm_new_dai_widgets(struct snd_soc_dapm_context *dapm, |
2835 | struct snd_soc_dai *dai) | 3140 | struct snd_soc_dai *dai) |
2836 | { | 3141 | { |
@@ -2934,37 +3239,61 @@ int snd_soc_dapm_link_dai_widgets(struct snd_soc_card *card) | |||
2934 | return 0; | 3239 | return 0; |
2935 | } | 3240 | } |
2936 | 3241 | ||
2937 | static void soc_dapm_stream_event(struct snd_soc_dapm_context *dapm, | 3242 | static void soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd, int stream, |
2938 | int stream, struct snd_soc_dai *dai, | 3243 | int event) |
2939 | int event) | ||
2940 | { | 3244 | { |
2941 | struct snd_soc_dapm_widget *w; | ||
2942 | 3245 | ||
2943 | if (stream == SNDRV_PCM_STREAM_PLAYBACK) | 3246 | struct snd_soc_dapm_widget *w_cpu, *w_codec; |
2944 | w = dai->playback_widget; | 3247 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
2945 | else | 3248 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
2946 | w = dai->capture_widget; | ||
2947 | 3249 | ||
2948 | if (!w) | 3250 | if (stream == SNDRV_PCM_STREAM_PLAYBACK) { |
2949 | return; | 3251 | w_cpu = cpu_dai->playback_widget; |
3252 | w_codec = codec_dai->playback_widget; | ||
3253 | } else { | ||
3254 | w_cpu = cpu_dai->capture_widget; | ||
3255 | w_codec = codec_dai->capture_widget; | ||
3256 | } | ||
2950 | 3257 | ||
2951 | dapm_mark_dirty(w, "stream event"); | 3258 | if (w_cpu) { |
2952 | 3259 | ||
2953 | switch (event) { | 3260 | dapm_mark_dirty(w_cpu, "stream event"); |
2954 | case SND_SOC_DAPM_STREAM_START: | 3261 | |
2955 | w->active = 1; | 3262 | switch (event) { |
2956 | break; | 3263 | case SND_SOC_DAPM_STREAM_START: |
2957 | case SND_SOC_DAPM_STREAM_STOP: | 3264 | w_cpu->active = 1; |
2958 | w->active = 0; | 3265 | break; |
2959 | break; | 3266 | case SND_SOC_DAPM_STREAM_STOP: |
2960 | case SND_SOC_DAPM_STREAM_SUSPEND: | 3267 | w_cpu->active = 0; |
2961 | case SND_SOC_DAPM_STREAM_RESUME: | 3268 | break; |
2962 | case SND_SOC_DAPM_STREAM_PAUSE_PUSH: | 3269 | case SND_SOC_DAPM_STREAM_SUSPEND: |
2963 | case SND_SOC_DAPM_STREAM_PAUSE_RELEASE: | 3270 | case SND_SOC_DAPM_STREAM_RESUME: |
2964 | break; | 3271 | case SND_SOC_DAPM_STREAM_PAUSE_PUSH: |
3272 | case SND_SOC_DAPM_STREAM_PAUSE_RELEASE: | ||
3273 | break; | ||
3274 | } | ||
3275 | } | ||
3276 | |||
3277 | if (w_codec) { | ||
3278 | |||
3279 | dapm_mark_dirty(w_codec, "stream event"); | ||
3280 | |||
3281 | switch (event) { | ||
3282 | case SND_SOC_DAPM_STREAM_START: | ||
3283 | w_codec->active = 1; | ||
3284 | break; | ||
3285 | case SND_SOC_DAPM_STREAM_STOP: | ||
3286 | w_codec->active = 0; | ||
3287 | break; | ||
3288 | case SND_SOC_DAPM_STREAM_SUSPEND: | ||
3289 | case SND_SOC_DAPM_STREAM_RESUME: | ||
3290 | case SND_SOC_DAPM_STREAM_PAUSE_PUSH: | ||
3291 | case SND_SOC_DAPM_STREAM_PAUSE_RELEASE: | ||
3292 | break; | ||
3293 | } | ||
2965 | } | 3294 | } |
2966 | 3295 | ||
2967 | dapm_power_widgets(dapm, event); | 3296 | dapm_power_widgets(&rtd->card->dapm, event); |
2968 | } | 3297 | } |
2969 | 3298 | ||
2970 | /** | 3299 | /** |
@@ -2978,15 +3307,14 @@ static void soc_dapm_stream_event(struct snd_soc_dapm_context *dapm, | |||
2978 | * | 3307 | * |
2979 | * Returns 0 for success else error. | 3308 | * Returns 0 for success else error. |
2980 | */ | 3309 | */ |
2981 | int snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd, int stream, | 3310 | void snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd, int stream, |
2982 | struct snd_soc_dai *dai, int event) | 3311 | int event) |
2983 | { | 3312 | { |
2984 | struct snd_soc_codec *codec = rtd->codec; | 3313 | struct snd_soc_card *card = rtd->card; |
2985 | 3314 | ||
2986 | mutex_lock(&codec->mutex); | 3315 | mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); |
2987 | soc_dapm_stream_event(&codec->dapm, stream, dai, event); | 3316 | soc_dapm_stream_event(rtd, stream, event); |
2988 | mutex_unlock(&codec->mutex); | 3317 | mutex_unlock(&card->dapm_mutex); |
2989 | return 0; | ||
2990 | } | 3318 | } |
2991 | 3319 | ||
2992 | /** | 3320 | /** |
diff --git a/sound/soc/soc-jack.c b/sound/soc/soc-jack.c index ee4353f843ea..7f8b3b7428bb 100644 --- a/sound/soc/soc-jack.c +++ b/sound/soc/soc-jack.c | |||
@@ -36,6 +36,7 @@ | |||
36 | int snd_soc_jack_new(struct snd_soc_codec *codec, const char *id, int type, | 36 | int snd_soc_jack_new(struct snd_soc_codec *codec, const char *id, int type, |
37 | struct snd_soc_jack *jack) | 37 | struct snd_soc_jack *jack) |
38 | { | 38 | { |
39 | mutex_init(&jack->mutex); | ||
39 | jack->codec = codec; | 40 | jack->codec = codec; |
40 | INIT_LIST_HEAD(&jack->pins); | 41 | INIT_LIST_HEAD(&jack->pins); |
41 | INIT_LIST_HEAD(&jack->jack_zones); | 42 | INIT_LIST_HEAD(&jack->jack_zones); |
@@ -75,7 +76,7 @@ void snd_soc_jack_report(struct snd_soc_jack *jack, int status, int mask) | |||
75 | codec = jack->codec; | 76 | codec = jack->codec; |
76 | dapm = &codec->dapm; | 77 | dapm = &codec->dapm; |
77 | 78 | ||
78 | mutex_lock(&codec->mutex); | 79 | mutex_lock(&jack->mutex); |
79 | 80 | ||
80 | oldstatus = jack->status; | 81 | oldstatus = jack->status; |
81 | 82 | ||
@@ -109,7 +110,7 @@ void snd_soc_jack_report(struct snd_soc_jack *jack, int status, int mask) | |||
109 | snd_jack_report(jack->jack, jack->status); | 110 | snd_jack_report(jack->jack, jack->status); |
110 | 111 | ||
111 | out: | 112 | out: |
112 | mutex_unlock(&codec->mutex); | 113 | mutex_unlock(&jack->mutex); |
113 | } | 114 | } |
114 | EXPORT_SYMBOL_GPL(snd_soc_jack_report); | 115 | EXPORT_SYMBOL_GPL(snd_soc_jack_report); |
115 | 116 | ||
diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c index 0ad8dcacd2f3..bedd1717a373 100644 --- a/sound/soc/soc-pcm.c +++ b/sound/soc/soc-pcm.c | |||
@@ -22,12 +22,38 @@ | |||
22 | #include <linux/pm_runtime.h> | 22 | #include <linux/pm_runtime.h> |
23 | #include <linux/slab.h> | 23 | #include <linux/slab.h> |
24 | #include <linux/workqueue.h> | 24 | #include <linux/workqueue.h> |
25 | #include <linux/export.h> | ||
26 | #include <linux/debugfs.h> | ||
25 | #include <sound/core.h> | 27 | #include <sound/core.h> |
26 | #include <sound/pcm.h> | 28 | #include <sound/pcm.h> |
27 | #include <sound/pcm_params.h> | 29 | #include <sound/pcm_params.h> |
28 | #include <sound/soc.h> | 30 | #include <sound/soc.h> |
31 | #include <sound/soc-dpcm.h> | ||
29 | #include <sound/initval.h> | 32 | #include <sound/initval.h> |
30 | 33 | ||
34 | #define DPCM_MAX_BE_USERS 8 | ||
35 | |||
36 | /* DPCM stream event, send event to FE and all active BEs. */ | ||
37 | static int dpcm_dapm_stream_event(struct snd_soc_pcm_runtime *fe, int dir, | ||
38 | int event) | ||
39 | { | ||
40 | struct snd_soc_dpcm *dpcm; | ||
41 | |||
42 | list_for_each_entry(dpcm, &fe->dpcm[dir].be_clients, list_be) { | ||
43 | |||
44 | struct snd_soc_pcm_runtime *be = dpcm->be; | ||
45 | |||
46 | dev_dbg(be->dev, "pm: BE %s event %d dir %d\n", | ||
47 | be->dai_link->name, event, dir); | ||
48 | |||
49 | snd_soc_dapm_stream_event(be, dir, event); | ||
50 | } | ||
51 | |||
52 | snd_soc_dapm_stream_event(fe, dir, event); | ||
53 | |||
54 | return 0; | ||
55 | } | ||
56 | |||
31 | static int soc_pcm_apply_symmetry(struct snd_pcm_substream *substream, | 57 | static int soc_pcm_apply_symmetry(struct snd_pcm_substream *substream, |
32 | struct snd_soc_dai *soc_dai) | 58 | struct snd_soc_dai *soc_dai) |
33 | { | 59 | { |
@@ -156,6 +182,10 @@ static int soc_pcm_open(struct snd_pcm_substream *substream) | |||
156 | } | 182 | } |
157 | } | 183 | } |
158 | 184 | ||
185 | /* Dynamic PCM DAI links compat checks use dynamic capabilities */ | ||
186 | if (rtd->dai_link->dynamic || rtd->dai_link->no_pcm) | ||
187 | goto dynamic; | ||
188 | |||
159 | /* Check that the codec and cpu DAIs are compatible */ | 189 | /* Check that the codec and cpu DAIs are compatible */ |
160 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { | 190 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
161 | runtime->hw.rate_min = | 191 | runtime->hw.rate_min = |
@@ -248,6 +278,7 @@ static int soc_pcm_open(struct snd_pcm_substream *substream) | |||
248 | pr_debug("asoc: min rate %d max rate %d\n", runtime->hw.rate_min, | 278 | pr_debug("asoc: min rate %d max rate %d\n", runtime->hw.rate_min, |
249 | runtime->hw.rate_max); | 279 | runtime->hw.rate_max); |
250 | 280 | ||
281 | dynamic: | ||
251 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { | 282 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
252 | cpu_dai->playback_active++; | 283 | cpu_dai->playback_active++; |
253 | codec_dai->playback_active++; | 284 | codec_dai->playback_active++; |
@@ -308,7 +339,7 @@ static void close_delayed_work(struct work_struct *work) | |||
308 | if (codec_dai->pop_wait == 1) { | 339 | if (codec_dai->pop_wait == 1) { |
309 | codec_dai->pop_wait = 0; | 340 | codec_dai->pop_wait = 0; |
310 | snd_soc_dapm_stream_event(rtd, SNDRV_PCM_STREAM_PLAYBACK, | 341 | snd_soc_dapm_stream_event(rtd, SNDRV_PCM_STREAM_PLAYBACK, |
311 | codec_dai, SND_SOC_DAPM_STREAM_STOP); | 342 | SND_SOC_DAPM_STREAM_STOP); |
312 | } | 343 | } |
313 | 344 | ||
314 | mutex_unlock(&rtd->pcm_mutex); | 345 | mutex_unlock(&rtd->pcm_mutex); |
@@ -373,7 +404,6 @@ static int soc_pcm_close(struct snd_pcm_substream *substream) | |||
373 | /* powered down playback stream now */ | 404 | /* powered down playback stream now */ |
374 | snd_soc_dapm_stream_event(rtd, | 405 | snd_soc_dapm_stream_event(rtd, |
375 | SNDRV_PCM_STREAM_PLAYBACK, | 406 | SNDRV_PCM_STREAM_PLAYBACK, |
376 | codec_dai, | ||
377 | SND_SOC_DAPM_STREAM_STOP); | 407 | SND_SOC_DAPM_STREAM_STOP); |
378 | } else { | 408 | } else { |
379 | /* start delayed pop wq here for playback streams */ | 409 | /* start delayed pop wq here for playback streams */ |
@@ -384,7 +414,7 @@ static int soc_pcm_close(struct snd_pcm_substream *substream) | |||
384 | } else { | 414 | } else { |
385 | /* capture streams can be powered down now */ | 415 | /* capture streams can be powered down now */ |
386 | snd_soc_dapm_stream_event(rtd, SNDRV_PCM_STREAM_CAPTURE, | 416 | snd_soc_dapm_stream_event(rtd, SNDRV_PCM_STREAM_CAPTURE, |
387 | codec_dai, SND_SOC_DAPM_STREAM_STOP); | 417 | SND_SOC_DAPM_STREAM_STOP); |
388 | } | 418 | } |
389 | 419 | ||
390 | mutex_unlock(&rtd->pcm_mutex); | 420 | mutex_unlock(&rtd->pcm_mutex); |
@@ -453,8 +483,8 @@ static int soc_pcm_prepare(struct snd_pcm_substream *substream) | |||
453 | cancel_delayed_work(&rtd->delayed_work); | 483 | cancel_delayed_work(&rtd->delayed_work); |
454 | } | 484 | } |
455 | 485 | ||
456 | snd_soc_dapm_stream_event(rtd, substream->stream, codec_dai, | 486 | snd_soc_dapm_stream_event(rtd, substream->stream, |
457 | SND_SOC_DAPM_STREAM_START); | 487 | SND_SOC_DAPM_STREAM_START); |
458 | 488 | ||
459 | snd_soc_dai_digital_mute(codec_dai, 0); | 489 | snd_soc_dai_digital_mute(codec_dai, 0); |
460 | 490 | ||
@@ -602,6 +632,34 @@ static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd) | |||
602 | return 0; | 632 | return 0; |
603 | } | 633 | } |
604 | 634 | ||
635 | static int soc_pcm_bespoke_trigger(struct snd_pcm_substream *substream, | ||
636 | int cmd) | ||
637 | { | ||
638 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
639 | struct snd_soc_platform *platform = rtd->platform; | ||
640 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; | ||
641 | struct snd_soc_dai *codec_dai = rtd->codec_dai; | ||
642 | int ret; | ||
643 | |||
644 | if (codec_dai->driver->ops->bespoke_trigger) { | ||
645 | ret = codec_dai->driver->ops->bespoke_trigger(substream, cmd, codec_dai); | ||
646 | if (ret < 0) | ||
647 | return ret; | ||
648 | } | ||
649 | |||
650 | if (platform->driver->bespoke_trigger) { | ||
651 | ret = platform->driver->bespoke_trigger(substream, cmd); | ||
652 | if (ret < 0) | ||
653 | return ret; | ||
654 | } | ||
655 | |||
656 | if (cpu_dai->driver->ops->bespoke_trigger) { | ||
657 | ret = cpu_dai->driver->ops->bespoke_trigger(substream, cmd, cpu_dai); | ||
658 | if (ret < 0) | ||
659 | return ret; | ||
660 | } | ||
661 | return 0; | ||
662 | } | ||
605 | /* | 663 | /* |
606 | * soc level wrapper for pointer callback | 664 | * soc level wrapper for pointer callback |
607 | * If cpu_dai, codec_dai, platform driver has the delay callback, than | 665 | * If cpu_dai, codec_dai, platform driver has the delay callback, than |
@@ -634,6 +692,1308 @@ static snd_pcm_uframes_t soc_pcm_pointer(struct snd_pcm_substream *substream) | |||
634 | return offset; | 692 | return offset; |
635 | } | 693 | } |
636 | 694 | ||
695 | /* connect a FE and BE */ | ||
696 | static int dpcm_be_connect(struct snd_soc_pcm_runtime *fe, | ||
697 | struct snd_soc_pcm_runtime *be, int stream) | ||
698 | { | ||
699 | struct snd_soc_dpcm *dpcm; | ||
700 | |||
701 | /* only add new dpcms */ | ||
702 | list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) { | ||
703 | if (dpcm->be == be && dpcm->fe == fe) | ||
704 | return 0; | ||
705 | } | ||
706 | |||
707 | dpcm = kzalloc(sizeof(struct snd_soc_dpcm), GFP_KERNEL); | ||
708 | if (!dpcm) | ||
709 | return -ENOMEM; | ||
710 | |||
711 | dpcm->be = be; | ||
712 | dpcm->fe = fe; | ||
713 | be->dpcm[stream].runtime = fe->dpcm[stream].runtime; | ||
714 | dpcm->state = SND_SOC_DPCM_LINK_STATE_NEW; | ||
715 | list_add(&dpcm->list_be, &fe->dpcm[stream].be_clients); | ||
716 | list_add(&dpcm->list_fe, &be->dpcm[stream].fe_clients); | ||
717 | |||
718 | dev_dbg(fe->dev, " connected new DPCM %s path %s %s %s\n", | ||
719 | stream ? "capture" : "playback", fe->dai_link->name, | ||
720 | stream ? "<-" : "->", be->dai_link->name); | ||
721 | |||
722 | #ifdef CONFIG_DEBUG_FS | ||
723 | dpcm->debugfs_state = debugfs_create_u32(be->dai_link->name, 0644, | ||
724 | fe->debugfs_dpcm_root, &dpcm->state); | ||
725 | #endif | ||
726 | return 1; | ||
727 | } | ||
728 | |||
729 | /* reparent a BE onto another FE */ | ||
730 | static void dpcm_be_reparent(struct snd_soc_pcm_runtime *fe, | ||
731 | struct snd_soc_pcm_runtime *be, int stream) | ||
732 | { | ||
733 | struct snd_soc_dpcm *dpcm; | ||
734 | struct snd_pcm_substream *fe_substream, *be_substream; | ||
735 | |||
736 | /* reparent if BE is connected to other FEs */ | ||
737 | if (!be->dpcm[stream].users) | ||
738 | return; | ||
739 | |||
740 | be_substream = snd_soc_dpcm_get_substream(be, stream); | ||
741 | |||
742 | list_for_each_entry(dpcm, &be->dpcm[stream].fe_clients, list_fe) { | ||
743 | if (dpcm->fe == fe) | ||
744 | continue; | ||
745 | |||
746 | dev_dbg(fe->dev, " reparent %s path %s %s %s\n", | ||
747 | stream ? "capture" : "playback", | ||
748 | dpcm->fe->dai_link->name, | ||
749 | stream ? "<-" : "->", dpcm->be->dai_link->name); | ||
750 | |||
751 | fe_substream = snd_soc_dpcm_get_substream(dpcm->fe, stream); | ||
752 | be_substream->runtime = fe_substream->runtime; | ||
753 | break; | ||
754 | } | ||
755 | } | ||
756 | |||
757 | /* disconnect a BE and FE */ | ||
758 | static void dpcm_be_disconnect(struct snd_soc_pcm_runtime *fe, int stream) | ||
759 | { | ||
760 | struct snd_soc_dpcm *dpcm, *d; | ||
761 | |||
762 | list_for_each_entry_safe(dpcm, d, &fe->dpcm[stream].be_clients, list_be) { | ||
763 | dev_dbg(fe->dev, "BE %s disconnect check for %s\n", | ||
764 | stream ? "capture" : "playback", | ||
765 | dpcm->be->dai_link->name); | ||
766 | |||
767 | if (dpcm->state != SND_SOC_DPCM_LINK_STATE_FREE) | ||
768 | continue; | ||
769 | |||
770 | dev_dbg(fe->dev, " freed DSP %s path %s %s %s\n", | ||
771 | stream ? "capture" : "playback", fe->dai_link->name, | ||
772 | stream ? "<-" : "->", dpcm->be->dai_link->name); | ||
773 | |||
774 | /* BEs still alive need new FE */ | ||
775 | dpcm_be_reparent(fe, dpcm->be, stream); | ||
776 | |||
777 | #ifdef CONFIG_DEBUG_FS | ||
778 | debugfs_remove(dpcm->debugfs_state); | ||
779 | #endif | ||
780 | list_del(&dpcm->list_be); | ||
781 | list_del(&dpcm->list_fe); | ||
782 | kfree(dpcm); | ||
783 | } | ||
784 | } | ||
785 | |||
786 | /* get BE for DAI widget and stream */ | ||
787 | static struct snd_soc_pcm_runtime *dpcm_get_be(struct snd_soc_card *card, | ||
788 | struct snd_soc_dapm_widget *widget, int stream) | ||
789 | { | ||
790 | struct snd_soc_pcm_runtime *be; | ||
791 | int i; | ||
792 | |||
793 | if (stream == SNDRV_PCM_STREAM_PLAYBACK) { | ||
794 | for (i = 0; i < card->num_links; i++) { | ||
795 | be = &card->rtd[i]; | ||
796 | |||
797 | if (be->cpu_dai->playback_widget == widget || | ||
798 | be->codec_dai->playback_widget == widget) | ||
799 | return be; | ||
800 | } | ||
801 | } else { | ||
802 | |||
803 | for (i = 0; i < card->num_links; i++) { | ||
804 | be = &card->rtd[i]; | ||
805 | |||
806 | if (be->cpu_dai->capture_widget == widget || | ||
807 | be->codec_dai->capture_widget == widget) | ||
808 | return be; | ||
809 | } | ||
810 | } | ||
811 | |||
812 | dev_err(card->dev, "can't get %s BE for %s\n", | ||
813 | stream ? "capture" : "playback", widget->name); | ||
814 | return NULL; | ||
815 | } | ||
816 | |||
817 | static inline struct snd_soc_dapm_widget * | ||
818 | rtd_get_cpu_widget(struct snd_soc_pcm_runtime *rtd, int stream) | ||
819 | { | ||
820 | if (stream == SNDRV_PCM_STREAM_PLAYBACK) | ||
821 | return rtd->cpu_dai->playback_widget; | ||
822 | else | ||
823 | return rtd->cpu_dai->capture_widget; | ||
824 | } | ||
825 | |||
826 | static inline struct snd_soc_dapm_widget * | ||
827 | rtd_get_codec_widget(struct snd_soc_pcm_runtime *rtd, int stream) | ||
828 | { | ||
829 | if (stream == SNDRV_PCM_STREAM_PLAYBACK) | ||
830 | return rtd->codec_dai->playback_widget; | ||
831 | else | ||
832 | return rtd->codec_dai->capture_widget; | ||
833 | } | ||
834 | |||
835 | static int widget_in_list(struct snd_soc_dapm_widget_list *list, | ||
836 | struct snd_soc_dapm_widget *widget) | ||
837 | { | ||
838 | int i; | ||
839 | |||
840 | for (i = 0; i < list->num_widgets; i++) { | ||
841 | if (widget == list->widgets[i]) | ||
842 | return 1; | ||
843 | } | ||
844 | |||
845 | return 0; | ||
846 | } | ||
847 | |||
848 | static int dpcm_path_get(struct snd_soc_pcm_runtime *fe, | ||
849 | int stream, struct snd_soc_dapm_widget_list **list_) | ||
850 | { | ||
851 | struct snd_soc_dai *cpu_dai = fe->cpu_dai; | ||
852 | struct snd_soc_dapm_widget_list *list; | ||
853 | int paths; | ||
854 | |||
855 | list = kzalloc(sizeof(struct snd_soc_dapm_widget_list) + | ||
856 | sizeof(struct snd_soc_dapm_widget *), GFP_KERNEL); | ||
857 | if (list == NULL) | ||
858 | return -ENOMEM; | ||
859 | |||
860 | /* get number of valid DAI paths and their widgets */ | ||
861 | paths = snd_soc_dapm_dai_get_connected_widgets(cpu_dai, stream, &list); | ||
862 | |||
863 | dev_dbg(fe->dev, "found %d audio %s paths\n", paths, | ||
864 | stream ? "capture" : "playback"); | ||
865 | |||
866 | *list_ = list; | ||
867 | return paths; | ||
868 | } | ||
869 | |||
870 | static inline void dpcm_path_put(struct snd_soc_dapm_widget_list **list) | ||
871 | { | ||
872 | kfree(*list); | ||
873 | } | ||
874 | |||
875 | static int dpcm_prune_paths(struct snd_soc_pcm_runtime *fe, int stream, | ||
876 | struct snd_soc_dapm_widget_list **list_) | ||
877 | { | ||
878 | struct snd_soc_dpcm *dpcm; | ||
879 | struct snd_soc_dapm_widget_list *list = *list_; | ||
880 | struct snd_soc_dapm_widget *widget; | ||
881 | int prune = 0; | ||
882 | |||
883 | /* Destroy any old FE <--> BE connections */ | ||
884 | list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) { | ||
885 | |||
886 | /* is there a valid CPU DAI widget for this BE */ | ||
887 | widget = rtd_get_cpu_widget(dpcm->be, stream); | ||
888 | |||
889 | /* prune the BE if it's no longer in our active list */ | ||
890 | if (widget && widget_in_list(list, widget)) | ||
891 | continue; | ||
892 | |||
893 | /* is there a valid CODEC DAI widget for this BE */ | ||
894 | widget = rtd_get_codec_widget(dpcm->be, stream); | ||
895 | |||
896 | /* prune the BE if it's no longer in our active list */ | ||
897 | if (widget && widget_in_list(list, widget)) | ||
898 | continue; | ||
899 | |||
900 | dev_dbg(fe->dev, "pruning %s BE %s for %s\n", | ||
901 | stream ? "capture" : "playback", | ||
902 | dpcm->be->dai_link->name, fe->dai_link->name); | ||
903 | dpcm->state = SND_SOC_DPCM_LINK_STATE_FREE; | ||
904 | dpcm->be->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_BE; | ||
905 | prune++; | ||
906 | } | ||
907 | |||
908 | dev_dbg(fe->dev, "found %d old BE paths for pruning\n", prune); | ||
909 | return prune; | ||
910 | } | ||
911 | |||
912 | static int dpcm_add_paths(struct snd_soc_pcm_runtime *fe, int stream, | ||
913 | struct snd_soc_dapm_widget_list **list_) | ||
914 | { | ||
915 | struct snd_soc_card *card = fe->card; | ||
916 | struct snd_soc_dapm_widget_list *list = *list_; | ||
917 | struct snd_soc_pcm_runtime *be; | ||
918 | int i, new = 0, err; | ||
919 | |||
920 | /* Create any new FE <--> BE connections */ | ||
921 | for (i = 0; i < list->num_widgets; i++) { | ||
922 | |||
923 | if (list->widgets[i]->id != snd_soc_dapm_dai) | ||
924 | continue; | ||
925 | |||
926 | /* is there a valid BE rtd for this widget */ | ||
927 | be = dpcm_get_be(card, list->widgets[i], stream); | ||
928 | if (!be) { | ||
929 | dev_err(fe->dev, "no BE found for %s\n", | ||
930 | list->widgets[i]->name); | ||
931 | continue; | ||
932 | } | ||
933 | |||
934 | /* make sure BE is a real BE */ | ||
935 | if (!be->dai_link->no_pcm) | ||
936 | continue; | ||
937 | |||
938 | /* don't connect if FE is not running */ | ||
939 | if (!fe->dpcm[stream].runtime) | ||
940 | continue; | ||
941 | |||
942 | /* newly connected FE and BE */ | ||
943 | err = dpcm_be_connect(fe, be, stream); | ||
944 | if (err < 0) { | ||
945 | dev_err(fe->dev, "can't connect %s\n", | ||
946 | list->widgets[i]->name); | ||
947 | break; | ||
948 | } else if (err == 0) /* already connected */ | ||
949 | continue; | ||
950 | |||
951 | /* new */ | ||
952 | be->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_BE; | ||
953 | new++; | ||
954 | } | ||
955 | |||
956 | dev_dbg(fe->dev, "found %d new BE paths\n", new); | ||
957 | return new; | ||
958 | } | ||
959 | |||
960 | /* | ||
961 | * Find the corresponding BE DAIs that source or sink audio to this | ||
962 | * FE substream. | ||
963 | */ | ||
964 | static int dpcm_process_paths(struct snd_soc_pcm_runtime *fe, | ||
965 | int stream, struct snd_soc_dapm_widget_list **list, int new) | ||
966 | { | ||
967 | if (new) | ||
968 | return dpcm_add_paths(fe, stream, list); | ||
969 | else | ||
970 | return dpcm_prune_paths(fe, stream, list); | ||
971 | } | ||
972 | |||
973 | static void dpcm_clear_pending_state(struct snd_soc_pcm_runtime *fe, int stream) | ||
974 | { | ||
975 | struct snd_soc_dpcm *dpcm; | ||
976 | |||
977 | list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) | ||
978 | dpcm->be->dpcm[stream].runtime_update = | ||
979 | SND_SOC_DPCM_UPDATE_NO; | ||
980 | } | ||
981 | |||
982 | static void dpcm_be_dai_startup_unwind(struct snd_soc_pcm_runtime *fe, | ||
983 | int stream) | ||
984 | { | ||
985 | struct snd_soc_dpcm *dpcm; | ||
986 | |||
987 | /* disable any enabled and non active backends */ | ||
988 | list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) { | ||
989 | |||
990 | struct snd_soc_pcm_runtime *be = dpcm->be; | ||
991 | struct snd_pcm_substream *be_substream = | ||
992 | snd_soc_dpcm_get_substream(be, stream); | ||
993 | |||
994 | if (be->dpcm[stream].users == 0) | ||
995 | dev_err(be->dev, "no users %s at close - state %d\n", | ||
996 | stream ? "capture" : "playback", | ||
997 | be->dpcm[stream].state); | ||
998 | |||
999 | if (--be->dpcm[stream].users != 0) | ||
1000 | continue; | ||
1001 | |||
1002 | if (be->dpcm[stream].state != SND_SOC_DPCM_STATE_OPEN) | ||
1003 | continue; | ||
1004 | |||
1005 | soc_pcm_close(be_substream); | ||
1006 | be_substream->runtime = NULL; | ||
1007 | be->dpcm[stream].state = SND_SOC_DPCM_STATE_CLOSE; | ||
1008 | } | ||
1009 | } | ||
1010 | |||
1011 | static int dpcm_be_dai_startup(struct snd_soc_pcm_runtime *fe, int stream) | ||
1012 | { | ||
1013 | struct snd_soc_dpcm *dpcm; | ||
1014 | int err, count = 0; | ||
1015 | |||
1016 | /* only startup BE DAIs that are either sinks or sources to this FE DAI */ | ||
1017 | list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) { | ||
1018 | |||
1019 | struct snd_soc_pcm_runtime *be = dpcm->be; | ||
1020 | struct snd_pcm_substream *be_substream = | ||
1021 | snd_soc_dpcm_get_substream(be, stream); | ||
1022 | |||
1023 | /* is this op for this BE ? */ | ||
1024 | if (!snd_soc_dpcm_be_can_update(fe, be, stream)) | ||
1025 | continue; | ||
1026 | |||
1027 | /* first time the dpcm is open ? */ | ||
1028 | if (be->dpcm[stream].users == DPCM_MAX_BE_USERS) | ||
1029 | dev_err(be->dev, "too many users %s at open %d\n", | ||
1030 | stream ? "capture" : "playback", | ||
1031 | be->dpcm[stream].state); | ||
1032 | |||
1033 | if (be->dpcm[stream].users++ != 0) | ||
1034 | continue; | ||
1035 | |||
1036 | if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_NEW) && | ||
1037 | (be->dpcm[stream].state != SND_SOC_DPCM_STATE_CLOSE)) | ||
1038 | continue; | ||
1039 | |||
1040 | dev_dbg(be->dev, "dpcm: open BE %s\n", be->dai_link->name); | ||
1041 | |||
1042 | be_substream->runtime = be->dpcm[stream].runtime; | ||
1043 | err = soc_pcm_open(be_substream); | ||
1044 | if (err < 0) { | ||
1045 | dev_err(be->dev, "BE open failed %d\n", err); | ||
1046 | be->dpcm[stream].users--; | ||
1047 | if (be->dpcm[stream].users < 0) | ||
1048 | dev_err(be->dev, "no users %s at unwind %d\n", | ||
1049 | stream ? "capture" : "playback", | ||
1050 | be->dpcm[stream].state); | ||
1051 | |||
1052 | be->dpcm[stream].state = SND_SOC_DPCM_STATE_CLOSE; | ||
1053 | goto unwind; | ||
1054 | } | ||
1055 | |||
1056 | be->dpcm[stream].state = SND_SOC_DPCM_STATE_OPEN; | ||
1057 | count++; | ||
1058 | } | ||
1059 | |||
1060 | return count; | ||
1061 | |||
1062 | unwind: | ||
1063 | /* disable any enabled and non active backends */ | ||
1064 | list_for_each_entry_continue_reverse(dpcm, &fe->dpcm[stream].be_clients, list_be) { | ||
1065 | struct snd_soc_pcm_runtime *be = dpcm->be; | ||
1066 | struct snd_pcm_substream *be_substream = | ||
1067 | snd_soc_dpcm_get_substream(be, stream); | ||
1068 | |||
1069 | if (!snd_soc_dpcm_be_can_update(fe, be, stream)) | ||
1070 | continue; | ||
1071 | |||
1072 | if (be->dpcm[stream].users == 0) | ||
1073 | dev_err(be->dev, "no users %s at close %d\n", | ||
1074 | stream ? "capture" : "playback", | ||
1075 | be->dpcm[stream].state); | ||
1076 | |||
1077 | if (--be->dpcm[stream].users != 0) | ||
1078 | continue; | ||
1079 | |||
1080 | if (be->dpcm[stream].state != SND_SOC_DPCM_STATE_OPEN) | ||
1081 | continue; | ||
1082 | |||
1083 | soc_pcm_close(be_substream); | ||
1084 | be_substream->runtime = NULL; | ||
1085 | be->dpcm[stream].state = SND_SOC_DPCM_STATE_CLOSE; | ||
1086 | } | ||
1087 | |||
1088 | return err; | ||
1089 | } | ||
1090 | |||
1091 | static void dpcm_set_fe_runtime(struct snd_pcm_substream *substream) | ||
1092 | { | ||
1093 | struct snd_pcm_runtime *runtime = substream->runtime; | ||
1094 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
1095 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; | ||
1096 | struct snd_soc_dai_driver *cpu_dai_drv = cpu_dai->driver; | ||
1097 | |||
1098 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { | ||
1099 | runtime->hw.rate_min = cpu_dai_drv->playback.rate_min; | ||
1100 | runtime->hw.rate_max = cpu_dai_drv->playback.rate_max; | ||
1101 | runtime->hw.channels_min = cpu_dai_drv->playback.channels_min; | ||
1102 | runtime->hw.channels_max = cpu_dai_drv->playback.channels_max; | ||
1103 | runtime->hw.formats &= cpu_dai_drv->playback.formats; | ||
1104 | runtime->hw.rates = cpu_dai_drv->playback.rates; | ||
1105 | } else { | ||
1106 | runtime->hw.rate_min = cpu_dai_drv->capture.rate_min; | ||
1107 | runtime->hw.rate_max = cpu_dai_drv->capture.rate_max; | ||
1108 | runtime->hw.channels_min = cpu_dai_drv->capture.channels_min; | ||
1109 | runtime->hw.channels_max = cpu_dai_drv->capture.channels_max; | ||
1110 | runtime->hw.formats &= cpu_dai_drv->capture.formats; | ||
1111 | runtime->hw.rates = cpu_dai_drv->capture.rates; | ||
1112 | } | ||
1113 | } | ||
1114 | |||
1115 | static int dpcm_fe_dai_startup(struct snd_pcm_substream *fe_substream) | ||
1116 | { | ||
1117 | struct snd_soc_pcm_runtime *fe = fe_substream->private_data; | ||
1118 | struct snd_pcm_runtime *runtime = fe_substream->runtime; | ||
1119 | int stream = fe_substream->stream, ret = 0; | ||
1120 | |||
1121 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE; | ||
1122 | |||
1123 | ret = dpcm_be_dai_startup(fe, fe_substream->stream); | ||
1124 | if (ret < 0) { | ||
1125 | dev_err(fe->dev,"dpcm: failed to start some BEs %d\n", ret); | ||
1126 | goto be_err; | ||
1127 | } | ||
1128 | |||
1129 | dev_dbg(fe->dev, "dpcm: open FE %s\n", fe->dai_link->name); | ||
1130 | |||
1131 | /* start the DAI frontend */ | ||
1132 | ret = soc_pcm_open(fe_substream); | ||
1133 | if (ret < 0) { | ||
1134 | dev_err(fe->dev,"dpcm: failed to start FE %d\n", ret); | ||
1135 | goto unwind; | ||
1136 | } | ||
1137 | |||
1138 | fe->dpcm[stream].state = SND_SOC_DPCM_STATE_OPEN; | ||
1139 | |||
1140 | dpcm_set_fe_runtime(fe_substream); | ||
1141 | snd_pcm_limit_hw_rates(runtime); | ||
1142 | |||
1143 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO; | ||
1144 | return 0; | ||
1145 | |||
1146 | unwind: | ||
1147 | dpcm_be_dai_startup_unwind(fe, fe_substream->stream); | ||
1148 | be_err: | ||
1149 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO; | ||
1150 | return ret; | ||
1151 | } | ||
1152 | |||
1153 | static int dpcm_be_dai_shutdown(struct snd_soc_pcm_runtime *fe, int stream) | ||
1154 | { | ||
1155 | struct snd_soc_dpcm *dpcm; | ||
1156 | |||
1157 | /* only shutdown BEs that are either sinks or sources to this FE DAI */ | ||
1158 | list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) { | ||
1159 | |||
1160 | struct snd_soc_pcm_runtime *be = dpcm->be; | ||
1161 | struct snd_pcm_substream *be_substream = | ||
1162 | snd_soc_dpcm_get_substream(be, stream); | ||
1163 | |||
1164 | /* is this op for this BE ? */ | ||
1165 | if (!snd_soc_dpcm_be_can_update(fe, be, stream)) | ||
1166 | continue; | ||
1167 | |||
1168 | if (be->dpcm[stream].users == 0) | ||
1169 | dev_err(be->dev, "no users %s at close - state %d\n", | ||
1170 | stream ? "capture" : "playback", | ||
1171 | be->dpcm[stream].state); | ||
1172 | |||
1173 | if (--be->dpcm[stream].users != 0) | ||
1174 | continue; | ||
1175 | |||
1176 | if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_FREE) && | ||
1177 | (be->dpcm[stream].state != SND_SOC_DPCM_STATE_OPEN)) | ||
1178 | continue; | ||
1179 | |||
1180 | dev_dbg(be->dev, "dpcm: close BE %s\n", | ||
1181 | dpcm->fe->dai_link->name); | ||
1182 | |||
1183 | soc_pcm_close(be_substream); | ||
1184 | be_substream->runtime = NULL; | ||
1185 | |||
1186 | be->dpcm[stream].state = SND_SOC_DPCM_STATE_CLOSE; | ||
1187 | } | ||
1188 | return 0; | ||
1189 | } | ||
1190 | |||
1191 | static int dpcm_fe_dai_shutdown(struct snd_pcm_substream *substream) | ||
1192 | { | ||
1193 | struct snd_soc_pcm_runtime *fe = substream->private_data; | ||
1194 | int stream = substream->stream; | ||
1195 | |||
1196 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE; | ||
1197 | |||
1198 | /* shutdown the BEs */ | ||
1199 | dpcm_be_dai_shutdown(fe, substream->stream); | ||
1200 | |||
1201 | dev_dbg(fe->dev, "dpcm: close FE %s\n", fe->dai_link->name); | ||
1202 | |||
1203 | /* now shutdown the frontend */ | ||
1204 | soc_pcm_close(substream); | ||
1205 | |||
1206 | /* run the stream event for each BE */ | ||
1207 | dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_STOP); | ||
1208 | |||
1209 | fe->dpcm[stream].state = SND_SOC_DPCM_STATE_CLOSE; | ||
1210 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO; | ||
1211 | return 0; | ||
1212 | } | ||
1213 | |||
1214 | static int dpcm_be_dai_hw_free(struct snd_soc_pcm_runtime *fe, int stream) | ||
1215 | { | ||
1216 | struct snd_soc_dpcm *dpcm; | ||
1217 | |||
1218 | /* only hw_params backends that are either sinks or sources | ||
1219 | * to this frontend DAI */ | ||
1220 | list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) { | ||
1221 | |||
1222 | struct snd_soc_pcm_runtime *be = dpcm->be; | ||
1223 | struct snd_pcm_substream *be_substream = | ||
1224 | snd_soc_dpcm_get_substream(be, stream); | ||
1225 | |||
1226 | /* is this op for this BE ? */ | ||
1227 | if (!snd_soc_dpcm_be_can_update(fe, be, stream)) | ||
1228 | continue; | ||
1229 | |||
1230 | /* only free hw when no longer used - check all FEs */ | ||
1231 | if (!snd_soc_dpcm_can_be_free_stop(fe, be, stream)) | ||
1232 | continue; | ||
1233 | |||
1234 | if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_PARAMS) && | ||
1235 | (be->dpcm[stream].state != SND_SOC_DPCM_STATE_PREPARE) && | ||
1236 | (be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_FREE) && | ||
1237 | (be->dpcm[stream].state != SND_SOC_DPCM_STATE_STOP)) | ||
1238 | continue; | ||
1239 | |||
1240 | dev_dbg(be->dev, "dpcm: hw_free BE %s\n", | ||
1241 | dpcm->fe->dai_link->name); | ||
1242 | |||
1243 | soc_pcm_hw_free(be_substream); | ||
1244 | |||
1245 | be->dpcm[stream].state = SND_SOC_DPCM_STATE_HW_FREE; | ||
1246 | } | ||
1247 | |||
1248 | return 0; | ||
1249 | } | ||
1250 | |||
1251 | static int dpcm_fe_dai_hw_free(struct snd_pcm_substream *substream) | ||
1252 | { | ||
1253 | struct snd_soc_pcm_runtime *fe = substream->private_data; | ||
1254 | int err, stream = substream->stream; | ||
1255 | |||
1256 | mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME); | ||
1257 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE; | ||
1258 | |||
1259 | dev_dbg(fe->dev, "dpcm: hw_free FE %s\n", fe->dai_link->name); | ||
1260 | |||
1261 | /* call hw_free on the frontend */ | ||
1262 | err = soc_pcm_hw_free(substream); | ||
1263 | if (err < 0) | ||
1264 | dev_err(fe->dev,"dpcm: hw_free FE %s failed\n", | ||
1265 | fe->dai_link->name); | ||
1266 | |||
1267 | /* only hw_params backends that are either sinks or sources | ||
1268 | * to this frontend DAI */ | ||
1269 | err = dpcm_be_dai_hw_free(fe, stream); | ||
1270 | |||
1271 | fe->dpcm[stream].state = SND_SOC_DPCM_STATE_HW_FREE; | ||
1272 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO; | ||
1273 | |||
1274 | mutex_unlock(&fe->card->mutex); | ||
1275 | return 0; | ||
1276 | } | ||
1277 | |||
1278 | static int dpcm_be_dai_hw_params(struct snd_soc_pcm_runtime *fe, int stream) | ||
1279 | { | ||
1280 | struct snd_soc_dpcm *dpcm; | ||
1281 | int ret; | ||
1282 | |||
1283 | list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) { | ||
1284 | |||
1285 | struct snd_soc_pcm_runtime *be = dpcm->be; | ||
1286 | struct snd_pcm_substream *be_substream = | ||
1287 | snd_soc_dpcm_get_substream(be, stream); | ||
1288 | |||
1289 | /* is this op for this BE ? */ | ||
1290 | if (!snd_soc_dpcm_be_can_update(fe, be, stream)) | ||
1291 | continue; | ||
1292 | |||
1293 | /* only allow hw_params() if no connected FEs are running */ | ||
1294 | if (!snd_soc_dpcm_can_be_params(fe, be, stream)) | ||
1295 | continue; | ||
1296 | |||
1297 | if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_OPEN) && | ||
1298 | (be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_PARAMS) && | ||
1299 | (be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_FREE)) | ||
1300 | continue; | ||
1301 | |||
1302 | dev_dbg(be->dev, "dpcm: hw_params BE %s\n", | ||
1303 | dpcm->fe->dai_link->name); | ||
1304 | |||
1305 | /* copy params for each dpcm */ | ||
1306 | memcpy(&dpcm->hw_params, &fe->dpcm[stream].hw_params, | ||
1307 | sizeof(struct snd_pcm_hw_params)); | ||
1308 | |||
1309 | /* perform any hw_params fixups */ | ||
1310 | if (be->dai_link->be_hw_params_fixup) { | ||
1311 | ret = be->dai_link->be_hw_params_fixup(be, | ||
1312 | &dpcm->hw_params); | ||
1313 | if (ret < 0) { | ||
1314 | dev_err(be->dev, | ||
1315 | "dpcm: hw_params BE fixup failed %d\n", | ||
1316 | ret); | ||
1317 | goto unwind; | ||
1318 | } | ||
1319 | } | ||
1320 | |||
1321 | ret = soc_pcm_hw_params(be_substream, &dpcm->hw_params); | ||
1322 | if (ret < 0) { | ||
1323 | dev_err(dpcm->be->dev, | ||
1324 | "dpcm: hw_params BE failed %d\n", ret); | ||
1325 | goto unwind; | ||
1326 | } | ||
1327 | |||
1328 | be->dpcm[stream].state = SND_SOC_DPCM_STATE_HW_PARAMS; | ||
1329 | } | ||
1330 | return 0; | ||
1331 | |||
1332 | unwind: | ||
1333 | /* disable any enabled and non active backends */ | ||
1334 | list_for_each_entry_continue_reverse(dpcm, &fe->dpcm[stream].be_clients, list_be) { | ||
1335 | struct snd_soc_pcm_runtime *be = dpcm->be; | ||
1336 | struct snd_pcm_substream *be_substream = | ||
1337 | snd_soc_dpcm_get_substream(be, stream); | ||
1338 | |||
1339 | if (!snd_soc_dpcm_be_can_update(fe, be, stream)) | ||
1340 | continue; | ||
1341 | |||
1342 | /* only allow hw_free() if no connected FEs are running */ | ||
1343 | if (!snd_soc_dpcm_can_be_free_stop(fe, be, stream)) | ||
1344 | continue; | ||
1345 | |||
1346 | if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_OPEN) && | ||
1347 | (be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_PARAMS) && | ||
1348 | (be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_FREE) && | ||
1349 | (be->dpcm[stream].state != SND_SOC_DPCM_STATE_STOP)) | ||
1350 | continue; | ||
1351 | |||
1352 | soc_pcm_hw_free(be_substream); | ||
1353 | } | ||
1354 | |||
1355 | return ret; | ||
1356 | } | ||
1357 | |||
1358 | static int dpcm_fe_dai_hw_params(struct snd_pcm_substream *substream, | ||
1359 | struct snd_pcm_hw_params *params) | ||
1360 | { | ||
1361 | struct snd_soc_pcm_runtime *fe = substream->private_data; | ||
1362 | int ret, stream = substream->stream; | ||
1363 | |||
1364 | mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME); | ||
1365 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE; | ||
1366 | |||
1367 | memcpy(&fe->dpcm[substream->stream].hw_params, params, | ||
1368 | sizeof(struct snd_pcm_hw_params)); | ||
1369 | ret = dpcm_be_dai_hw_params(fe, substream->stream); | ||
1370 | if (ret < 0) { | ||
1371 | dev_err(fe->dev,"dpcm: hw_params BE failed %d\n", ret); | ||
1372 | goto out; | ||
1373 | } | ||
1374 | |||
1375 | dev_dbg(fe->dev, "dpcm: hw_params FE %s rate %d chan %x fmt %d\n", | ||
1376 | fe->dai_link->name, params_rate(params), | ||
1377 | params_channels(params), params_format(params)); | ||
1378 | |||
1379 | /* call hw_params on the frontend */ | ||
1380 | ret = soc_pcm_hw_params(substream, params); | ||
1381 | if (ret < 0) { | ||
1382 | dev_err(fe->dev,"dpcm: hw_params FE failed %d\n", ret); | ||
1383 | dpcm_be_dai_hw_free(fe, stream); | ||
1384 | } else | ||
1385 | fe->dpcm[stream].state = SND_SOC_DPCM_STATE_HW_PARAMS; | ||
1386 | |||
1387 | out: | ||
1388 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO; | ||
1389 | mutex_unlock(&fe->card->mutex); | ||
1390 | return ret; | ||
1391 | } | ||
1392 | |||
1393 | static int dpcm_do_trigger(struct snd_soc_dpcm *dpcm, | ||
1394 | struct snd_pcm_substream *substream, int cmd) | ||
1395 | { | ||
1396 | int ret; | ||
1397 | |||
1398 | dev_dbg(dpcm->be->dev, "dpcm: trigger BE %s cmd %d\n", | ||
1399 | dpcm->fe->dai_link->name, cmd); | ||
1400 | |||
1401 | ret = soc_pcm_trigger(substream, cmd); | ||
1402 | if (ret < 0) | ||
1403 | dev_err(dpcm->be->dev,"dpcm: trigger BE failed %d\n", ret); | ||
1404 | |||
1405 | return ret; | ||
1406 | } | ||
1407 | |||
1408 | static int dpcm_be_dai_trigger(struct snd_soc_pcm_runtime *fe, int stream, | ||
1409 | int cmd) | ||
1410 | { | ||
1411 | struct snd_soc_dpcm *dpcm; | ||
1412 | int ret = 0; | ||
1413 | |||
1414 | list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) { | ||
1415 | |||
1416 | struct snd_soc_pcm_runtime *be = dpcm->be; | ||
1417 | struct snd_pcm_substream *be_substream = | ||
1418 | snd_soc_dpcm_get_substream(be, stream); | ||
1419 | |||
1420 | /* is this op for this BE ? */ | ||
1421 | if (!snd_soc_dpcm_be_can_update(fe, be, stream)) | ||
1422 | continue; | ||
1423 | |||
1424 | switch (cmd) { | ||
1425 | case SNDRV_PCM_TRIGGER_START: | ||
1426 | if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_PREPARE) && | ||
1427 | (be->dpcm[stream].state != SND_SOC_DPCM_STATE_STOP)) | ||
1428 | continue; | ||
1429 | |||
1430 | ret = dpcm_do_trigger(dpcm, be_substream, cmd); | ||
1431 | if (ret) | ||
1432 | return ret; | ||
1433 | |||
1434 | be->dpcm[stream].state = SND_SOC_DPCM_STATE_START; | ||
1435 | break; | ||
1436 | case SNDRV_PCM_TRIGGER_RESUME: | ||
1437 | if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_SUSPEND)) | ||
1438 | continue; | ||
1439 | |||
1440 | ret = dpcm_do_trigger(dpcm, be_substream, cmd); | ||
1441 | if (ret) | ||
1442 | return ret; | ||
1443 | |||
1444 | be->dpcm[stream].state = SND_SOC_DPCM_STATE_START; | ||
1445 | break; | ||
1446 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: | ||
1447 | if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_PAUSED)) | ||
1448 | continue; | ||
1449 | |||
1450 | ret = dpcm_do_trigger(dpcm, be_substream, cmd); | ||
1451 | if (ret) | ||
1452 | return ret; | ||
1453 | |||
1454 | be->dpcm[stream].state = SND_SOC_DPCM_STATE_START; | ||
1455 | break; | ||
1456 | case SNDRV_PCM_TRIGGER_STOP: | ||
1457 | if (be->dpcm[stream].state != SND_SOC_DPCM_STATE_START) | ||
1458 | continue; | ||
1459 | |||
1460 | if (!snd_soc_dpcm_can_be_free_stop(fe, be, stream)) | ||
1461 | continue; | ||
1462 | |||
1463 | ret = dpcm_do_trigger(dpcm, be_substream, cmd); | ||
1464 | if (ret) | ||
1465 | return ret; | ||
1466 | |||
1467 | be->dpcm[stream].state = SND_SOC_DPCM_STATE_STOP; | ||
1468 | break; | ||
1469 | case SNDRV_PCM_TRIGGER_SUSPEND: | ||
1470 | if (be->dpcm[stream].state != SND_SOC_DPCM_STATE_STOP) | ||
1471 | continue; | ||
1472 | |||
1473 | if (!snd_soc_dpcm_can_be_free_stop(fe, be, stream)) | ||
1474 | continue; | ||
1475 | |||
1476 | ret = dpcm_do_trigger(dpcm, be_substream, cmd); | ||
1477 | if (ret) | ||
1478 | return ret; | ||
1479 | |||
1480 | be->dpcm[stream].state = SND_SOC_DPCM_STATE_SUSPEND; | ||
1481 | break; | ||
1482 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: | ||
1483 | if (be->dpcm[stream].state != SND_SOC_DPCM_STATE_START) | ||
1484 | continue; | ||
1485 | |||
1486 | if (!snd_soc_dpcm_can_be_free_stop(fe, be, stream)) | ||
1487 | continue; | ||
1488 | |||
1489 | ret = dpcm_do_trigger(dpcm, be_substream, cmd); | ||
1490 | if (ret) | ||
1491 | return ret; | ||
1492 | |||
1493 | be->dpcm[stream].state = SND_SOC_DPCM_STATE_PAUSED; | ||
1494 | break; | ||
1495 | } | ||
1496 | } | ||
1497 | |||
1498 | return ret; | ||
1499 | } | ||
1500 | EXPORT_SYMBOL_GPL(dpcm_be_dai_trigger); | ||
1501 | |||
1502 | static int dpcm_fe_dai_trigger(struct snd_pcm_substream *substream, int cmd) | ||
1503 | { | ||
1504 | struct snd_soc_pcm_runtime *fe = substream->private_data; | ||
1505 | int stream = substream->stream, ret; | ||
1506 | enum snd_soc_dpcm_trigger trigger = fe->dai_link->trigger[stream]; | ||
1507 | |||
1508 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE; | ||
1509 | |||
1510 | switch (trigger) { | ||
1511 | case SND_SOC_DPCM_TRIGGER_PRE: | ||
1512 | /* call trigger on the frontend before the backend. */ | ||
1513 | |||
1514 | dev_dbg(fe->dev, "dpcm: pre trigger FE %s cmd %d\n", | ||
1515 | fe->dai_link->name, cmd); | ||
1516 | |||
1517 | ret = soc_pcm_trigger(substream, cmd); | ||
1518 | if (ret < 0) { | ||
1519 | dev_err(fe->dev,"dpcm: trigger FE failed %d\n", ret); | ||
1520 | goto out; | ||
1521 | } | ||
1522 | |||
1523 | ret = dpcm_be_dai_trigger(fe, substream->stream, cmd); | ||
1524 | break; | ||
1525 | case SND_SOC_DPCM_TRIGGER_POST: | ||
1526 | /* call trigger on the frontend after the backend. */ | ||
1527 | |||
1528 | ret = dpcm_be_dai_trigger(fe, substream->stream, cmd); | ||
1529 | if (ret < 0) { | ||
1530 | dev_err(fe->dev,"dpcm: trigger FE failed %d\n", ret); | ||
1531 | goto out; | ||
1532 | } | ||
1533 | |||
1534 | dev_dbg(fe->dev, "dpcm: post trigger FE %s cmd %d\n", | ||
1535 | fe->dai_link->name, cmd); | ||
1536 | |||
1537 | ret = soc_pcm_trigger(substream, cmd); | ||
1538 | break; | ||
1539 | case SND_SOC_DPCM_TRIGGER_BESPOKE: | ||
1540 | /* bespoke trigger() - handles both FE and BEs */ | ||
1541 | |||
1542 | dev_dbg(fe->dev, "dpcm: bespoke trigger FE %s cmd %d\n", | ||
1543 | fe->dai_link->name, cmd); | ||
1544 | |||
1545 | ret = soc_pcm_bespoke_trigger(substream, cmd); | ||
1546 | if (ret < 0) { | ||
1547 | dev_err(fe->dev,"dpcm: trigger FE failed %d\n", ret); | ||
1548 | goto out; | ||
1549 | } | ||
1550 | break; | ||
1551 | default: | ||
1552 | dev_err(fe->dev, "dpcm: invalid trigger cmd %d for %s\n", cmd, | ||
1553 | fe->dai_link->name); | ||
1554 | ret = -EINVAL; | ||
1555 | goto out; | ||
1556 | } | ||
1557 | |||
1558 | switch (cmd) { | ||
1559 | case SNDRV_PCM_TRIGGER_START: | ||
1560 | case SNDRV_PCM_TRIGGER_RESUME: | ||
1561 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: | ||
1562 | fe->dpcm[stream].state = SND_SOC_DPCM_STATE_START; | ||
1563 | break; | ||
1564 | case SNDRV_PCM_TRIGGER_STOP: | ||
1565 | case SNDRV_PCM_TRIGGER_SUSPEND: | ||
1566 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: | ||
1567 | fe->dpcm[stream].state = SND_SOC_DPCM_STATE_STOP; | ||
1568 | break; | ||
1569 | } | ||
1570 | |||
1571 | out: | ||
1572 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO; | ||
1573 | return ret; | ||
1574 | } | ||
1575 | |||
1576 | static int dpcm_be_dai_prepare(struct snd_soc_pcm_runtime *fe, int stream) | ||
1577 | { | ||
1578 | struct snd_soc_dpcm *dpcm; | ||
1579 | int ret = 0; | ||
1580 | |||
1581 | list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) { | ||
1582 | |||
1583 | struct snd_soc_pcm_runtime *be = dpcm->be; | ||
1584 | struct snd_pcm_substream *be_substream = | ||
1585 | snd_soc_dpcm_get_substream(be, stream); | ||
1586 | |||
1587 | /* is this op for this BE ? */ | ||
1588 | if (!snd_soc_dpcm_be_can_update(fe, be, stream)) | ||
1589 | continue; | ||
1590 | |||
1591 | if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_PARAMS) && | ||
1592 | (be->dpcm[stream].state != SND_SOC_DPCM_STATE_STOP)) | ||
1593 | continue; | ||
1594 | |||
1595 | dev_dbg(be->dev, "dpcm: prepare BE %s\n", | ||
1596 | dpcm->fe->dai_link->name); | ||
1597 | |||
1598 | ret = soc_pcm_prepare(be_substream); | ||
1599 | if (ret < 0) { | ||
1600 | dev_err(be->dev, "dpcm: backend prepare failed %d\n", | ||
1601 | ret); | ||
1602 | break; | ||
1603 | } | ||
1604 | |||
1605 | be->dpcm[stream].state = SND_SOC_DPCM_STATE_PREPARE; | ||
1606 | } | ||
1607 | return ret; | ||
1608 | } | ||
1609 | |||
1610 | static int dpcm_fe_dai_prepare(struct snd_pcm_substream *substream) | ||
1611 | { | ||
1612 | struct snd_soc_pcm_runtime *fe = substream->private_data; | ||
1613 | int stream = substream->stream, ret = 0; | ||
1614 | |||
1615 | mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME); | ||
1616 | |||
1617 | dev_dbg(fe->dev, "dpcm: prepare FE %s\n", fe->dai_link->name); | ||
1618 | |||
1619 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE; | ||
1620 | |||
1621 | /* there is no point preparing this FE if there are no BEs */ | ||
1622 | if (list_empty(&fe->dpcm[stream].be_clients)) { | ||
1623 | dev_err(fe->dev, "dpcm: no backend DAIs enabled for %s\n", | ||
1624 | fe->dai_link->name); | ||
1625 | ret = -EINVAL; | ||
1626 | goto out; | ||
1627 | } | ||
1628 | |||
1629 | ret = dpcm_be_dai_prepare(fe, substream->stream); | ||
1630 | if (ret < 0) | ||
1631 | goto out; | ||
1632 | |||
1633 | /* call prepare on the frontend */ | ||
1634 | ret = soc_pcm_prepare(substream); | ||
1635 | if (ret < 0) { | ||
1636 | dev_err(fe->dev,"dpcm: prepare FE %s failed\n", | ||
1637 | fe->dai_link->name); | ||
1638 | goto out; | ||
1639 | } | ||
1640 | |||
1641 | /* run the stream event for each BE */ | ||
1642 | dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_START); | ||
1643 | fe->dpcm[stream].state = SND_SOC_DPCM_STATE_PREPARE; | ||
1644 | |||
1645 | out: | ||
1646 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO; | ||
1647 | mutex_unlock(&fe->card->mutex); | ||
1648 | |||
1649 | return ret; | ||
1650 | } | ||
1651 | |||
1652 | static int soc_pcm_ioctl(struct snd_pcm_substream *substream, | ||
1653 | unsigned int cmd, void *arg) | ||
1654 | { | ||
1655 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
1656 | struct snd_soc_platform *platform = rtd->platform; | ||
1657 | |||
1658 | if (platform->driver->ops->ioctl) | ||
1659 | return platform->driver->ops->ioctl(substream, cmd, arg); | ||
1660 | return snd_pcm_lib_ioctl(substream, cmd, arg); | ||
1661 | } | ||
1662 | |||
1663 | static int dpcm_run_update_shutdown(struct snd_soc_pcm_runtime *fe, int stream) | ||
1664 | { | ||
1665 | struct snd_pcm_substream *substream = | ||
1666 | snd_soc_dpcm_get_substream(fe, stream); | ||
1667 | enum snd_soc_dpcm_trigger trigger = fe->dai_link->trigger[stream]; | ||
1668 | int err; | ||
1669 | |||
1670 | dev_dbg(fe->dev, "runtime %s close on FE %s\n", | ||
1671 | stream ? "capture" : "playback", fe->dai_link->name); | ||
1672 | |||
1673 | if (trigger == SND_SOC_DPCM_TRIGGER_BESPOKE) { | ||
1674 | /* call bespoke trigger - FE takes care of all BE triggers */ | ||
1675 | dev_dbg(fe->dev, "dpcm: bespoke trigger FE %s cmd stop\n", | ||
1676 | fe->dai_link->name); | ||
1677 | |||
1678 | err = soc_pcm_bespoke_trigger(substream, SNDRV_PCM_TRIGGER_STOP); | ||
1679 | if (err < 0) | ||
1680 | dev_err(fe->dev,"dpcm: trigger FE failed %d\n", err); | ||
1681 | } else { | ||
1682 | dev_dbg(fe->dev, "dpcm: trigger FE %s cmd stop\n", | ||
1683 | fe->dai_link->name); | ||
1684 | |||
1685 | err = dpcm_be_dai_trigger(fe, stream, SNDRV_PCM_TRIGGER_STOP); | ||
1686 | if (err < 0) | ||
1687 | dev_err(fe->dev,"dpcm: trigger FE failed %d\n", err); | ||
1688 | } | ||
1689 | |||
1690 | err = dpcm_be_dai_hw_free(fe, stream); | ||
1691 | if (err < 0) | ||
1692 | dev_err(fe->dev,"dpcm: hw_free FE failed %d\n", err); | ||
1693 | |||
1694 | err = dpcm_be_dai_shutdown(fe, stream); | ||
1695 | if (err < 0) | ||
1696 | dev_err(fe->dev,"dpcm: shutdown FE failed %d\n", err); | ||
1697 | |||
1698 | /* run the stream event for each BE */ | ||
1699 | dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_NOP); | ||
1700 | |||
1701 | return 0; | ||
1702 | } | ||
1703 | |||
1704 | static int dpcm_run_update_startup(struct snd_soc_pcm_runtime *fe, int stream) | ||
1705 | { | ||
1706 | struct snd_pcm_substream *substream = | ||
1707 | snd_soc_dpcm_get_substream(fe, stream); | ||
1708 | struct snd_soc_dpcm *dpcm; | ||
1709 | enum snd_soc_dpcm_trigger trigger = fe->dai_link->trigger[stream]; | ||
1710 | int ret; | ||
1711 | |||
1712 | dev_dbg(fe->dev, "runtime %s open on FE %s\n", | ||
1713 | stream ? "capture" : "playback", fe->dai_link->name); | ||
1714 | |||
1715 | /* Only start the BE if the FE is ready */ | ||
1716 | if (fe->dpcm[stream].state == SND_SOC_DPCM_STATE_HW_FREE || | ||
1717 | fe->dpcm[stream].state == SND_SOC_DPCM_STATE_CLOSE) | ||
1718 | return -EINVAL; | ||
1719 | |||
1720 | /* startup must always be called for new BEs */ | ||
1721 | ret = dpcm_be_dai_startup(fe, stream); | ||
1722 | if (ret < 0) { | ||
1723 | goto disconnect; | ||
1724 | return ret; | ||
1725 | } | ||
1726 | |||
1727 | /* keep going if FE state is > open */ | ||
1728 | if (fe->dpcm[stream].state == SND_SOC_DPCM_STATE_OPEN) | ||
1729 | return 0; | ||
1730 | |||
1731 | ret = dpcm_be_dai_hw_params(fe, stream); | ||
1732 | if (ret < 0) { | ||
1733 | goto close; | ||
1734 | return ret; | ||
1735 | } | ||
1736 | |||
1737 | /* keep going if FE state is > hw_params */ | ||
1738 | if (fe->dpcm[stream].state == SND_SOC_DPCM_STATE_HW_PARAMS) | ||
1739 | return 0; | ||
1740 | |||
1741 | |||
1742 | ret = dpcm_be_dai_prepare(fe, stream); | ||
1743 | if (ret < 0) { | ||
1744 | goto hw_free; | ||
1745 | return ret; | ||
1746 | } | ||
1747 | |||
1748 | /* run the stream event for each BE */ | ||
1749 | dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_NOP); | ||
1750 | |||
1751 | /* keep going if FE state is > prepare */ | ||
1752 | if (fe->dpcm[stream].state == SND_SOC_DPCM_STATE_PREPARE || | ||
1753 | fe->dpcm[stream].state == SND_SOC_DPCM_STATE_STOP) | ||
1754 | return 0; | ||
1755 | |||
1756 | if (trigger == SND_SOC_DPCM_TRIGGER_BESPOKE) { | ||
1757 | /* call trigger on the frontend - FE takes care of all BE triggers */ | ||
1758 | dev_dbg(fe->dev, "dpcm: bespoke trigger FE %s cmd start\n", | ||
1759 | fe->dai_link->name); | ||
1760 | |||
1761 | ret = soc_pcm_bespoke_trigger(substream, SNDRV_PCM_TRIGGER_START); | ||
1762 | if (ret < 0) { | ||
1763 | dev_err(fe->dev,"dpcm: bespoke trigger FE failed %d\n", ret); | ||
1764 | goto hw_free; | ||
1765 | } | ||
1766 | } else { | ||
1767 | dev_dbg(fe->dev, "dpcm: trigger FE %s cmd start\n", | ||
1768 | fe->dai_link->name); | ||
1769 | |||
1770 | ret = dpcm_be_dai_trigger(fe, stream, | ||
1771 | SNDRV_PCM_TRIGGER_START); | ||
1772 | if (ret < 0) { | ||
1773 | dev_err(fe->dev,"dpcm: trigger FE failed %d\n", ret); | ||
1774 | goto hw_free; | ||
1775 | } | ||
1776 | } | ||
1777 | |||
1778 | return 0; | ||
1779 | |||
1780 | hw_free: | ||
1781 | dpcm_be_dai_hw_free(fe, stream); | ||
1782 | close: | ||
1783 | dpcm_be_dai_shutdown(fe, stream); | ||
1784 | disconnect: | ||
1785 | /* disconnect any non started BEs */ | ||
1786 | list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) { | ||
1787 | struct snd_soc_pcm_runtime *be = dpcm->be; | ||
1788 | if (be->dpcm[stream].state != SND_SOC_DPCM_STATE_START) | ||
1789 | dpcm->state = SND_SOC_DPCM_LINK_STATE_FREE; | ||
1790 | } | ||
1791 | |||
1792 | return ret; | ||
1793 | } | ||
1794 | |||
1795 | static int dpcm_run_new_update(struct snd_soc_pcm_runtime *fe, int stream) | ||
1796 | { | ||
1797 | int ret; | ||
1798 | |||
1799 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_BE; | ||
1800 | ret = dpcm_run_update_startup(fe, stream); | ||
1801 | if (ret < 0) | ||
1802 | dev_err(fe->dev, "failed to startup some BEs\n"); | ||
1803 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO; | ||
1804 | |||
1805 | return ret; | ||
1806 | } | ||
1807 | |||
1808 | static int dpcm_run_old_update(struct snd_soc_pcm_runtime *fe, int stream) | ||
1809 | { | ||
1810 | int ret; | ||
1811 | |||
1812 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_BE; | ||
1813 | ret = dpcm_run_update_shutdown(fe, stream); | ||
1814 | if (ret < 0) | ||
1815 | dev_err(fe->dev, "failed to shutdown some BEs\n"); | ||
1816 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO; | ||
1817 | |||
1818 | return ret; | ||
1819 | } | ||
1820 | |||
1821 | /* Called by DAPM mixer/mux changes to update audio routing between PCMs and | ||
1822 | * any DAI links. | ||
1823 | */ | ||
1824 | int soc_dpcm_runtime_update(struct snd_soc_dapm_widget *widget) | ||
1825 | { | ||
1826 | struct snd_soc_card *card; | ||
1827 | int i, old, new, paths; | ||
1828 | |||
1829 | if (widget->codec) | ||
1830 | card = widget->codec->card; | ||
1831 | else if (widget->platform) | ||
1832 | card = widget->platform->card; | ||
1833 | else | ||
1834 | return -EINVAL; | ||
1835 | |||
1836 | mutex_lock_nested(&card->mutex, SND_SOC_CARD_CLASS_RUNTIME); | ||
1837 | for (i = 0; i < card->num_rtd; i++) { | ||
1838 | struct snd_soc_dapm_widget_list *list; | ||
1839 | struct snd_soc_pcm_runtime *fe = &card->rtd[i]; | ||
1840 | |||
1841 | /* make sure link is FE */ | ||
1842 | if (!fe->dai_link->dynamic) | ||
1843 | continue; | ||
1844 | |||
1845 | /* only check active links */ | ||
1846 | if (!fe->cpu_dai->active) | ||
1847 | continue; | ||
1848 | |||
1849 | /* DAPM sync will call this to update DSP paths */ | ||
1850 | dev_dbg(fe->dev, "DPCM runtime update for FE %s\n", | ||
1851 | fe->dai_link->name); | ||
1852 | |||
1853 | /* skip if FE doesn't have playback capability */ | ||
1854 | if (!fe->cpu_dai->driver->playback.channels_min) | ||
1855 | goto capture; | ||
1856 | |||
1857 | paths = dpcm_path_get(fe, SNDRV_PCM_STREAM_PLAYBACK, &list); | ||
1858 | if (paths < 0) { | ||
1859 | dev_warn(fe->dev, "%s no valid %s path\n", | ||
1860 | fe->dai_link->name, "playback"); | ||
1861 | mutex_unlock(&card->mutex); | ||
1862 | return paths; | ||
1863 | } | ||
1864 | |||
1865 | /* update any new playback paths */ | ||
1866 | new = dpcm_process_paths(fe, SNDRV_PCM_STREAM_PLAYBACK, &list, 1); | ||
1867 | if (new) { | ||
1868 | dpcm_run_new_update(fe, SNDRV_PCM_STREAM_PLAYBACK); | ||
1869 | dpcm_clear_pending_state(fe, SNDRV_PCM_STREAM_PLAYBACK); | ||
1870 | dpcm_be_disconnect(fe, SNDRV_PCM_STREAM_PLAYBACK); | ||
1871 | } | ||
1872 | |||
1873 | /* update any old playback paths */ | ||
1874 | old = dpcm_process_paths(fe, SNDRV_PCM_STREAM_PLAYBACK, &list, 0); | ||
1875 | if (old) { | ||
1876 | dpcm_run_old_update(fe, SNDRV_PCM_STREAM_PLAYBACK); | ||
1877 | dpcm_clear_pending_state(fe, SNDRV_PCM_STREAM_PLAYBACK); | ||
1878 | dpcm_be_disconnect(fe, SNDRV_PCM_STREAM_PLAYBACK); | ||
1879 | } | ||
1880 | |||
1881 | capture: | ||
1882 | /* skip if FE doesn't have capture capability */ | ||
1883 | if (!fe->cpu_dai->driver->capture.channels_min) | ||
1884 | continue; | ||
1885 | |||
1886 | paths = dpcm_path_get(fe, SNDRV_PCM_STREAM_CAPTURE, &list); | ||
1887 | if (paths < 0) { | ||
1888 | dev_warn(fe->dev, "%s no valid %s path\n", | ||
1889 | fe->dai_link->name, "capture"); | ||
1890 | mutex_unlock(&card->mutex); | ||
1891 | return paths; | ||
1892 | } | ||
1893 | |||
1894 | /* update any new capture paths */ | ||
1895 | new = dpcm_process_paths(fe, SNDRV_PCM_STREAM_CAPTURE, &list, 1); | ||
1896 | if (new) { | ||
1897 | dpcm_run_new_update(fe, SNDRV_PCM_STREAM_CAPTURE); | ||
1898 | dpcm_clear_pending_state(fe, SNDRV_PCM_STREAM_CAPTURE); | ||
1899 | dpcm_be_disconnect(fe, SNDRV_PCM_STREAM_CAPTURE); | ||
1900 | } | ||
1901 | |||
1902 | /* update any old capture paths */ | ||
1903 | old = dpcm_process_paths(fe, SNDRV_PCM_STREAM_CAPTURE, &list, 0); | ||
1904 | if (old) { | ||
1905 | dpcm_run_old_update(fe, SNDRV_PCM_STREAM_CAPTURE); | ||
1906 | dpcm_clear_pending_state(fe, SNDRV_PCM_STREAM_CAPTURE); | ||
1907 | dpcm_be_disconnect(fe, SNDRV_PCM_STREAM_CAPTURE); | ||
1908 | } | ||
1909 | |||
1910 | dpcm_path_put(&list); | ||
1911 | } | ||
1912 | |||
1913 | mutex_unlock(&card->mutex); | ||
1914 | return 0; | ||
1915 | } | ||
1916 | int soc_dpcm_be_digital_mute(struct snd_soc_pcm_runtime *fe, int mute) | ||
1917 | { | ||
1918 | struct snd_soc_dpcm *dpcm; | ||
1919 | struct list_head *clients = | ||
1920 | &fe->dpcm[SNDRV_PCM_STREAM_PLAYBACK].be_clients; | ||
1921 | |||
1922 | list_for_each_entry(dpcm, clients, list_be) { | ||
1923 | |||
1924 | struct snd_soc_pcm_runtime *be = dpcm->be; | ||
1925 | struct snd_soc_dai *dai = be->codec_dai; | ||
1926 | struct snd_soc_dai_driver *drv = dai->driver; | ||
1927 | |||
1928 | if (be->dai_link->ignore_suspend) | ||
1929 | continue; | ||
1930 | |||
1931 | dev_dbg(be->dev, "BE digital mute %s\n", be->dai_link->name); | ||
1932 | |||
1933 | if (drv->ops->digital_mute && dai->playback_active) | ||
1934 | drv->ops->digital_mute(dai, mute); | ||
1935 | } | ||
1936 | |||
1937 | return 0; | ||
1938 | } | ||
1939 | |||
1940 | static int dpcm_fe_dai_open(struct snd_pcm_substream *fe_substream) | ||
1941 | { | ||
1942 | struct snd_soc_pcm_runtime *fe = fe_substream->private_data; | ||
1943 | struct snd_soc_dpcm *dpcm; | ||
1944 | struct snd_soc_dapm_widget_list *list; | ||
1945 | int ret; | ||
1946 | int stream = fe_substream->stream; | ||
1947 | |||
1948 | mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME); | ||
1949 | fe->dpcm[stream].runtime = fe_substream->runtime; | ||
1950 | |||
1951 | if (dpcm_path_get(fe, stream, &list) <= 0) { | ||
1952 | dev_warn(fe->dev, "asoc: %s no valid %s route\n", | ||
1953 | fe->dai_link->name, stream ? "capture" : "playback"); | ||
1954 | mutex_unlock(&fe->card->mutex); | ||
1955 | return -EINVAL; | ||
1956 | } | ||
1957 | |||
1958 | /* calculate valid and active FE <-> BE dpcms */ | ||
1959 | dpcm_process_paths(fe, stream, &list, 1); | ||
1960 | |||
1961 | ret = dpcm_fe_dai_startup(fe_substream); | ||
1962 | if (ret < 0) { | ||
1963 | /* clean up all links */ | ||
1964 | list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) | ||
1965 | dpcm->state = SND_SOC_DPCM_LINK_STATE_FREE; | ||
1966 | |||
1967 | dpcm_be_disconnect(fe, stream); | ||
1968 | fe->dpcm[stream].runtime = NULL; | ||
1969 | } | ||
1970 | |||
1971 | dpcm_clear_pending_state(fe, stream); | ||
1972 | dpcm_path_put(&list); | ||
1973 | mutex_unlock(&fe->card->mutex); | ||
1974 | return ret; | ||
1975 | } | ||
1976 | |||
1977 | static int dpcm_fe_dai_close(struct snd_pcm_substream *fe_substream) | ||
1978 | { | ||
1979 | struct snd_soc_pcm_runtime *fe = fe_substream->private_data; | ||
1980 | struct snd_soc_dpcm *dpcm; | ||
1981 | int stream = fe_substream->stream, ret; | ||
1982 | |||
1983 | mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME); | ||
1984 | ret = dpcm_fe_dai_shutdown(fe_substream); | ||
1985 | |||
1986 | /* mark FE's links ready to prune */ | ||
1987 | list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) | ||
1988 | dpcm->state = SND_SOC_DPCM_LINK_STATE_FREE; | ||
1989 | |||
1990 | dpcm_be_disconnect(fe, stream); | ||
1991 | |||
1992 | fe->dpcm[stream].runtime = NULL; | ||
1993 | mutex_unlock(&fe->card->mutex); | ||
1994 | return ret; | ||
1995 | } | ||
1996 | |||
637 | /* create a new pcm */ | 1997 | /* create a new pcm */ |
638 | int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num) | 1998 | int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num) |
639 | { | 1999 | { |
@@ -641,56 +2001,94 @@ int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num) | |||
641 | struct snd_soc_platform *platform = rtd->platform; | 2001 | struct snd_soc_platform *platform = rtd->platform; |
642 | struct snd_soc_dai *codec_dai = rtd->codec_dai; | 2002 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
643 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; | 2003 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
644 | struct snd_pcm_ops *soc_pcm_ops = &rtd->ops; | ||
645 | struct snd_pcm *pcm; | 2004 | struct snd_pcm *pcm; |
646 | char new_name[64]; | 2005 | char new_name[64]; |
647 | int ret = 0, playback = 0, capture = 0; | 2006 | int ret = 0, playback = 0, capture = 0; |
648 | 2007 | ||
649 | soc_pcm_ops->open = soc_pcm_open; | 2008 | if (rtd->dai_link->dynamic || rtd->dai_link->no_pcm) { |
650 | soc_pcm_ops->close = soc_pcm_close; | 2009 | if (cpu_dai->driver->playback.channels_min) |
651 | soc_pcm_ops->hw_params = soc_pcm_hw_params; | 2010 | playback = 1; |
652 | soc_pcm_ops->hw_free = soc_pcm_hw_free; | 2011 | if (cpu_dai->driver->capture.channels_min) |
653 | soc_pcm_ops->prepare = soc_pcm_prepare; | 2012 | capture = 1; |
654 | soc_pcm_ops->trigger = soc_pcm_trigger; | 2013 | } else { |
655 | soc_pcm_ops->pointer = soc_pcm_pointer; | 2014 | if (codec_dai->driver->playback.channels_min) |
656 | 2015 | playback = 1; | |
657 | /* check client and interface hw capabilities */ | 2016 | if (codec_dai->driver->capture.channels_min) |
658 | snprintf(new_name, sizeof(new_name), "%s %s-%d", | 2017 | capture = 1; |
659 | rtd->dai_link->stream_name, codec_dai->name, num); | 2018 | } |
660 | 2019 | ||
661 | if (codec_dai->driver->playback.channels_min) | 2020 | /* create the PCM */ |
662 | playback = 1; | 2021 | if (rtd->dai_link->no_pcm) { |
663 | if (codec_dai->driver->capture.channels_min) | 2022 | snprintf(new_name, sizeof(new_name), "(%s)", |
664 | capture = 1; | 2023 | rtd->dai_link->stream_name); |
665 | 2024 | ||
666 | dev_dbg(rtd->card->dev, "registered pcm #%d %s\n",num,new_name); | 2025 | ret = snd_pcm_new_internal(rtd->card->snd_card, new_name, num, |
667 | ret = snd_pcm_new(rtd->card->snd_card, new_name, | 2026 | playback, capture, &pcm); |
668 | num, playback, capture, &pcm); | 2027 | } else { |
2028 | if (rtd->dai_link->dynamic) | ||
2029 | snprintf(new_name, sizeof(new_name), "%s (*)", | ||
2030 | rtd->dai_link->stream_name); | ||
2031 | else | ||
2032 | snprintf(new_name, sizeof(new_name), "%s %s-%d", | ||
2033 | rtd->dai_link->stream_name, codec_dai->name, num); | ||
2034 | |||
2035 | ret = snd_pcm_new(rtd->card->snd_card, new_name, num, playback, | ||
2036 | capture, &pcm); | ||
2037 | } | ||
669 | if (ret < 0) { | 2038 | if (ret < 0) { |
670 | printk(KERN_ERR "asoc: can't create pcm for codec %s\n", codec->name); | 2039 | printk(KERN_ERR "asoc: can't create pcm for codec %s\n", codec->name); |
671 | return ret; | 2040 | return ret; |
672 | } | 2041 | } |
2042 | dev_dbg(rtd->card->dev, "registered pcm #%d %s\n",num, new_name); | ||
673 | 2043 | ||
674 | /* DAPM dai link stream work */ | 2044 | /* DAPM dai link stream work */ |
675 | INIT_DELAYED_WORK(&rtd->delayed_work, close_delayed_work); | 2045 | INIT_DELAYED_WORK(&rtd->delayed_work, close_delayed_work); |
676 | 2046 | ||
677 | rtd->pcm = pcm; | 2047 | rtd->pcm = pcm; |
678 | pcm->private_data = rtd; | 2048 | pcm->private_data = rtd; |
2049 | |||
2050 | if (rtd->dai_link->no_pcm) { | ||
2051 | if (playback) | ||
2052 | pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream->private_data = rtd; | ||
2053 | if (capture) | ||
2054 | pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream->private_data = rtd; | ||
2055 | goto out; | ||
2056 | } | ||
2057 | |||
2058 | /* ASoC PCM operations */ | ||
2059 | if (rtd->dai_link->dynamic) { | ||
2060 | rtd->ops.open = dpcm_fe_dai_open; | ||
2061 | rtd->ops.hw_params = dpcm_fe_dai_hw_params; | ||
2062 | rtd->ops.prepare = dpcm_fe_dai_prepare; | ||
2063 | rtd->ops.trigger = dpcm_fe_dai_trigger; | ||
2064 | rtd->ops.hw_free = dpcm_fe_dai_hw_free; | ||
2065 | rtd->ops.close = dpcm_fe_dai_close; | ||
2066 | rtd->ops.pointer = soc_pcm_pointer; | ||
2067 | rtd->ops.ioctl = soc_pcm_ioctl; | ||
2068 | } else { | ||
2069 | rtd->ops.open = soc_pcm_open; | ||
2070 | rtd->ops.hw_params = soc_pcm_hw_params; | ||
2071 | rtd->ops.prepare = soc_pcm_prepare; | ||
2072 | rtd->ops.trigger = soc_pcm_trigger; | ||
2073 | rtd->ops.hw_free = soc_pcm_hw_free; | ||
2074 | rtd->ops.close = soc_pcm_close; | ||
2075 | rtd->ops.pointer = soc_pcm_pointer; | ||
2076 | rtd->ops.ioctl = soc_pcm_ioctl; | ||
2077 | } | ||
2078 | |||
679 | if (platform->driver->ops) { | 2079 | if (platform->driver->ops) { |
680 | soc_pcm_ops->mmap = platform->driver->ops->mmap; | 2080 | rtd->ops.ack = platform->driver->ops->ack; |
681 | soc_pcm_ops->pointer = platform->driver->ops->pointer; | 2081 | rtd->ops.copy = platform->driver->ops->copy; |
682 | soc_pcm_ops->ioctl = platform->driver->ops->ioctl; | 2082 | rtd->ops.silence = platform->driver->ops->silence; |
683 | soc_pcm_ops->copy = platform->driver->ops->copy; | 2083 | rtd->ops.page = platform->driver->ops->page; |
684 | soc_pcm_ops->silence = platform->driver->ops->silence; | 2084 | rtd->ops.mmap = platform->driver->ops->mmap; |
685 | soc_pcm_ops->ack = platform->driver->ops->ack; | ||
686 | soc_pcm_ops->page = platform->driver->ops->page; | ||
687 | } | 2085 | } |
688 | 2086 | ||
689 | if (playback) | 2087 | if (playback) |
690 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, soc_pcm_ops); | 2088 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &rtd->ops); |
691 | 2089 | ||
692 | if (capture) | 2090 | if (capture) |
693 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, soc_pcm_ops); | 2091 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &rtd->ops); |
694 | 2092 | ||
695 | if (platform->driver->pcm_new) { | 2093 | if (platform->driver->pcm_new) { |
696 | ret = platform->driver->pcm_new(rtd); | 2094 | ret = platform->driver->pcm_new(rtd); |
@@ -701,7 +2099,257 @@ int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num) | |||
701 | } | 2099 | } |
702 | 2100 | ||
703 | pcm->private_free = platform->driver->pcm_free; | 2101 | pcm->private_free = platform->driver->pcm_free; |
2102 | out: | ||
704 | printk(KERN_INFO "asoc: %s <-> %s mapping ok\n", codec_dai->name, | 2103 | printk(KERN_INFO "asoc: %s <-> %s mapping ok\n", codec_dai->name, |
705 | cpu_dai->name); | 2104 | cpu_dai->name); |
706 | return ret; | 2105 | return ret; |
707 | } | 2106 | } |
2107 | |||
2108 | /* is the current PCM operation for this FE ? */ | ||
2109 | int snd_soc_dpcm_fe_can_update(struct snd_soc_pcm_runtime *fe, int stream) | ||
2110 | { | ||
2111 | if (fe->dpcm[stream].runtime_update == SND_SOC_DPCM_UPDATE_FE) | ||
2112 | return 1; | ||
2113 | return 0; | ||
2114 | } | ||
2115 | EXPORT_SYMBOL_GPL(snd_soc_dpcm_fe_can_update); | ||
2116 | |||
2117 | /* is the current PCM operation for this BE ? */ | ||
2118 | int snd_soc_dpcm_be_can_update(struct snd_soc_pcm_runtime *fe, | ||
2119 | struct snd_soc_pcm_runtime *be, int stream) | ||
2120 | { | ||
2121 | if ((fe->dpcm[stream].runtime_update == SND_SOC_DPCM_UPDATE_FE) || | ||
2122 | ((fe->dpcm[stream].runtime_update == SND_SOC_DPCM_UPDATE_BE) && | ||
2123 | be->dpcm[stream].runtime_update)) | ||
2124 | return 1; | ||
2125 | return 0; | ||
2126 | } | ||
2127 | EXPORT_SYMBOL_GPL(snd_soc_dpcm_be_can_update); | ||
2128 | |||
2129 | /* get the substream for this BE */ | ||
2130 | struct snd_pcm_substream * | ||
2131 | snd_soc_dpcm_get_substream(struct snd_soc_pcm_runtime *be, int stream) | ||
2132 | { | ||
2133 | return be->pcm->streams[stream].substream; | ||
2134 | } | ||
2135 | EXPORT_SYMBOL_GPL(snd_soc_dpcm_get_substream); | ||
2136 | |||
2137 | /* get the BE runtime state */ | ||
2138 | enum snd_soc_dpcm_state | ||
2139 | snd_soc_dpcm_be_get_state(struct snd_soc_pcm_runtime *be, int stream) | ||
2140 | { | ||
2141 | return be->dpcm[stream].state; | ||
2142 | } | ||
2143 | EXPORT_SYMBOL_GPL(snd_soc_dpcm_be_get_state); | ||
2144 | |||
2145 | /* set the BE runtime state */ | ||
2146 | void snd_soc_dpcm_be_set_state(struct snd_soc_pcm_runtime *be, | ||
2147 | int stream, enum snd_soc_dpcm_state state) | ||
2148 | { | ||
2149 | be->dpcm[stream].state = state; | ||
2150 | } | ||
2151 | EXPORT_SYMBOL_GPL(snd_soc_dpcm_be_set_state); | ||
2152 | |||
2153 | /* | ||
2154 | * We can only hw_free, stop, pause or suspend a BE DAI if any of it's FE | ||
2155 | * are not running, paused or suspended for the specified stream direction. | ||
2156 | */ | ||
2157 | int snd_soc_dpcm_can_be_free_stop(struct snd_soc_pcm_runtime *fe, | ||
2158 | struct snd_soc_pcm_runtime *be, int stream) | ||
2159 | { | ||
2160 | struct snd_soc_dpcm *dpcm; | ||
2161 | int state; | ||
2162 | |||
2163 | list_for_each_entry(dpcm, &be->dpcm[stream].fe_clients, list_fe) { | ||
2164 | |||
2165 | if (dpcm->fe == fe) | ||
2166 | continue; | ||
2167 | |||
2168 | state = dpcm->fe->dpcm[stream].state; | ||
2169 | if (state == SND_SOC_DPCM_STATE_START || | ||
2170 | state == SND_SOC_DPCM_STATE_PAUSED || | ||
2171 | state == SND_SOC_DPCM_STATE_SUSPEND) | ||
2172 | return 0; | ||
2173 | } | ||
2174 | |||
2175 | /* it's safe to free/stop this BE DAI */ | ||
2176 | return 1; | ||
2177 | } | ||
2178 | EXPORT_SYMBOL_GPL(snd_soc_dpcm_can_be_free_stop); | ||
2179 | |||
2180 | /* | ||
2181 | * We can only change hw params a BE DAI if any of it's FE are not prepared, | ||
2182 | * running, paused or suspended for the specified stream direction. | ||
2183 | */ | ||
2184 | int snd_soc_dpcm_can_be_params(struct snd_soc_pcm_runtime *fe, | ||
2185 | struct snd_soc_pcm_runtime *be, int stream) | ||
2186 | { | ||
2187 | struct snd_soc_dpcm *dpcm; | ||
2188 | int state; | ||
2189 | |||
2190 | list_for_each_entry(dpcm, &be->dpcm[stream].fe_clients, list_fe) { | ||
2191 | |||
2192 | if (dpcm->fe == fe) | ||
2193 | continue; | ||
2194 | |||
2195 | state = dpcm->fe->dpcm[stream].state; | ||
2196 | if (state == SND_SOC_DPCM_STATE_START || | ||
2197 | state == SND_SOC_DPCM_STATE_PAUSED || | ||
2198 | state == SND_SOC_DPCM_STATE_SUSPEND || | ||
2199 | state == SND_SOC_DPCM_STATE_PREPARE) | ||
2200 | return 0; | ||
2201 | } | ||
2202 | |||
2203 | /* it's safe to change hw_params */ | ||
2204 | return 1; | ||
2205 | } | ||
2206 | EXPORT_SYMBOL_GPL(snd_soc_dpcm_can_be_params); | ||
2207 | |||
2208 | int snd_soc_platform_trigger(struct snd_pcm_substream *substream, | ||
2209 | int cmd, struct snd_soc_platform *platform) | ||
2210 | { | ||
2211 | if (platform->driver->ops->trigger) | ||
2212 | return platform->driver->ops->trigger(substream, cmd); | ||
2213 | return 0; | ||
2214 | } | ||
2215 | EXPORT_SYMBOL_GPL(snd_soc_platform_trigger); | ||
2216 | |||
2217 | #ifdef CONFIG_DEBUG_FS | ||
2218 | static char *dpcm_state_string(enum snd_soc_dpcm_state state) | ||
2219 | { | ||
2220 | switch (state) { | ||
2221 | case SND_SOC_DPCM_STATE_NEW: | ||
2222 | return "new"; | ||
2223 | case SND_SOC_DPCM_STATE_OPEN: | ||
2224 | return "open"; | ||
2225 | case SND_SOC_DPCM_STATE_HW_PARAMS: | ||
2226 | return "hw_params"; | ||
2227 | case SND_SOC_DPCM_STATE_PREPARE: | ||
2228 | return "prepare"; | ||
2229 | case SND_SOC_DPCM_STATE_START: | ||
2230 | return "start"; | ||
2231 | case SND_SOC_DPCM_STATE_STOP: | ||
2232 | return "stop"; | ||
2233 | case SND_SOC_DPCM_STATE_SUSPEND: | ||
2234 | return "suspend"; | ||
2235 | case SND_SOC_DPCM_STATE_PAUSED: | ||
2236 | return "paused"; | ||
2237 | case SND_SOC_DPCM_STATE_HW_FREE: | ||
2238 | return "hw_free"; | ||
2239 | case SND_SOC_DPCM_STATE_CLOSE: | ||
2240 | return "close"; | ||
2241 | } | ||
2242 | |||
2243 | return "unknown"; | ||
2244 | } | ||
2245 | |||
2246 | static ssize_t dpcm_show_state(struct snd_soc_pcm_runtime *fe, | ||
2247 | int stream, char *buf, size_t size) | ||
2248 | { | ||
2249 | struct snd_pcm_hw_params *params = &fe->dpcm[stream].hw_params; | ||
2250 | struct snd_soc_dpcm *dpcm; | ||
2251 | ssize_t offset = 0; | ||
2252 | |||
2253 | /* FE state */ | ||
2254 | offset += snprintf(buf + offset, size - offset, | ||
2255 | "[%s - %s]\n", fe->dai_link->name, | ||
2256 | stream ? "Capture" : "Playback"); | ||
2257 | |||
2258 | offset += snprintf(buf + offset, size - offset, "State: %s\n", | ||
2259 | dpcm_state_string(fe->dpcm[stream].state)); | ||
2260 | |||
2261 | if ((fe->dpcm[stream].state >= SND_SOC_DPCM_STATE_HW_PARAMS) && | ||
2262 | (fe->dpcm[stream].state <= SND_SOC_DPCM_STATE_STOP)) | ||
2263 | offset += snprintf(buf + offset, size - offset, | ||
2264 | "Hardware Params: " | ||
2265 | "Format = %s, Channels = %d, Rate = %d\n", | ||
2266 | snd_pcm_format_name(params_format(params)), | ||
2267 | params_channels(params), | ||
2268 | params_rate(params)); | ||
2269 | |||
2270 | /* BEs state */ | ||
2271 | offset += snprintf(buf + offset, size - offset, "Backends:\n"); | ||
2272 | |||
2273 | if (list_empty(&fe->dpcm[stream].be_clients)) { | ||
2274 | offset += snprintf(buf + offset, size - offset, | ||
2275 | " No active DSP links\n"); | ||
2276 | goto out; | ||
2277 | } | ||
2278 | |||
2279 | list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) { | ||
2280 | struct snd_soc_pcm_runtime *be = dpcm->be; | ||
2281 | params = &dpcm->hw_params; | ||
2282 | |||
2283 | offset += snprintf(buf + offset, size - offset, | ||
2284 | "- %s\n", be->dai_link->name); | ||
2285 | |||
2286 | offset += snprintf(buf + offset, size - offset, | ||
2287 | " State: %s\n", | ||
2288 | dpcm_state_string(be->dpcm[stream].state)); | ||
2289 | |||
2290 | if ((be->dpcm[stream].state >= SND_SOC_DPCM_STATE_HW_PARAMS) && | ||
2291 | (be->dpcm[stream].state <= SND_SOC_DPCM_STATE_STOP)) | ||
2292 | offset += snprintf(buf + offset, size - offset, | ||
2293 | " Hardware Params: " | ||
2294 | "Format = %s, Channels = %d, Rate = %d\n", | ||
2295 | snd_pcm_format_name(params_format(params)), | ||
2296 | params_channels(params), | ||
2297 | params_rate(params)); | ||
2298 | } | ||
2299 | |||
2300 | out: | ||
2301 | return offset; | ||
2302 | } | ||
2303 | |||
2304 | static ssize_t dpcm_state_read_file(struct file *file, char __user *user_buf, | ||
2305 | size_t count, loff_t *ppos) | ||
2306 | { | ||
2307 | struct snd_soc_pcm_runtime *fe = file->private_data; | ||
2308 | ssize_t out_count = PAGE_SIZE, offset = 0, ret = 0; | ||
2309 | char *buf; | ||
2310 | |||
2311 | buf = kmalloc(out_count, GFP_KERNEL); | ||
2312 | if (!buf) | ||
2313 | return -ENOMEM; | ||
2314 | |||
2315 | if (fe->cpu_dai->driver->playback.channels_min) | ||
2316 | offset += dpcm_show_state(fe, SNDRV_PCM_STREAM_PLAYBACK, | ||
2317 | buf + offset, out_count - offset); | ||
2318 | |||
2319 | if (fe->cpu_dai->driver->capture.channels_min) | ||
2320 | offset += dpcm_show_state(fe, SNDRV_PCM_STREAM_CAPTURE, | ||
2321 | buf + offset, out_count - offset); | ||
2322 | |||
2323 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, offset); | ||
2324 | |||
2325 | kfree(buf); | ||
2326 | return ret; | ||
2327 | } | ||
2328 | |||
2329 | static const struct file_operations dpcm_state_fops = { | ||
2330 | .open = simple_open, | ||
2331 | .read = dpcm_state_read_file, | ||
2332 | .llseek = default_llseek, | ||
2333 | }; | ||
2334 | |||
2335 | int soc_dpcm_debugfs_add(struct snd_soc_pcm_runtime *rtd) | ||
2336 | { | ||
2337 | if (!rtd->dai_link) | ||
2338 | return 0; | ||
2339 | |||
2340 | rtd->debugfs_dpcm_root = debugfs_create_dir(rtd->dai_link->name, | ||
2341 | rtd->card->debugfs_card_root); | ||
2342 | if (!rtd->debugfs_dpcm_root) { | ||
2343 | dev_dbg(rtd->dev, | ||
2344 | "ASoC: Failed to create dpcm debugfs directory %s\n", | ||
2345 | rtd->dai_link->name); | ||
2346 | return -EINVAL; | ||
2347 | } | ||
2348 | |||
2349 | rtd->debugfs_dpcm_state = debugfs_create_file("state", 0444, | ||
2350 | rtd->debugfs_dpcm_root, | ||
2351 | rtd, &dpcm_state_fops); | ||
2352 | |||
2353 | return 0; | ||
2354 | } | ||
2355 | #endif | ||
diff --git a/sound/soc/tegra/Kconfig b/sound/soc/tegra/Kconfig index ce1b773c351f..c1c8e955f4d3 100644 --- a/sound/soc/tegra/Kconfig +++ b/sound/soc/tegra/Kconfig | |||
@@ -1,26 +1,63 @@ | |||
1 | config SND_SOC_TEGRA | 1 | config SND_SOC_TEGRA |
2 | tristate "SoC Audio for the Tegra System-on-Chip" | 2 | tristate "SoC Audio for the Tegra System-on-Chip" |
3 | depends on ARCH_TEGRA && TEGRA_SYSTEM_DMA | 3 | depends on ARCH_TEGRA && TEGRA_SYSTEM_DMA |
4 | select REGMAP_MMIO | ||
4 | help | 5 | help |
5 | Say Y or M here if you want support for SoC audio on Tegra. | 6 | Say Y or M here if you want support for SoC audio on Tegra. |
6 | 7 | ||
7 | config SND_SOC_TEGRA_I2S | 8 | config SND_SOC_TEGRA20_DAS |
8 | tristate | 9 | tristate |
9 | depends on SND_SOC_TEGRA | 10 | depends on SND_SOC_TEGRA && ARCH_TEGRA_2x_SOC |
11 | help | ||
12 | Say Y or M if you want to add support for the Tegra20 DAS module. | ||
13 | You will also need to select the individual machine drivers to | ||
14 | support below. | ||
15 | |||
16 | config SND_SOC_TEGRA20_I2S | ||
17 | tristate | ||
18 | depends on SND_SOC_TEGRA && ARCH_TEGRA_2x_SOC | ||
19 | select SND_SOC_TEGRA20_DAS | ||
10 | help | 20 | help |
11 | Say Y or M if you want to add support for codecs attached to the | 21 | Say Y or M if you want to add support for codecs attached to the |
12 | Tegra I2S interface. You will also need to select the individual | 22 | Tegra20 I2S interface. You will also need to select the individual |
13 | machine drivers to support below. | 23 | machine drivers to support below. |
14 | 24 | ||
15 | config SND_SOC_TEGRA_SPDIF | 25 | config SND_SOC_TEGRA20_SPDIF |
16 | tristate | 26 | tristate |
17 | depends on SND_SOC_TEGRA | 27 | depends on SND_SOC_TEGRA && ARCH_TEGRA_2x_SOC |
18 | default m | 28 | default m |
19 | help | 29 | help |
20 | Say Y or M if you want to add support for the SPDIF interface. | 30 | Say Y or M if you want to add support for the Tegra20 SPDIF interface. |
21 | You will also need to select the individual machine drivers to support | 31 | You will also need to select the individual machine drivers to support |
22 | below. | 32 | below. |
23 | 33 | ||
34 | config SND_SOC_TEGRA30_AHUB | ||
35 | tristate | ||
36 | depends on SND_SOC_TEGRA && ARCH_TEGRA_3x_SOC | ||
37 | help | ||
38 | Say Y or M if you want to add support for the Tegra20 AHUB module. | ||
39 | You will also need to select the individual machine drivers to | ||
40 | support below. | ||
41 | |||
42 | config SND_SOC_TEGRA30_I2S | ||
43 | tristate | ||
44 | depends on SND_SOC_TEGRA && ARCH_TEGRA_3x_SOC | ||
45 | select SND_SOC_TEGRA30_AHUB | ||
46 | help | ||
47 | Say Y or M if you want to add support for codecs attached to the | ||
48 | Tegra30 I2S interface. You will also need to select the individual | ||
49 | machine drivers to support below. | ||
50 | |||
51 | config SND_SOC_TEGRA_WM8753 | ||
52 | tristate "SoC Audio support for Tegra boards using a WM8753 codec" | ||
53 | depends on SND_SOC_TEGRA && I2C | ||
54 | select SND_SOC_TEGRA20_I2S if ARCH_TEGRA_2x_SOC | ||
55 | select SND_SOC_TEGRA30_I2S if ARCH_TEGRA_3x_SOC | ||
56 | select SND_SOC_WM8753 | ||
57 | help | ||
58 | Say Y or M here if you want to add support for SoC audio on Tegra | ||
59 | boards using the WM8753 codec, such as Whistler. | ||
60 | |||
24 | config MACH_HAS_SND_SOC_TEGRA_WM8903 | 61 | config MACH_HAS_SND_SOC_TEGRA_WM8903 |
25 | bool | 62 | bool |
26 | help | 63 | help |
@@ -32,7 +69,8 @@ config SND_SOC_TEGRA_WM8903 | |||
32 | tristate "SoC Audio support for Tegra boards using a WM8903 codec" | 69 | tristate "SoC Audio support for Tegra boards using a WM8903 codec" |
33 | depends on SND_SOC_TEGRA && I2C | 70 | depends on SND_SOC_TEGRA && I2C |
34 | depends on MACH_HAS_SND_SOC_TEGRA_WM8903 | 71 | depends on MACH_HAS_SND_SOC_TEGRA_WM8903 |
35 | select SND_SOC_TEGRA_I2S | 72 | select SND_SOC_TEGRA20_I2S if ARCH_TEGRA_2x_SOC |
73 | select SND_SOC_TEGRA30_I2S if ARCH_TEGRA_3x_SOC | ||
36 | select SND_SOC_WM8903 | 74 | select SND_SOC_WM8903 |
37 | help | 75 | help |
38 | Say Y or M here if you want to add support for SoC audio on Tegra | 76 | Say Y or M here if you want to add support for SoC audio on Tegra |
@@ -42,17 +80,17 @@ config SND_SOC_TEGRA_WM8903 | |||
42 | config SND_SOC_TEGRA_TRIMSLICE | 80 | config SND_SOC_TEGRA_TRIMSLICE |
43 | tristate "SoC Audio support for TrimSlice board" | 81 | tristate "SoC Audio support for TrimSlice board" |
44 | depends on SND_SOC_TEGRA && MACH_TRIMSLICE && I2C | 82 | depends on SND_SOC_TEGRA && MACH_TRIMSLICE && I2C |
45 | select SND_SOC_TEGRA_I2S | 83 | select SND_SOC_TEGRA20_I2S if ARCH_TEGRA_2x_SOC |
46 | select SND_SOC_TLV320AIC23 | 84 | select SND_SOC_TLV320AIC23 |
47 | help | 85 | help |
48 | Say Y or M here if you want to add support for SoC audio on the | 86 | Say Y or M here if you want to add support for SoC audio on the |
49 | TrimSlice platform. | 87 | TrimSlice platform. |
50 | 88 | ||
51 | config SND_SOC_TEGRA_ALC5632 | 89 | config SND_SOC_TEGRA_ALC5632 |
52 | tristate "SoC Audio support for Tegra boards using an ALC5632 codec" | 90 | tristate "SoC Audio support for Tegra boards using an ALC5632 codec" |
53 | depends on SND_SOC_TEGRA && I2C | 91 | depends on SND_SOC_TEGRA && I2C |
54 | select SND_SOC_TEGRA_I2S | 92 | select SND_SOC_TEGRA20_I2S if ARCH_TEGRA_2x_SOC |
55 | select SND_SOC_ALC5632 | 93 | select SND_SOC_ALC5632 |
56 | help | 94 | help |
57 | Say Y or M here if you want to add support for SoC audio on the | 95 | Say Y or M here if you want to add support for SoC audio on the |
58 | Toshiba AC100 netbook. | 96 | Toshiba AC100 netbook. |
diff --git a/sound/soc/tegra/Makefile b/sound/soc/tegra/Makefile index 8e584b8fcfba..391e78a34c06 100644 --- a/sound/soc/tegra/Makefile +++ b/sound/soc/tegra/Makefile | |||
@@ -1,21 +1,27 @@ | |||
1 | # Tegra platform Support | 1 | # Tegra platform Support |
2 | snd-soc-tegra-das-objs := tegra_das.o | ||
3 | snd-soc-tegra-pcm-objs := tegra_pcm.o | 2 | snd-soc-tegra-pcm-objs := tegra_pcm.o |
4 | snd-soc-tegra-i2s-objs := tegra_i2s.o | ||
5 | snd-soc-tegra-spdif-objs := tegra_spdif.o | ||
6 | snd-soc-tegra-utils-objs += tegra_asoc_utils.o | 3 | snd-soc-tegra-utils-objs += tegra_asoc_utils.o |
4 | snd-soc-tegra20-das-objs := tegra20_das.o | ||
5 | snd-soc-tegra20-i2s-objs := tegra20_i2s.o | ||
6 | snd-soc-tegra20-spdif-objs := tegra20_spdif.o | ||
7 | snd-soc-tegra30-ahub-objs := tegra30_ahub.o | ||
8 | snd-soc-tegra30-i2s-objs := tegra30_i2s.o | ||
7 | 9 | ||
8 | obj-$(CONFIG_SND_SOC_TEGRA) += snd-soc-tegra-utils.o | ||
9 | obj-$(CONFIG_SND_SOC_TEGRA) += snd-soc-tegra-das.o | ||
10 | obj-$(CONFIG_SND_SOC_TEGRA) += snd-soc-tegra-pcm.o | 10 | obj-$(CONFIG_SND_SOC_TEGRA) += snd-soc-tegra-pcm.o |
11 | obj-$(CONFIG_SND_SOC_TEGRA_I2S) += snd-soc-tegra-i2s.o | 11 | obj-$(CONFIG_SND_SOC_TEGRA) += snd-soc-tegra-utils.o |
12 | obj-$(CONFIG_SND_SOC_TEGRA_SPDIF) += snd-soc-tegra-spdif.o | 12 | obj-$(CONFIG_SND_SOC_TEGRA20_DAS) += snd-soc-tegra20-das.o |
13 | obj-$(CONFIG_SND_SOC_TEGRA20_I2S) += snd-soc-tegra20-i2s.o | ||
14 | obj-$(CONFIG_SND_SOC_TEGRA20_SPDIF) += snd-soc-tegra20-spdif.o | ||
15 | obj-$(CONFIG_SND_SOC_TEGRA30_AHUB) += snd-soc-tegra30-ahub.o | ||
16 | obj-$(CONFIG_SND_SOC_TEGRA30_I2S) += snd-soc-tegra30-i2s.o | ||
13 | 17 | ||
14 | # Tegra machine Support | 18 | # Tegra machine Support |
19 | snd-soc-tegra-wm8753-objs := tegra_wm8753.o | ||
15 | snd-soc-tegra-wm8903-objs := tegra_wm8903.o | 20 | snd-soc-tegra-wm8903-objs := tegra_wm8903.o |
16 | snd-soc-tegra-trimslice-objs := trimslice.o | 21 | snd-soc-tegra-trimslice-objs := trimslice.o |
17 | snd-soc-tegra-alc5632-objs := tegra_alc5632.o | 22 | snd-soc-tegra-alc5632-objs := tegra_alc5632.o |
18 | 23 | ||
24 | obj-$(CONFIG_SND_SOC_TEGRA_WM8753) += snd-soc-tegra-wm8753.o | ||
19 | obj-$(CONFIG_SND_SOC_TEGRA_WM8903) += snd-soc-tegra-wm8903.o | 25 | obj-$(CONFIG_SND_SOC_TEGRA_WM8903) += snd-soc-tegra-wm8903.o |
20 | obj-$(CONFIG_SND_SOC_TEGRA_TRIMSLICE) += snd-soc-tegra-trimslice.o | 26 | obj-$(CONFIG_SND_SOC_TEGRA_TRIMSLICE) += snd-soc-tegra-trimslice.o |
21 | obj-$(CONFIG_SND_SOC_TEGRA_ALC5632) += snd-soc-tegra-alc5632.o | 27 | obj-$(CONFIG_SND_SOC_TEGRA_ALC5632) += snd-soc-tegra-alc5632.o |
diff --git a/sound/soc/tegra/tegra20_das.c b/sound/soc/tegra/tegra20_das.c new file mode 100644 index 000000000000..bf99296bce95 --- /dev/null +++ b/sound/soc/tegra/tegra20_das.c | |||
@@ -0,0 +1,233 @@ | |||
1 | /* | ||
2 | * tegra20_das.c - Tegra20 DAS driver | ||
3 | * | ||
4 | * Author: Stephen Warren <swarren@nvidia.com> | ||
5 | * Copyright (C) 2010 - NVIDIA, Inc. | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or | ||
8 | * modify it under the terms of the GNU General Public License | ||
9 | * version 2 as published by the Free Software Foundation. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, but | ||
12 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | * General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program; if not, write to the Free Software | ||
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
19 | * 02110-1301 USA | ||
20 | * | ||
21 | */ | ||
22 | |||
23 | #include <linux/device.h> | ||
24 | #include <linux/io.h> | ||
25 | #include <linux/module.h> | ||
26 | #include <linux/platform_device.h> | ||
27 | #include <linux/regmap.h> | ||
28 | #include <linux/slab.h> | ||
29 | #include <sound/soc.h> | ||
30 | #include "tegra20_das.h" | ||
31 | |||
32 | #define DRV_NAME "tegra20-das" | ||
33 | |||
34 | static struct tegra20_das *das; | ||
35 | |||
36 | static inline void tegra20_das_write(u32 reg, u32 val) | ||
37 | { | ||
38 | regmap_write(das->regmap, reg, val); | ||
39 | } | ||
40 | |||
41 | static inline u32 tegra20_das_read(u32 reg) | ||
42 | { | ||
43 | u32 val; | ||
44 | regmap_read(das->regmap, reg, &val); | ||
45 | return val; | ||
46 | } | ||
47 | |||
48 | int tegra20_das_connect_dap_to_dac(int dap, int dac) | ||
49 | { | ||
50 | u32 addr; | ||
51 | u32 reg; | ||
52 | |||
53 | if (!das) | ||
54 | return -ENODEV; | ||
55 | |||
56 | addr = TEGRA20_DAS_DAP_CTRL_SEL + | ||
57 | (dap * TEGRA20_DAS_DAP_CTRL_SEL_STRIDE); | ||
58 | reg = dac << TEGRA20_DAS_DAP_CTRL_SEL_DAP_CTRL_SEL_P; | ||
59 | |||
60 | tegra20_das_write(addr, reg); | ||
61 | |||
62 | return 0; | ||
63 | } | ||
64 | EXPORT_SYMBOL_GPL(tegra20_das_connect_dap_to_dac); | ||
65 | |||
66 | int tegra20_das_connect_dap_to_dap(int dap, int otherdap, int master, | ||
67 | int sdata1rx, int sdata2rx) | ||
68 | { | ||
69 | u32 addr; | ||
70 | u32 reg; | ||
71 | |||
72 | if (!das) | ||
73 | return -ENODEV; | ||
74 | |||
75 | addr = TEGRA20_DAS_DAP_CTRL_SEL + | ||
76 | (dap * TEGRA20_DAS_DAP_CTRL_SEL_STRIDE); | ||
77 | reg = otherdap << TEGRA20_DAS_DAP_CTRL_SEL_DAP_CTRL_SEL_P | | ||
78 | !!sdata2rx << TEGRA20_DAS_DAP_CTRL_SEL_DAP_SDATA2_TX_RX_P | | ||
79 | !!sdata1rx << TEGRA20_DAS_DAP_CTRL_SEL_DAP_SDATA1_TX_RX_P | | ||
80 | !!master << TEGRA20_DAS_DAP_CTRL_SEL_DAP_MS_SEL_P; | ||
81 | |||
82 | tegra20_das_write(addr, reg); | ||
83 | |||
84 | return 0; | ||
85 | } | ||
86 | EXPORT_SYMBOL_GPL(tegra20_das_connect_dap_to_dap); | ||
87 | |||
88 | int tegra20_das_connect_dac_to_dap(int dac, int dap) | ||
89 | { | ||
90 | u32 addr; | ||
91 | u32 reg; | ||
92 | |||
93 | if (!das) | ||
94 | return -ENODEV; | ||
95 | |||
96 | addr = TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL + | ||
97 | (dac * TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL_STRIDE); | ||
98 | reg = dap << TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_CLK_SEL_P | | ||
99 | dap << TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_SDATA1_SEL_P | | ||
100 | dap << TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_SDATA2_SEL_P; | ||
101 | |||
102 | tegra20_das_write(addr, reg); | ||
103 | |||
104 | return 0; | ||
105 | } | ||
106 | EXPORT_SYMBOL_GPL(tegra20_das_connect_dac_to_dap); | ||
107 | |||
108 | #define LAST_REG(name) \ | ||
109 | (TEGRA20_DAS_##name + \ | ||
110 | (TEGRA20_DAS_##name##_STRIDE * (TEGRA20_DAS_##name##_COUNT - 1))) | ||
111 | |||
112 | static bool tegra20_das_wr_rd_reg(struct device *dev, unsigned int reg) | ||
113 | { | ||
114 | if ((reg >= TEGRA20_DAS_DAP_CTRL_SEL) && | ||
115 | (reg <= LAST_REG(DAP_CTRL_SEL))) | ||
116 | return true; | ||
117 | if ((reg >= TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL) && | ||
118 | (reg <= LAST_REG(DAC_INPUT_DATA_CLK_SEL))) | ||
119 | return true; | ||
120 | |||
121 | return false; | ||
122 | } | ||
123 | |||
124 | static const struct regmap_config tegra20_das_regmap_config = { | ||
125 | .reg_bits = 32, | ||
126 | .reg_stride = 4, | ||
127 | .val_bits = 32, | ||
128 | .max_register = LAST_REG(DAC_INPUT_DATA_CLK_SEL), | ||
129 | .writeable_reg = tegra20_das_wr_rd_reg, | ||
130 | .readable_reg = tegra20_das_wr_rd_reg, | ||
131 | .cache_type = REGCACHE_RBTREE, | ||
132 | }; | ||
133 | |||
134 | static int __devinit tegra20_das_probe(struct platform_device *pdev) | ||
135 | { | ||
136 | struct resource *res, *region; | ||
137 | void __iomem *regs; | ||
138 | int ret = 0; | ||
139 | |||
140 | if (das) | ||
141 | return -ENODEV; | ||
142 | |||
143 | das = devm_kzalloc(&pdev->dev, sizeof(struct tegra20_das), GFP_KERNEL); | ||
144 | if (!das) { | ||
145 | dev_err(&pdev->dev, "Can't allocate tegra20_das\n"); | ||
146 | ret = -ENOMEM; | ||
147 | goto err; | ||
148 | } | ||
149 | das->dev = &pdev->dev; | ||
150 | |||
151 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
152 | if (!res) { | ||
153 | dev_err(&pdev->dev, "No memory resource\n"); | ||
154 | ret = -ENODEV; | ||
155 | goto err; | ||
156 | } | ||
157 | |||
158 | region = devm_request_mem_region(&pdev->dev, res->start, | ||
159 | resource_size(res), pdev->name); | ||
160 | if (!region) { | ||
161 | dev_err(&pdev->dev, "Memory region already claimed\n"); | ||
162 | ret = -EBUSY; | ||
163 | goto err; | ||
164 | } | ||
165 | |||
166 | regs = devm_ioremap(&pdev->dev, res->start, resource_size(res)); | ||
167 | if (!regs) { | ||
168 | dev_err(&pdev->dev, "ioremap failed\n"); | ||
169 | ret = -ENOMEM; | ||
170 | goto err; | ||
171 | } | ||
172 | |||
173 | das->regmap = devm_regmap_init_mmio(&pdev->dev, regs, | ||
174 | &tegra20_das_regmap_config); | ||
175 | if (IS_ERR(das->regmap)) { | ||
176 | dev_err(&pdev->dev, "regmap init failed\n"); | ||
177 | ret = PTR_ERR(das->regmap); | ||
178 | goto err; | ||
179 | } | ||
180 | |||
181 | ret = tegra20_das_connect_dap_to_dac(TEGRA20_DAS_DAP_ID_1, | ||
182 | TEGRA20_DAS_DAP_SEL_DAC1); | ||
183 | if (ret) { | ||
184 | dev_err(&pdev->dev, "Can't set up DAS DAP connection\n"); | ||
185 | goto err; | ||
186 | } | ||
187 | ret = tegra20_das_connect_dac_to_dap(TEGRA20_DAS_DAC_ID_1, | ||
188 | TEGRA20_DAS_DAC_SEL_DAP1); | ||
189 | if (ret) { | ||
190 | dev_err(&pdev->dev, "Can't set up DAS DAC connection\n"); | ||
191 | goto err; | ||
192 | } | ||
193 | |||
194 | platform_set_drvdata(pdev, das); | ||
195 | |||
196 | return 0; | ||
197 | |||
198 | err: | ||
199 | das = NULL; | ||
200 | return ret; | ||
201 | } | ||
202 | |||
203 | static int __devexit tegra20_das_remove(struct platform_device *pdev) | ||
204 | { | ||
205 | if (!das) | ||
206 | return -ENODEV; | ||
207 | |||
208 | das = NULL; | ||
209 | |||
210 | return 0; | ||
211 | } | ||
212 | |||
213 | static const struct of_device_id tegra20_das_of_match[] __devinitconst = { | ||
214 | { .compatible = "nvidia,tegra20-das", }, | ||
215 | {}, | ||
216 | }; | ||
217 | |||
218 | static struct platform_driver tegra20_das_driver = { | ||
219 | .probe = tegra20_das_probe, | ||
220 | .remove = __devexit_p(tegra20_das_remove), | ||
221 | .driver = { | ||
222 | .name = DRV_NAME, | ||
223 | .owner = THIS_MODULE, | ||
224 | .of_match_table = tegra20_das_of_match, | ||
225 | }, | ||
226 | }; | ||
227 | module_platform_driver(tegra20_das_driver); | ||
228 | |||
229 | MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>"); | ||
230 | MODULE_DESCRIPTION("Tegra20 DAS driver"); | ||
231 | MODULE_LICENSE("GPL"); | ||
232 | MODULE_ALIAS("platform:" DRV_NAME); | ||
233 | MODULE_DEVICE_TABLE(of, tegra20_das_of_match); | ||
diff --git a/sound/soc/tegra/tegra20_das.h b/sound/soc/tegra/tegra20_das.h new file mode 100644 index 000000000000..be217f3d3a75 --- /dev/null +++ b/sound/soc/tegra/tegra20_das.h | |||
@@ -0,0 +1,134 @@ | |||
1 | /* | ||
2 | * tegra20_das.h - Definitions for Tegra20 DAS driver | ||
3 | * | ||
4 | * Author: Stephen Warren <swarren@nvidia.com> | ||
5 | * Copyright (C) 2010,2012 - NVIDIA, Inc. | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or | ||
8 | * modify it under the terms of the GNU General Public License | ||
9 | * version 2 as published by the Free Software Foundation. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, but | ||
12 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | * General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program; if not, write to the Free Software | ||
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
19 | * 02110-1301 USA | ||
20 | * | ||
21 | */ | ||
22 | |||
23 | #ifndef __TEGRA20_DAS_H__ | ||
24 | #define __TEGRA20_DAS_H__ | ||
25 | |||
26 | /* Register TEGRA20_DAS_DAP_CTRL_SEL */ | ||
27 | #define TEGRA20_DAS_DAP_CTRL_SEL 0x00 | ||
28 | #define TEGRA20_DAS_DAP_CTRL_SEL_COUNT 5 | ||
29 | #define TEGRA20_DAS_DAP_CTRL_SEL_STRIDE 4 | ||
30 | #define TEGRA20_DAS_DAP_CTRL_SEL_DAP_MS_SEL_P 31 | ||
31 | #define TEGRA20_DAS_DAP_CTRL_SEL_DAP_MS_SEL_S 1 | ||
32 | #define TEGRA20_DAS_DAP_CTRL_SEL_DAP_SDATA1_TX_RX_P 30 | ||
33 | #define TEGRA20_DAS_DAP_CTRL_SEL_DAP_SDATA1_TX_RX_S 1 | ||
34 | #define TEGRA20_DAS_DAP_CTRL_SEL_DAP_SDATA2_TX_RX_P 29 | ||
35 | #define TEGRA20_DAS_DAP_CTRL_SEL_DAP_SDATA2_TX_RX_S 1 | ||
36 | #define TEGRA20_DAS_DAP_CTRL_SEL_DAP_CTRL_SEL_P 0 | ||
37 | #define TEGRA20_DAS_DAP_CTRL_SEL_DAP_CTRL_SEL_S 5 | ||
38 | |||
39 | /* Values for field TEGRA20_DAS_DAP_CTRL_SEL_DAP_CTRL_SEL */ | ||
40 | #define TEGRA20_DAS_DAP_SEL_DAC1 0 | ||
41 | #define TEGRA20_DAS_DAP_SEL_DAC2 1 | ||
42 | #define TEGRA20_DAS_DAP_SEL_DAC3 2 | ||
43 | #define TEGRA20_DAS_DAP_SEL_DAP1 16 | ||
44 | #define TEGRA20_DAS_DAP_SEL_DAP2 17 | ||
45 | #define TEGRA20_DAS_DAP_SEL_DAP3 18 | ||
46 | #define TEGRA20_DAS_DAP_SEL_DAP4 19 | ||
47 | #define TEGRA20_DAS_DAP_SEL_DAP5 20 | ||
48 | |||
49 | /* Register TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL */ | ||
50 | #define TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL 0x40 | ||
51 | #define TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL_COUNT 3 | ||
52 | #define TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL_STRIDE 4 | ||
53 | #define TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_SDATA2_SEL_P 28 | ||
54 | #define TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_SDATA2_SEL_S 4 | ||
55 | #define TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_SDATA1_SEL_P 24 | ||
56 | #define TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_SDATA1_SEL_S 4 | ||
57 | #define TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_CLK_SEL_P 0 | ||
58 | #define TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_CLK_SEL_S 4 | ||
59 | |||
60 | /* | ||
61 | * Values for: | ||
62 | * TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_SDATA2_SEL | ||
63 | * TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_SDATA1_SEL | ||
64 | * TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_CLK_SEL | ||
65 | */ | ||
66 | #define TEGRA20_DAS_DAC_SEL_DAP1 0 | ||
67 | #define TEGRA20_DAS_DAC_SEL_DAP2 1 | ||
68 | #define TEGRA20_DAS_DAC_SEL_DAP3 2 | ||
69 | #define TEGRA20_DAS_DAC_SEL_DAP4 3 | ||
70 | #define TEGRA20_DAS_DAC_SEL_DAP5 4 | ||
71 | |||
72 | /* | ||
73 | * Names/IDs of the DACs/DAPs. | ||
74 | */ | ||
75 | |||
76 | #define TEGRA20_DAS_DAP_ID_1 0 | ||
77 | #define TEGRA20_DAS_DAP_ID_2 1 | ||
78 | #define TEGRA20_DAS_DAP_ID_3 2 | ||
79 | #define TEGRA20_DAS_DAP_ID_4 3 | ||
80 | #define TEGRA20_DAS_DAP_ID_5 4 | ||
81 | |||
82 | #define TEGRA20_DAS_DAC_ID_1 0 | ||
83 | #define TEGRA20_DAS_DAC_ID_2 1 | ||
84 | #define TEGRA20_DAS_DAC_ID_3 2 | ||
85 | |||
86 | struct tegra20_das { | ||
87 | struct device *dev; | ||
88 | struct regmap *regmap; | ||
89 | }; | ||
90 | |||
91 | /* | ||
92 | * Terminology: | ||
93 | * DAS: Digital audio switch (HW module controlled by this driver) | ||
94 | * DAP: Digital audio port (port/pins on Tegra device) | ||
95 | * DAC: Digital audio controller (e.g. I2S or AC97 controller elsewhere) | ||
96 | * | ||
97 | * The Tegra DAS is a mux/cross-bar which can connect each DAP to a specific | ||
98 | * DAC, or another DAP. When DAPs are connected, one must be the master and | ||
99 | * one the slave. Each DAC allows selection of a specific DAP for input, to | ||
100 | * cater for the case where N DAPs are connected to 1 DAC for broadcast | ||
101 | * output. | ||
102 | * | ||
103 | * This driver is dumb; no attempt is made to ensure that a valid routing | ||
104 | * configuration is programmed. | ||
105 | */ | ||
106 | |||
107 | /* | ||
108 | * Connect a DAP to to a DAC | ||
109 | * dap_id: DAP to connect: TEGRA20_DAS_DAP_ID_* | ||
110 | * dac_sel: DAC to connect to: TEGRA20_DAS_DAP_SEL_DAC* | ||
111 | */ | ||
112 | extern int tegra20_das_connect_dap_to_dac(int dap_id, int dac_sel); | ||
113 | |||
114 | /* | ||
115 | * Connect a DAP to to another DAP | ||
116 | * dap_id: DAP to connect: TEGRA20_DAS_DAP_ID_* | ||
117 | * other_dap_sel: DAP to connect to: TEGRA20_DAS_DAP_SEL_DAP* | ||
118 | * master: Is this DAP the master (1) or slave (0) | ||
119 | * sdata1rx: Is this DAP's SDATA1 pin RX (1) or TX (0) | ||
120 | * sdata2rx: Is this DAP's SDATA2 pin RX (1) or TX (0) | ||
121 | */ | ||
122 | extern int tegra20_das_connect_dap_to_dap(int dap_id, int other_dap_sel, | ||
123 | int master, int sdata1rx, | ||
124 | int sdata2rx); | ||
125 | |||
126 | /* | ||
127 | * Connect a DAC's input to a DAP | ||
128 | * (DAC outputs are selected by the DAP) | ||
129 | * dac_id: DAC ID to connect: TEGRA20_DAS_DAC_ID_* | ||
130 | * dap_sel: DAP to receive input from: TEGRA20_DAS_DAC_SEL_DAP* | ||
131 | */ | ||
132 | extern int tegra20_das_connect_dac_to_dap(int dac_id, int dap_sel); | ||
133 | |||
134 | #endif | ||
diff --git a/sound/soc/tegra/tegra20_i2s.c b/sound/soc/tegra/tegra20_i2s.c new file mode 100644 index 000000000000..0c7af63d444b --- /dev/null +++ b/sound/soc/tegra/tegra20_i2s.c | |||
@@ -0,0 +1,494 @@ | |||
1 | /* | ||
2 | * tegra20_i2s.c - Tegra20 I2S driver | ||
3 | * | ||
4 | * Author: Stephen Warren <swarren@nvidia.com> | ||
5 | * Copyright (C) 2010,2012 - NVIDIA, Inc. | ||
6 | * | ||
7 | * Based on code copyright/by: | ||
8 | * | ||
9 | * Copyright (c) 2009-2010, NVIDIA Corporation. | ||
10 | * Scott Peterson <speterson@nvidia.com> | ||
11 | * | ||
12 | * Copyright (C) 2010 Google, Inc. | ||
13 | * Iliyan Malchev <malchev@google.com> | ||
14 | * | ||
15 | * This program is free software; you can redistribute it and/or | ||
16 | * modify it under the terms of the GNU General Public License | ||
17 | * version 2 as published by the Free Software Foundation. | ||
18 | * | ||
19 | * This program is distributed in the hope that it will be useful, but | ||
20 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
22 | * General Public License for more details. | ||
23 | * | ||
24 | * You should have received a copy of the GNU General Public License | ||
25 | * along with this program; if not, write to the Free Software | ||
26 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
27 | * 02110-1301 USA | ||
28 | * | ||
29 | */ | ||
30 | |||
31 | #include <linux/clk.h> | ||
32 | #include <linux/device.h> | ||
33 | #include <linux/io.h> | ||
34 | #include <linux/module.h> | ||
35 | #include <linux/of.h> | ||
36 | #include <linux/platform_device.h> | ||
37 | #include <linux/pm_runtime.h> | ||
38 | #include <linux/regmap.h> | ||
39 | #include <linux/slab.h> | ||
40 | #include <sound/core.h> | ||
41 | #include <sound/pcm.h> | ||
42 | #include <sound/pcm_params.h> | ||
43 | #include <sound/soc.h> | ||
44 | |||
45 | #include "tegra20_i2s.h" | ||
46 | |||
47 | #define DRV_NAME "tegra20-i2s" | ||
48 | |||
49 | static inline void tegra20_i2s_write(struct tegra20_i2s *i2s, u32 reg, u32 val) | ||
50 | { | ||
51 | regmap_write(i2s->regmap, reg, val); | ||
52 | } | ||
53 | |||
54 | static inline u32 tegra20_i2s_read(struct tegra20_i2s *i2s, u32 reg) | ||
55 | { | ||
56 | u32 val; | ||
57 | regmap_read(i2s->regmap, reg, &val); | ||
58 | return val; | ||
59 | } | ||
60 | |||
61 | static int tegra20_i2s_runtime_suspend(struct device *dev) | ||
62 | { | ||
63 | struct tegra20_i2s *i2s = dev_get_drvdata(dev); | ||
64 | |||
65 | clk_disable(i2s->clk_i2s); | ||
66 | |||
67 | return 0; | ||
68 | } | ||
69 | |||
70 | static int tegra20_i2s_runtime_resume(struct device *dev) | ||
71 | { | ||
72 | struct tegra20_i2s *i2s = dev_get_drvdata(dev); | ||
73 | int ret; | ||
74 | |||
75 | ret = clk_enable(i2s->clk_i2s); | ||
76 | if (ret) { | ||
77 | dev_err(dev, "clk_enable failed: %d\n", ret); | ||
78 | return ret; | ||
79 | } | ||
80 | |||
81 | return 0; | ||
82 | } | ||
83 | |||
84 | static int tegra20_i2s_set_fmt(struct snd_soc_dai *dai, | ||
85 | unsigned int fmt) | ||
86 | { | ||
87 | struct tegra20_i2s *i2s = snd_soc_dai_get_drvdata(dai); | ||
88 | |||
89 | switch (fmt & SND_SOC_DAIFMT_INV_MASK) { | ||
90 | case SND_SOC_DAIFMT_NB_NF: | ||
91 | break; | ||
92 | default: | ||
93 | return -EINVAL; | ||
94 | } | ||
95 | |||
96 | i2s->reg_ctrl &= ~TEGRA20_I2S_CTRL_MASTER_ENABLE; | ||
97 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { | ||
98 | case SND_SOC_DAIFMT_CBS_CFS: | ||
99 | i2s->reg_ctrl |= TEGRA20_I2S_CTRL_MASTER_ENABLE; | ||
100 | break; | ||
101 | case SND_SOC_DAIFMT_CBM_CFM: | ||
102 | break; | ||
103 | default: | ||
104 | return -EINVAL; | ||
105 | } | ||
106 | |||
107 | i2s->reg_ctrl &= ~(TEGRA20_I2S_CTRL_BIT_FORMAT_MASK | | ||
108 | TEGRA20_I2S_CTRL_LRCK_MASK); | ||
109 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { | ||
110 | case SND_SOC_DAIFMT_DSP_A: | ||
111 | i2s->reg_ctrl |= TEGRA20_I2S_CTRL_BIT_FORMAT_DSP; | ||
112 | i2s->reg_ctrl |= TEGRA20_I2S_CTRL_LRCK_L_LOW; | ||
113 | break; | ||
114 | case SND_SOC_DAIFMT_DSP_B: | ||
115 | i2s->reg_ctrl |= TEGRA20_I2S_CTRL_BIT_FORMAT_DSP; | ||
116 | i2s->reg_ctrl |= TEGRA20_I2S_CTRL_LRCK_R_LOW; | ||
117 | break; | ||
118 | case SND_SOC_DAIFMT_I2S: | ||
119 | i2s->reg_ctrl |= TEGRA20_I2S_CTRL_BIT_FORMAT_I2S; | ||
120 | i2s->reg_ctrl |= TEGRA20_I2S_CTRL_LRCK_L_LOW; | ||
121 | break; | ||
122 | case SND_SOC_DAIFMT_RIGHT_J: | ||
123 | i2s->reg_ctrl |= TEGRA20_I2S_CTRL_BIT_FORMAT_RJM; | ||
124 | i2s->reg_ctrl |= TEGRA20_I2S_CTRL_LRCK_L_LOW; | ||
125 | break; | ||
126 | case SND_SOC_DAIFMT_LEFT_J: | ||
127 | i2s->reg_ctrl |= TEGRA20_I2S_CTRL_BIT_FORMAT_LJM; | ||
128 | i2s->reg_ctrl |= TEGRA20_I2S_CTRL_LRCK_L_LOW; | ||
129 | break; | ||
130 | default: | ||
131 | return -EINVAL; | ||
132 | } | ||
133 | |||
134 | return 0; | ||
135 | } | ||
136 | |||
137 | static int tegra20_i2s_hw_params(struct snd_pcm_substream *substream, | ||
138 | struct snd_pcm_hw_params *params, | ||
139 | struct snd_soc_dai *dai) | ||
140 | { | ||
141 | struct device *dev = substream->pcm->card->dev; | ||
142 | struct tegra20_i2s *i2s = snd_soc_dai_get_drvdata(dai); | ||
143 | u32 reg; | ||
144 | int ret, sample_size, srate, i2sclock, bitcnt; | ||
145 | |||
146 | i2s->reg_ctrl &= ~TEGRA20_I2S_CTRL_BIT_SIZE_MASK; | ||
147 | switch (params_format(params)) { | ||
148 | case SNDRV_PCM_FORMAT_S16_LE: | ||
149 | i2s->reg_ctrl |= TEGRA20_I2S_CTRL_BIT_SIZE_16; | ||
150 | sample_size = 16; | ||
151 | break; | ||
152 | case SNDRV_PCM_FORMAT_S24_LE: | ||
153 | i2s->reg_ctrl |= TEGRA20_I2S_CTRL_BIT_SIZE_24; | ||
154 | sample_size = 24; | ||
155 | break; | ||
156 | case SNDRV_PCM_FORMAT_S32_LE: | ||
157 | i2s->reg_ctrl |= TEGRA20_I2S_CTRL_BIT_SIZE_32; | ||
158 | sample_size = 32; | ||
159 | break; | ||
160 | default: | ||
161 | return -EINVAL; | ||
162 | } | ||
163 | |||
164 | srate = params_rate(params); | ||
165 | |||
166 | /* Final "* 2" required by Tegra hardware */ | ||
167 | i2sclock = srate * params_channels(params) * sample_size * 2; | ||
168 | |||
169 | ret = clk_set_rate(i2s->clk_i2s, i2sclock); | ||
170 | if (ret) { | ||
171 | dev_err(dev, "Can't set I2S clock rate: %d\n", ret); | ||
172 | return ret; | ||
173 | } | ||
174 | |||
175 | bitcnt = (i2sclock / (2 * srate)) - 1; | ||
176 | if (bitcnt < 0 || bitcnt > TEGRA20_I2S_TIMING_CHANNEL_BIT_COUNT_MASK_US) | ||
177 | return -EINVAL; | ||
178 | reg = bitcnt << TEGRA20_I2S_TIMING_CHANNEL_BIT_COUNT_SHIFT; | ||
179 | |||
180 | if (i2sclock % (2 * srate)) | ||
181 | reg |= TEGRA20_I2S_TIMING_NON_SYM_ENABLE; | ||
182 | |||
183 | tegra20_i2s_write(i2s, TEGRA20_I2S_TIMING, reg); | ||
184 | |||
185 | tegra20_i2s_write(i2s, TEGRA20_I2S_FIFO_SCR, | ||
186 | TEGRA20_I2S_FIFO_SCR_FIFO2_ATN_LVL_FOUR_SLOTS | | ||
187 | TEGRA20_I2S_FIFO_SCR_FIFO1_ATN_LVL_FOUR_SLOTS); | ||
188 | |||
189 | return 0; | ||
190 | } | ||
191 | |||
192 | static void tegra20_i2s_start_playback(struct tegra20_i2s *i2s) | ||
193 | { | ||
194 | i2s->reg_ctrl |= TEGRA20_I2S_CTRL_FIFO1_ENABLE; | ||
195 | tegra20_i2s_write(i2s, TEGRA20_I2S_CTRL, i2s->reg_ctrl); | ||
196 | } | ||
197 | |||
198 | static void tegra20_i2s_stop_playback(struct tegra20_i2s *i2s) | ||
199 | { | ||
200 | i2s->reg_ctrl &= ~TEGRA20_I2S_CTRL_FIFO1_ENABLE; | ||
201 | tegra20_i2s_write(i2s, TEGRA20_I2S_CTRL, i2s->reg_ctrl); | ||
202 | } | ||
203 | |||
204 | static void tegra20_i2s_start_capture(struct tegra20_i2s *i2s) | ||
205 | { | ||
206 | i2s->reg_ctrl |= TEGRA20_I2S_CTRL_FIFO2_ENABLE; | ||
207 | tegra20_i2s_write(i2s, TEGRA20_I2S_CTRL, i2s->reg_ctrl); | ||
208 | } | ||
209 | |||
210 | static void tegra20_i2s_stop_capture(struct tegra20_i2s *i2s) | ||
211 | { | ||
212 | i2s->reg_ctrl &= ~TEGRA20_I2S_CTRL_FIFO2_ENABLE; | ||
213 | tegra20_i2s_write(i2s, TEGRA20_I2S_CTRL, i2s->reg_ctrl); | ||
214 | } | ||
215 | |||
216 | static int tegra20_i2s_trigger(struct snd_pcm_substream *substream, int cmd, | ||
217 | struct snd_soc_dai *dai) | ||
218 | { | ||
219 | struct tegra20_i2s *i2s = snd_soc_dai_get_drvdata(dai); | ||
220 | |||
221 | switch (cmd) { | ||
222 | case SNDRV_PCM_TRIGGER_START: | ||
223 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: | ||
224 | case SNDRV_PCM_TRIGGER_RESUME: | ||
225 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) | ||
226 | tegra20_i2s_start_playback(i2s); | ||
227 | else | ||
228 | tegra20_i2s_start_capture(i2s); | ||
229 | break; | ||
230 | case SNDRV_PCM_TRIGGER_STOP: | ||
231 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: | ||
232 | case SNDRV_PCM_TRIGGER_SUSPEND: | ||
233 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) | ||
234 | tegra20_i2s_stop_playback(i2s); | ||
235 | else | ||
236 | tegra20_i2s_stop_capture(i2s); | ||
237 | break; | ||
238 | default: | ||
239 | return -EINVAL; | ||
240 | } | ||
241 | |||
242 | return 0; | ||
243 | } | ||
244 | |||
245 | static int tegra20_i2s_probe(struct snd_soc_dai *dai) | ||
246 | { | ||
247 | struct tegra20_i2s *i2s = snd_soc_dai_get_drvdata(dai); | ||
248 | |||
249 | dai->capture_dma_data = &i2s->capture_dma_data; | ||
250 | dai->playback_dma_data = &i2s->playback_dma_data; | ||
251 | |||
252 | return 0; | ||
253 | } | ||
254 | |||
255 | static const struct snd_soc_dai_ops tegra20_i2s_dai_ops = { | ||
256 | .set_fmt = tegra20_i2s_set_fmt, | ||
257 | .hw_params = tegra20_i2s_hw_params, | ||
258 | .trigger = tegra20_i2s_trigger, | ||
259 | }; | ||
260 | |||
261 | static const struct snd_soc_dai_driver tegra20_i2s_dai_template = { | ||
262 | .probe = tegra20_i2s_probe, | ||
263 | .playback = { | ||
264 | .channels_min = 2, | ||
265 | .channels_max = 2, | ||
266 | .rates = SNDRV_PCM_RATE_8000_96000, | ||
267 | .formats = SNDRV_PCM_FMTBIT_S16_LE, | ||
268 | }, | ||
269 | .capture = { | ||
270 | .channels_min = 2, | ||
271 | .channels_max = 2, | ||
272 | .rates = SNDRV_PCM_RATE_8000_96000, | ||
273 | .formats = SNDRV_PCM_FMTBIT_S16_LE, | ||
274 | }, | ||
275 | .ops = &tegra20_i2s_dai_ops, | ||
276 | .symmetric_rates = 1, | ||
277 | }; | ||
278 | |||
279 | static bool tegra20_i2s_wr_rd_reg(struct device *dev, unsigned int reg) | ||
280 | { | ||
281 | switch (reg) { | ||
282 | case TEGRA20_I2S_CTRL: | ||
283 | case TEGRA20_I2S_STATUS: | ||
284 | case TEGRA20_I2S_TIMING: | ||
285 | case TEGRA20_I2S_FIFO_SCR: | ||
286 | case TEGRA20_I2S_PCM_CTRL: | ||
287 | case TEGRA20_I2S_NW_CTRL: | ||
288 | case TEGRA20_I2S_TDM_CTRL: | ||
289 | case TEGRA20_I2S_TDM_TX_RX_CTRL: | ||
290 | case TEGRA20_I2S_FIFO1: | ||
291 | case TEGRA20_I2S_FIFO2: | ||
292 | return true; | ||
293 | default: | ||
294 | return false; | ||
295 | }; | ||
296 | } | ||
297 | |||
298 | static bool tegra20_i2s_volatile_reg(struct device *dev, unsigned int reg) | ||
299 | { | ||
300 | switch (reg) { | ||
301 | case TEGRA20_I2S_STATUS: | ||
302 | case TEGRA20_I2S_FIFO_SCR: | ||
303 | case TEGRA20_I2S_FIFO1: | ||
304 | case TEGRA20_I2S_FIFO2: | ||
305 | return true; | ||
306 | default: | ||
307 | return false; | ||
308 | }; | ||
309 | } | ||
310 | |||
311 | static bool tegra20_i2s_precious_reg(struct device *dev, unsigned int reg) | ||
312 | { | ||
313 | switch (reg) { | ||
314 | case TEGRA20_I2S_FIFO1: | ||
315 | case TEGRA20_I2S_FIFO2: | ||
316 | return true; | ||
317 | default: | ||
318 | return false; | ||
319 | }; | ||
320 | } | ||
321 | |||
322 | static const struct regmap_config tegra20_i2s_regmap_config = { | ||
323 | .reg_bits = 32, | ||
324 | .reg_stride = 4, | ||
325 | .val_bits = 32, | ||
326 | .max_register = TEGRA20_I2S_FIFO2, | ||
327 | .writeable_reg = tegra20_i2s_wr_rd_reg, | ||
328 | .readable_reg = tegra20_i2s_wr_rd_reg, | ||
329 | .volatile_reg = tegra20_i2s_volatile_reg, | ||
330 | .precious_reg = tegra20_i2s_precious_reg, | ||
331 | .cache_type = REGCACHE_RBTREE, | ||
332 | }; | ||
333 | |||
334 | static __devinit int tegra20_i2s_platform_probe(struct platform_device *pdev) | ||
335 | { | ||
336 | struct tegra20_i2s *i2s; | ||
337 | struct resource *mem, *memregion, *dmareq; | ||
338 | u32 of_dma[2]; | ||
339 | u32 dma_ch; | ||
340 | void __iomem *regs; | ||
341 | int ret; | ||
342 | |||
343 | i2s = devm_kzalloc(&pdev->dev, sizeof(struct tegra20_i2s), GFP_KERNEL); | ||
344 | if (!i2s) { | ||
345 | dev_err(&pdev->dev, "Can't allocate tegra20_i2s\n"); | ||
346 | ret = -ENOMEM; | ||
347 | goto err; | ||
348 | } | ||
349 | dev_set_drvdata(&pdev->dev, i2s); | ||
350 | |||
351 | i2s->dai = tegra20_i2s_dai_template; | ||
352 | i2s->dai.name = dev_name(&pdev->dev); | ||
353 | |||
354 | i2s->clk_i2s = clk_get(&pdev->dev, NULL); | ||
355 | if (IS_ERR(i2s->clk_i2s)) { | ||
356 | dev_err(&pdev->dev, "Can't retrieve i2s clock\n"); | ||
357 | ret = PTR_ERR(i2s->clk_i2s); | ||
358 | goto err; | ||
359 | } | ||
360 | |||
361 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
362 | if (!mem) { | ||
363 | dev_err(&pdev->dev, "No memory resource\n"); | ||
364 | ret = -ENODEV; | ||
365 | goto err_clk_put; | ||
366 | } | ||
367 | |||
368 | dmareq = platform_get_resource(pdev, IORESOURCE_DMA, 0); | ||
369 | if (!dmareq) { | ||
370 | if (of_property_read_u32_array(pdev->dev.of_node, | ||
371 | "nvidia,dma-request-selector", | ||
372 | of_dma, 2) < 0) { | ||
373 | dev_err(&pdev->dev, "No DMA resource\n"); | ||
374 | ret = -ENODEV; | ||
375 | goto err_clk_put; | ||
376 | } | ||
377 | dma_ch = of_dma[1]; | ||
378 | } else { | ||
379 | dma_ch = dmareq->start; | ||
380 | } | ||
381 | |||
382 | memregion = devm_request_mem_region(&pdev->dev, mem->start, | ||
383 | resource_size(mem), DRV_NAME); | ||
384 | if (!memregion) { | ||
385 | dev_err(&pdev->dev, "Memory region already claimed\n"); | ||
386 | ret = -EBUSY; | ||
387 | goto err_clk_put; | ||
388 | } | ||
389 | |||
390 | regs = devm_ioremap(&pdev->dev, mem->start, resource_size(mem)); | ||
391 | if (!regs) { | ||
392 | dev_err(&pdev->dev, "ioremap failed\n"); | ||
393 | ret = -ENOMEM; | ||
394 | goto err_clk_put; | ||
395 | } | ||
396 | |||
397 | i2s->regmap = devm_regmap_init_mmio(&pdev->dev, regs, | ||
398 | &tegra20_i2s_regmap_config); | ||
399 | if (IS_ERR(i2s->regmap)) { | ||
400 | dev_err(&pdev->dev, "regmap init failed\n"); | ||
401 | ret = PTR_ERR(i2s->regmap); | ||
402 | goto err_clk_put; | ||
403 | } | ||
404 | |||
405 | i2s->capture_dma_data.addr = mem->start + TEGRA20_I2S_FIFO2; | ||
406 | i2s->capture_dma_data.wrap = 4; | ||
407 | i2s->capture_dma_data.width = 32; | ||
408 | i2s->capture_dma_data.req_sel = dma_ch; | ||
409 | |||
410 | i2s->playback_dma_data.addr = mem->start + TEGRA20_I2S_FIFO1; | ||
411 | i2s->playback_dma_data.wrap = 4; | ||
412 | i2s->playback_dma_data.width = 32; | ||
413 | i2s->playback_dma_data.req_sel = dma_ch; | ||
414 | |||
415 | i2s->reg_ctrl = TEGRA20_I2S_CTRL_FIFO_FORMAT_PACKED; | ||
416 | |||
417 | pm_runtime_enable(&pdev->dev); | ||
418 | if (!pm_runtime_enabled(&pdev->dev)) { | ||
419 | ret = tegra20_i2s_runtime_resume(&pdev->dev); | ||
420 | if (ret) | ||
421 | goto err_pm_disable; | ||
422 | } | ||
423 | |||
424 | ret = snd_soc_register_dai(&pdev->dev, &i2s->dai); | ||
425 | if (ret) { | ||
426 | dev_err(&pdev->dev, "Could not register DAI: %d\n", ret); | ||
427 | ret = -ENOMEM; | ||
428 | goto err_suspend; | ||
429 | } | ||
430 | |||
431 | ret = tegra_pcm_platform_register(&pdev->dev); | ||
432 | if (ret) { | ||
433 | dev_err(&pdev->dev, "Could not register PCM: %d\n", ret); | ||
434 | goto err_unregister_dai; | ||
435 | } | ||
436 | |||
437 | return 0; | ||
438 | |||
439 | err_unregister_dai: | ||
440 | snd_soc_unregister_dai(&pdev->dev); | ||
441 | err_suspend: | ||
442 | if (!pm_runtime_status_suspended(&pdev->dev)) | ||
443 | tegra20_i2s_runtime_suspend(&pdev->dev); | ||
444 | err_pm_disable: | ||
445 | pm_runtime_disable(&pdev->dev); | ||
446 | err_clk_put: | ||
447 | clk_put(i2s->clk_i2s); | ||
448 | err: | ||
449 | return ret; | ||
450 | } | ||
451 | |||
452 | static int __devexit tegra20_i2s_platform_remove(struct platform_device *pdev) | ||
453 | { | ||
454 | struct tegra20_i2s *i2s = dev_get_drvdata(&pdev->dev); | ||
455 | |||
456 | pm_runtime_disable(&pdev->dev); | ||
457 | if (!pm_runtime_status_suspended(&pdev->dev)) | ||
458 | tegra20_i2s_runtime_suspend(&pdev->dev); | ||
459 | |||
460 | tegra_pcm_platform_unregister(&pdev->dev); | ||
461 | snd_soc_unregister_dai(&pdev->dev); | ||
462 | |||
463 | clk_put(i2s->clk_i2s); | ||
464 | |||
465 | return 0; | ||
466 | } | ||
467 | |||
468 | static const struct of_device_id tegra20_i2s_of_match[] __devinitconst = { | ||
469 | { .compatible = "nvidia,tegra20-i2s", }, | ||
470 | {}, | ||
471 | }; | ||
472 | |||
473 | static const struct dev_pm_ops tegra20_i2s_pm_ops __devinitconst = { | ||
474 | SET_RUNTIME_PM_OPS(tegra20_i2s_runtime_suspend, | ||
475 | tegra20_i2s_runtime_resume, NULL) | ||
476 | }; | ||
477 | |||
478 | static struct platform_driver tegra20_i2s_driver = { | ||
479 | .driver = { | ||
480 | .name = DRV_NAME, | ||
481 | .owner = THIS_MODULE, | ||
482 | .of_match_table = tegra20_i2s_of_match, | ||
483 | .pm = &tegra20_i2s_pm_ops, | ||
484 | }, | ||
485 | .probe = tegra20_i2s_platform_probe, | ||
486 | .remove = __devexit_p(tegra20_i2s_platform_remove), | ||
487 | }; | ||
488 | module_platform_driver(tegra20_i2s_driver); | ||
489 | |||
490 | MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>"); | ||
491 | MODULE_DESCRIPTION("Tegra20 I2S ASoC driver"); | ||
492 | MODULE_LICENSE("GPL"); | ||
493 | MODULE_ALIAS("platform:" DRV_NAME); | ||
494 | MODULE_DEVICE_TABLE(of, tegra20_i2s_of_match); | ||
diff --git a/sound/soc/tegra/tegra20_i2s.h b/sound/soc/tegra/tegra20_i2s.h new file mode 100644 index 000000000000..a57efc6a597e --- /dev/null +++ b/sound/soc/tegra/tegra20_i2s.h | |||
@@ -0,0 +1,164 @@ | |||
1 | /* | ||
2 | * tegra20_i2s.h - Definitions for Tegra20 I2S driver | ||
3 | * | ||
4 | * Author: Stephen Warren <swarren@nvidia.com> | ||
5 | * Copyright (C) 2010,2012 - NVIDIA, Inc. | ||
6 | * | ||
7 | * Based on code copyright/by: | ||
8 | * | ||
9 | * Copyright (c) 2009-2010, NVIDIA Corporation. | ||
10 | * Scott Peterson <speterson@nvidia.com> | ||
11 | * | ||
12 | * Copyright (C) 2010 Google, Inc. | ||
13 | * Iliyan Malchev <malchev@google.com> | ||
14 | * | ||
15 | * This program is free software; you can redistribute it and/or | ||
16 | * modify it under the terms of the GNU General Public License | ||
17 | * version 2 as published by the Free Software Foundation. | ||
18 | * | ||
19 | * This program is distributed in the hope that it will be useful, but | ||
20 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
22 | * General Public License for more details. | ||
23 | * | ||
24 | * You should have received a copy of the GNU General Public License | ||
25 | * along with this program; if not, write to the Free Software | ||
26 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
27 | * 02110-1301 USA | ||
28 | * | ||
29 | */ | ||
30 | |||
31 | #ifndef __TEGRA20_I2S_H__ | ||
32 | #define __TEGRA20_I2S_H__ | ||
33 | |||
34 | #include "tegra_pcm.h" | ||
35 | |||
36 | /* Register offsets from TEGRA20_I2S1_BASE and TEGRA20_I2S2_BASE */ | ||
37 | |||
38 | #define TEGRA20_I2S_CTRL 0x00 | ||
39 | #define TEGRA20_I2S_STATUS 0x04 | ||
40 | #define TEGRA20_I2S_TIMING 0x08 | ||
41 | #define TEGRA20_I2S_FIFO_SCR 0x0c | ||
42 | #define TEGRA20_I2S_PCM_CTRL 0x10 | ||
43 | #define TEGRA20_I2S_NW_CTRL 0x14 | ||
44 | #define TEGRA20_I2S_TDM_CTRL 0x20 | ||
45 | #define TEGRA20_I2S_TDM_TX_RX_CTRL 0x24 | ||
46 | #define TEGRA20_I2S_FIFO1 0x40 | ||
47 | #define TEGRA20_I2S_FIFO2 0x80 | ||
48 | |||
49 | /* Fields in TEGRA20_I2S_CTRL */ | ||
50 | |||
51 | #define TEGRA20_I2S_CTRL_FIFO2_TX_ENABLE (1 << 30) | ||
52 | #define TEGRA20_I2S_CTRL_FIFO1_ENABLE (1 << 29) | ||
53 | #define TEGRA20_I2S_CTRL_FIFO2_ENABLE (1 << 28) | ||
54 | #define TEGRA20_I2S_CTRL_FIFO1_RX_ENABLE (1 << 27) | ||
55 | #define TEGRA20_I2S_CTRL_FIFO_LPBK_ENABLE (1 << 26) | ||
56 | #define TEGRA20_I2S_CTRL_MASTER_ENABLE (1 << 25) | ||
57 | |||
58 | #define TEGRA20_I2S_LRCK_LEFT_LOW 0 | ||
59 | #define TEGRA20_I2S_LRCK_RIGHT_LOW 1 | ||
60 | |||
61 | #define TEGRA20_I2S_CTRL_LRCK_SHIFT 24 | ||
62 | #define TEGRA20_I2S_CTRL_LRCK_MASK (1 << TEGRA20_I2S_CTRL_LRCK_SHIFT) | ||
63 | #define TEGRA20_I2S_CTRL_LRCK_L_LOW (TEGRA20_I2S_LRCK_LEFT_LOW << TEGRA20_I2S_CTRL_LRCK_SHIFT) | ||
64 | #define TEGRA20_I2S_CTRL_LRCK_R_LOW (TEGRA20_I2S_LRCK_RIGHT_LOW << TEGRA20_I2S_CTRL_LRCK_SHIFT) | ||
65 | |||
66 | #define TEGRA20_I2S_BIT_FORMAT_I2S 0 | ||
67 | #define TEGRA20_I2S_BIT_FORMAT_RJM 1 | ||
68 | #define TEGRA20_I2S_BIT_FORMAT_LJM 2 | ||
69 | #define TEGRA20_I2S_BIT_FORMAT_DSP 3 | ||
70 | |||
71 | #define TEGRA20_I2S_CTRL_BIT_FORMAT_SHIFT 10 | ||
72 | #define TEGRA20_I2S_CTRL_BIT_FORMAT_MASK (3 << TEGRA20_I2S_CTRL_BIT_FORMAT_SHIFT) | ||
73 | #define TEGRA20_I2S_CTRL_BIT_FORMAT_I2S (TEGRA20_I2S_BIT_FORMAT_I2S << TEGRA20_I2S_CTRL_BIT_FORMAT_SHIFT) | ||
74 | #define TEGRA20_I2S_CTRL_BIT_FORMAT_RJM (TEGRA20_I2S_BIT_FORMAT_RJM << TEGRA20_I2S_CTRL_BIT_FORMAT_SHIFT) | ||
75 | #define TEGRA20_I2S_CTRL_BIT_FORMAT_LJM (TEGRA20_I2S_BIT_FORMAT_LJM << TEGRA20_I2S_CTRL_BIT_FORMAT_SHIFT) | ||
76 | #define TEGRA20_I2S_CTRL_BIT_FORMAT_DSP (TEGRA20_I2S_BIT_FORMAT_DSP << TEGRA20_I2S_CTRL_BIT_FORMAT_SHIFT) | ||
77 | |||
78 | #define TEGRA20_I2S_BIT_SIZE_16 0 | ||
79 | #define TEGRA20_I2S_BIT_SIZE_20 1 | ||
80 | #define TEGRA20_I2S_BIT_SIZE_24 2 | ||
81 | #define TEGRA20_I2S_BIT_SIZE_32 3 | ||
82 | |||
83 | #define TEGRA20_I2S_CTRL_BIT_SIZE_SHIFT 8 | ||
84 | #define TEGRA20_I2S_CTRL_BIT_SIZE_MASK (3 << TEGRA20_I2S_CTRL_BIT_SIZE_SHIFT) | ||
85 | #define TEGRA20_I2S_CTRL_BIT_SIZE_16 (TEGRA20_I2S_BIT_SIZE_16 << TEGRA20_I2S_CTRL_BIT_SIZE_SHIFT) | ||
86 | #define TEGRA20_I2S_CTRL_BIT_SIZE_20 (TEGRA20_I2S_BIT_SIZE_20 << TEGRA20_I2S_CTRL_BIT_SIZE_SHIFT) | ||
87 | #define TEGRA20_I2S_CTRL_BIT_SIZE_24 (TEGRA20_I2S_BIT_SIZE_24 << TEGRA20_I2S_CTRL_BIT_SIZE_SHIFT) | ||
88 | #define TEGRA20_I2S_CTRL_BIT_SIZE_32 (TEGRA20_I2S_BIT_SIZE_32 << TEGRA20_I2S_CTRL_BIT_SIZE_SHIFT) | ||
89 | |||
90 | #define TEGRA20_I2S_FIFO_16_LSB 0 | ||
91 | #define TEGRA20_I2S_FIFO_20_LSB 1 | ||
92 | #define TEGRA20_I2S_FIFO_24_LSB 2 | ||
93 | #define TEGRA20_I2S_FIFO_32 3 | ||
94 | #define TEGRA20_I2S_FIFO_PACKED 7 | ||
95 | |||
96 | #define TEGRA20_I2S_CTRL_FIFO_FORMAT_SHIFT 4 | ||
97 | #define TEGRA20_I2S_CTRL_FIFO_FORMAT_MASK (7 << TEGRA20_I2S_CTRL_FIFO_FORMAT_SHIFT) | ||
98 | #define TEGRA20_I2S_CTRL_FIFO_FORMAT_16_LSB (TEGRA20_I2S_FIFO_16_LSB << TEGRA20_I2S_CTRL_FIFO_FORMAT_SHIFT) | ||
99 | #define TEGRA20_I2S_CTRL_FIFO_FORMAT_20_LSB (TEGRA20_I2S_FIFO_20_LSB << TEGRA20_I2S_CTRL_FIFO_FORMAT_SHIFT) | ||
100 | #define TEGRA20_I2S_CTRL_FIFO_FORMAT_24_LSB (TEGRA20_I2S_FIFO_24_LSB << TEGRA20_I2S_CTRL_FIFO_FORMAT_SHIFT) | ||
101 | #define TEGRA20_I2S_CTRL_FIFO_FORMAT_32 (TEGRA20_I2S_FIFO_32 << TEGRA20_I2S_CTRL_FIFO_FORMAT_SHIFT) | ||
102 | #define TEGRA20_I2S_CTRL_FIFO_FORMAT_PACKED (TEGRA20_I2S_FIFO_PACKED << TEGRA20_I2S_CTRL_FIFO_FORMAT_SHIFT) | ||
103 | |||
104 | #define TEGRA20_I2S_CTRL_IE_FIFO1_ERR (1 << 3) | ||
105 | #define TEGRA20_I2S_CTRL_IE_FIFO2_ERR (1 << 2) | ||
106 | #define TEGRA20_I2S_CTRL_QE_FIFO1 (1 << 1) | ||
107 | #define TEGRA20_I2S_CTRL_QE_FIFO2 (1 << 0) | ||
108 | |||
109 | /* Fields in TEGRA20_I2S_STATUS */ | ||
110 | |||
111 | #define TEGRA20_I2S_STATUS_FIFO1_RDY (1 << 31) | ||
112 | #define TEGRA20_I2S_STATUS_FIFO2_RDY (1 << 30) | ||
113 | #define TEGRA20_I2S_STATUS_FIFO1_BSY (1 << 29) | ||
114 | #define TEGRA20_I2S_STATUS_FIFO2_BSY (1 << 28) | ||
115 | #define TEGRA20_I2S_STATUS_FIFO1_ERR (1 << 3) | ||
116 | #define TEGRA20_I2S_STATUS_FIFO2_ERR (1 << 2) | ||
117 | #define TEGRA20_I2S_STATUS_QS_FIFO1 (1 << 1) | ||
118 | #define TEGRA20_I2S_STATUS_QS_FIFO2 (1 << 0) | ||
119 | |||
120 | /* Fields in TEGRA20_I2S_TIMING */ | ||
121 | |||
122 | #define TEGRA20_I2S_TIMING_NON_SYM_ENABLE (1 << 12) | ||
123 | #define TEGRA20_I2S_TIMING_CHANNEL_BIT_COUNT_SHIFT 0 | ||
124 | #define TEGRA20_I2S_TIMING_CHANNEL_BIT_COUNT_MASK_US 0x7fff | ||
125 | #define TEGRA20_I2S_TIMING_CHANNEL_BIT_COUNT_MASK (TEGRA20_I2S_TIMING_CHANNEL_BIT_COUNT_MASK_US << TEGRA20_I2S_TIMING_CHANNEL_BIT_COUNT_SHIFT) | ||
126 | |||
127 | /* Fields in TEGRA20_I2S_FIFO_SCR */ | ||
128 | |||
129 | #define TEGRA20_I2S_FIFO_SCR_FIFO2_FULL_EMPTY_COUNT_SHIFT 24 | ||
130 | #define TEGRA20_I2S_FIFO_SCR_FIFO1_FULL_EMPTY_COUNT_SHIFT 16 | ||
131 | #define TEGRA20_I2S_FIFO_SCR_FIFO_FULL_EMPTY_COUNT_MASK 0x3f | ||
132 | |||
133 | #define TEGRA20_I2S_FIFO_SCR_FIFO2_CLR (1 << 12) | ||
134 | #define TEGRA20_I2S_FIFO_SCR_FIFO1_CLR (1 << 8) | ||
135 | |||
136 | #define TEGRA20_I2S_FIFO_ATN_LVL_ONE_SLOT 0 | ||
137 | #define TEGRA20_I2S_FIFO_ATN_LVL_FOUR_SLOTS 1 | ||
138 | #define TEGRA20_I2S_FIFO_ATN_LVL_EIGHT_SLOTS 2 | ||
139 | #define TEGRA20_I2S_FIFO_ATN_LVL_TWELVE_SLOTS 3 | ||
140 | |||
141 | #define TEGRA20_I2S_FIFO_SCR_FIFO2_ATN_LVL_SHIFT 4 | ||
142 | #define TEGRA20_I2S_FIFO_SCR_FIFO2_ATN_LVL_MASK (3 << TEGRA20_I2S_FIFO_SCR_FIFO2_ATN_LVL_SHIFT) | ||
143 | #define TEGRA20_I2S_FIFO_SCR_FIFO2_ATN_LVL_ONE_SLOT (TEGRA20_I2S_FIFO_ATN_LVL_ONE_SLOT << TEGRA20_I2S_FIFO_SCR_FIFO2_ATN_LVL_SHIFT) | ||
144 | #define TEGRA20_I2S_FIFO_SCR_FIFO2_ATN_LVL_FOUR_SLOTS (TEGRA20_I2S_FIFO_ATN_LVL_FOUR_SLOTS << TEGRA20_I2S_FIFO_SCR_FIFO2_ATN_LVL_SHIFT) | ||
145 | #define TEGRA20_I2S_FIFO_SCR_FIFO2_ATN_LVL_EIGHT_SLOTS (TEGRA20_I2S_FIFO_ATN_LVL_EIGHT_SLOTS << TEGRA20_I2S_FIFO_SCR_FIFO2_ATN_LVL_SHIFT) | ||
146 | #define TEGRA20_I2S_FIFO_SCR_FIFO2_ATN_LVL_TWELVE_SLOTS (TEGRA20_I2S_FIFO_ATN_LVL_TWELVE_SLOTS << TEGRA20_I2S_FIFO_SCR_FIFO2_ATN_LVL_SHIFT) | ||
147 | |||
148 | #define TEGRA20_I2S_FIFO_SCR_FIFO1_ATN_LVL_SHIFT 0 | ||
149 | #define TEGRA20_I2S_FIFO_SCR_FIFO1_ATN_LVL_MASK (3 << TEGRA20_I2S_FIFO_SCR_FIFO1_ATN_LVL_SHIFT) | ||
150 | #define TEGRA20_I2S_FIFO_SCR_FIFO1_ATN_LVL_ONE_SLOT (TEGRA20_I2S_FIFO_ATN_LVL_ONE_SLOT << TEGRA20_I2S_FIFO_SCR_FIFO1_ATN_LVL_SHIFT) | ||
151 | #define TEGRA20_I2S_FIFO_SCR_FIFO1_ATN_LVL_FOUR_SLOTS (TEGRA20_I2S_FIFO_ATN_LVL_FOUR_SLOTS << TEGRA20_I2S_FIFO_SCR_FIFO1_ATN_LVL_SHIFT) | ||
152 | #define TEGRA20_I2S_FIFO_SCR_FIFO1_ATN_LVL_EIGHT_SLOTS (TEGRA20_I2S_FIFO_ATN_LVL_EIGHT_SLOTS << TEGRA20_I2S_FIFO_SCR_FIFO1_ATN_LVL_SHIFT) | ||
153 | #define TEGRA20_I2S_FIFO_SCR_FIFO1_ATN_LVL_TWELVE_SLOTS (TEGRA20_I2S_FIFO_ATN_LVL_TWELVE_SLOTS << TEGRA20_I2S_FIFO_SCR_FIFO1_ATN_LVL_SHIFT) | ||
154 | |||
155 | struct tegra20_i2s { | ||
156 | struct snd_soc_dai_driver dai; | ||
157 | struct clk *clk_i2s; | ||
158 | struct tegra_pcm_dma_params capture_dma_data; | ||
159 | struct tegra_pcm_dma_params playback_dma_data; | ||
160 | struct regmap *regmap; | ||
161 | u32 reg_ctrl; | ||
162 | }; | ||
163 | |||
164 | #endif | ||
diff --git a/sound/soc/tegra/tegra20_spdif.c b/sound/soc/tegra/tegra20_spdif.c new file mode 100644 index 000000000000..f9b57418bd08 --- /dev/null +++ b/sound/soc/tegra/tegra20_spdif.c | |||
@@ -0,0 +1,404 @@ | |||
1 | /* | ||
2 | * tegra20_spdif.c - Tegra20 SPDIF driver | ||
3 | * | ||
4 | * Author: Stephen Warren <swarren@nvidia.com> | ||
5 | * Copyright (C) 2011-2012 - NVIDIA, Inc. | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or | ||
8 | * modify it under the terms of the GNU General Public License | ||
9 | * version 2 as published by the Free Software Foundation. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, but | ||
12 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | * General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program; if not, write to the Free Software | ||
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
19 | * 02110-1301 USA | ||
20 | * | ||
21 | */ | ||
22 | |||
23 | #include <linux/clk.h> | ||
24 | #include <linux/device.h> | ||
25 | #include <linux/io.h> | ||
26 | #include <linux/module.h> | ||
27 | #include <linux/platform_device.h> | ||
28 | #include <linux/pm_runtime.h> | ||
29 | #include <linux/regmap.h> | ||
30 | #include <linux/slab.h> | ||
31 | #include <sound/core.h> | ||
32 | #include <sound/pcm.h> | ||
33 | #include <sound/pcm_params.h> | ||
34 | #include <sound/soc.h> | ||
35 | |||
36 | #include "tegra20_spdif.h" | ||
37 | |||
38 | #define DRV_NAME "tegra20-spdif" | ||
39 | |||
40 | static inline void tegra20_spdif_write(struct tegra20_spdif *spdif, u32 reg, | ||
41 | u32 val) | ||
42 | { | ||
43 | regmap_write(spdif->regmap, reg, val); | ||
44 | } | ||
45 | |||
46 | static inline u32 tegra20_spdif_read(struct tegra20_spdif *spdif, u32 reg) | ||
47 | { | ||
48 | u32 val; | ||
49 | regmap_read(spdif->regmap, reg, &val); | ||
50 | return val; | ||
51 | } | ||
52 | |||
53 | static int tegra20_spdif_runtime_suspend(struct device *dev) | ||
54 | { | ||
55 | struct tegra20_spdif *spdif = dev_get_drvdata(dev); | ||
56 | |||
57 | clk_disable(spdif->clk_spdif_out); | ||
58 | |||
59 | return 0; | ||
60 | } | ||
61 | |||
62 | static int tegra20_spdif_runtime_resume(struct device *dev) | ||
63 | { | ||
64 | struct tegra20_spdif *spdif = dev_get_drvdata(dev); | ||
65 | int ret; | ||
66 | |||
67 | ret = clk_enable(spdif->clk_spdif_out); | ||
68 | if (ret) { | ||
69 | dev_err(dev, "clk_enable failed: %d\n", ret); | ||
70 | return ret; | ||
71 | } | ||
72 | |||
73 | return 0; | ||
74 | } | ||
75 | |||
76 | static int tegra20_spdif_hw_params(struct snd_pcm_substream *substream, | ||
77 | struct snd_pcm_hw_params *params, | ||
78 | struct snd_soc_dai *dai) | ||
79 | { | ||
80 | struct device *dev = substream->pcm->card->dev; | ||
81 | struct tegra20_spdif *spdif = snd_soc_dai_get_drvdata(dai); | ||
82 | int ret, spdifclock; | ||
83 | |||
84 | spdif->reg_ctrl &= ~TEGRA20_SPDIF_CTRL_PACK; | ||
85 | spdif->reg_ctrl &= ~TEGRA20_SPDIF_CTRL_BIT_MODE_MASK; | ||
86 | switch (params_format(params)) { | ||
87 | case SNDRV_PCM_FORMAT_S16_LE: | ||
88 | spdif->reg_ctrl |= TEGRA20_SPDIF_CTRL_PACK; | ||
89 | spdif->reg_ctrl |= TEGRA20_SPDIF_CTRL_BIT_MODE_16BIT; | ||
90 | break; | ||
91 | default: | ||
92 | return -EINVAL; | ||
93 | } | ||
94 | |||
95 | switch (params_rate(params)) { | ||
96 | case 32000: | ||
97 | spdifclock = 4096000; | ||
98 | break; | ||
99 | case 44100: | ||
100 | spdifclock = 5644800; | ||
101 | break; | ||
102 | case 48000: | ||
103 | spdifclock = 6144000; | ||
104 | break; | ||
105 | case 88200: | ||
106 | spdifclock = 11289600; | ||
107 | break; | ||
108 | case 96000: | ||
109 | spdifclock = 12288000; | ||
110 | break; | ||
111 | case 176400: | ||
112 | spdifclock = 22579200; | ||
113 | break; | ||
114 | case 192000: | ||
115 | spdifclock = 24576000; | ||
116 | break; | ||
117 | default: | ||
118 | return -EINVAL; | ||
119 | } | ||
120 | |||
121 | ret = clk_set_rate(spdif->clk_spdif_out, spdifclock); | ||
122 | if (ret) { | ||
123 | dev_err(dev, "Can't set SPDIF clock rate: %d\n", ret); | ||
124 | return ret; | ||
125 | } | ||
126 | |||
127 | return 0; | ||
128 | } | ||
129 | |||
130 | static void tegra20_spdif_start_playback(struct tegra20_spdif *spdif) | ||
131 | { | ||
132 | spdif->reg_ctrl |= TEGRA20_SPDIF_CTRL_TX_EN; | ||
133 | tegra20_spdif_write(spdif, TEGRA20_SPDIF_CTRL, spdif->reg_ctrl); | ||
134 | } | ||
135 | |||
136 | static void tegra20_spdif_stop_playback(struct tegra20_spdif *spdif) | ||
137 | { | ||
138 | spdif->reg_ctrl &= ~TEGRA20_SPDIF_CTRL_TX_EN; | ||
139 | tegra20_spdif_write(spdif, TEGRA20_SPDIF_CTRL, spdif->reg_ctrl); | ||
140 | } | ||
141 | |||
142 | static int tegra20_spdif_trigger(struct snd_pcm_substream *substream, int cmd, | ||
143 | struct snd_soc_dai *dai) | ||
144 | { | ||
145 | struct tegra20_spdif *spdif = snd_soc_dai_get_drvdata(dai); | ||
146 | |||
147 | switch (cmd) { | ||
148 | case SNDRV_PCM_TRIGGER_START: | ||
149 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: | ||
150 | case SNDRV_PCM_TRIGGER_RESUME: | ||
151 | tegra20_spdif_start_playback(spdif); | ||
152 | break; | ||
153 | case SNDRV_PCM_TRIGGER_STOP: | ||
154 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: | ||
155 | case SNDRV_PCM_TRIGGER_SUSPEND: | ||
156 | tegra20_spdif_stop_playback(spdif); | ||
157 | break; | ||
158 | default: | ||
159 | return -EINVAL; | ||
160 | } | ||
161 | |||
162 | return 0; | ||
163 | } | ||
164 | |||
165 | static int tegra20_spdif_probe(struct snd_soc_dai *dai) | ||
166 | { | ||
167 | struct tegra20_spdif *spdif = snd_soc_dai_get_drvdata(dai); | ||
168 | |||
169 | dai->capture_dma_data = NULL; | ||
170 | dai->playback_dma_data = &spdif->playback_dma_data; | ||
171 | |||
172 | return 0; | ||
173 | } | ||
174 | |||
175 | static const struct snd_soc_dai_ops tegra20_spdif_dai_ops = { | ||
176 | .hw_params = tegra20_spdif_hw_params, | ||
177 | .trigger = tegra20_spdif_trigger, | ||
178 | }; | ||
179 | |||
180 | static struct snd_soc_dai_driver tegra20_spdif_dai = { | ||
181 | .name = DRV_NAME, | ||
182 | .probe = tegra20_spdif_probe, | ||
183 | .playback = { | ||
184 | .channels_min = 2, | ||
185 | .channels_max = 2, | ||
186 | .rates = SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | | ||
187 | SNDRV_PCM_RATE_48000, | ||
188 | .formats = SNDRV_PCM_FMTBIT_S16_LE, | ||
189 | }, | ||
190 | .ops = &tegra20_spdif_dai_ops, | ||
191 | }; | ||
192 | |||
193 | static bool tegra20_spdif_wr_rd_reg(struct device *dev, unsigned int reg) | ||
194 | { | ||
195 | switch (reg) { | ||
196 | case TEGRA20_SPDIF_CTRL: | ||
197 | case TEGRA20_SPDIF_STATUS: | ||
198 | case TEGRA20_SPDIF_STROBE_CTRL: | ||
199 | case TEGRA20_SPDIF_DATA_FIFO_CSR: | ||
200 | case TEGRA20_SPDIF_DATA_OUT: | ||
201 | case TEGRA20_SPDIF_DATA_IN: | ||
202 | case TEGRA20_SPDIF_CH_STA_RX_A: | ||
203 | case TEGRA20_SPDIF_CH_STA_RX_B: | ||
204 | case TEGRA20_SPDIF_CH_STA_RX_C: | ||
205 | case TEGRA20_SPDIF_CH_STA_RX_D: | ||
206 | case TEGRA20_SPDIF_CH_STA_RX_E: | ||
207 | case TEGRA20_SPDIF_CH_STA_RX_F: | ||
208 | case TEGRA20_SPDIF_CH_STA_TX_A: | ||
209 | case TEGRA20_SPDIF_CH_STA_TX_B: | ||
210 | case TEGRA20_SPDIF_CH_STA_TX_C: | ||
211 | case TEGRA20_SPDIF_CH_STA_TX_D: | ||
212 | case TEGRA20_SPDIF_CH_STA_TX_E: | ||
213 | case TEGRA20_SPDIF_CH_STA_TX_F: | ||
214 | case TEGRA20_SPDIF_USR_STA_RX_A: | ||
215 | case TEGRA20_SPDIF_USR_DAT_TX_A: | ||
216 | return true; | ||
217 | default: | ||
218 | return false; | ||
219 | }; | ||
220 | } | ||
221 | |||
222 | static bool tegra20_spdif_volatile_reg(struct device *dev, unsigned int reg) | ||
223 | { | ||
224 | switch (reg) { | ||
225 | case TEGRA20_SPDIF_STATUS: | ||
226 | case TEGRA20_SPDIF_DATA_FIFO_CSR: | ||
227 | case TEGRA20_SPDIF_DATA_OUT: | ||
228 | case TEGRA20_SPDIF_DATA_IN: | ||
229 | case TEGRA20_SPDIF_CH_STA_RX_A: | ||
230 | case TEGRA20_SPDIF_CH_STA_RX_B: | ||
231 | case TEGRA20_SPDIF_CH_STA_RX_C: | ||
232 | case TEGRA20_SPDIF_CH_STA_RX_D: | ||
233 | case TEGRA20_SPDIF_CH_STA_RX_E: | ||
234 | case TEGRA20_SPDIF_CH_STA_RX_F: | ||
235 | case TEGRA20_SPDIF_USR_STA_RX_A: | ||
236 | case TEGRA20_SPDIF_USR_DAT_TX_A: | ||
237 | return true; | ||
238 | default: | ||
239 | return false; | ||
240 | }; | ||
241 | } | ||
242 | |||
243 | static bool tegra20_spdif_precious_reg(struct device *dev, unsigned int reg) | ||
244 | { | ||
245 | switch (reg) { | ||
246 | case TEGRA20_SPDIF_DATA_OUT: | ||
247 | case TEGRA20_SPDIF_DATA_IN: | ||
248 | case TEGRA20_SPDIF_USR_STA_RX_A: | ||
249 | case TEGRA20_SPDIF_USR_DAT_TX_A: | ||
250 | return true; | ||
251 | default: | ||
252 | return false; | ||
253 | }; | ||
254 | } | ||
255 | |||
256 | static const struct regmap_config tegra20_spdif_regmap_config = { | ||
257 | .reg_bits = 32, | ||
258 | .reg_stride = 4, | ||
259 | .val_bits = 32, | ||
260 | .max_register = TEGRA20_SPDIF_USR_DAT_TX_A, | ||
261 | .writeable_reg = tegra20_spdif_wr_rd_reg, | ||
262 | .readable_reg = tegra20_spdif_wr_rd_reg, | ||
263 | .volatile_reg = tegra20_spdif_volatile_reg, | ||
264 | .precious_reg = tegra20_spdif_precious_reg, | ||
265 | .cache_type = REGCACHE_RBTREE, | ||
266 | }; | ||
267 | |||
268 | static __devinit int tegra20_spdif_platform_probe(struct platform_device *pdev) | ||
269 | { | ||
270 | struct tegra20_spdif *spdif; | ||
271 | struct resource *mem, *memregion, *dmareq; | ||
272 | void __iomem *regs; | ||
273 | int ret; | ||
274 | |||
275 | spdif = devm_kzalloc(&pdev->dev, sizeof(struct tegra20_spdif), | ||
276 | GFP_KERNEL); | ||
277 | if (!spdif) { | ||
278 | dev_err(&pdev->dev, "Can't allocate tegra20_spdif\n"); | ||
279 | ret = -ENOMEM; | ||
280 | goto err; | ||
281 | } | ||
282 | dev_set_drvdata(&pdev->dev, spdif); | ||
283 | |||
284 | spdif->clk_spdif_out = clk_get(&pdev->dev, "spdif_out"); | ||
285 | if (IS_ERR(spdif->clk_spdif_out)) { | ||
286 | pr_err("Can't retrieve spdif clock\n"); | ||
287 | ret = PTR_ERR(spdif->clk_spdif_out); | ||
288 | goto err; | ||
289 | } | ||
290 | |||
291 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
292 | if (!mem) { | ||
293 | dev_err(&pdev->dev, "No memory resource\n"); | ||
294 | ret = -ENODEV; | ||
295 | goto err_clk_put; | ||
296 | } | ||
297 | |||
298 | dmareq = platform_get_resource(pdev, IORESOURCE_DMA, 0); | ||
299 | if (!dmareq) { | ||
300 | dev_err(&pdev->dev, "No DMA resource\n"); | ||
301 | ret = -ENODEV; | ||
302 | goto err_clk_put; | ||
303 | } | ||
304 | |||
305 | memregion = devm_request_mem_region(&pdev->dev, mem->start, | ||
306 | resource_size(mem), DRV_NAME); | ||
307 | if (!memregion) { | ||
308 | dev_err(&pdev->dev, "Memory region already claimed\n"); | ||
309 | ret = -EBUSY; | ||
310 | goto err_clk_put; | ||
311 | } | ||
312 | |||
313 | regs = devm_ioremap(&pdev->dev, mem->start, resource_size(mem)); | ||
314 | if (!regs) { | ||
315 | dev_err(&pdev->dev, "ioremap failed\n"); | ||
316 | ret = -ENOMEM; | ||
317 | goto err_clk_put; | ||
318 | } | ||
319 | |||
320 | spdif->regmap = devm_regmap_init_mmio(&pdev->dev, regs, | ||
321 | &tegra20_spdif_regmap_config); | ||
322 | if (IS_ERR(spdif->regmap)) { | ||
323 | dev_err(&pdev->dev, "regmap init failed\n"); | ||
324 | ret = PTR_ERR(spdif->regmap); | ||
325 | goto err_clk_put; | ||
326 | } | ||
327 | |||
328 | spdif->playback_dma_data.addr = mem->start + TEGRA20_SPDIF_DATA_OUT; | ||
329 | spdif->playback_dma_data.wrap = 4; | ||
330 | spdif->playback_dma_data.width = 32; | ||
331 | spdif->playback_dma_data.req_sel = dmareq->start; | ||
332 | |||
333 | pm_runtime_enable(&pdev->dev); | ||
334 | if (!pm_runtime_enabled(&pdev->dev)) { | ||
335 | ret = tegra20_spdif_runtime_resume(&pdev->dev); | ||
336 | if (ret) | ||
337 | goto err_pm_disable; | ||
338 | } | ||
339 | |||
340 | ret = snd_soc_register_dai(&pdev->dev, &tegra20_spdif_dai); | ||
341 | if (ret) { | ||
342 | dev_err(&pdev->dev, "Could not register DAI: %d\n", ret); | ||
343 | ret = -ENOMEM; | ||
344 | goto err_suspend; | ||
345 | } | ||
346 | |||
347 | ret = tegra_pcm_platform_register(&pdev->dev); | ||
348 | if (ret) { | ||
349 | dev_err(&pdev->dev, "Could not register PCM: %d\n", ret); | ||
350 | goto err_unregister_dai; | ||
351 | } | ||
352 | |||
353 | return 0; | ||
354 | |||
355 | err_unregister_dai: | ||
356 | snd_soc_unregister_dai(&pdev->dev); | ||
357 | err_suspend: | ||
358 | if (!pm_runtime_status_suspended(&pdev->dev)) | ||
359 | tegra20_spdif_runtime_suspend(&pdev->dev); | ||
360 | err_pm_disable: | ||
361 | pm_runtime_disable(&pdev->dev); | ||
362 | err_clk_put: | ||
363 | clk_put(spdif->clk_spdif_out); | ||
364 | err: | ||
365 | return ret; | ||
366 | } | ||
367 | |||
368 | static int __devexit tegra20_spdif_platform_remove(struct platform_device *pdev) | ||
369 | { | ||
370 | struct tegra20_spdif *spdif = dev_get_drvdata(&pdev->dev); | ||
371 | |||
372 | pm_runtime_disable(&pdev->dev); | ||
373 | if (!pm_runtime_status_suspended(&pdev->dev)) | ||
374 | tegra20_spdif_runtime_suspend(&pdev->dev); | ||
375 | |||
376 | tegra_pcm_platform_unregister(&pdev->dev); | ||
377 | snd_soc_unregister_dai(&pdev->dev); | ||
378 | |||
379 | clk_put(spdif->clk_spdif_out); | ||
380 | |||
381 | return 0; | ||
382 | } | ||
383 | |||
384 | static const struct dev_pm_ops tegra20_spdif_pm_ops __devinitconst = { | ||
385 | SET_RUNTIME_PM_OPS(tegra20_spdif_runtime_suspend, | ||
386 | tegra20_spdif_runtime_resume, NULL) | ||
387 | }; | ||
388 | |||
389 | static struct platform_driver tegra20_spdif_driver = { | ||
390 | .driver = { | ||
391 | .name = DRV_NAME, | ||
392 | .owner = THIS_MODULE, | ||
393 | .pm = &tegra20_spdif_pm_ops, | ||
394 | }, | ||
395 | .probe = tegra20_spdif_platform_probe, | ||
396 | .remove = __devexit_p(tegra20_spdif_platform_remove), | ||
397 | }; | ||
398 | |||
399 | module_platform_driver(tegra20_spdif_driver); | ||
400 | |||
401 | MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>"); | ||
402 | MODULE_DESCRIPTION("Tegra20 SPDIF ASoC driver"); | ||
403 | MODULE_LICENSE("GPL"); | ||
404 | MODULE_ALIAS("platform:" DRV_NAME); | ||
diff --git a/sound/soc/tegra/tegra20_spdif.h b/sound/soc/tegra/tegra20_spdif.h new file mode 100644 index 000000000000..ed756527efea --- /dev/null +++ b/sound/soc/tegra/tegra20_spdif.h | |||
@@ -0,0 +1,471 @@ | |||
1 | /* | ||
2 | * tegra20_spdif.h - Definitions for Tegra20 SPDIF driver | ||
3 | * | ||
4 | * Author: Stephen Warren <swarren@nvidia.com> | ||
5 | * Copyright (C) 2011 - NVIDIA, Inc. | ||
6 | * | ||
7 | * Based on code copyright/by: | ||
8 | * Copyright (c) 2008-2009, NVIDIA Corporation | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or | ||
11 | * modify it under the terms of the GNU General Public License | ||
12 | * version 2 as published by the Free Software Foundation. | ||
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, but | ||
15 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
17 | * General Public License for more details. | ||
18 | * | ||
19 | * You should have received a copy of the GNU General Public License | ||
20 | * along with this program; if not, write to the Free Software | ||
21 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
22 | * 02110-1301 USA | ||
23 | * | ||
24 | */ | ||
25 | |||
26 | #ifndef __TEGRA20_SPDIF_H__ | ||
27 | #define __TEGRA20_SPDIF_H__ | ||
28 | |||
29 | #include "tegra_pcm.h" | ||
30 | |||
31 | /* Offsets from TEGRA20_SPDIF_BASE */ | ||
32 | |||
33 | #define TEGRA20_SPDIF_CTRL 0x0 | ||
34 | #define TEGRA20_SPDIF_STATUS 0x4 | ||
35 | #define TEGRA20_SPDIF_STROBE_CTRL 0x8 | ||
36 | #define TEGRA20_SPDIF_DATA_FIFO_CSR 0x0C | ||
37 | #define TEGRA20_SPDIF_DATA_OUT 0x40 | ||
38 | #define TEGRA20_SPDIF_DATA_IN 0x80 | ||
39 | #define TEGRA20_SPDIF_CH_STA_RX_A 0x100 | ||
40 | #define TEGRA20_SPDIF_CH_STA_RX_B 0x104 | ||
41 | #define TEGRA20_SPDIF_CH_STA_RX_C 0x108 | ||
42 | #define TEGRA20_SPDIF_CH_STA_RX_D 0x10C | ||
43 | #define TEGRA20_SPDIF_CH_STA_RX_E 0x110 | ||
44 | #define TEGRA20_SPDIF_CH_STA_RX_F 0x114 | ||
45 | #define TEGRA20_SPDIF_CH_STA_TX_A 0x140 | ||
46 | #define TEGRA20_SPDIF_CH_STA_TX_B 0x144 | ||
47 | #define TEGRA20_SPDIF_CH_STA_TX_C 0x148 | ||
48 | #define TEGRA20_SPDIF_CH_STA_TX_D 0x14C | ||
49 | #define TEGRA20_SPDIF_CH_STA_TX_E 0x150 | ||
50 | #define TEGRA20_SPDIF_CH_STA_TX_F 0x154 | ||
51 | #define TEGRA20_SPDIF_USR_STA_RX_A 0x180 | ||
52 | #define TEGRA20_SPDIF_USR_DAT_TX_A 0x1C0 | ||
53 | |||
54 | /* Fields in TEGRA20_SPDIF_CTRL */ | ||
55 | |||
56 | /* Start capturing from 0=right, 1=left channel */ | ||
57 | #define TEGRA20_SPDIF_CTRL_CAP_LC (1 << 30) | ||
58 | |||
59 | /* SPDIF receiver(RX) enable */ | ||
60 | #define TEGRA20_SPDIF_CTRL_RX_EN (1 << 29) | ||
61 | |||
62 | /* SPDIF Transmitter(TX) enable */ | ||
63 | #define TEGRA20_SPDIF_CTRL_TX_EN (1 << 28) | ||
64 | |||
65 | /* Transmit Channel status */ | ||
66 | #define TEGRA20_SPDIF_CTRL_TC_EN (1 << 27) | ||
67 | |||
68 | /* Transmit user Data */ | ||
69 | #define TEGRA20_SPDIF_CTRL_TU_EN (1 << 26) | ||
70 | |||
71 | /* Interrupt on transmit error */ | ||
72 | #define TEGRA20_SPDIF_CTRL_IE_TXE (1 << 25) | ||
73 | |||
74 | /* Interrupt on receive error */ | ||
75 | #define TEGRA20_SPDIF_CTRL_IE_RXE (1 << 24) | ||
76 | |||
77 | /* Interrupt on invalid preamble */ | ||
78 | #define TEGRA20_SPDIF_CTRL_IE_P (1 << 23) | ||
79 | |||
80 | /* Interrupt on "B" preamble */ | ||
81 | #define TEGRA20_SPDIF_CTRL_IE_B (1 << 22) | ||
82 | |||
83 | /* Interrupt when block of channel status received */ | ||
84 | #define TEGRA20_SPDIF_CTRL_IE_C (1 << 21) | ||
85 | |||
86 | /* Interrupt when a valid information unit (IU) is received */ | ||
87 | #define TEGRA20_SPDIF_CTRL_IE_U (1 << 20) | ||
88 | |||
89 | /* Interrupt when RX user FIFO attention level is reached */ | ||
90 | #define TEGRA20_SPDIF_CTRL_QE_RU (1 << 19) | ||
91 | |||
92 | /* Interrupt when TX user FIFO attention level is reached */ | ||
93 | #define TEGRA20_SPDIF_CTRL_QE_TU (1 << 18) | ||
94 | |||
95 | /* Interrupt when RX data FIFO attention level is reached */ | ||
96 | #define TEGRA20_SPDIF_CTRL_QE_RX (1 << 17) | ||
97 | |||
98 | /* Interrupt when TX data FIFO attention level is reached */ | ||
99 | #define TEGRA20_SPDIF_CTRL_QE_TX (1 << 16) | ||
100 | |||
101 | /* Loopback test mode enable */ | ||
102 | #define TEGRA20_SPDIF_CTRL_LBK_EN (1 << 15) | ||
103 | |||
104 | /* | ||
105 | * Pack data mode: | ||
106 | * 0 = Single data (16 bit needs to be padded to match the | ||
107 | * interface data bit size). | ||
108 | * 1 = Packeted left/right channel data into a single word. | ||
109 | */ | ||
110 | #define TEGRA20_SPDIF_CTRL_PACK (1 << 14) | ||
111 | |||
112 | /* | ||
113 | * 00 = 16bit data | ||
114 | * 01 = 20bit data | ||
115 | * 10 = 24bit data | ||
116 | * 11 = raw data | ||
117 | */ | ||
118 | #define TEGRA20_SPDIF_BIT_MODE_16BIT 0 | ||
119 | #define TEGRA20_SPDIF_BIT_MODE_20BIT 1 | ||
120 | #define TEGRA20_SPDIF_BIT_MODE_24BIT 2 | ||
121 | #define TEGRA20_SPDIF_BIT_MODE_RAW 3 | ||
122 | |||
123 | #define TEGRA20_SPDIF_CTRL_BIT_MODE_SHIFT 12 | ||
124 | #define TEGRA20_SPDIF_CTRL_BIT_MODE_MASK (3 << TEGRA20_SPDIF_CTRL_BIT_MODE_SHIFT) | ||
125 | #define TEGRA20_SPDIF_CTRL_BIT_MODE_16BIT (TEGRA20_SPDIF_BIT_MODE_16BIT << TEGRA20_SPDIF_CTRL_BIT_MODE_SHIFT) | ||
126 | #define TEGRA20_SPDIF_CTRL_BIT_MODE_20BIT (TEGRA20_SPDIF_BIT_MODE_20BIT << TEGRA20_SPDIF_CTRL_BIT_MODE_SHIFT) | ||
127 | #define TEGRA20_SPDIF_CTRL_BIT_MODE_24BIT (TEGRA20_SPDIF_BIT_MODE_24BIT << TEGRA20_SPDIF_CTRL_BIT_MODE_SHIFT) | ||
128 | #define TEGRA20_SPDIF_CTRL_BIT_MODE_RAW (TEGRA20_SPDIF_BIT_MODE_RAW << TEGRA20_SPDIF_CTRL_BIT_MODE_SHIFT) | ||
129 | |||
130 | /* Fields in TEGRA20_SPDIF_STATUS */ | ||
131 | |||
132 | /* | ||
133 | * Note: IS_P, IS_B, IS_C, and IS_U are sticky bits. Software must | ||
134 | * write a 1 to the corresponding bit location to clear the status. | ||
135 | */ | ||
136 | |||
137 | /* | ||
138 | * Receiver(RX) shifter is busy receiving data. | ||
139 | * This bit is asserted when the receiver first locked onto the | ||
140 | * preamble of the data stream after RX_EN is asserted. This bit is | ||
141 | * deasserted when either, | ||
142 | * (a) the end of a frame is reached after RX_EN is deeasserted, or | ||
143 | * (b) the SPDIF data stream becomes inactive. | ||
144 | */ | ||
145 | #define TEGRA20_SPDIF_STATUS_RX_BSY (1 << 29) | ||
146 | |||
147 | /* | ||
148 | * Transmitter(TX) shifter is busy transmitting data. | ||
149 | * This bit is asserted when TX_EN is asserted. | ||
150 | * This bit is deasserted when the end of a frame is reached after | ||
151 | * TX_EN is deasserted. | ||
152 | */ | ||
153 | #define TEGRA20_SPDIF_STATUS_TX_BSY (1 << 28) | ||
154 | |||
155 | /* | ||
156 | * TX is busy shifting out channel status. | ||
157 | * This bit is asserted when both TX_EN and TC_EN are asserted and | ||
158 | * data from CH_STA_TX_A register is loaded into the internal shifter. | ||
159 | * This bit is deasserted when either, | ||
160 | * (a) the end of a frame is reached after TX_EN is deasserted, or | ||
161 | * (b) CH_STA_TX_F register is loaded into the internal shifter. | ||
162 | */ | ||
163 | #define TEGRA20_SPDIF_STATUS_TC_BSY (1 << 27) | ||
164 | |||
165 | /* | ||
166 | * TX User data FIFO busy. | ||
167 | * This bit is asserted when TX_EN and TXU_EN are asserted and | ||
168 | * there's data in the TX user FIFO. This bit is deassert when either, | ||
169 | * (a) the end of a frame is reached after TX_EN is deasserted, or | ||
170 | * (b) there's no data left in the TX user FIFO. | ||
171 | */ | ||
172 | #define TEGRA20_SPDIF_STATUS_TU_BSY (1 << 26) | ||
173 | |||
174 | /* TX FIFO Underrun error status */ | ||
175 | #define TEGRA20_SPDIF_STATUS_TX_ERR (1 << 25) | ||
176 | |||
177 | /* RX FIFO Overrun error status */ | ||
178 | #define TEGRA20_SPDIF_STATUS_RX_ERR (1 << 24) | ||
179 | |||
180 | /* Preamble status: 0=Preamble OK, 1=bad/missing preamble */ | ||
181 | #define TEGRA20_SPDIF_STATUS_IS_P (1 << 23) | ||
182 | |||
183 | /* B-preamble detection status: 0=not detected, 1=B-preamble detected */ | ||
184 | #define TEGRA20_SPDIF_STATUS_IS_B (1 << 22) | ||
185 | |||
186 | /* | ||
187 | * RX channel block data receive status: | ||
188 | * 0=entire block not recieved yet. | ||
189 | * 1=received entire block of channel status, | ||
190 | */ | ||
191 | #define TEGRA20_SPDIF_STATUS_IS_C (1 << 21) | ||
192 | |||
193 | /* RX User Data Valid flag: 1=valid IU detected, 0 = no IU detected. */ | ||
194 | #define TEGRA20_SPDIF_STATUS_IS_U (1 << 20) | ||
195 | |||
196 | /* | ||
197 | * RX User FIFO Status: | ||
198 | * 1=attention level reached, 0=attention level not reached. | ||
199 | */ | ||
200 | #define TEGRA20_SPDIF_STATUS_QS_RU (1 << 19) | ||
201 | |||
202 | /* | ||
203 | * TX User FIFO Status: | ||
204 | * 1=attention level reached, 0=attention level not reached. | ||
205 | */ | ||
206 | #define TEGRA20_SPDIF_STATUS_QS_TU (1 << 18) | ||
207 | |||
208 | /* | ||
209 | * RX Data FIFO Status: | ||
210 | * 1=attention level reached, 0=attention level not reached. | ||
211 | */ | ||
212 | #define TEGRA20_SPDIF_STATUS_QS_RX (1 << 17) | ||
213 | |||
214 | /* | ||
215 | * TX Data FIFO Status: | ||
216 | * 1=attention level reached, 0=attention level not reached. | ||
217 | */ | ||
218 | #define TEGRA20_SPDIF_STATUS_QS_TX (1 << 16) | ||
219 | |||
220 | /* Fields in TEGRA20_SPDIF_STROBE_CTRL */ | ||
221 | |||
222 | /* | ||
223 | * Indicates the approximate number of detected SPDIFIN clocks within a | ||
224 | * bi-phase period. | ||
225 | */ | ||
226 | #define TEGRA20_SPDIF_STROBE_CTRL_PERIOD_SHIFT 16 | ||
227 | #define TEGRA20_SPDIF_STROBE_CTRL_PERIOD_MASK (0xff << TEGRA20_SPDIF_STROBE_CTRL_PERIOD_SHIFT) | ||
228 | |||
229 | /* Data strobe mode: 0=Auto-locked 1=Manual locked */ | ||
230 | #define TEGRA20_SPDIF_STROBE_CTRL_STROBE (1 << 15) | ||
231 | |||
232 | /* | ||
233 | * Manual data strobe time within the bi-phase clock period (in terms of | ||
234 | * the number of over-sampling clocks). | ||
235 | */ | ||
236 | #define TEGRA20_SPDIF_STROBE_CTRL_DATA_STROBES_SHIFT 8 | ||
237 | #define TEGRA20_SPDIF_STROBE_CTRL_DATA_STROBES_MASK (0x1f << TEGRA20_SPDIF_STROBE_CTRL_DATA_STROBES_SHIFT) | ||
238 | |||
239 | /* | ||
240 | * Manual SPDIFIN bi-phase clock period (in terms of the number of | ||
241 | * over-sampling clocks). | ||
242 | */ | ||
243 | #define TEGRA20_SPDIF_STROBE_CTRL_CLOCK_PERIOD_SHIFT 0 | ||
244 | #define TEGRA20_SPDIF_STROBE_CTRL_CLOCK_PERIOD_MASK (0x3f << TEGRA20_SPDIF_STROBE_CTRL_CLOCK_PERIOD_SHIFT) | ||
245 | |||
246 | /* Fields in SPDIF_DATA_FIFO_CSR */ | ||
247 | |||
248 | /* Clear Receiver User FIFO (RX USR.FIFO) */ | ||
249 | #define TEGRA20_SPDIF_DATA_FIFO_CSR_RU_CLR (1 << 31) | ||
250 | |||
251 | #define TEGRA20_SPDIF_FIFO_ATN_LVL_U_ONE_SLOT 0 | ||
252 | #define TEGRA20_SPDIF_FIFO_ATN_LVL_U_TWO_SLOTS 1 | ||
253 | #define TEGRA20_SPDIF_FIFO_ATN_LVL_U_THREE_SLOTS 2 | ||
254 | #define TEGRA20_SPDIF_FIFO_ATN_LVL_U_FOUR_SLOTS 3 | ||
255 | |||
256 | /* RU FIFO attention level */ | ||
257 | #define TEGRA20_SPDIF_DATA_FIFO_CSR_RU_ATN_LVL_SHIFT 29 | ||
258 | #define TEGRA20_SPDIF_DATA_FIFO_CSR_RU_ATN_LVL_MASK \ | ||
259 | (0x3 << TEGRA20_SPDIF_DATA_FIFO_CSR_RU_ATN_LVL_SHIFT) | ||
260 | #define TEGRA20_SPDIF_DATA_FIFO_CSR_RU_ATN_LVL_RU1_WORD_FULL \ | ||
261 | (TEGRA20_SPDIF_FIFO_ATN_LVL_U_ONE_SLOT << TEGRA20_SPDIF_DATA_FIFO_CSR_RU_ATN_LVL_SHIFT) | ||
262 | #define TEGRA20_SPDIF_DATA_FIFO_CSR_RU_ATN_LVL_RU2_WORD_FULL \ | ||
263 | (TEGRA20_SPDIF_FIFO_ATN_LVL_U_TWO_SLOTS << TEGRA20_SPDIF_DATA_FIFO_CSR_RU_ATN_LVL_SHIFT) | ||
264 | #define TEGRA20_SPDIF_DATA_FIFO_CSR_RU_ATN_LVL_RU3_WORD_FULL \ | ||
265 | (TEGRA20_SPDIF_FIFO_ATN_LVL_U_THREE_SLOTS << TEGRA20_SPDIF_DATA_FIFO_CSR_RU_ATN_LVL_SHIFT) | ||
266 | #define TEGRA20_SPDIF_DATA_FIFO_CSR_RU_ATN_LVL_RU4_WORD_FULL \ | ||
267 | (TEGRA20_SPDIF_FIFO_ATN_LVL_U_FOUR_SLOTS << TEGRA20_SPDIF_DATA_FIFO_CSR_RU_ATN_LVL_SHIFT) | ||
268 | |||
269 | /* Number of RX USR.FIFO levels with valid data. */ | ||
270 | #define TEGRA20_SPDIF_DATA_FIFO_CSR_RU_FULL_COUNT_SHIFT 24 | ||
271 | #define TEGRA20_SPDIF_DATA_FIFO_CSR_RU_FULL_COUNT_MASK (0x1f << TEGRA20_SPDIF_DATA_FIFO_CSR_RU_FULL_COUNT_SHIFT) | ||
272 | |||
273 | /* Clear Transmitter User FIFO (TX USR.FIFO) */ | ||
274 | #define TEGRA20_SPDIF_DATA_FIFO_CSR_TU_CLR (1 << 23) | ||
275 | |||
276 | /* TU FIFO attention level */ | ||
277 | #define TEGRA20_SPDIF_DATA_FIFO_CSR_TU_ATN_LVL_SHIFT 21 | ||
278 | #define TEGRA20_SPDIF_DATA_FIFO_CSR_TU_ATN_LVL_MASK \ | ||
279 | (0x3 << TEGRA20_SPDIF_DATA_FIFO_CSR_TU_ATN_LVL_SHIFT) | ||
280 | #define TEGRA20_SPDIF_DATA_FIFO_CSR_TU_ATN_LVL_TU1_WORD_FULL \ | ||
281 | (TEGRA20_SPDIF_FIFO_ATN_LVL_U_ONE_SLOT << TEGRA20_SPDIF_DATA_FIFO_CSR_TU_ATN_LVL_SHIFT) | ||
282 | #define TEGRA20_SPDIF_DATA_FIFO_CSR_TU_ATN_LVL_TU2_WORD_FULL \ | ||
283 | (TEGRA20_SPDIF_FIFO_ATN_LVL_U_TWO_SLOTS << TEGRA20_SPDIF_DATA_FIFO_CSR_TU_ATN_LVL_SHIFT) | ||
284 | #define TEGRA20_SPDIF_DATA_FIFO_CSR_TU_ATN_LVL_TU3_WORD_FULL \ | ||
285 | (TEGRA20_SPDIF_FIFO_ATN_LVL_U_THREE_SLOTS << TEGRA20_SPDIF_DATA_FIFO_CSR_TU_ATN_LVL_SHIFT) | ||
286 | #define TEGRA20_SPDIF_DATA_FIFO_CSR_TU_ATN_LVL_TU4_WORD_FULL \ | ||
287 | (TEGRA20_SPDIF_FIFO_ATN_LVL_U_FOUR_SLOTS << TEGRA20_SPDIF_DATA_FIFO_CSR_TU_ATN_LVL_SHIFT) | ||
288 | |||
289 | /* Number of TX USR.FIFO levels that could be filled. */ | ||
290 | #define TEGRA20_SPDIF_DATA_FIFO_CSR_TU_EMPTY_COUNT_SHIFT 16 | ||
291 | #define TEGRA20_SPDIF_DATA_FIFO_CSR_TU_EMPTY_COUNT_MASK (0x1f << SPDIF_DATA_FIFO_CSR_TU_EMPTY_COUNT_SHIFT) | ||
292 | |||
293 | /* Clear Receiver Data FIFO (RX DATA.FIFO) */ | ||
294 | #define TEGRA20_SPDIF_DATA_FIFO_CSR_RX_CLR (1 << 15) | ||
295 | |||
296 | #define TEGRA20_SPDIF_FIFO_ATN_LVL_D_ONE_SLOT 0 | ||
297 | #define TEGRA20_SPDIF_FIFO_ATN_LVL_D_FOUR_SLOTS 1 | ||
298 | #define TEGRA20_SPDIF_FIFO_ATN_LVL_D_EIGHT_SLOTS 2 | ||
299 | #define TEGRA20_SPDIF_FIFO_ATN_LVL_D_TWELVE_SLOTS 3 | ||
300 | |||
301 | /* RU FIFO attention level */ | ||
302 | #define TEGRA20_SPDIF_DATA_FIFO_CSR_RX_ATN_LVL_SHIFT 13 | ||
303 | #define TEGRA20_SPDIF_DATA_FIFO_CSR_RX_ATN_LVL_MASK \ | ||
304 | (0x3 << TEGRA20_SPDIF_DATA_FIFO_CSR_RX_ATN_LVL_SHIFT) | ||
305 | #define TEGRA20_SPDIF_DATA_FIFO_CSR_RX_ATN_LVL_RU1_WORD_FULL \ | ||
306 | (TEGRA20_SPDIF_FIFO_ATN_LVL_D_ONE_SLOT << TEGRA20_SPDIF_DATA_FIFO_CSR_RX_ATN_LVL_SHIFT) | ||
307 | #define TEGRA20_SPDIF_DATA_FIFO_CSR_RX_ATN_LVL_RU4_WORD_FULL \ | ||
308 | (TEGRA20_SPDIF_FIFO_ATN_LVL_D_FOUR_SLOTS << TEGRA20_SPDIF_DATA_FIFO_CSR_RX_ATN_LVL_SHIFT) | ||
309 | #define TEGRA20_SPDIF_DATA_FIFO_CSR_RX_ATN_LVL_RU8_WORD_FULL \ | ||
310 | (TEGRA20_SPDIF_FIFO_ATN_LVL_D_EIGHT_SLOTS << TEGRA20_SPDIF_DATA_FIFO_CSR_RX_ATN_LVL_SHIFT) | ||
311 | #define TEGRA20_SPDIF_DATA_FIFO_CSR_RX_ATN_LVL_RU12_WORD_FULL \ | ||
312 | (TEGRA20_SPDIF_FIFO_ATN_LVL_D_TWELVE_SLOTS << TEGRA20_SPDIF_DATA_FIFO_CSR_RX_ATN_LVL_SHIFT) | ||
313 | |||
314 | /* Number of RX DATA.FIFO levels with valid data. */ | ||
315 | #define TEGRA20_SPDIF_DATA_FIFO_CSR_RX_FULL_COUNT_SHIFT 8 | ||
316 | #define TEGRA20_SPDIF_DATA_FIFO_CSR_RX_FULL_COUNT_MASK (0x1f << TEGRA20_SPDIF_DATA_FIFO_CSR_RX_FULL_COUNT_SHIFT) | ||
317 | |||
318 | /* Clear Transmitter Data FIFO (TX DATA.FIFO) */ | ||
319 | #define TEGRA20_SPDIF_DATA_FIFO_CSR_TX_CLR (1 << 7) | ||
320 | |||
321 | /* TU FIFO attention level */ | ||
322 | #define TEGRA20_SPDIF_DATA_FIFO_CSR_TX_ATN_LVL_SHIFT 5 | ||
323 | #define TEGRA20_SPDIF_DATA_FIFO_CSR_TX_ATN_LVL_MASK \ | ||
324 | (0x3 << TEGRA20_SPDIF_DATA_FIFO_CSR_TX_ATN_LVL_SHIFT) | ||
325 | #define TEGRA20_SPDIF_DATA_FIFO_CSR_TX_ATN_LVL_TU1_WORD_FULL \ | ||
326 | (TEGRA20_SPDIF_FIFO_ATN_LVL_D_ONE_SLOT << TEGRA20_SPDIF_DATA_FIFO_CSR_TX_ATN_LVL_SHIFT) | ||
327 | #define TEGRA20_SPDIF_DATA_FIFO_CSR_TX_ATN_LVL_TU4_WORD_FULL \ | ||
328 | (TEGRA20_SPDIF_FIFO_ATN_LVL_D_FOUR_SLOTS << TEGRA20_SPDIF_DATA_FIFO_CSR_TX_ATN_LVL_SHIFT) | ||
329 | #define TEGRA20_SPDIF_DATA_FIFO_CSR_TX_ATN_LVL_TU8_WORD_FULL \ | ||
330 | (TEGRA20_SPDIF_FIFO_ATN_LVL_D_EIGHT_SLOTS << TEGRA20_SPDIF_DATA_FIFO_CSR_TX_ATN_LVL_SHIFT) | ||
331 | #define TEGRA20_SPDIF_DATA_FIFO_CSR_TX_ATN_LVL_TU12_WORD_FULL \ | ||
332 | (TEGRA20_SPDIF_FIFO_ATN_LVL_D_TWELVE_SLOTS << TEGRA20_SPDIF_DATA_FIFO_CSR_TX_ATN_LVL_SHIFT) | ||
333 | |||
334 | /* Number of TX DATA.FIFO levels that could be filled. */ | ||
335 | #define TEGRA20_SPDIF_DATA_FIFO_CSR_TX_EMPTY_COUNT_SHIFT 0 | ||
336 | #define TEGRA20_SPDIF_DATA_FIFO_CSR_TX_EMPTY_COUNT_MASK (0x1f << SPDIF_DATA_FIFO_CSR_TX_EMPTY_COUNT_SHIFT) | ||
337 | |||
338 | /* Fields in TEGRA20_SPDIF_DATA_OUT */ | ||
339 | |||
340 | /* | ||
341 | * This register has 5 different formats: | ||
342 | * 16-bit (BIT_MODE=00, PACK=0) | ||
343 | * 20-bit (BIT_MODE=01, PACK=0) | ||
344 | * 24-bit (BIT_MODE=10, PACK=0) | ||
345 | * raw (BIT_MODE=11, PACK=0) | ||
346 | * 16-bit packed (BIT_MODE=00, PACK=1) | ||
347 | */ | ||
348 | |||
349 | #define TEGRA20_SPDIF_DATA_OUT_DATA_16_SHIFT 0 | ||
350 | #define TEGRA20_SPDIF_DATA_OUT_DATA_16_MASK (0xffff << TEGRA20_SPDIF_DATA_OUT_DATA_16_SHIFT) | ||
351 | |||
352 | #define TEGRA20_SPDIF_DATA_OUT_DATA_20_SHIFT 0 | ||
353 | #define TEGRA20_SPDIF_DATA_OUT_DATA_20_MASK (0xfffff << TEGRA20_SPDIF_DATA_OUT_DATA_20_SHIFT) | ||
354 | |||
355 | #define TEGRA20_SPDIF_DATA_OUT_DATA_24_SHIFT 0 | ||
356 | #define TEGRA20_SPDIF_DATA_OUT_DATA_24_MASK (0xffffff << TEGRA20_SPDIF_DATA_OUT_DATA_24_SHIFT) | ||
357 | |||
358 | #define TEGRA20_SPDIF_DATA_OUT_DATA_RAW_P (1 << 31) | ||
359 | #define TEGRA20_SPDIF_DATA_OUT_DATA_RAW_C (1 << 30) | ||
360 | #define TEGRA20_SPDIF_DATA_OUT_DATA_RAW_U (1 << 29) | ||
361 | #define TEGRA20_SPDIF_DATA_OUT_DATA_RAW_V (1 << 28) | ||
362 | |||
363 | #define TEGRA20_SPDIF_DATA_OUT_DATA_RAW_DATA_SHIFT 8 | ||
364 | #define TEGRA20_SPDIF_DATA_OUT_DATA_RAW_DATA_MASK (0xfffff << TEGRA20_SPDIF_DATA_OUT_DATA_RAW_DATA_SHIFT) | ||
365 | |||
366 | #define TEGRA20_SPDIF_DATA_OUT_DATA_RAW_AUX_SHIFT 4 | ||
367 | #define TEGRA20_SPDIF_DATA_OUT_DATA_RAW_AUX_MASK (0xf << TEGRA20_SPDIF_DATA_OUT_DATA_RAW_AUX_SHIFT) | ||
368 | |||
369 | #define TEGRA20_SPDIF_DATA_OUT_DATA_RAW_PREAMBLE_SHIFT 0 | ||
370 | #define TEGRA20_SPDIF_DATA_OUT_DATA_RAW_PREAMBLE_MASK (0xf << TEGRA20_SPDIF_DATA_OUT_DATA_RAW_PREAMBLE_SHIFT) | ||
371 | |||
372 | #define TEGRA20_SPDIF_DATA_OUT_DATA_16_PACKED_RIGHT_SHIFT 16 | ||
373 | #define TEGRA20_SPDIF_DATA_OUT_DATA_16_PACKED_RIGHT_MASK (0xffff << TEGRA20_SPDIF_DATA_OUT_DATA_16_PACKED_RIGHT_SHIFT) | ||
374 | |||
375 | #define TEGRA20_SPDIF_DATA_OUT_DATA_16_PACKED_LEFT_SHIFT 0 | ||
376 | #define TEGRA20_SPDIF_DATA_OUT_DATA_16_PACKED_LEFT_MASK (0xffff << TEGRA20_SPDIF_DATA_OUT_DATA_16_PACKED_LEFT_SHIFT) | ||
377 | |||
378 | /* Fields in TEGRA20_SPDIF_DATA_IN */ | ||
379 | |||
380 | /* | ||
381 | * This register has 5 different formats: | ||
382 | * 16-bit (BIT_MODE=00, PACK=0) | ||
383 | * 20-bit (BIT_MODE=01, PACK=0) | ||
384 | * 24-bit (BIT_MODE=10, PACK=0) | ||
385 | * raw (BIT_MODE=11, PACK=0) | ||
386 | * 16-bit packed (BIT_MODE=00, PACK=1) | ||
387 | * | ||
388 | * Bits 31:24 are common to all modes except 16-bit packed | ||
389 | */ | ||
390 | |||
391 | #define TEGRA20_SPDIF_DATA_IN_DATA_P (1 << 31) | ||
392 | #define TEGRA20_SPDIF_DATA_IN_DATA_C (1 << 30) | ||
393 | #define TEGRA20_SPDIF_DATA_IN_DATA_U (1 << 29) | ||
394 | #define TEGRA20_SPDIF_DATA_IN_DATA_V (1 << 28) | ||
395 | |||
396 | #define TEGRA20_SPDIF_DATA_IN_DATA_PREAMBLE_SHIFT 24 | ||
397 | #define TEGRA20_SPDIF_DATA_IN_DATA_PREAMBLE_MASK (0xf << TEGRA20_SPDIF_DATA_IN_DATA_PREAMBLE_SHIFT) | ||
398 | |||
399 | #define TEGRA20_SPDIF_DATA_IN_DATA_16_SHIFT 0 | ||
400 | #define TEGRA20_SPDIF_DATA_IN_DATA_16_MASK (0xffff << TEGRA20_SPDIF_DATA_IN_DATA_16_SHIFT) | ||
401 | |||
402 | #define TEGRA20_SPDIF_DATA_IN_DATA_20_SHIFT 0 | ||
403 | #define TEGRA20_SPDIF_DATA_IN_DATA_20_MASK (0xfffff << TEGRA20_SPDIF_DATA_IN_DATA_20_SHIFT) | ||
404 | |||
405 | #define TEGRA20_SPDIF_DATA_IN_DATA_24_SHIFT 0 | ||
406 | #define TEGRA20_SPDIF_DATA_IN_DATA_24_MASK (0xffffff << TEGRA20_SPDIF_DATA_IN_DATA_24_SHIFT) | ||
407 | |||
408 | #define TEGRA20_SPDIF_DATA_IN_DATA_RAW_DATA_SHIFT 8 | ||
409 | #define TEGRA20_SPDIF_DATA_IN_DATA_RAW_DATA_MASK (0xfffff << TEGRA20_SPDIF_DATA_IN_DATA_RAW_DATA_SHIFT) | ||
410 | |||
411 | #define TEGRA20_SPDIF_DATA_IN_DATA_RAW_AUX_SHIFT 4 | ||
412 | #define TEGRA20_SPDIF_DATA_IN_DATA_RAW_AUX_MASK (0xf << TEGRA20_SPDIF_DATA_IN_DATA_RAW_AUX_SHIFT) | ||
413 | |||
414 | #define TEGRA20_SPDIF_DATA_IN_DATA_RAW_PREAMBLE_SHIFT 0 | ||
415 | #define TEGRA20_SPDIF_DATA_IN_DATA_RAW_PREAMBLE_MASK (0xf << TEGRA20_SPDIF_DATA_IN_DATA_RAW_PREAMBLE_SHIFT) | ||
416 | |||
417 | #define TEGRA20_SPDIF_DATA_IN_DATA_16_PACKED_RIGHT_SHIFT 16 | ||
418 | #define TEGRA20_SPDIF_DATA_IN_DATA_16_PACKED_RIGHT_MASK (0xffff << TEGRA20_SPDIF_DATA_IN_DATA_16_PACKED_RIGHT_SHIFT) | ||
419 | |||
420 | #define TEGRA20_SPDIF_DATA_IN_DATA_16_PACKED_LEFT_SHIFT 0 | ||
421 | #define TEGRA20_SPDIF_DATA_IN_DATA_16_PACKED_LEFT_MASK (0xffff << TEGRA20_SPDIF_DATA_IN_DATA_16_PACKED_LEFT_SHIFT) | ||
422 | |||
423 | /* Fields in TEGRA20_SPDIF_CH_STA_RX_A */ | ||
424 | /* Fields in TEGRA20_SPDIF_CH_STA_RX_B */ | ||
425 | /* Fields in TEGRA20_SPDIF_CH_STA_RX_C */ | ||
426 | /* Fields in TEGRA20_SPDIF_CH_STA_RX_D */ | ||
427 | /* Fields in TEGRA20_SPDIF_CH_STA_RX_E */ | ||
428 | /* Fields in TEGRA20_SPDIF_CH_STA_RX_F */ | ||
429 | |||
430 | /* | ||
431 | * The 6-word receive channel data page buffer holds a block (192 frames) of | ||
432 | * channel status information. The order of receive is from LSB to MSB | ||
433 | * bit, and from CH_STA_RX_A to CH_STA_RX_F then back to CH_STA_RX_A. | ||
434 | */ | ||
435 | |||
436 | /* Fields in TEGRA20_SPDIF_CH_STA_TX_A */ | ||
437 | /* Fields in TEGRA20_SPDIF_CH_STA_TX_B */ | ||
438 | /* Fields in TEGRA20_SPDIF_CH_STA_TX_C */ | ||
439 | /* Fields in TEGRA20_SPDIF_CH_STA_TX_D */ | ||
440 | /* Fields in TEGRA20_SPDIF_CH_STA_TX_E */ | ||
441 | /* Fields in TEGRA20_SPDIF_CH_STA_TX_F */ | ||
442 | |||
443 | /* | ||
444 | * The 6-word transmit channel data page buffer holds a block (192 frames) of | ||
445 | * channel status information. The order of transmission is from LSB to MSB | ||
446 | * bit, and from CH_STA_TX_A to CH_STA_TX_F then back to CH_STA_TX_A. | ||
447 | */ | ||
448 | |||
449 | /* Fields in TEGRA20_SPDIF_USR_STA_RX_A */ | ||
450 | |||
451 | /* | ||
452 | * This 4-word deep FIFO receives user FIFO field information. The order of | ||
453 | * receive is from LSB to MSB bit. | ||
454 | */ | ||
455 | |||
456 | /* Fields in TEGRA20_SPDIF_USR_DAT_TX_A */ | ||
457 | |||
458 | /* | ||
459 | * This 4-word deep FIFO transmits user FIFO field information. The order of | ||
460 | * transmission is from LSB to MSB bit. | ||
461 | */ | ||
462 | |||
463 | struct tegra20_spdif { | ||
464 | struct clk *clk_spdif_out; | ||
465 | struct tegra_pcm_dma_params capture_dma_data; | ||
466 | struct tegra_pcm_dma_params playback_dma_data; | ||
467 | struct regmap *regmap; | ||
468 | u32 reg_ctrl; | ||
469 | }; | ||
470 | |||
471 | #endif | ||
diff --git a/sound/soc/tegra/tegra30_ahub.c b/sound/soc/tegra/tegra30_ahub.c new file mode 100644 index 000000000000..57cd419f743e --- /dev/null +++ b/sound/soc/tegra/tegra30_ahub.c | |||
@@ -0,0 +1,631 @@ | |||
1 | /* | ||
2 | * tegra30_ahub.c - Tegra30 AHUB driver | ||
3 | * | ||
4 | * Copyright (c) 2011,2012, NVIDIA CORPORATION. All rights reserved. | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify it | ||
7 | * under the terms and conditions of the GNU General Public License, | ||
8 | * version 2, as published by the Free Software Foundation. | ||
9 | * | ||
10 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
13 | * more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | */ | ||
18 | |||
19 | #include <linux/clk.h> | ||
20 | #include <linux/device.h> | ||
21 | #include <linux/io.h> | ||
22 | #include <linux/module.h> | ||
23 | #include <linux/of_platform.h> | ||
24 | #include <linux/platform_device.h> | ||
25 | #include <linux/pm_runtime.h> | ||
26 | #include <linux/regmap.h> | ||
27 | #include <linux/slab.h> | ||
28 | #include <mach/clk.h> | ||
29 | #include <mach/dma.h> | ||
30 | #include <sound/soc.h> | ||
31 | #include "tegra30_ahub.h" | ||
32 | |||
33 | #define DRV_NAME "tegra30-ahub" | ||
34 | |||
35 | static struct tegra30_ahub *ahub; | ||
36 | |||
37 | static inline void tegra30_apbif_write(u32 reg, u32 val) | ||
38 | { | ||
39 | regmap_write(ahub->regmap_apbif, reg, val); | ||
40 | } | ||
41 | |||
42 | static inline u32 tegra30_apbif_read(u32 reg) | ||
43 | { | ||
44 | u32 val; | ||
45 | regmap_read(ahub->regmap_apbif, reg, &val); | ||
46 | return val; | ||
47 | } | ||
48 | |||
49 | static inline void tegra30_audio_write(u32 reg, u32 val) | ||
50 | { | ||
51 | regmap_write(ahub->regmap_ahub, reg, val); | ||
52 | } | ||
53 | |||
54 | static int tegra30_ahub_runtime_suspend(struct device *dev) | ||
55 | { | ||
56 | regcache_cache_only(ahub->regmap_apbif, true); | ||
57 | regcache_cache_only(ahub->regmap_ahub, true); | ||
58 | |||
59 | clk_disable(ahub->clk_apbif); | ||
60 | clk_disable(ahub->clk_d_audio); | ||
61 | |||
62 | return 0; | ||
63 | } | ||
64 | |||
65 | /* | ||
66 | * clk_apbif isn't required for an I2S<->I2S configuration where no PCM data | ||
67 | * is read from or sent to memory. However, that's not something the rest of | ||
68 | * the driver supports right now, so we'll just treat the two clocks as one | ||
69 | * for now. | ||
70 | * | ||
71 | * These functions should not be a plain ref-count. Instead, each active stream | ||
72 | * contributes some requirement to the minimum clock rate, so starting or | ||
73 | * stopping streams should dynamically adjust the clock as required. However, | ||
74 | * this is not yet implemented. | ||
75 | */ | ||
76 | static int tegra30_ahub_runtime_resume(struct device *dev) | ||
77 | { | ||
78 | int ret; | ||
79 | |||
80 | ret = clk_enable(ahub->clk_d_audio); | ||
81 | if (ret) { | ||
82 | dev_err(dev, "clk_enable d_audio failed: %d\n", ret); | ||
83 | return ret; | ||
84 | } | ||
85 | ret = clk_enable(ahub->clk_apbif); | ||
86 | if (ret) { | ||
87 | dev_err(dev, "clk_enable apbif failed: %d\n", ret); | ||
88 | clk_disable(ahub->clk_d_audio); | ||
89 | return ret; | ||
90 | } | ||
91 | |||
92 | regcache_cache_only(ahub->regmap_apbif, false); | ||
93 | regcache_cache_only(ahub->regmap_ahub, false); | ||
94 | |||
95 | return 0; | ||
96 | } | ||
97 | |||
98 | int tegra30_ahub_allocate_rx_fifo(enum tegra30_ahub_rxcif *rxcif, | ||
99 | unsigned long *fiforeg, | ||
100 | unsigned long *reqsel) | ||
101 | { | ||
102 | int channel; | ||
103 | u32 reg, val; | ||
104 | |||
105 | channel = find_first_zero_bit(ahub->rx_usage, | ||
106 | TEGRA30_AHUB_CHANNEL_CTRL_COUNT); | ||
107 | if (channel >= TEGRA30_AHUB_CHANNEL_CTRL_COUNT) | ||
108 | return -EBUSY; | ||
109 | |||
110 | __set_bit(channel, ahub->rx_usage); | ||
111 | |||
112 | *rxcif = TEGRA30_AHUB_RXCIF_APBIF_RX0 + channel; | ||
113 | *fiforeg = ahub->apbif_addr + TEGRA30_AHUB_CHANNEL_RXFIFO + | ||
114 | (channel * TEGRA30_AHUB_CHANNEL_RXFIFO_STRIDE); | ||
115 | *reqsel = ahub->dma_sel + channel; | ||
116 | |||
117 | reg = TEGRA30_AHUB_CHANNEL_CTRL + | ||
118 | (channel * TEGRA30_AHUB_CHANNEL_CTRL_STRIDE); | ||
119 | val = tegra30_apbif_read(reg); | ||
120 | val &= ~(TEGRA30_AHUB_CHANNEL_CTRL_RX_THRESHOLD_MASK | | ||
121 | TEGRA30_AHUB_CHANNEL_CTRL_RX_PACK_MASK); | ||
122 | val |= (7 << TEGRA30_AHUB_CHANNEL_CTRL_RX_THRESHOLD_SHIFT) | | ||
123 | TEGRA30_AHUB_CHANNEL_CTRL_RX_PACK_EN | | ||
124 | TEGRA30_AHUB_CHANNEL_CTRL_RX_PACK_16; | ||
125 | tegra30_apbif_write(reg, val); | ||
126 | |||
127 | reg = TEGRA30_AHUB_CIF_RX_CTRL + | ||
128 | (channel * TEGRA30_AHUB_CIF_RX_CTRL_STRIDE); | ||
129 | val = (0 << TEGRA30_AUDIOCIF_CTRL_FIFO_THRESHOLD_SHIFT) | | ||
130 | (1 << TEGRA30_AUDIOCIF_CTRL_AUDIO_CHANNELS_SHIFT) | | ||
131 | (1 << TEGRA30_AUDIOCIF_CTRL_CLIENT_CHANNELS_SHIFT) | | ||
132 | TEGRA30_AUDIOCIF_CTRL_AUDIO_BITS_16 | | ||
133 | TEGRA30_AUDIOCIF_CTRL_CLIENT_BITS_16 | | ||
134 | TEGRA30_AUDIOCIF_CTRL_DIRECTION_RX; | ||
135 | tegra30_apbif_write(reg, val); | ||
136 | |||
137 | return 0; | ||
138 | } | ||
139 | EXPORT_SYMBOL_GPL(tegra30_ahub_allocate_rx_fifo); | ||
140 | |||
141 | int tegra30_ahub_enable_rx_fifo(enum tegra30_ahub_rxcif rxcif) | ||
142 | { | ||
143 | int channel = rxcif - TEGRA30_AHUB_RXCIF_APBIF_RX0; | ||
144 | int reg, val; | ||
145 | |||
146 | reg = TEGRA30_AHUB_CHANNEL_CTRL + | ||
147 | (channel * TEGRA30_AHUB_CHANNEL_CTRL_STRIDE); | ||
148 | val = tegra30_apbif_read(reg); | ||
149 | val |= TEGRA30_AHUB_CHANNEL_CTRL_RX_EN; | ||
150 | tegra30_apbif_write(reg, val); | ||
151 | |||
152 | return 0; | ||
153 | } | ||
154 | EXPORT_SYMBOL_GPL(tegra30_ahub_enable_rx_fifo); | ||
155 | |||
156 | int tegra30_ahub_disable_rx_fifo(enum tegra30_ahub_rxcif rxcif) | ||
157 | { | ||
158 | int channel = rxcif - TEGRA30_AHUB_RXCIF_APBIF_RX0; | ||
159 | int reg, val; | ||
160 | |||
161 | reg = TEGRA30_AHUB_CHANNEL_CTRL + | ||
162 | (channel * TEGRA30_AHUB_CHANNEL_CTRL_STRIDE); | ||
163 | val = tegra30_apbif_read(reg); | ||
164 | val &= ~TEGRA30_AHUB_CHANNEL_CTRL_RX_EN; | ||
165 | tegra30_apbif_write(reg, val); | ||
166 | |||
167 | return 0; | ||
168 | } | ||
169 | EXPORT_SYMBOL_GPL(tegra30_ahub_disable_rx_fifo); | ||
170 | |||
171 | int tegra30_ahub_free_rx_fifo(enum tegra30_ahub_rxcif rxcif) | ||
172 | { | ||
173 | int channel = rxcif - TEGRA30_AHUB_RXCIF_APBIF_RX0; | ||
174 | |||
175 | __clear_bit(channel, ahub->rx_usage); | ||
176 | |||
177 | return 0; | ||
178 | } | ||
179 | EXPORT_SYMBOL_GPL(tegra30_ahub_free_rx_fifo); | ||
180 | |||
181 | int tegra30_ahub_allocate_tx_fifo(enum tegra30_ahub_txcif *txcif, | ||
182 | unsigned long *fiforeg, | ||
183 | unsigned long *reqsel) | ||
184 | { | ||
185 | int channel; | ||
186 | u32 reg, val; | ||
187 | |||
188 | channel = find_first_zero_bit(ahub->tx_usage, | ||
189 | TEGRA30_AHUB_CHANNEL_CTRL_COUNT); | ||
190 | if (channel >= TEGRA30_AHUB_CHANNEL_CTRL_COUNT) | ||
191 | return -EBUSY; | ||
192 | |||
193 | __set_bit(channel, ahub->tx_usage); | ||
194 | |||
195 | *txcif = TEGRA30_AHUB_TXCIF_APBIF_TX0 + channel; | ||
196 | *fiforeg = ahub->apbif_addr + TEGRA30_AHUB_CHANNEL_TXFIFO + | ||
197 | (channel * TEGRA30_AHUB_CHANNEL_TXFIFO_STRIDE); | ||
198 | *reqsel = ahub->dma_sel + channel; | ||
199 | |||
200 | reg = TEGRA30_AHUB_CHANNEL_CTRL + | ||
201 | (channel * TEGRA30_AHUB_CHANNEL_CTRL_STRIDE); | ||
202 | val = tegra30_apbif_read(reg); | ||
203 | val &= ~(TEGRA30_AHUB_CHANNEL_CTRL_TX_THRESHOLD_MASK | | ||
204 | TEGRA30_AHUB_CHANNEL_CTRL_TX_PACK_MASK); | ||
205 | val |= (7 << TEGRA30_AHUB_CHANNEL_CTRL_TX_THRESHOLD_SHIFT) | | ||
206 | TEGRA30_AHUB_CHANNEL_CTRL_TX_PACK_EN | | ||
207 | TEGRA30_AHUB_CHANNEL_CTRL_TX_PACK_16; | ||
208 | tegra30_apbif_write(reg, val); | ||
209 | |||
210 | reg = TEGRA30_AHUB_CIF_TX_CTRL + | ||
211 | (channel * TEGRA30_AHUB_CIF_TX_CTRL_STRIDE); | ||
212 | val = (0 << TEGRA30_AUDIOCIF_CTRL_FIFO_THRESHOLD_SHIFT) | | ||
213 | (1 << TEGRA30_AUDIOCIF_CTRL_AUDIO_CHANNELS_SHIFT) | | ||
214 | (1 << TEGRA30_AUDIOCIF_CTRL_CLIENT_CHANNELS_SHIFT) | | ||
215 | TEGRA30_AUDIOCIF_CTRL_AUDIO_BITS_16 | | ||
216 | TEGRA30_AUDIOCIF_CTRL_CLIENT_BITS_16 | | ||
217 | TEGRA30_AUDIOCIF_CTRL_DIRECTION_TX; | ||
218 | tegra30_apbif_write(reg, val); | ||
219 | |||
220 | return 0; | ||
221 | } | ||
222 | EXPORT_SYMBOL_GPL(tegra30_ahub_allocate_tx_fifo); | ||
223 | |||
224 | int tegra30_ahub_enable_tx_fifo(enum tegra30_ahub_txcif txcif) | ||
225 | { | ||
226 | int channel = txcif - TEGRA30_AHUB_TXCIF_APBIF_TX0; | ||
227 | int reg, val; | ||
228 | |||
229 | reg = TEGRA30_AHUB_CHANNEL_CTRL + | ||
230 | (channel * TEGRA30_AHUB_CHANNEL_CTRL_STRIDE); | ||
231 | val = tegra30_apbif_read(reg); | ||
232 | val |= TEGRA30_AHUB_CHANNEL_CTRL_TX_EN; | ||
233 | tegra30_apbif_write(reg, val); | ||
234 | |||
235 | return 0; | ||
236 | } | ||
237 | EXPORT_SYMBOL_GPL(tegra30_ahub_enable_tx_fifo); | ||
238 | |||
239 | int tegra30_ahub_disable_tx_fifo(enum tegra30_ahub_txcif txcif) | ||
240 | { | ||
241 | int channel = txcif - TEGRA30_AHUB_TXCIF_APBIF_TX0; | ||
242 | int reg, val; | ||
243 | |||
244 | reg = TEGRA30_AHUB_CHANNEL_CTRL + | ||
245 | (channel * TEGRA30_AHUB_CHANNEL_CTRL_STRIDE); | ||
246 | val = tegra30_apbif_read(reg); | ||
247 | val &= ~TEGRA30_AHUB_CHANNEL_CTRL_TX_EN; | ||
248 | tegra30_apbif_write(reg, val); | ||
249 | |||
250 | return 0; | ||
251 | } | ||
252 | EXPORT_SYMBOL_GPL(tegra30_ahub_disable_tx_fifo); | ||
253 | |||
254 | int tegra30_ahub_free_tx_fifo(enum tegra30_ahub_txcif txcif) | ||
255 | { | ||
256 | int channel = txcif - TEGRA30_AHUB_TXCIF_APBIF_TX0; | ||
257 | |||
258 | __clear_bit(channel, ahub->tx_usage); | ||
259 | |||
260 | return 0; | ||
261 | } | ||
262 | EXPORT_SYMBOL_GPL(tegra30_ahub_free_tx_fifo); | ||
263 | |||
264 | int tegra30_ahub_set_rx_cif_source(enum tegra30_ahub_rxcif rxcif, | ||
265 | enum tegra30_ahub_txcif txcif) | ||
266 | { | ||
267 | int channel = rxcif - TEGRA30_AHUB_RXCIF_APBIF_RX0; | ||
268 | int reg; | ||
269 | |||
270 | reg = TEGRA30_AHUB_AUDIO_RX + | ||
271 | (channel * TEGRA30_AHUB_AUDIO_RX_STRIDE); | ||
272 | tegra30_audio_write(reg, 1 << txcif); | ||
273 | |||
274 | return 0; | ||
275 | } | ||
276 | EXPORT_SYMBOL_GPL(tegra30_ahub_set_rx_cif_source); | ||
277 | |||
278 | int tegra30_ahub_unset_rx_cif_source(enum tegra30_ahub_rxcif rxcif) | ||
279 | { | ||
280 | int channel = rxcif - TEGRA30_AHUB_RXCIF_APBIF_RX0; | ||
281 | int reg; | ||
282 | |||
283 | reg = TEGRA30_AHUB_AUDIO_RX + | ||
284 | (channel * TEGRA30_AHUB_AUDIO_RX_STRIDE); | ||
285 | tegra30_audio_write(reg, 0); | ||
286 | |||
287 | return 0; | ||
288 | } | ||
289 | EXPORT_SYMBOL_GPL(tegra30_ahub_unset_rx_cif_source); | ||
290 | |||
291 | static const char * const configlink_clocks[] __devinitconst = { | ||
292 | "i2s0", | ||
293 | "i2s1", | ||
294 | "i2s2", | ||
295 | "i2s3", | ||
296 | "i2s4", | ||
297 | "dam0", | ||
298 | "dam1", | ||
299 | "dam2", | ||
300 | "spdif_in", | ||
301 | }; | ||
302 | |||
303 | struct of_dev_auxdata ahub_auxdata[] __devinitdata = { | ||
304 | OF_DEV_AUXDATA("nvidia,tegra30-i2s", 0x70080300, "tegra30-i2s.0", NULL), | ||
305 | OF_DEV_AUXDATA("nvidia,tegra30-i2s", 0x70080400, "tegra30-i2s.1", NULL), | ||
306 | OF_DEV_AUXDATA("nvidia,tegra30-i2s", 0x70080500, "tegra30-i2s.2", NULL), | ||
307 | OF_DEV_AUXDATA("nvidia,tegra30-i2s", 0x70080600, "tegra30-i2s.3", NULL), | ||
308 | OF_DEV_AUXDATA("nvidia,tegra30-i2s", 0x70080700, "tegra30-i2s.4", NULL), | ||
309 | {} | ||
310 | }; | ||
311 | |||
312 | #define LAST_REG(name) \ | ||
313 | (TEGRA30_AHUB_##name + \ | ||
314 | (TEGRA30_AHUB_##name##_STRIDE * TEGRA30_AHUB_##name##_COUNT) - 4) | ||
315 | |||
316 | #define REG_IN_ARRAY(reg, name) \ | ||
317 | ((reg >= TEGRA30_AHUB_##name) && \ | ||
318 | (reg <= LAST_REG(name) && \ | ||
319 | (!((reg - TEGRA30_AHUB_##name) % TEGRA30_AHUB_##name##_STRIDE)))) | ||
320 | |||
321 | static bool tegra30_ahub_apbif_wr_rd_reg(struct device *dev, unsigned int reg) | ||
322 | { | ||
323 | switch (reg) { | ||
324 | case TEGRA30_AHUB_CONFIG_LINK_CTRL: | ||
325 | case TEGRA30_AHUB_MISC_CTRL: | ||
326 | case TEGRA30_AHUB_APBDMA_LIVE_STATUS: | ||
327 | case TEGRA30_AHUB_I2S_LIVE_STATUS: | ||
328 | case TEGRA30_AHUB_SPDIF_LIVE_STATUS: | ||
329 | case TEGRA30_AHUB_I2S_INT_MASK: | ||
330 | case TEGRA30_AHUB_DAM_INT_MASK: | ||
331 | case TEGRA30_AHUB_SPDIF_INT_MASK: | ||
332 | case TEGRA30_AHUB_APBIF_INT_MASK: | ||
333 | case TEGRA30_AHUB_I2S_INT_STATUS: | ||
334 | case TEGRA30_AHUB_DAM_INT_STATUS: | ||
335 | case TEGRA30_AHUB_SPDIF_INT_STATUS: | ||
336 | case TEGRA30_AHUB_APBIF_INT_STATUS: | ||
337 | case TEGRA30_AHUB_I2S_INT_SOURCE: | ||
338 | case TEGRA30_AHUB_DAM_INT_SOURCE: | ||
339 | case TEGRA30_AHUB_SPDIF_INT_SOURCE: | ||
340 | case TEGRA30_AHUB_APBIF_INT_SOURCE: | ||
341 | case TEGRA30_AHUB_I2S_INT_SET: | ||
342 | case TEGRA30_AHUB_DAM_INT_SET: | ||
343 | case TEGRA30_AHUB_SPDIF_INT_SET: | ||
344 | case TEGRA30_AHUB_APBIF_INT_SET: | ||
345 | return true; | ||
346 | default: | ||
347 | break; | ||
348 | }; | ||
349 | |||
350 | if (REG_IN_ARRAY(reg, CHANNEL_CTRL) || | ||
351 | REG_IN_ARRAY(reg, CHANNEL_CLEAR) || | ||
352 | REG_IN_ARRAY(reg, CHANNEL_STATUS) || | ||
353 | REG_IN_ARRAY(reg, CHANNEL_TXFIFO) || | ||
354 | REG_IN_ARRAY(reg, CHANNEL_RXFIFO) || | ||
355 | REG_IN_ARRAY(reg, CIF_TX_CTRL) || | ||
356 | REG_IN_ARRAY(reg, CIF_RX_CTRL) || | ||
357 | REG_IN_ARRAY(reg, DAM_LIVE_STATUS)) | ||
358 | return true; | ||
359 | |||
360 | return false; | ||
361 | } | ||
362 | |||
363 | static bool tegra30_ahub_apbif_volatile_reg(struct device *dev, | ||
364 | unsigned int reg) | ||
365 | { | ||
366 | switch (reg) { | ||
367 | case TEGRA30_AHUB_CONFIG_LINK_CTRL: | ||
368 | case TEGRA30_AHUB_MISC_CTRL: | ||
369 | case TEGRA30_AHUB_APBDMA_LIVE_STATUS: | ||
370 | case TEGRA30_AHUB_I2S_LIVE_STATUS: | ||
371 | case TEGRA30_AHUB_SPDIF_LIVE_STATUS: | ||
372 | case TEGRA30_AHUB_I2S_INT_STATUS: | ||
373 | case TEGRA30_AHUB_DAM_INT_STATUS: | ||
374 | case TEGRA30_AHUB_SPDIF_INT_STATUS: | ||
375 | case TEGRA30_AHUB_APBIF_INT_STATUS: | ||
376 | case TEGRA30_AHUB_I2S_INT_SET: | ||
377 | case TEGRA30_AHUB_DAM_INT_SET: | ||
378 | case TEGRA30_AHUB_SPDIF_INT_SET: | ||
379 | case TEGRA30_AHUB_APBIF_INT_SET: | ||
380 | return true; | ||
381 | default: | ||
382 | break; | ||
383 | }; | ||
384 | |||
385 | if (REG_IN_ARRAY(reg, CHANNEL_CLEAR) || | ||
386 | REG_IN_ARRAY(reg, CHANNEL_STATUS) || | ||
387 | REG_IN_ARRAY(reg, CHANNEL_TXFIFO) || | ||
388 | REG_IN_ARRAY(reg, CHANNEL_RXFIFO) || | ||
389 | REG_IN_ARRAY(reg, DAM_LIVE_STATUS)) | ||
390 | return true; | ||
391 | |||
392 | return false; | ||
393 | } | ||
394 | |||
395 | static bool tegra30_ahub_apbif_precious_reg(struct device *dev, | ||
396 | unsigned int reg) | ||
397 | { | ||
398 | if (REG_IN_ARRAY(reg, CHANNEL_TXFIFO) || | ||
399 | REG_IN_ARRAY(reg, CHANNEL_RXFIFO)) | ||
400 | return true; | ||
401 | |||
402 | return false; | ||
403 | } | ||
404 | |||
405 | static const struct regmap_config tegra30_ahub_apbif_regmap_config = { | ||
406 | .name = "apbif", | ||
407 | .reg_bits = 32, | ||
408 | .val_bits = 32, | ||
409 | .reg_stride = 4, | ||
410 | .max_register = TEGRA30_AHUB_APBIF_INT_SET, | ||
411 | .writeable_reg = tegra30_ahub_apbif_wr_rd_reg, | ||
412 | .readable_reg = tegra30_ahub_apbif_wr_rd_reg, | ||
413 | .volatile_reg = tegra30_ahub_apbif_volatile_reg, | ||
414 | .precious_reg = tegra30_ahub_apbif_precious_reg, | ||
415 | .cache_type = REGCACHE_RBTREE, | ||
416 | }; | ||
417 | |||
418 | static bool tegra30_ahub_ahub_wr_rd_reg(struct device *dev, unsigned int reg) | ||
419 | { | ||
420 | if (REG_IN_ARRAY(reg, AUDIO_RX)) | ||
421 | return true; | ||
422 | |||
423 | return false; | ||
424 | } | ||
425 | |||
426 | static const struct regmap_config tegra30_ahub_ahub_regmap_config = { | ||
427 | .name = "ahub", | ||
428 | .reg_bits = 32, | ||
429 | .val_bits = 32, | ||
430 | .reg_stride = 4, | ||
431 | .max_register = LAST_REG(AUDIO_RX), | ||
432 | .writeable_reg = tegra30_ahub_ahub_wr_rd_reg, | ||
433 | .readable_reg = tegra30_ahub_ahub_wr_rd_reg, | ||
434 | .cache_type = REGCACHE_RBTREE, | ||
435 | }; | ||
436 | |||
437 | static int __devinit tegra30_ahub_probe(struct platform_device *pdev) | ||
438 | { | ||
439 | struct clk *clk; | ||
440 | int i; | ||
441 | struct resource *res0, *res1, *region; | ||
442 | u32 of_dma[2]; | ||
443 | void __iomem *regs_apbif, *regs_ahub; | ||
444 | int ret = 0; | ||
445 | |||
446 | if (ahub) | ||
447 | return -ENODEV; | ||
448 | |||
449 | /* | ||
450 | * The AHUB hosts a register bus: the "configlink". For this to | ||
451 | * operate correctly, all devices on this bus must be out of reset. | ||
452 | * Ensure that here. | ||
453 | */ | ||
454 | for (i = 0; i < ARRAY_SIZE(configlink_clocks); i++) { | ||
455 | clk = clk_get_sys(NULL, configlink_clocks[i]); | ||
456 | if (IS_ERR(clk)) { | ||
457 | dev_err(&pdev->dev, "Can't get clock %s\n", | ||
458 | configlink_clocks[i]); | ||
459 | ret = PTR_ERR(clk); | ||
460 | goto err; | ||
461 | } | ||
462 | tegra_periph_reset_deassert(clk); | ||
463 | clk_put(clk); | ||
464 | } | ||
465 | |||
466 | ahub = devm_kzalloc(&pdev->dev, sizeof(struct tegra30_ahub), | ||
467 | GFP_KERNEL); | ||
468 | if (!ahub) { | ||
469 | dev_err(&pdev->dev, "Can't allocate tegra30_ahub\n"); | ||
470 | ret = -ENOMEM; | ||
471 | goto err; | ||
472 | } | ||
473 | dev_set_drvdata(&pdev->dev, ahub); | ||
474 | |||
475 | ahub->dev = &pdev->dev; | ||
476 | |||
477 | ahub->clk_d_audio = clk_get(&pdev->dev, "d_audio"); | ||
478 | if (IS_ERR(ahub->clk_d_audio)) { | ||
479 | dev_err(&pdev->dev, "Can't retrieve ahub d_audio clock\n"); | ||
480 | ret = PTR_ERR(ahub->clk_d_audio); | ||
481 | goto err; | ||
482 | } | ||
483 | |||
484 | ahub->clk_apbif = clk_get(&pdev->dev, "apbif"); | ||
485 | if (IS_ERR(ahub->clk_apbif)) { | ||
486 | dev_err(&pdev->dev, "Can't retrieve ahub apbif clock\n"); | ||
487 | ret = PTR_ERR(ahub->clk_apbif); | ||
488 | goto err_clk_put_d_audio; | ||
489 | } | ||
490 | |||
491 | if (of_property_read_u32_array(pdev->dev.of_node, | ||
492 | "nvidia,dma-request-selector", | ||
493 | of_dma, 2) < 0) { | ||
494 | dev_err(&pdev->dev, | ||
495 | "Missing property nvidia,dma-request-selector\n"); | ||
496 | ret = -ENODEV; | ||
497 | goto err_clk_put_d_audio; | ||
498 | } | ||
499 | ahub->dma_sel = of_dma[1]; | ||
500 | |||
501 | res0 = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
502 | if (!res0) { | ||
503 | dev_err(&pdev->dev, "No apbif memory resource\n"); | ||
504 | ret = -ENODEV; | ||
505 | goto err_clk_put_apbif; | ||
506 | } | ||
507 | |||
508 | region = devm_request_mem_region(&pdev->dev, res0->start, | ||
509 | resource_size(res0), DRV_NAME); | ||
510 | if (!region) { | ||
511 | dev_err(&pdev->dev, "request region apbif failed\n"); | ||
512 | ret = -EBUSY; | ||
513 | goto err_clk_put_apbif; | ||
514 | } | ||
515 | ahub->apbif_addr = res0->start; | ||
516 | |||
517 | regs_apbif = devm_ioremap(&pdev->dev, res0->start, | ||
518 | resource_size(res0)); | ||
519 | if (!regs_apbif) { | ||
520 | dev_err(&pdev->dev, "ioremap apbif failed\n"); | ||
521 | ret = -ENOMEM; | ||
522 | goto err_clk_put_apbif; | ||
523 | } | ||
524 | |||
525 | ahub->regmap_apbif = devm_regmap_init_mmio(&pdev->dev, regs_apbif, | ||
526 | &tegra30_ahub_apbif_regmap_config); | ||
527 | if (IS_ERR(ahub->regmap_apbif)) { | ||
528 | dev_err(&pdev->dev, "apbif regmap init failed\n"); | ||
529 | ret = PTR_ERR(ahub->regmap_apbif); | ||
530 | goto err_clk_put_apbif; | ||
531 | } | ||
532 | regcache_cache_only(ahub->regmap_apbif, true); | ||
533 | |||
534 | res1 = platform_get_resource(pdev, IORESOURCE_MEM, 1); | ||
535 | if (!res1) { | ||
536 | dev_err(&pdev->dev, "No ahub memory resource\n"); | ||
537 | ret = -ENODEV; | ||
538 | goto err_clk_put_apbif; | ||
539 | } | ||
540 | |||
541 | region = devm_request_mem_region(&pdev->dev, res1->start, | ||
542 | resource_size(res1), DRV_NAME); | ||
543 | if (!region) { | ||
544 | dev_err(&pdev->dev, "request region ahub failed\n"); | ||
545 | ret = -EBUSY; | ||
546 | goto err_clk_put_apbif; | ||
547 | } | ||
548 | |||
549 | regs_ahub = devm_ioremap(&pdev->dev, res1->start, | ||
550 | resource_size(res1)); | ||
551 | if (!regs_ahub) { | ||
552 | dev_err(&pdev->dev, "ioremap ahub failed\n"); | ||
553 | ret = -ENOMEM; | ||
554 | goto err_clk_put_apbif; | ||
555 | } | ||
556 | |||
557 | ahub->regmap_ahub = devm_regmap_init_mmio(&pdev->dev, regs_ahub, | ||
558 | &tegra30_ahub_ahub_regmap_config); | ||
559 | if (IS_ERR(ahub->regmap_ahub)) { | ||
560 | dev_err(&pdev->dev, "ahub regmap init failed\n"); | ||
561 | ret = PTR_ERR(ahub->regmap_ahub); | ||
562 | goto err_clk_put_apbif; | ||
563 | } | ||
564 | regcache_cache_only(ahub->regmap_ahub, true); | ||
565 | |||
566 | pm_runtime_enable(&pdev->dev); | ||
567 | if (!pm_runtime_enabled(&pdev->dev)) { | ||
568 | ret = tegra30_ahub_runtime_resume(&pdev->dev); | ||
569 | if (ret) | ||
570 | goto err_pm_disable; | ||
571 | } | ||
572 | |||
573 | of_platform_populate(pdev->dev.of_node, NULL, ahub_auxdata, | ||
574 | &pdev->dev); | ||
575 | |||
576 | return 0; | ||
577 | |||
578 | err_pm_disable: | ||
579 | pm_runtime_disable(&pdev->dev); | ||
580 | err_clk_put_apbif: | ||
581 | clk_put(ahub->clk_apbif); | ||
582 | err_clk_put_d_audio: | ||
583 | clk_put(ahub->clk_d_audio); | ||
584 | ahub = 0; | ||
585 | err: | ||
586 | return ret; | ||
587 | } | ||
588 | |||
589 | static int __devexit tegra30_ahub_remove(struct platform_device *pdev) | ||
590 | { | ||
591 | if (!ahub) | ||
592 | return -ENODEV; | ||
593 | |||
594 | pm_runtime_disable(&pdev->dev); | ||
595 | if (!pm_runtime_status_suspended(&pdev->dev)) | ||
596 | tegra30_ahub_runtime_suspend(&pdev->dev); | ||
597 | |||
598 | clk_put(ahub->clk_apbif); | ||
599 | clk_put(ahub->clk_d_audio); | ||
600 | |||
601 | ahub = 0; | ||
602 | |||
603 | return 0; | ||
604 | } | ||
605 | |||
606 | static const struct of_device_id tegra30_ahub_of_match[] __devinitconst = { | ||
607 | { .compatible = "nvidia,tegra30-ahub", }, | ||
608 | {}, | ||
609 | }; | ||
610 | |||
611 | static const struct dev_pm_ops tegra30_ahub_pm_ops __devinitconst = { | ||
612 | SET_RUNTIME_PM_OPS(tegra30_ahub_runtime_suspend, | ||
613 | tegra30_ahub_runtime_resume, NULL) | ||
614 | }; | ||
615 | |||
616 | static struct platform_driver tegra30_ahub_driver = { | ||
617 | .probe = tegra30_ahub_probe, | ||
618 | .remove = __devexit_p(tegra30_ahub_remove), | ||
619 | .driver = { | ||
620 | .name = DRV_NAME, | ||
621 | .owner = THIS_MODULE, | ||
622 | .of_match_table = tegra30_ahub_of_match, | ||
623 | .pm = &tegra30_ahub_pm_ops, | ||
624 | }, | ||
625 | }; | ||
626 | module_platform_driver(tegra30_ahub_driver); | ||
627 | |||
628 | MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>"); | ||
629 | MODULE_DESCRIPTION("Tegra30 AHUB driver"); | ||
630 | MODULE_LICENSE("GPL v2"); | ||
631 | MODULE_ALIAS("platform:" DRV_NAME); | ||
diff --git a/sound/soc/tegra/tegra30_ahub.h b/sound/soc/tegra/tegra30_ahub.h new file mode 100644 index 000000000000..e690e2eecc92 --- /dev/null +++ b/sound/soc/tegra/tegra30_ahub.h | |||
@@ -0,0 +1,483 @@ | |||
1 | /* | ||
2 | * tegra30_ahub.h - Definitions for Tegra30 AHUB driver | ||
3 | * | ||
4 | * Copyright (c) 2011,2012, NVIDIA CORPORATION. All rights reserved. | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify it | ||
7 | * under the terms and conditions of the GNU General Public License, | ||
8 | * version 2, as published by the Free Software Foundation. | ||
9 | * | ||
10 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
13 | * more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | */ | ||
18 | |||
19 | #ifndef __TEGRA30_AHUB_H__ | ||
20 | #define __TEGRA30_AHUB_H__ | ||
21 | |||
22 | /* Fields in *_CIF_RX/TX_CTRL; used by AHUB FIFOs, and all other audio modules */ | ||
23 | |||
24 | #define TEGRA30_AUDIOCIF_CTRL_FIFO_THRESHOLD_SHIFT 28 | ||
25 | #define TEGRA30_AUDIOCIF_CTRL_FIFO_THRESHOLD_MASK_US 0xf | ||
26 | #define TEGRA30_AUDIOCIF_CTRL_FIFO_THRESHOLD_MASK (TEGRA30_AUDIOCIF_CTRL_FIFO_THRESHOLD_MASK_US << TEGRA30_AUDIOCIF_CTRL_FIFO_THRESHOLD_SHIFT) | ||
27 | |||
28 | /* Channel count minus 1 */ | ||
29 | #define TEGRA30_AUDIOCIF_CTRL_AUDIO_CHANNELS_SHIFT 24 | ||
30 | #define TEGRA30_AUDIOCIF_CTRL_AUDIO_CHANNELS_MASK_US 7 | ||
31 | #define TEGRA30_AUDIOCIF_CTRL_AUDIO_CHANNELS_MASK (TEGRA30_AUDIOCIF_CTRL_AUDIO_CHANNELS_MASK_US << TEGRA30_AUDIOCIF_CTRL_AUDIO_CHANNELS_SHIFT) | ||
32 | |||
33 | /* Channel count minus 1 */ | ||
34 | #define TEGRA30_AUDIOCIF_CTRL_CLIENT_CHANNELS_SHIFT 16 | ||
35 | #define TEGRA30_AUDIOCIF_CTRL_CLIENT_CHANNELS_MASK_US 7 | ||
36 | #define TEGRA30_AUDIOCIF_CTRL_CLIENT_CHANNELS_MASK (TEGRA30_AUDIOCIF_CTRL_CLIENT_CHANNELS_MASK_US << TEGRA30_AUDIOCIF_CTRL_CLIENT_CHANNELS_SHIFT) | ||
37 | |||
38 | #define TEGRA30_AUDIOCIF_BITS_4 0 | ||
39 | #define TEGRA30_AUDIOCIF_BITS_8 1 | ||
40 | #define TEGRA30_AUDIOCIF_BITS_12 2 | ||
41 | #define TEGRA30_AUDIOCIF_BITS_16 3 | ||
42 | #define TEGRA30_AUDIOCIF_BITS_20 4 | ||
43 | #define TEGRA30_AUDIOCIF_BITS_24 5 | ||
44 | #define TEGRA30_AUDIOCIF_BITS_28 6 | ||
45 | #define TEGRA30_AUDIOCIF_BITS_32 7 | ||
46 | |||
47 | #define TEGRA30_AUDIOCIF_CTRL_AUDIO_BITS_SHIFT 12 | ||
48 | #define TEGRA30_AUDIOCIF_CTRL_AUDIO_BITS_MASK (7 << TEGRA30_AUDIOCIF_CTRL_AUDIO_BITS_SHIFT) | ||
49 | #define TEGRA30_AUDIOCIF_CTRL_AUDIO_BITS_4 (TEGRA30_AUDIOCIF_BITS_4 << TEGRA30_AUDIOCIF_CTRL_AUDIO_BITS_SHIFT) | ||
50 | #define TEGRA30_AUDIOCIF_CTRL_AUDIO_BITS_8 (TEGRA30_AUDIOCIF_BITS_8 << TEGRA30_AUDIOCIF_CTRL_AUDIO_BITS_SHIFT) | ||
51 | #define TEGRA30_AUDIOCIF_CTRL_AUDIO_BITS_12 (TEGRA30_AUDIOCIF_BITS_12 << TEGRA30_AUDIOCIF_CTRL_AUDIO_BITS_SHIFT) | ||
52 | #define TEGRA30_AUDIOCIF_CTRL_AUDIO_BITS_16 (TEGRA30_AUDIOCIF_BITS_16 << TEGRA30_AUDIOCIF_CTRL_AUDIO_BITS_SHIFT) | ||
53 | #define TEGRA30_AUDIOCIF_CTRL_AUDIO_BITS_20 (TEGRA30_AUDIOCIF_BITS_20 << TEGRA30_AUDIOCIF_CTRL_AUDIO_BITS_SHIFT) | ||
54 | #define TEGRA30_AUDIOCIF_CTRL_AUDIO_BITS_24 (TEGRA30_AUDIOCIF_BITS_24 << TEGRA30_AUDIOCIF_CTRL_AUDIO_BITS_SHIFT) | ||
55 | #define TEGRA30_AUDIOCIF_CTRL_AUDIO_BITS_28 (TEGRA30_AUDIOCIF_BITS_28 << TEGRA30_AUDIOCIF_CTRL_AUDIO_BITS_SHIFT) | ||
56 | #define TEGRA30_AUDIOCIF_CTRL_AUDIO_BITS_32 (TEGRA30_AUDIOCIF_BITS_32 << TEGRA30_AUDIOCIF_CTRL_AUDIO_BITS_SHIFT) | ||
57 | |||
58 | #define TEGRA30_AUDIOCIF_CTRL_CLIENT_BITS_SHIFT 8 | ||
59 | #define TEGRA30_AUDIOCIF_CTRL_CLIENT_BITS_MASK (7 << TEGRA30_AUDIOCIF_CTRL_CLIENT_BITS_SHIFT) | ||
60 | #define TEGRA30_AUDIOCIF_CTRL_CLIENT_BITS_4 (TEGRA30_AUDIOCIF_BITS_4 << TEGRA30_AUDIOCIF_CTRL_CLIENT_BITS_SHIFT) | ||
61 | #define TEGRA30_AUDIOCIF_CTRL_CLIENT_BITS_8 (TEGRA30_AUDIOCIF_BITS_8 << TEGRA30_AUDIOCIF_CTRL_CLIENT_BITS_SHIFT) | ||
62 | #define TEGRA30_AUDIOCIF_CTRL_CLIENT_BITS_12 (TEGRA30_AUDIOCIF_BITS_12 << TEGRA30_AUDIOCIF_CTRL_CLIENT_BITS_SHIFT) | ||
63 | #define TEGRA30_AUDIOCIF_CTRL_CLIENT_BITS_16 (TEGRA30_AUDIOCIF_BITS_16 << TEGRA30_AUDIOCIF_CTRL_CLIENT_BITS_SHIFT) | ||
64 | #define TEGRA30_AUDIOCIF_CTRL_CLIENT_BITS_20 (TEGRA30_AUDIOCIF_BITS_20 << TEGRA30_AUDIOCIF_CTRL_CLIENT_BITS_SHIFT) | ||
65 | #define TEGRA30_AUDIOCIF_CTRL_CLIENT_BITS_24 (TEGRA30_AUDIOCIF_BITS_24 << TEGRA30_AUDIOCIF_CTRL_CLIENT_BITS_SHIFT) | ||
66 | #define TEGRA30_AUDIOCIF_CTRL_CLIENT_BITS_28 (TEGRA30_AUDIOCIF_BITS_28 << TEGRA30_AUDIOCIF_CTRL_CLIENT_BITS_SHIFT) | ||
67 | #define TEGRA30_AUDIOCIF_CTRL_CLIENT_BITS_32 (TEGRA30_AUDIOCIF_BITS_32 << TEGRA30_AUDIOCIF_CTRL_CLIENT_BITS_SHIFT) | ||
68 | |||
69 | #define TEGRA30_AUDIOCIF_EXPAND_ZERO 0 | ||
70 | #define TEGRA30_AUDIOCIF_EXPAND_ONE 1 | ||
71 | #define TEGRA30_AUDIOCIF_EXPAND_LFSR 2 | ||
72 | |||
73 | #define TEGRA30_AUDIOCIF_CTRL_EXPAND_SHIFT 6 | ||
74 | #define TEGRA30_AUDIOCIF_CTRL_EXPAND_MASK (3 << TEGRA30_AUDIOCIF_CTRL_EXPAND_SHIFT) | ||
75 | #define TEGRA30_AUDIOCIF_CTRL_EXPAND_ZERO (TEGRA30_AUDIOCIF_EXPAND_ZERO << TEGRA30_AUDIOCIF_CTRL_EXPAND_SHIFT) | ||
76 | #define TEGRA30_AUDIOCIF_CTRL_EXPAND_ONE (TEGRA30_AUDIOCIF_EXPAND_ONE << TEGRA30_AUDIOCIF_CTRL_EXPAND_SHIFT) | ||
77 | #define TEGRA30_AUDIOCIF_CTRL_EXPAND_LFSR (TEGRA30_AUDIOCIF_EXPAND_LFSR << TEGRA30_AUDIOCIF_CTRL_EXPAND_SHIFT) | ||
78 | |||
79 | #define TEGRA30_AUDIOCIF_STEREO_CONV_CH0 0 | ||
80 | #define TEGRA30_AUDIOCIF_STEREO_CONV_CH1 1 | ||
81 | #define TEGRA30_AUDIOCIF_STEREO_CONV_AVG 2 | ||
82 | |||
83 | #define TEGRA30_AUDIOCIF_CTRL_STEREO_CONV_SHIFT 4 | ||
84 | #define TEGRA30_AUDIOCIF_CTRL_STEREO_CONV_MASK (3 << TEGRA30_AUDIOCIF_CTRL_STEREO_CONV_SHIFT) | ||
85 | #define TEGRA30_AUDIOCIF_CTRL_STEREO_CONV_CH0 (TEGRA30_AUDIOCIF_STEREO_CONV_CH0 << TEGRA30_AUDIOCIF_CTRL_STEREO_CONV_SHIFT) | ||
86 | #define TEGRA30_AUDIOCIF_CTRL_STEREO_CONV_CH1 (TEGRA30_AUDIOCIF_STEREO_CONV_CH1 << TEGRA30_AUDIOCIF_CTRL_STEREO_CONV_SHIFT) | ||
87 | #define TEGRA30_AUDIOCIF_CTRL_STEREO_CONV_AVG (TEGRA30_AUDIOCIF_STEREO_CONV_AVG << TEGRA30_AUDIOCIF_CTRL_STEREO_CONV_SHIFT) | ||
88 | |||
89 | #define TEGRA30_AUDIOCIF_CTRL_REPLICATE 3 | ||
90 | |||
91 | #define TEGRA30_AUDIOCIF_DIRECTION_TX 0 | ||
92 | #define TEGRA30_AUDIOCIF_DIRECTION_RX 1 | ||
93 | |||
94 | #define TEGRA30_AUDIOCIF_CTRL_DIRECTION_SHIFT 2 | ||
95 | #define TEGRA30_AUDIOCIF_CTRL_DIRECTION_MASK (1 << TEGRA30_AUDIOCIF_CTRL_DIRECTION_SHIFT) | ||
96 | #define TEGRA30_AUDIOCIF_CTRL_DIRECTION_TX (TEGRA30_AUDIOCIF_DIRECTION_TX << TEGRA30_AUDIOCIF_CTRL_DIRECTION_SHIFT) | ||
97 | #define TEGRA30_AUDIOCIF_CTRL_DIRECTION_RX (TEGRA30_AUDIOCIF_DIRECTION_RX << TEGRA30_AUDIOCIF_CTRL_DIRECTION_SHIFT) | ||
98 | |||
99 | #define TEGRA30_AUDIOCIF_TRUNCATE_ROUND 0 | ||
100 | #define TEGRA30_AUDIOCIF_TRUNCATE_CHOP 1 | ||
101 | |||
102 | #define TEGRA30_AUDIOCIF_CTRL_TRUNCATE_SHIFT 1 | ||
103 | #define TEGRA30_AUDIOCIF_CTRL_TRUNCATE_MASK (1 << TEGRA30_AUDIOCIF_CTRL_TRUNCATE_SHIFT) | ||
104 | #define TEGRA30_AUDIOCIF_CTRL_TRUNCATE_ROUND (TEGRA30_AUDIOCIF_TRUNCATE_ROUND << TEGRA30_AUDIOCIF_CTRL_TRUNCATE_SHIFT) | ||
105 | #define TEGRA30_AUDIOCIF_CTRL_TRUNCATE_CHOP (TEGRA30_AUDIOCIF_TRUNCATE_CHOP << TEGRA30_AUDIOCIF_CTRL_TRUNCATE_SHIFT) | ||
106 | |||
107 | #define TEGRA30_AUDIOCIF_MONO_CONV_ZERO 0 | ||
108 | #define TEGRA30_AUDIOCIF_MONO_CONV_COPY 1 | ||
109 | |||
110 | #define TEGRA30_AUDIOCIF_CTRL_MONO_CONV_SHIFT 0 | ||
111 | #define TEGRA30_AUDIOCIF_CTRL_MONO_CONV_MASK (1 << TEGRA30_AUDIOCIF_CTRL_MONO_CONV_SHIFT) | ||
112 | #define TEGRA30_AUDIOCIF_CTRL_MONO_CONV_ZERO (TEGRA30_AUDIOCIF_MONO_CONV_ZERO << TEGRA30_AUDIOCIF_CTRL_MONO_CONV_SHIFT) | ||
113 | #define TEGRA30_AUDIOCIF_CTRL_MONO_CONV_COPY (TEGRA30_AUDIOCIF_MONO_CONV_COPY << TEGRA30_AUDIOCIF_CTRL_MONO_CONV_SHIFT) | ||
114 | |||
115 | /* Registers within TEGRA30_AUDIO_CLUSTER_BASE */ | ||
116 | |||
117 | /* TEGRA30_AHUB_CHANNEL_CTRL */ | ||
118 | |||
119 | #define TEGRA30_AHUB_CHANNEL_CTRL 0x0 | ||
120 | #define TEGRA30_AHUB_CHANNEL_CTRL_STRIDE 0x20 | ||
121 | #define TEGRA30_AHUB_CHANNEL_CTRL_COUNT 4 | ||
122 | #define TEGRA30_AHUB_CHANNEL_CTRL_TX_EN (1 << 31) | ||
123 | #define TEGRA30_AHUB_CHANNEL_CTRL_RX_EN (1 << 30) | ||
124 | #define TEGRA30_AHUB_CHANNEL_CTRL_LOOPBACK (1 << 29) | ||
125 | |||
126 | #define TEGRA30_AHUB_CHANNEL_CTRL_TX_THRESHOLD_SHIFT 16 | ||
127 | #define TEGRA30_AHUB_CHANNEL_CTRL_TX_THRESHOLD_MASK_US 0xff | ||
128 | #define TEGRA30_AHUB_CHANNEL_CTRL_TX_THRESHOLD_MASK (TEGRA30_AHUB_CHANNEL_CTRL_TX_THRESHOLD_MASK_US << TEGRA30_AHUB_CHANNEL_CTRL_TX_THRESHOLD_SHIFT) | ||
129 | |||
130 | #define TEGRA30_AHUB_CHANNEL_CTRL_RX_THRESHOLD_SHIFT 8 | ||
131 | #define TEGRA30_AHUB_CHANNEL_CTRL_RX_THRESHOLD_MASK_US 0xff | ||
132 | #define TEGRA30_AHUB_CHANNEL_CTRL_RX_THRESHOLD_MASK (TEGRA30_AHUB_CHANNEL_CTRL_RX_THRESHOLD_MASK_US << TEGRA30_AHUB_CHANNEL_CTRL_RX_THRESHOLD_SHIFT) | ||
133 | |||
134 | #define TEGRA30_AHUB_CHANNEL_CTRL_TX_PACK_EN (1 << 6) | ||
135 | |||
136 | #define TEGRA30_PACK_8_4 2 | ||
137 | #define TEGRA30_PACK_16 3 | ||
138 | |||
139 | #define TEGRA30_AHUB_CHANNEL_CTRL_TX_PACK_SHIFT 4 | ||
140 | #define TEGRA30_AHUB_CHANNEL_CTRL_TX_PACK_MASK_US 3 | ||
141 | #define TEGRA30_AHUB_CHANNEL_CTRL_TX_PACK_MASK (TEGRA30_AHUB_CHANNEL_CTRL_TX_PACK_MASK_US << TEGRA30_AHUB_CHANNEL_CTRL_TX_PACK_SHIFT) | ||
142 | #define TEGRA30_AHUB_CHANNEL_CTRL_TX_PACK_8_4 (TEGRA30_PACK_8_4 << TEGRA30_AHUB_CHANNEL_CTRL_TX_PACK_SHIFT) | ||
143 | #define TEGRA30_AHUB_CHANNEL_CTRL_TX_PACK_16 (TEGRA30_PACK_16 << TEGRA30_AHUB_CHANNEL_CTRL_TX_PACK_SHIFT) | ||
144 | |||
145 | #define TEGRA30_AHUB_CHANNEL_CTRL_RX_PACK_EN (1 << 2) | ||
146 | |||
147 | #define TEGRA30_AHUB_CHANNEL_CTRL_RX_PACK_SHIFT 0 | ||
148 | #define TEGRA30_AHUB_CHANNEL_CTRL_RX_PACK_MASK_US 3 | ||
149 | #define TEGRA30_AHUB_CHANNEL_CTRL_RX_PACK_MASK (TEGRA30_AHUB_CHANNEL_CTRL_RX_PACK_MASK_US << TEGRA30_AHUB_CHANNEL_CTRL_RX_PACK_SHIFT) | ||
150 | #define TEGRA30_AHUB_CHANNEL_CTRL_RX_PACK_8_4 (TEGRA30_PACK_8_4 << TEGRA30_AHUB_CHANNEL_CTRL_RX_PACK_SHIFT) | ||
151 | #define TEGRA30_AHUB_CHANNEL_CTRL_RX_PACK_16 (TEGRA30_PACK_16 << TEGRA30_AHUB_CHANNEL_CTRL_RX_PACK_SHIFT) | ||
152 | |||
153 | /* TEGRA30_AHUB_CHANNEL_CLEAR */ | ||
154 | |||
155 | #define TEGRA30_AHUB_CHANNEL_CLEAR 0x4 | ||
156 | #define TEGRA30_AHUB_CHANNEL_CLEAR_STRIDE 0x20 | ||
157 | #define TEGRA30_AHUB_CHANNEL_CLEAR_COUNT 4 | ||
158 | #define TEGRA30_AHUB_CHANNEL_CLEAR_TX_SOFT_RESET (1 << 31) | ||
159 | #define TEGRA30_AHUB_CHANNEL_CLEAR_RX_SOFT_RESET (1 << 30) | ||
160 | |||
161 | /* TEGRA30_AHUB_CHANNEL_STATUS */ | ||
162 | |||
163 | #define TEGRA30_AHUB_CHANNEL_STATUS 0x8 | ||
164 | #define TEGRA30_AHUB_CHANNEL_STATUS_STRIDE 0x20 | ||
165 | #define TEGRA30_AHUB_CHANNEL_STATUS_COUNT 4 | ||
166 | #define TEGRA30_AHUB_CHANNEL_STATUS_TX_FREE_SHIFT 24 | ||
167 | #define TEGRA30_AHUB_CHANNEL_STATUS_TX_FREE_MASK_US 0xff | ||
168 | #define TEGRA30_AHUB_CHANNEL_STATUS_TX_FREE_MASK (TEGRA30_AHUB_CHANNEL_STATUS_TX_FREE_MASK_US << TEGRA30_AHUB_CHANNEL_STATUS_TX_FREE_SHIFT) | ||
169 | #define TEGRA30_AHUB_CHANNEL_STATUS_RX_FREE_SHIFT 16 | ||
170 | #define TEGRA30_AHUB_CHANNEL_STATUS_RX_FREE_MASK_US 0xff | ||
171 | #define TEGRA30_AHUB_CHANNEL_STATUS_RX_FREE_MASK (TEGRA30_AHUB_CHANNEL_STATUS_RX_FREE_MASK_US << TEGRA30_AHUB_CHANNEL_STATUS_RX_FREE_SHIFT) | ||
172 | #define TEGRA30_AHUB_CHANNEL_STATUS_TX_TRIG (1 << 1) | ||
173 | #define TEGRA30_AHUB_CHANNEL_STATUS_RX_TRIG (1 << 0) | ||
174 | |||
175 | /* TEGRA30_AHUB_CHANNEL_TXFIFO */ | ||
176 | |||
177 | #define TEGRA30_AHUB_CHANNEL_TXFIFO 0xc | ||
178 | #define TEGRA30_AHUB_CHANNEL_TXFIFO_STRIDE 0x20 | ||
179 | #define TEGRA30_AHUB_CHANNEL_TXFIFO_COUNT 4 | ||
180 | |||
181 | /* TEGRA30_AHUB_CHANNEL_RXFIFO */ | ||
182 | |||
183 | #define TEGRA30_AHUB_CHANNEL_RXFIFO 0x10 | ||
184 | #define TEGRA30_AHUB_CHANNEL_RXFIFO_STRIDE 0x20 | ||
185 | #define TEGRA30_AHUB_CHANNEL_RXFIFO_COUNT 4 | ||
186 | |||
187 | /* TEGRA30_AHUB_CIF_TX_CTRL */ | ||
188 | |||
189 | #define TEGRA30_AHUB_CIF_TX_CTRL 0x14 | ||
190 | #define TEGRA30_AHUB_CIF_TX_CTRL_STRIDE 0x20 | ||
191 | #define TEGRA30_AHUB_CIF_TX_CTRL_COUNT 4 | ||
192 | /* Uses field from TEGRA30_AUDIOCIF_CTRL_* */ | ||
193 | |||
194 | /* TEGRA30_AHUB_CIF_RX_CTRL */ | ||
195 | |||
196 | #define TEGRA30_AHUB_CIF_RX_CTRL 0x18 | ||
197 | #define TEGRA30_AHUB_CIF_RX_CTRL_STRIDE 0x20 | ||
198 | #define TEGRA30_AHUB_CIF_RX_CTRL_COUNT 4 | ||
199 | /* Uses field from TEGRA30_AUDIOCIF_CTRL_* */ | ||
200 | |||
201 | /* TEGRA30_AHUB_CONFIG_LINK_CTRL */ | ||
202 | |||
203 | #define TEGRA30_AHUB_CONFIG_LINK_CTRL 0x80 | ||
204 | #define TEGRA30_AHUB_CONFIG_LINK_CTRL_MASTER_FIFO_FULL_CNT_SHIFT 28 | ||
205 | #define TEGRA30_AHUB_CONFIG_LINK_CTRL_MASTER_FIFO_FULL_CNT_MASK_US 0xf | ||
206 | #define TEGRA30_AHUB_CONFIG_LINK_CTRL_MASTER_FIFO_FULL_CNT_MASK (TEGRA30_AHUB_CONFIG_LINK_CTRL_MASTER_FIFO_FULL_CNT_MASK_US << TEGRA30_AHUB_CONFIG_LINK_CTRL_MASTER_FIFO_FULL_CNT_SHIFT) | ||
207 | #define TEGRA30_AHUB_CONFIG_LINK_CTRL_TIMEOUT_CNT_SHIFT 16 | ||
208 | #define TEGRA30_AHUB_CONFIG_LINK_CTRL_TIMEOUT_CNT_MASK_US 0xfff | ||
209 | #define TEGRA30_AHUB_CONFIG_LINK_CTRL_TIMEOUT_CNT_MASK (TEGRA30_AHUB_CONFIG_LINK_CTRL_TIMEOUT_CNT_MASK_US << TEGRA30_AHUB_CONFIG_LINK_CTRL_TIMEOUT_CNT_SHIFT) | ||
210 | #define TEGRA30_AHUB_CONFIG_LINK_CTRL_IDLE_CNT_SHIFT 4 | ||
211 | #define TEGRA30_AHUB_CONFIG_LINK_CTRL_IDLE_CNT_MASK_US 0xfff | ||
212 | #define TEGRA30_AHUB_CONFIG_LINK_CTRL_IDLE_CNT_MASK (TEGRA30_AHUB_CONFIG_LINK_CTRL_IDLE_CNT_MASK_US << TEGRA30_AHUB_CONFIG_LINK_CTRL_IDLE_CNT_SHIFT) | ||
213 | #define TEGRA30_AHUB_CONFIG_LINK_CTRL_CG_EN (1 << 2) | ||
214 | #define TEGRA30_AHUB_CONFIG_LINK_CTRL_CLEAR_TIMEOUT_CNTR (1 << 1) | ||
215 | #define TEGRA30_AHUB_CONFIG_LINK_CTRL_SOFT_RESET (1 << 0) | ||
216 | |||
217 | /* TEGRA30_AHUB_MISC_CTRL */ | ||
218 | |||
219 | #define TEGRA30_AHUB_MISC_CTRL 0x84 | ||
220 | #define TEGRA30_AHUB_MISC_CTRL_AUDIO_ACTIVE (1 << 31) | ||
221 | #define TEGRA30_AHUB_MISC_CTRL_AUDIO_CG_EN (1 << 8) | ||
222 | #define TEGRA30_AHUB_MISC_CTRL_AUDIO_OBS_SEL_SHIFT 0 | ||
223 | #define TEGRA30_AHUB_MISC_CTRL_AUDIO_OBS_SEL_MASK (0x1f << TEGRA30_AHUB_MISC_CTRL_AUDIO_OBS_SEL_SHIFT) | ||
224 | |||
225 | /* TEGRA30_AHUB_APBDMA_LIVE_STATUS */ | ||
226 | |||
227 | #define TEGRA30_AHUB_APBDMA_LIVE_STATUS 0x88 | ||
228 | #define TEGRA30_AHUB_APBDMA_LIVE_STATUS_CH3_RX_CIF_FIFO_FULL (1 << 31) | ||
229 | #define TEGRA30_AHUB_APBDMA_LIVE_STATUS_CH3_TX_CIF_FIFO_FULL (1 << 30) | ||
230 | #define TEGRA30_AHUB_APBDMA_LIVE_STATUS_CH2_RX_CIF_FIFO_FULL (1 << 29) | ||
231 | #define TEGRA30_AHUB_APBDMA_LIVE_STATUS_CH2_TX_CIF_FIFO_FULL (1 << 28) | ||
232 | #define TEGRA30_AHUB_APBDMA_LIVE_STATUS_CH1_RX_CIF_FIFO_FULL (1 << 27) | ||
233 | #define TEGRA30_AHUB_APBDMA_LIVE_STATUS_CH1_TX_CIF_FIFO_FULL (1 << 26) | ||
234 | #define TEGRA30_AHUB_APBDMA_LIVE_STATUS_CH0_RX_CIF_FIFO_FULL (1 << 25) | ||
235 | #define TEGRA30_AHUB_APBDMA_LIVE_STATUS_CH0_TX_CIF_FIFO_FULL (1 << 24) | ||
236 | #define TEGRA30_AHUB_APBDMA_LIVE_STATUS_CH3_RX_CIF_FIFO_EMPTY (1 << 23) | ||
237 | #define TEGRA30_AHUB_APBDMA_LIVE_STATUS_CH3_TX_CIF_FIFO_EMPTY (1 << 22) | ||
238 | #define TEGRA30_AHUB_APBDMA_LIVE_STATUS_CH2_RX_CIF_FIFO_EMPTY (1 << 21) | ||
239 | #define TEGRA30_AHUB_APBDMA_LIVE_STATUS_CH2_TX_CIF_FIFO_EMPTY (1 << 20) | ||
240 | #define TEGRA30_AHUB_APBDMA_LIVE_STATUS_CH1_RX_CIF_FIFO_EMPTY (1 << 19) | ||
241 | #define TEGRA30_AHUB_APBDMA_LIVE_STATUS_CH1_TX_CIF_FIFO_EMPTY (1 << 18) | ||
242 | #define TEGRA30_AHUB_APBDMA_LIVE_STATUS_CH0_RX_CIF_FIFO_EMPTY (1 << 17) | ||
243 | #define TEGRA30_AHUB_APBDMA_LIVE_STATUS_CH0_TX_CIF_FIFO_EMPTY (1 << 16) | ||
244 | #define TEGRA30_AHUB_APBDMA_LIVE_STATUS_CH3_RX_DMA_FIFO_FULL (1 << 15) | ||
245 | #define TEGRA30_AHUB_APBDMA_LIVE_STATUS_CH3_TX_DMA_FIFO_FULL (1 << 14) | ||
246 | #define TEGRA30_AHUB_APBDMA_LIVE_STATUS_CH2_RX_DMA_FIFO_FULL (1 << 13) | ||
247 | #define TEGRA30_AHUB_APBDMA_LIVE_STATUS_CH2_TX_DMA_FIFO_FULL (1 << 12) | ||
248 | #define TEGRA30_AHUB_APBDMA_LIVE_STATUS_CH1_RX_DMA_FIFO_FULL (1 << 11) | ||
249 | #define TEGRA30_AHUB_APBDMA_LIVE_STATUS_CH1_TX_DMA_FIFO_FULL (1 << 10) | ||
250 | #define TEGRA30_AHUB_APBDMA_LIVE_STATUS_CH0_RX_DMA_FIFO_FULL (1 << 9) | ||
251 | #define TEGRA30_AHUB_APBDMA_LIVE_STATUS_CH0_TX_DMA_FIFO_FULL (1 << 8) | ||
252 | #define TEGRA30_AHUB_APBDMA_LIVE_STATUS_CH3_RX_DMA_FIFO_EMPTY (1 << 7) | ||
253 | #define TEGRA30_AHUB_APBDMA_LIVE_STATUS_CH3_TX_DMA_FIFO_EMPTY (1 << 6) | ||
254 | #define TEGRA30_AHUB_APBDMA_LIVE_STATUS_CH2_RX_DMA_FIFO_EMPTY (1 << 5) | ||
255 | #define TEGRA30_AHUB_APBDMA_LIVE_STATUS_CH2_TX_DMA_FIFO_EMPTY (1 << 4) | ||
256 | #define TEGRA30_AHUB_APBDMA_LIVE_STATUS_CH1_RX_DMA_FIFO_EMPTY (1 << 3) | ||
257 | #define TEGRA30_AHUB_APBDMA_LIVE_STATUS_CH1_TX_DMA_FIFO_EMPTY (1 << 2) | ||
258 | #define TEGRA30_AHUB_APBDMA_LIVE_STATUS_CH0_RX_DMA_FIFO_EMPTY (1 << 1) | ||
259 | #define TEGRA30_AHUB_APBDMA_LIVE_STATUS_CH0_TX_DMA_FIFO_EMPTY (1 << 0) | ||
260 | |||
261 | /* TEGRA30_AHUB_I2S_LIVE_STATUS */ | ||
262 | |||
263 | #define TEGRA30_AHUB_I2S_LIVE_STATUS 0x8c | ||
264 | #define TEGRA30_AHUB_I2S_LIVE_STATUS_I2S4_RX_FIFO_FULL (1 << 29) | ||
265 | #define TEGRA30_AHUB_I2S_LIVE_STATUS_I2S4_TX_FIFO_FULL (1 << 28) | ||
266 | #define TEGRA30_AHUB_I2S_LIVE_STATUS_I2S3_RX_FIFO_FULL (1 << 27) | ||
267 | #define TEGRA30_AHUB_I2S_LIVE_STATUS_I2S3_TX_FIFO_FULL (1 << 26) | ||
268 | #define TEGRA30_AHUB_I2S_LIVE_STATUS_I2S2_RX_FIFO_FULL (1 << 25) | ||
269 | #define TEGRA30_AHUB_I2S_LIVE_STATUS_I2S2_TX_FIFO_FULL (1 << 24) | ||
270 | #define TEGRA30_AHUB_I2S_LIVE_STATUS_I2S1_RX_FIFO_FULL (1 << 23) | ||
271 | #define TEGRA30_AHUB_I2S_LIVE_STATUS_I2S1_TX_FIFO_FULL (1 << 22) | ||
272 | #define TEGRA30_AHUB_I2S_LIVE_STATUS_I2S0_RX_FIFO_FULL (1 << 21) | ||
273 | #define TEGRA30_AHUB_I2S_LIVE_STATUS_I2S0_TX_FIFO_FULL (1 << 20) | ||
274 | #define TEGRA30_AHUB_I2S_LIVE_STATUS_I2S4_RX_FIFO_ENABLED (1 << 19) | ||
275 | #define TEGRA30_AHUB_I2S_LIVE_STATUS_I2S4_TX_FIFO_ENABLED (1 << 18) | ||
276 | #define TEGRA30_AHUB_I2S_LIVE_STATUS_I2S3_RX_FIFO_ENABLED (1 << 17) | ||
277 | #define TEGRA30_AHUB_I2S_LIVE_STATUS_I2S3_TX_FIFO_ENABLED (1 << 16) | ||
278 | #define TEGRA30_AHUB_I2S_LIVE_STATUS_I2S2_RX_FIFO_ENABLED (1 << 15) | ||
279 | #define TEGRA30_AHUB_I2S_LIVE_STATUS_I2S2_TX_FIFO_ENABLED (1 << 14) | ||
280 | #define TEGRA30_AHUB_I2S_LIVE_STATUS_I2S1_RX_FIFO_ENABLED (1 << 13) | ||
281 | #define TEGRA30_AHUB_I2S_LIVE_STATUS_I2S1_TX_FIFO_ENABLED (1 << 12) | ||
282 | #define TEGRA30_AHUB_I2S_LIVE_STATUS_I2S0_RX_FIFO_ENABLED (1 << 11) | ||
283 | #define TEGRA30_AHUB_I2S_LIVE_STATUS_I2S0_TX_FIFO_ENABLED (1 << 10) | ||
284 | #define TEGRA30_AHUB_I2S_LIVE_STATUS_I2S4_RX_FIFO_EMPTY (1 << 9) | ||
285 | #define TEGRA30_AHUB_I2S_LIVE_STATUS_I2S4_TX_FIFO_EMPTY (1 << 8) | ||
286 | #define TEGRA30_AHUB_I2S_LIVE_STATUS_I2S3_RX_FIFO_EMPTY (1 << 7) | ||
287 | #define TEGRA30_AHUB_I2S_LIVE_STATUS_I2S3_TX_FIFO_EMPTY (1 << 6) | ||
288 | #define TEGRA30_AHUB_I2S_LIVE_STATUS_I2S2_RX_FIFO_EMPTY (1 << 5) | ||
289 | #define TEGRA30_AHUB_I2S_LIVE_STATUS_I2S2_TX_FIFO_EMPTY (1 << 4) | ||
290 | #define TEGRA30_AHUB_I2S_LIVE_STATUS_I2S1_RX_FIFO_EMPTY (1 << 3) | ||
291 | #define TEGRA30_AHUB_I2S_LIVE_STATUS_I2S1_TX_FIFO_EMPTY (1 << 2) | ||
292 | #define TEGRA30_AHUB_I2S_LIVE_STATUS_I2S0_RX_FIFO_EMPTY (1 << 1) | ||
293 | #define TEGRA30_AHUB_I2S_LIVE_STATUS_I2S0_TX_FIFO_EMPTY (1 << 0) | ||
294 | |||
295 | /* TEGRA30_AHUB_DAM0_LIVE_STATUS */ | ||
296 | |||
297 | #define TEGRA30_AHUB_DAM_LIVE_STATUS 0x90 | ||
298 | #define TEGRA30_AHUB_DAM_LIVE_STATUS_STRIDE 0x8 | ||
299 | #define TEGRA30_AHUB_DAM_LIVE_STATUS_COUNT 3 | ||
300 | #define TEGRA30_AHUB_DAM_LIVE_STATUS_TX_ENABLED (1 << 26) | ||
301 | #define TEGRA30_AHUB_DAM_LIVE_STATUS_RX1_ENABLED (1 << 25) | ||
302 | #define TEGRA30_AHUB_DAM_LIVE_STATUS_RX0_ENABLED (1 << 24) | ||
303 | #define TEGRA30_AHUB_DAM_LIVE_STATUS_TXFIFO_FULL (1 << 15) | ||
304 | #define TEGRA30_AHUB_DAM_LIVE_STATUS_RX1FIFO_FULL (1 << 9) | ||
305 | #define TEGRA30_AHUB_DAM_LIVE_STATUS_RX0FIFO_FULL (1 << 8) | ||
306 | #define TEGRA30_AHUB_DAM_LIVE_STATUS_TXFIFO_EMPTY (1 << 7) | ||
307 | #define TEGRA30_AHUB_DAM_LIVE_STATUS_RX1FIFO_EMPTY (1 << 1) | ||
308 | #define TEGRA30_AHUB_DAM_LIVE_STATUS_RX0FIFO_EMPTY (1 << 0) | ||
309 | |||
310 | /* TEGRA30_AHUB_SPDIF_LIVE_STATUS */ | ||
311 | |||
312 | #define TEGRA30_AHUB_SPDIF_LIVE_STATUS 0xa8 | ||
313 | #define TEGRA30_AHUB_SPDIF_LIVE_STATUS_USER_TX_ENABLED (1 << 11) | ||
314 | #define TEGRA30_AHUB_SPDIF_LIVE_STATUS_USER_RX_ENABLED (1 << 10) | ||
315 | #define TEGRA30_AHUB_SPDIF_LIVE_STATUS_DATA_TX_ENABLED (1 << 9) | ||
316 | #define TEGRA30_AHUB_SPDIF_LIVE_STATUS_DATA_RX_ENABLED (1 << 8) | ||
317 | #define TEGRA30_AHUB_SPDIF_LIVE_STATUS_USER_TXFIFO_FULL (1 << 7) | ||
318 | #define TEGRA30_AHUB_SPDIF_LIVE_STATUS_USER_RXFIFO_FULL (1 << 6) | ||
319 | #define TEGRA30_AHUB_SPDIF_LIVE_STATUS_DATA_TXFIFO_FULL (1 << 5) | ||
320 | #define TEGRA30_AHUB_SPDIF_LIVE_STATUS_DATA_RXFIFO_FULL (1 << 4) | ||
321 | #define TEGRA30_AHUB_SPDIF_LIVE_STATUS_USER_TXFIFO_EMPTY (1 << 3) | ||
322 | #define TEGRA30_AHUB_SPDIF_LIVE_STATUS_USER_RXFIFO_EMPTY (1 << 2) | ||
323 | #define TEGRA30_AHUB_SPDIF_LIVE_STATUS_DATA_TXFIFO_EMPTY (1 << 1) | ||
324 | #define TEGRA30_AHUB_SPDIF_LIVE_STATUS_DATA_RXFIFO_EMPTY (1 << 0) | ||
325 | |||
326 | /* TEGRA30_AHUB_I2S_INT_MASK */ | ||
327 | |||
328 | #define TEGRA30_AHUB_I2S_INT_MASK 0xb0 | ||
329 | |||
330 | /* TEGRA30_AHUB_DAM_INT_MASK */ | ||
331 | |||
332 | #define TEGRA30_AHUB_DAM_INT_MASK 0xb4 | ||
333 | |||
334 | /* TEGRA30_AHUB_SPDIF_INT_MASK */ | ||
335 | |||
336 | #define TEGRA30_AHUB_SPDIF_INT_MASK 0xbc | ||
337 | |||
338 | /* TEGRA30_AHUB_APBIF_INT_MASK */ | ||
339 | |||
340 | #define TEGRA30_AHUB_APBIF_INT_MASK 0xc0 | ||
341 | |||
342 | /* TEGRA30_AHUB_I2S_INT_STATUS */ | ||
343 | |||
344 | #define TEGRA30_AHUB_I2S_INT_STATUS 0xc8 | ||
345 | |||
346 | /* TEGRA30_AHUB_DAM_INT_STATUS */ | ||
347 | |||
348 | #define TEGRA30_AHUB_DAM_INT_STATUS 0xcc | ||
349 | |||
350 | /* TEGRA30_AHUB_SPDIF_INT_STATUS */ | ||
351 | |||
352 | #define TEGRA30_AHUB_SPDIF_INT_STATUS 0xd4 | ||
353 | |||
354 | /* TEGRA30_AHUB_APBIF_INT_STATUS */ | ||
355 | |||
356 | #define TEGRA30_AHUB_APBIF_INT_STATUS 0xd8 | ||
357 | |||
358 | /* TEGRA30_AHUB_I2S_INT_SOURCE */ | ||
359 | |||
360 | #define TEGRA30_AHUB_I2S_INT_SOURCE 0xe0 | ||
361 | |||
362 | /* TEGRA30_AHUB_DAM_INT_SOURCE */ | ||
363 | |||
364 | #define TEGRA30_AHUB_DAM_INT_SOURCE 0xe4 | ||
365 | |||
366 | /* TEGRA30_AHUB_SPDIF_INT_SOURCE */ | ||
367 | |||
368 | #define TEGRA30_AHUB_SPDIF_INT_SOURCE 0xec | ||
369 | |||
370 | /* TEGRA30_AHUB_APBIF_INT_SOURCE */ | ||
371 | |||
372 | #define TEGRA30_AHUB_APBIF_INT_SOURCE 0xf0 | ||
373 | |||
374 | /* TEGRA30_AHUB_I2S_INT_SET */ | ||
375 | |||
376 | #define TEGRA30_AHUB_I2S_INT_SET 0xf8 | ||
377 | |||
378 | /* TEGRA30_AHUB_DAM_INT_SET */ | ||
379 | |||
380 | #define TEGRA30_AHUB_DAM_INT_SET 0xfc | ||
381 | |||
382 | /* TEGRA30_AHUB_SPDIF_INT_SET */ | ||
383 | |||
384 | #define TEGRA30_AHUB_SPDIF_INT_SET 0x100 | ||
385 | |||
386 | /* TEGRA30_AHUB_APBIF_INT_SET */ | ||
387 | |||
388 | #define TEGRA30_AHUB_APBIF_INT_SET 0x104 | ||
389 | |||
390 | /* Registers within TEGRA30_AHUB_BASE */ | ||
391 | |||
392 | #define TEGRA30_AHUB_AUDIO_RX 0x0 | ||
393 | #define TEGRA30_AHUB_AUDIO_RX_STRIDE 0x4 | ||
394 | #define TEGRA30_AHUB_AUDIO_RX_COUNT 17 | ||
395 | /* This register repeats once for each entry in enum tegra30_ahub_rxcif */ | ||
396 | /* The fields in this register are 1 bit per entry in tegra30_ahub_txcif */ | ||
397 | |||
398 | /* | ||
399 | * Terminology: | ||
400 | * AHUB: Audio Hub; a cross-bar switch between the audio devices: DMA FIFOs, | ||
401 | * I2S controllers, SPDIF controllers, and DAMs. | ||
402 | * XBAR: The core cross-bar component of the AHUB. | ||
403 | * CIF: Client Interface; the HW module connecting an audio device to the | ||
404 | * XBAR. | ||
405 | * DAM: Digital Audio Mixer: A HW module that mixes multiple audio streams, | ||
406 | * possibly including sample-rate conversion. | ||
407 | * | ||
408 | * Each TX CIF transmits data into the XBAR. Each RX CIF can receive audio | ||
409 | * transmitted by a particular TX CIF. | ||
410 | * | ||
411 | * This driver is currently very simplistic; many HW features are not | ||
412 | * exposed; DAMs are not supported, only 16-bit stereo audio is supported, | ||
413 | * etc. | ||
414 | */ | ||
415 | |||
416 | enum tegra30_ahub_txcif { | ||
417 | TEGRA30_AHUB_TXCIF_APBIF_TX0, | ||
418 | TEGRA30_AHUB_TXCIF_APBIF_TX1, | ||
419 | TEGRA30_AHUB_TXCIF_APBIF_TX2, | ||
420 | TEGRA30_AHUB_TXCIF_APBIF_TX3, | ||
421 | TEGRA30_AHUB_TXCIF_I2S0_TX0, | ||
422 | TEGRA30_AHUB_TXCIF_I2S1_TX0, | ||
423 | TEGRA30_AHUB_TXCIF_I2S2_TX0, | ||
424 | TEGRA30_AHUB_TXCIF_I2S3_TX0, | ||
425 | TEGRA30_AHUB_TXCIF_I2S4_TX0, | ||
426 | TEGRA30_AHUB_TXCIF_DAM0_TX0, | ||
427 | TEGRA30_AHUB_TXCIF_DAM1_TX0, | ||
428 | TEGRA30_AHUB_TXCIF_DAM2_TX0, | ||
429 | TEGRA30_AHUB_TXCIF_SPDIF_TX0, | ||
430 | TEGRA30_AHUB_TXCIF_SPDIF_TX1, | ||
431 | }; | ||
432 | |||
433 | enum tegra30_ahub_rxcif { | ||
434 | TEGRA30_AHUB_RXCIF_APBIF_RX0, | ||
435 | TEGRA30_AHUB_RXCIF_APBIF_RX1, | ||
436 | TEGRA30_AHUB_RXcIF_APBIF_RX2, | ||
437 | TEGRA30_AHUB_RXCIF_APBIF_RX3, | ||
438 | TEGRA30_AHUB_RXCIF_I2S0_RX0, | ||
439 | TEGRA30_AHUB_RXCIF_I2S1_RX0, | ||
440 | TEGRA30_AHUB_RXCIF_I2S2_RX0, | ||
441 | TEGRA30_AHUB_RXCIF_I2S3_RX0, | ||
442 | TEGRA30_AHUB_RXCIF_I2S4_RX0, | ||
443 | TEGRA30_AHUB_RXCIF_DAM0_RX0, | ||
444 | TEGRA30_AHUB_RXCIF_DAM0_RX1, | ||
445 | TEGRA30_AHUB_RXCIF_DAM1_RX0, | ||
446 | TEGRA30_AHUB_RXCIF_DAM2_RX1, | ||
447 | TEGRA30_AHUB_RXCIF_DAM3_RX0, | ||
448 | TEGRA30_AHUB_RXCIF_DAM3_RX1, | ||
449 | TEGRA30_AHUB_RXCIF_SPDIF_RX0, | ||
450 | TEGRA30_AHUB_RXCIF_SPDIF_RX1, | ||
451 | }; | ||
452 | |||
453 | extern int tegra30_ahub_allocate_rx_fifo(enum tegra30_ahub_rxcif *rxcif, | ||
454 | unsigned long *fiforeg, | ||
455 | unsigned long *reqsel); | ||
456 | extern int tegra30_ahub_enable_rx_fifo(enum tegra30_ahub_rxcif rxcif); | ||
457 | extern int tegra30_ahub_disable_rx_fifo(enum tegra30_ahub_rxcif rxcif); | ||
458 | extern int tegra30_ahub_free_rx_fifo(enum tegra30_ahub_rxcif rxcif); | ||
459 | |||
460 | extern int tegra30_ahub_allocate_tx_fifo(enum tegra30_ahub_txcif *txcif, | ||
461 | unsigned long *fiforeg, | ||
462 | unsigned long *reqsel); | ||
463 | extern int tegra30_ahub_enable_tx_fifo(enum tegra30_ahub_txcif txcif); | ||
464 | extern int tegra30_ahub_disable_tx_fifo(enum tegra30_ahub_txcif txcif); | ||
465 | extern int tegra30_ahub_free_tx_fifo(enum tegra30_ahub_txcif txcif); | ||
466 | |||
467 | extern int tegra30_ahub_set_rx_cif_source(enum tegra30_ahub_rxcif rxcif, | ||
468 | enum tegra30_ahub_txcif txcif); | ||
469 | extern int tegra30_ahub_unset_rx_cif_source(enum tegra30_ahub_rxcif rxcif); | ||
470 | |||
471 | struct tegra30_ahub { | ||
472 | struct device *dev; | ||
473 | struct clk *clk_d_audio; | ||
474 | struct clk *clk_apbif; | ||
475 | int dma_sel; | ||
476 | resource_size_t apbif_addr; | ||
477 | struct regmap *regmap_apbif; | ||
478 | struct regmap *regmap_ahub; | ||
479 | DECLARE_BITMAP(rx_usage, TEGRA30_AHUB_CHANNEL_CTRL_COUNT); | ||
480 | DECLARE_BITMAP(tx_usage, TEGRA30_AHUB_CHANNEL_CTRL_COUNT); | ||
481 | }; | ||
482 | |||
483 | #endif | ||
diff --git a/sound/soc/tegra/tegra30_i2s.c b/sound/soc/tegra/tegra30_i2s.c new file mode 100644 index 000000000000..8596032985dc --- /dev/null +++ b/sound/soc/tegra/tegra30_i2s.c | |||
@@ -0,0 +1,536 @@ | |||
1 | /* | ||
2 | * tegra30_i2s.c - Tegra30 I2S driver | ||
3 | * | ||
4 | * Author: Stephen Warren <swarren@nvidia.com> | ||
5 | * Copyright (c) 2010-2012, NVIDIA CORPORATION. All rights reserved. | ||
6 | * | ||
7 | * Based on code copyright/by: | ||
8 | * | ||
9 | * Copyright (c) 2009-2010, NVIDIA Corporation. | ||
10 | * Scott Peterson <speterson@nvidia.com> | ||
11 | * | ||
12 | * Copyright (C) 2010 Google, Inc. | ||
13 | * Iliyan Malchev <malchev@google.com> | ||
14 | * | ||
15 | * This program is free software; you can redistribute it and/or modify it | ||
16 | * under the terms and conditions of the GNU General Public License, | ||
17 | * version 2, as published by the Free Software Foundation. | ||
18 | * | ||
19 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
20 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
21 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
22 | * more details. | ||
23 | * | ||
24 | * You should have received a copy of the GNU General Public License | ||
25 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
26 | */ | ||
27 | |||
28 | #include <linux/clk.h> | ||
29 | #include <linux/device.h> | ||
30 | #include <linux/io.h> | ||
31 | #include <linux/module.h> | ||
32 | #include <linux/of.h> | ||
33 | #include <linux/platform_device.h> | ||
34 | #include <linux/pm_runtime.h> | ||
35 | #include <linux/regmap.h> | ||
36 | #include <linux/slab.h> | ||
37 | #include <sound/core.h> | ||
38 | #include <sound/pcm.h> | ||
39 | #include <sound/pcm_params.h> | ||
40 | #include <sound/soc.h> | ||
41 | |||
42 | #include "tegra30_ahub.h" | ||
43 | #include "tegra30_i2s.h" | ||
44 | |||
45 | #define DRV_NAME "tegra30-i2s" | ||
46 | |||
47 | static inline void tegra30_i2s_write(struct tegra30_i2s *i2s, u32 reg, u32 val) | ||
48 | { | ||
49 | regmap_write(i2s->regmap, reg, val); | ||
50 | } | ||
51 | |||
52 | static inline u32 tegra30_i2s_read(struct tegra30_i2s *i2s, u32 reg) | ||
53 | { | ||
54 | u32 val; | ||
55 | regmap_read(i2s->regmap, reg, &val); | ||
56 | return val; | ||
57 | } | ||
58 | |||
59 | static int tegra30_i2s_runtime_suspend(struct device *dev) | ||
60 | { | ||
61 | struct tegra30_i2s *i2s = dev_get_drvdata(dev); | ||
62 | |||
63 | regcache_cache_only(i2s->regmap, true); | ||
64 | |||
65 | clk_disable(i2s->clk_i2s); | ||
66 | |||
67 | return 0; | ||
68 | } | ||
69 | |||
70 | static int tegra30_i2s_runtime_resume(struct device *dev) | ||
71 | { | ||
72 | struct tegra30_i2s *i2s = dev_get_drvdata(dev); | ||
73 | int ret; | ||
74 | |||
75 | ret = clk_enable(i2s->clk_i2s); | ||
76 | if (ret) { | ||
77 | dev_err(dev, "clk_enable failed: %d\n", ret); | ||
78 | return ret; | ||
79 | } | ||
80 | |||
81 | regcache_cache_only(i2s->regmap, false); | ||
82 | |||
83 | return 0; | ||
84 | } | ||
85 | |||
86 | int tegra30_i2s_startup(struct snd_pcm_substream *substream, | ||
87 | struct snd_soc_dai *dai) | ||
88 | { | ||
89 | struct tegra30_i2s *i2s = snd_soc_dai_get_drvdata(dai); | ||
90 | int ret; | ||
91 | |||
92 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { | ||
93 | ret = tegra30_ahub_allocate_tx_fifo(&i2s->playback_fifo_cif, | ||
94 | &i2s->playback_dma_data.addr, | ||
95 | &i2s->playback_dma_data.req_sel); | ||
96 | i2s->playback_dma_data.wrap = 4; | ||
97 | i2s->playback_dma_data.width = 32; | ||
98 | tegra30_ahub_set_rx_cif_source(i2s->playback_i2s_cif, | ||
99 | i2s->playback_fifo_cif); | ||
100 | } else { | ||
101 | ret = tegra30_ahub_allocate_rx_fifo(&i2s->capture_fifo_cif, | ||
102 | &i2s->capture_dma_data.addr, | ||
103 | &i2s->capture_dma_data.req_sel); | ||
104 | i2s->capture_dma_data.wrap = 4; | ||
105 | i2s->capture_dma_data.width = 32; | ||
106 | tegra30_ahub_set_rx_cif_source(i2s->capture_fifo_cif, | ||
107 | i2s->capture_i2s_cif); | ||
108 | } | ||
109 | |||
110 | return ret; | ||
111 | } | ||
112 | |||
113 | void tegra30_i2s_shutdown(struct snd_pcm_substream *substream, | ||
114 | struct snd_soc_dai *dai) | ||
115 | { | ||
116 | struct tegra30_i2s *i2s = snd_soc_dai_get_drvdata(dai); | ||
117 | |||
118 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { | ||
119 | tegra30_ahub_unset_rx_cif_source(i2s->playback_i2s_cif); | ||
120 | tegra30_ahub_free_tx_fifo(i2s->playback_fifo_cif); | ||
121 | } else { | ||
122 | tegra30_ahub_unset_rx_cif_source(i2s->capture_fifo_cif); | ||
123 | tegra30_ahub_free_rx_fifo(i2s->capture_fifo_cif); | ||
124 | } | ||
125 | } | ||
126 | |||
127 | static int tegra30_i2s_set_fmt(struct snd_soc_dai *dai, | ||
128 | unsigned int fmt) | ||
129 | { | ||
130 | struct tegra30_i2s *i2s = snd_soc_dai_get_drvdata(dai); | ||
131 | |||
132 | switch (fmt & SND_SOC_DAIFMT_INV_MASK) { | ||
133 | case SND_SOC_DAIFMT_NB_NF: | ||
134 | break; | ||
135 | default: | ||
136 | return -EINVAL; | ||
137 | } | ||
138 | |||
139 | i2s->reg_ctrl &= ~TEGRA30_I2S_CTRL_MASTER_ENABLE; | ||
140 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { | ||
141 | case SND_SOC_DAIFMT_CBS_CFS: | ||
142 | i2s->reg_ctrl |= TEGRA30_I2S_CTRL_MASTER_ENABLE; | ||
143 | break; | ||
144 | case SND_SOC_DAIFMT_CBM_CFM: | ||
145 | break; | ||
146 | default: | ||
147 | return -EINVAL; | ||
148 | } | ||
149 | |||
150 | i2s->reg_ctrl &= ~(TEGRA30_I2S_CTRL_FRAME_FORMAT_MASK | | ||
151 | TEGRA30_I2S_CTRL_LRCK_MASK); | ||
152 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { | ||
153 | case SND_SOC_DAIFMT_DSP_A: | ||
154 | i2s->reg_ctrl |= TEGRA30_I2S_CTRL_FRAME_FORMAT_FSYNC; | ||
155 | i2s->reg_ctrl |= TEGRA30_I2S_CTRL_LRCK_L_LOW; | ||
156 | break; | ||
157 | case SND_SOC_DAIFMT_DSP_B: | ||
158 | i2s->reg_ctrl |= TEGRA30_I2S_CTRL_FRAME_FORMAT_FSYNC; | ||
159 | i2s->reg_ctrl |= TEGRA30_I2S_CTRL_LRCK_R_LOW; | ||
160 | break; | ||
161 | case SND_SOC_DAIFMT_I2S: | ||
162 | i2s->reg_ctrl |= TEGRA30_I2S_CTRL_FRAME_FORMAT_LRCK; | ||
163 | i2s->reg_ctrl |= TEGRA30_I2S_CTRL_LRCK_L_LOW; | ||
164 | break; | ||
165 | case SND_SOC_DAIFMT_RIGHT_J: | ||
166 | i2s->reg_ctrl |= TEGRA30_I2S_CTRL_FRAME_FORMAT_LRCK; | ||
167 | i2s->reg_ctrl |= TEGRA30_I2S_CTRL_LRCK_L_LOW; | ||
168 | break; | ||
169 | case SND_SOC_DAIFMT_LEFT_J: | ||
170 | i2s->reg_ctrl |= TEGRA30_I2S_CTRL_FRAME_FORMAT_LRCK; | ||
171 | i2s->reg_ctrl |= TEGRA30_I2S_CTRL_LRCK_L_LOW; | ||
172 | break; | ||
173 | default: | ||
174 | return -EINVAL; | ||
175 | } | ||
176 | |||
177 | return 0; | ||
178 | } | ||
179 | |||
180 | static int tegra30_i2s_hw_params(struct snd_pcm_substream *substream, | ||
181 | struct snd_pcm_hw_params *params, | ||
182 | struct snd_soc_dai *dai) | ||
183 | { | ||
184 | struct device *dev = substream->pcm->card->dev; | ||
185 | struct tegra30_i2s *i2s = snd_soc_dai_get_drvdata(dai); | ||
186 | u32 val; | ||
187 | int ret, sample_size, srate, i2sclock, bitcnt; | ||
188 | |||
189 | if (params_channels(params) != 2) | ||
190 | return -EINVAL; | ||
191 | |||
192 | i2s->reg_ctrl &= ~TEGRA30_I2S_CTRL_BIT_SIZE_MASK; | ||
193 | switch (params_format(params)) { | ||
194 | case SNDRV_PCM_FORMAT_S16_LE: | ||
195 | i2s->reg_ctrl |= TEGRA30_I2S_CTRL_BIT_SIZE_16; | ||
196 | sample_size = 16; | ||
197 | break; | ||
198 | default: | ||
199 | return -EINVAL; | ||
200 | } | ||
201 | |||
202 | srate = params_rate(params); | ||
203 | |||
204 | /* Final "* 2" required by Tegra hardware */ | ||
205 | i2sclock = srate * params_channels(params) * sample_size * 2; | ||
206 | |||
207 | bitcnt = (i2sclock / (2 * srate)) - 1; | ||
208 | if (bitcnt < 0 || bitcnt > TEGRA30_I2S_TIMING_CHANNEL_BIT_COUNT_MASK_US) | ||
209 | return -EINVAL; | ||
210 | |||
211 | ret = clk_set_rate(i2s->clk_i2s, i2sclock); | ||
212 | if (ret) { | ||
213 | dev_err(dev, "Can't set I2S clock rate: %d\n", ret); | ||
214 | return ret; | ||
215 | } | ||
216 | |||
217 | val = bitcnt << TEGRA30_I2S_TIMING_CHANNEL_BIT_COUNT_SHIFT; | ||
218 | |||
219 | if (i2sclock % (2 * srate)) | ||
220 | val |= TEGRA30_I2S_TIMING_NON_SYM_ENABLE; | ||
221 | |||
222 | tegra30_i2s_write(i2s, TEGRA30_I2S_TIMING, val); | ||
223 | |||
224 | val = (0 << TEGRA30_AUDIOCIF_CTRL_FIFO_THRESHOLD_SHIFT) | | ||
225 | (1 << TEGRA30_AUDIOCIF_CTRL_AUDIO_CHANNELS_SHIFT) | | ||
226 | (1 << TEGRA30_AUDIOCIF_CTRL_CLIENT_CHANNELS_SHIFT) | | ||
227 | TEGRA30_AUDIOCIF_CTRL_AUDIO_BITS_16 | | ||
228 | TEGRA30_AUDIOCIF_CTRL_CLIENT_BITS_16; | ||
229 | |||
230 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { | ||
231 | val |= TEGRA30_AUDIOCIF_CTRL_DIRECTION_RX; | ||
232 | tegra30_i2s_write(i2s, TEGRA30_I2S_CIF_RX_CTRL, val); | ||
233 | } else { | ||
234 | val |= TEGRA30_AUDIOCIF_CTRL_DIRECTION_TX; | ||
235 | tegra30_i2s_write(i2s, TEGRA30_I2S_CIF_TX_CTRL, val); | ||
236 | } | ||
237 | |||
238 | val = (1 << TEGRA30_I2S_OFFSET_RX_DATA_OFFSET_SHIFT) | | ||
239 | (1 << TEGRA30_I2S_OFFSET_TX_DATA_OFFSET_SHIFT); | ||
240 | tegra30_i2s_write(i2s, TEGRA30_I2S_OFFSET, val); | ||
241 | |||
242 | return 0; | ||
243 | } | ||
244 | |||
245 | static void tegra30_i2s_start_playback(struct tegra30_i2s *i2s) | ||
246 | { | ||
247 | tegra30_ahub_enable_tx_fifo(i2s->playback_fifo_cif); | ||
248 | i2s->reg_ctrl |= TEGRA30_I2S_CTRL_XFER_EN_TX; | ||
249 | tegra30_i2s_write(i2s, TEGRA30_I2S_CTRL, i2s->reg_ctrl); | ||
250 | } | ||
251 | |||
252 | static void tegra30_i2s_stop_playback(struct tegra30_i2s *i2s) | ||
253 | { | ||
254 | tegra30_ahub_disable_tx_fifo(i2s->playback_fifo_cif); | ||
255 | i2s->reg_ctrl &= ~TEGRA30_I2S_CTRL_XFER_EN_TX; | ||
256 | tegra30_i2s_write(i2s, TEGRA30_I2S_CTRL, i2s->reg_ctrl); | ||
257 | } | ||
258 | |||
259 | static void tegra30_i2s_start_capture(struct tegra30_i2s *i2s) | ||
260 | { | ||
261 | tegra30_ahub_enable_rx_fifo(i2s->capture_fifo_cif); | ||
262 | i2s->reg_ctrl |= TEGRA30_I2S_CTRL_XFER_EN_RX; | ||
263 | tegra30_i2s_write(i2s, TEGRA30_I2S_CTRL, i2s->reg_ctrl); | ||
264 | } | ||
265 | |||
266 | static void tegra30_i2s_stop_capture(struct tegra30_i2s *i2s) | ||
267 | { | ||
268 | tegra30_ahub_disable_rx_fifo(i2s->capture_fifo_cif); | ||
269 | i2s->reg_ctrl &= ~TEGRA30_I2S_CTRL_XFER_EN_RX; | ||
270 | tegra30_i2s_write(i2s, TEGRA30_I2S_CTRL, i2s->reg_ctrl); | ||
271 | } | ||
272 | |||
273 | static int tegra30_i2s_trigger(struct snd_pcm_substream *substream, int cmd, | ||
274 | struct snd_soc_dai *dai) | ||
275 | { | ||
276 | struct tegra30_i2s *i2s = snd_soc_dai_get_drvdata(dai); | ||
277 | |||
278 | switch (cmd) { | ||
279 | case SNDRV_PCM_TRIGGER_START: | ||
280 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: | ||
281 | case SNDRV_PCM_TRIGGER_RESUME: | ||
282 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) | ||
283 | tegra30_i2s_start_playback(i2s); | ||
284 | else | ||
285 | tegra30_i2s_start_capture(i2s); | ||
286 | break; | ||
287 | case SNDRV_PCM_TRIGGER_STOP: | ||
288 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: | ||
289 | case SNDRV_PCM_TRIGGER_SUSPEND: | ||
290 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) | ||
291 | tegra30_i2s_stop_playback(i2s); | ||
292 | else | ||
293 | tegra30_i2s_stop_capture(i2s); | ||
294 | break; | ||
295 | default: | ||
296 | return -EINVAL; | ||
297 | } | ||
298 | |||
299 | return 0; | ||
300 | } | ||
301 | |||
302 | static int tegra30_i2s_probe(struct snd_soc_dai *dai) | ||
303 | { | ||
304 | struct tegra30_i2s *i2s = snd_soc_dai_get_drvdata(dai); | ||
305 | |||
306 | dai->capture_dma_data = &i2s->capture_dma_data; | ||
307 | dai->playback_dma_data = &i2s->playback_dma_data; | ||
308 | |||
309 | return 0; | ||
310 | } | ||
311 | |||
312 | static struct snd_soc_dai_ops tegra30_i2s_dai_ops = { | ||
313 | .startup = tegra30_i2s_startup, | ||
314 | .shutdown = tegra30_i2s_shutdown, | ||
315 | .set_fmt = tegra30_i2s_set_fmt, | ||
316 | .hw_params = tegra30_i2s_hw_params, | ||
317 | .trigger = tegra30_i2s_trigger, | ||
318 | }; | ||
319 | |||
320 | static const struct snd_soc_dai_driver tegra30_i2s_dai_template = { | ||
321 | .probe = tegra30_i2s_probe, | ||
322 | .playback = { | ||
323 | .channels_min = 2, | ||
324 | .channels_max = 2, | ||
325 | .rates = SNDRV_PCM_RATE_8000_96000, | ||
326 | .formats = SNDRV_PCM_FMTBIT_S16_LE, | ||
327 | }, | ||
328 | .capture = { | ||
329 | .channels_min = 2, | ||
330 | .channels_max = 2, | ||
331 | .rates = SNDRV_PCM_RATE_8000_96000, | ||
332 | .formats = SNDRV_PCM_FMTBIT_S16_LE, | ||
333 | }, | ||
334 | .ops = &tegra30_i2s_dai_ops, | ||
335 | .symmetric_rates = 1, | ||
336 | }; | ||
337 | |||
338 | static bool tegra30_i2s_wr_rd_reg(struct device *dev, unsigned int reg) | ||
339 | { | ||
340 | switch (reg) { | ||
341 | case TEGRA30_I2S_CTRL: | ||
342 | case TEGRA30_I2S_TIMING: | ||
343 | case TEGRA30_I2S_OFFSET: | ||
344 | case TEGRA30_I2S_CH_CTRL: | ||
345 | case TEGRA30_I2S_SLOT_CTRL: | ||
346 | case TEGRA30_I2S_CIF_RX_CTRL: | ||
347 | case TEGRA30_I2S_CIF_TX_CTRL: | ||
348 | case TEGRA30_I2S_FLOWCTL: | ||
349 | case TEGRA30_I2S_TX_STEP: | ||
350 | case TEGRA30_I2S_FLOW_STATUS: | ||
351 | case TEGRA30_I2S_FLOW_TOTAL: | ||
352 | case TEGRA30_I2S_FLOW_OVER: | ||
353 | case TEGRA30_I2S_FLOW_UNDER: | ||
354 | case TEGRA30_I2S_LCOEF_1_4_0: | ||
355 | case TEGRA30_I2S_LCOEF_1_4_1: | ||
356 | case TEGRA30_I2S_LCOEF_1_4_2: | ||
357 | case TEGRA30_I2S_LCOEF_1_4_3: | ||
358 | case TEGRA30_I2S_LCOEF_1_4_4: | ||
359 | case TEGRA30_I2S_LCOEF_1_4_5: | ||
360 | case TEGRA30_I2S_LCOEF_2_4_0: | ||
361 | case TEGRA30_I2S_LCOEF_2_4_1: | ||
362 | case TEGRA30_I2S_LCOEF_2_4_2: | ||
363 | return true; | ||
364 | default: | ||
365 | return false; | ||
366 | }; | ||
367 | } | ||
368 | |||
369 | static bool tegra30_i2s_volatile_reg(struct device *dev, unsigned int reg) | ||
370 | { | ||
371 | switch (reg) { | ||
372 | case TEGRA30_I2S_FLOW_STATUS: | ||
373 | case TEGRA30_I2S_FLOW_TOTAL: | ||
374 | case TEGRA30_I2S_FLOW_OVER: | ||
375 | case TEGRA30_I2S_FLOW_UNDER: | ||
376 | return true; | ||
377 | default: | ||
378 | return false; | ||
379 | }; | ||
380 | } | ||
381 | |||
382 | static const struct regmap_config tegra30_i2s_regmap_config = { | ||
383 | .reg_bits = 32, | ||
384 | .reg_stride = 4, | ||
385 | .val_bits = 32, | ||
386 | .max_register = TEGRA30_I2S_LCOEF_2_4_2, | ||
387 | .writeable_reg = tegra30_i2s_wr_rd_reg, | ||
388 | .readable_reg = tegra30_i2s_wr_rd_reg, | ||
389 | .volatile_reg = tegra30_i2s_volatile_reg, | ||
390 | .cache_type = REGCACHE_RBTREE, | ||
391 | }; | ||
392 | |||
393 | static __devinit int tegra30_i2s_platform_probe(struct platform_device *pdev) | ||
394 | { | ||
395 | struct tegra30_i2s *i2s; | ||
396 | u32 cif_ids[2]; | ||
397 | struct resource *mem, *memregion; | ||
398 | void __iomem *regs; | ||
399 | int ret; | ||
400 | |||
401 | i2s = devm_kzalloc(&pdev->dev, sizeof(struct tegra30_i2s), GFP_KERNEL); | ||
402 | if (!i2s) { | ||
403 | dev_err(&pdev->dev, "Can't allocate tegra30_i2s\n"); | ||
404 | ret = -ENOMEM; | ||
405 | goto err; | ||
406 | } | ||
407 | dev_set_drvdata(&pdev->dev, i2s); | ||
408 | |||
409 | i2s->dai = tegra30_i2s_dai_template; | ||
410 | i2s->dai.name = dev_name(&pdev->dev); | ||
411 | |||
412 | ret = of_property_read_u32_array(pdev->dev.of_node, | ||
413 | "nvidia,ahub-cif-ids", cif_ids, | ||
414 | ARRAY_SIZE(cif_ids)); | ||
415 | if (ret < 0) | ||
416 | goto err; | ||
417 | |||
418 | i2s->playback_i2s_cif = cif_ids[0]; | ||
419 | i2s->capture_i2s_cif = cif_ids[1]; | ||
420 | |||
421 | i2s->clk_i2s = clk_get(&pdev->dev, NULL); | ||
422 | if (IS_ERR(i2s->clk_i2s)) { | ||
423 | dev_err(&pdev->dev, "Can't retrieve i2s clock\n"); | ||
424 | ret = PTR_ERR(i2s->clk_i2s); | ||
425 | goto err; | ||
426 | } | ||
427 | |||
428 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
429 | if (!mem) { | ||
430 | dev_err(&pdev->dev, "No memory resource\n"); | ||
431 | ret = -ENODEV; | ||
432 | goto err_clk_put; | ||
433 | } | ||
434 | |||
435 | memregion = devm_request_mem_region(&pdev->dev, mem->start, | ||
436 | resource_size(mem), DRV_NAME); | ||
437 | if (!memregion) { | ||
438 | dev_err(&pdev->dev, "Memory region already claimed\n"); | ||
439 | ret = -EBUSY; | ||
440 | goto err_clk_put; | ||
441 | } | ||
442 | |||
443 | regs = devm_ioremap(&pdev->dev, mem->start, resource_size(mem)); | ||
444 | if (!regs) { | ||
445 | dev_err(&pdev->dev, "ioremap failed\n"); | ||
446 | ret = -ENOMEM; | ||
447 | goto err_clk_put; | ||
448 | } | ||
449 | |||
450 | i2s->regmap = devm_regmap_init_mmio(&pdev->dev, regs, | ||
451 | &tegra30_i2s_regmap_config); | ||
452 | if (IS_ERR(i2s->regmap)) { | ||
453 | dev_err(&pdev->dev, "regmap init failed\n"); | ||
454 | ret = PTR_ERR(i2s->regmap); | ||
455 | goto err_clk_put; | ||
456 | } | ||
457 | regcache_cache_only(i2s->regmap, true); | ||
458 | |||
459 | pm_runtime_enable(&pdev->dev); | ||
460 | if (!pm_runtime_enabled(&pdev->dev)) { | ||
461 | ret = tegra30_i2s_runtime_resume(&pdev->dev); | ||
462 | if (ret) | ||
463 | goto err_pm_disable; | ||
464 | } | ||
465 | |||
466 | ret = snd_soc_register_dai(&pdev->dev, &i2s->dai); | ||
467 | if (ret) { | ||
468 | dev_err(&pdev->dev, "Could not register DAI: %d\n", ret); | ||
469 | ret = -ENOMEM; | ||
470 | goto err_suspend; | ||
471 | } | ||
472 | |||
473 | ret = tegra_pcm_platform_register(&pdev->dev); | ||
474 | if (ret) { | ||
475 | dev_err(&pdev->dev, "Could not register PCM: %d\n", ret); | ||
476 | goto err_unregister_dai; | ||
477 | } | ||
478 | |||
479 | return 0; | ||
480 | |||
481 | err_unregister_dai: | ||
482 | snd_soc_unregister_dai(&pdev->dev); | ||
483 | err_suspend: | ||
484 | if (!pm_runtime_status_suspended(&pdev->dev)) | ||
485 | tegra30_i2s_runtime_suspend(&pdev->dev); | ||
486 | err_pm_disable: | ||
487 | pm_runtime_disable(&pdev->dev); | ||
488 | err_clk_put: | ||
489 | clk_put(i2s->clk_i2s); | ||
490 | err: | ||
491 | return ret; | ||
492 | } | ||
493 | |||
494 | static int __devexit tegra30_i2s_platform_remove(struct platform_device *pdev) | ||
495 | { | ||
496 | struct tegra30_i2s *i2s = dev_get_drvdata(&pdev->dev); | ||
497 | |||
498 | pm_runtime_disable(&pdev->dev); | ||
499 | if (!pm_runtime_status_suspended(&pdev->dev)) | ||
500 | tegra30_i2s_runtime_suspend(&pdev->dev); | ||
501 | |||
502 | tegra_pcm_platform_unregister(&pdev->dev); | ||
503 | snd_soc_unregister_dai(&pdev->dev); | ||
504 | |||
505 | clk_put(i2s->clk_i2s); | ||
506 | |||
507 | return 0; | ||
508 | } | ||
509 | |||
510 | static const struct of_device_id tegra30_i2s_of_match[] __devinitconst = { | ||
511 | { .compatible = "nvidia,tegra30-i2s", }, | ||
512 | {}, | ||
513 | }; | ||
514 | |||
515 | static const struct dev_pm_ops tegra30_i2s_pm_ops __devinitconst = { | ||
516 | SET_RUNTIME_PM_OPS(tegra30_i2s_runtime_suspend, | ||
517 | tegra30_i2s_runtime_resume, NULL) | ||
518 | }; | ||
519 | |||
520 | static struct platform_driver tegra30_i2s_driver = { | ||
521 | .driver = { | ||
522 | .name = DRV_NAME, | ||
523 | .owner = THIS_MODULE, | ||
524 | .of_match_table = tegra30_i2s_of_match, | ||
525 | .pm = &tegra30_i2s_pm_ops, | ||
526 | }, | ||
527 | .probe = tegra30_i2s_platform_probe, | ||
528 | .remove = __devexit_p(tegra30_i2s_platform_remove), | ||
529 | }; | ||
530 | module_platform_driver(tegra30_i2s_driver); | ||
531 | |||
532 | MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>"); | ||
533 | MODULE_DESCRIPTION("Tegra30 I2S ASoC driver"); | ||
534 | MODULE_LICENSE("GPL"); | ||
535 | MODULE_ALIAS("platform:" DRV_NAME); | ||
536 | MODULE_DEVICE_TABLE(of, tegra30_i2s_of_match); | ||
diff --git a/sound/soc/tegra/tegra30_i2s.h b/sound/soc/tegra/tegra30_i2s.h new file mode 100644 index 000000000000..91adf29c7a87 --- /dev/null +++ b/sound/soc/tegra/tegra30_i2s.h | |||
@@ -0,0 +1,242 @@ | |||
1 | /* | ||
2 | * tegra30_i2s.h - Definitions for Tegra30 I2S driver | ||
3 | * | ||
4 | * Copyright (c) 2011,2012, NVIDIA CORPORATION. All rights reserved. | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify it | ||
7 | * under the terms and conditions of the GNU General Public License, | ||
8 | * version 2, as published by the Free Software Foundation. | ||
9 | * | ||
10 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
13 | * more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | */ | ||
18 | |||
19 | #ifndef __TEGRA30_I2S_H__ | ||
20 | #define __TEGRA30_I2S_H__ | ||
21 | |||
22 | #include "tegra_pcm.h" | ||
23 | |||
24 | /* Register offsets from TEGRA30_I2S*_BASE */ | ||
25 | |||
26 | #define TEGRA30_I2S_CTRL 0x0 | ||
27 | #define TEGRA30_I2S_TIMING 0x4 | ||
28 | #define TEGRA30_I2S_OFFSET 0x08 | ||
29 | #define TEGRA30_I2S_CH_CTRL 0x0c | ||
30 | #define TEGRA30_I2S_SLOT_CTRL 0x10 | ||
31 | #define TEGRA30_I2S_CIF_RX_CTRL 0x14 | ||
32 | #define TEGRA30_I2S_CIF_TX_CTRL 0x18 | ||
33 | #define TEGRA30_I2S_FLOWCTL 0x1c | ||
34 | #define TEGRA30_I2S_TX_STEP 0x20 | ||
35 | #define TEGRA30_I2S_FLOW_STATUS 0x24 | ||
36 | #define TEGRA30_I2S_FLOW_TOTAL 0x28 | ||
37 | #define TEGRA30_I2S_FLOW_OVER 0x2c | ||
38 | #define TEGRA30_I2S_FLOW_UNDER 0x30 | ||
39 | #define TEGRA30_I2S_LCOEF_1_4_0 0x34 | ||
40 | #define TEGRA30_I2S_LCOEF_1_4_1 0x38 | ||
41 | #define TEGRA30_I2S_LCOEF_1_4_2 0x3c | ||
42 | #define TEGRA30_I2S_LCOEF_1_4_3 0x40 | ||
43 | #define TEGRA30_I2S_LCOEF_1_4_4 0x44 | ||
44 | #define TEGRA30_I2S_LCOEF_1_4_5 0x48 | ||
45 | #define TEGRA30_I2S_LCOEF_2_4_0 0x4c | ||
46 | #define TEGRA30_I2S_LCOEF_2_4_1 0x50 | ||
47 | #define TEGRA30_I2S_LCOEF_2_4_2 0x54 | ||
48 | |||
49 | /* Fields in TEGRA30_I2S_CTRL */ | ||
50 | |||
51 | #define TEGRA30_I2S_CTRL_XFER_EN_TX (1 << 31) | ||
52 | #define TEGRA30_I2S_CTRL_XFER_EN_RX (1 << 30) | ||
53 | #define TEGRA30_I2S_CTRL_CG_EN (1 << 29) | ||
54 | #define TEGRA30_I2S_CTRL_SOFT_RESET (1 << 28) | ||
55 | #define TEGRA30_I2S_CTRL_TX_FLOWCTL_EN (1 << 27) | ||
56 | |||
57 | #define TEGRA30_I2S_CTRL_OBS_SEL_SHIFT 24 | ||
58 | #define TEGRA30_I2S_CTRL_OBS_SEL_MASK (7 << TEGRA30_I2S_CTRL_OBS_SEL_SHIFT) | ||
59 | |||
60 | #define TEGRA30_I2S_FRAME_FORMAT_LRCK 0 | ||
61 | #define TEGRA30_I2S_FRAME_FORMAT_FSYNC 1 | ||
62 | |||
63 | #define TEGRA30_I2S_CTRL_FRAME_FORMAT_SHIFT 12 | ||
64 | #define TEGRA30_I2S_CTRL_FRAME_FORMAT_MASK (7 << TEGRA30_I2S_CTRL_FRAME_FORMAT_SHIFT) | ||
65 | #define TEGRA30_I2S_CTRL_FRAME_FORMAT_LRCK (TEGRA30_I2S_FRAME_FORMAT_LRCK << TEGRA30_I2S_CTRL_FRAME_FORMAT_SHIFT) | ||
66 | #define TEGRA30_I2S_CTRL_FRAME_FORMAT_FSYNC (TEGRA30_I2S_FRAME_FORMAT_FSYNC << TEGRA30_I2S_CTRL_FRAME_FORMAT_SHIFT) | ||
67 | |||
68 | #define TEGRA30_I2S_CTRL_MASTER_ENABLE (1 << 10) | ||
69 | |||
70 | #define TEGRA30_I2S_LRCK_LEFT_LOW 0 | ||
71 | #define TEGRA30_I2S_LRCK_RIGHT_LOW 1 | ||
72 | |||
73 | #define TEGRA30_I2S_CTRL_LRCK_SHIFT 9 | ||
74 | #define TEGRA30_I2S_CTRL_LRCK_MASK (1 << TEGRA30_I2S_CTRL_LRCK_SHIFT) | ||
75 | #define TEGRA30_I2S_CTRL_LRCK_L_LOW (TEGRA30_I2S_LRCK_LEFT_LOW << TEGRA30_I2S_CTRL_LRCK_SHIFT) | ||
76 | #define TEGRA30_I2S_CTRL_LRCK_R_LOW (TEGRA30_I2S_LRCK_RIGHT_LOW << TEGRA30_I2S_CTRL_LRCK_SHIFT) | ||
77 | |||
78 | #define TEGRA30_I2S_CTRL_LPBK_ENABLE (1 << 8) | ||
79 | |||
80 | #define TEGRA30_I2S_BIT_CODE_LINEAR 0 | ||
81 | #define TEGRA30_I2S_BIT_CODE_ULAW 1 | ||
82 | #define TEGRA30_I2S_BIT_CODE_ALAW 2 | ||
83 | |||
84 | #define TEGRA30_I2S_CTRL_BIT_CODE_SHIFT 4 | ||
85 | #define TEGRA30_I2S_CTRL_BIT_CODE_MASK (3 << TEGRA30_I2S_CTRL_BIT_CODE_SHIFT) | ||
86 | #define TEGRA30_I2S_CTRL_BIT_CODE_LINEAR (TEGRA30_I2S_BIT_CODE_LINEAR << TEGRA30_I2S_CTRL_BIT_CODE_SHIFT) | ||
87 | #define TEGRA30_I2S_CTRL_BIT_CODE_ULAW (TEGRA30_I2S_BIT_CODE_ULAW << TEGRA30_I2S_CTRL_BIT_CODE_SHIFT) | ||
88 | #define TEGRA30_I2S_CTRL_BIT_CODE_ALAW (TEGRA30_I2S_BIT_CODE_ALAW << TEGRA30_I2S_CTRL_BIT_CODE_SHIFT) | ||
89 | |||
90 | #define TEGRA30_I2S_BITS_8 1 | ||
91 | #define TEGRA30_I2S_BITS_12 2 | ||
92 | #define TEGRA30_I2S_BITS_16 3 | ||
93 | #define TEGRA30_I2S_BITS_20 4 | ||
94 | #define TEGRA30_I2S_BITS_24 5 | ||
95 | #define TEGRA30_I2S_BITS_28 6 | ||
96 | #define TEGRA30_I2S_BITS_32 7 | ||
97 | |||
98 | /* Sample container size; see {RX,TX}_MASK field in CH_CTRL below */ | ||
99 | #define TEGRA30_I2S_CTRL_BIT_SIZE_SHIFT 0 | ||
100 | #define TEGRA30_I2S_CTRL_BIT_SIZE_MASK (7 << TEGRA30_I2S_CTRL_BIT_SIZE_SHIFT) | ||
101 | #define TEGRA30_I2S_CTRL_BIT_SIZE_8 (TEGRA30_I2S_BITS_8 << TEGRA30_I2S_CTRL_BIT_SIZE_SHIFT) | ||
102 | #define TEGRA30_I2S_CTRL_BIT_SIZE_12 (TEGRA30_I2S_BITS_12 << TEGRA30_I2S_CTRL_BIT_SIZE_SHIFT) | ||
103 | #define TEGRA30_I2S_CTRL_BIT_SIZE_16 (TEGRA30_I2S_BITS_16 << TEGRA30_I2S_CTRL_BIT_SIZE_SHIFT) | ||
104 | #define TEGRA30_I2S_CTRL_BIT_SIZE_20 (TEGRA30_I2S_BITS_20 << TEGRA30_I2S_CTRL_BIT_SIZE_SHIFT) | ||
105 | #define TEGRA30_I2S_CTRL_BIT_SIZE_24 (TEGRA30_I2S_BITS_24 << TEGRA30_I2S_CTRL_BIT_SIZE_SHIFT) | ||
106 | #define TEGRA30_I2S_CTRL_BIT_SIZE_28 (TEGRA30_I2S_BITS_28 << TEGRA30_I2S_CTRL_BIT_SIZE_SHIFT) | ||
107 | #define TEGRA30_I2S_CTRL_BIT_SIZE_32 (TEGRA30_I2S_BITS_32 << TEGRA30_I2S_CTRL_BIT_SIZE_SHIFT) | ||
108 | |||
109 | /* Fields in TEGRA30_I2S_TIMING */ | ||
110 | |||
111 | #define TEGRA30_I2S_TIMING_NON_SYM_ENABLE (1 << 12) | ||
112 | #define TEGRA30_I2S_TIMING_CHANNEL_BIT_COUNT_SHIFT 0 | ||
113 | #define TEGRA30_I2S_TIMING_CHANNEL_BIT_COUNT_MASK_US 0x7fff | ||
114 | #define TEGRA30_I2S_TIMING_CHANNEL_BIT_COUNT_MASK (TEGRA30_I2S_TIMING_CHANNEL_BIT_COUNT_MASK_US << TEGRA30_I2S_TIMING_CHANNEL_BIT_COUNT_SHIFT) | ||
115 | |||
116 | /* Fields in TEGRA30_I2S_OFFSET */ | ||
117 | |||
118 | #define TEGRA30_I2S_OFFSET_RX_DATA_OFFSET_SHIFT 16 | ||
119 | #define TEGRA30_I2S_OFFSET_RX_DATA_OFFSET_MASK_US 0x7ff | ||
120 | #define TEGRA30_I2S_OFFSET_RX_DATA_OFFSET_MASK (TEGRA30_I2S_OFFSET_RX_DATA_OFFSET_MASK_US << TEGRA30_I2S_OFFSET_RX_DATA_OFFSET_SHIFT) | ||
121 | #define TEGRA30_I2S_OFFSET_TX_DATA_OFFSET_SHIFT 0 | ||
122 | #define TEGRA30_I2S_OFFSET_TX_DATA_OFFSET_MASK_US 0x7ff | ||
123 | #define TEGRA30_I2S_OFFSET_TX_DATA_OFFSET_MASK (TEGRA30_I2S_OFFSET_TX_DATA_OFFSET_MASK_US << TEGRA30_I2S_OFFSET_TX_DATA_OFFSET_SHIFT) | ||
124 | |||
125 | /* Fields in TEGRA30_I2S_CH_CTRL */ | ||
126 | |||
127 | /* (FSYNC width - 1) in bit clocks */ | ||
128 | #define TEGRA30_I2S_CH_CTRL_FSYNC_WIDTH_SHIFT 24 | ||
129 | #define TEGRA30_I2S_CH_CTRL_FSYNC_WIDTH_MASK_US 0xff | ||
130 | #define TEGRA30_I2S_CH_CTRL_FSYNC_WIDTH_MASK (TEGRA30_I2S_CH_CTRL_FSYNC_WIDTH_MASK_US << TEGRA30_I2S_CH_CTRL_FSYNC_WIDTH_SHIFT) | ||
131 | |||
132 | #define TEGRA30_I2S_HIGHZ_NO 0 | ||
133 | #define TEGRA30_I2S_HIGHZ_YES 1 | ||
134 | #define TEGRA30_I2S_HIGHZ_ON_HALF_BIT_CLK 2 | ||
135 | |||
136 | #define TEGRA30_I2S_CH_CTRL_HIGHZ_CTRL_SHIFT 12 | ||
137 | #define TEGRA30_I2S_CH_CTRL_HIGHZ_CTRL_MASK (3 << TEGRA30_I2S_CH_CTRL_HIGHZ_CTRL_SHIFT) | ||
138 | #define TEGRA30_I2S_CH_CTRL_HIGHZ_CTRL_NO (TEGRA30_I2S_HIGHZ_NO << TEGRA30_I2S_CH_CTRL_HIGHZ_CTRL_SHIFT) | ||
139 | #define TEGRA30_I2S_CH_CTRL_HIGHZ_CTRL_YES (TEGRA30_I2S_HIGHZ_YES << TEGRA30_I2S_CH_CTRL_HIGHZ_CTRL_SHIFT) | ||
140 | #define TEGRA30_I2S_CH_CTRL_HIGHZ_CTRL_ON_HALF_BIT_CLK (TEGRA30_I2S_HIGHZ_ON_HALF_BIT_CLK << TEGRA30_I2S_CH_CTRL_HIGHZ_CTRL_SHIFT) | ||
141 | |||
142 | #define TEGRA30_I2S_MSB_FIRST 0 | ||
143 | #define TEGRA30_I2S_LSB_FIRST 1 | ||
144 | |||
145 | #define TEGRA30_I2S_CH_CTRL_RX_BIT_ORDER_SHIFT 10 | ||
146 | #define TEGRA30_I2S_CH_CTRL_RX_BIT_ORDER_MASK (1 << TEGRA30_I2S_CH_CTRL_RX_BIT_ORDER_SHIFT) | ||
147 | #define TEGRA30_I2S_CH_CTRL_RX_BIT_ORDER_MSB_FIRST (TEGRA30_I2S_MSB_FIRST << TEGRA30_I2S_CH_CTRL_RX_BIT_ORDER_SHIFT) | ||
148 | #define TEGRA30_I2S_CH_CTRL_RX_BIT_ORDER_LSB_FIRST (TEGRA30_I2S_LSB_FIRST << TEGRA30_I2S_CH_CTRL_RX_BIT_ORDER_SHIFT) | ||
149 | #define TEGRA30_I2S_CH_CTRL_TX_BIT_ORDER_SHIFT 9 | ||
150 | #define TEGRA30_I2S_CH_CTRL_TX_BIT_ORDER_MASK (1 << TEGRA30_I2S_CH_CTRL_TX_BIT_ORDER_SHIFT) | ||
151 | #define TEGRA30_I2S_CH_CTRL_TX_BIT_ORDER_MSB_FIRST (TEGRA30_I2S_MSB_FIRST << TEGRA30_I2S_CH_CTRL_TX_BIT_ORDER_SHIFT) | ||
152 | #define TEGRA30_I2S_CH_CTRL_TX_BIT_ORDER_LSB_FIRST (TEGRA30_I2S_LSB_FIRST << TEGRA30_I2S_CH_CTRL_TX_BIT_ORDER_SHIFT) | ||
153 | |||
154 | #define TEGRA30_I2S_POS_EDGE 0 | ||
155 | #define TEGRA30_I2S_NEG_EDGE 1 | ||
156 | |||
157 | #define TEGRA30_I2S_CH_CTRL_EGDE_CTRL_SHIFT 8 | ||
158 | #define TEGRA30_I2S_CH_CTRL_EGDE_CTRL_MASK (1 << TEGRA30_I2S_CH_CTRL_EGDE_CTRL_SHIFT) | ||
159 | #define TEGRA30_I2S_CH_CTRL_EGDE_CTRL_POS_EDGE (TEGRA30_I2S_POS_EDGE << TEGRA30_I2S_CH_CTRL_EGDE_CTRL_SHIFT) | ||
160 | #define TEGRA30_I2S_CH_CTRL_EGDE_CTRL_NEG_EDGE (TEGRA30_I2S_NEG_EDGE << TEGRA30_I2S_CH_CTRL_EGDE_CTRL_SHIFT) | ||
161 | |||
162 | /* Sample size is # bits from BIT_SIZE minus this field */ | ||
163 | #define TEGRA30_I2S_CH_CTRL_RX_MASK_BITS_SHIFT 4 | ||
164 | #define TEGRA30_I2S_CH_CTRL_RX_MASK_BITS_MASK_US 7 | ||
165 | #define TEGRA30_I2S_CH_CTRL_RX_MASK_BITS_MASK (TEGRA30_I2S_CH_CTRL_RX_MASK_BITS_MASK_US << TEGRA30_I2S_CH_CTRL_RX_MASK_BITS_SHIFT) | ||
166 | |||
167 | #define TEGRA30_I2S_CH_CTRL_TX_MASK_BITS_SHIFT 0 | ||
168 | #define TEGRA30_I2S_CH_CTRL_TX_MASK_BITS_MASK_US 7 | ||
169 | #define TEGRA30_I2S_CH_CTRL_TX_MASK_BITS_MASK (TEGRA30_I2S_CH_CTRL_TX_MASK_BITS_MASK_US << TEGRA30_I2S_CH_CTRL_TX_MASK_BITS_SHIFT) | ||
170 | |||
171 | /* Fields in TEGRA30_I2S_SLOT_CTRL */ | ||
172 | |||
173 | /* Number of slots in frame, minus 1 */ | ||
174 | #define TEGRA30_I2S_SLOT_CTRL_TOTAL_SLOTS_SHIFT 16 | ||
175 | #define TEGRA30_I2S_SLOT_CTRL_TOTAL_SLOTS_MASK_US 7 | ||
176 | #define TEGRA30_I2S_SLOT_CTRL_TOTAL_SLOTS_MASK (TEGRA30_I2S_SLOT_CTRL_TOTAL_SLOT_MASK_US << TEGRA30_I2S_SLOT_CTRL_TOTAL_SLOT_SHIFT) | ||
177 | |||
178 | /* TDM mode slot enable bitmask */ | ||
179 | #define TEGRA30_I2S_SLOT_CTRL_RX_SLOT_ENABLES_SHIFT 8 | ||
180 | #define TEGRA30_I2S_SLOT_CTRL_RX_SLOT_ENABLES_MASK (0xff << TEGRA30_I2S_SLOT_CTRL_RX_SLOT_ENABLES_SHIFT) | ||
181 | |||
182 | #define TEGRA30_I2S_SLOT_CTRL_TX_SLOT_ENABLES_SHIFT 0 | ||
183 | #define TEGRA30_I2S_SLOT_CTRL_TX_SLOT_ENABLES_MASK (0xff << TEGRA30_I2S_SLOT_CTRL_TX_SLOT_ENABLES_SHIFT) | ||
184 | |||
185 | /* Fields in TEGRA30_I2S_CIF_RX_CTRL */ | ||
186 | /* Uses field from TEGRA30_AUDIOCIF_CTRL_* in tegra30_ahub.h */ | ||
187 | |||
188 | /* Fields in TEGRA30_I2S_CIF_TX_CTRL */ | ||
189 | /* Uses field from TEGRA30_AUDIOCIF_CTRL_* in tegra30_ahub.h */ | ||
190 | |||
191 | /* Fields in TEGRA30_I2S_FLOWCTL */ | ||
192 | |||
193 | #define TEGRA30_I2S_FILTER_LINEAR 0 | ||
194 | #define TEGRA30_I2S_FILTER_QUAD 1 | ||
195 | |||
196 | #define TEGRA30_I2S_FLOWCTL_FILTER_SHIFT 31 | ||
197 | #define TEGRA30_I2S_FLOWCTL_FILTER_MASK (1 << TEGRA30_I2S_FLOWCTL_FILTER_SHIFT) | ||
198 | #define TEGRA30_I2S_FLOWCTL_FILTER_LINEAR (TEGRA30_I2S_FILTER_LINEAR << TEGRA30_I2S_FLOWCTL_FILTER_SHIFT) | ||
199 | #define TEGRA30_I2S_FLOWCTL_FILTER_QUAD (TEGRA30_I2S_FILTER_QUAD << TEGRA30_I2S_FLOWCTL_FILTER_SHIFT) | ||
200 | |||
201 | /* Fields in TEGRA30_I2S_TX_STEP */ | ||
202 | |||
203 | #define TEGRA30_I2S_TX_STEP_SHIFT 0 | ||
204 | #define TEGRA30_I2S_TX_STEP_MASK_US 0xffff | ||
205 | #define TEGRA30_I2S_TX_STEP_MASK (TEGRA30_I2S_TX_STEP_MASK_US << TEGRA30_I2S_TX_STEP_SHIFT) | ||
206 | |||
207 | /* Fields in TEGRA30_I2S_FLOW_STATUS */ | ||
208 | |||
209 | #define TEGRA30_I2S_FLOW_STATUS_UNDERFLOW (1 << 31) | ||
210 | #define TEGRA30_I2S_FLOW_STATUS_OVERFLOW (1 << 30) | ||
211 | #define TEGRA30_I2S_FLOW_STATUS_MONITOR_INT_EN (1 << 4) | ||
212 | #define TEGRA30_I2S_FLOW_STATUS_COUNTER_CLR (1 << 3) | ||
213 | #define TEGRA30_I2S_FLOW_STATUS_MONITOR_CLR (1 << 2) | ||
214 | #define TEGRA30_I2S_FLOW_STATUS_COUNTER_EN (1 << 1) | ||
215 | #define TEGRA30_I2S_FLOW_STATUS_MONITOR_EN (1 << 0) | ||
216 | |||
217 | /* | ||
218 | * There are no fields in TEGRA30_I2S_FLOW_TOTAL, TEGRA30_I2S_FLOW_OVER, | ||
219 | * TEGRA30_I2S_FLOW_UNDER; they are counters taking the whole register. | ||
220 | */ | ||
221 | |||
222 | /* Fields in TEGRA30_I2S_LCOEF_* */ | ||
223 | |||
224 | #define TEGRA30_I2S_LCOEF_COEF_SHIFT 0 | ||
225 | #define TEGRA30_I2S_LCOEF_COEF_MASK_US 0xffff | ||
226 | #define TEGRA30_I2S_LCOEF_COEF_MASK (TEGRA30_I2S_LCOEF_COEF_MASK_US << TEGRA30_I2S_LCOEF_COEF_SHIFT) | ||
227 | |||
228 | struct tegra30_i2s { | ||
229 | struct snd_soc_dai_driver dai; | ||
230 | int cif_id; | ||
231 | struct clk *clk_i2s; | ||
232 | enum tegra30_ahub_txcif capture_i2s_cif; | ||
233 | enum tegra30_ahub_rxcif capture_fifo_cif; | ||
234 | struct tegra_pcm_dma_params capture_dma_data; | ||
235 | enum tegra30_ahub_rxcif playback_i2s_cif; | ||
236 | enum tegra30_ahub_txcif playback_fifo_cif; | ||
237 | struct tegra_pcm_dma_params playback_dma_data; | ||
238 | struct regmap *regmap; | ||
239 | u32 reg_ctrl; | ||
240 | }; | ||
241 | |||
242 | #endif | ||
diff --git a/sound/soc/tegra/tegra_alc5632.c b/sound/soc/tegra/tegra_alc5632.c index e45ccd851f6a..32de7006daf0 100644 --- a/sound/soc/tegra/tegra_alc5632.c +++ b/sound/soc/tegra/tegra_alc5632.c | |||
@@ -1,16 +1,17 @@ | |||
1 | /* | 1 | /* |
2 | * tegra_alc5632.c -- Toshiba AC100(PAZ00) machine ASoC driver | 2 | * tegra_alc5632.c -- Toshiba AC100(PAZ00) machine ASoC driver |
3 | * | 3 | * |
4 | * Copyright (C) 2011 The AC100 Kernel Team <ac100@lists.lauchpad.net> | 4 | * Copyright (C) 2011 The AC100 Kernel Team <ac100@lists.lauchpad.net> |
5 | * | 5 | * Copyright (C) 2012 - NVIDIA, Inc. |
6 | * Authors: Leon Romanovsky <leon@leon.nu> | 6 | * |
7 | * Andrey Danin <danindrey@mail.ru> | 7 | * Authors: Leon Romanovsky <leon@leon.nu> |
8 | * Marc Dietrich <marvin24@gmx.de> | 8 | * Andrey Danin <danindrey@mail.ru> |
9 | * | 9 | * Marc Dietrich <marvin24@gmx.de> |
10 | * This program is free software; you can redistribute it and/or modify | 10 | * |
11 | * it under the terms of the GNU General Public License version 2 as | 11 | * This program is free software; you can redistribute it and/or modify |
12 | * published by the Free Software Foundation. | 12 | * it under the terms of the GNU General Public License version 2 as |
13 | */ | 13 | * published by the Free Software Foundation. |
14 | */ | ||
14 | 15 | ||
15 | #include <asm/mach-types.h> | 16 | #include <asm/mach-types.h> |
16 | 17 | ||
@@ -28,9 +29,6 @@ | |||
28 | 29 | ||
29 | #include "../codecs/alc5632.h" | 30 | #include "../codecs/alc5632.h" |
30 | 31 | ||
31 | #include "tegra_das.h" | ||
32 | #include "tegra_i2s.h" | ||
33 | #include "tegra_pcm.h" | ||
34 | #include "tegra_asoc_utils.h" | 32 | #include "tegra_asoc_utils.h" |
35 | 33 | ||
36 | #define DRV_NAME "tegra-alc5632" | 34 | #define DRV_NAME "tegra-alc5632" |
@@ -39,7 +37,6 @@ | |||
39 | 37 | ||
40 | struct tegra_alc5632 { | 38 | struct tegra_alc5632 { |
41 | struct tegra_asoc_utils_data util_data; | 39 | struct tegra_asoc_utils_data util_data; |
42 | struct platform_device *pcm_dev; | ||
43 | int gpio_requested; | 40 | int gpio_requested; |
44 | int gpio_hp_det; | 41 | int gpio_hp_det; |
45 | }; | 42 | }; |
@@ -140,7 +137,6 @@ static int tegra_alc5632_asoc_init(struct snd_soc_pcm_runtime *rtd) | |||
140 | static struct snd_soc_dai_link tegra_alc5632_dai = { | 137 | static struct snd_soc_dai_link tegra_alc5632_dai = { |
141 | .name = "ALC5632", | 138 | .name = "ALC5632", |
142 | .stream_name = "ALC5632 PCM", | 139 | .stream_name = "ALC5632 PCM", |
143 | .platform_name = "tegra-pcm-audio", | ||
144 | .codec_dai_name = "alc5632-hifi", | 140 | .codec_dai_name = "alc5632-hifi", |
145 | .init = tegra_alc5632_asoc_init, | 141 | .init = tegra_alc5632_asoc_init, |
146 | .ops = &tegra_alc5632_asoc_ops, | 142 | .ops = &tegra_alc5632_asoc_ops, |
@@ -179,8 +175,6 @@ static __devinit int tegra_alc5632_probe(struct platform_device *pdev) | |||
179 | platform_set_drvdata(pdev, card); | 175 | platform_set_drvdata(pdev, card); |
180 | snd_soc_card_set_drvdata(card, alc5632); | 176 | snd_soc_card_set_drvdata(card, alc5632); |
181 | 177 | ||
182 | alc5632->pcm_dev = ERR_PTR(-EINVAL); | ||
183 | |||
184 | if (!(pdev->dev.of_node)) { | 178 | if (!(pdev->dev.of_node)) { |
185 | dev_err(&pdev->dev, "Must be instantiated using device tree\n"); | 179 | dev_err(&pdev->dev, "Must be instantiated using device tree\n"); |
186 | ret = -EINVAL; | 180 | ret = -EINVAL; |
@@ -214,18 +208,11 @@ static __devinit int tegra_alc5632_probe(struct platform_device *pdev) | |||
214 | goto err; | 208 | goto err; |
215 | } | 209 | } |
216 | 210 | ||
217 | alc5632->pcm_dev = platform_device_register_simple( | 211 | tegra_alc5632_dai.platform_of_node = tegra_alc5632_dai.cpu_dai_of_node; |
218 | "tegra-pcm-audio", -1, NULL, 0); | ||
219 | if (IS_ERR(alc5632->pcm_dev)) { | ||
220 | dev_err(&pdev->dev, | ||
221 | "Can't instantiate tegra-pcm-audio\n"); | ||
222 | ret = PTR_ERR(alc5632->pcm_dev); | ||
223 | goto err; | ||
224 | } | ||
225 | 212 | ||
226 | ret = tegra_asoc_utils_init(&alc5632->util_data, &pdev->dev); | 213 | ret = tegra_asoc_utils_init(&alc5632->util_data, &pdev->dev); |
227 | if (ret) | 214 | if (ret) |
228 | goto err_unregister; | 215 | goto err; |
229 | 216 | ||
230 | ret = snd_soc_register_card(card); | 217 | ret = snd_soc_register_card(card); |
231 | if (ret) { | 218 | if (ret) { |
@@ -238,9 +225,6 @@ static __devinit int tegra_alc5632_probe(struct platform_device *pdev) | |||
238 | 225 | ||
239 | err_fini_utils: | 226 | err_fini_utils: |
240 | tegra_asoc_utils_fini(&alc5632->util_data); | 227 | tegra_asoc_utils_fini(&alc5632->util_data); |
241 | err_unregister: | ||
242 | if (!IS_ERR(alc5632->pcm_dev)) | ||
243 | platform_device_unregister(alc5632->pcm_dev); | ||
244 | err: | 228 | err: |
245 | return ret; | 229 | return ret; |
246 | } | 230 | } |
@@ -259,8 +243,6 @@ static int __devexit tegra_alc5632_remove(struct platform_device *pdev) | |||
259 | snd_soc_unregister_card(card); | 243 | snd_soc_unregister_card(card); |
260 | 244 | ||
261 | tegra_asoc_utils_fini(&machine->util_data); | 245 | tegra_asoc_utils_fini(&machine->util_data); |
262 | if (!IS_ERR(machine->pcm_dev)) | ||
263 | platform_device_unregister(machine->pcm_dev); | ||
264 | 246 | ||
265 | return 0; | 247 | return 0; |
266 | } | 248 | } |
diff --git a/sound/soc/tegra/tegra_asoc_utils.c b/sound/soc/tegra/tegra_asoc_utils.c index f8428e410e05..9515ce58ea02 100644 --- a/sound/soc/tegra/tegra_asoc_utils.c +++ b/sound/soc/tegra/tegra_asoc_utils.c | |||
@@ -2,7 +2,7 @@ | |||
2 | * tegra_asoc_utils.c - Harmony machine ASoC driver | 2 | * tegra_asoc_utils.c - Harmony machine ASoC driver |
3 | * | 3 | * |
4 | * Author: Stephen Warren <swarren@nvidia.com> | 4 | * Author: Stephen Warren <swarren@nvidia.com> |
5 | * Copyright (C) 2010 - NVIDIA, Inc. | 5 | * Copyright (C) 2010,2012 - NVIDIA, Inc. |
6 | * | 6 | * |
7 | * This program is free software; you can redistribute it and/or | 7 | * This program is free software; you can redistribute it and/or |
8 | * modify it under the terms of the GNU General Public License | 8 | * modify it under the terms of the GNU General Public License |
@@ -25,6 +25,7 @@ | |||
25 | #include <linux/err.h> | 25 | #include <linux/err.h> |
26 | #include <linux/kernel.h> | 26 | #include <linux/kernel.h> |
27 | #include <linux/module.h> | 27 | #include <linux/module.h> |
28 | #include <linux/of.h> | ||
28 | 29 | ||
29 | #include "tegra_asoc_utils.h" | 30 | #include "tegra_asoc_utils.h" |
30 | 31 | ||
@@ -40,7 +41,10 @@ int tegra_asoc_utils_set_rate(struct tegra_asoc_utils_data *data, int srate, | |||
40 | case 22050: | 41 | case 22050: |
41 | case 44100: | 42 | case 44100: |
42 | case 88200: | 43 | case 88200: |
43 | new_baseclock = 56448000; | 44 | if (data->soc == TEGRA_ASOC_UTILS_SOC_TEGRA20) |
45 | new_baseclock = 56448000; | ||
46 | else | ||
47 | new_baseclock = 564480000; | ||
44 | break; | 48 | break; |
45 | case 8000: | 49 | case 8000: |
46 | case 16000: | 50 | case 16000: |
@@ -48,7 +52,10 @@ int tegra_asoc_utils_set_rate(struct tegra_asoc_utils_data *data, int srate, | |||
48 | case 48000: | 52 | case 48000: |
49 | case 64000: | 53 | case 64000: |
50 | case 96000: | 54 | case 96000: |
51 | new_baseclock = 73728000; | 55 | if (data->soc == TEGRA_ASOC_UTILS_SOC_TEGRA20) |
56 | new_baseclock = 73728000; | ||
57 | else | ||
58 | new_baseclock = 552960000; | ||
52 | break; | 59 | break; |
53 | default: | 60 | default: |
54 | return -EINVAL; | 61 | return -EINVAL; |
@@ -78,7 +85,7 @@ int tegra_asoc_utils_set_rate(struct tegra_asoc_utils_data *data, int srate, | |||
78 | return err; | 85 | return err; |
79 | } | 86 | } |
80 | 87 | ||
81 | /* Don't set cdev1 rate; its locked to pll_a_out0 */ | 88 | /* Don't set cdev1/extern1 rate; it's locked to pll_a_out0 */ |
82 | 89 | ||
83 | err = clk_enable(data->clk_pll_a); | 90 | err = clk_enable(data->clk_pll_a); |
84 | if (err) { | 91 | if (err) { |
@@ -112,6 +119,17 @@ int tegra_asoc_utils_init(struct tegra_asoc_utils_data *data, | |||
112 | 119 | ||
113 | data->dev = dev; | 120 | data->dev = dev; |
114 | 121 | ||
122 | if (of_machine_is_compatible("nvidia,tegra20")) | ||
123 | data->soc = TEGRA_ASOC_UTILS_SOC_TEGRA20; | ||
124 | else if (of_machine_is_compatible("nvidia,tegra30")) | ||
125 | data->soc = TEGRA_ASOC_UTILS_SOC_TEGRA30; | ||
126 | else if (!dev->of_node) | ||
127 | /* non-DT is always Tegra20 */ | ||
128 | data->soc = TEGRA_ASOC_UTILS_SOC_TEGRA20; | ||
129 | else | ||
130 | /* DT boot, but unknown SoC */ | ||
131 | return -EINVAL; | ||
132 | |||
115 | data->clk_pll_a = clk_get_sys(NULL, "pll_a"); | 133 | data->clk_pll_a = clk_get_sys(NULL, "pll_a"); |
116 | if (IS_ERR(data->clk_pll_a)) { | 134 | if (IS_ERR(data->clk_pll_a)) { |
117 | dev_err(data->dev, "Can't retrieve clk pll_a\n"); | 135 | dev_err(data->dev, "Can't retrieve clk pll_a\n"); |
@@ -126,15 +144,24 @@ int tegra_asoc_utils_init(struct tegra_asoc_utils_data *data, | |||
126 | goto err_put_pll_a; | 144 | goto err_put_pll_a; |
127 | } | 145 | } |
128 | 146 | ||
129 | data->clk_cdev1 = clk_get_sys(NULL, "cdev1"); | 147 | if (data->soc == TEGRA_ASOC_UTILS_SOC_TEGRA20) |
148 | data->clk_cdev1 = clk_get_sys(NULL, "cdev1"); | ||
149 | else | ||
150 | data->clk_cdev1 = clk_get_sys("extern1", NULL); | ||
130 | if (IS_ERR(data->clk_cdev1)) { | 151 | if (IS_ERR(data->clk_cdev1)) { |
131 | dev_err(data->dev, "Can't retrieve clk cdev1\n"); | 152 | dev_err(data->dev, "Can't retrieve clk cdev1\n"); |
132 | ret = PTR_ERR(data->clk_cdev1); | 153 | ret = PTR_ERR(data->clk_cdev1); |
133 | goto err_put_pll_a_out0; | 154 | goto err_put_pll_a_out0; |
134 | } | 155 | } |
135 | 156 | ||
157 | ret = tegra_asoc_utils_set_rate(data, 44100, 256 * 44100); | ||
158 | if (ret) | ||
159 | goto err_put_cdev1; | ||
160 | |||
136 | return 0; | 161 | return 0; |
137 | 162 | ||
163 | err_put_cdev1: | ||
164 | clk_put(data->clk_cdev1); | ||
138 | err_put_pll_a_out0: | 165 | err_put_pll_a_out0: |
139 | clk_put(data->clk_pll_a_out0); | 166 | clk_put(data->clk_pll_a_out0); |
140 | err_put_pll_a: | 167 | err_put_pll_a: |
diff --git a/sound/soc/tegra/tegra_asoc_utils.h b/sound/soc/tegra/tegra_asoc_utils.h index 4818195da25c..44db1dbb8f21 100644 --- a/sound/soc/tegra/tegra_asoc_utils.h +++ b/sound/soc/tegra/tegra_asoc_utils.h | |||
@@ -2,7 +2,7 @@ | |||
2 | * tegra_asoc_utils.h - Definitions for Tegra DAS driver | 2 | * tegra_asoc_utils.h - Definitions for Tegra DAS driver |
3 | * | 3 | * |
4 | * Author: Stephen Warren <swarren@nvidia.com> | 4 | * Author: Stephen Warren <swarren@nvidia.com> |
5 | * Copyright (C) 2010 - NVIDIA, Inc. | 5 | * Copyright (C) 2010,2012 - NVIDIA, Inc. |
6 | * | 6 | * |
7 | * This program is free software; you can redistribute it and/or | 7 | * This program is free software; you can redistribute it and/or |
8 | * modify it under the terms of the GNU General Public License | 8 | * modify it under the terms of the GNU General Public License |
@@ -26,8 +26,14 @@ | |||
26 | struct clk; | 26 | struct clk; |
27 | struct device; | 27 | struct device; |
28 | 28 | ||
29 | enum tegra_asoc_utils_soc { | ||
30 | TEGRA_ASOC_UTILS_SOC_TEGRA20, | ||
31 | TEGRA_ASOC_UTILS_SOC_TEGRA30, | ||
32 | }; | ||
33 | |||
29 | struct tegra_asoc_utils_data { | 34 | struct tegra_asoc_utils_data { |
30 | struct device *dev; | 35 | struct device *dev; |
36 | enum tegra_asoc_utils_soc soc; | ||
31 | struct clk *clk_pll_a; | 37 | struct clk *clk_pll_a; |
32 | struct clk *clk_pll_a_out0; | 38 | struct clk *clk_pll_a_out0; |
33 | struct clk *clk_cdev1; | 39 | struct clk *clk_cdev1; |
@@ -42,4 +48,3 @@ int tegra_asoc_utils_init(struct tegra_asoc_utils_data *data, | |||
42 | void tegra_asoc_utils_fini(struct tegra_asoc_utils_data *data); | 48 | void tegra_asoc_utils_fini(struct tegra_asoc_utils_data *data); |
43 | 49 | ||
44 | #endif | 50 | #endif |
45 | |||
diff --git a/sound/soc/tegra/tegra_das.c b/sound/soc/tegra/tegra_das.c deleted file mode 100644 index 3b3c1ba4d235..000000000000 --- a/sound/soc/tegra/tegra_das.c +++ /dev/null | |||
@@ -1,261 +0,0 @@ | |||
1 | /* | ||
2 | * tegra_das.c - Tegra DAS driver | ||
3 | * | ||
4 | * Author: Stephen Warren <swarren@nvidia.com> | ||
5 | * Copyright (C) 2010 - NVIDIA, Inc. | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or | ||
8 | * modify it under the terms of the GNU General Public License | ||
9 | * version 2 as published by the Free Software Foundation. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, but | ||
12 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | * General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program; if not, write to the Free Software | ||
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
19 | * 02110-1301 USA | ||
20 | * | ||
21 | */ | ||
22 | |||
23 | #include <linux/module.h> | ||
24 | #include <linux/debugfs.h> | ||
25 | #include <linux/device.h> | ||
26 | #include <linux/platform_device.h> | ||
27 | #include <linux/seq_file.h> | ||
28 | #include <linux/slab.h> | ||
29 | #include <linux/io.h> | ||
30 | #include <mach/iomap.h> | ||
31 | #include <sound/soc.h> | ||
32 | #include "tegra_das.h" | ||
33 | |||
34 | #define DRV_NAME "tegra-das" | ||
35 | |||
36 | static struct tegra_das *das; | ||
37 | |||
38 | static inline void tegra_das_write(u32 reg, u32 val) | ||
39 | { | ||
40 | __raw_writel(val, das->regs + reg); | ||
41 | } | ||
42 | |||
43 | static inline u32 tegra_das_read(u32 reg) | ||
44 | { | ||
45 | return __raw_readl(das->regs + reg); | ||
46 | } | ||
47 | |||
48 | int tegra_das_connect_dap_to_dac(int dap, int dac) | ||
49 | { | ||
50 | u32 addr; | ||
51 | u32 reg; | ||
52 | |||
53 | if (!das) | ||
54 | return -ENODEV; | ||
55 | |||
56 | addr = TEGRA_DAS_DAP_CTRL_SEL + | ||
57 | (dap * TEGRA_DAS_DAP_CTRL_SEL_STRIDE); | ||
58 | reg = dac << TEGRA_DAS_DAP_CTRL_SEL_DAP_CTRL_SEL_P; | ||
59 | |||
60 | tegra_das_write(addr, reg); | ||
61 | |||
62 | return 0; | ||
63 | } | ||
64 | EXPORT_SYMBOL_GPL(tegra_das_connect_dap_to_dac); | ||
65 | |||
66 | int tegra_das_connect_dap_to_dap(int dap, int otherdap, int master, | ||
67 | int sdata1rx, int sdata2rx) | ||
68 | { | ||
69 | u32 addr; | ||
70 | u32 reg; | ||
71 | |||
72 | if (!das) | ||
73 | return -ENODEV; | ||
74 | |||
75 | addr = TEGRA_DAS_DAP_CTRL_SEL + | ||
76 | (dap * TEGRA_DAS_DAP_CTRL_SEL_STRIDE); | ||
77 | reg = otherdap << TEGRA_DAS_DAP_CTRL_SEL_DAP_CTRL_SEL_P | | ||
78 | !!sdata2rx << TEGRA_DAS_DAP_CTRL_SEL_DAP_SDATA2_TX_RX_P | | ||
79 | !!sdata1rx << TEGRA_DAS_DAP_CTRL_SEL_DAP_SDATA1_TX_RX_P | | ||
80 | !!master << TEGRA_DAS_DAP_CTRL_SEL_DAP_MS_SEL_P; | ||
81 | |||
82 | tegra_das_write(addr, reg); | ||
83 | |||
84 | return 0; | ||
85 | } | ||
86 | EXPORT_SYMBOL_GPL(tegra_das_connect_dap_to_dap); | ||
87 | |||
88 | int tegra_das_connect_dac_to_dap(int dac, int dap) | ||
89 | { | ||
90 | u32 addr; | ||
91 | u32 reg; | ||
92 | |||
93 | if (!das) | ||
94 | return -ENODEV; | ||
95 | |||
96 | addr = TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL + | ||
97 | (dac * TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL_STRIDE); | ||
98 | reg = dap << TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_CLK_SEL_P | | ||
99 | dap << TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_SDATA1_SEL_P | | ||
100 | dap << TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_SDATA2_SEL_P; | ||
101 | |||
102 | tegra_das_write(addr, reg); | ||
103 | |||
104 | return 0; | ||
105 | } | ||
106 | EXPORT_SYMBOL_GPL(tegra_das_connect_dac_to_dap); | ||
107 | |||
108 | #ifdef CONFIG_DEBUG_FS | ||
109 | static int tegra_das_show(struct seq_file *s, void *unused) | ||
110 | { | ||
111 | int i; | ||
112 | u32 addr; | ||
113 | u32 reg; | ||
114 | |||
115 | for (i = 0; i < TEGRA_DAS_DAP_CTRL_SEL_COUNT; i++) { | ||
116 | addr = TEGRA_DAS_DAP_CTRL_SEL + | ||
117 | (i * TEGRA_DAS_DAP_CTRL_SEL_STRIDE); | ||
118 | reg = tegra_das_read(addr); | ||
119 | seq_printf(s, "TEGRA_DAS_DAP_CTRL_SEL[%d] = %08x\n", i, reg); | ||
120 | } | ||
121 | |||
122 | for (i = 0; i < TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL_COUNT; i++) { | ||
123 | addr = TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL + | ||
124 | (i * TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL_STRIDE); | ||
125 | reg = tegra_das_read(addr); | ||
126 | seq_printf(s, "TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL[%d] = %08x\n", | ||
127 | i, reg); | ||
128 | } | ||
129 | |||
130 | return 0; | ||
131 | } | ||
132 | |||
133 | static int tegra_das_debug_open(struct inode *inode, struct file *file) | ||
134 | { | ||
135 | return single_open(file, tegra_das_show, inode->i_private); | ||
136 | } | ||
137 | |||
138 | static const struct file_operations tegra_das_debug_fops = { | ||
139 | .open = tegra_das_debug_open, | ||
140 | .read = seq_read, | ||
141 | .llseek = seq_lseek, | ||
142 | .release = single_release, | ||
143 | }; | ||
144 | |||
145 | static void tegra_das_debug_add(struct tegra_das *das) | ||
146 | { | ||
147 | das->debug = debugfs_create_file(DRV_NAME, S_IRUGO, | ||
148 | snd_soc_debugfs_root, das, | ||
149 | &tegra_das_debug_fops); | ||
150 | } | ||
151 | |||
152 | static void tegra_das_debug_remove(struct tegra_das *das) | ||
153 | { | ||
154 | if (das->debug) | ||
155 | debugfs_remove(das->debug); | ||
156 | } | ||
157 | #else | ||
158 | static inline void tegra_das_debug_add(struct tegra_das *das) | ||
159 | { | ||
160 | } | ||
161 | |||
162 | static inline void tegra_das_debug_remove(struct tegra_das *das) | ||
163 | { | ||
164 | } | ||
165 | #endif | ||
166 | |||
167 | static int __devinit tegra_das_probe(struct platform_device *pdev) | ||
168 | { | ||
169 | struct resource *res, *region; | ||
170 | int ret = 0; | ||
171 | |||
172 | if (das) | ||
173 | return -ENODEV; | ||
174 | |||
175 | das = devm_kzalloc(&pdev->dev, sizeof(struct tegra_das), GFP_KERNEL); | ||
176 | if (!das) { | ||
177 | dev_err(&pdev->dev, "Can't allocate tegra_das\n"); | ||
178 | ret = -ENOMEM; | ||
179 | goto err; | ||
180 | } | ||
181 | das->dev = &pdev->dev; | ||
182 | |||
183 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
184 | if (!res) { | ||
185 | dev_err(&pdev->dev, "No memory resource\n"); | ||
186 | ret = -ENODEV; | ||
187 | goto err; | ||
188 | } | ||
189 | |||
190 | region = devm_request_mem_region(&pdev->dev, res->start, | ||
191 | resource_size(res), pdev->name); | ||
192 | if (!region) { | ||
193 | dev_err(&pdev->dev, "Memory region already claimed\n"); | ||
194 | ret = -EBUSY; | ||
195 | goto err; | ||
196 | } | ||
197 | |||
198 | das->regs = devm_ioremap(&pdev->dev, res->start, resource_size(res)); | ||
199 | if (!das->regs) { | ||
200 | dev_err(&pdev->dev, "ioremap failed\n"); | ||
201 | ret = -ENOMEM; | ||
202 | goto err; | ||
203 | } | ||
204 | |||
205 | ret = tegra_das_connect_dap_to_dac(TEGRA_DAS_DAP_ID_1, | ||
206 | TEGRA_DAS_DAP_SEL_DAC1); | ||
207 | if (ret) { | ||
208 | dev_err(&pdev->dev, "Can't set up DAS DAP connection\n"); | ||
209 | goto err; | ||
210 | } | ||
211 | ret = tegra_das_connect_dac_to_dap(TEGRA_DAS_DAC_ID_1, | ||
212 | TEGRA_DAS_DAC_SEL_DAP1); | ||
213 | if (ret) { | ||
214 | dev_err(&pdev->dev, "Can't set up DAS DAC connection\n"); | ||
215 | goto err; | ||
216 | } | ||
217 | |||
218 | tegra_das_debug_add(das); | ||
219 | |||
220 | platform_set_drvdata(pdev, das); | ||
221 | |||
222 | return 0; | ||
223 | |||
224 | err: | ||
225 | das = NULL; | ||
226 | return ret; | ||
227 | } | ||
228 | |||
229 | static int __devexit tegra_das_remove(struct platform_device *pdev) | ||
230 | { | ||
231 | if (!das) | ||
232 | return -ENODEV; | ||
233 | |||
234 | tegra_das_debug_remove(das); | ||
235 | |||
236 | das = NULL; | ||
237 | |||
238 | return 0; | ||
239 | } | ||
240 | |||
241 | static const struct of_device_id tegra_das_of_match[] __devinitconst = { | ||
242 | { .compatible = "nvidia,tegra20-das", }, | ||
243 | {}, | ||
244 | }; | ||
245 | |||
246 | static struct platform_driver tegra_das_driver = { | ||
247 | .probe = tegra_das_probe, | ||
248 | .remove = __devexit_p(tegra_das_remove), | ||
249 | .driver = { | ||
250 | .name = DRV_NAME, | ||
251 | .owner = THIS_MODULE, | ||
252 | .of_match_table = tegra_das_of_match, | ||
253 | }, | ||
254 | }; | ||
255 | module_platform_driver(tegra_das_driver); | ||
256 | |||
257 | MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>"); | ||
258 | MODULE_DESCRIPTION("Tegra DAS driver"); | ||
259 | MODULE_LICENSE("GPL"); | ||
260 | MODULE_ALIAS("platform:" DRV_NAME); | ||
261 | MODULE_DEVICE_TABLE(of, tegra_das_of_match); | ||
diff --git a/sound/soc/tegra/tegra_das.h b/sound/soc/tegra/tegra_das.h deleted file mode 100644 index 2c96c7b3c459..000000000000 --- a/sound/soc/tegra/tegra_das.h +++ /dev/null | |||
@@ -1,135 +0,0 @@ | |||
1 | /* | ||
2 | * tegra_das.h - Definitions for Tegra DAS driver | ||
3 | * | ||
4 | * Author: Stephen Warren <swarren@nvidia.com> | ||
5 | * Copyright (C) 2010 - NVIDIA, Inc. | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or | ||
8 | * modify it under the terms of the GNU General Public License | ||
9 | * version 2 as published by the Free Software Foundation. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, but | ||
12 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | * General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program; if not, write to the Free Software | ||
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
19 | * 02110-1301 USA | ||
20 | * | ||
21 | */ | ||
22 | |||
23 | #ifndef __TEGRA_DAS_H__ | ||
24 | #define __TEGRA_DAS_H__ | ||
25 | |||
26 | /* Register TEGRA_DAS_DAP_CTRL_SEL */ | ||
27 | #define TEGRA_DAS_DAP_CTRL_SEL 0x00 | ||
28 | #define TEGRA_DAS_DAP_CTRL_SEL_COUNT 5 | ||
29 | #define TEGRA_DAS_DAP_CTRL_SEL_STRIDE 4 | ||
30 | #define TEGRA_DAS_DAP_CTRL_SEL_DAP_MS_SEL_P 31 | ||
31 | #define TEGRA_DAS_DAP_CTRL_SEL_DAP_MS_SEL_S 1 | ||
32 | #define TEGRA_DAS_DAP_CTRL_SEL_DAP_SDATA1_TX_RX_P 30 | ||
33 | #define TEGRA_DAS_DAP_CTRL_SEL_DAP_SDATA1_TX_RX_S 1 | ||
34 | #define TEGRA_DAS_DAP_CTRL_SEL_DAP_SDATA2_TX_RX_P 29 | ||
35 | #define TEGRA_DAS_DAP_CTRL_SEL_DAP_SDATA2_TX_RX_S 1 | ||
36 | #define TEGRA_DAS_DAP_CTRL_SEL_DAP_CTRL_SEL_P 0 | ||
37 | #define TEGRA_DAS_DAP_CTRL_SEL_DAP_CTRL_SEL_S 5 | ||
38 | |||
39 | /* Values for field TEGRA_DAS_DAP_CTRL_SEL_DAP_CTRL_SEL */ | ||
40 | #define TEGRA_DAS_DAP_SEL_DAC1 0 | ||
41 | #define TEGRA_DAS_DAP_SEL_DAC2 1 | ||
42 | #define TEGRA_DAS_DAP_SEL_DAC3 2 | ||
43 | #define TEGRA_DAS_DAP_SEL_DAP1 16 | ||
44 | #define TEGRA_DAS_DAP_SEL_DAP2 17 | ||
45 | #define TEGRA_DAS_DAP_SEL_DAP3 18 | ||
46 | #define TEGRA_DAS_DAP_SEL_DAP4 19 | ||
47 | #define TEGRA_DAS_DAP_SEL_DAP5 20 | ||
48 | |||
49 | /* Register TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL */ | ||
50 | #define TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL 0x40 | ||
51 | #define TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL_COUNT 3 | ||
52 | #define TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL_STRIDE 4 | ||
53 | #define TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_SDATA2_SEL_P 28 | ||
54 | #define TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_SDATA2_SEL_S 4 | ||
55 | #define TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_SDATA1_SEL_P 24 | ||
56 | #define TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_SDATA1_SEL_S 4 | ||
57 | #define TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_CLK_SEL_P 0 | ||
58 | #define TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_CLK_SEL_S 4 | ||
59 | |||
60 | /* | ||
61 | * Values for: | ||
62 | * TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_SDATA2_SEL | ||
63 | * TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_SDATA1_SEL | ||
64 | * TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_CLK_SEL | ||
65 | */ | ||
66 | #define TEGRA_DAS_DAC_SEL_DAP1 0 | ||
67 | #define TEGRA_DAS_DAC_SEL_DAP2 1 | ||
68 | #define TEGRA_DAS_DAC_SEL_DAP3 2 | ||
69 | #define TEGRA_DAS_DAC_SEL_DAP4 3 | ||
70 | #define TEGRA_DAS_DAC_SEL_DAP5 4 | ||
71 | |||
72 | /* | ||
73 | * Names/IDs of the DACs/DAPs. | ||
74 | */ | ||
75 | |||
76 | #define TEGRA_DAS_DAP_ID_1 0 | ||
77 | #define TEGRA_DAS_DAP_ID_2 1 | ||
78 | #define TEGRA_DAS_DAP_ID_3 2 | ||
79 | #define TEGRA_DAS_DAP_ID_4 3 | ||
80 | #define TEGRA_DAS_DAP_ID_5 4 | ||
81 | |||
82 | #define TEGRA_DAS_DAC_ID_1 0 | ||
83 | #define TEGRA_DAS_DAC_ID_2 1 | ||
84 | #define TEGRA_DAS_DAC_ID_3 2 | ||
85 | |||
86 | struct tegra_das { | ||
87 | struct device *dev; | ||
88 | void __iomem *regs; | ||
89 | struct dentry *debug; | ||
90 | }; | ||
91 | |||
92 | /* | ||
93 | * Terminology: | ||
94 | * DAS: Digital audio switch (HW module controlled by this driver) | ||
95 | * DAP: Digital audio port (port/pins on Tegra device) | ||
96 | * DAC: Digital audio controller (e.g. I2S or AC97 controller elsewhere) | ||
97 | * | ||
98 | * The Tegra DAS is a mux/cross-bar which can connect each DAP to a specific | ||
99 | * DAC, or another DAP. When DAPs are connected, one must be the master and | ||
100 | * one the slave. Each DAC allows selection of a specific DAP for input, to | ||
101 | * cater for the case where N DAPs are connected to 1 DAC for broadcast | ||
102 | * output. | ||
103 | * | ||
104 | * This driver is dumb; no attempt is made to ensure that a valid routing | ||
105 | * configuration is programmed. | ||
106 | */ | ||
107 | |||
108 | /* | ||
109 | * Connect a DAP to to a DAC | ||
110 | * dap_id: DAP to connect: TEGRA_DAS_DAP_ID_* | ||
111 | * dac_sel: DAC to connect to: TEGRA_DAS_DAP_SEL_DAC* | ||
112 | */ | ||
113 | extern int tegra_das_connect_dap_to_dac(int dap_id, int dac_sel); | ||
114 | |||
115 | /* | ||
116 | * Connect a DAP to to another DAP | ||
117 | * dap_id: DAP to connect: TEGRA_DAS_DAP_ID_* | ||
118 | * other_dap_sel: DAP to connect to: TEGRA_DAS_DAP_SEL_DAP* | ||
119 | * master: Is this DAP the master (1) or slave (0) | ||
120 | * sdata1rx: Is this DAP's SDATA1 pin RX (1) or TX (0) | ||
121 | * sdata2rx: Is this DAP's SDATA2 pin RX (1) or TX (0) | ||
122 | */ | ||
123 | extern int tegra_das_connect_dap_to_dap(int dap_id, int other_dap_sel, | ||
124 | int master, int sdata1rx, | ||
125 | int sdata2rx); | ||
126 | |||
127 | /* | ||
128 | * Connect a DAC's input to a DAP | ||
129 | * (DAC outputs are selected by the DAP) | ||
130 | * dac_id: DAC ID to connect: TEGRA_DAS_DAC_ID_* | ||
131 | * dap_sel: DAP to receive input from: TEGRA_DAS_DAC_SEL_DAP* | ||
132 | */ | ||
133 | extern int tegra_das_connect_dac_to_dap(int dac_id, int dap_sel); | ||
134 | |||
135 | #endif | ||
diff --git a/sound/soc/tegra/tegra_i2s.c b/sound/soc/tegra/tegra_i2s.c deleted file mode 100644 index e53349912b2e..000000000000 --- a/sound/soc/tegra/tegra_i2s.c +++ /dev/null | |||
@@ -1,459 +0,0 @@ | |||
1 | /* | ||
2 | * tegra_i2s.c - Tegra I2S driver | ||
3 | * | ||
4 | * Author: Stephen Warren <swarren@nvidia.com> | ||
5 | * Copyright (C) 2010 - NVIDIA, Inc. | ||
6 | * | ||
7 | * Based on code copyright/by: | ||
8 | * | ||
9 | * Copyright (c) 2009-2010, NVIDIA Corporation. | ||
10 | * Scott Peterson <speterson@nvidia.com> | ||
11 | * | ||
12 | * Copyright (C) 2010 Google, Inc. | ||
13 | * Iliyan Malchev <malchev@google.com> | ||
14 | * | ||
15 | * This program is free software; you can redistribute it and/or | ||
16 | * modify it under the terms of the GNU General Public License | ||
17 | * version 2 as published by the Free Software Foundation. | ||
18 | * | ||
19 | * This program is distributed in the hope that it will be useful, but | ||
20 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
22 | * General Public License for more details. | ||
23 | * | ||
24 | * You should have received a copy of the GNU General Public License | ||
25 | * along with this program; if not, write to the Free Software | ||
26 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
27 | * 02110-1301 USA | ||
28 | * | ||
29 | */ | ||
30 | |||
31 | #include <linux/clk.h> | ||
32 | #include <linux/module.h> | ||
33 | #include <linux/debugfs.h> | ||
34 | #include <linux/device.h> | ||
35 | #include <linux/platform_device.h> | ||
36 | #include <linux/seq_file.h> | ||
37 | #include <linux/slab.h> | ||
38 | #include <linux/io.h> | ||
39 | #include <linux/of.h> | ||
40 | #include <mach/iomap.h> | ||
41 | #include <sound/core.h> | ||
42 | #include <sound/pcm.h> | ||
43 | #include <sound/pcm_params.h> | ||
44 | #include <sound/soc.h> | ||
45 | |||
46 | #include "tegra_i2s.h" | ||
47 | |||
48 | #define DRV_NAME "tegra-i2s" | ||
49 | |||
50 | static inline void tegra_i2s_write(struct tegra_i2s *i2s, u32 reg, u32 val) | ||
51 | { | ||
52 | __raw_writel(val, i2s->regs + reg); | ||
53 | } | ||
54 | |||
55 | static inline u32 tegra_i2s_read(struct tegra_i2s *i2s, u32 reg) | ||
56 | { | ||
57 | return __raw_readl(i2s->regs + reg); | ||
58 | } | ||
59 | |||
60 | #ifdef CONFIG_DEBUG_FS | ||
61 | static int tegra_i2s_show(struct seq_file *s, void *unused) | ||
62 | { | ||
63 | #define REG(r) { r, #r } | ||
64 | static const struct { | ||
65 | int offset; | ||
66 | const char *name; | ||
67 | } regs[] = { | ||
68 | REG(TEGRA_I2S_CTRL), | ||
69 | REG(TEGRA_I2S_STATUS), | ||
70 | REG(TEGRA_I2S_TIMING), | ||
71 | REG(TEGRA_I2S_FIFO_SCR), | ||
72 | REG(TEGRA_I2S_PCM_CTRL), | ||
73 | REG(TEGRA_I2S_NW_CTRL), | ||
74 | REG(TEGRA_I2S_TDM_CTRL), | ||
75 | REG(TEGRA_I2S_TDM_TX_RX_CTRL), | ||
76 | }; | ||
77 | #undef REG | ||
78 | |||
79 | struct tegra_i2s *i2s = s->private; | ||
80 | int i; | ||
81 | |||
82 | clk_enable(i2s->clk_i2s); | ||
83 | |||
84 | for (i = 0; i < ARRAY_SIZE(regs); i++) { | ||
85 | u32 val = tegra_i2s_read(i2s, regs[i].offset); | ||
86 | seq_printf(s, "%s = %08x\n", regs[i].name, val); | ||
87 | } | ||
88 | |||
89 | clk_disable(i2s->clk_i2s); | ||
90 | |||
91 | return 0; | ||
92 | } | ||
93 | |||
94 | static int tegra_i2s_debug_open(struct inode *inode, struct file *file) | ||
95 | { | ||
96 | return single_open(file, tegra_i2s_show, inode->i_private); | ||
97 | } | ||
98 | |||
99 | static const struct file_operations tegra_i2s_debug_fops = { | ||
100 | .open = tegra_i2s_debug_open, | ||
101 | .read = seq_read, | ||
102 | .llseek = seq_lseek, | ||
103 | .release = single_release, | ||
104 | }; | ||
105 | |||
106 | static void tegra_i2s_debug_add(struct tegra_i2s *i2s) | ||
107 | { | ||
108 | i2s->debug = debugfs_create_file(i2s->dai.name, S_IRUGO, | ||
109 | snd_soc_debugfs_root, i2s, | ||
110 | &tegra_i2s_debug_fops); | ||
111 | } | ||
112 | |||
113 | static void tegra_i2s_debug_remove(struct tegra_i2s *i2s) | ||
114 | { | ||
115 | if (i2s->debug) | ||
116 | debugfs_remove(i2s->debug); | ||
117 | } | ||
118 | #else | ||
119 | static inline void tegra_i2s_debug_add(struct tegra_i2s *i2s) | ||
120 | { | ||
121 | } | ||
122 | |||
123 | static inline void tegra_i2s_debug_remove(struct tegra_i2s *i2s) | ||
124 | { | ||
125 | } | ||
126 | #endif | ||
127 | |||
128 | static int tegra_i2s_set_fmt(struct snd_soc_dai *dai, | ||
129 | unsigned int fmt) | ||
130 | { | ||
131 | struct tegra_i2s *i2s = snd_soc_dai_get_drvdata(dai); | ||
132 | |||
133 | switch (fmt & SND_SOC_DAIFMT_INV_MASK) { | ||
134 | case SND_SOC_DAIFMT_NB_NF: | ||
135 | break; | ||
136 | default: | ||
137 | return -EINVAL; | ||
138 | } | ||
139 | |||
140 | i2s->reg_ctrl &= ~TEGRA_I2S_CTRL_MASTER_ENABLE; | ||
141 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { | ||
142 | case SND_SOC_DAIFMT_CBS_CFS: | ||
143 | i2s->reg_ctrl |= TEGRA_I2S_CTRL_MASTER_ENABLE; | ||
144 | break; | ||
145 | case SND_SOC_DAIFMT_CBM_CFM: | ||
146 | break; | ||
147 | default: | ||
148 | return -EINVAL; | ||
149 | } | ||
150 | |||
151 | i2s->reg_ctrl &= ~(TEGRA_I2S_CTRL_BIT_FORMAT_MASK | | ||
152 | TEGRA_I2S_CTRL_LRCK_MASK); | ||
153 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { | ||
154 | case SND_SOC_DAIFMT_DSP_A: | ||
155 | i2s->reg_ctrl |= TEGRA_I2S_CTRL_BIT_FORMAT_DSP; | ||
156 | i2s->reg_ctrl |= TEGRA_I2S_CTRL_LRCK_L_LOW; | ||
157 | break; | ||
158 | case SND_SOC_DAIFMT_DSP_B: | ||
159 | i2s->reg_ctrl |= TEGRA_I2S_CTRL_BIT_FORMAT_DSP; | ||
160 | i2s->reg_ctrl |= TEGRA_I2S_CTRL_LRCK_R_LOW; | ||
161 | break; | ||
162 | case SND_SOC_DAIFMT_I2S: | ||
163 | i2s->reg_ctrl |= TEGRA_I2S_CTRL_BIT_FORMAT_I2S; | ||
164 | i2s->reg_ctrl |= TEGRA_I2S_CTRL_LRCK_L_LOW; | ||
165 | break; | ||
166 | case SND_SOC_DAIFMT_RIGHT_J: | ||
167 | i2s->reg_ctrl |= TEGRA_I2S_CTRL_BIT_FORMAT_RJM; | ||
168 | i2s->reg_ctrl |= TEGRA_I2S_CTRL_LRCK_L_LOW; | ||
169 | break; | ||
170 | case SND_SOC_DAIFMT_LEFT_J: | ||
171 | i2s->reg_ctrl |= TEGRA_I2S_CTRL_BIT_FORMAT_LJM; | ||
172 | i2s->reg_ctrl |= TEGRA_I2S_CTRL_LRCK_L_LOW; | ||
173 | break; | ||
174 | default: | ||
175 | return -EINVAL; | ||
176 | } | ||
177 | |||
178 | return 0; | ||
179 | } | ||
180 | |||
181 | static int tegra_i2s_hw_params(struct snd_pcm_substream *substream, | ||
182 | struct snd_pcm_hw_params *params, | ||
183 | struct snd_soc_dai *dai) | ||
184 | { | ||
185 | struct device *dev = substream->pcm->card->dev; | ||
186 | struct tegra_i2s *i2s = snd_soc_dai_get_drvdata(dai); | ||
187 | u32 reg; | ||
188 | int ret, sample_size, srate, i2sclock, bitcnt; | ||
189 | |||
190 | i2s->reg_ctrl &= ~TEGRA_I2S_CTRL_BIT_SIZE_MASK; | ||
191 | switch (params_format(params)) { | ||
192 | case SNDRV_PCM_FORMAT_S16_LE: | ||
193 | i2s->reg_ctrl |= TEGRA_I2S_CTRL_BIT_SIZE_16; | ||
194 | sample_size = 16; | ||
195 | break; | ||
196 | case SNDRV_PCM_FORMAT_S24_LE: | ||
197 | i2s->reg_ctrl |= TEGRA_I2S_CTRL_BIT_SIZE_24; | ||
198 | sample_size = 24; | ||
199 | break; | ||
200 | case SNDRV_PCM_FORMAT_S32_LE: | ||
201 | i2s->reg_ctrl |= TEGRA_I2S_CTRL_BIT_SIZE_32; | ||
202 | sample_size = 32; | ||
203 | break; | ||
204 | default: | ||
205 | return -EINVAL; | ||
206 | } | ||
207 | |||
208 | srate = params_rate(params); | ||
209 | |||
210 | /* Final "* 2" required by Tegra hardware */ | ||
211 | i2sclock = srate * params_channels(params) * sample_size * 2; | ||
212 | |||
213 | ret = clk_set_rate(i2s->clk_i2s, i2sclock); | ||
214 | if (ret) { | ||
215 | dev_err(dev, "Can't set I2S clock rate: %d\n", ret); | ||
216 | return ret; | ||
217 | } | ||
218 | |||
219 | bitcnt = (i2sclock / (2 * srate)) - 1; | ||
220 | if (bitcnt < 0 || bitcnt > TEGRA_I2S_TIMING_CHANNEL_BIT_COUNT_MASK_US) | ||
221 | return -EINVAL; | ||
222 | reg = bitcnt << TEGRA_I2S_TIMING_CHANNEL_BIT_COUNT_SHIFT; | ||
223 | |||
224 | if (i2sclock % (2 * srate)) | ||
225 | reg |= TEGRA_I2S_TIMING_NON_SYM_ENABLE; | ||
226 | |||
227 | if (!i2s->clk_refs) | ||
228 | clk_enable(i2s->clk_i2s); | ||
229 | |||
230 | tegra_i2s_write(i2s, TEGRA_I2S_TIMING, reg); | ||
231 | |||
232 | tegra_i2s_write(i2s, TEGRA_I2S_FIFO_SCR, | ||
233 | TEGRA_I2S_FIFO_SCR_FIFO2_ATN_LVL_FOUR_SLOTS | | ||
234 | TEGRA_I2S_FIFO_SCR_FIFO1_ATN_LVL_FOUR_SLOTS); | ||
235 | |||
236 | if (!i2s->clk_refs) | ||
237 | clk_disable(i2s->clk_i2s); | ||
238 | |||
239 | return 0; | ||
240 | } | ||
241 | |||
242 | static void tegra_i2s_start_playback(struct tegra_i2s *i2s) | ||
243 | { | ||
244 | i2s->reg_ctrl |= TEGRA_I2S_CTRL_FIFO1_ENABLE; | ||
245 | tegra_i2s_write(i2s, TEGRA_I2S_CTRL, i2s->reg_ctrl); | ||
246 | } | ||
247 | |||
248 | static void tegra_i2s_stop_playback(struct tegra_i2s *i2s) | ||
249 | { | ||
250 | i2s->reg_ctrl &= ~TEGRA_I2S_CTRL_FIFO1_ENABLE; | ||
251 | tegra_i2s_write(i2s, TEGRA_I2S_CTRL, i2s->reg_ctrl); | ||
252 | } | ||
253 | |||
254 | static void tegra_i2s_start_capture(struct tegra_i2s *i2s) | ||
255 | { | ||
256 | i2s->reg_ctrl |= TEGRA_I2S_CTRL_FIFO2_ENABLE; | ||
257 | tegra_i2s_write(i2s, TEGRA_I2S_CTRL, i2s->reg_ctrl); | ||
258 | } | ||
259 | |||
260 | static void tegra_i2s_stop_capture(struct tegra_i2s *i2s) | ||
261 | { | ||
262 | i2s->reg_ctrl &= ~TEGRA_I2S_CTRL_FIFO2_ENABLE; | ||
263 | tegra_i2s_write(i2s, TEGRA_I2S_CTRL, i2s->reg_ctrl); | ||
264 | } | ||
265 | |||
266 | static int tegra_i2s_trigger(struct snd_pcm_substream *substream, int cmd, | ||
267 | struct snd_soc_dai *dai) | ||
268 | { | ||
269 | struct tegra_i2s *i2s = snd_soc_dai_get_drvdata(dai); | ||
270 | |||
271 | switch (cmd) { | ||
272 | case SNDRV_PCM_TRIGGER_START: | ||
273 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: | ||
274 | case SNDRV_PCM_TRIGGER_RESUME: | ||
275 | if (!i2s->clk_refs) | ||
276 | clk_enable(i2s->clk_i2s); | ||
277 | i2s->clk_refs++; | ||
278 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) | ||
279 | tegra_i2s_start_playback(i2s); | ||
280 | else | ||
281 | tegra_i2s_start_capture(i2s); | ||
282 | break; | ||
283 | case SNDRV_PCM_TRIGGER_STOP: | ||
284 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: | ||
285 | case SNDRV_PCM_TRIGGER_SUSPEND: | ||
286 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) | ||
287 | tegra_i2s_stop_playback(i2s); | ||
288 | else | ||
289 | tegra_i2s_stop_capture(i2s); | ||
290 | i2s->clk_refs--; | ||
291 | if (!i2s->clk_refs) | ||
292 | clk_disable(i2s->clk_i2s); | ||
293 | break; | ||
294 | default: | ||
295 | return -EINVAL; | ||
296 | } | ||
297 | |||
298 | return 0; | ||
299 | } | ||
300 | |||
301 | static int tegra_i2s_probe(struct snd_soc_dai *dai) | ||
302 | { | ||
303 | struct tegra_i2s * i2s = snd_soc_dai_get_drvdata(dai); | ||
304 | |||
305 | dai->capture_dma_data = &i2s->capture_dma_data; | ||
306 | dai->playback_dma_data = &i2s->playback_dma_data; | ||
307 | |||
308 | return 0; | ||
309 | } | ||
310 | |||
311 | static const struct snd_soc_dai_ops tegra_i2s_dai_ops = { | ||
312 | .set_fmt = tegra_i2s_set_fmt, | ||
313 | .hw_params = tegra_i2s_hw_params, | ||
314 | .trigger = tegra_i2s_trigger, | ||
315 | }; | ||
316 | |||
317 | static const struct snd_soc_dai_driver tegra_i2s_dai_template = { | ||
318 | .probe = tegra_i2s_probe, | ||
319 | .playback = { | ||
320 | .channels_min = 2, | ||
321 | .channels_max = 2, | ||
322 | .rates = SNDRV_PCM_RATE_8000_96000, | ||
323 | .formats = SNDRV_PCM_FMTBIT_S16_LE, | ||
324 | }, | ||
325 | .capture = { | ||
326 | .channels_min = 2, | ||
327 | .channels_max = 2, | ||
328 | .rates = SNDRV_PCM_RATE_8000_96000, | ||
329 | .formats = SNDRV_PCM_FMTBIT_S16_LE, | ||
330 | }, | ||
331 | .ops = &tegra_i2s_dai_ops, | ||
332 | .symmetric_rates = 1, | ||
333 | }; | ||
334 | |||
335 | static __devinit int tegra_i2s_platform_probe(struct platform_device *pdev) | ||
336 | { | ||
337 | struct tegra_i2s * i2s; | ||
338 | struct resource *mem, *memregion, *dmareq; | ||
339 | u32 of_dma[2]; | ||
340 | u32 dma_ch; | ||
341 | int ret; | ||
342 | |||
343 | i2s = devm_kzalloc(&pdev->dev, sizeof(struct tegra_i2s), GFP_KERNEL); | ||
344 | if (!i2s) { | ||
345 | dev_err(&pdev->dev, "Can't allocate tegra_i2s\n"); | ||
346 | ret = -ENOMEM; | ||
347 | goto err; | ||
348 | } | ||
349 | dev_set_drvdata(&pdev->dev, i2s); | ||
350 | |||
351 | i2s->dai = tegra_i2s_dai_template; | ||
352 | i2s->dai.name = dev_name(&pdev->dev); | ||
353 | |||
354 | i2s->clk_i2s = clk_get(&pdev->dev, NULL); | ||
355 | if (IS_ERR(i2s->clk_i2s)) { | ||
356 | dev_err(&pdev->dev, "Can't retrieve i2s clock\n"); | ||
357 | ret = PTR_ERR(i2s->clk_i2s); | ||
358 | goto err; | ||
359 | } | ||
360 | |||
361 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
362 | if (!mem) { | ||
363 | dev_err(&pdev->dev, "No memory resource\n"); | ||
364 | ret = -ENODEV; | ||
365 | goto err_clk_put; | ||
366 | } | ||
367 | |||
368 | dmareq = platform_get_resource(pdev, IORESOURCE_DMA, 0); | ||
369 | if (!dmareq) { | ||
370 | if (of_property_read_u32_array(pdev->dev.of_node, | ||
371 | "nvidia,dma-request-selector", | ||
372 | of_dma, 2) < 0) { | ||
373 | dev_err(&pdev->dev, "No DMA resource\n"); | ||
374 | ret = -ENODEV; | ||
375 | goto err_clk_put; | ||
376 | } | ||
377 | dma_ch = of_dma[1]; | ||
378 | } else { | ||
379 | dma_ch = dmareq->start; | ||
380 | } | ||
381 | |||
382 | memregion = devm_request_mem_region(&pdev->dev, mem->start, | ||
383 | resource_size(mem), DRV_NAME); | ||
384 | if (!memregion) { | ||
385 | dev_err(&pdev->dev, "Memory region already claimed\n"); | ||
386 | ret = -EBUSY; | ||
387 | goto err_clk_put; | ||
388 | } | ||
389 | |||
390 | i2s->regs = devm_ioremap(&pdev->dev, mem->start, resource_size(mem)); | ||
391 | if (!i2s->regs) { | ||
392 | dev_err(&pdev->dev, "ioremap failed\n"); | ||
393 | ret = -ENOMEM; | ||
394 | goto err_clk_put; | ||
395 | } | ||
396 | |||
397 | i2s->capture_dma_data.addr = mem->start + TEGRA_I2S_FIFO2; | ||
398 | i2s->capture_dma_data.wrap = 4; | ||
399 | i2s->capture_dma_data.width = 32; | ||
400 | i2s->capture_dma_data.req_sel = dma_ch; | ||
401 | |||
402 | i2s->playback_dma_data.addr = mem->start + TEGRA_I2S_FIFO1; | ||
403 | i2s->playback_dma_data.wrap = 4; | ||
404 | i2s->playback_dma_data.width = 32; | ||
405 | i2s->playback_dma_data.req_sel = dma_ch; | ||
406 | |||
407 | i2s->reg_ctrl = TEGRA_I2S_CTRL_FIFO_FORMAT_PACKED; | ||
408 | |||
409 | ret = snd_soc_register_dai(&pdev->dev, &i2s->dai); | ||
410 | if (ret) { | ||
411 | dev_err(&pdev->dev, "Could not register DAI: %d\n", ret); | ||
412 | ret = -ENOMEM; | ||
413 | goto err_clk_put; | ||
414 | } | ||
415 | |||
416 | tegra_i2s_debug_add(i2s); | ||
417 | |||
418 | return 0; | ||
419 | |||
420 | err_clk_put: | ||
421 | clk_put(i2s->clk_i2s); | ||
422 | err: | ||
423 | return ret; | ||
424 | } | ||
425 | |||
426 | static int __devexit tegra_i2s_platform_remove(struct platform_device *pdev) | ||
427 | { | ||
428 | struct tegra_i2s *i2s = dev_get_drvdata(&pdev->dev); | ||
429 | |||
430 | snd_soc_unregister_dai(&pdev->dev); | ||
431 | |||
432 | tegra_i2s_debug_remove(i2s); | ||
433 | |||
434 | clk_put(i2s->clk_i2s); | ||
435 | |||
436 | return 0; | ||
437 | } | ||
438 | |||
439 | static const struct of_device_id tegra_i2s_of_match[] __devinitconst = { | ||
440 | { .compatible = "nvidia,tegra20-i2s", }, | ||
441 | {}, | ||
442 | }; | ||
443 | |||
444 | static struct platform_driver tegra_i2s_driver = { | ||
445 | .driver = { | ||
446 | .name = DRV_NAME, | ||
447 | .owner = THIS_MODULE, | ||
448 | .of_match_table = tegra_i2s_of_match, | ||
449 | }, | ||
450 | .probe = tegra_i2s_platform_probe, | ||
451 | .remove = __devexit_p(tegra_i2s_platform_remove), | ||
452 | }; | ||
453 | module_platform_driver(tegra_i2s_driver); | ||
454 | |||
455 | MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>"); | ||
456 | MODULE_DESCRIPTION("Tegra I2S ASoC driver"); | ||
457 | MODULE_LICENSE("GPL"); | ||
458 | MODULE_ALIAS("platform:" DRV_NAME); | ||
459 | MODULE_DEVICE_TABLE(of, tegra_i2s_of_match); | ||
diff --git a/sound/soc/tegra/tegra_i2s.h b/sound/soc/tegra/tegra_i2s.h deleted file mode 100644 index 15ce1e2e8bde..000000000000 --- a/sound/soc/tegra/tegra_i2s.h +++ /dev/null | |||
@@ -1,166 +0,0 @@ | |||
1 | /* | ||
2 | * tegra_i2s.h - Definitions for Tegra I2S driver | ||
3 | * | ||
4 | * Author: Stephen Warren <swarren@nvidia.com> | ||
5 | * Copyright (C) 2010 - NVIDIA, Inc. | ||
6 | * | ||
7 | * Based on code copyright/by: | ||
8 | * | ||
9 | * Copyright (c) 2009-2010, NVIDIA Corporation. | ||
10 | * Scott Peterson <speterson@nvidia.com> | ||
11 | * | ||
12 | * Copyright (C) 2010 Google, Inc. | ||
13 | * Iliyan Malchev <malchev@google.com> | ||
14 | * | ||
15 | * This program is free software; you can redistribute it and/or | ||
16 | * modify it under the terms of the GNU General Public License | ||
17 | * version 2 as published by the Free Software Foundation. | ||
18 | * | ||
19 | * This program is distributed in the hope that it will be useful, but | ||
20 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
22 | * General Public License for more details. | ||
23 | * | ||
24 | * You should have received a copy of the GNU General Public License | ||
25 | * along with this program; if not, write to the Free Software | ||
26 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
27 | * 02110-1301 USA | ||
28 | * | ||
29 | */ | ||
30 | |||
31 | #ifndef __TEGRA_I2S_H__ | ||
32 | #define __TEGRA_I2S_H__ | ||
33 | |||
34 | #include "tegra_pcm.h" | ||
35 | |||
36 | /* Register offsets from TEGRA_I2S1_BASE and TEGRA_I2S2_BASE */ | ||
37 | |||
38 | #define TEGRA_I2S_CTRL 0x00 | ||
39 | #define TEGRA_I2S_STATUS 0x04 | ||
40 | #define TEGRA_I2S_TIMING 0x08 | ||
41 | #define TEGRA_I2S_FIFO_SCR 0x0c | ||
42 | #define TEGRA_I2S_PCM_CTRL 0x10 | ||
43 | #define TEGRA_I2S_NW_CTRL 0x14 | ||
44 | #define TEGRA_I2S_TDM_CTRL 0x20 | ||
45 | #define TEGRA_I2S_TDM_TX_RX_CTRL 0x24 | ||
46 | #define TEGRA_I2S_FIFO1 0x40 | ||
47 | #define TEGRA_I2S_FIFO2 0x80 | ||
48 | |||
49 | /* Fields in TEGRA_I2S_CTRL */ | ||
50 | |||
51 | #define TEGRA_I2S_CTRL_FIFO2_TX_ENABLE (1 << 30) | ||
52 | #define TEGRA_I2S_CTRL_FIFO1_ENABLE (1 << 29) | ||
53 | #define TEGRA_I2S_CTRL_FIFO2_ENABLE (1 << 28) | ||
54 | #define TEGRA_I2S_CTRL_FIFO1_RX_ENABLE (1 << 27) | ||
55 | #define TEGRA_I2S_CTRL_FIFO_LPBK_ENABLE (1 << 26) | ||
56 | #define TEGRA_I2S_CTRL_MASTER_ENABLE (1 << 25) | ||
57 | |||
58 | #define TEGRA_I2S_LRCK_LEFT_LOW 0 | ||
59 | #define TEGRA_I2S_LRCK_RIGHT_LOW 1 | ||
60 | |||
61 | #define TEGRA_I2S_CTRL_LRCK_SHIFT 24 | ||
62 | #define TEGRA_I2S_CTRL_LRCK_MASK (1 << TEGRA_I2S_CTRL_LRCK_SHIFT) | ||
63 | #define TEGRA_I2S_CTRL_LRCK_L_LOW (TEGRA_I2S_LRCK_LEFT_LOW << TEGRA_I2S_CTRL_LRCK_SHIFT) | ||
64 | #define TEGRA_I2S_CTRL_LRCK_R_LOW (TEGRA_I2S_LRCK_RIGHT_LOW << TEGRA_I2S_CTRL_LRCK_SHIFT) | ||
65 | |||
66 | #define TEGRA_I2S_BIT_FORMAT_I2S 0 | ||
67 | #define TEGRA_I2S_BIT_FORMAT_RJM 1 | ||
68 | #define TEGRA_I2S_BIT_FORMAT_LJM 2 | ||
69 | #define TEGRA_I2S_BIT_FORMAT_DSP 3 | ||
70 | |||
71 | #define TEGRA_I2S_CTRL_BIT_FORMAT_SHIFT 10 | ||
72 | #define TEGRA_I2S_CTRL_BIT_FORMAT_MASK (3 << TEGRA_I2S_CTRL_BIT_FORMAT_SHIFT) | ||
73 | #define TEGRA_I2S_CTRL_BIT_FORMAT_I2S (TEGRA_I2S_BIT_FORMAT_I2S << TEGRA_I2S_CTRL_BIT_FORMAT_SHIFT) | ||
74 | #define TEGRA_I2S_CTRL_BIT_FORMAT_RJM (TEGRA_I2S_BIT_FORMAT_RJM << TEGRA_I2S_CTRL_BIT_FORMAT_SHIFT) | ||
75 | #define TEGRA_I2S_CTRL_BIT_FORMAT_LJM (TEGRA_I2S_BIT_FORMAT_LJM << TEGRA_I2S_CTRL_BIT_FORMAT_SHIFT) | ||
76 | #define TEGRA_I2S_CTRL_BIT_FORMAT_DSP (TEGRA_I2S_BIT_FORMAT_DSP << TEGRA_I2S_CTRL_BIT_FORMAT_SHIFT) | ||
77 | |||
78 | #define TEGRA_I2S_BIT_SIZE_16 0 | ||
79 | #define TEGRA_I2S_BIT_SIZE_20 1 | ||
80 | #define TEGRA_I2S_BIT_SIZE_24 2 | ||
81 | #define TEGRA_I2S_BIT_SIZE_32 3 | ||
82 | |||
83 | #define TEGRA_I2S_CTRL_BIT_SIZE_SHIFT 8 | ||
84 | #define TEGRA_I2S_CTRL_BIT_SIZE_MASK (3 << TEGRA_I2S_CTRL_BIT_SIZE_SHIFT) | ||
85 | #define TEGRA_I2S_CTRL_BIT_SIZE_16 (TEGRA_I2S_BIT_SIZE_16 << TEGRA_I2S_CTRL_BIT_SIZE_SHIFT) | ||
86 | #define TEGRA_I2S_CTRL_BIT_SIZE_20 (TEGRA_I2S_BIT_SIZE_20 << TEGRA_I2S_CTRL_BIT_SIZE_SHIFT) | ||
87 | #define TEGRA_I2S_CTRL_BIT_SIZE_24 (TEGRA_I2S_BIT_SIZE_24 << TEGRA_I2S_CTRL_BIT_SIZE_SHIFT) | ||
88 | #define TEGRA_I2S_CTRL_BIT_SIZE_32 (TEGRA_I2S_BIT_SIZE_32 << TEGRA_I2S_CTRL_BIT_SIZE_SHIFT) | ||
89 | |||
90 | #define TEGRA_I2S_FIFO_16_LSB 0 | ||
91 | #define TEGRA_I2S_FIFO_20_LSB 1 | ||
92 | #define TEGRA_I2S_FIFO_24_LSB 2 | ||
93 | #define TEGRA_I2S_FIFO_32 3 | ||
94 | #define TEGRA_I2S_FIFO_PACKED 7 | ||
95 | |||
96 | #define TEGRA_I2S_CTRL_FIFO_FORMAT_SHIFT 4 | ||
97 | #define TEGRA_I2S_CTRL_FIFO_FORMAT_MASK (7 << TEGRA_I2S_CTRL_FIFO_FORMAT_SHIFT) | ||
98 | #define TEGRA_I2S_CTRL_FIFO_FORMAT_16_LSB (TEGRA_I2S_FIFO_16_LSB << TEGRA_I2S_CTRL_FIFO_FORMAT_SHIFT) | ||
99 | #define TEGRA_I2S_CTRL_FIFO_FORMAT_20_LSB (TEGRA_I2S_FIFO_20_LSB << TEGRA_I2S_CTRL_FIFO_FORMAT_SHIFT) | ||
100 | #define TEGRA_I2S_CTRL_FIFO_FORMAT_24_LSB (TEGRA_I2S_FIFO_24_LSB << TEGRA_I2S_CTRL_FIFO_FORMAT_SHIFT) | ||
101 | #define TEGRA_I2S_CTRL_FIFO_FORMAT_32 (TEGRA_I2S_FIFO_32 << TEGRA_I2S_CTRL_FIFO_FORMAT_SHIFT) | ||
102 | #define TEGRA_I2S_CTRL_FIFO_FORMAT_PACKED (TEGRA_I2S_FIFO_PACKED << TEGRA_I2S_CTRL_FIFO_FORMAT_SHIFT) | ||
103 | |||
104 | #define TEGRA_I2S_CTRL_IE_FIFO1_ERR (1 << 3) | ||
105 | #define TEGRA_I2S_CTRL_IE_FIFO2_ERR (1 << 2) | ||
106 | #define TEGRA_I2S_CTRL_QE_FIFO1 (1 << 1) | ||
107 | #define TEGRA_I2S_CTRL_QE_FIFO2 (1 << 0) | ||
108 | |||
109 | /* Fields in TEGRA_I2S_STATUS */ | ||
110 | |||
111 | #define TEGRA_I2S_STATUS_FIFO1_RDY (1 << 31) | ||
112 | #define TEGRA_I2S_STATUS_FIFO2_RDY (1 << 30) | ||
113 | #define TEGRA_I2S_STATUS_FIFO1_BSY (1 << 29) | ||
114 | #define TEGRA_I2S_STATUS_FIFO2_BSY (1 << 28) | ||
115 | #define TEGRA_I2S_STATUS_FIFO1_ERR (1 << 3) | ||
116 | #define TEGRA_I2S_STATUS_FIFO2_ERR (1 << 2) | ||
117 | #define TEGRA_I2S_STATUS_QS_FIFO1 (1 << 1) | ||
118 | #define TEGRA_I2S_STATUS_QS_FIFO2 (1 << 0) | ||
119 | |||
120 | /* Fields in TEGRA_I2S_TIMING */ | ||
121 | |||
122 | #define TEGRA_I2S_TIMING_NON_SYM_ENABLE (1 << 12) | ||
123 | #define TEGRA_I2S_TIMING_CHANNEL_BIT_COUNT_SHIFT 0 | ||
124 | #define TEGRA_I2S_TIMING_CHANNEL_BIT_COUNT_MASK_US 0x7fff | ||
125 | #define TEGRA_I2S_TIMING_CHANNEL_BIT_COUNT_MASK (TEGRA_I2S_TIMING_CHANNEL_BIT_COUNT_MASK_US << TEGRA_I2S_TIMING_CHANNEL_BIT_COUNT_SHIFT) | ||
126 | |||
127 | /* Fields in TEGRA_I2S_FIFO_SCR */ | ||
128 | |||
129 | #define TEGRA_I2S_FIFO_SCR_FIFO2_FULL_EMPTY_COUNT_SHIFT 24 | ||
130 | #define TEGRA_I2S_FIFO_SCR_FIFO1_FULL_EMPTY_COUNT_SHIFT 16 | ||
131 | #define TEGRA_I2S_FIFO_SCR_FIFO_FULL_EMPTY_COUNT_MASK 0x3f | ||
132 | |||
133 | #define TEGRA_I2S_FIFO_SCR_FIFO2_CLR (1 << 12) | ||
134 | #define TEGRA_I2S_FIFO_SCR_FIFO1_CLR (1 << 8) | ||
135 | |||
136 | #define TEGRA_I2S_FIFO_ATN_LVL_ONE_SLOT 0 | ||
137 | #define TEGRA_I2S_FIFO_ATN_LVL_FOUR_SLOTS 1 | ||
138 | #define TEGRA_I2S_FIFO_ATN_LVL_EIGHT_SLOTS 2 | ||
139 | #define TEGRA_I2S_FIFO_ATN_LVL_TWELVE_SLOTS 3 | ||
140 | |||
141 | #define TEGRA_I2S_FIFO_SCR_FIFO2_ATN_LVL_SHIFT 4 | ||
142 | #define TEGRA_I2S_FIFO_SCR_FIFO2_ATN_LVL_MASK (3 << TEGRA_I2S_FIFO_SCR_FIFO2_ATN_LVL_SHIFT) | ||
143 | #define TEGRA_I2S_FIFO_SCR_FIFO2_ATN_LVL_ONE_SLOT (TEGRA_I2S_FIFO_ATN_LVL_ONE_SLOT << TEGRA_I2S_FIFO_SCR_FIFO2_ATN_LVL_SHIFT) | ||
144 | #define TEGRA_I2S_FIFO_SCR_FIFO2_ATN_LVL_FOUR_SLOTS (TEGRA_I2S_FIFO_ATN_LVL_FOUR_SLOTS << TEGRA_I2S_FIFO_SCR_FIFO2_ATN_LVL_SHIFT) | ||
145 | #define TEGRA_I2S_FIFO_SCR_FIFO2_ATN_LVL_EIGHT_SLOTS (TEGRA_I2S_FIFO_ATN_LVL_EIGHT_SLOTS << TEGRA_I2S_FIFO_SCR_FIFO2_ATN_LVL_SHIFT) | ||
146 | #define TEGRA_I2S_FIFO_SCR_FIFO2_ATN_LVL_TWELVE_SLOTS (TEGRA_I2S_FIFO_ATN_LVL_TWELVE_SLOTS << TEGRA_I2S_FIFO_SCR_FIFO2_ATN_LVL_SHIFT) | ||
147 | |||
148 | #define TEGRA_I2S_FIFO_SCR_FIFO1_ATN_LVL_SHIFT 0 | ||
149 | #define TEGRA_I2S_FIFO_SCR_FIFO1_ATN_LVL_MASK (3 << TEGRA_I2S_FIFO_SCR_FIFO1_ATN_LVL_SHIFT) | ||
150 | #define TEGRA_I2S_FIFO_SCR_FIFO1_ATN_LVL_ONE_SLOT (TEGRA_I2S_FIFO_ATN_LVL_ONE_SLOT << TEGRA_I2S_FIFO_SCR_FIFO1_ATN_LVL_SHIFT) | ||
151 | #define TEGRA_I2S_FIFO_SCR_FIFO1_ATN_LVL_FOUR_SLOTS (TEGRA_I2S_FIFO_ATN_LVL_FOUR_SLOTS << TEGRA_I2S_FIFO_SCR_FIFO1_ATN_LVL_SHIFT) | ||
152 | #define TEGRA_I2S_FIFO_SCR_FIFO1_ATN_LVL_EIGHT_SLOTS (TEGRA_I2S_FIFO_ATN_LVL_EIGHT_SLOTS << TEGRA_I2S_FIFO_SCR_FIFO1_ATN_LVL_SHIFT) | ||
153 | #define TEGRA_I2S_FIFO_SCR_FIFO1_ATN_LVL_TWELVE_SLOTS (TEGRA_I2S_FIFO_ATN_LVL_TWELVE_SLOTS << TEGRA_I2S_FIFO_SCR_FIFO1_ATN_LVL_SHIFT) | ||
154 | |||
155 | struct tegra_i2s { | ||
156 | struct snd_soc_dai_driver dai; | ||
157 | struct clk *clk_i2s; | ||
158 | int clk_refs; | ||
159 | struct tegra_pcm_dma_params capture_dma_data; | ||
160 | struct tegra_pcm_dma_params playback_dma_data; | ||
161 | void __iomem *regs; | ||
162 | struct dentry *debug; | ||
163 | u32 reg_ctrl; | ||
164 | }; | ||
165 | |||
166 | #endif | ||
diff --git a/sound/soc/tegra/tegra_pcm.c b/sound/soc/tegra/tegra_pcm.c index 8b4457137c7c..127348dc09b1 100644 --- a/sound/soc/tegra/tegra_pcm.c +++ b/sound/soc/tegra/tegra_pcm.c | |||
@@ -2,7 +2,7 @@ | |||
2 | * tegra_pcm.c - Tegra PCM driver | 2 | * tegra_pcm.c - Tegra PCM driver |
3 | * | 3 | * |
4 | * Author: Stephen Warren <swarren@nvidia.com> | 4 | * Author: Stephen Warren <swarren@nvidia.com> |
5 | * Copyright (C) 2010 - NVIDIA, Inc. | 5 | * Copyright (C) 2010,2012 - NVIDIA, Inc. |
6 | * | 6 | * |
7 | * Based on code copyright/by: | 7 | * Based on code copyright/by: |
8 | * | 8 | * |
@@ -29,8 +29,8 @@ | |||
29 | * | 29 | * |
30 | */ | 30 | */ |
31 | 31 | ||
32 | #include <linux/module.h> | ||
33 | #include <linux/dma-mapping.h> | 32 | #include <linux/dma-mapping.h> |
33 | #include <linux/module.h> | ||
34 | #include <linux/slab.h> | 34 | #include <linux/slab.h> |
35 | #include <sound/core.h> | 35 | #include <sound/core.h> |
36 | #include <sound/pcm.h> | 36 | #include <sound/pcm.h> |
@@ -39,8 +39,6 @@ | |||
39 | 39 | ||
40 | #include "tegra_pcm.h" | 40 | #include "tegra_pcm.h" |
41 | 41 | ||
42 | #define DRV_NAME "tegra-pcm-audio" | ||
43 | |||
44 | static const struct snd_pcm_hardware tegra_pcm_hardware = { | 42 | static const struct snd_pcm_hardware tegra_pcm_hardware = { |
45 | .info = SNDRV_PCM_INFO_MMAP | | 43 | .info = SNDRV_PCM_INFO_MMAP | |
46 | SNDRV_PCM_INFO_MMAP_VALID | | 44 | SNDRV_PCM_INFO_MMAP_VALID | |
@@ -372,28 +370,18 @@ static struct snd_soc_platform_driver tegra_pcm_platform = { | |||
372 | .pcm_free = tegra_pcm_free, | 370 | .pcm_free = tegra_pcm_free, |
373 | }; | 371 | }; |
374 | 372 | ||
375 | static int __devinit tegra_pcm_platform_probe(struct platform_device *pdev) | 373 | int __devinit tegra_pcm_platform_register(struct device *dev) |
376 | { | 374 | { |
377 | return snd_soc_register_platform(&pdev->dev, &tegra_pcm_platform); | 375 | return snd_soc_register_platform(dev, &tegra_pcm_platform); |
378 | } | 376 | } |
377 | EXPORT_SYMBOL_GPL(tegra_pcm_platform_register); | ||
379 | 378 | ||
380 | static int __devexit tegra_pcm_platform_remove(struct platform_device *pdev) | 379 | void __devexit tegra_pcm_platform_unregister(struct device *dev) |
381 | { | 380 | { |
382 | snd_soc_unregister_platform(&pdev->dev); | 381 | snd_soc_unregister_platform(dev); |
383 | return 0; | ||
384 | } | 382 | } |
385 | 383 | EXPORT_SYMBOL_GPL(tegra_pcm_platform_unregister); | |
386 | static struct platform_driver tegra_pcm_driver = { | ||
387 | .driver = { | ||
388 | .name = DRV_NAME, | ||
389 | .owner = THIS_MODULE, | ||
390 | }, | ||
391 | .probe = tegra_pcm_platform_probe, | ||
392 | .remove = __devexit_p(tegra_pcm_platform_remove), | ||
393 | }; | ||
394 | module_platform_driver(tegra_pcm_driver); | ||
395 | 384 | ||
396 | MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>"); | 385 | MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>"); |
397 | MODULE_DESCRIPTION("Tegra PCM ASoC driver"); | 386 | MODULE_DESCRIPTION("Tegra PCM ASoC driver"); |
398 | MODULE_LICENSE("GPL"); | 387 | MODULE_LICENSE("GPL"); |
399 | MODULE_ALIAS("platform:" DRV_NAME); | ||
diff --git a/sound/soc/tegra/tegra_pcm.h b/sound/soc/tegra/tegra_pcm.h index dbb90339fe0d..985d418a35e7 100644 --- a/sound/soc/tegra/tegra_pcm.h +++ b/sound/soc/tegra/tegra_pcm.h | |||
@@ -2,7 +2,7 @@ | |||
2 | * tegra_pcm.h - Definitions for Tegra PCM driver | 2 | * tegra_pcm.h - Definitions for Tegra PCM driver |
3 | * | 3 | * |
4 | * Author: Stephen Warren <swarren@nvidia.com> | 4 | * Author: Stephen Warren <swarren@nvidia.com> |
5 | * Copyright (C) 2010 - NVIDIA, Inc. | 5 | * Copyright (C) 2010,2012 - NVIDIA, Inc. |
6 | * | 6 | * |
7 | * Based on code copyright/by: | 7 | * Based on code copyright/by: |
8 | * | 8 | * |
@@ -52,4 +52,7 @@ struct tegra_runtime_data { | |||
52 | struct tegra_dma_channel *dma_chan; | 52 | struct tegra_dma_channel *dma_chan; |
53 | }; | 53 | }; |
54 | 54 | ||
55 | int tegra_pcm_platform_register(struct device *dev); | ||
56 | void tegra_pcm_platform_unregister(struct device *dev); | ||
57 | |||
55 | #endif | 58 | #endif |
diff --git a/sound/soc/tegra/tegra_spdif.c b/sound/soc/tegra/tegra_spdif.c deleted file mode 100644 index 9ff2c601445f..000000000000 --- a/sound/soc/tegra/tegra_spdif.c +++ /dev/null | |||
@@ -1,364 +0,0 @@ | |||
1 | /* | ||
2 | * tegra_spdif.c - Tegra SPDIF driver | ||
3 | * | ||
4 | * Author: Stephen Warren <swarren@nvidia.com> | ||
5 | * Copyright (C) 2011 - NVIDIA, Inc. | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or | ||
8 | * modify it under the terms of the GNU General Public License | ||
9 | * version 2 as published by the Free Software Foundation. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, but | ||
12 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | * General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program; if not, write to the Free Software | ||
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
19 | * 02110-1301 USA | ||
20 | * | ||
21 | */ | ||
22 | |||
23 | #include <linux/clk.h> | ||
24 | #include <linux/module.h> | ||
25 | #include <linux/debugfs.h> | ||
26 | #include <linux/device.h> | ||
27 | #include <linux/platform_device.h> | ||
28 | #include <linux/seq_file.h> | ||
29 | #include <linux/slab.h> | ||
30 | #include <linux/io.h> | ||
31 | #include <mach/iomap.h> | ||
32 | #include <sound/core.h> | ||
33 | #include <sound/pcm.h> | ||
34 | #include <sound/pcm_params.h> | ||
35 | #include <sound/soc.h> | ||
36 | |||
37 | #include "tegra_spdif.h" | ||
38 | |||
39 | #define DRV_NAME "tegra-spdif" | ||
40 | |||
41 | static inline void tegra_spdif_write(struct tegra_spdif *spdif, u32 reg, | ||
42 | u32 val) | ||
43 | { | ||
44 | __raw_writel(val, spdif->regs + reg); | ||
45 | } | ||
46 | |||
47 | static inline u32 tegra_spdif_read(struct tegra_spdif *spdif, u32 reg) | ||
48 | { | ||
49 | return __raw_readl(spdif->regs + reg); | ||
50 | } | ||
51 | |||
52 | #ifdef CONFIG_DEBUG_FS | ||
53 | static int tegra_spdif_show(struct seq_file *s, void *unused) | ||
54 | { | ||
55 | #define REG(r) { r, #r } | ||
56 | static const struct { | ||
57 | int offset; | ||
58 | const char *name; | ||
59 | } regs[] = { | ||
60 | REG(TEGRA_SPDIF_CTRL), | ||
61 | REG(TEGRA_SPDIF_STATUS), | ||
62 | REG(TEGRA_SPDIF_STROBE_CTRL), | ||
63 | REG(TEGRA_SPDIF_DATA_FIFO_CSR), | ||
64 | REG(TEGRA_SPDIF_CH_STA_RX_A), | ||
65 | REG(TEGRA_SPDIF_CH_STA_RX_B), | ||
66 | REG(TEGRA_SPDIF_CH_STA_RX_C), | ||
67 | REG(TEGRA_SPDIF_CH_STA_RX_D), | ||
68 | REG(TEGRA_SPDIF_CH_STA_RX_E), | ||
69 | REG(TEGRA_SPDIF_CH_STA_RX_F), | ||
70 | REG(TEGRA_SPDIF_CH_STA_TX_A), | ||
71 | REG(TEGRA_SPDIF_CH_STA_TX_B), | ||
72 | REG(TEGRA_SPDIF_CH_STA_TX_C), | ||
73 | REG(TEGRA_SPDIF_CH_STA_TX_D), | ||
74 | REG(TEGRA_SPDIF_CH_STA_TX_E), | ||
75 | REG(TEGRA_SPDIF_CH_STA_TX_F), | ||
76 | }; | ||
77 | #undef REG | ||
78 | |||
79 | struct tegra_spdif *spdif = s->private; | ||
80 | int i; | ||
81 | |||
82 | clk_enable(spdif->clk_spdif_out); | ||
83 | |||
84 | for (i = 0; i < ARRAY_SIZE(regs); i++) { | ||
85 | u32 val = tegra_spdif_read(spdif, regs[i].offset); | ||
86 | seq_printf(s, "%s = %08x\n", regs[i].name, val); | ||
87 | } | ||
88 | |||
89 | clk_disable(spdif->clk_spdif_out); | ||
90 | |||
91 | return 0; | ||
92 | } | ||
93 | |||
94 | static int tegra_spdif_debug_open(struct inode *inode, struct file *file) | ||
95 | { | ||
96 | return single_open(file, tegra_spdif_show, inode->i_private); | ||
97 | } | ||
98 | |||
99 | static const struct file_operations tegra_spdif_debug_fops = { | ||
100 | .open = tegra_spdif_debug_open, | ||
101 | .read = seq_read, | ||
102 | .llseek = seq_lseek, | ||
103 | .release = single_release, | ||
104 | }; | ||
105 | |||
106 | static void tegra_spdif_debug_add(struct tegra_spdif *spdif) | ||
107 | { | ||
108 | spdif->debug = debugfs_create_file(DRV_NAME, S_IRUGO, | ||
109 | snd_soc_debugfs_root, spdif, | ||
110 | &tegra_spdif_debug_fops); | ||
111 | } | ||
112 | |||
113 | static void tegra_spdif_debug_remove(struct tegra_spdif *spdif) | ||
114 | { | ||
115 | if (spdif->debug) | ||
116 | debugfs_remove(spdif->debug); | ||
117 | } | ||
118 | #else | ||
119 | static inline void tegra_spdif_debug_add(struct tegra_spdif *spdif) | ||
120 | { | ||
121 | } | ||
122 | |||
123 | static inline void tegra_spdif_debug_remove(struct tegra_spdif *spdif) | ||
124 | { | ||
125 | } | ||
126 | #endif | ||
127 | |||
128 | static int tegra_spdif_hw_params(struct snd_pcm_substream *substream, | ||
129 | struct snd_pcm_hw_params *params, | ||
130 | struct snd_soc_dai *dai) | ||
131 | { | ||
132 | struct device *dev = substream->pcm->card->dev; | ||
133 | struct tegra_spdif *spdif = snd_soc_dai_get_drvdata(dai); | ||
134 | int ret, spdifclock; | ||
135 | |||
136 | spdif->reg_ctrl &= ~TEGRA_SPDIF_CTRL_PACK; | ||
137 | spdif->reg_ctrl &= ~TEGRA_SPDIF_CTRL_BIT_MODE_MASK; | ||
138 | switch (params_format(params)) { | ||
139 | case SNDRV_PCM_FORMAT_S16_LE: | ||
140 | spdif->reg_ctrl |= TEGRA_SPDIF_CTRL_PACK; | ||
141 | spdif->reg_ctrl |= TEGRA_SPDIF_CTRL_BIT_MODE_16BIT; | ||
142 | break; | ||
143 | default: | ||
144 | return -EINVAL; | ||
145 | } | ||
146 | |||
147 | switch (params_rate(params)) { | ||
148 | case 32000: | ||
149 | spdifclock = 4096000; | ||
150 | break; | ||
151 | case 44100: | ||
152 | spdifclock = 5644800; | ||
153 | break; | ||
154 | case 48000: | ||
155 | spdifclock = 6144000; | ||
156 | break; | ||
157 | case 88200: | ||
158 | spdifclock = 11289600; | ||
159 | break; | ||
160 | case 96000: | ||
161 | spdifclock = 12288000; | ||
162 | break; | ||
163 | case 176400: | ||
164 | spdifclock = 22579200; | ||
165 | break; | ||
166 | case 192000: | ||
167 | spdifclock = 24576000; | ||
168 | break; | ||
169 | default: | ||
170 | return -EINVAL; | ||
171 | } | ||
172 | |||
173 | ret = clk_set_rate(spdif->clk_spdif_out, spdifclock); | ||
174 | if (ret) { | ||
175 | dev_err(dev, "Can't set SPDIF clock rate: %d\n", ret); | ||
176 | return ret; | ||
177 | } | ||
178 | |||
179 | return 0; | ||
180 | } | ||
181 | |||
182 | static void tegra_spdif_start_playback(struct tegra_spdif *spdif) | ||
183 | { | ||
184 | spdif->reg_ctrl |= TEGRA_SPDIF_CTRL_TX_EN; | ||
185 | tegra_spdif_write(spdif, TEGRA_SPDIF_CTRL, spdif->reg_ctrl); | ||
186 | } | ||
187 | |||
188 | static void tegra_spdif_stop_playback(struct tegra_spdif *spdif) | ||
189 | { | ||
190 | spdif->reg_ctrl &= ~TEGRA_SPDIF_CTRL_TX_EN; | ||
191 | tegra_spdif_write(spdif, TEGRA_SPDIF_CTRL, spdif->reg_ctrl); | ||
192 | } | ||
193 | |||
194 | static int tegra_spdif_trigger(struct snd_pcm_substream *substream, int cmd, | ||
195 | struct snd_soc_dai *dai) | ||
196 | { | ||
197 | struct tegra_spdif *spdif = snd_soc_dai_get_drvdata(dai); | ||
198 | |||
199 | switch (cmd) { | ||
200 | case SNDRV_PCM_TRIGGER_START: | ||
201 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: | ||
202 | case SNDRV_PCM_TRIGGER_RESUME: | ||
203 | if (!spdif->clk_refs) | ||
204 | clk_enable(spdif->clk_spdif_out); | ||
205 | spdif->clk_refs++; | ||
206 | tegra_spdif_start_playback(spdif); | ||
207 | break; | ||
208 | case SNDRV_PCM_TRIGGER_STOP: | ||
209 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: | ||
210 | case SNDRV_PCM_TRIGGER_SUSPEND: | ||
211 | tegra_spdif_stop_playback(spdif); | ||
212 | spdif->clk_refs--; | ||
213 | if (!spdif->clk_refs) | ||
214 | clk_disable(spdif->clk_spdif_out); | ||
215 | break; | ||
216 | default: | ||
217 | return -EINVAL; | ||
218 | } | ||
219 | |||
220 | return 0; | ||
221 | } | ||
222 | |||
223 | static int tegra_spdif_probe(struct snd_soc_dai *dai) | ||
224 | { | ||
225 | struct tegra_spdif *spdif = snd_soc_dai_get_drvdata(dai); | ||
226 | |||
227 | dai->capture_dma_data = NULL; | ||
228 | dai->playback_dma_data = &spdif->playback_dma_data; | ||
229 | |||
230 | return 0; | ||
231 | } | ||
232 | |||
233 | static const struct snd_soc_dai_ops tegra_spdif_dai_ops = { | ||
234 | .hw_params = tegra_spdif_hw_params, | ||
235 | .trigger = tegra_spdif_trigger, | ||
236 | }; | ||
237 | |||
238 | static struct snd_soc_dai_driver tegra_spdif_dai = { | ||
239 | .name = DRV_NAME, | ||
240 | .probe = tegra_spdif_probe, | ||
241 | .playback = { | ||
242 | .channels_min = 2, | ||
243 | .channels_max = 2, | ||
244 | .rates = SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | | ||
245 | SNDRV_PCM_RATE_48000, | ||
246 | .formats = SNDRV_PCM_FMTBIT_S16_LE, | ||
247 | }, | ||
248 | .ops = &tegra_spdif_dai_ops, | ||
249 | }; | ||
250 | |||
251 | static __devinit int tegra_spdif_platform_probe(struct platform_device *pdev) | ||
252 | { | ||
253 | struct tegra_spdif *spdif; | ||
254 | struct resource *mem, *memregion, *dmareq; | ||
255 | int ret; | ||
256 | |||
257 | spdif = kzalloc(sizeof(struct tegra_spdif), GFP_KERNEL); | ||
258 | if (!spdif) { | ||
259 | dev_err(&pdev->dev, "Can't allocate tegra_spdif\n"); | ||
260 | ret = -ENOMEM; | ||
261 | goto exit; | ||
262 | } | ||
263 | dev_set_drvdata(&pdev->dev, spdif); | ||
264 | |||
265 | spdif->clk_spdif_out = clk_get(&pdev->dev, "spdif_out"); | ||
266 | if (IS_ERR(spdif->clk_spdif_out)) { | ||
267 | pr_err("Can't retrieve spdif clock\n"); | ||
268 | ret = PTR_ERR(spdif->clk_spdif_out); | ||
269 | goto err_free; | ||
270 | } | ||
271 | |||
272 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
273 | if (!mem) { | ||
274 | dev_err(&pdev->dev, "No memory resource\n"); | ||
275 | ret = -ENODEV; | ||
276 | goto err_clk_put; | ||
277 | } | ||
278 | |||
279 | dmareq = platform_get_resource(pdev, IORESOURCE_DMA, 0); | ||
280 | if (!dmareq) { | ||
281 | dev_err(&pdev->dev, "No DMA resource\n"); | ||
282 | ret = -ENODEV; | ||
283 | goto err_clk_put; | ||
284 | } | ||
285 | |||
286 | memregion = request_mem_region(mem->start, resource_size(mem), | ||
287 | DRV_NAME); | ||
288 | if (!memregion) { | ||
289 | dev_err(&pdev->dev, "Memory region already claimed\n"); | ||
290 | ret = -EBUSY; | ||
291 | goto err_clk_put; | ||
292 | } | ||
293 | |||
294 | spdif->regs = ioremap(mem->start, resource_size(mem)); | ||
295 | if (!spdif->regs) { | ||
296 | dev_err(&pdev->dev, "ioremap failed\n"); | ||
297 | ret = -ENOMEM; | ||
298 | goto err_release; | ||
299 | } | ||
300 | |||
301 | spdif->playback_dma_data.addr = mem->start + TEGRA_SPDIF_DATA_OUT; | ||
302 | spdif->playback_dma_data.wrap = 4; | ||
303 | spdif->playback_dma_data.width = 32; | ||
304 | spdif->playback_dma_data.req_sel = dmareq->start; | ||
305 | |||
306 | ret = snd_soc_register_dai(&pdev->dev, &tegra_spdif_dai); | ||
307 | if (ret) { | ||
308 | dev_err(&pdev->dev, "Could not register DAI: %d\n", ret); | ||
309 | ret = -ENOMEM; | ||
310 | goto err_unmap; | ||
311 | } | ||
312 | |||
313 | tegra_spdif_debug_add(spdif); | ||
314 | |||
315 | return 0; | ||
316 | |||
317 | err_unmap: | ||
318 | iounmap(spdif->regs); | ||
319 | err_release: | ||
320 | release_mem_region(mem->start, resource_size(mem)); | ||
321 | err_clk_put: | ||
322 | clk_put(spdif->clk_spdif_out); | ||
323 | err_free: | ||
324 | kfree(spdif); | ||
325 | exit: | ||
326 | return ret; | ||
327 | } | ||
328 | |||
329 | static int __devexit tegra_spdif_platform_remove(struct platform_device *pdev) | ||
330 | { | ||
331 | struct tegra_spdif *spdif = dev_get_drvdata(&pdev->dev); | ||
332 | struct resource *res; | ||
333 | |||
334 | snd_soc_unregister_dai(&pdev->dev); | ||
335 | |||
336 | tegra_spdif_debug_remove(spdif); | ||
337 | |||
338 | iounmap(spdif->regs); | ||
339 | |||
340 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
341 | release_mem_region(res->start, resource_size(res)); | ||
342 | |||
343 | clk_put(spdif->clk_spdif_out); | ||
344 | |||
345 | kfree(spdif); | ||
346 | |||
347 | return 0; | ||
348 | } | ||
349 | |||
350 | static struct platform_driver tegra_spdif_driver = { | ||
351 | .driver = { | ||
352 | .name = DRV_NAME, | ||
353 | .owner = THIS_MODULE, | ||
354 | }, | ||
355 | .probe = tegra_spdif_platform_probe, | ||
356 | .remove = __devexit_p(tegra_spdif_platform_remove), | ||
357 | }; | ||
358 | |||
359 | module_platform_driver(tegra_spdif_driver); | ||
360 | |||
361 | MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>"); | ||
362 | MODULE_DESCRIPTION("Tegra SPDIF ASoC driver"); | ||
363 | MODULE_LICENSE("GPL"); | ||
364 | MODULE_ALIAS("platform:" DRV_NAME); | ||
diff --git a/sound/soc/tegra/tegra_spdif.h b/sound/soc/tegra/tegra_spdif.h deleted file mode 100644 index 2e03db430279..000000000000 --- a/sound/soc/tegra/tegra_spdif.h +++ /dev/null | |||
@@ -1,473 +0,0 @@ | |||
1 | /* | ||
2 | * tegra_spdif.h - Definitions for Tegra SPDIF driver | ||
3 | * | ||
4 | * Author: Stephen Warren <swarren@nvidia.com> | ||
5 | * Copyright (C) 2011 - NVIDIA, Inc. | ||
6 | * | ||
7 | * Based on code copyright/by: | ||
8 | * Copyright (c) 2008-2009, NVIDIA Corporation | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or | ||
11 | * modify it under the terms of the GNU General Public License | ||
12 | * version 2 as published by the Free Software Foundation. | ||
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, but | ||
15 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
17 | * General Public License for more details. | ||
18 | * | ||
19 | * You should have received a copy of the GNU General Public License | ||
20 | * along with this program; if not, write to the Free Software | ||
21 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
22 | * 02110-1301 USA | ||
23 | * | ||
24 | */ | ||
25 | |||
26 | #ifndef __TEGRA_SPDIF_H__ | ||
27 | #define __TEGRA_SPDIF_H__ | ||
28 | |||
29 | #include "tegra_pcm.h" | ||
30 | |||
31 | /* Offsets from TEGRA_SPDIF_BASE */ | ||
32 | |||
33 | #define TEGRA_SPDIF_CTRL 0x0 | ||
34 | #define TEGRA_SPDIF_STATUS 0x4 | ||
35 | #define TEGRA_SPDIF_STROBE_CTRL 0x8 | ||
36 | #define TEGRA_SPDIF_DATA_FIFO_CSR 0x0C | ||
37 | #define TEGRA_SPDIF_DATA_OUT 0x40 | ||
38 | #define TEGRA_SPDIF_DATA_IN 0x80 | ||
39 | #define TEGRA_SPDIF_CH_STA_RX_A 0x100 | ||
40 | #define TEGRA_SPDIF_CH_STA_RX_B 0x104 | ||
41 | #define TEGRA_SPDIF_CH_STA_RX_C 0x108 | ||
42 | #define TEGRA_SPDIF_CH_STA_RX_D 0x10C | ||
43 | #define TEGRA_SPDIF_CH_STA_RX_E 0x110 | ||
44 | #define TEGRA_SPDIF_CH_STA_RX_F 0x114 | ||
45 | #define TEGRA_SPDIF_CH_STA_TX_A 0x140 | ||
46 | #define TEGRA_SPDIF_CH_STA_TX_B 0x144 | ||
47 | #define TEGRA_SPDIF_CH_STA_TX_C 0x148 | ||
48 | #define TEGRA_SPDIF_CH_STA_TX_D 0x14C | ||
49 | #define TEGRA_SPDIF_CH_STA_TX_E 0x150 | ||
50 | #define TEGRA_SPDIF_CH_STA_TX_F 0x154 | ||
51 | #define TEGRA_SPDIF_USR_STA_RX_A 0x180 | ||
52 | #define TEGRA_SPDIF_USR_DAT_TX_A 0x1C0 | ||
53 | |||
54 | /* Fields in TEGRA_SPDIF_CTRL */ | ||
55 | |||
56 | /* Start capturing from 0=right, 1=left channel */ | ||
57 | #define TEGRA_SPDIF_CTRL_CAP_LC (1 << 30) | ||
58 | |||
59 | /* SPDIF receiver(RX) enable */ | ||
60 | #define TEGRA_SPDIF_CTRL_RX_EN (1 << 29) | ||
61 | |||
62 | /* SPDIF Transmitter(TX) enable */ | ||
63 | #define TEGRA_SPDIF_CTRL_TX_EN (1 << 28) | ||
64 | |||
65 | /* Transmit Channel status */ | ||
66 | #define TEGRA_SPDIF_CTRL_TC_EN (1 << 27) | ||
67 | |||
68 | /* Transmit user Data */ | ||
69 | #define TEGRA_SPDIF_CTRL_TU_EN (1 << 26) | ||
70 | |||
71 | /* Interrupt on transmit error */ | ||
72 | #define TEGRA_SPDIF_CTRL_IE_TXE (1 << 25) | ||
73 | |||
74 | /* Interrupt on receive error */ | ||
75 | #define TEGRA_SPDIF_CTRL_IE_RXE (1 << 24) | ||
76 | |||
77 | /* Interrupt on invalid preamble */ | ||
78 | #define TEGRA_SPDIF_CTRL_IE_P (1 << 23) | ||
79 | |||
80 | /* Interrupt on "B" preamble */ | ||
81 | #define TEGRA_SPDIF_CTRL_IE_B (1 << 22) | ||
82 | |||
83 | /* Interrupt when block of channel status received */ | ||
84 | #define TEGRA_SPDIF_CTRL_IE_C (1 << 21) | ||
85 | |||
86 | /* Interrupt when a valid information unit (IU) is received */ | ||
87 | #define TEGRA_SPDIF_CTRL_IE_U (1 << 20) | ||
88 | |||
89 | /* Interrupt when RX user FIFO attention level is reached */ | ||
90 | #define TEGRA_SPDIF_CTRL_QE_RU (1 << 19) | ||
91 | |||
92 | /* Interrupt when TX user FIFO attention level is reached */ | ||
93 | #define TEGRA_SPDIF_CTRL_QE_TU (1 << 18) | ||
94 | |||
95 | /* Interrupt when RX data FIFO attention level is reached */ | ||
96 | #define TEGRA_SPDIF_CTRL_QE_RX (1 << 17) | ||
97 | |||
98 | /* Interrupt when TX data FIFO attention level is reached */ | ||
99 | #define TEGRA_SPDIF_CTRL_QE_TX (1 << 16) | ||
100 | |||
101 | /* Loopback test mode enable */ | ||
102 | #define TEGRA_SPDIF_CTRL_LBK_EN (1 << 15) | ||
103 | |||
104 | /* | ||
105 | * Pack data mode: | ||
106 | * 0 = Single data (16 bit needs to be padded to match the | ||
107 | * interface data bit size). | ||
108 | * 1 = Packeted left/right channel data into a single word. | ||
109 | */ | ||
110 | #define TEGRA_SPDIF_CTRL_PACK (1 << 14) | ||
111 | |||
112 | /* | ||
113 | * 00 = 16bit data | ||
114 | * 01 = 20bit data | ||
115 | * 10 = 24bit data | ||
116 | * 11 = raw data | ||
117 | */ | ||
118 | #define TEGRA_SPDIF_BIT_MODE_16BIT 0 | ||
119 | #define TEGRA_SPDIF_BIT_MODE_20BIT 1 | ||
120 | #define TEGRA_SPDIF_BIT_MODE_24BIT 2 | ||
121 | #define TEGRA_SPDIF_BIT_MODE_RAW 3 | ||
122 | |||
123 | #define TEGRA_SPDIF_CTRL_BIT_MODE_SHIFT 12 | ||
124 | #define TEGRA_SPDIF_CTRL_BIT_MODE_MASK (3 << TEGRA_SPDIF_CTRL_BIT_MODE_SHIFT) | ||
125 | #define TEGRA_SPDIF_CTRL_BIT_MODE_16BIT (TEGRA_SPDIF_BIT_MODE_16BIT << TEGRA_SPDIF_CTRL_BIT_MODE_SHIFT) | ||
126 | #define TEGRA_SPDIF_CTRL_BIT_MODE_20BIT (TEGRA_SPDIF_BIT_MODE_20BIT << TEGRA_SPDIF_CTRL_BIT_MODE_SHIFT) | ||
127 | #define TEGRA_SPDIF_CTRL_BIT_MODE_24BIT (TEGRA_SPDIF_BIT_MODE_24BIT << TEGRA_SPDIF_CTRL_BIT_MODE_SHIFT) | ||
128 | #define TEGRA_SPDIF_CTRL_BIT_MODE_RAW (TEGRA_SPDIF_BIT_MODE_RAW << TEGRA_SPDIF_CTRL_BIT_MODE_SHIFT) | ||
129 | |||
130 | /* Fields in TEGRA_SPDIF_STATUS */ | ||
131 | |||
132 | /* | ||
133 | * Note: IS_P, IS_B, IS_C, and IS_U are sticky bits. Software must | ||
134 | * write a 1 to the corresponding bit location to clear the status. | ||
135 | */ | ||
136 | |||
137 | /* | ||
138 | * Receiver(RX) shifter is busy receiving data. | ||
139 | * This bit is asserted when the receiver first locked onto the | ||
140 | * preamble of the data stream after RX_EN is asserted. This bit is | ||
141 | * deasserted when either, | ||
142 | * (a) the end of a frame is reached after RX_EN is deeasserted, or | ||
143 | * (b) the SPDIF data stream becomes inactive. | ||
144 | */ | ||
145 | #define TEGRA_SPDIF_STATUS_RX_BSY (1 << 29) | ||
146 | |||
147 | /* | ||
148 | * Transmitter(TX) shifter is busy transmitting data. | ||
149 | * This bit is asserted when TX_EN is asserted. | ||
150 | * This bit is deasserted when the end of a frame is reached after | ||
151 | * TX_EN is deasserted. | ||
152 | */ | ||
153 | #define TEGRA_SPDIF_STATUS_TX_BSY (1 << 28) | ||
154 | |||
155 | /* | ||
156 | * TX is busy shifting out channel status. | ||
157 | * This bit is asserted when both TX_EN and TC_EN are asserted and | ||
158 | * data from CH_STA_TX_A register is loaded into the internal shifter. | ||
159 | * This bit is deasserted when either, | ||
160 | * (a) the end of a frame is reached after TX_EN is deasserted, or | ||
161 | * (b) CH_STA_TX_F register is loaded into the internal shifter. | ||
162 | */ | ||
163 | #define TEGRA_SPDIF_STATUS_TC_BSY (1 << 27) | ||
164 | |||
165 | /* | ||
166 | * TX User data FIFO busy. | ||
167 | * This bit is asserted when TX_EN and TXU_EN are asserted and | ||
168 | * there's data in the TX user FIFO. This bit is deassert when either, | ||
169 | * (a) the end of a frame is reached after TX_EN is deasserted, or | ||
170 | * (b) there's no data left in the TX user FIFO. | ||
171 | */ | ||
172 | #define TEGRA_SPDIF_STATUS_TU_BSY (1 << 26) | ||
173 | |||
174 | /* TX FIFO Underrun error status */ | ||
175 | #define TEGRA_SPDIF_STATUS_TX_ERR (1 << 25) | ||
176 | |||
177 | /* RX FIFO Overrun error status */ | ||
178 | #define TEGRA_SPDIF_STATUS_RX_ERR (1 << 24) | ||
179 | |||
180 | /* Preamble status: 0=Preamble OK, 1=bad/missing preamble */ | ||
181 | #define TEGRA_SPDIF_STATUS_IS_P (1 << 23) | ||
182 | |||
183 | /* B-preamble detection status: 0=not detected, 1=B-preamble detected */ | ||
184 | #define TEGRA_SPDIF_STATUS_IS_B (1 << 22) | ||
185 | |||
186 | /* | ||
187 | * RX channel block data receive status: | ||
188 | * 0=entire block not recieved yet. | ||
189 | * 1=received entire block of channel status, | ||
190 | */ | ||
191 | #define TEGRA_SPDIF_STATUS_IS_C (1 << 21) | ||
192 | |||
193 | /* RX User Data Valid flag: 1=valid IU detected, 0 = no IU detected. */ | ||
194 | #define TEGRA_SPDIF_STATUS_IS_U (1 << 20) | ||
195 | |||
196 | /* | ||
197 | * RX User FIFO Status: | ||
198 | * 1=attention level reached, 0=attention level not reached. | ||
199 | */ | ||
200 | #define TEGRA_SPDIF_STATUS_QS_RU (1 << 19) | ||
201 | |||
202 | /* | ||
203 | * TX User FIFO Status: | ||
204 | * 1=attention level reached, 0=attention level not reached. | ||
205 | */ | ||
206 | #define TEGRA_SPDIF_STATUS_QS_TU (1 << 18) | ||
207 | |||
208 | /* | ||
209 | * RX Data FIFO Status: | ||
210 | * 1=attention level reached, 0=attention level not reached. | ||
211 | */ | ||
212 | #define TEGRA_SPDIF_STATUS_QS_RX (1 << 17) | ||
213 | |||
214 | /* | ||
215 | * TX Data FIFO Status: | ||
216 | * 1=attention level reached, 0=attention level not reached. | ||
217 | */ | ||
218 | #define TEGRA_SPDIF_STATUS_QS_TX (1 << 16) | ||
219 | |||
220 | /* Fields in TEGRA_SPDIF_STROBE_CTRL */ | ||
221 | |||
222 | /* | ||
223 | * Indicates the approximate number of detected SPDIFIN clocks within a | ||
224 | * bi-phase period. | ||
225 | */ | ||
226 | #define TEGRA_SPDIF_STROBE_CTRL_PERIOD_SHIFT 16 | ||
227 | #define TEGRA_SPDIF_STROBE_CTRL_PERIOD_MASK (0xff << TEGRA_SPDIF_STROBE_CTRL_PERIOD_SHIFT) | ||
228 | |||
229 | /* Data strobe mode: 0=Auto-locked 1=Manual locked */ | ||
230 | #define TEGRA_SPDIF_STROBE_CTRL_STROBE (1 << 15) | ||
231 | |||
232 | /* | ||
233 | * Manual data strobe time within the bi-phase clock period (in terms of | ||
234 | * the number of over-sampling clocks). | ||
235 | */ | ||
236 | #define TEGRA_SPDIF_STROBE_CTRL_DATA_STROBES_SHIFT 8 | ||
237 | #define TEGRA_SPDIF_STROBE_CTRL_DATA_STROBES_MASK (0x1f << TEGRA_SPDIF_STROBE_CTRL_DATA_STROBES_SHIFT) | ||
238 | |||
239 | /* | ||
240 | * Manual SPDIFIN bi-phase clock period (in terms of the number of | ||
241 | * over-sampling clocks). | ||
242 | */ | ||
243 | #define TEGRA_SPDIF_STROBE_CTRL_CLOCK_PERIOD_SHIFT 0 | ||
244 | #define TEGRA_SPDIF_STROBE_CTRL_CLOCK_PERIOD_MASK (0x3f << TEGRA_SPDIF_STROBE_CTRL_CLOCK_PERIOD_SHIFT) | ||
245 | |||
246 | /* Fields in SPDIF_DATA_FIFO_CSR */ | ||
247 | |||
248 | /* Clear Receiver User FIFO (RX USR.FIFO) */ | ||
249 | #define TEGRA_SPDIF_DATA_FIFO_CSR_RU_CLR (1 << 31) | ||
250 | |||
251 | #define TEGRA_SPDIF_FIFO_ATN_LVL_U_ONE_SLOT 0 | ||
252 | #define TEGRA_SPDIF_FIFO_ATN_LVL_U_TWO_SLOTS 1 | ||
253 | #define TEGRA_SPDIF_FIFO_ATN_LVL_U_THREE_SLOTS 2 | ||
254 | #define TEGRA_SPDIF_FIFO_ATN_LVL_U_FOUR_SLOTS 3 | ||
255 | |||
256 | /* RU FIFO attention level */ | ||
257 | #define TEGRA_SPDIF_DATA_FIFO_CSR_RU_ATN_LVL_SHIFT 29 | ||
258 | #define TEGRA_SPDIF_DATA_FIFO_CSR_RU_ATN_LVL_MASK \ | ||
259 | (0x3 << TEGRA_SPDIF_DATA_FIFO_CSR_RU_ATN_LVL_SHIFT) | ||
260 | #define TEGRA_SPDIF_DATA_FIFO_CSR_RU_ATN_LVL_RU1_WORD_FULL \ | ||
261 | (TEGRA_SPDIF_FIFO_ATN_LVL_U_ONE_SLOT << TEGRA_SPDIF_DATA_FIFO_CSR_RU_ATN_LVL_SHIFT) | ||
262 | #define TEGRA_SPDIF_DATA_FIFO_CSR_RU_ATN_LVL_RU2_WORD_FULL \ | ||
263 | (TEGRA_SPDIF_FIFO_ATN_LVL_U_TWO_SLOTS << TEGRA_SPDIF_DATA_FIFO_CSR_RU_ATN_LVL_SHIFT) | ||
264 | #define TEGRA_SPDIF_DATA_FIFO_CSR_RU_ATN_LVL_RU3_WORD_FULL \ | ||
265 | (TEGRA_SPDIF_FIFO_ATN_LVL_U_THREE_SLOTS << TEGRA_SPDIF_DATA_FIFO_CSR_RU_ATN_LVL_SHIFT) | ||
266 | #define TEGRA_SPDIF_DATA_FIFO_CSR_RU_ATN_LVL_RU4_WORD_FULL \ | ||
267 | (TEGRA_SPDIF_FIFO_ATN_LVL_U_FOUR_SLOTS << TEGRA_SPDIF_DATA_FIFO_CSR_RU_ATN_LVL_SHIFT) | ||
268 | |||
269 | /* Number of RX USR.FIFO levels with valid data. */ | ||
270 | #define TEGRA_SPDIF_DATA_FIFO_CSR_RU_FULL_COUNT_SHIFT 24 | ||
271 | #define TEGRA_SPDIF_DATA_FIFO_CSR_RU_FULL_COUNT_MASK (0x1f << TEGRA_SPDIF_DATA_FIFO_CSR_RU_FULL_COUNT_SHIFT) | ||
272 | |||
273 | /* Clear Transmitter User FIFO (TX USR.FIFO) */ | ||
274 | #define TEGRA_SPDIF_DATA_FIFO_CSR_TU_CLR (1 << 23) | ||
275 | |||
276 | /* TU FIFO attention level */ | ||
277 | #define TEGRA_SPDIF_DATA_FIFO_CSR_TU_ATN_LVL_SHIFT 21 | ||
278 | #define TEGRA_SPDIF_DATA_FIFO_CSR_TU_ATN_LVL_MASK \ | ||
279 | (0x3 << TEGRA_SPDIF_DATA_FIFO_CSR_TU_ATN_LVL_SHIFT) | ||
280 | #define TEGRA_SPDIF_DATA_FIFO_CSR_TU_ATN_LVL_TU1_WORD_FULL \ | ||
281 | (TEGRA_SPDIF_FIFO_ATN_LVL_U_ONE_SLOT << TEGRA_SPDIF_DATA_FIFO_CSR_TU_ATN_LVL_SHIFT) | ||
282 | #define TEGRA_SPDIF_DATA_FIFO_CSR_TU_ATN_LVL_TU2_WORD_FULL \ | ||
283 | (TEGRA_SPDIF_FIFO_ATN_LVL_U_TWO_SLOTS << TEGRA_SPDIF_DATA_FIFO_CSR_TU_ATN_LVL_SHIFT) | ||
284 | #define TEGRA_SPDIF_DATA_FIFO_CSR_TU_ATN_LVL_TU3_WORD_FULL \ | ||
285 | (TEGRA_SPDIF_FIFO_ATN_LVL_U_THREE_SLOTS << TEGRA_SPDIF_DATA_FIFO_CSR_TU_ATN_LVL_SHIFT) | ||
286 | #define TEGRA_SPDIF_DATA_FIFO_CSR_TU_ATN_LVL_TU4_WORD_FULL \ | ||
287 | (TEGRA_SPDIF_FIFO_ATN_LVL_U_FOUR_SLOTS << TEGRA_SPDIF_DATA_FIFO_CSR_TU_ATN_LVL_SHIFT) | ||
288 | |||
289 | /* Number of TX USR.FIFO levels that could be filled. */ | ||
290 | #define TEGRA_SPDIF_DATA_FIFO_CSR_TU_EMPTY_COUNT_SHIFT 16 | ||
291 | #define TEGRA_SPDIF_DATA_FIFO_CSR_TU_EMPTY_COUNT_MASK (0x1f << SPDIF_DATA_FIFO_CSR_TU_EMPTY_COUNT_SHIFT) | ||
292 | |||
293 | /* Clear Receiver Data FIFO (RX DATA.FIFO) */ | ||
294 | #define TEGRA_SPDIF_DATA_FIFO_CSR_RX_CLR (1 << 15) | ||
295 | |||
296 | #define TEGRA_SPDIF_FIFO_ATN_LVL_D_ONE_SLOT 0 | ||
297 | #define TEGRA_SPDIF_FIFO_ATN_LVL_D_FOUR_SLOTS 1 | ||
298 | #define TEGRA_SPDIF_FIFO_ATN_LVL_D_EIGHT_SLOTS 2 | ||
299 | #define TEGRA_SPDIF_FIFO_ATN_LVL_D_TWELVE_SLOTS 3 | ||
300 | |||
301 | /* RU FIFO attention level */ | ||
302 | #define TEGRA_SPDIF_DATA_FIFO_CSR_RX_ATN_LVL_SHIFT 13 | ||
303 | #define TEGRA_SPDIF_DATA_FIFO_CSR_RX_ATN_LVL_MASK \ | ||
304 | (0x3 << TEGRA_SPDIF_DATA_FIFO_CSR_RX_ATN_LVL_SHIFT) | ||
305 | #define TEGRA_SPDIF_DATA_FIFO_CSR_RX_ATN_LVL_RU1_WORD_FULL \ | ||
306 | (TEGRA_SPDIF_FIFO_ATN_LVL_D_ONE_SLOT << TEGRA_SPDIF_DATA_FIFO_CSR_RX_ATN_LVL_SHIFT) | ||
307 | #define TEGRA_SPDIF_DATA_FIFO_CSR_RX_ATN_LVL_RU4_WORD_FULL \ | ||
308 | (TEGRA_SPDIF_FIFO_ATN_LVL_D_FOUR_SLOTS << TEGRA_SPDIF_DATA_FIFO_CSR_RX_ATN_LVL_SHIFT) | ||
309 | #define TEGRA_SPDIF_DATA_FIFO_CSR_RX_ATN_LVL_RU8_WORD_FULL \ | ||
310 | (TEGRA_SPDIF_FIFO_ATN_LVL_D_EIGHT_SLOTS << TEGRA_SPDIF_DATA_FIFO_CSR_RX_ATN_LVL_SHIFT) | ||
311 | #define TEGRA_SPDIF_DATA_FIFO_CSR_RX_ATN_LVL_RU12_WORD_FULL \ | ||
312 | (TEGRA_SPDIF_FIFO_ATN_LVL_D_TWELVE_SLOTS << TEGRA_SPDIF_DATA_FIFO_CSR_RX_ATN_LVL_SHIFT) | ||
313 | |||
314 | /* Number of RX DATA.FIFO levels with valid data. */ | ||
315 | #define TEGRA_SPDIF_DATA_FIFO_CSR_RX_FULL_COUNT_SHIFT 8 | ||
316 | #define TEGRA_SPDIF_DATA_FIFO_CSR_RX_FULL_COUNT_MASK (0x1f << TEGRA_SPDIF_DATA_FIFO_CSR_RX_FULL_COUNT_SHIFT) | ||
317 | |||
318 | /* Clear Transmitter Data FIFO (TX DATA.FIFO) */ | ||
319 | #define TEGRA_SPDIF_DATA_FIFO_CSR_TX_CLR (1 << 7) | ||
320 | |||
321 | /* TU FIFO attention level */ | ||
322 | #define TEGRA_SPDIF_DATA_FIFO_CSR_TX_ATN_LVL_SHIFT 5 | ||
323 | #define TEGRA_SPDIF_DATA_FIFO_CSR_TX_ATN_LVL_MASK \ | ||
324 | (0x3 << TEGRA_SPDIF_DATA_FIFO_CSR_TX_ATN_LVL_SHIFT) | ||
325 | #define TEGRA_SPDIF_DATA_FIFO_CSR_TX_ATN_LVL_TU1_WORD_FULL \ | ||
326 | (TEGRA_SPDIF_FIFO_ATN_LVL_D_ONE_SLOT << TEGRA_SPDIF_DATA_FIFO_CSR_TX_ATN_LVL_SHIFT) | ||
327 | #define TEGRA_SPDIF_DATA_FIFO_CSR_TX_ATN_LVL_TU4_WORD_FULL \ | ||
328 | (TEGRA_SPDIF_FIFO_ATN_LVL_D_FOUR_SLOTS << TEGRA_SPDIF_DATA_FIFO_CSR_TX_ATN_LVL_SHIFT) | ||
329 | #define TEGRA_SPDIF_DATA_FIFO_CSR_TX_ATN_LVL_TU8_WORD_FULL \ | ||
330 | (TEGRA_SPDIF_FIFO_ATN_LVL_D_EIGHT_SLOTS << TEGRA_SPDIF_DATA_FIFO_CSR_TX_ATN_LVL_SHIFT) | ||
331 | #define TEGRA_SPDIF_DATA_FIFO_CSR_TX_ATN_LVL_TU12_WORD_FULL \ | ||
332 | (TEGRA_SPDIF_FIFO_ATN_LVL_D_TWELVE_SLOTS << TEGRA_SPDIF_DATA_FIFO_CSR_TX_ATN_LVL_SHIFT) | ||
333 | |||
334 | /* Number of TX DATA.FIFO levels that could be filled. */ | ||
335 | #define TEGRA_SPDIF_DATA_FIFO_CSR_TX_EMPTY_COUNT_SHIFT 0 | ||
336 | #define TEGRA_SPDIF_DATA_FIFO_CSR_TX_EMPTY_COUNT_MASK (0x1f << SPDIF_DATA_FIFO_CSR_TX_EMPTY_COUNT_SHIFT) | ||
337 | |||
338 | /* Fields in TEGRA_SPDIF_DATA_OUT */ | ||
339 | |||
340 | /* | ||
341 | * This register has 5 different formats: | ||
342 | * 16-bit (BIT_MODE=00, PACK=0) | ||
343 | * 20-bit (BIT_MODE=01, PACK=0) | ||
344 | * 24-bit (BIT_MODE=10, PACK=0) | ||
345 | * raw (BIT_MODE=11, PACK=0) | ||
346 | * 16-bit packed (BIT_MODE=00, PACK=1) | ||
347 | */ | ||
348 | |||
349 | #define TEGRA_SPDIF_DATA_OUT_DATA_16_SHIFT 0 | ||
350 | #define TEGRA_SPDIF_DATA_OUT_DATA_16_MASK (0xffff << TEGRA_SPDIF_DATA_OUT_DATA_16_SHIFT) | ||
351 | |||
352 | #define TEGRA_SPDIF_DATA_OUT_DATA_20_SHIFT 0 | ||
353 | #define TEGRA_SPDIF_DATA_OUT_DATA_20_MASK (0xfffff << TEGRA_SPDIF_DATA_OUT_DATA_20_SHIFT) | ||
354 | |||
355 | #define TEGRA_SPDIF_DATA_OUT_DATA_24_SHIFT 0 | ||
356 | #define TEGRA_SPDIF_DATA_OUT_DATA_24_MASK (0xffffff << TEGRA_SPDIF_DATA_OUT_DATA_24_SHIFT) | ||
357 | |||
358 | #define TEGRA_SPDIF_DATA_OUT_DATA_RAW_P (1 << 31) | ||
359 | #define TEGRA_SPDIF_DATA_OUT_DATA_RAW_C (1 << 30) | ||
360 | #define TEGRA_SPDIF_DATA_OUT_DATA_RAW_U (1 << 29) | ||
361 | #define TEGRA_SPDIF_DATA_OUT_DATA_RAW_V (1 << 28) | ||
362 | |||
363 | #define TEGRA_SPDIF_DATA_OUT_DATA_RAW_DATA_SHIFT 8 | ||
364 | #define TEGRA_SPDIF_DATA_OUT_DATA_RAW_DATA_MASK (0xfffff << TEGRA_SPDIF_DATA_OUT_DATA_RAW_DATA_SHIFT) | ||
365 | |||
366 | #define TEGRA_SPDIF_DATA_OUT_DATA_RAW_AUX_SHIFT 4 | ||
367 | #define TEGRA_SPDIF_DATA_OUT_DATA_RAW_AUX_MASK (0xf << TEGRA_SPDIF_DATA_OUT_DATA_RAW_AUX_SHIFT) | ||
368 | |||
369 | #define TEGRA_SPDIF_DATA_OUT_DATA_RAW_PREAMBLE_SHIFT 0 | ||
370 | #define TEGRA_SPDIF_DATA_OUT_DATA_RAW_PREAMBLE_MASK (0xf << TEGRA_SPDIF_DATA_OUT_DATA_RAW_PREAMBLE_SHIFT) | ||
371 | |||
372 | #define TEGRA_SPDIF_DATA_OUT_DATA_16_PACKED_RIGHT_SHIFT 16 | ||
373 | #define TEGRA_SPDIF_DATA_OUT_DATA_16_PACKED_RIGHT_MASK (0xffff << TEGRA_SPDIF_DATA_OUT_DATA_16_PACKED_RIGHT_SHIFT) | ||
374 | |||
375 | #define TEGRA_SPDIF_DATA_OUT_DATA_16_PACKED_LEFT_SHIFT 0 | ||
376 | #define TEGRA_SPDIF_DATA_OUT_DATA_16_PACKED_LEFT_MASK (0xffff << TEGRA_SPDIF_DATA_OUT_DATA_16_PACKED_LEFT_SHIFT) | ||
377 | |||
378 | /* Fields in TEGRA_SPDIF_DATA_IN */ | ||
379 | |||
380 | /* | ||
381 | * This register has 5 different formats: | ||
382 | * 16-bit (BIT_MODE=00, PACK=0) | ||
383 | * 20-bit (BIT_MODE=01, PACK=0) | ||
384 | * 24-bit (BIT_MODE=10, PACK=0) | ||
385 | * raw (BIT_MODE=11, PACK=0) | ||
386 | * 16-bit packed (BIT_MODE=00, PACK=1) | ||
387 | * | ||
388 | * Bits 31:24 are common to all modes except 16-bit packed | ||
389 | */ | ||
390 | |||
391 | #define TEGRA_SPDIF_DATA_IN_DATA_P (1 << 31) | ||
392 | #define TEGRA_SPDIF_DATA_IN_DATA_C (1 << 30) | ||
393 | #define TEGRA_SPDIF_DATA_IN_DATA_U (1 << 29) | ||
394 | #define TEGRA_SPDIF_DATA_IN_DATA_V (1 << 28) | ||
395 | |||
396 | #define TEGRA_SPDIF_DATA_IN_DATA_PREAMBLE_SHIFT 24 | ||
397 | #define TEGRA_SPDIF_DATA_IN_DATA_PREAMBLE_MASK (0xf << TEGRA_SPDIF_DATA_IN_DATA_PREAMBLE_SHIFT) | ||
398 | |||
399 | #define TEGRA_SPDIF_DATA_IN_DATA_16_SHIFT 0 | ||
400 | #define TEGRA_SPDIF_DATA_IN_DATA_16_MASK (0xffff << TEGRA_SPDIF_DATA_IN_DATA_16_SHIFT) | ||
401 | |||
402 | #define TEGRA_SPDIF_DATA_IN_DATA_20_SHIFT 0 | ||
403 | #define TEGRA_SPDIF_DATA_IN_DATA_20_MASK (0xfffff << TEGRA_SPDIF_DATA_IN_DATA_20_SHIFT) | ||
404 | |||
405 | #define TEGRA_SPDIF_DATA_IN_DATA_24_SHIFT 0 | ||
406 | #define TEGRA_SPDIF_DATA_IN_DATA_24_MASK (0xffffff << TEGRA_SPDIF_DATA_IN_DATA_24_SHIFT) | ||
407 | |||
408 | #define TEGRA_SPDIF_DATA_IN_DATA_RAW_DATA_SHIFT 8 | ||
409 | #define TEGRA_SPDIF_DATA_IN_DATA_RAW_DATA_MASK (0xfffff << TEGRA_SPDIF_DATA_IN_DATA_RAW_DATA_SHIFT) | ||
410 | |||
411 | #define TEGRA_SPDIF_DATA_IN_DATA_RAW_AUX_SHIFT 4 | ||
412 | #define TEGRA_SPDIF_DATA_IN_DATA_RAW_AUX_MASK (0xf << TEGRA_SPDIF_DATA_IN_DATA_RAW_AUX_SHIFT) | ||
413 | |||
414 | #define TEGRA_SPDIF_DATA_IN_DATA_RAW_PREAMBLE_SHIFT 0 | ||
415 | #define TEGRA_SPDIF_DATA_IN_DATA_RAW_PREAMBLE_MASK (0xf << TEGRA_SPDIF_DATA_IN_DATA_RAW_PREAMBLE_SHIFT) | ||
416 | |||
417 | #define TEGRA_SPDIF_DATA_IN_DATA_16_PACKED_RIGHT_SHIFT 16 | ||
418 | #define TEGRA_SPDIF_DATA_IN_DATA_16_PACKED_RIGHT_MASK (0xffff << TEGRA_SPDIF_DATA_IN_DATA_16_PACKED_RIGHT_SHIFT) | ||
419 | |||
420 | #define TEGRA_SPDIF_DATA_IN_DATA_16_PACKED_LEFT_SHIFT 0 | ||
421 | #define TEGRA_SPDIF_DATA_IN_DATA_16_PACKED_LEFT_MASK (0xffff << TEGRA_SPDIF_DATA_IN_DATA_16_PACKED_LEFT_SHIFT) | ||
422 | |||
423 | /* Fields in TEGRA_SPDIF_CH_STA_RX_A */ | ||
424 | /* Fields in TEGRA_SPDIF_CH_STA_RX_B */ | ||
425 | /* Fields in TEGRA_SPDIF_CH_STA_RX_C */ | ||
426 | /* Fields in TEGRA_SPDIF_CH_STA_RX_D */ | ||
427 | /* Fields in TEGRA_SPDIF_CH_STA_RX_E */ | ||
428 | /* Fields in TEGRA_SPDIF_CH_STA_RX_F */ | ||
429 | |||
430 | /* | ||
431 | * The 6-word receive channel data page buffer holds a block (192 frames) of | ||
432 | * channel status information. The order of receive is from LSB to MSB | ||
433 | * bit, and from CH_STA_RX_A to CH_STA_RX_F then back to CH_STA_RX_A. | ||
434 | */ | ||
435 | |||
436 | /* Fields in TEGRA_SPDIF_CH_STA_TX_A */ | ||
437 | /* Fields in TEGRA_SPDIF_CH_STA_TX_B */ | ||
438 | /* Fields in TEGRA_SPDIF_CH_STA_TX_C */ | ||
439 | /* Fields in TEGRA_SPDIF_CH_STA_TX_D */ | ||
440 | /* Fields in TEGRA_SPDIF_CH_STA_TX_E */ | ||
441 | /* Fields in TEGRA_SPDIF_CH_STA_TX_F */ | ||
442 | |||
443 | /* | ||
444 | * The 6-word transmit channel data page buffer holds a block (192 frames) of | ||
445 | * channel status information. The order of transmission is from LSB to MSB | ||
446 | * bit, and from CH_STA_TX_A to CH_STA_TX_F then back to CH_STA_TX_A. | ||
447 | */ | ||
448 | |||
449 | /* Fields in TEGRA_SPDIF_USR_STA_RX_A */ | ||
450 | |||
451 | /* | ||
452 | * This 4-word deep FIFO receives user FIFO field information. The order of | ||
453 | * receive is from LSB to MSB bit. | ||
454 | */ | ||
455 | |||
456 | /* Fields in TEGRA_SPDIF_USR_DAT_TX_A */ | ||
457 | |||
458 | /* | ||
459 | * This 4-word deep FIFO transmits user FIFO field information. The order of | ||
460 | * transmission is from LSB to MSB bit. | ||
461 | */ | ||
462 | |||
463 | struct tegra_spdif { | ||
464 | struct clk *clk_spdif_out; | ||
465 | int clk_refs; | ||
466 | struct tegra_pcm_dma_params capture_dma_data; | ||
467 | struct tegra_pcm_dma_params playback_dma_data; | ||
468 | void __iomem *regs; | ||
469 | struct dentry *debug; | ||
470 | u32 reg_ctrl; | ||
471 | }; | ||
472 | |||
473 | #endif | ||
diff --git a/sound/soc/tegra/tegra_wm8753.c b/sound/soc/tegra/tegra_wm8753.c new file mode 100644 index 000000000000..4e77026807a2 --- /dev/null +++ b/sound/soc/tegra/tegra_wm8753.c | |||
@@ -0,0 +1,224 @@ | |||
1 | /* | ||
2 | * tegra_wm8753.c - Tegra machine ASoC driver for boards using WM8753 codec. | ||
3 | * | ||
4 | * Author: Stephen Warren <swarren@nvidia.com> | ||
5 | * Copyright (C) 2010-2012 - NVIDIA, Inc. | ||
6 | * | ||
7 | * Based on code copyright/by: | ||
8 | * | ||
9 | * (c) 2009, 2010 Nvidia Graphics Pvt. Ltd. | ||
10 | * | ||
11 | * Copyright 2007 Wolfson Microelectronics PLC. | ||
12 | * Author: Graeme Gregory | ||
13 | * graeme.gregory@wolfsonmicro.com or linux@wolfsonmicro.com | ||
14 | * | ||
15 | * This program is free software; you can redistribute it and/or | ||
16 | * modify it under the terms of the GNU General Public License | ||
17 | * version 2 as published by the Free Software Foundation. | ||
18 | * | ||
19 | * This program is distributed in the hope that it will be useful, but | ||
20 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
22 | * General Public License for more details. | ||
23 | * | ||
24 | * You should have received a copy of the GNU General Public License | ||
25 | * along with this program; if not, write to the Free Software | ||
26 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
27 | * 02110-1301 USA | ||
28 | * | ||
29 | */ | ||
30 | |||
31 | #include <asm/mach-types.h> | ||
32 | |||
33 | #include <linux/module.h> | ||
34 | #include <linux/platform_device.h> | ||
35 | #include <linux/slab.h> | ||
36 | #include <linux/gpio.h> | ||
37 | #include <linux/of_gpio.h> | ||
38 | |||
39 | #include <sound/core.h> | ||
40 | #include <sound/jack.h> | ||
41 | #include <sound/pcm.h> | ||
42 | #include <sound/pcm_params.h> | ||
43 | #include <sound/soc.h> | ||
44 | |||
45 | #include "../codecs/wm8753.h" | ||
46 | |||
47 | #include "tegra_asoc_utils.h" | ||
48 | |||
49 | #define DRV_NAME "tegra-snd-wm8753" | ||
50 | |||
51 | struct tegra_wm8753 { | ||
52 | struct tegra_asoc_utils_data util_data; | ||
53 | }; | ||
54 | |||
55 | static int tegra_wm8753_hw_params(struct snd_pcm_substream *substream, | ||
56 | struct snd_pcm_hw_params *params) | ||
57 | { | ||
58 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
59 | struct snd_soc_dai *codec_dai = rtd->codec_dai; | ||
60 | struct snd_soc_codec *codec = rtd->codec; | ||
61 | struct snd_soc_card *card = codec->card; | ||
62 | struct tegra_wm8753 *machine = snd_soc_card_get_drvdata(card); | ||
63 | int srate, mclk; | ||
64 | int err; | ||
65 | |||
66 | srate = params_rate(params); | ||
67 | switch (srate) { | ||
68 | case 11025: | ||
69 | case 22050: | ||
70 | case 44100: | ||
71 | case 88200: | ||
72 | mclk = 11289600; | ||
73 | break; | ||
74 | default: | ||
75 | mclk = 12288000; | ||
76 | break; | ||
77 | } | ||
78 | |||
79 | err = tegra_asoc_utils_set_rate(&machine->util_data, srate, mclk); | ||
80 | if (err < 0) { | ||
81 | dev_err(card->dev, "Can't configure clocks\n"); | ||
82 | return err; | ||
83 | } | ||
84 | |||
85 | err = snd_soc_dai_set_sysclk(codec_dai, WM8753_MCLK, mclk, | ||
86 | SND_SOC_CLOCK_IN); | ||
87 | if (err < 0) { | ||
88 | dev_err(card->dev, "codec_dai clock not set\n"); | ||
89 | return err; | ||
90 | } | ||
91 | |||
92 | return 0; | ||
93 | } | ||
94 | |||
95 | static struct snd_soc_ops tegra_wm8753_ops = { | ||
96 | .hw_params = tegra_wm8753_hw_params, | ||
97 | }; | ||
98 | |||
99 | static const struct snd_soc_dapm_widget tegra_wm8753_dapm_widgets[] = { | ||
100 | SND_SOC_DAPM_HP("Headphone Jack", NULL), | ||
101 | SND_SOC_DAPM_MIC("Mic Jack", NULL), | ||
102 | }; | ||
103 | |||
104 | static struct snd_soc_dai_link tegra_wm8753_dai = { | ||
105 | .name = "WM8753", | ||
106 | .stream_name = "WM8753 PCM", | ||
107 | .codec_dai_name = "wm8753-hifi", | ||
108 | .ops = &tegra_wm8753_ops, | ||
109 | .dai_fmt = SND_SOC_DAIFMT_I2S | | ||
110 | SND_SOC_DAIFMT_NB_NF | | ||
111 | SND_SOC_DAIFMT_CBS_CFS, | ||
112 | }; | ||
113 | |||
114 | static struct snd_soc_card snd_soc_tegra_wm8753 = { | ||
115 | .name = "tegra-wm8753", | ||
116 | .owner = THIS_MODULE, | ||
117 | .dai_link = &tegra_wm8753_dai, | ||
118 | .num_links = 1, | ||
119 | |||
120 | .dapm_widgets = tegra_wm8753_dapm_widgets, | ||
121 | .num_dapm_widgets = ARRAY_SIZE(tegra_wm8753_dapm_widgets), | ||
122 | .fully_routed = true, | ||
123 | }; | ||
124 | |||
125 | static __devinit int tegra_wm8753_driver_probe(struct platform_device *pdev) | ||
126 | { | ||
127 | struct snd_soc_card *card = &snd_soc_tegra_wm8753; | ||
128 | struct tegra_wm8753 *machine; | ||
129 | int ret; | ||
130 | |||
131 | machine = devm_kzalloc(&pdev->dev, sizeof(struct tegra_wm8753), | ||
132 | GFP_KERNEL); | ||
133 | if (!machine) { | ||
134 | dev_err(&pdev->dev, "Can't allocate tegra_wm8753 struct\n"); | ||
135 | ret = -ENOMEM; | ||
136 | goto err; | ||
137 | } | ||
138 | |||
139 | card->dev = &pdev->dev; | ||
140 | platform_set_drvdata(pdev, card); | ||
141 | snd_soc_card_set_drvdata(card, machine); | ||
142 | |||
143 | ret = snd_soc_of_parse_card_name(card, "nvidia,model"); | ||
144 | if (ret) | ||
145 | goto err; | ||
146 | |||
147 | ret = snd_soc_of_parse_audio_routing(card, "nvidia,audio-routing"); | ||
148 | if (ret) | ||
149 | goto err; | ||
150 | |||
151 | tegra_wm8753_dai.codec_of_node = of_parse_phandle( | ||
152 | pdev->dev.of_node, "nvidia,audio-codec", 0); | ||
153 | if (!tegra_wm8753_dai.codec_of_node) { | ||
154 | dev_err(&pdev->dev, | ||
155 | "Property 'nvidia,audio-codec' missing or invalid\n"); | ||
156 | ret = -EINVAL; | ||
157 | goto err; | ||
158 | } | ||
159 | |||
160 | tegra_wm8753_dai.cpu_dai_of_node = of_parse_phandle( | ||
161 | pdev->dev.of_node, "nvidia,i2s-controller", 0); | ||
162 | if (!tegra_wm8753_dai.cpu_dai_of_node) { | ||
163 | dev_err(&pdev->dev, | ||
164 | "Property 'nvidia,i2s-controller' missing or invalid\n"); | ||
165 | ret = -EINVAL; | ||
166 | goto err; | ||
167 | } | ||
168 | |||
169 | tegra_wm8753_dai.platform_of_node = | ||
170 | tegra_wm8753_dai.cpu_dai_of_node; | ||
171 | |||
172 | ret = tegra_asoc_utils_init(&machine->util_data, &pdev->dev); | ||
173 | if (ret) | ||
174 | goto err; | ||
175 | |||
176 | ret = snd_soc_register_card(card); | ||
177 | if (ret) { | ||
178 | dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", | ||
179 | ret); | ||
180 | goto err_fini_utils; | ||
181 | } | ||
182 | |||
183 | return 0; | ||
184 | |||
185 | err_fini_utils: | ||
186 | tegra_asoc_utils_fini(&machine->util_data); | ||
187 | err: | ||
188 | return ret; | ||
189 | } | ||
190 | |||
191 | static int __devexit tegra_wm8753_driver_remove(struct platform_device *pdev) | ||
192 | { | ||
193 | struct snd_soc_card *card = platform_get_drvdata(pdev); | ||
194 | struct tegra_wm8753 *machine = snd_soc_card_get_drvdata(card); | ||
195 | |||
196 | snd_soc_unregister_card(card); | ||
197 | |||
198 | tegra_asoc_utils_fini(&machine->util_data); | ||
199 | |||
200 | return 0; | ||
201 | } | ||
202 | |||
203 | static const struct of_device_id tegra_wm8753_of_match[] __devinitconst = { | ||
204 | { .compatible = "nvidia,tegra-audio-wm8753", }, | ||
205 | {}, | ||
206 | }; | ||
207 | |||
208 | static struct platform_driver tegra_wm8753_driver = { | ||
209 | .driver = { | ||
210 | .name = DRV_NAME, | ||
211 | .owner = THIS_MODULE, | ||
212 | .pm = &snd_soc_pm_ops, | ||
213 | .of_match_table = tegra_wm8753_of_match, | ||
214 | }, | ||
215 | .probe = tegra_wm8753_driver_probe, | ||
216 | .remove = __devexit_p(tegra_wm8753_driver_remove), | ||
217 | }; | ||
218 | module_platform_driver(tegra_wm8753_driver); | ||
219 | |||
220 | MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>"); | ||
221 | MODULE_DESCRIPTION("Tegra+WM8753 machine ASoC driver"); | ||
222 | MODULE_LICENSE("GPL"); | ||
223 | MODULE_ALIAS("platform:" DRV_NAME); | ||
224 | MODULE_DEVICE_TABLE(of, tegra_wm8753_of_match); | ||
diff --git a/sound/soc/tegra/tegra_wm8903.c b/sound/soc/tegra/tegra_wm8903.c index 566655e23b7d..0b0df49d9d33 100644 --- a/sound/soc/tegra/tegra_wm8903.c +++ b/sound/soc/tegra/tegra_wm8903.c | |||
@@ -2,7 +2,7 @@ | |||
2 | * tegra_wm8903.c - Tegra machine ASoC driver for boards using WM8903 codec. | 2 | * tegra_wm8903.c - Tegra machine ASoC driver for boards using WM8903 codec. |
3 | * | 3 | * |
4 | * Author: Stephen Warren <swarren@nvidia.com> | 4 | * Author: Stephen Warren <swarren@nvidia.com> |
5 | * Copyright (C) 2010-2011 - NVIDIA, Inc. | 5 | * Copyright (C) 2010-2012 - NVIDIA, Inc. |
6 | * | 6 | * |
7 | * Based on code copyright/by: | 7 | * Based on code copyright/by: |
8 | * | 8 | * |
@@ -46,9 +46,6 @@ | |||
46 | 46 | ||
47 | #include "../codecs/wm8903.h" | 47 | #include "../codecs/wm8903.h" |
48 | 48 | ||
49 | #include "tegra_das.h" | ||
50 | #include "tegra_i2s.h" | ||
51 | #include "tegra_pcm.h" | ||
52 | #include "tegra_asoc_utils.h" | 49 | #include "tegra_asoc_utils.h" |
53 | 50 | ||
54 | #define DRV_NAME "tegra-snd-wm8903" | 51 | #define DRV_NAME "tegra-snd-wm8903" |
@@ -61,7 +58,6 @@ | |||
61 | 58 | ||
62 | struct tegra_wm8903 { | 59 | struct tegra_wm8903 { |
63 | struct tegra_wm8903_platform_data pdata; | 60 | struct tegra_wm8903_platform_data pdata; |
64 | struct platform_device *pcm_dev; | ||
65 | struct tegra_asoc_utils_data util_data; | 61 | struct tegra_asoc_utils_data util_data; |
66 | int gpio_requested; | 62 | int gpio_requested; |
67 | }; | 63 | }; |
@@ -354,8 +350,8 @@ static struct snd_soc_dai_link tegra_wm8903_dai = { | |||
354 | .name = "WM8903", | 350 | .name = "WM8903", |
355 | .stream_name = "WM8903 PCM", | 351 | .stream_name = "WM8903 PCM", |
356 | .codec_name = "wm8903.0-001a", | 352 | .codec_name = "wm8903.0-001a", |
357 | .platform_name = "tegra-pcm-audio", | 353 | .platform_name = "tegra20-i2s.0", |
358 | .cpu_dai_name = "tegra-i2s.0", | 354 | .cpu_dai_name = "tegra20-i2s.0", |
359 | .codec_dai_name = "wm8903-hifi", | 355 | .codec_dai_name = "wm8903-hifi", |
360 | .init = tegra_wm8903_init, | 356 | .init = tegra_wm8903_init, |
361 | .ops = &tegra_wm8903_ops, | 357 | .ops = &tegra_wm8903_ops, |
@@ -392,7 +388,6 @@ static __devinit int tegra_wm8903_driver_probe(struct platform_device *pdev) | |||
392 | ret = -ENOMEM; | 388 | ret = -ENOMEM; |
393 | goto err; | 389 | goto err; |
394 | } | 390 | } |
395 | machine->pcm_dev = ERR_PTR(-EINVAL); | ||
396 | 391 | ||
397 | card->dev = &pdev->dev; | 392 | card->dev = &pdev->dev; |
398 | platform_set_drvdata(pdev, card); | 393 | platform_set_drvdata(pdev, card); |
@@ -428,14 +423,9 @@ static __devinit int tegra_wm8903_driver_probe(struct platform_device *pdev) | |||
428 | goto err; | 423 | goto err; |
429 | } | 424 | } |
430 | 425 | ||
431 | machine->pcm_dev = platform_device_register_simple( | 426 | tegra_wm8903_dai.platform_name = NULL; |
432 | "tegra-pcm-audio", -1, NULL, 0); | 427 | tegra_wm8903_dai.platform_of_node = |
433 | if (IS_ERR(machine->pcm_dev)) { | 428 | tegra_wm8903_dai.cpu_dai_of_node; |
434 | dev_err(&pdev->dev, | ||
435 | "Can't instantiate tegra-pcm-audio\n"); | ||
436 | ret = PTR_ERR(machine->pcm_dev); | ||
437 | goto err; | ||
438 | } | ||
439 | } else { | 429 | } else { |
440 | if (machine_is_harmony()) { | 430 | if (machine_is_harmony()) { |
441 | card->dapm_routes = harmony_audio_map; | 431 | card->dapm_routes = harmony_audio_map; |
@@ -454,7 +444,7 @@ static __devinit int tegra_wm8903_driver_probe(struct platform_device *pdev) | |||
454 | 444 | ||
455 | ret = tegra_asoc_utils_init(&machine->util_data, &pdev->dev); | 445 | ret = tegra_asoc_utils_init(&machine->util_data, &pdev->dev); |
456 | if (ret) | 446 | if (ret) |
457 | goto err_unregister; | 447 | goto err; |
458 | 448 | ||
459 | ret = snd_soc_register_card(card); | 449 | ret = snd_soc_register_card(card); |
460 | if (ret) { | 450 | if (ret) { |
@@ -467,9 +457,6 @@ static __devinit int tegra_wm8903_driver_probe(struct platform_device *pdev) | |||
467 | 457 | ||
468 | err_fini_utils: | 458 | err_fini_utils: |
469 | tegra_asoc_utils_fini(&machine->util_data); | 459 | tegra_asoc_utils_fini(&machine->util_data); |
470 | err_unregister: | ||
471 | if (!IS_ERR(machine->pcm_dev)) | ||
472 | platform_device_unregister(machine->pcm_dev); | ||
473 | err: | 460 | err: |
474 | return ret; | 461 | return ret; |
475 | } | 462 | } |
@@ -497,8 +484,6 @@ static int __devexit tegra_wm8903_driver_remove(struct platform_device *pdev) | |||
497 | snd_soc_unregister_card(card); | 484 | snd_soc_unregister_card(card); |
498 | 485 | ||
499 | tegra_asoc_utils_fini(&machine->util_data); | 486 | tegra_asoc_utils_fini(&machine->util_data); |
500 | if (!IS_ERR(machine->pcm_dev)) | ||
501 | platform_device_unregister(machine->pcm_dev); | ||
502 | 487 | ||
503 | return 0; | 488 | return 0; |
504 | } | 489 | } |
diff --git a/sound/soc/tegra/trimslice.c b/sound/soc/tegra/trimslice.c index 2bdfc550cff8..4a8d5b672c9f 100644 --- a/sound/soc/tegra/trimslice.c +++ b/sound/soc/tegra/trimslice.c | |||
@@ -27,6 +27,7 @@ | |||
27 | #include <asm/mach-types.h> | 27 | #include <asm/mach-types.h> |
28 | 28 | ||
29 | #include <linux/module.h> | 29 | #include <linux/module.h> |
30 | #include <linux/of.h> | ||
30 | #include <linux/platform_device.h> | 31 | #include <linux/platform_device.h> |
31 | #include <linux/slab.h> | 32 | #include <linux/slab.h> |
32 | 33 | ||
@@ -38,9 +39,6 @@ | |||
38 | 39 | ||
39 | #include "../codecs/tlv320aic23.h" | 40 | #include "../codecs/tlv320aic23.h" |
40 | 41 | ||
41 | #include "tegra_das.h" | ||
42 | #include "tegra_i2s.h" | ||
43 | #include "tegra_pcm.h" | ||
44 | #include "tegra_asoc_utils.h" | 42 | #include "tegra_asoc_utils.h" |
45 | 43 | ||
46 | #define DRV_NAME "tegra-snd-trimslice" | 44 | #define DRV_NAME "tegra-snd-trimslice" |
@@ -119,8 +117,8 @@ static struct snd_soc_dai_link trimslice_tlv320aic23_dai = { | |||
119 | .name = "TLV320AIC23", | 117 | .name = "TLV320AIC23", |
120 | .stream_name = "AIC23", | 118 | .stream_name = "AIC23", |
121 | .codec_name = "tlv320aic23-codec.2-001a", | 119 | .codec_name = "tlv320aic23-codec.2-001a", |
122 | .platform_name = "tegra-pcm-audio", | 120 | .platform_name = "tegra20-i2s.0", |
123 | .cpu_dai_name = "tegra-i2s.0", | 121 | .cpu_dai_name = "tegra20-i2s.0", |
124 | .codec_dai_name = "tlv320aic23-hifi", | 122 | .codec_dai_name = "tlv320aic23-hifi", |
125 | .ops = &trimslice_asoc_ops, | 123 | .ops = &trimslice_asoc_ops, |
126 | }; | 124 | }; |
@@ -152,6 +150,32 @@ static __devinit int tegra_snd_trimslice_probe(struct platform_device *pdev) | |||
152 | goto err; | 150 | goto err; |
153 | } | 151 | } |
154 | 152 | ||
153 | if (pdev->dev.of_node) { | ||
154 | trimslice_tlv320aic23_dai.codec_name = NULL; | ||
155 | trimslice_tlv320aic23_dai.codec_of_node = of_parse_phandle( | ||
156 | pdev->dev.of_node, "nvidia,audio-codec", 0); | ||
157 | if (!trimslice_tlv320aic23_dai.codec_of_node) { | ||
158 | dev_err(&pdev->dev, | ||
159 | "Property 'nvidia,audio-codec' missing or invalid\n"); | ||
160 | ret = -EINVAL; | ||
161 | goto err; | ||
162 | } | ||
163 | |||
164 | trimslice_tlv320aic23_dai.cpu_dai_name = NULL; | ||
165 | trimslice_tlv320aic23_dai.cpu_dai_of_node = of_parse_phandle( | ||
166 | pdev->dev.of_node, "nvidia,i2s-controller", 0); | ||
167 | if (!trimslice_tlv320aic23_dai.cpu_dai_of_node) { | ||
168 | dev_err(&pdev->dev, | ||
169 | "Property 'nvidia,i2s-controller' missing or invalid\n"); | ||
170 | ret = -EINVAL; | ||
171 | goto err; | ||
172 | } | ||
173 | |||
174 | trimslice_tlv320aic23_dai.platform_name = NULL; | ||
175 | trimslice_tlv320aic23_dai.platform_of_node = | ||
176 | trimslice_tlv320aic23_dai.cpu_dai_of_node; | ||
177 | } | ||
178 | |||
155 | ret = tegra_asoc_utils_init(&trimslice->util_data, &pdev->dev); | 179 | ret = tegra_asoc_utils_init(&trimslice->util_data, &pdev->dev); |
156 | if (ret) | 180 | if (ret) |
157 | goto err; | 181 | goto err; |
@@ -187,10 +211,17 @@ static int __devexit tegra_snd_trimslice_remove(struct platform_device *pdev) | |||
187 | return 0; | 211 | return 0; |
188 | } | 212 | } |
189 | 213 | ||
214 | static const struct of_device_id trimslice_of_match[] __devinitconst = { | ||
215 | { .compatible = "nvidia,tegra-audio-trimslice", }, | ||
216 | {}, | ||
217 | }; | ||
218 | MODULE_DEVICE_TABLE(of, trimslice_of_match); | ||
219 | |||
190 | static struct platform_driver tegra_snd_trimslice_driver = { | 220 | static struct platform_driver tegra_snd_trimslice_driver = { |
191 | .driver = { | 221 | .driver = { |
192 | .name = DRV_NAME, | 222 | .name = DRV_NAME, |
193 | .owner = THIS_MODULE, | 223 | .owner = THIS_MODULE, |
224 | .of_match_table = trimslice_of_match, | ||
194 | }, | 225 | }, |
195 | .probe = tegra_snd_trimslice_probe, | 226 | .probe = tegra_snd_trimslice_probe, |
196 | .remove = __devexit_p(tegra_snd_trimslice_remove), | 227 | .remove = __devexit_p(tegra_snd_trimslice_remove), |
diff --git a/sound/soc/ux500/Kconfig b/sound/soc/ux500/Kconfig new file mode 100644 index 000000000000..44cf43404cd9 --- /dev/null +++ b/sound/soc/ux500/Kconfig | |||
@@ -0,0 +1,14 @@ | |||
1 | # | ||
2 | # Ux500 SoC audio configuration | ||
3 | # | ||
4 | menuconfig SND_SOC_UX500 | ||
5 | tristate "SoC Audio support for Ux500 platform" | ||
6 | depends on SND_SOC | ||
7 | depends on MFD_DB8500_PRCMU | ||
8 | help | ||
9 | Say Y if you want to enable ASoC-support for | ||
10 | any of the Ux500 platforms (e.g. U8500). | ||
11 | |||
12 | config SND_SOC_UX500_PLAT_MSP_I2S | ||
13 | tristate | ||
14 | depends on SND_SOC_UX500 | ||
diff --git a/sound/soc/ux500/Makefile b/sound/soc/ux500/Makefile new file mode 100644 index 000000000000..19974c5a2ea1 --- /dev/null +++ b/sound/soc/ux500/Makefile | |||
@@ -0,0 +1,4 @@ | |||
1 | # Ux500 Platform Support | ||
2 | |||
3 | snd-soc-ux500-plat-msp-i2s-objs := ux500_msp_dai.o ux500_msp_i2s.o | ||
4 | obj-$(CONFIG_SND_SOC_UX500_PLAT_MSP_I2S) += snd-soc-ux500-plat-msp-i2s.o | ||
diff --git a/sound/soc/ux500/ux500_msp_dai.c b/sound/soc/ux500/ux500_msp_dai.c new file mode 100644 index 000000000000..93c6c40e724c --- /dev/null +++ b/sound/soc/ux500/ux500_msp_dai.c | |||
@@ -0,0 +1,843 @@ | |||
1 | /* | ||
2 | * Copyright (C) ST-Ericsson SA 2012 | ||
3 | * | ||
4 | * Author: Ola Lilja <ola.o.lilja@stericsson.com>, | ||
5 | * Roger Nilsson <roger.xr.nilsson@stericsson.com> | ||
6 | * for ST-Ericsson. | ||
7 | * | ||
8 | * License terms: | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or modify | ||
11 | * it under the terms of the GNU General Public License version 2 as published | ||
12 | * by the Free Software Foundation. | ||
13 | */ | ||
14 | |||
15 | #include <linux/module.h> | ||
16 | #include <linux/slab.h> | ||
17 | #include <linux/bitops.h> | ||
18 | #include <linux/platform_device.h> | ||
19 | #include <linux/clk.h> | ||
20 | #include <linux/regulator/consumer.h> | ||
21 | #include <linux/mfd/dbx500-prcmu.h> | ||
22 | |||
23 | #include <mach/hardware.h> | ||
24 | #include <mach/board-mop500-msp.h> | ||
25 | |||
26 | #include <sound/soc.h> | ||
27 | #include <sound/soc-dai.h> | ||
28 | |||
29 | #include "ux500_msp_i2s.h" | ||
30 | #include "ux500_msp_dai.h" | ||
31 | |||
32 | static int setup_pcm_multichan(struct snd_soc_dai *dai, | ||
33 | struct ux500_msp_config *msp_config) | ||
34 | { | ||
35 | struct ux500_msp_i2s_drvdata *drvdata = dev_get_drvdata(dai->dev); | ||
36 | struct msp_multichannel_config *multi = | ||
37 | &msp_config->multichannel_config; | ||
38 | |||
39 | if (drvdata->slots > 1) { | ||
40 | msp_config->multichannel_configured = 1; | ||
41 | |||
42 | multi->tx_multichannel_enable = true; | ||
43 | multi->rx_multichannel_enable = true; | ||
44 | multi->rx_comparison_enable_mode = MSP_COMPARISON_DISABLED; | ||
45 | |||
46 | multi->tx_channel_0_enable = drvdata->tx_mask; | ||
47 | multi->tx_channel_1_enable = 0; | ||
48 | multi->tx_channel_2_enable = 0; | ||
49 | multi->tx_channel_3_enable = 0; | ||
50 | |||
51 | multi->rx_channel_0_enable = drvdata->rx_mask; | ||
52 | multi->rx_channel_1_enable = 0; | ||
53 | multi->rx_channel_2_enable = 0; | ||
54 | multi->rx_channel_3_enable = 0; | ||
55 | |||
56 | dev_dbg(dai->dev, | ||
57 | "%s: Multichannel enabled. Slots: %d, TX: %u, RX: %u\n", | ||
58 | __func__, drvdata->slots, multi->tx_channel_0_enable, | ||
59 | multi->rx_channel_0_enable); | ||
60 | } | ||
61 | |||
62 | return 0; | ||
63 | } | ||
64 | |||
65 | static int setup_frameper(struct snd_soc_dai *dai, unsigned int rate, | ||
66 | struct msp_protdesc *prot_desc) | ||
67 | { | ||
68 | struct ux500_msp_i2s_drvdata *drvdata = dev_get_drvdata(dai->dev); | ||
69 | |||
70 | switch (drvdata->slots) { | ||
71 | case 1: | ||
72 | switch (rate) { | ||
73 | case 8000: | ||
74 | prot_desc->frame_period = | ||
75 | FRAME_PER_SINGLE_SLOT_8_KHZ; | ||
76 | break; | ||
77 | |||
78 | case 16000: | ||
79 | prot_desc->frame_period = | ||
80 | FRAME_PER_SINGLE_SLOT_16_KHZ; | ||
81 | break; | ||
82 | |||
83 | case 44100: | ||
84 | prot_desc->frame_period = | ||
85 | FRAME_PER_SINGLE_SLOT_44_1_KHZ; | ||
86 | break; | ||
87 | |||
88 | case 48000: | ||
89 | prot_desc->frame_period = | ||
90 | FRAME_PER_SINGLE_SLOT_48_KHZ; | ||
91 | break; | ||
92 | |||
93 | default: | ||
94 | dev_err(dai->dev, | ||
95 | "%s: Error: Unsupported sample-rate (freq = %d)!\n", | ||
96 | __func__, rate); | ||
97 | return -EINVAL; | ||
98 | } | ||
99 | break; | ||
100 | |||
101 | case 2: | ||
102 | prot_desc->frame_period = FRAME_PER_2_SLOTS; | ||
103 | break; | ||
104 | |||
105 | case 8: | ||
106 | prot_desc->frame_period = FRAME_PER_8_SLOTS; | ||
107 | break; | ||
108 | |||
109 | case 16: | ||
110 | prot_desc->frame_period = FRAME_PER_16_SLOTS; | ||
111 | break; | ||
112 | default: | ||
113 | dev_err(dai->dev, | ||
114 | "%s: Error: Unsupported slot-count (slots = %d)!\n", | ||
115 | __func__, drvdata->slots); | ||
116 | return -EINVAL; | ||
117 | } | ||
118 | |||
119 | prot_desc->clocks_per_frame = | ||
120 | prot_desc->frame_period+1; | ||
121 | |||
122 | dev_dbg(dai->dev, "%s: Clocks per frame: %u\n", | ||
123 | __func__, | ||
124 | prot_desc->clocks_per_frame); | ||
125 | |||
126 | return 0; | ||
127 | } | ||
128 | |||
129 | static int setup_pcm_framing(struct snd_soc_dai *dai, unsigned int rate, | ||
130 | struct msp_protdesc *prot_desc) | ||
131 | { | ||
132 | struct ux500_msp_i2s_drvdata *drvdata = dev_get_drvdata(dai->dev); | ||
133 | |||
134 | u32 frame_length = MSP_FRAME_LEN_1; | ||
135 | prot_desc->frame_width = 0; | ||
136 | |||
137 | switch (drvdata->slots) { | ||
138 | case 1: | ||
139 | frame_length = MSP_FRAME_LEN_1; | ||
140 | break; | ||
141 | |||
142 | case 2: | ||
143 | frame_length = MSP_FRAME_LEN_2; | ||
144 | break; | ||
145 | |||
146 | case 8: | ||
147 | frame_length = MSP_FRAME_LEN_8; | ||
148 | break; | ||
149 | |||
150 | case 16: | ||
151 | frame_length = MSP_FRAME_LEN_16; | ||
152 | break; | ||
153 | default: | ||
154 | dev_err(dai->dev, | ||
155 | "%s: Error: Unsupported slot-count (slots = %d)!\n", | ||
156 | __func__, drvdata->slots); | ||
157 | return -EINVAL; | ||
158 | } | ||
159 | |||
160 | prot_desc->tx_frame_len_1 = frame_length; | ||
161 | prot_desc->rx_frame_len_1 = frame_length; | ||
162 | prot_desc->tx_frame_len_2 = frame_length; | ||
163 | prot_desc->rx_frame_len_2 = frame_length; | ||
164 | |||
165 | prot_desc->tx_elem_len_1 = MSP_ELEM_LEN_16; | ||
166 | prot_desc->rx_elem_len_1 = MSP_ELEM_LEN_16; | ||
167 | prot_desc->tx_elem_len_2 = MSP_ELEM_LEN_16; | ||
168 | prot_desc->rx_elem_len_2 = MSP_ELEM_LEN_16; | ||
169 | |||
170 | return setup_frameper(dai, rate, prot_desc); | ||
171 | } | ||
172 | |||
173 | static int setup_clocking(struct snd_soc_dai *dai, | ||
174 | unsigned int fmt, | ||
175 | struct ux500_msp_config *msp_config) | ||
176 | { | ||
177 | switch (fmt & SND_SOC_DAIFMT_INV_MASK) { | ||
178 | case SND_SOC_DAIFMT_NB_NF: | ||
179 | break; | ||
180 | |||
181 | case SND_SOC_DAIFMT_NB_IF: | ||
182 | msp_config->tx_fsync_pol ^= 1 << TFSPOL_SHIFT; | ||
183 | msp_config->rx_fsync_pol ^= 1 << RFSPOL_SHIFT; | ||
184 | |||
185 | break; | ||
186 | |||
187 | default: | ||
188 | dev_err(dai->dev, | ||
189 | "%s: Error: Unsopported inversion (fmt = 0x%x)!\n", | ||
190 | __func__, fmt); | ||
191 | |||
192 | return -EINVAL; | ||
193 | } | ||
194 | |||
195 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { | ||
196 | case SND_SOC_DAIFMT_CBM_CFM: | ||
197 | dev_dbg(dai->dev, "%s: Codec is master.\n", __func__); | ||
198 | |||
199 | msp_config->iodelay = 0x20; | ||
200 | msp_config->rx_fsync_sel = 0; | ||
201 | msp_config->tx_fsync_sel = 1 << TFSSEL_SHIFT; | ||
202 | msp_config->tx_clk_sel = 0; | ||
203 | msp_config->rx_clk_sel = 0; | ||
204 | msp_config->srg_clk_sel = 0x2 << SCKSEL_SHIFT; | ||
205 | |||
206 | break; | ||
207 | |||
208 | case SND_SOC_DAIFMT_CBS_CFS: | ||
209 | dev_dbg(dai->dev, "%s: Codec is slave.\n", __func__); | ||
210 | |||
211 | msp_config->tx_clk_sel = TX_CLK_SEL_SRG; | ||
212 | msp_config->tx_fsync_sel = TX_SYNC_SRG_PROG; | ||
213 | msp_config->rx_clk_sel = RX_CLK_SEL_SRG; | ||
214 | msp_config->rx_fsync_sel = RX_SYNC_SRG; | ||
215 | msp_config->srg_clk_sel = 1 << SCKSEL_SHIFT; | ||
216 | |||
217 | break; | ||
218 | |||
219 | default: | ||
220 | dev_err(dai->dev, "%s: Error: Unsopported master (fmt = 0x%x)!\n", | ||
221 | __func__, fmt); | ||
222 | |||
223 | return -EINVAL; | ||
224 | } | ||
225 | |||
226 | return 0; | ||
227 | } | ||
228 | |||
229 | static int setup_pcm_protdesc(struct snd_soc_dai *dai, | ||
230 | unsigned int fmt, | ||
231 | struct msp_protdesc *prot_desc) | ||
232 | { | ||
233 | prot_desc->rx_phase_mode = MSP_SINGLE_PHASE; | ||
234 | prot_desc->tx_phase_mode = MSP_SINGLE_PHASE; | ||
235 | prot_desc->rx_phase2_start_mode = MSP_PHASE2_START_MODE_IMEDIATE; | ||
236 | prot_desc->tx_phase2_start_mode = MSP_PHASE2_START_MODE_IMEDIATE; | ||
237 | prot_desc->rx_byte_order = MSP_BTF_MS_BIT_FIRST; | ||
238 | prot_desc->tx_byte_order = MSP_BTF_MS_BIT_FIRST; | ||
239 | prot_desc->tx_fsync_pol = MSP_FSYNC_POL(MSP_FSYNC_POL_ACT_HI); | ||
240 | prot_desc->rx_fsync_pol = MSP_FSYNC_POL_ACT_HI << RFSPOL_SHIFT; | ||
241 | |||
242 | if ((fmt & SND_SOC_DAIFMT_FORMAT_MASK) == SND_SOC_DAIFMT_DSP_A) { | ||
243 | dev_dbg(dai->dev, "%s: DSP_A.\n", __func__); | ||
244 | prot_desc->rx_clk_pol = MSP_RISING_EDGE; | ||
245 | prot_desc->tx_clk_pol = MSP_FALLING_EDGE; | ||
246 | |||
247 | prot_desc->rx_data_delay = MSP_DELAY_1; | ||
248 | prot_desc->tx_data_delay = MSP_DELAY_1; | ||
249 | } else { | ||
250 | dev_dbg(dai->dev, "%s: DSP_B.\n", __func__); | ||
251 | prot_desc->rx_clk_pol = MSP_FALLING_EDGE; | ||
252 | prot_desc->tx_clk_pol = MSP_RISING_EDGE; | ||
253 | |||
254 | prot_desc->rx_data_delay = MSP_DELAY_0; | ||
255 | prot_desc->tx_data_delay = MSP_DELAY_0; | ||
256 | } | ||
257 | |||
258 | prot_desc->rx_half_word_swap = MSP_SWAP_NONE; | ||
259 | prot_desc->tx_half_word_swap = MSP_SWAP_NONE; | ||
260 | prot_desc->compression_mode = MSP_COMPRESS_MODE_LINEAR; | ||
261 | prot_desc->expansion_mode = MSP_EXPAND_MODE_LINEAR; | ||
262 | prot_desc->frame_sync_ignore = MSP_FSYNC_IGNORE; | ||
263 | |||
264 | return 0; | ||
265 | } | ||
266 | |||
267 | static int setup_i2s_protdesc(struct msp_protdesc *prot_desc) | ||
268 | { | ||
269 | prot_desc->rx_phase_mode = MSP_DUAL_PHASE; | ||
270 | prot_desc->tx_phase_mode = MSP_DUAL_PHASE; | ||
271 | prot_desc->rx_phase2_start_mode = MSP_PHASE2_START_MODE_FSYNC; | ||
272 | prot_desc->tx_phase2_start_mode = MSP_PHASE2_START_MODE_FSYNC; | ||
273 | prot_desc->rx_byte_order = MSP_BTF_MS_BIT_FIRST; | ||
274 | prot_desc->tx_byte_order = MSP_BTF_MS_BIT_FIRST; | ||
275 | prot_desc->tx_fsync_pol = MSP_FSYNC_POL(MSP_FSYNC_POL_ACT_LO); | ||
276 | prot_desc->rx_fsync_pol = MSP_FSYNC_POL_ACT_LO << RFSPOL_SHIFT; | ||
277 | |||
278 | prot_desc->rx_frame_len_1 = MSP_FRAME_LEN_1; | ||
279 | prot_desc->rx_frame_len_2 = MSP_FRAME_LEN_1; | ||
280 | prot_desc->tx_frame_len_1 = MSP_FRAME_LEN_1; | ||
281 | prot_desc->tx_frame_len_2 = MSP_FRAME_LEN_1; | ||
282 | prot_desc->rx_elem_len_1 = MSP_ELEM_LEN_16; | ||
283 | prot_desc->rx_elem_len_2 = MSP_ELEM_LEN_16; | ||
284 | prot_desc->tx_elem_len_1 = MSP_ELEM_LEN_16; | ||
285 | prot_desc->tx_elem_len_2 = MSP_ELEM_LEN_16; | ||
286 | |||
287 | prot_desc->rx_clk_pol = MSP_RISING_EDGE; | ||
288 | prot_desc->tx_clk_pol = MSP_FALLING_EDGE; | ||
289 | |||
290 | prot_desc->rx_data_delay = MSP_DELAY_0; | ||
291 | prot_desc->tx_data_delay = MSP_DELAY_0; | ||
292 | |||
293 | prot_desc->tx_half_word_swap = MSP_SWAP_NONE; | ||
294 | prot_desc->rx_half_word_swap = MSP_SWAP_NONE; | ||
295 | prot_desc->compression_mode = MSP_COMPRESS_MODE_LINEAR; | ||
296 | prot_desc->expansion_mode = MSP_EXPAND_MODE_LINEAR; | ||
297 | prot_desc->frame_sync_ignore = MSP_FSYNC_IGNORE; | ||
298 | |||
299 | return 0; | ||
300 | } | ||
301 | |||
302 | static int setup_msp_config(struct snd_pcm_substream *substream, | ||
303 | struct snd_soc_dai *dai, | ||
304 | struct ux500_msp_config *msp_config) | ||
305 | { | ||
306 | struct ux500_msp_i2s_drvdata *drvdata = dev_get_drvdata(dai->dev); | ||
307 | struct msp_protdesc *prot_desc = &msp_config->protdesc; | ||
308 | struct snd_pcm_runtime *runtime = substream->runtime; | ||
309 | unsigned int fmt = drvdata->fmt; | ||
310 | int ret; | ||
311 | |||
312 | memset(msp_config, 0, sizeof(*msp_config)); | ||
313 | |||
314 | msp_config->f_inputclk = drvdata->master_clk; | ||
315 | |||
316 | msp_config->tx_fifo_config = TX_FIFO_ENABLE; | ||
317 | msp_config->rx_fifo_config = RX_FIFO_ENABLE; | ||
318 | msp_config->def_elem_len = 1; | ||
319 | msp_config->direction = substream->stream == SNDRV_PCM_STREAM_PLAYBACK ? | ||
320 | MSP_DIR_TX : MSP_DIR_RX; | ||
321 | msp_config->data_size = MSP_DATA_BITS_32; | ||
322 | msp_config->frame_freq = runtime->rate; | ||
323 | |||
324 | dev_dbg(dai->dev, "%s: f_inputclk = %u, frame_freq = %u.\n", | ||
325 | __func__, msp_config->f_inputclk, msp_config->frame_freq); | ||
326 | /* To avoid division by zero */ | ||
327 | prot_desc->clocks_per_frame = 1; | ||
328 | |||
329 | dev_dbg(dai->dev, "%s: rate: %u, channels: %d.\n", __func__, | ||
330 | runtime->rate, runtime->channels); | ||
331 | switch (fmt & | ||
332 | (SND_SOC_DAIFMT_FORMAT_MASK | SND_SOC_DAIFMT_MASTER_MASK)) { | ||
333 | case SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBS_CFS: | ||
334 | dev_dbg(dai->dev, "%s: SND_SOC_DAIFMT_I2S.\n", __func__); | ||
335 | |||
336 | msp_config->default_protdesc = 1; | ||
337 | msp_config->protocol = MSP_I2S_PROTOCOL; | ||
338 | break; | ||
339 | |||
340 | case SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBM_CFM: | ||
341 | dev_dbg(dai->dev, "%s: SND_SOC_DAIFMT_I2S.\n", __func__); | ||
342 | |||
343 | msp_config->data_size = MSP_DATA_BITS_16; | ||
344 | msp_config->protocol = MSP_I2S_PROTOCOL; | ||
345 | |||
346 | ret = setup_i2s_protdesc(prot_desc); | ||
347 | if (ret < 0) | ||
348 | return ret; | ||
349 | |||
350 | break; | ||
351 | |||
352 | case SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_CBS_CFS: | ||
353 | case SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_CBM_CFM: | ||
354 | case SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_CBS_CFS: | ||
355 | case SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_CBM_CFM: | ||
356 | dev_dbg(dai->dev, "%s: PCM format.\n", __func__); | ||
357 | |||
358 | msp_config->data_size = MSP_DATA_BITS_16; | ||
359 | msp_config->protocol = MSP_PCM_PROTOCOL; | ||
360 | |||
361 | ret = setup_pcm_protdesc(dai, fmt, prot_desc); | ||
362 | if (ret < 0) | ||
363 | return ret; | ||
364 | |||
365 | ret = setup_pcm_multichan(dai, msp_config); | ||
366 | if (ret < 0) | ||
367 | return ret; | ||
368 | |||
369 | ret = setup_pcm_framing(dai, runtime->rate, prot_desc); | ||
370 | if (ret < 0) | ||
371 | return ret; | ||
372 | |||
373 | break; | ||
374 | |||
375 | default: | ||
376 | dev_err(dai->dev, "%s: Error: Unsopported format (%d)!\n", | ||
377 | __func__, fmt); | ||
378 | return -EINVAL; | ||
379 | } | ||
380 | |||
381 | return setup_clocking(dai, fmt, msp_config); | ||
382 | } | ||
383 | |||
384 | static int ux500_msp_dai_startup(struct snd_pcm_substream *substream, | ||
385 | struct snd_soc_dai *dai) | ||
386 | { | ||
387 | int ret = 0; | ||
388 | struct ux500_msp_i2s_drvdata *drvdata = dev_get_drvdata(dai->dev); | ||
389 | |||
390 | dev_dbg(dai->dev, "%s: MSP %d (%s): Enter.\n", __func__, dai->id, | ||
391 | snd_pcm_stream_str(substream)); | ||
392 | |||
393 | /* Enable regulator */ | ||
394 | ret = regulator_enable(drvdata->reg_vape); | ||
395 | if (ret != 0) { | ||
396 | dev_err(drvdata->msp->dev, | ||
397 | "%s: Failed to enable regulator!\n", __func__); | ||
398 | return ret; | ||
399 | } | ||
400 | |||
401 | /* Enable clock */ | ||
402 | dev_dbg(dai->dev, "%s: Enabling MSP-clock.\n", __func__); | ||
403 | clk_enable(drvdata->clk); | ||
404 | |||
405 | return 0; | ||
406 | } | ||
407 | |||
408 | static void ux500_msp_dai_shutdown(struct snd_pcm_substream *substream, | ||
409 | struct snd_soc_dai *dai) | ||
410 | { | ||
411 | int ret; | ||
412 | struct ux500_msp_i2s_drvdata *drvdata = dev_get_drvdata(dai->dev); | ||
413 | bool is_playback = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK); | ||
414 | |||
415 | dev_dbg(dai->dev, "%s: MSP %d (%s): Enter.\n", __func__, dai->id, | ||
416 | snd_pcm_stream_str(substream)); | ||
417 | |||
418 | if (drvdata->vape_opp_constraint == 1) { | ||
419 | prcmu_qos_update_requirement(PRCMU_QOS_APE_OPP, | ||
420 | "ux500_msp_i2s", 50); | ||
421 | drvdata->vape_opp_constraint = 0; | ||
422 | } | ||
423 | |||
424 | if (ux500_msp_i2s_close(drvdata->msp, | ||
425 | is_playback ? MSP_DIR_TX : MSP_DIR_RX)) { | ||
426 | dev_err(dai->dev, | ||
427 | "%s: Error: MSP %d (%s): Unable to close i2s.\n", | ||
428 | __func__, dai->id, snd_pcm_stream_str(substream)); | ||
429 | } | ||
430 | |||
431 | /* Disable clock */ | ||
432 | clk_disable(drvdata->clk); | ||
433 | |||
434 | /* Disable regulator */ | ||
435 | ret = regulator_disable(drvdata->reg_vape); | ||
436 | if (ret < 0) | ||
437 | dev_err(dai->dev, | ||
438 | "%s: ERROR: Failed to disable regulator (%d)!\n", | ||
439 | __func__, ret); | ||
440 | } | ||
441 | |||
442 | static int ux500_msp_dai_prepare(struct snd_pcm_substream *substream, | ||
443 | struct snd_soc_dai *dai) | ||
444 | { | ||
445 | int ret = 0; | ||
446 | struct ux500_msp_i2s_drvdata *drvdata = dev_get_drvdata(dai->dev); | ||
447 | struct snd_pcm_runtime *runtime = substream->runtime; | ||
448 | struct ux500_msp_config msp_config; | ||
449 | |||
450 | dev_dbg(dai->dev, "%s: MSP %d (%s): Enter (rate = %d).\n", __func__, | ||
451 | dai->id, snd_pcm_stream_str(substream), runtime->rate); | ||
452 | |||
453 | setup_msp_config(substream, dai, &msp_config); | ||
454 | |||
455 | ret = ux500_msp_i2s_open(drvdata->msp, &msp_config); | ||
456 | if (ret < 0) { | ||
457 | dev_err(dai->dev, "%s: Error: msp_setup failed (ret = %d)!\n", | ||
458 | __func__, ret); | ||
459 | return ret; | ||
460 | } | ||
461 | |||
462 | /* Set OPP-level */ | ||
463 | if ((drvdata->fmt & SND_SOC_DAIFMT_MASTER_MASK) && | ||
464 | (drvdata->msp->f_bitclk > 19200000)) { | ||
465 | /* If the bit-clock is higher than 19.2MHz, Vape should be | ||
466 | * run in 100% OPP. Only when bit-clock is used (MSP master) */ | ||
467 | prcmu_qos_update_requirement(PRCMU_QOS_APE_OPP, | ||
468 | "ux500-msp-i2s", 100); | ||
469 | drvdata->vape_opp_constraint = 1; | ||
470 | } else { | ||
471 | prcmu_qos_update_requirement(PRCMU_QOS_APE_OPP, | ||
472 | "ux500-msp-i2s", 50); | ||
473 | drvdata->vape_opp_constraint = 0; | ||
474 | } | ||
475 | |||
476 | return ret; | ||
477 | } | ||
478 | |||
479 | static int ux500_msp_dai_hw_params(struct snd_pcm_substream *substream, | ||
480 | struct snd_pcm_hw_params *params, | ||
481 | struct snd_soc_dai *dai) | ||
482 | { | ||
483 | unsigned int mask, slots_active; | ||
484 | struct snd_pcm_runtime *runtime = substream->runtime; | ||
485 | struct ux500_msp_i2s_drvdata *drvdata = dev_get_drvdata(dai->dev); | ||
486 | |||
487 | dev_dbg(dai->dev, "%s: MSP %d (%s): Enter.\n", | ||
488 | __func__, dai->id, snd_pcm_stream_str(substream)); | ||
489 | |||
490 | switch (drvdata->fmt & SND_SOC_DAIFMT_FORMAT_MASK) { | ||
491 | case SND_SOC_DAIFMT_I2S: | ||
492 | snd_pcm_hw_constraint_minmax(runtime, | ||
493 | SNDRV_PCM_HW_PARAM_CHANNELS, | ||
494 | 1, 2); | ||
495 | break; | ||
496 | |||
497 | case SND_SOC_DAIFMT_DSP_B: | ||
498 | case SND_SOC_DAIFMT_DSP_A: | ||
499 | mask = substream->stream == SNDRV_PCM_STREAM_PLAYBACK ? | ||
500 | drvdata->tx_mask : | ||
501 | drvdata->rx_mask; | ||
502 | |||
503 | slots_active = hweight32(mask); | ||
504 | dev_dbg(dai->dev, "TDM-slots active: %d", slots_active); | ||
505 | |||
506 | snd_pcm_hw_constraint_minmax(runtime, | ||
507 | SNDRV_PCM_HW_PARAM_CHANNELS, | ||
508 | slots_active, slots_active); | ||
509 | break; | ||
510 | |||
511 | default: | ||
512 | dev_err(dai->dev, | ||
513 | "%s: Error: Unsupported protocol (fmt = 0x%x)!\n", | ||
514 | __func__, drvdata->fmt); | ||
515 | return -EINVAL; | ||
516 | } | ||
517 | |||
518 | return 0; | ||
519 | } | ||
520 | |||
521 | static int ux500_msp_dai_set_dai_fmt(struct snd_soc_dai *dai, | ||
522 | unsigned int fmt) | ||
523 | { | ||
524 | struct ux500_msp_i2s_drvdata *drvdata = dev_get_drvdata(dai->dev); | ||
525 | |||
526 | dev_dbg(dai->dev, "%s: MSP %d: Enter.\n", __func__, dai->id); | ||
527 | |||
528 | switch (fmt & (SND_SOC_DAIFMT_FORMAT_MASK | | ||
529 | SND_SOC_DAIFMT_MASTER_MASK)) { | ||
530 | case SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBS_CFS: | ||
531 | case SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBM_CFM: | ||
532 | case SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_CBS_CFS: | ||
533 | case SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_CBM_CFM: | ||
534 | case SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_CBS_CFS: | ||
535 | case SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_CBM_CFM: | ||
536 | break; | ||
537 | |||
538 | default: | ||
539 | dev_err(dai->dev, | ||
540 | "%s: Error: Unsupported protocol/master (fmt = 0x%x)!\n", | ||
541 | __func__, drvdata->fmt); | ||
542 | return -EINVAL; | ||
543 | } | ||
544 | |||
545 | switch (fmt & SND_SOC_DAIFMT_INV_MASK) { | ||
546 | case SND_SOC_DAIFMT_NB_NF: | ||
547 | case SND_SOC_DAIFMT_NB_IF: | ||
548 | case SND_SOC_DAIFMT_IB_IF: | ||
549 | break; | ||
550 | |||
551 | default: | ||
552 | dev_err(dai->dev, | ||
553 | "%s: Error: Unsupported inversion (fmt = 0x%x)!\n", | ||
554 | __func__, drvdata->fmt); | ||
555 | return -EINVAL; | ||
556 | } | ||
557 | |||
558 | drvdata->fmt = fmt; | ||
559 | return 0; | ||
560 | } | ||
561 | |||
562 | static int ux500_msp_dai_set_tdm_slot(struct snd_soc_dai *dai, | ||
563 | unsigned int tx_mask, | ||
564 | unsigned int rx_mask, | ||
565 | int slots, int slot_width) | ||
566 | { | ||
567 | struct ux500_msp_i2s_drvdata *drvdata = dev_get_drvdata(dai->dev); | ||
568 | unsigned int cap; | ||
569 | |||
570 | switch (slots) { | ||
571 | case 1: | ||
572 | cap = 0x01; | ||
573 | break; | ||
574 | case 2: | ||
575 | cap = 0x03; | ||
576 | break; | ||
577 | case 8: | ||
578 | cap = 0xFF; | ||
579 | break; | ||
580 | case 16: | ||
581 | cap = 0xFFFF; | ||
582 | break; | ||
583 | default: | ||
584 | dev_err(dai->dev, "%s: Error: Unsupported slot-count (%d)!\n", | ||
585 | __func__, slots); | ||
586 | return -EINVAL; | ||
587 | } | ||
588 | drvdata->slots = slots; | ||
589 | |||
590 | if (!(slot_width == 16)) { | ||
591 | dev_err(dai->dev, "%s: Error: Unsupported slot-width (%d)!\n", | ||
592 | __func__, slot_width); | ||
593 | return -EINVAL; | ||
594 | } | ||
595 | drvdata->slot_width = slot_width; | ||
596 | |||
597 | drvdata->tx_mask = tx_mask & cap; | ||
598 | drvdata->rx_mask = rx_mask & cap; | ||
599 | |||
600 | return 0; | ||
601 | } | ||
602 | |||
603 | static int ux500_msp_dai_set_dai_sysclk(struct snd_soc_dai *dai, | ||
604 | int clk_id, unsigned int freq, int dir) | ||
605 | { | ||
606 | struct ux500_msp_i2s_drvdata *drvdata = dev_get_drvdata(dai->dev); | ||
607 | |||
608 | dev_dbg(dai->dev, "%s: MSP %d: Enter. clk-id: %d, freq: %u.\n", | ||
609 | __func__, dai->id, clk_id, freq); | ||
610 | |||
611 | switch (clk_id) { | ||
612 | case UX500_MSP_MASTER_CLOCK: | ||
613 | drvdata->master_clk = freq; | ||
614 | break; | ||
615 | |||
616 | default: | ||
617 | dev_err(dai->dev, "%s: MSP %d: Invalid clk-id (%d)!\n", | ||
618 | __func__, dai->id, clk_id); | ||
619 | return -EINVAL; | ||
620 | } | ||
621 | |||
622 | return 0; | ||
623 | } | ||
624 | |||
625 | static int ux500_msp_dai_trigger(struct snd_pcm_substream *substream, | ||
626 | int cmd, struct snd_soc_dai *dai) | ||
627 | { | ||
628 | int ret = 0; | ||
629 | struct ux500_msp_i2s_drvdata *drvdata = dev_get_drvdata(dai->dev); | ||
630 | |||
631 | dev_dbg(dai->dev, "%s: MSP %d (%s): Enter (msp->id = %d, cmd = %d).\n", | ||
632 | __func__, dai->id, snd_pcm_stream_str(substream), | ||
633 | (int)drvdata->msp->id, cmd); | ||
634 | |||
635 | ret = ux500_msp_i2s_trigger(drvdata->msp, cmd, substream->stream); | ||
636 | |||
637 | return ret; | ||
638 | } | ||
639 | |||
640 | static int ux500_msp_dai_probe(struct snd_soc_dai *dai) | ||
641 | { | ||
642 | struct ux500_msp_i2s_drvdata *drvdata = dev_get_drvdata(dai->dev); | ||
643 | |||
644 | drvdata->playback_dma_data.dma_cfg = drvdata->msp->dma_cfg_tx; | ||
645 | drvdata->capture_dma_data.dma_cfg = drvdata->msp->dma_cfg_rx; | ||
646 | |||
647 | dai->playback_dma_data = &drvdata->playback_dma_data; | ||
648 | dai->capture_dma_data = &drvdata->capture_dma_data; | ||
649 | |||
650 | drvdata->playback_dma_data.data_size = drvdata->slot_width; | ||
651 | drvdata->capture_dma_data.data_size = drvdata->slot_width; | ||
652 | |||
653 | return 0; | ||
654 | } | ||
655 | |||
656 | static struct snd_soc_dai_ops ux500_msp_dai_ops[] = { | ||
657 | { | ||
658 | .set_sysclk = ux500_msp_dai_set_dai_sysclk, | ||
659 | .set_fmt = ux500_msp_dai_set_dai_fmt, | ||
660 | .set_tdm_slot = ux500_msp_dai_set_tdm_slot, | ||
661 | .startup = ux500_msp_dai_startup, | ||
662 | .shutdown = ux500_msp_dai_shutdown, | ||
663 | .prepare = ux500_msp_dai_prepare, | ||
664 | .trigger = ux500_msp_dai_trigger, | ||
665 | .hw_params = ux500_msp_dai_hw_params, | ||
666 | } | ||
667 | }; | ||
668 | |||
669 | static struct snd_soc_dai_driver ux500_msp_dai_drv[UX500_NBR_OF_DAI] = { | ||
670 | { | ||
671 | .name = "ux500-msp-i2s.0", | ||
672 | .probe = ux500_msp_dai_probe, | ||
673 | .id = 0, | ||
674 | .suspend = NULL, | ||
675 | .resume = NULL, | ||
676 | .playback = { | ||
677 | .channels_min = UX500_MSP_MIN_CHANNELS, | ||
678 | .channels_max = UX500_MSP_MAX_CHANNELS, | ||
679 | .rates = UX500_I2S_RATES, | ||
680 | .formats = UX500_I2S_FORMATS, | ||
681 | }, | ||
682 | .capture = { | ||
683 | .channels_min = UX500_MSP_MIN_CHANNELS, | ||
684 | .channels_max = UX500_MSP_MAX_CHANNELS, | ||
685 | .rates = UX500_I2S_RATES, | ||
686 | .formats = UX500_I2S_FORMATS, | ||
687 | }, | ||
688 | .ops = ux500_msp_dai_ops, | ||
689 | }, | ||
690 | { | ||
691 | .name = "ux500-msp-i2s.1", | ||
692 | .probe = ux500_msp_dai_probe, | ||
693 | .id = 1, | ||
694 | .suspend = NULL, | ||
695 | .resume = NULL, | ||
696 | .playback = { | ||
697 | .channels_min = UX500_MSP_MIN_CHANNELS, | ||
698 | .channels_max = UX500_MSP_MAX_CHANNELS, | ||
699 | .rates = UX500_I2S_RATES, | ||
700 | .formats = UX500_I2S_FORMATS, | ||
701 | }, | ||
702 | .capture = { | ||
703 | .channels_min = UX500_MSP_MIN_CHANNELS, | ||
704 | .channels_max = UX500_MSP_MAX_CHANNELS, | ||
705 | .rates = UX500_I2S_RATES, | ||
706 | .formats = UX500_I2S_FORMATS, | ||
707 | }, | ||
708 | .ops = ux500_msp_dai_ops, | ||
709 | }, | ||
710 | { | ||
711 | .name = "ux500-msp-i2s.2", | ||
712 | .id = 2, | ||
713 | .probe = ux500_msp_dai_probe, | ||
714 | .suspend = NULL, | ||
715 | .resume = NULL, | ||
716 | .playback = { | ||
717 | .channels_min = UX500_MSP_MIN_CHANNELS, | ||
718 | .channels_max = UX500_MSP_MAX_CHANNELS, | ||
719 | .rates = UX500_I2S_RATES, | ||
720 | .formats = UX500_I2S_FORMATS, | ||
721 | }, | ||
722 | .capture = { | ||
723 | .channels_min = UX500_MSP_MIN_CHANNELS, | ||
724 | .channels_max = UX500_MSP_MAX_CHANNELS, | ||
725 | .rates = UX500_I2S_RATES, | ||
726 | .formats = UX500_I2S_FORMATS, | ||
727 | }, | ||
728 | .ops = ux500_msp_dai_ops, | ||
729 | }, | ||
730 | { | ||
731 | .name = "ux500-msp-i2s.3", | ||
732 | .probe = ux500_msp_dai_probe, | ||
733 | .id = 3, | ||
734 | .suspend = NULL, | ||
735 | .resume = NULL, | ||
736 | .playback = { | ||
737 | .channels_min = UX500_MSP_MIN_CHANNELS, | ||
738 | .channels_max = UX500_MSP_MAX_CHANNELS, | ||
739 | .rates = UX500_I2S_RATES, | ||
740 | .formats = UX500_I2S_FORMATS, | ||
741 | }, | ||
742 | .capture = { | ||
743 | .channels_min = UX500_MSP_MIN_CHANNELS, | ||
744 | .channels_max = UX500_MSP_MAX_CHANNELS, | ||
745 | .rates = UX500_I2S_RATES, | ||
746 | .formats = UX500_I2S_FORMATS, | ||
747 | }, | ||
748 | .ops = ux500_msp_dai_ops, | ||
749 | }, | ||
750 | }; | ||
751 | |||
752 | static int __devinit ux500_msp_drv_probe(struct platform_device *pdev) | ||
753 | { | ||
754 | struct ux500_msp_i2s_drvdata *drvdata; | ||
755 | int ret = 0; | ||
756 | |||
757 | dev_dbg(&pdev->dev, "%s: Enter (pdev->name = %s).\n", __func__, | ||
758 | pdev->name); | ||
759 | |||
760 | drvdata = devm_kzalloc(&pdev->dev, | ||
761 | sizeof(struct ux500_msp_i2s_drvdata), | ||
762 | GFP_KERNEL); | ||
763 | drvdata->fmt = 0; | ||
764 | drvdata->slots = 1; | ||
765 | drvdata->tx_mask = 0x01; | ||
766 | drvdata->rx_mask = 0x01; | ||
767 | drvdata->slot_width = 16; | ||
768 | drvdata->master_clk = MSP_INPUT_FREQ_APB; | ||
769 | |||
770 | drvdata->reg_vape = devm_regulator_get(&pdev->dev, "v-ape"); | ||
771 | if (IS_ERR(drvdata->reg_vape)) { | ||
772 | ret = (int)PTR_ERR(drvdata->reg_vape); | ||
773 | dev_err(&pdev->dev, | ||
774 | "%s: ERROR: Failed to get Vape supply (%d)!\n", | ||
775 | __func__, ret); | ||
776 | return ret; | ||
777 | } | ||
778 | prcmu_qos_add_requirement(PRCMU_QOS_APE_OPP, (char *)pdev->name, 50); | ||
779 | |||
780 | drvdata->clk = clk_get(&pdev->dev, NULL); | ||
781 | if (IS_ERR(drvdata->clk)) { | ||
782 | ret = (int)PTR_ERR(drvdata->clk); | ||
783 | dev_err(&pdev->dev, "%s: ERROR: clk_get failed (%d)!\n", | ||
784 | __func__, ret); | ||
785 | goto err_clk; | ||
786 | } | ||
787 | |||
788 | ret = ux500_msp_i2s_init_msp(pdev, &drvdata->msp, | ||
789 | pdev->dev.platform_data); | ||
790 | if (!drvdata->msp) { | ||
791 | dev_err(&pdev->dev, | ||
792 | "%s: ERROR: Failed to init MSP-struct (%d)!", | ||
793 | __func__, ret); | ||
794 | goto err_init_msp; | ||
795 | } | ||
796 | dev_set_drvdata(&pdev->dev, drvdata); | ||
797 | |||
798 | ret = snd_soc_register_dai(&pdev->dev, | ||
799 | &ux500_msp_dai_drv[drvdata->msp->id]); | ||
800 | if (ret < 0) { | ||
801 | dev_err(&pdev->dev, "Error: %s: Failed to register MSP%d!\n", | ||
802 | __func__, drvdata->msp->id); | ||
803 | goto err_init_msp; | ||
804 | } | ||
805 | |||
806 | return 0; | ||
807 | |||
808 | err_init_msp: | ||
809 | clk_put(drvdata->clk); | ||
810 | |||
811 | err_clk: | ||
812 | devm_regulator_put(drvdata->reg_vape); | ||
813 | |||
814 | return ret; | ||
815 | } | ||
816 | |||
817 | static int __devexit ux500_msp_drv_remove(struct platform_device *pdev) | ||
818 | { | ||
819 | struct ux500_msp_i2s_drvdata *drvdata = dev_get_drvdata(&pdev->dev); | ||
820 | |||
821 | snd_soc_unregister_dais(&pdev->dev, ARRAY_SIZE(ux500_msp_dai_drv)); | ||
822 | |||
823 | devm_regulator_put(drvdata->reg_vape); | ||
824 | prcmu_qos_remove_requirement(PRCMU_QOS_APE_OPP, "ux500_msp_i2s"); | ||
825 | |||
826 | clk_put(drvdata->clk); | ||
827 | |||
828 | ux500_msp_i2s_cleanup_msp(pdev, drvdata->msp); | ||
829 | |||
830 | return 0; | ||
831 | } | ||
832 | |||
833 | static struct platform_driver msp_i2s_driver = { | ||
834 | .driver = { | ||
835 | .name = "ux500-msp-i2s", | ||
836 | .owner = THIS_MODULE, | ||
837 | }, | ||
838 | .probe = ux500_msp_drv_probe, | ||
839 | .remove = ux500_msp_drv_remove, | ||
840 | }; | ||
841 | module_platform_driver(msp_i2s_driver); | ||
842 | |||
843 | MODULE_LICENSE("GPLv2"); | ||
diff --git a/sound/soc/ux500/ux500_msp_dai.h b/sound/soc/ux500/ux500_msp_dai.h new file mode 100644 index 000000000000..98202a34a5dd --- /dev/null +++ b/sound/soc/ux500/ux500_msp_dai.h | |||
@@ -0,0 +1,79 @@ | |||
1 | /* | ||
2 | * Copyright (C) ST-Ericsson SA 2012 | ||
3 | * | ||
4 | * Author: Ola Lilja <ola.o.lilja@stericsson.com>, | ||
5 | * Roger Nilsson <roger.xr.nilsson@stericsson.com> | ||
6 | * for ST-Ericsson. | ||
7 | * | ||
8 | * License terms: | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or modify | ||
11 | * it under the terms of the GNU General Public License version 2 as published | ||
12 | * by the Free Software Foundation. | ||
13 | */ | ||
14 | |||
15 | #ifndef UX500_msp_dai_H | ||
16 | #define UX500_msp_dai_H | ||
17 | |||
18 | #include <linux/types.h> | ||
19 | #include <linux/spinlock.h> | ||
20 | |||
21 | #include "ux500_msp_i2s.h" | ||
22 | |||
23 | #define UX500_NBR_OF_DAI 4 | ||
24 | |||
25 | #define UX500_I2S_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 | \ | ||
26 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000) | ||
27 | |||
28 | #define UX500_I2S_FORMATS (SNDRV_PCM_FMTBIT_S16_LE) | ||
29 | |||
30 | #define FRAME_PER_SINGLE_SLOT_8_KHZ 31 | ||
31 | #define FRAME_PER_SINGLE_SLOT_16_KHZ 124 | ||
32 | #define FRAME_PER_SINGLE_SLOT_44_1_KHZ 63 | ||
33 | #define FRAME_PER_SINGLE_SLOT_48_KHZ 49 | ||
34 | #define FRAME_PER_2_SLOTS 31 | ||
35 | #define FRAME_PER_8_SLOTS 138 | ||
36 | #define FRAME_PER_16_SLOTS 277 | ||
37 | |||
38 | #ifndef CONFIG_SND_SOC_UX500_AB5500 | ||
39 | #define UX500_MSP_INTERNAL_CLOCK_FREQ 40000000 | ||
40 | #define UX500_MSP1_INTERNAL_CLOCK_FREQ UX500_MSP_INTERNAL_CLOCK_FREQ | ||
41 | #else | ||
42 | #define UX500_MSP_INTERNAL_CLOCK_FREQ 13000000 | ||
43 | #define UX500_MSP1_INTERNAL_CLOCK_FREQ (UX500_MSP_INTERNAL_CLOCK_FREQ * 2) | ||
44 | #endif | ||
45 | |||
46 | #define UX500_MSP_MIN_CHANNELS 1 | ||
47 | #define UX500_MSP_MAX_CHANNELS 8 | ||
48 | |||
49 | #define PLAYBACK_CONFIGURED 1 | ||
50 | #define CAPTURE_CONFIGURED 2 | ||
51 | |||
52 | enum ux500_msp_clock_id { | ||
53 | UX500_MSP_MASTER_CLOCK, | ||
54 | }; | ||
55 | |||
56 | struct ux500_msp_i2s_drvdata { | ||
57 | struct ux500_msp *msp; | ||
58 | struct regulator *reg_vape; | ||
59 | struct ux500_msp_dma_params playback_dma_data; | ||
60 | struct ux500_msp_dma_params capture_dma_data; | ||
61 | unsigned int fmt; | ||
62 | unsigned int tx_mask; | ||
63 | unsigned int rx_mask; | ||
64 | int slots; | ||
65 | int slot_width; | ||
66 | u8 configured; | ||
67 | int data_delay; | ||
68 | |||
69 | /* Clocks */ | ||
70 | unsigned int master_clk; | ||
71 | struct clk *clk; | ||
72 | |||
73 | /* Regulators */ | ||
74 | int vape_opp_constraint; | ||
75 | }; | ||
76 | |||
77 | int ux500_msp_dai_set_data_delay(struct snd_soc_dai *dai, int delay); | ||
78 | |||
79 | #endif | ||
diff --git a/sound/soc/ux500/ux500_msp_i2s.c b/sound/soc/ux500/ux500_msp_i2s.c new file mode 100644 index 000000000000..496dec10c96e --- /dev/null +++ b/sound/soc/ux500/ux500_msp_i2s.c | |||
@@ -0,0 +1,742 @@ | |||
1 | /* | ||
2 | * Copyright (C) ST-Ericsson SA 2012 | ||
3 | * | ||
4 | * Author: Ola Lilja <ola.o.lilja@stericsson.com>, | ||
5 | * Roger Nilsson <roger.xr.nilsson@stericsson.com>, | ||
6 | * Sandeep Kaushik <sandeep.kaushik@st.com> | ||
7 | * for ST-Ericsson. | ||
8 | * | ||
9 | * License terms: | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or modify | ||
12 | * it under the terms of the GNU General Public License version 2 as published | ||
13 | * by the Free Software Foundation. | ||
14 | */ | ||
15 | |||
16 | #include <linux/module.h> | ||
17 | #include <linux/platform_device.h> | ||
18 | #include <linux/delay.h> | ||
19 | #include <linux/slab.h> | ||
20 | |||
21 | #include <mach/hardware.h> | ||
22 | #include <mach/board-mop500-msp.h> | ||
23 | |||
24 | #include <sound/soc.h> | ||
25 | |||
26 | #include "ux500_msp_i2s.h" | ||
27 | |||
28 | /* Protocol desciptors */ | ||
29 | static const struct msp_protdesc prot_descs[] = { | ||
30 | { /* I2S */ | ||
31 | MSP_SINGLE_PHASE, | ||
32 | MSP_SINGLE_PHASE, | ||
33 | MSP_PHASE2_START_MODE_IMEDIATE, | ||
34 | MSP_PHASE2_START_MODE_IMEDIATE, | ||
35 | MSP_BTF_MS_BIT_FIRST, | ||
36 | MSP_BTF_MS_BIT_FIRST, | ||
37 | MSP_FRAME_LEN_1, | ||
38 | MSP_FRAME_LEN_1, | ||
39 | MSP_FRAME_LEN_1, | ||
40 | MSP_FRAME_LEN_1, | ||
41 | MSP_ELEM_LEN_32, | ||
42 | MSP_ELEM_LEN_32, | ||
43 | MSP_ELEM_LEN_32, | ||
44 | MSP_ELEM_LEN_32, | ||
45 | MSP_DELAY_1, | ||
46 | MSP_DELAY_1, | ||
47 | MSP_RISING_EDGE, | ||
48 | MSP_FALLING_EDGE, | ||
49 | MSP_FSYNC_POL_ACT_LO, | ||
50 | MSP_FSYNC_POL_ACT_LO, | ||
51 | MSP_SWAP_NONE, | ||
52 | MSP_SWAP_NONE, | ||
53 | MSP_COMPRESS_MODE_LINEAR, | ||
54 | MSP_EXPAND_MODE_LINEAR, | ||
55 | MSP_FSYNC_IGNORE, | ||
56 | 31, | ||
57 | 15, | ||
58 | 32, | ||
59 | }, { /* PCM */ | ||
60 | MSP_DUAL_PHASE, | ||
61 | MSP_DUAL_PHASE, | ||
62 | MSP_PHASE2_START_MODE_FSYNC, | ||
63 | MSP_PHASE2_START_MODE_FSYNC, | ||
64 | MSP_BTF_MS_BIT_FIRST, | ||
65 | MSP_BTF_MS_BIT_FIRST, | ||
66 | MSP_FRAME_LEN_1, | ||
67 | MSP_FRAME_LEN_1, | ||
68 | MSP_FRAME_LEN_1, | ||
69 | MSP_FRAME_LEN_1, | ||
70 | MSP_ELEM_LEN_16, | ||
71 | MSP_ELEM_LEN_16, | ||
72 | MSP_ELEM_LEN_16, | ||
73 | MSP_ELEM_LEN_16, | ||
74 | MSP_DELAY_0, | ||
75 | MSP_DELAY_0, | ||
76 | MSP_RISING_EDGE, | ||
77 | MSP_FALLING_EDGE, | ||
78 | MSP_FSYNC_POL_ACT_HI, | ||
79 | MSP_FSYNC_POL_ACT_HI, | ||
80 | MSP_SWAP_NONE, | ||
81 | MSP_SWAP_NONE, | ||
82 | MSP_COMPRESS_MODE_LINEAR, | ||
83 | MSP_EXPAND_MODE_LINEAR, | ||
84 | MSP_FSYNC_IGNORE, | ||
85 | 255, | ||
86 | 0, | ||
87 | 256, | ||
88 | }, { /* Companded PCM */ | ||
89 | MSP_SINGLE_PHASE, | ||
90 | MSP_SINGLE_PHASE, | ||
91 | MSP_PHASE2_START_MODE_FSYNC, | ||
92 | MSP_PHASE2_START_MODE_FSYNC, | ||
93 | MSP_BTF_MS_BIT_FIRST, | ||
94 | MSP_BTF_MS_BIT_FIRST, | ||
95 | MSP_FRAME_LEN_1, | ||
96 | MSP_FRAME_LEN_1, | ||
97 | MSP_FRAME_LEN_1, | ||
98 | MSP_FRAME_LEN_1, | ||
99 | MSP_ELEM_LEN_8, | ||
100 | MSP_ELEM_LEN_8, | ||
101 | MSP_ELEM_LEN_8, | ||
102 | MSP_ELEM_LEN_8, | ||
103 | MSP_DELAY_0, | ||
104 | MSP_DELAY_0, | ||
105 | MSP_RISING_EDGE, | ||
106 | MSP_RISING_EDGE, | ||
107 | MSP_FSYNC_POL_ACT_HI, | ||
108 | MSP_FSYNC_POL_ACT_HI, | ||
109 | MSP_SWAP_NONE, | ||
110 | MSP_SWAP_NONE, | ||
111 | MSP_COMPRESS_MODE_LINEAR, | ||
112 | MSP_EXPAND_MODE_LINEAR, | ||
113 | MSP_FSYNC_IGNORE, | ||
114 | 255, | ||
115 | 0, | ||
116 | 256, | ||
117 | }, | ||
118 | }; | ||
119 | |||
120 | static void set_prot_desc_tx(struct ux500_msp *msp, | ||
121 | struct msp_protdesc *protdesc, | ||
122 | enum msp_data_size data_size) | ||
123 | { | ||
124 | u32 temp_reg = 0; | ||
125 | |||
126 | temp_reg |= MSP_P2_ENABLE_BIT(protdesc->tx_phase_mode); | ||
127 | temp_reg |= MSP_P2_START_MODE_BIT(protdesc->tx_phase2_start_mode); | ||
128 | temp_reg |= MSP_P1_FRAME_LEN_BITS(protdesc->tx_frame_len_1); | ||
129 | temp_reg |= MSP_P2_FRAME_LEN_BITS(protdesc->tx_frame_len_2); | ||
130 | if (msp->def_elem_len) { | ||
131 | temp_reg |= MSP_P1_ELEM_LEN_BITS(protdesc->tx_elem_len_1); | ||
132 | temp_reg |= MSP_P2_ELEM_LEN_BITS(protdesc->tx_elem_len_2); | ||
133 | } else { | ||
134 | temp_reg |= MSP_P1_ELEM_LEN_BITS(data_size); | ||
135 | temp_reg |= MSP_P2_ELEM_LEN_BITS(data_size); | ||
136 | } | ||
137 | temp_reg |= MSP_DATA_DELAY_BITS(protdesc->tx_data_delay); | ||
138 | temp_reg |= MSP_SET_ENDIANNES_BIT(protdesc->tx_byte_order); | ||
139 | temp_reg |= MSP_FSYNC_POL(protdesc->tx_fsync_pol); | ||
140 | temp_reg |= MSP_DATA_WORD_SWAP(protdesc->tx_half_word_swap); | ||
141 | temp_reg |= MSP_SET_COMPANDING_MODE(protdesc->compression_mode); | ||
142 | temp_reg |= MSP_SET_FSYNC_IGNORE(protdesc->frame_sync_ignore); | ||
143 | |||
144 | writel(temp_reg, msp->registers + MSP_TCF); | ||
145 | } | ||
146 | |||
147 | static void set_prot_desc_rx(struct ux500_msp *msp, | ||
148 | struct msp_protdesc *protdesc, | ||
149 | enum msp_data_size data_size) | ||
150 | { | ||
151 | u32 temp_reg = 0; | ||
152 | |||
153 | temp_reg |= MSP_P2_ENABLE_BIT(protdesc->rx_phase_mode); | ||
154 | temp_reg |= MSP_P2_START_MODE_BIT(protdesc->rx_phase2_start_mode); | ||
155 | temp_reg |= MSP_P1_FRAME_LEN_BITS(protdesc->rx_frame_len_1); | ||
156 | temp_reg |= MSP_P2_FRAME_LEN_BITS(protdesc->rx_frame_len_2); | ||
157 | if (msp->def_elem_len) { | ||
158 | temp_reg |= MSP_P1_ELEM_LEN_BITS(protdesc->rx_elem_len_1); | ||
159 | temp_reg |= MSP_P2_ELEM_LEN_BITS(protdesc->rx_elem_len_2); | ||
160 | } else { | ||
161 | temp_reg |= MSP_P1_ELEM_LEN_BITS(data_size); | ||
162 | temp_reg |= MSP_P2_ELEM_LEN_BITS(data_size); | ||
163 | } | ||
164 | |||
165 | temp_reg |= MSP_DATA_DELAY_BITS(protdesc->rx_data_delay); | ||
166 | temp_reg |= MSP_SET_ENDIANNES_BIT(protdesc->rx_byte_order); | ||
167 | temp_reg |= MSP_FSYNC_POL(protdesc->rx_fsync_pol); | ||
168 | temp_reg |= MSP_DATA_WORD_SWAP(protdesc->rx_half_word_swap); | ||
169 | temp_reg |= MSP_SET_COMPANDING_MODE(protdesc->expansion_mode); | ||
170 | temp_reg |= MSP_SET_FSYNC_IGNORE(protdesc->frame_sync_ignore); | ||
171 | |||
172 | writel(temp_reg, msp->registers + MSP_RCF); | ||
173 | } | ||
174 | |||
175 | static int configure_protocol(struct ux500_msp *msp, | ||
176 | struct ux500_msp_config *config) | ||
177 | { | ||
178 | struct msp_protdesc *protdesc; | ||
179 | enum msp_data_size data_size; | ||
180 | u32 temp_reg = 0; | ||
181 | |||
182 | data_size = config->data_size; | ||
183 | msp->def_elem_len = config->def_elem_len; | ||
184 | if (config->default_protdesc == 1) { | ||
185 | if (config->protocol >= MSP_INVALID_PROTOCOL) { | ||
186 | dev_err(msp->dev, "%s: ERROR: Invalid protocol!\n", | ||
187 | __func__); | ||
188 | return -EINVAL; | ||
189 | } | ||
190 | protdesc = | ||
191 | (struct msp_protdesc *)&prot_descs[config->protocol]; | ||
192 | } else { | ||
193 | protdesc = (struct msp_protdesc *)&config->protdesc; | ||
194 | } | ||
195 | |||
196 | if (data_size < MSP_DATA_BITS_DEFAULT || data_size > MSP_DATA_BITS_32) { | ||
197 | dev_err(msp->dev, | ||
198 | "%s: ERROR: Invalid data-size requested (data_size = %d)!\n", | ||
199 | __func__, data_size); | ||
200 | return -EINVAL; | ||
201 | } | ||
202 | |||
203 | if (config->direction & MSP_DIR_TX) | ||
204 | set_prot_desc_tx(msp, protdesc, data_size); | ||
205 | if (config->direction & MSP_DIR_RX) | ||
206 | set_prot_desc_rx(msp, protdesc, data_size); | ||
207 | |||
208 | /* The code below should not be separated. */ | ||
209 | temp_reg = readl(msp->registers + MSP_GCR) & ~TX_CLK_POL_RISING; | ||
210 | temp_reg |= MSP_TX_CLKPOL_BIT(~protdesc->tx_clk_pol); | ||
211 | writel(temp_reg, msp->registers + MSP_GCR); | ||
212 | temp_reg = readl(msp->registers + MSP_GCR) & ~RX_CLK_POL_RISING; | ||
213 | temp_reg |= MSP_RX_CLKPOL_BIT(protdesc->rx_clk_pol); | ||
214 | writel(temp_reg, msp->registers + MSP_GCR); | ||
215 | |||
216 | return 0; | ||
217 | } | ||
218 | |||
219 | static int setup_bitclk(struct ux500_msp *msp, struct ux500_msp_config *config) | ||
220 | { | ||
221 | u32 reg_val_GCR; | ||
222 | u32 frame_per = 0; | ||
223 | u32 sck_div = 0; | ||
224 | u32 frame_width = 0; | ||
225 | u32 temp_reg = 0; | ||
226 | struct msp_protdesc *protdesc = NULL; | ||
227 | |||
228 | reg_val_GCR = readl(msp->registers + MSP_GCR); | ||
229 | writel(reg_val_GCR & ~SRG_ENABLE, msp->registers + MSP_GCR); | ||
230 | |||
231 | if (config->default_protdesc) | ||
232 | protdesc = | ||
233 | (struct msp_protdesc *)&prot_descs[config->protocol]; | ||
234 | else | ||
235 | protdesc = (struct msp_protdesc *)&config->protdesc; | ||
236 | |||
237 | switch (config->protocol) { | ||
238 | case MSP_PCM_PROTOCOL: | ||
239 | case MSP_PCM_COMPAND_PROTOCOL: | ||
240 | frame_width = protdesc->frame_width; | ||
241 | sck_div = config->f_inputclk / (config->frame_freq * | ||
242 | (protdesc->clocks_per_frame)); | ||
243 | frame_per = protdesc->frame_period; | ||
244 | break; | ||
245 | case MSP_I2S_PROTOCOL: | ||
246 | frame_width = protdesc->frame_width; | ||
247 | sck_div = config->f_inputclk / (config->frame_freq * | ||
248 | (protdesc->clocks_per_frame)); | ||
249 | frame_per = protdesc->frame_period; | ||
250 | break; | ||
251 | default: | ||
252 | dev_err(msp->dev, "%s: ERROR: Unknown protocol (%d)!\n", | ||
253 | __func__, | ||
254 | config->protocol); | ||
255 | return -EINVAL; | ||
256 | } | ||
257 | |||
258 | temp_reg = (sck_div - 1) & SCK_DIV_MASK; | ||
259 | temp_reg |= FRAME_WIDTH_BITS(frame_width); | ||
260 | temp_reg |= FRAME_PERIOD_BITS(frame_per); | ||
261 | writel(temp_reg, msp->registers + MSP_SRG); | ||
262 | |||
263 | msp->f_bitclk = (config->f_inputclk)/(sck_div + 1); | ||
264 | |||
265 | /* Enable bit-clock */ | ||
266 | udelay(100); | ||
267 | reg_val_GCR = readl(msp->registers + MSP_GCR); | ||
268 | writel(reg_val_GCR | SRG_ENABLE, msp->registers + MSP_GCR); | ||
269 | udelay(100); | ||
270 | |||
271 | return 0; | ||
272 | } | ||
273 | |||
274 | static int configure_multichannel(struct ux500_msp *msp, | ||
275 | struct ux500_msp_config *config) | ||
276 | { | ||
277 | struct msp_protdesc *protdesc; | ||
278 | struct msp_multichannel_config *mcfg; | ||
279 | u32 reg_val_MCR; | ||
280 | |||
281 | if (config->default_protdesc == 1) { | ||
282 | if (config->protocol >= MSP_INVALID_PROTOCOL) { | ||
283 | dev_err(msp->dev, | ||
284 | "%s: ERROR: Invalid protocol (%d)!\n", | ||
285 | __func__, config->protocol); | ||
286 | return -EINVAL; | ||
287 | } | ||
288 | protdesc = (struct msp_protdesc *) | ||
289 | &prot_descs[config->protocol]; | ||
290 | } else { | ||
291 | protdesc = (struct msp_protdesc *)&config->protdesc; | ||
292 | } | ||
293 | |||
294 | mcfg = &config->multichannel_config; | ||
295 | if (mcfg->tx_multichannel_enable) { | ||
296 | if (protdesc->tx_phase_mode == MSP_SINGLE_PHASE) { | ||
297 | reg_val_MCR = readl(msp->registers + MSP_MCR); | ||
298 | writel(reg_val_MCR | (mcfg->tx_multichannel_enable ? | ||
299 | 1 << TMCEN_BIT : 0), | ||
300 | msp->registers + MSP_MCR); | ||
301 | writel(mcfg->tx_channel_0_enable, | ||
302 | msp->registers + MSP_TCE0); | ||
303 | writel(mcfg->tx_channel_1_enable, | ||
304 | msp->registers + MSP_TCE1); | ||
305 | writel(mcfg->tx_channel_2_enable, | ||
306 | msp->registers + MSP_TCE2); | ||
307 | writel(mcfg->tx_channel_3_enable, | ||
308 | msp->registers + MSP_TCE3); | ||
309 | } else { | ||
310 | dev_err(msp->dev, | ||
311 | "%s: ERROR: Only single-phase supported (TX-mode: %d)!\n", | ||
312 | __func__, protdesc->tx_phase_mode); | ||
313 | return -EINVAL; | ||
314 | } | ||
315 | } | ||
316 | if (mcfg->rx_multichannel_enable) { | ||
317 | if (protdesc->rx_phase_mode == MSP_SINGLE_PHASE) { | ||
318 | reg_val_MCR = readl(msp->registers + MSP_MCR); | ||
319 | writel(reg_val_MCR | (mcfg->rx_multichannel_enable ? | ||
320 | 1 << RMCEN_BIT : 0), | ||
321 | msp->registers + MSP_MCR); | ||
322 | writel(mcfg->rx_channel_0_enable, | ||
323 | msp->registers + MSP_RCE0); | ||
324 | writel(mcfg->rx_channel_1_enable, | ||
325 | msp->registers + MSP_RCE1); | ||
326 | writel(mcfg->rx_channel_2_enable, | ||
327 | msp->registers + MSP_RCE2); | ||
328 | writel(mcfg->rx_channel_3_enable, | ||
329 | msp->registers + MSP_RCE3); | ||
330 | } else { | ||
331 | dev_err(msp->dev, | ||
332 | "%s: ERROR: Only single-phase supported (RX-mode: %d)!\n", | ||
333 | __func__, protdesc->rx_phase_mode); | ||
334 | return -EINVAL; | ||
335 | } | ||
336 | if (mcfg->rx_comparison_enable_mode) { | ||
337 | reg_val_MCR = readl(msp->registers + MSP_MCR); | ||
338 | writel(reg_val_MCR | | ||
339 | (mcfg->rx_comparison_enable_mode << RCMPM_BIT), | ||
340 | msp->registers + MSP_MCR); | ||
341 | |||
342 | writel(mcfg->comparison_mask, | ||
343 | msp->registers + MSP_RCM); | ||
344 | writel(mcfg->comparison_value, | ||
345 | msp->registers + MSP_RCV); | ||
346 | |||
347 | } | ||
348 | } | ||
349 | |||
350 | return 0; | ||
351 | } | ||
352 | |||
353 | static int enable_msp(struct ux500_msp *msp, struct ux500_msp_config *config) | ||
354 | { | ||
355 | int status = 0; | ||
356 | u32 reg_val_DMACR, reg_val_GCR; | ||
357 | |||
358 | /* Check msp state whether in RUN or CONFIGURED Mode */ | ||
359 | if ((msp->msp_state == MSP_STATE_IDLE) && (msp->plat_init)) { | ||
360 | status = msp->plat_init(); | ||
361 | if (status) { | ||
362 | dev_err(msp->dev, "%s: ERROR: Failed to init MSP (%d)!\n", | ||
363 | __func__, status); | ||
364 | return status; | ||
365 | } | ||
366 | } | ||
367 | |||
368 | /* Configure msp with protocol dependent settings */ | ||
369 | configure_protocol(msp, config); | ||
370 | setup_bitclk(msp, config); | ||
371 | if (config->multichannel_configured == 1) { | ||
372 | status = configure_multichannel(msp, config); | ||
373 | if (status) | ||
374 | dev_warn(msp->dev, | ||
375 | "%s: WARN: configure_multichannel failed (%d)!\n", | ||
376 | __func__, status); | ||
377 | } | ||
378 | |||
379 | /* Make sure the correct DMA-directions are configured */ | ||
380 | if ((config->direction & MSP_DIR_RX) && (!msp->dma_cfg_rx)) { | ||
381 | dev_err(msp->dev, "%s: ERROR: MSP RX-mode is not configured!", | ||
382 | __func__); | ||
383 | return -EINVAL; | ||
384 | } | ||
385 | if ((config->direction == MSP_DIR_TX) && (!msp->dma_cfg_tx)) { | ||
386 | dev_err(msp->dev, "%s: ERROR: MSP TX-mode is not configured!", | ||
387 | __func__); | ||
388 | return -EINVAL; | ||
389 | } | ||
390 | |||
391 | reg_val_DMACR = readl(msp->registers + MSP_DMACR); | ||
392 | if (config->direction & MSP_DIR_RX) | ||
393 | reg_val_DMACR |= RX_DMA_ENABLE; | ||
394 | if (config->direction & MSP_DIR_TX) | ||
395 | reg_val_DMACR |= TX_DMA_ENABLE; | ||
396 | writel(reg_val_DMACR, msp->registers + MSP_DMACR); | ||
397 | |||
398 | writel(config->iodelay, msp->registers + MSP_IODLY); | ||
399 | |||
400 | /* Enable frame generation logic */ | ||
401 | reg_val_GCR = readl(msp->registers + MSP_GCR); | ||
402 | writel(reg_val_GCR | FRAME_GEN_ENABLE, msp->registers + MSP_GCR); | ||
403 | |||
404 | return status; | ||
405 | } | ||
406 | |||
407 | static void flush_fifo_rx(struct ux500_msp *msp) | ||
408 | { | ||
409 | u32 reg_val_DR, reg_val_GCR, reg_val_FLR; | ||
410 | u32 limit = 32; | ||
411 | |||
412 | reg_val_GCR = readl(msp->registers + MSP_GCR); | ||
413 | writel(reg_val_GCR | RX_ENABLE, msp->registers + MSP_GCR); | ||
414 | |||
415 | reg_val_FLR = readl(msp->registers + MSP_FLR); | ||
416 | while (!(reg_val_FLR & RX_FIFO_EMPTY) && limit--) { | ||
417 | reg_val_DR = readl(msp->registers + MSP_DR); | ||
418 | reg_val_FLR = readl(msp->registers + MSP_FLR); | ||
419 | } | ||
420 | |||
421 | writel(reg_val_GCR, msp->registers + MSP_GCR); | ||
422 | } | ||
423 | |||
424 | static void flush_fifo_tx(struct ux500_msp *msp) | ||
425 | { | ||
426 | u32 reg_val_TSTDR, reg_val_GCR, reg_val_FLR; | ||
427 | u32 limit = 32; | ||
428 | |||
429 | reg_val_GCR = readl(msp->registers + MSP_GCR); | ||
430 | writel(reg_val_GCR | TX_ENABLE, msp->registers + MSP_GCR); | ||
431 | writel(MSP_ITCR_ITEN | MSP_ITCR_TESTFIFO, msp->registers + MSP_ITCR); | ||
432 | |||
433 | reg_val_FLR = readl(msp->registers + MSP_FLR); | ||
434 | while (!(reg_val_FLR & TX_FIFO_EMPTY) && limit--) { | ||
435 | reg_val_TSTDR = readl(msp->registers + MSP_TSTDR); | ||
436 | reg_val_FLR = readl(msp->registers + MSP_FLR); | ||
437 | } | ||
438 | writel(0x0, msp->registers + MSP_ITCR); | ||
439 | writel(reg_val_GCR, msp->registers + MSP_GCR); | ||
440 | } | ||
441 | |||
442 | int ux500_msp_i2s_open(struct ux500_msp *msp, | ||
443 | struct ux500_msp_config *config) | ||
444 | { | ||
445 | u32 old_reg, new_reg, mask; | ||
446 | int res; | ||
447 | unsigned int tx_sel, rx_sel, tx_busy, rx_busy; | ||
448 | |||
449 | if (in_interrupt()) { | ||
450 | dev_err(msp->dev, | ||
451 | "%s: ERROR: Open called in interrupt context!\n", | ||
452 | __func__); | ||
453 | return -1; | ||
454 | } | ||
455 | |||
456 | tx_sel = (config->direction & MSP_DIR_TX) > 0; | ||
457 | rx_sel = (config->direction & MSP_DIR_RX) > 0; | ||
458 | if (!tx_sel && !rx_sel) { | ||
459 | dev_err(msp->dev, "%s: Error: No direction selected!\n", | ||
460 | __func__); | ||
461 | return -EINVAL; | ||
462 | } | ||
463 | |||
464 | tx_busy = (msp->dir_busy & MSP_DIR_TX) > 0; | ||
465 | rx_busy = (msp->dir_busy & MSP_DIR_RX) > 0; | ||
466 | if (tx_busy && tx_sel) { | ||
467 | dev_err(msp->dev, "%s: Error: TX is in use!\n", __func__); | ||
468 | return -EBUSY; | ||
469 | } | ||
470 | if (rx_busy && rx_sel) { | ||
471 | dev_err(msp->dev, "%s: Error: RX is in use!\n", __func__); | ||
472 | return -EBUSY; | ||
473 | } | ||
474 | |||
475 | msp->dir_busy |= (tx_sel ? MSP_DIR_TX : 0) | (rx_sel ? MSP_DIR_RX : 0); | ||
476 | |||
477 | /* First do the global config register */ | ||
478 | mask = RX_CLK_SEL_MASK | TX_CLK_SEL_MASK | RX_FSYNC_MASK | | ||
479 | TX_FSYNC_MASK | RX_SYNC_SEL_MASK | TX_SYNC_SEL_MASK | | ||
480 | RX_FIFO_ENABLE_MASK | TX_FIFO_ENABLE_MASK | SRG_CLK_SEL_MASK | | ||
481 | LOOPBACK_MASK | TX_EXTRA_DELAY_MASK; | ||
482 | |||
483 | new_reg = (config->tx_clk_sel | config->rx_clk_sel | | ||
484 | config->rx_fsync_pol | config->tx_fsync_pol | | ||
485 | config->rx_fsync_sel | config->tx_fsync_sel | | ||
486 | config->rx_fifo_config | config->tx_fifo_config | | ||
487 | config->srg_clk_sel | config->loopback_enable | | ||
488 | config->tx_data_enable); | ||
489 | |||
490 | old_reg = readl(msp->registers + MSP_GCR); | ||
491 | old_reg &= ~mask; | ||
492 | new_reg |= old_reg; | ||
493 | writel(new_reg, msp->registers + MSP_GCR); | ||
494 | |||
495 | res = enable_msp(msp, config); | ||
496 | if (res < 0) { | ||
497 | dev_err(msp->dev, "%s: ERROR: enable_msp failed (%d)!\n", | ||
498 | __func__, res); | ||
499 | return -EBUSY; | ||
500 | } | ||
501 | if (config->loopback_enable & 0x80) | ||
502 | msp->loopback_enable = 1; | ||
503 | |||
504 | /* Flush FIFOs */ | ||
505 | flush_fifo_tx(msp); | ||
506 | flush_fifo_rx(msp); | ||
507 | |||
508 | msp->msp_state = MSP_STATE_CONFIGURED; | ||
509 | return 0; | ||
510 | } | ||
511 | |||
512 | static void disable_msp_rx(struct ux500_msp *msp) | ||
513 | { | ||
514 | u32 reg_val_GCR, reg_val_DMACR, reg_val_IMSC; | ||
515 | |||
516 | reg_val_GCR = readl(msp->registers + MSP_GCR); | ||
517 | writel(reg_val_GCR & ~RX_ENABLE, msp->registers + MSP_GCR); | ||
518 | reg_val_DMACR = readl(msp->registers + MSP_DMACR); | ||
519 | writel(reg_val_DMACR & ~RX_DMA_ENABLE, msp->registers + MSP_DMACR); | ||
520 | reg_val_IMSC = readl(msp->registers + MSP_IMSC); | ||
521 | writel(reg_val_IMSC & | ||
522 | ~(RX_SERVICE_INT | RX_OVERRUN_ERROR_INT), | ||
523 | msp->registers + MSP_IMSC); | ||
524 | |||
525 | msp->dir_busy &= ~MSP_DIR_RX; | ||
526 | } | ||
527 | |||
528 | static void disable_msp_tx(struct ux500_msp *msp) | ||
529 | { | ||
530 | u32 reg_val_GCR, reg_val_DMACR, reg_val_IMSC; | ||
531 | |||
532 | reg_val_GCR = readl(msp->registers + MSP_GCR); | ||
533 | writel(reg_val_GCR & ~TX_ENABLE, msp->registers + MSP_GCR); | ||
534 | reg_val_DMACR = readl(msp->registers + MSP_DMACR); | ||
535 | writel(reg_val_DMACR & ~TX_DMA_ENABLE, msp->registers + MSP_DMACR); | ||
536 | reg_val_IMSC = readl(msp->registers + MSP_IMSC); | ||
537 | writel(reg_val_IMSC & | ||
538 | ~(TX_SERVICE_INT | TX_UNDERRUN_ERR_INT), | ||
539 | msp->registers + MSP_IMSC); | ||
540 | |||
541 | msp->dir_busy &= ~MSP_DIR_TX; | ||
542 | } | ||
543 | |||
544 | static int disable_msp(struct ux500_msp *msp, unsigned int dir) | ||
545 | { | ||
546 | u32 reg_val_GCR; | ||
547 | int status = 0; | ||
548 | unsigned int disable_tx, disable_rx; | ||
549 | |||
550 | reg_val_GCR = readl(msp->registers + MSP_GCR); | ||
551 | disable_tx = dir & MSP_DIR_TX; | ||
552 | disable_rx = dir & MSP_DIR_TX; | ||
553 | if (disable_tx && disable_rx) { | ||
554 | reg_val_GCR = readl(msp->registers + MSP_GCR); | ||
555 | writel(reg_val_GCR | LOOPBACK_MASK, | ||
556 | msp->registers + MSP_GCR); | ||
557 | |||
558 | /* Flush TX-FIFO */ | ||
559 | flush_fifo_tx(msp); | ||
560 | |||
561 | /* Disable TX-channel */ | ||
562 | writel((readl(msp->registers + MSP_GCR) & | ||
563 | (~TX_ENABLE)), msp->registers + MSP_GCR); | ||
564 | |||
565 | /* Flush RX-FIFO */ | ||
566 | flush_fifo_rx(msp); | ||
567 | |||
568 | /* Disable Loopback and Receive channel */ | ||
569 | writel((readl(msp->registers + MSP_GCR) & | ||
570 | (~(RX_ENABLE | LOOPBACK_MASK))), | ||
571 | msp->registers + MSP_GCR); | ||
572 | |||
573 | disable_msp_tx(msp); | ||
574 | disable_msp_rx(msp); | ||
575 | } else if (disable_tx) | ||
576 | disable_msp_tx(msp); | ||
577 | else if (disable_rx) | ||
578 | disable_msp_rx(msp); | ||
579 | |||
580 | return status; | ||
581 | } | ||
582 | |||
583 | int ux500_msp_i2s_trigger(struct ux500_msp *msp, int cmd, int direction) | ||
584 | { | ||
585 | u32 reg_val_GCR, enable_bit; | ||
586 | |||
587 | if (msp->msp_state == MSP_STATE_IDLE) { | ||
588 | dev_err(msp->dev, "%s: ERROR: MSP is not configured!\n", | ||
589 | __func__); | ||
590 | return -EINVAL; | ||
591 | } | ||
592 | |||
593 | switch (cmd) { | ||
594 | case SNDRV_PCM_TRIGGER_START: | ||
595 | case SNDRV_PCM_TRIGGER_RESUME: | ||
596 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: | ||
597 | if (direction == SNDRV_PCM_STREAM_PLAYBACK) | ||
598 | enable_bit = TX_ENABLE; | ||
599 | else | ||
600 | enable_bit = RX_ENABLE; | ||
601 | reg_val_GCR = readl(msp->registers + MSP_GCR); | ||
602 | writel(reg_val_GCR | enable_bit, msp->registers + MSP_GCR); | ||
603 | break; | ||
604 | |||
605 | case SNDRV_PCM_TRIGGER_STOP: | ||
606 | case SNDRV_PCM_TRIGGER_SUSPEND: | ||
607 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: | ||
608 | if (direction == SNDRV_PCM_STREAM_PLAYBACK) | ||
609 | disable_msp_tx(msp); | ||
610 | else | ||
611 | disable_msp_rx(msp); | ||
612 | break; | ||
613 | default: | ||
614 | return -EINVAL; | ||
615 | break; | ||
616 | } | ||
617 | |||
618 | return 0; | ||
619 | } | ||
620 | |||
621 | int ux500_msp_i2s_close(struct ux500_msp *msp, unsigned int dir) | ||
622 | { | ||
623 | int status = 0; | ||
624 | |||
625 | dev_dbg(msp->dev, "%s: Enter (dir = 0x%01x).\n", __func__, dir); | ||
626 | |||
627 | status = disable_msp(msp, dir); | ||
628 | if (msp->dir_busy == 0) { | ||
629 | /* disable sample rate and frame generators */ | ||
630 | msp->msp_state = MSP_STATE_IDLE; | ||
631 | writel((readl(msp->registers + MSP_GCR) & | ||
632 | (~(FRAME_GEN_ENABLE | SRG_ENABLE))), | ||
633 | msp->registers + MSP_GCR); | ||
634 | if (msp->plat_exit) | ||
635 | status = msp->plat_exit(); | ||
636 | if (status) | ||
637 | dev_warn(msp->dev, | ||
638 | "%s: WARN: ux500_msp_i2s_exit failed (%d)!\n", | ||
639 | __func__, status); | ||
640 | writel(0, msp->registers + MSP_GCR); | ||
641 | writel(0, msp->registers + MSP_TCF); | ||
642 | writel(0, msp->registers + MSP_RCF); | ||
643 | writel(0, msp->registers + MSP_DMACR); | ||
644 | writel(0, msp->registers + MSP_SRG); | ||
645 | writel(0, msp->registers + MSP_MCR); | ||
646 | writel(0, msp->registers + MSP_RCM); | ||
647 | writel(0, msp->registers + MSP_RCV); | ||
648 | writel(0, msp->registers + MSP_TCE0); | ||
649 | writel(0, msp->registers + MSP_TCE1); | ||
650 | writel(0, msp->registers + MSP_TCE2); | ||
651 | writel(0, msp->registers + MSP_TCE3); | ||
652 | writel(0, msp->registers + MSP_RCE0); | ||
653 | writel(0, msp->registers + MSP_RCE1); | ||
654 | writel(0, msp->registers + MSP_RCE2); | ||
655 | writel(0, msp->registers + MSP_RCE3); | ||
656 | } | ||
657 | |||
658 | return status; | ||
659 | |||
660 | } | ||
661 | |||
662 | int ux500_msp_i2s_init_msp(struct platform_device *pdev, | ||
663 | struct ux500_msp **msp_p, | ||
664 | struct msp_i2s_platform_data *platform_data) | ||
665 | { | ||
666 | int ret = 0; | ||
667 | struct resource *res = NULL; | ||
668 | struct i2s_controller *i2s_cont; | ||
669 | struct ux500_msp *msp; | ||
670 | |||
671 | dev_dbg(&pdev->dev, "%s: Enter (name: %s, id: %d).\n", __func__, | ||
672 | pdev->name, platform_data->id); | ||
673 | |||
674 | *msp_p = devm_kzalloc(&pdev->dev, sizeof(struct ux500_msp), GFP_KERNEL); | ||
675 | msp = *msp_p; | ||
676 | |||
677 | msp->id = platform_data->id; | ||
678 | msp->dev = &pdev->dev; | ||
679 | msp->plat_init = platform_data->msp_i2s_init; | ||
680 | msp->plat_exit = platform_data->msp_i2s_exit; | ||
681 | msp->dma_cfg_rx = platform_data->msp_i2s_dma_rx; | ||
682 | msp->dma_cfg_tx = platform_data->msp_i2s_dma_tx; | ||
683 | |||
684 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
685 | if (res == NULL) { | ||
686 | dev_err(&pdev->dev, "%s: ERROR: Unable to get resource!\n", | ||
687 | __func__); | ||
688 | ret = -ENOMEM; | ||
689 | goto err_res; | ||
690 | } | ||
691 | |||
692 | msp->registers = ioremap(res->start, (res->end - res->start + 1)); | ||
693 | if (msp->registers == NULL) { | ||
694 | dev_err(&pdev->dev, "%s: ERROR: ioremap failed!\n", __func__); | ||
695 | ret = -ENOMEM; | ||
696 | goto err_res; | ||
697 | } | ||
698 | |||
699 | msp->msp_state = MSP_STATE_IDLE; | ||
700 | msp->loopback_enable = 0; | ||
701 | |||
702 | /* I2S-controller is allocated and added in I2S controller class. */ | ||
703 | i2s_cont = devm_kzalloc(&pdev->dev, sizeof(*i2s_cont), GFP_KERNEL); | ||
704 | if (!i2s_cont) { | ||
705 | dev_err(&pdev->dev, | ||
706 | "%s: ERROR: Failed to allocate I2S-controller!\n", | ||
707 | __func__); | ||
708 | goto err_i2s_cont; | ||
709 | } | ||
710 | i2s_cont->dev.parent = &pdev->dev; | ||
711 | i2s_cont->data = (void *)msp; | ||
712 | i2s_cont->id = (s16)msp->id; | ||
713 | snprintf(i2s_cont->name, sizeof(i2s_cont->name), "ux500-msp-i2s.%04x", | ||
714 | msp->id); | ||
715 | dev_dbg(&pdev->dev, "I2S device-name: '%s'\n", i2s_cont->name); | ||
716 | msp->i2s_cont = i2s_cont; | ||
717 | |||
718 | return 0; | ||
719 | |||
720 | err_i2s_cont: | ||
721 | iounmap(msp->registers); | ||
722 | |||
723 | err_res: | ||
724 | devm_kfree(&pdev->dev, msp); | ||
725 | |||
726 | return ret; | ||
727 | } | ||
728 | |||
729 | void ux500_msp_i2s_cleanup_msp(struct platform_device *pdev, | ||
730 | struct ux500_msp *msp) | ||
731 | { | ||
732 | dev_dbg(msp->dev, "%s: Enter (id = %d).\n", __func__, msp->id); | ||
733 | |||
734 | device_unregister(&msp->i2s_cont->dev); | ||
735 | devm_kfree(&pdev->dev, msp->i2s_cont); | ||
736 | |||
737 | iounmap(msp->registers); | ||
738 | |||
739 | devm_kfree(&pdev->dev, msp); | ||
740 | } | ||
741 | |||
742 | MODULE_LICENSE("GPLv2"); | ||
diff --git a/sound/soc/ux500/ux500_msp_i2s.h b/sound/soc/ux500/ux500_msp_i2s.h new file mode 100644 index 000000000000..7f71b4a0d4bc --- /dev/null +++ b/sound/soc/ux500/ux500_msp_i2s.h | |||
@@ -0,0 +1,553 @@ | |||
1 | /* | ||
2 | * Copyright (C) ST-Ericsson SA 2012 | ||
3 | * | ||
4 | * Author: Ola Lilja <ola.o.lilja@stericsson.com>, | ||
5 | * for ST-Ericsson. | ||
6 | * | ||
7 | * License terms: | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or modify | ||
10 | * it under the terms of the GNU General Public License version 2 as published | ||
11 | * by the Free Software Foundation. | ||
12 | */ | ||
13 | |||
14 | |||
15 | #ifndef UX500_MSP_I2S_H | ||
16 | #define UX500_MSP_I2S_H | ||
17 | |||
18 | #include <linux/platform_device.h> | ||
19 | |||
20 | #include <mach/board-mop500-msp.h> | ||
21 | |||
22 | #define MSP_INPUT_FREQ_APB 48000000 | ||
23 | |||
24 | /*** Stereo mode. Used for APB data accesses as 16 bits accesses (mono), | ||
25 | * 32 bits accesses (stereo). | ||
26 | ***/ | ||
27 | enum msp_stereo_mode { | ||
28 | MSP_MONO, | ||
29 | MSP_STEREO | ||
30 | }; | ||
31 | |||
32 | /* Direction (Transmit/Receive mode) */ | ||
33 | enum msp_direction { | ||
34 | MSP_TX = 1, | ||
35 | MSP_RX = 2 | ||
36 | }; | ||
37 | |||
38 | /* Transmit and receive configuration register */ | ||
39 | #define MSP_BIG_ENDIAN 0x00000000 | ||
40 | #define MSP_LITTLE_ENDIAN 0x00001000 | ||
41 | #define MSP_UNEXPECTED_FS_ABORT 0x00000000 | ||
42 | #define MSP_UNEXPECTED_FS_IGNORE 0x00008000 | ||
43 | #define MSP_NON_MODE_BIT_MASK 0x00009000 | ||
44 | |||
45 | /* Global configuration register */ | ||
46 | #define RX_ENABLE 0x00000001 | ||
47 | #define RX_FIFO_ENABLE 0x00000002 | ||
48 | #define RX_SYNC_SRG 0x00000010 | ||
49 | #define RX_CLK_POL_RISING 0x00000020 | ||
50 | #define RX_CLK_SEL_SRG 0x00000040 | ||
51 | #define TX_ENABLE 0x00000100 | ||
52 | #define TX_FIFO_ENABLE 0x00000200 | ||
53 | #define TX_SYNC_SRG_PROG 0x00001800 | ||
54 | #define TX_SYNC_SRG_AUTO 0x00001000 | ||
55 | #define TX_CLK_POL_RISING 0x00002000 | ||
56 | #define TX_CLK_SEL_SRG 0x00004000 | ||
57 | #define TX_EXTRA_DELAY_ENABLE 0x00008000 | ||
58 | #define SRG_ENABLE 0x00010000 | ||
59 | #define FRAME_GEN_ENABLE 0x00100000 | ||
60 | #define SRG_CLK_SEL_APB 0x00000000 | ||
61 | #define RX_FIFO_SYNC_HI 0x00000000 | ||
62 | #define TX_FIFO_SYNC_HI 0x00000000 | ||
63 | #define SPI_CLK_MODE_NORMAL 0x00000000 | ||
64 | |||
65 | #define MSP_FRAME_SIZE_AUTO -1 | ||
66 | |||
67 | #define MSP_DR 0x00 | ||
68 | #define MSP_GCR 0x04 | ||
69 | #define MSP_TCF 0x08 | ||
70 | #define MSP_RCF 0x0c | ||
71 | #define MSP_SRG 0x10 | ||
72 | #define MSP_FLR 0x14 | ||
73 | #define MSP_DMACR 0x18 | ||
74 | |||
75 | #define MSP_IMSC 0x20 | ||
76 | #define MSP_RIS 0x24 | ||
77 | #define MSP_MIS 0x28 | ||
78 | #define MSP_ICR 0x2c | ||
79 | #define MSP_MCR 0x30 | ||
80 | #define MSP_RCV 0x34 | ||
81 | #define MSP_RCM 0x38 | ||
82 | |||
83 | #define MSP_TCE0 0x40 | ||
84 | #define MSP_TCE1 0x44 | ||
85 | #define MSP_TCE2 0x48 | ||
86 | #define MSP_TCE3 0x4c | ||
87 | |||
88 | #define MSP_RCE0 0x60 | ||
89 | #define MSP_RCE1 0x64 | ||
90 | #define MSP_RCE2 0x68 | ||
91 | #define MSP_RCE3 0x6c | ||
92 | #define MSP_IODLY 0x70 | ||
93 | |||
94 | #define MSP_ITCR 0x80 | ||
95 | #define MSP_ITIP 0x84 | ||
96 | #define MSP_ITOP 0x88 | ||
97 | #define MSP_TSTDR 0x8c | ||
98 | |||
99 | #define MSP_PID0 0xfe0 | ||
100 | #define MSP_PID1 0xfe4 | ||
101 | #define MSP_PID2 0xfe8 | ||
102 | #define MSP_PID3 0xfec | ||
103 | |||
104 | #define MSP_CID0 0xff0 | ||
105 | #define MSP_CID1 0xff4 | ||
106 | #define MSP_CID2 0xff8 | ||
107 | #define MSP_CID3 0xffc | ||
108 | |||
109 | /* Protocol dependant parameters list */ | ||
110 | #define RX_ENABLE_MASK BIT(0) | ||
111 | #define RX_FIFO_ENABLE_MASK BIT(1) | ||
112 | #define RX_FSYNC_MASK BIT(2) | ||
113 | #define DIRECT_COMPANDING_MASK BIT(3) | ||
114 | #define RX_SYNC_SEL_MASK BIT(4) | ||
115 | #define RX_CLK_POL_MASK BIT(5) | ||
116 | #define RX_CLK_SEL_MASK BIT(6) | ||
117 | #define LOOPBACK_MASK BIT(7) | ||
118 | #define TX_ENABLE_MASK BIT(8) | ||
119 | #define TX_FIFO_ENABLE_MASK BIT(9) | ||
120 | #define TX_FSYNC_MASK BIT(10) | ||
121 | #define TX_MSP_TDR_TSR BIT(11) | ||
122 | #define TX_SYNC_SEL_MASK (BIT(12) | BIT(11)) | ||
123 | #define TX_CLK_POL_MASK BIT(13) | ||
124 | #define TX_CLK_SEL_MASK BIT(14) | ||
125 | #define TX_EXTRA_DELAY_MASK BIT(15) | ||
126 | #define SRG_ENABLE_MASK BIT(16) | ||
127 | #define SRG_CLK_POL_MASK BIT(17) | ||
128 | #define SRG_CLK_SEL_MASK (BIT(19) | BIT(18)) | ||
129 | #define FRAME_GEN_EN_MASK BIT(20) | ||
130 | #define SPI_CLK_MODE_MASK (BIT(22) | BIT(21)) | ||
131 | #define SPI_BURST_MODE_MASK BIT(23) | ||
132 | |||
133 | #define RXEN_SHIFT 0 | ||
134 | #define RFFEN_SHIFT 1 | ||
135 | #define RFSPOL_SHIFT 2 | ||
136 | #define DCM_SHIFT 3 | ||
137 | #define RFSSEL_SHIFT 4 | ||
138 | #define RCKPOL_SHIFT 5 | ||
139 | #define RCKSEL_SHIFT 6 | ||
140 | #define LBM_SHIFT 7 | ||
141 | #define TXEN_SHIFT 8 | ||
142 | #define TFFEN_SHIFT 9 | ||
143 | #define TFSPOL_SHIFT 10 | ||
144 | #define TFSSEL_SHIFT 11 | ||
145 | #define TCKPOL_SHIFT 13 | ||
146 | #define TCKSEL_SHIFT 14 | ||
147 | #define TXDDL_SHIFT 15 | ||
148 | #define SGEN_SHIFT 16 | ||
149 | #define SCKPOL_SHIFT 17 | ||
150 | #define SCKSEL_SHIFT 18 | ||
151 | #define FGEN_SHIFT 20 | ||
152 | #define SPICKM_SHIFT 21 | ||
153 | #define TBSWAP_SHIFT 28 | ||
154 | |||
155 | #define RCKPOL_MASK BIT(0) | ||
156 | #define TCKPOL_MASK BIT(0) | ||
157 | #define SPICKM_MASK (BIT(1) | BIT(0)) | ||
158 | #define MSP_RX_CLKPOL_BIT(n) ((n & RCKPOL_MASK) << RCKPOL_SHIFT) | ||
159 | #define MSP_TX_CLKPOL_BIT(n) ((n & TCKPOL_MASK) << TCKPOL_SHIFT) | ||
160 | |||
161 | #define P1ELEN_SHIFT 0 | ||
162 | #define P1FLEN_SHIFT 3 | ||
163 | #define DTYP_SHIFT 10 | ||
164 | #define ENDN_SHIFT 12 | ||
165 | #define DDLY_SHIFT 13 | ||
166 | #define FSIG_SHIFT 15 | ||
167 | #define P2ELEN_SHIFT 16 | ||
168 | #define P2FLEN_SHIFT 19 | ||
169 | #define P2SM_SHIFT 26 | ||
170 | #define P2EN_SHIFT 27 | ||
171 | #define FSYNC_SHIFT 15 | ||
172 | |||
173 | #define P1ELEN_MASK 0x00000007 | ||
174 | #define P2ELEN_MASK 0x00070000 | ||
175 | #define P1FLEN_MASK 0x00000378 | ||
176 | #define P2FLEN_MASK 0x03780000 | ||
177 | #define DDLY_MASK 0x00003000 | ||
178 | #define DTYP_MASK 0x00000600 | ||
179 | #define P2SM_MASK 0x04000000 | ||
180 | #define P2EN_MASK 0x08000000 | ||
181 | #define ENDN_MASK 0x00001000 | ||
182 | #define TFSPOL_MASK 0x00000400 | ||
183 | #define TBSWAP_MASK 0x30000000 | ||
184 | #define COMPANDING_MODE_MASK 0x00000c00 | ||
185 | #define FSYNC_MASK 0x00008000 | ||
186 | |||
187 | #define MSP_P1_ELEM_LEN_BITS(n) (n & P1ELEN_MASK) | ||
188 | #define MSP_P2_ELEM_LEN_BITS(n) (((n) << P2ELEN_SHIFT) & P2ELEN_MASK) | ||
189 | #define MSP_P1_FRAME_LEN_BITS(n) (((n) << P1FLEN_SHIFT) & P1FLEN_MASK) | ||
190 | #define MSP_P2_FRAME_LEN_BITS(n) (((n) << P2FLEN_SHIFT) & P2FLEN_MASK) | ||
191 | #define MSP_DATA_DELAY_BITS(n) (((n) << DDLY_SHIFT) & DDLY_MASK) | ||
192 | #define MSP_DATA_TYPE_BITS(n) (((n) << DTYP_SHIFT) & DTYP_MASK) | ||
193 | #define MSP_P2_START_MODE_BIT(n) ((n << P2SM_SHIFT) & P2SM_MASK) | ||
194 | #define MSP_P2_ENABLE_BIT(n) ((n << P2EN_SHIFT) & P2EN_MASK) | ||
195 | #define MSP_SET_ENDIANNES_BIT(n) ((n << ENDN_SHIFT) & ENDN_MASK) | ||
196 | #define MSP_FSYNC_POL(n) ((n << TFSPOL_SHIFT) & TFSPOL_MASK) | ||
197 | #define MSP_DATA_WORD_SWAP(n) ((n << TBSWAP_SHIFT) & TBSWAP_MASK) | ||
198 | #define MSP_SET_COMPANDING_MODE(n) ((n << DTYP_SHIFT) & \ | ||
199 | COMPANDING_MODE_MASK) | ||
200 | #define MSP_SET_FSYNC_IGNORE(n) ((n << FSYNC_SHIFT) & FSYNC_MASK) | ||
201 | |||
202 | /* Flag register */ | ||
203 | #define RX_BUSY BIT(0) | ||
204 | #define RX_FIFO_EMPTY BIT(1) | ||
205 | #define RX_FIFO_FULL BIT(2) | ||
206 | #define TX_BUSY BIT(3) | ||
207 | #define TX_FIFO_EMPTY BIT(4) | ||
208 | #define TX_FIFO_FULL BIT(5) | ||
209 | |||
210 | #define RBUSY_SHIFT 0 | ||
211 | #define RFE_SHIFT 1 | ||
212 | #define RFU_SHIFT 2 | ||
213 | #define TBUSY_SHIFT 3 | ||
214 | #define TFE_SHIFT 4 | ||
215 | #define TFU_SHIFT 5 | ||
216 | |||
217 | /* Multichannel control register */ | ||
218 | #define RMCEN_SHIFT 0 | ||
219 | #define RMCSF_SHIFT 1 | ||
220 | #define RCMPM_SHIFT 3 | ||
221 | #define TMCEN_SHIFT 5 | ||
222 | #define TNCSF_SHIFT 6 | ||
223 | |||
224 | /* Sample rate generator register */ | ||
225 | #define SCKDIV_SHIFT 0 | ||
226 | #define FRWID_SHIFT 10 | ||
227 | #define FRPER_SHIFT 16 | ||
228 | |||
229 | #define SCK_DIV_MASK 0x0000003FF | ||
230 | #define FRAME_WIDTH_BITS(n) (((n) << FRWID_SHIFT) & 0x0000FC00) | ||
231 | #define FRAME_PERIOD_BITS(n) (((n) << FRPER_SHIFT) & 0x1FFF0000) | ||
232 | |||
233 | /* DMA controller register */ | ||
234 | #define RX_DMA_ENABLE BIT(0) | ||
235 | #define TX_DMA_ENABLE BIT(1) | ||
236 | |||
237 | #define RDMAE_SHIFT 0 | ||
238 | #define TDMAE_SHIFT 1 | ||
239 | |||
240 | /* Interrupt Register */ | ||
241 | #define RX_SERVICE_INT BIT(0) | ||
242 | #define RX_OVERRUN_ERROR_INT BIT(1) | ||
243 | #define RX_FSYNC_ERR_INT BIT(2) | ||
244 | #define RX_FSYNC_INT BIT(3) | ||
245 | #define TX_SERVICE_INT BIT(4) | ||
246 | #define TX_UNDERRUN_ERR_INT BIT(5) | ||
247 | #define TX_FSYNC_ERR_INT BIT(6) | ||
248 | #define TX_FSYNC_INT BIT(7) | ||
249 | #define ALL_INT 0x000000ff | ||
250 | |||
251 | /* MSP test control register */ | ||
252 | #define MSP_ITCR_ITEN BIT(0) | ||
253 | #define MSP_ITCR_TESTFIFO BIT(1) | ||
254 | |||
255 | #define RMCEN_BIT 0 | ||
256 | #define RMCSF_BIT 1 | ||
257 | #define RCMPM_BIT 3 | ||
258 | #define TMCEN_BIT 5 | ||
259 | #define TNCSF_BIT 6 | ||
260 | |||
261 | /* Single or dual phase mode */ | ||
262 | enum msp_phase_mode { | ||
263 | MSP_SINGLE_PHASE, | ||
264 | MSP_DUAL_PHASE | ||
265 | }; | ||
266 | |||
267 | /* Frame length */ | ||
268 | enum msp_frame_length { | ||
269 | MSP_FRAME_LEN_1 = 0, | ||
270 | MSP_FRAME_LEN_2 = 1, | ||
271 | MSP_FRAME_LEN_4 = 3, | ||
272 | MSP_FRAME_LEN_8 = 7, | ||
273 | MSP_FRAME_LEN_12 = 11, | ||
274 | MSP_FRAME_LEN_16 = 15, | ||
275 | MSP_FRAME_LEN_20 = 19, | ||
276 | MSP_FRAME_LEN_32 = 31, | ||
277 | MSP_FRAME_LEN_48 = 47, | ||
278 | MSP_FRAME_LEN_64 = 63 | ||
279 | }; | ||
280 | |||
281 | /* Element length */ | ||
282 | enum msp_elem_length { | ||
283 | MSP_ELEM_LEN_8 = 0, | ||
284 | MSP_ELEM_LEN_10 = 1, | ||
285 | MSP_ELEM_LEN_12 = 2, | ||
286 | MSP_ELEM_LEN_14 = 3, | ||
287 | MSP_ELEM_LEN_16 = 4, | ||
288 | MSP_ELEM_LEN_20 = 5, | ||
289 | MSP_ELEM_LEN_24 = 6, | ||
290 | MSP_ELEM_LEN_32 = 7 | ||
291 | }; | ||
292 | |||
293 | enum msp_data_xfer_width { | ||
294 | MSP_DATA_TRANSFER_WIDTH_BYTE, | ||
295 | MSP_DATA_TRANSFER_WIDTH_HALFWORD, | ||
296 | MSP_DATA_TRANSFER_WIDTH_WORD | ||
297 | }; | ||
298 | |||
299 | enum msp_frame_sync { | ||
300 | MSP_FSYNC_UNIGNORE = 0, | ||
301 | MSP_FSYNC_IGNORE = 1, | ||
302 | }; | ||
303 | |||
304 | enum msp_phase2_start_mode { | ||
305 | MSP_PHASE2_START_MODE_IMEDIATE, | ||
306 | MSP_PHASE2_START_MODE_FSYNC | ||
307 | }; | ||
308 | |||
309 | enum msp_btf { | ||
310 | MSP_BTF_MS_BIT_FIRST = 0, | ||
311 | MSP_BTF_LS_BIT_FIRST = 1 | ||
312 | }; | ||
313 | |||
314 | enum msp_fsync_pol { | ||
315 | MSP_FSYNC_POL_ACT_HI = 0, | ||
316 | MSP_FSYNC_POL_ACT_LO = 1 | ||
317 | }; | ||
318 | |||
319 | /* Data delay (in bit clock cycles) */ | ||
320 | enum msp_delay { | ||
321 | MSP_DELAY_0 = 0, | ||
322 | MSP_DELAY_1 = 1, | ||
323 | MSP_DELAY_2 = 2, | ||
324 | MSP_DELAY_3 = 3 | ||
325 | }; | ||
326 | |||
327 | /* Configurations of clocks (transmit, receive or sample rate generator) */ | ||
328 | enum msp_edge { | ||
329 | MSP_FALLING_EDGE = 0, | ||
330 | MSP_RISING_EDGE = 1, | ||
331 | }; | ||
332 | |||
333 | enum msp_hws { | ||
334 | MSP_SWAP_NONE = 0, | ||
335 | MSP_SWAP_BYTE_PER_WORD = 1, | ||
336 | MSP_SWAP_BYTE_PER_HALF_WORD = 2, | ||
337 | MSP_SWAP_HALF_WORD_PER_WORD = 3 | ||
338 | }; | ||
339 | |||
340 | enum msp_compress_mode { | ||
341 | MSP_COMPRESS_MODE_LINEAR = 0, | ||
342 | MSP_COMPRESS_MODE_MU_LAW = 2, | ||
343 | MSP_COMPRESS_MODE_A_LAW = 3 | ||
344 | }; | ||
345 | |||
346 | enum msp_spi_burst_mode { | ||
347 | MSP_SPI_BURST_MODE_DISABLE = 0, | ||
348 | MSP_SPI_BURST_MODE_ENABLE = 1 | ||
349 | }; | ||
350 | |||
351 | enum msp_expand_mode { | ||
352 | MSP_EXPAND_MODE_LINEAR = 0, | ||
353 | MSP_EXPAND_MODE_LINEAR_SIGNED = 1, | ||
354 | MSP_EXPAND_MODE_MU_LAW = 2, | ||
355 | MSP_EXPAND_MODE_A_LAW = 3 | ||
356 | }; | ||
357 | |||
358 | #define MSP_FRAME_PERIOD_IN_MONO_MODE 256 | ||
359 | #define MSP_FRAME_PERIOD_IN_STEREO_MODE 32 | ||
360 | #define MSP_FRAME_WIDTH_IN_STEREO_MODE 16 | ||
361 | |||
362 | enum msp_protocol { | ||
363 | MSP_I2S_PROTOCOL, | ||
364 | MSP_PCM_PROTOCOL, | ||
365 | MSP_PCM_COMPAND_PROTOCOL, | ||
366 | MSP_INVALID_PROTOCOL | ||
367 | }; | ||
368 | |||
369 | /* | ||
370 | * No of registers to backup during | ||
371 | * suspend resume | ||
372 | */ | ||
373 | #define MAX_MSP_BACKUP_REGS 36 | ||
374 | |||
375 | enum enum_i2s_controller { | ||
376 | MSP_0_I2S_CONTROLLER = 0, | ||
377 | MSP_1_I2S_CONTROLLER, | ||
378 | MSP_2_I2S_CONTROLLER, | ||
379 | MSP_3_I2S_CONTROLLER, | ||
380 | }; | ||
381 | |||
382 | enum i2s_direction_t { | ||
383 | MSP_DIR_TX = 0x01, | ||
384 | MSP_DIR_RX = 0x02, | ||
385 | }; | ||
386 | |||
387 | enum msp_data_size { | ||
388 | MSP_DATA_BITS_DEFAULT = -1, | ||
389 | MSP_DATA_BITS_8 = 0x00, | ||
390 | MSP_DATA_BITS_10, | ||
391 | MSP_DATA_BITS_12, | ||
392 | MSP_DATA_BITS_14, | ||
393 | MSP_DATA_BITS_16, | ||
394 | MSP_DATA_BITS_20, | ||
395 | MSP_DATA_BITS_24, | ||
396 | MSP_DATA_BITS_32, | ||
397 | }; | ||
398 | |||
399 | enum msp_state { | ||
400 | MSP_STATE_IDLE = 0, | ||
401 | MSP_STATE_CONFIGURED = 1, | ||
402 | MSP_STATE_RUNNING = 2, | ||
403 | }; | ||
404 | |||
405 | enum msp_rx_comparison_enable_mode { | ||
406 | MSP_COMPARISON_DISABLED = 0, | ||
407 | MSP_COMPARISON_NONEQUAL_ENABLED = 2, | ||
408 | MSP_COMPARISON_EQUAL_ENABLED = 3 | ||
409 | }; | ||
410 | |||
411 | struct msp_multichannel_config { | ||
412 | bool rx_multichannel_enable; | ||
413 | bool tx_multichannel_enable; | ||
414 | enum msp_rx_comparison_enable_mode rx_comparison_enable_mode; | ||
415 | u8 padding; | ||
416 | u32 comparison_value; | ||
417 | u32 comparison_mask; | ||
418 | u32 rx_channel_0_enable; | ||
419 | u32 rx_channel_1_enable; | ||
420 | u32 rx_channel_2_enable; | ||
421 | u32 rx_channel_3_enable; | ||
422 | u32 tx_channel_0_enable; | ||
423 | u32 tx_channel_1_enable; | ||
424 | u32 tx_channel_2_enable; | ||
425 | u32 tx_channel_3_enable; | ||
426 | }; | ||
427 | |||
428 | struct msp_protdesc { | ||
429 | u32 rx_phase_mode; | ||
430 | u32 tx_phase_mode; | ||
431 | u32 rx_phase2_start_mode; | ||
432 | u32 tx_phase2_start_mode; | ||
433 | u32 rx_byte_order; | ||
434 | u32 tx_byte_order; | ||
435 | u32 rx_frame_len_1; | ||
436 | u32 rx_frame_len_2; | ||
437 | u32 tx_frame_len_1; | ||
438 | u32 tx_frame_len_2; | ||
439 | u32 rx_elem_len_1; | ||
440 | u32 rx_elem_len_2; | ||
441 | u32 tx_elem_len_1; | ||
442 | u32 tx_elem_len_2; | ||
443 | u32 rx_data_delay; | ||
444 | u32 tx_data_delay; | ||
445 | u32 rx_clk_pol; | ||
446 | u32 tx_clk_pol; | ||
447 | u32 rx_fsync_pol; | ||
448 | u32 tx_fsync_pol; | ||
449 | u32 rx_half_word_swap; | ||
450 | u32 tx_half_word_swap; | ||
451 | u32 compression_mode; | ||
452 | u32 expansion_mode; | ||
453 | u32 frame_sync_ignore; | ||
454 | u32 frame_period; | ||
455 | u32 frame_width; | ||
456 | u32 clocks_per_frame; | ||
457 | }; | ||
458 | |||
459 | struct i2s_message { | ||
460 | enum i2s_direction_t i2s_direction; | ||
461 | void *txdata; | ||
462 | void *rxdata; | ||
463 | size_t txbytes; | ||
464 | size_t rxbytes; | ||
465 | int dma_flag; | ||
466 | int tx_offset; | ||
467 | int rx_offset; | ||
468 | bool cyclic_dma; | ||
469 | dma_addr_t buf_addr; | ||
470 | size_t buf_len; | ||
471 | size_t period_len; | ||
472 | }; | ||
473 | |||
474 | struct i2s_controller { | ||
475 | struct module *owner; | ||
476 | unsigned int id; | ||
477 | unsigned int class; | ||
478 | const struct i2s_algorithm *algo; /* the algorithm to access the bus */ | ||
479 | void *data; | ||
480 | struct mutex bus_lock; | ||
481 | struct device dev; /* the controller device */ | ||
482 | char name[48]; | ||
483 | }; | ||
484 | |||
485 | struct ux500_msp_config { | ||
486 | unsigned int f_inputclk; | ||
487 | unsigned int rx_clk_sel; | ||
488 | unsigned int tx_clk_sel; | ||
489 | unsigned int srg_clk_sel; | ||
490 | unsigned int rx_fsync_pol; | ||
491 | unsigned int tx_fsync_pol; | ||
492 | unsigned int rx_fsync_sel; | ||
493 | unsigned int tx_fsync_sel; | ||
494 | unsigned int rx_fifo_config; | ||
495 | unsigned int tx_fifo_config; | ||
496 | unsigned int spi_clk_mode; | ||
497 | unsigned int spi_burst_mode; | ||
498 | unsigned int loopback_enable; | ||
499 | unsigned int tx_data_enable; | ||
500 | unsigned int default_protdesc; | ||
501 | struct msp_protdesc protdesc; | ||
502 | int multichannel_configured; | ||
503 | struct msp_multichannel_config multichannel_config; | ||
504 | unsigned int direction; | ||
505 | unsigned int protocol; | ||
506 | unsigned int frame_freq; | ||
507 | unsigned int frame_size; | ||
508 | enum msp_data_size data_size; | ||
509 | unsigned int def_elem_len; | ||
510 | unsigned int iodelay; | ||
511 | void (*handler) (void *data); | ||
512 | void *tx_callback_data; | ||
513 | void *rx_callback_data; | ||
514 | }; | ||
515 | |||
516 | struct ux500_msp { | ||
517 | enum enum_i2s_controller id; | ||
518 | void __iomem *registers; | ||
519 | struct device *dev; | ||
520 | struct i2s_controller *i2s_cont; | ||
521 | struct stedma40_chan_cfg *dma_cfg_rx; | ||
522 | struct stedma40_chan_cfg *dma_cfg_tx; | ||
523 | struct dma_chan *tx_pipeid; | ||
524 | struct dma_chan *rx_pipeid; | ||
525 | enum msp_state msp_state; | ||
526 | int (*transfer) (struct ux500_msp *msp, struct i2s_message *message); | ||
527 | int (*plat_init) (void); | ||
528 | int (*plat_exit) (void); | ||
529 | struct timer_list notify_timer; | ||
530 | int def_elem_len; | ||
531 | unsigned int dir_busy; | ||
532 | int loopback_enable; | ||
533 | u32 backup_regs[MAX_MSP_BACKUP_REGS]; | ||
534 | unsigned int f_bitclk; | ||
535 | }; | ||
536 | |||
537 | struct ux500_msp_dma_params { | ||
538 | unsigned int data_size; | ||
539 | struct stedma40_chan_cfg *dma_cfg; | ||
540 | }; | ||
541 | |||
542 | int ux500_msp_i2s_init_msp(struct platform_device *pdev, | ||
543 | struct ux500_msp **msp_p, | ||
544 | struct msp_i2s_platform_data *platform_data); | ||
545 | void ux500_msp_i2s_cleanup_msp(struct platform_device *pdev, | ||
546 | struct ux500_msp *msp); | ||
547 | int ux500_msp_i2s_open(struct ux500_msp *msp, struct ux500_msp_config *config); | ||
548 | int ux500_msp_i2s_close(struct ux500_msp *msp, | ||
549 | unsigned int dir); | ||
550 | int ux500_msp_i2s_trigger(struct ux500_msp *msp, int cmd, | ||
551 | int direction); | ||
552 | |||
553 | #endif | ||
diff --git a/sound/sound_core.c b/sound/sound_core.c index c6e81fb928e9..fb9255cca214 100644 --- a/sound/sound_core.c +++ b/sound/sound_core.c | |||
@@ -361,7 +361,7 @@ int register_sound_special_device(const struct file_operations *fops, int unit, | |||
361 | struct device *dev) | 361 | struct device *dev) |
362 | { | 362 | { |
363 | const int chain = unit % SOUND_STEP; | 363 | const int chain = unit % SOUND_STEP; |
364 | int max_unit = 128 + chain; | 364 | int max_unit = 256; |
365 | const char *name; | 365 | const char *name; |
366 | char _name[16]; | 366 | char _name[16]; |
367 | 367 | ||
diff --git a/sound/usb/card.c b/sound/usb/card.c index 4a7be7b98331..d5b5c3388e28 100644 --- a/sound/usb/card.c +++ b/sound/usb/card.c | |||
@@ -131,8 +131,9 @@ static void snd_usb_stream_disconnect(struct list_head *head) | |||
131 | subs = &as->substream[idx]; | 131 | subs = &as->substream[idx]; |
132 | if (!subs->num_formats) | 132 | if (!subs->num_formats) |
133 | continue; | 133 | continue; |
134 | snd_usb_release_substream_urbs(subs, 1); | ||
135 | subs->interface = -1; | 134 | subs->interface = -1; |
135 | subs->data_endpoint = NULL; | ||
136 | subs->sync_endpoint = NULL; | ||
136 | } | 137 | } |
137 | } | 138 | } |
138 | 139 | ||
@@ -276,6 +277,7 @@ static int snd_usb_create_streams(struct snd_usb_audio *chip, int ctrlif) | |||
276 | 277 | ||
277 | static int snd_usb_audio_free(struct snd_usb_audio *chip) | 278 | static int snd_usb_audio_free(struct snd_usb_audio *chip) |
278 | { | 279 | { |
280 | mutex_destroy(&chip->mutex); | ||
279 | kfree(chip); | 281 | kfree(chip); |
280 | return 0; | 282 | return 0; |
281 | } | 283 | } |
@@ -336,6 +338,7 @@ static int snd_usb_audio_create(struct usb_device *dev, int idx, | |||
336 | return -ENOMEM; | 338 | return -ENOMEM; |
337 | } | 339 | } |
338 | 340 | ||
341 | mutex_init(&chip->mutex); | ||
339 | mutex_init(&chip->shutdown_mutex); | 342 | mutex_init(&chip->shutdown_mutex); |
340 | chip->index = idx; | 343 | chip->index = idx; |
341 | chip->dev = dev; | 344 | chip->dev = dev; |
@@ -348,6 +351,7 @@ static int snd_usb_audio_create(struct usb_device *dev, int idx, | |||
348 | chip->usb_id = USB_ID(le16_to_cpu(dev->descriptor.idVendor), | 351 | chip->usb_id = USB_ID(le16_to_cpu(dev->descriptor.idVendor), |
349 | le16_to_cpu(dev->descriptor.idProduct)); | 352 | le16_to_cpu(dev->descriptor.idProduct)); |
350 | INIT_LIST_HEAD(&chip->pcm_list); | 353 | INIT_LIST_HEAD(&chip->pcm_list); |
354 | INIT_LIST_HEAD(&chip->ep_list); | ||
351 | INIT_LIST_HEAD(&chip->midi_list); | 355 | INIT_LIST_HEAD(&chip->midi_list); |
352 | INIT_LIST_HEAD(&chip->mixer_list); | 356 | INIT_LIST_HEAD(&chip->mixer_list); |
353 | 357 | ||
@@ -565,6 +569,10 @@ static void snd_usb_audio_disconnect(struct usb_device *dev, | |||
565 | list_for_each(p, &chip->pcm_list) { | 569 | list_for_each(p, &chip->pcm_list) { |
566 | snd_usb_stream_disconnect(p); | 570 | snd_usb_stream_disconnect(p); |
567 | } | 571 | } |
572 | /* release the endpoint resources */ | ||
573 | list_for_each(p, &chip->ep_list) { | ||
574 | snd_usb_endpoint_free(p); | ||
575 | } | ||
568 | /* release the midi resources */ | 576 | /* release the midi resources */ |
569 | list_for_each(p, &chip->midi_list) { | 577 | list_for_each(p, &chip->midi_list) { |
570 | snd_usbmidi_disconnect(p); | 578 | snd_usbmidi_disconnect(p); |
diff --git a/sound/usb/card.h b/sound/usb/card.h index da5fa1ac4eda..0d37238b8457 100644 --- a/sound/usb/card.h +++ b/sound/usb/card.h | |||
@@ -30,20 +30,71 @@ struct audioformat { | |||
30 | }; | 30 | }; |
31 | 31 | ||
32 | struct snd_usb_substream; | 32 | struct snd_usb_substream; |
33 | struct snd_usb_endpoint; | ||
33 | 34 | ||
34 | struct snd_urb_ctx { | 35 | struct snd_urb_ctx { |
35 | struct urb *urb; | 36 | struct urb *urb; |
36 | unsigned int buffer_size; /* size of data buffer, if data URB */ | 37 | unsigned int buffer_size; /* size of data buffer, if data URB */ |
37 | struct snd_usb_substream *subs; | 38 | struct snd_usb_substream *subs; |
39 | struct snd_usb_endpoint *ep; | ||
38 | int index; /* index for urb array */ | 40 | int index; /* index for urb array */ |
39 | int packets; /* number of packets per urb */ | 41 | int packets; /* number of packets per urb */ |
42 | int packet_size[MAX_PACKS_HS]; /* size of packets for next submission */ | ||
43 | struct list_head ready_list; | ||
40 | }; | 44 | }; |
41 | 45 | ||
42 | struct snd_urb_ops { | 46 | struct snd_usb_endpoint { |
43 | int (*prepare)(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *u); | 47 | struct snd_usb_audio *chip; |
44 | int (*retire)(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *u); | 48 | |
45 | int (*prepare_sync)(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *u); | 49 | int use_count; |
46 | int (*retire_sync)(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *u); | 50 | int ep_num; /* the referenced endpoint number */ |
51 | int type; /* SND_USB_ENDPOINT_TYPE_* */ | ||
52 | unsigned long flags; | ||
53 | |||
54 | void (*prepare_data_urb) (struct snd_usb_substream *subs, | ||
55 | struct urb *urb); | ||
56 | void (*retire_data_urb) (struct snd_usb_substream *subs, | ||
57 | struct urb *urb); | ||
58 | |||
59 | struct snd_usb_substream *data_subs; | ||
60 | struct snd_usb_endpoint *sync_master; | ||
61 | struct snd_usb_endpoint *sync_slave; | ||
62 | |||
63 | struct snd_urb_ctx urb[MAX_URBS]; | ||
64 | |||
65 | struct snd_usb_packet_info { | ||
66 | uint32_t packet_size[MAX_PACKS_HS]; | ||
67 | int packets; | ||
68 | } next_packet[MAX_URBS]; | ||
69 | int next_packet_read_pos, next_packet_write_pos; | ||
70 | struct list_head ready_playback_urbs; | ||
71 | |||
72 | unsigned int nurbs; /* # urbs */ | ||
73 | unsigned long active_mask; /* bitmask of active urbs */ | ||
74 | unsigned long unlink_mask; /* bitmask of unlinked urbs */ | ||
75 | char *syncbuf; /* sync buffer for all sync URBs */ | ||
76 | dma_addr_t sync_dma; /* DMA address of syncbuf */ | ||
77 | |||
78 | unsigned int pipe; /* the data i/o pipe */ | ||
79 | unsigned int freqn; /* nominal sampling rate in fs/fps in Q16.16 format */ | ||
80 | unsigned int freqm; /* momentary sampling rate in fs/fps in Q16.16 format */ | ||
81 | int freqshift; /* how much to shift the feedback value to get Q16.16 */ | ||
82 | unsigned int freqmax; /* maximum sampling rate, used for buffer management */ | ||
83 | unsigned int phase; /* phase accumulator */ | ||
84 | unsigned int maxpacksize; /* max packet size in bytes */ | ||
85 | unsigned int maxframesize; /* max packet size in frames */ | ||
86 | unsigned int curpacksize; /* current packet size in bytes (for capture) */ | ||
87 | unsigned int curframesize; /* current packet size in frames (for capture) */ | ||
88 | unsigned int syncmaxsize; /* sync endpoint packet size */ | ||
89 | unsigned int fill_max:1; /* fill max packet size always */ | ||
90 | unsigned int datainterval; /* log_2 of data packet interval */ | ||
91 | unsigned int syncinterval; /* P for adaptive mode, 0 otherwise */ | ||
92 | unsigned char silence_value; | ||
93 | unsigned int stride; | ||
94 | int iface, alt_idx; | ||
95 | |||
96 | spinlock_t lock; | ||
97 | struct list_head list; | ||
47 | }; | 98 | }; |
48 | 99 | ||
49 | struct snd_usb_substream { | 100 | struct snd_usb_substream { |
@@ -57,21 +108,6 @@ struct snd_usb_substream { | |||
57 | unsigned int cur_rate; /* current rate (for hw_params callback) */ | 108 | unsigned int cur_rate; /* current rate (for hw_params callback) */ |
58 | unsigned int period_bytes; /* current period bytes (for hw_params callback) */ | 109 | unsigned int period_bytes; /* current period bytes (for hw_params callback) */ |
59 | unsigned int altset_idx; /* USB data format: index of alternate setting */ | 110 | unsigned int altset_idx; /* USB data format: index of alternate setting */ |
60 | unsigned int datapipe; /* the data i/o pipe */ | ||
61 | unsigned int syncpipe; /* 1 - async out or adaptive in */ | ||
62 | unsigned int datainterval; /* log_2 of data packet interval */ | ||
63 | unsigned int syncinterval; /* P for adaptive mode, 0 otherwise */ | ||
64 | unsigned int freqn; /* nominal sampling rate in fs/fps in Q16.16 format */ | ||
65 | unsigned int freqm; /* momentary sampling rate in fs/fps in Q16.16 format */ | ||
66 | int freqshift; /* how much to shift the feedback value to get Q16.16 */ | ||
67 | unsigned int freqmax; /* maximum sampling rate, used for buffer management */ | ||
68 | unsigned int phase; /* phase accumulator */ | ||
69 | unsigned int maxpacksize; /* max packet size in bytes */ | ||
70 | unsigned int maxframesize; /* max packet size in frames */ | ||
71 | unsigned int curpacksize; /* current packet size in bytes (for capture) */ | ||
72 | unsigned int curframesize; /* current packet size in frames (for capture) */ | ||
73 | unsigned int syncmaxsize; /* sync endpoint packet size */ | ||
74 | unsigned int fill_max: 1; /* fill max packet size always */ | ||
75 | unsigned int txfr_quirk:1; /* allow sub-frame alignment */ | 111 | unsigned int txfr_quirk:1; /* allow sub-frame alignment */ |
76 | unsigned int fmt_type; /* USB audio format type (1-3) */ | 112 | unsigned int fmt_type; /* USB audio format type (1-3) */ |
77 | 113 | ||
@@ -82,11 +118,10 @@ struct snd_usb_substream { | |||
82 | unsigned long active_mask; /* bitmask of active urbs */ | 118 | unsigned long active_mask; /* bitmask of active urbs */ |
83 | unsigned long unlink_mask; /* bitmask of unlinked urbs */ | 119 | unsigned long unlink_mask; /* bitmask of unlinked urbs */ |
84 | 120 | ||
85 | unsigned int nurbs; /* # urbs */ | 121 | /* data and sync endpoints for this stream */ |
86 | struct snd_urb_ctx dataurb[MAX_URBS]; /* data urb table */ | 122 | struct snd_usb_endpoint *data_endpoint; |
87 | struct snd_urb_ctx syncurb[SYNC_URBS]; /* sync urb table */ | 123 | struct snd_usb_endpoint *sync_endpoint; |
88 | char *syncbuf; /* sync buffer for all sync URBs */ | 124 | unsigned long flags; |
89 | dma_addr_t sync_dma; /* DMA address of syncbuf */ | ||
90 | 125 | ||
91 | u64 formats; /* format bitmasks (all or'ed) */ | 126 | u64 formats; /* format bitmasks (all or'ed) */ |
92 | unsigned int num_formats; /* number of supported audio formats (list) */ | 127 | unsigned int num_formats; /* number of supported audio formats (list) */ |
@@ -94,7 +129,6 @@ struct snd_usb_substream { | |||
94 | struct snd_pcm_hw_constraint_list rate_list; /* limited rates */ | 129 | struct snd_pcm_hw_constraint_list rate_list; /* limited rates */ |
95 | spinlock_t lock; | 130 | spinlock_t lock; |
96 | 131 | ||
97 | struct snd_urb_ops ops; /* callbacks (must be filled at init) */ | ||
98 | int last_frame_number; /* stored frame number */ | 132 | int last_frame_number; /* stored frame number */ |
99 | int last_delay; /* stored delay */ | 133 | int last_delay; /* stored delay */ |
100 | }; | 134 | }; |
diff --git a/sound/usb/endpoint.c b/sound/usb/endpoint.c index 08dcce53720b..e6906901debb 100644 --- a/sound/usb/endpoint.c +++ b/sound/usb/endpoint.c | |||
@@ -20,9 +20,11 @@ | |||
20 | #include <linux/ratelimit.h> | 20 | #include <linux/ratelimit.h> |
21 | #include <linux/usb.h> | 21 | #include <linux/usb.h> |
22 | #include <linux/usb/audio.h> | 22 | #include <linux/usb/audio.h> |
23 | #include <linux/slab.h> | ||
23 | 24 | ||
24 | #include <sound/core.h> | 25 | #include <sound/core.h> |
25 | #include <sound/pcm.h> | 26 | #include <sound/pcm.h> |
27 | #include <sound/pcm_params.h> | ||
26 | 28 | ||
27 | #include "usbaudio.h" | 29 | #include "usbaudio.h" |
28 | #include "helper.h" | 30 | #include "helper.h" |
@@ -30,6 +32,36 @@ | |||
30 | #include "endpoint.h" | 32 | #include "endpoint.h" |
31 | #include "pcm.h" | 33 | #include "pcm.h" |
32 | 34 | ||
35 | #define EP_FLAG_ACTIVATED 0 | ||
36 | #define EP_FLAG_RUNNING 1 | ||
37 | |||
38 | /* | ||
39 | * snd_usb_endpoint is a model that abstracts everything related to an | ||
40 | * USB endpoint and its streaming. | ||
41 | * | ||
42 | * There are functions to activate and deactivate the streaming URBs and | ||
43 | * optional callbacks to let the pcm logic handle the actual content of the | ||
44 | * packets for playback and record. Thus, the bus streaming and the audio | ||
45 | * handlers are fully decoupled. | ||
46 | * | ||
47 | * There are two different types of endpoints in audio applications. | ||
48 | * | ||
49 | * SND_USB_ENDPOINT_TYPE_DATA handles full audio data payload for both | ||
50 | * inbound and outbound traffic. | ||
51 | * | ||
52 | * SND_USB_ENDPOINT_TYPE_SYNC endpoints are for inbound traffic only and | ||
53 | * expect the payload to carry Q10.14 / Q16.16 formatted sync information | ||
54 | * (3 or 4 bytes). | ||
55 | * | ||
56 | * Each endpoint has to be configured prior to being used by calling | ||
57 | * snd_usb_endpoint_set_params(). | ||
58 | * | ||
59 | * The model incorporates a reference counting, so that multiple users | ||
60 | * can call snd_usb_endpoint_start() and snd_usb_endpoint_stop(), and | ||
61 | * only the first user will effectively start the URBs, and only the last | ||
62 | * one to stop it will tear the URBs down again. | ||
63 | */ | ||
64 | |||
33 | /* | 65 | /* |
34 | * convert a sampling rate into our full speed format (fs/1000 in Q16.16) | 66 | * convert a sampling rate into our full speed format (fs/1000 in Q16.16) |
35 | * this will overflow at approx 524 kHz | 67 | * this will overflow at approx 524 kHz |
@@ -49,71 +81,415 @@ static inline unsigned get_usb_high_speed_rate(unsigned int rate) | |||
49 | } | 81 | } |
50 | 82 | ||
51 | /* | 83 | /* |
52 | * unlink active urbs. | 84 | * release a urb data |
53 | */ | 85 | */ |
54 | static int deactivate_urbs(struct snd_usb_substream *subs, int force, int can_sleep) | 86 | static void release_urb_ctx(struct snd_urb_ctx *u) |
55 | { | 87 | { |
56 | struct snd_usb_audio *chip = subs->stream->chip; | 88 | if (u->buffer_size) |
57 | unsigned int i; | 89 | usb_free_coherent(u->ep->chip->dev, u->buffer_size, |
58 | int async; | 90 | u->urb->transfer_buffer, |
91 | u->urb->transfer_dma); | ||
92 | usb_free_urb(u->urb); | ||
93 | u->urb = NULL; | ||
94 | } | ||
95 | |||
96 | static const char *usb_error_string(int err) | ||
97 | { | ||
98 | switch (err) { | ||
99 | case -ENODEV: | ||
100 | return "no device"; | ||
101 | case -ENOENT: | ||
102 | return "endpoint not enabled"; | ||
103 | case -EPIPE: | ||
104 | return "endpoint stalled"; | ||
105 | case -ENOSPC: | ||
106 | return "not enough bandwidth"; | ||
107 | case -ESHUTDOWN: | ||
108 | return "device disabled"; | ||
109 | case -EHOSTUNREACH: | ||
110 | return "device suspended"; | ||
111 | case -EINVAL: | ||
112 | case -EAGAIN: | ||
113 | case -EFBIG: | ||
114 | case -EMSGSIZE: | ||
115 | return "internal error"; | ||
116 | default: | ||
117 | return "unknown error"; | ||
118 | } | ||
119 | } | ||
120 | |||
121 | /** | ||
122 | * snd_usb_endpoint_implicit_feedback_sink: Report endpoint usage type | ||
123 | * | ||
124 | * @ep: The snd_usb_endpoint | ||
125 | * | ||
126 | * Determine whether an endpoint is driven by an implicit feedback | ||
127 | * data endpoint source. | ||
128 | */ | ||
129 | int snd_usb_endpoint_implict_feedback_sink(struct snd_usb_endpoint *ep) | ||
130 | { | ||
131 | return ep->sync_master && | ||
132 | ep->sync_master->type == SND_USB_ENDPOINT_TYPE_DATA && | ||
133 | ep->type == SND_USB_ENDPOINT_TYPE_DATA && | ||
134 | usb_pipeout(ep->pipe); | ||
135 | } | ||
59 | 136 | ||
60 | subs->running = 0; | 137 | /* |
138 | * For streaming based on information derived from sync endpoints, | ||
139 | * prepare_outbound_urb_sizes() will call next_packet_size() to | ||
140 | * determine the number of samples to be sent in the next packet. | ||
141 | * | ||
142 | * For implicit feedback, next_packet_size() is unused. | ||
143 | */ | ||
144 | static int next_packet_size(struct snd_usb_endpoint *ep) | ||
145 | { | ||
146 | unsigned long flags; | ||
147 | int ret; | ||
61 | 148 | ||
62 | if (!force && subs->stream->chip->shutdown) /* to be sure... */ | 149 | if (ep->fill_max) |
63 | return -EBADFD; | 150 | return ep->maxframesize; |
64 | 151 | ||
65 | async = !can_sleep && chip->async_unlink; | 152 | spin_lock_irqsave(&ep->lock, flags); |
153 | ep->phase = (ep->phase & 0xffff) | ||
154 | + (ep->freqm << ep->datainterval); | ||
155 | ret = min(ep->phase >> 16, ep->maxframesize); | ||
156 | spin_unlock_irqrestore(&ep->lock, flags); | ||
66 | 157 | ||
67 | if (!async && in_interrupt()) | 158 | return ret; |
68 | return 0; | 159 | } |
69 | 160 | ||
70 | for (i = 0; i < subs->nurbs; i++) { | 161 | static void retire_outbound_urb(struct snd_usb_endpoint *ep, |
71 | if (test_bit(i, &subs->active_mask)) { | 162 | struct snd_urb_ctx *urb_ctx) |
72 | if (!test_and_set_bit(i, &subs->unlink_mask)) { | 163 | { |
73 | struct urb *u = subs->dataurb[i].urb; | 164 | if (ep->retire_data_urb) |
74 | if (async) | 165 | ep->retire_data_urb(ep->data_subs, urb_ctx->urb); |
75 | usb_unlink_urb(u); | 166 | } |
76 | else | 167 | |
77 | usb_kill_urb(u); | 168 | static void retire_inbound_urb(struct snd_usb_endpoint *ep, |
169 | struct snd_urb_ctx *urb_ctx) | ||
170 | { | ||
171 | struct urb *urb = urb_ctx->urb; | ||
172 | |||
173 | if (ep->sync_slave) | ||
174 | snd_usb_handle_sync_urb(ep->sync_slave, ep, urb); | ||
175 | |||
176 | if (ep->retire_data_urb) | ||
177 | ep->retire_data_urb(ep->data_subs, urb); | ||
178 | } | ||
179 | |||
180 | static void prepare_outbound_urb_sizes(struct snd_usb_endpoint *ep, | ||
181 | struct snd_urb_ctx *ctx) | ||
182 | { | ||
183 | int i; | ||
184 | |||
185 | for (i = 0; i < ctx->packets; ++i) | ||
186 | ctx->packet_size[i] = next_packet_size(ep); | ||
187 | } | ||
188 | |||
189 | /* | ||
190 | * Prepare a PLAYBACK urb for submission to the bus. | ||
191 | */ | ||
192 | static void prepare_outbound_urb(struct snd_usb_endpoint *ep, | ||
193 | struct snd_urb_ctx *ctx) | ||
194 | { | ||
195 | int i; | ||
196 | struct urb *urb = ctx->urb; | ||
197 | unsigned char *cp = urb->transfer_buffer; | ||
198 | |||
199 | urb->dev = ep->chip->dev; /* we need to set this at each time */ | ||
200 | |||
201 | switch (ep->type) { | ||
202 | case SND_USB_ENDPOINT_TYPE_DATA: | ||
203 | if (ep->prepare_data_urb) { | ||
204 | ep->prepare_data_urb(ep->data_subs, urb); | ||
205 | } else { | ||
206 | /* no data provider, so send silence */ | ||
207 | unsigned int offs = 0; | ||
208 | for (i = 0; i < ctx->packets; ++i) { | ||
209 | int counts = ctx->packet_size[i]; | ||
210 | urb->iso_frame_desc[i].offset = offs * ep->stride; | ||
211 | urb->iso_frame_desc[i].length = counts * ep->stride; | ||
212 | offs += counts; | ||
78 | } | 213 | } |
214 | |||
215 | urb->number_of_packets = ctx->packets; | ||
216 | urb->transfer_buffer_length = offs * ep->stride; | ||
217 | memset(urb->transfer_buffer, ep->silence_value, | ||
218 | offs * ep->stride); | ||
79 | } | 219 | } |
220 | break; | ||
221 | |||
222 | case SND_USB_ENDPOINT_TYPE_SYNC: | ||
223 | if (snd_usb_get_speed(ep->chip->dev) >= USB_SPEED_HIGH) { | ||
224 | /* | ||
225 | * fill the length and offset of each urb descriptor. | ||
226 | * the fixed 12.13 frequency is passed as 16.16 through the pipe. | ||
227 | */ | ||
228 | urb->iso_frame_desc[0].length = 4; | ||
229 | urb->iso_frame_desc[0].offset = 0; | ||
230 | cp[0] = ep->freqn; | ||
231 | cp[1] = ep->freqn >> 8; | ||
232 | cp[2] = ep->freqn >> 16; | ||
233 | cp[3] = ep->freqn >> 24; | ||
234 | } else { | ||
235 | /* | ||
236 | * fill the length and offset of each urb descriptor. | ||
237 | * the fixed 10.14 frequency is passed through the pipe. | ||
238 | */ | ||
239 | urb->iso_frame_desc[0].length = 3; | ||
240 | urb->iso_frame_desc[0].offset = 0; | ||
241 | cp[0] = ep->freqn >> 2; | ||
242 | cp[1] = ep->freqn >> 10; | ||
243 | cp[2] = ep->freqn >> 18; | ||
244 | } | ||
245 | |||
246 | break; | ||
80 | } | 247 | } |
81 | if (subs->syncpipe) { | 248 | } |
82 | for (i = 0; i < SYNC_URBS; i++) { | 249 | |
83 | if (test_bit(i+16, &subs->active_mask)) { | 250 | /* |
84 | if (!test_and_set_bit(i+16, &subs->unlink_mask)) { | 251 | * Prepare a CAPTURE or SYNC urb for submission to the bus. |
85 | struct urb *u = subs->syncurb[i].urb; | 252 | */ |
86 | if (async) | 253 | static inline void prepare_inbound_urb(struct snd_usb_endpoint *ep, |
87 | usb_unlink_urb(u); | 254 | struct snd_urb_ctx *urb_ctx) |
88 | else | 255 | { |
89 | usb_kill_urb(u); | 256 | int i, offs; |
90 | } | 257 | struct urb *urb = urb_ctx->urb; |
91 | } | 258 | |
259 | urb->dev = ep->chip->dev; /* we need to set this at each time */ | ||
260 | |||
261 | switch (ep->type) { | ||
262 | case SND_USB_ENDPOINT_TYPE_DATA: | ||
263 | offs = 0; | ||
264 | for (i = 0; i < urb_ctx->packets; i++) { | ||
265 | urb->iso_frame_desc[i].offset = offs; | ||
266 | urb->iso_frame_desc[i].length = ep->curpacksize; | ||
267 | offs += ep->curpacksize; | ||
92 | } | 268 | } |
269 | |||
270 | urb->transfer_buffer_length = offs; | ||
271 | urb->number_of_packets = urb_ctx->packets; | ||
272 | break; | ||
273 | |||
274 | case SND_USB_ENDPOINT_TYPE_SYNC: | ||
275 | urb->iso_frame_desc[0].length = min(4u, ep->syncmaxsize); | ||
276 | urb->iso_frame_desc[0].offset = 0; | ||
277 | break; | ||
93 | } | 278 | } |
94 | return 0; | ||
95 | } | 279 | } |
96 | 280 | ||
281 | /* | ||
282 | * Send output urbs that have been prepared previously. URBs are dequeued | ||
283 | * from ep->ready_playback_urbs and in case there there aren't any available | ||
284 | * or there are no packets that have been prepared, this function does | ||
285 | * nothing. | ||
286 | * | ||
287 | * The reason why the functionality of sending and preparing URBs is separated | ||
288 | * is that host controllers don't guarantee the order in which they return | ||
289 | * inbound and outbound packets to their submitters. | ||
290 | * | ||
291 | * This function is only used for implicit feedback endpoints. For endpoints | ||
292 | * driven by dedicated sync endpoints, URBs are immediately re-submitted | ||
293 | * from their completion handler. | ||
294 | */ | ||
295 | static void queue_pending_output_urbs(struct snd_usb_endpoint *ep) | ||
296 | { | ||
297 | while (test_bit(EP_FLAG_RUNNING, &ep->flags)) { | ||
298 | |||
299 | unsigned long flags; | ||
300 | struct snd_usb_packet_info *uninitialized_var(packet); | ||
301 | struct snd_urb_ctx *ctx = NULL; | ||
302 | struct urb *urb; | ||
303 | int err, i; | ||
304 | |||
305 | spin_lock_irqsave(&ep->lock, flags); | ||
306 | if (ep->next_packet_read_pos != ep->next_packet_write_pos) { | ||
307 | packet = ep->next_packet + ep->next_packet_read_pos; | ||
308 | ep->next_packet_read_pos++; | ||
309 | ep->next_packet_read_pos %= MAX_URBS; | ||
310 | |||
311 | /* take URB out of FIFO */ | ||
312 | if (!list_empty(&ep->ready_playback_urbs)) | ||
313 | ctx = list_first_entry(&ep->ready_playback_urbs, | ||
314 | struct snd_urb_ctx, ready_list); | ||
315 | } | ||
316 | spin_unlock_irqrestore(&ep->lock, flags); | ||
317 | |||
318 | if (ctx == NULL) | ||
319 | return; | ||
320 | |||
321 | list_del_init(&ctx->ready_list); | ||
322 | urb = ctx->urb; | ||
323 | |||
324 | /* copy over the length information */ | ||
325 | for (i = 0; i < packet->packets; i++) | ||
326 | ctx->packet_size[i] = packet->packet_size[i]; | ||
327 | |||
328 | /* call the data handler to fill in playback data */ | ||
329 | prepare_outbound_urb(ep, ctx); | ||
330 | |||
331 | err = usb_submit_urb(ctx->urb, GFP_ATOMIC); | ||
332 | if (err < 0) | ||
333 | snd_printk(KERN_ERR "Unable to submit urb #%d: %d (urb %p)\n", | ||
334 | ctx->index, err, ctx->urb); | ||
335 | else | ||
336 | set_bit(ctx->index, &ep->active_mask); | ||
337 | } | ||
338 | } | ||
97 | 339 | ||
98 | /* | 340 | /* |
99 | * release a urb data | 341 | * complete callback for urbs |
100 | */ | 342 | */ |
101 | static void release_urb_ctx(struct snd_urb_ctx *u) | 343 | static void snd_complete_urb(struct urb *urb) |
344 | { | ||
345 | struct snd_urb_ctx *ctx = urb->context; | ||
346 | struct snd_usb_endpoint *ep = ctx->ep; | ||
347 | int err; | ||
348 | |||
349 | if (unlikely(urb->status == -ENOENT || /* unlinked */ | ||
350 | urb->status == -ENODEV || /* device removed */ | ||
351 | urb->status == -ECONNRESET || /* unlinked */ | ||
352 | urb->status == -ESHUTDOWN || /* device disabled */ | ||
353 | ep->chip->shutdown)) /* device disconnected */ | ||
354 | goto exit_clear; | ||
355 | |||
356 | if (usb_pipeout(ep->pipe)) { | ||
357 | retire_outbound_urb(ep, ctx); | ||
358 | /* can be stopped during retire callback */ | ||
359 | if (unlikely(!test_bit(EP_FLAG_RUNNING, &ep->flags))) | ||
360 | goto exit_clear; | ||
361 | |||
362 | if (snd_usb_endpoint_implict_feedback_sink(ep)) { | ||
363 | unsigned long flags; | ||
364 | |||
365 | spin_lock_irqsave(&ep->lock, flags); | ||
366 | list_add_tail(&ctx->ready_list, &ep->ready_playback_urbs); | ||
367 | spin_unlock_irqrestore(&ep->lock, flags); | ||
368 | queue_pending_output_urbs(ep); | ||
369 | |||
370 | goto exit_clear; | ||
371 | } | ||
372 | |||
373 | prepare_outbound_urb_sizes(ep, ctx); | ||
374 | prepare_outbound_urb(ep, ctx); | ||
375 | } else { | ||
376 | retire_inbound_urb(ep, ctx); | ||
377 | /* can be stopped during retire callback */ | ||
378 | if (unlikely(!test_bit(EP_FLAG_RUNNING, &ep->flags))) | ||
379 | goto exit_clear; | ||
380 | |||
381 | prepare_inbound_urb(ep, ctx); | ||
382 | } | ||
383 | |||
384 | err = usb_submit_urb(urb, GFP_ATOMIC); | ||
385 | if (err == 0) | ||
386 | return; | ||
387 | |||
388 | snd_printk(KERN_ERR "cannot submit urb (err = %d)\n", err); | ||
389 | //snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN); | ||
390 | |||
391 | exit_clear: | ||
392 | clear_bit(ctx->index, &ep->active_mask); | ||
393 | } | ||
394 | |||
395 | /** | ||
396 | * snd_usb_add_endpoint: Add an endpoint to an USB audio chip | ||
397 | * | ||
398 | * @chip: The chip | ||
399 | * @alts: The USB host interface | ||
400 | * @ep_num: The number of the endpoint to use | ||
401 | * @direction: SNDRV_PCM_STREAM_PLAYBACK or SNDRV_PCM_STREAM_CAPTURE | ||
402 | * @type: SND_USB_ENDPOINT_TYPE_DATA or SND_USB_ENDPOINT_TYPE_SYNC | ||
403 | * | ||
404 | * If the requested endpoint has not been added to the given chip before, | ||
405 | * a new instance is created. Otherwise, a pointer to the previoulsy | ||
406 | * created instance is returned. In case of any error, NULL is returned. | ||
407 | * | ||
408 | * New endpoints will be added to chip->ep_list and must be freed by | ||
409 | * calling snd_usb_endpoint_free(). | ||
410 | */ | ||
411 | struct snd_usb_endpoint *snd_usb_add_endpoint(struct snd_usb_audio *chip, | ||
412 | struct usb_host_interface *alts, | ||
413 | int ep_num, int direction, int type) | ||
102 | { | 414 | { |
103 | if (u->urb) { | 415 | struct list_head *p; |
104 | if (u->buffer_size) | 416 | struct snd_usb_endpoint *ep; |
105 | usb_free_coherent(u->subs->dev, u->buffer_size, | 417 | int ret, is_playback = direction == SNDRV_PCM_STREAM_PLAYBACK; |
106 | u->urb->transfer_buffer, | 418 | |
107 | u->urb->transfer_dma); | 419 | mutex_lock(&chip->mutex); |
108 | usb_free_urb(u->urb); | 420 | |
109 | u->urb = NULL; | 421 | list_for_each(p, &chip->ep_list) { |
422 | ep = list_entry(p, struct snd_usb_endpoint, list); | ||
423 | if (ep->ep_num == ep_num && | ||
424 | ep->iface == alts->desc.bInterfaceNumber && | ||
425 | ep->alt_idx == alts->desc.bAlternateSetting) { | ||
426 | snd_printdd(KERN_DEBUG "Re-using EP %x in iface %d,%d @%p\n", | ||
427 | ep_num, ep->iface, ep->alt_idx, ep); | ||
428 | goto __exit_unlock; | ||
429 | } | ||
430 | } | ||
431 | |||
432 | snd_printdd(KERN_DEBUG "Creating new %s %s endpoint #%x\n", | ||
433 | is_playback ? "playback" : "capture", | ||
434 | type == SND_USB_ENDPOINT_TYPE_DATA ? "data" : "sync", | ||
435 | ep_num); | ||
436 | |||
437 | /* select the alt setting once so the endpoints become valid */ | ||
438 | ret = usb_set_interface(chip->dev, alts->desc.bInterfaceNumber, | ||
439 | alts->desc.bAlternateSetting); | ||
440 | if (ret < 0) { | ||
441 | snd_printk(KERN_ERR "%s(): usb_set_interface() failed, ret = %d\n", | ||
442 | __func__, ret); | ||
443 | ep = NULL; | ||
444 | goto __exit_unlock; | ||
110 | } | 445 | } |
446 | |||
447 | ep = kzalloc(sizeof(*ep), GFP_KERNEL); | ||
448 | if (!ep) | ||
449 | goto __exit_unlock; | ||
450 | |||
451 | ep->chip = chip; | ||
452 | spin_lock_init(&ep->lock); | ||
453 | ep->type = type; | ||
454 | ep->ep_num = ep_num; | ||
455 | ep->iface = alts->desc.bInterfaceNumber; | ||
456 | ep->alt_idx = alts->desc.bAlternateSetting; | ||
457 | INIT_LIST_HEAD(&ep->ready_playback_urbs); | ||
458 | ep_num &= USB_ENDPOINT_NUMBER_MASK; | ||
459 | |||
460 | if (is_playback) | ||
461 | ep->pipe = usb_sndisocpipe(chip->dev, ep_num); | ||
462 | else | ||
463 | ep->pipe = usb_rcvisocpipe(chip->dev, ep_num); | ||
464 | |||
465 | if (type == SND_USB_ENDPOINT_TYPE_SYNC) { | ||
466 | if (get_endpoint(alts, 1)->bLength >= USB_DT_ENDPOINT_AUDIO_SIZE && | ||
467 | get_endpoint(alts, 1)->bRefresh >= 1 && | ||
468 | get_endpoint(alts, 1)->bRefresh <= 9) | ||
469 | ep->syncinterval = get_endpoint(alts, 1)->bRefresh; | ||
470 | else if (snd_usb_get_speed(chip->dev) == USB_SPEED_FULL) | ||
471 | ep->syncinterval = 1; | ||
472 | else if (get_endpoint(alts, 1)->bInterval >= 1 && | ||
473 | get_endpoint(alts, 1)->bInterval <= 16) | ||
474 | ep->syncinterval = get_endpoint(alts, 1)->bInterval - 1; | ||
475 | else | ||
476 | ep->syncinterval = 3; | ||
477 | |||
478 | ep->syncmaxsize = le16_to_cpu(get_endpoint(alts, 1)->wMaxPacketSize); | ||
479 | } | ||
480 | |||
481 | list_add_tail(&ep->list, &chip->ep_list); | ||
482 | |||
483 | __exit_unlock: | ||
484 | mutex_unlock(&chip->mutex); | ||
485 | |||
486 | return ep; | ||
111 | } | 487 | } |
112 | 488 | ||
113 | /* | 489 | /* |
114 | * wait until all urbs are processed. | 490 | * wait until all urbs are processed. |
115 | */ | 491 | */ |
116 | static int wait_clear_urbs(struct snd_usb_substream *subs) | 492 | static int wait_clear_urbs(struct snd_usb_endpoint *ep) |
117 | { | 493 | { |
118 | unsigned long end_time = jiffies + msecs_to_jiffies(1000); | 494 | unsigned long end_time = jiffies + msecs_to_jiffies(1000); |
119 | unsigned int i; | 495 | unsigned int i; |
@@ -121,153 +497,148 @@ static int wait_clear_urbs(struct snd_usb_substream *subs) | |||
121 | 497 | ||
122 | do { | 498 | do { |
123 | alive = 0; | 499 | alive = 0; |
124 | for (i = 0; i < subs->nurbs; i++) { | 500 | for (i = 0; i < ep->nurbs; i++) |
125 | if (test_bit(i, &subs->active_mask)) | 501 | if (test_bit(i, &ep->active_mask)) |
126 | alive++; | 502 | alive++; |
127 | } | 503 | |
128 | if (subs->syncpipe) { | 504 | if (!alive) |
129 | for (i = 0; i < SYNC_URBS; i++) { | ||
130 | if (test_bit(i + 16, &subs->active_mask)) | ||
131 | alive++; | ||
132 | } | ||
133 | } | ||
134 | if (! alive) | ||
135 | break; | 505 | break; |
506 | |||
136 | schedule_timeout_uninterruptible(1); | 507 | schedule_timeout_uninterruptible(1); |
137 | } while (time_before(jiffies, end_time)); | 508 | } while (time_before(jiffies, end_time)); |
509 | |||
138 | if (alive) | 510 | if (alive) |
139 | snd_printk(KERN_ERR "timeout: still %d active urbs..\n", alive); | 511 | snd_printk(KERN_ERR "timeout: still %d active urbs on EP #%x\n", |
512 | alive, ep->ep_num); | ||
513 | |||
140 | return 0; | 514 | return 0; |
141 | } | 515 | } |
142 | 516 | ||
143 | /* | 517 | /* |
144 | * release a substream | 518 | * unlink active urbs. |
145 | */ | 519 | */ |
146 | void snd_usb_release_substream_urbs(struct snd_usb_substream *subs, int force) | 520 | static int deactivate_urbs(struct snd_usb_endpoint *ep, int force, int can_sleep) |
147 | { | 521 | { |
148 | int i; | 522 | unsigned int i; |
523 | int async; | ||
149 | 524 | ||
150 | /* stop urbs (to be sure) */ | 525 | if (!force && ep->chip->shutdown) /* to be sure... */ |
151 | deactivate_urbs(subs, force, 1); | 526 | return -EBADFD; |
152 | wait_clear_urbs(subs); | ||
153 | |||
154 | for (i = 0; i < MAX_URBS; i++) | ||
155 | release_urb_ctx(&subs->dataurb[i]); | ||
156 | for (i = 0; i < SYNC_URBS; i++) | ||
157 | release_urb_ctx(&subs->syncurb[i]); | ||
158 | usb_free_coherent(subs->dev, SYNC_URBS * 4, | ||
159 | subs->syncbuf, subs->sync_dma); | ||
160 | subs->syncbuf = NULL; | ||
161 | subs->nurbs = 0; | ||
162 | } | ||
163 | 527 | ||
164 | /* | 528 | async = !can_sleep && ep->chip->async_unlink; |
165 | * complete callback from data urb | 529 | |
166 | */ | 530 | clear_bit(EP_FLAG_RUNNING, &ep->flags); |
167 | static void snd_complete_urb(struct urb *urb) | 531 | |
168 | { | 532 | INIT_LIST_HEAD(&ep->ready_playback_urbs); |
169 | struct snd_urb_ctx *ctx = urb->context; | 533 | ep->next_packet_read_pos = 0; |
170 | struct snd_usb_substream *subs = ctx->subs; | 534 | ep->next_packet_write_pos = 0; |
171 | struct snd_pcm_substream *substream = ctx->subs->pcm_substream; | 535 | |
172 | int err = 0; | 536 | if (!async && in_interrupt()) |
173 | 537 | return 0; | |
174 | if ((subs->running && subs->ops.retire(subs, substream->runtime, urb)) || | 538 | |
175 | !subs->running || /* can be stopped during retire callback */ | 539 | for (i = 0; i < ep->nurbs; i++) { |
176 | (err = subs->ops.prepare(subs, substream->runtime, urb)) < 0 || | 540 | if (test_bit(i, &ep->active_mask)) { |
177 | (err = usb_submit_urb(urb, GFP_ATOMIC)) < 0) { | 541 | if (!test_and_set_bit(i, &ep->unlink_mask)) { |
178 | clear_bit(ctx->index, &subs->active_mask); | 542 | struct urb *u = ep->urb[i].urb; |
179 | if (err < 0) { | 543 | if (async) |
180 | snd_printd(KERN_ERR "cannot submit urb (err = %d)\n", err); | 544 | usb_unlink_urb(u); |
181 | snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN); | 545 | else |
546 | usb_kill_urb(u); | ||
547 | } | ||
182 | } | 548 | } |
183 | } | 549 | } |
184 | } | ||
185 | 550 | ||
551 | return 0; | ||
552 | } | ||
186 | 553 | ||
187 | /* | 554 | /* |
188 | * complete callback from sync urb | 555 | * release an endpoint's urbs |
189 | */ | 556 | */ |
190 | static void snd_complete_sync_urb(struct urb *urb) | 557 | static void release_urbs(struct snd_usb_endpoint *ep, int force) |
191 | { | 558 | { |
192 | struct snd_urb_ctx *ctx = urb->context; | 559 | int i; |
193 | struct snd_usb_substream *subs = ctx->subs; | ||
194 | struct snd_pcm_substream *substream = ctx->subs->pcm_substream; | ||
195 | int err = 0; | ||
196 | |||
197 | if ((subs->running && subs->ops.retire_sync(subs, substream->runtime, urb)) || | ||
198 | !subs->running || /* can be stopped during retire callback */ | ||
199 | (err = subs->ops.prepare_sync(subs, substream->runtime, urb)) < 0 || | ||
200 | (err = usb_submit_urb(urb, GFP_ATOMIC)) < 0) { | ||
201 | clear_bit(ctx->index + 16, &subs->active_mask); | ||
202 | if (err < 0) { | ||
203 | snd_printd(KERN_ERR "cannot submit sync urb (err = %d)\n", err); | ||
204 | snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN); | ||
205 | } | ||
206 | } | ||
207 | } | ||
208 | 560 | ||
561 | /* route incoming urbs to nirvana */ | ||
562 | ep->retire_data_urb = NULL; | ||
563 | ep->prepare_data_urb = NULL; | ||
564 | |||
565 | /* stop urbs */ | ||
566 | deactivate_urbs(ep, force, 1); | ||
567 | wait_clear_urbs(ep); | ||
568 | |||
569 | for (i = 0; i < ep->nurbs; i++) | ||
570 | release_urb_ctx(&ep->urb[i]); | ||
571 | |||
572 | if (ep->syncbuf) | ||
573 | usb_free_coherent(ep->chip->dev, SYNC_URBS * 4, | ||
574 | ep->syncbuf, ep->sync_dma); | ||
575 | |||
576 | ep->syncbuf = NULL; | ||
577 | ep->nurbs = 0; | ||
578 | } | ||
209 | 579 | ||
210 | /* | 580 | /* |
211 | * initialize a substream for plaback/capture | 581 | * configure a data endpoint |
212 | */ | 582 | */ |
213 | int snd_usb_init_substream_urbs(struct snd_usb_substream *subs, | 583 | static int data_ep_set_params(struct snd_usb_endpoint *ep, |
214 | unsigned int period_bytes, | 584 | struct snd_pcm_hw_params *hw_params, |
215 | unsigned int rate, | 585 | struct audioformat *fmt, |
216 | unsigned int frame_bits) | 586 | struct snd_usb_endpoint *sync_ep) |
217 | { | 587 | { |
218 | unsigned int maxsize, i; | 588 | unsigned int maxsize, i, urb_packs, total_packs, packs_per_ms; |
219 | int is_playback = subs->direction == SNDRV_PCM_STREAM_PLAYBACK; | 589 | int period_bytes = params_period_bytes(hw_params); |
220 | unsigned int urb_packs, total_packs, packs_per_ms; | 590 | int format = params_format(hw_params); |
221 | struct snd_usb_audio *chip = subs->stream->chip; | 591 | int is_playback = usb_pipeout(ep->pipe); |
592 | int frame_bits = snd_pcm_format_physical_width(params_format(hw_params)) * | ||
593 | params_channels(hw_params); | ||
594 | |||
595 | ep->datainterval = fmt->datainterval; | ||
596 | ep->stride = frame_bits >> 3; | ||
597 | ep->silence_value = format == SNDRV_PCM_FORMAT_U8 ? 0x80 : 0; | ||
222 | 598 | ||
223 | /* calculate the frequency in 16.16 format */ | ||
224 | if (snd_usb_get_speed(subs->dev) == USB_SPEED_FULL) | ||
225 | subs->freqn = get_usb_full_speed_rate(rate); | ||
226 | else | ||
227 | subs->freqn = get_usb_high_speed_rate(rate); | ||
228 | subs->freqm = subs->freqn; | ||
229 | subs->freqshift = INT_MIN; | ||
230 | /* calculate max. frequency */ | 599 | /* calculate max. frequency */ |
231 | if (subs->maxpacksize) { | 600 | if (ep->maxpacksize) { |
232 | /* whatever fits into a max. size packet */ | 601 | /* whatever fits into a max. size packet */ |
233 | maxsize = subs->maxpacksize; | 602 | maxsize = ep->maxpacksize; |
234 | subs->freqmax = (maxsize / (frame_bits >> 3)) | 603 | ep->freqmax = (maxsize / (frame_bits >> 3)) |
235 | << (16 - subs->datainterval); | 604 | << (16 - ep->datainterval); |
236 | } else { | 605 | } else { |
237 | /* no max. packet size: just take 25% higher than nominal */ | 606 | /* no max. packet size: just take 25% higher than nominal */ |
238 | subs->freqmax = subs->freqn + (subs->freqn >> 2); | 607 | ep->freqmax = ep->freqn + (ep->freqn >> 2); |
239 | maxsize = ((subs->freqmax + 0xffff) * (frame_bits >> 3)) | 608 | maxsize = ((ep->freqmax + 0xffff) * (frame_bits >> 3)) |
240 | >> (16 - subs->datainterval); | 609 | >> (16 - ep->datainterval); |
241 | } | 610 | } |
242 | subs->phase = 0; | ||
243 | 611 | ||
244 | if (subs->fill_max) | 612 | if (ep->fill_max) |
245 | subs->curpacksize = subs->maxpacksize; | 613 | ep->curpacksize = ep->maxpacksize; |
246 | else | 614 | else |
247 | subs->curpacksize = maxsize; | 615 | ep->curpacksize = maxsize; |
248 | 616 | ||
249 | if (snd_usb_get_speed(subs->dev) != USB_SPEED_FULL) | 617 | if (snd_usb_get_speed(ep->chip->dev) != USB_SPEED_FULL) |
250 | packs_per_ms = 8 >> subs->datainterval; | 618 | packs_per_ms = 8 >> ep->datainterval; |
251 | else | 619 | else |
252 | packs_per_ms = 1; | 620 | packs_per_ms = 1; |
253 | 621 | ||
254 | if (is_playback) { | 622 | if (is_playback && !snd_usb_endpoint_implict_feedback_sink(ep)) { |
255 | urb_packs = max(chip->nrpacks, 1); | 623 | urb_packs = max(ep->chip->nrpacks, 1); |
256 | urb_packs = min(urb_packs, (unsigned int)MAX_PACKS); | 624 | urb_packs = min(urb_packs, (unsigned int) MAX_PACKS); |
257 | } else | 625 | } else { |
258 | urb_packs = 1; | 626 | urb_packs = 1; |
627 | } | ||
628 | |||
259 | urb_packs *= packs_per_ms; | 629 | urb_packs *= packs_per_ms; |
260 | if (subs->syncpipe) | 630 | |
261 | urb_packs = min(urb_packs, 1U << subs->syncinterval); | 631 | if (sync_ep && !snd_usb_endpoint_implict_feedback_sink(ep)) |
632 | urb_packs = min(urb_packs, 1U << sync_ep->syncinterval); | ||
262 | 633 | ||
263 | /* decide how many packets to be used */ | 634 | /* decide how many packets to be used */ |
264 | if (is_playback) { | 635 | if (is_playback && !snd_usb_endpoint_implict_feedback_sink(ep)) { |
265 | unsigned int minsize, maxpacks; | 636 | unsigned int minsize, maxpacks; |
266 | /* determine how small a packet can be */ | 637 | /* determine how small a packet can be */ |
267 | minsize = (subs->freqn >> (16 - subs->datainterval)) | 638 | minsize = (ep->freqn >> (16 - ep->datainterval)) |
268 | * (frame_bits >> 3); | 639 | * (frame_bits >> 3); |
269 | /* with sync from device, assume it can be 12% lower */ | 640 | /* with sync from device, assume it can be 12% lower */ |
270 | if (subs->syncpipe) | 641 | if (sync_ep) |
271 | minsize -= minsize >> 3; | 642 | minsize -= minsize >> 3; |
272 | minsize = max(minsize, 1u); | 643 | minsize = max(minsize, 1u); |
273 | total_packs = (period_bytes + minsize - 1) / minsize; | 644 | total_packs = (period_bytes + minsize - 1) / minsize; |
@@ -284,284 +655,472 @@ int snd_usb_init_substream_urbs(struct snd_usb_substream *subs, | |||
284 | urb_packs >>= 1; | 655 | urb_packs >>= 1; |
285 | total_packs = MAX_URBS * urb_packs; | 656 | total_packs = MAX_URBS * urb_packs; |
286 | } | 657 | } |
287 | subs->nurbs = (total_packs + urb_packs - 1) / urb_packs; | 658 | |
288 | if (subs->nurbs > MAX_URBS) { | 659 | ep->nurbs = (total_packs + urb_packs - 1) / urb_packs; |
660 | if (ep->nurbs > MAX_URBS) { | ||
289 | /* too much... */ | 661 | /* too much... */ |
290 | subs->nurbs = MAX_URBS; | 662 | ep->nurbs = MAX_URBS; |
291 | total_packs = MAX_URBS * urb_packs; | 663 | total_packs = MAX_URBS * urb_packs; |
292 | } else if (subs->nurbs < 2) { | 664 | } else if (ep->nurbs < 2) { |
293 | /* too little - we need at least two packets | 665 | /* too little - we need at least two packets |
294 | * to ensure contiguous playback/capture | 666 | * to ensure contiguous playback/capture |
295 | */ | 667 | */ |
296 | subs->nurbs = 2; | 668 | ep->nurbs = 2; |
297 | } | 669 | } |
298 | 670 | ||
299 | /* allocate and initialize data urbs */ | 671 | /* allocate and initialize data urbs */ |
300 | for (i = 0; i < subs->nurbs; i++) { | 672 | for (i = 0; i < ep->nurbs; i++) { |
301 | struct snd_urb_ctx *u = &subs->dataurb[i]; | 673 | struct snd_urb_ctx *u = &ep->urb[i]; |
302 | u->index = i; | 674 | u->index = i; |
303 | u->subs = subs; | 675 | u->ep = ep; |
304 | u->packets = (i + 1) * total_packs / subs->nurbs | 676 | u->packets = (i + 1) * total_packs / ep->nurbs |
305 | - i * total_packs / subs->nurbs; | 677 | - i * total_packs / ep->nurbs; |
306 | u->buffer_size = maxsize * u->packets; | 678 | u->buffer_size = maxsize * u->packets; |
307 | if (subs->fmt_type == UAC_FORMAT_TYPE_II) | 679 | |
680 | if (fmt->fmt_type == UAC_FORMAT_TYPE_II) | ||
308 | u->packets++; /* for transfer delimiter */ | 681 | u->packets++; /* for transfer delimiter */ |
309 | u->urb = usb_alloc_urb(u->packets, GFP_KERNEL); | 682 | u->urb = usb_alloc_urb(u->packets, GFP_KERNEL); |
310 | if (!u->urb) | 683 | if (!u->urb) |
311 | goto out_of_memory; | 684 | goto out_of_memory; |
685 | |||
312 | u->urb->transfer_buffer = | 686 | u->urb->transfer_buffer = |
313 | usb_alloc_coherent(subs->dev, u->buffer_size, | 687 | usb_alloc_coherent(ep->chip->dev, u->buffer_size, |
314 | GFP_KERNEL, &u->urb->transfer_dma); | 688 | GFP_KERNEL, &u->urb->transfer_dma); |
315 | if (!u->urb->transfer_buffer) | 689 | if (!u->urb->transfer_buffer) |
316 | goto out_of_memory; | 690 | goto out_of_memory; |
317 | u->urb->pipe = subs->datapipe; | 691 | u->urb->pipe = ep->pipe; |
318 | u->urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP; | 692 | u->urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP; |
319 | u->urb->interval = 1 << subs->datainterval; | 693 | u->urb->interval = 1 << ep->datainterval; |
320 | u->urb->context = u; | 694 | u->urb->context = u; |
321 | u->urb->complete = snd_complete_urb; | 695 | u->urb->complete = snd_complete_urb; |
696 | INIT_LIST_HEAD(&u->ready_list); | ||
322 | } | 697 | } |
323 | 698 | ||
324 | if (subs->syncpipe) { | ||
325 | /* allocate and initialize sync urbs */ | ||
326 | subs->syncbuf = usb_alloc_coherent(subs->dev, SYNC_URBS * 4, | ||
327 | GFP_KERNEL, &subs->sync_dma); | ||
328 | if (!subs->syncbuf) | ||
329 | goto out_of_memory; | ||
330 | for (i = 0; i < SYNC_URBS; i++) { | ||
331 | struct snd_urb_ctx *u = &subs->syncurb[i]; | ||
332 | u->index = i; | ||
333 | u->subs = subs; | ||
334 | u->packets = 1; | ||
335 | u->urb = usb_alloc_urb(1, GFP_KERNEL); | ||
336 | if (!u->urb) | ||
337 | goto out_of_memory; | ||
338 | u->urb->transfer_buffer = subs->syncbuf + i * 4; | ||
339 | u->urb->transfer_dma = subs->sync_dma + i * 4; | ||
340 | u->urb->transfer_buffer_length = 4; | ||
341 | u->urb->pipe = subs->syncpipe; | ||
342 | u->urb->transfer_flags = URB_ISO_ASAP | | ||
343 | URB_NO_TRANSFER_DMA_MAP; | ||
344 | u->urb->number_of_packets = 1; | ||
345 | u->urb->interval = 1 << subs->syncinterval; | ||
346 | u->urb->context = u; | ||
347 | u->urb->complete = snd_complete_sync_urb; | ||
348 | } | ||
349 | } | ||
350 | return 0; | 699 | return 0; |
351 | 700 | ||
352 | out_of_memory: | 701 | out_of_memory: |
353 | snd_usb_release_substream_urbs(subs, 0); | 702 | release_urbs(ep, 0); |
354 | return -ENOMEM; | 703 | return -ENOMEM; |
355 | } | 704 | } |
356 | 705 | ||
357 | /* | 706 | /* |
358 | * prepare urb for full speed capture sync pipe | 707 | * configure a sync endpoint |
359 | * | ||
360 | * fill the length and offset of each urb descriptor. | ||
361 | * the fixed 10.14 frequency is passed through the pipe. | ||
362 | */ | 708 | */ |
363 | static int prepare_capture_sync_urb(struct snd_usb_substream *subs, | 709 | static int sync_ep_set_params(struct snd_usb_endpoint *ep, |
364 | struct snd_pcm_runtime *runtime, | 710 | struct snd_pcm_hw_params *hw_params, |
365 | struct urb *urb) | 711 | struct audioformat *fmt) |
366 | { | 712 | { |
367 | unsigned char *cp = urb->transfer_buffer; | 713 | int i; |
368 | struct snd_urb_ctx *ctx = urb->context; | 714 | |
715 | ep->syncbuf = usb_alloc_coherent(ep->chip->dev, SYNC_URBS * 4, | ||
716 | GFP_KERNEL, &ep->sync_dma); | ||
717 | if (!ep->syncbuf) | ||
718 | return -ENOMEM; | ||
719 | |||
720 | for (i = 0; i < SYNC_URBS; i++) { | ||
721 | struct snd_urb_ctx *u = &ep->urb[i]; | ||
722 | u->index = i; | ||
723 | u->ep = ep; | ||
724 | u->packets = 1; | ||
725 | u->urb = usb_alloc_urb(1, GFP_KERNEL); | ||
726 | if (!u->urb) | ||
727 | goto out_of_memory; | ||
728 | u->urb->transfer_buffer = ep->syncbuf + i * 4; | ||
729 | u->urb->transfer_dma = ep->sync_dma + i * 4; | ||
730 | u->urb->transfer_buffer_length = 4; | ||
731 | u->urb->pipe = ep->pipe; | ||
732 | u->urb->transfer_flags = URB_ISO_ASAP | | ||
733 | URB_NO_TRANSFER_DMA_MAP; | ||
734 | u->urb->number_of_packets = 1; | ||
735 | u->urb->interval = 1 << ep->syncinterval; | ||
736 | u->urb->context = u; | ||
737 | u->urb->complete = snd_complete_urb; | ||
738 | } | ||
739 | |||
740 | ep->nurbs = SYNC_URBS; | ||
369 | 741 | ||
370 | urb->dev = ctx->subs->dev; /* we need to set this at each time */ | ||
371 | urb->iso_frame_desc[0].length = 3; | ||
372 | urb->iso_frame_desc[0].offset = 0; | ||
373 | cp[0] = subs->freqn >> 2; | ||
374 | cp[1] = subs->freqn >> 10; | ||
375 | cp[2] = subs->freqn >> 18; | ||
376 | return 0; | 742 | return 0; |
743 | |||
744 | out_of_memory: | ||
745 | release_urbs(ep, 0); | ||
746 | return -ENOMEM; | ||
377 | } | 747 | } |
378 | 748 | ||
379 | /* | 749 | /** |
380 | * prepare urb for high speed capture sync pipe | 750 | * snd_usb_endpoint_set_params: configure an snd_usb_endpoint |
751 | * | ||
752 | * @ep: the snd_usb_endpoint to configure | ||
753 | * @hw_params: the hardware parameters | ||
754 | * @fmt: the USB audio format information | ||
755 | * @sync_ep: the sync endpoint to use, if any | ||
381 | * | 756 | * |
382 | * fill the length and offset of each urb descriptor. | 757 | * Determine the number of URBs to be used on this endpoint. |
383 | * the fixed 12.13 frequency is passed as 16.16 through the pipe. | 758 | * An endpoint must be configured before it can be started. |
759 | * An endpoint that is already running can not be reconfigured. | ||
384 | */ | 760 | */ |
385 | static int prepare_capture_sync_urb_hs(struct snd_usb_substream *subs, | 761 | int snd_usb_endpoint_set_params(struct snd_usb_endpoint *ep, |
386 | struct snd_pcm_runtime *runtime, | 762 | struct snd_pcm_hw_params *hw_params, |
387 | struct urb *urb) | 763 | struct audioformat *fmt, |
764 | struct snd_usb_endpoint *sync_ep) | ||
388 | { | 765 | { |
389 | unsigned char *cp = urb->transfer_buffer; | 766 | int err; |
390 | struct snd_urb_ctx *ctx = urb->context; | ||
391 | 767 | ||
392 | urb->dev = ctx->subs->dev; /* we need to set this at each time */ | 768 | if (ep->use_count != 0) { |
393 | urb->iso_frame_desc[0].length = 4; | 769 | snd_printk(KERN_WARNING "Unable to change format on ep #%x: already in use\n", |
394 | urb->iso_frame_desc[0].offset = 0; | 770 | ep->ep_num); |
395 | cp[0] = subs->freqn; | 771 | return -EBUSY; |
396 | cp[1] = subs->freqn >> 8; | 772 | } |
397 | cp[2] = subs->freqn >> 16; | 773 | |
398 | cp[3] = subs->freqn >> 24; | 774 | /* release old buffers, if any */ |
399 | return 0; | 775 | release_urbs(ep, 0); |
776 | |||
777 | ep->datainterval = fmt->datainterval; | ||
778 | ep->maxpacksize = fmt->maxpacksize; | ||
779 | ep->fill_max = !!(fmt->attributes & UAC_EP_CS_ATTR_FILL_MAX); | ||
780 | |||
781 | if (snd_usb_get_speed(ep->chip->dev) == USB_SPEED_FULL) | ||
782 | ep->freqn = get_usb_full_speed_rate(params_rate(hw_params)); | ||
783 | else | ||
784 | ep->freqn = get_usb_high_speed_rate(params_rate(hw_params)); | ||
785 | |||
786 | /* calculate the frequency in 16.16 format */ | ||
787 | ep->freqm = ep->freqn; | ||
788 | ep->freqshift = INT_MIN; | ||
789 | |||
790 | ep->phase = 0; | ||
791 | |||
792 | switch (ep->type) { | ||
793 | case SND_USB_ENDPOINT_TYPE_DATA: | ||
794 | err = data_ep_set_params(ep, hw_params, fmt, sync_ep); | ||
795 | break; | ||
796 | case SND_USB_ENDPOINT_TYPE_SYNC: | ||
797 | err = sync_ep_set_params(ep, hw_params, fmt); | ||
798 | break; | ||
799 | default: | ||
800 | err = -EINVAL; | ||
801 | } | ||
802 | |||
803 | snd_printdd(KERN_DEBUG "Setting params for ep #%x (type %d, %d urbs), ret=%d\n", | ||
804 | ep->ep_num, ep->type, ep->nurbs, err); | ||
805 | |||
806 | return err; | ||
400 | } | 807 | } |
401 | 808 | ||
402 | /* | 809 | /** |
403 | * process after capture sync complete | 810 | * snd_usb_endpoint_start: start an snd_usb_endpoint |
404 | * - nothing to do | 811 | * |
812 | * @ep: the endpoint to start | ||
813 | * | ||
814 | * A call to this function will increment the use count of the endpoint. | ||
815 | * In case it is not already running, the URBs for this endpoint will be | ||
816 | * submitted. Otherwise, this function does nothing. | ||
817 | * | ||
818 | * Must be balanced to calls of snd_usb_endpoint_stop(). | ||
819 | * | ||
820 | * Returns an error if the URB submission failed, 0 in all other cases. | ||
405 | */ | 821 | */ |
406 | static int retire_capture_sync_urb(struct snd_usb_substream *subs, | 822 | int snd_usb_endpoint_start(struct snd_usb_endpoint *ep) |
407 | struct snd_pcm_runtime *runtime, | ||
408 | struct urb *urb) | ||
409 | { | 823 | { |
824 | int err; | ||
825 | unsigned int i; | ||
826 | |||
827 | if (ep->chip->shutdown) | ||
828 | return -EBADFD; | ||
829 | |||
830 | /* already running? */ | ||
831 | if (++ep->use_count != 1) | ||
832 | return 0; | ||
833 | |||
834 | if (snd_BUG_ON(!test_bit(EP_FLAG_ACTIVATED, &ep->flags))) | ||
835 | return -EINVAL; | ||
836 | |||
837 | /* just to be sure */ | ||
838 | deactivate_urbs(ep, 0, 1); | ||
839 | wait_clear_urbs(ep); | ||
840 | |||
841 | ep->active_mask = 0; | ||
842 | ep->unlink_mask = 0; | ||
843 | ep->phase = 0; | ||
844 | |||
845 | /* | ||
846 | * If this endpoint has a data endpoint as implicit feedback source, | ||
847 | * don't start the urbs here. Instead, mark them all as available, | ||
848 | * wait for the record urbs to return and queue the playback urbs | ||
849 | * from that context. | ||
850 | */ | ||
851 | |||
852 | set_bit(EP_FLAG_RUNNING, &ep->flags); | ||
853 | |||
854 | if (snd_usb_endpoint_implict_feedback_sink(ep)) { | ||
855 | for (i = 0; i < ep->nurbs; i++) { | ||
856 | struct snd_urb_ctx *ctx = ep->urb + i; | ||
857 | list_add_tail(&ctx->ready_list, &ep->ready_playback_urbs); | ||
858 | } | ||
859 | |||
860 | return 0; | ||
861 | } | ||
862 | |||
863 | for (i = 0; i < ep->nurbs; i++) { | ||
864 | struct urb *urb = ep->urb[i].urb; | ||
865 | |||
866 | if (snd_BUG_ON(!urb)) | ||
867 | goto __error; | ||
868 | |||
869 | if (usb_pipeout(ep->pipe)) { | ||
870 | prepare_outbound_urb_sizes(ep, urb->context); | ||
871 | prepare_outbound_urb(ep, urb->context); | ||
872 | } else { | ||
873 | prepare_inbound_urb(ep, urb->context); | ||
874 | } | ||
875 | |||
876 | err = usb_submit_urb(urb, GFP_ATOMIC); | ||
877 | if (err < 0) { | ||
878 | snd_printk(KERN_ERR "cannot submit urb %d, error %d: %s\n", | ||
879 | i, err, usb_error_string(err)); | ||
880 | goto __error; | ||
881 | } | ||
882 | set_bit(i, &ep->active_mask); | ||
883 | } | ||
884 | |||
410 | return 0; | 885 | return 0; |
886 | |||
887 | __error: | ||
888 | clear_bit(EP_FLAG_RUNNING, &ep->flags); | ||
889 | ep->use_count--; | ||
890 | deactivate_urbs(ep, 0, 0); | ||
891 | return -EPIPE; | ||
411 | } | 892 | } |
412 | 893 | ||
413 | /* | 894 | /** |
414 | * prepare urb for capture data pipe | 895 | * snd_usb_endpoint_stop: stop an snd_usb_endpoint |
896 | * | ||
897 | * @ep: the endpoint to stop (may be NULL) | ||
415 | * | 898 | * |
416 | * fill the offset and length of each descriptor. | 899 | * A call to this function will decrement the use count of the endpoint. |
900 | * In case the last user has requested the endpoint stop, the URBs will | ||
901 | * actually be deactivated. | ||
417 | * | 902 | * |
418 | * we use a temporary buffer to write the captured data. | 903 | * Must be balanced to calls of snd_usb_endpoint_start(). |
419 | * since the length of written data is determined by host, we cannot | ||
420 | * write onto the pcm buffer directly... the data is thus copied | ||
421 | * later at complete callback to the global buffer. | ||
422 | */ | 904 | */ |
423 | static int prepare_capture_urb(struct snd_usb_substream *subs, | 905 | void snd_usb_endpoint_stop(struct snd_usb_endpoint *ep, |
424 | struct snd_pcm_runtime *runtime, | 906 | int force, int can_sleep, int wait) |
425 | struct urb *urb) | ||
426 | { | 907 | { |
427 | int i, offs; | 908 | if (!ep) |
428 | struct snd_urb_ctx *ctx = urb->context; | 909 | return; |
429 | 910 | ||
430 | offs = 0; | 911 | if (snd_BUG_ON(ep->use_count == 0)) |
431 | urb->dev = ctx->subs->dev; /* we need to set this at each time */ | 912 | return; |
432 | for (i = 0; i < ctx->packets; i++) { | 913 | |
433 | urb->iso_frame_desc[i].offset = offs; | 914 | if (snd_BUG_ON(!test_bit(EP_FLAG_ACTIVATED, &ep->flags))) |
434 | urb->iso_frame_desc[i].length = subs->curpacksize; | 915 | return; |
435 | offs += subs->curpacksize; | 916 | |
917 | if (--ep->use_count == 0) { | ||
918 | deactivate_urbs(ep, force, can_sleep); | ||
919 | ep->data_subs = NULL; | ||
920 | ep->sync_slave = NULL; | ||
921 | ep->retire_data_urb = NULL; | ||
922 | ep->prepare_data_urb = NULL; | ||
923 | |||
924 | if (wait) | ||
925 | wait_clear_urbs(ep); | ||
436 | } | 926 | } |
437 | urb->transfer_buffer_length = offs; | ||
438 | urb->number_of_packets = ctx->packets; | ||
439 | return 0; | ||
440 | } | 927 | } |
441 | 928 | ||
442 | /* | 929 | /** |
443 | * process after capture complete | 930 | * snd_usb_endpoint_activate: activate an snd_usb_endpoint |
931 | * | ||
932 | * @ep: the endpoint to activate | ||
933 | * | ||
934 | * If the endpoint is not currently in use, this functions will select the | ||
935 | * correct alternate interface setting for the interface of this endpoint. | ||
444 | * | 936 | * |
445 | * copy the data from each desctiptor to the pcm buffer, and | 937 | * In case of any active users, this functions does nothing. |
446 | * update the current position. | 938 | * |
939 | * Returns an error if usb_set_interface() failed, 0 in all other | ||
940 | * cases. | ||
447 | */ | 941 | */ |
448 | static int retire_capture_urb(struct snd_usb_substream *subs, | 942 | int snd_usb_endpoint_activate(struct snd_usb_endpoint *ep) |
449 | struct snd_pcm_runtime *runtime, | ||
450 | struct urb *urb) | ||
451 | { | 943 | { |
452 | unsigned long flags; | 944 | if (ep->use_count != 0) |
453 | unsigned char *cp; | 945 | return 0; |
454 | int i; | ||
455 | unsigned int stride, frames, bytes, oldptr; | ||
456 | int period_elapsed = 0; | ||
457 | 946 | ||
458 | stride = runtime->frame_bits >> 3; | 947 | if (!ep->chip->shutdown && |
948 | !test_and_set_bit(EP_FLAG_ACTIVATED, &ep->flags)) { | ||
949 | int ret; | ||
459 | 950 | ||
460 | for (i = 0; i < urb->number_of_packets; i++) { | 951 | ret = usb_set_interface(ep->chip->dev, ep->iface, ep->alt_idx); |
461 | cp = (unsigned char *)urb->transfer_buffer + urb->iso_frame_desc[i].offset; | 952 | if (ret < 0) { |
462 | if (urb->iso_frame_desc[i].status && printk_ratelimit()) { | 953 | snd_printk(KERN_ERR "%s() usb_set_interface() failed, ret = %d\n", |
463 | snd_printdd("frame %d active: %d\n", i, urb->iso_frame_desc[i].status); | 954 | __func__, ret); |
464 | // continue; | 955 | clear_bit(EP_FLAG_ACTIVATED, &ep->flags); |
465 | } | 956 | return ret; |
466 | bytes = urb->iso_frame_desc[i].actual_length; | ||
467 | frames = bytes / stride; | ||
468 | if (!subs->txfr_quirk) | ||
469 | bytes = frames * stride; | ||
470 | if (bytes % (runtime->sample_bits >> 3) != 0) { | ||
471 | #ifdef CONFIG_SND_DEBUG_VERBOSE | ||
472 | int oldbytes = bytes; | ||
473 | #endif | ||
474 | bytes = frames * stride; | ||
475 | snd_printdd(KERN_ERR "Corrected urb data len. %d->%d\n", | ||
476 | oldbytes, bytes); | ||
477 | } | ||
478 | /* update the current pointer */ | ||
479 | spin_lock_irqsave(&subs->lock, flags); | ||
480 | oldptr = subs->hwptr_done; | ||
481 | subs->hwptr_done += bytes; | ||
482 | if (subs->hwptr_done >= runtime->buffer_size * stride) | ||
483 | subs->hwptr_done -= runtime->buffer_size * stride; | ||
484 | frames = (bytes + (oldptr % stride)) / stride; | ||
485 | subs->transfer_done += frames; | ||
486 | if (subs->transfer_done >= runtime->period_size) { | ||
487 | subs->transfer_done -= runtime->period_size; | ||
488 | period_elapsed = 1; | ||
489 | } | ||
490 | spin_unlock_irqrestore(&subs->lock, flags); | ||
491 | /* copy a data chunk */ | ||
492 | if (oldptr + bytes > runtime->buffer_size * stride) { | ||
493 | unsigned int bytes1 = | ||
494 | runtime->buffer_size * stride - oldptr; | ||
495 | memcpy(runtime->dma_area + oldptr, cp, bytes1); | ||
496 | memcpy(runtime->dma_area, cp + bytes1, bytes - bytes1); | ||
497 | } else { | ||
498 | memcpy(runtime->dma_area + oldptr, cp, bytes); | ||
499 | } | 957 | } |
958 | |||
959 | return 0; | ||
500 | } | 960 | } |
501 | if (period_elapsed) | 961 | |
502 | snd_pcm_period_elapsed(subs->pcm_substream); | 962 | return -EBUSY; |
503 | return 0; | ||
504 | } | 963 | } |
505 | 964 | ||
506 | /* | 965 | /** |
507 | * Process after capture complete when paused. Nothing to do. | 966 | * snd_usb_endpoint_deactivate: deactivate an snd_usb_endpoint |
967 | * | ||
968 | * @ep: the endpoint to deactivate | ||
969 | * | ||
970 | * If the endpoint is not currently in use, this functions will select the | ||
971 | * alternate interface setting 0 for the interface of this endpoint. | ||
972 | * | ||
973 | * In case of any active users, this functions does nothing. | ||
974 | * | ||
975 | * Returns an error if usb_set_interface() failed, 0 in all other | ||
976 | * cases. | ||
508 | */ | 977 | */ |
509 | static int retire_paused_capture_urb(struct snd_usb_substream *subs, | 978 | int snd_usb_endpoint_deactivate(struct snd_usb_endpoint *ep) |
510 | struct snd_pcm_runtime *runtime, | ||
511 | struct urb *urb) | ||
512 | { | 979 | { |
513 | return 0; | 980 | if (!ep) |
514 | } | 981 | return -EINVAL; |
515 | 982 | ||
983 | if (ep->use_count != 0) | ||
984 | return 0; | ||
516 | 985 | ||
517 | /* | 986 | if (!ep->chip->shutdown && |
518 | * prepare urb for playback sync pipe | 987 | test_and_clear_bit(EP_FLAG_ACTIVATED, &ep->flags)) { |
988 | int ret; | ||
989 | |||
990 | ret = usb_set_interface(ep->chip->dev, ep->iface, 0); | ||
991 | if (ret < 0) { | ||
992 | snd_printk(KERN_ERR "%s(): usb_set_interface() failed, ret = %d\n", | ||
993 | __func__, ret); | ||
994 | return ret; | ||
995 | } | ||
996 | |||
997 | return 0; | ||
998 | } | ||
999 | |||
1000 | return -EBUSY; | ||
1001 | } | ||
1002 | |||
1003 | /** | ||
1004 | * snd_usb_endpoint_free: Free the resources of an snd_usb_endpoint | ||
1005 | * | ||
1006 | * @ep: the list header of the endpoint to free | ||
519 | * | 1007 | * |
520 | * set up the offset and length to receive the current frequency. | 1008 | * This function does not care for the endpoint's use count but will tear |
1009 | * down all the streaming URBs immediately and free all resources. | ||
521 | */ | 1010 | */ |
522 | static int prepare_playback_sync_urb(struct snd_usb_substream *subs, | 1011 | void snd_usb_endpoint_free(struct list_head *head) |
523 | struct snd_pcm_runtime *runtime, | ||
524 | struct urb *urb) | ||
525 | { | 1012 | { |
526 | struct snd_urb_ctx *ctx = urb->context; | 1013 | struct snd_usb_endpoint *ep; |
527 | 1014 | ||
528 | urb->dev = ctx->subs->dev; /* we need to set this at each time */ | 1015 | ep = list_entry(head, struct snd_usb_endpoint, list); |
529 | urb->iso_frame_desc[0].length = min(4u, ctx->subs->syncmaxsize); | 1016 | release_urbs(ep, 1); |
530 | urb->iso_frame_desc[0].offset = 0; | 1017 | kfree(ep); |
531 | return 0; | ||
532 | } | 1018 | } |
533 | 1019 | ||
534 | /* | 1020 | /** |
535 | * process after playback sync complete | 1021 | * snd_usb_handle_sync_urb: parse an USB sync packet |
536 | * | 1022 | * |
537 | * Full speed devices report feedback values in 10.14 format as samples per | 1023 | * @ep: the endpoint to handle the packet |
538 | * frame, high speed devices in 16.16 format as samples per microframe. | 1024 | * @sender: the sending endpoint |
539 | * Because the Audio Class 1 spec was written before USB 2.0, many high speed | 1025 | * @urb: the received packet |
540 | * devices use a wrong interpretation, some others use an entirely different | 1026 | * |
541 | * format. Therefore, we cannot predict what format any particular device uses | 1027 | * This function is called from the context of an endpoint that received |
542 | * and must detect it automatically. | 1028 | * the packet and is used to let another endpoint object handle the payload. |
543 | */ | 1029 | */ |
544 | static int retire_playback_sync_urb(struct snd_usb_substream *subs, | 1030 | void snd_usb_handle_sync_urb(struct snd_usb_endpoint *ep, |
545 | struct snd_pcm_runtime *runtime, | 1031 | struct snd_usb_endpoint *sender, |
546 | struct urb *urb) | 1032 | const struct urb *urb) |
547 | { | 1033 | { |
548 | unsigned int f; | ||
549 | int shift; | 1034 | int shift; |
1035 | unsigned int f; | ||
550 | unsigned long flags; | 1036 | unsigned long flags; |
551 | 1037 | ||
1038 | snd_BUG_ON(ep == sender); | ||
1039 | |||
1040 | /* | ||
1041 | * In case the endpoint is operating in implicit feedback mode, prepare | ||
1042 | * a new outbound URB that has the same layout as the received packet | ||
1043 | * and add it to the list of pending urbs. queue_pending_output_urbs() | ||
1044 | * will take care of them later. | ||
1045 | */ | ||
1046 | if (snd_usb_endpoint_implict_feedback_sink(ep) && | ||
1047 | ep->use_count != 0) { | ||
1048 | |||
1049 | /* implicit feedback case */ | ||
1050 | int i, bytes = 0; | ||
1051 | struct snd_urb_ctx *in_ctx; | ||
1052 | struct snd_usb_packet_info *out_packet; | ||
1053 | |||
1054 | in_ctx = urb->context; | ||
1055 | |||
1056 | /* Count overall packet size */ | ||
1057 | for (i = 0; i < in_ctx->packets; i++) | ||
1058 | if (urb->iso_frame_desc[i].status == 0) | ||
1059 | bytes += urb->iso_frame_desc[i].actual_length; | ||
1060 | |||
1061 | /* | ||
1062 | * skip empty packets. At least M-Audio's Fast Track Ultra stops | ||
1063 | * streaming once it received a 0-byte OUT URB | ||
1064 | */ | ||
1065 | if (bytes == 0) | ||
1066 | return; | ||
1067 | |||
1068 | spin_lock_irqsave(&ep->lock, flags); | ||
1069 | out_packet = ep->next_packet + ep->next_packet_write_pos; | ||
1070 | |||
1071 | /* | ||
1072 | * Iterate through the inbound packet and prepare the lengths | ||
1073 | * for the output packet. The OUT packet we are about to send | ||
1074 | * will have the same amount of payload bytes than the IN | ||
1075 | * packet we just received. | ||
1076 | */ | ||
1077 | |||
1078 | out_packet->packets = in_ctx->packets; | ||
1079 | for (i = 0; i < in_ctx->packets; i++) { | ||
1080 | if (urb->iso_frame_desc[i].status == 0) | ||
1081 | out_packet->packet_size[i] = | ||
1082 | urb->iso_frame_desc[i].actual_length / ep->stride; | ||
1083 | else | ||
1084 | out_packet->packet_size[i] = 0; | ||
1085 | } | ||
1086 | |||
1087 | ep->next_packet_write_pos++; | ||
1088 | ep->next_packet_write_pos %= MAX_URBS; | ||
1089 | spin_unlock_irqrestore(&ep->lock, flags); | ||
1090 | queue_pending_output_urbs(ep); | ||
1091 | |||
1092 | return; | ||
1093 | } | ||
1094 | |||
1095 | /* | ||
1096 | * process after playback sync complete | ||
1097 | * | ||
1098 | * Full speed devices report feedback values in 10.14 format as samples | ||
1099 | * per frame, high speed devices in 16.16 format as samples per | ||
1100 | * microframe. | ||
1101 | * | ||
1102 | * Because the Audio Class 1 spec was written before USB 2.0, many high | ||
1103 | * speed devices use a wrong interpretation, some others use an | ||
1104 | * entirely different format. | ||
1105 | * | ||
1106 | * Therefore, we cannot predict what format any particular device uses | ||
1107 | * and must detect it automatically. | ||
1108 | */ | ||
1109 | |||
552 | if (urb->iso_frame_desc[0].status != 0 || | 1110 | if (urb->iso_frame_desc[0].status != 0 || |
553 | urb->iso_frame_desc[0].actual_length < 3) | 1111 | urb->iso_frame_desc[0].actual_length < 3) |
554 | return 0; | 1112 | return; |
555 | 1113 | ||
556 | f = le32_to_cpup(urb->transfer_buffer); | 1114 | f = le32_to_cpup(urb->transfer_buffer); |
557 | if (urb->iso_frame_desc[0].actual_length == 3) | 1115 | if (urb->iso_frame_desc[0].actual_length == 3) |
558 | f &= 0x00ffffff; | 1116 | f &= 0x00ffffff; |
559 | else | 1117 | else |
560 | f &= 0x0fffffff; | 1118 | f &= 0x0fffffff; |
1119 | |||
561 | if (f == 0) | 1120 | if (f == 0) |
562 | return 0; | 1121 | return; |
563 | 1122 | ||
564 | if (unlikely(subs->freqshift == INT_MIN)) { | 1123 | if (unlikely(ep->freqshift == INT_MIN)) { |
565 | /* | 1124 | /* |
566 | * The first time we see a feedback value, determine its format | 1125 | * The first time we see a feedback value, determine its format |
567 | * by shifting it left or right until it matches the nominal | 1126 | * by shifting it left or right until it matches the nominal |
@@ -569,398 +1128,34 @@ static int retire_playback_sync_urb(struct snd_usb_substream *subs, | |||
569 | * differ from the nominal value more than +50% or -25%. | 1128 | * differ from the nominal value more than +50% or -25%. |
570 | */ | 1129 | */ |
571 | shift = 0; | 1130 | shift = 0; |
572 | while (f < subs->freqn - subs->freqn / 4) { | 1131 | while (f < ep->freqn - ep->freqn / 4) { |
573 | f <<= 1; | 1132 | f <<= 1; |
574 | shift++; | 1133 | shift++; |
575 | } | 1134 | } |
576 | while (f > subs->freqn + subs->freqn / 2) { | 1135 | while (f > ep->freqn + ep->freqn / 2) { |
577 | f >>= 1; | 1136 | f >>= 1; |
578 | shift--; | 1137 | shift--; |
579 | } | 1138 | } |
580 | subs->freqshift = shift; | 1139 | ep->freqshift = shift; |
581 | } | 1140 | } else if (ep->freqshift >= 0) |
582 | else if (subs->freqshift >= 0) | 1141 | f <<= ep->freqshift; |
583 | f <<= subs->freqshift; | ||
584 | else | 1142 | else |
585 | f >>= -subs->freqshift; | 1143 | f >>= -ep->freqshift; |
586 | 1144 | ||
587 | if (likely(f >= subs->freqn - subs->freqn / 8 && f <= subs->freqmax)) { | 1145 | if (likely(f >= ep->freqn - ep->freqn / 8 && f <= ep->freqmax)) { |
588 | /* | 1146 | /* |
589 | * If the frequency looks valid, set it. | 1147 | * If the frequency looks valid, set it. |
590 | * This value is referred to in prepare_playback_urb(). | 1148 | * This value is referred to in prepare_playback_urb(). |
591 | */ | 1149 | */ |
592 | spin_lock_irqsave(&subs->lock, flags); | 1150 | spin_lock_irqsave(&ep->lock, flags); |
593 | subs->freqm = f; | 1151 | ep->freqm = f; |
594 | spin_unlock_irqrestore(&subs->lock, flags); | 1152 | spin_unlock_irqrestore(&ep->lock, flags); |
595 | } else { | 1153 | } else { |
596 | /* | 1154 | /* |
597 | * Out of range; maybe the shift value is wrong. | 1155 | * Out of range; maybe the shift value is wrong. |
598 | * Reset it so that we autodetect again the next time. | 1156 | * Reset it so that we autodetect again the next time. |
599 | */ | 1157 | */ |
600 | subs->freqshift = INT_MIN; | 1158 | ep->freqshift = INT_MIN; |
601 | } | ||
602 | |||
603 | return 0; | ||
604 | } | ||
605 | |||
606 | /* determine the number of frames in the next packet */ | ||
607 | static int snd_usb_audio_next_packet_size(struct snd_usb_substream *subs) | ||
608 | { | ||
609 | if (subs->fill_max) | ||
610 | return subs->maxframesize; | ||
611 | else { | ||
612 | subs->phase = (subs->phase & 0xffff) | ||
613 | + (subs->freqm << subs->datainterval); | ||
614 | return min(subs->phase >> 16, subs->maxframesize); | ||
615 | } | 1159 | } |
616 | } | 1160 | } |
617 | 1161 | ||
618 | /* | ||
619 | * Prepare urb for streaming before playback starts or when paused. | ||
620 | * | ||
621 | * We don't have any data, so we send silence. | ||
622 | */ | ||
623 | static int prepare_nodata_playback_urb(struct snd_usb_substream *subs, | ||
624 | struct snd_pcm_runtime *runtime, | ||
625 | struct urb *urb) | ||
626 | { | ||
627 | unsigned int i, offs, counts; | ||
628 | struct snd_urb_ctx *ctx = urb->context; | ||
629 | int stride = runtime->frame_bits >> 3; | ||
630 | |||
631 | offs = 0; | ||
632 | urb->dev = ctx->subs->dev; | ||
633 | for (i = 0; i < ctx->packets; ++i) { | ||
634 | counts = snd_usb_audio_next_packet_size(subs); | ||
635 | urb->iso_frame_desc[i].offset = offs * stride; | ||
636 | urb->iso_frame_desc[i].length = counts * stride; | ||
637 | offs += counts; | ||
638 | } | ||
639 | urb->number_of_packets = ctx->packets; | ||
640 | urb->transfer_buffer_length = offs * stride; | ||
641 | memset(urb->transfer_buffer, | ||
642 | runtime->format == SNDRV_PCM_FORMAT_U8 ? 0x80 : 0, | ||
643 | offs * stride); | ||
644 | return 0; | ||
645 | } | ||
646 | |||
647 | /* | ||
648 | * prepare urb for playback data pipe | ||
649 | * | ||
650 | * Since a URB can handle only a single linear buffer, we must use double | ||
651 | * buffering when the data to be transferred overflows the buffer boundary. | ||
652 | * To avoid inconsistencies when updating hwptr_done, we use double buffering | ||
653 | * for all URBs. | ||
654 | */ | ||
655 | static int prepare_playback_urb(struct snd_usb_substream *subs, | ||
656 | struct snd_pcm_runtime *runtime, | ||
657 | struct urb *urb) | ||
658 | { | ||
659 | int i, stride; | ||
660 | unsigned int counts, frames, bytes; | ||
661 | unsigned long flags; | ||
662 | int period_elapsed = 0; | ||
663 | struct snd_urb_ctx *ctx = urb->context; | ||
664 | |||
665 | stride = runtime->frame_bits >> 3; | ||
666 | |||
667 | frames = 0; | ||
668 | urb->dev = ctx->subs->dev; /* we need to set this at each time */ | ||
669 | urb->number_of_packets = 0; | ||
670 | spin_lock_irqsave(&subs->lock, flags); | ||
671 | for (i = 0; i < ctx->packets; i++) { | ||
672 | counts = snd_usb_audio_next_packet_size(subs); | ||
673 | /* set up descriptor */ | ||
674 | urb->iso_frame_desc[i].offset = frames * stride; | ||
675 | urb->iso_frame_desc[i].length = counts * stride; | ||
676 | frames += counts; | ||
677 | urb->number_of_packets++; | ||
678 | subs->transfer_done += counts; | ||
679 | if (subs->transfer_done >= runtime->period_size) { | ||
680 | subs->transfer_done -= runtime->period_size; | ||
681 | period_elapsed = 1; | ||
682 | if (subs->fmt_type == UAC_FORMAT_TYPE_II) { | ||
683 | if (subs->transfer_done > 0) { | ||
684 | /* FIXME: fill-max mode is not | ||
685 | * supported yet */ | ||
686 | frames -= subs->transfer_done; | ||
687 | counts -= subs->transfer_done; | ||
688 | urb->iso_frame_desc[i].length = | ||
689 | counts * stride; | ||
690 | subs->transfer_done = 0; | ||
691 | } | ||
692 | i++; | ||
693 | if (i < ctx->packets) { | ||
694 | /* add a transfer delimiter */ | ||
695 | urb->iso_frame_desc[i].offset = | ||
696 | frames * stride; | ||
697 | urb->iso_frame_desc[i].length = 0; | ||
698 | urb->number_of_packets++; | ||
699 | } | ||
700 | break; | ||
701 | } | ||
702 | } | ||
703 | if (period_elapsed) /* finish at the period boundary */ | ||
704 | break; | ||
705 | } | ||
706 | bytes = frames * stride; | ||
707 | if (subs->hwptr_done + bytes > runtime->buffer_size * stride) { | ||
708 | /* err, the transferred area goes over buffer boundary. */ | ||
709 | unsigned int bytes1 = | ||
710 | runtime->buffer_size * stride - subs->hwptr_done; | ||
711 | memcpy(urb->transfer_buffer, | ||
712 | runtime->dma_area + subs->hwptr_done, bytes1); | ||
713 | memcpy(urb->transfer_buffer + bytes1, | ||
714 | runtime->dma_area, bytes - bytes1); | ||
715 | } else { | ||
716 | memcpy(urb->transfer_buffer, | ||
717 | runtime->dma_area + subs->hwptr_done, bytes); | ||
718 | } | ||
719 | subs->hwptr_done += bytes; | ||
720 | if (subs->hwptr_done >= runtime->buffer_size * stride) | ||
721 | subs->hwptr_done -= runtime->buffer_size * stride; | ||
722 | |||
723 | /* update delay with exact number of samples queued */ | ||
724 | runtime->delay = subs->last_delay; | ||
725 | runtime->delay += frames; | ||
726 | subs->last_delay = runtime->delay; | ||
727 | |||
728 | /* realign last_frame_number */ | ||
729 | subs->last_frame_number = usb_get_current_frame_number(subs->dev); | ||
730 | subs->last_frame_number &= 0xFF; /* keep 8 LSBs */ | ||
731 | |||
732 | spin_unlock_irqrestore(&subs->lock, flags); | ||
733 | urb->transfer_buffer_length = bytes; | ||
734 | if (period_elapsed) | ||
735 | snd_pcm_period_elapsed(subs->pcm_substream); | ||
736 | return 0; | ||
737 | } | ||
738 | |||
739 | /* | ||
740 | * process after playback data complete | ||
741 | * - decrease the delay count again | ||
742 | */ | ||
743 | static int retire_playback_urb(struct snd_usb_substream *subs, | ||
744 | struct snd_pcm_runtime *runtime, | ||
745 | struct urb *urb) | ||
746 | { | ||
747 | unsigned long flags; | ||
748 | int stride = runtime->frame_bits >> 3; | ||
749 | int processed = urb->transfer_buffer_length / stride; | ||
750 | int est_delay; | ||
751 | |||
752 | spin_lock_irqsave(&subs->lock, flags); | ||
753 | |||
754 | est_delay = snd_usb_pcm_delay(subs, runtime->rate); | ||
755 | /* update delay with exact number of samples played */ | ||
756 | if (processed > subs->last_delay) | ||
757 | subs->last_delay = 0; | ||
758 | else | ||
759 | subs->last_delay -= processed; | ||
760 | runtime->delay = subs->last_delay; | ||
761 | |||
762 | /* | ||
763 | * Report when delay estimate is off by more than 2ms. | ||
764 | * The error should be lower than 2ms since the estimate relies | ||
765 | * on two reads of a counter updated every ms. | ||
766 | */ | ||
767 | if (abs(est_delay - subs->last_delay) * 1000 > runtime->rate * 2) | ||
768 | snd_printk(KERN_DEBUG "delay: estimated %d, actual %d\n", | ||
769 | est_delay, subs->last_delay); | ||
770 | |||
771 | spin_unlock_irqrestore(&subs->lock, flags); | ||
772 | return 0; | ||
773 | } | ||
774 | |||
775 | static const char *usb_error_string(int err) | ||
776 | { | ||
777 | switch (err) { | ||
778 | case -ENODEV: | ||
779 | return "no device"; | ||
780 | case -ENOENT: | ||
781 | return "endpoint not enabled"; | ||
782 | case -EPIPE: | ||
783 | return "endpoint stalled"; | ||
784 | case -ENOSPC: | ||
785 | return "not enough bandwidth"; | ||
786 | case -ESHUTDOWN: | ||
787 | return "device disabled"; | ||
788 | case -EHOSTUNREACH: | ||
789 | return "device suspended"; | ||
790 | case -EINVAL: | ||
791 | case -EAGAIN: | ||
792 | case -EFBIG: | ||
793 | case -EMSGSIZE: | ||
794 | return "internal error"; | ||
795 | default: | ||
796 | return "unknown error"; | ||
797 | } | ||
798 | } | ||
799 | |||
800 | /* | ||
801 | * set up and start data/sync urbs | ||
802 | */ | ||
803 | static int start_urbs(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime) | ||
804 | { | ||
805 | unsigned int i; | ||
806 | int err; | ||
807 | |||
808 | if (subs->stream->chip->shutdown) | ||
809 | return -EBADFD; | ||
810 | |||
811 | for (i = 0; i < subs->nurbs; i++) { | ||
812 | if (snd_BUG_ON(!subs->dataurb[i].urb)) | ||
813 | return -EINVAL; | ||
814 | if (subs->ops.prepare(subs, runtime, subs->dataurb[i].urb) < 0) { | ||
815 | snd_printk(KERN_ERR "cannot prepare datapipe for urb %d\n", i); | ||
816 | goto __error; | ||
817 | } | ||
818 | } | ||
819 | if (subs->syncpipe) { | ||
820 | for (i = 0; i < SYNC_URBS; i++) { | ||
821 | if (snd_BUG_ON(!subs->syncurb[i].urb)) | ||
822 | return -EINVAL; | ||
823 | if (subs->ops.prepare_sync(subs, runtime, subs->syncurb[i].urb) < 0) { | ||
824 | snd_printk(KERN_ERR "cannot prepare syncpipe for urb %d\n", i); | ||
825 | goto __error; | ||
826 | } | ||
827 | } | ||
828 | } | ||
829 | |||
830 | subs->active_mask = 0; | ||
831 | subs->unlink_mask = 0; | ||
832 | subs->running = 1; | ||
833 | for (i = 0; i < subs->nurbs; i++) { | ||
834 | err = usb_submit_urb(subs->dataurb[i].urb, GFP_ATOMIC); | ||
835 | if (err < 0) { | ||
836 | snd_printk(KERN_ERR "cannot submit datapipe " | ||
837 | "for urb %d, error %d: %s\n", | ||
838 | i, err, usb_error_string(err)); | ||
839 | goto __error; | ||
840 | } | ||
841 | set_bit(i, &subs->active_mask); | ||
842 | } | ||
843 | if (subs->syncpipe) { | ||
844 | for (i = 0; i < SYNC_URBS; i++) { | ||
845 | err = usb_submit_urb(subs->syncurb[i].urb, GFP_ATOMIC); | ||
846 | if (err < 0) { | ||
847 | snd_printk(KERN_ERR "cannot submit syncpipe " | ||
848 | "for urb %d, error %d: %s\n", | ||
849 | i, err, usb_error_string(err)); | ||
850 | goto __error; | ||
851 | } | ||
852 | set_bit(i + 16, &subs->active_mask); | ||
853 | } | ||
854 | } | ||
855 | return 0; | ||
856 | |||
857 | __error: | ||
858 | // snd_pcm_stop(subs->pcm_substream, SNDRV_PCM_STATE_XRUN); | ||
859 | deactivate_urbs(subs, 0, 0); | ||
860 | return -EPIPE; | ||
861 | } | ||
862 | |||
863 | |||
864 | /* | ||
865 | */ | ||
866 | static struct snd_urb_ops audio_urb_ops[2] = { | ||
867 | { | ||
868 | .prepare = prepare_nodata_playback_urb, | ||
869 | .retire = retire_playback_urb, | ||
870 | .prepare_sync = prepare_playback_sync_urb, | ||
871 | .retire_sync = retire_playback_sync_urb, | ||
872 | }, | ||
873 | { | ||
874 | .prepare = prepare_capture_urb, | ||
875 | .retire = retire_capture_urb, | ||
876 | .prepare_sync = prepare_capture_sync_urb, | ||
877 | .retire_sync = retire_capture_sync_urb, | ||
878 | }, | ||
879 | }; | ||
880 | |||
881 | /* | ||
882 | * initialize the substream instance. | ||
883 | */ | ||
884 | |||
885 | void snd_usb_init_substream(struct snd_usb_stream *as, | ||
886 | int stream, struct audioformat *fp) | ||
887 | { | ||
888 | struct snd_usb_substream *subs = &as->substream[stream]; | ||
889 | |||
890 | INIT_LIST_HEAD(&subs->fmt_list); | ||
891 | spin_lock_init(&subs->lock); | ||
892 | |||
893 | subs->stream = as; | ||
894 | subs->direction = stream; | ||
895 | subs->dev = as->chip->dev; | ||
896 | subs->txfr_quirk = as->chip->txfr_quirk; | ||
897 | subs->ops = audio_urb_ops[stream]; | ||
898 | if (snd_usb_get_speed(subs->dev) >= USB_SPEED_HIGH) | ||
899 | subs->ops.prepare_sync = prepare_capture_sync_urb_hs; | ||
900 | |||
901 | snd_usb_set_pcm_ops(as->pcm, stream); | ||
902 | |||
903 | list_add_tail(&fp->list, &subs->fmt_list); | ||
904 | subs->formats |= fp->formats; | ||
905 | subs->endpoint = fp->endpoint; | ||
906 | subs->num_formats++; | ||
907 | subs->fmt_type = fp->fmt_type; | ||
908 | } | ||
909 | |||
910 | int snd_usb_substream_playback_trigger(struct snd_pcm_substream *substream, int cmd) | ||
911 | { | ||
912 | struct snd_usb_substream *subs = substream->runtime->private_data; | ||
913 | |||
914 | switch (cmd) { | ||
915 | case SNDRV_PCM_TRIGGER_START: | ||
916 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: | ||
917 | subs->ops.prepare = prepare_playback_urb; | ||
918 | return 0; | ||
919 | case SNDRV_PCM_TRIGGER_STOP: | ||
920 | return deactivate_urbs(subs, 0, 0); | ||
921 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: | ||
922 | subs->ops.prepare = prepare_nodata_playback_urb; | ||
923 | return 0; | ||
924 | } | ||
925 | |||
926 | return -EINVAL; | ||
927 | } | ||
928 | |||
929 | int snd_usb_substream_capture_trigger(struct snd_pcm_substream *substream, int cmd) | ||
930 | { | ||
931 | struct snd_usb_substream *subs = substream->runtime->private_data; | ||
932 | |||
933 | switch (cmd) { | ||
934 | case SNDRV_PCM_TRIGGER_START: | ||
935 | subs->ops.retire = retire_capture_urb; | ||
936 | return start_urbs(subs, substream->runtime); | ||
937 | case SNDRV_PCM_TRIGGER_STOP: | ||
938 | return deactivate_urbs(subs, 0, 0); | ||
939 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: | ||
940 | subs->ops.retire = retire_paused_capture_urb; | ||
941 | return 0; | ||
942 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: | ||
943 | subs->ops.retire = retire_capture_urb; | ||
944 | return 0; | ||
945 | } | ||
946 | |||
947 | return -EINVAL; | ||
948 | } | ||
949 | |||
950 | int snd_usb_substream_prepare(struct snd_usb_substream *subs, | ||
951 | struct snd_pcm_runtime *runtime) | ||
952 | { | ||
953 | /* clear urbs (to be sure) */ | ||
954 | deactivate_urbs(subs, 0, 1); | ||
955 | wait_clear_urbs(subs); | ||
956 | |||
957 | /* for playback, submit the URBs now; otherwise, the first hwptr_done | ||
958 | * updates for all URBs would happen at the same time when starting */ | ||
959 | if (subs->direction == SNDRV_PCM_STREAM_PLAYBACK) { | ||
960 | subs->ops.prepare = prepare_nodata_playback_urb; | ||
961 | return start_urbs(subs, runtime); | ||
962 | } | ||
963 | |||
964 | return 0; | ||
965 | } | ||
966 | |||
diff --git a/sound/usb/endpoint.h b/sound/usb/endpoint.h index 88eb63a636eb..ee2723fb174f 100644 --- a/sound/usb/endpoint.h +++ b/sound/usb/endpoint.h | |||
@@ -1,21 +1,29 @@ | |||
1 | #ifndef __USBAUDIO_ENDPOINT_H | 1 | #ifndef __USBAUDIO_ENDPOINT_H |
2 | #define __USBAUDIO_ENDPOINT_H | 2 | #define __USBAUDIO_ENDPOINT_H |
3 | 3 | ||
4 | void snd_usb_init_substream(struct snd_usb_stream *as, | 4 | #define SND_USB_ENDPOINT_TYPE_DATA 0 |
5 | int stream, | 5 | #define SND_USB_ENDPOINT_TYPE_SYNC 1 |
6 | struct audioformat *fp); | ||
7 | 6 | ||
8 | int snd_usb_init_substream_urbs(struct snd_usb_substream *subs, | 7 | struct snd_usb_endpoint *snd_usb_add_endpoint(struct snd_usb_audio *chip, |
9 | unsigned int period_bytes, | 8 | struct usb_host_interface *alts, |
10 | unsigned int rate, | 9 | int ep_num, int direction, int type); |
11 | unsigned int frame_bits); | ||
12 | 10 | ||
13 | void snd_usb_release_substream_urbs(struct snd_usb_substream *subs, int force); | 11 | int snd_usb_endpoint_set_params(struct snd_usb_endpoint *ep, |
12 | struct snd_pcm_hw_params *hw_params, | ||
13 | struct audioformat *fmt, | ||
14 | struct snd_usb_endpoint *sync_ep); | ||
14 | 15 | ||
15 | int snd_usb_substream_prepare(struct snd_usb_substream *subs, | 16 | int snd_usb_endpoint_start(struct snd_usb_endpoint *ep); |
16 | struct snd_pcm_runtime *runtime); | 17 | void snd_usb_endpoint_stop(struct snd_usb_endpoint *ep, |
18 | int force, int can_sleep, int wait); | ||
19 | int snd_usb_endpoint_activate(struct snd_usb_endpoint *ep); | ||
20 | int snd_usb_endpoint_deactivate(struct snd_usb_endpoint *ep); | ||
21 | void snd_usb_endpoint_free(struct list_head *head); | ||
17 | 22 | ||
18 | int snd_usb_substream_playback_trigger(struct snd_pcm_substream *substream, int cmd); | 23 | int snd_usb_endpoint_implict_feedback_sink(struct snd_usb_endpoint *ep); |
19 | int snd_usb_substream_capture_trigger(struct snd_pcm_substream *substream, int cmd); | 24 | |
25 | void snd_usb_handle_sync_urb(struct snd_usb_endpoint *ep, | ||
26 | struct snd_usb_endpoint *sender, | ||
27 | const struct urb *urb); | ||
20 | 28 | ||
21 | #endif /* __USBAUDIO_ENDPOINT_H */ | 29 | #endif /* __USBAUDIO_ENDPOINT_H */ |
diff --git a/sound/usb/mixer.c b/sound/usb/mixer.c index ab23869c01bb..4f40ba823163 100644 --- a/sound/usb/mixer.c +++ b/sound/usb/mixer.c | |||
@@ -486,7 +486,7 @@ static int set_cur_mix_value(struct usb_mixer_elem_info *cval, int channel, | |||
486 | /* | 486 | /* |
487 | * TLV callback for mixer volume controls | 487 | * TLV callback for mixer volume controls |
488 | */ | 488 | */ |
489 | static int mixer_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag, | 489 | int snd_usb_mixer_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag, |
490 | unsigned int size, unsigned int __user *_tlv) | 490 | unsigned int size, unsigned int __user *_tlv) |
491 | { | 491 | { |
492 | struct usb_mixer_elem_info *cval = kcontrol->private_data; | 492 | struct usb_mixer_elem_info *cval = kcontrol->private_data; |
@@ -770,6 +770,26 @@ static void volume_control_quirks(struct usb_mixer_elem_info *cval, | |||
770 | struct snd_kcontrol *kctl) | 770 | struct snd_kcontrol *kctl) |
771 | { | 771 | { |
772 | switch (cval->mixer->chip->usb_id) { | 772 | switch (cval->mixer->chip->usb_id) { |
773 | case USB_ID(0x0763, 0x2081): /* M-Audio Fast Track Ultra 8R */ | ||
774 | case USB_ID(0x0763, 0x2080): /* M-Audio Fast Track Ultra */ | ||
775 | if (strcmp(kctl->id.name, "Effect Duration") == 0) { | ||
776 | snd_printk(KERN_INFO | ||
777 | "usb-audio: set quirk for FTU Effect Duration\n"); | ||
778 | cval->min = 0x0000; | ||
779 | cval->max = 0x7f00; | ||
780 | cval->res = 0x0100; | ||
781 | break; | ||
782 | } | ||
783 | if (strcmp(kctl->id.name, "Effect Volume") == 0 || | ||
784 | strcmp(kctl->id.name, "Effect Feedback Volume") == 0) { | ||
785 | snd_printk(KERN_INFO | ||
786 | "usb-audio: set quirks for FTU Effect Feedback/Volume\n"); | ||
787 | cval->min = 0x00; | ||
788 | cval->max = 0x7f; | ||
789 | break; | ||
790 | } | ||
791 | break; | ||
792 | |||
773 | case USB_ID(0x0471, 0x0101): | 793 | case USB_ID(0x0471, 0x0101): |
774 | case USB_ID(0x0471, 0x0104): | 794 | case USB_ID(0x0471, 0x0104): |
775 | case USB_ID(0x0471, 0x0105): | 795 | case USB_ID(0x0471, 0x0105): |
@@ -1121,9 +1141,6 @@ static void build_feature_ctl(struct mixer_build *state, void *raw_desc, | |||
1121 | len = snd_usb_copy_string_desc(state, nameid, | 1141 | len = snd_usb_copy_string_desc(state, nameid, |
1122 | kctl->id.name, sizeof(kctl->id.name)); | 1142 | kctl->id.name, sizeof(kctl->id.name)); |
1123 | 1143 | ||
1124 | /* get min/max values */ | ||
1125 | get_min_max_with_quirks(cval, 0, kctl); | ||
1126 | |||
1127 | switch (control) { | 1144 | switch (control) { |
1128 | case UAC_FU_MUTE: | 1145 | case UAC_FU_MUTE: |
1129 | case UAC_FU_VOLUME: | 1146 | case UAC_FU_VOLUME: |
@@ -1155,17 +1172,7 @@ static void build_feature_ctl(struct mixer_build *state, void *raw_desc, | |||
1155 | } | 1172 | } |
1156 | append_ctl_name(kctl, control == UAC_FU_MUTE ? | 1173 | append_ctl_name(kctl, control == UAC_FU_MUTE ? |
1157 | " Switch" : " Volume"); | 1174 | " Switch" : " Volume"); |
1158 | if (control == UAC_FU_VOLUME) { | ||
1159 | check_mapped_dB(map, cval); | ||
1160 | if (cval->dBmin < cval->dBmax || !cval->initialized) { | ||
1161 | kctl->tlv.c = mixer_vol_tlv; | ||
1162 | kctl->vd[0].access |= | ||
1163 | SNDRV_CTL_ELEM_ACCESS_TLV_READ | | ||
1164 | SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK; | ||
1165 | } | ||
1166 | } | ||
1167 | break; | 1175 | break; |
1168 | |||
1169 | default: | 1176 | default: |
1170 | if (! len) | 1177 | if (! len) |
1171 | strlcpy(kctl->id.name, audio_feature_info[control-1].name, | 1178 | strlcpy(kctl->id.name, audio_feature_info[control-1].name, |
@@ -1173,6 +1180,19 @@ static void build_feature_ctl(struct mixer_build *state, void *raw_desc, | |||
1173 | break; | 1180 | break; |
1174 | } | 1181 | } |
1175 | 1182 | ||
1183 | /* get min/max values */ | ||
1184 | get_min_max_with_quirks(cval, 0, kctl); | ||
1185 | |||
1186 | if (control == UAC_FU_VOLUME) { | ||
1187 | check_mapped_dB(map, cval); | ||
1188 | if (cval->dBmin < cval->dBmax || !cval->initialized) { | ||
1189 | kctl->tlv.c = snd_usb_mixer_vol_tlv; | ||
1190 | kctl->vd[0].access |= | ||
1191 | SNDRV_CTL_ELEM_ACCESS_TLV_READ | | ||
1192 | SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK; | ||
1193 | } | ||
1194 | } | ||
1195 | |||
1176 | range = (cval->max - cval->min) / cval->res; | 1196 | range = (cval->max - cval->min) / cval->res; |
1177 | /* Are there devices with volume range more than 255? I use a bit more | 1197 | /* Are there devices with volume range more than 255? I use a bit more |
1178 | * to be sure. 384 is a resolution magic number found on Logitech | 1198 | * to be sure. 384 is a resolution magic number found on Logitech |
@@ -1388,7 +1408,7 @@ static int parse_audio_mixer_unit(struct mixer_build *state, int unitid, void *r | |||
1388 | for (pin = 0; pin < input_pins; pin++) { | 1408 | for (pin = 0; pin < input_pins; pin++) { |
1389 | err = parse_audio_unit(state, desc->baSourceID[pin]); | 1409 | err = parse_audio_unit(state, desc->baSourceID[pin]); |
1390 | if (err < 0) | 1410 | if (err < 0) |
1391 | return err; | 1411 | continue; |
1392 | err = check_input_term(state, desc->baSourceID[pin], &iterm); | 1412 | err = check_input_term(state, desc->baSourceID[pin], &iterm); |
1393 | if (err < 0) | 1413 | if (err < 0) |
1394 | return err; | 1414 | return err; |
diff --git a/sound/usb/mixer.h b/sound/usb/mixer.h index 81b2d8a32fb0..a7f3d45a8acf 100644 --- a/sound/usb/mixer.h +++ b/sound/usb/mixer.h | |||
@@ -68,4 +68,7 @@ int snd_usb_mixer_activate(struct usb_mixer_interface *mixer); | |||
68 | int snd_usb_mixer_add_control(struct usb_mixer_interface *mixer, | 68 | int snd_usb_mixer_add_control(struct usb_mixer_interface *mixer, |
69 | struct snd_kcontrol *kctl); | 69 | struct snd_kcontrol *kctl); |
70 | 70 | ||
71 | int snd_usb_mixer_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag, | ||
72 | unsigned int size, unsigned int __user *_tlv); | ||
73 | |||
71 | #endif /* __USBMIXER_H */ | 74 | #endif /* __USBMIXER_H */ |
diff --git a/sound/usb/mixer_maps.c b/sound/usb/mixer_maps.c index f1324c423835..41daaa24c25f 100644 --- a/sound/usb/mixer_maps.c +++ b/sound/usb/mixer_maps.c | |||
@@ -288,6 +288,15 @@ static struct usbmix_name_map scratch_live_map[] = { | |||
288 | { 0 } /* terminator */ | 288 | { 0 } /* terminator */ |
289 | }; | 289 | }; |
290 | 290 | ||
291 | static struct usbmix_name_map ebox44_map[] = { | ||
292 | { 4, NULL }, /* FU */ | ||
293 | { 6, NULL }, /* MU */ | ||
294 | { 7, NULL }, /* FU */ | ||
295 | { 10, NULL }, /* FU */ | ||
296 | { 11, NULL }, /* MU */ | ||
297 | { 0 } | ||
298 | }; | ||
299 | |||
291 | /* "Gamesurround Muse Pocket LT" looks same like "Sound Blaster MP3+" | 300 | /* "Gamesurround Muse Pocket LT" looks same like "Sound Blaster MP3+" |
292 | * most importand difference is SU[8], it should be set to "Capture Source" | 301 | * most importand difference is SU[8], it should be set to "Capture Source" |
293 | * to make alsamixer and PA working properly. | 302 | * to make alsamixer and PA working properly. |
@@ -371,6 +380,10 @@ static struct usbmix_ctl_map usbmix_ctl_maps[] = { | |||
371 | .map = scratch_live_map, | 380 | .map = scratch_live_map, |
372 | .ignore_ctl_error = 1, | 381 | .ignore_ctl_error = 1, |
373 | }, | 382 | }, |
383 | { | ||
384 | .id = USB_ID(0x200c, 0x1018), | ||
385 | .map = ebox44_map, | ||
386 | }, | ||
374 | { 0 } /* terminator */ | 387 | { 0 } /* terminator */ |
375 | }; | 388 | }; |
376 | 389 | ||
diff --git a/sound/usb/mixer_quirks.c b/sound/usb/mixer_quirks.c index ab125ee0b0f0..41f4b6911920 100644 --- a/sound/usb/mixer_quirks.c +++ b/sound/usb/mixer_quirks.c | |||
@@ -42,6 +42,77 @@ | |||
42 | 42 | ||
43 | extern struct snd_kcontrol_new *snd_usb_feature_unit_ctl; | 43 | extern struct snd_kcontrol_new *snd_usb_feature_unit_ctl; |
44 | 44 | ||
45 | /* private_free callback */ | ||
46 | static void usb_mixer_elem_free(struct snd_kcontrol *kctl) | ||
47 | { | ||
48 | kfree(kctl->private_data); | ||
49 | kctl->private_data = NULL; | ||
50 | } | ||
51 | |||
52 | /* This function allows for the creation of standard UAC controls. | ||
53 | * See the quirks for M-Audio FTUs or Ebox-44. | ||
54 | * If you don't want to set a TLV callback pass NULL. | ||
55 | * | ||
56 | * Since there doesn't seem to be a devices that needs a multichannel | ||
57 | * version, we keep it mono for simplicity. | ||
58 | */ | ||
59 | static int snd_create_std_mono_ctl(struct usb_mixer_interface *mixer, | ||
60 | unsigned int unitid, | ||
61 | unsigned int control, | ||
62 | unsigned int cmask, | ||
63 | int val_type, | ||
64 | const char *name, | ||
65 | snd_kcontrol_tlv_rw_t *tlv_callback) | ||
66 | { | ||
67 | int err; | ||
68 | struct usb_mixer_elem_info *cval; | ||
69 | struct snd_kcontrol *kctl; | ||
70 | |||
71 | cval = kzalloc(sizeof(*cval), GFP_KERNEL); | ||
72 | if (!cval) | ||
73 | return -ENOMEM; | ||
74 | |||
75 | cval->id = unitid; | ||
76 | cval->mixer = mixer; | ||
77 | cval->val_type = val_type; | ||
78 | cval->channels = 1; | ||
79 | cval->control = control; | ||
80 | cval->cmask = cmask; | ||
81 | |||
82 | /* get_min_max() is called only for integer volumes later, | ||
83 | * so provide a short-cut for booleans */ | ||
84 | cval->min = 0; | ||
85 | cval->max = 1; | ||
86 | cval->res = 0; | ||
87 | cval->dBmin = 0; | ||
88 | cval->dBmax = 0; | ||
89 | |||
90 | /* Create control */ | ||
91 | kctl = snd_ctl_new1(snd_usb_feature_unit_ctl, cval); | ||
92 | if (!kctl) { | ||
93 | kfree(cval); | ||
94 | return -ENOMEM; | ||
95 | } | ||
96 | |||
97 | /* Set name */ | ||
98 | snprintf(kctl->id.name, sizeof(kctl->id.name), name); | ||
99 | kctl->private_free = usb_mixer_elem_free; | ||
100 | |||
101 | /* set TLV */ | ||
102 | if (tlv_callback) { | ||
103 | kctl->tlv.c = tlv_callback; | ||
104 | kctl->vd[0].access |= | ||
105 | SNDRV_CTL_ELEM_ACCESS_TLV_READ | | ||
106 | SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK; | ||
107 | } | ||
108 | /* Add control to mixer */ | ||
109 | err = snd_usb_mixer_add_control(mixer, kctl); | ||
110 | if (err < 0) | ||
111 | return err; | ||
112 | |||
113 | return 0; | ||
114 | } | ||
115 | |||
45 | /* | 116 | /* |
46 | * Sound Blaster remote control configuration | 117 | * Sound Blaster remote control configuration |
47 | * | 118 | * |
@@ -495,60 +566,218 @@ static int snd_nativeinstruments_create_mixer(struct usb_mixer_interface *mixer, | |||
495 | } | 566 | } |
496 | 567 | ||
497 | /* M-Audio FastTrack Ultra quirks */ | 568 | /* M-Audio FastTrack Ultra quirks */ |
569 | /* FTU Effect switch */ | ||
570 | struct snd_ftu_eff_switch_priv_val { | ||
571 | struct usb_mixer_interface *mixer; | ||
572 | int cached_value; | ||
573 | int is_cached; | ||
574 | }; | ||
498 | 575 | ||
499 | /* private_free callback */ | 576 | static int snd_ftu_eff_switch_info(struct snd_kcontrol *kcontrol, |
500 | static void usb_mixer_elem_free(struct snd_kcontrol *kctl) | 577 | struct snd_ctl_elem_info *uinfo) |
501 | { | 578 | { |
502 | kfree(kctl->private_data); | 579 | static const char *texts[8] = {"Room 1", |
503 | kctl->private_data = NULL; | 580 | "Room 2", |
581 | "Room 3", | ||
582 | "Hall 1", | ||
583 | "Hall 2", | ||
584 | "Plate", | ||
585 | "Delay", | ||
586 | "Echo" | ||
587 | }; | ||
588 | |||
589 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; | ||
590 | uinfo->count = 1; | ||
591 | uinfo->value.enumerated.items = 8; | ||
592 | if (uinfo->value.enumerated.item > 7) | ||
593 | uinfo->value.enumerated.item = 7; | ||
594 | strcpy(uinfo->value.enumerated.name, | ||
595 | texts[uinfo->value.enumerated.item]); | ||
596 | |||
597 | return 0; | ||
504 | } | 598 | } |
505 | 599 | ||
506 | static int snd_maudio_ftu_create_ctl(struct usb_mixer_interface *mixer, | 600 | static int snd_ftu_eff_switch_get(struct snd_kcontrol *kctl, |
507 | int in, int out, const char *name) | 601 | struct snd_ctl_elem_value *ucontrol) |
508 | { | 602 | { |
509 | struct usb_mixer_elem_info *cval; | 603 | struct snd_usb_audio *chip; |
604 | struct usb_mixer_interface *mixer; | ||
605 | struct snd_ftu_eff_switch_priv_val *pval; | ||
606 | int err; | ||
607 | unsigned char value[2]; | ||
608 | |||
609 | const int id = 6; | ||
610 | const int validx = 1; | ||
611 | const int val_len = 2; | ||
612 | |||
613 | value[0] = 0x00; | ||
614 | value[1] = 0x00; | ||
615 | |||
616 | pval = (struct snd_ftu_eff_switch_priv_val *) | ||
617 | kctl->private_value; | ||
618 | |||
619 | if (pval->is_cached) { | ||
620 | ucontrol->value.enumerated.item[0] = pval->cached_value; | ||
621 | return 0; | ||
622 | } | ||
623 | |||
624 | mixer = (struct usb_mixer_interface *) pval->mixer; | ||
625 | if (snd_BUG_ON(!mixer)) | ||
626 | return -EINVAL; | ||
627 | |||
628 | chip = (struct snd_usb_audio *) mixer->chip; | ||
629 | if (snd_BUG_ON(!chip)) | ||
630 | return -EINVAL; | ||
631 | |||
632 | |||
633 | err = snd_usb_ctl_msg(chip->dev, | ||
634 | usb_rcvctrlpipe(chip->dev, 0), UAC_GET_CUR, | ||
635 | USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN, | ||
636 | validx << 8, snd_usb_ctrl_intf(chip) | (id << 8), | ||
637 | value, val_len); | ||
638 | if (err < 0) | ||
639 | return err; | ||
640 | |||
641 | ucontrol->value.enumerated.item[0] = value[0]; | ||
642 | pval->cached_value = value[0]; | ||
643 | pval->is_cached = 1; | ||
644 | |||
645 | return 0; | ||
646 | } | ||
647 | |||
648 | static int snd_ftu_eff_switch_put(struct snd_kcontrol *kctl, | ||
649 | struct snd_ctl_elem_value *ucontrol) | ||
650 | { | ||
651 | struct snd_usb_audio *chip; | ||
652 | struct snd_ftu_eff_switch_priv_val *pval; | ||
653 | |||
654 | struct usb_mixer_interface *mixer; | ||
655 | int changed, cur_val, err, new_val; | ||
656 | unsigned char value[2]; | ||
657 | |||
658 | |||
659 | const int id = 6; | ||
660 | const int validx = 1; | ||
661 | const int val_len = 2; | ||
662 | |||
663 | changed = 0; | ||
664 | |||
665 | pval = (struct snd_ftu_eff_switch_priv_val *) | ||
666 | kctl->private_value; | ||
667 | cur_val = pval->cached_value; | ||
668 | new_val = ucontrol->value.enumerated.item[0]; | ||
669 | |||
670 | mixer = (struct usb_mixer_interface *) pval->mixer; | ||
671 | if (snd_BUG_ON(!mixer)) | ||
672 | return -EINVAL; | ||
673 | |||
674 | chip = (struct snd_usb_audio *) mixer->chip; | ||
675 | if (snd_BUG_ON(!chip)) | ||
676 | return -EINVAL; | ||
677 | |||
678 | if (!pval->is_cached) { | ||
679 | /* Read current value */ | ||
680 | err = snd_usb_ctl_msg(chip->dev, | ||
681 | usb_rcvctrlpipe(chip->dev, 0), UAC_GET_CUR, | ||
682 | USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN, | ||
683 | validx << 8, snd_usb_ctrl_intf(chip) | (id << 8), | ||
684 | value, val_len); | ||
685 | if (err < 0) | ||
686 | return err; | ||
687 | |||
688 | cur_val = value[0]; | ||
689 | pval->cached_value = cur_val; | ||
690 | pval->is_cached = 1; | ||
691 | } | ||
692 | /* update value if needed */ | ||
693 | if (cur_val != new_val) { | ||
694 | value[0] = new_val; | ||
695 | value[1] = 0; | ||
696 | err = snd_usb_ctl_msg(chip->dev, | ||
697 | usb_sndctrlpipe(chip->dev, 0), UAC_SET_CUR, | ||
698 | USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT, | ||
699 | validx << 8, snd_usb_ctrl_intf(chip) | (id << 8), | ||
700 | value, val_len); | ||
701 | if (err < 0) | ||
702 | return err; | ||
703 | |||
704 | pval->cached_value = new_val; | ||
705 | pval->is_cached = 1; | ||
706 | changed = 1; | ||
707 | } | ||
708 | |||
709 | return changed; | ||
710 | } | ||
711 | |||
712 | static int snd_ftu_create_effect_switch(struct usb_mixer_interface *mixer) | ||
713 | { | ||
714 | static struct snd_kcontrol_new template = { | ||
715 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | ||
716 | .name = "Effect Program Switch", | ||
717 | .index = 0, | ||
718 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, | ||
719 | .info = snd_ftu_eff_switch_info, | ||
720 | .get = snd_ftu_eff_switch_get, | ||
721 | .put = snd_ftu_eff_switch_put | ||
722 | }; | ||
723 | |||
724 | int err; | ||
510 | struct snd_kcontrol *kctl; | 725 | struct snd_kcontrol *kctl; |
726 | struct snd_ftu_eff_switch_priv_val *pval; | ||
511 | 727 | ||
512 | cval = kzalloc(sizeof(*cval), GFP_KERNEL); | 728 | pval = kzalloc(sizeof(*pval), GFP_KERNEL); |
513 | if (!cval) | 729 | if (!pval) |
514 | return -ENOMEM; | 730 | return -ENOMEM; |
515 | 731 | ||
516 | cval->id = 5; | 732 | pval->cached_value = 0; |
517 | cval->mixer = mixer; | 733 | pval->is_cached = 0; |
518 | cval->val_type = USB_MIXER_S16; | 734 | pval->mixer = mixer; |
519 | cval->channels = 1; | ||
520 | cval->control = out + 1; | ||
521 | cval->cmask = 1 << in; | ||
522 | 735 | ||
523 | kctl = snd_ctl_new1(snd_usb_feature_unit_ctl, cval); | 736 | template.private_value = (unsigned long) pval; |
737 | kctl = snd_ctl_new1(&template, mixer->chip); | ||
524 | if (!kctl) { | 738 | if (!kctl) { |
525 | kfree(cval); | 739 | kfree(pval); |
526 | return -ENOMEM; | 740 | return -ENOMEM; |
527 | } | 741 | } |
528 | 742 | ||
529 | snprintf(kctl->id.name, sizeof(kctl->id.name), name); | 743 | err = snd_ctl_add(mixer->chip->card, kctl); |
530 | kctl->private_free = usb_mixer_elem_free; | 744 | if (err < 0) |
531 | return snd_usb_mixer_add_control(mixer, kctl); | 745 | return err; |
746 | |||
747 | return 0; | ||
532 | } | 748 | } |
533 | 749 | ||
534 | static int snd_maudio_ftu_create_mixer(struct usb_mixer_interface *mixer) | 750 | /* Create volume controls for FTU devices*/ |
751 | static int snd_ftu_create_volume_ctls(struct usb_mixer_interface *mixer) | ||
535 | { | 752 | { |
536 | char name[64]; | 753 | char name[64]; |
754 | unsigned int control, cmask; | ||
537 | int in, out, err; | 755 | int in, out, err; |
538 | 756 | ||
757 | const unsigned int id = 5; | ||
758 | const int val_type = USB_MIXER_S16; | ||
759 | |||
539 | for (out = 0; out < 8; out++) { | 760 | for (out = 0; out < 8; out++) { |
761 | control = out + 1; | ||
540 | for (in = 0; in < 8; in++) { | 762 | for (in = 0; in < 8; in++) { |
763 | cmask = 1 << in; | ||
541 | snprintf(name, sizeof(name), | 764 | snprintf(name, sizeof(name), |
542 | "AIn%d - Out%d Capture Volume", in + 1, out + 1); | 765 | "AIn%d - Out%d Capture Volume", |
543 | err = snd_maudio_ftu_create_ctl(mixer, in, out, name); | 766 | in + 1, out + 1); |
767 | err = snd_create_std_mono_ctl(mixer, id, control, | ||
768 | cmask, val_type, name, | ||
769 | &snd_usb_mixer_vol_tlv); | ||
544 | if (err < 0) | 770 | if (err < 0) |
545 | return err; | 771 | return err; |
546 | } | 772 | } |
547 | |||
548 | for (in = 8; in < 16; in++) { | 773 | for (in = 8; in < 16; in++) { |
774 | cmask = 1 << in; | ||
549 | snprintf(name, sizeof(name), | 775 | snprintf(name, sizeof(name), |
550 | "DIn%d - Out%d Playback Volume", in - 7, out + 1); | 776 | "DIn%d - Out%d Playback Volume", |
551 | err = snd_maudio_ftu_create_ctl(mixer, in, out, name); | 777 | in - 7, out + 1); |
778 | err = snd_create_std_mono_ctl(mixer, id, control, | ||
779 | cmask, val_type, name, | ||
780 | &snd_usb_mixer_vol_tlv); | ||
552 | if (err < 0) | 781 | if (err < 0) |
553 | return err; | 782 | return err; |
554 | } | 783 | } |
@@ -557,6 +786,191 @@ static int snd_maudio_ftu_create_mixer(struct usb_mixer_interface *mixer) | |||
557 | return 0; | 786 | return 0; |
558 | } | 787 | } |
559 | 788 | ||
789 | /* This control needs a volume quirk, see mixer.c */ | ||
790 | static int snd_ftu_create_effect_volume_ctl(struct usb_mixer_interface *mixer) | ||
791 | { | ||
792 | static const char name[] = "Effect Volume"; | ||
793 | const unsigned int id = 6; | ||
794 | const int val_type = USB_MIXER_U8; | ||
795 | const unsigned int control = 2; | ||
796 | const unsigned int cmask = 0; | ||
797 | |||
798 | return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type, | ||
799 | name, snd_usb_mixer_vol_tlv); | ||
800 | } | ||
801 | |||
802 | /* This control needs a volume quirk, see mixer.c */ | ||
803 | static int snd_ftu_create_effect_duration_ctl(struct usb_mixer_interface *mixer) | ||
804 | { | ||
805 | static const char name[] = "Effect Duration"; | ||
806 | const unsigned int id = 6; | ||
807 | const int val_type = USB_MIXER_S16; | ||
808 | const unsigned int control = 3; | ||
809 | const unsigned int cmask = 0; | ||
810 | |||
811 | return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type, | ||
812 | name, snd_usb_mixer_vol_tlv); | ||
813 | } | ||
814 | |||
815 | /* This control needs a volume quirk, see mixer.c */ | ||
816 | static int snd_ftu_create_effect_feedback_ctl(struct usb_mixer_interface *mixer) | ||
817 | { | ||
818 | static const char name[] = "Effect Feedback Volume"; | ||
819 | const unsigned int id = 6; | ||
820 | const int val_type = USB_MIXER_U8; | ||
821 | const unsigned int control = 4; | ||
822 | const unsigned int cmask = 0; | ||
823 | |||
824 | return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type, | ||
825 | name, NULL); | ||
826 | } | ||
827 | |||
828 | static int snd_ftu_create_effect_return_ctls(struct usb_mixer_interface *mixer) | ||
829 | { | ||
830 | unsigned int cmask; | ||
831 | int err, ch; | ||
832 | char name[48]; | ||
833 | |||
834 | const unsigned int id = 7; | ||
835 | const int val_type = USB_MIXER_S16; | ||
836 | const unsigned int control = 7; | ||
837 | |||
838 | for (ch = 0; ch < 4; ++ch) { | ||
839 | cmask = 1 << ch; | ||
840 | snprintf(name, sizeof(name), | ||
841 | "Effect Return %d Volume", ch + 1); | ||
842 | err = snd_create_std_mono_ctl(mixer, id, control, | ||
843 | cmask, val_type, name, | ||
844 | snd_usb_mixer_vol_tlv); | ||
845 | if (err < 0) | ||
846 | return err; | ||
847 | } | ||
848 | |||
849 | return 0; | ||
850 | } | ||
851 | |||
852 | static int snd_ftu_create_effect_send_ctls(struct usb_mixer_interface *mixer) | ||
853 | { | ||
854 | unsigned int cmask; | ||
855 | int err, ch; | ||
856 | char name[48]; | ||
857 | |||
858 | const unsigned int id = 5; | ||
859 | const int val_type = USB_MIXER_S16; | ||
860 | const unsigned int control = 9; | ||
861 | |||
862 | for (ch = 0; ch < 8; ++ch) { | ||
863 | cmask = 1 << ch; | ||
864 | snprintf(name, sizeof(name), | ||
865 | "Effect Send AIn%d Volume", ch + 1); | ||
866 | err = snd_create_std_mono_ctl(mixer, id, control, cmask, | ||
867 | val_type, name, | ||
868 | snd_usb_mixer_vol_tlv); | ||
869 | if (err < 0) | ||
870 | return err; | ||
871 | } | ||
872 | for (ch = 8; ch < 16; ++ch) { | ||
873 | cmask = 1 << ch; | ||
874 | snprintf(name, sizeof(name), | ||
875 | "Effect Send DIn%d Volume", ch - 7); | ||
876 | err = snd_create_std_mono_ctl(mixer, id, control, cmask, | ||
877 | val_type, name, | ||
878 | snd_usb_mixer_vol_tlv); | ||
879 | if (err < 0) | ||
880 | return err; | ||
881 | } | ||
882 | return 0; | ||
883 | } | ||
884 | |||
885 | static int snd_ftu_create_mixer(struct usb_mixer_interface *mixer) | ||
886 | { | ||
887 | int err; | ||
888 | |||
889 | err = snd_ftu_create_volume_ctls(mixer); | ||
890 | if (err < 0) | ||
891 | return err; | ||
892 | |||
893 | err = snd_ftu_create_effect_switch(mixer); | ||
894 | if (err < 0) | ||
895 | return err; | ||
896 | err = snd_ftu_create_effect_volume_ctl(mixer); | ||
897 | if (err < 0) | ||
898 | return err; | ||
899 | |||
900 | err = snd_ftu_create_effect_duration_ctl(mixer); | ||
901 | if (err < 0) | ||
902 | return err; | ||
903 | |||
904 | err = snd_ftu_create_effect_feedback_ctl(mixer); | ||
905 | if (err < 0) | ||
906 | return err; | ||
907 | |||
908 | err = snd_ftu_create_effect_return_ctls(mixer); | ||
909 | if (err < 0) | ||
910 | return err; | ||
911 | |||
912 | err = snd_ftu_create_effect_send_ctls(mixer); | ||
913 | if (err < 0) | ||
914 | return err; | ||
915 | |||
916 | return 0; | ||
917 | } | ||
918 | |||
919 | |||
920 | /* | ||
921 | * Create mixer for Electrix Ebox-44 | ||
922 | * | ||
923 | * The mixer units from this device are corrupt, and even where they | ||
924 | * are valid they presents mono controls as L and R channels of | ||
925 | * stereo. So we create a good mixer in code. | ||
926 | */ | ||
927 | |||
928 | static int snd_ebox44_create_mixer(struct usb_mixer_interface *mixer) | ||
929 | { | ||
930 | int err; | ||
931 | |||
932 | err = snd_create_std_mono_ctl(mixer, 4, 1, 0x0, USB_MIXER_INV_BOOLEAN, | ||
933 | "Headphone Playback Switch", NULL); | ||
934 | if (err < 0) | ||
935 | return err; | ||
936 | err = snd_create_std_mono_ctl(mixer, 4, 2, 0x1, USB_MIXER_S16, | ||
937 | "Headphone A Mix Playback Volume", NULL); | ||
938 | if (err < 0) | ||
939 | return err; | ||
940 | err = snd_create_std_mono_ctl(mixer, 4, 2, 0x2, USB_MIXER_S16, | ||
941 | "Headphone B Mix Playback Volume", NULL); | ||
942 | if (err < 0) | ||
943 | return err; | ||
944 | |||
945 | err = snd_create_std_mono_ctl(mixer, 7, 1, 0x0, USB_MIXER_INV_BOOLEAN, | ||
946 | "Output Playback Switch", NULL); | ||
947 | if (err < 0) | ||
948 | return err; | ||
949 | err = snd_create_std_mono_ctl(mixer, 7, 2, 0x1, USB_MIXER_S16, | ||
950 | "Output A Playback Volume", NULL); | ||
951 | if (err < 0) | ||
952 | return err; | ||
953 | err = snd_create_std_mono_ctl(mixer, 7, 2, 0x2, USB_MIXER_S16, | ||
954 | "Output B Playback Volume", NULL); | ||
955 | if (err < 0) | ||
956 | return err; | ||
957 | |||
958 | err = snd_create_std_mono_ctl(mixer, 10, 1, 0x0, USB_MIXER_INV_BOOLEAN, | ||
959 | "Input Capture Switch", NULL); | ||
960 | if (err < 0) | ||
961 | return err; | ||
962 | err = snd_create_std_mono_ctl(mixer, 10, 2, 0x1, USB_MIXER_S16, | ||
963 | "Input A Capture Volume", NULL); | ||
964 | if (err < 0) | ||
965 | return err; | ||
966 | err = snd_create_std_mono_ctl(mixer, 10, 2, 0x2, USB_MIXER_S16, | ||
967 | "Input B Capture Volume", NULL); | ||
968 | if (err < 0) | ||
969 | return err; | ||
970 | |||
971 | return 0; | ||
972 | } | ||
973 | |||
560 | void snd_emuusb_set_samplerate(struct snd_usb_audio *chip, | 974 | void snd_emuusb_set_samplerate(struct snd_usb_audio *chip, |
561 | unsigned char samplerate_id) | 975 | unsigned char samplerate_id) |
562 | { | 976 | { |
@@ -600,7 +1014,7 @@ int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer) | |||
600 | 1014 | ||
601 | case USB_ID(0x0763, 0x2080): /* M-Audio Fast Track Ultra */ | 1015 | case USB_ID(0x0763, 0x2080): /* M-Audio Fast Track Ultra */ |
602 | case USB_ID(0x0763, 0x2081): /* M-Audio Fast Track Ultra 8R */ | 1016 | case USB_ID(0x0763, 0x2081): /* M-Audio Fast Track Ultra 8R */ |
603 | err = snd_maudio_ftu_create_mixer(mixer); | 1017 | err = snd_ftu_create_mixer(mixer); |
604 | break; | 1018 | break; |
605 | 1019 | ||
606 | case USB_ID(0x0b05, 0x1739): | 1020 | case USB_ID(0x0b05, 0x1739): |
@@ -619,6 +1033,10 @@ int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer) | |||
619 | snd_nativeinstruments_ta10_mixers, | 1033 | snd_nativeinstruments_ta10_mixers, |
620 | ARRAY_SIZE(snd_nativeinstruments_ta10_mixers)); | 1034 | ARRAY_SIZE(snd_nativeinstruments_ta10_mixers)); |
621 | break; | 1035 | break; |
1036 | |||
1037 | case USB_ID(0x200c, 0x1018): /* Electrix Ebox-44 */ | ||
1038 | err = snd_ebox44_create_mixer(mixer); | ||
1039 | break; | ||
622 | } | 1040 | } |
623 | 1041 | ||
624 | return err; | 1042 | return err; |
diff --git a/sound/usb/pcm.c b/sound/usb/pcm.c index 0eed6115c2d4..24839d932648 100644 --- a/sound/usb/pcm.c +++ b/sound/usb/pcm.c | |||
@@ -16,6 +16,7 @@ | |||
16 | 16 | ||
17 | #include <linux/init.h> | 17 | #include <linux/init.h> |
18 | #include <linux/slab.h> | 18 | #include <linux/slab.h> |
19 | #include <linux/ratelimit.h> | ||
19 | #include <linux/usb.h> | 20 | #include <linux/usb.h> |
20 | #include <linux/usb/audio.h> | 21 | #include <linux/usb/audio.h> |
21 | #include <linux/usb/audio-v2.h> | 22 | #include <linux/usb/audio-v2.h> |
@@ -34,6 +35,9 @@ | |||
34 | #include "clock.h" | 35 | #include "clock.h" |
35 | #include "power.h" | 36 | #include "power.h" |
36 | 37 | ||
38 | #define SUBSTREAM_FLAG_DATA_EP_STARTED 0 | ||
39 | #define SUBSTREAM_FLAG_SYNC_EP_STARTED 1 | ||
40 | |||
37 | /* return the estimated delay based on USB frame counters */ | 41 | /* return the estimated delay based on USB frame counters */ |
38 | snd_pcm_uframes_t snd_usb_pcm_delay(struct snd_usb_substream *subs, | 42 | snd_pcm_uframes_t snd_usb_pcm_delay(struct snd_usb_substream *subs, |
39 | unsigned int rate) | 43 | unsigned int rate) |
@@ -208,6 +212,84 @@ int snd_usb_init_pitch(struct snd_usb_audio *chip, int iface, | |||
208 | } | 212 | } |
209 | } | 213 | } |
210 | 214 | ||
215 | static int start_endpoints(struct snd_usb_substream *subs) | ||
216 | { | ||
217 | int err; | ||
218 | |||
219 | if (!subs->data_endpoint) | ||
220 | return -EINVAL; | ||
221 | |||
222 | if (!test_and_set_bit(SUBSTREAM_FLAG_DATA_EP_STARTED, &subs->flags)) { | ||
223 | struct snd_usb_endpoint *ep = subs->data_endpoint; | ||
224 | |||
225 | snd_printdd(KERN_DEBUG "Starting data EP @%p\n", ep); | ||
226 | |||
227 | ep->data_subs = subs; | ||
228 | err = snd_usb_endpoint_start(ep); | ||
229 | if (err < 0) { | ||
230 | clear_bit(SUBSTREAM_FLAG_DATA_EP_STARTED, &subs->flags); | ||
231 | return err; | ||
232 | } | ||
233 | } | ||
234 | |||
235 | if (subs->sync_endpoint && | ||
236 | !test_and_set_bit(SUBSTREAM_FLAG_SYNC_EP_STARTED, &subs->flags)) { | ||
237 | struct snd_usb_endpoint *ep = subs->sync_endpoint; | ||
238 | |||
239 | snd_printdd(KERN_DEBUG "Starting sync EP @%p\n", ep); | ||
240 | |||
241 | ep->sync_slave = subs->data_endpoint; | ||
242 | err = snd_usb_endpoint_start(ep); | ||
243 | if (err < 0) { | ||
244 | clear_bit(SUBSTREAM_FLAG_SYNC_EP_STARTED, &subs->flags); | ||
245 | return err; | ||
246 | } | ||
247 | } | ||
248 | |||
249 | return 0; | ||
250 | } | ||
251 | |||
252 | static void stop_endpoints(struct snd_usb_substream *subs, | ||
253 | int force, int can_sleep, int wait) | ||
254 | { | ||
255 | if (test_and_clear_bit(SUBSTREAM_FLAG_SYNC_EP_STARTED, &subs->flags)) | ||
256 | snd_usb_endpoint_stop(subs->sync_endpoint, | ||
257 | force, can_sleep, wait); | ||
258 | |||
259 | if (test_and_clear_bit(SUBSTREAM_FLAG_DATA_EP_STARTED, &subs->flags)) | ||
260 | snd_usb_endpoint_stop(subs->data_endpoint, | ||
261 | force, can_sleep, wait); | ||
262 | } | ||
263 | |||
264 | static int activate_endpoints(struct snd_usb_substream *subs) | ||
265 | { | ||
266 | if (subs->sync_endpoint) { | ||
267 | int ret; | ||
268 | |||
269 | ret = snd_usb_endpoint_activate(subs->sync_endpoint); | ||
270 | if (ret < 0) | ||
271 | return ret; | ||
272 | } | ||
273 | |||
274 | return snd_usb_endpoint_activate(subs->data_endpoint); | ||
275 | } | ||
276 | |||
277 | static int deactivate_endpoints(struct snd_usb_substream *subs) | ||
278 | { | ||
279 | int reta, retb; | ||
280 | |||
281 | reta = snd_usb_endpoint_deactivate(subs->sync_endpoint); | ||
282 | retb = snd_usb_endpoint_deactivate(subs->data_endpoint); | ||
283 | |||
284 | if (reta < 0) | ||
285 | return reta; | ||
286 | |||
287 | if (retb < 0) | ||
288 | return retb; | ||
289 | |||
290 | return 0; | ||
291 | } | ||
292 | |||
211 | /* | 293 | /* |
212 | * find a matching format and set up the interface | 294 | * find a matching format and set up the interface |
213 | */ | 295 | */ |
@@ -219,7 +301,7 @@ static int set_format(struct snd_usb_substream *subs, struct audioformat *fmt) | |||
219 | struct usb_interface *iface; | 301 | struct usb_interface *iface; |
220 | unsigned int ep, attr; | 302 | unsigned int ep, attr; |
221 | int is_playback = subs->direction == SNDRV_PCM_STREAM_PLAYBACK; | 303 | int is_playback = subs->direction == SNDRV_PCM_STREAM_PLAYBACK; |
222 | int err; | 304 | int err, implicit_fb = 0; |
223 | 305 | ||
224 | iface = usb_ifnum_to_if(dev, fmt->iface); | 306 | iface = usb_ifnum_to_if(dev, fmt->iface); |
225 | if (WARN_ON(!iface)) | 307 | if (WARN_ON(!iface)) |
@@ -232,40 +314,11 @@ static int set_format(struct snd_usb_substream *subs, struct audioformat *fmt) | |||
232 | if (fmt == subs->cur_audiofmt) | 314 | if (fmt == subs->cur_audiofmt) |
233 | return 0; | 315 | return 0; |
234 | 316 | ||
235 | /* close the old interface */ | 317 | subs->data_endpoint = snd_usb_add_endpoint(subs->stream->chip, |
236 | if (subs->interface >= 0 && subs->interface != fmt->iface) { | 318 | alts, fmt->endpoint, subs->direction, |
237 | if (usb_set_interface(subs->dev, subs->interface, 0) < 0) { | 319 | SND_USB_ENDPOINT_TYPE_DATA); |
238 | snd_printk(KERN_ERR "%d:%d:%d: return to setting 0 failed\n", | 320 | if (!subs->data_endpoint) |
239 | dev->devnum, fmt->iface, fmt->altsetting); | 321 | return -EINVAL; |
240 | return -EIO; | ||
241 | } | ||
242 | subs->interface = -1; | ||
243 | subs->altset_idx = 0; | ||
244 | } | ||
245 | |||
246 | /* set interface */ | ||
247 | if (subs->interface != fmt->iface || subs->altset_idx != fmt->altset_idx) { | ||
248 | if (usb_set_interface(dev, fmt->iface, fmt->altsetting) < 0) { | ||
249 | snd_printk(KERN_ERR "%d:%d:%d: usb_set_interface failed\n", | ||
250 | dev->devnum, fmt->iface, fmt->altsetting); | ||
251 | return -EIO; | ||
252 | } | ||
253 | snd_printdd(KERN_INFO "setting usb interface %d:%d\n", fmt->iface, fmt->altsetting); | ||
254 | subs->interface = fmt->iface; | ||
255 | subs->altset_idx = fmt->altset_idx; | ||
256 | } | ||
257 | |||
258 | /* create a data pipe */ | ||
259 | ep = fmt->endpoint & USB_ENDPOINT_NUMBER_MASK; | ||
260 | if (is_playback) | ||
261 | subs->datapipe = usb_sndisocpipe(dev, ep); | ||
262 | else | ||
263 | subs->datapipe = usb_rcvisocpipe(dev, ep); | ||
264 | subs->datainterval = fmt->datainterval; | ||
265 | subs->syncpipe = subs->syncinterval = 0; | ||
266 | subs->maxpacksize = fmt->maxpacksize; | ||
267 | subs->syncmaxsize = 0; | ||
268 | subs->fill_max = 0; | ||
269 | 322 | ||
270 | /* we need a sync pipe in async OUT or adaptive IN mode */ | 323 | /* we need a sync pipe in async OUT or adaptive IN mode */ |
271 | /* check the number of EP, since some devices have broken | 324 | /* check the number of EP, since some devices have broken |
@@ -273,8 +326,25 @@ static int set_format(struct snd_usb_substream *subs, struct audioformat *fmt) | |||
273 | * assume it as adaptive-out or sync-in. | 326 | * assume it as adaptive-out or sync-in. |
274 | */ | 327 | */ |
275 | attr = fmt->ep_attr & USB_ENDPOINT_SYNCTYPE; | 328 | attr = fmt->ep_attr & USB_ENDPOINT_SYNCTYPE; |
329 | |||
330 | switch (subs->stream->chip->usb_id) { | ||
331 | case USB_ID(0x0763, 0x2080): /* M-Audio FastTrack Ultra */ | ||
332 | case USB_ID(0x0763, 0x2081): | ||
333 | if (is_playback) { | ||
334 | implicit_fb = 1; | ||
335 | ep = 0x81; | ||
336 | iface = usb_ifnum_to_if(dev, 2); | ||
337 | |||
338 | if (!iface || iface->num_altsetting == 0) | ||
339 | return -EINVAL; | ||
340 | |||
341 | alts = &iface->altsetting[1]; | ||
342 | goto add_sync_ep; | ||
343 | } | ||
344 | } | ||
345 | |||
276 | if (((is_playback && attr == USB_ENDPOINT_SYNC_ASYNC) || | 346 | if (((is_playback && attr == USB_ENDPOINT_SYNC_ASYNC) || |
277 | (! is_playback && attr == USB_ENDPOINT_SYNC_ADAPTIVE)) && | 347 | (!is_playback && attr == USB_ENDPOINT_SYNC_ADAPTIVE)) && |
278 | altsd->bNumEndpoints >= 2) { | 348 | altsd->bNumEndpoints >= 2) { |
279 | /* check sync-pipe endpoint */ | 349 | /* check sync-pipe endpoint */ |
280 | /* ... and check descriptor size before accessing bSynchAddress | 350 | /* ... and check descriptor size before accessing bSynchAddress |
@@ -282,7 +352,8 @@ static int set_format(struct snd_usb_substream *subs, struct audioformat *fmt) | |||
282 | the audio fields in the endpoint descriptors */ | 352 | the audio fields in the endpoint descriptors */ |
283 | if ((get_endpoint(alts, 1)->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) != 0x01 || | 353 | if ((get_endpoint(alts, 1)->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) != 0x01 || |
284 | (get_endpoint(alts, 1)->bLength >= USB_DT_ENDPOINT_AUDIO_SIZE && | 354 | (get_endpoint(alts, 1)->bLength >= USB_DT_ENDPOINT_AUDIO_SIZE && |
285 | get_endpoint(alts, 1)->bSynchAddress != 0)) { | 355 | get_endpoint(alts, 1)->bSynchAddress != 0 && |
356 | !implicit_fb)) { | ||
286 | snd_printk(KERN_ERR "%d:%d:%d : invalid synch pipe\n", | 357 | snd_printk(KERN_ERR "%d:%d:%d : invalid synch pipe\n", |
287 | dev->devnum, fmt->iface, fmt->altsetting); | 358 | dev->devnum, fmt->iface, fmt->altsetting); |
288 | return -EINVAL; | 359 | return -EINVAL; |
@@ -290,33 +361,27 @@ static int set_format(struct snd_usb_substream *subs, struct audioformat *fmt) | |||
290 | ep = get_endpoint(alts, 1)->bEndpointAddress; | 361 | ep = get_endpoint(alts, 1)->bEndpointAddress; |
291 | if (get_endpoint(alts, 0)->bLength >= USB_DT_ENDPOINT_AUDIO_SIZE && | 362 | if (get_endpoint(alts, 0)->bLength >= USB_DT_ENDPOINT_AUDIO_SIZE && |
292 | (( is_playback && ep != (unsigned int)(get_endpoint(alts, 0)->bSynchAddress | USB_DIR_IN)) || | 363 | (( is_playback && ep != (unsigned int)(get_endpoint(alts, 0)->bSynchAddress | USB_DIR_IN)) || |
293 | (!is_playback && ep != (unsigned int)(get_endpoint(alts, 0)->bSynchAddress & ~USB_DIR_IN)))) { | 364 | (!is_playback && ep != (unsigned int)(get_endpoint(alts, 0)->bSynchAddress & ~USB_DIR_IN)) || |
365 | ( is_playback && !implicit_fb))) { | ||
294 | snd_printk(KERN_ERR "%d:%d:%d : invalid synch pipe\n", | 366 | snd_printk(KERN_ERR "%d:%d:%d : invalid synch pipe\n", |
295 | dev->devnum, fmt->iface, fmt->altsetting); | 367 | dev->devnum, fmt->iface, fmt->altsetting); |
296 | return -EINVAL; | 368 | return -EINVAL; |
297 | } | 369 | } |
298 | ep &= USB_ENDPOINT_NUMBER_MASK; | 370 | |
299 | if (is_playback) | 371 | implicit_fb = (get_endpoint(alts, 1)->bmAttributes & USB_ENDPOINT_USAGE_MASK) |
300 | subs->syncpipe = usb_rcvisocpipe(dev, ep); | 372 | == USB_ENDPOINT_USAGE_IMPLICIT_FB; |
301 | else | 373 | |
302 | subs->syncpipe = usb_sndisocpipe(dev, ep); | 374 | add_sync_ep: |
303 | if (get_endpoint(alts, 1)->bLength >= USB_DT_ENDPOINT_AUDIO_SIZE && | 375 | subs->sync_endpoint = snd_usb_add_endpoint(subs->stream->chip, |
304 | get_endpoint(alts, 1)->bRefresh >= 1 && | 376 | alts, ep, !subs->direction, |
305 | get_endpoint(alts, 1)->bRefresh <= 9) | 377 | implicit_fb ? |
306 | subs->syncinterval = get_endpoint(alts, 1)->bRefresh; | 378 | SND_USB_ENDPOINT_TYPE_DATA : |
307 | else if (snd_usb_get_speed(subs->dev) == USB_SPEED_FULL) | 379 | SND_USB_ENDPOINT_TYPE_SYNC); |
308 | subs->syncinterval = 1; | 380 | if (!subs->sync_endpoint) |
309 | else if (get_endpoint(alts, 1)->bInterval >= 1 && | 381 | return -EINVAL; |
310 | get_endpoint(alts, 1)->bInterval <= 16) | 382 | |
311 | subs->syncinterval = get_endpoint(alts, 1)->bInterval - 1; | 383 | subs->data_endpoint->sync_master = subs->sync_endpoint; |
312 | else | 384 | } |
313 | subs->syncinterval = 3; | ||
314 | subs->syncmaxsize = le16_to_cpu(get_endpoint(alts, 1)->wMaxPacketSize); | ||
315 | } | ||
316 | |||
317 | /* always fill max packet size */ | ||
318 | if (fmt->attributes & UAC_EP_CS_ATTR_FILL_MAX) | ||
319 | subs->fill_max = 1; | ||
320 | 385 | ||
321 | if ((err = snd_usb_init_pitch(subs->stream->chip, subs->interface, alts, fmt)) < 0) | 386 | if ((err = snd_usb_init_pitch(subs->stream->chip, subs->interface, alts, fmt)) < 0) |
322 | return err; | 387 | return err; |
@@ -390,15 +455,30 @@ static int snd_usb_hw_params(struct snd_pcm_substream *substream, | |||
390 | if (changed) { | 455 | if (changed) { |
391 | mutex_lock(&subs->stream->chip->shutdown_mutex); | 456 | mutex_lock(&subs->stream->chip->shutdown_mutex); |
392 | /* format changed */ | 457 | /* format changed */ |
393 | snd_usb_release_substream_urbs(subs, 0); | 458 | stop_endpoints(subs, 0, 0, 0); |
394 | /* influenced: period_bytes, channels, rate, format, */ | 459 | deactivate_endpoints(subs); |
395 | ret = snd_usb_init_substream_urbs(subs, params_period_bytes(hw_params), | 460 | |
396 | params_rate(hw_params), | 461 | ret = activate_endpoints(subs); |
397 | snd_pcm_format_physical_width(params_format(hw_params)) * | 462 | if (ret < 0) |
398 | params_channels(hw_params)); | 463 | goto unlock; |
464 | |||
465 | ret = snd_usb_endpoint_set_params(subs->data_endpoint, hw_params, fmt, | ||
466 | subs->sync_endpoint); | ||
467 | if (ret < 0) | ||
468 | goto unlock; | ||
469 | |||
470 | if (subs->sync_endpoint) | ||
471 | ret = snd_usb_endpoint_set_params(subs->sync_endpoint, | ||
472 | hw_params, fmt, NULL); | ||
473 | unlock: | ||
399 | mutex_unlock(&subs->stream->chip->shutdown_mutex); | 474 | mutex_unlock(&subs->stream->chip->shutdown_mutex); |
400 | } | 475 | } |
401 | 476 | ||
477 | if (ret == 0) { | ||
478 | subs->interface = fmt->iface; | ||
479 | subs->altset_idx = fmt->altset_idx; | ||
480 | } | ||
481 | |||
402 | return ret; | 482 | return ret; |
403 | } | 483 | } |
404 | 484 | ||
@@ -415,7 +495,7 @@ static int snd_usb_hw_free(struct snd_pcm_substream *substream) | |||
415 | subs->cur_rate = 0; | 495 | subs->cur_rate = 0; |
416 | subs->period_bytes = 0; | 496 | subs->period_bytes = 0; |
417 | mutex_lock(&subs->stream->chip->shutdown_mutex); | 497 | mutex_lock(&subs->stream->chip->shutdown_mutex); |
418 | snd_usb_release_substream_urbs(subs, 0); | 498 | stop_endpoints(subs, 0, 1, 1); |
419 | mutex_unlock(&subs->stream->chip->shutdown_mutex); | 499 | mutex_unlock(&subs->stream->chip->shutdown_mutex); |
420 | return snd_pcm_lib_free_vmalloc_buffer(substream); | 500 | return snd_pcm_lib_free_vmalloc_buffer(substream); |
421 | } | 501 | } |
@@ -435,19 +515,28 @@ static int snd_usb_pcm_prepare(struct snd_pcm_substream *substream) | |||
435 | return -ENXIO; | 515 | return -ENXIO; |
436 | } | 516 | } |
437 | 517 | ||
518 | if (snd_BUG_ON(!subs->data_endpoint)) | ||
519 | return -EIO; | ||
520 | |||
438 | /* some unit conversions in runtime */ | 521 | /* some unit conversions in runtime */ |
439 | subs->maxframesize = bytes_to_frames(runtime, subs->maxpacksize); | 522 | subs->data_endpoint->maxframesize = |
440 | subs->curframesize = bytes_to_frames(runtime, subs->curpacksize); | 523 | bytes_to_frames(runtime, subs->data_endpoint->maxpacksize); |
524 | subs->data_endpoint->curframesize = | ||
525 | bytes_to_frames(runtime, subs->data_endpoint->curpacksize); | ||
441 | 526 | ||
442 | /* reset the pointer */ | 527 | /* reset the pointer */ |
443 | subs->hwptr_done = 0; | 528 | subs->hwptr_done = 0; |
444 | subs->transfer_done = 0; | 529 | subs->transfer_done = 0; |
445 | subs->phase = 0; | ||
446 | subs->last_delay = 0; | 530 | subs->last_delay = 0; |
447 | subs->last_frame_number = 0; | 531 | subs->last_frame_number = 0; |
448 | runtime->delay = 0; | 532 | runtime->delay = 0; |
449 | 533 | ||
450 | return snd_usb_substream_prepare(subs, runtime); | 534 | /* for playback, submit the URBs now; otherwise, the first hwptr_done |
535 | * updates for all URBs would happen at the same time when starting */ | ||
536 | if (subs->direction == SNDRV_PCM_STREAM_PLAYBACK) | ||
537 | return start_endpoints(subs); | ||
538 | |||
539 | return 0; | ||
451 | } | 540 | } |
452 | 541 | ||
453 | static struct snd_pcm_hardware snd_usb_hardware = | 542 | static struct snd_pcm_hardware snd_usb_hardware = |
@@ -842,16 +931,171 @@ static int snd_usb_pcm_open(struct snd_pcm_substream *substream, int direction) | |||
842 | 931 | ||
843 | static int snd_usb_pcm_close(struct snd_pcm_substream *substream, int direction) | 932 | static int snd_usb_pcm_close(struct snd_pcm_substream *substream, int direction) |
844 | { | 933 | { |
934 | int ret; | ||
845 | struct snd_usb_stream *as = snd_pcm_substream_chip(substream); | 935 | struct snd_usb_stream *as = snd_pcm_substream_chip(substream); |
846 | struct snd_usb_substream *subs = &as->substream[direction]; | 936 | struct snd_usb_substream *subs = &as->substream[direction]; |
847 | 937 | ||
848 | if (!as->chip->shutdown && subs->interface >= 0) { | 938 | stop_endpoints(subs, 0, 0, 0); |
849 | usb_set_interface(subs->dev, subs->interface, 0); | 939 | ret = deactivate_endpoints(subs); |
850 | subs->interface = -1; | ||
851 | } | ||
852 | subs->pcm_substream = NULL; | 940 | subs->pcm_substream = NULL; |
853 | snd_usb_autosuspend(subs->stream->chip); | 941 | snd_usb_autosuspend(subs->stream->chip); |
854 | return 0; | 942 | |
943 | return ret; | ||
944 | } | ||
945 | |||
946 | /* Since a URB can handle only a single linear buffer, we must use double | ||
947 | * buffering when the data to be transferred overflows the buffer boundary. | ||
948 | * To avoid inconsistencies when updating hwptr_done, we use double buffering | ||
949 | * for all URBs. | ||
950 | */ | ||
951 | static void retire_capture_urb(struct snd_usb_substream *subs, | ||
952 | struct urb *urb) | ||
953 | { | ||
954 | struct snd_pcm_runtime *runtime = subs->pcm_substream->runtime; | ||
955 | unsigned int stride, frames, bytes, oldptr; | ||
956 | int i, period_elapsed = 0; | ||
957 | unsigned long flags; | ||
958 | unsigned char *cp; | ||
959 | |||
960 | stride = runtime->frame_bits >> 3; | ||
961 | |||
962 | for (i = 0; i < urb->number_of_packets; i++) { | ||
963 | cp = (unsigned char *)urb->transfer_buffer + urb->iso_frame_desc[i].offset; | ||
964 | if (urb->iso_frame_desc[i].status && printk_ratelimit()) { | ||
965 | snd_printdd(KERN_ERR "frame %d active: %d\n", i, urb->iso_frame_desc[i].status); | ||
966 | // continue; | ||
967 | } | ||
968 | bytes = urb->iso_frame_desc[i].actual_length; | ||
969 | frames = bytes / stride; | ||
970 | if (!subs->txfr_quirk) | ||
971 | bytes = frames * stride; | ||
972 | if (bytes % (runtime->sample_bits >> 3) != 0) { | ||
973 | #ifdef CONFIG_SND_DEBUG_VERBOSE | ||
974 | int oldbytes = bytes; | ||
975 | #endif | ||
976 | bytes = frames * stride; | ||
977 | snd_printdd(KERN_ERR "Corrected urb data len. %d->%d\n", | ||
978 | oldbytes, bytes); | ||
979 | } | ||
980 | /* update the current pointer */ | ||
981 | spin_lock_irqsave(&subs->lock, flags); | ||
982 | oldptr = subs->hwptr_done; | ||
983 | subs->hwptr_done += bytes; | ||
984 | if (subs->hwptr_done >= runtime->buffer_size * stride) | ||
985 | subs->hwptr_done -= runtime->buffer_size * stride; | ||
986 | frames = (bytes + (oldptr % stride)) / stride; | ||
987 | subs->transfer_done += frames; | ||
988 | if (subs->transfer_done >= runtime->period_size) { | ||
989 | subs->transfer_done -= runtime->period_size; | ||
990 | period_elapsed = 1; | ||
991 | } | ||
992 | spin_unlock_irqrestore(&subs->lock, flags); | ||
993 | /* copy a data chunk */ | ||
994 | if (oldptr + bytes > runtime->buffer_size * stride) { | ||
995 | unsigned int bytes1 = | ||
996 | runtime->buffer_size * stride - oldptr; | ||
997 | memcpy(runtime->dma_area + oldptr, cp, bytes1); | ||
998 | memcpy(runtime->dma_area, cp + bytes1, bytes - bytes1); | ||
999 | } else { | ||
1000 | memcpy(runtime->dma_area + oldptr, cp, bytes); | ||
1001 | } | ||
1002 | } | ||
1003 | |||
1004 | if (period_elapsed) | ||
1005 | snd_pcm_period_elapsed(subs->pcm_substream); | ||
1006 | } | ||
1007 | |||
1008 | static void prepare_playback_urb(struct snd_usb_substream *subs, | ||
1009 | struct urb *urb) | ||
1010 | { | ||
1011 | struct snd_pcm_runtime *runtime = subs->pcm_substream->runtime; | ||
1012 | struct snd_urb_ctx *ctx = urb->context; | ||
1013 | unsigned int counts, frames, bytes; | ||
1014 | int i, stride, period_elapsed = 0; | ||
1015 | unsigned long flags; | ||
1016 | |||
1017 | stride = runtime->frame_bits >> 3; | ||
1018 | |||
1019 | frames = 0; | ||
1020 | urb->number_of_packets = 0; | ||
1021 | spin_lock_irqsave(&subs->lock, flags); | ||
1022 | for (i = 0; i < ctx->packets; i++) { | ||
1023 | counts = ctx->packet_size[i]; | ||
1024 | /* set up descriptor */ | ||
1025 | urb->iso_frame_desc[i].offset = frames * stride; | ||
1026 | urb->iso_frame_desc[i].length = counts * stride; | ||
1027 | frames += counts; | ||
1028 | urb->number_of_packets++; | ||
1029 | subs->transfer_done += counts; | ||
1030 | if (subs->transfer_done >= runtime->period_size) { | ||
1031 | subs->transfer_done -= runtime->period_size; | ||
1032 | period_elapsed = 1; | ||
1033 | if (subs->fmt_type == UAC_FORMAT_TYPE_II) { | ||
1034 | if (subs->transfer_done > 0) { | ||
1035 | /* FIXME: fill-max mode is not | ||
1036 | * supported yet */ | ||
1037 | frames -= subs->transfer_done; | ||
1038 | counts -= subs->transfer_done; | ||
1039 | urb->iso_frame_desc[i].length = | ||
1040 | counts * stride; | ||
1041 | subs->transfer_done = 0; | ||
1042 | } | ||
1043 | i++; | ||
1044 | if (i < ctx->packets) { | ||
1045 | /* add a transfer delimiter */ | ||
1046 | urb->iso_frame_desc[i].offset = | ||
1047 | frames * stride; | ||
1048 | urb->iso_frame_desc[i].length = 0; | ||
1049 | urb->number_of_packets++; | ||
1050 | } | ||
1051 | break; | ||
1052 | } | ||
1053 | } | ||
1054 | if (period_elapsed && | ||
1055 | !snd_usb_endpoint_implict_feedback_sink(subs->data_endpoint)) /* finish at the period boundary */ | ||
1056 | break; | ||
1057 | } | ||
1058 | bytes = frames * stride; | ||
1059 | if (subs->hwptr_done + bytes > runtime->buffer_size * stride) { | ||
1060 | /* err, the transferred area goes over buffer boundary. */ | ||
1061 | unsigned int bytes1 = | ||
1062 | runtime->buffer_size * stride - subs->hwptr_done; | ||
1063 | memcpy(urb->transfer_buffer, | ||
1064 | runtime->dma_area + subs->hwptr_done, bytes1); | ||
1065 | memcpy(urb->transfer_buffer + bytes1, | ||
1066 | runtime->dma_area, bytes - bytes1); | ||
1067 | } else { | ||
1068 | memcpy(urb->transfer_buffer, | ||
1069 | runtime->dma_area + subs->hwptr_done, bytes); | ||
1070 | } | ||
1071 | subs->hwptr_done += bytes; | ||
1072 | if (subs->hwptr_done >= runtime->buffer_size * stride) | ||
1073 | subs->hwptr_done -= runtime->buffer_size * stride; | ||
1074 | runtime->delay += frames; | ||
1075 | spin_unlock_irqrestore(&subs->lock, flags); | ||
1076 | urb->transfer_buffer_length = bytes; | ||
1077 | if (period_elapsed) | ||
1078 | snd_pcm_period_elapsed(subs->pcm_substream); | ||
1079 | } | ||
1080 | |||
1081 | /* | ||
1082 | * process after playback data complete | ||
1083 | * - decrease the delay count again | ||
1084 | */ | ||
1085 | static void retire_playback_urb(struct snd_usb_substream *subs, | ||
1086 | struct urb *urb) | ||
1087 | { | ||
1088 | unsigned long flags; | ||
1089 | struct snd_pcm_runtime *runtime = subs->pcm_substream->runtime; | ||
1090 | int stride = runtime->frame_bits >> 3; | ||
1091 | int processed = urb->transfer_buffer_length / stride; | ||
1092 | |||
1093 | spin_lock_irqsave(&subs->lock, flags); | ||
1094 | if (processed > runtime->delay) | ||
1095 | runtime->delay = 0; | ||
1096 | else | ||
1097 | runtime->delay -= processed; | ||
1098 | spin_unlock_irqrestore(&subs->lock, flags); | ||
855 | } | 1099 | } |
856 | 1100 | ||
857 | static int snd_usb_playback_open(struct snd_pcm_substream *substream) | 1101 | static int snd_usb_playback_open(struct snd_pcm_substream *substream) |
@@ -874,6 +1118,63 @@ static int snd_usb_capture_close(struct snd_pcm_substream *substream) | |||
874 | return snd_usb_pcm_close(substream, SNDRV_PCM_STREAM_CAPTURE); | 1118 | return snd_usb_pcm_close(substream, SNDRV_PCM_STREAM_CAPTURE); |
875 | } | 1119 | } |
876 | 1120 | ||
1121 | static int snd_usb_substream_playback_trigger(struct snd_pcm_substream *substream, | ||
1122 | int cmd) | ||
1123 | { | ||
1124 | struct snd_usb_substream *subs = substream->runtime->private_data; | ||
1125 | |||
1126 | switch (cmd) { | ||
1127 | case SNDRV_PCM_TRIGGER_START: | ||
1128 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: | ||
1129 | subs->data_endpoint->prepare_data_urb = prepare_playback_urb; | ||
1130 | subs->data_endpoint->retire_data_urb = retire_playback_urb; | ||
1131 | subs->running = 1; | ||
1132 | return 0; | ||
1133 | case SNDRV_PCM_TRIGGER_STOP: | ||
1134 | stop_endpoints(subs, 0, 0, 0); | ||
1135 | subs->running = 0; | ||
1136 | return 0; | ||
1137 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: | ||
1138 | subs->data_endpoint->prepare_data_urb = NULL; | ||
1139 | subs->data_endpoint->retire_data_urb = NULL; | ||
1140 | subs->running = 0; | ||
1141 | return 0; | ||
1142 | } | ||
1143 | |||
1144 | return -EINVAL; | ||
1145 | } | ||
1146 | |||
1147 | int snd_usb_substream_capture_trigger(struct snd_pcm_substream *substream, int cmd) | ||
1148 | { | ||
1149 | int err; | ||
1150 | struct snd_usb_substream *subs = substream->runtime->private_data; | ||
1151 | |||
1152 | switch (cmd) { | ||
1153 | case SNDRV_PCM_TRIGGER_START: | ||
1154 | err = start_endpoints(subs); | ||
1155 | if (err < 0) | ||
1156 | return err; | ||
1157 | |||
1158 | subs->data_endpoint->retire_data_urb = retire_capture_urb; | ||
1159 | subs->running = 1; | ||
1160 | return 0; | ||
1161 | case SNDRV_PCM_TRIGGER_STOP: | ||
1162 | stop_endpoints(subs, 0, 0, 0); | ||
1163 | subs->running = 0; | ||
1164 | return 0; | ||
1165 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: | ||
1166 | subs->data_endpoint->retire_data_urb = NULL; | ||
1167 | subs->running = 0; | ||
1168 | return 0; | ||
1169 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: | ||
1170 | subs->data_endpoint->retire_data_urb = retire_capture_urb; | ||
1171 | subs->running = 1; | ||
1172 | return 0; | ||
1173 | } | ||
1174 | |||
1175 | return -EINVAL; | ||
1176 | } | ||
1177 | |||
877 | static struct snd_pcm_ops snd_usb_playback_ops = { | 1178 | static struct snd_pcm_ops snd_usb_playback_ops = { |
878 | .open = snd_usb_playback_open, | 1179 | .open = snd_usb_playback_open, |
879 | .close = snd_usb_playback_close, | 1180 | .close = snd_usb_playback_close, |
diff --git a/sound/usb/proc.c b/sound/usb/proc.c index 961c9a250686..ebc1a5b5b3f1 100644 --- a/sound/usb/proc.c +++ b/sound/usb/proc.c | |||
@@ -25,6 +25,7 @@ | |||
25 | #include "usbaudio.h" | 25 | #include "usbaudio.h" |
26 | #include "helper.h" | 26 | #include "helper.h" |
27 | #include "card.h" | 27 | #include "card.h" |
28 | #include "endpoint.h" | ||
28 | #include "proc.h" | 29 | #include "proc.h" |
29 | 30 | ||
30 | /* convert our full speed USB rate into sampling rate in Hz */ | 31 | /* convert our full speed USB rate into sampling rate in Hz */ |
@@ -115,28 +116,33 @@ static void proc_dump_substream_formats(struct snd_usb_substream *subs, struct s | |||
115 | } | 116 | } |
116 | } | 117 | } |
117 | 118 | ||
119 | static void proc_dump_ep_status(struct snd_usb_substream *subs, | ||
120 | struct snd_usb_endpoint *ep, | ||
121 | struct snd_info_buffer *buffer) | ||
122 | { | ||
123 | if (!ep) | ||
124 | return; | ||
125 | snd_iprintf(buffer, " Packet Size = %d\n", ep->curpacksize); | ||
126 | snd_iprintf(buffer, " Momentary freq = %u Hz (%#x.%04x)\n", | ||
127 | snd_usb_get_speed(subs->dev) == USB_SPEED_FULL | ||
128 | ? get_full_speed_hz(ep->freqm) | ||
129 | : get_high_speed_hz(ep->freqm), | ||
130 | ep->freqm >> 16, ep->freqm & 0xffff); | ||
131 | if (ep->freqshift != INT_MIN) { | ||
132 | int res = 16 - ep->freqshift; | ||
133 | snd_iprintf(buffer, " Feedback Format = %d.%d\n", | ||
134 | (ep->syncmaxsize > 3 ? 32 : 24) - res, res); | ||
135 | } | ||
136 | } | ||
137 | |||
118 | static void proc_dump_substream_status(struct snd_usb_substream *subs, struct snd_info_buffer *buffer) | 138 | static void proc_dump_substream_status(struct snd_usb_substream *subs, struct snd_info_buffer *buffer) |
119 | { | 139 | { |
120 | if (subs->running) { | 140 | if (subs->running) { |
121 | unsigned int i; | ||
122 | snd_iprintf(buffer, " Status: Running\n"); | 141 | snd_iprintf(buffer, " Status: Running\n"); |
123 | snd_iprintf(buffer, " Interface = %d\n", subs->interface); | 142 | snd_iprintf(buffer, " Interface = %d\n", subs->interface); |
124 | snd_iprintf(buffer, " Altset = %d\n", subs->altset_idx); | 143 | snd_iprintf(buffer, " Altset = %d\n", subs->altset_idx); |
125 | snd_iprintf(buffer, " URBs = %d [ ", subs->nurbs); | 144 | proc_dump_ep_status(subs, subs->data_endpoint, buffer); |
126 | for (i = 0; i < subs->nurbs; i++) | 145 | proc_dump_ep_status(subs, subs->sync_endpoint, buffer); |
127 | snd_iprintf(buffer, "%d ", subs->dataurb[i].packets); | ||
128 | snd_iprintf(buffer, "]\n"); | ||
129 | snd_iprintf(buffer, " Packet Size = %d\n", subs->curpacksize); | ||
130 | snd_iprintf(buffer, " Momentary freq = %u Hz (%#x.%04x)\n", | ||
131 | snd_usb_get_speed(subs->dev) == USB_SPEED_FULL | ||
132 | ? get_full_speed_hz(subs->freqm) | ||
133 | : get_high_speed_hz(subs->freqm), | ||
134 | subs->freqm >> 16, subs->freqm & 0xffff); | ||
135 | if (subs->freqshift != INT_MIN) | ||
136 | snd_iprintf(buffer, " Feedback Format = %d.%d\n", | ||
137 | (subs->syncmaxsize > 3 ? 32 : 24) | ||
138 | - (16 - subs->freqshift), | ||
139 | 16 - subs->freqshift); | ||
140 | } else { | 146 | } else { |
141 | snd_iprintf(buffer, " Status: Stop\n"); | 147 | snd_iprintf(buffer, " Status: Stop\n"); |
142 | } | 148 | } |
diff --git a/sound/usb/stream.c b/sound/usb/stream.c index 5ff8010b2d6f..6b7d7a2b7baa 100644 --- a/sound/usb/stream.c +++ b/sound/usb/stream.c | |||
@@ -73,6 +73,31 @@ static void snd_usb_audio_pcm_free(struct snd_pcm *pcm) | |||
73 | } | 73 | } |
74 | } | 74 | } |
75 | 75 | ||
76 | /* | ||
77 | * initialize the substream instance. | ||
78 | */ | ||
79 | |||
80 | static void snd_usb_init_substream(struct snd_usb_stream *as, | ||
81 | int stream, | ||
82 | struct audioformat *fp) | ||
83 | { | ||
84 | struct snd_usb_substream *subs = &as->substream[stream]; | ||
85 | |||
86 | INIT_LIST_HEAD(&subs->fmt_list); | ||
87 | spin_lock_init(&subs->lock); | ||
88 | |||
89 | subs->stream = as; | ||
90 | subs->direction = stream; | ||
91 | subs->dev = as->chip->dev; | ||
92 | subs->txfr_quirk = as->chip->txfr_quirk; | ||
93 | |||
94 | snd_usb_set_pcm_ops(as->pcm, stream); | ||
95 | |||
96 | list_add_tail(&fp->list, &subs->fmt_list); | ||
97 | subs->formats |= fp->formats; | ||
98 | subs->num_formats++; | ||
99 | subs->fmt_type = fp->fmt_type; | ||
100 | } | ||
76 | 101 | ||
77 | /* | 102 | /* |
78 | * add this endpoint to the chip instance. | 103 | * add this endpoint to the chip instance. |
@@ -94,9 +119,9 @@ int snd_usb_add_audio_stream(struct snd_usb_audio *chip, | |||
94 | if (as->fmt_type != fp->fmt_type) | 119 | if (as->fmt_type != fp->fmt_type) |
95 | continue; | 120 | continue; |
96 | subs = &as->substream[stream]; | 121 | subs = &as->substream[stream]; |
97 | if (!subs->endpoint) | 122 | if (!subs->data_endpoint) |
98 | continue; | 123 | continue; |
99 | if (subs->endpoint == fp->endpoint) { | 124 | if (subs->data_endpoint->ep_num == fp->endpoint) { |
100 | list_add_tail(&fp->list, &subs->fmt_list); | 125 | list_add_tail(&fp->list, &subs->fmt_list); |
101 | subs->num_formats++; | 126 | subs->num_formats++; |
102 | subs->formats |= fp->formats; | 127 | subs->formats |= fp->formats; |
@@ -109,7 +134,7 @@ int snd_usb_add_audio_stream(struct snd_usb_audio *chip, | |||
109 | if (as->fmt_type != fp->fmt_type) | 134 | if (as->fmt_type != fp->fmt_type) |
110 | continue; | 135 | continue; |
111 | subs = &as->substream[stream]; | 136 | subs = &as->substream[stream]; |
112 | if (subs->endpoint) | 137 | if (subs->data_endpoint) |
113 | continue; | 138 | continue; |
114 | err = snd_pcm_new_stream(as->pcm, stream, 1); | 139 | err = snd_pcm_new_stream(as->pcm, stream, 1); |
115 | if (err < 0) | 140 | if (err < 0) |
diff --git a/sound/usb/usbaudio.h b/sound/usb/usbaudio.h index 3e2b03577936..b8233ebe250f 100644 --- a/sound/usb/usbaudio.h +++ b/sound/usb/usbaudio.h | |||
@@ -36,6 +36,7 @@ struct snd_usb_audio { | |||
36 | struct snd_card *card; | 36 | struct snd_card *card; |
37 | struct usb_interface *pm_intf; | 37 | struct usb_interface *pm_intf; |
38 | u32 usb_id; | 38 | u32 usb_id; |
39 | struct mutex mutex; | ||
39 | struct mutex shutdown_mutex; | 40 | struct mutex shutdown_mutex; |
40 | unsigned int shutdown:1; | 41 | unsigned int shutdown:1; |
41 | unsigned int probing:1; | 42 | unsigned int probing:1; |
@@ -46,6 +47,7 @@ struct snd_usb_audio { | |||
46 | int num_suspended_intf; | 47 | int num_suspended_intf; |
47 | 48 | ||
48 | struct list_head pcm_list; /* list of pcm streams */ | 49 | struct list_head pcm_list; /* list of pcm streams */ |
50 | struct list_head ep_list; /* list of audio-related endpoints */ | ||
49 | int pcm_devs; | 51 | int pcm_devs; |
50 | 52 | ||
51 | struct list_head midi_list; /* list of midi interfaces */ | 53 | struct list_head midi_list; /* list of midi interfaces */ |