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
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>
27 #include <sound/soc-dapm.h>
29 #include <asm/mach-types.h>
30 #include <mach/hardware.h>
31 #include <mach/gpio.h>
32 #include <mach/mcbsp.h>
34 #include "omap-mcbsp.h"
36 #include "../codecs/twl4030.h"
38 static int omap3beagle_hw_params(struct snd_pcm_substream *substream,
39 struct snd_pcm_hw_params *params)
41 struct snd_soc_pcm_runtime *rtd = substream->private_data;
42 struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
43 struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
47 switch (params_channels(params)) {
48 case 2: /* Stereo I2S mode */
49 fmt = SND_SOC_DAIFMT_I2S |
50 SND_SOC_DAIFMT_NB_NF |
51 SND_SOC_DAIFMT_CBM_CFM;
53 case 4: /* Four channel TDM mode */
54 fmt = SND_SOC_DAIFMT_DSP_A |
55 SND_SOC_DAIFMT_IB_NF |
56 SND_SOC_DAIFMT_CBM_CFM;
62 /* Set codec DAI configuration */
63 ret = snd_soc_dai_set_fmt(codec_dai, fmt);
65 printk(KERN_ERR "can't set codec DAI configuration\n");
69 /* Set cpu DAI configuration */
70 ret = snd_soc_dai_set_fmt(cpu_dai, fmt);
72 printk(KERN_ERR "can't set cpu DAI configuration\n");
76 /* Set the codec system clock for DAC and ADC */
77 ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000,
80 printk(KERN_ERR "can't set codec system clock\n");
87 static struct snd_soc_ops omap3beagle_ops = {
88 .hw_params = omap3beagle_hw_params,
91 /* Digital audio interface glue - connects codec <--> CPU */
92 static struct snd_soc_dai_link omap3beagle_dai = {
94 .stream_name = "TWL4030",
95 .cpu_dai = &omap_mcbsp_dai[0],
96 .codec_dai = &twl4030_dai[TWL4030_DAI_HIFI],
97 .ops = &omap3beagle_ops,
100 /* Audio machine driver */
101 static struct snd_soc_card snd_soc_omap3beagle = {
102 .name = "omap3beagle",
103 .platform = &omap_soc_platform,
104 .dai_link = &omap3beagle_dai,
108 /* Audio subsystem */
109 static struct snd_soc_device omap3beagle_snd_devdata = {
110 .card = &snd_soc_omap3beagle,
111 .codec_dev = &soc_codec_dev_twl4030,
114 static struct platform_device *omap3beagle_snd_device;
116 static int __init omap3beagle_soc_init(void)
120 if (!machine_is_omap3_beagle()) {
121 pr_debug("Not OMAP3 Beagle!\n");
124 pr_info("OMAP3 Beagle SoC init\n");
126 omap3beagle_snd_device = platform_device_alloc("soc-audio", -1);
127 if (!omap3beagle_snd_device) {
128 printk(KERN_ERR "Platform device allocation failed\n");
132 platform_set_drvdata(omap3beagle_snd_device, &omap3beagle_snd_devdata);
133 omap3beagle_snd_devdata.dev = &omap3beagle_snd_device->dev;
134 *(unsigned int *)omap3beagle_dai.cpu_dai->private_data = 1; /* McBSP2 */
136 ret = platform_device_add(omap3beagle_snd_device);
143 printk(KERN_ERR "Unable to add platform device\n");
144 platform_device_put(omap3beagle_snd_device);
149 static void __exit omap3beagle_soc_exit(void)
151 platform_device_unregister(omap3beagle_snd_device);
154 module_init(omap3beagle_soc_init);
155 module_exit(omap3beagle_soc_exit);
157 MODULE_AUTHOR("Steve Sakoman <steve@sakoman.com>");
158 MODULE_DESCRIPTION("ALSA SoC OMAP3 Beagle");
159 MODULE_LICENSE("GPL");