aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/codecs/hdmi-codec.c
diff options
context:
space:
mode:
Diffstat (limited to 'sound/soc/codecs/hdmi-codec.c')
-rw-r--r--sound/soc/codecs/hdmi-codec.c92
1 files changed, 11 insertions, 81 deletions
diff --git a/sound/soc/codecs/hdmi-codec.c b/sound/soc/codecs/hdmi-codec.c
index 8c5ae1fc23a9..22ed0dc88f0a 100644
--- a/sound/soc/codecs/hdmi-codec.c
+++ b/sound/soc/codecs/hdmi-codec.c
@@ -25,17 +25,6 @@
25 25
26#include <drm/drm_crtc.h> /* This is only to get MAX_ELD_BYTES */ 26#include <drm/drm_crtc.h> /* This is only to get MAX_ELD_BYTES */
27 27
28struct hdmi_device {
29 struct device *dev;
30 struct list_head list;
31 int cnt;
32};
33#define pos_to_hdmi_device(pos) container_of((pos), struct hdmi_device, list)
34LIST_HEAD(hdmi_device_list);
35static DEFINE_MUTEX(hdmi_mutex);
36
37#define DAI_NAME_SIZE 16
38
39#define HDMI_CODEC_CHMAP_IDX_UNKNOWN -1 28#define HDMI_CODEC_CHMAP_IDX_UNKNOWN -1
40 29
41struct hdmi_codec_channel_map_table { 30struct hdmi_codec_channel_map_table {
@@ -293,7 +282,6 @@ struct hdmi_codec_priv {
293 struct hdmi_codec_daifmt daifmt[2]; 282 struct hdmi_codec_daifmt daifmt[2];
294 struct mutex current_stream_lock; 283 struct mutex current_stream_lock;
295 struct snd_pcm_substream *current_stream; 284 struct snd_pcm_substream *current_stream;
296 struct snd_pcm_hw_constraint_list ratec;
297 uint8_t eld[MAX_ELD_BYTES]; 285 uint8_t eld[MAX_ELD_BYTES];
298 struct snd_pcm_chmap *chmap_info; 286 struct snd_pcm_chmap *chmap_info;
299 unsigned int chmap_idx; 287 unsigned int chmap_idx;
@@ -702,6 +690,7 @@ static int hdmi_codec_pcm_new(struct snd_soc_pcm_runtime *rtd,
702} 690}
703 691
704static struct snd_soc_dai_driver hdmi_i2s_dai = { 692static struct snd_soc_dai_driver hdmi_i2s_dai = {
693 .name = "i2s-hifi",
705 .id = DAI_ID_I2S, 694 .id = DAI_ID_I2S,
706 .playback = { 695 .playback = {
707 .stream_name = "Playback", 696 .stream_name = "Playback",
@@ -716,6 +705,7 @@ static struct snd_soc_dai_driver hdmi_i2s_dai = {
716}; 705};
717 706
718static const struct snd_soc_dai_driver hdmi_spdif_dai = { 707static const struct snd_soc_dai_driver hdmi_spdif_dai = {
708 .name = "spdif-hifi",
719 .id = DAI_ID_SPDIF, 709 .id = DAI_ID_SPDIF,
720 .playback = { 710 .playback = {
721 .stream_name = "Playback", 711 .stream_name = "Playback",
@@ -728,30 +718,16 @@ static const struct snd_soc_dai_driver hdmi_spdif_dai = {
728 .pcm_new = hdmi_codec_pcm_new, 718 .pcm_new = hdmi_codec_pcm_new,
729}; 719};
730 720
731static char hdmi_dai_name[][DAI_NAME_SIZE] = { 721static int hdmi_of_xlate_dai_id(struct snd_soc_component *component,
732 "hdmi-hifi.0", 722 struct device_node *endpoint)
733 "hdmi-hifi.1",
734 "hdmi-hifi.2",
735 "hdmi-hifi.3",
736};
737
738static int hdmi_of_xlate_dai_name(struct snd_soc_component *component,
739 struct of_phandle_args *args,
740 const char **dai_name)
741{ 723{
742 int id; 724 struct hdmi_codec_priv *hcp = snd_soc_component_get_drvdata(component);
725 int ret = -ENOTSUPP; /* see snd_soc_get_dai_id() */
743 726
744 if (args->args_count) 727 if (hcp->hcd.ops->get_dai_id)
745 id = args->args[0]; 728 ret = hcp->hcd.ops->get_dai_id(component, endpoint);
746 else
747 id = 0;
748 729
749 if (id < ARRAY_SIZE(hdmi_dai_name)) { 730 return ret;
750 *dai_name = hdmi_dai_name[id];
751 return 0;
752 }
753
754 return -EAGAIN;
755} 731}
756 732
757static struct snd_soc_codec_driver hdmi_codec = { 733static struct snd_soc_codec_driver hdmi_codec = {
@@ -762,7 +738,7 @@ static struct snd_soc_codec_driver hdmi_codec = {
762 .num_dapm_widgets = ARRAY_SIZE(hdmi_widgets), 738 .num_dapm_widgets = ARRAY_SIZE(hdmi_widgets),
763 .dapm_routes = hdmi_routes, 739 .dapm_routes = hdmi_routes,
764 .num_dapm_routes = ARRAY_SIZE(hdmi_routes), 740 .num_dapm_routes = ARRAY_SIZE(hdmi_routes),
765 .of_xlate_dai_name = hdmi_of_xlate_dai_name, 741 .of_xlate_dai_id = hdmi_of_xlate_dai_id,
766 }, 742 },
767}; 743};
768 744
@@ -771,8 +747,6 @@ static int hdmi_codec_probe(struct platform_device *pdev)
771 struct hdmi_codec_pdata *hcd = pdev->dev.platform_data; 747 struct hdmi_codec_pdata *hcd = pdev->dev.platform_data;
772 struct device *dev = &pdev->dev; 748 struct device *dev = &pdev->dev;
773 struct hdmi_codec_priv *hcp; 749 struct hdmi_codec_priv *hcp;
774 struct hdmi_device *hd;
775 struct list_head *pos;
776 int dai_count, i = 0; 750 int dai_count, i = 0;
777 int ret; 751 int ret;
778 752
@@ -794,35 +768,6 @@ static int hdmi_codec_probe(struct platform_device *pdev)
794 if (!hcp) 768 if (!hcp)
795 return -ENOMEM; 769 return -ENOMEM;
796 770
797 hd = NULL;
798 mutex_lock(&hdmi_mutex);
799 list_for_each(pos, &hdmi_device_list) {
800 struct hdmi_device *tmp = pos_to_hdmi_device(pos);
801
802 if (tmp->dev == dev->parent) {
803 hd = tmp;
804 break;
805 }
806 }
807
808 if (!hd) {
809 hd = devm_kzalloc(dev, sizeof(*hd), GFP_KERNEL);
810 if (!hd) {
811 mutex_unlock(&hdmi_mutex);
812 return -ENOMEM;
813 }
814
815 hd->dev = dev->parent;
816
817 list_add_tail(&hd->list, &hdmi_device_list);
818 }
819 mutex_unlock(&hdmi_mutex);
820
821 if (hd->cnt >= ARRAY_SIZE(hdmi_dai_name)) {
822 dev_err(dev, "too many hdmi codec are deteced\n");
823 return -EINVAL;
824 }
825
826 hcp->hcd = *hcd; 771 hcp->hcd = *hcd;
827 mutex_init(&hcp->current_stream_lock); 772 mutex_init(&hcp->current_stream_lock);
828 773
@@ -835,14 +780,11 @@ static int hdmi_codec_probe(struct platform_device *pdev)
835 hcp->daidrv[i] = hdmi_i2s_dai; 780 hcp->daidrv[i] = hdmi_i2s_dai;
836 hcp->daidrv[i].playback.channels_max = 781 hcp->daidrv[i].playback.channels_max =
837 hcd->max_i2s_channels; 782 hcd->max_i2s_channels;
838 hcp->daidrv[i].name = hdmi_dai_name[hd->cnt++];
839 i++; 783 i++;
840 } 784 }
841 785
842 if (hcd->spdif) { 786 if (hcd->spdif)
843 hcp->daidrv[i] = hdmi_spdif_dai; 787 hcp->daidrv[i] = hdmi_spdif_dai;
844 hcp->daidrv[i].name = hdmi_dai_name[hd->cnt++];
845 }
846 788
847 ret = snd_soc_register_codec(dev, &hdmi_codec, hcp->daidrv, 789 ret = snd_soc_register_codec(dev, &hdmi_codec, hcp->daidrv,
848 dai_count); 790 dai_count);
@@ -859,20 +801,8 @@ static int hdmi_codec_probe(struct platform_device *pdev)
859static int hdmi_codec_remove(struct platform_device *pdev) 801static int hdmi_codec_remove(struct platform_device *pdev)
860{ 802{
861 struct device *dev = &pdev->dev; 803 struct device *dev = &pdev->dev;
862 struct list_head *pos;
863 struct hdmi_codec_priv *hcp; 804 struct hdmi_codec_priv *hcp;
864 805
865 mutex_lock(&hdmi_mutex);
866 list_for_each(pos, &hdmi_device_list) {
867 struct hdmi_device *tmp = pos_to_hdmi_device(pos);
868
869 if (tmp->dev == dev->parent) {
870 list_del(pos);
871 break;
872 }
873 }
874 mutex_unlock(&hdmi_mutex);
875
876 hcp = dev_get_drvdata(dev); 806 hcp = dev_get_drvdata(dev);
877 kfree(hcp->chmap_info); 807 kfree(hcp->chmap_info);
878 snd_soc_unregister_codec(dev); 808 snd_soc_unregister_codec(dev);