Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Intel SST Haswell/Broadwell PCM Support |
| 3 | * |
| 4 | * Copyright (C) 2013, Intel Corporation. All rights reserved. |
| 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 version |
| 8 | * 2 as published by the Free Software Foundation. |
| 9 | * |
| 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. |
| 14 | * |
| 15 | */ |
| 16 | |
| 17 | #include <linux/module.h> |
| 18 | #include <linux/dma-mapping.h> |
| 19 | #include <linux/slab.h> |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 20 | #include <linux/delay.h> |
Liam Girdwood | 2e4f7591 | 2014-10-29 17:40:43 +0000 | [diff] [blame] | 21 | #include <linux/pm_runtime.h> |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 22 | #include <asm/page.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> |
| 31 | |
| 32 | #include "sst-haswell-ipc.h" |
| 33 | #include "sst-dsp-priv.h" |
| 34 | #include "sst-dsp.h" |
| 35 | |
| 36 | #define HSW_PCM_COUNT 6 |
| 37 | #define HSW_VOLUME_MAX 0x7FFFFFFF /* 0dB */ |
| 38 | |
Libin Yang | 1b00699 | 2015-02-10 10:02:47 +0800 | [diff] [blame] | 39 | #define SST_OLD_POSITION(d, r, o) ((d) + \ |
| 40 | frames_to_bytes(r, o)) |
| 41 | #define SST_SAMPLES(r, x) (bytes_to_samples(r, \ |
| 42 | frames_to_bytes(r, (x)))) |
| 43 | |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 44 | /* simple volume table */ |
| 45 | static const u32 volume_map[] = { |
| 46 | HSW_VOLUME_MAX >> 30, |
| 47 | HSW_VOLUME_MAX >> 29, |
| 48 | HSW_VOLUME_MAX >> 28, |
| 49 | HSW_VOLUME_MAX >> 27, |
| 50 | HSW_VOLUME_MAX >> 26, |
| 51 | HSW_VOLUME_MAX >> 25, |
| 52 | HSW_VOLUME_MAX >> 24, |
| 53 | HSW_VOLUME_MAX >> 23, |
| 54 | HSW_VOLUME_MAX >> 22, |
| 55 | HSW_VOLUME_MAX >> 21, |
| 56 | HSW_VOLUME_MAX >> 20, |
| 57 | HSW_VOLUME_MAX >> 19, |
| 58 | HSW_VOLUME_MAX >> 18, |
| 59 | HSW_VOLUME_MAX >> 17, |
| 60 | HSW_VOLUME_MAX >> 16, |
| 61 | HSW_VOLUME_MAX >> 15, |
| 62 | HSW_VOLUME_MAX >> 14, |
| 63 | HSW_VOLUME_MAX >> 13, |
| 64 | HSW_VOLUME_MAX >> 12, |
| 65 | HSW_VOLUME_MAX >> 11, |
| 66 | HSW_VOLUME_MAX >> 10, |
| 67 | HSW_VOLUME_MAX >> 9, |
| 68 | HSW_VOLUME_MAX >> 8, |
| 69 | HSW_VOLUME_MAX >> 7, |
| 70 | HSW_VOLUME_MAX >> 6, |
| 71 | HSW_VOLUME_MAX >> 5, |
| 72 | HSW_VOLUME_MAX >> 4, |
| 73 | HSW_VOLUME_MAX >> 3, |
| 74 | HSW_VOLUME_MAX >> 2, |
| 75 | HSW_VOLUME_MAX >> 1, |
| 76 | HSW_VOLUME_MAX >> 0, |
| 77 | }; |
| 78 | |
| 79 | #define HSW_PCM_PERIODS_MAX 64 |
| 80 | #define HSW_PCM_PERIODS_MIN 2 |
| 81 | |
Liam Girdwood | 2e4f7591 | 2014-10-29 17:40:43 +0000 | [diff] [blame] | 82 | #define HSW_PCM_DAI_ID_SYSTEM 0 |
| 83 | #define HSW_PCM_DAI_ID_OFFLOAD0 1 |
| 84 | #define HSW_PCM_DAI_ID_OFFLOAD1 2 |
| 85 | #define HSW_PCM_DAI_ID_LOOPBACK 3 |
Liam Girdwood | 2e4f7591 | 2014-10-29 17:40:43 +0000 | [diff] [blame] | 86 | |
| 87 | |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 88 | static const struct snd_pcm_hardware hsw_pcm_hardware = { |
| 89 | .info = SNDRV_PCM_INFO_MMAP | |
| 90 | SNDRV_PCM_INFO_MMAP_VALID | |
| 91 | SNDRV_PCM_INFO_INTERLEAVED | |
| 92 | SNDRV_PCM_INFO_PAUSE | |
| 93 | SNDRV_PCM_INFO_RESUME | |
Libin Yang | 9fd3781 | 2015-02-17 12:28:23 +0800 | [diff] [blame] | 94 | SNDRV_PCM_INFO_NO_PERIOD_WAKEUP | |
| 95 | SNDRV_PCM_INFO_DRAIN_TRIGGER, |
Jie Yang | 8e89761 | 2014-07-14 17:37:36 +0800 | [diff] [blame] | 96 | .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE | |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 97 | SNDRV_PCM_FMTBIT_S32_LE, |
| 98 | .period_bytes_min = PAGE_SIZE, |
| 99 | .period_bytes_max = (HSW_PCM_PERIODS_MAX / HSW_PCM_PERIODS_MIN) * PAGE_SIZE, |
| 100 | .periods_min = HSW_PCM_PERIODS_MIN, |
| 101 | .periods_max = HSW_PCM_PERIODS_MAX, |
| 102 | .buffer_bytes_max = HSW_PCM_PERIODS_MAX * PAGE_SIZE, |
| 103 | }; |
| 104 | |
Liam Girdwood | e9600bc | 2014-10-28 17:37:12 +0000 | [diff] [blame] | 105 | struct hsw_pcm_module_map { |
| 106 | int dai_id; |
Jie Yang | 98b9c1d | 2015-01-08 14:32:20 +0800 | [diff] [blame] | 107 | int stream; |
Liam Girdwood | e9600bc | 2014-10-28 17:37:12 +0000 | [diff] [blame] | 108 | enum sst_hsw_module_id mod_id; |
| 109 | }; |
| 110 | |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 111 | /* private data for each PCM DSP stream */ |
| 112 | struct hsw_pcm_data { |
| 113 | int dai_id; |
| 114 | struct sst_hsw_stream *stream; |
Liam Girdwood | e9600bc | 2014-10-28 17:37:12 +0000 | [diff] [blame] | 115 | struct sst_module_runtime *runtime; |
Liam Girdwood | 2e4f7591 | 2014-10-29 17:40:43 +0000 | [diff] [blame] | 116 | struct sst_module_runtime_context context; |
| 117 | struct snd_pcm *hsw_pcm; |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 118 | u32 volume[2]; |
| 119 | struct snd_pcm_substream *substream; |
| 120 | struct snd_compr_stream *cstream; |
| 121 | unsigned int wpos; |
| 122 | struct mutex mutex; |
Liam Girdwood | 916152c | 2014-05-02 16:56:32 +0100 | [diff] [blame] | 123 | bool allocated; |
Liam Girdwood | e9600bc | 2014-10-28 17:37:12 +0000 | [diff] [blame] | 124 | int persistent_offset; |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 125 | }; |
| 126 | |
Liam Girdwood | 2e4f7591 | 2014-10-29 17:40:43 +0000 | [diff] [blame] | 127 | enum hsw_pm_state { |
Jie Yang | cd311dd | 2015-02-05 22:56:48 +0800 | [diff] [blame] | 128 | HSW_PM_STATE_D0 = 0, |
| 129 | HSW_PM_STATE_RTD3 = 1, |
| 130 | HSW_PM_STATE_D3 = 2, |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 131 | }; |
| 132 | |
| 133 | /* private data for the driver */ |
| 134 | struct hsw_priv_data { |
| 135 | /* runtime DSP */ |
| 136 | struct sst_hsw *hsw; |
Liam Girdwood | 2e4f7591 | 2014-10-29 17:40:43 +0000 | [diff] [blame] | 137 | struct device *dev; |
| 138 | enum hsw_pm_state pm_state; |
| 139 | struct snd_soc_card *soc_card; |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 140 | |
| 141 | /* page tables */ |
Liam Girdwood | 0b708c8 | 2014-05-02 16:56:30 +0100 | [diff] [blame] | 142 | struct snd_dma_buffer dmab[HSW_PCM_COUNT][2]; |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 143 | |
| 144 | /* DAI data */ |
Jie Yang | 7ff9d67 | 2015-01-09 14:36:36 +0800 | [diff] [blame] | 145 | struct hsw_pcm_data pcm[HSW_PCM_COUNT][2]; |
| 146 | }; |
| 147 | |
| 148 | |
| 149 | /* static mappings between PCMs and modules - may be dynamic in future */ |
| 150 | static struct hsw_pcm_module_map mod_map[] = { |
| 151 | {HSW_PCM_DAI_ID_SYSTEM, 0, SST_HSW_MODULE_PCM_SYSTEM}, |
| 152 | {HSW_PCM_DAI_ID_OFFLOAD0, 0, SST_HSW_MODULE_PCM}, |
| 153 | {HSW_PCM_DAI_ID_OFFLOAD1, 0, SST_HSW_MODULE_PCM}, |
| 154 | {HSW_PCM_DAI_ID_LOOPBACK, 1, SST_HSW_MODULE_PCM_REFERENCE}, |
| 155 | {HSW_PCM_DAI_ID_SYSTEM, 1, SST_HSW_MODULE_PCM_CAPTURE}, |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 156 | }; |
| 157 | |
Liam Girdwood | 916152c | 2014-05-02 16:56:32 +0100 | [diff] [blame] | 158 | static u32 hsw_notify_pointer(struct sst_hsw_stream *stream, void *data); |
| 159 | |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 160 | static inline u32 hsw_mixer_to_ipc(unsigned int value) |
| 161 | { |
| 162 | if (value >= ARRAY_SIZE(volume_map)) |
| 163 | return volume_map[0]; |
| 164 | else |
| 165 | return volume_map[value]; |
| 166 | } |
| 167 | |
| 168 | static inline unsigned int hsw_ipc_to_mixer(u32 value) |
| 169 | { |
| 170 | int i; |
| 171 | |
| 172 | for (i = 0; i < ARRAY_SIZE(volume_map); i++) { |
| 173 | if (volume_map[i] >= value) |
| 174 | return i; |
| 175 | } |
| 176 | |
| 177 | return i - 1; |
| 178 | } |
| 179 | |
| 180 | static int hsw_stream_volume_put(struct snd_kcontrol *kcontrol, |
| 181 | struct snd_ctl_elem_value *ucontrol) |
| 182 | { |
Liam Girdwood | 2e4f7591 | 2014-10-29 17:40:43 +0000 | [diff] [blame] | 183 | struct snd_soc_platform *platform = snd_soc_kcontrol_platform(kcontrol); |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 184 | struct soc_mixer_control *mc = |
| 185 | (struct soc_mixer_control *)kcontrol->private_value; |
Liam Girdwood | 2e4f7591 | 2014-10-29 17:40:43 +0000 | [diff] [blame] | 186 | struct hsw_priv_data *pdata = |
| 187 | snd_soc_platform_get_drvdata(platform); |
Jie Yang | 7ff9d67 | 2015-01-09 14:36:36 +0800 | [diff] [blame] | 188 | struct hsw_pcm_data *pcm_data; |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 189 | struct sst_hsw *hsw = pdata->hsw; |
| 190 | u32 volume; |
Jie Yang | 7ff9d67 | 2015-01-09 14:36:36 +0800 | [diff] [blame] | 191 | int dai, stream; |
| 192 | |
| 193 | dai = mod_map[mc->reg].dai_id; |
| 194 | stream = mod_map[mc->reg].stream; |
| 195 | pcm_data = &pdata->pcm[dai][stream]; |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 196 | |
| 197 | mutex_lock(&pcm_data->mutex); |
Liam Girdwood | 2e4f7591 | 2014-10-29 17:40:43 +0000 | [diff] [blame] | 198 | pm_runtime_get_sync(pdata->dev); |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 199 | |
| 200 | if (!pcm_data->stream) { |
| 201 | pcm_data->volume[0] = |
| 202 | hsw_mixer_to_ipc(ucontrol->value.integer.value[0]); |
| 203 | pcm_data->volume[1] = |
| 204 | hsw_mixer_to_ipc(ucontrol->value.integer.value[1]); |
Liam Girdwood | 2e4f7591 | 2014-10-29 17:40:43 +0000 | [diff] [blame] | 205 | pm_runtime_mark_last_busy(pdata->dev); |
| 206 | pm_runtime_put_autosuspend(pdata->dev); |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 207 | mutex_unlock(&pcm_data->mutex); |
| 208 | return 0; |
| 209 | } |
| 210 | |
| 211 | if (ucontrol->value.integer.value[0] == |
| 212 | ucontrol->value.integer.value[1]) { |
| 213 | volume = hsw_mixer_to_ipc(ucontrol->value.integer.value[0]); |
Jie Yang | f1e5982 | 2014-11-25 21:00:53 +0800 | [diff] [blame] | 214 | /* apply volume value to all channels */ |
| 215 | sst_hsw_stream_set_volume(hsw, pcm_data->stream, 0, SST_HSW_CHANNELS_ALL, volume); |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 216 | } else { |
| 217 | volume = hsw_mixer_to_ipc(ucontrol->value.integer.value[0]); |
| 218 | sst_hsw_stream_set_volume(hsw, pcm_data->stream, 0, 0, volume); |
| 219 | volume = hsw_mixer_to_ipc(ucontrol->value.integer.value[1]); |
| 220 | sst_hsw_stream_set_volume(hsw, pcm_data->stream, 0, 1, volume); |
| 221 | } |
| 222 | |
Liam Girdwood | 2e4f7591 | 2014-10-29 17:40:43 +0000 | [diff] [blame] | 223 | pm_runtime_mark_last_busy(pdata->dev); |
| 224 | pm_runtime_put_autosuspend(pdata->dev); |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 225 | mutex_unlock(&pcm_data->mutex); |
| 226 | return 0; |
| 227 | } |
| 228 | |
| 229 | static int hsw_stream_volume_get(struct snd_kcontrol *kcontrol, |
| 230 | struct snd_ctl_elem_value *ucontrol) |
| 231 | { |
Liam Girdwood | 2e4f7591 | 2014-10-29 17:40:43 +0000 | [diff] [blame] | 232 | struct snd_soc_platform *platform = snd_soc_kcontrol_platform(kcontrol); |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 233 | struct soc_mixer_control *mc = |
| 234 | (struct soc_mixer_control *)kcontrol->private_value; |
Liam Girdwood | 2e4f7591 | 2014-10-29 17:40:43 +0000 | [diff] [blame] | 235 | struct hsw_priv_data *pdata = |
| 236 | snd_soc_platform_get_drvdata(platform); |
Jie Yang | 7ff9d67 | 2015-01-09 14:36:36 +0800 | [diff] [blame] | 237 | struct hsw_pcm_data *pcm_data; |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 238 | struct sst_hsw *hsw = pdata->hsw; |
| 239 | u32 volume; |
Jie Yang | 7ff9d67 | 2015-01-09 14:36:36 +0800 | [diff] [blame] | 240 | int dai, stream; |
| 241 | |
| 242 | dai = mod_map[mc->reg].dai_id; |
| 243 | stream = mod_map[mc->reg].stream; |
| 244 | pcm_data = &pdata->pcm[dai][stream]; |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 245 | |
| 246 | mutex_lock(&pcm_data->mutex); |
Liam Girdwood | 2e4f7591 | 2014-10-29 17:40:43 +0000 | [diff] [blame] | 247 | pm_runtime_get_sync(pdata->dev); |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 248 | |
| 249 | if (!pcm_data->stream) { |
| 250 | ucontrol->value.integer.value[0] = |
| 251 | hsw_ipc_to_mixer(pcm_data->volume[0]); |
| 252 | ucontrol->value.integer.value[1] = |
| 253 | hsw_ipc_to_mixer(pcm_data->volume[1]); |
Liam Girdwood | 2e4f7591 | 2014-10-29 17:40:43 +0000 | [diff] [blame] | 254 | pm_runtime_mark_last_busy(pdata->dev); |
| 255 | pm_runtime_put_autosuspend(pdata->dev); |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 256 | mutex_unlock(&pcm_data->mutex); |
| 257 | return 0; |
| 258 | } |
| 259 | |
| 260 | sst_hsw_stream_get_volume(hsw, pcm_data->stream, 0, 0, &volume); |
| 261 | ucontrol->value.integer.value[0] = hsw_ipc_to_mixer(volume); |
| 262 | sst_hsw_stream_get_volume(hsw, pcm_data->stream, 0, 1, &volume); |
| 263 | ucontrol->value.integer.value[1] = hsw_ipc_to_mixer(volume); |
Liam Girdwood | 2e4f7591 | 2014-10-29 17:40:43 +0000 | [diff] [blame] | 264 | |
| 265 | pm_runtime_mark_last_busy(pdata->dev); |
| 266 | pm_runtime_put_autosuspend(pdata->dev); |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 267 | mutex_unlock(&pcm_data->mutex); |
| 268 | |
| 269 | return 0; |
| 270 | } |
| 271 | |
| 272 | static int hsw_volume_put(struct snd_kcontrol *kcontrol, |
| 273 | struct snd_ctl_elem_value *ucontrol) |
| 274 | { |
Liam Girdwood | 2e4f7591 | 2014-10-29 17:40:43 +0000 | [diff] [blame] | 275 | struct snd_soc_platform *platform = snd_soc_kcontrol_platform(kcontrol); |
| 276 | struct hsw_priv_data *pdata = snd_soc_platform_get_drvdata(platform); |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 277 | struct sst_hsw *hsw = pdata->hsw; |
| 278 | u32 volume; |
| 279 | |
Liam Girdwood | 2e4f7591 | 2014-10-29 17:40:43 +0000 | [diff] [blame] | 280 | pm_runtime_get_sync(pdata->dev); |
| 281 | |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 282 | if (ucontrol->value.integer.value[0] == |
| 283 | ucontrol->value.integer.value[1]) { |
| 284 | |
| 285 | volume = hsw_mixer_to_ipc(ucontrol->value.integer.value[0]); |
Jie Yang | f1e5982 | 2014-11-25 21:00:53 +0800 | [diff] [blame] | 286 | sst_hsw_mixer_set_volume(hsw, 0, SST_HSW_CHANNELS_ALL, volume); |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 287 | |
| 288 | } else { |
| 289 | volume = hsw_mixer_to_ipc(ucontrol->value.integer.value[0]); |
| 290 | sst_hsw_mixer_set_volume(hsw, 0, 0, volume); |
| 291 | |
| 292 | volume = hsw_mixer_to_ipc(ucontrol->value.integer.value[1]); |
| 293 | sst_hsw_mixer_set_volume(hsw, 0, 1, volume); |
| 294 | } |
| 295 | |
Liam Girdwood | 2e4f7591 | 2014-10-29 17:40:43 +0000 | [diff] [blame] | 296 | pm_runtime_mark_last_busy(pdata->dev); |
| 297 | pm_runtime_put_autosuspend(pdata->dev); |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 298 | return 0; |
| 299 | } |
| 300 | |
| 301 | static int hsw_volume_get(struct snd_kcontrol *kcontrol, |
| 302 | struct snd_ctl_elem_value *ucontrol) |
| 303 | { |
Liam Girdwood | 2e4f7591 | 2014-10-29 17:40:43 +0000 | [diff] [blame] | 304 | struct snd_soc_platform *platform = snd_soc_kcontrol_platform(kcontrol); |
| 305 | struct hsw_priv_data *pdata = snd_soc_platform_get_drvdata(platform); |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 306 | struct sst_hsw *hsw = pdata->hsw; |
| 307 | unsigned int volume = 0; |
| 308 | |
Liam Girdwood | 2e4f7591 | 2014-10-29 17:40:43 +0000 | [diff] [blame] | 309 | pm_runtime_get_sync(pdata->dev); |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 310 | sst_hsw_mixer_get_volume(hsw, 0, 0, &volume); |
| 311 | ucontrol->value.integer.value[0] = hsw_ipc_to_mixer(volume); |
| 312 | |
| 313 | sst_hsw_mixer_get_volume(hsw, 0, 1, &volume); |
| 314 | ucontrol->value.integer.value[1] = hsw_ipc_to_mixer(volume); |
| 315 | |
Liam Girdwood | 2e4f7591 | 2014-10-29 17:40:43 +0000 | [diff] [blame] | 316 | pm_runtime_mark_last_busy(pdata->dev); |
| 317 | pm_runtime_put_autosuspend(pdata->dev); |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 318 | return 0; |
| 319 | } |
| 320 | |
Lu, Han | 76c07b8 | 2015-03-12 13:53:00 +0800 | [diff] [blame] | 321 | static int hsw_waves_switch_get(struct snd_kcontrol *kcontrol, |
| 322 | struct snd_ctl_elem_value *ucontrol) |
| 323 | { |
| 324 | struct snd_soc_platform *platform = snd_soc_kcontrol_platform(kcontrol); |
| 325 | struct hsw_priv_data *pdata = snd_soc_platform_get_drvdata(platform); |
| 326 | struct sst_hsw *hsw = pdata->hsw; |
| 327 | enum sst_hsw_module_id id = SST_HSW_MODULE_WAVES; |
| 328 | |
| 329 | ucontrol->value.integer.value[0] = |
| 330 | (sst_hsw_is_module_active(hsw, id) || |
| 331 | sst_hsw_is_module_enabled_rtd3(hsw, id)); |
| 332 | return 0; |
| 333 | } |
| 334 | |
| 335 | static int hsw_waves_switch_put(struct snd_kcontrol *kcontrol, |
| 336 | struct snd_ctl_elem_value *ucontrol) |
| 337 | { |
| 338 | struct snd_soc_platform *platform = snd_soc_kcontrol_platform(kcontrol); |
| 339 | struct hsw_priv_data *pdata = snd_soc_platform_get_drvdata(platform); |
| 340 | struct sst_hsw *hsw = pdata->hsw; |
| 341 | int ret = 0; |
| 342 | enum sst_hsw_module_id id = SST_HSW_MODULE_WAVES; |
| 343 | bool switch_on = (bool)ucontrol->value.integer.value[0]; |
| 344 | |
| 345 | /* if module is in RAM on the DSP, apply user settings to module through |
| 346 | * ipc. If module is not in RAM on the DSP, store user setting for |
| 347 | * track */ |
| 348 | if (sst_hsw_is_module_loaded(hsw, id)) { |
| 349 | if (switch_on == sst_hsw_is_module_active(hsw, id)) |
| 350 | return 0; |
| 351 | |
| 352 | if (switch_on) |
| 353 | ret = sst_hsw_module_enable(hsw, id, 0); |
| 354 | else |
| 355 | ret = sst_hsw_module_disable(hsw, id, 0); |
| 356 | } else { |
| 357 | if (switch_on == sst_hsw_is_module_enabled_rtd3(hsw, id)) |
| 358 | return 0; |
| 359 | |
| 360 | if (switch_on) |
| 361 | sst_hsw_set_module_enabled_rtd3(hsw, id); |
| 362 | else |
| 363 | sst_hsw_set_module_disabled_rtd3(hsw, id); |
| 364 | } |
| 365 | |
| 366 | return ret; |
| 367 | } |
| 368 | |
Lu, Han | 3814c20 | 2015-03-12 13:53:02 +0800 | [diff] [blame] | 369 | static int hsw_waves_param_get(struct snd_kcontrol *kcontrol, |
| 370 | struct snd_ctl_elem_value *ucontrol) |
| 371 | { |
| 372 | struct snd_soc_platform *platform = snd_soc_kcontrol_platform(kcontrol); |
| 373 | struct hsw_priv_data *pdata = snd_soc_platform_get_drvdata(platform); |
| 374 | struct sst_hsw *hsw = pdata->hsw; |
| 375 | |
| 376 | /* return a matching line from param buffer */ |
| 377 | return sst_hsw_load_param_line(hsw, ucontrol->value.bytes.data); |
| 378 | } |
| 379 | |
| 380 | static int hsw_waves_param_put(struct snd_kcontrol *kcontrol, |
| 381 | struct snd_ctl_elem_value *ucontrol) |
| 382 | { |
| 383 | struct snd_soc_platform *platform = snd_soc_kcontrol_platform(kcontrol); |
| 384 | struct hsw_priv_data *pdata = snd_soc_platform_get_drvdata(platform); |
| 385 | struct sst_hsw *hsw = pdata->hsw; |
| 386 | int ret; |
| 387 | enum sst_hsw_module_id id = SST_HSW_MODULE_WAVES; |
| 388 | int param_id = ucontrol->value.bytes.data[0]; |
| 389 | int param_size = WAVES_PARAM_COUNT; |
| 390 | |
| 391 | /* clear param buffer and reset buffer index */ |
| 392 | if (param_id == 0xFF) { |
| 393 | sst_hsw_reset_param_buf(hsw); |
| 394 | return 0; |
| 395 | } |
| 396 | |
| 397 | /* store params into buffer */ |
| 398 | ret = sst_hsw_store_param_line(hsw, ucontrol->value.bytes.data); |
| 399 | if (ret < 0) |
| 400 | return ret; |
| 401 | |
Lu, Han | 5d5b275 | 2015-03-19 08:38:00 +0800 | [diff] [blame^] | 402 | if (sst_hsw_is_module_active(hsw, id)) |
Lu, Han | 3814c20 | 2015-03-12 13:53:02 +0800 | [diff] [blame] | 403 | ret = sst_hsw_module_set_param(hsw, id, 0, param_id, |
| 404 | param_size, ucontrol->value.bytes.data); |
Lu, Han | 3814c20 | 2015-03-12 13:53:02 +0800 | [diff] [blame] | 405 | return ret; |
| 406 | } |
| 407 | |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 408 | /* TLV used by both global and stream volumes */ |
| 409 | static const DECLARE_TLV_DB_SCALE(hsw_vol_tlv, -9000, 300, 1); |
| 410 | |
| 411 | /* System Pin has no volume control */ |
| 412 | static const struct snd_kcontrol_new hsw_volume_controls[] = { |
| 413 | /* Global DSP volume */ |
| 414 | SOC_DOUBLE_EXT_TLV("Master Playback Volume", 0, 0, 8, |
Jie Yang | c5f0406 | 2014-11-28 10:41:28 +0800 | [diff] [blame] | 415 | ARRAY_SIZE(volume_map) - 1, 0, |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 416 | hsw_volume_get, hsw_volume_put, hsw_vol_tlv), |
| 417 | /* Offload 0 volume */ |
| 418 | SOC_DOUBLE_EXT_TLV("Media0 Playback Volume", 1, 0, 8, |
Jie Yang | c5f0406 | 2014-11-28 10:41:28 +0800 | [diff] [blame] | 419 | ARRAY_SIZE(volume_map) - 1, 0, |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 420 | hsw_stream_volume_get, hsw_stream_volume_put, hsw_vol_tlv), |
| 421 | /* Offload 1 volume */ |
| 422 | SOC_DOUBLE_EXT_TLV("Media1 Playback Volume", 2, 0, 8, |
Jie Yang | c5f0406 | 2014-11-28 10:41:28 +0800 | [diff] [blame] | 423 | ARRAY_SIZE(volume_map) - 1, 0, |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 424 | hsw_stream_volume_get, hsw_stream_volume_put, hsw_vol_tlv), |
| 425 | /* Mic Capture volume */ |
Jie Yang | 7ff9d67 | 2015-01-09 14:36:36 +0800 | [diff] [blame] | 426 | SOC_DOUBLE_EXT_TLV("Mic Capture Volume", 4, 0, 8, |
Jie Yang | c5f0406 | 2014-11-28 10:41:28 +0800 | [diff] [blame] | 427 | ARRAY_SIZE(volume_map) - 1, 0, |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 428 | hsw_stream_volume_get, hsw_stream_volume_put, hsw_vol_tlv), |
Lu, Han | 76c07b8 | 2015-03-12 13:53:00 +0800 | [diff] [blame] | 429 | /* enable/disable module waves */ |
| 430 | SOC_SINGLE_BOOL_EXT("Waves Switch", 0, |
| 431 | hsw_waves_switch_get, hsw_waves_switch_put), |
Lu, Han | 3814c20 | 2015-03-12 13:53:02 +0800 | [diff] [blame] | 432 | /* set parameters to module waves */ |
| 433 | SND_SOC_BYTES_EXT("Waves Set Param", WAVES_PARAM_COUNT, |
| 434 | hsw_waves_param_get, hsw_waves_param_put), |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 435 | }; |
| 436 | |
| 437 | /* Create DMA buffer page table for DSP */ |
Liam Girdwood | 0b708c8 | 2014-05-02 16:56:30 +0100 | [diff] [blame] | 438 | static int create_adsp_page_table(struct snd_pcm_substream *substream, |
| 439 | struct hsw_priv_data *pdata, struct snd_soc_pcm_runtime *rtd, |
| 440 | unsigned char *dma_area, size_t size, int pcm) |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 441 | { |
Liam Girdwood | 0b708c8 | 2014-05-02 16:56:30 +0100 | [diff] [blame] | 442 | struct snd_dma_buffer *dmab = snd_pcm_get_dma_buf(substream); |
| 443 | int i, pages, stream = substream->stream; |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 444 | |
Liam Girdwood | 0b708c8 | 2014-05-02 16:56:30 +0100 | [diff] [blame] | 445 | pages = snd_sgbuf_aligned_pages(size); |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 446 | |
| 447 | dev_dbg(rtd->dev, "generating page table for %p size 0x%zu pages %d\n", |
| 448 | dma_area, size, pages); |
| 449 | |
| 450 | for (i = 0; i < pages; i++) { |
| 451 | u32 idx = (((i << 2) + i)) >> 1; |
Liam Girdwood | 0b708c8 | 2014-05-02 16:56:30 +0100 | [diff] [blame] | 452 | u32 pfn = snd_sgbuf_get_addr(dmab, i * PAGE_SIZE) >> PAGE_SHIFT; |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 453 | u32 *pg_table; |
| 454 | |
| 455 | dev_dbg(rtd->dev, "pfn i %i idx %d pfn %x\n", i, idx, pfn); |
| 456 | |
Liam Girdwood | 0b708c8 | 2014-05-02 16:56:30 +0100 | [diff] [blame] | 457 | pg_table = (u32 *)(pdata->dmab[pcm][stream].area + idx); |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 458 | |
| 459 | if (i & 1) |
| 460 | *pg_table |= (pfn << 4); |
| 461 | else |
| 462 | *pg_table |= pfn; |
| 463 | } |
| 464 | |
| 465 | return 0; |
| 466 | } |
| 467 | |
| 468 | /* this may get called several times by oss emulation */ |
| 469 | static int hsw_pcm_hw_params(struct snd_pcm_substream *substream, |
| 470 | struct snd_pcm_hw_params *params) |
| 471 | { |
| 472 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 473 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 474 | struct hsw_priv_data *pdata = |
| 475 | snd_soc_platform_get_drvdata(rtd->platform); |
Jie Yang | 7ff9d67 | 2015-01-09 14:36:36 +0800 | [diff] [blame] | 476 | struct hsw_pcm_data *pcm_data; |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 477 | struct sst_hsw *hsw = pdata->hsw; |
| 478 | struct sst_module *module_data; |
| 479 | struct sst_dsp *dsp; |
Liam Girdwood | 0b708c8 | 2014-05-02 16:56:30 +0100 | [diff] [blame] | 480 | struct snd_dma_buffer *dmab; |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 481 | enum sst_hsw_stream_type stream_type; |
| 482 | enum sst_hsw_stream_path_id path_id; |
| 483 | u32 rate, bits, map, pages, module_id; |
| 484 | u8 channels; |
Jie Yang | 7ff9d67 | 2015-01-09 14:36:36 +0800 | [diff] [blame] | 485 | int ret, dai; |
| 486 | |
| 487 | dai = mod_map[rtd->cpu_dai->id].dai_id; |
| 488 | pcm_data = &pdata->pcm[dai][substream->stream]; |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 489 | |
Liam Girdwood | 916152c | 2014-05-02 16:56:32 +0100 | [diff] [blame] | 490 | /* check if we are being called a subsequent time */ |
| 491 | if (pcm_data->allocated) { |
| 492 | ret = sst_hsw_stream_reset(hsw, pcm_data->stream); |
| 493 | if (ret < 0) |
| 494 | dev_dbg(rtd->dev, "error: reset stream failed %d\n", |
| 495 | ret); |
| 496 | |
| 497 | ret = sst_hsw_stream_free(hsw, pcm_data->stream); |
| 498 | if (ret < 0) { |
| 499 | dev_dbg(rtd->dev, "error: free stream failed %d\n", |
| 500 | ret); |
| 501 | return ret; |
| 502 | } |
| 503 | pcm_data->allocated = false; |
| 504 | |
| 505 | pcm_data->stream = sst_hsw_stream_new(hsw, rtd->cpu_dai->id, |
| 506 | hsw_notify_pointer, pcm_data); |
| 507 | if (pcm_data->stream == NULL) { |
| 508 | dev_err(rtd->dev, "error: failed to create stream\n"); |
| 509 | return -EINVAL; |
| 510 | } |
| 511 | } |
| 512 | |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 513 | /* stream direction */ |
| 514 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 515 | path_id = SST_HSW_STREAM_PATH_SSP0_OUT; |
| 516 | else |
| 517 | path_id = SST_HSW_STREAM_PATH_SSP0_IN; |
| 518 | |
| 519 | /* DSP stream type depends on DAI ID */ |
| 520 | switch (rtd->cpu_dai->id) { |
| 521 | case 0: |
Jie Yang | 7bb73cb | 2014-11-28 21:52:11 +0800 | [diff] [blame] | 522 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
| 523 | stream_type = SST_HSW_STREAM_TYPE_SYSTEM; |
| 524 | module_id = SST_HSW_MODULE_PCM_SYSTEM; |
| 525 | } |
| 526 | else { |
| 527 | stream_type = SST_HSW_STREAM_TYPE_CAPTURE; |
| 528 | module_id = SST_HSW_MODULE_PCM_CAPTURE; |
| 529 | } |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 530 | break; |
| 531 | case 1: |
| 532 | case 2: |
| 533 | stream_type = SST_HSW_STREAM_TYPE_RENDER; |
| 534 | module_id = SST_HSW_MODULE_PCM; |
| 535 | break; |
| 536 | case 3: |
| 537 | /* path ID needs to be OUT for loopback */ |
| 538 | stream_type = SST_HSW_STREAM_TYPE_LOOPBACK; |
| 539 | path_id = SST_HSW_STREAM_PATH_SSP0_OUT; |
| 540 | module_id = SST_HSW_MODULE_PCM_REFERENCE; |
| 541 | break; |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 542 | default: |
| 543 | dev_err(rtd->dev, "error: invalid DAI ID %d\n", |
| 544 | rtd->cpu_dai->id); |
| 545 | return -EINVAL; |
| 546 | }; |
| 547 | |
| 548 | ret = sst_hsw_stream_format(hsw, pcm_data->stream, |
| 549 | path_id, stream_type, SST_HSW_STREAM_FORMAT_PCM_FORMAT); |
| 550 | if (ret < 0) { |
| 551 | dev_err(rtd->dev, "error: failed to set format %d\n", ret); |
| 552 | return ret; |
| 553 | } |
| 554 | |
| 555 | rate = params_rate(params); |
| 556 | ret = sst_hsw_stream_set_rate(hsw, pcm_data->stream, rate); |
| 557 | if (ret < 0) { |
| 558 | dev_err(rtd->dev, "error: could not set rate %d\n", rate); |
| 559 | return ret; |
| 560 | } |
| 561 | |
| 562 | switch (params_format(params)) { |
| 563 | case SNDRV_PCM_FORMAT_S16_LE: |
| 564 | bits = SST_HSW_DEPTH_16BIT; |
| 565 | sst_hsw_stream_set_valid(hsw, pcm_data->stream, 16); |
| 566 | break; |
| 567 | case SNDRV_PCM_FORMAT_S24_LE: |
Jie Yang | 8e89761 | 2014-07-14 17:37:36 +0800 | [diff] [blame] | 568 | bits = SST_HSW_DEPTH_32BIT; |
| 569 | sst_hsw_stream_set_valid(hsw, pcm_data->stream, 24); |
| 570 | break; |
| 571 | case SNDRV_PCM_FORMAT_S8: |
| 572 | bits = SST_HSW_DEPTH_8BIT; |
| 573 | sst_hsw_stream_set_valid(hsw, pcm_data->stream, 8); |
| 574 | break; |
| 575 | case SNDRV_PCM_FORMAT_S32_LE: |
| 576 | bits = SST_HSW_DEPTH_32BIT; |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 577 | sst_hsw_stream_set_valid(hsw, pcm_data->stream, 32); |
| 578 | break; |
| 579 | default: |
| 580 | dev_err(rtd->dev, "error: invalid format %d\n", |
| 581 | params_format(params)); |
| 582 | return -EINVAL; |
| 583 | } |
| 584 | |
| 585 | ret = sst_hsw_stream_set_bits(hsw, pcm_data->stream, bits); |
| 586 | if (ret < 0) { |
| 587 | dev_err(rtd->dev, "error: could not set bits %d\n", bits); |
| 588 | return ret; |
| 589 | } |
| 590 | |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 591 | channels = params_channels(params); |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 592 | map = create_channel_map(SST_HSW_CHANNEL_CONFIG_STEREO); |
| 593 | sst_hsw_stream_set_map_config(hsw, pcm_data->stream, |
| 594 | map, SST_HSW_CHANNEL_CONFIG_STEREO); |
| 595 | |
| 596 | ret = sst_hsw_stream_set_channels(hsw, pcm_data->stream, channels); |
| 597 | if (ret < 0) { |
| 598 | dev_err(rtd->dev, "error: could not set channels %d\n", |
| 599 | channels); |
| 600 | return ret; |
| 601 | } |
| 602 | |
| 603 | ret = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params)); |
| 604 | if (ret < 0) { |
| 605 | dev_err(rtd->dev, "error: could not allocate %d bytes for PCM %d\n", |
| 606 | params_buffer_bytes(params), ret); |
| 607 | return ret; |
| 608 | } |
| 609 | |
Liam Girdwood | 0b708c8 | 2014-05-02 16:56:30 +0100 | [diff] [blame] | 610 | dmab = snd_pcm_get_dma_buf(substream); |
| 611 | |
| 612 | ret = create_adsp_page_table(substream, pdata, rtd, runtime->dma_area, |
| 613 | runtime->dma_bytes, rtd->cpu_dai->id); |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 614 | if (ret < 0) |
| 615 | return ret; |
| 616 | |
| 617 | sst_hsw_stream_set_style(hsw, pcm_data->stream, |
| 618 | SST_HSW_INTERLEAVING_PER_CHANNEL); |
| 619 | |
| 620 | if (runtime->dma_bytes % PAGE_SIZE) |
| 621 | pages = (runtime->dma_bytes / PAGE_SIZE) + 1; |
| 622 | else |
| 623 | pages = runtime->dma_bytes / PAGE_SIZE; |
| 624 | |
| 625 | ret = sst_hsw_stream_buffer(hsw, pcm_data->stream, |
Liam Girdwood | 0b708c8 | 2014-05-02 16:56:30 +0100 | [diff] [blame] | 626 | pdata->dmab[rtd->cpu_dai->id][substream->stream].addr, |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 627 | pages, runtime->dma_bytes, 0, |
Liam Girdwood | 0b708c8 | 2014-05-02 16:56:30 +0100 | [diff] [blame] | 628 | snd_sgbuf_get_addr(dmab, 0) >> PAGE_SHIFT); |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 629 | if (ret < 0) { |
| 630 | dev_err(rtd->dev, "error: failed to set DMA buffer %d\n", ret); |
| 631 | return ret; |
| 632 | } |
| 633 | |
| 634 | dsp = sst_hsw_get_dsp(hsw); |
| 635 | |
| 636 | module_data = sst_module_get_from_id(dsp, module_id); |
| 637 | if (module_data == NULL) { |
| 638 | dev_err(rtd->dev, "error: failed to get module config\n"); |
| 639 | return -EINVAL; |
| 640 | } |
| 641 | |
Liam Girdwood | e9600bc | 2014-10-28 17:37:12 +0000 | [diff] [blame] | 642 | sst_hsw_stream_set_module_info(hsw, pcm_data->stream, |
| 643 | pcm_data->runtime); |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 644 | |
| 645 | ret = sst_hsw_stream_commit(hsw, pcm_data->stream); |
| 646 | if (ret < 0) { |
| 647 | dev_err(rtd->dev, "error: failed to commit stream %d\n", ret); |
| 648 | return ret; |
| 649 | } |
Jie Yang | f1e5982 | 2014-11-25 21:00:53 +0800 | [diff] [blame] | 650 | |
| 651 | if (!pcm_data->allocated) { |
| 652 | /* Set previous saved volume */ |
| 653 | sst_hsw_stream_set_volume(hsw, pcm_data->stream, 0, |
| 654 | 0, pcm_data->volume[0]); |
| 655 | sst_hsw_stream_set_volume(hsw, pcm_data->stream, 0, |
| 656 | 1, pcm_data->volume[1]); |
| 657 | pcm_data->allocated = true; |
| 658 | } |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 659 | |
| 660 | ret = sst_hsw_stream_pause(hsw, pcm_data->stream, 1); |
| 661 | if (ret < 0) |
| 662 | dev_err(rtd->dev, "error: failed to pause %d\n", ret); |
| 663 | |
| 664 | return 0; |
| 665 | } |
| 666 | |
| 667 | static int hsw_pcm_hw_free(struct snd_pcm_substream *substream) |
| 668 | { |
| 669 | snd_pcm_lib_free_pages(substream); |
| 670 | return 0; |
| 671 | } |
| 672 | |
| 673 | static int hsw_pcm_trigger(struct snd_pcm_substream *substream, int cmd) |
| 674 | { |
| 675 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 676 | struct hsw_priv_data *pdata = |
| 677 | snd_soc_platform_get_drvdata(rtd->platform); |
Jie Yang | 7ff9d67 | 2015-01-09 14:36:36 +0800 | [diff] [blame] | 678 | struct hsw_pcm_data *pcm_data; |
Libin Yang | 1b00699 | 2015-02-10 10:02:47 +0800 | [diff] [blame] | 679 | struct sst_hsw_stream *sst_stream; |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 680 | struct sst_hsw *hsw = pdata->hsw; |
Libin Yang | 1b00699 | 2015-02-10 10:02:47 +0800 | [diff] [blame] | 681 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 682 | snd_pcm_uframes_t pos; |
Jie Yang | 7ff9d67 | 2015-01-09 14:36:36 +0800 | [diff] [blame] | 683 | int dai; |
| 684 | |
| 685 | dai = mod_map[rtd->cpu_dai->id].dai_id; |
| 686 | pcm_data = &pdata->pcm[dai][substream->stream]; |
Libin Yang | 1b00699 | 2015-02-10 10:02:47 +0800 | [diff] [blame] | 687 | sst_stream = pcm_data->stream; |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 688 | |
| 689 | switch (cmd) { |
| 690 | case SNDRV_PCM_TRIGGER_START: |
| 691 | case SNDRV_PCM_TRIGGER_RESUME: |
| 692 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
Libin Yang | 1b00699 | 2015-02-10 10:02:47 +0800 | [diff] [blame] | 693 | sst_hsw_stream_set_silence_start(hsw, sst_stream, false); |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 694 | sst_hsw_stream_resume(hsw, pcm_data->stream, 0); |
| 695 | break; |
| 696 | case SNDRV_PCM_TRIGGER_STOP: |
| 697 | case SNDRV_PCM_TRIGGER_SUSPEND: |
| 698 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
Libin Yang | 1b00699 | 2015-02-10 10:02:47 +0800 | [diff] [blame] | 699 | sst_hsw_stream_set_silence_start(hsw, sst_stream, false); |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 700 | sst_hsw_stream_pause(hsw, pcm_data->stream, 0); |
| 701 | break; |
Libin Yang | 1b00699 | 2015-02-10 10:02:47 +0800 | [diff] [blame] | 702 | case SNDRV_PCM_TRIGGER_DRAIN: |
| 703 | pos = runtime->control->appl_ptr % runtime->buffer_size; |
| 704 | sst_hsw_stream_set_old_position(hsw, pcm_data->stream, pos); |
| 705 | sst_hsw_stream_set_silence_start(hsw, sst_stream, true); |
| 706 | break; |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 707 | default: |
| 708 | break; |
| 709 | } |
| 710 | |
| 711 | return 0; |
| 712 | } |
| 713 | |
| 714 | static u32 hsw_notify_pointer(struct sst_hsw_stream *stream, void *data) |
| 715 | { |
| 716 | struct hsw_pcm_data *pcm_data = data; |
| 717 | struct snd_pcm_substream *substream = pcm_data->substream; |
| 718 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 719 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Libin Yang | 1b00699 | 2015-02-10 10:02:47 +0800 | [diff] [blame] | 720 | struct hsw_priv_data *pdata = |
| 721 | snd_soc_platform_get_drvdata(rtd->platform); |
| 722 | struct sst_hsw *hsw = pdata->hsw; |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 723 | u32 pos; |
Libin Yang | 1b00699 | 2015-02-10 10:02:47 +0800 | [diff] [blame] | 724 | snd_pcm_uframes_t position = bytes_to_frames(runtime, |
| 725 | sst_hsw_get_dsp_position(hsw, pcm_data->stream)); |
| 726 | unsigned char *dma_area = runtime->dma_area; |
| 727 | snd_pcm_uframes_t dma_frames = |
| 728 | bytes_to_frames(runtime, runtime->dma_bytes); |
| 729 | snd_pcm_uframes_t old_position; |
| 730 | ssize_t samples; |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 731 | |
| 732 | pos = frames_to_bytes(runtime, |
| 733 | (runtime->control->appl_ptr % runtime->buffer_size)); |
| 734 | |
Liam Girdwood | 8046249 | 2014-10-16 15:29:17 +0100 | [diff] [blame] | 735 | dev_vdbg(rtd->dev, "PCM: App pointer %d bytes\n", pos); |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 736 | |
Libin Yang | 1b00699 | 2015-02-10 10:02:47 +0800 | [diff] [blame] | 737 | /* SST fw don't know where to stop dma |
| 738 | * So, SST driver need to clean the data which has been consumed |
| 739 | */ |
| 740 | if (dma_area == NULL || dma_frames <= 0 |
| 741 | || (substream->stream == SNDRV_PCM_STREAM_CAPTURE) |
| 742 | || !sst_hsw_stream_get_silence_start(hsw, stream)) { |
| 743 | snd_pcm_period_elapsed(substream); |
| 744 | return pos; |
| 745 | } |
| 746 | |
| 747 | old_position = sst_hsw_stream_get_old_position(hsw, stream); |
| 748 | if (position > old_position) { |
| 749 | if (position < dma_frames) { |
| 750 | samples = SST_SAMPLES(runtime, position - old_position); |
| 751 | snd_pcm_format_set_silence(runtime->format, |
| 752 | SST_OLD_POSITION(dma_area, |
| 753 | runtime, old_position), |
| 754 | samples); |
| 755 | } else |
| 756 | dev_err(rtd->dev, "PCM: position is wrong\n"); |
| 757 | } else { |
| 758 | if (old_position < dma_frames) { |
| 759 | samples = SST_SAMPLES(runtime, |
| 760 | dma_frames - old_position); |
| 761 | snd_pcm_format_set_silence(runtime->format, |
| 762 | SST_OLD_POSITION(dma_area, |
| 763 | runtime, old_position), |
| 764 | samples); |
| 765 | } else |
| 766 | dev_err(rtd->dev, "PCM: dma_bytes is wrong\n"); |
| 767 | if (position < dma_frames) { |
| 768 | samples = SST_SAMPLES(runtime, position); |
| 769 | snd_pcm_format_set_silence(runtime->format, |
| 770 | dma_area, samples); |
| 771 | } else |
| 772 | dev_err(rtd->dev, "PCM: position is wrong\n"); |
| 773 | } |
| 774 | sst_hsw_stream_set_old_position(hsw, stream, position); |
| 775 | |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 776 | /* let alsa know we have play a period */ |
| 777 | snd_pcm_period_elapsed(substream); |
| 778 | return pos; |
| 779 | } |
| 780 | |
| 781 | static snd_pcm_uframes_t hsw_pcm_pointer(struct snd_pcm_substream *substream) |
| 782 | { |
| 783 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 784 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 785 | struct hsw_priv_data *pdata = |
| 786 | snd_soc_platform_get_drvdata(rtd->platform); |
Jie Yang | 7ff9d67 | 2015-01-09 14:36:36 +0800 | [diff] [blame] | 787 | struct hsw_pcm_data *pcm_data; |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 788 | struct sst_hsw *hsw = pdata->hsw; |
| 789 | snd_pcm_uframes_t offset; |
Liam Girdwood | 51b4e24 | 2014-05-02 16:56:33 +0100 | [diff] [blame] | 790 | uint64_t ppos; |
Jie Yang | 7ff9d67 | 2015-01-09 14:36:36 +0800 | [diff] [blame] | 791 | u32 position; |
| 792 | int dai; |
| 793 | |
| 794 | dai = mod_map[rtd->cpu_dai->id].dai_id; |
| 795 | pcm_data = &pdata->pcm[dai][substream->stream]; |
| 796 | position = sst_hsw_get_dsp_position(hsw, pcm_data->stream); |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 797 | |
Liam Girdwood | 51b4e24 | 2014-05-02 16:56:33 +0100 | [diff] [blame] | 798 | offset = bytes_to_frames(runtime, position); |
| 799 | ppos = sst_hsw_get_dsp_presentation_position(hsw, pcm_data->stream); |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 800 | |
Liam Girdwood | 8046249 | 2014-10-16 15:29:17 +0100 | [diff] [blame] | 801 | dev_vdbg(rtd->dev, "PCM: DMA pointer %du bytes, pos %llu\n", |
Liam Girdwood | 51b4e24 | 2014-05-02 16:56:33 +0100 | [diff] [blame] | 802 | position, ppos); |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 803 | return offset; |
| 804 | } |
| 805 | |
| 806 | static int hsw_pcm_open(struct snd_pcm_substream *substream) |
| 807 | { |
| 808 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 809 | struct hsw_priv_data *pdata = |
| 810 | snd_soc_platform_get_drvdata(rtd->platform); |
| 811 | struct hsw_pcm_data *pcm_data; |
| 812 | struct sst_hsw *hsw = pdata->hsw; |
Jie Yang | 7ff9d67 | 2015-01-09 14:36:36 +0800 | [diff] [blame] | 813 | int dai; |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 814 | |
Jie Yang | 7ff9d67 | 2015-01-09 14:36:36 +0800 | [diff] [blame] | 815 | dai = mod_map[rtd->cpu_dai->id].dai_id; |
| 816 | pcm_data = &pdata->pcm[dai][substream->stream]; |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 817 | |
| 818 | mutex_lock(&pcm_data->mutex); |
Liam Girdwood | 2e4f7591 | 2014-10-29 17:40:43 +0000 | [diff] [blame] | 819 | pm_runtime_get_sync(pdata->dev); |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 820 | |
| 821 | snd_soc_pcm_set_drvdata(rtd, pcm_data); |
| 822 | pcm_data->substream = substream; |
| 823 | |
| 824 | snd_soc_set_runtime_hwparams(substream, &hsw_pcm_hardware); |
| 825 | |
| 826 | pcm_data->stream = sst_hsw_stream_new(hsw, rtd->cpu_dai->id, |
| 827 | hsw_notify_pointer, pcm_data); |
| 828 | if (pcm_data->stream == NULL) { |
| 829 | dev_err(rtd->dev, "error: failed to create stream\n"); |
Liam Girdwood | 2e4f7591 | 2014-10-29 17:40:43 +0000 | [diff] [blame] | 830 | pm_runtime_mark_last_busy(pdata->dev); |
| 831 | pm_runtime_put_autosuspend(pdata->dev); |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 832 | mutex_unlock(&pcm_data->mutex); |
| 833 | return -EINVAL; |
| 834 | } |
| 835 | |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 836 | mutex_unlock(&pcm_data->mutex); |
| 837 | return 0; |
| 838 | } |
| 839 | |
| 840 | static int hsw_pcm_close(struct snd_pcm_substream *substream) |
| 841 | { |
| 842 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 843 | struct hsw_priv_data *pdata = |
| 844 | snd_soc_platform_get_drvdata(rtd->platform); |
Jie Yang | 7ff9d67 | 2015-01-09 14:36:36 +0800 | [diff] [blame] | 845 | struct hsw_pcm_data *pcm_data; |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 846 | struct sst_hsw *hsw = pdata->hsw; |
Jie Yang | 7ff9d67 | 2015-01-09 14:36:36 +0800 | [diff] [blame] | 847 | int ret, dai; |
| 848 | |
| 849 | dai = mod_map[rtd->cpu_dai->id].dai_id; |
| 850 | pcm_data = &pdata->pcm[dai][substream->stream]; |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 851 | |
| 852 | mutex_lock(&pcm_data->mutex); |
| 853 | ret = sst_hsw_stream_reset(hsw, pcm_data->stream); |
| 854 | if (ret < 0) { |
| 855 | dev_dbg(rtd->dev, "error: reset stream failed %d\n", ret); |
| 856 | goto out; |
| 857 | } |
| 858 | |
| 859 | ret = sst_hsw_stream_free(hsw, pcm_data->stream); |
| 860 | if (ret < 0) { |
| 861 | dev_dbg(rtd->dev, "error: free stream failed %d\n", ret); |
| 862 | goto out; |
| 863 | } |
Liam Girdwood | 916152c | 2014-05-02 16:56:32 +0100 | [diff] [blame] | 864 | pcm_data->allocated = 0; |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 865 | pcm_data->stream = NULL; |
| 866 | |
| 867 | out: |
Liam Girdwood | 2e4f7591 | 2014-10-29 17:40:43 +0000 | [diff] [blame] | 868 | pm_runtime_mark_last_busy(pdata->dev); |
| 869 | pm_runtime_put_autosuspend(pdata->dev); |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 870 | mutex_unlock(&pcm_data->mutex); |
| 871 | return ret; |
| 872 | } |
| 873 | |
| 874 | static struct snd_pcm_ops hsw_pcm_ops = { |
| 875 | .open = hsw_pcm_open, |
| 876 | .close = hsw_pcm_close, |
| 877 | .ioctl = snd_pcm_lib_ioctl, |
| 878 | .hw_params = hsw_pcm_hw_params, |
| 879 | .hw_free = hsw_pcm_hw_free, |
| 880 | .trigger = hsw_pcm_trigger, |
| 881 | .pointer = hsw_pcm_pointer, |
Liam Girdwood | 0b708c8 | 2014-05-02 16:56:30 +0100 | [diff] [blame] | 882 | .page = snd_pcm_sgbuf_ops_page, |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 883 | }; |
| 884 | |
Liam Girdwood | e9600bc | 2014-10-28 17:37:12 +0000 | [diff] [blame] | 885 | static int hsw_pcm_create_modules(struct hsw_priv_data *pdata) |
| 886 | { |
| 887 | struct sst_hsw *hsw = pdata->hsw; |
| 888 | struct hsw_pcm_data *pcm_data; |
| 889 | int i; |
| 890 | |
| 891 | for (i = 0; i < ARRAY_SIZE(mod_map); i++) { |
Jie Yang | 7ff9d67 | 2015-01-09 14:36:36 +0800 | [diff] [blame] | 892 | pcm_data = &pdata->pcm[mod_map[i].dai_id][mod_map[i].stream]; |
Liam Girdwood | e9600bc | 2014-10-28 17:37:12 +0000 | [diff] [blame] | 893 | |
Liam Girdwood | 2e4f7591 | 2014-10-29 17:40:43 +0000 | [diff] [blame] | 894 | /* create new runtime module, use same offset if recreated */ |
Liam Girdwood | e9600bc | 2014-10-28 17:37:12 +0000 | [diff] [blame] | 895 | pcm_data->runtime = sst_hsw_runtime_module_create(hsw, |
| 896 | mod_map[i].mod_id, pcm_data->persistent_offset); |
| 897 | if (pcm_data->runtime == NULL) |
| 898 | goto err; |
| 899 | pcm_data->persistent_offset = |
| 900 | pcm_data->runtime->persistent_offset; |
| 901 | } |
| 902 | |
Lu, Han | 8c43fc2 | 2015-03-10 10:41:21 +0800 | [diff] [blame] | 903 | /* create runtime blocks for module waves */ |
| 904 | if (sst_hsw_is_module_loaded(hsw, SST_HSW_MODULE_WAVES)) { |
| 905 | pcm_data = &pdata->pcm[HSW_PCM_COUNT-1][0]; |
| 906 | pcm_data->runtime = sst_hsw_runtime_module_create(hsw, |
| 907 | SST_HSW_MODULE_WAVES, pcm_data->persistent_offset); |
| 908 | if (pcm_data->runtime == NULL) |
| 909 | goto err; |
| 910 | pcm_data->persistent_offset = |
| 911 | pcm_data->runtime->persistent_offset; |
| 912 | } |
| 913 | |
Liam Girdwood | e9600bc | 2014-10-28 17:37:12 +0000 | [diff] [blame] | 914 | return 0; |
| 915 | |
| 916 | err: |
| 917 | for (--i; i >= 0; i--) { |
Jie Yang | 7ff9d67 | 2015-01-09 14:36:36 +0800 | [diff] [blame] | 918 | pcm_data = &pdata->pcm[mod_map[i].dai_id][mod_map[i].stream]; |
Liam Girdwood | e9600bc | 2014-10-28 17:37:12 +0000 | [diff] [blame] | 919 | sst_hsw_runtime_module_free(pcm_data->runtime); |
| 920 | } |
| 921 | |
| 922 | return -ENODEV; |
| 923 | } |
| 924 | |
| 925 | static void hsw_pcm_free_modules(struct hsw_priv_data *pdata) |
| 926 | { |
Lu, Han | 8c43fc2 | 2015-03-10 10:41:21 +0800 | [diff] [blame] | 927 | struct sst_hsw *hsw = pdata->hsw; |
Liam Girdwood | e9600bc | 2014-10-28 17:37:12 +0000 | [diff] [blame] | 928 | struct hsw_pcm_data *pcm_data; |
| 929 | int i; |
| 930 | |
| 931 | for (i = 0; i < ARRAY_SIZE(mod_map); i++) { |
Jie Yang | 7ff9d67 | 2015-01-09 14:36:36 +0800 | [diff] [blame] | 932 | pcm_data = &pdata->pcm[mod_map[i].dai_id][mod_map[i].stream]; |
Lu, Han | 8c43fc2 | 2015-03-10 10:41:21 +0800 | [diff] [blame] | 933 | sst_hsw_runtime_module_free(pcm_data->runtime); |
| 934 | } |
| 935 | if (sst_hsw_is_module_loaded(hsw, SST_HSW_MODULE_WAVES)) { |
| 936 | pcm_data = &pdata->pcm[HSW_PCM_COUNT-1][0]; |
Liam Girdwood | e9600bc | 2014-10-28 17:37:12 +0000 | [diff] [blame] | 937 | sst_hsw_runtime_module_free(pcm_data->runtime); |
| 938 | } |
| 939 | } |
| 940 | |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 941 | static int hsw_pcm_new(struct snd_soc_pcm_runtime *rtd) |
| 942 | { |
| 943 | struct snd_pcm *pcm = rtd->pcm; |
Liam Girdwood | 10df350 | 2014-05-02 16:56:31 +0100 | [diff] [blame] | 944 | struct snd_soc_platform *platform = rtd->platform; |
| 945 | struct sst_pdata *pdata = dev_get_platdata(platform->dev); |
Liam Girdwood | 2e4f7591 | 2014-10-29 17:40:43 +0000 | [diff] [blame] | 946 | struct hsw_priv_data *priv_data = dev_get_drvdata(platform->dev); |
Liam Girdwood | 10df350 | 2014-05-02 16:56:31 +0100 | [diff] [blame] | 947 | struct device *dev = pdata->dma_dev; |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 948 | int ret = 0; |
| 949 | |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 950 | if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream || |
| 951 | pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream) { |
| 952 | ret = snd_pcm_lib_preallocate_pages_for_all(pcm, |
Liam Girdwood | 0b708c8 | 2014-05-02 16:56:30 +0100 | [diff] [blame] | 953 | SNDRV_DMA_TYPE_DEV_SG, |
Liam Girdwood | 10df350 | 2014-05-02 16:56:31 +0100 | [diff] [blame] | 954 | dev, |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 955 | hsw_pcm_hardware.buffer_bytes_max, |
| 956 | hsw_pcm_hardware.buffer_bytes_max); |
| 957 | if (ret) { |
| 958 | dev_err(rtd->dev, "dma buffer allocation failed %d\n", |
| 959 | ret); |
| 960 | return ret; |
| 961 | } |
| 962 | } |
Jie Yang | 7ff9d67 | 2015-01-09 14:36:36 +0800 | [diff] [blame] | 963 | if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream) |
| 964 | priv_data->pcm[rtd->cpu_dai->id][SNDRV_PCM_STREAM_PLAYBACK].hsw_pcm = pcm; |
| 965 | if (pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream) |
| 966 | priv_data->pcm[rtd->cpu_dai->id][SNDRV_PCM_STREAM_CAPTURE].hsw_pcm = pcm; |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 967 | |
| 968 | return ret; |
| 969 | } |
| 970 | |
| 971 | #define HSW_FORMATS \ |
Liam Girdwood | 2ccf3bd | 2014-10-16 15:29:14 +0100 | [diff] [blame] | 972 | (SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S16_LE) |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 973 | |
| 974 | static struct snd_soc_dai_driver hsw_dais[] = { |
| 975 | { |
| 976 | .name = "System Pin", |
Liam Girdwood | 2e4f7591 | 2014-10-29 17:40:43 +0000 | [diff] [blame] | 977 | .id = HSW_PCM_DAI_ID_SYSTEM, |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 978 | .playback = { |
| 979 | .stream_name = "System Playback", |
| 980 | .channels_min = 2, |
| 981 | .channels_max = 2, |
| 982 | .rates = SNDRV_PCM_RATE_48000, |
Jie Yang | 8e89761 | 2014-07-14 17:37:36 +0800 | [diff] [blame] | 983 | .formats = SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S16_LE, |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 984 | }, |
Jie Yang | 7bb73cb | 2014-11-28 21:52:11 +0800 | [diff] [blame] | 985 | .capture = { |
| 986 | .stream_name = "Analog Capture", |
| 987 | .channels_min = 2, |
| 988 | .channels_max = 4, |
| 989 | .rates = SNDRV_PCM_RATE_48000, |
| 990 | .formats = SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S16_LE, |
| 991 | }, |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 992 | }, |
| 993 | { |
| 994 | /* PCM */ |
| 995 | .name = "Offload0 Pin", |
Liam Girdwood | 2e4f7591 | 2014-10-29 17:40:43 +0000 | [diff] [blame] | 996 | .id = HSW_PCM_DAI_ID_OFFLOAD0, |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 997 | .playback = { |
| 998 | .stream_name = "Offload0 Playback", |
| 999 | .channels_min = 2, |
| 1000 | .channels_max = 2, |
| 1001 | .rates = SNDRV_PCM_RATE_8000_192000, |
| 1002 | .formats = HSW_FORMATS, |
| 1003 | }, |
| 1004 | }, |
| 1005 | { |
| 1006 | /* PCM */ |
| 1007 | .name = "Offload1 Pin", |
Liam Girdwood | 2e4f7591 | 2014-10-29 17:40:43 +0000 | [diff] [blame] | 1008 | .id = HSW_PCM_DAI_ID_OFFLOAD1, |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 1009 | .playback = { |
| 1010 | .stream_name = "Offload1 Playback", |
| 1011 | .channels_min = 2, |
| 1012 | .channels_max = 2, |
| 1013 | .rates = SNDRV_PCM_RATE_8000_192000, |
| 1014 | .formats = HSW_FORMATS, |
| 1015 | }, |
| 1016 | }, |
| 1017 | { |
| 1018 | .name = "Loopback Pin", |
Liam Girdwood | 2e4f7591 | 2014-10-29 17:40:43 +0000 | [diff] [blame] | 1019 | .id = HSW_PCM_DAI_ID_LOOPBACK, |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 1020 | .capture = { |
| 1021 | .stream_name = "Loopback Capture", |
| 1022 | .channels_min = 2, |
| 1023 | .channels_max = 2, |
Jie Yang | 8e89761 | 2014-07-14 17:37:36 +0800 | [diff] [blame] | 1024 | .rates = SNDRV_PCM_RATE_48000, |
| 1025 | .formats = SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S16_LE, |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 1026 | }, |
| 1027 | }, |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 1028 | }; |
| 1029 | |
| 1030 | static const struct snd_soc_dapm_widget widgets[] = { |
| 1031 | |
| 1032 | /* Backend DAIs */ |
| 1033 | SND_SOC_DAPM_AIF_IN("SSP0 CODEC IN", NULL, 0, SND_SOC_NOPM, 0, 0), |
| 1034 | SND_SOC_DAPM_AIF_OUT("SSP0 CODEC OUT", NULL, 0, SND_SOC_NOPM, 0, 0), |
| 1035 | SND_SOC_DAPM_AIF_IN("SSP1 BT IN", NULL, 0, SND_SOC_NOPM, 0, 0), |
| 1036 | SND_SOC_DAPM_AIF_OUT("SSP1 BT OUT", NULL, 0, SND_SOC_NOPM, 0, 0), |
| 1037 | |
| 1038 | /* Global Playback Mixer */ |
| 1039 | SND_SOC_DAPM_MIXER("Playback VMixer", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 1040 | }; |
| 1041 | |
| 1042 | static const struct snd_soc_dapm_route graph[] = { |
| 1043 | |
| 1044 | /* Playback Mixer */ |
| 1045 | {"Playback VMixer", NULL, "System Playback"}, |
| 1046 | {"Playback VMixer", NULL, "Offload0 Playback"}, |
| 1047 | {"Playback VMixer", NULL, "Offload1 Playback"}, |
| 1048 | |
| 1049 | {"SSP0 CODEC OUT", NULL, "Playback VMixer"}, |
| 1050 | |
| 1051 | {"Analog Capture", NULL, "SSP0 CODEC IN"}, |
| 1052 | }; |
| 1053 | |
| 1054 | static int hsw_pcm_probe(struct snd_soc_platform *platform) |
| 1055 | { |
Lars-Peter Clausen | bd03380 | 2014-08-20 13:08:47 +0200 | [diff] [blame] | 1056 | struct hsw_priv_data *priv_data = snd_soc_platform_get_drvdata(platform); |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 1057 | struct sst_pdata *pdata = dev_get_platdata(platform->dev); |
Liam Girdwood | 2e4f7591 | 2014-10-29 17:40:43 +0000 | [diff] [blame] | 1058 | struct device *dma_dev, *dev; |
Liam Girdwood | 0b708c8 | 2014-05-02 16:56:30 +0100 | [diff] [blame] | 1059 | int i, ret = 0; |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 1060 | |
Liam Girdwood | 2e4f7591 | 2014-10-29 17:40:43 +0000 | [diff] [blame] | 1061 | if (!pdata) |
| 1062 | return -ENODEV; |
| 1063 | |
| 1064 | dev = platform->dev; |
| 1065 | dma_dev = pdata->dma_dev; |
| 1066 | |
Liam Girdwood | 2e4f7591 | 2014-10-29 17:40:43 +0000 | [diff] [blame] | 1067 | priv_data->hsw = pdata->dsp; |
| 1068 | priv_data->dev = platform->dev; |
| 1069 | priv_data->pm_state = HSW_PM_STATE_D0; |
| 1070 | priv_data->soc_card = platform->component.card; |
| 1071 | |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 1072 | /* allocate DSP buffer page tables */ |
| 1073 | for (i = 0; i < ARRAY_SIZE(hsw_dais); i++) { |
| 1074 | |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 1075 | /* playback */ |
| 1076 | if (hsw_dais[i].playback.channels_min) { |
Jie Yang | 7ff9d67 | 2015-01-09 14:36:36 +0800 | [diff] [blame] | 1077 | mutex_init(&priv_data->pcm[i][SNDRV_PCM_STREAM_PLAYBACK].mutex); |
Liam Girdwood | 0b708c8 | 2014-05-02 16:56:30 +0100 | [diff] [blame] | 1078 | ret = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, dma_dev, |
| 1079 | PAGE_SIZE, &priv_data->dmab[i][0]); |
| 1080 | if (ret < 0) |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 1081 | goto err; |
| 1082 | } |
| 1083 | |
| 1084 | /* capture */ |
| 1085 | if (hsw_dais[i].capture.channels_min) { |
Jie Yang | 7ff9d67 | 2015-01-09 14:36:36 +0800 | [diff] [blame] | 1086 | mutex_init(&priv_data->pcm[i][SNDRV_PCM_STREAM_CAPTURE].mutex); |
Liam Girdwood | 0b708c8 | 2014-05-02 16:56:30 +0100 | [diff] [blame] | 1087 | ret = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, dma_dev, |
| 1088 | PAGE_SIZE, &priv_data->dmab[i][1]); |
| 1089 | if (ret < 0) |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 1090 | goto err; |
| 1091 | } |
| 1092 | } |
| 1093 | |
Liam Girdwood | e9600bc | 2014-10-28 17:37:12 +0000 | [diff] [blame] | 1094 | /* allocate runtime modules */ |
Lu, Han | 8c43fc2 | 2015-03-10 10:41:21 +0800 | [diff] [blame] | 1095 | ret = hsw_pcm_create_modules(priv_data); |
| 1096 | if (ret < 0) |
| 1097 | goto err; |
Liam Girdwood | e9600bc | 2014-10-28 17:37:12 +0000 | [diff] [blame] | 1098 | |
Liam Girdwood | 2e4f7591 | 2014-10-29 17:40:43 +0000 | [diff] [blame] | 1099 | /* enable runtime PM with auto suspend */ |
| 1100 | pm_runtime_set_autosuspend_delay(platform->dev, |
| 1101 | SST_RUNTIME_SUSPEND_DELAY); |
| 1102 | pm_runtime_use_autosuspend(platform->dev); |
| 1103 | pm_runtime_enable(platform->dev); |
| 1104 | pm_runtime_idle(platform->dev); |
| 1105 | |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 1106 | return 0; |
| 1107 | |
| 1108 | err: |
| 1109 | for (;i >= 0; i--) { |
| 1110 | if (hsw_dais[i].playback.channels_min) |
Liam Girdwood | 0b708c8 | 2014-05-02 16:56:30 +0100 | [diff] [blame] | 1111 | snd_dma_free_pages(&priv_data->dmab[i][0]); |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 1112 | if (hsw_dais[i].capture.channels_min) |
Liam Girdwood | 0b708c8 | 2014-05-02 16:56:30 +0100 | [diff] [blame] | 1113 | snd_dma_free_pages(&priv_data->dmab[i][1]); |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 1114 | } |
Liam Girdwood | 0b708c8 | 2014-05-02 16:56:30 +0100 | [diff] [blame] | 1115 | return ret; |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 1116 | } |
| 1117 | |
| 1118 | static int hsw_pcm_remove(struct snd_soc_platform *platform) |
| 1119 | { |
| 1120 | struct hsw_priv_data *priv_data = |
| 1121 | snd_soc_platform_get_drvdata(platform); |
| 1122 | int i; |
| 1123 | |
Liam Girdwood | 2e4f7591 | 2014-10-29 17:40:43 +0000 | [diff] [blame] | 1124 | pm_runtime_disable(platform->dev); |
| 1125 | hsw_pcm_free_modules(priv_data); |
| 1126 | |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 1127 | for (i = 0; i < ARRAY_SIZE(hsw_dais); i++) { |
| 1128 | if (hsw_dais[i].playback.channels_min) |
Liam Girdwood | 0b708c8 | 2014-05-02 16:56:30 +0100 | [diff] [blame] | 1129 | snd_dma_free_pages(&priv_data->dmab[i][0]); |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 1130 | if (hsw_dais[i].capture.channels_min) |
Liam Girdwood | 0b708c8 | 2014-05-02 16:56:30 +0100 | [diff] [blame] | 1131 | snd_dma_free_pages(&priv_data->dmab[i][1]); |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 1132 | } |
| 1133 | |
| 1134 | return 0; |
| 1135 | } |
| 1136 | |
| 1137 | static struct snd_soc_platform_driver hsw_soc_platform = { |
| 1138 | .probe = hsw_pcm_probe, |
| 1139 | .remove = hsw_pcm_remove, |
| 1140 | .ops = &hsw_pcm_ops, |
| 1141 | .pcm_new = hsw_pcm_new, |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 1142 | }; |
| 1143 | |
| 1144 | static const struct snd_soc_component_driver hsw_dai_component = { |
Lars-Peter Clausen | 923976a | 2014-08-20 13:08:48 +0200 | [diff] [blame] | 1145 | .name = "haswell-dai", |
| 1146 | .controls = hsw_volume_controls, |
| 1147 | .num_controls = ARRAY_SIZE(hsw_volume_controls), |
| 1148 | .dapm_widgets = widgets, |
| 1149 | .num_dapm_widgets = ARRAY_SIZE(widgets), |
| 1150 | .dapm_routes = graph, |
| 1151 | .num_dapm_routes = ARRAY_SIZE(graph), |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 1152 | }; |
| 1153 | |
| 1154 | static int hsw_pcm_dev_probe(struct platform_device *pdev) |
| 1155 | { |
| 1156 | struct sst_pdata *sst_pdata = dev_get_platdata(&pdev->dev); |
Lars-Peter Clausen | bd03380 | 2014-08-20 13:08:47 +0200 | [diff] [blame] | 1157 | struct hsw_priv_data *priv_data; |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 1158 | int ret; |
| 1159 | |
Lars-Peter Clausen | bd03380 | 2014-08-20 13:08:47 +0200 | [diff] [blame] | 1160 | if (!sst_pdata) |
| 1161 | return -EINVAL; |
| 1162 | |
| 1163 | priv_data = devm_kzalloc(&pdev->dev, sizeof(*priv_data), GFP_KERNEL); |
| 1164 | if (!priv_data) |
| 1165 | return -ENOMEM; |
| 1166 | |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 1167 | ret = sst_hsw_dsp_init(&pdev->dev, sst_pdata); |
| 1168 | if (ret < 0) |
| 1169 | return -ENODEV; |
| 1170 | |
Lars-Peter Clausen | bd03380 | 2014-08-20 13:08:47 +0200 | [diff] [blame] | 1171 | priv_data->hsw = sst_pdata->dsp; |
| 1172 | platform_set_drvdata(pdev, priv_data); |
| 1173 | |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 1174 | ret = snd_soc_register_platform(&pdev->dev, &hsw_soc_platform); |
| 1175 | if (ret < 0) |
| 1176 | goto err_plat; |
| 1177 | |
| 1178 | ret = snd_soc_register_component(&pdev->dev, &hsw_dai_component, |
| 1179 | hsw_dais, ARRAY_SIZE(hsw_dais)); |
| 1180 | if (ret < 0) |
| 1181 | goto err_comp; |
| 1182 | |
| 1183 | return 0; |
| 1184 | |
| 1185 | err_comp: |
| 1186 | snd_soc_unregister_platform(&pdev->dev); |
| 1187 | err_plat: |
| 1188 | sst_hsw_dsp_free(&pdev->dev, sst_pdata); |
| 1189 | return 0; |
| 1190 | } |
| 1191 | |
| 1192 | static int hsw_pcm_dev_remove(struct platform_device *pdev) |
| 1193 | { |
| 1194 | struct sst_pdata *sst_pdata = dev_get_platdata(&pdev->dev); |
| 1195 | |
| 1196 | snd_soc_unregister_platform(&pdev->dev); |
| 1197 | snd_soc_unregister_component(&pdev->dev); |
| 1198 | sst_hsw_dsp_free(&pdev->dev, sst_pdata); |
| 1199 | |
| 1200 | return 0; |
| 1201 | } |
| 1202 | |
Rafael J. Wysocki | 45544c8 | 2014-12-19 15:26:46 +0100 | [diff] [blame] | 1203 | #ifdef CONFIG_PM |
Liam Girdwood | 2e4f7591 | 2014-10-29 17:40:43 +0000 | [diff] [blame] | 1204 | |
| 1205 | static int hsw_pcm_runtime_idle(struct device *dev) |
| 1206 | { |
| 1207 | return 0; |
| 1208 | } |
| 1209 | |
| 1210 | static int hsw_pcm_runtime_suspend(struct device *dev) |
| 1211 | { |
| 1212 | struct hsw_priv_data *pdata = dev_get_drvdata(dev); |
| 1213 | struct sst_hsw *hsw = pdata->hsw; |
Lu, Han | 76c07b8 | 2015-03-12 13:53:00 +0800 | [diff] [blame] | 1214 | int ret; |
Liam Girdwood | 2e4f7591 | 2014-10-29 17:40:43 +0000 | [diff] [blame] | 1215 | |
Jie Yang | cd311dd | 2015-02-05 22:56:48 +0800 | [diff] [blame] | 1216 | if (pdata->pm_state >= HSW_PM_STATE_RTD3) |
Liam Girdwood | 2e4f7591 | 2014-10-29 17:40:43 +0000 | [diff] [blame] | 1217 | return 0; |
| 1218 | |
Lu, Han | 76c07b8 | 2015-03-12 13:53:00 +0800 | [diff] [blame] | 1219 | /* fw modules will be unloaded on RTD3, set flag to track */ |
| 1220 | if (sst_hsw_is_module_active(hsw, SST_HSW_MODULE_WAVES)) { |
| 1221 | ret = sst_hsw_module_disable(hsw, SST_HSW_MODULE_WAVES, 0); |
| 1222 | if (ret < 0) |
| 1223 | return ret; |
| 1224 | sst_hsw_set_module_enabled_rtd3(hsw, SST_HSW_MODULE_WAVES); |
| 1225 | } |
Liam Girdwood | 2e4f7591 | 2014-10-29 17:40:43 +0000 | [diff] [blame] | 1226 | sst_hsw_dsp_runtime_suspend(hsw); |
| 1227 | sst_hsw_dsp_runtime_sleep(hsw); |
Jie Yang | cd311dd | 2015-02-05 22:56:48 +0800 | [diff] [blame] | 1228 | pdata->pm_state = HSW_PM_STATE_RTD3; |
Liam Girdwood | 2e4f7591 | 2014-10-29 17:40:43 +0000 | [diff] [blame] | 1229 | |
| 1230 | return 0; |
| 1231 | } |
| 1232 | |
| 1233 | static int hsw_pcm_runtime_resume(struct device *dev) |
| 1234 | { |
| 1235 | struct hsw_priv_data *pdata = dev_get_drvdata(dev); |
| 1236 | struct sst_hsw *hsw = pdata->hsw; |
| 1237 | int ret; |
| 1238 | |
Jie Yang | cd311dd | 2015-02-05 22:56:48 +0800 | [diff] [blame] | 1239 | if (pdata->pm_state != HSW_PM_STATE_RTD3) |
Liam Girdwood | 2e4f7591 | 2014-10-29 17:40:43 +0000 | [diff] [blame] | 1240 | return 0; |
| 1241 | |
| 1242 | ret = sst_hsw_dsp_load(hsw); |
| 1243 | if (ret < 0) { |
| 1244 | dev_err(dev, "failed to reload %d\n", ret); |
| 1245 | return ret; |
| 1246 | } |
| 1247 | |
| 1248 | ret = hsw_pcm_create_modules(pdata); |
| 1249 | if (ret < 0) { |
| 1250 | dev_err(dev, "failed to create modules %d\n", ret); |
| 1251 | return ret; |
| 1252 | } |
| 1253 | |
| 1254 | ret = sst_hsw_dsp_runtime_resume(hsw); |
| 1255 | if (ret < 0) |
| 1256 | return ret; |
| 1257 | else if (ret == 1) /* no action required */ |
| 1258 | return 0; |
| 1259 | |
Lu, Han | 76c07b8 | 2015-03-12 13:53:00 +0800 | [diff] [blame] | 1260 | /* check flag when resume */ |
| 1261 | if (sst_hsw_is_module_enabled_rtd3(hsw, SST_HSW_MODULE_WAVES)) { |
| 1262 | ret = sst_hsw_module_enable(hsw, SST_HSW_MODULE_WAVES, 0); |
| 1263 | if (ret < 0) |
| 1264 | return ret; |
Lu, Han | 3814c20 | 2015-03-12 13:53:02 +0800 | [diff] [blame] | 1265 | /* put parameters from buffer to dsp */ |
| 1266 | ret = sst_hsw_launch_param_buf(hsw); |
| 1267 | if (ret < 0) |
| 1268 | return ret; |
Lu, Han | 76c07b8 | 2015-03-12 13:53:00 +0800 | [diff] [blame] | 1269 | /* unset flag */ |
| 1270 | sst_hsw_set_module_disabled_rtd3(hsw, SST_HSW_MODULE_WAVES); |
| 1271 | } |
| 1272 | |
Liam Girdwood | 2e4f7591 | 2014-10-29 17:40:43 +0000 | [diff] [blame] | 1273 | pdata->pm_state = HSW_PM_STATE_D0; |
| 1274 | return ret; |
| 1275 | } |
| 1276 | |
Liam Girdwood | 35e03a8 | 2014-10-30 14:58:19 +0000 | [diff] [blame] | 1277 | #else |
| 1278 | #define hsw_pcm_runtime_idle NULL |
| 1279 | #define hsw_pcm_runtime_suspend NULL |
| 1280 | #define hsw_pcm_runtime_resume NULL |
| 1281 | #endif |
| 1282 | |
Rafael J. Wysocki | 45544c8 | 2014-12-19 15:26:46 +0100 | [diff] [blame] | 1283 | #ifdef CONFIG_PM |
Liam Girdwood | 7b8ef67 | 2014-11-04 13:27:45 +0000 | [diff] [blame] | 1284 | |
Liam Girdwood | 2e4f7591 | 2014-10-29 17:40:43 +0000 | [diff] [blame] | 1285 | static void hsw_pcm_complete(struct device *dev) |
| 1286 | { |
| 1287 | struct hsw_priv_data *pdata = dev_get_drvdata(dev); |
| 1288 | struct sst_hsw *hsw = pdata->hsw; |
| 1289 | struct hsw_pcm_data *pcm_data; |
| 1290 | int i, err; |
| 1291 | |
Jie Yang | cd311dd | 2015-02-05 22:56:48 +0800 | [diff] [blame] | 1292 | if (pdata->pm_state != HSW_PM_STATE_D3) |
Liam Girdwood | 2e4f7591 | 2014-10-29 17:40:43 +0000 | [diff] [blame] | 1293 | return; |
| 1294 | |
| 1295 | err = sst_hsw_dsp_load(hsw); |
| 1296 | if (err < 0) { |
| 1297 | dev_err(dev, "failed to reload %d\n", err); |
| 1298 | return; |
| 1299 | } |
| 1300 | |
| 1301 | err = hsw_pcm_create_modules(pdata); |
| 1302 | if (err < 0) { |
| 1303 | dev_err(dev, "failed to create modules %d\n", err); |
| 1304 | return; |
| 1305 | } |
| 1306 | |
Jie Yang | 98b9c1d | 2015-01-08 14:32:20 +0800 | [diff] [blame] | 1307 | for (i = 0; i < ARRAY_SIZE(mod_map); i++) { |
Jie Yang | 7ff9d67 | 2015-01-09 14:36:36 +0800 | [diff] [blame] | 1308 | pcm_data = &pdata->pcm[mod_map[i].dai_id][mod_map[i].stream]; |
Liam Girdwood | 2e4f7591 | 2014-10-29 17:40:43 +0000 | [diff] [blame] | 1309 | |
| 1310 | if (!pcm_data->substream) |
| 1311 | continue; |
| 1312 | |
| 1313 | err = sst_module_runtime_restore(pcm_data->runtime, |
| 1314 | &pcm_data->context); |
| 1315 | if (err < 0) |
| 1316 | dev_err(dev, "failed to restore context for PCM %d\n", i); |
| 1317 | } |
| 1318 | |
| 1319 | snd_soc_resume(pdata->soc_card->dev); |
| 1320 | |
| 1321 | err = sst_hsw_dsp_runtime_resume(hsw); |
| 1322 | if (err < 0) |
| 1323 | return; |
| 1324 | else if (err == 1) /* no action required */ |
| 1325 | return; |
| 1326 | |
| 1327 | pdata->pm_state = HSW_PM_STATE_D0; |
| 1328 | return; |
| 1329 | } |
| 1330 | |
| 1331 | static int hsw_pcm_prepare(struct device *dev) |
| 1332 | { |
| 1333 | struct hsw_priv_data *pdata = dev_get_drvdata(dev); |
| 1334 | struct sst_hsw *hsw = pdata->hsw; |
| 1335 | struct hsw_pcm_data *pcm_data; |
| 1336 | int i, err; |
| 1337 | |
| 1338 | if (pdata->pm_state == HSW_PM_STATE_D3) |
| 1339 | return 0; |
Jie Yang | cd311dd | 2015-02-05 22:56:48 +0800 | [diff] [blame] | 1340 | else if (pdata->pm_state == HSW_PM_STATE_D0) { |
| 1341 | /* suspend all active streams */ |
| 1342 | for (i = 0; i < ARRAY_SIZE(mod_map); i++) { |
| 1343 | pcm_data = &pdata->pcm[mod_map[i].dai_id][mod_map[i].stream]; |
Liam Girdwood | 2e4f7591 | 2014-10-29 17:40:43 +0000 | [diff] [blame] | 1344 | |
Jie Yang | cd311dd | 2015-02-05 22:56:48 +0800 | [diff] [blame] | 1345 | if (!pcm_data->substream) |
| 1346 | continue; |
| 1347 | dev_dbg(dev, "suspending pcm %d\n", i); |
| 1348 | snd_pcm_suspend_all(pcm_data->hsw_pcm); |
Liam Girdwood | 2e4f7591 | 2014-10-29 17:40:43 +0000 | [diff] [blame] | 1349 | |
Jie Yang | cd311dd | 2015-02-05 22:56:48 +0800 | [diff] [blame] | 1350 | /* We need to wait until the DSP FW stops the streams */ |
| 1351 | msleep(2); |
| 1352 | } |
| 1353 | |
| 1354 | /* preserve persistent memory */ |
| 1355 | for (i = 0; i < ARRAY_SIZE(mod_map); i++) { |
| 1356 | pcm_data = &pdata->pcm[mod_map[i].dai_id][mod_map[i].stream]; |
| 1357 | |
| 1358 | if (!pcm_data->substream) |
| 1359 | continue; |
| 1360 | |
| 1361 | dev_dbg(dev, "saving context pcm %d\n", i); |
| 1362 | err = sst_module_runtime_save(pcm_data->runtime, |
| 1363 | &pcm_data->context); |
| 1364 | if (err < 0) |
| 1365 | dev_err(dev, "failed to save context for PCM %d\n", i); |
| 1366 | } |
| 1367 | /* enter D3 state and stall */ |
| 1368 | sst_hsw_dsp_runtime_suspend(hsw); |
| 1369 | /* put the DSP to sleep */ |
| 1370 | sst_hsw_dsp_runtime_sleep(hsw); |
Liam Girdwood | 2e4f7591 | 2014-10-29 17:40:43 +0000 | [diff] [blame] | 1371 | } |
| 1372 | |
| 1373 | snd_soc_suspend(pdata->soc_card->dev); |
| 1374 | snd_soc_poweroff(pdata->soc_card->dev); |
| 1375 | |
Liam Girdwood | 2e4f7591 | 2014-10-29 17:40:43 +0000 | [diff] [blame] | 1376 | pdata->pm_state = HSW_PM_STATE_D3; |
| 1377 | |
| 1378 | return 0; |
| 1379 | } |
| 1380 | |
Liam Girdwood | 7b8ef67 | 2014-11-04 13:27:45 +0000 | [diff] [blame] | 1381 | #else |
| 1382 | #define hsw_pcm_prepare NULL |
| 1383 | #define hsw_pcm_complete NULL |
| 1384 | #endif |
| 1385 | |
Liam Girdwood | 2e4f7591 | 2014-10-29 17:40:43 +0000 | [diff] [blame] | 1386 | static const struct dev_pm_ops hsw_pcm_pm = { |
| 1387 | .runtime_idle = hsw_pcm_runtime_idle, |
| 1388 | .runtime_suspend = hsw_pcm_runtime_suspend, |
| 1389 | .runtime_resume = hsw_pcm_runtime_resume, |
| 1390 | .prepare = hsw_pcm_prepare, |
| 1391 | .complete = hsw_pcm_complete, |
| 1392 | }; |
Liam Girdwood | 2e4f7591 | 2014-10-29 17:40:43 +0000 | [diff] [blame] | 1393 | |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 1394 | static struct platform_driver hsw_pcm_driver = { |
| 1395 | .driver = { |
| 1396 | .name = "haswell-pcm-audio", |
Liam Girdwood | 2e4f7591 | 2014-10-29 17:40:43 +0000 | [diff] [blame] | 1397 | .pm = &hsw_pcm_pm, |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 1398 | }, |
| 1399 | |
| 1400 | .probe = hsw_pcm_dev_probe, |
| 1401 | .remove = hsw_pcm_dev_remove, |
| 1402 | }; |
| 1403 | module_platform_driver(hsw_pcm_driver); |
| 1404 | |
| 1405 | MODULE_AUTHOR("Liam Girdwood, Xingchao Wang"); |
| 1406 | MODULE_DESCRIPTION("Haswell/Lynxpoint + Broadwell/Wildcatpoint PCM"); |
| 1407 | MODULE_LICENSE("GPL v2"); |
| 1408 | MODULE_ALIAS("platform:haswell-pcm-audio"); |