blob: c4a3c5778b38994e1561630c8329687481d90f15 [file] [log] [blame]
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301/*
2 * byt_cr_dpcm_rt5640.c - ASoc Machine driver for Intel Byt CR platform
3 *
4 * Copyright (C) 2014 Intel Corp
5 * Author: Subhransu S. Prusty <subhransu.s.prusty@intel.com>
6 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18 */
19
20#include <linux/init.h>
21#include <linux/module.h>
22#include <linux/platform_device.h>
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -060023#include <linux/acpi.h>
Subhransu S. Prusty996cc842014-11-19 15:13:27 +053024#include <linux/device.h>
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -060025#include <linux/dmi.h>
Subhransu S. Prusty996cc842014-11-19 15:13:27 +053026#include <linux/slab.h>
Pierre-Louis Bossarte214f5e2016-08-12 16:27:53 -050027#include <asm/cpu_device_id.h>
28#include <asm/platform_sst_audio.h>
Subhransu S. Prusty996cc842014-11-19 15:13:27 +053029#include <sound/pcm.h>
30#include <sound/pcm_params.h>
31#include <sound/soc.h>
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -060032#include <sound/jack.h>
Jie Yange56c72d2015-04-02 15:37:02 +080033#include "../../codecs/rt5640.h"
Jie Yangb97169d2015-04-02 15:37:04 +080034#include "../atom/sst-atom-controls.h"
Pierre-Louis Bossartcaf94ed2016-01-04 17:20:28 -060035#include "../common/sst-acpi.h"
Pierre-Louis Bossarte214f5e2016-08-12 16:27:53 -050036#include "../common/sst-dsp.h"
Subhransu S. Prusty996cc842014-11-19 15:13:27 +053037
Pierre-Louis Bossartab738e42016-03-03 21:36:37 -060038enum {
39 BYT_RT5640_DMIC1_MAP,
40 BYT_RT5640_DMIC2_MAP,
41 BYT_RT5640_IN1_MAP,
42};
43
44#define BYT_RT5640_MAP(quirk) ((quirk) & 0xff)
45#define BYT_RT5640_DMIC_EN BIT(16)
Pierre-Louis Bossart68817cd2016-08-12 16:27:45 -050046#define BYT_RT5640_MONO_SPEAKER BIT(17)
Pierre-Louis Bossart5d98f582016-08-12 16:27:46 -050047#define BYT_RT5640_DIFF_MIC BIT(18) /* defaut is single-ended */
Pierre-Louis Bossart89b89072016-08-12 16:27:50 -050048#define BYT_RT5640_SSP2_AIF2 BIT(19) /* default is using AIF1 */
Pierre-Louis Bossartf47088d2016-08-12 16:27:51 -050049#define BYT_RT5640_SSP0_AIF1 BIT(20)
50#define BYT_RT5640_SSP0_AIF2 BIT(21)
Pierre-Louis Bossartab738e42016-03-03 21:36:37 -060051
52static unsigned long byt_rt5640_quirk = BYT_RT5640_DMIC1_MAP |
53 BYT_RT5640_DMIC_EN;
54
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -060055static const struct snd_soc_dapm_widget byt_rt5640_widgets[] = {
Subhransu S. Prusty996cc842014-11-19 15:13:27 +053056 SND_SOC_DAPM_HP("Headphone", NULL),
57 SND_SOC_DAPM_MIC("Headset Mic", NULL),
Pierre-Louis Bossarte2be1da2015-12-17 20:35:40 -060058 SND_SOC_DAPM_MIC("Internal Mic", NULL),
59 SND_SOC_DAPM_SPK("Speaker", NULL),
Subhransu S. Prusty996cc842014-11-19 15:13:27 +053060};
61
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -060062static const struct snd_soc_dapm_route byt_rt5640_audio_map[] = {
Subhransu S. Prusty996cc842014-11-19 15:13:27 +053063 {"Headset Mic", NULL, "MICBIAS1"},
Pierre-Louis Bossarte2be1da2015-12-17 20:35:40 -060064 {"IN2P", NULL, "Headset Mic"},
Subhransu S. Prusty996cc842014-11-19 15:13:27 +053065 {"Headphone", NULL, "HPOL"},
66 {"Headphone", NULL, "HPOR"},
Subhransu S. Prusty996cc842014-11-19 15:13:27 +053067};
68
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -060069static const struct snd_soc_dapm_route byt_rt5640_intmic_dmic1_map[] = {
70 {"DMIC1", NULL, "Internal Mic"},
71};
72
73static const struct snd_soc_dapm_route byt_rt5640_intmic_dmic2_map[] = {
74 {"DMIC2", NULL, "Internal Mic"},
75};
76
77static const struct snd_soc_dapm_route byt_rt5640_intmic_in1_map[] = {
78 {"Internal Mic", NULL, "MICBIAS1"},
79 {"IN1P", NULL, "Internal Mic"},
80};
81
Pierre-Louis Bossart89b89072016-08-12 16:27:50 -050082static const struct snd_soc_dapm_route byt_rt5640_ssp2_aif1_map[] = {
83 {"ssp2 Tx", NULL, "codec_out0"},
84 {"ssp2 Tx", NULL, "codec_out1"},
85 {"codec_in0", NULL, "ssp2 Rx"},
86 {"codec_in1", NULL, "ssp2 Rx"},
87
88 {"AIF1 Playback", NULL, "ssp2 Tx"},
89 {"ssp2 Rx", NULL, "AIF1 Capture"},
90};
91
92static const struct snd_soc_dapm_route byt_rt5640_ssp2_aif2_map[] = {
93 {"ssp2 Tx", NULL, "codec_out0"},
94 {"ssp2 Tx", NULL, "codec_out1"},
95 {"codec_in0", NULL, "ssp2 Rx"},
96 {"codec_in1", NULL, "ssp2 Rx"},
97
98 {"AIF2 Playback", NULL, "ssp2 Tx"},
99 {"ssp2 Rx", NULL, "AIF2 Capture"},
100};
101
Pierre-Louis Bossartf47088d2016-08-12 16:27:51 -0500102static const struct snd_soc_dapm_route byt_rt5640_ssp0_aif1_map[] = {
103 {"ssp0 Tx", NULL, "modem_out"},
104 {"modem_in", NULL, "ssp0 Rx"},
105
106 {"AIF1 Playback", NULL, "ssp0 Tx"},
107 {"ssp0 Rx", NULL, "AIF1 Capture"},
108};
109
110static const struct snd_soc_dapm_route byt_rt5640_ssp0_aif2_map[] = {
111 {"ssp0 Tx", NULL, "modem_out"},
112 {"modem_in", NULL, "ssp0 Rx"},
113
114 {"AIF2 Playback", NULL, "ssp0 Tx"},
115 {"ssp0 Rx", NULL, "AIF2 Capture"},
116};
117
Pierre-Louis Bossart68817cd2016-08-12 16:27:45 -0500118static const struct snd_soc_dapm_route byt_rt5640_stereo_spk_map[] = {
119 {"Speaker", NULL, "SPOLP"},
120 {"Speaker", NULL, "SPOLN"},
121 {"Speaker", NULL, "SPORP"},
122 {"Speaker", NULL, "SPORN"},
123};
124
125static const struct snd_soc_dapm_route byt_rt5640_mono_spk_map[] = {
126 {"Speaker", NULL, "SPOLP"},
127 {"Speaker", NULL, "SPOLN"},
128};
129
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600130static const struct snd_kcontrol_new byt_rt5640_controls[] = {
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530131 SOC_DAPM_PIN_SWITCH("Headphone"),
132 SOC_DAPM_PIN_SWITCH("Headset Mic"),
Pierre-Louis Bossarte2be1da2015-12-17 20:35:40 -0600133 SOC_DAPM_PIN_SWITCH("Internal Mic"),
134 SOC_DAPM_PIN_SWITCH("Speaker"),
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530135};
136
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600137static int byt_rt5640_aif1_hw_params(struct snd_pcm_substream *substream,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530138 struct snd_pcm_hw_params *params)
139{
140 struct snd_soc_pcm_runtime *rtd = substream->private_data;
141 struct snd_soc_dai *codec_dai = rtd->codec_dai;
142 int ret;
143
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530144 ret = snd_soc_dai_set_sysclk(codec_dai, RT5640_SCLK_S_PLL1,
145 params_rate(params) * 512,
146 SND_SOC_CLOCK_IN);
147 if (ret < 0) {
148 dev_err(rtd->dev, "can't set codec clock %d\n", ret);
149 return ret;
150 }
151
Pierre-Louis Bossart038a50e2016-08-12 16:27:52 -0500152 if ((byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) ||
153 (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2)) {
154
155 ret = snd_soc_dai_set_pll(codec_dai, 0, RT5640_PLL1_S_BCLK1,
156 params_rate(params) * 32, /* FIXME */
157 params_rate(params) * 512);
158 } else {
159 ret = snd_soc_dai_set_pll(codec_dai, 0, RT5640_PLL1_S_BCLK1,
160 params_rate(params) * 50,
161 params_rate(params) * 512);
162 }
163
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530164 if (ret < 0) {
165 dev_err(rtd->dev, "can't set codec pll: %d\n", ret);
166 return ret;
167 }
168
169 return 0;
170}
171
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600172static int byt_rt5640_quirk_cb(const struct dmi_system_id *id)
173{
174 byt_rt5640_quirk = (unsigned long)id->driver_data;
175 return 1;
176}
177
178static const struct dmi_system_id byt_rt5640_quirk_table[] = {
179 {
180 .callback = byt_rt5640_quirk_cb,
181 .matches = {
Pierre-Louis Bossart73442e32016-08-12 16:27:44 -0500182 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
183 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "T100TA"),
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600184 },
185 .driver_data = (unsigned long *)BYT_RT5640_IN1_MAP,
186 },
187 {
188 .callback = byt_rt5640_quirk_cb,
189 .matches = {
Pierre-Louis Bossart73442e32016-08-12 16:27:44 -0500190 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
191 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "T100TAF"),
192 },
Pierre-Louis Bossart68817cd2016-08-12 16:27:45 -0500193 .driver_data = (unsigned long *)(BYT_RT5640_IN1_MAP |
Pierre-Louis Bossart5d98f582016-08-12 16:27:46 -0500194 BYT_RT5640_MONO_SPEAKER |
Pierre-Louis Bossarte214f5e2016-08-12 16:27:53 -0500195 BYT_RT5640_DIFF_MIC |
196 BYT_RT5640_SSP0_AIF2
Pierre-Louis Bossart68817cd2016-08-12 16:27:45 -0500197 ),
Pierre-Louis Bossart73442e32016-08-12 16:27:44 -0500198 },
199 {
200 .callback = byt_rt5640_quirk_cb,
201 .matches = {
202 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "DellInc."),
203 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Venue 8 Pro 5830"),
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600204 },
205 .driver_data = (unsigned long *)(BYT_RT5640_DMIC2_MAP |
206 BYT_RT5640_DMIC_EN),
207 },
Jorge Fernandez Monteagudo55fc2052016-01-04 17:20:30 -0600208 {
209 .callback = byt_rt5640_quirk_cb,
210 .matches = {
Pierre-Louis Bossart73442e32016-08-12 16:27:44 -0500211 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
212 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "HP ElitePad 1000 G2"),
Jorge Fernandez Monteagudo55fc2052016-01-04 17:20:30 -0600213 },
214 .driver_data = (unsigned long *)BYT_RT5640_IN1_MAP,
215 },
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600216 {}
217};
218
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -0600219static int byt_rt5640_init(struct snd_soc_pcm_runtime *runtime)
220{
221 int ret;
222 struct snd_soc_codec *codec = runtime->codec;
223 struct snd_soc_card *card = runtime->card;
224 const struct snd_soc_dapm_route *custom_map;
225 int num_routes;
226
227 card->dapm.idle_bias_off = true;
228
Pierre-Louis Bossart0ec66e2d2016-01-04 17:20:27 -0600229 rt5640_sel_asrc_clk_src(codec,
230 RT5640_DA_STEREO_FILTER |
231 RT5640_AD_STEREO_FILTER,
232 RT5640_CLK_SEL_ASRC);
233
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -0600234 ret = snd_soc_add_card_controls(card, byt_rt5640_controls,
235 ARRAY_SIZE(byt_rt5640_controls));
236 if (ret) {
237 dev_err(card->dev, "unable to add card controls\n");
238 return ret;
239 }
240
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -0600241 switch (BYT_RT5640_MAP(byt_rt5640_quirk)) {
242 case BYT_RT5640_IN1_MAP:
243 custom_map = byt_rt5640_intmic_in1_map;
244 num_routes = ARRAY_SIZE(byt_rt5640_intmic_in1_map);
245 break;
246 case BYT_RT5640_DMIC2_MAP:
247 custom_map = byt_rt5640_intmic_dmic2_map;
248 num_routes = ARRAY_SIZE(byt_rt5640_intmic_dmic2_map);
249 break;
250 default:
251 custom_map = byt_rt5640_intmic_dmic1_map;
252 num_routes = ARRAY_SIZE(byt_rt5640_intmic_dmic1_map);
253 }
254
255 ret = snd_soc_dapm_add_routes(&card->dapm, custom_map, num_routes);
256 if (ret)
257 return ret;
258
Pierre-Louis Bossart89b89072016-08-12 16:27:50 -0500259 if (byt_rt5640_quirk & BYT_RT5640_SSP2_AIF2) {
260 ret = snd_soc_dapm_add_routes(&card->dapm,
261 byt_rt5640_ssp2_aif2_map,
262 ARRAY_SIZE(byt_rt5640_ssp2_aif2_map));
Pierre-Louis Bossartf47088d2016-08-12 16:27:51 -0500263 } else if (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) {
264 ret = snd_soc_dapm_add_routes(&card->dapm,
265 byt_rt5640_ssp0_aif1_map,
266 ARRAY_SIZE(byt_rt5640_ssp0_aif1_map));
267 } else if (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2) {
268 ret = snd_soc_dapm_add_routes(&card->dapm,
269 byt_rt5640_ssp0_aif2_map,
270 ARRAY_SIZE(byt_rt5640_ssp0_aif2_map));
Pierre-Louis Bossart89b89072016-08-12 16:27:50 -0500271 } else {
272 ret = snd_soc_dapm_add_routes(&card->dapm,
273 byt_rt5640_ssp2_aif1_map,
274 ARRAY_SIZE(byt_rt5640_ssp2_aif1_map));
275 }
276 if (ret)
277 return ret;
278
Pierre-Louis Bossart68817cd2016-08-12 16:27:45 -0500279 if (byt_rt5640_quirk & BYT_RT5640_MONO_SPEAKER) {
280 ret = snd_soc_dapm_add_routes(&card->dapm,
281 byt_rt5640_mono_spk_map,
282 ARRAY_SIZE(byt_rt5640_mono_spk_map));
283 } else {
284 ret = snd_soc_dapm_add_routes(&card->dapm,
285 byt_rt5640_stereo_spk_map,
286 ARRAY_SIZE(byt_rt5640_stereo_spk_map));
287 }
288 if (ret)
289 return ret;
290
Pierre-Louis Bossart5d98f582016-08-12 16:27:46 -0500291 if (byt_rt5640_quirk & BYT_RT5640_DIFF_MIC) {
292 snd_soc_update_bits(codec, RT5640_IN1_IN2, RT5640_IN_DF1,
293 RT5640_IN_DF1);
294 }
295
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -0600296 if (byt_rt5640_quirk & BYT_RT5640_DMIC_EN) {
297 ret = rt5640_dmic_enable(codec, 0, 0);
298 if (ret)
299 return ret;
300 }
301
302 snd_soc_dapm_ignore_suspend(&card->dapm, "Headphone");
303 snd_soc_dapm_ignore_suspend(&card->dapm, "Speaker");
304
305 return ret;
306}
307
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600308static const struct snd_soc_pcm_stream byt_rt5640_dai_params = {
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530309 .formats = SNDRV_PCM_FMTBIT_S24_LE,
310 .rate_min = 48000,
311 .rate_max = 48000,
312 .channels_min = 2,
313 .channels_max = 2,
314};
315
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600316static int byt_rt5640_codec_fixup(struct snd_soc_pcm_runtime *rtd,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530317 struct snd_pcm_hw_params *params)
318{
319 struct snd_interval *rate = hw_param_interval(params,
320 SNDRV_PCM_HW_PARAM_RATE);
321 struct snd_interval *channels = hw_param_interval(params,
322 SNDRV_PCM_HW_PARAM_CHANNELS);
Sebastien Guiriec3f27ded2015-12-17 20:35:39 -0600323 int ret;
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530324
Pierre-Louis Bossart038a50e2016-08-12 16:27:52 -0500325 /* The DSP will covert the FE rate to 48k, stereo */
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530326 rate->min = rate->max = 48000;
327 channels->min = channels->max = 2;
328
Pierre-Louis Bossart038a50e2016-08-12 16:27:52 -0500329 if ((byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) ||
330 (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2)) {
Sebastien Guiriec3f27ded2015-12-17 20:35:39 -0600331
Pierre-Louis Bossart038a50e2016-08-12 16:27:52 -0500332 /* set SSP2 to 16-bit */
333 params_set_format(params, SNDRV_PCM_FORMAT_S16_LE);
334
335 /*
336 * Default mode for SSP configuration is TDM 4 slot, override config
337 * with explicit setting to I2S 2ch 16-bit. The word length is set with
338 * dai_set_tdm_slot() since there is no other API exposed
339 */
340 ret = snd_soc_dai_set_fmt(rtd->cpu_dai,
341 SND_SOC_DAIFMT_I2S |
342 SND_SOC_DAIFMT_NB_IF |
343 SND_SOC_DAIFMT_CBS_CFS
344 );
345 if (ret < 0) {
346 dev_err(rtd->dev, "can't set format to I2S, err %d\n", ret);
347 return ret;
348 }
349
350 ret = snd_soc_dai_set_tdm_slot(rtd->cpu_dai, 0x3, 0x3, 2, 16);
351 if (ret < 0) {
352 dev_err(rtd->dev, "can't set I2S config, err %d\n", ret);
353 return ret;
354 }
355
356 } else {
357
358 /* set SSP2 to 24-bit */
359 params_set_format(params, SNDRV_PCM_FORMAT_S24_LE);
360
361 /*
362 * Default mode for SSP configuration is TDM 4 slot, override config
363 * with explicit setting to I2S 2ch 24-bit. The word length is set with
364 * dai_set_tdm_slot() since there is no other API exposed
365 */
366 ret = snd_soc_dai_set_fmt(rtd->cpu_dai,
367 SND_SOC_DAIFMT_I2S |
368 SND_SOC_DAIFMT_NB_IF |
369 SND_SOC_DAIFMT_CBS_CFS
370 );
371 if (ret < 0) {
372 dev_err(rtd->dev, "can't set format to I2S, err %d\n", ret);
373 return ret;
374 }
375
376 ret = snd_soc_dai_set_tdm_slot(rtd->cpu_dai, 0x3, 0x3, 2, 24);
377 if (ret < 0) {
378 dev_err(rtd->dev, "can't set I2S config, err %d\n", ret);
379 return ret;
380 }
Sebastien Guiriec3f27ded2015-12-17 20:35:39 -0600381 }
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530382 return 0;
383}
384
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600385static int byt_rt5640_aif1_startup(struct snd_pcm_substream *substream)
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530386{
Lars-Peter Clausend0a1b662015-10-18 15:39:30 +0200387 return snd_pcm_hw_constraint_single(substream->runtime,
388 SNDRV_PCM_HW_PARAM_RATE, 48000);
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530389}
390
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600391static struct snd_soc_ops byt_rt5640_aif1_ops = {
392 .startup = byt_rt5640_aif1_startup,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530393};
394
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600395static struct snd_soc_ops byt_rt5640_be_ssp2_ops = {
396 .hw_params = byt_rt5640_aif1_hw_params,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530397};
398
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600399static struct snd_soc_dai_link byt_rt5640_dais[] = {
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530400 [MERR_DPCM_AUDIO] = {
401 .name = "Baytrail Audio Port",
402 .stream_name = "Baytrail Audio",
403 .cpu_dai_name = "media-cpu-dai",
404 .codec_dai_name = "snd-soc-dummy-dai",
405 .codec_name = "snd-soc-dummy",
406 .platform_name = "sst-mfld-platform",
407 .ignore_suspend = 1,
408 .dynamic = 1,
409 .dpcm_playback = 1,
410 .dpcm_capture = 1,
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600411 .ops = &byt_rt5640_aif1_ops,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530412 },
Pierre-Louis Bossartd35eb962015-12-17 20:35:45 -0600413 [MERR_DPCM_DEEP_BUFFER] = {
414 .name = "Deep-Buffer Audio Port",
415 .stream_name = "Deep-Buffer Audio",
416 .cpu_dai_name = "deepbuffer-cpu-dai",
417 .codec_dai_name = "snd-soc-dummy-dai",
418 .codec_name = "snd-soc-dummy",
419 .platform_name = "sst-mfld-platform",
420 .ignore_suspend = 1,
421 .nonatomic = true,
422 .dynamic = 1,
423 .dpcm_playback = 1,
424 .ops = &byt_rt5640_aif1_ops,
425 },
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530426 [MERR_DPCM_COMPR] = {
427 .name = "Baytrail Compressed Port",
428 .stream_name = "Baytrail Compress",
429 .cpu_dai_name = "compress-cpu-dai",
430 .codec_dai_name = "snd-soc-dummy-dai",
431 .codec_name = "snd-soc-dummy",
432 .platform_name = "sst-mfld-platform",
433 },
434 /* back ends */
435 {
436 .name = "SSP2-Codec",
Mengdong Lin2f0ad492016-04-19 13:12:35 +0800437 .id = 1,
Pierre-Louis Bossartf47088d2016-08-12 16:27:51 -0500438 .cpu_dai_name = "ssp2-port", /* overwritten for ssp0 routing */
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530439 .platform_name = "sst-mfld-platform",
440 .no_pcm = 1,
Pierre-Louis Bossart89b89072016-08-12 16:27:50 -0500441 .codec_dai_name = "rt5640-aif1", /* changed w/ quirk */
Pierre-Louis Bossart7762ef42016-01-04 17:20:29 -0600442 .codec_name = "i2c-10EC5640:00", /* overwritten with HID */
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530443 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
444 | SND_SOC_DAIFMT_CBS_CFS,
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600445 .be_hw_params_fixup = byt_rt5640_codec_fixup,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530446 .ignore_suspend = 1,
447 .dpcm_playback = 1,
448 .dpcm_capture = 1,
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -0600449 .init = byt_rt5640_init,
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600450 .ops = &byt_rt5640_be_ssp2_ops,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530451 },
452};
453
454/* SoC card */
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -0600455static struct snd_soc_card byt_rt5640_card = {
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600456 .name = "bytcr-rt5640",
Axel Lin54d86972015-08-21 20:59:21 +0800457 .owner = THIS_MODULE,
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600458 .dai_link = byt_rt5640_dais,
459 .num_links = ARRAY_SIZE(byt_rt5640_dais),
460 .dapm_widgets = byt_rt5640_widgets,
461 .num_dapm_widgets = ARRAY_SIZE(byt_rt5640_widgets),
462 .dapm_routes = byt_rt5640_audio_map,
463 .num_dapm_routes = ARRAY_SIZE(byt_rt5640_audio_map),
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -0600464 .fully_routed = true,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530465};
466
Pierre-Louis Bossartcaf94ed2016-01-04 17:20:28 -0600467static char byt_rt5640_codec_name[16]; /* i2c-<HID>:00 with HID being 8 chars */
Pierre-Louis Bossart89b89072016-08-12 16:27:50 -0500468static char byt_rt5640_codec_aif_name[12]; /* = "rt5640-aif[1|2]" */
Pierre-Louis Bossartf47088d2016-08-12 16:27:51 -0500469static char byt_rt5640_cpu_dai_name[10]; /* = "ssp[0|2]-port" */
Pierre-Louis Bossartcaf94ed2016-01-04 17:20:28 -0600470
Pierre-Louis Bossarte214f5e2016-08-12 16:27:53 -0500471static bool is_valleyview(void)
472{
473 static const struct x86_cpu_id cpu_ids[] __initconst = {
474 { X86_VENDOR_INTEL, 6, 55 }, /* Valleyview, Bay Trail */
475 {}
476 };
477
478 if (!x86_match_cpu(cpu_ids))
479 return false;
480 return true;
481}
482
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600483static int snd_byt_rt5640_mc_probe(struct platform_device *pdev)
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530484{
485 int ret_val = 0;
Pierre-Louis Bossartcaf94ed2016-01-04 17:20:28 -0600486 struct sst_acpi_mach *mach;
Pierre-Louis Bossarta232b962016-03-03 21:36:38 -0600487 const char *i2c_name = NULL;
488 int i;
489 int dai_index;
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530490
491 /* register the soc card */
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -0600492 byt_rt5640_card.dev = &pdev->dev;
Pierre-Louis Bossartcaf94ed2016-01-04 17:20:28 -0600493 mach = byt_rt5640_card.dev->platform_data;
494
Pierre-Louis Bossarta232b962016-03-03 21:36:38 -0600495 /* fix index of codec dai */
496 dai_index = MERR_DPCM_COMPR + 1;
497 for (i = 0; i < ARRAY_SIZE(byt_rt5640_dais); i++) {
498 if (!strcmp(byt_rt5640_dais[i].codec_name, "i2c-10EC5640:00")) {
499 dai_index = i;
500 break;
501 }
502 }
503
Pierre-Louis Bossartcaf94ed2016-01-04 17:20:28 -0600504 /* fixup codec name based on HID */
Pierre-Louis Bossarta232b962016-03-03 21:36:38 -0600505 i2c_name = sst_acpi_find_name_from_hid(mach->id);
506 if (i2c_name != NULL) {
507 snprintf(byt_rt5640_codec_name, sizeof(byt_rt5640_codec_name),
508 "%s%s", "i2c-", i2c_name);
509
510 byt_rt5640_dais[dai_index].codec_name = byt_rt5640_codec_name;
511 }
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530512
Pierre-Louis Bossarte214f5e2016-08-12 16:27:53 -0500513 /*
514 * swap SSP0 if bytcr is detected
515 * (will be overridden if DMI quirk is detected)
516 */
517 if (is_valleyview()) {
518 struct sst_platform_info *p_info = mach->pdata;
519 const struct sst_res_info *res_info = p_info->res_info;
520
521 /* TODO: use CHAN package info from BIOS to detect AIF1/AIF2 */
522 if (res_info->acpi_ipc_irq_index == 0) {
523 byt_rt5640_quirk |= BYT_RT5640_SSP0_AIF2;
524 }
525 }
526
Pierre-Louis Bossartab738e42016-03-03 21:36:37 -0600527 /* check quirks before creating card */
528 dmi_check_system(byt_rt5640_quirk_table);
529
Pierre-Louis Bossartf47088d2016-08-12 16:27:51 -0500530 if ((byt_rt5640_quirk & BYT_RT5640_SSP2_AIF2) ||
531 (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2)) {
Pierre-Louis Bossart89b89072016-08-12 16:27:50 -0500532
533 /* fixup codec aif name */
534 snprintf(byt_rt5640_codec_aif_name,
535 sizeof(byt_rt5640_codec_aif_name),
536 "%s", "rt5640-aif2");
537
538 byt_rt5640_dais[dai_index].codec_dai_name =
539 byt_rt5640_codec_aif_name;
540 }
541
Pierre-Louis Bossartf47088d2016-08-12 16:27:51 -0500542 if ((byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) ||
543 (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2)) {
544
545 /* fixup cpu dai name name */
546 snprintf(byt_rt5640_cpu_dai_name,
547 sizeof(byt_rt5640_cpu_dai_name),
548 "%s", "ssp0-port");
549
550 byt_rt5640_dais[dai_index].cpu_dai_name =
551 byt_rt5640_cpu_dai_name;
552 }
553
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -0600554 ret_val = devm_snd_soc_register_card(&pdev->dev, &byt_rt5640_card);
555
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530556 if (ret_val) {
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600557 dev_err(&pdev->dev, "devm_snd_soc_register_card failed %d\n",
558 ret_val);
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530559 return ret_val;
560 }
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -0600561 platform_set_drvdata(pdev, &byt_rt5640_card);
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530562 return ret_val;
563}
564
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600565static struct platform_driver snd_byt_rt5640_mc_driver = {
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530566 .driver = {
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600567 .name = "bytcr_rt5640",
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530568 .pm = &snd_soc_pm_ops,
569 },
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600570 .probe = snd_byt_rt5640_mc_probe,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530571};
572
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600573module_platform_driver(snd_byt_rt5640_mc_driver);
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530574
575MODULE_DESCRIPTION("ASoC Intel(R) Baytrail CR Machine driver");
576MODULE_AUTHOR("Subhransu S. Prusty <subhransu.s.prusty@intel.com>");
577MODULE_LICENSE("GPL v2");
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600578MODULE_ALIAS("platform:bytcr_rt5640");