blob: 240e0975dd6a716e47546a54deb83cecffb9b960 [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"
36#include "../codecs/twl4030.h"
37
38static int omap3beagle_hw_params(struct snd_pcm_substream *substream,
39 struct snd_pcm_hw_params *params)
40{
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;
Peter Ujfalusia8353a52009-04-24 11:03:21 +030044 unsigned int fmt;
Steve Sakomandc061022008-10-30 21:55:24 -070045 int ret;
46
Peter Ujfalusia8353a52009-04-24 11:03:21 +030047 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;
52 break;
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;
57 break;
58 default:
59 return -EINVAL;
60 }
61
Steve Sakomandc061022008-10-30 21:55:24 -070062 /* Set codec DAI configuration */
Peter Ujfalusia8353a52009-04-24 11:03:21 +030063 ret = snd_soc_dai_set_fmt(codec_dai, fmt);
Steve Sakomandc061022008-10-30 21:55:24 -070064 if (ret < 0) {
65 printk(KERN_ERR "can't set codec DAI configuration\n");
66 return ret;
67 }
68
69 /* Set cpu DAI configuration */
Peter Ujfalusia8353a52009-04-24 11:03:21 +030070 ret = snd_soc_dai_set_fmt(cpu_dai, fmt);
Steve Sakomandc061022008-10-30 21:55:24 -070071 if (ret < 0) {
72 printk(KERN_ERR "can't set cpu DAI configuration\n");
73 return ret;
74 }
75
76 /* Set the codec system clock for DAC and ADC */
77 ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000,
78 SND_SOC_CLOCK_IN);
79 if (ret < 0) {
80 printk(KERN_ERR "can't set codec system clock\n");
81 return ret;
82 }
83
84 return 0;
85}
86
87static struct snd_soc_ops omap3beagle_ops = {
88 .hw_params = omap3beagle_hw_params,
89};
90
91/* Digital audio interface glue - connects codec <--> CPU */
92static struct snd_soc_dai_link omap3beagle_dai = {
93 .name = "TWL4030",
94 .stream_name = "TWL4030",
95 .cpu_dai = &omap_mcbsp_dai[0],
Joonyoung Shim7154b3e2009-04-20 19:21:35 +090096 .codec_dai = &twl4030_dai[TWL4030_DAI_HIFI],
Steve Sakomandc061022008-10-30 21:55:24 -070097 .ops = &omap3beagle_ops,
98};
99
100/* Audio machine driver */
Mark Brown87506542008-11-18 20:50:34 +0000101static struct snd_soc_card snd_soc_omap3beagle = {
Steve Sakomandc061022008-10-30 21:55:24 -0700102 .name = "omap3beagle",
Mark Brown87689d52008-12-02 16:01:14 +0000103 .platform = &omap_soc_platform,
Steve Sakomandc061022008-10-30 21:55:24 -0700104 .dai_link = &omap3beagle_dai,
105 .num_links = 1,
106};
107
108/* Audio subsystem */
109static struct snd_soc_device omap3beagle_snd_devdata = {
Mark Brown87506542008-11-18 20:50:34 +0000110 .card = &snd_soc_omap3beagle,
Steve Sakomandc061022008-10-30 21:55:24 -0700111 .codec_dev = &soc_codec_dev_twl4030,
112};
113
114static struct platform_device *omap3beagle_snd_device;
115
116static int __init omap3beagle_soc_init(void)
117{
118 int ret;
119
Thomas Weber867af972010-02-11 16:13:59 +0100120 if (!(machine_is_omap3_beagle() || machine_is_devkit8000())) {
121 pr_debug("Not OMAP3 Beagle or Devkit8000!\n");
Steve Sakomandc061022008-10-30 21:55:24 -0700122 return -ENODEV;
123 }
Thomas Weber867af972010-02-11 16:13:59 +0100124 pr_info("OMAP3 Beagle/Devkit8000 SoC init\n");
Steve Sakomandc061022008-10-30 21:55:24 -0700125
126 omap3beagle_snd_device = platform_device_alloc("soc-audio", -1);
127 if (!omap3beagle_snd_device) {
128 printk(KERN_ERR "Platform device allocation failed\n");
129 return -ENOMEM;
130 }
131
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 */
135
136 ret = platform_device_add(omap3beagle_snd_device);
137 if (ret)
138 goto err1;
139
140 return 0;
141
142err1:
143 printk(KERN_ERR "Unable to add platform device\n");
144 platform_device_put(omap3beagle_snd_device);
145
146 return ret;
147}
148
149static void __exit omap3beagle_soc_exit(void)
150{
151 platform_device_unregister(omap3beagle_snd_device);
152}
153
154module_init(omap3beagle_soc_init);
155module_exit(omap3beagle_soc_exit);
156
157MODULE_AUTHOR("Steve Sakoman <steve@sakoman.com>");
158MODULE_DESCRIPTION("ALSA SoC OMAP3 Beagle");
159MODULE_LICENSE("GPL");