blob: e19f78bfb919a196b49a0997730d82618386b369 [file] [log] [blame]
Kuninori Morimoto4ff1fef2019-07-26 13:49:48 +09001// SPDX-License-Identifier: GPL-2.0
2//
3// soc-component.c
4//
5// Copyright (C) 2019 Renesas Electronics Corp.
6// Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
7//
8#include <sound/soc.h>
9
10/**
11 * snd_soc_component_set_sysclk - configure COMPONENT system or master clock.
12 * @component: COMPONENT
13 * @clk_id: DAI specific clock ID
14 * @source: Source for the clock
15 * @freq: new clock frequency in Hz
16 * @dir: new clock direction - input/output.
17 *
18 * Configures the CODEC master (MCLK) or system (SYSCLK) clocking.
19 */
20int snd_soc_component_set_sysclk(struct snd_soc_component *component,
21 int clk_id, int source, unsigned int freq,
22 int dir)
23{
24 if (component->driver->set_sysclk)
25 return component->driver->set_sysclk(component, clk_id, source,
26 freq, dir);
27
28 return -ENOTSUPP;
29}
30EXPORT_SYMBOL_GPL(snd_soc_component_set_sysclk);
31
32/*
33 * snd_soc_component_set_pll - configure component PLL.
34 * @component: COMPONENT
35 * @pll_id: DAI specific PLL ID
36 * @source: DAI specific source for the PLL
37 * @freq_in: PLL input clock frequency in Hz
38 * @freq_out: requested PLL output clock frequency in Hz
39 *
40 * Configures and enables PLL to generate output clock based on input clock.
41 */
42int snd_soc_component_set_pll(struct snd_soc_component *component, int pll_id,
43 int source, unsigned int freq_in,
44 unsigned int freq_out)
45{
46 if (component->driver->set_pll)
47 return component->driver->set_pll(component, pll_id, source,
48 freq_in, freq_out);
49
50 return -EINVAL;
51}
52EXPORT_SYMBOL_GPL(snd_soc_component_set_pll);
53
54int snd_soc_component_enable_pin(struct snd_soc_component *component,
55 const char *pin)
56{
57 struct snd_soc_dapm_context *dapm =
58 snd_soc_component_get_dapm(component);
59 char *full_name;
60 int ret;
61
62 if (!component->name_prefix)
63 return snd_soc_dapm_enable_pin(dapm, pin);
64
65 full_name = kasprintf(GFP_KERNEL, "%s %s", component->name_prefix, pin);
66 if (!full_name)
67 return -ENOMEM;
68
69 ret = snd_soc_dapm_enable_pin(dapm, full_name);
70 kfree(full_name);
71
72 return ret;
73}
74EXPORT_SYMBOL_GPL(snd_soc_component_enable_pin);
75
76int snd_soc_component_enable_pin_unlocked(struct snd_soc_component *component,
77 const char *pin)
78{
79 struct snd_soc_dapm_context *dapm =
80 snd_soc_component_get_dapm(component);
81 char *full_name;
82 int ret;
83
84 if (!component->name_prefix)
85 return snd_soc_dapm_enable_pin_unlocked(dapm, pin);
86
87 full_name = kasprintf(GFP_KERNEL, "%s %s", component->name_prefix, pin);
88 if (!full_name)
89 return -ENOMEM;
90
91 ret = snd_soc_dapm_enable_pin_unlocked(dapm, full_name);
92 kfree(full_name);
93
94 return ret;
95}
96EXPORT_SYMBOL_GPL(snd_soc_component_enable_pin_unlocked);
97
98int snd_soc_component_disable_pin(struct snd_soc_component *component,
99 const char *pin)
100{
101 struct snd_soc_dapm_context *dapm =
102 snd_soc_component_get_dapm(component);
103 char *full_name;
104 int ret;
105
106 if (!component->name_prefix)
107 return snd_soc_dapm_disable_pin(dapm, pin);
108
109 full_name = kasprintf(GFP_KERNEL, "%s %s", component->name_prefix, pin);
110 if (!full_name)
111 return -ENOMEM;
112
113 ret = snd_soc_dapm_disable_pin(dapm, full_name);
114 kfree(full_name);
115
116 return ret;
117}
118EXPORT_SYMBOL_GPL(snd_soc_component_disable_pin);
119
120int snd_soc_component_disable_pin_unlocked(struct snd_soc_component *component,
121 const char *pin)
122{
123 struct snd_soc_dapm_context *dapm =
124 snd_soc_component_get_dapm(component);
125 char *full_name;
126 int ret;
127
128 if (!component->name_prefix)
129 return snd_soc_dapm_disable_pin_unlocked(dapm, pin);
130
131 full_name = kasprintf(GFP_KERNEL, "%s %s", component->name_prefix, pin);
132 if (!full_name)
133 return -ENOMEM;
134
135 ret = snd_soc_dapm_disable_pin_unlocked(dapm, full_name);
136 kfree(full_name);
137
138 return ret;
139}
140EXPORT_SYMBOL_GPL(snd_soc_component_disable_pin_unlocked);
141
142int snd_soc_component_nc_pin(struct snd_soc_component *component,
143 const char *pin)
144{
145 struct snd_soc_dapm_context *dapm =
146 snd_soc_component_get_dapm(component);
147 char *full_name;
148 int ret;
149
150 if (!component->name_prefix)
151 return snd_soc_dapm_nc_pin(dapm, pin);
152
153 full_name = kasprintf(GFP_KERNEL, "%s %s", component->name_prefix, pin);
154 if (!full_name)
155 return -ENOMEM;
156
157 ret = snd_soc_dapm_nc_pin(dapm, full_name);
158 kfree(full_name);
159
160 return ret;
161}
162EXPORT_SYMBOL_GPL(snd_soc_component_nc_pin);
163
164int snd_soc_component_nc_pin_unlocked(struct snd_soc_component *component,
165 const char *pin)
166{
167 struct snd_soc_dapm_context *dapm =
168 snd_soc_component_get_dapm(component);
169 char *full_name;
170 int ret;
171
172 if (!component->name_prefix)
173 return snd_soc_dapm_nc_pin_unlocked(dapm, pin);
174
175 full_name = kasprintf(GFP_KERNEL, "%s %s", component->name_prefix, pin);
176 if (!full_name)
177 return -ENOMEM;
178
179 ret = snd_soc_dapm_nc_pin_unlocked(dapm, full_name);
180 kfree(full_name);
181
182 return ret;
183}
184EXPORT_SYMBOL_GPL(snd_soc_component_nc_pin_unlocked);
185
186int snd_soc_component_get_pin_status(struct snd_soc_component *component,
187 const char *pin)
188{
189 struct snd_soc_dapm_context *dapm =
190 snd_soc_component_get_dapm(component);
191 char *full_name;
192 int ret;
193
194 if (!component->name_prefix)
195 return snd_soc_dapm_get_pin_status(dapm, pin);
196
197 full_name = kasprintf(GFP_KERNEL, "%s %s", component->name_prefix, pin);
198 if (!full_name)
199 return -ENOMEM;
200
201 ret = snd_soc_dapm_get_pin_status(dapm, full_name);
202 kfree(full_name);
203
204 return ret;
205}
206EXPORT_SYMBOL_GPL(snd_soc_component_get_pin_status);
207
208int snd_soc_component_force_enable_pin(struct snd_soc_component *component,
209 const char *pin)
210{
211 struct snd_soc_dapm_context *dapm =
212 snd_soc_component_get_dapm(component);
213 char *full_name;
214 int ret;
215
216 if (!component->name_prefix)
217 return snd_soc_dapm_force_enable_pin(dapm, pin);
218
219 full_name = kasprintf(GFP_KERNEL, "%s %s", component->name_prefix, pin);
220 if (!full_name)
221 return -ENOMEM;
222
223 ret = snd_soc_dapm_force_enable_pin(dapm, full_name);
224 kfree(full_name);
225
226 return ret;
227}
228EXPORT_SYMBOL_GPL(snd_soc_component_force_enable_pin);
229
230int snd_soc_component_force_enable_pin_unlocked(
231 struct snd_soc_component *component,
232 const char *pin)
233{
234 struct snd_soc_dapm_context *dapm =
235 snd_soc_component_get_dapm(component);
236 char *full_name;
237 int ret;
238
239 if (!component->name_prefix)
240 return snd_soc_dapm_force_enable_pin_unlocked(dapm, pin);
241
242 full_name = kasprintf(GFP_KERNEL, "%s %s", component->name_prefix, pin);
243 if (!full_name)
244 return -ENOMEM;
245
246 ret = snd_soc_dapm_force_enable_pin_unlocked(dapm, full_name);
247 kfree(full_name);
248
249 return ret;
250}
251EXPORT_SYMBOL_GPL(snd_soc_component_force_enable_pin_unlocked);
252
253/**
254 * snd_soc_component_set_jack - configure component jack.
255 * @component: COMPONENTs
256 * @jack: structure to use for the jack
257 * @data: can be used if codec driver need extra data for configuring jack
258 *
259 * Configures and enables jack detection function.
260 */
261int snd_soc_component_set_jack(struct snd_soc_component *component,
262 struct snd_soc_jack *jack, void *data)
263{
264 if (component->driver->set_jack)
265 return component->driver->set_jack(component, jack, data);
266
267 return -ENOTSUPP;
268}
269EXPORT_SYMBOL_GPL(snd_soc_component_set_jack);