]>
Commit | Line | Data |
---|---|---|
2874c5fd | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
74d04c3e TP |
2 | /* |
3 | * Copyright (C) 2014 Marvell | |
4 | * | |
5 | * Thomas Petazzoni <thomas.petazzoni@free-electrons.com> | |
74d04c3e TP |
6 | */ |
7 | ||
8 | #include <linux/module.h> | |
9 | #include <linux/moduleparam.h> | |
10 | #include <linux/interrupt.h> | |
11 | #include <linux/platform_device.h> | |
12 | #include <linux/slab.h> | |
13 | #include <sound/soc.h> | |
14 | #include <linux/of.h> | |
15 | #include <linux/platform_data/asoc-kirkwood.h> | |
16 | #include "../codecs/cs42l51.h" | |
17 | ||
18 | static int a370db_hw_params(struct snd_pcm_substream *substream, | |
19 | struct snd_pcm_hw_params *params) | |
20 | { | |
21 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | |
22 | struct snd_soc_dai *codec_dai = rtd->codec_dai; | |
23 | unsigned int freq; | |
24 | ||
25 | switch (params_rate(params)) { | |
26 | default: | |
27 | case 44100: | |
28 | freq = 11289600; | |
29 | break; | |
30 | case 48000: | |
31 | freq = 12288000; | |
32 | break; | |
33 | case 96000: | |
34 | freq = 24576000; | |
35 | break; | |
36 | } | |
37 | ||
38 | return snd_soc_dai_set_sysclk(codec_dai, 0, freq, SND_SOC_CLOCK_IN); | |
39 | } | |
40 | ||
9b6fdef6 | 41 | static const struct snd_soc_ops a370db_ops = { |
74d04c3e TP |
42 | .hw_params = a370db_hw_params, |
43 | }; | |
44 | ||
45 | static const struct snd_soc_dapm_widget a370db_dapm_widgets[] = { | |
46 | SND_SOC_DAPM_HP("Out Jack", NULL), | |
47 | SND_SOC_DAPM_LINE("In Jack", NULL), | |
48 | }; | |
49 | ||
50 | static const struct snd_soc_dapm_route a370db_route[] = { | |
51 | { "Out Jack", NULL, "HPL" }, | |
52 | { "Out Jack", NULL, "HPR" }, | |
53 | { "AIN1L", NULL, "In Jack" }, | |
54 | { "AIN1L", NULL, "In Jack" }, | |
55 | }; | |
56 | ||
57 | static struct snd_soc_dai_link a370db_dai[] = { | |
58 | { | |
59 | .name = "CS42L51", | |
60 | .stream_name = "analog", | |
61 | .cpu_dai_name = "i2s", | |
62 | .codec_dai_name = "cs42l51-hifi", | |
63 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBS_CFS, | |
64 | .ops = &a370db_ops, | |
65 | }, | |
cece5656 TP |
66 | { |
67 | .name = "S/PDIF out", | |
68 | .stream_name = "spdif-out", | |
69 | .cpu_dai_name = "spdif", | |
70 | .codec_dai_name = "dit-hifi", | |
71 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBS_CFS, | |
72 | }, | |
73 | { | |
74 | .name = "S/PDIF in", | |
75 | .stream_name = "spdif-in", | |
76 | .cpu_dai_name = "spdif", | |
77 | .codec_dai_name = "dir-hifi", | |
78 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBS_CFS, | |
79 | }, | |
74d04c3e TP |
80 | }; |
81 | ||
82 | static struct snd_soc_card a370db = { | |
83 | .name = "a370db", | |
84 | .owner = THIS_MODULE, | |
85 | .dai_link = a370db_dai, | |
86 | .num_links = ARRAY_SIZE(a370db_dai), | |
87 | .dapm_widgets = a370db_dapm_widgets, | |
88 | .num_dapm_widgets = ARRAY_SIZE(a370db_dapm_widgets), | |
89 | .dapm_routes = a370db_route, | |
90 | .num_dapm_routes = ARRAY_SIZE(a370db_route), | |
91 | }; | |
92 | ||
93 | static int a370db_probe(struct platform_device *pdev) | |
94 | { | |
95 | struct snd_soc_card *card = &a370db; | |
96 | ||
97 | card->dev = &pdev->dev; | |
98 | ||
99 | a370db_dai[0].cpu_of_node = | |
100 | of_parse_phandle(pdev->dev.of_node, | |
101 | "marvell,audio-controller", 0); | |
102 | a370db_dai[0].platform_of_node = a370db_dai[0].cpu_of_node; | |
103 | ||
104 | a370db_dai[0].codec_of_node = | |
105 | of_parse_phandle(pdev->dev.of_node, | |
106 | "marvell,audio-codec", 0); | |
107 | ||
cece5656 TP |
108 | a370db_dai[1].cpu_of_node = a370db_dai[0].cpu_of_node; |
109 | a370db_dai[1].platform_of_node = a370db_dai[0].cpu_of_node; | |
110 | ||
111 | a370db_dai[1].codec_of_node = | |
112 | of_parse_phandle(pdev->dev.of_node, | |
113 | "marvell,audio-codec", 1); | |
114 | ||
115 | a370db_dai[2].cpu_of_node = a370db_dai[0].cpu_of_node; | |
116 | a370db_dai[2].platform_of_node = a370db_dai[0].cpu_of_node; | |
117 | ||
118 | a370db_dai[2].codec_of_node = | |
119 | of_parse_phandle(pdev->dev.of_node, | |
120 | "marvell,audio-codec", 2); | |
121 | ||
74d04c3e TP |
122 | return devm_snd_soc_register_card(card->dev, card); |
123 | } | |
124 | ||
125 | static const struct of_device_id a370db_dt_ids[] = { | |
126 | { .compatible = "marvell,a370db-audio" }, | |
127 | { }, | |
128 | }; | |
30953a80 | 129 | MODULE_DEVICE_TABLE(of, a370db_dt_ids); |
74d04c3e TP |
130 | |
131 | static struct platform_driver a370db_driver = { | |
132 | .driver = { | |
133 | .name = "a370db-audio", | |
74d04c3e TP |
134 | .of_match_table = of_match_ptr(a370db_dt_ids), |
135 | }, | |
136 | .probe = a370db_probe, | |
137 | }; | |
138 | ||
139 | module_platform_driver(a370db_driver); | |
140 | ||
141 | MODULE_AUTHOR("Thomas Petazzoni <thomas.petazzoni@free-electrons.com>"); | |
142 | MODULE_DESCRIPTION("ALSA SoC a370db audio client"); | |
143 | MODULE_LICENSE("GPL"); | |
144 | MODULE_ALIAS("platform:a370db-audio"); |