Skip to content

Commit 357c59a

Browse files
committed
Merge remote-tracking branch 'asoc/topic/rockchip' into asoc-next
2 parents f904f84 + 8eae6c2 commit 357c59a

1 file changed

Lines changed: 133 additions & 26 deletions

File tree

‎sound/soc/rockchip/rk3399_gru_sound.c‎

Lines changed: 133 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <linux/of_gpio.h>
2424
#include <linux/delay.h>
2525
#include <linux/spi/spi.h>
26+
#include <linux/i2c.h>
2627
#include <linux/input.h>
2728
#include <sound/core.h>
2829
#include <sound/jack.h>
@@ -47,25 +48,15 @@ static const struct snd_soc_dapm_widget rockchip_dapm_widgets[] = {
4748
SND_SOC_DAPM_SPK("Speakers", NULL),
4849
SND_SOC_DAPM_MIC("Headset Mic", NULL),
4950
SND_SOC_DAPM_MIC("Int Mic", NULL),
50-
};
51-
52-
static const struct snd_soc_dapm_route rockchip_dapm_routes[] = {
53-
/* Input Lines */
54-
{"MIC", NULL, "Headset Mic"},
55-
{"DMIC1L", NULL, "Int Mic"},
56-
{"DMIC1R", NULL, "Int Mic"},
57-
58-
/* Output Lines */
59-
{"Headphones", NULL, "HPL"},
60-
{"Headphones", NULL, "HPR"},
61-
{"Speakers", NULL, "Speaker"},
51+
SND_SOC_DAPM_LINE("HDMI", NULL),
6252
};
6353

6454
static const struct snd_kcontrol_new rockchip_controls[] = {
6555
SOC_DAPM_PIN_SWITCH("Headphones"),
6656
SOC_DAPM_PIN_SWITCH("Speakers"),
6757
SOC_DAPM_PIN_SWITCH("Headset Mic"),
6858
SOC_DAPM_PIN_SWITCH("Int Mic"),
59+
SOC_DAPM_PIN_SWITCH("HDMI"),
6960
};
7061

7162
static int rockchip_sound_max98357a_hw_params(struct snd_pcm_substream *substream,
@@ -314,8 +305,6 @@ static struct snd_soc_card rockchip_sound_card = {
314305
.owner = THIS_MODULE,
315306
.dapm_widgets = rockchip_dapm_widgets,
316307
.num_dapm_widgets = ARRAY_SIZE(rockchip_dapm_widgets),
317-
.dapm_routes = rockchip_dapm_routes,
318-
.num_dapm_routes = ARRAY_SIZE(rockchip_dapm_routes),
319308
.controls = rockchip_controls,
320309
.num_controls = ARRAY_SIZE(rockchip_controls),
321310
};
@@ -329,15 +318,6 @@ enum {
329318
DAILINK_RT5514_DSP,
330319
};
331320

332-
static const char * const dailink_compat[] = {
333-
[DAILINK_CDNDP] = "rockchip,rk3399-cdn-dp",
334-
[DAILINK_DA7219] = "dlg,da7219",
335-
[DAILINK_DMIC] = "dmic-codec",
336-
[DAILINK_MAX98357A] = "maxim,max98357a",
337-
[DAILINK_RT5514] = "realtek,rt5514-i2c",
338-
[DAILINK_RT5514_DSP] = "realtek,rt5514-spi",
339-
};
340-
341321
static const struct snd_soc_dai_link rockchip_dais[] = {
342322
[DAILINK_CDNDP] = {
343323
.name = "DP",
@@ -391,13 +371,117 @@ static const struct snd_soc_dai_link rockchip_dais[] = {
391371
},
392372
};
393373

374+
static const struct snd_soc_dapm_route rockchip_sound_cdndp_routes[] = {
375+
/* Output */
376+
{"HDMI", NULL, "TX"},
377+
};
378+
379+
static const struct snd_soc_dapm_route rockchip_sound_da7219_routes[] = {
380+
/* Output */
381+
{"Headphones", NULL, "HPL"},
382+
{"Headphones", NULL, "HPR"},
383+
384+
/* Input */
385+
{"MIC", NULL, "Headset Mic"},
386+
};
387+
388+
static const struct snd_soc_dapm_route rockchip_sound_dmic_routes[] = {
389+
/* Input */
390+
{"DMic", NULL, "Int Mic"},
391+
};
392+
393+
static const struct snd_soc_dapm_route rockchip_sound_max98357a_routes[] = {
394+
/* Output */
395+
{"Speakers", NULL, "Speaker"},
396+
};
397+
398+
static const struct snd_soc_dapm_route rockchip_sound_rt5514_routes[] = {
399+
/* Input */
400+
{"DMIC1L", NULL, "Int Mic"},
401+
{"DMIC1R", NULL, "Int Mic"},
402+
};
403+
404+
struct rockchip_sound_route {
405+
const struct snd_soc_dapm_route *routes;
406+
int num_routes;
407+
};
408+
409+
static const struct rockchip_sound_route rockchip_routes[] = {
410+
[DAILINK_CDNDP] = {
411+
.routes = rockchip_sound_cdndp_routes,
412+
.num_routes = ARRAY_SIZE(rockchip_sound_cdndp_routes),
413+
},
414+
[DAILINK_DA7219] = {
415+
.routes = rockchip_sound_da7219_routes,
416+
.num_routes = ARRAY_SIZE(rockchip_sound_da7219_routes),
417+
},
418+
[DAILINK_DMIC] = {
419+
.routes = rockchip_sound_dmic_routes,
420+
.num_routes = ARRAY_SIZE(rockchip_sound_dmic_routes),
421+
},
422+
[DAILINK_MAX98357A] = {
423+
.routes = rockchip_sound_max98357a_routes,
424+
.num_routes = ARRAY_SIZE(rockchip_sound_max98357a_routes),
425+
},
426+
[DAILINK_RT5514] = {
427+
.routes = rockchip_sound_rt5514_routes,
428+
.num_routes = ARRAY_SIZE(rockchip_sound_rt5514_routes),
429+
},
430+
[DAILINK_RT5514_DSP] = {},
431+
};
432+
433+
struct dailink_match_data {
434+
const char *compatible;
435+
struct bus_type *bus_type;
436+
};
437+
438+
static const struct dailink_match_data dailink_match[] = {
439+
[DAILINK_CDNDP] = {
440+
.compatible = "rockchip,rk3399-cdn-dp",
441+
},
442+
[DAILINK_DA7219] = {
443+
.compatible = "dlg,da7219",
444+
},
445+
[DAILINK_DMIC] = {
446+
.compatible = "dmic-codec",
447+
},
448+
[DAILINK_MAX98357A] = {
449+
.compatible = "maxim,max98357a",
450+
},
451+
[DAILINK_RT5514] = {
452+
.compatible = "realtek,rt5514",
453+
.bus_type = &i2c_bus_type,
454+
},
455+
[DAILINK_RT5514_DSP] = {
456+
.compatible = "realtek,rt5514",
457+
.bus_type = &spi_bus_type,
458+
},
459+
};
460+
461+
static int of_dev_node_match(struct device *dev, void *data)
462+
{
463+
return dev->of_node == data;
464+
}
465+
394466
static int rockchip_sound_codec_node_match(struct device_node *np_codec)
395467
{
468+
struct device *dev;
396469
int i;
397470

398-
for (i = 0; i < ARRAY_SIZE(dailink_compat); i++) {
399-
if (of_device_is_compatible(np_codec, dailink_compat[i]))
400-
return i;
471+
for (i = 0; i < ARRAY_SIZE(dailink_match); i++) {
472+
if (!of_device_is_compatible(np_codec,
473+
dailink_match[i].compatible))
474+
continue;
475+
476+
if (dailink_match[i].bus_type) {
477+
dev = bus_find_device(dailink_match[i].bus_type, NULL,
478+
np_codec, of_dev_node_match);
479+
if (!dev)
480+
continue;
481+
put_device(dev);
482+
}
483+
484+
return i;
401485
}
402486
return -1;
403487
}
@@ -408,16 +492,28 @@ static int rockchip_sound_of_parse_dais(struct device *dev,
408492
struct device_node *np_cpu, *np_cpu0, *np_cpu1;
409493
struct device_node *np_codec;
410494
struct snd_soc_dai_link *dai;
495+
struct snd_soc_dapm_route *routes;
411496
int i, index;
497+
int num_routes;
412498

413499
card->dai_link = devm_kzalloc(dev, sizeof(rockchip_dais),
414500
GFP_KERNEL);
415501
if (!card->dai_link)
416502
return -ENOMEM;
417503

504+
num_routes = 0;
505+
for (i = 0; i < ARRAY_SIZE(rockchip_routes); i++)
506+
num_routes += rockchip_routes[i].num_routes;
507+
routes = devm_kzalloc(dev, num_routes * sizeof(*routes),
508+
GFP_KERNEL);
509+
if (!routes)
510+
return -ENOMEM;
511+
card->dapm_routes = routes;
512+
418513
np_cpu0 = of_parse_phandle(dev->of_node, "rockchip,cpu", 0);
419514
np_cpu1 = of_parse_phandle(dev->of_node, "rockchip,cpu", 1);
420515

516+
card->num_dapm_routes = 0;
421517
card->num_links = 0;
422518
for (i = 0; i < ARRAY_SIZE(rockchip_dais); i++) {
423519
np_codec = of_parse_phandle(dev->of_node,
@@ -445,6 +541,17 @@ static int rockchip_sound_of_parse_dais(struct device *dev,
445541
dai->codec_of_node = np_codec;
446542
dai->platform_of_node = np_cpu;
447543
dai->cpu_of_node = np_cpu;
544+
545+
if (card->num_dapm_routes + rockchip_routes[index].num_routes >
546+
num_routes) {
547+
dev_err(dev, "Too many routes\n");
548+
return -EINVAL;
549+
}
550+
551+
memcpy(routes + card->num_dapm_routes,
552+
rockchip_routes[index].routes,
553+
rockchip_routes[index].num_routes * sizeof(*routes));
554+
card->num_dapm_routes += rockchip_routes[index].num_routes;
448555
}
449556

450557
return 0;

0 commit comments

Comments
 (0)