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> |
Kuninori Morimoto | 9ab711c | 2020-05-25 09:57:41 +0900 | [diff] [blame] | 22 | #include <sound/soc-link.h> |
Cezary Rojewski | 4137f4b | 2019-12-17 10:58:50 +0100 | [diff] [blame] | 23 | #include <linux/pm_runtime.h> |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 24 | |
Charles Keepax | 1e57b82 | 2018-04-24 16:39:03 +0100 | [diff] [blame] | 25 | static int soc_compr_components_open(struct snd_compr_stream *cstream, |
| 26 | struct snd_soc_component **last) |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 27 | { |
| 28 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 29 | struct snd_soc_component *component; |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 30 | int i, ret; |
Charles Keepax | 1e57b82 | 2018-04-24 16:39:03 +0100 | [diff] [blame] | 31 | |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 32 | for_each_rtd_components(rtd, i, component) { |
Kuninori Morimoto | c6cb522 | 2020-04-20 16:07:50 +0900 | [diff] [blame] | 33 | if (!component->driver->compress_ops || |
| 34 | !component->driver->compress_ops->open) |
| 35 | continue; |
| 36 | |
| 37 | ret = component->driver->compress_ops->open(component, cstream); |
| 38 | if (ret < 0) { |
| 39 | dev_err(component->dev, |
| 40 | "Compress ASoC: can't open platform %s: %d\n", |
| 41 | component->name, ret); |
| 42 | |
| 43 | *last = component; |
| 44 | return ret; |
| 45 | } |
| 46 | } |
| 47 | |
Charles Keepax | 1e57b82 | 2018-04-24 16:39:03 +0100 | [diff] [blame] | 48 | *last = NULL; |
| 49 | return 0; |
| 50 | } |
| 51 | |
| 52 | static int soc_compr_components_free(struct snd_compr_stream *cstream, |
| 53 | struct snd_soc_component *last) |
| 54 | { |
| 55 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
| 56 | struct snd_soc_component *component; |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 57 | int i; |
Charles Keepax | 1e57b82 | 2018-04-24 16:39:03 +0100 | [diff] [blame] | 58 | |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 59 | for_each_rtd_components(rtd, i, component) { |
Charles Keepax | 1e57b82 | 2018-04-24 16:39:03 +0100 | [diff] [blame] | 60 | if (component == last) |
| 61 | break; |
| 62 | |
Kuninori Morimoto | c6cb522 | 2020-04-20 16:07:50 +0900 | [diff] [blame] | 63 | if (!component->driver->compress_ops || |
| 64 | !component->driver->compress_ops->free) |
| 65 | continue; |
| 66 | |
| 67 | component->driver->compress_ops->free(component, cstream); |
| 68 | } |
| 69 | |
Charles Keepax | 1e57b82 | 2018-04-24 16:39:03 +0100 | [diff] [blame] | 70 | return 0; |
| 71 | } |
| 72 | |
| 73 | static int soc_compr_open(struct snd_compr_stream *cstream) |
| 74 | { |
| 75 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
Kuninori Morimoto | 939a5cf | 2020-09-28 09:01:17 +0900 | [diff] [blame] | 76 | struct snd_soc_component *component = NULL; |
Kuninori Morimoto | c2233a2 | 2020-03-30 10:47:37 +0900 | [diff] [blame] | 77 | struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0); |
Kuninori Morimoto | 939a5cf | 2020-09-28 09:01:17 +0900 | [diff] [blame] | 78 | int ret; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 79 | |
Kuninori Morimoto | 939a5cf | 2020-09-28 09:01:17 +0900 | [diff] [blame] | 80 | ret = snd_soc_pcm_component_pm_runtime_get(rtd, cstream); |
| 81 | if (ret < 0) |
| 82 | goto pm_err; |
Cezary Rojewski | 4137f4b | 2019-12-17 10:58:50 +0100 | [diff] [blame] | 83 | |
Peter Ujfalusi | 72b745e | 2019-08-13 13:45:32 +0300 | [diff] [blame] | 84 | mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 85 | |
Kuninori Morimoto | b5ae4cc | 2020-04-24 08:15:24 +0900 | [diff] [blame] | 86 | ret = snd_soc_dai_compr_startup(cpu_dai, cstream); |
| 87 | if (ret < 0) |
| 88 | goto out; |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 89 | |
Charles Keepax | 1e57b82 | 2018-04-24 16:39:03 +0100 | [diff] [blame] | 90 | ret = soc_compr_components_open(cstream, &component); |
| 91 | if (ret < 0) |
| 92 | goto machine_err; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 93 | |
Kuninori Morimoto | 9ab711c | 2020-05-25 09:57:41 +0900 | [diff] [blame] | 94 | ret = snd_soc_link_compr_startup(cstream); |
| 95 | if (ret < 0) |
| 96 | goto machine_err; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 97 | |
Lars-Peter Clausen | 24894b7 | 2014-03-05 13:17:43 +0100 | [diff] [blame] | 98 | snd_soc_runtime_activate(rtd, cstream->direction); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 99 | |
Peter Ujfalusi | 72b745e | 2019-08-13 13:45:32 +0300 | [diff] [blame] | 100 | mutex_unlock(&rtd->card->pcm_mutex); |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 101 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 102 | return 0; |
| 103 | |
| 104 | machine_err: |
Charles Keepax | 1e57b82 | 2018-04-24 16:39:03 +0100 | [diff] [blame] | 105 | soc_compr_components_free(cstream, component); |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 106 | |
Kuninori Morimoto | 2b25f81 | 2020-04-24 08:15:28 +0900 | [diff] [blame] | 107 | snd_soc_dai_compr_shutdown(cpu_dai, cstream); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 108 | out: |
Peter Ujfalusi | 72b745e | 2019-08-13 13:45:32 +0300 | [diff] [blame] | 109 | mutex_unlock(&rtd->card->pcm_mutex); |
Cezary Rojewski | 4137f4b | 2019-12-17 10:58:50 +0100 | [diff] [blame] | 110 | pm_err: |
Kuninori Morimoto | 939a5cf | 2020-09-28 09:01:17 +0900 | [diff] [blame] | 111 | snd_soc_pcm_component_pm_runtime_put(rtd, cstream, 1); |
Cezary Rojewski | 4137f4b | 2019-12-17 10:58:50 +0100 | [diff] [blame] | 112 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 113 | return ret; |
| 114 | } |
| 115 | |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 116 | static int soc_compr_open_fe(struct snd_compr_stream *cstream) |
| 117 | { |
| 118 | struct snd_soc_pcm_runtime *fe = cstream->private_data; |
Satish Babu Patakokila | 01b8ced | 2017-06-16 17:33:40 -0700 | [diff] [blame] | 119 | struct snd_pcm_substream *fe_substream = |
| 120 | fe->pcm->streams[cstream->direction].substream; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 121 | struct snd_soc_component *component; |
Kuninori Morimoto | c2233a2 | 2020-03-30 10:47:37 +0900 | [diff] [blame] | 122 | struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(fe, 0); |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 123 | struct snd_soc_dpcm *dpcm; |
| 124 | struct snd_soc_dapm_widget_list *list; |
| 125 | int stream; |
Charles Keepax | 572e6c8 | 2018-04-24 16:39:01 +0100 | [diff] [blame] | 126 | int ret; |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 127 | |
| 128 | if (cstream->direction == SND_COMPRESS_PLAYBACK) |
| 129 | stream = SNDRV_PCM_STREAM_PLAYBACK; |
| 130 | else |
| 131 | stream = SNDRV_PCM_STREAM_CAPTURE; |
| 132 | |
| 133 | mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME); |
Srinivas Kandagatla | 0b0722e | 2018-08-03 13:30:03 +0100 | [diff] [blame] | 134 | fe->dpcm[stream].runtime = fe_substream->runtime; |
| 135 | |
| 136 | ret = dpcm_path_get(fe, stream, &list); |
| 137 | if (ret < 0) |
| 138 | goto be_err; |
| 139 | else if (ret == 0) |
| 140 | dev_dbg(fe->dev, "Compress ASoC: %s no valid %s route\n", |
| 141 | fe->dai_link->name, stream ? "capture" : "playback"); |
| 142 | /* calculate valid and active FE <-> BE dpcms */ |
| 143 | dpcm_process_paths(fe, stream, &list, 1); |
| 144 | fe->dpcm[stream].runtime = fe_substream->runtime; |
| 145 | |
| 146 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE; |
| 147 | |
| 148 | ret = dpcm_be_dai_startup(fe, stream); |
| 149 | if (ret < 0) { |
| 150 | /* clean up all links */ |
Kuninori Morimoto | 8d6258a | 2018-09-18 01:31:09 +0000 | [diff] [blame] | 151 | for_each_dpcm_be(fe, stream, dpcm) |
Srinivas Kandagatla | 0b0722e | 2018-08-03 13:30:03 +0100 | [diff] [blame] | 152 | dpcm->state = SND_SOC_DPCM_LINK_STATE_FREE; |
| 153 | |
| 154 | dpcm_be_disconnect(fe, stream); |
| 155 | fe->dpcm[stream].runtime = NULL; |
| 156 | goto out; |
| 157 | } |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 158 | |
Kuninori Morimoto | b5ae4cc | 2020-04-24 08:15:24 +0900 | [diff] [blame] | 159 | ret = snd_soc_dai_compr_startup(cpu_dai, cstream); |
| 160 | if (ret < 0) |
| 161 | goto out; |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 162 | |
Charles Keepax | 1e57b82 | 2018-04-24 16:39:03 +0100 | [diff] [blame] | 163 | ret = soc_compr_components_open(cstream, &component); |
| 164 | if (ret < 0) |
Srinivas Kandagatla | 0b0722e | 2018-08-03 13:30:03 +0100 | [diff] [blame] | 165 | goto open_err; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 166 | |
Kuninori Morimoto | 9ab711c | 2020-05-25 09:57:41 +0900 | [diff] [blame] | 167 | ret = snd_soc_link_compr_startup(cstream); |
| 168 | if (ret < 0) |
| 169 | goto machine_err; |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 170 | |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 171 | dpcm_clear_pending_state(fe, stream); |
| 172 | dpcm_path_put(&list); |
| 173 | |
| 174 | fe->dpcm[stream].state = SND_SOC_DPCM_STATE_OPEN; |
| 175 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO; |
| 176 | |
Lars-Peter Clausen | 24894b7 | 2014-03-05 13:17:43 +0100 | [diff] [blame] | 177 | snd_soc_runtime_activate(fe, stream); |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 178 | |
| 179 | mutex_unlock(&fe->card->mutex); |
| 180 | |
| 181 | return 0; |
| 182 | |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 183 | machine_err: |
Charles Keepax | 1e57b82 | 2018-04-24 16:39:03 +0100 | [diff] [blame] | 184 | soc_compr_components_free(cstream, component); |
Srinivas Kandagatla | 0b0722e | 2018-08-03 13:30:03 +0100 | [diff] [blame] | 185 | open_err: |
Kuninori Morimoto | 2b25f81 | 2020-04-24 08:15:28 +0900 | [diff] [blame] | 186 | snd_soc_dai_compr_shutdown(cpu_dai, cstream); |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 187 | out: |
Srinivas Kandagatla | 0b0722e | 2018-08-03 13:30:03 +0100 | [diff] [blame] | 188 | dpcm_path_put(&list); |
| 189 | be_err: |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 190 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO; |
| 191 | mutex_unlock(&fe->card->mutex); |
| 192 | return ret; |
| 193 | } |
| 194 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 195 | static int soc_compr_free(struct snd_compr_stream *cstream) |
| 196 | { |
| 197 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
Kuninori Morimoto | c2233a2 | 2020-03-30 10:47:37 +0900 | [diff] [blame] | 198 | struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0); |
| 199 | struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0); |
Kuninori Morimoto | 939a5cf | 2020-09-28 09:01:17 +0900 | [diff] [blame] | 200 | int stream; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 201 | |
Peter Ujfalusi | 72b745e | 2019-08-13 13:45:32 +0300 | [diff] [blame] | 202 | mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 203 | |
Lars-Peter Clausen | 24894b7 | 2014-03-05 13:17:43 +0100 | [diff] [blame] | 204 | if (cstream->direction == SND_COMPRESS_PLAYBACK) |
| 205 | stream = SNDRV_PCM_STREAM_PLAYBACK; |
| 206 | else |
| 207 | stream = SNDRV_PCM_STREAM_CAPTURE; |
| 208 | |
| 209 | snd_soc_runtime_deactivate(rtd, stream); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 210 | |
Mark Brown | da18396 | 2013-02-06 15:44:07 +0000 | [diff] [blame] | 211 | snd_soc_dai_digital_mute(codec_dai, 1, cstream->direction); |
| 212 | |
Kuninori Morimoto | b3dea62 | 2020-05-15 09:46:51 +0900 | [diff] [blame] | 213 | if (!snd_soc_dai_active(cpu_dai)) |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 214 | cpu_dai->rate = 0; |
| 215 | |
Kuninori Morimoto | b3dea62 | 2020-05-15 09:46:51 +0900 | [diff] [blame] | 216 | if (!snd_soc_dai_active(codec_dai)) |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 217 | codec_dai->rate = 0; |
| 218 | |
Kuninori Morimoto | 0e532c9 | 2020-05-25 09:57:45 +0900 | [diff] [blame] | 219 | snd_soc_link_compr_shutdown(cstream); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 220 | |
Charles Keepax | 1e57b82 | 2018-04-24 16:39:03 +0100 | [diff] [blame] | 221 | soc_compr_components_free(cstream, NULL); |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 222 | |
Kuninori Morimoto | 2b25f81 | 2020-04-24 08:15:28 +0900 | [diff] [blame] | 223 | snd_soc_dai_compr_shutdown(cpu_dai, cstream); |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 224 | |
Kuninori Morimoto | 3f4cf79 | 2020-01-10 11:36:23 +0900 | [diff] [blame] | 225 | snd_soc_dapm_stream_stop(rtd, stream); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 226 | |
Peter Ujfalusi | 72b745e | 2019-08-13 13:45:32 +0300 | [diff] [blame] | 227 | mutex_unlock(&rtd->card->pcm_mutex); |
Cezary Rojewski | 4137f4b | 2019-12-17 10:58:50 +0100 | [diff] [blame] | 228 | |
Kuninori Morimoto | 939a5cf | 2020-09-28 09:01:17 +0900 | [diff] [blame] | 229 | snd_soc_pcm_component_pm_runtime_put(rtd, cstream, 0); |
Cezary Rojewski | 4137f4b | 2019-12-17 10:58:50 +0100 | [diff] [blame] | 230 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 231 | return 0; |
| 232 | } |
| 233 | |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 234 | static int soc_compr_free_fe(struct snd_compr_stream *cstream) |
| 235 | { |
| 236 | struct snd_soc_pcm_runtime *fe = cstream->private_data; |
Kuninori Morimoto | c2233a2 | 2020-03-30 10:47:37 +0900 | [diff] [blame] | 237 | struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(fe, 0); |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 238 | struct snd_soc_dpcm *dpcm; |
| 239 | int stream, ret; |
| 240 | |
| 241 | mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME); |
| 242 | |
Lars-Peter Clausen | 24894b7 | 2014-03-05 13:17:43 +0100 | [diff] [blame] | 243 | if (cstream->direction == SND_COMPRESS_PLAYBACK) |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 244 | stream = SNDRV_PCM_STREAM_PLAYBACK; |
Lars-Peter Clausen | 24894b7 | 2014-03-05 13:17:43 +0100 | [diff] [blame] | 245 | else |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 246 | stream = SNDRV_PCM_STREAM_CAPTURE; |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 247 | |
Lars-Peter Clausen | 24894b7 | 2014-03-05 13:17:43 +0100 | [diff] [blame] | 248 | snd_soc_runtime_deactivate(fe, stream); |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 249 | |
| 250 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE; |
| 251 | |
| 252 | ret = dpcm_be_dai_hw_free(fe, stream); |
| 253 | if (ret < 0) |
Charles Keepax | 141dfc9 | 2018-01-26 13:08:45 +0000 | [diff] [blame] | 254 | dev_err(fe->dev, "Compressed ASoC: hw_free failed: %d\n", ret); |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 255 | |
| 256 | ret = dpcm_be_dai_shutdown(fe, stream); |
| 257 | |
| 258 | /* mark FE's links ready to prune */ |
Kuninori Morimoto | 8d6258a | 2018-09-18 01:31:09 +0000 | [diff] [blame] | 259 | for_each_dpcm_be(fe, stream, dpcm) |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 260 | dpcm->state = SND_SOC_DPCM_LINK_STATE_FREE; |
| 261 | |
Kuninori Morimoto | 1c53123 | 2020-02-21 10:25:18 +0900 | [diff] [blame] | 262 | dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_STOP); |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 263 | |
| 264 | fe->dpcm[stream].state = SND_SOC_DPCM_STATE_CLOSE; |
| 265 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO; |
| 266 | |
| 267 | dpcm_be_disconnect(fe, stream); |
| 268 | |
| 269 | fe->dpcm[stream].runtime = NULL; |
| 270 | |
Kuninori Morimoto | 0e532c9 | 2020-05-25 09:57:45 +0900 | [diff] [blame] | 271 | snd_soc_link_compr_shutdown(cstream); |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 272 | |
Charles Keepax | 1e57b82 | 2018-04-24 16:39:03 +0100 | [diff] [blame] | 273 | soc_compr_components_free(cstream, NULL); |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 274 | |
Kuninori Morimoto | 2b25f81 | 2020-04-24 08:15:28 +0900 | [diff] [blame] | 275 | snd_soc_dai_compr_shutdown(cpu_dai, cstream); |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 276 | |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 277 | mutex_unlock(&fe->card->mutex); |
| 278 | return 0; |
| 279 | } |
| 280 | |
Charles Keepax | 4ef0ecb | 2019-02-05 11:18:13 +0000 | [diff] [blame] | 281 | static int soc_compr_components_trigger(struct snd_compr_stream *cstream, |
| 282 | int cmd) |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 283 | { |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 284 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 285 | struct snd_soc_component *component; |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 286 | int i, ret; |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 287 | |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 288 | for_each_rtd_components(rtd, i, component) { |
Kuninori Morimoto | c6cb522 | 2020-04-20 16:07:50 +0900 | [diff] [blame] | 289 | if (!component->driver->compress_ops || |
| 290 | !component->driver->compress_ops->trigger) |
| 291 | continue; |
| 292 | |
| 293 | ret = component->driver->compress_ops->trigger( |
| 294 | component, cstream, cmd); |
| 295 | if (ret < 0) |
| 296 | return ret; |
| 297 | } |
| 298 | |
Charles Keepax | 4ef0ecb | 2019-02-05 11:18:13 +0000 | [diff] [blame] | 299 | return 0; |
| 300 | } |
| 301 | |
| 302 | static int soc_compr_trigger(struct snd_compr_stream *cstream, int cmd) |
| 303 | { |
| 304 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
Kuninori Morimoto | c2233a2 | 2020-03-30 10:47:37 +0900 | [diff] [blame] | 305 | struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0); |
| 306 | struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0); |
Charles Keepax | 4ef0ecb | 2019-02-05 11:18:13 +0000 | [diff] [blame] | 307 | int ret; |
| 308 | |
Peter Ujfalusi | 72b745e | 2019-08-13 13:45:32 +0300 | [diff] [blame] | 309 | mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); |
Charles Keepax | 4ef0ecb | 2019-02-05 11:18:13 +0000 | [diff] [blame] | 310 | |
| 311 | ret = soc_compr_components_trigger(cstream, cmd); |
| 312 | if (ret < 0) |
| 313 | goto out; |
| 314 | |
Kuninori Morimoto | eb08411 | 2020-04-24 08:15:32 +0900 | [diff] [blame] | 315 | ret = snd_soc_dai_compr_trigger(cpu_dai, cstream, cmd); |
| 316 | if (ret < 0) |
| 317 | goto out; |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 318 | |
Mark Brown | da18396 | 2013-02-06 15:44:07 +0000 | [diff] [blame] | 319 | switch (cmd) { |
| 320 | case SNDRV_PCM_TRIGGER_START: |
| 321 | snd_soc_dai_digital_mute(codec_dai, 0, cstream->direction); |
| 322 | break; |
| 323 | case SNDRV_PCM_TRIGGER_STOP: |
| 324 | snd_soc_dai_digital_mute(codec_dai, 1, cstream->direction); |
| 325 | break; |
Mark Brown | e38b9b7 | 2013-02-06 13:52:42 +0000 | [diff] [blame] | 326 | } |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 327 | |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 328 | out: |
Peter Ujfalusi | 72b745e | 2019-08-13 13:45:32 +0300 | [diff] [blame] | 329 | mutex_unlock(&rtd->card->pcm_mutex); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 330 | return ret; |
| 331 | } |
| 332 | |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 333 | static int soc_compr_trigger_fe(struct snd_compr_stream *cstream, int cmd) |
| 334 | { |
| 335 | struct snd_soc_pcm_runtime *fe = cstream->private_data; |
Kuninori Morimoto | c2233a2 | 2020-03-30 10:47:37 +0900 | [diff] [blame] | 336 | struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(fe, 0); |
Charles Keepax | 52cadf1 | 2019-02-05 11:18:12 +0000 | [diff] [blame] | 337 | int ret, stream; |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 338 | |
| 339 | if (cmd == SND_COMPR_TRIGGER_PARTIAL_DRAIN || |
Charles Keepax | 4ef0ecb | 2019-02-05 11:18:13 +0000 | [diff] [blame] | 340 | cmd == SND_COMPR_TRIGGER_DRAIN) |
| 341 | return soc_compr_components_trigger(cstream, cmd); |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 342 | |
| 343 | if (cstream->direction == SND_COMPRESS_PLAYBACK) |
| 344 | stream = SNDRV_PCM_STREAM_PLAYBACK; |
| 345 | else |
| 346 | stream = SNDRV_PCM_STREAM_CAPTURE; |
| 347 | |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 348 | mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME); |
| 349 | |
Kuninori Morimoto | eb08411 | 2020-04-24 08:15:32 +0900 | [diff] [blame] | 350 | ret = snd_soc_dai_compr_trigger(cpu_dai, cstream, cmd); |
| 351 | if (ret < 0) |
| 352 | goto out; |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 353 | |
Charles Keepax | 4ef0ecb | 2019-02-05 11:18:13 +0000 | [diff] [blame] | 354 | ret = soc_compr_components_trigger(cstream, cmd); |
| 355 | if (ret < 0) |
| 356 | goto out; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 357 | |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 358 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE; |
| 359 | |
| 360 | ret = dpcm_be_dai_trigger(fe, stream, cmd); |
| 361 | |
| 362 | switch (cmd) { |
| 363 | case SNDRV_PCM_TRIGGER_START: |
| 364 | case SNDRV_PCM_TRIGGER_RESUME: |
| 365 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
| 366 | fe->dpcm[stream].state = SND_SOC_DPCM_STATE_START; |
| 367 | break; |
| 368 | case SNDRV_PCM_TRIGGER_STOP: |
| 369 | case SNDRV_PCM_TRIGGER_SUSPEND: |
| 370 | fe->dpcm[stream].state = SND_SOC_DPCM_STATE_STOP; |
| 371 | break; |
| 372 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
| 373 | fe->dpcm[stream].state = SND_SOC_DPCM_STATE_PAUSED; |
| 374 | break; |
| 375 | } |
| 376 | |
| 377 | out: |
| 378 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO; |
| 379 | mutex_unlock(&fe->card->mutex); |
| 380 | return ret; |
| 381 | } |
| 382 | |
Charles Keepax | 4ef0ecb | 2019-02-05 11:18:13 +0000 | [diff] [blame] | 383 | static int soc_compr_components_set_params(struct snd_compr_stream *cstream, |
| 384 | struct snd_compr_params *params) |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 385 | { |
| 386 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 387 | struct snd_soc_component *component; |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 388 | int i, ret; |
Charles Keepax | 4ef0ecb | 2019-02-05 11:18:13 +0000 | [diff] [blame] | 389 | |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 390 | for_each_rtd_components(rtd, i, component) { |
Kuninori Morimoto | c6cb522 | 2020-04-20 16:07:50 +0900 | [diff] [blame] | 391 | if (!component->driver->compress_ops || |
| 392 | !component->driver->compress_ops->set_params) |
| 393 | continue; |
| 394 | |
| 395 | ret = component->driver->compress_ops->set_params( |
| 396 | component, cstream, params); |
| 397 | if (ret < 0) |
| 398 | return ret; |
| 399 | } |
| 400 | |
Charles Keepax | 4ef0ecb | 2019-02-05 11:18:13 +0000 | [diff] [blame] | 401 | return 0; |
| 402 | } |
| 403 | |
| 404 | static int soc_compr_set_params(struct snd_compr_stream *cstream, |
| 405 | struct snd_compr_params *params) |
| 406 | { |
| 407 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
Kuninori Morimoto | c2233a2 | 2020-03-30 10:47:37 +0900 | [diff] [blame] | 408 | struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0); |
Charles Keepax | 52cadf1 | 2019-02-05 11:18:12 +0000 | [diff] [blame] | 409 | int ret; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 410 | |
Peter Ujfalusi | 72b745e | 2019-08-13 13:45:32 +0300 | [diff] [blame] | 411 | mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 412 | |
Charles Keepax | ef050be | 2018-04-24 16:39:02 +0100 | [diff] [blame] | 413 | /* |
| 414 | * First we call set_params for the CPU DAI, then the component |
| 415 | * driver this should configure the SoC side. If the machine has |
| 416 | * compressed ops then we call that as well. The expectation is |
| 417 | * that these callbacks will configure everything for this compress |
| 418 | * path, like configuring a PCM port for a CODEC. |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 419 | */ |
Kuninori Morimoto | 8dfedaf | 2020-04-24 08:15:36 +0900 | [diff] [blame] | 420 | ret = snd_soc_dai_compr_set_params(cpu_dai, cstream, params); |
| 421 | if (ret < 0) |
| 422 | goto err; |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 423 | |
Charles Keepax | 4ef0ecb | 2019-02-05 11:18:13 +0000 | [diff] [blame] | 424 | ret = soc_compr_components_set_params(cstream, params); |
| 425 | if (ret < 0) |
| 426 | goto err; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 427 | |
Kuninori Morimoto | eab810f | 2020-05-25 09:57:50 +0900 | [diff] [blame] | 428 | ret = snd_soc_link_compr_set_params(cstream); |
| 429 | if (ret < 0) |
| 430 | goto err; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 431 | |
Charles Keepax | 2c071ed | 2013-05-20 08:33:54 +0100 | [diff] [blame] | 432 | if (cstream->direction == SND_COMPRESS_PLAYBACK) |
| 433 | snd_soc_dapm_stream_event(rtd, SNDRV_PCM_STREAM_PLAYBACK, |
Charles Keepax | 89027d9 | 2018-04-26 17:30:07 +0100 | [diff] [blame] | 434 | SND_SOC_DAPM_STREAM_START); |
Charles Keepax | 2c071ed | 2013-05-20 08:33:54 +0100 | [diff] [blame] | 435 | else |
| 436 | snd_soc_dapm_stream_event(rtd, SNDRV_PCM_STREAM_CAPTURE, |
Charles Keepax | 89027d9 | 2018-04-26 17:30:07 +0100 | [diff] [blame] | 437 | SND_SOC_DAPM_STREAM_START); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 438 | |
Charles Keepax | fa40ef2 | 2013-03-27 16:39:01 +0000 | [diff] [blame] | 439 | /* cancel any delayed stream shutdown that is pending */ |
| 440 | rtd->pop_wait = 0; |
Peter Ujfalusi | 72b745e | 2019-08-13 13:45:32 +0300 | [diff] [blame] | 441 | mutex_unlock(&rtd->card->pcm_mutex); |
Charles Keepax | fa40ef2 | 2013-03-27 16:39:01 +0000 | [diff] [blame] | 442 | |
| 443 | cancel_delayed_work_sync(&rtd->delayed_work); |
| 444 | |
Charles Keepax | 52cadf1 | 2019-02-05 11:18:12 +0000 | [diff] [blame] | 445 | return 0; |
Charles Keepax | fa40ef2 | 2013-03-27 16:39:01 +0000 | [diff] [blame] | 446 | |
| 447 | err: |
Peter Ujfalusi | 72b745e | 2019-08-13 13:45:32 +0300 | [diff] [blame] | 448 | mutex_unlock(&rtd->card->pcm_mutex); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 449 | return ret; |
| 450 | } |
| 451 | |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 452 | static int soc_compr_set_params_fe(struct snd_compr_stream *cstream, |
Charles Keepax | 89027d9 | 2018-04-26 17:30:07 +0100 | [diff] [blame] | 453 | struct snd_compr_params *params) |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 454 | { |
| 455 | struct snd_soc_pcm_runtime *fe = cstream->private_data; |
Satish Babu Patakokila | 01b8ced | 2017-06-16 17:33:40 -0700 | [diff] [blame] | 456 | struct snd_pcm_substream *fe_substream = |
| 457 | fe->pcm->streams[cstream->direction].substream; |
Kuninori Morimoto | c2233a2 | 2020-03-30 10:47:37 +0900 | [diff] [blame] | 458 | struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(fe, 0); |
Charles Keepax | 52cadf1 | 2019-02-05 11:18:12 +0000 | [diff] [blame] | 459 | int ret, stream; |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 460 | |
| 461 | if (cstream->direction == SND_COMPRESS_PLAYBACK) |
| 462 | stream = SNDRV_PCM_STREAM_PLAYBACK; |
| 463 | else |
| 464 | stream = SNDRV_PCM_STREAM_CAPTURE; |
| 465 | |
| 466 | mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME); |
| 467 | |
Srinivas Kandagatla | 0b0722e | 2018-08-03 13:30:03 +0100 | [diff] [blame] | 468 | /* |
| 469 | * Create an empty hw_params for the BE as the machine driver must |
| 470 | * fix this up to match DSP decoder and ASRC configuration. |
| 471 | * I.e. machine driver fixup for compressed BE is mandatory. |
| 472 | */ |
| 473 | memset(&fe->dpcm[fe_substream->stream].hw_params, 0, |
| 474 | sizeof(struct snd_pcm_hw_params)); |
| 475 | |
| 476 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE; |
| 477 | |
| 478 | ret = dpcm_be_dai_hw_params(fe, stream); |
| 479 | if (ret < 0) |
| 480 | goto out; |
| 481 | |
| 482 | ret = dpcm_be_dai_prepare(fe, stream); |
| 483 | if (ret < 0) |
| 484 | goto out; |
| 485 | |
Kuninori Morimoto | 8dfedaf | 2020-04-24 08:15:36 +0900 | [diff] [blame] | 486 | ret = snd_soc_dai_compr_set_params(cpu_dai, cstream, params); |
| 487 | if (ret < 0) |
| 488 | goto out; |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 489 | |
Charles Keepax | 4ef0ecb | 2019-02-05 11:18:13 +0000 | [diff] [blame] | 490 | ret = soc_compr_components_set_params(cstream, params); |
| 491 | if (ret < 0) |
| 492 | goto out; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 493 | |
Kuninori Morimoto | eab810f | 2020-05-25 09:57:50 +0900 | [diff] [blame] | 494 | ret = snd_soc_link_compr_set_params(cstream); |
| 495 | if (ret < 0) |
| 496 | goto out; |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 497 | |
Daniel Mack | 15f6b09 | 2014-10-19 09:07:35 +0200 | [diff] [blame] | 498 | dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_START); |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 499 | fe->dpcm[stream].state = SND_SOC_DPCM_STATE_PREPARE; |
| 500 | |
| 501 | out: |
| 502 | fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO; |
| 503 | mutex_unlock(&fe->card->mutex); |
| 504 | return ret; |
| 505 | } |
| 506 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 507 | static int soc_compr_get_params(struct snd_compr_stream *cstream, |
Charles Keepax | 89027d9 | 2018-04-26 17:30:07 +0100 | [diff] [blame] | 508 | struct snd_codec *params) |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 509 | { |
| 510 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 511 | struct snd_soc_component *component; |
Kuninori Morimoto | c2233a2 | 2020-03-30 10:47:37 +0900 | [diff] [blame] | 512 | struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0); |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 513 | int i, ret = 0; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 514 | |
Peter Ujfalusi | 72b745e | 2019-08-13 13:45:32 +0300 | [diff] [blame] | 515 | mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 516 | |
Kuninori Morimoto | adbef543 | 2020-04-24 08:15:40 +0900 | [diff] [blame] | 517 | ret = snd_soc_dai_compr_get_params(cpu_dai, cstream, params); |
| 518 | if (ret < 0) |
| 519 | goto err; |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 520 | |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 521 | for_each_rtd_components(rtd, i, component) { |
Kuninori Morimoto | c6cb522 | 2020-04-20 16:07:50 +0900 | [diff] [blame] | 522 | if (!component->driver->compress_ops || |
| 523 | !component->driver->compress_ops->get_params) |
| 524 | continue; |
| 525 | |
| 526 | ret = component->driver->compress_ops->get_params( |
| 527 | component, cstream, params); |
| 528 | break; |
| 529 | } |
| 530 | |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 531 | err: |
Peter Ujfalusi | 72b745e | 2019-08-13 13:45:32 +0300 | [diff] [blame] | 532 | mutex_unlock(&rtd->card->pcm_mutex); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 533 | return ret; |
| 534 | } |
| 535 | |
| 536 | static int soc_compr_get_caps(struct snd_compr_stream *cstream, |
Charles Keepax | 89027d9 | 2018-04-26 17:30:07 +0100 | [diff] [blame] | 537 | struct snd_compr_caps *caps) |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 538 | { |
| 539 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 540 | struct snd_soc_component *component; |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 541 | int i, ret = 0; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 542 | |
Peter Ujfalusi | 72b745e | 2019-08-13 13:45:32 +0300 | [diff] [blame] | 543 | mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 544 | |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 545 | for_each_rtd_components(rtd, i, component) { |
Kuninori Morimoto | c6cb522 | 2020-04-20 16:07:50 +0900 | [diff] [blame] | 546 | if (!component->driver->compress_ops || |
| 547 | !component->driver->compress_ops->get_caps) |
| 548 | continue; |
| 549 | |
| 550 | ret = component->driver->compress_ops->get_caps( |
| 551 | component, cstream, caps); |
| 552 | break; |
| 553 | } |
| 554 | |
Peter Ujfalusi | 72b745e | 2019-08-13 13:45:32 +0300 | [diff] [blame] | 555 | mutex_unlock(&rtd->card->pcm_mutex); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 556 | return ret; |
| 557 | } |
| 558 | |
| 559 | static int soc_compr_get_codec_caps(struct snd_compr_stream *cstream, |
Charles Keepax | 89027d9 | 2018-04-26 17:30:07 +0100 | [diff] [blame] | 560 | struct snd_compr_codec_caps *codec) |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 561 | { |
| 562 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 563 | struct snd_soc_component *component; |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 564 | int i, ret = 0; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 565 | |
Peter Ujfalusi | 72b745e | 2019-08-13 13:45:32 +0300 | [diff] [blame] | 566 | mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 567 | |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 568 | for_each_rtd_components(rtd, i, component) { |
Kuninori Morimoto | c6cb522 | 2020-04-20 16:07:50 +0900 | [diff] [blame] | 569 | if (!component->driver->compress_ops || |
| 570 | !component->driver->compress_ops->get_codec_caps) |
| 571 | continue; |
| 572 | |
| 573 | ret = component->driver->compress_ops->get_codec_caps( |
| 574 | component, cstream, codec); |
| 575 | break; |
| 576 | } |
| 577 | |
Peter Ujfalusi | 72b745e | 2019-08-13 13:45:32 +0300 | [diff] [blame] | 578 | mutex_unlock(&rtd->card->pcm_mutex); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 579 | return ret; |
| 580 | } |
| 581 | |
| 582 | static int soc_compr_ack(struct snd_compr_stream *cstream, size_t bytes) |
| 583 | { |
| 584 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 585 | struct snd_soc_component *component; |
Kuninori Morimoto | c2233a2 | 2020-03-30 10:47:37 +0900 | [diff] [blame] | 586 | struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0); |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 587 | int i, ret = 0; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 588 | |
Peter Ujfalusi | 72b745e | 2019-08-13 13:45:32 +0300 | [diff] [blame] | 589 | mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 590 | |
Kuninori Morimoto | 5329435 | 2020-04-24 08:15:45 +0900 | [diff] [blame] | 591 | ret = snd_soc_dai_compr_ack(cpu_dai, cstream, bytes); |
| 592 | if (ret < 0) |
| 593 | goto err; |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 594 | |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 595 | for_each_rtd_components(rtd, i, component) { |
Kuninori Morimoto | c6cb522 | 2020-04-20 16:07:50 +0900 | [diff] [blame] | 596 | if (!component->driver->compress_ops || |
| 597 | !component->driver->compress_ops->ack) |
| 598 | continue; |
| 599 | |
| 600 | ret = component->driver->compress_ops->ack( |
| 601 | component, cstream, bytes); |
| 602 | if (ret < 0) |
| 603 | goto err; |
| 604 | } |
| 605 | |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 606 | err: |
Peter Ujfalusi | 72b745e | 2019-08-13 13:45:32 +0300 | [diff] [blame] | 607 | mutex_unlock(&rtd->card->pcm_mutex); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 608 | return ret; |
| 609 | } |
| 610 | |
| 611 | static int soc_compr_pointer(struct snd_compr_stream *cstream, |
Charles Keepax | 89027d9 | 2018-04-26 17:30:07 +0100 | [diff] [blame] | 612 | struct snd_compr_tstamp *tstamp) |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 613 | { |
| 614 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 615 | struct snd_soc_component *component; |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 616 | int i, ret = 0; |
Kuninori Morimoto | c2233a2 | 2020-03-30 10:47:37 +0900 | [diff] [blame] | 617 | struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 618 | |
Peter Ujfalusi | 72b745e | 2019-08-13 13:45:32 +0300 | [diff] [blame] | 619 | mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); |
Charles Keepax | 15e2e61 | 2013-01-24 09:44:29 +0000 | [diff] [blame] | 620 | |
Kuninori Morimoto | ed38cc5 | 2020-04-24 08:15:49 +0900 | [diff] [blame] | 621 | ret = snd_soc_dai_compr_pointer(cpu_dai, cstream, tstamp); |
| 622 | if (ret < 0) |
| 623 | goto out; |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 624 | |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 625 | for_each_rtd_components(rtd, i, component) { |
Kuninori Morimoto | c6cb522 | 2020-04-20 16:07:50 +0900 | [diff] [blame] | 626 | if (!component->driver->compress_ops || |
| 627 | !component->driver->compress_ops->pointer) |
| 628 | continue; |
| 629 | |
| 630 | ret = component->driver->compress_ops->pointer( |
| 631 | component, cstream, tstamp); |
| 632 | break; |
| 633 | } |
Kuninori Morimoto | ed38cc5 | 2020-04-24 08:15:49 +0900 | [diff] [blame] | 634 | out: |
Peter Ujfalusi | 72b745e | 2019-08-13 13:45:32 +0300 | [diff] [blame] | 635 | mutex_unlock(&rtd->card->pcm_mutex); |
Charles Keepax | 7c9190f | 2016-06-20 09:51:32 +0100 | [diff] [blame] | 636 | return ret; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 637 | } |
| 638 | |
Charles Keepax | 1f88eb0 | 2013-02-05 10:41:47 +0000 | [diff] [blame] | 639 | static int soc_compr_copy(struct snd_compr_stream *cstream, |
Charles Keepax | 4daf891 | 2013-04-18 11:01:38 +0100 | [diff] [blame] | 640 | char __user *buf, size_t count) |
Charles Keepax | 1f88eb0 | 2013-02-05 10:41:47 +0000 | [diff] [blame] | 641 | { |
| 642 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 643 | struct snd_soc_component *component; |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 644 | int i, ret = 0; |
Charles Keepax | 1f88eb0 | 2013-02-05 10:41:47 +0000 | [diff] [blame] | 645 | |
Peter Ujfalusi | 72b745e | 2019-08-13 13:45:32 +0300 | [diff] [blame] | 646 | mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); |
Charles Keepax | 1f88eb0 | 2013-02-05 10:41:47 +0000 | [diff] [blame] | 647 | |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 648 | for_each_rtd_components(rtd, i, component) { |
Kuninori Morimoto | c6cb522 | 2020-04-20 16:07:50 +0900 | [diff] [blame] | 649 | if (!component->driver->compress_ops || |
| 650 | !component->driver->compress_ops->copy) |
| 651 | continue; |
| 652 | |
| 653 | ret = component->driver->compress_ops->copy( |
| 654 | component, cstream, buf, count); |
| 655 | break; |
| 656 | } |
| 657 | |
Peter Ujfalusi | 72b745e | 2019-08-13 13:45:32 +0300 | [diff] [blame] | 658 | mutex_unlock(&rtd->card->pcm_mutex); |
Charles Keepax | 1f88eb0 | 2013-02-05 10:41:47 +0000 | [diff] [blame] | 659 | return ret; |
| 660 | } |
| 661 | |
Vinod Koul | 02bd90e | 2013-07-28 20:06:15 +0530 | [diff] [blame] | 662 | static int soc_compr_set_metadata(struct snd_compr_stream *cstream, |
Charles Keepax | 89027d9 | 2018-04-26 17:30:07 +0100 | [diff] [blame] | 663 | struct snd_compr_metadata *metadata) |
Jeeja KP | 36953d9 | 2013-03-26 21:22:28 +0530 | [diff] [blame] | 664 | { |
| 665 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 666 | struct snd_soc_component *component; |
Kuninori Morimoto | c2233a2 | 2020-03-30 10:47:37 +0900 | [diff] [blame] | 667 | struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0); |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 668 | int i, ret; |
Jeeja KP | 36953d9 | 2013-03-26 21:22:28 +0530 | [diff] [blame] | 669 | |
Kuninori Morimoto | 88b3a7d | 2020-04-24 08:15:54 +0900 | [diff] [blame] | 670 | ret = snd_soc_dai_compr_set_metadata(cpu_dai, cstream, metadata); |
| 671 | if (ret < 0) |
| 672 | return ret; |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 673 | |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 674 | for_each_rtd_components(rtd, i, component) { |
Kuninori Morimoto | c6cb522 | 2020-04-20 16:07:50 +0900 | [diff] [blame] | 675 | if (!component->driver->compress_ops || |
| 676 | !component->driver->compress_ops->set_metadata) |
| 677 | continue; |
| 678 | |
| 679 | ret = component->driver->compress_ops->set_metadata( |
| 680 | component, cstream, metadata); |
| 681 | if (ret < 0) |
| 682 | return ret; |
| 683 | } |
| 684 | |
Charles Keepax | 52cadf1 | 2019-02-05 11:18:12 +0000 | [diff] [blame] | 685 | return 0; |
Jeeja KP | 36953d9 | 2013-03-26 21:22:28 +0530 | [diff] [blame] | 686 | } |
| 687 | |
Vinod Koul | 02bd90e | 2013-07-28 20:06:15 +0530 | [diff] [blame] | 688 | static int soc_compr_get_metadata(struct snd_compr_stream *cstream, |
Charles Keepax | 89027d9 | 2018-04-26 17:30:07 +0100 | [diff] [blame] | 689 | struct snd_compr_metadata *metadata) |
Jeeja KP | 36953d9 | 2013-03-26 21:22:28 +0530 | [diff] [blame] | 690 | { |
| 691 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 692 | struct snd_soc_component *component; |
Kuninori Morimoto | c2233a2 | 2020-03-30 10:47:37 +0900 | [diff] [blame] | 693 | struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0); |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 694 | int i, ret; |
Jeeja KP | 36953d9 | 2013-03-26 21:22:28 +0530 | [diff] [blame] | 695 | |
Kuninori Morimoto | 94d7281 | 2020-04-24 08:15:59 +0900 | [diff] [blame] | 696 | ret = snd_soc_dai_compr_get_metadata(cpu_dai, cstream, metadata); |
| 697 | if (ret < 0) |
| 698 | return ret; |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 699 | |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 700 | for_each_rtd_components(rtd, i, component) { |
Kuninori Morimoto | c6cb522 | 2020-04-20 16:07:50 +0900 | [diff] [blame] | 701 | if (!component->driver->compress_ops || |
| 702 | !component->driver->compress_ops->get_metadata) |
| 703 | continue; |
| 704 | |
| 705 | return component->driver->compress_ops->get_metadata( |
| 706 | component, cstream, metadata); |
| 707 | } |
| 708 | |
Charles Keepax | 52cadf1 | 2019-02-05 11:18:12 +0000 | [diff] [blame] | 709 | return 0; |
Jeeja KP | 36953d9 | 2013-03-26 21:22:28 +0530 | [diff] [blame] | 710 | } |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 711 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 712 | /* ASoC Compress operations */ |
| 713 | static struct snd_compr_ops soc_compr_ops = { |
| 714 | .open = soc_compr_open, |
| 715 | .free = soc_compr_free, |
| 716 | .set_params = soc_compr_set_params, |
Vinod Koul | 02bd90e | 2013-07-28 20:06:15 +0530 | [diff] [blame] | 717 | .set_metadata = soc_compr_set_metadata, |
| 718 | .get_metadata = soc_compr_get_metadata, |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 719 | .get_params = soc_compr_get_params, |
| 720 | .trigger = soc_compr_trigger, |
| 721 | .pointer = soc_compr_pointer, |
| 722 | .ack = soc_compr_ack, |
| 723 | .get_caps = soc_compr_get_caps, |
| 724 | .get_codec_caps = soc_compr_get_codec_caps |
| 725 | }; |
| 726 | |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 727 | /* ASoC Dynamic Compress operations */ |
| 728 | static struct snd_compr_ops soc_compr_dyn_ops = { |
| 729 | .open = soc_compr_open_fe, |
| 730 | .free = soc_compr_free_fe, |
| 731 | .set_params = soc_compr_set_params_fe, |
| 732 | .get_params = soc_compr_get_params, |
| 733 | .set_metadata = soc_compr_set_metadata, |
| 734 | .get_metadata = soc_compr_get_metadata, |
| 735 | .trigger = soc_compr_trigger_fe, |
| 736 | .pointer = soc_compr_pointer, |
| 737 | .ack = soc_compr_ack, |
| 738 | .get_caps = soc_compr_get_caps, |
| 739 | .get_codec_caps = soc_compr_get_codec_caps |
| 740 | }; |
| 741 | |
Jie Yang | 6f0c422 | 2015-10-13 23:41:00 +0800 | [diff] [blame] | 742 | /** |
| 743 | * snd_soc_new_compress - create a new compress. |
| 744 | * |
| 745 | * @rtd: The runtime for which we will create compress |
| 746 | * @num: the device index number (zero based - shared with normal PCMs) |
| 747 | * |
| 748 | * Return: 0 for success, else error. |
| 749 | */ |
| 750 | 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] | 751 | { |
Kuninori Morimoto | 9e7e373 | 2017-10-11 01:37:45 +0000 | [diff] [blame] | 752 | struct snd_soc_component *component; |
Kuninori Morimoto | c2233a2 | 2020-03-30 10:47:37 +0900 | [diff] [blame] | 753 | struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0); |
| 754 | struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 755 | struct snd_compr *compr; |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 756 | struct snd_pcm *be_pcm; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 757 | char new_name[64]; |
| 758 | int ret = 0, direction = 0; |
Vinod Koul | a106804 | 2016-01-07 21:48:14 +0530 | [diff] [blame] | 759 | int playback = 0, capture = 0; |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 760 | int i; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 761 | |
Bard Liao | 6e1276a | 2020-02-25 21:39:16 +0800 | [diff] [blame] | 762 | if (rtd->num_cpus > 1 || |
| 763 | rtd->num_codecs > 1) { |
Charles Keepax | 141dfc9 | 2018-01-26 13:08:45 +0000 | [diff] [blame] | 764 | dev_err(rtd->card->dev, |
Bard Liao | 6e1276a | 2020-02-25 21:39:16 +0800 | [diff] [blame] | 765 | "Compress ASoC: Multi CPU/Codec not supported\n"); |
Benoit Cousson | 8151d5e | 2014-07-08 23:19:37 +0200 | [diff] [blame] | 766 | return -EINVAL; |
| 767 | } |
| 768 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 769 | /* check client and interface hw capabilities */ |
Kuninori Morimoto | 467fece | 2019-07-22 10:36:16 +0900 | [diff] [blame] | 770 | if (snd_soc_dai_stream_valid(codec_dai, SNDRV_PCM_STREAM_PLAYBACK) && |
| 771 | snd_soc_dai_stream_valid(cpu_dai, SNDRV_PCM_STREAM_PLAYBACK)) |
Vinod Koul | a106804 | 2016-01-07 21:48:14 +0530 | [diff] [blame] | 772 | playback = 1; |
Kuninori Morimoto | 467fece | 2019-07-22 10:36:16 +0900 | [diff] [blame] | 773 | if (snd_soc_dai_stream_valid(codec_dai, SNDRV_PCM_STREAM_CAPTURE) && |
| 774 | snd_soc_dai_stream_valid(cpu_dai, SNDRV_PCM_STREAM_CAPTURE)) |
Vinod Koul | a106804 | 2016-01-07 21:48:14 +0530 | [diff] [blame] | 775 | capture = 1; |
| 776 | |
Vinod Koul | a106804 | 2016-01-07 21:48:14 +0530 | [diff] [blame] | 777 | /* |
| 778 | * Compress devices are unidirectional so only one of the directions |
| 779 | * should be set, check for that (xor) |
| 780 | */ |
| 781 | if (playback + capture != 1) { |
Charles Keepax | 141dfc9 | 2018-01-26 13:08:45 +0000 | [diff] [blame] | 782 | dev_err(rtd->card->dev, |
| 783 | "Compress ASoC: Invalid direction for P %d, C %d\n", |
| 784 | playback, capture); |
Charles Keepax | daa2db5 | 2013-04-18 11:02:38 +0100 | [diff] [blame] | 785 | return -EINVAL; |
Vinod Koul | a106804 | 2016-01-07 21:48:14 +0530 | [diff] [blame] | 786 | } |
| 787 | |
Peng Donglin | aeb6fa0 | 2017-08-16 22:47:53 +0800 | [diff] [blame] | 788 | if (playback) |
Vinod Koul | a106804 | 2016-01-07 21:48:14 +0530 | [diff] [blame] | 789 | direction = SND_COMPRESS_PLAYBACK; |
| 790 | else |
| 791 | direction = SND_COMPRESS_CAPTURE; |
Charles Keepax | daa2db5 | 2013-04-18 11:02:38 +0100 | [diff] [blame] | 792 | |
Amadeusz Sławiński | 09f448a | 2019-06-17 13:36:36 +0200 | [diff] [blame] | 793 | compr = devm_kzalloc(rtd->card->dev, sizeof(*compr), GFP_KERNEL); |
Markus Elfring | 7a0cf42 | 2017-08-10 16:21:34 +0200 | [diff] [blame] | 794 | if (!compr) |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 795 | return -ENOMEM; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 796 | |
Charles Keepax | 1f88eb0 | 2013-02-05 10:41:47 +0000 | [diff] [blame] | 797 | compr->ops = devm_kzalloc(rtd->card->dev, sizeof(soc_compr_ops), |
| 798 | GFP_KERNEL); |
Amadeusz Sławiński | 09f448a | 2019-06-17 13:36:36 +0200 | [diff] [blame] | 799 | if (!compr->ops) |
| 800 | return -ENOMEM; |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 801 | |
| 802 | if (rtd->dai_link->dynamic) { |
| 803 | snprintf(new_name, sizeof(new_name), "(%s)", |
| 804 | rtd->dai_link->stream_name); |
| 805 | |
| 806 | ret = snd_pcm_new_internal(rtd->card->snd_card, new_name, num, |
Qais Yousef | d3268a4 | 2015-01-14 08:47:29 +0000 | [diff] [blame] | 807 | rtd->dai_link->dpcm_playback, |
| 808 | rtd->dai_link->dpcm_capture, &be_pcm); |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 809 | if (ret < 0) { |
Charles Keepax | 141dfc9 | 2018-01-26 13:08:45 +0000 | [diff] [blame] | 810 | dev_err(rtd->card->dev, |
| 811 | "Compress ASoC: can't create compressed for %s: %d\n", |
| 812 | rtd->dai_link->name, ret); |
Amadeusz Sławiński | 09f448a | 2019-06-17 13:36:36 +0200 | [diff] [blame] | 813 | return ret; |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 814 | } |
| 815 | |
| 816 | rtd->pcm = be_pcm; |
| 817 | rtd->fe_compr = 1; |
Qais Yousef | d3268a4 | 2015-01-14 08:47:29 +0000 | [diff] [blame] | 818 | if (rtd->dai_link->dpcm_playback) |
| 819 | be_pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream->private_data = rtd; |
| 820 | else if (rtd->dai_link->dpcm_capture) |
| 821 | be_pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream->private_data = rtd; |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 822 | memcpy(compr->ops, &soc_compr_dyn_ops, sizeof(soc_compr_dyn_ops)); |
Peng Donglin | aeb6fa0 | 2017-08-16 22:47:53 +0800 | [diff] [blame] | 823 | } else { |
| 824 | snprintf(new_name, sizeof(new_name), "%s %s-%d", |
| 825 | rtd->dai_link->stream_name, codec_dai->name, num); |
| 826 | |
Liam Girdwood | 2a99ef0 | 2014-01-17 17:03:56 +0000 | [diff] [blame] | 827 | memcpy(compr->ops, &soc_compr_ops, sizeof(soc_compr_ops)); |
Peng Donglin | aeb6fa0 | 2017-08-16 22:47:53 +0800 | [diff] [blame] | 828 | } |
Charles Keepax | 1f88eb0 | 2013-02-05 10:41:47 +0000 | [diff] [blame] | 829 | |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 830 | for_each_rtd_components(rtd, i, component) { |
Kuninori Morimoto | c6cb522 | 2020-04-20 16:07:50 +0900 | [diff] [blame] | 831 | if (!component->driver->compress_ops || |
| 832 | !component->driver->compress_ops->copy) |
| 833 | continue; |
| 834 | |
| 835 | compr->ops->copy = soc_compr_copy; |
| 836 | break; |
| 837 | } |
| 838 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 839 | mutex_init(&compr->lock); |
Richard Fitzgerald | e5241a8 | 2015-11-25 13:00:24 +0000 | [diff] [blame] | 840 | ret = snd_compress_new(rtd->card->snd_card, num, direction, |
| 841 | new_name, compr); |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 842 | if (ret < 0) { |
Kuninori Morimoto | c2233a2 | 2020-03-30 10:47:37 +0900 | [diff] [blame] | 843 | component = asoc_rtd_to_codec(rtd, 0)->component; |
Charles Keepax | 141dfc9 | 2018-01-26 13:08:45 +0000 | [diff] [blame] | 844 | dev_err(component->dev, |
| 845 | "Compress ASoC: can't create compress for codec %s: %d\n", |
| 846 | component->name, ret); |
Amadeusz Sławiński | 09f448a | 2019-06-17 13:36:36 +0200 | [diff] [blame] | 847 | return ret; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 848 | } |
| 849 | |
Charles Keepax | 202c8f7 | 2013-01-24 09:44:30 +0000 | [diff] [blame] | 850 | /* DAPM dai link stream work */ |
Kuninori Morimoto | 83f94a2 | 2020-01-10 11:36:17 +0900 | [diff] [blame] | 851 | rtd->close_delayed_work_func = snd_soc_close_delayed_work; |
Charles Keepax | 202c8f7 | 2013-01-24 09:44:30 +0000 | [diff] [blame] | 852 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 853 | rtd->compr = compr; |
| 854 | compr->private_data = rtd; |
| 855 | |
Pierre-Louis Bossart | 1d5cd52 | 2020-06-12 15:40:50 -0500 | [diff] [blame] | 856 | dev_dbg(rtd->card->dev, "Compress ASoC: %s <-> %s mapping ok\n", |
| 857 | codec_dai->name, cpu_dai->name); |
Charles Keepax | 1f88eb0 | 2013-02-05 10:41:47 +0000 | [diff] [blame] | 858 | |
Amadeusz Sławiński | 09f448a | 2019-06-17 13:36:36 +0200 | [diff] [blame] | 859 | return 0; |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 860 | } |
Jie Yang | 6f0c422 | 2015-10-13 23:41:00 +0800 | [diff] [blame] | 861 | EXPORT_SYMBOL_GPL(snd_soc_new_compress); |