1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (c) 2018, The Linux Foundation. All rights reserved.
4 */
5
6 #include <dt-bindings/sound/qcom,q6afe.h>
7 #include <linux/module.h>
8 #include <linux/platform_device.h>
9 #include <sound/core.h>
10 #include <sound/pcm.h>
11 #include <sound/pcm_params.h>
12 #include <sound/jack.h>
13 #include <sound/soc.h>
14 #include <linux/soundwire/sdw.h>
15 #include <uapi/linux/input-event-codes.h>
16 #include "common.h"
17 #include "qdsp6/q6afe.h"
18 #include "sdw.h"
19 #include "../codecs/rt5663.h"
20
21 #define DRIVER_NAME "sdm845"
22 #define DEFAULT_SAMPLE_RATE_48K 48000
23 #define DEFAULT_MCLK_RATE 24576000
24 #define TDM_BCLK_RATE 6144000
25 #define MI2S_BCLK_RATE 1536000
26 #define LEFT_SPK_TDM_TX_MASK 0x30
27 #define RIGHT_SPK_TDM_TX_MASK 0xC0
28 #define SPK_TDM_RX_MASK 0x03
29 #define NUM_TDM_SLOTS 8
30 #define SLIM_MAX_TX_PORTS 16
31 #define SLIM_MAX_RX_PORTS 13
32 #define WCD934X_DEFAULT_MCLK_RATE 9600000
33
34 struct sdm845_snd_data {
35 struct snd_soc_jack jack;
36 bool jack_setup;
37 bool slim_port_setup;
38 bool stream_prepared[AFE_PORT_MAX];
39 struct snd_soc_card *card;
40 uint32_t pri_mi2s_clk_count;
41 uint32_t sec_mi2s_clk_count;
42 uint32_t quat_tdm_clk_count;
43 struct sdw_stream_runtime *sruntime[AFE_PORT_MAX];
44 };
45
46 static struct snd_soc_jack_pin sdm845_jack_pins[] = {
47 {
48 .pin = "Headphone Jack",
49 .mask = SND_JACK_HEADPHONE,
50 },
51 {
52 .pin = "Headset Mic",
53 .mask = SND_JACK_MICROPHONE,
54 },
55 };
56
57 static unsigned int tdm_slot_offset[8] = {0, 4, 8, 12, 16, 20, 24, 28};
58
sdm845_slim_snd_hw_params(struct snd_pcm_substream * substream,struct snd_pcm_hw_params * params)59 static int sdm845_slim_snd_hw_params(struct snd_pcm_substream *substream,
60 struct snd_pcm_hw_params *params)
61 {
62 struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
63 struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0);
64 struct snd_soc_dai *codec_dai;
65 struct sdm845_snd_data *pdata = snd_soc_card_get_drvdata(rtd->card);
66 u32 rx_ch[SLIM_MAX_RX_PORTS], tx_ch[SLIM_MAX_TX_PORTS];
67 struct sdw_stream_runtime *sruntime;
68 u32 rx_ch_cnt = 0, tx_ch_cnt = 0;
69 int ret = 0, i;
70
71 for_each_rtd_codec_dais(rtd, i, codec_dai) {
72 sruntime = snd_soc_dai_get_stream(codec_dai,
73 substream->stream);
74 if (sruntime != ERR_PTR(-ENOTSUPP))
75 pdata->sruntime[cpu_dai->id] = sruntime;
76
77 ret = snd_soc_dai_get_channel_map(codec_dai,
78 &tx_ch_cnt, tx_ch, &rx_ch_cnt, rx_ch);
79
80 if (ret != 0 && ret != -ENOTSUPP) {
81 pr_err("failed to get codec chan map, err:%d\n", ret);
82 return ret;
83 } else if (ret == -ENOTSUPP) {
84 /* Ignore unsupported */
85 continue;
86 }
87
88 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
89 ret = snd_soc_dai_set_channel_map(cpu_dai, 0, NULL,
90 rx_ch_cnt, rx_ch);
91 else
92 ret = snd_soc_dai_set_channel_map(cpu_dai, tx_ch_cnt,
93 tx_ch, 0, NULL);
94 }
95
96 return 0;
97 }
98
sdm845_tdm_snd_hw_params(struct snd_pcm_substream * substream,struct snd_pcm_hw_params * params)99 static int sdm845_tdm_snd_hw_params(struct snd_pcm_substream *substream,
100 struct snd_pcm_hw_params *params)
101 {
102 struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
103 struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0);
104 struct snd_soc_dai *codec_dai;
105 int ret = 0, j;
106 int channels, slot_width;
107
108 switch (params_format(params)) {
109 case SNDRV_PCM_FORMAT_S16_LE:
110 slot_width = 16;
111 break;
112 default:
113 dev_err(rtd->dev, "%s: invalid param format 0x%x\n",
114 __func__, params_format(params));
115 return -EINVAL;
116 }
117
118 channels = params_channels(params);
119 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
120 ret = snd_soc_dai_set_tdm_slot(cpu_dai, 0, 0x3,
121 8, slot_width);
122 if (ret < 0) {
123 dev_err(rtd->dev, "%s: failed to set tdm slot, err:%d\n",
124 __func__, ret);
125 goto end;
126 }
127
128 ret = snd_soc_dai_set_channel_map(cpu_dai, 0, NULL,
129 channels, tdm_slot_offset);
130 if (ret < 0) {
131 dev_err(rtd->dev, "%s: failed to set channel map, err:%d\n",
132 __func__, ret);
133 goto end;
134 }
135 } else {
136 ret = snd_soc_dai_set_tdm_slot(cpu_dai, 0xf, 0,
137 8, slot_width);
138 if (ret < 0) {
139 dev_err(rtd->dev, "%s: failed to set tdm slot, err:%d\n",
140 __func__, ret);
141 goto end;
142 }
143
144 ret = snd_soc_dai_set_channel_map(cpu_dai, channels,
145 tdm_slot_offset, 0, NULL);
146 if (ret < 0) {
147 dev_err(rtd->dev, "%s: failed to set channel map, err:%d\n",
148 __func__, ret);
149 goto end;
150 }
151 }
152
153 for_each_rtd_codec_dais(rtd, j, codec_dai) {
154
155 if (!strcmp(codec_dai->component->name_prefix, "Left")) {
156 ret = snd_soc_dai_set_tdm_slot(
157 codec_dai, LEFT_SPK_TDM_TX_MASK,
158 SPK_TDM_RX_MASK, NUM_TDM_SLOTS,
159 slot_width);
160 if (ret < 0) {
161 dev_err(rtd->dev,
162 "DEV0 TDM slot err:%d\n", ret);
163 return ret;
164 }
165 }
166
167 if (!strcmp(codec_dai->component->name_prefix, "Right")) {
168 ret = snd_soc_dai_set_tdm_slot(
169 codec_dai, RIGHT_SPK_TDM_TX_MASK,
170 SPK_TDM_RX_MASK, NUM_TDM_SLOTS,
171 slot_width);
172 if (ret < 0) {
173 dev_err(rtd->dev,
174 "DEV1 TDM slot err:%d\n", ret);
175 return ret;
176 }
177 }
178 }
179
180 end:
181 return ret;
182 }
183
sdm845_snd_hw_params(struct snd_pcm_substream * substream,struct snd_pcm_hw_params * params)184 static int sdm845_snd_hw_params(struct snd_pcm_substream *substream,
185 struct snd_pcm_hw_params *params)
186 {
187 struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
188 struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0);
189 struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(rtd, 0);
190 int ret = 0;
191
192 switch (cpu_dai->id) {
193 case PRIMARY_MI2S_RX:
194 case PRIMARY_MI2S_TX:
195 /*
196 * Use ASRC for internal clocks, as PLL rate isn't multiple
197 * of BCLK.
198 */
199 rt5663_sel_asrc_clk_src(
200 codec_dai->component,
201 RT5663_DA_STEREO_FILTER | RT5663_AD_STEREO_FILTER,
202 RT5663_CLK_SEL_I2S1_ASRC);
203 ret = snd_soc_dai_set_sysclk(
204 codec_dai, RT5663_SCLK_S_MCLK, DEFAULT_MCLK_RATE,
205 SND_SOC_CLOCK_IN);
206 if (ret < 0)
207 dev_err(rtd->dev,
208 "snd_soc_dai_set_sysclk err = %d\n", ret);
209 break;
210 case QUATERNARY_TDM_RX_0:
211 case QUATERNARY_TDM_TX_0:
212 ret = sdm845_tdm_snd_hw_params(substream, params);
213 break;
214 case SLIMBUS_0_RX...SLIMBUS_6_TX:
215 ret = sdm845_slim_snd_hw_params(substream, params);
216 break;
217 case QUATERNARY_MI2S_RX:
218 case SECONDARY_MI2S_RX:
219 break;
220 default:
221 pr_err("%s: invalid dai id 0x%x\n", __func__, cpu_dai->id);
222 break;
223 }
224 return ret;
225 }
226
sdm845_jack_free(struct snd_jack * jack)227 static void sdm845_jack_free(struct snd_jack *jack)
228 {
229 struct snd_soc_component *component = jack->private_data;
230
231 snd_soc_component_set_jack(component, NULL, NULL);
232 }
233
sdm845_dai_init(struct snd_soc_pcm_runtime * rtd)234 static int sdm845_dai_init(struct snd_soc_pcm_runtime *rtd)
235 {
236 struct snd_soc_component *component;
237 struct snd_soc_card *card = rtd->card;
238 struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(rtd, 0);
239 struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0);
240 struct sdm845_snd_data *pdata = snd_soc_card_get_drvdata(card);
241 struct snd_soc_dai_link *link = rtd->dai_link;
242 struct snd_jack *jack;
243 /*
244 * Codec SLIMBUS configuration
245 * RX1, RX2, RX3, RX4, RX5, RX6, RX7, RX8, RX9, RX10, RX11, RX12, RX13
246 * TX1, TX2, TX3, TX4, TX5, TX6, TX7, TX8, TX9, TX10, TX11, TX12, TX13
247 * TX14, TX15, TX16
248 */
249 unsigned int rx_ch[SLIM_MAX_RX_PORTS] = {144, 145, 146, 147, 148, 149,
250 150, 151, 152, 153, 154, 155, 156};
251 unsigned int tx_ch[SLIM_MAX_TX_PORTS] = {128, 129, 130, 131, 132, 133,
252 134, 135, 136, 137, 138, 139,
253 140, 141, 142, 143};
254 int rval, i;
255
256
257 if (!pdata->jack_setup) {
258 rval = snd_soc_card_jack_new_pins(card, "Headset Jack",
259 SND_JACK_HEADSET |
260 SND_JACK_HEADPHONE |
261 SND_JACK_BTN_0 | SND_JACK_BTN_1 |
262 SND_JACK_BTN_2 | SND_JACK_BTN_3,
263 &pdata->jack,
264 sdm845_jack_pins,
265 ARRAY_SIZE(sdm845_jack_pins));
266
267 if (rval < 0) {
268 dev_err(card->dev, "Unable to add Headphone Jack\n");
269 return rval;
270 }
271
272 jack = pdata->jack.jack;
273
274 snd_jack_set_key(jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
275 snd_jack_set_key(jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
276 snd_jack_set_key(jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
277 snd_jack_set_key(jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
278 pdata->jack_setup = true;
279 }
280
281 switch (cpu_dai->id) {
282 case PRIMARY_MI2S_RX:
283 jack = pdata->jack.jack;
284 component = codec_dai->component;
285
286 jack->private_data = component;
287 jack->private_free = sdm845_jack_free;
288 rval = snd_soc_component_set_jack(component,
289 &pdata->jack, NULL);
290 if (rval != 0 && rval != -ENOTSUPP) {
291 dev_warn(card->dev, "Failed to set jack: %d\n", rval);
292 return rval;
293 }
294 break;
295 case SLIMBUS_0_RX...SLIMBUS_6_TX:
296 /* setting up wcd multiple times for slim port is redundant */
297 if (pdata->slim_port_setup || !link->no_pcm)
298 return 0;
299
300 for_each_rtd_codec_dais(rtd, i, codec_dai) {
301 rval = snd_soc_dai_set_channel_map(codec_dai,
302 ARRAY_SIZE(tx_ch),
303 tx_ch,
304 ARRAY_SIZE(rx_ch),
305 rx_ch);
306 if (rval != 0 && rval != -ENOTSUPP)
307 return rval;
308
309 snd_soc_dai_set_sysclk(codec_dai, 0,
310 WCD934X_DEFAULT_MCLK_RATE,
311 SNDRV_PCM_STREAM_PLAYBACK);
312
313 rval = snd_soc_component_set_jack(codec_dai->component,
314 &pdata->jack, NULL);
315 if (rval != 0 && rval != -ENOTSUPP) {
316 dev_warn(card->dev, "Failed to set jack: %d\n", rval);
317 return rval;
318 }
319 }
320
321 pdata->slim_port_setup = true;
322
323 break;
324 default:
325 break;
326 }
327
328 return 0;
329 }
330
331
sdm845_snd_startup(struct snd_pcm_substream * substream)332 static int sdm845_snd_startup(struct snd_pcm_substream *substream)
333 {
334 unsigned int fmt = SND_SOC_DAIFMT_BP_FP;
335 unsigned int codec_dai_fmt = SND_SOC_DAIFMT_BC_FC;
336 struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
337 struct snd_soc_card *card = rtd->card;
338 struct sdm845_snd_data *data = snd_soc_card_get_drvdata(card);
339 struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0);
340 struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(rtd, 0);
341 int j;
342 int ret;
343
344 switch (cpu_dai->id) {
345 case PRIMARY_MI2S_RX:
346 case PRIMARY_MI2S_TX:
347 codec_dai_fmt |= SND_SOC_DAIFMT_NB_NF;
348 if (++(data->pri_mi2s_clk_count) == 1) {
349 snd_soc_dai_set_sysclk(cpu_dai,
350 Q6AFE_LPASS_CLK_ID_MCLK_1,
351 DEFAULT_MCLK_RATE, SNDRV_PCM_STREAM_PLAYBACK);
352 snd_soc_dai_set_sysclk(cpu_dai,
353 Q6AFE_LPASS_CLK_ID_PRI_MI2S_IBIT,
354 MI2S_BCLK_RATE, SNDRV_PCM_STREAM_PLAYBACK);
355 }
356 snd_soc_dai_set_fmt(cpu_dai, fmt);
357 snd_soc_dai_set_fmt(codec_dai, codec_dai_fmt);
358 break;
359
360 case SECONDARY_MI2S_RX:
361 case SECONDARY_MI2S_TX:
362 codec_dai_fmt |= SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_I2S;
363 if (++(data->sec_mi2s_clk_count) == 1) {
364 snd_soc_dai_set_sysclk(cpu_dai,
365 Q6AFE_LPASS_CLK_ID_SEC_MI2S_IBIT,
366 MI2S_BCLK_RATE, SNDRV_PCM_STREAM_CAPTURE);
367 }
368 snd_soc_dai_set_fmt(cpu_dai, fmt);
369 snd_soc_dai_set_fmt(codec_dai, codec_dai_fmt);
370 break;
371 case QUATERNARY_MI2S_RX:
372 snd_soc_dai_set_sysclk(cpu_dai,
373 Q6AFE_LPASS_CLK_ID_QUAD_MI2S_IBIT,
374 MI2S_BCLK_RATE, SNDRV_PCM_STREAM_PLAYBACK);
375 snd_soc_dai_set_fmt(cpu_dai, fmt);
376 break;
377
378 case QUATERNARY_TDM_RX_0:
379 case QUATERNARY_TDM_TX_0:
380 if (++(data->quat_tdm_clk_count) == 1) {
381 snd_soc_dai_set_sysclk(cpu_dai,
382 Q6AFE_LPASS_CLK_ID_QUAD_TDM_IBIT,
383 TDM_BCLK_RATE, SNDRV_PCM_STREAM_PLAYBACK);
384 }
385
386 codec_dai_fmt |= SND_SOC_DAIFMT_IB_NF | SND_SOC_DAIFMT_DSP_B;
387
388 for_each_rtd_codec_dais(rtd, j, codec_dai) {
389
390 if (!strcmp(codec_dai->component->name_prefix,
391 "Left")) {
392 ret = snd_soc_dai_set_fmt(
393 codec_dai, codec_dai_fmt);
394 if (ret < 0) {
395 dev_err(rtd->dev,
396 "Left TDM fmt err:%d\n", ret);
397 return ret;
398 }
399 }
400
401 if (!strcmp(codec_dai->component->name_prefix,
402 "Right")) {
403 ret = snd_soc_dai_set_fmt(
404 codec_dai, codec_dai_fmt);
405 if (ret < 0) {
406 dev_err(rtd->dev,
407 "Right TDM slot err:%d\n", ret);
408 return ret;
409 }
410 }
411 }
412 break;
413 case SLIMBUS_0_RX...SLIMBUS_6_TX:
414 break;
415
416 default:
417 pr_err("%s: invalid dai id 0x%x\n", __func__, cpu_dai->id);
418 break;
419 }
420 return qcom_snd_sdw_startup(substream);
421 }
422
sdm845_snd_shutdown(struct snd_pcm_substream * substream)423 static void sdm845_snd_shutdown(struct snd_pcm_substream *substream)
424 {
425 struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
426 struct snd_soc_card *card = rtd->card;
427 struct sdm845_snd_data *data = snd_soc_card_get_drvdata(card);
428 struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0);
429 struct sdw_stream_runtime *sruntime = data->sruntime[cpu_dai->id];
430
431 switch (cpu_dai->id) {
432 case PRIMARY_MI2S_RX:
433 case PRIMARY_MI2S_TX:
434 if (--(data->pri_mi2s_clk_count) == 0) {
435 snd_soc_dai_set_sysclk(cpu_dai,
436 Q6AFE_LPASS_CLK_ID_MCLK_1,
437 0, SNDRV_PCM_STREAM_PLAYBACK);
438 snd_soc_dai_set_sysclk(cpu_dai,
439 Q6AFE_LPASS_CLK_ID_PRI_MI2S_IBIT,
440 0, SNDRV_PCM_STREAM_PLAYBACK);
441 }
442 break;
443
444 case SECONDARY_MI2S_RX:
445 case SECONDARY_MI2S_TX:
446 if (--(data->sec_mi2s_clk_count) == 0) {
447 snd_soc_dai_set_sysclk(cpu_dai,
448 Q6AFE_LPASS_CLK_ID_SEC_MI2S_IBIT,
449 0, SNDRV_PCM_STREAM_CAPTURE);
450 }
451 break;
452
453 case QUATERNARY_TDM_RX_0:
454 case QUATERNARY_TDM_TX_0:
455 if (--(data->quat_tdm_clk_count) == 0) {
456 snd_soc_dai_set_sysclk(cpu_dai,
457 Q6AFE_LPASS_CLK_ID_QUAD_TDM_IBIT,
458 0, SNDRV_PCM_STREAM_PLAYBACK);
459 }
460 break;
461 case SLIMBUS_0_RX...SLIMBUS_6_TX:
462 case QUATERNARY_MI2S_RX:
463 break;
464
465 default:
466 pr_err("%s: invalid dai id 0x%x\n", __func__, cpu_dai->id);
467 break;
468 }
469
470 data->sruntime[cpu_dai->id] = NULL;
471 sdw_release_stream(sruntime);
472 }
473
sdm845_snd_prepare(struct snd_pcm_substream * substream)474 static int sdm845_snd_prepare(struct snd_pcm_substream *substream)
475 {
476 struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
477 struct sdm845_snd_data *data = snd_soc_card_get_drvdata(rtd->card);
478 struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0);
479 struct sdw_stream_runtime *sruntime = data->sruntime[cpu_dai->id];
480 int ret;
481
482 if (!sruntime)
483 return 0;
484
485 if (data->stream_prepared[cpu_dai->id]) {
486 sdw_disable_stream(sruntime);
487 sdw_deprepare_stream(sruntime);
488 data->stream_prepared[cpu_dai->id] = false;
489 }
490
491 ret = sdw_prepare_stream(sruntime);
492 if (ret)
493 return ret;
494
495 /**
496 * NOTE: there is a strict hw requirement about the ordering of port
497 * enables and actual WSA881x PA enable. PA enable should only happen
498 * after soundwire ports are enabled if not DC on the line is
499 * accumulated resulting in Click/Pop Noise
500 * PA enable/mute are handled as part of codec DAPM and digital mute.
501 */
502
503 ret = sdw_enable_stream(sruntime);
504 if (ret) {
505 sdw_deprepare_stream(sruntime);
506 return ret;
507 }
508 data->stream_prepared[cpu_dai->id] = true;
509
510 return ret;
511 }
512
sdm845_snd_hw_free(struct snd_pcm_substream * substream)513 static int sdm845_snd_hw_free(struct snd_pcm_substream *substream)
514 {
515 struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
516 struct sdm845_snd_data *data = snd_soc_card_get_drvdata(rtd->card);
517 struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0);
518 struct sdw_stream_runtime *sruntime = data->sruntime[cpu_dai->id];
519
520 if (sruntime && data->stream_prepared[cpu_dai->id]) {
521 sdw_disable_stream(sruntime);
522 sdw_deprepare_stream(sruntime);
523 data->stream_prepared[cpu_dai->id] = false;
524 }
525
526 return 0;
527 }
528
529 static const struct snd_soc_ops sdm845_be_ops = {
530 .hw_params = sdm845_snd_hw_params,
531 .hw_free = sdm845_snd_hw_free,
532 .prepare = sdm845_snd_prepare,
533 .startup = sdm845_snd_startup,
534 .shutdown = sdm845_snd_shutdown,
535 };
536
sdm845_be_hw_params_fixup(struct snd_soc_pcm_runtime * rtd,struct snd_pcm_hw_params * params)537 static int sdm845_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
538 struct snd_pcm_hw_params *params)
539 {
540 struct snd_interval *rate = hw_param_interval(params,
541 SNDRV_PCM_HW_PARAM_RATE);
542 struct snd_interval *channels = hw_param_interval(params,
543 SNDRV_PCM_HW_PARAM_CHANNELS);
544 struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
545
546 rate->min = rate->max = DEFAULT_SAMPLE_RATE_48K;
547 channels->min = channels->max = 2;
548 snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S16_LE);
549
550 return 0;
551 }
552
553 static const struct snd_soc_dapm_widget sdm845_snd_widgets[] = {
554 SND_SOC_DAPM_HP("Headphone Jack", NULL),
555 SND_SOC_DAPM_MIC("Headset Mic", NULL),
556 SND_SOC_DAPM_SPK("Left Spk", NULL),
557 SND_SOC_DAPM_SPK("Right Spk", NULL),
558 SND_SOC_DAPM_MIC("Int Mic", NULL),
559 };
560
561 static const struct snd_kcontrol_new sdm845_snd_controls[] = {
562 SOC_DAPM_PIN_SWITCH("Headphone Jack"),
563 SOC_DAPM_PIN_SWITCH("Headset Mic"),
564 };
565
sdm845_add_ops(struct snd_soc_card * card)566 static void sdm845_add_ops(struct snd_soc_card *card)
567 {
568 struct snd_soc_dai_link *link;
569 int i;
570
571 for_each_card_prelinks(card, i, link) {
572 if (link->no_pcm == 1) {
573 link->ops = &sdm845_be_ops;
574 link->be_hw_params_fixup = sdm845_be_hw_params_fixup;
575 }
576 link->init = sdm845_dai_init;
577 }
578 }
579
sdm845_snd_platform_probe(struct platform_device * pdev)580 static int sdm845_snd_platform_probe(struct platform_device *pdev)
581 {
582 struct snd_soc_card *card;
583 struct sdm845_snd_data *data;
584 struct device *dev = &pdev->dev;
585 int ret;
586
587 card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL);
588 if (!card)
589 return -ENOMEM;
590
591 /* Allocate the private data */
592 data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
593 if (!data)
594 return -ENOMEM;
595
596 card->driver_name = DRIVER_NAME;
597 card->dapm_widgets = sdm845_snd_widgets;
598 card->num_dapm_widgets = ARRAY_SIZE(sdm845_snd_widgets);
599 card->controls = sdm845_snd_controls;
600 card->num_controls = ARRAY_SIZE(sdm845_snd_controls);
601 card->dev = dev;
602 card->owner = THIS_MODULE;
603 dev_set_drvdata(dev, card);
604 ret = qcom_snd_parse_of(card);
605 if (ret)
606 return ret;
607
608 data->card = card;
609 snd_soc_card_set_drvdata(card, data);
610
611 sdm845_add_ops(card);
612 return devm_snd_soc_register_card(dev, card);
613 }
614
615 static const struct of_device_id sdm845_snd_device_id[] = {
616 { .compatible = "qcom,sdm845-sndcard" },
617 /* Do not grow the list for compatible devices */
618 { .compatible = "qcom,db845c-sndcard" },
619 { .compatible = "lenovo,yoga-c630-sndcard" },
620 {},
621 };
622 MODULE_DEVICE_TABLE(of, sdm845_snd_device_id);
623
624 static struct platform_driver sdm845_snd_driver = {
625 .probe = sdm845_snd_platform_probe,
626 .driver = {
627 .name = "msm-snd-sdm845",
628 .of_match_table = sdm845_snd_device_id,
629 },
630 };
631 module_platform_driver(sdm845_snd_driver);
632
633 MODULE_DESCRIPTION("sdm845 ASoC Machine Driver");
634 MODULE_LICENSE("GPL");
635