aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeffy Chen <jeffy.chen@rock-chips.com>2017-09-19 08:57:58 -0400
committerMark Brown <broonie@kernel.org>2017-09-19 09:12:56 -0400
commitd9f9c167edae999fc0fcbc97188ab29278e24958 (patch)
tree05db4a95f8bc022bf91f933580c4b233264bbea3
parente9331ee9b164d58b4dd0abc882ba7e23d2f404b3 (diff)
ASoC: rockchip: Init dapm routes dynamically
Currently we are using a fixed list of dapm routes. Init dapm routes dynamically when parsing dailinks, since we are supporting optional codecs. Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com> Reviewed-by: Matthias Kaehlcke <mka@chromium.org> Tested-by: Matthias Kaehlcke <mka@chromium.org> Signed-off-by: Mark Brown <broonie@kernel.org>
-rw-r--r--sound/soc/rockchip/rk3399_gru_sound.c88
1 files changed, 72 insertions, 16 deletions
diff --git a/sound/soc/rockchip/rk3399_gru_sound.c b/sound/soc/rockchip/rk3399_gru_sound.c
index ad19e391c4a6..fab868850d3a 100644
--- a/sound/soc/rockchip/rk3399_gru_sound.c
+++ b/sound/soc/rockchip/rk3399_gru_sound.c
@@ -50,20 +50,6 @@ static const struct snd_soc_dapm_widget rockchip_dapm_widgets[] = {
50 SND_SOC_DAPM_LINE("HDMI", NULL), 50 SND_SOC_DAPM_LINE("HDMI", NULL),
51}; 51};
52 52
53static const struct snd_soc_dapm_route rockchip_dapm_routes[] = {
54 /* Input Lines */
55 {"MIC", NULL, "Headset Mic"},
56 {"DMIC1L", NULL, "Int Mic"},
57 {"DMIC1R", NULL, "Int Mic"},
58 {"DMic", NULL, "Int Mic"},
59
60 /* Output Lines */
61 {"Headphones", NULL, "HPL"},
62 {"Headphones", NULL, "HPR"},
63 {"Speakers", NULL, "Speaker"},
64 {"HDMI", NULL, "TX"},
65};
66
67static const struct snd_kcontrol_new rockchip_controls[] = { 53static const struct snd_kcontrol_new rockchip_controls[] = {
68 SOC_DAPM_PIN_SWITCH("Headphones"), 54 SOC_DAPM_PIN_SWITCH("Headphones"),
69 SOC_DAPM_PIN_SWITCH("Speakers"), 55 SOC_DAPM_PIN_SWITCH("Speakers"),
@@ -318,8 +304,6 @@ static struct snd_soc_card rockchip_sound_card = {
318 .owner = THIS_MODULE, 304 .owner = THIS_MODULE,
319 .dapm_widgets = rockchip_dapm_widgets, 305 .dapm_widgets = rockchip_dapm_widgets,
320 .num_dapm_widgets = ARRAY_SIZE(rockchip_dapm_widgets), 306 .num_dapm_widgets = ARRAY_SIZE(rockchip_dapm_widgets),
321 .dapm_routes = rockchip_dapm_routes,
322 .num_dapm_routes = ARRAY_SIZE(rockchip_dapm_routes),
323 .controls = rockchip_controls, 307 .controls = rockchip_controls,
324 .num_controls = ARRAY_SIZE(rockchip_controls), 308 .num_controls = ARRAY_SIZE(rockchip_controls),
325}; 309};
@@ -395,6 +379,65 @@ static const struct snd_soc_dai_link rockchip_dais[] = {
395 }, 379 },
396}; 380};
397 381
382static const struct snd_soc_dapm_route rockchip_sound_cdndp_routes[] = {
383 /* Output */
384 {"HDMI", NULL, "TX"},
385};
386
387static const struct snd_soc_dapm_route rockchip_sound_da7219_routes[] = {
388 /* Output */
389 {"Headphones", NULL, "HPL"},
390 {"Headphones", NULL, "HPR"},
391
392 /* Input */
393 {"MIC", NULL, "Headset Mic"},
394};
395
396static const struct snd_soc_dapm_route rockchip_sound_dmic_routes[] = {
397 /* Input */
398 {"DMic", NULL, "Int Mic"},
399};
400
401static const struct snd_soc_dapm_route rockchip_sound_max98357a_routes[] = {
402 /* Output */
403 {"Speakers", NULL, "Speaker"},
404};
405
406static const struct snd_soc_dapm_route rockchip_sound_rt5514_routes[] = {
407 /* Input */
408 {"DMIC1L", NULL, "Int Mic"},
409 {"DMIC1R", NULL, "Int Mic"},
410};
411
412struct rockchip_sound_route {
413 const struct snd_soc_dapm_route *routes;
414 int num_routes;
415};
416
417static const struct rockchip_sound_route rockchip_routes[] = {
418 [DAILINK_CDNDP] = {
419 .routes = rockchip_sound_cdndp_routes,
420 .num_routes = ARRAY_SIZE(rockchip_sound_cdndp_routes),
421 },
422 [DAILINK_DA7219] = {
423 .routes = rockchip_sound_da7219_routes,
424 .num_routes = ARRAY_SIZE(rockchip_sound_da7219_routes),
425 },
426 [DAILINK_DMIC] = {
427 .routes = rockchip_sound_dmic_routes,
428 .num_routes = ARRAY_SIZE(rockchip_sound_dmic_routes),
429 },
430 [DAILINK_MAX98357A] = {
431 .routes = rockchip_sound_max98357a_routes,
432 .num_routes = ARRAY_SIZE(rockchip_sound_max98357a_routes),
433 },
434 [DAILINK_RT5514] = {
435 .routes = rockchip_sound_rt5514_routes,
436 .num_routes = ARRAY_SIZE(rockchip_sound_rt5514_routes),
437 },
438 [DAILINK_RT5514_DSP] = {},
439};
440
398static int rockchip_sound_codec_node_match(struct device_node *np_codec) 441static int rockchip_sound_codec_node_match(struct device_node *np_codec)
399{ 442{
400 int i; 443 int i;
@@ -412,6 +455,7 @@ static int rockchip_sound_of_parse_dais(struct device *dev,
412 struct device_node *np_cpu, *np_cpu0, *np_cpu1; 455 struct device_node *np_cpu, *np_cpu0, *np_cpu1;
413 struct device_node *np_codec; 456 struct device_node *np_codec;
414 struct snd_soc_dai_link *dai; 457 struct snd_soc_dai_link *dai;
458 struct snd_soc_dapm_route *routes;
415 int i, index; 459 int i, index;
416 460
417 card->dai_link = devm_kzalloc(dev, sizeof(rockchip_dais), 461 card->dai_link = devm_kzalloc(dev, sizeof(rockchip_dais),
@@ -419,9 +463,16 @@ static int rockchip_sound_of_parse_dais(struct device *dev,
419 if (!card->dai_link) 463 if (!card->dai_link)
420 return -ENOMEM; 464 return -ENOMEM;
421 465
466 routes = devm_kzalloc(dev, sizeof(rockchip_routes),
467 GFP_KERNEL);
468 if (!routes)
469 return -ENOMEM;
470 card->dapm_routes = routes;
471
422 np_cpu0 = of_parse_phandle(dev->of_node, "rockchip,cpu", 0); 472 np_cpu0 = of_parse_phandle(dev->of_node, "rockchip,cpu", 0);
423 np_cpu1 = of_parse_phandle(dev->of_node, "rockchip,cpu", 1); 473 np_cpu1 = of_parse_phandle(dev->of_node, "rockchip,cpu", 1);
424 474
475 card->num_dapm_routes = 0;
425 card->num_links = 0; 476 card->num_links = 0;
426 for (i = 0; i < ARRAY_SIZE(rockchip_dais); i++) { 477 for (i = 0; i < ARRAY_SIZE(rockchip_dais); i++) {
427 np_codec = of_parse_phandle(dev->of_node, 478 np_codec = of_parse_phandle(dev->of_node,
@@ -449,6 +500,11 @@ static int rockchip_sound_of_parse_dais(struct device *dev,
449 dai->codec_of_node = np_codec; 500 dai->codec_of_node = np_codec;
450 dai->platform_of_node = np_cpu; 501 dai->platform_of_node = np_cpu;
451 dai->cpu_of_node = np_cpu; 502 dai->cpu_of_node = np_cpu;
503
504 memcpy(routes + card->num_dapm_routes,
505 rockchip_routes[index].routes,
506 rockchip_routes[index].num_routes * sizeof(*routes));
507 card->num_dapm_routes += rockchip_routes[index].num_routes;
452 } 508 }
453 509
454 return 0; 510 return 0;