Merge remote-tracking branch 'arm/for-next'
[linux-2.6/next.git] / sound / soc / omap / omap3beagle.c
blob40db813c0795b1e485ddcdc402229eddce7a7e9d
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 <sound/core.h>
25 #include <sound/pcm.h>
26 #include <sound/soc.h>
28 #include <asm/mach-types.h>
29 #include <mach/hardware.h>
30 #include <mach/gpio.h>
31 #include <plat/mcbsp.h>
33 #include "omap-mcbsp.h"
34 #include "omap-pcm.h"
36 static int omap3beagle_hw_params(struct snd_pcm_substream *substream,
37 struct snd_pcm_hw_params *params)
39 struct snd_soc_pcm_runtime *rtd = substream->private_data;
40 struct snd_soc_dai *codec_dai = rtd->codec_dai;
41 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
42 unsigned int fmt;
43 int ret;
45 switch (params_channels(params)) {
46 case 2: /* Stereo I2S mode */
47 fmt = SND_SOC_DAIFMT_I2S |
48 SND_SOC_DAIFMT_NB_NF |
49 SND_SOC_DAIFMT_CBM_CFM;
50 break;
51 case 4: /* Four channel TDM mode */
52 fmt = SND_SOC_DAIFMT_DSP_A |
53 SND_SOC_DAIFMT_IB_NF |
54 SND_SOC_DAIFMT_CBM_CFM;
55 break;
56 default:
57 return -EINVAL;
60 /* Set codec DAI configuration */
61 ret = snd_soc_dai_set_fmt(codec_dai, fmt);
62 if (ret < 0) {
63 printk(KERN_ERR "can't set codec DAI configuration\n");
64 return ret;
67 /* Set cpu DAI configuration */
68 ret = snd_soc_dai_set_fmt(cpu_dai, fmt);
69 if (ret < 0) {
70 printk(KERN_ERR "can't set cpu DAI configuration\n");
71 return ret;
74 /* Set the codec system clock for DAC and ADC */
75 ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000,
76 SND_SOC_CLOCK_IN);
77 if (ret < 0) {
78 printk(KERN_ERR "can't set codec system clock\n");
79 return ret;
82 return 0;
85 static struct snd_soc_ops omap3beagle_ops = {
86 .hw_params = omap3beagle_hw_params,
89 /* Digital audio interface glue - connects codec <--> CPU */
90 static struct snd_soc_dai_link omap3beagle_dai = {
91 .name = "TWL4030",
92 .stream_name = "TWL4030",
93 .cpu_dai_name = "omap-mcbsp-dai.1",
94 .platform_name = "omap-pcm-audio",
95 .codec_dai_name = "twl4030-hifi",
96 .codec_name = "twl4030-codec",
97 .ops = &omap3beagle_ops,
100 /* Audio machine driver */
101 static struct snd_soc_card snd_soc_omap3beagle = {
102 .name = "omap3beagle",
103 .owner = THIS_MODULE,
104 .dai_link = &omap3beagle_dai,
105 .num_links = 1,
108 static struct platform_device *omap3beagle_snd_device;
110 static int __init omap3beagle_soc_init(void)
112 int ret;
114 if (!(machine_is_omap3_beagle() || machine_is_devkit8000()))
115 return -ENODEV;
116 pr_info("OMAP3 Beagle/Devkit8000 SoC init\n");
118 omap3beagle_snd_device = platform_device_alloc("soc-audio", -1);
119 if (!omap3beagle_snd_device) {
120 printk(KERN_ERR "Platform device allocation failed\n");
121 return -ENOMEM;
124 platform_set_drvdata(omap3beagle_snd_device, &snd_soc_omap3beagle);
126 ret = platform_device_add(omap3beagle_snd_device);
127 if (ret)
128 goto err1;
130 return 0;
132 err1:
133 printk(KERN_ERR "Unable to add platform device\n");
134 platform_device_put(omap3beagle_snd_device);
136 return ret;
139 static void __exit omap3beagle_soc_exit(void)
141 platform_device_unregister(omap3beagle_snd_device);
144 module_init(omap3beagle_soc_init);
145 module_exit(omap3beagle_soc_exit);
147 MODULE_AUTHOR("Steve Sakoman <steve@sakoman.com>");
148 MODULE_DESCRIPTION("ALSA SoC OMAP3 Beagle");
149 MODULE_LICENSE("GPL");