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