blob: aa4053bf6710f88cd50d9d3225754152e7caa435 [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>
Arun KS17f9ecf2008-10-02 15:02:45 +053031#include <linux/gpio.h>
Paul Gortmakerda155d52011-07-15 12:38:28 -040032#include <linux/module.h>
Arnd Bergmann22037472012-08-24 15:21:06 +020033#include <linux/platform_data/asoc-ti-mcbsp.h>
Arun KS17f9ecf2008-10-02 15:02:45 +053034
35#include "omap-mcbsp.h"
Arun KS17f9ecf2008-10-02 15:02:45 +053036#include "../codecs/tlv320aic23.h"
37
38#define CODEC_CLOCK 12000000
39
40static struct clk *tlv320aic23_mclk;
41
42static int osk_startup(struct snd_pcm_substream *substream)
43{
44 return clk_enable(tlv320aic23_mclk);
45}
46
47static void osk_shutdown(struct snd_pcm_substream *substream)
48{
49 clk_disable(tlv320aic23_mclk);
50}
51
52static int osk_hw_params(struct snd_pcm_substream *substream,
53 struct snd_pcm_hw_params *params)
54{
55 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000056 struct snd_soc_dai *codec_dai = rtd->codec_dai;
Arun KS17f9ecf2008-10-02 15:02:45 +053057 int err;
58
Arun KS17f9ecf2008-10-02 15:02:45 +053059 /* Set the codec system clock for DAC and ADC */
60 err =
61 snd_soc_dai_set_sysclk(codec_dai, 0, CODEC_CLOCK, SND_SOC_CLOCK_IN);
62
63 if (err < 0) {
64 printk(KERN_ERR "can't set codec system clock\n");
65 return err;
66 }
67
68 return err;
69}
70
71static struct snd_soc_ops osk_ops = {
72 .startup = osk_startup,
73 .hw_params = osk_hw_params,
74 .shutdown = osk_shutdown,
75};
76
77static const struct snd_soc_dapm_widget tlv320aic23_dapm_widgets[] = {
78 SND_SOC_DAPM_HP("Headphone Jack", NULL),
79 SND_SOC_DAPM_LINE("Line In", NULL),
80 SND_SOC_DAPM_MIC("Mic Jack", NULL),
81};
82
83static const struct snd_soc_dapm_route audio_map[] = {
84 {"Headphone Jack", NULL, "LHPOUT"},
85 {"Headphone Jack", NULL, "RHPOUT"},
86
87 {"LLINEIN", NULL, "Line In"},
88 {"RLINEIN", NULL, "Line In"},
89
90 {"MICIN", NULL, "Mic Jack"},
91};
92
Arun KS17f9ecf2008-10-02 15:02:45 +053093/* Digital audio interface glue - connects codec <--> CPU */
94static struct snd_soc_dai_link osk_dai = {
95 .name = "TLV320AIC23",
96 .stream_name = "AIC23",
Peter Ujfalusi45656b42012-02-14 18:20:58 +020097 .cpu_dai_name = "omap-mcbsp.1",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000098 .codec_dai_name = "tlv320aic23-hifi",
Peter Ujfalusib29064a2014-04-16 15:46:27 +030099 .platform_name = "omap-mcbsp.1",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000100 .codec_name = "tlv320aic23-codec",
Jarkko Nikulacf9feff2011-09-30 16:07:45 +0300101 .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_NB_NF |
102 SND_SOC_DAIFMT_CBM_CFM,
Arun KS17f9ecf2008-10-02 15:02:45 +0530103 .ops = &osk_ops,
104};
105
106/* Audio machine driver */
Mark Brown87506542008-11-18 20:50:34 +0000107static struct snd_soc_card snd_soc_card_osk = {
Arun KS17f9ecf2008-10-02 15:02:45 +0530108 .name = "OSK5912",
Axel Linb425b882011-12-22 11:08:59 +0800109 .owner = THIS_MODULE,
Arun KS17f9ecf2008-10-02 15:02:45 +0530110 .dai_link = &osk_dai,
111 .num_links = 1,
Peter Ujfalusi93b4d792011-10-10 15:34:11 +0300112
113 .dapm_widgets = tlv320aic23_dapm_widgets,
114 .num_dapm_widgets = ARRAY_SIZE(tlv320aic23_dapm_widgets),
115 .dapm_routes = audio_map,
116 .num_dapm_routes = ARRAY_SIZE(audio_map),
Arun KS17f9ecf2008-10-02 15:02:45 +0530117};
118
Arun KS17f9ecf2008-10-02 15:02:45 +0530119static struct platform_device *osk_snd_device;
120
121static int __init osk_soc_init(void)
122{
123 int err;
124 u32 curRate;
125 struct device *dev;
126
127 if (!(machine_is_omap_osk()))
128 return -ENODEV;
129
130 osk_snd_device = platform_device_alloc("soc-audio", -1);
131 if (!osk_snd_device)
132 return -ENOMEM;
133
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000134 platform_set_drvdata(osk_snd_device, &snd_soc_card_osk);
Arun KS17f9ecf2008-10-02 15:02:45 +0530135 err = platform_device_add(osk_snd_device);
136 if (err)
137 goto err1;
138
139 dev = &osk_snd_device->dev;
140
141 tlv320aic23_mclk = clk_get(dev, "mclk");
142 if (IS_ERR(tlv320aic23_mclk)) {
143 printk(KERN_ERR "Could not get mclk clock\n");
Axel Lin25436182010-11-24 22:24:01 +0800144 err = PTR_ERR(tlv320aic23_mclk);
145 goto err2;
Arun KS17f9ecf2008-10-02 15:02:45 +0530146 }
147
Arun KS17f9ecf2008-10-02 15:02:45 +0530148 /*
149 * Configure 12 MHz output on MCLK.
150 */
151 curRate = (uint) clk_get_rate(tlv320aic23_mclk);
152 if (curRate != CODEC_CLOCK) {
153 if (clk_set_rate(tlv320aic23_mclk, CODEC_CLOCK)) {
154 printk(KERN_ERR "Cannot set MCLK for AIC23 CODEC\n");
155 err = -ECANCELED;
Axel Lin25436182010-11-24 22:24:01 +0800156 goto err3;
Arun KS17f9ecf2008-10-02 15:02:45 +0530157 }
158 }
159
David Brownell5706d502009-03-11 02:37:25 -0800160 printk(KERN_INFO "MCLK = %d [%d]\n",
161 (uint) clk_get_rate(tlv320aic23_mclk), CODEC_CLOCK);
Arun KS17f9ecf2008-10-02 15:02:45 +0530162
163 return 0;
Axel Lin25436182010-11-24 22:24:01 +0800164
165err3:
Arun KS17f9ecf2008-10-02 15:02:45 +0530166 clk_put(tlv320aic23_mclk);
Axel Lin25436182010-11-24 22:24:01 +0800167err2:
Arun KS17f9ecf2008-10-02 15:02:45 +0530168 platform_device_del(osk_snd_device);
Axel Lin25436182010-11-24 22:24:01 +0800169err1:
Arun KS17f9ecf2008-10-02 15:02:45 +0530170 platform_device_put(osk_snd_device);
171
172 return err;
173
174}
175
176static void __exit osk_soc_exit(void)
177{
Axel Lin25436182010-11-24 22:24:01 +0800178 clk_put(tlv320aic23_mclk);
Arun KS17f9ecf2008-10-02 15:02:45 +0530179 platform_device_unregister(osk_snd_device);
180}
181
182module_init(osk_soc_init);
183module_exit(osk_soc_exit);
184
185MODULE_AUTHOR("Arun KS <arunks@mistralsolutions.com>");
186MODULE_DESCRIPTION("ALSA SoC OSK 5912");
187MODULE_LICENSE("GPL");