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