.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * cht_bsw_rt5672.c - ASoc Machine driver for Intel Cherryview-based platforms |
---|
3 | 4 | * Cherrytrail and Braswell, with RT5672 codec. |
---|
.. | .. |
---|
5 | 6 | * Copyright (C) 2014 Intel Corp |
---|
6 | 7 | * Author: Subhransu S. Prusty <subhransu.s.prusty@intel.com> |
---|
7 | 8 | * Mengdong Lin <mengdong.lin@intel.com> |
---|
8 | | - * |
---|
9 | | - * This program is free software; you can redistribute it and/or modify |
---|
10 | | - * it under the terms of the GNU General Public License as published by |
---|
11 | | - * the Free Software Foundation; version 2 of the License. |
---|
12 | | - * |
---|
13 | | - * This program is distributed in the hope that it will be useful, but |
---|
14 | | - * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
16 | | - * General Public License for more details. |
---|
17 | 9 | */ |
---|
18 | 10 | |
---|
| 11 | +#include <linux/gpio/consumer.h> |
---|
| 12 | +#include <linux/input.h> |
---|
19 | 13 | #include <linux/module.h> |
---|
20 | 14 | #include <linux/platform_device.h> |
---|
21 | 15 | #include <linux/slab.h> |
---|
.. | .. |
---|
149 | 143 | static int cht_aif1_hw_params(struct snd_pcm_substream *substream, |
---|
150 | 144 | struct snd_pcm_hw_params *params) |
---|
151 | 145 | { |
---|
152 | | - struct snd_soc_pcm_runtime *rtd = substream->private_data; |
---|
153 | | - struct snd_soc_dai *codec_dai = rtd->codec_dai; |
---|
| 146 | + struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); |
---|
| 147 | + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0); |
---|
154 | 148 | int ret; |
---|
155 | 149 | |
---|
156 | 150 | /* set codec PLL source to the 19.2MHz platform clock (MCLK) */ |
---|
.. | .. |
---|
182 | 176 | static int cht_codec_init(struct snd_soc_pcm_runtime *runtime) |
---|
183 | 177 | { |
---|
184 | 178 | int ret; |
---|
185 | | - struct snd_soc_dai *codec_dai = runtime->codec_dai; |
---|
| 179 | + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(runtime, 0); |
---|
186 | 180 | struct snd_soc_component *component = codec_dai->component; |
---|
187 | 181 | struct cht_mc_private *ctx = snd_soc_card_get_drvdata(runtime->card); |
---|
188 | 182 | |
---|
.. | .. |
---|
211 | 205 | ARRAY_SIZE(cht_bsw_headset_pins)); |
---|
212 | 206 | if (ret) |
---|
213 | 207 | return ret; |
---|
| 208 | + |
---|
| 209 | + snd_jack_set_key(ctx->headset.jack, SND_JACK_BTN_0, KEY_PLAYPAUSE); |
---|
| 210 | + snd_jack_set_key(ctx->headset.jack, SND_JACK_BTN_1, KEY_VOLUMEUP); |
---|
| 211 | + snd_jack_set_key(ctx->headset.jack, SND_JACK_BTN_2, KEY_VOLUMEDOWN); |
---|
214 | 212 | |
---|
215 | 213 | rt5670_set_jack_detect(component, &ctx->headset); |
---|
216 | 214 | if (ctx->mclk) { |
---|
.. | .. |
---|
255 | 253 | params_set_format(params, SNDRV_PCM_FORMAT_S24_LE); |
---|
256 | 254 | |
---|
257 | 255 | /* |
---|
258 | | - * Default mode for SSP configuration is TDM 4 slot |
---|
| 256 | + * The default mode for the cpu-dai is TDM 4 slot. The default mode |
---|
| 257 | + * for the codec-dai is I2S. So we need to either set the cpu-dai to |
---|
| 258 | + * I2S mode to match the codec-dai, or set the codec-dai to TDM 4 slot |
---|
| 259 | + * (or program both to yet another mode). |
---|
| 260 | + * One board, the Lenovo Miix 2 10, uses not 1 but 2 codecs connected |
---|
| 261 | + * to SSP2. The second piggy-backed, output-only codec is inside the |
---|
| 262 | + * keyboard-dock (which has extra speakers). Unlike the main rt5672 |
---|
| 263 | + * codec, we cannot configure this codec, it is hard coded to use |
---|
| 264 | + * 2 channel 24 bit I2S. For this to work we must use I2S mode on this |
---|
| 265 | + * board. Since we only support 2 channels anyways, there is no need |
---|
| 266 | + * for TDM on any cht-bsw-rt5672 designs. So we use I2S 2ch everywhere. |
---|
259 | 267 | */ |
---|
260 | | - ret = snd_soc_dai_set_fmt(rtd->codec_dai, |
---|
261 | | - SND_SOC_DAIFMT_DSP_B | |
---|
262 | | - SND_SOC_DAIFMT_IB_NF | |
---|
| 268 | + ret = snd_soc_dai_set_fmt(asoc_rtd_to_cpu(rtd, 0), |
---|
| 269 | + SND_SOC_DAIFMT_I2S | |
---|
| 270 | + SND_SOC_DAIFMT_NB_NF | |
---|
263 | 271 | SND_SOC_DAIFMT_CBS_CFS); |
---|
264 | 272 | if (ret < 0) { |
---|
265 | | - dev_err(rtd->dev, "can't set format to TDM %d\n", ret); |
---|
266 | | - return ret; |
---|
267 | | - } |
---|
268 | | - |
---|
269 | | - /* TDM 4 slots 24 bit, set Rx & Tx bitmask to 4 active slots */ |
---|
270 | | - ret = snd_soc_dai_set_tdm_slot(rtd->codec_dai, 0xF, 0xF, 4, 24); |
---|
271 | | - if (ret < 0) { |
---|
272 | | - dev_err(rtd->dev, "can't set codec TDM slot %d\n", ret); |
---|
| 273 | + dev_err(rtd->dev, "can't set format to I2S, err %d\n", ret); |
---|
273 | 274 | return ret; |
---|
274 | 275 | } |
---|
275 | 276 | |
---|
.. | .. |
---|
290 | 291 | .hw_params = cht_aif1_hw_params, |
---|
291 | 292 | }; |
---|
292 | 293 | |
---|
| 294 | +SND_SOC_DAILINK_DEF(dummy, |
---|
| 295 | + DAILINK_COMP_ARRAY(COMP_DUMMY())); |
---|
| 296 | + |
---|
| 297 | +SND_SOC_DAILINK_DEF(media, |
---|
| 298 | + DAILINK_COMP_ARRAY(COMP_CPU("media-cpu-dai"))); |
---|
| 299 | + |
---|
| 300 | +SND_SOC_DAILINK_DEF(deepbuffer, |
---|
| 301 | + DAILINK_COMP_ARRAY(COMP_CPU("deepbuffer-cpu-dai"))); |
---|
| 302 | + |
---|
| 303 | +SND_SOC_DAILINK_DEF(ssp2_port, |
---|
| 304 | + DAILINK_COMP_ARRAY(COMP_CPU("ssp2-port"))); |
---|
| 305 | +SND_SOC_DAILINK_DEF(ssp2_codec, |
---|
| 306 | + DAILINK_COMP_ARRAY(COMP_CODEC("i2c-10EC5670:00", |
---|
| 307 | + "rt5670-aif1"))); |
---|
| 308 | + |
---|
| 309 | +SND_SOC_DAILINK_DEF(platform, |
---|
| 310 | + DAILINK_COMP_ARRAY(COMP_PLATFORM("sst-mfld-platform"))); |
---|
| 311 | + |
---|
293 | 312 | static struct snd_soc_dai_link cht_dailink[] = { |
---|
294 | 313 | /* Front End DAI links */ |
---|
295 | 314 | [MERR_DPCM_AUDIO] = { |
---|
296 | 315 | .name = "Audio Port", |
---|
297 | 316 | .stream_name = "Audio", |
---|
298 | | - .cpu_dai_name = "media-cpu-dai", |
---|
299 | | - .codec_dai_name = "snd-soc-dummy-dai", |
---|
300 | | - .codec_name = "snd-soc-dummy", |
---|
301 | | - .platform_name = "sst-mfld-platform", |
---|
302 | 317 | .nonatomic = true, |
---|
303 | 318 | .dynamic = 1, |
---|
304 | 319 | .dpcm_playback = 1, |
---|
305 | 320 | .dpcm_capture = 1, |
---|
306 | 321 | .ops = &cht_aif1_ops, |
---|
| 322 | + SND_SOC_DAILINK_REG(media, dummy, platform), |
---|
307 | 323 | }, |
---|
308 | 324 | [MERR_DPCM_DEEP_BUFFER] = { |
---|
309 | 325 | .name = "Deep-Buffer Audio Port", |
---|
310 | 326 | .stream_name = "Deep-Buffer Audio", |
---|
311 | | - .cpu_dai_name = "deepbuffer-cpu-dai", |
---|
312 | | - .codec_dai_name = "snd-soc-dummy-dai", |
---|
313 | | - .codec_name = "snd-soc-dummy", |
---|
314 | | - .platform_name = "sst-mfld-platform", |
---|
315 | 327 | .nonatomic = true, |
---|
316 | 328 | .dynamic = 1, |
---|
317 | 329 | .dpcm_playback = 1, |
---|
318 | 330 | .ops = &cht_aif1_ops, |
---|
| 331 | + SND_SOC_DAILINK_REG(deepbuffer, dummy, platform), |
---|
319 | 332 | }, |
---|
320 | 333 | |
---|
321 | 334 | /* Back End DAI links */ |
---|
.. | .. |
---|
323 | 336 | /* SSP2 - Codec */ |
---|
324 | 337 | .name = "SSP2-Codec", |
---|
325 | 338 | .id = 0, |
---|
326 | | - .cpu_dai_name = "ssp2-port", |
---|
327 | | - .platform_name = "sst-mfld-platform", |
---|
328 | 339 | .no_pcm = 1, |
---|
329 | 340 | .nonatomic = true, |
---|
330 | | - .codec_dai_name = "rt5670-aif1", |
---|
331 | | - .codec_name = "i2c-10EC5670:00", |
---|
332 | 341 | .init = cht_codec_init, |
---|
333 | 342 | .be_hw_params_fixup = cht_codec_fixup, |
---|
334 | 343 | .dpcm_playback = 1, |
---|
335 | 344 | .dpcm_capture = 1, |
---|
336 | 345 | .ops = &cht_be_ssp2_ops, |
---|
| 346 | + SND_SOC_DAILINK_REG(ssp2_port, ssp2_codec, platform), |
---|
337 | 347 | }, |
---|
338 | 348 | }; |
---|
339 | 349 | |
---|
.. | .. |
---|
342 | 352 | struct snd_soc_component *component; |
---|
343 | 353 | struct cht_mc_private *ctx = snd_soc_card_get_drvdata(card); |
---|
344 | 354 | |
---|
345 | | - list_for_each_entry(component, &card->component_dev_list, card_list) { |
---|
| 355 | + for_each_card_components(card, component) { |
---|
346 | 356 | if (!strncmp(component->name, |
---|
347 | 357 | ctx->codec_name, sizeof(ctx->codec_name))) { |
---|
348 | 358 | |
---|
.. | .. |
---|
359 | 369 | struct snd_soc_component *component; |
---|
360 | 370 | struct cht_mc_private *ctx = snd_soc_card_get_drvdata(card); |
---|
361 | 371 | |
---|
362 | | - list_for_each_entry(component, &card->component_dev_list, card_list) { |
---|
| 372 | + for_each_card_components(card, component) { |
---|
363 | 373 | if (!strncmp(component->name, |
---|
364 | 374 | ctx->codec_name, sizeof(ctx->codec_name))) { |
---|
365 | 375 | |
---|
.. | .. |
---|
372 | 382 | return 0; |
---|
373 | 383 | } |
---|
374 | 384 | |
---|
| 385 | +#if IS_ENABLED(CONFIG_SND_SOC_SOF_BAYTRAIL) |
---|
| 386 | +/* use space before codec name to simplify card ID, and simplify driver name */ |
---|
| 387 | +#define CARD_NAME "bytcht rt5672" /* card name will be 'sof-bytcht rt5672' */ |
---|
| 388 | +#define DRIVER_NAME "SOF" |
---|
| 389 | +#else |
---|
| 390 | +#define CARD_NAME "cht-bsw-rt5672" |
---|
| 391 | +#define DRIVER_NAME NULL /* card name will be used for driver name */ |
---|
| 392 | +#endif |
---|
| 393 | + |
---|
375 | 394 | /* SoC card */ |
---|
376 | 395 | static struct snd_soc_card snd_soc_card_cht = { |
---|
377 | | - .name = "cht-bsw-rt5672", |
---|
| 396 | + .name = CARD_NAME, |
---|
| 397 | + .driver_name = DRIVER_NAME, |
---|
378 | 398 | .owner = THIS_MODULE, |
---|
379 | 399 | .dai_link = cht_dailink, |
---|
380 | 400 | .num_links = ARRAY_SIZE(cht_dailink), |
---|
.. | .. |
---|
395 | 415 | int ret_val = 0; |
---|
396 | 416 | struct cht_mc_private *drv; |
---|
397 | 417 | struct snd_soc_acpi_mach *mach = pdev->dev.platform_data; |
---|
398 | | - const char *i2c_name; |
---|
| 418 | + const char *platform_name; |
---|
| 419 | + struct acpi_device *adev; |
---|
399 | 420 | int i; |
---|
400 | 421 | |
---|
401 | | - drv = devm_kzalloc(&pdev->dev, sizeof(*drv), GFP_ATOMIC); |
---|
| 422 | + drv = devm_kzalloc(&pdev->dev, sizeof(*drv), GFP_KERNEL); |
---|
402 | 423 | if (!drv) |
---|
403 | 424 | return -ENOMEM; |
---|
404 | 425 | |
---|
405 | 426 | strcpy(drv->codec_name, RT5672_I2C_DEFAULT); |
---|
406 | 427 | |
---|
407 | 428 | /* fixup codec name based on HID */ |
---|
408 | | - if (mach) { |
---|
409 | | - i2c_name = acpi_dev_get_first_match_name(mach->id, NULL, -1); |
---|
410 | | - if (i2c_name) { |
---|
411 | | - snprintf(drv->codec_name, sizeof(drv->codec_name), |
---|
412 | | - "i2c-%s", i2c_name); |
---|
413 | | - for (i = 0; i < ARRAY_SIZE(cht_dailink); i++) { |
---|
414 | | - if (!strcmp(cht_dailink[i].codec_name, |
---|
415 | | - RT5672_I2C_DEFAULT)) { |
---|
416 | | - cht_dailink[i].codec_name = |
---|
417 | | - drv->codec_name; |
---|
418 | | - break; |
---|
419 | | - } |
---|
| 429 | + adev = acpi_dev_get_first_match_dev(mach->id, NULL, -1); |
---|
| 430 | + if (adev) { |
---|
| 431 | + snprintf(drv->codec_name, sizeof(drv->codec_name), |
---|
| 432 | + "i2c-%s", acpi_dev_name(adev)); |
---|
| 433 | + put_device(&adev->dev); |
---|
| 434 | + for (i = 0; i < ARRAY_SIZE(cht_dailink); i++) { |
---|
| 435 | + if (!strcmp(cht_dailink[i].codecs->name, |
---|
| 436 | + RT5672_I2C_DEFAULT)) { |
---|
| 437 | + cht_dailink[i].codecs->name = drv->codec_name; |
---|
| 438 | + break; |
---|
420 | 439 | } |
---|
421 | 440 | } |
---|
422 | 441 | } |
---|
| 442 | + |
---|
| 443 | + /* override plaform name, if required */ |
---|
| 444 | + snd_soc_card_cht.dev = &pdev->dev; |
---|
| 445 | + platform_name = mach->mach_params.platform; |
---|
| 446 | + |
---|
| 447 | + ret_val = snd_soc_fixup_dai_links_platform_name(&snd_soc_card_cht, |
---|
| 448 | + platform_name); |
---|
| 449 | + if (ret_val) |
---|
| 450 | + return ret_val; |
---|
423 | 451 | |
---|
424 | 452 | drv->mclk = devm_clk_get(&pdev->dev, "pmc_plt_clk_3"); |
---|
425 | 453 | if (IS_ERR(drv->mclk)) { |
---|
.. | .. |
---|
431 | 459 | snd_soc_card_set_drvdata(&snd_soc_card_cht, drv); |
---|
432 | 460 | |
---|
433 | 461 | /* register the soc card */ |
---|
434 | | - snd_soc_card_cht.dev = &pdev->dev; |
---|
435 | 462 | ret_val = devm_snd_soc_register_card(&pdev->dev, &snd_soc_card_cht); |
---|
436 | 463 | if (ret_val) { |
---|
437 | 464 | dev_err(&pdev->dev, |
---|
.. | .. |
---|
445 | 472 | static struct platform_driver snd_cht_mc_driver = { |
---|
446 | 473 | .driver = { |
---|
447 | 474 | .name = "cht-bsw-rt5672", |
---|
| 475 | +#if IS_ENABLED(CONFIG_SND_SOC_SOF_BAYTRAIL) |
---|
| 476 | + .pm = &snd_soc_pm_ops, |
---|
| 477 | +#endif |
---|
448 | 478 | }, |
---|
449 | 479 | .probe = snd_cht_mc_probe, |
---|
450 | 480 | }; |
---|