.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * ALSA SoC codec for HDMI encoder drivers |
---|
3 | | - * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com/ |
---|
| 4 | + * Copyright (C) 2015 Texas Instruments Incorporated - https://www.ti.com/ |
---|
4 | 5 | * Author: Jyri Sarha <jsarha@ti.com> |
---|
5 | | - * |
---|
6 | | - * This program is free software; you can redistribute it and/or |
---|
7 | | - * modify it under the terms of the GNU General Public License |
---|
8 | | - * version 2 as published by the Free Software Foundation. |
---|
9 | | - * |
---|
10 | | - * This program is distributed in the hope that it will be useful, but |
---|
11 | | - * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
12 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
13 | | - * General Public License for more details. |
---|
14 | 6 | */ |
---|
15 | 7 | #include <linux/module.h> |
---|
16 | 8 | #include <linux/string.h> |
---|
.. | .. |
---|
30 | 22 | |
---|
31 | 23 | struct hdmi_codec_channel_map_table { |
---|
32 | 24 | unsigned char map; /* ALSA API channel map position */ |
---|
33 | | - unsigned long spk_mask; /* speaker position bit mask */ |
---|
34 | 25 | }; |
---|
35 | 26 | |
---|
36 | 27 | /* |
---|
.. | .. |
---|
279 | 270 | |
---|
280 | 271 | struct hdmi_codec_priv { |
---|
281 | 272 | struct hdmi_codec_pdata hcd; |
---|
282 | | - struct snd_soc_dai_driver *daidrv; |
---|
283 | | - struct hdmi_codec_daifmt daifmt[2]; |
---|
284 | | - struct mutex current_stream_lock; |
---|
285 | | - struct snd_pcm_substream *current_stream; |
---|
286 | 273 | uint8_t eld[MAX_ELD_BYTES]; |
---|
287 | 274 | struct snd_pcm_chmap *chmap_info; |
---|
288 | 275 | unsigned int chmap_idx; |
---|
289 | | - unsigned int mode; |
---|
| 276 | + struct mutex lock; |
---|
| 277 | + bool busy; |
---|
| 278 | + bool eld_bypass; |
---|
290 | 279 | struct snd_soc_jack *jack; |
---|
291 | 280 | unsigned int jack_status; |
---|
| 281 | + u8 iec_status[24]; |
---|
| 282 | + struct snd_pcm_substream *substream; |
---|
292 | 283 | }; |
---|
293 | 284 | |
---|
294 | 285 | static const struct snd_soc_dapm_widget hdmi_widgets[] = { |
---|
.. | .. |
---|
305 | 296 | struct snd_ctl_elem_info *uinfo) |
---|
306 | 297 | { |
---|
307 | 298 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES; |
---|
308 | | - uinfo->count = FIELD_SIZEOF(struct hdmi_codec_priv, eld); |
---|
| 299 | + uinfo->count = sizeof_field(struct hdmi_codec_priv, eld); |
---|
309 | 300 | |
---|
310 | 301 | return 0; |
---|
311 | 302 | } |
---|
.. | .. |
---|
318 | 309 | |
---|
319 | 310 | memcpy(ucontrol->value.bytes.data, hcp->eld, sizeof(hcp->eld)); |
---|
320 | 311 | |
---|
321 | | - return 0; |
---|
322 | | -} |
---|
323 | | - |
---|
324 | | -static int hdmi_audio_mode_info(struct snd_kcontrol *kcontrol, |
---|
325 | | - struct snd_ctl_elem_info *uinfo) |
---|
326 | | -{ |
---|
327 | | - uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
---|
328 | | - uinfo->count = 1; |
---|
329 | | - uinfo->value.integer.min = 0; |
---|
330 | | - uinfo->value.integer.max = HBR; |
---|
331 | | - return 0; |
---|
332 | | -} |
---|
333 | | - |
---|
334 | | -static int hdmi_audio_mode_get(struct snd_kcontrol *kcontrol, |
---|
335 | | - struct snd_ctl_elem_value *ucontrol) |
---|
336 | | -{ |
---|
337 | | - struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); |
---|
338 | | - struct hdmi_codec_priv *hcp = snd_soc_component_get_drvdata(component); |
---|
339 | | - |
---|
340 | | - ucontrol->value.integer.value[0] = hcp->mode; |
---|
341 | | - return 0; |
---|
342 | | -} |
---|
343 | | - |
---|
344 | | -static int hdmi_audio_mode_put(struct snd_kcontrol *kcontrol, |
---|
345 | | - struct snd_ctl_elem_value *ucontrol) |
---|
346 | | -{ |
---|
347 | | - struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); |
---|
348 | | - struct hdmi_codec_priv *hcp = snd_soc_component_get_drvdata(component); |
---|
349 | | - |
---|
350 | | - hcp->mode = ucontrol->value.integer.value[0]; |
---|
351 | 312 | return 0; |
---|
352 | 313 | } |
---|
353 | 314 | |
---|
.. | .. |
---|
391 | 352 | unsigned long spk_mask; |
---|
392 | 353 | const struct hdmi_codec_cea_spk_alloc *cap = hdmi_codec_channel_alloc; |
---|
393 | 354 | |
---|
| 355 | + if (hcp->eld_bypass) |
---|
| 356 | + return 0; |
---|
| 357 | + |
---|
394 | 358 | spk_alloc = drm_eld_get_spk_alloc(hcp->eld); |
---|
395 | 359 | spk_mask = hdmi_codec_spk_mask_from_alloc(spk_alloc); |
---|
396 | 360 | |
---|
.. | .. |
---|
427 | 391 | return 0; |
---|
428 | 392 | } |
---|
429 | 393 | |
---|
430 | | -static int hdmi_codec_new_stream(struct snd_pcm_substream *substream, |
---|
431 | | - struct snd_soc_dai *dai) |
---|
| 394 | +static int hdmi_codec_iec958_info(struct snd_kcontrol *kcontrol, |
---|
| 395 | + struct snd_ctl_elem_info *uinfo) |
---|
432 | 396 | { |
---|
433 | | - struct hdmi_codec_priv *hcp = snd_soc_dai_get_drvdata(dai); |
---|
434 | | - int ret = 0; |
---|
| 397 | + uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; |
---|
| 398 | + uinfo->count = 1; |
---|
| 399 | + return 0; |
---|
| 400 | +} |
---|
435 | 401 | |
---|
436 | | - mutex_lock(&hcp->current_stream_lock); |
---|
437 | | - if (!hcp->current_stream) { |
---|
438 | | - hcp->current_stream = substream; |
---|
439 | | - } else if (hcp->current_stream != substream) { |
---|
440 | | - dev_err(dai->dev, "Only one simultaneous stream supported!\n"); |
---|
441 | | - ret = -EINVAL; |
---|
442 | | - } |
---|
443 | | - mutex_unlock(&hcp->current_stream_lock); |
---|
| 402 | +static int hdmi_codec_iec958_default_get(struct snd_kcontrol *kcontrol, |
---|
| 403 | + struct snd_ctl_elem_value *ucontrol) |
---|
| 404 | +{ |
---|
| 405 | + struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); |
---|
| 406 | + struct hdmi_codec_priv *hcp = snd_soc_component_get_drvdata(component); |
---|
444 | 407 | |
---|
445 | | - return ret; |
---|
| 408 | + memcpy(ucontrol->value.iec958.status, hcp->iec_status, |
---|
| 409 | + sizeof(hcp->iec_status)); |
---|
| 410 | + |
---|
| 411 | + return 0; |
---|
| 412 | +} |
---|
| 413 | + |
---|
| 414 | +static int hdmi_codec_iec958_default_put(struct snd_kcontrol *kcontrol, |
---|
| 415 | + struct snd_ctl_elem_value *ucontrol) |
---|
| 416 | +{ |
---|
| 417 | + struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); |
---|
| 418 | + struct hdmi_codec_priv *hcp = snd_soc_component_get_drvdata(component); |
---|
| 419 | + |
---|
| 420 | + memcpy(hcp->iec_status, ucontrol->value.iec958.status, |
---|
| 421 | + sizeof(hcp->iec_status)); |
---|
| 422 | + |
---|
| 423 | + return 0; |
---|
| 424 | +} |
---|
| 425 | + |
---|
| 426 | +static int hdmi_codec_iec958_mask_get(struct snd_kcontrol *kcontrol, |
---|
| 427 | + struct snd_ctl_elem_value *ucontrol) |
---|
| 428 | +{ |
---|
| 429 | + memset(ucontrol->value.iec958.status, 0xff, |
---|
| 430 | + sizeof_field(struct hdmi_codec_priv, iec_status)); |
---|
| 431 | + |
---|
| 432 | + return 0; |
---|
| 433 | +} |
---|
| 434 | + |
---|
| 435 | +static int hdmi_codec_eld_bypass_get(struct snd_kcontrol *kcontrol, |
---|
| 436 | + struct snd_ctl_elem_value *ucontrol) |
---|
| 437 | +{ |
---|
| 438 | + struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); |
---|
| 439 | + struct hdmi_codec_priv *hcp = snd_soc_component_get_drvdata(component); |
---|
| 440 | + |
---|
| 441 | + ucontrol->value.integer.value[0] = hcp->eld_bypass; |
---|
| 442 | + |
---|
| 443 | + return 0; |
---|
| 444 | +} |
---|
| 445 | + |
---|
| 446 | +static int hdmi_codec_eld_bypass_put(struct snd_kcontrol *kcontrol, |
---|
| 447 | + struct snd_ctl_elem_value *ucontrol) |
---|
| 448 | +{ |
---|
| 449 | + struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); |
---|
| 450 | + struct hdmi_codec_priv *hcp = snd_soc_component_get_drvdata(component); |
---|
| 451 | + |
---|
| 452 | + if (hcp->eld_bypass == ucontrol->value.integer.value[0]) |
---|
| 453 | + return 0; |
---|
| 454 | + |
---|
| 455 | + hcp->eld_bypass = ucontrol->value.integer.value[0]; |
---|
| 456 | + |
---|
| 457 | + return 1; |
---|
446 | 458 | } |
---|
447 | 459 | |
---|
448 | 460 | static int hdmi_codec_startup(struct snd_pcm_substream *substream, |
---|
.. | .. |
---|
452 | 464 | bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK; |
---|
453 | 465 | int ret = 0; |
---|
454 | 466 | |
---|
455 | | - dev_dbg(dai->dev, "%s()\n", __func__); |
---|
456 | | - |
---|
457 | | - ret = hdmi_codec_new_stream(substream, dai); |
---|
458 | | - if (ret) |
---|
459 | | - return ret; |
---|
| 467 | + mutex_lock(&hcp->lock); |
---|
| 468 | + if (hcp->busy) { |
---|
| 469 | + dev_err(dai->dev, "Only one simultaneous stream supported!\n"); |
---|
| 470 | + mutex_unlock(&hcp->lock); |
---|
| 471 | + return -EINVAL; |
---|
| 472 | + } |
---|
460 | 473 | |
---|
461 | 474 | if (hcp->hcd.ops->audio_startup) { |
---|
462 | 475 | ret = hcp->hcd.ops->audio_startup(dai->dev->parent, hcp->hcd.data); |
---|
463 | | - if (ret) { |
---|
464 | | - mutex_lock(&hcp->current_stream_lock); |
---|
465 | | - hcp->current_stream = NULL; |
---|
466 | | - mutex_unlock(&hcp->current_stream_lock); |
---|
467 | | - return ret; |
---|
468 | | - } |
---|
| 476 | + if (ret) |
---|
| 477 | + goto err; |
---|
469 | 478 | } |
---|
470 | 479 | |
---|
471 | | - if (tx && hcp->hcd.ops->get_eld) { |
---|
| 480 | + if (tx && !hcp->eld_bypass && hcp->hcd.ops->get_eld) { |
---|
472 | 481 | ret = hcp->hcd.ops->get_eld(dai->dev->parent, hcp->hcd.data, |
---|
473 | 482 | hcp->eld, sizeof(hcp->eld)); |
---|
| 483 | + if (ret) |
---|
| 484 | + goto err; |
---|
474 | 485 | |
---|
475 | | - if (!ret) { |
---|
476 | | - ret = snd_pcm_hw_constraint_eld(substream->runtime, |
---|
477 | | - hcp->eld); |
---|
478 | | - if (ret) { |
---|
479 | | - mutex_lock(&hcp->current_stream_lock); |
---|
480 | | - hcp->current_stream = NULL; |
---|
481 | | - mutex_unlock(&hcp->current_stream_lock); |
---|
482 | | - return ret; |
---|
483 | | - } |
---|
484 | | - } |
---|
| 486 | + ret = snd_pcm_hw_constraint_eld(substream->runtime, hcp->eld); |
---|
| 487 | + if (ret) |
---|
| 488 | + goto err; |
---|
| 489 | + |
---|
485 | 490 | /* Select chmap supported */ |
---|
486 | 491 | hdmi_codec_eld_chmap(hcp); |
---|
487 | 492 | } |
---|
488 | | - return 0; |
---|
| 493 | + |
---|
| 494 | + hcp->busy = true; |
---|
| 495 | + hcp->substream = substream; |
---|
| 496 | + |
---|
| 497 | +err: |
---|
| 498 | + mutex_unlock(&hcp->lock); |
---|
| 499 | + return ret; |
---|
489 | 500 | } |
---|
490 | 501 | |
---|
491 | 502 | static void hdmi_codec_shutdown(struct snd_pcm_substream *substream, |
---|
.. | .. |
---|
493 | 504 | { |
---|
494 | 505 | struct hdmi_codec_priv *hcp = snd_soc_dai_get_drvdata(dai); |
---|
495 | 506 | |
---|
496 | | - dev_dbg(dai->dev, "%s()\n", __func__); |
---|
497 | | - |
---|
498 | | - WARN_ON(hcp->current_stream != substream); |
---|
499 | | - |
---|
500 | 507 | hcp->chmap_idx = HDMI_CODEC_CHMAP_IDX_UNKNOWN; |
---|
501 | 508 | hcp->hcd.ops->audio_shutdown(dai->dev->parent, hcp->hcd.data); |
---|
502 | 509 | |
---|
503 | | - mutex_lock(&hcp->current_stream_lock); |
---|
504 | | - hcp->current_stream = NULL; |
---|
505 | | - mutex_unlock(&hcp->current_stream_lock); |
---|
| 510 | + mutex_lock(&hcp->lock); |
---|
| 511 | + hcp->substream = NULL; |
---|
| 512 | + hcp->busy = false; |
---|
| 513 | + mutex_unlock(&hcp->lock); |
---|
| 514 | +} |
---|
| 515 | + |
---|
| 516 | +static int hdmi_codec_fill_codec_params(struct snd_soc_dai *dai, |
---|
| 517 | + unsigned int sample_width, |
---|
| 518 | + unsigned int sample_rate, |
---|
| 519 | + unsigned int channels, |
---|
| 520 | + struct hdmi_codec_params *hp) |
---|
| 521 | +{ |
---|
| 522 | + struct hdmi_codec_priv *hcp = snd_soc_dai_get_drvdata(dai); |
---|
| 523 | + int idx; |
---|
| 524 | + |
---|
| 525 | + /* Select a channel allocation that matches with ELD and pcm channels */ |
---|
| 526 | + idx = hdmi_codec_get_ch_alloc_table_idx(hcp, channels); |
---|
| 527 | + if (idx < 0) { |
---|
| 528 | + dev_err(dai->dev, "Not able to map channels to speakers (%d)\n", |
---|
| 529 | + idx); |
---|
| 530 | + hcp->chmap_idx = HDMI_CODEC_CHMAP_IDX_UNKNOWN; |
---|
| 531 | + return idx; |
---|
| 532 | + } |
---|
| 533 | + |
---|
| 534 | + memset(hp, 0, sizeof(*hp)); |
---|
| 535 | + |
---|
| 536 | + hdmi_audio_infoframe_init(&hp->cea); |
---|
| 537 | + hp->cea.channels = channels; |
---|
| 538 | + hp->cea.coding_type = HDMI_AUDIO_CODING_TYPE_STREAM; |
---|
| 539 | + hp->cea.sample_size = HDMI_AUDIO_SAMPLE_SIZE_STREAM; |
---|
| 540 | + hp->cea.sample_frequency = HDMI_AUDIO_SAMPLE_FREQUENCY_STREAM; |
---|
| 541 | + hp->cea.channel_allocation = hdmi_codec_channel_alloc[idx].ca_id; |
---|
| 542 | + |
---|
| 543 | + hp->sample_width = sample_width; |
---|
| 544 | + hp->sample_rate = sample_rate; |
---|
| 545 | + hp->channels = channels; |
---|
| 546 | + |
---|
| 547 | + hcp->chmap_idx = hdmi_codec_channel_alloc[idx].ca_id; |
---|
| 548 | + |
---|
| 549 | + return 0; |
---|
506 | 550 | } |
---|
507 | 551 | |
---|
508 | 552 | static int hdmi_codec_hw_params(struct snd_pcm_substream *substream, |
---|
.. | .. |
---|
510 | 554 | struct snd_soc_dai *dai) |
---|
511 | 555 | { |
---|
512 | 556 | struct hdmi_codec_priv *hcp = snd_soc_dai_get_drvdata(dai); |
---|
| 557 | + struct hdmi_codec_daifmt *cf = dai->playback_dma_data; |
---|
513 | 558 | struct hdmi_codec_params hp = { |
---|
514 | 559 | .iec = { |
---|
515 | 560 | .status = { 0 }, |
---|
.. | .. |
---|
518 | 563 | .dig_subframe = { 0 }, |
---|
519 | 564 | } |
---|
520 | 565 | }; |
---|
521 | | - int ret, idx; |
---|
| 566 | + int ret; |
---|
| 567 | + |
---|
| 568 | + if (!hcp->hcd.ops->hw_params) |
---|
| 569 | + return 0; |
---|
522 | 570 | |
---|
523 | 571 | dev_dbg(dai->dev, "%s() width %d rate %d channels %d\n", __func__, |
---|
524 | 572 | params_width(params), params_rate(params), |
---|
525 | 573 | params_channels(params)); |
---|
526 | 574 | |
---|
527 | | - if (params_width(params) > 24) |
---|
528 | | - params->msbits = 24; |
---|
| 575 | + ret = hdmi_codec_fill_codec_params(dai, |
---|
| 576 | + params_width(params), |
---|
| 577 | + params_rate(params), |
---|
| 578 | + params_channels(params), |
---|
| 579 | + &hp); |
---|
| 580 | + if (ret < 0) |
---|
| 581 | + return ret; |
---|
529 | 582 | |
---|
530 | | - ret = snd_pcm_create_iec958_consumer_hw_params(params, hp.iec.status, |
---|
531 | | - sizeof(hp.iec.status)); |
---|
| 583 | + memcpy(hp.iec.status, hcp->iec_status, sizeof(hp.iec.status)); |
---|
| 584 | + ret = snd_pcm_fill_iec958_consumer_hw_params(params, hp.iec.status, |
---|
| 585 | + sizeof(hp.iec.status)); |
---|
532 | 586 | if (ret < 0) { |
---|
533 | 587 | dev_err(dai->dev, "Creating IEC958 channel status failed %d\n", |
---|
534 | 588 | ret); |
---|
535 | 589 | return ret; |
---|
536 | 590 | } |
---|
537 | 591 | |
---|
538 | | - ret = hdmi_codec_new_stream(substream, dai); |
---|
539 | | - if (ret) |
---|
540 | | - return ret; |
---|
541 | | - |
---|
542 | | - hdmi_audio_infoframe_init(&hp.cea); |
---|
543 | | - hp.cea.channels = params_channels(params); |
---|
544 | | - hp.cea.coding_type = HDMI_AUDIO_CODING_TYPE_STREAM; |
---|
545 | | - hp.cea.sample_size = HDMI_AUDIO_SAMPLE_SIZE_STREAM; |
---|
546 | | - hp.cea.sample_frequency = HDMI_AUDIO_SAMPLE_FREQUENCY_STREAM; |
---|
547 | | - |
---|
548 | | - /* Select a channel allocation that matches with ELD and pcm channels */ |
---|
549 | | - idx = hdmi_codec_get_ch_alloc_table_idx(hcp, hp.cea.channels); |
---|
550 | | - if (idx < 0) { |
---|
551 | | - dev_err(dai->dev, "Not able to map channels to speakers (%d)\n", |
---|
552 | | - idx); |
---|
553 | | - hcp->chmap_idx = HDMI_CODEC_CHMAP_IDX_UNKNOWN; |
---|
554 | | - return idx; |
---|
555 | | - } |
---|
556 | | - hp.cea.channel_allocation = hdmi_codec_channel_alloc[idx].ca_id; |
---|
557 | | - hcp->chmap_idx = hdmi_codec_channel_alloc[idx].ca_id; |
---|
558 | | - |
---|
559 | | - hp.sample_width = params_width(params); |
---|
560 | | - hp.sample_rate = params_rate(params); |
---|
561 | | - hp.channels = params_channels(params); |
---|
562 | | - hp.mode = hcp->mode; |
---|
563 | | - |
---|
| 592 | + cf->bit_fmt = params_format(params); |
---|
564 | 593 | return hcp->hcd.ops->hw_params(dai->dev->parent, hcp->hcd.data, |
---|
565 | | - &hcp->daifmt[dai->id], &hp); |
---|
| 594 | + cf, &hp); |
---|
566 | 595 | } |
---|
567 | 596 | |
---|
568 | | -static int hdmi_codec_set_fmt(struct snd_soc_dai *dai, |
---|
569 | | - unsigned int fmt) |
---|
| 597 | +static int hdmi_codec_prepare(struct snd_pcm_substream *substream, |
---|
| 598 | + struct snd_soc_dai *dai) |
---|
570 | 599 | { |
---|
571 | 600 | struct hdmi_codec_priv *hcp = snd_soc_dai_get_drvdata(dai); |
---|
572 | | - struct hdmi_codec_daifmt cf = { 0 }; |
---|
| 601 | + struct hdmi_codec_daifmt *cf = dai->playback_dma_data; |
---|
| 602 | + struct snd_pcm_runtime *runtime = substream->runtime; |
---|
| 603 | + unsigned int channels = runtime->channels; |
---|
| 604 | + unsigned int width = snd_pcm_format_width(runtime->format); |
---|
| 605 | + unsigned int rate = runtime->rate; |
---|
| 606 | + struct hdmi_codec_params hp; |
---|
| 607 | + int ret; |
---|
573 | 608 | |
---|
574 | | - dev_dbg(dai->dev, "%s()\n", __func__); |
---|
575 | | - |
---|
576 | | - if (dai->id == DAI_ID_SPDIF) |
---|
| 609 | + if (!hcp->hcd.ops->prepare) |
---|
577 | 610 | return 0; |
---|
| 611 | + |
---|
| 612 | + dev_dbg(dai->dev, "%s() width %d rate %d channels %d\n", __func__, |
---|
| 613 | + width, rate, channels); |
---|
| 614 | + |
---|
| 615 | + ret = hdmi_codec_fill_codec_params(dai, width, rate, channels, &hp); |
---|
| 616 | + if (ret < 0) |
---|
| 617 | + return ret; |
---|
| 618 | + |
---|
| 619 | + memcpy(hp.iec.status, hcp->iec_status, sizeof(hp.iec.status)); |
---|
| 620 | + ret = snd_pcm_fill_iec958_consumer(runtime, hp.iec.status, |
---|
| 621 | + sizeof(hp.iec.status)); |
---|
| 622 | + if (ret < 0) { |
---|
| 623 | + dev_err(dai->dev, "Creating IEC958 channel status failed %d\n", |
---|
| 624 | + ret); |
---|
| 625 | + return ret; |
---|
| 626 | + } |
---|
| 627 | + |
---|
| 628 | + cf->bit_fmt = runtime->format; |
---|
| 629 | + return hcp->hcd.ops->prepare(dai->dev->parent, hcp->hcd.data, |
---|
| 630 | + cf, &hp); |
---|
| 631 | +} |
---|
| 632 | + |
---|
| 633 | +static int hdmi_codec_i2s_set_fmt(struct snd_soc_dai *dai, |
---|
| 634 | + unsigned int fmt) |
---|
| 635 | +{ |
---|
| 636 | + struct hdmi_codec_daifmt *cf = dai->playback_dma_data; |
---|
| 637 | + |
---|
| 638 | + /* Reset daifmt */ |
---|
| 639 | + memset(cf, 0, sizeof(*cf)); |
---|
578 | 640 | |
---|
579 | 641 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
---|
580 | 642 | case SND_SOC_DAIFMT_CBM_CFM: |
---|
581 | | - cf.bit_clk_master = 1; |
---|
582 | | - cf.frame_clk_master = 1; |
---|
| 643 | + cf->bit_clk_master = 1; |
---|
| 644 | + cf->frame_clk_master = 1; |
---|
583 | 645 | break; |
---|
584 | 646 | case SND_SOC_DAIFMT_CBS_CFM: |
---|
585 | | - cf.frame_clk_master = 1; |
---|
| 647 | + cf->frame_clk_master = 1; |
---|
586 | 648 | break; |
---|
587 | 649 | case SND_SOC_DAIFMT_CBM_CFS: |
---|
588 | | - cf.bit_clk_master = 1; |
---|
| 650 | + cf->bit_clk_master = 1; |
---|
589 | 651 | break; |
---|
590 | 652 | case SND_SOC_DAIFMT_CBS_CFS: |
---|
591 | 653 | break; |
---|
.. | .. |
---|
597 | 659 | case SND_SOC_DAIFMT_NB_NF: |
---|
598 | 660 | break; |
---|
599 | 661 | case SND_SOC_DAIFMT_NB_IF: |
---|
600 | | - cf.frame_clk_inv = 1; |
---|
| 662 | + cf->frame_clk_inv = 1; |
---|
601 | 663 | break; |
---|
602 | 664 | case SND_SOC_DAIFMT_IB_NF: |
---|
603 | | - cf.bit_clk_inv = 1; |
---|
| 665 | + cf->bit_clk_inv = 1; |
---|
604 | 666 | break; |
---|
605 | 667 | case SND_SOC_DAIFMT_IB_IF: |
---|
606 | | - cf.frame_clk_inv = 1; |
---|
607 | | - cf.bit_clk_inv = 1; |
---|
| 668 | + cf->frame_clk_inv = 1; |
---|
| 669 | + cf->bit_clk_inv = 1; |
---|
608 | 670 | break; |
---|
609 | 671 | } |
---|
610 | 672 | |
---|
611 | 673 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { |
---|
612 | 674 | case SND_SOC_DAIFMT_I2S: |
---|
613 | | - cf.fmt = HDMI_I2S; |
---|
| 675 | + cf->fmt = HDMI_I2S; |
---|
614 | 676 | break; |
---|
615 | 677 | case SND_SOC_DAIFMT_DSP_A: |
---|
616 | | - cf.fmt = HDMI_DSP_A; |
---|
| 678 | + cf->fmt = HDMI_DSP_A; |
---|
617 | 679 | break; |
---|
618 | 680 | case SND_SOC_DAIFMT_DSP_B: |
---|
619 | | - cf.fmt = HDMI_DSP_B; |
---|
| 681 | + cf->fmt = HDMI_DSP_B; |
---|
620 | 682 | break; |
---|
621 | 683 | case SND_SOC_DAIFMT_RIGHT_J: |
---|
622 | | - cf.fmt = HDMI_RIGHT_J; |
---|
| 684 | + cf->fmt = HDMI_RIGHT_J; |
---|
623 | 685 | break; |
---|
624 | 686 | case SND_SOC_DAIFMT_LEFT_J: |
---|
625 | | - cf.fmt = HDMI_LEFT_J; |
---|
| 687 | + cf->fmt = HDMI_LEFT_J; |
---|
626 | 688 | break; |
---|
627 | 689 | case SND_SOC_DAIFMT_AC97: |
---|
628 | | - cf.fmt = HDMI_AC97; |
---|
| 690 | + cf->fmt = HDMI_AC97; |
---|
629 | 691 | break; |
---|
630 | 692 | default: |
---|
631 | 693 | dev_err(dai->dev, "Invalid DAI interface format\n"); |
---|
632 | 694 | return -EINVAL; |
---|
633 | 695 | } |
---|
634 | 696 | |
---|
635 | | - hcp->daifmt[dai->id] = cf; |
---|
636 | | - |
---|
637 | 697 | return 0; |
---|
638 | 698 | } |
---|
639 | 699 | |
---|
640 | | -static int hdmi_codec_digital_mute(struct snd_soc_dai *dai, int mute) |
---|
| 700 | +static int hdmi_codec_mute(struct snd_soc_dai *dai, int mute, int direction) |
---|
641 | 701 | { |
---|
642 | 702 | struct hdmi_codec_priv *hcp = snd_soc_dai_get_drvdata(dai); |
---|
643 | 703 | |
---|
644 | | - dev_dbg(dai->dev, "%s()\n", __func__); |
---|
| 704 | + /* |
---|
| 705 | + * ignore if direction was CAPTURE |
---|
| 706 | + * and it had .no_capture_mute flag |
---|
| 707 | + * see |
---|
| 708 | + * snd_soc_dai_digital_mute() |
---|
| 709 | + */ |
---|
| 710 | + if (hcp->hcd.ops->mute_stream && |
---|
| 711 | + (direction == SNDRV_PCM_STREAM_PLAYBACK || |
---|
| 712 | + !hcp->hcd.ops->no_capture_mute)) |
---|
| 713 | + return hcp->hcd.ops->mute_stream(dai->dev->parent, |
---|
| 714 | + hcp->hcd.data, |
---|
| 715 | + mute, direction); |
---|
645 | 716 | |
---|
646 | | - if (hcp->hcd.ops->digital_mute) |
---|
647 | | - return hcp->hcd.ops->digital_mute(dai->dev->parent, |
---|
648 | | - hcp->hcd.data, mute); |
---|
649 | | - |
---|
650 | | - return 0; |
---|
| 717 | + return -ENOTSUPP; |
---|
651 | 718 | } |
---|
652 | 719 | |
---|
653 | | -static const struct snd_soc_dai_ops hdmi_dai_ops = { |
---|
| 720 | +static const struct snd_soc_dai_ops hdmi_codec_i2s_dai_ops = { |
---|
654 | 721 | .startup = hdmi_codec_startup, |
---|
655 | 722 | .shutdown = hdmi_codec_shutdown, |
---|
656 | 723 | .hw_params = hdmi_codec_hw_params, |
---|
657 | | - .set_fmt = hdmi_codec_set_fmt, |
---|
658 | | - .digital_mute = hdmi_codec_digital_mute, |
---|
| 724 | + .prepare = hdmi_codec_prepare, |
---|
| 725 | + .set_fmt = hdmi_codec_i2s_set_fmt, |
---|
| 726 | + .mute_stream = hdmi_codec_mute, |
---|
659 | 727 | }; |
---|
660 | 728 | |
---|
| 729 | +static const struct snd_soc_dai_ops hdmi_codec_spdif_dai_ops = { |
---|
| 730 | + .startup = hdmi_codec_startup, |
---|
| 731 | + .shutdown = hdmi_codec_shutdown, |
---|
| 732 | + .hw_params = hdmi_codec_hw_params, |
---|
| 733 | + .mute_stream = hdmi_codec_mute, |
---|
| 734 | +}; |
---|
661 | 735 | |
---|
662 | 736 | #define HDMI_RATES (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 |\ |
---|
663 | 737 | SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 |\ |
---|
.. | .. |
---|
681 | 755 | SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S20_3BE |\ |
---|
682 | 756 | SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S24_3BE |\ |
---|
683 | 757 | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE |\ |
---|
684 | | - SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE) |
---|
| 758 | + SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE |\ |
---|
| 759 | + SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE) |
---|
| 760 | + |
---|
| 761 | +static struct snd_kcontrol_new hdmi_codec_controls[] = { |
---|
| 762 | + { |
---|
| 763 | + .access = SNDRV_CTL_ELEM_ACCESS_READ, |
---|
| 764 | + .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
---|
| 765 | + .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, MASK), |
---|
| 766 | + .info = hdmi_codec_iec958_info, |
---|
| 767 | + .get = hdmi_codec_iec958_mask_get, |
---|
| 768 | + }, |
---|
| 769 | + { |
---|
| 770 | + .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
---|
| 771 | + .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT), |
---|
| 772 | + .info = hdmi_codec_iec958_info, |
---|
| 773 | + .get = hdmi_codec_iec958_default_get, |
---|
| 774 | + .put = hdmi_codec_iec958_default_put, |
---|
| 775 | + }, |
---|
| 776 | + { |
---|
| 777 | + .access = (SNDRV_CTL_ELEM_ACCESS_READ | |
---|
| 778 | + SNDRV_CTL_ELEM_ACCESS_VOLATILE), |
---|
| 779 | + .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
---|
| 780 | + .name = "ELD", |
---|
| 781 | + .info = hdmi_eld_ctl_info, |
---|
| 782 | + .get = hdmi_eld_ctl_get, |
---|
| 783 | + }, |
---|
| 784 | + SOC_SINGLE_BOOL_EXT("ELD Bypass Switch", 0, |
---|
| 785 | + hdmi_codec_eld_bypass_get, hdmi_codec_eld_bypass_put), |
---|
| 786 | +}; |
---|
685 | 787 | |
---|
686 | 788 | static int hdmi_codec_pcm_new(struct snd_soc_pcm_runtime *rtd, |
---|
687 | 789 | struct snd_soc_dai *dai) |
---|
688 | 790 | { |
---|
689 | 791 | struct snd_soc_dai_driver *drv = dai->driver; |
---|
690 | 792 | struct hdmi_codec_priv *hcp = snd_soc_dai_get_drvdata(dai); |
---|
691 | | - struct snd_kcontrol *kctl; |
---|
692 | | - struct snd_kcontrol_new hdmi_eld_ctl = { |
---|
693 | | - .access = SNDRV_CTL_ELEM_ACCESS_READ | |
---|
694 | | - SNDRV_CTL_ELEM_ACCESS_VOLATILE, |
---|
695 | | - .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
---|
696 | | - .name = "ELD", |
---|
697 | | - .info = hdmi_eld_ctl_info, |
---|
698 | | - .get = hdmi_eld_ctl_get, |
---|
699 | | - .device = rtd->pcm->device, |
---|
700 | | - }; |
---|
701 | | - struct snd_kcontrol_new hdmi_mode_ctl = { |
---|
702 | | - .access = SNDRV_CTL_ELEM_ACCESS_READ | |
---|
703 | | - SNDRV_CTL_ELEM_ACCESS_WRITE | |
---|
704 | | - SNDRV_CTL_ELEM_ACCESS_VOLATILE, |
---|
705 | | - .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
---|
706 | | - .name = "AUDIO MODE", |
---|
707 | | - .info = hdmi_audio_mode_info, |
---|
708 | | - .get = hdmi_audio_mode_get, |
---|
709 | | - .put = hdmi_audio_mode_put, |
---|
710 | | - }; |
---|
| 793 | + unsigned int i; |
---|
711 | 794 | int ret; |
---|
712 | | - |
---|
713 | | - dev_dbg(dai->dev, "%s()\n", __func__); |
---|
714 | 795 | |
---|
715 | 796 | ret = snd_pcm_add_chmap_ctls(rtd->pcm, SNDRV_PCM_STREAM_PLAYBACK, |
---|
716 | 797 | NULL, drv->playback.channels_max, 0, |
---|
.. | .. |
---|
726 | 807 | hcp->chmap_info->chmap = hdmi_codec_stereo_chmaps; |
---|
727 | 808 | hcp->chmap_idx = HDMI_CODEC_CHMAP_IDX_UNKNOWN; |
---|
728 | 809 | |
---|
729 | | - /* add ELD ctl with the device number corresponding to the PCM stream */ |
---|
730 | | - kctl = snd_ctl_new1(&hdmi_eld_ctl, dai->component); |
---|
731 | | - if (!kctl) |
---|
732 | | - return -ENOMEM; |
---|
| 810 | + for (i = 0; i < ARRAY_SIZE(hdmi_codec_controls); i++) { |
---|
| 811 | + struct snd_kcontrol *kctl; |
---|
733 | 812 | |
---|
734 | | - ret = snd_ctl_add(rtd->card->snd_card, kctl); |
---|
735 | | - if (ret < 0) |
---|
736 | | - return ret; |
---|
| 813 | + /* add ELD ctl with the device number corresponding to the PCM stream */ |
---|
| 814 | + kctl = snd_ctl_new1(&hdmi_codec_controls[i], dai->component); |
---|
| 815 | + if (!kctl) |
---|
| 816 | + return -ENOMEM; |
---|
737 | 817 | |
---|
738 | | - /* add MODE ctl with the device number corresponding to the PCM stream */ |
---|
739 | | - kctl = snd_ctl_new1(&hdmi_mode_ctl, dai->component); |
---|
740 | | - if (!kctl) |
---|
741 | | - return -ENOMEM; |
---|
| 818 | + kctl->id.device = rtd->pcm->device; |
---|
| 819 | + ret = snd_ctl_add(rtd->card->snd_card, kctl); |
---|
| 820 | + if (ret < 0) |
---|
| 821 | + return ret; |
---|
| 822 | + } |
---|
742 | 823 | |
---|
743 | | - return snd_ctl_add(rtd->card->snd_card, kctl); |
---|
| 824 | + return 0; |
---|
744 | 825 | } |
---|
745 | 826 | |
---|
746 | 827 | static int hdmi_dai_probe(struct snd_soc_dai *dai) |
---|
747 | 828 | { |
---|
748 | 829 | struct snd_soc_dapm_context *dapm; |
---|
| 830 | + struct hdmi_codec_daifmt *daifmt; |
---|
749 | 831 | struct snd_soc_dapm_route route[] = { |
---|
750 | 832 | { |
---|
751 | 833 | .sink = "TX", |
---|
.. | .. |
---|
756 | 838 | .source = "RX", |
---|
757 | 839 | }, |
---|
758 | 840 | }; |
---|
| 841 | + int ret; |
---|
759 | 842 | |
---|
760 | 843 | dapm = snd_soc_component_get_dapm(dai->component); |
---|
761 | | - return snd_soc_dapm_add_routes(dapm, route, 2); |
---|
| 844 | + ret = snd_soc_dapm_add_routes(dapm, route, 2); |
---|
| 845 | + if (ret) |
---|
| 846 | + return ret; |
---|
| 847 | + |
---|
| 848 | + daifmt = kzalloc(sizeof(*daifmt), GFP_KERNEL); |
---|
| 849 | + if (!daifmt) |
---|
| 850 | + return -ENOMEM; |
---|
| 851 | + |
---|
| 852 | + dai->playback_dma_data = daifmt; |
---|
| 853 | + return 0; |
---|
762 | 854 | } |
---|
763 | 855 | |
---|
764 | 856 | static void hdmi_codec_jack_report(struct hdmi_codec_priv *hcp, |
---|
.. | .. |
---|
774 | 866 | { |
---|
775 | 867 | struct hdmi_codec_priv *hcp = dev_get_drvdata(dev); |
---|
776 | 868 | |
---|
777 | | - if (plugged) |
---|
| 869 | + if (plugged) { |
---|
| 870 | + if (!hcp->eld_bypass && hcp->hcd.ops->get_eld) { |
---|
| 871 | + hcp->hcd.ops->get_eld(dev->parent, hcp->hcd.data, |
---|
| 872 | + hcp->eld, sizeof(hcp->eld)); |
---|
| 873 | + } |
---|
778 | 874 | hdmi_codec_jack_report(hcp, SND_JACK_LINEOUT); |
---|
779 | | - else |
---|
| 875 | + } else { |
---|
780 | 876 | hdmi_codec_jack_report(hcp, 0); |
---|
| 877 | + memset(hcp->eld, 0, sizeof(hcp->eld)); |
---|
| 878 | + } |
---|
| 879 | + |
---|
| 880 | + mutex_lock(&hcp->lock); |
---|
| 881 | + if (hcp->substream) { |
---|
| 882 | + /* |
---|
| 883 | + * Workaround for HDMIIN and HDMIOUT plug-{in,out} when streaming. |
---|
| 884 | + * |
---|
| 885 | + * Actually, we should do stop stream both for HDMI_{OUT,IN} on |
---|
| 886 | + * plug-{out,in} event. but for better experience and depop stream, |
---|
| 887 | + * we optimize as follows: |
---|
| 888 | + * |
---|
| 889 | + * a) Do stop stream for HDMIIN on plug-out when streaming. |
---|
| 890 | + * because HDMIIN work as SLAVE mode, CLK lost after HDMI cable |
---|
| 891 | + * plugged out which will make stream stuck until ALSA timeout(10s). |
---|
| 892 | + * so, for better experience, we should stop stream at the moment. |
---|
| 893 | + * |
---|
| 894 | + * b) Do stop stream for HDMIOUT on plug-in when streaming. |
---|
| 895 | + * because HDMIOUT work as MASTER mode, there is no clk-issue like |
---|
| 896 | + * HDMIIN, but, on HDR situation, HDMI will be reconfigured which |
---|
| 897 | + * make HDMI audio configure lost, especially for NLPCM/HBR bitstream |
---|
| 898 | + * which require IEC937 packet alignment, so, for this situation, |
---|
| 899 | + * we stop stream to notify user to re-open and configure sound card |
---|
| 900 | + * and then go on streaming. |
---|
| 901 | + */ |
---|
| 902 | + int stream = hcp->substream->stream; |
---|
| 903 | + |
---|
| 904 | + if (stream == SNDRV_PCM_STREAM_PLAYBACK && plugged) |
---|
| 905 | + snd_pcm_stop(hcp->substream, SNDRV_PCM_STATE_SETUP); |
---|
| 906 | + else if (stream == SNDRV_PCM_STREAM_CAPTURE && !plugged) |
---|
| 907 | + snd_pcm_stop(hcp->substream, SNDRV_PCM_STATE_DISCONNECTED); |
---|
| 908 | + |
---|
| 909 | + dev_dbg(dev, "stream[%d]: %s\n", stream, plugged ? "plug in" : "plug out"); |
---|
| 910 | + } |
---|
| 911 | + mutex_unlock(&hcp->lock); |
---|
781 | 912 | } |
---|
782 | 913 | |
---|
783 | 914 | static int hdmi_codec_set_jack(struct snd_soc_component *component, |
---|
.. | .. |
---|
785 | 916 | void *data) |
---|
786 | 917 | { |
---|
787 | 918 | struct hdmi_codec_priv *hcp = snd_soc_component_get_drvdata(component); |
---|
788 | | - int ret = -EOPNOTSUPP; |
---|
| 919 | + int ret = -ENOTSUPP; |
---|
789 | 920 | |
---|
790 | 921 | if (hcp->hcd.ops->hook_plugged_cb) { |
---|
791 | 922 | hcp->jack = jack; |
---|
.. | .. |
---|
799 | 930 | return ret; |
---|
800 | 931 | } |
---|
801 | 932 | |
---|
| 933 | +static int hdmi_dai_spdif_probe(struct snd_soc_dai *dai) |
---|
| 934 | +{ |
---|
| 935 | + struct hdmi_codec_daifmt *cf; |
---|
| 936 | + int ret; |
---|
| 937 | + |
---|
| 938 | + ret = hdmi_dai_probe(dai); |
---|
| 939 | + if (ret) |
---|
| 940 | + return ret; |
---|
| 941 | + |
---|
| 942 | + cf = dai->playback_dma_data; |
---|
| 943 | + cf->fmt = HDMI_SPDIF; |
---|
| 944 | + |
---|
| 945 | + return 0; |
---|
| 946 | +} |
---|
| 947 | + |
---|
| 948 | +static int hdmi_codec_dai_remove(struct snd_soc_dai *dai) |
---|
| 949 | +{ |
---|
| 950 | + kfree(dai->playback_dma_data); |
---|
| 951 | + return 0; |
---|
| 952 | +} |
---|
| 953 | + |
---|
802 | 954 | static const struct snd_soc_dai_driver hdmi_i2s_dai = { |
---|
803 | 955 | .name = "i2s-hifi", |
---|
804 | 956 | .id = DAI_ID_I2S, |
---|
805 | 957 | .probe = hdmi_dai_probe, |
---|
| 958 | + .remove = hdmi_codec_dai_remove, |
---|
806 | 959 | .playback = { |
---|
807 | 960 | .stream_name = "I2S Playback", |
---|
808 | 961 | .channels_min = 2, |
---|
.. | .. |
---|
819 | 972 | .formats = I2S_FORMATS, |
---|
820 | 973 | .sig_bits = 24, |
---|
821 | 974 | }, |
---|
822 | | - .ops = &hdmi_dai_ops, |
---|
| 975 | + .ops = &hdmi_codec_i2s_dai_ops, |
---|
823 | 976 | .pcm_new = hdmi_codec_pcm_new, |
---|
824 | 977 | }; |
---|
825 | 978 | |
---|
826 | 979 | static const struct snd_soc_dai_driver hdmi_spdif_dai = { |
---|
827 | 980 | .name = "spdif-hifi", |
---|
828 | 981 | .id = DAI_ID_SPDIF, |
---|
829 | | - .probe = hdmi_dai_probe, |
---|
| 982 | + .probe = hdmi_dai_spdif_probe, |
---|
| 983 | + .remove = hdmi_codec_dai_remove, |
---|
830 | 984 | .playback = { |
---|
831 | 985 | .stream_name = "SPDIF Playback", |
---|
832 | 986 | .channels_min = 2, |
---|
.. | .. |
---|
841 | 995 | .rates = HDMI_RATES, |
---|
842 | 996 | .formats = SPDIF_FORMATS, |
---|
843 | 997 | }, |
---|
844 | | - .ops = &hdmi_dai_ops, |
---|
| 998 | + .ops = &hdmi_codec_spdif_dai_ops, |
---|
845 | 999 | .pcm_new = hdmi_codec_pcm_new, |
---|
846 | 1000 | }; |
---|
847 | 1001 | |
---|
.. | .. |
---|
857 | 1011 | return ret; |
---|
858 | 1012 | } |
---|
859 | 1013 | |
---|
| 1014 | +static void hdmi_remove(struct snd_soc_component *component) |
---|
| 1015 | +{ |
---|
| 1016 | + struct hdmi_codec_priv *hcp = snd_soc_component_get_drvdata(component); |
---|
| 1017 | + |
---|
| 1018 | + if (hcp->hcd.ops->hook_plugged_cb) |
---|
| 1019 | + hcp->hcd.ops->hook_plugged_cb(component->dev->parent, |
---|
| 1020 | + hcp->hcd.data, NULL, NULL); |
---|
| 1021 | +} |
---|
| 1022 | + |
---|
860 | 1023 | static const struct snd_soc_component_driver hdmi_driver = { |
---|
| 1024 | + .remove = hdmi_remove, |
---|
861 | 1025 | .dapm_widgets = hdmi_widgets, |
---|
862 | 1026 | .num_dapm_widgets = ARRAY_SIZE(hdmi_widgets), |
---|
863 | 1027 | .of_xlate_dai_id = hdmi_of_xlate_dai_id, |
---|
.. | .. |
---|
871 | 1035 | static int hdmi_codec_probe(struct platform_device *pdev) |
---|
872 | 1036 | { |
---|
873 | 1037 | struct hdmi_codec_pdata *hcd = pdev->dev.platform_data; |
---|
| 1038 | + struct snd_soc_dai_driver *daidrv; |
---|
874 | 1039 | struct device *dev = &pdev->dev; |
---|
875 | 1040 | struct hdmi_codec_priv *hcp; |
---|
876 | 1041 | int dai_count, i = 0; |
---|
877 | 1042 | int ret; |
---|
878 | 1043 | |
---|
879 | | - dev_dbg(dev, "%s()\n", __func__); |
---|
880 | | - |
---|
881 | 1044 | if (!hcd) { |
---|
882 | | - dev_err(dev, "%s: No plalform data\n", __func__); |
---|
| 1045 | + dev_err(dev, "%s: No platform data\n", __func__); |
---|
883 | 1046 | return -EINVAL; |
---|
884 | 1047 | } |
---|
885 | 1048 | |
---|
886 | 1049 | dai_count = hcd->i2s + hcd->spdif; |
---|
887 | | - if (dai_count < 1 || !hcd->ops || !hcd->ops->hw_params || |
---|
| 1050 | + if (dai_count < 1 || !hcd->ops || |
---|
| 1051 | + (!hcd->ops->hw_params && !hcd->ops->prepare) || |
---|
888 | 1052 | !hcd->ops->audio_shutdown) { |
---|
889 | 1053 | dev_err(dev, "%s: Invalid parameters\n", __func__); |
---|
890 | 1054 | return -EINVAL; |
---|
.. | .. |
---|
895 | 1059 | return -ENOMEM; |
---|
896 | 1060 | |
---|
897 | 1061 | hcp->hcd = *hcd; |
---|
898 | | - mutex_init(&hcp->current_stream_lock); |
---|
| 1062 | + mutex_init(&hcp->lock); |
---|
899 | 1063 | |
---|
900 | | - hcp->daidrv = devm_kcalloc(dev, dai_count, sizeof(*hcp->daidrv), |
---|
901 | | - GFP_KERNEL); |
---|
902 | | - if (!hcp->daidrv) |
---|
| 1064 | + ret = snd_pcm_create_iec958_consumer_default(hcp->iec_status, |
---|
| 1065 | + sizeof(hcp->iec_status)); |
---|
| 1066 | + if (ret < 0) |
---|
| 1067 | + return ret; |
---|
| 1068 | + |
---|
| 1069 | + daidrv = devm_kcalloc(dev, dai_count, sizeof(*daidrv), GFP_KERNEL); |
---|
| 1070 | + if (!daidrv) |
---|
903 | 1071 | return -ENOMEM; |
---|
904 | 1072 | |
---|
905 | 1073 | if (hcd->i2s) { |
---|
906 | | - hcp->daidrv[i] = hdmi_i2s_dai; |
---|
907 | | - hcp->daidrv[i].playback.channels_max = |
---|
908 | | - hcd->max_i2s_channels; |
---|
| 1074 | + daidrv[i] = hdmi_i2s_dai; |
---|
| 1075 | + daidrv[i].playback.channels_max = hcd->max_i2s_channels; |
---|
909 | 1076 | i++; |
---|
910 | 1077 | } |
---|
911 | 1078 | |
---|
912 | | - if (hcd->spdif) { |
---|
913 | | - hcp->daidrv[i] = hdmi_spdif_dai; |
---|
914 | | - hcp->daifmt[DAI_ID_SPDIF].fmt = HDMI_SPDIF; |
---|
915 | | - } |
---|
| 1079 | + if (hcd->spdif) |
---|
| 1080 | + daidrv[i] = hdmi_spdif_dai; |
---|
916 | 1081 | |
---|
917 | 1082 | dev_set_drvdata(dev, hcp); |
---|
918 | 1083 | |
---|
919 | | - ret = devm_snd_soc_register_component(dev, &hdmi_driver, hcp->daidrv, |
---|
920 | | - dai_count); |
---|
| 1084 | + ret = devm_snd_soc_register_component(dev, &hdmi_driver, daidrv, |
---|
| 1085 | + dai_count); |
---|
921 | 1086 | if (ret) { |
---|
922 | 1087 | dev_err(dev, "%s: snd_soc_register_component() failed (%d)\n", |
---|
923 | 1088 | __func__, ret); |
---|