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