blob: 6c6f67356c99e5eecfe4ee407526a370a0437b9d [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>
Subhransu S. Prusty996cc842014-11-19 15:13:27 +053027#include <sound/pcm.h>
28#include <sound/pcm_params.h>
29#include <sound/soc.h>
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -060030#include <sound/jack.h>
Jie Yange56c72d2015-04-02 15:37:02 +080031#include "../../codecs/rt5640.h"
Jie Yangb97169d2015-04-02 15:37:04 +080032#include "../atom/sst-atom-controls.h"
Pierre-Louis Bossartcaf94ed2016-01-04 17:20:28 -060033#include "../common/sst-acpi.h"
Subhransu S. Prusty996cc842014-11-19 15:13:27 +053034
Pierre-Louis Bossartab738e42016-03-03 21:36:37 -060035enum {
36 BYT_RT5640_DMIC1_MAP,
37 BYT_RT5640_DMIC2_MAP,
38 BYT_RT5640_IN1_MAP,
39};
40
41#define BYT_RT5640_MAP(quirk) ((quirk) & 0xff)
42#define BYT_RT5640_DMIC_EN BIT(16)
Pierre-Louis Bossart68817cd2016-08-12 16:27:45 -050043#define BYT_RT5640_MONO_SPEAKER BIT(17)
Pierre-Louis Bossart5d98f582016-08-12 16:27:46 -050044#define BYT_RT5640_DIFF_MIC BIT(18) /* defaut is single-ended */
Pierre-Louis Bossart89b89072016-08-12 16:27:50 -050045#define BYT_RT5640_SSP2_AIF2 BIT(19) /* default is using AIF1 */
Pierre-Louis Bossartab738e42016-03-03 21:36:37 -060046
47static unsigned long byt_rt5640_quirk = BYT_RT5640_DMIC1_MAP |
48 BYT_RT5640_DMIC_EN;
49
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -060050static const struct snd_soc_dapm_widget byt_rt5640_widgets[] = {
Subhransu S. Prusty996cc842014-11-19 15:13:27 +053051 SND_SOC_DAPM_HP("Headphone", NULL),
52 SND_SOC_DAPM_MIC("Headset Mic", NULL),
Pierre-Louis Bossarte2be1da2015-12-17 20:35:40 -060053 SND_SOC_DAPM_MIC("Internal Mic", NULL),
54 SND_SOC_DAPM_SPK("Speaker", NULL),
Subhransu S. Prusty996cc842014-11-19 15:13:27 +053055};
56
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -060057static const struct snd_soc_dapm_route byt_rt5640_audio_map[] = {
Subhransu S. Prusty996cc842014-11-19 15:13:27 +053058 {"Headset Mic", NULL, "MICBIAS1"},
Pierre-Louis Bossarte2be1da2015-12-17 20:35:40 -060059 {"IN2P", NULL, "Headset Mic"},
Subhransu S. Prusty996cc842014-11-19 15:13:27 +053060 {"Headphone", NULL, "HPOL"},
61 {"Headphone", NULL, "HPOR"},
Subhransu S. Prusty996cc842014-11-19 15:13:27 +053062};
63
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -060064static const struct snd_soc_dapm_route byt_rt5640_intmic_dmic1_map[] = {
65 {"DMIC1", NULL, "Internal Mic"},
66};
67
68static const struct snd_soc_dapm_route byt_rt5640_intmic_dmic2_map[] = {
69 {"DMIC2", NULL, "Internal Mic"},
70};
71
72static const struct snd_soc_dapm_route byt_rt5640_intmic_in1_map[] = {
73 {"Internal Mic", NULL, "MICBIAS1"},
74 {"IN1P", NULL, "Internal Mic"},
75};
76
Pierre-Louis Bossart89b89072016-08-12 16:27:50 -050077static const struct snd_soc_dapm_route byt_rt5640_ssp2_aif1_map[] = {
78 {"ssp2 Tx", NULL, "codec_out0"},
79 {"ssp2 Tx", NULL, "codec_out1"},
80 {"codec_in0", NULL, "ssp2 Rx"},
81 {"codec_in1", NULL, "ssp2 Rx"},
82
83 {"AIF1 Playback", NULL, "ssp2 Tx"},
84 {"ssp2 Rx", NULL, "AIF1 Capture"},
85};
86
87static const struct snd_soc_dapm_route byt_rt5640_ssp2_aif2_map[] = {
88 {"ssp2 Tx", NULL, "codec_out0"},
89 {"ssp2 Tx", NULL, "codec_out1"},
90 {"codec_in0", NULL, "ssp2 Rx"},
91 {"codec_in1", NULL, "ssp2 Rx"},
92
93 {"AIF2 Playback", NULL, "ssp2 Tx"},
94 {"ssp2 Rx", NULL, "AIF2 Capture"},
95};
96
Pierre-Louis Bossart68817cd2016-08-12 16:27:45 -050097static const struct snd_soc_dapm_route byt_rt5640_stereo_spk_map[] = {
98 {"Speaker", NULL, "SPOLP"},
99 {"Speaker", NULL, "SPOLN"},
100 {"Speaker", NULL, "SPORP"},
101 {"Speaker", NULL, "SPORN"},
102};
103
104static const struct snd_soc_dapm_route byt_rt5640_mono_spk_map[] = {
105 {"Speaker", NULL, "SPOLP"},
106 {"Speaker", NULL, "SPOLN"},
107};
108
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600109static const struct snd_kcontrol_new byt_rt5640_controls[] = {
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530110 SOC_DAPM_PIN_SWITCH("Headphone"),
111 SOC_DAPM_PIN_SWITCH("Headset Mic"),
Pierre-Louis Bossarte2be1da2015-12-17 20:35:40 -0600112 SOC_DAPM_PIN_SWITCH("Internal Mic"),
113 SOC_DAPM_PIN_SWITCH("Speaker"),
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530114};
115
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600116static int byt_rt5640_aif1_hw_params(struct snd_pcm_substream *substream,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530117 struct snd_pcm_hw_params *params)
118{
119 struct snd_soc_pcm_runtime *rtd = substream->private_data;
120 struct snd_soc_dai *codec_dai = rtd->codec_dai;
121 int ret;
122
123 snd_soc_dai_set_bclk_ratio(codec_dai, 50);
124
125 ret = snd_soc_dai_set_sysclk(codec_dai, RT5640_SCLK_S_PLL1,
126 params_rate(params) * 512,
127 SND_SOC_CLOCK_IN);
128 if (ret < 0) {
129 dev_err(rtd->dev, "can't set codec clock %d\n", ret);
130 return ret;
131 }
132
133 ret = snd_soc_dai_set_pll(codec_dai, 0, RT5640_PLL1_S_BCLK1,
134 params_rate(params) * 50,
135 params_rate(params) * 512);
136 if (ret < 0) {
137 dev_err(rtd->dev, "can't set codec pll: %d\n", ret);
138 return ret;
139 }
140
141 return 0;
142}
143
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600144static int byt_rt5640_quirk_cb(const struct dmi_system_id *id)
145{
146 byt_rt5640_quirk = (unsigned long)id->driver_data;
147 return 1;
148}
149
150static const struct dmi_system_id byt_rt5640_quirk_table[] = {
151 {
152 .callback = byt_rt5640_quirk_cb,
153 .matches = {
Pierre-Louis Bossart73442e32016-08-12 16:27:44 -0500154 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
155 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "T100TA"),
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600156 },
157 .driver_data = (unsigned long *)BYT_RT5640_IN1_MAP,
158 },
159 {
160 .callback = byt_rt5640_quirk_cb,
161 .matches = {
Pierre-Louis Bossart73442e32016-08-12 16:27:44 -0500162 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
163 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "T100TAF"),
164 },
Pierre-Louis Bossart68817cd2016-08-12 16:27:45 -0500165 .driver_data = (unsigned long *)(BYT_RT5640_IN1_MAP |
Pierre-Louis Bossart5d98f582016-08-12 16:27:46 -0500166 BYT_RT5640_MONO_SPEAKER |
167 BYT_RT5640_DIFF_MIC
Pierre-Louis Bossart68817cd2016-08-12 16:27:45 -0500168 ),
Pierre-Louis Bossart73442e32016-08-12 16:27:44 -0500169 },
170 {
171 .callback = byt_rt5640_quirk_cb,
172 .matches = {
173 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "DellInc."),
174 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Venue 8 Pro 5830"),
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600175 },
176 .driver_data = (unsigned long *)(BYT_RT5640_DMIC2_MAP |
177 BYT_RT5640_DMIC_EN),
178 },
Jorge Fernandez Monteagudo55fc2052016-01-04 17:20:30 -0600179 {
180 .callback = byt_rt5640_quirk_cb,
181 .matches = {
Pierre-Louis Bossart73442e32016-08-12 16:27:44 -0500182 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
183 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "HP ElitePad 1000 G2"),
Jorge Fernandez Monteagudo55fc2052016-01-04 17:20:30 -0600184 },
185 .driver_data = (unsigned long *)BYT_RT5640_IN1_MAP,
186 },
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600187 {}
188};
189
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -0600190static int byt_rt5640_init(struct snd_soc_pcm_runtime *runtime)
191{
192 int ret;
193 struct snd_soc_codec *codec = runtime->codec;
194 struct snd_soc_card *card = runtime->card;
195 const struct snd_soc_dapm_route *custom_map;
196 int num_routes;
197
198 card->dapm.idle_bias_off = true;
199
Pierre-Louis Bossart0ec66e2d2016-01-04 17:20:27 -0600200 rt5640_sel_asrc_clk_src(codec,
201 RT5640_DA_STEREO_FILTER |
202 RT5640_AD_STEREO_FILTER,
203 RT5640_CLK_SEL_ASRC);
204
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -0600205 ret = snd_soc_add_card_controls(card, byt_rt5640_controls,
206 ARRAY_SIZE(byt_rt5640_controls));
207 if (ret) {
208 dev_err(card->dev, "unable to add card controls\n");
209 return ret;
210 }
211
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -0600212 switch (BYT_RT5640_MAP(byt_rt5640_quirk)) {
213 case BYT_RT5640_IN1_MAP:
214 custom_map = byt_rt5640_intmic_in1_map;
215 num_routes = ARRAY_SIZE(byt_rt5640_intmic_in1_map);
216 break;
217 case BYT_RT5640_DMIC2_MAP:
218 custom_map = byt_rt5640_intmic_dmic2_map;
219 num_routes = ARRAY_SIZE(byt_rt5640_intmic_dmic2_map);
220 break;
221 default:
222 custom_map = byt_rt5640_intmic_dmic1_map;
223 num_routes = ARRAY_SIZE(byt_rt5640_intmic_dmic1_map);
224 }
225
226 ret = snd_soc_dapm_add_routes(&card->dapm, custom_map, num_routes);
227 if (ret)
228 return ret;
229
Pierre-Louis Bossart89b89072016-08-12 16:27:50 -0500230 if (byt_rt5640_quirk & BYT_RT5640_SSP2_AIF2) {
231 ret = snd_soc_dapm_add_routes(&card->dapm,
232 byt_rt5640_ssp2_aif2_map,
233 ARRAY_SIZE(byt_rt5640_ssp2_aif2_map));
234 } else {
235 ret = snd_soc_dapm_add_routes(&card->dapm,
236 byt_rt5640_ssp2_aif1_map,
237 ARRAY_SIZE(byt_rt5640_ssp2_aif1_map));
238 }
239 if (ret)
240 return ret;
241
Pierre-Louis Bossart68817cd2016-08-12 16:27:45 -0500242 if (byt_rt5640_quirk & BYT_RT5640_MONO_SPEAKER) {
243 ret = snd_soc_dapm_add_routes(&card->dapm,
244 byt_rt5640_mono_spk_map,
245 ARRAY_SIZE(byt_rt5640_mono_spk_map));
246 } else {
247 ret = snd_soc_dapm_add_routes(&card->dapm,
248 byt_rt5640_stereo_spk_map,
249 ARRAY_SIZE(byt_rt5640_stereo_spk_map));
250 }
251 if (ret)
252 return ret;
253
Pierre-Louis Bossart5d98f582016-08-12 16:27:46 -0500254 if (byt_rt5640_quirk & BYT_RT5640_DIFF_MIC) {
255 snd_soc_update_bits(codec, RT5640_IN1_IN2, RT5640_IN_DF1,
256 RT5640_IN_DF1);
257 }
258
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -0600259 if (byt_rt5640_quirk & BYT_RT5640_DMIC_EN) {
260 ret = rt5640_dmic_enable(codec, 0, 0);
261 if (ret)
262 return ret;
263 }
264
265 snd_soc_dapm_ignore_suspend(&card->dapm, "Headphone");
266 snd_soc_dapm_ignore_suspend(&card->dapm, "Speaker");
267
268 return ret;
269}
270
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600271static const struct snd_soc_pcm_stream byt_rt5640_dai_params = {
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530272 .formats = SNDRV_PCM_FMTBIT_S24_LE,
273 .rate_min = 48000,
274 .rate_max = 48000,
275 .channels_min = 2,
276 .channels_max = 2,
277};
278
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600279static int byt_rt5640_codec_fixup(struct snd_soc_pcm_runtime *rtd,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530280 struct snd_pcm_hw_params *params)
281{
282 struct snd_interval *rate = hw_param_interval(params,
283 SNDRV_PCM_HW_PARAM_RATE);
284 struct snd_interval *channels = hw_param_interval(params,
285 SNDRV_PCM_HW_PARAM_CHANNELS);
Sebastien Guiriec3f27ded2015-12-17 20:35:39 -0600286 int ret;
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530287
288 /* The DSP will covert the FE rate to 48k, stereo, 24bits */
289 rate->min = rate->max = 48000;
290 channels->min = channels->max = 2;
291
292 /* set SSP2 to 24-bit */
Fang, Yang A369a9f52015-02-09 00:18:12 -0800293 params_set_format(params, SNDRV_PCM_FORMAT_S24_LE);
Sebastien Guiriec3f27ded2015-12-17 20:35:39 -0600294
295 /*
296 * Default mode for SSP configuration is TDM 4 slot, override config
297 * with explicit setting to I2S 2ch 24-bit. The word length is set with
298 * dai_set_tdm_slot() since there is no other API exposed
299 */
300 ret = snd_soc_dai_set_fmt(rtd->cpu_dai,
301 SND_SOC_DAIFMT_I2S |
302 SND_SOC_DAIFMT_NB_IF |
303 SND_SOC_DAIFMT_CBS_CFS
304 );
305 if (ret < 0) {
306 dev_err(rtd->dev, "can't set format to I2S, err %d\n", ret);
307 return ret;
308 }
309
310 ret = snd_soc_dai_set_tdm_slot(rtd->cpu_dai, 0x3, 0x3, 2, 24);
311 if (ret < 0) {
312 dev_err(rtd->dev, "can't set I2S config, err %d\n", ret);
313 return ret;
314 }
315
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530316 return 0;
317}
318
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600319static int byt_rt5640_aif1_startup(struct snd_pcm_substream *substream)
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530320{
Lars-Peter Clausend0a1b662015-10-18 15:39:30 +0200321 return snd_pcm_hw_constraint_single(substream->runtime,
322 SNDRV_PCM_HW_PARAM_RATE, 48000);
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530323}
324
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600325static struct snd_soc_ops byt_rt5640_aif1_ops = {
326 .startup = byt_rt5640_aif1_startup,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530327};
328
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600329static struct snd_soc_ops byt_rt5640_be_ssp2_ops = {
330 .hw_params = byt_rt5640_aif1_hw_params,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530331};
332
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600333static struct snd_soc_dai_link byt_rt5640_dais[] = {
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530334 [MERR_DPCM_AUDIO] = {
335 .name = "Baytrail Audio Port",
336 .stream_name = "Baytrail Audio",
337 .cpu_dai_name = "media-cpu-dai",
338 .codec_dai_name = "snd-soc-dummy-dai",
339 .codec_name = "snd-soc-dummy",
340 .platform_name = "sst-mfld-platform",
341 .ignore_suspend = 1,
342 .dynamic = 1,
343 .dpcm_playback = 1,
344 .dpcm_capture = 1,
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600345 .ops = &byt_rt5640_aif1_ops,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530346 },
Pierre-Louis Bossartd35eb962015-12-17 20:35:45 -0600347 [MERR_DPCM_DEEP_BUFFER] = {
348 .name = "Deep-Buffer Audio Port",
349 .stream_name = "Deep-Buffer Audio",
350 .cpu_dai_name = "deepbuffer-cpu-dai",
351 .codec_dai_name = "snd-soc-dummy-dai",
352 .codec_name = "snd-soc-dummy",
353 .platform_name = "sst-mfld-platform",
354 .ignore_suspend = 1,
355 .nonatomic = true,
356 .dynamic = 1,
357 .dpcm_playback = 1,
358 .ops = &byt_rt5640_aif1_ops,
359 },
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530360 [MERR_DPCM_COMPR] = {
361 .name = "Baytrail Compressed Port",
362 .stream_name = "Baytrail Compress",
363 .cpu_dai_name = "compress-cpu-dai",
364 .codec_dai_name = "snd-soc-dummy-dai",
365 .codec_name = "snd-soc-dummy",
366 .platform_name = "sst-mfld-platform",
367 },
368 /* back ends */
369 {
370 .name = "SSP2-Codec",
Mengdong Lin2f0ad492016-04-19 13:12:35 +0800371 .id = 1,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530372 .cpu_dai_name = "ssp2-port",
373 .platform_name = "sst-mfld-platform",
374 .no_pcm = 1,
Pierre-Louis Bossart89b89072016-08-12 16:27:50 -0500375 .codec_dai_name = "rt5640-aif1", /* changed w/ quirk */
Pierre-Louis Bossart7762ef42016-01-04 17:20:29 -0600376 .codec_name = "i2c-10EC5640:00", /* overwritten with HID */
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530377 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
378 | SND_SOC_DAIFMT_CBS_CFS,
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600379 .be_hw_params_fixup = byt_rt5640_codec_fixup,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530380 .ignore_suspend = 1,
381 .dpcm_playback = 1,
382 .dpcm_capture = 1,
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -0600383 .init = byt_rt5640_init,
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600384 .ops = &byt_rt5640_be_ssp2_ops,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530385 },
386};
387
388/* SoC card */
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -0600389static struct snd_soc_card byt_rt5640_card = {
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600390 .name = "bytcr-rt5640",
Axel Lin54d86972015-08-21 20:59:21 +0800391 .owner = THIS_MODULE,
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600392 .dai_link = byt_rt5640_dais,
393 .num_links = ARRAY_SIZE(byt_rt5640_dais),
394 .dapm_widgets = byt_rt5640_widgets,
395 .num_dapm_widgets = ARRAY_SIZE(byt_rt5640_widgets),
396 .dapm_routes = byt_rt5640_audio_map,
397 .num_dapm_routes = ARRAY_SIZE(byt_rt5640_audio_map),
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -0600398 .fully_routed = true,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530399};
400
Pierre-Louis Bossartcaf94ed2016-01-04 17:20:28 -0600401static char byt_rt5640_codec_name[16]; /* i2c-<HID>:00 with HID being 8 chars */
Pierre-Louis Bossart89b89072016-08-12 16:27:50 -0500402static char byt_rt5640_codec_aif_name[12]; /* = "rt5640-aif[1|2]" */
Pierre-Louis Bossartcaf94ed2016-01-04 17:20:28 -0600403
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600404static int snd_byt_rt5640_mc_probe(struct platform_device *pdev)
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530405{
406 int ret_val = 0;
Pierre-Louis Bossartcaf94ed2016-01-04 17:20:28 -0600407 struct sst_acpi_mach *mach;
Pierre-Louis Bossarta232b962016-03-03 21:36:38 -0600408 const char *i2c_name = NULL;
409 int i;
410 int dai_index;
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530411
412 /* register the soc card */
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -0600413 byt_rt5640_card.dev = &pdev->dev;
Pierre-Louis Bossartcaf94ed2016-01-04 17:20:28 -0600414 mach = byt_rt5640_card.dev->platform_data;
415
Pierre-Louis Bossarta232b962016-03-03 21:36:38 -0600416 /* fix index of codec dai */
417 dai_index = MERR_DPCM_COMPR + 1;
418 for (i = 0; i < ARRAY_SIZE(byt_rt5640_dais); i++) {
419 if (!strcmp(byt_rt5640_dais[i].codec_name, "i2c-10EC5640:00")) {
420 dai_index = i;
421 break;
422 }
423 }
424
Pierre-Louis Bossartcaf94ed2016-01-04 17:20:28 -0600425 /* fixup codec name based on HID */
Pierre-Louis Bossarta232b962016-03-03 21:36:38 -0600426 i2c_name = sst_acpi_find_name_from_hid(mach->id);
427 if (i2c_name != NULL) {
428 snprintf(byt_rt5640_codec_name, sizeof(byt_rt5640_codec_name),
429 "%s%s", "i2c-", i2c_name);
430
431 byt_rt5640_dais[dai_index].codec_name = byt_rt5640_codec_name;
432 }
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530433
Pierre-Louis Bossartab738e42016-03-03 21:36:37 -0600434 /* check quirks before creating card */
435 dmi_check_system(byt_rt5640_quirk_table);
436
Pierre-Louis Bossart89b89072016-08-12 16:27:50 -0500437 if (byt_rt5640_quirk & BYT_RT5640_SSP2_AIF2) {
438
439 /* fixup codec aif name */
440 snprintf(byt_rt5640_codec_aif_name,
441 sizeof(byt_rt5640_codec_aif_name),
442 "%s", "rt5640-aif2");
443
444 byt_rt5640_dais[dai_index].codec_dai_name =
445 byt_rt5640_codec_aif_name;
446 }
447
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -0600448 ret_val = devm_snd_soc_register_card(&pdev->dev, &byt_rt5640_card);
449
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530450 if (ret_val) {
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600451 dev_err(&pdev->dev, "devm_snd_soc_register_card failed %d\n",
452 ret_val);
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530453 return ret_val;
454 }
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -0600455 platform_set_drvdata(pdev, &byt_rt5640_card);
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530456 return ret_val;
457}
458
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600459static struct platform_driver snd_byt_rt5640_mc_driver = {
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530460 .driver = {
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600461 .name = "bytcr_rt5640",
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530462 .pm = &snd_soc_pm_ops,
463 },
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600464 .probe = snd_byt_rt5640_mc_probe,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530465};
466
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600467module_platform_driver(snd_byt_rt5640_mc_driver);
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530468
469MODULE_DESCRIPTION("ASoC Intel(R) Baytrail CR Machine driver");
470MODULE_AUTHOR("Subhransu S. Prusty <subhransu.s.prusty@intel.com>");
471MODULE_LICENSE("GPL v2");
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600472MODULE_ALIAS("platform:bytcr_rt5640");