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