1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24#include <linux/clk.h>
25#include <linux/platform_device.h>
26#include <sound/core.h>
27#include <sound/pcm.h>
28#include <sound/soc.h>
29
30#include <asm/mach-types.h>
31#include <linux/gpio.h>
32#include <linux/module.h>
33#include <linux/platform_data/asoc-ti-mcbsp.h>
34
35#include "omap-mcbsp.h"
36#include "omap-pcm.h"
37#include "../codecs/tlv320aic23.h"
38
39#define CODEC_CLOCK 12000000
40
41static struct clk *tlv320aic23_mclk;
42
43static int osk_startup(struct snd_pcm_substream *substream)
44{
45 return clk_enable(tlv320aic23_mclk);
46}
47
48static void osk_shutdown(struct snd_pcm_substream *substream)
49{
50 clk_disable(tlv320aic23_mclk);
51}
52
53static int osk_hw_params(struct snd_pcm_substream *substream,
54 struct snd_pcm_hw_params *params)
55{
56 struct snd_soc_pcm_runtime *rtd = substream->private_data;
57 struct snd_soc_dai *codec_dai = rtd->codec_dai;
58 int err;
59
60
61 err =
62 snd_soc_dai_set_sysclk(codec_dai, 0, CODEC_CLOCK, SND_SOC_CLOCK_IN);
63
64 if (err < 0) {
65 printk(KERN_ERR "can't set codec system clock\n");
66 return err;
67 }
68
69 return err;
70}
71
72static struct snd_soc_ops osk_ops = {
73 .startup = osk_startup,
74 .hw_params = osk_hw_params,
75 .shutdown = osk_shutdown,
76};
77
78static const struct snd_soc_dapm_widget tlv320aic23_dapm_widgets[] = {
79 SND_SOC_DAPM_HP("Headphone Jack", NULL),
80 SND_SOC_DAPM_LINE("Line In", NULL),
81 SND_SOC_DAPM_MIC("Mic Jack", NULL),
82};
83
84static const struct snd_soc_dapm_route audio_map[] = {
85 {"Headphone Jack", NULL, "LHPOUT"},
86 {"Headphone Jack", NULL, "RHPOUT"},
87
88 {"LLINEIN", NULL, "Line In"},
89 {"RLINEIN", NULL, "Line In"},
90
91 {"MICIN", NULL, "Mic Jack"},
92};
93
94
95static struct snd_soc_dai_link osk_dai = {
96 .name = "TLV320AIC23",
97 .stream_name = "AIC23",
98 .cpu_dai_name = "omap-mcbsp.1",
99 .codec_dai_name = "tlv320aic23-hifi",
100 .platform_name = "omap-pcm-audio",
101 .codec_name = "tlv320aic23-codec",
102 .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_NB_NF |
103 SND_SOC_DAIFMT_CBM_CFM,
104 .ops = &osk_ops,
105};
106
107
108static struct snd_soc_card snd_soc_card_osk = {
109 .name = "OSK5912",
110 .owner = THIS_MODULE,
111 .dai_link = &osk_dai,
112 .num_links = 1,
113
114 .dapm_widgets = tlv320aic23_dapm_widgets,
115 .num_dapm_widgets = ARRAY_SIZE(tlv320aic23_dapm_widgets),
116 .dapm_routes = audio_map,
117 .num_dapm_routes = ARRAY_SIZE(audio_map),
118};
119
120static struct platform_device *osk_snd_device;
121
122static int __init osk_soc_init(void)
123{
124 int err;
125 u32 curRate;
126 struct device *dev;
127
128 if (!(machine_is_omap_osk()))
129 return -ENODEV;
130
131 osk_snd_device = platform_device_alloc("soc-audio", -1);
132 if (!osk_snd_device)
133 return -ENOMEM;
134
135 platform_set_drvdata(osk_snd_device, &snd_soc_card_osk);
136 err = platform_device_add(osk_snd_device);
137 if (err)
138 goto err1;
139
140 dev = &osk_snd_device->dev;
141
142 tlv320aic23_mclk = clk_get(dev, "mclk");
143 if (IS_ERR(tlv320aic23_mclk)) {
144 printk(KERN_ERR "Could not get mclk clock\n");
145 err = PTR_ERR(tlv320aic23_mclk);
146 goto err2;
147 }
148
149
150
151
152 curRate = (uint) clk_get_rate(tlv320aic23_mclk);
153 if (curRate != CODEC_CLOCK) {
154 if (clk_set_rate(tlv320aic23_mclk, CODEC_CLOCK)) {
155 printk(KERN_ERR "Cannot set MCLK for AIC23 CODEC\n");
156 err = -ECANCELED;
157 goto err3;
158 }
159 }
160
161 printk(KERN_INFO "MCLK = %d [%d]\n",
162 (uint) clk_get_rate(tlv320aic23_mclk), CODEC_CLOCK);
163
164 return 0;
165
166err3:
167 clk_put(tlv320aic23_mclk);
168err2:
169 platform_device_del(osk_snd_device);
170err1:
171 platform_device_put(osk_snd_device);
172
173 return err;
174
175}
176
177static void __exit osk_soc_exit(void)
178{
179 clk_put(tlv320aic23_mclk);
180 platform_device_unregister(osk_snd_device);
181}
182
183module_init(osk_soc_init);
184module_exit(osk_soc_exit);
185
186MODULE_AUTHOR("Arun KS <arunks@mistralsolutions.com>");
187MODULE_DESCRIPTION("ALSA SoC OSK 5912");
188MODULE_LICENSE("GPL");
189