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