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 | e871231 | 2020-06-16 14:19:52 +0900 | [diff] [blame] | 406 | static unsigned int soc_component_read_no_lock( |
| 407 | struct snd_soc_component *component, |
| 408 | unsigned int reg) |
Kuninori Morimoto | 460b42d | 2020-06-04 17:08:03 +0900 | [diff] [blame] | 409 | { |
| 410 | int ret; |
Kuninori Morimoto | cf6e26c | 2020-06-16 14:19:41 +0900 | [diff] [blame] | 411 | unsigned int val = 0; |
Kuninori Morimoto | 460b42d | 2020-06-04 17:08:03 +0900 | [diff] [blame] | 412 | |
| 413 | if (component->regmap) |
Kuninori Morimoto | cf6e26c | 2020-06-16 14:19:41 +0900 | [diff] [blame] | 414 | ret = regmap_read(component->regmap, reg, &val); |
Kuninori Morimoto | 460b42d | 2020-06-04 17:08:03 +0900 | [diff] [blame] | 415 | else if (component->driver->read) { |
Kuninori Morimoto | 460b42d | 2020-06-04 17:08:03 +0900 | [diff] [blame] | 416 | ret = 0; |
Kuninori Morimoto | cf6e26c | 2020-06-16 14:19:41 +0900 | [diff] [blame] | 417 | val = component->driver->read(component, reg); |
Kuninori Morimoto | 460b42d | 2020-06-04 17:08:03 +0900 | [diff] [blame] | 418 | } |
| 419 | else |
| 420 | ret = -EIO; |
| 421 | |
Kuninori Morimoto | 460b42d | 2020-06-04 17:08:03 +0900 | [diff] [blame] | 422 | if (ret < 0) |
Kuninori Morimoto | cf6e26c | 2020-06-16 14:19:41 +0900 | [diff] [blame] | 423 | soc_component_ret(component, ret); |
Kuninori Morimoto | 460b42d | 2020-06-04 17:08:03 +0900 | [diff] [blame] | 424 | |
| 425 | return val; |
| 426 | } |
Kuninori Morimoto | e871231 | 2020-06-16 14:19:52 +0900 | [diff] [blame] | 427 | |
| 428 | /** |
| 429 | * snd_soc_component_read() - Read register value |
| 430 | * @component: Component to read from |
| 431 | * @reg: Register to read |
| 432 | * |
| 433 | * Return: read value |
| 434 | */ |
| 435 | unsigned int snd_soc_component_read(struct snd_soc_component *component, |
| 436 | unsigned int reg) |
| 437 | { |
| 438 | unsigned int val; |
| 439 | |
| 440 | mutex_lock(&component->io_mutex); |
| 441 | val = soc_component_read_no_lock(component, reg); |
| 442 | mutex_unlock(&component->io_mutex); |
| 443 | |
| 444 | return val; |
| 445 | } |
Kuninori Morimoto | cf6e26c | 2020-06-16 14:19:41 +0900 | [diff] [blame] | 446 | EXPORT_SYMBOL_GPL(snd_soc_component_read); |
Kuninori Morimoto | 460b42d | 2020-06-04 17:08:03 +0900 | [diff] [blame] | 447 | |
Kuninori Morimoto | e871231 | 2020-06-16 14:19:52 +0900 | [diff] [blame] | 448 | static int soc_component_write_no_lock( |
| 449 | struct snd_soc_component *component, |
| 450 | unsigned int reg, unsigned int val) |
| 451 | { |
| 452 | int ret = -EIO; |
| 453 | |
| 454 | if (component->regmap) |
| 455 | ret = regmap_write(component->regmap, reg, val); |
| 456 | else if (component->driver->write) |
| 457 | ret = component->driver->write(component, reg, val); |
| 458 | |
| 459 | return soc_component_ret(component, ret); |
| 460 | } |
| 461 | |
Kuninori Morimoto | 460b42d | 2020-06-04 17:08:03 +0900 | [diff] [blame] | 462 | /** |
| 463 | * snd_soc_component_write() - Write register value |
| 464 | * @component: Component to write to |
| 465 | * @reg: Register to write |
| 466 | * @val: Value to write to the register |
| 467 | * |
| 468 | * Return: 0 on success, a negative error code otherwise. |
| 469 | */ |
| 470 | int snd_soc_component_write(struct snd_soc_component *component, |
| 471 | unsigned int reg, unsigned int val) |
| 472 | { |
Kuninori Morimoto | e871231 | 2020-06-16 14:19:52 +0900 | [diff] [blame] | 473 | int ret; |
Kuninori Morimoto | 460b42d | 2020-06-04 17:08:03 +0900 | [diff] [blame] | 474 | |
Kuninori Morimoto | e871231 | 2020-06-16 14:19:52 +0900 | [diff] [blame] | 475 | mutex_lock(&component->io_mutex); |
| 476 | ret = soc_component_write_no_lock(component, reg, val); |
| 477 | mutex_unlock(&component->io_mutex); |
Kuninori Morimoto | 460b42d | 2020-06-04 17:08:03 +0900 | [diff] [blame] | 478 | |
Kuninori Morimoto | e871231 | 2020-06-16 14:19:52 +0900 | [diff] [blame] | 479 | return ret; |
Kuninori Morimoto | 460b42d | 2020-06-04 17:08:03 +0900 | [diff] [blame] | 480 | } |
| 481 | EXPORT_SYMBOL_GPL(snd_soc_component_write); |
| 482 | |
| 483 | static int snd_soc_component_update_bits_legacy( |
| 484 | struct snd_soc_component *component, unsigned int reg, |
| 485 | unsigned int mask, unsigned int val, bool *change) |
| 486 | { |
| 487 | unsigned int old, new; |
Kuninori Morimoto | cf6e26c | 2020-06-16 14:19:41 +0900 | [diff] [blame] | 488 | int ret = 0; |
Kuninori Morimoto | 460b42d | 2020-06-04 17:08:03 +0900 | [diff] [blame] | 489 | |
| 490 | mutex_lock(&component->io_mutex); |
| 491 | |
Kuninori Morimoto | e871231 | 2020-06-16 14:19:52 +0900 | [diff] [blame] | 492 | old = soc_component_read_no_lock(component, reg); |
Kuninori Morimoto | 460b42d | 2020-06-04 17:08:03 +0900 | [diff] [blame] | 493 | |
| 494 | new = (old & ~mask) | (val & mask); |
| 495 | *change = old != new; |
| 496 | if (*change) |
Kuninori Morimoto | e871231 | 2020-06-16 14:19:52 +0900 | [diff] [blame] | 497 | ret = soc_component_write_no_lock(component, reg, new); |
Kuninori Morimoto | cf6e26c | 2020-06-16 14:19:41 +0900 | [diff] [blame] | 498 | |
Kuninori Morimoto | 460b42d | 2020-06-04 17:08:03 +0900 | [diff] [blame] | 499 | mutex_unlock(&component->io_mutex); |
| 500 | |
| 501 | return soc_component_ret(component, ret); |
| 502 | } |
| 503 | |
| 504 | /** |
| 505 | * snd_soc_component_update_bits() - Perform read/modify/write cycle |
| 506 | * @component: Component to update |
| 507 | * @reg: Register to update |
| 508 | * @mask: Mask that specifies which bits to update |
| 509 | * @val: New value for the bits specified by mask |
| 510 | * |
| 511 | * Return: 1 if the operation was successful and the value of the register |
| 512 | * changed, 0 if the operation was successful, but the value did not change. |
| 513 | * Returns a negative error code otherwise. |
| 514 | */ |
| 515 | int snd_soc_component_update_bits(struct snd_soc_component *component, |
| 516 | unsigned int reg, unsigned int mask, unsigned int val) |
| 517 | { |
| 518 | bool change; |
| 519 | int ret; |
| 520 | |
| 521 | if (component->regmap) |
| 522 | ret = regmap_update_bits_check(component->regmap, reg, mask, |
| 523 | val, &change); |
| 524 | else |
| 525 | ret = snd_soc_component_update_bits_legacy(component, reg, |
| 526 | mask, val, &change); |
| 527 | |
| 528 | if (ret < 0) |
| 529 | return soc_component_ret(component, ret); |
| 530 | return change; |
| 531 | } |
| 532 | EXPORT_SYMBOL_GPL(snd_soc_component_update_bits); |
| 533 | |
| 534 | /** |
| 535 | * snd_soc_component_update_bits_async() - Perform asynchronous |
| 536 | * read/modify/write cycle |
| 537 | * @component: Component to update |
| 538 | * @reg: Register to update |
| 539 | * @mask: Mask that specifies which bits to update |
| 540 | * @val: New value for the bits specified by mask |
| 541 | * |
| 542 | * This function is similar to snd_soc_component_update_bits(), but the update |
| 543 | * operation is scheduled asynchronously. This means it may not be completed |
| 544 | * when the function returns. To make sure that all scheduled updates have been |
| 545 | * completed snd_soc_component_async_complete() must be called. |
| 546 | * |
| 547 | * Return: 1 if the operation was successful and the value of the register |
| 548 | * changed, 0 if the operation was successful, but the value did not change. |
| 549 | * Returns a negative error code otherwise. |
| 550 | */ |
| 551 | int snd_soc_component_update_bits_async(struct snd_soc_component *component, |
| 552 | unsigned int reg, unsigned int mask, unsigned int val) |
| 553 | { |
| 554 | bool change; |
| 555 | int ret; |
| 556 | |
| 557 | if (component->regmap) |
| 558 | ret = regmap_update_bits_check_async(component->regmap, reg, |
| 559 | mask, val, &change); |
| 560 | else |
| 561 | ret = snd_soc_component_update_bits_legacy(component, reg, |
| 562 | mask, val, &change); |
| 563 | |
| 564 | if (ret < 0) |
| 565 | return soc_component_ret(component, ret); |
| 566 | return change; |
| 567 | } |
| 568 | EXPORT_SYMBOL_GPL(snd_soc_component_update_bits_async); |
| 569 | |
| 570 | /** |
| 571 | * snd_soc_component_async_complete() - Ensure asynchronous I/O has completed |
| 572 | * @component: Component for which to wait |
| 573 | * |
| 574 | * This function blocks until all asynchronous I/O which has previously been |
| 575 | * scheduled using snd_soc_component_update_bits_async() has completed. |
| 576 | */ |
| 577 | void snd_soc_component_async_complete(struct snd_soc_component *component) |
| 578 | { |
| 579 | if (component->regmap) |
| 580 | regmap_async_complete(component->regmap); |
| 581 | } |
| 582 | EXPORT_SYMBOL_GPL(snd_soc_component_async_complete); |
| 583 | |
| 584 | /** |
| 585 | * snd_soc_component_test_bits - Test register for change |
| 586 | * @component: component |
| 587 | * @reg: Register to test |
| 588 | * @mask: Mask that specifies which bits to test |
| 589 | * @value: Value to test against |
| 590 | * |
| 591 | * Tests a register with a new value and checks if the new value is |
| 592 | * different from the old value. |
| 593 | * |
| 594 | * Return: 1 for change, otherwise 0. |
| 595 | */ |
| 596 | int snd_soc_component_test_bits(struct snd_soc_component *component, |
| 597 | unsigned int reg, unsigned int mask, unsigned int value) |
| 598 | { |
| 599 | unsigned int old, new; |
Kuninori Morimoto | 460b42d | 2020-06-04 17:08:03 +0900 | [diff] [blame] | 600 | |
Kuninori Morimoto | cf6e26c | 2020-06-16 14:19:41 +0900 | [diff] [blame] | 601 | old = snd_soc_component_read(component, reg); |
Kuninori Morimoto | 460b42d | 2020-06-04 17:08:03 +0900 | [diff] [blame] | 602 | new = (old & ~mask) | value; |
| 603 | return old != new; |
| 604 | } |
| 605 | EXPORT_SYMBOL_GPL(snd_soc_component_test_bits); |
| 606 | |
Kuninori Morimoto | 0035e25 | 2019-07-26 13:51:47 +0900 | [diff] [blame] | 607 | int snd_soc_pcm_component_pointer(struct snd_pcm_substream *substream) |
| 608 | { |
Kuninori Morimoto | 0ceef68 | 2020-07-20 10:17:39 +0900 | [diff] [blame^] | 609 | struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); |
Kuninori Morimoto | 0035e25 | 2019-07-26 13:51:47 +0900 | [diff] [blame] | 610 | struct snd_soc_component *component; |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 611 | int i; |
Kuninori Morimoto | 0035e25 | 2019-07-26 13:51:47 +0900 | [diff] [blame] | 612 | |
Kuninori Morimoto | 2b544dd | 2019-10-15 12:59:31 +0900 | [diff] [blame] | 613 | /* FIXME: use 1st pointer */ |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 614 | for_each_rtd_components(rtd, i, component) |
Kuninori Morimoto | e2cb4a1 | 2019-10-02 14:30:48 +0900 | [diff] [blame] | 615 | if (component->driver->pointer) |
| 616 | return component->driver->pointer(component, substream); |
Kuninori Morimoto | 0035e25 | 2019-07-26 13:51:47 +0900 | [diff] [blame] | 617 | |
| 618 | return 0; |
| 619 | } |
Kuninori Morimoto | 96a4790 | 2019-07-26 13:51:51 +0900 | [diff] [blame] | 620 | |
| 621 | int snd_soc_pcm_component_ioctl(struct snd_pcm_substream *substream, |
| 622 | unsigned int cmd, void *arg) |
| 623 | { |
Kuninori Morimoto | 0ceef68 | 2020-07-20 10:17:39 +0900 | [diff] [blame^] | 624 | struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); |
Kuninori Morimoto | 96a4790 | 2019-07-26 13:51:51 +0900 | [diff] [blame] | 625 | struct snd_soc_component *component; |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 626 | int i; |
Kuninori Morimoto | 96a4790 | 2019-07-26 13:51:51 +0900 | [diff] [blame] | 627 | |
Kuninori Morimoto | 2b544dd | 2019-10-15 12:59:31 +0900 | [diff] [blame] | 628 | /* FIXME: use 1st ioctl */ |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 629 | for_each_rtd_components(rtd, i, component) |
Kuninori Morimoto | e2cb4a1 | 2019-10-02 14:30:48 +0900 | [diff] [blame] | 630 | if (component->driver->ioctl) |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 631 | return soc_component_ret( |
| 632 | component, |
| 633 | component->driver->ioctl(component, |
| 634 | substream, cmd, arg)); |
Kuninori Morimoto | 96a4790 | 2019-07-26 13:51:51 +0900 | [diff] [blame] | 635 | |
| 636 | return snd_pcm_lib_ioctl(substream, cmd, arg); |
| 637 | } |
Kuninori Morimoto | 82d81f5 | 2019-07-26 13:51:56 +0900 | [diff] [blame] | 638 | |
Takashi Iwai | 1e5ddb6 | 2019-11-21 20:07:09 +0100 | [diff] [blame] | 639 | int snd_soc_pcm_component_sync_stop(struct snd_pcm_substream *substream) |
| 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); |
Takashi Iwai | 1e5ddb6 | 2019-11-21 20:07:09 +0100 | [diff] [blame] | 642 | struct snd_soc_component *component; |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 643 | int i, ret; |
Takashi Iwai | 1e5ddb6 | 2019-11-21 20:07:09 +0100 | [diff] [blame] | 644 | |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 645 | for_each_rtd_components(rtd, i, component) { |
Kuninori Morimoto | f1861a7 | 2020-02-28 10:48:35 +0900 | [diff] [blame] | 646 | if (component->driver->sync_stop) { |
Takashi Iwai | 1e5ddb6 | 2019-11-21 20:07:09 +0100 | [diff] [blame] | 647 | ret = component->driver->sync_stop(component, |
| 648 | substream); |
| 649 | if (ret < 0) |
Shengjiu Wang | be75db5 | 2020-07-16 13:07:08 +0800 | [diff] [blame] | 650 | return soc_component_ret(component, ret); |
Takashi Iwai | 1e5ddb6 | 2019-11-21 20:07:09 +0100 | [diff] [blame] | 651 | } |
| 652 | } |
| 653 | |
| 654 | return 0; |
| 655 | } |
| 656 | |
Kuninori Morimoto | 82d81f5 | 2019-07-26 13:51:56 +0900 | [diff] [blame] | 657 | int snd_soc_pcm_component_copy_user(struct snd_pcm_substream *substream, |
| 658 | int channel, unsigned long pos, |
| 659 | void __user *buf, unsigned long bytes) |
| 660 | { |
Kuninori Morimoto | 0ceef68 | 2020-07-20 10:17:39 +0900 | [diff] [blame^] | 661 | struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); |
Kuninori Morimoto | 82d81f5 | 2019-07-26 13:51:56 +0900 | [diff] [blame] | 662 | struct snd_soc_component *component; |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 663 | int i; |
Kuninori Morimoto | 82d81f5 | 2019-07-26 13:51:56 +0900 | [diff] [blame] | 664 | |
Kuninori Morimoto | 2b544dd | 2019-10-15 12:59:31 +0900 | [diff] [blame] | 665 | /* FIXME. it returns 1st copy now */ |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 666 | for_each_rtd_components(rtd, i, component) |
Kuninori Morimoto | e2cb4a1 | 2019-10-02 14:30:48 +0900 | [diff] [blame] | 667 | if (component->driver->copy_user) |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 668 | return soc_component_ret( |
| 669 | component, |
| 670 | component->driver->copy_user( |
| 671 | component, substream, channel, |
| 672 | pos, buf, bytes)); |
Kuninori Morimoto | 82d81f5 | 2019-07-26 13:51:56 +0900 | [diff] [blame] | 673 | |
| 674 | return -EINVAL; |
| 675 | } |
Kuninori Morimoto | 9c712e4 | 2019-07-26 13:52:00 +0900 | [diff] [blame] | 676 | |
| 677 | struct page *snd_soc_pcm_component_page(struct snd_pcm_substream *substream, |
| 678 | unsigned long offset) |
| 679 | { |
Kuninori Morimoto | 0ceef68 | 2020-07-20 10:17:39 +0900 | [diff] [blame^] | 680 | struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); |
Kuninori Morimoto | 9c712e4 | 2019-07-26 13:52:00 +0900 | [diff] [blame] | 681 | struct snd_soc_component *component; |
| 682 | struct page *page; |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 683 | int i; |
Kuninori Morimoto | 9c712e4 | 2019-07-26 13:52:00 +0900 | [diff] [blame] | 684 | |
Kuninori Morimoto | 2b544dd | 2019-10-15 12:59:31 +0900 | [diff] [blame] | 685 | /* FIXME. it returns 1st page now */ |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 686 | for_each_rtd_components(rtd, i, component) { |
Kuninori Morimoto | e2cb4a1 | 2019-10-02 14:30:48 +0900 | [diff] [blame] | 687 | if (component->driver->page) { |
| 688 | page = component->driver->page(component, |
| 689 | substream, offset); |
| 690 | if (page) |
| 691 | return page; |
| 692 | } |
Kuninori Morimoto | 9c712e4 | 2019-07-26 13:52:00 +0900 | [diff] [blame] | 693 | } |
| 694 | |
| 695 | return NULL; |
| 696 | } |
Kuninori Morimoto | 205875e | 2019-07-26 13:52:04 +0900 | [diff] [blame] | 697 | |
| 698 | int snd_soc_pcm_component_mmap(struct snd_pcm_substream *substream, |
| 699 | struct vm_area_struct *vma) |
| 700 | { |
Kuninori Morimoto | 0ceef68 | 2020-07-20 10:17:39 +0900 | [diff] [blame^] | 701 | struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); |
Kuninori Morimoto | 205875e | 2019-07-26 13:52:04 +0900 | [diff] [blame] | 702 | struct snd_soc_component *component; |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 703 | int i; |
Kuninori Morimoto | 205875e | 2019-07-26 13:52:04 +0900 | [diff] [blame] | 704 | |
Kuninori Morimoto | 2b544dd | 2019-10-15 12:59:31 +0900 | [diff] [blame] | 705 | /* FIXME. it returns 1st mmap now */ |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 706 | for_each_rtd_components(rtd, i, component) |
Kuninori Morimoto | e2cb4a1 | 2019-10-02 14:30:48 +0900 | [diff] [blame] | 707 | if (component->driver->mmap) |
Shengjiu Wang | be75db5 | 2020-07-16 13:07:08 +0800 | [diff] [blame] | 708 | return soc_component_ret( |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 709 | component, |
| 710 | component->driver->mmap(component, |
| 711 | substream, vma)); |
Kuninori Morimoto | 205875e | 2019-07-26 13:52:04 +0900 | [diff] [blame] | 712 | |
| 713 | return -EINVAL; |
| 714 | } |
Kuninori Morimoto | 7484291 | 2019-07-26 13:52:08 +0900 | [diff] [blame] | 715 | |
Kuninori Morimoto | b2b2afb | 2019-11-18 10:50:32 +0900 | [diff] [blame] | 716 | int snd_soc_pcm_component_new(struct snd_soc_pcm_runtime *rtd) |
Kuninori Morimoto | 7484291 | 2019-07-26 13:52:08 +0900 | [diff] [blame] | 717 | { |
Kuninori Morimoto | 7484291 | 2019-07-26 13:52:08 +0900 | [diff] [blame] | 718 | struct snd_soc_component *component; |
| 719 | int ret; |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 720 | int i; |
Kuninori Morimoto | 7484291 | 2019-07-26 13:52:08 +0900 | [diff] [blame] | 721 | |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 722 | for_each_rtd_components(rtd, i, component) { |
Kuninori Morimoto | c64bfc9 | 2019-10-02 14:30:59 +0900 | [diff] [blame] | 723 | if (component->driver->pcm_construct) { |
| 724 | ret = component->driver->pcm_construct(component, rtd); |
| 725 | if (ret < 0) |
Shengjiu Wang | be75db5 | 2020-07-16 13:07:08 +0800 | [diff] [blame] | 726 | return soc_component_ret(component, ret); |
Kuninori Morimoto | c64bfc9 | 2019-10-02 14:30:59 +0900 | [diff] [blame] | 727 | } |
Kuninori Morimoto | 7484291 | 2019-07-26 13:52:08 +0900 | [diff] [blame] | 728 | } |
| 729 | |
| 730 | return 0; |
| 731 | } |
Kuninori Morimoto | 79776da | 2019-07-26 13:52:12 +0900 | [diff] [blame] | 732 | |
Kuninori Morimoto | b2b2afb | 2019-11-18 10:50:32 +0900 | [diff] [blame] | 733 | void snd_soc_pcm_component_free(struct snd_soc_pcm_runtime *rtd) |
Kuninori Morimoto | 79776da | 2019-07-26 13:52:12 +0900 | [diff] [blame] | 734 | { |
Kuninori Morimoto | 79776da | 2019-07-26 13:52:12 +0900 | [diff] [blame] | 735 | struct snd_soc_component *component; |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 736 | int i; |
Kuninori Morimoto | 79776da | 2019-07-26 13:52:12 +0900 | [diff] [blame] | 737 | |
Takashi Iwai | 8e3366c | 2020-01-07 08:09:56 +0100 | [diff] [blame] | 738 | if (!rtd->pcm) |
| 739 | return; |
| 740 | |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 741 | for_each_rtd_components(rtd, i, component) |
Kuninori Morimoto | c64bfc9 | 2019-10-02 14:30:59 +0900 | [diff] [blame] | 742 | if (component->driver->pcm_destruct) |
Kuninori Morimoto | b2b2afb | 2019-11-18 10:50:32 +0900 | [diff] [blame] | 743 | component->driver->pcm_destruct(component, rtd->pcm); |
Kuninori Morimoto | 79776da | 2019-07-26 13:52:12 +0900 | [diff] [blame] | 744 | } |
Kuninori Morimoto | 4f39514 | 2020-06-04 17:06:58 +0900 | [diff] [blame] | 745 | |
| 746 | int snd_soc_pcm_component_prepare(struct snd_pcm_substream *substream) |
| 747 | { |
Kuninori Morimoto | 0ceef68 | 2020-07-20 10:17:39 +0900 | [diff] [blame^] | 748 | struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); |
Kuninori Morimoto | 4f39514 | 2020-06-04 17:06:58 +0900 | [diff] [blame] | 749 | struct snd_soc_component *component; |
| 750 | int i, ret; |
| 751 | |
| 752 | for_each_rtd_components(rtd, i, component) { |
| 753 | if (component->driver->prepare) { |
| 754 | ret = component->driver->prepare(component, substream); |
| 755 | if (ret < 0) |
| 756 | return soc_component_ret(component, ret); |
| 757 | } |
| 758 | } |
| 759 | |
| 760 | return 0; |
| 761 | } |
Kuninori Morimoto | e1bafa8 | 2020-06-04 17:07:11 +0900 | [diff] [blame] | 762 | |
| 763 | int snd_soc_pcm_component_hw_params(struct snd_pcm_substream *substream, |
| 764 | struct snd_pcm_hw_params *params, |
| 765 | struct snd_soc_component **last) |
| 766 | { |
Kuninori Morimoto | 0ceef68 | 2020-07-20 10:17:39 +0900 | [diff] [blame^] | 767 | struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); |
Kuninori Morimoto | e1bafa8 | 2020-06-04 17:07:11 +0900 | [diff] [blame] | 768 | struct snd_soc_component *component; |
| 769 | int i, ret; |
| 770 | |
| 771 | for_each_rtd_components(rtd, i, component) { |
| 772 | if (component->driver->hw_params) { |
| 773 | ret = component->driver->hw_params(component, |
| 774 | substream, params); |
| 775 | if (ret < 0) { |
| 776 | *last = component; |
| 777 | return soc_component_ret(component, ret); |
| 778 | } |
| 779 | } |
| 780 | } |
| 781 | |
| 782 | *last = NULL; |
| 783 | return 0; |
| 784 | } |
Kuninori Morimoto | 0475111 | 2020-06-04 17:07:24 +0900 | [diff] [blame] | 785 | |
| 786 | void snd_soc_pcm_component_hw_free(struct snd_pcm_substream *substream, |
| 787 | struct snd_soc_component *last) |
| 788 | { |
Kuninori Morimoto | 0ceef68 | 2020-07-20 10:17:39 +0900 | [diff] [blame^] | 789 | struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); |
Kuninori Morimoto | 0475111 | 2020-06-04 17:07:24 +0900 | [diff] [blame] | 790 | struct snd_soc_component *component; |
| 791 | int i, ret; |
| 792 | |
| 793 | for_each_rtd_components(rtd, i, component) { |
| 794 | if (component == last) |
| 795 | break; |
| 796 | |
| 797 | if (component->driver->hw_free) { |
| 798 | ret = component->driver->hw_free(component, substream); |
| 799 | if (ret < 0) |
| 800 | soc_component_ret(component, ret); |
| 801 | } |
| 802 | } |
| 803 | } |
Kuninori Morimoto | 32fd120 | 2020-06-04 17:07:40 +0900 | [diff] [blame] | 804 | |
| 805 | int snd_soc_pcm_component_trigger(struct snd_pcm_substream *substream, |
| 806 | int cmd) |
| 807 | { |
Kuninori Morimoto | 0ceef68 | 2020-07-20 10:17:39 +0900 | [diff] [blame^] | 808 | struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); |
Kuninori Morimoto | 32fd120 | 2020-06-04 17:07:40 +0900 | [diff] [blame] | 809 | struct snd_soc_component *component; |
| 810 | int i, ret; |
| 811 | |
| 812 | for_each_rtd_components(rtd, i, component) { |
| 813 | if (component->driver->trigger) { |
| 814 | ret = component->driver->trigger(component, substream, cmd); |
| 815 | if (ret < 0) |
| 816 | return soc_component_ret(component, ret); |
| 817 | } |
| 818 | } |
| 819 | |
| 820 | return 0; |
| 821 | } |