Merge tag 'v3.3.7' into 3.3/master
[zen-stable.git] / sound / soc / omap / omap3beagle.c
blob3357dcc47ed48ccaf26fa1dfe9854c7ffb8ed0cb
1 /*
2 * omap3beagle.c -- SoC audio for OMAP3 Beagle
4 * Author: Steve Sakoman <steve@sakoman.com>
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.
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.
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
22 #include <linux/clk.h>
23 #include <linux/platform_device.h>
24 #include <linux/module.h>
25 #include <sound/core.h>
26 #include <sound/pcm.h>
27 #include <sound/soc.h>
29 #include <asm/mach-types.h>
30 #include <mach/hardware.h>
31 #include <mach/gpio.h>
32 #include <plat/mcbsp.h>
34 #include "omap-mcbsp.h"
35 #include "omap-pcm.h"
37 static int omap3beagle_hw_params(struct snd_pcm_substream *substream,
38 struct snd_pcm_hw_params *params)
40 struct snd_soc_pcm_runtime *rtd = substream->private_data;
41 struct snd_soc_dai *codec_dai = rtd->codec_dai;
42 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
43 unsigned int fmt;
44 int ret;
46 switch (params_channels(params)) {
47 case 2: /* Stereo I2S mode */
48 fmt = SND_SOC_DAIFMT_I2S |
49 SND_SOC_DAIFMT_NB_NF |
50 SND_SOC_DAIFMT_CBM_CFM;
51 break;
52 case 4: /* Four channel TDM mode */
53 fmt = SND_SOC_DAIFMT_DSP_A |
54 SND_SOC_DAIFMT_IB_NF |
55 SND_SOC_DAIFMT_CBM_CFM;
56 break;
57 default:
58 return -EINVAL;
61 /* Set codec DAI configuration */
62 ret = snd_soc_dai_set_fmt(codec_dai, fmt);
63 if (ret < 0) {
64 printk(KERN_ERR "can't set codec DAI configuration\n");
65 return ret;
68 /* Set cpu DAI configuration */
69 ret = snd_soc_dai_set_fmt(cpu_dai, fmt);
70 if (ret < 0) {
71 printk(KERN_ERR "can't set cpu DAI configuration\n");
72 return ret;
75 /* Set the codec system clock for DAC and ADC */
76 ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000,
77 SND_SOC_CLOCK_IN);
78 if (ret < 0) {
79 printk(KERN_ERR "can't set codec system clock\n");
80 return ret;
83 return 0;
86 static struct snd_soc_ops omap3beagle_ops = {
87 .hw_params = omap3beagle_hw_params,
90 /* Digital audio interface glue - connects codec <--> CPU */
91 static struct snd_soc_dai_link omap3beagle_dai = {
92 .name = "TWL4030",
93 .stream_name = "TWL4030",
94 .cpu_dai_name = "omap-mcbsp-dai.1",
95 .platform_name = "omap-pcm-audio",
96 .codec_dai_name = "twl4030-hifi",
97 .codec_name = "twl4030-codec",
98 .ops = &omap3beagle_ops,
101 /* Audio machine driver */
102 static struct snd_soc_card snd_soc_omap3beagle = {
103 .name = "omap3beagle",
104 .owner = THIS_MODULE,
105 .dai_link = &omap3beagle_dai,
106 .num_links = 1,
109 static struct platform_device *omap3beagle_snd_device;
111 static int __init omap3beagle_soc_init(void)
113 int ret;
115 if (!(machine_is_omap3_beagle() || machine_is_devkit8000()))
116 return -ENODEV;
117 pr_info("OMAP3 Beagle/Devkit8000 SoC init\n");
119 omap3beagle_snd_device = platform_device_alloc("soc-audio", -1);
120 if (!omap3beagle_snd_device) {
121 printk(KERN_ERR "Platform device allocation failed\n");
122 return -ENOMEM;
125 platform_set_drvdata(omap3beagle_snd_device, &snd_soc_omap3beagle);
127 ret = platform_device_add(omap3beagle_snd_device);
128 if (ret)
129 goto err1;
131 return 0;
133 err1:
134 printk(KERN_ERR "Unable to add platform device\n");
135 platform_device_put(omap3beagle_snd_device);
137 return ret;
140 static void __exit omap3beagle_soc_exit(void)
142 platform_device_unregister(omap3beagle_snd_device);
145 module_init(omap3beagle_soc_init);
146 module_exit(omap3beagle_soc_exit);
148 MODULE_AUTHOR("Steve Sakoman <steve@sakoman.com>");
149 MODULE_DESCRIPTION("ALSA SoC OMAP3 Beagle");
150 MODULE_LICENSE("GPL");