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