2 * Copyright (C) 2014 Marvell
4 * Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
12 #include <linux/module.h>
13 #include <linux/moduleparam.h>
14 #include <linux/interrupt.h>
15 #include <linux/platform_device.h>
16 #include <linux/slab.h>
17 #include <sound/soc.h>
19 #include <linux/platform_data/asoc-kirkwood.h>
20 #include "../codecs/cs42l51.h"
22 static int a370db_hw_params(struct snd_pcm_substream *substream,
23 struct snd_pcm_hw_params *params)
25 struct snd_soc_pcm_runtime *rtd = substream->private_data;
26 struct snd_soc_dai *codec_dai = rtd->codec_dai;
29 switch (params_rate(params)) {
42 return snd_soc_dai_set_sysclk(codec_dai, 0, freq, SND_SOC_CLOCK_IN);
45 static const struct snd_soc_ops a370db_ops = {
46 .hw_params = a370db_hw_params,
49 static const struct snd_soc_dapm_widget a370db_dapm_widgets[] = {
50 SND_SOC_DAPM_HP("Out Jack", NULL),
51 SND_SOC_DAPM_LINE("In Jack", NULL),
54 static const struct snd_soc_dapm_route a370db_route[] = {
55 { "Out Jack", NULL, "HPL" },
56 { "Out Jack", NULL, "HPR" },
57 { "AIN1L", NULL, "In Jack" },
58 { "AIN1L", NULL, "In Jack" },
61 SND_SOC_DAILINK_DEFS(analog,
62 DAILINK_COMP_ARRAY(COMP_CPU("i2s")),
63 DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "cs42l51-hifi")),
64 DAILINK_COMP_ARRAY(COMP_EMPTY()));
66 SND_SOC_DAILINK_DEFS(spdif_out,
67 DAILINK_COMP_ARRAY(COMP_CPU("spdif")),
68 DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "dit-hifi")),
69 DAILINK_COMP_ARRAY(COMP_EMPTY()));
71 SND_SOC_DAILINK_DEFS(spdif_in,
72 DAILINK_COMP_ARRAY(COMP_CPU("spdif")),
73 DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "dir-hifi")),
74 DAILINK_COMP_ARRAY(COMP_EMPTY()));
76 static struct snd_soc_dai_link a370db_dai[] = {
79 .stream_name = "analog",
80 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBS_CFS,
82 SND_SOC_DAILINK_REG(analog),
86 .stream_name = "spdif-out",
87 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBS_CFS,
88 SND_SOC_DAILINK_REG(spdif_out),
92 .stream_name = "spdif-in",
93 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBS_CFS,
94 SND_SOC_DAILINK_REG(spdif_in),
98 static struct snd_soc_card a370db = {
100 .owner = THIS_MODULE,
101 .dai_link = a370db_dai,
102 .num_links = ARRAY_SIZE(a370db_dai),
103 .dapm_widgets = a370db_dapm_widgets,
104 .num_dapm_widgets = ARRAY_SIZE(a370db_dapm_widgets),
105 .dapm_routes = a370db_route,
106 .num_dapm_routes = ARRAY_SIZE(a370db_route),
109 static int a370db_probe(struct platform_device *pdev)
111 struct snd_soc_card *card = &a370db;
113 card->dev = &pdev->dev;
115 a370db_dai[0].cpus->of_node =
116 of_parse_phandle(pdev->dev.of_node,
117 "marvell,audio-controller", 0);
118 a370db_dai[0].platforms->of_node = a370db_dai[0].cpus->of_node;
120 a370db_dai[0].codecs->of_node =
121 of_parse_phandle(pdev->dev.of_node,
122 "marvell,audio-codec", 0);
124 a370db_dai[1].cpus->of_node = a370db_dai[0].cpus->of_node;
125 a370db_dai[1].platforms->of_node = a370db_dai[0].cpus->of_node;
127 a370db_dai[1].codecs->of_node =
128 of_parse_phandle(pdev->dev.of_node,
129 "marvell,audio-codec", 1);
131 a370db_dai[2].cpus->of_node = a370db_dai[0].cpus->of_node;
132 a370db_dai[2].platforms->of_node = a370db_dai[0].cpus->of_node;
134 a370db_dai[2].codecs->of_node =
135 of_parse_phandle(pdev->dev.of_node,
136 "marvell,audio-codec", 2);
138 return devm_snd_soc_register_card(card->dev, card);
141 static const struct of_device_id a370db_dt_ids[] = {
142 { .compatible = "marvell,a370db-audio" },
145 MODULE_DEVICE_TABLE(of, a370db_dt_ids);
147 static struct platform_driver a370db_driver = {
149 .name = "a370db-audio",
150 .of_match_table = of_match_ptr(a370db_dt_ids),
152 .probe = a370db_probe,
155 module_platform_driver(a370db_driver);
157 MODULE_AUTHOR("Thomas Petazzoni <thomas.petazzoni@free-electrons.com>");
158 MODULE_DESCRIPTION("ALSA SoC a370db audio client");
159 MODULE_LICENSE("GPL");
160 MODULE_ALIAS("platform:a370db-audio");