Commit | Line | Data |
---|---|---|
b4df0a6c SL |
1 | /* |
2 | * afeb9260.c -- SoC audio for AFEB9260 | |
3 | * | |
4 | * Copyright (C) 2009 Sergey Lapin <slapin@ossfans.org> | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or | |
7 | * modify it under the terms of the GNU General Public License | |
8 | * version 2 as published by the Free Software Foundation. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, but | |
11 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | * General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License | |
16 | * along with this program; if not, write to the Free Software | |
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | |
18 | * 02110-1301 USA | |
19 | * | |
20 | */ | |
21 | ||
22 | #include <linux/module.h> | |
23 | #include <linux/moduleparam.h> | |
24 | #include <linux/kernel.h> | |
25 | #include <linux/clk.h> | |
26 | #include <linux/platform_device.h> | |
27 | ||
28 | #include <linux/atmel-ssc.h> | |
29 | #include <sound/core.h> | |
30 | #include <sound/pcm.h> | |
31 | #include <sound/pcm_params.h> | |
32 | #include <sound/soc.h> | |
b4df0a6c SL |
33 | |
34 | #include <asm/mach-types.h> | |
35 | #include <mach/hardware.h> | |
36 | #include <linux/gpio.h> | |
37 | ||
38 | #include "../codecs/tlv320aic23.h" | |
39 | #include "atmel-pcm.h" | |
40 | #include "atmel_ssc_dai.h" | |
41 | ||
42 | #define CODEC_CLOCK 12000000 | |
43 | ||
44 | static int afeb9260_hw_params(struct snd_pcm_substream *substream, | |
45 | struct snd_pcm_hw_params *params) | |
46 | { | |
47 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | |
f0fba2ad LG |
48 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
49 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; | |
b4df0a6c SL |
50 | int err; |
51 | ||
52 | /* Set codec DAI configuration */ | |
53 | err = snd_soc_dai_set_fmt(codec_dai, | |
54 | SND_SOC_DAIFMT_I2S| | |
55 | SND_SOC_DAIFMT_NB_IF | | |
56 | SND_SOC_DAIFMT_CBM_CFM); | |
57 | if (err < 0) { | |
58 | printk(KERN_ERR "can't set codec DAI configuration\n"); | |
59 | return err; | |
60 | } | |
61 | ||
62 | /* Set cpu DAI configuration */ | |
63 | err = snd_soc_dai_set_fmt(cpu_dai, | |
64 | SND_SOC_DAIFMT_I2S | | |
65 | SND_SOC_DAIFMT_NB_IF | | |
66 | SND_SOC_DAIFMT_CBM_CFM); | |
67 | if (err < 0) { | |
68 | printk(KERN_ERR "can't set cpu DAI configuration\n"); | |
69 | return err; | |
70 | } | |
71 | ||
72 | /* Set the codec system clock for DAC and ADC */ | |
73 | err = | |
74 | snd_soc_dai_set_sysclk(codec_dai, 0, CODEC_CLOCK, SND_SOC_CLOCK_IN); | |
75 | ||
76 | if (err < 0) { | |
77 | printk(KERN_ERR "can't set codec system clock\n"); | |
78 | return err; | |
79 | } | |
80 | ||
81 | return err; | |
82 | } | |
83 | ||
84 | static struct snd_soc_ops afeb9260_ops = { | |
85 | .hw_params = afeb9260_hw_params, | |
86 | }; | |
87 | ||
88 | static const struct snd_soc_dapm_widget tlv320aic23_dapm_widgets[] = { | |
89 | SND_SOC_DAPM_HP("Headphone Jack", NULL), | |
90 | SND_SOC_DAPM_LINE("Line In", NULL), | |
91 | SND_SOC_DAPM_MIC("Mic Jack", NULL), | |
92 | }; | |
93 | ||
94 | static const struct snd_soc_dapm_route audio_map[] = { | |
95 | {"Headphone Jack", NULL, "LHPOUT"}, | |
96 | {"Headphone Jack", NULL, "RHPOUT"}, | |
97 | ||
98 | {"LLINEIN", NULL, "Line In"}, | |
99 | {"RLINEIN", NULL, "Line In"}, | |
100 | ||
101 | {"MICIN", NULL, "Mic Jack"}, | |
102 | }; | |
103 | ||
f0fba2ad | 104 | static int afeb9260_tlv320aic23_init(struct snd_soc_pcm_runtime *rtd) |
b4df0a6c | 105 | { |
f0fba2ad | 106 | struct snd_soc_codec *codec = rtd->codec; |
ce6120cc | 107 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
b4df0a6c SL |
108 | |
109 | /* Add afeb9260 specific widgets */ | |
ce6120cc | 110 | snd_soc_dapm_new_controls(dapm, tlv320aic23_dapm_widgets, |
b4df0a6c SL |
111 | ARRAY_SIZE(tlv320aic23_dapm_widgets)); |
112 | ||
113 | /* Set up afeb9260 specific audio path audio_map */ | |
ce6120cc | 114 | snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map)); |
b4df0a6c | 115 | |
ce6120cc LG |
116 | snd_soc_dapm_enable_pin(dapm, "Headphone Jack"); |
117 | snd_soc_dapm_enable_pin(dapm, "Line In"); | |
118 | snd_soc_dapm_enable_pin(dapm, "Mic Jack"); | |
b4df0a6c | 119 | |
b4df0a6c SL |
120 | return 0; |
121 | } | |
122 | ||
123 | /* Digital audio interface glue - connects codec <--> CPU */ | |
124 | static struct snd_soc_dai_link afeb9260_dai = { | |
125 | .name = "TLV320AIC23", | |
126 | .stream_name = "AIC23", | |
f0fba2ad LG |
127 | .cpu_dai_name = "atmel-ssc-dai.0", |
128 | .codec_dai_name = "tlv320aic23-hifi", | |
129 | .platform_name = "atmel_pcm-audio", | |
81d7da54 | 130 | .codec_name = "tlv320aic23-codec.0-001a", |
b4df0a6c SL |
131 | .init = afeb9260_tlv320aic23_init, |
132 | .ops = &afeb9260_ops, | |
133 | }; | |
134 | ||
135 | /* Audio machine driver */ | |
136 | static struct snd_soc_card snd_soc_machine_afeb9260 = { | |
137 | .name = "AFEB9260", | |
b4df0a6c SL |
138 | .dai_link = &afeb9260_dai, |
139 | .num_links = 1, | |
140 | }; | |
141 | ||
b4df0a6c SL |
142 | static struct platform_device *afeb9260_snd_device; |
143 | ||
144 | static int __init afeb9260_soc_init(void) | |
145 | { | |
146 | int err; | |
147 | struct device *dev; | |
b4df0a6c SL |
148 | |
149 | if (!(machine_is_afeb9260())) | |
150 | return -ENODEV; | |
151 | ||
b4df0a6c SL |
152 | |
153 | afeb9260_snd_device = platform_device_alloc("soc-audio", -1); | |
154 | if (!afeb9260_snd_device) { | |
155 | printk(KERN_ERR "ASoC: Platform device allocation failed\n"); | |
156 | return -ENOMEM; | |
157 | } | |
158 | ||
f0fba2ad | 159 | platform_set_drvdata(afeb9260_snd_device, &snd_soc_machine_afeb9260); |
b4df0a6c SL |
160 | err = platform_device_add(afeb9260_snd_device); |
161 | if (err) | |
162 | goto err1; | |
163 | ||
164 | dev = &afeb9260_snd_device->dev; | |
165 | ||
166 | return 0; | |
167 | err1: | |
b4df0a6c | 168 | platform_device_put(afeb9260_snd_device); |
b4df0a6c | 169 | return err; |
b4df0a6c SL |
170 | } |
171 | ||
172 | static void __exit afeb9260_soc_exit(void) | |
173 | { | |
174 | platform_device_unregister(afeb9260_snd_device); | |
175 | } | |
176 | ||
177 | module_init(afeb9260_soc_init); | |
178 | module_exit(afeb9260_soc_exit); | |
179 | ||
180 | MODULE_AUTHOR("Sergey Lapin <slapin@ossfans.org>"); | |
181 | MODULE_DESCRIPTION("ALSA SoC for AFEB9260"); | |
182 | MODULE_LICENSE("GPL"); | |
183 |