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