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