xref: /openbmc/linux/sound/soc/fsl/eukrea-tlv320.c (revision 79f08d9e)
1 /*
2  * eukrea-tlv320.c  --  SoC audio for eukrea_cpuimxXX in I2S mode
3  *
4  * Copyright 2010 Eric Bénard, Eukréa Electromatique <eric@eukrea.com>
5  *
6  * based on sound/soc/s3c24xx/s3c24xx_simtec_tlv320aic23.c
7  * which is Copyright 2009 Simtec Electronics
8  * and on sound/soc/imx/phycore-ac97.c which is
9  * Copyright 2009 Sascha Hauer, Pengutronix <s.hauer@pengutronix.de>
10  *
11  *  This program is free software; you can redistribute  it and/or modify it
12  *  under  the terms of  the GNU General  Public License as published by the
13  *  Free Software Foundation;  either version 2 of the  License, or (at your
14  *  option) any later version.
15  *
16  */
17 
18 #include <linux/module.h>
19 #include <linux/moduleparam.h>
20 #include <linux/device.h>
21 #include <linux/i2c.h>
22 #include <sound/core.h>
23 #include <sound/pcm.h>
24 #include <sound/soc.h>
25 #include <asm/mach-types.h>
26 
27 #include "../codecs/tlv320aic23.h"
28 #include "imx-ssi.h"
29 #include "imx-audmux.h"
30 
31 #define CODEC_CLOCK 12000000
32 
33 static int eukrea_tlv320_hw_params(struct snd_pcm_substream *substream,
34 			    struct snd_pcm_hw_params *params)
35 {
36 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
37 	struct snd_soc_dai *codec_dai = rtd->codec_dai;
38 	struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
39 	int ret;
40 
41 	ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
42 				  SND_SOC_DAIFMT_NB_NF |
43 				  SND_SOC_DAIFMT_CBM_CFM);
44 	if (ret) {
45 		dev_err(cpu_dai->dev,
46 			"Failed to set the cpu dai format.\n");
47 		return ret;
48 	}
49 
50 	ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
51 				  SND_SOC_DAIFMT_NB_NF |
52 				  SND_SOC_DAIFMT_CBM_CFM);
53 	if (ret) {
54 		dev_err(cpu_dai->dev,
55 			"Failed to set the codec format.\n");
56 		return ret;
57 	}
58 
59 	ret = snd_soc_dai_set_sysclk(codec_dai, 0,
60 				     CODEC_CLOCK, SND_SOC_CLOCK_OUT);
61 	if (ret) {
62 		dev_err(cpu_dai->dev,
63 			"Failed to set the codec sysclk.\n");
64 		return ret;
65 	}
66 	snd_soc_dai_set_tdm_slot(cpu_dai, 0xffffffc, 0xffffffc, 2, 0);
67 
68 	ret = snd_soc_dai_set_sysclk(cpu_dai, IMX_SSP_SYS_CLK, 0,
69 				SND_SOC_CLOCK_IN);
70 	if (ret) {
71 		dev_err(cpu_dai->dev,
72 			"Can't set the IMX_SSP_SYS_CLK CPU system clock.\n");
73 		return ret;
74 	}
75 
76 	return 0;
77 }
78 
79 static struct snd_soc_ops eukrea_tlv320_snd_ops = {
80 	.hw_params	= eukrea_tlv320_hw_params,
81 };
82 
83 static struct snd_soc_dai_link eukrea_tlv320_dai = {
84 	.name		= "tlv320aic23",
85 	.stream_name	= "TLV320AIC23",
86 	.codec_dai_name	= "tlv320aic23-hifi",
87 	.platform_name	= "imx-ssi.0",
88 	.codec_name	= "tlv320aic23-codec.0-001a",
89 	.cpu_dai_name	= "imx-ssi.0",
90 	.ops		= &eukrea_tlv320_snd_ops,
91 };
92 
93 static struct snd_soc_card eukrea_tlv320 = {
94 	.name		= "cpuimx-audio",
95 	.owner		= THIS_MODULE,
96 	.dai_link	= &eukrea_tlv320_dai,
97 	.num_links	= 1,
98 };
99 
100 static int eukrea_tlv320_probe(struct platform_device *pdev)
101 {
102 	int ret;
103 	int int_port = 0, ext_port;
104 
105 	if (machine_is_eukrea_cpuimx27()) {
106 		imx_audmux_v1_configure_port(MX27_AUDMUX_HPCR1_SSI0,
107 			IMX_AUDMUX_V1_PCR_SYN |
108 			IMX_AUDMUX_V1_PCR_TFSDIR |
109 			IMX_AUDMUX_V1_PCR_TCLKDIR |
110 			IMX_AUDMUX_V1_PCR_RFSDIR |
111 			IMX_AUDMUX_V1_PCR_RCLKDIR |
112 			IMX_AUDMUX_V1_PCR_TFCSEL(MX27_AUDMUX_HPCR3_SSI_PINS_4) |
113 			IMX_AUDMUX_V1_PCR_RFCSEL(MX27_AUDMUX_HPCR3_SSI_PINS_4) |
114 			IMX_AUDMUX_V1_PCR_RXDSEL(MX27_AUDMUX_HPCR3_SSI_PINS_4)
115 		);
116 		imx_audmux_v1_configure_port(MX27_AUDMUX_HPCR3_SSI_PINS_4,
117 			IMX_AUDMUX_V1_PCR_SYN |
118 			IMX_AUDMUX_V1_PCR_RXDSEL(MX27_AUDMUX_HPCR1_SSI0)
119 		);
120 	} else if (machine_is_eukrea_cpuimx25sd() ||
121 		   machine_is_eukrea_cpuimx35sd() ||
122 		   machine_is_eukrea_cpuimx51sd()) {
123 		ext_port = machine_is_eukrea_cpuimx25sd() ? 4 : 3;
124 		imx_audmux_v2_configure_port(int_port,
125 			IMX_AUDMUX_V2_PTCR_SYN |
126 			IMX_AUDMUX_V2_PTCR_TFSDIR |
127 			IMX_AUDMUX_V2_PTCR_TFSEL(ext_port) |
128 			IMX_AUDMUX_V2_PTCR_TCLKDIR |
129 			IMX_AUDMUX_V2_PTCR_TCSEL(ext_port),
130 			IMX_AUDMUX_V2_PDCR_RXDSEL(ext_port)
131 		);
132 		imx_audmux_v2_configure_port(ext_port,
133 			IMX_AUDMUX_V2_PTCR_SYN,
134 			IMX_AUDMUX_V2_PDCR_RXDSEL(int_port)
135 		);
136 	} else {
137 		/* return happy. We might run on a totally different machine */
138 		return 0;
139 	}
140 
141 	eukrea_tlv320.dev = &pdev->dev;
142 	ret = snd_soc_register_card(&eukrea_tlv320);
143 	if (ret)
144 		dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret);
145 
146 	return ret;
147 }
148 
149 static int eukrea_tlv320_remove(struct platform_device *pdev)
150 {
151 	snd_soc_unregister_card(&eukrea_tlv320);
152 
153 	return 0;
154 }
155 
156 static struct platform_driver eukrea_tlv320_driver = {
157 	.driver = {
158 		.name = "eukrea_tlv320",
159 		.owner = THIS_MODULE,
160 	},
161 	.probe = eukrea_tlv320_probe,
162 	.remove = eukrea_tlv320_remove,
163 };
164 
165 module_platform_driver(eukrea_tlv320_driver);
166 
167 MODULE_AUTHOR("Eric Bénard <eric@eukrea.com>");
168 MODULE_DESCRIPTION("CPUIMX ALSA SoC driver");
169 MODULE_LICENSE("GPL");
170 MODULE_ALIAS("platform:eukrea_tlv320");
171