2 * am3517evm.c -- ALSA SoC support for OMAP3517 / AM3517 EVM
4 * Author: Anuj Aggarwal <anuj.aggarwal@ti.com>
6 * Based on sound/soc/omap/beagle.c by Steve Sakoman
8 * Copyright (C) 2009 Texas Instruments Incorporated
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.
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.
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>
26 #include <asm/mach-types.h>
27 #include <mach/hardware.h>
28 #include <mach/gpio.h>
29 #include <plat/mcbsp.h>
31 #include "omap-mcbsp.h"
34 #include "../codecs/tlv320aic23.h"
36 #define CODEC_CLOCK 12000000
38 static int am3517evm_hw_params(struct snd_pcm_substream *substream,
39 struct snd_pcm_hw_params *params)
41 struct snd_soc_pcm_runtime *rtd = substream->private_data;
42 struct snd_soc_dai *codec_dai = rtd->codec_dai;
43 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
46 /* 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);
50 printk(KERN_ERR "can't set codec system clock\n");
54 ret = snd_soc_dai_set_sysclk(cpu_dai, OMAP_MCBSP_CLKR_SRC_CLKX, 0,
57 printk(KERN_ERR "can't set CPU system clock OMAP_MCBSP_CLKR_SRC_CLKX\n");
61 snd_soc_dai_set_sysclk(cpu_dai, OMAP_MCBSP_FSR_SRC_FSX, 0,
64 printk(KERN_ERR "can't set CPU system clock OMAP_MCBSP_FSR_SRC_FSX\n");
71 static struct snd_soc_ops am3517evm_ops = {
72 .hw_params = am3517evm_hw_params,
75 /* am3517evm machine dapm widgets */
76 static 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),
82 static 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"},
87 {"LLINEIN", NULL, "Line In"},
88 {"RLINEIN", NULL, "Line In"},
90 {"MICIN", NULL, "Mic In"},
93 static int am3517evm_aic23_init(struct snd_soc_pcm_runtime *rtd)
95 struct snd_soc_codec *codec = rtd->codec;
96 struct snd_soc_dapm_context *dapm = &codec->dapm;
98 /* Add am3517-evm specific widgets */
99 snd_soc_dapm_new_controls(dapm, tlv320aic23_dapm_widgets,
100 ARRAY_SIZE(tlv320aic23_dapm_widgets));
102 /* Set up davinci-evm specific audio path audio_map */
103 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
105 /* always connected */
106 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");
110 snd_soc_dapm_sync(dapm);
115 /* Digital audio interface glue - connects codec <--> CPU */
116 static struct snd_soc_dai_link am3517evm_dai = {
117 .name = "TLV320AIC23",
118 .stream_name = "AIC23",
119 .cpu_dai_name ="omap-mcbsp-dai.0",
120 .codec_dai_name = "tlv320aic23-hifi",
121 .platform_name = "omap-pcm-audio",
122 .codec_name = "tlv320aic23-codec.2-001a",
123 .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_NB_NF |
124 SND_SOC_DAIFMT_CBM_CFM,
125 .init = am3517evm_aic23_init,
126 .ops = &am3517evm_ops,
129 /* Audio machine driver */
130 static struct snd_soc_card snd_soc_am3517evm = {
132 .dai_link = &am3517evm_dai,
136 static struct platform_device *am3517evm_snd_device;
138 static int __init am3517evm_soc_init(void)
142 if (!machine_is_omap3517evm())
144 pr_info("OMAP3517 / AM3517 EVM SoC init\n");
146 am3517evm_snd_device = platform_device_alloc("soc-audio", -1);
147 if (!am3517evm_snd_device) {
148 printk(KERN_ERR "Platform device allocation failed\n");
152 platform_set_drvdata(am3517evm_snd_device, &snd_soc_am3517evm);
154 ret = platform_device_add(am3517evm_snd_device);
161 printk(KERN_ERR "Unable to add platform device\n");
162 platform_device_put(am3517evm_snd_device);
167 static void __exit am3517evm_soc_exit(void)
169 platform_device_unregister(am3517evm_snd_device);
172 module_init(am3517evm_soc_init);
173 module_exit(am3517evm_soc_exit);
175 MODULE_AUTHOR("Anuj Aggarwal <anuj.aggarwal@ti.com>");
176 MODULE_DESCRIPTION("ALSA SoC OMAP3517 / AM3517 EVM");
177 MODULE_LICENSE("GPL v2");