2 * rockchip_rt5651_tc358749x.c -- RK3399 machine driver with
3 * RT5651/TC358749 codecs
5 * Copyright (c) 2016, ROCKCHIP CORPORATION. All rights reserved.
6 * Author: Xiaotan Luo <lxt@rock-chips.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 and
10 * only version 2 as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
18 #include <linux/module.h>
19 #include <sound/soc.h>
21 #include "rockchip_i2s.h"
22 #include "../codecs/rt5651.h"
23 #include "../codecs/tc358749x.h"
25 #define DRV_NAME "rk3399-rt5651-tc358749x"
27 static const struct snd_soc_dapm_widget rockchip_dapm_widgets[] = {
28 SND_SOC_DAPM_HP("Headphones", NULL),
29 SND_SOC_DAPM_SPK("Lineout", NULL),
30 SND_SOC_DAPM_MIC("Headset Mic", NULL),
31 SND_SOC_DAPM_MIC("Int Mic", NULL),
34 static const struct snd_soc_dapm_route rockchip_dapm_routes[] = {
35 {"Headphones", NULL, "HPOL"},
36 {"Headphones", NULL, "HPOR"},
37 {"Lineout", NULL, "LOUTL"},
38 {"Lineout", NULL, "LOUTR"},
41 static const struct snd_kcontrol_new rockchip_controls[] = {
42 SOC_DAPM_PIN_SWITCH("Headphones"),
43 SOC_DAPM_PIN_SWITCH("Lineout"),
44 SOC_DAPM_PIN_SWITCH("Headset Mic"),
45 SOC_DAPM_PIN_SWITCH("Int Mic"),
48 static int rockchip_rt5651_hw_params(struct snd_pcm_substream *substream,
49 struct snd_pcm_hw_params *params)
51 struct snd_soc_pcm_runtime *rtd = substream->private_data;
52 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
53 struct snd_soc_dai *codec_dai = rtd->codec_dai;
56 /* in bypass mode, the mclk has to be one of the frequencies below */
57 switch (params_rate(params)) {
77 ret = snd_soc_dai_set_sysclk(cpu_dai, 0, mclk, SND_SOC_CLOCK_OUT);
79 dev_err(codec_dai->dev, "Can't set cpu clock out %d\n", ret);
83 ret = snd_soc_dai_set_sysclk(codec_dai, 0, mclk, SND_SOC_CLOCK_IN);
85 dev_err(codec_dai->dev, "Can't set codec clock in %d\n", ret);
92 static int rockchip_rt5651_voice_hw_params(struct snd_pcm_substream *substream,
93 struct snd_pcm_hw_params *params)
95 struct snd_soc_pcm_runtime *rtd = substream->private_data;
96 struct snd_soc_dai *codec_dai = rtd->codec_dai;
99 /* in bypass mode, the mclk has to be one of the frequencies below */
100 switch (params_rate(params)) {
120 /*Set the system clk for codec*/
121 snd_soc_dai_set_pll(codec_dai, 0, RT5651_PLL1_S_MCLK, mclk, 24576000);
123 ret = snd_soc_dai_set_sysclk(codec_dai, RT5651_SCLK_S_PLL1, 24576000,
126 dev_err(codec_dai->dev, "Can't set codec clock in %d\n", ret);
132 static struct snd_soc_ops rockchip_sound_rt5651_hifi_ops = {
133 .hw_params = rockchip_rt5651_hw_params,
136 static struct snd_soc_ops rockchip_sound_rt5651_voice_ops = {
137 .hw_params = rockchip_rt5651_voice_hw_params,
142 DAILINK_RT5651_VOICE,
143 DAILINK_TC358749_HDMIIN,
146 #define DAILINK_ENTITIES (DAILINK_TC358749_HDMIIN + 1)
148 static struct snd_soc_dai_link rockchip_dailinks[] = {
149 [DAILINK_RT5651_HIFI] = {
150 .name = "RT5651 HIFI",
151 .stream_name = "RT5651 PCM",
152 .codec_dai_name = "rt5651-aif1",
153 .ops = &rockchip_sound_rt5651_hifi_ops,
154 /* set rt5651 as slave */
155 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
156 SND_SOC_DAIFMT_CBS_CFS,
158 [DAILINK_RT5651_VOICE] = {
159 .name = "RT5651 HDMIIN",
160 .stream_name = "RT5651 PCM",
161 .codec_dai_name = "rt5651-aif2",
162 .ops = &rockchip_sound_rt5651_voice_ops,
163 /* set rt5651 as slave */
164 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
165 SND_SOC_DAIFMT_CBS_CFS,
167 [DAILINK_TC358749_HDMIIN] = {
168 .name = "TC358749 HDMIIN",
169 .stream_name = "TC358749 PCM",
170 .codec_dai_name = "tc358749x-audio",
174 static struct snd_soc_card rockchip_sound_card = {
175 .name = "realtekrt5651codec_hdmiin",
176 .owner = THIS_MODULE,
177 .dai_link = rockchip_dailinks,
178 .num_links = ARRAY_SIZE(rockchip_dailinks),
179 .dapm_widgets = rockchip_dapm_widgets,
180 .num_dapm_widgets = ARRAY_SIZE(rockchip_dapm_widgets),
181 .dapm_routes = rockchip_dapm_routes,
182 .num_dapm_routes = ARRAY_SIZE(rockchip_dapm_routes),
183 .controls = rockchip_controls,
184 .num_controls = ARRAY_SIZE(rockchip_controls),
187 static int rockchip_sound_probe(struct platform_device *pdev)
189 struct snd_soc_card *card = &rockchip_sound_card;
190 struct device_node *cpu_node;
193 dev_info(&pdev->dev, "%s\n", __func__);
195 cpu_node = of_parse_phandle(pdev->dev.of_node, "rockchip,cpu", 0);
198 "Property 'rockchip,cpu' failed\n");
202 for (i = 0; i < DAILINK_ENTITIES; i++) {
203 rockchip_dailinks[i].platform_of_node = cpu_node;
204 rockchip_dailinks[i].cpu_of_node = cpu_node;
206 rockchip_dailinks[i].codec_of_node =
207 of_parse_phandle(pdev->dev.of_node,
208 "rockchip,codec", i);
209 if (!rockchip_dailinks[i].codec_of_node) {
211 "Property[%d] 'rockchip,codec' failed\n", i);
216 card->dev = &pdev->dev;
217 platform_set_drvdata(pdev, card);
218 ret = devm_snd_soc_register_card(&pdev->dev, card);
220 dev_err(&pdev->dev, "%s register card failed %d\n",
223 dev_info(&pdev->dev, "snd_soc_register_card successful\n");
227 static const struct of_device_id rockchip_sound_of_match[] = {
228 { .compatible = "rockchip,rockchip-rt5651-tc358749x-sound", },
232 static struct platform_driver rockchip_sound_driver = {
233 .probe = rockchip_sound_probe,
236 .of_match_table = rockchip_sound_of_match,
238 .pm = &snd_soc_pm_ops,
243 module_platform_driver(rockchip_sound_driver);
245 MODULE_AUTHOR("Xiaotan Luo <lxt@rock-chips.com>");
246 MODULE_DESCRIPTION("Rockchip ASoC Machine Driver");
247 MODULE_LICENSE("GPL v2");
248 MODULE_ALIAS("platform:" DRV_NAME);
249 MODULE_DEVICE_TABLE(of, rockchip_sound_of_match);