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 | 4ff1fef | 2019-07-26 13:49:48 +0900 | [diff] [blame] | 80 | int snd_soc_component_enable_pin(struct snd_soc_component *component, |
| 81 | const char *pin) |
| 82 | { |
| 83 | struct snd_soc_dapm_context *dapm = |
| 84 | snd_soc_component_get_dapm(component); |
| 85 | char *full_name; |
| 86 | int ret; |
| 87 | |
| 88 | if (!component->name_prefix) |
| 89 | return snd_soc_dapm_enable_pin(dapm, pin); |
| 90 | |
| 91 | full_name = kasprintf(GFP_KERNEL, "%s %s", component->name_prefix, pin); |
| 92 | if (!full_name) |
| 93 | return -ENOMEM; |
| 94 | |
| 95 | ret = snd_soc_dapm_enable_pin(dapm, full_name); |
| 96 | kfree(full_name); |
| 97 | |
| 98 | return ret; |
| 99 | } |
| 100 | EXPORT_SYMBOL_GPL(snd_soc_component_enable_pin); |
| 101 | |
| 102 | int snd_soc_component_enable_pin_unlocked(struct snd_soc_component *component, |
| 103 | const char *pin) |
| 104 | { |
| 105 | struct snd_soc_dapm_context *dapm = |
| 106 | snd_soc_component_get_dapm(component); |
| 107 | char *full_name; |
| 108 | int ret; |
| 109 | |
| 110 | if (!component->name_prefix) |
| 111 | return snd_soc_dapm_enable_pin_unlocked(dapm, pin); |
| 112 | |
| 113 | full_name = kasprintf(GFP_KERNEL, "%s %s", component->name_prefix, pin); |
| 114 | if (!full_name) |
| 115 | return -ENOMEM; |
| 116 | |
| 117 | ret = snd_soc_dapm_enable_pin_unlocked(dapm, full_name); |
| 118 | kfree(full_name); |
| 119 | |
| 120 | return ret; |
| 121 | } |
| 122 | EXPORT_SYMBOL_GPL(snd_soc_component_enable_pin_unlocked); |
| 123 | |
| 124 | int snd_soc_component_disable_pin(struct snd_soc_component *component, |
| 125 | const char *pin) |
| 126 | { |
| 127 | struct snd_soc_dapm_context *dapm = |
| 128 | snd_soc_component_get_dapm(component); |
| 129 | char *full_name; |
| 130 | int ret; |
| 131 | |
| 132 | if (!component->name_prefix) |
| 133 | return snd_soc_dapm_disable_pin(dapm, pin); |
| 134 | |
| 135 | full_name = kasprintf(GFP_KERNEL, "%s %s", component->name_prefix, pin); |
| 136 | if (!full_name) |
| 137 | return -ENOMEM; |
| 138 | |
| 139 | ret = snd_soc_dapm_disable_pin(dapm, full_name); |
| 140 | kfree(full_name); |
| 141 | |
| 142 | return ret; |
| 143 | } |
| 144 | EXPORT_SYMBOL_GPL(snd_soc_component_disable_pin); |
| 145 | |
| 146 | int snd_soc_component_disable_pin_unlocked(struct snd_soc_component *component, |
| 147 | const char *pin) |
| 148 | { |
| 149 | struct snd_soc_dapm_context *dapm = |
| 150 | snd_soc_component_get_dapm(component); |
| 151 | char *full_name; |
| 152 | int ret; |
| 153 | |
| 154 | if (!component->name_prefix) |
| 155 | return snd_soc_dapm_disable_pin_unlocked(dapm, pin); |
| 156 | |
| 157 | full_name = kasprintf(GFP_KERNEL, "%s %s", component->name_prefix, pin); |
| 158 | if (!full_name) |
| 159 | return -ENOMEM; |
| 160 | |
| 161 | ret = snd_soc_dapm_disable_pin_unlocked(dapm, full_name); |
| 162 | kfree(full_name); |
| 163 | |
| 164 | return ret; |
| 165 | } |
| 166 | EXPORT_SYMBOL_GPL(snd_soc_component_disable_pin_unlocked); |
| 167 | |
| 168 | int snd_soc_component_nc_pin(struct snd_soc_component *component, |
| 169 | const char *pin) |
| 170 | { |
| 171 | struct snd_soc_dapm_context *dapm = |
| 172 | snd_soc_component_get_dapm(component); |
| 173 | char *full_name; |
| 174 | int ret; |
| 175 | |
| 176 | if (!component->name_prefix) |
| 177 | return snd_soc_dapm_nc_pin(dapm, pin); |
| 178 | |
| 179 | full_name = kasprintf(GFP_KERNEL, "%s %s", component->name_prefix, pin); |
| 180 | if (!full_name) |
| 181 | return -ENOMEM; |
| 182 | |
| 183 | ret = snd_soc_dapm_nc_pin(dapm, full_name); |
| 184 | kfree(full_name); |
| 185 | |
| 186 | return ret; |
| 187 | } |
| 188 | EXPORT_SYMBOL_GPL(snd_soc_component_nc_pin); |
| 189 | |
| 190 | int snd_soc_component_nc_pin_unlocked(struct snd_soc_component *component, |
| 191 | const char *pin) |
| 192 | { |
| 193 | struct snd_soc_dapm_context *dapm = |
| 194 | snd_soc_component_get_dapm(component); |
| 195 | char *full_name; |
| 196 | int ret; |
| 197 | |
| 198 | if (!component->name_prefix) |
| 199 | return snd_soc_dapm_nc_pin_unlocked(dapm, pin); |
| 200 | |
| 201 | full_name = kasprintf(GFP_KERNEL, "%s %s", component->name_prefix, pin); |
| 202 | if (!full_name) |
| 203 | return -ENOMEM; |
| 204 | |
| 205 | ret = snd_soc_dapm_nc_pin_unlocked(dapm, full_name); |
| 206 | kfree(full_name); |
| 207 | |
| 208 | return ret; |
| 209 | } |
| 210 | EXPORT_SYMBOL_GPL(snd_soc_component_nc_pin_unlocked); |
| 211 | |
| 212 | int snd_soc_component_get_pin_status(struct snd_soc_component *component, |
| 213 | const char *pin) |
| 214 | { |
| 215 | struct snd_soc_dapm_context *dapm = |
| 216 | snd_soc_component_get_dapm(component); |
| 217 | char *full_name; |
| 218 | int ret; |
| 219 | |
| 220 | if (!component->name_prefix) |
| 221 | return snd_soc_dapm_get_pin_status(dapm, pin); |
| 222 | |
| 223 | full_name = kasprintf(GFP_KERNEL, "%s %s", component->name_prefix, pin); |
| 224 | if (!full_name) |
| 225 | return -ENOMEM; |
| 226 | |
| 227 | ret = snd_soc_dapm_get_pin_status(dapm, full_name); |
| 228 | kfree(full_name); |
| 229 | |
| 230 | return ret; |
| 231 | } |
| 232 | EXPORT_SYMBOL_GPL(snd_soc_component_get_pin_status); |
| 233 | |
| 234 | int snd_soc_component_force_enable_pin(struct snd_soc_component *component, |
| 235 | const char *pin) |
| 236 | { |
| 237 | struct snd_soc_dapm_context *dapm = |
| 238 | snd_soc_component_get_dapm(component); |
| 239 | char *full_name; |
| 240 | int ret; |
| 241 | |
| 242 | if (!component->name_prefix) |
| 243 | return snd_soc_dapm_force_enable_pin(dapm, pin); |
| 244 | |
| 245 | full_name = kasprintf(GFP_KERNEL, "%s %s", component->name_prefix, pin); |
| 246 | if (!full_name) |
| 247 | return -ENOMEM; |
| 248 | |
| 249 | ret = snd_soc_dapm_force_enable_pin(dapm, full_name); |
| 250 | kfree(full_name); |
| 251 | |
| 252 | return ret; |
| 253 | } |
| 254 | EXPORT_SYMBOL_GPL(snd_soc_component_force_enable_pin); |
| 255 | |
| 256 | int snd_soc_component_force_enable_pin_unlocked( |
| 257 | struct snd_soc_component *component, |
| 258 | const char *pin) |
| 259 | { |
| 260 | struct snd_soc_dapm_context *dapm = |
| 261 | snd_soc_component_get_dapm(component); |
| 262 | char *full_name; |
| 263 | int ret; |
| 264 | |
| 265 | if (!component->name_prefix) |
| 266 | return snd_soc_dapm_force_enable_pin_unlocked(dapm, pin); |
| 267 | |
| 268 | full_name = kasprintf(GFP_KERNEL, "%s %s", component->name_prefix, pin); |
| 269 | if (!full_name) |
| 270 | return -ENOMEM; |
| 271 | |
| 272 | ret = snd_soc_dapm_force_enable_pin_unlocked(dapm, full_name); |
| 273 | kfree(full_name); |
| 274 | |
| 275 | return ret; |
| 276 | } |
| 277 | EXPORT_SYMBOL_GPL(snd_soc_component_force_enable_pin_unlocked); |
| 278 | |
| 279 | /** |
| 280 | * snd_soc_component_set_jack - configure component jack. |
| 281 | * @component: COMPONENTs |
| 282 | * @jack: structure to use for the jack |
| 283 | * @data: can be used if codec driver need extra data for configuring jack |
| 284 | * |
| 285 | * Configures and enables jack detection function. |
| 286 | */ |
| 287 | int snd_soc_component_set_jack(struct snd_soc_component *component, |
| 288 | struct snd_soc_jack *jack, void *data) |
| 289 | { |
| 290 | if (component->driver->set_jack) |
| 291 | return component->driver->set_jack(component, jack, data); |
| 292 | |
| 293 | return -ENOTSUPP; |
| 294 | } |
| 295 | EXPORT_SYMBOL_GPL(snd_soc_component_set_jack); |
Kuninori Morimoto | 4a81e8f | 2019-07-26 13:49:54 +0900 | [diff] [blame] | 296 | |
| 297 | int snd_soc_component_module_get(struct snd_soc_component *component, |
| 298 | int upon_open) |
| 299 | { |
| 300 | if (component->driver->module_get_upon_open == !!upon_open && |
| 301 | !try_module_get(component->dev->driver->owner)) |
| 302 | return -ENODEV; |
| 303 | |
| 304 | return 0; |
| 305 | } |
| 306 | |
| 307 | void snd_soc_component_module_put(struct snd_soc_component *component, |
| 308 | int upon_open) |
| 309 | { |
| 310 | if (component->driver->module_get_upon_open == !!upon_open) |
| 311 | module_put(component->dev->driver->owner); |
| 312 | } |
Kuninori Morimoto | ae2f484 | 2019-07-26 13:50:01 +0900 | [diff] [blame] | 313 | |
| 314 | int snd_soc_component_open(struct snd_soc_component *component, |
| 315 | struct snd_pcm_substream *substream) |
| 316 | { |
Kuninori Morimoto | e2cb4a1 | 2019-10-02 14:30:48 +0900 | [diff] [blame] | 317 | if (component->driver->open) |
| 318 | return component->driver->open(component, substream); |
Kuninori Morimoto | ae2f484 | 2019-07-26 13:50:01 +0900 | [diff] [blame] | 319 | return 0; |
| 320 | } |
Kuninori Morimoto | 3672beb | 2019-07-26 13:50:07 +0900 | [diff] [blame] | 321 | |
| 322 | int snd_soc_component_close(struct snd_soc_component *component, |
| 323 | struct snd_pcm_substream *substream) |
| 324 | { |
Kuninori Morimoto | e2cb4a1 | 2019-10-02 14:30:48 +0900 | [diff] [blame] | 325 | if (component->driver->close) |
| 326 | return component->driver->close(component, substream); |
Kuninori Morimoto | 3672beb | 2019-07-26 13:50:07 +0900 | [diff] [blame] | 327 | return 0; |
| 328 | } |
Kuninori Morimoto | 6d53723 | 2019-07-26 13:50:13 +0900 | [diff] [blame] | 329 | |
| 330 | int snd_soc_component_prepare(struct snd_soc_component *component, |
| 331 | struct snd_pcm_substream *substream) |
| 332 | { |
Kuninori Morimoto | e2cb4a1 | 2019-10-02 14:30:48 +0900 | [diff] [blame] | 333 | if (component->driver->prepare) |
| 334 | return component->driver->prepare(component, substream); |
Kuninori Morimoto | 6d53723 | 2019-07-26 13:50:13 +0900 | [diff] [blame] | 335 | return 0; |
| 336 | } |
Kuninori Morimoto | 245c539 | 2019-07-26 13:50:19 +0900 | [diff] [blame] | 337 | |
| 338 | int snd_soc_component_hw_params(struct snd_soc_component *component, |
| 339 | struct snd_pcm_substream *substream, |
| 340 | struct snd_pcm_hw_params *params) |
| 341 | { |
Kuninori Morimoto | e2cb4a1 | 2019-10-02 14:30:48 +0900 | [diff] [blame] | 342 | if (component->driver->hw_params) |
| 343 | return component->driver->hw_params(component, |
| 344 | substream, params); |
Kuninori Morimoto | 245c539 | 2019-07-26 13:50:19 +0900 | [diff] [blame] | 345 | return 0; |
| 346 | } |
Kuninori Morimoto | eae7136 | 2019-07-26 13:50:24 +0900 | [diff] [blame] | 347 | |
| 348 | int snd_soc_component_hw_free(struct snd_soc_component *component, |
| 349 | struct snd_pcm_substream *substream) |
| 350 | { |
Kuninori Morimoto | e2cb4a1 | 2019-10-02 14:30:48 +0900 | [diff] [blame] | 351 | if (component->driver->hw_free) |
| 352 | return component->driver->hw_free(component, substream); |
Kuninori Morimoto | eae7136 | 2019-07-26 13:50:24 +0900 | [diff] [blame] | 353 | return 0; |
| 354 | } |
Kuninori Morimoto | 5693d50 | 2019-07-26 13:50:29 +0900 | [diff] [blame] | 355 | |
| 356 | int snd_soc_component_trigger(struct snd_soc_component *component, |
| 357 | struct snd_pcm_substream *substream, |
| 358 | int cmd) |
| 359 | { |
Kuninori Morimoto | e2cb4a1 | 2019-10-02 14:30:48 +0900 | [diff] [blame] | 360 | if (component->driver->trigger) |
| 361 | return component->driver->trigger(component, substream, cmd); |
Kuninori Morimoto | 5693d50 | 2019-07-26 13:50:29 +0900 | [diff] [blame] | 362 | return 0; |
| 363 | } |
Kuninori Morimoto | 66c5157 | 2019-07-26 13:50:34 +0900 | [diff] [blame] | 364 | |
| 365 | void snd_soc_component_suspend(struct snd_soc_component *component) |
| 366 | { |
| 367 | if (component->driver->suspend) |
| 368 | component->driver->suspend(component); |
| 369 | component->suspended = 1; |
| 370 | } |
Kuninori Morimoto | 9a840cb | 2019-07-26 13:51:08 +0900 | [diff] [blame] | 371 | |
| 372 | void snd_soc_component_resume(struct snd_soc_component *component) |
| 373 | { |
| 374 | if (component->driver->resume) |
| 375 | component->driver->resume(component); |
| 376 | component->suspended = 0; |
| 377 | } |
Kuninori Morimoto | e40fadb | 2019-07-26 13:51:13 +0900 | [diff] [blame] | 378 | |
| 379 | int snd_soc_component_is_suspended(struct snd_soc_component *component) |
| 380 | { |
| 381 | return component->suspended; |
| 382 | } |
Kuninori Morimoto | 08e837d | 2019-07-26 13:51:17 +0900 | [diff] [blame] | 383 | |
| 384 | int snd_soc_component_probe(struct snd_soc_component *component) |
| 385 | { |
| 386 | if (component->driver->probe) |
| 387 | return component->driver->probe(component); |
| 388 | |
| 389 | return 0; |
| 390 | } |
Kuninori Morimoto | 03b34dd | 2019-07-26 13:51:22 +0900 | [diff] [blame] | 391 | |
| 392 | void snd_soc_component_remove(struct snd_soc_component *component) |
| 393 | { |
| 394 | if (component->driver->remove) |
| 395 | component->driver->remove(component); |
| 396 | } |
Kuninori Morimoto | 2c7b170 | 2019-07-26 13:51:26 +0900 | [diff] [blame] | 397 | |
| 398 | int snd_soc_component_of_xlate_dai_id(struct snd_soc_component *component, |
| 399 | struct device_node *ep) |
| 400 | { |
| 401 | if (component->driver->of_xlate_dai_id) |
| 402 | return component->driver->of_xlate_dai_id(component, ep); |
| 403 | |
| 404 | return -ENOTSUPP; |
| 405 | } |
Kuninori Morimoto | a2a3417 | 2019-07-26 13:51:31 +0900 | [diff] [blame] | 406 | |
| 407 | int snd_soc_component_of_xlate_dai_name(struct snd_soc_component *component, |
| 408 | struct of_phandle_args *args, |
| 409 | const char **dai_name) |
| 410 | { |
| 411 | if (component->driver->of_xlate_dai_name) |
| 412 | return component->driver->of_xlate_dai_name(component, |
| 413 | args, dai_name); |
| 414 | return -ENOTSUPP; |
| 415 | } |
Kuninori Morimoto | 0035e25 | 2019-07-26 13:51:47 +0900 | [diff] [blame] | 416 | |
| 417 | int snd_soc_pcm_component_pointer(struct snd_pcm_substream *substream) |
| 418 | { |
| 419 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 420 | struct snd_soc_component *component; |
| 421 | struct snd_soc_rtdcom_list *rtdcom; |
| 422 | |
Kuninori Morimoto | 2b544dd | 2019-10-15 12:59:31 +0900 | [diff] [blame] | 423 | /* FIXME: use 1st pointer */ |
| 424 | for_each_rtd_components(rtd, rtdcom, component) |
Kuninori Morimoto | e2cb4a1 | 2019-10-02 14:30:48 +0900 | [diff] [blame] | 425 | if (component->driver->pointer) |
| 426 | return component->driver->pointer(component, substream); |
Kuninori Morimoto | 0035e25 | 2019-07-26 13:51:47 +0900 | [diff] [blame] | 427 | |
| 428 | return 0; |
| 429 | } |
Kuninori Morimoto | 96a4790 | 2019-07-26 13:51:51 +0900 | [diff] [blame] | 430 | |
| 431 | int snd_soc_pcm_component_ioctl(struct snd_pcm_substream *substream, |
| 432 | unsigned int cmd, void *arg) |
| 433 | { |
| 434 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 435 | struct snd_soc_component *component; |
| 436 | struct snd_soc_rtdcom_list *rtdcom; |
| 437 | |
Kuninori Morimoto | 2b544dd | 2019-10-15 12:59:31 +0900 | [diff] [blame] | 438 | /* FIXME: use 1st ioctl */ |
| 439 | for_each_rtd_components(rtd, rtdcom, component) |
Kuninori Morimoto | e2cb4a1 | 2019-10-02 14:30:48 +0900 | [diff] [blame] | 440 | if (component->driver->ioctl) |
| 441 | return component->driver->ioctl(component, substream, |
| 442 | cmd, arg); |
Kuninori Morimoto | 96a4790 | 2019-07-26 13:51:51 +0900 | [diff] [blame] | 443 | |
| 444 | return snd_pcm_lib_ioctl(substream, cmd, arg); |
| 445 | } |
Kuninori Morimoto | 82d81f5 | 2019-07-26 13:51:56 +0900 | [diff] [blame] | 446 | |
| 447 | int snd_soc_pcm_component_copy_user(struct snd_pcm_substream *substream, |
| 448 | int channel, unsigned long pos, |
| 449 | void __user *buf, unsigned long bytes) |
| 450 | { |
| 451 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 452 | struct snd_soc_rtdcom_list *rtdcom; |
| 453 | struct snd_soc_component *component; |
| 454 | |
Kuninori Morimoto | 2b544dd | 2019-10-15 12:59:31 +0900 | [diff] [blame] | 455 | /* FIXME. it returns 1st copy now */ |
| 456 | for_each_rtd_components(rtd, rtdcom, component) |
Kuninori Morimoto | e2cb4a1 | 2019-10-02 14:30:48 +0900 | [diff] [blame] | 457 | if (component->driver->copy_user) |
| 458 | return component->driver->copy_user( |
| 459 | component, substream, channel, pos, buf, bytes); |
Kuninori Morimoto | 82d81f5 | 2019-07-26 13:51:56 +0900 | [diff] [blame] | 460 | |
| 461 | return -EINVAL; |
| 462 | } |
Kuninori Morimoto | 9c712e4 | 2019-07-26 13:52:00 +0900 | [diff] [blame] | 463 | |
| 464 | struct page *snd_soc_pcm_component_page(struct snd_pcm_substream *substream, |
| 465 | unsigned long offset) |
| 466 | { |
| 467 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 468 | struct snd_soc_rtdcom_list *rtdcom; |
| 469 | struct snd_soc_component *component; |
| 470 | struct page *page; |
| 471 | |
Kuninori Morimoto | 2b544dd | 2019-10-15 12:59:31 +0900 | [diff] [blame] | 472 | /* FIXME. it returns 1st page now */ |
| 473 | for_each_rtd_components(rtd, rtdcom, component) { |
Kuninori Morimoto | e2cb4a1 | 2019-10-02 14:30:48 +0900 | [diff] [blame] | 474 | if (component->driver->page) { |
| 475 | page = component->driver->page(component, |
| 476 | substream, offset); |
| 477 | if (page) |
| 478 | return page; |
| 479 | } |
Kuninori Morimoto | 9c712e4 | 2019-07-26 13:52:00 +0900 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | return NULL; |
| 483 | } |
Kuninori Morimoto | 205875e | 2019-07-26 13:52:04 +0900 | [diff] [blame] | 484 | |
| 485 | int snd_soc_pcm_component_mmap(struct snd_pcm_substream *substream, |
| 486 | struct vm_area_struct *vma) |
| 487 | { |
| 488 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 489 | struct snd_soc_rtdcom_list *rtdcom; |
| 490 | struct snd_soc_component *component; |
| 491 | |
Kuninori Morimoto | 2b544dd | 2019-10-15 12:59:31 +0900 | [diff] [blame] | 492 | /* FIXME. it returns 1st mmap now */ |
| 493 | for_each_rtd_components(rtd, rtdcom, component) |
Kuninori Morimoto | e2cb4a1 | 2019-10-02 14:30:48 +0900 | [diff] [blame] | 494 | if (component->driver->mmap) |
| 495 | return component->driver->mmap(component, |
| 496 | substream, vma); |
Kuninori Morimoto | 205875e | 2019-07-26 13:52:04 +0900 | [diff] [blame] | 497 | |
| 498 | return -EINVAL; |
| 499 | } |
Kuninori Morimoto | 7484291 | 2019-07-26 13:52:08 +0900 | [diff] [blame] | 500 | |
Kuninori Morimoto | b2b2afb | 2019-11-18 10:50:32 +0900 | [diff] [blame] | 501 | int snd_soc_pcm_component_new(struct snd_soc_pcm_runtime *rtd) |
Kuninori Morimoto | 7484291 | 2019-07-26 13:52:08 +0900 | [diff] [blame] | 502 | { |
Kuninori Morimoto | 7484291 | 2019-07-26 13:52:08 +0900 | [diff] [blame] | 503 | struct snd_soc_rtdcom_list *rtdcom; |
| 504 | struct snd_soc_component *component; |
| 505 | int ret; |
| 506 | |
Kuninori Morimoto | 2b544dd | 2019-10-15 12:59:31 +0900 | [diff] [blame] | 507 | for_each_rtd_components(rtd, rtdcom, component) { |
Kuninori Morimoto | c64bfc9 | 2019-10-02 14:30:59 +0900 | [diff] [blame] | 508 | if (component->driver->pcm_construct) { |
| 509 | ret = component->driver->pcm_construct(component, rtd); |
| 510 | if (ret < 0) |
| 511 | return ret; |
| 512 | } |
Kuninori Morimoto | 7484291 | 2019-07-26 13:52:08 +0900 | [diff] [blame] | 513 | } |
| 514 | |
| 515 | return 0; |
| 516 | } |
Kuninori Morimoto | 79776da | 2019-07-26 13:52:12 +0900 | [diff] [blame] | 517 | |
Kuninori Morimoto | b2b2afb | 2019-11-18 10:50:32 +0900 | [diff] [blame] | 518 | void snd_soc_pcm_component_free(struct snd_soc_pcm_runtime *rtd) |
Kuninori Morimoto | 79776da | 2019-07-26 13:52:12 +0900 | [diff] [blame] | 519 | { |
Kuninori Morimoto | 79776da | 2019-07-26 13:52:12 +0900 | [diff] [blame] | 520 | struct snd_soc_rtdcom_list *rtdcom; |
| 521 | struct snd_soc_component *component; |
| 522 | |
Takashi Iwai | 8e3366c | 2020-01-07 08:09:56 +0100 | [diff] [blame^] | 523 | if (!rtd->pcm) |
| 524 | return; |
| 525 | |
Kuninori Morimoto | 2b544dd | 2019-10-15 12:59:31 +0900 | [diff] [blame] | 526 | for_each_rtd_components(rtd, rtdcom, component) |
Kuninori Morimoto | c64bfc9 | 2019-10-02 14:30:59 +0900 | [diff] [blame] | 527 | if (component->driver->pcm_destruct) |
Kuninori Morimoto | b2b2afb | 2019-11-18 10:50:32 +0900 | [diff] [blame] | 528 | component->driver->pcm_destruct(component, rtd->pcm); |
Kuninori Morimoto | 79776da | 2019-07-26 13:52:12 +0900 | [diff] [blame] | 529 | } |