blob: 7c11e1afe9e640a9e90c006b00fdadb8e4ff5939 [file] [log] [blame]
Steve Sakomandc061022008-10-30 21:55:24 -07001/*
2 * omap3beagle.c -- SoC audio for OMAP3 Beagle
3 *
4 * Author: Steve Sakoman <steve@sakoman.com>
5 *
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.
9 *
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.
14 *
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
19 *
20 */
21
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>
28
29#include <asm/mach-types.h>
30#include <mach/hardware.h>
31#include <mach/gpio.h>
Tony Lindgrence491cf2009-10-20 09:40:47 -070032#include <plat/mcbsp.h>
Steve Sakomandc061022008-10-30 21:55:24 -070033
34#include "omap-mcbsp.h"
35#include "omap-pcm.h"
Steve Sakomandc061022008-10-30 21:55:24 -070036
37static int omap3beagle_hw_params(struct snd_pcm_substream *substream,
38 struct snd_pcm_hw_params *params)
39{
40 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000041 struct snd_soc_dai *codec_dai = rtd->codec_dai;
42 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
Peter Ujfalusia8353a52009-04-24 11:03:21 +030043 unsigned int fmt;
Steve Sakomandc061022008-10-30 21:55:24 -070044 int ret;
45
Peter Ujfalusia8353a52009-04-24 11:03:21 +030046 switch (params_channels(params)) {
47 case 2: /* Stereo I2S mode */
48 fmt = SND_SOC_DAIFMT_I2S |
49 SND_SOC_DAIFMT_NB_NF |
50 SND_SOC_DAIFMT_CBM_CFM;
51 break;
52 case 4: /* Four channel TDM mode */
53 fmt = SND_SOC_DAIFMT_DSP_A |
54 SND_SOC_DAIFMT_IB_NF |
55 SND_SOC_DAIFMT_CBM_CFM;
56 break;
57 default:
58 return -EINVAL;
59 }
60
Steve Sakomandc061022008-10-30 21:55:24 -070061 /* Set codec DAI configuration */
Peter Ujfalusia8353a52009-04-24 11:03:21 +030062 ret = snd_soc_dai_set_fmt(codec_dai, fmt);
Steve Sakomandc061022008-10-30 21:55:24 -070063 if (ret < 0) {
64 printk(KERN_ERR "can't set codec DAI configuration\n");
65 return ret;
66 }
67
68 /* Set cpu DAI configuration */
Peter Ujfalusia8353a52009-04-24 11:03:21 +030069 ret = snd_soc_dai_set_fmt(cpu_dai, fmt);
Steve Sakomandc061022008-10-30 21:55:24 -070070 if (ret < 0) {
71 printk(KERN_ERR "can't set cpu DAI configuration\n");
72 return ret;
73 }
74
75 /* Set the codec system clock for DAC and ADC */
76 ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000,
77 SND_SOC_CLOCK_IN);
78 if (ret < 0) {
79 printk(KERN_ERR "can't set codec system clock\n");
80 return ret;
81 }
82
83 return 0;
84}
85
86static struct snd_soc_ops omap3beagle_ops = {
87 .hw_params = omap3beagle_hw_params,
88};
89
90/* Digital audio interface glue - connects codec <--> CPU */
91static struct snd_soc_dai_link omap3beagle_dai = {
92 .name = "TWL4030",
93 .stream_name = "TWL4030",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000094 .cpu_dai_name = "omap-mcbsp-dai.1",
95 .platform_name = "omap-pcm-audio",
96 .codec_dai_name = "twl4030-hifi",
97 .codec_name = "twl4030-codec",
Steve Sakomandc061022008-10-30 21:55:24 -070098 .ops = &omap3beagle_ops,
99};
100
101/* Audio machine driver */
Mark Brown87506542008-11-18 20:50:34 +0000102static struct snd_soc_card snd_soc_omap3beagle = {
Steve Sakomandc061022008-10-30 21:55:24 -0700103 .name = "omap3beagle",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000104 .owner = THIS_MODULE,
Steve Sakomandc061022008-10-30 21:55:24 -0700105 .dai_link = &omap3beagle_dai,
106 .num_links = 1,
107};
108
Steve Sakomandc061022008-10-30 21:55:24 -0700109static struct platform_device *omap3beagle_snd_device;
110
111static int __init omap3beagle_soc_init(void)
112{
113 int ret;
114
Thomas Weber867af972010-02-11 16:13:59 +0100115 if (!(machine_is_omap3_beagle() || machine_is_devkit8000())) {
116 pr_debug("Not OMAP3 Beagle or Devkit8000!\n");
Steve Sakomandc061022008-10-30 21:55:24 -0700117 return -ENODEV;
118 }
Thomas Weber867af972010-02-11 16:13:59 +0100119 pr_info("OMAP3 Beagle/Devkit8000 SoC init\n");
Steve Sakomandc061022008-10-30 21:55:24 -0700120
121 omap3beagle_snd_device = platform_device_alloc("soc-audio", -1);
122 if (!omap3beagle_snd_device) {
123 printk(KERN_ERR "Platform device allocation failed\n");
124 return -ENOMEM;
125 }
126
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000127 platform_set_drvdata(omap3beagle_snd_device, &snd_soc_omap3beagle);
Steve Sakomandc061022008-10-30 21:55:24 -0700128
129 ret = platform_device_add(omap3beagle_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(omap3beagle_snd_device);
138
139 return ret;
140}
141
142static void __exit omap3beagle_soc_exit(void)
143{
144 platform_device_unregister(omap3beagle_snd_device);
145}
146
147module_init(omap3beagle_soc_init);
148module_exit(omap3beagle_soc_exit);
149
150MODULE_AUTHOR("Steve Sakoman <steve@sakoman.com>");
151MODULE_DESCRIPTION("ALSA SoC OMAP3 Beagle");
152MODULE_LICENSE("GPL");