1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27#include <linux/module.h>
28#include <linux/of.h>
29#include <linux/platform_device.h>
30#include <linux/slab.h>
31
32#include <sound/core.h>
33#include <sound/jack.h>
34#include <sound/pcm.h>
35#include <sound/pcm_params.h>
36#include <sound/soc.h>
37
38#include "../codecs/tlv320aic23.h"
39
40#include "tegra_asoc_utils.h"
41
42#define DRV_NAME "tegra-snd-trimslice"
43
44struct tegra_trimslice {
45 struct tegra_asoc_utils_data util_data;
46};
47
48static int trimslice_asoc_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 *codec_dai = rtd->codec_dai;
53 struct snd_soc_codec *codec = codec_dai->codec;
54 struct snd_soc_card *card = codec->card;
55 struct tegra_trimslice *trimslice = snd_soc_card_get_drvdata(card);
56 int srate, mclk;
57 int err;
58
59 srate = params_rate(params);
60 mclk = 128 * srate;
61
62 err = tegra_asoc_utils_set_rate(&trimslice->util_data, srate, mclk);
63 if (err < 0) {
64 dev_err(card->dev, "Can't configure clocks\n");
65 return err;
66 }
67
68 err = snd_soc_dai_set_sysclk(codec_dai, 0, mclk,
69 SND_SOC_CLOCK_IN);
70 if (err < 0) {
71 dev_err(card->dev, "codec_dai clock not set\n");
72 return err;
73 }
74
75 return 0;
76}
77
78static struct snd_soc_ops trimslice_asoc_ops = {
79 .hw_params = trimslice_asoc_hw_params,
80};
81
82static const struct snd_soc_dapm_widget trimslice_dapm_widgets[] = {
83 SND_SOC_DAPM_HP("Line Out", NULL),
84 SND_SOC_DAPM_LINE("Line In", NULL),
85};
86
87static const struct snd_soc_dapm_route trimslice_audio_map[] = {
88 {"Line Out", NULL, "LOUT"},
89 {"Line Out", NULL, "ROUT"},
90
91 {"LLINEIN", NULL, "Line In"},
92 {"RLINEIN", NULL, "Line In"},
93};
94
95static struct snd_soc_dai_link trimslice_tlv320aic23_dai = {
96 .name = "TLV320AIC23",
97 .stream_name = "AIC23",
98 .codec_dai_name = "tlv320aic23-hifi",
99 .ops = &trimslice_asoc_ops,
100 .dai_fmt = SND_SOC_DAIFMT_I2S |
101 SND_SOC_DAIFMT_NB_NF |
102 SND_SOC_DAIFMT_CBS_CFS,
103};
104
105static struct snd_soc_card snd_soc_trimslice = {
106 .name = "tegra-trimslice",
107 .owner = THIS_MODULE,
108 .dai_link = &trimslice_tlv320aic23_dai,
109 .num_links = 1,
110
111 .dapm_widgets = trimslice_dapm_widgets,
112 .num_dapm_widgets = ARRAY_SIZE(trimslice_dapm_widgets),
113 .dapm_routes = trimslice_audio_map,
114 .num_dapm_routes = ARRAY_SIZE(trimslice_audio_map),
115 .fully_routed = true,
116};
117
118static int tegra_snd_trimslice_probe(struct platform_device *pdev)
119{
120 struct device_node *np = pdev->dev.of_node;
121 struct snd_soc_card *card = &snd_soc_trimslice;
122 struct tegra_trimslice *trimslice;
123 int ret;
124
125 trimslice = devm_kzalloc(&pdev->dev, sizeof(struct tegra_trimslice),
126 GFP_KERNEL);
127 if (!trimslice) {
128 dev_err(&pdev->dev, "Can't allocate tegra_trimslice\n");
129 return -ENOMEM;
130 }
131
132 card->dev = &pdev->dev;
133 platform_set_drvdata(pdev, card);
134 snd_soc_card_set_drvdata(card, trimslice);
135
136 trimslice_tlv320aic23_dai.codec_of_node = of_parse_phandle(np,
137 "nvidia,audio-codec", 0);
138 if (!trimslice_tlv320aic23_dai.codec_of_node) {
139 dev_err(&pdev->dev,
140 "Property 'nvidia,audio-codec' missing or invalid\n");
141 ret = -EINVAL;
142 goto err;
143 }
144
145 trimslice_tlv320aic23_dai.cpu_of_node = of_parse_phandle(np,
146 "nvidia,i2s-controller", 0);
147 if (!trimslice_tlv320aic23_dai.cpu_of_node) {
148 dev_err(&pdev->dev,
149 "Property 'nvidia,i2s-controller' missing or invalid\n");
150 ret = -EINVAL;
151 goto err;
152 }
153
154 trimslice_tlv320aic23_dai.platform_of_node =
155 trimslice_tlv320aic23_dai.cpu_of_node;
156
157 ret = tegra_asoc_utils_init(&trimslice->util_data, &pdev->dev);
158 if (ret)
159 goto err;
160
161 ret = snd_soc_register_card(card);
162 if (ret) {
163 dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n",
164 ret);
165 goto err_fini_utils;
166 }
167
168 return 0;
169
170err_fini_utils:
171 tegra_asoc_utils_fini(&trimslice->util_data);
172err:
173 return ret;
174}
175
176static int tegra_snd_trimslice_remove(struct platform_device *pdev)
177{
178 struct snd_soc_card *card = platform_get_drvdata(pdev);
179 struct tegra_trimslice *trimslice = snd_soc_card_get_drvdata(card);
180
181 snd_soc_unregister_card(card);
182
183 tegra_asoc_utils_fini(&trimslice->util_data);
184
185 return 0;
186}
187
188static const struct of_device_id trimslice_of_match[] = {
189 { .compatible = "nvidia,tegra-audio-trimslice", },
190 {},
191};
192MODULE_DEVICE_TABLE(of, trimslice_of_match);
193
194static struct platform_driver tegra_snd_trimslice_driver = {
195 .driver = {
196 .name = DRV_NAME,
197 .owner = THIS_MODULE,
198 .of_match_table = trimslice_of_match,
199 },
200 .probe = tegra_snd_trimslice_probe,
201 .remove = tegra_snd_trimslice_remove,
202};
203module_platform_driver(tegra_snd_trimslice_driver);
204
205MODULE_AUTHOR("Mike Rapoport <mike@compulab.co.il>");
206MODULE_DESCRIPTION("Trimslice machine ASoC driver");
207MODULE_LICENSE("GPL");
208MODULE_ALIAS("platform:" DRV_NAME);
209