blob: a997988af14785701c30b64a502c5fd6f1277fe6 [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>
Paul Gortmakerda155d52011-07-15 12:38:28 -040022#include <linux/module.h>
Anuj Aggarwal89e9abe2009-10-30 00:22:30 +053023#include <sound/core.h>
24#include <sound/pcm.h>
25#include <sound/soc.h>
Anuj Aggarwal89e9abe2009-10-30 00:22:30 +053026
27#include <asm/mach-types.h>
28#include <mach/hardware.h>
29#include <mach/gpio.h>
30#include <plat/mcbsp.h>
31
32#include "omap-mcbsp.h"
33#include "omap-pcm.h"
34
35#include "../codecs/tlv320aic23.h"
36
37#define CODEC_CLOCK 12000000
38
39static int am3517evm_hw_params(struct snd_pcm_substream *substream,
40 struct snd_pcm_hw_params *params)
41{
42 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000043 struct snd_soc_dai *codec_dai = rtd->codec_dai;
44 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
Anuj Aggarwal89e9abe2009-10-30 00:22:30 +053045 int ret;
46
Anuj Aggarwal89e9abe2009-10-30 00:22:30 +053047 /* Set the codec system clock for DAC and ADC */
48 ret = snd_soc_dai_set_sysclk(codec_dai, 0,
49 CODEC_CLOCK, SND_SOC_CLOCK_IN);
Peter Ujfalusifca04ae2012-08-16 16:41:03 +030050 if (ret < 0)
Anuj Aggarwal89e9abe2009-10-30 00:22:30 +053051 printk(KERN_ERR "can't set codec system clock\n");
Anuj Aggarwal89e9abe2009-10-30 00:22:30 +053052
Peter Ujfalusifca04ae2012-08-16 16:41:03 +030053 return ret;
Anuj Aggarwal89e9abe2009-10-30 00:22:30 +053054}
55
56static struct snd_soc_ops am3517evm_ops = {
57 .hw_params = am3517evm_hw_params,
58};
59
60/* am3517evm machine dapm widgets */
61static const struct snd_soc_dapm_widget tlv320aic23_dapm_widgets[] = {
62 SND_SOC_DAPM_HP("Line Out", NULL),
63 SND_SOC_DAPM_LINE("Line In", NULL),
64 SND_SOC_DAPM_MIC("Mic In", NULL),
65};
66
67static const struct snd_soc_dapm_route audio_map[] = {
68 /* Line Out connected to LLOUT, RLOUT */
69 {"Line Out", NULL, "LOUT"},
70 {"Line Out", NULL, "ROUT"},
71
72 {"LLINEIN", NULL, "Line In"},
73 {"RLINEIN", NULL, "Line In"},
74
75 {"MICIN", NULL, "Mic In"},
76};
77
Anuj Aggarwal89e9abe2009-10-30 00:22:30 +053078/* Digital audio interface glue - connects codec <--> CPU */
79static struct snd_soc_dai_link am3517evm_dai = {
80 .name = "TLV320AIC23",
81 .stream_name = "AIC23",
Peter Ujfalusi45656b42012-02-14 18:20:58 +020082 .cpu_dai_name = "omap-mcbsp.1",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000083 .codec_dai_name = "tlv320aic23-hifi",
84 .platform_name = "omap-pcm-audio",
Abhilash K Vffd6eae2011-03-08 21:02:43 +053085 .codec_name = "tlv320aic23-codec.2-001a",
Jarkko Nikulacf9feff2011-09-30 16:07:45 +030086 .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_NB_NF |
87 SND_SOC_DAIFMT_CBM_CFM,
Anuj Aggarwal89e9abe2009-10-30 00:22:30 +053088 .ops = &am3517evm_ops,
89};
90
91/* Audio machine driver */
92static struct snd_soc_card snd_soc_am3517evm = {
93 .name = "am3517evm",
Axel Linb425b882011-12-22 11:08:59 +080094 .owner = THIS_MODULE,
Anuj Aggarwal89e9abe2009-10-30 00:22:30 +053095 .dai_link = &am3517evm_dai,
96 .num_links = 1,
Peter Ujfalusid2266022011-10-10 15:34:09 +030097
98 .dapm_widgets = tlv320aic23_dapm_widgets,
99 .num_dapm_widgets = ARRAY_SIZE(tlv320aic23_dapm_widgets),
100 .dapm_routes = audio_map,
101 .num_dapm_routes = ARRAY_SIZE(audio_map),
Anuj Aggarwal89e9abe2009-10-30 00:22:30 +0530102};
103
Anuj Aggarwal89e9abe2009-10-30 00:22:30 +0530104static struct platform_device *am3517evm_snd_device;
105
106static int __init am3517evm_soc_init(void)
107{
108 int ret;
109
Jarkko Nikulaec588ae2010-10-06 16:47:26 +0300110 if (!machine_is_omap3517evm())
Anuj Aggarwal89e9abe2009-10-30 00:22:30 +0530111 return -ENODEV;
Anuj Aggarwal89e9abe2009-10-30 00:22:30 +0530112 pr_info("OMAP3517 / AM3517 EVM SoC init\n");
113
114 am3517evm_snd_device = platform_device_alloc("soc-audio", -1);
115 if (!am3517evm_snd_device) {
116 printk(KERN_ERR "Platform device allocation failed\n");
117 return -ENOMEM;
118 }
119
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000120 platform_set_drvdata(am3517evm_snd_device, &snd_soc_am3517evm);
Anuj Aggarwal89e9abe2009-10-30 00:22:30 +0530121
122 ret = platform_device_add(am3517evm_snd_device);
123 if (ret)
124 goto err1;
125
126 return 0;
127
128err1:
129 printk(KERN_ERR "Unable to add platform device\n");
130 platform_device_put(am3517evm_snd_device);
131
132 return ret;
133}
134
135static void __exit am3517evm_soc_exit(void)
136{
137 platform_device_unregister(am3517evm_snd_device);
138}
139
140module_init(am3517evm_soc_init);
141module_exit(am3517evm_soc_exit);
142
143MODULE_AUTHOR("Anuj Aggarwal <anuj.aggarwal@ti.com>");
144MODULE_DESCRIPTION("ALSA SoC OMAP3517 / AM3517 EVM");
145MODULE_LICENSE("GPL v2");