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