| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * cht-bsw-max98090.c - ASoc Machine driver for Intel Cherryview-based |
|---|
| 3 | 4 | * platforms Cherrytrail and Braswell, with max98090 & TI codec. |
|---|
| .. | .. |
|---|
| 7 | 8 | * This file is modified from cht_bsw_rt5645.c |
|---|
| 8 | 9 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 9 | 10 | * |
|---|
| 10 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 11 | | - * it under the terms of the GNU General Public License as published by |
|---|
| 12 | | - * the Free Software Foundation; version 2 of the License. |
|---|
| 13 | | - * |
|---|
| 14 | | - * This program is distributed in the hope that it will be useful, but |
|---|
| 15 | | - * WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 16 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|---|
| 17 | | - * General Public License for more details. |
|---|
| 18 | | - * |
|---|
| 19 | 11 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 20 | 12 | */ |
|---|
| 21 | 13 | |
|---|
| 22 | 14 | #include <linux/dmi.h> |
|---|
| 15 | +#include <linux/gpio/consumer.h> |
|---|
| 23 | 16 | #include <linux/module.h> |
|---|
| 24 | 17 | #include <linux/platform_device.h> |
|---|
| 25 | 18 | #include <linux/slab.h> |
|---|
| .. | .. |
|---|
| 28 | 21 | #include <sound/pcm.h> |
|---|
| 29 | 22 | #include <sound/pcm_params.h> |
|---|
| 30 | 23 | #include <sound/soc.h> |
|---|
| 24 | +#include <sound/soc-acpi.h> |
|---|
| 31 | 25 | #include <sound/jack.h> |
|---|
| 32 | 26 | #include "../../codecs/max98090.h" |
|---|
| 33 | 27 | #include "../atom/sst-atom-controls.h" |
|---|
| .. | .. |
|---|
| 118 | 112 | static int cht_aif1_hw_params(struct snd_pcm_substream *substream, |
|---|
| 119 | 113 | struct snd_pcm_hw_params *params) |
|---|
| 120 | 114 | { |
|---|
| 121 | | - struct snd_soc_pcm_runtime *rtd = substream->private_data; |
|---|
| 122 | | - struct snd_soc_dai *codec_dai = rtd->codec_dai; |
|---|
| 115 | + struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); |
|---|
| 116 | + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0); |
|---|
| 123 | 117 | int ret; |
|---|
| 124 | 118 | |
|---|
| 125 | 119 | ret = snd_soc_dai_set_sysclk(codec_dai, M98090_REG_SYSTEM_CLOCK, |
|---|
| .. | .. |
|---|
| 263 | 257 | int ret = 0; |
|---|
| 264 | 258 | unsigned int fmt = 0; |
|---|
| 265 | 259 | |
|---|
| 266 | | - ret = snd_soc_dai_set_tdm_slot(rtd->cpu_dai, 0x3, 0x3, 2, 16); |
|---|
| 260 | + ret = snd_soc_dai_set_tdm_slot(asoc_rtd_to_cpu(rtd, 0), 0x3, 0x3, 2, 16); |
|---|
| 267 | 261 | if (ret < 0) { |
|---|
| 268 | 262 | dev_err(rtd->dev, "can't set cpu_dai slot fmt: %d\n", ret); |
|---|
| 269 | 263 | return ret; |
|---|
| .. | .. |
|---|
| 272 | 266 | fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
|---|
| 273 | 267 | | SND_SOC_DAIFMT_CBS_CFS; |
|---|
| 274 | 268 | |
|---|
| 275 | | - ret = snd_soc_dai_set_fmt(rtd->cpu_dai, fmt); |
|---|
| 269 | + ret = snd_soc_dai_set_fmt(asoc_rtd_to_cpu(rtd, 0), fmt); |
|---|
| 276 | 270 | if (ret < 0) { |
|---|
| 277 | 271 | dev_err(rtd->dev, "can't set cpu_dai set fmt: %d\n", ret); |
|---|
| 278 | 272 | return ret; |
|---|
| .. | .. |
|---|
| 331 | 325 | }; |
|---|
| 332 | 326 | |
|---|
| 333 | 327 | static struct snd_soc_aux_dev cht_max98090_headset_dev = { |
|---|
| 334 | | - .name = "Headset Chip", |
|---|
| 328 | + .dlc = COMP_AUX("i2c-104C227E:00"), |
|---|
| 335 | 329 | .init = cht_max98090_headset_init, |
|---|
| 336 | | - .codec_name = "i2c-104C227E:00", |
|---|
| 337 | 330 | }; |
|---|
| 331 | + |
|---|
| 332 | +SND_SOC_DAILINK_DEF(dummy, |
|---|
| 333 | + DAILINK_COMP_ARRAY(COMP_DUMMY())); |
|---|
| 334 | + |
|---|
| 335 | +SND_SOC_DAILINK_DEF(media, |
|---|
| 336 | + DAILINK_COMP_ARRAY(COMP_CPU("media-cpu-dai"))); |
|---|
| 337 | + |
|---|
| 338 | +SND_SOC_DAILINK_DEF(deepbuffer, |
|---|
| 339 | + DAILINK_COMP_ARRAY(COMP_CPU("deepbuffer-cpu-dai"))); |
|---|
| 340 | + |
|---|
| 341 | +SND_SOC_DAILINK_DEF(ssp2_port, |
|---|
| 342 | + DAILINK_COMP_ARRAY(COMP_CPU("ssp2-port"))); |
|---|
| 343 | +SND_SOC_DAILINK_DEF(ssp2_codec, |
|---|
| 344 | + DAILINK_COMP_ARRAY(COMP_CODEC("i2c-193C9890:00", "HiFi"))); |
|---|
| 345 | + |
|---|
| 346 | +SND_SOC_DAILINK_DEF(platform, |
|---|
| 347 | + DAILINK_COMP_ARRAY(COMP_PLATFORM("sst-mfld-platform"))); |
|---|
| 338 | 348 | |
|---|
| 339 | 349 | static struct snd_soc_dai_link cht_dailink[] = { |
|---|
| 340 | 350 | [MERR_DPCM_AUDIO] = { |
|---|
| 341 | 351 | .name = "Audio Port", |
|---|
| 342 | 352 | .stream_name = "Audio", |
|---|
| 343 | | - .cpu_dai_name = "media-cpu-dai", |
|---|
| 344 | | - .codec_dai_name = "snd-soc-dummy-dai", |
|---|
| 345 | | - .codec_name = "snd-soc-dummy", |
|---|
| 346 | | - .platform_name = "sst-mfld-platform", |
|---|
| 347 | 353 | .nonatomic = true, |
|---|
| 348 | 354 | .dynamic = 1, |
|---|
| 349 | 355 | .dpcm_playback = 1, |
|---|
| 350 | 356 | .dpcm_capture = 1, |
|---|
| 351 | 357 | .ops = &cht_aif1_ops, |
|---|
| 358 | + SND_SOC_DAILINK_REG(media, dummy, platform), |
|---|
| 352 | 359 | }, |
|---|
| 353 | 360 | [MERR_DPCM_DEEP_BUFFER] = { |
|---|
| 354 | 361 | .name = "Deep-Buffer Audio Port", |
|---|
| 355 | 362 | .stream_name = "Deep-Buffer Audio", |
|---|
| 356 | | - .cpu_dai_name = "deepbuffer-cpu-dai", |
|---|
| 357 | | - .codec_dai_name = "snd-soc-dummy-dai", |
|---|
| 358 | | - .codec_name = "snd-soc-dummy", |
|---|
| 359 | | - .platform_name = "sst-mfld-platform", |
|---|
| 360 | 363 | .nonatomic = true, |
|---|
| 361 | 364 | .dynamic = 1, |
|---|
| 362 | 365 | .dpcm_playback = 1, |
|---|
| 363 | 366 | .ops = &cht_aif1_ops, |
|---|
| 367 | + SND_SOC_DAILINK_REG(deepbuffer, dummy, platform), |
|---|
| 364 | 368 | }, |
|---|
| 365 | 369 | /* back ends */ |
|---|
| 366 | 370 | { |
|---|
| 367 | 371 | .name = "SSP2-Codec", |
|---|
| 368 | 372 | .id = 0, |
|---|
| 369 | | - .cpu_dai_name = "ssp2-port", |
|---|
| 370 | | - .platform_name = "sst-mfld-platform", |
|---|
| 371 | 373 | .no_pcm = 1, |
|---|
| 372 | | - .codec_dai_name = "HiFi", |
|---|
| 373 | | - .codec_name = "i2c-193C9890:00", |
|---|
| 374 | 374 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
|---|
| 375 | 375 | | SND_SOC_DAIFMT_CBS_CFS, |
|---|
| 376 | 376 | .init = cht_codec_init, |
|---|
| .. | .. |
|---|
| 378 | 378 | .dpcm_playback = 1, |
|---|
| 379 | 379 | .dpcm_capture = 1, |
|---|
| 380 | 380 | .ops = &cht_be_ssp2_ops, |
|---|
| 381 | + SND_SOC_DAILINK_REG(ssp2_port, ssp2_codec, platform), |
|---|
| 381 | 382 | }, |
|---|
| 382 | 383 | }; |
|---|
| 383 | 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 max98090" /* card name will be 'sof-bytcht max98090 */ |
|---|
| 388 | +#define DRIVER_NAME "SOF" |
|---|
| 389 | +#else |
|---|
| 390 | +#define CARD_NAME "chtmax98090" |
|---|
| 391 | +#define DRIVER_NAME NULL /* card name will be used for driver name */ |
|---|
| 392 | +#endif |
|---|
| 393 | + |
|---|
| 384 | 394 | /* SoC card */ |
|---|
| 385 | 395 | static struct snd_soc_card snd_soc_card_cht = { |
|---|
| 386 | | - .name = "chtmax98090", |
|---|
| 396 | + .name = CARD_NAME, |
|---|
| 397 | + .driver_name = DRIVER_NAME, |
|---|
| 387 | 398 | .owner = THIS_MODULE, |
|---|
| 388 | 399 | .dai_link = cht_dailink, |
|---|
| 389 | 400 | .num_links = ARRAY_SIZE(cht_dailink), |
|---|
| .. | .. |
|---|
| 399 | 410 | |
|---|
| 400 | 411 | static const struct dmi_system_id cht_max98090_quirk_table[] = { |
|---|
| 401 | 412 | { |
|---|
| 413 | + /* Banjo model Chromebook */ |
|---|
| 414 | + .matches = { |
|---|
| 415 | + DMI_MATCH(DMI_PRODUCT_NAME, "Banjo"), |
|---|
| 416 | + }, |
|---|
| 417 | + .driver_data = (void *)QUIRK_PMC_PLT_CLK_0, |
|---|
| 418 | + }, |
|---|
| 419 | + { |
|---|
| 420 | + /* Candy model Chromebook */ |
|---|
| 421 | + .matches = { |
|---|
| 422 | + DMI_MATCH(DMI_PRODUCT_NAME, "Candy"), |
|---|
| 423 | + }, |
|---|
| 424 | + .driver_data = (void *)QUIRK_PMC_PLT_CLK_0, |
|---|
| 425 | + }, |
|---|
| 426 | + { |
|---|
| 402 | 427 | /* Clapper model Chromebook */ |
|---|
| 403 | 428 | .matches = { |
|---|
| 404 | 429 | DMI_MATCH(DMI_PRODUCT_NAME, "Clapper"), |
|---|
| 430 | + }, |
|---|
| 431 | + .driver_data = (void *)QUIRK_PMC_PLT_CLK_0, |
|---|
| 432 | + }, |
|---|
| 433 | + { |
|---|
| 434 | + /* Cyan model Chromebook */ |
|---|
| 435 | + .matches = { |
|---|
| 436 | + DMI_MATCH(DMI_PRODUCT_NAME, "Cyan"), |
|---|
| 437 | + }, |
|---|
| 438 | + .driver_data = (void *)QUIRK_PMC_PLT_CLK_0, |
|---|
| 439 | + }, |
|---|
| 440 | + { |
|---|
| 441 | + /* Enguarde model Chromebook */ |
|---|
| 442 | + .matches = { |
|---|
| 443 | + DMI_MATCH(DMI_PRODUCT_NAME, "Enguarde"), |
|---|
| 444 | + }, |
|---|
| 445 | + .driver_data = (void *)QUIRK_PMC_PLT_CLK_0, |
|---|
| 446 | + }, |
|---|
| 447 | + { |
|---|
| 448 | + /* Glimmer model Chromebook */ |
|---|
| 449 | + .matches = { |
|---|
| 450 | + DMI_MATCH(DMI_PRODUCT_NAME, "Glimmer"), |
|---|
| 405 | 451 | }, |
|---|
| 406 | 452 | .driver_data = (void *)QUIRK_PMC_PLT_CLK_0, |
|---|
| 407 | 453 | }, |
|---|
| .. | .. |
|---|
| 413 | 459 | .driver_data = (void *)QUIRK_PMC_PLT_CLK_0, |
|---|
| 414 | 460 | }, |
|---|
| 415 | 461 | { |
|---|
| 462 | + /* Heli model Chromebook */ |
|---|
| 463 | + .matches = { |
|---|
| 464 | + DMI_MATCH(DMI_PRODUCT_NAME, "Heli"), |
|---|
| 465 | + }, |
|---|
| 466 | + .driver_data = (void *)QUIRK_PMC_PLT_CLK_0, |
|---|
| 467 | + }, |
|---|
| 468 | + { |
|---|
| 469 | + /* Kip model Chromebook */ |
|---|
| 470 | + .matches = { |
|---|
| 471 | + DMI_MATCH(DMI_PRODUCT_NAME, "Kip"), |
|---|
| 472 | + }, |
|---|
| 473 | + .driver_data = (void *)QUIRK_PMC_PLT_CLK_0, |
|---|
| 474 | + }, |
|---|
| 475 | + { |
|---|
| 476 | + /* Ninja model Chromebook */ |
|---|
| 477 | + .matches = { |
|---|
| 478 | + DMI_MATCH(DMI_PRODUCT_NAME, "Ninja"), |
|---|
| 479 | + }, |
|---|
| 480 | + .driver_data = (void *)QUIRK_PMC_PLT_CLK_0, |
|---|
| 481 | + }, |
|---|
| 482 | + { |
|---|
| 483 | + /* Orco model Chromebook */ |
|---|
| 484 | + .matches = { |
|---|
| 485 | + DMI_MATCH(DMI_PRODUCT_NAME, "Orco"), |
|---|
| 486 | + }, |
|---|
| 487 | + .driver_data = (void *)QUIRK_PMC_PLT_CLK_0, |
|---|
| 488 | + }, |
|---|
| 489 | + { |
|---|
| 490 | + /* Quawks model Chromebook */ |
|---|
| 491 | + .matches = { |
|---|
| 492 | + DMI_MATCH(DMI_PRODUCT_NAME, "Quawks"), |
|---|
| 493 | + }, |
|---|
| 494 | + .driver_data = (void *)QUIRK_PMC_PLT_CLK_0, |
|---|
| 495 | + }, |
|---|
| 496 | + { |
|---|
| 497 | + /* Rambi model Chromebook */ |
|---|
| 498 | + .matches = { |
|---|
| 499 | + DMI_MATCH(DMI_PRODUCT_NAME, "Rambi"), |
|---|
| 500 | + }, |
|---|
| 501 | + .driver_data = (void *)QUIRK_PMC_PLT_CLK_0, |
|---|
| 502 | + }, |
|---|
| 503 | + { |
|---|
| 504 | + /* Squawks model Chromebook */ |
|---|
| 505 | + .matches = { |
|---|
| 506 | + DMI_MATCH(DMI_PRODUCT_NAME, "Squawks"), |
|---|
| 507 | + }, |
|---|
| 508 | + .driver_data = (void *)QUIRK_PMC_PLT_CLK_0, |
|---|
| 509 | + }, |
|---|
| 510 | + { |
|---|
| 511 | + /* Sumo model Chromebook */ |
|---|
| 512 | + .matches = { |
|---|
| 513 | + DMI_MATCH(DMI_PRODUCT_NAME, "Sumo"), |
|---|
| 514 | + }, |
|---|
| 515 | + .driver_data = (void *)QUIRK_PMC_PLT_CLK_0, |
|---|
| 516 | + }, |
|---|
| 517 | + { |
|---|
| 416 | 518 | /* Swanky model Chromebook (Toshiba Chromebook 2) */ |
|---|
| 417 | 519 | .matches = { |
|---|
| 418 | 520 | DMI_MATCH(DMI_PRODUCT_NAME, "Swanky"), |
|---|
| 521 | + }, |
|---|
| 522 | + .driver_data = (void *)QUIRK_PMC_PLT_CLK_0, |
|---|
| 523 | + }, |
|---|
| 524 | + { |
|---|
| 525 | + /* Winky model Chromebook */ |
|---|
| 526 | + .matches = { |
|---|
| 527 | + DMI_MATCH(DMI_PRODUCT_NAME, "Winky"), |
|---|
| 419 | 528 | }, |
|---|
| 420 | 529 | .driver_data = (void *)QUIRK_PMC_PLT_CLK_0, |
|---|
| 421 | 530 | }, |
|---|
| .. | .. |
|---|
| 429 | 538 | int ret_val = 0; |
|---|
| 430 | 539 | struct cht_mc_private *drv; |
|---|
| 431 | 540 | const char *mclk_name; |
|---|
| 541 | + struct snd_soc_acpi_mach *mach; |
|---|
| 542 | + const char *platform_name; |
|---|
| 432 | 543 | |
|---|
| 433 | 544 | drv = devm_kzalloc(&pdev->dev, sizeof(*drv), GFP_KERNEL); |
|---|
| 434 | 545 | if (!drv) |
|---|
| .. | .. |
|---|
| 450 | 561 | dev_dbg(dev, "Unable to add GPIO mapping table\n"); |
|---|
| 451 | 562 | } |
|---|
| 452 | 563 | |
|---|
| 453 | | - /* register the soc card */ |
|---|
| 564 | + /* override plaform name, if required */ |
|---|
| 454 | 565 | snd_soc_card_cht.dev = &pdev->dev; |
|---|
| 566 | + mach = pdev->dev.platform_data; |
|---|
| 567 | + platform_name = mach->mach_params.platform; |
|---|
| 568 | + |
|---|
| 569 | + ret_val = snd_soc_fixup_dai_links_platform_name(&snd_soc_card_cht, |
|---|
| 570 | + platform_name); |
|---|
| 571 | + if (ret_val) |
|---|
| 572 | + return ret_val; |
|---|
| 573 | + |
|---|
| 574 | + /* register the soc card */ |
|---|
| 455 | 575 | snd_soc_card_set_drvdata(&snd_soc_card_cht, drv); |
|---|
| 456 | 576 | |
|---|
| 457 | 577 | if (drv->quirks & QUIRK_PMC_PLT_CLK_0) |
|---|
| .. | .. |
|---|
| 506 | 626 | static struct platform_driver snd_cht_mc_driver = { |
|---|
| 507 | 627 | .driver = { |
|---|
| 508 | 628 | .name = "cht-bsw-max98090", |
|---|
| 629 | +#if IS_ENABLED(CONFIG_SND_SOC_SOF_BAYTRAIL) |
|---|
| 630 | + .pm = &snd_soc_pm_ops, |
|---|
| 631 | +#endif |
|---|
| 509 | 632 | }, |
|---|
| 510 | 633 | .probe = snd_cht_mc_probe, |
|---|
| 511 | 634 | .remove = snd_cht_mc_remove, |
|---|