1 // SPDX-License-Identifier: GPL-2.0
5 // Copyright (C) 2019 Renesas Electronics Corp.
6 // Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
8 #include <linux/module.h>
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.
19 * Configures the CODEC master (MCLK) or system (SYSCLK) clocking.
21 int snd_soc_component_set_sysclk(struct snd_soc_component
*component
,
22 int clk_id
, int source
, unsigned int freq
,
25 if (component
->driver
->set_sysclk
)
26 return component
->driver
->set_sysclk(component
, clk_id
, source
,
31 EXPORT_SYMBOL_GPL(snd_soc_component_set_sysclk
);
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
41 * Configures and enables PLL to generate output clock based on input clock.
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
)
47 if (component
->driver
->set_pll
)
48 return component
->driver
->set_pll(component
, pll_id
, source
,
53 EXPORT_SYMBOL_GPL(snd_soc_component_set_pll
);
55 void snd_soc_component_seq_notifier(struct snd_soc_component
*component
,
56 enum snd_soc_dapm_type type
, int subseq
)
58 if (component
->driver
->seq_notifier
)
59 component
->driver
->seq_notifier(component
, type
, subseq
);
62 int snd_soc_component_stream_event(struct snd_soc_component
*component
,
65 if (component
->driver
->stream_event
)
66 return component
->driver
->stream_event(component
, event
);
71 int snd_soc_component_set_bias_level(struct snd_soc_component
*component
,
72 enum snd_soc_bias_level level
)
74 if (component
->driver
->set_bias_level
)
75 return component
->driver
->set_bias_level(component
, level
);
80 int snd_soc_component_enable_pin(struct snd_soc_component
*component
,
83 struct snd_soc_dapm_context
*dapm
=
84 snd_soc_component_get_dapm(component
);
88 if (!component
->name_prefix
)
89 return snd_soc_dapm_enable_pin(dapm
, pin
);
91 full_name
= kasprintf(GFP_KERNEL
, "%s %s", component
->name_prefix
, pin
);
95 ret
= snd_soc_dapm_enable_pin(dapm
, full_name
);
100 EXPORT_SYMBOL_GPL(snd_soc_component_enable_pin
);
102 int snd_soc_component_enable_pin_unlocked(struct snd_soc_component
*component
,
105 struct snd_soc_dapm_context
*dapm
=
106 snd_soc_component_get_dapm(component
);
110 if (!component
->name_prefix
)
111 return snd_soc_dapm_enable_pin_unlocked(dapm
, pin
);
113 full_name
= kasprintf(GFP_KERNEL
, "%s %s", component
->name_prefix
, pin
);
117 ret
= snd_soc_dapm_enable_pin_unlocked(dapm
, full_name
);
122 EXPORT_SYMBOL_GPL(snd_soc_component_enable_pin_unlocked
);
124 int snd_soc_component_disable_pin(struct snd_soc_component
*component
,
127 struct snd_soc_dapm_context
*dapm
=
128 snd_soc_component_get_dapm(component
);
132 if (!component
->name_prefix
)
133 return snd_soc_dapm_disable_pin(dapm
, pin
);
135 full_name
= kasprintf(GFP_KERNEL
, "%s %s", component
->name_prefix
, pin
);
139 ret
= snd_soc_dapm_disable_pin(dapm
, full_name
);
144 EXPORT_SYMBOL_GPL(snd_soc_component_disable_pin
);
146 int snd_soc_component_disable_pin_unlocked(struct snd_soc_component
*component
,
149 struct snd_soc_dapm_context
*dapm
=
150 snd_soc_component_get_dapm(component
);
154 if (!component
->name_prefix
)
155 return snd_soc_dapm_disable_pin_unlocked(dapm
, pin
);
157 full_name
= kasprintf(GFP_KERNEL
, "%s %s", component
->name_prefix
, pin
);
161 ret
= snd_soc_dapm_disable_pin_unlocked(dapm
, full_name
);
166 EXPORT_SYMBOL_GPL(snd_soc_component_disable_pin_unlocked
);
168 int snd_soc_component_nc_pin(struct snd_soc_component
*component
,
171 struct snd_soc_dapm_context
*dapm
=
172 snd_soc_component_get_dapm(component
);
176 if (!component
->name_prefix
)
177 return snd_soc_dapm_nc_pin(dapm
, pin
);
179 full_name
= kasprintf(GFP_KERNEL
, "%s %s", component
->name_prefix
, pin
);
183 ret
= snd_soc_dapm_nc_pin(dapm
, full_name
);
188 EXPORT_SYMBOL_GPL(snd_soc_component_nc_pin
);
190 int snd_soc_component_nc_pin_unlocked(struct snd_soc_component
*component
,
193 struct snd_soc_dapm_context
*dapm
=
194 snd_soc_component_get_dapm(component
);
198 if (!component
->name_prefix
)
199 return snd_soc_dapm_nc_pin_unlocked(dapm
, pin
);
201 full_name
= kasprintf(GFP_KERNEL
, "%s %s", component
->name_prefix
, pin
);
205 ret
= snd_soc_dapm_nc_pin_unlocked(dapm
, full_name
);
210 EXPORT_SYMBOL_GPL(snd_soc_component_nc_pin_unlocked
);
212 int snd_soc_component_get_pin_status(struct snd_soc_component
*component
,
215 struct snd_soc_dapm_context
*dapm
=
216 snd_soc_component_get_dapm(component
);
220 if (!component
->name_prefix
)
221 return snd_soc_dapm_get_pin_status(dapm
, pin
);
223 full_name
= kasprintf(GFP_KERNEL
, "%s %s", component
->name_prefix
, pin
);
227 ret
= snd_soc_dapm_get_pin_status(dapm
, full_name
);
232 EXPORT_SYMBOL_GPL(snd_soc_component_get_pin_status
);
234 int snd_soc_component_force_enable_pin(struct snd_soc_component
*component
,
237 struct snd_soc_dapm_context
*dapm
=
238 snd_soc_component_get_dapm(component
);
242 if (!component
->name_prefix
)
243 return snd_soc_dapm_force_enable_pin(dapm
, pin
);
245 full_name
= kasprintf(GFP_KERNEL
, "%s %s", component
->name_prefix
, pin
);
249 ret
= snd_soc_dapm_force_enable_pin(dapm
, full_name
);
254 EXPORT_SYMBOL_GPL(snd_soc_component_force_enable_pin
);
256 int snd_soc_component_force_enable_pin_unlocked(
257 struct snd_soc_component
*component
,
260 struct snd_soc_dapm_context
*dapm
=
261 snd_soc_component_get_dapm(component
);
265 if (!component
->name_prefix
)
266 return snd_soc_dapm_force_enable_pin_unlocked(dapm
, pin
);
268 full_name
= kasprintf(GFP_KERNEL
, "%s %s", component
->name_prefix
, pin
);
272 ret
= snd_soc_dapm_force_enable_pin_unlocked(dapm
, full_name
);
277 EXPORT_SYMBOL_GPL(snd_soc_component_force_enable_pin_unlocked
);
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
285 * Configures and enables jack detection function.
287 int snd_soc_component_set_jack(struct snd_soc_component
*component
,
288 struct snd_soc_jack
*jack
, void *data
)
290 if (component
->driver
->set_jack
)
291 return component
->driver
->set_jack(component
, jack
, data
);
295 EXPORT_SYMBOL_GPL(snd_soc_component_set_jack
);
297 int snd_soc_component_module_get(struct snd_soc_component
*component
,
300 if (component
->driver
->module_get_upon_open
== !!upon_open
&&
301 !try_module_get(component
->dev
->driver
->owner
))
307 void snd_soc_component_module_put(struct snd_soc_component
*component
,
310 if (component
->driver
->module_get_upon_open
== !!upon_open
)
311 module_put(component
->dev
->driver
->owner
);
314 int snd_soc_component_open(struct snd_soc_component
*component
,
315 struct snd_pcm_substream
*substream
)
317 if (component
->driver
->open
)
318 return component
->driver
->open(component
, substream
);
322 int snd_soc_component_close(struct snd_soc_component
*component
,
323 struct snd_pcm_substream
*substream
)
325 if (component
->driver
->close
)
326 return component
->driver
->close(component
, substream
);
330 int snd_soc_component_prepare(struct snd_soc_component
*component
,
331 struct snd_pcm_substream
*substream
)
333 if (component
->driver
->prepare
)
334 return component
->driver
->prepare(component
, substream
);
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
)
342 if (component
->driver
->hw_params
)
343 return component
->driver
->hw_params(component
,
348 int snd_soc_component_hw_free(struct snd_soc_component
*component
,
349 struct snd_pcm_substream
*substream
)
351 if (component
->driver
->hw_free
)
352 return component
->driver
->hw_free(component
, substream
);
356 int snd_soc_component_trigger(struct snd_soc_component
*component
,
357 struct snd_pcm_substream
*substream
,
360 if (component
->driver
->trigger
)
361 return component
->driver
->trigger(component
, substream
, cmd
);
365 void snd_soc_component_suspend(struct snd_soc_component
*component
)
367 if (component
->driver
->suspend
)
368 component
->driver
->suspend(component
);
369 component
->suspended
= 1;
372 void snd_soc_component_resume(struct snd_soc_component
*component
)
374 if (component
->driver
->resume
)
375 component
->driver
->resume(component
);
376 component
->suspended
= 0;
379 int snd_soc_component_is_suspended(struct snd_soc_component
*component
)
381 return component
->suspended
;
384 int snd_soc_component_probe(struct snd_soc_component
*component
)
386 if (component
->driver
->probe
)
387 return component
->driver
->probe(component
);
392 void snd_soc_component_remove(struct snd_soc_component
*component
)
394 if (component
->driver
->remove
)
395 component
->driver
->remove(component
);
398 int snd_soc_component_of_xlate_dai_id(struct snd_soc_component
*component
,
399 struct device_node
*ep
)
401 if (component
->driver
->of_xlate_dai_id
)
402 return component
->driver
->of_xlate_dai_id(component
, ep
);
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
)
411 if (component
->driver
->of_xlate_dai_name
)
412 return component
->driver
->of_xlate_dai_name(component
,
417 int snd_soc_pcm_component_pointer(struct snd_pcm_substream
*substream
)
419 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
420 struct snd_soc_component
*component
;
423 /* FIXME: use 1st pointer */
424 for_each_rtd_components(rtd
, i
, component
)
425 if (component
->driver
->pointer
)
426 return component
->driver
->pointer(component
, substream
);
431 int snd_soc_pcm_component_ioctl(struct snd_pcm_substream
*substream
,
432 unsigned int cmd
, void *arg
)
434 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
435 struct snd_soc_component
*component
;
438 /* FIXME: use 1st ioctl */
439 for_each_rtd_components(rtd
, i
, component
)
440 if (component
->driver
->ioctl
)
441 return component
->driver
->ioctl(component
, substream
,
444 return snd_pcm_lib_ioctl(substream
, cmd
, arg
);
447 int snd_soc_pcm_component_sync_stop(struct snd_pcm_substream
*substream
)
449 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
450 struct snd_soc_component
*component
;
453 for_each_rtd_components(rtd
, i
, component
) {
454 if (component
->driver
->ioctl
) {
455 ret
= component
->driver
->sync_stop(component
,
465 int snd_soc_pcm_component_copy_user(struct snd_pcm_substream
*substream
,
466 int channel
, unsigned long pos
,
467 void __user
*buf
, unsigned long bytes
)
469 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
470 struct snd_soc_component
*component
;
473 /* FIXME. it returns 1st copy now */
474 for_each_rtd_components(rtd
, i
, component
)
475 if (component
->driver
->copy_user
)
476 return component
->driver
->copy_user(
477 component
, substream
, channel
, pos
, buf
, bytes
);
482 struct page
*snd_soc_pcm_component_page(struct snd_pcm_substream
*substream
,
483 unsigned long offset
)
485 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
486 struct snd_soc_component
*component
;
490 /* FIXME. it returns 1st page now */
491 for_each_rtd_components(rtd
, i
, component
) {
492 if (component
->driver
->page
) {
493 page
= component
->driver
->page(component
,
503 int snd_soc_pcm_component_mmap(struct snd_pcm_substream
*substream
,
504 struct vm_area_struct
*vma
)
506 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
507 struct snd_soc_component
*component
;
510 /* FIXME. it returns 1st mmap now */
511 for_each_rtd_components(rtd
, i
, component
)
512 if (component
->driver
->mmap
)
513 return component
->driver
->mmap(component
,
519 int snd_soc_pcm_component_new(struct snd_soc_pcm_runtime
*rtd
)
521 struct snd_soc_component
*component
;
525 for_each_rtd_components(rtd
, i
, component
) {
526 if (component
->driver
->pcm_construct
) {
527 ret
= component
->driver
->pcm_construct(component
, rtd
);
536 void snd_soc_pcm_component_free(struct snd_soc_pcm_runtime
*rtd
)
538 struct snd_soc_component
*component
;
544 for_each_rtd_components(rtd
, i
, component
)
545 if (component
->driver
->pcm_destruct
)
546 component
->driver
->pcm_destruct(component
, rtd
->pcm
);