Kuninori Morimoto | b3ed4c8 | 2018-07-02 06:24:57 +0000 | [diff] [blame^] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | // |
| 3 | // soc-compress.c -- ALSA SoC Compress |
| 4 | // |
| 5 | // Copyright (C) 2012 Intel Corp. |
| 6 | // |
| 7 | // Authors: Namarta Kohli <namartax.kohli@intel.com> |
| 8 | // Ramesh Babu K V <ramesh.babu@linux.intel.com> |
| 9 | // Vinod Koul <vinod.koul@linux.intel.com> |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 10 | |
| 11 | #include <linux/kernel.h> |
| 12 | #include <linux/init.h> |
| 13 | #include <linux/delay.h> |
| 14 | #include <linux/slab.h> |
| 15 | #include <linux/workqueue.h> |
| 16 | #include <sound/core.h> |
| 17 | #include <sound/compress_params.h> |
| 18 | #include <sound/compress_driver.h> |
| 19 | #include <sound/soc.h> |
| 20 | #include <sound/initval.h> |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 21 | #include <sound/soc-dpcm.h> |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 22 | |
Charles Keepax | 1e57b82 | 2018-04-24 16:39:03 +0100 | [diff] [blame] | 23 | static int soc_compr_components_open(struct snd_compr_stream *cstream, |
| 24 | struct snd_soc_component **last) |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 25 | { |
| 26 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 27 | struct snd_soc_component *component; |
| 28 | struct snd_soc_rtdcom_list *rtdcom; |
Charles Keepax | 1e57b82 | 2018-04-24 16:39:03 +0100 | [diff] [blame] | 29 | int ret; |
| 30 | |
| 31 | for_each_rtdcom(rtd, rtdcom) { |
| 32 | component = rtdcom->component; |
| 33 | |
| 34 | if (!component->driver->compr_ops || |
| 35 | !component->driver->compr_ops->open) |
| 36 | continue; |
| 37 | |
| 38 | ret = component->driver->compr_ops->open(cstream); |
| 39 | if (ret < 0) { |
| 40 | dev_err(component->dev, |
| 41 | "Compress ASoC: can't open platform %s: %d\n", |
| 42 | component->name, ret); |
| 43 | |
| 44 | *last = component; |
| 45 | return ret; |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | *last = NULL; |
| 50 | return 0; |
| 51 | } |
| 52 | |
| 53 | static int soc_compr_components_free(struct snd_compr_stream *cstream, |
| 54 | struct snd_soc_component *last) |
| 55 | { |
| 56 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
| 57 | struct snd_soc_component *component; |
| 58 | struct snd_soc_rtdcom_list *rtdcom; |
| 59 | |
| 60 | for_each_rtdcom(rtd, rtdcom) { |
| 61 | component = rtdcom->component; |
| 62 | |
| 63 | if (component == last) |
| 64 | break; |
| 65 | |
| 66 | if (!component->driver->compr_ops || |
| 67 | !component->driver->compr_ops->free) |
| 68 | continue; |
| 69 | |
| 70 | component->driver->compr_ops->free(cstream); |
| 71 | } |
| 72 | |
| 73 | return 0; |
| 74 | } |
| 75 | |
| 76 | static int soc_compr_open(struct snd_compr_stream *cstream) |
| 77 | { |
| 78 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
| 79 | struct snd_soc_component *component; |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 80 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Charles Keepax | 572e6c8 | 2018-04-24 16:39:01 +0100 | [diff] [blame] | 81 | int ret; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 82 | |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 83 | mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); |
| 84 | |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 85 | if (cpu_dai->driver->cops && cpu_dai->driver->cops->startup) { |
| 86 | ret = cpu_dai->driver->cops->startup(cstream, cpu_dai); |
| 87 | if (ret < 0) { |
Charles Keepax | 141dfc9 | 2018-01-26 13:08:45 +0000 | [diff] [blame] | 88 | dev_err(cpu_dai->dev, |
| 89 | "Compress ASoC: can't open interface %s: %d\n", |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 90 | cpu_dai->name, ret); |
| 91 | goto out; |
| 92 | } |
| 93 | } |
| 94 | |
Charles Keepax | 1e57b82 | 2018-04-24 16:39:03 +0100 | [diff] [blame] | 95 | ret = soc_compr_components_open(cstream, &component); |
| 96 | if (ret < 0) |
| 97 | goto machine_err; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 98 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 99 | if (rtd->dai_link->compr_ops && rtd->dai_link->compr_ops->startup) { |
| 100 | ret = rtd->dai_link->compr_ops->startup(cstream); |
| 101 | if (ret < 0) { |
Charles Keepax | 141dfc9 | 2018-01-26 13:08:45 +0000 | [diff] [blame] | 102 | dev_err(rtd->dev, |
| 103 | "Compress ASoC: %s startup failed: %d\n", |
| 104 | rtd->dai_link->name, ret); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 105 | goto machine_err; |
| 106 | } |
| 107 | } |
| 108 | |
Lars-Peter Clausen | 24894b7 | 2014-03-05 13:17:43 +0100 | [diff] [blame] | 109 | snd_soc_runtime_activate(rtd, cstream->direction); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 110 | |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 111 | mutex_unlock(&rtd->pcm_mutex); |
| 112 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 113 | return 0; |
| 114 | |
| 115 | machine_err: |
Charles Keepax | 1e57b82 | 2018-04-24 16:39:03 +0100 | [diff] [blame] | 116 | soc_compr_components_free(cstream, component); |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 117 | |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 118 | if (cpu_dai->driver->cops && cpu_dai->driver->cops->shutdown) |
| 119 | cpu_dai->driver->cops->shutdown(cstream, cpu_dai); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 120 | out: |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 121 | mutex_unlock(&rtd->pcm_mutex); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 122 | return ret; |
| 123 | } |
| 124 | |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 125 | static int soc_compr_open_fe(struct snd_compr_stream *cstream) |
| 126 | { |
| 127 | struct snd_soc_pcm_runtime *fe = cstream->private_data; |
Satish Babu Patakokila | 01b8ced | 2017-06-16 17:33:40 -0700 | [diff] [blame] | 128 | struct snd_pcm_substream *fe_substream = |
| 129 | fe->pcm->streams[cstream->direction].substream; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 130 | struct snd_soc_component *component; |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 131 | struct snd_soc_dai *cpu_dai = fe->cpu_dai; |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 132 | struct snd_soc_dpcm *dpcm; |
| 133 | struct snd_soc_dapm_widget_list *list; |
| 134 | int stream; |
Charles Keepax | 572e6c8 | 2018-04-24 16:39:01 +0100 | [diff] [blame] | 135 | int ret; |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 136 | |
| 137 | if (cstream->direction == SND_COMPRESS_PLAYBACK) |
| 138 | stream = SNDRV_PCM_STREAM_PLAYBACK; |
| 139 | else |
| 140 | stream = SNDRV_PCM_STREAM_CAPTURE; |
| 141 | |
| 142 | mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME); |
| 143 | |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 144 | if (cpu_dai->driver->cops && cpu_dai->driver->cops->startup) { |
| 145 | ret = cpu_dai->driver->cops->startup(cstream, cpu_dai); |
| 146 | if (ret < 0) { |
Charles Keepax | 141dfc9 | 2018-01-26 13:08:45 +0000 | [diff] [blame] | 147 | dev_err(cpu_dai->dev, |
| 148 | "Compress ASoC: can't open interface %s: %d\n", |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 149 | cpu_dai->name, ret); |
| 150 | goto out; |
| 151 | } |
| 152 | } |
| 153 | |
Charles Keepax | 1e57b82 | 2018-04-24 16:39:03 +0100 | [diff] [blame] | 154 | ret = soc_compr_components_open(cstream, &component); |
| 155 | if (ret < 0) |
| 156 | goto machine_err; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 157 | |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 158 | if (fe->dai_link->compr_ops && fe->dai_link->compr_ops->startup) { |
| 159 | ret = fe->dai_link->compr_ops->startup(cstream); |
| 160 | if (ret < 0) { |
Charles Keepax | 141dfc9 | 2018-01-26 13:08:45 +0000 | [diff] [blame] | 161 | pr_err("Compress ASoC: %s startup failed: %d\n", |
| 162 | fe->dai_link->name, ret); |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 163 | goto machine_err; |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | fe->dpcm[stream].runtime = fe_substream->runtime; |
| 168 | |
Qiao Zhou | 8f70e51 | 2014-09-10 17:54:07 +0800 | [diff] [blame] | 169 | ret = dpcm_path_get(fe, stream, &list); |
Qiao Zhou | 2e4ec1c | 2014-09-12 09:41:31 +0800 | [diff] [blame] | 170 | if (ret < 0) |
Qiao Zhou | 8f70e51 | 2014-09-10 17:54:07 +0800 | [diff] [blame] | 171 | goto fe_err; |
Qiao Zhou | 2e4ec1c | 2014-09-12 09:41:31 +0800 | [diff] [blame] | 172 | else if (ret == 0) |
Charles Keepax | 141dfc9 | 2018-01-26 13:08:45 +0000 | [diff] [blame] | 173 | dev_dbg(fe->dev, "Compress ASoC: %s no valid %s route\n", |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 174 | fe->dai_link->name, stream ? "capture" : "playback"); |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 175 | |
| 176 | /* calculate valid and active FE <-> BE dpcms */ |
| 177 | dpcm_process_paths(fe, stream, &list, 1); |
| 178 | |
| 179 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE; |
| 180 | |
| 181 | ret = dpcm_be_dai_startup(fe, stream); |
| 182 | if (ret < 0) { |
| 183 | /* clean up all links */ |
| 184 | list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) |
| 185 | dpcm->state = SND_SOC_DPCM_LINK_STATE_FREE; |
| 186 | |
| 187 | dpcm_be_disconnect(fe, stream); |
| 188 | fe->dpcm[stream].runtime = NULL; |
Charles Keepax | b0f12c6 | 2016-08-16 11:24:46 +0100 | [diff] [blame] | 189 | goto path_err; |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | dpcm_clear_pending_state(fe, stream); |
| 193 | dpcm_path_put(&list); |
| 194 | |
| 195 | fe->dpcm[stream].state = SND_SOC_DPCM_STATE_OPEN; |
| 196 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO; |
| 197 | |
Lars-Peter Clausen | 24894b7 | 2014-03-05 13:17:43 +0100 | [diff] [blame] | 198 | snd_soc_runtime_activate(fe, stream); |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 199 | |
| 200 | mutex_unlock(&fe->card->mutex); |
| 201 | |
| 202 | return 0; |
| 203 | |
Charles Keepax | b0f12c6 | 2016-08-16 11:24:46 +0100 | [diff] [blame] | 204 | path_err: |
| 205 | dpcm_path_put(&list); |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 206 | fe_err: |
| 207 | if (fe->dai_link->compr_ops && fe->dai_link->compr_ops->shutdown) |
| 208 | fe->dai_link->compr_ops->shutdown(cstream); |
| 209 | machine_err: |
Charles Keepax | 1e57b82 | 2018-04-24 16:39:03 +0100 | [diff] [blame] | 210 | soc_compr_components_free(cstream, component); |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 211 | |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 212 | if (cpu_dai->driver->cops && cpu_dai->driver->cops->shutdown) |
| 213 | cpu_dai->driver->cops->shutdown(cstream, cpu_dai); |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 214 | out: |
| 215 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO; |
| 216 | mutex_unlock(&fe->card->mutex); |
| 217 | return ret; |
| 218 | } |
| 219 | |
Charles Keepax | 202c8f7 | 2013-01-24 09:44:30 +0000 | [diff] [blame] | 220 | /* |
| 221 | * Power down the audio subsystem pmdown_time msecs after close is called. |
| 222 | * This is to ensure there are no pops or clicks in between any music tracks |
| 223 | * due to DAPM power cycling. |
| 224 | */ |
| 225 | static void close_delayed_work(struct work_struct *work) |
| 226 | { |
| 227 | struct snd_soc_pcm_runtime *rtd = |
| 228 | container_of(work, struct snd_soc_pcm_runtime, delayed_work.work); |
| 229 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 230 | |
| 231 | mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); |
| 232 | |
Charles Keepax | 141dfc9 | 2018-01-26 13:08:45 +0000 | [diff] [blame] | 233 | dev_dbg(rtd->dev, |
| 234 | "Compress ASoC: pop wq checking: %s status: %s waiting: %s\n", |
| 235 | codec_dai->driver->playback.stream_name, |
| 236 | codec_dai->playback_active ? "active" : "inactive", |
| 237 | rtd->pop_wait ? "yes" : "no"); |
Charles Keepax | 202c8f7 | 2013-01-24 09:44:30 +0000 | [diff] [blame] | 238 | |
| 239 | /* are we waiting on this codec DAI stream */ |
| 240 | if (rtd->pop_wait == 1) { |
| 241 | rtd->pop_wait = 0; |
| 242 | snd_soc_dapm_stream_event(rtd, SNDRV_PCM_STREAM_PLAYBACK, |
| 243 | SND_SOC_DAPM_STREAM_STOP); |
| 244 | } |
| 245 | |
| 246 | mutex_unlock(&rtd->pcm_mutex); |
| 247 | } |
| 248 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 249 | static int soc_compr_free(struct snd_compr_stream *cstream) |
| 250 | { |
| 251 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 252 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
| 253 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
Lars-Peter Clausen | 24894b7 | 2014-03-05 13:17:43 +0100 | [diff] [blame] | 254 | int stream; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 255 | |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 256 | mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); |
| 257 | |
Lars-Peter Clausen | 24894b7 | 2014-03-05 13:17:43 +0100 | [diff] [blame] | 258 | if (cstream->direction == SND_COMPRESS_PLAYBACK) |
| 259 | stream = SNDRV_PCM_STREAM_PLAYBACK; |
| 260 | else |
| 261 | stream = SNDRV_PCM_STREAM_CAPTURE; |
| 262 | |
| 263 | snd_soc_runtime_deactivate(rtd, stream); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 264 | |
Mark Brown | da18396 | 2013-02-06 15:44:07 +0000 | [diff] [blame] | 265 | snd_soc_dai_digital_mute(codec_dai, 1, cstream->direction); |
| 266 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 267 | if (!cpu_dai->active) |
| 268 | cpu_dai->rate = 0; |
| 269 | |
| 270 | if (!codec_dai->active) |
| 271 | codec_dai->rate = 0; |
| 272 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 273 | if (rtd->dai_link->compr_ops && rtd->dai_link->compr_ops->shutdown) |
| 274 | rtd->dai_link->compr_ops->shutdown(cstream); |
| 275 | |
Charles Keepax | 1e57b82 | 2018-04-24 16:39:03 +0100 | [diff] [blame] | 276 | soc_compr_components_free(cstream, NULL); |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 277 | |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 278 | if (cpu_dai->driver->cops && cpu_dai->driver->cops->shutdown) |
| 279 | cpu_dai->driver->cops->shutdown(cstream, cpu_dai); |
| 280 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 281 | if (cstream->direction == SND_COMPRESS_PLAYBACK) { |
Lars-Peter Clausen | 208a158 | 2014-03-05 13:17:42 +0100 | [diff] [blame] | 282 | if (snd_soc_runtime_ignore_pmdown_time(rtd)) { |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 283 | snd_soc_dapm_stream_event(rtd, |
Charles Keepax | 89027d9 | 2018-04-26 17:30:07 +0100 | [diff] [blame] | 284 | SNDRV_PCM_STREAM_PLAYBACK, |
| 285 | SND_SOC_DAPM_STREAM_STOP); |
Charles Keepax | 8c3d2aa | 2013-01-24 09:44:28 +0000 | [diff] [blame] | 286 | } else { |
Misael Lopez Cruz | 9bffb1f | 2012-12-13 12:23:05 -0600 | [diff] [blame] | 287 | rtd->pop_wait = 1; |
Mark Brown | 3d24cfe | 2013-08-09 18:12:29 +0100 | [diff] [blame] | 288 | queue_delayed_work(system_power_efficient_wq, |
| 289 | &rtd->delayed_work, |
| 290 | msecs_to_jiffies(rtd->pmdown_time)); |
Charles Keepax | 8c3d2aa | 2013-01-24 09:44:28 +0000 | [diff] [blame] | 291 | } |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 292 | } else { |
| 293 | /* capture streams can be powered down now */ |
| 294 | snd_soc_dapm_stream_event(rtd, |
Charles Keepax | 89027d9 | 2018-04-26 17:30:07 +0100 | [diff] [blame] | 295 | SNDRV_PCM_STREAM_CAPTURE, |
| 296 | SND_SOC_DAPM_STREAM_STOP); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 297 | } |
| 298 | |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 299 | mutex_unlock(&rtd->pcm_mutex); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 300 | return 0; |
| 301 | } |
| 302 | |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 303 | static int soc_compr_free_fe(struct snd_compr_stream *cstream) |
| 304 | { |
| 305 | struct snd_soc_pcm_runtime *fe = cstream->private_data; |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 306 | struct snd_soc_dai *cpu_dai = fe->cpu_dai; |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 307 | struct snd_soc_dpcm *dpcm; |
| 308 | int stream, ret; |
| 309 | |
| 310 | mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME); |
| 311 | |
Lars-Peter Clausen | 24894b7 | 2014-03-05 13:17:43 +0100 | [diff] [blame] | 312 | if (cstream->direction == SND_COMPRESS_PLAYBACK) |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 313 | stream = SNDRV_PCM_STREAM_PLAYBACK; |
Lars-Peter Clausen | 24894b7 | 2014-03-05 13:17:43 +0100 | [diff] [blame] | 314 | else |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 315 | stream = SNDRV_PCM_STREAM_CAPTURE; |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 316 | |
Lars-Peter Clausen | 24894b7 | 2014-03-05 13:17:43 +0100 | [diff] [blame] | 317 | snd_soc_runtime_deactivate(fe, stream); |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 318 | |
| 319 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE; |
| 320 | |
| 321 | ret = dpcm_be_dai_hw_free(fe, stream); |
| 322 | if (ret < 0) |
Charles Keepax | 141dfc9 | 2018-01-26 13:08:45 +0000 | [diff] [blame] | 323 | dev_err(fe->dev, "Compressed ASoC: hw_free failed: %d\n", ret); |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 324 | |
| 325 | ret = dpcm_be_dai_shutdown(fe, stream); |
| 326 | |
| 327 | /* mark FE's links ready to prune */ |
| 328 | list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) |
| 329 | dpcm->state = SND_SOC_DPCM_LINK_STATE_FREE; |
| 330 | |
Daniel Mack | 15f6b09 | 2014-10-19 09:07:35 +0200 | [diff] [blame] | 331 | dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_STOP); |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 332 | |
| 333 | fe->dpcm[stream].state = SND_SOC_DPCM_STATE_CLOSE; |
| 334 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO; |
| 335 | |
| 336 | dpcm_be_disconnect(fe, stream); |
| 337 | |
| 338 | fe->dpcm[stream].runtime = NULL; |
| 339 | |
| 340 | if (fe->dai_link->compr_ops && fe->dai_link->compr_ops->shutdown) |
| 341 | fe->dai_link->compr_ops->shutdown(cstream); |
| 342 | |
Charles Keepax | 1e57b82 | 2018-04-24 16:39:03 +0100 | [diff] [blame] | 343 | soc_compr_components_free(cstream, NULL); |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 344 | |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 345 | if (cpu_dai->driver->cops && cpu_dai->driver->cops->shutdown) |
| 346 | cpu_dai->driver->cops->shutdown(cstream, cpu_dai); |
| 347 | |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 348 | mutex_unlock(&fe->card->mutex); |
| 349 | return 0; |
| 350 | } |
| 351 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 352 | static int soc_compr_trigger(struct snd_compr_stream *cstream, int cmd) |
| 353 | { |
| 354 | |
| 355 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 356 | struct snd_soc_component *component; |
| 357 | struct snd_soc_rtdcom_list *rtdcom; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 358 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 359 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 360 | int ret = 0, __ret; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 361 | |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 362 | mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); |
| 363 | |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 364 | for_each_rtdcom(rtd, rtdcom) { |
| 365 | component = rtdcom->component; |
| 366 | |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 367 | if (!component->driver->compr_ops || |
| 368 | !component->driver->compr_ops->trigger) |
| 369 | continue; |
| 370 | |
| 371 | __ret = component->driver->compr_ops->trigger(cstream, cmd); |
| 372 | if (__ret < 0) |
| 373 | ret = __ret; |
| 374 | } |
| 375 | if (ret < 0) |
| 376 | goto out; |
| 377 | |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 378 | if (cpu_dai->driver->cops && cpu_dai->driver->cops->trigger) |
| 379 | cpu_dai->driver->cops->trigger(cstream, cmd, cpu_dai); |
| 380 | |
Mark Brown | da18396 | 2013-02-06 15:44:07 +0000 | [diff] [blame] | 381 | switch (cmd) { |
| 382 | case SNDRV_PCM_TRIGGER_START: |
| 383 | snd_soc_dai_digital_mute(codec_dai, 0, cstream->direction); |
| 384 | break; |
| 385 | case SNDRV_PCM_TRIGGER_STOP: |
| 386 | snd_soc_dai_digital_mute(codec_dai, 1, cstream->direction); |
| 387 | break; |
Mark Brown | e38b9b7 | 2013-02-06 13:52:42 +0000 | [diff] [blame] | 388 | } |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 389 | |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 390 | out: |
| 391 | mutex_unlock(&rtd->pcm_mutex); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 392 | return ret; |
| 393 | } |
| 394 | |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 395 | static int soc_compr_trigger_fe(struct snd_compr_stream *cstream, int cmd) |
| 396 | { |
| 397 | struct snd_soc_pcm_runtime *fe = cstream->private_data; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 398 | struct snd_soc_component *component; |
| 399 | struct snd_soc_rtdcom_list *rtdcom; |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 400 | struct snd_soc_dai *cpu_dai = fe->cpu_dai; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 401 | int ret = 0, __ret, stream; |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 402 | |
| 403 | if (cmd == SND_COMPR_TRIGGER_PARTIAL_DRAIN || |
| 404 | cmd == SND_COMPR_TRIGGER_DRAIN) { |
| 405 | |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 406 | for_each_rtdcom(fe, rtdcom) { |
| 407 | component = rtdcom->component; |
| 408 | |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 409 | if (!component->driver->compr_ops || |
| 410 | !component->driver->compr_ops->trigger) |
| 411 | continue; |
| 412 | |
| 413 | __ret = component->driver->compr_ops->trigger(cstream, cmd); |
| 414 | if (__ret < 0) |
| 415 | ret = __ret; |
| 416 | } |
| 417 | return ret; |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | if (cstream->direction == SND_COMPRESS_PLAYBACK) |
| 421 | stream = SNDRV_PCM_STREAM_PLAYBACK; |
| 422 | else |
| 423 | stream = SNDRV_PCM_STREAM_CAPTURE; |
| 424 | |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 425 | mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME); |
| 426 | |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 427 | if (cpu_dai->driver->cops && cpu_dai->driver->cops->trigger) { |
| 428 | ret = cpu_dai->driver->cops->trigger(cstream, cmd, cpu_dai); |
| 429 | if (ret < 0) |
| 430 | goto out; |
| 431 | } |
| 432 | |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 433 | for_each_rtdcom(fe, rtdcom) { |
| 434 | component = rtdcom->component; |
| 435 | |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 436 | if (!component->driver->compr_ops || |
| 437 | !component->driver->compr_ops->trigger) |
| 438 | continue; |
| 439 | |
| 440 | __ret = component->driver->compr_ops->trigger(cstream, cmd); |
| 441 | if (__ret < 0) |
| 442 | ret = __ret; |
| 443 | } |
| 444 | if (ret < 0) |
| 445 | goto out; |
| 446 | |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 447 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE; |
| 448 | |
| 449 | ret = dpcm_be_dai_trigger(fe, stream, cmd); |
| 450 | |
| 451 | switch (cmd) { |
| 452 | case SNDRV_PCM_TRIGGER_START: |
| 453 | case SNDRV_PCM_TRIGGER_RESUME: |
| 454 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
| 455 | fe->dpcm[stream].state = SND_SOC_DPCM_STATE_START; |
| 456 | break; |
| 457 | case SNDRV_PCM_TRIGGER_STOP: |
| 458 | case SNDRV_PCM_TRIGGER_SUSPEND: |
| 459 | fe->dpcm[stream].state = SND_SOC_DPCM_STATE_STOP; |
| 460 | break; |
| 461 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
| 462 | fe->dpcm[stream].state = SND_SOC_DPCM_STATE_PAUSED; |
| 463 | break; |
| 464 | } |
| 465 | |
| 466 | out: |
| 467 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO; |
| 468 | mutex_unlock(&fe->card->mutex); |
| 469 | return ret; |
| 470 | } |
| 471 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 472 | static int soc_compr_set_params(struct snd_compr_stream *cstream, |
| 473 | struct snd_compr_params *params) |
| 474 | { |
| 475 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 476 | struct snd_soc_component *component; |
| 477 | struct snd_soc_rtdcom_list *rtdcom; |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 478 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 479 | int ret = 0, __ret; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 480 | |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 481 | mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); |
| 482 | |
Charles Keepax | ef050be | 2018-04-24 16:39:02 +0100 | [diff] [blame] | 483 | /* |
| 484 | * First we call set_params for the CPU DAI, then the component |
| 485 | * driver this should configure the SoC side. If the machine has |
| 486 | * compressed ops then we call that as well. The expectation is |
| 487 | * that these callbacks will configure everything for this compress |
| 488 | * path, like configuring a PCM port for a CODEC. |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 489 | */ |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 490 | if (cpu_dai->driver->cops && cpu_dai->driver->cops->set_params) { |
| 491 | ret = cpu_dai->driver->cops->set_params(cstream, params, cpu_dai); |
| 492 | if (ret < 0) |
| 493 | goto err; |
| 494 | } |
| 495 | |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 496 | for_each_rtdcom(rtd, rtdcom) { |
| 497 | component = rtdcom->component; |
| 498 | |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 499 | if (!component->driver->compr_ops || |
| 500 | !component->driver->compr_ops->set_params) |
| 501 | continue; |
| 502 | |
| 503 | __ret = component->driver->compr_ops->set_params(cstream, params); |
| 504 | if (__ret < 0) |
| 505 | ret = __ret; |
| 506 | } |
| 507 | if (ret < 0) |
| 508 | goto err; |
| 509 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 510 | if (rtd->dai_link->compr_ops && rtd->dai_link->compr_ops->set_params) { |
| 511 | ret = rtd->dai_link->compr_ops->set_params(cstream); |
| 512 | if (ret < 0) |
Charles Keepax | fa40ef2 | 2013-03-27 16:39:01 +0000 | [diff] [blame] | 513 | goto err; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 514 | } |
| 515 | |
Charles Keepax | 2c071ed | 2013-05-20 08:33:54 +0100 | [diff] [blame] | 516 | if (cstream->direction == SND_COMPRESS_PLAYBACK) |
| 517 | snd_soc_dapm_stream_event(rtd, SNDRV_PCM_STREAM_PLAYBACK, |
Charles Keepax | 89027d9 | 2018-04-26 17:30:07 +0100 | [diff] [blame] | 518 | SND_SOC_DAPM_STREAM_START); |
Charles Keepax | 2c071ed | 2013-05-20 08:33:54 +0100 | [diff] [blame] | 519 | else |
| 520 | snd_soc_dapm_stream_event(rtd, SNDRV_PCM_STREAM_CAPTURE, |
Charles Keepax | 89027d9 | 2018-04-26 17:30:07 +0100 | [diff] [blame] | 521 | SND_SOC_DAPM_STREAM_START); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 522 | |
Charles Keepax | fa40ef2 | 2013-03-27 16:39:01 +0000 | [diff] [blame] | 523 | /* cancel any delayed stream shutdown that is pending */ |
| 524 | rtd->pop_wait = 0; |
| 525 | mutex_unlock(&rtd->pcm_mutex); |
| 526 | |
| 527 | cancel_delayed_work_sync(&rtd->delayed_work); |
| 528 | |
| 529 | return ret; |
| 530 | |
| 531 | err: |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 532 | mutex_unlock(&rtd->pcm_mutex); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 533 | return ret; |
| 534 | } |
| 535 | |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 536 | static int soc_compr_set_params_fe(struct snd_compr_stream *cstream, |
Charles Keepax | 89027d9 | 2018-04-26 17:30:07 +0100 | [diff] [blame] | 537 | struct snd_compr_params *params) |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 538 | { |
| 539 | struct snd_soc_pcm_runtime *fe = cstream->private_data; |
Satish Babu Patakokila | 01b8ced | 2017-06-16 17:33:40 -0700 | [diff] [blame] | 540 | struct snd_pcm_substream *fe_substream = |
| 541 | fe->pcm->streams[cstream->direction].substream; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 542 | struct snd_soc_component *component; |
| 543 | struct snd_soc_rtdcom_list *rtdcom; |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 544 | struct snd_soc_dai *cpu_dai = fe->cpu_dai; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 545 | int ret = 0, __ret, stream; |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 546 | |
| 547 | if (cstream->direction == SND_COMPRESS_PLAYBACK) |
| 548 | stream = SNDRV_PCM_STREAM_PLAYBACK; |
| 549 | else |
| 550 | stream = SNDRV_PCM_STREAM_CAPTURE; |
| 551 | |
| 552 | mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME); |
| 553 | |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 554 | if (cpu_dai->driver->cops && cpu_dai->driver->cops->set_params) { |
| 555 | ret = cpu_dai->driver->cops->set_params(cstream, params, cpu_dai); |
| 556 | if (ret < 0) |
| 557 | goto out; |
| 558 | } |
| 559 | |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 560 | for_each_rtdcom(fe, rtdcom) { |
| 561 | component = rtdcom->component; |
| 562 | |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 563 | if (!component->driver->compr_ops || |
| 564 | !component->driver->compr_ops->set_params) |
| 565 | continue; |
| 566 | |
| 567 | __ret = component->driver->compr_ops->set_params(cstream, params); |
| 568 | if (__ret < 0) |
| 569 | ret = __ret; |
| 570 | } |
| 571 | if (ret < 0) |
| 572 | goto out; |
| 573 | |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 574 | if (fe->dai_link->compr_ops && fe->dai_link->compr_ops->set_params) { |
| 575 | ret = fe->dai_link->compr_ops->set_params(cstream); |
| 576 | if (ret < 0) |
| 577 | goto out; |
| 578 | } |
| 579 | |
| 580 | /* |
| 581 | * Create an empty hw_params for the BE as the machine driver must |
| 582 | * fix this up to match DSP decoder and ASRC configuration. |
| 583 | * I.e. machine driver fixup for compressed BE is mandatory. |
| 584 | */ |
| 585 | memset(&fe->dpcm[fe_substream->stream].hw_params, 0, |
| 586 | sizeof(struct snd_pcm_hw_params)); |
| 587 | |
| 588 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE; |
| 589 | |
| 590 | ret = dpcm_be_dai_hw_params(fe, stream); |
| 591 | if (ret < 0) |
| 592 | goto out; |
| 593 | |
| 594 | ret = dpcm_be_dai_prepare(fe, stream); |
| 595 | if (ret < 0) |
| 596 | goto out; |
| 597 | |
Daniel Mack | 15f6b09 | 2014-10-19 09:07:35 +0200 | [diff] [blame] | 598 | dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_START); |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 599 | fe->dpcm[stream].state = SND_SOC_DPCM_STATE_PREPARE; |
| 600 | |
| 601 | out: |
| 602 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO; |
| 603 | mutex_unlock(&fe->card->mutex); |
| 604 | return ret; |
| 605 | } |
| 606 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 607 | static int soc_compr_get_params(struct snd_compr_stream *cstream, |
Charles Keepax | 89027d9 | 2018-04-26 17:30:07 +0100 | [diff] [blame] | 608 | struct snd_codec *params) |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 609 | { |
| 610 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 611 | struct snd_soc_component *component; |
| 612 | struct snd_soc_rtdcom_list *rtdcom; |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 613 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 614 | int ret = 0, __ret; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 615 | |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 616 | mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); |
| 617 | |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 618 | if (cpu_dai->driver->cops && cpu_dai->driver->cops->get_params) { |
| 619 | ret = cpu_dai->driver->cops->get_params(cstream, params, cpu_dai); |
| 620 | if (ret < 0) |
| 621 | goto err; |
| 622 | } |
| 623 | |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 624 | for_each_rtdcom(rtd, rtdcom) { |
| 625 | component = rtdcom->component; |
| 626 | |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 627 | if (!component->driver->compr_ops || |
| 628 | !component->driver->compr_ops->get_params) |
| 629 | continue; |
| 630 | |
| 631 | __ret = component->driver->compr_ops->get_params(cstream, params); |
| 632 | if (__ret < 0) |
| 633 | ret = __ret; |
| 634 | } |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 635 | |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 636 | err: |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 637 | mutex_unlock(&rtd->pcm_mutex); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 638 | return ret; |
| 639 | } |
| 640 | |
| 641 | static int soc_compr_get_caps(struct snd_compr_stream *cstream, |
Charles Keepax | 89027d9 | 2018-04-26 17:30:07 +0100 | [diff] [blame] | 642 | struct snd_compr_caps *caps) |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 643 | { |
| 644 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 645 | struct snd_soc_component *component; |
| 646 | struct snd_soc_rtdcom_list *rtdcom; |
| 647 | int ret = 0, __ret; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 648 | |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 649 | mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); |
| 650 | |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 651 | for_each_rtdcom(rtd, rtdcom) { |
| 652 | component = rtdcom->component; |
| 653 | |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 654 | if (!component->driver->compr_ops || |
| 655 | !component->driver->compr_ops->get_caps) |
| 656 | continue; |
| 657 | |
| 658 | __ret = component->driver->compr_ops->get_caps(cstream, caps); |
| 659 | if (__ret < 0) |
| 660 | ret = __ret; |
| 661 | } |
| 662 | |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 663 | mutex_unlock(&rtd->pcm_mutex); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 664 | return ret; |
| 665 | } |
| 666 | |
| 667 | static int soc_compr_get_codec_caps(struct snd_compr_stream *cstream, |
Charles Keepax | 89027d9 | 2018-04-26 17:30:07 +0100 | [diff] [blame] | 668 | struct snd_compr_codec_caps *codec) |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 669 | { |
| 670 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 671 | struct snd_soc_component *component; |
| 672 | struct snd_soc_rtdcom_list *rtdcom; |
| 673 | int ret = 0, __ret; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 674 | |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 675 | mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); |
| 676 | |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 677 | for_each_rtdcom(rtd, rtdcom) { |
| 678 | component = rtdcom->component; |
| 679 | |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 680 | if (!component->driver->compr_ops || |
| 681 | !component->driver->compr_ops->get_codec_caps) |
| 682 | continue; |
| 683 | |
| 684 | __ret = component->driver->compr_ops->get_codec_caps(cstream, codec); |
| 685 | if (__ret < 0) |
| 686 | ret = __ret; |
| 687 | } |
| 688 | |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 689 | mutex_unlock(&rtd->pcm_mutex); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 690 | return ret; |
| 691 | } |
| 692 | |
| 693 | static int soc_compr_ack(struct snd_compr_stream *cstream, size_t bytes) |
| 694 | { |
| 695 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 696 | struct snd_soc_component *component; |
| 697 | struct snd_soc_rtdcom_list *rtdcom; |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 698 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 699 | int ret = 0, __ret; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 700 | |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 701 | mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); |
| 702 | |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 703 | if (cpu_dai->driver->cops && cpu_dai->driver->cops->ack) { |
| 704 | ret = cpu_dai->driver->cops->ack(cstream, bytes, cpu_dai); |
| 705 | if (ret < 0) |
| 706 | goto err; |
| 707 | } |
| 708 | |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 709 | for_each_rtdcom(rtd, rtdcom) { |
| 710 | component = rtdcom->component; |
| 711 | |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 712 | if (!component->driver->compr_ops || |
| 713 | !component->driver->compr_ops->ack) |
| 714 | continue; |
| 715 | |
| 716 | __ret = component->driver->compr_ops->ack(cstream, bytes); |
| 717 | if (__ret < 0) |
| 718 | ret = __ret; |
| 719 | } |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 720 | |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 721 | err: |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 722 | mutex_unlock(&rtd->pcm_mutex); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 723 | return ret; |
| 724 | } |
| 725 | |
| 726 | static int soc_compr_pointer(struct snd_compr_stream *cstream, |
Charles Keepax | 89027d9 | 2018-04-26 17:30:07 +0100 | [diff] [blame] | 727 | struct snd_compr_tstamp *tstamp) |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 728 | { |
| 729 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 730 | struct snd_soc_component *component; |
| 731 | struct snd_soc_rtdcom_list *rtdcom; |
| 732 | int ret = 0, __ret; |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 733 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 734 | |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 735 | mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); |
| 736 | |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 737 | if (cpu_dai->driver->cops && cpu_dai->driver->cops->pointer) |
| 738 | cpu_dai->driver->cops->pointer(cstream, tstamp, cpu_dai); |
| 739 | |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 740 | for_each_rtdcom(rtd, rtdcom) { |
| 741 | component = rtdcom->component; |
| 742 | |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 743 | if (!component->driver->compr_ops || |
| 744 | !component->driver->compr_ops->pointer) |
| 745 | continue; |
| 746 | |
| 747 | __ret = component->driver->compr_ops->pointer(cstream, tstamp); |
| 748 | if (__ret < 0) |
| 749 | ret = __ret; |
| 750 | } |
| 751 | |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 752 | mutex_unlock(&rtd->pcm_mutex); |
Charles Keepax | 7c9190f | 2016-06-20 09:51:32 +0100 | [diff] [blame] | 753 | return ret; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 754 | } |
| 755 | |
Charles Keepax | 1f88eb0 | 2013-02-05 10:41:47 +0000 | [diff] [blame] | 756 | static int soc_compr_copy(struct snd_compr_stream *cstream, |
Charles Keepax | 4daf891 | 2013-04-18 11:01:38 +0100 | [diff] [blame] | 757 | char __user *buf, size_t count) |
Charles Keepax | 1f88eb0 | 2013-02-05 10:41:47 +0000 | [diff] [blame] | 758 | { |
| 759 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 760 | struct snd_soc_component *component; |
| 761 | struct snd_soc_rtdcom_list *rtdcom; |
Charles Keepax | 290df4d3 | 2018-01-26 13:08:43 +0000 | [diff] [blame] | 762 | int ret = 0; |
Charles Keepax | 1f88eb0 | 2013-02-05 10:41:47 +0000 | [diff] [blame] | 763 | |
| 764 | mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); |
| 765 | |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 766 | for_each_rtdcom(rtd, rtdcom) { |
| 767 | component = rtdcom->component; |
| 768 | |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 769 | if (!component->driver->compr_ops || |
| 770 | !component->driver->compr_ops->copy) |
| 771 | continue; |
| 772 | |
Charles Keepax | 290df4d3 | 2018-01-26 13:08:43 +0000 | [diff] [blame] | 773 | ret = component->driver->compr_ops->copy(cstream, buf, count); |
| 774 | break; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 775 | } |
Charles Keepax | 290df4d3 | 2018-01-26 13:08:43 +0000 | [diff] [blame] | 776 | |
Charles Keepax | 1f88eb0 | 2013-02-05 10:41:47 +0000 | [diff] [blame] | 777 | mutex_unlock(&rtd->pcm_mutex); |
| 778 | return ret; |
| 779 | } |
| 780 | |
Vinod Koul | 02bd90e | 2013-07-28 20:06:15 +0530 | [diff] [blame] | 781 | static int soc_compr_set_metadata(struct snd_compr_stream *cstream, |
Charles Keepax | 89027d9 | 2018-04-26 17:30:07 +0100 | [diff] [blame] | 782 | struct snd_compr_metadata *metadata) |
Jeeja KP | 36953d9 | 2013-03-26 21:22:28 +0530 | [diff] [blame] | 783 | { |
| 784 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 785 | struct snd_soc_component *component; |
| 786 | struct snd_soc_rtdcom_list *rtdcom; |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 787 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 788 | int ret = 0, __ret; |
Jeeja KP | 36953d9 | 2013-03-26 21:22:28 +0530 | [diff] [blame] | 789 | |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 790 | if (cpu_dai->driver->cops && cpu_dai->driver->cops->set_metadata) { |
| 791 | ret = cpu_dai->driver->cops->set_metadata(cstream, metadata, cpu_dai); |
| 792 | if (ret < 0) |
| 793 | return ret; |
| 794 | } |
| 795 | |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 796 | for_each_rtdcom(rtd, rtdcom) { |
| 797 | component = rtdcom->component; |
| 798 | |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 799 | if (!component->driver->compr_ops || |
| 800 | !component->driver->compr_ops->set_metadata) |
| 801 | continue; |
| 802 | |
| 803 | __ret = component->driver->compr_ops->set_metadata(cstream, metadata); |
| 804 | if (__ret < 0) |
| 805 | ret = __ret; |
| 806 | } |
Jeeja KP | 36953d9 | 2013-03-26 21:22:28 +0530 | [diff] [blame] | 807 | |
| 808 | return ret; |
| 809 | } |
| 810 | |
Vinod Koul | 02bd90e | 2013-07-28 20:06:15 +0530 | [diff] [blame] | 811 | static int soc_compr_get_metadata(struct snd_compr_stream *cstream, |
Charles Keepax | 89027d9 | 2018-04-26 17:30:07 +0100 | [diff] [blame] | 812 | struct snd_compr_metadata *metadata) |
Jeeja KP | 36953d9 | 2013-03-26 21:22:28 +0530 | [diff] [blame] | 813 | { |
| 814 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 815 | struct snd_soc_component *component; |
| 816 | struct snd_soc_rtdcom_list *rtdcom; |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 817 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 818 | int ret = 0, __ret; |
Jeeja KP | 36953d9 | 2013-03-26 21:22:28 +0530 | [diff] [blame] | 819 | |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 820 | if (cpu_dai->driver->cops && cpu_dai->driver->cops->get_metadata) { |
| 821 | ret = cpu_dai->driver->cops->get_metadata(cstream, metadata, cpu_dai); |
| 822 | if (ret < 0) |
| 823 | return ret; |
| 824 | } |
| 825 | |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 826 | for_each_rtdcom(rtd, rtdcom) { |
| 827 | component = rtdcom->component; |
| 828 | |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 829 | if (!component->driver->compr_ops || |
| 830 | !component->driver->compr_ops->get_metadata) |
| 831 | continue; |
| 832 | |
| 833 | __ret = component->driver->compr_ops->get_metadata(cstream, metadata); |
| 834 | if (__ret < 0) |
| 835 | ret = __ret; |
| 836 | } |
Jeeja KP | 36953d9 | 2013-03-26 21:22:28 +0530 | [diff] [blame] | 837 | |
| 838 | return ret; |
| 839 | } |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 840 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 841 | /* ASoC Compress operations */ |
| 842 | static struct snd_compr_ops soc_compr_ops = { |
| 843 | .open = soc_compr_open, |
| 844 | .free = soc_compr_free, |
| 845 | .set_params = soc_compr_set_params, |
Vinod Koul | 02bd90e | 2013-07-28 20:06:15 +0530 | [diff] [blame] | 846 | .set_metadata = soc_compr_set_metadata, |
| 847 | .get_metadata = soc_compr_get_metadata, |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 848 | .get_params = soc_compr_get_params, |
| 849 | .trigger = soc_compr_trigger, |
| 850 | .pointer = soc_compr_pointer, |
| 851 | .ack = soc_compr_ack, |
| 852 | .get_caps = soc_compr_get_caps, |
| 853 | .get_codec_caps = soc_compr_get_codec_caps |
| 854 | }; |
| 855 | |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 856 | /* ASoC Dynamic Compress operations */ |
| 857 | static struct snd_compr_ops soc_compr_dyn_ops = { |
| 858 | .open = soc_compr_open_fe, |
| 859 | .free = soc_compr_free_fe, |
| 860 | .set_params = soc_compr_set_params_fe, |
| 861 | .get_params = soc_compr_get_params, |
| 862 | .set_metadata = soc_compr_set_metadata, |
| 863 | .get_metadata = soc_compr_get_metadata, |
| 864 | .trigger = soc_compr_trigger_fe, |
| 865 | .pointer = soc_compr_pointer, |
| 866 | .ack = soc_compr_ack, |
| 867 | .get_caps = soc_compr_get_caps, |
| 868 | .get_codec_caps = soc_compr_get_codec_caps |
| 869 | }; |
| 870 | |
Jie Yang | 6f0c422 | 2015-10-13 23:41:00 +0800 | [diff] [blame] | 871 | /** |
| 872 | * snd_soc_new_compress - create a new compress. |
| 873 | * |
| 874 | * @rtd: The runtime for which we will create compress |
| 875 | * @num: the device index number (zero based - shared with normal PCMs) |
| 876 | * |
| 877 | * Return: 0 for success, else error. |
| 878 | */ |
| 879 | int snd_soc_new_compress(struct snd_soc_pcm_runtime *rtd, int num) |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 880 | { |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 881 | struct snd_soc_component *component; |
| 882 | struct snd_soc_rtdcom_list *rtdcom; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 883 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 884 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
| 885 | struct snd_compr *compr; |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 886 | struct snd_pcm *be_pcm; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 887 | char new_name[64]; |
| 888 | int ret = 0, direction = 0; |
Vinod Koul | a106804 | 2016-01-07 21:48:14 +0530 | [diff] [blame] | 889 | int playback = 0, capture = 0; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 890 | |
Benoit Cousson | 8151d5e | 2014-07-08 23:19:37 +0200 | [diff] [blame] | 891 | if (rtd->num_codecs > 1) { |
Charles Keepax | 141dfc9 | 2018-01-26 13:08:45 +0000 | [diff] [blame] | 892 | dev_err(rtd->card->dev, |
| 893 | "Compress ASoC: Multicodec not supported\n"); |
Benoit Cousson | 8151d5e | 2014-07-08 23:19:37 +0200 | [diff] [blame] | 894 | return -EINVAL; |
| 895 | } |
| 896 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 897 | /* check client and interface hw capabilities */ |
Charles Keepax | daa2db5 | 2013-04-18 11:02:38 +0100 | [diff] [blame] | 898 | if (codec_dai->driver->playback.channels_min) |
Vinod Koul | a106804 | 2016-01-07 21:48:14 +0530 | [diff] [blame] | 899 | playback = 1; |
| 900 | if (codec_dai->driver->capture.channels_min) |
| 901 | capture = 1; |
| 902 | |
| 903 | capture = capture && cpu_dai->driver->capture.channels_min; |
| 904 | playback = playback && cpu_dai->driver->playback.channels_min; |
| 905 | |
| 906 | /* |
| 907 | * Compress devices are unidirectional so only one of the directions |
| 908 | * should be set, check for that (xor) |
| 909 | */ |
| 910 | if (playback + capture != 1) { |
Charles Keepax | 141dfc9 | 2018-01-26 13:08:45 +0000 | [diff] [blame] | 911 | dev_err(rtd->card->dev, |
| 912 | "Compress ASoC: Invalid direction for P %d, C %d\n", |
| 913 | playback, capture); |
Charles Keepax | daa2db5 | 2013-04-18 11:02:38 +0100 | [diff] [blame] | 914 | return -EINVAL; |
Vinod Koul | a106804 | 2016-01-07 21:48:14 +0530 | [diff] [blame] | 915 | } |
| 916 | |
Peng Donglin | aeb6fa0 | 2017-08-16 22:47:53 +0800 | [diff] [blame] | 917 | if (playback) |
Vinod Koul | a106804 | 2016-01-07 21:48:14 +0530 | [diff] [blame] | 918 | direction = SND_COMPRESS_PLAYBACK; |
| 919 | else |
| 920 | direction = SND_COMPRESS_CAPTURE; |
Charles Keepax | daa2db5 | 2013-04-18 11:02:38 +0100 | [diff] [blame] | 921 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 922 | compr = kzalloc(sizeof(*compr), GFP_KERNEL); |
Markus Elfring | 7a0cf42 | 2017-08-10 16:21:34 +0200 | [diff] [blame] | 923 | if (!compr) |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 924 | return -ENOMEM; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 925 | |
Charles Keepax | 1f88eb0 | 2013-02-05 10:41:47 +0000 | [diff] [blame] | 926 | compr->ops = devm_kzalloc(rtd->card->dev, sizeof(soc_compr_ops), |
| 927 | GFP_KERNEL); |
Markus Elfring | 7a0cf42 | 2017-08-10 16:21:34 +0200 | [diff] [blame] | 928 | if (!compr->ops) { |
Charles Keepax | 1f88eb0 | 2013-02-05 10:41:47 +0000 | [diff] [blame] | 929 | ret = -ENOMEM; |
| 930 | goto compr_err; |
| 931 | } |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 932 | |
| 933 | if (rtd->dai_link->dynamic) { |
| 934 | snprintf(new_name, sizeof(new_name), "(%s)", |
| 935 | rtd->dai_link->stream_name); |
| 936 | |
| 937 | ret = snd_pcm_new_internal(rtd->card->snd_card, new_name, num, |
Qais Yousef | d3268a4 | 2015-01-14 08:47:29 +0000 | [diff] [blame] | 938 | rtd->dai_link->dpcm_playback, |
| 939 | rtd->dai_link->dpcm_capture, &be_pcm); |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 940 | if (ret < 0) { |
Charles Keepax | 141dfc9 | 2018-01-26 13:08:45 +0000 | [diff] [blame] | 941 | dev_err(rtd->card->dev, |
| 942 | "Compress ASoC: can't create compressed for %s: %d\n", |
| 943 | rtd->dai_link->name, ret); |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 944 | goto compr_err; |
| 945 | } |
| 946 | |
| 947 | rtd->pcm = be_pcm; |
| 948 | rtd->fe_compr = 1; |
Qais Yousef | d3268a4 | 2015-01-14 08:47:29 +0000 | [diff] [blame] | 949 | if (rtd->dai_link->dpcm_playback) |
| 950 | be_pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream->private_data = rtd; |
| 951 | else if (rtd->dai_link->dpcm_capture) |
| 952 | be_pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream->private_data = rtd; |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 953 | memcpy(compr->ops, &soc_compr_dyn_ops, sizeof(soc_compr_dyn_ops)); |
Peng Donglin | aeb6fa0 | 2017-08-16 22:47:53 +0800 | [diff] [blame] | 954 | } else { |
| 955 | snprintf(new_name, sizeof(new_name), "%s %s-%d", |
| 956 | rtd->dai_link->stream_name, codec_dai->name, num); |
| 957 | |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 958 | memcpy(compr->ops, &soc_compr_ops, sizeof(soc_compr_ops)); |
Peng Donglin | aeb6fa0 | 2017-08-16 22:47:53 +0800 | [diff] [blame] | 959 | } |
Charles Keepax | 1f88eb0 | 2013-02-05 10:41:47 +0000 | [diff] [blame] | 960 | |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 961 | for_each_rtdcom(rtd, rtdcom) { |
| 962 | component = rtdcom->component; |
| 963 | |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 964 | if (!component->driver->compr_ops || |
| 965 | !component->driver->compr_ops->copy) |
| 966 | continue; |
| 967 | |
| 968 | compr->ops->copy = soc_compr_copy; |
Charles Keepax | ca76db6 | 2018-04-26 17:30:04 +0100 | [diff] [blame] | 969 | break; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 970 | } |
| 971 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 972 | mutex_init(&compr->lock); |
Richard Fitzgerald | e5241a8 | 2015-11-25 13:00:24 +0000 | [diff] [blame] | 973 | ret = snd_compress_new(rtd->card->snd_card, num, direction, |
| 974 | new_name, compr); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 975 | if (ret < 0) { |
Kuninori Morimoto | e5acfc7 | 2017-12-05 04:23:05 +0000 | [diff] [blame] | 976 | component = rtd->codec_dai->component; |
Charles Keepax | 141dfc9 | 2018-01-26 13:08:45 +0000 | [diff] [blame] | 977 | dev_err(component->dev, |
| 978 | "Compress ASoC: can't create compress for codec %s: %d\n", |
| 979 | component->name, ret); |
Charles Keepax | 1f88eb0 | 2013-02-05 10:41:47 +0000 | [diff] [blame] | 980 | goto compr_err; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 981 | } |
| 982 | |
Charles Keepax | 202c8f7 | 2013-01-24 09:44:30 +0000 | [diff] [blame] | 983 | /* DAPM dai link stream work */ |
| 984 | INIT_DELAYED_WORK(&rtd->delayed_work, close_delayed_work); |
| 985 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 986 | rtd->compr = compr; |
| 987 | compr->private_data = rtd; |
| 988 | |
Charles Keepax | 141dfc9 | 2018-01-26 13:08:45 +0000 | [diff] [blame] | 989 | dev_info(rtd->card->dev, "Compress ASoC: %s <-> %s mapping ok\n", |
| 990 | codec_dai->name, cpu_dai->name); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 991 | return ret; |
Charles Keepax | 1f88eb0 | 2013-02-05 10:41:47 +0000 | [diff] [blame] | 992 | |
| 993 | compr_err: |
| 994 | kfree(compr); |
| 995 | return ret; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 996 | } |
Jie Yang | 6f0c422 | 2015-10-13 23:41:00 +0800 | [diff] [blame] | 997 | EXPORT_SYMBOL_GPL(snd_soc_new_compress); |