]>
Commit | Line | Data |
---|---|---|
14610ce7 AA |
1 | /* |
2 | * omap3evm.c -- ALSA SoC support for OMAP3 EVM | |
3 | * | |
4 | * Author: Anuj Aggarwal <anuj.aggarwal@ti.com> | |
5 | * | |
6 | * Based on sound/soc/omap/beagle.c by Steve Sakoman | |
7 | * | |
8 | * Copyright (C) 2008 Texas Instruments, Incorporated | |
9 | * | |
10 | * This program is free software; you can redistribute it and/or modify it | |
11 | * under the terms of the GNU General Public License as published by the | |
12 | * Free Software Foundation version 2. | |
13 | * | |
14 | * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind, | |
15 | * whether express or implied; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
17 | * General Public License for more details. | |
18 | */ | |
19 | ||
20 | #include <linux/clk.h> | |
21 | #include <linux/platform_device.h> | |
22 | #include <sound/core.h> | |
23 | #include <sound/pcm.h> | |
24 | #include <sound/soc.h> | |
25 | #include <sound/soc-dapm.h> | |
26 | ||
27 | #include <asm/mach-types.h> | |
28 | #include <mach/hardware.h> | |
29 | #include <mach/gpio.h> | |
30 | #include <mach/mcbsp.h> | |
31 | ||
32 | #include "omap-mcbsp.h" | |
33 | #include "omap-pcm.h" | |
34 | #include "../codecs/twl4030.h" | |
35 | ||
36 | static int omap3evm_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->dai->codec_dai; | |
41 | struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai; | |
42 | 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 | ||
75 | static struct snd_soc_ops omap3evm_ops = { | |
76 | .hw_params = omap3evm_hw_params, | |
77 | }; | |
78 | ||
79 | /* Digital audio interface glue - connects codec <--> CPU */ | |
80 | static struct snd_soc_dai_link omap3evm_dai = { | |
81 | .name = "TWL4030", | |
82 | .stream_name = "TWL4030", | |
83 | .cpu_dai = &omap_mcbsp_dai[0], | |
84 | .codec_dai = &twl4030_dai[TWL4030_DAI_HIFI], | |
85 | .ops = &omap3evm_ops, | |
86 | }; | |
87 | ||
88 | /* Audio machine driver */ | |
89 | static struct snd_soc_card snd_soc_omap3evm = { | |
90 | .name = "omap3evm", | |
91 | .platform = &omap_soc_platform, | |
92 | .dai_link = &omap3evm_dai, | |
93 | .num_links = 1, | |
94 | }; | |
95 | ||
96 | /* Audio subsystem */ | |
97 | static struct snd_soc_device omap3evm_snd_devdata = { | |
98 | .card = &snd_soc_omap3evm, | |
99 | .codec_dev = &soc_codec_dev_twl4030, | |
100 | }; | |
101 | ||
102 | static struct platform_device *omap3evm_snd_device; | |
103 | ||
104 | static int __init omap3evm_soc_init(void) | |
105 | { | |
106 | int ret; | |
107 | ||
108 | if (!machine_is_omap3evm()) { | |
109 | pr_err("Not OMAP3 EVM!\n"); | |
110 | return -ENODEV; | |
111 | } | |
112 | pr_info("OMAP3 EVM SoC init\n"); | |
113 | ||
114 | omap3evm_snd_device = platform_device_alloc("soc-audio", -1); | |
115 | if (!omap3evm_snd_device) { | |
116 | printk(KERN_ERR "Platform device allocation failed\n"); | |
117 | return -ENOMEM; | |
118 | } | |
119 | ||
120 | platform_set_drvdata(omap3evm_snd_device, &omap3evm_snd_devdata); | |
121 | omap3evm_snd_devdata.dev = &omap3evm_snd_device->dev; | |
122 | *(unsigned int *)omap3evm_dai.cpu_dai->private_data = 1; | |
123 | ||
124 | ret = platform_device_add(omap3evm_snd_device); | |
125 | if (ret) | |
126 | goto err1; | |
127 | ||
128 | return 0; | |
129 | ||
130 | err1: | |
131 | printk(KERN_ERR "Unable to add platform device\n"); | |
132 | platform_device_put(omap3evm_snd_device); | |
133 | ||
134 | return ret; | |
135 | } | |
136 | ||
137 | static void __exit omap3evm_soc_exit(void) | |
138 | { | |
139 | platform_device_unregister(omap3evm_snd_device); | |
140 | } | |
141 | ||
142 | module_init(omap3evm_soc_init); | |
143 | module_exit(omap3evm_soc_exit); | |
144 | ||
145 | MODULE_AUTHOR("Anuj Aggarwal <anuj.aggarwal@ti.com>"); | |
146 | MODULE_DESCRIPTION("ALSA SoC OMAP3 EVM"); | |
147 | MODULE_LICENSE("GPLv2"); |