16
16
#include <sound/soc.h>
17
17
#include <uapi/linux/input-event-codes.h>
18
18
#include <dt-bindings/sound/apq8016-lpass.h>
19
+ #include "common.h"
19
20
20
21
struct apq8016_sbc_data {
22
+ struct snd_soc_card card ;
21
23
void __iomem * mic_iomux ;
22
24
void __iomem * spkr_iomux ;
23
25
struct snd_soc_jack jack ;
24
26
bool jack_setup ;
25
- struct snd_soc_dai_link dai_link []; /* dynamically allocated */
26
27
};
27
28
28
29
#define MIC_CTRL_TER_WS_SLAVE_SEL BIT(21)
@@ -110,107 +111,13 @@ static int apq8016_sbc_dai_init(struct snd_soc_pcm_runtime *rtd)
110
111
return 0 ;
111
112
}
112
113
113
- static struct apq8016_sbc_data * apq8016_sbc_parse_of (struct snd_soc_card * card )
114
+ static void apq8016_sbc_add_ops (struct snd_soc_card * card )
114
115
{
115
- struct device * dev = card -> dev ;
116
116
struct snd_soc_dai_link * link ;
117
- struct device_node * np , * codec , * cpu , * node = dev -> of_node ;
118
- struct apq8016_sbc_data * data ;
119
- struct snd_soc_dai_link_component * dlc ;
120
- int ret , num_links ;
121
-
122
- ret = snd_soc_of_parse_card_name (card , "qcom,model" );
123
- if (ret ) {
124
- dev_err (dev , "Error parsing card name: %d\n" , ret );
125
- return ERR_PTR (ret );
126
- }
127
-
128
- /* DAPM routes */
129
- if (of_property_read_bool (node , "qcom,audio-routing" )) {
130
- ret = snd_soc_of_parse_audio_routing (card ,
131
- "qcom,audio-routing" );
132
- if (ret )
133
- return ERR_PTR (ret );
134
- }
135
-
136
-
137
- /* Populate links */
138
- num_links = of_get_child_count (node );
139
-
140
- /* Allocate the private data and the DAI link array */
141
- data = devm_kzalloc (dev ,
142
- struct_size (data , dai_link , num_links ),
143
- GFP_KERNEL );
144
- if (!data )
145
- return ERR_PTR (- ENOMEM );
146
-
147
- card -> dai_link = & data -> dai_link [0 ];
148
- card -> num_links = num_links ;
149
-
150
- link = data -> dai_link ;
151
-
152
- for_each_child_of_node (node , np ) {
153
- dlc = devm_kzalloc (dev , 2 * sizeof (* dlc ), GFP_KERNEL );
154
- if (!dlc )
155
- return ERR_PTR (- ENOMEM );
156
-
157
- link -> cpus = & dlc [0 ];
158
- link -> platforms = & dlc [1 ];
159
-
160
- link -> num_cpus = 1 ;
161
- link -> num_platforms = 1 ;
162
-
163
- cpu = of_get_child_by_name (np , "cpu" );
164
- codec = of_get_child_by_name (np , "codec" );
165
-
166
- if (!cpu || !codec ) {
167
- dev_err (dev , "Can't find cpu/codec DT node\n" );
168
- ret = - EINVAL ;
169
- goto error ;
170
- }
117
+ int i ;
171
118
172
- link -> cpus -> of_node = of_parse_phandle (cpu , "sound-dai" , 0 );
173
- if (!link -> cpus -> of_node ) {
174
- dev_err (card -> dev , "error getting cpu phandle\n" );
175
- ret = - EINVAL ;
176
- goto error ;
177
- }
178
-
179
- ret = snd_soc_of_get_dai_name (cpu , & link -> cpus -> dai_name );
180
- if (ret ) {
181
- dev_err (card -> dev , "error getting cpu dai name\n" );
182
- goto error ;
183
- }
184
-
185
- ret = snd_soc_of_get_dai_link_codecs (dev , codec , link );
186
-
187
- if (ret < 0 ) {
188
- dev_err (card -> dev , "error getting codec dai name\n" );
189
- goto error ;
190
- }
191
-
192
- link -> platforms -> of_node = link -> cpus -> of_node ;
193
- ret = of_property_read_string (np , "link-name" , & link -> name );
194
- if (ret ) {
195
- dev_err (card -> dev , "error getting codec dai_link name\n" );
196
- goto error ;
197
- }
198
-
199
- link -> stream_name = link -> name ;
119
+ for_each_card_prelinks (card , i , link )
200
120
link -> init = apq8016_sbc_dai_init ;
201
- link ++ ;
202
-
203
- of_node_put (cpu );
204
- of_node_put (codec );
205
- }
206
-
207
- return data ;
208
-
209
- error :
210
- of_node_put (np );
211
- of_node_put (cpu );
212
- of_node_put (codec );
213
- return ERR_PTR (ret );
214
121
}
215
122
216
123
static const struct snd_soc_dapm_widget apq8016_sbc_dapm_widgets [] = {
@@ -228,20 +135,20 @@ static int apq8016_sbc_platform_probe(struct platform_device *pdev)
228
135
struct snd_soc_card * card ;
229
136
struct apq8016_sbc_data * data ;
230
137
struct resource * res ;
138
+ int ret ;
231
139
232
- card = devm_kzalloc (dev , sizeof (* card ), GFP_KERNEL );
233
- if (!card )
140
+ data = devm_kzalloc (dev , sizeof (* data ), GFP_KERNEL );
141
+ if (!data )
234
142
return - ENOMEM ;
235
143
144
+ card = & data -> card ;
236
145
card -> dev = dev ;
237
146
card -> dapm_widgets = apq8016_sbc_dapm_widgets ;
238
147
card -> num_dapm_widgets = ARRAY_SIZE (apq8016_sbc_dapm_widgets );
239
- data = apq8016_sbc_parse_of (card );
240
- if (IS_ERR (data )) {
241
- dev_err (& pdev -> dev , "Error resolving dai links: %ld\n" ,
242
- PTR_ERR (data ));
243
- return PTR_ERR (data );
244
- }
148
+
149
+ ret = qcom_snd_parse_of (card );
150
+ if (ret )
151
+ return ret ;
245
152
246
153
res = platform_get_resource_byname (pdev , IORESOURCE_MEM , "mic-iomux" );
247
154
data -> mic_iomux = devm_ioremap_resource (dev , res );
@@ -255,6 +162,7 @@ static int apq8016_sbc_platform_probe(struct platform_device *pdev)
255
162
256
163
snd_soc_card_set_drvdata (card , data );
257
164
165
+ apq8016_sbc_add_ops (card );
258
166
return devm_snd_soc_register_card (& pdev -> dev , card );
259
167
}
260
168
0 commit comments