]> git.karo-electronics.de Git - mv-sheeva.git/blob - sound/soc/omap/omap2evm.c
cf3fc8a675b5fc504169f35aaf418095d7da71d0
[mv-sheeva.git] / sound / soc / omap / omap2evm.c
1 /*
2  * omap2evm.c  --  SoC audio machine driver for omap2evm board
3  *
4  * Author: Arun KS <arunks@mistralsolutions.com>
5  *
6  * Based on sound/soc/omap/overo.c by Steve Sakoman
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * version 2 as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA
21  *
22  */
23
24 #include <linux/clk.h>
25 #include <linux/platform_device.h>
26 #include <sound/core.h>
27 #include <sound/pcm.h>
28 #include <sound/soc.h>
29 #include <sound/soc-dapm.h>
30
31 #include <asm/mach-types.h>
32 #include <mach/hardware.h>
33 #include <mach/gpio.h>
34 #include <plat/mcbsp.h>
35
36 #include "omap-mcbsp.h"
37 #include "omap-pcm.h"
38
39 static int omap2evm_hw_params(struct snd_pcm_substream *substream,
40         struct snd_pcm_hw_params *params)
41 {
42         struct snd_soc_pcm_runtime *rtd = substream->private_data;
43         struct snd_soc_dai *codec_dai = rtd->codec_dai;
44         struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
45         int ret;
46
47         /* Set codec DAI configuration */
48         ret = snd_soc_dai_set_fmt(codec_dai,
49                                   SND_SOC_DAIFMT_I2S |
50                                   SND_SOC_DAIFMT_NB_NF |
51                                   SND_SOC_DAIFMT_CBM_CFM);
52         if (ret < 0) {
53                 printk(KERN_ERR "can't set codec DAI configuration\n");
54                 return ret;
55         }
56
57         /* Set cpu DAI configuration */
58         ret = snd_soc_dai_set_fmt(cpu_dai,
59                                   SND_SOC_DAIFMT_I2S |
60                                   SND_SOC_DAIFMT_NB_NF |
61                                   SND_SOC_DAIFMT_CBM_CFM);
62         if (ret < 0) {
63                 printk(KERN_ERR "can't set cpu DAI configuration\n");
64                 return ret;
65         }
66
67         /* Set the codec system clock for DAC and ADC */
68         ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000,
69                                             SND_SOC_CLOCK_IN);
70         if (ret < 0) {
71                 printk(KERN_ERR "can't set codec system clock\n");
72                 return ret;
73         }
74
75         return 0;
76 }
77
78 static struct snd_soc_ops omap2evm_ops = {
79         .hw_params = omap2evm_hw_params,
80 };
81
82 /* Digital audio interface glue - connects codec <--> CPU */
83 static struct snd_soc_dai_link omap2evm_dai = {
84         .name = "TWL4030",
85         .stream_name = "TWL4030",
86         .cpu_dai_name = "omap-mcbsp-dai.1",
87         .codec_dai_name = "twl4030-hifi",
88         .platform_name = "omap-pcm-audio",
89         .codec_name = "twl4030-codec",
90         .ops = &omap2evm_ops,
91 };
92
93 /* Audio machine driver */
94 static struct snd_soc_card snd_soc_omap2evm = {
95         .name = "omap2evm",
96         .dai_link = &omap2evm_dai,
97         .num_links = 1,
98 };
99
100 static struct platform_device *omap2evm_snd_device;
101
102 static int __init omap2evm_soc_init(void)
103 {
104         int ret;
105
106         if (!machine_is_omap2evm())
107                 return -ENODEV;
108         printk(KERN_INFO "omap2evm SoC init\n");
109
110         omap2evm_snd_device = platform_device_alloc("soc-audio", -1);
111         if (!omap2evm_snd_device) {
112                 printk(KERN_ERR "Platform device allocation failed\n");
113                 return -ENOMEM;
114         }
115
116         platform_set_drvdata(omap2evm_snd_device, &snd_soc_omap2evm);
117
118         ret = platform_device_add(omap2evm_snd_device);
119         if (ret)
120                 goto err1;
121
122         return 0;
123
124 err1:
125         printk(KERN_ERR "Unable to add platform device\n");
126         platform_device_put(omap2evm_snd_device);
127
128         return ret;
129 }
130 module_init(omap2evm_soc_init);
131
132 static void __exit omap2evm_soc_exit(void)
133 {
134         platform_device_unregister(omap2evm_snd_device);
135 }
136 module_exit(omap2evm_soc_exit);
137
138 MODULE_AUTHOR("Arun KS <arunks@mistralsolutions.com>");
139 MODULE_DESCRIPTION("ALSA SoC omap2evm");
140 MODULE_LICENSE("GPL");