2 * Intel SST Haswell/Broadwell PCM Support
4 * Copyright (C) 2013, Intel Corporation. All rights reserved.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License version
8 * 2 as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
17 #include <linux/module.h>
18 #include <linux/dma-mapping.h>
19 #include <linux/slab.h>
20 #include <linux/module.h>
21 #include <linux/delay.h>
23 #include <asm/pgtable.h>
24 #include <sound/core.h>
25 #include <sound/pcm.h>
26 #include <sound/pcm_params.h>
27 #include <sound/dmaengine_pcm.h>
28 #include <sound/soc.h>
29 #include <sound/tlv.h>
30 #include <sound/compress_driver.h>
32 #include "sst-haswell-ipc.h"
33 #include "sst-dsp-priv.h"
36 #define HSW_PCM_COUNT 6
37 #define HSW_VOLUME_MAX 0x7FFFFFFF /* 0dB */
39 /* simple volume table */
40 static const u32 volume_map[] = {
74 #define HSW_PCM_PERIODS_MAX 64
75 #define HSW_PCM_PERIODS_MIN 2
77 static const struct snd_pcm_hardware hsw_pcm_hardware = {
78 .info = SNDRV_PCM_INFO_MMAP |
79 SNDRV_PCM_INFO_MMAP_VALID |
80 SNDRV_PCM_INFO_INTERLEAVED |
81 SNDRV_PCM_INFO_PAUSE |
82 SNDRV_PCM_INFO_RESUME |
83 SNDRV_PCM_INFO_NO_PERIOD_WAKEUP,
84 .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FORMAT_S24_LE |
85 SNDRV_PCM_FMTBIT_S32_LE,
86 .period_bytes_min = PAGE_SIZE,
87 .period_bytes_max = (HSW_PCM_PERIODS_MAX / HSW_PCM_PERIODS_MIN) * PAGE_SIZE,
88 .periods_min = HSW_PCM_PERIODS_MIN,
89 .periods_max = HSW_PCM_PERIODS_MAX,
90 .buffer_bytes_max = HSW_PCM_PERIODS_MAX * PAGE_SIZE,
93 /* private data for each PCM DSP stream */
96 struct sst_hsw_stream *stream;
98 struct snd_pcm_substream *substream;
99 struct snd_compr_stream *cstream;
104 /* private data for the driver */
105 struct hsw_priv_data {
110 unsigned char *pcm_pg[HSW_PCM_COUNT][2];
113 struct hsw_pcm_data pcm[HSW_PCM_COUNT];
116 static inline u32 hsw_mixer_to_ipc(unsigned int value)
118 if (value >= ARRAY_SIZE(volume_map))
119 return volume_map[0];
121 return volume_map[value];
124 static inline unsigned int hsw_ipc_to_mixer(u32 value)
128 for (i = 0; i < ARRAY_SIZE(volume_map); i++) {
129 if (volume_map[i] >= value)
136 static int hsw_stream_volume_put(struct snd_kcontrol *kcontrol,
137 struct snd_ctl_elem_value *ucontrol)
139 struct snd_soc_platform *platform = snd_kcontrol_chip(kcontrol);
140 struct soc_mixer_control *mc =
141 (struct soc_mixer_control *)kcontrol->private_value;
142 struct hsw_priv_data *pdata =
143 snd_soc_platform_get_drvdata(platform);
144 struct hsw_pcm_data *pcm_data = &pdata->pcm[mc->reg];
145 struct sst_hsw *hsw = pdata->hsw;
148 mutex_lock(&pcm_data->mutex);
150 if (!pcm_data->stream) {
151 pcm_data->volume[0] =
152 hsw_mixer_to_ipc(ucontrol->value.integer.value[0]);
153 pcm_data->volume[1] =
154 hsw_mixer_to_ipc(ucontrol->value.integer.value[1]);
155 mutex_unlock(&pcm_data->mutex);
159 if (ucontrol->value.integer.value[0] ==
160 ucontrol->value.integer.value[1]) {
161 volume = hsw_mixer_to_ipc(ucontrol->value.integer.value[0]);
162 sst_hsw_stream_set_volume(hsw, pcm_data->stream, 0, 2, volume);
164 volume = hsw_mixer_to_ipc(ucontrol->value.integer.value[0]);
165 sst_hsw_stream_set_volume(hsw, pcm_data->stream, 0, 0, volume);
166 volume = hsw_mixer_to_ipc(ucontrol->value.integer.value[1]);
167 sst_hsw_stream_set_volume(hsw, pcm_data->stream, 0, 1, volume);
170 mutex_unlock(&pcm_data->mutex);
174 static int hsw_stream_volume_get(struct snd_kcontrol *kcontrol,
175 struct snd_ctl_elem_value *ucontrol)
177 struct snd_soc_platform *platform = snd_kcontrol_chip(kcontrol);
178 struct soc_mixer_control *mc =
179 (struct soc_mixer_control *)kcontrol->private_value;
180 struct hsw_priv_data *pdata =
181 snd_soc_platform_get_drvdata(platform);
182 struct hsw_pcm_data *pcm_data = &pdata->pcm[mc->reg];
183 struct sst_hsw *hsw = pdata->hsw;
186 mutex_lock(&pcm_data->mutex);
188 if (!pcm_data->stream) {
189 ucontrol->value.integer.value[0] =
190 hsw_ipc_to_mixer(pcm_data->volume[0]);
191 ucontrol->value.integer.value[1] =
192 hsw_ipc_to_mixer(pcm_data->volume[1]);
193 mutex_unlock(&pcm_data->mutex);
197 sst_hsw_stream_get_volume(hsw, pcm_data->stream, 0, 0, &volume);
198 ucontrol->value.integer.value[0] = hsw_ipc_to_mixer(volume);
199 sst_hsw_stream_get_volume(hsw, pcm_data->stream, 0, 1, &volume);
200 ucontrol->value.integer.value[1] = hsw_ipc_to_mixer(volume);
201 mutex_unlock(&pcm_data->mutex);
206 static int hsw_volume_put(struct snd_kcontrol *kcontrol,
207 struct snd_ctl_elem_value *ucontrol)
209 struct snd_soc_platform *platform = snd_kcontrol_chip(kcontrol);
210 struct hsw_priv_data *pdata = snd_soc_platform_get_drvdata(platform);
211 struct sst_hsw *hsw = pdata->hsw;
214 if (ucontrol->value.integer.value[0] ==
215 ucontrol->value.integer.value[1]) {
217 volume = hsw_mixer_to_ipc(ucontrol->value.integer.value[0]);
218 sst_hsw_mixer_set_volume(hsw, 0, 2, volume);
221 volume = hsw_mixer_to_ipc(ucontrol->value.integer.value[0]);
222 sst_hsw_mixer_set_volume(hsw, 0, 0, volume);
224 volume = hsw_mixer_to_ipc(ucontrol->value.integer.value[1]);
225 sst_hsw_mixer_set_volume(hsw, 0, 1, volume);
231 static int hsw_volume_get(struct snd_kcontrol *kcontrol,
232 struct snd_ctl_elem_value *ucontrol)
234 struct snd_soc_platform *platform = snd_kcontrol_chip(kcontrol);
235 struct hsw_priv_data *pdata = snd_soc_platform_get_drvdata(platform);
236 struct sst_hsw *hsw = pdata->hsw;
237 unsigned int volume = 0;
239 sst_hsw_mixer_get_volume(hsw, 0, 0, &volume);
240 ucontrol->value.integer.value[0] = hsw_ipc_to_mixer(volume);
242 sst_hsw_mixer_get_volume(hsw, 0, 1, &volume);
243 ucontrol->value.integer.value[1] = hsw_ipc_to_mixer(volume);
248 /* TLV used by both global and stream volumes */
249 static const DECLARE_TLV_DB_SCALE(hsw_vol_tlv, -9000, 300, 1);
251 /* System Pin has no volume control */
252 static const struct snd_kcontrol_new hsw_volume_controls[] = {
253 /* Global DSP volume */
254 SOC_DOUBLE_EXT_TLV("Master Playback Volume", 0, 0, 8,
255 ARRAY_SIZE(volume_map) -1, 0,
256 hsw_volume_get, hsw_volume_put, hsw_vol_tlv),
257 /* Offload 0 volume */
258 SOC_DOUBLE_EXT_TLV("Media0 Playback Volume", 1, 0, 8,
259 ARRAY_SIZE(volume_map), 0,
260 hsw_stream_volume_get, hsw_stream_volume_put, hsw_vol_tlv),
261 /* Offload 1 volume */
262 SOC_DOUBLE_EXT_TLV("Media1 Playback Volume", 2, 0, 8,
263 ARRAY_SIZE(volume_map), 0,
264 hsw_stream_volume_get, hsw_stream_volume_put, hsw_vol_tlv),
265 /* Loopback volume */
266 SOC_DOUBLE_EXT_TLV("Loopback Capture Volume", 3, 0, 8,
267 ARRAY_SIZE(volume_map), 0,
268 hsw_stream_volume_get, hsw_stream_volume_put, hsw_vol_tlv),
269 /* Mic Capture volume */
270 SOC_DOUBLE_EXT_TLV("Mic Capture Volume", 4, 0, 8,
271 ARRAY_SIZE(volume_map), 0,
272 hsw_stream_volume_get, hsw_stream_volume_put, hsw_vol_tlv),
275 /* Create DMA buffer page table for DSP */
276 static int create_adsp_page_table(struct hsw_priv_data *pdata,
277 struct snd_soc_pcm_runtime *rtd,
278 unsigned char *dma_area, size_t size, int pcm, int stream)
282 if (size % PAGE_SIZE)
283 pages = (size / PAGE_SIZE) + 1;
285 pages = size / PAGE_SIZE;
287 dev_dbg(rtd->dev, "generating page table for %p size 0x%zu pages %d\n",
288 dma_area, size, pages);
290 for (i = 0; i < pages; i++) {
291 u32 idx = (((i << 2) + i)) >> 1;
292 u32 pfn = (virt_to_phys(dma_area + i * PAGE_SIZE)) >> PAGE_SHIFT;
295 dev_dbg(rtd->dev, "pfn i %i idx %d pfn %x\n", i, idx, pfn);
297 pg_table = (u32*)(pdata->pcm_pg[pcm][stream] + idx);
300 *pg_table |= (pfn << 4);
308 /* this may get called several times by oss emulation */
309 static int hsw_pcm_hw_params(struct snd_pcm_substream *substream,
310 struct snd_pcm_hw_params *params)
312 struct snd_soc_pcm_runtime *rtd = substream->private_data;
313 struct snd_pcm_runtime *runtime = substream->runtime;
314 struct hsw_priv_data *pdata =
315 snd_soc_platform_get_drvdata(rtd->platform);
316 struct hsw_pcm_data *pcm_data = snd_soc_pcm_get_drvdata(rtd);
317 struct sst_hsw *hsw = pdata->hsw;
318 struct sst_module *module_data;
320 enum sst_hsw_stream_type stream_type;
321 enum sst_hsw_stream_path_id path_id;
322 u32 rate, bits, map, pages, module_id;
326 /* stream direction */
327 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
328 path_id = SST_HSW_STREAM_PATH_SSP0_OUT;
330 path_id = SST_HSW_STREAM_PATH_SSP0_IN;
332 /* DSP stream type depends on DAI ID */
333 switch (rtd->cpu_dai->id) {
335 stream_type = SST_HSW_STREAM_TYPE_SYSTEM;
336 module_id = SST_HSW_MODULE_PCM_SYSTEM;
340 stream_type = SST_HSW_STREAM_TYPE_RENDER;
341 module_id = SST_HSW_MODULE_PCM;
344 /* path ID needs to be OUT for loopback */
345 stream_type = SST_HSW_STREAM_TYPE_LOOPBACK;
346 path_id = SST_HSW_STREAM_PATH_SSP0_OUT;
347 module_id = SST_HSW_MODULE_PCM_REFERENCE;
350 stream_type = SST_HSW_STREAM_TYPE_CAPTURE;
351 module_id = SST_HSW_MODULE_PCM_CAPTURE;
354 dev_err(rtd->dev, "error: invalid DAI ID %d\n",
359 ret = sst_hsw_stream_format(hsw, pcm_data->stream,
360 path_id, stream_type, SST_HSW_STREAM_FORMAT_PCM_FORMAT);
362 dev_err(rtd->dev, "error: failed to set format %d\n", ret);
366 rate = params_rate(params);
367 ret = sst_hsw_stream_set_rate(hsw, pcm_data->stream, rate);
369 dev_err(rtd->dev, "error: could not set rate %d\n", rate);
373 switch (params_format(params)) {
374 case SNDRV_PCM_FORMAT_S16_LE:
375 bits = SST_HSW_DEPTH_16BIT;
376 sst_hsw_stream_set_valid(hsw, pcm_data->stream, 16);
378 case SNDRV_PCM_FORMAT_S24_LE:
379 bits = SST_HSW_DEPTH_24BIT;
380 sst_hsw_stream_set_valid(hsw, pcm_data->stream, 32);
383 dev_err(rtd->dev, "error: invalid format %d\n",
384 params_format(params));
388 ret = sst_hsw_stream_set_bits(hsw, pcm_data->stream, bits);
390 dev_err(rtd->dev, "error: could not set bits %d\n", bits);
394 /* we only support stereo atm */
395 channels = params_channels(params);
397 dev_err(rtd->dev, "error: invalid channels %d\n", channels);
401 map = create_channel_map(SST_HSW_CHANNEL_CONFIG_STEREO);
402 sst_hsw_stream_set_map_config(hsw, pcm_data->stream,
403 map, SST_HSW_CHANNEL_CONFIG_STEREO);
405 ret = sst_hsw_stream_set_channels(hsw, pcm_data->stream, channels);
407 dev_err(rtd->dev, "error: could not set channels %d\n",
412 ret = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params));
414 dev_err(rtd->dev, "error: could not allocate %d bytes for PCM %d\n",
415 params_buffer_bytes(params), ret);
419 ret = create_adsp_page_table(pdata, rtd, runtime->dma_area,
420 runtime->dma_bytes, rtd->cpu_dai->id, substream->stream);
424 sst_hsw_stream_set_style(hsw, pcm_data->stream,
425 SST_HSW_INTERLEAVING_PER_CHANNEL);
427 if (runtime->dma_bytes % PAGE_SIZE)
428 pages = (runtime->dma_bytes / PAGE_SIZE) + 1;
430 pages = runtime->dma_bytes / PAGE_SIZE;
432 ret = sst_hsw_stream_buffer(hsw, pcm_data->stream,
433 virt_to_phys(pdata->pcm_pg[rtd->cpu_dai->id][substream->stream]),
434 pages, runtime->dma_bytes, 0,
435 (u32)(virt_to_phys(runtime->dma_area) >> PAGE_SHIFT));
437 dev_err(rtd->dev, "error: failed to set DMA buffer %d\n", ret);
441 dsp = sst_hsw_get_dsp(hsw);
443 module_data = sst_module_get_from_id(dsp, module_id);
444 if (module_data == NULL) {
445 dev_err(rtd->dev, "error: failed to get module config\n");
449 /* we use hardcoded memory offsets atm, will be updated for new FW */
450 if (stream_type == SST_HSW_STREAM_TYPE_CAPTURE) {
451 sst_hsw_stream_set_module_info(hsw, pcm_data->stream,
452 SST_HSW_MODULE_PCM_CAPTURE, module_data->entry);
453 sst_hsw_stream_set_pmemory_info(hsw, pcm_data->stream,
455 sst_hsw_stream_set_smemory_info(hsw, pcm_data->stream,
457 } else { /* stream_type == SST_HSW_STREAM_TYPE_SYSTEM */
458 sst_hsw_stream_set_module_info(hsw, pcm_data->stream,
459 SST_HSW_MODULE_PCM_SYSTEM, module_data->entry);
461 sst_hsw_stream_set_pmemory_info(hsw, pcm_data->stream,
462 module_data->offset, module_data->size);
463 sst_hsw_stream_set_pmemory_info(hsw, pcm_data->stream,
466 sst_hsw_stream_set_smemory_info(hsw, pcm_data->stream,
467 module_data->offset, module_data->size);
468 sst_hsw_stream_set_smemory_info(hsw, pcm_data->stream,
472 ret = sst_hsw_stream_commit(hsw, pcm_data->stream);
474 dev_err(rtd->dev, "error: failed to commit stream %d\n", ret);
478 ret = sst_hsw_stream_pause(hsw, pcm_data->stream, 1);
480 dev_err(rtd->dev, "error: failed to pause %d\n", ret);
485 static int hsw_pcm_hw_free(struct snd_pcm_substream *substream)
487 snd_pcm_lib_free_pages(substream);
491 static int hsw_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
493 struct snd_soc_pcm_runtime *rtd = substream->private_data;
494 struct hsw_priv_data *pdata =
495 snd_soc_platform_get_drvdata(rtd->platform);
496 struct hsw_pcm_data *pcm_data = snd_soc_pcm_get_drvdata(rtd);
497 struct sst_hsw *hsw = pdata->hsw;
500 case SNDRV_PCM_TRIGGER_START:
501 case SNDRV_PCM_TRIGGER_RESUME:
502 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
503 sst_hsw_stream_resume(hsw, pcm_data->stream, 0);
505 case SNDRV_PCM_TRIGGER_STOP:
506 case SNDRV_PCM_TRIGGER_SUSPEND:
507 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
508 sst_hsw_stream_pause(hsw, pcm_data->stream, 0);
517 static u32 hsw_notify_pointer(struct sst_hsw_stream *stream, void *data)
519 struct hsw_pcm_data *pcm_data = data;
520 struct snd_pcm_substream *substream = pcm_data->substream;
521 struct snd_pcm_runtime *runtime = substream->runtime;
522 struct snd_soc_pcm_runtime *rtd = substream->private_data;
525 pos = frames_to_bytes(runtime,
526 (runtime->control->appl_ptr % runtime->buffer_size));
528 dev_dbg(rtd->dev, "PCM: App pointer %d bytes\n", pos);
530 /* let alsa know we have play a period */
531 snd_pcm_period_elapsed(substream);
535 static snd_pcm_uframes_t hsw_pcm_pointer(struct snd_pcm_substream *substream)
537 struct snd_soc_pcm_runtime *rtd = substream->private_data;
538 struct snd_pcm_runtime *runtime = substream->runtime;
539 struct hsw_priv_data *pdata =
540 snd_soc_platform_get_drvdata(rtd->platform);
541 struct hsw_pcm_data *pcm_data = snd_soc_pcm_get_drvdata(rtd);
542 struct sst_hsw *hsw = pdata->hsw;
543 snd_pcm_uframes_t offset;
545 offset = bytes_to_frames(runtime,
546 sst_hsw_get_dsp_position(hsw, pcm_data->stream));
548 dev_dbg(rtd->dev, "PCM: DMA pointer %zu bytes\n",
549 frames_to_bytes(runtime, (u32)offset));
553 static int hsw_pcm_open(struct snd_pcm_substream *substream)
555 struct snd_soc_pcm_runtime *rtd = substream->private_data;
556 struct hsw_priv_data *pdata =
557 snd_soc_platform_get_drvdata(rtd->platform);
558 struct hsw_pcm_data *pcm_data;
559 struct sst_hsw *hsw = pdata->hsw;
561 pcm_data = &pdata->pcm[rtd->cpu_dai->id];
563 mutex_lock(&pcm_data->mutex);
565 snd_soc_pcm_set_drvdata(rtd, pcm_data);
566 pcm_data->substream = substream;
568 snd_soc_set_runtime_hwparams(substream, &hsw_pcm_hardware);
570 pcm_data->stream = sst_hsw_stream_new(hsw, rtd->cpu_dai->id,
571 hsw_notify_pointer, pcm_data);
572 if (pcm_data->stream == NULL) {
573 dev_err(rtd->dev, "error: failed to create stream\n");
574 mutex_unlock(&pcm_data->mutex);
578 /* Set previous saved volume */
579 sst_hsw_stream_set_volume(hsw, pcm_data->stream, 0,
580 0, pcm_data->volume[0]);
581 sst_hsw_stream_set_volume(hsw, pcm_data->stream, 0,
582 1, pcm_data->volume[1]);
584 mutex_unlock(&pcm_data->mutex);
588 static int hsw_pcm_close(struct snd_pcm_substream *substream)
590 struct snd_soc_pcm_runtime *rtd = substream->private_data;
591 struct hsw_priv_data *pdata =
592 snd_soc_platform_get_drvdata(rtd->platform);
593 struct hsw_pcm_data *pcm_data = snd_soc_pcm_get_drvdata(rtd);
594 struct sst_hsw *hsw = pdata->hsw;
597 mutex_lock(&pcm_data->mutex);
598 ret = sst_hsw_stream_reset(hsw, pcm_data->stream);
600 dev_dbg(rtd->dev, "error: reset stream failed %d\n", ret);
604 ret = sst_hsw_stream_free(hsw, pcm_data->stream);
606 dev_dbg(rtd->dev, "error: free stream failed %d\n", ret);
609 pcm_data->stream = NULL;
612 mutex_unlock(&pcm_data->mutex);
616 static struct snd_pcm_ops hsw_pcm_ops = {
617 .open = hsw_pcm_open,
618 .close = hsw_pcm_close,
619 .ioctl = snd_pcm_lib_ioctl,
620 .hw_params = hsw_pcm_hw_params,
621 .hw_free = hsw_pcm_hw_free,
622 .trigger = hsw_pcm_trigger,
623 .pointer = hsw_pcm_pointer,
624 .mmap = snd_pcm_lib_default_mmap,
627 static void hsw_pcm_free(struct snd_pcm *pcm)
629 snd_pcm_lib_preallocate_free_for_all(pcm);
632 static int hsw_pcm_new(struct snd_soc_pcm_runtime *rtd)
634 struct snd_pcm *pcm = rtd->pcm;
637 ret = dma_coerce_mask_and_coherent(rtd->card->dev, DMA_BIT_MASK(32));
641 if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream ||
642 pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream) {
643 ret = snd_pcm_lib_preallocate_pages_for_all(pcm,
646 hsw_pcm_hardware.buffer_bytes_max,
647 hsw_pcm_hardware.buffer_bytes_max);
649 dev_err(rtd->dev, "dma buffer allocation failed %d\n",
658 #define HSW_FORMATS \
659 (SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S16_LE |\
660 SNDRV_PCM_FMTBIT_S32_LE)
662 static struct snd_soc_dai_driver hsw_dais[] = {
664 .name = "System Pin",
666 .stream_name = "System Playback",
669 .rates = SNDRV_PCM_RATE_48000,
670 .formats = SNDRV_PCM_FMTBIT_S16_LE,
675 .name = "Offload0 Pin",
677 .stream_name = "Offload0 Playback",
680 .rates = SNDRV_PCM_RATE_8000_192000,
681 .formats = HSW_FORMATS,
686 .name = "Offload1 Pin",
688 .stream_name = "Offload1 Playback",
691 .rates = SNDRV_PCM_RATE_8000_192000,
692 .formats = HSW_FORMATS,
696 .name = "Loopback Pin",
698 .stream_name = "Loopback Capture",
701 .rates = SNDRV_PCM_RATE_8000_192000,
702 .formats = HSW_FORMATS,
706 .name = "Capture Pin",
708 .stream_name = "Analog Capture",
711 .rates = SNDRV_PCM_RATE_8000_192000,
712 .formats = HSW_FORMATS,
717 static const struct snd_soc_dapm_widget widgets[] = {
720 SND_SOC_DAPM_AIF_IN("SSP0 CODEC IN", NULL, 0, SND_SOC_NOPM, 0, 0),
721 SND_SOC_DAPM_AIF_OUT("SSP0 CODEC OUT", NULL, 0, SND_SOC_NOPM, 0, 0),
722 SND_SOC_DAPM_AIF_IN("SSP1 BT IN", NULL, 0, SND_SOC_NOPM, 0, 0),
723 SND_SOC_DAPM_AIF_OUT("SSP1 BT OUT", NULL, 0, SND_SOC_NOPM, 0, 0),
725 /* Global Playback Mixer */
726 SND_SOC_DAPM_MIXER("Playback VMixer", SND_SOC_NOPM, 0, 0, NULL, 0),
729 static const struct snd_soc_dapm_route graph[] = {
732 {"Playback VMixer", NULL, "System Playback"},
733 {"Playback VMixer", NULL, "Offload0 Playback"},
734 {"Playback VMixer", NULL, "Offload1 Playback"},
736 {"SSP0 CODEC OUT", NULL, "Playback VMixer"},
738 {"Analog Capture", NULL, "SSP0 CODEC IN"},
741 static int hsw_pcm_probe(struct snd_soc_platform *platform)
743 struct sst_pdata *pdata = dev_get_platdata(platform->dev);
744 struct hsw_priv_data *priv_data;
750 priv_data = devm_kzalloc(platform->dev, sizeof(*priv_data), GFP_KERNEL);
751 priv_data->hsw = pdata->dsp;
752 snd_soc_platform_set_drvdata(platform, priv_data);
754 /* allocate DSP buffer page tables */
755 for (i = 0; i < ARRAY_SIZE(hsw_dais); i++) {
757 mutex_init(&priv_data->pcm[i].mutex);
760 if (hsw_dais[i].playback.channels_min) {
761 priv_data->pcm_pg[i][0] = kzalloc(PAGE_SIZE, GFP_DMA);
762 if (priv_data->pcm_pg[i][0] == NULL)
767 if (hsw_dais[i].capture.channels_min) {
768 priv_data->pcm_pg[i][1] = kzalloc(PAGE_SIZE, GFP_DMA);
769 if (priv_data->pcm_pg[i][1] == NULL)
778 if (hsw_dais[i].playback.channels_min)
779 kfree(priv_data->pcm_pg[i][0]);
780 if (hsw_dais[i].capture.channels_min)
781 kfree(priv_data->pcm_pg[i][1]);
786 static int hsw_pcm_remove(struct snd_soc_platform *platform)
788 struct hsw_priv_data *priv_data =
789 snd_soc_platform_get_drvdata(platform);
792 for (i = 0; i < ARRAY_SIZE(hsw_dais); i++) {
793 if (hsw_dais[i].playback.channels_min)
794 kfree(priv_data->pcm_pg[i][0]);
795 if (hsw_dais[i].capture.channels_min)
796 kfree(priv_data->pcm_pg[i][1]);
802 static struct snd_soc_platform_driver hsw_soc_platform = {
803 .probe = hsw_pcm_probe,
804 .remove = hsw_pcm_remove,
806 .pcm_new = hsw_pcm_new,
807 .pcm_free = hsw_pcm_free,
808 .controls = hsw_volume_controls,
809 .num_controls = ARRAY_SIZE(hsw_volume_controls),
810 .dapm_widgets = widgets,
811 .num_dapm_widgets = ARRAY_SIZE(widgets),
812 .dapm_routes = graph,
813 .num_dapm_routes = ARRAY_SIZE(graph),
816 static const struct snd_soc_component_driver hsw_dai_component = {
817 .name = "haswell-dai",
820 static int hsw_pcm_dev_probe(struct platform_device *pdev)
822 struct sst_pdata *sst_pdata = dev_get_platdata(&pdev->dev);
825 ret = sst_hsw_dsp_init(&pdev->dev, sst_pdata);
829 ret = snd_soc_register_platform(&pdev->dev, &hsw_soc_platform);
833 ret = snd_soc_register_component(&pdev->dev, &hsw_dai_component,
834 hsw_dais, ARRAY_SIZE(hsw_dais));
841 snd_soc_unregister_platform(&pdev->dev);
843 sst_hsw_dsp_free(&pdev->dev, sst_pdata);
847 static int hsw_pcm_dev_remove(struct platform_device *pdev)
849 struct sst_pdata *sst_pdata = dev_get_platdata(&pdev->dev);
851 snd_soc_unregister_platform(&pdev->dev);
852 snd_soc_unregister_component(&pdev->dev);
853 sst_hsw_dsp_free(&pdev->dev, sst_pdata);
858 static struct platform_driver hsw_pcm_driver = {
860 .name = "haswell-pcm-audio",
861 .owner = THIS_MODULE,
864 .probe = hsw_pcm_dev_probe,
865 .remove = hsw_pcm_dev_remove,
867 module_platform_driver(hsw_pcm_driver);
869 MODULE_AUTHOR("Liam Girdwood, Xingchao Wang");
870 MODULE_DESCRIPTION("Haswell/Lynxpoint + Broadwell/Wildcatpoint PCM");
871 MODULE_LICENSE("GPL v2");
872 MODULE_ALIAS("platform:haswell-pcm-audio");