2 * Rockchip machine ASoC driver for Rockchip built-in HDMI and DP audio output
4 * Copyright (C) 2017 Fuzhou Rockchip Electronics Co., Ltd
6 * Authors: Sugar Zhang <sugar.zhang@rock-chips.com>,
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms and conditions of the GNU General Public License,
10 * version 2, as published by the Free Software Foundation.
12 * This program is distributed in the hope it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include <linux/module.h>
23 #include <linux/platform_device.h>
24 #include <linux/slab.h>
25 #include <sound/core.h>
26 #include <sound/pcm.h>
27 #include <sound/pcm_params.h>
28 #include <sound/soc.h>
29 #include <sound/soc-dapm.h>
31 #include "rockchip_i2s.h"
33 #define DRV_NAME "rk-hdmi-dp-sound"
36 static int rk_hdmi_dp_hw_params(struct snd_pcm_substream *substream,
37 struct snd_pcm_hw_params *params)
40 struct snd_soc_pcm_runtime *rtd = substream->private_data;
41 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
44 switch (params_rate(params)) {
64 ret = snd_soc_dai_set_sysclk(cpu_dai, 0, mclk,
67 if (ret && ret != -ENOTSUPP) {
68 dev_err(cpu_dai->dev, "Can't set cpu clock %d\n", ret);
75 static struct snd_soc_ops rk_ops = {
76 .hw_params = rk_hdmi_dp_hw_params,
79 static struct snd_soc_dai_link rk_dailink = {
81 .stream_name = "HDMI-DP",
83 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
84 SND_SOC_DAIFMT_CBS_CFS,
87 static struct snd_soc_card snd_soc_card_rk = {
88 .name = "rk-hdmi-dp-sound",
89 .dai_link = &rk_dailink,
94 static int rk_hdmi_dp_probe(struct platform_device *pdev)
96 struct snd_soc_card *card = &snd_soc_card_rk;
97 struct device_node *np = pdev->dev.of_node;
98 struct snd_soc_dai_link *link = card->dai_link;
99 struct snd_soc_dai_link_component *codecs;
100 struct of_phandle_args args;
101 struct device_node *node;
103 int ret = 0, i = 0, idx = 0;
105 card->dev = &pdev->dev;
107 count = of_count_phandle_with_args(np, "rockchip,codec", NULL);
108 if (count < 0 || count > MAX_CODECS)
111 /* refine codecs, remove unavailable node */
112 for (i = 0; i < count; i++) {
113 node = of_parse_phandle(np, "rockchip,codec", i);
116 if (of_device_is_available(node))
123 codecs = devm_kcalloc(&pdev->dev, idx,
124 sizeof(*codecs), GFP_KERNEL);
125 link->codecs = codecs;
126 link->num_codecs = idx;
128 for (i = 0; i < count; i++) {
129 node = of_parse_phandle(np, "rockchip,codec", i);
132 if (!of_device_is_available(node))
135 ret = of_parse_phandle_with_fixed_args(np, "rockchip,codec",
140 codecs[idx].of_node = node;
141 ret = snd_soc_get_dai_name(&args, &codecs[idx].dai_name);
147 link->cpu_of_node = of_parse_phandle(np, "rockchip,cpu", 0);
148 if (!link->cpu_of_node)
151 link->platform_of_node = link->cpu_of_node;
153 ret = devm_snd_soc_register_card(&pdev->dev, card);
154 if (ret == -EPROBE_DEFER)
155 return -EPROBE_DEFER;
157 dev_err(&pdev->dev, "card register failed %d\n", ret);
161 platform_set_drvdata(pdev, card);
166 static const struct of_device_id rockchip_sound_of_match[] = {
167 { .compatible = "rockchip,rk3399-hdmi-dp", },
171 MODULE_DEVICE_TABLE(of, rockchip_sound_of_match);
173 static struct platform_driver rockchip_sound_driver = {
174 .probe = rk_hdmi_dp_probe,
177 .pm = &snd_soc_pm_ops,
178 .of_match_table = rockchip_sound_of_match,
182 module_platform_driver(rockchip_sound_driver);
184 MODULE_AUTHOR("Sugar Zhang <sugar.zhang@rock-chips.com>");
185 MODULE_DESCRIPTION("Rockchip Built-in HDMI and DP machine ASoC driver");
186 MODULE_LICENSE("GPL v2");
187 MODULE_ALIAS("platform:" DRV_NAME);