0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #include <linux/errno.h>
0013 #include <linux/module.h>
0014 #include <linux/moduleparam.h>
0015 #include <linux/of.h>
0016 #include <linux/of_platform.h>
0017 #include <linux/device.h>
0018 #include <linux/i2c.h>
0019 #include <sound/core.h>
0020 #include <sound/pcm.h>
0021 #include <sound/soc.h>
0022 #include <asm/mach-types.h>
0023
0024 #include "../codecs/tlv320aic23.h"
0025 #include "imx-ssi.h"
0026 #include "imx-audmux.h"
0027
0028 #define CODEC_CLOCK 12000000
0029
0030 static int eukrea_tlv320_hw_params(struct snd_pcm_substream *substream,
0031 struct snd_pcm_hw_params *params)
0032 {
0033 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
0034 struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
0035 struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
0036 int ret;
0037
0038 ret = snd_soc_dai_set_sysclk(codec_dai, 0,
0039 CODEC_CLOCK, SND_SOC_CLOCK_OUT);
0040 if (ret) {
0041 dev_err(cpu_dai->dev,
0042 "Failed to set the codec sysclk.\n");
0043 return ret;
0044 }
0045
0046 snd_soc_dai_set_tdm_slot(cpu_dai, 0x3, 0x3, 2, 0);
0047
0048 ret = snd_soc_dai_set_sysclk(cpu_dai, IMX_SSP_SYS_CLK, 0,
0049 SND_SOC_CLOCK_IN);
0050
0051 if (ret && ret != -EINVAL) {
0052 dev_err(cpu_dai->dev,
0053 "Can't set the IMX_SSP_SYS_CLK CPU system clock.\n");
0054 return ret;
0055 }
0056
0057 return 0;
0058 }
0059
0060 static const struct snd_soc_ops eukrea_tlv320_snd_ops = {
0061 .hw_params = eukrea_tlv320_hw_params,
0062 };
0063
0064 SND_SOC_DAILINK_DEFS(hifi,
0065 DAILINK_COMP_ARRAY(COMP_EMPTY()),
0066 DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "tlv320aic23-hifi")),
0067 DAILINK_COMP_ARRAY(COMP_EMPTY()));
0068
0069 static struct snd_soc_dai_link eukrea_tlv320_dai = {
0070 .name = "tlv320aic23",
0071 .stream_name = "TLV320AIC23",
0072 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
0073 SND_SOC_DAIFMT_CBP_CFP,
0074 .ops = &eukrea_tlv320_snd_ops,
0075 SND_SOC_DAILINK_REG(hifi),
0076 };
0077
0078 static struct snd_soc_card eukrea_tlv320 = {
0079 .owner = THIS_MODULE,
0080 .dai_link = &eukrea_tlv320_dai,
0081 .num_links = 1,
0082 };
0083
0084 static int eukrea_tlv320_probe(struct platform_device *pdev)
0085 {
0086 int ret;
0087 int int_port = 0, ext_port;
0088 struct device_node *np = pdev->dev.of_node;
0089 struct device_node *ssi_np = NULL, *codec_np = NULL;
0090
0091 eukrea_tlv320.dev = &pdev->dev;
0092 if (np) {
0093 ret = snd_soc_of_parse_card_name(&eukrea_tlv320,
0094 "eukrea,model");
0095 if (ret) {
0096 dev_err(&pdev->dev,
0097 "eukrea,model node missing or invalid.\n");
0098 goto err;
0099 }
0100
0101 ssi_np = of_parse_phandle(pdev->dev.of_node,
0102 "ssi-controller", 0);
0103 if (!ssi_np) {
0104 dev_err(&pdev->dev,
0105 "ssi-controller missing or invalid.\n");
0106 ret = -ENODEV;
0107 goto err;
0108 }
0109
0110 codec_np = of_parse_phandle(ssi_np, "codec-handle", 0);
0111 if (codec_np)
0112 eukrea_tlv320_dai.codecs->of_node = codec_np;
0113 else
0114 dev_err(&pdev->dev, "codec-handle node missing or invalid.\n");
0115
0116 ret = of_property_read_u32(np, "fsl,mux-int-port", &int_port);
0117 if (ret) {
0118 dev_err(&pdev->dev,
0119 "fsl,mux-int-port node missing or invalid.\n");
0120 goto err;
0121 }
0122 ret = of_property_read_u32(np, "fsl,mux-ext-port", &ext_port);
0123 if (ret) {
0124 dev_err(&pdev->dev,
0125 "fsl,mux-ext-port node missing or invalid.\n");
0126 goto err;
0127 }
0128
0129
0130
0131
0132
0133 int_port--;
0134 ext_port--;
0135
0136 eukrea_tlv320_dai.cpus->of_node = ssi_np;
0137 eukrea_tlv320_dai.platforms->of_node = ssi_np;
0138 } else {
0139 eukrea_tlv320_dai.cpus->dai_name = "imx-ssi.0";
0140 eukrea_tlv320_dai.platforms->name = "imx-ssi.0";
0141 eukrea_tlv320_dai.codecs->name = "tlv320aic23-codec.0-001a";
0142 eukrea_tlv320.name = "cpuimx-audio";
0143 }
0144
0145 if (machine_is_eukrea_cpuimx27() ||
0146 of_find_compatible_node(NULL, NULL, "fsl,imx21-audmux")) {
0147 imx_audmux_v1_configure_port(MX27_AUDMUX_HPCR1_SSI0,
0148 IMX_AUDMUX_V1_PCR_SYN |
0149 IMX_AUDMUX_V1_PCR_TFSDIR |
0150 IMX_AUDMUX_V1_PCR_TCLKDIR |
0151 IMX_AUDMUX_V1_PCR_RFSDIR |
0152 IMX_AUDMUX_V1_PCR_RCLKDIR |
0153 IMX_AUDMUX_V1_PCR_TFCSEL(MX27_AUDMUX_HPCR3_SSI_PINS_4) |
0154 IMX_AUDMUX_V1_PCR_RFCSEL(MX27_AUDMUX_HPCR3_SSI_PINS_4) |
0155 IMX_AUDMUX_V1_PCR_RXDSEL(MX27_AUDMUX_HPCR3_SSI_PINS_4)
0156 );
0157 imx_audmux_v1_configure_port(MX27_AUDMUX_HPCR3_SSI_PINS_4,
0158 IMX_AUDMUX_V1_PCR_SYN |
0159 IMX_AUDMUX_V1_PCR_RXDSEL(MX27_AUDMUX_HPCR1_SSI0)
0160 );
0161 } else if (machine_is_eukrea_cpuimx25sd() ||
0162 machine_is_eukrea_cpuimx35sd() ||
0163 machine_is_eukrea_cpuimx51sd() ||
0164 of_find_compatible_node(NULL, NULL, "fsl,imx31-audmux")) {
0165 if (!np)
0166 ext_port = machine_is_eukrea_cpuimx25sd() ?
0167 4 : 3;
0168
0169 imx_audmux_v2_configure_port(int_port,
0170 IMX_AUDMUX_V2_PTCR_SYN |
0171 IMX_AUDMUX_V2_PTCR_TFSDIR |
0172 IMX_AUDMUX_V2_PTCR_TFSEL(ext_port) |
0173 IMX_AUDMUX_V2_PTCR_TCLKDIR |
0174 IMX_AUDMUX_V2_PTCR_TCSEL(ext_port),
0175 IMX_AUDMUX_V2_PDCR_RXDSEL(ext_port)
0176 );
0177 imx_audmux_v2_configure_port(ext_port,
0178 IMX_AUDMUX_V2_PTCR_SYN,
0179 IMX_AUDMUX_V2_PDCR_RXDSEL(int_port)
0180 );
0181 } else {
0182 if (np) {
0183
0184
0185
0186 dev_err(&pdev->dev,
0187 "Missing or invalid audmux DT node.\n");
0188 return -ENODEV;
0189 } else {
0190
0191
0192
0193 return 0;
0194 }
0195 }
0196
0197 ret = snd_soc_register_card(&eukrea_tlv320);
0198 err:
0199 if (ret)
0200 dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret);
0201 of_node_put(ssi_np);
0202
0203 return ret;
0204 }
0205
0206 static int eukrea_tlv320_remove(struct platform_device *pdev)
0207 {
0208 snd_soc_unregister_card(&eukrea_tlv320);
0209
0210 return 0;
0211 }
0212
0213 static const struct of_device_id imx_tlv320_dt_ids[] = {
0214 { .compatible = "eukrea,asoc-tlv320"},
0215 { }
0216 };
0217 MODULE_DEVICE_TABLE(of, imx_tlv320_dt_ids);
0218
0219 static struct platform_driver eukrea_tlv320_driver = {
0220 .driver = {
0221 .name = "eukrea_tlv320",
0222 .of_match_table = imx_tlv320_dt_ids,
0223 },
0224 .probe = eukrea_tlv320_probe,
0225 .remove = eukrea_tlv320_remove,
0226 };
0227
0228 module_platform_driver(eukrea_tlv320_driver);
0229
0230 MODULE_AUTHOR("Eric Bénard <eric@eukrea.com>");
0231 MODULE_DESCRIPTION("CPUIMX ALSA SoC driver");
0232 MODULE_LICENSE("GPL");
0233 MODULE_ALIAS("platform:eukrea_tlv320");