blob: 0ae34702995ba6316cbe63defd1fd73d0948034f [file] [log] [blame]
Enric Balletbò i Serrab2a22362009-11-18 15:59:24 +01001/*
2 * igep0020.c -- SoC audio for IGEP v2
3 *
4 * Based on sound/soc/omap/overo.c by Steve Sakoman
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>
Enric Balletbò i Serrab2a22362009-11-18 15:59:24 +010027
28#include <asm/mach-types.h>
29#include <mach/hardware.h>
30#include <mach/gpio.h>
31#include <plat/mcbsp.h>
32
33#include "omap-mcbsp.h"
34#include "omap-pcm.h"
Enric Balletbò i Serrab2a22362009-11-18 15:59:24 +010035
36static int igep2_hw_params(struct snd_pcm_substream *substream,
37 struct snd_pcm_hw_params *params)
38{
39 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000040 struct snd_soc_dai *codec_dai = rtd->codec_dai;
41 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
Enric Balletbò i Serrab2a22362009-11-18 15:59:24 +010042 int ret;
43
44 /* Set codec DAI configuration */
45 ret = snd_soc_dai_set_fmt(codec_dai,
46 SND_SOC_DAIFMT_I2S |
47 SND_SOC_DAIFMT_NB_NF |
48 SND_SOC_DAIFMT_CBM_CFM);
49 if (ret < 0) {
50 printk(KERN_ERR "can't set codec DAI configuration\n");
51 return ret;
52 }
53
54 /* Set cpu DAI configuration */
55 ret = snd_soc_dai_set_fmt(cpu_dai,
56 SND_SOC_DAIFMT_I2S |
57 SND_SOC_DAIFMT_NB_NF |
58 SND_SOC_DAIFMT_CBM_CFM);
59 if (ret < 0) {
60 printk(KERN_ERR "can't set cpu DAI configuration\n");
61 return ret;
62 }
63
64 /* Set the codec system clock for DAC and ADC */
65 ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000,
66 SND_SOC_CLOCK_IN);
67 if (ret < 0) {
68 printk(KERN_ERR "can't set codec system clock\n");
69 return ret;
70 }
71
72 return 0;
73}
74
75static struct snd_soc_ops igep2_ops = {
76 .hw_params = igep2_hw_params,
77};
78
79/* Digital audio interface glue - connects codec <--> CPU */
80static struct snd_soc_dai_link igep2_dai = {
81 .name = "TWL4030",
82 .stream_name = "TWL4030",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000083 .cpu_dai_name = "omap-mcbsp-dai.1",
84 .codec_dai_name = "twl4030-hifi",
85 .platform_name = "omap-pcm-audio",
86 .codec_name = "twl4030-codec",
Enric Balletbò i Serrab2a22362009-11-18 15:59:24 +010087 .ops = &igep2_ops,
88};
89
90/* Audio machine driver */
91static struct snd_soc_card snd_soc_card_igep2 = {
92 .name = "igep2",
Enric Balletbò i Serrab2a22362009-11-18 15:59:24 +010093 .dai_link = &igep2_dai,
94 .num_links = 1,
95};
96
Enric Balletbò i Serrab2a22362009-11-18 15:59:24 +010097static struct platform_device *igep2_snd_device;
98
99static int __init igep2_soc_init(void)
100{
101 int ret;
102
Jarkko Nikulaec588ae2010-10-06 16:47:26 +0300103 if (!machine_is_igep0020())
Enric Balletbò i Serrab2a22362009-11-18 15:59:24 +0100104 return -ENODEV;
Enric Balletbò i Serrab2a22362009-11-18 15:59:24 +0100105 printk(KERN_INFO "IGEP v2 SoC init\n");
106
107 igep2_snd_device = platform_device_alloc("soc-audio", -1);
108 if (!igep2_snd_device) {
109 printk(KERN_ERR "Platform device allocation failed\n");
110 return -ENOMEM;
111 }
112
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000113 platform_set_drvdata(igep2_snd_device, &snd_soc_card_igep2);
Enric Balletbò i Serrab2a22362009-11-18 15:59:24 +0100114
115 ret = platform_device_add(igep2_snd_device);
116 if (ret)
117 goto err1;
118
119 return 0;
120
121err1:
122 printk(KERN_ERR "Unable to add platform device\n");
123 platform_device_put(igep2_snd_device);
124
125 return ret;
126}
127module_init(igep2_soc_init);
128
129static void __exit igep2_soc_exit(void)
130{
131 platform_device_unregister(igep2_snd_device);
132}
133module_exit(igep2_soc_exit);
134
135MODULE_AUTHOR("Enric Balletbo i Serra <eballetbo@iseebcn.com>");
136MODULE_DESCRIPTION("ALSA SoC IGEP v2");
137MODULE_LICENSE("GPL");