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