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