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