1 // SPDX-License-Identifier: GPL-2.0+
3 // eukrea-tlv320.c -- SoC audio for eukrea_cpuimxXX in I2S mode
5 // Copyright 2010 Eric Bénard, Eukréa Electromatique <eric@eukrea.com>
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>
12 #include <linux/errno.h>
13 #include <linux/module.h>
14 #include <linux/moduleparam.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>
24 #include "../codecs/tlv320aic23.h"
26 #include "imx-audmux.h"
28 #define CODEC_CLOCK 12000000
30 static int eukrea_tlv320_hw_params(struct snd_pcm_substream
*substream
,
31 struct snd_pcm_hw_params
*params
)
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
;
38 ret
= snd_soc_dai_set_sysclk(codec_dai
, 0,
39 CODEC_CLOCK
, SND_SOC_CLOCK_OUT
);
42 "Failed to set the codec sysclk.\n");
46 snd_soc_dai_set_tdm_slot(cpu_dai
, 0x3, 0x3, 2, 0);
48 ret
= snd_soc_dai_set_sysclk(cpu_dai
, IMX_SSP_SYS_CLK
, 0,
50 /* fsl_ssi lacks the set_sysclk ops */
51 if (ret
&& ret
!= -EINVAL
) {
53 "Can't set the IMX_SSP_SYS_CLK CPU system clock.\n");
60 static const struct snd_soc_ops eukrea_tlv320_snd_ops
= {
61 .hw_params
= eukrea_tlv320_hw_params
,
64 SND_SOC_DAILINK_DEFS(hifi
,
65 DAILINK_COMP_ARRAY(COMP_EMPTY()),
66 DAILINK_COMP_ARRAY(COMP_CODEC(NULL
, "tlv320aic23-hifi")),
67 DAILINK_COMP_ARRAY(COMP_EMPTY()));
69 static struct snd_soc_dai_link eukrea_tlv320_dai
= {
70 .name
= "tlv320aic23",
71 .stream_name
= "TLV320AIC23",
72 .dai_fmt
= SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_NB_NF
|
73 SND_SOC_DAIFMT_CBM_CFM
,
74 .ops
= &eukrea_tlv320_snd_ops
,
75 SND_SOC_DAILINK_REG(hifi
),
78 static struct snd_soc_card eukrea_tlv320
= {
80 .dai_link
= &eukrea_tlv320_dai
,
84 static int eukrea_tlv320_probe(struct platform_device
*pdev
)
87 int int_port
= 0, ext_port
;
88 struct device_node
*np
= pdev
->dev
.of_node
;
89 struct device_node
*ssi_np
= NULL
, *codec_np
= NULL
;
91 eukrea_tlv320
.dev
= &pdev
->dev
;
93 ret
= snd_soc_of_parse_card_name(&eukrea_tlv320
,
97 "eukrea,model node missing or invalid.\n");
101 ssi_np
= of_parse_phandle(pdev
->dev
.of_node
,
102 "ssi-controller", 0);
105 "ssi-controller missing or invalid.\n");
110 codec_np
= of_parse_phandle(ssi_np
, "codec-handle", 0);
112 eukrea_tlv320_dai
.codecs
->of_node
= codec_np
;
114 dev_err(&pdev
->dev
, "codec-handle node missing or invalid.\n");
116 ret
= of_property_read_u32(np
, "fsl,mux-int-port", &int_port
);
119 "fsl,mux-int-port node missing or invalid.\n");
122 ret
= of_property_read_u32(np
, "fsl,mux-ext-port", &ext_port
);
125 "fsl,mux-ext-port node missing or invalid.\n");
130 * The port numbering in the hardware manual starts at 1, while
131 * the audmux API expects it starts at 0.
136 eukrea_tlv320_dai
.cpus
->of_node
= ssi_np
;
137 eukrea_tlv320_dai
.platforms
->of_node
= ssi_np
;
139 eukrea_tlv320_dai
.cpus
->dai_name
= "imx-ssi.0";
140 eukrea_tlv320_dai
.platforms
->name
= "imx-ssi.0";
141 eukrea_tlv320_dai
.codecs
->name
= "tlv320aic23-codec.0-001a";
142 eukrea_tlv320
.name
= "cpuimx-audio";
145 if (machine_is_eukrea_cpuimx27() ||
146 of_find_compatible_node(NULL
, NULL
, "fsl,imx21-audmux")) {
147 imx_audmux_v1_configure_port(MX27_AUDMUX_HPCR1_SSI0
,
148 IMX_AUDMUX_V1_PCR_SYN
|
149 IMX_AUDMUX_V1_PCR_TFSDIR
|
150 IMX_AUDMUX_V1_PCR_TCLKDIR
|
151 IMX_AUDMUX_V1_PCR_RFSDIR
|
152 IMX_AUDMUX_V1_PCR_RCLKDIR
|
153 IMX_AUDMUX_V1_PCR_TFCSEL(MX27_AUDMUX_HPCR3_SSI_PINS_4
) |
154 IMX_AUDMUX_V1_PCR_RFCSEL(MX27_AUDMUX_HPCR3_SSI_PINS_4
) |
155 IMX_AUDMUX_V1_PCR_RXDSEL(MX27_AUDMUX_HPCR3_SSI_PINS_4
)
157 imx_audmux_v1_configure_port(MX27_AUDMUX_HPCR3_SSI_PINS_4
,
158 IMX_AUDMUX_V1_PCR_SYN
|
159 IMX_AUDMUX_V1_PCR_RXDSEL(MX27_AUDMUX_HPCR1_SSI0
)
161 } else if (machine_is_eukrea_cpuimx25sd() ||
162 machine_is_eukrea_cpuimx35sd() ||
163 machine_is_eukrea_cpuimx51sd() ||
164 of_find_compatible_node(NULL
, NULL
, "fsl,imx31-audmux")) {
166 ext_port
= machine_is_eukrea_cpuimx25sd() ?
169 imx_audmux_v2_configure_port(int_port
,
170 IMX_AUDMUX_V2_PTCR_SYN
|
171 IMX_AUDMUX_V2_PTCR_TFSDIR
|
172 IMX_AUDMUX_V2_PTCR_TFSEL(ext_port
) |
173 IMX_AUDMUX_V2_PTCR_TCLKDIR
|
174 IMX_AUDMUX_V2_PTCR_TCSEL(ext_port
),
175 IMX_AUDMUX_V2_PDCR_RXDSEL(ext_port
)
177 imx_audmux_v2_configure_port(ext_port
,
178 IMX_AUDMUX_V2_PTCR_SYN
,
179 IMX_AUDMUX_V2_PDCR_RXDSEL(int_port
)
183 /* The eukrea,asoc-tlv320 driver was explicitly
184 * requested (through the device tree).
187 "Missing or invalid audmux DT node.\n");
191 * We might run on a totally different machine.
197 ret
= snd_soc_register_card(&eukrea_tlv320
);
200 dev_err(&pdev
->dev
, "snd_soc_register_card failed (%d)\n", ret
);
206 static int eukrea_tlv320_remove(struct platform_device
*pdev
)
208 snd_soc_unregister_card(&eukrea_tlv320
);
213 static const struct of_device_id imx_tlv320_dt_ids
[] = {
214 { .compatible
= "eukrea,asoc-tlv320"},
217 MODULE_DEVICE_TABLE(of
, imx_tlv320_dt_ids
);
219 static struct platform_driver eukrea_tlv320_driver
= {
221 .name
= "eukrea_tlv320",
222 .of_match_table
= imx_tlv320_dt_ids
,
224 .probe
= eukrea_tlv320_probe
,
225 .remove
= eukrea_tlv320_remove
,
228 module_platform_driver(eukrea_tlv320_driver
);
230 MODULE_AUTHOR("Eric Bénard <eric@eukrea.com>");
231 MODULE_DESCRIPTION("CPUIMX ALSA SoC driver");
232 MODULE_LICENSE("GPL");
233 MODULE_ALIAS("platform:eukrea_tlv320");