]>
Commit | Line | Data |
---|---|---|
dc06102a SS |
1 | /* |
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> | |
ce491cf8 | 32 | #include <plat/mcbsp.h> |
dc06102a SS |
33 | |
34 | #include "omap-mcbsp.h" | |
35 | #include "omap-pcm.h" | |
dc06102a SS |
36 | |
37 | static 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; | |
f0fba2ad LG |
41 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
42 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; | |
a8353a57 | 43 | unsigned int fmt; |
dc06102a SS |
44 | int ret; |
45 | ||
a8353a57 PU |
46 | 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 | ||
dc06102a | 61 | /* Set codec DAI configuration */ |
a8353a57 | 62 | ret = snd_soc_dai_set_fmt(codec_dai, fmt); |
dc06102a SS |
63 | if (ret < 0) { |
64 | printk(KERN_ERR "can't set codec DAI configuration\n"); | |
65 | return ret; | |
66 | } | |
67 | ||
68 | /* Set cpu DAI configuration */ | |
a8353a57 | 69 | ret = snd_soc_dai_set_fmt(cpu_dai, fmt); |
dc06102a SS |
70 | 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 | ||
86 | static struct snd_soc_ops omap3beagle_ops = { | |
87 | .hw_params = omap3beagle_hw_params, | |
88 | }; | |
89 | ||
90 | /* Digital audio interface glue - connects codec <--> CPU */ | |
91 | static struct snd_soc_dai_link omap3beagle_dai = { | |
92 | .name = "TWL4030", | |
93 | .stream_name = "TWL4030", | |
f0fba2ad LG |
94 | .cpu_dai_name = "omap-mcbsp-dai.1", |
95 | .platform_name = "omap-pcm-audio", | |
96 | .codec_dai_name = "twl4030-hifi", | |
97 | .codec_name = "twl4030-codec", | |
dc06102a SS |
98 | .ops = &omap3beagle_ops, |
99 | }; | |
100 | ||
101 | /* Audio machine driver */ | |
87506549 | 102 | static struct snd_soc_card snd_soc_omap3beagle = { |
dc06102a | 103 | .name = "omap3beagle", |
f0fba2ad | 104 | .owner = THIS_MODULE, |
dc06102a SS |
105 | .dai_link = &omap3beagle_dai, |
106 | .num_links = 1, | |
107 | }; | |
108 | ||
dc06102a SS |
109 | static struct platform_device *omap3beagle_snd_device; |
110 | ||
111 | static int __init omap3beagle_soc_init(void) | |
112 | { | |
113 | int ret; | |
114 | ||
ec588ae6 | 115 | if (!(machine_is_omap3_beagle() || machine_is_devkit8000())) |
dc06102a | 116 | return -ENODEV; |
867af973 | 117 | pr_info("OMAP3 Beagle/Devkit8000 SoC init\n"); |
dc06102a SS |
118 | |
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 | ||
f0fba2ad | 125 | platform_set_drvdata(omap3beagle_snd_device, &snd_soc_omap3beagle); |
dc06102a SS |
126 | |
127 | ret = platform_device_add(omap3beagle_snd_device); | |
128 | if (ret) | |
129 | goto err1; | |
130 | ||
131 | return 0; | |
132 | ||
133 | err1: | |
134 | printk(KERN_ERR "Unable to add platform device\n"); | |
135 | platform_device_put(omap3beagle_snd_device); | |
136 | ||
137 | return ret; | |
138 | } | |
139 | ||
140 | static void __exit omap3beagle_soc_exit(void) | |
141 | { | |
142 | platform_device_unregister(omap3beagle_snd_device); | |
143 | } | |
144 | ||
145 | module_init(omap3beagle_soc_init); | |
146 | module_exit(omap3beagle_soc_exit); | |
147 | ||
148 | MODULE_AUTHOR("Steve Sakoman <steve@sakoman.com>"); | |
149 | MODULE_DESCRIPTION("ALSA SoC OMAP3 Beagle"); | |
150 | MODULE_LICENSE("GPL"); |