blob: c7adea38274cb25f101d7dda9e6296eb4ff4e3f3 [file] [log] [blame]
Arun KSdf573d22008-11-19 17:45:19 +05301/*
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>
Tony Lindgrence491cf2009-10-20 09:40:47 -070034#include <plat/mcbsp.h>
Arun KSdf573d22008-11-19 17:45:19 +053035
36#include "omap-mcbsp.h"
37#include "omap-pcm.h"
38#include "../codecs/twl4030.h"
39
40static int omap2evm_hw_params(struct snd_pcm_substream *substream,
Mark Browndee89c42008-11-18 22:11:38 +000041 struct snd_pcm_hw_params *params,
42 struct snd_soc_dai *dai)
Arun KSdf573d22008-11-19 17:45:19 +053043{
44 struct snd_soc_pcm_runtime *rtd = substream->private_data;
45 struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
46 struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
47 int ret;
48
49 /* Set codec DAI configuration */
50 ret = snd_soc_dai_set_fmt(codec_dai,
51 SND_SOC_DAIFMT_I2S |
52 SND_SOC_DAIFMT_NB_NF |
53 SND_SOC_DAIFMT_CBM_CFM);
54 if (ret < 0) {
55 printk(KERN_ERR "can't set codec DAI configuration\n");
56 return ret;
57 }
58
59 /* Set cpu DAI configuration */
60 ret = snd_soc_dai_set_fmt(cpu_dai,
61 SND_SOC_DAIFMT_I2S |
62 SND_SOC_DAIFMT_NB_NF |
63 SND_SOC_DAIFMT_CBM_CFM);
64 if (ret < 0) {
65 printk(KERN_ERR "can't set cpu DAI configuration\n");
66 return ret;
67 }
68
69 /* Set the codec system clock for DAC and ADC */
70 ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000,
71 SND_SOC_CLOCK_IN);
72 if (ret < 0) {
73 printk(KERN_ERR "can't set codec system clock\n");
74 return ret;
75 }
76
77 return 0;
78}
79
80static struct snd_soc_ops omap2evm_ops = {
81 .hw_params = omap2evm_hw_params,
82};
83
84/* Digital audio interface glue - connects codec <--> CPU */
85static struct snd_soc_dai_link omap2evm_dai = {
86 .name = "TWL4030",
87 .stream_name = "TWL4030",
88 .cpu_dai = &omap_mcbsp_dai[0],
Joonyoung Shim7154b3e2009-04-20 19:21:35 +090089 .codec_dai = &twl4030_dai[TWL4030_DAI_HIFI],
Arun KSdf573d22008-11-19 17:45:19 +053090 .ops = &omap2evm_ops,
91};
92
93/* Audio machine driver */
Mark Brown87506542008-11-18 20:50:34 +000094static struct snd_soc_card snd_soc_omap2evm = {
Arun KSdf573d22008-11-19 17:45:19 +053095 .name = "omap2evm",
Mark Brown87689d52008-12-02 16:01:14 +000096 .platform = &omap_soc_platform,
Arun KSdf573d22008-11-19 17:45:19 +053097 .dai_link = &omap2evm_dai,
98 .num_links = 1,
99};
100
101/* Audio subsystem */
102static struct snd_soc_device omap2evm_snd_devdata = {
Mark Brown87506542008-11-18 20:50:34 +0000103 .card = &snd_soc_omap2evm,
Arun KSdf573d22008-11-19 17:45:19 +0530104 .codec_dev = &soc_codec_dev_twl4030,
105};
106
107static struct platform_device *omap2evm_snd_device;
108
109static int __init omap2evm_soc_init(void)
110{
111 int ret;
112
113 if (!machine_is_omap2evm()) {
114 pr_debug("Not omap2evm!\n");
115 return -ENODEV;
116 }
117 printk(KERN_INFO "omap2evm SoC init\n");
118
119 omap2evm_snd_device = platform_device_alloc("soc-audio", -1);
120 if (!omap2evm_snd_device) {
121 printk(KERN_ERR "Platform device allocation failed\n");
122 return -ENOMEM;
123 }
124
125 platform_set_drvdata(omap2evm_snd_device, &omap2evm_snd_devdata);
126 omap2evm_snd_devdata.dev = &omap2evm_snd_device->dev;
127 *(unsigned int *)omap2evm_dai.cpu_dai->private_data = 1; /* McBSP2 */
128
129 ret = platform_device_add(omap2evm_snd_device);
130 if (ret)
131 goto err1;
132
133 return 0;
134
135err1:
136 printk(KERN_ERR "Unable to add platform device\n");
137 platform_device_put(omap2evm_snd_device);
138
139 return ret;
140}
141module_init(omap2evm_soc_init);
142
143static void __exit omap2evm_soc_exit(void)
144{
145 platform_device_unregister(omap2evm_snd_device);
146}
147module_exit(omap2evm_soc_exit);
148
149MODULE_AUTHOR("Arun KS <arunks@mistralsolutions.com>");
150MODULE_DESCRIPTION("ALSA SoC omap2evm");
151MODULE_LICENSE("GPL");