blob: e263188841b6ffa21c0ad1d0083c6cb8ca513c53 [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>
Paul Gortmakerda155d52011-07-15 12:38:28 -040024#include <linux/module.h>
Steve Sakomandc061022008-10-30 21:55:24 -070025#include <sound/core.h>
26#include <sound/pcm.h>
27#include <sound/soc.h>
Steve Sakomandc061022008-10-30 21:55:24 -070028
29#include <asm/mach-types.h>
30#include <mach/hardware.h>
31#include <mach/gpio.h>
Arnd Bergmann22037472012-08-24 15:21:06 +020032#include <linux/platform_data/asoc-ti-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",
Peter Ujfalusi45656b42012-02-14 18:20:58 +020094 .cpu_dai_name = "omap-mcbsp.2",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000095 .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
Jarkko Nikulaec588ae2010-10-06 16:47:26 +0300115 if (!(machine_is_omap3_beagle() || machine_is_devkit8000()))
Steve Sakomandc061022008-10-30 21:55:24 -0700116 return -ENODEV;
Thomas Weber867af972010-02-11 16:13:59 +0100117 pr_info("OMAP3 Beagle/Devkit8000 SoC init\n");
Steve Sakomandc061022008-10-30 21:55:24 -0700118
119 omap3beagle_snd_device = platform_device_alloc("soc-audio", -1);
120 if (!omap3beagle_snd_device) {
121 printk(KERN_ERR "Platform device allocation failed\n");
122 return -ENOMEM;
123 }
124
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000125 platform_set_drvdata(omap3beagle_snd_device, &snd_soc_omap3beagle);
Steve Sakomandc061022008-10-30 21:55:24 -0700126
127 ret = platform_device_add(omap3beagle_snd_device);
128 if (ret)
129 goto err1;
130
131 return 0;
132
133err1:
134 printk(KERN_ERR "Unable to add platform device\n");
135 platform_device_put(omap3beagle_snd_device);
136
137 return ret;
138}
139
140static void __exit omap3beagle_soc_exit(void)
141{
142 platform_device_unregister(omap3beagle_snd_device);
143}
144
145module_init(omap3beagle_soc_init);
146module_exit(omap3beagle_soc_exit);
147
148MODULE_AUTHOR("Steve Sakoman <steve@sakoman.com>");
149MODULE_DESCRIPTION("ALSA SoC OMAP3 Beagle");
150MODULE_LICENSE("GPL");