blob: c3550aeee533d55a2bcbb534c811a549721d99b7 [file] [log] [blame]
Steve Sakoman4e207872008-10-30 21:50:13 -07001/*
2 * overo.c -- SoC audio for Gumstix Overo
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 Sakoman4e207872008-10-30 21:50:13 -070025#include <sound/core.h>
26#include <sound/pcm.h>
27#include <sound/soc.h>
Steve Sakoman4e207872008-10-30 21:50:13 -070028
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 Sakoman4e207872008-10-30 21:50:13 -070033
34#include "omap-mcbsp.h"
35#include "omap-pcm.h"
Steve Sakoman4e207872008-10-30 21:50:13 -070036
37static int overo_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;
Steve Sakoman4e207872008-10-30 21:50:13 -070042 int ret;
43
Steve Sakoman4e207872008-10-30 21:50:13 -070044 /* Set the codec system clock for DAC and ADC */
45 ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000,
46 SND_SOC_CLOCK_IN);
47 if (ret < 0) {
48 printk(KERN_ERR "can't set codec system clock\n");
49 return ret;
50 }
51
52 return 0;
53}
54
55static struct snd_soc_ops overo_ops = {
56 .hw_params = overo_hw_params,
57};
58
59/* Digital audio interface glue - connects codec <--> CPU */
60static struct snd_soc_dai_link overo_dai = {
61 .name = "TWL4030",
62 .stream_name = "TWL4030",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000063 .cpu_dai_name = "omap-mcbsp-dai.1",
64 .codec_dai_name = "twl4030-hifi",
65 .platform_name = "omap-pcm-audio",
66 .codec_name = "twl4030-codec",
Jarkko Nikulacf9feff2011-09-30 16:07:45 +030067 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
68 SND_SOC_DAIFMT_CBM_CFM,
Steve Sakoman4e207872008-10-30 21:50:13 -070069 .ops = &overo_ops,
70};
71
72/* Audio machine driver */
Mark Brown87506542008-11-18 20:50:34 +000073static struct snd_soc_card snd_soc_card_overo = {
Steve Sakoman4e207872008-10-30 21:50:13 -070074 .name = "overo",
75 .dai_link = &overo_dai,
76 .num_links = 1,
77};
78
Steve Sakoman4e207872008-10-30 21:50:13 -070079static struct platform_device *overo_snd_device;
80
81static int __init overo_soc_init(void)
82{
83 int ret;
84
Mike Rapoport8df89bc2009-11-16 16:19:25 +020085 if (!(machine_is_overo() || machine_is_cm_t35())) {
86 pr_debug("Incomatible machine!\n");
Steve Sakoman4e207872008-10-30 21:50:13 -070087 return -ENODEV;
88 }
89 printk(KERN_INFO "overo SoC init\n");
90
91 overo_snd_device = platform_device_alloc("soc-audio", -1);
92 if (!overo_snd_device) {
93 printk(KERN_ERR "Platform device allocation failed\n");
94 return -ENOMEM;
95 }
96
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000097 platform_set_drvdata(overo_snd_device, &snd_soc_card_overo);
Steve Sakoman4e207872008-10-30 21:50:13 -070098
99 ret = platform_device_add(overo_snd_device);
100 if (ret)
101 goto err1;
102
103 return 0;
104
105err1:
106 printk(KERN_ERR "Unable to add platform device\n");
107 platform_device_put(overo_snd_device);
108
109 return ret;
110}
111module_init(overo_soc_init);
112
113static void __exit overo_soc_exit(void)
114{
115 platform_device_unregister(overo_snd_device);
116}
117module_exit(overo_soc_exit);
118
119MODULE_AUTHOR("Steve Sakoman <steve@sakoman.com>");
120MODULE_DESCRIPTION("ALSA SoC overo");
121MODULE_LICENSE("GPL");