Skip to content

Commit ab09e25

Browse files
committed
WIP: cdn_dp hdmi audio switch
1 parent 8c6aae9 commit ab09e25

File tree

2 files changed

+83
-36
lines changed

2 files changed

+83
-36
lines changed

arch/arm64/boot/dts/rockchip/rk3399-rockpro64.dtsi

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,32 @@
7373
reset-gpios = <&gpio0 RK_PB2 GPIO_ACTIVE_LOW>;
7474
};
7575

76-
hdmi-sound {
77-
status = "okay";
78-
compatible = "rockchip,rk3399-hdmi-dp";
79-
rockchip,cpu = <&i2s2>;
80-
rockchip,codec = <&hdmi>, <&cdn_dp>;
76+
cdn_dp_hdmi_sound: cdn-dp-hdmi-sound {
77+
compatible = "simple-audio-card";
78+
simple-audio-card,format = "i2s";
79+
simple-audio-card,mclk-fs = <256>;
80+
simple-audio-card,name = "cdn-dp-hdmi-sound";
81+
82+
simple-audio-card,dai-link@0 {
83+
format = "i2s";
84+
cpu {
85+
sound-dai = <&i2s2>;
86+
};
87+
88+
codec {
89+
sound-dai = <&hdmi 0>;
90+
};
91+
};
92+
simple-audio-card,dai-link@1 {
93+
format = "i2s";
94+
cpu {
95+
sound-dai = <&i2s2>;
96+
};
97+
98+
codec {
99+
sound-dai = <&cdn_dp 1>;
100+
};
101+
};
81102
};
82103

83104
sound {
@@ -264,10 +285,6 @@
264285
status = "okay";
265286
};
266287

267-
&hdmi_sound {
268-
status = "okay";
269-
};
270-
271288
&gpu {
272289
mali-supply = <&vdd_gpu>;
273290
status = "okay";

sound/soc/rockchip/rockchip_hdmi_dp.c

Lines changed: 57 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@
3535
#define DRV_NAME "rk-hdmi-dp-sound"
3636
#define MAX_CODECS 2
3737

38+
static const struct snd_soc_dapm_widget rk_dapm_widgets[] = {
39+
SND_SOC_DAPM_LINE("HDMI", NULL),
40+
};
41+
42+
static const struct snd_soc_dapm_route rk_dapm_routes[] = {
43+
{"HDMI", NULL, "TX"},
44+
};
45+
46+
static const struct snd_kcontrol_new rk_mc_controls[] = {
47+
SOC_DAPM_PIN_SWITCH("HDMI"),
48+
};
49+
3850
static int rk_hdmi_dp_hw_params(struct snd_pcm_substream *substream,
3951
struct snd_pcm_hw_params *params)
4052
{
@@ -142,32 +154,43 @@ static struct snd_soc_ops rockchip_sound_hdmidp_ops = {
142154
.hw_params = rk_hdmi_dp_hw_params,
143155
};
144156

157+
SND_SOC_DAILINK_DEFS(audio,
158+
DAILINK_COMP_ARRAY(COMP_CPU(NULL)),
159+
DAILINK_COMP_ARRAY(COMP_CODEC(NULL, NULL), COMP_CODEC(NULL, NULL)),
160+
DAILINK_COMP_ARRAY(COMP_PLATFORM(NULL)));
161+
145162
static struct snd_soc_dai_link rk_dailink = {
146163
.name = "HDMI-DP",
147164
.stream_name = "HDMI-DP",
148165
.init = rockchip_sound_hdmi_dp_init,
149166
.ops = &rockchip_sound_hdmidp_ops,
150167
.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
151168
SND_SOC_DAIFMT_CBS_CFS,
169+
SND_SOC_DAILINK_REG(audio),
152170
};
153171

154172
static struct snd_soc_card snd_soc_card_rk = {
155173
.name = "rk-hdmi-dp-sound",
156174
.dai_link = &rk_dailink,
157175
.num_links = 1,
158176
.num_aux_devs = 0,
177+
.dapm_widgets = rk_dapm_widgets,
178+
.num_dapm_widgets = ARRAY_SIZE(rk_dapm_widgets),
179+
.dapm_routes = rk_dapm_routes,
180+
.num_dapm_routes = ARRAY_SIZE(rk_dapm_routes),
181+
.controls = rk_mc_controls,
182+
.num_controls = ARRAY_SIZE(rk_mc_controls),
159183
};
160184

161185
static int rk_hdmi_dp_probe(struct platform_device *pdev)
162186
{
163187
struct snd_soc_card *card = &snd_soc_card_rk;
164188
struct device_node *np = pdev->dev.of_node;
165189
struct snd_soc_dai_link *link = card->dai_link;
166-
struct snd_soc_dai_link_component *codecs;
190+
struct snd_soc_dai_link_component *codec;
167191
struct of_phandle_args args;
168-
struct device_node *node;
169192
int count;
170-
int ret = 0, i = 0, idx = 0;
193+
int ret = 0, i = 0;
171194

172195
card->dev = &pdev->dev;
173196

@@ -176,44 +199,51 @@ static int rk_hdmi_dp_probe(struct platform_device *pdev)
176199
return -EINVAL;
177200

178201
/* refine codecs, remove unavailable node */
179-
for (i = 0; i < count; i++) {
180-
node = of_parse_phandle(np, "rockchip,codec", i);
181-
if (!node)
182-
return -ENODEV;
183-
if (of_device_is_available(node))
184-
idx++;
185-
}
186-
187-
if (!idx)
188-
return -ENODEV;
202+
link->num_codecs = 0;
189203

190-
codecs = devm_kcalloc(&pdev->dev, idx,
191-
sizeof(*codecs), GFP_KERNEL);
192-
link->codecs = codecs;
193-
link->num_codecs = idx;
194-
idx = 0;
195204
for (i = 0; i < count; i++) {
196-
node = of_parse_phandle(np, "rockchip,codec", i);
197-
if (!node)
198-
return -ENODEV;
199-
if (!of_device_is_available(node))
205+
codec = &link->codecs[link->num_codecs];
206+
207+
codec->of_node = of_parse_phandle(np, "rockchip,codec", i);
208+
if (!codec->of_node) {
209+
dev_err(&pdev->dev,
210+
"Property 'rockchip,codec' missing or invalid\n");
211+
return -EINVAL;
212+
}
213+
214+
if (!of_device_is_available(codec->of_node)) {
215+
dev_err(&pdev->dev,
216+
"Property 'rockchip,codec' is not available\n");
200217
continue;
218+
}
201219

202220
ret = of_parse_phandle_with_fixed_args(np, "rockchip,codec",
203221
0, i, &args);
204-
if (ret)
222+
if (ret) {
223+
dev_err(&pdev->dev,
224+
"Unable to parse property 'rockchip,codec'\n");
205225
return ret;
226+
}
206227

207-
codecs[idx].of_node = node;
208-
ret = snd_soc_get_dai_name(&args, &codecs[idx].dai_name);
228+
ret = snd_soc_get_dai_name(&args, &codec->dai_name);
209229
if (ret)
210230
return ret;
211-
idx++;
231+
232+
link->num_codecs++;
233+
}
234+
235+
if (!link->num_codecs) {
236+
dev_err(&pdev->dev,
237+
"Property 'rockchip,cpu' missing or invalid\n");
238+
return -ENODEV;
212239
}
213240

214241
link->cpus->of_node = of_parse_phandle(np, "rockchip,cpu", 0);
215-
if (!link->cpus->of_node)
242+
if (!link->cpus->of_node) {
243+
dev_err(&pdev->dev,
244+
"Property 'rockchip,cpu' missing or invalid\n");
216245
return -ENODEV;
246+
}
217247
link->platforms->of_node = link->cpus->of_node;
218248

219249
ret = devm_snd_soc_register_card(&pdev->dev, card);

0 commit comments

Comments
 (0)