blob: b1eb696f33b657b5f6efee7650ac1f9319a5787e [file] [log] [blame]
Fang, Yang Ae18acdc2015-02-04 18:19:32 -08001/*
2 * cht-bsw-rt5645.c - ASoc Machine driver for Intel Cherryview-based platforms
3 * Cherrytrail and Braswell, with RT5645 codec.
4 *
5 * Copyright (C) 2015 Intel Corp
6 * Author: Fang, Yang A <yang.a.fang@intel.com>
7 * N,Harshapriya <harshapriya.n@intel.com>
8 * This file is modified from cht_bsw_rt5672.c
9 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; version 2 of the License.
14 *
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
21 */
22
23#include <linux/module.h>
Fang, Yang Ac4ba51b2015-04-23 10:23:02 -070024#include <linux/acpi.h>
Fang, Yang Ae18acdc2015-02-04 18:19:32 -080025#include <linux/platform_device.h>
26#include <linux/slab.h>
Pierre-Louis Bossart09f78f12017-04-04 19:32:29 +000027#include <asm/cpu_device_id.h>
28#include <asm/platform_sst_audio.h>
29#include <linux/clk.h>
Fang, Yang Ae18acdc2015-02-04 18:19:32 -080030#include <sound/pcm.h>
31#include <sound/pcm_params.h>
32#include <sound/soc.h>
33#include <sound/jack.h>
Jie Yange56c72d2015-04-02 15:37:02 +080034#include "../../codecs/rt5645.h"
Jie Yangb97169d2015-04-02 15:37:04 +080035#include "../atom/sst-atom-controls.h"
Vinod Koul07d5c172016-07-08 15:39:51 +053036#include "../common/sst-acpi.h"
Fang, Yang Ae18acdc2015-02-04 18:19:32 -080037
38#define CHT_PLAT_CLK_3_HZ 19200000
39#define CHT_CODEC_DAI "rt5645-aif1"
40
Fang, Yang Ac4ba51b2015-04-23 10:23:02 -070041struct cht_acpi_card {
42 char *codec_id;
43 int codec_type;
44 struct snd_soc_card *soc_card;
45};
46
Fang, Yang Ae18acdc2015-02-04 18:19:32 -080047struct cht_mc_private {
Fang, Yang A673c4f82015-05-05 16:55:34 -070048 struct snd_soc_jack jack;
Fang, Yang Ac4ba51b2015-04-23 10:23:02 -070049 struct cht_acpi_card *acpi_card;
Takashi Iwaid61a9692016-11-22 18:11:08 +010050 char codec_name[16];
Pierre-Louis Bossart09f78f12017-04-04 19:32:29 +000051 struct clk *mclk;
Fang, Yang Ae18acdc2015-02-04 18:19:32 -080052};
53
54static inline struct snd_soc_dai *cht_get_codec_dai(struct snd_soc_card *card)
55{
Mengdong Lin1a497982015-11-18 02:34:11 -050056 struct snd_soc_pcm_runtime *rtd;
Fang, Yang Ae18acdc2015-02-04 18:19:32 -080057
Mengdong Lin1a497982015-11-18 02:34:11 -050058 list_for_each_entry(rtd, &card->rtd_list, list) {
Fang, Yang Ae18acdc2015-02-04 18:19:32 -080059 if (!strncmp(rtd->codec_dai->name, CHT_CODEC_DAI,
60 strlen(CHT_CODEC_DAI)))
61 return rtd->codec_dai;
62 }
63 return NULL;
64}
65
66static int platform_clock_control(struct snd_soc_dapm_widget *w,
67 struct snd_kcontrol *k, int event)
68{
69 struct snd_soc_dapm_context *dapm = w->dapm;
70 struct snd_soc_card *card = dapm->card;
71 struct snd_soc_dai *codec_dai;
Pierre-Louis Bossart09f78f12017-04-04 19:32:29 +000072 struct cht_mc_private *ctx = snd_soc_card_get_drvdata(card);
Fang, Yang Ae18acdc2015-02-04 18:19:32 -080073 int ret;
74
75 codec_dai = cht_get_codec_dai(card);
76 if (!codec_dai) {
77 dev_err(card->dev, "Codec dai not found; Unable to set platform clock\n");
78 return -EIO;
79 }
80
Pierre-Louis Bossart09f78f12017-04-04 19:32:29 +000081 if (SND_SOC_DAPM_EVENT_ON(event)) {
82 if (ctx->mclk) {
83 ret = clk_prepare_enable(ctx->mclk);
84 if (ret < 0) {
85 dev_err(card->dev,
86 "could not configure MCLK state");
87 return ret;
88 }
89 }
90 } else {
91 /* Set codec sysclk source to its internal clock because codec PLL will
92 * be off when idle and MCLK will also be off when codec is
93 * runtime suspended. Codec needs clock for jack detection and button
94 * press. MCLK is turned off with clock framework or ACPI.
95 */
96 ret = snd_soc_dai_set_sysclk(codec_dai, RT5645_SCLK_S_RCCLK,
97 48000 * 512, SND_SOC_CLOCK_IN);
98 if (ret < 0) {
99 dev_err(card->dev, "can't set codec sysclk: %d\n", ret);
100 return ret;
101 }
Fang, Yang Ae18acdc2015-02-04 18:19:32 -0800102
Pierre-Louis Bossart09f78f12017-04-04 19:32:29 +0000103 if (ctx->mclk)
104 clk_disable_unprepare(ctx->mclk);
Fang, Yang Ae18acdc2015-02-04 18:19:32 -0800105 }
106
107 return 0;
108}
109
110static const struct snd_soc_dapm_widget cht_dapm_widgets[] = {
111 SND_SOC_DAPM_HP("Headphone", NULL),
112 SND_SOC_DAPM_MIC("Headset Mic", NULL),
113 SND_SOC_DAPM_MIC("Int Mic", NULL),
Hans de Goedec5ae3c62018-01-02 19:53:14 +0100114 SND_SOC_DAPM_MIC("Int Analog Mic", NULL),
Fang, Yang Ae18acdc2015-02-04 18:19:32 -0800115 SND_SOC_DAPM_SPK("Ext Spk", NULL),
116 SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM, 0, 0,
Pierre-Louis Bossart09f78f12017-04-04 19:32:29 +0000117 platform_clock_control, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
Fang, Yang Ae18acdc2015-02-04 18:19:32 -0800118};
119
Fang, Yang Ac4ba51b2015-04-23 10:23:02 -0700120static const struct snd_soc_dapm_route cht_rt5645_audio_map[] = {
Fang, Yang Ae18acdc2015-02-04 18:19:32 -0800121 {"IN1P", NULL, "Headset Mic"},
122 {"IN1N", NULL, "Headset Mic"},
123 {"DMIC L1", NULL, "Int Mic"},
124 {"DMIC R1", NULL, "Int Mic"},
Hans de Goedec5ae3c62018-01-02 19:53:14 +0100125 {"IN2P", NULL, "Int Analog Mic"},
126 {"IN2N", NULL, "Int Analog Mic"},
Fang, Yang Ae18acdc2015-02-04 18:19:32 -0800127 {"Headphone", NULL, "HPOL"},
128 {"Headphone", NULL, "HPOR"},
129 {"Ext Spk", NULL, "SPOL"},
130 {"Ext Spk", NULL, "SPOR"},
131 {"AIF1 Playback", NULL, "ssp2 Tx"},
132 {"ssp2 Tx", NULL, "codec_out0"},
133 {"ssp2 Tx", NULL, "codec_out1"},
134 {"codec_in0", NULL, "ssp2 Rx" },
135 {"codec_in1", NULL, "ssp2 Rx" },
136 {"ssp2 Rx", NULL, "AIF1 Capture"},
137 {"Headphone", NULL, "Platform Clock"},
138 {"Headset Mic", NULL, "Platform Clock"},
139 {"Int Mic", NULL, "Platform Clock"},
Hans de Goedec5ae3c62018-01-02 19:53:14 +0100140 {"Int Analog Mic", NULL, "Platform Clock"},
141 {"Int Analog Mic", NULL, "micbias1"},
142 {"Int Analog Mic", NULL, "micbias2"},
Fang, Yang Ae18acdc2015-02-04 18:19:32 -0800143 {"Ext Spk", NULL, "Platform Clock"},
144};
145
Fang, Yang Ac4ba51b2015-04-23 10:23:02 -0700146static const struct snd_soc_dapm_route cht_rt5650_audio_map[] = {
147 {"IN1P", NULL, "Headset Mic"},
148 {"IN1N", NULL, "Headset Mic"},
149 {"DMIC L2", NULL, "Int Mic"},
150 {"DMIC R2", NULL, "Int Mic"},
151 {"Headphone", NULL, "HPOL"},
152 {"Headphone", NULL, "HPOR"},
153 {"Ext Spk", NULL, "SPOL"},
154 {"Ext Spk", NULL, "SPOR"},
155 {"AIF1 Playback", NULL, "ssp2 Tx"},
156 {"ssp2 Tx", NULL, "codec_out0"},
157 {"ssp2 Tx", NULL, "codec_out1"},
158 {"codec_in0", NULL, "ssp2 Rx" },
159 {"codec_in1", NULL, "ssp2 Rx" },
160 {"ssp2 Rx", NULL, "AIF1 Capture"},
161 {"Headphone", NULL, "Platform Clock"},
162 {"Headset Mic", NULL, "Platform Clock"},
163 {"Int Mic", NULL, "Platform Clock"},
164 {"Ext Spk", NULL, "Platform Clock"},
165};
166
Fang, Yang Ae18acdc2015-02-04 18:19:32 -0800167static const struct snd_kcontrol_new cht_mc_controls[] = {
168 SOC_DAPM_PIN_SWITCH("Headphone"),
169 SOC_DAPM_PIN_SWITCH("Headset Mic"),
170 SOC_DAPM_PIN_SWITCH("Int Mic"),
Hans de Goedec5ae3c62018-01-02 19:53:14 +0100171 SOC_DAPM_PIN_SWITCH("Int Analog Mic"),
Fang, Yang Ae18acdc2015-02-04 18:19:32 -0800172 SOC_DAPM_PIN_SWITCH("Ext Spk"),
173};
174
Carlo Caione2303b322016-02-16 22:27:19 +0100175static struct snd_soc_jack_pin cht_bsw_jack_pins[] = {
176 {
177 .pin = "Headphone",
178 .mask = SND_JACK_HEADPHONE,
179 },
180 {
181 .pin = "Headset Mic",
182 .mask = SND_JACK_MICROPHONE,
183 },
184};
185
Fang, Yang Ae18acdc2015-02-04 18:19:32 -0800186static int cht_aif1_hw_params(struct snd_pcm_substream *substream,
187 struct snd_pcm_hw_params *params)
188{
189 struct snd_soc_pcm_runtime *rtd = substream->private_data;
190 struct snd_soc_dai *codec_dai = rtd->codec_dai;
191 int ret;
192
193 /* set codec PLL source to the 19.2MHz platform clock (MCLK) */
194 ret = snd_soc_dai_set_pll(codec_dai, 0, RT5645_PLL1_S_MCLK,
195 CHT_PLAT_CLK_3_HZ, params_rate(params) * 512);
196 if (ret < 0) {
197 dev_err(rtd->dev, "can't set codec pll: %d\n", ret);
198 return ret;
199 }
200
201 ret = snd_soc_dai_set_sysclk(codec_dai, RT5645_SCLK_S_PLL1,
202 params_rate(params) * 512, SND_SOC_CLOCK_IN);
203 if (ret < 0) {
204 dev_err(rtd->dev, "can't set codec sysclk: %d\n", ret);
205 return ret;
206 }
207
208 return 0;
209}
210
211static int cht_codec_init(struct snd_soc_pcm_runtime *runtime)
212{
213 int ret;
Fang, Yang A673c4f82015-05-05 16:55:34 -0700214 int jack_type;
Fang, Yang Ae18acdc2015-02-04 18:19:32 -0800215 struct snd_soc_codec *codec = runtime->codec;
216 struct snd_soc_dai *codec_dai = runtime->codec_dai;
217 struct cht_mc_private *ctx = snd_soc_card_get_drvdata(runtime->card);
218
219 /* Select clk_i2s1_asrc as ASRC clock source */
220 rt5645_sel_asrc_clk_src(codec,
221 RT5645_DA_STEREO_FILTER |
222 RT5645_DA_MONO_L_FILTER |
223 RT5645_DA_MONO_R_FILTER |
224 RT5645_AD_STEREO_FILTER,
225 RT5645_CLK_SEL_I2S1_ASRC);
226
227 /* TDM 4 slots 24 bit, set Rx & Tx bitmask to 4 active slots */
228 ret = snd_soc_dai_set_tdm_slot(codec_dai, 0xF, 0xF, 4, 24);
229 if (ret < 0) {
230 dev_err(runtime->dev, "can't set codec TDM slot %d\n", ret);
231 return ret;
232 }
233
Fang, Yang A673c4f82015-05-05 16:55:34 -0700234 if (ctx->acpi_card->codec_type == CODEC_TYPE_RT5650)
235 jack_type = SND_JACK_HEADPHONE | SND_JACK_MICROPHONE |
236 SND_JACK_BTN_0 | SND_JACK_BTN_1 |
237 SND_JACK_BTN_2 | SND_JACK_BTN_3;
238 else
239 jack_type = SND_JACK_HEADPHONE | SND_JACK_MICROPHONE;
240
Carlo Caione2303b322016-02-16 22:27:19 +0100241 ret = snd_soc_card_jack_new(runtime->card, "Headset",
Fang, Yang A673c4f82015-05-05 16:55:34 -0700242 jack_type, &ctx->jack,
Carlo Caione2303b322016-02-16 22:27:19 +0100243 cht_bsw_jack_pins, ARRAY_SIZE(cht_bsw_jack_pins));
Fang, Yang Ae18acdc2015-02-04 18:19:32 -0800244 if (ret) {
Fang, Yang A673c4f82015-05-05 16:55:34 -0700245 dev_err(runtime->dev, "Headset jack creation failed %d\n", ret);
Fang, Yang Ae18acdc2015-02-04 18:19:32 -0800246 return ret;
247 }
248
Fang, Yang A673c4f82015-05-05 16:55:34 -0700249 rt5645_set_jack_detect(codec, &ctx->jack, &ctx->jack, &ctx->jack);
Fang, Yang Ae18acdc2015-02-04 18:19:32 -0800250
Pierre-Louis Bossart09f78f12017-04-04 19:32:29 +0000251 if (ctx->mclk) {
252 /*
253 * The firmware might enable the clock at
254 * boot (this information may or may not
255 * be reflected in the enable clock register).
256 * To change the rate we must disable the clock
257 * first to cover these cases. Due to common
258 * clock framework restrictions that do not allow
259 * to disable a clock that has not been enabled,
260 * we need to enable the clock first.
261 */
262 ret = clk_prepare_enable(ctx->mclk);
263 if (!ret)
264 clk_disable_unprepare(ctx->mclk);
265
266 ret = clk_set_rate(ctx->mclk, CHT_PLAT_CLK_3_HZ);
267
268 if (ret)
269 dev_err(runtime->dev, "unable to set MCLK rate\n");
270 }
Fang, Yang Ae18acdc2015-02-04 18:19:32 -0800271 return ret;
272}
273
274static int cht_codec_fixup(struct snd_soc_pcm_runtime *rtd,
275 struct snd_pcm_hw_params *params)
276{
277 struct snd_interval *rate = hw_param_interval(params,
278 SNDRV_PCM_HW_PARAM_RATE);
279 struct snd_interval *channels = hw_param_interval(params,
280 SNDRV_PCM_HW_PARAM_CHANNELS);
281
282 /* The DSP will covert the FE rate to 48k, stereo, 24bits */
283 rate->min = rate->max = 48000;
284 channels->min = channels->max = 2;
285
286 /* set SSP2 to 24-bit */
Fang, Yang A369a9f52015-02-09 00:18:12 -0800287 params_set_format(params, SNDRV_PCM_FORMAT_S24_LE);
Fang, Yang Ae18acdc2015-02-04 18:19:32 -0800288 return 0;
289}
290
Fang, Yang Ae18acdc2015-02-04 18:19:32 -0800291static int cht_aif1_startup(struct snd_pcm_substream *substream)
292{
Lars-Peter Clausen3d6a76c2015-10-18 15:39:32 +0200293 return snd_pcm_hw_constraint_single(substream->runtime,
294 SNDRV_PCM_HW_PARAM_RATE, 48000);
Fang, Yang Ae18acdc2015-02-04 18:19:32 -0800295}
296
297static struct snd_soc_ops cht_aif1_ops = {
298 .startup = cht_aif1_startup,
299};
300
301static struct snd_soc_ops cht_be_ssp2_ops = {
302 .hw_params = cht_aif1_hw_params,
303};
304
305static struct snd_soc_dai_link cht_dailink[] = {
306 [MERR_DPCM_AUDIO] = {
307 .name = "Audio Port",
308 .stream_name = "Audio",
309 .cpu_dai_name = "media-cpu-dai",
310 .codec_dai_name = "snd-soc-dummy-dai",
311 .codec_name = "snd-soc-dummy",
312 .platform_name = "sst-mfld-platform",
Fang, Yang Ac4ba51b2015-04-23 10:23:02 -0700313 .nonatomic = true,
Fang, Yang Ae18acdc2015-02-04 18:19:32 -0800314 .dynamic = 1,
315 .dpcm_playback = 1,
316 .dpcm_capture = 1,
317 .ops = &cht_aif1_ops,
318 },
Pierre-Louis Bossartd35eb962015-12-17 20:35:45 -0600319 [MERR_DPCM_DEEP_BUFFER] = {
320 .name = "Deep-Buffer Audio Port",
321 .stream_name = "Deep-Buffer Audio",
322 .cpu_dai_name = "deepbuffer-cpu-dai",
323 .codec_dai_name = "snd-soc-dummy-dai",
324 .codec_name = "snd-soc-dummy",
325 .platform_name = "sst-mfld-platform",
326 .nonatomic = true,
327 .dynamic = 1,
328 .dpcm_playback = 1,
329 .ops = &cht_aif1_ops,
330 },
Fang, Yang Ae18acdc2015-02-04 18:19:32 -0800331 [MERR_DPCM_COMPR] = {
332 .name = "Compressed Port",
333 .stream_name = "Compress",
334 .cpu_dai_name = "compress-cpu-dai",
335 .codec_dai_name = "snd-soc-dummy-dai",
336 .codec_name = "snd-soc-dummy",
337 .platform_name = "sst-mfld-platform",
338 },
339 /* CODEC<->CODEC link */
340 /* back ends */
341 {
342 .name = "SSP2-Codec",
Mengdong Lin2f0ad492016-04-19 13:12:35 +0800343 .id = 1,
Fang, Yang Ae18acdc2015-02-04 18:19:32 -0800344 .cpu_dai_name = "ssp2-port",
345 .platform_name = "sst-mfld-platform",
346 .no_pcm = 1,
347 .codec_dai_name = "rt5645-aif1",
348 .codec_name = "i2c-10EC5645:00",
349 .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_IB_NF
350 | SND_SOC_DAIFMT_CBS_CFS,
351 .init = cht_codec_init,
352 .be_hw_params_fixup = cht_codec_fixup,
Fang, Yang Ac4ba51b2015-04-23 10:23:02 -0700353 .nonatomic = true,
Fang, Yang Ae18acdc2015-02-04 18:19:32 -0800354 .dpcm_playback = 1,
355 .dpcm_capture = 1,
356 .ops = &cht_be_ssp2_ops,
357 },
358};
359
360/* SoC card */
Fang, Yang Ac4ba51b2015-04-23 10:23:02 -0700361static struct snd_soc_card snd_soc_card_chtrt5645 = {
Fang, Yang Ae18acdc2015-02-04 18:19:32 -0800362 .name = "chtrt5645",
Axel Lin54d86972015-08-21 20:59:21 +0800363 .owner = THIS_MODULE,
Fang, Yang Ae18acdc2015-02-04 18:19:32 -0800364 .dai_link = cht_dailink,
365 .num_links = ARRAY_SIZE(cht_dailink),
366 .dapm_widgets = cht_dapm_widgets,
367 .num_dapm_widgets = ARRAY_SIZE(cht_dapm_widgets),
Fang, Yang Ac4ba51b2015-04-23 10:23:02 -0700368 .dapm_routes = cht_rt5645_audio_map,
369 .num_dapm_routes = ARRAY_SIZE(cht_rt5645_audio_map),
Fang, Yang Ae18acdc2015-02-04 18:19:32 -0800370 .controls = cht_mc_controls,
371 .num_controls = ARRAY_SIZE(cht_mc_controls),
372};
373
Fang, Yang Ac4ba51b2015-04-23 10:23:02 -0700374static struct snd_soc_card snd_soc_card_chtrt5650 = {
375 .name = "chtrt5650",
Axel Lin54d86972015-08-21 20:59:21 +0800376 .owner = THIS_MODULE,
Fang, Yang Ac4ba51b2015-04-23 10:23:02 -0700377 .dai_link = cht_dailink,
378 .num_links = ARRAY_SIZE(cht_dailink),
379 .dapm_widgets = cht_dapm_widgets,
380 .num_dapm_widgets = ARRAY_SIZE(cht_dapm_widgets),
381 .dapm_routes = cht_rt5650_audio_map,
382 .num_dapm_routes = ARRAY_SIZE(cht_rt5650_audio_map),
383 .controls = cht_mc_controls,
384 .num_controls = ARRAY_SIZE(cht_mc_controls),
385};
386
387static struct cht_acpi_card snd_soc_cards[] = {
Vinod Koul07d5c172016-07-08 15:39:51 +0530388 {"10EC5640", CODEC_TYPE_RT5645, &snd_soc_card_chtrt5645},
Fang, Yang Ac4ba51b2015-04-23 10:23:02 -0700389 {"10EC5645", CODEC_TYPE_RT5645, &snd_soc_card_chtrt5645},
390 {"10EC5650", CODEC_TYPE_RT5650, &snd_soc_card_chtrt5650},
391};
392
Vinod Koul07d5c172016-07-08 15:39:51 +0530393static char cht_rt5640_codec_name[16]; /* i2c-<HID>:00 with HID being 8 chars */
394
Pierre-Louis Bossart09f78f12017-04-04 19:32:29 +0000395static bool is_valleyview(void)
396{
397 static const struct x86_cpu_id cpu_ids[] = {
398 { X86_VENDOR_INTEL, 6, 55 }, /* Valleyview, Bay Trail */
399 {}
400 };
401
402 if (!x86_match_cpu(cpu_ids))
403 return false;
404 return true;
405}
406
Fang, Yang Ae18acdc2015-02-04 18:19:32 -0800407static int snd_cht_mc_probe(struct platform_device *pdev)
408{
409 int ret_val = 0;
Fang, Yang Ac4ba51b2015-04-23 10:23:02 -0700410 int i;
Fang, Yang Ae18acdc2015-02-04 18:19:32 -0800411 struct cht_mc_private *drv;
Fang, Yang Ac4ba51b2015-04-23 10:23:02 -0700412 struct snd_soc_card *card = snd_soc_cards[0].soc_card;
Vinod Koul07d5c172016-07-08 15:39:51 +0530413 struct sst_acpi_mach *mach;
414 const char *i2c_name = NULL;
Vinod Koul5d554ea2016-07-08 18:30:17 +0530415 int dai_index = 0;
Pierre-Louis Bossart584f4312017-04-04 19:32:29 +0000416 bool found = false;
Fang, Yang Ae18acdc2015-02-04 18:19:32 -0800417
418 drv = devm_kzalloc(&pdev->dev, sizeof(*drv), GFP_ATOMIC);
419 if (!drv)
420 return -ENOMEM;
421
Pierre-Louis Bossart584f4312017-04-04 19:32:29 +0000422 mach = (&pdev->dev)->platform_data;
423
Fang, Yang Ac4ba51b2015-04-23 10:23:02 -0700424 for (i = 0; i < ARRAY_SIZE(snd_soc_cards); i++) {
Pierre-Louis Bossart584f4312017-04-04 19:32:29 +0000425 if (acpi_dev_found(snd_soc_cards[i].codec_id) &&
426 (!strncmp(snd_soc_cards[i].codec_id, mach->id, 8))) {
Fang, Yang Ac4ba51b2015-04-23 10:23:02 -0700427 dev_dbg(&pdev->dev,
428 "found codec %s\n", snd_soc_cards[i].codec_id);
429 card = snd_soc_cards[i].soc_card;
430 drv->acpi_card = &snd_soc_cards[i];
Pierre-Louis Bossart584f4312017-04-04 19:32:29 +0000431 found = true;
Fang, Yang Ac4ba51b2015-04-23 10:23:02 -0700432 break;
433 }
434 }
Pierre-Louis Bossart584f4312017-04-04 19:32:29 +0000435
436 if (!found) {
437 dev_err(&pdev->dev, "No matching HID found in supported list\n");
438 return -ENODEV;
439 }
440
Fang, Yang Ac4ba51b2015-04-23 10:23:02 -0700441 card->dev = &pdev->dev;
Takashi Iwaid61a9692016-11-22 18:11:08 +0100442 sprintf(drv->codec_name, "i2c-%s:00", drv->acpi_card->codec_id);
Carlo Caionec8560b72016-02-23 09:50:20 +0100443
Fang, Yang Ac4ba51b2015-04-23 10:23:02 -0700444 /* set correct codec name */
Carlo Caionec8560b72016-02-23 09:50:20 +0100445 for (i = 0; i < ARRAY_SIZE(cht_dailink); i++)
Vinod Koul07d5c172016-07-08 15:39:51 +0530446 if (!strcmp(card->dai_link[i].codec_name, "i2c-10EC5645:00")) {
Takashi Iwaid61a9692016-11-22 18:11:08 +0100447 card->dai_link[i].codec_name = drv->codec_name;
Vinod Koul07d5c172016-07-08 15:39:51 +0530448 dai_index = i;
449 }
450
451 /* fixup codec name based on HID */
452 i2c_name = sst_acpi_find_name_from_hid(mach->id);
453 if (i2c_name != NULL) {
454 snprintf(cht_rt5640_codec_name, sizeof(cht_rt5640_codec_name),
455 "%s%s", "i2c-", i2c_name);
456 cht_dailink[dai_index].codec_name = cht_rt5640_codec_name;
457 }
Carlo Caionec8560b72016-02-23 09:50:20 +0100458
Pierre-Louis Bossart09f78f12017-04-04 19:32:29 +0000459 if (is_valleyview()) {
460 drv->mclk = devm_clk_get(&pdev->dev, "pmc_plt_clk_3");
461 if (IS_ERR(drv->mclk)) {
462 dev_err(&pdev->dev,
463 "Failed to get MCLK from pmc_plt_clk_3: %ld\n",
464 PTR_ERR(drv->mclk));
465 return PTR_ERR(drv->mclk);
466 }
467 }
468
Fang, Yang Ac4ba51b2015-04-23 10:23:02 -0700469 snd_soc_card_set_drvdata(card, drv);
470 ret_val = devm_snd_soc_register_card(&pdev->dev, card);
Fang, Yang Ae18acdc2015-02-04 18:19:32 -0800471 if (ret_val) {
472 dev_err(&pdev->dev,
473 "snd_soc_register_card failed %d\n", ret_val);
474 return ret_val;
475 }
Fang, Yang Ac4ba51b2015-04-23 10:23:02 -0700476 platform_set_drvdata(pdev, card);
Fang, Yang Ae18acdc2015-02-04 18:19:32 -0800477 return ret_val;
478}
479
480static struct platform_driver snd_cht_mc_driver = {
481 .driver = {
Fang, Yang Ae18acdc2015-02-04 18:19:32 -0800482 .name = "cht-bsw-rt5645",
Fang, Yang Ae18acdc2015-02-04 18:19:32 -0800483 },
484 .probe = snd_cht_mc_probe,
485};
486
487module_platform_driver(snd_cht_mc_driver)
488
489MODULE_DESCRIPTION("ASoC Intel(R) Braswell Machine driver");
490MODULE_AUTHOR("Fang, Yang A,N,Harshapriya");
491MODULE_LICENSE("GPL v2");
492MODULE_ALIAS("platform:cht-bsw-rt5645");