Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Intel Baytrail SST PCM Support |
| 3 | * Copyright (c) 2014, Intel Corporation. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms and conditions of the GNU General Public License, |
| 7 | * version 2, as published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 12 | * more details. |
| 13 | */ |
| 14 | |
| 15 | #include <linux/module.h> |
| 16 | #include <linux/dma-mapping.h> |
| 17 | #include <linux/slab.h> |
| 18 | #include <sound/core.h> |
| 19 | #include <sound/pcm.h> |
| 20 | #include <sound/pcm_params.h> |
| 21 | #include <sound/soc.h> |
| 22 | #include "sst-baytrail-ipc.h" |
| 23 | #include "sst-dsp-priv.h" |
| 24 | #include "sst-dsp.h" |
| 25 | |
| 26 | #define BYT_PCM_COUNT 2 |
| 27 | |
| 28 | static const struct snd_pcm_hardware sst_byt_pcm_hardware = { |
| 29 | .info = SNDRV_PCM_INFO_MMAP | |
| 30 | SNDRV_PCM_INFO_MMAP_VALID | |
| 31 | SNDRV_PCM_INFO_INTERLEAVED | |
| 32 | SNDRV_PCM_INFO_PAUSE | |
| 33 | SNDRV_PCM_INFO_RESUME, |
| 34 | .formats = SNDRV_PCM_FMTBIT_S16_LE | |
| 35 | SNDRV_PCM_FORMAT_S24_LE, |
| 36 | .period_bytes_min = 384, |
| 37 | .period_bytes_max = 48000, |
| 38 | .periods_min = 2, |
| 39 | .periods_max = 250, |
| 40 | .buffer_bytes_max = 96000, |
| 41 | }; |
| 42 | |
| 43 | /* private data for each PCM DSP stream */ |
| 44 | struct sst_byt_pcm_data { |
| 45 | struct sst_byt_stream *stream; |
| 46 | struct snd_pcm_substream *substream; |
| 47 | struct mutex mutex; |
Jarkko Nikula | c83649e | 2014-05-08 16:07:21 +0300 | [diff] [blame] | 48 | |
| 49 | /* latest DSP DMA hw pointer */ |
| 50 | u32 hw_ptr; |
Liam Girdwood | af94aa5 | 2014-05-08 16:07:26 +0300 | [diff] [blame^] | 51 | |
| 52 | struct work_struct work; |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 53 | }; |
| 54 | |
| 55 | /* private data for the driver */ |
| 56 | struct sst_byt_priv_data { |
| 57 | /* runtime DSP */ |
| 58 | struct sst_byt *byt; |
| 59 | |
| 60 | /* DAI data */ |
| 61 | struct sst_byt_pcm_data pcm[BYT_PCM_COUNT]; |
| 62 | }; |
| 63 | |
| 64 | /* this may get called several times by oss emulation */ |
| 65 | static int sst_byt_pcm_hw_params(struct snd_pcm_substream *substream, |
| 66 | struct snd_pcm_hw_params *params) |
| 67 | { |
| 68 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 69 | struct sst_byt_priv_data *pdata = |
| 70 | snd_soc_platform_get_drvdata(rtd->platform); |
| 71 | struct sst_byt_pcm_data *pcm_data = snd_soc_pcm_get_drvdata(rtd); |
| 72 | struct sst_byt *byt = pdata->byt; |
| 73 | u32 rate, bits; |
| 74 | u8 channels; |
| 75 | int ret, playback = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK); |
| 76 | |
| 77 | dev_dbg(rtd->dev, "PCM: hw_params, pcm_data %p\n", pcm_data); |
| 78 | |
| 79 | ret = sst_byt_stream_type(byt, pcm_data->stream, |
| 80 | 1, 1, !playback); |
| 81 | if (ret < 0) { |
| 82 | dev_err(rtd->dev, "failed to set stream format %d\n", ret); |
| 83 | return ret; |
| 84 | } |
| 85 | |
| 86 | rate = params_rate(params); |
| 87 | ret = sst_byt_stream_set_rate(byt, pcm_data->stream, rate); |
| 88 | if (ret < 0) { |
| 89 | dev_err(rtd->dev, "could not set rate %d\n", rate); |
| 90 | return ret; |
| 91 | } |
| 92 | |
| 93 | bits = snd_pcm_format_width(params_format(params)); |
| 94 | ret = sst_byt_stream_set_bits(byt, pcm_data->stream, bits); |
| 95 | if (ret < 0) { |
| 96 | dev_err(rtd->dev, "could not set formats %d\n", |
| 97 | params_rate(params)); |
| 98 | return ret; |
| 99 | } |
| 100 | |
| 101 | channels = (u8)(params_channels(params) & 0xF); |
| 102 | ret = sst_byt_stream_set_channels(byt, pcm_data->stream, channels); |
| 103 | if (ret < 0) { |
| 104 | dev_err(rtd->dev, "could not set channels %d\n", |
| 105 | params_rate(params)); |
| 106 | return ret; |
| 107 | } |
| 108 | |
| 109 | snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params)); |
| 110 | |
| 111 | ret = sst_byt_stream_buffer(byt, pcm_data->stream, |
| 112 | substream->dma_buffer.addr, |
| 113 | params_buffer_bytes(params)); |
| 114 | if (ret < 0) { |
| 115 | dev_err(rtd->dev, "PCM: failed to set DMA buffer %d\n", ret); |
| 116 | return ret; |
| 117 | } |
| 118 | |
| 119 | ret = sst_byt_stream_commit(byt, pcm_data->stream); |
| 120 | if (ret < 0) { |
| 121 | dev_err(rtd->dev, "PCM: failed stream commit %d\n", ret); |
| 122 | return ret; |
| 123 | } |
| 124 | |
| 125 | return 0; |
| 126 | } |
| 127 | |
| 128 | static int sst_byt_pcm_hw_free(struct snd_pcm_substream *substream) |
| 129 | { |
| 130 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 131 | |
| 132 | dev_dbg(rtd->dev, "PCM: hw_free\n"); |
| 133 | snd_pcm_lib_free_pages(substream); |
| 134 | |
| 135 | return 0; |
| 136 | } |
| 137 | |
Liam Girdwood | af94aa5 | 2014-05-08 16:07:26 +0300 | [diff] [blame^] | 138 | static int sst_byt_pcm_restore_stream_context(struct snd_pcm_substream *substream) |
| 139 | { |
| 140 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 141 | struct sst_byt_priv_data *pdata = |
| 142 | snd_soc_platform_get_drvdata(rtd->platform); |
| 143 | struct sst_byt_pcm_data *pcm_data = snd_soc_pcm_get_drvdata(rtd); |
| 144 | struct sst_byt *byt = pdata->byt; |
| 145 | int ret; |
| 146 | |
| 147 | /* commit stream using existing stream params */ |
| 148 | ret = sst_byt_stream_commit(byt, pcm_data->stream); |
| 149 | if (ret < 0) { |
| 150 | dev_err(rtd->dev, "PCM: failed stream commit %d\n", ret); |
| 151 | return ret; |
| 152 | } |
| 153 | |
| 154 | sst_byt_stream_start(byt, pcm_data->stream, pcm_data->hw_ptr); |
| 155 | |
| 156 | dev_dbg(rtd->dev, "stream context restored at offset %d\n", |
| 157 | pcm_data->hw_ptr); |
| 158 | |
| 159 | return 0; |
| 160 | } |
| 161 | |
| 162 | static void sst_byt_pcm_work(struct work_struct *work) |
| 163 | { |
| 164 | struct sst_byt_pcm_data *pcm_data = |
| 165 | container_of(work, struct sst_byt_pcm_data, work); |
| 166 | |
| 167 | sst_byt_pcm_restore_stream_context(pcm_data->substream); |
| 168 | } |
| 169 | |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 170 | static int sst_byt_pcm_trigger(struct snd_pcm_substream *substream, int cmd) |
| 171 | { |
| 172 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 173 | struct sst_byt_priv_data *pdata = |
| 174 | snd_soc_platform_get_drvdata(rtd->platform); |
| 175 | struct sst_byt_pcm_data *pcm_data = snd_soc_pcm_get_drvdata(rtd); |
| 176 | struct sst_byt *byt = pdata->byt; |
| 177 | |
| 178 | dev_dbg(rtd->dev, "PCM: trigger %d\n", cmd); |
| 179 | |
| 180 | switch (cmd) { |
| 181 | case SNDRV_PCM_TRIGGER_START: |
Jarkko Nikula | a6686ed | 2014-05-08 16:07:23 +0300 | [diff] [blame] | 182 | sst_byt_stream_start(byt, pcm_data->stream, 0); |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 183 | break; |
| 184 | case SNDRV_PCM_TRIGGER_RESUME: |
Liam Girdwood | af94aa5 | 2014-05-08 16:07:26 +0300 | [diff] [blame^] | 185 | schedule_work(&pcm_data->work); |
| 186 | break; |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 187 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
| 188 | sst_byt_stream_resume(byt, pcm_data->stream); |
| 189 | break; |
| 190 | case SNDRV_PCM_TRIGGER_STOP: |
| 191 | sst_byt_stream_stop(byt, pcm_data->stream); |
| 192 | break; |
| 193 | case SNDRV_PCM_TRIGGER_SUSPEND: |
| 194 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
| 195 | sst_byt_stream_pause(byt, pcm_data->stream); |
| 196 | break; |
| 197 | default: |
| 198 | break; |
| 199 | } |
| 200 | |
| 201 | return 0; |
| 202 | } |
| 203 | |
| 204 | static u32 byt_notify_pointer(struct sst_byt_stream *stream, void *data) |
| 205 | { |
| 206 | struct sst_byt_pcm_data *pcm_data = data; |
| 207 | struct snd_pcm_substream *substream = pcm_data->substream; |
| 208 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 209 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Jarkko Nikula | c83649e | 2014-05-08 16:07:21 +0300 | [diff] [blame] | 210 | struct sst_byt_priv_data *pdata = |
| 211 | snd_soc_platform_get_drvdata(rtd->platform); |
| 212 | struct sst_byt *byt = pdata->byt; |
| 213 | u32 pos, hw_pos; |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 214 | |
Jarkko Nikula | c83649e | 2014-05-08 16:07:21 +0300 | [diff] [blame] | 215 | hw_pos = sst_byt_get_dsp_position(byt, pcm_data->stream, |
| 216 | snd_pcm_lib_buffer_bytes(substream)); |
| 217 | pcm_data->hw_ptr = hw_pos; |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 218 | pos = frames_to_bytes(runtime, |
| 219 | (runtime->control->appl_ptr % |
| 220 | runtime->buffer_size)); |
| 221 | |
Jarkko Nikula | c83649e | 2014-05-08 16:07:21 +0300 | [diff] [blame] | 222 | dev_dbg(rtd->dev, "PCM: App/DMA pointer %u/%u bytes\n", pos, hw_pos); |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 223 | |
| 224 | snd_pcm_period_elapsed(substream); |
| 225 | return pos; |
| 226 | } |
| 227 | |
| 228 | static snd_pcm_uframes_t sst_byt_pcm_pointer(struct snd_pcm_substream *substream) |
| 229 | { |
| 230 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 231 | struct snd_pcm_runtime *runtime = substream->runtime; |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 232 | struct sst_byt_pcm_data *pcm_data = snd_soc_pcm_get_drvdata(rtd); |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 233 | |
Jarkko Nikula | c83649e | 2014-05-08 16:07:21 +0300 | [diff] [blame] | 234 | dev_dbg(rtd->dev, "PCM: DMA pointer %u bytes\n", pcm_data->hw_ptr); |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 235 | |
Jarkko Nikula | c83649e | 2014-05-08 16:07:21 +0300 | [diff] [blame] | 236 | return bytes_to_frames(runtime, pcm_data->hw_ptr); |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | static int sst_byt_pcm_open(struct snd_pcm_substream *substream) |
| 240 | { |
| 241 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 242 | struct sst_byt_priv_data *pdata = |
| 243 | snd_soc_platform_get_drvdata(rtd->platform); |
| 244 | struct sst_byt_pcm_data *pcm_data = snd_soc_pcm_get_drvdata(rtd); |
| 245 | struct sst_byt *byt = pdata->byt; |
| 246 | |
| 247 | dev_dbg(rtd->dev, "PCM: open\n"); |
| 248 | |
| 249 | pcm_data = &pdata->pcm[rtd->cpu_dai->id]; |
| 250 | mutex_lock(&pcm_data->mutex); |
| 251 | |
| 252 | snd_soc_pcm_set_drvdata(rtd, pcm_data); |
| 253 | pcm_data->substream = substream; |
| 254 | |
| 255 | snd_soc_set_runtime_hwparams(substream, &sst_byt_pcm_hardware); |
| 256 | |
| 257 | pcm_data->stream = sst_byt_stream_new(byt, rtd->cpu_dai->id + 1, |
| 258 | byt_notify_pointer, pcm_data); |
| 259 | if (pcm_data->stream == NULL) { |
| 260 | dev_err(rtd->dev, "failed to create stream\n"); |
| 261 | mutex_unlock(&pcm_data->mutex); |
| 262 | return -EINVAL; |
| 263 | } |
| 264 | |
| 265 | mutex_unlock(&pcm_data->mutex); |
| 266 | return 0; |
| 267 | } |
| 268 | |
| 269 | static int sst_byt_pcm_close(struct snd_pcm_substream *substream) |
| 270 | { |
| 271 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 272 | struct sst_byt_priv_data *pdata = |
| 273 | snd_soc_platform_get_drvdata(rtd->platform); |
| 274 | struct sst_byt_pcm_data *pcm_data = snd_soc_pcm_get_drvdata(rtd); |
| 275 | struct sst_byt *byt = pdata->byt; |
| 276 | int ret; |
| 277 | |
| 278 | dev_dbg(rtd->dev, "PCM: close\n"); |
| 279 | |
| 280 | mutex_lock(&pcm_data->mutex); |
| 281 | ret = sst_byt_stream_free(byt, pcm_data->stream); |
| 282 | if (ret < 0) { |
| 283 | dev_dbg(rtd->dev, "Free stream fail\n"); |
| 284 | goto out; |
| 285 | } |
| 286 | pcm_data->stream = NULL; |
| 287 | |
| 288 | out: |
| 289 | mutex_unlock(&pcm_data->mutex); |
| 290 | return ret; |
| 291 | } |
| 292 | |
| 293 | static int sst_byt_pcm_mmap(struct snd_pcm_substream *substream, |
| 294 | struct vm_area_struct *vma) |
| 295 | { |
| 296 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 297 | |
| 298 | dev_dbg(rtd->dev, "PCM: mmap\n"); |
| 299 | return snd_pcm_lib_default_mmap(substream, vma); |
| 300 | } |
| 301 | |
| 302 | static struct snd_pcm_ops sst_byt_pcm_ops = { |
| 303 | .open = sst_byt_pcm_open, |
| 304 | .close = sst_byt_pcm_close, |
| 305 | .ioctl = snd_pcm_lib_ioctl, |
| 306 | .hw_params = sst_byt_pcm_hw_params, |
| 307 | .hw_free = sst_byt_pcm_hw_free, |
| 308 | .trigger = sst_byt_pcm_trigger, |
| 309 | .pointer = sst_byt_pcm_pointer, |
| 310 | .mmap = sst_byt_pcm_mmap, |
| 311 | }; |
| 312 | |
| 313 | static void sst_byt_pcm_free(struct snd_pcm *pcm) |
| 314 | { |
| 315 | snd_pcm_lib_preallocate_free_for_all(pcm); |
| 316 | } |
| 317 | |
| 318 | static int sst_byt_pcm_new(struct snd_soc_pcm_runtime *rtd) |
| 319 | { |
| 320 | struct snd_pcm *pcm = rtd->pcm; |
| 321 | size_t size; |
| 322 | int ret = 0; |
| 323 | |
| 324 | ret = dma_coerce_mask_and_coherent(rtd->card->dev, DMA_BIT_MASK(32)); |
| 325 | if (ret) |
| 326 | return ret; |
| 327 | |
| 328 | if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream || |
| 329 | pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream) { |
| 330 | size = sst_byt_pcm_hardware.buffer_bytes_max; |
| 331 | ret = snd_pcm_lib_preallocate_pages_for_all(pcm, |
| 332 | SNDRV_DMA_TYPE_DEV, |
| 333 | rtd->card->dev, |
| 334 | size, size); |
| 335 | if (ret) { |
| 336 | dev_err(rtd->dev, "dma buffer allocation failed %d\n", |
| 337 | ret); |
| 338 | return ret; |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | return ret; |
| 343 | } |
| 344 | |
| 345 | static struct snd_soc_dai_driver byt_dais[] = { |
| 346 | { |
| 347 | .name = "Front-cpu-dai", |
| 348 | .playback = { |
| 349 | .stream_name = "System Playback", |
| 350 | .channels_min = 2, |
| 351 | .channels_max = 2, |
| 352 | .rates = SNDRV_PCM_RATE_48000, |
| 353 | .formats = SNDRV_PCM_FMTBIT_S24_3LE | |
| 354 | SNDRV_PCM_FMTBIT_S16_LE, |
| 355 | }, |
| 356 | }, |
| 357 | { |
| 358 | .name = "Mic1-cpu-dai", |
| 359 | .capture = { |
| 360 | .stream_name = "Analog Capture", |
| 361 | .channels_min = 2, |
| 362 | .channels_max = 2, |
| 363 | .rates = SNDRV_PCM_RATE_48000, |
| 364 | .formats = SNDRV_PCM_FMTBIT_S16_LE, |
| 365 | }, |
| 366 | }, |
| 367 | }; |
| 368 | |
| 369 | static int sst_byt_pcm_probe(struct snd_soc_platform *platform) |
| 370 | { |
| 371 | struct sst_pdata *plat_data = dev_get_platdata(platform->dev); |
| 372 | struct sst_byt_priv_data *priv_data; |
| 373 | int i; |
| 374 | |
| 375 | if (!plat_data) |
| 376 | return -ENODEV; |
| 377 | |
| 378 | priv_data = devm_kzalloc(platform->dev, sizeof(*priv_data), |
| 379 | GFP_KERNEL); |
| 380 | priv_data->byt = plat_data->dsp; |
| 381 | snd_soc_platform_set_drvdata(platform, priv_data); |
| 382 | |
Liam Girdwood | af94aa5 | 2014-05-08 16:07:26 +0300 | [diff] [blame^] | 383 | for (i = 0; i < ARRAY_SIZE(byt_dais); i++) { |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 384 | mutex_init(&priv_data->pcm[i].mutex); |
Liam Girdwood | af94aa5 | 2014-05-08 16:07:26 +0300 | [diff] [blame^] | 385 | INIT_WORK(&priv_data->pcm[i].work, sst_byt_pcm_work); |
| 386 | } |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 387 | |
| 388 | return 0; |
| 389 | } |
| 390 | |
| 391 | static int sst_byt_pcm_remove(struct snd_soc_platform *platform) |
| 392 | { |
| 393 | return 0; |
| 394 | } |
| 395 | |
| 396 | static struct snd_soc_platform_driver byt_soc_platform = { |
| 397 | .probe = sst_byt_pcm_probe, |
| 398 | .remove = sst_byt_pcm_remove, |
| 399 | .ops = &sst_byt_pcm_ops, |
| 400 | .pcm_new = sst_byt_pcm_new, |
| 401 | .pcm_free = sst_byt_pcm_free, |
| 402 | }; |
| 403 | |
| 404 | static const struct snd_soc_component_driver byt_dai_component = { |
| 405 | .name = "byt-dai", |
| 406 | }; |
| 407 | |
Liam Girdwood | af94aa5 | 2014-05-08 16:07:26 +0300 | [diff] [blame^] | 408 | #ifdef CONFIG_PM |
| 409 | static int sst_byt_pcm_dev_suspend_noirq(struct device *dev) |
| 410 | { |
| 411 | struct sst_pdata *sst_pdata = dev_get_platdata(dev); |
| 412 | int ret; |
| 413 | |
| 414 | dev_dbg(dev, "suspending noirq\n"); |
| 415 | |
| 416 | /* at this point all streams will be stopped and context saved */ |
| 417 | ret = sst_byt_dsp_suspend_noirq(dev, sst_pdata); |
| 418 | if (ret < 0) { |
| 419 | dev_err(dev, "failed to suspend %d\n", ret); |
| 420 | return ret; |
| 421 | } |
| 422 | |
| 423 | return ret; |
| 424 | } |
| 425 | |
| 426 | static int sst_byt_pcm_dev_suspend_late(struct device *dev) |
| 427 | { |
| 428 | struct sst_pdata *sst_pdata = dev_get_platdata(dev); |
| 429 | int ret; |
| 430 | |
| 431 | dev_dbg(dev, "suspending late\n"); |
| 432 | |
| 433 | ret = sst_byt_dsp_suspend_late(dev, sst_pdata); |
| 434 | if (ret < 0) { |
| 435 | dev_err(dev, "failed to suspend %d\n", ret); |
| 436 | return ret; |
| 437 | } |
| 438 | |
| 439 | return ret; |
| 440 | } |
| 441 | |
| 442 | static int sst_byt_pcm_dev_resume_early(struct device *dev) |
| 443 | { |
| 444 | struct sst_pdata *sst_pdata = dev_get_platdata(dev); |
| 445 | |
| 446 | dev_dbg(dev, "resume early\n"); |
| 447 | |
| 448 | /* load fw and boot DSP */ |
| 449 | return sst_byt_dsp_boot(dev, sst_pdata); |
| 450 | } |
| 451 | |
| 452 | static int sst_byt_pcm_dev_resume(struct device *dev) |
| 453 | { |
| 454 | struct sst_pdata *sst_pdata = dev_get_platdata(dev); |
| 455 | |
| 456 | dev_dbg(dev, "resume\n"); |
| 457 | |
| 458 | /* wait for FW to finish booting */ |
| 459 | return sst_byt_dsp_wait_for_ready(dev, sst_pdata); |
| 460 | } |
| 461 | |
| 462 | static const struct dev_pm_ops sst_byt_pm_ops = { |
| 463 | .suspend_noirq = sst_byt_pcm_dev_suspend_noirq, |
| 464 | .suspend_late = sst_byt_pcm_dev_suspend_late, |
| 465 | .resume_early = sst_byt_pcm_dev_resume_early, |
| 466 | .resume = sst_byt_pcm_dev_resume, |
| 467 | }; |
| 468 | |
| 469 | #define SST_BYT_PM_OPS (&sst_byt_pm_ops) |
| 470 | #else |
| 471 | #define SST_BYT_PM_OPS NULL |
| 472 | #endif |
| 473 | |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 474 | static int sst_byt_pcm_dev_probe(struct platform_device *pdev) |
| 475 | { |
| 476 | struct sst_pdata *sst_pdata = dev_get_platdata(&pdev->dev); |
| 477 | int ret; |
| 478 | |
| 479 | ret = sst_byt_dsp_init(&pdev->dev, sst_pdata); |
| 480 | if (ret < 0) |
| 481 | return -ENODEV; |
| 482 | |
| 483 | ret = snd_soc_register_platform(&pdev->dev, &byt_soc_platform); |
| 484 | if (ret < 0) |
| 485 | goto err_plat; |
| 486 | |
| 487 | ret = snd_soc_register_component(&pdev->dev, &byt_dai_component, |
| 488 | byt_dais, ARRAY_SIZE(byt_dais)); |
| 489 | if (ret < 0) |
| 490 | goto err_comp; |
| 491 | |
| 492 | return 0; |
| 493 | |
| 494 | err_comp: |
| 495 | snd_soc_unregister_platform(&pdev->dev); |
| 496 | err_plat: |
| 497 | sst_byt_dsp_free(&pdev->dev, sst_pdata); |
| 498 | return ret; |
| 499 | } |
| 500 | |
| 501 | static int sst_byt_pcm_dev_remove(struct platform_device *pdev) |
| 502 | { |
| 503 | struct sst_pdata *sst_pdata = dev_get_platdata(&pdev->dev); |
| 504 | |
| 505 | snd_soc_unregister_platform(&pdev->dev); |
| 506 | snd_soc_unregister_component(&pdev->dev); |
| 507 | sst_byt_dsp_free(&pdev->dev, sst_pdata); |
| 508 | |
| 509 | return 0; |
| 510 | } |
| 511 | |
| 512 | static struct platform_driver sst_byt_pcm_driver = { |
| 513 | .driver = { |
| 514 | .name = "baytrail-pcm-audio", |
| 515 | .owner = THIS_MODULE, |
Liam Girdwood | af94aa5 | 2014-05-08 16:07:26 +0300 | [diff] [blame^] | 516 | .pm = SST_BYT_PM_OPS, |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 517 | }, |
| 518 | |
| 519 | .probe = sst_byt_pcm_dev_probe, |
| 520 | .remove = sst_byt_pcm_dev_remove, |
| 521 | }; |
| 522 | module_platform_driver(sst_byt_pcm_driver); |
| 523 | |
| 524 | MODULE_AUTHOR("Jarkko Nikula"); |
| 525 | MODULE_DESCRIPTION("Baytrail PCM"); |
| 526 | MODULE_LICENSE("GPL v2"); |
| 527 | MODULE_ALIAS("platform:baytrail-pcm-audio"); |