Kuninori Morimoto | 4ff1fef | 2019-07-26 13:49:48 +0900 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | // |
| 3 | // soc-component.c |
| 4 | // |
Kuninori Morimoto | 460b42d | 2020-06-04 17:08:03 +0900 | [diff] [blame] | 5 | // Copyright 2009-2011 Wolfson Microelectronics PLC. |
Kuninori Morimoto | 4ff1fef | 2019-07-26 13:49:48 +0900 | [diff] [blame] | 6 | // Copyright (C) 2019 Renesas Electronics Corp. |
Kuninori Morimoto | 460b42d | 2020-06-04 17:08:03 +0900 | [diff] [blame] | 7 | // |
| 8 | // Mark Brown <broonie@opensource.wolfsonmicro.com> |
Kuninori Morimoto | 4ff1fef | 2019-07-26 13:49:48 +0900 | [diff] [blame] | 9 | // Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> |
| 10 | // |
Kuninori Morimoto | 4a81e8f | 2019-07-26 13:49:54 +0900 | [diff] [blame] | 11 | #include <linux/module.h> |
Kuninori Morimoto | 939a5cf | 2020-09-28 09:01:17 +0900 | [diff] [blame] | 12 | #include <linux/pm_runtime.h> |
Kuninori Morimoto | 4ff1fef | 2019-07-26 13:49:48 +0900 | [diff] [blame] | 13 | #include <sound/soc.h> |
Srinivas Kandagatla | 8ac9e47 | 2021-01-29 10:05:39 +0000 | [diff] [blame] | 14 | #include <linux/bitops.h> |
Kuninori Morimoto | 4ff1fef | 2019-07-26 13:49:48 +0900 | [diff] [blame] | 15 | |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 16 | #define soc_component_ret(dai, ret) _soc_component_ret(dai, __func__, ret) |
| 17 | static inline int _soc_component_ret(struct snd_soc_component *component, |
| 18 | const char *func, int ret) |
| 19 | { |
| 20 | /* Positive/Zero values are not errors */ |
| 21 | if (ret >= 0) |
| 22 | return ret; |
| 23 | |
| 24 | /* Negative values might be errors */ |
| 25 | switch (ret) { |
| 26 | case -EPROBE_DEFER: |
| 27 | case -ENOTSUPP: |
| 28 | break; |
| 29 | default: |
| 30 | dev_err(component->dev, |
| 31 | "ASoC: error at %s on %s: %d\n", |
| 32 | func, component->name, ret); |
| 33 | } |
| 34 | |
| 35 | return ret; |
| 36 | } |
| 37 | |
Srinivas Kandagatla | 1da0b98 | 2021-01-26 17:17:48 +0000 | [diff] [blame] | 38 | static inline int soc_component_field_shift(struct snd_soc_component *component, |
| 39 | unsigned int mask) |
| 40 | { |
| 41 | if (!mask) { |
| 42 | dev_err(component->dev, "ASoC: error field mask is zero for %s\n", |
| 43 | component->name); |
| 44 | return 0; |
| 45 | } |
| 46 | |
Srinivas Kandagatla | 8ac9e47 | 2021-01-29 10:05:39 +0000 | [diff] [blame] | 47 | return (ffs(mask) - 1); |
Srinivas Kandagatla | 1da0b98 | 2021-01-26 17:17:48 +0000 | [diff] [blame] | 48 | } |
| 49 | |
Kuninori Morimoto | 51aff91 | 2020-09-28 09:01:04 +0900 | [diff] [blame] | 50 | /* |
| 51 | * We might want to check substream by using list. |
| 52 | * In such case, we can update these macros. |
| 53 | */ |
| 54 | #define soc_component_mark_push(component, substream, tgt) ((component)->mark_##tgt = substream) |
| 55 | #define soc_component_mark_pop(component, substream, tgt) ((component)->mark_##tgt = NULL) |
| 56 | #define soc_component_mark_match(component, substream, tgt) ((component)->mark_##tgt == substream) |
| 57 | |
Kuninori Morimoto | 257c4da | 2020-06-04 17:07:54 +0900 | [diff] [blame] | 58 | void snd_soc_component_set_aux(struct snd_soc_component *component, |
| 59 | struct snd_soc_aux_dev *aux) |
| 60 | { |
| 61 | component->init = (aux) ? aux->init : NULL; |
| 62 | } |
| 63 | |
| 64 | int snd_soc_component_init(struct snd_soc_component *component) |
| 65 | { |
| 66 | int ret = 0; |
| 67 | |
| 68 | if (component->init) |
| 69 | ret = component->init(component); |
| 70 | |
| 71 | return soc_component_ret(component, ret); |
| 72 | } |
| 73 | |
Kuninori Morimoto | 4ff1fef | 2019-07-26 13:49:48 +0900 | [diff] [blame] | 74 | /** |
| 75 | * snd_soc_component_set_sysclk - configure COMPONENT system or master clock. |
| 76 | * @component: COMPONENT |
| 77 | * @clk_id: DAI specific clock ID |
| 78 | * @source: Source for the clock |
| 79 | * @freq: new clock frequency in Hz |
| 80 | * @dir: new clock direction - input/output. |
| 81 | * |
| 82 | * Configures the CODEC master (MCLK) or system (SYSCLK) clocking. |
| 83 | */ |
| 84 | int snd_soc_component_set_sysclk(struct snd_soc_component *component, |
| 85 | int clk_id, int source, unsigned int freq, |
| 86 | int dir) |
| 87 | { |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 88 | int ret = -ENOTSUPP; |
| 89 | |
Kuninori Morimoto | 4ff1fef | 2019-07-26 13:49:48 +0900 | [diff] [blame] | 90 | if (component->driver->set_sysclk) |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 91 | ret = component->driver->set_sysclk(component, clk_id, source, |
Kuninori Morimoto | 4ff1fef | 2019-07-26 13:49:48 +0900 | [diff] [blame] | 92 | freq, dir); |
| 93 | |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 94 | return soc_component_ret(component, ret); |
Kuninori Morimoto | 4ff1fef | 2019-07-26 13:49:48 +0900 | [diff] [blame] | 95 | } |
| 96 | EXPORT_SYMBOL_GPL(snd_soc_component_set_sysclk); |
| 97 | |
| 98 | /* |
| 99 | * snd_soc_component_set_pll - configure component PLL. |
| 100 | * @component: COMPONENT |
| 101 | * @pll_id: DAI specific PLL ID |
| 102 | * @source: DAI specific source for the PLL |
| 103 | * @freq_in: PLL input clock frequency in Hz |
| 104 | * @freq_out: requested PLL output clock frequency in Hz |
| 105 | * |
| 106 | * Configures and enables PLL to generate output clock based on input clock. |
| 107 | */ |
| 108 | int snd_soc_component_set_pll(struct snd_soc_component *component, int pll_id, |
| 109 | int source, unsigned int freq_in, |
| 110 | unsigned int freq_out) |
| 111 | { |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 112 | int ret = -EINVAL; |
| 113 | |
Kuninori Morimoto | 4ff1fef | 2019-07-26 13:49:48 +0900 | [diff] [blame] | 114 | if (component->driver->set_pll) |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 115 | ret = component->driver->set_pll(component, pll_id, source, |
Kuninori Morimoto | 4ff1fef | 2019-07-26 13:49:48 +0900 | [diff] [blame] | 116 | freq_in, freq_out); |
| 117 | |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 118 | return soc_component_ret(component, ret); |
Kuninori Morimoto | 4ff1fef | 2019-07-26 13:49:48 +0900 | [diff] [blame] | 119 | } |
| 120 | EXPORT_SYMBOL_GPL(snd_soc_component_set_pll); |
| 121 | |
Kuninori Morimoto | 9d415fb | 2019-07-26 13:51:35 +0900 | [diff] [blame] | 122 | void snd_soc_component_seq_notifier(struct snd_soc_component *component, |
| 123 | enum snd_soc_dapm_type type, int subseq) |
| 124 | { |
| 125 | if (component->driver->seq_notifier) |
| 126 | component->driver->seq_notifier(component, type, subseq); |
| 127 | } |
| 128 | |
Kuninori Morimoto | 8e2a990 | 2019-07-26 13:51:39 +0900 | [diff] [blame] | 129 | int snd_soc_component_stream_event(struct snd_soc_component *component, |
| 130 | int event) |
| 131 | { |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 132 | int ret = 0; |
Kuninori Morimoto | 8e2a990 | 2019-07-26 13:51:39 +0900 | [diff] [blame] | 133 | |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 134 | if (component->driver->stream_event) |
| 135 | ret = component->driver->stream_event(component, event); |
| 136 | |
| 137 | return soc_component_ret(component, ret); |
Kuninori Morimoto | 8e2a990 | 2019-07-26 13:51:39 +0900 | [diff] [blame] | 138 | } |
| 139 | |
Kuninori Morimoto | 7951b146 | 2019-07-26 13:51:43 +0900 | [diff] [blame] | 140 | int snd_soc_component_set_bias_level(struct snd_soc_component *component, |
| 141 | enum snd_soc_bias_level level) |
| 142 | { |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 143 | int ret = 0; |
Kuninori Morimoto | 7951b146 | 2019-07-26 13:51:43 +0900 | [diff] [blame] | 144 | |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 145 | if (component->driver->set_bias_level) |
| 146 | ret = component->driver->set_bias_level(component, level); |
| 147 | |
| 148 | return soc_component_ret(component, ret); |
Kuninori Morimoto | 7951b146 | 2019-07-26 13:51:43 +0900 | [diff] [blame] | 149 | } |
| 150 | |
Kuninori Morimoto | 4ca8701 | 2020-06-04 17:06:11 +0900 | [diff] [blame] | 151 | int snd_soc_component_enable_pin(struct snd_soc_component *component, |
| 152 | const char *pin) |
| 153 | { |
Mark Brown | 31428c7 | 2021-07-26 20:41:23 +0100 | [diff] [blame] | 154 | struct snd_soc_dapm_context *dapm = |
| 155 | snd_soc_component_get_dapm(component); |
| 156 | return snd_soc_dapm_enable_pin(dapm, pin); |
Kuninori Morimoto | 4ca8701 | 2020-06-04 17:06:11 +0900 | [diff] [blame] | 157 | } |
Kuninori Morimoto | 4ff1fef | 2019-07-26 13:49:48 +0900 | [diff] [blame] | 158 | EXPORT_SYMBOL_GPL(snd_soc_component_enable_pin); |
| 159 | |
| 160 | int snd_soc_component_enable_pin_unlocked(struct snd_soc_component *component, |
| 161 | const char *pin) |
| 162 | { |
Mark Brown | 31428c7 | 2021-07-26 20:41:23 +0100 | [diff] [blame] | 163 | struct snd_soc_dapm_context *dapm = |
| 164 | snd_soc_component_get_dapm(component); |
| 165 | return snd_soc_dapm_enable_pin_unlocked(dapm, pin); |
Kuninori Morimoto | 4ff1fef | 2019-07-26 13:49:48 +0900 | [diff] [blame] | 166 | } |
| 167 | EXPORT_SYMBOL_GPL(snd_soc_component_enable_pin_unlocked); |
| 168 | |
| 169 | int snd_soc_component_disable_pin(struct snd_soc_component *component, |
| 170 | const char *pin) |
| 171 | { |
Mark Brown | 31428c7 | 2021-07-26 20:41:23 +0100 | [diff] [blame] | 172 | struct snd_soc_dapm_context *dapm = |
| 173 | snd_soc_component_get_dapm(component); |
| 174 | return snd_soc_dapm_disable_pin(dapm, pin); |
Kuninori Morimoto | 4ff1fef | 2019-07-26 13:49:48 +0900 | [diff] [blame] | 175 | } |
| 176 | EXPORT_SYMBOL_GPL(snd_soc_component_disable_pin); |
| 177 | |
| 178 | int snd_soc_component_disable_pin_unlocked(struct snd_soc_component *component, |
| 179 | const char *pin) |
| 180 | { |
Mark Brown | 31428c7 | 2021-07-26 20:41:23 +0100 | [diff] [blame] | 181 | struct snd_soc_dapm_context *dapm = |
| 182 | snd_soc_component_get_dapm(component); |
| 183 | return snd_soc_dapm_disable_pin_unlocked(dapm, pin); |
Kuninori Morimoto | 4ff1fef | 2019-07-26 13:49:48 +0900 | [diff] [blame] | 184 | } |
| 185 | EXPORT_SYMBOL_GPL(snd_soc_component_disable_pin_unlocked); |
| 186 | |
| 187 | int snd_soc_component_nc_pin(struct snd_soc_component *component, |
| 188 | const char *pin) |
| 189 | { |
Mark Brown | 31428c7 | 2021-07-26 20:41:23 +0100 | [diff] [blame] | 190 | struct snd_soc_dapm_context *dapm = |
| 191 | snd_soc_component_get_dapm(component); |
| 192 | return snd_soc_dapm_nc_pin(dapm, pin); |
Kuninori Morimoto | 4ff1fef | 2019-07-26 13:49:48 +0900 | [diff] [blame] | 193 | } |
| 194 | EXPORT_SYMBOL_GPL(snd_soc_component_nc_pin); |
| 195 | |
| 196 | int snd_soc_component_nc_pin_unlocked(struct snd_soc_component *component, |
| 197 | const char *pin) |
| 198 | { |
Mark Brown | 31428c7 | 2021-07-26 20:41:23 +0100 | [diff] [blame] | 199 | struct snd_soc_dapm_context *dapm = |
| 200 | snd_soc_component_get_dapm(component); |
| 201 | return snd_soc_dapm_nc_pin_unlocked(dapm, pin); |
Kuninori Morimoto | 4ff1fef | 2019-07-26 13:49:48 +0900 | [diff] [blame] | 202 | } |
| 203 | EXPORT_SYMBOL_GPL(snd_soc_component_nc_pin_unlocked); |
| 204 | |
| 205 | int snd_soc_component_get_pin_status(struct snd_soc_component *component, |
| 206 | const char *pin) |
| 207 | { |
Mark Brown | 31428c7 | 2021-07-26 20:41:23 +0100 | [diff] [blame] | 208 | struct snd_soc_dapm_context *dapm = |
| 209 | snd_soc_component_get_dapm(component); |
| 210 | return snd_soc_dapm_get_pin_status(dapm, pin); |
Kuninori Morimoto | 4ff1fef | 2019-07-26 13:49:48 +0900 | [diff] [blame] | 211 | } |
| 212 | EXPORT_SYMBOL_GPL(snd_soc_component_get_pin_status); |
| 213 | |
| 214 | int snd_soc_component_force_enable_pin(struct snd_soc_component *component, |
| 215 | const char *pin) |
| 216 | { |
Mark Brown | 31428c7 | 2021-07-26 20:41:23 +0100 | [diff] [blame] | 217 | struct snd_soc_dapm_context *dapm = |
| 218 | snd_soc_component_get_dapm(component); |
| 219 | return snd_soc_dapm_force_enable_pin(dapm, pin); |
Kuninori Morimoto | 4ff1fef | 2019-07-26 13:49:48 +0900 | [diff] [blame] | 220 | } |
| 221 | EXPORT_SYMBOL_GPL(snd_soc_component_force_enable_pin); |
| 222 | |
| 223 | int snd_soc_component_force_enable_pin_unlocked( |
| 224 | struct snd_soc_component *component, |
| 225 | const char *pin) |
| 226 | { |
Mark Brown | 31428c7 | 2021-07-26 20:41:23 +0100 | [diff] [blame] | 227 | struct snd_soc_dapm_context *dapm = |
| 228 | snd_soc_component_get_dapm(component); |
| 229 | return snd_soc_dapm_force_enable_pin_unlocked(dapm, pin); |
Kuninori Morimoto | 4ff1fef | 2019-07-26 13:49:48 +0900 | [diff] [blame] | 230 | } |
| 231 | EXPORT_SYMBOL_GPL(snd_soc_component_force_enable_pin_unlocked); |
| 232 | |
| 233 | /** |
| 234 | * snd_soc_component_set_jack - configure component jack. |
| 235 | * @component: COMPONENTs |
| 236 | * @jack: structure to use for the jack |
| 237 | * @data: can be used if codec driver need extra data for configuring jack |
| 238 | * |
| 239 | * Configures and enables jack detection function. |
| 240 | */ |
| 241 | int snd_soc_component_set_jack(struct snd_soc_component *component, |
| 242 | struct snd_soc_jack *jack, void *data) |
| 243 | { |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 244 | int ret = -ENOTSUPP; |
Kuninori Morimoto | 4ff1fef | 2019-07-26 13:49:48 +0900 | [diff] [blame] | 245 | |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 246 | if (component->driver->set_jack) |
| 247 | ret = component->driver->set_jack(component, jack, data); |
| 248 | |
| 249 | return soc_component_ret(component, ret); |
Kuninori Morimoto | 4ff1fef | 2019-07-26 13:49:48 +0900 | [diff] [blame] | 250 | } |
| 251 | EXPORT_SYMBOL_GPL(snd_soc_component_set_jack); |
Kuninori Morimoto | 4a81e8f | 2019-07-26 13:49:54 +0900 | [diff] [blame] | 252 | |
| 253 | int snd_soc_component_module_get(struct snd_soc_component *component, |
Peter Ujfalusi | a739fdc | 2021-09-01 12:52:54 +0300 | [diff] [blame] | 254 | void *mark, int upon_open) |
Kuninori Morimoto | 4a81e8f | 2019-07-26 13:49:54 +0900 | [diff] [blame] | 255 | { |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 256 | int ret = 0; |
| 257 | |
Kuninori Morimoto | 4a81e8f | 2019-07-26 13:49:54 +0900 | [diff] [blame] | 258 | if (component->driver->module_get_upon_open == !!upon_open && |
| 259 | !try_module_get(component->dev->driver->owner)) |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 260 | ret = -ENODEV; |
Kuninori Morimoto | 4a81e8f | 2019-07-26 13:49:54 +0900 | [diff] [blame] | 261 | |
Peter Ujfalusi | a739fdc | 2021-09-01 12:52:54 +0300 | [diff] [blame] | 262 | /* mark module if succeeded */ |
Kuninori Morimoto | 51aff91 | 2020-09-28 09:01:04 +0900 | [diff] [blame] | 263 | if (ret == 0) |
Peter Ujfalusi | a739fdc | 2021-09-01 12:52:54 +0300 | [diff] [blame] | 264 | soc_component_mark_push(component, mark, module); |
Kuninori Morimoto | 51aff91 | 2020-09-28 09:01:04 +0900 | [diff] [blame] | 265 | |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 266 | return soc_component_ret(component, ret); |
Kuninori Morimoto | 4a81e8f | 2019-07-26 13:49:54 +0900 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | void snd_soc_component_module_put(struct snd_soc_component *component, |
Peter Ujfalusi | a739fdc | 2021-09-01 12:52:54 +0300 | [diff] [blame] | 270 | void *mark, int upon_open, int rollback) |
Kuninori Morimoto | 4a81e8f | 2019-07-26 13:49:54 +0900 | [diff] [blame] | 271 | { |
Peter Ujfalusi | a739fdc | 2021-09-01 12:52:54 +0300 | [diff] [blame] | 272 | if (rollback && !soc_component_mark_match(component, mark, module)) |
Kuninori Morimoto | 51aff91 | 2020-09-28 09:01:04 +0900 | [diff] [blame] | 273 | return; |
| 274 | |
Kuninori Morimoto | 4a81e8f | 2019-07-26 13:49:54 +0900 | [diff] [blame] | 275 | if (component->driver->module_get_upon_open == !!upon_open) |
| 276 | module_put(component->dev->driver->owner); |
Kuninori Morimoto | 51aff91 | 2020-09-28 09:01:04 +0900 | [diff] [blame] | 277 | |
Peter Ujfalusi | a739fdc | 2021-09-01 12:52:54 +0300 | [diff] [blame] | 278 | /* remove the mark from module */ |
| 279 | soc_component_mark_pop(component, mark, module); |
Kuninori Morimoto | 4a81e8f | 2019-07-26 13:49:54 +0900 | [diff] [blame] | 280 | } |
Kuninori Morimoto | ae2f484 | 2019-07-26 13:50:01 +0900 | [diff] [blame] | 281 | |
| 282 | int snd_soc_component_open(struct snd_soc_component *component, |
| 283 | struct snd_pcm_substream *substream) |
| 284 | { |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 285 | int ret = 0; |
| 286 | |
Kuninori Morimoto | e2cb4a1 | 2019-10-02 14:30:48 +0900 | [diff] [blame] | 287 | if (component->driver->open) |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 288 | ret = component->driver->open(component, substream); |
| 289 | |
Kuninori Morimoto | 51aff91 | 2020-09-28 09:01:04 +0900 | [diff] [blame] | 290 | /* mark substream if succeeded */ |
| 291 | if (ret == 0) |
| 292 | soc_component_mark_push(component, substream, open); |
| 293 | |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 294 | return soc_component_ret(component, ret); |
Kuninori Morimoto | ae2f484 | 2019-07-26 13:50:01 +0900 | [diff] [blame] | 295 | } |
Kuninori Morimoto | 3672beb | 2019-07-26 13:50:07 +0900 | [diff] [blame] | 296 | |
| 297 | int snd_soc_component_close(struct snd_soc_component *component, |
Kuninori Morimoto | 51aff91 | 2020-09-28 09:01:04 +0900 | [diff] [blame] | 298 | struct snd_pcm_substream *substream, |
| 299 | int rollback) |
Kuninori Morimoto | 3672beb | 2019-07-26 13:50:07 +0900 | [diff] [blame] | 300 | { |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 301 | int ret = 0; |
| 302 | |
Kuninori Morimoto | 51aff91 | 2020-09-28 09:01:04 +0900 | [diff] [blame] | 303 | if (rollback && !soc_component_mark_match(component, substream, open)) |
| 304 | return 0; |
| 305 | |
Kuninori Morimoto | e2cb4a1 | 2019-10-02 14:30:48 +0900 | [diff] [blame] | 306 | if (component->driver->close) |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 307 | ret = component->driver->close(component, substream); |
| 308 | |
Kuninori Morimoto | 51aff91 | 2020-09-28 09:01:04 +0900 | [diff] [blame] | 309 | /* remove marked substream */ |
| 310 | soc_component_mark_pop(component, substream, open); |
| 311 | |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 312 | return soc_component_ret(component, ret); |
Kuninori Morimoto | 3672beb | 2019-07-26 13:50:07 +0900 | [diff] [blame] | 313 | } |
Kuninori Morimoto | 6d53723 | 2019-07-26 13:50:13 +0900 | [diff] [blame] | 314 | |
Kuninori Morimoto | 66c5157 | 2019-07-26 13:50:34 +0900 | [diff] [blame] | 315 | void snd_soc_component_suspend(struct snd_soc_component *component) |
| 316 | { |
| 317 | if (component->driver->suspend) |
| 318 | component->driver->suspend(component); |
| 319 | component->suspended = 1; |
| 320 | } |
Kuninori Morimoto | 9a840cb | 2019-07-26 13:51:08 +0900 | [diff] [blame] | 321 | |
| 322 | void snd_soc_component_resume(struct snd_soc_component *component) |
| 323 | { |
| 324 | if (component->driver->resume) |
| 325 | component->driver->resume(component); |
| 326 | component->suspended = 0; |
| 327 | } |
Kuninori Morimoto | e40fadb | 2019-07-26 13:51:13 +0900 | [diff] [blame] | 328 | |
| 329 | int snd_soc_component_is_suspended(struct snd_soc_component *component) |
| 330 | { |
| 331 | return component->suspended; |
| 332 | } |
Kuninori Morimoto | 08e837d | 2019-07-26 13:51:17 +0900 | [diff] [blame] | 333 | |
| 334 | int snd_soc_component_probe(struct snd_soc_component *component) |
| 335 | { |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 336 | int ret = 0; |
Kuninori Morimoto | 08e837d | 2019-07-26 13:51:17 +0900 | [diff] [blame] | 337 | |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 338 | if (component->driver->probe) |
| 339 | ret = component->driver->probe(component); |
| 340 | |
| 341 | return soc_component_ret(component, ret); |
Kuninori Morimoto | 08e837d | 2019-07-26 13:51:17 +0900 | [diff] [blame] | 342 | } |
Kuninori Morimoto | 03b34dd | 2019-07-26 13:51:22 +0900 | [diff] [blame] | 343 | |
| 344 | void snd_soc_component_remove(struct snd_soc_component *component) |
| 345 | { |
| 346 | if (component->driver->remove) |
| 347 | component->driver->remove(component); |
| 348 | } |
Kuninori Morimoto | 2c7b170 | 2019-07-26 13:51:26 +0900 | [diff] [blame] | 349 | |
| 350 | int snd_soc_component_of_xlate_dai_id(struct snd_soc_component *component, |
| 351 | struct device_node *ep) |
| 352 | { |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 353 | int ret = -ENOTSUPP; |
Kuninori Morimoto | 2c7b170 | 2019-07-26 13:51:26 +0900 | [diff] [blame] | 354 | |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 355 | if (component->driver->of_xlate_dai_id) |
| 356 | ret = component->driver->of_xlate_dai_id(component, ep); |
| 357 | |
| 358 | return soc_component_ret(component, ret); |
Kuninori Morimoto | 2c7b170 | 2019-07-26 13:51:26 +0900 | [diff] [blame] | 359 | } |
Kuninori Morimoto | a2a3417 | 2019-07-26 13:51:31 +0900 | [diff] [blame] | 360 | |
| 361 | int snd_soc_component_of_xlate_dai_name(struct snd_soc_component *component, |
Krzysztof Kozlowski | 933f98b | 2021-02-21 16:30:24 +0100 | [diff] [blame] | 362 | const struct of_phandle_args *args, |
Kuninori Morimoto | a2a3417 | 2019-07-26 13:51:31 +0900 | [diff] [blame] | 363 | const char **dai_name) |
| 364 | { |
| 365 | if (component->driver->of_xlate_dai_name) |
Jerome Brunet | cc4d8ce | 2020-07-23 16:20:20 +0200 | [diff] [blame] | 366 | return component->driver->of_xlate_dai_name(component, |
| 367 | args, dai_name); |
| 368 | /* |
| 369 | * Don't use soc_component_ret here because we may not want to report |
| 370 | * the error just yet. If a device has more than one component, the |
| 371 | * first may not match and we don't want spam the log with this. |
| 372 | */ |
| 373 | return -ENOTSUPP; |
Kuninori Morimoto | a2a3417 | 2019-07-26 13:51:31 +0900 | [diff] [blame] | 374 | } |
Kuninori Morimoto | 0035e25 | 2019-07-26 13:51:47 +0900 | [diff] [blame] | 375 | |
Kuninori Morimoto | c7d75b5 | 2020-06-04 17:06:22 +0900 | [diff] [blame] | 376 | void snd_soc_component_setup_regmap(struct snd_soc_component *component) |
| 377 | { |
| 378 | int val_bytes = regmap_get_val_bytes(component->regmap); |
| 379 | |
| 380 | /* Errors are legitimate for non-integer byte multiples */ |
| 381 | if (val_bytes > 0) |
| 382 | component->val_bytes = val_bytes; |
| 383 | } |
| 384 | |
| 385 | #ifdef CONFIG_REGMAP |
| 386 | |
| 387 | /** |
| 388 | * snd_soc_component_init_regmap() - Initialize regmap instance for the |
| 389 | * component |
| 390 | * @component: The component for which to initialize the regmap instance |
| 391 | * @regmap: The regmap instance that should be used by the component |
| 392 | * |
| 393 | * This function allows deferred assignment of the regmap instance that is |
| 394 | * associated with the component. Only use this if the regmap instance is not |
| 395 | * yet ready when the component is registered. The function must also be called |
| 396 | * before the first IO attempt of the component. |
| 397 | */ |
| 398 | void snd_soc_component_init_regmap(struct snd_soc_component *component, |
| 399 | struct regmap *regmap) |
| 400 | { |
| 401 | component->regmap = regmap; |
| 402 | snd_soc_component_setup_regmap(component); |
| 403 | } |
| 404 | EXPORT_SYMBOL_GPL(snd_soc_component_init_regmap); |
| 405 | |
| 406 | /** |
| 407 | * snd_soc_component_exit_regmap() - De-initialize regmap instance for the |
| 408 | * component |
| 409 | * @component: The component for which to de-initialize the regmap instance |
| 410 | * |
| 411 | * Calls regmap_exit() on the regmap instance associated to the component and |
| 412 | * removes the regmap instance from the component. |
| 413 | * |
| 414 | * This function should only be used if snd_soc_component_init_regmap() was used |
| 415 | * to initialize the regmap instance. |
| 416 | */ |
| 417 | void snd_soc_component_exit_regmap(struct snd_soc_component *component) |
| 418 | { |
| 419 | regmap_exit(component->regmap); |
| 420 | component->regmap = NULL; |
| 421 | } |
| 422 | EXPORT_SYMBOL_GPL(snd_soc_component_exit_regmap); |
| 423 | |
| 424 | #endif |
| 425 | |
Peter Ujfalusi | cd46f38 | 2021-09-01 12:52:55 +0300 | [diff] [blame] | 426 | int snd_soc_component_compr_open(struct snd_soc_component *component, |
| 427 | struct snd_compr_stream *cstream) |
Kuninori Morimoto | a4e427c | 2020-11-13 13:15:20 +0900 | [diff] [blame] | 428 | { |
Peter Ujfalusi | cd46f38 | 2021-09-01 12:52:55 +0300 | [diff] [blame] | 429 | int ret = 0; |
Kuninori Morimoto | a4e427c | 2020-11-13 13:15:20 +0900 | [diff] [blame] | 430 | |
Peter Ujfalusi | cd46f38 | 2021-09-01 12:52:55 +0300 | [diff] [blame] | 431 | if (component->driver->compress_ops && |
| 432 | component->driver->compress_ops->open) |
| 433 | ret = component->driver->compress_ops->open(component, cstream); |
| 434 | |
| 435 | /* mark substream if succeeded */ |
| 436 | if (ret == 0) |
Kuninori Morimoto | f94ba9a | 2020-11-19 08:50:09 +0900 | [diff] [blame] | 437 | soc_component_mark_push(component, cstream, compr_open); |
Kuninori Morimoto | a4e427c | 2020-11-13 13:15:20 +0900 | [diff] [blame] | 438 | |
Peter Ujfalusi | cd46f38 | 2021-09-01 12:52:55 +0300 | [diff] [blame] | 439 | return soc_component_ret(component, ret); |
Kuninori Morimoto | a4e427c | 2020-11-13 13:15:20 +0900 | [diff] [blame] | 440 | } |
| 441 | EXPORT_SYMBOL_GPL(snd_soc_component_compr_open); |
| 442 | |
Peter Ujfalusi | cd46f38 | 2021-09-01 12:52:55 +0300 | [diff] [blame] | 443 | void snd_soc_component_compr_free(struct snd_soc_component *component, |
| 444 | struct snd_compr_stream *cstream, |
Kuninori Morimoto | f94ba9a | 2020-11-19 08:50:09 +0900 | [diff] [blame] | 445 | int rollback) |
Kuninori Morimoto | dbde5e21 | 2020-11-13 13:15:26 +0900 | [diff] [blame] | 446 | { |
Peter Ujfalusi | cd46f38 | 2021-09-01 12:52:55 +0300 | [diff] [blame] | 447 | if (rollback && !soc_component_mark_match(component, cstream, compr_open)) |
| 448 | return; |
Kuninori Morimoto | dbde5e21 | 2020-11-13 13:15:26 +0900 | [diff] [blame] | 449 | |
Peter Ujfalusi | cd46f38 | 2021-09-01 12:52:55 +0300 | [diff] [blame] | 450 | if (component->driver->compress_ops && |
| 451 | component->driver->compress_ops->free) |
| 452 | component->driver->compress_ops->free(component, cstream); |
Kuninori Morimoto | dbde5e21 | 2020-11-13 13:15:26 +0900 | [diff] [blame] | 453 | |
Peter Ujfalusi | cd46f38 | 2021-09-01 12:52:55 +0300 | [diff] [blame] | 454 | /* remove marked substream */ |
| 455 | soc_component_mark_pop(component, cstream, compr_open); |
Kuninori Morimoto | dbde5e21 | 2020-11-13 13:15:26 +0900 | [diff] [blame] | 456 | } |
| 457 | EXPORT_SYMBOL_GPL(snd_soc_component_compr_free); |
| 458 | |
Kuninori Morimoto | 08aee25 | 2020-11-13 13:15:33 +0900 | [diff] [blame] | 459 | int snd_soc_component_compr_trigger(struct snd_compr_stream *cstream, int cmd) |
| 460 | { |
| 461 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
| 462 | struct snd_soc_component *component; |
| 463 | int i, ret; |
| 464 | |
| 465 | for_each_rtd_components(rtd, i, component) { |
| 466 | if (component->driver->compress_ops && |
| 467 | component->driver->compress_ops->trigger) { |
| 468 | ret = component->driver->compress_ops->trigger( |
| 469 | component, cstream, cmd); |
| 470 | if (ret < 0) |
| 471 | return soc_component_ret(component, ret); |
| 472 | } |
| 473 | } |
| 474 | |
| 475 | return 0; |
| 476 | } |
| 477 | EXPORT_SYMBOL_GPL(snd_soc_component_compr_trigger); |
| 478 | |
Kuninori Morimoto | ff08cf8 | 2020-11-13 13:15:49 +0900 | [diff] [blame] | 479 | int snd_soc_component_compr_set_params(struct snd_compr_stream *cstream, |
| 480 | struct snd_compr_params *params) |
| 481 | { |
| 482 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
| 483 | struct snd_soc_component *component; |
| 484 | int i, ret; |
| 485 | |
| 486 | for_each_rtd_components(rtd, i, component) { |
| 487 | if (component->driver->compress_ops && |
| 488 | component->driver->compress_ops->set_params) { |
| 489 | ret = component->driver->compress_ops->set_params( |
| 490 | component, cstream, params); |
| 491 | if (ret < 0) |
| 492 | return soc_component_ret(component, ret); |
| 493 | } |
| 494 | } |
| 495 | |
| 496 | return 0; |
| 497 | } |
| 498 | EXPORT_SYMBOL_GPL(snd_soc_component_compr_set_params); |
| 499 | |
Kuninori Morimoto | 77c221e | 2020-11-13 13:15:56 +0900 | [diff] [blame] | 500 | int snd_soc_component_compr_get_params(struct snd_compr_stream *cstream, |
| 501 | struct snd_codec *params) |
| 502 | { |
| 503 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
| 504 | struct snd_soc_component *component; |
| 505 | int i, ret; |
| 506 | |
| 507 | for_each_rtd_components(rtd, i, component) { |
| 508 | if (component->driver->compress_ops && |
| 509 | component->driver->compress_ops->get_params) { |
| 510 | ret = component->driver->compress_ops->get_params( |
| 511 | component, cstream, params); |
| 512 | return soc_component_ret(component, ret); |
| 513 | } |
| 514 | } |
| 515 | |
| 516 | return 0; |
| 517 | } |
| 518 | EXPORT_SYMBOL_GPL(snd_soc_component_compr_get_params); |
| 519 | |
Kuninori Morimoto | d67fcb2 | 2020-11-13 13:16:03 +0900 | [diff] [blame] | 520 | int snd_soc_component_compr_get_caps(struct snd_compr_stream *cstream, |
| 521 | struct snd_compr_caps *caps) |
| 522 | { |
| 523 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
| 524 | struct snd_soc_component *component; |
| 525 | int i, ret = 0; |
| 526 | |
| 527 | mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); |
| 528 | |
| 529 | for_each_rtd_components(rtd, i, component) { |
| 530 | if (component->driver->compress_ops && |
| 531 | component->driver->compress_ops->get_caps) { |
| 532 | ret = component->driver->compress_ops->get_caps( |
| 533 | component, cstream, caps); |
| 534 | break; |
| 535 | } |
| 536 | } |
| 537 | |
| 538 | mutex_unlock(&rtd->card->pcm_mutex); |
| 539 | |
| 540 | return soc_component_ret(component, ret); |
| 541 | } |
| 542 | EXPORT_SYMBOL_GPL(snd_soc_component_compr_get_caps); |
| 543 | |
Kuninori Morimoto | 0f6fe09 | 2020-11-13 13:16:11 +0900 | [diff] [blame] | 544 | int snd_soc_component_compr_get_codec_caps(struct snd_compr_stream *cstream, |
| 545 | struct snd_compr_codec_caps *codec) |
| 546 | { |
| 547 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
| 548 | struct snd_soc_component *component; |
| 549 | int i, ret = 0; |
| 550 | |
| 551 | mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); |
| 552 | |
| 553 | for_each_rtd_components(rtd, i, component) { |
| 554 | if (component->driver->compress_ops && |
| 555 | component->driver->compress_ops->get_codec_caps) { |
| 556 | ret = component->driver->compress_ops->get_codec_caps( |
| 557 | component, cstream, codec); |
| 558 | break; |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | mutex_unlock(&rtd->card->pcm_mutex); |
| 563 | |
| 564 | return soc_component_ret(component, ret); |
| 565 | } |
| 566 | EXPORT_SYMBOL_GPL(snd_soc_component_compr_get_codec_caps); |
| 567 | |
Kuninori Morimoto | 0506b88 | 2020-11-13 13:16:17 +0900 | [diff] [blame] | 568 | int snd_soc_component_compr_ack(struct snd_compr_stream *cstream, size_t bytes) |
| 569 | { |
| 570 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
| 571 | struct snd_soc_component *component; |
| 572 | int i, ret; |
| 573 | |
| 574 | for_each_rtd_components(rtd, i, component) { |
| 575 | if (component->driver->compress_ops && |
| 576 | component->driver->compress_ops->ack) { |
| 577 | ret = component->driver->compress_ops->ack( |
| 578 | component, cstream, bytes); |
| 579 | if (ret < 0) |
| 580 | return soc_component_ret(component, ret); |
| 581 | } |
| 582 | } |
| 583 | |
| 584 | return 0; |
| 585 | } |
| 586 | EXPORT_SYMBOL_GPL(snd_soc_component_compr_ack); |
| 587 | |
Kuninori Morimoto | 03ecea6 | 2020-11-13 13:16:24 +0900 | [diff] [blame] | 588 | int snd_soc_component_compr_pointer(struct snd_compr_stream *cstream, |
| 589 | struct snd_compr_tstamp *tstamp) |
| 590 | { |
| 591 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
| 592 | struct snd_soc_component *component; |
| 593 | int i, ret; |
| 594 | |
| 595 | for_each_rtd_components(rtd, i, component) { |
| 596 | if (component->driver->compress_ops && |
| 597 | component->driver->compress_ops->pointer) { |
| 598 | ret = component->driver->compress_ops->pointer( |
| 599 | component, cstream, tstamp); |
| 600 | return soc_component_ret(component, ret); |
| 601 | } |
| 602 | } |
| 603 | |
| 604 | return 0; |
| 605 | } |
| 606 | EXPORT_SYMBOL_GPL(snd_soc_component_compr_pointer); |
| 607 | |
Kuninori Morimoto | b5852e6 | 2020-11-13 13:16:30 +0900 | [diff] [blame] | 608 | int snd_soc_component_compr_copy(struct snd_compr_stream *cstream, |
| 609 | char __user *buf, size_t count) |
| 610 | { |
| 611 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
| 612 | struct snd_soc_component *component; |
| 613 | int i, ret = 0; |
| 614 | |
| 615 | mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); |
| 616 | |
| 617 | for_each_rtd_components(rtd, i, component) { |
| 618 | if (component->driver->compress_ops && |
| 619 | component->driver->compress_ops->copy) { |
| 620 | ret = component->driver->compress_ops->copy( |
| 621 | component, cstream, buf, count); |
| 622 | break; |
| 623 | } |
| 624 | } |
| 625 | |
| 626 | mutex_unlock(&rtd->card->pcm_mutex); |
| 627 | |
| 628 | return soc_component_ret(component, ret); |
| 629 | } |
| 630 | EXPORT_SYMBOL_GPL(snd_soc_component_compr_copy); |
| 631 | |
Kuninori Morimoto | 1b308fb | 2020-11-13 13:16:36 +0900 | [diff] [blame] | 632 | int snd_soc_component_compr_set_metadata(struct snd_compr_stream *cstream, |
| 633 | struct snd_compr_metadata *metadata) |
| 634 | { |
| 635 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
| 636 | struct snd_soc_component *component; |
| 637 | int i, ret; |
| 638 | |
| 639 | for_each_rtd_components(rtd, i, component) { |
| 640 | if (component->driver->compress_ops && |
| 641 | component->driver->compress_ops->set_metadata) { |
| 642 | ret = component->driver->compress_ops->set_metadata( |
| 643 | component, cstream, metadata); |
| 644 | if (ret < 0) |
| 645 | return soc_component_ret(component, ret); |
| 646 | } |
| 647 | } |
| 648 | |
| 649 | return 0; |
| 650 | } |
| 651 | EXPORT_SYMBOL_GPL(snd_soc_component_compr_set_metadata); |
| 652 | |
Kuninori Morimoto | bab78c2 | 2020-11-13 13:16:41 +0900 | [diff] [blame] | 653 | int snd_soc_component_compr_get_metadata(struct snd_compr_stream *cstream, |
| 654 | struct snd_compr_metadata *metadata) |
| 655 | { |
| 656 | struct snd_soc_pcm_runtime *rtd = cstream->private_data; |
| 657 | struct snd_soc_component *component; |
| 658 | int i, ret; |
| 659 | |
| 660 | for_each_rtd_components(rtd, i, component) { |
| 661 | if (component->driver->compress_ops && |
| 662 | component->driver->compress_ops->get_metadata) { |
| 663 | ret = component->driver->compress_ops->get_metadata( |
| 664 | component, cstream, metadata); |
| 665 | return soc_component_ret(component, ret); |
| 666 | } |
| 667 | } |
| 668 | |
| 669 | return 0; |
| 670 | } |
| 671 | EXPORT_SYMBOL_GPL(snd_soc_component_compr_get_metadata); |
| 672 | |
Kuninori Morimoto | e871231 | 2020-06-16 14:19:52 +0900 | [diff] [blame] | 673 | static unsigned int soc_component_read_no_lock( |
| 674 | struct snd_soc_component *component, |
| 675 | unsigned int reg) |
Kuninori Morimoto | 460b42d | 2020-06-04 17:08:03 +0900 | [diff] [blame] | 676 | { |
| 677 | int ret; |
Kuninori Morimoto | cf6e26c | 2020-06-16 14:19:41 +0900 | [diff] [blame] | 678 | unsigned int val = 0; |
Kuninori Morimoto | 460b42d | 2020-06-04 17:08:03 +0900 | [diff] [blame] | 679 | |
| 680 | if (component->regmap) |
Kuninori Morimoto | cf6e26c | 2020-06-16 14:19:41 +0900 | [diff] [blame] | 681 | ret = regmap_read(component->regmap, reg, &val); |
Kuninori Morimoto | 460b42d | 2020-06-04 17:08:03 +0900 | [diff] [blame] | 682 | else if (component->driver->read) { |
Kuninori Morimoto | 460b42d | 2020-06-04 17:08:03 +0900 | [diff] [blame] | 683 | ret = 0; |
Kuninori Morimoto | cf6e26c | 2020-06-16 14:19:41 +0900 | [diff] [blame] | 684 | val = component->driver->read(component, reg); |
Kuninori Morimoto | 460b42d | 2020-06-04 17:08:03 +0900 | [diff] [blame] | 685 | } |
| 686 | else |
| 687 | ret = -EIO; |
| 688 | |
Kuninori Morimoto | 460b42d | 2020-06-04 17:08:03 +0900 | [diff] [blame] | 689 | if (ret < 0) |
Takashi Iwai | efc913c | 2020-08-10 15:46:31 +0200 | [diff] [blame] | 690 | return soc_component_ret(component, ret); |
Kuninori Morimoto | 460b42d | 2020-06-04 17:08:03 +0900 | [diff] [blame] | 691 | |
| 692 | return val; |
| 693 | } |
Kuninori Morimoto | e871231 | 2020-06-16 14:19:52 +0900 | [diff] [blame] | 694 | |
| 695 | /** |
| 696 | * snd_soc_component_read() - Read register value |
| 697 | * @component: Component to read from |
| 698 | * @reg: Register to read |
| 699 | * |
| 700 | * Return: read value |
| 701 | */ |
| 702 | unsigned int snd_soc_component_read(struct snd_soc_component *component, |
| 703 | unsigned int reg) |
| 704 | { |
| 705 | unsigned int val; |
| 706 | |
| 707 | mutex_lock(&component->io_mutex); |
| 708 | val = soc_component_read_no_lock(component, reg); |
| 709 | mutex_unlock(&component->io_mutex); |
| 710 | |
| 711 | return val; |
| 712 | } |
Kuninori Morimoto | cf6e26c | 2020-06-16 14:19:41 +0900 | [diff] [blame] | 713 | EXPORT_SYMBOL_GPL(snd_soc_component_read); |
Kuninori Morimoto | 460b42d | 2020-06-04 17:08:03 +0900 | [diff] [blame] | 714 | |
Kuninori Morimoto | e871231 | 2020-06-16 14:19:52 +0900 | [diff] [blame] | 715 | static int soc_component_write_no_lock( |
| 716 | struct snd_soc_component *component, |
| 717 | unsigned int reg, unsigned int val) |
| 718 | { |
| 719 | int ret = -EIO; |
| 720 | |
| 721 | if (component->regmap) |
| 722 | ret = regmap_write(component->regmap, reg, val); |
| 723 | else if (component->driver->write) |
| 724 | ret = component->driver->write(component, reg, val); |
| 725 | |
| 726 | return soc_component_ret(component, ret); |
| 727 | } |
| 728 | |
Kuninori Morimoto | 460b42d | 2020-06-04 17:08:03 +0900 | [diff] [blame] | 729 | /** |
| 730 | * snd_soc_component_write() - Write register value |
| 731 | * @component: Component to write to |
| 732 | * @reg: Register to write |
| 733 | * @val: Value to write to the register |
| 734 | * |
| 735 | * Return: 0 on success, a negative error code otherwise. |
| 736 | */ |
| 737 | int snd_soc_component_write(struct snd_soc_component *component, |
| 738 | unsigned int reg, unsigned int val) |
| 739 | { |
Kuninori Morimoto | e871231 | 2020-06-16 14:19:52 +0900 | [diff] [blame] | 740 | int ret; |
Kuninori Morimoto | 460b42d | 2020-06-04 17:08:03 +0900 | [diff] [blame] | 741 | |
Kuninori Morimoto | e871231 | 2020-06-16 14:19:52 +0900 | [diff] [blame] | 742 | mutex_lock(&component->io_mutex); |
| 743 | ret = soc_component_write_no_lock(component, reg, val); |
| 744 | mutex_unlock(&component->io_mutex); |
Kuninori Morimoto | 460b42d | 2020-06-04 17:08:03 +0900 | [diff] [blame] | 745 | |
Kuninori Morimoto | e871231 | 2020-06-16 14:19:52 +0900 | [diff] [blame] | 746 | return ret; |
Kuninori Morimoto | 460b42d | 2020-06-04 17:08:03 +0900 | [diff] [blame] | 747 | } |
| 748 | EXPORT_SYMBOL_GPL(snd_soc_component_write); |
| 749 | |
| 750 | static int snd_soc_component_update_bits_legacy( |
| 751 | struct snd_soc_component *component, unsigned int reg, |
| 752 | unsigned int mask, unsigned int val, bool *change) |
| 753 | { |
| 754 | unsigned int old, new; |
Kuninori Morimoto | cf6e26c | 2020-06-16 14:19:41 +0900 | [diff] [blame] | 755 | int ret = 0; |
Kuninori Morimoto | 460b42d | 2020-06-04 17:08:03 +0900 | [diff] [blame] | 756 | |
| 757 | mutex_lock(&component->io_mutex); |
| 758 | |
Kuninori Morimoto | e871231 | 2020-06-16 14:19:52 +0900 | [diff] [blame] | 759 | old = soc_component_read_no_lock(component, reg); |
Kuninori Morimoto | 460b42d | 2020-06-04 17:08:03 +0900 | [diff] [blame] | 760 | |
| 761 | new = (old & ~mask) | (val & mask); |
| 762 | *change = old != new; |
| 763 | if (*change) |
Kuninori Morimoto | e871231 | 2020-06-16 14:19:52 +0900 | [diff] [blame] | 764 | ret = soc_component_write_no_lock(component, reg, new); |
Kuninori Morimoto | cf6e26c | 2020-06-16 14:19:41 +0900 | [diff] [blame] | 765 | |
Kuninori Morimoto | 460b42d | 2020-06-04 17:08:03 +0900 | [diff] [blame] | 766 | mutex_unlock(&component->io_mutex); |
| 767 | |
| 768 | return soc_component_ret(component, ret); |
| 769 | } |
| 770 | |
| 771 | /** |
| 772 | * snd_soc_component_update_bits() - Perform read/modify/write cycle |
| 773 | * @component: Component to update |
| 774 | * @reg: Register to update |
| 775 | * @mask: Mask that specifies which bits to update |
| 776 | * @val: New value for the bits specified by mask |
| 777 | * |
| 778 | * Return: 1 if the operation was successful and the value of the register |
| 779 | * changed, 0 if the operation was successful, but the value did not change. |
| 780 | * Returns a negative error code otherwise. |
| 781 | */ |
| 782 | int snd_soc_component_update_bits(struct snd_soc_component *component, |
| 783 | unsigned int reg, unsigned int mask, unsigned int val) |
| 784 | { |
| 785 | bool change; |
| 786 | int ret; |
| 787 | |
| 788 | if (component->regmap) |
| 789 | ret = regmap_update_bits_check(component->regmap, reg, mask, |
| 790 | val, &change); |
| 791 | else |
| 792 | ret = snd_soc_component_update_bits_legacy(component, reg, |
| 793 | mask, val, &change); |
| 794 | |
| 795 | if (ret < 0) |
| 796 | return soc_component_ret(component, ret); |
| 797 | return change; |
| 798 | } |
| 799 | EXPORT_SYMBOL_GPL(snd_soc_component_update_bits); |
| 800 | |
| 801 | /** |
| 802 | * snd_soc_component_update_bits_async() - Perform asynchronous |
| 803 | * read/modify/write cycle |
| 804 | * @component: Component to update |
| 805 | * @reg: Register to update |
| 806 | * @mask: Mask that specifies which bits to update |
| 807 | * @val: New value for the bits specified by mask |
| 808 | * |
| 809 | * This function is similar to snd_soc_component_update_bits(), but the update |
| 810 | * operation is scheduled asynchronously. This means it may not be completed |
| 811 | * when the function returns. To make sure that all scheduled updates have been |
| 812 | * completed snd_soc_component_async_complete() must be called. |
| 813 | * |
| 814 | * Return: 1 if the operation was successful and the value of the register |
| 815 | * changed, 0 if the operation was successful, but the value did not change. |
| 816 | * Returns a negative error code otherwise. |
| 817 | */ |
| 818 | int snd_soc_component_update_bits_async(struct snd_soc_component *component, |
| 819 | unsigned int reg, unsigned int mask, unsigned int val) |
| 820 | { |
| 821 | bool change; |
| 822 | int ret; |
| 823 | |
| 824 | if (component->regmap) |
| 825 | ret = regmap_update_bits_check_async(component->regmap, reg, |
| 826 | mask, val, &change); |
| 827 | else |
| 828 | ret = snd_soc_component_update_bits_legacy(component, reg, |
| 829 | mask, val, &change); |
| 830 | |
| 831 | if (ret < 0) |
| 832 | return soc_component_ret(component, ret); |
| 833 | return change; |
| 834 | } |
| 835 | EXPORT_SYMBOL_GPL(snd_soc_component_update_bits_async); |
| 836 | |
| 837 | /** |
Srinivas Kandagatla | 1da0b98 | 2021-01-26 17:17:48 +0000 | [diff] [blame] | 838 | * snd_soc_component_read_field() - Read register field value |
| 839 | * @component: Component to read from |
| 840 | * @reg: Register to read |
| 841 | * @mask: mask of the register field |
| 842 | * |
| 843 | * Return: read value of register field. |
| 844 | */ |
| 845 | unsigned int snd_soc_component_read_field(struct snd_soc_component *component, |
| 846 | unsigned int reg, unsigned int mask) |
| 847 | { |
| 848 | unsigned int val; |
| 849 | |
| 850 | val = snd_soc_component_read(component, reg); |
| 851 | |
| 852 | val = (val & mask) >> soc_component_field_shift(component, mask); |
| 853 | |
| 854 | return val; |
| 855 | } |
| 856 | EXPORT_SYMBOL_GPL(snd_soc_component_read_field); |
| 857 | |
| 858 | /** |
| 859 | * snd_soc_component_write_field() - write to register field |
| 860 | * @component: Component to write to |
| 861 | * @reg: Register to write |
| 862 | * @mask: mask of the register field to update |
| 863 | * @val: value of the field to write |
| 864 | * |
| 865 | * Return: 1 for change, otherwise 0. |
| 866 | */ |
| 867 | int snd_soc_component_write_field(struct snd_soc_component *component, |
| 868 | unsigned int reg, unsigned int mask, |
| 869 | unsigned int val) |
| 870 | { |
| 871 | |
| 872 | val = (val << soc_component_field_shift(component, mask)) & mask; |
| 873 | |
| 874 | return snd_soc_component_update_bits(component, reg, mask, val); |
| 875 | } |
| 876 | EXPORT_SYMBOL_GPL(snd_soc_component_write_field); |
| 877 | |
| 878 | /** |
Kuninori Morimoto | 460b42d | 2020-06-04 17:08:03 +0900 | [diff] [blame] | 879 | * snd_soc_component_async_complete() - Ensure asynchronous I/O has completed |
| 880 | * @component: Component for which to wait |
| 881 | * |
| 882 | * This function blocks until all asynchronous I/O which has previously been |
| 883 | * scheduled using snd_soc_component_update_bits_async() has completed. |
| 884 | */ |
| 885 | void snd_soc_component_async_complete(struct snd_soc_component *component) |
| 886 | { |
| 887 | if (component->regmap) |
| 888 | regmap_async_complete(component->regmap); |
| 889 | } |
| 890 | EXPORT_SYMBOL_GPL(snd_soc_component_async_complete); |
| 891 | |
| 892 | /** |
| 893 | * snd_soc_component_test_bits - Test register for change |
| 894 | * @component: component |
| 895 | * @reg: Register to test |
| 896 | * @mask: Mask that specifies which bits to test |
| 897 | * @value: Value to test against |
| 898 | * |
| 899 | * Tests a register with a new value and checks if the new value is |
| 900 | * different from the old value. |
| 901 | * |
| 902 | * Return: 1 for change, otherwise 0. |
| 903 | */ |
| 904 | int snd_soc_component_test_bits(struct snd_soc_component *component, |
| 905 | unsigned int reg, unsigned int mask, unsigned int value) |
| 906 | { |
| 907 | unsigned int old, new; |
Kuninori Morimoto | 460b42d | 2020-06-04 17:08:03 +0900 | [diff] [blame] | 908 | |
Kuninori Morimoto | cf6e26c | 2020-06-16 14:19:41 +0900 | [diff] [blame] | 909 | old = snd_soc_component_read(component, reg); |
Kuninori Morimoto | 460b42d | 2020-06-04 17:08:03 +0900 | [diff] [blame] | 910 | new = (old & ~mask) | value; |
| 911 | return old != new; |
| 912 | } |
| 913 | EXPORT_SYMBOL_GPL(snd_soc_component_test_bits); |
| 914 | |
Kuninori Morimoto | 0035e25 | 2019-07-26 13:51:47 +0900 | [diff] [blame] | 915 | int snd_soc_pcm_component_pointer(struct snd_pcm_substream *substream) |
| 916 | { |
Kuninori Morimoto | 0ceef68 | 2020-07-20 10:17:39 +0900 | [diff] [blame] | 917 | struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); |
Kuninori Morimoto | 0035e25 | 2019-07-26 13:51:47 +0900 | [diff] [blame] | 918 | struct snd_soc_component *component; |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 919 | int i; |
Kuninori Morimoto | 0035e25 | 2019-07-26 13:51:47 +0900 | [diff] [blame] | 920 | |
Kuninori Morimoto | 2b544dd | 2019-10-15 12:59:31 +0900 | [diff] [blame] | 921 | /* FIXME: use 1st pointer */ |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 922 | for_each_rtd_components(rtd, i, component) |
Kuninori Morimoto | e2cb4a1 | 2019-10-02 14:30:48 +0900 | [diff] [blame] | 923 | if (component->driver->pointer) |
| 924 | return component->driver->pointer(component, substream); |
Kuninori Morimoto | 0035e25 | 2019-07-26 13:51:47 +0900 | [diff] [blame] | 925 | |
| 926 | return 0; |
| 927 | } |
Kuninori Morimoto | 96a4790 | 2019-07-26 13:51:51 +0900 | [diff] [blame] | 928 | |
| 929 | int snd_soc_pcm_component_ioctl(struct snd_pcm_substream *substream, |
| 930 | unsigned int cmd, void *arg) |
| 931 | { |
Kuninori Morimoto | 0ceef68 | 2020-07-20 10:17:39 +0900 | [diff] [blame] | 932 | struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); |
Kuninori Morimoto | 96a4790 | 2019-07-26 13:51:51 +0900 | [diff] [blame] | 933 | struct snd_soc_component *component; |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 934 | int i; |
Kuninori Morimoto | 96a4790 | 2019-07-26 13:51:51 +0900 | [diff] [blame] | 935 | |
Kuninori Morimoto | 2b544dd | 2019-10-15 12:59:31 +0900 | [diff] [blame] | 936 | /* FIXME: use 1st ioctl */ |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 937 | for_each_rtd_components(rtd, i, component) |
Kuninori Morimoto | e2cb4a1 | 2019-10-02 14:30:48 +0900 | [diff] [blame] | 938 | if (component->driver->ioctl) |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 939 | return soc_component_ret( |
| 940 | component, |
| 941 | component->driver->ioctl(component, |
| 942 | substream, cmd, arg)); |
Kuninori Morimoto | 96a4790 | 2019-07-26 13:51:51 +0900 | [diff] [blame] | 943 | |
| 944 | return snd_pcm_lib_ioctl(substream, cmd, arg); |
| 945 | } |
Kuninori Morimoto | 82d81f5 | 2019-07-26 13:51:56 +0900 | [diff] [blame] | 946 | |
Takashi Iwai | 1e5ddb6 | 2019-11-21 20:07:09 +0100 | [diff] [blame] | 947 | int snd_soc_pcm_component_sync_stop(struct snd_pcm_substream *substream) |
| 948 | { |
Kuninori Morimoto | 0ceef68 | 2020-07-20 10:17:39 +0900 | [diff] [blame] | 949 | struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); |
Takashi Iwai | 1e5ddb6 | 2019-11-21 20:07:09 +0100 | [diff] [blame] | 950 | struct snd_soc_component *component; |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 951 | int i, ret; |
Takashi Iwai | 1e5ddb6 | 2019-11-21 20:07:09 +0100 | [diff] [blame] | 952 | |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 953 | for_each_rtd_components(rtd, i, component) { |
Kuninori Morimoto | f1861a7 | 2020-02-28 10:48:35 +0900 | [diff] [blame] | 954 | if (component->driver->sync_stop) { |
Takashi Iwai | 1e5ddb6 | 2019-11-21 20:07:09 +0100 | [diff] [blame] | 955 | ret = component->driver->sync_stop(component, |
| 956 | substream); |
| 957 | if (ret < 0) |
Shengjiu Wang | be75db5 | 2020-07-16 13:07:08 +0800 | [diff] [blame] | 958 | return soc_component_ret(component, ret); |
Takashi Iwai | 1e5ddb6 | 2019-11-21 20:07:09 +0100 | [diff] [blame] | 959 | } |
| 960 | } |
| 961 | |
| 962 | return 0; |
| 963 | } |
| 964 | |
Kuninori Morimoto | 82d81f5 | 2019-07-26 13:51:56 +0900 | [diff] [blame] | 965 | int snd_soc_pcm_component_copy_user(struct snd_pcm_substream *substream, |
| 966 | int channel, unsigned long pos, |
| 967 | void __user *buf, unsigned long bytes) |
| 968 | { |
Kuninori Morimoto | 0ceef68 | 2020-07-20 10:17:39 +0900 | [diff] [blame] | 969 | struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); |
Kuninori Morimoto | 82d81f5 | 2019-07-26 13:51:56 +0900 | [diff] [blame] | 970 | struct snd_soc_component *component; |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 971 | int i; |
Kuninori Morimoto | 82d81f5 | 2019-07-26 13:51:56 +0900 | [diff] [blame] | 972 | |
Kuninori Morimoto | 2b544dd | 2019-10-15 12:59:31 +0900 | [diff] [blame] | 973 | /* FIXME. it returns 1st copy now */ |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 974 | for_each_rtd_components(rtd, i, component) |
Kuninori Morimoto | e2cb4a1 | 2019-10-02 14:30:48 +0900 | [diff] [blame] | 975 | if (component->driver->copy_user) |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 976 | return soc_component_ret( |
| 977 | component, |
| 978 | component->driver->copy_user( |
| 979 | component, substream, channel, |
| 980 | pos, buf, bytes)); |
Kuninori Morimoto | 82d81f5 | 2019-07-26 13:51:56 +0900 | [diff] [blame] | 981 | |
| 982 | return -EINVAL; |
| 983 | } |
Kuninori Morimoto | 9c712e4 | 2019-07-26 13:52:00 +0900 | [diff] [blame] | 984 | |
| 985 | struct page *snd_soc_pcm_component_page(struct snd_pcm_substream *substream, |
| 986 | unsigned long offset) |
| 987 | { |
Kuninori Morimoto | 0ceef68 | 2020-07-20 10:17:39 +0900 | [diff] [blame] | 988 | struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); |
Kuninori Morimoto | 9c712e4 | 2019-07-26 13:52:00 +0900 | [diff] [blame] | 989 | struct snd_soc_component *component; |
| 990 | struct page *page; |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 991 | int i; |
Kuninori Morimoto | 9c712e4 | 2019-07-26 13:52:00 +0900 | [diff] [blame] | 992 | |
Kuninori Morimoto | 2b544dd | 2019-10-15 12:59:31 +0900 | [diff] [blame] | 993 | /* FIXME. it returns 1st page now */ |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 994 | for_each_rtd_components(rtd, i, component) { |
Kuninori Morimoto | e2cb4a1 | 2019-10-02 14:30:48 +0900 | [diff] [blame] | 995 | if (component->driver->page) { |
| 996 | page = component->driver->page(component, |
| 997 | substream, offset); |
| 998 | if (page) |
| 999 | return page; |
| 1000 | } |
Kuninori Morimoto | 9c712e4 | 2019-07-26 13:52:00 +0900 | [diff] [blame] | 1001 | } |
| 1002 | |
| 1003 | return NULL; |
| 1004 | } |
Kuninori Morimoto | 205875e | 2019-07-26 13:52:04 +0900 | [diff] [blame] | 1005 | |
| 1006 | int snd_soc_pcm_component_mmap(struct snd_pcm_substream *substream, |
| 1007 | struct vm_area_struct *vma) |
| 1008 | { |
Kuninori Morimoto | 0ceef68 | 2020-07-20 10:17:39 +0900 | [diff] [blame] | 1009 | struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); |
Kuninori Morimoto | 205875e | 2019-07-26 13:52:04 +0900 | [diff] [blame] | 1010 | struct snd_soc_component *component; |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 1011 | int i; |
Kuninori Morimoto | 205875e | 2019-07-26 13:52:04 +0900 | [diff] [blame] | 1012 | |
Kuninori Morimoto | 2b544dd | 2019-10-15 12:59:31 +0900 | [diff] [blame] | 1013 | /* FIXME. it returns 1st mmap now */ |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 1014 | for_each_rtd_components(rtd, i, component) |
Kuninori Morimoto | e2cb4a1 | 2019-10-02 14:30:48 +0900 | [diff] [blame] | 1015 | if (component->driver->mmap) |
Shengjiu Wang | be75db5 | 2020-07-16 13:07:08 +0800 | [diff] [blame] | 1016 | return soc_component_ret( |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 1017 | component, |
| 1018 | component->driver->mmap(component, |
| 1019 | substream, vma)); |
Kuninori Morimoto | 205875e | 2019-07-26 13:52:04 +0900 | [diff] [blame] | 1020 | |
| 1021 | return -EINVAL; |
| 1022 | } |
Kuninori Morimoto | 7484291 | 2019-07-26 13:52:08 +0900 | [diff] [blame] | 1023 | |
Kuninori Morimoto | b2b2afb | 2019-11-18 10:50:32 +0900 | [diff] [blame] | 1024 | int snd_soc_pcm_component_new(struct snd_soc_pcm_runtime *rtd) |
Kuninori Morimoto | 7484291 | 2019-07-26 13:52:08 +0900 | [diff] [blame] | 1025 | { |
Kuninori Morimoto | 7484291 | 2019-07-26 13:52:08 +0900 | [diff] [blame] | 1026 | struct snd_soc_component *component; |
| 1027 | int ret; |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 1028 | int i; |
Kuninori Morimoto | 7484291 | 2019-07-26 13:52:08 +0900 | [diff] [blame] | 1029 | |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 1030 | for_each_rtd_components(rtd, i, component) { |
Kuninori Morimoto | c64bfc9 | 2019-10-02 14:30:59 +0900 | [diff] [blame] | 1031 | if (component->driver->pcm_construct) { |
| 1032 | ret = component->driver->pcm_construct(component, rtd); |
| 1033 | if (ret < 0) |
Shengjiu Wang | be75db5 | 2020-07-16 13:07:08 +0800 | [diff] [blame] | 1034 | return soc_component_ret(component, ret); |
Kuninori Morimoto | c64bfc9 | 2019-10-02 14:30:59 +0900 | [diff] [blame] | 1035 | } |
Kuninori Morimoto | 7484291 | 2019-07-26 13:52:08 +0900 | [diff] [blame] | 1036 | } |
| 1037 | |
| 1038 | return 0; |
| 1039 | } |
Kuninori Morimoto | 79776da | 2019-07-26 13:52:12 +0900 | [diff] [blame] | 1040 | |
Kuninori Morimoto | b2b2afb | 2019-11-18 10:50:32 +0900 | [diff] [blame] | 1041 | void snd_soc_pcm_component_free(struct snd_soc_pcm_runtime *rtd) |
Kuninori Morimoto | 79776da | 2019-07-26 13:52:12 +0900 | [diff] [blame] | 1042 | { |
Kuninori Morimoto | 79776da | 2019-07-26 13:52:12 +0900 | [diff] [blame] | 1043 | struct snd_soc_component *component; |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 1044 | int i; |
Kuninori Morimoto | 79776da | 2019-07-26 13:52:12 +0900 | [diff] [blame] | 1045 | |
Takashi Iwai | 8e3366c | 2020-01-07 08:09:56 +0100 | [diff] [blame] | 1046 | if (!rtd->pcm) |
| 1047 | return; |
| 1048 | |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 1049 | for_each_rtd_components(rtd, i, component) |
Kuninori Morimoto | c64bfc9 | 2019-10-02 14:30:59 +0900 | [diff] [blame] | 1050 | if (component->driver->pcm_destruct) |
Kuninori Morimoto | b2b2afb | 2019-11-18 10:50:32 +0900 | [diff] [blame] | 1051 | component->driver->pcm_destruct(component, rtd->pcm); |
Kuninori Morimoto | 79776da | 2019-07-26 13:52:12 +0900 | [diff] [blame] | 1052 | } |
Kuninori Morimoto | 4f39514 | 2020-06-04 17:06:58 +0900 | [diff] [blame] | 1053 | |
| 1054 | int snd_soc_pcm_component_prepare(struct snd_pcm_substream *substream) |
| 1055 | { |
Kuninori Morimoto | 0ceef68 | 2020-07-20 10:17:39 +0900 | [diff] [blame] | 1056 | struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); |
Kuninori Morimoto | 4f39514 | 2020-06-04 17:06:58 +0900 | [diff] [blame] | 1057 | struct snd_soc_component *component; |
| 1058 | int i, ret; |
| 1059 | |
| 1060 | for_each_rtd_components(rtd, i, component) { |
| 1061 | if (component->driver->prepare) { |
| 1062 | ret = component->driver->prepare(component, substream); |
| 1063 | if (ret < 0) |
| 1064 | return soc_component_ret(component, ret); |
| 1065 | } |
| 1066 | } |
| 1067 | |
| 1068 | return 0; |
| 1069 | } |
Kuninori Morimoto | e1bafa8 | 2020-06-04 17:07:11 +0900 | [diff] [blame] | 1070 | |
| 1071 | int snd_soc_pcm_component_hw_params(struct snd_pcm_substream *substream, |
Kuninori Morimoto | 3a36a64 | 2020-09-29 13:31:41 +0900 | [diff] [blame] | 1072 | struct snd_pcm_hw_params *params) |
Kuninori Morimoto | e1bafa8 | 2020-06-04 17:07:11 +0900 | [diff] [blame] | 1073 | { |
Kuninori Morimoto | 0ceef68 | 2020-07-20 10:17:39 +0900 | [diff] [blame] | 1074 | struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); |
Kuninori Morimoto | e1bafa8 | 2020-06-04 17:07:11 +0900 | [diff] [blame] | 1075 | struct snd_soc_component *component; |
| 1076 | int i, ret; |
| 1077 | |
| 1078 | for_each_rtd_components(rtd, i, component) { |
| 1079 | if (component->driver->hw_params) { |
| 1080 | ret = component->driver->hw_params(component, |
| 1081 | substream, params); |
Kuninori Morimoto | 3a36a64 | 2020-09-29 13:31:41 +0900 | [diff] [blame] | 1082 | if (ret < 0) |
Kuninori Morimoto | e1bafa8 | 2020-06-04 17:07:11 +0900 | [diff] [blame] | 1083 | return soc_component_ret(component, ret); |
Kuninori Morimoto | e1bafa8 | 2020-06-04 17:07:11 +0900 | [diff] [blame] | 1084 | } |
Kuninori Morimoto | 3a36a64 | 2020-09-29 13:31:41 +0900 | [diff] [blame] | 1085 | /* mark substream if succeeded */ |
| 1086 | soc_component_mark_push(component, substream, hw_params); |
Kuninori Morimoto | e1bafa8 | 2020-06-04 17:07:11 +0900 | [diff] [blame] | 1087 | } |
| 1088 | |
Kuninori Morimoto | e1bafa8 | 2020-06-04 17:07:11 +0900 | [diff] [blame] | 1089 | return 0; |
| 1090 | } |
Kuninori Morimoto | 0475111 | 2020-06-04 17:07:24 +0900 | [diff] [blame] | 1091 | |
| 1092 | void snd_soc_pcm_component_hw_free(struct snd_pcm_substream *substream, |
Kuninori Morimoto | 3a36a64 | 2020-09-29 13:31:41 +0900 | [diff] [blame] | 1093 | int rollback) |
Kuninori Morimoto | 0475111 | 2020-06-04 17:07:24 +0900 | [diff] [blame] | 1094 | { |
Kuninori Morimoto | 0ceef68 | 2020-07-20 10:17:39 +0900 | [diff] [blame] | 1095 | struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); |
Kuninori Morimoto | 0475111 | 2020-06-04 17:07:24 +0900 | [diff] [blame] | 1096 | struct snd_soc_component *component; |
| 1097 | int i, ret; |
| 1098 | |
| 1099 | for_each_rtd_components(rtd, i, component) { |
Kuninori Morimoto | 3a36a64 | 2020-09-29 13:31:41 +0900 | [diff] [blame] | 1100 | if (rollback && !soc_component_mark_match(component, substream, hw_params)) |
| 1101 | continue; |
Kuninori Morimoto | 0475111 | 2020-06-04 17:07:24 +0900 | [diff] [blame] | 1102 | |
| 1103 | if (component->driver->hw_free) { |
| 1104 | ret = component->driver->hw_free(component, substream); |
| 1105 | if (ret < 0) |
| 1106 | soc_component_ret(component, ret); |
| 1107 | } |
Kuninori Morimoto | 3a36a64 | 2020-09-29 13:31:41 +0900 | [diff] [blame] | 1108 | |
| 1109 | /* remove marked substream */ |
| 1110 | soc_component_mark_pop(component, substream, hw_params); |
Kuninori Morimoto | 0475111 | 2020-06-04 17:07:24 +0900 | [diff] [blame] | 1111 | } |
| 1112 | } |
Kuninori Morimoto | 32fd120 | 2020-06-04 17:07:40 +0900 | [diff] [blame] | 1113 | |
Kuninori Morimoto | 6374f49 | 2020-12-01 08:51:33 +0900 | [diff] [blame] | 1114 | static int soc_component_trigger(struct snd_soc_component *component, |
| 1115 | struct snd_pcm_substream *substream, |
| 1116 | int cmd) |
| 1117 | { |
| 1118 | int ret = 0; |
| 1119 | |
| 1120 | if (component->driver->trigger) |
| 1121 | ret = component->driver->trigger(component, substream, cmd); |
| 1122 | |
| 1123 | return soc_component_ret(component, ret); |
| 1124 | } |
| 1125 | |
Kuninori Morimoto | 32fd120 | 2020-06-04 17:07:40 +0900 | [diff] [blame] | 1126 | int snd_soc_pcm_component_trigger(struct snd_pcm_substream *substream, |
Kuninori Morimoto | 6374f49 | 2020-12-01 08:51:33 +0900 | [diff] [blame] | 1127 | int cmd, int rollback) |
Kuninori Morimoto | 32fd120 | 2020-06-04 17:07:40 +0900 | [diff] [blame] | 1128 | { |
Kuninori Morimoto | 0ceef68 | 2020-07-20 10:17:39 +0900 | [diff] [blame] | 1129 | struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); |
Kuninori Morimoto | 32fd120 | 2020-06-04 17:07:40 +0900 | [diff] [blame] | 1130 | struct snd_soc_component *component; |
Kuninori Morimoto | 6374f49 | 2020-12-01 08:51:33 +0900 | [diff] [blame] | 1131 | int i, r, ret = 0; |
Kuninori Morimoto | 32fd120 | 2020-06-04 17:07:40 +0900 | [diff] [blame] | 1132 | |
Kuninori Morimoto | 6374f49 | 2020-12-01 08:51:33 +0900 | [diff] [blame] | 1133 | switch (cmd) { |
| 1134 | case SNDRV_PCM_TRIGGER_START: |
| 1135 | case SNDRV_PCM_TRIGGER_RESUME: |
| 1136 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
| 1137 | for_each_rtd_components(rtd, i, component) { |
| 1138 | ret = soc_component_trigger(component, substream, cmd); |
Kuninori Morimoto | 32fd120 | 2020-06-04 17:07:40 +0900 | [diff] [blame] | 1139 | if (ret < 0) |
Kuninori Morimoto | 6374f49 | 2020-12-01 08:51:33 +0900 | [diff] [blame] | 1140 | break; |
| 1141 | soc_component_mark_push(component, substream, trigger); |
| 1142 | } |
| 1143 | break; |
| 1144 | case SNDRV_PCM_TRIGGER_STOP: |
| 1145 | case SNDRV_PCM_TRIGGER_SUSPEND: |
| 1146 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
| 1147 | for_each_rtd_components(rtd, i, component) { |
| 1148 | if (rollback && !soc_component_mark_match(component, substream, trigger)) |
| 1149 | continue; |
| 1150 | |
| 1151 | r = soc_component_trigger(component, substream, cmd); |
| 1152 | if (r < 0) |
| 1153 | ret = r; /* use last ret */ |
| 1154 | soc_component_mark_pop(component, substream, trigger); |
Kuninori Morimoto | 32fd120 | 2020-06-04 17:07:40 +0900 | [diff] [blame] | 1155 | } |
| 1156 | } |
| 1157 | |
Kuninori Morimoto | 6374f49 | 2020-12-01 08:51:33 +0900 | [diff] [blame] | 1158 | return ret; |
Kuninori Morimoto | 32fd120 | 2020-06-04 17:07:40 +0900 | [diff] [blame] | 1159 | } |
Kuninori Morimoto | 939a5cf | 2020-09-28 09:01:17 +0900 | [diff] [blame] | 1160 | |
| 1161 | int snd_soc_pcm_component_pm_runtime_get(struct snd_soc_pcm_runtime *rtd, |
| 1162 | void *stream) |
| 1163 | { |
| 1164 | struct snd_soc_component *component; |
Kuninori Morimoto | 500b39d | 2021-08-16 13:56:19 +0900 | [diff] [blame] | 1165 | int i; |
Kuninori Morimoto | 939a5cf | 2020-09-28 09:01:17 +0900 | [diff] [blame] | 1166 | |
| 1167 | for_each_rtd_components(rtd, i, component) { |
Kuninori Morimoto | 500b39d | 2021-08-16 13:56:19 +0900 | [diff] [blame] | 1168 | int ret = pm_runtime_get_sync(component->dev); |
Kuninori Morimoto | 939a5cf | 2020-09-28 09:01:17 +0900 | [diff] [blame] | 1169 | if (ret < 0 && ret != -EACCES) { |
| 1170 | pm_runtime_put_noidle(component->dev); |
| 1171 | return soc_component_ret(component, ret); |
| 1172 | } |
| 1173 | /* mark stream if succeeded */ |
| 1174 | soc_component_mark_push(component, stream, pm); |
| 1175 | } |
| 1176 | |
| 1177 | return 0; |
| 1178 | } |
| 1179 | |
| 1180 | void snd_soc_pcm_component_pm_runtime_put(struct snd_soc_pcm_runtime *rtd, |
| 1181 | void *stream, int rollback) |
| 1182 | { |
| 1183 | struct snd_soc_component *component; |
| 1184 | int i; |
| 1185 | |
| 1186 | for_each_rtd_components(rtd, i, component) { |
| 1187 | if (rollback && !soc_component_mark_match(component, stream, pm)) |
| 1188 | continue; |
| 1189 | |
| 1190 | pm_runtime_mark_last_busy(component->dev); |
| 1191 | pm_runtime_put_autosuspend(component->dev); |
| 1192 | |
| 1193 | /* remove marked stream */ |
| 1194 | soc_component_mark_pop(component, stream, pm); |
| 1195 | } |
| 1196 | } |
Shengjiu Wang | 8bdfc04 | 2021-03-12 10:38:40 +0800 | [diff] [blame] | 1197 | |
| 1198 | int snd_soc_pcm_component_ack(struct snd_pcm_substream *substream) |
| 1199 | { |
| 1200 | struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); |
| 1201 | struct snd_soc_component *component; |
| 1202 | int i; |
| 1203 | |
| 1204 | /* FIXME: use 1st pointer */ |
| 1205 | for_each_rtd_components(rtd, i, component) |
| 1206 | if (component->driver->ack) |
| 1207 | return component->driver->ack(component, substream); |
| 1208 | |
| 1209 | return 0; |
| 1210 | } |