Commit | Line | Data |
---|---|---|
89e9abe7 AA |
1 | /* |
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> | |
da155d5b | 22 | #include <linux/module.h> |
89e9abe7 AA |
23 | #include <sound/core.h> |
24 | #include <sound/pcm.h> | |
25 | #include <sound/soc.h> | |
89e9abe7 AA |
26 | |
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 | ||
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; | |
f0fba2ad LG |
43 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
44 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; | |
89e9abe7 AA |
45 | int ret; |
46 | ||
89e9abe7 AA |
47 | /* 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); | |
50 | if (ret < 0) { | |
51 | printk(KERN_ERR "can't set codec system clock\n"); | |
52 | return ret; | |
53 | } | |
54 | ||
55 | ret = snd_soc_dai_set_sysclk(cpu_dai, OMAP_MCBSP_CLKR_SRC_CLKX, 0, | |
56 | SND_SOC_CLOCK_IN); | |
57 | if (ret < 0) { | |
58 | printk(KERN_ERR "can't set CPU system clock OMAP_MCBSP_CLKR_SRC_CLKX\n"); | |
59 | return ret; | |
60 | } | |
61 | ||
62 | snd_soc_dai_set_sysclk(cpu_dai, OMAP_MCBSP_FSR_SRC_FSX, 0, | |
63 | SND_SOC_CLOCK_IN); | |
64 | if (ret < 0) { | |
65 | printk(KERN_ERR "can't set CPU system clock OMAP_MCBSP_FSR_SRC_FSX\n"); | |
66 | return ret; | |
67 | } | |
68 | ||
69 | return 0; | |
70 | } | |
71 | ||
72 | static struct snd_soc_ops am3517evm_ops = { | |
73 | .hw_params = am3517evm_hw_params, | |
74 | }; | |
75 | ||
76 | /* am3517evm machine dapm widgets */ | |
77 | static const struct snd_soc_dapm_widget tlv320aic23_dapm_widgets[] = { | |
78 | SND_SOC_DAPM_HP("Line Out", NULL), | |
79 | SND_SOC_DAPM_LINE("Line In", NULL), | |
80 | SND_SOC_DAPM_MIC("Mic In", NULL), | |
81 | }; | |
82 | ||
83 | static const struct snd_soc_dapm_route audio_map[] = { | |
84 | /* Line Out connected to LLOUT, RLOUT */ | |
85 | {"Line Out", NULL, "LOUT"}, | |
86 | {"Line Out", NULL, "ROUT"}, | |
87 | ||
88 | {"LLINEIN", NULL, "Line In"}, | |
89 | {"RLINEIN", NULL, "Line In"}, | |
90 | ||
91 | {"MICIN", NULL, "Mic In"}, | |
92 | }; | |
93 | ||
89e9abe7 AA |
94 | /* Digital audio interface glue - connects codec <--> CPU */ |
95 | static struct snd_soc_dai_link am3517evm_dai = { | |
96 | .name = "TLV320AIC23", | |
97 | .stream_name = "AIC23", | |
f0fba2ad LG |
98 | .cpu_dai_name ="omap-mcbsp-dai.0", |
99 | .codec_dai_name = "tlv320aic23-hifi", | |
100 | .platform_name = "omap-pcm-audio", | |
ffd6eae2 | 101 | .codec_name = "tlv320aic23-codec.2-001a", |
cf9feff2 JN |
102 | .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_NB_NF | |
103 | SND_SOC_DAIFMT_CBM_CFM, | |
89e9abe7 AA |
104 | .ops = &am3517evm_ops, |
105 | }; | |
106 | ||
107 | /* Audio machine driver */ | |
108 | static struct snd_soc_card snd_soc_am3517evm = { | |
109 | .name = "am3517evm", | |
b425b884 | 110 | .owner = THIS_MODULE, |
89e9abe7 AA |
111 | .dai_link = &am3517evm_dai, |
112 | .num_links = 1, | |
d2266025 PU |
113 | |
114 | .dapm_widgets = tlv320aic23_dapm_widgets, | |
115 | .num_dapm_widgets = ARRAY_SIZE(tlv320aic23_dapm_widgets), | |
116 | .dapm_routes = audio_map, | |
117 | .num_dapm_routes = ARRAY_SIZE(audio_map), | |
89e9abe7 AA |
118 | }; |
119 | ||
89e9abe7 AA |
120 | static struct platform_device *am3517evm_snd_device; |
121 | ||
122 | static int __init am3517evm_soc_init(void) | |
123 | { | |
124 | int ret; | |
125 | ||
ec588ae6 | 126 | if (!machine_is_omap3517evm()) |
89e9abe7 | 127 | return -ENODEV; |
89e9abe7 AA |
128 | pr_info("OMAP3517 / AM3517 EVM SoC init\n"); |
129 | ||
130 | am3517evm_snd_device = platform_device_alloc("soc-audio", -1); | |
131 | if (!am3517evm_snd_device) { | |
132 | printk(KERN_ERR "Platform device allocation failed\n"); | |
133 | return -ENOMEM; | |
134 | } | |
135 | ||
f0fba2ad | 136 | platform_set_drvdata(am3517evm_snd_device, &snd_soc_am3517evm); |
89e9abe7 AA |
137 | |
138 | ret = platform_device_add(am3517evm_snd_device); | |
139 | if (ret) | |
140 | goto err1; | |
141 | ||
142 | return 0; | |
143 | ||
144 | err1: | |
145 | printk(KERN_ERR "Unable to add platform device\n"); | |
146 | platform_device_put(am3517evm_snd_device); | |
147 | ||
148 | return ret; | |
149 | } | |
150 | ||
151 | static void __exit am3517evm_soc_exit(void) | |
152 | { | |
153 | platform_device_unregister(am3517evm_snd_device); | |
154 | } | |
155 | ||
156 | module_init(am3517evm_soc_init); | |
157 | module_exit(am3517evm_soc_exit); | |
158 | ||
159 | MODULE_AUTHOR("Anuj Aggarwal <anuj.aggarwal@ti.com>"); | |
160 | MODULE_DESCRIPTION("ALSA SoC OMAP3517 / AM3517 EVM"); | |
161 | MODULE_LICENSE("GPL v2"); |