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;
105 /* private data for the driver */
106 struct hsw_priv_data {
111 struct snd_dma_buffer dmab[HSW_PCM_COUNT][2];
114 struct hsw_pcm_data pcm[HSW_PCM_COUNT];
117 static u32 hsw_notify_pointer(struct sst_hsw_stream *stream, void *data);
119 static inline u32 hsw_mixer_to_ipc(unsigned int value)
121 if (value >= ARRAY_SIZE(volume_map))
122 return volume_map[0];
124 return volume_map[value];
127 static inline unsigned int hsw_ipc_to_mixer(u32 value)
131 for (i = 0; i < ARRAY_SIZE(volume_map); i++) {
132 if (volume_map[i] >= value)
139 static int hsw_stream_volume_put(struct snd_kcontrol *kcontrol,
140 struct snd_ctl_elem_value *ucontrol)
142 struct snd_soc_platform *platform = snd_kcontrol_chip(kcontrol);
143 struct soc_mixer_control *mc =
144 (struct soc_mixer_control *)kcontrol->private_value;
145 struct hsw_priv_data *pdata =
146 snd_soc_platform_get_drvdata(platform);
147 struct hsw_pcm_data *pcm_data = &pdata->pcm[mc->reg];
148 struct sst_hsw *hsw = pdata->hsw;
151 mutex_lock(&pcm_data->mutex);
153 if (!pcm_data->stream) {
154 pcm_data->volume[0] =
155 hsw_mixer_to_ipc(ucontrol->value.integer.value[0]);
156 pcm_data->volume[1] =
157 hsw_mixer_to_ipc(ucontrol->value.integer.value[1]);
158 mutex_unlock(&pcm_data->mutex);
162 if (ucontrol->value.integer.value[0] ==
163 ucontrol->value.integer.value[1]) {
164 volume = hsw_mixer_to_ipc(ucontrol->value.integer.value[0]);
165 sst_hsw_stream_set_volume(hsw, pcm_data->stream, 0, 2, volume);
167 volume = hsw_mixer_to_ipc(ucontrol->value.integer.value[0]);
168 sst_hsw_stream_set_volume(hsw, pcm_data->stream, 0, 0, volume);
169 volume = hsw_mixer_to_ipc(ucontrol->value.integer.value[1]);
170 sst_hsw_stream_set_volume(hsw, pcm_data->stream, 0, 1, volume);
173 mutex_unlock(&pcm_data->mutex);
177 static int hsw_stream_volume_get(struct snd_kcontrol *kcontrol,
178 struct snd_ctl_elem_value *ucontrol)
180 struct snd_soc_platform *platform = snd_kcontrol_chip(kcontrol);
181 struct soc_mixer_control *mc =
182 (struct soc_mixer_control *)kcontrol->private_value;
183 struct hsw_priv_data *pdata =
184 snd_soc_platform_get_drvdata(platform);
185 struct hsw_pcm_data *pcm_data = &pdata->pcm[mc->reg];
186 struct sst_hsw *hsw = pdata->hsw;
189 mutex_lock(&pcm_data->mutex);
191 if (!pcm_data->stream) {
192 ucontrol->value.integer.value[0] =
193 hsw_ipc_to_mixer(pcm_data->volume[0]);
194 ucontrol->value.integer.value[1] =
195 hsw_ipc_to_mixer(pcm_data->volume[1]);
196 mutex_unlock(&pcm_data->mutex);
200 sst_hsw_stream_get_volume(hsw, pcm_data->stream, 0, 0, &volume);
201 ucontrol->value.integer.value[0] = hsw_ipc_to_mixer(volume);
202 sst_hsw_stream_get_volume(hsw, pcm_data->stream, 0, 1, &volume);
203 ucontrol->value.integer.value[1] = hsw_ipc_to_mixer(volume);
204 mutex_unlock(&pcm_data->mutex);
209 static int hsw_volume_put(struct snd_kcontrol *kcontrol,
210 struct snd_ctl_elem_value *ucontrol)
212 struct snd_soc_platform *platform = snd_kcontrol_chip(kcontrol);
213 struct hsw_priv_data *pdata = snd_soc_platform_get_drvdata(platform);
214 struct sst_hsw *hsw = pdata->hsw;
217 if (ucontrol->value.integer.value[0] ==
218 ucontrol->value.integer.value[1]) {
220 volume = hsw_mixer_to_ipc(ucontrol->value.integer.value[0]);
221 sst_hsw_mixer_set_volume(hsw, 0, 2, volume);
224 volume = hsw_mixer_to_ipc(ucontrol->value.integer.value[0]);
225 sst_hsw_mixer_set_volume(hsw, 0, 0, volume);
227 volume = hsw_mixer_to_ipc(ucontrol->value.integer.value[1]);
228 sst_hsw_mixer_set_volume(hsw, 0, 1, volume);
234 static int hsw_volume_get(struct snd_kcontrol *kcontrol,
235 struct snd_ctl_elem_value *ucontrol)
237 struct snd_soc_platform *platform = snd_kcontrol_chip(kcontrol);
238 struct hsw_priv_data *pdata = snd_soc_platform_get_drvdata(platform);
239 struct sst_hsw *hsw = pdata->hsw;
240 unsigned int volume = 0;
242 sst_hsw_mixer_get_volume(hsw, 0, 0, &volume);
243 ucontrol->value.integer.value[0] = hsw_ipc_to_mixer(volume);
245 sst_hsw_mixer_get_volume(hsw, 0, 1, &volume);
246 ucontrol->value.integer.value[1] = hsw_ipc_to_mixer(volume);
251 /* TLV used by both global and stream volumes */
252 static const DECLARE_TLV_DB_SCALE(hsw_vol_tlv, -9000, 300, 1);
254 /* System Pin has no volume control */
255 static const struct snd_kcontrol_new hsw_volume_controls[] = {
256 /* Global DSP volume */
257 SOC_DOUBLE_EXT_TLV("Master Playback Volume", 0, 0, 8,
258 ARRAY_SIZE(volume_map) -1, 0,
259 hsw_volume_get, hsw_volume_put, hsw_vol_tlv),
260 /* Offload 0 volume */
261 SOC_DOUBLE_EXT_TLV("Media0 Playback Volume", 1, 0, 8,
262 ARRAY_SIZE(volume_map), 0,
263 hsw_stream_volume_get, hsw_stream_volume_put, hsw_vol_tlv),
264 /* Offload 1 volume */
265 SOC_DOUBLE_EXT_TLV("Media1 Playback Volume", 2, 0, 8,
266 ARRAY_SIZE(volume_map), 0,
267 hsw_stream_volume_get, hsw_stream_volume_put, hsw_vol_tlv),
268 /* Loopback volume */
269 SOC_DOUBLE_EXT_TLV("Loopback Capture Volume", 3, 0, 8,
270 ARRAY_SIZE(volume_map), 0,
271 hsw_stream_volume_get, hsw_stream_volume_put, hsw_vol_tlv),
272 /* Mic Capture volume */
273 SOC_DOUBLE_EXT_TLV("Mic Capture Volume", 4, 0, 8,
274 ARRAY_SIZE(volume_map), 0,
275 hsw_stream_volume_get, hsw_stream_volume_put, hsw_vol_tlv),
278 /* Create DMA buffer page table for DSP */
279 static int create_adsp_page_table(struct snd_pcm_substream *substream,
280 struct hsw_priv_data *pdata, struct snd_soc_pcm_runtime *rtd,
281 unsigned char *dma_area, size_t size, int pcm)
283 struct snd_dma_buffer *dmab = snd_pcm_get_dma_buf(substream);
284 int i, pages, stream = substream->stream;
286 pages = snd_sgbuf_aligned_pages(size);
288 dev_dbg(rtd->dev, "generating page table for %p size 0x%zu pages %d\n",
289 dma_area, size, pages);
291 for (i = 0; i < pages; i++) {
292 u32 idx = (((i << 2) + i)) >> 1;
293 u32 pfn = snd_sgbuf_get_addr(dmab, i * PAGE_SIZE) >> PAGE_SHIFT;
296 dev_dbg(rtd->dev, "pfn i %i idx %d pfn %x\n", i, idx, pfn);
298 pg_table = (u32 *)(pdata->dmab[pcm][stream].area + idx);
301 *pg_table |= (pfn << 4);
309 /* this may get called several times by oss emulation */
310 static int hsw_pcm_hw_params(struct snd_pcm_substream *substream,
311 struct snd_pcm_hw_params *params)
313 struct snd_soc_pcm_runtime *rtd = substream->private_data;
314 struct snd_pcm_runtime *runtime = substream->runtime;
315 struct hsw_priv_data *pdata =
316 snd_soc_platform_get_drvdata(rtd->platform);
317 struct hsw_pcm_data *pcm_data = snd_soc_pcm_get_drvdata(rtd);
318 struct sst_hsw *hsw = pdata->hsw;
319 struct sst_module *module_data;
321 struct snd_dma_buffer *dmab;
322 enum sst_hsw_stream_type stream_type;
323 enum sst_hsw_stream_path_id path_id;
324 u32 rate, bits, map, pages, module_id;
328 /* check if we are being called a subsequent time */
329 if (pcm_data->allocated) {
330 ret = sst_hsw_stream_reset(hsw, pcm_data->stream);
332 dev_dbg(rtd->dev, "error: reset stream failed %d\n",
335 ret = sst_hsw_stream_free(hsw, pcm_data->stream);
337 dev_dbg(rtd->dev, "error: free stream failed %d\n",
341 pcm_data->allocated = false;
343 pcm_data->stream = sst_hsw_stream_new(hsw, rtd->cpu_dai->id,
344 hsw_notify_pointer, pcm_data);
345 if (pcm_data->stream == NULL) {
346 dev_err(rtd->dev, "error: failed to create stream\n");
351 /* stream direction */
352 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
353 path_id = SST_HSW_STREAM_PATH_SSP0_OUT;
355 path_id = SST_HSW_STREAM_PATH_SSP0_IN;
357 /* DSP stream type depends on DAI ID */
358 switch (rtd->cpu_dai->id) {
360 stream_type = SST_HSW_STREAM_TYPE_SYSTEM;
361 module_id = SST_HSW_MODULE_PCM_SYSTEM;
365 stream_type = SST_HSW_STREAM_TYPE_RENDER;
366 module_id = SST_HSW_MODULE_PCM;
369 /* path ID needs to be OUT for loopback */
370 stream_type = SST_HSW_STREAM_TYPE_LOOPBACK;
371 path_id = SST_HSW_STREAM_PATH_SSP0_OUT;
372 module_id = SST_HSW_MODULE_PCM_REFERENCE;
375 stream_type = SST_HSW_STREAM_TYPE_CAPTURE;
376 module_id = SST_HSW_MODULE_PCM_CAPTURE;
379 dev_err(rtd->dev, "error: invalid DAI ID %d\n",
384 ret = sst_hsw_stream_format(hsw, pcm_data->stream,
385 path_id, stream_type, SST_HSW_STREAM_FORMAT_PCM_FORMAT);
387 dev_err(rtd->dev, "error: failed to set format %d\n", ret);
391 rate = params_rate(params);
392 ret = sst_hsw_stream_set_rate(hsw, pcm_data->stream, rate);
394 dev_err(rtd->dev, "error: could not set rate %d\n", rate);
398 switch (params_format(params)) {
399 case SNDRV_PCM_FORMAT_S16_LE:
400 bits = SST_HSW_DEPTH_16BIT;
401 sst_hsw_stream_set_valid(hsw, pcm_data->stream, 16);
403 case SNDRV_PCM_FORMAT_S24_LE:
404 bits = SST_HSW_DEPTH_24BIT;
405 sst_hsw_stream_set_valid(hsw, pcm_data->stream, 32);
408 dev_err(rtd->dev, "error: invalid format %d\n",
409 params_format(params));
413 ret = sst_hsw_stream_set_bits(hsw, pcm_data->stream, bits);
415 dev_err(rtd->dev, "error: could not set bits %d\n", bits);
419 /* we only support stereo atm */
420 channels = params_channels(params);
422 dev_err(rtd->dev, "error: invalid channels %d\n", channels);
426 map = create_channel_map(SST_HSW_CHANNEL_CONFIG_STEREO);
427 sst_hsw_stream_set_map_config(hsw, pcm_data->stream,
428 map, SST_HSW_CHANNEL_CONFIG_STEREO);
430 ret = sst_hsw_stream_set_channels(hsw, pcm_data->stream, channels);
432 dev_err(rtd->dev, "error: could not set channels %d\n",
437 ret = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params));
439 dev_err(rtd->dev, "error: could not allocate %d bytes for PCM %d\n",
440 params_buffer_bytes(params), ret);
444 dmab = snd_pcm_get_dma_buf(substream);
446 ret = create_adsp_page_table(substream, pdata, rtd, runtime->dma_area,
447 runtime->dma_bytes, rtd->cpu_dai->id);
451 sst_hsw_stream_set_style(hsw, pcm_data->stream,
452 SST_HSW_INTERLEAVING_PER_CHANNEL);
454 if (runtime->dma_bytes % PAGE_SIZE)
455 pages = (runtime->dma_bytes / PAGE_SIZE) + 1;
457 pages = runtime->dma_bytes / PAGE_SIZE;
459 ret = sst_hsw_stream_buffer(hsw, pcm_data->stream,
460 pdata->dmab[rtd->cpu_dai->id][substream->stream].addr,
461 pages, runtime->dma_bytes, 0,
462 snd_sgbuf_get_addr(dmab, 0) >> PAGE_SHIFT);
464 dev_err(rtd->dev, "error: failed to set DMA buffer %d\n", ret);
468 dsp = sst_hsw_get_dsp(hsw);
470 module_data = sst_module_get_from_id(dsp, module_id);
471 if (module_data == NULL) {
472 dev_err(rtd->dev, "error: failed to get module config\n");
476 /* we use hardcoded memory offsets atm, will be updated for new FW */
477 if (stream_type == SST_HSW_STREAM_TYPE_CAPTURE) {
478 sst_hsw_stream_set_module_info(hsw, pcm_data->stream,
479 SST_HSW_MODULE_PCM_CAPTURE, module_data->entry);
480 sst_hsw_stream_set_pmemory_info(hsw, pcm_data->stream,
482 sst_hsw_stream_set_smemory_info(hsw, pcm_data->stream,
484 } else { /* stream_type == SST_HSW_STREAM_TYPE_SYSTEM */
485 sst_hsw_stream_set_module_info(hsw, pcm_data->stream,
486 SST_HSW_MODULE_PCM_SYSTEM, module_data->entry);
488 sst_hsw_stream_set_pmemory_info(hsw, pcm_data->stream,
489 module_data->offset, module_data->size);
490 sst_hsw_stream_set_pmemory_info(hsw, pcm_data->stream,
493 sst_hsw_stream_set_smemory_info(hsw, pcm_data->stream,
494 module_data->offset, module_data->size);
495 sst_hsw_stream_set_smemory_info(hsw, pcm_data->stream,
499 ret = sst_hsw_stream_commit(hsw, pcm_data->stream);
501 dev_err(rtd->dev, "error: failed to commit stream %d\n", ret);
504 pcm_data->allocated = true;
506 ret = sst_hsw_stream_pause(hsw, pcm_data->stream, 1);
508 dev_err(rtd->dev, "error: failed to pause %d\n", ret);
513 static int hsw_pcm_hw_free(struct snd_pcm_substream *substream)
515 snd_pcm_lib_free_pages(substream);
519 static int hsw_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
521 struct snd_soc_pcm_runtime *rtd = substream->private_data;
522 struct hsw_priv_data *pdata =
523 snd_soc_platform_get_drvdata(rtd->platform);
524 struct hsw_pcm_data *pcm_data = snd_soc_pcm_get_drvdata(rtd);
525 struct sst_hsw *hsw = pdata->hsw;
528 case SNDRV_PCM_TRIGGER_START:
529 case SNDRV_PCM_TRIGGER_RESUME:
530 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
531 sst_hsw_stream_resume(hsw, pcm_data->stream, 0);
533 case SNDRV_PCM_TRIGGER_STOP:
534 case SNDRV_PCM_TRIGGER_SUSPEND:
535 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
536 sst_hsw_stream_pause(hsw, pcm_data->stream, 0);
545 static u32 hsw_notify_pointer(struct sst_hsw_stream *stream, void *data)
547 struct hsw_pcm_data *pcm_data = data;
548 struct snd_pcm_substream *substream = pcm_data->substream;
549 struct snd_pcm_runtime *runtime = substream->runtime;
550 struct snd_soc_pcm_runtime *rtd = substream->private_data;
553 pos = frames_to_bytes(runtime,
554 (runtime->control->appl_ptr % runtime->buffer_size));
556 dev_dbg(rtd->dev, "PCM: App pointer %d bytes\n", pos);
558 /* let alsa know we have play a period */
559 snd_pcm_period_elapsed(substream);
563 static snd_pcm_uframes_t hsw_pcm_pointer(struct snd_pcm_substream *substream)
565 struct snd_soc_pcm_runtime *rtd = substream->private_data;
566 struct snd_pcm_runtime *runtime = substream->runtime;
567 struct hsw_priv_data *pdata =
568 snd_soc_platform_get_drvdata(rtd->platform);
569 struct hsw_pcm_data *pcm_data = snd_soc_pcm_get_drvdata(rtd);
570 struct sst_hsw *hsw = pdata->hsw;
571 snd_pcm_uframes_t offset;
573 u32 position = sst_hsw_get_dsp_position(hsw, pcm_data->stream);
575 offset = bytes_to_frames(runtime, position);
576 ppos = sst_hsw_get_dsp_presentation_position(hsw, pcm_data->stream);
578 dev_dbg(rtd->dev, "PCM: DMA pointer %du bytes, pos %llu\n",
583 static int hsw_pcm_open(struct snd_pcm_substream *substream)
585 struct snd_soc_pcm_runtime *rtd = substream->private_data;
586 struct hsw_priv_data *pdata =
587 snd_soc_platform_get_drvdata(rtd->platform);
588 struct hsw_pcm_data *pcm_data;
589 struct sst_hsw *hsw = pdata->hsw;
591 pcm_data = &pdata->pcm[rtd->cpu_dai->id];
593 mutex_lock(&pcm_data->mutex);
595 snd_soc_pcm_set_drvdata(rtd, pcm_data);
596 pcm_data->substream = substream;
598 snd_soc_set_runtime_hwparams(substream, &hsw_pcm_hardware);
600 pcm_data->stream = sst_hsw_stream_new(hsw, rtd->cpu_dai->id,
601 hsw_notify_pointer, pcm_data);
602 if (pcm_data->stream == NULL) {
603 dev_err(rtd->dev, "error: failed to create stream\n");
604 mutex_unlock(&pcm_data->mutex);
608 /* Set previous saved volume */
609 sst_hsw_stream_set_volume(hsw, pcm_data->stream, 0,
610 0, pcm_data->volume[0]);
611 sst_hsw_stream_set_volume(hsw, pcm_data->stream, 0,
612 1, pcm_data->volume[1]);
614 mutex_unlock(&pcm_data->mutex);
618 static int hsw_pcm_close(struct snd_pcm_substream *substream)
620 struct snd_soc_pcm_runtime *rtd = substream->private_data;
621 struct hsw_priv_data *pdata =
622 snd_soc_platform_get_drvdata(rtd->platform);
623 struct hsw_pcm_data *pcm_data = snd_soc_pcm_get_drvdata(rtd);
624 struct sst_hsw *hsw = pdata->hsw;
627 mutex_lock(&pcm_data->mutex);
628 ret = sst_hsw_stream_reset(hsw, pcm_data->stream);
630 dev_dbg(rtd->dev, "error: reset stream failed %d\n", ret);
634 ret = sst_hsw_stream_free(hsw, pcm_data->stream);
636 dev_dbg(rtd->dev, "error: free stream failed %d\n", ret);
639 pcm_data->allocated = 0;
640 pcm_data->stream = NULL;
643 mutex_unlock(&pcm_data->mutex);
647 static struct snd_pcm_ops hsw_pcm_ops = {
648 .open = hsw_pcm_open,
649 .close = hsw_pcm_close,
650 .ioctl = snd_pcm_lib_ioctl,
651 .hw_params = hsw_pcm_hw_params,
652 .hw_free = hsw_pcm_hw_free,
653 .trigger = hsw_pcm_trigger,
654 .pointer = hsw_pcm_pointer,
655 .page = snd_pcm_sgbuf_ops_page,
658 static void hsw_pcm_free(struct snd_pcm *pcm)
660 snd_pcm_lib_preallocate_free_for_all(pcm);
663 static int hsw_pcm_new(struct snd_soc_pcm_runtime *rtd)
665 struct snd_pcm *pcm = rtd->pcm;
666 struct snd_soc_platform *platform = rtd->platform;
667 struct sst_pdata *pdata = dev_get_platdata(platform->dev);
668 struct device *dev = pdata->dma_dev;
671 if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream ||
672 pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream) {
673 ret = snd_pcm_lib_preallocate_pages_for_all(pcm,
674 SNDRV_DMA_TYPE_DEV_SG,
676 hsw_pcm_hardware.buffer_bytes_max,
677 hsw_pcm_hardware.buffer_bytes_max);
679 dev_err(rtd->dev, "dma buffer allocation failed %d\n",
688 #define HSW_FORMATS \
689 (SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S16_LE |\
690 SNDRV_PCM_FMTBIT_S32_LE)
692 static struct snd_soc_dai_driver hsw_dais[] = {
694 .name = "System Pin",
696 .stream_name = "System Playback",
699 .rates = SNDRV_PCM_RATE_48000,
700 .formats = SNDRV_PCM_FMTBIT_S16_LE,
705 .name = "Offload0 Pin",
707 .stream_name = "Offload0 Playback",
710 .rates = SNDRV_PCM_RATE_8000_192000,
711 .formats = HSW_FORMATS,
716 .name = "Offload1 Pin",
718 .stream_name = "Offload1 Playback",
721 .rates = SNDRV_PCM_RATE_8000_192000,
722 .formats = HSW_FORMATS,
726 .name = "Loopback Pin",
728 .stream_name = "Loopback Capture",
731 .rates = SNDRV_PCM_RATE_8000_192000,
732 .formats = HSW_FORMATS,
736 .name = "Capture Pin",
738 .stream_name = "Analog Capture",
741 .rates = SNDRV_PCM_RATE_8000_192000,
742 .formats = HSW_FORMATS,
747 static const struct snd_soc_dapm_widget widgets[] = {
750 SND_SOC_DAPM_AIF_IN("SSP0 CODEC IN", NULL, 0, SND_SOC_NOPM, 0, 0),
751 SND_SOC_DAPM_AIF_OUT("SSP0 CODEC OUT", NULL, 0, SND_SOC_NOPM, 0, 0),
752 SND_SOC_DAPM_AIF_IN("SSP1 BT IN", NULL, 0, SND_SOC_NOPM, 0, 0),
753 SND_SOC_DAPM_AIF_OUT("SSP1 BT OUT", NULL, 0, SND_SOC_NOPM, 0, 0),
755 /* Global Playback Mixer */
756 SND_SOC_DAPM_MIXER("Playback VMixer", SND_SOC_NOPM, 0, 0, NULL, 0),
759 static const struct snd_soc_dapm_route graph[] = {
762 {"Playback VMixer", NULL, "System Playback"},
763 {"Playback VMixer", NULL, "Offload0 Playback"},
764 {"Playback VMixer", NULL, "Offload1 Playback"},
766 {"SSP0 CODEC OUT", NULL, "Playback VMixer"},
768 {"Analog Capture", NULL, "SSP0 CODEC IN"},
771 static int hsw_pcm_probe(struct snd_soc_platform *platform)
773 struct sst_pdata *pdata = dev_get_platdata(platform->dev);
774 struct hsw_priv_data *priv_data;
775 struct device *dma_dev;
781 dma_dev = pdata->dma_dev;
783 priv_data = devm_kzalloc(platform->dev, sizeof(*priv_data), GFP_KERNEL);
784 priv_data->hsw = pdata->dsp;
785 snd_soc_platform_set_drvdata(platform, priv_data);
787 /* allocate DSP buffer page tables */
788 for (i = 0; i < ARRAY_SIZE(hsw_dais); i++) {
790 mutex_init(&priv_data->pcm[i].mutex);
793 if (hsw_dais[i].playback.channels_min) {
794 ret = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, dma_dev,
795 PAGE_SIZE, &priv_data->dmab[i][0]);
801 if (hsw_dais[i].capture.channels_min) {
802 ret = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, dma_dev,
803 PAGE_SIZE, &priv_data->dmab[i][1]);
813 if (hsw_dais[i].playback.channels_min)
814 snd_dma_free_pages(&priv_data->dmab[i][0]);
815 if (hsw_dais[i].capture.channels_min)
816 snd_dma_free_pages(&priv_data->dmab[i][1]);
821 static int hsw_pcm_remove(struct snd_soc_platform *platform)
823 struct hsw_priv_data *priv_data =
824 snd_soc_platform_get_drvdata(platform);
827 for (i = 0; i < ARRAY_SIZE(hsw_dais); i++) {
828 if (hsw_dais[i].playback.channels_min)
829 snd_dma_free_pages(&priv_data->dmab[i][0]);
830 if (hsw_dais[i].capture.channels_min)
831 snd_dma_free_pages(&priv_data->dmab[i][1]);
837 static struct snd_soc_platform_driver hsw_soc_platform = {
838 .probe = hsw_pcm_probe,
839 .remove = hsw_pcm_remove,
841 .pcm_new = hsw_pcm_new,
842 .pcm_free = hsw_pcm_free,
843 .controls = hsw_volume_controls,
844 .num_controls = ARRAY_SIZE(hsw_volume_controls),
845 .dapm_widgets = widgets,
846 .num_dapm_widgets = ARRAY_SIZE(widgets),
847 .dapm_routes = graph,
848 .num_dapm_routes = ARRAY_SIZE(graph),
851 static const struct snd_soc_component_driver hsw_dai_component = {
852 .name = "haswell-dai",
855 static int hsw_pcm_dev_probe(struct platform_device *pdev)
857 struct sst_pdata *sst_pdata = dev_get_platdata(&pdev->dev);
860 ret = sst_hsw_dsp_init(&pdev->dev, sst_pdata);
864 ret = snd_soc_register_platform(&pdev->dev, &hsw_soc_platform);
868 ret = snd_soc_register_component(&pdev->dev, &hsw_dai_component,
869 hsw_dais, ARRAY_SIZE(hsw_dais));
876 snd_soc_unregister_platform(&pdev->dev);
878 sst_hsw_dsp_free(&pdev->dev, sst_pdata);
882 static int hsw_pcm_dev_remove(struct platform_device *pdev)
884 struct sst_pdata *sst_pdata = dev_get_platdata(&pdev->dev);
886 snd_soc_unregister_platform(&pdev->dev);
887 snd_soc_unregister_component(&pdev->dev);
888 sst_hsw_dsp_free(&pdev->dev, sst_pdata);
893 static struct platform_driver hsw_pcm_driver = {
895 .name = "haswell-pcm-audio",
896 .owner = THIS_MODULE,
899 .probe = hsw_pcm_dev_probe,
900 .remove = hsw_pcm_dev_remove,
902 module_platform_driver(hsw_pcm_driver);
904 MODULE_AUTHOR("Liam Girdwood, Xingchao Wang");
905 MODULE_DESCRIPTION("Haswell/Lynxpoint + Broadwell/Wildcatpoint PCM");
906 MODULE_LICENSE("GPL v2");
907 MODULE_ALIAS("platform:haswell-pcm-audio");