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 | // |
| 5 | // Copyright (C) 2019 Renesas Electronics Corp. |
| 6 | // Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> |
| 7 | // |
Kuninori Morimoto | 4a81e8f | 2019-07-26 13:49:54 +0900 | [diff] [blame] | 8 | #include <linux/module.h> |
Kuninori Morimoto | 4ff1fef | 2019-07-26 13:49:48 +0900 | [diff] [blame] | 9 | #include <sound/soc.h> |
| 10 | |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 11 | #define soc_component_ret(dai, ret) _soc_component_ret(dai, __func__, ret) |
| 12 | static inline int _soc_component_ret(struct snd_soc_component *component, |
| 13 | const char *func, int ret) |
| 14 | { |
| 15 | /* Positive/Zero values are not errors */ |
| 16 | if (ret >= 0) |
| 17 | return ret; |
| 18 | |
| 19 | /* Negative values might be errors */ |
| 20 | switch (ret) { |
| 21 | case -EPROBE_DEFER: |
| 22 | case -ENOTSUPP: |
| 23 | break; |
| 24 | default: |
| 25 | dev_err(component->dev, |
| 26 | "ASoC: error at %s on %s: %d\n", |
| 27 | func, component->name, ret); |
| 28 | } |
| 29 | |
| 30 | return ret; |
| 31 | } |
| 32 | |
Kuninori Morimoto | 536aba1 | 2020-06-04 17:06:32 +0900 | [diff] [blame] | 33 | int snd_soc_component_initialize(struct snd_soc_component *component, |
| 34 | const struct snd_soc_component_driver *driver, |
| 35 | struct device *dev, const char *name) |
| 36 | { |
| 37 | INIT_LIST_HEAD(&component->dai_list); |
| 38 | INIT_LIST_HEAD(&component->dobj_list); |
| 39 | INIT_LIST_HEAD(&component->card_list); |
| 40 | mutex_init(&component->io_mutex); |
| 41 | |
| 42 | component->name = name; |
| 43 | component->dev = dev; |
| 44 | component->driver = driver; |
| 45 | |
| 46 | return 0; |
| 47 | } |
| 48 | |
Kuninori Morimoto | 257c4da | 2020-06-04 17:07:54 +0900 | [diff] [blame^] | 49 | void snd_soc_component_set_aux(struct snd_soc_component *component, |
| 50 | struct snd_soc_aux_dev *aux) |
| 51 | { |
| 52 | component->init = (aux) ? aux->init : NULL; |
| 53 | } |
| 54 | |
| 55 | int snd_soc_component_init(struct snd_soc_component *component) |
| 56 | { |
| 57 | int ret = 0; |
| 58 | |
| 59 | if (component->init) |
| 60 | ret = component->init(component); |
| 61 | |
| 62 | return soc_component_ret(component, ret); |
| 63 | } |
| 64 | |
Kuninori Morimoto | 4ff1fef | 2019-07-26 13:49:48 +0900 | [diff] [blame] | 65 | /** |
| 66 | * snd_soc_component_set_sysclk - configure COMPONENT system or master clock. |
| 67 | * @component: COMPONENT |
| 68 | * @clk_id: DAI specific clock ID |
| 69 | * @source: Source for the clock |
| 70 | * @freq: new clock frequency in Hz |
| 71 | * @dir: new clock direction - input/output. |
| 72 | * |
| 73 | * Configures the CODEC master (MCLK) or system (SYSCLK) clocking. |
| 74 | */ |
| 75 | int snd_soc_component_set_sysclk(struct snd_soc_component *component, |
| 76 | int clk_id, int source, unsigned int freq, |
| 77 | int dir) |
| 78 | { |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 79 | int ret = -ENOTSUPP; |
| 80 | |
Kuninori Morimoto | 4ff1fef | 2019-07-26 13:49:48 +0900 | [diff] [blame] | 81 | if (component->driver->set_sysclk) |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 82 | ret = component->driver->set_sysclk(component, clk_id, source, |
Kuninori Morimoto | 4ff1fef | 2019-07-26 13:49:48 +0900 | [diff] [blame] | 83 | freq, dir); |
| 84 | |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 85 | return soc_component_ret(component, ret); |
Kuninori Morimoto | 4ff1fef | 2019-07-26 13:49:48 +0900 | [diff] [blame] | 86 | } |
| 87 | EXPORT_SYMBOL_GPL(snd_soc_component_set_sysclk); |
| 88 | |
| 89 | /* |
| 90 | * snd_soc_component_set_pll - configure component PLL. |
| 91 | * @component: COMPONENT |
| 92 | * @pll_id: DAI specific PLL ID |
| 93 | * @source: DAI specific source for the PLL |
| 94 | * @freq_in: PLL input clock frequency in Hz |
| 95 | * @freq_out: requested PLL output clock frequency in Hz |
| 96 | * |
| 97 | * Configures and enables PLL to generate output clock based on input clock. |
| 98 | */ |
| 99 | int snd_soc_component_set_pll(struct snd_soc_component *component, int pll_id, |
| 100 | int source, unsigned int freq_in, |
| 101 | unsigned int freq_out) |
| 102 | { |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 103 | int ret = -EINVAL; |
| 104 | |
Kuninori Morimoto | 4ff1fef | 2019-07-26 13:49:48 +0900 | [diff] [blame] | 105 | if (component->driver->set_pll) |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 106 | ret = component->driver->set_pll(component, pll_id, source, |
Kuninori Morimoto | 4ff1fef | 2019-07-26 13:49:48 +0900 | [diff] [blame] | 107 | freq_in, freq_out); |
| 108 | |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 109 | return soc_component_ret(component, ret); |
Kuninori Morimoto | 4ff1fef | 2019-07-26 13:49:48 +0900 | [diff] [blame] | 110 | } |
| 111 | EXPORT_SYMBOL_GPL(snd_soc_component_set_pll); |
| 112 | |
Kuninori Morimoto | 9d415fb | 2019-07-26 13:51:35 +0900 | [diff] [blame] | 113 | void snd_soc_component_seq_notifier(struct snd_soc_component *component, |
| 114 | enum snd_soc_dapm_type type, int subseq) |
| 115 | { |
| 116 | if (component->driver->seq_notifier) |
| 117 | component->driver->seq_notifier(component, type, subseq); |
| 118 | } |
| 119 | |
Kuninori Morimoto | 8e2a990 | 2019-07-26 13:51:39 +0900 | [diff] [blame] | 120 | int snd_soc_component_stream_event(struct snd_soc_component *component, |
| 121 | int event) |
| 122 | { |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 123 | int ret = 0; |
Kuninori Morimoto | 8e2a990 | 2019-07-26 13:51:39 +0900 | [diff] [blame] | 124 | |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 125 | if (component->driver->stream_event) |
| 126 | ret = component->driver->stream_event(component, event); |
| 127 | |
| 128 | return soc_component_ret(component, ret); |
Kuninori Morimoto | 8e2a990 | 2019-07-26 13:51:39 +0900 | [diff] [blame] | 129 | } |
| 130 | |
Kuninori Morimoto | 7951b146 | 2019-07-26 13:51:43 +0900 | [diff] [blame] | 131 | int snd_soc_component_set_bias_level(struct snd_soc_component *component, |
| 132 | enum snd_soc_bias_level level) |
| 133 | { |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 134 | int ret = 0; |
Kuninori Morimoto | 7951b146 | 2019-07-26 13:51:43 +0900 | [diff] [blame] | 135 | |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 136 | if (component->driver->set_bias_level) |
| 137 | ret = component->driver->set_bias_level(component, level); |
| 138 | |
| 139 | return soc_component_ret(component, ret); |
Kuninori Morimoto | 7951b146 | 2019-07-26 13:51:43 +0900 | [diff] [blame] | 140 | } |
| 141 | |
Kuninori Morimoto | 4ca8701 | 2020-06-04 17:06:11 +0900 | [diff] [blame] | 142 | static int soc_component_pin(struct snd_soc_component *component, |
| 143 | const char *pin, |
| 144 | int (*pin_func)(struct snd_soc_dapm_context *dapm, |
| 145 | const char *pin)) |
Kuninori Morimoto | 4ff1fef | 2019-07-26 13:49:48 +0900 | [diff] [blame] | 146 | { |
| 147 | struct snd_soc_dapm_context *dapm = |
| 148 | snd_soc_component_get_dapm(component); |
| 149 | char *full_name; |
| 150 | int ret; |
| 151 | |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 152 | if (!component->name_prefix) { |
| 153 | ret = pin_func(dapm, pin); |
| 154 | goto end; |
| 155 | } |
Kuninori Morimoto | 4ff1fef | 2019-07-26 13:49:48 +0900 | [diff] [blame] | 156 | |
| 157 | full_name = kasprintf(GFP_KERNEL, "%s %s", component->name_prefix, pin); |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 158 | if (!full_name) { |
| 159 | ret = -ENOMEM; |
| 160 | goto end; |
| 161 | } |
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 | ret = pin_func(dapm, full_name); |
Kuninori Morimoto | 4ff1fef | 2019-07-26 13:49:48 +0900 | [diff] [blame] | 164 | kfree(full_name); |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 165 | end: |
| 166 | return soc_component_ret(component, ret); |
Kuninori Morimoto | 4ff1fef | 2019-07-26 13:49:48 +0900 | [diff] [blame] | 167 | } |
Kuninori Morimoto | 4ca8701 | 2020-06-04 17:06:11 +0900 | [diff] [blame] | 168 | |
| 169 | int snd_soc_component_enable_pin(struct snd_soc_component *component, |
| 170 | const char *pin) |
| 171 | { |
| 172 | return soc_component_pin(component, pin, snd_soc_dapm_enable_pin); |
| 173 | } |
Kuninori Morimoto | 4ff1fef | 2019-07-26 13:49:48 +0900 | [diff] [blame] | 174 | EXPORT_SYMBOL_GPL(snd_soc_component_enable_pin); |
| 175 | |
| 176 | int snd_soc_component_enable_pin_unlocked(struct snd_soc_component *component, |
| 177 | const char *pin) |
| 178 | { |
Kuninori Morimoto | 4ca8701 | 2020-06-04 17:06:11 +0900 | [diff] [blame] | 179 | return soc_component_pin(component, pin, snd_soc_dapm_enable_pin_unlocked); |
Kuninori Morimoto | 4ff1fef | 2019-07-26 13:49:48 +0900 | [diff] [blame] | 180 | } |
| 181 | EXPORT_SYMBOL_GPL(snd_soc_component_enable_pin_unlocked); |
| 182 | |
| 183 | int snd_soc_component_disable_pin(struct snd_soc_component *component, |
| 184 | const char *pin) |
| 185 | { |
Kuninori Morimoto | 4ca8701 | 2020-06-04 17:06:11 +0900 | [diff] [blame] | 186 | return soc_component_pin(component, pin, snd_soc_dapm_disable_pin); |
Kuninori Morimoto | 4ff1fef | 2019-07-26 13:49:48 +0900 | [diff] [blame] | 187 | } |
| 188 | EXPORT_SYMBOL_GPL(snd_soc_component_disable_pin); |
| 189 | |
| 190 | int snd_soc_component_disable_pin_unlocked(struct snd_soc_component *component, |
| 191 | const char *pin) |
| 192 | { |
Kuninori Morimoto | 4ca8701 | 2020-06-04 17:06:11 +0900 | [diff] [blame] | 193 | return soc_component_pin(component, pin, snd_soc_dapm_disable_pin_unlocked); |
Kuninori Morimoto | 4ff1fef | 2019-07-26 13:49:48 +0900 | [diff] [blame] | 194 | } |
| 195 | EXPORT_SYMBOL_GPL(snd_soc_component_disable_pin_unlocked); |
| 196 | |
| 197 | int snd_soc_component_nc_pin(struct snd_soc_component *component, |
| 198 | const char *pin) |
| 199 | { |
Kuninori Morimoto | 4ca8701 | 2020-06-04 17:06:11 +0900 | [diff] [blame] | 200 | return soc_component_pin(component, pin, snd_soc_dapm_nc_pin); |
Kuninori Morimoto | 4ff1fef | 2019-07-26 13:49:48 +0900 | [diff] [blame] | 201 | } |
| 202 | EXPORT_SYMBOL_GPL(snd_soc_component_nc_pin); |
| 203 | |
| 204 | int snd_soc_component_nc_pin_unlocked(struct snd_soc_component *component, |
| 205 | const char *pin) |
| 206 | { |
Kuninori Morimoto | 4ca8701 | 2020-06-04 17:06:11 +0900 | [diff] [blame] | 207 | return soc_component_pin(component, pin, snd_soc_dapm_nc_pin_unlocked); |
Kuninori Morimoto | 4ff1fef | 2019-07-26 13:49:48 +0900 | [diff] [blame] | 208 | } |
| 209 | EXPORT_SYMBOL_GPL(snd_soc_component_nc_pin_unlocked); |
| 210 | |
| 211 | int snd_soc_component_get_pin_status(struct snd_soc_component *component, |
| 212 | const char *pin) |
| 213 | { |
Kuninori Morimoto | 4ca8701 | 2020-06-04 17:06:11 +0900 | [diff] [blame] | 214 | return soc_component_pin(component, pin, snd_soc_dapm_get_pin_status); |
Kuninori Morimoto | 4ff1fef | 2019-07-26 13:49:48 +0900 | [diff] [blame] | 215 | } |
| 216 | EXPORT_SYMBOL_GPL(snd_soc_component_get_pin_status); |
| 217 | |
| 218 | int snd_soc_component_force_enable_pin(struct snd_soc_component *component, |
| 219 | const char *pin) |
| 220 | { |
Kuninori Morimoto | 4ca8701 | 2020-06-04 17:06:11 +0900 | [diff] [blame] | 221 | return soc_component_pin(component, pin, snd_soc_dapm_force_enable_pin); |
Kuninori Morimoto | 4ff1fef | 2019-07-26 13:49:48 +0900 | [diff] [blame] | 222 | } |
| 223 | EXPORT_SYMBOL_GPL(snd_soc_component_force_enable_pin); |
| 224 | |
| 225 | int snd_soc_component_force_enable_pin_unlocked( |
| 226 | struct snd_soc_component *component, |
| 227 | const char *pin) |
| 228 | { |
Kuninori Morimoto | 4ca8701 | 2020-06-04 17:06:11 +0900 | [diff] [blame] | 229 | return soc_component_pin(component, pin, snd_soc_dapm_force_enable_pin_unlocked); |
Kuninori Morimoto | 4ff1fef | 2019-07-26 13:49:48 +0900 | [diff] [blame] | 230 | } |
| 231 | EXPORT_SYMBOL_GPL(snd_soc_component_force_enable_pin_unlocked); |
| 232 | |
| 233 | /** |
| 234 | * snd_soc_component_set_jack - configure component jack. |
| 235 | * @component: COMPONENTs |
| 236 | * @jack: structure to use for the jack |
| 237 | * @data: can be used if codec driver need extra data for configuring jack |
| 238 | * |
| 239 | * Configures and enables jack detection function. |
| 240 | */ |
| 241 | int snd_soc_component_set_jack(struct snd_soc_component *component, |
| 242 | struct snd_soc_jack *jack, void *data) |
| 243 | { |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 244 | int ret = -ENOTSUPP; |
Kuninori Morimoto | 4ff1fef | 2019-07-26 13:49:48 +0900 | [diff] [blame] | 245 | |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 246 | if (component->driver->set_jack) |
| 247 | ret = component->driver->set_jack(component, jack, data); |
| 248 | |
| 249 | return soc_component_ret(component, ret); |
Kuninori Morimoto | 4ff1fef | 2019-07-26 13:49:48 +0900 | [diff] [blame] | 250 | } |
| 251 | EXPORT_SYMBOL_GPL(snd_soc_component_set_jack); |
Kuninori Morimoto | 4a81e8f | 2019-07-26 13:49:54 +0900 | [diff] [blame] | 252 | |
| 253 | int snd_soc_component_module_get(struct snd_soc_component *component, |
| 254 | int upon_open) |
| 255 | { |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 256 | int ret = 0; |
| 257 | |
Kuninori Morimoto | 4a81e8f | 2019-07-26 13:49:54 +0900 | [diff] [blame] | 258 | if (component->driver->module_get_upon_open == !!upon_open && |
| 259 | !try_module_get(component->dev->driver->owner)) |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 260 | ret = -ENODEV; |
Kuninori Morimoto | 4a81e8f | 2019-07-26 13:49:54 +0900 | [diff] [blame] | 261 | |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 262 | 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, |
| 266 | int upon_open) |
| 267 | { |
| 268 | if (component->driver->module_get_upon_open == !!upon_open) |
| 269 | module_put(component->dev->driver->owner); |
| 270 | } |
Kuninori Morimoto | ae2f484 | 2019-07-26 13:50:01 +0900 | [diff] [blame] | 271 | |
| 272 | int snd_soc_component_open(struct snd_soc_component *component, |
| 273 | struct snd_pcm_substream *substream) |
| 274 | { |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 275 | int ret = 0; |
| 276 | |
Kuninori Morimoto | e2cb4a1 | 2019-10-02 14:30:48 +0900 | [diff] [blame] | 277 | if (component->driver->open) |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 278 | ret = component->driver->open(component, substream); |
| 279 | |
| 280 | return soc_component_ret(component, ret); |
Kuninori Morimoto | ae2f484 | 2019-07-26 13:50:01 +0900 | [diff] [blame] | 281 | } |
Kuninori Morimoto | 3672beb | 2019-07-26 13:50:07 +0900 | [diff] [blame] | 282 | |
| 283 | int snd_soc_component_close(struct snd_soc_component *component, |
| 284 | struct snd_pcm_substream *substream) |
| 285 | { |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 286 | int ret = 0; |
| 287 | |
Kuninori Morimoto | e2cb4a1 | 2019-10-02 14:30:48 +0900 | [diff] [blame] | 288 | if (component->driver->close) |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 289 | ret = component->driver->close(component, substream); |
| 290 | |
| 291 | return soc_component_ret(component, ret); |
Kuninori Morimoto | 3672beb | 2019-07-26 13:50:07 +0900 | [diff] [blame] | 292 | } |
Kuninori Morimoto | 6d53723 | 2019-07-26 13:50:13 +0900 | [diff] [blame] | 293 | |
Kuninori Morimoto | 66c5157 | 2019-07-26 13:50:34 +0900 | [diff] [blame] | 294 | void snd_soc_component_suspend(struct snd_soc_component *component) |
| 295 | { |
| 296 | if (component->driver->suspend) |
| 297 | component->driver->suspend(component); |
| 298 | component->suspended = 1; |
| 299 | } |
Kuninori Morimoto | 9a840cb | 2019-07-26 13:51:08 +0900 | [diff] [blame] | 300 | |
| 301 | void snd_soc_component_resume(struct snd_soc_component *component) |
| 302 | { |
| 303 | if (component->driver->resume) |
| 304 | component->driver->resume(component); |
| 305 | component->suspended = 0; |
| 306 | } |
Kuninori Morimoto | e40fadb | 2019-07-26 13:51:13 +0900 | [diff] [blame] | 307 | |
| 308 | int snd_soc_component_is_suspended(struct snd_soc_component *component) |
| 309 | { |
| 310 | return component->suspended; |
| 311 | } |
Kuninori Morimoto | 08e837d | 2019-07-26 13:51:17 +0900 | [diff] [blame] | 312 | |
| 313 | int snd_soc_component_probe(struct snd_soc_component *component) |
| 314 | { |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 315 | int ret = 0; |
Kuninori Morimoto | 08e837d | 2019-07-26 13:51:17 +0900 | [diff] [blame] | 316 | |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 317 | if (component->driver->probe) |
| 318 | ret = component->driver->probe(component); |
| 319 | |
| 320 | return soc_component_ret(component, ret); |
Kuninori Morimoto | 08e837d | 2019-07-26 13:51:17 +0900 | [diff] [blame] | 321 | } |
Kuninori Morimoto | 03b34dd | 2019-07-26 13:51:22 +0900 | [diff] [blame] | 322 | |
| 323 | void snd_soc_component_remove(struct snd_soc_component *component) |
| 324 | { |
| 325 | if (component->driver->remove) |
| 326 | component->driver->remove(component); |
| 327 | } |
Kuninori Morimoto | 2c7b170 | 2019-07-26 13:51:26 +0900 | [diff] [blame] | 328 | |
| 329 | int snd_soc_component_of_xlate_dai_id(struct snd_soc_component *component, |
| 330 | struct device_node *ep) |
| 331 | { |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 332 | int ret = -ENOTSUPP; |
Kuninori Morimoto | 2c7b170 | 2019-07-26 13:51:26 +0900 | [diff] [blame] | 333 | |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 334 | if (component->driver->of_xlate_dai_id) |
| 335 | ret = component->driver->of_xlate_dai_id(component, ep); |
| 336 | |
| 337 | return soc_component_ret(component, ret); |
Kuninori Morimoto | 2c7b170 | 2019-07-26 13:51:26 +0900 | [diff] [blame] | 338 | } |
Kuninori Morimoto | a2a3417 | 2019-07-26 13:51:31 +0900 | [diff] [blame] | 339 | |
| 340 | int snd_soc_component_of_xlate_dai_name(struct snd_soc_component *component, |
| 341 | struct of_phandle_args *args, |
| 342 | const char **dai_name) |
| 343 | { |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 344 | int ret = -ENOTSUPP; |
| 345 | |
Kuninori Morimoto | a2a3417 | 2019-07-26 13:51:31 +0900 | [diff] [blame] | 346 | if (component->driver->of_xlate_dai_name) |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 347 | ret = component->driver->of_xlate_dai_name(component, |
| 348 | args, dai_name); |
| 349 | |
| 350 | return soc_component_ret(component, ret); |
Kuninori Morimoto | a2a3417 | 2019-07-26 13:51:31 +0900 | [diff] [blame] | 351 | } |
Kuninori Morimoto | 0035e25 | 2019-07-26 13:51:47 +0900 | [diff] [blame] | 352 | |
Kuninori Morimoto | c7d75b5 | 2020-06-04 17:06:22 +0900 | [diff] [blame] | 353 | void snd_soc_component_setup_regmap(struct snd_soc_component *component) |
| 354 | { |
| 355 | int val_bytes = regmap_get_val_bytes(component->regmap); |
| 356 | |
| 357 | /* Errors are legitimate for non-integer byte multiples */ |
| 358 | if (val_bytes > 0) |
| 359 | component->val_bytes = val_bytes; |
| 360 | } |
| 361 | |
| 362 | #ifdef CONFIG_REGMAP |
| 363 | |
| 364 | /** |
| 365 | * snd_soc_component_init_regmap() - Initialize regmap instance for the |
| 366 | * component |
| 367 | * @component: The component for which to initialize the regmap instance |
| 368 | * @regmap: The regmap instance that should be used by the component |
| 369 | * |
| 370 | * This function allows deferred assignment of the regmap instance that is |
| 371 | * associated with the component. Only use this if the regmap instance is not |
| 372 | * yet ready when the component is registered. The function must also be called |
| 373 | * before the first IO attempt of the component. |
| 374 | */ |
| 375 | void snd_soc_component_init_regmap(struct snd_soc_component *component, |
| 376 | struct regmap *regmap) |
| 377 | { |
| 378 | component->regmap = regmap; |
| 379 | snd_soc_component_setup_regmap(component); |
| 380 | } |
| 381 | EXPORT_SYMBOL_GPL(snd_soc_component_init_regmap); |
| 382 | |
| 383 | /** |
| 384 | * snd_soc_component_exit_regmap() - De-initialize regmap instance for the |
| 385 | * component |
| 386 | * @component: The component for which to de-initialize the regmap instance |
| 387 | * |
| 388 | * Calls regmap_exit() on the regmap instance associated to the component and |
| 389 | * removes the regmap instance from the component. |
| 390 | * |
| 391 | * This function should only be used if snd_soc_component_init_regmap() was used |
| 392 | * to initialize the regmap instance. |
| 393 | */ |
| 394 | void snd_soc_component_exit_regmap(struct snd_soc_component *component) |
| 395 | { |
| 396 | regmap_exit(component->regmap); |
| 397 | component->regmap = NULL; |
| 398 | } |
| 399 | EXPORT_SYMBOL_GPL(snd_soc_component_exit_regmap); |
| 400 | |
| 401 | #endif |
| 402 | |
Kuninori Morimoto | 0035e25 | 2019-07-26 13:51:47 +0900 | [diff] [blame] | 403 | int snd_soc_pcm_component_pointer(struct snd_pcm_substream *substream) |
| 404 | { |
| 405 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 406 | struct snd_soc_component *component; |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 407 | int i; |
Kuninori Morimoto | 0035e25 | 2019-07-26 13:51:47 +0900 | [diff] [blame] | 408 | |
Kuninori Morimoto | 2b544dd | 2019-10-15 12:59:31 +0900 | [diff] [blame] | 409 | /* FIXME: use 1st pointer */ |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 410 | for_each_rtd_components(rtd, i, component) |
Kuninori Morimoto | e2cb4a1 | 2019-10-02 14:30:48 +0900 | [diff] [blame] | 411 | if (component->driver->pointer) |
| 412 | return component->driver->pointer(component, substream); |
Kuninori Morimoto | 0035e25 | 2019-07-26 13:51:47 +0900 | [diff] [blame] | 413 | |
| 414 | return 0; |
| 415 | } |
Kuninori Morimoto | 96a4790 | 2019-07-26 13:51:51 +0900 | [diff] [blame] | 416 | |
| 417 | int snd_soc_pcm_component_ioctl(struct snd_pcm_substream *substream, |
| 418 | unsigned int cmd, void *arg) |
| 419 | { |
| 420 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 421 | struct snd_soc_component *component; |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 422 | int i; |
Kuninori Morimoto | 96a4790 | 2019-07-26 13:51:51 +0900 | [diff] [blame] | 423 | |
Kuninori Morimoto | 2b544dd | 2019-10-15 12:59:31 +0900 | [diff] [blame] | 424 | /* FIXME: use 1st ioctl */ |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 425 | for_each_rtd_components(rtd, i, component) |
Kuninori Morimoto | e2cb4a1 | 2019-10-02 14:30:48 +0900 | [diff] [blame] | 426 | if (component->driver->ioctl) |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 427 | return soc_component_ret( |
| 428 | component, |
| 429 | component->driver->ioctl(component, |
| 430 | substream, cmd, arg)); |
Kuninori Morimoto | 96a4790 | 2019-07-26 13:51:51 +0900 | [diff] [blame] | 431 | |
| 432 | return snd_pcm_lib_ioctl(substream, cmd, arg); |
| 433 | } |
Kuninori Morimoto | 82d81f5 | 2019-07-26 13:51:56 +0900 | [diff] [blame] | 434 | |
Takashi Iwai | 1e5ddb6 | 2019-11-21 20:07:09 +0100 | [diff] [blame] | 435 | int snd_soc_pcm_component_sync_stop(struct snd_pcm_substream *substream) |
| 436 | { |
| 437 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 438 | struct snd_soc_component *component; |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 439 | int i, ret; |
Takashi Iwai | 1e5ddb6 | 2019-11-21 20:07:09 +0100 | [diff] [blame] | 440 | |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 441 | for_each_rtd_components(rtd, i, component) { |
Kuninori Morimoto | f1861a7 | 2020-02-28 10:48:35 +0900 | [diff] [blame] | 442 | if (component->driver->sync_stop) { |
Takashi Iwai | 1e5ddb6 | 2019-11-21 20:07:09 +0100 | [diff] [blame] | 443 | ret = component->driver->sync_stop(component, |
| 444 | substream); |
| 445 | if (ret < 0) |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 446 | soc_component_ret(component, ret); |
Takashi Iwai | 1e5ddb6 | 2019-11-21 20:07:09 +0100 | [diff] [blame] | 447 | } |
| 448 | } |
| 449 | |
| 450 | return 0; |
| 451 | } |
| 452 | |
Kuninori Morimoto | 82d81f5 | 2019-07-26 13:51:56 +0900 | [diff] [blame] | 453 | int snd_soc_pcm_component_copy_user(struct snd_pcm_substream *substream, |
| 454 | int channel, unsigned long pos, |
| 455 | void __user *buf, unsigned long bytes) |
| 456 | { |
| 457 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Kuninori Morimoto | 82d81f5 | 2019-07-26 13:51:56 +0900 | [diff] [blame] | 458 | struct snd_soc_component *component; |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 459 | int i; |
Kuninori Morimoto | 82d81f5 | 2019-07-26 13:51:56 +0900 | [diff] [blame] | 460 | |
Kuninori Morimoto | 2b544dd | 2019-10-15 12:59:31 +0900 | [diff] [blame] | 461 | /* FIXME. it returns 1st copy now */ |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 462 | for_each_rtd_components(rtd, i, component) |
Kuninori Morimoto | e2cb4a1 | 2019-10-02 14:30:48 +0900 | [diff] [blame] | 463 | if (component->driver->copy_user) |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 464 | return soc_component_ret( |
| 465 | component, |
| 466 | component->driver->copy_user( |
| 467 | component, substream, channel, |
| 468 | pos, buf, bytes)); |
Kuninori Morimoto | 82d81f5 | 2019-07-26 13:51:56 +0900 | [diff] [blame] | 469 | |
| 470 | return -EINVAL; |
| 471 | } |
Kuninori Morimoto | 9c712e4 | 2019-07-26 13:52:00 +0900 | [diff] [blame] | 472 | |
| 473 | struct page *snd_soc_pcm_component_page(struct snd_pcm_substream *substream, |
| 474 | unsigned long offset) |
| 475 | { |
| 476 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Kuninori Morimoto | 9c712e4 | 2019-07-26 13:52:00 +0900 | [diff] [blame] | 477 | struct snd_soc_component *component; |
| 478 | struct page *page; |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 479 | int i; |
Kuninori Morimoto | 9c712e4 | 2019-07-26 13:52:00 +0900 | [diff] [blame] | 480 | |
Kuninori Morimoto | 2b544dd | 2019-10-15 12:59:31 +0900 | [diff] [blame] | 481 | /* FIXME. it returns 1st page now */ |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 482 | for_each_rtd_components(rtd, i, component) { |
Kuninori Morimoto | e2cb4a1 | 2019-10-02 14:30:48 +0900 | [diff] [blame] | 483 | if (component->driver->page) { |
| 484 | page = component->driver->page(component, |
| 485 | substream, offset); |
| 486 | if (page) |
| 487 | return page; |
| 488 | } |
Kuninori Morimoto | 9c712e4 | 2019-07-26 13:52:00 +0900 | [diff] [blame] | 489 | } |
| 490 | |
| 491 | return NULL; |
| 492 | } |
Kuninori Morimoto | 205875e | 2019-07-26 13:52:04 +0900 | [diff] [blame] | 493 | |
| 494 | int snd_soc_pcm_component_mmap(struct snd_pcm_substream *substream, |
| 495 | struct vm_area_struct *vma) |
| 496 | { |
| 497 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Kuninori Morimoto | 205875e | 2019-07-26 13:52:04 +0900 | [diff] [blame] | 498 | struct snd_soc_component *component; |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 499 | int i; |
Kuninori Morimoto | 205875e | 2019-07-26 13:52:04 +0900 | [diff] [blame] | 500 | |
Kuninori Morimoto | 2b544dd | 2019-10-15 12:59:31 +0900 | [diff] [blame] | 501 | /* FIXME. it returns 1st mmap now */ |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 502 | for_each_rtd_components(rtd, i, component) |
Kuninori Morimoto | e2cb4a1 | 2019-10-02 14:30:48 +0900 | [diff] [blame] | 503 | if (component->driver->mmap) |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 504 | soc_component_ret( |
| 505 | component, |
| 506 | component->driver->mmap(component, |
| 507 | substream, vma)); |
Kuninori Morimoto | 205875e | 2019-07-26 13:52:04 +0900 | [diff] [blame] | 508 | |
| 509 | return -EINVAL; |
| 510 | } |
Kuninori Morimoto | 7484291 | 2019-07-26 13:52:08 +0900 | [diff] [blame] | 511 | |
Kuninori Morimoto | b2b2afb | 2019-11-18 10:50:32 +0900 | [diff] [blame] | 512 | int snd_soc_pcm_component_new(struct snd_soc_pcm_runtime *rtd) |
Kuninori Morimoto | 7484291 | 2019-07-26 13:52:08 +0900 | [diff] [blame] | 513 | { |
Kuninori Morimoto | 7484291 | 2019-07-26 13:52:08 +0900 | [diff] [blame] | 514 | struct snd_soc_component *component; |
| 515 | int ret; |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 516 | int i; |
Kuninori Morimoto | 7484291 | 2019-07-26 13:52:08 +0900 | [diff] [blame] | 517 | |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 518 | for_each_rtd_components(rtd, i, component) { |
Kuninori Morimoto | c64bfc9 | 2019-10-02 14:30:59 +0900 | [diff] [blame] | 519 | if (component->driver->pcm_construct) { |
| 520 | ret = component->driver->pcm_construct(component, rtd); |
| 521 | if (ret < 0) |
Kuninori Morimoto | e2329ee | 2020-06-04 17:06:41 +0900 | [diff] [blame] | 522 | soc_component_ret(component, ret); |
Kuninori Morimoto | c64bfc9 | 2019-10-02 14:30:59 +0900 | [diff] [blame] | 523 | } |
Kuninori Morimoto | 7484291 | 2019-07-26 13:52:08 +0900 | [diff] [blame] | 524 | } |
| 525 | |
| 526 | return 0; |
| 527 | } |
Kuninori Morimoto | 79776da | 2019-07-26 13:52:12 +0900 | [diff] [blame] | 528 | |
Kuninori Morimoto | b2b2afb | 2019-11-18 10:50:32 +0900 | [diff] [blame] | 529 | void snd_soc_pcm_component_free(struct snd_soc_pcm_runtime *rtd) |
Kuninori Morimoto | 79776da | 2019-07-26 13:52:12 +0900 | [diff] [blame] | 530 | { |
Kuninori Morimoto | 79776da | 2019-07-26 13:52:12 +0900 | [diff] [blame] | 531 | struct snd_soc_component *component; |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 532 | int i; |
Kuninori Morimoto | 79776da | 2019-07-26 13:52:12 +0900 | [diff] [blame] | 533 | |
Takashi Iwai | 8e3366c | 2020-01-07 08:09:56 +0100 | [diff] [blame] | 534 | if (!rtd->pcm) |
| 535 | return; |
| 536 | |
Kuninori Morimoto | 613fb50 | 2020-01-10 11:35:21 +0900 | [diff] [blame] | 537 | for_each_rtd_components(rtd, i, component) |
Kuninori Morimoto | c64bfc9 | 2019-10-02 14:30:59 +0900 | [diff] [blame] | 538 | if (component->driver->pcm_destruct) |
Kuninori Morimoto | b2b2afb | 2019-11-18 10:50:32 +0900 | [diff] [blame] | 539 | component->driver->pcm_destruct(component, rtd->pcm); |
Kuninori Morimoto | 79776da | 2019-07-26 13:52:12 +0900 | [diff] [blame] | 540 | } |
Kuninori Morimoto | 4f39514 | 2020-06-04 17:06:58 +0900 | [diff] [blame] | 541 | |
| 542 | int snd_soc_pcm_component_prepare(struct snd_pcm_substream *substream) |
| 543 | { |
| 544 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 545 | struct snd_soc_component *component; |
| 546 | int i, ret; |
| 547 | |
| 548 | for_each_rtd_components(rtd, i, component) { |
| 549 | if (component->driver->prepare) { |
| 550 | ret = component->driver->prepare(component, substream); |
| 551 | if (ret < 0) |
| 552 | return soc_component_ret(component, ret); |
| 553 | } |
| 554 | } |
| 555 | |
| 556 | return 0; |
| 557 | } |
Kuninori Morimoto | e1bafa8 | 2020-06-04 17:07:11 +0900 | [diff] [blame] | 558 | |
| 559 | int snd_soc_pcm_component_hw_params(struct snd_pcm_substream *substream, |
| 560 | struct snd_pcm_hw_params *params, |
| 561 | struct snd_soc_component **last) |
| 562 | { |
| 563 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 564 | struct snd_soc_component *component; |
| 565 | int i, ret; |
| 566 | |
| 567 | for_each_rtd_components(rtd, i, component) { |
| 568 | if (component->driver->hw_params) { |
| 569 | ret = component->driver->hw_params(component, |
| 570 | substream, params); |
| 571 | if (ret < 0) { |
| 572 | *last = component; |
| 573 | return soc_component_ret(component, ret); |
| 574 | } |
| 575 | } |
| 576 | } |
| 577 | |
| 578 | *last = NULL; |
| 579 | return 0; |
| 580 | } |
Kuninori Morimoto | 0475111 | 2020-06-04 17:07:24 +0900 | [diff] [blame] | 581 | |
| 582 | void snd_soc_pcm_component_hw_free(struct snd_pcm_substream *substream, |
| 583 | struct snd_soc_component *last) |
| 584 | { |
| 585 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 586 | struct snd_soc_component *component; |
| 587 | int i, ret; |
| 588 | |
| 589 | for_each_rtd_components(rtd, i, component) { |
| 590 | if (component == last) |
| 591 | break; |
| 592 | |
| 593 | if (component->driver->hw_free) { |
| 594 | ret = component->driver->hw_free(component, substream); |
| 595 | if (ret < 0) |
| 596 | soc_component_ret(component, ret); |
| 597 | } |
| 598 | } |
| 599 | } |
Kuninori Morimoto | 32fd120 | 2020-06-04 17:07:40 +0900 | [diff] [blame] | 600 | |
| 601 | int snd_soc_pcm_component_trigger(struct snd_pcm_substream *substream, |
| 602 | int cmd) |
| 603 | { |
| 604 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 605 | struct snd_soc_component *component; |
| 606 | int i, ret; |
| 607 | |
| 608 | for_each_rtd_components(rtd, i, component) { |
| 609 | if (component->driver->trigger) { |
| 610 | ret = component->driver->trigger(component, substream, cmd); |
| 611 | if (ret < 0) |
| 612 | return soc_component_ret(component, ret); |
| 613 | } |
| 614 | } |
| 615 | |
| 616 | return 0; |
| 617 | } |