2 * osk5912.c -- SoC audio for OSK 5912
4 * Copyright (C) 2008 Mistral Solutions
6 * Contact: Arun KS <arunks@mistralsolutions.com>
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.
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.
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
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>
30 #include <asm/mach-types.h>
31 #include <mach/hardware.h>
32 #include <linux/gpio.h>
33 #include <plat/mcbsp.h>
35 #include "omap-mcbsp.h"
37 #include "../codecs/tlv320aic23.h"
39 #define CODEC_CLOCK 12000000
41 static struct clk
*tlv320aic23_mclk
;
43 static int osk_startup(struct snd_pcm_substream
*substream
)
45 return clk_enable(tlv320aic23_mclk
);
48 static void osk_shutdown(struct snd_pcm_substream
*substream
)
50 clk_disable(tlv320aic23_mclk
);
53 static int osk_hw_params(struct snd_pcm_substream
*substream
,
54 struct snd_pcm_hw_params
*params
)
56 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
57 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
58 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
61 /* Set codec DAI configuration */
62 err
= snd_soc_dai_set_fmt(codec_dai
,
63 SND_SOC_DAIFMT_DSP_B
|
64 SND_SOC_DAIFMT_NB_NF
|
65 SND_SOC_DAIFMT_CBM_CFM
);
67 printk(KERN_ERR
"can't set codec DAI configuration\n");
71 /* Set cpu DAI configuration */
72 err
= snd_soc_dai_set_fmt(cpu_dai
,
73 SND_SOC_DAIFMT_DSP_B
|
74 SND_SOC_DAIFMT_NB_NF
|
75 SND_SOC_DAIFMT_CBM_CFM
);
77 printk(KERN_ERR
"can't set cpu DAI configuration\n");
81 /* Set the codec system clock for DAC and ADC */
83 snd_soc_dai_set_sysclk(codec_dai
, 0, CODEC_CLOCK
, SND_SOC_CLOCK_IN
);
86 printk(KERN_ERR
"can't set codec system clock\n");
93 static struct snd_soc_ops osk_ops
= {
94 .startup
= osk_startup
,
95 .hw_params
= osk_hw_params
,
96 .shutdown
= osk_shutdown
,
99 static 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
),
105 static const struct snd_soc_dapm_route audio_map
[] = {
106 {"Headphone Jack", NULL
, "LHPOUT"},
107 {"Headphone Jack", NULL
, "RHPOUT"},
109 {"LLINEIN", NULL
, "Line In"},
110 {"RLINEIN", NULL
, "Line In"},
112 {"MICIN", NULL
, "Mic Jack"},
115 static int osk_tlv320aic23_init(struct snd_soc_pcm_runtime
*rtd
)
117 struct snd_soc_codec
*codec
= rtd
->codec
;
118 struct snd_soc_dapm_context
*dapm
= &codec
->dapm
;
120 /* Add osk5912 specific widgets */
121 snd_soc_dapm_new_controls(dapm
, tlv320aic23_dapm_widgets
,
122 ARRAY_SIZE(tlv320aic23_dapm_widgets
));
124 /* Set up osk5912 specific audio path audio_map */
125 snd_soc_dapm_add_routes(dapm
, audio_map
, ARRAY_SIZE(audio_map
));
127 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");
131 snd_soc_dapm_sync(dapm
);
136 /* Digital audio interface glue - connects codec <--> CPU */
137 static struct snd_soc_dai_link osk_dai
= {
138 .name
= "TLV320AIC23",
139 .stream_name
= "AIC23",
140 .cpu_dai_name
= "omap-mcbsp-dai.0",
141 .codec_dai_name
= "tlv320aic23-hifi",
142 .platform_name
= "omap-pcm-audio",
143 .codec_name
= "tlv320aic23-codec",
144 .init
= osk_tlv320aic23_init
,
148 /* Audio machine driver */
149 static struct snd_soc_card snd_soc_card_osk
= {
151 .dai_link
= &osk_dai
,
155 static struct platform_device
*osk_snd_device
;
157 static int __init
osk_soc_init(void)
163 if (!(machine_is_omap_osk()))
166 osk_snd_device
= platform_device_alloc("soc-audio", -1);
170 platform_set_drvdata(osk_snd_device
, &snd_soc_card_osk
);
171 err
= platform_device_add(osk_snd_device
);
175 dev
= &osk_snd_device
->dev
;
177 tlv320aic23_mclk
= clk_get(dev
, "mclk");
178 if (IS_ERR(tlv320aic23_mclk
)) {
179 printk(KERN_ERR
"Could not get mclk clock\n");
180 err
= PTR_ERR(tlv320aic23_mclk
);
185 * Configure 12 MHz output on MCLK.
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");
196 printk(KERN_INFO
"MCLK = %d [%d]\n",
197 (uint
) clk_get_rate(tlv320aic23_mclk
), CODEC_CLOCK
);
202 clk_put(tlv320aic23_mclk
);
204 platform_device_del(osk_snd_device
);
206 platform_device_put(osk_snd_device
);
212 static void __exit
osk_soc_exit(void)
214 clk_put(tlv320aic23_mclk
);
215 platform_device_unregister(osk_snd_device
);
218 module_init(osk_soc_init
);
219 module_exit(osk_soc_exit
);
221 MODULE_AUTHOR("Arun KS <arunks@mistralsolutions.com>");
222 MODULE_DESCRIPTION("ALSA SoC OSK 5912");
223 MODULE_LICENSE("GPL");