]> nv-tegra.nvidia Code Review - linux-2.6.git/blob - sound/soc/omap/omap3evm.c
Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/sparc-2.6
[linux-2.6.git] / sound / soc / omap / omap3evm.c
1 /*
2  * omap3evm.c  -- ALSA SoC support for OMAP3 EVM
3  *
4  * Author: Anuj Aggarwal <anuj.aggarwal@ti.com>
5  *
6  * Based on sound/soc/omap/beagle.c by Steve Sakoman
7  *
8  * Copyright (C) 2008 Texas Instruments, Incorporated
9  *
10  * This program is free software; you can redistribute it and/or modify it
11  * under the terms of the GNU General Public License as published by the
12  * Free Software Foundation version 2.
13  *
14  * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind,
15  * whether express or implied; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * General Public License for more details.
18  */
19
20 #include <linux/clk.h>
21 #include <linux/platform_device.h>
22 #include <sound/core.h>
23 #include <sound/pcm.h>
24 #include <sound/soc.h>
25 #include <sound/soc-dapm.h>
26
27 #include <asm/mach-types.h>
28 #include <mach/hardware.h>
29 #include <mach/gpio.h>
30 #include <plat/mcbsp.h>
31
32 #include "omap-mcbsp.h"
33 #include "omap-pcm.h"
34 #include "../codecs/twl4030.h"
35
36 static int omap3evm_hw_params(struct snd_pcm_substream *substream,
37         struct snd_pcm_hw_params *params)
38 {
39         struct snd_soc_pcm_runtime *rtd = substream->private_data;
40         struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
41         struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
42         int ret;
43
44         /* Set codec DAI configuration */
45         ret = snd_soc_dai_set_fmt(codec_dai,
46                                   SND_SOC_DAIFMT_I2S |
47                                   SND_SOC_DAIFMT_NB_NF |
48                                   SND_SOC_DAIFMT_CBM_CFM);
49         if (ret < 0) {
50                 printk(KERN_ERR "Can't set codec DAI configuration\n");
51                 return ret;
52         }
53
54         /* Set cpu DAI configuration */
55         ret = snd_soc_dai_set_fmt(cpu_dai,
56                                   SND_SOC_DAIFMT_I2S |
57                                   SND_SOC_DAIFMT_NB_NF |
58                                   SND_SOC_DAIFMT_CBM_CFM);
59         if (ret < 0) {
60                 printk(KERN_ERR "Can't set cpu DAI configuration\n");
61                 return ret;
62         }
63
64         /* Set the codec system clock for DAC and ADC */
65         ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000,
66                                      SND_SOC_CLOCK_IN);
67         if (ret < 0) {
68                 printk(KERN_ERR "Can't set codec system clock\n");
69                 return ret;
70         }
71
72         return 0;
73 }
74
75 static struct snd_soc_ops omap3evm_ops = {
76         .hw_params = omap3evm_hw_params,
77 };
78
79 /* Digital audio interface glue - connects codec <--> CPU */
80 static struct snd_soc_dai_link omap3evm_dai = {
81         .name           = "TWL4030",
82         .stream_name    = "TWL4030",
83         .cpu_dai        = &omap_mcbsp_dai[0],
84         .codec_dai      = &twl4030_dai[TWL4030_DAI_HIFI],
85         .ops            = &omap3evm_ops,
86 };
87
88 /* Audio machine driver */
89 static struct snd_soc_card snd_soc_omap3evm = {
90         .name = "omap3evm",
91         .platform = &omap_soc_platform,
92         .dai_link = &omap3evm_dai,
93         .num_links = 1,
94 };
95
96 /* twl4030 setup */
97 static struct twl4030_setup_data twl4030_setup = {
98         .ramp_delay_value = 4,
99         .sysclk = 26000,
100 };
101
102 /* Audio subsystem */
103 static struct snd_soc_device omap3evm_snd_devdata = {
104         .card = &snd_soc_omap3evm,
105         .codec_dev = &soc_codec_dev_twl4030,
106         .codec_data = &twl4030_setup,
107 };
108
109 static struct platform_device *omap3evm_snd_device;
110
111 static int __init omap3evm_soc_init(void)
112 {
113         int ret;
114
115         if (!machine_is_omap3evm()) {
116                 pr_err("Not OMAP3 EVM!\n");
117                 return -ENODEV;
118         }
119         pr_info("OMAP3 EVM SoC init\n");
120
121         omap3evm_snd_device = platform_device_alloc("soc-audio", -1);
122         if (!omap3evm_snd_device) {
123                 printk(KERN_ERR "Platform device allocation failed\n");
124                 return -ENOMEM;
125         }
126
127         platform_set_drvdata(omap3evm_snd_device, &omap3evm_snd_devdata);
128         omap3evm_snd_devdata.dev = &omap3evm_snd_device->dev;
129         *(unsigned int *)omap3evm_dai.cpu_dai->private_data = 1;
130
131         ret = platform_device_add(omap3evm_snd_device);
132         if (ret)
133                 goto err1;
134
135         return 0;
136
137 err1:
138         printk(KERN_ERR "Unable to add platform device\n");
139         platform_device_put(omap3evm_snd_device);
140
141         return ret;
142 }
143
144 static void __exit omap3evm_soc_exit(void)
145 {
146         platform_device_unregister(omap3evm_snd_device);
147 }
148
149 module_init(omap3evm_soc_init);
150 module_exit(omap3evm_soc_exit);
151
152 MODULE_AUTHOR("Anuj Aggarwal <anuj.aggarwal@ti.com>");
153 MODULE_DESCRIPTION("ALSA SoC OMAP3 EVM");
154 MODULE_LICENSE("GPL v2");