diff options
author | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-01-22 10:38:37 -0500 |
---|---|---|
committer | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-01-22 10:38:37 -0500 |
commit | fcc9d2e5a6c89d22b8b773a64fb4ad21ac318446 (patch) | |
tree | a57612d1888735a2ec7972891b68c1ac5ec8faea /sound/soc/omap/omap3beagle.c | |
parent | 8dea78da5cee153b8af9c07a2745f6c55057fe12 (diff) |
Diffstat (limited to 'sound/soc/omap/omap3beagle.c')
-rw-r--r-- | sound/soc/omap/omap3beagle.c | 149 |
1 files changed, 149 insertions, 0 deletions
diff --git a/sound/soc/omap/omap3beagle.c b/sound/soc/omap/omap3beagle.c new file mode 100644 index 00000000000..40db813c079 --- /dev/null +++ b/sound/soc/omap/omap3beagle.c | |||
@@ -0,0 +1,149 @@ | |||
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 | |||
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" | ||
35 | |||
36 | static int omap3beagle_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; | ||
40 | struct snd_soc_dai *codec_dai = rtd->codec_dai; | ||
41 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; | ||
42 | unsigned int fmt; | ||
43 | int ret; | ||
44 | |||
45 | switch (params_channels(params)) { | ||
46 | case 2: /* Stereo I2S mode */ | ||
47 | fmt = SND_SOC_DAIFMT_I2S | | ||
48 | SND_SOC_DAIFMT_NB_NF | | ||
49 | SND_SOC_DAIFMT_CBM_CFM; | ||
50 | break; | ||
51 | case 4: /* Four channel TDM mode */ | ||
52 | fmt = SND_SOC_DAIFMT_DSP_A | | ||
53 | SND_SOC_DAIFMT_IB_NF | | ||
54 | SND_SOC_DAIFMT_CBM_CFM; | ||
55 | break; | ||
56 | default: | ||
57 | return -EINVAL; | ||
58 | } | ||
59 | |||
60 | /* Set codec DAI configuration */ | ||
61 | ret = snd_soc_dai_set_fmt(codec_dai, fmt); | ||
62 | if (ret < 0) { | ||
63 | printk(KERN_ERR "can't set codec DAI configuration\n"); | ||
64 | return ret; | ||
65 | } | ||
66 | |||
67 | /* Set cpu DAI configuration */ | ||
68 | ret = snd_soc_dai_set_fmt(cpu_dai, fmt); | ||
69 | if (ret < 0) { | ||
70 | printk(KERN_ERR "can't set cpu DAI configuration\n"); | ||
71 | return ret; | ||
72 | } | ||
73 | |||
74 | /* Set the codec system clock for DAC and ADC */ | ||
75 | ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000, | ||
76 | SND_SOC_CLOCK_IN); | ||
77 | if (ret < 0) { | ||
78 | printk(KERN_ERR "can't set codec system clock\n"); | ||
79 | return ret; | ||
80 | } | ||
81 | |||
82 | return 0; | ||
83 | } | ||
84 | |||
85 | static struct snd_soc_ops omap3beagle_ops = { | ||
86 | .hw_params = omap3beagle_hw_params, | ||
87 | }; | ||
88 | |||
89 | /* Digital audio interface glue - connects codec <--> CPU */ | ||
90 | static struct snd_soc_dai_link omap3beagle_dai = { | ||
91 | .name = "TWL4030", | ||
92 | .stream_name = "TWL4030", | ||
93 | .cpu_dai_name = "omap-mcbsp-dai.1", | ||
94 | .platform_name = "omap-pcm-audio", | ||
95 | .codec_dai_name = "twl4030-hifi", | ||
96 | .codec_name = "twl4030-codec", | ||
97 | .ops = &omap3beagle_ops, | ||
98 | }; | ||
99 | |||
100 | /* Audio machine driver */ | ||
101 | static struct snd_soc_card snd_soc_omap3beagle = { | ||
102 | .name = "omap3beagle", | ||
103 | .owner = THIS_MODULE, | ||
104 | .dai_link = &omap3beagle_dai, | ||
105 | .num_links = 1, | ||
106 | }; | ||
107 | |||
108 | static struct platform_device *omap3beagle_snd_device; | ||
109 | |||
110 | static int __init omap3beagle_soc_init(void) | ||
111 | { | ||
112 | int ret; | ||
113 | |||
114 | if (!(machine_is_omap3_beagle() || machine_is_devkit8000())) | ||
115 | return -ENODEV; | ||
116 | pr_info("OMAP3 Beagle/Devkit8000 SoC init\n"); | ||
117 | |||
118 | omap3beagle_snd_device = platform_device_alloc("soc-audio", -1); | ||
119 | if (!omap3beagle_snd_device) { | ||
120 | printk(KERN_ERR "Platform device allocation failed\n"); | ||
121 | return -ENOMEM; | ||
122 | } | ||
123 | |||
124 | platform_set_drvdata(omap3beagle_snd_device, &snd_soc_omap3beagle); | ||
125 | |||
126 | ret = platform_device_add(omap3beagle_snd_device); | ||
127 | if (ret) | ||
128 | goto err1; | ||
129 | |||
130 | return 0; | ||
131 | |||
132 | err1: | ||
133 | printk(KERN_ERR "Unable to add platform device\n"); | ||
134 | platform_device_put(omap3beagle_snd_device); | ||
135 | |||
136 | return ret; | ||
137 | } | ||
138 | |||
139 | static void __exit omap3beagle_soc_exit(void) | ||
140 | { | ||
141 | platform_device_unregister(omap3beagle_snd_device); | ||
142 | } | ||
143 | |||
144 | module_init(omap3beagle_soc_init); | ||
145 | module_exit(omap3beagle_soc_exit); | ||
146 | |||
147 | MODULE_AUTHOR("Steve Sakoman <steve@sakoman.com>"); | ||
148 | MODULE_DESCRIPTION("ALSA SoC OMAP3 Beagle"); | ||
149 | MODULE_LICENSE("GPL"); | ||