Commit | Line | Data |
---|---|---|
ecf4630f AD |
1 | // SPDX-License-Identifier: GPL-2.0+ |
2 | // | |
3 | // eukrea-tlv320.c -- SoC audio for eukrea_cpuimxXX in I2S mode | |
4 | // | |
5 | // Copyright 2010 Eric Bénard, Eukréa Electromatique <eric@eukrea.com> | |
6 | // | |
7 | // based on sound/soc/s3c24xx/s3c24xx_simtec_tlv320aic23.c | |
8 | // which is Copyright 2009 Simtec Electronics | |
9 | // and on sound/soc/imx/phycore-ac97.c which is | |
10 | // Copyright 2009 Sascha Hauer, Pengutronix <s.hauer@pengutronix.de> | |
91157888 | 11 | |
66f23290 | 12 | #include <linux/errno.h> |
91157888 EB |
13 | #include <linux/module.h> |
14 | #include <linux/moduleparam.h> | |
66f23290 DC |
15 | #include <linux/of.h> |
16 | #include <linux/of_platform.h> | |
91157888 EB |
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> | |
91157888 EB |
22 | #include <asm/mach-types.h> |
23 | ||
24 | #include "../codecs/tlv320aic23.h" | |
25 | #include "imx-ssi.h" | |
3c77c29c | 26 | #include "imx-audmux.h" |
91157888 EB |
27 | |
28 | #define CODEC_CLOCK 12000000 | |
29 | ||
30 | static 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; | |
add330ec SH |
34 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
35 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; | |
91157888 EB |
36 | int ret; |
37 | ||
91157888 EB |
38 | ret = snd_soc_dai_set_sysclk(codec_dai, 0, |
39 | CODEC_CLOCK, SND_SOC_CLOCK_OUT); | |
40 | if (ret) { | |
154bab12 DC |
41 | dev_err(cpu_dai->dev, |
42 | "Failed to set the codec sysclk.\n"); | |
91157888 EB |
43 | return ret; |
44 | } | |
66f23290 | 45 | |
d0077aaf | 46 | snd_soc_dai_set_tdm_slot(cpu_dai, 0x3, 0x3, 2, 0); |
91157888 EB |
47 | |
48 | ret = snd_soc_dai_set_sysclk(cpu_dai, IMX_SSP_SYS_CLK, 0, | |
49 | SND_SOC_CLOCK_IN); | |
66f23290 DC |
50 | /* fsl_ssi lacks the set_sysclk ops */ |
51 | if (ret && ret != -EINVAL) { | |
154bab12 DC |
52 | dev_err(cpu_dai->dev, |
53 | "Can't set the IMX_SSP_SYS_CLK CPU system clock.\n"); | |
91157888 EB |
54 | return ret; |
55 | } | |
56 | ||
57 | return 0; | |
58 | } | |
59 | ||
5ace37bd | 60 | static const struct snd_soc_ops eukrea_tlv320_snd_ops = { |
91157888 EB |
61 | .hw_params = eukrea_tlv320_hw_params, |
62 | }; | |
63 | ||
64 | static struct snd_soc_dai_link eukrea_tlv320_dai = { | |
65 | .name = "tlv320aic23", | |
66 | .stream_name = "TLV320AIC23", | |
add330ec | 67 | .codec_dai_name = "tlv320aic23-hifi", |
4de59dbd LPC |
68 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | |
69 | SND_SOC_DAIFMT_CBM_CFM, | |
91157888 EB |
70 | .ops = &eukrea_tlv320_snd_ops, |
71 | }; | |
72 | ||
73 | static struct snd_soc_card eukrea_tlv320 = { | |
6aff8ccb | 74 | .owner = THIS_MODULE, |
91157888 EB |
75 | .dai_link = &eukrea_tlv320_dai, |
76 | .num_links = 1, | |
77 | }; | |
78 | ||
a0a3d518 | 79 | static int eukrea_tlv320_probe(struct platform_device *pdev) |
91157888 EB |
80 | { |
81 | int ret; | |
60282ede | 82 | int int_port = 0, ext_port; |
66f23290 | 83 | struct device_node *np = pdev->dev.of_node; |
077661b6 | 84 | struct device_node *ssi_np = NULL, *codec_np = NULL; |
60282ede | 85 | |
66f23290 DC |
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"); | |
b820d52e | 115 | goto err; |
66f23290 DC |
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"); | |
b820d52e | 121 | goto err; |
66f23290 DC |
122 | } |
123 | ||
124 | /* | |
125 | * The port numbering in the hardware manual starts at 1, while | |
126 | * the audmux API expects it starts at 0. | |
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")) { | |
af4872fb SG |
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) | |
60282ede | 151 | ); |
af4872fb SG |
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) | |
60282ede SG |
155 | ); |
156 | } else if (machine_is_eukrea_cpuimx25sd() || | |
157 | machine_is_eukrea_cpuimx35sd() || | |
66f23290 DC |
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 | ||
af4872fb SG |
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) | |
60282ede | 171 | ); |
af4872fb SG |
172 | imx_audmux_v2_configure_port(ext_port, |
173 | IMX_AUDMUX_V2_PTCR_SYN, | |
174 | IMX_AUDMUX_V2_PDCR_RXDSEL(int_port) | |
60282ede SG |
175 | ); |
176 | } else { | |
66f23290 | 177 | if (np) { |
dcfcf2c2 | 178 | /* The eukrea,asoc-tlv320 driver was explicitly |
66f23290 DC |
179 | * requested (through the device tree). |
180 | */ | |
181 | dev_err(&pdev->dev, | |
182 | "Missing or invalid audmux DT node.\n"); | |
183 | return -ENODEV; | |
184 | } else { | |
185 | /* Return happy. | |
186 | * We might run on a totally different machine. | |
187 | */ | |
188 | return 0; | |
189 | } | |
60282ede | 190 | } |
91157888 | 191 | |
da75c924 | 192 | ret = snd_soc_register_card(&eukrea_tlv320); |
66f23290 | 193 | err: |
da75c924 FE |
194 | if (ret) |
195 | dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret); | |
89dea487 | 196 | of_node_put(ssi_np); |
91157888 EB |
197 | |
198 | return ret; | |
199 | } | |
200 | ||
a0a3d518 | 201 | static int eukrea_tlv320_remove(struct platform_device *pdev) |
91157888 | 202 | { |
da75c924 FE |
203 | snd_soc_unregister_card(&eukrea_tlv320); |
204 | ||
205 | return 0; | |
91157888 EB |
206 | } |
207 | ||
66f23290 DC |
208 | static const struct of_device_id imx_tlv320_dt_ids[] = { |
209 | { .compatible = "eukrea,asoc-tlv320"}, | |
210 | { /* sentinel */ } | |
211 | }; | |
212 | MODULE_DEVICE_TABLE(of, imx_tlv320_dt_ids); | |
213 | ||
da75c924 FE |
214 | static struct platform_driver eukrea_tlv320_driver = { |
215 | .driver = { | |
216 | .name = "eukrea_tlv320", | |
66f23290 | 217 | .of_match_table = imx_tlv320_dt_ids, |
da75c924 FE |
218 | }, |
219 | .probe = eukrea_tlv320_probe, | |
154bab12 DC |
220 | .remove = eukrea_tlv320_remove, |
221 | }; | |
da75c924 FE |
222 | |
223 | module_platform_driver(eukrea_tlv320_driver); | |
91157888 EB |
224 | |
225 | MODULE_AUTHOR("Eric Bénard <eric@eukrea.com>"); | |
226 | MODULE_DESCRIPTION("CPUIMX ALSA SoC driver"); | |
227 | MODULE_LICENSE("GPL"); | |
da75c924 | 228 | MODULE_ALIAS("platform:eukrea_tlv320"); |