Skip to content

Commit 758b9ce

Browse files
LuoXiaoTanrkhuangtao
authored andcommitted
ASoC: rockchip: add rt5651_tc358749x driver
add rockchip_rt5651_tc358749x machine driver to support HDMIIn function Change-Id: Ieb0e046bec60ea0a27ee49ce1204b032ad646724 Signed-off-by: LuoXiaoTan <lxt@rock-chips.com>
1 parent 80eba80 commit 758b9ce

3 files changed

Lines changed: 261 additions & 0 deletions

File tree

sound/soc/rockchip/Kconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,16 @@ config SND_SOC_ROCKCHIP_RT5645
7070
Say Y or M here if you want to add support for SoC audio on Rockchip
7171
boards using the RT5645/RT5650 codec, such as Veyron.
7272

73+
config SND_SOC_ROCKCHIP_RT5651_TC358749
74+
tristate "ASoC support for Rockchip boards RT5651 TC358749 HDMIIN"
75+
depends on SND_SOC_ROCKCHIP && I2C && GPIOLIB && CLKDEV_LOOKUP
76+
select SND_SOC_ROCKCHIP_I2S
77+
select SND_SOC_RT5651
78+
select SND_SOC_TC358749X
79+
help
80+
Say Y or M here if you want to add support for SoC audio on Rockchip
81+
boards for RT5651 TC358749 HDMIIn
82+
7383
config SND_SOC_ROCKCHIP_CDNDP
7484
tristate "ASoC support for Rockchip CDN DP common codec"
7585
depends on SND_SOC_ROCKCHIP && CLKDEV_LOOKUP

sound/soc/rockchip/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ snd-soc-rockchip-da7219-objs := rockchip_da7219.o
1111
snd-soc-rockchip-hdmi-dp-objs := rockchip_hdmi_dp.o
1212
snd-soc-rockchip-max98090-objs := rockchip_max98090.o
1313
snd-soc-rockchip-rt5645-objs := rockchip_rt5645.o
14+
snd-soc-rockchip-rt5651-tc358749x-objs := rockchip_rt5651_tc358749x.o
1415
snd-soc-rockchip-cdndp-objs := rockchip_cdndp.o
1516

1617
obj-$(CONFIG_SND_SOC_ROCKCHIP_DA7219) += snd-soc-rockchip-da7219.o
1718
obj-$(CONFIG_SND_SOC_ROCKCHIP_HDMI_DP) += snd-soc-rockchip-hdmi-dp.o
1819
obj-$(CONFIG_SND_SOC_ROCKCHIP_MAX98090) += snd-soc-rockchip-max98090.o
1920
obj-$(CONFIG_SND_SOC_ROCKCHIP_RT5645) += snd-soc-rockchip-rt5645.o
21+
obj-$(CONFIG_SND_SOC_ROCKCHIP_RT5651_TC358749) += snd-soc-rockchip-rt5651-tc358749x.o
2022
obj-$(CONFIG_SND_SOC_ROCKCHIP_CDNDP) += snd-soc-rockchip-cdndp.o
Lines changed: 249 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,249 @@
1+
/*
2+
* rockchip_rt5651_tc358749x.c -- RK3399 machine driver with
3+
* RT5651/TC358749 codecs
4+
*
5+
* Copyright (c) 2016, ROCKCHIP CORPORATION. All rights reserved.
6+
* Author: Xiaotan Luo <lxt@rock-chips.com>
7+
*
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.
11+
*
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.
16+
*/
17+
18+
#include <linux/module.h>
19+
#include <sound/soc.h>
20+
21+
#include "rockchip_i2s.h"
22+
#include "../codecs/rt5651.h"
23+
#include "../codecs/tc358749x.h"
24+
25+
#define DRV_NAME "rk3399-rt5651-tc358749x"
26+
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),
32+
};
33+
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"},
39+
};
40+
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"),
46+
};
47+
48+
static int rockchip_rt5651_hw_params(struct snd_pcm_substream *substream,
49+
struct snd_pcm_hw_params *params)
50+
{
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;
54+
int mclk, ret;
55+
56+
/* in bypass mode, the mclk has to be one of the frequencies below */
57+
switch (params_rate(params)) {
58+
case 8000:
59+
case 16000:
60+
case 24000:
61+
case 32000:
62+
case 48000:
63+
case 64000:
64+
case 96000:
65+
mclk = 12288000;
66+
break;
67+
case 11025:
68+
case 22050:
69+
case 44100:
70+
case 88200:
71+
mclk = 11289600;
72+
break;
73+
default:
74+
return -EINVAL;
75+
}
76+
77+
ret = snd_soc_dai_set_sysclk(cpu_dai, 0, mclk, SND_SOC_CLOCK_OUT);
78+
if (ret < 0) {
79+
dev_err(codec_dai->dev, "Can't set cpu clock out %d\n", ret);
80+
return ret;
81+
}
82+
83+
ret = snd_soc_dai_set_sysclk(codec_dai, 0, mclk, SND_SOC_CLOCK_IN);
84+
if (ret < 0) {
85+
dev_err(codec_dai->dev, "Can't set codec clock in %d\n", ret);
86+
return ret;
87+
}
88+
89+
return 0;
90+
}
91+
92+
static int rockchip_rt5651_voice_hw_params(struct snd_pcm_substream *substream,
93+
struct snd_pcm_hw_params *params)
94+
{
95+
struct snd_soc_pcm_runtime *rtd = substream->private_data;
96+
struct snd_soc_dai *codec_dai = rtd->codec_dai;
97+
int mclk, ret;
98+
99+
/* in bypass mode, the mclk has to be one of the frequencies below */
100+
switch (params_rate(params)) {
101+
case 8000:
102+
case 16000:
103+
case 24000:
104+
case 32000:
105+
case 48000:
106+
case 64000:
107+
case 96000:
108+
mclk = 12288000;
109+
break;
110+
case 11025:
111+
case 22050:
112+
case 44100:
113+
case 88200:
114+
mclk = 11289600;
115+
break;
116+
default:
117+
return -EINVAL;
118+
}
119+
120+
/*Set the system clk for codec*/
121+
snd_soc_dai_set_pll(codec_dai, 0, RT5651_PLL1_S_MCLK, mclk, 24576000);
122+
123+
ret = snd_soc_dai_set_sysclk(codec_dai, RT5651_SCLK_S_PLL1, 24576000,
124+
SND_SOC_CLOCK_IN);
125+
if (ret < 0) {
126+
dev_err(codec_dai->dev, "Can't set codec clock in %d\n", ret);
127+
return ret;
128+
}
129+
return 0;
130+
}
131+
132+
static struct snd_soc_ops rockchip_sound_rt5651_hifi_ops = {
133+
.hw_params = rockchip_rt5651_hw_params,
134+
};
135+
136+
static struct snd_soc_ops rockchip_sound_rt5651_voice_ops = {
137+
.hw_params = rockchip_rt5651_voice_hw_params,
138+
};
139+
140+
enum {
141+
DAILINK_RT5651_HIFI,
142+
DAILINK_RT5651_VOICE,
143+
DAILINK_TC358749_HDMIIN,
144+
};
145+
146+
#define DAILINK_ENTITIES (DAILINK_TC358749_HDMIIN + 1)
147+
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,
157+
},
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,
166+
},
167+
[DAILINK_TC358749_HDMIIN] = {
168+
.name = "TC358749 HDMIIN",
169+
.stream_name = "TC358749 PCM",
170+
.codec_dai_name = "tc358749x-audio",
171+
},
172+
};
173+
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),
185+
};
186+
187+
static int rockchip_sound_probe(struct platform_device *pdev)
188+
{
189+
struct snd_soc_card *card = &rockchip_sound_card;
190+
struct device_node *cpu_node;
191+
int i, ret;
192+
193+
dev_info(&pdev->dev, "%s\n", __func__);
194+
195+
cpu_node = of_parse_phandle(pdev->dev.of_node, "rockchip,cpu", 0);
196+
if (!cpu_node) {
197+
dev_err(&pdev->dev,
198+
"Property 'rockchip,cpu' failed\n");
199+
return -EINVAL;
200+
}
201+
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;
205+
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) {
210+
dev_err(&pdev->dev,
211+
"Property[%d] 'rockchip,codec' failed\n", i);
212+
return -EINVAL;
213+
}
214+
}
215+
216+
card->dev = &pdev->dev;
217+
platform_set_drvdata(pdev, card);
218+
ret = devm_snd_soc_register_card(&pdev->dev, card);
219+
if (ret)
220+
dev_err(&pdev->dev, "%s register card failed %d\n",
221+
__func__, ret);
222+
223+
dev_info(&pdev->dev, "snd_soc_register_card successful\n");
224+
return ret;
225+
}
226+
227+
static const struct of_device_id rockchip_sound_of_match[] = {
228+
{ .compatible = "rockchip,rockchip-rt5651-tc358749x-sound", },
229+
{},
230+
};
231+
232+
static struct platform_driver rockchip_sound_driver = {
233+
.probe = rockchip_sound_probe,
234+
.driver = {
235+
.name = DRV_NAME,
236+
.of_match_table = rockchip_sound_of_match,
237+
#ifdef CONFIG_PM
238+
.pm = &snd_soc_pm_ops,
239+
#endif
240+
},
241+
};
242+
243+
module_platform_driver(rockchip_sound_driver);
244+
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);

0 commit comments

Comments
 (0)