blob: 771bff27ac3e4809e3ae38d75c9d22b648375247 [file] [log] [blame]
Lopez Cruz, Misaeldf205932009-06-11 17:35:27 -05001/*
2 * zoom2.c -- SoC audio for Zoom2
3 *
4 * Author: Misael Lopez Cruz <x0052729@ti.com>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * version 2 as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18 * 02110-1301 USA
19 *
20 */
21
22#include <linux/clk.h>
23#include <linux/platform_device.h>
Tony Lindgren257d36f2012-10-03 09:31:02 -070024#include <linux/gpio.h>
Lopez Cruz, Misaeldf205932009-06-11 17:35:27 -050025#include <sound/core.h>
26#include <sound/pcm.h>
27#include <sound/soc.h>
Lopez Cruz, Misaeldf205932009-06-11 17:35:27 -050028
29#include <asm/mach-types.h>
Arnd Bergmann22037472012-08-24 15:21:06 +020030#include <linux/platform_data/asoc-ti-mcbsp.h>
Tony Lindgren257d36f2012-10-03 09:31:02 -070031#include <linux/platform_data/gpio-omap.h>
Lopez Cruz, Misaeldf205932009-06-11 17:35:27 -050032
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000033/* Register descriptions for twl4030 codec part */
Peter Ujfalusi57fe7252011-05-31 12:02:49 +030034#include <linux/mfd/twl4030-audio.h>
Paul Gortmakerda155d52011-07-15 12:38:28 -040035#include <linux/module.h>
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000036
Lopez Cruz, Misaeldf205932009-06-11 17:35:27 -050037#include "omap-mcbsp.h"
38#include "omap-pcm.h"
Lopez Cruz, Misaeldf205932009-06-11 17:35:27 -050039
Lopez Cruz, Misaeldf205932009-06-11 17:35:27 -050040static int zoom2_hw_params(struct snd_pcm_substream *substream,
41 struct snd_pcm_hw_params *params)
42{
43 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000044 struct snd_soc_dai *codec_dai = rtd->codec_dai;
Lopez Cruz, Misaeldf205932009-06-11 17:35:27 -050045 int ret;
46
Lopez Cruz, Misaeldf205932009-06-11 17:35:27 -050047 /* Set the codec system clock for DAC and ADC */
48 ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000,
49 SND_SOC_CLOCK_IN);
50 if (ret < 0) {
51 printk(KERN_ERR "can't set codec system clock\n");
52 return ret;
53 }
54
55 return 0;
56}
57
58static struct snd_soc_ops zoom2_ops = {
59 .hw_params = zoom2_hw_params,
60};
61
Lopez Cruz, Misaeldf205932009-06-11 17:35:27 -050062/* Zoom2 machine DAPM */
63static const struct snd_soc_dapm_widget zoom2_twl4030_dapm_widgets[] = {
64 SND_SOC_DAPM_MIC("Ext Mic", NULL),
65 SND_SOC_DAPM_SPK("Ext Spk", NULL),
66 SND_SOC_DAPM_MIC("Headset Mic", NULL),
67 SND_SOC_DAPM_HP("Headset Stereophone", NULL),
68 SND_SOC_DAPM_LINE("Aux In", NULL),
69};
70
71static const struct snd_soc_dapm_route audio_map[] = {
72 /* External Mics: MAINMIC, SUBMIC with bias*/
73 {"MAINMIC", NULL, "Mic Bias 1"},
74 {"SUBMIC", NULL, "Mic Bias 2"},
75 {"Mic Bias 1", NULL, "Ext Mic"},
76 {"Mic Bias 2", NULL, "Ext Mic"},
77
78 /* External Speakers: HFL, HFR */
79 {"Ext Spk", NULL, "HFL"},
80 {"Ext Spk", NULL, "HFR"},
81
82 /* Headset Stereophone: HSOL, HSOR */
83 {"Headset Stereophone", NULL, "HSOL"},
84 {"Headset Stereophone", NULL, "HSOR"},
85
86 /* Headset Mic: HSMIC with bias */
87 {"HSMIC", NULL, "Headset Mic Bias"},
88 {"Headset Mic Bias", NULL, "Headset Mic"},
89
90 /* Aux In: AUXL, AUXR */
91 {"Aux In", NULL, "AUXL"},
92 {"Aux In", NULL, "AUXR"},
93};
94
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000095static int zoom2_twl4030_init(struct snd_soc_pcm_runtime *rtd)
Lopez Cruz, Misaeldf205932009-06-11 17:35:27 -050096{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000097 struct snd_soc_codec *codec = rtd->codec;
Liam Girdwoodce6120c2010-11-05 15:53:46 +020098 struct snd_soc_dapm_context *dapm = &codec->dapm;
Lopez Cruz, Misaeldf205932009-06-11 17:35:27 -050099
Lopez Cruz, Misaeldf205932009-06-11 17:35:27 -0500100 /* TWL4030 not connected pins */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200101 snd_soc_dapm_nc_pin(dapm, "CARKITMIC");
102 snd_soc_dapm_nc_pin(dapm, "DIGIMIC0");
103 snd_soc_dapm_nc_pin(dapm, "DIGIMIC1");
104 snd_soc_dapm_nc_pin(dapm, "EARPIECE");
105 snd_soc_dapm_nc_pin(dapm, "PREDRIVEL");
106 snd_soc_dapm_nc_pin(dapm, "PREDRIVER");
107 snd_soc_dapm_nc_pin(dapm, "CARKITL");
108 snd_soc_dapm_nc_pin(dapm, "CARKITR");
Lopez Cruz, Misaeldf205932009-06-11 17:35:27 -0500109
Peter Ujfalusicb424872011-10-10 15:34:08 +0300110 return 0;
Lopez Cruz, Misaeldf205932009-06-11 17:35:27 -0500111}
112
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000113static int zoom2_twl4030_voice_init(struct snd_soc_pcm_runtime *rtd)
Lopez Cruz, Misaeldf205932009-06-11 17:35:27 -0500114{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000115 struct snd_soc_codec *codec = rtd->codec;
Lopez Cruz, Misaeldf205932009-06-11 17:35:27 -0500116 unsigned short reg;
117
118 /* Enable voice interface */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000119 reg = codec->driver->read(codec, TWL4030_REG_VOICE_IF);
Lopez Cruz, Misaeldf205932009-06-11 17:35:27 -0500120 reg |= TWL4030_VIF_DIN_EN | TWL4030_VIF_DOUT_EN | TWL4030_VIF_EN;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000121 codec->driver->write(codec, TWL4030_REG_VOICE_IF, reg);
Lopez Cruz, Misaeldf205932009-06-11 17:35:27 -0500122
123 return 0;
124}
125
126/* Digital audio interface glue - connects codec <--> CPU */
127static struct snd_soc_dai_link zoom2_dai[] = {
128 {
129 .name = "TWL4030 I2S",
130 .stream_name = "TWL4030 Audio",
Peter Ujfalusi45656b42012-02-14 18:20:58 +0200131 .cpu_dai_name = "omap-mcbsp.2",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000132 .codec_dai_name = "twl4030-hifi",
133 .platform_name = "omap-pcm-audio",
134 .codec_name = "twl4030-codec",
Jarkko Nikulacf9feff2011-09-30 16:07:45 +0300135 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
136 SND_SOC_DAIFMT_CBM_CFM,
Lopez Cruz, Misaeldf205932009-06-11 17:35:27 -0500137 .init = zoom2_twl4030_init,
138 .ops = &zoom2_ops,
139 },
140 {
141 .name = "TWL4030 PCM",
142 .stream_name = "TWL4030 Voice",
Peter Ujfalusi45656b42012-02-14 18:20:58 +0200143 .cpu_dai_name = "omap-mcbsp.3",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000144 .codec_dai_name = "twl4030-voice",
145 .platform_name = "omap-pcm-audio",
146 .codec_name = "twl4030-codec",
Jarkko Nikulacf9feff2011-09-30 16:07:45 +0300147 .dai_fmt = SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_IB_NF |
148 SND_SOC_DAIFMT_CBM_CFM,
Lopez Cruz, Misaeldf205932009-06-11 17:35:27 -0500149 .init = zoom2_twl4030_voice_init,
Jarkko Nikulaa3c6dac2011-09-30 16:07:46 +0300150 .ops = &zoom2_ops,
Lopez Cruz, Misaeldf205932009-06-11 17:35:27 -0500151 },
152};
153
154/* Audio machine driver */
155static struct snd_soc_card snd_soc_zoom2 = {
156 .name = "Zoom2",
Axel Linb425b882011-12-22 11:08:59 +0800157 .owner = THIS_MODULE,
Lopez Cruz, Misaeldf205932009-06-11 17:35:27 -0500158 .dai_link = zoom2_dai,
159 .num_links = ARRAY_SIZE(zoom2_dai),
Peter Ujfalusi1083dbd2011-10-10 15:34:13 +0300160
161 .dapm_widgets = zoom2_twl4030_dapm_widgets,
162 .num_dapm_widgets = ARRAY_SIZE(zoom2_twl4030_dapm_widgets),
163 .dapm_routes = audio_map,
164 .num_dapm_routes = ARRAY_SIZE(audio_map),
Lopez Cruz, Misaeldf205932009-06-11 17:35:27 -0500165};
166
Lopez Cruz, Misaeldf205932009-06-11 17:35:27 -0500167static struct platform_device *zoom2_snd_device;
168
169static int __init zoom2_soc_init(void)
170{
171 int ret;
172
Jarkko Nikulaec588ae2010-10-06 16:47:26 +0300173 if (!machine_is_omap_zoom2())
Lopez Cruz, Misaeldf205932009-06-11 17:35:27 -0500174 return -ENODEV;
Lopez Cruz, Misaeldf205932009-06-11 17:35:27 -0500175 printk(KERN_INFO "Zoom2 SoC init\n");
176
177 zoom2_snd_device = platform_device_alloc("soc-audio", -1);
178 if (!zoom2_snd_device) {
179 printk(KERN_ERR "Platform device allocation failed\n");
180 return -ENOMEM;
181 }
182
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000183 platform_set_drvdata(zoom2_snd_device, &snd_soc_zoom2);
Lopez Cruz, Misaeldf205932009-06-11 17:35:27 -0500184 ret = platform_device_add(zoom2_snd_device);
185 if (ret)
186 goto err1;
187
Lopez Cruz, Misaeldf205932009-06-11 17:35:27 -0500188 return 0;
189
190err1:
191 printk(KERN_ERR "Unable to add platform device\n");
192 platform_device_put(zoom2_snd_device);
193
194 return ret;
195}
196module_init(zoom2_soc_init);
197
198static void __exit zoom2_soc_exit(void)
199{
Lopez Cruz, Misaeldf205932009-06-11 17:35:27 -0500200 platform_device_unregister(zoom2_snd_device);
201}
202module_exit(zoom2_soc_exit);
203
204MODULE_AUTHOR("Misael Lopez Cruz <x0052729@ti.com>");
205MODULE_DESCRIPTION("ALSA SoC Zoom2");
206MODULE_LICENSE("GPL");
207