]>
Commit | Line | Data |
---|---|---|
a03bdaa5 DD |
1 | /* |
2 | * bytcht_es8316.c - ASoc Machine driver for Intel Baytrail/Cherrytrail | |
3 | * platforms with Everest ES8316 SoC | |
4 | * | |
5 | * Copyright (C) 2017 Endless Mobile, Inc. | |
6 | * Authors: David Yang <yangxiaohua@everest-semi.com>, | |
7 | * Daniel Drake <drake@endlessm.com> | |
8 | * | |
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 | */ | |
0d3e91da | 22 | #include <linux/acpi.h> |
6ca382c4 HG |
23 | #include <linux/clk.h> |
24 | #include <linux/device.h> | |
0d3e91da HG |
25 | #include <linux/gpio/consumer.h> |
26 | #include <linux/i2c.h> | |
a03bdaa5 | 27 | #include <linux/init.h> |
4bf538b4 | 28 | #include <linux/input.h> |
a03bdaa5 DD |
29 | #include <linux/module.h> |
30 | #include <linux/platform_device.h> | |
a03bdaa5 | 31 | #include <linux/slab.h> |
349e1386 HG |
32 | #include <asm/cpu_device_id.h> |
33 | #include <asm/intel-family.h> | |
a03bdaa5 | 34 | #include <asm/platform_sst_audio.h> |
4bf538b4 | 35 | #include <sound/jack.h> |
a03bdaa5 DD |
36 | #include <sound/pcm.h> |
37 | #include <sound/pcm_params.h> | |
38 | #include <sound/soc.h> | |
7feb2f78 | 39 | #include <sound/soc-acpi.h> |
a03bdaa5 | 40 | #include "../atom/sst-atom-controls.h" |
a03bdaa5 DD |
41 | #include "../common/sst-dsp.h" |
42 | ||
43 | struct byt_cht_es8316_private { | |
44 | struct clk *mclk; | |
4bf538b4 | 45 | struct snd_soc_jack jack; |
0d3e91da HG |
46 | struct gpio_desc *speaker_en_gpio; |
47 | bool speaker_en; | |
a03bdaa5 DD |
48 | }; |
49 | ||
730501a9 HG |
50 | enum { |
51 | BYT_CHT_ES8316_INTMIC_IN1_MAP, | |
52 | BYT_CHT_ES8316_INTMIC_IN2_MAP, | |
53 | }; | |
54 | ||
55 | #define BYT_CHT_ES8316_MAP(quirk) ((quirk) & GENMASK(3, 0)) | |
349e1386 HG |
56 | #define BYT_CHT_ES8316_SSP0 BIT(16) |
57 | ||
58 | static int quirk; | |
59 | ||
60 | static int quirk_override = -1; | |
61 | module_param_named(quirk, quirk_override, int, 0444); | |
62 | MODULE_PARM_DESC(quirk, "Board-specific quirk override"); | |
63 | ||
64 | static void log_quirks(struct device *dev) | |
65 | { | |
730501a9 HG |
66 | if (BYT_CHT_ES8316_MAP(quirk) == BYT_CHT_ES8316_INTMIC_IN1_MAP) |
67 | dev_info(dev, "quirk IN1_MAP enabled"); | |
68 | if (BYT_CHT_ES8316_MAP(quirk) == BYT_CHT_ES8316_INTMIC_IN2_MAP) | |
69 | dev_info(dev, "quirk IN2_MAP enabled"); | |
349e1386 HG |
70 | if (quirk & BYT_CHT_ES8316_SSP0) |
71 | dev_info(dev, "quirk SSP0 enabled"); | |
72 | } | |
73 | ||
0d3e91da HG |
74 | static int byt_cht_es8316_speaker_power_event(struct snd_soc_dapm_widget *w, |
75 | struct snd_kcontrol *kcontrol, int event) | |
76 | { | |
77 | struct snd_soc_card *card = w->dapm->card; | |
78 | struct byt_cht_es8316_private *priv = snd_soc_card_get_drvdata(card); | |
79 | ||
80 | if (SND_SOC_DAPM_EVENT_ON(event)) | |
81 | priv->speaker_en = true; | |
82 | else | |
83 | priv->speaker_en = false; | |
84 | ||
85 | gpiod_set_value_cansleep(priv->speaker_en_gpio, priv->speaker_en); | |
86 | ||
87 | return 0; | |
88 | } | |
89 | ||
a03bdaa5 | 90 | static const struct snd_soc_dapm_widget byt_cht_es8316_widgets[] = { |
0d3e91da | 91 | SND_SOC_DAPM_SPK("Speaker", NULL), |
a03bdaa5 | 92 | SND_SOC_DAPM_HP("Headphone", NULL), |
4bf538b4 | 93 | SND_SOC_DAPM_MIC("Headset Mic", NULL), |
730501a9 | 94 | SND_SOC_DAPM_MIC("Internal Mic", NULL), |
0d3e91da HG |
95 | |
96 | SND_SOC_DAPM_SUPPLY("Speaker Power", SND_SOC_NOPM, 0, 0, | |
97 | byt_cht_es8316_speaker_power_event, | |
98 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU), | |
a03bdaa5 DD |
99 | }; |
100 | ||
101 | static const struct snd_soc_dapm_route byt_cht_es8316_audio_map[] = { | |
a03bdaa5 DD |
102 | {"Headphone", NULL, "HPOL"}, |
103 | {"Headphone", NULL, "HPOR"}, | |
0d3e91da HG |
104 | |
105 | /* | |
106 | * There is no separate speaker output instead the speakers are muxed to | |
107 | * the HP outputs. The mux is controlled by the "Speaker Power" supply. | |
108 | */ | |
109 | {"Speaker", NULL, "HPOL"}, | |
110 | {"Speaker", NULL, "HPOR"}, | |
111 | {"Speaker", NULL, "Speaker Power"}, | |
349e1386 HG |
112 | }; |
113 | ||
730501a9 HG |
114 | static const struct snd_soc_dapm_route byt_cht_es8316_intmic_in1_map[] = { |
115 | {"MIC1", NULL, "Internal Mic"}, | |
116 | {"MIC2", NULL, "Headset Mic"}, | |
117 | }; | |
118 | ||
119 | static const struct snd_soc_dapm_route byt_cht_es8316_intmic_in2_map[] = { | |
120 | {"MIC2", NULL, "Internal Mic"}, | |
121 | {"MIC1", NULL, "Headset Mic"}, | |
122 | }; | |
123 | ||
349e1386 HG |
124 | static const struct snd_soc_dapm_route byt_cht_es8316_ssp0_map[] = { |
125 | {"Playback", NULL, "ssp0 Tx"}, | |
126 | {"ssp0 Tx", NULL, "modem_out"}, | |
127 | {"modem_in", NULL, "ssp0 Rx"}, | |
128 | {"ssp0 Rx", NULL, "Capture"}, | |
129 | }; | |
a03bdaa5 | 130 | |
349e1386 | 131 | static const struct snd_soc_dapm_route byt_cht_es8316_ssp2_map[] = { |
a03bdaa5 DD |
132 | {"Playback", NULL, "ssp2 Tx"}, |
133 | {"ssp2 Tx", NULL, "codec_out0"}, | |
134 | {"ssp2 Tx", NULL, "codec_out1"}, | |
135 | {"codec_in0", NULL, "ssp2 Rx" }, | |
136 | {"codec_in1", NULL, "ssp2 Rx" }, | |
137 | {"ssp2 Rx", NULL, "Capture"}, | |
138 | }; | |
139 | ||
140 | static const struct snd_kcontrol_new byt_cht_es8316_controls[] = { | |
0d3e91da | 141 | SOC_DAPM_PIN_SWITCH("Speaker"), |
a03bdaa5 | 142 | SOC_DAPM_PIN_SWITCH("Headphone"), |
4bf538b4 | 143 | SOC_DAPM_PIN_SWITCH("Headset Mic"), |
730501a9 | 144 | SOC_DAPM_PIN_SWITCH("Internal Mic"), |
a03bdaa5 DD |
145 | }; |
146 | ||
4bf538b4 HG |
147 | static struct snd_soc_jack_pin byt_cht_es8316_jack_pins[] = { |
148 | { | |
149 | .pin = "Headphone", | |
150 | .mask = SND_JACK_HEADPHONE, | |
151 | }, | |
152 | { | |
153 | .pin = "Headset Mic", | |
154 | .mask = SND_JACK_MICROPHONE, | |
155 | }, | |
156 | }; | |
157 | ||
a03bdaa5 DD |
158 | static int byt_cht_es8316_init(struct snd_soc_pcm_runtime *runtime) |
159 | { | |
4bf538b4 | 160 | struct snd_soc_component *codec = runtime->codec_dai->component; |
a03bdaa5 DD |
161 | struct snd_soc_card *card = runtime->card; |
162 | struct byt_cht_es8316_private *priv = snd_soc_card_get_drvdata(card); | |
349e1386 HG |
163 | const struct snd_soc_dapm_route *custom_map; |
164 | int num_routes; | |
a03bdaa5 DD |
165 | int ret; |
166 | ||
167 | card->dapm.idle_bias_off = true; | |
168 | ||
730501a9 HG |
169 | switch (BYT_CHT_ES8316_MAP(quirk)) { |
170 | case BYT_CHT_ES8316_INTMIC_IN1_MAP: | |
171 | default: | |
172 | custom_map = byt_cht_es8316_intmic_in1_map; | |
173 | num_routes = ARRAY_SIZE(byt_cht_es8316_intmic_in1_map); | |
174 | break; | |
175 | case BYT_CHT_ES8316_INTMIC_IN2_MAP: | |
176 | custom_map = byt_cht_es8316_intmic_in2_map; | |
177 | num_routes = ARRAY_SIZE(byt_cht_es8316_intmic_in2_map); | |
178 | break; | |
179 | } | |
180 | ret = snd_soc_dapm_add_routes(&card->dapm, custom_map, num_routes); | |
181 | if (ret) | |
182 | return ret; | |
183 | ||
349e1386 HG |
184 | if (quirk & BYT_CHT_ES8316_SSP0) { |
185 | custom_map = byt_cht_es8316_ssp0_map; | |
186 | num_routes = ARRAY_SIZE(byt_cht_es8316_ssp0_map); | |
187 | } else { | |
188 | custom_map = byt_cht_es8316_ssp2_map; | |
189 | num_routes = ARRAY_SIZE(byt_cht_es8316_ssp2_map); | |
190 | } | |
191 | ret = snd_soc_dapm_add_routes(&card->dapm, custom_map, num_routes); | |
192 | if (ret) | |
193 | return ret; | |
194 | ||
a03bdaa5 DD |
195 | /* |
196 | * The firmware might enable the clock at boot (this information | |
197 | * may or may not be reflected in the enable clock register). | |
198 | * To change the rate we must disable the clock first to cover these | |
199 | * cases. Due to common clock framework restrictions that do not allow | |
200 | * to disable a clock that has not been enabled, we need to enable | |
201 | * the clock first. | |
202 | */ | |
203 | ret = clk_prepare_enable(priv->mclk); | |
204 | if (!ret) | |
205 | clk_disable_unprepare(priv->mclk); | |
206 | ||
207 | ret = clk_set_rate(priv->mclk, 19200000); | |
208 | if (ret) | |
209 | dev_err(card->dev, "unable to set MCLK rate\n"); | |
210 | ||
211 | ret = clk_prepare_enable(priv->mclk); | |
212 | if (ret) | |
213 | dev_err(card->dev, "unable to enable MCLK\n"); | |
214 | ||
215 | ret = snd_soc_dai_set_sysclk(runtime->codec_dai, 0, 19200000, | |
216 | SND_SOC_CLOCK_IN); | |
217 | if (ret < 0) { | |
218 | dev_err(card->dev, "can't set codec clock %d\n", ret); | |
219 | return ret; | |
220 | } | |
221 | ||
4bf538b4 HG |
222 | ret = snd_soc_card_jack_new(card, "Headset", |
223 | SND_JACK_HEADSET | SND_JACK_BTN_0, | |
224 | &priv->jack, byt_cht_es8316_jack_pins, | |
225 | ARRAY_SIZE(byt_cht_es8316_jack_pins)); | |
226 | if (ret) { | |
227 | dev_err(card->dev, "jack creation failed %d\n", ret); | |
228 | return ret; | |
229 | } | |
230 | ||
231 | snd_jack_set_key(priv->jack.jack, SND_JACK_BTN_0, KEY_PLAYPAUSE); | |
232 | snd_soc_component_set_jack(codec, &priv->jack, NULL); | |
233 | ||
a03bdaa5 DD |
234 | return 0; |
235 | } | |
236 | ||
237 | static const struct snd_soc_pcm_stream byt_cht_es8316_dai_params = { | |
238 | .formats = SNDRV_PCM_FMTBIT_S24_LE, | |
239 | .rate_min = 48000, | |
240 | .rate_max = 48000, | |
241 | .channels_min = 2, | |
242 | .channels_max = 2, | |
243 | }; | |
244 | ||
245 | static int byt_cht_es8316_codec_fixup(struct snd_soc_pcm_runtime *rtd, | |
246 | struct snd_pcm_hw_params *params) | |
247 | { | |
248 | struct snd_interval *rate = hw_param_interval(params, | |
249 | SNDRV_PCM_HW_PARAM_RATE); | |
250 | struct snd_interval *channels = hw_param_interval(params, | |
251 | SNDRV_PCM_HW_PARAM_CHANNELS); | |
349e1386 | 252 | int ret, bits; |
a03bdaa5 DD |
253 | |
254 | /* The DSP will covert the FE rate to 48k, stereo */ | |
255 | rate->min = rate->max = 48000; | |
256 | channels->min = channels->max = 2; | |
257 | ||
349e1386 HG |
258 | if (quirk & BYT_CHT_ES8316_SSP0) { |
259 | /* set SSP0 to 16-bit */ | |
260 | params_set_format(params, SNDRV_PCM_FORMAT_S16_LE); | |
261 | bits = 16; | |
262 | } else { | |
263 | /* set SSP2 to 24-bit */ | |
264 | params_set_format(params, SNDRV_PCM_FORMAT_S24_LE); | |
265 | bits = 24; | |
266 | } | |
a03bdaa5 DD |
267 | |
268 | /* | |
269 | * Default mode for SSP configuration is TDM 4 slot, override config | |
270 | * with explicit setting to I2S 2ch 24-bit. The word length is set with | |
271 | * dai_set_tdm_slot() since there is no other API exposed | |
272 | */ | |
273 | ret = snd_soc_dai_set_fmt(rtd->cpu_dai, | |
274 | SND_SOC_DAIFMT_I2S | | |
275 | SND_SOC_DAIFMT_NB_NF | | |
276 | SND_SOC_DAIFMT_CBS_CFS | |
277 | ); | |
278 | if (ret < 0) { | |
279 | dev_err(rtd->dev, "can't set format to I2S, err %d\n", ret); | |
280 | return ret; | |
281 | } | |
282 | ||
349e1386 | 283 | ret = snd_soc_dai_set_tdm_slot(rtd->cpu_dai, 0x3, 0x3, 2, bits); |
a03bdaa5 DD |
284 | if (ret < 0) { |
285 | dev_err(rtd->dev, "can't set I2S config, err %d\n", ret); | |
286 | return ret; | |
287 | } | |
288 | ||
289 | return 0; | |
290 | } | |
291 | ||
292 | static int byt_cht_es8316_aif1_startup(struct snd_pcm_substream *substream) | |
293 | { | |
294 | return snd_pcm_hw_constraint_single(substream->runtime, | |
295 | SNDRV_PCM_HW_PARAM_RATE, 48000); | |
296 | } | |
297 | ||
298 | static const struct snd_soc_ops byt_cht_es8316_aif1_ops = { | |
299 | .startup = byt_cht_es8316_aif1_startup, | |
300 | }; | |
301 | ||
302 | static struct snd_soc_dai_link byt_cht_es8316_dais[] = { | |
303 | [MERR_DPCM_AUDIO] = { | |
304 | .name = "Audio Port", | |
305 | .stream_name = "Audio", | |
306 | .cpu_dai_name = "media-cpu-dai", | |
307 | .codec_dai_name = "snd-soc-dummy-dai", | |
308 | .codec_name = "snd-soc-dummy", | |
309 | .platform_name = "sst-mfld-platform", | |
310 | .nonatomic = true, | |
311 | .dynamic = 1, | |
312 | .dpcm_playback = 1, | |
313 | .dpcm_capture = 1, | |
314 | .ops = &byt_cht_es8316_aif1_ops, | |
315 | }, | |
316 | ||
317 | [MERR_DPCM_DEEP_BUFFER] = { | |
318 | .name = "Deep-Buffer Audio Port", | |
319 | .stream_name = "Deep-Buffer Audio", | |
320 | .cpu_dai_name = "deepbuffer-cpu-dai", | |
321 | .codec_dai_name = "snd-soc-dummy-dai", | |
322 | .codec_name = "snd-soc-dummy", | |
323 | .platform_name = "sst-mfld-platform", | |
324 | .nonatomic = true, | |
325 | .dynamic = 1, | |
326 | .dpcm_playback = 1, | |
327 | .ops = &byt_cht_es8316_aif1_ops, | |
328 | }, | |
329 | ||
a03bdaa5 DD |
330 | /* back ends */ |
331 | { | |
332 | /* Only SSP2 has been tested here, so BYT-CR platforms that | |
333 | * require SSP0 will not work. | |
334 | */ | |
335 | .name = "SSP2-Codec", | |
149f7757 | 336 | .id = 0, |
a03bdaa5 DD |
337 | .cpu_dai_name = "ssp2-port", |
338 | .platform_name = "sst-mfld-platform", | |
339 | .no_pcm = 1, | |
340 | .codec_dai_name = "ES8316 HiFi", | |
341 | .codec_name = "i2c-ESSX8316:00", | |
342 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | |
343 | | SND_SOC_DAIFMT_CBS_CFS, | |
344 | .be_hw_params_fixup = byt_cht_es8316_codec_fixup, | |
345 | .nonatomic = true, | |
346 | .dpcm_playback = 1, | |
347 | .dpcm_capture = 1, | |
348 | .init = byt_cht_es8316_init, | |
349 | }, | |
350 | }; | |
351 | ||
352 | ||
353 | /* SoC card */ | |
4bf538b4 HG |
354 | static char codec_name[SND_ACPI_I2C_ID_LEN]; |
355 | ||
356 | static int byt_cht_es8316_suspend(struct snd_soc_card *card) | |
357 | { | |
358 | struct snd_soc_component *component; | |
359 | ||
360 | for_each_card_components(card, component) { | |
361 | if (!strcmp(component->name, codec_name)) { | |
362 | dev_dbg(component->dev, "disabling jack detect before suspend\n"); | |
363 | snd_soc_component_set_jack(component, NULL, NULL); | |
364 | break; | |
365 | } | |
366 | } | |
367 | ||
368 | return 0; | |
369 | } | |
370 | ||
371 | static int byt_cht_es8316_resume(struct snd_soc_card *card) | |
372 | { | |
373 | struct byt_cht_es8316_private *priv = snd_soc_card_get_drvdata(card); | |
374 | struct snd_soc_component *component; | |
375 | ||
376 | for_each_card_components(card, component) { | |
377 | if (!strcmp(component->name, codec_name)) { | |
378 | dev_dbg(component->dev, "re-enabling jack detect after resume\n"); | |
379 | snd_soc_component_set_jack(component, &priv->jack, NULL); | |
380 | break; | |
381 | } | |
382 | } | |
383 | ||
0d3e91da HG |
384 | /* |
385 | * Some Cherry Trail boards with an ES8316 codec have a bug in their | |
386 | * ACPI tables where the MSSL1680 touchscreen's _PS0 and _PS3 methods | |
387 | * wrongly also set the speaker-enable GPIO to 1/0. Testing has shown | |
388 | * that this really is a bug and the GPIO has no influence on the | |
389 | * touchscreen at all. | |
390 | * | |
391 | * The silead.c touchscreen driver does not support runtime suspend, so | |
392 | * the GPIO can only be changed underneath us during a system suspend. | |
393 | * This resume() function runs from a pm complete() callback, and thus | |
394 | * is guaranteed to run after the touchscreen driver/ACPI-subsys has | |
395 | * brought the touchscreen back up again (and thus changed the GPIO). | |
396 | * | |
397 | * So to work around this we pass GPIOD_FLAGS_BIT_NONEXCLUSIVE when | |
398 | * requesting the GPIO and we set its value here to undo any changes | |
399 | * done by the touchscreen's broken _PS0 ACPI method. | |
400 | */ | |
401 | gpiod_set_value_cansleep(priv->speaker_en_gpio, priv->speaker_en); | |
402 | ||
4bf538b4 HG |
403 | return 0; |
404 | } | |
405 | ||
a03bdaa5 DD |
406 | static struct snd_soc_card byt_cht_es8316_card = { |
407 | .name = "bytcht-es8316", | |
408 | .owner = THIS_MODULE, | |
409 | .dai_link = byt_cht_es8316_dais, | |
410 | .num_links = ARRAY_SIZE(byt_cht_es8316_dais), | |
411 | .dapm_widgets = byt_cht_es8316_widgets, | |
412 | .num_dapm_widgets = ARRAY_SIZE(byt_cht_es8316_widgets), | |
413 | .dapm_routes = byt_cht_es8316_audio_map, | |
414 | .num_dapm_routes = ARRAY_SIZE(byt_cht_es8316_audio_map), | |
415 | .controls = byt_cht_es8316_controls, | |
416 | .num_controls = ARRAY_SIZE(byt_cht_es8316_controls), | |
417 | .fully_routed = true, | |
4bf538b4 HG |
418 | .suspend_pre = byt_cht_es8316_suspend, |
419 | .resume_post = byt_cht_es8316_resume, | |
a03bdaa5 DD |
420 | }; |
421 | ||
349e1386 HG |
422 | static const struct x86_cpu_id baytrail_cpu_ids[] = { |
423 | { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_SILVERMONT }, /* Valleyview */ | |
424 | {} | |
425 | }; | |
426 | ||
0d3e91da HG |
427 | static const struct acpi_gpio_params first_gpio = { 0, 0, false }; |
428 | ||
429 | static const struct acpi_gpio_mapping byt_cht_es8316_gpios[] = { | |
430 | { "speaker-enable-gpios", &first_gpio, 1 }, | |
431 | { }, | |
432 | }; | |
433 | ||
a03bdaa5 DD |
434 | static int snd_byt_cht_es8316_mc_probe(struct platform_device *pdev) |
435 | { | |
a03bdaa5 | 436 | struct byt_cht_es8316_private *priv; |
86909c8f | 437 | struct device *dev = &pdev->dev; |
3c22a73f PLB |
438 | struct snd_soc_acpi_mach *mach; |
439 | const char *i2c_name = NULL; | |
0d3e91da | 440 | struct device *codec_dev; |
3c22a73f PLB |
441 | int dai_index = 0; |
442 | int i; | |
443 | int ret = 0; | |
a03bdaa5 | 444 | |
86909c8f | 445 | priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); |
a03bdaa5 DD |
446 | if (!priv) |
447 | return -ENOMEM; | |
448 | ||
86909c8f | 449 | mach = dev->platform_data; |
3c22a73f PLB |
450 | /* fix index of codec dai */ |
451 | for (i = 0; i < ARRAY_SIZE(byt_cht_es8316_dais); i++) { | |
452 | if (!strcmp(byt_cht_es8316_dais[i].codec_name, | |
453 | "i2c-ESSX8316:00")) { | |
454 | dai_index = i; | |
455 | break; | |
456 | } | |
457 | } | |
458 | ||
459 | /* fixup codec name based on HID */ | |
3a147959 | 460 | i2c_name = acpi_dev_get_first_match_name(mach->id, NULL, -1); |
3c22a73f PLB |
461 | if (i2c_name) { |
462 | snprintf(codec_name, sizeof(codec_name), | |
463 | "%s%s", "i2c-", i2c_name); | |
464 | byt_cht_es8316_dais[dai_index].codec_name = codec_name; | |
465 | } | |
466 | ||
349e1386 HG |
467 | /* Check for BYTCR or other platform and setup quirks */ |
468 | if (x86_match_cpu(baytrail_cpu_ids) && | |
469 | mach->mach_params.acpi_ipc_irq_index == 0) { | |
730501a9 HG |
470 | /* On BYTCR default to SSP0, internal-mic-in2-map */ |
471 | quirk = BYT_CHT_ES8316_SSP0 | BYT_CHT_ES8316_INTMIC_IN2_MAP; | |
349e1386 | 472 | } else { |
730501a9 HG |
473 | /* Others default to internal-mic-in1-map */ |
474 | quirk = BYT_CHT_ES8316_INTMIC_IN1_MAP; | |
349e1386 HG |
475 | } |
476 | if (quirk_override != -1) { | |
477 | dev_info(dev, "Overriding quirk 0x%x => 0x%x\n", quirk, | |
478 | quirk_override); | |
479 | quirk = quirk_override; | |
480 | } | |
481 | log_quirks(dev); | |
482 | ||
483 | if (quirk & BYT_CHT_ES8316_SSP0) | |
484 | byt_cht_es8316_dais[dai_index].cpu_dai_name = "ssp0-port"; | |
485 | ||
86909c8f HG |
486 | /* get the clock */ |
487 | priv->mclk = devm_clk_get(dev, "pmc_plt_clk_3"); | |
a03bdaa5 DD |
488 | if (IS_ERR(priv->mclk)) { |
489 | ret = PTR_ERR(priv->mclk); | |
86909c8f | 490 | dev_err(dev, "clk_get pmc_plt_clk_3 failed: %d\n", ret); |
a03bdaa5 DD |
491 | return ret; |
492 | } | |
493 | ||
0d3e91da HG |
494 | /* get speaker enable GPIO */ |
495 | codec_dev = bus_find_device_by_name(&i2c_bus_type, NULL, codec_name); | |
496 | if (!codec_dev) | |
497 | return -EPROBE_DEFER; | |
498 | ||
499 | devm_acpi_dev_add_driver_gpios(codec_dev, byt_cht_es8316_gpios); | |
500 | priv->speaker_en_gpio = | |
501 | gpiod_get_index(codec_dev, "speaker-enable", 0, | |
502 | /* see comment in byt_cht_es8316_resume */ | |
503 | GPIOD_OUT_LOW | GPIOD_FLAGS_BIT_NONEXCLUSIVE); | |
504 | put_device(codec_dev); | |
505 | ||
506 | if (IS_ERR(priv->speaker_en_gpio)) { | |
507 | ret = PTR_ERR(priv->speaker_en_gpio); | |
508 | switch (ret) { | |
509 | case -ENOENT: | |
510 | priv->speaker_en_gpio = NULL; | |
511 | break; | |
512 | default: | |
513 | dev_err(dev, "get speaker GPIO failed: %d\n", ret); | |
514 | /* fall through */ | |
515 | case -EPROBE_DEFER: | |
516 | return ret; | |
517 | } | |
518 | } | |
519 | ||
86909c8f HG |
520 | /* register the soc card */ |
521 | byt_cht_es8316_card.dev = dev; | |
522 | snd_soc_card_set_drvdata(&byt_cht_es8316_card, priv); | |
523 | ||
524 | ret = devm_snd_soc_register_card(dev, &byt_cht_es8316_card); | |
a03bdaa5 | 525 | if (ret) { |
0d3e91da | 526 | gpiod_put(priv->speaker_en_gpio); |
86909c8f | 527 | dev_err(dev, "snd_soc_register_card failed: %d\n", ret); |
a03bdaa5 DD |
528 | return ret; |
529 | } | |
530 | platform_set_drvdata(pdev, &byt_cht_es8316_card); | |
86909c8f | 531 | return 0; |
a03bdaa5 DD |
532 | } |
533 | ||
0d3e91da HG |
534 | static int snd_byt_cht_es8316_mc_remove(struct platform_device *pdev) |
535 | { | |
536 | struct byt_cht_es8316_private *priv = platform_get_drvdata(pdev); | |
537 | ||
538 | gpiod_put(priv->speaker_en_gpio); | |
539 | return 0; | |
540 | } | |
541 | ||
a03bdaa5 DD |
542 | static struct platform_driver snd_byt_cht_es8316_mc_driver = { |
543 | .driver = { | |
544 | .name = "bytcht_es8316", | |
545 | }, | |
546 | .probe = snd_byt_cht_es8316_mc_probe, | |
0d3e91da | 547 | .remove = snd_byt_cht_es8316_mc_remove, |
a03bdaa5 DD |
548 | }; |
549 | ||
550 | module_platform_driver(snd_byt_cht_es8316_mc_driver); | |
551 | MODULE_DESCRIPTION("ASoC Intel(R) Baytrail/Cherrytrail Machine driver"); | |
552 | MODULE_AUTHOR("David Yang <yangxiaohua@everest-semi.com>"); | |
553 | MODULE_LICENSE("GPL v2"); | |
554 | MODULE_ALIAS("platform:bytcht_es8316"); |