hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/sound/soc/codecs/hdmi-codec.c
....@@ -1,16 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * 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/
45 * 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.
146 */
157 #include <linux/module.h>
168 #include <linux/string.h>
....@@ -30,7 +22,6 @@
3022
3123 struct hdmi_codec_channel_map_table {
3224 unsigned char map; /* ALSA API channel map position */
33
- unsigned long spk_mask; /* speaker position bit mask */
3425 };
3526
3627 /*
....@@ -279,16 +270,16 @@
279270
280271 struct hdmi_codec_priv {
281272 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;
286273 uint8_t eld[MAX_ELD_BYTES];
287274 struct snd_pcm_chmap *chmap_info;
288275 unsigned int chmap_idx;
289
- unsigned int mode;
276
+ struct mutex lock;
277
+ bool busy;
278
+ bool eld_bypass;
290279 struct snd_soc_jack *jack;
291280 unsigned int jack_status;
281
+ u8 iec_status[24];
282
+ struct snd_pcm_substream *substream;
292283 };
293284
294285 static const struct snd_soc_dapm_widget hdmi_widgets[] = {
....@@ -305,7 +296,7 @@
305296 struct snd_ctl_elem_info *uinfo)
306297 {
307298 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);
309300
310301 return 0;
311302 }
....@@ -318,36 +309,6 @@
318309
319310 memcpy(ucontrol->value.bytes.data, hcp->eld, sizeof(hcp->eld));
320311
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];
351312 return 0;
352313 }
353314
....@@ -391,6 +352,9 @@
391352 unsigned long spk_mask;
392353 const struct hdmi_codec_cea_spk_alloc *cap = hdmi_codec_channel_alloc;
393354
355
+ if (hcp->eld_bypass)
356
+ return 0;
357
+
394358 spk_alloc = drm_eld_get_spk_alloc(hcp->eld);
395359 spk_mask = hdmi_codec_spk_mask_from_alloc(spk_alloc);
396360
....@@ -427,22 +391,70 @@
427391 return 0;
428392 }
429393
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)
432396 {
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
+}
435401
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);
444407
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;
446458 }
447459
448460 static int hdmi_codec_startup(struct snd_pcm_substream *substream,
....@@ -452,40 +464,39 @@
452464 bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
453465 int ret = 0;
454466
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
+ }
460473
461474 if (hcp->hcd.ops->audio_startup) {
462475 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;
469478 }
470479
471
- if (tx && hcp->hcd.ops->get_eld) {
480
+ if (tx && !hcp->eld_bypass && hcp->hcd.ops->get_eld) {
472481 ret = hcp->hcd.ops->get_eld(dai->dev->parent, hcp->hcd.data,
473482 hcp->eld, sizeof(hcp->eld));
483
+ if (ret)
484
+ goto err;
474485
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
+
485490 /* Select chmap supported */
486491 hdmi_codec_eld_chmap(hcp);
487492 }
488
- return 0;
493
+
494
+ hcp->busy = true;
495
+ hcp->substream = substream;
496
+
497
+err:
498
+ mutex_unlock(&hcp->lock);
499
+ return ret;
489500 }
490501
491502 static void hdmi_codec_shutdown(struct snd_pcm_substream *substream,
....@@ -493,16 +504,49 @@
493504 {
494505 struct hdmi_codec_priv *hcp = snd_soc_dai_get_drvdata(dai);
495506
496
- dev_dbg(dai->dev, "%s()\n", __func__);
497
-
498
- WARN_ON(hcp->current_stream != substream);
499
-
500507 hcp->chmap_idx = HDMI_CODEC_CHMAP_IDX_UNKNOWN;
501508 hcp->hcd.ops->audio_shutdown(dai->dev->parent, hcp->hcd.data);
502509
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;
506550 }
507551
508552 static int hdmi_codec_hw_params(struct snd_pcm_substream *substream,
....@@ -510,6 +554,7 @@
510554 struct snd_soc_dai *dai)
511555 {
512556 struct hdmi_codec_priv *hcp = snd_soc_dai_get_drvdata(dai);
557
+ struct hdmi_codec_daifmt *cf = dai->playback_dma_data;
513558 struct hdmi_codec_params hp = {
514559 .iec = {
515560 .status = { 0 },
....@@ -518,74 +563,91 @@
518563 .dig_subframe = { 0 },
519564 }
520565 };
521
- int ret, idx;
566
+ int ret;
567
+
568
+ if (!hcp->hcd.ops->hw_params)
569
+ return 0;
522570
523571 dev_dbg(dai->dev, "%s() width %d rate %d channels %d\n", __func__,
524572 params_width(params), params_rate(params),
525573 params_channels(params));
526574
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;
529582
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));
532586 if (ret < 0) {
533587 dev_err(dai->dev, "Creating IEC958 channel status failed %d\n",
534588 ret);
535589 return ret;
536590 }
537591
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);
564593 return hcp->hcd.ops->hw_params(dai->dev->parent, hcp->hcd.data,
565
- &hcp->daifmt[dai->id], &hp);
594
+ cf, &hp);
566595 }
567596
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)
570599 {
571600 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;
573608
574
- dev_dbg(dai->dev, "%s()\n", __func__);
575
-
576
- if (dai->id == DAI_ID_SPDIF)
609
+ if (!hcp->hcd.ops->prepare)
577610 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));
578640
579641 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
580642 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;
583645 break;
584646 case SND_SOC_DAIFMT_CBS_CFM:
585
- cf.frame_clk_master = 1;
647
+ cf->frame_clk_master = 1;
586648 break;
587649 case SND_SOC_DAIFMT_CBM_CFS:
588
- cf.bit_clk_master = 1;
650
+ cf->bit_clk_master = 1;
589651 break;
590652 case SND_SOC_DAIFMT_CBS_CFS:
591653 break;
....@@ -597,67 +659,79 @@
597659 case SND_SOC_DAIFMT_NB_NF:
598660 break;
599661 case SND_SOC_DAIFMT_NB_IF:
600
- cf.frame_clk_inv = 1;
662
+ cf->frame_clk_inv = 1;
601663 break;
602664 case SND_SOC_DAIFMT_IB_NF:
603
- cf.bit_clk_inv = 1;
665
+ cf->bit_clk_inv = 1;
604666 break;
605667 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;
608670 break;
609671 }
610672
611673 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
612674 case SND_SOC_DAIFMT_I2S:
613
- cf.fmt = HDMI_I2S;
675
+ cf->fmt = HDMI_I2S;
614676 break;
615677 case SND_SOC_DAIFMT_DSP_A:
616
- cf.fmt = HDMI_DSP_A;
678
+ cf->fmt = HDMI_DSP_A;
617679 break;
618680 case SND_SOC_DAIFMT_DSP_B:
619
- cf.fmt = HDMI_DSP_B;
681
+ cf->fmt = HDMI_DSP_B;
620682 break;
621683 case SND_SOC_DAIFMT_RIGHT_J:
622
- cf.fmt = HDMI_RIGHT_J;
684
+ cf->fmt = HDMI_RIGHT_J;
623685 break;
624686 case SND_SOC_DAIFMT_LEFT_J:
625
- cf.fmt = HDMI_LEFT_J;
687
+ cf->fmt = HDMI_LEFT_J;
626688 break;
627689 case SND_SOC_DAIFMT_AC97:
628
- cf.fmt = HDMI_AC97;
690
+ cf->fmt = HDMI_AC97;
629691 break;
630692 default:
631693 dev_err(dai->dev, "Invalid DAI interface format\n");
632694 return -EINVAL;
633695 }
634696
635
- hcp->daifmt[dai->id] = cf;
636
-
637697 return 0;
638698 }
639699
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)
641701 {
642702 struct hdmi_codec_priv *hcp = snd_soc_dai_get_drvdata(dai);
643703
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);
645716
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;
651718 }
652719
653
-static const struct snd_soc_dai_ops hdmi_dai_ops = {
720
+static const struct snd_soc_dai_ops hdmi_codec_i2s_dai_ops = {
654721 .startup = hdmi_codec_startup,
655722 .shutdown = hdmi_codec_shutdown,
656723 .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,
659727 };
660728
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
+};
661735
662736 #define HDMI_RATES (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 |\
663737 SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 |\
....@@ -681,36 +755,43 @@
681755 SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S20_3BE |\
682756 SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S24_3BE |\
683757 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
+};
685787
686788 static int hdmi_codec_pcm_new(struct snd_soc_pcm_runtime *rtd,
687789 struct snd_soc_dai *dai)
688790 {
689791 struct snd_soc_dai_driver *drv = dai->driver;
690792 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;
711794 int ret;
712
-
713
- dev_dbg(dai->dev, "%s()\n", __func__);
714795
715796 ret = snd_pcm_add_chmap_ctls(rtd->pcm, SNDRV_PCM_STREAM_PLAYBACK,
716797 NULL, drv->playback.channels_max, 0,
....@@ -726,26 +807,27 @@
726807 hcp->chmap_info->chmap = hdmi_codec_stereo_chmaps;
727808 hcp->chmap_idx = HDMI_CODEC_CHMAP_IDX_UNKNOWN;
728809
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;
733812
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;
737817
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
+ }
742823
743
- return snd_ctl_add(rtd->card->snd_card, kctl);
824
+ return 0;
744825 }
745826
746827 static int hdmi_dai_probe(struct snd_soc_dai *dai)
747828 {
748829 struct snd_soc_dapm_context *dapm;
830
+ struct hdmi_codec_daifmt *daifmt;
749831 struct snd_soc_dapm_route route[] = {
750832 {
751833 .sink = "TX",
....@@ -756,9 +838,19 @@
756838 .source = "RX",
757839 },
758840 };
841
+ int ret;
759842
760843 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;
762854 }
763855
764856 static void hdmi_codec_jack_report(struct hdmi_codec_priv *hcp,
....@@ -774,10 +866,49 @@
774866 {
775867 struct hdmi_codec_priv *hcp = dev_get_drvdata(dev);
776868
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
+ }
778874 hdmi_codec_jack_report(hcp, SND_JACK_LINEOUT);
779
- else
875
+ } else {
780876 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);
781912 }
782913
783914 static int hdmi_codec_set_jack(struct snd_soc_component *component,
....@@ -785,7 +916,7 @@
785916 void *data)
786917 {
787918 struct hdmi_codec_priv *hcp = snd_soc_component_get_drvdata(component);
788
- int ret = -EOPNOTSUPP;
919
+ int ret = -ENOTSUPP;
789920
790921 if (hcp->hcd.ops->hook_plugged_cb) {
791922 hcp->jack = jack;
....@@ -799,10 +930,32 @@
799930 return ret;
800931 }
801932
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
+
802954 static const struct snd_soc_dai_driver hdmi_i2s_dai = {
803955 .name = "i2s-hifi",
804956 .id = DAI_ID_I2S,
805957 .probe = hdmi_dai_probe,
958
+ .remove = hdmi_codec_dai_remove,
806959 .playback = {
807960 .stream_name = "I2S Playback",
808961 .channels_min = 2,
....@@ -819,14 +972,15 @@
819972 .formats = I2S_FORMATS,
820973 .sig_bits = 24,
821974 },
822
- .ops = &hdmi_dai_ops,
975
+ .ops = &hdmi_codec_i2s_dai_ops,
823976 .pcm_new = hdmi_codec_pcm_new,
824977 };
825978
826979 static const struct snd_soc_dai_driver hdmi_spdif_dai = {
827980 .name = "spdif-hifi",
828981 .id = DAI_ID_SPDIF,
829
- .probe = hdmi_dai_probe,
982
+ .probe = hdmi_dai_spdif_probe,
983
+ .remove = hdmi_codec_dai_remove,
830984 .playback = {
831985 .stream_name = "SPDIF Playback",
832986 .channels_min = 2,
....@@ -841,7 +995,7 @@
841995 .rates = HDMI_RATES,
842996 .formats = SPDIF_FORMATS,
843997 },
844
- .ops = &hdmi_dai_ops,
998
+ .ops = &hdmi_codec_spdif_dai_ops,
845999 .pcm_new = hdmi_codec_pcm_new,
8461000 };
8471001
....@@ -857,7 +1011,17 @@
8571011 return ret;
8581012 }
8591013
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
+
8601023 static const struct snd_soc_component_driver hdmi_driver = {
1024
+ .remove = hdmi_remove,
8611025 .dapm_widgets = hdmi_widgets,
8621026 .num_dapm_widgets = ARRAY_SIZE(hdmi_widgets),
8631027 .of_xlate_dai_id = hdmi_of_xlate_dai_id,
....@@ -871,20 +1035,20 @@
8711035 static int hdmi_codec_probe(struct platform_device *pdev)
8721036 {
8731037 struct hdmi_codec_pdata *hcd = pdev->dev.platform_data;
1038
+ struct snd_soc_dai_driver *daidrv;
8741039 struct device *dev = &pdev->dev;
8751040 struct hdmi_codec_priv *hcp;
8761041 int dai_count, i = 0;
8771042 int ret;
8781043
879
- dev_dbg(dev, "%s()\n", __func__);
880
-
8811044 if (!hcd) {
882
- dev_err(dev, "%s: No plalform data\n", __func__);
1045
+ dev_err(dev, "%s: No platform data\n", __func__);
8831046 return -EINVAL;
8841047 }
8851048
8861049 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) ||
8881052 !hcd->ops->audio_shutdown) {
8891053 dev_err(dev, "%s: Invalid parameters\n", __func__);
8901054 return -EINVAL;
....@@ -895,29 +1059,30 @@
8951059 return -ENOMEM;
8961060
8971061 hcp->hcd = *hcd;
898
- mutex_init(&hcp->current_stream_lock);
1062
+ mutex_init(&hcp->lock);
8991063
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)
9031071 return -ENOMEM;
9041072
9051073 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;
9091076 i++;
9101077 }
9111078
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;
9161081
9171082 dev_set_drvdata(dev, hcp);
9181083
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);
9211086 if (ret) {
9221087 dev_err(dev, "%s: snd_soc_register_component() failed (%d)\n",
9231088 __func__, ret);