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->ops &&
318 component->driver->ops->open)
319 return component->driver->ops->open(substream);
324 int snd_soc_component_close(struct snd_soc_component *component,
325 struct snd_pcm_substream *substream)
327 if (component->driver->ops &&
328 component->driver->ops->close)
329 return component->driver->ops->close(substream);
334 int snd_soc_component_prepare(struct snd_soc_component *component,
335 struct snd_pcm_substream *substream)
337 if (component->driver->ops &&
338 component->driver->ops->prepare)
339 return component->driver->ops->prepare(substream);
344 int snd_soc_component_hw_params(struct snd_soc_component *component,
345 struct snd_pcm_substream *substream,
346 struct snd_pcm_hw_params *params)
348 if (component->driver->ops &&
349 component->driver->ops->hw_params)
350 return component->driver->ops->hw_params(substream, params);
355 int snd_soc_component_hw_free(struct snd_soc_component *component,
356 struct snd_pcm_substream *substream)
358 if (component->driver->ops &&
359 component->driver->ops->hw_free)
360 return component->driver->ops->hw_free(substream);
365 int snd_soc_component_trigger(struct snd_soc_component *component,
366 struct snd_pcm_substream *substream,
369 if (component->driver->ops &&
370 component->driver->ops->trigger)
371 return component->driver->ops->trigger(substream, cmd);
376 void snd_soc_component_suspend(struct snd_soc_component *component)
378 if (component->driver->suspend)
379 component->driver->suspend(component);
380 component->suspended = 1;
383 void snd_soc_component_resume(struct snd_soc_component *component)
385 if (component->driver->resume)
386 component->driver->resume(component);
387 component->suspended = 0;
390 int snd_soc_component_is_suspended(struct snd_soc_component *component)
392 return component->suspended;
395 int snd_soc_component_probe(struct snd_soc_component *component)
397 if (component->driver->probe)
398 return component->driver->probe(component);
403 void snd_soc_component_remove(struct snd_soc_component *component)
405 if (component->driver->remove)
406 component->driver->remove(component);
409 int snd_soc_component_of_xlate_dai_id(struct snd_soc_component *component,
410 struct device_node *ep)
412 if (component->driver->of_xlate_dai_id)
413 return component->driver->of_xlate_dai_id(component, ep);
418 int snd_soc_component_of_xlate_dai_name(struct snd_soc_component *component,
419 struct of_phandle_args *args,
420 const char **dai_name)
422 if (component->driver->of_xlate_dai_name)
423 return component->driver->of_xlate_dai_name(component,
428 int snd_soc_pcm_component_pointer(struct snd_pcm_substream *substream)
430 struct snd_soc_pcm_runtime *rtd = substream->private_data;
431 struct snd_soc_component *component;
432 struct snd_soc_rtdcom_list *rtdcom;
434 for_each_rtdcom(rtd, rtdcom) {
435 component = rtdcom->component;
437 /* FIXME: use 1st pointer */
438 if (component->driver->ops &&
439 component->driver->ops->pointer)
440 return component->driver->ops->pointer(substream);
446 int snd_soc_pcm_component_ioctl(struct snd_pcm_substream *substream,
447 unsigned int cmd, void *arg)
449 struct snd_soc_pcm_runtime *rtd = substream->private_data;
450 struct snd_soc_component *component;
451 struct snd_soc_rtdcom_list *rtdcom;
453 for_each_rtdcom(rtd, rtdcom) {
454 component = rtdcom->component;
456 /* FIXME: use 1st ioctl */
457 if (component->driver->ops &&
458 component->driver->ops->ioctl)
459 return component->driver->ops->ioctl(substream,
463 return snd_pcm_lib_ioctl(substream, cmd, arg);
466 int snd_soc_pcm_component_copy_user(struct snd_pcm_substream *substream,
467 int channel, unsigned long pos,
468 void __user *buf, unsigned long bytes)
470 struct snd_soc_pcm_runtime *rtd = substream->private_data;
471 struct snd_soc_rtdcom_list *rtdcom;
472 struct snd_soc_component *component;
474 for_each_rtdcom(rtd, rtdcom) {
475 component = rtdcom->component;
477 /* FIXME. it returns 1st copy now */
478 if (component->driver->ops &&
479 component->driver->ops->copy_user)
480 return component->driver->ops->copy_user(
481 substream, channel, pos, buf, bytes);
487 struct page *snd_soc_pcm_component_page(struct snd_pcm_substream *substream,
488 unsigned long offset)
490 struct snd_soc_pcm_runtime *rtd = substream->private_data;
491 struct snd_soc_rtdcom_list *rtdcom;
492 struct snd_soc_component *component;
495 for_each_rtdcom(rtd, rtdcom) {
496 component = rtdcom->component;
498 /* FIXME. it returns 1st page now */
499 if (component->driver->ops &&
500 component->driver->ops->page) {
501 page = component->driver->ops->page(substream, offset);
510 int snd_soc_pcm_component_mmap(struct snd_pcm_substream *substream,
511 struct vm_area_struct *vma)
513 struct snd_soc_pcm_runtime *rtd = substream->private_data;
514 struct snd_soc_rtdcom_list *rtdcom;
515 struct snd_soc_component *component;
517 for_each_rtdcom(rtd, rtdcom) {
518 component = rtdcom->component;
520 /* FIXME. it returns 1st mmap now */
521 if (component->driver->ops &&
522 component->driver->ops->mmap)
523 return component->driver->ops->mmap(substream, vma);
529 int snd_soc_pcm_component_new(struct snd_pcm *pcm)
531 struct snd_soc_pcm_runtime *rtd = pcm->private_data;
532 struct snd_soc_rtdcom_list *rtdcom;
533 struct snd_soc_component *component;
536 for_each_rtdcom(rtd, rtdcom) {
537 component = rtdcom->component;
539 if (component->driver->pcm_new) {
540 ret = component->driver->pcm_new(rtd);
549 void snd_soc_pcm_component_free(struct snd_pcm *pcm)
551 struct snd_soc_pcm_runtime *rtd = pcm->private_data;
552 struct snd_soc_rtdcom_list *rtdcom;
553 struct snd_soc_component *component;
555 for_each_rtdcom(rtd, rtdcom) {
556 component = rtdcom->component;
558 if (component->driver->pcm_free)
559 component->driver->pcm_free(pcm);