blob: 7e75e775fb4a8943eea07911aa289ac98390b7d4 [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;
58 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
Arun KS17f9ecf2008-10-02 15:02:45 +053059 int err;
60
61 /* Set codec DAI configuration */
62 err = snd_soc_dai_set_fmt(codec_dai,
Jarkko Nikulabd258672008-12-22 10:21:36 +020063 SND_SOC_DAIFMT_DSP_B |
Jarkko Nikula002fbad2009-04-15 13:48:17 +030064 SND_SOC_DAIFMT_NB_NF |
Arun KS17f9ecf2008-10-02 15:02:45 +053065 SND_SOC_DAIFMT_CBM_CFM);
66 if (err < 0) {
67 printk(KERN_ERR "can't set codec DAI configuration\n");
68 return err;
69 }
70
71 /* Set cpu DAI configuration */
72 err = snd_soc_dai_set_fmt(cpu_dai,
Jarkko Nikulabd258672008-12-22 10:21:36 +020073 SND_SOC_DAIFMT_DSP_B |
Jarkko Nikula002fbad2009-04-15 13:48:17 +030074 SND_SOC_DAIFMT_NB_NF |
Arun KS17f9ecf2008-10-02 15:02:45 +053075 SND_SOC_DAIFMT_CBM_CFM);
76 if (err < 0) {
77 printk(KERN_ERR "can't set cpu DAI configuration\n");
78 return err;
79 }
80
81 /* Set the codec system clock for DAC and ADC */
82 err =
83 snd_soc_dai_set_sysclk(codec_dai, 0, CODEC_CLOCK, SND_SOC_CLOCK_IN);
84
85 if (err < 0) {
86 printk(KERN_ERR "can't set codec system clock\n");
87 return err;
88 }
89
90 return err;
91}
92
93static struct snd_soc_ops osk_ops = {
94 .startup = osk_startup,
95 .hw_params = osk_hw_params,
96 .shutdown = osk_shutdown,
97};
98
99static const struct snd_soc_dapm_widget tlv320aic23_dapm_widgets[] = {
100 SND_SOC_DAPM_HP("Headphone Jack", NULL),
101 SND_SOC_DAPM_LINE("Line In", NULL),
102 SND_SOC_DAPM_MIC("Mic Jack", NULL),
103};
104
105static const struct snd_soc_dapm_route audio_map[] = {
106 {"Headphone Jack", NULL, "LHPOUT"},
107 {"Headphone Jack", NULL, "RHPOUT"},
108
109 {"LLINEIN", NULL, "Line In"},
110 {"RLINEIN", NULL, "Line In"},
111
112 {"MICIN", NULL, "Mic Jack"},
113};
114
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000115static int osk_tlv320aic23_init(struct snd_soc_pcm_runtime *rtd)
Arun KS17f9ecf2008-10-02 15:02:45 +0530116{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000117 struct snd_soc_codec *codec = rtd->codec;
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200118 struct snd_soc_dapm_context *dapm = &codec->dapm;
Arun KS17f9ecf2008-10-02 15:02:45 +0530119
120 /* Add osk5912 specific widgets */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200121 snd_soc_dapm_new_controls(dapm, tlv320aic23_dapm_widgets,
Arun KS17f9ecf2008-10-02 15:02:45 +0530122 ARRAY_SIZE(tlv320aic23_dapm_widgets));
123
124 /* Set up osk5912 specific audio path audio_map */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200125 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
Arun KS17f9ecf2008-10-02 15:02:45 +0530126
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200127 snd_soc_dapm_enable_pin(dapm, "Headphone Jack");
128 snd_soc_dapm_enable_pin(dapm, "Line In");
129 snd_soc_dapm_enable_pin(dapm, "Mic Jack");
Arun KS17f9ecf2008-10-02 15:02:45 +0530130
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200131 snd_soc_dapm_sync(dapm);
Arun KS17f9ecf2008-10-02 15:02:45 +0530132
133 return 0;
134}
135
136/* Digital audio interface glue - connects codec <--> CPU */
137static struct snd_soc_dai_link osk_dai = {
138 .name = "TLV320AIC23",
139 .stream_name = "AIC23",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000140 .cpu_dai_name = "omap-mcbsp-dai.0",
141 .codec_dai_name = "tlv320aic23-hifi",
142 .platform_name = "omap-pcm-audio",
143 .codec_name = "tlv320aic23-codec",
Arun KS17f9ecf2008-10-02 15:02:45 +0530144 .init = osk_tlv320aic23_init,
145 .ops = &osk_ops,
146};
147
148/* Audio machine driver */
Mark Brown87506542008-11-18 20:50:34 +0000149static struct snd_soc_card snd_soc_card_osk = {
Arun KS17f9ecf2008-10-02 15:02:45 +0530150 .name = "OSK5912",
151 .dai_link = &osk_dai,
152 .num_links = 1,
153};
154
Arun KS17f9ecf2008-10-02 15:02:45 +0530155static struct platform_device *osk_snd_device;
156
157static int __init osk_soc_init(void)
158{
159 int err;
160 u32 curRate;
161 struct device *dev;
162
163 if (!(machine_is_omap_osk()))
164 return -ENODEV;
165
166 osk_snd_device = platform_device_alloc("soc-audio", -1);
167 if (!osk_snd_device)
168 return -ENOMEM;
169
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000170 platform_set_drvdata(osk_snd_device, &snd_soc_card_osk);
Arun KS17f9ecf2008-10-02 15:02:45 +0530171 err = platform_device_add(osk_snd_device);
172 if (err)
173 goto err1;
174
175 dev = &osk_snd_device->dev;
176
177 tlv320aic23_mclk = clk_get(dev, "mclk");
178 if (IS_ERR(tlv320aic23_mclk)) {
179 printk(KERN_ERR "Could not get mclk clock\n");
Axel Lin25436182010-11-24 22:24:01 +0800180 err = PTR_ERR(tlv320aic23_mclk);
181 goto err2;
Arun KS17f9ecf2008-10-02 15:02:45 +0530182 }
183
Arun KS17f9ecf2008-10-02 15:02:45 +0530184 /*
185 * Configure 12 MHz output on MCLK.
186 */
187 curRate = (uint) clk_get_rate(tlv320aic23_mclk);
188 if (curRate != CODEC_CLOCK) {
189 if (clk_set_rate(tlv320aic23_mclk, CODEC_CLOCK)) {
190 printk(KERN_ERR "Cannot set MCLK for AIC23 CODEC\n");
191 err = -ECANCELED;
Axel Lin25436182010-11-24 22:24:01 +0800192 goto err3;
Arun KS17f9ecf2008-10-02 15:02:45 +0530193 }
194 }
195
David Brownell5706d502009-03-11 02:37:25 -0800196 printk(KERN_INFO "MCLK = %d [%d]\n",
197 (uint) clk_get_rate(tlv320aic23_mclk), CODEC_CLOCK);
Arun KS17f9ecf2008-10-02 15:02:45 +0530198
199 return 0;
Axel Lin25436182010-11-24 22:24:01 +0800200
201err3:
Arun KS17f9ecf2008-10-02 15:02:45 +0530202 clk_put(tlv320aic23_mclk);
Axel Lin25436182010-11-24 22:24:01 +0800203err2:
Arun KS17f9ecf2008-10-02 15:02:45 +0530204 platform_device_del(osk_snd_device);
Axel Lin25436182010-11-24 22:24:01 +0800205err1:
Arun KS17f9ecf2008-10-02 15:02:45 +0530206 platform_device_put(osk_snd_device);
207
208 return err;
209
210}
211
212static void __exit osk_soc_exit(void)
213{
Axel Lin25436182010-11-24 22:24:01 +0800214 clk_put(tlv320aic23_mclk);
Arun KS17f9ecf2008-10-02 15:02:45 +0530215 platform_device_unregister(osk_snd_device);
216}
217
218module_init(osk_soc_init);
219module_exit(osk_soc_exit);
220
221MODULE_AUTHOR("Arun KS <arunks@mistralsolutions.com>");
222MODULE_DESCRIPTION("ALSA SoC OSK 5912");
223MODULE_LICENSE("GPL");