ARM64: DTS: Fix Firefly board audio driver
[firefly-linux-kernel-4.4.55.git] / sound / soc / codecs / dw-hdmi-audio.c
1 /*
2  * dw-hdmi-audio.c
3  *
4  * DesignerWare ALSA SoC Codec driver for DW HDMI audio.
5  * Copyright (c) 2016 Fuzhou Rockchip Electronics Co., Ltd
6  *
7  * This program is free software; you can redistribute it and/or modify it
8  * under the terms and conditions of the GNU General Public License,
9  * version 2, as published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
14  * more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.*
18  *
19  */
20 #include <linux/init.h>
21 #include <linux/module.h>
22 #include <linux/device.h>
23 #include <sound/pcm.h>
24 #include <sound/soc.h>
25 #include <sound/core.h>
26 #include <sound/initval.h>
27 #include <sound/pcm_params.h>
28 #include "../../../drivers/video/rockchip/hdmi/rockchip-hdmi.h"
29
30 static int snd_dw_hdmi_dai_hw_params(struct snd_pcm_substream *substream,
31                                      struct snd_pcm_hw_params *params,
32                                      struct snd_soc_dai *codec_dai)
33 {
34         return snd_config_hdmi_audio(params);
35 }
36
37 static const struct snd_soc_dapm_widget snd_dw_hdmi_audio_widgets[] = {
38         SND_SOC_DAPM_OUTPUT("TX"),
39 };
40
41 static const struct snd_soc_dapm_route snd_dw_hdmi_audio_routes[] = {
42         { "TX", NULL, "Playback" },
43 };
44
45 static const struct snd_soc_dai_ops dw_hdmi_dai_ops = {
46         .hw_params = snd_dw_hdmi_dai_hw_params,
47 };
48
49 static struct snd_soc_dai_driver dw_hdmi_audio_dai = {
50         .name = "dw-hdmi-hifi",
51         .playback = {
52                 .stream_name = "Playback",
53                 .channels_min = 2,
54                 .channels_max = 8,
55                 .rates = SNDRV_PCM_RATE_32000 |
56                          SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |
57                          SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 |
58                          SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_192000,
59                 .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE,
60         },
61         .ops = &dw_hdmi_dai_ops,
62 };
63
64 static const struct snd_soc_codec_driver dw_hdmi_audio = {
65         .dapm_widgets = snd_dw_hdmi_audio_widgets,
66         .num_dapm_widgets = ARRAY_SIZE(snd_dw_hdmi_audio_widgets),
67         .dapm_routes = snd_dw_hdmi_audio_routes,
68         .num_dapm_routes = ARRAY_SIZE(snd_dw_hdmi_audio_routes),
69 };
70
71 static int dw_hdmi_audio_probe(struct platform_device *pdev)
72 {
73         int ret;
74
75         ret = snd_soc_register_codec(&pdev->dev, &dw_hdmi_audio,
76                                      &dw_hdmi_audio_dai, 1);
77         if (ret)
78                 dev_err(&pdev->dev, "register codec failed (%d)\n", ret);
79
80         return ret;
81 }
82
83 static int dw_hdmi_audio_remove(struct platform_device *pdev)
84 {
85         snd_soc_unregister_codec(&pdev->dev);
86
87         return 0;
88 }
89
90 static const struct of_device_id dw_hdmi_audio_ids[] = {
91         { .compatible = "dw-hdmi-audio", },
92         { }
93 };
94
95 static struct platform_driver dw_hdmi_audio_driver = {
96         .driver = {
97                 .name = "dw-hdmi-audio",
98                 .of_match_table = of_match_ptr(dw_hdmi_audio_ids),
99         },
100         .probe = dw_hdmi_audio_probe,
101         .remove = dw_hdmi_audio_remove,
102 };
103 module_platform_driver(dw_hdmi_audio_driver);
104
105 MODULE_AUTHOR("Sugar Zhang <sugar.zhang@rock-chips.com>");
106 MODULE_DESCRIPTION("DW HDMI Audio ASoC Interface");
107 MODULE_LICENSE("GPL");