blob: 48af0f87f84d9c8f34519e40fcfdb04e43d1ba7b [file] [log] [blame]
Anuj Aggarwal89e9abe2009-10-30 00:22:30 +05301/*
2 * am3517evm.c -- ALSA SoC support for OMAP3517 / AM3517 EVM
3 *
4 * Author: Anuj Aggarwal <anuj.aggarwal@ti.com>
5 *
6 * Based on sound/soc/omap/beagle.c by Steve Sakoman
7 *
8 * Copyright (C) 2009 Texas Instruments Incorporated
9 *
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation version 2.
13 *
14 * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind,
15 * whether express or implied; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 */
19
20#include <linux/clk.h>
21#include <linux/platform_device.h>
22#include <sound/core.h>
23#include <sound/pcm.h>
24#include <sound/soc.h>
Anuj Aggarwal89e9abe2009-10-30 00:22:30 +053025
26#include <asm/mach-types.h>
27#include <mach/hardware.h>
28#include <mach/gpio.h>
29#include <plat/mcbsp.h>
30
31#include "omap-mcbsp.h"
32#include "omap-pcm.h"
33
34#include "../codecs/tlv320aic23.h"
35
36#define CODEC_CLOCK 12000000
37
38static int am3517evm_hw_params(struct snd_pcm_substream *substream,
39 struct snd_pcm_hw_params *params)
40{
41 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000042 struct snd_soc_dai *codec_dai = rtd->codec_dai;
43 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
Anuj Aggarwal89e9abe2009-10-30 00:22:30 +053044 int ret;
45
Anuj Aggarwal89e9abe2009-10-30 00:22:30 +053046 /* Set the codec system clock for DAC and ADC */
47 ret = snd_soc_dai_set_sysclk(codec_dai, 0,
48 CODEC_CLOCK, SND_SOC_CLOCK_IN);
49 if (ret < 0) {
50 printk(KERN_ERR "can't set codec system clock\n");
51 return ret;
52 }
53
54 ret = snd_soc_dai_set_sysclk(cpu_dai, OMAP_MCBSP_CLKR_SRC_CLKX, 0,
55 SND_SOC_CLOCK_IN);
56 if (ret < 0) {
57 printk(KERN_ERR "can't set CPU system clock OMAP_MCBSP_CLKR_SRC_CLKX\n");
58 return ret;
59 }
60
61 snd_soc_dai_set_sysclk(cpu_dai, OMAP_MCBSP_FSR_SRC_FSX, 0,
62 SND_SOC_CLOCK_IN);
63 if (ret < 0) {
64 printk(KERN_ERR "can't set CPU system clock OMAP_MCBSP_FSR_SRC_FSX\n");
65 return ret;
66 }
67
68 return 0;
69}
70
71static struct snd_soc_ops am3517evm_ops = {
72 .hw_params = am3517evm_hw_params,
73};
74
75/* am3517evm machine dapm widgets */
76static const struct snd_soc_dapm_widget tlv320aic23_dapm_widgets[] = {
77 SND_SOC_DAPM_HP("Line Out", NULL),
78 SND_SOC_DAPM_LINE("Line In", NULL),
79 SND_SOC_DAPM_MIC("Mic In", NULL),
80};
81
82static const struct snd_soc_dapm_route audio_map[] = {
83 /* Line Out connected to LLOUT, RLOUT */
84 {"Line Out", NULL, "LOUT"},
85 {"Line Out", NULL, "ROUT"},
86
87 {"LLINEIN", NULL, "Line In"},
88 {"RLINEIN", NULL, "Line In"},
89
90 {"MICIN", NULL, "Mic In"},
91};
92
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000093static int am3517evm_aic23_init(struct snd_soc_pcm_runtime *rtd)
Anuj Aggarwal89e9abe2009-10-30 00:22:30 +053094{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000095 struct snd_soc_codec *codec = rtd->codec;
Liam Girdwoodce6120c2010-11-05 15:53:46 +020096 struct snd_soc_dapm_context *dapm = &codec->dapm;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000097
Anuj Aggarwal89e9abe2009-10-30 00:22:30 +053098 /* Add am3517-evm specific widgets */
Liam Girdwoodce6120c2010-11-05 15:53:46 +020099 snd_soc_dapm_new_controls(dapm, tlv320aic23_dapm_widgets,
Anuj Aggarwal89e9abe2009-10-30 00:22:30 +0530100 ARRAY_SIZE(tlv320aic23_dapm_widgets));
101
102 /* Set up davinci-evm specific audio path audio_map */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200103 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
Anuj Aggarwal89e9abe2009-10-30 00:22:30 +0530104
105 /* always connected */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200106 snd_soc_dapm_enable_pin(dapm, "Line Out");
107 snd_soc_dapm_enable_pin(dapm, "Line In");
108 snd_soc_dapm_enable_pin(dapm, "Mic In");
Anuj Aggarwal89e9abe2009-10-30 00:22:30 +0530109
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200110 snd_soc_dapm_sync(dapm);
Anuj Aggarwal89e9abe2009-10-30 00:22:30 +0530111
112 return 0;
113}
114
115/* Digital audio interface glue - connects codec <--> CPU */
116static struct snd_soc_dai_link am3517evm_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",
Abhilash K Vffd6eae2011-03-08 21:02:43 +0530122 .codec_name = "tlv320aic23-codec.2-001a",
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,
Anuj Aggarwal89e9abe2009-10-30 00:22:30 +0530125 .init = am3517evm_aic23_init,
126 .ops = &am3517evm_ops,
127};
128
129/* Audio machine driver */
130static struct snd_soc_card snd_soc_am3517evm = {
131 .name = "am3517evm",
Anuj Aggarwal89e9abe2009-10-30 00:22:30 +0530132 .dai_link = &am3517evm_dai,
133 .num_links = 1,
134};
135
Anuj Aggarwal89e9abe2009-10-30 00:22:30 +0530136static struct platform_device *am3517evm_snd_device;
137
138static int __init am3517evm_soc_init(void)
139{
140 int ret;
141
Jarkko Nikulaec588ae2010-10-06 16:47:26 +0300142 if (!machine_is_omap3517evm())
Anuj Aggarwal89e9abe2009-10-30 00:22:30 +0530143 return -ENODEV;
Anuj Aggarwal89e9abe2009-10-30 00:22:30 +0530144 pr_info("OMAP3517 / AM3517 EVM SoC init\n");
145
146 am3517evm_snd_device = platform_device_alloc("soc-audio", -1);
147 if (!am3517evm_snd_device) {
148 printk(KERN_ERR "Platform device allocation failed\n");
149 return -ENOMEM;
150 }
151
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000152 platform_set_drvdata(am3517evm_snd_device, &snd_soc_am3517evm);
Anuj Aggarwal89e9abe2009-10-30 00:22:30 +0530153
154 ret = platform_device_add(am3517evm_snd_device);
155 if (ret)
156 goto err1;
157
158 return 0;
159
160err1:
161 printk(KERN_ERR "Unable to add platform device\n");
162 platform_device_put(am3517evm_snd_device);
163
164 return ret;
165}
166
167static void __exit am3517evm_soc_exit(void)
168{
169 platform_device_unregister(am3517evm_snd_device);
170}
171
172module_init(am3517evm_soc_init);
173module_exit(am3517evm_soc_exit);
174
175MODULE_AUTHOR("Anuj Aggarwal <anuj.aggarwal@ti.com>");
176MODULE_DESCRIPTION("ALSA SoC OMAP3517 / AM3517 EVM");
177MODULE_LICENSE("GPL v2");