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" |
Jie Yang | 66a6fd9 | 2015-04-02 15:37:03 +0800 | [diff] [blame] | 23 | #include "../common/sst-dsp-priv.h" |
| 24 | #include "../common/sst-dsp.h" |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 25 | |
Kuninori Morimoto | 81dc5f3 | 2018-01-29 02:42:02 +0000 | [diff] [blame] | 26 | #define DRV_NAME "byt-dai" |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 27 | #define BYT_PCM_COUNT 2 |
| 28 | |
| 29 | static const struct snd_pcm_hardware sst_byt_pcm_hardware = { |
| 30 | .info = SNDRV_PCM_INFO_MMAP | |
| 31 | SNDRV_PCM_INFO_MMAP_VALID | |
| 32 | SNDRV_PCM_INFO_INTERLEAVED | |
| 33 | SNDRV_PCM_INFO_PAUSE | |
| 34 | SNDRV_PCM_INFO_RESUME, |
| 35 | .formats = SNDRV_PCM_FMTBIT_S16_LE | |
Jie Yang | 8e89761 | 2014-07-14 17:37:36 +0800 | [diff] [blame] | 36 | SNDRV_PCM_FMTBIT_S24_LE, |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 37 | .period_bytes_min = 384, |
| 38 | .period_bytes_max = 48000, |
| 39 | .periods_min = 2, |
| 40 | .periods_max = 250, |
| 41 | .buffer_bytes_max = 96000, |
| 42 | }; |
| 43 | |
| 44 | /* private data for each PCM DSP stream */ |
| 45 | struct sst_byt_pcm_data { |
| 46 | struct sst_byt_stream *stream; |
| 47 | struct snd_pcm_substream *substream; |
| 48 | struct mutex mutex; |
Jarkko Nikula | c83649e | 2014-05-08 16:07:21 +0300 | [diff] [blame] | 49 | |
| 50 | /* latest DSP DMA hw pointer */ |
| 51 | u32 hw_ptr; |
Liam Girdwood | af94aa5 | 2014-05-08 16:07:26 +0300 | [diff] [blame] | 52 | |
| 53 | struct work_struct work; |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 54 | }; |
| 55 | |
| 56 | /* private data for the driver */ |
| 57 | struct sst_byt_priv_data { |
| 58 | /* runtime DSP */ |
| 59 | struct sst_byt *byt; |
| 60 | |
| 61 | /* DAI data */ |
| 62 | struct sst_byt_pcm_data pcm[BYT_PCM_COUNT]; |
Jarkko Nikula | b80d19c | 2014-08-11 14:15:38 +0300 | [diff] [blame] | 63 | |
| 64 | /* flag indicating is stream context restore needed after suspend */ |
| 65 | bool restore_stream; |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | /* this may get called several times by oss emulation */ |
| 69 | static int sst_byt_pcm_hw_params(struct snd_pcm_substream *substream, |
| 70 | struct snd_pcm_hw_params *params) |
| 71 | { |
| 72 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Kuninori Morimoto | 81dc5f3 | 2018-01-29 02:42:02 +0000 | [diff] [blame] | 73 | struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, DRV_NAME); |
| 74 | struct sst_byt_priv_data *pdata = snd_soc_component_get_drvdata(component); |
Liam Girdwood | 3a46c7b | 2014-05-14 17:20:53 +0300 | [diff] [blame] | 75 | struct sst_byt_pcm_data *pcm_data = &pdata->pcm[substream->stream]; |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 76 | struct sst_byt *byt = pdata->byt; |
| 77 | u32 rate, bits; |
| 78 | u8 channels; |
| 79 | int ret, playback = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK); |
| 80 | |
| 81 | dev_dbg(rtd->dev, "PCM: hw_params, pcm_data %p\n", pcm_data); |
| 82 | |
| 83 | ret = sst_byt_stream_type(byt, pcm_data->stream, |
| 84 | 1, 1, !playback); |
| 85 | if (ret < 0) { |
| 86 | dev_err(rtd->dev, "failed to set stream format %d\n", ret); |
| 87 | return ret; |
| 88 | } |
| 89 | |
| 90 | rate = params_rate(params); |
| 91 | ret = sst_byt_stream_set_rate(byt, pcm_data->stream, rate); |
| 92 | if (ret < 0) { |
| 93 | dev_err(rtd->dev, "could not set rate %d\n", rate); |
| 94 | return ret; |
| 95 | } |
| 96 | |
| 97 | bits = snd_pcm_format_width(params_format(params)); |
| 98 | ret = sst_byt_stream_set_bits(byt, pcm_data->stream, bits); |
| 99 | if (ret < 0) { |
| 100 | dev_err(rtd->dev, "could not set formats %d\n", |
| 101 | params_rate(params)); |
| 102 | return ret; |
| 103 | } |
| 104 | |
| 105 | channels = (u8)(params_channels(params) & 0xF); |
| 106 | ret = sst_byt_stream_set_channels(byt, pcm_data->stream, channels); |
| 107 | if (ret < 0) { |
| 108 | dev_err(rtd->dev, "could not set channels %d\n", |
| 109 | params_rate(params)); |
| 110 | return ret; |
| 111 | } |
| 112 | |
| 113 | snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params)); |
| 114 | |
| 115 | ret = sst_byt_stream_buffer(byt, pcm_data->stream, |
| 116 | substream->dma_buffer.addr, |
| 117 | params_buffer_bytes(params)); |
| 118 | if (ret < 0) { |
| 119 | dev_err(rtd->dev, "PCM: failed to set DMA buffer %d\n", ret); |
| 120 | return ret; |
| 121 | } |
| 122 | |
| 123 | ret = sst_byt_stream_commit(byt, pcm_data->stream); |
| 124 | if (ret < 0) { |
| 125 | dev_err(rtd->dev, "PCM: failed stream commit %d\n", ret); |
| 126 | return ret; |
| 127 | } |
| 128 | |
| 129 | return 0; |
| 130 | } |
| 131 | |
| 132 | static int sst_byt_pcm_hw_free(struct snd_pcm_substream *substream) |
| 133 | { |
| 134 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 135 | |
| 136 | dev_dbg(rtd->dev, "PCM: hw_free\n"); |
| 137 | snd_pcm_lib_free_pages(substream); |
| 138 | |
| 139 | return 0; |
| 140 | } |
| 141 | |
Liam Girdwood | af94aa5 | 2014-05-08 16:07:26 +0300 | [diff] [blame] | 142 | static int sst_byt_pcm_restore_stream_context(struct snd_pcm_substream *substream) |
| 143 | { |
| 144 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Kuninori Morimoto | 81dc5f3 | 2018-01-29 02:42:02 +0000 | [diff] [blame] | 145 | struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, DRV_NAME); |
| 146 | struct sst_byt_priv_data *pdata = snd_soc_component_get_drvdata(component); |
Liam Girdwood | 3a46c7b | 2014-05-14 17:20:53 +0300 | [diff] [blame] | 147 | struct sst_byt_pcm_data *pcm_data = &pdata->pcm[substream->stream]; |
Liam Girdwood | af94aa5 | 2014-05-08 16:07:26 +0300 | [diff] [blame] | 148 | struct sst_byt *byt = pdata->byt; |
| 149 | int ret; |
| 150 | |
| 151 | /* commit stream using existing stream params */ |
| 152 | ret = sst_byt_stream_commit(byt, pcm_data->stream); |
| 153 | if (ret < 0) { |
| 154 | dev_err(rtd->dev, "PCM: failed stream commit %d\n", ret); |
| 155 | return ret; |
| 156 | } |
| 157 | |
| 158 | sst_byt_stream_start(byt, pcm_data->stream, pcm_data->hw_ptr); |
| 159 | |
| 160 | dev_dbg(rtd->dev, "stream context restored at offset %d\n", |
| 161 | pcm_data->hw_ptr); |
| 162 | |
| 163 | return 0; |
| 164 | } |
| 165 | |
| 166 | static void sst_byt_pcm_work(struct work_struct *work) |
| 167 | { |
| 168 | struct sst_byt_pcm_data *pcm_data = |
| 169 | container_of(work, struct sst_byt_pcm_data, work); |
| 170 | |
Kevin Strasser | 2fa190c | 2014-05-19 11:14:23 +0300 | [diff] [blame] | 171 | if (snd_pcm_running(pcm_data->substream)) |
| 172 | sst_byt_pcm_restore_stream_context(pcm_data->substream); |
Liam Girdwood | af94aa5 | 2014-05-08 16:07:26 +0300 | [diff] [blame] | 173 | } |
| 174 | |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 175 | static int sst_byt_pcm_trigger(struct snd_pcm_substream *substream, int cmd) |
| 176 | { |
| 177 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Kuninori Morimoto | 81dc5f3 | 2018-01-29 02:42:02 +0000 | [diff] [blame] | 178 | struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, DRV_NAME); |
| 179 | struct sst_byt_priv_data *pdata = snd_soc_component_get_drvdata(component); |
Liam Girdwood | 3a46c7b | 2014-05-14 17:20:53 +0300 | [diff] [blame] | 180 | struct sst_byt_pcm_data *pcm_data = &pdata->pcm[substream->stream]; |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 181 | struct sst_byt *byt = pdata->byt; |
| 182 | |
| 183 | dev_dbg(rtd->dev, "PCM: trigger %d\n", cmd); |
| 184 | |
| 185 | switch (cmd) { |
| 186 | case SNDRV_PCM_TRIGGER_START: |
Jarkko Nikula | 58dcc48 | 2014-05-26 16:56:30 +0300 | [diff] [blame] | 187 | pcm_data->hw_ptr = 0; |
Jarkko Nikula | a6686ed | 2014-05-08 16:07:23 +0300 | [diff] [blame] | 188 | sst_byt_stream_start(byt, pcm_data->stream, 0); |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 189 | break; |
| 190 | case SNDRV_PCM_TRIGGER_RESUME: |
Pierre-Louis Bossart | e295450 | 2018-12-16 16:49:07 -0600 | [diff] [blame] | 191 | if (pdata->restore_stream) |
Jarkko Nikula | b80d19c | 2014-08-11 14:15:38 +0300 | [diff] [blame] | 192 | schedule_work(&pcm_data->work); |
| 193 | else |
| 194 | sst_byt_stream_resume(byt, pcm_data->stream); |
Liam Girdwood | af94aa5 | 2014-05-08 16:07:26 +0300 | [diff] [blame] | 195 | break; |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 196 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
| 197 | sst_byt_stream_resume(byt, pcm_data->stream); |
| 198 | break; |
| 199 | case SNDRV_PCM_TRIGGER_STOP: |
| 200 | sst_byt_stream_stop(byt, pcm_data->stream); |
| 201 | break; |
| 202 | case SNDRV_PCM_TRIGGER_SUSPEND: |
Jarkko Nikula | b80d19c | 2014-08-11 14:15:38 +0300 | [diff] [blame] | 203 | pdata->restore_stream = false; |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 204 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
| 205 | sst_byt_stream_pause(byt, pcm_data->stream); |
| 206 | break; |
| 207 | default: |
| 208 | break; |
| 209 | } |
| 210 | |
| 211 | return 0; |
| 212 | } |
| 213 | |
| 214 | static u32 byt_notify_pointer(struct sst_byt_stream *stream, void *data) |
| 215 | { |
| 216 | struct sst_byt_pcm_data *pcm_data = data; |
| 217 | struct snd_pcm_substream *substream = pcm_data->substream; |
| 218 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 219 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Kuninori Morimoto | 81dc5f3 | 2018-01-29 02:42:02 +0000 | [diff] [blame] | 220 | struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, DRV_NAME); |
| 221 | struct sst_byt_priv_data *pdata = snd_soc_component_get_drvdata(component); |
Jarkko Nikula | c83649e | 2014-05-08 16:07:21 +0300 | [diff] [blame] | 222 | struct sst_byt *byt = pdata->byt; |
| 223 | u32 pos, hw_pos; |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 224 | |
Jarkko Nikula | c83649e | 2014-05-08 16:07:21 +0300 | [diff] [blame] | 225 | hw_pos = sst_byt_get_dsp_position(byt, pcm_data->stream, |
| 226 | snd_pcm_lib_buffer_bytes(substream)); |
| 227 | pcm_data->hw_ptr = hw_pos; |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 228 | pos = frames_to_bytes(runtime, |
| 229 | (runtime->control->appl_ptr % |
| 230 | runtime->buffer_size)); |
| 231 | |
Jarkko Nikula | c83649e | 2014-05-08 16:07:21 +0300 | [diff] [blame] | 232 | 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] | 233 | |
| 234 | snd_pcm_period_elapsed(substream); |
| 235 | return pos; |
| 236 | } |
| 237 | |
| 238 | static snd_pcm_uframes_t sst_byt_pcm_pointer(struct snd_pcm_substream *substream) |
| 239 | { |
| 240 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 241 | struct snd_pcm_runtime *runtime = substream->runtime; |
Kuninori Morimoto | 81dc5f3 | 2018-01-29 02:42:02 +0000 | [diff] [blame] | 242 | struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, DRV_NAME); |
| 243 | struct sst_byt_priv_data *pdata = snd_soc_component_get_drvdata(component); |
Liam Girdwood | 3a46c7b | 2014-05-14 17:20:53 +0300 | [diff] [blame] | 244 | struct sst_byt_pcm_data *pcm_data = &pdata->pcm[substream->stream]; |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 245 | |
Jarkko Nikula | c83649e | 2014-05-08 16:07:21 +0300 | [diff] [blame] | 246 | 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] | 247 | |
Jarkko Nikula | c83649e | 2014-05-08 16:07:21 +0300 | [diff] [blame] | 248 | return bytes_to_frames(runtime, pcm_data->hw_ptr); |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | static int sst_byt_pcm_open(struct snd_pcm_substream *substream) |
| 252 | { |
| 253 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Kuninori Morimoto | 81dc5f3 | 2018-01-29 02:42:02 +0000 | [diff] [blame] | 254 | struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, DRV_NAME); |
| 255 | struct sst_byt_priv_data *pdata = snd_soc_component_get_drvdata(component); |
Liam Girdwood | 3a46c7b | 2014-05-14 17:20:53 +0300 | [diff] [blame] | 256 | struct sst_byt_pcm_data *pcm_data = &pdata->pcm[substream->stream]; |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 257 | struct sst_byt *byt = pdata->byt; |
| 258 | |
| 259 | dev_dbg(rtd->dev, "PCM: open\n"); |
| 260 | |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 261 | mutex_lock(&pcm_data->mutex); |
| 262 | |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 263 | pcm_data->substream = substream; |
| 264 | |
| 265 | snd_soc_set_runtime_hwparams(substream, &sst_byt_pcm_hardware); |
| 266 | |
Jarkko Nikula | 8c44b2b | 2014-05-15 14:41:48 +0300 | [diff] [blame] | 267 | pcm_data->stream = sst_byt_stream_new(byt, substream->stream + 1, |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 268 | byt_notify_pointer, pcm_data); |
| 269 | if (pcm_data->stream == NULL) { |
| 270 | dev_err(rtd->dev, "failed to create stream\n"); |
| 271 | mutex_unlock(&pcm_data->mutex); |
| 272 | return -EINVAL; |
| 273 | } |
| 274 | |
| 275 | mutex_unlock(&pcm_data->mutex); |
| 276 | return 0; |
| 277 | } |
| 278 | |
| 279 | static int sst_byt_pcm_close(struct snd_pcm_substream *substream) |
| 280 | { |
| 281 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Kuninori Morimoto | 81dc5f3 | 2018-01-29 02:42:02 +0000 | [diff] [blame] | 282 | struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, DRV_NAME); |
| 283 | struct sst_byt_priv_data *pdata = snd_soc_component_get_drvdata(component); |
Liam Girdwood | 3a46c7b | 2014-05-14 17:20:53 +0300 | [diff] [blame] | 284 | struct sst_byt_pcm_data *pcm_data = &pdata->pcm[substream->stream]; |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 285 | struct sst_byt *byt = pdata->byt; |
| 286 | int ret; |
| 287 | |
| 288 | dev_dbg(rtd->dev, "PCM: close\n"); |
| 289 | |
Kevin Strasser | 2fa190c | 2014-05-19 11:14:23 +0300 | [diff] [blame] | 290 | cancel_work_sync(&pcm_data->work); |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 291 | mutex_lock(&pcm_data->mutex); |
| 292 | ret = sst_byt_stream_free(byt, pcm_data->stream); |
| 293 | if (ret < 0) { |
| 294 | dev_dbg(rtd->dev, "Free stream fail\n"); |
| 295 | goto out; |
| 296 | } |
| 297 | pcm_data->stream = NULL; |
| 298 | |
| 299 | out: |
| 300 | mutex_unlock(&pcm_data->mutex); |
| 301 | return ret; |
| 302 | } |
| 303 | |
| 304 | static int sst_byt_pcm_mmap(struct snd_pcm_substream *substream, |
| 305 | struct vm_area_struct *vma) |
| 306 | { |
| 307 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 308 | |
| 309 | dev_dbg(rtd->dev, "PCM: mmap\n"); |
| 310 | return snd_pcm_lib_default_mmap(substream, vma); |
| 311 | } |
| 312 | |
Arvind Yadav | f2c402b | 2017-08-14 11:26:27 +0530 | [diff] [blame] | 313 | static const struct snd_pcm_ops sst_byt_pcm_ops = { |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 314 | .open = sst_byt_pcm_open, |
| 315 | .close = sst_byt_pcm_close, |
| 316 | .ioctl = snd_pcm_lib_ioctl, |
| 317 | .hw_params = sst_byt_pcm_hw_params, |
| 318 | .hw_free = sst_byt_pcm_hw_free, |
| 319 | .trigger = sst_byt_pcm_trigger, |
| 320 | .pointer = sst_byt_pcm_pointer, |
| 321 | .mmap = sst_byt_pcm_mmap, |
| 322 | }; |
| 323 | |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 324 | static int sst_byt_pcm_new(struct snd_soc_pcm_runtime *rtd) |
| 325 | { |
| 326 | struct snd_pcm *pcm = rtd->pcm; |
| 327 | size_t size; |
Kuninori Morimoto | 81dc5f3 | 2018-01-29 02:42:02 +0000 | [diff] [blame] | 328 | struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, DRV_NAME); |
| 329 | struct sst_pdata *pdata = dev_get_platdata(component->dev); |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 330 | int ret = 0; |
| 331 | |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 332 | if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream || |
| 333 | pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream) { |
| 334 | size = sst_byt_pcm_hardware.buffer_bytes_max; |
| 335 | ret = snd_pcm_lib_preallocate_pages_for_all(pcm, |
| 336 | SNDRV_DMA_TYPE_DEV, |
Jarkko Nikula | dfe1951 | 2014-05-09 16:47:44 +0300 | [diff] [blame] | 337 | pdata->dma_dev, |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 338 | size, size); |
| 339 | if (ret) { |
| 340 | dev_err(rtd->dev, "dma buffer allocation failed %d\n", |
| 341 | ret); |
| 342 | return ret; |
| 343 | } |
| 344 | } |
| 345 | |
| 346 | return ret; |
| 347 | } |
| 348 | |
| 349 | static struct snd_soc_dai_driver byt_dais[] = { |
| 350 | { |
Liam Girdwood | 49fee17 | 2014-05-14 17:20:54 +0300 | [diff] [blame] | 351 | .name = "Baytrail PCM", |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 352 | .playback = { |
| 353 | .stream_name = "System Playback", |
| 354 | .channels_min = 2, |
| 355 | .channels_max = 2, |
| 356 | .rates = SNDRV_PCM_RATE_48000, |
| 357 | .formats = SNDRV_PCM_FMTBIT_S24_3LE | |
| 358 | SNDRV_PCM_FMTBIT_S16_LE, |
| 359 | }, |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 360 | .capture = { |
| 361 | .stream_name = "Analog Capture", |
| 362 | .channels_min = 2, |
| 363 | .channels_max = 2, |
| 364 | .rates = SNDRV_PCM_RATE_48000, |
| 365 | .formats = SNDRV_PCM_FMTBIT_S16_LE, |
| 366 | }, |
| 367 | }, |
| 368 | }; |
| 369 | |
Kuninori Morimoto | 81dc5f3 | 2018-01-29 02:42:02 +0000 | [diff] [blame] | 370 | static int sst_byt_pcm_probe(struct snd_soc_component *component) |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 371 | { |
Kuninori Morimoto | 81dc5f3 | 2018-01-29 02:42:02 +0000 | [diff] [blame] | 372 | struct sst_pdata *plat_data = dev_get_platdata(component->dev); |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 373 | struct sst_byt_priv_data *priv_data; |
| 374 | int i; |
| 375 | |
| 376 | if (!plat_data) |
| 377 | return -ENODEV; |
| 378 | |
Kuninori Morimoto | 81dc5f3 | 2018-01-29 02:42:02 +0000 | [diff] [blame] | 379 | priv_data = devm_kzalloc(component->dev, sizeof(*priv_data), |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 380 | GFP_KERNEL); |
Julia Lawall | 3f317c9 | 2015-12-20 12:15:53 +0100 | [diff] [blame] | 381 | if (!priv_data) |
| 382 | return -ENOMEM; |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 383 | priv_data->byt = plat_data->dsp; |
Kuninori Morimoto | 81dc5f3 | 2018-01-29 02:42:02 +0000 | [diff] [blame] | 384 | snd_soc_component_set_drvdata(component, priv_data); |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 385 | |
Liam Girdwood | 49fee17 | 2014-05-14 17:20:54 +0300 | [diff] [blame] | 386 | for (i = 0; i < BYT_PCM_COUNT; i++) { |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 387 | mutex_init(&priv_data->pcm[i].mutex); |
Liam Girdwood | af94aa5 | 2014-05-08 16:07:26 +0300 | [diff] [blame] | 388 | INIT_WORK(&priv_data->pcm[i].work, sst_byt_pcm_work); |
| 389 | } |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 390 | |
| 391 | return 0; |
| 392 | } |
| 393 | |
Kuninori Morimoto | 81dc5f3 | 2018-01-29 02:42:02 +0000 | [diff] [blame] | 394 | static const struct snd_soc_component_driver byt_dai_component = { |
| 395 | .name = DRV_NAME, |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 396 | .probe = sst_byt_pcm_probe, |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 397 | .ops = &sst_byt_pcm_ops, |
| 398 | .pcm_new = sst_byt_pcm_new, |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 399 | }; |
| 400 | |
Liam Girdwood | af94aa5 | 2014-05-08 16:07:26 +0300 | [diff] [blame] | 401 | #ifdef CONFIG_PM |
Liam Girdwood | af94aa5 | 2014-05-08 16:07:26 +0300 | [diff] [blame] | 402 | static int sst_byt_pcm_dev_suspend_late(struct device *dev) |
| 403 | { |
| 404 | struct sst_pdata *sst_pdata = dev_get_platdata(dev); |
Jarkko Nikula | b80d19c | 2014-08-11 14:15:38 +0300 | [diff] [blame] | 405 | struct sst_byt_priv_data *priv_data = dev_get_drvdata(dev); |
Liam Girdwood | af94aa5 | 2014-05-08 16:07:26 +0300 | [diff] [blame] | 406 | int ret; |
| 407 | |
| 408 | dev_dbg(dev, "suspending late\n"); |
| 409 | |
| 410 | ret = sst_byt_dsp_suspend_late(dev, sst_pdata); |
| 411 | if (ret < 0) { |
| 412 | dev_err(dev, "failed to suspend %d\n", ret); |
| 413 | return ret; |
| 414 | } |
| 415 | |
Jarkko Nikula | b80d19c | 2014-08-11 14:15:38 +0300 | [diff] [blame] | 416 | priv_data->restore_stream = true; |
| 417 | |
Liam Girdwood | af94aa5 | 2014-05-08 16:07:26 +0300 | [diff] [blame] | 418 | return ret; |
| 419 | } |
| 420 | |
| 421 | static int sst_byt_pcm_dev_resume_early(struct device *dev) |
| 422 | { |
| 423 | struct sst_pdata *sst_pdata = dev_get_platdata(dev); |
Jarkko Nikula | 9246539 | 2014-08-11 14:15:37 +0300 | [diff] [blame] | 424 | int ret; |
Liam Girdwood | af94aa5 | 2014-05-08 16:07:26 +0300 | [diff] [blame] | 425 | |
| 426 | dev_dbg(dev, "resume early\n"); |
| 427 | |
| 428 | /* load fw and boot DSP */ |
Jarkko Nikula | 9246539 | 2014-08-11 14:15:37 +0300 | [diff] [blame] | 429 | ret = sst_byt_dsp_boot(dev, sst_pdata); |
| 430 | if (ret) |
| 431 | return ret; |
Liam Girdwood | af94aa5 | 2014-05-08 16:07:26 +0300 | [diff] [blame] | 432 | |
| 433 | /* wait for FW to finish booting */ |
| 434 | return sst_byt_dsp_wait_for_ready(dev, sst_pdata); |
| 435 | } |
| 436 | |
| 437 | static const struct dev_pm_ops sst_byt_pm_ops = { |
Liam Girdwood | af94aa5 | 2014-05-08 16:07:26 +0300 | [diff] [blame] | 438 | .suspend_late = sst_byt_pcm_dev_suspend_late, |
| 439 | .resume_early = sst_byt_pcm_dev_resume_early, |
Liam Girdwood | af94aa5 | 2014-05-08 16:07:26 +0300 | [diff] [blame] | 440 | }; |
| 441 | |
| 442 | #define SST_BYT_PM_OPS (&sst_byt_pm_ops) |
| 443 | #else |
| 444 | #define SST_BYT_PM_OPS NULL |
| 445 | #endif |
| 446 | |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 447 | static int sst_byt_pcm_dev_probe(struct platform_device *pdev) |
| 448 | { |
| 449 | struct sst_pdata *sst_pdata = dev_get_platdata(&pdev->dev); |
| 450 | int ret; |
| 451 | |
| 452 | ret = sst_byt_dsp_init(&pdev->dev, sst_pdata); |
| 453 | if (ret < 0) |
| 454 | return -ENODEV; |
| 455 | |
Kuninori Morimoto | 81dc5f3 | 2018-01-29 02:42:02 +0000 | [diff] [blame] | 456 | ret = devm_snd_soc_register_component(&pdev->dev, &byt_dai_component, |
| 457 | byt_dais, ARRAY_SIZE(byt_dais)); |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 458 | if (ret < 0) |
| 459 | goto err_plat; |
| 460 | |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 461 | return 0; |
| 462 | |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 463 | err_plat: |
| 464 | sst_byt_dsp_free(&pdev->dev, sst_pdata); |
| 465 | return ret; |
| 466 | } |
| 467 | |
| 468 | static int sst_byt_pcm_dev_remove(struct platform_device *pdev) |
| 469 | { |
| 470 | struct sst_pdata *sst_pdata = dev_get_platdata(&pdev->dev); |
| 471 | |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 472 | sst_byt_dsp_free(&pdev->dev, sst_pdata); |
| 473 | |
| 474 | return 0; |
| 475 | } |
| 476 | |
| 477 | static struct platform_driver sst_byt_pcm_driver = { |
| 478 | .driver = { |
| 479 | .name = "baytrail-pcm-audio", |
Liam Girdwood | af94aa5 | 2014-05-08 16:07:26 +0300 | [diff] [blame] | 480 | .pm = SST_BYT_PM_OPS, |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 481 | }, |
| 482 | |
| 483 | .probe = sst_byt_pcm_dev_probe, |
| 484 | .remove = sst_byt_pcm_dev_remove, |
| 485 | }; |
| 486 | module_platform_driver(sst_byt_pcm_driver); |
| 487 | |
| 488 | MODULE_AUTHOR("Jarkko Nikula"); |
| 489 | MODULE_DESCRIPTION("Baytrail PCM"); |
| 490 | MODULE_LICENSE("GPL v2"); |
| 491 | MODULE_ALIAS("platform:baytrail-pcm-audio"); |