d121f5f7633c6aacb73037de7f8a80f631961084
[linux-2.6-microblaze.git] / sound / soc / soc-component.c
1 // SPDX-License-Identifier: GPL-2.0
2 //
3 // soc-component.c
4 //
5 // Copyright 2009-2011 Wolfson Microelectronics PLC.
6 // Copyright (C) 2019 Renesas Electronics Corp.
7 //
8 // Mark Brown <broonie@opensource.wolfsonmicro.com>
9 // Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
10 //
11 #include <linux/module.h>
12 #include <sound/soc.h>
13
14 #define soc_component_ret(dai, ret) _soc_component_ret(dai, __func__, ret)
15 static inline int _soc_component_ret(struct snd_soc_component *component,
16                                      const char *func, int ret)
17 {
18         /* Positive/Zero values are not errors */
19         if (ret >= 0)
20                 return ret;
21
22         /* Negative values might be errors */
23         switch (ret) {
24         case -EPROBE_DEFER:
25         case -ENOTSUPP:
26                 break;
27         default:
28                 dev_err(component->dev,
29                         "ASoC: error at %s on %s: %d\n",
30                         func, component->name, ret);
31         }
32
33         return ret;
34 }
35
36 int snd_soc_component_initialize(struct snd_soc_component *component,
37                                  const struct snd_soc_component_driver *driver,
38                                  struct device *dev, const char *name)
39 {
40         INIT_LIST_HEAD(&component->dai_list);
41         INIT_LIST_HEAD(&component->dobj_list);
42         INIT_LIST_HEAD(&component->card_list);
43         mutex_init(&component->io_mutex);
44
45         component->name         = name;
46         component->dev          = dev;
47         component->driver       = driver;
48
49         return 0;
50 }
51
52 void snd_soc_component_set_aux(struct snd_soc_component *component,
53                                struct snd_soc_aux_dev *aux)
54 {
55         component->init = (aux) ? aux->init : NULL;
56 }
57
58 int snd_soc_component_init(struct snd_soc_component *component)
59 {
60         int ret = 0;
61
62         if (component->init)
63                 ret = component->init(component);
64
65         return soc_component_ret(component, ret);
66 }
67
68 /**
69  * snd_soc_component_set_sysclk - configure COMPONENT system or master clock.
70  * @component: COMPONENT
71  * @clk_id: DAI specific clock ID
72  * @source: Source for the clock
73  * @freq: new clock frequency in Hz
74  * @dir: new clock direction - input/output.
75  *
76  * Configures the CODEC master (MCLK) or system (SYSCLK) clocking.
77  */
78 int snd_soc_component_set_sysclk(struct snd_soc_component *component,
79                                  int clk_id, int source, unsigned int freq,
80                                  int dir)
81 {
82         int ret = -ENOTSUPP;
83
84         if (component->driver->set_sysclk)
85                 ret = component->driver->set_sysclk(component, clk_id, source,
86                                                      freq, dir);
87
88         return soc_component_ret(component, ret);
89 }
90 EXPORT_SYMBOL_GPL(snd_soc_component_set_sysclk);
91
92 /*
93  * snd_soc_component_set_pll - configure component PLL.
94  * @component: COMPONENT
95  * @pll_id: DAI specific PLL ID
96  * @source: DAI specific source for the PLL
97  * @freq_in: PLL input clock frequency in Hz
98  * @freq_out: requested PLL output clock frequency in Hz
99  *
100  * Configures and enables PLL to generate output clock based on input clock.
101  */
102 int snd_soc_component_set_pll(struct snd_soc_component *component, int pll_id,
103                               int source, unsigned int freq_in,
104                               unsigned int freq_out)
105 {
106         int ret = -EINVAL;
107
108         if (component->driver->set_pll)
109                 ret = component->driver->set_pll(component, pll_id, source,
110                                                   freq_in, freq_out);
111
112         return soc_component_ret(component, ret);
113 }
114 EXPORT_SYMBOL_GPL(snd_soc_component_set_pll);
115
116 void snd_soc_component_seq_notifier(struct snd_soc_component *component,
117                                     enum snd_soc_dapm_type type, int subseq)
118 {
119         if (component->driver->seq_notifier)
120                 component->driver->seq_notifier(component, type, subseq);
121 }
122
123 int snd_soc_component_stream_event(struct snd_soc_component *component,
124                                    int event)
125 {
126         int ret = 0;
127
128         if (component->driver->stream_event)
129                 ret = component->driver->stream_event(component, event);
130
131         return soc_component_ret(component, ret);
132 }
133
134 int snd_soc_component_set_bias_level(struct snd_soc_component *component,
135                                      enum snd_soc_bias_level level)
136 {
137         int ret = 0;
138
139         if (component->driver->set_bias_level)
140                 ret = component->driver->set_bias_level(component, level);
141
142         return soc_component_ret(component, ret);
143 }
144
145 static int soc_component_pin(struct snd_soc_component *component,
146                              const char *pin,
147                              int (*pin_func)(struct snd_soc_dapm_context *dapm,
148                                              const char *pin))
149 {
150         struct snd_soc_dapm_context *dapm =
151                 snd_soc_component_get_dapm(component);
152         char *full_name;
153         int ret;
154
155         if (!component->name_prefix) {
156                 ret = pin_func(dapm, pin);
157                 goto end;
158         }
159
160         full_name = kasprintf(GFP_KERNEL, "%s %s", component->name_prefix, pin);
161         if (!full_name) {
162                 ret = -ENOMEM;
163                 goto end;
164         }
165
166         ret = pin_func(dapm, full_name);
167         kfree(full_name);
168 end:
169         return soc_component_ret(component, ret);
170 }
171
172 int snd_soc_component_enable_pin(struct snd_soc_component *component,
173                                  const char *pin)
174 {
175         return soc_component_pin(component, pin, snd_soc_dapm_enable_pin);
176 }
177 EXPORT_SYMBOL_GPL(snd_soc_component_enable_pin);
178
179 int snd_soc_component_enable_pin_unlocked(struct snd_soc_component *component,
180                                           const char *pin)
181 {
182         return soc_component_pin(component, pin, snd_soc_dapm_enable_pin_unlocked);
183 }
184 EXPORT_SYMBOL_GPL(snd_soc_component_enable_pin_unlocked);
185
186 int snd_soc_component_disable_pin(struct snd_soc_component *component,
187                                   const char *pin)
188 {
189         return soc_component_pin(component, pin, snd_soc_dapm_disable_pin);
190 }
191 EXPORT_SYMBOL_GPL(snd_soc_component_disable_pin);
192
193 int snd_soc_component_disable_pin_unlocked(struct snd_soc_component *component,
194                                            const char *pin)
195 {
196         return soc_component_pin(component, pin, snd_soc_dapm_disable_pin_unlocked);
197 }
198 EXPORT_SYMBOL_GPL(snd_soc_component_disable_pin_unlocked);
199
200 int snd_soc_component_nc_pin(struct snd_soc_component *component,
201                              const char *pin)
202 {
203         return soc_component_pin(component, pin, snd_soc_dapm_nc_pin);
204 }
205 EXPORT_SYMBOL_GPL(snd_soc_component_nc_pin);
206
207 int snd_soc_component_nc_pin_unlocked(struct snd_soc_component *component,
208                                       const char *pin)
209 {
210         return soc_component_pin(component, pin, snd_soc_dapm_nc_pin_unlocked);
211 }
212 EXPORT_SYMBOL_GPL(snd_soc_component_nc_pin_unlocked);
213
214 int snd_soc_component_get_pin_status(struct snd_soc_component *component,
215                                      const char *pin)
216 {
217         return soc_component_pin(component, pin, snd_soc_dapm_get_pin_status);
218 }
219 EXPORT_SYMBOL_GPL(snd_soc_component_get_pin_status);
220
221 int snd_soc_component_force_enable_pin(struct snd_soc_component *component,
222                                        const char *pin)
223 {
224         return soc_component_pin(component, pin, snd_soc_dapm_force_enable_pin);
225 }
226 EXPORT_SYMBOL_GPL(snd_soc_component_force_enable_pin);
227
228 int snd_soc_component_force_enable_pin_unlocked(
229         struct snd_soc_component *component,
230         const char *pin)
231 {
232         return soc_component_pin(component, pin, snd_soc_dapm_force_enable_pin_unlocked);
233 }
234 EXPORT_SYMBOL_GPL(snd_soc_component_force_enable_pin_unlocked);
235
236 /**
237  * snd_soc_component_set_jack - configure component jack.
238  * @component: COMPONENTs
239  * @jack: structure to use for the jack
240  * @data: can be used if codec driver need extra data for configuring jack
241  *
242  * Configures and enables jack detection function.
243  */
244 int snd_soc_component_set_jack(struct snd_soc_component *component,
245                                struct snd_soc_jack *jack, void *data)
246 {
247         int ret = -ENOTSUPP;
248
249         if (component->driver->set_jack)
250                 ret = component->driver->set_jack(component, jack, data);
251
252         return soc_component_ret(component, ret);
253 }
254 EXPORT_SYMBOL_GPL(snd_soc_component_set_jack);
255
256 int snd_soc_component_module_get(struct snd_soc_component *component,
257                                  int upon_open)
258 {
259         int ret = 0;
260
261         if (component->driver->module_get_upon_open == !!upon_open &&
262             !try_module_get(component->dev->driver->owner))
263                 ret = -ENODEV;
264
265         return soc_component_ret(component, ret);
266 }
267
268 void snd_soc_component_module_put(struct snd_soc_component *component,
269                                   int upon_open)
270 {
271         if (component->driver->module_get_upon_open == !!upon_open)
272                 module_put(component->dev->driver->owner);
273 }
274
275 int snd_soc_component_open(struct snd_soc_component *component,
276                            struct snd_pcm_substream *substream)
277 {
278         int ret = 0;
279
280         if (component->driver->open)
281                 ret = component->driver->open(component, substream);
282
283         return soc_component_ret(component, ret);
284 }
285
286 int snd_soc_component_close(struct snd_soc_component *component,
287                             struct snd_pcm_substream *substream)
288 {
289         int ret = 0;
290
291         if (component->driver->close)
292                 ret = component->driver->close(component, substream);
293
294         return soc_component_ret(component, ret);
295 }
296
297 void snd_soc_component_suspend(struct snd_soc_component *component)
298 {
299         if (component->driver->suspend)
300                 component->driver->suspend(component);
301         component->suspended = 1;
302 }
303
304 void snd_soc_component_resume(struct snd_soc_component *component)
305 {
306         if (component->driver->resume)
307                 component->driver->resume(component);
308         component->suspended = 0;
309 }
310
311 int snd_soc_component_is_suspended(struct snd_soc_component *component)
312 {
313         return component->suspended;
314 }
315
316 int snd_soc_component_probe(struct snd_soc_component *component)
317 {
318         int ret = 0;
319
320         if (component->driver->probe)
321                 ret = component->driver->probe(component);
322
323         return soc_component_ret(component, ret);
324 }
325
326 void snd_soc_component_remove(struct snd_soc_component *component)
327 {
328         if (component->driver->remove)
329                 component->driver->remove(component);
330 }
331
332 int snd_soc_component_of_xlate_dai_id(struct snd_soc_component *component,
333                                       struct device_node *ep)
334 {
335         int ret = -ENOTSUPP;
336
337         if (component->driver->of_xlate_dai_id)
338                 ret = component->driver->of_xlate_dai_id(component, ep);
339
340         return soc_component_ret(component, ret);
341 }
342
343 int snd_soc_component_of_xlate_dai_name(struct snd_soc_component *component,
344                                         struct of_phandle_args *args,
345                                         const char **dai_name)
346 {
347         int ret = -ENOTSUPP;
348
349         if (component->driver->of_xlate_dai_name)
350                 ret = component->driver->of_xlate_dai_name(component,
351                                                            args, dai_name);
352
353         return soc_component_ret(component, ret);
354 }
355
356 void snd_soc_component_setup_regmap(struct snd_soc_component *component)
357 {
358         int val_bytes = regmap_get_val_bytes(component->regmap);
359
360         /* Errors are legitimate for non-integer byte multiples */
361         if (val_bytes > 0)
362                 component->val_bytes = val_bytes;
363 }
364
365 #ifdef CONFIG_REGMAP
366
367 /**
368  * snd_soc_component_init_regmap() - Initialize regmap instance for the
369  *                                   component
370  * @component: The component for which to initialize the regmap instance
371  * @regmap: The regmap instance that should be used by the component
372  *
373  * This function allows deferred assignment of the regmap instance that is
374  * associated with the component. Only use this if the regmap instance is not
375  * yet ready when the component is registered. The function must also be called
376  * before the first IO attempt of the component.
377  */
378 void snd_soc_component_init_regmap(struct snd_soc_component *component,
379                                    struct regmap *regmap)
380 {
381         component->regmap = regmap;
382         snd_soc_component_setup_regmap(component);
383 }
384 EXPORT_SYMBOL_GPL(snd_soc_component_init_regmap);
385
386 /**
387  * snd_soc_component_exit_regmap() - De-initialize regmap instance for the
388  *                                   component
389  * @component: The component for which to de-initialize the regmap instance
390  *
391  * Calls regmap_exit() on the regmap instance associated to the component and
392  * removes the regmap instance from the component.
393  *
394  * This function should only be used if snd_soc_component_init_regmap() was used
395  * to initialize the regmap instance.
396  */
397 void snd_soc_component_exit_regmap(struct snd_soc_component *component)
398 {
399         regmap_exit(component->regmap);
400         component->regmap = NULL;
401 }
402 EXPORT_SYMBOL_GPL(snd_soc_component_exit_regmap);
403
404 #endif
405
406 /**
407  * snd_soc_component_read() - Read register value
408  * @component: Component to read from
409  * @reg: Register to read
410  * @val: Pointer to where the read value is stored
411  *
412  * Return: 0 on success, a negative error code otherwise.
413  */
414 int snd_soc_component_read(struct snd_soc_component *component,
415                            unsigned int reg, unsigned int *val)
416 {
417         int ret;
418
419         if (component->regmap)
420                 ret = regmap_read(component->regmap, reg, val);
421         else if (component->driver->read) {
422                 *val = component->driver->read(component, reg);
423                 ret = 0;
424         }
425         else
426                 ret = -EIO;
427
428         return soc_component_ret(component, ret);
429 }
430 EXPORT_SYMBOL_GPL(snd_soc_component_read);
431
432 unsigned int snd_soc_component_read32(struct snd_soc_component *component,
433                                       unsigned int reg)
434 {
435         unsigned int val;
436         int ret;
437
438         ret = snd_soc_component_read(component, reg, &val);
439         if (ret < 0)
440                 return soc_component_ret(component, -1);
441
442         return val;
443 }
444 EXPORT_SYMBOL_GPL(snd_soc_component_read32);
445
446 /**
447  * snd_soc_component_write() - Write register value
448  * @component: Component to write to
449  * @reg: Register to write
450  * @val: Value to write to the register
451  *
452  * Return: 0 on success, a negative error code otherwise.
453  */
454 int snd_soc_component_write(struct snd_soc_component *component,
455                             unsigned int reg, unsigned int val)
456 {
457         int ret = -EIO;
458
459         if (component->regmap)
460                 ret = regmap_write(component->regmap, reg, val);
461         else if (component->driver->write)
462                 ret = component->driver->write(component, reg, val);
463
464         return soc_component_ret(component, ret);
465 }
466 EXPORT_SYMBOL_GPL(snd_soc_component_write);
467
468 static int snd_soc_component_update_bits_legacy(
469         struct snd_soc_component *component, unsigned int reg,
470         unsigned int mask, unsigned int val, bool *change)
471 {
472         unsigned int old, new;
473         int ret;
474
475         mutex_lock(&component->io_mutex);
476
477         ret = snd_soc_component_read(component, reg, &old);
478         if (ret < 0)
479                 goto out_unlock;
480
481         new = (old & ~mask) | (val & mask);
482         *change = old != new;
483         if (*change)
484                 ret = snd_soc_component_write(component, reg, new);
485 out_unlock:
486         mutex_unlock(&component->io_mutex);
487
488         return soc_component_ret(component, ret);
489 }
490
491 /**
492  * snd_soc_component_update_bits() - Perform read/modify/write cycle
493  * @component: Component to update
494  * @reg: Register to update
495  * @mask: Mask that specifies which bits to update
496  * @val: New value for the bits specified by mask
497  *
498  * Return: 1 if the operation was successful and the value of the register
499  * changed, 0 if the operation was successful, but the value did not change.
500  * Returns a negative error code otherwise.
501  */
502 int snd_soc_component_update_bits(struct snd_soc_component *component,
503                                   unsigned int reg, unsigned int mask, unsigned int val)
504 {
505         bool change;
506         int ret;
507
508         if (component->regmap)
509                 ret = regmap_update_bits_check(component->regmap, reg, mask,
510                                                val, &change);
511         else
512                 ret = snd_soc_component_update_bits_legacy(component, reg,
513                                                            mask, val, &change);
514
515         if (ret < 0)
516                 return soc_component_ret(component, ret);
517         return change;
518 }
519 EXPORT_SYMBOL_GPL(snd_soc_component_update_bits);
520
521 /**
522  * snd_soc_component_update_bits_async() - Perform asynchronous
523  *  read/modify/write cycle
524  * @component: Component to update
525  * @reg: Register to update
526  * @mask: Mask that specifies which bits to update
527  * @val: New value for the bits specified by mask
528  *
529  * This function is similar to snd_soc_component_update_bits(), but the update
530  * operation is scheduled asynchronously. This means it may not be completed
531  * when the function returns. To make sure that all scheduled updates have been
532  * completed snd_soc_component_async_complete() must be called.
533  *
534  * Return: 1 if the operation was successful and the value of the register
535  * changed, 0 if the operation was successful, but the value did not change.
536  * Returns a negative error code otherwise.
537  */
538 int snd_soc_component_update_bits_async(struct snd_soc_component *component,
539                                         unsigned int reg, unsigned int mask, unsigned int val)
540 {
541         bool change;
542         int ret;
543
544         if (component->regmap)
545                 ret = regmap_update_bits_check_async(component->regmap, reg,
546                                                      mask, val, &change);
547         else
548                 ret = snd_soc_component_update_bits_legacy(component, reg,
549                                                            mask, val, &change);
550
551         if (ret < 0)
552                 return soc_component_ret(component, ret);
553         return change;
554 }
555 EXPORT_SYMBOL_GPL(snd_soc_component_update_bits_async);
556
557 /**
558  * snd_soc_component_async_complete() - Ensure asynchronous I/O has completed
559  * @component: Component for which to wait
560  *
561  * This function blocks until all asynchronous I/O which has previously been
562  * scheduled using snd_soc_component_update_bits_async() has completed.
563  */
564 void snd_soc_component_async_complete(struct snd_soc_component *component)
565 {
566         if (component->regmap)
567                 regmap_async_complete(component->regmap);
568 }
569 EXPORT_SYMBOL_GPL(snd_soc_component_async_complete);
570
571 /**
572  * snd_soc_component_test_bits - Test register for change
573  * @component: component
574  * @reg: Register to test
575  * @mask: Mask that specifies which bits to test
576  * @value: Value to test against
577  *
578  * Tests a register with a new value and checks if the new value is
579  * different from the old value.
580  *
581  * Return: 1 for change, otherwise 0.
582  */
583 int snd_soc_component_test_bits(struct snd_soc_component *component,
584                                 unsigned int reg, unsigned int mask, unsigned int value)
585 {
586         unsigned int old, new;
587         int ret;
588
589         ret = snd_soc_component_read(component, reg, &old);
590         if (ret < 0)
591                 return soc_component_ret(component, ret);
592         new = (old & ~mask) | value;
593         return old != new;
594 }
595 EXPORT_SYMBOL_GPL(snd_soc_component_test_bits);
596
597 int snd_soc_pcm_component_pointer(struct snd_pcm_substream *substream)
598 {
599         struct snd_soc_pcm_runtime *rtd = substream->private_data;
600         struct snd_soc_component *component;
601         int i;
602
603         /* FIXME: use 1st pointer */
604         for_each_rtd_components(rtd, i, component)
605                 if (component->driver->pointer)
606                         return component->driver->pointer(component, substream);
607
608         return 0;
609 }
610
611 int snd_soc_pcm_component_ioctl(struct snd_pcm_substream *substream,
612                                 unsigned int cmd, void *arg)
613 {
614         struct snd_soc_pcm_runtime *rtd = substream->private_data;
615         struct snd_soc_component *component;
616         int i;
617
618         /* FIXME: use 1st ioctl */
619         for_each_rtd_components(rtd, i, component)
620                 if (component->driver->ioctl)
621                         return soc_component_ret(
622                                 component,
623                                 component->driver->ioctl(component,
624                                                          substream, cmd, arg));
625
626         return snd_pcm_lib_ioctl(substream, cmd, arg);
627 }
628
629 int snd_soc_pcm_component_sync_stop(struct snd_pcm_substream *substream)
630 {
631         struct snd_soc_pcm_runtime *rtd = substream->private_data;
632         struct snd_soc_component *component;
633         int i, ret;
634
635         for_each_rtd_components(rtd, i, component) {
636                 if (component->driver->sync_stop) {
637                         ret = component->driver->sync_stop(component,
638                                                            substream);
639                         if (ret < 0)
640                                 soc_component_ret(component, ret);
641                 }
642         }
643
644         return 0;
645 }
646
647 int snd_soc_pcm_component_copy_user(struct snd_pcm_substream *substream,
648                                     int channel, unsigned long pos,
649                                     void __user *buf, unsigned long bytes)
650 {
651         struct snd_soc_pcm_runtime *rtd = substream->private_data;
652         struct snd_soc_component *component;
653         int i;
654
655         /* FIXME. it returns 1st copy now */
656         for_each_rtd_components(rtd, i, component)
657                 if (component->driver->copy_user)
658                         return soc_component_ret(
659                                 component,
660                                 component->driver->copy_user(
661                                         component, substream, channel,
662                                         pos, buf, bytes));
663
664         return -EINVAL;
665 }
666
667 struct page *snd_soc_pcm_component_page(struct snd_pcm_substream *substream,
668                                         unsigned long offset)
669 {
670         struct snd_soc_pcm_runtime *rtd = substream->private_data;
671         struct snd_soc_component *component;
672         struct page *page;
673         int i;
674
675         /* FIXME. it returns 1st page now */
676         for_each_rtd_components(rtd, i, component) {
677                 if (component->driver->page) {
678                         page = component->driver->page(component,
679                                                        substream, offset);
680                         if (page)
681                                 return page;
682                 }
683         }
684
685         return NULL;
686 }
687
688 int snd_soc_pcm_component_mmap(struct snd_pcm_substream *substream,
689                                struct vm_area_struct *vma)
690 {
691         struct snd_soc_pcm_runtime *rtd = substream->private_data;
692         struct snd_soc_component *component;
693         int i;
694
695         /* FIXME. it returns 1st mmap now */
696         for_each_rtd_components(rtd, i, component)
697                 if (component->driver->mmap)
698                         soc_component_ret(
699                                 component,
700                                 component->driver->mmap(component,
701                                                         substream, vma));
702
703         return -EINVAL;
704 }
705
706 int snd_soc_pcm_component_new(struct snd_soc_pcm_runtime *rtd)
707 {
708         struct snd_soc_component *component;
709         int ret;
710         int i;
711
712         for_each_rtd_components(rtd, i, component) {
713                 if (component->driver->pcm_construct) {
714                         ret = component->driver->pcm_construct(component, rtd);
715                         if (ret < 0)
716                                 soc_component_ret(component, ret);
717                 }
718         }
719
720         return 0;
721 }
722
723 void snd_soc_pcm_component_free(struct snd_soc_pcm_runtime *rtd)
724 {
725         struct snd_soc_component *component;
726         int i;
727
728         if (!rtd->pcm)
729                 return;
730
731         for_each_rtd_components(rtd, i, component)
732                 if (component->driver->pcm_destruct)
733                         component->driver->pcm_destruct(component, rtd->pcm);
734 }
735
736 int snd_soc_pcm_component_prepare(struct snd_pcm_substream *substream)
737 {
738         struct snd_soc_pcm_runtime *rtd = substream->private_data;
739         struct snd_soc_component *component;
740         int i, ret;
741
742         for_each_rtd_components(rtd, i, component) {
743                 if (component->driver->prepare) {
744                         ret = component->driver->prepare(component, substream);
745                         if (ret < 0)
746                                 return soc_component_ret(component, ret);
747                 }
748         }
749
750         return 0;
751 }
752
753 int snd_soc_pcm_component_hw_params(struct snd_pcm_substream *substream,
754                                     struct snd_pcm_hw_params *params,
755                                     struct snd_soc_component **last)
756 {
757         struct snd_soc_pcm_runtime *rtd = substream->private_data;
758         struct snd_soc_component *component;
759         int i, ret;
760
761         for_each_rtd_components(rtd, i, component) {
762                 if (component->driver->hw_params) {
763                         ret = component->driver->hw_params(component,
764                                                            substream, params);
765                         if (ret < 0) {
766                                 *last = component;
767                                 return soc_component_ret(component, ret);
768                         }
769                 }
770         }
771
772         *last = NULL;
773         return 0;
774 }
775
776 void snd_soc_pcm_component_hw_free(struct snd_pcm_substream *substream,
777                                    struct snd_soc_component *last)
778 {
779         struct snd_soc_pcm_runtime *rtd = substream->private_data;
780         struct snd_soc_component *component;
781         int i, ret;
782
783         for_each_rtd_components(rtd, i, component) {
784                 if (component == last)
785                         break;
786
787                 if (component->driver->hw_free) {
788                         ret = component->driver->hw_free(component, substream);
789                         if (ret < 0)
790                                 soc_component_ret(component, ret);
791                 }
792         }
793 }
794
795 int snd_soc_pcm_component_trigger(struct snd_pcm_substream *substream,
796                                   int cmd)
797 {
798         struct snd_soc_pcm_runtime *rtd = substream->private_data;
799         struct snd_soc_component *component;
800         int i, ret;
801
802         for_each_rtd_components(rtd, i, component) {
803                 if (component->driver->trigger) {
804                         ret = component->driver->trigger(component, substream, cmd);
805                         if (ret < 0)
806                                 return soc_component_ret(component, ret);
807                 }
808         }
809
810         return 0;
811 }