1
2
3
4
5
6
7
8
9
10
11
12#include <linux/errno.h>
13#include <linux/module.h>
14#include <linux/moduleparam.h>
15#include <linux/of.h>
16#include <linux/of_platform.h>
17#include <linux/device.h>
18#include <linux/i2c.h>
19#include <sound/core.h>
20#include <sound/pcm.h>
21#include <sound/soc.h>
22#include <asm/mach-types.h>
23
24#include "../codecs/tlv320aic23.h"
25#include "imx-ssi.h"
26#include "imx-audmux.h"
27
28#define CODEC_CLOCK 12000000
29
30static int eukrea_tlv320_hw_params(struct snd_pcm_substream *substream,
31 struct snd_pcm_hw_params *params)
32{
33 struct snd_soc_pcm_runtime *rtd = substream->private_data;
34 struct snd_soc_dai *codec_dai = rtd->codec_dai;
35 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
36 int ret;
37
38 ret = snd_soc_dai_set_sysclk(codec_dai, 0,
39 CODEC_CLOCK, SND_SOC_CLOCK_OUT);
40 if (ret) {
41 dev_err(cpu_dai->dev,
42 "Failed to set the codec sysclk.\n");
43 return ret;
44 }
45
46 snd_soc_dai_set_tdm_slot(cpu_dai, 0x3, 0x3, 2, 0);
47
48 ret = snd_soc_dai_set_sysclk(cpu_dai, IMX_SSP_SYS_CLK, 0,
49 SND_SOC_CLOCK_IN);
50
51 if (ret && ret != -EINVAL) {
52 dev_err(cpu_dai->dev,
53 "Can't set the IMX_SSP_SYS_CLK CPU system clock.\n");
54 return ret;
55 }
56
57 return 0;
58}
59
60static const struct snd_soc_ops eukrea_tlv320_snd_ops = {
61 .hw_params = eukrea_tlv320_hw_params,
62};
63
64static struct snd_soc_dai_link eukrea_tlv320_dai = {
65 .name = "tlv320aic23",
66 .stream_name = "TLV320AIC23",
67 .codec_dai_name = "tlv320aic23-hifi",
68 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
69 SND_SOC_DAIFMT_CBM_CFM,
70 .ops = &eukrea_tlv320_snd_ops,
71};
72
73static struct snd_soc_card eukrea_tlv320 = {
74 .owner = THIS_MODULE,
75 .dai_link = &eukrea_tlv320_dai,
76 .num_links = 1,
77};
78
79static int eukrea_tlv320_probe(struct platform_device *pdev)
80{
81 int ret;
82 int int_port = 0, ext_port;
83 struct device_node *np = pdev->dev.of_node;
84 struct device_node *ssi_np = NULL, *codec_np = NULL;
85
86 eukrea_tlv320.dev = &pdev->dev;
87 if (np) {
88 ret = snd_soc_of_parse_card_name(&eukrea_tlv320,
89 "eukrea,model");
90 if (ret) {
91 dev_err(&pdev->dev,
92 "eukrea,model node missing or invalid.\n");
93 goto err;
94 }
95
96 ssi_np = of_parse_phandle(pdev->dev.of_node,
97 "ssi-controller", 0);
98 if (!ssi_np) {
99 dev_err(&pdev->dev,
100 "ssi-controller missing or invalid.\n");
101 ret = -ENODEV;
102 goto err;
103 }
104
105 codec_np = of_parse_phandle(ssi_np, "codec-handle", 0);
106 if (codec_np)
107 eukrea_tlv320_dai.codec_of_node = codec_np;
108 else
109 dev_err(&pdev->dev, "codec-handle node missing or invalid.\n");
110
111 ret = of_property_read_u32(np, "fsl,mux-int-port", &int_port);
112 if (ret) {
113 dev_err(&pdev->dev,
114 "fsl,mux-int-port node missing or invalid.\n");
115 goto err;
116 }
117 ret = of_property_read_u32(np, "fsl,mux-ext-port", &ext_port);
118 if (ret) {
119 dev_err(&pdev->dev,
120 "fsl,mux-ext-port node missing or invalid.\n");
121 goto err;
122 }
123
124
125
126
127
128 int_port--;
129 ext_port--;
130
131 eukrea_tlv320_dai.cpu_of_node = ssi_np;
132 eukrea_tlv320_dai.platform_of_node = ssi_np;
133 } else {
134 eukrea_tlv320_dai.cpu_dai_name = "imx-ssi.0";
135 eukrea_tlv320_dai.platform_name = "imx-ssi.0";
136 eukrea_tlv320_dai.codec_name = "tlv320aic23-codec.0-001a";
137 eukrea_tlv320.name = "cpuimx-audio";
138 }
139
140 if (machine_is_eukrea_cpuimx27() ||
141 of_find_compatible_node(NULL, NULL, "fsl,imx21-audmux")) {
142 imx_audmux_v1_configure_port(MX27_AUDMUX_HPCR1_SSI0,
143 IMX_AUDMUX_V1_PCR_SYN |
144 IMX_AUDMUX_V1_PCR_TFSDIR |
145 IMX_AUDMUX_V1_PCR_TCLKDIR |
146 IMX_AUDMUX_V1_PCR_RFSDIR |
147 IMX_AUDMUX_V1_PCR_RCLKDIR |
148 IMX_AUDMUX_V1_PCR_TFCSEL(MX27_AUDMUX_HPCR3_SSI_PINS_4) |
149 IMX_AUDMUX_V1_PCR_RFCSEL(MX27_AUDMUX_HPCR3_SSI_PINS_4) |
150 IMX_AUDMUX_V1_PCR_RXDSEL(MX27_AUDMUX_HPCR3_SSI_PINS_4)
151 );
152 imx_audmux_v1_configure_port(MX27_AUDMUX_HPCR3_SSI_PINS_4,
153 IMX_AUDMUX_V1_PCR_SYN |
154 IMX_AUDMUX_V1_PCR_RXDSEL(MX27_AUDMUX_HPCR1_SSI0)
155 );
156 } else if (machine_is_eukrea_cpuimx25sd() ||
157 machine_is_eukrea_cpuimx35sd() ||
158 machine_is_eukrea_cpuimx51sd() ||
159 of_find_compatible_node(NULL, NULL, "fsl,imx31-audmux")) {
160 if (!np)
161 ext_port = machine_is_eukrea_cpuimx25sd() ?
162 4 : 3;
163
164 imx_audmux_v2_configure_port(int_port,
165 IMX_AUDMUX_V2_PTCR_SYN |
166 IMX_AUDMUX_V2_PTCR_TFSDIR |
167 IMX_AUDMUX_V2_PTCR_TFSEL(ext_port) |
168 IMX_AUDMUX_V2_PTCR_TCLKDIR |
169 IMX_AUDMUX_V2_PTCR_TCSEL(ext_port),
170 IMX_AUDMUX_V2_PDCR_RXDSEL(ext_port)
171 );
172 imx_audmux_v2_configure_port(ext_port,
173 IMX_AUDMUX_V2_PTCR_SYN,
174 IMX_AUDMUX_V2_PDCR_RXDSEL(int_port)
175 );
176 } else {
177 if (np) {
178
179
180
181 dev_err(&pdev->dev,
182 "Missing or invalid audmux DT node.\n");
183 return -ENODEV;
184 } else {
185
186
187
188 return 0;
189 }
190 }
191
192 ret = snd_soc_register_card(&eukrea_tlv320);
193err:
194 if (ret)
195 dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret);
196 of_node_put(ssi_np);
197
198 return ret;
199}
200
201static int eukrea_tlv320_remove(struct platform_device *pdev)
202{
203 snd_soc_unregister_card(&eukrea_tlv320);
204
205 return 0;
206}
207
208static const struct of_device_id imx_tlv320_dt_ids[] = {
209 { .compatible = "eukrea,asoc-tlv320"},
210 { }
211};
212MODULE_DEVICE_TABLE(of, imx_tlv320_dt_ids);
213
214static struct platform_driver eukrea_tlv320_driver = {
215 .driver = {
216 .name = "eukrea_tlv320",
217 .of_match_table = imx_tlv320_dt_ids,
218 },
219 .probe = eukrea_tlv320_probe,
220 .remove = eukrea_tlv320_remove,
221};
222
223module_platform_driver(eukrea_tlv320_driver);
224
225MODULE_AUTHOR("Eric Bénard <eric@eukrea.com>");
226MODULE_DESCRIPTION("CPUIMX ALSA SoC driver");
227MODULE_LICENSE("GPL");
228MODULE_ALIAS("platform:eukrea_tlv320");
229