Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
am3517evm.c
Go to the documentation of this file.
1 /*
2  * am3517evm.c -- ALSA SoC support for OMAP3517 / AM3517 EVM
3  *
4  * Author: Anuj Aggarwal <[email protected]>
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 <linux/module.h>
23 #include <sound/core.h>
24 #include <sound/pcm.h>
25 #include <sound/soc.h>
26 
27 #include <asm/mach-types.h>
28 #include <mach/hardware.h>
29 #include <mach/gpio.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 
39 static 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;
43  struct snd_soc_dai *codec_dai = rtd->codec_dai;
44  int ret;
45 
46  /* Set the codec system clock for DAC and ADC */
47  ret = snd_soc_dai_set_sysclk(codec_dai, 0,
49  if (ret < 0)
50  printk(KERN_ERR "can't set codec system clock\n");
51 
52  return ret;
53 }
54 
55 static struct snd_soc_ops am3517evm_ops = {
56  .hw_params = am3517evm_hw_params,
57 };
58 
59 /* am3517evm machine dapm widgets */
60 static const struct snd_soc_dapm_widget tlv320aic23_dapm_widgets[] = {
61  SND_SOC_DAPM_HP("Line Out", NULL),
62  SND_SOC_DAPM_LINE("Line In", NULL),
63  SND_SOC_DAPM_MIC("Mic In", NULL),
64 };
65 
66 static const struct snd_soc_dapm_route audio_map[] = {
67  /* Line Out connected to LLOUT, RLOUT */
68  {"Line Out", NULL, "LOUT"},
69  {"Line Out", NULL, "ROUT"},
70 
71  {"LLINEIN", NULL, "Line In"},
72  {"RLINEIN", NULL, "Line In"},
73 
74  {"MICIN", NULL, "Mic In"},
75 };
76 
77 /* Digital audio interface glue - connects codec <--> CPU */
78 static struct snd_soc_dai_link am3517evm_dai = {
79  .name = "TLV320AIC23",
80  .stream_name = "AIC23",
81  .cpu_dai_name = "omap-mcbsp.1",
82  .codec_dai_name = "tlv320aic23-hifi",
83  .platform_name = "omap-pcm-audio",
84  .codec_name = "tlv320aic23-codec.2-001a",
87  .ops = &am3517evm_ops,
88 };
89 
90 /* Audio machine driver */
91 static struct snd_soc_card snd_soc_am3517evm = {
92  .name = "am3517evm",
93  .owner = THIS_MODULE,
94  .dai_link = &am3517evm_dai,
95  .num_links = 1,
96 
97  .dapm_widgets = tlv320aic23_dapm_widgets,
98  .num_dapm_widgets = ARRAY_SIZE(tlv320aic23_dapm_widgets),
99  .dapm_routes = audio_map,
100  .num_dapm_routes = ARRAY_SIZE(audio_map),
101 };
102 
103 static struct platform_device *am3517evm_snd_device;
104 
105 static int __init am3517evm_soc_init(void)
106 {
107  int ret;
108 
109  if (!machine_is_omap3517evm())
110  return -ENODEV;
111  pr_info("OMAP3517 / AM3517 EVM SoC init\n");
112 
113  am3517evm_snd_device = platform_device_alloc("soc-audio", -1);
114  if (!am3517evm_snd_device) {
115  printk(KERN_ERR "Platform device allocation failed\n");
116  return -ENOMEM;
117  }
118 
119  platform_set_drvdata(am3517evm_snd_device, &snd_soc_am3517evm);
120 
121  ret = platform_device_add(am3517evm_snd_device);
122  if (ret)
123  goto err1;
124 
125  return 0;
126 
127 err1:
128  printk(KERN_ERR "Unable to add platform device\n");
129  platform_device_put(am3517evm_snd_device);
130 
131  return ret;
132 }
133 
134 static void __exit am3517evm_soc_exit(void)
135 {
136  platform_device_unregister(am3517evm_snd_device);
137 }
138 
139 module_init(am3517evm_soc_init);
140 module_exit(am3517evm_soc_exit);
141 
142 MODULE_AUTHOR("Anuj Aggarwal <[email protected]>");
143 MODULE_DESCRIPTION("ALSA SoC OMAP3517 / AM3517 EVM");
144 MODULE_LICENSE("GPL v2");