1 // SPDX-License-Identifier: GPL-2.0-only 2 /* 3 * tegra_asoc_machine.c - Universal ASoC machine driver for NVIDIA Tegra boards. 4 */ 5 6 #include <linux/clk.h> 7 #include <linux/export.h> 8 #include <linux/gpio/consumer.h> 9 #include <linux/module.h> 10 #include <linux/of.h> 11 #include <linux/of_device.h> 12 #include <linux/platform_device.h> 13 #include <linux/slab.h> 14 15 #include <sound/core.h> 16 #include <sound/jack.h> 17 #include <sound/pcm.h> 18 #include <sound/pcm_params.h> 19 #include <sound/soc.h> 20 21 #include "tegra_asoc_machine.h" 22 23 /* Headphones Jack */ 24 25 static struct snd_soc_jack tegra_machine_hp_jack; 26 27 static struct snd_soc_jack_pin tegra_machine_hp_jack_pins[] = { 28 { .pin = "Headphone", .mask = SND_JACK_HEADPHONE }, 29 { .pin = "Headphones", .mask = SND_JACK_HEADPHONE }, 30 }; 31 32 static struct snd_soc_jack_gpio tegra_machine_hp_jack_gpio = { 33 .name = "Headphones detection", 34 .report = SND_JACK_HEADPHONE, 35 .debounce_time = 150, 36 }; 37 38 /* Headset Jack */ 39 40 static struct snd_soc_jack tegra_machine_headset_jack; 41 42 static struct snd_soc_jack_pin tegra_machine_headset_jack_pins[] = { 43 { .pin = "Headset Mic", .mask = SND_JACK_MICROPHONE }, 44 { .pin = "Headset Stereophone", .mask = SND_JACK_HEADPHONE }, 45 }; 46 47 static struct snd_soc_jack_gpio tegra_machine_headset_jack_gpio = { 48 .name = "Headset detection", 49 .report = SND_JACK_HEADSET, 50 .debounce_time = 150, 51 }; 52 53 /* Mic Jack */ 54 55 static struct snd_soc_jack tegra_machine_mic_jack; 56 57 static struct snd_soc_jack_pin tegra_machine_mic_jack_pins[] = { 58 { .pin = "Mic Jack", .mask = SND_JACK_MICROPHONE }, 59 { .pin = "Headset Mic", .mask = SND_JACK_MICROPHONE }, 60 }; 61 62 static struct snd_soc_jack_gpio tegra_machine_mic_jack_gpio = { 63 .name = "Mic detection", 64 .report = SND_JACK_MICROPHONE, 65 .debounce_time = 150, 66 }; 67 68 static int tegra_machine_event(struct snd_soc_dapm_widget *w, 69 struct snd_kcontrol *k, int event) 70 { 71 struct snd_soc_dapm_context *dapm = w->dapm; 72 struct tegra_machine *machine = snd_soc_card_get_drvdata(dapm->card); 73 74 if (!strcmp(w->name, "Int Spk") || !strcmp(w->name, "Speakers")) 75 gpiod_set_value_cansleep(machine->gpiod_spkr_en, 76 SND_SOC_DAPM_EVENT_ON(event)); 77 78 if (!strcmp(w->name, "Mic Jack")) 79 gpiod_set_value_cansleep(machine->gpiod_ext_mic_en, 80 SND_SOC_DAPM_EVENT_ON(event)); 81 82 if (!strcmp(w->name, "Int Mic")) 83 gpiod_set_value_cansleep(machine->gpiod_int_mic_en, 84 SND_SOC_DAPM_EVENT_ON(event)); 85 86 if (!strcmp(w->name, "Headphone") || !strcmp(w->name, "Headphone Jack")) 87 gpiod_set_value_cansleep(machine->gpiod_hp_mute, 88 !SND_SOC_DAPM_EVENT_ON(event)); 89 90 return 0; 91 } 92 93 static const struct snd_soc_dapm_widget tegra_machine_dapm_widgets[] = { 94 SND_SOC_DAPM_HP("Headphone Jack", tegra_machine_event), 95 SND_SOC_DAPM_HP("Headphone", tegra_machine_event), 96 SND_SOC_DAPM_HP("Headset Stereophone", NULL), 97 SND_SOC_DAPM_HP("Headphones", NULL), 98 SND_SOC_DAPM_SPK("Speakers", tegra_machine_event), 99 SND_SOC_DAPM_SPK("Int Spk", tegra_machine_event), 100 SND_SOC_DAPM_MIC("Int Mic", tegra_machine_event), 101 SND_SOC_DAPM_MIC("Mic Jack", tegra_machine_event), 102 SND_SOC_DAPM_MIC("Internal Mic 1", NULL), 103 SND_SOC_DAPM_MIC("Internal Mic 2", NULL), 104 SND_SOC_DAPM_MIC("Headset Mic", NULL), 105 SND_SOC_DAPM_MIC("Digital Mic", NULL), 106 SND_SOC_DAPM_MIC("Mic", NULL), 107 SND_SOC_DAPM_LINE("Line In Jack", NULL), 108 SND_SOC_DAPM_LINE("Line In", NULL), 109 SND_SOC_DAPM_LINE("LineIn", NULL), 110 }; 111 112 static const struct snd_kcontrol_new tegra_machine_controls[] = { 113 SOC_DAPM_PIN_SWITCH("Speakers"), 114 SOC_DAPM_PIN_SWITCH("Int Spk"), 115 SOC_DAPM_PIN_SWITCH("Int Mic"), 116 SOC_DAPM_PIN_SWITCH("Headset Mic"), 117 SOC_DAPM_PIN_SWITCH("Internal Mic 1"), 118 SOC_DAPM_PIN_SWITCH("Internal Mic 2"), 119 }; 120 121 int tegra_asoc_machine_init(struct snd_soc_pcm_runtime *rtd) 122 { 123 struct snd_soc_card *card = rtd->card; 124 struct tegra_machine *machine = snd_soc_card_get_drvdata(card); 125 int err; 126 127 if (machine->gpiod_hp_det && machine->asoc->add_hp_jack) { 128 err = snd_soc_card_jack_new(card, "Headphones Jack", 129 SND_JACK_HEADPHONE, 130 &tegra_machine_hp_jack, 131 tegra_machine_hp_jack_pins, 132 ARRAY_SIZE(tegra_machine_hp_jack_pins)); 133 if (err) { 134 dev_err(rtd->dev, 135 "Headphones Jack creation failed: %d\n", err); 136 return err; 137 } 138 139 tegra_machine_hp_jack_gpio.desc = machine->gpiod_hp_det; 140 141 err = snd_soc_jack_add_gpios(&tegra_machine_hp_jack, 1, 142 &tegra_machine_hp_jack_gpio); 143 if (err) 144 dev_err(rtd->dev, "HP GPIOs not added: %d\n", err); 145 } 146 147 if (machine->gpiod_hp_det && machine->asoc->add_headset_jack) { 148 err = snd_soc_card_jack_new(card, "Headset Jack", 149 SND_JACK_HEADSET, 150 &tegra_machine_headset_jack, 151 tegra_machine_headset_jack_pins, 152 ARRAY_SIZE(tegra_machine_headset_jack_pins)); 153 if (err) { 154 dev_err(rtd->dev, 155 "Headset Jack creation failed: %d\n", err); 156 return err; 157 } 158 159 tegra_machine_headset_jack_gpio.desc = machine->gpiod_hp_det; 160 161 err = snd_soc_jack_add_gpios(&tegra_machine_headset_jack, 1, 162 &tegra_machine_headset_jack_gpio); 163 if (err) 164 dev_err(rtd->dev, "Headset GPIOs not added: %d\n", err); 165 } 166 167 if (machine->gpiod_mic_det && machine->asoc->add_mic_jack) { 168 err = snd_soc_card_jack_new(rtd->card, "Mic Jack", 169 SND_JACK_MICROPHONE, 170 &tegra_machine_mic_jack, 171 tegra_machine_mic_jack_pins, 172 ARRAY_SIZE(tegra_machine_mic_jack_pins)); 173 if (err) { 174 dev_err(rtd->dev, "Mic Jack creation failed: %d\n", err); 175 return err; 176 } 177 178 tegra_machine_mic_jack_gpio.desc = machine->gpiod_mic_det; 179 180 err = snd_soc_jack_add_gpios(&tegra_machine_mic_jack, 1, 181 &tegra_machine_mic_jack_gpio); 182 if (err) 183 dev_err(rtd->dev, "Mic GPIOs not added: %d\n", err); 184 } 185 186 return 0; 187 } 188 EXPORT_SYMBOL_GPL(tegra_asoc_machine_init); 189 190 static unsigned int tegra_machine_mclk_rate_128(unsigned int srate) 191 { 192 return 128 * srate; 193 } 194 195 static unsigned int tegra_machine_mclk_rate_256(unsigned int srate) 196 { 197 return 256 * srate; 198 } 199 200 static unsigned int tegra_machine_mclk_rate_512(unsigned int srate) 201 { 202 return 512 * srate; 203 } 204 205 static unsigned int tegra_machine_mclk_rate_12mhz(unsigned int srate) 206 { 207 unsigned int mclk; 208 209 switch (srate) { 210 case 8000: 211 case 16000: 212 case 24000: 213 case 32000: 214 case 48000: 215 case 64000: 216 case 96000: 217 mclk = 12288000; 218 break; 219 case 11025: 220 case 22050: 221 case 44100: 222 case 88200: 223 mclk = 11289600; 224 break; 225 default: 226 mclk = 12000000; 227 break; 228 } 229 230 return mclk; 231 } 232 233 static int tegra_machine_hw_params(struct snd_pcm_substream *substream, 234 struct snd_pcm_hw_params *params) 235 { 236 struct snd_soc_pcm_runtime *rtd = substream->private_data; 237 struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0); 238 struct snd_soc_card *card = rtd->card; 239 struct tegra_machine *machine = snd_soc_card_get_drvdata(card); 240 unsigned int srate = params_rate(params); 241 unsigned int mclk = machine->asoc->mclk_rate(srate); 242 unsigned int clk_id = machine->asoc->mclk_id; 243 unsigned int new_baseclock; 244 int err; 245 246 switch (srate) { 247 case 11025: 248 case 22050: 249 case 44100: 250 case 88200: 251 if (of_machine_is_compatible("nvidia,tegra20")) 252 new_baseclock = 56448000; 253 else if (of_machine_is_compatible("nvidia,tegra30")) 254 new_baseclock = 564480000; 255 else 256 new_baseclock = 282240000; 257 break; 258 case 8000: 259 case 16000: 260 case 32000: 261 case 48000: 262 case 64000: 263 case 96000: 264 if (of_machine_is_compatible("nvidia,tegra20")) 265 new_baseclock = 73728000; 266 else if (of_machine_is_compatible("nvidia,tegra30")) 267 new_baseclock = 552960000; 268 else 269 new_baseclock = 368640000; 270 break; 271 default: 272 dev_err(card->dev, "Invalid sound rate: %u\n", srate); 273 return -EINVAL; 274 } 275 276 if (new_baseclock != machine->set_baseclock || 277 mclk != machine->set_mclk) { 278 machine->set_baseclock = 0; 279 machine->set_mclk = 0; 280 281 clk_disable_unprepare(machine->clk_cdev1); 282 283 err = clk_set_rate(machine->clk_pll_a, new_baseclock); 284 if (err) { 285 dev_err(card->dev, "Can't set pll_a rate: %d\n", err); 286 return err; 287 } 288 289 err = clk_set_rate(machine->clk_pll_a_out0, mclk); 290 if (err) { 291 dev_err(card->dev, "Can't set pll_a_out0 rate: %d\n", err); 292 return err; 293 } 294 295 /* Don't set cdev1/extern1 rate; it's locked to pll_a_out0 */ 296 297 err = clk_prepare_enable(machine->clk_cdev1); 298 if (err) { 299 dev_err(card->dev, "Can't enable cdev1: %d\n", err); 300 return err; 301 } 302 303 machine->set_baseclock = new_baseclock; 304 machine->set_mclk = mclk; 305 } 306 307 err = snd_soc_dai_set_sysclk(codec_dai, clk_id, mclk, SND_SOC_CLOCK_IN); 308 if (err < 0) { 309 dev_err(card->dev, "codec_dai clock not set: %d\n", err); 310 return err; 311 } 312 313 return 0; 314 } 315 316 static struct snd_soc_ops tegra_machine_snd_ops = { 317 .hw_params = tegra_machine_hw_params, 318 }; 319 320 static void tegra_machine_node_release(void *of_node) 321 { 322 of_node_put(of_node); 323 } 324 325 static struct device_node * 326 tegra_machine_parse_phandle(struct device *dev, const char *name) 327 { 328 struct device_node *np; 329 int err; 330 331 np = of_parse_phandle(dev->of_node, name, 0); 332 if (!np) { 333 dev_err(dev, "Property '%s' missing or invalid\n", name); 334 return ERR_PTR(-EINVAL); 335 } 336 337 err = devm_add_action_or_reset(dev, tegra_machine_node_release, np); 338 if (err) 339 return ERR_PTR(err); 340 341 return np; 342 } 343 344 int tegra_asoc_machine_probe(struct platform_device *pdev) 345 { 346 struct device_node *np_codec, *np_i2s; 347 const struct tegra_asoc_data *asoc; 348 struct device *dev = &pdev->dev; 349 struct tegra_machine *machine; 350 struct snd_soc_card *card; 351 struct gpio_desc *gpiod; 352 int err; 353 354 machine = devm_kzalloc(dev, sizeof(*machine), GFP_KERNEL); 355 if (!machine) 356 return -ENOMEM; 357 358 asoc = of_device_get_match_data(dev); 359 card = asoc->card; 360 card->dev = dev; 361 362 machine->asoc = asoc; 363 machine->mic_jack = &tegra_machine_mic_jack; 364 machine->hp_jack_gpio = &tegra_machine_hp_jack_gpio; 365 snd_soc_card_set_drvdata(card, machine); 366 367 gpiod = devm_gpiod_get_optional(dev, "nvidia,hp-mute", GPIOD_OUT_HIGH); 368 machine->gpiod_hp_mute = gpiod; 369 if (IS_ERR(gpiod)) 370 return PTR_ERR(gpiod); 371 372 gpiod = devm_gpiod_get_optional(dev, "nvidia,hp-det", GPIOD_IN); 373 machine->gpiod_hp_det = gpiod; 374 if (IS_ERR(gpiod)) 375 return PTR_ERR(gpiod); 376 377 gpiod = devm_gpiod_get_optional(dev, "nvidia,mic-det", GPIOD_IN); 378 machine->gpiod_mic_det = gpiod; 379 if (IS_ERR(gpiod)) 380 return PTR_ERR(gpiod); 381 382 gpiod = devm_gpiod_get_optional(dev, "nvidia,spkr-en", GPIOD_OUT_LOW); 383 machine->gpiod_spkr_en = gpiod; 384 if (IS_ERR(gpiod)) 385 return PTR_ERR(gpiod); 386 387 gpiod = devm_gpiod_get_optional(dev, "nvidia,int-mic-en", GPIOD_OUT_LOW); 388 machine->gpiod_int_mic_en = gpiod; 389 if (IS_ERR(gpiod)) 390 return PTR_ERR(gpiod); 391 392 gpiod = devm_gpiod_get_optional(dev, "nvidia,ext-mic-en", GPIOD_OUT_LOW); 393 machine->gpiod_ext_mic_en = gpiod; 394 if (IS_ERR(gpiod)) 395 return PTR_ERR(gpiod); 396 397 err = snd_soc_of_parse_card_name(card, "nvidia,model"); 398 if (err) 399 return err; 400 401 if (!card->dapm_routes) { 402 err = snd_soc_of_parse_audio_routing(card, "nvidia,audio-routing"); 403 if (err) 404 return err; 405 } 406 407 np_codec = tegra_machine_parse_phandle(dev, "nvidia,audio-codec"); 408 if (IS_ERR(np_codec)) 409 return PTR_ERR(np_codec); 410 411 np_i2s = tegra_machine_parse_phandle(dev, "nvidia,i2s-controller"); 412 if (IS_ERR(np_i2s)) 413 return PTR_ERR(np_i2s); 414 415 card->dai_link->cpus->of_node = np_i2s; 416 card->dai_link->codecs->of_node = np_codec; 417 card->dai_link->platforms->of_node = np_i2s; 418 419 if (asoc->add_common_controls) { 420 card->controls = tegra_machine_controls; 421 card->num_controls = ARRAY_SIZE(tegra_machine_controls); 422 } 423 424 if (asoc->add_common_dapm_widgets) { 425 card->dapm_widgets = tegra_machine_dapm_widgets; 426 card->num_dapm_widgets = ARRAY_SIZE(tegra_machine_dapm_widgets); 427 } 428 429 if (asoc->add_common_snd_ops) 430 card->dai_link->ops = &tegra_machine_snd_ops; 431 432 if (!card->owner) 433 card->owner = THIS_MODULE; 434 if (!card->driver_name) 435 card->driver_name = "tegra"; 436 437 machine->clk_pll_a = devm_clk_get(dev, "pll_a"); 438 if (IS_ERR(machine->clk_pll_a)) { 439 dev_err(dev, "Can't retrieve clk pll_a\n"); 440 return PTR_ERR(machine->clk_pll_a); 441 } 442 443 machine->clk_pll_a_out0 = devm_clk_get(dev, "pll_a_out0"); 444 if (IS_ERR(machine->clk_pll_a_out0)) { 445 dev_err(dev, "Can't retrieve clk pll_a_out0\n"); 446 return PTR_ERR(machine->clk_pll_a_out0); 447 } 448 449 machine->clk_cdev1 = devm_clk_get(dev, "mclk"); 450 if (IS_ERR(machine->clk_cdev1)) { 451 dev_err(dev, "Can't retrieve clk cdev1\n"); 452 return PTR_ERR(machine->clk_cdev1); 453 } 454 455 /* 456 * If clock parents are not set in DT, configure here to use clk_out_1 457 * as mclk and extern1 as parent for Tegra30 and higher. 458 */ 459 if (!of_find_property(dev->of_node, "assigned-clock-parents", NULL) && 460 !of_machine_is_compatible("nvidia,tegra20")) { 461 struct clk *clk_out_1, *clk_extern1; 462 463 dev_warn(dev, "Configuring clocks for a legacy device-tree\n"); 464 dev_warn(dev, "Please update DT to use assigned-clock-parents\n"); 465 466 clk_extern1 = devm_clk_get(dev, "extern1"); 467 if (IS_ERR(clk_extern1)) { 468 dev_err(dev, "Can't retrieve clk extern1\n"); 469 return PTR_ERR(clk_extern1); 470 } 471 472 err = clk_set_parent(clk_extern1, machine->clk_pll_a_out0); 473 if (err < 0) { 474 dev_err(dev, "Set parent failed for clk extern1\n"); 475 return err; 476 } 477 478 clk_out_1 = devm_clk_get(dev, "pmc_clk_out_1"); 479 if (IS_ERR(clk_out_1)) { 480 dev_err(dev, "Can't retrieve pmc_clk_out_1\n"); 481 return PTR_ERR(clk_out_1); 482 } 483 484 err = clk_set_parent(clk_out_1, clk_extern1); 485 if (err < 0) { 486 dev_err(dev, "Set parent failed for pmc_clk_out_1\n"); 487 return err; 488 } 489 490 machine->clk_cdev1 = clk_out_1; 491 } 492 493 if (asoc->set_ac97) { 494 /* 495 * AC97 rate is fixed at 24.576MHz and is used for both the 496 * host controller and the external codec 497 */ 498 err = clk_set_rate(machine->clk_pll_a, 73728000); 499 if (err) { 500 dev_err(dev, "Can't set pll_a rate: %d\n", err); 501 return err; 502 } 503 504 err = clk_set_rate(machine->clk_pll_a_out0, 24576000); 505 if (err) { 506 dev_err(dev, "Can't set pll_a_out0 rate: %d\n", err); 507 return err; 508 } 509 510 machine->set_baseclock = 73728000; 511 machine->set_mclk = 24576000; 512 } 513 514 /* 515 * FIXME: There is some unknown dependency between audio MCLK disable 516 * and suspend-resume functionality on Tegra30, although audio MCLK is 517 * only needed for audio. 518 */ 519 err = clk_prepare_enable(machine->clk_cdev1); 520 if (err) { 521 dev_err(dev, "Can't enable cdev1: %d\n", err); 522 return err; 523 } 524 525 err = devm_snd_soc_register_card(dev, card); 526 if (err) 527 return err; 528 529 return 0; 530 } 531 EXPORT_SYMBOL_GPL(tegra_asoc_machine_probe); 532 533 /* WM8753 machine */ 534 535 SND_SOC_DAILINK_DEFS(wm8753_hifi, 536 DAILINK_COMP_ARRAY(COMP_EMPTY()), 537 DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "wm8753-hifi")), 538 DAILINK_COMP_ARRAY(COMP_EMPTY())); 539 540 static struct snd_soc_dai_link tegra_wm8753_dai = { 541 .name = "WM8753", 542 .stream_name = "WM8753 PCM", 543 .dai_fmt = SND_SOC_DAIFMT_I2S | 544 SND_SOC_DAIFMT_NB_NF | 545 SND_SOC_DAIFMT_CBS_CFS, 546 SND_SOC_DAILINK_REG(wm8753_hifi), 547 }; 548 549 static struct snd_soc_card snd_soc_tegra_wm8753 = { 550 .components = "codec:wm8753", 551 .dai_link = &tegra_wm8753_dai, 552 .num_links = 1, 553 .fully_routed = true, 554 }; 555 556 static const struct tegra_asoc_data tegra_wm8753_data = { 557 .mclk_rate = tegra_machine_mclk_rate_12mhz, 558 .card = &snd_soc_tegra_wm8753, 559 .add_common_dapm_widgets = true, 560 .add_common_snd_ops = true, 561 }; 562 563 /* WM9712 machine */ 564 565 static int tegra_wm9712_init(struct snd_soc_pcm_runtime *rtd) 566 { 567 return snd_soc_dapm_force_enable_pin(&rtd->card->dapm, "Mic Bias"); 568 } 569 570 SND_SOC_DAILINK_DEFS(wm9712_hifi, 571 DAILINK_COMP_ARRAY(COMP_EMPTY()), 572 DAILINK_COMP_ARRAY(COMP_CODEC("wm9712-codec", "wm9712-hifi")), 573 DAILINK_COMP_ARRAY(COMP_EMPTY())); 574 575 static struct snd_soc_dai_link tegra_wm9712_dai = { 576 .name = "AC97 HiFi", 577 .stream_name = "AC97 HiFi", 578 .init = tegra_wm9712_init, 579 SND_SOC_DAILINK_REG(wm9712_hifi), 580 }; 581 582 static struct snd_soc_card snd_soc_tegra_wm9712 = { 583 .components = "codec:wm9712", 584 .dai_link = &tegra_wm9712_dai, 585 .num_links = 1, 586 .fully_routed = true, 587 }; 588 589 static const struct tegra_asoc_data tegra_wm9712_data = { 590 .card = &snd_soc_tegra_wm9712, 591 .add_common_dapm_widgets = true, 592 .set_ac97 = true, 593 }; 594 595 /* MAX98090 machine */ 596 597 SND_SOC_DAILINK_DEFS(max98090_hifi, 598 DAILINK_COMP_ARRAY(COMP_EMPTY()), 599 DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "HiFi")), 600 DAILINK_COMP_ARRAY(COMP_EMPTY())); 601 602 static struct snd_soc_dai_link tegra_max98090_dai = { 603 .name = "max98090", 604 .stream_name = "max98090 PCM", 605 .init = tegra_asoc_machine_init, 606 .dai_fmt = SND_SOC_DAIFMT_I2S | 607 SND_SOC_DAIFMT_NB_NF | 608 SND_SOC_DAIFMT_CBS_CFS, 609 SND_SOC_DAILINK_REG(max98090_hifi), 610 }; 611 612 static struct snd_soc_card snd_soc_tegra_max98090 = { 613 .components = "codec:max98090", 614 .dai_link = &tegra_max98090_dai, 615 .num_links = 1, 616 .fully_routed = true, 617 }; 618 619 static const struct tegra_asoc_data tegra_max98090_data = { 620 .mclk_rate = tegra_machine_mclk_rate_12mhz, 621 .card = &snd_soc_tegra_max98090, 622 .add_common_dapm_widgets = true, 623 .add_common_controls = true, 624 .add_common_snd_ops = true, 625 .add_mic_jack = true, 626 .add_hp_jack = true, 627 }; 628 629 /* SGTL5000 machine */ 630 631 SND_SOC_DAILINK_DEFS(sgtl5000_hifi, 632 DAILINK_COMP_ARRAY(COMP_EMPTY()), 633 DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "sgtl5000")), 634 DAILINK_COMP_ARRAY(COMP_EMPTY())); 635 636 static struct snd_soc_dai_link tegra_sgtl5000_dai = { 637 .name = "sgtl5000", 638 .stream_name = "HiFi", 639 .dai_fmt = SND_SOC_DAIFMT_I2S | 640 SND_SOC_DAIFMT_NB_NF | 641 SND_SOC_DAIFMT_CBS_CFS, 642 SND_SOC_DAILINK_REG(sgtl5000_hifi), 643 }; 644 645 static struct snd_soc_card snd_soc_tegra_sgtl5000 = { 646 .components = "codec:sgtl5000", 647 .dai_link = &tegra_sgtl5000_dai, 648 .num_links = 1, 649 .fully_routed = true, 650 }; 651 652 static const struct tegra_asoc_data tegra_sgtl5000_data = { 653 .mclk_rate = tegra_machine_mclk_rate_12mhz, 654 .card = &snd_soc_tegra_sgtl5000, 655 .add_common_dapm_widgets = true, 656 .add_common_snd_ops = true, 657 }; 658 659 /* TLV320AIC23 machine */ 660 661 static const struct snd_soc_dapm_widget trimslice_dapm_widgets[] = { 662 SND_SOC_DAPM_HP("Line Out", NULL), 663 SND_SOC_DAPM_LINE("Line In", NULL), 664 }; 665 666 static const struct snd_soc_dapm_route trimslice_audio_map[] = { 667 {"Line Out", NULL, "LOUT"}, 668 {"Line Out", NULL, "ROUT"}, 669 670 {"LLINEIN", NULL, "Line In"}, 671 {"RLINEIN", NULL, "Line In"}, 672 }; 673 674 SND_SOC_DAILINK_DEFS(tlv320aic23_hifi, 675 DAILINK_COMP_ARRAY(COMP_EMPTY()), 676 DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "tlv320aic23-hifi")), 677 DAILINK_COMP_ARRAY(COMP_EMPTY())); 678 679 static struct snd_soc_dai_link tegra_tlv320aic23_dai = { 680 .name = "TLV320AIC23", 681 .stream_name = "AIC23", 682 .dai_fmt = SND_SOC_DAIFMT_I2S | 683 SND_SOC_DAIFMT_NB_NF | 684 SND_SOC_DAIFMT_CBS_CFS, 685 SND_SOC_DAILINK_REG(tlv320aic23_hifi), 686 }; 687 688 static struct snd_soc_card snd_soc_tegra_trimslice = { 689 .components = "codec:tlv320aic23", 690 .dai_link = &tegra_tlv320aic23_dai, 691 .num_links = 1, 692 .dapm_widgets = trimslice_dapm_widgets, 693 .num_dapm_widgets = ARRAY_SIZE(trimslice_dapm_widgets), 694 .dapm_routes = trimslice_audio_map, 695 .num_dapm_routes = ARRAY_SIZE(trimslice_audio_map), 696 .fully_routed = true, 697 }; 698 699 static const struct tegra_asoc_data tegra_trimslice_data = { 700 .mclk_rate = tegra_machine_mclk_rate_128, 701 .card = &snd_soc_tegra_trimslice, 702 .add_common_snd_ops = true, 703 }; 704 705 /* RT5677 machine */ 706 707 static int tegra_rt5677_init(struct snd_soc_pcm_runtime *rtd) 708 { 709 struct snd_soc_card *card = rtd->card; 710 int err; 711 712 err = tegra_asoc_machine_init(rtd); 713 if (err) 714 return err; 715 716 snd_soc_dapm_force_enable_pin(&card->dapm, "MICBIAS1"); 717 718 return 0; 719 } 720 721 SND_SOC_DAILINK_DEFS(rt5677_aif1, 722 DAILINK_COMP_ARRAY(COMP_EMPTY()), 723 DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "rt5677-aif1")), 724 DAILINK_COMP_ARRAY(COMP_EMPTY())); 725 726 static struct snd_soc_dai_link tegra_rt5677_dai = { 727 .name = "RT5677", 728 .stream_name = "RT5677 PCM", 729 .init = tegra_rt5677_init, 730 .dai_fmt = SND_SOC_DAIFMT_I2S | 731 SND_SOC_DAIFMT_NB_NF | 732 SND_SOC_DAIFMT_CBS_CFS, 733 SND_SOC_DAILINK_REG(rt5677_aif1), 734 }; 735 736 static struct snd_soc_card snd_soc_tegra_rt5677 = { 737 .components = "codec:rt5677", 738 .dai_link = &tegra_rt5677_dai, 739 .num_links = 1, 740 .fully_routed = true, 741 }; 742 743 static const struct tegra_asoc_data tegra_rt5677_data = { 744 .mclk_rate = tegra_machine_mclk_rate_256, 745 .card = &snd_soc_tegra_rt5677, 746 .add_common_dapm_widgets = true, 747 .add_common_controls = true, 748 .add_common_snd_ops = true, 749 .add_mic_jack = true, 750 .add_hp_jack = true, 751 }; 752 753 /* RT5640 machine */ 754 755 SND_SOC_DAILINK_DEFS(rt5640_aif1, 756 DAILINK_COMP_ARRAY(COMP_EMPTY()), 757 DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "rt5640-aif1")), 758 DAILINK_COMP_ARRAY(COMP_EMPTY())); 759 760 static struct snd_soc_dai_link tegra_rt5640_dai = { 761 .name = "RT5640", 762 .stream_name = "RT5640 PCM", 763 .init = tegra_asoc_machine_init, 764 .dai_fmt = SND_SOC_DAIFMT_I2S | 765 SND_SOC_DAIFMT_NB_NF | 766 SND_SOC_DAIFMT_CBS_CFS, 767 SND_SOC_DAILINK_REG(rt5640_aif1), 768 }; 769 770 static struct snd_soc_card snd_soc_tegra_rt5640 = { 771 .components = "codec:rt5640", 772 .dai_link = &tegra_rt5640_dai, 773 .num_links = 1, 774 .fully_routed = true, 775 }; 776 777 static const struct tegra_asoc_data tegra_rt5640_data = { 778 .mclk_rate = tegra_machine_mclk_rate_256, 779 .card = &snd_soc_tegra_rt5640, 780 .add_common_dapm_widgets = true, 781 .add_common_controls = true, 782 .add_common_snd_ops = true, 783 .add_hp_jack = true, 784 }; 785 786 /* RT5632 machine */ 787 788 SND_SOC_DAILINK_DEFS(rt5632_hifi, 789 DAILINK_COMP_ARRAY(COMP_EMPTY()), 790 DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "alc5632-hifi")), 791 DAILINK_COMP_ARRAY(COMP_EMPTY())); 792 793 static struct snd_soc_dai_link tegra_rt5632_dai = { 794 .name = "ALC5632", 795 .stream_name = "ALC5632 PCM", 796 .init = tegra_rt5677_init, 797 .dai_fmt = SND_SOC_DAIFMT_I2S | 798 SND_SOC_DAIFMT_NB_NF | 799 SND_SOC_DAIFMT_CBS_CFS, 800 SND_SOC_DAILINK_REG(rt5632_hifi), 801 }; 802 803 static struct snd_soc_card snd_soc_tegra_rt5632 = { 804 .components = "codec:rt5632", 805 .dai_link = &tegra_rt5632_dai, 806 .num_links = 1, 807 .fully_routed = true, 808 }; 809 810 static const struct tegra_asoc_data tegra_rt5632_data = { 811 .mclk_rate = tegra_machine_mclk_rate_512, 812 .card = &snd_soc_tegra_rt5632, 813 .add_common_dapm_widgets = true, 814 .add_common_controls = true, 815 .add_common_snd_ops = true, 816 .add_headset_jack = true, 817 }; 818 819 static const struct of_device_id tegra_machine_of_match[] = { 820 { .compatible = "nvidia,tegra-audio-trimslice", .data = &tegra_trimslice_data }, 821 { .compatible = "nvidia,tegra-audio-max98090", .data = &tegra_max98090_data }, 822 { .compatible = "nvidia,tegra-audio-sgtl5000", .data = &tegra_sgtl5000_data }, 823 { .compatible = "nvidia,tegra-audio-wm9712", .data = &tegra_wm9712_data }, 824 { .compatible = "nvidia,tegra-audio-wm8753", .data = &tegra_wm8753_data }, 825 { .compatible = "nvidia,tegra-audio-rt5677", .data = &tegra_rt5677_data }, 826 { .compatible = "nvidia,tegra-audio-rt5640", .data = &tegra_rt5640_data }, 827 { .compatible = "nvidia,tegra-audio-alc5632", .data = &tegra_rt5632_data }, 828 {}, 829 }; 830 MODULE_DEVICE_TABLE(of, tegra_machine_of_match); 831 832 static struct platform_driver tegra_asoc_machine_driver = { 833 .driver = { 834 .name = "tegra-audio", 835 .of_match_table = tegra_machine_of_match, 836 .pm = &snd_soc_pm_ops, 837 }, 838 .probe = tegra_asoc_machine_probe, 839 }; 840 module_platform_driver(tegra_asoc_machine_driver); 841 842 MODULE_AUTHOR("Anatol Pomozov <anatol@google.com>"); 843 MODULE_AUTHOR("Andrey Danin <danindrey@mail.ru>"); 844 MODULE_AUTHOR("Dmitry Osipenko <digetx@gmail.com>"); 845 MODULE_AUTHOR("Ion Agorria <ion@agorria.com>"); 846 MODULE_AUTHOR("Leon Romanovsky <leon@leon.nu>"); 847 MODULE_AUTHOR("Lucas Stach <dev@lynxeye.de>"); 848 MODULE_AUTHOR("Marc Dietrich <marvin24@gmx.de>"); 849 MODULE_AUTHOR("Marcel Ziswiler <marcel@ziswiler.com>"); 850 MODULE_AUTHOR("Mike Rapoport <mike@compulab.co.il>"); 851 MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>"); 852 MODULE_AUTHOR("Svyatoslav Ryhel <clamor95@gmail.com>"); 853 MODULE_DESCRIPTION("Tegra machine ASoC driver"); 854 MODULE_LICENSE("GPL"); 855