blob: 597833246e3ad7d8a4cc14b2806638c2142ad167 [file] [log] [blame]
Arun KS17f9ecf2008-10-02 15:02:45 +05301/*
2 * osk5912.c -- SoC audio for OSK 5912
3 *
4 * Copyright (C) 2008 Mistral Solutions
5 *
6 * Contact: Arun KS <arunks@mistralsolutions.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
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>
Arun KS17f9ecf2008-10-02 15:02:45 +053029
30#include <asm/mach-types.h>
31#include <mach/hardware.h>
32#include <linux/gpio.h>
Tony Lindgrence491cf2009-10-20 09:40:47 -070033#include <plat/mcbsp.h>
Arun KS17f9ecf2008-10-02 15:02:45 +053034
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;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000057 struct snd_soc_dai *codec_dai = rtd->codec_dai;
Arun KS17f9ecf2008-10-02 15:02:45 +053058 int err;
59
Arun KS17f9ecf2008-10-02 15:02:45 +053060 /* Set the codec system clock for DAC and ADC */
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
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000094static int osk_tlv320aic23_init(struct snd_soc_pcm_runtime *rtd)
Arun KS17f9ecf2008-10-02 15:02:45 +053095{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000096 struct snd_soc_codec *codec = rtd->codec;
Liam Girdwoodce6120c2010-11-05 15:53:46 +020097 struct snd_soc_dapm_context *dapm = &codec->dapm;
Arun KS17f9ecf2008-10-02 15:02:45 +053098
99 /* Add osk5912 specific widgets */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200100 snd_soc_dapm_new_controls(dapm, tlv320aic23_dapm_widgets,
Arun KS17f9ecf2008-10-02 15:02:45 +0530101 ARRAY_SIZE(tlv320aic23_dapm_widgets));
102
103 /* Set up osk5912 specific audio path audio_map */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200104 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
Arun KS17f9ecf2008-10-02 15:02:45 +0530105
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200106 snd_soc_dapm_enable_pin(dapm, "Headphone Jack");
107 snd_soc_dapm_enable_pin(dapm, "Line In");
108 snd_soc_dapm_enable_pin(dapm, "Mic Jack");
Arun KS17f9ecf2008-10-02 15:02:45 +0530109
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200110 snd_soc_dapm_sync(dapm);
Arun KS17f9ecf2008-10-02 15:02:45 +0530111
112 return 0;
113}
114
115/* Digital audio interface glue - connects codec <--> CPU */
116static struct snd_soc_dai_link osk_dai = {
117 .name = "TLV320AIC23",
118 .stream_name = "AIC23",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000119 .cpu_dai_name = "omap-mcbsp-dai.0",
120 .codec_dai_name = "tlv320aic23-hifi",
121 .platform_name = "omap-pcm-audio",
122 .codec_name = "tlv320aic23-codec",
Jarkko Nikulacf9feff2011-09-30 16:07:45 +0300123 .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_NB_NF |
124 SND_SOC_DAIFMT_CBM_CFM,
Arun KS17f9ecf2008-10-02 15:02:45 +0530125 .init = osk_tlv320aic23_init,
126 .ops = &osk_ops,
127};
128
129/* Audio machine driver */
Mark Brown87506542008-11-18 20:50:34 +0000130static struct snd_soc_card snd_soc_card_osk = {
Arun KS17f9ecf2008-10-02 15:02:45 +0530131 .name = "OSK5912",
132 .dai_link = &osk_dai,
133 .num_links = 1,
134};
135
Arun KS17f9ecf2008-10-02 15:02:45 +0530136static struct platform_device *osk_snd_device;
137
138static int __init osk_soc_init(void)
139{
140 int err;
141 u32 curRate;
142 struct device *dev;
143
144 if (!(machine_is_omap_osk()))
145 return -ENODEV;
146
147 osk_snd_device = platform_device_alloc("soc-audio", -1);
148 if (!osk_snd_device)
149 return -ENOMEM;
150
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000151 platform_set_drvdata(osk_snd_device, &snd_soc_card_osk);
Arun KS17f9ecf2008-10-02 15:02:45 +0530152 err = platform_device_add(osk_snd_device);
153 if (err)
154 goto err1;
155
156 dev = &osk_snd_device->dev;
157
158 tlv320aic23_mclk = clk_get(dev, "mclk");
159 if (IS_ERR(tlv320aic23_mclk)) {
160 printk(KERN_ERR "Could not get mclk clock\n");
Axel Lin25436182010-11-24 22:24:01 +0800161 err = PTR_ERR(tlv320aic23_mclk);
162 goto err2;
Arun KS17f9ecf2008-10-02 15:02:45 +0530163 }
164
Arun KS17f9ecf2008-10-02 15:02:45 +0530165 /*
166 * Configure 12 MHz output on MCLK.
167 */
168 curRate = (uint) clk_get_rate(tlv320aic23_mclk);
169 if (curRate != CODEC_CLOCK) {
170 if (clk_set_rate(tlv320aic23_mclk, CODEC_CLOCK)) {
171 printk(KERN_ERR "Cannot set MCLK for AIC23 CODEC\n");
172 err = -ECANCELED;
Axel Lin25436182010-11-24 22:24:01 +0800173 goto err3;
Arun KS17f9ecf2008-10-02 15:02:45 +0530174 }
175 }
176
David Brownell5706d502009-03-11 02:37:25 -0800177 printk(KERN_INFO "MCLK = %d [%d]\n",
178 (uint) clk_get_rate(tlv320aic23_mclk), CODEC_CLOCK);
Arun KS17f9ecf2008-10-02 15:02:45 +0530179
180 return 0;
Axel Lin25436182010-11-24 22:24:01 +0800181
182err3:
Arun KS17f9ecf2008-10-02 15:02:45 +0530183 clk_put(tlv320aic23_mclk);
Axel Lin25436182010-11-24 22:24:01 +0800184err2:
Arun KS17f9ecf2008-10-02 15:02:45 +0530185 platform_device_del(osk_snd_device);
Axel Lin25436182010-11-24 22:24:01 +0800186err1:
Arun KS17f9ecf2008-10-02 15:02:45 +0530187 platform_device_put(osk_snd_device);
188
189 return err;
190
191}
192
193static void __exit osk_soc_exit(void)
194{
Axel Lin25436182010-11-24 22:24:01 +0800195 clk_put(tlv320aic23_mclk);
Arun KS17f9ecf2008-10-02 15:02:45 +0530196 platform_device_unregister(osk_snd_device);
197}
198
199module_init(osk_soc_init);
200module_exit(osk_soc_exit);
201
202MODULE_AUTHOR("Arun KS <arunks@mistralsolutions.com>");
203MODULE_DESCRIPTION("ALSA SoC OSK 5912");
204MODULE_LICENSE("GPL");